dorkos 0.131.0 → 0.133.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 +499 -314
- package/dist/browser/fresh-verifier.mjs +13 -13
- package/dist/browser/native/darwin-supervisor-worker.mjs +3 -3
- package/dist/browser/native/package-manifest.json +1 -1
- package/dist/browser/source-manifest.json +1 -1
- package/dist/client/assets/{AboutPage-BZ2LLJ0k.js → AboutPage-D-EHHVPa.js} +1 -1
- package/dist/client/assets/{ActivityErrorState-BnqAwUiy.js → ActivityErrorState-BTHnE1vP.js} +1 -1
- package/dist/client/assets/{ActivityPage-BlZKrSVo.js → ActivityPage-BfSLPIdR.js} +1 -1
- package/dist/client/assets/{ActivityRow-Ch8HxQ2m.js → ActivityRow-PwUBjQw8.js} +1 -1
- package/dist/client/assets/{AdapterIcon-CfocFMw-.js → AdapterIcon-DgkNN6bi.js} +1 -1
- package/dist/client/assets/{AdapterSetupWizard-Dtjx1Oad.js → AdapterSetupWizard-DX0dzp7q.js} +2 -2
- package/dist/client/assets/{AgentOptionRow-BGRvUeF7.js → AgentOptionRow-ApuDEKqq.js} +1 -1
- package/dist/client/assets/{AgentPicker-BcURPZQp.js → AgentPicker-BDci-9aL.js} +1 -1
- package/dist/client/assets/{AgentRequestCard-kNq5A_IN.js → AgentRequestCard-B2gxCMGi.js} +3 -3
- package/dist/client/assets/{AppearancePage-Cd-k7dcc.js → AppearancePage-8SVnFe0k.js} +1 -1
- package/dist/client/assets/ApplyToOverridesDialog-CnL1ubxL.js +1 -0
- package/dist/client/assets/{AttentionSignalRow-QY8AIjf9.js → AttentionSignalRow-CCKhUtil.js} +1 -1
- package/dist/client/assets/{BaseTanStackRouterDevtoolsPanel-B-iktbLX-Cgkvajbw.js → BaseTanStackRouterDevtoolsPanel-B-iktbLX-B7wFPzG4.js} +3 -3
- package/dist/client/assets/BindingDialog-C4BHVXno.js +1 -0
- package/dist/client/assets/{BlintzCanvas-CMzZnmWK.js → BlintzCanvas-7E5uwVms.js} +3 -3
- package/dist/client/assets/{CanvasCsvContent-uxMaHePf.js → CanvasCsvContent-l7lfyDGn.js} +4 -4
- package/dist/client/assets/CanvasFileContent-Bqd0IEfK.js +2 -0
- package/dist/client/assets/CanvasModel3dContent-DqL0Sy4r.js +2 -0
- package/dist/client/assets/{ChannelComposer-BAg0a29Q.js → ChannelComposer-CAYvz_ZB.js} +12 -17
- package/dist/client/assets/{ChatAppsOff-DD28V0vX.js → ChatAppsOff-CNeKBVNz.js} +2 -2
- package/dist/client/assets/{CodeMirrorDiff-CyoduBgM.js → CodeMirrorDiff-BZRcNFsS.js} +1 -1
- package/dist/client/assets/{CodeMirrorEditor-DGccoZ8Q.js → CodeMirrorEditor-DD5tArRn.js} +1 -1
- package/dist/client/assets/{ComputerResourceView-Dk98shko.js → ComputerResourceView-BUmsVssG.js} +1 -1
- package/dist/client/assets/{ComputerViewer-Broprz4q.js → ComputerViewer-BKMR5LkF.js} +1 -1
- package/dist/client/assets/{ConnectionAccessLists-C_qLz8GJ.js → ConnectionAccessLists-DYUiFmPY.js} +1 -1
- package/dist/client/assets/{ConnectionsPage-CmGgGmDO.js → ConnectionsPage-DR2Kfm9Q.js} +2 -2
- package/dist/client/assets/{ConventionPage-BxWLIUUC.js → ConventionPage-Do6q8873.js} +2 -2
- package/dist/client/assets/{ExtensionPageRoute-CyfIRaGs.js → ExtensionPageRoute-CP7NM7fw.js} +2 -2
- package/dist/client/assets/{FeatureDisabledState-By2dhVpu.js → FeatureDisabledState-Bi23k3rg.js} +1 -1
- package/dist/client/assets/{FloatingTanStackRouterDevtools-CqogiFob-B6wKQpLR.js → FloatingTanStackRouterDevtools-CqogiFob-lRlmDXYz.js} +1 -1
- package/dist/client/assets/{ForwardConsentHost-kDdpyBgA.js → ForwardConsentHost-DSR1pEEK.js} +1 -1
- package/dist/client/assets/HandlePage-aHId3bYX.js +1 -0
- package/dist/client/assets/HeartbeatPage-BTNVcHOI.js +1 -0
- package/dist/client/assets/{KeyEntry-Ctc1zp2J.js → KeyEntry-67acsEG2.js} +1 -1
- package/dist/client/assets/{LexicalField-7zd4B8f1.js → LexicalField-Cb68LIar.js} +2 -2
- package/dist/client/assets/{ManagesPage-BG1TIMP3.js → ManagesPage-ChPlBF42.js} +1 -1
- package/dist/client/assets/{Marketplace-C9r4jRJf.js → Marketplace-CzPhJEE1.js} +4 -4
- package/dist/client/assets/{MarketplaceSourcesView-C01Cdrge.js → MarketplaceSourcesView-CmQgxQmU.js} +1 -1
- package/dist/client/assets/{McpAppFrame-Dm7MqOhc.js → McpAppFrame-z5JUaCSA.js} +2 -2
- package/dist/client/assets/{McpSigninBody-CsXP_7lE.js → McpSigninBody-ZrnzwrOH.js} +1 -1
- package/dist/client/assets/{Model3dViewer-DOl8ZkrU.js → Model3dViewer-HJpWK-JI.js} +1 -1
- package/dist/client/assets/NamePage-C7F-SotG.js +1 -0
- package/dist/client/assets/{NewDirectMessageMenu-Dj-Qw8zA.js → NewDirectMessageMenu-CjBjzsDe.js} +1 -1
- package/dist/client/assets/{NotificationsPage-UExs4YE2.js → NotificationsPage-DwNUI0Z3.js} +1 -1
- package/dist/client/assets/{OpenMeshSwitch-Dx3M3wwS.js → OpenMeshSwitch-RNAZY1vn.js} +2 -2
- package/dist/client/assets/{OperatorIdentityForm-Bz5570RF.js → OperatorIdentityForm-B7S2C_eT.js} +1 -1
- package/dist/client/assets/PermissionHistory-D0chstxf.js +1 -0
- package/dist/client/assets/PermissionsPage-ToK0DZVV.js +1 -0
- package/dist/client/assets/{PersonalityPopover-Do-k_Hhw.js → PersonalityPopover-BvMtUQRM.js} +1 -1
- package/dist/client/assets/PhotoPage-Cqo3PNO_.js +1 -0
- package/dist/client/assets/{PreviewRefusedNotice-B-yyzQZP.js → PreviewRefusedNotice-DzbkMrUo.js} +1 -1
- package/dist/client/assets/{ProfileFields-DiarOK2y.js → ProfileFields-DU8dTGHT.js} +1 -1
- package/dist/client/assets/{ProfilePanelContainer-33Xkwoc3.js → ProfilePanelContainer-BfT-ufV7.js} +1 -1
- package/dist/client/assets/{ProfileRolePicker-BI6T4hj8.js → ProfileRolePicker-DrOtV-0N.js} +1 -1
- package/dist/client/assets/{PromptSuggestionChips-v5MScpZF.js → PromptSuggestionChips-CEnhme_V.js} +1 -1
- package/dist/client/assets/{ReportsToPopover-BALADuTO.js → ReportsToPopover-CwjpR1Tw.js} +1 -1
- package/dist/client/assets/{RoomSurface-BatV7gf5.js → RoomSurface-CChzNJKw.js} +1 -1
- package/dist/client/assets/{RoomsPage-DCCC3Dst.js → RoomsPage-Dbf6ijKr.js} +1 -1
- package/dist/client/assets/{RunsOnPopover-C7hMPyrb.js → RunsOnPopover-Bh5sSsSC.js} +1 -1
- package/dist/client/assets/{RuntimeConnectFlow-Dc5a8dlJ.js → RuntimeConnectFlow-BYQnY5vv.js} +1 -1
- package/dist/client/assets/{RuntimeSetupDialog-w90VGjJ4.js → RuntimeSetupDialog-DTO5v0dP.js} +1 -1
- package/dist/client/assets/{SeenDevices-BIMmbMWC.js → SeenDevices-cuY7ASEy.js} +3 -3
- package/dist/client/assets/{SessionsPage-0lwvSYHB.js → SessionsPage-BrqpVx-t.js} +1 -1
- package/dist/client/assets/{SettingsDialog-CrP6JzPg.js → SettingsDialog-DCAZX_1d.js} +4 -4
- package/dist/client/assets/{SkillsPage-BDgKWTfe.js → SkillsPage-D5who_ZH.js} +1 -1
- package/dist/client/assets/TaskDialogWrapper-BJ6XtOC5.js +1 -0
- package/dist/client/assets/TasksEmptyState-B3SjsxQa.js +3 -0
- package/dist/client/assets/{TasksPage-DjGbMGvn.js → TasksPage-B72w7J87.js} +1 -1
- package/dist/client/assets/{TeamComputerEntry-B_sM9Fik.js → TeamComputerEntry-B9ma5j-X.js} +1 -1
- package/dist/client/assets/TodoPromiseList-DDKWAfmv.js +1 -0
- package/dist/client/assets/TodoPromisesPage-BNXpvXzS.js +1 -0
- package/dist/client/assets/{ToolsPage-CeETRCd8.js → ToolsPage-DbJykCG3.js} +2 -2
- package/dist/client/assets/{TopologyGraph-CnpH2NjE.js → TopologyGraph-DKZS3nlr.js} +3 -3
- package/dist/client/assets/{TourHost-BQHrS47S.js → TourHost-Bw3Uoea5.js} +1 -1
- package/dist/client/assets/{UnlinkDialog-DOQLeNx4.js → UnlinkDialog-B-XCFNSd.js} +1 -1
- package/dist/client/assets/{UnreadDivider-DhyK6uGG.js → UnreadDivider-1aPVzwd7.js} +1 -1
- package/dist/client/assets/{WidgetErrorCard-Bwlfu514.js → WidgetErrorCard-C5ieVv_9.js} +6 -6
- package/dist/client/assets/{WithheldExtensionsNotice-BDc-CM2t.js → WithheldExtensionsNotice-CCO4ClRZ.js} +1 -1
- package/dist/client/assets/{WorkQueuePage-iO_DO1YK.js → WorkQueuePage-BbPKNwDg.js} +1 -1
- package/dist/client/assets/WorkView-BRcytACJ.js +51 -0
- package/dist/client/assets/_shell-EwFeSIGp.js +80 -0
- package/dist/client/assets/{_shell._home-BWi5YPaR.js → _shell._home-DD2mg-iK.js} +1 -1
- package/dist/client/assets/{_shell._home.activity-BU1NIGb7.js → _shell._home.activity-Z1QuU2M4.js} +1 -1
- package/dist/client/assets/_shell._home.index-BzTYr8Bw.js +3 -0
- package/dist/client/assets/_shell._home.tasks-BtC85Iut.js +1 -0
- package/dist/client/assets/{_shell._home.workspaces-wbnqJ58w.js → _shell._home.workspaces-qMG5OJYR.js} +1 -1
- package/dist/client/assets/{_shell.channels-D1KdvWZF.js → _shell.channels-BE4EK-iM.js} +2 -2
- package/dist/client/assets/_shell.connections-CBx0ogzx.js +1 -0
- package/dist/client/assets/{_shell.feedback-requests-DzHWC1fJ.js → _shell.feedback-requests-CwKSkkuD.js} +2 -2
- package/dist/client/assets/_shell.marketplace-CgWBUKSA.js +1 -0
- package/dist/client/assets/_shell.marketplace_.sources-8HZpKFDI.js +1 -0
- package/dist/client/assets/_shell.session-D6HcVbnm.js +1 -0
- package/dist/client/assets/{_shell.team-BMNSUpQQ.js → _shell.team-Dm5a4f8_.js} +4 -4
- package/dist/client/assets/_shell.threads-BavVtQOE.js +1 -0
- package/dist/client/assets/_shell.todos-B6uWr0zA.js +6 -0
- package/dist/client/assets/_shell.x._extensionId-DaELdkCH.js +1 -0
- package/dist/client/assets/_shell.x._extensionId_._-DaELdkCH.js +1 -0
- package/dist/client/assets/{abnfDiagram-WEYOIA3C-Co2k29JX.js → abnfDiagram-WEYOIA3C-Bu2T3jVw.js} +1 -1
- package/dist/client/assets/{access-copy-D6BUySpp.js → access-copy-tkiFMhRf.js} +1 -1
- package/dist/client/assets/{arc-DLZZpkuJ.js → arc-5q4SfXO9.js} +1 -1
- package/dist/client/assets/{architectureDiagram-ZHVYKT53-ClS9xqK5.js → architectureDiagram-ZHVYKT53-BnDMOBhV.js} +1 -1
- package/dist/client/assets/{banner-B8iMuXCP.js → banner-CSKUrrI0.js} +2 -2
- package/dist/client/assets/{blockDiagram-RJAE7QA3-DheoOELu.js → blockDiagram-RJAE7QA3-CtushlEs.js} +1 -1
- package/dist/client/assets/{c4Diagram-XDPPPE54-VWWZJ5x4.js → c4Diagram-XDPPPE54-7L-qYwKH.js} +1 -1
- package/dist/client/assets/channel-A3XT7_2L.js +1 -0
- package/dist/client/assets/{chunk-2E7WHVMD-BqPLJVkv.js → chunk-2E7WHVMD-ksBVyqQ3.js} +1 -1
- package/dist/client/assets/{chunk-2Q5K7J3B-DZn6OnKe.js → chunk-2Q5K7J3B-Bfqdkihb.js} +1 -1
- package/dist/client/assets/{chunk-4EMNKR2T-Dl9Poajp.js → chunk-4EMNKR2T-Brf2dH9x.js} +1 -1
- package/dist/client/assets/{chunk-55XCU76K-RoKuZPUc.js → chunk-55XCU76K-BlE7Cq40.js} +1 -1
- package/dist/client/assets/{chunk-5VM5RSS4-DV_1XHtU.js → chunk-5VM5RSS4-Bkgg3j7L.js} +1 -1
- package/dist/client/assets/{chunk-JWPE2WC7-B_IuS45y.js → chunk-JWPE2WC7-B9TRpN4O.js} +1 -1
- package/dist/client/assets/{chunk-VQ5W62QI-DkLNi45x.js → chunk-VQ5W62QI-ZoILnIYi.js} +1 -1
- package/dist/client/assets/{chunk-XXDRQBXY-ISM-1Dpw.js → chunk-XXDRQBXY-r2xNhaKz.js} +1 -1
- package/dist/client/assets/{chunk-ZCHMQSOR-MKaLMW8o.js → chunk-ZCHMQSOR-DfV3cF7d.js} +2 -2
- package/dist/client/assets/{classDiagram-v2-4MYWR3UA-CIWuu4ht.js → classDiagram-v2-4MYWR3UA-VOVqMNNP.js} +1 -1
- package/dist/client/assets/{command-CxGYZKco.js → command-CaUEAy3b.js} +1 -1
- package/dist/client/assets/{copy-button-DjAoGwds.js → copy-button-BOznikwM.js} +1 -1
- package/dist/client/assets/{cose-bilkent-JH36ORCC-HiCifRyi.js → cose-bilkent-JH36ORCC-CAdBvyLz.js} +1 -1
- package/dist/client/assets/{cpu-DHHTTvp_.js → cpu-j9vX9Wfk.js} +1 -1
- package/dist/client/assets/{cynefin-EF2NZ3EQ-DjJGZrPz.js → cynefin-EF2NZ3EQ-DcH1A9Oo.js} +1 -1
- package/dist/client/assets/{cynefinDiagram-WF24UDRP-DE2NdiJ2.js → cynefinDiagram-WF24UDRP-DJuKBXHi.js} +1 -1
- package/dist/client/assets/{dagre-NK4GIZVX-C6gDOD26.js → dagre-NK4GIZVX-D099H_0S.js} +1 -1
- package/dist/client/assets/{detail-row-CjwI1iuc.js → detail-row-Crl89jnh.js} +1 -1
- package/dist/client/assets/{diagram-CBK3MWTC-38LckcsL.js → diagram-CBK3MWTC-Cd_4W9XO.js} +1 -1
- package/dist/client/assets/{diagram-I5XIIV2D--8L6D9Ra.js → diagram-I5XIIV2D-Bc7aQKt3.js} +1 -1
- package/dist/client/assets/{diagram-ODIL2UCW-DGC2Inhd.js → diagram-ODIL2UCW-awVJZ4Bg.js} +1 -1
- package/dist/client/assets/{diagram-PFBEJUXE-BDHp0AyR.js → diagram-PFBEJUXE-dhsj9aeU.js} +1 -1
- package/dist/client/assets/{diagram-RJA3I4VV-uBatJYPi.js → diagram-RJA3I4VV-Dm59CbiV.js} +1 -1
- package/dist/client/assets/{diagram-TYUNFSNR-C8e1EH9X.js → diagram-TYUNFSNR-BhvcIjA9.js} +1 -1
- package/dist/client/assets/{ebnfDiagram-V4P3TTPT-DimRzU5B.js → ebnfDiagram-V4P3TTPT-C4wT_MTC.js} +1 -1
- package/dist/client/assets/{elk-QONTBCTQ-Dz6_Y2-G.js → elk-QONTBCTQ-CPI0zjmW.js} +1 -1
- package/dist/client/assets/{empty-state-saV209Il.js → empty-state-BHcmkSzu.js} +1 -1
- package/dist/client/assets/{erDiagram-KYQIGQAA-JeuTF8w6.js → erDiagram-KYQIGQAA-C_vGcbOB.js} +1 -1
- package/dist/client/assets/{execution-config-ClQZyDs9.js → execution-config-BS5rtvTZ.js} +1 -1
- package/dist/client/assets/{file-BIF-4ARS.js → file-CQGljfDT.js} +1 -1
- package/dist/client/assets/{file-exclamation-point-DxadH2b-.js → file-exclamation-point-B0a55VME.js} +1 -1
- package/dist/client/assets/{file-text-C_NPIQr4.js → file-text-Cycq_S0e.js} +1 -1
- package/dist/client/assets/{find-latest-widget-fence-CXai_zs0.js → find-latest-widget-fence-B6sJdG3Q.js} +4 -4
- package/dist/client/assets/{flowDiagram-IUGLLWBU-9FHDdK4j.js → flowDiagram-IUGLLWBU-_VNfmnxx.js} +1 -1
- package/dist/client/assets/{form-D3VdAYl4.js → form-BL14vwyB.js} +1 -1
- package/dist/client/assets/{format-cron-BqRDcFZM.js → format-cron-meJMgYNe.js} +1 -1
- package/dist/client/assets/{ganttDiagram-R7GPNTJY-CLMuXlHt.js → ganttDiagram-R7GPNTJY-o0gGU7X_.js} +1 -1
- package/dist/client/assets/{git-branch-Df7a5_fb.js → git-branch-CsLE6G0Y.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PDYL7XHY-sE7Rlpr6.js → gitGraphDiagram-PDYL7XHY-DjXjUpJo.js} +1 -1
- package/dist/client/assets/{graph-iNVyFhBQ.js → graph-BMYee_VK.js} +1 -1
- package/dist/client/assets/{heart-BHMhDZ0K.js → heart-Cn3a-UQI.js} +1 -1
- package/dist/client/assets/{highlighted-body-KPVGNVTW-VvvsrJbu.js → highlighted-body-KPVGNVTW-DsX5yCC0.js} +1 -1
- package/dist/client/assets/{image-lightbox-CGEIRguA.js → image-lightbox-BZ_eBZgA.js} +1 -1
- package/dist/client/assets/{image-off-C5-TmSq8.js → image-off-DjR7LI5G.js} +1 -1
- package/dist/client/assets/{index-C3zS0ghJ.js → index-1MwES_vb.js} +1 -1
- package/dist/client/assets/{index-ClyRhxV_.js → index-47--OGKJ.js} +1 -1
- package/dist/client/assets/{index-CTgUh4p3.js → index-4rSR8lau.js} +1 -1
- package/dist/client/assets/{index-D9bEy8X-.js → index-B4TxpTKD.js} +1 -1
- package/dist/client/assets/{index-Dw-4S640.js → index-B8LqLhq7.js} +1 -1
- package/dist/client/assets/index-BJRgbiEd.js +1 -0
- package/dist/client/assets/{index-DWZ5M321.js → index-BOCclWF3.js} +1 -1
- package/dist/client/assets/index-BR1m9FON.js +1066 -0
- package/dist/client/assets/index-BcFn_S6b.js +1 -0
- package/dist/client/assets/{index-DRtg_sGG.js → index-BcnwvTnt.js} +1 -1
- package/dist/client/assets/index-BdVQOlVQ.css +1 -0
- package/dist/client/assets/{index-DEvpdTo6.js → index-BmKHO-FD.js} +1 -1
- package/dist/client/assets/{index-Bd0PAkxf.js → index-BsZkXHsH.js} +1 -1
- package/dist/client/assets/{index-Cudi8rs6.js → index-BxWr8Mrf.js} +1 -1
- package/dist/client/assets/index-C5EvpXcq.js +1 -0
- package/dist/client/assets/{index-CExh9cKN.js → index-Cb_p_ynP.js} +1 -1
- package/dist/client/assets/{index-YZbu9tke.js → index-CczLBUKI.js} +1 -1
- package/dist/client/assets/{index-264YDu-W.js → index-Cf4Gtxf9.js} +1 -1
- package/dist/client/assets/{index-Dpu2CORc.js → index-CfKSlYjb.js} +1 -1
- package/dist/client/assets/{index-Bzm9YMbr.js → index-Cgjq7a-8.js} +1 -1
- package/dist/client/assets/{index-Ci_J5Q-6.js → index-CpWxcN5D.js} +1 -1
- package/dist/client/assets/{index-BK5QrGfQ.js → index-Cv67OXfk.js} +1 -1
- package/dist/client/assets/{index-Di-MIFQG.js → index-D5Qmx1JR.js} +3 -3
- package/dist/client/assets/{index-LPrq0pOA.js → index-DARchye_.js} +1 -1
- package/dist/client/assets/{index-DMwivStD.js → index-DFb4kOjm.js} +2 -2
- package/dist/client/assets/{index-WeLoaNzW.js → index-DLN0kcME.js} +1 -1
- package/dist/client/assets/{index-BMLCfTba.js → index-DMSSN08i.js} +1 -1
- package/dist/client/assets/{index-Y6BDhuGt.js → index-DQ8uADJF.js} +1 -1
- package/dist/client/assets/index-DZhMvc9m.js +1 -0
- package/dist/client/assets/{index-CLsoFUml.js → index-Dfko0tSp.js} +1 -1
- package/dist/client/assets/{index-BgdYXP8E.js → index-DiM3QX-4.js} +3 -3
- package/dist/client/assets/{index-BxFLHNLg.js → index-DlvUENo4.js} +1 -1
- package/dist/client/assets/{index-BLUUshO9.js → index-DqZmnJED.js} +1 -1
- package/dist/client/assets/{index-D_bAtIJZ.js → index-DrlB9RSk.js} +1 -1
- package/dist/client/assets/{index-CgWzzIbx.js → index-H4e5Wpmi.js} +1 -1
- package/dist/client/assets/{index-k67dvyau.js → index-Joav7LQU.js} +1 -1
- package/dist/client/assets/{index-B0FHRkHM.js → index-KganLhU1.js} +2 -2
- package/dist/client/assets/{index-DFkofTx1.js → index-Kt6r3DQg.js} +1 -1
- package/dist/client/assets/{index-B8I1k-z9.js → index-Z2ApBQt4.js} +1 -1
- package/dist/client/assets/index-dY7IFpet.js +1 -0
- package/dist/client/assets/{index-DYVNSRDk.js → index-faSyUc2q.js} +1 -1
- package/dist/client/assets/{index-BgRYuqWs.js → index-gmyiXkmr.js} +1 -1
- package/dist/client/assets/{index-BZTLFzJp.js → index-o6kGmVGx.js} +1 -1
- package/dist/client/assets/{index-C_0JoCV6.js → index-vHKVYcH7.js} +1 -1
- package/dist/client/assets/{index.esm-CYmalBux.js → index.esm-CJIDYBqd.js} +1 -1
- package/dist/client/assets/{infoDiagram-MVDRKAX5-0aR9wjgO.js → infoDiagram-MVDRKAX5-B1mMyUlp.js} +1 -1
- package/dist/client/assets/{inline-code-DyTKSC5b.js → inline-code-mh48Uhbi.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-HPEHV2GE-D1lN8x2t.js → ishikawaDiagram-HPEHV2GE-efEMQ0_X.js} +1 -1
- package/dist/client/assets/{journeyDiagram-BOSHW7O7-CkXITXiJ.js → journeyDiagram-BOSHW7O7-DSAywiVk.js} +1 -1
- package/dist/client/assets/{kanban-definition-FNSA4HC5-ge33IiSq.js → kanban-definition-FNSA4HC5-B9pbU4zK.js} +1 -1
- package/dist/client/assets/{layers-Bx3K7OUm.js → layers-B0Z5Od3N.js} +1 -1
- package/dist/client/assets/{lightbulb-C5LvXkvM.js → lightbulb-Cfb5ecEd.js} +1 -1
- package/dist/client/assets/{link-2-Bj0_Zkvr.js → link-2-Dzy5BUL3.js} +1 -1
- package/dist/client/assets/{list-runtime-types-VNj1C8TB.js → list-runtime-types-DLmjtBMq.js} +1 -1
- package/dist/client/assets/{markdown-content-BRaPEOC7.js → markdown-content-DhAtZOfj.js} +1 -1
- package/dist/client/assets/{mention-pill-B_MiJWfo.js → mention-pill-DmA8FxL4.js} +1 -1
- package/dist/client/assets/{mermaid.core-B2hil_4a.js → mermaid.core-DUIkdbeL.js} +4 -4
- package/dist/client/assets/{message-square-off-T33FHpr7.js → message-square-off-BowIzJUV.js} +1 -1
- package/dist/client/assets/{mindmap-definition-6OY57UG3-Bu_Ia4Xz.js → mindmap-definition-6OY57UG3-Dz7ZOR4C.js} +1 -1
- package/dist/client/assets/{more-details-oDazWBxm.js → more-details-DV7LmY0E.js} +1 -1
- package/dist/client/assets/{owner-notice-VepbAQhj.js → owner-notice-DdFc2P8z.js} +1 -1
- package/dist/client/assets/{package-DBsl3ao5.js → package-BhKXbvU_.js} +1 -1
- package/dist/client/assets/{page-container-Bkarym6m.js → page-container-0sWZ3xh9.js} +1 -1
- package/dist/client/assets/{pane-resize-handle-gBlb5k1v.js → pane-resize-handle-Bjy4udre.js} +1 -1
- package/dist/client/assets/{paperclip-BeFttiUK.js → paperclip-C-7LhBfl.js} +1 -1
- package/dist/client/assets/{path-input-NY_yCBHb.js → path-input-BPVyI72G.js} +1 -1
- package/dist/client/assets/{pegDiagram-ECIUJNBX-0KmJlW0E.js → pegDiagram-ECIUJNBX-C4EOP-Fa.js} +1 -1
- package/dist/client/assets/{pieDiagram-GNMPY74T-IjeZXicv.js → pieDiagram-GNMPY74T-CQ1OxRkv.js} +1 -1
- package/dist/client/assets/{plug-CTqOZ7cA.js → plug-CIZ-wWL8.js} +1 -1
- package/dist/client/assets/{primer-trigger-CjaGrT2u.js → primer-trigger-XA5fLzR5.js} +2 -2
- package/dist/client/assets/{profile-errors-B8XkL2Rp.js → profile-errors-C1XACbc9.js} +1 -1
- package/dist/client/assets/{progress-Cr-4myw6.js → progress-BA2JPtb6.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-D57K4MC3-CP6kLJKa.js → quadrantDiagram-D57K4MC3-Cw4BdkpS.js} +1 -1
- package/dist/client/assets/{query-error-state-DvhY-YKM.js → query-error-state-Cm-Lozlb.js} +1 -1
- package/dist/client/assets/{radio-CmDmmJy6.js → radio-DQ29H26H.js} +1 -1
- package/dist/client/assets/{railroadDiagram-Y72NRBL7-Bcto__oE.js → railroadDiagram-Y72NRBL7-CSKtYLmm.js} +1 -1
- package/dist/client/assets/registry-Tbt9pcZl.js +39 -0
- package/dist/client/assets/registry-jD9zw538.js +1 -0
- package/dist/client/assets/{relay-trace-schemas-ZLR1S8ft.js → relay-trace-schemas-4AAUf-Zl.js} +2 -2
- package/dist/client/assets/{repeat-DVTM8et8.js → repeat-B8g-x-Sc.js} +1 -1
- package/dist/client/assets/{requirementDiagram-EQYSW5RA-DNJrds3m.js → requirementDiagram-EQYSW5RA-BPSBZr7X.js} +1 -1
- package/dist/client/assets/{room-files-source-9Wdtc-bG.js → room-files-source-BkiK4-ZI.js} +2 -2
- package/dist/client/assets/{rotate-ccw-clock-qJSWqifh.js → rotate-ccw-clock-DRtL-2nr.js} +1 -1
- package/dist/client/assets/{rotate-cw-uoeBxIeM.js → rotate-cw-BbHkWN-J.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-SY24JHO5-DNlU7xGI.js → sankeyDiagram-SY24JHO5-DVlHablQ.js} +1 -1
- package/dist/client/assets/{scroll-area-B1d3NfEn.js → scroll-area-DAC7NrVU.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-BLEHNHQU-CRk71coF.js → sequenceDiagram-BLEHNHQU--wZkN8xk.js} +1 -1
- package/dist/client/assets/{shield-x-BpQmg1qz.js → shield-x-CEWfkzDN.js} +1 -1
- package/dist/client/assets/{signed-in-CTmJ3OqM.js → signed-in-CMhCR-m8.js} +1 -1
- package/dist/client/assets/{sizeCapture-INFHLROL-cihX3QNq.js → sizeCapture-INFHLROL-CLXc7d3S.js} +1 -1
- package/dist/client/assets/{soul-file-BwiyiI5v.js → soul-file-CbX7rNqz.js} +1 -1
- package/dist/client/assets/{stateDiagram-v2-A6IESKWZ-BAwwRsnH.js → stateDiagram-v2-A6IESKWZ-5xa1FM_X.js} +1 -1
- package/dist/client/assets/{swimlanes-B3ENRKFQ-CpDB6CUC.js → swimlanes-B3ENRKFQ-DKgxJxjE.js} +1 -1
- package/dist/client/assets/swimlanesDiagram-AYQRV4AK-f6MOc3pl.js +8 -0
- package/dist/client/assets/{table-dWrfPeX-.js → table-D0EJT0uP.js} +1 -1
- package/dist/client/assets/{tabs-D4txthOi.js → tabs-Ctjzrm8t.js} +1 -1
- package/dist/client/assets/{timeline-definition-JXYKGLGB-RDrKgCoU.js → timeline-definition-JXYKGLGB-B9P7ituI.js} +1 -1
- package/dist/client/assets/trust-dial-D__tIhzt.js +11 -0
- package/dist/client/assets/{trust-posture-atZIh8tf.js → trust-posture-DaHHtOZn.js} +1 -1
- package/dist/client/assets/{unplug-CnevV4yX.js → unplug-B-ipHefz.js} +1 -1
- package/dist/client/assets/{unverified-catalog-notice-BQwT36FA.js → unverified-catalog-notice-C8swqaTn.js} +1 -1
- package/dist/client/assets/{use-bindings-CltfjAWW.js → use-bindings-gLHRNAFU.js} +1 -1
- package/dist/client/assets/{use-composer-prefs-D-Zlt6z2.js → use-composer-prefs-CjpxcBIe.js} +1 -1
- package/dist/client/assets/{use-connector-management-C3CLnOOt.js → use-connector-management-BLiCJMgU.js} +1 -1
- package/dist/client/assets/{use-deep-link-scroll-DQlz-scx.js → use-deep-link-scroll-r2nKjzA-.js} +1 -1
- package/dist/client/assets/{use-delete-binding-D73CLm_7.js → use-delete-binding-BSiOik_K.js} +1 -1
- package/dist/client/assets/{use-dev-links-BqVFsMKU.js → use-dev-links-DXcIlMf-.js} +1 -1
- package/dist/client/assets/use-direct-message-panel-BbH8N4mE.js +1 -0
- package/dist/client/assets/{use-external-adapter-catalog-DrnksH0t.js → use-external-adapter-catalog-mmKni5ui.js} +1 -1
- package/dist/client/assets/{use-filter-state-D4i-hDOk.js → use-filter-state-CiPZ0AIH.js} +2 -2
- package/dist/client/assets/{use-full-activity-feed-DdDsRg8s.js → use-full-activity-feed-DXroUzfN.js} +1 -1
- package/dist/client/assets/use-is-below-desktop-LUZL5z5t.js +1 -0
- package/dist/client/assets/{use-mesh-topology-B7aLtPkZ.js → use-mesh-topology-upehQ5Cv.js} +1 -1
- package/dist/client/assets/{use-mounted-ref-DSSTCJfY.js → use-mounted-ref-IHwyriaF.js} +1 -1
- package/dist/client/assets/{use-notification-prefs-DaF3kwmq.js → use-notification-prefs-BHOK2P2l.js} +1 -1
- package/dist/client/assets/use-pending-read-mVsOBTzn.js +1 -0
- package/dist/client/assets/{use-personality-commit-D5b90JPX.js → use-personality-commit-Chf3UX8P.js} +1 -1
- package/dist/client/assets/{use-promo-activation-CPAOQpfe.js → use-promo-activation-Dlw6bg7G.js} +2 -2
- package/dist/client/assets/{use-promo-dismissals-Bx1gz1R1.js → use-promo-dismissals-Dx_fli7I.js} +1 -1
- package/dist/client/assets/{use-pulse-freshness-DeulB37O.js → use-pulse-freshness-CG_I6a-O.js} +1 -1
- package/dist/client/assets/{use-room-follow-claim-Dwke6RFQ.js → use-room-follow-claim-Bgrpr3bO.js} +1 -1
- package/dist/client/assets/{use-room-sessions-iepVrIMm.js → use-room-sessions-DecGrP3E.js} +1 -1
- package/dist/client/assets/{use-roving-tab-list-pCPKNQKv.js → use-roving-tab-list-CDkh-Ujm.js} +1 -1
- package/dist/client/assets/{use-session-canvas-BvvO-_V1.js → use-session-canvas-tvLLPQcm.js} +6 -6
- package/dist/client/assets/{use-status-budget-Bs7MMriS.js → use-status-budget-BBl2yxLR.js} +2 -2
- package/dist/client/assets/{use-todos-C-eREuDS.js → use-todos-BzRauzdQ.js} +1 -1
- package/dist/client/assets/{use-transform-lj3TkjYO.js → use-transform-DzJeHpxm.js} +1 -1
- package/dist/client/assets/{use-unclaimed-chats-BF3-0jHC.js → use-unclaimed-chats--HZdmq4F.js} +1 -1
- package/dist/client/assets/use-update-config-DjL7-nUR.js +1 -0
- package/dist/client/assets/{useMutationState-B_x_4f2K.js → useMutationState-DIywUTDG.js} +1 -1
- package/dist/client/assets/{usecaseDiagram-WPOLBNNX-DBsRYa4J.js → usecaseDiagram-WPOLBNNX-C9aLJ03F.js} +1 -1
- package/dist/client/assets/{vennDiagram-Q3Y3IDCW-rFAXvcQI.js → vennDiagram-Q3Y3IDCW-ChBIWbL0.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-IVAIDKWA-bI0JZkO3.js → wardleyDiagram-IVAIDKWA-DvQDOaTm.js} +1 -1
- package/dist/client/assets/{xychartDiagram-4URNHDU4-DZUd8iln.js → xychartDiagram-4URNHDU4-8FxLPP2c.js} +1 -1
- package/dist/client/assets/zap-DSllMMHe.js +6 -0
- package/dist/client/index.html +2 -2
- package/dist/drizzle/20261104060919_package_approval_request.sql +1 -0
- package/dist/drizzle/20261104081935_hook_decline_review.sql +3 -0
- package/dist/drizzle/20261107183323_dor3933_todos_rename.sql +64 -0
- package/dist/drizzle/20261108014418_dor3938_cross_agent_writer.sql +4 -0
- package/dist/drizzle/meta/20261104060919_snapshot.json +14889 -0
- package/dist/drizzle/meta/20261104081935_snapshot.json +14910 -0
- package/dist/drizzle/meta/20261107183323_snapshot.json +14910 -0
- package/dist/drizzle/meta/20261108014418_snapshot.json +14938 -0
- package/dist/drizzle/meta/_journal.json +28 -0
- package/dist/server/index.js +24875 -21931
- package/dist/server/index.js.map +2 -2
- package/package.json +5 -5
- package/dist/client/assets/ApplyToOverridesDialog-DE9VVQCA.js +0 -1
- package/dist/client/assets/BindingDialog-C_yflKOE.js +0 -1
- package/dist/client/assets/CanvasFileContent-C3ZKszxn.js +0 -2
- package/dist/client/assets/CanvasModel3dContent-CsNUuaj6.js +0 -2
- package/dist/client/assets/CommitmentList-DOvfnyDA.js +0 -1
- package/dist/client/assets/CommitmentsPage-D81vxHUk.js +0 -1
- package/dist/client/assets/HandlePage-vsG04kBg.js +0 -1
- package/dist/client/assets/HeartbeatPage-CMj1SS30.js +0 -1
- package/dist/client/assets/NamePage-DdX2yQ5f.js +0 -1
- package/dist/client/assets/PermissionHistory-Bhl2kr1R.js +0 -1
- package/dist/client/assets/PermissionsPage-DUbenFkt.js +0 -1
- package/dist/client/assets/PhotoPage-CExABoHA.js +0 -1
- package/dist/client/assets/TaskDialogWrapper-BVb8gAr0.js +0 -1
- package/dist/client/assets/TasksEmptyState-RkUEEU2r.js +0 -3
- package/dist/client/assets/WorkView-BDk_vwu3.js +0 -51
- package/dist/client/assets/_shell-CMNFxZKJ.js +0 -80
- package/dist/client/assets/_shell._home.index-BjR-d3_s.js +0 -3
- package/dist/client/assets/_shell._home.tasks-CqURPMQD.js +0 -1
- package/dist/client/assets/_shell.connections-D3gJrBTQ.js +0 -1
- package/dist/client/assets/_shell.marketplace-HdefWdN_.js +0 -1
- package/dist/client/assets/_shell.marketplace_.sources-wAZKfDQF.js +0 -1
- package/dist/client/assets/_shell.session-C0utZeSI.js +0 -1
- package/dist/client/assets/_shell.threads-TvzYRNMt.js +0 -1
- package/dist/client/assets/_shell.todos-sOFmsIPE.js +0 -6
- package/dist/client/assets/_shell.x._extensionId-DiEQZIvl.js +0 -1
- package/dist/client/assets/_shell.x._extensionId_._-DiEQZIvl.js +0 -1
- package/dist/client/assets/channel-B0WiEIVe.js +0 -1
- package/dist/client/assets/index-BwTGkJbK.js +0 -1071
- package/dist/client/assets/index-CCHGVclj.js +0 -1
- package/dist/client/assets/index-CiUmx-i3.js +0 -1
- package/dist/client/assets/index-Dd4JoHFP.js +0 -1
- package/dist/client/assets/index-DlmGvYpy.js +0 -1
- package/dist/client/assets/index-EXJsA5kw.js +0 -1
- package/dist/client/assets/index-MpS13vhQ.css +0 -1
- package/dist/client/assets/registry-BQTcAm5U.js +0 -39
- package/dist/client/assets/registry-HencHRXy.js +0 -1
- package/dist/client/assets/swimlanesDiagram-AYQRV4AK-nJfOIWYW.js +0 -8
- package/dist/client/assets/use-direct-message-panel-B3qfpDjY.js +0 -1
- package/dist/client/assets/use-is-below-desktop-BXHT3oPL.js +0 -1
- package/dist/client/assets/use-local-browser-DDWknHZE.js +0 -1
- package/dist/client/assets/use-pending-read-uvmEJ7H9.js +0 -1
- package/dist/client/assets/use-update-config-D-OGlXGR.js +0 -1
package/dist/client/assets/{use-session-canvas-BvvO-_V1.js → use-session-canvas-tvLLPQcm.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-
|
|
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,
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlintzCanvas-7E5uwVms.js","assets/index-BR1m9FON.js","assets/index-BdVQOlVQ.css","assets/index-CfKSlYjb.js","assets/index-D5Qmx1JR.js","assets/BlintzCanvas-DCXOV_yN.css","assets/CanvasFileContent-Bqd0IEfK.js","assets/rotate-cw-BbHkWN-J.js","assets/query-keys-DeYqUDia.js","assets/index.esm-CJIDYBqd.js","assets/WidgetErrorCard-C5ieVv_9.js","assets/index-CpWxcN5D.js","assets/progress-BA2JPtb6.js","assets/markdown-content-DhAtZOfj.js","assets/table-D0EJT0uP.js","assets/zap-DSllMMHe.js","assets/package-BhKXbvU_.js","assets/heart-Cn3a-UQI.js","assets/git-branch-CsLE6G0Y.js","assets/file-text-Cycq_S0e.js","assets/file-CQGljfDT.js","assets/McpAppFrame-z5JUaCSA.js","assets/more-details-DV7LmY0E.js","assets/CanvasModel3dContent-DqL0Sy4r.js","assets/CanvasCsvContent-l7lfyDGn.js","assets/index-Cgjq7a-8.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,lO as vt,dv as K,g4 as te,dz as St,dx as $e,dw as le,oV as dn,oW as fn,oX as hn,a_ as _e,cr as Pt,e9 as pn,aZ as Y,oY as mn,du as rr,oZ as Er,o_ as ct,o$ as gn,oE as Qe,p0 as Bt,ov as vn,dy as ut,hj as Q,p1 as bn,p2 as yn,j as h,p3 as wn,kR as xn,ii as kn,ij as Cn,eP as jn,G as Ut,I as Rn,fX as En,cy as On,p4 as Sn,k6 as _n,ka as Dn,dR as In,p5 as Nn,p6 as An,p7 as Tn,B as it,J as Or,gv as Sr,C as Mn,aO as Fn,p8 as nr}from"./index-BR1m9FON.js";import{R as zn}from"./rotate-cw-BbHkWN-J.js";import{d as _t}from"./query-keys-DeYqUDia.js";import{T as qn,a as Ln,u as Pn}from"./index.esm-CJIDYBqd.js";import{v as Bn,a as Un,W as Wn}from"./WidgetErrorCard-C5ieVv_9.js";import{M as $n}from"./McpAppFrame-z5JUaCSA.js";/**
|
|
3
3
|
* @license lucide-react v1.48.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -19,9 +19,9 @@ var an=Object.defineProperty;var tr=e=>{throw TypeError(e)};var cn=(e,t,r)=>t in
|
|
|
19
19
|
*
|
|
20
20
|
* This source code is licensed under the ISC license.
|
|
21
21
|
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const 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
|
|
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 Xn(){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},Zn=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)}),Zn,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 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:O,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:O,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: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,A.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 T=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 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 Oe=u.current,Kt=new TextEncoder;if(o.current||(Oe.overheadBytes=Kt.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,sn]of[["console",V.console],["network",V.network]])for(const on of sn){const er=Kt.encode(JSON.stringify(on)).length;Oe[Le].push(er),Oe.entryBytes+=er}X.console.push(...V.console),X.network.push(...V.network);const nn=()=>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||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(),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"){(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: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?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 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}sr().then(F=>{Z(y,E,S)&&S.frame.postMessage({__dorkosDevtools:"capture-request",bridgeGeneration:S.generation,requestId:y,lib:F},"*")},()=>{G(y,E)})})}async function Vt(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?as(E.frames[E.frames.length-1]):new Uint8Array;E.drawn=await ss(E.frames,800,F),F();let ue=await ir(E.drawn,{frameMs:500,maxBytes:8*1024*1024},F);if(F(),!ue.ok&&E.drawn.length&&(is(E.drawn,F),ue=await ir(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:or(`${y}.gif`,"image/gif",ue.bytes),keyframe:or(`${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:T}}const ze=le().min(1).max(128),me={protocol:te("dorkos-doc"),v:te(1),nonce:ze,requestToken:ze,loadToken:ct,generation:Or.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(Or,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 Os(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 Es{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)&&Ee(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)||!Ee(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 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=dr(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:_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)&&Ee(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 Es,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 Ee(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 O=lr(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&&ur(e),Ve(e,O)},L=(j,O)=>$t(e,j,O),B=j=>{const O=Cs(e,j),k=ee(e),T=k&&xe(e,k);return!R(j)||!O||O.through>O.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,O,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=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),!T&&!j.incarnation&&(f=!0),C()&&Hs(e,j,O,l===void 0,k)},x=(j,O)=>{var se;const k=Bs(e,j,O);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,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 T=Mr(e,j,O,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,O,k)},M=(j,O)=>{const k=Object.freeze({});Ft.set(k,Object.freeze({owner:e,revision:N,observation:b,epoch:o,notification:j,mode:O}));try{return js(e,k)}finally{Ft.delete(k)}},W=j=>{if(i||!m()||(i=!0,L(ge(t,r)),!m()))return;const O=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=O:O(),m()&&j()};return Wr.set(e,j=>{const O=et(e,j);if(!O||O.notification.type==="canvas_channel_snapshot")return;const k=ee(e),T=o;!k||!O.notification.incarnation||!Q(xe(e,k).birth,O.notification.incarnation)||(L(q=>zr(q,O.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,O)=>Xe(e,j,O),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,O,k)=>m()&&j===o&&O===ee(e)&&(!k||s===k),abortAdmission:(j,O)=>{Lr(e,j,O)&&z(!0)},reserve:j=>{const O=lr(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++,ur(e);try{Ve(e,j)}finally{O==null||O()}}}}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:()=>Os(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,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: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,O=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||!(O!=null&&O.isConnected)||O.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 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 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}
|
|
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:X,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:X,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 X(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")||!X(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 Xt,Zt,Yt,Qt;const D=a.current;if(!D||D.retired||he.source!==D.frame||he.origin!==D.origin||((Xt=l.current)==null?void 0:Xt.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 Z=Date.now();if(Z-m.current<Ie.batchMs){o.current?o.current.dropped=!0:v.current=!0;return}m.current=Z}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 Z=o.current??{documentId:D.documentId,logicalUrl:D.logicalUrl,bridgeGeneration:D.generation,seq:V.seq,console:[],network:[]};Z.seq=V.seq,v.current&&(Z.dropped=!0),v.current=!1;const Ee=u.current,Kt=new TextEncoder;if(o.current||(Ee.overheadBytes=Kt.encode(JSON.stringify({...Z,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}Z.console.push(...V.console),Z.network.push(...V.network);const nn=()=>Ee.overheadBytes+Ee.entryBytes+Math.max(0,Z.console.length-1)+Math.max(0,Z.network.length-1);for(;Z.console.length>500||Z.network.length>200||nn()>Ie.queueBytes;){Z.dropped=!0;const Le=(((Zt=Z.console[0])==null?void 0:Zt.timestamp)??1/0)<=(((Yt=Z.network[0])==null?void 0:Yt.timestamp)??1/0)?"console":"network";if(!Z[Le].length)break;Z[Le].shift(),Ee.entryBytes-=Ee[Le].shift()}o.current=Z,d.current===null&&(d.current=setTimeout(O,Ie.batchMs));return}if(V.__dorkosDevtools==="capture-result"){const Z=_(V.requestId,"capture",D);if(!Z)return;if(Z.kind==="frame"){(Qt=Z.resolve)==null||Qt.call(Z,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=>{X(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,Xe=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=Xe.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?Xe.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 Xe.set(o,{owner:e,run:n,frame:c,phase:"taken",advanced:!1}),o},advancePending(c){const o=Xe.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",Xe.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 Ze(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||!Ze(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=>Ze(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||!Ze(e,t,!0)||!Q(s.birth,r.birth)?null:Object.freeze({current:i=>Ze(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 Xs(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=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}=Xs(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,X=ee(e);return!X&&q&&(l=g??q),!$s(e,j,E)||!R(j)?"discard":(!X&&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)=>Ze(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=Zs(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((X,se)=>X===q[se]))){x.tried=q,b.current=!0;try{const X=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=X&&((G=T.prepareFrameLoad(n,X))==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 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 Oi(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",Ei="/__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}${Ei}`)){if(m)return;const M=Oi(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 O=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=()=>On(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(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]/,Ot=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&&Ot(e[r]);)r+=1;let n=e.length;for(;n>r&&Ot(e[n-1]);)n-=1;let s=n;for(;s>r&&e[s-1]==="#";)s-=1;return s<n&&s>r&&Ot(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}=En(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]),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||!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:O,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-CMzZnmWK.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)},O=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&&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(Er,{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(Et,{label:"Zoom in",onClick:()=>e(),children:h.jsx(Gn,{className:"size-4"})}),h.jsx(Et,{label:"Zoom out",onClick:()=>t(),children:h.jsx(Vn,{className:"size-4"})}),h.jsx(Et,{label:"Reset zoom",onClick:()=>r(),children:h.jsx(Hn,{className:"size-4"})})]})}function Et({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 Oo({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 Eo(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=Eo(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-C3ZKszxn.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-CsNUuaj6.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-uxMaHePf.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-BwTGkJbK.js").then(e=>e.wp),__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(Oo,{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-CMzZnmWK.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(Er,{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};
|
|
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=Zi(a);if(o!=="")return o}return Gi(t)}const Xi=/[\r\u2028\u2029]/,Et=e=>e===" "||e===" ";function Zi(e){const t=/^ {0,3}#[ \t]/.exec(e);if(!t||Xi.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=Xn(),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 X=()=>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&&!X()?{status:"idle"}:(G||(z(null),R("saved",u.current.receipt,U)),{status:C.effect,confirmed:{hash:C.hash,content:U}})}return!G&&!X()?{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 X=l.current.baseHash!==null?{expectedHash:l.current.baseHash}:{expectedContent:l.current.baseContent};return await I(w,X)}catch(X){if(X 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 X=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,X,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 X;if(!H||!A||!b())return Promise.resolve({status:"idle"});const C=A.currentHash,U=((X=l.current.finalToken)==null?void 0:X.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-7E5uwVms.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 Xr(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 Zr(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(Xr(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(()=>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?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(()=>Zr(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(Xr(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-Bqd0IEfK.js"),__vite__mapDeps([6,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).then(e=>({default:e.CanvasFileContent}))),Ao=p.lazy(()=>_e(()=>import("./CanvasModel3dContent-DqL0Sy4r.js"),__vite__mapDeps([23,1,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).then(e=>({default:e.CanvasModel3dContent}))),To=p.lazy(()=>_e(()=>import("./CanvasCsvContent-l7lfyDGn.js"),__vite__mapDeps([24,1,2,25,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])).then(e=>({default:e.CanvasCsvContent}))),Mo=p.lazy(()=>_e(()=>import("./index-BR1m9FON.js").then(e=>e.ww),__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-7E5uwVms.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,Xr as i,ra as j,Qr as r,ho as u};
|