dorkos 0.101.0 → 0.103.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 (208) hide show
  1. package/README.md +10 -10
  2. package/dist/bin/cli.js +2935 -1738
  3. package/dist/browser/native/package-manifest.json +1 -1
  4. package/dist/browser/source-manifest.json +1 -1
  5. package/dist/client/assets/{AboutPage-CwxCTicf.js → AboutPage-BNVLNd3q.js} +1 -1
  6. package/dist/client/assets/{ActivityRow-D0QQ0SFu.js → ActivityRow-CvjAfRBM.js} +1 -1
  7. package/dist/client/assets/AdapterIcon-wGSXBn-k.js +1 -0
  8. package/dist/client/assets/AdapterSetupWizard-CmSJ2sno.js +2 -0
  9. package/dist/client/assets/{AgentRequestCard-BLLmoAES.js → AgentRequestCard-D62XQXBM.js} +4 -4
  10. package/dist/client/assets/{AppearancePage-GqrWckTQ.js → AppearancePage-Bds0L-wm.js} +1 -1
  11. package/dist/client/assets/{AttentionSignalRow-sEhnIPBB.js → AttentionSignalRow-C6RkjCWK.js} +1 -1
  12. package/dist/client/assets/{BaseTanStackRouterDevtoolsPanel-B-iktbLX-BXjzhT_D.js → BaseTanStackRouterDevtoolsPanel-B-iktbLX-CerNarG-.js} +24 -24
  13. package/dist/client/assets/{BlintzCanvas-CXi0fvcM.js → BlintzCanvas-CUqethk_.js} +24 -24
  14. package/dist/client/assets/{CanvasCsvContent-QhDSf8Pd.js → CanvasCsvContent-DdbIUPMJ.js} +1 -1
  15. package/dist/client/assets/CanvasFileContent-CX2VNF4o.js +2 -0
  16. package/dist/client/assets/CanvasModel3dContent-OprkQsgq.js +2 -0
  17. package/dist/client/assets/{CodeMirrorDiff-BMG7DBg2.js → CodeMirrorDiff-BnMdmI0K.js} +1 -1
  18. package/dist/client/assets/{CodeMirrorEditor-BYdz0ipX.js → CodeMirrorEditor-C7T-DaVA.js} +1 -1
  19. package/dist/client/assets/ConnectionAccessLists-B3QGnSxM.js +1 -0
  20. package/dist/client/assets/ConnectionsPage-E3br6maQ.js +11 -0
  21. package/dist/client/assets/{ConventionPage-y-Zq3Klp.js → ConventionPage-vMN5qEwP.js} +3 -3
  22. package/dist/client/assets/{ExtensionPageRoute-gZKKPhaj.js → ExtensionPageRoute-DFkPAzjs.js} +2 -2
  23. package/dist/client/assets/{FloatingTanStackRouterDevtools-CqogiFob-CbKIa11X.js → FloatingTanStackRouterDevtools-CqogiFob-BP4itJWW.js} +1 -1
  24. package/dist/client/assets/HandlePage-De4D_IVs.js +1 -0
  25. package/dist/client/assets/{LexicalField-Ceoa9flp.js → LexicalField-BbUXXxTw.js} +1 -1
  26. package/dist/client/assets/{ManagesPage-Dcqdm6I8.js → ManagesPage-DsNSZHug.js} +1 -1
  27. package/dist/client/assets/Marketplace-D4zHIIak.js +36 -0
  28. package/dist/client/assets/MarketplaceSourcesView-DILS8-ca.js +1 -0
  29. package/dist/client/assets/{McpAppFrame-B1ThSf2U.js → McpAppFrame-Cl_2azg-.js} +2 -2
  30. package/dist/client/assets/McpSigninBody-TpoSImsV.js +1 -0
  31. package/dist/client/assets/{Model3dViewer-DlcQ3-LS.js → Model3dViewer-C-iyu5eV.js} +1 -1
  32. package/dist/client/assets/NamePage-C-3w8oeg.js +1 -0
  33. package/dist/client/assets/NewDirectMessageMenu-bJE7b4lX.js +1 -0
  34. package/dist/client/assets/{NotificationsPage-CQQIdLtI.js → NotificationsPage-CL23qwVw.js} +1 -1
  35. package/dist/client/assets/OperatorIdentityForm-ixaqUfIO.js +1 -0
  36. package/dist/client/assets/{PermissionsPage-TX-d7aVQ.js → PermissionsPage-D4xbxTkc.js} +1 -1
  37. package/dist/client/assets/{PersonalityPicker-C_9JVOva.js → PersonalityPicker-CTvPlN-k.js} +1 -1
  38. package/dist/client/assets/{PersonalityPopover-BoTED73t.js → PersonalityPopover-Coy0eaIg.js} +1 -1
  39. package/dist/client/assets/PhotoPage-DpEEXO3e.js +1 -0
  40. package/dist/client/assets/PreviewRefusedNotice-B2GLqLYi.js +1 -0
  41. package/dist/client/assets/{PromptSuggestionChips-B_oUtFMI.js → PromptSuggestionChips-YdKEWyNT.js} +1 -1
  42. package/dist/client/assets/RoomSurface-BwIBBvYq.js +44 -0
  43. package/dist/client/assets/{RoomsPage-zOjjpHdA.js → RoomsPage-DaEXPz65.js} +1 -1
  44. package/dist/client/assets/RunsOnPopover-tvbVPKVf.js +1 -0
  45. package/dist/client/assets/SessionsPage-CAdV_XBY.js +1 -0
  46. package/dist/client/assets/SkillsPage-B4F19LmV.js +1 -0
  47. package/dist/client/assets/{TasksPage-BZapA_v6.js → TasksPage-BXcaEx3V.js} +1 -1
  48. package/dist/client/assets/ToolsPage-BYBwPql_.js +2 -0
  49. package/dist/client/assets/{TopologyGraph-BMcPxZsA.js → TopologyGraph-CZ2Y5I2e.js} +1 -1
  50. package/dist/client/assets/TourHost-BNpDrN0O.js +1 -0
  51. package/dist/client/assets/UnlinkDialog-Zyuh5qZY.js +1 -0
  52. package/dist/client/assets/{UnreadDivider-KSqqcHKN.js → UnreadDivider-Dh67_mAz.js} +1 -1
  53. package/dist/client/assets/_shell-lcu5vkQ7.js +98 -0
  54. package/dist/client/assets/{_shell._home-Bp_p1VUv.js → _shell._home-CPV1Z64k.js} +1 -1
  55. package/dist/client/assets/_shell._home.activity-CEvkKYBD.js +1 -0
  56. package/dist/client/assets/_shell._home.index-tGnRLvY-.js +3 -0
  57. package/dist/client/assets/{_shell._home.tasks-BsBH_4tZ.js → _shell._home.tasks-CtpZNevK.js} +1 -1
  58. package/dist/client/assets/_shell._home.workspaces-D6tkWdS8.js +1 -0
  59. package/dist/client/assets/{_shell.channels-DWAHkDPV.js → _shell.channels-DbrQXIVv.js} +4 -4
  60. package/dist/client/assets/_shell.connections-C3Ho4S8R.js +6 -0
  61. package/dist/client/assets/{_shell.feedback-requests-Hjv640j9.js → _shell.feedback-requests-D9l7SJi1.js} +1 -1
  62. package/dist/client/assets/_shell.marketplace-BfY-kBJk.js +1 -0
  63. package/dist/client/assets/_shell.marketplace_.sources-B0km_EUs.js +1 -0
  64. package/dist/client/assets/_shell.session-O8MC-USm.js +54 -0
  65. package/dist/client/assets/{_shell.team-ctLQztjw.js → _shell.team-DvJK7irE.js} +4 -4
  66. package/dist/client/assets/_shell.x._extensionId-_-fII74H.js +1 -0
  67. package/dist/client/assets/_shell.x._extensionId_._-_-fII74H.js +1 -0
  68. package/dist/client/assets/agent-attention-BvnWcLpc.js +5 -0
  69. package/dist/client/assets/{agent-browser-CCN16ZOz.js → agent-browser-DsDp0cSX.js} +1 -1
  70. package/dist/client/assets/{banner-DOm9_4l-.js → banner-Cja2VfwN.js} +2 -2
  71. package/dist/client/assets/{file-exclamation-point-BKzL0QhY.js → file-exclamation-point-D8KYFYSh.js} +1 -1
  72. package/dist/client/assets/{highlighted-body-KPVGNVTW-DTxMTVdP.js → highlighted-body-KPVGNVTW-Chp5pHWq.js} +1 -1
  73. package/dist/client/assets/{hover-card-qzuFUCaR.js → hover-card-FvX18DHP.js} +1 -1
  74. package/dist/client/assets/{index-Dcs6e-U_.js → index-BFPRILKF.js} +1 -1
  75. package/dist/client/assets/{index-CtOB9fS3.js → index-BKCteC7q.js} +1 -1
  76. package/dist/client/assets/index-Bbffv0TQ.js +1247 -0
  77. package/dist/client/assets/{index-BMOfHKE0.js → index-BhatJcNc.js} +1 -1
  78. package/dist/client/assets/index-BroohPSu.js +1 -0
  79. package/dist/client/assets/{index-DT_v3O-B.js → index-Bt4vTnDj.js} +1 -1
  80. package/dist/client/assets/{index-DwzSdOh3.js → index-BwkmCRvO.js} +1 -1
  81. package/dist/client/assets/{index-CTai_TxZ.js → index-BzS1K2wS.js} +1 -1
  82. package/dist/client/assets/{index-C3XnoXTY.js → index-C6F5gzX-.js} +1 -1
  83. package/dist/client/assets/{index-BaB-skF0.js → index-CIzSi3tA.js} +3 -3
  84. package/dist/client/assets/{index-BPcwoJoz.js → index-CLCbHvV5.js} +1 -1
  85. package/dist/client/assets/{index-DA-i3I4q.js → index-CXjobHw0.js} +1 -1
  86. package/dist/client/assets/{index-DgH_dl1a.js → index-CYcJ7ENW.js} +2 -2
  87. package/dist/client/assets/{index-3lQkXKcq.js → index-CeqzGl3y.js} +1 -1
  88. package/dist/client/assets/{index-DgtF-nBt.js → index-CknNaeS2.js} +1 -1
  89. package/dist/client/assets/{index-Bk98IpMn.js → index-CtK6WJzD.js} +1 -1
  90. package/dist/client/assets/{index-C8ZMfyGc.js → index-CvxLe-_3.js} +1 -1
  91. package/dist/client/assets/{index-CF9fqPef.js → index-D24Ttd-y.js} +4 -4
  92. package/dist/client/assets/{index-CIPHHziB.js → index-D6Jn2eBq.js} +1 -1
  93. package/dist/client/assets/{index-D3DXMH4x.js → index-DDibi3-x.js} +1 -1
  94. package/dist/client/assets/{index-C7B2uRgo.js → index-DElGMXW8.js} +2 -2
  95. package/dist/client/assets/{index-CmlaXay_.js → index-DGNJkiFb.js} +1 -1
  96. package/dist/client/assets/{index-WjW-NUCp.js → index-DI2T-dXr.js} +1 -1
  97. package/dist/client/assets/{index-CLhD0Bno.js → index-DZf_utaG.js} +1 -1
  98. package/dist/client/assets/{index-CTXNRyRE.js → index-D_XtXoLp.js} +1 -1
  99. package/dist/client/assets/{index-CDTumWMC.js → index-DjdQaKwP.js} +1 -1
  100. package/dist/client/assets/index-Do18O9VZ.js +1 -0
  101. package/dist/client/assets/{index-CVl132_4.js → index-Do1vOFrm.js} +1 -1
  102. package/dist/client/assets/{index-BIMClIrX.js → index-Dv1DkyeB.js} +1 -1
  103. package/dist/client/assets/{index-IgIVF9T_.js → index-DyvLJ_Z5.js} +1 -1
  104. package/dist/client/assets/index-HgvJwMGi.js +5 -0
  105. package/dist/client/assets/{index-DR1JT9Uz.js → index-OxwtxTFo.js} +3 -3
  106. package/dist/client/assets/index-QSDTjavn.js +1 -0
  107. package/dist/client/assets/{index-DOxEmnH2.js → index-ZLdoJdwS.js} +1 -1
  108. package/dist/client/assets/index-_GlgFH88.css +1 -0
  109. package/dist/client/assets/{index-CScfHuKF.js → index-euarUu2E.js} +1 -1
  110. package/dist/client/assets/{index-B-z7hA9x.js → index-jYh6X22t.js} +1 -1
  111. package/dist/client/assets/{index-CIfwPLXd.js → index-uQ1vTS05.js} +1 -1
  112. package/dist/client/assets/{index-CejezM4U.js → index-xfBvKz-h.js} +1 -1
  113. package/dist/client/assets/{index-BW5ce4t8.js → index-znQ5q2gV.js} +1 -1
  114. package/dist/client/assets/{layers-CJHXSEKK.js → layers-8-cbYlfw.js} +1 -1
  115. package/dist/client/assets/{lightbulb-DWjxw7lb.js → lightbulb-DoB0IKly.js} +1 -1
  116. package/dist/client/assets/{mention-pill-akMU3IVs.js → mention-pill-BHC6tMG9.js} +1 -1
  117. package/dist/client/assets/{message-square-off-DEagHpQY.js → message-square-off-CEHuZJtY.js} +1 -1
  118. package/dist/client/assets/{owner-notice-CLsx0s7q.js → owner-notice-dtDSKfGs.js} +1 -1
  119. package/dist/client/assets/{page-container-W7byjRmk.js → page-container-BOrdASM1.js} +1 -1
  120. package/dist/client/assets/primer-trigger-CC-cR5zN.js +3 -0
  121. package/dist/client/assets/{radio-B8Ozjv9U.js → radio-BfZPhctR.js} +1 -1
  122. package/dist/client/assets/{room-files-source-Bsc3YA91.js → room-files-source-BHupFaLE.js} +2 -2
  123. package/dist/client/assets/{rotate-ccw-clock-CNcDcTvq.js → rotate-ccw-clock-BvzfP8lR.js} +1 -1
  124. package/dist/client/assets/{rotate-cw-xvfipJLN.js → rotate-cw-BDweizfR.js} +1 -1
  125. package/dist/client/assets/{scroll-area-C95q3ss7.js → scroll-area-Dph6w3a6.js} +1 -1
  126. package/dist/client/assets/{search-x-C6SAxw7a.js → search-x-CoFJOP2l.js} +2 -2
  127. package/dist/client/assets/{shield-x-DxOGc0dW.js → shield-x-BZ6rhiT0.js} +1 -1
  128. package/dist/client/assets/{soul-file-pg0ShYy3.js → soul-file-H8fwhgiL.js} +1 -1
  129. package/dist/client/assets/use-delete-binding-CUsepFIL.js +1 -0
  130. package/dist/client/assets/use-dev-links-DYYe0vvP.js +1 -0
  131. package/dist/client/assets/{use-external-adapter-catalog-B0gcY-k7.js → use-external-adapter-catalog-CAl3MNq-.js} +1 -1
  132. package/dist/client/assets/use-full-activity-feed-Bb7BUusp.js +1 -0
  133. package/dist/client/assets/use-is-below-desktop-CIgGSgoL.js +1 -0
  134. package/dist/client/assets/use-jump-back-in-BdLBzvDr.js +11 -0
  135. package/dist/client/assets/use-mesh-topology-wYtCBbF_.js +1 -0
  136. package/dist/client/assets/use-pending-read-9UcfnDwF.js +1 -0
  137. package/dist/client/assets/{use-personality-commit-OH7d0xl_.js → use-personality-commit-CaxUHrX5.js} +1 -1
  138. package/dist/client/assets/{use-promo-activation-BgdGasXE.js → use-promo-activation-rNaAOdoh.js} +2 -2
  139. package/dist/client/assets/use-pulse-freshness-CygG3s-S.js +1 -0
  140. package/dist/client/assets/use-room-follow-claim-BIK37Iy3.js +1 -0
  141. package/dist/client/assets/{use-roving-tab-list-Be60AWK3.js → use-roving-tab-list-DQgkKGzc.js} +1 -1
  142. package/dist/client/assets/{use-session-canvas-Bqs6IQO7.js → use-session-canvas-Dpy5BEId.js} +5 -5
  143. package/dist/client/assets/use-session-diagnostics-atu9cfgr.js +16 -0
  144. package/dist/client/assets/use-unclaimed-chats-qUI5vY5K.js +1 -0
  145. package/dist/client/index.html +2 -2
  146. package/dist/drizzle/20261008170031_session_touches.sql +5 -0
  147. package/dist/drizzle/20261009171311_chat_messages.sql +41 -0
  148. package/dist/drizzle/20261009173712_started_by_report_back.sql +1 -0
  149. package/dist/drizzle/meta/20261008170031_snapshot.json +12642 -0
  150. package/dist/drizzle/meta/20261009171311_snapshot.json +12906 -0
  151. package/dist/drizzle/meta/20261009173712_snapshot.json +12914 -0
  152. package/dist/drizzle/meta/_journal.json +21 -0
  153. package/dist/server/index.js +23608 -19236
  154. package/dist/server/index.js.map +2 -2
  155. package/package.json +6 -6
  156. package/dist/client/assets/AdapterIcon-CL-MyyKy.js +0 -1
  157. package/dist/client/assets/AdapterSetupWizard-C8HOvHLF.js +0 -2
  158. package/dist/client/assets/CanvasFileContent-ZZhdofR4.js +0 -2
  159. package/dist/client/assets/CanvasModel3dContent-DMMMZh4o.js +0 -2
  160. package/dist/client/assets/ConnectionAccessLists-PW1uzcGU.js +0 -1
  161. package/dist/client/assets/ConnectionsPage-EwitZwOE.js +0 -11
  162. package/dist/client/assets/HandlePage-CL3_n1CI.js +0 -1
  163. package/dist/client/assets/Marketplace-DsU-q1ZZ.js +0 -36
  164. package/dist/client/assets/MarketplaceSourcesView-D72YoKNR.js +0 -1
  165. package/dist/client/assets/McpSigninBody-Btg3PnYN.js +0 -1
  166. package/dist/client/assets/NamePage-Bzqj4Eob.js +0 -1
  167. package/dist/client/assets/NewDirectMessageMenu-89yeGqvy.js +0 -1
  168. package/dist/client/assets/OperatorIdentityForm-BhiB9tQp.js +0 -1
  169. package/dist/client/assets/PhotoPage-C3fMlebQ.js +0 -1
  170. package/dist/client/assets/PreviewRefusedNotice-ChCgdKWN.js +0 -1
  171. package/dist/client/assets/RoomSurface-CgtNuYhl.js +0 -39
  172. package/dist/client/assets/RunsOnPopover-JTm1cYuw.js +0 -1
  173. package/dist/client/assets/SessionsPage-D4kyvHQf.js +0 -6
  174. package/dist/client/assets/SkillsPage-KYUVzuVa.js +0 -1
  175. package/dist/client/assets/ToolsPage-CWpHMlrR.js +0 -2
  176. package/dist/client/assets/TourHost-VY1-sy1Y.js +0 -1
  177. package/dist/client/assets/UnlinkDialog-3p38G_9q.js +0 -1
  178. package/dist/client/assets/_shell-DAjwimLg.js +0 -93
  179. package/dist/client/assets/_shell._home.activity-tk-XApvX.js +0 -1
  180. package/dist/client/assets/_shell._home.index-BNVhSN0y.js +0 -3
  181. package/dist/client/assets/_shell._home.workspaces-DuXnjQh0.js +0 -1
  182. package/dist/client/assets/_shell.connections-DIm3mUHy.js +0 -6
  183. package/dist/client/assets/_shell.marketplace-DF6Y7mc0.js +0 -1
  184. package/dist/client/assets/_shell.marketplace_.sources-Do8cm7kq.js +0 -1
  185. package/dist/client/assets/_shell.session-DlN8iOl-.js +0 -43
  186. package/dist/client/assets/_shell.x._extensionId-0Q1rJtud.js +0 -1
  187. package/dist/client/assets/_shell.x._extensionId_._-0Q1rJtud.js +0 -1
  188. package/dist/client/assets/agent-attention-Dn__3LQE.js +0 -5
  189. package/dist/client/assets/hand-DLUdsiuR.js +0 -6
  190. package/dist/client/assets/index-CQWqpw_G.js +0 -1
  191. package/dist/client/assets/index-D5uYwabS.js +0 -1
  192. package/dist/client/assets/index-DFMDv6qR.js +0 -1
  193. package/dist/client/assets/index-DMYBI16t.js +0 -1252
  194. package/dist/client/assets/index-DbbZNAKk.js +0 -5
  195. package/dist/client/assets/index-Dgp1LmEk.css +0 -1
  196. package/dist/client/assets/primer-trigger-DuM9vVnV.js +0 -3
  197. package/dist/client/assets/use-delete-binding-CZVeHqn0.js +0 -1
  198. package/dist/client/assets/use-dev-links-Df2WkCic.js +0 -1
  199. package/dist/client/assets/use-full-activity-feed-SYcgdMZu.js +0 -1
  200. package/dist/client/assets/use-is-below-desktop-C5_YenEp.js +0 -1
  201. package/dist/client/assets/use-jump-back-in-DWUPb1gi.js +0 -11
  202. package/dist/client/assets/use-mesh-topology-HLzZIgis.js +0 -1
  203. package/dist/client/assets/use-pending-read-BuJknrxG.js +0 -1
  204. package/dist/client/assets/use-pulse-freshness-BlD-dM_g.js +0 -1
  205. package/dist/client/assets/use-rename-session-D3MuyK-F.js +0 -1
  206. package/dist/client/assets/use-room-follow-claim-CyjhzbRJ.js +0 -1
  207. package/dist/client/assets/use-session-diagnostics-CfKdB2iY.js +0 -16
  208. package/dist/client/assets/use-unclaimed-chats-lqMhotUB.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-CXi0fvcM.js","assets/index-DMYBI16t.js","assets/index-Dgp1LmEk.css","assets/index-DR1JT9Uz.js","assets/BlintzCanvas-GgiCXV7C.css","assets/CanvasFileContent-ZZhdofR4.js","assets/rotate-cw-xvfipJLN.js","assets/McpAppFrame-B1ThSf2U.js","assets/CanvasModel3dContent-DMMMZh4o.js","assets/CanvasCsvContent-QhDSf8Pd.js","assets/index-CejezM4U.js"])))=>i.map(i=>d[i]);
2
- var Hn=Object.defineProperty;var vr=e=>{throw TypeError(e)};var Un=(e,r,t)=>r in e?Hn(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var ee=(e,r,t)=>Un(e,typeof r!="symbol"?r+"":r,t),Zn=(e,r,t)=>r.has(e)||vr("Cannot "+t);var gr=(e,r,t)=>r.has(e)?vr("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t);var xe=(e,r,t)=>(Zn(e,r,"access private method"),t);import{Y as St,m2 as Pt,z as ie,J as Q,G as br,D as Ge,F as et,m3 as Vn,m4 as Gn,m5 as $n,aH as je,Q as pe,r as g,bN as Kt,m6 as Jn,aD as K,i3 as Qn,j as h,gw as Kn,gx as In,es as ei,aa as It,I as ti,f9 as ri,B as mt,aF as qr,aG as Hr,C as ni,i7 as kt,m7 as ii,m8 as oi,m9 as ai,ma as si,mb as Ur,mc as Wt,md as gt,me as Zr,_ as wr,mf as li,A as yr,mg as ui,mh as ci,mi as te,mj as di,mk as Cr}from"./index-DMYBI16t.js";import{R as fi}from"./rotate-cw-xvfipJLN.js";import{M as pi}from"./McpAppFrame-B1ThSf2U.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-CUqethk_.js","assets/index-Bbffv0TQ.js","assets/index-_GlgFH88.css","assets/index-OxwtxTFo.js","assets/BlintzCanvas-GgiCXV7C.css","assets/CanvasFileContent-CX2VNF4o.js","assets/rotate-cw-BDweizfR.js","assets/McpAppFrame-Cl_2azg-.js","assets/CanvasModel3dContent-OprkQsgq.js","assets/CanvasCsvContent-DdbIUPMJ.js","assets/index-xfBvKz-h.js"])))=>i.map(i=>d[i]);
2
+ var Hn=Object.defineProperty;var vr=e=>{throw TypeError(e)};var Un=(e,r,t)=>r in e?Hn(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var ee=(e,r,t)=>Un(e,typeof r!="symbol"?r+"":r,t),Zn=(e,r,t)=>r.has(e)||vr("Cannot "+t);var gr=(e,r,t)=>r.has(e)?vr("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t);var xe=(e,r,t)=>(Zn(e,r,"access private method"),t);import{V as St,ky as kt,G as ie,O as Q,N as br,K as Ge,L as et,kz as Vn,kA as Gn,kB as $n,aI as je,a5 as pe,r as g,bO as Kt,kC as Jn,aE as K,hw as Qn,j as h,gy as Kn,gz as In,eu as ei,ab as It,I as ti,fb as ri,B as mt,aG as qr,aH as Hr,C as ni,hA as Pt,kD as ii,kE as oi,kF as ai,kG as si,kH as Ur,kI as Wt,kJ as gt,kK as Zr,_ as wr,kL as li,J as yr,kM as ui,kN as ci,kO as te,kP as di,kQ as Cr}from"./index-Bbffv0TQ.js";import{R as fi}from"./rotate-cw-BDweizfR.js";import{M as pi}from"./McpAppFrame-Cl_2azg-.js";/**
3
3
  * @license lucide-react v1.48.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -19,9 +19,9 @@ var Hn=Object.defineProperty;var vr=e=>{throw TypeError(e)};var Un=(e,r,t)=>r in
19
19
  *
20
20
  * This source code is licensed under the ISC license.
21
21
  * See the LICENSE file in the root directory of this source tree.
22
- */const Jr={name:"zoom-out",size:24,node:[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]};Jr.node;const vi=St(Jr),ze={pending:64,queueBytes:1048576,batchMs:300,frames:62,imageChars:9e5,imageEdge:1568,resourceErrors:1e4},bt=et().min(1).max(128),Le={bridgeGeneration:bt},gi=ie({...Le,__dorkosDevtools:Q("capture-result"),requestId:bt,dataUrl:et().max(9e5).optional(),error:et().max(2048).optional()}),bi=Vn.omit({hostOutcome:!0}).extend({...Le,__dorkosDevtools:Q("act-result"),dataUrl:et().max(9e5).optional()}),wi=Gn.extend({status:Ge().int().min(0).max(599),durationMs:Ge().min(0),responseSize:Ge().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),timestamp:Ge().min(0)}),yi=$n.refine(e=>e.timestamp>=0),Ci=Pt("__dorkosDevtools",[ie({__dorkosDevtools:Q("hello"),pageInstanceId:bt,bridgeVersion:Q(2)}),ie({...Le,__dorkosDevtools:Q("ready"),pageInstanceId:bt}),ie({...Le,__dorkosDevtools:Q("navigated")}),ie({...Le,__dorkosDevtools:Q("resource-error")}),ie({...Le,__dorkosDevtools:Q("batch"),seq:Ge().int().min(0).max(Number.MAX_SAFE_INTEGER),console:br(yi).max(500),network:br(wi).max(200)}),gi,bi]);function Si(e){const r=new Set;let t=0,n=0;const i=s=>(n+=s)<=16384;function o(s){if(!i(2))return!1;for(let l=0;l<s.length;l++){const c=s.charCodeAt(l);if(c>=55296&&c<=56319&&l+1<s.length&&s.charCodeAt(l+1)>=56320&&s.charCodeAt(l+1)<=57343){if(!i(2))return!1;l++;continue}const u=c===34||c===92||[8,9,10,12,13].includes(c)?2:c<32||c>=55296&&c<=57343?6:1;if(!i(u))return!1}return!0}function a(s,l){if(++t>2048||l>8)return!1;if(s===null)return i(4);if(typeof s=="boolean")return i(s?4:5);if(typeof s=="string")return o(s);if(typeof s=="number")return Number.isFinite(s)&&i(String(s).length);if(typeof s!="object"||r.has(s))return!1;const c=Object.getPrototypeOf(s);if(c!==Object.prototype&&c!==null&&c!==Array.prototype)return!1;const u=Array.isArray(s);if(u&&s.length>2048||Object.getOwnPropertySymbols(s).length||!i(2))return!1;r.add(s);let d=0;for(const f in s){if(!Object.prototype.hasOwnProperty.call(s,f))continue;if(++d>2048||u&&(!/^\d+$/.test(f)||Number(f)>=s.length))return!1;const p=Object.getOwnPropertyDescriptor(s,f);if(["__proto__","constructor","prototype"].includes(f)||!("value"in p)||!p.enumerable||d>1&&!i(1)||!u&&(!o(f)||!i(1))||!a(p.value,l+1))return!1}return r.delete(s),!u||d===s.length}try{return a(e,0)}catch{return!1}}function Pi(e){try{if(!e||typeof e!="object")return null;const r=e;if(r.__dorkosDevtools==="capture-result"&&r.dataUrl===void 0&&r.error===void 0)return null;if(r.__dorkosDevtools==="batch"){if(!Array.isArray(r.console)||r.console.length>500||!Array.isArray(r.network)||r.network.length>200)return null;for(const i of r.console){if(!i||typeof i!="object")return null;const o=i.args;if(o!==void 0&&(!Array.isArray(o)||o.length>50||!Si(o)))return null}}const t=Ci.safeParse(e);if(!t.success)return null;const n=t.data;return"dataUrl"in n&&n.dataUrl!==void 0&&!Qr(n.dataUrl)?null:n}catch{return null}}function Qr(e){if(e.length>9e5||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(e))return null;try{const r=atob(e.slice(e.indexOf(",")+1));if(r.length<24||r.slice(0,8)!==`‰PNG\r
22
+ */const Jr={name:"zoom-out",size:24,node:[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]};Jr.node;const vi=St(Jr),ze={pending:64,queueBytes:1048576,batchMs:300,frames:62,imageChars:9e5,imageEdge:1568,resourceErrors:1e4},bt=et().min(1).max(128),Le={bridgeGeneration:bt},gi=ie({...Le,__dorkosDevtools:Q("capture-result"),requestId:bt,dataUrl:et().max(9e5).optional(),error:et().max(2048).optional()}),bi=Vn.omit({hostOutcome:!0}).extend({...Le,__dorkosDevtools:Q("act-result"),dataUrl:et().max(9e5).optional()}),wi=Gn.extend({status:Ge().int().min(0).max(599),durationMs:Ge().min(0),responseSize:Ge().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),timestamp:Ge().min(0)}),yi=$n.refine(e=>e.timestamp>=0),Ci=kt("__dorkosDevtools",[ie({__dorkosDevtools:Q("hello"),pageInstanceId:bt,bridgeVersion:Q(2)}),ie({...Le,__dorkosDevtools:Q("ready"),pageInstanceId:bt}),ie({...Le,__dorkosDevtools:Q("navigated")}),ie({...Le,__dorkosDevtools:Q("resource-error")}),ie({...Le,__dorkosDevtools:Q("batch"),seq:Ge().int().min(0).max(Number.MAX_SAFE_INTEGER),console:br(yi).max(500),network:br(wi).max(200)}),gi,bi]);function Si(e){const r=new Set;let t=0,n=0;const i=s=>(n+=s)<=16384;function o(s){if(!i(2))return!1;for(let l=0;l<s.length;l++){const c=s.charCodeAt(l);if(c>=55296&&c<=56319&&l+1<s.length&&s.charCodeAt(l+1)>=56320&&s.charCodeAt(l+1)<=57343){if(!i(2))return!1;l++;continue}const u=c===34||c===92||[8,9,10,12,13].includes(c)?2:c<32||c>=55296&&c<=57343?6:1;if(!i(u))return!1}return!0}function a(s,l){if(++t>2048||l>8)return!1;if(s===null)return i(4);if(typeof s=="boolean")return i(s?4:5);if(typeof s=="string")return o(s);if(typeof s=="number")return Number.isFinite(s)&&i(String(s).length);if(typeof s!="object"||r.has(s))return!1;const c=Object.getPrototypeOf(s);if(c!==Object.prototype&&c!==null&&c!==Array.prototype)return!1;const u=Array.isArray(s);if(u&&s.length>2048||Object.getOwnPropertySymbols(s).length||!i(2))return!1;r.add(s);let d=0;for(const f in s){if(!Object.prototype.hasOwnProperty.call(s,f))continue;if(++d>2048||u&&(!/^\d+$/.test(f)||Number(f)>=s.length))return!1;const p=Object.getOwnPropertyDescriptor(s,f);if(["__proto__","constructor","prototype"].includes(f)||!("value"in p)||!p.enumerable||d>1&&!i(1)||!u&&(!o(f)||!i(1))||!a(p.value,l+1))return!1}return r.delete(s),!u||d===s.length}try{return a(e,0)}catch{return!1}}function ki(e){try{if(!e||typeof e!="object")return null;const r=e;if(r.__dorkosDevtools==="capture-result"&&r.dataUrl===void 0&&r.error===void 0)return null;if(r.__dorkosDevtools==="batch"){if(!Array.isArray(r.console)||r.console.length>500||!Array.isArray(r.network)||r.network.length>200)return null;for(const i of r.console){if(!i||typeof i!="object")return null;const o=i.args;if(o!==void 0&&(!Array.isArray(o)||o.length>50||!Si(o)))return null}}const t=Ci.safeParse(e);if(!t.success)return null;const n=t.data;return"dataUrl"in n&&n.dataUrl!==void 0&&!Qr(n.dataUrl)?null:n}catch{return null}}function Qr(e){if(e.length>9e5||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(e))return null;try{const r=atob(e.slice(e.indexOf(",")+1));if(r.length<24||r.slice(0,8)!==`‰PNG\r
23
23
  
24
- `||r.slice(12,16)!=="IHDR")return null;const t=o=>r.charCodeAt(o)*2**24+(r.charCodeAt(o+1)<<16)+(r.charCodeAt(o+2)<<8)+r.charCodeAt(o+3),n=t(16),i=t(20);return n>0&&i>0&&n<=1568&&i<=1568?{width:n,height:i}:null}catch{return null}}let jt=null;async function Sr(){return jt===null&&(jt=(await je(()=>import("./html-to-image-cl8bZGTj.js"),[])).default),jt}let At=null;async function ki(){if(At===null){const e=await je(()=>import("./gifenc.esm-sOOlYEo8.js"),[]);At={GIFEncoder:e.GIFEncoder,quantize:e.quantize,applyPalette:e.applyPalette}}return At}async function Pr(e,r,t=()=>{}){if(e.length===0)return{ok:!1,error:"The recording has no frames in it."};t();const{GIFEncoder:n,quantize:i,applyPalette:o}=await ki();t();const a=e[0],s=e[e.length-1],l=new Uint8ClampedArray(a.data.length+s.data.length);l.set(a.data,0),l.set(s.data,a.data.length);const c=i(l,256),u=n();for(let f=0;f<e.length;f++){t();const p=e[f];if(u.writeFrame(o(p.data,c),p.width,p.height,{...f===0?{palette:c,repeat:0}:{},delay:r.frameMs}),u.bytesView().byteLength>r.maxBytes)return{ok:!1,error:`The recording came out bigger than ${Math.round(r.maxBytes/1024/1024)} MB, so it was not saved.`}}u.finish();const d=u.bytes();return d.byteLength>r.maxBytes?{ok:!1,error:`The recording came out bigger than ${Math.round(r.maxBytes/1024/1024)} MB, so it was not saved.`}:{ok:!0,bytes:d}}async function Ei(e,r,t=()=>{}){const n=[],i=document.createElement("canvas");let o=0,a=0;try{for(let s=0;s<Math.min(e.length,62);s++){t();const l=e[s];if(!Qr(l)){e[s]="";continue}const c=await Oi(l);e[s]="";try{if(t(),!c)continue;if(!o){const f=Math.min(1,Math.min(800,r)/Math.max(c.width,c.height,1));o=Math.max(1,Math.round(c.width*f)),a=Math.max(1,Math.round(c.height*f)),i.width=o,i.height=a}const u=i.getContext("2d",{willReadFrequently:!0});if(!u)return[];u.fillStyle="#ffffff",u.fillRect(0,0,o,a);const d=Math.min(o/c.width,a/c.height);u.drawImage(c,0,0,Math.round(c.width*d),Math.round(c.height*d)),t(),n.push({data:u.getImageData(0,0,o,a).data,width:o,height:a})}finally{c&&(c.src="")}}return n}catch(s){throw n.length=0,s}finally{e.length=0,i.width=0,i.height=0}}function Ti(e,r=()=>{}){const t=document.createElement("canvas"),n=document.createElement("canvas");try{for(let i=0;i<e.length;i++){r();const o=e[i];n.width=o.width,n.height=o.height,t.width=Math.max(1,Math.round(o.width/2)),t.height=Math.max(1,Math.round(o.height/2));const a=n.getContext("2d"),s=t.getContext("2d",{willReadFrequently:!0});if(!a||!s)throw new Error("Canvas pixels are unavailable");a.putImageData(new ImageData(new Uint8ClampedArray(o.data),o.width,o.height),0,0),s.drawImage(n,0,0,t.width,t.height),e[i]={data:s.getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}}finally{n.width=n.height=t.width=t.height=0}}function Oi(e){return new Promise(r=>{const t=new Image;t.onload=()=>{t.onload=t.onerror=null,r(t)},t.onerror=()=>{t.onload=t.onerror=null,t.src="",r(null)},t.src=e})}function kr(e,r,t){const n=t.slice().buffer;return{name:e,type:r,size:t.byteLength,arrayBuffer:async()=>n}}function _i(e){const r=atob(e.slice(e.indexOf(",")+1));return Uint8Array.from(r,t=>t.charCodeAt(0))}const ji=8e3;function Ai(e){const r=pe(),t=g.useRef(r);g.useLayoutEffect(()=>{t.current=r});const[n]=Kt(),[i,o]=g.useState(0),a=g.useRef(null),s=g.useRef(new Map),l=g.useRef(null),c=g.useRef({console:[],network:[],entryBytes:0,overheadBytes:0}),u=g.useRef(null),d=g.useRef(-1),f=g.useRef(null),p=g.useRef(null),v=g.useRef(!1),m=g.useRef(-1/0),P=g.useRef(!1),w=g.useRef(null),A=g.useRef(0),C=g.useRef(null),O=g.useRef(null),z=g.useRef(!1),Y=g.useRef(null),N=g.useRef({...e,sessionId:n}),M=g.useRef(Promise.resolve()),W=g.useRef(()=>{}),q=g.useRef({initialize:R,retire:E,consume:we,register:se,eligiblePending:le,refuseRequest:G,live:Z,captureFrame:He,valid:Be,reportRecordingStart:Xe,cancelReservation:We,finish:ct});g.useLayoutEffect(()=>{q.current={initialize:R,retire:E,consume:we,register:se,eligiblePending:le,refuseRequest:G,live:Z,captureFrame:He,valid:Be,reportRecordingStart:Xe,cancelReservation:We,finish:ct}});const B=k=>Y.current===k||K.getState().openDocuments.some(b=>b.id===k&&b.openedHere);function y(k,{active:b,activation:T=!1,keepalive:S=!1,reset:x=!1}){if(!k.sessionId)return;const $={documentId:k.documentId,logicalUrl:k.logicalUrl,bridgeGeneration:k.generation,seq:Math.max(0,d.current),console:[],network:[],active:b,activation:T,instrumented:k.ready&&!k.retired,...x?{reset:!0}:{}};M.current=M.current.then(()=>t.current.ingestDevtoolsCapture(k.sessionId,$,S?{keepalive:!0}:void 0)).catch(()=>{})}function E(){var T;const k=a.current;k&&(k.retired=!0),a.current=null,u.current!==null&&clearTimeout(u.current),u.current=null,l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0},d.current=-1,m.current=-1/0,P.current=!1;for(const[S,x]of s.current)x.life.sessionId&&x.deadline>Date.now()&&x.kind!=="frame"&&G(S,x.kind,x.life,"The frame changed while this request was pending."),clearTimeout(x.timer),(T=x.resolve)==null||T.call(x,null);s.current.clear(),k&&y(k,{active:!1});const b=w.current;b&&(clearTimeout(b.reservationTimer),b.cancelled=!0,b.abort.abort(),b.frames.length=0,b.finishing||(b.drawn.length=0,w.current=null)),C.current!==null&&cancelAnimationFrame(C.current),C.current=null,A.current=0,o(0)}function R({loadActivation:k,reset:b=!1}={}){var H,ne;const T=N.current,S=(H=T.iframeRef.current)==null?void 0:H.contentWindow;if(v.current||!S||!T.bridgeEligibility||!T.resolvedSource)return;const x={generation:crypto.randomUUID(),frame:S,sessionId:T.sessionId,documentId:T.documentId,logicalUrl:T.logicalUrl,source:T.resolvedSource,origin:T.bridgeEligibility==="served-document"?"null":T.previewOrigin,ready:!1,activation:!1,retired:!1};a.current=x;const $=k??(z.current||O.current!==x.documentId&&B(x.documentId));x.activation=$,z.current=!1,O.current=x.documentId,y(x,{active:!0,activation:$,reset:b}),((ne=f.current)==null?void 0:ne.frame)===S&&f.current.source===T.resolvedSource&&f.current.reload===T.reloadNonce&&f.current.documentId===T.documentId&&f.current.logicalUrl===T.logicalUrl&&S.postMessage({__dorkosDevtools:"init",bridgeGeneration:x.generation},"*")}g.useLayoutEffect(()=>{var S;N.current={...e,sessionId:n};const k={frame:(S=e.iframeRef.current)==null?void 0:S.contentWindow,sessionId:n,documentId:e.documentId,logicalUrl:e.logicalUrl,source:e.resolvedSource,eligibility:e.bridgeEligibility,origin:e.previewOrigin,reload:e.reloadNonce},b=p.current;if(!b||Object.keys(k).some(x=>k[x]!==b[x])){const x=!b||b.frame!==k.frame||b.documentId!==k.documentId||b.logicalUrl!==k.logicalUrl||b.source!==k.source||b.reload!==k.reload;p.current=k,v.current=!1,E(),R({reset:x})}});const _=g.useCallback(()=>{var $,H,ne;const{initialize:k,retire:b}=q.current,T=N.current,S=($=T.iframeRef.current)==null?void 0:$.contentWindow,x=(H=a.current)!=null&&H.ready?!1:(ne=a.current)==null?void 0:ne.activation;S&&T.resolvedSource&&(f.current={frame:S,source:T.resolvedSource,reload:T.reloadNonce,documentId:T.documentId,logicalUrl:T.logicalUrl}),v.current=!1,b(),k({loadActivation:x,reset:!0})},[]),D=g.useCallback(()=>{const k=a.current;z.current=!0,Y.current=N.current.documentId,k&&W.current({active:!0,activation:!0})},[]);g.useLayoutEffect(()=>{W.current=k=>{a.current&&y(a.current,k)}});function Z(k){return a.current===k&&!k.retired}function G(k,b,T,S){if(!T.sessionId)return;const x={requestId:k,bridgeGeneration:T.generation,documentId:T.documentId,hostOutcome:"host",error:S};b==="action"?t.current.postDevtoolsAction(T.sessionId,{...x,ok:!1}).catch(()=>{}):t.current.ingestDevtoolsCapture(T.sessionId,{...x,logicalUrl:T.logicalUrl,seq:Math.max(0,d.current),console:[],network:[],screenshot:{requestId:k,error:S}}).catch(()=>{})}function se(k,b,T,{capture:S=!1,resolve:x,timeoutMs:$=8e3}={}){if(s.current.size>=ze.pending||s.current.has(k))return null;const H=setTimeout(()=>me(k,ne),$),ne={kind:b,life:T,capture:S,deadline:Date.now()+$,timer:H,resolve:x};return s.current.set(k,ne),ne}function me(k,b){var T;s.current.get(k)===b&&(s.current.delete(k),clearTimeout(b.timer),(T=b.resolve)==null||T.call(b,null))}function le(k,b,T){return s.current.get(k)!==b||b.life!==T||!Z(T)?!1:Date.now()>=b.deadline?(me(k,b),!1):!0}function we(k,b,T){const S=s.current.get(k);return!S||S.life!==T||S.kind!==b&&!(b==="capture"&&S.kind==="frame")||!le(k,S,T)?null:(s.current.delete(k),clearTimeout(S.timer),S)}g.useEffect(()=>{const{initialize:k,retire:b,consume:T}=q.current;function S(){u.current=null;const he=l.current;l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0};const j=a.current;he&&j&&!j.retired&&j.sessionId&&he.bridgeGeneration===j.generation&&t.current.ingestDevtoolsCapture(j.sessionId,he)}function x(he){var cr,dr,fr,pr;const j=a.current;if(!j||j.retired||he.source!==j.frame||he.origin!==j.origin||((cr=f.current)==null?void 0:cr.frame)!==j.frame||f.current.source!==j.source||f.current.reload!==N.current.reloadNonce||f.current.documentId!==j.documentId||f.current.logicalUrl!==j.logicalUrl)return;const X=he.data;if(!X||typeof X!="object"||typeof X.__dorkosDevtools!="string"||!["hello","ready","navigated","resource-error","batch","capture-result","act-result"].includes(X.__dorkosDevtools)||X.__dorkosDevtools!=="hello"&&X.bridgeGeneration!==j.generation)return;const oe=X.__dorkosDevtools==="batch";if(oe){if(!j.ready||!j.sessionId||X.bridgeGeneration!==j.generation||!Number.isSafeInteger(X.seq)||X.seq<0||X.seq<=d.current)return;const V=Date.now();if(V-m.current<ze.batchMs){l.current?l.current.dropped=!0:P.current=!0;return}m.current=V}const U=Pi(X);if(!U){oe&&(P.current=!0);return}if(U.__dorkosDevtools==="hello"){j.frame.postMessage({__dorkosDevtools:"init",bridgeGeneration:j.generation},"*");return}if(U.bridgeGeneration!==j.generation)return;if(U.__dorkosDevtools==="ready"){j.ready||(j.ready=!0,j.activation=!1,y(j,{active:!0}));return}if(!j.ready)return;if(U.__dorkosDevtools==="navigated"){v.current=!0,b();return}if(U.__dorkosDevtools==="resource-error"){A.current=Math.min(ze.resourceErrors,A.current+1),C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null,Z(j)&&o(A.current)}));return}if(!j.sessionId)return;if(U.__dorkosDevtools==="batch"){if(U.seq<=d.current)return;d.current=U.seq;const V=l.current??{documentId:j.documentId,logicalUrl:j.logicalUrl,bridgeGeneration:j.generation,seq:U.seq,console:[],network:[]};V.seq=U.seq,P.current&&(V.dropped=!0),P.current=!1;const ke=c.current,hr=new TextEncoder;if(l.current||(ke.overheadBytes=hr.encode(JSON.stringify({...V,seq:Number.MAX_SAFE_INTEGER,dropped:!0,console:[],network:[]})).length),ke.overheadBytes>ze.queueBytes){l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0},P.current=!0;return}for(const[Ze,Fn]of[["console",U.console],["network",U.network]])for(const qn of Fn){const mr=hr.encode(JSON.stringify(qn)).length;ke[Ze].push(mr),ke.entryBytes+=mr}V.console.push(...U.console),V.network.push(...U.network);const Ln=()=>ke.overheadBytes+ke.entryBytes+Math.max(0,V.console.length-1)+Math.max(0,V.network.length-1);for(;V.console.length>500||V.network.length>200||Ln()>ze.queueBytes;){V.dropped=!0;const Ze=(((dr=V.console[0])==null?void 0:dr.timestamp)??1/0)<=(((fr=V.network[0])==null?void 0:fr.timestamp)??1/0)?"console":"network";if(!V[Ze].length)break;V[Ze].shift(),ke.entryBytes-=ke[Ze].shift()}l.current=V,u.current===null&&(u.current=setTimeout(S,ze.batchMs));return}if(U.__dorkosDevtools==="capture-result"){const V=T(U.requestId,"capture",j);if(!V)return;if(V.kind==="frame"){(pr=V.resolve)==null||pr.call(V,U.dataUrl??null);return}t.current.ingestDevtoolsCapture(j.sessionId,{bridgeGeneration:j.generation,documentId:j.documentId,logicalUrl:j.logicalUrl,seq:Math.max(0,d.current),console:[],network:[],hostOutcome:"page-reported",screenshot:{requestId:U.requestId,dataUrl:U.dataUrl,error:U.error}});return}const Ue=T(U.requestId,"action",j);if(!Ue)return;const Re=w.current,ur=Ue.capture&&U.dataUrl!==void 0&&Re!==null&&Re.life===j&&Re.activated&&!Re.finishing&&!Re.cancelled&&Re.frames.length<61;ur&&Re.frames.push(U.dataUrl);const{__dorkosDevtools:pl,dataUrl:hl,...Bn}=U;t.current.postDevtoolsAction(j.sessionId,{...Bn,hostOutcome:"page-reported",documentId:j.documentId,captured:ur||void 0})}window.addEventListener("message",x);const $=setInterval(()=>W.current({active:!0}),15e3),H=()=>{a.current||k(),W.current({active:!0,activation:!0})},ne=()=>{W.current({active:!1,keepalive:!0}),b()},ae=()=>{document.visibilityState==="visible"&&H()};return window.addEventListener("focus",H),window.addEventListener("pagehide",ne),window.addEventListener("pageshow",H),document.addEventListener("visibilitychange",ae),()=>{window.removeEventListener("message",x),clearInterval($),window.removeEventListener("focus",H),window.removeEventListener("pagehide",ne),window.removeEventListener("pageshow",H),document.removeEventListener("visibilitychange",ae),b()}},[]),g.useEffect(()=>Jn.subscribeSessionEvent((k,b)=>{if(b.type!=="devtools_capture_request"&&b.type!=="devtools_action_request"&&b.type!=="devtools_recording_request")return;const{register:T,eligiblePending:S,refuseRequest:x,captureFrame:$,valid:H,finish:ne,reportRecordingStart:ae,cancelReservation:he}=q.current,j=a.current;if(!(!(j!=null&&j.ready)||!j.sessionId||j.retired||b.targetClientId!==t.current.clientId||b.documentId!==j.documentId||b.bridgeGeneration!==j.generation)){if(b.type==="devtools_capture_request"||b.type==="devtools_action_request"){const X=b.type==="devtools_action_request",oe=T(b.requestId,X?"action":"capture",j,{capture:X&&!!b.capture,timeoutMs:X&&b.command.action==="wait_for"?Math.min(1e4,b.command.timeoutMs)+2e3:8e3});if(!oe){s.current.has(b.requestId)||x(b.requestId,X?"action":"capture",j,"Too many browser requests are waiting. Try again when one finishes.");return}const U=Ue=>{S(b.requestId,oe,j)&&j.frame.postMessage(X?{__dorkosDevtools:"act-request",bridgeGeneration:j.generation,requestId:b.requestId,documentId:j.documentId,command:b.command,...b.capture?{capture:!0,lib:Ue}:{}}:{__dorkosDevtools:"capture-request",bridgeGeneration:j.generation,requestId:b.requestId,lib:Ue},"*")};!X||b.capture?Sr().then(U,()=>U()):U()}if(b.type==="devtools_recording_request"){if(b.action==="cancel-start"){he(b.recordingId,b.requestId,j);return}if(b.action==="confirm-start"){const X=w.current;if(!X||X.id!==b.recordingId||X.startRequestId!==b.requestId||X.life!==j||X.finishing||!H(X))return;if(!X.activated){if(performance.now()>=X.reservationDeadline){he(X.id,X.startRequestId,j),ae(b,j,{phase:"started",ok:!1,error:"This recording reservation expired before capture could start."});return}clearTimeout(X.reservationTimer),X.activated=!0,X.startedAt=Date.now(),$(j).then(oe=>{oe&&H(X)&&X.frames.push(oe)})}ae(b,j,{phase:"started",ok:!0});return}if(b.action==="start"){const X=b.reservationTimeoutMs;if(!Number.isSafeInteger(X)||!X||X<1||X>ji){ae(b,j,{phase:"reserved",ok:!1,error:"This recording request has no valid reservation timeout."});return}if(w.current){ae(b,j,{phase:"reserved",ok:!1,error:"Another recording in this window is still running or being saved. Wait for it to finish, then start again."});return}const oe={id:b.recordingId,startRequestId:b.requestId,activated:!1,reservationDeadline:performance.now()+X,life:j,startedAt:Date.now(),frames:[],drawn:[],finishing:!1,cancelled:!1,abort:new AbortController};w.current=oe,oe.reservationTimer=setTimeout(()=>{w.current===oe&&!oe.activated&&he(oe.id,oe.startRequestId,j)},X),ae(b,j,{phase:"reserved",ok:!0})}else ne(b.requestId,b.recordingId,j)}}}),[]);function Xe(k,b,T){!Z(b)||!b.sessionId||t.current.ingestDevtoolsCapture(b.sessionId,{hostOutcome:"host",documentId:b.documentId,bridgeGeneration:b.generation,seq:0,console:[],network:[],recordingStart:{...T,requestId:k.requestId,recordingId:k.recordingId}}).catch(()=>{})}function We(k,b,T){var x;const S=w.current;if(!(!S||S.id!==k||S.startRequestId!==b||S.life!==T||S.finishing)){clearTimeout(S.reservationTimer),S.cancelled=!0,S.abort.abort(),S.frames.length=0,S.drawn.length=0;for(const[$,H]of s.current)H.life===T&&H.kind==="frame"&&(clearTimeout(H.timer),(x=H.resolve)==null||x.call(H,null),s.current.delete($));w.current=null}}function Be(k){return w.current===k&&!k.cancelled&&Z(k.life)}function He(k){const b=`frame-${crypto.randomUUID()}`;return new Promise(T=>{const S=se(b,"frame",k,{resolve:T});if(!S){T(null);return}Sr().then(x=>{le(b,S,k)&&k.frame.postMessage({__dorkosDevtools:"capture-request",bridgeGeneration:k.generation,requestId:b,lib:x},"*")},()=>{me(b,S)})})}async function ct(k,b,T){const S=w.current;if(!S||!S.activated||S.id!==b||S.life!==T){Z(T)&&await t.current.uploadDevtoolsRecording(T.sessionId,{requestId:k,bridgeGeneration:T.generation,documentId:T.documentId,hostOutcome:"host",error:"The window showing that page stopped recording before it could be saved."}).catch(()=>{});return}if(S.finishing)return;S.finishing=!0;const x=()=>{if(!Be(S))throw new Error("retired")},$={requestId:k,bridgeGeneration:T.generation,documentId:T.documentId};try{const H=await He(T);x(),H&&S.frames.length<ze.frames&&S.frames.push(H);const ne=S.frames.length?_i(S.frames[S.frames.length-1]):new Uint8Array;S.drawn=await Ei(S.frames,800,x),x();let ae=await Pr(S.drawn,{frameMs:500,maxBytes:8*1024*1024},x);if(x(),!ae.ok&&S.drawn.length&&(Ti(S.drawn,x),ae=await Pr(S.drawn,{frameMs:500,maxBytes:8*1024*1024},x),x()),!ae.ok){await t.current.uploadDevtoolsRecording(T.sessionId,{...$,hostOutcome:"host",error:ae.error},{signal:S.abort.signal}),x();return}x(),await t.current.uploadDevtoolsRecording(T.sessionId,{...$,frames:S.drawn.length,durationMs:Date.now()-S.startedAt,recording:kr(`${b}.gif`,"image/gif",ae.bytes),keyframe:kr(`${b}.png`,"image/png",ne)},{signal:S.abort.signal}),x()}catch{Be(S)&&await t.current.uploadDevtoolsRecording(T.sessionId,{...$,hostOutcome:"host",error:"This window could not turn that recording into a file."},{signal:S.abort.signal}).catch(()=>{})}finally{S.frames.length=0,S.drawn.length=0,w.current===S&&(w.current=null)}}return{resourceErrorCount:i,notePersonNavigated:D,noteFrameLoaded:_}}const Ri=15e3;function xi(e){const r=e instanceof Error?e.message.trim():"";return r.length>0?r:"Couldn’t reach DorkOS. Check your network and try again."}function zi(e){const r=pe();return{open:g.useCallback(async t=>{await r.openRoomCanvasDocument(e,t)},[r,e]),update:g.useCallback(async(t,n)=>{await r.updateRoomCanvasDocument(e,t,{content:n})},[r,e]),pin:g.useCallback(async(t,n)=>{await r.updateRoomCanvasDocument(e,t,{pinned:n})},[r,e]),close:g.useCallback(async t=>{await r.closeRoomCanvasDocument(e,t)},[r,e])}}function Di(e,r){const t=pe(),n=K(i=>i.setRoomCanvasEditing);g.useEffect(()=>{if(n(e,r),r===null)return;const i=a=>{t.setRoomCanvasEditing(e,r,a).catch(s=>{console.warn("[room-canvas] edit lock failed",{roomId:e,documentId:r,err:s})})};i(!0);const o=setInterval(()=>i(!0),Ri);return()=>{clearInterval(o),i(!1),n(e,null)}},[t,e,r,n])}const Ni=400;function yl(e,r){const t=pe(),n=K(i=>i.roomCanvasPresenceEpoch[e]??0);g.useEffect(()=>{const i=s=>{t.setRoomCanvasViewing(e,s).catch(l=>{console.warn("[room-canvas] could not say where we are looking",{roomId:e,err:l})})};let o=!1;const a=setTimeout(()=>{o=!0,i(r)},Ni);return()=>{clearTimeout(a),o&&i(null)}},[t,e,r,n])}const Mi="allow-scripts allow-forms allow-popups allow-modals",Rt="allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-downloads",Yi=new Set(["javascript:","data:","blob:"]),Xi=new Set(["localhost","127.0.0.1","0.0.0.0","[::1]","::1"]);function er(e){return Xi.has(e)||e.endsWith(".localhost")}function Wi(e){return er(e)?"direct":"server"}function Bi(e,r){let t;try{t=new URL(e)}catch{return null}const n=t.searchParams.get(Er),i=new URL(t.origin),o=r.indexOf("?");return i.pathname=(o===-1?r:r.slice(0,o))||"/",i.search=o===-1?"":r.slice(o),n!==null&&i.searchParams.set(Er,n),i.toString()}const Er="__dorkos_preview",Li="/__dorkos_preview/health";function Fi(e){return e==="https:"?443:80}function Kr(e){let r;try{r=new URL(e)}catch{return{mode:"serve",path:e}}if(Yi.has(r.protocol))return{mode:"blocked"};if(r.protocol==="file:")return{mode:"serve",path:decodeURIComponent(r.pathname)};if(r.protocol==="http:"||r.protocol==="https:"){if(er(r.hostname)){const t=r.port?Number(r.port):Fi(r.protocol);return{mode:"proxy",hostname:r.hostname,port:t,path:`${r.pathname}${r.search}`}}return{mode:"external",url:e}}return{mode:"blocked"}}function qi(e){const r=e.trim();if(r===""||/^[a-z][a-z0-9+.-]*:\/\//i.test(r)||r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;const t=r.split("/")[0];if(r.includes("/")&&!t.includes(".")&&!t.includes(":"))return r;const i=t.split(":")[0];return`${er(i)?"http":"https"}://${r}`}function Hi(e){const r=Kr(e);if(r.mode==="serve")return{kind:"local",path:r.path};if(r.mode==="blocked")return{kind:"raw",text:e};try{const t=new URL(e),n=t.host.replace(/^www\./,""),i=t.pathname==="/"&&t.search===""&&t.hash===""?"":`${t.pathname}${t.search}${t.hash}`;return{kind:"url",host:n,rest:i}}catch{return{kind:"raw",text:e}}}const Ui=2e3;async function Tr(e,r=globalThis.fetch,t=Ui){const n=new AbortController,i=setTimeout(()=>n.abort(),t);try{return await r(e,{mode:"no-cors",cache:"no-store",signal:n.signal}),!0}catch{return n.signal.aborted}finally{clearTimeout(i)}}function Zi({target:e,currentUrl:r,strategy:t,cwd:n,reloadNonce:i}){const o=JSON.stringify([r,t,n,i]),[a,s]=g.useState(null),[l,c]=g.useState(null),[u,d]=g.useState(null),f=pe(),p=g.useRef(f);return g.useEffect(()=>{p.current=f}),g.useEffect(()=>{const v=p.current;let m=!1;const P=O=>{s(o),c(O)};async function w(O){if(n===null){d({kind:"no-session"});return}try{const z=await v.createServeUrl(n,O);if(m)return;z===null?d({kind:"unsupported"}):P({src:z,sandbox:Mi,previewOrigin:null,bridgeEligibility:"served-document"})}catch{m||d({kind:"failed"})}}async function A(O,z){let Y;try{const M=await v.probeLoopbackPort(O);Y=M===null?"unknown":M.listening}catch{Y="unknown"}if(m)return;let N=null;if(Y!==!1){let M=null;try{M=await v.createProxyUrl(O)}catch{if(m)return;N={kind:"failed"}}if(m)return;if((M==null?void 0:M.unavailable)==="tunnel"){d({kind:"tunnel"});return}if((M==null?void 0:M.unavailable)==="no-port"&&(N={kind:"no-port"}),M!=null&&M.url){const W=new URL(M.url);if(await Tr(`${W.origin}${Li}`)){if(m)return;const q=Bi(M.url,z);if(q!==null){P({src:q,sandbox:Rt,previewOrigin:W.origin,bridgeEligibility:"preview-listener"});return}}if(m)return;N={kind:"origin-unreachable",host:W.hostname,listenPort:W.port}}}if(t==="direct"&&await Tr(r)){if(m)return;P({src:r,sandbox:Rt,previewOrigin:null,bridgeEligibility:null});return}m||d(N??{kind:"no-upstream"})}async function C(){if(d(null),c(null),e.mode!=="blocked"){if(e.mode==="external"){P({src:e.url,sandbox:Rt,previewOrigin:null,bridgeEligibility:null});return}return e.mode==="serve"?w(e.path):A(e.port,e.path)}}return C(),()=>{m=!0}},[e,r,t,n,i,o]),{resolved:a===o?l:null,resolveError:u}}const Vi=1e4;function Gi(e,r){if(e&&e.contentUrl===r&&e.stack.length>0){const t=Math.min(Math.max(e.cursor,0),e.stack.length-1);return{stack:e.stack,cursor:t}}return{stack:[r],cursor:0}}function $i({documentId:e,content:r}){const t=K(_=>_.selectedCwd),n=K(_=>_.writeBrowserHistory),[i]=g.useState(()=>Gi(K.getState().browserHistories[e],r.url)),[o,a]=g.useState(i.stack),[s,l]=g.useState(i.cursor),[c,u]=g.useState(0);g.useEffect(()=>{n(e,{contentUrl:r.url,stack:o,cursor:s})},[e,r.url,o,s,n]);const d=o[s],f=g.useMemo(()=>Kr(d),[d]),p=g.useMemo(()=>f.mode==="proxy"?Wi(window.location.hostname):null,[f]),v=g.useRef(null),{resolved:m,resolveError:P}=Zi({target:f,currentUrl:d,strategy:p,cwd:t,reloadNonce:c}),{resourceErrorCount:w,notePersonNavigated:A,noteFrameLoaded:C}=Ai({iframeRef:v,documentId:e,logicalUrl:d,reloadNonce:c,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),O=K(_=>_.roomCanvasLiveRoomId),{open:z}=zi(O??""),[Y,N]=g.useState(null),M=g.useCallback(_=>{a(D=>[...D.slice(0,s+1),_]),l(D=>D+1)},[s]),W=Qn(O),q=K(_=>O?_.roomCanvasEditing[O]??null:null);g.useEffect(()=>{if(W===null||q!==null||W.documentId!==e)return;const _=W.url;_===void 0||_===d||M(_)},[W,q,e,d,M]);const B=s>0,y=s<o.length-1,E=g.useCallback(_=>{const D=qi(_);if(!D||D===d){A(),u(Z=>Z+1);return}if(O){N(null),z({type:"browser",url:D}).catch(Z=>{N({url:D,message:xi(Z)})});return}A(),M(D)},[d,M,O,z,A]),R=()=>ri(d);return h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsxs("div",{className:"border-border/60 flex h-9 items-center gap-1 border-b px-2",children:[h.jsx(dt,{label:"Back",disabled:!B,onClick:()=>l(_=>_-1),children:h.jsx(Kn,{className:"size-4"})}),h.jsx(dt,{label:"Forward",disabled:!y,onClick:()=>l(_=>_+1),children:h.jsx(In,{className:"size-4"})}),h.jsx(dt,{label:"Reload",onClick:()=>u(_=>_+1),children:h.jsx(fi,{className:"size-4"})}),h.jsx(Ji,{url:(Y==null?void 0:Y.url)??d,startEditing:Y!==null,onSubmit:E},Y===null?"address":`retry:${Y.url}`),h.jsx(dt,{label:"Open in system browser",onClick:R,children:h.jsx(ei,{className:"size-4"})})]}),Y!==null&&h.jsx("p",{role:"status",className:"text-destructive border-border/60 border-b px-2 py-1 text-xs",children:Y.message}),h.jsx(eo,{target:f,resolved:m,resolveError:P,reloadNonce:c,resourceErrorCount:w,title:r.title??"Embedded browser",onOpenExternally:R,onReload:()=>{A(),u(_=>_+1)},iframeRef:v,onFrameLoad:C})]})}function Ji({url:e,startEditing:r=!1,onSubmit:t}){const[n,i]=g.useState(r),[o,a]=g.useState(e);if(!n)return h.jsx(Ki,{url:e,onActivate:()=>{a(e),i(!0)}});const s=l=>{l.preventDefault(),i(!1),t(o)};return h.jsx("form",{onSubmit:s,className:"min-w-0 flex-1",children:h.jsx(ti,{"aria-label":"Address",autoFocus:!0,value:o,onChange:l=>a(l.target.value),onFocus:l=>l.currentTarget.select(),onBlur:()=>i(!1),onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),i(!1))},spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"h-7 w-full text-sm"})})}function Qi(e){return e.kind==="local"?e.path:e.kind==="url"?`${e.host}${e.rest}`:e.text}function Ki({url:e,onActivate:r}){const t=g.useMemo(()=>Hi(e),[e]);return h.jsxs("button",{type:"button","aria-label":`Address: ${Qi(t)}`,onClick:r,className:"text-muted-foreground hover:bg-muted focus-ring flex h-7 min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 text-left text-sm transition-colors",children:[t.kind==="local"&&h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"bg-muted-foreground/15 text-3xs rounded px-1 py-0.5 font-medium tracking-wide uppercase",children:"local"}),h.jsx("span",{className:"text-foreground truncate",children:t.path})]}),t.kind==="url"&&h.jsxs("span",{className:"truncate",children:[h.jsx("span",{className:"text-foreground",children:t.host}),h.jsx("span",{className:"text-muted-foreground",children:t.rest})]}),t.kind==="raw"&&h.jsx("span",{className:"truncate",children:t.text})]})}function Ii(e,r){switch(e.kind){case"no-session":return"Open a session to preview local files.";case"unsupported":return"Local previews aren’t available in this environment.";case"failed":return"Couldn’t load this preview. Reload, or open the app in your browser.";case"tunnel":return"Dev server previews don’t work remotely. Open DorkOS on the computer running it.";case"no-port":return"All preview ports are in use. Close a preview, then reload.";case"origin-unreachable":return`This view can’t reach port ${e.listenPort} on ${e.host}. Open DorkOS on the computer running it.`;case"no-upstream":return`Nothing is listening on ${r.mode==="proxy"?`${r.hostname}:${r.port}`:"that address"}. Start the dev server, then reload.`}}function eo({target:e,resolved:r,resolveError:t,reloadNonce:n,resourceErrorCount:i,title:o,onOpenExternally:a,onReload:s,iframeRef:l,onFrameLoad:c}){if(e.mode==="blocked")return h.jsx(xt,{children:"This address is blocked for safety."});if(t!==null)return h.jsxs(xt,{children:[h.jsx("p",{children:Ii(t,e)}),t.kind!=="no-session"&&t.kind!=="unsupported"&&h.jsx("button",{type:"button",onClick:s,className:"text-foreground mt-3 hover:underline",children:"Reload"})]});if(r===null)return h.jsx(xt,{children:"Loading…"});const u=e.mode==="external";return h.jsx(to,{src:r.src,sandbox:r.sandbox,title:o,iframeRef:l,onFrameLoad:c,watchLoadDeadline:!u,resourceErrorCount:i,showEmbedFallback:u,onOpenExternally:a,onReload:s},`${r.src}:${n}`)}function to({src:e,sandbox:r,title:t,iframeRef:n,onFrameLoad:i,watchLoadDeadline:o,resourceErrorCount:a,showEmbedFallback:s,onOpenExternally:l,onReload:c}){const[u,d]=g.useState(!1),[f,p]=g.useState(!1);return g.useEffect(()=>{if(!o)return;const v=setTimeout(()=>p(!0),Vi);return()=>clearTimeout(v)},[o]),h.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[f&&!u&&h.jsx(Or,{onOpenExternally:l,onReload:c,children:"This preview is slow to load."}),a>0&&h.jsxs(Or,{onOpenExternally:l,children:["This page hit ",a===1e4?"at least 10,000":a," ",a===1?"error":"errors"," while loading."]}),h.jsx("iframe",{ref:n,src:e,sandbox:r,onLoad:()=>{d(!0),i()},className:"min-h-0 w-full flex-1 border-0",title:t}),s&&h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-t px-3 py-1.5 text-xs",children:[h.jsx("span",{children:"This site can’t always be embedded here."}),h.jsx("button",{type:"button",onClick:l,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function Or({children:e,onOpenExternally:r,onReload:t}){return h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-b px-3 py-1.5 text-xs",children:[h.jsx("span",{children:e}),h.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[t&&h.jsx("button",{type:"button",onClick:t,className:"text-foreground hover:underline",children:"Reload"}),h.jsx("button",{type:"button",onClick:r,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function dt({label:e,disabled:r,onClick:t,children:n}){return h.jsx("button",{type:"button","aria-label":e,disabled:r,onClick:t,className:It("text-muted-foreground hover:text-foreground hover:bg-muted focus-ring rounded-md p-1.5 transition-colors",r&&"pointer-events-none opacity-40"),children:n})}function xt({children:e}){return h.jsx("div",{className:"text-muted-foreground flex min-h-0 flex-1 flex-col items-center justify-center p-8 text-center",children:e})}function ro({sourcePath:e,cwd:r,loadedContent:t}){const n=pe(),[i,o]=g.useState("idle"),[a,s]=g.useState(null),l=g.useRef(null),c=g.useRef(t),u=g.useRef(Promise.resolve()),d=!!(e&&r),f=g.useCallback(async(w,A)=>{const C=await n.writeFile(r,e,w,A);if(C.ok){if(typeof C.hash!="string"||C.hash.length===0||C.effect!=="changed"&&C.effect!=="no_op")throw new Error("Invalid file save acknowledgement");return l.current=C.hash,c.current=w,s(null),o("saved"),{status:C.effect,confirmed:{hash:C.hash,content:w}}}return s(C.conflict),o("conflict"),{status:"conflict"}},[n,r,e]),p=g.useCallback(w=>{if(!d)return Promise.resolve({status:"idle"});const A=u.current.catch(()=>{}).then(async()=>{o("saving");try{const C=l.current!==null?{expectedHash:l.current}:{expectedContent:c.current};return await f(w,C)}catch{return o("error"),{status:"error"}}});return u.current=A.then(()=>{}),A},[d,f]),v=g.useCallback(w=>{if(!d||!a)return Promise.resolve({status:"idle"});const A=a.currentHash,C=u.current.catch(()=>{}).then(async()=>{o("saving");try{return await f(w,{expectedHash:A})}catch{return o("error"),{status:"error"}}});return u.current=C.then(()=>{}),C},[d,a,f]),m=g.useCallback(()=>({hash:l.current,content:c.current}),[]),P=g.useCallback(()=>{if(!a)return null;const w=a.currentContent;return l.current=a.currentHash,c.current=w,s(null),o("idle"),w},[a]);return{status:i,conflict:a,canSave:d,save:p,overwrite:v,adoptDisk:P,getConfirmedBase:m}}const no=g.lazy(()=>je(()=>import("./BlintzCanvas-CXi0fvcM.js"),__vite__mapDeps([0,1,2,3,4])).then(e=>({default:e.BlintzCanvas}))),io=500;function oo(e){switch(e){case"saving":return"Saving…";case"saved":return"Saved";case"error":return"Couldn’t save";default:return null}}function ao({content:e,documentId:r,onContentChange:t}){const[n,i]=g.useState(!1),[o,a]=g.useState(e.content),s=K(B=>B.canvasSessionId),l=K(B=>B.setDocumentEditing),c=K(B=>{var y;return((y=B.openDocuments.find(E=>E.id===r))==null?void 0:y.editing)??!1}),u=K(B=>B.selectedCwd),d=n&&c,f=ro({sourcePath:e.sourcePath,cwd:u,loadedContent:e.content}),p=f.canSave,v=g.useRef(null),m=g.useRef(null),P=g.useRef(o),w=g.useRef(e),A=g.useRef(t),C=g.useRef(f.save);g.useEffect(()=>{P.current=o,w.current=e,A.current=t,C.current=f.save});const O=g.useCallback(B=>{K.getState().canvasSessionId===v.current&&(A.current({...w.current,content:B}),C.current(B))},[]),z=g.useCallback(B=>{a(B),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null,O(B)},io)},[O]),Y=()=>{v.current=K.getState().canvasSessionId,a(e.content),i(!0),l(r,!0)},N=()=>{m.current&&(clearTimeout(m.current),m.current=null,O(P.current)),i(!1),l(r,!1)};g.useEffect(()=>{d&&s!==v.current&&(m.current&&(clearTimeout(m.current),m.current=null),i(!1),l(r,!1))},[s,d,r,l]),g.useEffect(()=>{d||!m.current||(clearTimeout(m.current),m.current=null)},[d]),g.useEffect(()=>()=>{m.current&&(clearTimeout(m.current),m.current=null,O(P.current)),l(r,!1)},[O,r,l]);const M=()=>{const B=f.adoptDisk();B!=null&&(t({...e,content:B}),a(B))},W=()=>{f.overwrite(P.current)},q=oo(f.status);return h.jsxs("div",{className:"relative flex h-full flex-col",children:[h.jsxs("div",{className:"sticky top-0 z-10 flex h-0 items-start justify-end gap-2 pr-2",children:[p&&q&&h.jsx("span",{className:"text-muted-foreground mt-3 text-xs","aria-live":"polite",children:q}),p&&h.jsx(mt,{type:"button",variant:"ghost",size:"icon-md",className:"text-muted-foreground hover:text-foreground mt-2",onClick:d?N:Y,"aria-label":d?"Finish editing":"Edit document",children:d?h.jsx(qr,{className:"size-4"}):h.jsx(Hr,{className:"size-4"})})]}),f.status==="conflict"&&h.jsxs("div",{className:"bg-destructive/10 text-destructive mx-2 mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md px-3 py-2 text-sm",children:[h.jsx("span",{className:"flex-1",children:"This file changed on disk since you opened it."}),h.jsx(mt,{type:"button",variant:"ghost",size:"sm",className:"h-7",onClick:M,children:"Reload"}),h.jsx(mt,{type:"button",variant:"destructive",size:"sm",className:"h-7",onClick:W,children:"Overwrite"})]}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(g.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading editor…"}),children:h.jsx(no,{value:d?o:e.content,editable:d,onChange:d?z:void 0})})})]})}function so({content:e}){return h.jsx("div",{className:"p-4 font-mono text-sm",children:h.jsx(Ir,{value:e.data,depth:0})})}const lo=20;function Ir({value:e,depth:r,keyName:t}){const[n,i]=g.useState(r>2),o=g.useCallback(()=>i(u=>!u),[]);if(r>=lo)return h.jsx(Ve,{keyName:t,value:"[max depth]",className:"text-muted-foreground"});if(e===null)return h.jsx(Ve,{keyName:t,value:"null",className:"text-muted-foreground"});if(typeof e=="boolean")return h.jsx(Ve,{keyName:t,value:String(e),className:"text-blue-500"});if(typeof e=="number")return h.jsx(Ve,{keyName:t,value:String(e),className:"text-green-500"});if(typeof e=="string")return h.jsx(Ve,{keyName:t,value:`"${e}"`,className:"text-amber-500"});const a=Array.isArray(e),s=a?e.map((u,d)=>[String(d),u]):Object.entries(e),l=a?"[":"{",c=a?"]":"}";return h.jsxs("div",{style:{paddingLeft:r>0?16:0},children:[h.jsxs("button",{type:"button",className:"hover:bg-muted -ml-0.5 inline-flex items-center gap-0.5 rounded px-0.5 transition-colors duration-150",onClick:o,children:[h.jsx(ni,{className:It("size-3 transition-transform",!n&&"rotate-90")}),t!=null&&h.jsxs("span",{className:"text-foreground",children:[t,": "]}),h.jsxs("span",{className:"text-muted-foreground",children:[l,n&&` … ${s.length} items `,n&&c]})]}),!n&&h.jsxs(h.Fragment,{children:[s.map(([u,d])=>h.jsx(Ir,{keyName:a?void 0:u,value:d,depth:r+1},u)),h.jsx("div",{className:"text-muted-foreground",children:c})]})]})}function Ve({keyName:e,value:r,className:t}){return h.jsxs("div",{style:{paddingLeft:16},children:[e!=null&&h.jsxs("span",{className:"text-foreground",children:[e,": "]}),h.jsx("span",{className:t,children:r})]})}var Ce=function(e,r){return Number(e.toFixed(r))},uo=function(e,r){return typeof e=="number"?e:r},F=function(e,r,t){t&&typeof t=="function"&&t(e,r)},co=function(e){return-Math.cos(e*Math.PI)/2+.5},fo=function(e){return e},po=function(e){return e*e},ho=function(e){return e*(2-e)},mo=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},vo=function(e){return e*e*e},go=function(e){return--e*e*e+1},bo=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},wo=function(e){return e*e*e*e},yo=function(e){return 1- --e*e*e*e},Co=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},So=function(e){return e*e*e*e*e},Po=function(e){return 1+--e*e*e*e*e},ko=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},en={easeOut:co,linear:fo,easeInQuad:po,easeOutQuad:ho,easeInOutQuad:mo,easeInCubic:vo,easeOutCubic:go,easeInOutCubic:bo,easeInQuart:wo,easeOutQuart:yo,easeInOutQuart:Co,easeInQuint:So,easeOutQuint:Po,easeInOutQuint:ko},Eo=function(e){var r=e.animationResolve;e.animationResolve=null,r==null||r()},ue=function(e){e.animationFrame!==null&&cancelAnimationFrame(e.animationFrame),e.animationFrame=null,e.isAnimating=!1,e.animation=null,e.velocity=null,Eo(e)};function tn(e,r,t,n,i){if(!e.mounted){i==null||i();return}var o=new Date().getTime(),a=1;ue(e);var s=function(){if(!(!e.mounted||e.animation!==s)){var l=new Date().getTime()-o,c=l/t,u=en[r],d=u(c);if(l>=t){e.animation=null,e.animationFrame=null;var f=e.animationResolve;e.animationResolve=null,n(a),f==null||f(),e.flushResizeAlignment()}else n(d),e.animationFrame=requestAnimationFrame(s)}};e.animation=s,e.animationResolve=i??null,e.animationFrame=requestAnimationFrame(s)}function To(e){var r=e.scale,t=e.positionX,n=e.positionY;return!(Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(n))}function Ae(e,r,t,n){var i=To(r);if(!e.mounted||!i)return Promise.resolve();var o=e.setState,a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=r.scale-s,d=r.positionX-l,f=r.positionY-c;return t===0?(o(r.scale,r.positionX,r.positionY),Promise.resolve()):new Promise(function(p){tn(e,n,t,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var m=s+u*v,P=l+d*v,w=c+f*v;o(m,P,w)},p)})}function Oo(e,r,t){var n=e.clientWidth,i=e.clientHeight,o=r.offsetWidth,a=r.offsetHeight,s=o*t,l=a*t,c=n-s,u=i-l;return{wrapperWidth:n,wrapperHeight:i,newContentWidth:s,newDiffWidth:c,newContentHeight:l,newDiffHeight:u}}var _o=function(e,r,t,n,i,o,a){var s=e>r?t*(a?.5:1):0,l=n>i?o*(a?.5:1):0,c=e-r-s,u=s,d=n-i-l,f=l;return{minPositionX:c,maxPositionX:u,minPositionY:d,maxPositionY:f,scaleWidthFactor:s,scaleHeightFactor:l}},tr=function(e,r){var t=e.wrapperComponent,n=e.contentComponent,i=e.setup,o=i.centerZoomedOut,a=i.disablePadding;if(!t||!n)throw new Error("Components are not mounted");var s=Oo(t,n,r),l=s.wrapperWidth,c=s.wrapperHeight,u=s.newContentWidth,d=s.newContentHeight,f=s.newDiffWidth,p=s.newDiffHeight,v=_o(l,u,f,c,d,p,!!o),m=l>=u&&c>=d;a&&m&&!o&&(v.minPositionX=0,v.maxPositionX=0,v.minPositionY=0,v.maxPositionY=0);var P=e.setup,w=P.minPositionX,A=P.maxPositionX,C=P.minPositionY,O=P.maxPositionY;return w!=null&&(v.minPositionX=l*(1-r)+w*r),A!=null&&(v.maxPositionX=A*r),C!=null&&(v.minPositionY=c*(1-r)+C*r),O!=null&&(v.maxPositionY=O*r),v},tt=function(e,r,t,n){return n?e<r?Ce(r,2):e>t?Ce(t,2):Ce(e,2):Ce(e,2)},ce=function(e,r){var t=tr(e,r);return e.bounds=t,t};function Me(e,r,t,n,i,o,a){var s=t.minPositionX,l=t.minPositionY,c=t.maxPositionX,u=t.maxPositionY,d=0,f=0;a&&(d=i,f=o);var p=tt(e,s-d,c+d,n),v=tt(r,l-f,u+f,n);return{x:p,y:v}}function Et(e,r,t,n,i,o){var a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=n-s;if(!Number.isFinite(r)||!Number.isFinite(t))return console.error("Mouse X and Y position were not provided!"),{x:l,y:c};var d=l-r*u,f=c-t*u,p=Me(d,f,i,o,0,0,null);return p}var _r=1e-7;function Fe(e,r,t,n,i){var o=i?n:0,a=Math.max(r-o,_r),s=t+o;return!Number.isNaN(t)&&e>=s?s:!Number.isNaN(r)&&e<=a?a:Math.max(e,_r)}var jr=function(e,r){var t=e.setup.panning.excluded,n=e.isInitialized,i=e.wrapperComponent,o=r.target,a=function(u){return!!u&&typeof u=="object"&&u.nodeType===1&&typeof u.contains=="function"},s=typeof r.composedPath=="function"?r.composedPath().some(function(u){return a(u)&&!!(i!=null&&i.contains(u))}):!!(i!=null&&i.contains(o)),l=n&&o&&s;if(!l)return!1;var c=qe(o,t);return!(c||sa(o)||ir(o))},Ar=function(e){var r=e.isInitialized,t=e.isPanning,n=e.setup,i=n.panning.disabled,o=r&&t&&!i;return!!o},jo=function(e,r){var t=e.state,n=t.positionX,i=t.positionY;e.isPanning=!0;var o=r.clientX,a=r.clientY;e.startCoords={x:o-n,y:a-i}},Ao=function(e,r){var t=r.touches,n=e.state,i=n.positionX,o=n.positionY;e.isPanning=!0;var a=t.length===1;if(a){var s=t[0].clientX,l=t[0].clientY;e.startCoords={x:s-i,y:l-o}}};function Ro(e){var r=e.state,t=r.positionX,n=r.positionY,i=r.scale,o=e.setup,a=o.disabled,s=o.limitToBounds,l=o.centerZoomedOut,c=e.wrapperComponent;if(!(a||!c||!e.bounds)){var u=e.bounds,d=u.maxPositionX,f=u.minPositionX,p=u.maxPositionY,v=u.minPositionY,m=t>d||t<f,P=n>p||n<v,w=t>d?c.clientWidth:e.setup.minPositionX||0,A=n>p?c.clientHeight:e.setup.minPositionY||0,C=Et(e,w,A,i,e.bounds,s||l),O=C.x,z=C.y;return{scale:i,positionX:m?O:t,positionY:P?z:n}}}function rn(e,r,t,n,i){var o=e.setup.limitToBounds,a=e.wrapperComponent,s=e.bounds,l=e.state,c=l.scale,u=l.positionX,d=l.positionY;if(!(a===null||s===null||r===u&&t===d)){var f=Me(r,t,s,o,n,i,a),p=f.x,v=f.y;e.setState(c,p,v)}}var xo=function(e,r,t){var n=e.startCoords,i=e.state,o=e.setup.panning,a=o.lockAxisX,s=o.lockAxisY,l=i.positionX,c=i.positionY;if(!n)return{x:l,y:c};var u=r-n.x,d=t-n.y,f=a?l:u,p=s?c:d;return{x:f,y:p}},Oe=function(e,r,t){var n=e.setup,i=e.state,o=n.minScale,a=n.disablePadding,s=n.centerZoomedOut,l=t??i.scale;return r>0&&l>=o&&!a&&!s?r:0},Te;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(Te||(Te={}));var zo=function(e){var r=e.mounted,t=e.wrapperComponent,n=e.contentComponent,i=e.setup,o=i.disabled,a=i.velocityAnimation,s=i.limitToBounds,l=e.state.scale,c=a.disabled;if(c||o||!r||!t||!n)return!1;if(!s)return!0;var u=t.clientWidth<n.offsetWidth*l||t.clientHeight<n.offsetHeight*l;return u},Do=function(e){var r=e.mounted,t=e.velocity,n=e.bounds,i=e.setup,o=i.disabled,a=i.velocityAnimation,s=a.disabled,l=!s&&!o&&r;return!(!l||!t||!n)};function No(e,r){var t=e.setup.velocityAnimation,n=t.animationTime,i=t.maxAnimationTime,o=t.inertia;return Math.min(n*Math.max(1,Math.abs(r/o)),i)}function Rr(e,r,t,n,i,o,a,s,l,c){if(i){if(r>a&&t>a){var u=a+(e-a)*c;return u>l?l:u<a?a:u}if(r<o&&t<o){var u=o+(e-o)*c;return u<s?s:u>o?o:u}}return n?r:tt(e,o,a,i)}function Mo(e){var r=1,t=e.clientWidth/window.innerWidth;return Number.isNaN(t)?r:Math.min(r,t)}var zt=function(e,r,t){var n=0,i=e*t;return Number.isNaN(i)?n:e<0?Math.max(i,-r):Math.min(i,r)};function Yo(e,r,t){var n,i,o=zo(e);if(o){var a=e.lastMousePosition,s=e.velocityTime,l=e.setup,c=e.wrapperComponent,u=l.velocityAnimation,d=u.maxStrengthMouse,f=u.maxStrengthTouch,p=u.sensitivityTouch,v=u.sensitivityMouse,m=Date.now();if(a&&s&&c){var P=Mo(c),w=(n={},n[Te.TOUCH]=p,n[Te.MOUSE]=v,n)[t],A=(i={},i[Te.TOUCH]=f,i[Te.MOUSE]=d,i)[t],C=r.x-a.x,O=r.y-a.y,z=zt(C/P,A,w),Y=zt(O/P,A,w),N=m-s,M=C*C+O*O,W=zt(Math.sqrt(M)/N,A,w);e.velocity={velocityX:z,velocityY:Y,total:W}}e.lastMousePosition=r,e.velocityTime=m}}function Xo(e){var r=e.velocity,t=e.bounds,n=e.setup,i=e.wrapperComponent,o=Do(e);if(!(!o||!r||!t||!i)){var a=r.velocityX,s=r.velocityY,l=r.total,c=t.maxPositionX,u=t.minPositionX,d=t.maxPositionY,f=t.minPositionY,p=n.limitToBounds,v=n.autoAlignment,m=n.zoomAnimation,P=n.panning,w=P.lockAxisY,A=P.lockAxisX,C=m.animationType,O=v.sizeX,z=v.sizeY,Y=v.velocityAlignmentTime,N=Y,M=No(e,l),W=Math.max(M,N),q=Oe(e,O),B=Oe(e,z),y=q*i.clientWidth/100,E=B*i.clientHeight/100,R=c+y,_=u-y,D=d+E,Z=f-E,G=e.state,se=new Date().getTime();tn(e,C,W,function(me){var le=e.state,we=le.scale,Xe=le.positionX,We=le.positionY,Be=new Date().getTime()-se,He=Be/N,ct=en[v.animationType],k=1-ct(Math.min(1,He)),b=1-me,T=Xe+a*b,S=We+s*b,x=Rr(T,G.positionX,Xe,A,p,u,c,_,R,k),$=Rr(S,G.positionY,We,w,p,f,d,Z,D,k);if(Xe!==T||We!==S){e.setState(we,x,$);var H=e.props.onPanning;H&&H(L(e),{})}})}}function xr(e,r){var t=e.state,n=t.scale,i=t.positionX,o=t.positionY;e.panStartPosition={x:i,y:o},ue(e),ce(e,n),"touches"in r?Ao(e,r):jo(e,r)}function nn(e,r){var t=e.state.scale,n=e.setup,i=n.minScale,o=n.autoAlignment,a=o.disabled,s=o.sizeX,l=o.sizeY,c=o.animationTime,u=o.animationType,d=a||t<i||!s&&!l;if(!d){e.isResizeAlignmentPending&&ce(e,t);var f=Ro(e);if(f){var p=e.state,v=p.positionX,m=p.positionY,P=f.positionX===v&&f.positionY===m;P||Ae(e,f,c,u)}}}function zr(e,r,t,n){var i=e.startCoords,o=e.setup,a=o.autoAlignment,s=a.sizeX,l=a.sizeY;if(i){var c=xo(e,r,t),u=c.x,d=c.y,f=Oe(e,s),p=Oe(e,l);Yo(e,{x:u,y:d},n),rn(e,u,d,f,p)}}function Wo(e,r){if(e.isPanning){var t=e.velocity,n=e.wrapperComponent,i=e.contentComponent;e.isPanning=!1;var o=e.state,a=o.positionX,s=o.positionY,l=o.scale,c=e.panStartPosition;if(e.panStartPosition=null,c){var u=a-c.x,d=s-c.y;if(u*u+d*d<=25)return}e.isAnimating=!1,e.animation=null,e.isResizeAlignmentPending&&ce(e,l);var f=(n==null?void 0:n.clientWidth)||0,p=(n==null?void 0:n.clientHeight)||0,v=((i==null?void 0:i.offsetWidth)||0)*l,m=((i==null?void 0:i.offsetHeight)||0)*l,P=!e.setup.limitToBounds||f<v||p<m,w=!r&&t&&t.total>.1&&P;w?Xo(e):nn(e)}}function Tt(e,r,t,n){var i=e.setup,o=i.minScale,a=i.maxScale,s=i.limitToBounds,l=Fe(Ce(r,2),o,a,0,!1),c=ce(e,l),u=Et(e,t,n,l,c,s),d=u.x,f=u.y;return{scale:l,positionX:d,positionY:f}}function rr(e,r,t){var n=e.state.scale,i=e.wrapperComponent,o=e.setup,a=o.minScale,s=o.maxScale,l=o.limitToBounds,c=o.zoomAnimation,u=c.disabled,d=c.animationTime,f=c.animationType,p=n>=a&&n<=s,v=u||p;if((n>=1||l)&&nn(e),!(v||!i||!e.mounted)){var m=r||i.clientWidth/2,P=t||i.clientHeight/2,w=n<a?a:s,A=Tt(e,w,m,P);A&&Ae(e,A,d,f)}}var de=function(){return de=Object.assign||function(r){for(var t,n=1,i=arguments.length;n<i;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},de.apply(this,arguments)};function Dr(e,r,t){for(var n=0,i=r.length,o;n<i;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return e.concat(o||Array.prototype.slice.call(r))}var Dt={scale:1,positionX:0,positionY:0},Ne={disabled:!1,minPositionX:null,maxPositionX:null,minPositionY:null,maxPositionY:null,minScale:1,maxScale:8,limitToBounds:!0,centerZoomedOut:!1,centerOnInit:!1,fitOnInit:!1,disablePadding:!1,smooth:!0,detached:!1,wheel:{step:.015,disabled:!1,wheelDisabled:!1,touchPadDisabled:!1,activationKeys:[],excluded:[]},trackPadPanning:{disabled:!0,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,activationKeys:[],excluded:[]},panning:{disabled:!1,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,allowLeftClickPan:!0,allowMiddleClickPan:!0,allowRightClickPan:!0,activationKeys:[],excluded:[]},pinch:{step:5,disabled:!1,allowPanning:!0,excluded:[]},keyboard:{disabled:!0,panStep:50,zoomStep:.25,animationTime:100,animationType:"easeOut",excluded:[]},doubleClick:{disabled:!1,step:.7,mode:"zoomIn",animationType:"easeOut",animationTime:200,excluded:[]},zoomAnimation:{disabled:!1,size:.4,animationTime:200,animationType:"easeOut"},autoAlignment:{disabled:!1,sizeX:100,sizeY:100,animationTime:200,velocityAlignmentTime:400,animationType:"easeOut"},velocityAnimation:{disabled:!1,sensitivityMouse:1,sensitivityTouch:1.2,maxStrengthMouse:20,maxStrengthTouch:40,inertia:1,animationTime:300,maxAnimationTime:800,animationType:"easeOut"}},Bt={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},on=function(e){var r,t,n,i,o,a,s,l,c,u=Math.max((r=e.minScale)!==null&&r!==void 0?r:Ne.minScale,1e-7),d=(t=e.maxScale)!==null&&t!==void 0?t:Ne.maxScale,f=(n=e.initialScale)!==null&&n!==void 0?n:Dt.scale,p=Math.min(Math.max(f,u),d),v=tt((i=e.initialPositionX)!==null&&i!==void 0?i:Dt.positionX,(o=e.minPositionX)!==null&&o!==void 0?o:-1/0,(a=e.maxPositionX)!==null&&a!==void 0?a:1/0,e.minPositionX!=null||e.maxPositionX!=null),m=tt((s=e.initialPositionY)!==null&&s!==void 0?s:Dt.positionY,(l=e.minPositionY)!==null&&l!==void 0?l:-1/0,(c=e.maxPositionY)!==null&&c!==void 0?c:1/0,e.minPositionY!=null||e.maxPositionY!=null);return{previousScale:p,scale:p,positionX:v,positionY:m}},Nr=function(e){var r=de({},Ne);return Object.keys(e).forEach(function(t){var n=t,i=typeof e[n]<"u",o=typeof Ne[n]<"u";if(o&&i){var a=Object.prototype.toString.call(Ne[n]),s=a==="[object Object]",l=a==="[object Array]";s?r[n]=de(de({},Ne[n]),e[n]):l?r[n]=Dr(Dr([],Ne[n],!0),e[n]):r[n]=e[n]}}),r.minScale<=0&&(r.minScale=1e-7),r},an=function(e,r,t){var n=e.state.scale,i=e.wrapperComponent,o=e.setup,a=o.maxScale,s=o.minScale,l=o.zoomAnimation,c=l.size;if(!i)throw new Error("Wrapper is not mounted");var u=n+r*t,d=Fe(Ce(u,3),s,a,c,!1);return d};function rt(e,r,t,n){var i,o,a=e.wrapperComponent,s=e.props,l=s.onZoomStart,c=s.onZoom,u=s.onZoomStop,d=new MouseEvent("mousemove",{bubbles:!0}),f=L(e);F(f,d,l),F(f,d,c);var p=Ae(e,r,t,n),v=(o=(i=a==null?void 0:a.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;return v&&v.setTimeout(function(){e.mounted&&F(L(e),d,u)},t),p}function sn(e,r,t,n,i){var o=e.wrapperComponent,a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=e.setup.zoomAnimation;if(!o)return console.error("No WrapperComponent found"),Promise.resolve();var d=u.disabled?0:n,f=o.clientWidth,p=o.clientHeight,v=(f/2-l)/s,m=(p/2-c)/s,P=an(e,r,t),w=Tt(e,P,v,m);return w?rt(e,w,d,i):(console.error("Error during zoom event. New transformation state was not calculated."),Promise.resolve())}function Bo(e,r,t,n){var i,o,a=e.wrapperComponent,s=e.props,l=s.onPanningStart,c=s.onPanning,u=s.onPanningStop,d=new MouseEvent("mousemove",{bubbles:!0}),f=L(e);F(f,d,l),F(f,d,c);var p=Ae(e,r,t,n),v=(o=(i=a==null?void 0:a.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;return v&&v.setTimeout(function(){e.mounted&&F(L(e),d,u)},t),p}function nr(e,r,t,n){r===void 0&&(r="contain");var i=e.wrapperComponent,o=e.contentComponent,a=e.setup;if(!i||!o)return null;var s=o.offsetWidth,l=o.offsetHeight,c=i.clientWidth,u=i.clientHeight;if(!s||!l||!c||!u)return null;var d=c/s,f=u/l,p=r==="cover"?Math.max(d,f):Math.min(d,f);return n!==void 0&&(p=Math.min(p,n)),t!==void 0&&(p=Math.max(p,t)),p=Fe(p,a.minScale,a.maxScale,0,!1),Ot(p,i,o)}function ln(e,r,t,n){var i=e.setup,o=e.wrapperComponent,a=e.contentComponent,s=i.limitToBounds,l=i.centerOnInit,c=i.fitOnInit,u=on(e.props),d=e.state,f=d.scale,p=d.positionX,v=d.positionY;if(!o)return Promise.resolve();if(c){var m=nr(e,c==="cover"?"cover":"contain");if(m)return f===m.scale&&p===m.positionX&&v===m.positionY?Promise.resolve():(n==null||n(),rt(e,m,r,t))}var P=u.positionX,w=u.positionY;if(l&&a){var A=Ot(u.scale,o,a);P=A.positionX,w=A.positionY}var C=tr(e,u.scale),O=Me(P,w,C,s,0,0,o),z={scale:u.scale,positionX:O.x,positionY:O.y};return f===u.scale&&p===u.positionX&&v===u.positionY?Promise.resolve():(n==null||n(),rt(e,z,r,t))}var un=function(e){if("getBoundingClientRect"in e){var r=e.getBoundingClientRect();return{x:r.left,y:r.top,width:r.width,height:r.height}}return e};function Lo(e){var r=e.map(un),t=Math.min.apply(Math,r.map(function(a){return a.x})),n=Math.min.apply(Math,r.map(function(a){return a.y})),i=Math.max.apply(Math,r.map(function(a){return a.x+a.width})),o=Math.max.apply(Math,r.map(function(a){return a.y+a.height}));return{x:t,y:n,width:i-t,height:o-n}}function Fo(e,r,t,n){var i=un(e),o=r.getBoundingClientRect(),a=t.getBoundingClientRect(),s=o.x*n.scale,l=o.y*n.scale;return{x:(i.x-a.x+s)/n.scale,y:(i.y-a.y+l)/n.scale}}function qo(e,r,t,n,i,o,a){n===void 0&&(n=0),i===void 0&&(i=0);var s=e.wrapperComponent,l=e.contentComponent,c=e.state,u=e.setup,d=u.limitToBounds,f=u.minScale,p=u.maxScale;if(!s||!l)return c;var v=s.getBoundingClientRect(),m=Fo(r,s,l,c),P=m.x,w=m.y,A=r.width/c.scale,C=r.height/c.scale,O=s.clientWidth/A,z=s.clientHeight/C,Y=t||Math.min(O,z);a!==void 0&&(Y=Math.min(Y,a)),o!==void 0&&(Y=Math.max(Y,o));var N=Fe(Y,f,p,0,!1),M=(v.width-A*N)/2,W=(v.height-C*N)/2,q=(v.left-P)*N+M+n,B=(v.top-w)*N+W+i,y=tr(e,N),E=Me(q,B,y,d,0,0,s),R=E.x,_=E.y;return{positionX:R,positionY:_,scale:N}}function cn(e,r,t){var n=e.wrapperComponent,i=e.state;if(!n)return{x:0,y:0};var o=n.getBoundingClientRect();return{x:(r-o.left-i.positionX)/i.scale,y:(t-o.top-i.positionY)/i.scale}}function Ho(e,r,t){var n=e.wrapperComponent,i=e.state;if(!n)return{x:0,y:0};var o=n.getBoundingClientRect();return{x:o.left+i.positionX+r*i.scale,y:o.top+i.positionY+t*i.scale}}var Uo=function(e){return function(r,t,n){return r===void 0&&(r=.5),t===void 0&&(t=300),n===void 0&&(n="easeOut"),sn(e,1,r,t,n)}},Zo=function(e){return function(r,t,n){return r===void 0&&(r=.5),t===void 0&&(t=300),n===void 0&&(n="easeOut"),sn(e,-1,r,t,n)}},Vo=function(e){return function(r,t,n,i,o){i===void 0&&(i=300),o===void 0&&(o="easeOut");var a=e.state,s=a.positionX,l=a.positionY,c=a.scale,u=e.wrapperComponent,d=e.contentComponent,f=e.setup.disabled;if(f||!u||!d)return Promise.resolve();var p={positionX:Number.isNaN(r)?s:r,positionY:Number.isNaN(t)?l:t,scale:Number.isNaN(n)?c:n};return Ae(e,p,i,o)}},Go=function(e){return function(r,t){return r===void 0&&(r=200),t===void 0&&(t="easeOut"),ln(e,r,t)}},$o=function(e){return function(r,t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut");var i=e.state,o=e.wrapperComponent,a=e.contentComponent;if(o&&a){var s=Ot(r||i.scale,o,a);return Ae(e,s,t,n)}return Promise.resolve()}},Jo=function(e){return function(r,t,n,i,o){i===void 0&&(i=300),o===void 0&&(o="easeOut");var a=e.wrapperComponent,s=e.contentComponent,l=e.setup;if(l.disabled||!a||!s)return Promise.resolve();var c=cn(e,t,n),u=Tt(e,r,c.x,c.y);if(!u)return Promise.resolve();var d=l.zoomAnimation.disabled?0:i;return rt(e,u,d,o)}},Qo=function(e){return function(r,t){return cn(e,r,t)}},Ko=function(e){return function(r,t){return Ho(e,r,t)}},Io=function(e,r){var t,n=e.wrapperComponent;if(!n)return[];var i=n.getRootNode(),o=i&&"getElementById"in i?i:(t=n.ownerDocument)!==null&&t!==void 0?t:typeof document<"u"?document:null,a=Array.isArray(r)?r:[r];return a.map(function(s){return typeof s=="string"?o==null?void 0:o.getElementById(s):s}).filter(function(s){return!!s&&n.contains(s)})},ea=function(e){return function(r,t,n,i,o,a){var s,l,c,u;n===void 0&&(n=600),i===void 0&&(i="easeOut"),o===void 0&&(o=0),a===void 0&&(a=0),ue(e);var d=typeof t=="object"&&t!==null?t:{scale:t},f=Io(e,r);if(!e.wrapperComponent||f.length===0)return Promise.resolve();var p=qo(e,Lo(f),d.scale,(s=d.offsetX)!==null&&s!==void 0?s:o,(l=d.offsetY)!==null&&l!==void 0?l:a,d.minScale,d.maxScale);return Ae(e,p,(c=d.animationTime)!==null&&c!==void 0?c:n,(u=d.animationType)!==null&&u!==void 0?u:i)}},ta=function(e){return function(r){var t,n,i;r===void 0&&(r={});var o=e.wrapperComponent,a=e.contentComponent,s=e.setup;if(s.disabled||!o||!a)return Promise.resolve();var l=nr(e,(t=r.mode)!==null&&t!==void 0?t:"contain",r.minScale,r.maxScale);if(!l)return Promise.resolve();var c=s.zoomAnimation.disabled?0:(n=r.animationTime)!==null&&n!==void 0?n:200;return rt(e,l,c,(i=r.animationType)!==null&&i!==void 0?i:"easeOut")}},ra=function(e){return function(r,t,n,i){n===void 0&&(n=200),i===void 0&&(i="easeOut");var o=e.wrapperComponent,a=e.contentComponent,s=e.setup,l=e.state;if(s.disabled||!o||!a||!Number.isFinite(r)||!Number.isFinite(t))return Promise.resolve();var c=ce(e,l.scale),u=Me(l.positionX+r,l.positionY+t,c,s.limitToBounds,0,0,o),d=u.x,f=u.y;return d===l.positionX&&f===l.positionY?Promise.resolve():Bo(e,{scale:l.scale,positionX:d,positionY:f},n,i)}},nt=function(e){return{instance:e,state:e.state,zoomIn:Uo(e),zoomOut:Zo(e),setTransform:Vo(e),resetTransform:Go(e),centerView:$o(e),zoomToElement:ea(e),zoomToPoint:Jo(e),clientToContent:Qo(e),contentToClient:Ko(e),fitToView:ta(e),panBy:ra(e)}},na=function(e){return{instance:e,state:e.state}},L=function(e){var r={};return Object.assign(r,na(e)),Object.assign(r,nt(e)),r},Nt=!1;function ft(){try{var e={get passive(){return Nt=!0,!1}};return e}catch{return Nt=!1,Nt}}var pt=".".concat(Bt.wrapperClass),qe=function(e,r){return r.some(function(t){return e.matches("".concat(pt," ").concat(t,", ").concat(pt," .").concat(t,", ").concat(pt," ").concat(t," *, ").concat(pt," .").concat(t," *"))})},ia=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]),oa='[contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]',aa='[draggable="true"]',dn=function(e){return!e||typeof e.closest!="function"?null:e},ir=function(e){var r=dn(e);return r?ia.has(r.tagName)||r.isContentEditable?!0:r.closest(oa)!==null:!1},sa=function(e){var r=dn(e);return r?r.closest(aa)!==null:!1},it=function(e){e&&clearTimeout(e)},la=function(e){return Number.parseFloat(e.toFixed(8))},fn=function(e,r,t){var n=la(t);return"translate(".concat(e,"px, ").concat(r,"px) scale(").concat(n,")")},Ot=function(e,r,t){var n=t.offsetWidth*e,i=t.offsetHeight*e,o=(r.clientWidth-n)/2,a=(r.clientHeight-i)/2;return{scale:e,positionX:o,positionY:a}};function ua(e,r){e!=null&&(typeof e=="function"?e(r):e.current=r)}function ca(e){return function(r){e.forEach(function(t){typeof t=="function"?t(r):t!=null&&(t.current=r)})}}var or=typeof window<"u"?g.useLayoutEffect:g.useEffect,da={panLeft:["ArrowLeft"],panRight:["ArrowRight"],panUp:["ArrowUp"],panDown:["ArrowDown"],zoomIn:["+","="],zoomOut:["-","_"],reset:["0"]},fa=function(e){return Object.values(da).some(function(r){return r.includes(e)})};function pa(e,r){var t=e.setup,n=t.disabled,i=t.keyboard,o=t.panning;if(n||i.disabled||r.defaultPrevented||r.ctrlKey||r.metaKey||r.altKey||!fa(r.key))return!1;var a=r.target;if(ir(a)||a&&typeof a.matches=="function"&&qe(a,i.excluded))return!1;var s=i.panStep,l=i.zoomStep,c=i.animationTime,u=i.animationType,d=nt(e),f=r.key,p=o.lockAxisX?0:s,v=o.lockAxisY?0:s;return f==="ArrowLeft"?d.panBy(p,0,c,u):f==="ArrowRight"?d.panBy(-p,0,c,u):f==="ArrowUp"?d.panBy(0,v,c,u):f==="ArrowDown"?d.panBy(0,-v,c,u):f==="+"||f==="="?d.zoomIn(l,c,u):f==="-"||f==="_"?d.zoomOut(l,c,u):f==="0"&&d.resetTransform(c,u),r.cancelable&&r.preventDefault(),r.stopPropagation(),!0}var Lt=function(e,r){return{wrapperWidth:e.offsetWidth,wrapperHeight:e.offsetHeight,contentWidth:r.offsetWidth,contentHeight:r.offsetHeight}},ha=function(e,r){return!e||e.wrapperWidth!==r.wrapperWidth||e.wrapperHeight!==r.wrapperHeight||e.contentWidth!==r.contentWidth||e.contentHeight!==r.contentHeight},pn=function(e){return e.isPanning||e.isPinching},ma=function(e){return pn(e)||e.wheelStopEventTimer!==null||e.wheelAnimationTimer!==null};function hn(e){var r=e.wrapperComponent,t=e.contentComponent,n=e.setup,i=e.state;if(!r||!t)return null;var o=ce(e,i.scale),a=n.limitToBounds,s=n.centerZoomedOut;if(!a&&!s)return null;var l=Me(i.positionX,i.positionY,o,!0,0,0,r),c=l.x,u=l.y,d=c===Ce(i.positionX,2)&&u===Ce(i.positionY,2);return d?null:{scale:i.scale,positionX:c,positionY:u}}var Ft=function(e){e.animation=null,e.animationFrame=null,e.isAnimating=!1,e.resizeAnimation=null};function va(e){var r=e.setup.autoAlignment.animationTime,t=Math.max(r/5,1);ue(e);var n=Date.now(),i=function(){if(!(!e.mounted||e.animation!==i)){var o=Date.now(),a=Math.max(o-n,1);n=o;var s=hn(e);if(!s){Ft(e);return}var l=e.state,c=l.scale,u=l.positionX,d=l.positionY,f=1-Math.exp(-a/t),p=u+(s.positionX-u)*f,v=d+(s.positionY-d)*f,m=Math.abs(s.positionX-p)<.5&&Math.abs(s.positionY-v)<.5;if(m&&(p=s.positionX,v=s.positionY),e.isAnimating=!m,e.setState(c,p,v),m){Ft(e);return}e.animationFrame=requestAnimationFrame(i)}};e.animation=i,e.resizeAnimation=i,e.animationResolve=null,e.animationFrame=requestAnimationFrame(i)}function mn(e){if(e.setup.disabled){ce(e,e.state.scale);return}if(pn(e)){e.isResizeAlignmentPending=!0;return}var r=e.animation!==null&&e.animation===e.resizeAnimation;if(e.animation&&!r){var t=e.state.scale,n=e.setup,i=n.minScale,o=n.maxScale;if(t<i||t>o){e.isResizeAlignmentPending=!0;return}ue(e)}var a=hn(e);if(!a){r&&Ft(e);return}if(!r){if(e.setup.autoAlignment.animationTime===0){e.setState(a.scale,a.positionX,a.positionY);return}va(e)}}function ga(e){var r=e.wrapperComponent,t=e.contentComponent;if(!(!r||!t)){var n=Lt(r,t);ha(e.measuredSizes,n)&&(e.measuredSizes=n,mn(e))}}var vn=function(e,r){var t=e.setup.wheel,n=t.disabled,i=t.wheelDisabled,o=t.touchPadDisabled,a=t.excluded,s=e.isInitialized,l=e.isPanning,c=r.target,u=s&&!l&&!n&&c;if(!u||r.deltaY===0||i&&!r.ctrlKey||o&&r.ctrlKey)return!1;var d=qe(c,a);if(d)return!1;var f=e.isPressingKeys(e.setup.wheel.activationKeys);return!!f},ba=function(e,r){var t=e.setup,n=t.disabled,i=t.trackPadPanning,o=i.activationKeys,a=i.excluded;if(!e.wrapperComponent||!e.contentComponent||n||i.disabled||r.ctrlKey)return!1;var s=vn(e,r);if(s)return!1;var l=r.target,c=qe(l,a);if(c)return!1;var u=e.isPressingKeys(o);return!!u},wa=function(e){return e?e.deltaY<0?1:-1:0};function ya(e,r){var t=wa(e),n=uo(r,t);return n}function gn(e,r,t){var n=r.getBoundingClientRect(),i=0,o=0;if("clientX"in e)i=(e.clientX-n.left)/t,o=(e.clientY-n.top)/t;else{var a=e.touches[0];i=(a.clientX-n.left)/t,o=(a.clientY-n.top)/t}return Number.isNaN(i)||Number.isNaN(o)?(console.error("No mouse or touch offset found"),{x:0,y:0}):{x:i,y:o}}var Ca=function(e,r,t,n,i){var o=e.state.scale,a=e.wrapperComponent,s=e.setup,l=s.maxScale,c=s.minScale,u=s.zoomAnimation,d=s.disablePadding,f=u.size,p=u.disabled;if(!a)throw new Error("Wrapper is not mounted");var v=o+r*t,m=n?!1:!p,P=Fe(v,c,l,f,m&&!d);return P},bn=function(e,r){var t=e.previousWheelEvent,n=e.state.scale,i=e.setup,o=i.maxScale,a=i.minScale;return t?n<o||n>a||Math.sign(t.deltaY)!==Math.sign(r.deltaY)||t.deltaY>0&&t.deltaY<r.deltaY||t.deltaY<0&&t.deltaY>r.deltaY||Math.sign(t.deltaY)!==Math.sign(r.deltaY):!1},Sa=function(e,r){var t=e.setup.pinch,n=t.disabled,i=t.excluded,o=e.isInitialized,a=r.target,s=o&&!n&&a;if(!s)return!1;var l=qe(a,i);return!l},Pa=function(e){var r=e.setup.pinch.disabled,t=e.isInitialized,n=e.pinchStartDistance,i=t&&!r&&n!==null;return!!i},ka=function(e,r,t){var n=t.getBoundingClientRect(),i=e.touches,o=i[0].clientX-n.left,a=i[0].clientY-n.top,s=i[1].clientX-n.left,l=i[1].clientY-n.top;return{x:(o+s)/2/r,y:(a+l)/2/r}},wn=function(e){return Math.sqrt(Math.pow(e.touches[0].pageX-e.touches[1].pageX,2)+Math.pow(e.touches[0].pageY-e.touches[1].pageY,2))},Ea=5,Ta=function(e,r){var t=e.pinchStartScale,n=e.pinchStartDistance,i=e.setup,o=i.maxScale,a=i.minScale,s=i.zoomAnimation,l=i.disablePadding,c=i.pinch,u=s.size,d=s.disabled,f=c.step;if(!t||n===null)throw new Error("Pinch touches distance was not provided");if(r<0)return e.state.scale;var p=r/n,v=p*t,m=(v-t)*(f/Ea),P=t+m,w=P===1/0?0:Ce(P,10);return Fe(w,a,o,u,!d&&!l)},yn=160,Cn=100,Oa=function(e,r){var t=e.props,n=t.onWheelStart,i=t.onZoomStart;ue(e),e.wheelStopEventTimer||(F(L(e),r,n),F(L(e),r,i))},_a=function(e,r){var t=e.props,n=t.onWheel,i=t.onZoom,o=e.contentComponent,a=e.setup,s=e.state,l=s.scale,c=a.limitToBounds,u=a.centerZoomedOut,d=a.zoomAnimation,f=a.wheel,p=a.disablePadding,v=a.smooth,m=d.size,P=d.disabled,w=f.step;if(!o)throw new Error("Component not mounted");r.cancelable&&r.preventDefault(),r.stopPropagation();var A=ya(r,null),C=v?w*Math.abs(r.deltaY):w,O=Ca(e,A,C,!r.ctrlKey);if(l!==O){var z=ce(e,O),Y=gn(r,o,l),N=P||m===0||u||p,M=c&&N,W=Et(e,Y.x,Y.y,O,z,M),q=W.x,B=W.y;e.previousWheelEvent=r,e.setState(O,q,B),F(L(e),r,n),F(L(e),r,i)}},ja=function(e,r){var t=e.props,n=t.onWheelStop,i=t.onZoomStop;it(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(rr(e,r.x,r.y),e.wheelAnimationTimer=null,e.flushResizeAlignment())},Cn);var o=bn(e,r);o&&(it(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,F(L(e),r,n),F(L(e),r,i),e.flushResizeAlignment())},yn))},Aa=function(e,r){var t=e.props,n=t.onWheelStart,i=t.onPanningStart;ue(e),e.wheelStopEventTimer||(e.wheelAnimationTimer||ce(e,e.state.scale),F(L(e),r,n),F(L(e),r,i))},Ra=function(e,r){var t=e.props,n=t.onWheelStop,i=t.onPanningStop;it(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(rr(e,r.x,r.y),e.wheelAnimationTimer=null,e.flushResizeAlignment())},Cn);var o=bn(e,r);o&&(it(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,F(L(e),r,n),F(L(e),r,i),e.flushResizeAlignment())},yn))},Sn=function(e){for(var r=0,t=0,n=0;n<2;n+=1)r+=e.touches[n].clientX,t+=e.touches[n].clientY;var i=r/2,o=t/2;return{x:i,y:o}},xa=function(e,r){var t=wn(r);e.pinchStartDistance=t,e.lastDistance=t,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=Sn(r),ue(e)},za=function(e,r){var t=e.contentComponent,n=e.pinchStartDistance,i=e.wrapperComponent,o=e.pinchPreviousCenter,a=e.state.scale,s=e.setup,l=s.limitToBounds,c=s.centerZoomedOut,u=s.zoomAnimation,d=s.autoAlignment,f=s.pinch,p=s.panning,v=u.disabled,m=u.size,P=f.allowPanning;if(!(n===null||!t)){var w=ka(r,a,t);if(!(!Number.isFinite(w.x)||!Number.isFinite(w.y))){var A=wn(r),C=Ta(e,A),O=Sn(r),z=a/C,Y=(O.x-((o==null?void 0:o.x)||0))*z,N=(O.y-((o==null?void 0:o.y)||0))*z;if(!(C===a&&Y===0&&N===0)){e.pinchPreviousCenter=O;var M=ce(e,C),W=v||m===0||c,q=l&&W,B=Et(e,w.x,w.y,C,M,q),y=B.x,E=B.y;if(e.pinchMidpoint=w,e.lastDistance=A,p.disabled||!P)e.setState(C,y,E);else{var R=d.sizeX,_=d.sizeY,D=Oe(e,R,C),Z=Oe(e,_,C),G=y+Y,se=E+N,me=Me(G,se,M,l,D,Z,i),le=me.x,we=me.y;e.setState(C,le,we)}}}}},Da=function(e){var r=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,rr(e,r==null?void 0:r.x,r==null?void 0:r.y)},Pn=function(e,r){var t=e.props.onZoomStop,n=e.setup.doubleClick.animationTime;it(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,e.mounted&&F(L(e),r,t)},n)},Na=function(e,r){var t=e.props,n=t.onZoomStart,i=t.onZoom,o=e.setup.doubleClick,a=o.animationTime,s=o.animationType;F(L(e),r,n),ln(e,a,s,function(){return F(L(e),r,i)}),Pn(e,r)};function Ma(e,r){return e==="toggle"?r===1?1:-1:e==="zoomOut"?-1:1}function Ya(e,r){var t=e.setup,n=e.doubleClickStopEventTimer,i=e.state,o=e.contentComponent,a=i.scale,s=e.props,l=s.onZoomStart,c=s.onZoom,u=t.doubleClick,d=u.disabled,f=u.mode,p=u.step,v=u.animationTime,m=u.animationType;if(!d&&!n){if(f==="reset")return Na(e,r);if(!o)return console.error("No ContentComponent found");var P=Ma(f,e.state.scale),w=an(e,P,p);if(a!==w){F(L(e),r,l);var A=gn(r,o,a),C=Tt(e,w,A.x,A.y);if(!C)return console.error("Error during zoom event. New transformation state was not calculated.");F(L(e),r,c),Ae(e,C,v,m),Pn(e,r)}}}var Xa=function(e,r){var t=e.isInitialized,n=e.setup,i=e.wrapperComponent,o=n.doubleClick,a=o.disabled,s=o.excluded,l=r.target,c=i==null?void 0:i.contains(l),u=t&&l&&c&&!a;if(!u)return!1;var d=qe(l,s);return!(d||ir(l))},Wa=(function(){function e(r){var t=this;this.mounted=!0,this.onChangeCallbacks=new Set,this.onInitCallbacks=new Set,this.onTransformCallbacks=new Set,this.wrapperComponent=null,this.contentComponent=null,this.isInitialized=!1,this.bounds=null,this.previousWheelEvent=null,this.wheelStopEventTimer=null,this.wheelAnimationTimer=null,this.isPanning=!1,this.isWheelPanning=!1,this.startCoords=null,this.panStartPosition=null,this.lastTouch=null,this.isPinching=!1,this.distance=null,this.lastDistance=null,this.pinchStartDistance=null,this.pinchStartScale=null,this.pinchMidpoint=null,this.pinchPreviousCenter=null,this.doubleClickStopEventTimer=null,this.velocity=null,this.velocityTime=null,this.lastMousePosition=null,this.isAnimating=!1,this.animation=null,this.animationFrame=null,this.animationResolve=null,this.initObserverTimer=null,this.isInitialLayoutPending=!1,this.measuredSizes=null,this.isResizeAlignmentPending=!1,this.resizeAnimation=null,this.pressedKeys={},this.selectionLock=null,this.mount=function(){t.mounted=!0,t.initializeWindowEvents()},this.unmount=function(){t.mounted=!1,t.cleanupWindowEvents()},this.update=function(n){t.props=n,t.setup=Nr(n),t.wrapperComponent&&t.contentComponent&&!ma(t)&&ce(t,t.state.scale)},this.clearTimers=function(){t.wheelStopEventTimer&&clearTimeout(t.wheelStopEventTimer),t.wheelAnimationTimer&&clearTimeout(t.wheelAnimationTimer),t.doubleClickStopEventTimer&&clearTimeout(t.doubleClickStopEventTimer),t.initObserverTimer&&clearTimeout(t.initObserverTimer),t.wheelStopEventTimer=null,t.wheelAnimationTimer=null,t.doubleClickStopEventTimer=null,t.initObserverTimer=null},this.initializeWindowEvents=function(){var n,i,o,a,s=ft(),l=(n=t.wrapperComponent)===null||n===void 0?void 0:n.ownerDocument,c=l==null?void 0:l.defaultView;(i=t.wrapperComponent)===null||i===void 0||i.addEventListener("wheel",t.onWheelPanning,s),(o=t.wrapperComponent)===null||o===void 0||o.addEventListener("keyup",t.setKeyUnPressed,s),(a=t.wrapperComponent)===null||a===void 0||a.addEventListener("keydown",t.setKeyPressed,s),c==null||c.addEventListener("mousedown",t.onPanningStart,s),c==null||c.addEventListener("mousemove",t.onPanning,s),c==null||c.addEventListener("mouseup",t.onPanningStop,s),l==null||l.addEventListener("mouseleave",t.clearPanning,s),c==null||c.addEventListener("keyup",t.setKeyUnPressed,s),c==null||c.addEventListener("keydown",t.setKeyPressed,s),c==null||c.addEventListener("blur",t.handleWindowBlur)},this.cleanupWindowEvents=function(){var n,i,o,a,s,l=ft(),c=(n=t.wrapperComponent)===null||n===void 0?void 0:n.ownerDocument,u=c==null?void 0:c.defaultView;u==null||u.removeEventListener("mousedown",t.onPanningStart,l),u==null||u.removeEventListener("mousemove",t.onPanning,l),u==null||u.removeEventListener("mouseup",t.onPanningStop,l),c==null||c.removeEventListener("mouseleave",t.clearPanning,l),u==null||u.removeEventListener("keyup",t.setKeyUnPressed,l),u==null||u.removeEventListener("keydown",t.setKeyPressed,l),u==null||u.removeEventListener("blur",t.handleWindowBlur),(i=t.wrapperComponent)===null||i===void 0||i.removeEventListener("wheel",t.onWheelPanning,l),(o=t.wrapperComponent)===null||o===void 0||o.removeEventListener("keyup",t.setKeyUnPressed,l),(a=t.wrapperComponent)===null||a===void 0||a.removeEventListener("keydown",t.setKeyPressed,l),t.cleanupWrapperEvents(),t.clearTimers(),ue(t),t.unlockTextSelection(),(s=t.observer)===null||s===void 0||s.disconnect(),t.observer=void 0,t.isInitialLayoutPending=!1,t.isResizeAlignmentPending=!1,t.resizeAnimation=null},this.cleanupWrapperEvents=function(){var n=t.wrapperComponent;if(n){var i=ft();n.removeEventListener("wheel",t.onWheelZoom,i),n.removeEventListener("dblclick",t.onDoubleClick,i),n.removeEventListener("keydown",t.onKeyboardNavigation,i),n.removeEventListener("touchstart",t.onTouchPanningStart,i),n.removeEventListener("touchmove",t.onTouchPanning,i),n.removeEventListener("touchend",t.onTouchPanningStop,i)}},this.handleInitializeWrapperEvents=function(n){var i=ft();n.addEventListener("wheel",t.onWheelZoom,i),n.addEventListener("dblclick",t.onDoubleClick,i),n.addEventListener("keydown",t.onKeyboardNavigation,i),n.addEventListener("touchstart",t.onTouchPanningStart,i),n.addEventListener("touchmove",t.onTouchPanning,i),n.addEventListener("touchend",t.onTouchPanningStop,i)},this.handleInitialize=function(){var n=t.setup,i=n.centerOnInit,o=n.fitOnInit;if(t.applyTransformation(),t.onInitCallbacks.forEach(function(s){return s(L(t))}),i||o){var a=t.applyInitialLayout();t.isInitialLayoutPending=!0,t.initObserverTimer&&clearTimeout(t.initObserverTimer),a&&(t.initObserverTimer=setTimeout(function(){t.initObserverTimer=null,t.isInitialLayoutPending=!1},5e3))}},this.observeSizes=function(n,i){var o;(o=t.observer)===null||o===void 0||o.disconnect(),t.observer=void 0,t.measuredSizes=Lt(n,i),!(typeof ResizeObserver>"u")&&(t.observer=new ResizeObserver(t.onSizeChange),t.observer.observe(n),t.observer.observe(i))},this.onSizeChange=function(){var n=t,i=n.wrapperComponent,o=n.contentComponent;if(!(!t.mounted||!i||!o)){if(t.isInitialLayoutPending){var a=(o.offsetWidth>0||o.offsetHeight>0)&&i.clientWidth>0&&i.clientHeight>0;if(!a)return;t.isInitialLayoutPending=!1,t.initObserverTimer&&clearTimeout(t.initObserverTimer),t.initObserverTimer=null,t.onInitCallbacks.forEach(function(s){return s(L(t))}),t.applyInitialLayout(),t.measuredSizes=Lt(i,o),ce(t,t.state.scale);return}ga(t)}},this.flushResizeAlignment=function(){t.isResizeAlignmentPending&&(t.isResizeAlignmentPending=!1,mn(t))},this.onWheelZoom=function(n){var i=t.setup.disabled;if(!i){t.syncModifierKeys(n);var o=vn(t,n);o&&(Oa(t,n),_a(t,n),ja(t,n))}},this.onWheelPanning=function(n){var i=t.props.onPanning,o=t.setup.trackPadPanning,a=o.lockAxisX,s=o.lockAxisY;t.syncModifierKeys(n);var l=ba(t,n);if(l){n.cancelable&&n.preventDefault(),n.stopPropagation();var c=t.state,u=c.positionX,d=c.positionY,f=u-n.deltaX,p=d-n.deltaY,v=a?u:f,m=s?d:p,P=t.setup.autoAlignment,w=P.sizeX,A=P.sizeY,C=Oe(t,w),O=Oe(t,A);v===u&&m===d||(Aa(t,n),rn(t,v,m,C,O),F(L(t),n,i),Ra(t,n))}},this.onPanningStart=function(n){var i=t.setup,o=i.disabled,a=i.panning,s=t.props.onPanningStart;if(!(o||a.disabled)){t.syncModifierKeys(n);var l=jr(t,n);if(l){var c=t.isPressingKeys(t.setup.panning.activationKeys);c&&(n.button===0&&!t.setup.panning.allowLeftClickPan||n.button===1&&!t.setup.panning.allowMiddleClickPan||n.button===2&&!t.setup.panning.allowRightClickPan||(n.cancelable&&n.preventDefault(),n.stopPropagation(),ue(t),xr(t,n),t.lockTextSelection(),t.focusForKeyboard(),F(L(t),n,s)))}}},this.onPanning=function(n){var i=t.setup.disabled,o=t.props.onPanning;if(!i){if(t.syncModifierKeys(n),t.isPanning&&n.buttons===0){t.clearPanning(n);return}var a=Ar(t);if(a){var s=t.isPressingKeys(t.setup.panning.activationKeys);s&&(n.cancelable&&n.preventDefault(),n.stopPropagation(),zr(t,n.clientX,n.clientY,Te.MOUSE),F(L(t),n,o))}}},this.onPanningStop=function(n){var i=t.setup.panning.velocityDisabled,o=t.props.onPanningStop;t.isPanning&&(t.unlockTextSelection(),Wo(t,i),F(L(t),n,o),t.flushResizeAlignment())},this.onPinchStart=function(n){var i=t.setup.disabled,o=t.props.onPinchStart;if(!i){var a=Sa(t,n);a&&(xa(t,n),ue(t),F(L(t),n,o))}},this.onPinch=function(n){var i=t.setup.disabled,o=t.props.onPinch;if(!i){var a=Pa(t);a&&(n.cancelable&&n.preventDefault(),n.stopPropagation(),za(t,n),F(L(t),n,o))}},this.onPinchStop=function(n){var i=t.props.onPinchStop;t.pinchStartScale&&(Da(t),F(L(t),n,i),t.flushResizeAlignment())},this.onTouchPanningStart=function(n){var i=t.setup,o=i.disabled,a=i.doubleClick,s=t.props.onPanningStart;if(!o){var l=!(a!=null&&a.disabled),c=t.lastTouch&&+new Date-t.lastTouch<200;if(l&&c&&n.touches.length===1)t.lastTouch=null,t.onDoubleClick(n);else{t.lastTouch=+new Date,ue(t);var u=n.touches,d=u.length===1,f=u.length===2,p=jr(t,n);if(d){if(!p||t.setup.panning.disabled)return;ue(t),xr(t,n),t.lockTextSelection(),t.focusForKeyboard(),F(L(t),n,s)}f&&t.onPinchStart(n)}}},this.onTouchPanning=function(n){var i=t.setup.disabled,o=t.props.onPanning;if(t.isPanning&&n.touches.length===1){if(i)return;var a=Ar(t);if(!a)return;n.cancelable&&n.preventDefault(),n.stopPropagation();var s=n.touches[0];zr(t,s.clientX,s.clientY,Te.TOUCH),F(L(t),n,o)}else n.touches.length>1&&t.onPinch(n)},this.onTouchPanningStop=function(n){t.onPanningStop(n),t.onPinchStop(n)},this.onDoubleClick=function(n){var i=t.setup.disabled;if(!i){var o=Xa(t,n);o&&Ya(t,n)}},this.clearPanning=function(n){t.isPanning&&t.onPanningStop(n)},this.handleWindowBlur=function(){t.pressedKeys={},t.isPanning&&(t.isPanning=!1,t.startCoords=null),t.unlockTextSelection(),t.flushResizeAlignment()},this.syncModifierKeys=function(n){var i=n.ctrlKey,o=n.metaKey,a=n.shiftKey,s=n.altKey;typeof i=="boolean"&&(t.pressedKeys.Control=i),typeof o=="boolean"&&(t.pressedKeys.Meta=o),typeof a=="boolean"&&(t.pressedKeys.Shift=a),typeof s=="boolean"&&(t.pressedKeys.Alt=s)},this.setKeyPressed=function(n){t.pressedKeys[n.key]=!0},this.setKeyUnPressed=function(n){t.pressedKeys[n.key]=!1},this.isPressingKeys=function(n){return typeof n=="function"?n(Object.entries(t.pressedKeys).filter(function(i){var o=i[1];return o}).map(function(i){var o=i[0];return o})):n.length?!!n.every(function(i){return t.pressedKeys[i]}):!0},this.onKeyboardNavigation=function(n){pa(t,n)},this.focusForKeyboard=function(){var n,i=t.wrapperComponent;if(!(!i||t.setup.keyboard.disabled)){var o=(n=i.ownerDocument)===null||n===void 0?void 0:n.activeElement;o&&i.contains(o)||typeof i.focus=="function"&&i.focus({preventScroll:!0})}},this.lockTextSelection=function(){var n=t.wrapperComponent;!n||t.selectionLock||(t.selectionLock={userSelect:n.style.userSelect,webkitUserSelect:n.style.webkitUserSelect},n.style.userSelect="none",n.style.webkitUserSelect="none")},this.unlockTextSelection=function(){var n=t.selectionLock;t.selectionLock=null;var i=t.wrapperComponent;!i||!n||(i.style.userSelect=n.userSelect,i.style.webkitUserSelect=n.webkitUserSelect)},this.applyInitialLayout=function(){var n=t.setup.fitOnInit,i=t,o=i.wrapperComponent,a=i.contentComponent,s=!!o&&!!a&&o.clientWidth>0&&o.clientHeight>0&&(a.offsetWidth>0||a.offsetHeight>0);if(n){var l=nr(t,n==="cover"?"cover":"contain");if(l)return t.setState(l.scale,l.positionX,l.positionY),s}return t.setCenter(),s},this.setCenter=function(){if(t.wrapperComponent&&t.contentComponent){var n=Ot(t.state.scale,t.wrapperComponent,t.contentComponent);t.setState(n.scale,n.positionX,n.positionY)}},this.handleTransformStyles=function(n,i,o){return t.props.customTransform?t.props.customTransform(n,i,o):fn(n,i,o)},this.getContext=function(){return L(t)},this.applyTransformation=function(){if(!(!t.mounted||!t.contentComponent)){var n=t.state,i=n.scale,o=n.positionX,a=n.positionY,s=t.handleTransformStyles(o,a,i);t.props.detached||(t.contentComponent.style.transform=s),t.onTransformCallbacks.forEach(function(l){return l({scale:i,positionX:o,positionY:a,previousScale:t.state.previousScale,ref:L(t)})})}},this.setState=function(n,i,o){var a=t.props.onTransform;if(!Number.isNaN(n)&&!Number.isNaN(i)&&!Number.isNaN(o)){var s=Math.max(n,1e-7);s!==t.state.scale&&(t.state.previousScale=t.state.scale,t.state.scale=s),t.state.positionX=i,t.state.positionY=o,t.applyTransformation();var l=L(t);t.onChangeCallbacks.forEach(function(c){return c(l)}),F(l,{scale:t.state.scale,positionX:i,positionY:o},a)}else console.error("Detected NaN set state values")},this.onTransform=function(n){return t.onTransformCallbacks.has(n)||t.onTransformCallbacks.add(n),function(){t.onTransformCallbacks.delete(n)}},this.onChange=function(n){return t.onChangeCallbacks.has(n)||t.onChangeCallbacks.add(n),function(){t.onChangeCallbacks.delete(n)}},this.onInit=function(n){return t.onInitCallbacks.has(n)||t.onInitCallbacks.add(n),function(){t.onInitCallbacks.delete(n)}},this.init=function(n,i){t.mounted=!0,t.cleanupWindowEvents(),t.wrapperComponent=n,t.contentComponent=i,ce(t,t.state.scale),t.handleInitializeWrapperEvents(n),t.handleInitialize(),t.observeSizes(n,i),t.initializeWindowEvents(),t.isInitialized=!0;var o=L(t);F(o,void 0,t.props.onInit),ua(t.props.ref,o)},this.props=r,this.setup=Nr(this.props),this.state=on(this.props)}return e})(),lt=kt.createContext(null),Ba=function(e,r){return typeof e=="function"?e(r):e},La=kt.forwardRef(function(e,r){var t=g.useRef(null);t.current===null&&(t.current=new Wa(e));var n=t.current,i=Ba(e.children,nt(n));return g.useImperativeHandle(r,function(){return nt(n)},[n]),g.useEffect(function(){return n.mount(),function(){n.unmount()}},[n]),g.useEffect(function(){n.update(e)},[n,e]),h.jsx(lt.Provider,de({value:n},{children:i}))});kt.forwardRef(function(e,r){var t=g.useRef(null),n=g.useContext(lt);return or(function(){var i=function(o){if(t.current){var a=0,s=0;t.current.style.transform=n.handleTransformStyles(a,s,1/o)}};return i(n.state.scale),n.onChange(function(o){i(o.instance.state.scale)})},[n]),h.jsx("div",de({},e,{ref:ca([t,r])}))});function Fa(e,r){r===void 0&&(r={});var t=r.insertAt;if(!(typeof document>"u")){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",t==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var qa=`.transform-component-module_wrapper__SPB86 {
24
+ `||r.slice(12,16)!=="IHDR")return null;const t=o=>r.charCodeAt(o)*2**24+(r.charCodeAt(o+1)<<16)+(r.charCodeAt(o+2)<<8)+r.charCodeAt(o+3),n=t(16),i=t(20);return n>0&&i>0&&n<=1568&&i<=1568?{width:n,height:i}:null}catch{return null}}let jt=null;async function Sr(){return jt===null&&(jt=(await je(()=>import("./html-to-image-cl8bZGTj.js"),[])).default),jt}let At=null;async function Pi(){if(At===null){const e=await je(()=>import("./gifenc.esm-sOOlYEo8.js"),[]);At={GIFEncoder:e.GIFEncoder,quantize:e.quantize,applyPalette:e.applyPalette}}return At}async function kr(e,r,t=()=>{}){if(e.length===0)return{ok:!1,error:"The recording has no frames in it."};t();const{GIFEncoder:n,quantize:i,applyPalette:o}=await Pi();t();const a=e[0],s=e[e.length-1],l=new Uint8ClampedArray(a.data.length+s.data.length);l.set(a.data,0),l.set(s.data,a.data.length);const c=i(l,256),u=n();for(let f=0;f<e.length;f++){t();const p=e[f];if(u.writeFrame(o(p.data,c),p.width,p.height,{...f===0?{palette:c,repeat:0}:{},delay:r.frameMs}),u.bytesView().byteLength>r.maxBytes)return{ok:!1,error:`The recording came out bigger than ${Math.round(r.maxBytes/1024/1024)} MB, so it was not saved.`}}u.finish();const d=u.bytes();return d.byteLength>r.maxBytes?{ok:!1,error:`The recording came out bigger than ${Math.round(r.maxBytes/1024/1024)} MB, so it was not saved.`}:{ok:!0,bytes:d}}async function Ei(e,r,t=()=>{}){const n=[],i=document.createElement("canvas");let o=0,a=0;try{for(let s=0;s<Math.min(e.length,62);s++){t();const l=e[s];if(!Qr(l)){e[s]="";continue}const c=await Oi(l);e[s]="";try{if(t(),!c)continue;if(!o){const f=Math.min(1,Math.min(800,r)/Math.max(c.width,c.height,1));o=Math.max(1,Math.round(c.width*f)),a=Math.max(1,Math.round(c.height*f)),i.width=o,i.height=a}const u=i.getContext("2d",{willReadFrequently:!0});if(!u)return[];u.fillStyle="#ffffff",u.fillRect(0,0,o,a);const d=Math.min(o/c.width,a/c.height);u.drawImage(c,0,0,Math.round(c.width*d),Math.round(c.height*d)),t(),n.push({data:u.getImageData(0,0,o,a).data,width:o,height:a})}finally{c&&(c.src="")}}return n}catch(s){throw n.length=0,s}finally{e.length=0,i.width=0,i.height=0}}function Ti(e,r=()=>{}){const t=document.createElement("canvas"),n=document.createElement("canvas");try{for(let i=0;i<e.length;i++){r();const o=e[i];n.width=o.width,n.height=o.height,t.width=Math.max(1,Math.round(o.width/2)),t.height=Math.max(1,Math.round(o.height/2));const a=n.getContext("2d"),s=t.getContext("2d",{willReadFrequently:!0});if(!a||!s)throw new Error("Canvas pixels are unavailable");a.putImageData(new ImageData(new Uint8ClampedArray(o.data),o.width,o.height),0,0),s.drawImage(n,0,0,t.width,t.height),e[i]={data:s.getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}}finally{n.width=n.height=t.width=t.height=0}}function Oi(e){return new Promise(r=>{const t=new Image;t.onload=()=>{t.onload=t.onerror=null,r(t)},t.onerror=()=>{t.onload=t.onerror=null,t.src="",r(null)},t.src=e})}function Pr(e,r,t){const n=t.slice().buffer;return{name:e,type:r,size:t.byteLength,arrayBuffer:async()=>n}}function _i(e){const r=atob(e.slice(e.indexOf(",")+1));return Uint8Array.from(r,t=>t.charCodeAt(0))}const ji=8e3;function Ai(e){const r=pe(),t=g.useRef(r);g.useLayoutEffect(()=>{t.current=r});const[n]=Kt(),[i,o]=g.useState(0),a=g.useRef(null),s=g.useRef(new Map),l=g.useRef(null),c=g.useRef({console:[],network:[],entryBytes:0,overheadBytes:0}),u=g.useRef(null),d=g.useRef(-1),f=g.useRef(null),p=g.useRef(null),v=g.useRef(!1),m=g.useRef(-1/0),k=g.useRef(!1),w=g.useRef(null),A=g.useRef(0),C=g.useRef(null),O=g.useRef(null),z=g.useRef(!1),Y=g.useRef(null),N=g.useRef({...e,sessionId:n}),M=g.useRef(Promise.resolve()),W=g.useRef(()=>{}),q=g.useRef({initialize:R,retire:E,consume:we,register:se,eligiblePending:le,refuseRequest:G,live:Z,captureFrame:He,valid:Be,reportRecordingStart:Xe,cancelReservation:We,finish:ct});g.useLayoutEffect(()=>{q.current={initialize:R,retire:E,consume:we,register:se,eligiblePending:le,refuseRequest:G,live:Z,captureFrame:He,valid:Be,reportRecordingStart:Xe,cancelReservation:We,finish:ct}});const B=P=>Y.current===P||K.getState().openDocuments.some(b=>b.id===P&&b.openedHere);function y(P,{active:b,activation:T=!1,keepalive:S=!1,reset:x=!1}){if(!P.sessionId)return;const $={documentId:P.documentId,logicalUrl:P.logicalUrl,bridgeGeneration:P.generation,seq:Math.max(0,d.current),console:[],network:[],active:b,activation:T,instrumented:P.ready&&!P.retired,...x?{reset:!0}:{}};M.current=M.current.then(()=>t.current.ingestDevtoolsCapture(P.sessionId,$,S?{keepalive:!0}:void 0)).catch(()=>{})}function E(){var T;const P=a.current;P&&(P.retired=!0),a.current=null,u.current!==null&&clearTimeout(u.current),u.current=null,l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0},d.current=-1,m.current=-1/0,k.current=!1;for(const[S,x]of s.current)x.life.sessionId&&x.deadline>Date.now()&&x.kind!=="frame"&&G(S,x.kind,x.life,"The frame changed while this request was pending."),clearTimeout(x.timer),(T=x.resolve)==null||T.call(x,null);s.current.clear(),P&&y(P,{active:!1});const b=w.current;b&&(clearTimeout(b.reservationTimer),b.cancelled=!0,b.abort.abort(),b.frames.length=0,b.finishing||(b.drawn.length=0,w.current=null)),C.current!==null&&cancelAnimationFrame(C.current),C.current=null,A.current=0,o(0)}function R({loadActivation:P,reset:b=!1}={}){var H,ne;const T=N.current,S=(H=T.iframeRef.current)==null?void 0:H.contentWindow;if(v.current||!S||!T.bridgeEligibility||!T.resolvedSource)return;const x={generation:crypto.randomUUID(),frame:S,sessionId:T.sessionId,documentId:T.documentId,logicalUrl:T.logicalUrl,source:T.resolvedSource,origin:T.bridgeEligibility==="served-document"?"null":T.previewOrigin,ready:!1,activation:!1,retired:!1};a.current=x;const $=P??(z.current||O.current!==x.documentId&&B(x.documentId));x.activation=$,z.current=!1,O.current=x.documentId,y(x,{active:!0,activation:$,reset:b}),((ne=f.current)==null?void 0:ne.frame)===S&&f.current.source===T.resolvedSource&&f.current.reload===T.reloadNonce&&f.current.documentId===T.documentId&&f.current.logicalUrl===T.logicalUrl&&S.postMessage({__dorkosDevtools:"init",bridgeGeneration:x.generation},"*")}g.useLayoutEffect(()=>{var S;N.current={...e,sessionId:n};const P={frame:(S=e.iframeRef.current)==null?void 0:S.contentWindow,sessionId:n,documentId:e.documentId,logicalUrl:e.logicalUrl,source:e.resolvedSource,eligibility:e.bridgeEligibility,origin:e.previewOrigin,reload:e.reloadNonce},b=p.current;if(!b||Object.keys(P).some(x=>P[x]!==b[x])){const x=!b||b.frame!==P.frame||b.documentId!==P.documentId||b.logicalUrl!==P.logicalUrl||b.source!==P.source||b.reload!==P.reload;p.current=P,v.current=!1,E(),R({reset:x})}});const _=g.useCallback(()=>{var $,H,ne;const{initialize:P,retire:b}=q.current,T=N.current,S=($=T.iframeRef.current)==null?void 0:$.contentWindow,x=(H=a.current)!=null&&H.ready?!1:(ne=a.current)==null?void 0:ne.activation;S&&T.resolvedSource&&(f.current={frame:S,source:T.resolvedSource,reload:T.reloadNonce,documentId:T.documentId,logicalUrl:T.logicalUrl}),v.current=!1,b(),P({loadActivation:x,reset:!0})},[]),D=g.useCallback(()=>{const P=a.current;z.current=!0,Y.current=N.current.documentId,P&&W.current({active:!0,activation:!0})},[]);g.useLayoutEffect(()=>{W.current=P=>{a.current&&y(a.current,P)}});function Z(P){return a.current===P&&!P.retired}function G(P,b,T,S){if(!T.sessionId)return;const x={requestId:P,bridgeGeneration:T.generation,documentId:T.documentId,hostOutcome:"host",error:S};b==="action"?t.current.postDevtoolsAction(T.sessionId,{...x,ok:!1}).catch(()=>{}):t.current.ingestDevtoolsCapture(T.sessionId,{...x,logicalUrl:T.logicalUrl,seq:Math.max(0,d.current),console:[],network:[],screenshot:{requestId:P,error:S}}).catch(()=>{})}function se(P,b,T,{capture:S=!1,resolve:x,timeoutMs:$=8e3}={}){if(s.current.size>=ze.pending||s.current.has(P))return null;const H=setTimeout(()=>me(P,ne),$),ne={kind:b,life:T,capture:S,deadline:Date.now()+$,timer:H,resolve:x};return s.current.set(P,ne),ne}function me(P,b){var T;s.current.get(P)===b&&(s.current.delete(P),clearTimeout(b.timer),(T=b.resolve)==null||T.call(b,null))}function le(P,b,T){return s.current.get(P)!==b||b.life!==T||!Z(T)?!1:Date.now()>=b.deadline?(me(P,b),!1):!0}function we(P,b,T){const S=s.current.get(P);return!S||S.life!==T||S.kind!==b&&!(b==="capture"&&S.kind==="frame")||!le(P,S,T)?null:(s.current.delete(P),clearTimeout(S.timer),S)}g.useEffect(()=>{const{initialize:P,retire:b,consume:T}=q.current;function S(){u.current=null;const he=l.current;l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0};const j=a.current;he&&j&&!j.retired&&j.sessionId&&he.bridgeGeneration===j.generation&&t.current.ingestDevtoolsCapture(j.sessionId,he)}function x(he){var cr,dr,fr,pr;const j=a.current;if(!j||j.retired||he.source!==j.frame||he.origin!==j.origin||((cr=f.current)==null?void 0:cr.frame)!==j.frame||f.current.source!==j.source||f.current.reload!==N.current.reloadNonce||f.current.documentId!==j.documentId||f.current.logicalUrl!==j.logicalUrl)return;const X=he.data;if(!X||typeof X!="object"||typeof X.__dorkosDevtools!="string"||!["hello","ready","navigated","resource-error","batch","capture-result","act-result"].includes(X.__dorkosDevtools)||X.__dorkosDevtools!=="hello"&&X.bridgeGeneration!==j.generation)return;const oe=X.__dorkosDevtools==="batch";if(oe){if(!j.ready||!j.sessionId||X.bridgeGeneration!==j.generation||!Number.isSafeInteger(X.seq)||X.seq<0||X.seq<=d.current)return;const V=Date.now();if(V-m.current<ze.batchMs){l.current?l.current.dropped=!0:k.current=!0;return}m.current=V}const U=ki(X);if(!U){oe&&(k.current=!0);return}if(U.__dorkosDevtools==="hello"){j.frame.postMessage({__dorkosDevtools:"init",bridgeGeneration:j.generation},"*");return}if(U.bridgeGeneration!==j.generation)return;if(U.__dorkosDevtools==="ready"){j.ready||(j.ready=!0,j.activation=!1,y(j,{active:!0}));return}if(!j.ready)return;if(U.__dorkosDevtools==="navigated"){v.current=!0,b();return}if(U.__dorkosDevtools==="resource-error"){A.current=Math.min(ze.resourceErrors,A.current+1),C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null,Z(j)&&o(A.current)}));return}if(!j.sessionId)return;if(U.__dorkosDevtools==="batch"){if(U.seq<=d.current)return;d.current=U.seq;const V=l.current??{documentId:j.documentId,logicalUrl:j.logicalUrl,bridgeGeneration:j.generation,seq:U.seq,console:[],network:[]};V.seq=U.seq,k.current&&(V.dropped=!0),k.current=!1;const Pe=c.current,hr=new TextEncoder;if(l.current||(Pe.overheadBytes=hr.encode(JSON.stringify({...V,seq:Number.MAX_SAFE_INTEGER,dropped:!0,console:[],network:[]})).length),Pe.overheadBytes>ze.queueBytes){l.current=null,c.current={console:[],network:[],entryBytes:0,overheadBytes:0},k.current=!0;return}for(const[Ze,Fn]of[["console",U.console],["network",U.network]])for(const qn of Fn){const mr=hr.encode(JSON.stringify(qn)).length;Pe[Ze].push(mr),Pe.entryBytes+=mr}V.console.push(...U.console),V.network.push(...U.network);const Ln=()=>Pe.overheadBytes+Pe.entryBytes+Math.max(0,V.console.length-1)+Math.max(0,V.network.length-1);for(;V.console.length>500||V.network.length>200||Ln()>ze.queueBytes;){V.dropped=!0;const Ze=(((dr=V.console[0])==null?void 0:dr.timestamp)??1/0)<=(((fr=V.network[0])==null?void 0:fr.timestamp)??1/0)?"console":"network";if(!V[Ze].length)break;V[Ze].shift(),Pe.entryBytes-=Pe[Ze].shift()}l.current=V,u.current===null&&(u.current=setTimeout(S,ze.batchMs));return}if(U.__dorkosDevtools==="capture-result"){const V=T(U.requestId,"capture",j);if(!V)return;if(V.kind==="frame"){(pr=V.resolve)==null||pr.call(V,U.dataUrl??null);return}t.current.ingestDevtoolsCapture(j.sessionId,{bridgeGeneration:j.generation,documentId:j.documentId,logicalUrl:j.logicalUrl,seq:Math.max(0,d.current),console:[],network:[],hostOutcome:"page-reported",screenshot:{requestId:U.requestId,dataUrl:U.dataUrl,error:U.error}});return}const Ue=T(U.requestId,"action",j);if(!Ue)return;const Re=w.current,ur=Ue.capture&&U.dataUrl!==void 0&&Re!==null&&Re.life===j&&Re.activated&&!Re.finishing&&!Re.cancelled&&Re.frames.length<61;ur&&Re.frames.push(U.dataUrl);const{__dorkosDevtools:pl,dataUrl:hl,...Bn}=U;t.current.postDevtoolsAction(j.sessionId,{...Bn,hostOutcome:"page-reported",documentId:j.documentId,captured:ur||void 0})}window.addEventListener("message",x);const $=setInterval(()=>W.current({active:!0}),15e3),H=()=>{a.current||P(),W.current({active:!0,activation:!0})},ne=()=>{W.current({active:!1,keepalive:!0}),b()},ae=()=>{document.visibilityState==="visible"&&H()};return window.addEventListener("focus",H),window.addEventListener("pagehide",ne),window.addEventListener("pageshow",H),document.addEventListener("visibilitychange",ae),()=>{window.removeEventListener("message",x),clearInterval($),window.removeEventListener("focus",H),window.removeEventListener("pagehide",ne),window.removeEventListener("pageshow",H),document.removeEventListener("visibilitychange",ae),b()}},[]),g.useEffect(()=>Jn.subscribeSessionEvent((P,b)=>{if(b.type!=="devtools_capture_request"&&b.type!=="devtools_action_request"&&b.type!=="devtools_recording_request")return;const{register:T,eligiblePending:S,refuseRequest:x,captureFrame:$,valid:H,finish:ne,reportRecordingStart:ae,cancelReservation:he}=q.current,j=a.current;if(!(!(j!=null&&j.ready)||!j.sessionId||j.retired||b.targetClientId!==t.current.clientId||b.documentId!==j.documentId||b.bridgeGeneration!==j.generation)){if(b.type==="devtools_capture_request"||b.type==="devtools_action_request"){const X=b.type==="devtools_action_request",oe=T(b.requestId,X?"action":"capture",j,{capture:X&&!!b.capture,timeoutMs:X&&b.command.action==="wait_for"?Math.min(1e4,b.command.timeoutMs)+2e3:8e3});if(!oe){s.current.has(b.requestId)||x(b.requestId,X?"action":"capture",j,"Too many browser requests are waiting. Try again when one finishes.");return}const U=Ue=>{S(b.requestId,oe,j)&&j.frame.postMessage(X?{__dorkosDevtools:"act-request",bridgeGeneration:j.generation,requestId:b.requestId,documentId:j.documentId,command:b.command,...b.capture?{capture:!0,lib:Ue}:{}}:{__dorkosDevtools:"capture-request",bridgeGeneration:j.generation,requestId:b.requestId,lib:Ue},"*")};!X||b.capture?Sr().then(U,()=>U()):U()}if(b.type==="devtools_recording_request"){if(b.action==="cancel-start"){he(b.recordingId,b.requestId,j);return}if(b.action==="confirm-start"){const X=w.current;if(!X||X.id!==b.recordingId||X.startRequestId!==b.requestId||X.life!==j||X.finishing||!H(X))return;if(!X.activated){if(performance.now()>=X.reservationDeadline){he(X.id,X.startRequestId,j),ae(b,j,{phase:"started",ok:!1,error:"This recording reservation expired before capture could start."});return}clearTimeout(X.reservationTimer),X.activated=!0,X.startedAt=Date.now(),$(j).then(oe=>{oe&&H(X)&&X.frames.push(oe)})}ae(b,j,{phase:"started",ok:!0});return}if(b.action==="start"){const X=b.reservationTimeoutMs;if(!Number.isSafeInteger(X)||!X||X<1||X>ji){ae(b,j,{phase:"reserved",ok:!1,error:"This recording request has no valid reservation timeout."});return}if(w.current){ae(b,j,{phase:"reserved",ok:!1,error:"Another recording in this window is still running or being saved. Wait for it to finish, then start again."});return}const oe={id:b.recordingId,startRequestId:b.requestId,activated:!1,reservationDeadline:performance.now()+X,life:j,startedAt:Date.now(),frames:[],drawn:[],finishing:!1,cancelled:!1,abort:new AbortController};w.current=oe,oe.reservationTimer=setTimeout(()=>{w.current===oe&&!oe.activated&&he(oe.id,oe.startRequestId,j)},X),ae(b,j,{phase:"reserved",ok:!0})}else ne(b.requestId,b.recordingId,j)}}}),[]);function Xe(P,b,T){!Z(b)||!b.sessionId||t.current.ingestDevtoolsCapture(b.sessionId,{hostOutcome:"host",documentId:b.documentId,bridgeGeneration:b.generation,seq:0,console:[],network:[],recordingStart:{...T,requestId:P.requestId,recordingId:P.recordingId}}).catch(()=>{})}function We(P,b,T){var x;const S=w.current;if(!(!S||S.id!==P||S.startRequestId!==b||S.life!==T||S.finishing)){clearTimeout(S.reservationTimer),S.cancelled=!0,S.abort.abort(),S.frames.length=0,S.drawn.length=0;for(const[$,H]of s.current)H.life===T&&H.kind==="frame"&&(clearTimeout(H.timer),(x=H.resolve)==null||x.call(H,null),s.current.delete($));w.current=null}}function Be(P){return w.current===P&&!P.cancelled&&Z(P.life)}function He(P){const b=`frame-${crypto.randomUUID()}`;return new Promise(T=>{const S=se(b,"frame",P,{resolve:T});if(!S){T(null);return}Sr().then(x=>{le(b,S,P)&&P.frame.postMessage({__dorkosDevtools:"capture-request",bridgeGeneration:P.generation,requestId:b,lib:x},"*")},()=>{me(b,S)})})}async function ct(P,b,T){const S=w.current;if(!S||!S.activated||S.id!==b||S.life!==T){Z(T)&&await t.current.uploadDevtoolsRecording(T.sessionId,{requestId:P,bridgeGeneration:T.generation,documentId:T.documentId,hostOutcome:"host",error:"The window showing that page stopped recording before it could be saved."}).catch(()=>{});return}if(S.finishing)return;S.finishing=!0;const x=()=>{if(!Be(S))throw new Error("retired")},$={requestId:P,bridgeGeneration:T.generation,documentId:T.documentId};try{const H=await He(T);x(),H&&S.frames.length<ze.frames&&S.frames.push(H);const ne=S.frames.length?_i(S.frames[S.frames.length-1]):new Uint8Array;S.drawn=await Ei(S.frames,800,x),x();let ae=await kr(S.drawn,{frameMs:500,maxBytes:8*1024*1024},x);if(x(),!ae.ok&&S.drawn.length&&(Ti(S.drawn,x),ae=await kr(S.drawn,{frameMs:500,maxBytes:8*1024*1024},x),x()),!ae.ok){await t.current.uploadDevtoolsRecording(T.sessionId,{...$,hostOutcome:"host",error:ae.error},{signal:S.abort.signal}),x();return}x(),await t.current.uploadDevtoolsRecording(T.sessionId,{...$,frames:S.drawn.length,durationMs:Date.now()-S.startedAt,recording:Pr(`${b}.gif`,"image/gif",ae.bytes),keyframe:Pr(`${b}.png`,"image/png",ne)},{signal:S.abort.signal}),x()}catch{Be(S)&&await t.current.uploadDevtoolsRecording(T.sessionId,{...$,hostOutcome:"host",error:"This window could not turn that recording into a file."},{signal:S.abort.signal}).catch(()=>{})}finally{S.frames.length=0,S.drawn.length=0,w.current===S&&(w.current=null)}}return{resourceErrorCount:i,notePersonNavigated:D,noteFrameLoaded:_}}const Ri=15e3;function xi(e){const r=e instanceof Error?e.message.trim():"";return r.length>0?r:"Couldn’t reach DorkOS. Check your network and try again."}function zi(e){const r=pe();return{open:g.useCallback(async t=>{await r.openRoomCanvasDocument(e,t)},[r,e]),update:g.useCallback(async(t,n)=>{await r.updateRoomCanvasDocument(e,t,{content:n})},[r,e]),pin:g.useCallback(async(t,n)=>{await r.updateRoomCanvasDocument(e,t,{pinned:n})},[r,e]),close:g.useCallback(async t=>{await r.closeRoomCanvasDocument(e,t)},[r,e])}}function Di(e,r){const t=pe(),n=K(i=>i.setRoomCanvasEditing);g.useEffect(()=>{if(n(e,r),r===null)return;const i=a=>{t.setRoomCanvasEditing(e,r,a).catch(s=>{console.warn("[room-canvas] edit lock failed",{roomId:e,documentId:r,err:s})})};i(!0);const o=setInterval(()=>i(!0),Ri);return()=>{clearInterval(o),i(!1),n(e,null)}},[t,e,r,n])}const Ni=400;function yl(e,r){const t=pe(),n=K(i=>i.roomCanvasPresenceEpoch[e]??0);g.useEffect(()=>{const i=s=>{t.setRoomCanvasViewing(e,s).catch(l=>{console.warn("[room-canvas] could not say where we are looking",{roomId:e,err:l})})};let o=!1;const a=setTimeout(()=>{o=!0,i(r)},Ni);return()=>{clearTimeout(a),o&&i(null)}},[t,e,r,n])}const Mi="allow-scripts allow-forms allow-popups allow-modals",Rt="allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-downloads",Yi=new Set(["javascript:","data:","blob:"]),Xi=new Set(["localhost","127.0.0.1","0.0.0.0","[::1]","::1"]);function er(e){return Xi.has(e)||e.endsWith(".localhost")}function Wi(e){return er(e)?"direct":"server"}function Bi(e,r){let t;try{t=new URL(e)}catch{return null}const n=t.searchParams.get(Er),i=new URL(t.origin),o=r.indexOf("?");return i.pathname=(o===-1?r:r.slice(0,o))||"/",i.search=o===-1?"":r.slice(o),n!==null&&i.searchParams.set(Er,n),i.toString()}const Er="__dorkos_preview",Li="/__dorkos_preview/health";function Fi(e){return e==="https:"?443:80}function Kr(e){let r;try{r=new URL(e)}catch{return{mode:"serve",path:e}}if(Yi.has(r.protocol))return{mode:"blocked"};if(r.protocol==="file:")return{mode:"serve",path:decodeURIComponent(r.pathname)};if(r.protocol==="http:"||r.protocol==="https:"){if(er(r.hostname)){const t=r.port?Number(r.port):Fi(r.protocol);return{mode:"proxy",hostname:r.hostname,port:t,path:`${r.pathname}${r.search}`}}return{mode:"external",url:e}}return{mode:"blocked"}}function qi(e){const r=e.trim();if(r===""||/^[a-z][a-z0-9+.-]*:\/\//i.test(r)||r.startsWith("/")||r.startsWith("./")||r.startsWith("../"))return r;const t=r.split("/")[0];if(r.includes("/")&&!t.includes(".")&&!t.includes(":"))return r;const i=t.split(":")[0];return`${er(i)?"http":"https"}://${r}`}function Hi(e){const r=Kr(e);if(r.mode==="serve")return{kind:"local",path:r.path};if(r.mode==="blocked")return{kind:"raw",text:e};try{const t=new URL(e),n=t.host.replace(/^www\./,""),i=t.pathname==="/"&&t.search===""&&t.hash===""?"":`${t.pathname}${t.search}${t.hash}`;return{kind:"url",host:n,rest:i}}catch{return{kind:"raw",text:e}}}const Ui=2e3;async function Tr(e,r=globalThis.fetch,t=Ui){const n=new AbortController,i=setTimeout(()=>n.abort(),t);try{return await r(e,{mode:"no-cors",cache:"no-store",signal:n.signal}),!0}catch{return n.signal.aborted}finally{clearTimeout(i)}}function Zi({target:e,currentUrl:r,strategy:t,cwd:n,reloadNonce:i}){const o=JSON.stringify([r,t,n,i]),[a,s]=g.useState(null),[l,c]=g.useState(null),[u,d]=g.useState(null),f=pe(),p=g.useRef(f);return g.useEffect(()=>{p.current=f}),g.useEffect(()=>{const v=p.current;let m=!1;const k=O=>{s(o),c(O)};async function w(O){if(n===null){d({kind:"no-session"});return}try{const z=await v.createServeUrl(n,O);if(m)return;z===null?d({kind:"unsupported"}):k({src:z,sandbox:Mi,previewOrigin:null,bridgeEligibility:"served-document"})}catch{m||d({kind:"failed"})}}async function A(O,z){let Y;try{const M=await v.probeLoopbackPort(O);Y=M===null?"unknown":M.listening}catch{Y="unknown"}if(m)return;let N=null;if(Y!==!1){let M=null;try{M=await v.createProxyUrl(O)}catch{if(m)return;N={kind:"failed"}}if(m)return;if((M==null?void 0:M.unavailable)==="tunnel"){d({kind:"tunnel"});return}if((M==null?void 0:M.unavailable)==="no-port"&&(N={kind:"no-port"}),M!=null&&M.url){const W=new URL(M.url);if(await Tr(`${W.origin}${Li}`)){if(m)return;const q=Bi(M.url,z);if(q!==null){k({src:q,sandbox:Rt,previewOrigin:W.origin,bridgeEligibility:"preview-listener"});return}}if(m)return;N={kind:"origin-unreachable",host:W.hostname,listenPort:W.port}}}if(t==="direct"&&await Tr(r)){if(m)return;k({src:r,sandbox:Rt,previewOrigin:null,bridgeEligibility:null});return}m||d(N??{kind:"no-upstream"})}async function C(){if(d(null),c(null),e.mode!=="blocked"){if(e.mode==="external"){k({src:e.url,sandbox:Rt,previewOrigin:null,bridgeEligibility:null});return}return e.mode==="serve"?w(e.path):A(e.port,e.path)}}return C(),()=>{m=!0}},[e,r,t,n,i,o]),{resolved:a===o?l:null,resolveError:u}}const Vi=1e4;function Gi(e,r){if(e&&e.contentUrl===r&&e.stack.length>0){const t=Math.min(Math.max(e.cursor,0),e.stack.length-1);return{stack:e.stack,cursor:t}}return{stack:[r],cursor:0}}function $i({documentId:e,content:r}){const t=K(_=>_.selectedCwd),n=K(_=>_.writeBrowserHistory),[i]=g.useState(()=>Gi(K.getState().browserHistories[e],r.url)),[o,a]=g.useState(i.stack),[s,l]=g.useState(i.cursor),[c,u]=g.useState(0);g.useEffect(()=>{n(e,{contentUrl:r.url,stack:o,cursor:s})},[e,r.url,o,s,n]);const d=o[s],f=g.useMemo(()=>Kr(d),[d]),p=g.useMemo(()=>f.mode==="proxy"?Wi(window.location.hostname):null,[f]),v=g.useRef(null),{resolved:m,resolveError:k}=Zi({target:f,currentUrl:d,strategy:p,cwd:t,reloadNonce:c}),{resourceErrorCount:w,notePersonNavigated:A,noteFrameLoaded:C}=Ai({iframeRef:v,documentId:e,logicalUrl:d,reloadNonce:c,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),O=K(_=>_.roomCanvasLiveRoomId),{open:z}=zi(O??""),[Y,N]=g.useState(null),M=g.useCallback(_=>{a(D=>[...D.slice(0,s+1),_]),l(D=>D+1)},[s]),W=Qn(O),q=K(_=>O?_.roomCanvasEditing[O]??null:null);g.useEffect(()=>{if(W===null||q!==null||W.documentId!==e)return;const _=W.url;_===void 0||_===d||M(_)},[W,q,e,d,M]);const B=s>0,y=s<o.length-1,E=g.useCallback(_=>{const D=qi(_);if(!D||D===d){A(),u(Z=>Z+1);return}if(O){N(null),z({type:"browser",url:D}).catch(Z=>{N({url:D,message:xi(Z)})});return}A(),M(D)},[d,M,O,z,A]),R=()=>ri(d);return h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsxs("div",{className:"border-border/60 flex h-9 items-center gap-1 border-b px-2",children:[h.jsx(dt,{label:"Back",disabled:!B,onClick:()=>l(_=>_-1),children:h.jsx(Kn,{className:"size-4"})}),h.jsx(dt,{label:"Forward",disabled:!y,onClick:()=>l(_=>_+1),children:h.jsx(In,{className:"size-4"})}),h.jsx(dt,{label:"Reload",onClick:()=>u(_=>_+1),children:h.jsx(fi,{className:"size-4"})}),h.jsx(Ji,{url:(Y==null?void 0:Y.url)??d,startEditing:Y!==null,onSubmit:E},Y===null?"address":`retry:${Y.url}`),h.jsx(dt,{label:"Open in system browser",onClick:R,children:h.jsx(ei,{className:"size-4"})})]}),Y!==null&&h.jsx("p",{role:"status",className:"text-destructive border-border/60 border-b px-2 py-1 text-xs",children:Y.message}),h.jsx(eo,{target:f,resolved:m,resolveError:k,reloadNonce:c,resourceErrorCount:w,title:r.title??"Embedded browser",onOpenExternally:R,onReload:()=>{A(),u(_=>_+1)},iframeRef:v,onFrameLoad:C})]})}function Ji({url:e,startEditing:r=!1,onSubmit:t}){const[n,i]=g.useState(r),[o,a]=g.useState(e);if(!n)return h.jsx(Ki,{url:e,onActivate:()=>{a(e),i(!0)}});const s=l=>{l.preventDefault(),i(!1),t(o)};return h.jsx("form",{onSubmit:s,className:"min-w-0 flex-1",children:h.jsx(ti,{"aria-label":"Address",autoFocus:!0,value:o,onChange:l=>a(l.target.value),onFocus:l=>l.currentTarget.select(),onBlur:()=>i(!1),onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),i(!1))},spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"h-7 w-full text-sm"})})}function Qi(e){return e.kind==="local"?e.path:e.kind==="url"?`${e.host}${e.rest}`:e.text}function Ki({url:e,onActivate:r}){const t=g.useMemo(()=>Hi(e),[e]);return h.jsxs("button",{type:"button","aria-label":`Address: ${Qi(t)}`,onClick:r,className:"text-muted-foreground hover:bg-muted focus-ring flex h-7 min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 text-left text-sm transition-colors",children:[t.kind==="local"&&h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"bg-muted-foreground/15 text-3xs rounded px-1 py-0.5 font-medium tracking-wide uppercase",children:"local"}),h.jsx("span",{className:"text-foreground truncate",children:t.path})]}),t.kind==="url"&&h.jsxs("span",{className:"truncate",children:[h.jsx("span",{className:"text-foreground",children:t.host}),h.jsx("span",{className:"text-muted-foreground",children:t.rest})]}),t.kind==="raw"&&h.jsx("span",{className:"truncate",children:t.text})]})}function Ii(e,r){switch(e.kind){case"no-session":return"Open a chat to preview local files.";case"unsupported":return"Local previews aren’t available in this environment.";case"failed":return"Couldn’t load this preview. Reload, or open the app in your browser.";case"tunnel":return"Dev server previews don’t work remotely. Open DorkOS on the computer running it.";case"no-port":return"All preview ports are in use. Close a preview, then reload.";case"origin-unreachable":return`This view can’t reach port ${e.listenPort} on ${e.host}. Open DorkOS on the computer running it.`;case"no-upstream":return`Nothing is listening on ${r.mode==="proxy"?`${r.hostname}:${r.port}`:"that address"}. Start the dev server, then reload.`}}function eo({target:e,resolved:r,resolveError:t,reloadNonce:n,resourceErrorCount:i,title:o,onOpenExternally:a,onReload:s,iframeRef:l,onFrameLoad:c}){if(e.mode==="blocked")return h.jsx(xt,{children:"This address is blocked for safety."});if(t!==null)return h.jsxs(xt,{children:[h.jsx("p",{children:Ii(t,e)}),t.kind!=="no-session"&&t.kind!=="unsupported"&&h.jsx("button",{type:"button",onClick:s,className:"text-foreground mt-3 hover:underline",children:"Reload"})]});if(r===null)return h.jsx(xt,{children:"Loading…"});const u=e.mode==="external";return h.jsx(to,{src:r.src,sandbox:r.sandbox,title:o,iframeRef:l,onFrameLoad:c,watchLoadDeadline:!u,resourceErrorCount:i,showEmbedFallback:u,onOpenExternally:a,onReload:s},`${r.src}:${n}`)}function to({src:e,sandbox:r,title:t,iframeRef:n,onFrameLoad:i,watchLoadDeadline:o,resourceErrorCount:a,showEmbedFallback:s,onOpenExternally:l,onReload:c}){const[u,d]=g.useState(!1),[f,p]=g.useState(!1);return g.useEffect(()=>{if(!o)return;const v=setTimeout(()=>p(!0),Vi);return()=>clearTimeout(v)},[o]),h.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[f&&!u&&h.jsx(Or,{onOpenExternally:l,onReload:c,children:"This preview is slow to load."}),a>0&&h.jsxs(Or,{onOpenExternally:l,children:["This page hit ",a===1e4?"at least 10,000":a," ",a===1?"error":"errors"," while loading."]}),h.jsx("iframe",{ref:n,src:e,sandbox:r,onLoad:()=>{d(!0),i()},className:"min-h-0 w-full flex-1 border-0",title:t}),s&&h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-t px-3 py-1.5 text-xs",children:[h.jsx("span",{children:"This site can’t always be embedded here."}),h.jsx("button",{type:"button",onClick:l,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function Or({children:e,onOpenExternally:r,onReload:t}){return h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-b px-3 py-1.5 text-xs",children:[h.jsx("span",{children:e}),h.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[t&&h.jsx("button",{type:"button",onClick:t,className:"text-foreground hover:underline",children:"Reload"}),h.jsx("button",{type:"button",onClick:r,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function dt({label:e,disabled:r,onClick:t,children:n}){return h.jsx("button",{type:"button","aria-label":e,disabled:r,onClick:t,className:It("text-muted-foreground hover:text-foreground hover:bg-muted focus-ring rounded-md p-1.5 transition-colors",r&&"pointer-events-none opacity-40"),children:n})}function xt({children:e}){return h.jsx("div",{className:"text-muted-foreground flex min-h-0 flex-1 flex-col items-center justify-center p-8 text-center",children:e})}function ro({sourcePath:e,cwd:r,loadedContent:t}){const n=pe(),[i,o]=g.useState("idle"),[a,s]=g.useState(null),l=g.useRef(null),c=g.useRef(t),u=g.useRef(Promise.resolve()),d=!!(e&&r),f=g.useCallback(async(w,A)=>{const C=await n.writeFile(r,e,w,A);if(C.ok){if(typeof C.hash!="string"||C.hash.length===0||C.effect!=="changed"&&C.effect!=="no_op")throw new Error("Invalid file save acknowledgement");return l.current=C.hash,c.current=w,s(null),o("saved"),{status:C.effect,confirmed:{hash:C.hash,content:w}}}return s(C.conflict),o("conflict"),{status:"conflict"}},[n,r,e]),p=g.useCallback(w=>{if(!d)return Promise.resolve({status:"idle"});const A=u.current.catch(()=>{}).then(async()=>{o("saving");try{const C=l.current!==null?{expectedHash:l.current}:{expectedContent:c.current};return await f(w,C)}catch{return o("error"),{status:"error"}}});return u.current=A.then(()=>{}),A},[d,f]),v=g.useCallback(w=>{if(!d||!a)return Promise.resolve({status:"idle"});const A=a.currentHash,C=u.current.catch(()=>{}).then(async()=>{o("saving");try{return await f(w,{expectedHash:A})}catch{return o("error"),{status:"error"}}});return u.current=C.then(()=>{}),C},[d,a,f]),m=g.useCallback(()=>({hash:l.current,content:c.current}),[]),k=g.useCallback(()=>{if(!a)return null;const w=a.currentContent;return l.current=a.currentHash,c.current=w,s(null),o("idle"),w},[a]);return{status:i,conflict:a,canSave:d,save:p,overwrite:v,adoptDisk:k,getConfirmedBase:m}}const no=g.lazy(()=>je(()=>import("./BlintzCanvas-CUqethk_.js"),__vite__mapDeps([0,1,2,3,4])).then(e=>({default:e.BlintzCanvas}))),io=500;function oo(e){switch(e){case"saving":return"Saving…";case"saved":return"Saved";case"error":return"Couldn’t save";default:return null}}function ao({content:e,documentId:r,onContentChange:t}){const[n,i]=g.useState(!1),[o,a]=g.useState(e.content),s=K(B=>B.canvasSessionId),l=K(B=>B.setDocumentEditing),c=K(B=>{var y;return((y=B.openDocuments.find(E=>E.id===r))==null?void 0:y.editing)??!1}),u=K(B=>B.selectedCwd),d=n&&c,f=ro({sourcePath:e.sourcePath,cwd:u,loadedContent:e.content}),p=f.canSave,v=g.useRef(null),m=g.useRef(null),k=g.useRef(o),w=g.useRef(e),A=g.useRef(t),C=g.useRef(f.save);g.useEffect(()=>{k.current=o,w.current=e,A.current=t,C.current=f.save});const O=g.useCallback(B=>{K.getState().canvasSessionId===v.current&&(A.current({...w.current,content:B}),C.current(B))},[]),z=g.useCallback(B=>{a(B),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null,O(B)},io)},[O]),Y=()=>{v.current=K.getState().canvasSessionId,a(e.content),i(!0),l(r,!0)},N=()=>{m.current&&(clearTimeout(m.current),m.current=null,O(k.current)),i(!1),l(r,!1)};g.useEffect(()=>{d&&s!==v.current&&(m.current&&(clearTimeout(m.current),m.current=null),i(!1),l(r,!1))},[s,d,r,l]),g.useEffect(()=>{d||!m.current||(clearTimeout(m.current),m.current=null)},[d]),g.useEffect(()=>()=>{m.current&&(clearTimeout(m.current),m.current=null,O(k.current)),l(r,!1)},[O,r,l]);const M=()=>{const B=f.adoptDisk();B!=null&&(t({...e,content:B}),a(B))},W=()=>{f.overwrite(k.current)},q=oo(f.status);return h.jsxs("div",{className:"relative flex h-full flex-col",children:[h.jsxs("div",{className:"sticky top-0 z-10 flex h-0 items-start justify-end gap-2 pr-2",children:[p&&q&&h.jsx("span",{className:"text-muted-foreground mt-3 text-xs","aria-live":"polite",children:q}),p&&h.jsx(mt,{type:"button",variant:"ghost",size:"icon-md",className:"text-muted-foreground hover:text-foreground mt-2",onClick:d?N:Y,"aria-label":d?"Finish editing":"Edit document",children:d?h.jsx(qr,{className:"size-4"}):h.jsx(Hr,{className:"size-4"})})]}),f.status==="conflict"&&h.jsxs("div",{className:"bg-destructive/10 text-destructive mx-2 mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md px-3 py-2 text-sm",children:[h.jsx("span",{className:"flex-1",children:"This file changed on disk since you opened it."}),h.jsx(mt,{type:"button",variant:"ghost",size:"sm",className:"h-7",onClick:M,children:"Reload"}),h.jsx(mt,{type:"button",variant:"destructive",size:"sm",className:"h-7",onClick:W,children:"Overwrite"})]}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(g.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading editor…"}),children:h.jsx(no,{value:d?o:e.content,editable:d,onChange:d?z:void 0})})})]})}function so({content:e}){return h.jsx("div",{className:"p-4 font-mono text-sm",children:h.jsx(Ir,{value:e.data,depth:0})})}const lo=20;function Ir({value:e,depth:r,keyName:t}){const[n,i]=g.useState(r>2),o=g.useCallback(()=>i(u=>!u),[]);if(r>=lo)return h.jsx(Ve,{keyName:t,value:"[max depth]",className:"text-muted-foreground"});if(e===null)return h.jsx(Ve,{keyName:t,value:"null",className:"text-muted-foreground"});if(typeof e=="boolean")return h.jsx(Ve,{keyName:t,value:String(e),className:"text-blue-500"});if(typeof e=="number")return h.jsx(Ve,{keyName:t,value:String(e),className:"text-green-500"});if(typeof e=="string")return h.jsx(Ve,{keyName:t,value:`"${e}"`,className:"text-amber-500"});const a=Array.isArray(e),s=a?e.map((u,d)=>[String(d),u]):Object.entries(e),l=a?"[":"{",c=a?"]":"}";return h.jsxs("div",{style:{paddingLeft:r>0?16:0},children:[h.jsxs("button",{type:"button",className:"hover:bg-muted -ml-0.5 inline-flex items-center gap-0.5 rounded px-0.5 transition-colors duration-150",onClick:o,children:[h.jsx(ni,{className:It("size-3 transition-transform",!n&&"rotate-90")}),t!=null&&h.jsxs("span",{className:"text-foreground",children:[t,": "]}),h.jsxs("span",{className:"text-muted-foreground",children:[l,n&&` … ${s.length} items `,n&&c]})]}),!n&&h.jsxs(h.Fragment,{children:[s.map(([u,d])=>h.jsx(Ir,{keyName:a?void 0:u,value:d,depth:r+1},u)),h.jsx("div",{className:"text-muted-foreground",children:c})]})]})}function Ve({keyName:e,value:r,className:t}){return h.jsxs("div",{style:{paddingLeft:16},children:[e!=null&&h.jsxs("span",{className:"text-foreground",children:[e,": "]}),h.jsx("span",{className:t,children:r})]})}var Ce=function(e,r){return Number(e.toFixed(r))},uo=function(e,r){return typeof e=="number"?e:r},F=function(e,r,t){t&&typeof t=="function"&&t(e,r)},co=function(e){return-Math.cos(e*Math.PI)/2+.5},fo=function(e){return e},po=function(e){return e*e},ho=function(e){return e*(2-e)},mo=function(e){return e<.5?2*e*e:-1+(4-2*e)*e},vo=function(e){return e*e*e},go=function(e){return--e*e*e+1},bo=function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},wo=function(e){return e*e*e*e},yo=function(e){return 1- --e*e*e*e},Co=function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},So=function(e){return e*e*e*e*e},ko=function(e){return 1+--e*e*e*e*e},Po=function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e},en={easeOut:co,linear:fo,easeInQuad:po,easeOutQuad:ho,easeInOutQuad:mo,easeInCubic:vo,easeOutCubic:go,easeInOutCubic:bo,easeInQuart:wo,easeOutQuart:yo,easeInOutQuart:Co,easeInQuint:So,easeOutQuint:ko,easeInOutQuint:Po},Eo=function(e){var r=e.animationResolve;e.animationResolve=null,r==null||r()},ue=function(e){e.animationFrame!==null&&cancelAnimationFrame(e.animationFrame),e.animationFrame=null,e.isAnimating=!1,e.animation=null,e.velocity=null,Eo(e)};function tn(e,r,t,n,i){if(!e.mounted){i==null||i();return}var o=new Date().getTime(),a=1;ue(e);var s=function(){if(!(!e.mounted||e.animation!==s)){var l=new Date().getTime()-o,c=l/t,u=en[r],d=u(c);if(l>=t){e.animation=null,e.animationFrame=null;var f=e.animationResolve;e.animationResolve=null,n(a),f==null||f(),e.flushResizeAlignment()}else n(d),e.animationFrame=requestAnimationFrame(s)}};e.animation=s,e.animationResolve=i??null,e.animationFrame=requestAnimationFrame(s)}function To(e){var r=e.scale,t=e.positionX,n=e.positionY;return!(Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(n))}function Ae(e,r,t,n){var i=To(r);if(!e.mounted||!i)return Promise.resolve();var o=e.setState,a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=r.scale-s,d=r.positionX-l,f=r.positionY-c;return t===0?(o(r.scale,r.positionX,r.positionY),Promise.resolve()):new Promise(function(p){tn(e,n,t,function(v){v!==1?e.isAnimating=!0:e.isAnimating=!1;var m=s+u*v,k=l+d*v,w=c+f*v;o(m,k,w)},p)})}function Oo(e,r,t){var n=e.clientWidth,i=e.clientHeight,o=r.offsetWidth,a=r.offsetHeight,s=o*t,l=a*t,c=n-s,u=i-l;return{wrapperWidth:n,wrapperHeight:i,newContentWidth:s,newDiffWidth:c,newContentHeight:l,newDiffHeight:u}}var _o=function(e,r,t,n,i,o,a){var s=e>r?t*(a?.5:1):0,l=n>i?o*(a?.5:1):0,c=e-r-s,u=s,d=n-i-l,f=l;return{minPositionX:c,maxPositionX:u,minPositionY:d,maxPositionY:f,scaleWidthFactor:s,scaleHeightFactor:l}},tr=function(e,r){var t=e.wrapperComponent,n=e.contentComponent,i=e.setup,o=i.centerZoomedOut,a=i.disablePadding;if(!t||!n)throw new Error("Components are not mounted");var s=Oo(t,n,r),l=s.wrapperWidth,c=s.wrapperHeight,u=s.newContentWidth,d=s.newContentHeight,f=s.newDiffWidth,p=s.newDiffHeight,v=_o(l,u,f,c,d,p,!!o),m=l>=u&&c>=d;a&&m&&!o&&(v.minPositionX=0,v.maxPositionX=0,v.minPositionY=0,v.maxPositionY=0);var k=e.setup,w=k.minPositionX,A=k.maxPositionX,C=k.minPositionY,O=k.maxPositionY;return w!=null&&(v.minPositionX=l*(1-r)+w*r),A!=null&&(v.maxPositionX=A*r),C!=null&&(v.minPositionY=c*(1-r)+C*r),O!=null&&(v.maxPositionY=O*r),v},tt=function(e,r,t,n){return n?e<r?Ce(r,2):e>t?Ce(t,2):Ce(e,2):Ce(e,2)},ce=function(e,r){var t=tr(e,r);return e.bounds=t,t};function Me(e,r,t,n,i,o,a){var s=t.minPositionX,l=t.minPositionY,c=t.maxPositionX,u=t.maxPositionY,d=0,f=0;a&&(d=i,f=o);var p=tt(e,s-d,c+d,n),v=tt(r,l-f,u+f,n);return{x:p,y:v}}function Et(e,r,t,n,i,o){var a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=n-s;if(!Number.isFinite(r)||!Number.isFinite(t))return console.error("Mouse X and Y position were not provided!"),{x:l,y:c};var d=l-r*u,f=c-t*u,p=Me(d,f,i,o,0,0,null);return p}var _r=1e-7;function Fe(e,r,t,n,i){var o=i?n:0,a=Math.max(r-o,_r),s=t+o;return!Number.isNaN(t)&&e>=s?s:!Number.isNaN(r)&&e<=a?a:Math.max(e,_r)}var jr=function(e,r){var t=e.setup.panning.excluded,n=e.isInitialized,i=e.wrapperComponent,o=r.target,a=function(u){return!!u&&typeof u=="object"&&u.nodeType===1&&typeof u.contains=="function"},s=typeof r.composedPath=="function"?r.composedPath().some(function(u){return a(u)&&!!(i!=null&&i.contains(u))}):!!(i!=null&&i.contains(o)),l=n&&o&&s;if(!l)return!1;var c=qe(o,t);return!(c||sa(o)||ir(o))},Ar=function(e){var r=e.isInitialized,t=e.isPanning,n=e.setup,i=n.panning.disabled,o=r&&t&&!i;return!!o},jo=function(e,r){var t=e.state,n=t.positionX,i=t.positionY;e.isPanning=!0;var o=r.clientX,a=r.clientY;e.startCoords={x:o-n,y:a-i}},Ao=function(e,r){var t=r.touches,n=e.state,i=n.positionX,o=n.positionY;e.isPanning=!0;var a=t.length===1;if(a){var s=t[0].clientX,l=t[0].clientY;e.startCoords={x:s-i,y:l-o}}};function Ro(e){var r=e.state,t=r.positionX,n=r.positionY,i=r.scale,o=e.setup,a=o.disabled,s=o.limitToBounds,l=o.centerZoomedOut,c=e.wrapperComponent;if(!(a||!c||!e.bounds)){var u=e.bounds,d=u.maxPositionX,f=u.minPositionX,p=u.maxPositionY,v=u.minPositionY,m=t>d||t<f,k=n>p||n<v,w=t>d?c.clientWidth:e.setup.minPositionX||0,A=n>p?c.clientHeight:e.setup.minPositionY||0,C=Et(e,w,A,i,e.bounds,s||l),O=C.x,z=C.y;return{scale:i,positionX:m?O:t,positionY:k?z:n}}}function rn(e,r,t,n,i){var o=e.setup.limitToBounds,a=e.wrapperComponent,s=e.bounds,l=e.state,c=l.scale,u=l.positionX,d=l.positionY;if(!(a===null||s===null||r===u&&t===d)){var f=Me(r,t,s,o,n,i,a),p=f.x,v=f.y;e.setState(c,p,v)}}var xo=function(e,r,t){var n=e.startCoords,i=e.state,o=e.setup.panning,a=o.lockAxisX,s=o.lockAxisY,l=i.positionX,c=i.positionY;if(!n)return{x:l,y:c};var u=r-n.x,d=t-n.y,f=a?l:u,p=s?c:d;return{x:f,y:p}},Oe=function(e,r,t){var n=e.setup,i=e.state,o=n.minScale,a=n.disablePadding,s=n.centerZoomedOut,l=t??i.scale;return r>0&&l>=o&&!a&&!s?r:0},Te;(function(e){e.TRACK_PAD="track_pad",e.MOUSE="mouse",e.TOUCH="touch"})(Te||(Te={}));var zo=function(e){var r=e.mounted,t=e.wrapperComponent,n=e.contentComponent,i=e.setup,o=i.disabled,a=i.velocityAnimation,s=i.limitToBounds,l=e.state.scale,c=a.disabled;if(c||o||!r||!t||!n)return!1;if(!s)return!0;var u=t.clientWidth<n.offsetWidth*l||t.clientHeight<n.offsetHeight*l;return u},Do=function(e){var r=e.mounted,t=e.velocity,n=e.bounds,i=e.setup,o=i.disabled,a=i.velocityAnimation,s=a.disabled,l=!s&&!o&&r;return!(!l||!t||!n)};function No(e,r){var t=e.setup.velocityAnimation,n=t.animationTime,i=t.maxAnimationTime,o=t.inertia;return Math.min(n*Math.max(1,Math.abs(r/o)),i)}function Rr(e,r,t,n,i,o,a,s,l,c){if(i){if(r>a&&t>a){var u=a+(e-a)*c;return u>l?l:u<a?a:u}if(r<o&&t<o){var u=o+(e-o)*c;return u<s?s:u>o?o:u}}return n?r:tt(e,o,a,i)}function Mo(e){var r=1,t=e.clientWidth/window.innerWidth;return Number.isNaN(t)?r:Math.min(r,t)}var zt=function(e,r,t){var n=0,i=e*t;return Number.isNaN(i)?n:e<0?Math.max(i,-r):Math.min(i,r)};function Yo(e,r,t){var n,i,o=zo(e);if(o){var a=e.lastMousePosition,s=e.velocityTime,l=e.setup,c=e.wrapperComponent,u=l.velocityAnimation,d=u.maxStrengthMouse,f=u.maxStrengthTouch,p=u.sensitivityTouch,v=u.sensitivityMouse,m=Date.now();if(a&&s&&c){var k=Mo(c),w=(n={},n[Te.TOUCH]=p,n[Te.MOUSE]=v,n)[t],A=(i={},i[Te.TOUCH]=f,i[Te.MOUSE]=d,i)[t],C=r.x-a.x,O=r.y-a.y,z=zt(C/k,A,w),Y=zt(O/k,A,w),N=m-s,M=C*C+O*O,W=zt(Math.sqrt(M)/N,A,w);e.velocity={velocityX:z,velocityY:Y,total:W}}e.lastMousePosition=r,e.velocityTime=m}}function Xo(e){var r=e.velocity,t=e.bounds,n=e.setup,i=e.wrapperComponent,o=Do(e);if(!(!o||!r||!t||!i)){var a=r.velocityX,s=r.velocityY,l=r.total,c=t.maxPositionX,u=t.minPositionX,d=t.maxPositionY,f=t.minPositionY,p=n.limitToBounds,v=n.autoAlignment,m=n.zoomAnimation,k=n.panning,w=k.lockAxisY,A=k.lockAxisX,C=m.animationType,O=v.sizeX,z=v.sizeY,Y=v.velocityAlignmentTime,N=Y,M=No(e,l),W=Math.max(M,N),q=Oe(e,O),B=Oe(e,z),y=q*i.clientWidth/100,E=B*i.clientHeight/100,R=c+y,_=u-y,D=d+E,Z=f-E,G=e.state,se=new Date().getTime();tn(e,C,W,function(me){var le=e.state,we=le.scale,Xe=le.positionX,We=le.positionY,Be=new Date().getTime()-se,He=Be/N,ct=en[v.animationType],P=1-ct(Math.min(1,He)),b=1-me,T=Xe+a*b,S=We+s*b,x=Rr(T,G.positionX,Xe,A,p,u,c,_,R,P),$=Rr(S,G.positionY,We,w,p,f,d,Z,D,P);if(Xe!==T||We!==S){e.setState(we,x,$);var H=e.props.onPanning;H&&H(L(e),{})}})}}function xr(e,r){var t=e.state,n=t.scale,i=t.positionX,o=t.positionY;e.panStartPosition={x:i,y:o},ue(e),ce(e,n),"touches"in r?Ao(e,r):jo(e,r)}function nn(e,r){var t=e.state.scale,n=e.setup,i=n.minScale,o=n.autoAlignment,a=o.disabled,s=o.sizeX,l=o.sizeY,c=o.animationTime,u=o.animationType,d=a||t<i||!s&&!l;if(!d){e.isResizeAlignmentPending&&ce(e,t);var f=Ro(e);if(f){var p=e.state,v=p.positionX,m=p.positionY,k=f.positionX===v&&f.positionY===m;k||Ae(e,f,c,u)}}}function zr(e,r,t,n){var i=e.startCoords,o=e.setup,a=o.autoAlignment,s=a.sizeX,l=a.sizeY;if(i){var c=xo(e,r,t),u=c.x,d=c.y,f=Oe(e,s),p=Oe(e,l);Yo(e,{x:u,y:d},n),rn(e,u,d,f,p)}}function Wo(e,r){if(e.isPanning){var t=e.velocity,n=e.wrapperComponent,i=e.contentComponent;e.isPanning=!1;var o=e.state,a=o.positionX,s=o.positionY,l=o.scale,c=e.panStartPosition;if(e.panStartPosition=null,c){var u=a-c.x,d=s-c.y;if(u*u+d*d<=25)return}e.isAnimating=!1,e.animation=null,e.isResizeAlignmentPending&&ce(e,l);var f=(n==null?void 0:n.clientWidth)||0,p=(n==null?void 0:n.clientHeight)||0,v=((i==null?void 0:i.offsetWidth)||0)*l,m=((i==null?void 0:i.offsetHeight)||0)*l,k=!e.setup.limitToBounds||f<v||p<m,w=!r&&t&&t.total>.1&&k;w?Xo(e):nn(e)}}function Tt(e,r,t,n){var i=e.setup,o=i.minScale,a=i.maxScale,s=i.limitToBounds,l=Fe(Ce(r,2),o,a,0,!1),c=ce(e,l),u=Et(e,t,n,l,c,s),d=u.x,f=u.y;return{scale:l,positionX:d,positionY:f}}function rr(e,r,t){var n=e.state.scale,i=e.wrapperComponent,o=e.setup,a=o.minScale,s=o.maxScale,l=o.limitToBounds,c=o.zoomAnimation,u=c.disabled,d=c.animationTime,f=c.animationType,p=n>=a&&n<=s,v=u||p;if((n>=1||l)&&nn(e),!(v||!i||!e.mounted)){var m=r||i.clientWidth/2,k=t||i.clientHeight/2,w=n<a?a:s,A=Tt(e,w,m,k);A&&Ae(e,A,d,f)}}var de=function(){return de=Object.assign||function(r){for(var t,n=1,i=arguments.length;n<i;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},de.apply(this,arguments)};function Dr(e,r,t){for(var n=0,i=r.length,o;n<i;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return e.concat(o||Array.prototype.slice.call(r))}var Dt={scale:1,positionX:0,positionY:0},Ne={disabled:!1,minPositionX:null,maxPositionX:null,minPositionY:null,maxPositionY:null,minScale:1,maxScale:8,limitToBounds:!0,centerZoomedOut:!1,centerOnInit:!1,fitOnInit:!1,disablePadding:!1,smooth:!0,detached:!1,wheel:{step:.015,disabled:!1,wheelDisabled:!1,touchPadDisabled:!1,activationKeys:[],excluded:[]},trackPadPanning:{disabled:!0,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,activationKeys:[],excluded:[]},panning:{disabled:!1,velocityDisabled:!1,lockAxisX:!1,lockAxisY:!1,allowLeftClickPan:!0,allowMiddleClickPan:!0,allowRightClickPan:!0,activationKeys:[],excluded:[]},pinch:{step:5,disabled:!1,allowPanning:!0,excluded:[]},keyboard:{disabled:!0,panStep:50,zoomStep:.25,animationTime:100,animationType:"easeOut",excluded:[]},doubleClick:{disabled:!1,step:.7,mode:"zoomIn",animationType:"easeOut",animationTime:200,excluded:[]},zoomAnimation:{disabled:!1,size:.4,animationTime:200,animationType:"easeOut"},autoAlignment:{disabled:!1,sizeX:100,sizeY:100,animationTime:200,velocityAlignmentTime:400,animationType:"easeOut"},velocityAnimation:{disabled:!1,sensitivityMouse:1,sensitivityTouch:1.2,maxStrengthMouse:20,maxStrengthTouch:40,inertia:1,animationTime:300,maxAnimationTime:800,animationType:"easeOut"}},Bt={wrapperClass:"react-transform-wrapper",contentClass:"react-transform-component"},on=function(e){var r,t,n,i,o,a,s,l,c,u=Math.max((r=e.minScale)!==null&&r!==void 0?r:Ne.minScale,1e-7),d=(t=e.maxScale)!==null&&t!==void 0?t:Ne.maxScale,f=(n=e.initialScale)!==null&&n!==void 0?n:Dt.scale,p=Math.min(Math.max(f,u),d),v=tt((i=e.initialPositionX)!==null&&i!==void 0?i:Dt.positionX,(o=e.minPositionX)!==null&&o!==void 0?o:-1/0,(a=e.maxPositionX)!==null&&a!==void 0?a:1/0,e.minPositionX!=null||e.maxPositionX!=null),m=tt((s=e.initialPositionY)!==null&&s!==void 0?s:Dt.positionY,(l=e.minPositionY)!==null&&l!==void 0?l:-1/0,(c=e.maxPositionY)!==null&&c!==void 0?c:1/0,e.minPositionY!=null||e.maxPositionY!=null);return{previousScale:p,scale:p,positionX:v,positionY:m}},Nr=function(e){var r=de({},Ne);return Object.keys(e).forEach(function(t){var n=t,i=typeof e[n]<"u",o=typeof Ne[n]<"u";if(o&&i){var a=Object.prototype.toString.call(Ne[n]),s=a==="[object Object]",l=a==="[object Array]";s?r[n]=de(de({},Ne[n]),e[n]):l?r[n]=Dr(Dr([],Ne[n],!0),e[n]):r[n]=e[n]}}),r.minScale<=0&&(r.minScale=1e-7),r},an=function(e,r,t){var n=e.state.scale,i=e.wrapperComponent,o=e.setup,a=o.maxScale,s=o.minScale,l=o.zoomAnimation,c=l.size;if(!i)throw new Error("Wrapper is not mounted");var u=n+r*t,d=Fe(Ce(u,3),s,a,c,!1);return d};function rt(e,r,t,n){var i,o,a=e.wrapperComponent,s=e.props,l=s.onZoomStart,c=s.onZoom,u=s.onZoomStop,d=new MouseEvent("mousemove",{bubbles:!0}),f=L(e);F(f,d,l),F(f,d,c);var p=Ae(e,r,t,n),v=(o=(i=a==null?void 0:a.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;return v&&v.setTimeout(function(){e.mounted&&F(L(e),d,u)},t),p}function sn(e,r,t,n,i){var o=e.wrapperComponent,a=e.state,s=a.scale,l=a.positionX,c=a.positionY,u=e.setup.zoomAnimation;if(!o)return console.error("No WrapperComponent found"),Promise.resolve();var d=u.disabled?0:n,f=o.clientWidth,p=o.clientHeight,v=(f/2-l)/s,m=(p/2-c)/s,k=an(e,r,t),w=Tt(e,k,v,m);return w?rt(e,w,d,i):(console.error("Error during zoom event. New transformation state was not calculated."),Promise.resolve())}function Bo(e,r,t,n){var i,o,a=e.wrapperComponent,s=e.props,l=s.onPanningStart,c=s.onPanning,u=s.onPanningStop,d=new MouseEvent("mousemove",{bubbles:!0}),f=L(e);F(f,d,l),F(f,d,c);var p=Ae(e,r,t,n),v=(o=(i=a==null?void 0:a.ownerDocument)===null||i===void 0?void 0:i.defaultView)!==null&&o!==void 0?o:typeof window<"u"?window:null;return v&&v.setTimeout(function(){e.mounted&&F(L(e),d,u)},t),p}function nr(e,r,t,n){r===void 0&&(r="contain");var i=e.wrapperComponent,o=e.contentComponent,a=e.setup;if(!i||!o)return null;var s=o.offsetWidth,l=o.offsetHeight,c=i.clientWidth,u=i.clientHeight;if(!s||!l||!c||!u)return null;var d=c/s,f=u/l,p=r==="cover"?Math.max(d,f):Math.min(d,f);return n!==void 0&&(p=Math.min(p,n)),t!==void 0&&(p=Math.max(p,t)),p=Fe(p,a.minScale,a.maxScale,0,!1),Ot(p,i,o)}function ln(e,r,t,n){var i=e.setup,o=e.wrapperComponent,a=e.contentComponent,s=i.limitToBounds,l=i.centerOnInit,c=i.fitOnInit,u=on(e.props),d=e.state,f=d.scale,p=d.positionX,v=d.positionY;if(!o)return Promise.resolve();if(c){var m=nr(e,c==="cover"?"cover":"contain");if(m)return f===m.scale&&p===m.positionX&&v===m.positionY?Promise.resolve():(n==null||n(),rt(e,m,r,t))}var k=u.positionX,w=u.positionY;if(l&&a){var A=Ot(u.scale,o,a);k=A.positionX,w=A.positionY}var C=tr(e,u.scale),O=Me(k,w,C,s,0,0,o),z={scale:u.scale,positionX:O.x,positionY:O.y};return f===u.scale&&p===u.positionX&&v===u.positionY?Promise.resolve():(n==null||n(),rt(e,z,r,t))}var un=function(e){if("getBoundingClientRect"in e){var r=e.getBoundingClientRect();return{x:r.left,y:r.top,width:r.width,height:r.height}}return e};function Lo(e){var r=e.map(un),t=Math.min.apply(Math,r.map(function(a){return a.x})),n=Math.min.apply(Math,r.map(function(a){return a.y})),i=Math.max.apply(Math,r.map(function(a){return a.x+a.width})),o=Math.max.apply(Math,r.map(function(a){return a.y+a.height}));return{x:t,y:n,width:i-t,height:o-n}}function Fo(e,r,t,n){var i=un(e),o=r.getBoundingClientRect(),a=t.getBoundingClientRect(),s=o.x*n.scale,l=o.y*n.scale;return{x:(i.x-a.x+s)/n.scale,y:(i.y-a.y+l)/n.scale}}function qo(e,r,t,n,i,o,a){n===void 0&&(n=0),i===void 0&&(i=0);var s=e.wrapperComponent,l=e.contentComponent,c=e.state,u=e.setup,d=u.limitToBounds,f=u.minScale,p=u.maxScale;if(!s||!l)return c;var v=s.getBoundingClientRect(),m=Fo(r,s,l,c),k=m.x,w=m.y,A=r.width/c.scale,C=r.height/c.scale,O=s.clientWidth/A,z=s.clientHeight/C,Y=t||Math.min(O,z);a!==void 0&&(Y=Math.min(Y,a)),o!==void 0&&(Y=Math.max(Y,o));var N=Fe(Y,f,p,0,!1),M=(v.width-A*N)/2,W=(v.height-C*N)/2,q=(v.left-k)*N+M+n,B=(v.top-w)*N+W+i,y=tr(e,N),E=Me(q,B,y,d,0,0,s),R=E.x,_=E.y;return{positionX:R,positionY:_,scale:N}}function cn(e,r,t){var n=e.wrapperComponent,i=e.state;if(!n)return{x:0,y:0};var o=n.getBoundingClientRect();return{x:(r-o.left-i.positionX)/i.scale,y:(t-o.top-i.positionY)/i.scale}}function Ho(e,r,t){var n=e.wrapperComponent,i=e.state;if(!n)return{x:0,y:0};var o=n.getBoundingClientRect();return{x:o.left+i.positionX+r*i.scale,y:o.top+i.positionY+t*i.scale}}var Uo=function(e){return function(r,t,n){return r===void 0&&(r=.5),t===void 0&&(t=300),n===void 0&&(n="easeOut"),sn(e,1,r,t,n)}},Zo=function(e){return function(r,t,n){return r===void 0&&(r=.5),t===void 0&&(t=300),n===void 0&&(n="easeOut"),sn(e,-1,r,t,n)}},Vo=function(e){return function(r,t,n,i,o){i===void 0&&(i=300),o===void 0&&(o="easeOut");var a=e.state,s=a.positionX,l=a.positionY,c=a.scale,u=e.wrapperComponent,d=e.contentComponent,f=e.setup.disabled;if(f||!u||!d)return Promise.resolve();var p={positionX:Number.isNaN(r)?s:r,positionY:Number.isNaN(t)?l:t,scale:Number.isNaN(n)?c:n};return Ae(e,p,i,o)}},Go=function(e){return function(r,t){return r===void 0&&(r=200),t===void 0&&(t="easeOut"),ln(e,r,t)}},$o=function(e){return function(r,t,n){t===void 0&&(t=200),n===void 0&&(n="easeOut");var i=e.state,o=e.wrapperComponent,a=e.contentComponent;if(o&&a){var s=Ot(r||i.scale,o,a);return Ae(e,s,t,n)}return Promise.resolve()}},Jo=function(e){return function(r,t,n,i,o){i===void 0&&(i=300),o===void 0&&(o="easeOut");var a=e.wrapperComponent,s=e.contentComponent,l=e.setup;if(l.disabled||!a||!s)return Promise.resolve();var c=cn(e,t,n),u=Tt(e,r,c.x,c.y);if(!u)return Promise.resolve();var d=l.zoomAnimation.disabled?0:i;return rt(e,u,d,o)}},Qo=function(e){return function(r,t){return cn(e,r,t)}},Ko=function(e){return function(r,t){return Ho(e,r,t)}},Io=function(e,r){var t,n=e.wrapperComponent;if(!n)return[];var i=n.getRootNode(),o=i&&"getElementById"in i?i:(t=n.ownerDocument)!==null&&t!==void 0?t:typeof document<"u"?document:null,a=Array.isArray(r)?r:[r];return a.map(function(s){return typeof s=="string"?o==null?void 0:o.getElementById(s):s}).filter(function(s){return!!s&&n.contains(s)})},ea=function(e){return function(r,t,n,i,o,a){var s,l,c,u;n===void 0&&(n=600),i===void 0&&(i="easeOut"),o===void 0&&(o=0),a===void 0&&(a=0),ue(e);var d=typeof t=="object"&&t!==null?t:{scale:t},f=Io(e,r);if(!e.wrapperComponent||f.length===0)return Promise.resolve();var p=qo(e,Lo(f),d.scale,(s=d.offsetX)!==null&&s!==void 0?s:o,(l=d.offsetY)!==null&&l!==void 0?l:a,d.minScale,d.maxScale);return Ae(e,p,(c=d.animationTime)!==null&&c!==void 0?c:n,(u=d.animationType)!==null&&u!==void 0?u:i)}},ta=function(e){return function(r){var t,n,i;r===void 0&&(r={});var o=e.wrapperComponent,a=e.contentComponent,s=e.setup;if(s.disabled||!o||!a)return Promise.resolve();var l=nr(e,(t=r.mode)!==null&&t!==void 0?t:"contain",r.minScale,r.maxScale);if(!l)return Promise.resolve();var c=s.zoomAnimation.disabled?0:(n=r.animationTime)!==null&&n!==void 0?n:200;return rt(e,l,c,(i=r.animationType)!==null&&i!==void 0?i:"easeOut")}},ra=function(e){return function(r,t,n,i){n===void 0&&(n=200),i===void 0&&(i="easeOut");var o=e.wrapperComponent,a=e.contentComponent,s=e.setup,l=e.state;if(s.disabled||!o||!a||!Number.isFinite(r)||!Number.isFinite(t))return Promise.resolve();var c=ce(e,l.scale),u=Me(l.positionX+r,l.positionY+t,c,s.limitToBounds,0,0,o),d=u.x,f=u.y;return d===l.positionX&&f===l.positionY?Promise.resolve():Bo(e,{scale:l.scale,positionX:d,positionY:f},n,i)}},nt=function(e){return{instance:e,state:e.state,zoomIn:Uo(e),zoomOut:Zo(e),setTransform:Vo(e),resetTransform:Go(e),centerView:$o(e),zoomToElement:ea(e),zoomToPoint:Jo(e),clientToContent:Qo(e),contentToClient:Ko(e),fitToView:ta(e),panBy:ra(e)}},na=function(e){return{instance:e,state:e.state}},L=function(e){var r={};return Object.assign(r,na(e)),Object.assign(r,nt(e)),r},Nt=!1;function ft(){try{var e={get passive(){return Nt=!0,!1}};return e}catch{return Nt=!1,Nt}}var pt=".".concat(Bt.wrapperClass),qe=function(e,r){return r.some(function(t){return e.matches("".concat(pt," ").concat(t,", ").concat(pt," .").concat(t,", ").concat(pt," ").concat(t," *, ").concat(pt," .").concat(t," *"))})},ia=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]),oa='[contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]',aa='[draggable="true"]',dn=function(e){return!e||typeof e.closest!="function"?null:e},ir=function(e){var r=dn(e);return r?ia.has(r.tagName)||r.isContentEditable?!0:r.closest(oa)!==null:!1},sa=function(e){var r=dn(e);return r?r.closest(aa)!==null:!1},it=function(e){e&&clearTimeout(e)},la=function(e){return Number.parseFloat(e.toFixed(8))},fn=function(e,r,t){var n=la(t);return"translate(".concat(e,"px, ").concat(r,"px) scale(").concat(n,")")},Ot=function(e,r,t){var n=t.offsetWidth*e,i=t.offsetHeight*e,o=(r.clientWidth-n)/2,a=(r.clientHeight-i)/2;return{scale:e,positionX:o,positionY:a}};function ua(e,r){e!=null&&(typeof e=="function"?e(r):e.current=r)}function ca(e){return function(r){e.forEach(function(t){typeof t=="function"?t(r):t!=null&&(t.current=r)})}}var or=typeof window<"u"?g.useLayoutEffect:g.useEffect,da={panLeft:["ArrowLeft"],panRight:["ArrowRight"],panUp:["ArrowUp"],panDown:["ArrowDown"],zoomIn:["+","="],zoomOut:["-","_"],reset:["0"]},fa=function(e){return Object.values(da).some(function(r){return r.includes(e)})};function pa(e,r){var t=e.setup,n=t.disabled,i=t.keyboard,o=t.panning;if(n||i.disabled||r.defaultPrevented||r.ctrlKey||r.metaKey||r.altKey||!fa(r.key))return!1;var a=r.target;if(ir(a)||a&&typeof a.matches=="function"&&qe(a,i.excluded))return!1;var s=i.panStep,l=i.zoomStep,c=i.animationTime,u=i.animationType,d=nt(e),f=r.key,p=o.lockAxisX?0:s,v=o.lockAxisY?0:s;return f==="ArrowLeft"?d.panBy(p,0,c,u):f==="ArrowRight"?d.panBy(-p,0,c,u):f==="ArrowUp"?d.panBy(0,v,c,u):f==="ArrowDown"?d.panBy(0,-v,c,u):f==="+"||f==="="?d.zoomIn(l,c,u):f==="-"||f==="_"?d.zoomOut(l,c,u):f==="0"&&d.resetTransform(c,u),r.cancelable&&r.preventDefault(),r.stopPropagation(),!0}var Lt=function(e,r){return{wrapperWidth:e.offsetWidth,wrapperHeight:e.offsetHeight,contentWidth:r.offsetWidth,contentHeight:r.offsetHeight}},ha=function(e,r){return!e||e.wrapperWidth!==r.wrapperWidth||e.wrapperHeight!==r.wrapperHeight||e.contentWidth!==r.contentWidth||e.contentHeight!==r.contentHeight},pn=function(e){return e.isPanning||e.isPinching},ma=function(e){return pn(e)||e.wheelStopEventTimer!==null||e.wheelAnimationTimer!==null};function hn(e){var r=e.wrapperComponent,t=e.contentComponent,n=e.setup,i=e.state;if(!r||!t)return null;var o=ce(e,i.scale),a=n.limitToBounds,s=n.centerZoomedOut;if(!a&&!s)return null;var l=Me(i.positionX,i.positionY,o,!0,0,0,r),c=l.x,u=l.y,d=c===Ce(i.positionX,2)&&u===Ce(i.positionY,2);return d?null:{scale:i.scale,positionX:c,positionY:u}}var Ft=function(e){e.animation=null,e.animationFrame=null,e.isAnimating=!1,e.resizeAnimation=null};function va(e){var r=e.setup.autoAlignment.animationTime,t=Math.max(r/5,1);ue(e);var n=Date.now(),i=function(){if(!(!e.mounted||e.animation!==i)){var o=Date.now(),a=Math.max(o-n,1);n=o;var s=hn(e);if(!s){Ft(e);return}var l=e.state,c=l.scale,u=l.positionX,d=l.positionY,f=1-Math.exp(-a/t),p=u+(s.positionX-u)*f,v=d+(s.positionY-d)*f,m=Math.abs(s.positionX-p)<.5&&Math.abs(s.positionY-v)<.5;if(m&&(p=s.positionX,v=s.positionY),e.isAnimating=!m,e.setState(c,p,v),m){Ft(e);return}e.animationFrame=requestAnimationFrame(i)}};e.animation=i,e.resizeAnimation=i,e.animationResolve=null,e.animationFrame=requestAnimationFrame(i)}function mn(e){if(e.setup.disabled){ce(e,e.state.scale);return}if(pn(e)){e.isResizeAlignmentPending=!0;return}var r=e.animation!==null&&e.animation===e.resizeAnimation;if(e.animation&&!r){var t=e.state.scale,n=e.setup,i=n.minScale,o=n.maxScale;if(t<i||t>o){e.isResizeAlignmentPending=!0;return}ue(e)}var a=hn(e);if(!a){r&&Ft(e);return}if(!r){if(e.setup.autoAlignment.animationTime===0){e.setState(a.scale,a.positionX,a.positionY);return}va(e)}}function ga(e){var r=e.wrapperComponent,t=e.contentComponent;if(!(!r||!t)){var n=Lt(r,t);ha(e.measuredSizes,n)&&(e.measuredSizes=n,mn(e))}}var vn=function(e,r){var t=e.setup.wheel,n=t.disabled,i=t.wheelDisabled,o=t.touchPadDisabled,a=t.excluded,s=e.isInitialized,l=e.isPanning,c=r.target,u=s&&!l&&!n&&c;if(!u||r.deltaY===0||i&&!r.ctrlKey||o&&r.ctrlKey)return!1;var d=qe(c,a);if(d)return!1;var f=e.isPressingKeys(e.setup.wheel.activationKeys);return!!f},ba=function(e,r){var t=e.setup,n=t.disabled,i=t.trackPadPanning,o=i.activationKeys,a=i.excluded;if(!e.wrapperComponent||!e.contentComponent||n||i.disabled||r.ctrlKey)return!1;var s=vn(e,r);if(s)return!1;var l=r.target,c=qe(l,a);if(c)return!1;var u=e.isPressingKeys(o);return!!u},wa=function(e){return e?e.deltaY<0?1:-1:0};function ya(e,r){var t=wa(e),n=uo(r,t);return n}function gn(e,r,t){var n=r.getBoundingClientRect(),i=0,o=0;if("clientX"in e)i=(e.clientX-n.left)/t,o=(e.clientY-n.top)/t;else{var a=e.touches[0];i=(a.clientX-n.left)/t,o=(a.clientY-n.top)/t}return Number.isNaN(i)||Number.isNaN(o)?(console.error("No mouse or touch offset found"),{x:0,y:0}):{x:i,y:o}}var Ca=function(e,r,t,n,i){var o=e.state.scale,a=e.wrapperComponent,s=e.setup,l=s.maxScale,c=s.minScale,u=s.zoomAnimation,d=s.disablePadding,f=u.size,p=u.disabled;if(!a)throw new Error("Wrapper is not mounted");var v=o+r*t,m=n?!1:!p,k=Fe(v,c,l,f,m&&!d);return k},bn=function(e,r){var t=e.previousWheelEvent,n=e.state.scale,i=e.setup,o=i.maxScale,a=i.minScale;return t?n<o||n>a||Math.sign(t.deltaY)!==Math.sign(r.deltaY)||t.deltaY>0&&t.deltaY<r.deltaY||t.deltaY<0&&t.deltaY>r.deltaY||Math.sign(t.deltaY)!==Math.sign(r.deltaY):!1},Sa=function(e,r){var t=e.setup.pinch,n=t.disabled,i=t.excluded,o=e.isInitialized,a=r.target,s=o&&!n&&a;if(!s)return!1;var l=qe(a,i);return!l},ka=function(e){var r=e.setup.pinch.disabled,t=e.isInitialized,n=e.pinchStartDistance,i=t&&!r&&n!==null;return!!i},Pa=function(e,r,t){var n=t.getBoundingClientRect(),i=e.touches,o=i[0].clientX-n.left,a=i[0].clientY-n.top,s=i[1].clientX-n.left,l=i[1].clientY-n.top;return{x:(o+s)/2/r,y:(a+l)/2/r}},wn=function(e){return Math.sqrt(Math.pow(e.touches[0].pageX-e.touches[1].pageX,2)+Math.pow(e.touches[0].pageY-e.touches[1].pageY,2))},Ea=5,Ta=function(e,r){var t=e.pinchStartScale,n=e.pinchStartDistance,i=e.setup,o=i.maxScale,a=i.minScale,s=i.zoomAnimation,l=i.disablePadding,c=i.pinch,u=s.size,d=s.disabled,f=c.step;if(!t||n===null)throw new Error("Pinch touches distance was not provided");if(r<0)return e.state.scale;var p=r/n,v=p*t,m=(v-t)*(f/Ea),k=t+m,w=k===1/0?0:Ce(k,10);return Fe(w,a,o,u,!d&&!l)},yn=160,Cn=100,Oa=function(e,r){var t=e.props,n=t.onWheelStart,i=t.onZoomStart;ue(e),e.wheelStopEventTimer||(F(L(e),r,n),F(L(e),r,i))},_a=function(e,r){var t=e.props,n=t.onWheel,i=t.onZoom,o=e.contentComponent,a=e.setup,s=e.state,l=s.scale,c=a.limitToBounds,u=a.centerZoomedOut,d=a.zoomAnimation,f=a.wheel,p=a.disablePadding,v=a.smooth,m=d.size,k=d.disabled,w=f.step;if(!o)throw new Error("Component not mounted");r.cancelable&&r.preventDefault(),r.stopPropagation();var A=ya(r,null),C=v?w*Math.abs(r.deltaY):w,O=Ca(e,A,C,!r.ctrlKey);if(l!==O){var z=ce(e,O),Y=gn(r,o,l),N=k||m===0||u||p,M=c&&N,W=Et(e,Y.x,Y.y,O,z,M),q=W.x,B=W.y;e.previousWheelEvent=r,e.setState(O,q,B),F(L(e),r,n),F(L(e),r,i)}},ja=function(e,r){var t=e.props,n=t.onWheelStop,i=t.onZoomStop;it(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(rr(e,r.x,r.y),e.wheelAnimationTimer=null,e.flushResizeAlignment())},Cn);var o=bn(e,r);o&&(it(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,F(L(e),r,n),F(L(e),r,i),e.flushResizeAlignment())},yn))},Aa=function(e,r){var t=e.props,n=t.onWheelStart,i=t.onPanningStart;ue(e),e.wheelStopEventTimer||(e.wheelAnimationTimer||ce(e,e.state.scale),F(L(e),r,n),F(L(e),r,i))},Ra=function(e,r){var t=e.props,n=t.onWheelStop,i=t.onPanningStop;it(e.wheelAnimationTimer),e.wheelAnimationTimer=setTimeout(function(){e.mounted&&(rr(e,r.x,r.y),e.wheelAnimationTimer=null,e.flushResizeAlignment())},Cn);var o=bn(e,r);o&&(it(e.wheelStopEventTimer),e.wheelStopEventTimer=setTimeout(function(){e.mounted&&(e.wheelStopEventTimer=null,F(L(e),r,n),F(L(e),r,i),e.flushResizeAlignment())},yn))},Sn=function(e){for(var r=0,t=0,n=0;n<2;n+=1)r+=e.touches[n].clientX,t+=e.touches[n].clientY;var i=r/2,o=t/2;return{x:i,y:o}},xa=function(e,r){var t=wn(r);e.pinchStartDistance=t,e.lastDistance=t,e.pinchStartScale=e.state.scale,e.isPanning=!1,e.isPinching=!0,e.pinchPreviousCenter=Sn(r),ue(e)},za=function(e,r){var t=e.contentComponent,n=e.pinchStartDistance,i=e.wrapperComponent,o=e.pinchPreviousCenter,a=e.state.scale,s=e.setup,l=s.limitToBounds,c=s.centerZoomedOut,u=s.zoomAnimation,d=s.autoAlignment,f=s.pinch,p=s.panning,v=u.disabled,m=u.size,k=f.allowPanning;if(!(n===null||!t)){var w=Pa(r,a,t);if(!(!Number.isFinite(w.x)||!Number.isFinite(w.y))){var A=wn(r),C=Ta(e,A),O=Sn(r),z=a/C,Y=(O.x-((o==null?void 0:o.x)||0))*z,N=(O.y-((o==null?void 0:o.y)||0))*z;if(!(C===a&&Y===0&&N===0)){e.pinchPreviousCenter=O;var M=ce(e,C),W=v||m===0||c,q=l&&W,B=Et(e,w.x,w.y,C,M,q),y=B.x,E=B.y;if(e.pinchMidpoint=w,e.lastDistance=A,p.disabled||!k)e.setState(C,y,E);else{var R=d.sizeX,_=d.sizeY,D=Oe(e,R,C),Z=Oe(e,_,C),G=y+Y,se=E+N,me=Me(G,se,M,l,D,Z,i),le=me.x,we=me.y;e.setState(C,le,we)}}}}},Da=function(e){var r=e.pinchMidpoint;e.velocity=null,e.lastDistance=null,e.pinchMidpoint=null,e.pinchStartScale=null,e.pinchStartDistance=null,e.isPinching=!1,rr(e,r==null?void 0:r.x,r==null?void 0:r.y)},kn=function(e,r){var t=e.props.onZoomStop,n=e.setup.doubleClick.animationTime;it(e.doubleClickStopEventTimer),e.doubleClickStopEventTimer=setTimeout(function(){e.doubleClickStopEventTimer=null,e.mounted&&F(L(e),r,t)},n)},Na=function(e,r){var t=e.props,n=t.onZoomStart,i=t.onZoom,o=e.setup.doubleClick,a=o.animationTime,s=o.animationType;F(L(e),r,n),ln(e,a,s,function(){return F(L(e),r,i)}),kn(e,r)};function Ma(e,r){return e==="toggle"?r===1?1:-1:e==="zoomOut"?-1:1}function Ya(e,r){var t=e.setup,n=e.doubleClickStopEventTimer,i=e.state,o=e.contentComponent,a=i.scale,s=e.props,l=s.onZoomStart,c=s.onZoom,u=t.doubleClick,d=u.disabled,f=u.mode,p=u.step,v=u.animationTime,m=u.animationType;if(!d&&!n){if(f==="reset")return Na(e,r);if(!o)return console.error("No ContentComponent found");var k=Ma(f,e.state.scale),w=an(e,k,p);if(a!==w){F(L(e),r,l);var A=gn(r,o,a),C=Tt(e,w,A.x,A.y);if(!C)return console.error("Error during zoom event. New transformation state was not calculated.");F(L(e),r,c),Ae(e,C,v,m),kn(e,r)}}}var Xa=function(e,r){var t=e.isInitialized,n=e.setup,i=e.wrapperComponent,o=n.doubleClick,a=o.disabled,s=o.excluded,l=r.target,c=i==null?void 0:i.contains(l),u=t&&l&&c&&!a;if(!u)return!1;var d=qe(l,s);return!(d||ir(l))},Wa=(function(){function e(r){var t=this;this.mounted=!0,this.onChangeCallbacks=new Set,this.onInitCallbacks=new Set,this.onTransformCallbacks=new Set,this.wrapperComponent=null,this.contentComponent=null,this.isInitialized=!1,this.bounds=null,this.previousWheelEvent=null,this.wheelStopEventTimer=null,this.wheelAnimationTimer=null,this.isPanning=!1,this.isWheelPanning=!1,this.startCoords=null,this.panStartPosition=null,this.lastTouch=null,this.isPinching=!1,this.distance=null,this.lastDistance=null,this.pinchStartDistance=null,this.pinchStartScale=null,this.pinchMidpoint=null,this.pinchPreviousCenter=null,this.doubleClickStopEventTimer=null,this.velocity=null,this.velocityTime=null,this.lastMousePosition=null,this.isAnimating=!1,this.animation=null,this.animationFrame=null,this.animationResolve=null,this.initObserverTimer=null,this.isInitialLayoutPending=!1,this.measuredSizes=null,this.isResizeAlignmentPending=!1,this.resizeAnimation=null,this.pressedKeys={},this.selectionLock=null,this.mount=function(){t.mounted=!0,t.initializeWindowEvents()},this.unmount=function(){t.mounted=!1,t.cleanupWindowEvents()},this.update=function(n){t.props=n,t.setup=Nr(n),t.wrapperComponent&&t.contentComponent&&!ma(t)&&ce(t,t.state.scale)},this.clearTimers=function(){t.wheelStopEventTimer&&clearTimeout(t.wheelStopEventTimer),t.wheelAnimationTimer&&clearTimeout(t.wheelAnimationTimer),t.doubleClickStopEventTimer&&clearTimeout(t.doubleClickStopEventTimer),t.initObserverTimer&&clearTimeout(t.initObserverTimer),t.wheelStopEventTimer=null,t.wheelAnimationTimer=null,t.doubleClickStopEventTimer=null,t.initObserverTimer=null},this.initializeWindowEvents=function(){var n,i,o,a,s=ft(),l=(n=t.wrapperComponent)===null||n===void 0?void 0:n.ownerDocument,c=l==null?void 0:l.defaultView;(i=t.wrapperComponent)===null||i===void 0||i.addEventListener("wheel",t.onWheelPanning,s),(o=t.wrapperComponent)===null||o===void 0||o.addEventListener("keyup",t.setKeyUnPressed,s),(a=t.wrapperComponent)===null||a===void 0||a.addEventListener("keydown",t.setKeyPressed,s),c==null||c.addEventListener("mousedown",t.onPanningStart,s),c==null||c.addEventListener("mousemove",t.onPanning,s),c==null||c.addEventListener("mouseup",t.onPanningStop,s),l==null||l.addEventListener("mouseleave",t.clearPanning,s),c==null||c.addEventListener("keyup",t.setKeyUnPressed,s),c==null||c.addEventListener("keydown",t.setKeyPressed,s),c==null||c.addEventListener("blur",t.handleWindowBlur)},this.cleanupWindowEvents=function(){var n,i,o,a,s,l=ft(),c=(n=t.wrapperComponent)===null||n===void 0?void 0:n.ownerDocument,u=c==null?void 0:c.defaultView;u==null||u.removeEventListener("mousedown",t.onPanningStart,l),u==null||u.removeEventListener("mousemove",t.onPanning,l),u==null||u.removeEventListener("mouseup",t.onPanningStop,l),c==null||c.removeEventListener("mouseleave",t.clearPanning,l),u==null||u.removeEventListener("keyup",t.setKeyUnPressed,l),u==null||u.removeEventListener("keydown",t.setKeyPressed,l),u==null||u.removeEventListener("blur",t.handleWindowBlur),(i=t.wrapperComponent)===null||i===void 0||i.removeEventListener("wheel",t.onWheelPanning,l),(o=t.wrapperComponent)===null||o===void 0||o.removeEventListener("keyup",t.setKeyUnPressed,l),(a=t.wrapperComponent)===null||a===void 0||a.removeEventListener("keydown",t.setKeyPressed,l),t.cleanupWrapperEvents(),t.clearTimers(),ue(t),t.unlockTextSelection(),(s=t.observer)===null||s===void 0||s.disconnect(),t.observer=void 0,t.isInitialLayoutPending=!1,t.isResizeAlignmentPending=!1,t.resizeAnimation=null},this.cleanupWrapperEvents=function(){var n=t.wrapperComponent;if(n){var i=ft();n.removeEventListener("wheel",t.onWheelZoom,i),n.removeEventListener("dblclick",t.onDoubleClick,i),n.removeEventListener("keydown",t.onKeyboardNavigation,i),n.removeEventListener("touchstart",t.onTouchPanningStart,i),n.removeEventListener("touchmove",t.onTouchPanning,i),n.removeEventListener("touchend",t.onTouchPanningStop,i)}},this.handleInitializeWrapperEvents=function(n){var i=ft();n.addEventListener("wheel",t.onWheelZoom,i),n.addEventListener("dblclick",t.onDoubleClick,i),n.addEventListener("keydown",t.onKeyboardNavigation,i),n.addEventListener("touchstart",t.onTouchPanningStart,i),n.addEventListener("touchmove",t.onTouchPanning,i),n.addEventListener("touchend",t.onTouchPanningStop,i)},this.handleInitialize=function(){var n=t.setup,i=n.centerOnInit,o=n.fitOnInit;if(t.applyTransformation(),t.onInitCallbacks.forEach(function(s){return s(L(t))}),i||o){var a=t.applyInitialLayout();t.isInitialLayoutPending=!0,t.initObserverTimer&&clearTimeout(t.initObserverTimer),a&&(t.initObserverTimer=setTimeout(function(){t.initObserverTimer=null,t.isInitialLayoutPending=!1},5e3))}},this.observeSizes=function(n,i){var o;(o=t.observer)===null||o===void 0||o.disconnect(),t.observer=void 0,t.measuredSizes=Lt(n,i),!(typeof ResizeObserver>"u")&&(t.observer=new ResizeObserver(t.onSizeChange),t.observer.observe(n),t.observer.observe(i))},this.onSizeChange=function(){var n=t,i=n.wrapperComponent,o=n.contentComponent;if(!(!t.mounted||!i||!o)){if(t.isInitialLayoutPending){var a=(o.offsetWidth>0||o.offsetHeight>0)&&i.clientWidth>0&&i.clientHeight>0;if(!a)return;t.isInitialLayoutPending=!1,t.initObserverTimer&&clearTimeout(t.initObserverTimer),t.initObserverTimer=null,t.onInitCallbacks.forEach(function(s){return s(L(t))}),t.applyInitialLayout(),t.measuredSizes=Lt(i,o),ce(t,t.state.scale);return}ga(t)}},this.flushResizeAlignment=function(){t.isResizeAlignmentPending&&(t.isResizeAlignmentPending=!1,mn(t))},this.onWheelZoom=function(n){var i=t.setup.disabled;if(!i){t.syncModifierKeys(n);var o=vn(t,n);o&&(Oa(t,n),_a(t,n),ja(t,n))}},this.onWheelPanning=function(n){var i=t.props.onPanning,o=t.setup.trackPadPanning,a=o.lockAxisX,s=o.lockAxisY;t.syncModifierKeys(n);var l=ba(t,n);if(l){n.cancelable&&n.preventDefault(),n.stopPropagation();var c=t.state,u=c.positionX,d=c.positionY,f=u-n.deltaX,p=d-n.deltaY,v=a?u:f,m=s?d:p,k=t.setup.autoAlignment,w=k.sizeX,A=k.sizeY,C=Oe(t,w),O=Oe(t,A);v===u&&m===d||(Aa(t,n),rn(t,v,m,C,O),F(L(t),n,i),Ra(t,n))}},this.onPanningStart=function(n){var i=t.setup,o=i.disabled,a=i.panning,s=t.props.onPanningStart;if(!(o||a.disabled)){t.syncModifierKeys(n);var l=jr(t,n);if(l){var c=t.isPressingKeys(t.setup.panning.activationKeys);c&&(n.button===0&&!t.setup.panning.allowLeftClickPan||n.button===1&&!t.setup.panning.allowMiddleClickPan||n.button===2&&!t.setup.panning.allowRightClickPan||(n.cancelable&&n.preventDefault(),n.stopPropagation(),ue(t),xr(t,n),t.lockTextSelection(),t.focusForKeyboard(),F(L(t),n,s)))}}},this.onPanning=function(n){var i=t.setup.disabled,o=t.props.onPanning;if(!i){if(t.syncModifierKeys(n),t.isPanning&&n.buttons===0){t.clearPanning(n);return}var a=Ar(t);if(a){var s=t.isPressingKeys(t.setup.panning.activationKeys);s&&(n.cancelable&&n.preventDefault(),n.stopPropagation(),zr(t,n.clientX,n.clientY,Te.MOUSE),F(L(t),n,o))}}},this.onPanningStop=function(n){var i=t.setup.panning.velocityDisabled,o=t.props.onPanningStop;t.isPanning&&(t.unlockTextSelection(),Wo(t,i),F(L(t),n,o),t.flushResizeAlignment())},this.onPinchStart=function(n){var i=t.setup.disabled,o=t.props.onPinchStart;if(!i){var a=Sa(t,n);a&&(xa(t,n),ue(t),F(L(t),n,o))}},this.onPinch=function(n){var i=t.setup.disabled,o=t.props.onPinch;if(!i){var a=ka(t);a&&(n.cancelable&&n.preventDefault(),n.stopPropagation(),za(t,n),F(L(t),n,o))}},this.onPinchStop=function(n){var i=t.props.onPinchStop;t.pinchStartScale&&(Da(t),F(L(t),n,i),t.flushResizeAlignment())},this.onTouchPanningStart=function(n){var i=t.setup,o=i.disabled,a=i.doubleClick,s=t.props.onPanningStart;if(!o){var l=!(a!=null&&a.disabled),c=t.lastTouch&&+new Date-t.lastTouch<200;if(l&&c&&n.touches.length===1)t.lastTouch=null,t.onDoubleClick(n);else{t.lastTouch=+new Date,ue(t);var u=n.touches,d=u.length===1,f=u.length===2,p=jr(t,n);if(d){if(!p||t.setup.panning.disabled)return;ue(t),xr(t,n),t.lockTextSelection(),t.focusForKeyboard(),F(L(t),n,s)}f&&t.onPinchStart(n)}}},this.onTouchPanning=function(n){var i=t.setup.disabled,o=t.props.onPanning;if(t.isPanning&&n.touches.length===1){if(i)return;var a=Ar(t);if(!a)return;n.cancelable&&n.preventDefault(),n.stopPropagation();var s=n.touches[0];zr(t,s.clientX,s.clientY,Te.TOUCH),F(L(t),n,o)}else n.touches.length>1&&t.onPinch(n)},this.onTouchPanningStop=function(n){t.onPanningStop(n),t.onPinchStop(n)},this.onDoubleClick=function(n){var i=t.setup.disabled;if(!i){var o=Xa(t,n);o&&Ya(t,n)}},this.clearPanning=function(n){t.isPanning&&t.onPanningStop(n)},this.handleWindowBlur=function(){t.pressedKeys={},t.isPanning&&(t.isPanning=!1,t.startCoords=null),t.unlockTextSelection(),t.flushResizeAlignment()},this.syncModifierKeys=function(n){var i=n.ctrlKey,o=n.metaKey,a=n.shiftKey,s=n.altKey;typeof i=="boolean"&&(t.pressedKeys.Control=i),typeof o=="boolean"&&(t.pressedKeys.Meta=o),typeof a=="boolean"&&(t.pressedKeys.Shift=a),typeof s=="boolean"&&(t.pressedKeys.Alt=s)},this.setKeyPressed=function(n){t.pressedKeys[n.key]=!0},this.setKeyUnPressed=function(n){t.pressedKeys[n.key]=!1},this.isPressingKeys=function(n){return typeof n=="function"?n(Object.entries(t.pressedKeys).filter(function(i){var o=i[1];return o}).map(function(i){var o=i[0];return o})):n.length?!!n.every(function(i){return t.pressedKeys[i]}):!0},this.onKeyboardNavigation=function(n){pa(t,n)},this.focusForKeyboard=function(){var n,i=t.wrapperComponent;if(!(!i||t.setup.keyboard.disabled)){var o=(n=i.ownerDocument)===null||n===void 0?void 0:n.activeElement;o&&i.contains(o)||typeof i.focus=="function"&&i.focus({preventScroll:!0})}},this.lockTextSelection=function(){var n=t.wrapperComponent;!n||t.selectionLock||(t.selectionLock={userSelect:n.style.userSelect,webkitUserSelect:n.style.webkitUserSelect},n.style.userSelect="none",n.style.webkitUserSelect="none")},this.unlockTextSelection=function(){var n=t.selectionLock;t.selectionLock=null;var i=t.wrapperComponent;!i||!n||(i.style.userSelect=n.userSelect,i.style.webkitUserSelect=n.webkitUserSelect)},this.applyInitialLayout=function(){var n=t.setup.fitOnInit,i=t,o=i.wrapperComponent,a=i.contentComponent,s=!!o&&!!a&&o.clientWidth>0&&o.clientHeight>0&&(a.offsetWidth>0||a.offsetHeight>0);if(n){var l=nr(t,n==="cover"?"cover":"contain");if(l)return t.setState(l.scale,l.positionX,l.positionY),s}return t.setCenter(),s},this.setCenter=function(){if(t.wrapperComponent&&t.contentComponent){var n=Ot(t.state.scale,t.wrapperComponent,t.contentComponent);t.setState(n.scale,n.positionX,n.positionY)}},this.handleTransformStyles=function(n,i,o){return t.props.customTransform?t.props.customTransform(n,i,o):fn(n,i,o)},this.getContext=function(){return L(t)},this.applyTransformation=function(){if(!(!t.mounted||!t.contentComponent)){var n=t.state,i=n.scale,o=n.positionX,a=n.positionY,s=t.handleTransformStyles(o,a,i);t.props.detached||(t.contentComponent.style.transform=s),t.onTransformCallbacks.forEach(function(l){return l({scale:i,positionX:o,positionY:a,previousScale:t.state.previousScale,ref:L(t)})})}},this.setState=function(n,i,o){var a=t.props.onTransform;if(!Number.isNaN(n)&&!Number.isNaN(i)&&!Number.isNaN(o)){var s=Math.max(n,1e-7);s!==t.state.scale&&(t.state.previousScale=t.state.scale,t.state.scale=s),t.state.positionX=i,t.state.positionY=o,t.applyTransformation();var l=L(t);t.onChangeCallbacks.forEach(function(c){return c(l)}),F(l,{scale:t.state.scale,positionX:i,positionY:o},a)}else console.error("Detected NaN set state values")},this.onTransform=function(n){return t.onTransformCallbacks.has(n)||t.onTransformCallbacks.add(n),function(){t.onTransformCallbacks.delete(n)}},this.onChange=function(n){return t.onChangeCallbacks.has(n)||t.onChangeCallbacks.add(n),function(){t.onChangeCallbacks.delete(n)}},this.onInit=function(n){return t.onInitCallbacks.has(n)||t.onInitCallbacks.add(n),function(){t.onInitCallbacks.delete(n)}},this.init=function(n,i){t.mounted=!0,t.cleanupWindowEvents(),t.wrapperComponent=n,t.contentComponent=i,ce(t,t.state.scale),t.handleInitializeWrapperEvents(n),t.handleInitialize(),t.observeSizes(n,i),t.initializeWindowEvents(),t.isInitialized=!0;var o=L(t);F(o,void 0,t.props.onInit),ua(t.props.ref,o)},this.props=r,this.setup=Nr(this.props),this.state=on(this.props)}return e})(),lt=Pt.createContext(null),Ba=function(e,r){return typeof e=="function"?e(r):e},La=Pt.forwardRef(function(e,r){var t=g.useRef(null);t.current===null&&(t.current=new Wa(e));var n=t.current,i=Ba(e.children,nt(n));return g.useImperativeHandle(r,function(){return nt(n)},[n]),g.useEffect(function(){return n.mount(),function(){n.unmount()}},[n]),g.useEffect(function(){n.update(e)},[n,e]),h.jsx(lt.Provider,de({value:n},{children:i}))});Pt.forwardRef(function(e,r){var t=g.useRef(null),n=g.useContext(lt);return or(function(){var i=function(o){if(t.current){var a=0,s=0;t.current.style.transform=n.handleTransformStyles(a,s,1/o)}};return i(n.state.scale),n.onChange(function(o){i(o.instance.state.scale)})},[n]),h.jsx("div",de({},e,{ref:ca([t,r])}))});function Fa(e,r){r===void 0&&(r={});var t=r.insertAt;if(!(typeof document>"u")){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",t==="top"&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var qa=`.transform-component-module_wrapper__SPB86 {
25
25
  position: relative;
26
26
  width: -moz-fit-content;
27
27
  width: fit-content;
@@ -61,4 +61,4 @@ var Hn=Object.defineProperty;var vr=e=>{throw TypeError(e)};var Un=(e,r,t)=>r in
61
61
  background-size: 20px 20px;
62
62
  background-position: 0 0;
63
63
  }
64
- `,Mt={wrapper:"transform-component-module_wrapper__SPB86",content:"transform-component-module_content__FBWxo",infiniteGrid:"transform-component-module_infiniteGrid__Z-aP3"};Fa(qa);var Ha=function(e){var r,t=e.children,n=e.wrapperClass,i=n===void 0?"":n,o=e.contentClass,a=o===void 0?"":o,s=e.wrapperStyle,l=e.contentStyle,c=e.wrapperProps,u=c===void 0?{}:c,d=e.contentProps,f=d===void 0?{}:d,p=e.infinite,v=p===void 0?!1:p,m=g.useContext(lt),P=m.init,w=m.cleanupWindowEvents,A=g.useRef(null),C=g.useRef(null),O=g.useRef(null);or(function(){var Y=A.current,N=C.current;return Y!==null&&N!==null&&P&&(P==null||P(Y,N)),function(){w==null||w()}},[]),g.useEffect(function(){if(v){var Y=O.current;if(Y){var N=function(){var M=m.state,W=M.positionX,q=M.positionY;Y.style.backgroundPosition="".concat(W,"px ").concat(q,"px")};return N(),m.onChange(N)}}},[v,m]);var z=!(!((r=m.setup.keyboard)===null||r===void 0)&&r.disabled);return h.jsxs("div",de({tabIndex:z?0:void 0},u,{ref:A,className:"".concat(Bt.wrapperClass," ").concat(Mt.wrapper," ").concat(i),style:s},{children:[v&&h.jsx("div",{ref:O,className:Mt.infiniteGrid,"aria-hidden":!0}),h.jsx("div",de({},f,{ref:C,className:"".concat(Bt.contentClass," ").concat(Mt.content," ").concat(a),style:de(de({transformOrigin:"0 0"},l),{transform:fn(m.state.positionX,m.state.positionY,m.state.scale)})},{children:t}))]}))};function Ua(e,r){var t=Math.max(0,Math.min(e.x+e.width,r.x+r.width)-Math.max(e.x,r.x)),n=Math.max(0,Math.min(e.y+e.height,r.y+r.height)-Math.max(e.y,r.y));return t*n}function Za(e){var r=e.elementX,t=e.elementY,n=e.elementWidth,i=e.elementHeight,o=e.scale,a=e.positionX,s=e.positionY,l=e.viewportWidth,c=e.viewportHeight,u=e.margin,d=u===void 0?0:u,f=e.threshold,p=f===void 0?0:f,v={x:-d,y:-d,width:l+2*d,height:c+2*d},m={x:r*o+a,y:t*o+s,width:n*o,height:i*o};if(p<=0){var P=m.x<v.x+v.width&&m.x+m.width>v.x,w=m.y<v.y+v.height&&m.y+m.height>v.y;return P&&w}var A=m.width*m.height;if(A<=0)return!1;var C=Ua(v,m);return C/A>=p}kt.forwardRef(function(e,r){var t=e.x,n=e.y,i=e.width,o=e.height,a=e.margin,s=a===void 0?0:a,l=e.threshold,c=l===void 0?0:l,u=e.placeholder,d=u===void 0?null:u,f=e.onShow,p=e.onHide,v=e.children,m=e.className,P=e.style,w=g.useContext(lt),A=function(){var W=w.wrapperComponent;return W?Za({elementX:t,elementY:n,elementWidth:i,elementHeight:o,scale:w.state.scale,positionX:w.state.positionX,positionY:w.state.positionY,viewportWidth:W.clientWidth,viewportHeight:W.clientHeight,margin:s,threshold:c}):!1},C=g.useState(A),O=C[0],z=C[1],Y=g.useRef(!1),N=g.useRef(f),M=g.useRef(p);return N.current=f,M.current=p,or(function(){var W=function(){var y,E;if(w.wrapperComponent){var R=A();R!==Y.current&&(Y.current=R,z(R),R?(y=N.current)===null||y===void 0||y.call(N):(E=M.current)===null||E===void 0||E.call(M))}};W();var q=w.onChange(W),B;return w.wrapperComponent||(B=w.onInit(function(){return W()})),function(){q(),B==null||B()}},[w,t,n,i,o,s,c]),O?h.jsx("div",de({ref:r,className:m,style:P},{children:v})):d?h.jsx(h.Fragment,{children:d}):null});var Va=function(){var e=g.useContext(lt);if(!e)throw new Error("Transform context must be placed inside TransformWrapper");return e},Ga=function(){var e=Va();return nt(e)};const $a=new Set(["http:","https:"]);function Ja(e){const r=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!r||r[1].length===1?null:`${r[1].toLowerCase()}:`}const Qa={image:"data:image/",pdf:"data:application/pdf"};function kn(e,r,t){const n=e.trim();if(n.startsWith("data:"))return n.toLowerCase().startsWith(Qa[r])?{url:n,error:null}:{url:null,error:"unsupported-data"};const i=Ja(n);if(i!==null)return $a.has(i)?{url:n,error:null}:{url:null,error:"blocked"};const o=t(n);return o?{url:o,error:null}:{url:null,error:"local-unavailable"}}function En(e,r){switch(e){case"blocked":return`This ${r} source is blocked for safety.`;case"unsupported-data":return`This data URI isn’t a valid ${r} source.`;case"local-unavailable":return`Local ${r} files can’t be displayed here.`}}function Ka({content:e}){const r=pe(),t=K(u=>u.selectedCwd),n=g.useMemo(()=>kn(e.src,"image",u=>r.mediaUrl(t??"",u)),[e.src,r,t]),[i,o]=g.useState("loading"),[a,s]=g.useState(e.src);a!==e.src&&(s(e.src),o("loading"));const l=e.alt??e.title??"Canvas image";if(n.url===null){const u=n.error?En(n.error,"image"):"";return h.jsx(Mr,{children:u})}const c=n.url;return h.jsxs("div",{className:"bg-muted/40 relative flex h-full items-center justify-center",children:[i==="loading"&&h.jsx("p",{className:"text-muted-foreground absolute text-sm","aria-live":"polite",children:"Loading image…"}),i==="error"?h.jsx(Mr,{children:"This image couldn’t be loaded."}):h.jsxs(La,{centerOnInit:!0,doubleClick:{mode:"toggle"},wheel:{step:.15},children:[h.jsx(Ia,{}),h.jsx(Ha,{wrapperClass:"!h-full !w-full",contentClass:"!h-full !w-full flex items-center justify-center",children:h.jsx("img",{src:c,alt:l,onLoad:()=>o("loaded"),onError:()=>o("error"),className:It("max-h-full max-w-full object-contain transition-opacity",i==="loaded"?"opacity-100":"opacity-0")})})]})]})}function Ia(){const{zoomIn:e,zoomOut:r,resetTransform:t}=Ga();return h.jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[h.jsx(Yt,{label:"Zoom in",onClick:()=>e(),children:h.jsx(mi,{className:"size-4"})}),h.jsx(Yt,{label:"Zoom out",onClick:()=>r(),children:h.jsx(vi,{className:"size-4"})}),h.jsx(Yt,{label:"Reset zoom",onClick:()=>t(),children:h.jsx(hi,{className:"size-4"})})]})}function Yt({label:e,onClick:r,children:t}){return h.jsx("button",{type:"button",onClick:r,"aria-label":e,className:"bg-background/80 text-muted-foreground hover:text-foreground focus-ring rounded-md border p-1.5 backdrop-blur transition-colors",children:t})}function Mr({children:e}){return h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:e})})}function es({content:e}){const r=pe(),t=K(a=>a.selectedCwd),n=g.useMemo(()=>kn(e.src,"pdf",a=>r.mediaUrl(t??"",a)),[e.src,r,t]);if(n.url===null){const a=n.error?En(n.error,"pdf"):"";return h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:a})})}const i=n.url,o=e.title??"PDF document";return h.jsx("object",{data:i,type:"application/pdf",title:o,className:"h-full w-full",children:h.jsxs("div",{className:"text-muted-foreground flex h-full flex-col items-center justify-center gap-3 p-8 text-center",children:[h.jsx("p",{children:"This PDF can’t be shown here."}),h.jsxs("a",{href:i,target:"_blank",rel:"noreferrer",className:"text-foreground focus-ring rounded-md underline underline-offset-4",children:["Open ",o," in a new tab"]})]})})}function ts(e){const r=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!r||r[1].length===1?null:`${r[1].toLowerCase()}:`}const rs=new Set(["http:","https:","data:"]);function Tn(e,r,t){const n=e.trim(),i=ts(n);return i!==null?rs.has(i)?i==="data:"&&t!==void 0?n.toLowerCase().startsWith(t)?{url:n}:{url:null}:{url:n}:{url:null}:{url:r(n)}}function ns({content:e}){const r=pe(),t=K(o=>o.selectedCwd),n=g.useMemo(()=>Tn(e.src,o=>r.mediaUrl(t??"",o),"data:audio/"),[e.src,r,t]),i=e.title??"Canvas audio";return n.url===null?h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:"This audio can’t be played here."})}):h.jsx("div",{className:"bg-muted/40 flex h-full w-full items-center justify-center p-8",children:h.jsx("audio",{controls:!0,src:n.url,"aria-label":i,className:"w-full max-w-2xl",children:h.jsxs("p",{className:"text-muted-foreground text-sm",children:["Your browser can’t play this audio."," ",h.jsxs("a",{href:n.url,className:"text-foreground underline underline-offset-4",children:["Download ",i]}),"."]})})})}function is({content:e}){const r=pe(),t=K(o=>o.selectedCwd),n=g.useMemo(()=>Tn(e.src,o=>r.mediaUrl(t??"",o),"data:video/"),[e.src,r,t]),i=e.title??"Canvas video";return n.url===null?h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:"This video can’t be played here."})}):h.jsx("div",{className:"bg-muted/40 flex h-full w-full items-center justify-center",children:h.jsx("video",{controls:!0,src:n.url,"aria-label":i,className:"max-h-full w-full max-w-full object-contain",children:h.jsxs("p",{className:"text-muted-foreground p-8 text-sm",children:["Your browser can’t play this video."," ",h.jsxs("a",{href:n.url,className:"text-foreground underline underline-offset-4",children:["Download ",i]}),"."]})})})}function On({content:e,documentId:r,channel:t}){const[n]=Kt(),i=ii(e.definition),o=g.useMemo(()=>JSON.stringify(e.definition),[e.definition]);return h.jsx("div",{className:"p-4",children:i.ok?h.jsx(oi,{channel:t,document:i.document,sessionId:n??void 0},t?r??t.documentId:o):h.jsx(ai,{error:i.error,raw:i.raw})})}const ot=et().min(1).max(128),ve={protocol:Q("dorkos-doc"),v:Q(1),nonce:ot,requestToken:ot,loadToken:Wt,generation:Ur.shape.generation};Pt("kind",[ie({...ve,kind:Q("challenge")}).strict(),ie({...ve,kind:Q("ack")}).strict(),ie({...ve,kind:Q("connect")}).strict()]);Pt("kind",[ie({...ve,kind:Q("emit"),requestId:ot,event:gt}).strict(),ie({...ve,kind:Q("retire")}).strict()]);Pt("kind",[ie({...ve,kind:Q("receipt"),requestId:ot,receipt:Zr}).strict(),ie({...ve,kind:Q("refused"),requestId:ot,outcome:wr(["cancelled","unconfirmed","refused"])}).strict(),ie({...ve,kind:Q("state"),state:li,stateRev:Wt,docSeq:Wt,reset:yr()}).strict(),ie({...ve,kind:Q("event"),frame:ui}).strict(),ie({...ve,kind:Q("status"),status:wr(["connecting","ready","offline","revoked"]),unconfirmed:yr()}).strict()]);function os(e,r){try{if(si(r,1048576)!==void 0)return null;const t=e.safeParse(r);return t.success?t.data:null}catch{return null}}class as{constructor(){ee(this,"contiguous",0);ee(this,"through",0);ee(this,"pending",new Map)}get highest(){return this.contiguous}get catchUpThrough(){return this.through}get pendingCount(){return this.pending.size}reset(){this.contiguous=0,this.through=0,this.pending.clear()}resetHighest(){this.contiguous=0}advance(r){this.contiguous=Math.max(this.contiguous,r)}markThrough(r){this.through=Math.max(this.through,r)}recordGap(r){return this.markThrough(r.docSeq),this.pending.set(r.docSeq,r),this.pending.size<=200?!1:(this.pending.clear(),!0)}takeNextContiguous(){for(const n of this.pending.keys())n<=this.contiguous&&this.pending.delete(n);const r=this.contiguous+1,t=this.pending.get(r);return t&&this.pending.delete(r),t}clearReachedTarget(){return this.contiguous<this.through?!1:(this.through=0,!0)}}const qt=new WeakMap,ut=new WeakMap,Se=new WeakMap,Ke=new WeakMap;function _e(e){Ye(e);const r=qt.get(e);if(!r)throw new Error("Replay owner lifetime is absent.");return r}function ss(e,r){const t=ut.get(r);if(!t||t.owner!==e)throw new Error("Replay run is foreign.");return t}function _n(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){for(const r of Object.values(e))_n(r);Object.freeze(e)}return e}function ls(e){if(Ye(e),qt.has(e))throw new Error("Replay owner lifetime is already initialized.");qt.set(e,new as)}function ar(e){const r=_e(e);return Object.freeze({highest:r.highest,through:r.catchUpThrough,pending:r.pendingCount})}function Yr(e){_e(e).reset()}function Xr(e,r){const t=ut.get(r);if(!(!t||t.owner!==e))return Object.freeze({subject:t.subject,epoch:t.epoch,revision:t.revision,observation:t.observation,ended:t.ended})}function us(e,r,t){const n=Se.get(t),i=ut.get(r);if(!(!i||i.owner!==e||!n||n.owner!==e||n.run!==r||n.phase!=="consuming"||n.admissionRead||!re(e,r)))return n.admissionRead=!0,Object.freeze({response:n.response,since:n.since,revision:n.revision,observation:n.observation,targetBirth:i.targetBirth})}function cs(e,r,t){const n=ss(e,r),i=Se.get(t),o=zn(e,r,t);if(!o||!i||i.owner!==e||i.run!==r||i.phase!=="consuming"||!i.admissionRead||n.ended||n.epoch!==o.epoch||n.subject!==o.previous)throw new Error("Replay own issuance is foreign or stale.");n.subject=o.subject}function jn(e,r,t,n){if(!re(e,r))return;if(n){const o=Ke.get(t);return o&&o.owner===e&&o.run===r&&o.phase==="dispatching"&&!o.advanced?o.frame:void 0}const i=Se.get(t);return i&&i.owner===e&&i.run===r&&i.phase==="frames"&&i.dispatching!==void 0&&!i.advanced?i.frames[i.dispatching]:void 0}function ds(e,r,t,n){const i=Xs(e,r,t,n);if(!i||!re(e,r))throw new Error("Replay cursor advance has no genuine core witness.");const o=n?Ke.get(t):Se.get(t);if(!o||o.advanced)throw new Error("Replay frame advance was consumed.");o.advanced=!0,_e(e).advance(i.docSeq)}function fs(e,r){const t=ut.get(r),n=(t==null?void 0:t.lastPage)&&Se.get(t.lastPage);if(!t||t.owner!==e||!re(e,r)||t.target===void 0||!n||n.phase!=="finished"||n.next!==n.frames.length||n.response.events.length>=200&&_e(e).highest<t.target)return;const i=_e(e);return Object.freeze({highest:i.highest,through:i.catchUpThrough,target:t.target})}function ps(e,r){const t=st(e,r);if(!t)throw new Error("Replay notice is foreign or stale.");const n=_e(e),i=t.notification;if(t.mode==="quarantine")n.markThrough(i.type==="canvas_channel_snapshot"?i.snapshot.highWatermark:i.docSeq),i.type!=="canvas_channel_snapshot"&&n.recordGap(i);else{if(t.mode==="gap"&&i.type!=="canvas_channel_snapshot")return n.recordGap(i);t.mode==="event"&&Qs(e,r)}return!1}function hs(e,r){const t=st(e,r);if(!t||t.mode!=="event"||t.notification.type==="canvas_channel_snapshot")throw new Error("Notice cursor advance is foreign.");_e(e).advance(t.notification.docSeq)}function ms(e){const r=fe(e),t=_e(e),n=Object.freeze({}),i={owner:e,subject:r.subject,epoch:r.epoch,revision:r.revision,observation:r.observation,ended:!1,starting:t.highest,succeeded:!1};ut.set(n,i),Fs(e,n);const o=()=>re(e,n),a=()=>fe(e).live?o()?void 0:"restart":"stop";return Object.freeze({async readPage(){if(!o())return null;const s=fe(e),l=t.highest,c=_t(e),u=c.getCanvasChannel;if(!o())return null;const d=await u.call(c,r.documentId,{since:l,limit:200});if(!o())return null;const f=_n(ci.parse(d));if(!o())return null;const p=Object.freeze({});return Se.set(p,{owner:e,run:n,response:f,since:l,revision:s.revision,observation:s.observation,phase:"read",admissionRead:!1,frames:[],next:0,advanced:!1}),p},consumePage(s){const l=Se.get(s);return!o()||!l||l.owner!==e||l.run!==n||l.phase!=="read"?{kind:"done"}:(l.phase="consuming",qs(e,n,s)!=="accepted"||!o()?(l.phase="finished",{kind:"done"}):(i.target??(i.target=l.response.highWatermark),i.targetBirth=l.response.incarnation,l.frames=Object.freeze(l.response.events.filter(u=>u.docSeq<=i.target)),l.phase="frames",i.lastPage=s,l.response.resetRequired&&t.advance(l.response.retentionFloor-1),{kind:"frames",count:l.frames.length}))},advancePageFrame(s,l){const c=Se.get(s);if(!o()||!c||c.owner!==e||c.run!==n||c.phase!=="frames"||l!==c.next||!c.frames[l])return!1;c.next=l+1,c.dispatching=l,c.advanced=!1;try{return Br(e,n,s,!1)&&o()}finally{c.dispatching=void 0}},finishPage(s){const l=Se.get(s);if(!o()||!l||l.owner!==e||l.run!==n||l.phase!=="frames"||l.next!==l.frames.length||i.target===void 0)return"done";if(l.phase="finished",l.response.events.length<200||t.highest>=i.target)return t.advance(i.target),!o()||(Lr(e,n),!o())||(i.succeeded=!0),"done";if(t.highest<=l.since)throw new Error("Document replay made no progress.");return"again"},failed(){o()&&Hs(e,n)},beginFinalization(){return a()??(i.succeeded?"drain":"stop")},takePending(){if(!o())return null;const s=t.takeNextContiguous();if(!s||!o())return null;const l=Object.freeze({});return Ke.set(l,{owner:e,run:n,frame:s,phase:"taken",advanced:!1}),l},advancePending(s){const l=Ke.get(s);if(!o()||!l||l.owner!==e||l.run!==n||l.phase!=="taken")return!1;l.phase="dispatching";try{return Br(e,n,s,!0)&&o()}finally{l.phase="finished",Ke.delete(s)}},finishFinalization(){const s=a();if(s)return s;if(t.clearReachedTarget()){const l=a();if(l)return l;Lr(e,n);const c=a();if(c)return c}if(t.pendingCount||t.catchUpThrough>t.highest){const l=fe(e);if(t.highest>i.starting||l.revision>i.revision||l.observation>i.observation)return"restart";Us(e,n)}return a()??"stop"},current:o,end:()=>{i.ended=!0}})}var be,Ut,$e;class Ht{constructor(){gr(this,be);ee(this,"current",null);ee(this,"token",0);ee(this,"retiring",!1);ee(this,"subscribers",new Set);ee(this,"resources",new Map);ee(this,"doc",null);ee(this,"docClaims",new WeakMap);ee(this,"retiringDoc",!1);ee(this,"docResources",new Map);ee(this,"bindings",new WeakSet)}getCurrent(){return this.current}observeHostContext(r){if(this.retiring)return null;if(!r.transportOwner||typeof r.transportOwner!="object"||!Number.isSafeInteger(r.publisherEpoch)||r.publisherEpoch<0)throw new Error("Explicit transport owner and epoch required.");const t=["frame","documentId","resolvedSource","logicalUrl","reloadKey","sessionId","eligibility","exactOrigin","transportOwner","publisherEpoch"];if(t.some(i=>!Object.hasOwn(r,i))||typeof r.documentId!="string"||!r.documentId||typeof r.logicalUrl!="string"||typeof r.reloadKey!="string")throw new Error("Complete host context required.");const n=this.current;return n&&t.every(i=>Object.is(n[i],r[i]))?n:(this.retire(),this.current=Object.freeze({...r,token:this.token,loaded:!1}),this.current)}observeLoaded(r){return this.retiring||this.current!==r||!r.frame?null:(this.retire(),this.current=Object.freeze({...r,token:this.token,loaded:!0}),this.current)}retire(){if(this.retiring)return;const r=this.current;this.current=null;const t=this.doc;this.doc=null,this.token++,this.retiring=!0;const n=[...r?this.resources.get(r)??[]:[],...t?this.docResources.get(t)??[]:[],...this.subscribers];t&&this.docResources.delete(t),r&&this.resources.delete(r);try{for(const i of n)try{const o=i();o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}finally{this.retiring=!1}}subscribe(r){return this.subscribers.add(r),()=>{this.subscribers.delete(r)}}own(r,t){if(this.retiring||this.current!==r)throw new Error("Frame observation retired.");const n=this.resources.get(r)??new Set;return n.add(t),this.resources.set(r,n),()=>{n.delete(t)}}bindDoc(r,t,n){return xe(this,be,Ut).call(this,r,t,n)}acquireDoc(r,t,n){const i=xe(this,be,Ut).call(this,r,t,n),o=Object.freeze({});this.docClaims.set(i,o);let a=!1;return Object.freeze({binding:i,release:()=>{a||(a=!0,this.docClaims.get(i)===o&&(this.docClaims.delete(i),this.doc===i&&this.bindings.has(i)&&xe(this,be,$e).call(this)))}})}disableDoc(){xe(this,be,$e).call(this)}retireDoc(r){this.doc===r&&this.bindings.has(r)&&xe(this,be,$e).call(this)}ownDoc(r,t){if(!this.isCurrent(r))throw new Error("Doc binding retired.");const n=this.docResources.get(r)??new Set;return n.add(t),this.docResources.set(r,n),()=>{n.delete(t)}}isCurrent(r){return!this.retiring&&!this.retiringDoc&&this.doc===r&&this.bindings.has(r)&&this.current===r.observation}}be=new WeakSet,Ut=function(r,t,n){const i=this.doc,o=this.token,a=os(Ur,t);if(!a)throw this.disableDoc(),new Error("Established server Doc birth required.");const s=a,l=r.exactOrigin,c=r.eligibility==="served-document"?l==="null":r.eligibility==="preview-listener"&&l!==null&&new URL(l).origin===l;if(!r.loaded||!r.frame||typeof r.frame.postMessage!="function"||!r.resolvedSource||!c||r.documentId!==s.documentId||!n||n.length>200)throw new Error("Loaded eligible frame and established Doc birth required.");if(this.retiring||this.retiringDoc||this.current!==r||this.doc!==i||this.token!==o)throw new Error("Frame observation retired during Doc admission.");if(this.doc){if(this.doc.observation!==r)throw new Error("Doc binding belongs to another host load.");if(te(this.doc.incarnation,s)&&this.doc.scope===n)return this.doc;throw this.retire(),new Error("Doc birth changed; a fresh host load is required.")}const u=Object.freeze({observation:r,incarnation:Object.freeze(s),scope:n});try{return this.doc=u,this.bindings.add(u),u}catch(d){throw this.doc===u&&xe(this,be,$e).call(this),d}},$e=function(){if(this.retiringDoc)return;const r=this.doc;this.doc=null,this.retiringDoc=!0;const t=[...r?this.docResources.get(r)??[]:[]];r&&this.docResources.delete(r);try{for(const n of t)try{const i=n();i&&typeof i.then=="function"&&Promise.resolve(i).catch(()=>{})}catch{}}finally{this.retiringDoc=!1}};function vs(e,r,t){if(!t||typeof t.captureOriginal!="function"||typeof t.submit!="function"||typeof t.inspect!="function"||typeof t.isCurrentOwner!="function"||t.owner!==r.observation.transportOwner||t.publisherEpoch!==r.observation.publisherEpoch)throw new Error("Explicit current transport submit and inspect ports required.");const{owner:n,publisherEpoch:i,isCurrentOwner:o,submit:a,inspect:s,captureOriginal:l}=t,c=Object.freeze({expectedGeneration:r.incarnation.generation}),u=()=>{try{return e.isCurrent(r)?o(n,i)===!0&&e.isCurrent(r):!1}catch{return!1}};if(!u())throw new Error("Doc binding unavailable.");const d=()=>{if(!u())throw new Error("Doc binding retired.")};return Object.freeze({binding:r,current:u,captureOriginal:f=>{d();const p=f.id;d();const v=f.bytes;d();const m=Reflect.apply(l,t,[Object.freeze({id:p,bytes:v})]);if(d(),!m)return null;const P=m.id;d();const w=m.bytes;d();const A=m.submit;d();const C=m.inspect;return d(),P!==p||w!==v||typeof A!="function"||typeof C!="function"?null:Object.freeze({id:p,bytes:v,submit:async O=>{d(),O.throwIfAborted();const z=await Reflect.apply(A,m,[O]);return d(),O.throwIfAborted(),z},inspect:async O=>{d(),O.throwIfAborted();const z=await Reflect.apply(C,m,[O]);return d(),O.throwIfAborted(),z}})},retireObservation:()=>{u()&&e.retire()},onRetire:f=>e.ownDoc(r,f),submit:(f,p)=>(d(),p.throwIfAborted(),a(f,c,p)),inspect:(f,p)=>(d(),p.throwIfAborted(),s(f,c,p))})}class gs{constructor(){ee(this,"revision",0);ee(this,"draining",!1);ee(this,"cleanup");ee(this,"subscribers",new Set);ee(this,"retirements",new WeakMap)}captureRetirement(){const r=Object.freeze({}),t=++this.revision,n=this.cleanup;return this.cleanup=void 0,this.retirements.set(r,{revision:t,cleanup:n,callbacks:this.draining?[]:[...this.subscribers]}),r}drainRetirement(r){const t=this.retirements.get(r);if(!t)throw new Error("Frame resource retirement is foreign or consumed.");this.retirements.delete(r);const n=this.draining;this.draining=!0;try{this.drain(t.cleanup);for(const i of t.callbacks)this.drain(i)}finally{this.draining=n}}begin(){const r=this.captureRetirement(),t=this.revision;return this.drainRetirement(r),t}once(r,t,n){let i=!1;return()=>{if(i||(i=!0,!this.current(r)||!t()||!this.current(r)))return null;const o=n();return!this.current(r)||!t()||!this.current(r)?null:o}}drain(r){try{Promise.resolve(r==null?void 0:r()).catch(()=>{})}catch{}}current(r){return this.revision===r}install(r,t){return this.current(r)?(this.cleanup=t,!0):!1}subscribe(r){return this.subscribers.add(r),()=>{this.subscribers.delete(r)}}}function bs(e,r,t){const n=()=>e.current(r)&&t.current()===!0&&e.current(r),i=e.once(r,n,t.complete);return Object.freeze({completeLoad:()=>{const o=i();return!o||!n()||t.accept(o)!==!0||!n()?null:o}})}function ws(e,r,t){const n=()=>e.current(r)&&t.current()===!0&&e.current(r);if(!n())return null;const i=t.acquire();if(!i)return null;let o=!1,a=null,s;try{const l=i.binding;if(n()&&t.bindingCurrent(l)===!0&&n()){const c=t.createPort(l);n()&&t.portCurrent(c)===!0&&n()&&e.install(r,i.release)&&(o=!0,a=c)}}catch(l){s={cause:l}}if(!o)try{i.release()}catch(l){s??(s={cause:l})}if(s)throw s.cause;return a}function ys(e){const r=()=>Object.assign(new Error("Document actions are unavailable."),{status:409}),t=(i,o)=>{if(o.aborted||!e.current(i)||o.aborted)throw r()},n=(i,o)=>{const a=Zr.parse(o);if(a.receipt.id!==i)throw new Error("Document receipt does not match this action.");return a};return Object.freeze({current:e.current,submit:async(i,o)=>{const a=gt.parse(JSON.parse(JSON.stringify(i))),s=a.id;t("submit",o);const l=await e.submit(a,o);t("read",o);const c=n(s,l);return t("read",o),c},inspect:async(i,o)=>{t("read",o);const a=await e.inspect(i,o);t("read",o);const s=n(i,a);return t("read",o),s},captureOriginal:i=>{const o=gt.parse(JSON.parse(JSON.stringify(i))),a=o.id,s=JSON.stringify(o);if(!e.current("submit"))return null;const l=e.capture(o,s);if(!l||!e.current("submit")||!l.current("submit"))return null;let c=!1;const u=d=>l.current(d)===!0;return Object.freeze({id:a,bytes:s,current:u,submit:async d=>{if(c||d.aborted||!u("submit"))throw r();c=!0;const f=await l.submit(JSON.parse(s),d);if(d.aborted||!u("read"))throw r();const p=n(a,f);if(d.aborted||!u("read"))throw r();return p},inspect:async d=>{if(d.aborted||!u("read"))throw r();const f=await l.inspect(a,d);if(d.aborted||!u("read"))throw r();const p=n(a,f);if(d.aborted||!u("read"))throw r();return p}})}})}function Cs(e){return Object.freeze({id:e.id,bytes:e.bytes,submit:async r=>{try{return{kind:"accepted",receipt:await e.submit(r)}}catch{return{kind:"uncertain"}}},inspect:async r=>{try{return{kind:"accepted",receipt:await e.inspect(r)}}catch{return{kind:"unknown"}}}})}function Ss(e,r,t){const n=gt.parse(JSON.parse(e.bytes));if(n.id!==e.id||JSON.stringify(n)!==e.bytes||!t())return null;const i=r(n);return!t()||!i?null:Cs(i)}const Ps=Ht.prototype.acquireDoc,wt=new WeakMap,Zt=new WeakMap;function ks(e,r){const t=_t(e),n=new WeakMap,i=(a,s)=>r.current(s)&&Ee(e,a,!0);return Object.freeze({prepareFrameLoad:(a,s)=>{var f;if(!(a instanceof Ht)||s.loaded)return null;const l=Wr(e),c=l?(f=De(e,l))==null?void 0:f.httpBaseline:void 0,u=r.begin();if(!l||!c||!r.current(u)||!Ee(e,l,!0)||a.getCurrent()!==s||s.transportOwner!==t||!i(l,u))return null;let d=null;return bs(r,u,{current:()=>{var p;return Ee(e,l,!0)&&((p=De(e,l))==null?void 0:p.httpBaseline)===c&&a.getCurrent()===(d??s)&&r.current(u)&&Ee(e,l,!0)},complete:()=>(d=a.observeLoaded(s),d),accept:p=>{var v,m;return!r.current(u)||!Ee(e,l,!0)||((v=De(e,l))==null?void 0:v.httpBaseline)!==c||a.getCurrent()!==p||!r.current(u)||!Ee(e,l,!0)||((m=De(e,l))==null?void 0:m.httpBaseline)!==c?!1:(n.set(p,{record:l,birth:c.birth}),!0)}})},subscribeInvalidation:a=>r.subscribe(a),attachFrame:(a,s)=>{if(!(a instanceof Ht))return null;const l=Wr(e),c=r.begin();if(!l||!r.current(c)||!Ee(e,l,!0)||a.getCurrent()!==s||s.transportOwner!==t||!i(l,c))return null;const u=n.get(s);return!u||u.record!==l||!te(u.birth,De(e,l).birth)?null:ws(r,c,{current:()=>i(l,c),acquire:()=>{const d=Ps.call(a,s,De(e,l).birth,De(e,l).birth.documentId);let f=!1,p=null,v;try{i(l,c)&&a.getCurrent()===s&&i(l,c)&&(p=Object.freeze({binding:d.binding,release:d.release}),f=!0)}catch(m){v={cause:m}}if(!f)try{d.release()}catch(m){v??(v={cause:m})}if(v)throw v.cause;return p},bindingCurrent:d=>a.isCurrent(d)&&i(l,c),createPort:d=>vs(a,d,{owner:t,publisherEpoch:s.publisherEpoch,isCurrentOwner:(f,p)=>f===t&&p===s.publisherEpoch&&r.current(c)&&Ee(e,l),captureOriginal:f=>Ss(f,p=>{var v;return((v=Ls(e,l))==null?void 0:v.captureOriginal(p))??null},()=>i(l,c)),submit:async()=>({kind:"terminal"}),inspect:async()=>({kind:"unknown"})}),portCurrent:d=>d.current()&&i(l,c)})}})}function Es(e){if(Ye(e),wt.has(e))throw new Error("Frame owner is already initialized.");const r=new gs,t=ks(e,r);return wt.set(e,{frames:r,facade:t}),t}function Ts(e){var r;return Ye(e),(r=wt.get(e))==null?void 0:r.facade}function Je(e){Ye(e);const r=wt.get(e);if(!r)return;const t=Object.freeze({});return Zt.set(t,{owner:e,frames:r.frames,ticket:r.frames.captureRetirement()}),t}function Qe(e,r){if(!r)return;const t=Zt.get(r);if(!t||t.owner!==e)throw new Error("Frame retirement is foreign or consumed.");Zt.delete(r),t.frames.drainRetirement(t.ticket)}function An(e,r){const t=ye(e,r),n=Ys(e,r);if(!(!t||!n))return{owner:r,verified:t.verified,...ys(n)}}function ge(e,r){return{documentId:e,transport:r,events:[],available:!1}}function Os(e,r,t,n,i,o){var l,c;const a=e.documentId===t&&e.transport===n?e:ge(t,n);if(a.snapshot&&(r.highWatermark<a.snapshot.highWatermark||r.stateRev<a.snapshot.stateRev))return a;const s=new Map((((l=a.snapshot)==null?void 0:l.receipts)??[]).filter(u=>u.receipt.docSeq>=r.receiptRetentionFloor).map(u=>[u.receipt.id,u]));for(const u of r.receipts)s.set(u.receipt.id,u);return{...a,available:o,snapshot:{...r,...i?{}:{routing:(c=a.snapshot)==null?void 0:c.routing},receipts:[...s.values()].sort((u,d)=>d.receipt.docSeq-u.receipt.docSeq).slice(0,400)},events:r.resetRequired?a.events.filter(u=>u.docSeq>=r.retentionFloor):a.events}}function _s(e){var t,n,i,o,a,s,l,c,u,d,f,p;const r=async()=>{throw Object.assign(new Error("Document actions are unavailable."),{status:409})};return{documentId:e.documentId,enabled:e.available&&((t=e.binding)==null?void 0:t.verified)===!0&&((i=(n=e.snapshot)==null?void 0:n.routing)==null?void 0:i.enabled)===!0,submissionOwner:(o=e.binding)==null?void 0:o.owner,current:((a=e.binding)==null?void 0:a.current)??(()=>!1),approvedEventTypes:e.available?((l=(s=e.snapshot)==null?void 0:s.routing)==null?void 0:l.approvedEventTypes)??[]:[],destinationLabel:e.available?((u=(c=e.snapshot)==null?void 0:c.routing)==null?void 0:u.destinationLabel)??"Actions unavailable":"Actions unavailable",...e.snapshot?{snapshot:e.snapshot}:{},submit:((d=e.binding)==null?void 0:d.submit)??r,inspect:((f=e.binding)==null?void 0:f.inspect)??r,captureOriginal:(p=e.binding)==null?void 0:p.captureOriginal}}function js(e,r,t){return!!(e&&r&&t.incarnation&&te(r,t.incarnation)&&(t.highWatermark<e.highWatermark||t.stateRev<e.stateRev))}function Rn(e,r,t,n){const i=e.documentId===t&&e.transport===n?e:ge(t,n);return{...i,events:[...i.events,r].slice(-200)}}function As(e,r){if(e.incarnation&&(e.incarnation.documentId!==r||e.events.some(t=>t.documentId!==r||!t.incarnation||!te(e.incarnation,t.incarnation))))throw new Error("Document replay identity changed.")}const Vt=new WeakMap;function Rs(e,r,t){const n=us(e,r,t);if(n)return Vt.set(t,{owner:e,run:r,witness:n}),n}const xn=new WeakMap,at=new WeakMap,Gt=new WeakMap,$t=new WeakMap;function Pe(e,r){Ye(e);const t=r??at.get(e),n=t&&xn.get(t);return n&&n.owner===e&&at.get(e)===t&&n.active?n:void 0}function J(e){return Ye(e),at.get(e)}function ye(e,r){const t=Pe(e,r);return t?Object.freeze({birth:t.birth,httpBaseline:t.httpBaseline,snapshot:t.snapshot,verified:t.verified}):void 0}function Ie(e,r,t=!1){var o,a;const n=Pe(e,r),i=fe(e);return!!n&&i.live&&n.verified&&n.transport===_t(e)&&(!t||((a=(o=n.snapshot)==null?void 0:o.routing)==null?void 0:a.enabled)===!0)}function xs(e){const r=Pe(e);at.delete(e),r&&(r.active=!1,r.verified=!1)}function Xt(e,r){const t=Pe(e,r);t&&(t.verified=!1)}function zs(e,r,t){const n=Pe(e,t);return!n||!re(e,r)?!1:(n.verified=!0,re(e,r))}function Ds(e,r,t){const n=Vt.get(t);Vt.delete(t);const i=(n==null?void 0:n.owner)===e&&n.run===r?n.witness:void 0;if(!i||!re(e,r))return!1;const o=i.response.incarnation;let a=Pe(e);if(!a&&!o)return re(e,r);if(!a&&o){const s=fe(e),l=()=>{const v=fe(e);return re(e,r)&&v.epoch===s.epoch&&v.observation===s.observation&&J(e)===s.subject},c=_t(e),u=c.ingestCanvasEvent;if(!l())return!1;const d=Function.prototype.bind.call(u,c),f=c.getCanvasEventReceipt;if(!l())return!1;const p=Function.prototype.bind.call(f,c);if(!l())return!1;a={owner:e,token:Object.freeze({}),birth:Object.freeze({...o}),active:!0,verified:!1,submit:d,inspect:p,transport:c},xn.set(a.token,a),at.set(e,a.token),a.httpBaseline=Object.freeze({birth:a.birth,floor:i.response.receiptRetentionFloor}),Gt.set(t,Object.freeze({owner:e,run:r,epoch:s.epoch,previous:s.subject,subject:a.token}));try{cs(e,r,t)}catch(v){throw Pe(e)===a&&Gs(e,r,t),v}finally{Gt.delete(t)}if(!re(e,r))return!1}else if(a){if(!o||!te(a.birth,o))return!1;a.httpBaseline=Object.freeze({birth:a.birth,floor:i.response.receiptRetentionFloor})}return re(e,r)?(a&&(a.verified=$s(e)||a.verified),!0):!1}function sr(e,r,t){const n=lr(e),i=n.subject,o=()=>Mn(e,n,t);if(!i||!Ie(e,i)){const l=Je(e);Qe(e,l)}if(!o())return;const a=i&&An(e,i),s=Ts(e);n.dispatch(l=>{var d;if(!o())return l;const c=((d=l.binding)==null?void 0:d.owner)===i?l:ge(n.documentId,n.transport),u=typeof r=="function"?r(c):r;return o()?{...u,...u.snapshot?{snapshot:Object.freeze({...u.snapshot})}:{},binding:a,frameAdmission:s}:l})}function Ns(e,r,t,n,i){const o=lr(e),a=Pe(e);Mn(e,o,i)&&(a&&(a.snapshot=r),sr(e,s=>Os(s,r,o.documentId,o.transport,t,n),i))}function Ms(e,r,t,n){const i=jn(e,r,t,n);if(!re(e,r)||!i)return!1;if(i.docSeq<=ar(e).highest)return re(e,r);$t.set(t,{owner:e,run:r,pending:n,frame:i});try{ds(e,r,t,n)}finally{$t.delete(t)}if(!re(e,r))return!1;const o=lr(e);return sr(e,a=>Rn(a,i,o.documentId,o.transport),r),re(e,r)}function Ys(e,r){const t=Pe(e,r);if(!t)return;const n=fe(e).documentId;return{current:i=>Ie(e,r,i==="submit"),submit:(i,o)=>t.submit(n,i,{expectedGeneration:t.birth.generation},o),inspect:(i,o)=>t.inspect(n,i,{expectedGeneration:t.birth.generation},o),capture:()=>{const i=t.httpBaseline;return!i||!Ie(e,r,!0)||!te(i.birth,t.birth)?null:Object.freeze({current:o=>Ie(e,r,o==="submit")&&(o==="read"||t.httpBaseline===i),submit:(o,a)=>t.submit(n,o,{expectedGeneration:i.birth.generation},a),inspect:(o,a)=>t.inspect(n,o,{expectedGeneration:i.birth.generation},a)})}}}function zn(e,r,t){const n=Gt.get(t),i=fe(e);return n&&n.owner===e&&n.run===r&&i.epoch===n.epoch&&i.subject===n.subject&&i.live?n:void 0}function Xs(e,r,t,n){const i=$t.get(t);return i&&i.owner===e&&i.run===r&&i.pending===n&&re(e,r)?i.frame:void 0}const Dn=new WeakMap,yt=new WeakMap;function Ws(e){const r=yt.get(e);if(!r)throw new Error("Document construction ticket is foreign or consumed.");return yt.delete(e),r}function Bs(e,r,t){const n=Object.freeze({});yt.set(n,Object.freeze({documentId:e,transport:r,dispatch:t}));try{const i=Js(n);return Dn.set(n,i),n}finally{yt.delete(n)}}function I(e){const r=Dn.get(e);if(!r)throw new Error("Document owner is foreign.");return r}function Ye(e){I(e)}function fe(e){return I(e).facts()}function _t(e){return I(e).transport()}function Wr(e){return I(e).subject()}function De(e,r){return I(e).subjectFacts(r)}function Ee(e,r,t=!1){return I(e).subjectCurrent(r,t)}function Ls(e,r){return I(e).binding(r)}function Fs(e,r){I(e).reserve(r)}function re(e,r){return I(e).current(r)}function qs(e,r,t){return I(e).admit(r,t)}function Br(e,r,t,n){return I(e).frame(r,t,n)}function Lr(e,r){return I(e).qualify(r)}function Hs(e,r){I(e).failed(r)}function Us(e,r){I(e).unavailable(r)}function Zs(e,r){I(e).start(r)}function Vs(e){I(e).dispose()}const Nn=new WeakMap;function lr(e){const r=Object.freeze(I(e).projection());return Nn.set(r,Object.freeze({custodyKey:e,capture:r})),r}function Mn(e,r,t){const n=Nn.get(r);return(n==null?void 0:n.custodyKey)===e&&n.capture===r&&I(e).projectionCurrent(r.epoch,r.subject,t)}function Gs(e,r,t){I(e).abortAdmission(r,t)}function $s(e){return I(e).qualified()}const Jt=new WeakMap;function Js(e){const{documentId:r,transport:t,dispatch:n}=Ws(e);let i,o=!1,a;const s={live:!0};let l=0,c,u,d=!1,f,p,v=0;const m=()=>s.live,P=()=>xs(e);let w=0;const A=()=>ar(e),C=y=>{const E=Xr(e,y);return!!E&&!E.ended&&m()&&i===y&&E.epoch===l&&E.subject===J(e)},O=(y=!1)=>{const E=Je(e);P(),l++,i=void 0,y&&Yr(e),Qe(e,E)},z=(y,E)=>sr(e,y,E),Y=y=>{const E=fs(e,y),R=J(e),_=R&&ye(e,R);return!C(y)||!E||E.through>E.highest||!f||!_||!te(f,_.birth)||!zs(e,y,R)?!1:(f=void 0,z(D=>({...D,available:!0}),y),C(y))},N=(y,E,R)=>{const _=J(e),D=_&&ye(e,_),Z=l,G=()=>m()&&Z===l&&J(e)===_&&(!R||C(R));if(!G()||js(D==null?void 0:D.snapshot,D==null?void 0:D.birth,y))return;const se=E?y.routing:u;y={...y,routing:se&&Object.freeze({enabled:se.enabled,destinationLabel:se.destinationLabel,approvedEventTypes:Object.freeze([...se.approvedEventTypes])})},E&&(u=y.routing),!_&&!y.incarnation&&(d=!0),G()&&Ns(e,y,E,f===void 0,R)},M=(y,E)=>{var we;const R=Rs(e,y,E);if(!C(y)||!R)return"discard";const _=R.response;As(_,r);const D=_.incarnation;if((J(e)||f||p)&&!D)throw new Error("Document replay identity is unavailable.");if(p&&D&&!te(p,D))return O(!0),z(ge(r,t)),"restart";const Z=J(e),G=(Z&&((we=ye(e,Z))==null?void 0:we.birth))??f;if(D&&(G&&!te(G,D)||!G&&d||R.targetBirth&&!te(R.targetBirth,D)))return f=D,d=!1,u=void 0,c=void 0,O(!0),z(ge(r,t)),"restart";const{events:se,...me}=_,le=J(e);return!le&&D&&(f=p??D),!Ds(e,y,E)||!C(y)?"discard":(!le&&D&&(p=void 0),N(me,R.revision===w,y),C(y)?"accepted":"discard")},W=(y,E,R)=>{var G;const _=jn(e,y,E,R),D=J(e),Z=(D&&((G=ye(e,D))==null?void 0:G.birth))??f;return!C(y)||!_||_.documentId!==r||Z&&(!_.incarnation||!te(Z,_.incarnation))?!1:Ms(e,y,E,R)},q=(y,E)=>{const R=Object.freeze({});Jt.set(R,Object.freeze({owner:e,revision:w,observation:v,epoch:l,notification:y,mode:E}));try{return ps(e,R)}finally{Jt.delete(R)}},B=y=>{if(o||!m()||(o=!0,z(ge(r,t)),!m()))return;const E=di(void 0,R=>{if(!m()||R.documentId!==r)return;const _=R.type==="canvas_channel_snapshot"?R.snapshot.incarnation:R.incarnation,D=J(e);if(!D){if(f&&!p&&(!_||!te(f,_))||!_||_.documentId!==r)return;if(!p||!te(p,_)){const Z=!!p||!!f;if(p=Object.freeze({..._}),v++,u=void 0,c=void 0,d=!1,Z&&(O(!0),z(ge(r,t))),!m()||!p||!te(p,_))return}q(R,"quarantine"),m()&&y();return}if(f&&(!_||!te(f,_))){_&&y();return}if(_&&!te(ye(e,D).birth,_)){f=_,d=!1,u=void 0,c=void 0,O(!0),z(ge(r,t)),m()&&y();return}if(_){if(c!==void 0&&c!==R.scope){const Z=Je(e);if(c=R.scope,Xt(e,D),l++,i=void 0,w++,Qe(e,Z),J(e)!==D||!m())return;z(G=>({...G,available:!1})),J(e)===D&&m()&&y();return}c=R.scope,w++,R.type==="canvas_channel_snapshot"?N(R.snapshot,!0):R.docSeq>A().highest+1?(q(R,"gap")&&m()&&z(G=>({...G,available:!1})),m()&&y()):q(R,"event")}},t,()=>{if(!m())return;const R=Je(e),_=J(e);_&&Xt(e,_),l++,i=void 0,w++,Qe(e,R),z(D=>({...D,available:!1})),m()&&y()});m()?a=E:E(),m()&&y()};return Yn.set(e,y=>{const E=st(e,y);if(!E||E.notification.type==="canvas_channel_snapshot")return;const R=J(e),_=l;!R||!E.notification.incarnation||!te(ye(e,R).birth,E.notification.incarnation)||(z(D=>Rn(D,E.notification,r,t)),!m()||_!==l||J(e))}),{facts:()=>Object.freeze({documentId:r,live:m(),epoch:l,revision:w,observation:v,subject:J(e)}),transport:()=>t,subject:()=>J(e),subjectFacts:y=>ye(e,y),subjectCurrent:(y,E)=>Ie(e,y,E),binding:y=>An(e,y),qualified:()=>f===void 0,projection:()=>({documentId:r,transport:t,dispatch:n,epoch:l,run:i,subject:J(e)}),projectionCurrent:(y,E,R)=>m()&&y===l&&E===J(e)&&(!R||i===R),abortAdmission:(y,E)=>{zn(e,y,E)&&O(!0)},reserve:y=>{const E=Xr(e,y);if(!E||E.ended||!m()||E.epoch!==l||E.subject!==J(e))throw new Error("Replay run is foreign or stale.");i=y},current:C,admit:M,frame:W,qualify:Y,failed:y=>{if(!C(y))return;const E=J(e);E&&Xt(e,E),z(R=>({...R,available:!1}),y)},unavailable:y=>{C(y)&&z(E=>({...E,available:!1}),y)},start:B,dispose:()=>{if(!m())return;const y=Je(e);s.live=!1,i=void 0;const E=a;a=void 0,P(),l++,Yr(e);try{Qe(e,y)}finally{E==null||E()}}}}function st(e,r){const t=Jt.get(r),n=fe(e);if(!(!t||t.owner!==e||!n.live||n.epoch!==t.epoch||n.revision!==t.revision||n.observation!==t.observation))return t}function Qs(e,r){var s;const t=st(e,r);if(!t||t.notification.type==="canvas_channel_snapshot")return;const n=t.notification,o=fe(e).subject,a=o&&ye(e,o);!a||!n.incarnation||!te(a.birth,n.incarnation)||n.docSeq<=ar(e).highest||(hs(e,r),!(!st(e,r)||fe(e).subject!==o)&&((s=Yn.get(e))==null||s(r)))}const Yn=new WeakMap;function Ks(e,r,t){const n=Bs(e,r,t);ls(n);const i=Es(n);return Object.freeze({beginRun:()=>ms(n),frameAdmission:i,start:o=>Zs(n,o),dispose:()=>Vs(n)})}function Is(e){let r,t=0;const n=c=>{r===c&&(r=void 0)},i=(c,u)=>{c.settled||(c.settled=!0,u?c.reject(u.cause):c.resolve())},o=()=>{l().catch(()=>{})},a=(c,u)=>{const d=()=>t===c.revision;if(!d())return;const f=u.beginFinalization();if(d()){if(f==="restart"){o();return}if(f==="drain")for(;d();){const p=u.drainOne();if(!d())return;if(p!=="again"){if(p==="restart")o();else if(p==="tail"){const v=u.finishFinalization();d()&&v==="restart"&&o()}return}}}},s=async c=>{let u,d;try{u=e();try{for(;await u.page()==="again";);}catch(f){u.failed(f)}}catch(f){d={cause:f}}finally{n(c);try{u&&a(c,u)}catch(f){d={cause:f}}finally{i(c,d)}}},l=()=>{if(r)return r.promise;let c,u;const d=new Promise((p,v)=>{c=p,u=v}),f={revision:++t,promise:d,resolve:c,reject:u,settled:!1};return r=f,s(f),d};return Object.freeze({request:l})}function el(e,r,t){const n=Ks(e,r,t),i=Is(()=>{const o=n.beginRun();return{async page(){const a=await o.readPage();if(!a)return"done";const s=o.consumePage(a);if(s.kind!=="frames")return s.kind;for(let l=0;l<s.count;l++)if(!o.advancePageFrame(a,l))return"done";return o.finishPage(a)},failed:()=>o.failed(),beginFinalization:()=>{const a=o.beginFinalization();return a!=="drain"&&o.end(),a},drainOne(){if(!o.current())return o.end(),"stop";const a=o.takePending();return a?o.advancePending(a)?"again":(o.end(),"stop"):"tail"},finishFinalization:()=>{try{return o.finishFinalization()}finally{o.end()}}}});return n.start(()=>{i.request().catch(()=>{})}),Object.freeze({dispose:n.dispose})}function tl(e){const r=pe(),[t,n]=g.useState(()=>ge(e,r));g.useLayoutEffect(()=>{const a=el(e,r,n);return()=>a.dispose()},[e,r]);const i=t.documentId===e&&t.transport===r?t:ge(e,r);return{channel:g.useMemo(()=>_s(i),[i]),events:i.events,frameAdmission:i.frameAdmission}}function rl({content:e}){const[r]=Kt();return r?h.jsx("div",{className:"h-full w-full",children:h.jsx(pi,{sessionId:r,serverName:e.serverName,uri:e.uri,title:e.title})}):null}const nl=g.lazy(()=>je(()=>import("./CanvasFileContent-ZZhdofR4.js"),__vite__mapDeps([5,1,2,6,7])).then(e=>({default:e.CanvasFileContent}))),il=g.lazy(()=>je(()=>import("./CanvasModel3dContent-DMMMZh4o.js"),__vite__mapDeps([8,1,2,6,7])).then(e=>({default:e.CanvasModel3dContent}))),ol=g.lazy(()=>je(()=>import("./CanvasCsvContent-QhDSf8Pd.js"),__vite__mapDeps([9,1,2,10,6,7])).then(e=>({default:e.CanvasCsvContent}))),al=g.lazy(()=>je(()=>import("./index-DMYBI16t.js").then(e=>e.t$),__vite__mapDeps([1,2])).then(e=>({default:e.CanvasDiffContent})));function Cl({documentId:e,widgetChannel:r,content:t,onContentChange:n}){switch(t.type){case"url":case"browser":return h.jsx($i,{documentId:e,content:t},`${e}:${t.url}`);case"markdown":return h.jsx(ao,{documentId:e,content:t,onContentChange:n},t.sourcePath??"generated");case"json":return h.jsx(so,{content:t});case"image":return h.jsx(Ka,{content:t});case"pdf":return h.jsx(es,{content:t});case"audio":return h.jsx(ns,{content:t});case"video":return h.jsx(is,{content:t});case"widget":return r?h.jsx(On,{content:t,documentId:e,channel:r}):h.jsx(sl,{documentId:e,content:t});case"mcp_app":return h.jsx(rl,{content:t});case"file":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(nl,{documentId:e,content:t})});case"model3d":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(il,{content:t})});case"csv":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(ol,{content:t})});case"diff":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(al,{documentId:e,content:t},t.sourcePath)})}}function ht(){return h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"})}function sl({documentId:e,content:r}){const{channel:t}=tl(e);return h.jsx(On,{documentId:e,content:r,channel:t})}const ll=g.lazy(()=>je(()=>import("./BlintzCanvas-CXi0fvcM.js"),__vite__mapDeps([0,1,2,3,4])).then(e=>({default:e.BlintzCanvas})));function Sl({roomId:e,document:r,content:t,onSave:n}){const[i,o]=g.useState(null),[a,s]=g.useState(!1),[l,c]=g.useState(null),u=i!==null,d=t.sourcePath===void 0;Di(e,u?r.id:null);const f=async()=>{if(i===null)return;if(i===t.content){o(null),c(null);return}s(!0),c(null);const p=await n(r.id,{...t,content:i});s(!1),p?o(null):c("Couldn’t save. Your words are still here. Try again.")};return h.jsxs("div",{className:"flex h-full flex-col",children:[d&&h.jsxs("div",{className:"flex items-center justify-end gap-2 border-b px-2 py-1",children:[u&&h.jsx("span",{className:"text-muted-foreground text-xs",children:a?"Saving…":"Everyone sees your save."}),h.jsx(mt,{type:"button",size:"xs",variant:"ghost",disabled:a,"aria-label":u?"Save for the room":"Edit this document",onClick:()=>u?void f():o(t.content),children:u?h.jsx(qr,{className:"size-3.5"}):h.jsx(Hr,{className:"size-3.5"})})]}),l!==null&&h.jsx("p",{role:"status",className:"text-destructive border-b px-2 py-1 text-xs",children:l}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(g.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"}),children:h.jsx(ll,{value:i??t.content,editable:u,onChange:o},u?"editing":`rev-${r.rev}`)})})]})}const Qt="dorkos-canvas-sessions",ul=1440*60*60*1e3;function Xn(){try{const e=localStorage.getItem(Qt);if(!e)return null;const r=JSON.parse(e);return r===null||typeof r!="object"?null:r}catch{return null}}function Wn(e){try{Object.keys(e).length===0?localStorage.removeItem(Qt):localStorage.setItem(Qt,JSON.stringify(e))}catch{}}function cl(e){return Array.isArray(e.documents)?[...e.documents].sort((r,t)=>(r.openedAt??0)-(t.openedAt??0)).map(r=>r.content).filter(r=>!!r):e.content?[e.content]:[]}function Ct(e){return e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(Ct).join(",")}]`:`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t<n?-1:t>n?1:0).map(([t,n])=>`${JSON.stringify(t)}:${Ct(n)}`).join(",")}}`}function dl(e,r){const t=new Set,n=new Map;for(const o of e){const a=Cr(o.content);if(a!==null){t.add(a);continue}const s=Ct(o.content);n.set(s,(n.get(s)??0)+1)}const i=[];for(const o of r){const a=Cr(o);if(a!==null){t.has(a)||i.push(o);continue}const s=Ct(o),l=n.get(s)??0;l>0?n.set(s,l-1):i.push(o)}return i}const vt=new Set;function Pl(){vt.clear()}function kl(e,r={}){const t=pe(),n=r.canonical??!0;g.useEffect(()=>{e&&K.getState().loadCanvasForSession(e)},[e]),g.useEffect(()=>{if(!e||!n||vt.has(e))return;const i=Xn();if(!i)return;const o=i[e];if(!o){fl(i);return}vt.add(e),(async()=>{try{const a=cl(o),s=dl(await t.listSessionCanvas(e),a);if(s.length===0){Fr(e);return}for(const l of s)await t.openSessionCanvasDocument(e,l);Fr(e),K.getState().hydrateCanvasFromSnapshot(e,await t.listSessionCanvas(e))}catch{vt.delete(e)}})()},[e,n,t])}function Fr(e){const r=Xn();if(!r)return;const{[e]:t,...n}=r;Wn(n)}function fl(e){const r=Date.now()-ul,t=Object.entries(e).filter(([,n])=>n.accessedAt===void 0||n.accessedAt>=r);t.length!==Object.keys(e).length&&Wn(Object.fromEntries(t))}export{Cl as C,wl as F,Sl as R,zi as a,xi as b,yl as c,On as d,Pl as e,Ai as f,tl as g,kl as h,Tn as r,ro as u};
64
+ `,Mt={wrapper:"transform-component-module_wrapper__SPB86",content:"transform-component-module_content__FBWxo",infiniteGrid:"transform-component-module_infiniteGrid__Z-aP3"};Fa(qa);var Ha=function(e){var r,t=e.children,n=e.wrapperClass,i=n===void 0?"":n,o=e.contentClass,a=o===void 0?"":o,s=e.wrapperStyle,l=e.contentStyle,c=e.wrapperProps,u=c===void 0?{}:c,d=e.contentProps,f=d===void 0?{}:d,p=e.infinite,v=p===void 0?!1:p,m=g.useContext(lt),k=m.init,w=m.cleanupWindowEvents,A=g.useRef(null),C=g.useRef(null),O=g.useRef(null);or(function(){var Y=A.current,N=C.current;return Y!==null&&N!==null&&k&&(k==null||k(Y,N)),function(){w==null||w()}},[]),g.useEffect(function(){if(v){var Y=O.current;if(Y){var N=function(){var M=m.state,W=M.positionX,q=M.positionY;Y.style.backgroundPosition="".concat(W,"px ").concat(q,"px")};return N(),m.onChange(N)}}},[v,m]);var z=!(!((r=m.setup.keyboard)===null||r===void 0)&&r.disabled);return h.jsxs("div",de({tabIndex:z?0:void 0},u,{ref:A,className:"".concat(Bt.wrapperClass," ").concat(Mt.wrapper," ").concat(i),style:s},{children:[v&&h.jsx("div",{ref:O,className:Mt.infiniteGrid,"aria-hidden":!0}),h.jsx("div",de({},f,{ref:C,className:"".concat(Bt.contentClass," ").concat(Mt.content," ").concat(a),style:de(de({transformOrigin:"0 0"},l),{transform:fn(m.state.positionX,m.state.positionY,m.state.scale)})},{children:t}))]}))};function Ua(e,r){var t=Math.max(0,Math.min(e.x+e.width,r.x+r.width)-Math.max(e.x,r.x)),n=Math.max(0,Math.min(e.y+e.height,r.y+r.height)-Math.max(e.y,r.y));return t*n}function Za(e){var r=e.elementX,t=e.elementY,n=e.elementWidth,i=e.elementHeight,o=e.scale,a=e.positionX,s=e.positionY,l=e.viewportWidth,c=e.viewportHeight,u=e.margin,d=u===void 0?0:u,f=e.threshold,p=f===void 0?0:f,v={x:-d,y:-d,width:l+2*d,height:c+2*d},m={x:r*o+a,y:t*o+s,width:n*o,height:i*o};if(p<=0){var k=m.x<v.x+v.width&&m.x+m.width>v.x,w=m.y<v.y+v.height&&m.y+m.height>v.y;return k&&w}var A=m.width*m.height;if(A<=0)return!1;var C=Ua(v,m);return C/A>=p}Pt.forwardRef(function(e,r){var t=e.x,n=e.y,i=e.width,o=e.height,a=e.margin,s=a===void 0?0:a,l=e.threshold,c=l===void 0?0:l,u=e.placeholder,d=u===void 0?null:u,f=e.onShow,p=e.onHide,v=e.children,m=e.className,k=e.style,w=g.useContext(lt),A=function(){var W=w.wrapperComponent;return W?Za({elementX:t,elementY:n,elementWidth:i,elementHeight:o,scale:w.state.scale,positionX:w.state.positionX,positionY:w.state.positionY,viewportWidth:W.clientWidth,viewportHeight:W.clientHeight,margin:s,threshold:c}):!1},C=g.useState(A),O=C[0],z=C[1],Y=g.useRef(!1),N=g.useRef(f),M=g.useRef(p);return N.current=f,M.current=p,or(function(){var W=function(){var y,E;if(w.wrapperComponent){var R=A();R!==Y.current&&(Y.current=R,z(R),R?(y=N.current)===null||y===void 0||y.call(N):(E=M.current)===null||E===void 0||E.call(M))}};W();var q=w.onChange(W),B;return w.wrapperComponent||(B=w.onInit(function(){return W()})),function(){q(),B==null||B()}},[w,t,n,i,o,s,c]),O?h.jsx("div",de({ref:r,className:m,style:k},{children:v})):d?h.jsx(h.Fragment,{children:d}):null});var Va=function(){var e=g.useContext(lt);if(!e)throw new Error("Transform context must be placed inside TransformWrapper");return e},Ga=function(){var e=Va();return nt(e)};const $a=new Set(["http:","https:"]);function Ja(e){const r=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!r||r[1].length===1?null:`${r[1].toLowerCase()}:`}const Qa={image:"data:image/",pdf:"data:application/pdf"};function Pn(e,r,t){const n=e.trim();if(n.startsWith("data:"))return n.toLowerCase().startsWith(Qa[r])?{url:n,error:null}:{url:null,error:"unsupported-data"};const i=Ja(n);if(i!==null)return $a.has(i)?{url:n,error:null}:{url:null,error:"blocked"};const o=t(n);return o?{url:o,error:null}:{url:null,error:"local-unavailable"}}function En(e,r){switch(e){case"blocked":return`This ${r} source is blocked for safety.`;case"unsupported-data":return`This data URI isn’t a valid ${r} source.`;case"local-unavailable":return`Local ${r} files can’t be displayed here.`}}function Ka({content:e}){const r=pe(),t=K(u=>u.selectedCwd),n=g.useMemo(()=>Pn(e.src,"image",u=>r.mediaUrl(t??"",u)),[e.src,r,t]),[i,o]=g.useState("loading"),[a,s]=g.useState(e.src);a!==e.src&&(s(e.src),o("loading"));const l=e.alt??e.title??"Canvas image";if(n.url===null){const u=n.error?En(n.error,"image"):"";return h.jsx(Mr,{children:u})}const c=n.url;return h.jsxs("div",{className:"bg-muted/40 relative flex h-full items-center justify-center",children:[i==="loading"&&h.jsx("p",{className:"text-muted-foreground absolute text-sm","aria-live":"polite",children:"Loading image…"}),i==="error"?h.jsx(Mr,{children:"This image couldn’t be loaded."}):h.jsxs(La,{centerOnInit:!0,doubleClick:{mode:"toggle"},wheel:{step:.15},children:[h.jsx(Ia,{}),h.jsx(Ha,{wrapperClass:"!h-full !w-full",contentClass:"!h-full !w-full flex items-center justify-center",children:h.jsx("img",{src:c,alt:l,onLoad:()=>o("loaded"),onError:()=>o("error"),className:It("max-h-full max-w-full object-contain transition-opacity",i==="loaded"?"opacity-100":"opacity-0")})})]})]})}function Ia(){const{zoomIn:e,zoomOut:r,resetTransform:t}=Ga();return h.jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[h.jsx(Yt,{label:"Zoom in",onClick:()=>e(),children:h.jsx(mi,{className:"size-4"})}),h.jsx(Yt,{label:"Zoom out",onClick:()=>r(),children:h.jsx(vi,{className:"size-4"})}),h.jsx(Yt,{label:"Reset zoom",onClick:()=>t(),children:h.jsx(hi,{className:"size-4"})})]})}function Yt({label:e,onClick:r,children:t}){return h.jsx("button",{type:"button",onClick:r,"aria-label":e,className:"bg-background/80 text-muted-foreground hover:text-foreground focus-ring rounded-md border p-1.5 backdrop-blur transition-colors",children:t})}function Mr({children:e}){return h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:e})})}function es({content:e}){const r=pe(),t=K(a=>a.selectedCwd),n=g.useMemo(()=>Pn(e.src,"pdf",a=>r.mediaUrl(t??"",a)),[e.src,r,t]);if(n.url===null){const a=n.error?En(n.error,"pdf"):"";return h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:a})})}const i=n.url,o=e.title??"PDF document";return h.jsx("object",{data:i,type:"application/pdf",title:o,className:"h-full w-full",children:h.jsxs("div",{className:"text-muted-foreground flex h-full flex-col items-center justify-center gap-3 p-8 text-center",children:[h.jsx("p",{children:"This PDF can’t be shown here."}),h.jsxs("a",{href:i,target:"_blank",rel:"noreferrer",className:"text-foreground focus-ring rounded-md underline underline-offset-4",children:["Open ",o," in a new tab"]})]})})}function ts(e){const r=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!r||r[1].length===1?null:`${r[1].toLowerCase()}:`}const rs=new Set(["http:","https:","data:"]);function Tn(e,r,t){const n=e.trim(),i=ts(n);return i!==null?rs.has(i)?i==="data:"&&t!==void 0?n.toLowerCase().startsWith(t)?{url:n}:{url:null}:{url:n}:{url:null}:{url:r(n)}}function ns({content:e}){const r=pe(),t=K(o=>o.selectedCwd),n=g.useMemo(()=>Tn(e.src,o=>r.mediaUrl(t??"",o),"data:audio/"),[e.src,r,t]),i=e.title??"Canvas audio";return n.url===null?h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:"This audio can’t be played here."})}):h.jsx("div",{className:"bg-muted/40 flex h-full w-full items-center justify-center p-8",children:h.jsx("audio",{controls:!0,src:n.url,"aria-label":i,className:"w-full max-w-2xl",children:h.jsxs("p",{className:"text-muted-foreground text-sm",children:["Your browser can’t play this audio."," ",h.jsxs("a",{href:n.url,className:"text-foreground underline underline-offset-4",children:["Download ",i]}),"."]})})})}function is({content:e}){const r=pe(),t=K(o=>o.selectedCwd),n=g.useMemo(()=>Tn(e.src,o=>r.mediaUrl(t??"",o),"data:video/"),[e.src,r,t]),i=e.title??"Canvas video";return n.url===null?h.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-8 text-center",children:h.jsx("p",{children:"This video can’t be played here."})}):h.jsx("div",{className:"bg-muted/40 flex h-full w-full items-center justify-center",children:h.jsx("video",{controls:!0,src:n.url,"aria-label":i,className:"max-h-full w-full max-w-full object-contain",children:h.jsxs("p",{className:"text-muted-foreground p-8 text-sm",children:["Your browser can’t play this video."," ",h.jsxs("a",{href:n.url,className:"text-foreground underline underline-offset-4",children:["Download ",i]}),"."]})})})}function On({content:e,documentId:r,channel:t}){const[n]=Kt(),i=ii(e.definition),o=g.useMemo(()=>JSON.stringify(e.definition),[e.definition]);return h.jsx("div",{className:"p-4",children:i.ok?h.jsx(oi,{channel:t,document:i.document,sessionId:n??void 0},t?r??t.documentId:o):h.jsx(ai,{error:i.error,raw:i.raw})})}const ot=et().min(1).max(128),ve={protocol:Q("dorkos-doc"),v:Q(1),nonce:ot,requestToken:ot,loadToken:Wt,generation:Ur.shape.generation};kt("kind",[ie({...ve,kind:Q("challenge")}).strict(),ie({...ve,kind:Q("ack")}).strict(),ie({...ve,kind:Q("connect")}).strict()]);kt("kind",[ie({...ve,kind:Q("emit"),requestId:ot,event:gt}).strict(),ie({...ve,kind:Q("retire")}).strict()]);kt("kind",[ie({...ve,kind:Q("receipt"),requestId:ot,receipt:Zr}).strict(),ie({...ve,kind:Q("refused"),requestId:ot,outcome:wr(["cancelled","unconfirmed","refused"])}).strict(),ie({...ve,kind:Q("state"),state:li,stateRev:Wt,docSeq:Wt,reset:yr()}).strict(),ie({...ve,kind:Q("event"),frame:ui}).strict(),ie({...ve,kind:Q("status"),status:wr(["connecting","ready","offline","revoked"]),unconfirmed:yr()}).strict()]);function os(e,r){try{if(si(r,1048576)!==void 0)return null;const t=e.safeParse(r);return t.success?t.data:null}catch{return null}}class as{constructor(){ee(this,"contiguous",0);ee(this,"through",0);ee(this,"pending",new Map)}get highest(){return this.contiguous}get catchUpThrough(){return this.through}get pendingCount(){return this.pending.size}reset(){this.contiguous=0,this.through=0,this.pending.clear()}resetHighest(){this.contiguous=0}advance(r){this.contiguous=Math.max(this.contiguous,r)}markThrough(r){this.through=Math.max(this.through,r)}recordGap(r){return this.markThrough(r.docSeq),this.pending.set(r.docSeq,r),this.pending.size<=200?!1:(this.pending.clear(),!0)}takeNextContiguous(){for(const n of this.pending.keys())n<=this.contiguous&&this.pending.delete(n);const r=this.contiguous+1,t=this.pending.get(r);return t&&this.pending.delete(r),t}clearReachedTarget(){return this.contiguous<this.through?!1:(this.through=0,!0)}}const qt=new WeakMap,ut=new WeakMap,Se=new WeakMap,Ke=new WeakMap;function _e(e){Ye(e);const r=qt.get(e);if(!r)throw new Error("Replay owner lifetime is absent.");return r}function ss(e,r){const t=ut.get(r);if(!t||t.owner!==e)throw new Error("Replay run is foreign.");return t}function _n(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){for(const r of Object.values(e))_n(r);Object.freeze(e)}return e}function ls(e){if(Ye(e),qt.has(e))throw new Error("Replay owner lifetime is already initialized.");qt.set(e,new as)}function ar(e){const r=_e(e);return Object.freeze({highest:r.highest,through:r.catchUpThrough,pending:r.pendingCount})}function Yr(e){_e(e).reset()}function Xr(e,r){const t=ut.get(r);if(!(!t||t.owner!==e))return Object.freeze({subject:t.subject,epoch:t.epoch,revision:t.revision,observation:t.observation,ended:t.ended})}function us(e,r,t){const n=Se.get(t),i=ut.get(r);if(!(!i||i.owner!==e||!n||n.owner!==e||n.run!==r||n.phase!=="consuming"||n.admissionRead||!re(e,r)))return n.admissionRead=!0,Object.freeze({response:n.response,since:n.since,revision:n.revision,observation:n.observation,targetBirth:i.targetBirth})}function cs(e,r,t){const n=ss(e,r),i=Se.get(t),o=zn(e,r,t);if(!o||!i||i.owner!==e||i.run!==r||i.phase!=="consuming"||!i.admissionRead||n.ended||n.epoch!==o.epoch||n.subject!==o.previous)throw new Error("Replay own issuance is foreign or stale.");n.subject=o.subject}function jn(e,r,t,n){if(!re(e,r))return;if(n){const o=Ke.get(t);return o&&o.owner===e&&o.run===r&&o.phase==="dispatching"&&!o.advanced?o.frame:void 0}const i=Se.get(t);return i&&i.owner===e&&i.run===r&&i.phase==="frames"&&i.dispatching!==void 0&&!i.advanced?i.frames[i.dispatching]:void 0}function ds(e,r,t,n){const i=Xs(e,r,t,n);if(!i||!re(e,r))throw new Error("Replay cursor advance has no genuine core witness.");const o=n?Ke.get(t):Se.get(t);if(!o||o.advanced)throw new Error("Replay frame advance was consumed.");o.advanced=!0,_e(e).advance(i.docSeq)}function fs(e,r){const t=ut.get(r),n=(t==null?void 0:t.lastPage)&&Se.get(t.lastPage);if(!t||t.owner!==e||!re(e,r)||t.target===void 0||!n||n.phase!=="finished"||n.next!==n.frames.length||n.response.events.length>=200&&_e(e).highest<t.target)return;const i=_e(e);return Object.freeze({highest:i.highest,through:i.catchUpThrough,target:t.target})}function ps(e,r){const t=st(e,r);if(!t)throw new Error("Replay notice is foreign or stale.");const n=_e(e),i=t.notification;if(t.mode==="quarantine")n.markThrough(i.type==="canvas_channel_snapshot"?i.snapshot.highWatermark:i.docSeq),i.type!=="canvas_channel_snapshot"&&n.recordGap(i);else{if(t.mode==="gap"&&i.type!=="canvas_channel_snapshot")return n.recordGap(i);t.mode==="event"&&Qs(e,r)}return!1}function hs(e,r){const t=st(e,r);if(!t||t.mode!=="event"||t.notification.type==="canvas_channel_snapshot")throw new Error("Notice cursor advance is foreign.");_e(e).advance(t.notification.docSeq)}function ms(e){const r=fe(e),t=_e(e),n=Object.freeze({}),i={owner:e,subject:r.subject,epoch:r.epoch,revision:r.revision,observation:r.observation,ended:!1,starting:t.highest,succeeded:!1};ut.set(n,i),Fs(e,n);const o=()=>re(e,n),a=()=>fe(e).live?o()?void 0:"restart":"stop";return Object.freeze({async readPage(){if(!o())return null;const s=fe(e),l=t.highest,c=_t(e),u=c.getCanvasChannel;if(!o())return null;const d=await u.call(c,r.documentId,{since:l,limit:200});if(!o())return null;const f=_n(ci.parse(d));if(!o())return null;const p=Object.freeze({});return Se.set(p,{owner:e,run:n,response:f,since:l,revision:s.revision,observation:s.observation,phase:"read",admissionRead:!1,frames:[],next:0,advanced:!1}),p},consumePage(s){const l=Se.get(s);return!o()||!l||l.owner!==e||l.run!==n||l.phase!=="read"?{kind:"done"}:(l.phase="consuming",qs(e,n,s)!=="accepted"||!o()?(l.phase="finished",{kind:"done"}):(i.target??(i.target=l.response.highWatermark),i.targetBirth=l.response.incarnation,l.frames=Object.freeze(l.response.events.filter(u=>u.docSeq<=i.target)),l.phase="frames",i.lastPage=s,l.response.resetRequired&&t.advance(l.response.retentionFloor-1),{kind:"frames",count:l.frames.length}))},advancePageFrame(s,l){const c=Se.get(s);if(!o()||!c||c.owner!==e||c.run!==n||c.phase!=="frames"||l!==c.next||!c.frames[l])return!1;c.next=l+1,c.dispatching=l,c.advanced=!1;try{return Br(e,n,s,!1)&&o()}finally{c.dispatching=void 0}},finishPage(s){const l=Se.get(s);if(!o()||!l||l.owner!==e||l.run!==n||l.phase!=="frames"||l.next!==l.frames.length||i.target===void 0)return"done";if(l.phase="finished",l.response.events.length<200||t.highest>=i.target)return t.advance(i.target),!o()||(Lr(e,n),!o())||(i.succeeded=!0),"done";if(t.highest<=l.since)throw new Error("Document replay made no progress.");return"again"},failed(){o()&&Hs(e,n)},beginFinalization(){return a()??(i.succeeded?"drain":"stop")},takePending(){if(!o())return null;const s=t.takeNextContiguous();if(!s||!o())return null;const l=Object.freeze({});return Ke.set(l,{owner:e,run:n,frame:s,phase:"taken",advanced:!1}),l},advancePending(s){const l=Ke.get(s);if(!o()||!l||l.owner!==e||l.run!==n||l.phase!=="taken")return!1;l.phase="dispatching";try{return Br(e,n,s,!0)&&o()}finally{l.phase="finished",Ke.delete(s)}},finishFinalization(){const s=a();if(s)return s;if(t.clearReachedTarget()){const l=a();if(l)return l;Lr(e,n);const c=a();if(c)return c}if(t.pendingCount||t.catchUpThrough>t.highest){const l=fe(e);if(t.highest>i.starting||l.revision>i.revision||l.observation>i.observation)return"restart";Us(e,n)}return a()??"stop"},current:o,end:()=>{i.ended=!0}})}var be,Ut,$e;class Ht{constructor(){gr(this,be);ee(this,"current",null);ee(this,"token",0);ee(this,"retiring",!1);ee(this,"subscribers",new Set);ee(this,"resources",new Map);ee(this,"doc",null);ee(this,"docClaims",new WeakMap);ee(this,"retiringDoc",!1);ee(this,"docResources",new Map);ee(this,"bindings",new WeakSet)}getCurrent(){return this.current}observeHostContext(r){if(this.retiring)return null;if(!r.transportOwner||typeof r.transportOwner!="object"||!Number.isSafeInteger(r.publisherEpoch)||r.publisherEpoch<0)throw new Error("Explicit transport owner and epoch required.");const t=["frame","documentId","resolvedSource","logicalUrl","reloadKey","sessionId","eligibility","exactOrigin","transportOwner","publisherEpoch"];if(t.some(i=>!Object.hasOwn(r,i))||typeof r.documentId!="string"||!r.documentId||typeof r.logicalUrl!="string"||typeof r.reloadKey!="string")throw new Error("Complete host context required.");const n=this.current;return n&&t.every(i=>Object.is(n[i],r[i]))?n:(this.retire(),this.current=Object.freeze({...r,token:this.token,loaded:!1}),this.current)}observeLoaded(r){return this.retiring||this.current!==r||!r.frame?null:(this.retire(),this.current=Object.freeze({...r,token:this.token,loaded:!0}),this.current)}retire(){if(this.retiring)return;const r=this.current;this.current=null;const t=this.doc;this.doc=null,this.token++,this.retiring=!0;const n=[...r?this.resources.get(r)??[]:[],...t?this.docResources.get(t)??[]:[],...this.subscribers];t&&this.docResources.delete(t),r&&this.resources.delete(r);try{for(const i of n)try{const o=i();o&&typeof o.then=="function"&&Promise.resolve(o).catch(()=>{})}catch{}}finally{this.retiring=!1}}subscribe(r){return this.subscribers.add(r),()=>{this.subscribers.delete(r)}}own(r,t){if(this.retiring||this.current!==r)throw new Error("Frame observation retired.");const n=this.resources.get(r)??new Set;return n.add(t),this.resources.set(r,n),()=>{n.delete(t)}}bindDoc(r,t,n){return xe(this,be,Ut).call(this,r,t,n)}acquireDoc(r,t,n){const i=xe(this,be,Ut).call(this,r,t,n),o=Object.freeze({});this.docClaims.set(i,o);let a=!1;return Object.freeze({binding:i,release:()=>{a||(a=!0,this.docClaims.get(i)===o&&(this.docClaims.delete(i),this.doc===i&&this.bindings.has(i)&&xe(this,be,$e).call(this)))}})}disableDoc(){xe(this,be,$e).call(this)}retireDoc(r){this.doc===r&&this.bindings.has(r)&&xe(this,be,$e).call(this)}ownDoc(r,t){if(!this.isCurrent(r))throw new Error("Doc binding retired.");const n=this.docResources.get(r)??new Set;return n.add(t),this.docResources.set(r,n),()=>{n.delete(t)}}isCurrent(r){return!this.retiring&&!this.retiringDoc&&this.doc===r&&this.bindings.has(r)&&this.current===r.observation}}be=new WeakSet,Ut=function(r,t,n){const i=this.doc,o=this.token,a=os(Ur,t);if(!a)throw this.disableDoc(),new Error("Established server Doc birth required.");const s=a,l=r.exactOrigin,c=r.eligibility==="served-document"?l==="null":r.eligibility==="preview-listener"&&l!==null&&new URL(l).origin===l;if(!r.loaded||!r.frame||typeof r.frame.postMessage!="function"||!r.resolvedSource||!c||r.documentId!==s.documentId||!n||n.length>200)throw new Error("Loaded eligible frame and established Doc birth required.");if(this.retiring||this.retiringDoc||this.current!==r||this.doc!==i||this.token!==o)throw new Error("Frame observation retired during Doc admission.");if(this.doc){if(this.doc.observation!==r)throw new Error("Doc binding belongs to another host load.");if(te(this.doc.incarnation,s)&&this.doc.scope===n)return this.doc;throw this.retire(),new Error("Doc birth changed; a fresh host load is required.")}const u=Object.freeze({observation:r,incarnation:Object.freeze(s),scope:n});try{return this.doc=u,this.bindings.add(u),u}catch(d){throw this.doc===u&&xe(this,be,$e).call(this),d}},$e=function(){if(this.retiringDoc)return;const r=this.doc;this.doc=null,this.retiringDoc=!0;const t=[...r?this.docResources.get(r)??[]:[]];r&&this.docResources.delete(r);try{for(const n of t)try{const i=n();i&&typeof i.then=="function"&&Promise.resolve(i).catch(()=>{})}catch{}}finally{this.retiringDoc=!1}};function vs(e,r,t){if(!t||typeof t.captureOriginal!="function"||typeof t.submit!="function"||typeof t.inspect!="function"||typeof t.isCurrentOwner!="function"||t.owner!==r.observation.transportOwner||t.publisherEpoch!==r.observation.publisherEpoch)throw new Error("Explicit current transport submit and inspect ports required.");const{owner:n,publisherEpoch:i,isCurrentOwner:o,submit:a,inspect:s,captureOriginal:l}=t,c=Object.freeze({expectedGeneration:r.incarnation.generation}),u=()=>{try{return e.isCurrent(r)?o(n,i)===!0&&e.isCurrent(r):!1}catch{return!1}};if(!u())throw new Error("Doc binding unavailable.");const d=()=>{if(!u())throw new Error("Doc binding retired.")};return Object.freeze({binding:r,current:u,captureOriginal:f=>{d();const p=f.id;d();const v=f.bytes;d();const m=Reflect.apply(l,t,[Object.freeze({id:p,bytes:v})]);if(d(),!m)return null;const k=m.id;d();const w=m.bytes;d();const A=m.submit;d();const C=m.inspect;return d(),k!==p||w!==v||typeof A!="function"||typeof C!="function"?null:Object.freeze({id:p,bytes:v,submit:async O=>{d(),O.throwIfAborted();const z=await Reflect.apply(A,m,[O]);return d(),O.throwIfAborted(),z},inspect:async O=>{d(),O.throwIfAborted();const z=await Reflect.apply(C,m,[O]);return d(),O.throwIfAborted(),z}})},retireObservation:()=>{u()&&e.retire()},onRetire:f=>e.ownDoc(r,f),submit:(f,p)=>(d(),p.throwIfAborted(),a(f,c,p)),inspect:(f,p)=>(d(),p.throwIfAborted(),s(f,c,p))})}class gs{constructor(){ee(this,"revision",0);ee(this,"draining",!1);ee(this,"cleanup");ee(this,"subscribers",new Set);ee(this,"retirements",new WeakMap)}captureRetirement(){const r=Object.freeze({}),t=++this.revision,n=this.cleanup;return this.cleanup=void 0,this.retirements.set(r,{revision:t,cleanup:n,callbacks:this.draining?[]:[...this.subscribers]}),r}drainRetirement(r){const t=this.retirements.get(r);if(!t)throw new Error("Frame resource retirement is foreign or consumed.");this.retirements.delete(r);const n=this.draining;this.draining=!0;try{this.drain(t.cleanup);for(const i of t.callbacks)this.drain(i)}finally{this.draining=n}}begin(){const r=this.captureRetirement(),t=this.revision;return this.drainRetirement(r),t}once(r,t,n){let i=!1;return()=>{if(i||(i=!0,!this.current(r)||!t()||!this.current(r)))return null;const o=n();return!this.current(r)||!t()||!this.current(r)?null:o}}drain(r){try{Promise.resolve(r==null?void 0:r()).catch(()=>{})}catch{}}current(r){return this.revision===r}install(r,t){return this.current(r)?(this.cleanup=t,!0):!1}subscribe(r){return this.subscribers.add(r),()=>{this.subscribers.delete(r)}}}function bs(e,r,t){const n=()=>e.current(r)&&t.current()===!0&&e.current(r),i=e.once(r,n,t.complete);return Object.freeze({completeLoad:()=>{const o=i();return!o||!n()||t.accept(o)!==!0||!n()?null:o}})}function ws(e,r,t){const n=()=>e.current(r)&&t.current()===!0&&e.current(r);if(!n())return null;const i=t.acquire();if(!i)return null;let o=!1,a=null,s;try{const l=i.binding;if(n()&&t.bindingCurrent(l)===!0&&n()){const c=t.createPort(l);n()&&t.portCurrent(c)===!0&&n()&&e.install(r,i.release)&&(o=!0,a=c)}}catch(l){s={cause:l}}if(!o)try{i.release()}catch(l){s??(s={cause:l})}if(s)throw s.cause;return a}function ys(e){const r=()=>Object.assign(new Error("Document actions are unavailable."),{status:409}),t=(i,o)=>{if(o.aborted||!e.current(i)||o.aborted)throw r()},n=(i,o)=>{const a=Zr.parse(o);if(a.receipt.id!==i)throw new Error("Document receipt does not match this action.");return a};return Object.freeze({current:e.current,submit:async(i,o)=>{const a=gt.parse(JSON.parse(JSON.stringify(i))),s=a.id;t("submit",o);const l=await e.submit(a,o);t("read",o);const c=n(s,l);return t("read",o),c},inspect:async(i,o)=>{t("read",o);const a=await e.inspect(i,o);t("read",o);const s=n(i,a);return t("read",o),s},captureOriginal:i=>{const o=gt.parse(JSON.parse(JSON.stringify(i))),a=o.id,s=JSON.stringify(o);if(!e.current("submit"))return null;const l=e.capture(o,s);if(!l||!e.current("submit")||!l.current("submit"))return null;let c=!1;const u=d=>l.current(d)===!0;return Object.freeze({id:a,bytes:s,current:u,submit:async d=>{if(c||d.aborted||!u("submit"))throw r();c=!0;const f=await l.submit(JSON.parse(s),d);if(d.aborted||!u("read"))throw r();const p=n(a,f);if(d.aborted||!u("read"))throw r();return p},inspect:async d=>{if(d.aborted||!u("read"))throw r();const f=await l.inspect(a,d);if(d.aborted||!u("read"))throw r();const p=n(a,f);if(d.aborted||!u("read"))throw r();return p}})}})}function Cs(e){return Object.freeze({id:e.id,bytes:e.bytes,submit:async r=>{try{return{kind:"accepted",receipt:await e.submit(r)}}catch{return{kind:"uncertain"}}},inspect:async r=>{try{return{kind:"accepted",receipt:await e.inspect(r)}}catch{return{kind:"unknown"}}}})}function Ss(e,r,t){const n=gt.parse(JSON.parse(e.bytes));if(n.id!==e.id||JSON.stringify(n)!==e.bytes||!t())return null;const i=r(n);return!t()||!i?null:Cs(i)}const ks=Ht.prototype.acquireDoc,wt=new WeakMap,Zt=new WeakMap;function Ps(e,r){const t=_t(e),n=new WeakMap,i=(a,s)=>r.current(s)&&Ee(e,a,!0);return Object.freeze({prepareFrameLoad:(a,s)=>{var f;if(!(a instanceof Ht)||s.loaded)return null;const l=Wr(e),c=l?(f=De(e,l))==null?void 0:f.httpBaseline:void 0,u=r.begin();if(!l||!c||!r.current(u)||!Ee(e,l,!0)||a.getCurrent()!==s||s.transportOwner!==t||!i(l,u))return null;let d=null;return bs(r,u,{current:()=>{var p;return Ee(e,l,!0)&&((p=De(e,l))==null?void 0:p.httpBaseline)===c&&a.getCurrent()===(d??s)&&r.current(u)&&Ee(e,l,!0)},complete:()=>(d=a.observeLoaded(s),d),accept:p=>{var v,m;return!r.current(u)||!Ee(e,l,!0)||((v=De(e,l))==null?void 0:v.httpBaseline)!==c||a.getCurrent()!==p||!r.current(u)||!Ee(e,l,!0)||((m=De(e,l))==null?void 0:m.httpBaseline)!==c?!1:(n.set(p,{record:l,birth:c.birth}),!0)}})},subscribeInvalidation:a=>r.subscribe(a),attachFrame:(a,s)=>{if(!(a instanceof Ht))return null;const l=Wr(e),c=r.begin();if(!l||!r.current(c)||!Ee(e,l,!0)||a.getCurrent()!==s||s.transportOwner!==t||!i(l,c))return null;const u=n.get(s);return!u||u.record!==l||!te(u.birth,De(e,l).birth)?null:ws(r,c,{current:()=>i(l,c),acquire:()=>{const d=ks.call(a,s,De(e,l).birth,De(e,l).birth.documentId);let f=!1,p=null,v;try{i(l,c)&&a.getCurrent()===s&&i(l,c)&&(p=Object.freeze({binding:d.binding,release:d.release}),f=!0)}catch(m){v={cause:m}}if(!f)try{d.release()}catch(m){v??(v={cause:m})}if(v)throw v.cause;return p},bindingCurrent:d=>a.isCurrent(d)&&i(l,c),createPort:d=>vs(a,d,{owner:t,publisherEpoch:s.publisherEpoch,isCurrentOwner:(f,p)=>f===t&&p===s.publisherEpoch&&r.current(c)&&Ee(e,l),captureOriginal:f=>Ss(f,p=>{var v;return((v=Ls(e,l))==null?void 0:v.captureOriginal(p))??null},()=>i(l,c)),submit:async()=>({kind:"terminal"}),inspect:async()=>({kind:"unknown"})}),portCurrent:d=>d.current()&&i(l,c)})}})}function Es(e){if(Ye(e),wt.has(e))throw new Error("Frame owner is already initialized.");const r=new gs,t=Ps(e,r);return wt.set(e,{frames:r,facade:t}),t}function Ts(e){var r;return Ye(e),(r=wt.get(e))==null?void 0:r.facade}function Je(e){Ye(e);const r=wt.get(e);if(!r)return;const t=Object.freeze({});return Zt.set(t,{owner:e,frames:r.frames,ticket:r.frames.captureRetirement()}),t}function Qe(e,r){if(!r)return;const t=Zt.get(r);if(!t||t.owner!==e)throw new Error("Frame retirement is foreign or consumed.");Zt.delete(r),t.frames.drainRetirement(t.ticket)}function An(e,r){const t=ye(e,r),n=Ys(e,r);if(!(!t||!n))return{owner:r,verified:t.verified,...ys(n)}}function ge(e,r){return{documentId:e,transport:r,events:[],available:!1}}function Os(e,r,t,n,i,o){var l,c;const a=e.documentId===t&&e.transport===n?e:ge(t,n);if(a.snapshot&&(r.highWatermark<a.snapshot.highWatermark||r.stateRev<a.snapshot.stateRev))return a;const s=new Map((((l=a.snapshot)==null?void 0:l.receipts)??[]).filter(u=>u.receipt.docSeq>=r.receiptRetentionFloor).map(u=>[u.receipt.id,u]));for(const u of r.receipts)s.set(u.receipt.id,u);return{...a,available:o,snapshot:{...r,...i?{}:{routing:(c=a.snapshot)==null?void 0:c.routing},receipts:[...s.values()].sort((u,d)=>d.receipt.docSeq-u.receipt.docSeq).slice(0,400)},events:r.resetRequired?a.events.filter(u=>u.docSeq>=r.retentionFloor):a.events}}function _s(e){var t,n,i,o,a,s,l,c,u,d,f,p;const r=async()=>{throw Object.assign(new Error("Document actions are unavailable."),{status:409})};return{documentId:e.documentId,enabled:e.available&&((t=e.binding)==null?void 0:t.verified)===!0&&((i=(n=e.snapshot)==null?void 0:n.routing)==null?void 0:i.enabled)===!0,submissionOwner:(o=e.binding)==null?void 0:o.owner,current:((a=e.binding)==null?void 0:a.current)??(()=>!1),approvedEventTypes:e.available?((l=(s=e.snapshot)==null?void 0:s.routing)==null?void 0:l.approvedEventTypes)??[]:[],destinationLabel:e.available?((u=(c=e.snapshot)==null?void 0:c.routing)==null?void 0:u.destinationLabel)??"Actions unavailable":"Actions unavailable",...e.snapshot?{snapshot:e.snapshot}:{},submit:((d=e.binding)==null?void 0:d.submit)??r,inspect:((f=e.binding)==null?void 0:f.inspect)??r,captureOriginal:(p=e.binding)==null?void 0:p.captureOriginal}}function js(e,r,t){return!!(e&&r&&t.incarnation&&te(r,t.incarnation)&&(t.highWatermark<e.highWatermark||t.stateRev<e.stateRev))}function Rn(e,r,t,n){const i=e.documentId===t&&e.transport===n?e:ge(t,n);return{...i,events:[...i.events,r].slice(-200)}}function As(e,r){if(e.incarnation&&(e.incarnation.documentId!==r||e.events.some(t=>t.documentId!==r||!t.incarnation||!te(e.incarnation,t.incarnation))))throw new Error("Document replay identity changed.")}const Vt=new WeakMap;function Rs(e,r,t){const n=us(e,r,t);if(n)return Vt.set(t,{owner:e,run:r,witness:n}),n}const xn=new WeakMap,at=new WeakMap,Gt=new WeakMap,$t=new WeakMap;function ke(e,r){Ye(e);const t=r??at.get(e),n=t&&xn.get(t);return n&&n.owner===e&&at.get(e)===t&&n.active?n:void 0}function J(e){return Ye(e),at.get(e)}function ye(e,r){const t=ke(e,r);return t?Object.freeze({birth:t.birth,httpBaseline:t.httpBaseline,snapshot:t.snapshot,verified:t.verified}):void 0}function Ie(e,r,t=!1){var o,a;const n=ke(e,r),i=fe(e);return!!n&&i.live&&n.verified&&n.transport===_t(e)&&(!t||((a=(o=n.snapshot)==null?void 0:o.routing)==null?void 0:a.enabled)===!0)}function xs(e){const r=ke(e);at.delete(e),r&&(r.active=!1,r.verified=!1)}function Xt(e,r){const t=ke(e,r);t&&(t.verified=!1)}function zs(e,r,t){const n=ke(e,t);return!n||!re(e,r)?!1:(n.verified=!0,re(e,r))}function Ds(e,r,t){const n=Vt.get(t);Vt.delete(t);const i=(n==null?void 0:n.owner)===e&&n.run===r?n.witness:void 0;if(!i||!re(e,r))return!1;const o=i.response.incarnation;let a=ke(e);if(!a&&!o)return re(e,r);if(!a&&o){const s=fe(e),l=()=>{const v=fe(e);return re(e,r)&&v.epoch===s.epoch&&v.observation===s.observation&&J(e)===s.subject},c=_t(e),u=c.ingestCanvasEvent;if(!l())return!1;const d=Function.prototype.bind.call(u,c),f=c.getCanvasEventReceipt;if(!l())return!1;const p=Function.prototype.bind.call(f,c);if(!l())return!1;a={owner:e,token:Object.freeze({}),birth:Object.freeze({...o}),active:!0,verified:!1,submit:d,inspect:p,transport:c},xn.set(a.token,a),at.set(e,a.token),a.httpBaseline=Object.freeze({birth:a.birth,floor:i.response.receiptRetentionFloor}),Gt.set(t,Object.freeze({owner:e,run:r,epoch:s.epoch,previous:s.subject,subject:a.token}));try{cs(e,r,t)}catch(v){throw ke(e)===a&&Gs(e,r,t),v}finally{Gt.delete(t)}if(!re(e,r))return!1}else if(a){if(!o||!te(a.birth,o))return!1;a.httpBaseline=Object.freeze({birth:a.birth,floor:i.response.receiptRetentionFloor})}return re(e,r)?(a&&(a.verified=$s(e)||a.verified),!0):!1}function sr(e,r,t){const n=lr(e),i=n.subject,o=()=>Mn(e,n,t);if(!i||!Ie(e,i)){const l=Je(e);Qe(e,l)}if(!o())return;const a=i&&An(e,i),s=Ts(e);n.dispatch(l=>{var d;if(!o())return l;const c=((d=l.binding)==null?void 0:d.owner)===i?l:ge(n.documentId,n.transport),u=typeof r=="function"?r(c):r;return o()?{...u,...u.snapshot?{snapshot:Object.freeze({...u.snapshot})}:{},binding:a,frameAdmission:s}:l})}function Ns(e,r,t,n,i){const o=lr(e),a=ke(e);Mn(e,o,i)&&(a&&(a.snapshot=r),sr(e,s=>Os(s,r,o.documentId,o.transport,t,n),i))}function Ms(e,r,t,n){const i=jn(e,r,t,n);if(!re(e,r)||!i)return!1;if(i.docSeq<=ar(e).highest)return re(e,r);$t.set(t,{owner:e,run:r,pending:n,frame:i});try{ds(e,r,t,n)}finally{$t.delete(t)}if(!re(e,r))return!1;const o=lr(e);return sr(e,a=>Rn(a,i,o.documentId,o.transport),r),re(e,r)}function Ys(e,r){const t=ke(e,r);if(!t)return;const n=fe(e).documentId;return{current:i=>Ie(e,r,i==="submit"),submit:(i,o)=>t.submit(n,i,{expectedGeneration:t.birth.generation},o),inspect:(i,o)=>t.inspect(n,i,{expectedGeneration:t.birth.generation},o),capture:()=>{const i=t.httpBaseline;return!i||!Ie(e,r,!0)||!te(i.birth,t.birth)?null:Object.freeze({current:o=>Ie(e,r,o==="submit")&&(o==="read"||t.httpBaseline===i),submit:(o,a)=>t.submit(n,o,{expectedGeneration:i.birth.generation},a),inspect:(o,a)=>t.inspect(n,o,{expectedGeneration:i.birth.generation},a)})}}}function zn(e,r,t){const n=Gt.get(t),i=fe(e);return n&&n.owner===e&&n.run===r&&i.epoch===n.epoch&&i.subject===n.subject&&i.live?n:void 0}function Xs(e,r,t,n){const i=$t.get(t);return i&&i.owner===e&&i.run===r&&i.pending===n&&re(e,r)?i.frame:void 0}const Dn=new WeakMap,yt=new WeakMap;function Ws(e){const r=yt.get(e);if(!r)throw new Error("Document construction ticket is foreign or consumed.");return yt.delete(e),r}function Bs(e,r,t){const n=Object.freeze({});yt.set(n,Object.freeze({documentId:e,transport:r,dispatch:t}));try{const i=Js(n);return Dn.set(n,i),n}finally{yt.delete(n)}}function I(e){const r=Dn.get(e);if(!r)throw new Error("Document owner is foreign.");return r}function Ye(e){I(e)}function fe(e){return I(e).facts()}function _t(e){return I(e).transport()}function Wr(e){return I(e).subject()}function De(e,r){return I(e).subjectFacts(r)}function Ee(e,r,t=!1){return I(e).subjectCurrent(r,t)}function Ls(e,r){return I(e).binding(r)}function Fs(e,r){I(e).reserve(r)}function re(e,r){return I(e).current(r)}function qs(e,r,t){return I(e).admit(r,t)}function Br(e,r,t,n){return I(e).frame(r,t,n)}function Lr(e,r){return I(e).qualify(r)}function Hs(e,r){I(e).failed(r)}function Us(e,r){I(e).unavailable(r)}function Zs(e,r){I(e).start(r)}function Vs(e){I(e).dispose()}const Nn=new WeakMap;function lr(e){const r=Object.freeze(I(e).projection());return Nn.set(r,Object.freeze({custodyKey:e,capture:r})),r}function Mn(e,r,t){const n=Nn.get(r);return(n==null?void 0:n.custodyKey)===e&&n.capture===r&&I(e).projectionCurrent(r.epoch,r.subject,t)}function Gs(e,r,t){I(e).abortAdmission(r,t)}function $s(e){return I(e).qualified()}const Jt=new WeakMap;function Js(e){const{documentId:r,transport:t,dispatch:n}=Ws(e);let i,o=!1,a;const s={live:!0};let l=0,c,u,d=!1,f,p,v=0;const m=()=>s.live,k=()=>xs(e);let w=0;const A=()=>ar(e),C=y=>{const E=Xr(e,y);return!!E&&!E.ended&&m()&&i===y&&E.epoch===l&&E.subject===J(e)},O=(y=!1)=>{const E=Je(e);k(),l++,i=void 0,y&&Yr(e),Qe(e,E)},z=(y,E)=>sr(e,y,E),Y=y=>{const E=fs(e,y),R=J(e),_=R&&ye(e,R);return!C(y)||!E||E.through>E.highest||!f||!_||!te(f,_.birth)||!zs(e,y,R)?!1:(f=void 0,z(D=>({...D,available:!0}),y),C(y))},N=(y,E,R)=>{const _=J(e),D=_&&ye(e,_),Z=l,G=()=>m()&&Z===l&&J(e)===_&&(!R||C(R));if(!G()||js(D==null?void 0:D.snapshot,D==null?void 0:D.birth,y))return;const se=E?y.routing:u;y={...y,routing:se&&Object.freeze({enabled:se.enabled,destinationLabel:se.destinationLabel,approvedEventTypes:Object.freeze([...se.approvedEventTypes])})},E&&(u=y.routing),!_&&!y.incarnation&&(d=!0),G()&&Ns(e,y,E,f===void 0,R)},M=(y,E)=>{var we;const R=Rs(e,y,E);if(!C(y)||!R)return"discard";const _=R.response;As(_,r);const D=_.incarnation;if((J(e)||f||p)&&!D)throw new Error("Document replay identity is unavailable.");if(p&&D&&!te(p,D))return O(!0),z(ge(r,t)),"restart";const Z=J(e),G=(Z&&((we=ye(e,Z))==null?void 0:we.birth))??f;if(D&&(G&&!te(G,D)||!G&&d||R.targetBirth&&!te(R.targetBirth,D)))return f=D,d=!1,u=void 0,c=void 0,O(!0),z(ge(r,t)),"restart";const{events:se,...me}=_,le=J(e);return!le&&D&&(f=p??D),!Ds(e,y,E)||!C(y)?"discard":(!le&&D&&(p=void 0),N(me,R.revision===w,y),C(y)?"accepted":"discard")},W=(y,E,R)=>{var G;const _=jn(e,y,E,R),D=J(e),Z=(D&&((G=ye(e,D))==null?void 0:G.birth))??f;return!C(y)||!_||_.documentId!==r||Z&&(!_.incarnation||!te(Z,_.incarnation))?!1:Ms(e,y,E,R)},q=(y,E)=>{const R=Object.freeze({});Jt.set(R,Object.freeze({owner:e,revision:w,observation:v,epoch:l,notification:y,mode:E}));try{return ps(e,R)}finally{Jt.delete(R)}},B=y=>{if(o||!m()||(o=!0,z(ge(r,t)),!m()))return;const E=di(void 0,R=>{if(!m()||R.documentId!==r)return;const _=R.type==="canvas_channel_snapshot"?R.snapshot.incarnation:R.incarnation,D=J(e);if(!D){if(f&&!p&&(!_||!te(f,_))||!_||_.documentId!==r)return;if(!p||!te(p,_)){const Z=!!p||!!f;if(p=Object.freeze({..._}),v++,u=void 0,c=void 0,d=!1,Z&&(O(!0),z(ge(r,t))),!m()||!p||!te(p,_))return}q(R,"quarantine"),m()&&y();return}if(f&&(!_||!te(f,_))){_&&y();return}if(_&&!te(ye(e,D).birth,_)){f=_,d=!1,u=void 0,c=void 0,O(!0),z(ge(r,t)),m()&&y();return}if(_){if(c!==void 0&&c!==R.scope){const Z=Je(e);if(c=R.scope,Xt(e,D),l++,i=void 0,w++,Qe(e,Z),J(e)!==D||!m())return;z(G=>({...G,available:!1})),J(e)===D&&m()&&y();return}c=R.scope,w++,R.type==="canvas_channel_snapshot"?N(R.snapshot,!0):R.docSeq>A().highest+1?(q(R,"gap")&&m()&&z(G=>({...G,available:!1})),m()&&y()):q(R,"event")}},t,()=>{if(!m())return;const R=Je(e),_=J(e);_&&Xt(e,_),l++,i=void 0,w++,Qe(e,R),z(D=>({...D,available:!1})),m()&&y()});m()?a=E:E(),m()&&y()};return Yn.set(e,y=>{const E=st(e,y);if(!E||E.notification.type==="canvas_channel_snapshot")return;const R=J(e),_=l;!R||!E.notification.incarnation||!te(ye(e,R).birth,E.notification.incarnation)||(z(D=>Rn(D,E.notification,r,t)),!m()||_!==l||J(e))}),{facts:()=>Object.freeze({documentId:r,live:m(),epoch:l,revision:w,observation:v,subject:J(e)}),transport:()=>t,subject:()=>J(e),subjectFacts:y=>ye(e,y),subjectCurrent:(y,E)=>Ie(e,y,E),binding:y=>An(e,y),qualified:()=>f===void 0,projection:()=>({documentId:r,transport:t,dispatch:n,epoch:l,run:i,subject:J(e)}),projectionCurrent:(y,E,R)=>m()&&y===l&&E===J(e)&&(!R||i===R),abortAdmission:(y,E)=>{zn(e,y,E)&&O(!0)},reserve:y=>{const E=Xr(e,y);if(!E||E.ended||!m()||E.epoch!==l||E.subject!==J(e))throw new Error("Replay run is foreign or stale.");i=y},current:C,admit:M,frame:W,qualify:Y,failed:y=>{if(!C(y))return;const E=J(e);E&&Xt(e,E),z(R=>({...R,available:!1}),y)},unavailable:y=>{C(y)&&z(E=>({...E,available:!1}),y)},start:B,dispose:()=>{if(!m())return;const y=Je(e);s.live=!1,i=void 0;const E=a;a=void 0,k(),l++,Yr(e);try{Qe(e,y)}finally{E==null||E()}}}}function st(e,r){const t=Jt.get(r),n=fe(e);if(!(!t||t.owner!==e||!n.live||n.epoch!==t.epoch||n.revision!==t.revision||n.observation!==t.observation))return t}function Qs(e,r){var s;const t=st(e,r);if(!t||t.notification.type==="canvas_channel_snapshot")return;const n=t.notification,o=fe(e).subject,a=o&&ye(e,o);!a||!n.incarnation||!te(a.birth,n.incarnation)||n.docSeq<=ar(e).highest||(hs(e,r),!(!st(e,r)||fe(e).subject!==o)&&((s=Yn.get(e))==null||s(r)))}const Yn=new WeakMap;function Ks(e,r,t){const n=Bs(e,r,t);ls(n);const i=Es(n);return Object.freeze({beginRun:()=>ms(n),frameAdmission:i,start:o=>Zs(n,o),dispose:()=>Vs(n)})}function Is(e){let r,t=0;const n=c=>{r===c&&(r=void 0)},i=(c,u)=>{c.settled||(c.settled=!0,u?c.reject(u.cause):c.resolve())},o=()=>{l().catch(()=>{})},a=(c,u)=>{const d=()=>t===c.revision;if(!d())return;const f=u.beginFinalization();if(d()){if(f==="restart"){o();return}if(f==="drain")for(;d();){const p=u.drainOne();if(!d())return;if(p!=="again"){if(p==="restart")o();else if(p==="tail"){const v=u.finishFinalization();d()&&v==="restart"&&o()}return}}}},s=async c=>{let u,d;try{u=e();try{for(;await u.page()==="again";);}catch(f){u.failed(f)}}catch(f){d={cause:f}}finally{n(c);try{u&&a(c,u)}catch(f){d={cause:f}}finally{i(c,d)}}},l=()=>{if(r)return r.promise;let c,u;const d=new Promise((p,v)=>{c=p,u=v}),f={revision:++t,promise:d,resolve:c,reject:u,settled:!1};return r=f,s(f),d};return Object.freeze({request:l})}function el(e,r,t){const n=Ks(e,r,t),i=Is(()=>{const o=n.beginRun();return{async page(){const a=await o.readPage();if(!a)return"done";const s=o.consumePage(a);if(s.kind!=="frames")return s.kind;for(let l=0;l<s.count;l++)if(!o.advancePageFrame(a,l))return"done";return o.finishPage(a)},failed:()=>o.failed(),beginFinalization:()=>{const a=o.beginFinalization();return a!=="drain"&&o.end(),a},drainOne(){if(!o.current())return o.end(),"stop";const a=o.takePending();return a?o.advancePending(a)?"again":(o.end(),"stop"):"tail"},finishFinalization:()=>{try{return o.finishFinalization()}finally{o.end()}}}});return n.start(()=>{i.request().catch(()=>{})}),Object.freeze({dispose:n.dispose})}function tl(e){const r=pe(),[t,n]=g.useState(()=>ge(e,r));g.useLayoutEffect(()=>{const a=el(e,r,n);return()=>a.dispose()},[e,r]);const i=t.documentId===e&&t.transport===r?t:ge(e,r);return{channel:g.useMemo(()=>_s(i),[i]),events:i.events,frameAdmission:i.frameAdmission}}function rl({content:e}){const[r]=Kt();return r?h.jsx("div",{className:"h-full w-full",children:h.jsx(pi,{sessionId:r,serverName:e.serverName,uri:e.uri,title:e.title})}):null}const nl=g.lazy(()=>je(()=>import("./CanvasFileContent-CX2VNF4o.js"),__vite__mapDeps([5,1,2,6,7])).then(e=>({default:e.CanvasFileContent}))),il=g.lazy(()=>je(()=>import("./CanvasModel3dContent-OprkQsgq.js"),__vite__mapDeps([8,1,2,6,7])).then(e=>({default:e.CanvasModel3dContent}))),ol=g.lazy(()=>je(()=>import("./CanvasCsvContent-DdbIUPMJ.js"),__vite__mapDeps([9,1,2,10,6,7])).then(e=>({default:e.CanvasCsvContent}))),al=g.lazy(()=>je(()=>import("./index-Bbffv0TQ.js").then(e=>e.tW),__vite__mapDeps([1,2])).then(e=>({default:e.CanvasDiffContent})));function Cl({documentId:e,widgetChannel:r,content:t,onContentChange:n}){switch(t.type){case"url":case"browser":return h.jsx($i,{documentId:e,content:t},`${e}:${t.url}`);case"markdown":return h.jsx(ao,{documentId:e,content:t,onContentChange:n},t.sourcePath??"generated");case"json":return h.jsx(so,{content:t});case"image":return h.jsx(Ka,{content:t});case"pdf":return h.jsx(es,{content:t});case"audio":return h.jsx(ns,{content:t});case"video":return h.jsx(is,{content:t});case"widget":return r?h.jsx(On,{content:t,documentId:e,channel:r}):h.jsx(sl,{documentId:e,content:t});case"mcp_app":return h.jsx(rl,{content:t});case"file":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(nl,{documentId:e,content:t})});case"model3d":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(il,{content:t})});case"csv":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(ol,{content:t})});case"diff":return h.jsx(g.Suspense,{fallback:h.jsx(ht,{}),children:h.jsx(al,{documentId:e,content:t},t.sourcePath)})}}function ht(){return h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"})}function sl({documentId:e,content:r}){const{channel:t}=tl(e);return h.jsx(On,{documentId:e,content:r,channel:t})}const ll=g.lazy(()=>je(()=>import("./BlintzCanvas-CUqethk_.js"),__vite__mapDeps([0,1,2,3,4])).then(e=>({default:e.BlintzCanvas})));function Sl({roomId:e,document:r,content:t,onSave:n}){const[i,o]=g.useState(null),[a,s]=g.useState(!1),[l,c]=g.useState(null),u=i!==null,d=t.sourcePath===void 0;Di(e,u?r.id:null);const f=async()=>{if(i===null)return;if(i===t.content){o(null),c(null);return}s(!0),c(null);const p=await n(r.id,{...t,content:i});s(!1),p?o(null):c("Couldn’t save. Your words are still here. Try again.")};return h.jsxs("div",{className:"flex h-full flex-col",children:[d&&h.jsxs("div",{className:"flex items-center justify-end gap-2 border-b px-2 py-1",children:[u&&h.jsx("span",{className:"text-muted-foreground text-xs",children:a?"Saving…":"Everyone sees your save."}),h.jsx(mt,{type:"button",size:"xs",variant:"ghost",disabled:a,"aria-label":u?"Save for the room":"Edit this document",onClick:()=>u?void f():o(t.content),children:u?h.jsx(qr,{className:"size-3.5"}):h.jsx(Hr,{className:"size-3.5"})})]}),l!==null&&h.jsx("p",{role:"status",className:"text-destructive border-b px-2 py-1 text-xs",children:l}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(g.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"}),children:h.jsx(ll,{value:i??t.content,editable:u,onChange:o},u?"editing":`rev-${r.rev}`)})})]})}const Qt="dorkos-canvas-sessions",ul=1440*60*60*1e3;function Xn(){try{const e=localStorage.getItem(Qt);if(!e)return null;const r=JSON.parse(e);return r===null||typeof r!="object"?null:r}catch{return null}}function Wn(e){try{Object.keys(e).length===0?localStorage.removeItem(Qt):localStorage.setItem(Qt,JSON.stringify(e))}catch{}}function cl(e){return Array.isArray(e.documents)?[...e.documents].sort((r,t)=>(r.openedAt??0)-(t.openedAt??0)).map(r=>r.content).filter(r=>!!r):e.content?[e.content]:[]}function Ct(e){return e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(Ct).join(",")}]`:`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t<n?-1:t>n?1:0).map(([t,n])=>`${JSON.stringify(t)}:${Ct(n)}`).join(",")}}`}function dl(e,r){const t=new Set,n=new Map;for(const o of e){const a=Cr(o.content);if(a!==null){t.add(a);continue}const s=Ct(o.content);n.set(s,(n.get(s)??0)+1)}const i=[];for(const o of r){const a=Cr(o);if(a!==null){t.has(a)||i.push(o);continue}const s=Ct(o),l=n.get(s)??0;l>0?n.set(s,l-1):i.push(o)}return i}const vt=new Set;function kl(){vt.clear()}function Pl(e,r={}){const t=pe(),n=r.canonical??!0;g.useEffect(()=>{e&&K.getState().loadCanvasForSession(e)},[e]),g.useEffect(()=>{if(!e||!n||vt.has(e))return;const i=Xn();if(!i)return;const o=i[e];if(!o){fl(i);return}vt.add(e),(async()=>{try{const a=cl(o),s=dl(await t.listSessionCanvas(e),a);if(s.length===0){Fr(e);return}for(const l of s)await t.openSessionCanvasDocument(e,l);Fr(e),K.getState().hydrateCanvasFromSnapshot(e,await t.listSessionCanvas(e))}catch{vt.delete(e)}})()},[e,n,t])}function Fr(e){const r=Xn();if(!r)return;const{[e]:t,...n}=r;Wn(n)}function fl(e){const r=Date.now()-ul,t=Object.entries(e).filter(([,n])=>n.accessedAt===void 0||n.accessedAt>=r);t.length!==Object.keys(e).length&&Wn(Object.fromEntries(t))}export{Cl as C,wl as F,Sl as R,zi as a,xi as b,yl as c,On as d,kl as e,Ai as f,tl as g,Pl as h,Tn as r,ro as u};