dorkos 0.129.0 → 0.130.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.
- package/dist/bin/cli.js +694 -513
- package/dist/browser/native/package-manifest.json +1 -1
- package/dist/browser/source-manifest.json +1 -1
- package/dist/client/assets/{AboutPage-CML_SdU1.js → AboutPage-B2CzVj5W.js} +1 -1
- package/dist/client/assets/{ActivityErrorState-TuQRJopr.js → ActivityErrorState-Dl-P-e0R.js} +1 -1
- package/dist/client/assets/{ActivityPage-CmSxeVSK.js → ActivityPage-CW7tqLHb.js} +1 -1
- package/dist/client/assets/{ActivityRow-DJhDehIR.js → ActivityRow-Vy4aXWk-.js} +1 -1
- package/dist/client/assets/{AdapterIcon-CeRDpZGz.js → AdapterIcon-aabKVZmM.js} +1 -1
- package/dist/client/assets/{AdapterSetupWizard-B6KkTuJo.js → AdapterSetupWizard-C5Hs0xkG.js} +2 -2
- package/dist/client/assets/{AgentOptionRow-388OJkPc.js → AgentOptionRow-CqIMxq9S.js} +1 -1
- package/dist/client/assets/{AgentPicker-C51wqToQ.js → AgentPicker-C6mbTDJJ.js} +1 -1
- package/dist/client/assets/{AgentRequestCard-Bz31ewIs.js → AgentRequestCard-C8GV5Sxn.js} +3 -3
- package/dist/client/assets/{AppearancePage-DSVeowGb.js → AppearancePage-C0JKrHsO.js} +1 -1
- package/dist/client/assets/{ApplyToOverridesDialog-DRtcLrVY.js → ApplyToOverridesDialog-DWEi0MNt.js} +1 -1
- package/dist/client/assets/{AttentionSignalRow-CqKZyoxB.js → AttentionSignalRow-Cpu0lKYg.js} +1 -1
- package/dist/client/assets/{BaseTanStackRouterDevtoolsPanel-B-iktbLX-DA1jhqFy.js → BaseTanStackRouterDevtoolsPanel-B-iktbLX-_zVrHu5s.js} +1 -1
- package/dist/client/assets/{BindingDialog-D25PAed0.js → BindingDialog-4UeaJfUu.js} +1 -1
- package/dist/client/assets/BlintzCanvas-DCXIQZM_.js +1231 -0
- package/dist/client/assets/{CanvasCsvContent-ZWHWmb88.js → CanvasCsvContent-D-0TuvVs.js} +1 -1
- package/dist/client/assets/{CanvasFileContent-DR5pUgca.js → CanvasFileContent-DqSx7lz9.js} +2 -2
- package/dist/client/assets/{CanvasModel3dContent-OP1ZOMui.js → CanvasModel3dContent-zTx660yQ.js} +2 -2
- package/dist/client/assets/ChannelComposer-D4TYVkvO.js +45 -0
- package/dist/client/assets/{ChatAppsOff-ByitL4Xt.js → ChatAppsOff-BzfyQc55.js} +1 -1
- package/dist/client/assets/{CodeMirrorDiff-JsV_vWBa.js → CodeMirrorDiff-BLWBYGLp.js} +1 -1
- package/dist/client/assets/{CodeMirrorEditor-BfCJG9hQ.js → CodeMirrorEditor-D0q3ETxK.js} +1 -1
- package/dist/client/assets/{CommitmentList-yFV3_m00.js → CommitmentList-BoMiLsRe.js} +1 -1
- package/dist/client/assets/{CommitmentsPage-DeERVg-2.js → CommitmentsPage-_7mNJVUZ.js} +1 -1
- package/dist/client/assets/{ComputerResourceView-CYMMSE8Y.js → ComputerResourceView-Bo2LaCJf.js} +1 -1
- package/dist/client/assets/{ComputerViewer-H7kJSIj7.js → ComputerViewer-a4VSdAw_.js} +1 -1
- package/dist/client/assets/{ConnectionAccessLists-SRkf7-Y6.js → ConnectionAccessLists-Dvv0YO31.js} +1 -1
- package/dist/client/assets/{ConnectionsPage-D6e3hd4L.js → ConnectionsPage-oO8pNgbc.js} +2 -2
- package/dist/client/assets/{ConventionPage-CpvRMcSG.js → ConventionPage-CFJjwhBd.js} +2 -2
- package/dist/client/assets/{ExtensionPageRoute-CiFv6we8.js → ExtensionPageRoute-BqZN9q7M.js} +2 -2
- package/dist/client/assets/{FloatingTanStackRouterDevtools-CqogiFob-D-8CeYC7.js → FloatingTanStackRouterDevtools-CqogiFob-CnSp2ZEM.js} +1 -1
- package/dist/client/assets/{ForwardConsentHost-ml3b_fsX.js → ForwardConsentHost-4LhRvCdu.js} +1 -1
- package/dist/client/assets/HandlePage-BjoYPqme.js +1 -0
- package/dist/client/assets/{HeartbeatPage-C0zSvWH4.js → HeartbeatPage-rJzICayy.js} +1 -1
- package/dist/client/assets/{KeyEntry-Dq6eKAbX.js → KeyEntry-BTTuXleL.js} +1 -1
- package/dist/client/assets/{LexicalField-CYOqOLpV.js → LexicalField-Dk_SDrjk.js} +1 -1
- package/dist/client/assets/{ManagesPage-DZTMD3Al.js → ManagesPage-Cvu3CQDn.js} +1 -1
- package/dist/client/assets/{Marketplace-buSfuVrY.js → Marketplace-DPjPPlZz.js} +2 -2
- package/dist/client/assets/{MarketplaceSourcesView-BxwvBWgh.js → MarketplaceSourcesView-ChCys0on.js} +1 -1
- package/dist/client/assets/{McpAppFrame-CWiRFp8o.js → McpAppFrame-DNamtzOp.js} +2 -2
- package/dist/client/assets/{McpSigninBody-BpYSAV1h.js → McpSigninBody-DLw3ZdZE.js} +1 -1
- package/dist/client/assets/{Model3dViewer-B2KTvx6d.js → Model3dViewer-IwCBCPZ2.js} +1 -1
- package/dist/client/assets/NamePage-FY_D0eA2.js +1 -0
- package/dist/client/assets/NewDirectMessageMenu-BB0gvClR.js +1 -0
- package/dist/client/assets/{NotificationsPage-CWXIghVM.js → NotificationsPage-aCF0AtqL.js} +1 -1
- package/dist/client/assets/{OpenMeshSwitch-C9hiAEHP.js → OpenMeshSwitch-DjCWF2Vy.js} +2 -2
- package/dist/client/assets/{OperatorIdentityForm-CjmMoP6n.js → OperatorIdentityForm-Bcveds6f.js} +1 -1
- package/dist/client/assets/{PermissionHistory-D_Imuq02.js → PermissionHistory-CYsxFYmV.js} +1 -1
- package/dist/client/assets/{PermissionsPage-QMLV8PfB.js → PermissionsPage-sxHkY92V.js} +1 -1
- package/dist/client/assets/{PersonalityPopover-BL9DLK0Q.js → PersonalityPopover-BZ20JTnJ.js} +1 -1
- package/dist/client/assets/PhotoPage-KBzkb0sT.js +1 -0
- package/dist/client/assets/{PreviewRefusedNotice-Dt2hV0aJ.js → PreviewRefusedNotice-BFQPYcUG.js} +1 -1
- package/dist/client/assets/{ProfileFields-DD6X85w2.js → ProfileFields-sp17IFo8.js} +1 -1
- package/dist/client/assets/{ProfilePanelContainer-DuFEpNJ3.js → ProfilePanelContainer-mA44jh5A.js} +1 -1
- package/dist/client/assets/{ProfileRolePicker-CT9eJ1J0.js → ProfileRolePicker-Chh4_ZMB.js} +1 -1
- package/dist/client/assets/{PromptSuggestionChips-C8V611-5.js → PromptSuggestionChips-CEi_-fHF.js} +1 -1
- package/dist/client/assets/{ReportsToPopover-Bs55bP7b.js → ReportsToPopover-D1uknwnk.js} +1 -1
- package/dist/client/assets/RoomSurface-Clf1yLrr.js +1 -0
- package/dist/client/assets/{RoomsPage-CDiSwt-I.js → RoomsPage-BtCNzvhQ.js} +1 -1
- package/dist/client/assets/{RunsOnPopover-CFBDa9DO.js → RunsOnPopover-LCvBpe9J.js} +1 -1
- package/dist/client/assets/{RuntimeConnectFlow-DsawxJN7.js → RuntimeConnectFlow-C5UDeHUC.js} +1 -1
- package/dist/client/assets/{RuntimeSetupDialog-bdf844gx.js → RuntimeSetupDialog-Bqh67Vqb.js} +1 -1
- package/dist/client/assets/{SeenDevices-Cix5nnGQ.js → SeenDevices-DvCfdeDo.js} +3 -3
- package/dist/client/assets/{SessionsPage-CCu8rM-J.js → SessionsPage-DLByE-re.js} +1 -1
- package/dist/client/assets/{SettingsDialog-D7sVluoe.js → SettingsDialog-Co-Oxtyw.js} +3 -3
- package/dist/client/assets/{SkillsPage-SSq7ofgp.js → SkillsPage-Cc79IstM.js} +1 -1
- package/dist/client/assets/{TaskDialogWrapper-CBIuIbmj.js → TaskDialogWrapper-DuYV7Zch.js} +1 -1
- package/dist/client/assets/{TasksEmptyState-C0K_NOA3.js → TasksEmptyState-CfmPtBra.js} +2 -2
- package/dist/client/assets/{TasksPage-BpSn7GmR.js → TasksPage-DGk0zUhO.js} +1 -1
- package/dist/client/assets/{TeamComputerEntry-BAi9omUC.js → TeamComputerEntry-CLHbeX5i.js} +1 -1
- package/dist/client/assets/{ToolsPage-nkGWy6MR.js → ToolsPage-CSkDE7rZ.js} +2 -2
- package/dist/client/assets/{TopologyGraph-D6SSv0kC.js → TopologyGraph-pBC37k5P.js} +1 -1
- package/dist/client/assets/{TourHost-CrZciWIf.js → TourHost-CS9RsLj_.js} +1 -1
- package/dist/client/assets/{UnlinkDialog-B9zw8r6F.js → UnlinkDialog-CelhOUZ0.js} +1 -1
- package/dist/client/assets/{UnreadDivider-BnJ06LmP.js → UnreadDivider-B_OMR0mQ.js} +1 -1
- package/dist/client/assets/{WidgetErrorCard-CQKYI7oK.js → WidgetErrorCard-CsMqCyCb.js} +9 -9
- package/dist/client/assets/{WithheldExtensionsNotice-VMM5NjL5.js → WithheldExtensionsNotice-GiKb0iQu.js} +1 -1
- package/dist/client/assets/WorkQueuePage-Cu721KyM.js +1 -0
- package/dist/client/assets/{WorkView-D5d8DDxS.js → WorkView-CpWEaxMr.js} +1 -1
- package/dist/client/assets/_shell-CmGG8Ysk.js +80 -0
- package/dist/client/assets/{_shell._home-CcfELPIk.js → _shell._home-BnKkAeSp.js} +1 -1
- package/dist/client/assets/{_shell._home.activity-CGKsuLq8.js → _shell._home.activity-DaaLJbvO.js} +1 -1
- package/dist/client/assets/{_shell._home.index-DrJRgJCb.js → _shell._home.index-CNPasFxP.js} +2 -2
- package/dist/client/assets/_shell._home.tasks-DXEOJ5Nq.js +1 -0
- package/dist/client/assets/{_shell._home.workspaces-CjBJymCW.js → _shell._home.workspaces-UeSvmquR.js} +1 -1
- package/dist/client/assets/{_shell.channels-CzQFR6pU.js → _shell.channels-NUbf5mcb.js} +1 -1
- package/dist/client/assets/{_shell.connections-B5hafeep.js → _shell.connections-BEns4DKb.js} +1 -1
- package/dist/client/assets/{_shell.feedback-requests-DtD2bH-4.js → _shell.feedback-requests-NyjHNdnj.js} +2 -2
- package/dist/client/assets/_shell.marketplace-BEYqsDKe.js +1 -0
- package/dist/client/assets/_shell.marketplace_.sources-D6Ls30FY.js +1 -0
- package/dist/client/assets/_shell.session-CVc6i3eN.js +1 -0
- package/dist/client/assets/{_shell.team-BrGo-IxK.js → _shell.team-CXeOt4XD.js} +4 -4
- package/dist/client/assets/{_shell.threads-Ceq_tmNk.js → _shell.threads-BYdN1UtZ.js} +1 -1
- package/dist/client/assets/_shell.x._extensionId-DtJYSfvG.js +1 -0
- package/dist/client/assets/_shell.x._extensionId_._-DtJYSfvG.js +1 -0
- package/dist/client/assets/{abnfDiagram-WEYOIA3C-BN5bqwbu.js → abnfDiagram-WEYOIA3C-BLCVDt6M.js} +1 -1
- package/dist/client/assets/{access-copy-BAhTOOsG.js → access-copy-BSQ3QECN.js} +1 -1
- package/dist/client/assets/{arc-BfTE_VoF.js → arc-t4OhsI5R.js} +1 -1
- package/dist/client/assets/{architectureDiagram-ZHVYKT53-Dc6keeDz.js → architectureDiagram-ZHVYKT53-BcIfbGZR.js} +1 -1
- package/dist/client/assets/{banner-DOgGDCJ5.js → banner-B6xfuDA7.js} +1 -1
- package/dist/client/assets/{blockDiagram-RJAE7QA3-B4c6U-ob.js → blockDiagram-RJAE7QA3-DTOlrcEZ.js} +1 -1
- package/dist/client/assets/{c4Diagram-XDPPPE54-CCtD8QC8.js → c4Diagram-XDPPPE54-CHGqwaxa.js} +1 -1
- package/dist/client/assets/channel-CSk6LhO2.js +1 -0
- package/dist/client/assets/{chunk-2E7WHVMD-DcDNqIJG.js → chunk-2E7WHVMD-Bh4L_7yX.js} +1 -1
- package/dist/client/assets/{chunk-2Q5K7J3B-DOVVK0B8.js → chunk-2Q5K7J3B-BmouLl8r.js} +1 -1
- package/dist/client/assets/{chunk-4EMNKR2T-Cg-Do982.js → chunk-4EMNKR2T-BVhtiAdG.js} +1 -1
- package/dist/client/assets/{chunk-55XCU76K-CDmULSeY.js → chunk-55XCU76K-BdbLnE56.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-Bi0yIWW1.js → chunk-5VM5RSS4-Qg9lQpPO.js} +1 -1
- package/dist/client/assets/{chunk-JWPE2WC7-ZHaJh6CV.js → chunk-JWPE2WC7-CfIrQaMW.js} +1 -1
- package/dist/client/assets/{chunk-VQ5W62QI-DZi6GyW_.js → chunk-VQ5W62QI-BP9oQzc0.js} +1 -1
- package/dist/client/assets/{chunk-XXDRQBXY-D18oZOrd.js → chunk-XXDRQBXY-DKzIjnsB.js} +1 -1
- package/dist/client/assets/{chunk-ZCHMQSOR-BkZ0l0fE.js → chunk-ZCHMQSOR-DsvG6BGY.js} +2 -2
- package/dist/client/assets/{classDiagram-v2-4MYWR3UA-BfmK1buF.js → classDiagram-v2-4MYWR3UA-BSiSmGgP.js} +1 -1
- package/dist/client/assets/{command-CZqA020F.js → command-B_FPXirc.js} +1 -1
- package/dist/client/assets/{copy-button-ByA00JGh.js → copy-button-Bp75zBSh.js} +1 -1
- package/dist/client/assets/{cose-bilkent-JH36ORCC-B1NTVSbk.js → cose-bilkent-JH36ORCC-CXgyrZix.js} +1 -1
- package/dist/client/assets/{cpu-DNvpMmNN.js → cpu-DpkNIYeK.js} +1 -1
- package/dist/client/assets/{cynefin-EF2NZ3EQ-CB_HMIZ8.js → cynefin-EF2NZ3EQ-DkmPO3hK.js} +1 -1
- package/dist/client/assets/{cynefinDiagram-WF24UDRP-MmIWYdc2.js → cynefinDiagram-WF24UDRP-BDknJT17.js} +1 -1
- package/dist/client/assets/{dagre-NK4GIZVX-BQay0k4e.js → dagre-NK4GIZVX-BR4J5E3b.js} +1 -1
- package/dist/client/assets/{detail-row-290qyusq.js → detail-row-C8zz6mAC.js} +1 -1
- package/dist/client/assets/{diagram-CBK3MWTC-C1lRH4cb.js → diagram-CBK3MWTC-CvLKqPry.js} +1 -1
- package/dist/client/assets/{diagram-I5XIIV2D-CnANa27A.js → diagram-I5XIIV2D-CVtE60X9.js} +1 -1
- package/dist/client/assets/{diagram-ODIL2UCW-Cwt7hxes.js → diagram-ODIL2UCW-B--CpfLk.js} +1 -1
- package/dist/client/assets/{diagram-PFBEJUXE-DZtAER77.js → diagram-PFBEJUXE-08gch1t1.js} +1 -1
- package/dist/client/assets/{diagram-RJA3I4VV-CbVXbiGs.js → diagram-RJA3I4VV-C2e-ubaD.js} +1 -1
- package/dist/client/assets/{diagram-TYUNFSNR-D-AcGdsL.js → diagram-TYUNFSNR-DcpK4OXX.js} +1 -1
- package/dist/client/assets/{ebnfDiagram-V4P3TTPT-DLkrFSAy.js → ebnfDiagram-V4P3TTPT-DM44BkBt.js} +1 -1
- package/dist/client/assets/{elk-QONTBCTQ-DQM6Glxa.js → elk-QONTBCTQ-maYS1Zzm.js} +1 -1
- package/dist/client/assets/{empty-state-BnuM8oop.js → empty-state-HtOTBAoq.js} +1 -1
- package/dist/client/assets/{erDiagram-KYQIGQAA-C1qgB1Mn.js → erDiagram-KYQIGQAA-BR7z9r2M.js} +1 -1
- package/dist/client/assets/{execution-config-BjLHHc9x.js → execution-config-DYYeJyJh.js} +1 -1
- package/dist/client/assets/{file-D7_QdH_S.js → file-VtGYNr9E.js} +1 -1
- package/dist/client/assets/{file-exclamation-point-Cdt8YqyQ.js → file-exclamation-point-eBlQssyW.js} +1 -1
- package/dist/client/assets/{file-text-CB9l6Ur-.js → file-text-DvNAxTGZ.js} +1 -1
- package/dist/client/assets/{find-latest-widget-fence-SQB9WgjN.js → find-latest-widget-fence-C2qXvASs.js} +3 -3
- package/dist/client/assets/{flowDiagram-IUGLLWBU-DH-ePeFu.js → flowDiagram-IUGLLWBU-DiuMtMbj.js} +1 -1
- package/dist/client/assets/{form--HjBAzX8.js → form-CGIIzr1u.js} +1 -1
- package/dist/client/assets/{format-cron-svkfKW5b.js → format-cron-BzJ6ekoo.js} +1 -1
- package/dist/client/assets/{ganttDiagram-R7GPNTJY-fjb_iAW1.js → ganttDiagram-R7GPNTJY-Cf_z8Ri1.js} +1 -1
- package/dist/client/assets/{git-branch-CPOwiT8a.js → git-branch-BVzjBPW-.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PDYL7XHY-CcCqH5T3.js → gitGraphDiagram-PDYL7XHY-RZXACCBr.js} +1 -1
- package/dist/client/assets/{graph-DS3J2jnN.js → graph-DfAV_ObD.js} +1 -1
- package/dist/client/assets/{heart-C6uRnXx3.js → heart-BMOCYMFT.js} +1 -1
- package/dist/client/assets/{highlighted-body-KPVGNVTW-CNygKq0i.js → highlighted-body-KPVGNVTW-DrrsaKBc.js} +1 -1
- package/dist/client/assets/{image-lightbox-BQV3i0WJ.js → image-lightbox-tAwBNBhm.js} +1 -1
- package/dist/client/assets/{image-off-B88WBkcV.js → image-off-BpagBHk1.js} +1 -1
- package/dist/client/assets/{index-UJpgX--l.js → index-0uCJUW_h.js} +2 -2
- package/dist/client/assets/index-0y0K3rYv.js +1 -0
- package/dist/client/assets/{index-B_YZ5cyn.js → index-2GjydAcS.js} +1 -1
- package/dist/client/assets/{index-tRdq7FGO.js → index-6dsaPQ7-.js} +1 -1
- package/dist/client/assets/{index-DhqeMM58.js → index-7-yzdcAx.js} +3 -3
- package/dist/client/assets/{index-DXZ-w0Z9.js → index-A7HgzxSw.js} +1 -1
- package/dist/client/assets/{index-BTqJGL1_.js → index-BEqKTiCR.js} +1 -1
- package/dist/client/assets/{index-B_v2l2ND.js → index-BIN0yv4s.js} +1 -1
- package/dist/client/assets/{index-B6pmysqs.js → index-BL5Vmq62.js} +1 -1
- package/dist/client/assets/index-BOvFXsF_.js +1 -0
- package/dist/client/assets/{index-BtTqA4_d.js → index-BbcfxnHC.js} +1 -1
- package/dist/client/assets/{index-D0QV18E0.js → index-BdKIijqB.js} +1 -1
- package/dist/client/assets/{index-CZmU-67J.js → index-BfAymWoj.js} +1 -1
- package/dist/client/assets/{index-COXdXByr.js → index-Bgts5its.js} +1 -1
- package/dist/client/assets/{index-DYQjub9g.js → index-BiL3chP7.js} +1 -1
- package/dist/client/assets/{index-C7I0BjyX.js → index-Bu3PEVA_.js} +1 -1
- package/dist/client/assets/{index-BKdXHSbr.js → index-C6DTV4h3.js} +1 -1
- package/dist/client/assets/{index-DK8zHloW.js → index-CCH9c-nB.js} +1 -1
- package/dist/client/assets/{index-oc-yQ5Q4.js → index-CH4NJ8dD.js} +1 -1
- package/dist/client/assets/{index-BxsALYNM.js → index-CKGJp3Cm.js} +1 -1
- package/dist/client/assets/{index-BIZNH5u1.js → index-CeqI4FFw.js} +1 -1
- package/dist/client/assets/{index-Cbk19RQp.js → index-Cj9-XXKl.js} +1 -1
- package/dist/client/assets/{index-um-0KSur.js → index-Cu8tnfM_.js} +1 -1
- package/dist/client/assets/{index-B_rc9Pb1.js → index-D4OWRMsG.js} +1 -1
- package/dist/client/assets/{index-RQhQx8gq.js → index-D8SP73Xw.js} +1 -1
- package/dist/client/assets/{index-CEicS7Zi.js → index-DEJXVqcY.js} +1 -1
- package/dist/client/assets/{index-CTJA-mZu.js → index-DEMZynQt.js} +1 -1
- package/dist/client/assets/{index-5RD9flqf.js → index-DGzMwE1Z.js} +1 -1
- package/dist/client/assets/{index-CLTrC-a-.js → index-DIJdZqg2.js} +3 -3
- package/dist/client/assets/{index-Ds9wPt9M.js → index-DIRqrOEK.js} +1 -1
- package/dist/client/assets/{index-DBAPfYwE.js → index-DNbdGvs9.js} +1 -1
- package/dist/client/assets/{index-D5fV4hrl.js → index-DOBjxRe9.js} +1 -1
- package/dist/client/assets/{index-57qzL_5b.js → index-DcBlHsnC.js} +1 -1
- package/dist/client/assets/index-DdsaTuqO.js +1 -0
- package/dist/client/assets/{index-BN3zOTbR.js → index-Dt4H9Tms.js} +3 -3
- package/dist/client/assets/{index-BNq_mnok.js → index-HXC63Ry8.js} +1 -1
- package/dist/client/assets/index-MHIn2TC9.js +1063 -0
- package/dist/client/assets/{index-DdBvjuc4.js → index-OjJ_8uMM.js} +1 -1
- package/dist/client/assets/index-P4Wos1Gi.css +1 -0
- package/dist/client/assets/{index-Bktc0aFV.js → index-U5jTIqzv.js} +1 -1
- package/dist/client/assets/{index-CLVvKY2v.js → index-ZzPr9GUI.js} +1 -1
- package/dist/client/assets/{index-DO8NbOqk.js → index-d9cqTUAj.js} +1 -1
- package/dist/client/assets/{index-Cbbw2ByB.js → index-fcfCRITA.js} +1 -1
- package/dist/client/assets/{index-3CJSEcZE.js → index-onQlu3UR.js} +1 -1
- package/dist/client/assets/{index.esm-B10OaB6F.js → index.esm-DSKTDEoH.js} +1 -1
- package/dist/client/assets/{infoDiagram-MVDRKAX5-CGtvYWtj.js → infoDiagram-MVDRKAX5-B8dulOBe.js} +1 -1
- package/dist/client/assets/{inline-code-BL-6EKVP.js → inline-code-B3qpjdZ2.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-HPEHV2GE-ICsVVT2t.js → ishikawaDiagram-HPEHV2GE-Cy8aIg0O.js} +1 -1
- package/dist/client/assets/{journeyDiagram-BOSHW7O7-DEmSX2Hn.js → journeyDiagram-BOSHW7O7-BZAlejG3.js} +1 -1
- package/dist/client/assets/{kanban-definition-FNSA4HC5-SAV5PQOr.js → kanban-definition-FNSA4HC5-BxS1edpe.js} +1 -1
- package/dist/client/assets/{layers-Bfdpn7ZM.js → layers-ByCM7XO5.js} +1 -1
- package/dist/client/assets/{lightbulb-CSPTiZoi.js → lightbulb-KjW8YTXH.js} +1 -1
- package/dist/client/assets/{link-2-ZzmN9B9k.js → link-2-CtFfuMO5.js} +1 -1
- package/dist/client/assets/{list-runtime-types-7qV7HQ7K.js → list-runtime-types-DrzHejZo.js} +1 -1
- package/dist/client/assets/{markdown-content-CiDXslQf.js → markdown-content-DgiSdNwz.js} +1 -1
- package/dist/client/assets/mention-pill-CHPHlu-U.js +1 -0
- package/dist/client/assets/{mermaid.core-C-qvGQ5g.js → mermaid.core-ovqlC4PC.js} +4 -4
- package/dist/client/assets/{message-square-off-BehEHG9c.js → message-square-off-CEOyy4Pq.js} +1 -1
- package/dist/client/assets/{mindmap-definition-6OY57UG3-DzU2APoo.js → mindmap-definition-6OY57UG3-CsngqLzI.js} +1 -1
- package/dist/client/assets/{more-details-DF2dJXMV.js → more-details-BW9mauVT.js} +1 -1
- package/dist/client/assets/{owner-notice-DoH-_Veh.js → owner-notice-BRUVafHC.js} +1 -1
- package/dist/client/assets/{package-Fm_v1gMn.js → package-Bbs99yqi.js} +1 -1
- package/dist/client/assets/{page-container-Bcz5wJVR.js → page-container-BVfGgaaJ.js} +1 -1
- package/dist/client/assets/{pane-resize-handle-_EuIpxzc.js → pane-resize-handle-BL7Meu5R.js} +1 -1
- package/dist/client/assets/{paperclip-AGN67YEM.js → paperclip-QOWXs8-5.js} +1 -1
- package/dist/client/assets/{path-input-jrT0Ap4j.js → path-input-BDRHmgzW.js} +1 -1
- package/dist/client/assets/{pegDiagram-ECIUJNBX-CAyGJ7fm.js → pegDiagram-ECIUJNBX-DPsWmWqw.js} +1 -1
- package/dist/client/assets/{pieDiagram-GNMPY74T-tmLJe1p-.js → pieDiagram-GNMPY74T-BdOIDv4F.js} +1 -1
- package/dist/client/assets/{plug-C-4o4Kb8.js → plug-BrsPyUhu.js} +1 -1
- package/dist/client/assets/primer-trigger-C97fRm1v.js +3 -0
- package/dist/client/assets/{profile-errors-vJU1kT3U.js → profile-errors-nPLX60ha.js} +1 -1
- package/dist/client/assets/{progress-BTu_QWg8.js → progress-C9TALtIa.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-D57K4MC3-CUr2zJoz.js → quadrantDiagram-D57K4MC3-MzMEunU7.js} +1 -1
- package/dist/client/assets/{query-error-state-BCX32dab.js → query-error-state-BJjgx-WC.js} +1 -1
- package/dist/client/assets/{radio-DBitPjM1.js → radio-Biql29-B.js} +1 -1
- package/dist/client/assets/{railroadDiagram-Y72NRBL7-Bk9OMEWz.js → railroadDiagram-Y72NRBL7-Dzx_PYVW.js} +1 -1
- package/dist/client/assets/registry-B0HgbN69.js +1 -0
- package/dist/client/assets/registry-fiUD5cv6.js +39 -0
- package/dist/client/assets/{relay-trace-schemas-C-1Js81V.js → relay-trace-schemas-BJ4MfChd.js} +2 -2
- package/dist/client/assets/{repeat-B1wCYWXI.js → repeat-CKufDGoQ.js} +1 -1
- package/dist/client/assets/{requirementDiagram-EQYSW5RA-B2pkljrw.js → requirementDiagram-EQYSW5RA-J0pg6FEt.js} +1 -1
- package/dist/client/assets/{room-files-source-BDkq0-fd.js → room-files-source-iaYdshKo.js} +2 -2
- package/dist/client/assets/{rotate-ccw-clock-Ds8cHkxD.js → rotate-ccw-clock-CnARSw5V.js} +1 -1
- package/dist/client/assets/{rotate-cw-hUzouNTK.js → rotate-cw-BAn_5-Gq.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-SY24JHO5-DEW9eIPS.js → sankeyDiagram-SY24JHO5-6V_uy-zQ.js} +1 -1
- package/dist/client/assets/{scroll-area-RSd8NjrE.js → scroll-area-XDq7yL_d.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-BLEHNHQU-CoiCdD1D.js → sequenceDiagram-BLEHNHQU-C4jZi3N4.js} +1 -1
- package/dist/client/assets/{shield-x-KL4ZbHfz.js → shield-x-CpiXuMbN.js} +1 -1
- package/dist/client/assets/{signed-in-Dzxe2378.js → signed-in-Rv3Sjk8n.js} +1 -1
- package/dist/client/assets/{sizeCapture-INFHLROL-BWGf0Ghs.js → sizeCapture-INFHLROL-B7nxFreb.js} +1 -1
- package/dist/client/assets/{soul-file-BQXbWArv.js → soul-file-BQz4TtHo.js} +1 -1
- package/dist/client/assets/{stateDiagram-v2-A6IESKWZ-aeqwGZMB.js → stateDiagram-v2-A6IESKWZ-B5rvc4n2.js} +1 -1
- package/dist/client/assets/{swimlanes-B3ENRKFQ-BkWhAAlV.js → swimlanes-B3ENRKFQ-DnElusDo.js} +1 -1
- package/dist/client/assets/swimlanesDiagram-AYQRV4AK-DLpKz5fF.js +8 -0
- package/dist/client/assets/{table-CfLst6CF.js → table-NGiWzPO4.js} +1 -1
- package/dist/client/assets/{timeline-definition-JXYKGLGB-C1BUxIfq.js → timeline-definition-JXYKGLGB-DMgyn3XX.js} +1 -1
- package/dist/client/assets/{trust-posture-CfEIPM4Z.js → trust-posture-BArJ9H4j.js} +1 -1
- package/dist/client/assets/{unplug-B3eDst8L.js → unplug-MSjeZ0tJ.js} +1 -1
- package/dist/client/assets/{unverified-catalog-notice-BqIWxQuN.js → unverified-catalog-notice-DA96H8Df.js} +1 -1
- package/dist/client/assets/{use-bindings-DhOKnybh.js → use-bindings-BojBqRJS.js} +1 -1
- package/dist/client/assets/{use-composer-prefs-_rlNL0D8.js → use-composer-prefs-BDl8aMme.js} +1 -1
- package/dist/client/assets/{use-connector-management-CHLdhBhC.js → use-connector-management-FONU6FK8.js} +1 -1
- package/dist/client/assets/{use-deep-link-scroll-BVkszEn2.js → use-deep-link-scroll-CtbBPBgi.js} +1 -1
- package/dist/client/assets/{use-delete-binding-BET7vH2R.js → use-delete-binding-COhBv6X3.js} +1 -1
- package/dist/client/assets/{use-dev-links-BjLPuSUC.js → use-dev-links-Dh0MCiGY.js} +1 -1
- package/dist/client/assets/{use-direct-message-panel-ClXVf94w.js → use-direct-message-panel-CYnWunqk.js} +1 -1
- package/dist/client/assets/{use-external-adapter-catalog-D1INoacX.js → use-external-adapter-catalog-RTDOW8Yi.js} +1 -1
- package/dist/client/assets/{use-filter-state-BRlb3qG3.js → use-filter-state-CSFTDx7z.js} +1 -1
- package/dist/client/assets/{use-full-activity-feed-GWBg-_1B.js → use-full-activity-feed-DlY_ZbRZ.js} +1 -1
- package/dist/client/assets/use-is-below-desktop-ClzGXlRb.js +1 -0
- package/dist/client/assets/{use-local-browser-C-V2n_wd.js → use-local-browser-WwZd-FOP.js} +1 -1
- package/dist/client/assets/{use-mesh-topology-BzSFyR_s.js → use-mesh-topology-WnFkjq41.js} +1 -1
- package/dist/client/assets/{use-mounted-ref-1T3JbkY1.js → use-mounted-ref-Dz1h70pz.js} +1 -1
- package/dist/client/assets/{use-notification-prefs-qcYeVmLQ.js → use-notification-prefs-IrF5_cko.js} +1 -1
- package/dist/client/assets/use-pending-read-CnAnzOt_.js +1 -0
- package/dist/client/assets/{use-personality-commit-CJb-rqmM.js → use-personality-commit-C4hYkSPy.js} +1 -1
- package/dist/client/assets/use-promo-activation-CPVANFBh.js +6 -0
- package/dist/client/assets/{use-promo-dismissals-C6bPU5Rm.js → use-promo-dismissals-B9m0HT6L.js} +1 -1
- package/dist/client/assets/{use-pulse-freshness-Y11Ibit1.js → use-pulse-freshness-DMySxN8D.js} +1 -1
- package/dist/client/assets/{use-room-follow-claim-Di-yvoJD.js → use-room-follow-claim-ByaYVY0o.js} +1 -1
- package/dist/client/assets/{use-room-sessions-CPDRbQAW.js → use-room-sessions-DPB29acU.js} +1 -1
- package/dist/client/assets/{use-roving-tab-list-DK0OzOUz.js → use-roving-tab-list-BO8kbs-w.js} +1 -1
- package/dist/client/assets/{use-session-canvas-DA2i9Mdm.js → use-session-canvas-Cunag2K7.js} +9 -9
- package/dist/client/assets/{use-status-budget-jMg_w0rF.js → use-status-budget-jt-9aQR0.js} +2 -2
- package/dist/client/assets/{use-transform-BX3r518L.js → use-transform-ydtuYUNp.js} +1 -1
- package/dist/client/assets/{use-unclaimed-chats-B0nk8b84.js → use-unclaimed-chats-ClBWJgNm.js} +1 -1
- package/dist/client/assets/use-update-config-ZHtOtve0.js +1 -0
- package/dist/client/assets/{useMutationState-Rlga1GBT.js → useMutationState-B8ArIqeH.js} +1 -1
- package/dist/client/assets/{usecaseDiagram-WPOLBNNX-mjIwRNL1.js → usecaseDiagram-WPOLBNNX-C5JdAkG9.js} +1 -1
- package/dist/client/assets/{vennDiagram-Q3Y3IDCW-BcDIpVa6.js → vennDiagram-Q3Y3IDCW-CqLCy7LU.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-IVAIDKWA-NFX31kox.js → wardleyDiagram-IVAIDKWA-C9FlHLTd.js} +1 -1
- package/dist/client/assets/{xychartDiagram-4URNHDU4-DZZY7dL1.js → xychartDiagram-4URNHDU4-BIm-RUWd.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/drizzle/20261101195529_work_queue.sql +38 -0
- package/dist/drizzle/20261101233656_dor3644_session_launched_by.sql +1 -0
- package/dist/drizzle/20261102041558_dor3070_marketplace_summary.sql +2 -0
- package/dist/drizzle/20261102051715_dor3440_clear_origin_holds.sql +10 -0
- package/dist/drizzle/20261102135442_agent_browser_profiles.sql +15 -0
- package/dist/drizzle/meta/20261101195529_snapshot.json +14363 -0
- package/dist/drizzle/meta/20261101233656_snapshot.json +14370 -0
- package/dist/drizzle/meta/20261102041558_snapshot.json +14384 -0
- package/dist/drizzle/meta/20261102051715_snapshot.json +14384 -0
- package/dist/drizzle/meta/20261102135442_snapshot.json +14483 -0
- package/dist/drizzle/meta/_journal.json +35 -0
- package/dist/server/extension-child.cjs +1147 -572
- package/dist/server/index.js +41788 -36880
- package/dist/server/index.js.map +2 -2
- package/package.json +3 -3
- package/dist/client/assets/BlintzCanvas-BgIQdpTx.js +0 -1231
- package/dist/client/assets/ChannelComposer-BJ0nNzQb.js +0 -45
- package/dist/client/assets/HandlePage-Bq5qdCfY.js +0 -1
- package/dist/client/assets/NamePage-_yT2RQvT.js +0 -1
- package/dist/client/assets/NewDirectMessageMenu-CMp4ppiH.js +0 -1
- package/dist/client/assets/PhotoPage-Djh4IZBF.js +0 -1
- package/dist/client/assets/RoomSurface-DXZ36tmU.js +0 -1
- package/dist/client/assets/_shell-CTKp94uQ.js +0 -80
- package/dist/client/assets/_shell._home.tasks-B_lv_-fX.js +0 -1
- package/dist/client/assets/_shell.marketplace-DUpaCb0r.js +0 -1
- package/dist/client/assets/_shell.marketplace_.sources-C3pA7zZW.js +0 -1
- package/dist/client/assets/_shell.session-DH_9f3AK.js +0 -1
- package/dist/client/assets/_shell.x._extensionId-DaXLhYNr.js +0 -1
- package/dist/client/assets/_shell.x._extensionId_._-DaXLhYNr.js +0 -1
- package/dist/client/assets/channel-CF9_Q7CV.js +0 -1
- package/dist/client/assets/index-3JL8A9YZ.css +0 -1
- package/dist/client/assets/index-BPp-rj-W.js +0 -1
- package/dist/client/assets/index-C4Uak2ha.js +0 -1
- package/dist/client/assets/index-Daoy3TZ8.js +0 -1
- package/dist/client/assets/index-YUtEyz7O.js +0 -1053
- package/dist/client/assets/mention-pill-CuSUdpn7.js +0 -1
- package/dist/client/assets/primer-trigger-CmE4Ib-X.js +0 -3
- package/dist/client/assets/registry-DVPRVi8T.js +0 -34
- package/dist/client/assets/registry-DiFfRDdW.js +0 -1
- package/dist/client/assets/swimlanesDiagram-AYQRV4AK-CS2DMvLi.js +0 -8
- package/dist/client/assets/use-is-below-desktop-BjWA-tqP.js +0 -1
- package/dist/client/assets/use-pending-read-C1oA2H00.js +0 -1
- package/dist/client/assets/use-promo-activation-CAJItujg.js +0 -11
- package/dist/client/assets/use-update-config-Ce7sHmp2.js +0 -1
package/dist/client/assets/{use-session-canvas-DA2i9Mdm.js → use-session-canvas-Cunag2K7.js}
RENAMED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-
|
|
2
|
-
var
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-DCXIQZM_.js","assets/index-MHIn2TC9.js","assets/index-P4Wos1Gi.css","assets/index-U5jTIqzv.js","assets/index-DIJdZqg2.js","assets/BlintzCanvas-DCXOV_yN.css","assets/CanvasFileContent-DqSx7lz9.js","assets/rotate-cw-BAn_5-Gq.js","assets/query-keys-DeYqUDia.js","assets/index.esm-DSKTDEoH.js","assets/WidgetErrorCard-CsMqCyCb.js","assets/index-DEMZynQt.js","assets/progress-C9TALtIa.js","assets/markdown-content-DgiSdNwz.js","assets/table-NGiWzPO4.js","assets/package-Bbs99yqi.js","assets/heart-BMOCYMFT.js","assets/git-branch-BVzjBPW-.js","assets/file-text-DvNAxTGZ.js","assets/file-VtGYNr9E.js","assets/McpAppFrame-DNamtzOp.js","assets/more-details-BW9mauVT.js","assets/CanvasModel3dContent-zTx660yQ.js","assets/CanvasCsvContent-D-0TuvVs.js","assets/index-BiL3chP7.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var an=Object.defineProperty;var tr=e=>{throw TypeError(e)};var cn=(e,t,r)=>t in e?an(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var $=(e,t,r)=>cn(e,typeof t!="symbol"?t+"":t,r),wt=(e,t,r)=>t.has(e)||tr("Cannot "+r);var Pe=(e,t,r)=>(wt(e,t,"read from private field"),r?r.call(e):t.get(e)),Be=(e,t,r)=>t.has(e)?tr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),be=(e,t,r,n)=>(wt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),ye=(e,t,r)=>(wt(e,t,"access private method"),r);import{O as gt,a5 as ae,a6 as un,a7 as ln,r as p,lh as vt,dp as K,fU as te,dt as St,dr as $e,dq as le,op as dn,oq as fn,or as hn,a_ as _e,cl as Pt,e1 as pn,aZ as Y,os as mn,dn as rr,ot as Er,ou as ct,ov as gn,o8 as Qe,ow as Bt,o0 as vn,ds as ut,hc as Q,ox as bn,oy as yn,j as h,oz as wn,kk as xn,id as kn,ie as Cn,ez as jn,G as Ut,I as Rn,fI as En,cs as On,oA as Sn,jB as _n,jF as Dn,dL as In,oB as Nn,oC as An,oD as Tn,B as it,J as Or,gj as Sr,C as Mn,aO as Fn,oE as nr}from"./index-MHIn2TC9.js";import{R as zn}from"./rotate-cw-BAn_5-Gq.js";import{d as _t}from"./query-keys-DeYqUDia.js";import{T as qn,a as Ln,u as Pn}from"./index.esm-DSKTDEoH.js";import{v as Bn,a as Un,W as Wn}from"./WidgetErrorCard-CsMqCyCb.js";import{M as $n}from"./McpAppFrame-DNamtzOp.js";/**
|
|
3
3
|
* @license lucide-react v1.48.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
6
6
|
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const
|
|
7
|
+
*/const _r={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};_r.node;const Yo=gt(_r);/**
|
|
8
8
|
* @license lucide-react v1.48.0 - ISC
|
|
9
9
|
*
|
|
10
10
|
* This source code is licensed under the ISC license.
|
|
11
11
|
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/const
|
|
12
|
+
*/const Dr={name:"maximize",size:24,node:[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]};Dr.node;const Hn=gt(Dr);/**
|
|
13
13
|
* @license lucide-react v1.48.0 - ISC
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the ISC license.
|
|
16
16
|
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const
|
|
17
|
+
*/const Ir={name:"zoom-in",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:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]};Ir.node;const Gn=gt(Ir);/**
|
|
18
18
|
* @license lucide-react v1.48.0 - ISC
|
|
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
|
|
22
|
+
*/const Nr={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"}]]};Nr.node;const Vn=gt(Nr);function Jn(e,t){const r=ae();return un({queryKey:_t.index(e??""),queryFn:()=>r.getDocIndex(e),enabled:t&&e!==null,refetchOnWindowFocus:!0})}function Zn(){const e=ln();return p.useCallback(t=>{e.invalidateQueries({queryKey:t?_t.index(t):_t.all})},[e])}const Ie={pending:64,queueBytes:1048576,batchMs:300,frames:62,imageChars:9e5,imageEdge:1568,resourceErrors:1e4},lt=le().min(1).max(128),Fe={bridgeGeneration:lt},Xn=K({...Fe,__dorkosDevtools:te("capture-result"),requestId:lt,dataUrl:le().max(9e5).optional(),error:le().max(2048).optional()}),Yn=dn.omit({hostOutcome:!0}).extend({...Fe,__dorkosDevtools:te("act-result"),dataUrl:le().max(9e5).optional()}),Qn=fn.extend({status:$e().int().min(0).max(599),durationMs:$e().min(0),responseSize:$e().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),timestamp:$e().min(0)}),Kn=hn.refine(e=>e.timestamp>=0),es=vt("__dorkosDevtools",[K({__dorkosDevtools:te("hello"),pageInstanceId:lt,bridgeVersion:te(2)}),K({...Fe,__dorkosDevtools:te("ready"),pageInstanceId:lt}),K({...Fe,__dorkosDevtools:te("navigated")}),K({...Fe,__dorkosDevtools:te("resource-error")}),K({...Fe,__dorkosDevtools:te("batch"),seq:$e().int().min(0).max(Number.MAX_SAFE_INTEGER),console:St(Kn).max(500),network:St(Qn).max(200)}),Xn,Yn]);function ts(e){const t=new Set;let r=0,n=0;const s=c=>(n+=c)<=16384;function i(c){if(!s(2))return!1;for(let o=0;o<c.length;o++){const u=c.charCodeAt(o);if(u>=55296&&u<=56319&&o+1<c.length&&c.charCodeAt(o+1)>=56320&&c.charCodeAt(o+1)<=57343){if(!s(2))return!1;o++;continue}const d=u===34||u===92||[8,9,10,12,13].includes(u)?2:u<32||u>=55296&&u<=57343?6:1;if(!s(d))return!1}return!0}function a(c,o){if(++r>2048||o>8)return!1;if(c===null)return s(4);if(typeof c=="boolean")return s(c?4:5);if(typeof c=="string")return i(c);if(typeof c=="number")return Number.isFinite(c)&&s(String(c).length);if(typeof c!="object"||t.has(c))return!1;const u=Object.getPrototypeOf(c);if(u!==Object.prototype&&u!==null&&u!==Array.prototype)return!1;const d=Array.isArray(c);if(d&&c.length>2048||Object.getOwnPropertySymbols(c).length||!s(2))return!1;t.add(c);let f=0;for(const l in c){if(!Object.prototype.hasOwnProperty.call(c,l))continue;if(++f>2048||d&&(!/^\d+$/.test(l)||Number(l)>=c.length))return!1;const g=Object.getOwnPropertyDescriptor(c,l);if(["__proto__","constructor","prototype"].includes(l)||!("value"in g)||!g.enumerable||f>1&&!s(1)||!d&&(!i(l)||!s(1))||!a(g.value,o+1))return!1}return t.delete(c),!d||f===c.length}try{return a(e,0)}catch{return!1}}function rs(e){try{if(!e||typeof e!="object")return null;const t=e;if(t.__dorkosDevtools==="capture-result"&&t.dataUrl===void 0&&t.error===void 0)return null;if(t.__dorkosDevtools==="batch"){if(!Array.isArray(t.console)||t.console.length>500||!Array.isArray(t.network)||t.network.length>200)return null;for(const s of t.console){if(!s||typeof s!="object")return null;const i=s.args;if(i!==void 0&&(!Array.isArray(i)||i.length>50||!ts(i)))return null}}const r=es.safeParse(e);if(!r.success)return null;const n=r.data;return"dataUrl"in n&&n.dataUrl!==void 0&&!Ar(n.dataUrl)?null:n}catch{return null}}function Ar(e){if(e.length>9e5||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(e))return null;try{const t=atob(e.slice(e.indexOf(",")+1));if(t.length<24||t.slice(0,8)!==`PNG\r
|
|
23
23
|
|
|
24
|
-
`||t.slice(12,16)!=="IHDR")return null;const r=i=>t.charCodeAt(i)*2**24+(t.charCodeAt(i+1)<<16)+(t.charCodeAt(i+2)<<8)+t.charCodeAt(i+3),n=r(16),s=r(20);return n>0&&s>0&&n<=1568&&s<=1568?{width:n,height:s}:null}catch{return null}}let xt=null;async function nr(){return xt===null&&(xt=(await _e(()=>import("./html-to-image-cl8bZGTj.js"),[])).default),xt}let kt=null;async function rs(){if(kt===null){const e=await _e(()=>import("./gifenc.esm-sOOlYEo8.js"),[]);kt={GIFEncoder:e.GIFEncoder,quantize:e.quantize,applyPalette:e.applyPalette}}return kt}async function sr(e,t,r=()=>{}){if(e.length===0)return{ok:!1,error:"The recording has no frames in it."};r();const{GIFEncoder:n,quantize:s,applyPalette:i}=await rs();r();const a=e[0],c=e[e.length-1],o=new Uint8ClampedArray(a.data.length+c.data.length);o.set(a.data,0),o.set(c.data,a.data.length);const u=s(o,256),d=n();for(let l=0;l<e.length;l++){r();const g=e[l];if(d.writeFrame(i(g.data,u),g.width,g.height,{...l===0?{palette:u,repeat:0}:{},delay:t.frameMs}),d.bytesView().byteLength>t.maxBytes)return{ok:!1,error:`The recording came out bigger than ${Math.round(t.maxBytes/1024/1024)} MB, so it was not saved.`}}d.finish();const f=d.bytes();return f.byteLength>t.maxBytes?{ok:!1,error:`The recording came out bigger than ${Math.round(t.maxBytes/1024/1024)} MB, so it was not saved.`}:{ok:!0,bytes:f}}async function ns(e,t,r=()=>{}){const n=[],s=document.createElement("canvas");let i=0,a=0;try{for(let c=0;c<Math.min(e.length,62);c++){r();const o=e[c];if(!Nr(o)){e[c]="";continue}const u=await is(o);e[c]="";try{if(r(),!u)continue;if(!i){const l=Math.min(1,Math.min(800,t)/Math.max(u.width,u.height,1));i=Math.max(1,Math.round(u.width*l)),a=Math.max(1,Math.round(u.height*l)),s.width=i,s.height=a}const d=s.getContext("2d",{willReadFrequently:!0});if(!d)return[];d.fillStyle="#ffffff",d.fillRect(0,0,i,a);const f=Math.min(i/u.width,a/u.height);d.drawImage(u,0,0,Math.round(u.width*f),Math.round(u.height*f)),r(),n.push({data:d.getImageData(0,0,i,a).data,width:i,height:a})}finally{u&&(u.src="")}}return n}catch(c){throw n.length=0,c}finally{e.length=0,s.width=0,s.height=0}}function ss(e,t=()=>{}){const r=document.createElement("canvas"),n=document.createElement("canvas");try{for(let s=0;s<e.length;s++){t();const i=e[s];n.width=i.width,n.height=i.height,r.width=Math.max(1,Math.round(i.width/2)),r.height=Math.max(1,Math.round(i.height/2));const a=n.getContext("2d"),c=r.getContext("2d",{willReadFrequently:!0});if(!a||!c)throw new Error("Canvas pixels are unavailable");a.putImageData(new ImageData(new Uint8ClampedArray(i.data),i.width,i.height),0,0),c.drawImage(n,0,0,r.width,r.height),e[s]={data:c.getImageData(0,0,r.width,r.height).data,width:r.width,height:r.height}}}finally{n.width=n.height=r.width=r.height=0}}function is(e){return new Promise(t=>{const r=new Image;r.onload=()=>{r.onload=r.onerror=null,t(r)},r.onerror=()=>{r.onload=r.onerror=null,r.src="",t(null)},r.src=e})}function ir(e,t,r){const n=r.slice().buffer;return{name:e,type:t,size:r.byteLength,arrayBuffer:async()=>n}}function os(e){const t=atob(e.slice(e.indexOf(",")+1));return Uint8Array.from(t,r=>r.charCodeAt(0))}const as=8e3;function cs(e){const t=ae(),r=p.useRef(t);p.useLayoutEffect(()=>{r.current=t});const[n]=Lt(),[s,i]=p.useState(0),a=p.useRef(null),c=p.useRef(new Map),o=p.useRef(null),u=p.useRef({console:[],network:[],entryBytes:0,overheadBytes:0}),d=p.useRef(null),f=p.useRef(-1),l=p.useRef(null),g=p.useRef(null),b=p.useRef(!1),m=p.useRef(-1/0),v=p.useRef(!1),N=p.useRef(null),T=p.useRef(0),R=p.useRef(null),z=p.useRef(null),L=p.useRef(!1),B=p.useRef(null),H=p.useRef({...e,sessionId:n}),x=p.useRef(Promise.resolve()),I=p.useRef(()=>{}),M=p.useRef({initialize:k,retire:O,consume:se,register:U,eligiblePending:Z,refuseRequest:C,live:w,captureFrame:yt,valid:fe,reportRecordingStart:je,cancelReservation:Re,finish:Gt});p.useLayoutEffect(()=>{M.current={initialize:k,retire:O,consume:se,register:U,eligiblePending:Z,refuseRequest:C,live:w,captureFrame:yt,valid:fe,reportRecordingStart:je,cancelReservation:Re,finish:Gt}});const W=S=>B.current===S||Y.getState().openDocuments.some(y=>y.id===S&&y.openedHere);function j(S,{active:y,activation:_=!1,keepalive:E=!1,reset:F=!1}){if(!S.sessionId)return;const re={documentId:S.documentId,logicalUrl:S.logicalUrl,bridgeGeneration:S.generation,seq:Math.max(0,f.current),console:[],network:[],active:y,activation:_,instrumented:S.ready&&!S.retired,...F?{reset:!0}:{}};x.current=x.current.then(()=>r.current.ingestDevtoolsCapture(S.sessionId,re,E?{keepalive:!0}:void 0)).catch(()=>{})}function O(){var _;const S=a.current;S&&(S.retired=!0),a.current=null,d.current!==null&&clearTimeout(d.current),d.current=null,o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0},f.current=-1,m.current=-1/0,v.current=!1;for(const[E,F]of c.current)F.life.sessionId&&F.deadline>Date.now()&&F.kind!=="frame"&&C(E,F.kind,F.life,"The frame changed while this request was pending."),clearTimeout(F.timer),(_=F.resolve)==null||_.call(F,null);c.current.clear(),S&&j(S,{active:!1});const y=N.current;y&&(clearTimeout(y.reservationTimer),y.cancelled=!0,y.abort.abort(),y.frames.length=0,y.finishing||(y.drawn.length=0,N.current=null)),R.current!==null&&cancelAnimationFrame(R.current),R.current=null,T.current=0,i(0)}function k({loadActivation:S,reset:y=!1}={}){var J,oe;const _=H.current,E=(J=_.iframeRef.current)==null?void 0:J.contentWindow;if(b.current||!E||!_.bridgeEligibility||!_.resolvedSource)return;const F={generation:crypto.randomUUID(),frame:E,sessionId:_.sessionId,documentId:_.documentId,logicalUrl:_.logicalUrl,source:_.resolvedSource,origin:_.bridgeEligibility==="served-document"?"null":_.previewOrigin,ready:!1,activation:!1,retired:!1};a.current=F;const re=S??(L.current||z.current!==F.documentId&&W(F.documentId));F.activation=re,L.current=!1,z.current=F.documentId,j(F,{active:!0,activation:re,reset:y}),((oe=l.current)==null?void 0:oe.frame)===E&&l.current.source===_.resolvedSource&&l.current.reload===_.reloadNonce&&l.current.documentId===_.documentId&&l.current.logicalUrl===_.logicalUrl&&E.postMessage({__dorkosDevtools:"init",bridgeGeneration:F.generation},"*")}p.useLayoutEffect(()=>{var E;H.current={...e,sessionId:n};const S={frame:(E=e.iframeRef.current)==null?void 0:E.contentWindow,sessionId:n,documentId:e.documentId,logicalUrl:e.logicalUrl,source:e.resolvedSource,eligibility:e.bridgeEligibility,origin:e.previewOrigin,reload:e.reloadNonce},y=g.current;if(!y||Object.keys(S).some(F=>S[F]!==y[F])){const F=!y||y.frame!==S.frame||y.documentId!==S.documentId||y.logicalUrl!==S.logicalUrl||y.source!==S.source||y.reload!==S.reload;g.current=S,b.current=!1,O(),k({reset:F})}});const A=p.useCallback(()=>{var re,J,oe;const{initialize:S,retire:y}=M.current,_=H.current,E=(re=_.iframeRef.current)==null?void 0:re.contentWindow,F=(J=a.current)!=null&&J.ready?!1:(oe=a.current)==null?void 0:oe.activation;E&&_.resolvedSource&&(l.current={frame:E,source:_.resolvedSource,reload:_.reloadNonce,documentId:_.documentId,logicalUrl:_.logicalUrl}),b.current=!1,y(),S({loadActivation:F,reset:!0})},[]),q=p.useCallback(()=>{const S=a.current;L.current=!0,B.current=H.current.documentId,S&&I.current({active:!0,activation:!0})},[]);p.useLayoutEffect(()=>{I.current=S=>{a.current&&j(a.current,S)}});function w(S){return a.current===S&&!S.retired}function C(S,y,_,E){if(!_.sessionId)return;const F={requestId:S,bridgeGeneration:_.generation,documentId:_.documentId,hostOutcome:"host",error:E};y==="action"?r.current.postDevtoolsAction(_.sessionId,{...F,ok:!1}).catch(()=>{}):r.current.ingestDevtoolsCapture(_.sessionId,{...F,logicalUrl:_.logicalUrl,seq:Math.max(0,f.current),console:[],network:[],screenshot:{requestId:S,error:E}}).catch(()=>{})}function U(S,y,_,{capture:E=!1,resolve:F,timeoutMs:re=8e3}={}){if(c.current.size>=Ie.pending||c.current.has(S))return null;const J=setTimeout(()=>G(S,oe),re),oe={kind:y,life:_,capture:E,deadline:Date.now()+re,timer:J,resolve:F};return c.current.set(S,oe),oe}function G(S,y){var _;c.current.get(S)===y&&(c.current.delete(S),clearTimeout(y.timer),(_=y.resolve)==null||_.call(y,null))}function Z(S,y,_){return c.current.get(S)!==y||y.life!==_||!w(_)?!1:Date.now()>=y.deadline?(G(S,y),!1):!0}function se(S,y,_){const E=c.current.get(S);return!E||E.life!==_||E.kind!==y&&!(y==="capture"&&E.kind==="frame")||!Z(S,E,_)?null:(c.current.delete(S),clearTimeout(E.timer),E)}p.useEffect(()=>{const{initialize:S,retire:y,consume:_}=M.current;function E(){d.current=null;const he=o.current;o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0};const D=a.current;he&&D&&!D.retired&&D.sessionId&&he.bridgeGeneration===D.generation&&r.current.ingestDevtoolsCapture(D.sessionId,he)}function F(he){var Jt,Zt,Xt,Yt;const D=a.current;if(!D||D.retired||he.source!==D.frame||he.origin!==D.origin||((Jt=l.current)==null?void 0:Jt.frame)!==D.frame||l.current.source!==D.source||l.current.reload!==H.current.reloadNonce||l.current.documentId!==D.documentId||l.current.logicalUrl!==D.logicalUrl)return;const P=he.data;if(!P||typeof P!="object"||typeof P.__dorkosDevtools!="string"||!["hello","ready","navigated","resource-error","batch","capture-result","act-result"].includes(P.__dorkosDevtools)||P.__dorkosDevtools!=="hello"&&P.bridgeGeneration!==D.generation)return;const ce=P.__dorkosDevtools==="batch";if(ce){if(!D.ready||!D.sessionId||P.bridgeGeneration!==D.generation||!Number.isSafeInteger(P.seq)||P.seq<0||P.seq<=f.current)return;const X=Date.now();if(X-m.current<Ie.batchMs){o.current?o.current.dropped=!0:v.current=!0;return}m.current=X}const V=ts(P);if(!V){ce&&(v.current=!0);return}if(V.__dorkosDevtools==="hello"){D.frame.postMessage({__dorkosDevtools:"init",bridgeGeneration:D.generation},"*");return}if(V.bridgeGeneration!==D.generation)return;if(V.__dorkosDevtools==="ready"){D.ready||(D.ready=!0,D.activation=!1,j(D,{active:!0}));return}if(!D.ready)return;if(V.__dorkosDevtools==="navigated"){b.current=!0,y();return}if(V.__dorkosDevtools==="resource-error"){T.current=Math.min(Ie.resourceErrors,T.current+1),R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null,w(D)&&i(T.current)}));return}if(!D.sessionId)return;if(V.__dorkosDevtools==="batch"){if(V.seq<=f.current)return;f.current=V.seq;const X=o.current??{documentId:D.documentId,logicalUrl:D.logicalUrl,bridgeGeneration:D.generation,seq:V.seq,console:[],network:[]};X.seq=V.seq,v.current&&(X.dropped=!0),v.current=!1;const Oe=u.current,Qt=new TextEncoder;if(o.current||(Oe.overheadBytes=Qt.encode(JSON.stringify({...X,seq:Number.MAX_SAFE_INTEGER,dropped:!0,console:[],network:[]})).length),Oe.overheadBytes>Ie.queueBytes){o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0},v.current=!0;return}for(const[Le,nn]of[["console",V.console],["network",V.network]])for(const sn of nn){const Kt=Qt.encode(JSON.stringify(sn)).length;Oe[Le].push(Kt),Oe.entryBytes+=Kt}X.console.push(...V.console),X.network.push(...V.network);const rn=()=>Oe.overheadBytes+Oe.entryBytes+Math.max(0,X.console.length-1)+Math.max(0,X.network.length-1);for(;X.console.length>500||X.network.length>200||rn()>Ie.queueBytes;){X.dropped=!0;const Le=(((Zt=X.console[0])==null?void 0:Zt.timestamp)??1/0)<=(((Xt=X.network[0])==null?void 0:Xt.timestamp)??1/0)?"console":"network";if(!X[Le].length)break;X[Le].shift(),Oe.entryBytes-=Oe[Le].shift()}o.current=X,d.current===null&&(d.current=setTimeout(E,Ie.batchMs));return}if(V.__dorkosDevtools==="capture-result"){const X=_(V.requestId,"capture",D);if(!X)return;if(X.kind==="frame"){(Yt=X.resolve)==null||Yt.call(X,V.dataUrl??null);return}r.current.ingestDevtoolsCapture(D.sessionId,{bridgeGeneration:D.generation,documentId:D.documentId,logicalUrl:D.logicalUrl,seq:Math.max(0,f.current),console:[],network:[],hostOutcome:"page-reported",screenshot:{requestId:V.requestId,dataUrl:V.dataUrl,error:V.error}});return}const qe=_(V.requestId,"action",D);if(!qe)return;const De=N.current,Vt=qe.capture&&V.dataUrl!==void 0&&De!==null&&De.life===D&&De.activated&&!De.finishing&&!De.cancelled&&De.frames.length<61;Vt&&De.frames.push(V.dataUrl);const{__dorkosDevtools:Lo,dataUrl:Po,...tn}=V;r.current.postDevtoolsAction(D.sessionId,{...tn,hostOutcome:"page-reported",documentId:D.documentId,captured:Vt||void 0})}window.addEventListener("message",F);const re=setInterval(()=>I.current({active:!0}),15e3),J=()=>{a.current||S(),I.current({active:!0,activation:!0})},oe=()=>{I.current({active:!1,keepalive:!0}),y()},ue=()=>{document.visibilityState==="visible"&&J()};return window.addEventListener("focus",J),window.addEventListener("pagehide",oe),window.addEventListener("pageshow",J),document.addEventListener("visibilitychange",ue),()=>{window.removeEventListener("message",F),clearInterval(re),window.removeEventListener("focus",J),window.removeEventListener("pagehide",oe),window.removeEventListener("pageshow",J),document.removeEventListener("visibilitychange",ue),y()}},[]),p.useEffect(()=>hn.subscribeSessionEvent((S,y)=>{if(y.type!=="devtools_capture_request"&&y.type!=="devtools_action_request"&&y.type!=="devtools_recording_request")return;const{register:_,eligiblePending:E,refuseRequest:F,captureFrame:re,valid:J,finish:oe,reportRecordingStart:ue,cancelReservation:he}=M.current,D=a.current;if(!(!(D!=null&&D.ready)||!D.sessionId||D.retired||y.targetClientId!==r.current.clientId||y.documentId!==D.documentId||y.bridgeGeneration!==D.generation)){if(y.type==="devtools_capture_request"||y.type==="devtools_action_request"){const P=y.type==="devtools_action_request",ce=_(y.requestId,P?"action":"capture",D,{capture:P&&!!y.capture,timeoutMs:P&&y.command.action==="wait_for"?Math.min(1e4,y.command.timeoutMs)+2e3:8e3});if(!ce){c.current.has(y.requestId)||F(y.requestId,P?"action":"capture",D,"Too many browser requests are waiting. Try again when one finishes.");return}const V=qe=>{E(y.requestId,ce,D)&&D.frame.postMessage(P?{__dorkosDevtools:"act-request",bridgeGeneration:D.generation,requestId:y.requestId,documentId:D.documentId,command:y.command,...y.capture?{capture:!0,lib:qe}:{}}:{__dorkosDevtools:"capture-request",bridgeGeneration:D.generation,requestId:y.requestId,lib:qe},"*")};!P||y.capture?nr().then(V,()=>V()):V()}if(y.type==="devtools_recording_request"){if(y.action==="cancel-start"){he(y.recordingId,y.requestId,D);return}if(y.action==="confirm-start"){const P=N.current;if(!P||P.id!==y.recordingId||P.startRequestId!==y.requestId||P.life!==D||P.finishing||!J(P))return;if(!P.activated){if(performance.now()>=P.reservationDeadline){he(P.id,P.startRequestId,D),ue(y,D,{phase:"started",ok:!1,error:"This recording reservation expired before capture could start."});return}clearTimeout(P.reservationTimer),P.activated=!0,P.startedAt=Date.now(),re(D).then(ce=>{ce&&J(P)&&P.frames.push(ce)})}ue(y,D,{phase:"started",ok:!0});return}if(y.action==="start"){const P=y.reservationTimeoutMs;if(!Number.isSafeInteger(P)||!P||P<1||P>as){ue(y,D,{phase:"reserved",ok:!1,error:"This recording request has no valid reservation timeout."});return}if(N.current){ue(y,D,{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 ce={id:y.recordingId,startRequestId:y.requestId,activated:!1,reservationDeadline:performance.now()+P,life:D,startedAt:Date.now(),frames:[],drawn:[],finishing:!1,cancelled:!1,abort:new AbortController};N.current=ce,ce.reservationTimer=setTimeout(()=>{N.current===ce&&!ce.activated&&he(ce.id,ce.startRequestId,D)},P),ue(y,D,{phase:"reserved",ok:!0})}else oe(y.requestId,y.recordingId,D)}}}),[]);function je(S,y,_){!w(y)||!y.sessionId||r.current.ingestDevtoolsCapture(y.sessionId,{hostOutcome:"host",documentId:y.documentId,bridgeGeneration:y.generation,seq:0,console:[],network:[],recordingStart:{..._,requestId:S.requestId,recordingId:S.recordingId}}).catch(()=>{})}function Re(S,y,_){var F;const E=N.current;if(!(!E||E.id!==S||E.startRequestId!==y||E.life!==_||E.finishing)){clearTimeout(E.reservationTimer),E.cancelled=!0,E.abort.abort(),E.frames.length=0,E.drawn.length=0;for(const[re,J]of c.current)J.life===_&&J.kind==="frame"&&(clearTimeout(J.timer),(F=J.resolve)==null||F.call(J,null),c.current.delete(re));N.current=null}}function fe(S){return N.current===S&&!S.cancelled&&w(S.life)}function yt(S){const y=`frame-${crypto.randomUUID()}`;return new Promise(_=>{const E=U(y,"frame",S,{resolve:_});if(!E){_(null);return}nr().then(F=>{Z(y,E,S)&&S.frame.postMessage({__dorkosDevtools:"capture-request",bridgeGeneration:S.generation,requestId:y,lib:F},"*")},()=>{G(y,E)})})}async function Gt(S,y,_){const E=N.current;if(!E||!E.activated||E.id!==y||E.life!==_){w(_)&&await r.current.uploadDevtoolsRecording(_.sessionId,{requestId:S,bridgeGeneration:_.generation,documentId:_.documentId,hostOutcome:"host",error:"The window showing that page stopped recording before it could be saved."}).catch(()=>{});return}if(E.finishing)return;E.finishing=!0;const F=()=>{if(!fe(E))throw new Error("retired")},re={requestId:S,bridgeGeneration:_.generation,documentId:_.documentId};try{const J=await yt(_);F(),J&&E.frames.length<Ie.frames&&E.frames.push(J);const oe=E.frames.length?os(E.frames[E.frames.length-1]):new Uint8Array;E.drawn=await ns(E.frames,800,F),F();let ue=await sr(E.drawn,{frameMs:500,maxBytes:8*1024*1024},F);if(F(),!ue.ok&&E.drawn.length&&(ss(E.drawn,F),ue=await sr(E.drawn,{frameMs:500,maxBytes:8*1024*1024},F),F()),!ue.ok){await r.current.uploadDevtoolsRecording(_.sessionId,{...re,hostOutcome:"host",error:ue.error},{signal:E.abort.signal}),F();return}F(),await r.current.uploadDevtoolsRecording(_.sessionId,{...re,frames:E.drawn.length,durationMs:Date.now()-E.startedAt,recording:ir(`${y}.gif`,"image/gif",ue.bytes),keyframe:ir(`${y}.png`,"image/png",oe)},{signal:E.abort.signal}),F()}catch{fe(E)&&await r.current.uploadDevtoolsRecording(_.sessionId,{...re,hostOutcome:"host",error:"This window could not turn that recording into a file."},{signal:E.abort.signal}).catch(()=>{})}finally{E.frames.length=0,E.drawn.length=0,N.current===E&&(N.current=null)}}return{resourceErrorCount:s,notePersonNavigated:q,noteFrameLoaded:A}}const ze=le().min(1).max(128),me={protocol:te("dorkos-doc"),v:te(1),nonce:ze,requestToken:ze,loadToken:ct,generation:Rr.shape.generation},us="dorkos-boot",or=vt("kind",[K({...me,kind:te("challenge")}).strict(),K({...me,kind:te("ack"),boot:ze.optional()}).strict(),K({...me,kind:te("connect")}).strict()]),ls=K({type:te("canvas_event"),docSeq:ct,event:mn}).strict(),ds=vt("kind",[K({...me,kind:te("emit"),requestId:ze,event:Qe}).strict(),K({...me,kind:te("retire")}).strict()]),fs=vt("kind",[K({...me,kind:te("receipt"),requestId:ze,receipt:Pt}).strict(),K({...me,kind:te("refused"),requestId:ze,outcome:tr(["cancelled","unconfirmed","refused"])}).strict(),K({...me,kind:te("state"),state:gn,stateRev:ct,docSeq:ct,reset:ut()}).strict(),K({...me,kind:te("event"),frame:ls}).strict(),K({...me,kind:te("status"),status:tr(["connecting","ready","offline","revoked"]),unconfirmed:ut()}).strict()]);function Je(e,t){try{if(pn(t,1048576)!==void 0)return null;const r=e.safeParse(t);return r.success?r.data:null}catch{return null}}var ve,_t,He;class dt{constructor(){Be(this,ve);$(this,"current",null);$(this,"token",0);$(this,"retiring",!1);$(this,"subscribers",new Set);$(this,"resources",new Map);$(this,"doc",null);$(this,"docClaims",new WeakMap);$(this,"retiringDoc",!1);$(this,"docResources",new Map);$(this,"bindings",new WeakSet)}getCurrent(){return this.current}observeHostContext(t){if(this.retiring)return null;if(!t.transportOwner||typeof t.transportOwner!="object"||!Number.isSafeInteger(t.publisherEpoch)||t.publisherEpoch<0)throw new Error("Explicit transport owner and epoch required.");const r=["frame","documentId","resolvedSource","logicalUrl","reloadKey","sessionId","eligibility","exactOrigin","transportOwner","publisherEpoch"];if(r.some(s=>!Object.hasOwn(t,s))||typeof t.documentId!="string"||!t.documentId||typeof t.logicalUrl!="string"||typeof t.reloadKey!="string")throw new Error("Complete host context required.");const n=this.current;return n&&r.every(s=>Object.is(n[s],t[s]))?n:(this.retire(),this.current=Object.freeze({...t,token:this.token,loaded:!1}),this.current)}observeLoaded(t){return this.retiring||this.current!==t||!t.frame?null:(this.retire(),this.current=Object.freeze({...t,token:this.token,loaded:!0}),this.current)}retire(){if(this.retiring)return;const t=this.current;this.current=null;const r=this.doc;this.doc=null,this.token++,this.retiring=!0;const n=[...t?this.resources.get(t)??[]:[],...r?this.docResources.get(r)??[]:[],...this.subscribers];r&&this.docResources.delete(r),t&&this.resources.delete(t);try{for(const s of n)try{const i=s();i&&typeof i.then=="function"&&Promise.resolve(i).catch(()=>{})}catch{}}finally{this.retiring=!1}}subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}own(t,r){if(this.retiring||this.current!==t)throw new Error("Frame observation retired.");const n=this.resources.get(t)??new Set;return n.add(r),this.resources.set(t,n),()=>{n.delete(r)}}bindDoc(t,r,n){return ye(this,ve,_t).call(this,t,r,n)}acquireDoc(t,r,n){const s=ye(this,ve,_t).call(this,t,r,n),i=Object.freeze({});this.docClaims.set(s,i);let a=!1;return Object.freeze({binding:s,release:()=>{a||(a=!0,this.docClaims.get(s)===i&&(this.docClaims.delete(s),this.doc===s&&this.bindings.has(s)&&ye(this,ve,He).call(this)))}})}disableDoc(){ye(this,ve,He).call(this)}retireDoc(t){this.doc===t&&this.bindings.has(t)&&ye(this,ve,He).call(this)}ownDoc(t,r){if(!this.isCurrent(t))throw new Error("Doc binding retired.");const n=this.docResources.get(t)??new Set;return n.add(r),this.docResources.set(t,n),()=>{n.delete(r)}}isCurrent(t){return!this.retiring&&!this.retiringDoc&&this.doc===t&&this.bindings.has(t)&&this.current===t.observation}}ve=new WeakSet,_t=function(t,r,n){const s=this.doc,i=this.token,a=Je(Rr,r);if(!a)throw this.disableDoc(),new Error("Established server Doc birth required.");const c=a,o=t.exactOrigin,u=t.eligibility==="served-document"?o==="null":t.eligibility==="preview-listener"&&o!==null&&new URL(o).origin===o;if(!t.loaded||!t.frame||typeof t.frame.postMessage!="function"||!t.resolvedSource||!u||t.documentId!==c.documentId||!n||n.length>200)throw new Error("Loaded eligible frame and established Doc birth required.");if(this.retiring||this.retiringDoc||this.current!==t||this.doc!==s||this.token!==i)throw new Error("Frame observation retired during Doc admission.");if(this.doc){if(this.doc.observation!==t)throw new Error("Doc binding belongs to another host load.");if(Q(this.doc.incarnation,c)&&this.doc.scope===n)return this.doc;throw this.retire(),new Error("Doc birth changed; a fresh host load is required.")}const d=Object.freeze({observation:t,incarnation:Object.freeze(c),scope:n});try{return this.doc=d,this.bindings.add(d),d}catch(f){throw this.doc===d&&ye(this,ve,He).call(this),f}},He=function(){if(this.retiringDoc)return;const t=this.doc;this.doc=null,this.retiringDoc=!0;const r=[...t?this.docResources.get(t)??[]:[]];t&&this.docResources.delete(t);try{for(const n of r)try{const s=n();s&&typeof s.then=="function"&&Promise.resolve(s).catch(()=>{})}catch{}}finally{this.retiringDoc=!1}};function hs(e,t,r){if(!r||typeof r.captureOriginal!="function"||typeof r.submit!="function"||typeof r.inspect!="function"||typeof r.isCurrentOwner!="function"||r.owner!==t.observation.transportOwner||r.publisherEpoch!==t.observation.publisherEpoch)throw new Error("Explicit current transport submit and inspect ports required.");const{owner:n,publisherEpoch:s,isCurrentOwner:i,submit:a,inspect:c,captureOriginal:o}=r,u=Object.freeze({expectedGeneration:t.incarnation.generation}),d=()=>{try{return e.isCurrent(t)?i(n,s)===!0&&e.isCurrent(t):!1}catch{return!1}};if(!d())throw new Error("Doc binding unavailable.");const f=()=>{if(!d())throw new Error("Doc binding retired.")};return Object.freeze({binding:t,current:d,captureOriginal:l=>{f();const g=l.id;f();const b=l.bytes;f();const m=Reflect.apply(o,r,[Object.freeze({id:g,bytes:b})]);if(f(),!m)return null;const v=m.id;f();const N=m.bytes;f();const T=m.submit;f();const R=m.inspect;return f(),v!==g||N!==b||typeof T!="function"||typeof R!="function"?null:Object.freeze({id:g,bytes:b,submit:async z=>{f(),z.throwIfAborted();const L=await Reflect.apply(T,m,[z]);return f(),z.throwIfAborted(),L},inspect:async z=>{f(),z.throwIfAborted();const L=await Reflect.apply(R,m,[z]);return f(),z.throwIfAborted(),L}})},retireObservation:()=>{d()&&e.retire()},onRetire:l=>e.ownDoc(t,l),submit:(l,g)=>(f(),g.throwIfAborted(),a(l,u,g)),inspect:(l,g)=>(f(),g.throwIfAborted(),c(l,u,g))})}function ar(e,t){const r=Je(Pt,t);return r&&r.receipt.id===e&&r.receipt.docSeq>0?r:null}class ps{constructor(t,r){$(this,"entries",new Map);$(this,"bytes",0);$(this,"running",!1);$(this,"retired",!1);$(this,"abort",new AbortController);$(this,"timer");$(this,"wake",null);$(this,"detach");if(this.port=t,this.scheduler=r,!t.current()||!r||["schedule","cancel","random"].some(n=>typeof r[n]!="function"))throw new Error("Current bound Doc port and scheduler required.");this.detach=t.onRetire(()=>this.retire())}getStatus(){return Object.freeze({pending:[...this.entries.values()].filter(t=>!t.settled).length,bytes:this.bytes,unconfirmed:[...this.entries.values()].filter(t=>t.unconfirmed).length,retired:this.retired})}emit(t){if(!this.live())return Promise.resolve({kind:"cancelled"});const r=Qe.safeParse(t);if(!r.success)return Promise.resolve({kind:"refused"});if(!this.live())return Promise.resolve({kind:"cancelled"});const n=JSON.stringify(r.data),s=r.data.id,i=this.entries.get(s);if(i)return i.bytes===n?i.promise:Promise.resolve({kind:"refused"});const a=new TextEncoder().encode(JSON.stringify({bytes:n,id:s,birth:this.port.binding.incarnation,scope:this.port.binding.scope,loadToken:this.port.binding.observation.token,publisherEpoch:this.port.binding.observation.publisherEpoch,sent:!1,settled:!1,unconfirmed:!1,attempts:8,retryAfterMs:3e4})).byteLength+1024;for(const u of this.entries.values()){if(this.entries.size<100&&this.bytes+a<=1048576)break;u.settled&&!u.unconfirmed&&(this.entries.delete(u.id),this.bytes-=u.weight)}if(this.entries.size>=100||this.bytes+a>1048576)return Promise.resolve({kind:"refused"});let c;const o=new Promise(u=>{c=u});return this.entries.set(s,{id:s,bytes:n,weight:a,sent:!1,settled:!1,unconfirmed:!1,resolve:c,promise:o}),this.bytes+=a,this.pump(),o}retire(){var t,r;if(!this.retired){if(this.retired=!0,this.abort.abort(),this.timer!==void 0)try{this.scheduler.cancel(this.timer)}catch{}this.timer=void 0,(t=this.wake)==null||t.call(this),this.wake=null;for(const n of this.entries.values())this.settle(n,{kind:n.sent?"unconfirmed":"cancelled"});this.entries.clear(),this.bytes=0,(r=this.detach)==null||r.call(this)}}settle(t,r){t.settled||(t.settled=!0,t.unconfirmed=r.kind==="unconfirmed",t.resolve(r),r.kind!=="unconfirmed"&&r.kind!=="accepted"&&(this.entries.delete(t.id),this.bytes-=t.weight))}live(){return this.retired||this.abort.signal.aborted?!1:this.port.current()&&!this.retired&&!this.abort.signal.aborted}cancel(t){try{t!==void 0&&this.scheduler.cancel(t)}catch{}}async wait(t){if(!this.live()){this.retire();return}await new Promise(r=>{let n=!1,s;const i=()=>{n||(n=!0,this.wake===i&&(this.wake=null),r())};this.wake=i;try{if(s=this.scheduler.schedule(()=>{this.timer===s&&(this.timer=void 0),i()},t),!this.live()||n){this.cancel(s),i(),this.live()||this.retire();return}this.timer=s}catch{i(),this.retire()}})}async call(t,r){if(!this.live())return this.retire(),r;const n=new AbortController;let s=()=>{},i;const a=()=>{n.abort(),this.cancel(i),s(r)};this.abort.signal.addEventListener("abort",a,{once:!0});try{return await new Promise(c=>{let o=!1;if(s=u=>{o||(o=!0,c(u))},i=this.scheduler.schedule(()=>{n.abort(),s(r)},15e3),!this.live()||this.abort.signal.aborted||n.signal.aborted||o){a(),this.live()||this.retire();return}try{Promise.resolve(t(n.signal)).then(s,()=>s(r))}catch{s(r)}})}finally{this.abort.signal.removeEventListener("abort",a),this.cancel(i)}}async pump(){if(!this.running){this.running=!0;try{for(const t of this.entries.values()){if(t.settled)continue;let r=!1;for(let n=0;n<8&&!t.settled;n++){if(!this.live()){this.retire();break}if(!t.original&&(t.original=this.port.captureOriginal(Object.freeze({id:t.id,bytes:t.bytes}))??void 0,!t.original||!this.live())){this.settle(t,{kind:t.sent?"unconfirmed":"refused"});break}const s=t.original;if(r){let o;try{o=await this.call(u=>s.inspect(u),{kind:"unknown"})}catch{this.settle(t,{kind:"unconfirmed"});break}if(!this.live()){this.retire();break}if(o.kind==="accepted"){const u=ar(t.id,o.receipt);this.settle(t,u?{kind:"accepted",receipt:u}:{kind:"unconfirmed"});break}if(o.kind!=="absent"){this.settle(t,{kind:"unconfirmed"}),o.kind==="terminal"&&this.retire();break}}t.sent=!0;let i;try{i=await this.call(o=>s.submit(o),{kind:"uncertain"})}catch{i={kind:"uncertain"}}if(!this.live()){this.retire();break}if(i.kind==="accepted"){const o=ar(t.id,i.receipt);this.settle(t,o?{kind:"accepted",receipt:o}:{kind:"unconfirmed"});break}if(i.kind==="terminal"){this.settle(t,{kind:"unconfirmed"}),this.retire();break}r=!0;const a=this.scheduler.random();if(!this.live()||t.settled){this.retire();break}const c=i.kind==="retry"&&Number.isFinite(i.retryAfterMs)?Math.max(0,Math.min(3e4,i.retryAfterMs)):500;await this.wait(c+Math.floor(Math.max(0,Math.min(1,Number.isFinite(a)?a:0))*250))}t.settled||this.settle(t,{kind:"unconfirmed"})}}catch{this.retire()}finally{this.running=!1}}}}class ms{constructor(t,r){$(this,"challenge");$(this,"queue");$(this,"detach");$(this,"timer");$(this,"port",null);$(this,"connected",!1);$(this,"closed",!1);$(this,"started",!1);$(this,"pending",new Map);if(this.bound=t,this.ports=r,!t.current()||typeof(r==null?void 0:r.nonce)!="function"||typeof r.channel!="function"||typeof r.offline!="function")throw new Error("Current loaded Doc binding and explicit handshake ports required.");if(t.binding.observation.eligibility==="served-document"?typeof r.boot!="string"||r.boot.length===0:r.boot!==null)throw new Error("A served document needs its boot nonce; a preview has none.");this.challenge=or.parse({protocol:"dorkos-doc",v:1,kind:"challenge",nonce:r.nonce(),requestToken:r.nonce(),loadToken:t.binding.observation.token,generation:t.binding.incarnation.generation}),this.queue=new ps(t,r.scheduler),this.detach=t.onRetire(()=>this.close())}start(){if(!this.bound.current()||this.closed||this.started)return;this.started=!0;const t=this.bound.binding.observation;try{const r=this.ports.scheduler.schedule(()=>{this.close()},5e3);if(!this.bound.current()||this.closed){try{this.ports.scheduler.cancel(r)}finally{this.close()}return}this.timer=r,t.frame.postMessage(this.challenge,t.exactOrigin==="null"?"*":t.exactOrigin)}catch{this.close()}}receive(t){if(!this.started||this.closed||!this.bound.current()||t.source!==this.bound.binding.observation.frame||t.origin!==this.bound.binding.observation.exactOrigin||t.ports.length!==0)return!1;const r=Je(or,t.data);if(!r||r.kind!=="ack"||!this.matches(r)||!this.booted(r))return!1;if(this.connected)return!0;this.connected=!0;let n;const s=()=>this.bound.current()&&!this.closed,i=()=>{for(const a of["port1","port2"])try{n==null||n[a].close()}catch{}return this.close(),!1};try{if(this.timer!==void 0&&this.ports.scheduler.cancel(this.timer),this.timer=void 0,!s()||(n=this.ports.channel(),!s())||(this.port=n.port1,this.port.onmessage=a=>{a.ports.length||this.command(a.data)},!s())||(this.port.start(),!s())||(this.bound.binding.observation.frame.postMessage({...this.challenge,kind:"connect"},this.bound.binding.observation.exactOrigin==="null"?"*":this.bound.binding.observation.exactOrigin,[n.port2]),!s()))return i()}catch{return i()}return!0}publish(t){this.send({...t,...this.challenge,kind:t.kind})}close(t="offline"){var r,n,s;if(!this.closed){this.closed=!0;try{(r=this.port)==null||r.postMessage({...this.challenge,kind:"status",status:t,unconfirmed:!0})}catch{}try{this.queue.retire()}catch{}try{this.timer!==void 0&&this.ports.scheduler.cancel(this.timer)}catch{}this.timer=void 0;try{(n=this.port)==null||n.close()}catch{}this.port=null,this.pending.clear(),(s=this.detach)==null||s.call(this);try{this.ports.offline()}catch{}}}matches(t){return t.nonce===this.challenge.nonce&&t.requestToken===this.challenge.requestToken&&t.loadToken===this.challenge.loadToken&&t.generation===this.challenge.generation}booted(t){return this.ports.boot===null||t.boot===this.ports.boot}send(t){var r;if(!this.closed&&this.connected&&this.bound.current()){const n=Je(fs,t);if(n)try{(r=this.port)==null||r.postMessage(n)}catch{this.close()}}}command(t){if(this.closed||!this.connected||!this.bound.current())return;const r=Je(ds,t);if(!(!r||!this.matches(r))){if(r.kind==="retire"){this.bound.retireObservation(),this.close();return}this.pending.has(r.requestId)||this.pending.size>=100||(this.pending.set(r.requestId,r.event.id),this.queue.emit(r.event).then(n=>{!this.bound.current()||this.closed||this.pending.get(r.requestId)!==r.event.id||(this.pending.delete(r.requestId),this.send(n.kind==="accepted"?{...this.challenge,kind:"receipt",requestId:r.requestId,receipt:n.receipt}:{...this.challenge,kind:"refused",requestId:r.requestId,outcome:n.kind}))}))}}}class gs{constructor(){$(this,"contiguous",0);$(this,"through",0);$(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(t){this.contiguous=Math.max(this.contiguous,t)}markThrough(t){this.through=Math.max(this.through,t)}recordGap(t){return this.markThrough(t.docSeq),this.pending.set(t.docSeq,t),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 t=this.contiguous+1,r=this.pending.get(t);return r&&this.pending.delete(t),r}clearReachedTarget(){return this.contiguous<this.through?!1:(this.through=0,!0)}}const Dt=new WeakMap,rt=new WeakMap,ke=new WeakMap,Ze=new WeakMap;function Se(e){Me(e);const t=Dt.get(e);if(!t)throw new Error("Replay owner lifetime is absent.");return t}function vs(e,t){const r=rt.get(t);if(!r||r.owner!==e)throw new Error("Replay run is foreign.");return r}function Tr(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){for(const t of Object.values(e))Tr(t);Object.freeze(e)}return e}function bs(e){if(Me(e),Dt.has(e))throw new Error("Replay owner lifetime is already initialized.");Dt.set(e,new gs)}function Ut(e){const t=Se(e);return Object.freeze({highest:t.highest,through:t.catchUpThrough,pending:t.pendingCount})}function cr(e){Se(e).reset()}function ur(e,t){const r=rt.get(t);if(!(!r||r.owner!==e))return Object.freeze({subject:r.subject,epoch:r.epoch,revision:r.revision,observation:r.observation,ended:r.ended})}function ys(e,t,r){const n=ke.get(r),s=rt.get(t);if(!(!s||s.owner!==e||!n||n.owner!==e||n.run!==t||n.phase!=="consuming"||n.admissionRead||!ie(e,t)))return n.admissionRead=!0,Object.freeze({response:n.response,since:n.since,revision:n.revision,observation:n.observation,targetBirth:s.targetBirth})}function ws(e,t,r){const n=vs(e,t),s=ke.get(r),i=qr(e,t,r);if(!i||!s||s.owner!==e||s.run!==t||s.phase!=="consuming"||!s.admissionRead||n.ended||n.epoch!==i.epoch||n.subject!==i.previous)throw new Error("Replay own issuance is foreign or stale.");n.subject=i.subject}function Ar(e,t,r,n){if(!ie(e,t))return;if(n){const i=Ze.get(r);return i&&i.owner===e&&i.run===t&&i.phase==="dispatching"&&!i.advanced?i.frame:void 0}const s=ke.get(r);return s&&s.owner===e&&s.run===t&&s.phase==="frames"&&s.dispatching!==void 0&&!s.advanced?s.frames[s.dispatching]:void 0}function xs(e,t,r,n){const s=Vs(e,t,r,n);if(!s||!ie(e,t))throw new Error("Replay cursor advance has no genuine core witness.");const i=n?Ze.get(r):ke.get(r);if(!i||i.advanced)throw new Error("Replay frame advance was consumed.");i.advanced=!0,Se(e).advance(s.docSeq)}function ks(e,t){const r=rt.get(t),n=(r==null?void 0:r.lastPage)&&ke.get(r.lastPage);if(!r||r.owner!==e||!ie(e,t)||r.target===void 0||!n||n.phase!=="finished"||n.next!==n.frames.length||n.response.events.length>=200&&Se(e).highest<r.target)return;const s=Se(e);return Object.freeze({highest:s.highest,through:s.catchUpThrough,target:r.target})}function Cs(e,t){const r=et(e,t);if(!r)throw new Error("Replay notice is foreign or stale.");const n=Se(e),s=r.notification;if(r.mode==="quarantine")n.markThrough(s.type==="canvas_channel_snapshot"?s.snapshot.highWatermark:s.docSeq),s.type!=="canvas_channel_snapshot"&&n.recordGap(s);else{if(r.mode==="gap"&&s.type!=="canvas_channel_snapshot")return n.recordGap(s);r.mode==="event"&&oi(e,t)}return!1}function js(e,t){const r=et(e,t);if(!r||r.mode!=="event"||r.notification.type==="canvas_channel_snapshot")throw new Error("Notice cursor advance is foreign.");Se(e).advance(r.notification.docSeq)}function Rs(e){const t=de(e),r=Se(e),n=Object.freeze({}),s={owner:e,subject:t.subject,epoch:t.epoch,revision:t.revision,observation:t.observation,ended:!1,starting:r.highest,succeeded:!1};rt.set(n,s),Ys(e,n);const i=()=>ie(e,n),a=()=>de(e).live?i()?void 0:"restart":"stop";return Object.freeze({async readPage(){if(!i())return null;const c=de(e),o=r.highest,u=bt(e),d=u.getCanvasChannel;if(!i())return null;const f=await d.call(u,t.documentId,{since:o,limit:200});if(!i())return null;const l=Tr(vn.parse(f));if(!i())return null;const g=Object.freeze({});return ke.set(g,{owner:e,run:n,response:l,since:o,revision:c.revision,observation:c.observation,phase:"read",admissionRead:!1,frames:[],next:0,advanced:!1}),g},consumePage(c){const o=ke.get(c);return!i()||!o||o.owner!==e||o.run!==n||o.phase!=="read"?{kind:"done"}:(o.phase="consuming",Qs(e,n,c)!=="accepted"||!i()?(o.phase="finished",{kind:"done"}):(s.target??(s.target=o.response.highWatermark),s.targetBirth=o.response.incarnation,o.frames=Object.freeze(o.response.events.filter(d=>d.docSeq<=s.target)),o.phase="frames",s.lastPage=c,o.response.resetRequired&&r.advance(o.response.retentionFloor-1),{kind:"frames",count:o.frames.length}))},advancePageFrame(c,o){const u=ke.get(c);if(!i()||!u||u.owner!==e||u.run!==n||u.phase!=="frames"||o!==u.next||!u.frames[o])return!1;u.next=o+1,u.dispatching=o,u.advanced=!1;try{return dr(e,n,c,!1)&&i()}finally{u.dispatching=void 0}},finishPage(c){const o=ke.get(c);if(!i()||!o||o.owner!==e||o.run!==n||o.phase!=="frames"||o.next!==o.frames.length||s.target===void 0)return"done";if(o.phase="finished",o.response.events.length<200||r.highest>=s.target)return r.advance(s.target),!i()||(fr(e,n),!i())||(s.succeeded=!0),"done";if(r.highest<=o.since)throw new Error("Document replay made no progress.");return"again"},failed(){i()&&Ks(e,n)},beginFinalization(){return a()??(s.succeeded?"drain":"stop")},takePending(){if(!i())return null;const c=r.takeNextContiguous();if(!c||!i())return null;const o=Object.freeze({});return Ze.set(o,{owner:e,run:n,frame:c,phase:"taken",advanced:!1}),o},advancePending(c){const o=Ze.get(c);if(!i()||!o||o.owner!==e||o.run!==n||o.phase!=="taken")return!1;o.phase="dispatching";try{return dr(e,n,c,!0)&&i()}finally{o.phase="finished",Ze.delete(c)}},finishFinalization(){const c=a();if(c)return c;if(r.clearReachedTarget()){const o=a();if(o)return o;fr(e,n);const u=a();if(u)return u}if(r.pendingCount||r.catchUpThrough>r.highest){const o=de(e);if(r.highest>s.starting||o.revision>s.revision||o.observation>s.observation)return"restart";ei(e,n)}return a()??"stop"},current:i,end:()=>{s.ended=!0}})}class Os{constructor(){$(this,"revision",0);$(this,"draining",!1);$(this,"cleanup");$(this,"subscribers",new Set);$(this,"retirements",new WeakMap)}captureRetirement(){const t=Object.freeze({}),r=++this.revision,n=this.cleanup;return this.cleanup=void 0,this.retirements.set(t,{revision:r,cleanup:n,callbacks:this.draining?[]:[...this.subscribers]}),t}drainRetirement(t){const r=this.retirements.get(t);if(!r)throw new Error("Frame resource retirement is foreign or consumed.");this.retirements.delete(t);const n=this.draining;this.draining=!0;try{this.drain(r.cleanup);for(const s of r.callbacks)this.drain(s)}finally{this.draining=n}}begin(){const t=this.captureRetirement(),r=this.revision;return this.drainRetirement(t),r}once(t,r,n){let s=!1;return()=>{if(s||(s=!0,!this.current(t)||!r()||!this.current(t)))return null;const i=n();return!this.current(t)||!r()||!this.current(t)?null:i}}drain(t){try{Promise.resolve(t==null?void 0:t()).catch(()=>{})}catch{}}current(t){return this.revision===t}install(t,r){return this.current(t)?(this.cleanup=r,!0):!1}subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}}function Es(e,t,r){const n=()=>e.current(t)&&r.current()===!0&&e.current(t),s=e.once(t,n,r.complete);return Object.freeze({completeLoad:()=>{const i=s();return!i||!n()||r.accept(i)!==!0||!n()?null:i}})}function Ss(e,t,r){const n=()=>e.current(t)&&r.current()===!0&&e.current(t);if(!n())return null;const s=r.acquire();if(!s)return null;let i=!1,a=null,c;try{const o=s.binding;if(n()&&r.bindingCurrent(o)===!0&&n()){const u=r.createPort(o);n()&&r.portCurrent(u)===!0&&n()&&e.install(t,s.release)&&(i=!0,a=u)}}catch(o){c={cause:o}}if(!i)try{s.release()}catch(o){c??(c={cause:o})}if(c)throw c.cause;return a}function _s(e){const t=()=>Object.assign(new Error("Document actions are unavailable."),{status:409}),r=(s,i)=>{if(i.aborted||!e.current(s)||i.aborted)throw t()},n=(s,i)=>{const a=Pt.parse(i);if(a.receipt.id!==s)throw new Error("Document receipt does not match this action.");return a};return Object.freeze({current:e.current,submit:async(s,i)=>{const a=Qe.parse(JSON.parse(JSON.stringify(s))),c=a.id;r("submit",i);const o=await e.submit(a,i);r("read",i);const u=n(c,o);return r("read",i),u},inspect:async(s,i)=>{r("read",i);const a=await e.inspect(s,i);r("read",i);const c=n(s,a);return r("read",i),c},captureOriginal:s=>{const i=Qe.parse(JSON.parse(JSON.stringify(s))),a=i.id,c=JSON.stringify(i);if(!e.current("submit"))return null;const o=e.capture(i,c);if(!o||!e.current("submit")||!o.current("submit"))return null;let u=!1;const d=f=>o.current(f)===!0;return Object.freeze({id:a,bytes:c,current:d,submit:async f=>{if(u||f.aborted||!d("submit"))throw t();u=!0;const l=await o.submit(JSON.parse(c),f);if(f.aborted||!d("read"))throw t();const g=n(a,l);if(f.aborted||!d("read"))throw t();return g},inspect:async f=>{if(f.aborted||!d("read"))throw t();const l=await o.inspect(a,f);if(f.aborted||!d("read"))throw t();const g=n(a,l);if(f.aborted||!d("read"))throw t();return g}})}})}function Ds(e){return Object.freeze({id:e.id,bytes:e.bytes,submit:async t=>{try{return{kind:"accepted",receipt:await e.submit(t)}}catch{return{kind:"uncertain"}}},inspect:async t=>{try{return{kind:"accepted",receipt:await e.inspect(t)}}catch{return{kind:"unknown"}}}})}function Is(e,t,r){const n=Qe.parse(JSON.parse(e.bytes));if(n.id!==e.id||JSON.stringify(n)!==e.bytes||!r())return null;const s=t(n);return!r()||!s?null:Ds(s)}const Ns=dt.prototype.acquireDoc,ft=new WeakMap,It=new WeakMap;function Ts(e,t){const r=bt(e),n=new WeakMap,s=(a,c)=>t.current(c)&&Ee(e,a,!0);return Object.freeze({prepareFrameLoad:(a,c)=>{var l;if(!(a instanceof dt)||c.loaded)return null;const o=lr(e),u=o?(l=Ne(e,o))==null?void 0:l.httpBaseline:void 0,d=t.begin();if(!o||!u||!t.current(d)||!Ee(e,o,!0)||a.getCurrent()!==c||c.transportOwner!==r||!s(o,d))return null;let f=null;return Es(t,d,{current:()=>{var g;return Ee(e,o,!0)&&((g=Ne(e,o))==null?void 0:g.httpBaseline)===u&&a.getCurrent()===(f??c)&&t.current(d)&&Ee(e,o,!0)},complete:()=>(f=a.observeLoaded(c),f),accept:g=>{var b,m;return!t.current(d)||!Ee(e,o,!0)||((b=Ne(e,o))==null?void 0:b.httpBaseline)!==u||a.getCurrent()!==g||!t.current(d)||!Ee(e,o,!0)||((m=Ne(e,o))==null?void 0:m.httpBaseline)!==u?!1:(n.set(g,{record:o,birth:u.birth}),!0)}})},subscribeInvalidation:a=>t.subscribe(a),attachFrame:(a,c)=>{if(!(a instanceof dt))return null;const o=lr(e),u=t.begin();if(!o||!t.current(u)||!Ee(e,o,!0)||a.getCurrent()!==c||c.transportOwner!==r||!s(o,u))return null;const d=n.get(c);return!d||d.record!==o||!Q(d.birth,Ne(e,o).birth)?null:Ss(t,u,{current:()=>s(o,u),acquire:()=>{const f=Ns.call(a,c,Ne(e,o).birth,Ne(e,o).birth.documentId);let l=!1,g=null,b;try{s(o,u)&&a.getCurrent()===c&&s(o,u)&&(g=Object.freeze({binding:f.binding,release:f.release}),l=!0)}catch(m){b={cause:m}}if(!l)try{f.release()}catch(m){b??(b={cause:m})}if(b)throw b.cause;return g},bindingCurrent:f=>a.isCurrent(f)&&s(o,u),createPort:f=>hs(a,f,{owner:r,publisherEpoch:c.publisherEpoch,isCurrentOwner:(l,g)=>l===r&&g===c.publisherEpoch&&t.current(u)&&Ee(e,o),captureOriginal:l=>Is(l,g=>{var b;return((b=Xs(e,o))==null?void 0:b.captureOriginal(g))??null},()=>s(o,u)),submit:async()=>({kind:"terminal"}),inspect:async()=>({kind:"unknown"})}),portCurrent:f=>f.current()&&s(o,u)})}})}function As(e){if(Me(e),ft.has(e))throw new Error("Frame owner is already initialized.");const t=new Os,r=Ts(e,t);return ft.set(e,{frames:t,facade:r}),r}function Ms(e){var t;return Me(e),(t=ft.get(e))==null?void 0:t.facade}function Ge(e){Me(e);const t=ft.get(e);if(!t)return;const r=Object.freeze({});return It.set(r,{owner:e,frames:t.frames,ticket:t.frames.captureRetirement()}),r}function Ve(e,t){if(!t)return;const r=It.get(t);if(!r||r.owner!==e)throw new Error("Frame retirement is foreign or consumed.");It.delete(t),r.frames.drainRetirement(r.ticket)}function Mr(e,t){const r=xe(e,t),n=Gs(e,t);if(!(!r||!n))return{owner:t,verified:r.verified,..._s(n)}}function ge(e,t){return{documentId:e,transport:t,events:[],available:!1}}function Fs(e,t,r,n,s,i){var o,u;const a=e.documentId===r&&e.transport===n?e:ge(r,n);if(a.snapshot&&(t.highWatermark<a.snapshot.highWatermark||t.stateRev<a.snapshot.stateRev))return a;const c=new Map((((o=a.snapshot)==null?void 0:o.receipts)??[]).filter(d=>d.receipt.docSeq>=t.receiptRetentionFloor).map(d=>[d.receipt.id,d]));for(const d of t.receipts)c.set(d.receipt.id,d);return{...a,available:i,snapshot:{...t,...s?{}:{routing:(u=a.snapshot)==null?void 0:u.routing},receipts:[...c.values()].sort((d,f)=>f.receipt.docSeq-d.receipt.docSeq).slice(0,400)},events:t.resetRequired?a.events.filter(d=>d.docSeq>=t.retentionFloor):a.events}}function zs(e){var r,n,s,i,a,c,o,u,d,f,l,g;const t=async()=>{throw Object.assign(new Error("Document actions are unavailable."),{status:409})};return{documentId:e.documentId,enabled:e.available&&((r=e.binding)==null?void 0:r.verified)===!0&&((s=(n=e.snapshot)==null?void 0:n.routing)==null?void 0:s.enabled)===!0,submissionOwner:(i=e.binding)==null?void 0:i.owner,current:((a=e.binding)==null?void 0:a.current)??(()=>!1),approvedEventTypes:e.available?((o=(c=e.snapshot)==null?void 0:c.routing)==null?void 0:o.approvedEventTypes)??[]:[],destinationLabel:e.available?((d=(u=e.snapshot)==null?void 0:u.routing)==null?void 0:d.destinationLabel)??"Actions unavailable":"Actions unavailable",...e.snapshot?{snapshot:e.snapshot}:{},submit:((f=e.binding)==null?void 0:f.submit)??t,inspect:((l=e.binding)==null?void 0:l.inspect)??t,captureOriginal:(g=e.binding)==null?void 0:g.captureOriginal}}function qs(e,t,r){return!!(e&&t&&r.incarnation&&Q(t,r.incarnation)&&(r.highWatermark<e.highWatermark||r.stateRev<e.stateRev))}function Fr(e,t,r,n){const s=e.documentId===r&&e.transport===n?e:ge(r,n);return{...s,events:[...s.events,t].slice(-200)}}function Ls(e,t){if(e.incarnation&&(e.incarnation.documentId!==t||e.events.some(r=>r.documentId!==t||!r.incarnation||!Q(e.incarnation,r.incarnation))))throw new Error("Document replay identity changed.")}const Nt=new WeakMap;function Ps(e,t,r){const n=ys(e,t,r);if(n)return Nt.set(r,{owner:e,run:t,witness:n}),n}const zr=new WeakMap,Ke=new WeakMap,Tt=new WeakMap,At=new WeakMap;function Ce(e,t){Me(e);const r=t??Ke.get(e),n=r&&zr.get(r);return n&&n.owner===e&&Ke.get(e)===r&&n.active?n:void 0}function ee(e){return Me(e),Ke.get(e)}function xe(e,t){const r=Ce(e,t);return r?Object.freeze({birth:r.birth,httpBaseline:r.httpBaseline,snapshot:r.snapshot,verified:r.verified}):void 0}function Xe(e,t,r=!1){var i,a;const n=Ce(e,t),s=de(e);return!!n&&s.live&&n.verified&&n.transport===bt(e)&&(!r||((a=(i=n.snapshot)==null?void 0:i.routing)==null?void 0:a.enabled)===!0)}function Bs(e){const t=Ce(e);Ke.delete(e),t&&(t.active=!1,t.verified=!1)}function Ct(e,t){const r=Ce(e,t);r&&(r.verified=!1)}function Us(e,t,r){const n=Ce(e,r);return!n||!ie(e,t)?!1:(n.verified=!0,ie(e,t))}function Ws(e,t,r){const n=Nt.get(r);Nt.delete(r);const s=(n==null?void 0:n.owner)===e&&n.run===t?n.witness:void 0;if(!s||!ie(e,t))return!1;const i=s.response.incarnation;let a=Ce(e);if(!a&&!i)return ie(e,t);if(!a&&i){const c=de(e),o=()=>{const b=de(e);return ie(e,t)&&b.epoch===c.epoch&&b.observation===c.observation&&ee(e)===c.subject},u=bt(e),d=u.ingestCanvasEvent;if(!o())return!1;const f=Function.prototype.bind.call(d,u),l=u.getCanvasEventReceipt;if(!o())return!1;const g=Function.prototype.bind.call(l,u);if(!o())return!1;a={owner:e,token:Object.freeze({}),birth:Object.freeze({...i}),active:!0,verified:!1,submit:f,inspect:g,transport:u},zr.set(a.token,a),Ke.set(e,a.token),a.httpBaseline=Object.freeze({birth:a.birth,floor:s.response.receiptRetentionFloor}),Tt.set(r,Object.freeze({owner:e,run:t,epoch:c.epoch,previous:c.subject,subject:a.token}));try{ws(e,t,r)}catch(b){throw Ce(e)===a&&ni(e,t,r),b}finally{Tt.delete(r)}if(!ie(e,t))return!1}else if(a){if(!i||!Q(a.birth,i))return!1;a.httpBaseline=Object.freeze({birth:a.birth,floor:s.response.receiptRetentionFloor})}return ie(e,t)?(a&&(a.verified=si(e)||a.verified),!0):!1}function Wt(e,t,r){const n=$t(e),s=n.subject,i=()=>Br(e,n,r);if(!s||!Xe(e,s)){const o=Ge(e);Ve(e,o)}if(!i())return;const a=s&&Mr(e,s),c=Ms(e);n.dispatch(o=>{var f;if(!i())return o;const u=((f=o.binding)==null?void 0:f.owner)===s?o:ge(n.documentId,n.transport),d=typeof t=="function"?t(u):t;return i()?{...d,...d.snapshot?{snapshot:Object.freeze({...d.snapshot})}:{},binding:a,frameAdmission:c}:o})}function $s(e,t,r,n,s){const i=$t(e),a=Ce(e);Br(e,i,s)&&(a&&(a.snapshot=t),Wt(e,c=>Fs(c,t,i.documentId,i.transport,r,n),s))}function Hs(e,t,r,n){const s=Ar(e,t,r,n);if(!ie(e,t)||!s)return!1;if(s.docSeq<=Ut(e).highest)return ie(e,t);At.set(r,{owner:e,run:t,pending:n,frame:s});try{xs(e,t,r,n)}finally{At.delete(r)}if(!ie(e,t))return!1;const i=$t(e);return Wt(e,a=>Fr(a,s,i.documentId,i.transport),t),ie(e,t)}function Gs(e,t){const r=Ce(e,t);if(!r)return;const n=de(e).documentId;return{current:s=>Xe(e,t,s==="submit"),submit:(s,i)=>r.submit(n,s,{expectedGeneration:r.birth.generation},i),inspect:(s,i)=>r.inspect(n,s,{expectedGeneration:r.birth.generation},i),capture:()=>{const s=r.httpBaseline;return!s||!Xe(e,t,!0)||!Q(s.birth,r.birth)?null:Object.freeze({current:i=>Xe(e,t,i==="submit")&&(i==="read"||r.httpBaseline===s),submit:(i,a)=>r.submit(n,i,{expectedGeneration:s.birth.generation},a),inspect:(i,a)=>r.inspect(n,i,{expectedGeneration:s.birth.generation},a)})}}}function qr(e,t,r){const n=Tt.get(r),s=de(e);return n&&n.owner===e&&n.run===t&&s.epoch===n.epoch&&s.subject===n.subject&&s.live?n:void 0}function Vs(e,t,r,n){const s=At.get(r);return s&&s.owner===e&&s.run===t&&s.pending===n&&ie(e,t)?s.frame:void 0}const Lr=new WeakMap,ht=new WeakMap;function Js(e){const t=ht.get(e);if(!t)throw new Error("Document construction ticket is foreign or consumed.");return ht.delete(e),t}function Zs(e,t,r){const n=Object.freeze({});ht.set(n,Object.freeze({documentId:e,transport:t,dispatch:r}));try{const s=ii(n);return Lr.set(n,s),n}finally{ht.delete(n)}}function ne(e){const t=Lr.get(e);if(!t)throw new Error("Document owner is foreign.");return t}function Me(e){ne(e)}function de(e){return ne(e).facts()}function bt(e){return ne(e).transport()}function lr(e){return ne(e).subject()}function Ne(e,t){return ne(e).subjectFacts(t)}function Ee(e,t,r=!1){return ne(e).subjectCurrent(t,r)}function Xs(e,t){return ne(e).binding(t)}function Ys(e,t){ne(e).reserve(t)}function ie(e,t){return ne(e).current(t)}function Qs(e,t,r){return ne(e).admit(t,r)}function dr(e,t,r,n){return ne(e).frame(t,r,n)}function fr(e,t){return ne(e).qualify(t)}function Ks(e,t){ne(e).failed(t)}function ei(e,t){ne(e).unavailable(t)}function ti(e,t){ne(e).start(t)}function ri(e){ne(e).dispose()}const Pr=new WeakMap;function $t(e){const t=Object.freeze(ne(e).projection());return Pr.set(t,Object.freeze({custodyKey:e,capture:t})),t}function Br(e,t,r){const n=Pr.get(t);return(n==null?void 0:n.custodyKey)===e&&n.capture===t&&ne(e).projectionCurrent(t.epoch,t.subject,r)}function ni(e,t,r){ne(e).abortAdmission(t,r)}function si(e){return ne(e).qualified()}const Mt=new WeakMap;function ii(e){const{documentId:t,transport:r,dispatch:n}=Js(e);let s,i=!1,a;const c={live:!0};let o=0,u,d,f=!1,l,g,b=0;const m=()=>c.live,v=()=>Bs(e);let N=0;const T=()=>Ut(e),R=j=>{const O=ur(e,j);return!!O&&!O.ended&&m()&&s===j&&O.epoch===o&&O.subject===ee(e)},z=(j=!1)=>{const O=Ge(e);v(),o++,s=void 0,j&&cr(e),Ve(e,O)},L=(j,O)=>Wt(e,j,O),B=j=>{const O=ks(e,j),k=ee(e),A=k&&xe(e,k);return!R(j)||!O||O.through>O.highest||!l||!A||!Q(l,A.birth)||!Us(e,j,k)?!1:(l=void 0,L(q=>({...q,available:!0}),j),R(j))},H=(j,O,k)=>{const A=ee(e),q=A&&xe(e,A),w=o,C=()=>m()&&w===o&&ee(e)===A&&(!k||R(k));if(!C()||qs(q==null?void 0:q.snapshot,q==null?void 0:q.birth,j))return;const U=O?j.routing:d;j={...j,routing:U&&Object.freeze({enabled:U.enabled,destinationLabel:U.destinationLabel,approvedEventTypes:Object.freeze([...U.approvedEventTypes])})},O&&(d=j.routing),!A&&!j.incarnation&&(f=!0),C()&&$s(e,j,O,l===void 0,k)},x=(j,O)=>{var se;const k=Ps(e,j,O);if(!R(j)||!k)return"discard";const A=k.response;Ls(A,t);const q=A.incarnation;if((ee(e)||l||g)&&!q)throw new Error("Document replay identity is unavailable.");if(g&&q&&!Q(g,q))return z(!0),L(ge(t,r)),"restart";const w=ee(e),C=(w&&((se=xe(e,w))==null?void 0:se.birth))??l;if(q&&(C&&!Q(C,q)||!C&&f||k.targetBirth&&!Q(k.targetBirth,q)))return l=q,f=!1,d=void 0,u=void 0,z(!0),L(ge(t,r)),"restart";const{events:U,...G}=A,Z=ee(e);return!Z&&q&&(l=g??q),!Ws(e,j,O)||!R(j)?"discard":(!Z&&q&&(g=void 0),H(G,k.revision===N,j),R(j)?"accepted":"discard")},I=(j,O,k)=>{var C;const A=Ar(e,j,O,k),q=ee(e),w=(q&&((C=xe(e,q))==null?void 0:C.birth))??l;return!R(j)||!A||A.documentId!==t||w&&(!A.incarnation||!Q(w,A.incarnation))?!1:Hs(e,j,O,k)},M=(j,O)=>{const k=Object.freeze({});Mt.set(k,Object.freeze({owner:e,revision:N,observation:b,epoch:o,notification:j,mode:O}));try{return Cs(e,k)}finally{Mt.delete(k)}},W=j=>{if(i||!m()||(i=!0,L(ge(t,r)),!m()))return;const O=bn(void 0,k=>{if(!m()||k.documentId!==t)return;const A=k.type==="canvas_channel_snapshot"?k.snapshot.incarnation:k.incarnation,q=ee(e);if(!q){if(l&&!g&&(!A||!Q(l,A))||!A||A.documentId!==t)return;if(!g||!Q(g,A)){const w=!!g||!!l;if(g=Object.freeze({...A}),b++,d=void 0,u=void 0,f=!1,w&&(z(!0),L(ge(t,r))),!m()||!g||!Q(g,A))return}M(k,"quarantine"),m()&&j();return}if(l&&(!A||!Q(l,A))){A&&j();return}if(A&&!Q(xe(e,q).birth,A)){l=A,f=!1,d=void 0,u=void 0,z(!0),L(ge(t,r)),m()&&j();return}if(A){if(u!==void 0&&u!==k.scope){const w=Ge(e);if(u=k.scope,Ct(e,q),o++,s=void 0,N++,Ve(e,w),ee(e)!==q||!m())return;L(C=>({...C,available:!1})),ee(e)===q&&m()&&j();return}u=k.scope,N++,k.type==="canvas_channel_snapshot"?H(k.snapshot,!0):k.docSeq>T().highest+1?(M(k,"gap")&&m()&&L(C=>({...C,available:!1})),m()&&j()):M(k,"event")}},r,()=>{if(!m())return;const k=Ge(e),A=ee(e);A&&Ct(e,A),o++,s=void 0,N++,Ve(e,k),L(q=>({...q,available:!1})),m()&&j()});m()?a=O:O(),m()&&j()};return Ur.set(e,j=>{const O=et(e,j);if(!O||O.notification.type==="canvas_channel_snapshot")return;const k=ee(e),A=o;!k||!O.notification.incarnation||!Q(xe(e,k).birth,O.notification.incarnation)||(L(q=>Fr(q,O.notification,t,r)),!m()||A!==o||ee(e))}),{facts:()=>Object.freeze({documentId:t,live:m(),epoch:o,revision:N,observation:b,subject:ee(e)}),transport:()=>r,subject:()=>ee(e),subjectFacts:j=>xe(e,j),subjectCurrent:(j,O)=>Xe(e,j,O),binding:j=>Mr(e,j),qualified:()=>l===void 0,projection:()=>({documentId:t,transport:r,dispatch:n,epoch:o,run:s,subject:ee(e)}),projectionCurrent:(j,O,k)=>m()&&j===o&&O===ee(e)&&(!k||s===k),abortAdmission:(j,O)=>{qr(e,j,O)&&z(!0)},reserve:j=>{const O=ur(e,j);if(!O||O.ended||!m()||O.epoch!==o||O.subject!==ee(e))throw new Error("Replay run is foreign or stale.");s=j},current:R,admit:x,frame:I,qualify:B,failed:j=>{if(!R(j))return;const O=ee(e);O&&Ct(e,O),L(k=>({...k,available:!1}),j)},unavailable:j=>{R(j)&&L(O=>({...O,available:!1}),j)},start:W,dispose:()=>{if(!m())return;const j=Ge(e);c.live=!1,s=void 0;const O=a;a=void 0,v(),o++,cr(e);try{Ve(e,j)}finally{O==null||O()}}}}function et(e,t){const r=Mt.get(t),n=de(e);if(!(!r||r.owner!==e||!n.live||n.epoch!==r.epoch||n.revision!==r.revision||n.observation!==r.observation))return r}function oi(e,t){var c;const r=et(e,t);if(!r||r.notification.type==="canvas_channel_snapshot")return;const n=r.notification,i=de(e).subject,a=i&&xe(e,i);!a||!n.incarnation||!Q(a.birth,n.incarnation)||n.docSeq<=Ut(e).highest||(js(e,t),!(!et(e,t)||de(e).subject!==i)&&((c=Ur.get(e))==null||c(t)))}const Ur=new WeakMap;function ai(e,t,r){const n=Zs(e,t,r);bs(n);const s=As(n);return Object.freeze({beginRun:()=>Rs(n),frameAdmission:s,start:i=>ti(n,i),dispose:()=>ri(n)})}function ci(e,t){let r,n=0;const s=f=>{try{t==null||t(f)}catch{}},i=f=>{r===f&&(r=void 0)},a=(f,l)=>{f.settled||(f.settled=!0,r||s(!1),l?f.reject(l.cause):f.resolve())},c=()=>{d().catch(()=>{})},o=(f,l)=>{const g=()=>n===f.revision;if(!g())return;const b=l.beginFinalization();if(g()){if(b==="restart"){c();return}if(b==="drain")for(;g();){const m=l.drainOne();if(!g())return;if(m!=="again"){if(m==="restart")c();else if(m==="tail"){const v=l.finishFinalization();g()&&v==="restart"&&c()}return}}}},u=async f=>{let l,g;try{l=e();try{for(;await l.page()==="again";);}catch(b){l.failed(b)}}catch(b){g={cause:b}}finally{i(f);try{l&&o(f,l)}catch(b){g={cause:b}}finally{a(f,g)}}},d=()=>{if(r)return r.promise;let f,l;const g=new Promise((m,v)=>{f=m,l=v}),b={revision:++n,promise:g,resolve:f,reject:l,settled:!1};return r=b,s(!0),u(b),g};return Object.freeze({request:d})}function ui(e,t,r,n){const s=ai(e,t,r);let i=!1;const a=ci(()=>{const c=s.beginRun();return{async page(){const o=await c.readPage();if(!o)return"done";const u=c.consumePage(o);if(u.kind!=="frames")return u.kind;for(let d=0;d<u.count;d++)if(!c.advancePageFrame(o,d))return"done";return c.finishPage(o)},failed:()=>c.failed(),beginFinalization:()=>{const o=c.beginFinalization();return o!=="drain"&&c.end(),o},drainOne(){if(!c.current())return c.end(),"stop";const o=c.takePending();return o?c.advancePending(o)?"again":(c.end(),"stop"):"tail"},finishFinalization:()=>{try{return c.finishFinalization()}finally{c.end()}}}},c=>{i||n==null||n(c)});return s.start(()=>{a.request().catch(()=>{})}),Object.freeze({dispose(){i=!0,s.dispose()}})}function Wr(e){var u,d,f;const t=ae(),[r,n]=p.useState(()=>ge(e,t)),[s,i]=p.useState({documentId:e,transport:t,pending:!0});p.useLayoutEffect(()=>{const l=ui(e,t,n,g=>{i({documentId:e,transport:t,pending:g})});return()=>l.dispose()},[e,t]);const a=r.documentId===e&&r.transport===t?r:ge(e,t),c=p.useMemo(()=>zs(a),[a]),o=p.useMemo(()=>{var b;const l=(b=a.snapshot)==null?void 0:b.incarnation,g=a.binding;return l&&g?Object.freeze({incarnation:Object.freeze({...l}),current:()=>g.current("read")}):void 0},[(u=a.snapshot)==null?void 0:u.incarnation,a.binding]);return{channel:c,events:a.events,snapshot:a.snapshot,frameAdmission:a.frameAdmission,fileSaveBinding:o,fileSaveObservation:s.documentId!==e||s.transport!==t||s.pending?"pending":a.available&&((d=a.binding)!=null&&d.verified)&&((f=a.snapshot)!=null&&f.incarnation)?"ready":"unavailable"}}function li(e){return{type:e.type,docSeq:e.docSeq,event:e.event}}function di(e,t){const r=e.indexOf("#"),n=r<0?e:e.slice(0,r),s=r<0?"":e.slice(r);return`${n}${n.includes("?")?"&":"?"}${us}=${t}${s}`}const fi={random:()=>Math.random(),schedule:(e,t)=>setTimeout(e,t),cancel:e=>clearTimeout(e)};function hi(e){const t=ae(),r=Wr(e.documentId),[n]=p.useState(()=>new dt),[s,i]=p.useState(null),[,a]=p.useState(0),c=JSON.stringify([e.documentId,e.logicalUrl,e.resolvedSource,e.reloadNonce,e.bridgeEligibility,e.previewOrigin]),o=e.bridgeEligibility==="served-document",u=p.useMemo(()=>o?crypto.randomUUID():null,[o,c]),d=JSON.stringify([c,u]),f=e.resolvedSource===null||u===null?e.resolvedSource:di(e.resolvedSource,u),l=p.useRef(null),g=p.useRef({params:e,doc:r,key:d,transport:t}),b=p.useRef(!1),m=p.useRef(0),v=(x,I="offline")=>{const M=x.link;x.link=null,M&&(M.hostClosed=!0,M.handshake.close(I)),n.retire()},N=()=>{var M,W;const x=l.current,{doc:I}=g.current;!(x!=null&&x.link)||I.channel.enabled&&((W=(M=I.channel).current)!=null&&W.call(M,"read"))||(v(x,"revoked"),x.tried=null)},T=()=>{var W,j,O;const x=(W=l.current)==null?void 0:W.link,{doc:I}=g.current,M=I.snapshot;if(!(!(x!=null&&x.live)||!M||!((O=(j=I.channel).current)!=null&&O.call(j,"read")))){for(const k of I.events)k.docSeq<=x.load.delivered||(x.handshake.publish({kind:"event",frame:li(k)}),x.load.delivered=k.docSeq);M.stateRev>x.stateRev&&(x.handshake.publish({kind:"state",state:M.state,stateRev:M.stateRev,docSeq:M.highWatermark,reset:M.resetRequired}),x.stateRev=M.stateRev)}},R=()=>{var w,C,U,G;const x=l.current,{params:I,doc:M,key:W,transport:j}=g.current,O=I.iframeRef.current,k=x==null?void 0:x.load,A=M.frameAdmission;if(!(x!=null&&x.active)||x.link||!k||x.boot!==null&&k!==x.firstLoad||x.key!==W||x.transport!==j||!I.resolvedSource||!I.bridgeEligibility||!(O!=null&&O.isConnected)||O.contentWindow!==k.frame||!A||!M.snapshot||!M.channel.enabled||!((C=(w=M.channel).current)!=null&&C.call(w,"read")))return;const q=[k,A,M.snapshot,x.invalidations];if(!((U=x.tried)!=null&&U.every((Z,se)=>Z===q[se]))){x.tried=q,b.current=!0;try{const Z=n.observeHostContext({frame:k.frame,documentId:I.documentId,resolvedSource:I.resolvedSource,logicalUrl:I.logicalUrl,reloadKey:`${I.reloadNonce}:${++m.current}`,sessionId:null,eligibility:I.bridgeEligibility,exactOrigin:I.bridgeEligibility==="served-document"?"null":I.previewOrigin,transportOwner:j,publisherEpoch:m.current}),se=Z&&((G=A.prepareFrameLoad(n,Z))==null?void 0:G.completeLoad()),je=se&&A.attachFrame(n,se);if(!je){n.retire();return}const Re={load:k,live:!1,hostClosed:!1,stateRev:-1,handshake:new ms(je,{nonce:()=>crypto.randomUUID(),channel:()=>new MessageChannel,scheduler:fi,boot:x.boot,offline:()=>{const fe=l.current;(fe==null?void 0:fe.link)!==Re||Re.hostClosed||!Re.live&&fe.everLive&&i({key:fe.key,transport:fe.transport})}})};x.link=Re,Re.handshake.start()}catch{x.link=null,n.retire()}finally{b.current=!1}}},z=(x,I,M)=>{let W=l.current;return(!W||W.key!==x||W.transport!==I)&&(W=l.current={key:x,transport:I,boot:M,active:!1,load:null,firstLoad:null,link:null,tried:null,invalidations:0,everLive:!1}),W.active=!0,R(),W},L=x=>{x.active=!1,v(x),x.tried=null},B=p.useRef({connect:R,disconnect:v,publish:T,enter:z,leave:L,revokeIfWithdrawn:N});p.useLayoutEffect(()=>{B.current={connect:R,disconnect:v,publish:T,enter:z,leave:L,revokeIfWithdrawn:N},g.current={params:e,doc:r,key:d,transport:t}}),p.useLayoutEffect(()=>{const x=B.current.enter(d,t,u);return()=>B.current.leave(x)},[d,t,u]),p.useLayoutEffect(()=>{const x=r.frameAdmission;if(x)return x.subscribeInvalidation(()=>{const I=l.current;b.current||!I||(B.current.disconnect(I),I.invalidations++,a(M=>M+1))})},[r.frameAdmission]),p.useLayoutEffect(()=>{const x=I=>{const M=l.current,W=M==null?void 0:M.link;!M||!W||W.hostClosed||!W.handshake.receive(I)||W.live||(W.live=!0,M.everLive=!0,i(null),B.current.publish())};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[]),p.useLayoutEffect(()=>{B.current.revokeIfWithdrawn(),B.current.connect(),B.current.publish()});const H=p.useCallback(x=>{var O;const I=l.current,M=x.contentWindow;if(!I||!M||x!==g.current.params.iframeRef.current)return;B.current.disconnect(I);const W={frame:M,delivered:0},j=((O=I.firstLoad)==null?void 0:O.frame)===M;I.load=W,j||(I.firstLoad=W),I.tried=null,j&&I.everLive&&I.boot!==null?i({key:I.key,transport:I.transport}):i(null),B.current.connect()},[]);return{frameSource:f,requiresReload:(s==null?void 0:s.key)===d&&s.transport===t,noteFrameLoaded:H}}function pi(e,t,r){return r!=null&&r.bridgeEligibility?e.mode==="serve"?t===null?null:{kind:"serve",cwd:t,path:e.path}:e.mode==="proxy"?{kind:"proxy",port:e.port,path:e.path}:null:null}function mi({iframeRef:e,target:t,cwd:r,resolved:n,reloadNonce:s}){const i=ae(),a=p.useRef(i);p.useEffect(()=>{a.current=i});const c=pi(t,r,n),o=c?JSON.stringify(c):null,u=o?`${o}
|
|
24
|
+
`||t.slice(12,16)!=="IHDR")return null;const r=i=>t.charCodeAt(i)*2**24+(t.charCodeAt(i+1)<<16)+(t.charCodeAt(i+2)<<8)+t.charCodeAt(i+3),n=r(16),s=r(20);return n>0&&s>0&&n<=1568&&s<=1568?{width:n,height:s}:null}catch{return null}}let xt=null;async function sr(){return xt===null&&(xt=(await _e(()=>import("./html-to-image-cl8bZGTj.js"),[])).default),xt}let kt=null;async function ns(){if(kt===null){const e=await _e(()=>import("./gifenc.esm-sOOlYEo8.js"),[]);kt={GIFEncoder:e.GIFEncoder,quantize:e.quantize,applyPalette:e.applyPalette}}return kt}async function ir(e,t,r=()=>{}){if(e.length===0)return{ok:!1,error:"The recording has no frames in it."};r();const{GIFEncoder:n,quantize:s,applyPalette:i}=await ns();r();const a=e[0],c=e[e.length-1],o=new Uint8ClampedArray(a.data.length+c.data.length);o.set(a.data,0),o.set(c.data,a.data.length);const u=s(o,256),d=n();for(let l=0;l<e.length;l++){r();const g=e[l];if(d.writeFrame(i(g.data,u),g.width,g.height,{...l===0?{palette:u,repeat:0}:{},delay:t.frameMs}),d.bytesView().byteLength>t.maxBytes)return{ok:!1,error:`The recording came out bigger than ${Math.round(t.maxBytes/1024/1024)} MB, so it was not saved.`}}d.finish();const f=d.bytes();return f.byteLength>t.maxBytes?{ok:!1,error:`The recording came out bigger than ${Math.round(t.maxBytes/1024/1024)} MB, so it was not saved.`}:{ok:!0,bytes:f}}async function ss(e,t,r=()=>{}){const n=[],s=document.createElement("canvas");let i=0,a=0;try{for(let c=0;c<Math.min(e.length,62);c++){r();const o=e[c];if(!Ar(o)){e[c]="";continue}const u=await os(o);e[c]="";try{if(r(),!u)continue;if(!i){const l=Math.min(1,Math.min(800,t)/Math.max(u.width,u.height,1));i=Math.max(1,Math.round(u.width*l)),a=Math.max(1,Math.round(u.height*l)),s.width=i,s.height=a}const d=s.getContext("2d",{willReadFrequently:!0});if(!d)return[];d.fillStyle="#ffffff",d.fillRect(0,0,i,a);const f=Math.min(i/u.width,a/u.height);d.drawImage(u,0,0,Math.round(u.width*f),Math.round(u.height*f)),r(),n.push({data:d.getImageData(0,0,i,a).data,width:i,height:a})}finally{u&&(u.src="")}}return n}catch(c){throw n.length=0,c}finally{e.length=0,s.width=0,s.height=0}}function is(e,t=()=>{}){const r=document.createElement("canvas"),n=document.createElement("canvas");try{for(let s=0;s<e.length;s++){t();const i=e[s];n.width=i.width,n.height=i.height,r.width=Math.max(1,Math.round(i.width/2)),r.height=Math.max(1,Math.round(i.height/2));const a=n.getContext("2d"),c=r.getContext("2d",{willReadFrequently:!0});if(!a||!c)throw new Error("Canvas pixels are unavailable");a.putImageData(new ImageData(new Uint8ClampedArray(i.data),i.width,i.height),0,0),c.drawImage(n,0,0,r.width,r.height),e[s]={data:c.getImageData(0,0,r.width,r.height).data,width:r.width,height:r.height}}}finally{n.width=n.height=r.width=r.height=0}}function os(e){return new Promise(t=>{const r=new Image;r.onload=()=>{r.onload=r.onerror=null,t(r)},r.onerror=()=>{r.onload=r.onerror=null,r.src="",t(null)},r.src=e})}function or(e,t,r){const n=r.slice().buffer;return{name:e,type:t,size:r.byteLength,arrayBuffer:async()=>n}}function as(e){const t=atob(e.slice(e.indexOf(",")+1));return Uint8Array.from(t,r=>r.charCodeAt(0))}const cs=8e3;function us(e){const t=ae(),r=p.useRef(t);p.useLayoutEffect(()=>{r.current=t});const[n]=Pt(),[s,i]=p.useState(0),a=p.useRef(null),c=p.useRef(new Map),o=p.useRef(null),u=p.useRef({console:[],network:[],entryBytes:0,overheadBytes:0}),d=p.useRef(null),f=p.useRef(-1),l=p.useRef(null),g=p.useRef(null),b=p.useRef(!1),m=p.useRef(-1/0),v=p.useRef(!1),N=p.useRef(null),A=p.useRef(0),R=p.useRef(null),z=p.useRef(null),L=p.useRef(!1),B=p.useRef(null),H=p.useRef({...e,sessionId:n}),x=p.useRef(Promise.resolve()),I=p.useRef(()=>{}),M=p.useRef({initialize:k,retire:E,consume:se,register:U,eligiblePending:Z,refuseRequest:C,live:w,captureFrame:yt,valid:fe,reportRecordingStart:je,cancelReservation:Re,finish:Vt});p.useLayoutEffect(()=>{M.current={initialize:k,retire:E,consume:se,register:U,eligiblePending:Z,refuseRequest:C,live:w,captureFrame:yt,valid:fe,reportRecordingStart:je,cancelReservation:Re,finish:Vt}});const W=S=>B.current===S||Y.getState().openDocuments.some(y=>y.id===S&&y.openedHere);function j(S,{active:y,activation:_=!1,keepalive:O=!1,reset:F=!1}){if(!S.sessionId)return;const re={documentId:S.documentId,logicalUrl:S.logicalUrl,bridgeGeneration:S.generation,seq:Math.max(0,f.current),console:[],network:[],active:y,activation:_,instrumented:S.ready&&!S.retired,...F?{reset:!0}:{}};x.current=x.current.then(()=>r.current.ingestDevtoolsCapture(S.sessionId,re,O?{keepalive:!0}:void 0)).catch(()=>{})}function E(){var _;const S=a.current;S&&(S.retired=!0),a.current=null,d.current!==null&&clearTimeout(d.current),d.current=null,o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0},f.current=-1,m.current=-1/0,v.current=!1;for(const[O,F]of c.current)F.life.sessionId&&F.deadline>Date.now()&&F.kind!=="frame"&&C(O,F.kind,F.life,"The frame changed while this request was pending."),clearTimeout(F.timer),(_=F.resolve)==null||_.call(F,null);c.current.clear(),S&&j(S,{active:!1});const y=N.current;y&&(clearTimeout(y.reservationTimer),y.cancelled=!0,y.abort.abort(),y.frames.length=0,y.finishing||(y.drawn.length=0,N.current=null)),R.current!==null&&cancelAnimationFrame(R.current),R.current=null,A.current=0,i(0)}function k({loadActivation:S,reset:y=!1}={}){var J,oe;const _=H.current,O=(J=_.iframeRef.current)==null?void 0:J.contentWindow;if(b.current||!O||!_.bridgeEligibility||!_.resolvedSource)return;const F={generation:crypto.randomUUID(),frame:O,sessionId:_.sessionId,documentId:_.documentId,logicalUrl:_.logicalUrl,source:_.resolvedSource,origin:_.bridgeEligibility==="served-document"?"null":_.previewOrigin,ready:!1,activation:!1,retired:!1};a.current=F;const re=S??(L.current||z.current!==F.documentId&&W(F.documentId));F.activation=re,L.current=!1,z.current=F.documentId,j(F,{active:!0,activation:re,reset:y}),((oe=l.current)==null?void 0:oe.frame)===O&&l.current.source===_.resolvedSource&&l.current.reload===_.reloadNonce&&l.current.documentId===_.documentId&&l.current.logicalUrl===_.logicalUrl&&O.postMessage({__dorkosDevtools:"init",bridgeGeneration:F.generation},"*")}p.useLayoutEffect(()=>{var O;H.current={...e,sessionId:n};const S={frame:(O=e.iframeRef.current)==null?void 0:O.contentWindow,sessionId:n,documentId:e.documentId,logicalUrl:e.logicalUrl,source:e.resolvedSource,eligibility:e.bridgeEligibility,origin:e.previewOrigin,reload:e.reloadNonce},y=g.current;if(!y||Object.keys(S).some(F=>S[F]!==y[F])){const F=!y||y.frame!==S.frame||y.documentId!==S.documentId||y.logicalUrl!==S.logicalUrl||y.source!==S.source||y.reload!==S.reload;g.current=S,b.current=!1,E(),k({reset:F})}});const T=p.useCallback(()=>{var re,J,oe;const{initialize:S,retire:y}=M.current,_=H.current,O=(re=_.iframeRef.current)==null?void 0:re.contentWindow,F=(J=a.current)!=null&&J.ready?!1:(oe=a.current)==null?void 0:oe.activation;O&&_.resolvedSource&&(l.current={frame:O,source:_.resolvedSource,reload:_.reloadNonce,documentId:_.documentId,logicalUrl:_.logicalUrl}),b.current=!1,y(),S({loadActivation:F,reset:!0})},[]),q=p.useCallback(()=>{const S=a.current;L.current=!0,B.current=H.current.documentId,S&&I.current({active:!0,activation:!0})},[]);p.useLayoutEffect(()=>{I.current=S=>{a.current&&j(a.current,S)}});function w(S){return a.current===S&&!S.retired}function C(S,y,_,O){if(!_.sessionId)return;const F={requestId:S,bridgeGeneration:_.generation,documentId:_.documentId,hostOutcome:"host",error:O};y==="action"?r.current.postDevtoolsAction(_.sessionId,{...F,ok:!1}).catch(()=>{}):r.current.ingestDevtoolsCapture(_.sessionId,{...F,logicalUrl:_.logicalUrl,seq:Math.max(0,f.current),console:[],network:[],screenshot:{requestId:S,error:O}}).catch(()=>{})}function U(S,y,_,{capture:O=!1,resolve:F,timeoutMs:re=8e3}={}){if(c.current.size>=Ie.pending||c.current.has(S))return null;const J=setTimeout(()=>G(S,oe),re),oe={kind:y,life:_,capture:O,deadline:Date.now()+re,timer:J,resolve:F};return c.current.set(S,oe),oe}function G(S,y){var _;c.current.get(S)===y&&(c.current.delete(S),clearTimeout(y.timer),(_=y.resolve)==null||_.call(y,null))}function Z(S,y,_){return c.current.get(S)!==y||y.life!==_||!w(_)?!1:Date.now()>=y.deadline?(G(S,y),!1):!0}function se(S,y,_){const O=c.current.get(S);return!O||O.life!==_||O.kind!==y&&!(y==="capture"&&O.kind==="frame")||!Z(S,O,_)?null:(c.current.delete(S),clearTimeout(O.timer),O)}p.useEffect(()=>{const{initialize:S,retire:y,consume:_}=M.current;function O(){d.current=null;const he=o.current;o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0};const D=a.current;he&&D&&!D.retired&&D.sessionId&&he.bridgeGeneration===D.generation&&r.current.ingestDevtoolsCapture(D.sessionId,he)}function F(he){var Zt,Xt,Yt,Qt;const D=a.current;if(!D||D.retired||he.source!==D.frame||he.origin!==D.origin||((Zt=l.current)==null?void 0:Zt.frame)!==D.frame||l.current.source!==D.source||l.current.reload!==H.current.reloadNonce||l.current.documentId!==D.documentId||l.current.logicalUrl!==D.logicalUrl)return;const P=he.data;if(!P||typeof P!="object"||typeof P.__dorkosDevtools!="string"||!["hello","ready","navigated","resource-error","batch","capture-result","act-result"].includes(P.__dorkosDevtools)||P.__dorkosDevtools!=="hello"&&P.bridgeGeneration!==D.generation)return;const ce=P.__dorkosDevtools==="batch";if(ce){if(!D.ready||!D.sessionId||P.bridgeGeneration!==D.generation||!Number.isSafeInteger(P.seq)||P.seq<0||P.seq<=f.current)return;const X=Date.now();if(X-m.current<Ie.batchMs){o.current?o.current.dropped=!0:v.current=!0;return}m.current=X}const V=rs(P);if(!V){ce&&(v.current=!0);return}if(V.__dorkosDevtools==="hello"){D.frame.postMessage({__dorkosDevtools:"init",bridgeGeneration:D.generation},"*");return}if(V.bridgeGeneration!==D.generation)return;if(V.__dorkosDevtools==="ready"){D.ready||(D.ready=!0,D.activation=!1,j(D,{active:!0}));return}if(!D.ready)return;if(V.__dorkosDevtools==="navigated"){b.current=!0,y();return}if(V.__dorkosDevtools==="resource-error"){A.current=Math.min(Ie.resourceErrors,A.current+1),R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null,w(D)&&i(A.current)}));return}if(!D.sessionId)return;if(V.__dorkosDevtools==="batch"){if(V.seq<=f.current)return;f.current=V.seq;const X=o.current??{documentId:D.documentId,logicalUrl:D.logicalUrl,bridgeGeneration:D.generation,seq:V.seq,console:[],network:[]};X.seq=V.seq,v.current&&(X.dropped=!0),v.current=!1;const Ee=u.current,Kt=new TextEncoder;if(o.current||(Ee.overheadBytes=Kt.encode(JSON.stringify({...X,seq:Number.MAX_SAFE_INTEGER,dropped:!0,console:[],network:[]})).length),Ee.overheadBytes>Ie.queueBytes){o.current=null,u.current={console:[],network:[],entryBytes:0,overheadBytes:0},v.current=!0;return}for(const[Le,sn]of[["console",V.console],["network",V.network]])for(const on of sn){const er=Kt.encode(JSON.stringify(on)).length;Ee[Le].push(er),Ee.entryBytes+=er}X.console.push(...V.console),X.network.push(...V.network);const nn=()=>Ee.overheadBytes+Ee.entryBytes+Math.max(0,X.console.length-1)+Math.max(0,X.network.length-1);for(;X.console.length>500||X.network.length>200||nn()>Ie.queueBytes;){X.dropped=!0;const Le=(((Xt=X.console[0])==null?void 0:Xt.timestamp)??1/0)<=(((Yt=X.network[0])==null?void 0:Yt.timestamp)??1/0)?"console":"network";if(!X[Le].length)break;X[Le].shift(),Ee.entryBytes-=Ee[Le].shift()}o.current=X,d.current===null&&(d.current=setTimeout(O,Ie.batchMs));return}if(V.__dorkosDevtools==="capture-result"){const X=_(V.requestId,"capture",D);if(!X)return;if(X.kind==="frame"){(Qt=X.resolve)==null||Qt.call(X,V.dataUrl??null);return}r.current.ingestDevtoolsCapture(D.sessionId,{bridgeGeneration:D.generation,documentId:D.documentId,logicalUrl:D.logicalUrl,seq:Math.max(0,f.current),console:[],network:[],hostOutcome:"page-reported",screenshot:{requestId:V.requestId,dataUrl:V.dataUrl,error:V.error}});return}const qe=_(V.requestId,"action",D);if(!qe)return;const De=N.current,Jt=qe.capture&&V.dataUrl!==void 0&&De!==null&&De.life===D&&De.activated&&!De.finishing&&!De.cancelled&&De.frames.length<61;Jt&&De.frames.push(V.dataUrl);const{__dorkosDevtools:Uo,dataUrl:Wo,...rn}=V;r.current.postDevtoolsAction(D.sessionId,{...rn,hostOutcome:"page-reported",documentId:D.documentId,captured:Jt||void 0})}window.addEventListener("message",F);const re=setInterval(()=>I.current({active:!0}),15e3),J=()=>{a.current||S(),I.current({active:!0,activation:!0})},oe=()=>{I.current({active:!1,keepalive:!0}),y()},ue=()=>{document.visibilityState==="visible"&&J()};return window.addEventListener("focus",J),window.addEventListener("pagehide",oe),window.addEventListener("pageshow",J),document.addEventListener("visibilitychange",ue),()=>{window.removeEventListener("message",F),clearInterval(re),window.removeEventListener("focus",J),window.removeEventListener("pagehide",oe),window.removeEventListener("pageshow",J),document.removeEventListener("visibilitychange",ue),y()}},[]),p.useEffect(()=>pn.subscribeSessionEvent((S,y)=>{if(y.type!=="devtools_capture_request"&&y.type!=="devtools_action_request"&&y.type!=="devtools_recording_request")return;const{register:_,eligiblePending:O,refuseRequest:F,captureFrame:re,valid:J,finish:oe,reportRecordingStart:ue,cancelReservation:he}=M.current,D=a.current;if(!(!(D!=null&&D.ready)||!D.sessionId||D.retired||y.targetClientId!==r.current.clientId||y.documentId!==D.documentId||y.bridgeGeneration!==D.generation)){if(y.type==="devtools_capture_request"||y.type==="devtools_action_request"){const P=y.type==="devtools_action_request",ce=_(y.requestId,P?"action":"capture",D,{capture:P&&!!y.capture,timeoutMs:P&&y.command.action==="wait_for"?Math.min(1e4,y.command.timeoutMs)+2e3:8e3});if(!ce){c.current.has(y.requestId)||F(y.requestId,P?"action":"capture",D,"Too many browser requests are waiting. Try again when one finishes.");return}const V=qe=>{O(y.requestId,ce,D)&&D.frame.postMessage(P?{__dorkosDevtools:"act-request",bridgeGeneration:D.generation,requestId:y.requestId,documentId:D.documentId,command:y.command,...y.capture?{capture:!0,lib:qe}:{}}:{__dorkosDevtools:"capture-request",bridgeGeneration:D.generation,requestId:y.requestId,lib:qe},"*")};!P||y.capture?sr().then(V,()=>V()):V()}if(y.type==="devtools_recording_request"){if(y.action==="cancel-start"){he(y.recordingId,y.requestId,D);return}if(y.action==="confirm-start"){const P=N.current;if(!P||P.id!==y.recordingId||P.startRequestId!==y.requestId||P.life!==D||P.finishing||!J(P))return;if(!P.activated){if(performance.now()>=P.reservationDeadline){he(P.id,P.startRequestId,D),ue(y,D,{phase:"started",ok:!1,error:"This recording reservation expired before capture could start."});return}clearTimeout(P.reservationTimer),P.activated=!0,P.startedAt=Date.now(),re(D).then(ce=>{ce&&J(P)&&P.frames.push(ce)})}ue(y,D,{phase:"started",ok:!0});return}if(y.action==="start"){const P=y.reservationTimeoutMs;if(!Number.isSafeInteger(P)||!P||P<1||P>cs){ue(y,D,{phase:"reserved",ok:!1,error:"This recording request has no valid reservation timeout."});return}if(N.current){ue(y,D,{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 ce={id:y.recordingId,startRequestId:y.requestId,activated:!1,reservationDeadline:performance.now()+P,life:D,startedAt:Date.now(),frames:[],drawn:[],finishing:!1,cancelled:!1,abort:new AbortController};N.current=ce,ce.reservationTimer=setTimeout(()=>{N.current===ce&&!ce.activated&&he(ce.id,ce.startRequestId,D)},P),ue(y,D,{phase:"reserved",ok:!0})}else oe(y.requestId,y.recordingId,D)}}}),[]);function je(S,y,_){!w(y)||!y.sessionId||r.current.ingestDevtoolsCapture(y.sessionId,{hostOutcome:"host",documentId:y.documentId,bridgeGeneration:y.generation,seq:0,console:[],network:[],recordingStart:{..._,requestId:S.requestId,recordingId:S.recordingId}}).catch(()=>{})}function Re(S,y,_){var F;const O=N.current;if(!(!O||O.id!==S||O.startRequestId!==y||O.life!==_||O.finishing)){clearTimeout(O.reservationTimer),O.cancelled=!0,O.abort.abort(),O.frames.length=0,O.drawn.length=0;for(const[re,J]of c.current)J.life===_&&J.kind==="frame"&&(clearTimeout(J.timer),(F=J.resolve)==null||F.call(J,null),c.current.delete(re));N.current=null}}function fe(S){return N.current===S&&!S.cancelled&&w(S.life)}function yt(S){const y=`frame-${crypto.randomUUID()}`;return new Promise(_=>{const O=U(y,"frame",S,{resolve:_});if(!O){_(null);return}sr().then(F=>{Z(y,O,S)&&S.frame.postMessage({__dorkosDevtools:"capture-request",bridgeGeneration:S.generation,requestId:y,lib:F},"*")},()=>{G(y,O)})})}async function Vt(S,y,_){const O=N.current;if(!O||!O.activated||O.id!==y||O.life!==_){w(_)&&await r.current.uploadDevtoolsRecording(_.sessionId,{requestId:S,bridgeGeneration:_.generation,documentId:_.documentId,hostOutcome:"host",error:"The window showing that page stopped recording before it could be saved."}).catch(()=>{});return}if(O.finishing)return;O.finishing=!0;const F=()=>{if(!fe(O))throw new Error("retired")},re={requestId:S,bridgeGeneration:_.generation,documentId:_.documentId};try{const J=await yt(_);F(),J&&O.frames.length<Ie.frames&&O.frames.push(J);const oe=O.frames.length?as(O.frames[O.frames.length-1]):new Uint8Array;O.drawn=await ss(O.frames,800,F),F();let ue=await ir(O.drawn,{frameMs:500,maxBytes:8*1024*1024},F);if(F(),!ue.ok&&O.drawn.length&&(is(O.drawn,F),ue=await ir(O.drawn,{frameMs:500,maxBytes:8*1024*1024},F),F()),!ue.ok){await r.current.uploadDevtoolsRecording(_.sessionId,{...re,hostOutcome:"host",error:ue.error},{signal:O.abort.signal}),F();return}F(),await r.current.uploadDevtoolsRecording(_.sessionId,{...re,frames:O.drawn.length,durationMs:Date.now()-O.startedAt,recording:or(`${y}.gif`,"image/gif",ue.bytes),keyframe:or(`${y}.png`,"image/png",oe)},{signal:O.abort.signal}),F()}catch{fe(O)&&await r.current.uploadDevtoolsRecording(_.sessionId,{...re,hostOutcome:"host",error:"This window could not turn that recording into a file."},{signal:O.abort.signal}).catch(()=>{})}finally{O.frames.length=0,O.drawn.length=0,N.current===O&&(N.current=null)}}return{resourceErrorCount:s,notePersonNavigated:q,noteFrameLoaded:T}}const ze=le().min(1).max(128),me={protocol:te("dorkos-doc"),v:te(1),nonce:ze,requestToken:ze,loadToken:ct,generation:Er.shape.generation},ls="dorkos-boot",ar=vt("kind",[K({...me,kind:te("challenge")}).strict(),K({...me,kind:te("ack"),boot:ze.optional()}).strict(),K({...me,kind:te("connect")}).strict()]),ds=K({type:te("canvas_event"),docSeq:ct,event:gn}).strict(),fs=vt("kind",[K({...me,kind:te("emit"),requestId:ze,event:Qe}).strict(),K({...me,kind:te("retire")}).strict()]),hs=vt("kind",[K({...me,kind:te("receipt"),requestId:ze,receipt:Bt}).strict(),K({...me,kind:te("refused"),requestId:ze,outcome:rr(["cancelled","unconfirmed","refused"])}).strict(),K({...me,kind:te("state"),state:vn,stateRev:ct,docSeq:ct,reset:ut()}).strict(),K({...me,kind:te("event"),frame:ds}).strict(),K({...me,kind:te("status"),status:rr(["connecting","ready","offline","revoked"]),unconfirmed:ut()}).strict()]);function Je(e,t){try{if(mn(t,1048576)!==void 0)return null;const r=e.safeParse(t);return r.success?r.data:null}catch{return null}}var ve,Dt,He;class dt{constructor(){Be(this,ve);$(this,"current",null);$(this,"token",0);$(this,"retiring",!1);$(this,"subscribers",new Set);$(this,"resources",new Map);$(this,"doc",null);$(this,"docClaims",new WeakMap);$(this,"retiringDoc",!1);$(this,"docResources",new Map);$(this,"bindings",new WeakSet)}getCurrent(){return this.current}observeHostContext(t){if(this.retiring)return null;if(!t.transportOwner||typeof t.transportOwner!="object"||!Number.isSafeInteger(t.publisherEpoch)||t.publisherEpoch<0)throw new Error("Explicit transport owner and epoch required.");const r=["frame","documentId","resolvedSource","logicalUrl","reloadKey","sessionId","eligibility","exactOrigin","transportOwner","publisherEpoch"];if(r.some(s=>!Object.hasOwn(t,s))||typeof t.documentId!="string"||!t.documentId||typeof t.logicalUrl!="string"||typeof t.reloadKey!="string")throw new Error("Complete host context required.");const n=this.current;return n&&r.every(s=>Object.is(n[s],t[s]))?n:(this.retire(),this.current=Object.freeze({...t,token:this.token,loaded:!1}),this.current)}observeLoaded(t){return this.retiring||this.current!==t||!t.frame?null:(this.retire(),this.current=Object.freeze({...t,token:this.token,loaded:!0}),this.current)}retire(){if(this.retiring)return;const t=this.current;this.current=null;const r=this.doc;this.doc=null,this.token++,this.retiring=!0;const n=[...t?this.resources.get(t)??[]:[],...r?this.docResources.get(r)??[]:[],...this.subscribers];r&&this.docResources.delete(r),t&&this.resources.delete(t);try{for(const s of n)try{const i=s();i&&typeof i.then=="function"&&Promise.resolve(i).catch(()=>{})}catch{}}finally{this.retiring=!1}}subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}own(t,r){if(this.retiring||this.current!==t)throw new Error("Frame observation retired.");const n=this.resources.get(t)??new Set;return n.add(r),this.resources.set(t,n),()=>{n.delete(r)}}bindDoc(t,r,n){return ye(this,ve,Dt).call(this,t,r,n)}acquireDoc(t,r,n){const s=ye(this,ve,Dt).call(this,t,r,n),i=Object.freeze({});this.docClaims.set(s,i);let a=!1;return Object.freeze({binding:s,release:()=>{a||(a=!0,this.docClaims.get(s)===i&&(this.docClaims.delete(s),this.doc===s&&this.bindings.has(s)&&ye(this,ve,He).call(this)))}})}disableDoc(){ye(this,ve,He).call(this)}retireDoc(t){this.doc===t&&this.bindings.has(t)&&ye(this,ve,He).call(this)}ownDoc(t,r){if(!this.isCurrent(t))throw new Error("Doc binding retired.");const n=this.docResources.get(t)??new Set;return n.add(r),this.docResources.set(t,n),()=>{n.delete(r)}}isCurrent(t){return!this.retiring&&!this.retiringDoc&&this.doc===t&&this.bindings.has(t)&&this.current===t.observation}}ve=new WeakSet,Dt=function(t,r,n){const s=this.doc,i=this.token,a=Je(Er,r);if(!a)throw this.disableDoc(),new Error("Established server Doc birth required.");const c=a,o=t.exactOrigin,u=t.eligibility==="served-document"?o==="null":t.eligibility==="preview-listener"&&o!==null&&new URL(o).origin===o;if(!t.loaded||!t.frame||typeof t.frame.postMessage!="function"||!t.resolvedSource||!u||t.documentId!==c.documentId||!n||n.length>200)throw new Error("Loaded eligible frame and established Doc birth required.");if(this.retiring||this.retiringDoc||this.current!==t||this.doc!==s||this.token!==i)throw new Error("Frame observation retired during Doc admission.");if(this.doc){if(this.doc.observation!==t)throw new Error("Doc binding belongs to another host load.");if(Q(this.doc.incarnation,c)&&this.doc.scope===n)return this.doc;throw this.retire(),new Error("Doc birth changed; a fresh host load is required.")}const d=Object.freeze({observation:t,incarnation:Object.freeze(c),scope:n});try{return this.doc=d,this.bindings.add(d),d}catch(f){throw this.doc===d&&ye(this,ve,He).call(this),f}},He=function(){if(this.retiringDoc)return;const t=this.doc;this.doc=null,this.retiringDoc=!0;const r=[...t?this.docResources.get(t)??[]:[]];t&&this.docResources.delete(t);try{for(const n of r)try{const s=n();s&&typeof s.then=="function"&&Promise.resolve(s).catch(()=>{})}catch{}}finally{this.retiringDoc=!1}};function ps(e,t,r){if(!r||typeof r.captureOriginal!="function"||typeof r.submit!="function"||typeof r.inspect!="function"||typeof r.isCurrentOwner!="function"||r.owner!==t.observation.transportOwner||r.publisherEpoch!==t.observation.publisherEpoch)throw new Error("Explicit current transport submit and inspect ports required.");const{owner:n,publisherEpoch:s,isCurrentOwner:i,submit:a,inspect:c,captureOriginal:o}=r,u=Object.freeze({expectedGeneration:t.incarnation.generation}),d=()=>{try{return e.isCurrent(t)?i(n,s)===!0&&e.isCurrent(t):!1}catch{return!1}};if(!d())throw new Error("Doc binding unavailable.");const f=()=>{if(!d())throw new Error("Doc binding retired.")};return Object.freeze({binding:t,current:d,captureOriginal:l=>{f();const g=l.id;f();const b=l.bytes;f();const m=Reflect.apply(o,r,[Object.freeze({id:g,bytes:b})]);if(f(),!m)return null;const v=m.id;f();const N=m.bytes;f();const A=m.submit;f();const R=m.inspect;return f(),v!==g||N!==b||typeof A!="function"||typeof R!="function"?null:Object.freeze({id:g,bytes:b,submit:async z=>{f(),z.throwIfAborted();const L=await Reflect.apply(A,m,[z]);return f(),z.throwIfAborted(),L},inspect:async z=>{f(),z.throwIfAborted();const L=await Reflect.apply(R,m,[z]);return f(),z.throwIfAborted(),L}})},retireObservation:()=>{d()&&e.retire()},onRetire:l=>e.ownDoc(t,l),submit:(l,g)=>(f(),g.throwIfAborted(),a(l,u,g)),inspect:(l,g)=>(f(),g.throwIfAborted(),c(l,u,g))})}function cr(e,t){const r=Je(Bt,t);return r&&r.receipt.id===e&&r.receipt.docSeq>0?r:null}class ms{constructor(t,r){$(this,"entries",new Map);$(this,"bytes",0);$(this,"running",!1);$(this,"retired",!1);$(this,"abort",new AbortController);$(this,"timer");$(this,"wake",null);$(this,"detach");if(this.port=t,this.scheduler=r,!t.current()||!r||["schedule","cancel","random"].some(n=>typeof r[n]!="function"))throw new Error("Current bound Doc port and scheduler required.");this.detach=t.onRetire(()=>this.retire())}getStatus(){return Object.freeze({pending:[...this.entries.values()].filter(t=>!t.settled).length,bytes:this.bytes,unconfirmed:[...this.entries.values()].filter(t=>t.unconfirmed).length,retired:this.retired})}emit(t){if(!this.live())return Promise.resolve({kind:"cancelled"});const r=Qe.safeParse(t);if(!r.success)return Promise.resolve({kind:"refused"});if(!this.live())return Promise.resolve({kind:"cancelled"});const n=JSON.stringify(r.data),s=r.data.id,i=this.entries.get(s);if(i)return i.bytes===n?i.promise:Promise.resolve({kind:"refused"});const a=new TextEncoder().encode(JSON.stringify({bytes:n,id:s,birth:this.port.binding.incarnation,scope:this.port.binding.scope,loadToken:this.port.binding.observation.token,publisherEpoch:this.port.binding.observation.publisherEpoch,sent:!1,settled:!1,unconfirmed:!1,attempts:8,retryAfterMs:3e4})).byteLength+1024;for(const u of this.entries.values()){if(this.entries.size<100&&this.bytes+a<=1048576)break;u.settled&&!u.unconfirmed&&(this.entries.delete(u.id),this.bytes-=u.weight)}if(this.entries.size>=100||this.bytes+a>1048576)return Promise.resolve({kind:"refused"});let c;const o=new Promise(u=>{c=u});return this.entries.set(s,{id:s,bytes:n,weight:a,sent:!1,settled:!1,unconfirmed:!1,resolve:c,promise:o}),this.bytes+=a,this.pump(),o}retire(){var t,r;if(!this.retired){if(this.retired=!0,this.abort.abort(),this.timer!==void 0)try{this.scheduler.cancel(this.timer)}catch{}this.timer=void 0,(t=this.wake)==null||t.call(this),this.wake=null;for(const n of this.entries.values())this.settle(n,{kind:n.sent?"unconfirmed":"cancelled"});this.entries.clear(),this.bytes=0,(r=this.detach)==null||r.call(this)}}settle(t,r){t.settled||(t.settled=!0,t.unconfirmed=r.kind==="unconfirmed",t.resolve(r),r.kind!=="unconfirmed"&&r.kind!=="accepted"&&(this.entries.delete(t.id),this.bytes-=t.weight))}live(){return this.retired||this.abort.signal.aborted?!1:this.port.current()&&!this.retired&&!this.abort.signal.aborted}cancel(t){try{t!==void 0&&this.scheduler.cancel(t)}catch{}}async wait(t){if(!this.live()){this.retire();return}await new Promise(r=>{let n=!1,s;const i=()=>{n||(n=!0,this.wake===i&&(this.wake=null),r())};this.wake=i;try{if(s=this.scheduler.schedule(()=>{this.timer===s&&(this.timer=void 0),i()},t),!this.live()||n){this.cancel(s),i(),this.live()||this.retire();return}this.timer=s}catch{i(),this.retire()}})}async call(t,r){if(!this.live())return this.retire(),r;const n=new AbortController;let s=()=>{},i;const a=()=>{n.abort(),this.cancel(i),s(r)};this.abort.signal.addEventListener("abort",a,{once:!0});try{return await new Promise(c=>{let o=!1;if(s=u=>{o||(o=!0,c(u))},i=this.scheduler.schedule(()=>{n.abort(),s(r)},15e3),!this.live()||this.abort.signal.aborted||n.signal.aborted||o){a(),this.live()||this.retire();return}try{Promise.resolve(t(n.signal)).then(s,()=>s(r))}catch{s(r)}})}finally{this.abort.signal.removeEventListener("abort",a),this.cancel(i)}}async pump(){if(!this.running){this.running=!0;try{for(const t of this.entries.values()){if(t.settled)continue;let r=!1;for(let n=0;n<8&&!t.settled;n++){if(!this.live()){this.retire();break}if(!t.original&&(t.original=this.port.captureOriginal(Object.freeze({id:t.id,bytes:t.bytes}))??void 0,!t.original||!this.live())){this.settle(t,{kind:t.sent?"unconfirmed":"refused"});break}const s=t.original;if(r){let o;try{o=await this.call(u=>s.inspect(u),{kind:"unknown"})}catch{this.settle(t,{kind:"unconfirmed"});break}if(!this.live()){this.retire();break}if(o.kind==="accepted"){const u=cr(t.id,o.receipt);this.settle(t,u?{kind:"accepted",receipt:u}:{kind:"unconfirmed"});break}if(o.kind!=="absent"){this.settle(t,{kind:"unconfirmed"}),o.kind==="terminal"&&this.retire();break}}t.sent=!0;let i;try{i=await this.call(o=>s.submit(o),{kind:"uncertain"})}catch{i={kind:"uncertain"}}if(!this.live()){this.retire();break}if(i.kind==="accepted"){const o=cr(t.id,i.receipt);this.settle(t,o?{kind:"accepted",receipt:o}:{kind:"unconfirmed"});break}if(i.kind==="terminal"){this.settle(t,{kind:"unconfirmed"}),this.retire();break}r=!0;const a=this.scheduler.random();if(!this.live()||t.settled){this.retire();break}const c=i.kind==="retry"&&Number.isFinite(i.retryAfterMs)?Math.max(0,Math.min(3e4,i.retryAfterMs)):500;await this.wait(c+Math.floor(Math.max(0,Math.min(1,Number.isFinite(a)?a:0))*250))}t.settled||this.settle(t,{kind:"unconfirmed"})}}catch{this.retire()}finally{this.running=!1}}}}class gs{constructor(t,r){$(this,"challenge");$(this,"queue");$(this,"detach");$(this,"timer");$(this,"port",null);$(this,"connected",!1);$(this,"closed",!1);$(this,"started",!1);$(this,"pending",new Map);if(this.bound=t,this.ports=r,!t.current()||typeof(r==null?void 0:r.nonce)!="function"||typeof r.channel!="function"||typeof r.offline!="function")throw new Error("Current loaded Doc binding and explicit handshake ports required.");if(t.binding.observation.eligibility==="served-document"?typeof r.boot!="string"||r.boot.length===0:r.boot!==null)throw new Error("A served document needs its boot nonce; a preview has none.");this.challenge=ar.parse({protocol:"dorkos-doc",v:1,kind:"challenge",nonce:r.nonce(),requestToken:r.nonce(),loadToken:t.binding.observation.token,generation:t.binding.incarnation.generation}),this.queue=new ms(t,r.scheduler),this.detach=t.onRetire(()=>this.close())}start(){if(!this.bound.current()||this.closed||this.started)return;this.started=!0;const t=this.bound.binding.observation;try{const r=this.ports.scheduler.schedule(()=>{this.close()},5e3);if(!this.bound.current()||this.closed){try{this.ports.scheduler.cancel(r)}finally{this.close()}return}this.timer=r,t.frame.postMessage(this.challenge,t.exactOrigin==="null"?"*":t.exactOrigin)}catch{this.close()}}receive(t){if(!this.started||this.closed||!this.bound.current()||t.source!==this.bound.binding.observation.frame||t.origin!==this.bound.binding.observation.exactOrigin||t.ports.length!==0)return!1;const r=Je(ar,t.data);if(!r||r.kind!=="ack"||!this.matches(r)||!this.booted(r))return!1;if(this.connected)return!0;this.connected=!0;let n;const s=()=>this.bound.current()&&!this.closed,i=()=>{for(const a of["port1","port2"])try{n==null||n[a].close()}catch{}return this.close(),!1};try{if(this.timer!==void 0&&this.ports.scheduler.cancel(this.timer),this.timer=void 0,!s()||(n=this.ports.channel(),!s())||(this.port=n.port1,this.port.onmessage=a=>{a.ports.length||this.command(a.data)},!s())||(this.port.start(),!s())||(this.bound.binding.observation.frame.postMessage({...this.challenge,kind:"connect"},this.bound.binding.observation.exactOrigin==="null"?"*":this.bound.binding.observation.exactOrigin,[n.port2]),!s()))return i()}catch{return i()}return!0}publish(t){this.send({...t,...this.challenge,kind:t.kind})}close(t="offline"){var r,n,s;if(!this.closed){this.closed=!0;try{(r=this.port)==null||r.postMessage({...this.challenge,kind:"status",status:t,unconfirmed:!0})}catch{}try{this.queue.retire()}catch{}try{this.timer!==void 0&&this.ports.scheduler.cancel(this.timer)}catch{}this.timer=void 0;try{(n=this.port)==null||n.close()}catch{}this.port=null,this.pending.clear(),(s=this.detach)==null||s.call(this);try{this.ports.offline()}catch{}}}matches(t){return t.nonce===this.challenge.nonce&&t.requestToken===this.challenge.requestToken&&t.loadToken===this.challenge.loadToken&&t.generation===this.challenge.generation}booted(t){return this.ports.boot===null||t.boot===this.ports.boot}send(t){var r;if(!this.closed&&this.connected&&this.bound.current()){const n=Je(hs,t);if(n)try{(r=this.port)==null||r.postMessage(n)}catch{this.close()}}}command(t){if(this.closed||!this.connected||!this.bound.current())return;const r=Je(fs,t);if(!(!r||!this.matches(r))){if(r.kind==="retire"){this.bound.retireObservation(),this.close();return}this.pending.has(r.requestId)||this.pending.size>=100||(this.pending.set(r.requestId,r.event.id),this.queue.emit(r.event).then(n=>{!this.bound.current()||this.closed||this.pending.get(r.requestId)!==r.event.id||(this.pending.delete(r.requestId),this.send(n.kind==="accepted"?{...this.challenge,kind:"receipt",requestId:r.requestId,receipt:n.receipt}:{...this.challenge,kind:"refused",requestId:r.requestId,outcome:n.kind}))}))}}}class vs{constructor(){$(this,"contiguous",0);$(this,"through",0);$(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(t){this.contiguous=Math.max(this.contiguous,t)}markThrough(t){this.through=Math.max(this.through,t)}recordGap(t){return this.markThrough(t.docSeq),this.pending.set(t.docSeq,t),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 t=this.contiguous+1,r=this.pending.get(t);return r&&this.pending.delete(t),r}clearReachedTarget(){return this.contiguous<this.through?!1:(this.through=0,!0)}}const It=new WeakMap,rt=new WeakMap,ke=new WeakMap,Ze=new WeakMap;function Se(e){Me(e);const t=It.get(e);if(!t)throw new Error("Replay owner lifetime is absent.");return t}function bs(e,t){const r=rt.get(t);if(!r||r.owner!==e)throw new Error("Replay run is foreign.");return r}function Tr(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){for(const t of Object.values(e))Tr(t);Object.freeze(e)}return e}function ys(e){if(Me(e),It.has(e))throw new Error("Replay owner lifetime is already initialized.");It.set(e,new vs)}function Wt(e){const t=Se(e);return Object.freeze({highest:t.highest,through:t.catchUpThrough,pending:t.pendingCount})}function ur(e){Se(e).reset()}function lr(e,t){const r=rt.get(t);if(!(!r||r.owner!==e))return Object.freeze({subject:r.subject,epoch:r.epoch,revision:r.revision,observation:r.observation,ended:r.ended})}function ws(e,t,r){const n=ke.get(r),s=rt.get(t);if(!(!s||s.owner!==e||!n||n.owner!==e||n.run!==t||n.phase!=="consuming"||n.admissionRead||!ie(e,t)))return n.admissionRead=!0,Object.freeze({response:n.response,since:n.since,revision:n.revision,observation:n.observation,targetBirth:s.targetBirth})}function xs(e,t,r){const n=bs(e,t),s=ke.get(r),i=Lr(e,t,r);if(!i||!s||s.owner!==e||s.run!==t||s.phase!=="consuming"||!s.admissionRead||n.ended||n.epoch!==i.epoch||n.subject!==i.previous)throw new Error("Replay own issuance is foreign or stale.");n.subject=i.subject}function Mr(e,t,r,n){if(!ie(e,t))return;if(n){const i=Ze.get(r);return i&&i.owner===e&&i.run===t&&i.phase==="dispatching"&&!i.advanced?i.frame:void 0}const s=ke.get(r);return s&&s.owner===e&&s.run===t&&s.phase==="frames"&&s.dispatching!==void 0&&!s.advanced?s.frames[s.dispatching]:void 0}function ks(e,t,r,n){const s=Js(e,t,r,n);if(!s||!ie(e,t))throw new Error("Replay cursor advance has no genuine core witness.");const i=n?Ze.get(r):ke.get(r);if(!i||i.advanced)throw new Error("Replay frame advance was consumed.");i.advanced=!0,Se(e).advance(s.docSeq)}function Cs(e,t){const r=rt.get(t),n=(r==null?void 0:r.lastPage)&&ke.get(r.lastPage);if(!r||r.owner!==e||!ie(e,t)||r.target===void 0||!n||n.phase!=="finished"||n.next!==n.frames.length||n.response.events.length>=200&&Se(e).highest<r.target)return;const s=Se(e);return Object.freeze({highest:s.highest,through:s.catchUpThrough,target:r.target})}function js(e,t){const r=et(e,t);if(!r)throw new Error("Replay notice is foreign or stale.");const n=Se(e),s=r.notification;if(r.mode==="quarantine")n.markThrough(s.type==="canvas_channel_snapshot"?s.snapshot.highWatermark:s.docSeq),s.type!=="canvas_channel_snapshot"&&n.recordGap(s);else{if(r.mode==="gap"&&s.type!=="canvas_channel_snapshot")return n.recordGap(s);r.mode==="event"&&ai(e,t)}return!1}function Rs(e,t){const r=et(e,t);if(!r||r.mode!=="event"||r.notification.type==="canvas_channel_snapshot")throw new Error("Notice cursor advance is foreign.");Se(e).advance(r.notification.docSeq)}function Es(e){const t=de(e),r=Se(e),n=Object.freeze({}),s={owner:e,subject:t.subject,epoch:t.epoch,revision:t.revision,observation:t.observation,ended:!1,starting:r.highest,succeeded:!1};rt.set(n,s),Qs(e,n);const i=()=>ie(e,n),a=()=>de(e).live?i()?void 0:"restart":"stop";return Object.freeze({async readPage(){if(!i())return null;const c=de(e),o=r.highest,u=bt(e),d=u.getCanvasChannel;if(!i())return null;const f=await d.call(u,t.documentId,{since:o,limit:200});if(!i())return null;const l=Tr(bn.parse(f));if(!i())return null;const g=Object.freeze({});return ke.set(g,{owner:e,run:n,response:l,since:o,revision:c.revision,observation:c.observation,phase:"read",admissionRead:!1,frames:[],next:0,advanced:!1}),g},consumePage(c){const o=ke.get(c);return!i()||!o||o.owner!==e||o.run!==n||o.phase!=="read"?{kind:"done"}:(o.phase="consuming",Ks(e,n,c)!=="accepted"||!i()?(o.phase="finished",{kind:"done"}):(s.target??(s.target=o.response.highWatermark),s.targetBirth=o.response.incarnation,o.frames=Object.freeze(o.response.events.filter(d=>d.docSeq<=s.target)),o.phase="frames",s.lastPage=c,o.response.resetRequired&&r.advance(o.response.retentionFloor-1),{kind:"frames",count:o.frames.length}))},advancePageFrame(c,o){const u=ke.get(c);if(!i()||!u||u.owner!==e||u.run!==n||u.phase!=="frames"||o!==u.next||!u.frames[o])return!1;u.next=o+1,u.dispatching=o,u.advanced=!1;try{return fr(e,n,c,!1)&&i()}finally{u.dispatching=void 0}},finishPage(c){const o=ke.get(c);if(!i()||!o||o.owner!==e||o.run!==n||o.phase!=="frames"||o.next!==o.frames.length||s.target===void 0)return"done";if(o.phase="finished",o.response.events.length<200||r.highest>=s.target)return r.advance(s.target),!i()||(hr(e,n),!i())||(s.succeeded=!0),"done";if(r.highest<=o.since)throw new Error("Document replay made no progress.");return"again"},failed(){i()&&ei(e,n)},beginFinalization(){return a()??(s.succeeded?"drain":"stop")},takePending(){if(!i())return null;const c=r.takeNextContiguous();if(!c||!i())return null;const o=Object.freeze({});return Ze.set(o,{owner:e,run:n,frame:c,phase:"taken",advanced:!1}),o},advancePending(c){const o=Ze.get(c);if(!i()||!o||o.owner!==e||o.run!==n||o.phase!=="taken")return!1;o.phase="dispatching";try{return fr(e,n,c,!0)&&i()}finally{o.phase="finished",Ze.delete(c)}},finishFinalization(){const c=a();if(c)return c;if(r.clearReachedTarget()){const o=a();if(o)return o;hr(e,n);const u=a();if(u)return u}if(r.pendingCount||r.catchUpThrough>r.highest){const o=de(e);if(r.highest>s.starting||o.revision>s.revision||o.observation>s.observation)return"restart";ti(e,n)}return a()??"stop"},current:i,end:()=>{s.ended=!0}})}class Os{constructor(){$(this,"revision",0);$(this,"draining",!1);$(this,"cleanup");$(this,"subscribers",new Set);$(this,"retirements",new WeakMap)}captureRetirement(){const t=Object.freeze({}),r=++this.revision,n=this.cleanup;return this.cleanup=void 0,this.retirements.set(t,{revision:r,cleanup:n,callbacks:this.draining?[]:[...this.subscribers]}),t}drainRetirement(t){const r=this.retirements.get(t);if(!r)throw new Error("Frame resource retirement is foreign or consumed.");this.retirements.delete(t);const n=this.draining;this.draining=!0;try{this.drain(r.cleanup);for(const s of r.callbacks)this.drain(s)}finally{this.draining=n}}begin(){const t=this.captureRetirement(),r=this.revision;return this.drainRetirement(t),r}once(t,r,n){let s=!1;return()=>{if(s||(s=!0,!this.current(t)||!r()||!this.current(t)))return null;const i=n();return!this.current(t)||!r()||!this.current(t)?null:i}}drain(t){try{Promise.resolve(t==null?void 0:t()).catch(()=>{})}catch{}}current(t){return this.revision===t}install(t,r){return this.current(t)?(this.cleanup=r,!0):!1}subscribe(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}}function Ss(e,t,r){const n=()=>e.current(t)&&r.current()===!0&&e.current(t),s=e.once(t,n,r.complete);return Object.freeze({completeLoad:()=>{const i=s();return!i||!n()||r.accept(i)!==!0||!n()?null:i}})}function _s(e,t,r){const n=()=>e.current(t)&&r.current()===!0&&e.current(t);if(!n())return null;const s=r.acquire();if(!s)return null;let i=!1,a=null,c;try{const o=s.binding;if(n()&&r.bindingCurrent(o)===!0&&n()){const u=r.createPort(o);n()&&r.portCurrent(u)===!0&&n()&&e.install(t,s.release)&&(i=!0,a=u)}}catch(o){c={cause:o}}if(!i)try{s.release()}catch(o){c??(c={cause:o})}if(c)throw c.cause;return a}function Ds(e){const t=()=>Object.assign(new Error("Document actions are unavailable."),{status:409}),r=(s,i)=>{if(i.aborted||!e.current(s)||i.aborted)throw t()},n=(s,i)=>{const a=Bt.parse(i);if(a.receipt.id!==s)throw new Error("Document receipt does not match this action.");return a};return Object.freeze({current:e.current,submit:async(s,i)=>{const a=Qe.parse(JSON.parse(JSON.stringify(s))),c=a.id;r("submit",i);const o=await e.submit(a,i);r("read",i);const u=n(c,o);return r("read",i),u},inspect:async(s,i)=>{r("read",i);const a=await e.inspect(s,i);r("read",i);const c=n(s,a);return r("read",i),c},captureOriginal:s=>{const i=Qe.parse(JSON.parse(JSON.stringify(s))),a=i.id,c=JSON.stringify(i);if(!e.current("submit"))return null;const o=e.capture(i,c);if(!o||!e.current("submit")||!o.current("submit"))return null;let u=!1;const d=f=>o.current(f)===!0;return Object.freeze({id:a,bytes:c,current:d,submit:async f=>{if(u||f.aborted||!d("submit"))throw t();u=!0;const l=await o.submit(JSON.parse(c),f);if(f.aborted||!d("read"))throw t();const g=n(a,l);if(f.aborted||!d("read"))throw t();return g},inspect:async f=>{if(f.aborted||!d("read"))throw t();const l=await o.inspect(a,f);if(f.aborted||!d("read"))throw t();const g=n(a,l);if(f.aborted||!d("read"))throw t();return g}})}})}function Is(e){return Object.freeze({id:e.id,bytes:e.bytes,submit:async t=>{try{return{kind:"accepted",receipt:await e.submit(t)}}catch{return{kind:"uncertain"}}},inspect:async t=>{try{return{kind:"accepted",receipt:await e.inspect(t)}}catch{return{kind:"unknown"}}}})}function Ns(e,t,r){const n=Qe.parse(JSON.parse(e.bytes));if(n.id!==e.id||JSON.stringify(n)!==e.bytes||!r())return null;const s=t(n);return!r()||!s?null:Is(s)}const As=dt.prototype.acquireDoc,ft=new WeakMap,Nt=new WeakMap;function Ts(e,t){const r=bt(e),n=new WeakMap,s=(a,c)=>t.current(c)&&Oe(e,a,!0);return Object.freeze({prepareFrameLoad:(a,c)=>{var l;if(!(a instanceof dt)||c.loaded)return null;const o=dr(e),u=o?(l=Ne(e,o))==null?void 0:l.httpBaseline:void 0,d=t.begin();if(!o||!u||!t.current(d)||!Oe(e,o,!0)||a.getCurrent()!==c||c.transportOwner!==r||!s(o,d))return null;let f=null;return Ss(t,d,{current:()=>{var g;return Oe(e,o,!0)&&((g=Ne(e,o))==null?void 0:g.httpBaseline)===u&&a.getCurrent()===(f??c)&&t.current(d)&&Oe(e,o,!0)},complete:()=>(f=a.observeLoaded(c),f),accept:g=>{var b,m;return!t.current(d)||!Oe(e,o,!0)||((b=Ne(e,o))==null?void 0:b.httpBaseline)!==u||a.getCurrent()!==g||!t.current(d)||!Oe(e,o,!0)||((m=Ne(e,o))==null?void 0:m.httpBaseline)!==u?!1:(n.set(g,{record:o,birth:u.birth}),!0)}})},subscribeInvalidation:a=>t.subscribe(a),attachFrame:(a,c)=>{if(!(a instanceof dt))return null;const o=dr(e),u=t.begin();if(!o||!t.current(u)||!Oe(e,o,!0)||a.getCurrent()!==c||c.transportOwner!==r||!s(o,u))return null;const d=n.get(c);return!d||d.record!==o||!Q(d.birth,Ne(e,o).birth)?null:_s(t,u,{current:()=>s(o,u),acquire:()=>{const f=As.call(a,c,Ne(e,o).birth,Ne(e,o).birth.documentId);let l=!1,g=null,b;try{s(o,u)&&a.getCurrent()===c&&s(o,u)&&(g=Object.freeze({binding:f.binding,release:f.release}),l=!0)}catch(m){b={cause:m}}if(!l)try{f.release()}catch(m){b??(b={cause:m})}if(b)throw b.cause;return g},bindingCurrent:f=>a.isCurrent(f)&&s(o,u),createPort:f=>ps(a,f,{owner:r,publisherEpoch:c.publisherEpoch,isCurrentOwner:(l,g)=>l===r&&g===c.publisherEpoch&&t.current(u)&&Oe(e,o),captureOriginal:l=>Ns(l,g=>{var b;return((b=Ys(e,o))==null?void 0:b.captureOriginal(g))??null},()=>s(o,u)),submit:async()=>({kind:"terminal"}),inspect:async()=>({kind:"unknown"})}),portCurrent:f=>f.current()&&s(o,u)})}})}function Ms(e){if(Me(e),ft.has(e))throw new Error("Frame owner is already initialized.");const t=new Os,r=Ts(e,t);return ft.set(e,{frames:t,facade:r}),r}function Fs(e){var t;return Me(e),(t=ft.get(e))==null?void 0:t.facade}function Ge(e){Me(e);const t=ft.get(e);if(!t)return;const r=Object.freeze({});return Nt.set(r,{owner:e,frames:t.frames,ticket:t.frames.captureRetirement()}),r}function Ve(e,t){if(!t)return;const r=Nt.get(t);if(!r||r.owner!==e)throw new Error("Frame retirement is foreign or consumed.");Nt.delete(t),r.frames.drainRetirement(r.ticket)}function Fr(e,t){const r=xe(e,t),n=Vs(e,t);if(!(!r||!n))return{owner:t,verified:r.verified,...Ds(n)}}function ge(e,t){return{documentId:e,transport:t,events:[],available:!1}}function zs(e,t,r,n,s,i){var o,u;const a=e.documentId===r&&e.transport===n?e:ge(r,n);if(a.snapshot&&(t.highWatermark<a.snapshot.highWatermark||t.stateRev<a.snapshot.stateRev))return a;const c=new Map((((o=a.snapshot)==null?void 0:o.receipts)??[]).filter(d=>d.receipt.docSeq>=t.receiptRetentionFloor).map(d=>[d.receipt.id,d]));for(const d of t.receipts)c.set(d.receipt.id,d);return{...a,available:i,snapshot:{...t,...s?{}:{routing:(u=a.snapshot)==null?void 0:u.routing},receipts:[...c.values()].sort((d,f)=>f.receipt.docSeq-d.receipt.docSeq).slice(0,400)},events:t.resetRequired?a.events.filter(d=>d.docSeq>=t.retentionFloor):a.events}}function qs(e){var r,n,s,i,a,c,o,u,d,f,l,g;const t=async()=>{throw Object.assign(new Error("Document actions are unavailable."),{status:409})};return{documentId:e.documentId,enabled:e.available&&((r=e.binding)==null?void 0:r.verified)===!0&&((s=(n=e.snapshot)==null?void 0:n.routing)==null?void 0:s.enabled)===!0,submissionOwner:(i=e.binding)==null?void 0:i.owner,current:((a=e.binding)==null?void 0:a.current)??(()=>!1),approvedEventTypes:e.available?((o=(c=e.snapshot)==null?void 0:c.routing)==null?void 0:o.approvedEventTypes)??[]:[],destinationLabel:e.available?((d=(u=e.snapshot)==null?void 0:u.routing)==null?void 0:d.destinationLabel)??"Actions unavailable":"Actions unavailable",...e.snapshot?{snapshot:e.snapshot}:{},submit:((f=e.binding)==null?void 0:f.submit)??t,inspect:((l=e.binding)==null?void 0:l.inspect)??t,captureOriginal:(g=e.binding)==null?void 0:g.captureOriginal}}function Ls(e,t,r){return!!(e&&t&&r.incarnation&&Q(t,r.incarnation)&&(r.highWatermark<e.highWatermark||r.stateRev<e.stateRev))}function zr(e,t,r,n){const s=e.documentId===r&&e.transport===n?e:ge(r,n);return{...s,events:[...s.events,t].slice(-200)}}function Ps(e,t){if(e.incarnation&&(e.incarnation.documentId!==t||e.events.some(r=>r.documentId!==t||!r.incarnation||!Q(e.incarnation,r.incarnation))))throw new Error("Document replay identity changed.")}const At=new WeakMap;function Bs(e,t,r){const n=ws(e,t,r);if(n)return At.set(r,{owner:e,run:t,witness:n}),n}const qr=new WeakMap,Ke=new WeakMap,Tt=new WeakMap,Mt=new WeakMap;function Ce(e,t){Me(e);const r=t??Ke.get(e),n=r&&qr.get(r);return n&&n.owner===e&&Ke.get(e)===r&&n.active?n:void 0}function ee(e){return Me(e),Ke.get(e)}function xe(e,t){const r=Ce(e,t);return r?Object.freeze({birth:r.birth,httpBaseline:r.httpBaseline,snapshot:r.snapshot,verified:r.verified}):void 0}function Xe(e,t,r=!1){var i,a;const n=Ce(e,t),s=de(e);return!!n&&s.live&&n.verified&&n.transport===bt(e)&&(!r||((a=(i=n.snapshot)==null?void 0:i.routing)==null?void 0:a.enabled)===!0)}function Us(e){const t=Ce(e);Ke.delete(e),t&&(t.active=!1,t.verified=!1)}function Ct(e,t){const r=Ce(e,t);r&&(r.verified=!1)}function Ws(e,t,r){const n=Ce(e,r);return!n||!ie(e,t)?!1:(n.verified=!0,ie(e,t))}function $s(e,t,r){const n=At.get(r);At.delete(r);const s=(n==null?void 0:n.owner)===e&&n.run===t?n.witness:void 0;if(!s||!ie(e,t))return!1;const i=s.response.incarnation;let a=Ce(e);if(!a&&!i)return ie(e,t);if(!a&&i){const c=de(e),o=()=>{const b=de(e);return ie(e,t)&&b.epoch===c.epoch&&b.observation===c.observation&&ee(e)===c.subject},u=bt(e),d=u.ingestCanvasEvent;if(!o())return!1;const f=Function.prototype.bind.call(d,u),l=u.getCanvasEventReceipt;if(!o())return!1;const g=Function.prototype.bind.call(l,u);if(!o())return!1;a={owner:e,token:Object.freeze({}),birth:Object.freeze({...i}),active:!0,verified:!1,submit:f,inspect:g,transport:u},qr.set(a.token,a),Ke.set(e,a.token),a.httpBaseline=Object.freeze({birth:a.birth,floor:s.response.receiptRetentionFloor}),Tt.set(r,Object.freeze({owner:e,run:t,epoch:c.epoch,previous:c.subject,subject:a.token}));try{xs(e,t,r)}catch(b){throw Ce(e)===a&&si(e,t,r),b}finally{Tt.delete(r)}if(!ie(e,t))return!1}else if(a){if(!i||!Q(a.birth,i))return!1;a.httpBaseline=Object.freeze({birth:a.birth,floor:s.response.receiptRetentionFloor})}return ie(e,t)?(a&&(a.verified=ii(e)||a.verified),!0):!1}function $t(e,t,r){const n=Ht(e),s=n.subject,i=()=>Ur(e,n,r);if(!s||!Xe(e,s)){const o=Ge(e);Ve(e,o)}if(!i())return;const a=s&&Fr(e,s),c=Fs(e);n.dispatch(o=>{var f;if(!i())return o;const u=((f=o.binding)==null?void 0:f.owner)===s?o:ge(n.documentId,n.transport),d=typeof t=="function"?t(u):t;return i()?{...d,...d.snapshot?{snapshot:Object.freeze({...d.snapshot})}:{},binding:a,frameAdmission:c}:o})}function Hs(e,t,r,n,s){const i=Ht(e),a=Ce(e);Ur(e,i,s)&&(a&&(a.snapshot=t),$t(e,c=>zs(c,t,i.documentId,i.transport,r,n),s))}function Gs(e,t,r,n){const s=Mr(e,t,r,n);if(!ie(e,t)||!s)return!1;if(s.docSeq<=Wt(e).highest)return ie(e,t);Mt.set(r,{owner:e,run:t,pending:n,frame:s});try{ks(e,t,r,n)}finally{Mt.delete(r)}if(!ie(e,t))return!1;const i=Ht(e);return $t(e,a=>zr(a,s,i.documentId,i.transport),t),ie(e,t)}function Vs(e,t){const r=Ce(e,t);if(!r)return;const n=de(e).documentId;return{current:s=>Xe(e,t,s==="submit"),submit:(s,i)=>r.submit(n,s,{expectedGeneration:r.birth.generation},i),inspect:(s,i)=>r.inspect(n,s,{expectedGeneration:r.birth.generation},i),capture:()=>{const s=r.httpBaseline;return!s||!Xe(e,t,!0)||!Q(s.birth,r.birth)?null:Object.freeze({current:i=>Xe(e,t,i==="submit")&&(i==="read"||r.httpBaseline===s),submit:(i,a)=>r.submit(n,i,{expectedGeneration:s.birth.generation},a),inspect:(i,a)=>r.inspect(n,i,{expectedGeneration:s.birth.generation},a)})}}}function Lr(e,t,r){const n=Tt.get(r),s=de(e);return n&&n.owner===e&&n.run===t&&s.epoch===n.epoch&&s.subject===n.subject&&s.live?n:void 0}function Js(e,t,r,n){const s=Mt.get(r);return s&&s.owner===e&&s.run===t&&s.pending===n&&ie(e,t)?s.frame:void 0}const Pr=new WeakMap,ht=new WeakMap;function Zs(e){const t=ht.get(e);if(!t)throw new Error("Document construction ticket is foreign or consumed.");return ht.delete(e),t}function Xs(e,t,r){const n=Object.freeze({});ht.set(n,Object.freeze({documentId:e,transport:t,dispatch:r}));try{const s=oi(n);return Pr.set(n,s),n}finally{ht.delete(n)}}function ne(e){const t=Pr.get(e);if(!t)throw new Error("Document owner is foreign.");return t}function Me(e){ne(e)}function de(e){return ne(e).facts()}function bt(e){return ne(e).transport()}function dr(e){return ne(e).subject()}function Ne(e,t){return ne(e).subjectFacts(t)}function Oe(e,t,r=!1){return ne(e).subjectCurrent(t,r)}function Ys(e,t){return ne(e).binding(t)}function Qs(e,t){ne(e).reserve(t)}function ie(e,t){return ne(e).current(t)}function Ks(e,t,r){return ne(e).admit(t,r)}function fr(e,t,r,n){return ne(e).frame(t,r,n)}function hr(e,t){return ne(e).qualify(t)}function ei(e,t){ne(e).failed(t)}function ti(e,t){ne(e).unavailable(t)}function ri(e,t){ne(e).start(t)}function ni(e){ne(e).dispose()}const Br=new WeakMap;function Ht(e){const t=Object.freeze(ne(e).projection());return Br.set(t,Object.freeze({custodyKey:e,capture:t})),t}function Ur(e,t,r){const n=Br.get(t);return(n==null?void 0:n.custodyKey)===e&&n.capture===t&&ne(e).projectionCurrent(t.epoch,t.subject,r)}function si(e,t,r){ne(e).abortAdmission(t,r)}function ii(e){return ne(e).qualified()}const Ft=new WeakMap;function oi(e){const{documentId:t,transport:r,dispatch:n}=Zs(e);let s,i=!1,a;const c={live:!0};let o=0,u,d,f=!1,l,g,b=0;const m=()=>c.live,v=()=>Us(e);let N=0;const A=()=>Wt(e),R=j=>{const E=lr(e,j);return!!E&&!E.ended&&m()&&s===j&&E.epoch===o&&E.subject===ee(e)},z=(j=!1)=>{const E=Ge(e);v(),o++,s=void 0,j&&ur(e),Ve(e,E)},L=(j,E)=>$t(e,j,E),B=j=>{const E=Cs(e,j),k=ee(e),T=k&&xe(e,k);return!R(j)||!E||E.through>E.highest||!l||!T||!Q(l,T.birth)||!Ws(e,j,k)?!1:(l=void 0,L(q=>({...q,available:!0}),j),R(j))},H=(j,E,k)=>{const T=ee(e),q=T&&xe(e,T),w=o,C=()=>m()&&w===o&&ee(e)===T&&(!k||R(k));if(!C()||Ls(q==null?void 0:q.snapshot,q==null?void 0:q.birth,j))return;const U=E?j.routing:d;j={...j,routing:U&&Object.freeze({enabled:U.enabled,destinationLabel:U.destinationLabel,approvedEventTypes:Object.freeze([...U.approvedEventTypes])})},E&&(d=j.routing),!T&&!j.incarnation&&(f=!0),C()&&Hs(e,j,E,l===void 0,k)},x=(j,E)=>{var se;const k=Bs(e,j,E);if(!R(j)||!k)return"discard";const T=k.response;Ps(T,t);const q=T.incarnation;if((ee(e)||l||g)&&!q)throw new Error("Document replay identity is unavailable.");if(g&&q&&!Q(g,q))return z(!0),L(ge(t,r)),"restart";const w=ee(e),C=(w&&((se=xe(e,w))==null?void 0:se.birth))??l;if(q&&(C&&!Q(C,q)||!C&&f||k.targetBirth&&!Q(k.targetBirth,q)))return l=q,f=!1,d=void 0,u=void 0,z(!0),L(ge(t,r)),"restart";const{events:U,...G}=T,Z=ee(e);return!Z&&q&&(l=g??q),!$s(e,j,E)||!R(j)?"discard":(!Z&&q&&(g=void 0),H(G,k.revision===N,j),R(j)?"accepted":"discard")},I=(j,E,k)=>{var C;const T=Mr(e,j,E,k),q=ee(e),w=(q&&((C=xe(e,q))==null?void 0:C.birth))??l;return!R(j)||!T||T.documentId!==t||w&&(!T.incarnation||!Q(w,T.incarnation))?!1:Gs(e,j,E,k)},M=(j,E)=>{const k=Object.freeze({});Ft.set(k,Object.freeze({owner:e,revision:N,observation:b,epoch:o,notification:j,mode:E}));try{return js(e,k)}finally{Ft.delete(k)}},W=j=>{if(i||!m()||(i=!0,L(ge(t,r)),!m()))return;const E=yn(void 0,k=>{if(!m()||k.documentId!==t)return;const T=k.type==="canvas_channel_snapshot"?k.snapshot.incarnation:k.incarnation,q=ee(e);if(!q){if(l&&!g&&(!T||!Q(l,T))||!T||T.documentId!==t)return;if(!g||!Q(g,T)){const w=!!g||!!l;if(g=Object.freeze({...T}),b++,d=void 0,u=void 0,f=!1,w&&(z(!0),L(ge(t,r))),!m()||!g||!Q(g,T))return}M(k,"quarantine"),m()&&j();return}if(l&&(!T||!Q(l,T))){T&&j();return}if(T&&!Q(xe(e,q).birth,T)){l=T,f=!1,d=void 0,u=void 0,z(!0),L(ge(t,r)),m()&&j();return}if(T){if(u!==void 0&&u!==k.scope){const w=Ge(e);if(u=k.scope,Ct(e,q),o++,s=void 0,N++,Ve(e,w),ee(e)!==q||!m())return;L(C=>({...C,available:!1})),ee(e)===q&&m()&&j();return}u=k.scope,N++,k.type==="canvas_channel_snapshot"?H(k.snapshot,!0):k.docSeq>A().highest+1?(M(k,"gap")&&m()&&L(C=>({...C,available:!1})),m()&&j()):M(k,"event")}},r,()=>{if(!m())return;const k=Ge(e),T=ee(e);T&&Ct(e,T),o++,s=void 0,N++,Ve(e,k),L(q=>({...q,available:!1})),m()&&j()});m()?a=E:E(),m()&&j()};return Wr.set(e,j=>{const E=et(e,j);if(!E||E.notification.type==="canvas_channel_snapshot")return;const k=ee(e),T=o;!k||!E.notification.incarnation||!Q(xe(e,k).birth,E.notification.incarnation)||(L(q=>zr(q,E.notification,t,r)),!m()||T!==o||ee(e))}),{facts:()=>Object.freeze({documentId:t,live:m(),epoch:o,revision:N,observation:b,subject:ee(e)}),transport:()=>r,subject:()=>ee(e),subjectFacts:j=>xe(e,j),subjectCurrent:(j,E)=>Xe(e,j,E),binding:j=>Fr(e,j),qualified:()=>l===void 0,projection:()=>({documentId:t,transport:r,dispatch:n,epoch:o,run:s,subject:ee(e)}),projectionCurrent:(j,E,k)=>m()&&j===o&&E===ee(e)&&(!k||s===k),abortAdmission:(j,E)=>{Lr(e,j,E)&&z(!0)},reserve:j=>{const E=lr(e,j);if(!E||E.ended||!m()||E.epoch!==o||E.subject!==ee(e))throw new Error("Replay run is foreign or stale.");s=j},current:R,admit:x,frame:I,qualify:B,failed:j=>{if(!R(j))return;const E=ee(e);E&&Ct(e,E),L(k=>({...k,available:!1}),j)},unavailable:j=>{R(j)&&L(E=>({...E,available:!1}),j)},start:W,dispose:()=>{if(!m())return;const j=Ge(e);c.live=!1,s=void 0;const E=a;a=void 0,v(),o++,ur(e);try{Ve(e,j)}finally{E==null||E()}}}}function et(e,t){const r=Ft.get(t),n=de(e);if(!(!r||r.owner!==e||!n.live||n.epoch!==r.epoch||n.revision!==r.revision||n.observation!==r.observation))return r}function ai(e,t){var c;const r=et(e,t);if(!r||r.notification.type==="canvas_channel_snapshot")return;const n=r.notification,i=de(e).subject,a=i&&xe(e,i);!a||!n.incarnation||!Q(a.birth,n.incarnation)||n.docSeq<=Wt(e).highest||(Rs(e,t),!(!et(e,t)||de(e).subject!==i)&&((c=Wr.get(e))==null||c(t)))}const Wr=new WeakMap;function ci(e,t,r){const n=Xs(e,t,r);ys(n);const s=Ms(n);return Object.freeze({beginRun:()=>Es(n),frameAdmission:s,start:i=>ri(n,i),dispose:()=>ni(n)})}function ui(e,t){let r,n=0;const s=f=>{try{t==null||t(f)}catch{}},i=f=>{r===f&&(r=void 0)},a=(f,l)=>{f.settled||(f.settled=!0,r||s(!1),l?f.reject(l.cause):f.resolve())},c=()=>{d().catch(()=>{})},o=(f,l)=>{const g=()=>n===f.revision;if(!g())return;const b=l.beginFinalization();if(g()){if(b==="restart"){c();return}if(b==="drain")for(;g();){const m=l.drainOne();if(!g())return;if(m!=="again"){if(m==="restart")c();else if(m==="tail"){const v=l.finishFinalization();g()&&v==="restart"&&c()}return}}}},u=async f=>{let l,g;try{l=e();try{for(;await l.page()==="again";);}catch(b){l.failed(b)}}catch(b){g={cause:b}}finally{i(f);try{l&&o(f,l)}catch(b){g={cause:b}}finally{a(f,g)}}},d=()=>{if(r)return r.promise;let f,l;const g=new Promise((m,v)=>{f=m,l=v}),b={revision:++n,promise:g,resolve:f,reject:l,settled:!1};return r=b,s(!0),u(b),g};return Object.freeze({request:d})}function li(e,t,r,n){const s=ci(e,t,r);let i=!1;const a=ui(()=>{const c=s.beginRun();return{async page(){const o=await c.readPage();if(!o)return"done";const u=c.consumePage(o);if(u.kind!=="frames")return u.kind;for(let d=0;d<u.count;d++)if(!c.advancePageFrame(o,d))return"done";return c.finishPage(o)},failed:()=>c.failed(),beginFinalization:()=>{const o=c.beginFinalization();return o!=="drain"&&c.end(),o},drainOne(){if(!c.current())return c.end(),"stop";const o=c.takePending();return o?c.advancePending(o)?"again":(c.end(),"stop"):"tail"},finishFinalization:()=>{try{return c.finishFinalization()}finally{c.end()}}}},c=>{i||n==null||n(c)});return s.start(()=>{a.request().catch(()=>{})}),Object.freeze({dispose(){i=!0,s.dispose()}})}function $r(e){var u,d,f;const t=ae(),[r,n]=p.useState(()=>ge(e,t)),[s,i]=p.useState({documentId:e,transport:t,pending:!0});p.useLayoutEffect(()=>{const l=li(e,t,n,g=>{i({documentId:e,transport:t,pending:g})});return()=>l.dispose()},[e,t]);const a=r.documentId===e&&r.transport===t?r:ge(e,t),c=p.useMemo(()=>qs(a),[a]),o=p.useMemo(()=>{var b;const l=(b=a.snapshot)==null?void 0:b.incarnation,g=a.binding;return l&&g?Object.freeze({incarnation:Object.freeze({...l}),current:()=>g.current("read")}):void 0},[(u=a.snapshot)==null?void 0:u.incarnation,a.binding]);return{channel:c,events:a.events,snapshot:a.snapshot,frameAdmission:a.frameAdmission,fileSaveBinding:o,fileSaveObservation:s.documentId!==e||s.transport!==t||s.pending?"pending":a.available&&((d=a.binding)!=null&&d.verified)&&((f=a.snapshot)!=null&&f.incarnation)?"ready":"unavailable"}}function di(e){return{type:e.type,docSeq:e.docSeq,event:e.event}}function fi(e,t){const r=e.indexOf("#"),n=r<0?e:e.slice(0,r),s=r<0?"":e.slice(r);return`${n}${n.includes("?")?"&":"?"}${ls}=${t}${s}`}const hi={random:()=>Math.random(),schedule:(e,t)=>setTimeout(e,t),cancel:e=>clearTimeout(e)};function pi(e){const t=ae(),r=$r(e.documentId),[n]=p.useState(()=>new dt),[s,i]=p.useState(null),[,a]=p.useState(0),c=JSON.stringify([e.documentId,e.logicalUrl,e.resolvedSource,e.reloadNonce,e.bridgeEligibility,e.previewOrigin]),o=e.bridgeEligibility==="served-document",u=p.useMemo(()=>o?crypto.randomUUID():null,[o,c]),d=JSON.stringify([c,u]),f=e.resolvedSource===null||u===null?e.resolvedSource:fi(e.resolvedSource,u),l=p.useRef(null),g=p.useRef({params:e,doc:r,key:d,transport:t}),b=p.useRef(!1),m=p.useRef(0),v=(x,I="offline")=>{const M=x.link;x.link=null,M&&(M.hostClosed=!0,M.handshake.close(I)),n.retire()},N=()=>{var M,W;const x=l.current,{doc:I}=g.current;!(x!=null&&x.link)||I.channel.enabled&&((W=(M=I.channel).current)!=null&&W.call(M,"read"))||(v(x,"revoked"),x.tried=null)},A=()=>{var W,j,E;const x=(W=l.current)==null?void 0:W.link,{doc:I}=g.current,M=I.snapshot;if(!(!(x!=null&&x.live)||!M||!((E=(j=I.channel).current)!=null&&E.call(j,"read")))){for(const k of I.events)k.docSeq<=x.load.delivered||(x.handshake.publish({kind:"event",frame:di(k)}),x.load.delivered=k.docSeq);M.stateRev>x.stateRev&&(x.handshake.publish({kind:"state",state:M.state,stateRev:M.stateRev,docSeq:M.highWatermark,reset:M.resetRequired}),x.stateRev=M.stateRev)}},R=()=>{var w,C,U,G;const x=l.current,{params:I,doc:M,key:W,transport:j}=g.current,E=I.iframeRef.current,k=x==null?void 0:x.load,T=M.frameAdmission;if(!(x!=null&&x.active)||x.link||!k||x.boot!==null&&k!==x.firstLoad||x.key!==W||x.transport!==j||!I.resolvedSource||!I.bridgeEligibility||!(E!=null&&E.isConnected)||E.contentWindow!==k.frame||!T||!M.snapshot||!M.channel.enabled||!((C=(w=M.channel).current)!=null&&C.call(w,"read")))return;const q=[k,T,M.snapshot,x.invalidations];if(!((U=x.tried)!=null&&U.every((Z,se)=>Z===q[se]))){x.tried=q,b.current=!0;try{const Z=n.observeHostContext({frame:k.frame,documentId:I.documentId,resolvedSource:I.resolvedSource,logicalUrl:I.logicalUrl,reloadKey:`${I.reloadNonce}:${++m.current}`,sessionId:null,eligibility:I.bridgeEligibility,exactOrigin:I.bridgeEligibility==="served-document"?"null":I.previewOrigin,transportOwner:j,publisherEpoch:m.current}),se=Z&&((G=T.prepareFrameLoad(n,Z))==null?void 0:G.completeLoad()),je=se&&T.attachFrame(n,se);if(!je){n.retire();return}const Re={load:k,live:!1,hostClosed:!1,stateRev:-1,handshake:new gs(je,{nonce:()=>crypto.randomUUID(),channel:()=>new MessageChannel,scheduler:hi,boot:x.boot,offline:()=>{const fe=l.current;(fe==null?void 0:fe.link)!==Re||Re.hostClosed||!Re.live&&fe.everLive&&i({key:fe.key,transport:fe.transport})}})};x.link=Re,Re.handshake.start()}catch{x.link=null,n.retire()}finally{b.current=!1}}},z=(x,I,M)=>{let W=l.current;return(!W||W.key!==x||W.transport!==I)&&(W=l.current={key:x,transport:I,boot:M,active:!1,load:null,firstLoad:null,link:null,tried:null,invalidations:0,everLive:!1}),W.active=!0,R(),W},L=x=>{x.active=!1,v(x),x.tried=null},B=p.useRef({connect:R,disconnect:v,publish:A,enter:z,leave:L,revokeIfWithdrawn:N});p.useLayoutEffect(()=>{B.current={connect:R,disconnect:v,publish:A,enter:z,leave:L,revokeIfWithdrawn:N},g.current={params:e,doc:r,key:d,transport:t}}),p.useLayoutEffect(()=>{const x=B.current.enter(d,t,u);return()=>B.current.leave(x)},[d,t,u]),p.useLayoutEffect(()=>{const x=r.frameAdmission;if(x)return x.subscribeInvalidation(()=>{const I=l.current;b.current||!I||(B.current.disconnect(I),I.invalidations++,a(M=>M+1))})},[r.frameAdmission]),p.useLayoutEffect(()=>{const x=I=>{const M=l.current,W=M==null?void 0:M.link;!M||!W||W.hostClosed||!W.handshake.receive(I)||W.live||(W.live=!0,M.everLive=!0,i(null),B.current.publish())};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[]),p.useLayoutEffect(()=>{B.current.revokeIfWithdrawn(),B.current.connect(),B.current.publish()});const H=p.useCallback(x=>{var E;const I=l.current,M=x.contentWindow;if(!I||!M||x!==g.current.params.iframeRef.current)return;B.current.disconnect(I);const W={frame:M,delivered:0},j=((E=I.firstLoad)==null?void 0:E.frame)===M;I.load=W,j||(I.firstLoad=W),I.tried=null,j&&I.everLive&&I.boot!==null?i({key:I.key,transport:I.transport}):i(null),B.current.connect()},[]);return{frameSource:f,requiresReload:(s==null?void 0:s.key)===d&&s.transport===t,noteFrameLoaded:H}}function mi(e,t,r){return r!=null&&r.bridgeEligibility?e.mode==="serve"?t===null?null:{kind:"serve",cwd:t,path:e.path}:e.mode==="proxy"?{kind:"proxy",port:e.port,path:e.path}:null:null}function gi({iframeRef:e,target:t,cwd:r,resolved:n,reloadNonce:s}){const i=ae(),a=p.useRef(i);p.useEffect(()=>{a.current=i});const c=mi(t,r,n),o=c?JSON.stringify(c):null,u=o?`${o}
|
|
25
25
|
${n==null?void 0:n.src}
|
|
26
|
-
${s}`:null,[d,f]=p.useState(null);return p.useLayoutEffect(()=>{if(u===null||o===null)return;const l=JSON.parse(o);let g=!0,b=0;const m=new WeakSet,v=N=>{const T=N.target;if(T===null||T!==e.current)return;const R=++b;if(m.has(T)){f(null);return}m.add(T),a.current.getFrameBridgeStatus(l).then(z=>{!g||R!==b||f(z.bridge==="refused"&&z.reason?{pageKey:u,reason:z.reason}:null)},()=>{})};return document.addEventListener("load",v,!0),()=>{g=!1,document.removeEventListener("load",v,!0)}},[u,o,e]),d!==null&&d.pageKey===u?d.reason:null}const gi=15e3;function vi(e){const t=e instanceof Error?e.message.trim():"";return t.length>0?t:"Couldn’t reach DorkOS. Check your network and try again."}function bi(e){const t=ae();return{open:p.useCallback(async r=>{await t.openRoomCanvasDocument(e,r)},[t,e]),update:p.useCallback(async(r,n)=>{await t.updateRoomCanvasDocument(e,r,{content:n})},[t,e]),pin:p.useCallback(async(r,n)=>{await t.updateRoomCanvasDocument(e,r,{pinned:n})},[t,e]),close:p.useCallback(async r=>{await t.closeRoomCanvasDocument(e,r)},[t,e])}}function yi(e,t){const r=ae(),n=Y(s=>s.setRoomCanvasEditing);p.useEffect(()=>{if(n(e,t),t===null)return;const s=a=>{r.setRoomCanvasEditing(e,t,a).catch(c=>{console.warn("[room-canvas] edit lock failed",{roomId:e,documentId:t,err:c})})};s(!0);const i=setInterval(()=>s(!0),gi);return()=>{clearInterval(i),s(!1),n(e,null)}},[r,e,t,n])}const wi=400;function Zo(e,t){const r=ae(),n=Y(s=>s.roomCanvasPresenceEpoch[e]??0);p.useEffect(()=>{const s=c=>{r.setRoomCanvasViewing(e,c).catch(o=>{console.warn("[room-canvas] could not say where we are looking",{roomId:e,err:o})})};let i=!1;const a=setTimeout(()=>{i=!0,s(t)},wi);return()=>{clearTimeout(a),i&&s(null)}},[r,e,t,n])}const xi="allow-scripts allow-forms allow-popups allow-modals",jt="allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-downloads",ki=new Set(["javascript:","data:","blob:"]),Ci=new Set(["localhost","127.0.0.1","0.0.0.0","[::1]","::1"]);function Ht(e){return Ci.has(e)||e.endsWith(".localhost")}function ji(e){return Ht(e)?"direct":"server"}function Ri(e,t){let r;try{r=new URL(e)}catch{return null}const n=r.searchParams.get(hr),s=new URL(r.origin),i=t.indexOf("?");return s.pathname=(i===-1?t:t.slice(0,i))||"/",s.search=i===-1?"":t.slice(i),n!==null&&s.searchParams.set(hr,n),s.toString()}const hr="__dorkos_preview",Oi="/__dorkos_preview/health";function Ei(e){return e==="https:"?443:80}function $r(e){let t;try{t=new URL(e)}catch{return{mode:"serve",path:e}}if(ki.has(t.protocol))return{mode:"blocked"};if(t.protocol==="file:")return{mode:"serve",path:decodeURIComponent(t.pathname)};if(t.protocol==="http:"||t.protocol==="https:"){if(Ht(t.hostname)){const r=t.port?Number(t.port):Ei(t.protocol);return{mode:"proxy",hostname:t.hostname,port:r,path:`${t.pathname}${t.search}`}}return{mode:"external",url:e}}return{mode:"blocked"}}function Si(e){const t=e.trim();if(t===""||/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||t.startsWith("/")||t.startsWith("./")||t.startsWith("../"))return t;const r=t.split("/")[0];if(t.includes("/")&&!r.includes(".")&&!r.includes(":"))return t;const s=r.split(":")[0];return`${Ht(s)?"http":"https"}://${t}`}function _i(e){const t=$r(e);if(t.mode==="serve")return{kind:"local",path:t.path};if(t.mode==="blocked")return{kind:"raw",text:e};try{const r=new URL(e),n=r.host.replace(/^www\./,""),s=r.pathname==="/"&&r.search===""&&r.hash===""?"":`${r.pathname}${r.search}${r.hash}`;return{kind:"url",host:n,rest:s}}catch{return{kind:"raw",text:e}}}const Di=2e3;async function pr(e,t=globalThis.fetch,r=Di){const n=new AbortController,s=setTimeout(()=>n.abort(),r);try{return await t(e,{mode:"no-cors",cache:"no-store",signal:n.signal}),!0}catch{return n.signal.aborted}finally{clearTimeout(s)}}function Ii({target:e,currentUrl:t,strategy:r,cwd:n,reloadNonce:s}){const i=JSON.stringify([t,r,n,s]),[a,c]=p.useState(null),[o,u]=p.useState(null),[d,f]=p.useState(null),l=ae(),g=p.useRef(l);return p.useEffect(()=>{g.current=l}),p.useEffect(()=>{const b=g.current;let m=!1;const v=z=>{c(i),u(z)};async function N(z){if(n===null){f({kind:"no-session"});return}try{const L=await b.createServeUrl(n,z);if(m)return;L===null?f({kind:"unsupported"}):v({src:L,sandbox:xi,previewOrigin:null,bridgeEligibility:"served-document"})}catch{m||f({kind:"failed"})}}async function T(z,L){let B;try{const x=await b.probeLoopbackPort(z);B=x===null?"unknown":x.listening}catch{B="unknown"}if(m)return;let H=null;if(B!==!1){let x=null;try{x=await b.createProxyUrl(z)}catch{if(m)return;H={kind:"failed"}}if(m)return;if((x==null?void 0:x.unavailable)==="tunnel"){f({kind:"tunnel"});return}if((x==null?void 0:x.unavailable)==="no-port"&&(H={kind:"no-port"}),x!=null&&x.url){const I=new URL(x.url);if(await pr(`${I.origin}${Oi}`)){if(m)return;const M=Ri(x.url,L);if(M!==null){v({src:M,sandbox:jt,previewOrigin:I.origin,bridgeEligibility:"preview-listener"});return}}if(m)return;H={kind:"origin-unreachable",host:I.hostname,listenPort:I.port}}}if(r==="direct"&&await pr(t)){if(m)return;v({src:t,sandbox:jt,previewOrigin:null,bridgeEligibility:null});return}m||f(H??{kind:"no-upstream"})}async function R(){if(f(null),u(null),e.mode!=="blocked"){if(e.mode==="external"){v({src:e.url,sandbox:jt,previewOrigin:null,bridgeEligibility:null});return}return e.mode==="serve"?N(e.path):T(e.port,e.path)}}return R(),()=>{m=!0}},[e,t,r,n,s,i]),{resolved:a===i?o:null,resolveError:d}}const Ni=1e4;function Ti(e,t){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 ${t.mode==="proxy"?`${t.hostname}:${t.port}`:"that address"}. Start the dev server, then reload.`}}function Ai({target:e,resolved:t,frameSource:r,resolveError:n,reloadNonce:s,resourceErrorCount:i,title:a,onOpenExternally:c,onReload:o,iframeRef:u,onFrameLoad:d}){if(e.mode==="blocked")return h.jsx(Rt,{children:"This address is blocked for safety."});if(n!==null)return h.jsxs(Rt,{children:[h.jsx("p",{children:Ti(n,e)}),n.kind!=="no-session"&&n.kind!=="unsupported"&&h.jsx("button",{type:"button",onClick:o,className:"text-foreground mt-3 hover:underline",children:"Reload"})]});if(t===null||r===null)return h.jsx(Rt,{children:"Loading…"});const f=e.mode==="external";return h.jsx(Mi,{src:r,sandbox:t.sandbox,title:a,iframeRef:u,onFrameLoad:d,watchLoadDeadline:!f,resourceErrorCount:i,showEmbedFallback:f,onOpenExternally:c,onReload:o},`${r}:${s}`)}function Mi({src:e,sandbox:t,title:r,iframeRef:n,onFrameLoad:s,watchLoadDeadline:i,resourceErrorCount:a,showEmbedFallback:c,onOpenExternally:o,onReload:u}){const[d,f]=p.useState(!1),[l,g]=p.useState(!1);return p.useEffect(()=>{if(!i)return;const b=setTimeout(()=>g(!0),Ni);return()=>clearTimeout(b)},[i]),h.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[l&&!d&&h.jsx(mr,{onOpenExternally:o,onReload:u,children:"This preview is slow to load."}),a>0&&h.jsxs(mr,{onOpenExternally:o,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:t,onLoad:b=>{f(!0),s(b.currentTarget)},className:"min-h-0 w-full flex-1 border-0",title:r}),c&&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:o,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function mr({children:e,onOpenExternally:t,onReload:r}){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:[r&&h.jsx("button",{type:"button",onClick:r,className:"text-foreground hover:underline",children:"Reload"}),h.jsx("button",{type:"button",onClick:t,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function Rt({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})}const Fi=yn/(1024*1024),zi={csp:"This page’s security policy blocks added scripts, so it can’t talk to its agent.",encoding:"This page isn’t saved as UTF-8, so it can’t talk to its agent.",oversize:`This page is over ${Fi} MB, so it can’t talk to its agent.`,"no-head":"This page has no <head> tag, so it can’t talk to its agent.",markup:"DorkOS can’t safely read this page’s <head>, so it can’t talk to its agent.","fixed-source":"DorkOS couldn’t connect this page to its agent."};function qi({reason:e}){return h.jsx("p",{role:"status","data-bridge-refusal":e,className:"text-muted-foreground border-border/60 border-b px-2 py-1 text-xs",children:zi[e]})}function Li(e,t){if(e&&e.contentUrl===t&&e.stack.length>0){const r=Math.min(Math.max(e.cursor,0),e.stack.length-1);return{stack:e.stack,cursor:r}}return{stack:[t],cursor:0}}function Pi({documentId:e,content:t}){const r=Y(w=>w.selectedCwd),n=Y(w=>w.writeBrowserHistory),[s]=p.useState(()=>Li(Y.getState().browserHistories[e],t.url)),[i,a]=p.useState(s.stack),[c,o]=p.useState(s.cursor),[u,d]=p.useState(0);p.useEffect(()=>{n(e,{contentUrl:t.url,stack:i,cursor:c})},[e,t.url,i,c,n]);const f=i[c],l=p.useMemo(()=>$r(f),[f]),g=p.useMemo(()=>l.mode==="proxy"?ji(window.location.hostname):null,[l]),b=p.useRef(null),{resolved:m,resolveError:v}=Ii({target:l,currentUrl:f,strategy:g,cwd:r,reloadNonce:u}),{resourceErrorCount:N,notePersonNavigated:T,noteFrameLoaded:R}=cs({iframeRef:b,documentId:e,logicalUrl:f,reloadNonce:u,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),z=hi({iframeRef:b,documentId:e,logicalUrl:f,reloadNonce:u,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),L=mi({iframeRef:b,target:l,cwd:r,resolved:m,reloadNonce:u}),B=Y(w=>w.roomCanvasLiveRoomId),{open:H}=bi(B??""),[x,I]=p.useState(null),M=p.useCallback(w=>{a(C=>[...C.slice(0,c+1),w]),o(C=>C+1)},[c]),W=wn(B),j=Y(w=>B?w.roomCanvasEditing[B]??null:null);p.useEffect(()=>{if(W===null||j!==null||W.documentId!==e)return;const w=W.url;w===void 0||w===f||M(w)},[W,j,e,f,M]);const O=c>0,k=c<i.length-1,A=p.useCallback(w=>{const C=Si(w);if(!C||C===f){T(),d(U=>U+1);return}if(B){I(null),H({type:"browser",url:C}).catch(U=>{I({url:C,message:vi(U)})});return}T(),M(C)},[f,M,B,H,T]),q=()=>Rn(f);return h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsxs("div",{className:"border-border/60 flex shrink-0 flex-wrap items-center gap-1 border-b px-2 py-1 lg:h-9 lg:flex-nowrap lg:py-0",children:[h.jsx(nt,{label:"Back",disabled:!O,onClick:()=>o(w=>w-1),children:h.jsx(xn,{className:"size-4"})}),h.jsx(nt,{label:"Forward",disabled:!k,onClick:()=>o(w=>w+1),children:h.jsx(kn,{className:"size-4"})}),h.jsx(nt,{label:"Reload",onClick:()=>d(w=>w+1),children:h.jsx(Fn,{className:"size-4"})}),h.jsx("div",{className:"order-first flex w-full min-w-0 lg:order-none lg:w-auto lg:flex-1",children:h.jsx(Bi,{url:(x==null?void 0:x.url)??f,startEditing:x!==null,onSubmit:A},x===null?"address":`retry:${x.url}`)}),h.jsx(nt,{label:"Open in system browser",onClick:q,children:h.jsx(Cn,{className:"size-4"})})]}),x!==null&&h.jsx("p",{role:"status",className:"text-destructive border-border/60 border-b px-2 py-1 text-xs",children:x.message}),z.requiresReload&&h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-b px-2 py-1 text-xs",children:[h.jsx("p",{role:"status",children:"Page is offline. Reload to reconnect."}),h.jsx("button",{type:"button","aria-label":"Reload to reconnect",onClick:()=>{T(),d(w=>w+1)},className:"text-foreground shrink-0 hover:underline",children:"Reload"})]}),L!==null&&h.jsx(qi,{reason:L}),h.jsx(Ai,{target:l,resolved:m,frameSource:z.frameSource,resolveError:v,reloadNonce:u,resourceErrorCount:N,title:t.title??"Embedded browser",onOpenExternally:q,onReload:()=>{T(),d(w=>w+1)},iframeRef:b,onFrameLoad:w=>{z.noteFrameLoaded(w),R()}})]})}function Bi({url:e,startEditing:t=!1,onSubmit:r}){const[n,s]=p.useState(t),[i,a]=p.useState(e);if(!n)return h.jsx(Wi,{url:e,onActivate:()=>{a(e),s(!0)}});const c=o=>{o.preventDefault(),s(!1),r(i)};return h.jsx("form",{onSubmit:c,className:"min-w-0 flex-1",children:h.jsx(jn,{"aria-label":"Address",autoFocus:!0,value:i,onChange:o=>a(o.target.value),onFocus:o=>o.currentTarget.select(),onBlur:()=>s(!1),onKeyDown:o=>{o.key==="Escape"&&(o.preventDefault(),s(!1))},spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"h-11 w-full text-base lg:h-7 lg:text-sm"})})}function Ui(e){return e.kind==="local"?e.path:e.kind==="url"?`${e.host}${e.rest}`:e.text}function Wi({url:e,onActivate:t}){const r=p.useMemo(()=>_i(e),[e]);return h.jsxs("button",{type:"button","aria-label":`Address: ${Ui(r)}`,onClick:t,className:"text-muted-foreground hover:bg-muted focus-ring flex h-11 min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 text-left text-sm transition-colors lg:h-7",children:[r.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:r.path})]}),r.kind==="url"&&h.jsxs("span",{className:"truncate",children:[h.jsx("span",{className:"text-foreground",children:r.host}),h.jsx("span",{className:"text-muted-foreground",children:r.rest})]}),r.kind==="raw"&&h.jsx("span",{className:"truncate",children:r.text})]})}function nt({label:e,disabled:t,onClick:r,children:n}){return h.jsx("button",{type:"button","aria-label":e,disabled:t,onClick:r,className:Bt("text-muted-foreground hover:text-foreground hover:bg-muted focus-ring flex size-11 shrink-0 items-center justify-center rounded-md transition-colors lg:size-7",t&&"pointer-events-none opacity-40"),children:n})}const $i=4096;function Hi(e){return e.toLowerCase().endsWith(".md")?e.slice(0,-3):e}function Gi(e){const t=e.trim(),r=/^(["'])(.*)\1$/.exec(t);return r?r[2].trim():/^[|>][+-]?\d*$/.test(t)?"":t.replace(/\s+#.*$/,"").trim()}function Vi(e,t){var i;const r=e.replace(/^\uFEFF/,"").split(/\r?\n/);let n=0;if(r[0]==="---"){for(n=1;n<r.length;n+=1){const a=r[n];if(a==="---"||a==="...")break;const c=/^title:(.*)$/.exec(a);if(c){const o=Gi(c[1]);if(o!=="")return o}}n+=1}let s=null;for(;n<r.length;n+=1){const a=r[n],c=(i=/^ {0,3}(`{3,}|~{3,})/.exec(a))==null?void 0:i[1];if(c){s===null?s=c[0]:c[0]===s&&(s=null);continue}if(s!==null)continue;const o=/^ {0,3}#[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/.exec(a);if(o&&o[1].trim()!=="")return o[1].trim()}return Hi(t)}function Ji(e,t,r=$i){let n=new TextDecoder().decode(e.subarray(0,r));return e.length>=r&&(n=n.slice(0,Math.max(0,n.lastIndexOf(`
|
|
27
|
-
`)))),Vi(n,t)}function Zi(e,t){return Ji(new TextEncoder().encode(e),t)}const Hr=K({path:le().min(1),title:le(),slug:le()});K({root:le(),docs:Et(Hr),truncated:ut()});K({cwd:le().min(1)});K({cwd:le().min(1),target:le().min(1).max(1e3),from:le().min(1).optional()});K({doc:Hr.nullable(),complete:ut()});const Ft=".md";function we(e){return e.normalize("NFC").trim().toLowerCase()}function Gr(e){return we(e).replace(/\s+/g,"-")}function Ue(e){return e.toLowerCase().endsWith(Ft)?e.slice(0,-Ft.length):e}function gr(e){return e.slice(e.lastIndexOf("/")+1)}function ot(e){const t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}function pt(e){return e===""?[]:e.split("/")}function Xi(e,t){const r=pt(e);for(const n of t.split("/"))if(!(n===""||n==="."))if(n===".."){if(r.length===0)return null;r.pop()}else r.push(n);return r.length===0?null:r.join("/")}function vr(e,t){const r=pt(e),n=pt(t);let s=0;for(;s<r.length&&s<n.length&&r[s]===n[s];)s+=1;return r.length-s+(n.length-s)}function Yi(e){return Gr(e).replace(/[^\p{L}\p{N}_-]/gu,"")}function Qi(e,t,r=null){const n=r&&r.trim()!==""?`#${Yi(r)}`:"",s=e===null?null:e.normalize("NFC"),i=t.normalize("NFC");if(s===i&&n)return n;const a=pt(s===null?"":ot(s)),c=i.split("/");let o=0;for(;o<a.length&&o<c.length-1&&a[o]===c[o];)o+=1;return[...Array.from({length:a.length-o},()=>".."),...c.slice(o)].map(encodeURIComponent).join("/")+n}const Ki=/[[\]|#\n\r]/,eo=20;function to(e){const t=e.map(c=>({doc:c,folder:ot(c.path),path:we(c.path),title:we(c.title),base:we(Ue(gr(c.path)))})),r=new Map(t.map(c=>[c.path,c])),n=c=>(o,u)=>vr(c,o.folder)-vr(c,u.folder)||o.doc.path.length-u.doc.path.length||(o.doc.path<u.doc.path?-1:o.doc.path>u.doc.path?1:0);function s(c,o){const u=Ue(c),d=c.startsWith("/")?[""]:[o,""];for(const f of d){const l=Xi(f,u);if(l===null)continue;const g=r.get(we(l+Ft));if(g)return g}}function i(c,o){const u=c.normalize("NFC").trim();if(u==="")return null;const d=o===null?"":ot(o);if(u.includes("/")){const m=s(u,d);if(m)return m}const f=we(u),l=we(Ue(u)),g=Gr(l),b=t.filter(m=>m.title===f||m.base===l||m.doc.slug===g);return b.length===0?null:b.sort(n(d))[0]??null}function a(c,o){const u=[c.doc.title.trim(),Ue(gr(c.doc.path)),`/${Ue(c.doc.path)}`];for(const d of u)if(!(d===""||Ki.test(d))&&i(d,o)===c)return d;return null}return{docs:e,resolve:(c,o)=>{var u;return((u=i(c,o))==null?void 0:u.doc)??null},search(c,o,u=eo){const d=we(c),f=o===null?"":ot(o),l=o===null?null:we(o),g=[];for(const v of t){if(v.path===l)continue;const N=d===""||v.title.startsWith(d)?0:v.title.split(/[\s\-_/]+/).some(T=>T.startsWith(d))?1:v.title.includes(d)?2:v.path.includes(d)?3:-1;N>=0&&g.push({entry:v,score:N})}const b=n(f);g.sort((v,N)=>v.score-N.score||b(v.entry,N.entry));const m=[];for(const{entry:v}of g){if(m.length>=u)break;const N=a(v,o);N!==null&&m.push({target:N,title:v.doc.title,description:v.doc.path})}return m}}}function br(e,t){const r=t.normalize("NFC").replaceAll("\\","/"),n=r.startsWith("/")||/^[A-Za-z]:\//.test(r);let s=r;if(n){const a=e.normalize("NFC").replaceAll("\\","/").replace(/\/+$/,"");if(!r.startsWith(`${a}/`))return null;s=r.slice(a.length+1)}const i=[];for(const a of s.split("/"))if(!(a===""||a==="."))if(a===".."){if(i.length===0)return null;i.pop()}else i.push(a);return i.length===0?null:i.join("/")}const yr="Links within this doc don’t open.",wr="This folder is too big to check this link.",xr="Couldn’t check this link.";function kr(e,t,r){return{exists:!0,href:Qi(e,t.path,r),title:t.title}}function ro(e){const{index:t,truncated:r,docPath:n,lookup:s,open:i,refuse:a}=e,c=new Map,o=f=>{const l=f.normalize("NFC").trim().toLowerCase();let g=c.get(l);return g||(g=s(f.trim()).catch(()=>null),c.set(l,g)),g};return{resolve:f=>{if(f.target.trim()==="")return{exists:!1,title:yr};const l=t.resolve(f.target,n);return l?kr(n,l,f.heading):r?o(f.target).then(g=>g===null?{exists:!0,title:xr}:g.doc?kr(n,g.doc,f.heading):g.complete?{exists:!1}:{exists:!0,title:wr}):{exists:!1}},search:f=>t.search(f,n),onOpen:f=>{const l=f.target.trim();if(l===""){a(yr);return}const g=`No doc called “${l}” yet.`,b=t.resolve(l,n);if(b){i(b.path);return}if(!r){a(g);return}o(l).then(m=>{m!=null&&m.doc?i(m.doc.path):a(m===null?xr:m.complete?g:wr)})}}}function no({cwd:e,sourcePath:t,content:r="",saved:n=!1}){const{enabled:s}=On(En),i=s&&!!e&&!!t,{data:a}=Vn(e,i),c=Jn(),o=ae(),{setTheme:u}=Sn(),d=i&&a&&e&&t?br(e,t)??br(a.root,t):null,f=p.useMemo(()=>a?to(a.docs):null,[a]),l=p.useRef({index:f,docPath:d,content:r,cwd:e});p.useEffect(()=>{l.current={index:f,docPath:d,content:r,cwd:e}}),p.useEffect(()=>{const{index:b,docPath:m,content:v,cwd:N}=l.current;if(!n||!b||m===null)return;const T=b.docs.find(z=>z.path.normalize("NFC").toLowerCase()===m.toLowerCase()),R=m.slice(m.lastIndexOf("/")+1);(!T||T.title!==Zi(v,R))&&c(N)},[n,c]);const g=p.useCallback(b=>{_n({getStore:Y.getState,setTheme:u,supportsTerminal:o.supportsTerminal},{action:"open_file",sourcePath:b},"user")},[u,o]);return p.useMemo(()=>{if(!(!f||!a||d===null||!e))return ro({index:f,truncated:a.truncated,docPath:d,lookup:b=>o.resolveDocLink(e,b,d),open:g,refuse:b=>Dn.info(b)})},[f,a,d,e,o,g])}function so(e){return typeof e=="object"&&e!==null&&e.status===404}function io({owner:e,getOwner:t,readTail:r,writeTail:n,transport:s,cwd:i,sourcePath:a,documentId:c,pending:o}){const u=()=>{var m,v;return((m=t())==null?void 0:m.recoveryGate)==="unsupported"||((v=t())==null?void 0:v.recoveryGate)==="observed_clear"},d=m=>{var T;const v=In.parse(m),N=(T=t())==null?void 0:T.recoveryBinding;if(!N||v.documentId!==c||!Q(v.incarnation,N.incarnation))throw new Error("Original save scope changed");return v},f=s.originalFileSaveRecovery,l=()=>{var m;try{const v=t();return(v==null?void 0:v.identity)===e&&v.active&&!!((m=v.recoveryBinding)!=null&&m.current())}catch{return!1}},g=(m,v,N=!1,T=!1)=>{if(!f||!l())return Promise.resolve({status:"idle"});const R=t(),z={},L=()=>t()===R&&l()&&(!v||R.recoveryBinding===v)&&(!N||R.recoveryWork===z),B=R.discovery;let H=!1;R.recoveryWork=z,R.recoveryGate="pending",R.recoveryBusy=!0;const x=r().catch(()=>{}).then(async()=>{try{if(!L())return{status:"idle"};const I=await m();return L()?(N&&(R.recoveryGate="observed_clear"),H=!0,{status:"observed",value:I}):{status:"idle"}}catch(I){return L()?(R.recoveryGate="unavailable",{status:T&&so(I)?"refused":"unavailable"}):{status:"idle"}}finally{!H&&R.discovery===B&&(R.discovery=void 0),R.recoveryWork===z&&(R.recoveryBusy=!1,R.recoveryWork=void 0)}});return N||n(x.then(()=>{})),x};return{identity:e,supported:!!f,current:l,discover:(m=!1)=>{if(!f||!l())return Promise.resolve({status:"idle"});const v=t(),N=v.recoveryBinding;if(v.discoveryBinding===N&&v.discovery&&(v.pendingDiscovery===v.discovery||!m&&v.recoveryGate==="observed_clear"))return v.discovery;const T=g(async()=>{const R=d(await f.discover(c));return t()===v&&v.recoveryBinding===N&&l()&&(v.recoveryGate=R.admission==="blocked"?"blocked":"observed_clear"),R},N,!1,!0);return v.discoveryBinding=N,v.discovery=T,v.pendingDiscovery=T,T.then(R=>{v.pendingDiscovery===T&&(v.pendingDiscovery=void 0),R.status==="idle"&&v.discovery===T&&(v.discovery=void 0)}),T},recover(m){if(o())return Promise.resolve({status:"local_uncertain"});const v=t();return g(async()=>{if(!v||o())throw new Error("Mounted original still uncertain");const N=v.recoveryBinding,T=Nn.parse(await f.recover(c,m,N.incarnation));if(t()!==v||!l()||T.documentId!==c||T.entry.eventId!==m||!Q(T.incarnation,N.incarnation))throw new Error("Original recovery scope changed");const R=d(await f.discover(c));return t()===v&&l()&&(v.recoveryGate=R.admission==="blocked"?"blocked":"observed_clear"),{result:T,discovery:R}})},inspectCurrent(){const m=t();return!m||!l()||o()||!u()?Promise.resolve({status:"local_uncertain"}):g(async()=>{const v=await s.readFileContent(i,a);if(!v||typeof v.content!="string"||typeof v.hash!="string"||!/^[a-f0-9]{64}$/u.test(v.hash))throw new Error("Current file evidence missing");return{content:v.content,hash:v.hash}},m.recoveryBinding,!0)}}}class Te extends Error{constructor(){super("The original save is not confirmed. Retry it before saving another draft.")}}class Ye extends Error{}function oo(){const e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(r=>r.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function ao(e){const t=e;return(t==null?void 0:t.status)===412&&t.code==="DOC_SAVE_FAILED"}var pe,Ae,tt,zt;class co{constructor(){Be(this,tt);Be(this,pe);Be(this,Ae)}get pending(){return Pe(this,pe)!==void 0}get receipt(){return Pe(this,Ae)}async write(t,r,n,s,i,a,c=!1){if(Pe(this,pe))throw new Te;if(be(this,Ae,void 0),!a)return t.writeFile(r,n,s,i);if(!c&&!a.current())throw new Ye;const o=Object.freeze({cwd:r,path:n,content:s,options:Object.freeze({...i,documentSave:Object.freeze({documentId:a.incarnation.documentId,eventId:oo(),incarnation:Object.freeze({...a.incarnation})})})});return be(this,pe,o),ye(this,tt,zt).call(this,t,o)}async retry(t,r){const n=Pe(this,pe);if(!(n!=null&&n.options.documentSave)||!r.current()||!Q(n.options.documentSave.incarnation,r.incarnation))throw new Ye;return{result:await ye(this,tt,zt).call(this,t,n),content:n.content}}}pe=new WeakMap,Ae=new WeakMap,tt=new WeakSet,zt=async function(t,r){try{const n=await t.writeFile(r.cwd,r.path,r.content,r.options);if(!n||typeof n!="object"||typeof n.ok!="boolean")throw new Te;if(!n.ok){if(!n.conflict||typeof n.conflict.currentHash!="string"||!n.conflict.currentHash||typeof n.conflict.currentContent!="string")throw new Te;return be(this,pe,void 0),n}if(typeof n.hash!="string"||!n.hash||n.effect!=="changed"&&n.effect!=="no_op")throw new Te;const s="documentReceipt"in n?Tn.parse(n.documentReceipt):void 0,i=r.options.documentSave;if(!s&&n.effect!=="no_op")throw new Te;if(s&&(s.documentId!==i.documentId||s.eventId!==i.eventId||!Q(s.incarnation,i.incarnation)||s.fileHash!==n.hash||(s.status==="accepted"?n.effect!=="changed":n.effect!=="no_op")))throw new Te;if((s==null?void 0:s.status)==="duplicate"){const a=await t.readFileContent(r.cwd,r.path);if(!a||typeof a!="object"||Array.isArray(a)||typeof a.hash!="string"||!a.hash||typeof a.content!="string")throw new Te;if(a.hash!==s.fileHash||a.content!==r.content)return be(this,Ae,s),be(this,pe,void 0),{ok:!1,conflict:{currentHash:a.hash,currentContent:a.content}}}return be(this,Ae,s),be(this,pe,void 0),n}catch(n){throw ao(n)&&be(this,pe,void 0),n}};function uo({sourcePath:e,cwd:t,loadedContent:r,documentId:n,documentSaveBinding:s,documentRecoveryBinding:i}){const a=ae(),c=(s==null?void 0:s.incarnation)??(i==null?void 0:i.incarnation),o=c?JSON.stringify([c.documentId,c.physicalOpenedAt,c.channelCreatedAt,c.generation]):void 0,u=p.useRef(new co),d=p.useMemo(()=>({sourcePath:e,cwd:t,documentId:n,transport:a,birthKey:o}),[e,t,n,a,o]),f=p.useRef(null),l=p.useRef(null),g=p.useRef(Promise.resolve()),b=p.useCallback(()=>{var w;return((w=l.current)==null?void 0:w.identity)===d&&l.current.active},[d]);p.useLayoutEffect(()=>{var w;return((w=l.current)==null?void 0:w.identity)!==d?l.current={identity:d,baseHash:null,baseContent:r,active:!0,recoveryBinding:i,recoveryGate:i&&a.originalFileSaveRecovery?"pending":"unsupported"}:(l.current.active=!0,l.current.recoveryBinding=i),()=>{var C;((C=l.current)==null?void 0:C.identity)===d&&(l.current.active=!1)}},[d,r,i,a]);const[m,v]=p.useState({owner:d,status:"idle",conflict:null}),N=m.owner===d?m.status:"idle",T=m.owner===d?m.conflict:null,R=p.useCallback((w,C,U)=>{b()&&v(G=>({owner:d,status:w,documentReceipt:C,confirmedContent:U,conflict:G.owner===d?G.conflict:null}))},[d,b]),z=p.useCallback(w=>{b()&&v(C=>({owner:d,conflict:w,status:C.owner===d?C.status:"idle"}))},[d,b]),L=p.useCallback(()=>{var w,C;return((w=l.current)==null?void 0:w.recoveryGate)==="unsupported"||((C=l.current)==null?void 0:C.recoveryGate)==="observed_clear"},[]),B=p.useMemo(()=>{const w=()=>io({owner:d,getOwner:()=>l.current,readTail:()=>g.current,writeTail:C=>{g.current=C},transport:a,cwd:t,sourcePath:e,documentId:n,pending:()=>u.current.pending});return{identity:d,supported:!!a.originalFileSaveRecovery,current:()=>w().current(),discover:C=>w().discover(C),recover:C=>w().recover(C),inspectCurrent:()=>w().inspectCurrent()}},[d,a,t,e,n]),H=!!(e&&t),x=p.useCallback((w,C,U,G=!1)=>{const Z=()=>b()&&l.current===w&&(!s||s.current());if(C.ok){if(typeof C.hash!="string"||!C.hash||C.effect!=="changed"&&C.effect!=="no_op")throw new Error("Invalid file save acknowledgement");return w.baseHash=C.hash,w.baseContent=U,!G&&!Z()?{status:"idle"}:(G||(z(null),R("saved",u.current.receipt,U)),{status:C.effect,confirmed:{hash:C.hash,content:U}})}return!G&&!Z()?{status:"idle"}:(G||(z(C.conflict),R("conflict")),{status:"conflict"})},[b,s,z,R]),I=p.useCallback(async(w,C)=>{if(!b())return{status:"idle"};const U=l.current;s&&!u.current.pending&&(f.current=d);const G=await u.current.write(a,t,e,w,C,s);return x(U,G,w)},[b,a,t,e,s,x,d]),M=p.useCallback(w=>{var G;if(!H||!b())return Promise.resolve({status:"idle"});const C=((G=l.current.finalToken)==null?void 0:G.content)===w?l.current.finalToken:void 0,U=g.current.catch(()=>{}).then(async()=>{if(!b()||s&&!s.current())return{status:"idle"};if(u.current.pending)return R("uncertain"),{status:"uncertain"};if(!L())return R("error"),{status:"error"};l.current.finalToken===C&&(l.current.finalToken=void 0),R("saving");try{const Z=l.current.baseHash!==null?{expectedHash:l.current.baseHash}:{expectedContent:l.current.baseContent};return await I(w,Z)}catch(Z){if(Z instanceof Ye)return{status:"idle"};if(!b()||s&&!s.current())return{status:"idle"};const se=u.current.pending?"uncertain":"error";return R(se),{status:se}}});return g.current=U.then(()=>{}),U},[H,I,b,R,s,L]),W=p.useCallback(w=>{if(!H||!b()||s&&!s.current())return null;const C=l.current,U={content:w,id:Symbol("buffered canvas draft")};return C.finalToken=U,{cancel(){C.finalToken===U&&(C.finalToken=void 0)},flush(){if(C.finalToken!==U||l.current!==C||C.active)return Promise.resolve({status:"idle"});C.finalToken=void 0;const G=g.current.catch(()=>{}).then(async()=>{if(l.current!==C||C.active)return{status:"idle"};try{if(C.recoveryGate!=="unsupported"&&C.recoveryGate!=="observed_clear")return{status:"error"};const Z=C.baseHash!==null?{expectedHash:C.baseHash}:{expectedContent:C.baseContent};s&&!u.current.pending&&(f.current=d);const se=await u.current.write(a,t,e,w,Z,s,!0);return x(C,se,w,!0)}catch{return{status:"error"}}});return g.current=G.then(()=>{}),G}}},[H,b,a,t,e,s,x,d]),j=p.useCallback(async w=>{const C=l.current;return!C||C.identity!==d?!1:(await g.current.catch(()=>{}),l.current===C&&!u.current.pending&&C.baseContent===w)},[d]),O=p.useCallback(()=>{if(!b()||!s||f.current!==d)return Promise.resolve({status:"idle"});const w=l.current,C=g.current.catch(()=>{}).then(async()=>{if(!b()||l.current!==w||f.current!==d)return{status:"idle"};try{R("saving");const U=await u.current.retry(a,s);return x(w,U.result,U.content)}catch(U){if(U instanceof Ye||!b()||l.current!==w)return{status:"idle"};const G=u.current.pending?"uncertain":"error";return R(G),{status:G}}});return g.current=C.then(()=>{}),C},[b,s,a,x,R,d]),k=p.useCallback(w=>{var Z;if(!H||!T||!b())return Promise.resolve({status:"idle"});const C=T.currentHash,U=((Z=l.current.finalToken)==null?void 0:Z.content)===w?l.current.finalToken:void 0,G=g.current.catch(()=>{}).then(async()=>{if(!b()||s&&!s.current())return{status:"idle"};if(u.current.pending)return R("uncertain"),{status:"uncertain"};if(!L())return R("error"),{status:"error"};l.current.finalToken===U&&(l.current.finalToken=void 0),R("saving");try{return await I(w,{expectedHash:C})}catch(se){if(se instanceof Ye)return{status:"idle"};if(!b()||s&&!s.current())return{status:"idle"};const je=u.current.pending?"uncertain":"error";return R(je),{status:je}}});return g.current=G.then(()=>{}),G},[H,T,I,b,R,s,L]),A=p.useCallback(()=>{var w;return((w=l.current)==null?void 0:w.identity)===d?{hash:l.current.baseHash,content:l.current.baseContent}:{hash:null,content:r}},[d,r]),q=p.useCallback(()=>{if(!T||!b()||s&&!s.current())return null;l.current.finalToken=void 0;const w=T.currentContent;return l.current.baseHash=T.currentHash,l.current.baseContent=w,z(null),R("idle"),w},[T,b,z,R,s]);return{recovery:B,status:N,conflict:T,canSave:H,save:M,overwrite:k,adoptDisk:q,getConfirmedBase:A,prepareFinalSave:W,retryUnconfirmed:O,waitForCloseDrain:j,documentReceipt:m.owner===d?m.documentReceipt:void 0,confirmedContent:m.owner===d?m.confirmedContent:void 0}}const lo=p.lazy(()=>_e(()=>import("./BlintzCanvas-BgIQdpTx.js").then(e=>e.B),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.BlintzCanvas}))),fo=500;function ho(e){switch(e){case"saving":return"Saving…";case"saved":return"Saved";case"error":return"Couldn’t save";default:return null}}function po({content:e,documentId:t,onContentChange:r}){const[n,s]=p.useState(!1),[i,a]=p.useState(e.content),c=Y(k=>k.canvasSessionId),o=Y(k=>k.setDocumentEditing),u=Y(k=>{var A;return((A=k.openDocuments.find(q=>q.id===t))==null?void 0:A.editing)??!1}),d=Y(k=>k.selectedCwd),f=n&&u,l=uo({documentId:t,sourcePath:e.sourcePath,cwd:d,loadedContent:e.content}),g=l.canSave,b=no({cwd:d,sourcePath:g?e.sourcePath:null,content:i,saved:l.status==="saved"}),m=p.useRef(null),v=p.useRef(null),N=p.useRef(i),T=p.useRef(e),R=p.useRef(r),z=p.useRef(l.save),L=p.useRef(l.prepareFinalSave),B=p.useRef(null);p.useEffect(()=>{N.current=i,T.current=e,R.current=r,z.current=l.save,L.current=l.prepareFinalSave});const H=p.useCallback(k=>{Y.getState().canvasSessionId===m.current&&(R.current({...T.current,content:k}),z.current(k))},[]),x=p.useCallback(k=>{var A;a(k),N.current=k,(A=B.current)==null||A.cancel(),B.current=L.current(k),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{v.current=null,H(k)},fo)},[H]),I=()=>{m.current=Y.getState().canvasSessionId,a(e.content),s(!0),o(t,!0)},M=()=>{v.current&&(clearTimeout(v.current),v.current=null,H(N.current)),s(!1),o(t,!1)};p.useEffect(()=>{var k;f&&c!==m.current&&(v.current&&(clearTimeout(v.current),v.current=null),(k=B.current)==null||k.cancel(),B.current=null,s(!1),o(t,!1))},[c,f,t,o]),p.useEffect(()=>{var k;!n||f||(v.current&&clearTimeout(v.current),v.current=null,(k=B.current)==null||k.cancel(),B.current=null)},[f,n]),p.useEffect(()=>()=>{var k,A;v.current&&(clearTimeout(v.current),v.current=null,Y.getState().canvasSessionId===m.current&&R.current({...T.current,content:N.current})),Y.getState().canvasSessionId===m.current?(k=B.current)==null||k.flush():(A=B.current)==null||A.cancel(),B.current=null,o(t,!1)},[H,t,o]);const W=()=>{const k=l.adoptDisk();k!=null&&(r({...e,content:k}),a(k))},j=()=>{l.overwrite(N.current)},O=ho(l.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:[g&&O&&h.jsx("span",{className:"text-muted-foreground mt-3 text-xs","aria-live":"polite",children:O}),g&&h.jsx(it,{type:"button",variant:"ghost",size:"icon-md",className:"text-muted-foreground hover:text-foreground mt-2",onClick:f?M:I,"aria-label":f?"Finish editing":"Edit document",children:f?h.jsx(Or,{className:"size-4"}):h.jsx(Er,{className:"size-4"})})]}),l.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(it,{type:"button",variant:"ghost",size:"sm",className:"h-7",onClick:W,children:"Reload"}),h.jsx(it,{type:"button",variant:"destructive",size:"sm",className:"h-7",onClick:j,children:"Overwrite"})]}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(p.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading editor…"}),children:h.jsx(lo,{value:f?i:e.content,editable:f,onChange:f?x:void 0,wikiLinks:b})})})]})}function mo({content:e}){return h.jsx("div",{className:"p-4 font-mono text-sm",children:h.jsx(Vr,{value:e.data,depth:0})})}const go=20;function Vr({value:e,depth:t,keyName:r}){const[n,s]=p.useState(t>2),i=p.useCallback(()=>s(d=>!d),[]);if(t>=go)return h.jsx(We,{keyName:r,value:"[max depth]",className:"text-muted-foreground"});if(e===null)return h.jsx(We,{keyName:r,value:"null",className:"text-muted-foreground"});if(typeof e=="boolean")return h.jsx(We,{keyName:r,value:String(e),className:"text-blue-500"});if(typeof e=="number")return h.jsx(We,{keyName:r,value:String(e),className:"text-green-500"});if(typeof e=="string")return h.jsx(We,{keyName:r,value:`"${e}"`,className:"text-amber-500"});const a=Array.isArray(e),c=a?e.map((d,f)=>[String(f),d]):Object.entries(e),o=a?"[":"{",u=a?"]":"}";return h.jsxs("div",{style:{paddingLeft:t>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:i,children:[h.jsx(An,{className:Bt("size-3 transition-transform",!n&&"rotate-90")}),r!=null&&h.jsxs("span",{className:"text-foreground",children:[r,": "]}),h.jsxs("span",{className:"text-muted-foreground",children:[o,n&&` … ${c.length} items `,n&&u]})]}),!n&&h.jsxs(h.Fragment,{children:[c.map(([d,f])=>h.jsx(Vr,{keyName:a?void 0:d,value:f,depth:t+1},d)),h.jsx("div",{className:"text-muted-foreground",children:u})]})]})}function We({keyName:e,value:t,className:r}){return h.jsxs("div",{style:{paddingLeft:16},children:[e!=null&&h.jsxs("span",{className:"text-foreground",children:[e,": "]}),h.jsx("span",{className:r,children:t})]})}const vo=/^\/api\/rooms\/([A-Za-z0-9][A-Za-z0-9._-]*)\/canvas\/media\/([0-9a-f]{16}-[0-9a-f]{64}(?:\.[a-z0-9]{1,10})?)$/;function Jr(e,t){const r=vo.exec(e.trim());return r?t===void 0||r[1]===t:!1}const bo=new Set(["http:","https:"]);function yo(e){const t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||t[1].length===1?null:`${t[1].toLowerCase()}:`}const wo={image:"data:image/",pdf:"data:application/pdf"};function Zr(e,t,r){const n=e.trim();if(n.startsWith("data:"))return n.toLowerCase().startsWith(wo[t])?{url:n,error:null}:{url:null,error:"unsupported-data"};if(Jr(n))return{url:n,error:null};const s=yo(n);if(s!==null)return bo.has(s)?{url:n,error:null}:{url:null,error:"blocked"};const i=r(n);return i?{url:i,error:null}:{url:null,error:"local-unavailable"}}function Xr(e,t){switch(e){case"blocked":return`This ${t} source is blocked for safety.`;case"unsupported-data":return`This data URI isn’t a valid ${t} source.`;case"local-unavailable":return`Local ${t} files can’t be displayed here.`}}function xo({content:e}){const t=ae(),r=Y(d=>d.selectedCwd),n=p.useMemo(()=>Zr(e.src,"image",d=>t.mediaUrl(r??"",d)),[e.src,t,r]),[s,i]=p.useState("loading"),[a,c]=p.useState(e.src);a!==e.src&&(c(e.src),i("loading"));const o=e.alt??e.title??"Canvas image";if(n.url===null){const d=n.error?Xr(n.error,"image"):"";return h.jsx(Cr,{children:d})}const u=n.url;return h.jsxs("div",{className:"bg-muted/40 relative flex h-full items-center justify-center",children:[s==="loading"&&h.jsx("p",{className:"text-muted-foreground absolute text-sm","aria-live":"polite",children:"Loading image…"}),s==="error"?h.jsx(Cr,{children:"This image couldn’t be loaded."}):h.jsxs(zn,{centerOnInit:!0,doubleClick:{mode:"toggle"},wheel:{step:.15},children:[h.jsx(ko,{}),h.jsx(qn,{wrapperClass:"!h-full !w-full",contentClass:"!h-full !w-full flex items-center justify-center",children:h.jsx("img",{src:u,alt:o,onLoad:()=>i("loaded"),onError:()=>i("error"),className:Bt("max-h-full max-w-full object-contain transition-opacity",s==="loaded"?"opacity-100":"opacity-0")})})]})]})}function ko(){const{zoomIn:e,zoomOut:t,resetTransform:r}=Ln();return h.jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[h.jsx(Ot,{label:"Zoom in",onClick:()=>e(),children:h.jsx(Hn,{className:"size-4"})}),h.jsx(Ot,{label:"Zoom out",onClick:()=>t(),children:h.jsx(Gn,{className:"size-4"})}),h.jsx(Ot,{label:"Reset zoom",onClick:()=>r(),children:h.jsx($n,{className:"size-4"})})]})}function Ot({label:e,onClick:t,children:r}){return h.jsx("button",{type:"button",onClick:t,"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:r})}function Cr({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 Co({content:e}){const t=ae(),r=Mn().data,n=Y(o=>o.selectedCwd),s=p.useMemo(()=>Zr(e.src,"pdf",o=>t.mediaUrl(n??"",o)),[e.src,t,n]);if(s.url===null){const o=s.error?Xr(s.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:o})})}const i=s.url,a=e.title??"PDF document",c=new URL(i,window.location.href).origin===window.location.origin;return c&&!r?null:c&&(r==null?void 0:r.serverRole)==="hub"?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:"PDFs download here instead of opening."}),h.jsxs("a",{href:i,download:!0,className:"text-foreground focus-ring rounded-md underline underline-offset-4",children:["Download ",a]})]}):h.jsx("object",{data:i,type:"application/pdf",title:a,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 ",a," in a new tab"]})]})})}function jo(e){const t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||t[1].length===1?null:`${t[1].toLowerCase()}:`}const Ro=new Set(["http:","https:","data:"]);function Yr(e,t,r){const n=e.trim();if(Jr(n))return{url:n};const s=jo(n);return s!==null?Ro.has(s)?s==="data:"&&r!==void 0?n.toLowerCase().startsWith(r)?{url:n}:{url:null}:{url:n}:{url:null}:{url:t(n)}}function Oo({content:e}){const t=ae(),r=Y(i=>i.selectedCwd),n=p.useMemo(()=>Yr(e.src,i=>t.mediaUrl(r??"",i),"data:audio/"),[e.src,t,r]),s=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":s,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 ",s]}),"."]})})})}function Eo({content:e}){const t=ae(),r=Y(i=>i.selectedCwd),n=p.useMemo(()=>Yr(e.src,i=>t.mediaUrl(r??"",i),"data:video/"),[e.src,t,r]),s=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":s,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 ",s]}),"."]})})})}function Qr({content:e,documentId:t,channel:r}){const[n]=Lt(),s=Pn(e.definition),i=p.useMemo(()=>JSON.stringify(e.definition),[e.definition]);return h.jsx("div",{className:"p-4",children:s.ok?h.jsx(Bn,{channel:r,document:s.document,sessionId:n??void 0},r?t??r.documentId:i):h.jsx(Un,{error:s.error,raw:s.raw})})}function So({content:e}){const[t]=Lt();return t?h.jsx("div",{className:"h-full w-full",children:h.jsx(Wn,{sessionId:t,serverName:e.serverName,uri:e.uri,title:e.title})}):null}const _o=p.lazy(()=>_e(()=>import("./CanvasFileContent-DR5pUgca.js"),__vite__mapDeps([6,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasFileContent}))),Do=p.lazy(()=>_e(()=>import("./CanvasModel3dContent-OP1ZOMui.js"),__vite__mapDeps([22,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasModel3dContent}))),Io=p.lazy(()=>_e(()=>import("./CanvasCsvContent-ZWHWmb88.js"),__vite__mapDeps([23,1,2,24,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasCsvContent}))),No=p.lazy(()=>_e(()=>import("./index-YUtEyz7O.js").then(e=>e.vK),__vite__mapDeps([1,2])).then(e=>({default:e.CanvasDiffContent})));function Xo({documentId:e,widgetChannel:t,content:r,onContentChange:n}){switch(r.type){case"url":case"browser":return h.jsx(Pi,{documentId:e,content:r},`${e}:${r.url}`);case"markdown":return h.jsx(po,{documentId:e,content:r,onContentChange:n},r.sourcePath??"generated");case"json":return h.jsx(mo,{content:r});case"image":return h.jsx(xo,{content:r});case"pdf":return h.jsx(Co,{content:r});case"audio":return h.jsx(Oo,{content:r});case"video":return h.jsx(Eo,{content:r});case"widget":return t?h.jsx(Qr,{content:r,documentId:e,channel:t}):h.jsx(To,{documentId:e,content:r});case"mcp_app":return h.jsx(So,{content:r});case"file":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(_o,{documentId:e,content:r})});case"model3d":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(Do,{content:r})});case"csv":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(Io,{content:r})});case"diff":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(No,{documentId:e,content:r},r.sourcePath)})}}function st(){return h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"})}function To({documentId:e,content:t}){const{channel:r}=Wr(e);return h.jsx(Qr,{documentId:e,content:t,channel:r})}const Ao=p.lazy(()=>_e(()=>import("./BlintzCanvas-BgIQdpTx.js").then(e=>e.B),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.BlintzCanvas})));function Yo({roomId:e,document:t,content:r,onSave:n}){const[s,i]=p.useState(null),[a,c]=p.useState(!1),[o,u]=p.useState(null),d=s!==null,f=r.sourcePath===void 0;yi(e,d?t.id:null);const l=async()=>{if(s===null)return;if(s===r.content){i(null),u(null);return}c(!0),u(null);const g=await n(t.id,{...r,content:s});c(!1),g?i(null):u("Couldn’t save. Your words are still here. Try again.")};return h.jsxs("div",{className:"flex h-full flex-col",children:[f&&h.jsxs("div",{className:"flex items-center justify-end gap-2 border-b px-2 py-1",children:[d&&h.jsx("span",{className:"text-muted-foreground text-xs",children:a?"Saving…":"Everyone sees your save."}),h.jsx(it,{type:"button",size:"xs",variant:"ghost",disabled:a,"aria-label":d?"Save for the room":"Edit this document",onClick:()=>d?void l():i(r.content),children:d?h.jsx(Or,{className:"size-3.5"}):h.jsx(Er,{className:"size-3.5"})})]}),o!==null&&h.jsx("p",{role:"status",className:"text-destructive border-b px-2 py-1 text-xs",children:o}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(p.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"}),children:h.jsx(Ao,{value:s??r.content,editable:d,onChange:i},d?"editing":`rev-${t.rev}`)})})]})}const qt="dorkos-canvas-sessions",Mo=1440*60*60*1e3;function Kr(){try{const e=localStorage.getItem(qt);if(!e)return null;const t=JSON.parse(e);return t===null||typeof t!="object"?null:t}catch{return null}}function en(e){try{Object.keys(e).length===0?localStorage.removeItem(qt):localStorage.setItem(qt,JSON.stringify(e))}catch{}}function Fo(e){return Array.isArray(e.documents)?[...e.documents].sort((t,r)=>(t.openedAt??0)-(r.openedAt??0)).map(t=>t.content).filter(t=>!!t):e.content?[e.content]:[]}function mt(e){return e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(mt).join(",")}]`:`{${Object.entries(e).filter(([,r])=>r!==void 0).sort(([r],[n])=>r<n?-1:r>n?1:0).map(([r,n])=>`${JSON.stringify(r)}:${mt(n)}`).join(",")}}`}function zo(e,t){const r=new Set,n=new Map;for(const i of e){const a=rr(i.content);if(a!==null){r.add(a);continue}const c=mt(i.content);n.set(c,(n.get(c)??0)+1)}const s=[];for(const i of t){const a=rr(i);if(a!==null){r.has(a)||s.push(i);continue}const c=mt(i),o=n.get(c)??0;o>0?n.set(c,o-1):s.push(i)}return s}const at=new Set;function Qo(){at.clear()}function Ko(e,t={}){const r=ae(),n=t.canonical??!0;p.useEffect(()=>{e&&Y.getState().loadCanvasForSession(e)},[e]),p.useEffect(()=>{if(!e||!n||at.has(e))return;const s=Kr();if(!s)return;const i=s[e];if(!i){qo(s);return}at.add(e),(async()=>{try{const a=Fo(i),c=zo(await r.listSessionCanvas(e),a);if(c.length===0){jr(e);return}for(const o of c)await r.openSessionCanvasDocument(e,o);jr(e),Y.getState().hydrateCanvasFromSnapshot(e,await r.listSessionCanvas(e))}catch{at.delete(e)}})()},[e,n,r])}function jr(e){const t=Kr();if(!t)return;const{[e]:r,...n}=t;en(n)}function qo(e){const t=Date.now()-Mo,r=Object.entries(e).filter(([,n])=>n.accessedAt===void 0||n.accessedAt>=t);r.length!==Object.keys(e).length&&en(Object.fromEntries(r))}export{Xo as C,Jo as F,Yo as R,no as a,Wr as b,bi as c,vi as d,Zo as e,Qr as f,Qo as g,cs as h,Jr as i,Ko as j,Yr as r,uo as u};
|
|
26
|
+
${s}`:null,[d,f]=p.useState(null);return p.useLayoutEffect(()=>{if(u===null||o===null)return;const l=JSON.parse(o);let g=!0,b=0;const m=new WeakSet,v=N=>{const A=N.target;if(A===null||A!==e.current)return;const R=++b;if(m.has(A)){f(null);return}m.add(A),a.current.getFrameBridgeStatus(l).then(z=>{!g||R!==b||f(z.bridge==="refused"&&z.reason?{pageKey:u,reason:z.reason}:null)},()=>{})};return document.addEventListener("load",v,!0),()=>{g=!1,document.removeEventListener("load",v,!0)}},[u,o,e]),d!==null&&d.pageKey===u?d.reason:null}const vi=15e3;function bi(e){const t=e instanceof Error?e.message.trim():"";return t.length>0?t:"Couldn’t reach DorkOS. Check your network and try again."}function yi(e){const t=ae();return{open:p.useCallback(async r=>{await t.openRoomCanvasDocument(e,r)},[t,e]),update:p.useCallback(async(r,n)=>{await t.updateRoomCanvasDocument(e,r,{content:n})},[t,e]),pin:p.useCallback(async(r,n)=>{await t.updateRoomCanvasDocument(e,r,{pinned:n})},[t,e]),close:p.useCallback(async r=>{await t.closeRoomCanvasDocument(e,r)},[t,e])}}function wi(e,t){const r=ae(),n=Y(s=>s.setRoomCanvasEditing);p.useEffect(()=>{if(n(e,t),t===null)return;const s=a=>{r.setRoomCanvasEditing(e,t,a).catch(c=>{console.warn("[room-canvas] edit lock failed",{roomId:e,documentId:t,err:c})})};s(!0);const i=setInterval(()=>s(!0),vi);return()=>{clearInterval(i),s(!1),n(e,null)}},[r,e,t,n])}const xi=400;function Qo(e,t){const r=ae(),n=Y(s=>s.roomCanvasPresenceEpoch[e]??0);p.useEffect(()=>{const s=c=>{r.setRoomCanvasViewing(e,c).catch(o=>{console.warn("[room-canvas] could not say where we are looking",{roomId:e,err:o})})};let i=!1;const a=setTimeout(()=>{i=!0,s(t)},xi);return()=>{clearTimeout(a),i&&s(null)}},[r,e,t,n])}const ki="allow-scripts allow-forms allow-popups allow-modals",jt="allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-downloads",Ci=new Set(["javascript:","data:","blob:"]),ji=new Set(["localhost","127.0.0.1","0.0.0.0","[::1]","::1"]);function Gt(e){return ji.has(e)||e.endsWith(".localhost")}function Ri(e){return Gt(e)?"direct":"server"}function Ei(e,t){let r;try{r=new URL(e)}catch{return null}const n=r.searchParams.get(pr),s=new URL(r.origin),i=t.indexOf("?");return s.pathname=(i===-1?t:t.slice(0,i))||"/",s.search=i===-1?"":t.slice(i),n!==null&&s.searchParams.set(pr,n),s.toString()}const pr="__dorkos_preview",Oi="/__dorkos_preview/health";function Si(e){return e==="https:"?443:80}function Hr(e){let t;try{t=new URL(e)}catch{return{mode:"serve",path:e}}if(Ci.has(t.protocol))return{mode:"blocked"};if(t.protocol==="file:")return{mode:"serve",path:decodeURIComponent(t.pathname)};if(t.protocol==="http:"||t.protocol==="https:"){if(Gt(t.hostname)){const r=t.port?Number(t.port):Si(t.protocol);return{mode:"proxy",hostname:t.hostname,port:r,path:`${t.pathname}${t.search}`}}return{mode:"external",url:e}}return{mode:"blocked"}}function _i(e){const t=e.trim();if(t===""||/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||t.startsWith("/")||t.startsWith("./")||t.startsWith("../"))return t;const r=t.split("/")[0];if(t.includes("/")&&!r.includes(".")&&!r.includes(":"))return t;const s=r.split(":")[0];return`${Gt(s)?"http":"https"}://${t}`}function Di(e){const t=Hr(e);if(t.mode==="serve")return{kind:"local",path:t.path};if(t.mode==="blocked")return{kind:"raw",text:e};try{const r=new URL(e),n=r.host.replace(/^www\./,""),s=r.pathname==="/"&&r.search===""&&r.hash===""?"":`${r.pathname}${r.search}${r.hash}`;return{kind:"url",host:n,rest:s}}catch{return{kind:"raw",text:e}}}const Ii=2e3;async function mr(e,t=globalThis.fetch,r=Ii){const n=new AbortController,s=setTimeout(()=>n.abort(),r);try{return await t(e,{mode:"no-cors",cache:"no-store",signal:n.signal}),!0}catch{return n.signal.aborted}finally{clearTimeout(s)}}function Ni({target:e,currentUrl:t,strategy:r,cwd:n,reloadNonce:s}){const i=JSON.stringify([t,r,n,s]),[a,c]=p.useState(null),[o,u]=p.useState(null),[d,f]=p.useState(null),l=ae(),g=p.useRef(l);return p.useEffect(()=>{g.current=l}),p.useEffect(()=>{const b=g.current;let m=!1;const v=z=>{c(i),u(z)};async function N(z){if(n===null){f({kind:"no-session"});return}try{const L=await b.createServeUrl(n,z);if(m)return;L===null?f({kind:"unsupported"}):v({src:L,sandbox:ki,previewOrigin:null,bridgeEligibility:"served-document"})}catch{m||f({kind:"failed"})}}async function A(z,L){let B;try{const x=await b.probeLoopbackPort(z);B=x===null?"unknown":x.listening}catch{B="unknown"}if(m)return;let H=null;if(B!==!1){let x=null;try{x=await b.createProxyUrl(z)}catch{if(m)return;H={kind:"failed"}}if(m)return;if((x==null?void 0:x.unavailable)==="tunnel"){f({kind:"tunnel"});return}if((x==null?void 0:x.unavailable)==="no-port"&&(H={kind:"no-port"}),x!=null&&x.url){const I=new URL(x.url);if(await mr(`${I.origin}${Oi}`)){if(m)return;const M=Ei(x.url,L);if(M!==null){v({src:M,sandbox:jt,previewOrigin:I.origin,bridgeEligibility:"preview-listener"});return}}if(m)return;H={kind:"origin-unreachable",host:I.hostname,listenPort:I.port}}}if(r==="direct"&&await mr(t)){if(m)return;v({src:t,sandbox:jt,previewOrigin:null,bridgeEligibility:null});return}m||f(H??{kind:"no-upstream"})}async function R(){if(f(null),u(null),e.mode!=="blocked"){if(e.mode==="external"){v({src:e.url,sandbox:jt,previewOrigin:null,bridgeEligibility:null});return}return e.mode==="serve"?N(e.path):A(e.port,e.path)}}return R(),()=>{m=!0}},[e,t,r,n,s,i]),{resolved:a===i?o:null,resolveError:d}}const Ai=1e4;function Ti(e,t){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 ${t.mode==="proxy"?`${t.hostname}:${t.port}`:"that address"}. Start the dev server, then reload.`}}function Mi({target:e,resolved:t,frameSource:r,resolveError:n,reloadNonce:s,resourceErrorCount:i,title:a,onOpenExternally:c,onReload:o,iframeRef:u,onFrameLoad:d}){if(e.mode==="blocked")return h.jsx(Rt,{children:"This address is blocked for safety."});if(n!==null)return h.jsxs(Rt,{children:[h.jsx("p",{children:Ti(n,e)}),n.kind!=="no-session"&&n.kind!=="unsupported"&&h.jsx("button",{type:"button",onClick:o,className:"text-foreground mt-3 hover:underline",children:"Reload"})]});if(t===null||r===null)return h.jsx(Rt,{children:"Loading…"});const f=e.mode==="external";return h.jsx(Fi,{src:r,sandbox:t.sandbox,title:a,iframeRef:u,onFrameLoad:d,watchLoadDeadline:!f,resourceErrorCount:i,showEmbedFallback:f,onOpenExternally:c,onReload:o},`${r}:${s}`)}function Fi({src:e,sandbox:t,title:r,iframeRef:n,onFrameLoad:s,watchLoadDeadline:i,resourceErrorCount:a,showEmbedFallback:c,onOpenExternally:o,onReload:u}){const[d,f]=p.useState(!1),[l,g]=p.useState(!1);return p.useEffect(()=>{if(!i)return;const b=setTimeout(()=>g(!0),Ai);return()=>clearTimeout(b)},[i]),h.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[l&&!d&&h.jsx(gr,{onOpenExternally:o,onReload:u,children:"This preview is slow to load."}),a>0&&h.jsxs(gr,{onOpenExternally:o,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:t,onLoad:b=>{f(!0),s(b.currentTarget)},className:"min-h-0 w-full flex-1 border-0",title:r}),c&&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:o,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function gr({children:e,onOpenExternally:t,onReload:r}){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:[r&&h.jsx("button",{type:"button",onClick:r,className:"text-foreground hover:underline",children:"Reload"}),h.jsx("button",{type:"button",onClick:t,className:"text-foreground hover:underline",children:"Open in system browser"})]})]})}function Rt({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})}const zi=wn/(1024*1024),qi={csp:"This page’s security policy blocks added scripts, so it can’t talk to its agent.",encoding:"This page isn’t saved as UTF-8, so it can’t talk to its agent.",oversize:`This page is over ${zi} MB, so it can’t talk to its agent.`,"no-head":"This page has no <head> tag, so it can’t talk to its agent.",markup:"DorkOS can’t safely read this page’s <head>, so it can’t talk to its agent.","fixed-source":"DorkOS couldn’t connect this page to its agent."};function Li({reason:e}){return h.jsx("p",{role:"status","data-bridge-refusal":e,className:"text-muted-foreground border-border/60 border-b px-2 py-1 text-xs",children:qi[e]})}function Pi(e,t){if(e&&e.contentUrl===t&&e.stack.length>0){const r=Math.min(Math.max(e.cursor,0),e.stack.length-1);return{stack:e.stack,cursor:r}}return{stack:[t],cursor:0}}function Bi({documentId:e,content:t}){const r=Y(w=>w.selectedCwd),n=Y(w=>w.writeBrowserHistory),[s]=p.useState(()=>Pi(Y.getState().browserHistories[e],t.url)),[i,a]=p.useState(s.stack),[c,o]=p.useState(s.cursor),[u,d]=p.useState(0);p.useEffect(()=>{n(e,{contentUrl:t.url,stack:i,cursor:c})},[e,t.url,i,c,n]);const f=i[c],l=p.useMemo(()=>Hr(f),[f]),g=p.useMemo(()=>l.mode==="proxy"?Ri(window.location.hostname):null,[l]),b=p.useRef(null),{resolved:m,resolveError:v}=Ni({target:l,currentUrl:f,strategy:g,cwd:r,reloadNonce:u}),{resourceErrorCount:N,notePersonNavigated:A,noteFrameLoaded:R}=us({iframeRef:b,documentId:e,logicalUrl:f,reloadNonce:u,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),z=pi({iframeRef:b,documentId:e,logicalUrl:f,reloadNonce:u,previewOrigin:(m==null?void 0:m.previewOrigin)??null,bridgeEligibility:(m==null?void 0:m.bridgeEligibility)??null,resolvedSource:(m==null?void 0:m.src)??null}),L=gi({iframeRef:b,target:l,cwd:r,resolved:m,reloadNonce:u}),B=Y(w=>w.roomCanvasLiveRoomId),{open:H}=yi(B??""),[x,I]=p.useState(null),M=p.useCallback(w=>{a(C=>[...C.slice(0,c+1),w]),o(C=>C+1)},[c]),W=xn(B),j=Y(w=>B?w.roomCanvasEditing[B]??null:null);p.useEffect(()=>{if(W===null||j!==null||W.documentId!==e)return;const w=W.url;w===void 0||w===f||M(w)},[W,j,e,f,M]);const E=c>0,k=c<i.length-1,T=p.useCallback(w=>{const C=_i(w);if(!C||C===f){A(),d(U=>U+1);return}if(B){I(null),H({type:"browser",url:C}).catch(U=>{I({url:C,message:bi(U)})});return}A(),M(C)},[f,M,B,H,A]),q=()=>En(f);return h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsxs("div",{className:"border-border/60 flex shrink-0 flex-wrap items-center gap-1 border-b px-2 py-1 lg:h-9 lg:flex-nowrap lg:py-0",children:[h.jsx(nt,{label:"Back",disabled:!E,onClick:()=>o(w=>w-1),children:h.jsx(kn,{className:"size-4"})}),h.jsx(nt,{label:"Forward",disabled:!k,onClick:()=>o(w=>w+1),children:h.jsx(Cn,{className:"size-4"})}),h.jsx(nt,{label:"Reload",onClick:()=>d(w=>w+1),children:h.jsx(zn,{className:"size-4"})}),h.jsx("div",{className:"order-first flex w-full min-w-0 lg:order-none lg:w-auto lg:flex-1",children:h.jsx(Ui,{url:(x==null?void 0:x.url)??f,startEditing:x!==null,onSubmit:T},x===null?"address":`retry:${x.url}`)}),h.jsx(nt,{label:"Open in system browser",onClick:q,children:h.jsx(jn,{className:"size-4"})})]}),x!==null&&h.jsx("p",{role:"status",className:"text-destructive border-border/60 border-b px-2 py-1 text-xs",children:x.message}),z.requiresReload&&h.jsxs("div",{className:"text-muted-foreground border-border/60 flex items-center justify-between gap-2 border-b px-2 py-1 text-xs",children:[h.jsx("p",{role:"status",children:"Page is offline. Reload to reconnect."}),h.jsx("button",{type:"button","aria-label":"Reload to reconnect",onClick:()=>{A(),d(w=>w+1)},className:"text-foreground shrink-0 hover:underline",children:"Reload"})]}),L!==null&&h.jsx(Li,{reason:L}),h.jsx(Mi,{target:l,resolved:m,frameSource:z.frameSource,resolveError:v,reloadNonce:u,resourceErrorCount:N,title:t.title??"Embedded browser",onOpenExternally:q,onReload:()=>{A(),d(w=>w+1)},iframeRef:b,onFrameLoad:w=>{z.noteFrameLoaded(w),R()}})]})}function Ui({url:e,startEditing:t=!1,onSubmit:r}){const[n,s]=p.useState(t),[i,a]=p.useState(e);if(!n)return h.jsx($i,{url:e,onActivate:()=>{a(e),s(!0)}});const c=o=>{o.preventDefault(),s(!1),r(i)};return h.jsx("form",{onSubmit:c,className:"min-w-0 flex-1",children:h.jsx(Rn,{"aria-label":"Address",autoFocus:!0,value:i,onChange:o=>a(o.target.value),onFocus:o=>o.currentTarget.select(),onBlur:()=>s(!1),onKeyDown:o=>{o.key==="Escape"&&(o.preventDefault(),s(!1))},spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"h-11 w-full text-base lg:h-7 lg:text-sm"})})}function Wi(e){return e.kind==="local"?e.path:e.kind==="url"?`${e.host}${e.rest}`:e.text}function $i({url:e,onActivate:t}){const r=p.useMemo(()=>Di(e),[e]);return h.jsxs("button",{type:"button","aria-label":`Address: ${Wi(r)}`,onClick:t,className:"text-muted-foreground hover:bg-muted focus-ring flex h-11 min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 text-left text-sm transition-colors lg:h-7",children:[r.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:r.path})]}),r.kind==="url"&&h.jsxs("span",{className:"truncate",children:[h.jsx("span",{className:"text-foreground",children:r.host}),h.jsx("span",{className:"text-muted-foreground",children:r.rest})]}),r.kind==="raw"&&h.jsx("span",{className:"truncate",children:r.text})]})}function nt({label:e,disabled:t,onClick:r,children:n}){return h.jsx("button",{type:"button","aria-label":e,disabled:t,onClick:r,className:Ut("text-muted-foreground hover:text-foreground hover:bg-muted focus-ring flex size-11 shrink-0 items-center justify-center rounded-md transition-colors lg:size-7",t&&"pointer-events-none opacity-40"),children:n})}const Hi=4096;function Gi(e){return e.toLowerCase().endsWith(".md")?e.slice(0,-3):e}function Vi(e){const t=e.trim(),r=/^(["'])(.*)\1$/.exec(t);return r?r[2].trim():/^[|>][+-]?\d*$/.test(t)?"":t.replace(/\s+#.*$/,"").trim()}function Ji(e,t){var i;const r=e.replace(/^\uFEFF/,"").split(/\r?\n/);let n=0;if(r[0]==="---"){for(n=1;n<r.length;n+=1){const a=r[n];if(a==="---"||a==="...")break;const c=/^title:(.*)$/.exec(a);if(c){const o=Vi(c[1]);if(o!=="")return o}}n+=1}let s=null;for(;n<r.length;n+=1){const a=r[n],c=(i=/^ {0,3}(`{3,}|~{3,})/.exec(a))==null?void 0:i[1];if(c){s===null?s=c[0]:c[0]===s&&(s=null);continue}if(s!==null)continue;const o=Xi(a);if(o!=="")return o}return Gi(t)}const Zi=/[\r\u2028\u2029]/,Et=e=>e===" "||e===" ";function Xi(e){const t=/^ {0,3}#[ \t]/.exec(e);if(!t||Zi.test(e))return"";let r=t[0].length;for(;r<e.length&&Et(e[r]);)r+=1;let n=e.length;for(;n>r&&Et(e[n-1]);)n-=1;let s=n;for(;s>r&&e[s-1]==="#";)s-=1;return s<n&&s>r&&Et(e[s-1])&&(n=s),e.slice(r,n).trim()}function Yi(e,t,r=Hi){let n=new TextDecoder().decode(e.subarray(0,r));return e.length>=r&&(n=n.slice(0,Math.max(0,n.lastIndexOf(`
|
|
27
|
+
`)))),Ji(n,t)}function Qi(e,t){return Yi(new TextEncoder().encode(e),t)}const Gr=K({path:le().min(1),title:le(),slug:le()});K({root:le(),docs:St(Gr),truncated:ut()});K({cwd:le().min(1)});K({cwd:le().min(1),target:le().min(1).max(1e3),from:le().min(1).optional()});K({doc:Gr.nullable(),complete:ut()});const zt=".md";function we(e){return e.normalize("NFC").trim().toLowerCase()}function Vr(e){return we(e).replace(/\s+/g,"-")}function Ue(e){return e.toLowerCase().endsWith(zt)?e.slice(0,-zt.length):e}function vr(e){return e.slice(e.lastIndexOf("/")+1)}function ot(e){const t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}function pt(e){return e===""?[]:e.split("/")}function Ki(e,t){const r=pt(e);for(const n of t.split("/"))if(!(n===""||n==="."))if(n===".."){if(r.length===0)return null;r.pop()}else r.push(n);return r.length===0?null:r.join("/")}function br(e,t){const r=pt(e),n=pt(t);let s=0;for(;s<r.length&&s<n.length&&r[s]===n[s];)s+=1;return r.length-s+(n.length-s)}function eo(e){return Vr(e).replace(/[^\p{L}\p{N}_-]/gu,"")}function to(e,t,r=null){const n=r&&r.trim()!==""?`#${eo(r)}`:"",s=e===null?null:e.normalize("NFC"),i=t.normalize("NFC");if(s===i&&n)return n;const a=pt(s===null?"":ot(s)),c=i.split("/");let o=0;for(;o<a.length&&o<c.length-1&&a[o]===c[o];)o+=1;return[...Array.from({length:a.length-o},()=>".."),...c.slice(o)].map(encodeURIComponent).join("/")+n}const ro=/[[\]|#\n\r]/,no=20;function so(e){const t=e.map(c=>({doc:c,folder:ot(c.path),path:we(c.path),title:we(c.title),base:we(Ue(vr(c.path)))})),r=new Map(t.map(c=>[c.path,c])),n=c=>(o,u)=>br(c,o.folder)-br(c,u.folder)||o.doc.path.length-u.doc.path.length||(o.doc.path<u.doc.path?-1:o.doc.path>u.doc.path?1:0);function s(c,o){const u=Ue(c),d=c.startsWith("/")?[""]:[o,""];for(const f of d){const l=Ki(f,u);if(l===null)continue;const g=r.get(we(l+zt));if(g)return g}}function i(c,o){const u=c.normalize("NFC").trim();if(u==="")return null;const d=o===null?"":ot(o);if(u.includes("/")){const m=s(u,d);if(m)return m}const f=we(u),l=we(Ue(u)),g=Vr(l),b=t.filter(m=>m.title===f||m.base===l||m.doc.slug===g);return b.length===0?null:b.sort(n(d))[0]??null}function a(c,o){const u=[c.doc.title.trim(),Ue(vr(c.doc.path)),`/${Ue(c.doc.path)}`];for(const d of u)if(!(d===""||ro.test(d))&&i(d,o)===c)return d;return null}return{docs:e,resolve:(c,o)=>{var u;return((u=i(c,o))==null?void 0:u.doc)??null},search(c,o,u=no){const d=we(c),f=o===null?"":ot(o),l=o===null?null:we(o),g=[];for(const v of t){if(v.path===l)continue;const N=d===""||v.title.startsWith(d)?0:v.title.split(/[\s\-_/]+/).some(A=>A.startsWith(d))?1:v.title.includes(d)?2:v.path.includes(d)?3:-1;N>=0&&g.push({entry:v,score:N})}const b=n(f);g.sort((v,N)=>v.score-N.score||b(v.entry,N.entry));const m=[];for(const{entry:v}of g){if(m.length>=u)break;const N=a(v,o);N!==null&&m.push({target:N,title:v.doc.title,description:v.doc.path})}return m}}}function yr(e,t){const r=t.normalize("NFC").replaceAll("\\","/"),n=r.startsWith("/")||/^[A-Za-z]:\//.test(r);let s=r;if(n){const a=e.normalize("NFC").replaceAll("\\","/").replace(/\/+$/,"");if(!r.startsWith(`${a}/`))return null;s=r.slice(a.length+1)}const i=[];for(const a of s.split("/"))if(!(a===""||a==="."))if(a===".."){if(i.length===0)return null;i.pop()}else i.push(a);return i.length===0?null:i.join("/")}const wr="Links within this doc don’t open.",xr="This folder is too big to check this link.",kr="Couldn’t check this link.";function Cr(e,t,r){return{exists:!0,href:to(e,t.path,r),title:t.title}}function io(e){const{index:t,truncated:r,docPath:n,lookup:s,open:i,refuse:a}=e,c=new Map,o=f=>{const l=f.normalize("NFC").trim().toLowerCase();let g=c.get(l);return g||(g=s(f.trim()).catch(()=>null),c.set(l,g)),g};return{resolve:f=>{if(f.target.trim()==="")return{exists:!1,title:wr};const l=t.resolve(f.target,n);return l?Cr(n,l,f.heading):r?o(f.target).then(g=>g===null?{exists:!0,title:kr}:g.doc?Cr(n,g.doc,f.heading):g.complete?{exists:!1}:{exists:!0,title:xr}):{exists:!1}},search:f=>t.search(f,n),onOpen:f=>{const l=f.target.trim();if(l===""){a(wr);return}const g=`No doc called “${l}” yet.`,b=t.resolve(l,n);if(b){i(b.path);return}if(!r){a(g);return}o(l).then(m=>{m!=null&&m.doc?i(m.doc.path):a(m===null?kr:m.complete?g:xr)})}}}function oo({cwd:e,sourcePath:t,content:r="",saved:n=!1}){const{enabled:s}=On(Sn),i=s&&!!e&&!!t,{data:a}=Jn(e,i),c=Zn(),o=ae(),{setTheme:u}=_n(),d=i&&a&&e&&t?yr(e,t)??yr(a.root,t):null,f=p.useMemo(()=>a?so(a.docs):null,[a]),l=p.useRef({index:f,docPath:d,content:r,cwd:e});p.useEffect(()=>{l.current={index:f,docPath:d,content:r,cwd:e}}),p.useEffect(()=>{const{index:b,docPath:m,content:v,cwd:N}=l.current;if(!n||!b||m===null)return;const A=b.docs.find(z=>z.path.normalize("NFC").toLowerCase()===m.toLowerCase()),R=m.slice(m.lastIndexOf("/")+1);(!A||A.title!==Qi(v,R))&&c(N)},[n,c]);const g=p.useCallback(b=>{Dn({getStore:Y.getState,setTheme:u,supportsTerminal:o.supportsTerminal},{action:"open_file",sourcePath:b},"user")},[u,o]);return p.useMemo(()=>{if(!(!f||!a||d===null||!e))return io({index:f,truncated:a.truncated,docPath:d,lookup:b=>o.resolveDocLink(e,b,d),open:g,refuse:b=>In.info(b)})},[f,a,d,e,o,g])}function ao(e){return typeof e=="object"&&e!==null&&e.status===404}function co({owner:e,getOwner:t,readTail:r,writeTail:n,transport:s,cwd:i,sourcePath:a,documentId:c,pending:o}){const u=()=>{var m,v;return((m=t())==null?void 0:m.recoveryGate)==="unsupported"||((v=t())==null?void 0:v.recoveryGate)==="observed_clear"},d=m=>{var A;const v=Nn.parse(m),N=(A=t())==null?void 0:A.recoveryBinding;if(!N||v.documentId!==c||!Q(v.incarnation,N.incarnation))throw new Error("Original save scope changed");return v},f=s.originalFileSaveRecovery,l=()=>{var m;try{const v=t();return(v==null?void 0:v.identity)===e&&v.active&&!!((m=v.recoveryBinding)!=null&&m.current())}catch{return!1}},g=(m,v,N=!1,A=!1)=>{if(!f||!l())return Promise.resolve({status:"idle"});const R=t(),z={},L=()=>t()===R&&l()&&(!v||R.recoveryBinding===v)&&(!N||R.recoveryWork===z),B=R.discovery;let H=!1;R.recoveryWork=z,R.recoveryGate="pending",R.recoveryBusy=!0;const x=r().catch(()=>{}).then(async()=>{try{if(!L())return{status:"idle"};const I=await m();return L()?(N&&(R.recoveryGate="observed_clear"),H=!0,{status:"observed",value:I}):{status:"idle"}}catch(I){return L()?(R.recoveryGate="unavailable",{status:A&&ao(I)?"refused":"unavailable"}):{status:"idle"}}finally{!H&&R.discovery===B&&(R.discovery=void 0),R.recoveryWork===z&&(R.recoveryBusy=!1,R.recoveryWork=void 0)}});return N||n(x.then(()=>{})),x};return{identity:e,supported:!!f,current:l,discover:(m=!1)=>{if(!f||!l())return Promise.resolve({status:"idle"});const v=t(),N=v.recoveryBinding;if(v.discoveryBinding===N&&v.discovery&&(v.pendingDiscovery===v.discovery||!m&&v.recoveryGate==="observed_clear"))return v.discovery;const A=g(async()=>{const R=d(await f.discover(c));return t()===v&&v.recoveryBinding===N&&l()&&(v.recoveryGate=R.admission==="blocked"?"blocked":"observed_clear"),R},N,!1,!0);return v.discoveryBinding=N,v.discovery=A,v.pendingDiscovery=A,A.then(R=>{v.pendingDiscovery===A&&(v.pendingDiscovery=void 0),R.status==="idle"&&v.discovery===A&&(v.discovery=void 0)}),A},recover(m){if(o())return Promise.resolve({status:"local_uncertain"});const v=t();return g(async()=>{if(!v||o())throw new Error("Mounted original still uncertain");const N=v.recoveryBinding,A=An.parse(await f.recover(c,m,N.incarnation));if(t()!==v||!l()||A.documentId!==c||A.entry.eventId!==m||!Q(A.incarnation,N.incarnation))throw new Error("Original recovery scope changed");const R=d(await f.discover(c));return t()===v&&l()&&(v.recoveryGate=R.admission==="blocked"?"blocked":"observed_clear"),{result:A,discovery:R}})},inspectCurrent(){const m=t();return!m||!l()||o()||!u()?Promise.resolve({status:"local_uncertain"}):g(async()=>{const v=await s.readFileContent(i,a);if(!v||typeof v.content!="string"||typeof v.hash!="string"||!/^[a-f0-9]{64}$/u.test(v.hash))throw new Error("Current file evidence missing");return{content:v.content,hash:v.hash}},m.recoveryBinding,!0)}}}class Ae extends Error{constructor(){super("The original save is not confirmed. Retry it before saving another draft.")}}class Ye extends Error{}function uo(){const e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(r=>r.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function lo(e){const t=e;return(t==null?void 0:t.status)===412&&t.code==="DOC_SAVE_FAILED"}var pe,Te,tt,qt;class fo{constructor(){Be(this,tt);Be(this,pe);Be(this,Te)}get pending(){return Pe(this,pe)!==void 0}get receipt(){return Pe(this,Te)}async write(t,r,n,s,i,a,c=!1){if(Pe(this,pe))throw new Ae;if(be(this,Te,void 0),!a)return t.writeFile(r,n,s,i);if(!c&&!a.current())throw new Ye;const o=Object.freeze({cwd:r,path:n,content:s,options:Object.freeze({...i,documentSave:Object.freeze({documentId:a.incarnation.documentId,eventId:uo(),incarnation:Object.freeze({...a.incarnation})})})});return be(this,pe,o),ye(this,tt,qt).call(this,t,o)}async retry(t,r){const n=Pe(this,pe);if(!(n!=null&&n.options.documentSave)||!r.current()||!Q(n.options.documentSave.incarnation,r.incarnation))throw new Ye;return{result:await ye(this,tt,qt).call(this,t,n),content:n.content}}}pe=new WeakMap,Te=new WeakMap,tt=new WeakSet,qt=async function(t,r){try{const n=await t.writeFile(r.cwd,r.path,r.content,r.options);if(!n||typeof n!="object"||typeof n.ok!="boolean")throw new Ae;if(!n.ok){if(!n.conflict||typeof n.conflict.currentHash!="string"||!n.conflict.currentHash||typeof n.conflict.currentContent!="string")throw new Ae;return be(this,pe,void 0),n}if(typeof n.hash!="string"||!n.hash||n.effect!=="changed"&&n.effect!=="no_op")throw new Ae;const s="documentReceipt"in n?Tn.parse(n.documentReceipt):void 0,i=r.options.documentSave;if(!s&&n.effect!=="no_op")throw new Ae;if(s&&(s.documentId!==i.documentId||s.eventId!==i.eventId||!Q(s.incarnation,i.incarnation)||s.fileHash!==n.hash||(s.status==="accepted"?n.effect!=="changed":n.effect!=="no_op")))throw new Ae;if((s==null?void 0:s.status)==="duplicate"){const a=await t.readFileContent(r.cwd,r.path);if(!a||typeof a!="object"||Array.isArray(a)||typeof a.hash!="string"||!a.hash||typeof a.content!="string")throw new Ae;if(a.hash!==s.fileHash||a.content!==r.content)return be(this,Te,s),be(this,pe,void 0),{ok:!1,conflict:{currentHash:a.hash,currentContent:a.content}}}return be(this,Te,s),be(this,pe,void 0),n}catch(n){throw lo(n)&&be(this,pe,void 0),n}};function ho({sourcePath:e,cwd:t,loadedContent:r,documentId:n,documentSaveBinding:s,documentRecoveryBinding:i}){const a=ae(),c=(s==null?void 0:s.incarnation)??(i==null?void 0:i.incarnation),o=c?JSON.stringify([c.documentId,c.physicalOpenedAt,c.channelCreatedAt,c.generation]):void 0,u=p.useRef(new fo),d=p.useMemo(()=>({sourcePath:e,cwd:t,documentId:n,transport:a,birthKey:o}),[e,t,n,a,o]),f=p.useRef(null),l=p.useRef(null),g=p.useRef(Promise.resolve()),b=p.useCallback(()=>{var w;return((w=l.current)==null?void 0:w.identity)===d&&l.current.active},[d]);p.useLayoutEffect(()=>{var w;return((w=l.current)==null?void 0:w.identity)!==d?l.current={identity:d,baseHash:null,baseContent:r,active:!0,recoveryBinding:i,recoveryGate:i&&a.originalFileSaveRecovery?"pending":"unsupported"}:(l.current.active=!0,l.current.recoveryBinding=i),()=>{var C;((C=l.current)==null?void 0:C.identity)===d&&(l.current.active=!1)}},[d,r,i,a]);const[m,v]=p.useState({owner:d,status:"idle",conflict:null}),N=m.owner===d?m.status:"idle",A=m.owner===d?m.conflict:null,R=p.useCallback((w,C,U)=>{b()&&v(G=>({owner:d,status:w,documentReceipt:C,confirmedContent:U,conflict:G.owner===d?G.conflict:null}))},[d,b]),z=p.useCallback(w=>{b()&&v(C=>({owner:d,conflict:w,status:C.owner===d?C.status:"idle"}))},[d,b]),L=p.useCallback(()=>{var w,C;return((w=l.current)==null?void 0:w.recoveryGate)==="unsupported"||((C=l.current)==null?void 0:C.recoveryGate)==="observed_clear"},[]),B=p.useMemo(()=>{const w=()=>co({owner:d,getOwner:()=>l.current,readTail:()=>g.current,writeTail:C=>{g.current=C},transport:a,cwd:t,sourcePath:e,documentId:n,pending:()=>u.current.pending});return{identity:d,supported:!!a.originalFileSaveRecovery,current:()=>w().current(),discover:C=>w().discover(C),recover:C=>w().recover(C),inspectCurrent:()=>w().inspectCurrent()}},[d,a,t,e,n]),H=!!(e&&t),x=p.useCallback((w,C,U,G=!1)=>{const Z=()=>b()&&l.current===w&&(!s||s.current());if(C.ok){if(typeof C.hash!="string"||!C.hash||C.effect!=="changed"&&C.effect!=="no_op")throw new Error("Invalid file save acknowledgement");return w.baseHash=C.hash,w.baseContent=U,!G&&!Z()?{status:"idle"}:(G||(z(null),R("saved",u.current.receipt,U)),{status:C.effect,confirmed:{hash:C.hash,content:U}})}return!G&&!Z()?{status:"idle"}:(G||(z(C.conflict),R("conflict")),{status:"conflict"})},[b,s,z,R]),I=p.useCallback(async(w,C)=>{if(!b())return{status:"idle"};const U=l.current;s&&!u.current.pending&&(f.current=d);const G=await u.current.write(a,t,e,w,C,s);return x(U,G,w)},[b,a,t,e,s,x,d]),M=p.useCallback(w=>{var G;if(!H||!b())return Promise.resolve({status:"idle"});const C=((G=l.current.finalToken)==null?void 0:G.content)===w?l.current.finalToken:void 0,U=g.current.catch(()=>{}).then(async()=>{if(!b()||s&&!s.current())return{status:"idle"};if(u.current.pending)return R("uncertain"),{status:"uncertain"};if(!L())return R("error"),{status:"error"};l.current.finalToken===C&&(l.current.finalToken=void 0),R("saving");try{const Z=l.current.baseHash!==null?{expectedHash:l.current.baseHash}:{expectedContent:l.current.baseContent};return await I(w,Z)}catch(Z){if(Z instanceof Ye)return{status:"idle"};if(!b()||s&&!s.current())return{status:"idle"};const se=u.current.pending?"uncertain":"error";return R(se),{status:se}}});return g.current=U.then(()=>{}),U},[H,I,b,R,s,L]),W=p.useCallback(w=>{if(!H||!b()||s&&!s.current())return null;const C=l.current,U={content:w,id:Symbol("buffered canvas draft")};return C.finalToken=U,{cancel(){C.finalToken===U&&(C.finalToken=void 0)},flush(){if(C.finalToken!==U||l.current!==C||C.active)return Promise.resolve({status:"idle"});C.finalToken=void 0;const G=g.current.catch(()=>{}).then(async()=>{if(l.current!==C||C.active)return{status:"idle"};try{if(C.recoveryGate!=="unsupported"&&C.recoveryGate!=="observed_clear")return{status:"error"};const Z=C.baseHash!==null?{expectedHash:C.baseHash}:{expectedContent:C.baseContent};s&&!u.current.pending&&(f.current=d);const se=await u.current.write(a,t,e,w,Z,s,!0);return x(C,se,w,!0)}catch{return{status:"error"}}});return g.current=G.then(()=>{}),G}}},[H,b,a,t,e,s,x,d]),j=p.useCallback(async w=>{const C=l.current;return!C||C.identity!==d?!1:(await g.current.catch(()=>{}),l.current===C&&!u.current.pending&&C.baseContent===w)},[d]),E=p.useCallback(()=>{if(!b()||!s||f.current!==d)return Promise.resolve({status:"idle"});const w=l.current,C=g.current.catch(()=>{}).then(async()=>{if(!b()||l.current!==w||f.current!==d)return{status:"idle"};try{R("saving");const U=await u.current.retry(a,s);return x(w,U.result,U.content)}catch(U){if(U instanceof Ye||!b()||l.current!==w)return{status:"idle"};const G=u.current.pending?"uncertain":"error";return R(G),{status:G}}});return g.current=C.then(()=>{}),C},[b,s,a,x,R,d]),k=p.useCallback(w=>{var Z;if(!H||!A||!b())return Promise.resolve({status:"idle"});const C=A.currentHash,U=((Z=l.current.finalToken)==null?void 0:Z.content)===w?l.current.finalToken:void 0,G=g.current.catch(()=>{}).then(async()=>{if(!b()||s&&!s.current())return{status:"idle"};if(u.current.pending)return R("uncertain"),{status:"uncertain"};if(!L())return R("error"),{status:"error"};l.current.finalToken===U&&(l.current.finalToken=void 0),R("saving");try{return await I(w,{expectedHash:C})}catch(se){if(se instanceof Ye)return{status:"idle"};if(!b()||s&&!s.current())return{status:"idle"};const je=u.current.pending?"uncertain":"error";return R(je),{status:je}}});return g.current=G.then(()=>{}),G},[H,A,I,b,R,s,L]),T=p.useCallback(()=>{var w;return((w=l.current)==null?void 0:w.identity)===d?{hash:l.current.baseHash,content:l.current.baseContent}:{hash:null,content:r}},[d,r]),q=p.useCallback(()=>{if(!A||!b()||s&&!s.current())return null;l.current.finalToken=void 0;const w=A.currentContent;return l.current.baseHash=A.currentHash,l.current.baseContent=w,z(null),R("idle"),w},[A,b,z,R,s]);return{recovery:B,status:N,conflict:A,canSave:H,save:M,overwrite:k,adoptDisk:q,getConfirmedBase:T,prepareFinalSave:W,retryUnconfirmed:E,waitForCloseDrain:j,documentReceipt:m.owner===d?m.documentReceipt:void 0,confirmedContent:m.owner===d?m.confirmedContent:void 0}}const po=p.lazy(()=>_e(()=>import("./BlintzCanvas-DCXIQZM_.js").then(e=>e.B),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.BlintzCanvas}))),mo=500;function go(e){switch(e){case"saving":return"Saving…";case"saved":return"Saved";case"error":return"Couldn’t save";default:return null}}function vo({content:e,documentId:t,onContentChange:r}){const[n,s]=p.useState(!1),[i,a]=p.useState(e.content),c=Y(k=>k.canvasSessionId),o=Y(k=>k.setDocumentEditing),u=Y(k=>{var T;return((T=k.openDocuments.find(q=>q.id===t))==null?void 0:T.editing)??!1}),d=Y(k=>k.selectedCwd),f=n&&u,l=ho({documentId:t,sourcePath:e.sourcePath,cwd:d,loadedContent:e.content}),g=l.canSave,b=oo({cwd:d,sourcePath:g?e.sourcePath:null,content:i,saved:l.status==="saved"}),m=p.useRef(null),v=p.useRef(null),N=p.useRef(i),A=p.useRef(e),R=p.useRef(r),z=p.useRef(l.save),L=p.useRef(l.prepareFinalSave),B=p.useRef(null);p.useEffect(()=>{N.current=i,A.current=e,R.current=r,z.current=l.save,L.current=l.prepareFinalSave});const H=p.useCallback(k=>{Y.getState().canvasSessionId===m.current&&(R.current({...A.current,content:k}),z.current(k))},[]),x=p.useCallback(k=>{var T;a(k),N.current=k,(T=B.current)==null||T.cancel(),B.current=L.current(k),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{v.current=null,H(k)},mo)},[H]),I=()=>{m.current=Y.getState().canvasSessionId,a(e.content),s(!0),o(t,!0)},M=()=>{v.current&&(clearTimeout(v.current),v.current=null,H(N.current)),s(!1),o(t,!1)};p.useEffect(()=>{var k;f&&c!==m.current&&(v.current&&(clearTimeout(v.current),v.current=null),(k=B.current)==null||k.cancel(),B.current=null,s(!1),o(t,!1))},[c,f,t,o]),p.useEffect(()=>{var k;!n||f||(v.current&&clearTimeout(v.current),v.current=null,(k=B.current)==null||k.cancel(),B.current=null)},[f,n]),p.useEffect(()=>()=>{var k,T;v.current&&(clearTimeout(v.current),v.current=null,Y.getState().canvasSessionId===m.current&&R.current({...A.current,content:N.current})),Y.getState().canvasSessionId===m.current?(k=B.current)==null||k.flush():(T=B.current)==null||T.cancel(),B.current=null,o(t,!1)},[H,t,o]);const W=()=>{const k=l.adoptDisk();k!=null&&(r({...e,content:k}),a(k))},j=()=>{l.overwrite(N.current)},E=go(l.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:[g&&E&&h.jsx("span",{className:"text-muted-foreground mt-3 text-xs","aria-live":"polite",children:E}),g&&h.jsx(it,{type:"button",variant:"ghost",size:"icon-md",className:"text-muted-foreground hover:text-foreground mt-2",onClick:f?M:I,"aria-label":f?"Finish editing":"Edit document",children:f?h.jsx(Or,{className:"size-4"}):h.jsx(Sr,{className:"size-4"})})]}),l.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(it,{type:"button",variant:"ghost",size:"sm",className:"h-7",onClick:W,children:"Reload"}),h.jsx(it,{type:"button",variant:"destructive",size:"sm",className:"h-7",onClick:j,children:"Overwrite"})]}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(p.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading editor…"}),children:h.jsx(po,{value:f?i:e.content,editable:f,onChange:f?x:void 0,wikiLinks:b})})})]})}function bo({content:e}){return h.jsx("div",{className:"p-4 font-mono text-sm",children:h.jsx(Jr,{value:e.data,depth:0})})}const yo=20;function Jr({value:e,depth:t,keyName:r}){const[n,s]=p.useState(t>2),i=p.useCallback(()=>s(d=>!d),[]);if(t>=yo)return h.jsx(We,{keyName:r,value:"[max depth]",className:"text-muted-foreground"});if(e===null)return h.jsx(We,{keyName:r,value:"null",className:"text-muted-foreground"});if(typeof e=="boolean")return h.jsx(We,{keyName:r,value:String(e),className:"text-blue-500"});if(typeof e=="number")return h.jsx(We,{keyName:r,value:String(e),className:"text-green-500"});if(typeof e=="string")return h.jsx(We,{keyName:r,value:`"${e}"`,className:"text-amber-500"});const a=Array.isArray(e),c=a?e.map((d,f)=>[String(f),d]):Object.entries(e),o=a?"[":"{",u=a?"]":"}";return h.jsxs("div",{style:{paddingLeft:t>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:i,children:[h.jsx(Mn,{className:Ut("size-3 transition-transform",!n&&"rotate-90")}),r!=null&&h.jsxs("span",{className:"text-foreground",children:[r,": "]}),h.jsxs("span",{className:"text-muted-foreground",children:[o,n&&` … ${c.length} items `,n&&u]})]}),!n&&h.jsxs(h.Fragment,{children:[c.map(([d,f])=>h.jsx(Jr,{keyName:a?void 0:d,value:f,depth:t+1},d)),h.jsx("div",{className:"text-muted-foreground",children:u})]})]})}function We({keyName:e,value:t,className:r}){return h.jsxs("div",{style:{paddingLeft:16},children:[e!=null&&h.jsxs("span",{className:"text-foreground",children:[e,": "]}),h.jsx("span",{className:r,children:t})]})}const wo=/^\/api\/rooms\/([A-Za-z0-9][A-Za-z0-9._-]*)\/canvas\/media\/([0-9a-f]{16}-[0-9a-f]{64}(?:\.[a-z0-9]{1,10})?)$/;function Zr(e,t){const r=wo.exec(e.trim());return r?t===void 0||r[1]===t:!1}const xo=new Set(["http:","https:"]);function ko(e){const t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||t[1].length===1?null:`${t[1].toLowerCase()}:`}const Co={image:"data:image/",pdf:"data:application/pdf"};function Xr(e,t,r){const n=e.trim();if(n.startsWith("data:"))return n.toLowerCase().startsWith(Co[t])?{url:n,error:null}:{url:null,error:"unsupported-data"};if(Zr(n))return{url:n,error:null};const s=ko(n);if(s!==null)return xo.has(s)?{url:n,error:null}:{url:null,error:"blocked"};const i=r(n);return i?{url:i,error:null}:{url:null,error:"local-unavailable"}}function Yr(e,t){switch(e){case"blocked":return`This ${t} source is blocked for safety.`;case"unsupported-data":return`This data URI isn’t a valid ${t} source.`;case"local-unavailable":return`Local ${t} files can’t be displayed here.`}}function jo({content:e}){const t=ae(),r=Y(d=>d.selectedCwd),n=p.useMemo(()=>Xr(e.src,"image",d=>t.mediaUrl(r??"",d)),[e.src,t,r]),[s,i]=p.useState("loading"),[a,c]=p.useState(e.src);a!==e.src&&(c(e.src),i("loading"));const o=e.alt??e.title??"Canvas image";if(n.url===null){const d=n.error?Yr(n.error,"image"):"";return h.jsx(jr,{children:d})}const u=n.url;return h.jsxs("div",{className:"bg-muted/40 relative flex h-full items-center justify-center",children:[s==="loading"&&h.jsx("p",{className:"text-muted-foreground absolute text-sm","aria-live":"polite",children:"Loading image…"}),s==="error"?h.jsx(jr,{children:"This image couldn’t be loaded."}):h.jsxs(qn,{centerOnInit:!0,doubleClick:{mode:"toggle"},wheel:{step:.15},children:[h.jsx(Ro,{}),h.jsx(Ln,{wrapperClass:"!h-full !w-full",contentClass:"!h-full !w-full flex items-center justify-center",children:h.jsx("img",{src:u,alt:o,onLoad:()=>i("loaded"),onError:()=>i("error"),className:Ut("max-h-full max-w-full object-contain transition-opacity",s==="loaded"?"opacity-100":"opacity-0")})})]})]})}function Ro(){const{zoomIn:e,zoomOut:t,resetTransform:r}=Pn();return h.jsxs("div",{className:"absolute top-2 right-2 z-10 flex gap-1",children:[h.jsx(Ot,{label:"Zoom in",onClick:()=>e(),children:h.jsx(Gn,{className:"size-4"})}),h.jsx(Ot,{label:"Zoom out",onClick:()=>t(),children:h.jsx(Vn,{className:"size-4"})}),h.jsx(Ot,{label:"Reset zoom",onClick:()=>r(),children:h.jsx(Hn,{className:"size-4"})})]})}function Ot({label:e,onClick:t,children:r}){return h.jsx("button",{type:"button",onClick:t,"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:r})}function jr({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 Eo({content:e}){const t=ae(),r=Fn().data,n=Y(o=>o.selectedCwd),s=p.useMemo(()=>Xr(e.src,"pdf",o=>t.mediaUrl(n??"",o)),[e.src,t,n]);if(s.url===null){const o=s.error?Yr(s.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:o})})}const i=s.url,a=e.title??"PDF document",c=new URL(i,window.location.href).origin===window.location.origin;return c&&!r?null:c&&(r==null?void 0:r.serverRole)==="hub"?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:"PDFs download here instead of opening."}),h.jsxs("a",{href:i,download:!0,className:"text-foreground focus-ring rounded-md underline underline-offset-4",children:["Download ",a]})]}):h.jsx("object",{data:i,type:"application/pdf",title:a,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 ",a," in a new tab"]})]})})}function Oo(e){const t=/^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(e);return!t||t[1].length===1?null:`${t[1].toLowerCase()}:`}const So=new Set(["http:","https:","data:"]);function Qr(e,t,r){const n=e.trim();if(Zr(n))return{url:n};const s=Oo(n);return s!==null?So.has(s)?s==="data:"&&r!==void 0?n.toLowerCase().startsWith(r)?{url:n}:{url:null}:{url:n}:{url:null}:{url:t(n)}}function _o({content:e}){const t=ae(),r=Y(i=>i.selectedCwd),n=p.useMemo(()=>Qr(e.src,i=>t.mediaUrl(r??"",i),"data:audio/"),[e.src,t,r]),s=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":s,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 ",s]}),"."]})})})}function Do({content:e}){const t=ae(),r=Y(i=>i.selectedCwd),n=p.useMemo(()=>Qr(e.src,i=>t.mediaUrl(r??"",i),"data:video/"),[e.src,t,r]),s=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":s,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 ",s]}),"."]})})})}function Kr({content:e,documentId:t,channel:r}){const[n]=Pt(),s=Bn(e.definition),i=p.useMemo(()=>JSON.stringify(e.definition),[e.definition]);return h.jsx("div",{className:"p-4",children:s.ok?h.jsx(Un,{channel:r,document:s.document,sessionId:n??void 0},r?t??r.documentId:i):h.jsx(Wn,{error:s.error,raw:s.raw})})}function Io({content:e}){const[t]=Pt();return t?h.jsx("div",{className:"h-full w-full",children:h.jsx($n,{sessionId:t,serverName:e.serverName,uri:e.uri,title:e.title})}):null}const No=p.lazy(()=>_e(()=>import("./CanvasFileContent-DqSx7lz9.js"),__vite__mapDeps([6,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasFileContent}))),Ao=p.lazy(()=>_e(()=>import("./CanvasModel3dContent-zTx660yQ.js"),__vite__mapDeps([22,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasModel3dContent}))),To=p.lazy(()=>_e(()=>import("./CanvasCsvContent-D-0TuvVs.js"),__vite__mapDeps([23,1,2,24,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(e=>({default:e.CanvasCsvContent}))),Mo=p.lazy(()=>_e(()=>import("./index-MHIn2TC9.js").then(e=>e.v$),__vite__mapDeps([1,2])).then(e=>({default:e.CanvasDiffContent})));function Ko({documentId:e,widgetChannel:t,content:r,onContentChange:n}){switch(r.type){case"url":case"browser":return h.jsx(Bi,{documentId:e,content:r},`${e}:${r.url}`);case"markdown":return h.jsx(vo,{documentId:e,content:r,onContentChange:n},r.sourcePath??"generated");case"json":return h.jsx(bo,{content:r});case"image":return h.jsx(jo,{content:r});case"pdf":return h.jsx(Eo,{content:r});case"audio":return h.jsx(_o,{content:r});case"video":return h.jsx(Do,{content:r});case"widget":return t?h.jsx(Kr,{content:r,documentId:e,channel:t}):h.jsx(Fo,{documentId:e,content:r});case"mcp_app":return h.jsx(Io,{content:r});case"file":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(No,{documentId:e,content:r})});case"model3d":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(Ao,{content:r})});case"csv":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(To,{content:r})});case"diff":return h.jsx(p.Suspense,{fallback:h.jsx(st,{}),children:h.jsx(Mo,{documentId:e,content:r},r.sourcePath)})}}function st(){return h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"})}function Fo({documentId:e,content:t}){const{channel:r}=$r(e);return h.jsx(Kr,{documentId:e,content:t,channel:r})}const zo=p.lazy(()=>_e(()=>import("./BlintzCanvas-DCXIQZM_.js").then(e=>e.B),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.BlintzCanvas})));function ea({roomId:e,document:t,content:r,onSave:n}){const[s,i]=p.useState(null),[a,c]=p.useState(!1),[o,u]=p.useState(null),d=s!==null,f=r.sourcePath===void 0;wi(e,d?t.id:null);const l=async()=>{if(s===null)return;if(s===r.content){i(null),u(null);return}c(!0),u(null);const g=await n(t.id,{...r,content:s});c(!1),g?i(null):u("Couldn’t save. Your words are still here. Try again.")};return h.jsxs("div",{className:"flex h-full flex-col",children:[f&&h.jsxs("div",{className:"flex items-center justify-end gap-2 border-b px-2 py-1",children:[d&&h.jsx("span",{className:"text-muted-foreground text-xs",children:a?"Saving…":"Everyone sees your save."}),h.jsx(it,{type:"button",size:"xs",variant:"ghost",disabled:a,"aria-label":d?"Save for the room":"Edit this document",onClick:()=>d?void l():i(r.content),children:d?h.jsx(Or,{className:"size-3.5"}):h.jsx(Sr,{className:"size-3.5"})})]}),o!==null&&h.jsx("p",{role:"status",className:"text-destructive border-b px-2 py-1 text-xs",children:o}),h.jsx("div",{className:"flex-1 px-2 pb-6",children:h.jsx(p.Suspense,{fallback:h.jsx("div",{className:"text-muted-foreground p-4 text-sm",children:"Loading…"}),children:h.jsx(zo,{value:s??r.content,editable:d,onChange:i},d?"editing":`rev-${t.rev}`)})})]})}const Lt="dorkos-canvas-sessions",qo=1440*60*60*1e3;function en(){try{const e=localStorage.getItem(Lt);if(!e)return null;const t=JSON.parse(e);return t===null||typeof t!="object"?null:t}catch{return null}}function tn(e){try{Object.keys(e).length===0?localStorage.removeItem(Lt):localStorage.setItem(Lt,JSON.stringify(e))}catch{}}function Lo(e){return Array.isArray(e.documents)?[...e.documents].sort((t,r)=>(t.openedAt??0)-(r.openedAt??0)).map(t=>t.content).filter(t=>!!t):e.content?[e.content]:[]}function mt(e){return e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(mt).join(",")}]`:`{${Object.entries(e).filter(([,r])=>r!==void 0).sort(([r],[n])=>r<n?-1:r>n?1:0).map(([r,n])=>`${JSON.stringify(r)}:${mt(n)}`).join(",")}}`}function Po(e,t){const r=new Set,n=new Map;for(const i of e){const a=nr(i.content);if(a!==null){r.add(a);continue}const c=mt(i.content);n.set(c,(n.get(c)??0)+1)}const s=[];for(const i of t){const a=nr(i);if(a!==null){r.has(a)||s.push(i);continue}const c=mt(i),o=n.get(c)??0;o>0?n.set(c,o-1):s.push(i)}return s}const at=new Set;function ta(){at.clear()}function ra(e,t={}){const r=ae(),n=t.canonical??!0;p.useEffect(()=>{e&&Y.getState().loadCanvasForSession(e)},[e]),p.useEffect(()=>{if(!e||!n||at.has(e))return;const s=en();if(!s)return;const i=s[e];if(!i){Bo(s);return}at.add(e),(async()=>{try{const a=Lo(i),c=Po(await r.listSessionCanvas(e),a);if(c.length===0){Rr(e);return}for(const o of c)await r.openSessionCanvasDocument(e,o);Rr(e),Y.getState().hydrateCanvasFromSnapshot(e,await r.listSessionCanvas(e))}catch{at.delete(e)}})()},[e,n,r])}function Rr(e){const t=en();if(!t)return;const{[e]:r,...n}=t;tn(n)}function Bo(e){const t=Date.now()-qo,r=Object.entries(e).filter(([,n])=>n.accessedAt===void 0||n.accessedAt>=t);r.length!==Object.keys(e).length&&tn(Object.fromEntries(r))}export{Ko as C,Yo as F,ea as R,oo as a,$r as b,yi as c,bi as d,Qo as e,Kr as f,ta as g,us as h,Zr as i,ra as j,Qr as r,ho as u};
|