@neuralis/brain-core 0.1.0 → 0.2.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/README.md +26 -35
- package/app/cards/DiffView.tsx +9 -7
- package/app/cards/README.md +1 -1
- package/app/cards/diffLine.tsx +2 -4
- package/app/filesystem/README.md +1 -1
- package/app/filesystem/api/index.ts +14 -5
- package/app/filesystem/domain/types.ts +24 -5
- package/app/filesystem/store/filesystemStore.ts +20 -1
- package/app/filesystem/store/listSlice.ts +2 -0
- package/app/filesystem/store/searchSlice.ts +24 -1
- package/app/filesystem/ui/FileTreeSearch.tsx +29 -2
- package/app/filesystem/ui/PendingChangesPanel.tsx +74 -17
- package/app/filesystem/ui/PendingReviewDialog.tsx +45 -20
- package/app/filesystem/ui/README.md +8 -7
- package/app/filesystem/ui/ReembedDialog.tsx +20 -9
- package/app/filesystem/ui/SourceDeleteConfirm.tsx +1 -1
- package/app/filesystem/ui/SourcesPanel.tsx +110 -17
- package/app/filesystem/ui/VectorHealthPanel.tsx +14 -0
- package/app/filesystem/ui/pendingChangesModel.ts +9 -5
- package/dist/app/chunks/{astro-LRAFGXNX.js → astro-B2J4AS2D.js} +1 -1
- package/dist/app/chunks/bash-KY6SAQTH.js +1 -0
- package/dist/app/chunks/c-OBOPYVZ7.js +1 -0
- package/dist/app/chunks/{chunk-5H7ZCOD3.js → chunk-2X3GNKJ3.js} +1 -1
- package/dist/app/chunks/{chunk-XIFGTNRM.js → chunk-JPJIVRFI.js} +1 -1
- package/dist/app/chunks/{chunk-RH3QY5LF.js → chunk-LEFIFWND.js} +1 -1
- package/dist/app/chunks/{chunk-G4RZ3UNX.js → chunk-N6RXX3PH.js} +1 -1
- package/dist/app/chunks/{chunk-QXXJ73P5.js → chunk-PZAW4HPB.js} +1 -1
- package/dist/app/chunks/{chunk-3QLE7Y4L.js → chunk-ZBYWWTO6.js} +1 -1
- package/dist/app/chunks/cpp-TVWVOTEQ.js +1 -0
- package/dist/app/chunks/css-MANZBYA4.js +1 -0
- package/dist/app/chunks/{elixir-M36XROA6.js → elixir-S725Z7EH.js} +1 -1
- package/dist/app/chunks/{elm-7BG6QAIK.js → elm-5WUUSTNB.js} +1 -1
- package/dist/app/chunks/graphql-UGOPR3WU.js +1 -0
- package/dist/app/chunks/html-F6FWTBSG.js +1 -0
- package/dist/app/chunks/java-ANIVV5H5.js +1 -0
- package/dist/app/chunks/javascript-IH374YWG.js +1 -0
- package/dist/app/chunks/json-WGGVVXSB.js +1 -0
- package/dist/app/chunks/jsx-OTXJQD32.js +1 -0
- package/dist/app/chunks/{latex-ZWK7SXB6.js → latex-QCZNITGN.js} +1 -1
- package/dist/app/chunks/lua-4CRZ64PU.js +1 -0
- package/dist/app/chunks/{nginx-2L6VRV3A.js → nginx-V4CYS7WR.js} +1 -1
- package/dist/app/chunks/{perl-PBUAXXK6.js → perl-BHTX7F5B.js} +1 -1
- package/dist/app/chunks/{php-QJX57PA6.js → php-AYGJ5WYZ.js} +1 -1
- package/dist/app/chunks/r-4YFCFA4B.js +1 -0
- package/dist/app/chunks/{ruby-RLOWMVPO.js → ruby-42NMJWAL.js} +1 -1
- package/dist/app/chunks/{scss-B5CAI3HR.js → scss-XD7VU2CU.js} +1 -1
- package/dist/app/chunks/sql-B55MH6JJ.js +1 -0
- package/dist/app/chunks/{svelte-GT3D4C44.js → svelte-WR3QPIJU.js} +1 -1
- package/dist/app/chunks/tsx-S73GAE2L.js +1 -0
- package/dist/app/chunks/typescript-NEWOAB5Z.js +1 -0
- package/dist/app/chunks/{vue-JOW62MHD.js → vue-CCDS4VZK.js} +1 -1
- package/dist/app/chunks/xml-UXKAGLDR.js +1 -0
- package/dist/app/chunks/yaml-UMWKDTK7.js +1 -0
- package/dist/app/host.js +40 -40
- package/dist/scripts/embeddingLockV3.d.ts +30 -0
- package/dist/scripts/embeddingLockV3.d.ts.map +1 -0
- package/dist/scripts/embeddingLockV3.js +100 -0
- package/dist/scripts/embeddingLockV3.js.map +1 -0
- package/dist/scripts/vectorProofV1.d.ts +90 -0
- package/dist/scripts/vectorProofV1.d.ts.map +1 -0
- package/dist/scripts/vectorProofV1.js +220 -0
- package/dist/scripts/vectorProofV1.js.map +1 -0
- package/dist/src/config/env.d.ts +21 -0
- package/dist/src/config/env.d.ts.map +1 -1
- package/dist/src/config/env.js +55 -0
- package/dist/src/config/env.js.map +1 -1
- package/dist/src/connectors/AppSourceConfigStore.d.ts +12 -2
- package/dist/src/connectors/AppSourceConfigStore.d.ts.map +1 -1
- package/dist/src/connectors/AppSourceConfigStore.js +48 -40
- package/dist/src/connectors/AppSourceConfigStore.js.map +1 -1
- package/dist/src/connectors/LocalDiskConnector.d.ts +11 -14
- package/dist/src/connectors/LocalDiskConnector.d.ts.map +1 -1
- package/dist/src/connectors/LocalDiskConnector.js +87 -107
- package/dist/src/connectors/LocalDiskConnector.js.map +1 -1
- package/dist/src/connectors/sourceConfigMutation.d.ts +11 -1
- package/dist/src/connectors/sourceConfigMutation.d.ts.map +1 -1
- package/dist/src/connectors/sourceConfigMutation.js +36 -3
- package/dist/src/connectors/sourceConfigMutation.js.map +1 -1
- package/dist/src/domain/chunker.js +8 -3
- package/dist/src/domain/chunker.js.map +1 -1
- package/dist/src/domain/healthTypes.d.ts +11 -0
- package/dist/src/domain/healthTypes.d.ts.map +1 -1
- package/dist/src/domain/mime.d.ts +1 -0
- package/dist/src/domain/mime.d.ts.map +1 -1
- package/dist/src/domain/mime.js +48 -0
- package/dist/src/domain/mime.js.map +1 -1
- package/dist/src/domain/pendingChange.d.ts +7 -0
- package/dist/src/domain/pendingChange.d.ts.map +1 -1
- package/dist/src/domain/pendingChange.js +11 -0
- package/dist/src/domain/pendingChange.js.map +1 -1
- package/dist/src/domain/sourceConfig.d.ts +7 -14
- package/dist/src/domain/sourceConfig.d.ts.map +1 -1
- package/dist/src/domain/sourceConfig.js +1 -13
- package/dist/src/domain/sourceConfig.js.map +1 -1
- package/dist/src/domain/sourcePackages.d.ts +11 -2
- package/dist/src/domain/sourcePackages.d.ts.map +1 -1
- package/dist/src/domain/syncTrigger.d.ts +2 -3
- package/dist/src/domain/syncTrigger.d.ts.map +1 -1
- package/dist/src/domain/syncTrigger.js +2 -3
- package/dist/src/domain/syncTrigger.js.map +1 -1
- package/dist/src/domain/syncTypes.d.ts +21 -4
- package/dist/src/domain/syncTypes.d.ts.map +1 -1
- package/dist/src/domain/syncTypes.js.map +1 -1
- package/dist/src/domain/text.d.ts +3 -0
- package/dist/src/domain/text.d.ts.map +1 -1
- package/dist/src/domain/text.js +5 -0
- package/dist/src/domain/text.js.map +1 -1
- package/dist/src/domain/types.d.ts +9 -0
- package/dist/src/domain/types.d.ts.map +1 -1
- package/dist/src/embeddings/clients/GeminiEmbedder.d.ts.map +1 -1
- package/dist/src/embeddings/clients/GeminiEmbedder.js +11 -5
- package/dist/src/embeddings/clients/GeminiEmbedder.js.map +1 -1
- package/dist/src/embeddings/clients/OllamaEmbedder.d.ts.map +1 -1
- package/dist/src/embeddings/clients/OllamaEmbedder.js +13 -6
- package/dist/src/embeddings/clients/OllamaEmbedder.js.map +1 -1
- package/dist/src/embeddings/clients/OpenAIEmbedder.d.ts.map +1 -1
- package/dist/src/embeddings/clients/OpenAIEmbedder.js +12 -9
- package/dist/src/embeddings/clients/OpenAIEmbedder.js.map +1 -1
- package/dist/src/embeddings/clients/QwenEmbedder.d.ts.map +1 -1
- package/dist/src/embeddings/clients/QwenEmbedder.js +12 -5
- package/dist/src/embeddings/clients/QwenEmbedder.js.map +1 -1
- package/dist/src/embeddings/clients/VoyageEmbedder.d.ts.map +1 -1
- package/dist/src/embeddings/clients/VoyageEmbedder.js +12 -5
- package/dist/src/embeddings/clients/VoyageEmbedder.js.map +1 -1
- package/dist/src/embeddings/factory.d.ts +2 -0
- package/dist/src/embeddings/factory.d.ts.map +1 -1
- package/dist/src/embeddings/factory.js +23 -3
- package/dist/src/embeddings/factory.js.map +1 -1
- package/dist/src/embeddings/lock.d.ts +22 -11
- package/dist/src/embeddings/lock.d.ts.map +1 -1
- package/dist/src/embeddings/lock.js +47 -29
- package/dist/src/embeddings/lock.js.map +1 -1
- package/dist/src/embeddings/retry.d.ts +5 -0
- package/dist/src/embeddings/retry.d.ts.map +1 -1
- package/dist/src/embeddings/retry.js +35 -0
- package/dist/src/embeddings/retry.js.map +1 -1
- package/dist/src/events/pending.d.ts +56 -0
- package/dist/src/events/pending.d.ts.map +1 -0
- package/dist/src/events/pending.js +108 -0
- package/dist/src/events/pending.js.map +1 -0
- package/dist/src/events/source.d.ts +60 -14
- package/dist/src/events/source.d.ts.map +1 -1
- package/dist/src/events/source.js +149 -31
- package/dist/src/events/source.js.map +1 -1
- package/dist/src/events/vector.d.ts +33 -0
- package/dist/src/events/vector.d.ts.map +1 -0
- package/dist/src/events/vector.js +57 -0
- package/dist/src/events/vector.js.map +1 -0
- package/dist/src/git/GitRunner.d.ts.map +1 -1
- package/dist/src/git/GitRunner.js +11 -8
- package/dist/src/git/GitRunner.js.map +1 -1
- package/dist/src/git/sourceGitControl.d.ts.map +1 -1
- package/dist/src/git/sourceGitControl.js +2 -1
- package/dist/src/git/sourceGitControl.js.map +1 -1
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/lifecycle.d.ts +20 -4
- package/dist/src/lifecycle.d.ts.map +1 -1
- package/dist/src/lifecycle.js +5 -1
- package/dist/src/lifecycle.js.map +1 -1
- package/dist/src/routes/health.js +6 -1
- package/dist/src/routes/health.js.map +1 -1
- package/dist/src/routes/pending.d.ts.map +1 -1
- package/dist/src/routes/pending.js +2 -1
- package/dist/src/routes/pending.js.map +1 -1
- package/dist/src/routes/sources.d.ts.map +1 -1
- package/dist/src/routes/sources.js +60 -11
- package/dist/src/routes/sources.js.map +1 -1
- package/dist/src/services/BridgeService.d.ts +2 -2
- package/dist/src/services/BridgeService.d.ts.map +1 -1
- package/dist/src/services/BridgeService.js +11 -2
- package/dist/src/services/BridgeService.js.map +1 -1
- package/dist/src/services/FilesystemService.d.ts +3 -1
- package/dist/src/services/FilesystemService.d.ts.map +1 -1
- package/dist/src/services/FilesystemService.js +3 -1
- package/dist/src/services/FilesystemService.js.map +1 -1
- package/dist/src/services/FilesystemUiService.js +1 -1
- package/dist/src/services/FilesystemUiService.js.map +1 -1
- package/dist/src/services/SyncScheduler.d.ts.map +1 -1
- package/dist/src/services/SyncScheduler.js +0 -14
- package/dist/src/services/SyncScheduler.js.map +1 -1
- package/dist/src/services/VectorHealthService.d.ts.map +1 -1
- package/dist/src/services/VectorHealthService.js +2 -46
- package/dist/src/services/VectorHealthService.js.map +1 -1
- package/dist/src/services/baselineRepair.d.ts +2 -2
- package/dist/src/services/baselineRepair.js +2 -2
- package/dist/src/services/declaredSources.d.ts +8 -1
- package/dist/src/services/declaredSources.d.ts.map +1 -1
- package/dist/src/services/declaredSources.js +19 -19
- package/dist/src/services/declaredSources.js.map +1 -1
- package/dist/src/store/dataFormats.d.ts +14 -3
- package/dist/src/store/dataFormats.d.ts.map +1 -1
- package/dist/src/store/dataFormats.js +15 -5
- package/dist/src/store/dataFormats.js.map +1 -1
- package/dist/src/sync/DeltaSyncRunner.d.ts.map +1 -1
- package/dist/src/sync/DeltaSyncRunner.js +78 -243
- package/dist/src/sync/DeltaSyncRunner.js.map +1 -1
- package/dist/src/sync/SyncJobQueue.d.ts +33 -4
- package/dist/src/sync/SyncJobQueue.d.ts.map +1 -1
- package/dist/src/sync/SyncJobQueue.js +179 -19
- package/dist/src/sync/SyncJobQueue.js.map +1 -1
- package/dist/src/sync/moveDetector.d.ts +2 -1
- package/dist/src/sync/moveDetector.d.ts.map +1 -1
- package/dist/src/sync/moveDetector.js +2 -1
- package/dist/src/sync/moveDetector.js.map +1 -1
- package/dist/src/tools/fs_search.d.ts.map +1 -1
- package/dist/src/tools/fs_search.js +8 -0
- package/dist/src/tools/fs_search.js.map +1 -1
- package/dist/src/tools/fs_write.js +3 -1
- package/dist/src/tools/fs_write.js.map +1 -1
- package/dist/src/usecases/chunkUpsert.d.ts +4 -0
- package/dist/src/usecases/chunkUpsert.d.ts.map +1 -1
- package/dist/src/usecases/chunkUpsert.js +103 -60
- package/dist/src/usecases/chunkUpsert.js.map +1 -1
- package/dist/src/usecases/embeddingBacklog.d.ts +31 -0
- package/dist/src/usecases/embeddingBacklog.d.ts.map +1 -0
- package/dist/src/usecases/embeddingBacklog.js +244 -0
- package/dist/src/usecases/embeddingBacklog.js.map +1 -0
- package/dist/src/usecases/listSourcePackages.js +17 -1
- package/dist/src/usecases/listSourcePackages.js.map +1 -1
- package/dist/src/usecases/mediaLane.d.ts +11 -4
- package/dist/src/usecases/mediaLane.d.ts.map +1 -1
- package/dist/src/usecases/mediaLane.js +67 -30
- package/dist/src/usecases/mediaLane.js.map +1 -1
- package/dist/src/usecases/pendingReview.d.ts.map +1 -1
- package/dist/src/usecases/pendingReview.js +24 -7
- package/dist/src/usecases/pendingReview.js.map +1 -1
- package/dist/src/usecases/purgeExcludedPoints.d.ts +2 -0
- package/dist/src/usecases/purgeExcludedPoints.d.ts.map +1 -1
- package/dist/src/usecases/purgeExcludedPoints.js +3 -2
- package/dist/src/usecases/purgeExcludedPoints.js.map +1 -1
- package/dist/src/usecases/readFiles.d.ts.map +1 -1
- package/dist/src/usecases/readFiles.js +33 -6
- package/dist/src/usecases/readFiles.js.map +1 -1
- package/dist/src/usecases/reconcileSourcePackageRoots.d.ts +31 -0
- package/dist/src/usecases/reconcileSourcePackageRoots.d.ts.map +1 -0
- package/dist/src/usecases/reconcileSourcePackageRoots.js +114 -0
- package/dist/src/usecases/reconcileSourcePackageRoots.js.map +1 -0
- package/dist/src/usecases/searchFiles.d.ts.map +1 -1
- package/dist/src/usecases/searchFiles.js +62 -64
- package/dist/src/usecases/searchFiles.js.map +1 -1
- package/dist/src/usecases/syncIndexedFile.d.ts +42 -0
- package/dist/src/usecases/syncIndexedFile.d.ts.map +1 -0
- package/dist/src/usecases/syncIndexedFile.js +242 -0
- package/dist/src/usecases/syncIndexedFile.js.map +1 -0
- package/dist/src/usecases/syncPointWrites.d.ts +5 -0
- package/dist/src/usecases/syncPointWrites.d.ts.map +1 -1
- package/dist/src/usecases/syncPointWrites.js +32 -5
- package/dist/src/usecases/syncPointWrites.js.map +1 -1
- package/dist/src/usecases/uploadBinary.d.ts.map +1 -1
- package/dist/src/usecases/uploadBinary.js +36 -49
- package/dist/src/usecases/uploadBinary.js.map +1 -1
- package/dist/src/usecases/vector/endpointGuard.js +2 -1
- package/dist/src/usecases/vector/endpointGuard.js.map +1 -1
- package/dist/src/usecases/vector/estimate.d.ts +7 -4
- package/dist/src/usecases/vector/estimate.d.ts.map +1 -1
- package/dist/src/usecases/vector/estimate.js +8 -5
- package/dist/src/usecases/vector/estimate.js.map +1 -1
- package/dist/src/usecases/vector/rebuildGeneration.d.ts +29 -5
- package/dist/src/usecases/vector/rebuildGeneration.d.ts.map +1 -1
- package/dist/src/usecases/vector/rebuildGeneration.js +224 -82
- package/dist/src/usecases/vector/rebuildGeneration.js.map +1 -1
- package/dist/src/usecases/vectorMaintenance.d.ts +46 -4
- package/dist/src/usecases/vectorMaintenance.d.ts.map +1 -1
- package/dist/src/usecases/vectorMaintenance.js +190 -11
- package/dist/src/usecases/vectorMaintenance.js.map +1 -1
- package/dist/src/usecases/write/commit.d.ts +6 -8
- package/dist/src/usecases/write/commit.d.ts.map +1 -1
- package/dist/src/usecases/write/commit.js +96 -112
- package/dist/src/usecases/write/commit.js.map +1 -1
- package/dist/src/usecases/write/content.js +1 -2
- package/dist/src/usecases/write/content.js.map +1 -1
- package/dist/src/usecases/write/ports.d.ts +1 -0
- package/dist/src/usecases/write/ports.d.ts.map +1 -1
- package/dist/src/vector/FilesystemVectorIndex.d.ts +34 -3
- package/dist/src/vector/FilesystemVectorIndex.d.ts.map +1 -1
- package/dist/src/vector/FilesystemVectorIndex.js +254 -20
- package/dist/src/vector/FilesystemVectorIndex.js.map +1 -1
- package/dist/src/vector/InMemoryVectorIndex.d.ts +9 -2
- package/dist/src/vector/InMemoryVectorIndex.d.ts.map +1 -1
- package/dist/src/vector/InMemoryVectorIndex.js +25 -6
- package/dist/src/vector/InMemoryVectorIndex.js.map +1 -1
- package/dist/src/vector/QdrantVectorIndex.d.ts +35 -9
- package/dist/src/vector/QdrantVectorIndex.d.ts.map +1 -1
- package/dist/src/vector/QdrantVectorIndex.js +209 -90
- package/dist/src/vector/QdrantVectorIndex.js.map +1 -1
- package/dist/src/vector/qdrantFilter.d.ts +3 -1
- package/dist/src/vector/qdrantFilter.d.ts.map +1 -1
- package/dist/src/vector/qdrantFilter.js +2 -0
- package/dist/src/vector/qdrantFilter.js.map +1 -1
- package/dist/src/vector/types.d.ts +81 -0
- package/dist/src/vector/types.d.ts.map +1 -1
- package/dist/src/vector/types.js +2 -0
- package/dist/src/vector/types.js.map +1 -1
- package/dist/src/wiring.d.ts +6 -0
- package/dist/src/wiring.d.ts.map +1 -1
- package/dist/src/wiring.js +62 -3
- package/dist/src/wiring.js.map +1 -1
- package/dist/tools/fs_search.json +2 -2
- package/docs/drive-overview.md +2 -2
- package/instructions/brain-model.md +1 -1
- package/package.json +999 -10
- package/rules/brain-rules.md +1 -1
- package/skills/connect-business-data/SKILL.md +6 -4
- package/skills/create-package/SKILL.md +14 -12
- package/skills/create-package/references/config-and-credentials.md +3 -3
- package/skills/create-package/references/connectors-and-uri-policies.md +5 -3
- package/skills/create-package/references/manifest-and-discovery.md +4 -3
- package/skills/create-package/references/runtime-and-build.md +9 -9
- package/skills/create-package/references/skills-and-context.md +3 -3
- package/skills/create-package/references/surfaces-and-design.md +2 -1
- package/skills/create-package/references/team-and-workflows.md +2 -2
- package/skills/create-package/references/test-and-ship.md +15 -15
- package/skills/create-package/references/tools-and-schemas.md +1 -1
- package/skills/create-package/scripts/check-package.sh +3 -3
- package/skills/create-package/scripts/verify-loaded.sh +16 -16
- package/skills/manage-files/SKILL.md +2 -2
- package/skills/manage-sources/SKILL.md +16 -15
- package/skills/manage-sources/scripts/reembed.sh +9 -3
- package/skills/sync/SKILL.md +4 -4
- package/tools/fs_search.json +2 -2
- package/dist/app/chunks/bash-M45GHPBQ.js +0 -1
- package/dist/app/chunks/c-X3REOAWD.js +0 -1
- package/dist/app/chunks/cpp-VOWI743W.js +0 -1
- package/dist/app/chunks/css-2ZVPHE25.js +0 -1
- package/dist/app/chunks/graphql-7V2NP54C.js +0 -1
- package/dist/app/chunks/html-UF3LFLNA.js +0 -1
- package/dist/app/chunks/java-PNTAU4L3.js +0 -1
- package/dist/app/chunks/javascript-4JJTQGEL.js +0 -1
- package/dist/app/chunks/json-VLQ6D3JH.js +0 -1
- package/dist/app/chunks/jsx-KQKSLAAH.js +0 -1
- package/dist/app/chunks/lua-UFPYUJ2O.js +0 -1
- package/dist/app/chunks/r-QEZB45SR.js +0 -1
- package/dist/app/chunks/sql-DTZHNUZP.js +0 -1
- package/dist/app/chunks/tsx-WPR2WRZD.js +0 -1
- package/dist/app/chunks/typescript-LWO362OA.js +0 -1
- package/dist/app/chunks/xml-A5H72RTS.js +0 -1
- package/dist/app/chunks/yaml-MXHSIJCI.js +0 -1
- package/dist/src/services/purgePendingNodes.d.ts +0 -32
- package/dist/src/services/purgePendingNodes.d.ts.map +0 -1
- package/dist/src/services/purgePendingNodes.js +0 -61
- package/dist/src/services/purgePendingNodes.js.map +0 -1
- /package/dist/app/chunks/{chunk-737Y24HS.js → chunk-3JASFUPF.js} +0 -0
- /package/dist/app/chunks/{chunk-DKD2L57N.js → chunk-6EYLOQ4F.js} +0 -0
- /package/dist/app/chunks/{chunk-KYH5EHHY.js → chunk-7YRZ5LOQ.js} +0 -0
- /package/dist/app/chunks/{chunk-6TC3DVWV.js → chunk-C7LU4RID.js} +0 -0
- /package/dist/app/chunks/{chunk-TY33BMKR.js → chunk-CD52YDZP.js} +0 -0
- /package/dist/app/chunks/{chunk-OLEIKJ3X.js → chunk-DCJKTCJ5.js} +0 -0
- /package/dist/app/chunks/{chunk-QLBZ4JR2.js → chunk-EXIU2KBV.js} +0 -0
- /package/dist/app/chunks/{chunk-SFUNBBEA.js → chunk-FDP4LO4P.js} +0 -0
- /package/dist/app/chunks/{chunk-BGRVFATT.js → chunk-HNETUS7U.js} +0 -0
- /package/dist/app/chunks/{chunk-4QNMHAIR.js → chunk-LBFZJEDR.js} +0 -0
- /package/dist/app/chunks/{chunk-TRRUHDPN.js → chunk-ULRXL5VM.js} +0 -0
- /package/dist/app/chunks/{chunk-S6B4WWIF.js → chunk-XJK47SMJ.js} +0 -0
- /package/dist/app/chunks/{chunk-DZ5C5FKI.js → chunk-YYAAIAU2.js} +0 -0
- /package/dist/app/chunks/{clojure-OC6KPSJO.js → clojure-4QCN4GHG.js} +0 -0
- /package/dist/app/chunks/{core-KGE7TQJ3.js → core-ZHTX3P2Q.js} +0 -0
- /package/dist/app/chunks/{csharp-E7VIFITL.js → csharp-HQWR4N52.js} +0 -0
- /package/dist/app/chunks/{dark-plus-BOSCZXE4.js → dark-plus-GYPKKZES.js} +0 -0
- /package/dist/app/chunks/{dart-6Y3X27SZ.js → dart-FO4TTVO2.js} +0 -0
- /package/dist/app/chunks/{diff-TR2NPA64.js → diff-SHANV4YC.js} +0 -0
- /package/dist/app/chunks/{dist-T32U2VVR.js → dist-WSDF34DM.js} +0 -0
- /package/dist/app/chunks/{docker-N33HOW54.js → docker-VX55HTDS.js} +0 -0
- /package/dist/app/chunks/{go-6DGG5UTP.js → go-5UCPEC6S.js} +0 -0
- /package/dist/app/chunks/{haskell-KK36PMMM.js → haskell-25PJ3OSG.js} +0 -0
- /package/dist/app/chunks/{ini-VHVQ5TPB.js → ini-BJIVD5MK.js} +0 -0
- /package/dist/app/chunks/{kotlin-44WS3JHE.js → kotlin-MNR6XOEQ.js} +0 -0
- /package/dist/app/chunks/{less-5WZ3KLAK.js → less-KA5JURX6.js} +0 -0
- /package/dist/app/chunks/{light-plus-HGGBC43G.js → light-plus-QXH2UUWZ.js} +0 -0
- /package/dist/app/chunks/{make-X7RXMVW7.js → make-LPD5KOCO.js} +0 -0
- /package/dist/app/chunks/{markdown-46IKUAIB.js → markdown-LMWF6MQR.js} +0 -0
- /package/dist/app/chunks/{mdx-DGLHDAO7.js → mdx-WPMNN5BS.js} +0 -0
- /package/dist/app/chunks/{nix-Q6FYQZLX.js → nix-QGWLUUMZ.js} +0 -0
- /package/dist/app/chunks/{powershell-L4KJJ6DK.js → powershell-7GSBBEFF.js} +0 -0
- /package/dist/app/chunks/{prisma-IKS4LVH2.js → prisma-FPMPQISO.js} +0 -0
- /package/dist/app/chunks/{proto-AYCDOTJO.js → proto-7KDX5Z2U.js} +0 -0
- /package/dist/app/chunks/{python-KXMCSAFQ.js → python-CFG4FTQW.js} +0 -0
- /package/dist/app/chunks/{rust-J3BC3P6V.js → rust-X7A37WU3.js} +0 -0
- /package/dist/app/chunks/{scala-AYIIHBJK.js → scala-OYHJSUG2.js} +0 -0
- /package/dist/app/chunks/{swift-QPHHCQD3.js → swift-PE7VNYW5.js} +0 -0
- /package/dist/app/chunks/{toml-UV7JK7K7.js → toml-ETQRDILP.js} +0 -0
package/dist/app/host.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import{a as Vo,c as W}from"./chunks/chunk-DCANE7XH.js";var $e=Vo((pB,k0)=>{var qf=globalThis.__neuralis_shared_modules__,v0=qf&&Object.prototype.hasOwnProperty.call(qf,"react")?qf.react:void 0;if(v0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");k0.exports=v0});var mr=Vo((mB,C0)=>{var Vf=globalThis.__neuralis_shared_modules__,S0=Vf&&Object.prototype.hasOwnProperty.call(Vf,"@neuralis/package-system/client")?Vf["@neuralis/package-system/client"]:void 0;if(S0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");C0.exports=S0});var Qr=Vo((gB,I0)=>{var $f=globalThis.__neuralis_shared_modules__,L0=$f&&Object.prototype.hasOwnProperty.call($f,"@neuralis/agent-core/app/chat")?$f["@neuralis/agent-core/app/chat"]:void 0;if(L0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");I0.exports=L0});var le=Vo((IU,Rb)=>{var mh=globalThis.__neuralis_shared_modules__,Nb=mh&&Object.prototype.hasOwnProperty.call(mh,"react/jsx-runtime")?mh["react/jsx-runtime"]:void 0;if(Nb===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Rb.exports=Nb});var Ya=Vo((_8,Fb)=>{var yh=globalThis.__neuralis_shared_modules__,Db=yh&&Object.prototype.hasOwnProperty.call(yh,"react-dom")?yh["react-dom"]:void 0;if(Db===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");Fb.exports=Db});var YI=Vo((Y$,XI)=>{var u0=globalThis.__neuralis_shared_modules__,KI=u0&&Object.prototype.hasOwnProperty.call(u0,"@neuralis/agent-core/app/chat/store")?u0["@neuralis/agent-core/app/chat/store"]:void 0;if(KI===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");XI.exports=KI});var Hf=W($e(),1),Uf=W(mr(),1),d2=W(Qr(),1);var Mn=W($e(),1);var A0=n=>{let e,t=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(h=>h(e,f))}},a=()=>e,i={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(t.add(u),()=>t.delete(u))},l=e=n(r,a,i);return i},P0=(n=>n?A0(n):A0);var sl=W($e(),1);var I2=n=>n;function A2(n,e=I2){let t=sl.default.useSyncExternalStore(n.subscribe,sl.default.useCallback(()=>e(n.getState()),[n,e]),sl.default.useCallback(()=>e(n.getInitialState()),[n,e]));return sl.default.useDebugValue(t),t}var N0=n=>{let e=P0(n),t=r=>A2(e,r);return Object.assign(t,e),t},R0=(n=>n?N0(n):N0);function Xf(n,e){let t;try{t=n()}catch{return}return{getItem:a=>{var s;let o=l=>l===null?null:JSON.parse(l,e?.reviver),i=(s=t.getItem(a))!=null?s:null;return i instanceof Promise?i.then(o):o(i)},setItem:(a,s)=>t.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>t.removeItem(a)}}var Kf=n=>e=>{try{let t=n(e);return t instanceof Promise?t:{then(r){return Kf(r)(t)},catch(r){return this}}}catch(t){return{then(r){return this},catch(r){return Kf(r)(t)}}}},P2=(n,e)=>(t,r,a)=>{let s={storage:Xf(()=>window.localStorage),partialize:g=>g,version:0,merge:(g,x)=>({...x,...g}),...e},o=!1,i=0,l=new Set,u=new Set,c=s.storage;if(!c)return n((...g)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...g)},r,a);let d=()=>{let g=s.partialize({...r()});return c.setItem(s.name,{state:g,version:s.version})},f=a.setState;a.setState=(g,x)=>(f(g,x),d());let h=n((...g)=>(t(...g),d()),r,a);a.getInitialState=()=>h;let p,m=()=>{var g,x;if(!c)return;let w=++i;o=!1,l.forEach(C=>{var k;return C((k=r())!=null?k:h)});let y=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(g=r())!=null?g:h))||void 0;return Kf(c.getItem.bind(c))(s.name).then(C=>{if(C)if(typeof C.version=="number"&&C.version!==s.version){if(s.migrate){let k=s.migrate(C.state,C.version);return k instanceof Promise?k.then(v=>[!0,v]):[!0,k]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,C.state];return[!1,void 0]}).then(C=>{var k;if(w!==i)return;let[v,b]=C;if(p=s.merge(b,(k=r())!=null?k:h),t(p,!0),v)return d()}).then(()=>{w===i&&(y?.(r(),void 0),p=r(),o=!0,u.forEach(C=>C(p)))}).catch(C=>{w===i&&y?.(void 0,C)})};return a.persist={setOptions:g=>{s={...s,...g},g.storage&&(c=g.storage)},clearStorage:()=>{++i,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>m(),hasHydrated:()=>o,onHydrate:g=>(l.add(g),()=>{l.delete(g)}),onFinishHydration:g=>(u.add(g),()=>{u.delete(g)})},s.skipHydration||m(),p||h},M0=P2;var T0=W(mr(),1);function Ze(){return(0,T0.tryGetPackageApiImperativeAsync)("brain-core")}async function $o(n,e,t){let r=await Ze(),a={agentId:n};return e&&(a.projectId=e),t?.uri&&(a.uri=t.uri),typeof t?.recursive=="boolean"&&(a.recursive=t.recursive),t?.include&&(a.include=t.include),typeof t?.summary_chars=="number"&&(a.summary_chars=t.summary_chars),typeof t?.include_metadata=="boolean"&&(a.include_metadata=t.include_metadata),typeof t?.only_indexed=="boolean"&&(a.only_indexed=t.only_indexed),typeof t?.sources_only=="boolean"&&(a.sources_only=t.sources_only),typeof t?.include_counts=="boolean"&&(a.include_counts=t.include_counts),typeof t?.limit=="number"&&(a.limit=t.limit),r.post("list",a)}async function D0(n,e,t){return(await $o(n,e,{uri:`${t}://`,recursive:!1,include:"folders",include_counts:!0,limit:1})).sources?.[0]??null}async function Ko(n){return(await Ze()).post("read",n)}async function F0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.scope&&(e.scope=n.scope),n.observed&&(e.observed="1"),(await Ze()).get("sources",e)}async function Yf(n){return(await Ze()).patch("sources",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},...n.config})}async function E0(n){return(await Ze()).post("sources/sync",n)}async function B0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.source&&(e.source=n.source),(await Ze()).get("sources/sync-status",e)}async function O0(n){return(await Ze()).post("sources/enabled",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},source:n.source,enabled:n.enabled})}async function Zu(n){let e=new URLSearchParams;return e.set("agentId",n.agentId),n.projectId&&e.set("projectId",n.projectId),(await Ze()).get("sources/discoverable",Object.fromEntries(e))}function ds(n){return n?{repo:n}:{}}function gr(n){return n?{repo:n}:{}}async function Xo(n){let e={agentId:n.agentId,source:n.source};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/repos",e)}async function Qu(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/status",e)}async function _0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/branch",e)}async function ec(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),path:n.path};return typeof n.commit=="string"&&(e.commit=n.commit),typeof n.base=="string"&&(e.base=n.base),typeof n.head=="string"&&(e.head=n.head),typeof n.staged=="boolean"&&(e.staged=n.staged?"1":"0"),n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/diff",e)}async function tc(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Ze()).get("git/log",e)}async function H0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Ze()).get("git/log-stats",e)}async function nc(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),sha:n.sha};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/commit",e)}async function ol(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/outgoing",e)}async function U0(n){let e={agentId:n.agentId,source:n.source,...ds(n.repo),path:n.path,rev:n.rev};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("git/show",e)}var xr=()=>Ze();async function G0(n){return(await xr()).post("git/stage",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function z0(n){return(await xr()).post("git/unstage",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function W0(n){return(await xr()).post("git/stage",{source:n.source,...gr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function j0(n){return(await xr()).post("git/unstage",{source:n.source,...gr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function q0(n){return(await xr()).post("git/discard",{source:n.source,...gr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function V0(n){return(await xr()).post("git/commit",{source:n.source,...gr(n.repo),message:n.message,...n.amend?{amend:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function $0(n){return(await xr()).post("git/branch",{source:n.source,...gr(n.repo),action:"create",name:n.name,...n.startPoint?{startPoint:n.startPoint}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function K0(n){return(await xr()).post("git/branch",{source:n.source,...gr(n.repo),action:"delete",name:n.name,...n.force?{force:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function X0(n){return(await xr()).post("git/restore",{source:n.source,...gr(n.repo),rescue:n.rescue,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Jf(n){return(await xr()).post("git/checkout",{source:n.source,...gr(n.repo),ref:n.ref,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Y0(n){return(await xr()).post("git/fetch",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function J0(n){return(await xr()).post("git/pull",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Z0(n){return(await xr()).post("git/push",{source:n.source,...gr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Q0(n){return(await Ze()).post("search",n)}async function rc(n){let e=new FormData;return e.append("agentId",n.agentId),n.projectId&&e.append("projectId",n.projectId),e.append("file",n.file),n.uri&&e.append("uri",n.uri),n.tags?.length&&e.append("tags",n.tags.join(",")),(await Ze()).upload("upload",e)}async function yr(n){return(await Ze()).post("write",n)}function ma(n,e){return n?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":n?.message||n?.error||e}async function ac(n){return(await Ze()).post("approve",n)}async function il(n){return(await(await Ze()).post("pending",{...n,action:"preview"})).preview}async function ex(n){let e=await(await Ze()).post("pending",n);return{ok:e?.ok!==!1,changes:Array.isArray(e?.changes)?e.changes:[],orphanIds:Array.isArray(e?.orphanIds)?e.orphanIds:[]}}async function tx(n){let e={agentId:n.agentId,count_only:"1"};n.projectId&&(e.projectId=n.projectId);let t=await(await Ze()).get("pending",e);return typeof t?.count=="number"?t.count:0}async function nx(n){return(await Ze()).post("pending",{...n,action:"revert"})}async function rx(n){return(await Ze()).post("pending",{...n,action:"discard"})}async function ax(n){return(await Ze()).post("pending",{...n,action:"dismiss"})}async function sx(n){let e=await(await Ze()).post("pending",{...n,action:"discard-orphans"});return{ok:e?.ok!==!1,discarded:typeof e?.discarded=="number"?e.discarded:0}}function ox(n,e,t){let r=new URLSearchParams({agentId:n,uri:e});return t&&r.set("projectId",t),`/api/packages/brain-core/raw?${r.toString()}`}async function ix(n){return(await Ze()).post("health",n)}async function lx(n){return(await Ze()).post("health/scan",n)}async function ux(n){return(await Ze()).post("health/gc",n)}async function cx(n){return(await Ze()).post("sources",n)}async function dx(n){let e=new URLSearchParams({agentId:n.agentId});return n.projectId&&e.set("projectId",n.projectId),n.purgeVectors&&e.set("purge","1"),(await Ze()).del(`sources/${encodeURIComponent(n.source)}?${e.toString()}`)}async function fx(n){return(await Ze()).post("sources/reset",n)}async function hx(n){return(await Ze()).post("sources/reindex",n)}async function px(n){return(await Ze()).post("sources/purge",n)}function Qs(n){return typeof n=="number"&&Number.isFinite(n)?n:null}function N2(n){let e=n&&typeof n=="object"?n:null,t=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=Qs(t?.points),a=Qs(t?.tokens);if(!e||!t||r===null||a===null)return null;let s=Qs(t.relStdErr),o=Qs(t.usd);return{documents:Qs(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:o,usdMargin:s!==null&&o!==null?o*s:null,durationSeconds:Qs(t.seconds)}}async function mx(n){return N2(await(await Ze()).post("sources/reindex",{...n,force:!0,estimate:!0}))}async function gx(n){let e=await(await Ze()).post("sources/reindex",{...n,force:!0}),t=e?.job&&typeof e.job=="object"?e.job:null;return{documents:Qs(e?.documents),truncated:e?.truncated===!0,job:t}}async function xx(n){return(await Ze()).post("sources/cancel",n)}async function yx(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("sources/health",e)}async function Zf(n){let e={path:n.path,agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Ze()).get("sources/browse",e)}async function bx(){return(await Ze()).get("sources/kinds",{})}function Ve(n){let e=n.indexOf("://");return e>0?n.slice(0,e):"brain"}function rr(n){let e=n.indexOf("://");return e>0?n.slice(0,e+3):`${n}://`}function ot(n){let e=n.indexOf("://");if(e<1)return n;let t=n.slice(0,e+3),r=n.lastIndexOf("/");return r<=e+2?t:n.slice(0,r)}function ga(n){let e=n.indexOf("://");if(e<1)return[];let r=`${n.slice(0,e)}://`,a=n.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let o=[r],i=r;for(let l=0;l<s.length-1;l++)i=i.endsWith("/")?`${i}${s[l]}`:`${i}/${s[l]}`,o.push(i);return o}function yt(n){let e=n.indexOf("://"),t=e>=0?n.slice(e+3):n,r=t.lastIndexOf("/");return r>=0?t.slice(r+1):t}var wx=n=>n;function Wa(n){return n.uri}function R2(n,e,t){for(let r of e){if(n[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=ot(r),o=n[r];n[r]={...o||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:t}}}function eo(n,e,t){R2(n,ga(e),t)}function ll(n){if(typeof n=="string")return n;if(Array.isArray(n)){let e=n.map(t=>{if(t){if(typeof t=="string")return t;if(typeof t=="object"){let r=typeof t.text=="string"?t.text:void 0,a=typeof t.content=="string"?t.content:void 0;return r??a}}}).filter(t=>!!(t&&t.trim()));if(e.length>0)return e.join(`
|
|
2
|
-
`)}if(n&&typeof n=="object"){let e=n;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let t=ll(e.content);if(t)return t}try{return JSON.stringify(n,null,2)}catch{return}}}function Yo(n){return Array.isArray(n?.files)?n.files:Array.isArray(n?.widget?.files)?n.widget.files:Array.isArray(n?.state?.files)?n.state.files:Array.isArray(n?.data?.files)?n.data.files:[]}function Jo(n){return ll(n?.text)??ll(n?.content)??ll(n?.file_content)??ll(n?.fileContent)??""}function sc(n){if(!n||typeof n!="object")return;let e=n;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function oc(n,e){return typeof n.fileErrorByPath[e]=="string"||typeof n.fileBaseContentByPath[e]=="string"}function fs(n,e,t){return`${n??""}::${e??""}::${t}`}var Qf=0,eh={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},vx={searchQuery:"",searchMode:"keyword",searchFilters:eh,searchResults:[],searchLoading:!1,searchError:void 0};function th(n,e,t){let r=typeof n=="string"&&n.includes("://")?n:null;if(t&&r)return r.startsWith("brain://")?null:r;let a=r?rr(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(o=>o.source_kind!=="brain"&&typeof o.uri_root=="string")?.uri_root??null}function kx(n,e){return{setSearchQuery:t=>n(()=>({searchQuery:t})),setSearchMode:t=>n(()=>({searchMode:t})),setSearchFilters:t=>n(r=>({searchFilters:{...r.searchFilters,...t}})),clearSearch:()=>n(()=>({searchQuery:"",searchFilters:eh,searchResults:[],searchLoading:!1,searchError:void 0})),async runSearch({agentId:t,projectId:r}){let{searchQuery:a,searchMode:s,searchFilters:o,activeFolderPath:i,sources:l}=e(),u=(a??"").trim(),c=o??eh,d=c.glob.trim(),f=s==="keyword"?u.length>=2||d.length>=2:u.length>=2;if(!t||!f){n(()=>({searchResults:[],searchLoading:!1,searchError:void 0}));return}let h=typeof i=="string"&&i.includes("://")?i:void 0,p=s==="grep"?th(i,l,c.scopeToFolder):c.scopeToFolder?h:void 0;if(s==="grep"&&!p){n(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source."}));return}let m=c.tags.split(",").map(x=>x.trim()).filter(x=>x.length>0),g=++Qf;n(()=>({searchLoading:!0,searchError:void 0}));try{let x=await Q0({agentId:t,...r?{projectId:r}:{},search_mode:s==="keyword"?"filter":s,...u?{query:u}:{},...p?{folder_uri:p}:{},...d?{glob:d}:{},...s!=="grep"&&c.category.trim()?{category:c.category.trim()}:{},...s!=="grep"&&c.status.trim()?{status:c.status.trim()}:{},...s!=="grep"&&m.length>0?{tags:m}:{},...s!=="grep"&&c.createdAfter.trim()?{created_after:c.createdAfter.trim()}:{},...s!=="grep"&&c.createdBefore.trim()?{created_before:c.createdBefore.trim()}:{},limit:s==="semantic"?30:50});if(g!==Qf)return;let w=x.results||[],y=w.find(k=>typeof k.error=="string"&&k.error.length>0),C=w.filter(k=>typeof k.uri=="string"&&k.uri.includes("://")&&!k.error).map(k=>({id:k.id||`fs:${k.uri}:${k.chunk_start??""}`,uri:k.uri,filename:k.filename||String(k.uri).split("/").pop(),content_preview:k.content_preview,snippet:k.snippet,chunk_start:k.chunk_start,chunk_end:k.chunk_end,match_type:k.match_type,score:k.score}));n(()=>({searchResults:C,searchLoading:!1,searchError:y?String(y.error):void 0}))}catch(x){if(g!==Qf)return;n(()=>({searchResults:[],searchLoading:!1,searchError:x instanceof Error?x.message:"Search failed"}))}}}}var nh=new Map;function Zo(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var M2=200;function ic(n,e=M2){let t=[...n],r=[],a=!0;for(;t.length>e&&a;){a=!1;for(let s=0;s<t.length&&t.length>e;){let o=t[s],i=`${o}/`;if(o.endsWith("://")||t.some(l=>l.startsWith(i))){s+=1;continue}t.splice(s,1),r.push(o),a=!0}}return{kept:t,evicted:r}}var T2=Object.keys(Zo());function D2(n){let e={};for(let t of T2)e[t]=n[t];return e}function lc(n){let e=n.expandedFolders;return{openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:e instanceof Set?ic(Array.from(e)).kept:[],sidebarView:n.sidebarView??"tree",activeWorkspaceTab:n.activeWorkspaceTab??"file",workspacePanels:n.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:n.activeFolderPath??"brain://docs"}}function rh(n){let e=Zo();return n?{...e,openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:new Set(Array.isArray(n.expandedFolders)?ic(n.expandedFolders).kept:[]),sidebarView:n.sidebarView??e.sidebarView,activeWorkspaceTab:n.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:n.workspacePanels??e.workspacePanels,activeFolderPath:n.activeFolderPath??e.activeFolderPath}:e}function Sx(n,e){return{async loadList({agentId:t,projectId:r,userId:a,withCounts:s}){if(!t)return;let o=`${t}:${r||""}:${s?"c":""}`,i=nh.get(o);if(i){await i;return}let l="brain://",u=e(),c=a===void 0?u.activeUserId:a,d=u.activeUserId!==null&&u.activeUserId!==c,f=u.activeAgentId!==t||u.activeProjectId!==r||d,h;if(f?(e().fenceInFlightWriters(),n(m=>{let g={...m.contextStateByKey};m.activeAgentId&&(g[fs(m.activeUserId,m.activeProjectId,m.activeAgentId)]=D2(m));let x=fs(c,r,t);return h=g[x],delete g[x],{activeUserId:c,activeAgentId:t,activeProjectId:r,...Zo(),...h??{},contextStateByKey:g}})):n(()=>({activeUserId:c,activeAgentId:t,activeProjectId:r,sourcesLoading:!0})),h){let m=h.loadedFolders??{},g=new Set;for(let[x,w]of Object.entries(m)){if(!w)continue;let y=Ve(x);y&&g.add(y)}for(let x of g)e().reconcileSourceFolders({agentId:t,projectId:r,source:x})}e().rehydrateActiveTab();let p=(async()=>{let m;try{m=await $o(t,r??void 0,{sources_only:!0,recursive:!1,...s?{include_counts:!0}:{}})}catch{n(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let g=Array.isArray(m.folders)?m.folders:[],x=Array.isArray(m.files)?m.files:[],w=Array.isArray(m.sources)?m.sources:[];n(y=>{let C=y.activeAgentId===t&&y.activeProjectId===r,k=C?{...y.files}:{},v=Date.now();k[l]||(k[l]={storeKey:l,name:"brain",uri:l,type:"folder",lastUpdated:v,presence:"brain"});for(let N of g){let M=typeof N=="string"?N:typeof N?.uri=="string"?N.uri:"";if(!M)continue;let U=typeof N?.name=="string"?N.name:M.split("/").pop()||"folder",I=N?.presence??(Ve(M)==="brain"?"brain":"stale_indexed");eo(k,`${M}/placeholder`,v),k[M]={storeKey:M,name:U,uri:M,type:"folder",parentUri:M.endsWith("://")?void 0:ot(M),lastUpdated:v,presence:I,git:typeof N.git=="string"?String(N.git):void 0}}for(let N of x){let M=typeof N?.uri=="string"?String(N.uri):"";if(!M)continue;let U=typeof N?.id=="string"?String(N.id):void 0,I=typeof N.status=="string"?String(N.status):void 0,A=Array.isArray(N.tags)&&N.tags.length>0?N.tags:void 0,G=typeof N.category=="string"?String(N.category):void 0,V=N.version&&typeof N.version=="object"?N.version:void 0,K=typeof N.agent_id=="string"?String(N.agent_id):void 0,L=typeof N.project_id=="string"?String(N.project_id):void 0,R=N?.presence??(Ve(M)==="brain"?"brain":"stale_indexed"),z=typeof N.git=="string"?String(N.git):void 0;eo(k,M,v),k[M]={storeKey:M,id:U,name:String(N.filename||N.name||yt(M)),uri:M,os_uri:typeof N.os_uri=="string"?String(N.os_uri):void 0,type:"file",status:I,parentUri:ot(M),lastUpdated:v,category:G,tags:A,metadata:N.metadata&&typeof N.metadata=="object"?N.metadata:void 0,createdAt:typeof N.createdAt=="string"?String(N.createdAt):void 0,updatedAt:typeof N.updatedAt=="string"?String(N.updatedAt):void 0,version:V,sourceAgentId:K,sourceProjectId:L,presence:R,git:z};let J=ot(M),Q=k[J];Q&&Q.type==="folder"&&(k[J]={...Q,sourceAgentId:K??Q.sourceAgentId,sourceProjectId:L??Q.sourceProjectId,lastUpdated:v})}let b=C?{...y.loadedFolders||{}}:{},P=C?{...y.hydrationState||{}}:{};for(let N of w)!b[N.uri_root]&&!P[N.uri_root]&&(P[N.uri_root]="idle");return{files:k,sources:w,sourcesLoading:!1,snapshotError:void 0,loadedFolders:b,hydrationState:P}})})();nh.set(o,p);try{await p}finally{nh.delete(o)}},async refresh({agentId:t,projectId:r,withCounts:a}){await e().loadList({agentId:t,projectId:r,withCounts:a})}}}var ah=0,sh=0,Lx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function oh(n,e){let t=n??(typeof e=="string"?e:"");return t?t.includes("://")?Ve(t):t:""}function Cx(n,e){return typeof n=="string"?n:typeof e=="string"?e:""}function Ix(n,e){return{setGitViewMode:t=>n(()=>({gitViewMode:t})),setGitDiffTarget:t=>n(()=>({gitDiffTarget:t})),setGitCommitTarget:t=>n(r=>({gitCommitTarget:t,...t===null&&r.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:t=>{if(!t)return;let r=oh(void 0,e().activeSource);t===r&&n(a=>({gitLogNonce:(typeof a.gitLogNonce=="number"?a.gitLogNonce:0)+1}))},clearGit:()=>n(t=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...t.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(t){n(()=>({gitOutgoingStat:t}))},async loadGitStatus({agentId:t,projectId:r,source:a,repo:s}){let o=oh(a,e().activeSource),i=Cx(s,e().activeRepoRel);if(!t||!o){n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let l=++ah;n(()=>({gitLoading:!0,gitError:void 0}));try{let u=await Qu({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==ah)return;n(()=>({gitStatus:u?.status??null,gitTotals:u?.totals??null,gitLoading:!1,gitError:void 0}))}catch(u){if(l!==ah)return;n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:u instanceof Error?u.message:"Git status failed"}))}},async loadGitBranches({agentId:t,projectId:r,source:a,repo:s}){let o=oh(a,e().activeSource),i=Cx(s,e().activeRepoRel);if(!t||!o){n(()=>({gitBranches:[]}));return}let l=++sh;try{let u=await _0({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==sh)return;n(()=>({gitBranches:Array.isArray(u?.branches)?u.branches:[]}))}catch(u){if(l!==sh)return;n(()=>({gitBranches:[],gitError:u instanceof Error?u.message:"Git branches failed"}))}}}}var ih=5e4,Fr=0,Ax=0,uc=new Set,cc=new Map,lh=new Map,F2=3,pc=new Map;function dh(n){let e=(pc.get(n)??0)+1;return pc.set(n,e),e}function Nx(n,e){return pc.get(n)===e}function uh(n){return{storeKey:n,uri:n,name:yt(n),type:"file",parentUri:ot(n)}}function Px(n,e,t){let r=ot(e);if(r===e||t.parentUri===r)return t;let a={...t,parentUri:r};return n[e]=a,a}function Rx(n,e,t,r){let a=r?.issuedAt??t,s=r?.pending;for(let o of e.folders||[]){let i=typeof o=="string"?o:typeof o?.uri=="string"?o.uri:"";if(!i)continue;let l=typeof o?.name=="string"?o.name:i.split("/").pop()||"folder",u=o?.presence??"unindexed",c=typeof o?.git=="string"?String(o.git):void 0,d=typeof o?.status=="string"?o.status:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:l,uri:i,type:"folder",parentUri:i.endsWith("://")?void 0:ot(i),lastUpdated:t,presence:u,git:c,status:d};continue}f=Px(n,i,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(n[i]={...f,name:l,presence:u,git:c,status:d})}for(let o of e.files||[]){let i=typeof o?.uri=="string"?String(o.uri):"";if(!i)continue;eo(n,i,t);let l=typeof o.git=="string"?String(o.git):void 0,u=typeof o.status=="string"?o.status:void 0,c=o.presence??"unindexed",d=typeof o.os_uri=="string"?o.os_uri:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:yt(i),uri:i,type:"file",id:typeof o.id=="string"?o.id:void 0,os_uri:d,status:u,parentUri:ot(i),lastUpdated:t,category:typeof o.category=="string"?o.category:void 0,presence:c,pinned:o.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(i);continue}if(f=Px(n,i,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:yt(i)||f.name,presence:c,status:u,os_uri:d,git:l};typeof o.id=="string"&&(h.id=o.id),"category"in o&&(h.category=typeof o.category=="string"?o.category:void 0),"version"in o&&(h.version=o.version),"pinned"in o&&(h.pinned=o.pinned===!0),n[i]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(i):f.status==="pending_review"&&s.remove.add(i))}}function fh(n,e,t){if(t.add.size===0&&t.remove.size===0)return n;let r=new Set(e);for(let a of t.add)r.add(a);for(let a of t.remove)r.delete(a);return n.pendingReviewPaths=r,n}var E2=4;function B2(n,e){if(n.endsWith("://"))return!0;if(!e.has(n))return!1;for(let t of ga(n))if(!t.endsWith("://")&&!e.has(t))return!1;return!0}function Mx(n,e){return e.some(t=>n===t||n.startsWith(t.endsWith("://")?t:`${t}/`))}function Tx(n,e){let t=n;for(let[r,a]of Object.entries(n))a!==!0||!Mx(r,e)||(t===n&&(t={...n}),t[r]=!1);return t}function dc(n,e){let t=new Set(e),r=Array.from(n.expandedFolders).filter(l=>!t.has(l));r.push(...t);let{kept:a,evicted:s}=ic(r);if(s.length===0)return{expandedFolders:new Set(a)};let o=n.loadedFolders||{},i=Tx(o,s);return i===o?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:i}}async function O2(n,e,t){if(n.length===0)return[];let r=Math.max(1,Math.min(e,n.length)),a=new Array(n.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let o=s++;if(o>=n.length)return;a[o]=await t(n[o])}})),a}async function _2(n,e){let{agentId:t,projectId:r,source:a,extraTargets:s,wide:o}=e,i=Fr,l=n.get(),u=l.loadedFolders||{},c=new Set;if(o)for(let p of Object.keys(u))Ve(p)===a&&B2(p,l.expandedFolders)&&c.add(p);for(let p of s)Ve(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let m=p.indexOf("://"),g=(m>=0?p.slice(m+3):p).replace(/\/+$/,"");return g?g.split("/").length:0},f=Array.from(c).sort((p,m)=>d(m)-d(p));if(f.length===0)return;let h=await O2(f,E2,async p=>{let m=dh(p),g=Date.now();try{let x=await $o(t,r??void 0,{uri:p,recursive:!1});return Nx(p,m)?{folderKey:p,res:x,issuedAt:g,ok:!0}:{folderKey:p,res:null,issuedAt:g,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:g,ok:!1}}});n.set(p=>{if(i!==Fr)return p;let m={...p.files},g=Date.now(),x={add:new Set,remove:new Set},w=[],y=!1,C=!1;for(let M of h){if(!M.ok||!M.res){C=!0;continue}Rx(m,M.res,g,{issuedAt:M.issuedAt,pending:x}),M.res.truncated?C=!0:y=!0}let k=C===!!p.dirtySources[a]?p.dirtySources:(()=>{let M={...p.dirtySources};return C?M[a]=!0:delete M[a],M})(),v=p.loadedFolders;for(let M of h)!M.ok||!M.res||v?.[M.folderKey]!==!1||(v===p.loadedFolders&&(v={...v}),v[M.folderKey]=!0);if(!y)return fh({files:hh(m,p.expandedFolders,p.openFiles),dirtySources:k,loadedFolders:v},p.pendingReviewPaths,x);let b=new Map;for(let M of Object.keys(m)){let U=m[M]?.parentUri;if(!U)continue;let I=b.get(U);I?I.push(M):b.set(U,[M])}for(let M of h){if(!M.ok||!M.res)continue;let U=M.res;if(U.truncated)continue;let I=new Set;for(let A of U.files||[]){let G=typeof A?.uri=="string"?A.uri:"";G&&I.add(G)}for(let A of U.folders||[]){let G=typeof A=="string"?A:typeof A?.uri=="string"?A.uri:"";G&&I.add(G)}for(let A of b.get(M.folderKey)||[]){let G=m[A];if(G&&!I.has(A)&&!((G.lastUpdated??0)>=M.issuedAt)){if(G.type==="folder"){let K=(b.get(A)||[]).filter(R=>m[R]!==void 0);if(K.filter(R=>m[R].status!=="deleted").length>0)continue;K.length===0?delete m[A]:G.status!=="deleted"&&(m[A]={...G,status:"deleted",lastUpdated:g});continue}G.presence==="unindexed"?(delete m[A],w.push(A),G.status==="pending_review"&&x.remove.add(A)):G.status!=="deleted"&&(m[A]={...G,status:"deleted",lastUpdated:g},G.status==="pending_review"&&x.remove.add(A))}}}let N={files:hh(m,p.expandedFolders,p.openFiles),dirtySources:k,loadedFolders:v};if(w.length){let M=new Set(w),U=p.openFiles.filter(L=>!M.has(L));N.openFiles=U;let I={...p.tabMeta};for(let L of w)delete I[L];N.tabMeta=I,N.activeFile=p.activeFile&&M.has(p.activeFile)?U.length?U[U.length-1]:null:p.activeFile;let A={...p.fileContentByPath},G={...p.fileBaseContentByPath},V={...p.fileErrorByPath},K={...p.filePrevByPath};for(let L of w)delete A[L],delete G[L],delete V[L],delete K[L];N.fileContentByPath=A,N.fileBaseContentByPath=G,N.fileErrorByPath=V,N.filePrevByPath=K}return fh(N,p.pendingReviewPaths,x)})}async function fc(n,e){let{agentId:t,projectId:r,source:a,targets:s}=e,o=e.wide!==!1;if(!t||!a)return;let i=lh.get(a);if(i){if(i.rerun=!0,o&&(i.wide=!0),s)for(let u of s)i.extra.add(u);await i.promise;return}let l={rerun:!1,wide:o,extra:new Set(s??[]),promise:Promise.resolve()};lh.set(a,l),l.promise=(async()=>{try{for(let u=0;u<F2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await _2(n,{agentId:t,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{lh.delete(a)}})(),await l.promise}function hc(n,e){let t=`${e}/`,r=Object.keys(n.get().files).filter(a=>a===e||a.startsWith(t));r.length!==0&&n.set(a=>{let s={...a.files};for(let h of r)delete s[h];let o=new Set(r),i=a.openFiles.filter(h=>!o.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:i,activeFile:a.activeFile&&o.has(a.activeFile)?i.length?i[i.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var H2=30;function hh(n,e,t){let r=Object.keys(n);if(r.length<=ih)return n;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=ot(c);if(!d||d===c)break;c=d}}for(let u of t){a.add(u);let c=ot(u);for(;c;){a.add(c);let d=ot(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=n[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:n[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),o=r.length-ih;if(o<=0||s.length===0)return n;let i={...n},l=Math.min(o,s.length);for(let u=0;u<l;u++)delete i[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:ih,removed:l,protected:r.length-s.length}),i}var U2="filesystem",ul=120,ch=240,Dx="neuralis.filesystem.sidebarWidth";function G2(){if(typeof window>"u")return ch;try{let n=window.localStorage.getItem(Dx),e=n?Number(n):NaN;return Number.isFinite(e)&&e>=ul?e:ch}catch{return ch}}var B=R0()(M0((n,e)=>({files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:null,contextStateByKey:{},previewEditorsEnabled:!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:G2(),sidebarView:"tree",activeAgentId:null,activeProjectId:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,diffViewMode:"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,...vx,...kx(n,e),...Sx(n,e),...Lx,...Ix(n,e),toggleSidebar:()=>n(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarView:t=>n(()=>({sidebarView:t})),setSidebarWidth:t=>n(()=>{let r=Math.max(ul,Math.round(t));if(typeof window<"u")try{window.localStorage.setItem(Dx,String(r))}catch{}return{sidebarWidth:r}}),setActiveFolderPath:t=>n(()=>({activeFolderPath:t?String(t):null})),setActiveSource:(t,r)=>n(()=>({activeSource:t,activeRepoRel:typeof r=="string"?r:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(t,r)=>n(a=>{let s={upload:!1,sources:!1,packages:!1,pending:!1};r?s[t]=!0:(s.upload=a.workspacePanels.upload,s.sources=a.workspacePanels.sources,s.packages=a.workspacePanels.packages,s.pending=a.workspacePanels.pending,s[t]=!1);let o=r?t:a.activeWorkspaceTab===t?"file":a.activeWorkspaceTab;return{workspacePanels:s,activeWorkspaceTab:o}}),setPendingSourceSuggestion:t=>n(()=>({pendingSourceSuggestion:t})),setActiveWorkspaceTab:t=>n(()=>({activeWorkspaceTab:t})),setDiffViewMode:t=>n(()=>({diffViewMode:t})),setPreviewEditorsEnabled:t=>n(()=>({previewEditorsEnabled:t})),reorderOpenFiles:(t,r)=>n(a=>{if(t===r)return a;let s=[...a.openFiles],o=s.indexOf(t),i=s.indexOf(r);if(o<0||i<0)return a;let[l]=s.splice(o,1);return s.splice(i,0,l),{openFiles:s}}),toggleTabPin:t=>n(r=>{let a=r.tabMeta[t]||{};return{tabMeta:{...r.tabMeta,[t]:{...a,pinned:!a.pinned,preview:!1}}}}),promoteTab:t=>n(r=>{let a=r.tabMeta[t];return!a||!a.preview?r:{tabMeta:{...r.tabMeta,[t]:{...a,preview:!1}}}}),closeAllFiles:()=>n(t=>{let r=t.openFiles.filter(s=>t.tabMeta[s]?.pinned),a=t.activeFile&&r.includes(t.activeFile)?t.activeFile:r[r.length-1]??null;return{openFiles:r,activeFile:a}}),closeSavedFiles:()=>n(t=>{let r=o=>{let i=t.fileBaseContentByPath[o],l=t.fileContentByPath[o];return typeof i=="string"&&i!==l},a=t.openFiles.filter(o=>t.tabMeta[o]?.pinned||r(o)||t.files[o]?.status==="pending_review"),s=t.activeFile&&a.includes(t.activeFile)?t.activeFile:a[a.length-1]??null;return{openFiles:a,activeFile:s}}),closeOtherFiles:t=>n(r=>{let a=r.openFiles.filter(s=>s===t||r.tabMeta[s]?.pinned);return{openFiles:a,activeFile:a.includes(t)?t:a[a.length-1]??null}}),setPendingPanelFilter:t=>n(()=>({pendingPanelFilter:t})),toggleFolder:t=>n(r=>{if(r.expandedFolders.has(t)){let o=new Set(Array.from(r.expandedFolders).filter(u=>!Mx(u,[t]))),i=r.loadedFolders||{},l=Tx(i,[t]);return l===i?{expandedFolders:o}:{expandedFolders:o,loadedFolders:l}}let a=!!r.folderBadges[t],s=a?{...r.folderBadges}:r.folderBadges;return a&&delete s[t],{...dc(r,[t]),folderBadges:s}}),async ensureFolderLoaded({agentId:t,projectId:r,uri:a,force:s}){if(!t||!a)return;let o=e().loadedFolders?.[a];if(!s&&o)return;if(!s&&o===!1){await fc({get:e,set:n},{agentId:t,projectId:r,source:Ve(a),targets:[a],wide:!1});return}let i=cc.get(a);if(i){await i;return}n(u=>({hydrationState:{...u.hydrationState||{},[a]:"loading"}}));let l=(async()=>{let u=dh(a),c=Date.now();try{let d=await $o(t,r??void 0,{uri:a,recursive:!1});if(!Nx(a,u)){n(f=>({hydrationState:{...f.hydrationState||{},[a]:f.loadedFolders?.[a]?"ready":"idle"}}));return}n(f=>{let h={...f.files},p={add:new Set,remove:new Set};return Rx(h,d,Date.now(),{issuedAt:c,pending:p}),fh({files:hh(h,f.expandedFolders,f.openFiles),loadedFolders:{...f.loadedFolders||{},[a]:!0},hydrationState:{...f.hydrationState||{},[a]:"ready"}},f.pendingReviewPaths,p)})}catch(d){console.error("[Filesystem] subfolder load failed",d),n(f=>({hydrationState:{...f.hydrationState||{},[a]:"error"}}))}})();cc.set(a,l);try{await l}finally{cc.delete(a)}},clearOrganizeError:()=>n(()=>({organizeError:null})),clearSnapshotError:()=>n(()=>({snapshotError:void 0})),setSourceDirty:(t,r)=>n(a=>{if(!!a.dirtySources[t]===r)return a;let o={...a.dirtySources};return r?o[t]=!0:delete o[t],{dirtySources:o}}),async reconcileSourceFolders({agentId:t,projectId:r,source:a}){await fc({get:e,set:n},{agentId:t,projectId:r,source:a})},fenceInFlightWriters(){Fr+=1;for(let t of Array.from(pc.keys()))dh(t);cc.clear(),uc.clear()},resetClientState(t){let r=e();if(!r.activeProjectId||t.projectId!==r.activeProjectId||t.level!=="project"&&t.agentId!==r.activeAgentId||t.level==="widget"&&t.widgetType!==U2)return;e().fenceInFlightWriters();let a=`${r.activeUserId??""}::${r.activeProjectId}::`,s=fs(r.activeUserId,r.activeProjectId,r.activeAgentId??""),o={};for(let[i,l]of Object.entries(r.contextStateByKey))(t.level==="project"?i.startsWith(a):i===s)||(o[i]=l);n(()=>({...Zo(),contextStateByKey:o}))},async reconcileFolders({agentId:t,projectId:r,folders:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Map,o=e().loadedFolders||{};for(let i of a){if(!i)continue;let l=Ve(i);if(!l||o[i]===!1)continue;if(!o[i]){e().setSourceDirty(l,!0);continue}let u=s.get(l);u?u.push(i):s.set(l,[i])}s.size!==0&&await Promise.all(Array.from(s.entries()).map(([i,l])=>fc({get:e,set:n},{agentId:t,projectId:r,source:i,targets:l})))},async refreshTree({agentId:t,projectId:r}){if(!t)return;await e().loadList({agentId:t,projectId:r});let a=e(),s=new Set;for(let[o,i]of Object.entries(a.loadedFolders||{})){if(!i)continue;let l=Ve(o);l&&s.add(l)}await Promise.all(Array.from(s).map(o=>fc({get:e,set:n},{agentId:t,projectId:r,source:o})))},setActiveFile:t=>{n({activeFile:t,activeWorkspaceTab:"file"}),e().rehydrateActiveTab()},async rehydrateActiveTab(){let t=e(),r=t.activeFile,a=t.activeAgentId;if(!(!r||!a)&&!oc(t,r)&&!uc.has(r)){uc.add(r);try{let s=t.tabMeta[r]?.sourceAgentId,o=s&&s!==a&&!/^__.*__$/.test(s)?s:void 0;await t.openFile({agentId:a,projectId:t.activeProjectId,uri:r,readAgentId:o,revealPane:!1})}finally{uc.delete(r)}}},closeFile:t=>n(r=>{let a=r.openFiles.filter(i=>i!==t),s=r.activeFile===t?a.length?a[a.length-1]:null:r.activeFile,o={...r.tabMeta};return delete o[t],{openFiles:a,activeFile:s,tabMeta:o}}),replaceFilePath:(t,r)=>n(a=>{if(!t||!r||t===r)return a;let s=a.files[t],o={...a.files};s&&(delete o[t],o[r]={...s,storeKey:r,uri:r,name:yt(r)||s.name,parentUri:ot(r),lastUpdated:Date.now()});let i={...a.fileContentByPath},l={...a.fileBaseContentByPath},u={...a.fileErrorByPath},c={...a.filePrevByPath};Object.prototype.hasOwnProperty.call(i,t)&&(i[r]=i[t],delete i[t]),Object.prototype.hasOwnProperty.call(l,t)&&(l[r]=l[t],delete l[t]),Object.prototype.hasOwnProperty.call(u,t)&&(u[r]=u[t],delete u[t]),Object.prototype.hasOwnProperty.call(c,t)&&(c[r]=c[t],delete c[t]);let d=[];for(let f of a.openFiles){let h=f===t?r:f;d.includes(h)||d.push(h)}return{files:o,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c,openFiles:d,activeFile:a.activeFile===t?r:a.activeFile}}),patchFileNode:(t,r)=>n(a=>{let s=a.files[t];return s?{files:{...a.files,[t]:{...s,...r,lastUpdated:Date.now()}}}:a}),clearFilePrev:t=>n(r=>{if(!r.filePrevByPath[t])return r;let a={...r.filePrevByPath};return delete a[t],{filePrevByPath:a}}),upsertFileNodeFromEvent:({id:t,uri:r,folder_ancestors:a,status:s,sourceAgentId:o,sourceProjectId:i})=>n(l=>{if(!r||!l.files[r]&&s==="deleted")return l;let u=Date.now(),c={...l.files},d=a||ga(r);eo(c,r,u);let f=ot(r),h=c[f];h&&h.type==="folder"&&(c[f]={...h,sourceAgentId:o??h.sourceAgentId,sourceProjectId:i??h.sourceProjectId});let p=c[r],m=Ve(r)==="brain";c[r]={...p||uh(r),id:t??p?.id,name:yt(r)||p?.name||"file",type:"file",uri:r,status:s??p?.status,parentUri:f,sourceAgentId:o??p?.sourceAgentId,sourceProjectId:i??p?.sourceProjectId,lastUpdated:u,presence:p?.presence??(m?"brain":"synced"),git:p?.git};let g=new Set(l.pendingReviewPaths);if(s==="pending_review"?g.add(r):p?.status==="pending_review"&&s&&s!=="pending_review"&&g.delete(r),s==="active"&&p?.status==="pending_review"&&l.filePrevByPath[r]){let w={...l.filePrevByPath};return delete w[r],{files:c,filePrevByPath:w,pendingReviewPaths:g}}return{files:c,pendingReviewPaths:g}}),removeFilePath:t=>n(r=>{if(!t||!r.files[t]&&!r.openFiles.includes(t)&&!r.tabMeta[t])return r;let a={...r.files};delete a[t];let s=r.openFiles.filter(f=>f!==t),o=r.activeFile===t?s.length?s[s.length-1]:null:r.activeFile,i={...r.fileContentByPath},l={...r.fileBaseContentByPath},u={...r.fileErrorByPath},c={...r.filePrevByPath};delete i[t],delete l[t],delete u[t],delete c[t];let d={...r.tabMeta};return delete d[t],{files:a,openFiles:s,activeFile:o,tabMeta:d,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c}}),incrementFolderBadges:t=>n(r=>{if(!Array.isArray(t)||t.length===0)return r;let a={...r.folderBadges};for(let s of t)s&&(r.expandedFolders.has(s)||(a[s]=(a[s]||0)+1));return{folderBadges:a}}),clearFolderBadge:t=>n(r=>{if(!t||!r.folderBadges[t])return r;let a={...r.folderBadges};return delete a[t],{folderBadges:a}}),autoExpandToFile:t=>n(r=>dc(r,[rr(t),...ga(t)])),updateFileContent:(t,r)=>n(a=>({fileContentByPath:{...a.fileContentByPath,[t]:r},fileErrorByPath:{...a.fileErrorByPath,[t]:void 0}})),async saveFileInPlace({agentId:t,projectId:r,readAgentId:a,node:s,targetUri:o,content:i,currentContent:l}){let u=s.uri,c=!!o&&o!==u,d=i!==l;if(!c&&!d)return{uri:u,moved:!1,contentChanged:!1};let f=Fr,h=()=>f!==Fr,p=u;if(c){let m=await yr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:u,move:o});if(!m||m.ok!==!0)throw new Error(ma(m,"Move failed"));if(p=o,h())return{uri:p,moved:c,contentChanged:!1};e().replaceFilePath(s.storeKey||u,o)}if(d){let m=await yr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:p,overwrite:{content:i}});if(!m||m.ok!==!0)throw new Error(ma(m,"Save failed"));if(h())return{uri:p,moved:c,contentChanged:d};let g=c?p:s.storeKey||u;e().updateFileContent(g,i),e().patchFileNode(g,{status:"pending_review"})}return await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(new Set([ot(u),ot(p)]))}),h()?{uri:p,moved:c,contentChanged:d}:(await e().openFile({agentId:t,projectId:r,uri:p,readAgentId:a,force:!0}),{uri:p,moved:c,contentChanged:d})},async refreshPendingCount({agentId:t,projectId:r}){if(!t)return;let a=++Ax,s;try{s=await tx({agentId:t,...r?{projectId:r}:{}})}catch{return}if(a!==Ax)return;let o=e();o.activeAgentId!==t||o.activeProjectId!==r||n(()=>({pendingCount:s}))},async markFileDeleted({agentId:t,projectId:r,node:a}){let s=Fr,o=await yr({agentId:t,...r?{projectId:r}:{},id:a.id,uri:a.uri,delete:!0});if(!o||o.ok!==!0)throw new Error(ma(o,"Delete failed"));s===Fr&&await e().reconcileFolders({agentId:t,projectId:r,folders:[ot(a.uri)]})},async moveFileToFolder({agentId:t,projectId:r,fromUri:a,toFolderUri:s,id:o}){if(!t||!a||!s)return;let i=yt(a);if(!i)return;let l=s.endsWith("://")?`${s}${i}`:`${s}/${i}`;if(l===a)return;let u=ot(a),c=e().files[a]?.type==="folder",d;try{d=await yr({agentId:t,...r?{projectId:r}:{},id:o,uri:a,move:l})}catch(h){console.error("[Filesystem] move failed",a,h),n(()=>({organizeError:"Move failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] move rejected",a,d.code,d.error),n(()=>({organizeError:ma(d,"Move rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]});return}let f=d?.warning==="moved_with_source_retained";f&&n(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),c?(f||hc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:s,force:!0})):(n(h=>{let p=h.openFiles.map(m=>m===a?l:m);return{activeFolderPath:s,openFiles:Array.from(new Set(p)),activeFile:h.activeFile===a?l:h.activeFile}}),f||e().replaceFilePath(a,l)),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]})},async renameNode({agentId:t,projectId:r,uri:a,id:s,newName:o}){let i=(o??"").trim();if(!t||!a||!i||i===yt(a))return;let l=ot(a),u=l.endsWith("://")?`${l}${i}`:`${l}/${i}`;if(u===a)return;let c=e().files[a]?.type==="folder",d;try{d=await yr({agentId:t,...r?{projectId:r}:{},id:s,uri:a,move:c?u:i})}catch(f){console.error("[Filesystem] rename failed",a,f),n(()=>({organizeError:"Rename failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] rename rejected",a,d.code,d.error),n(()=>({organizeError:ma(d,"Rename rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]});return}c?(hc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:l,force:!0})):e().replaceFilePath(a,u),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]})},async createNode({agentId:t,projectId:r,parentUri:a,name:s,kind:o}){let i=(s??"").trim();if(!t||!a||!i)return;let l=a.endsWith("://")?`${a}${i}`:`${a}/${i}`,u=Fr;try{if(o==="folder"){let c=await yr({agentId:t,...r?{projectId:r}:{},uri:l,mkdir:!0});c?.ok&&u===Fr?n(d=>({...dc(d,[a]),files:{...d.files,[l]:{storeKey:l,name:i,uri:l,type:"folder",parentUri:a,presence:"unindexed",lastUpdated:Date.now()}}})):c&&c.ok===!1&&(console.error("[Filesystem] create folder rejected",l,c.code,c.error),n(()=>({organizeError:ma(c,"Could not create folder")})))}else await rc({agentId:t,...r?{projectId:r}:{},file:new File([""],i),uri:a,tags:[]})}catch(c){console.error("[Filesystem] create failed",o,l,c),n(()=>({organizeError:`Could not create ${o==="folder"?"folder":"file"}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:[a]})},async pasteNodes({agentId:t,projectId:r,targetFolderUri:a,op:s,uris:o}){if(!t||!a||!Array.isArray(o)||o.length===0)return;let i=new Set([a]),l=[];for(let u of o){if(!u)continue;let c=yt(u);if(!c)continue;let d=a.endsWith("://")?`${a}${c}`:`${a}/${c}`;if(d!==u){i.add(ot(u));try{if(s==="copy"){let f=await yr({agentId:t,...r?{projectId:r}:{},uri:u,copy:d});f&&f.ok===!1&&l.push(c)}else{let f=await yr({agentId:t,...r?{projectId:r}:{},uri:u,move:d});f&&f.ok===!1?l.push(c):f?.warning==="moved_with_source_retained"?l.push(`${c} (original retained)`):e().files[u]?.type==="folder"&&hc({get:e,set:n},u)}}catch(f){console.error("[Filesystem] paste failed",s,u,f),l.push(c)}}}l.length&&n(()=>({organizeError:`${s==="copy"?"Copy":"Move"} incomplete: ${l.join(", ")}`})),await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(i)})},async deleteNodes({agentId:t,projectId:r,targets:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Set,o=[],i=null;for(let l of a){if(!l?.uri)continue;s.add(ot(l.uri));let u=e().files[l.uri]?.type==="folder";try{let c=await yr({agentId:t,...r?{projectId:r}:{},id:l.id,uri:l.uri,delete:!0});if(c&&c.ok===!1){console.error("[Filesystem] delete rejected",l.uri,c.code,c.error),o.push(yt(l.uri)||l.uri),(typeof c.affected=="number"||c.failed?.length)&&(i={affected:c.affected,failed:c.failed});continue}u?hc({get:e,set:n},l.uri):e().patchFileNode(l.uri,{status:"deleted"})}catch(c){console.error("[Filesystem] delete failed",l.uri,c),o.push(yt(l.uri)||l.uri)}}if(o.length){let l=i?.failed?.length?` \u2014 ${i.affected??0} removed, could not remove: ${i.failed.slice(0,5).join(", ")}${i.failed.length>5?"\u2026":""}`:"";n(()=>({organizeError:`Delete failed: ${o.join(", ")}${l}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(s)})},async openFile({agentId:t,projectId:r,uri:a,readAgentId:s,force:o,revealPane:i=!0}){if(!t||!a)return;n(d=>{let f=d.openFiles.includes(a),h=d.previewEditorsEnabled&&!f&&!d.tabMeta[a]?.pinned,p=d.openFiles,m=d.tabMeta;if(h){let x=d.openFiles.find(w=>w!==a&&d.tabMeta[w]?.preview&&!d.tabMeta[w]?.pinned);x&&(p=p.filter(w=>w!==x),m={...m},delete m[x]),m={...m,[a]:{...m[a]||{},preview:!0}}}let g=p.includes(a)?p:[...p,a];if(g.length>H2){let x=g.findIndex(w=>w!==a&&!d.tabMeta[w]?.pinned);x>=0&&(g=g.filter((w,y)=>y!==x))}return{openFiles:g,activeFile:a,activeAgentId:t,activeProjectId:r,...i?{activeWorkspaceTab:"file"}:{},tabMeta:m}}),e().autoExpandToFile(a);{let d=new Set([rr(a),...ga(a)]);for(let f of d)!f||f===a||e().ensureFolderLoaded({agentId:t,projectId:r,uri:f})}let l=e(),u=typeof l.fileBaseContentByPath[a]=="string"||typeof l.fileContentByPath[a]=="string"&&(l.fileContentByPath[a]?.length||0)>0;if(!o&&u)return;let c=Fr;try{let d=await Ko({agentId:s||t,...r?{projectId:r}:{},files:[a]});if(c!==Fr)return;let f=Yo(d);if(f.length>0){let h=f[0],p=Jo(h),m=typeof h.error=="string"?h.error:void 0,g=typeof h.code=="string"&&h.code==="not_found";if(m&&g){e().removeFilePath(a);return}let x=typeof h.status=="string"?String(h.status):void 0,w=typeof h.category=="string"?h.category:void 0,y=Array.isArray(h.tags)?h.tags:void 0,C=h.metadata&&typeof h.metadata=="object"?h.metadata:void 0,k=typeof h.createdAt=="string"?h.createdAt:void 0,v=typeof h.updatedAt=="string"?h.updatedAt:void 0,b=h.version&&typeof h.version=="object"?h.version:void 0,P=typeof h.readSource=="string"?h.readSource:void 0,N=typeof h.id=="string"?h.id:void 0,M=typeof h.uri=="string"?String(h.uri):a,U=typeof h.agent_id=="string"?String(h.agent_id):s||t,I=typeof h.project_id=="string"?String(h.project_id):r||void 0,A=Ve(M)==="brain",G=b?.sync?.status,V=sc(b?.baseline);n(K=>{let L=K.files[M],R=K.fileContentByPath[M],z=K.fileBaseContentByPath[M],J=m&&typeof R=="string"?R:p,Q=m&&typeof z=="string"?z:p,re={...K.files},pe=!!N||!!x||!!b,ee=A?"brain":L?.presence??(pe?"synced":P==="live"?"unindexed":"synced");eo(re,M,Date.now());let ce=K.openFiles.includes(M)?K.openFiles:K.openFiles.map(ue=>ue===a?M:ue);return{files:{...re,[M]:{...L||uh(M),id:N??L?.id,name:String(h.filename||L?.name||yt(M)),type:"file",uri:M,parentUri:ot(M),status:x??L?.status,sourceAgentId:U,sourceProjectId:I??L?.sourceProjectId,lastUpdated:L?.lastUpdated??Date.now(),category:w??L?.category,tags:y??L?.tags,metadata:C??L?.metadata,createdAt:k??L?.createdAt,updatedAt:v??L?.updatedAt,version:b??L?.version,presence:ee,readSource:P??L?.readSource}},fileContentByPath:{...K.fileContentByPath,[M]:J},fileBaseContentByPath:{...K.fileBaseContentByPath,[M]:Q},fileErrorByPath:{...K.fileErrorByPath,[M]:m},filePrevByPath:{...K.filePrevByPath,[M]:V},openFiles:Array.from(new Set(ce)),activeFile:M,tabMeta:{...K.tabMeta,[M]:{...K.tabMeta[M]||K.tabMeta[a]||{},name:String(h.filename||L?.name||yt(M)),status:x??L?.status,sourceAgentId:U}}}})}}catch(d){let f=d instanceof Error?d.message:"Read failed";if(console.error("[Filesystem] read failed",d),c!==Fr)return;n(h=>({files:{...h.files,[a]:{...h.files[a]||uh(a),sourceAgentId:s||t,sourceProjectId:r||void 0,lastUpdated:h.files[a]?.lastUpdated??Date.now()}},fileErrorByPath:{...h.fileErrorByPath,[a]:f}}))}},async applyNav({agentId:t,projectId:r,nav:a,readAgentId:s,force:o}){if(!t||!a||a.kind!=="filesystem")return;let i=String(a.action||""),l=a.uri;if((i==="read"||i==="open"||i==="modify"||i==="save")&&l){await e().openFile({agentId:t,projectId:r,uri:l,readAgentId:s,force:o});return}if(i==="open-pending"){n(()=>({activeAgentId:t,activeProjectId:r})),e().setPendingPanelFilter(a.filter??{}),e().setWorkspacePanelOpen("pending",!0);return}i==="list"&&l&&n(u=>{let c=rr(l),d=u.expandedFolders.has(l)&&u.expandedFolders.has(c),f=u.activeAgentId===t,h=u.activeProjectId===r;return d&&f&&h?u:{...dc(u,[c,l]),activeAgentId:t,activeProjectId:r}})},async upload({agentId:t,projectId:r,file:a,uri:s}){if(!t)return;let o=s||"brain://docs";n(()=>({uploading:!0}));try{await rc({agentId:t,...r?{projectId:r}:{},file:a,uri:o,tags:["upload"]}),await e().reconcileFolders({agentId:t,projectId:r,folders:[o]})}finally{n(()=>({uploading:!1}))}},async uploadMany({agentId:t,projectId:r,files:a,uri:s}){if(!t)return;let o=Array.isArray(a)?a.filter(Boolean):[];if(o.length===0)return;let i=s||"brain://docs";n(()=>({uploading:!0}));try{for(let l of o)await rc({agentId:t,...r?{projectId:r}:{},file:l,uri:i,tags:["upload"]});await e().reconcileFolders({agentId:t,projectId:r,folders:[i]})}finally{n(()=>({uploading:!1}))}}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(n,e)=>{if(e>=2)return n;let t=n??{},r=t.activeAgentId?fs(null,t.activeProjectId??null,t.activeAgentId):null;return{previewEditorsEnabled:t.previewEditorsEnabled??!1,diffViewMode:t.diffViewMode??"auto",activeUserId:null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,contexts:r?{[r]:lc({...Zo(),openFiles:t.openFiles??[],activeFile:t.activeFile??null,tabMeta:t.tabMeta??{}})}:{}}},merge:(n,e)=>{let t=n;if(!t)return e;let r=t.contexts??{},a=t.activeAgentId?fs(t.activeUserId??null,t.activeProjectId??null,t.activeAgentId):null,s={};for(let[i,l]of Object.entries(r))i!==a&&(s[i]=rh(l));let o=a&&r[a]?rh(r[a]):{};return{...e,previewEditorsEnabled:t.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:t.diffViewMode??e.diffViewMode,activeUserId:t.activeUserId??null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,...o,contextStateByKey:s}},storage:Xf(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:n=>{let e={};for(let[t,r]of Object.entries(n.contextStateByKey))e[t]=lc(r);return n.activeAgentId&&(e[fs(n.activeUserId,n.activeProjectId,n.activeAgentId)]=lc(n)),{previewEditorsEnabled:n.previewEditorsEnabled,diffViewMode:n.diffViewMode,activeUserId:n.activeUserId,activeAgentId:n.activeAgentId,activeProjectId:n.activeProjectId,contexts:e}}}));var zl=W(mr(),1);var mc=W($e(),1);var Fx=n=>n?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Ex(n,e,t=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Fx(n),size:24,node:e,...t.length>0?{aliases:t}:{}}}var Bx=n=>{let e="",t=!1;for(let r of n){if(r==="-"||r==="_"||r<=" "){t=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=t?r.toUpperCase():r,t=!1}return e};var Ox=n=>{let e=Bx(n);return e.charAt(0).toUpperCase()+e.slice(1)};var dl=W($e(),1);var cl=(...n)=>n.filter((e,t,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===t).join(" ").trim();var hs={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function ph(n){return n!=null}function _x(n,e={}){let t=e.attributeNames??{},r=f=>t[f]??f,a=n.size??n.width??hs.width,s=n.size??n.height??hs.height,o=n.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],i=[...n.name?[`lucide-${n.name}`]:[],...o],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?cl(...l):cl("lucide",...i,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??hs["stroke-width"])*Number(n.size??n.width??hs.width)/Number(e.size??e.width??hs.width):e.strokeWidth??hs["stroke-width"];return["svg",{...Object.entries(hs).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&ph(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&ph(e.width)&&{[r("width")]:e.width},..."height"in e&&ph(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},n.node.map(f=>{let[h,p,m]=f,g=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return m?[h,g,m]:[h,g]})]}function Hx(n,e={}){return _x(n,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var Ux=n=>{for(let e in n)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var Qo=W($e(),1);var z2=(0,Qo.createContext)({});var Gx=()=>(0,Qo.useContext)(z2);var zx=(0,dl.forwardRef)(({color:n,size:e,width:t,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:o,className:i="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:m=!1,nonScalingStroke:g=!1,color:x="currentColor",className:w=""}=Gx()??{},y=!!l||Ux(d),[C,k,v=[]]=Hx(c,{color:n??x,width:t??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??m,nonScalingStroke:o??g,className:cl(w,i),hasA11yProp:y,attributes:d});return(0,dl.createElement)(C,{ref:f,...k},[...v.map(([b,P])=>(0,dl.createElement)(b,P)),...Array.isArray(l)?l:[l]])});function H(n,e=[],t=[]){let r=typeof n=="string"?Ex(n,e,t):n,a=(0,mc.forwardRef)(({className:s,...o},i)=>(0,mc.createElement)(zx,{ref:i,icon:r,className:s,...o}));return r.name&&(a.displayName=Ox(r.name)),a}var Wx={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};Wx.node;var ei=H(Wx);var jx={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};jx.node;var fl=H(jx);var qx={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};qx.node;var ti=H(qx);var Vx={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};Vx.node;var hl=H(Vx);var $x={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};$x.node;var pl=H($x);var Kx={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};Kx.node;var ml=H(Kx);var Xx={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};Xx.node;var xa=H(Xx);var Yx={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};Yx.node;var ps=H(Yx);var Jx={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Jx.node;var Dn=H(Jx);var Zx={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};Zx.node;var Tt=H(Zx);var Qx={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};Qx.node;var gl=H(Qx);var ey={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};ey.node;var un=H(ey);var ty={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};ty.node;var ja=H(ty);var ny={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};ny.node;var ms=H(ny);var ry={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};ry.node;var ea=H(ry);var ay={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};ay.node;var ta=H(ay);var sy={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};sy.node;var na=H(sy);var oy={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};oy.node;var xl=H(oy);var iy={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};iy.node;var ya=H(iy);var ly={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};ly.node;var yl=H(ly);var uy={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};uy.node;var Er=H(uy);var cy={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};cy.node;var gs=H(cy);var dy={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};dy.node;var ra=H(dy);var fy={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};fy.node;var bl=H(fy);var hy={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};hy.node;var br=H(hy);var py={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};py.node;var xs=H(py);var my={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};my.node;var wl=H(my);var gy={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};gy.node;var vl=H(gy);var xy={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};xy.node;var qa=H(xy);var yy={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};yy.node;var Va=H(yy);var by={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};by.node;var ys=H(by);var wy={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};wy.node;var kl=H(wy);var vy={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};vy.node;var bs=H(vy);var ky={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};ky.node;var ws=H(ky);var Sy={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Sy.node;var vs=H(Sy);var Cy={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Cy.node;var ks=H(Cy);var Ly={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ly.node;var ba=H(Ly);var Iy={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Iy.node;var Sl=H(Iy);var Ay={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]};Ay.node;var Ss=H(Ay);var Py={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Py.node;var wr=H(Py);var Ny={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};Ny.node;var Cl=H(Ny);var Ry={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ry.node;var Br=H(Ry);var My={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};My.node;var Ln=H(My);var Ty={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Ty.node;var Or=H(Ty);var Dy={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};Dy.node;var ar=H(Dy);var Fy={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};Fy.node;var ni=H(Fy);var Ey={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};Ey.node;var Gn=H(Ey);var By={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};By.node;var Ll=H(By);var Oy={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Oy.node;var Il=H(Oy);var _y={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};_y.node;var Al=H(_y);var Hy={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Hy.node;var to=H(Hy);var Uy={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Uy.node;var ze=H(Uy);var Gy={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};Gy.node;var no=H(Gy);var zy={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};zy.node;var ro=H(zy);var Wy={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};Wy.node;var Pl=H(Wy);var jy={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};jy.node;var Nl=H(jy);var qy={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};qy.node;var Rl=H(qy);var Vy={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};Vy.node;var Ml=H(Vy);var $y={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};$y.node;var vr=H($y);var Ky={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};Ky.node;var Cs=H(Ky);var Xy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};Xy.node;var Ls=H(Xy);var Yy={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};Yy.node;var ao=H(Yy);var Jy={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};Jy.node;var so=H(Jy);var Zy={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};Zy.node;var Tl=H(Zy);var Qy={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};Qy.node;var Fn=H(Qy);var eb={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};eb.node;var $a=H(eb);var tb={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};tb.node;var wa=H(tb);var nb={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};nb.node;var Ht=H(nb);var rb={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};rb.node;var oo=H(rb);var ab={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};ab.node;var io=H(ab);var sb={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};sb.node;var Ka=H(sb);var ob={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};ob.node;var Dl=H(ob);var ib={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};ib.node;var Fl=H(ib);var lb={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};lb.node;var ri=H(lb);var ub={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};ub.node;var va=H(ub);var cb={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};cb.node;var ai=H(cb);var db={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};db.node;var El=H(db);var fb={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};fb.node;var Is=H(fb);var hb={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};hb.node;var Bl=H(hb);var pb={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};pb.node;var lo=H(pb);var mb={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};mb.node;var Ol=H(mb);var gb={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};gb.node;var _l=H(gb);var xb={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};xb.node;var si=H(xb);var yb={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};yb.node;var As=H(yb);var bb={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};bb.node;var It=H(bb);var wb={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};wb.node;var dt=H(wb);var vb={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};vb.node;var ka=H(vb);var kb={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};kb.node;var Hl=H(kb);var Sb={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Sb.node;var Ul=H(Sb);var Cb={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Cb.node;var Sa=H(Cb);var Lb={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Lb.node;var Ps=H(Lb);var Ib={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Ib.node;var uo=H(Ib);var Ab={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};Ab.node;var Ut=H(Ab);var Pb={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Pb.node;var Gl=H(Pb);var Jt=W(le(),1);function gh(n){let{agentId:e,agentName:t,agentIcon:r,agentAccent:a,supportsSources:s=!0}=n,o=(0,zl.resolveAgentIcon)(r),i=B(g=>g.toggleSidebar),l=B(g=>g.sidebarOpen),u=B(g=>g.refreshTree),c=B(g=>g.activeProjectId),d=B(g=>g.uploading),f=B(g=>g.workspacePanels),h=B(g=>g.setWorkspacePanelOpen),p=B(g=>g.activeWorkspaceTab),m=B(g=>g.pendingCount);return(0,Jt.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Jt.jsx)("div",{className:"flex items-center gap-1",children:(0,Jt.jsx)("button",{onClick:i,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,Jt.jsx)(Cs,{className:"w-4 h-4"})})}),(0,Jt.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,Jt.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:t||"Agent","aria-label":t||"Agent",children:(0,Jt.jsx)(o,{className:"h-4 w-4"})}),(0,Jt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,Jt.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,Jt.jsx)(Ht,{className:"w-4 h-4"})}),(0,Jt.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,Jt.jsx)(ze,{className:"w-4 h-4 animate-spin"}):(0,Jt.jsx)(Sa,{className:"w-4 h-4"})}),s?(0,Jt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,Jt.jsx)(br,{className:"w-4 h-4"})}):null,s?(0,Jt.jsx)(zl.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,Jt.jsx)(zl.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh","scripts/search.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,Jt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,Jt.jsx)(vr,{className:"w-4 h-4"})}),(0,Jt.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:m>0?`Pending changes \u2014 ${m} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,Jt.jsx)(Va,{className:"w-4 h-4"}),m>0?(0,Jt.jsx)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:m>=1e3?"1000+":m}):null]})]})]})}var _e=W($e(),1),M1=W(mr(),1);function Xa(n,e){let t=n.grantedFeatures;return t?t.includes("*")||t.includes(e):!1}function oi(n,e){let t=e?.features;return!t||t.length===0?!0:t.every(r=>Xa(n,r))}var xh={owner:1,admin:2,manager:10,member:20,viewer:30};var W2=xh.member,Mb=Number.MAX_SAFE_INTEGER;var aa=W($e(),1),Wb=W(Ya(),1);function Eb(n){return typeof n=="object"?n.key:n}function Bb(n,e){let t=n.length;return new Proxy(n,{get(r,a,s){if(typeof a=="string"){let o=a.charCodeAt(0);if(o>=48&&o<=57){let i=+a;if(Number.isInteger(i)&&i>=0&&i<t){let l=r[i];if(typeof l!="object"){let u=e[i*2];l=r[i]={index:i,key:l,start:u,size:e[i*2+1],end:u+e[i*2+1],lane:0}}return l}}if(a==="length")return t}return Reflect.get(r,a,s)}})}function co(n,e,t){let r=t.initialDeps??[],a,s=!0;function o(){var i;let u=0,c=n();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),t?.onChange&&!(s&&t.skipInitialOnChange)&&t.onChange(a),s=!1,a}return o.updateDeps=i=>{r=i},o}function bh(n,e){if(n===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return n}var wh=(n,e)=>Math.abs(n-e)<1.01,Ob=(n,e,t)=>{let r;return Object.assign(function(...a){n.clearTimeout(r),r=n.setTimeout(()=>e.apply(this,a),t)},{cancel:()=>{n.clearTimeout(r)}})};var Wl,vh=()=>{if(Wl!==void 0)return Wl;if(typeof navigator>"u")return Wl=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return Wl=!0;let n=navigator.maxTouchPoints;return Wl=navigator.platform==="MacIntel"&&n!==void 0&&n>0};var _b=n=>{let{offsetWidth:e,offsetHeight:t}=n;return{width:e,height:t}},Y2=n=>n,J2=n=>{let e=Math.max(n.startIndex-n.overscan,0),r=Math.min(n.endIndex+n.overscan,n.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Hb=(n,e)=>{let t=n.scrollElement;if(!t)return;let r=n.targetWindow;if(!r)return;let a=o=>{let{width:i,height:l}=o;e({width:Math.round(i),height:Math.round(l)})};if(a(_b(t)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(o=>{let i=()=>{let l=o[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(_b(t))};n.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()});return s.observe(t,{box:"border-box"}),()=>{s.unobserve(t)}},gc={passive:!0};var Z2=typeof window>"u"?!0:"onscrollend"in window,Q2=(n,e,t)=>{let r=n.scrollElement;if(!r)return;let a=n.targetWindow;if(!a)return;let s=n.options.useScrollendEvent&&Z2,o=0,i=s?null:Ob(a,()=>e(t(r),!1),n.options.isScrollingResetDelay),l=d=>()=>{o=t(r),i?.(),e(o,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,gc),s&&r.addEventListener("scrollend",c,gc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),i?.cancel()}},Ub=(n,e)=>Q2(n,e,t=>{let{horizontal:r,isRtl:a}=n.options;return r?t.scrollLeft*(a&&-1||1):t.scrollTop});var eA=(n,e,t)=>{if(t.options.useCachedMeasurements){let r=t.indexFromElement(n),a=t.options.getItemKey(r);return t.itemSizeCache.get(a)??t.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[t.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=t.indexFromElement(n),a=t.options.getItemKey(r),s=t.itemSizeCache.get(a);if(s!==void 0)return s}return n[t.options.horizontal?"offsetWidth":"offsetHeight"]},tA=(n,{adjustments:e=0,behavior:t},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:n+e,behavior:t})};var Gb=tA;function nA(n,e,t,r){if(e===0)return!1;let a=r(0),s=new Set,o=0;for(;o<n;){let l=t(o);if(l===a)break;s.add(l),o++}let i=n-o;if(i===0||i>=e)return!1;for(let l=0;l<i;l++)if(r(l)!==t(o+l))return!1;for(let l=i;l<e;l++)if(s.has(r(l)))return!1;return!0}var xc=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var t,r,a;return((a=(r=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let t=null,r=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let o=()=>{let i=s.target,l=this.indexFromElement(i);if(!i.isConnected){this.observer.unobserve(i);for(let[u,c]of this.elementsCache)if(c===i){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(i,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),t=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=t=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Y2,rangeExtractor:J2,onChange:()=>{},measureElement:eA,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(let d in t){let f=t[d];f!==void 0&&(a[d]=f)}let s=this.options,o=null,i=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,m=C=>Eb(p[C]),g=d>0?m(0):null,x=d>0?m(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==g||a.getItemKey(f-1)!==x)){l=!0;let C=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;C&&(o=[C.key,this.getScrollOffset()-C.start]);let k=a.followOnAppend===!0?"auto":a.followOnAppend||null;k&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||nA(d,f,m,a.getItemKey))&&(i=k)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(o&&this.scrollOffset!==null){let[d,f]=o,h=this.getMeasurements(),{count:p,getItemKey:m}=this.options,g=0;for(;g<p&&m(g)!==d;)g++;if(g<p){let x=h[g];if(x){let w=Math.max(0,x.start+f);!i&&w!==this.scrollOffset&&(c=w-this.scrollOffset,this.scrollOffset=w,u=!0)}}}(u||i)&&(this.pendingScrollAnchor=[u?o[0]:null,u?o[1]:0,i,c])},this.notify=t=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,t)},this.maybeNotify=co(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(o-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!vh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,gc),o.addEventListener("touchend",l,gc),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[o,i,l,u]=s;o!==null&&!l&&(vh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!wh(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:t,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=t>a+.5?{target:t,maxAtWrite:a}:null,this._scrollToOffset(t,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let t=this.getScrollOffset(),r=this.getMaxScrollOffset();if(t<0||t>r)return;if(this._iosDeferredAdjustment<0&&t>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=co(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(t,r,a,s,o,i,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==i&&(this.lanesChangedFlag=!0),this.prevLanes=i,this.pendingMin=null,{count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=t=>t>=0&&t<this.options.count,this.getMeasurements=co(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!o)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(let w of this.laneAssignments.keys())w>=t&&this.laneAssignments.delete(w);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(w=>{this.itemSizeCache.set(w.key,w.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),i===1){let w=t*2,y=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!y||y.length<w){let b=new Float64Array(w);y&&h>0&&b.set(y.subarray(0,h*2)),y=b}let C=h===0?new Array(t):this._singleLaneMeasurements.items.slice(),k;if(h===0)k=r+a;else{let b=h-1;k=y[b*2]+y[b*2+1]+u}for(let b=h;b<t;b++){let P=s(b);C[b]=P;let N=f.get(P),M=typeof N=="number"?N:this.options.estimateSize(b);y[b*2]=k,y[b*2+1]=M,k+=M+u}this._singleLaneMeasurements={flat:y,items:C};let v=Bb(C,y);return this.measurementsCache=v,v}let p=this.measurementsCache.slice(0,h),m=new Array(i).fill(void 0),g=new Float64Array(i),x=0;for(let w=0;w<h;w++){let y=p[w];y&&(m[y.lane]===void 0&&x++,m[y.lane]=w,g[y.lane]=y.end)}for(let w=h;w<t;w++){let y=s(w),C=this.laneAssignments.get(w),k,v,b=l==="estimate"||f.has(y);if(C!==void 0&&this.options.lanes>1){k=C;let U=m[k],I=U!==void 0?p[U]:void 0;v=I?I.end+u:r+a}else if(x===i){let U=0,I=g[0],A=m[0];for(let G=1;G<i;G++){let V=g[G];(V<I||V===I&&m[G]<A)&&(U=G,I=V,A=m[G])}k=U,v=I+u,b&&this.laneAssignments.set(w,k)}else k=w%this.options.lanes,v=r+a,b&&this.laneAssignments.set(w,k);let P=f.get(y),N=typeof P=="number"?P:this.options.estimateSize(w),M=v+N;p[w]={index:w,start:v,size:N,end:M,key:y,lane:k},m[k]===void 0&&x++,m[k]=w,g[k]=M}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=co(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,r,a,s)=>t.length===0||r===0?(this.range=null,null):(this.range=aA(t,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=co(()=>{let t=null,r=null,a=this.calculateRange();return a&&(t=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,r]},(t,r,a,s,o)=>s===null||o===null?[]:t({startIndex:s,endIndex:o,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{let r=this.options.indexAttribute,a=t.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,a-s),i=Math.min(this.options.count-1,a+s);return t>=o&&t<=i}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((o,i)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(i))});return}let r=this.indexFromElement(t);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==t&&(s&&this.observer.unobserve(s),this.observer.observe(t),this.elementsCache.set(a,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,r)=>{var a,s,o;if(!this.isIndexInRange(t))return;let i,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(t),l=c[t*2],i=c[t*2+1];else{let h=this.measurementsCache[t];if(!h)return;u=h.key,l=h.start,i=h.size}let d=this.itemSizeCache.get(u)??i,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,m=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<m:l+d<=m&&this.scrollDirection!=="backward",w=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:u,start:l,size:i,end:l+i,lane:0},f,this):x);(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let y=!1;h?y=this.applyScrollAdjustment(this.getTotalSize()-p):w&&(y=this.applyScrollAdjustment(f)),this.notify(y),this._retryClampedAdjustment()}},this.getVirtualItems=co(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,r)=>{let a=[];for(let s=0,o=t.length;s<o;s++){let i=t[s],l=r[i];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,o=this.options.lanes===1&&s!=null,i=zb(0,a.length-1,o?l=>s[l*2]:l=>bh(a[l]).start,t);return bh(a[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=t>=o+s?"end":"start"),r==="center"?t+=(a-s)/2:r==="end"&&(t-=s);let i=this.getMaxScrollOffset();return Math.max(Math.min(i,t),0)},this.getOffsetForIndex=(t,r="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[t];if(!o)return;if(r==="auto")if(o.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),r];let i=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(i,r,o.size),r]},this.scrollToOffset=(t,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(t,r),o=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,t=Math.max(0,Math.min(t,this.options.count-1));let s=this.getOffsetForIndex(t,r);if(!s)return;let[o,i]=s,l=this.now();this.scrollState={index:t,align:i,behavior:a,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+t,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let o=a.length-1,i=(t=this._singleLaneMeasurements)==null?void 0:t.flat;i!=null?s=i[o*2]+i[o*2+1]:s=((r=a[o])==null?void 0:r.end)??0}else{let o=Array(this.options.lanes).fill(null),i=a.length-1;for(;i>=0&&o.some(l=>l===null);){let l=a[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}s=Math.max(...o.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let t=[];if(this.itemSizeCache.size===0)return t;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&t.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return t},this._scrollToOffset=(t,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=t+(r??0),this.options.scrollToFn(t,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(vh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=a!==this.scrollState.lastTargetOffset;if(!o&&wh(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){let i=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>i;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},zb=(n,e,t,r)=>{for(;n<=e;){let a=(n+e)/2|0,s=t(a);if(s<r)n=a+1;else if(s>r)e=a-1;else return a}return n>0?n-1:0};function rA(n,e,t){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=n[a*2];if(s<t)r=a+1;else if(s>t)e=a-1;else return a}return r>0?r-1:0}function aA(n,e,t,r,a){let s=n.length-1;if(n.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=rA(a,s,t),c=u,d=t+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let i=zb(0,s,u=>n[u].start,t),l=i;if(r===1)for(;l<s&&n[l].end<t+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<t+e);){let d=n[l];u[d.lane]=d.end,l++}let c=Array(r).fill(t+e);for(;i>=0&&c.some(d=>d>=t);){let d=n[i];c[d.lane]=d.start,i--}i=Math.max(0,i-i%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:i,endIndex:l}}var kh=typeof document<"u"?aa.useLayoutEffect:aa.useEffect;function sA({useFlushSync:n=!0,directDomUpdates:e=!1,directDomUpdatesMode:t="transform",...r}){let a=aa.useReducer(d=>d+1,0)[1],s=aa.useRef({enabled:e,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=t;let o=aa.useRef(!1),i=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;i(d);let h=!!d.options.horizontal,p=f.mode==="transform",m=h?"left":"top",g=d.options.scrollMargin,x=d.getVirtualItems();for(let w of x){let y=w.start-g,C=d.elementsCache.get(w.key);C&&f.lastPositions.get(C)!==y&&(f.lastPositions.set(C,y),p?C.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:C.style[m]=`${y}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,m=!0;if(p.enabled){l(d);let g=d.range,x=p.prevRange;m=!x||x.isScrolling!==d.isScrolling||x.startIndex!==g?.startIndex||x.endIndex!==g?.endIndex,m&&(p.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:d.isScrolling}:null)}m&&(n&&f&&!o.current?(0,Wb.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=aa.useState(()=>{let d=new xc(u),f=d.measureElement;return d.measureElement=h=>{o.current=!0;try{f(h)}finally{o.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let m=d.getTotalSize();p.lastSize=m;let g=d.options.horizontal?"width":"height";h.style[g]=`${m}px`}}})});return c.setOptions(u),kh(()=>c._didMount(),[]),kh(()=>(i(c),c._willUpdate())),kh(()=>{l(c)}),c}function ii(n){return sA({observeElementRect:Hb,observeElementOffset:Ub,scrollToFn:Gb,...n})}var Ja=W($e(),1);function jb(n){let{agentId:e,projectId:t,enabled:r}=n,[a,s]=(0,Ja.useState)([]),o=(0,Ja.useRef)(!0);(0,Ja.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let i=(0,Ja.useRef)(!1);return(0,Ja.useEffect)(()=>{i.current=!1,s([])},[e,t]),(0,Ja.useEffect)(()=>{!e||!r||i.current||(i.current=!0,Zu({agentId:e,...t?{projectId:t}:{}}).then(l=>{o.current&&s(l.suggestions??[])}).catch(()=>{o.current&&s([])}))},[e,t,r]),a}var wc=W($e(),1);var sr=W(mr(),1);var Ca=W(le(),1);function oA({className:n}){return(0,Ca.jsxs)("svg",{viewBox:"0 0 64 64",className:n,"aria-hidden":"true",children:[(0,Ca.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,Ca.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Ca.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function iA(n){if(!n)return"aged";let e=Date.parse(n);if(!Number.isFinite(e))return"aged";let t=Math.max(0,(Date.now()-e)/6e4);return t<=15?"fresh":t<=180?"recent":t<=1440?"aged":"stale"}function fo(n){switch(iA(n)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function jl(n){let e=n.status==="deleted",t=n.status==="pending_review",r=n.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:ms,label:"Deleted",title:"Marked as deleted",ghosted:!0}:t?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:dt,label:"Review pending",title:"Pending review before approval"}:n.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:br,label:"Brain node",title:"Stored in brain index"}:n.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:Ka,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:n.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:$a,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:so,label:"Pinned",title:"Pinned item"}:n.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:oA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:ya,label:"Neutral",title:"File entry"}}function qb(n){return n?Ss:Br}function Vb(n){let t=[jl(n).label];return n.version?.changedAt&&t.push(fo(n.version.changedAt).label),n.status==="pinned"&&t.push("Pinned"),t}function yc(n){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:n==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function bc(n){let e=n.enabled===!1,t=n.enabled==="auto"&&n.enabled_effective===!1;return e||t?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:n.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:n.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:n.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var lA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function Sh(n){return(n?lA[n]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function $b(n){return n.enabled===!1?"Source disabled":n.enabled==="auto"&&n.enabled_effective===!1?"Source auto \u2014 currently stopped":n.live===!1?Sh(n.live_reason):n.sync_status==="error"?n.last_error??"Sync error":n.sync_status==="paused"?"Sync paused":n.sync_status==="active"?"Sync active":null}function Ch(n){if(!n)return null;let e=Date.parse(n);if(!Number.isFinite(e))return null;let t=Math.max(0,Math.round((Date.now()-e)/6e4));if(t<1)return"now";if(t<60)return`${t}m`;let r=Math.round(t/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Kb({className:n,title:e}){return(0,Ca.jsx)("span",{title:e,className:"inline-flex",children:(0,Ca.jsx)(ar,{className:n})})}function q(...n){return n.filter(Boolean).join(" ")}var Qn=W(le(),1),uA=5,Xb=28;function Yb({suggestions:n,expanded:e,onToggleExpanded:t,onPick:r,overlay:a}){return n.length===0?null:(0,Qn.jsxs)("div",{className:q("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,Qn.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,Qn.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,Qn.jsx)("button",{type:"button",onClick:t,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,Qn.jsx)(Tt,{className:"h-3 w-3"}):(0,Qn.jsx)(ja,{className:"h-3 w-3"})})]}),(0,Qn.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":uA*Xb},children:n.map(s=>(0,Qn.jsx)(cA,{suggestion:s,onPick:r},s.id))})]})}var cA=wc.default.memo(function({suggestion:e,onPick:t}){let r=yc("unattached"),a=(0,sr.resolveLucideIcon)(e.icon??null)??Gn,s=(0,wc.useCallback)(()=>t(e),[t,e]),o=[e.description,e.root].filter(Boolean).join(`
|
|
3
|
-
`);return(0,
|
|
4
|
-
${et}`:""}`,"aria-label":`${e.name} \u2014 ${et}`,children:[(0,sn.jsx)("span",{className:"shrink-0 text-white/40",children:A?o?(0,sn.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,sn.jsx)(un,{className:"w-3.5 h-3.5"}):(0,sn.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),A?(0,sn.jsx)("span",{title:Q.title,children:(0,sn.jsx)(je,{className:q("w-4 h-4 shrink-0",Q.iconTone),style:{color:e.presence==="brain"&&J||void 0}})}):(0,sn.jsx)(xA,{uri:e.uri,tone:Q.iconTone,title:Q.title}),P?(0,sn.jsx)(yA,{initial:e.name,onCommit:Ne=>U?.({node:e,newName:Ne}),onCancel:()=>I?.()}):(0,sn.jsx)("span",{className:q("min-w-0 text-xs truncate flex-1 transition-colors",Q.tone,Q.ghosted&&"opacity-70",G&&"line-through"),children:e.name}),Dt?(0,sn.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[V?(0,sn.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,sn.jsx)(rw.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,ee?(0,sn.jsx)("span",{className:q("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,ce&&e.git?(0,sn.jsx)(vc,{code:e.git,dot:A}):null,re?(0,sn.jsx)(Kb,{className:q("w-3.5 h-3.5 shrink-0",ue.iconClassName),title:ue.label}):null,pe?(0,sn.jsx)("span",{className:q("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",k?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:i}):null]}):null]})});function yA({initial:n,onCommit:e,onCancel:t}){let r=(0,kr.useRef)(!1);return(0,sn.jsx)("input",{autoFocus:!0,defaultValue:n,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,o=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,o>0?o:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,t()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var Ms=W($e(),1),sw=W(Ya(),1);var Rs=W(le(),1),bA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:ks},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:wr},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Dl,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:ra,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:xl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Il},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:bl},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:wa},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:Ls,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:It,danger:!0,shortcut:"Del"}],wA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:ks},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:wr}],vA=210;function ow({x:n,y:e,enabled:t,onAction:r,onClose:a,variant:s="node"}){let o=s==="source"?wA:bA,i=(0,Ms.useRef)(null),[l,u]=(0,Ms.useState)({top:e,left:n});return(0,Ms.useLayoutEffect)(()=>{let c=i.current;if(!c)return;let d=c.getBoundingClientRect(),f=n,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[n,e]),(0,Ms.useEffect)(()=>{let c=h=>{i.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,sw.createPortal)((0,Rs.jsx)("div",{ref:i,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:vA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:o.map((c,d)=>{if(c.kind==="sep")return(0,Rs.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=t[c.action]===!0,h=c.Icon;return(0,Rs.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:q("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Rs.jsx)(h,{className:q("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Rs.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Rs.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var iw=W($e(),1),lw=W(Ya(),1);var bn=W(le(),1);function uw({names:n,busy:e,onCancel:t,onConfirm:r}){(0,iw.useEffect)(()=>{let o=i=>{e||(i.key==="Escape"?(i.preventDefault(),t()):i.key==="Enter"&&(i.preventDefault(),r()))};return document.addEventListener("keydown",o,!0),()=>document.removeEventListener("keydown",o,!0)},[e,t,r]);let a=n.length>1,s=a?`Delete ${n.length} items?`:`Delete '${n[0]}'?`;return(0,lw.createPortal)((0,bn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:o=>{o.target===o.currentTarget&&!e&&t()},children:(0,bn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,bn.jsx)(dt,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,bn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,bn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,bn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,bn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[n.slice(0,12).map(o=>(0,bn.jsx)("div",{className:"truncate",children:o},o)),n.length>12?(0,bn.jsxs)("div",{className:"text-white/35",children:["+",n.length-12," more\u2026"]}):null]}):null]})]}),(0,bn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,bn.jsxs)("button",{type:"button",onClick:t,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,bn.jsx)(Ut,{className:"h-3 w-3"}),"Cancel"]}),(0,bn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:q("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,bn.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,bn.jsx)(It,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var Za=W($e(),1),cw=W(Ya(),1);var Nt=W(le(),1);function kA(n){return n.usd===null?"unpriced \u2014 the active model has no price":`~$${n.usd.toFixed(2)}${n.usdMargin!==null?` \xB1 $${n.usdMargin.toFixed(2)}`:""}`}function SA(n){return n===null?"time unknown":n<90?`~${Math.round(n)} s`:n<5400?`~${Math.round(n/60)} min`:`~${(n/3600).toFixed(1)} h`}function kc({agentId:n,projectId:e,target:t,onClose:r,onStarted:a}){let[s,o]=(0,Za.useState)(null),[i,l]=(0,Za.useState)(!0),[u,c]=(0,Za.useState)(!1),[d,f]=(0,Za.useState)(null),[h,p]=(0,Za.useState)(!1),m={agentId:n,...e?{projectId:e}:{},source:t.source,...t.folder?{folder:t.folder}:{},...t.uri?{uri:t.uri}:{}};(0,Za.useEffect)(()=>{let x=!0;return l(!0),mx(m).then(w=>{x&&o(w)}).catch(w=>{x&&f(w instanceof Error?w.message:"Estimate failed")}).finally(()=>{x&&l(!1)}),()=>{x=!1}},[]),(0,Za.useEffect)(()=>{let x=w=>{w.key==="Escape"&&!u&&(w.preventDefault(),r())};return document.addEventListener("keydown",x,!0),()=>document.removeEventListener("keydown",x,!0)},[u,r]);let g=async()=>{c(!0),f(null);try{if(!(await gx(m)).job){p(!0),c(!1);return}a?.(),r()}catch(x){f(x instanceof Error?x.message:"Re-embed failed"),c(!1)}};return(0,cw.createPortal)((0,Nt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:x=>{x.target===x.currentTarget&&!u&&r()},children:(0,Nt.jsxs)("div",{role:"dialog","aria-label":`Re-embed ${t.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,Nt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,Nt.jsx)(wa,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,Nt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Nt.jsxs)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:["Re-embed ",t.label,"?"]}),(0,Nt.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:["Every file in this scope is read again and embedded with the ",(0,Nt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]}),(0,Nt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:i?(0,Nt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,Nt.jsx)(ze,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):s?(0,Nt.jsxs)(Nt.Fragment,{children:[(0,Nt.jsxs)("div",{children:[s.documents!==null?`${s.documents.toLocaleString()} documents \xB7 `:null,s.points.toLocaleString()," points"]}),(0,Nt.jsxs)("div",{children:["~",s.tokens.toLocaleString(),s.tokensMargin!==null?` \xB1 ${s.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,Nt.jsxs)("div",{children:[kA(s)," \xB7 ",SA(s.durationSeconds)]}),s.truncated?(0,Nt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):d?null:(0,Nt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),d?(0,Nt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:d}):null,h?(0,Nt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,Nt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,Nt.jsxs)("button",{type:"button",onClick:r,disabled:u,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,Nt.jsx)(Ut,{className:"h-3 w-3"}),"Cancel"]}),(0,Nt.jsxs)("button",{type:"button",onClick:()=>{g()},disabled:u||i||h,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[u?(0,Nt.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,Nt.jsx)(wa,{className:"h-3 w-3"}),"Re-embed"]})]})]})}),document.body)}var di=W($e(),1);var fw=W(Qr(),1);var In=W(le(),1);function CA(n){if(!n)return null;if(n.isRepo&&n.repoName)return{label:n.repoName,title:`Repository: ${n.repoName}`};if(n.containsRepos&&n.repoNames&&n.repoNames.length>0){let e=n.repoNames,t=e.slice(0,2).join(", ");return{label:e.length>2?`${t} +${e.length-2}`:t,title:`Repositories: ${e.join(", ")}`}}return null}function LA({info:n}){let e=(0,sr.resolveIconWithFallback)(n.kind_icon??void 0,Gn),t=n.source_kind==="brain"||n.source_kind==="local-disk",r=!!(n.git?.isRepo||n.git?.containsRepos);return(0,In.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,In.jsx)(e,{className:"w-4 h-4"}),t?(0,In.jsx)(Ml,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,In.jsx)(Ln,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function dw(n){return n.source_kind==="brain"?"brain":Ve(n.uri_root)}var hw=di.default.memo(function({info:e,expanded:t,onToggle:r,onContextMenu:a,onRefresh:s,hydration:o="ready",dirty:i=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,di.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,di.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,di.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=bc(e),p=$b(e),m=CA(e.git),g=o==="loading";return(0,In.jsxs)("div",{className:q("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",t&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":g||void 0,children:[(0,In.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":t,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,In.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,In.jsx)("span",{className:q("shrink-0",h.iconClassName,o==="idle"||o==="error"?"opacity-50":""),children:(0,In.jsx)(LA,{info:e})}),(0,In.jsx)("span",{className:q("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,o==="idle"||o==="error"?"opacity-70":""),children:dw(e)})]}),m?(0,In.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:m.title,children:[(0,In.jsx)(Ln,{className:"h-2.5 w-2.5 shrink-0"}),(0,In.jsx)("span",{className:"truncate",children:m.label})]}):null,s?(0,In.jsx)("button",{type:"button",onClick:f,disabled:g,"aria-label":`Refresh ${dw(e)}`,title:o==="error"?"Last listing failed \u2014 click to retry":i?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:q("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",g||i||o==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",i||o==="error"?"text-amber-300/80 hover:text-amber-200":""),children:g?(0,In.jsx)(fw.LiveSpinner,{className:"h-3 w-3"}):(0,In.jsx)(Ht,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var hi=W($e(),1);var ht=W(le(),1),IA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],fi="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function pw({agentId:n}){let e=B(v=>v.activeProjectId),t=B(v=>v.setActiveFolderPath),r=B(v=>v.openFile),a=B(v=>v.searchQuery),s=B(v=>v.searchMode),o=B(v=>v.setSearchMode),i=B(v=>v.searchFilters),l=B(v=>v.setSearchFilters),u=B(v=>v.searchResults),c=B(v=>v.searchLoading),d=B(v=>v.searchError),f=B(v=>v.runSearch),h=B(v=>v.activeFolderPath),p=B(v=>v.sources),[m,g]=(0,hi.useState)(!1),x=a.trim(),w=i.glob.trim(),y=s==="keyword"?x.length>=2||w.length>=2:x.length>=2,C=(0,hi.useMemo)(()=>th(h,p,i.scopeToFolder),[h,p,i.scopeToFolder]);(0,hi.useEffect)(()=>{if(!y)return;let v=setTimeout(()=>{f({agentId:n,projectId:e??null})},250);return()=>clearTimeout(v)},[n,e,y,s,a,i,f]);let k=(w?1:0)+(i.category.trim()?1:0)+(i.status.trim()?1:0)+(i.tags.trim()?1:0)+(i.createdAfter.trim()?1:0)+(i.createdBefore.trim()?1:0)+(i.scopeToFolder?1:0);return(0,ht.jsxs)("div",{className:"px-2 pb-2",children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,ht.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:IA.map(v=>{let b=v.id==="grep"&&!C;return(0,ht.jsx)("button",{type:"button",disabled:b,onClick:()=>o(v.id),title:b?"Grep needs a disk-backed source (brain:// has no live text)":v.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===v.id?"bg-white/[0.08] text-white/85":b?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===v.id,children:v.label},v.id)})}),(0,ht.jsxs)("button",{type:"button",onClick:()=>g(v=>!v),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${m||k>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":m,children:[(0,ht.jsx)(lo,{className:"w-3.5 h-3.5"}),k>0?(0,ht.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:k}):null]})]}),m?(0,ht.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"text",value:i.glob,onChange:v=>l({glob:v.target.value}),placeholder:"Filename\u2026",className:fi}),(0,ht.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,ht.jsx)("input",{type:"checkbox",checked:i.scopeToFolder,onChange:v=>l({scopeToFolder:v.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,ht.jsxs)(ht.Fragment,{children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"text",value:i.category,onChange:v=>l({category:v.target.value}),placeholder:"Category\u2026",className:fi}),(0,ht.jsx)("input",{type:"text",value:i.status,onChange:v=>l({status:v.target.value}),placeholder:"Status\u2026",className:fi})]}),(0,ht.jsx)("input",{type:"text",value:i.tags,onChange:v=>l({tags:v.target.value}),placeholder:"Tags (comma-separated)\u2026",className:fi}),(0,ht.jsxs)("div",{className:"flex items-center gap-1",children:[(0,ht.jsx)("input",{type:"date",value:i.createdAfter,onChange:v=>l({createdAfter:v.target.value}),title:"Created after",className:fi}),(0,ht.jsx)("input",{type:"date",value:i.createdBefore,onChange:v=>l({createdBefore:v.target.value}),title:"Created before",className:fi})]})]}):null]}):null,y?c?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"No matches"}):(0,ht.jsx)("div",{className:"space-y-1",children:u.map(v=>(0,ht.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{t(ot(v.uri)),r({agentId:n,projectId:e??null,uri:v.uri})},children:[(0,ht.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ht.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:v.filename}),typeof v.score=="number"?(0,ht.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:v.score.toFixed(2)}):null,v.match_type?(0,ht.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:v.match_type==="hybrid"?"H":v.match_type==="semantic"?"S":"K"}):null]}),(0,ht.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[v.uri,s==="grep"&&typeof v.chunk_start=="number"?`:${v.chunk_start}`:""]}),v.snippet??v.content_preview?(0,ht.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:v.snippet??v.content_preview}):null]},`${v.id}:${v.uri}:${v.chunk_start??""}`))}):(0,ht.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var ye=W($e(),1),C1=W(Ya(),1);var L1=W(mr(),1);var it=W($e(),1);var c1=W(Qr(),1);var ho=W(le(),1);function AA(n){return n<1e4?String(n):n<1e6?`${Math.round(n/1e3)}k`:`${(n/1e6).toFixed(1)}M`}function La({added:n,removed:e,binary:t,unknown:r,compact:a,className:s}){if(t)return(0,ho.jsx)("span",{className:q("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof n=="number"&&typeof e=="number")||n===0&&e===0&&!r)return null;let i=a?AA:String,l=r?"+":"";return(0,ho.jsxs)("span",{className:q("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${n} \u2212${e} across the counted files; ${r} more could not be measured`:`+${n} \u2212${e}`,children:[n>0?(0,ho.jsx)("span",{className:"text-emerald-400/80",children:`+${i(n)}${l}`}):null,e>0?(0,ho.jsx)("span",{className:"text-rose-400/80",children:`\u2212${i(e)}${l}`}):null,n===0&&e===0?(0,ho.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function PA(n){return(n.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function mw(n){let e=[],t=[];if(!Array.isArray(n)||n.length===0)return{nodes:e,edges:t,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,o=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<n.length;u++){let c=n[u],d=c.sha,f=r.indexOf(d);f<0&&(f=o(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let m=o(h[p]);m>s&&(s=m)}}e.push({commit:c,row:u,lane:f,isHead:PA(c),isMerge:h.length>=2})}let i=n.map(()=>[]),l=(u,c)=>{u>=0&&u<i.length&&i[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){t.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,m=u.lane,g=f.lane,x=u.lane;if(p<=h)continue;if(m===g){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let w=h+1;w<p;w++)l(w,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}else{let w=(m+g)/2,y=d>0?"merge":"fork";if(d>0){if(l(h,{kind:y,fromLane:m,toLane:w,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:y,fromLane:w,toLane:g,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let C=h+2;C<p;C++)l(C,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let C=h+1;C<p-1;C++)l(C,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:y,fromLane:m,toLane:w,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:y,fromLane:w,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}}else t.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:t,rowSegments:i,laneCount:s+1}}function gw(n,e){if(!Array.isArray(n)||e<=0||e>=n.length)return[];let t=[],r=new Set;for(let a of n[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),t.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return t}var Ph={commits:[],nextSkip:0,hasMore:!1};function xw(n,e){let t=[];for(let r of e.commits)!r||typeof r.sha!="string"||n.has(r.sha)||(n.add(r.sha),t.push(r));return t}function yw(n,e){let t=new Set(n.commits.map(a=>a.sha)),r=xw(t,e);return{commits:r.length>0?[...n.commits,...r]:n.commits,nextSkip:n.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:n.outgoing}}function bw(n){return{commits:xw(new Set,n),nextSkip:n.commits.length,hasMore:n.hasMore,outgoing:n.outgoing}}function Nh(n){return Math.min(1e3,Math.max(n,200))}function ww(n,e){let t=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<n.length;s++)!a&&r&&r.has(n[s].sha)&&(t.push({kind:"outgoing-divider"}),a=!0),t.push({kind:"commit",row:s});return t}function vw(n,e){return n.kind==="outgoing-divider"?"#outgoing-divider":e[n.row]?.sha??`row-${n.row}`}function kw(n){let e=n.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Sw(n,e){return e?"outgoing":n?"merge":"filled"}var NA="#89b4fa";function Cw(n,e){return n==="outgoing"?NA:e}function Rh(n,e=Date.now()){let t=Date.parse(n);if(Number.isNaN(t))return n;let r=Math.max(0,Math.floor((e-t)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let o=Math.floor(s/24);if(o<30)return`${o}d ago`;let i=Math.floor(o/30);return i<12?`${i}mo ago`:`${Math.floor(i/12)}y ago`}function Lw(n){return!n||typeof n.upstream!="string"||n.upstream.length===0?null:{upstream:n.upstream,ahead:typeof n.ahead=="number"&&n.ahead>=0?n.ahead:0,behind:typeof n.behind=="number"&&n.behind>=0?n.behind:0}}function Mh(n,e){if(typeof window>"u")return e;try{let t=JSON.parse(window.localStorage.getItem(n)??"null");return typeof t=="boolean"?t:e}catch{return e}}function Th(n,e){if(!(typeof window>"u"))try{window.localStorage.setItem(n,JSON.stringify(e))}catch{}}function Ts(n,e){return typeof e=="string"&&e.length>0?{prefix:`${n}://`,name:e,title:`Source "${n}" \u2014 repository "${e}"`}:{prefix:"",name:n,title:`Repository: ${n}`}}var es=W($e(),1);var En=W($e(),1),RA=3,Iw=200,Aw=8*1024*1024,MA="200% 0px";function Sc(n){let e=(0,En.useRef)(new Map),t=(0,En.useRef)(null),[r,a]=(0,En.useState)(new Set),s=(0,En.useRef)(0),o=(0,En.useRef)([]),i=(0,En.useRef)(new Map),l=(0,En.useRef)(0),u=(0,En.useRef)(new Map),c=(0,En.useCallback)((p,m)=>{let g=e.current.get(p);g!==m&&(g&&t.current?.unobserve(g),m?(m.dataset.diffCardKey=p,e.current.set(p,m),t.current?.observe(m)):e.current.delete(p))},[]);(0,En.useEffect)(()=>{if(a(new Set),!n||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(m=>{a(g=>{let x=new Set(g);for(let w of m){let y=w.target.dataset.diffCardKey;y&&(w.isIntersecting?x.add(y):x.delete(y))}return x.size===g.size&&[...x].every(w=>g.has(w))?g:x})},{root:n,rootMargin:MA});t.current=p;for(let m of e.current.values())p.observe(m);return()=>{p.disconnect(),t.current=null}},[n]);let d=(0,En.useCallback)((p,m,g,x)=>{let w=i.current,y=w.get(p);if(y&&(w.delete(p),l.current-=y.bytes),!(g>Aw)){w.set(p,{value:m,bytes:g}),l.current+=g,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Iw&&u.current.delete(u.current.keys().next().value);for(let[C,k]of w){if(w.size<=Iw&&l.current<=Aw)break;w.delete(C),l.current-=k.bytes}}},[]),f=(0,En.useCallback)((p,m,g)=>{if(g&&!g.fresh){let x=i.current.get(g.key);if(x)return i.current.delete(g.key),i.current.set(g.key,x),Promise.resolve(x.value)}return new Promise((x,w)=>{let y=()=>{s.current+=1;let C=()=>{s.current-=1,o.current.shift()?.()};if(!m()){C(),x(void 0);return}p().then(k=>{g&&d(g.key,k,g.bytes(k),g.family),C(),x(k)},k=>{C(),w(k)})};s.current<RA?y():o.current.push(y)})},[d]),h=(0,En.useCallback)((p,m)=>(i.current.get(p)??(m?i.current.get(u.current.get(m)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var gt=W($e(),1);var Oe=W(le()),kt=W($e());function Pw(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),t.push.apply(t,r)}return t}function At(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Pw(Object(t),!0).forEach((function(r){Oh(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):Pw(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function Oh(n,e,t){return(e=(function(r){var a=(function(s,o){if(typeof s!="object"||s===null)return s;var i=s[Symbol.toPrimitive];if(i!==void 0){var l=i.call(s,o||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function Fs(n,e){if(n==null)return{};var t,r,a=(function(o,i){if(o==null)return{};var l,u,c={},d=Object.keys(o);for(u=0;u<d.length;u++)l=d[u],i.indexOf(l)>=0||(c[l]=o[l]);return c})(n,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(r=0;r<s.length;r++)t=s[r],e.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(n,t)&&(a[t]=n[t])}return a}function en(n,e){return rv(n)||(function(t,r){var a=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(a!=null){var s,o,i,l,u=[],c=!0,d=!1;try{if(i=(a=a.call(t)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=i.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,o=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw o}}return u}})(n,e)||Fc(n,e)||sv()}function TA(n){return rv(n)||av(n)||Fc(n)||sv()}function Sr(n){return(function(e){if(Array.isArray(e))return _h(e)})(n)||av(n)||Fc(n)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
5
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function
|
|
6
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function
|
|
7
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,o=!0,i=!1;return{s:function(){t=t.call(n)},n:function(){var l=t.next();return o=l.done,l},e:function(l){i=!0,s=l},f:function(){try{o||t.return==null||t.return()}finally{if(i)throw s}}}}var
|
|
8
|
-
`),p=h.length,m=0;m<p;){var g=h[m];if(g.indexOf("diff --git")===0){o={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(g)).oldPath,newPath:c.newPath},d.push(o);var x,
|
|
1
|
+
import{a as Vo,c as j}from"./chunks/chunk-DCANE7XH.js";var Ve=Vo((IO,I0)=>{var Xf=globalThis.__neuralis_shared_modules__,L0=Xf&&Object.prototype.hasOwnProperty.call(Xf,"react")?Xf.react:void 0;if(L0===void 0)throw new Error("[neuralis-ui] shared module react is not provided by the host");I0.exports=L0});var wr=Vo((AO,P0)=>{var Yf=globalThis.__neuralis_shared_modules__,A0=Yf&&Object.prototype.hasOwnProperty.call(Yf,"@neuralis/package-system/client")?Yf["@neuralis/package-system/client"]:void 0;if(A0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/package-system/client is not provided by the host");P0.exports=A0});var ta=Vo((PO,R0)=>{var Jf=globalThis.__neuralis_shared_modules__,N0=Jf&&Object.prototype.hasOwnProperty.call(Jf,"@neuralis/agent-core/app/chat")?Jf["@neuralis/agent-core/app/chat"]:void 0;if(N0===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat is not provided by the host");R0.exports=N0});var le=Vo((_8,Fb)=>{var bh=globalThis.__neuralis_shared_modules__,Db=bh&&Object.prototype.hasOwnProperty.call(bh,"react/jsx-runtime")?bh["react/jsx-runtime"]:void 0;if(Db===void 0)throw new Error("[neuralis-ui] shared module react/jsx-runtime is not provided by the host");Fb.exports=Db});var Qa=Vo((YU,_b)=>{var kh=globalThis.__neuralis_shared_modules__,Bb=kh&&Object.prototype.hasOwnProperty.call(kh,"react-dom")?kh["react-dom"]:void 0;if(Bb===void 0)throw new Error("[neuralis-ui] shared module react-dom is not provided by the host");_b.exports=Bb});var r2=Vo((u9,n2)=>{var p0=globalThis.__neuralis_shared_modules__,t2=p0&&Object.prototype.hasOwnProperty.call(p0,"@neuralis/agent-core/app/chat/store")?p0["@neuralis/agent-core/app/chat/store"]:void 0;if(t2===void 0)throw new Error("[neuralis-ui] shared module @neuralis/agent-core/app/chat/store is not provided by the host");n2.exports=t2});var jf=j(Ve(),1),qf=j(wr(),1),y2=j(ta(),1);var Nn=j(Ve(),1);var M0=n=>{let e,t=new Set,r=(u,c)=>{let d=typeof u=="function"?u(e):u;if(!Object.is(d,e)){let f=e;e=c??(typeof d!="object"||d===null)?d:Object.assign({},e,d),t.forEach(h=>h(e,f))}},a=()=>e,i={setState:r,getState:a,getInitialState:()=>l,subscribe:u=>(t.add(u),()=>t.delete(u))},l=e=n(r,a,i);return i},T0=(n=>n?M0(n):M0);var il=j(Ve(),1);var O2=n=>n;function B2(n,e=O2){let t=il.default.useSyncExternalStore(n.subscribe,il.default.useCallback(()=>e(n.getState()),[n,e]),il.default.useCallback(()=>e(n.getInitialState()),[n,e]));return il.default.useDebugValue(t),t}var D0=n=>{let e=T0(n),t=r=>B2(e,r);return Object.assign(t,e),t},F0=(n=>n?D0(n):D0);function Qf(n,e){let t;try{t=n()}catch{return}return{getItem:a=>{var s;let o=l=>l===null?null:JSON.parse(l,e?.reviver),i=(s=t.getItem(a))!=null?s:null;return i instanceof Promise?i.then(o):o(i)},setItem:(a,s)=>t.setItem(a,JSON.stringify(s,e?.replacer)),removeItem:a=>t.removeItem(a)}}var Zf=n=>e=>{try{let t=n(e);return t instanceof Promise?t:{then(r){return Zf(r)(t)},catch(r){return this}}}catch(t){return{then(r){return this},catch(r){return Zf(r)(t)}}}},_2=(n,e)=>(t,r,a)=>{let s={storage:Qf(()=>window.localStorage),partialize:g=>g,version:0,merge:(g,x)=>({...x,...g}),...e},o=!1,i=0,l=new Set,u=new Set,c=s.storage;if(!c)return n((...g)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),t(...g)},r,a);let d=()=>{let g=s.partialize({...r()});return c.setItem(s.name,{state:g,version:s.version})},f=a.setState;a.setState=(g,x)=>(f(g,x),d());let h=n((...g)=>(t(...g),d()),r,a);a.getInitialState=()=>h;let p,m=()=>{var g,x;if(!c)return;let b=++i;o=!1,l.forEach(N=>{var L;return N((L=r())!=null?L:h)});let y=((x=s.onRehydrateStorage)==null?void 0:x.call(s,(g=r())!=null?g:h))||void 0;return Zf(c.getItem.bind(c))(s.name).then(N=>{if(N)if(typeof N.version=="number"&&N.version!==s.version){if(s.migrate){let L=s.migrate(N.state,N.version);return L instanceof Promise?L.then(A=>[!0,A]):[!0,L]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,N.state];return[!1,void 0]}).then(N=>{var L;if(b!==i)return;let[A,w]=N;if(p=s.merge(w,(L=r())!=null?L:h),t(p,!0),A)return d()}).then(()=>{b===i&&(y?.(r(),void 0),p=r(),o=!0,u.forEach(N=>N(p)))}).catch(N=>{b===i&&y?.(void 0,N)})};return a.persist={setOptions:g=>{s={...s,...g},g.storage&&(c=g.storage)},clearStorage:()=>{++i,c?.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>m(),hasHydrated:()=>o,onHydrate:g=>(l.add(g),()=>{l.delete(g)}),onFinishHydration:g=>(u.add(g),()=>{u.delete(g)})},s.skipHydration||m(),p||h},E0=_2;var O0=j(wr(),1);function Je(){return(0,O0.tryGetPackageApiImperativeAsync)("brain-core")}async function $o(n,e,t){let r=await Je(),a={agentId:n};return e&&(a.projectId=e),t?.uri&&(a.uri=t.uri),typeof t?.recursive=="boolean"&&(a.recursive=t.recursive),t?.include&&(a.include=t.include),typeof t?.summary_chars=="number"&&(a.summary_chars=t.summary_chars),typeof t?.include_metadata=="boolean"&&(a.include_metadata=t.include_metadata),typeof t?.only_indexed=="boolean"&&(a.only_indexed=t.only_indexed),typeof t?.sources_only=="boolean"&&(a.sources_only=t.sources_only),typeof t?.include_counts=="boolean"&&(a.include_counts=t.include_counts),typeof t?.limit=="number"&&(a.limit=t.limit),r.post("list",a)}async function B0(n,e,t){return(await $o(n,e,{uri:`${t}://`,recursive:!1,include:"folders",include_counts:!0,limit:1})).sources?.[0]??null}async function Ko(n){return(await Je()).post("read",n)}async function _0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.scope&&(e.scope=n.scope),n.observed&&(e.observed="1"),(await Je()).get("sources",e)}async function eh(n){return(await Je()).patch("sources",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},...n.config})}async function H0(n){return(await Je()).post("sources/sync",n)}async function U0(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),n.source&&(e.source=n.source),(await Je()).get("sources/sync-status",e)}async function G0(n){return(await Je()).post("sources/enabled",{agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},source:n.source,enabled:n.enabled})}async function ac(n){let e=new URLSearchParams;return e.set("agentId",n.agentId),n.projectId&&e.set("projectId",n.projectId),(await Je()).get("sources/discoverable",Object.fromEntries(e))}function ps(n){return n?{repo:n}:{}}function vr(n){return n?{repo:n}:{}}async function Xo(n){let e={agentId:n.agentId,source:n.source};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/repos",e)}async function sc(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/status",e)}async function z0(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/branch",e)}async function oc(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo),path:n.path};return typeof n.commit=="string"&&(e.commit=n.commit),typeof n.base=="string"&&(e.base=n.base),typeof n.head=="string"&&(e.head=n.head),typeof n.staged=="boolean"&&(e.staged=n.staged?"1":"0"),n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/diff",e)}async function ic(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Je()).get("git/log",e)}async function W0(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo)};return n.projectId&&(e.projectId=n.projectId),typeof n.maxCount=="number"&&(e.maxCount=String(n.maxCount)),typeof n.skip=="number"&&(e.skip=String(n.skip)),n.ref&&(e.ref=n.ref),(await Je()).get("git/log-stats",e)}async function lc(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo),sha:n.sha};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/commit",e)}async function ll(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo)};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/outgoing",e)}async function j0(n){let e={agentId:n.agentId,source:n.source,...ps(n.repo),path:n.path,rev:n.rev};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("git/show",e)}var kr=()=>Je();async function q0(n){return(await kr()).post("git/stage",{source:n.source,...vr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function V0(n){return(await kr()).post("git/unstage",{source:n.source,...vr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function $0(n){return(await kr()).post("git/stage",{source:n.source,...vr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function K0(n){return(await kr()).post("git/unstage",{source:n.source,...vr(n.repo),hunk:n.hunk,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function X0(n){return(await kr()).post("git/discard",{source:n.source,...vr(n.repo),paths:n.paths,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Y0(n){return(await kr()).post("git/commit",{source:n.source,...vr(n.repo),message:n.message,...n.amend?{amend:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function J0(n){return(await kr()).post("git/branch",{source:n.source,...vr(n.repo),action:"create",name:n.name,...n.startPoint?{startPoint:n.startPoint}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Z0(n){return(await kr()).post("git/branch",{source:n.source,...vr(n.repo),action:"delete",name:n.name,...n.force?{force:!0}:{},...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function Q0(n){return(await kr()).post("git/restore",{source:n.source,...vr(n.repo),rescue:n.rescue,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function th(n){return(await kr()).post("git/checkout",{source:n.source,...vr(n.repo),ref:n.ref,...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function ex(n){return(await kr()).post("git/fetch",{source:n.source,...vr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function tx(n){return(await kr()).post("git/pull",{source:n.source,...vr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function nx(n){return(await kr()).post("git/push",{source:n.source,...vr(n.repo),...n.projectId?{projectId:n.projectId}:{},agentId:n.agentId})}async function rx(n){return(await Je()).post("search",n)}async function uc(n){let e=new FormData;return e.append("agentId",n.agentId),n.projectId&&e.append("projectId",n.projectId),e.append("file",n.file),n.uri&&e.append("uri",n.uri),n.tags?.length&&e.append("tags",n.tags.join(",")),(await Je()).upload("upload",e)}async function Sr(n){return(await Je()).post("write",n)}function ya(n,e){return n?.code==="destination_exists"?"Something is already there \u2014 nothing was overwritten. Pick another name.":n?.message||n?.error||e}async function cc(n){return(await Je()).post("approve",n)}async function Yo(n){return(await(await Je()).post("pending",{...n,action:"preview"})).preview}async function ax(n){let e=await(await Je()).post("pending",n);return{ok:e?.ok!==!1,changes:Array.isArray(e?.changes)?e.changes:[],orphanIds:Array.isArray(e?.orphanIds)?e.orphanIds:[]}}async function sx(n){let e={agentId:n.agentId,count_only:"1"};n.projectId&&(e.projectId=n.projectId);let t=await(await Je()).get("pending",e);return typeof t?.count=="number"?t.count:0}async function ox(n){return(await Je()).post("pending",{...n,action:"revert"})}async function ix(n){return(await Je()).post("pending",{...n,action:"discard"})}async function lx(n){return(await Je()).post("pending",{...n,action:"dismiss"})}async function ux(n){let e=await(await Je()).post("pending",{...n,action:"discard-orphans"});return{ok:e?.ok!==!1,discarded:typeof e?.discarded=="number"?e.discarded:0}}function cx(n,e,t){let r=new URLSearchParams({agentId:n,uri:e});return t&&r.set("projectId",t),`/api/packages/brain-core/raw?${r.toString()}`}async function dx(n){return(await Je()).post("health",n)}async function fx(n){return(await Je()).post("health/scan",n)}async function hx(n){return(await Je()).post("health/gc",n)}async function px(n){return(await Je()).post("sources",n)}async function mx(n){let e=new URLSearchParams({agentId:n.agentId});return n.projectId&&e.set("projectId",n.projectId),n.purgeVectors&&e.set("purge","1"),(await Je()).del(`sources/${encodeURIComponent(n.source)}?${e.toString()}`)}async function gx(n){return(await Je()).post("sources/reset",n)}async function xx(n){return(await Je()).post("sources/reindex",n)}async function yx(n){return(await Je()).post("sources/purge",n)}function eo(n){return typeof n=="number"&&Number.isFinite(n)?n:null}function H2(n){let e=n&&typeof n=="object"?n:null,t=e?.estimate&&typeof e.estimate=="object"?e.estimate:null,r=eo(t?.points),a=eo(t?.tokens);if(!e||!t||r===null||a===null)return null;let s=eo(t.relStdErr),o=eo(t.usd);return{documents:eo(e.documents),truncated:e.truncated===!0,points:r,tokens:a,tokensMargin:s!==null?Math.round(a*s):null,usd:o,usdMargin:s!==null&&o!==null?o*s:null,durationSeconds:eo(t.seconds)}}var bx=n=>n==="pending"?{embeddingOnly:!0}:{force:!0};async function wx(n,e="reembed"){return H2(await(await Je()).post("sources/reindex",{...n,...bx(e),estimate:!0}))}async function dc(n,e="reembed"){let t=await(await Je()).post("sources/reindex",{...n,...bx(e)}),r=t?.job&&typeof t.job=="object"?t.job:null;return{documents:eo(t?.documents),truncated:t?.truncated===!0,job:r}}async function vx(n){return(await Je()).post("sources/cancel",n)}async function kx(n){let e={agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("sources/health",e)}async function nh(n){let e={path:n.path,agentId:n.agentId};return n.projectId&&(e.projectId=n.projectId),(await Je()).get("sources/browse",e)}async function Sx(){return(await Je()).get("sources/kinds",{})}function qe(n){let e=n.indexOf("://");return e>0?n.slice(0,e):"brain"}function or(n){let e=n.indexOf("://");return e>0?n.slice(0,e+3):`${n}://`}function nt(n){let e=n.indexOf("://");if(e<1)return n;let t=n.slice(0,e+3),r=n.lastIndexOf("/");return r<=e+2?t:n.slice(0,r)}function ba(n){let e=n.indexOf("://");if(e<1)return[];let r=`${n.slice(0,e)}://`,a=n.slice(e+3);if(!a)return[];let s=a.split("/").filter(Boolean);if(s.length===0)return[];let o=[r],i=r;for(let l=0;l<s.length-1;l++)i=i.endsWith("/")?`${i}${s[l]}`:`${i}/${s[l]}`,o.push(i);return o}function yt(n){let e=n.indexOf("://"),t=e>=0?n.slice(e+3):n,r=t.lastIndexOf("/");return r>=0?t.slice(r+1):t}var Cx=n=>n;function Va(n){return n.uri}function U2(n,e,t){for(let r of e){if(n[r]?.type==="folder")continue;let a=r.endsWith("://")?r.slice(0,r.indexOf("://")):r.split("/").pop()||"",s=nt(r),o=n[r];n[r]={...o||{},storeKey:r,name:a,uri:r,type:"folder",parentUri:s===r?void 0:s,lastUpdated:t}}}function to(n,e,t){U2(n,ba(e),t)}function ul(n){if(typeof n=="string")return n;if(Array.isArray(n)){let e=n.map(t=>{if(t){if(typeof t=="string")return t;if(typeof t=="object"){let r=typeof t.text=="string"?t.text:void 0,a=typeof t.content=="string"?t.content:void 0;return r??a}}}).filter(t=>!!(t&&t.trim()));if(e.length>0)return e.join(`
|
|
2
|
+
`)}if(n&&typeof n=="object"){let e=n;if(typeof e.text=="string")return e.text;if(typeof e.content=="string")return e.content;if(Array.isArray(e.content)){let t=ul(e.content);if(t)return t}try{return JSON.stringify(n,null,2)}catch{return}}}function Jo(n){return Array.isArray(n?.files)?n.files:Array.isArray(n?.widget?.files)?n.widget.files:Array.isArray(n?.state?.files)?n.state.files:Array.isArray(n?.data?.files)?n.data.files:[]}function Zo(n){return ul(n?.text)??ul(n?.content)??ul(n?.file_content)??ul(n?.fileContent)??""}function fc(n){if(!n||typeof n!="object")return;let e=n;if(e.content!=null)return{content:typeof e.content=="string"?e.content:JSON.stringify(e.content,null,2),updatedAt:typeof e.updatedAt=="string"?e.updatedAt:"",...typeof e.uri=="string"?{uri:e.uri}:{},...typeof e.status=="string"?{status:e.status}:{},...typeof e.sourceVersion=="string"?{sourceVersion:e.sourceVersion}:{},...e.metadata&&typeof e.metadata=="object"?{metadata:e.metadata}:{}}}function hc(n,e){return typeof n.fileErrorByPath[e]=="string"||typeof n.fileBaseContentByPath[e]=="string"}function ms(n,e,t){return`${n??""}::${e??""}::${t}`}var rh=0,ah={glob:"",category:"",status:"",tags:"",createdAfter:"",createdBefore:"",scopeToFolder:!1},Lx={searchQuery:"",searchMode:"keyword",searchFilters:ah,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}};function sh(n,e,t){let r=typeof n=="string"&&n.includes("://")?n:null;if(t&&r)return r.startsWith("brain://")?null:r;let a=r?or(r):null;return a&&!a.startsWith("brain://")?a:(e??[]).find(o=>o.source_kind!=="brain"&&typeof o.uri_root=="string")?.uri_root??null}function Ix(n,e){return{setSearchQuery:t=>n(()=>({searchQuery:t})),setSearchMode:t=>n(()=>({searchMode:t})),setSearchFilters:t=>n(r=>({searchFilters:{...r.searchFilters,...t}})),clearSearch:()=>n(()=>({searchQuery:"",searchFilters:ah,searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}})),async runSearch({agentId:t,projectId:r}){let{searchQuery:a,searchMode:s,searchFilters:o,activeFolderPath:i,sources:l}=e(),u=(a??"").trim(),c=o??ah,d=c.glob.trim(),f=s==="keyword"?u.length>=2||d.length>=2:u.length>=2;if(!t||!f){n(()=>({searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{}}));return}let h=typeof i=="string"&&i.includes("://")?i:void 0,p=s==="grep"?sh(i,l,c.scopeToFolder):c.scopeToFolder?h:void 0;if(s==="grep"&&!p){n(()=>({searchResults:[],searchLoading:!1,searchError:"Grep needs a non-brain folder scope \u2014 select a folder in a disk-backed source.",searchEffect:{}}));return}let m=c.tags.split(",").map(x=>x.trim()).filter(x=>x.length>0),g=++rh;n(()=>({searchLoading:!0,searchError:void 0}));try{let x=await rx({agentId:t,...r?{projectId:r}:{},search_mode:s==="keyword"?"filter":s,...u?{query:u}:{},...p?{folder_uri:p}:{},...d?{glob:d}:{},...s!=="grep"&&c.category.trim()?{category:c.category.trim()}:{},...s!=="grep"&&c.status.trim()?{status:c.status.trim()}:{},...s!=="grep"&&m.length>0?{tags:m}:{},...s!=="grep"&&c.createdAfter.trim()?{created_after:c.createdAfter.trim()}:{},...s!=="grep"&&c.createdBefore.trim()?{created_before:c.createdBefore.trim()}:{},limit:s==="semantic"?30:50});if(g!==rh)return;let b=x.results||[],y=b.find(L=>typeof L.error=="string"&&L.error.length>0),N=b.filter(L=>typeof L.uri=="string"&&L.uri.includes("://")&&!L.error).map(L=>({id:L.id||`fs:${L.uri}:${L.chunk_start??""}`,uri:L.uri,filename:L.filename||String(L.uri).split("/").pop(),content_preview:L.content_preview,snippet:L.snippet,chunk_start:L.chunk_start,chunk_end:L.chunk_end,match_type:L.match_type,score:L.score,...typeof L.embedding_status=="string"?{embedding_status:L.embedding_status}:{}}));n(()=>({searchResults:N,searchLoading:!1,searchError:y?String(y.error):void 0,searchEffect:{...x.requested_mode?{requestedMode:x.requested_mode}:{},...x.effective_mode?{effectiveMode:x.effective_mode}:{},...x.embedding_degraded?{embeddingDegraded:x.embedding_degraded}:{},...x.warning?{warning:x.warning}:{}}}))}catch(x){if(g!==rh)return;n(()=>({searchResults:[],searchLoading:!1,searchError:x instanceof Error?x.message:"Search failed",searchEffect:{}}))}}}}var oh=new Map;function Qo(){return{files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},pendingReviewPaths:new Set,pendingCount:0,expandedFolders:new Set,sidebarView:"tree",activeWorkspaceTab:"file",workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},pendingSourceSuggestion:null,vectorHealthOpen:!1,searchQuery:"",searchResults:[],searchLoading:!1,searchError:void 0,searchEffect:{},gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,pendingPanelFilter:{},activeFolderPath:"brain://docs",snapshotError:void 0}}var G2=200;function pc(n,e=G2){let t=[...n],r=[],a=!0;for(;t.length>e&&a;){a=!1;for(let s=0;s<t.length&&t.length>e;){let o=t[s],i=`${o}/`;if(o.endsWith("://")||t.some(l=>l.startsWith(i))){s+=1;continue}t.splice(s,1),r.push(o),a=!0}}return{kept:t,evicted:r}}var z2=Object.keys(Qo());function W2(n){let e={};for(let t of z2)e[t]=n[t];return e}function mc(n){let e=n.expandedFolders;return{openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:e instanceof Set?pc(Array.from(e)).kept:[],sidebarView:n.sidebarView??"tree",activeWorkspaceTab:n.activeWorkspaceTab??"file",workspacePanels:n.workspacePanels??{upload:!1,sources:!1,packages:!1,pending:!1},activeFolderPath:n.activeFolderPath??"brain://docs"}}function ih(n){let e=Qo();return n?{...e,openFiles:Array.isArray(n.openFiles)?n.openFiles:[],activeFile:typeof n.activeFile=="string"?n.activeFile:null,tabMeta:n.tabMeta??{},expandedFolders:new Set(Array.isArray(n.expandedFolders)?pc(n.expandedFolders).kept:[]),sidebarView:n.sidebarView??e.sidebarView,activeWorkspaceTab:n.activeWorkspaceTab??e.activeWorkspaceTab,workspacePanels:n.workspacePanels??e.workspacePanels,activeFolderPath:n.activeFolderPath??e.activeFolderPath}:e}function Ax(n,e){return{async loadList({agentId:t,projectId:r,userId:a,withCounts:s}){if(!t)return;let o=`${t}:${r||""}:${s?"c":""}`,i=oh.get(o);if(i){await i;return}let l="brain://",u=e(),c=a===void 0?u.activeUserId:a,d=u.activeUserId!==null&&u.activeUserId!==c,f=u.activeAgentId!==t||u.activeProjectId!==r||d,h;if(f?(e().fenceInFlightWriters(),n(m=>{let g={...m.contextStateByKey};m.activeAgentId&&(g[ms(m.activeUserId,m.activeProjectId,m.activeAgentId)]=W2(m));let x=ms(c,r,t);return h=g[x],delete g[x],{activeUserId:c,activeAgentId:t,activeProjectId:r,...Qo(),...h??{},contextStateByKey:g}})):n(()=>({activeUserId:c,activeAgentId:t,activeProjectId:r,sourcesLoading:!0})),h){let m=h.loadedFolders??{},g=new Set;for(let[x,b]of Object.entries(m)){if(!b)continue;let y=qe(x);y&&g.add(y)}for(let x of g)e().reconcileSourceFolders({agentId:t,projectId:r,source:x})}e().rehydrateActiveTab();let p=(async()=>{let m;try{m=await $o(t,r??void 0,{sources_only:!0,recursive:!1,...s?{include_counts:!0}:{}})}catch{n(()=>({snapshotError:"Filesystem service unavailable",sourcesLoading:!1}));return}let g=Array.isArray(m.folders)?m.folders:[],x=Array.isArray(m.files)?m.files:[],b=Array.isArray(m.sources)?m.sources:[];n(y=>{let N=y.activeAgentId===t&&y.activeProjectId===r,L=N?{...y.files}:{},A=Date.now();L[l]||(L[l]={storeKey:l,name:"brain",uri:l,type:"folder",lastUpdated:A,presence:"brain"});for(let T of g){let P=typeof T=="string"?T:typeof T?.uri=="string"?T.uri:"";if(!P)continue;let O=typeof T?.name=="string"?T.name:P.split("/").pop()||"folder",C=T?.presence??(qe(P)==="brain"?"brain":"stale_indexed");to(L,`${P}/placeholder`,A),L[P]={storeKey:P,name:O,uri:P,type:"folder",parentUri:P.endsWith("://")?void 0:nt(P),lastUpdated:A,presence:C,git:typeof T.git=="string"?String(T.git):void 0}}for(let T of x){let P=typeof T?.uri=="string"?String(T.uri):"";if(!P)continue;let O=typeof T?.id=="string"?String(T.id):void 0,C=typeof T.status=="string"?String(T.status):void 0,I=Array.isArray(T.tags)&&T.tags.length>0?T.tags:void 0,H=typeof T.category=="string"?String(T.category):void 0,q=T.version&&typeof T.version=="object"?T.version:void 0,$=typeof T.agent_id=="string"?String(T.agent_id):void 0,S=typeof T.project_id=="string"?String(T.project_id):void 0,M=T?.presence??(qe(P)==="brain"?"brain":"stale_indexed"),W=typeof T.git=="string"?String(T.git):void 0;to(L,P,A),L[P]={storeKey:P,id:O,name:String(T.filename||T.name||yt(P)),uri:P,os_uri:typeof T.os_uri=="string"?String(T.os_uri):void 0,type:"file",status:C,parentUri:nt(P),lastUpdated:A,category:H,tags:I,metadata:T.metadata&&typeof T.metadata=="object"?T.metadata:void 0,createdAt:typeof T.createdAt=="string"?String(T.createdAt):void 0,updatedAt:typeof T.updatedAt=="string"?String(T.updatedAt):void 0,version:q,sourceAgentId:$,sourceProjectId:S,presence:M,git:W};let ee=nt(P),te=L[ee];te&&te.type==="folder"&&(L[ee]={...te,sourceAgentId:$??te.sourceAgentId,sourceProjectId:S??te.sourceProjectId,lastUpdated:A})}let w=N?{...y.loadedFolders||{}}:{},v=N?{...y.hydrationState||{}}:{};for(let T of b)!w[T.uri_root]&&!v[T.uri_root]&&(v[T.uri_root]="idle");return{files:L,sources:b,sourcesLoading:!1,snapshotError:void 0,loadedFolders:w,hydrationState:v}})})();oh.set(o,p);try{await p}finally{oh.delete(o)}},async refresh({agentId:t,projectId:r,withCounts:a}){await e().loadList({agentId:t,projectId:r,withCounts:a})}}}var lh=0,uh=0,Nx={gitStatus:null,gitTotals:null,gitOutgoingStat:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitViewMode:"list",gitDiffTarget:null,gitCommitTarget:null,gitLogNonce:0};function ch(n,e){let t=n??(typeof e=="string"?e:"");return t?t.includes("://")?qe(t):t:""}function Px(n,e){return typeof n=="string"?n:typeof e=="string"?e:""}function Rx(n,e){return{setGitViewMode:t=>n(()=>({gitViewMode:t})),setGitDiffTarget:t=>n(()=>({gitDiffTarget:t})),setGitCommitTarget:t=>n(r=>({gitCommitTarget:t,...t===null&&r.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),notifyGitLogChanged:t=>{if(!t)return;let r=ch(void 0,e().activeSource);t===r&&n(a=>({gitLogNonce:(typeof a.gitLogNonce=="number"?a.gitLogNonce:0)+1}))},clearGit:()=>n(t=>({gitStatus:null,gitBranches:[],gitLoading:!1,gitError:void 0,gitDiffTarget:null,gitCommitTarget:null,...t.activeWorkspaceTab==="git-commit"?{activeWorkspaceTab:"file"}:{}})),setGitOutgoingStat(t){n(()=>({gitOutgoingStat:t}))},async loadGitStatus({agentId:t,projectId:r,source:a,repo:s}){let o=ch(a,e().activeSource),i=Px(s,e().activeRepoRel);if(!t||!o){n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:void 0}));return}let l=++lh;n(()=>({gitLoading:!0,gitError:void 0}));try{let u=await sc({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==lh)return;n(()=>({gitStatus:u?.status??null,gitTotals:u?.totals??null,gitLoading:!1,gitError:void 0}))}catch(u){if(l!==lh)return;n(()=>({gitStatus:null,gitTotals:null,gitLoading:!1,gitError:u instanceof Error?u.message:"Git status failed"}))}},async loadGitBranches({agentId:t,projectId:r,source:a,repo:s}){let o=ch(a,e().activeSource),i=Px(s,e().activeRepoRel);if(!t||!o){n(()=>({gitBranches:[]}));return}let l=++uh;try{let u=await z0({agentId:t,...r?{projectId:r}:{},source:o,...i?{repo:i}:{}});if(l!==uh)return;n(()=>({gitBranches:Array.isArray(u?.branches)?u.branches:[]}))}catch(u){if(l!==uh)return;n(()=>({gitBranches:[],gitError:u instanceof Error?u.message:"Git branches failed"}))}}}}var dh=5e4,Or=0,Mx=0,gc=new Set,xc=new Map,fh=new Map,j2=3,vc=new Map;function mh(n){let e=(vc.get(n)??0)+1;return vc.set(n,e),e}function Dx(n,e){return vc.get(n)===e}function hh(n){return{storeKey:n,uri:n,name:yt(n),type:"file",parentUri:nt(n)}}function Tx(n,e,t){let r=nt(e);if(r===e||t.parentUri===r)return t;let a={...t,parentUri:r};return n[e]=a,a}function Fx(n,e,t,r){let a=r?.issuedAt??t,s=r?.pending;for(let o of e.folders||[]){let i=typeof o=="string"?o:typeof o?.uri=="string"?o.uri:"";if(!i)continue;let l=typeof o?.name=="string"?o.name:i.split("/").pop()||"folder",u=o?.presence??"unindexed",c=typeof o?.git=="string"?String(o.git):void 0,d=typeof o?.status=="string"?o.status:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:l,uri:i,type:"folder",parentUri:i.endsWith("://")?void 0:nt(i),lastUpdated:t,presence:u,git:c,status:d};continue}f=Tx(n,i,f),!((f.lastUpdated??0)>=a)&&(f.git!==c||f.presence!==u||f.name!==l||f.status!==d)&&(n[i]={...f,name:l,presence:u,git:c,status:d})}for(let o of e.files||[]){let i=typeof o?.uri=="string"?String(o.uri):"";if(!i)continue;to(n,i,t);let l=typeof o.git=="string"?String(o.git):void 0,u=typeof o.status=="string"?o.status:void 0,c=o.presence??"unindexed",d=typeof o.os_uri=="string"?o.os_uri:void 0,f=n[i];if(!f){n[i]={storeKey:i,name:yt(i),uri:i,type:"file",id:typeof o.id=="string"?o.id:void 0,os_uri:d,status:u,parentUri:nt(i),lastUpdated:t,category:typeof o.category=="string"?o.category:void 0,presence:c,pinned:o.pinned===!0,git:l},s&&u==="pending_review"&&s.add.add(i);continue}if(f=Tx(n,i,f),(f.lastUpdated??0)>=a)continue;let h={...f,name:yt(i)||f.name,presence:c,status:u,os_uri:d,git:l};typeof o.id=="string"&&(h.id=o.id),"category"in o&&(h.category=typeof o.category=="string"?o.category:void 0),"version"in o&&(h.version=o.version),"pinned"in o&&(h.pinned=o.pinned===!0),n[i]=h,s&&f.status!==u&&(u==="pending_review"?s.add.add(i):f.status==="pending_review"&&s.remove.add(i))}}function gh(n,e,t){if(t.add.size===0&&t.remove.size===0)return n;let r=new Set(e);for(let a of t.add)r.add(a);for(let a of t.remove)r.delete(a);return n.pendingReviewPaths=r,n}var q2=4;function V2(n,e){if(n.endsWith("://"))return!0;if(!e.has(n))return!1;for(let t of ba(n))if(!t.endsWith("://")&&!e.has(t))return!1;return!0}function Ex(n,e){return e.some(t=>n===t||n.startsWith(t.endsWith("://")?t:`${t}/`))}function Ox(n,e){let t=n;for(let[r,a]of Object.entries(n))a!==!0||!Ex(r,e)||(t===n&&(t={...n}),t[r]=!1);return t}function yc(n,e){let t=new Set(e),r=Array.from(n.expandedFolders).filter(l=>!t.has(l));r.push(...t);let{kept:a,evicted:s}=pc(r);if(s.length===0)return{expandedFolders:new Set(a)};let o=n.loadedFolders||{},i=Ox(o,s);return i===o?{expandedFolders:new Set(a)}:{expandedFolders:new Set(a),loadedFolders:i}}async function $2(n,e,t){if(n.length===0)return[];let r=Math.max(1,Math.min(e,n.length)),a=new Array(n.length),s=0;return await Promise.all(Array.from({length:r},async()=>{for(;;){let o=s++;if(o>=n.length)return;a[o]=await t(n[o])}})),a}async function K2(n,e){let{agentId:t,projectId:r,source:a,extraTargets:s,wide:o}=e,i=Or,l=n.get(),u=l.loadedFolders||{},c=new Set;if(o)for(let p of Object.keys(u))qe(p)===a&&V2(p,l.expandedFolders)&&c.add(p);for(let p of s)qe(p)===a&&u[p]!==void 0&&c.add(p);let d=p=>{let m=p.indexOf("://"),g=(m>=0?p.slice(m+3):p).replace(/\/+$/,"");return g?g.split("/").length:0},f=Array.from(c).sort((p,m)=>d(m)-d(p));if(f.length===0)return;let h=await $2(f,q2,async p=>{let m=mh(p),g=Date.now();try{let x=await $o(t,r??void 0,{uri:p,recursive:!1});return Dx(p,m)?{folderKey:p,res:x,issuedAt:g,ok:!0}:{folderKey:p,res:null,issuedAt:g,ok:!1}}catch{return{folderKey:p,res:null,issuedAt:g,ok:!1}}});n.set(p=>{if(i!==Or)return p;let m={...p.files},g=Date.now(),x={add:new Set,remove:new Set},b=[],y=!1,N=!1;for(let P of h){if(!P.ok||!P.res){N=!0;continue}Fx(m,P.res,g,{issuedAt:P.issuedAt,pending:x}),P.res.truncated?N=!0:y=!0}let L=N===!!p.dirtySources[a]?p.dirtySources:(()=>{let P={...p.dirtySources};return N?P[a]=!0:delete P[a],P})(),A=p.loadedFolders;for(let P of h)!P.ok||!P.res||A?.[P.folderKey]!==!1||(A===p.loadedFolders&&(A={...A}),A[P.folderKey]=!0);if(!y)return gh({files:xh(m,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:A},p.pendingReviewPaths,x);let w=new Map;for(let P of Object.keys(m)){let O=m[P]?.parentUri;if(!O)continue;let C=w.get(O);C?C.push(P):w.set(O,[P])}for(let P of h){if(!P.ok||!P.res)continue;let O=P.res;if(O.truncated)continue;let C=new Set;for(let I of O.files||[]){let H=typeof I?.uri=="string"?I.uri:"";H&&C.add(H)}for(let I of O.folders||[]){let H=typeof I=="string"?I:typeof I?.uri=="string"?I.uri:"";H&&C.add(H)}for(let I of w.get(P.folderKey)||[]){let H=m[I];if(H&&!C.has(I)&&!((H.lastUpdated??0)>=P.issuedAt)){if(H.type==="folder"){let $=(w.get(I)||[]).filter(M=>m[M]!==void 0);if($.filter(M=>m[M].status!=="deleted").length>0)continue;$.length===0?delete m[I]:H.status!=="deleted"&&(m[I]={...H,status:"deleted",lastUpdated:g});continue}H.presence==="unindexed"?(delete m[I],b.push(I),H.status==="pending_review"&&x.remove.add(I)):H.status!=="deleted"&&(m[I]={...H,status:"deleted",lastUpdated:g},H.status==="pending_review"&&x.remove.add(I))}}}let T={files:xh(m,p.expandedFolders,p.openFiles),dirtySources:L,loadedFolders:A};if(b.length){let P=new Set(b),O=p.openFiles.filter(S=>!P.has(S));T.openFiles=O;let C={...p.tabMeta};for(let S of b)delete C[S];T.tabMeta=C,T.activeFile=p.activeFile&&P.has(p.activeFile)?O.length?O[O.length-1]:null:p.activeFile;let I={...p.fileContentByPath},H={...p.fileBaseContentByPath},q={...p.fileErrorByPath},$={...p.filePrevByPath};for(let S of b)delete I[S],delete H[S],delete q[S],delete $[S];T.fileContentByPath=I,T.fileBaseContentByPath=H,T.fileErrorByPath=q,T.filePrevByPath=$}return gh(T,p.pendingReviewPaths,x)})}async function bc(n,e){let{agentId:t,projectId:r,source:a,targets:s}=e,o=e.wide!==!1;if(!t||!a)return;let i=fh.get(a);if(i){if(i.rerun=!0,o&&(i.wide=!0),s)for(let u of s)i.extra.add(u);await i.promise;return}let l={rerun:!1,wide:o,extra:new Set(s??[]),promise:Promise.resolve()};fh.set(a,l),l.promise=(async()=>{try{for(let u=0;u<j2;u++){l.rerun=!1;let c=l.wide;l.wide=!1;let d=Array.from(l.extra);if(l.extra.clear(),await K2(n,{agentId:t,projectId:r,source:a,extraTargets:d,wide:c}),!l.rerun)break}}finally{fh.delete(a)}})(),await l.promise}function wc(n,e){let t=`${e}/`,r=Object.keys(n.get().files).filter(a=>a===e||a.startsWith(t));r.length!==0&&n.set(a=>{let s={...a.files};for(let h of r)delete s[h];let o=new Set(r),i=a.openFiles.filter(h=>!o.has(h)),l={...a.tabMeta},u={...a.fileContentByPath},c={...a.fileBaseContentByPath},d={...a.fileErrorByPath},f={...a.filePrevByPath};for(let h of r)delete l[h],delete u[h],delete c[h],delete d[h],delete f[h];return{files:s,openFiles:i,activeFile:a.activeFile&&o.has(a.activeFile)?i.length?i[i.length-1]:null:a.activeFile,tabMeta:l,fileContentByPath:u,fileBaseContentByPath:c,fileErrorByPath:d,filePrevByPath:f}})}var X2=30;function xh(n,e,t){let r=Object.keys(n);if(r.length<=dh)return n;let a=new Set;for(let u of e){a.add(u);let c=u;for(;c;){a.add(c);let d=nt(c);if(!d||d===c)break;c=d}}for(let u of t){a.add(u);let c=nt(u);for(;c;){a.add(c);let d=nt(c);if(!d||d===c)break;c=d}}for(let u of r)u.endsWith("://")&&a.add(u);let s=r.filter(u=>{if(a.has(u))return!1;let c=n[u].parentUri;return!(c&&e.has(c))}).map(u=>({key:u,ts:n[u].lastUpdated??0})).sort((u,c)=>u.ts-c.ts),o=r.length-dh;if(o<=0||s.length===0)return n;let i={...n},l=Math.min(o,s.length);for(let u=0;u<l;u++)delete i[s[u].key];return console.warn("[Filesystem] cold-row eviction",{total:r.length,cap:dh,removed:l,protected:r.length-s.length}),i}var Y2="filesystem",cl=120,ph=240,Bx="neuralis.filesystem.sidebarWidth";function J2(){if(typeof window>"u")return ph;try{let n=window.localStorage.getItem(Bx),e=n?Number(n):NaN;return Number.isFinite(e)&&e>=cl?e:ph}catch{return ph}}var _=F0()(E0((n,e)=>({files:{},folderBadges:{},fileContentByPath:{},fileBaseContentByPath:{},fileErrorByPath:{},filePrevByPath:{},openFiles:[],activeFile:null,tabMeta:{},activeUserId:null,contextStateByKey:{},previewEditorsEnabled:!1,expandedFolders:new Set,sidebarOpen:!0,sidebarWidth:J2(),sidebarView:"tree",activeAgentId:null,activeProjectId:null,sources:[],sourcesLoading:!0,activeSource:null,activeRepoRel:"",activeFolderPath:"brain://docs",uploading:!1,workspacePanels:{upload:!1,sources:!1,packages:!1,pending:!1},activeWorkspaceTab:"file",pendingSourceSuggestion:null,vectorHealthOpen:!1,diffViewMode:"auto",pendingPanelFilter:{},loadedFolders:{},hydrationState:{},dirtySources:{},sourceChangeRevision:{},organizeError:null,snapshotError:void 0,pendingReviewPaths:new Set,pendingCount:0,...Lx,...Ix(n,e),...Ax(n,e),...Nx,...Rx(n,e),toggleSidebar:()=>n(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarView:t=>n(()=>({sidebarView:t})),setSidebarWidth:t=>n(()=>{let r=Math.max(cl,Math.round(t));if(typeof window<"u")try{window.localStorage.setItem(Bx,String(r))}catch{}return{sidebarWidth:r}}),setActiveFolderPath:t=>n(()=>({activeFolderPath:t?String(t):null})),setActiveSource:(t,r)=>n(()=>({activeSource:t,activeRepoRel:typeof r=="string"?r:"",gitOutgoingStat:null})),setWorkspacePanelOpen:(t,r)=>n(a=>{let s={upload:!1,sources:!1,packages:!1,pending:!1};r?s[t]=!0:(s.upload=a.workspacePanels.upload,s.sources=a.workspacePanels.sources,s.packages=a.workspacePanels.packages,s.pending=a.workspacePanels.pending,s[t]=!1);let o=r?t:a.activeWorkspaceTab===t?"file":a.activeWorkspaceTab;return{workspacePanels:s,activeWorkspaceTab:o}}),setPendingSourceSuggestion:t=>n(()=>({pendingSourceSuggestion:t})),setVectorHealthOpen:t=>n(()=>({vectorHealthOpen:t})),setActiveWorkspaceTab:t=>n(()=>({activeWorkspaceTab:t})),setDiffViewMode:t=>n(()=>({diffViewMode:t})),setPreviewEditorsEnabled:t=>n(()=>({previewEditorsEnabled:t})),reorderOpenFiles:(t,r)=>n(a=>{if(t===r)return a;let s=[...a.openFiles],o=s.indexOf(t),i=s.indexOf(r);if(o<0||i<0)return a;let[l]=s.splice(o,1);return s.splice(i,0,l),{openFiles:s}}),toggleTabPin:t=>n(r=>{let a=r.tabMeta[t]||{};return{tabMeta:{...r.tabMeta,[t]:{...a,pinned:!a.pinned,preview:!1}}}}),promoteTab:t=>n(r=>{let a=r.tabMeta[t];return!a||!a.preview?r:{tabMeta:{...r.tabMeta,[t]:{...a,preview:!1}}}}),closeAllFiles:()=>n(t=>{let r=t.openFiles.filter(s=>t.tabMeta[s]?.pinned),a=t.activeFile&&r.includes(t.activeFile)?t.activeFile:r[r.length-1]??null;return{openFiles:r,activeFile:a}}),closeSavedFiles:()=>n(t=>{let r=o=>{let i=t.fileBaseContentByPath[o],l=t.fileContentByPath[o];return typeof i=="string"&&i!==l},a=t.openFiles.filter(o=>t.tabMeta[o]?.pinned||r(o)||t.files[o]?.status==="pending_review"),s=t.activeFile&&a.includes(t.activeFile)?t.activeFile:a[a.length-1]??null;return{openFiles:a,activeFile:s}}),closeOtherFiles:t=>n(r=>{let a=r.openFiles.filter(s=>s===t||r.tabMeta[s]?.pinned);return{openFiles:a,activeFile:a.includes(t)?t:a[a.length-1]??null}}),setPendingPanelFilter:t=>n(()=>({pendingPanelFilter:t})),toggleFolder:t=>n(r=>{if(r.expandedFolders.has(t)){let o=new Set(Array.from(r.expandedFolders).filter(u=>!Ex(u,[t]))),i=r.loadedFolders||{},l=Ox(i,[t]);return l===i?{expandedFolders:o}:{expandedFolders:o,loadedFolders:l}}let a=!!r.folderBadges[t],s=a?{...r.folderBadges}:r.folderBadges;return a&&delete s[t],{...yc(r,[t]),folderBadges:s}}),async ensureFolderLoaded({agentId:t,projectId:r,uri:a,force:s}){if(!t||!a)return;let o=e().loadedFolders?.[a];if(!s&&o)return;if(!s&&o===!1){await bc({get:e,set:n},{agentId:t,projectId:r,source:qe(a),targets:[a],wide:!1});return}let i=xc.get(a);if(i){await i;return}n(u=>({hydrationState:{...u.hydrationState||{},[a]:"loading"}}));let l=(async()=>{let u=mh(a),c=Date.now();try{let d=await $o(t,r??void 0,{uri:a,recursive:!1});if(!Dx(a,u)){n(f=>({hydrationState:{...f.hydrationState||{},[a]:f.loadedFolders?.[a]?"ready":"idle"}}));return}n(f=>{let h={...f.files},p={add:new Set,remove:new Set};return Fx(h,d,Date.now(),{issuedAt:c,pending:p}),gh({files:xh(h,f.expandedFolders,f.openFiles),loadedFolders:{...f.loadedFolders||{},[a]:!0},hydrationState:{...f.hydrationState||{},[a]:"ready"}},f.pendingReviewPaths,p)})}catch(d){console.error("[Filesystem] subfolder load failed",d),n(f=>({hydrationState:{...f.hydrationState||{},[a]:"error"}}))}})();xc.set(a,l);try{await l}finally{xc.delete(a)}},clearOrganizeError:()=>n(()=>({organizeError:null})),clearSnapshotError:()=>n(()=>({snapshotError:void 0})),setSourceDirty:(t,r)=>n(a=>{if(!!a.dirtySources[t]===r)return a;let o={...a.dirtySources};return r?o[t]=!0:delete o[t],{dirtySources:o}}),async reconcileSourceFolders({agentId:t,projectId:r,source:a}){await bc({get:e,set:n},{agentId:t,projectId:r,source:a})},fenceInFlightWriters(){Or+=1;for(let t of Array.from(vc.keys()))mh(t);xc.clear(),gc.clear()},resetClientState(t){let r=e();if(!r.activeProjectId||t.projectId!==r.activeProjectId||t.level!=="project"&&t.agentId!==r.activeAgentId||t.level==="widget"&&t.widgetType!==Y2)return;e().fenceInFlightWriters();let a=`${r.activeUserId??""}::${r.activeProjectId}::`,s=ms(r.activeUserId,r.activeProjectId,r.activeAgentId??""),o={};for(let[i,l]of Object.entries(r.contextStateByKey))(t.level==="project"?i.startsWith(a):i===s)||(o[i]=l);n(()=>({...Qo(),contextStateByKey:o}))},async reconcileFolders({agentId:t,projectId:r,folders:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Map,o=e().loadedFolders||{};for(let i of a){if(!i)continue;let l=qe(i);if(!l||o[i]===!1)continue;if(!o[i]){e().setSourceDirty(l,!0);continue}let u=s.get(l);u?u.push(i):s.set(l,[i])}s.size!==0&&await Promise.all(Array.from(s.entries()).map(([i,l])=>bc({get:e,set:n},{agentId:t,projectId:r,source:i,targets:l})))},async refreshTree({agentId:t,projectId:r}){if(!t)return;await e().loadList({agentId:t,projectId:r});let a=e(),s=new Set;for(let[o,i]of Object.entries(a.loadedFolders||{})){if(!i)continue;let l=qe(o);l&&s.add(l)}await Promise.all(Array.from(s).map(o=>bc({get:e,set:n},{agentId:t,projectId:r,source:o})))},setActiveFile:t=>{n({activeFile:t,activeWorkspaceTab:"file"}),e().rehydrateActiveTab()},async rehydrateActiveTab(){let t=e(),r=t.activeFile,a=t.activeAgentId;if(!(!r||!a)&&!hc(t,r)&&!gc.has(r)){gc.add(r);try{let s=t.tabMeta[r]?.sourceAgentId,o=s&&s!==a&&!/^__.*__$/.test(s)?s:void 0;await t.openFile({agentId:a,projectId:t.activeProjectId,uri:r,readAgentId:o,revealPane:!1})}finally{gc.delete(r)}}},closeFile:t=>n(r=>{let a=r.openFiles.filter(i=>i!==t),s=r.activeFile===t?a.length?a[a.length-1]:null:r.activeFile,o={...r.tabMeta};return delete o[t],{openFiles:a,activeFile:s,tabMeta:o}}),replaceFilePath:(t,r)=>n(a=>{if(!t||!r||t===r)return a;let s=a.files[t],o={...a.files};s&&(delete o[t],o[r]={...s,storeKey:r,uri:r,name:yt(r)||s.name,parentUri:nt(r),lastUpdated:Date.now()});let i={...a.fileContentByPath},l={...a.fileBaseContentByPath},u={...a.fileErrorByPath},c={...a.filePrevByPath};Object.prototype.hasOwnProperty.call(i,t)&&(i[r]=i[t],delete i[t]),Object.prototype.hasOwnProperty.call(l,t)&&(l[r]=l[t],delete l[t]),Object.prototype.hasOwnProperty.call(u,t)&&(u[r]=u[t],delete u[t]),Object.prototype.hasOwnProperty.call(c,t)&&(c[r]=c[t],delete c[t]);let d=[];for(let f of a.openFiles){let h=f===t?r:f;d.includes(h)||d.push(h)}return{files:o,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c,openFiles:d,activeFile:a.activeFile===t?r:a.activeFile}}),patchFileNode:(t,r)=>n(a=>{let s=a.files[t];return s?{files:{...a.files,[t]:{...s,...r,lastUpdated:Date.now()}}}:a}),clearFilePrev:t=>n(r=>{if(!r.filePrevByPath[t])return r;let a={...r.filePrevByPath};return delete a[t],{filePrevByPath:a}}),upsertFileNodeFromEvent:({id:t,uri:r,folder_ancestors:a,status:s,sourceAgentId:o,sourceProjectId:i})=>n(l=>{if(!r||!l.files[r]&&s==="deleted")return l;let u=Date.now(),c={...l.files},d=a||ba(r);to(c,r,u);let f=nt(r),h=c[f];h&&h.type==="folder"&&(c[f]={...h,sourceAgentId:o??h.sourceAgentId,sourceProjectId:i??h.sourceProjectId});let p=c[r],m=qe(r)==="brain";c[r]={...p||hh(r),id:t??p?.id,name:yt(r)||p?.name||"file",type:"file",uri:r,status:s??p?.status,parentUri:f,sourceAgentId:o??p?.sourceAgentId,sourceProjectId:i??p?.sourceProjectId,lastUpdated:u,presence:p?.presence??(m?"brain":"synced"),git:p?.git};let g=new Set(l.pendingReviewPaths);if(s==="pending_review"?g.add(r):p?.status==="pending_review"&&s&&s!=="pending_review"&&g.delete(r),s==="active"&&p?.status==="pending_review"&&l.filePrevByPath[r]){let b={...l.filePrevByPath};return delete b[r],{files:c,filePrevByPath:b,pendingReviewPaths:g}}return{files:c,pendingReviewPaths:g}}),removeFilePath:t=>n(r=>{if(!t||!r.files[t]&&!r.openFiles.includes(t)&&!r.tabMeta[t])return r;let a={...r.files};delete a[t];let s=r.openFiles.filter(f=>f!==t),o=r.activeFile===t?s.length?s[s.length-1]:null:r.activeFile,i={...r.fileContentByPath},l={...r.fileBaseContentByPath},u={...r.fileErrorByPath},c={...r.filePrevByPath};delete i[t],delete l[t],delete u[t],delete c[t];let d={...r.tabMeta};return delete d[t],{files:a,openFiles:s,activeFile:o,tabMeta:d,fileContentByPath:i,fileBaseContentByPath:l,fileErrorByPath:u,filePrevByPath:c}}),incrementFolderBadges:t=>n(r=>{if(!Array.isArray(t)||t.length===0)return r;let a={...r.folderBadges};for(let s of t)s&&(r.expandedFolders.has(s)||(a[s]=(a[s]||0)+1));return{folderBadges:a}}),clearFolderBadge:t=>n(r=>{if(!t||!r.folderBadges[t])return r;let a={...r.folderBadges};return delete a[t],{folderBadges:a}}),autoExpandToFile:t=>n(r=>yc(r,[or(t),...ba(t)])),updateFileContent:(t,r)=>n(a=>({fileContentByPath:{...a.fileContentByPath,[t]:r},fileErrorByPath:{...a.fileErrorByPath,[t]:void 0}})),async saveFileInPlace({agentId:t,projectId:r,readAgentId:a,node:s,targetUri:o,content:i,currentContent:l}){let u=s.uri,c=!!o&&o!==u,d=i!==l;if(!c&&!d)return{uri:u,moved:!1,contentChanged:!1};let f=Or,h=()=>f!==Or,p=u;if(c){let m=await Sr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:u,move:o});if(!m||m.ok!==!0)throw new Error(ya(m,"Move failed"));if(p=o,h())return{uri:p,moved:c,contentChanged:!1};e().replaceFilePath(s.storeKey||u,o)}if(d){let m=await Sr({agentId:t,...r?{projectId:r}:{},id:s.id,uri:p,overwrite:{content:i}});if(!m||m.ok!==!0)throw new Error(ya(m,"Save failed"));if(h())return{uri:p,moved:c,contentChanged:d};let g=c?p:s.storeKey||u;e().updateFileContent(g,i),e().patchFileNode(g,{status:"pending_review"})}return await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(new Set([nt(u),nt(p)]))}),h()?{uri:p,moved:c,contentChanged:d}:(await e().openFile({agentId:t,projectId:r,uri:p,readAgentId:a,force:!0}),{uri:p,moved:c,contentChanged:d})},async refreshPendingCount({agentId:t,projectId:r}){if(!t)return;let a=++Mx,s;try{s=await sx({agentId:t,...r?{projectId:r}:{}})}catch{return}if(a!==Mx)return;let o=e();o.activeAgentId!==t||o.activeProjectId!==r||n(()=>({pendingCount:s}))},async markFileDeleted({agentId:t,projectId:r,node:a}){let s=Or,o=await Sr({agentId:t,...r?{projectId:r}:{},id:a.id,uri:a.uri,delete:!0});if(!o||o.ok!==!0)throw new Error(ya(o,"Delete failed"));s===Or&&await e().reconcileFolders({agentId:t,projectId:r,folders:[nt(a.uri)]})},async moveFileToFolder({agentId:t,projectId:r,fromUri:a,toFolderUri:s,id:o}){if(!t||!a||!s)return;let i=yt(a);if(!i)return;let l=s.endsWith("://")?`${s}${i}`:`${s}/${i}`;if(l===a)return;let u=nt(a),c=e().files[a]?.type==="folder",d;try{d=await Sr({agentId:t,...r?{projectId:r}:{},id:o,uri:a,move:l})}catch(h){console.error("[Filesystem] move failed",a,h),n(()=>({organizeError:"Move failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] move rejected",a,d.code,d.error),n(()=>({organizeError:ya(d,"Move rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]});return}let f=d?.warning==="moved_with_source_retained";f&&n(()=>({organizeError:"Copied to the destination, but the original could not be removed \u2014 both copies exist."})),c?(f||wc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:s,force:!0})):(n(h=>{let p=h.openFiles.map(m=>m===a?l:m);return{activeFolderPath:s,openFiles:Array.from(new Set(p)),activeFile:h.activeFile===a?l:h.activeFile}}),f||e().replaceFilePath(a,l)),await e().reconcileFolders({agentId:t,projectId:r,folders:[u,s]})},async renameNode({agentId:t,projectId:r,uri:a,id:s,newName:o}){let i=(o??"").trim();if(!t||!a||!i||i===yt(a))return;let l=nt(a),u=l.endsWith("://")?`${l}${i}`:`${l}/${i}`;if(u===a)return;let c=e().files[a]?.type==="folder",d;try{d=await Sr({agentId:t,...r?{projectId:r}:{},id:s,uri:a,move:c?u:i})}catch(f){console.error("[Filesystem] rename failed",a,f),n(()=>({organizeError:"Rename failed"}));return}if(d&&d.ok===!1){console.error("[Filesystem] rename rejected",a,d.code,d.error),n(()=>({organizeError:ya(d,"Rename rejected")})),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]});return}c?(wc({get:e,set:n},a),await e().ensureFolderLoaded({agentId:t,projectId:r,uri:l,force:!0})):e().replaceFilePath(a,u),await e().reconcileFolders({agentId:t,projectId:r,folders:[l]})},async createNode({agentId:t,projectId:r,parentUri:a,name:s,kind:o}){let i=(s??"").trim();if(!t||!a||!i)return;let l=a.endsWith("://")?`${a}${i}`:`${a}/${i}`,u=Or;try{if(o==="folder"){let c=await Sr({agentId:t,...r?{projectId:r}:{},uri:l,mkdir:!0});c?.ok&&u===Or?n(d=>({...yc(d,[a]),files:{...d.files,[l]:{storeKey:l,name:i,uri:l,type:"folder",parentUri:a,presence:"unindexed",lastUpdated:Date.now()}}})):c&&c.ok===!1&&(console.error("[Filesystem] create folder rejected",l,c.code,c.error),n(()=>({organizeError:ya(c,"Could not create folder")})))}else await uc({agentId:t,...r?{projectId:r}:{},file:new File([""],i),uri:a,tags:[]})}catch(c){console.error("[Filesystem] create failed",o,l,c),n(()=>({organizeError:`Could not create ${o==="folder"?"folder":"file"}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:[a]})},async pasteNodes({agentId:t,projectId:r,targetFolderUri:a,op:s,uris:o}){if(!t||!a||!Array.isArray(o)||o.length===0)return;let i=new Set([a]),l=[];for(let u of o){if(!u)continue;let c=yt(u);if(!c)continue;let d=a.endsWith("://")?`${a}${c}`:`${a}/${c}`;if(d!==u){i.add(nt(u));try{if(s==="copy"){let f=await Sr({agentId:t,...r?{projectId:r}:{},uri:u,copy:d});f&&f.ok===!1&&l.push(c)}else{let f=await Sr({agentId:t,...r?{projectId:r}:{},uri:u,move:d});f&&f.ok===!1?l.push(c):f?.warning==="moved_with_source_retained"?l.push(`${c} (original retained)`):e().files[u]?.type==="folder"&&wc({get:e,set:n},u)}}catch(f){console.error("[Filesystem] paste failed",s,u,f),l.push(c)}}}l.length&&n(()=>({organizeError:`${s==="copy"?"Copy":"Move"} incomplete: ${l.join(", ")}`})),await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(i)})},async deleteNodes({agentId:t,projectId:r,targets:a}){if(!t||!Array.isArray(a)||a.length===0)return;let s=new Set,o=[],i=null;for(let l of a){if(!l?.uri)continue;s.add(nt(l.uri));let u=e().files[l.uri]?.type==="folder";try{let c=await Sr({agentId:t,...r?{projectId:r}:{},id:l.id,uri:l.uri,delete:!0});if(c&&c.ok===!1){console.error("[Filesystem] delete rejected",l.uri,c.code,c.error),o.push(yt(l.uri)||l.uri),(typeof c.affected=="number"||c.failed?.length)&&(i={affected:c.affected,failed:c.failed});continue}u?wc({get:e,set:n},l.uri):e().patchFileNode(l.uri,{status:"deleted"})}catch(c){console.error("[Filesystem] delete failed",l.uri,c),o.push(yt(l.uri)||l.uri)}}if(o.length){let l=i?.failed?.length?` \u2014 ${i.affected??0} removed, could not remove: ${i.failed.slice(0,5).join(", ")}${i.failed.length>5?"\u2026":""}`:"";n(()=>({organizeError:`Delete failed: ${o.join(", ")}${l}`}))}await e().reconcileFolders({agentId:t,projectId:r,folders:Array.from(s)})},async openFile({agentId:t,projectId:r,uri:a,readAgentId:s,force:o,revealPane:i=!0}){if(!t||!a)return;n(d=>{let f=d.openFiles.includes(a),h=d.previewEditorsEnabled&&!f&&!d.tabMeta[a]?.pinned,p=d.openFiles,m=d.tabMeta;if(h){let x=d.openFiles.find(b=>b!==a&&d.tabMeta[b]?.preview&&!d.tabMeta[b]?.pinned);x&&(p=p.filter(b=>b!==x),m={...m},delete m[x]),m={...m,[a]:{...m[a]||{},preview:!0}}}let g=p.includes(a)?p:[...p,a];if(g.length>X2){let x=g.findIndex(b=>b!==a&&!d.tabMeta[b]?.pinned);x>=0&&(g=g.filter((b,y)=>y!==x))}return{openFiles:g,activeFile:a,activeAgentId:t,activeProjectId:r,...i?{activeWorkspaceTab:"file"}:{},tabMeta:m}}),e().autoExpandToFile(a);{let d=new Set([or(a),...ba(a)]);for(let f of d)!f||f===a||e().ensureFolderLoaded({agentId:t,projectId:r,uri:f})}let l=e(),u=typeof l.fileBaseContentByPath[a]=="string"||typeof l.fileContentByPath[a]=="string"&&(l.fileContentByPath[a]?.length||0)>0;if(!o&&u)return;let c=Or;try{let d=await Ko({agentId:s||t,...r?{projectId:r}:{},files:[a]});if(c!==Or)return;let f=Jo(d);if(f.length>0){let h=f[0],p=Zo(h),m=typeof h.error=="string"?h.error:void 0,g=typeof h.code=="string"&&h.code==="not_found";if(m&&g){e().removeFilePath(a);return}let x=typeof h.status=="string"?String(h.status):void 0,b=typeof h.category=="string"?h.category:void 0,y=Array.isArray(h.tags)?h.tags:void 0,N=h.metadata&&typeof h.metadata=="object"?h.metadata:void 0,L=typeof h.createdAt=="string"?h.createdAt:void 0,A=typeof h.updatedAt=="string"?h.updatedAt:void 0,w=h.version&&typeof h.version=="object"?h.version:void 0,v=typeof h.readSource=="string"?h.readSource:void 0,T=typeof h.id=="string"?h.id:void 0,P=typeof h.uri=="string"?String(h.uri):a,O=typeof h.agent_id=="string"?String(h.agent_id):s||t,C=typeof h.project_id=="string"?String(h.project_id):r||void 0,I=qe(P)==="brain",H=w?.sync?.status,q=fc(w?.baseline);n($=>{let S=$.files[P],M=$.fileContentByPath[P],W=$.fileBaseContentByPath[P],ee=m&&typeof M=="string"?M:p,te=m&&typeof W=="string"?W:p,re={...$.files},ce=!!T||!!x||!!w,oe=I?"brain":S?.presence??(ce?"synced":v==="live"?"unindexed":"synced");to(re,P,Date.now());let ue=$.openFiles.includes(P)?$.openFiles:$.openFiles.map(ie=>ie===a?P:ie);return{files:{...re,[P]:{...S||hh(P),id:T??S?.id,name:String(h.filename||S?.name||yt(P)),type:"file",uri:P,parentUri:nt(P),status:x??S?.status,sourceAgentId:O,sourceProjectId:C??S?.sourceProjectId,lastUpdated:S?.lastUpdated??Date.now(),category:b??S?.category,tags:y??S?.tags,metadata:N??S?.metadata,createdAt:L??S?.createdAt,updatedAt:A??S?.updatedAt,version:w??S?.version,presence:oe,readSource:v??S?.readSource}},fileContentByPath:{...$.fileContentByPath,[P]:ee},fileBaseContentByPath:{...$.fileBaseContentByPath,[P]:te},fileErrorByPath:{...$.fileErrorByPath,[P]:m},filePrevByPath:{...$.filePrevByPath,[P]:q},openFiles:Array.from(new Set(ue)),activeFile:P,tabMeta:{...$.tabMeta,[P]:{...$.tabMeta[P]||$.tabMeta[a]||{},name:String(h.filename||S?.name||yt(P)),status:x??S?.status,sourceAgentId:O}}}})}}catch(d){let f=d instanceof Error?d.message:"Read failed";if(console.error("[Filesystem] read failed",d),c!==Or)return;n(h=>({files:{...h.files,[a]:{...h.files[a]||hh(a),sourceAgentId:s||t,sourceProjectId:r||void 0,lastUpdated:h.files[a]?.lastUpdated??Date.now()}},fileErrorByPath:{...h.fileErrorByPath,[a]:f}}))}},async applyNav({agentId:t,projectId:r,nav:a,readAgentId:s,force:o}){if(!t||!a||a.kind!=="filesystem")return;let i=String(a.action||""),l=a.uri;if((i==="read"||i==="open"||i==="modify"||i==="save")&&l){await e().openFile({agentId:t,projectId:r,uri:l,readAgentId:s,force:o});return}if(i==="open-pending"){n(()=>({activeAgentId:t,activeProjectId:r})),e().setPendingPanelFilter(a.filter??{}),e().setWorkspacePanelOpen("pending",!0);return}if(i==="open-sources"||i==="open-vector-health"){n(()=>({activeAgentId:t,activeProjectId:r,...i==="open-vector-health"?{vectorHealthOpen:!0}:{}})),e().setWorkspacePanelOpen("sources",!0);return}i==="list"&&l&&n(u=>{let c=or(l),d=u.expandedFolders.has(l)&&u.expandedFolders.has(c),f=u.activeAgentId===t,h=u.activeProjectId===r;return d&&f&&h?u:{...yc(u,[c,l]),activeAgentId:t,activeProjectId:r}})},async upload({agentId:t,projectId:r,file:a,uri:s}){if(!t)return;let o=s||"brain://docs";n(()=>({uploading:!0}));try{await uc({agentId:t,...r?{projectId:r}:{},file:a,uri:o,tags:["upload"]}),await e().reconcileFolders({agentId:t,projectId:r,folders:[o]})}finally{n(()=>({uploading:!1}))}},async uploadMany({agentId:t,projectId:r,files:a,uri:s}){if(!t)return;let o=Array.isArray(a)?a.filter(Boolean):[];if(o.length===0)return;let i=s||"brain://docs";n(()=>({uploading:!0}));try{for(let l of o)await uc({agentId:t,...r?{projectId:r}:{},file:l,uri:i,tags:["upload"]});await e().reconcileFolders({agentId:t,projectId:r,folders:[i]})}finally{n(()=>({uploading:!1}))}}}),{name:"neuralis.filesystem.tabs",version:2,migrate:(n,e)=>{if(e>=2)return n;let t=n??{},r=t.activeAgentId?ms(null,t.activeProjectId??null,t.activeAgentId):null;return{previewEditorsEnabled:t.previewEditorsEnabled??!1,diffViewMode:t.diffViewMode??"auto",activeUserId:null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,contexts:r?{[r]:mc({...Qo(),openFiles:t.openFiles??[],activeFile:t.activeFile??null,tabMeta:t.tabMeta??{}})}:{}}},merge:(n,e)=>{let t=n;if(!t)return e;let r=t.contexts??{},a=t.activeAgentId?ms(t.activeUserId??null,t.activeProjectId??null,t.activeAgentId):null,s={};for(let[i,l]of Object.entries(r))i!==a&&(s[i]=ih(l));let o=a&&r[a]?ih(r[a]):{};return{...e,previewEditorsEnabled:t.previewEditorsEnabled??e.previewEditorsEnabled,diffViewMode:t.diffViewMode??e.diffViewMode,activeUserId:t.activeUserId??null,activeAgentId:t.activeAgentId??null,activeProjectId:t.activeProjectId??null,...o,contextStateByKey:s}},storage:Qf(()=>typeof window<"u"&&window.localStorage?window.localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}}),partialize:n=>{let e={};for(let[t,r]of Object.entries(n.contextStateByKey))e[t]=mc(r);return n.activeAgentId&&(e[ms(n.activeUserId,n.activeProjectId,n.activeAgentId)]=mc(n)),{previewEditorsEnabled:n.previewEditorsEnabled,diffViewMode:n.diffViewMode,activeUserId:n.activeUserId,activeAgentId:n.activeAgentId,activeProjectId:n.activeProjectId,contexts:e}}}));var Wl=j(wr(),1);var kc=j(Ve(),1);var _x=n=>n?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function Hx(n,e,t=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:_x(n),size:24,node:e,...t.length>0?{aliases:t}:{}}}var Ux=n=>{let e="",t=!1;for(let r of n){if(r==="-"||r==="_"||r<=" "){t=e.length>0;continue}e.length===0?e+=r.toLowerCase():e+=t?r.toUpperCase():r,t=!1}return e};var Gx=n=>{let e=Ux(n);return e.charAt(0).toUpperCase()+e.slice(1)};var fl=j(Ve(),1);var dl=(...n)=>n.filter((e,t,r)=>!!e&&e.trim()!==""&&r.indexOf(e)===t).join(" ").trim();var gs={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function yh(n){return n!=null}function zx(n,e={}){let t=e.attributeNames??{},r=f=>t[f]??f,a=n.size??n.width??gs.width,s=n.size??n.height??gs.height,o=n.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],i=[...n.name?[`lucide-${n.name}`]:[],...o],l=e.className?.split(" ").filter(Boolean)??[],u=e.includeDefaultClasses===!1?dl(...l):dl("lucide",...i,...l),c=e.absoluteStrokeWidth?Number(e.strokeWidth??gs["stroke-width"])*Number(n.size??n.width??gs.width)/Number(e.size??e.width??gs.width):e.strokeWidth??gs["stroke-width"];return["svg",{...Object.entries(gs).reduce((f,[h,p])=>(f[r(h)]=p,f),{}),..."color"in e&&e.color&&{[r("stroke")]:e.color},..."size"in e&&yh(e.size)&&{[r("width")]:e.size,[r("height")]:e.size},..."width"in e&&yh(e.width)&&{[r("width")]:e.width},..."height"in e&&yh(e.height)&&{[r("height")]:e.height},[r("stroke-width")]:c,...u&&{[r("class")]:u},[r("viewBox")]:`0 0 ${a} ${s}`,...e.hasA11yProp===!1?{[r("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},n.node.map(f=>{let[h,p,m]=f,g=e.nonScalingStroke?{[r("vector-effect")]:"non-scaling-stroke",...p}:p;return m?[h,g,m]:[h,g]})]}function Wx(n,e={}){return zx(n,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}var jx=n=>{for(let e in n)if(e.startsWith("aria-")||e==="role"||e==="title")return!0;return!1};var ei=j(Ve(),1);var Z2=(0,ei.createContext)({});var qx=()=>(0,ei.useContext)(Z2);var Vx=(0,fl.forwardRef)(({color:n,size:e,width:t,height:r,strokeWidth:a,absoluteStrokeWidth:s,nonScalingStroke:o,className:i="",children:l,iconNode:u=[],icon:c={node:u,aliases:[],size:24},...d},f)=>{let{size:h=24,strokeWidth:p=2,absoluteStrokeWidth:m=!1,nonScalingStroke:g=!1,color:x="currentColor",className:b=""}=qx()??{},y=!!l||jx(d),[N,L,A=[]]=Wx(c,{color:n??x,width:t??e??h,height:r??e??h,strokeWidth:a??p,absoluteStrokeWidth:s??m,nonScalingStroke:o??g,className:dl(b,i),hasA11yProp:y,attributes:d});return(0,fl.createElement)(N,{ref:f,...L},[...A.map(([w,v])=>(0,fl.createElement)(w,v)),...Array.isArray(l)?l:[l]])});function G(n,e=[],t=[]){let r=typeof n=="string"?Hx(n,e,t):n,a=(0,kc.forwardRef)(({className:s,...o},i)=>(0,kc.createElement)(Vx,{ref:i,icon:r,className:s,...o}));return r.name&&(a.displayName=Gx(r.name)),a}var $x={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};$x.node;var ti=G($x);var Kx={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};Kx.node;var hl=G(Kx);var Xx={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};Xx.node;var ni=G(Xx);var Yx={name:"arrow-up-down",size:24,node:[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]};Yx.node;var pl=G(Yx);var Jx={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};Jx.node;var ml=G(Jx);var Zx={name:"bot",size:24,node:[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]};Zx.node;var gl=G(Zx);var Qx={name:"braces",size:24,node:[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],aliases:["curly-braces"]};Qx.node;var wa=G(Qx);var ey={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};ey.node;var xs=G(ey);var ty={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};ty.node;var Mn=G(ty);var ny={name:"chevron-down",size:24,node:[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]};ny.node;var Tt=G(ny);var ry={name:"chevron-left",size:24,node:[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]};ry.node;var xl=G(ry);var ay={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};ay.node;var un=G(ay);var sy={name:"chevron-up",size:24,node:[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]};sy.node;var $a=G(sy);var oy={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};oy.node;var ys=G(oy);var iy={name:"circle-check",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 9-5.5 5.5L8 12",key:"xofnsj"}]],aliases:["check-circle-2"]};iy.node;var na=G(iy);var ly={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};ly.node;var ra=G(ly);var uy={name:"circle-x",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],aliases:["x-circle"]};uy.node;var aa=G(uy);var cy={name:"clipboard-paste",size:24,node:[["path",{d:"M11 14h10",key:"1w8e9d"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v1.344",key:"1e62lh"}],["path",{d:"m17 18 4-4-4-4",key:"z2g111"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113",key:"bjbb7m"}],["rect",{x:"8",y:"2",width:"8",height:"4",rx:"1",key:"ublpy"}]]};cy.node;var yl=G(cy);var dy={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};dy.node;var va=G(dy);var fy={name:"cloud",size:24,node:[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]};fy.node;var bl=G(fy);var hy={name:"cloud-upload",size:24,node:[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],aliases:["upload-cloud"]};hy.node;var Br=G(hy);var py={name:"columns-2",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],aliases:["columns"]};py.node;var bs=G(py);var my={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};my.node;var sa=G(my);var gy={name:"corner-up-right",size:24,node:[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M4 20v-7a4 4 0 0 1 4-4h12",key:"1lu4f8"}]]};gy.node;var wl=G(gy);var xy={name:"database",size:24,node:[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]};xy.node;var ir=G(xy);var yy={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};yy.node;var ws=G(yy);var by={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};by.node;var vl=G(by);var wy={name:"file-code",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]]};wy.node;var kl=G(wy);var vy={name:"file-code-corner",size:24,node:[["path",{d:"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35",key:"1wthlu"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m5 16-3 3 3 3",key:"331omg"}],["path",{d:"m9 22 3-3-3-3",key:"lsp7cz"}]],aliases:["file-code-2"]};vy.node;var Ka=G(vy);var ky={name:"file-diff",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]};ky.node;var Xa=G(ky);var Sy={name:"file-exclamation-point",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["file-warning"]};Sy.node;var vs=G(Sy);var Cy={name:"file-image",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]};Cy.node;var Sl=G(Cy);var Ly={name:"file-pen",size:24,node:[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],aliases:["file-edit"]};Ly.node;var ks=G(Ly);var Iy={name:"file-play",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],aliases:["file-video"]};Iy.node;var Ss=G(Iy);var Ay={name:"file-plus-corner",size:24,node:[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]],aliases:["file-plus-2"]};Ay.node;var Cs=G(Ay);var Py={name:"file-plus",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]};Py.node;var Ls=G(Py);var Ny={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Ny.node;var ka=G(Ny);var Ry={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};Ry.node;var Cl=G(Ry);var My={name:"folder-open",size:24,node:[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]};My.node;var Is=G(My);var Ty={name:"folder-plus",size:24,node:[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Ty.node;var Cr=G(Ty);var Dy={name:"folder-tree",size:24,node:[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]};Dy.node;var Ll=G(Dy);var Fy={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};Fy.node;var _r=G(Fy);var Ey={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};Ey.node;var Sn=G(Ey);var Oy={name:"git-commit-horizontal",size:24,node:[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]],aliases:["git-commit"]};Oy.node;var Hr=G(Oy);var By={name:"git-compare-arrows",size:24,node:[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]};By.node;var lr=G(By);var _y={name:"git-compare",size:24,node:[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["path",{d:"M11 18H8a2 2 0 0 1-2-2V9",key:"19pyzm"}]]};_y.node;var ri=G(_y);var Hy={name:"hard-drive",size:24,node:[["path",{d:"M10 16h.01",key:"1bzywj"}],["path",{d:"M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"18tbho"}],["path",{d:"M21.946 12.013H2.054",key:"zqlbp7"}],["path",{d:"M6 16h.01",key:"1pmjb7"}]]};Hy.node;var Un=G(Hy);var Uy={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};Uy.node;var Il=G(Uy);var Gy={name:"link-2",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]};Gy.node;var Al=G(Gy);var zy={name:"link-2-off",size:24,node:[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]};zy.node;var Pl=G(zy);var Wy={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Wy.node;var no=G(Wy);var jy={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};jy.node;var We=G(jy);var qy={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};qy.node;var ro=G(qy);var Vy={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};Vy.node;var ao=G(Vy);var $y={name:"mouse-pointer-click",size:24,node:[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]};$y.node;var Nl=G($y);var Ky={name:"move-right",size:24,node:[["path",{d:"M18 8L22 12L18 16",key:"1r0oui"}],["path",{d:"M2 12H22",key:"1m8cig"}]]};Ky.node;var Rl=G(Ky);var Xy={name:"music-4",size:24,node:[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["path",{d:"m9 9 12-2",key:"1e64n2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]]};Xy.node;var Ml=G(Xy);var Yy={name:"network",size:24,node:[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]};Yy.node;var Tl=G(Yy);var Jy={name:"package",size:24,node:[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]};Jy.node;var Lr=G(Jy);var Zy={name:"panel-left",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],aliases:["sidebar"]};Zy.node;var As=G(Zy);var Qy={name:"pen-line",size:24,node:[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],aliases:["edit-3"]};Qy.node;var Ps=G(Qy);var eb={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};eb.node;var so=G(eb);var tb={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};tb.node;var oo=G(tb);var nb={name:"play",size:24,node:[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]};nb.node;var Dl=G(nb);var rb={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};rb.node;var Tn=G(rb);var ab={name:"radio",size:24,node:[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};ab.node;var Ya=G(ab);var sb={name:"refresh-ccw",size:24,node:[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]};sb.node;var Sa=G(sb);var ob={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};ob.node;var Ot=G(ob);var ib={name:"rotate-ccw",size:24,node:[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]};ib.node;var io=G(ib);var lb={name:"save",size:24,node:[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]};lb.node;var lo=G(lb);var ub={name:"scan-search",size:24,node:[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"m16 16-1.9-1.9",key:"1dq9hf"}]]};ub.node;var Ja=G(ub);var cb={name:"scissors",size:24,node:[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]};cb.node;var Fl=G(cb);var db={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};db.node;var El=G(db);var fb={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};fb.node;var ai=G(fb);var hb={name:"shield-alert",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]};hb.node;var Ca=G(hb);var pb={name:"shield-check",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]};pb.node;var si=G(pb);var mb={name:"shield-off",size:24,node:[["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71",key:"1jlk70"}],["path",{d:"M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264",key:"18rp1v"}]]};mb.node;var Ol=G(mb);var gb={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};gb.node;var Ns=G(gb);var xb={name:"sigma",size:24,node:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]};xb.node;var Bl=G(xb);var yb={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};yb.node;var uo=G(yb);var bb={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};bb.node;var _l=G(bb);var wb={name:"tag",size:24,node:[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]};wb.node;var Hl=G(wb);var vb={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};vb.node;var oi=G(vb);var kb={name:"text-align-justify",size:24,node:[["path",{d:"M3 5h18",key:"1u36vt"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 19h18",key:"awlh7x"}]],aliases:["align-justify"]};kb.node;var Rs=G(kb);var Sb={name:"trash",size:24,node:[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],aliases:["trash-2"]};Sb.node;var It=G(Sb);var Cb={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};Cb.node;var ct=G(Cb);var Lb={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};Lb.node;var La=G(Lb);var Ib={name:"unfold-vertical",size:24,node:[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m15 5-3-3-3 3",key:"itvq4r"}]]};Ib.node;var Ul=G(Ib);var Ab={name:"unlink",size:24,node:[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]};Ab.node;var Gl=G(Ab);var Pb={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};Pb.node;var Ia=G(Pb);var Nb={name:"wand-sparkles",size:24,node:[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],aliases:["wand-2"]};Nb.node;var Ms=G(Nb);var Rb={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Rb.node;var co=G(Rb);var Mb={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};Mb.node;var Bt=G(Mb);var Tb={name:"zap",size:24,node:[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]]};Tb.node;var zl=G(Tb);var Kt=j(le(),1);function wh(n){let{agentId:e,agentName:t,agentIcon:r,agentAccent:a,supportsSources:s=!0}=n,o=(0,Wl.resolveAgentIcon)(r),i=_(g=>g.toggleSidebar),l=_(g=>g.sidebarOpen),u=_(g=>g.refreshTree),c=_(g=>g.activeProjectId),d=_(g=>g.uploading),f=_(g=>g.workspacePanels),h=_(g=>g.setWorkspacePanelOpen),p=_(g=>g.activeWorkspaceTab),m=_(g=>g.pendingCount);return(0,Kt.jsxs)("div",{className:"h-10 flex items-center px-3 shrink-0 gap-2.5",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Kt.jsx)("div",{className:"flex items-center gap-1",children:(0,Kt.jsx)("button",{onClick:i,className:`p-1.5 rounded-lg transition-colors ${l?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white"}`,title:"Toggle Sidebar",children:(0,Kt.jsx)(As,{className:"w-4 h-4"})})}),(0,Kt.jsx)("div",{className:"h-4 w-[1px] bg-white/10"}),(0,Kt.jsx)("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center",style:{color:a||"var(--icon-muted)"},title:t||"Agent","aria-label":t||"Agent",children:(0,Kt.jsx)(o,{className:"h-4 w-4"})}),(0,Kt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,Kt.jsx)("button",{onClick:()=>u({agentId:e,projectId:c??null}),className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors",title:"Refresh",children:(0,Kt.jsx)(Ot,{className:"w-4 h-4"})}),(0,Kt.jsx)("button",{className:"p-1.5 rounded-lg text-white/50 hover:bg-white/5 hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Upload files",disabled:d,onClick:()=>{if(f.upload&&p==="upload"){h("upload",!1);return}h("upload",!0)},children:d?(0,Kt.jsx)(We,{className:"w-4 h-4 animate-spin"}):(0,Kt.jsx)(Ia,{className:"w-4 h-4"})}),s?(0,Kt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.sources&&p==="sources"?"bg-cyan-500/15 text-cyan-400":"text-white/50 hover:bg-white/5 hover:text-cyan-300"}`,title:"Data Sources & Sync",onClick:()=>{if(f.sources&&p==="sources"){h("sources",!1);return}h("sources",!0)},children:(0,Kt.jsx)(ir,{className:"w-4 h-4"})}):null,s?(0,Kt.jsx)(Wl.SkillLauncher,{variant:"icon",size:"sm",skill:"sync",packageId:"@neuralis/brain-core",label:"Sync sources with the agent",icon:"brain"}):null,(0,Kt.jsx)(Wl.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/mkdir.sh","scripts/copy.sh","scripts/modify.sh","scripts/search.sh"],label:"Create, copy, edit or search files with the agent",icon:"Folder"}),(0,Kt.jsx)("button",{className:`p-1.5 rounded-lg transition-colors ${f.packages&&p==="packages"?"bg-violet-500/15 text-violet-300":"text-white/50 hover:bg-white/5 hover:text-violet-200"}`,title:"Packages \u2014 trust & build",onClick:()=>{if(f.packages&&p==="packages"){h("packages",!1);return}h("packages",!0)},children:(0,Kt.jsx)(Lr,{className:"w-4 h-4"})}),(0,Kt.jsxs)("button",{className:`relative p-1.5 rounded-lg transition-colors ${f.pending&&p==="pending"?"bg-amber-500/15 text-amber-300":"text-white/50 hover:bg-white/5 hover:text-amber-200"}`,title:m>0?`Pending changes \u2014 ${m} to review`:"Pending changes \u2014 review, approve & revert",onClick:()=>{if(f.pending&&p==="pending"){h("pending",!1);return}h("pending",!0)},children:[(0,Kt.jsx)(Xa,{className:"w-4 h-4"}),m>0?(0,Kt.jsx)("span",{"data-testid":"pending-count-badge",className:"absolute -top-1 -right-1 min-w-[14px] rounded-full px-1 text-center text-[9px] leading-[14px] font-semibold bg-amber-500/15 text-amber-300",children:m>=1e3?"1000+":m}):null]})]})]})}var Ue=j(Ve(),1),E1=j(wr(),1);function Za(n,e){let t=n.grantedFeatures;return t?t.includes("*")||t.includes(e):!1}function ii(n,e){let t=e?.features;return!t||t.length===0?!0:t.every(r=>Za(n,r))}var vh={owner:1,admin:2,manager:10,member:20,viewer:30};var Q2=vh.member,Eb=Number.MAX_SAFE_INTEGER;var oa=j(Ve(),1),$b=j(Qa(),1);function Hb(n){return typeof n=="object"?n.key:n}function Ub(n,e){let t=n.length;return new Proxy(n,{get(r,a,s){if(typeof a=="string"){let o=a.charCodeAt(0);if(o>=48&&o<=57){let i=+a;if(Number.isInteger(i)&&i>=0&&i<t){let l=r[i];if(typeof l!="object"){let u=e[i*2];l=r[i]={index:i,key:l,start:u,size:e[i*2+1],end:u+e[i*2+1],lane:0}}return l}}if(a==="length")return t}return Reflect.get(r,a,s)}})}function fo(n,e,t){let r=t.initialDeps??[],a,s=!0;function o(){var i;let u=0,c=n();if(!(c.length!==r.length||c.some((h,p)=>r[p]!==h)))return a;r=c;let f=0;return a=e(...c),t?.onChange&&!(s&&t.skipInitialOnChange)&&t.onChange(a),s=!1,a}return o.updateDeps=i=>{r=i},o}function Sh(n,e){if(n===void 0)throw new Error(`Unexpected undefined${e?`: ${e}`:""}`);return n}var Ch=(n,e)=>Math.abs(n-e)<1.01,Gb=(n,e,t)=>{let r;return Object.assign(function(...a){n.clearTimeout(r),r=n.setTimeout(()=>e.apply(this,a),t)},{cancel:()=>{n.clearTimeout(r)}})};var jl,Lh=()=>{if(jl!==void 0)return jl;if(typeof navigator>"u")return jl=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return jl=!0;let n=navigator.maxTouchPoints;return jl=navigator.platform==="MacIntel"&&n!==void 0&&n>0};var zb=n=>{let{offsetWidth:e,offsetHeight:t}=n;return{width:e,height:t}},oA=n=>n,iA=n=>{let e=Math.max(n.startIndex-n.overscan,0),r=Math.min(n.endIndex+n.overscan,n.count-1)-e+1,a=new Array(r);for(let s=0;s<r;s++)a[s]=e+s;return a},Wb=(n,e)=>{let t=n.scrollElement;if(!t)return;let r=n.targetWindow;if(!r)return;let a=o=>{let{width:i,height:l}=o;e({width:Math.round(i),height:Math.round(l)})};if(a(zb(t)),!r.ResizeObserver)return()=>{};let s=new r.ResizeObserver(o=>{let i=()=>{let l=o[0];if(l?.borderBoxSize){let u=l.borderBoxSize[0];if(u){a({width:u.inlineSize,height:u.blockSize});return}}a(zb(t))};n.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(i):i()});return s.observe(t,{box:"border-box"}),()=>{s.unobserve(t)}},Sc={passive:!0};var lA=typeof window>"u"?!0:"onscrollend"in window,uA=(n,e,t)=>{let r=n.scrollElement;if(!r)return;let a=n.targetWindow;if(!a)return;let s=n.options.useScrollendEvent&&lA,o=0,i=s?null:Gb(a,()=>e(t(r),!1),n.options.isScrollingResetDelay),l=d=>()=>{o=t(r),i?.(),e(o,d)},u=l(!0),c=l(!1);return r.addEventListener("scroll",u,Sc),s&&r.addEventListener("scrollend",c,Sc),()=>{r.removeEventListener("scroll",u),s&&r.removeEventListener("scrollend",c),i?.cancel()}},jb=(n,e)=>uA(n,e,t=>{let{horizontal:r,isRtl:a}=n.options;return r?t.scrollLeft*(a&&-1||1):t.scrollTop});var cA=(n,e,t)=>{if(t.options.useCachedMeasurements){let r=t.indexFromElement(n),a=t.options.getItemKey(r);return t.itemSizeCache.get(a)??t.options.estimateSize(r)}if(e?.borderBoxSize){let r=e.borderBoxSize[0];if(r)return Math.round(r[t.options.horizontal?"inlineSize":"blockSize"])}if(!e){let r=t.indexFromElement(n),a=t.options.getItemKey(r),s=t.itemSizeCache.get(a);if(s!==void 0)return s}return n[t.options.horizontal?"offsetWidth":"offsetHeight"]},dA=(n,{adjustments:e=0,behavior:t},r)=>{var a,s;(s=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||s.call(a,{[r.options.horizontal?"left":"top"]:n+e,behavior:t})};var qb=dA;function fA(n,e,t,r){if(e===0)return!1;let a=r(0),s=new Set,o=0;for(;o<n;){let l=t(o);if(l===a)break;s.add(l),o++}let i=n-o;if(i===0||i>=e)return!1;for(let l=0;l<i;l++)if(r(l)!==t(o+l))return!1;for(let l=i;l<e;l++)if(s.has(r(l)))return!1;return!0}var Cc=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this._clampedAdjustment=null,this.elementsCache=new Map,this.now=()=>{var t,r,a;return((a=(r=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let t=null,r=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(a=>{a.forEach(s=>{let o=()=>{let i=s.target,l=this.indexFromElement(i);if(!i.isConnected){this.observer.unobserve(i);for(let[u,c]of this.elementsCache)if(c===i){this.elementsCache.delete(u);break}return}this.isIndexInRange(l)&&this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(i,s,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),t=null},observe:a=>{var s;return(s=r())==null?void 0:s.observe(a,{box:"border-box"})},unobserve:a=>{var s;return(s=r())==null?void 0:s.unobserve(a)}}})(),this.range=null,this.setOptions=t=>{var r;let a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:oA,rangeExtractor:iA,onChange:()=>{},measureElement:cA,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(let d in t){let f=t[d];f!==void 0&&(a[d]=f)}let s=this.options,o=null,i=null,l=!1;if(s!==void 0&&s.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){let d=s.count,f=a.count,h=this.getMeasurements(),p=((r=this._singleLaneMeasurements)==null?void 0:r.items)??h,m=N=>Hb(p[N]),g=d>0?m(0):null,x=d>0?m(d-1):null;if(f!==d||d>0&&f>0&&(a.getItemKey(0)!==g||a.getItemKey(f-1)!==x)){l=!0;let N=d>0?this.getVirtualItemForOffset(this.getScrollOffset())??h[0]:null;N&&(o=[N.key,this.getScrollOffset()-N.start]);let L=a.followOnAppend===!0?"auto":a.followOnAppend||null;L&&f>0&&this.isAtEnd(s.scrollEndThreshold)&&(d===0||a.getItemKey(f-1)!==x)&&(f>d||fA(d,f,m,a.getItemKey))&&(i=L)}}this.options=a,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,c=0;if(o&&this.scrollOffset!==null){let[d,f]=o,h=this.getMeasurements(),{count:p,getItemKey:m}=this.options,g=0;for(;g<p&&m(g)!==d;)g++;if(g<p){let x=h[g];if(x){let b=Math.max(0,x.start+f);!i&&b!==this.scrollOffset&&(c=b-this.scrollOffset,this.scrollOffset=b,u=!0)}}}(u||i)&&(this.pendingScrollAnchor=[u?o[0]:null,u?o[1]:0,i,c])},this.notify=t=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,t)},this.maybeNotify=fo(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._clampedAdjustment=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t,r;let a=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==a){if(this.cleanup(),!a){this.maybeNotify();return}if(this.scrollElement=a,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,i)=>{if(i&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this._clampedAdjustment!==null&&Math.abs(o-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null),this.scrollAdjustments=0;let l=this.getScrollOffset();this.scrollDirection=i?l===o?this.scrollDirection:l<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=i,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){let o=this.scrollElement,i=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},l=()=>{this._iosTouching=!1,!(!Lh()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",i,Sc),o.addEventListener("touchend",l,Sc),this.unsubs.push(()=>{o.removeEventListener("touchstart",i),o.removeEventListener("touchend",l),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let s=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled){let[o,i,l,u]=s;o!==null&&!l&&(Lh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?u!==0&&(this._iosDeferredAdjustment+=u):((r=this.scrollState)==null?void 0:r.behavior)==="smooth"&&!Ch(this.getScrollOffset()-u,this.scrollState.lastTargetOffset)||this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),l&&this.scrollToEnd({behavior:l})}this._retryClampedAdjustment()},this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:t,maxAtWrite:r}=this._clampedAdjustment,a=this.getMaxScrollOffset();a>r+.5&&(this._clampedAdjustment=t>a+.5?{target:t,maxAtWrite:a}:null,this._scrollToOffset(t,{adjustments:void 0,behavior:void 0}))},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let t=this.getScrollOffset(),r=this.getMaxScrollOffset();if(t<0||t>r)return;if(this._iosDeferredAdjustment<0&&t>=r-1){this._iosDeferredAdjustment=0;return}let a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(t,{adjustments:this.scrollAdjustments+=a,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=fo(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(t,r,a,s,o,i,l,u)=>(this.prevLanes!==void 0&&this.prevLanes!==i&&(this.lanesChangedFlag=!0),this.prevLanes=i,this.pendingMin=null,{count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u}),{key:!1}),this.isIndexInRange=t=>t>=0&&t<this.options.count,this.getMeasurements=fo(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:t,paddingStart:r,scrollMargin:a,getItemKey:s,enabled:o,lanes:i,laneAssignmentMode:l,gap:u},c)=>{var d;let f=this.itemSizeCache;if(!o)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(let b of this.laneAssignments.keys())b>=t&&this.laneAssignments.delete(b);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(b=>{this.itemSizeCache.set(b.key,b.size)}));let h=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),i===1){let b=t*2,y=(d=this._singleLaneMeasurements)==null?void 0:d.flat;if(!y||y.length<b){let w=new Float64Array(b);y&&h>0&&w.set(y.subarray(0,h*2)),y=w}let N=h===0?new Array(t):this._singleLaneMeasurements.items.slice(),L;if(h===0)L=r+a;else{let w=h-1;L=y[w*2]+y[w*2+1]+u}for(let w=h;w<t;w++){let v=s(w);N[w]=v;let T=f.get(v),P=typeof T=="number"?T:this.options.estimateSize(w);y[w*2]=L,y[w*2+1]=P,L+=P+u}this._singleLaneMeasurements={flat:y,items:N};let A=Ub(N,y);return this.measurementsCache=A,A}let p=this.measurementsCache.slice(0,h),m=new Array(i).fill(void 0),g=new Float64Array(i),x=0;for(let b=0;b<h;b++){let y=p[b];y&&(m[y.lane]===void 0&&x++,m[y.lane]=b,g[y.lane]=y.end)}for(let b=h;b<t;b++){let y=s(b),N=this.laneAssignments.get(b),L,A,w=l==="estimate"||f.has(y);if(N!==void 0&&this.options.lanes>1){L=N;let O=m[L],C=O!==void 0?p[O]:void 0;A=C?C.end+u:r+a}else if(x===i){let O=0,C=g[0],I=m[0];for(let H=1;H<i;H++){let q=g[H];(q<C||q===C&&m[H]<I)&&(O=H,C=q,I=m[H])}L=O,A=C+u,w&&this.laneAssignments.set(b,L)}else L=b%this.options.lanes,A=r+a,w&&this.laneAssignments.set(b,L);let v=f.get(y),T=typeof v=="number"?v:this.options.estimateSize(b),P=A+T;p[b]={index:b,start:A,size:T,end:P,key:y,lane:L},m[L]===void 0&&x++,m[L]=b,g[L]=P}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=fo(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,r,a,s)=>t.length===0||r===0?(this.range=null,null):(this.range=pA(t,r,a,s,s===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=fo(()=>{let t=null,r=null,a=this.calculateRange();return a&&(t=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,r]},(t,r,a,s,o)=>s===null||o===null?[]:t({startIndex:s,endIndex:o,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{let r=this.options.indexAttribute,a=t.getAttribute(r);return a?parseInt(a,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;let a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){let s=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),o=Math.max(0,a-s),i=Math.min(this.options.count-1,a+s);return t>=o&&t<=i}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((o,i)=>{o.isConnected||(this.observer.unobserve(o),this.elementsCache.delete(i))});return}let r=this.indexFromElement(t);if(!this.isIndexInRange(r))return;let a=this.options.getItemKey(r),s=this.elementsCache.get(a);s!==t&&(s&&this.observer.unobserve(s),this.observer.observe(t),this.elementsCache.set(a,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,r)=>{var a,s,o;if(!this.isIndexInRange(t))return;let i,l,u,c=(a=this._singleLaneMeasurements)==null?void 0:a.flat;if(this.options.lanes===1&&c!=null)u=this.options.getItemKey(t),l=c[t*2],i=c[t*2+1];else{let h=this.measurementsCache[t];if(!h)return;u=h.key,l=h.start,i=h.size}let d=this.itemSizeCache.get(u)??i,f=r-d;if(f!==0){let h=this.options.anchorTo==="end"&&((s=this.scrollState)==null?void 0:s.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=h?this.getTotalSize():0,m=this.getScrollOffset()+this.scrollAdjustments,x=!this.itemSizeCache.has(u)?l<m:l+d<=m&&this.scrollDirection!=="backward",b=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:u,start:l,size:i,end:l+i,lane:0},f,this):x);(this.pendingMin===null||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(u,r),this.itemSizeCacheVersion++;let y=!1;h?y=this.applyScrollAdjustment(this.getTotalSize()-p):b&&(y=this.applyScrollAdjustment(f)),this.notify(y),this._retryClampedAdjustment()}},this.getVirtualItems=fo(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,r)=>{let a=[];for(let s=0,o=t.length;s<o;s++){let i=t[s],l=r[i];a.push(l)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{var r;let a=this.getMeasurements();if(a.length===0)return;let s=(r=this._singleLaneMeasurements)==null?void 0:r.flat,o=this.options.lanes===1&&s!=null,i=Vb(0,a.length-1,o?l=>s[l*2]:l=>Sh(a[l]).start,t);return Sh(a[i])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,r,a=0)=>{if(!this.scrollElement)return 0;let s=this.getSize(),o=this.getScrollOffset();r==="auto"&&(r=t>=o+s?"end":"start"),r==="center"?t+=(a-s)/2:r==="end"&&(t-=s);let i=this.getMaxScrollOffset();return Math.max(Math.min(i,t),0)},this.getOffsetForIndex=(t,r="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));let a=this.getSize(),s=this.getScrollOffset(),o=this.measurementsCache[t];if(!o)return;if(r==="auto")if(o.end>=s+a-this.options.scrollPaddingEnd)r="end";else if(o.start<=s+this.options.scrollPaddingStart)r="start";else return[s,r];if(r==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),r];let i=r==="end"?o.end+this.options.scrollPaddingEnd:o.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(i,r,o.size),r]},this.scrollToOffset=(t,{align:r="start",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0;let s=this.getOffsetForAlignment(t,r),o=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:o,lastTargetOffset:s,stableFrames:0},this._scrollToOffset(s,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,t=Math.max(0,Math.min(t,this.options.count-1));let s=this.getOffsetForIndex(t,r);if(!s)return;let[o,i]=s,l=this.now();this.scrollState={index:t,align:i,behavior:a,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:r="auto"}={})=>{let a=this.getScrollOffset()+t,s=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:s,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:t="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:t});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.getTotalSize=()=>{var t,r;let a=this.getMeasurements(),s;if(a.length===0)s=this.options.paddingStart;else if(this.options.lanes===1){let o=a.length-1,i=(t=this._singleLaneMeasurements)==null?void 0:t.flat;i!=null?s=i[o*2]+i[o*2+1]:s=((r=a[o])==null?void 0:r.end)??0}else{let o=Array(this.options.lanes).fill(null),i=a.length-1;for(;i>=0&&o.some(l=>l===null);){let l=a[i];o[l.lane]===null&&(o[l.lane]=l.end),i--}s=Math.max(...o.filter(l=>l!==null))}return Math.max(s-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let t=[];if(this.itemSizeCache.size===0)return t;let r=this.getMeasurements();for(let a of r)a&&this.itemSizeCache.has(a.key)&&t.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return t},this._scrollToOffset=(t,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=t+(r??0),this.options.scrollToFn(t,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){if(e===0)return!1;if(Lh()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded))return this._iosDeferredAdjustment+=e,!1;{let r=this.getScrollOffset()+this.scrollAdjustments+e,a=this.scrollElement,s=a!==null&&("scrollHeight"in a||"document"in a)?this.getMaxScrollOffset():null;return this._clampedAdjustment=s!==null&&r>s+.5?{target:r,maxAtWrite:s}:null,this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0}}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,a=r?r[0]:this.scrollState.lastTargetOffset,s=1,o=a!==this.scrollState.lastTargetOffset;if(!o&&Ch(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=s){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,o){let i=this.getSize()||600,l=Math.abs(a-this.getScrollOffset()),u=this.scrollState.behavior==="smooth"&&l>i;this.scrollState.lastTargetOffset=a,u||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:u?"smooth":"auto"})}this.scheduleScrollReconcile()}},Vb=(n,e,t,r)=>{for(;n<=e;){let a=(n+e)/2|0,s=t(a);if(s<r)n=a+1;else if(s>r)e=a-1;else return a}return n>0?n-1:0};function hA(n,e,t){let r=0;for(;r<=e;){let a=(r+e)/2|0,s=n[a*2];if(s<t)r=a+1;else if(s>t)e=a-1;else return a}return r>0?r-1:0}function pA(n,e,t,r,a){let s=n.length-1;if(n.length<=r)return{startIndex:0,endIndex:s};if(r===1&&a!==null){let u=hA(a,s,t),c=u,d=t+e;for(;c<s&&a[c*2]+a[c*2+1]<d;)c++;return{startIndex:u,endIndex:c}}let i=Vb(0,s,u=>n[u].start,t),l=i;if(r===1)for(;l<s&&n[l].end<t+e;)l++;else if(r>1){let u=Array(r).fill(0);for(;l<s&&u.some(d=>d<t+e);){let d=n[l];u[d.lane]=d.end,l++}let c=Array(r).fill(t+e);for(;i>=0&&c.some(d=>d>=t);){let d=n[i];c[d.lane]=d.start,i--}i=Math.max(0,i-i%r),l=Math.min(s,l+(r-1-l%r))}return{startIndex:i,endIndex:l}}var Ih=typeof document<"u"?oa.useLayoutEffect:oa.useEffect;function mA({useFlushSync:n=!0,directDomUpdates:e=!1,directDomUpdatesMode:t="transform",...r}){let a=oa.useReducer(d=>d+1,0)[1],s=oa.useRef({enabled:e,mode:t,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});s.current.enabled=e,s.current.mode=t;let o=oa.useRef(!1),i=d=>{let f=s.current;if(!f.enabled||!f.container)return;let h=d.getTotalSize();if(h!==f.lastSize){f.lastSize=h;let p=d.options.horizontal?"width":"height";f.container.style[p]=`${h}px`}},l=d=>{let f=s.current;if(!f.enabled||!f.container)return;i(d);let h=!!d.options.horizontal,p=f.mode==="transform",m=h?"left":"top",g=d.options.scrollMargin,x=d.getVirtualItems();for(let b of x){let y=b.start-g,N=d.elementsCache.get(b.key);N&&f.lastPositions.get(N)!==y&&(f.lastPositions.set(N,y),p?N.style.transform=h?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:N.style[m]=`${y}px`)}},u={...r,onChange:(d,f)=>{var h;let p=s.current,m=!0;if(p.enabled){l(d);let g=d.range,x=p.prevRange;m=!x||x.isScrolling!==d.isScrolling||x.startIndex!==g?.startIndex||x.endIndex!==g?.endIndex,m&&(p.prevRange=g?{startIndex:g.startIndex,endIndex:g.endIndex,isScrolling:d.isScrolling}:null)}m&&(n&&f&&!o.current?(0,$b.flushSync)(a):a()),(h=r.onChange)==null||h.call(r,d,f)}},[c]=oa.useState(()=>{let d=new Cc(u),f=d.measureElement;return d.measureElement=h=>{o.current=!0;try{f(h)}finally{o.current=!1}},Object.assign(d,{containerRef:h=>{let p=s.current;if(p.container=h,p.lastSize=null,h&&p.enabled){let m=d.getTotalSize();p.lastSize=m;let g=d.options.horizontal?"width":"height";h.style[g]=`${m}px`}}})});return c.setOptions(u),Ih(()=>c._didMount(),[]),Ih(()=>(i(c),c._willUpdate())),Ih(()=>{l(c)}),c}function li(n){return mA({observeElementRect:Wb,observeElementOffset:jb,scrollToFn:qb,...n})}var es=j(Ve(),1);function Kb(n){let{agentId:e,projectId:t,enabled:r}=n,[a,s]=(0,es.useState)([]),o=(0,es.useRef)(!0);(0,es.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let i=(0,es.useRef)(!1);return(0,es.useEffect)(()=>{i.current=!1,s([])},[e,t]),(0,es.useEffect)(()=>{!e||!r||i.current||(i.current=!0,ac({agentId:e,...t?{projectId:t}:{}}).then(l=>{o.current&&s(l.suggestions??[])}).catch(()=>{o.current&&s([])}))},[e,t,r]),a}var Ac=j(Ve(),1);var ur=j(wr(),1);var Aa=j(le(),1);function gA({className:n}){return(0,Aa.jsxs)("svg",{viewBox:"0 0 64 64",className:n,"aria-hidden":"true",children:[(0,Aa.jsx)("path",{d:"M10 52L24 28L36 36L52 12",fill:"none",stroke:"currentColor",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,Aa.jsx)("circle",{cx:"10",cy:"52",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Aa.jsx)("circle",{cx:"24",cy:"28",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Aa.jsx)("circle",{cx:"36",cy:"36",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"}),(0,Aa.jsx)("circle",{cx:"52",cy:"12",r:"5.2",fill:"#fb923c",stroke:"currentColor",strokeWidth:"2.4"})]})}function xA(n){if(!n)return"aged";let e=Date.parse(n);if(!Number.isFinite(e))return"aged";let t=Math.max(0,(Date.now()-e)/6e4);return t<=15?"fresh":t<=180?"recent":t<=1440?"aged":"stale"}function ho(n){switch(xA(n)){case"fresh":return{pillClassName:"border-emerald-400/25 bg-emerald-500/14 text-emerald-100",iconClassName:"text-emerald-300/85",label:"Changed just now"};case"recent":return{pillClassName:"border-amber-400/22 bg-amber-500/10 text-amber-100/92",iconClassName:"text-amber-300/76",label:"Changed recently"};case"aged":return{pillClassName:"border-white/10 bg-white/[0.05] text-white/60",iconClassName:"text-white/40",label:"Older change"};default:return{pillClassName:"border-rose-400/18 bg-rose-500/10 text-rose-100/80",iconClassName:"text-rose-300/70",label:"Older indexed change"}}}function ql(n){let e=n.status==="deleted",t=n.status==="pending_review",r=n.status==="pinned";return e?{tone:"text-red-100/70",iconTone:"text-red-300/70",secondaryTone:"text-red-200/60",highlightTone:"bg-red-500/12",icon:ys,label:"Deleted",title:"Marked as deleted",ghosted:!0}:t?{tone:"text-amber-50/95",iconTone:"text-amber-300/85",secondaryTone:"text-amber-200/75",highlightTone:"bg-amber-500/10",icon:ct,label:"Review pending",title:"Pending review before approval"}:n.presence==="brain"?{tone:"text-violet-50/92",iconTone:"text-violet-300/80",secondaryTone:"text-violet-200/68",highlightTone:"bg-violet-500/10",icon:ir,label:"Brain node",title:"Stored in brain index"}:n.presence==="stale_indexed"?{tone:"text-rose-100/78",iconTone:"text-rose-300/75",secondaryTone:"text-rose-200/65",highlightTone:"bg-rose-500/8",icon:Ja,label:"Missing from disk",title:"Indexed but not found in live source",ghosted:!0}:n.presence==="unindexed"?{tone:"text-white/55",iconTone:"text-white/70",secondaryTone:"text-white/45",highlightTone:"bg-white/[0.04]",icon:Ya,label:"Unindexed",title:"Connector entry not vector-indexed yet"}:r?{tone:"text-white/82",iconTone:"text-amber-200/80",secondaryTone:"text-amber-100/65",highlightTone:"bg-amber-500/8",icon:oo,label:"Pinned",title:"Pinned item"}:n.presence==="synced"?{tone:"text-white",iconTone:"text-sky-300/80",secondaryTone:"text-white/82",highlightTone:"bg-sky-500/10",icon:gA,label:"Synced",title:"Indexed and present on the connector"}:{tone:"text-white/72",iconTone:"text-white/48",secondaryTone:"text-white/48",highlightTone:"bg-white/[0.04]",icon:va,label:"Neutral",title:"File entry"}}function Xb(n){return n?Is:_r}function Yb(n){let t=[ql(n).label];return n.version?.changedAt&&t.push(ho(n.version.changedAt).label),n.status==="pinned"&&t.push("Pinned"),t}function Lc(n){return{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30",containerClassName:"opacity-55",title:n==="disabled"?"Source disabled in this scope \u2014 toggle in the Sources panel.":"Source discovered but not yet attached \u2014 click to add."}}function Ic(n){let e=n.enabled===!1,t=n.enabled==="auto"&&n.enabled_effective===!1;return e||t?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.live===!1?{iconClassName:"text-white/35",labelClassName:"text-white/45",detailClassName:"text-white/30"}:n.sync_status==="error"?{iconClassName:"text-rose-300/80",labelClassName:"text-rose-50/92",detailClassName:"text-rose-200/65"}:n.sync_status==="paused"?{iconClassName:"text-amber-300/80",labelClassName:"text-amber-50/90",detailClassName:"text-amber-200/65"}:n.sync_status==="active"?{iconClassName:"text-sky-300/80",labelClassName:"text-sky-50/90",detailClassName:"text-sky-200/62"}:n.source_kind==="brain"?{iconClassName:"text-violet-300/85",labelClassName:"text-violet-50/92",detailClassName:"text-violet-200/60"}:{iconClassName:"text-white/80",labelClassName:"text-white/90",detailClassName:"text-white/55"}}var yA={runtime_offline:"Machine offline \u2014 container not running",fs_unreachable:"Filesystem unreachable \u2014 mount missing",fs_permission:"Filesystem unreadable \u2014 permission denied",store_unreachable:"Store offline \u2014 backing service unreachable"};function Ah(n){return(n?yA[n]:void 0)??"Disconnected \u2014 connector cannot reach its backing filesystem"}function Jb(n){return n.enabled===!1?"Source disabled":n.enabled==="auto"&&n.enabled_effective===!1?"Source auto \u2014 currently stopped":n.live===!1?Ah(n.live_reason):n.sync_status==="error"?n.last_error??"Sync error":n.sync_status==="paused"?"Sync paused":n.sync_status==="active"?"Sync active":null}function Ph(n){if(!n)return null;let e=Date.parse(n);if(!Number.isFinite(e))return null;let t=Math.max(0,Math.round((Date.now()-e)/6e4));if(t<1)return"now";if(t<60)return`${t}m`;let r=Math.round(t/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Zb({className:n,title:e}){return(0,Aa.jsx)("span",{title:e,className:"inline-flex",children:(0,Aa.jsx)(lr,{className:n})})}function V(...n){return n.filter(Boolean).join(" ")}var er=j(le(),1),bA=5,Qb=28;function ew({suggestions:n,expanded:e,onToggleExpanded:t,onPick:r,overlay:a}){return n.length===0?null:(0,er.jsxs)("div",{className:V("group/discover shrink-0 border-t border-white/[0.06] bg-[#0b0b0f]/95",a?"absolute inset-x-0 bottom-0 z-20 shadow-[0_-8px_24px_rgba(0,0,0,0.45)]":""),"data-testid":"discover-dock",children:[(0,er.jsxs)("div",{className:"flex items-center justify-between px-2 pt-1.5 pb-1",children:[(0,er.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-wider text-white/40",children:"Discover"}),(0,er.jsx)("button",{type:"button",onClick:t,className:"inline-flex h-4 w-4 items-center justify-center rounded text-white/40 opacity-0 transition-opacity hover:text-white/70 focus-visible:opacity-100 group-hover/discover:opacity-60",title:e?"Collapse discoverable sources":"Show all discoverable sources","aria-label":e?"Collapse discoverable sources":"Show all discoverable sources","aria-expanded":e,children:e?(0,er.jsx)(Tt,{className:"h-3 w-3"}):(0,er.jsx)($a,{className:"h-3 w-3"})})]}),(0,er.jsx)("ul",{className:"overlay-scroll overflow-y-auto pb-1",style:{maxHeight:e?"60vh":bA*Qb},children:n.map(s=>(0,er.jsx)(wA,{suggestion:s,onPick:r},s.id))})]})}var wA=Ac.default.memo(function({suggestion:e,onPick:t}){let r=Lc("unattached"),a=(0,ur.resolveLucideIcon)(e.icon??null)??Un,s=(0,Ac.useCallback)(()=>t(e),[t,e]),o=[e.description,e.root].filter(Boolean).join(`
|
|
3
|
+
`);return(0,er.jsx)("li",{children:(0,er.jsxs)("button",{type:"button",onClick:s,title:o||r.title,style:{height:Qb},className:V("flex w-full items-center gap-2 px-2 text-left transition-colors hover:bg-white/[0.05]",r.containerClassName),children:[(0,er.jsx)(a,{className:V("h-4 w-4 shrink-0",r.iconClassName)}),(0,er.jsx)("span",{className:V("truncate text-xs font-medium",r.labelClassName),children:e.label}),(0,er.jsxs)("span",{className:V("shrink-0 font-mono text-[9px]",r.detailClassName),children:[e.suggestedScheme,"://"]})]})})});var ui=j(Ve(),1),aw=j(le(),1),tw=(0,ui.createContext)(null),Nh=null;function fn(){let n=(0,ui.useContext)(tw);if(!n)throw new Error("useFilesystemHost must be used within a FilesystemHostProvider");return n}function nw(){return Nh}function rw({value:n,children:e}){return Nh=n,(0,ui.useEffect)(()=>{Nh=n},[n]),(0,aw.jsx)(tw.Provider,{value:n,children:e})}var ow=j(wr(),1);function sw(n){return String(n||"").trim().toLowerCase().replace(/[\s_]+/g,"-")}function Ts(n){let e=new Map,t=new Map,r=new Map;return n.ids.forEach((a,s)=>{let o=n.byId[a];if(!o)return;e.set(a,o);let i=o.slug?sw(o.slug):"";i&&t.set(i,o);let l=o.name?sw(o.name):"";l&&t.set(l,o);let u=o.config?.appearance?.color,c=(0,ow.resolveAgentColor)(u,s);r.set(a,c)}),{byId:e,bySlug:t,accentById:r}}function ci(n,e){if(n)return e.accentById.get(n)}var Ir=j(Ve(),1);var iw=j(ta(),1);var SA=j(le(),1);function di(n){let e=yt(n)||n.split("/").pop()||"",t=vA(e);return kA(e.toLowerCase(),t)}function vA(n){return n.includes(".")?n.split(".").pop().toLowerCase():""}function kA(n,e){if(n==="dockerfile")return ti;if(n==="package.json")return wa;if(n===".gitignore"||n===".env"||n.startsWith(".env."))return ka;if(n==="tsconfig.json"||n==="tsconfig.base.json")return wa;if(n.endsWith(".d.ts"))return Ka;let t=new Set(["ts","tsx","js","jsx","py","java","kt","php","go","rs","cpp","c","hpp","cs","swift","sh","bash","zsh","ps1","prisma"]),r=new Set(["md","mdx","txt","yml","yaml","xml","ini","toml","css","scss","html","csv","xls","xlsx"]),a=new Set(["png","jpg","jpeg","gif","webp","svg"]),s=new Set(["mp4","mov","webm"]),o=new Set(["mp3","wav"]),i=new Set(["zip","gz","tar","rar","lock"]);return e==="json"||e==="jsonl"?wa:t.has(e)?Ka:r.has(e)?ka:a.has(e)?Sl:s.has(e)?Ss:o.has(e)?Ml:i.has(e)?ti:Cl}var Mh=j(le(),1),CA={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",U:"text-rose-400","?":"text-emerald-400"},LA={M:"bg-amber-400",A:"bg-emerald-400",D:"bg-rose-400",R:"bg-sky-400",C:"bg-sky-400",U:"bg-rose-400","?":"bg-emerald-400"},Rh={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",U:"Unmerged","?":"Untracked"};function IA(n){let e=n[0]??" ",t=n[1]??" ";if(e==="?"||t==="?")return"?";let r=t!==" "?t:e;return r===" "?null:r}function Pc({code:n,dot:e=!1}){let t=IA(n);if(!t)return null;let r=n[0]!==" "&&n[0]!=="?",a=n[1]!==" "&&n[1]!=="?",s=(Rh[t]??"Changed")+(r&&a?" (staged + unstaged)":r?" (staged)":"");if(e)return(0,Mh.jsx)("span",{className:V("shrink-0 w-1.5 h-1.5 rounded-full",LA[t]??"bg-white/60"),title:`Git: contains ${(Rh[t]??"changes").toLowerCase()}`,"aria-label":`Git: folder contains changes (${Rh[t]??"changed"})`});let o=t==="?"?"U":t;return(0,Mh.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",CA[t]??"text-white/60"),title:`Git: ${s}`,"aria-label":`Git status: ${s}`,children:o})}var an=j(le(),1),Vl="application/x-neuralis-fs-node";function AA({uri:n,tone:e,title:t}){let r=di(n);return(0,an.jsx)("span",{className:V("inline-flex items-center justify-center shrink-0",e),title:t,children:(0,an.jsx)(r,{className:"w-4 h-4"})})}var lw=Ir.default.memo(function({node:e,depth:t=0,agentId:r,projectId:a,isActive:s,isExpanded:o,badgeCount:i,isDrop:l,isSelectedFolder:u,mark:c,agentIndex:d,fallbackAgent:f,uploading:h,packageIconBySlug:p,onToggleFolder:m,onOpenFile:g,onClearFileMark:x,onSetDropTarget:b,onUploadMany:y,onMoveFileToFolder:N,pendingReviewCount:L,isSelected:A,isCut:w,renaming:v,onNodeClick:T,onNodeContextMenu:P,onRenameCommit:O,onRenameCancel:C}){let I=e.type==="folder",H=e.status==="deleted",q=e.status==="pending_review",$=!I&&e.version?.diff?e.version.diff:void 0,S=e.storeKey||Va(e),M=(0,Ir.useRef)(null),W=e.sourceAgentId?d.byId.get(e.sourceAgentId)??null:f,ee=ci(W?.id,d),te=(0,Ir.useMemo)(()=>ql(e),[e]),re=!!($&&($.added>0||$.removed>0)),ce=!!(I&&i),oe=!!c,ue=!!e.git,ie=ho(e.version?.changedAt),Re=(0,Ir.useMemo)(()=>{if(!I||!p)return null;let Me=e.uri.match(/^(packages|data):\/\/([^/]+)\/?$/);return Me?Me[2]:null},[I,e.uri,p]),Ye=(Re?p?.[Re]:void 0)??Xb(o),$e=Yb(e).join(" \u2022 "),Pt=re||ce||oe||q||ue,Xe=(0,Ir.useCallback)(()=>{m({key:S})},[S,m]),lt=(0,Ir.useCallback)(()=>{g({agentId:r,projectId:a??null,uri:e.uri,readAgentId:W?.id}),c&&x({agentId:r,path:e.uri})},[r,e.uri,W?.id,g,x,a,c]),Nt=(0,Ir.useCallback)(Me=>{let tt=Me.metaKey||Me.ctrlKey,pt=Me.shiftKey;if(tt||pt){T?.({node:e,additive:tt,range:pt});return}T?.({node:e,additive:!1,range:!1}),I?Xe():lt()},[e,I,T,Xe,lt]),ot=(0,Ir.useCallback)(Me=>{Me.preventDefault(),Me.stopPropagation(),P?.({node:e,x:Me.clientX,y:Me.clientY})},[e,P]);return(0,an.jsxs)("div",{ref:M,className:V("group flex h-7 items-center gap-1.5 px-2 rounded-md cursor-pointer select-none transition-colors",s?"bg-white/10 text-white":"text-white/70 hover:bg-white/5 hover:text-white",u?"bg-sky-500/15 text-sky-100":"",A&&!s?"bg-sky-400/20 ring-1 ring-inset ring-sky-400/30 text-white":"",q&&!s?"bg-amber-500/[0.08] border-l-2 border-l-amber-400/60":"",H?"opacity-70":"",w?"opacity-45":"",l?"bg-white/10":""),style:{paddingLeft:`${t*12+8}px`},draggable:!v,onDragStart:Me=>{let tt={kind:"filesystem",action:I?"list":"read",uri:e.uri};Me.dataTransfer.setData("application/x-neuralis-fs-ref",JSON.stringify(tt)),Me.dataTransfer.setData(Vl,JSON.stringify({type:e.type,uri:e.uri,id:e.id,name:e.name})),Me.dataTransfer.setData("text/plain",`\u27E6fs:${I?"list":"read"}:${e.uri}\u27E7`),Me.dataTransfer.effectAllowed="copyMove"},onClick:Nt,onContextMenu:ot,onDragOver:Me=>{if(!I||h)return;let tt=Array.from(Me.dataTransfer.types||[]);(tt.includes("Files")||tt.includes(Vl))&&(Me.preventDefault(),Me.dataTransfer.dropEffect=tt.includes(Vl)?"move":"copy",b(S))},onDragLeave:()=>{l&&b(null)},onDrop:async Me=>{if(!I||h)return;let tt=Array.from(Me.dataTransfer.types||[]),pt=tt.includes("Files"),Rt=tt.includes(Vl);if(!(!pt&&!Rt)){if(Me.preventDefault(),b(null),Rt){let kt=Me.dataTransfer.getData(Vl);if(!kt)return;try{let Ee=JSON.parse(kt);if(!Ee.uri||Ee.uri===e.uri||e.uri===Ee.uri||e.uri.startsWith(`${Ee.uri}/`))return;await N({fromUri:Ee.uri,id:Ee.id,toFolderUri:e.uri});return}catch{return}}if(pt){let kt=Array.from(Me.dataTransfer.files||[]);if(kt.length===0)return;await y({agentId:r,projectId:a??null,files:kt,uri:e.uri})}}},title:`${e.uri}${$e?`
|
|
4
|
+
${$e}`:""}`,"aria-label":`${e.name} \u2014 ${$e}`,children:[(0,an.jsx)("span",{className:"shrink-0 text-white/40",children:I?o?(0,an.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,an.jsx)(un,{className:"w-3.5 h-3.5"}):(0,an.jsx)("span",{className:"w-3.5 h-3.5 inline-block"})}),I?(0,an.jsx)("span",{title:te.title,children:(0,an.jsx)(Ye,{className:V("w-4 h-4 shrink-0",te.iconTone),style:{color:e.presence==="brain"&&ee||void 0}})}):(0,an.jsx)(AA,{uri:e.uri,tone:te.iconTone,title:te.title}),v?(0,an.jsx)(PA,{initial:e.name,onCommit:Me=>O?.({node:e,newName:Me}),onCancel:()=>C?.()}):(0,an.jsx)("span",{className:V("min-w-0 text-xs truncate flex-1 transition-colors",te.tone,te.ghosted&&"opacity-70",H&&"line-through"),children:e.name}),Pt?(0,an.jsxs)("span",{className:"ml-1 shrink-0 flex items-center justify-end gap-1",children:[q?(0,an.jsx)("span",{title:"Pending review",className:"shrink-0 flex items-center",children:(0,an.jsx)(iw.LivePulseDot,{className:"text-amber-400/80 shrink-0"})}):null,oe?(0,an.jsx)("span",{className:V("w-1.5 h-1.5 rounded-full shrink-0",c?.kind==="new"?"bg-emerald-400":"bg-blue-400"),title:c?.kind==="new"?"New file":"Modified"}):null,ue&&e.git?(0,an.jsx)(Pc,{code:e.git,dot:I}):null,re?(0,an.jsx)(Zb,{className:V("w-3.5 h-3.5 shrink-0",ie.iconClassName),title:ie.label}):null,ce?(0,an.jsx)("span",{className:V("inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full text-[9px] font-semibold",L?"bg-amber-500/20 text-amber-200":"bg-sky-500/15 text-sky-200"),children:i}):null]}):null]})});function PA({initial:n,onCommit:e,onCancel:t}){let r=(0,Ir.useRef)(!1);return(0,an.jsx)("input",{autoFocus:!0,defaultValue:n,spellCheck:!1,onFocus:a=>{let s=a.currentTarget.value,o=s.lastIndexOf(".");a.currentTarget.setSelectionRange(0,o>0?o:s.length)},onClick:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),onKeyDown:a=>{a.stopPropagation(),a.key==="Enter"?r.current||(r.current=!0,e(a.currentTarget.value)):a.key==="Escape"&&(r.current||(r.current=!0,t()))},onBlur:a=>{r.current||(r.current=!0,e(a.currentTarget.value))},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none"})}var Fs=j(Ve(),1),uw=j(Qa(),1);var Ds=j(le(),1),NA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Ls},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:Cr},{kind:"sep"},{kind:"item",action:"cut",label:"Cut",Icon:Fl,shortcut:"\u2318X"},{kind:"item",action:"copy",label:"Copy",Icon:sa,shortcut:"\u2318C"},{kind:"item",action:"paste",label:"Paste",Icon:yl,shortcut:"\u2318V"},{kind:"sep"},{kind:"item",action:"copy-path",label:"Copy Path",Icon:Al},{kind:"item",action:"copy-relative-path",label:"Copy Relative Path",Icon:wl},{kind:"sep"},{kind:"item",action:"reembed",label:"Re-embed\u2026",Icon:Sa},{kind:"sep"},{kind:"item",action:"rename",label:"Rename",Icon:Ps,shortcut:"F2"},{kind:"item",action:"delete",label:"Delete",Icon:It,danger:!0,shortcut:"Del"}],RA=[{kind:"item",action:"new-file",label:"New File\u2026",Icon:Ls},{kind:"item",action:"new-folder",label:"New Folder\u2026",Icon:Cr}],MA=210;function cw({x:n,y:e,enabled:t,onAction:r,onClose:a,variant:s="node"}){let o=s==="source"?RA:NA,i=(0,Fs.useRef)(null),[l,u]=(0,Fs.useState)({top:e,left:n});return(0,Fs.useLayoutEffect)(()=>{let c=i.current;if(!c)return;let d=c.getBoundingClientRect(),f=n,h=e;f+d.width>window.innerWidth-4&&(f=Math.max(4,window.innerWidth-d.width-4)),h+d.height>window.innerHeight-4&&(h=Math.max(4,window.innerHeight-d.height-4)),u({top:h,left:f})},[n,e]),(0,Fs.useEffect)(()=>{let c=h=>{i.current?.contains(h.target)||a()},d=h=>{h.key==="Escape"&&a()},f=()=>a();return document.addEventListener("mousedown",c,!0),document.addEventListener("keydown",d,!0),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{document.removeEventListener("mousedown",c,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a]),(0,uw.createPortal)((0,Ds.jsx)("div",{ref:i,role:"menu",style:{position:"fixed",top:l.top,left:l.left,width:MA},className:"z-[1000] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",onContextMenu:c=>c.preventDefault(),children:o.map((c,d)=>{if(c.kind==="sep")return(0,Ds.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"},`s${d}`);let f=t[c.action]===!0,h=c.Icon;return(0,Ds.jsxs)("button",{type:"button",role:"menuitem",disabled:!f,onClick:()=>{f&&(r(c.action),a())},className:V("flex w-full items-center gap-2 px-3 py-1.5 text-left transition",f?"hover:bg-white/[0.06]":"opacity-35 cursor-not-allowed",c.danger&&f?"text-rose-200 hover:bg-rose-500/10":""),children:[(0,Ds.jsx)(h,{className:V("w-3.5 h-3.5 shrink-0",c.danger?"text-rose-300/80":"text-white/45")}),(0,Ds.jsx)("span",{className:"flex-1 truncate",children:c.label}),c.shortcut?(0,Ds.jsx)("span",{className:"text-[9px] text-white/30 tabular-nums",children:c.shortcut}):null]},c.action)})}),document.body)}var dw=j(Ve(),1),fw=j(Qa(),1);var xn=j(le(),1);function hw({names:n,busy:e,onCancel:t,onConfirm:r}){(0,dw.useEffect)(()=>{let o=i=>{e||(i.key==="Escape"?(i.preventDefault(),t()):i.key==="Enter"&&(i.preventDefault(),r()))};return document.addEventListener("keydown",o,!0),()=>document.removeEventListener("keydown",o,!0)},[e,t,r]);let a=n.length>1,s=a?`Delete ${n.length} items?`:`Delete '${n[0]}'?`;return(0,fw.createPortal)((0,xn.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:o=>{o.target===o.currentTarget&&!e&&t()},children:(0,xn.jsxs)("div",{className:"w-[340px] rounded-xl border border-rose-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,xn.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,xn.jsx)(ct,{className:"h-4 w-4 text-rose-300 shrink-0 mt-0.5"}),(0,xn.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,xn.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:s}),(0,xn.jsxs)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:[a?"The selected files move to Pending Changes. ":"The file moves to Pending Changes. ",(0,xn.jsx)("span",{className:"text-white/75",children:"You can restore"})," ",a?"them":"it"," from there \u2014 this is not a permanent erase."]}),a?(0,xn.jsxs)("div",{className:"mt-2 max-h-24 overflow-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[10px] font-mono text-white/50 space-y-0.5 overlay-scroll",children:[n.slice(0,12).map(o=>(0,xn.jsx)("div",{className:"truncate",children:o},o)),n.length>12?(0,xn.jsxs)("div",{className:"text-white/35",children:["+",n.length-12," more\u2026"]}):null]}):null]})]}),(0,xn.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,xn.jsxs)("button",{type:"button",onClick:t,disabled:e,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,xn.jsx)(Bt,{className:"h-3 w-3"}),"Cancel"]}),(0,xn.jsxs)("button",{type:"button",onClick:r,disabled:e,className:V("h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[e?(0,xn.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,xn.jsx)(It,{className:"h-3 w-3"}),"Delete"]})]})]})}),document.body)}var ts=j(Ve(),1),pw=j(Qa(),1);var bt=j(le(),1);function TA(n){return n.usd===null?"unpriced \u2014 the active model has no price":`~$${n.usd.toFixed(2)}${n.usdMargin!==null?` \xB1 $${n.usdMargin.toFixed(2)}`:""}`}function DA(n){return n===null?"time unknown":n<90?`~${Math.round(n)} s`:n<5400?`~${Math.round(n/60)} min`:`~${(n/3600).toFixed(1)} h`}function $l({agentId:n,projectId:e,target:t,onClose:r,onStarted:a,kind:s="reembed"}){let[o,i]=(0,ts.useState)(null),[l,u]=(0,ts.useState)(!0),[c,d]=(0,ts.useState)(!1),[f,h]=(0,ts.useState)(null),[p,m]=(0,ts.useState)(!1),g={agentId:n,...e?{projectId:e}:{},source:t.source,...t.folder?{folder:t.folder}:{},...t.uri?{uri:t.uri}:{}};(0,ts.useEffect)(()=>{let b=!0;return u(!0),wx(g,s).then(y=>{b&&i(y)}).catch(y=>{b&&h(y instanceof Error?y.message:"Estimate failed")}).finally(()=>{b&&u(!1)}),()=>{b=!1}},[]),(0,ts.useEffect)(()=>{let b=y=>{y.key==="Escape"&&!c&&(y.preventDefault(),r())};return document.addEventListener("keydown",b,!0),()=>document.removeEventListener("keydown",b,!0)},[c,r]);let x=async()=>{d(!0),h(null);try{if(!(await dc(g,s)).job){m(!0),d(!1);return}a?.(),r()}catch(b){h(b instanceof Error?b.message:"Re-embed failed"),d(!1)}};return(0,pw.createPortal)((0,bt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:b=>{b.target===b.currentTarget&&!c&&r()},children:(0,bt.jsxs)("div",{role:"dialog","aria-label":`${s==="pending"?"Embed pending files of":"Re-embed"} ${t.label}`,className:"w-[360px] rounded-xl border border-cyan-400/25 bg-[#15151d] p-4 shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,bt.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,bt.jsx)(Sa,{className:"h-4 w-4 text-cyan-300 shrink-0 mt-0.5"}),(0,bt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,bt.jsx)("div",{className:"truncate text-[12px] font-semibold text-white/90",children:s==="pending"?`Embed pending files of ${t.label}?`:`Re-embed ${t.label}?`}),(0,bt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:s==="pending"?(0,bt.jsxs)(bt.Fragment,{children:["Only files whose semantic embedding is missing or stale are embedded, with the"," ",(0,bt.jsx)("span",{className:"text-white/75",children:"active"})," model. The figures below cover the whole scope \u2014 an upper bound; files already embedded are skipped. Contents and text search are not touched."]}):(0,bt.jsxs)(bt.Fragment,{children:["Every file in this scope is read again and embedded with the ",(0,bt.jsx)("span",{className:"text-white/75",children:"active"})," ","model, whether it changed or not. File contents and history are not touched \u2014 only the vectors are replaced."]})}),(0,bt.jsx)("div",{className:"mt-2 rounded-md bg-white/[0.03] px-2 py-1.5 text-[10.5px] text-white/65 space-y-0.5",children:l?(0,bt.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-white/45",children:[(0,bt.jsx)(We,{className:"h-3 w-3 animate-spin"}),"Estimating from a sample\u2026"]}):o?(0,bt.jsxs)(bt.Fragment,{children:[(0,bt.jsxs)("div",{children:[o.documents!==null?`${o.documents.toLocaleString()} documents \xB7 `:null,o.points.toLocaleString()," points"]}),(0,bt.jsxs)("div",{children:["~",o.tokens.toLocaleString(),o.tokensMargin!==null?` \xB1 ${o.tokensMargin.toLocaleString()}`:""," tokens"]}),(0,bt.jsxs)("div",{children:[TA(o)," \xB7 ",DA(o.durationSeconds)]}),o.truncated?(0,bt.jsx)("div",{className:"text-amber-300/80",children:"The scope is larger than one listing \u2014 these figures cover its first part."}):null]}):f?null:(0,bt.jsx)("div",{className:"text-white/45",children:"No estimate available for this scope."})}),f?(0,bt.jsx)("div",{className:"mt-2 text-[10px] text-rose-300/90",children:f}):null,p?(0,bt.jsx)("div",{className:"mt-2 text-[10px] text-white/55",children:"Nothing readable in this scope \u2014 nothing was queued."}):null]})]}),(0,bt.jsxs)("div",{className:"mt-4 flex items-center justify-end gap-2",children:[(0,bt.jsxs)("button",{type:"button",onClick:r,disabled:c,className:"h-7 px-2.5 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[11px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,bt.jsx)(Bt,{className:"h-3 w-3"}),"Cancel"]}),(0,bt.jsxs)("button",{type:"button",onClick:()=>{x()},disabled:c||l||p,className:"h-7 px-3 rounded-md text-[11px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1.5 bg-cyan-500/20 hover:bg-cyan-500/30 border border-cyan-400/40 text-cyan-100",children:[c?(0,bt.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,bt.jsx)(Sa,{className:"h-3 w-3"}),s==="pending"?"Embed pending":"Re-embed"]})]})]})}),document.body)}var fi=j(Ve(),1);var gw=j(ta(),1);var Cn=j(le(),1);function FA(n){if(!n)return null;if(n.isRepo&&n.repoName)return{label:n.repoName,title:`Repository: ${n.repoName}`};if(n.containsRepos&&n.repoNames&&n.repoNames.length>0){let e=n.repoNames,t=e.slice(0,2).join(", ");return{label:e.length>2?`${t} +${e.length-2}`:t,title:`Repositories: ${e.join(", ")}`}}return null}function EA({info:n}){let e=(0,ur.resolveIconWithFallback)(n.kind_icon??void 0,Un),t=n.source_kind==="brain"||n.source_kind==="local-disk",r=!!(n.git?.isRepo||n.git?.containsRepos);return(0,Cn.jsxs)("span",{className:"relative inline-flex items-center justify-center",children:[(0,Cn.jsx)(e,{className:"w-4 h-4"}),t?(0,Cn.jsx)(Tl,{className:"absolute -right-1.5 -bottom-1.5 w-2.5 h-2.5 text-current bg-black/80 rounded-full p-[1px] opacity-80"}):null,r?(0,Cn.jsx)(Sn,{className:"absolute -right-1.5 -top-1.5 w-2.5 h-2.5 text-violet-300/90 bg-black/80 rounded-full p-[1px]"}):null]})}function mw(n){return n.source_kind==="brain"?"brain":qe(n.uri_root)}var xw=fi.default.memo(function({info:e,expanded:t,onToggle:r,onContextMenu:a,onRefresh:s,hydration:o="ready",dirty:i=!1,hideChevron:l=!0,compact:u=!1}){let c=(0,fi.useCallback)(()=>r(e.uri_root),[r,e.uri_root]),d=(0,fi.useCallback)(x=>a?.(e.uri_root,x),[a,e.uri_root]),f=(0,fi.useCallback)(x=>{x.stopPropagation(),x.preventDefault(),s?.(e.uri_root)},[s,e.uri_root]),h=Ic(e),p=Jb(e),m=FA(e.git),g=o==="loading";return(0,Cn.jsxs)("div",{className:V("group flex w-full items-center gap-2 rounded-md select-none text-left transition-colors",u?"py-1 px-1.5":"py-1.5 px-2","hover:bg-white/5",t&&"bg-white/[0.03]"),onContextMenu:d,"aria-busy":g||void 0,children:[(0,Cn.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 bg-transparent text-left outline-none",onClick:c,"aria-expanded":t,title:p?`${e.uri_root} \u2014 ${p}`:e.uri_root,children:[l?null:(0,Cn.jsx)("span",{className:"w-0","aria-hidden":"true"}),(0,Cn.jsx)("span",{className:V("shrink-0",h.iconClassName,o==="idle"||o==="error"?"opacity-50":""),children:(0,Cn.jsx)(EA,{info:e})}),(0,Cn.jsx)("span",{className:V("text-xs font-medium flex-1 truncate transition-colors",h.labelClassName,o==="idle"||o==="error"?"opacity-70":""),children:mw(e)})]}),m?(0,Cn.jsxs)("span",{className:"ml-1 inline-flex max-w-[120px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:m.title,children:[(0,Cn.jsx)(Sn,{className:"h-2.5 w-2.5 shrink-0"}),(0,Cn.jsx)("span",{className:"truncate",children:m.label})]}):null,s?(0,Cn.jsx)("button",{type:"button",onClick:f,disabled:g,"aria-label":`Refresh ${mw(e)}`,title:o==="error"?"Last listing failed \u2014 click to retry":i?"This source may be out of date \u2014 click to refresh":"Refresh this source",className:V("shrink-0 inline-flex h-4 w-4 items-center justify-center rounded transition-opacity","text-white/40 hover:text-white/80 focus-visible:opacity-100",g||i||o==="error"?"opacity-100":"opacity-0 group-hover:opacity-100",i||o==="error"?"text-amber-300/80 hover:text-amber-200":""),children:g?(0,Cn.jsx)(gw.LiveSpinner,{className:"h-3 w-3"}):(0,Cn.jsx)(Ot,{className:"h-3 w-3","aria-hidden":"true"})}):null]})});var pi=j(Ve(),1);var rt=j(le(),1),OA=[{id:"keyword",label:"Keyword",hint:"Indexed word search (primary)"},{id:"semantic",label:"Semantic",hint:"Embedding search by meaning"},{id:"grep",label:"Grep",hint:"Literal scan of live connector content"}],hi="h-6 w-full bg-transparent border border-white/[0.06] rounded px-1.5 text-[11px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20";function BA(n){return n?n.requestedMode==="semantic"&&n.effectiveMode&&n.effectiveMode!=="semantic"?`Searched as keyword \u2014 semantic search unavailable${n.embeddingDegraded?` (${n.embeddingDegraded})`:""}. Use specific words.`:n.warning??null:null}function yw({agentId:n}){let e=_(v=>v.activeProjectId),t=_(v=>v.setActiveFolderPath),r=_(v=>v.openFile),a=_(v=>v.searchQuery),s=_(v=>v.searchMode),o=_(v=>v.setSearchMode),i=_(v=>v.searchFilters),l=_(v=>v.setSearchFilters),u=_(v=>v.searchResults),c=_(v=>v.searchLoading),d=_(v=>v.searchError),f=_(v=>v.searchEffect),h=BA(f),p=_(v=>v.runSearch),m=_(v=>v.activeFolderPath),g=_(v=>v.sources),[x,b]=(0,pi.useState)(!1),y=a.trim(),N=i.glob.trim(),L=s==="keyword"?y.length>=2||N.length>=2:y.length>=2,A=(0,pi.useMemo)(()=>sh(m,g,i.scopeToFolder),[m,g,i.scopeToFolder]);(0,pi.useEffect)(()=>{if(!L)return;let v=setTimeout(()=>{p({agentId:n,projectId:e??null})},250);return()=>clearTimeout(v)},[n,e,L,s,a,i,p]);let w=(N?1:0)+(i.category.trim()?1:0)+(i.status.trim()?1:0)+(i.tags.trim()?1:0)+(i.createdAfter.trim()?1:0)+(i.createdBefore.trim()?1:0)+(i.scopeToFolder?1:0);return(0,rt.jsxs)("div",{className:"px-2 pb-2",children:[(0,rt.jsxs)("div",{className:"flex items-center gap-1 pb-1.5",children:[(0,rt.jsx)("div",{className:"flex-1 flex items-center rounded-md border border-white/[0.06] overflow-hidden",children:OA.map(v=>{let T=v.id==="grep"&&!A;return(0,rt.jsx)("button",{type:"button",disabled:T,onClick:()=>o(v.id),title:T?"Grep needs a disk-backed source (brain:// has no live text)":v.hint,className:`flex-1 h-6 text-[10px] uppercase tracking-wide transition-colors ${s===v.id?"bg-white/[0.08] text-white/85":T?"text-white/20 cursor-not-allowed":"text-white/40 hover:text-white/70"}`,"aria-pressed":s===v.id,children:v.label},v.id)})}),(0,rt.jsxs)("button",{type:"button",onClick:()=>b(v=>!v),className:`h-6 w-6 shrink-0 rounded-md inline-flex items-center justify-center transition-colors ${x||w>0?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search filters","aria-label":"Toggle search filters","aria-pressed":x,children:[(0,rt.jsx)(uo,{className:"w-3.5 h-3.5"}),w>0?(0,rt.jsx)("span",{className:"absolute translate-x-2.5 -translate-y-2 text-[8px] text-white/70",children:w}):null]})]}),x?(0,rt.jsxs)("div",{className:"pb-2 space-y-1",children:[(0,rt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,rt.jsx)("input",{type:"text",value:i.glob,onChange:v=>l({glob:v.target.value}),placeholder:"Filename\u2026",className:hi}),(0,rt.jsxs)("label",{className:"flex items-center gap-1 shrink-0 text-[10px] text-white/45 select-none cursor-pointer",title:"Scope to the active folder",children:[(0,rt.jsx)("input",{type:"checkbox",checked:i.scopeToFolder,onChange:v=>l({scopeToFolder:v.target.checked}),className:"accent-white/60"}),"folder"]})]}),s!=="grep"?(0,rt.jsxs)(rt.Fragment,{children:[(0,rt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,rt.jsx)("input",{type:"text",value:i.category,onChange:v=>l({category:v.target.value}),placeholder:"Category\u2026",className:hi}),(0,rt.jsx)("input",{type:"text",value:i.status,onChange:v=>l({status:v.target.value}),placeholder:"Status\u2026",className:hi})]}),(0,rt.jsx)("input",{type:"text",value:i.tags,onChange:v=>l({tags:v.target.value}),placeholder:"Tags (comma-separated)\u2026",className:hi}),(0,rt.jsxs)("div",{className:"flex items-center gap-1",children:[(0,rt.jsx)("input",{type:"date",value:i.createdAfter,onChange:v=>l({createdAfter:v.target.value}),title:"Created after",className:hi}),(0,rt.jsx)("input",{type:"date",value:i.createdBefore,onChange:v=>l({createdBefore:v.target.value}),title:"Created before",className:hi})]})]}):null]}):null,L?c?(0,rt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Searching\u2026"}):d?(0,rt.jsx)("div",{className:"px-2 py-3 text-[11px] text-red-300/70",children:d}):u.length===0?(0,rt.jsxs)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:[h?(0,rt.jsx)("div",{role:"status",className:"mb-1 text-[10px] text-amber-200/70",children:h}):null,"No matches"]}):(0,rt.jsxs)("div",{className:"space-y-1",children:[h?(0,rt.jsx)("div",{role:"status",className:"px-2 py-1 text-[10px] text-amber-200/70",children:h}):null,u.map(v=>(0,rt.jsxs)("button",{type:"button",className:"w-full text-left px-2 py-2 rounded-md hover:bg-white/5 border border-white/[0.04] transition-colors",onClick:()=>{t(nt(v.uri)),r({agentId:n,projectId:e??null,uri:v.uri})},children:[(0,rt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,rt.jsx)("span",{className:"text-[11px] text-white/80 truncate flex-1",children:v.filename}),typeof v.score=="number"?(0,rt.jsx)("span",{className:"text-[9px] text-white/30 shrink-0",children:v.score.toFixed(2)}):null,v.embedding_status==="missing"||v.embedding_status==="stale"?(0,rt.jsxs)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",title:"This file is text-searchable; its semantic embedding is not current",children:["embedding ",v.embedding_status]}):null,v.match_type?(0,rt.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded bg-white/[0.06] text-white/40 shrink-0",children:v.match_type==="hybrid"?"H":v.match_type==="semantic"?"S":"K"}):null]}),(0,rt.jsxs)("div",{className:"text-[10px] text-white/35 font-mono truncate",children:[v.uri,s==="grep"&&typeof v.chunk_start=="number"?`:${v.chunk_start}`:""]}),v.snippet??v.content_preview?(0,rt.jsx)("div",{className:"text-[10px] text-white/45 mt-1 line-clamp-2",children:v.snippet??v.content_preview}):null]},`${v.id}:${v.uri}:${v.chunk_start??""}`))]}):(0,rt.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:s==="keyword"?"Type to search (or set a filename filter)\u2026":"Type to search\u2026"})]})}var we=j(Ve(),1),P1=j(Qa(),1);var N1=j(wr(),1);var at=j(Ve(),1);var p1=j(ta(),1);var po=j(le(),1);function _A(n){return n<1e4?String(n):n<1e6?`${Math.round(n/1e3)}k`:`${(n/1e6).toFixed(1)}M`}function Pa({added:n,removed:e,binary:t,unknown:r,compact:a,className:s}){if(t)return(0,po.jsx)("span",{className:V("shrink-0 text-[9px] tabular-nums text-white/40",s),title:"Binary file \u2014 git reports no line count",children:"bin"});if(!(typeof n=="number"&&typeof e=="number")||n===0&&e===0&&!r)return null;let i=a?_A:String,l=r?"+":"";return(0,po.jsxs)("span",{className:V("flex shrink-0 items-center gap-1 text-[9px] tabular-nums",s),title:r?`+${n} \u2212${e} across the counted files; ${r} more could not be measured`:`+${n} \u2212${e}`,children:[n>0?(0,po.jsx)("span",{className:"text-emerald-400/80",children:`+${i(n)}${l}`}):null,e>0?(0,po.jsx)("span",{className:"text-rose-400/80",children:`\u2212${i(e)}${l}`}):null,n===0&&e===0?(0,po.jsx)("span",{className:"text-white/35",children:`0${l}`}):null]})}function HA(n){return(n.refs??[]).some(e=>e==="HEAD"||e.startsWith("HEAD ")||e.startsWith("HEAD-")||e.includes("HEAD ->"))}function bw(n){let e=[],t=[];if(!Array.isArray(n)||n.length===0)return{nodes:e,edges:t,rowSegments:[],laneCount:0};let r=[],a=new Map,s=0,o=u=>{let c=r.indexOf(u);if(c>=0)return c;let d=r.indexOf(null);return d>=0?(r[d]=u,d):(r.push(u),r.length-1)};for(let u=0;u<n.length;u++){let c=n[u],d=c.sha,f=r.indexOf(d);f<0&&(f=o(d));for(let p=0;p<r.length;p++)r[p]===d&&(r[p]=null);f>s&&(s=f),a.set(d,{row:u,lane:f});let h=Array.isArray(c.parents)?c.parents:[];if(h.length!==0){r[f]=h[0];for(let p=1;p<h.length;p++){let m=o(h[p]);m>s&&(s=m)}}e.push({commit:c,row:u,lane:f,isHead:HA(c),isMerge:h.length>=2})}let i=n.map(()=>[]),l=(u,c)=>{u>=0&&u<i.length&&i[u].push(c)};for(let u of e){let c=Array.isArray(u.commit.parents)?u.commit.parents:[];for(let d=0;d<c.length;d++){let f=a.get(c[d]);if(f){t.push({fromRow:u.row,fromLane:u.lane,toRow:f.row,toLane:f.lane,colorLane:u.lane,open:!1});let h=u.row,p=f.row,m=u.lane,g=f.lane,x=u.lane;if(p<=h)continue;if(m===g){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let b=h+1;b<p;b++)l(b,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}else{let b=(m+g)/2,y=d>0?"merge":"fork";if(d>0){if(l(h,{kind:y,fromLane:m,toLane:b,fromY:"center",toY:"edge",colorLane:x}),l(h+1,{kind:y,fromLane:b,toLane:g,fromY:"edge",toY:"center",colorLane:x}),h+1<p){l(h+1,{kind:"pass",fromLane:g,toLane:g,fromY:"center",toY:"edge",colorLane:x});for(let N=h+2;N<p;N++)l(N,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"edge",colorLane:x});l(p,{kind:"pass",fromLane:g,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}else{if(p-1>h){l(h,{kind:"pass",fromLane:m,toLane:m,fromY:"center",toY:"edge",colorLane:x});for(let N=h+1;N<p-1;N++)l(N,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"edge",colorLane:x});l(p-1,{kind:"pass",fromLane:m,toLane:m,fromY:"edge",toY:"center",colorLane:x})}l(p-1,{kind:y,fromLane:m,toLane:b,fromY:"center",toY:"edge",colorLane:x}),l(p,{kind:y,fromLane:b,toLane:g,fromY:"edge",toY:"center",colorLane:x})}}}else t.push({fromRow:u.row,fromLane:u.lane,toRow:u.row+1,toLane:u.lane,colorLane:u.lane,open:!0}),l(u.row,{kind:"stub",fromLane:u.lane,toLane:u.lane,fromY:"center",toY:"edge",colorLane:u.lane})}}return{nodes:e,edges:t,rowSegments:i,laneCount:s+1}}function ww(n,e){if(!Array.isArray(n)||e<=0||e>=n.length)return[];let t=[],r=new Set;for(let a of n[e]??[]){if(a.fromY!=="edge")continue;let s=`${a.fromLane}|${a.colorLane}`;r.has(s)||(r.add(s),t.push({kind:"pass",fromLane:a.fromLane,toLane:a.fromLane,fromY:"edge",toY:"edge",colorLane:a.colorLane}))}return t}var Th={commits:[],nextSkip:0,hasMore:!1};function vw(n,e){let t=[];for(let r of e.commits)!r||typeof r.sha!="string"||n.has(r.sha)||(n.add(r.sha),t.push(r));return t}function kw(n,e){let t=new Set(n.commits.map(a=>a.sha)),r=vw(t,e);return{commits:r.length>0?[...n.commits,...r]:n.commits,nextSkip:n.nextSkip+e.commits.length,hasMore:e.hasMore,outgoing:n.outgoing}}function Sw(n){return{commits:vw(new Set,n),nextSkip:n.commits.length,hasMore:n.hasMore,outgoing:n.outgoing}}function Dh(n){return Math.min(1e3,Math.max(n,200))}function Cw(n,e){let t=[],r=e&&e.length>0?new Set(e):null,a=!1;for(let s=0;s<n.length;s++)!a&&r&&r.has(n[s].sha)&&(t.push({kind:"outgoing-divider"}),a=!0),t.push({kind:"commit",row:s});return t}function Lw(n,e){return n.kind==="outgoing-divider"?"#outgoing-divider":e[n.row]?.sha??`row-${n.row}`}function Iw(n){let e=n.trim();return e.startsWith("tag:")?"tag":e.startsWith("origin/")?"remote":"local"}function Aw(n,e){return e?"outgoing":n?"merge":"filled"}var UA="#89b4fa";function Pw(n,e){return n==="outgoing"?UA:e}function Fh(n,e=Date.now()){let t=Date.parse(n);if(Number.isNaN(t))return n;let r=Math.max(0,Math.floor((e-t)/1e3));if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return`${a}m ago`;let s=Math.floor(a/60);if(s<24)return`${s}h ago`;let o=Math.floor(s/24);if(o<30)return`${o}d ago`;let i=Math.floor(o/30);return i<12?`${i}mo ago`:`${Math.floor(i/12)}y ago`}function Nw(n){return!n||typeof n.upstream!="string"||n.upstream.length===0?null:{upstream:n.upstream,ahead:typeof n.ahead=="number"&&n.ahead>=0?n.ahead:0,behind:typeof n.behind=="number"&&n.behind>=0?n.behind:0}}function Eh(n,e){if(typeof window>"u")return e;try{let t=JSON.parse(window.localStorage.getItem(n)??"null");return typeof t=="boolean"?t:e}catch{return e}}function Oh(n,e){if(!(typeof window>"u"))try{window.localStorage.setItem(n,JSON.stringify(e))}catch{}}function Es(n,e){return typeof e=="string"&&e.length>0?{prefix:`${n}://`,name:e,title:`Source "${n}" \u2014 repository "${e}"`}:{prefix:"",name:n,title:`Repository: ${n}`}}var rs=j(Ve(),1);var Dn=j(Ve(),1),GA=3,Rw=200,Mw=8*1024*1024,zA="200% 0px";function Nc(n){let e=(0,Dn.useRef)(new Map),t=(0,Dn.useRef)(null),[r,a]=(0,Dn.useState)(new Set),s=(0,Dn.useRef)(0),o=(0,Dn.useRef)([]),i=(0,Dn.useRef)(new Map),l=(0,Dn.useRef)(0),u=(0,Dn.useRef)(new Map),c=(0,Dn.useCallback)((p,m)=>{let g=e.current.get(p);g!==m&&(g&&t.current?.unobserve(g),m?(m.dataset.diffCardKey=p,e.current.set(p,m),t.current?.observe(m)):e.current.delete(p))},[]);(0,Dn.useEffect)(()=>{if(a(new Set),!n||typeof IntersectionObserver>"u")return;let p=new IntersectionObserver(m=>{a(g=>{let x=new Set(g);for(let b of m){let y=b.target.dataset.diffCardKey;y&&(b.isIntersecting?x.add(y):x.delete(y))}return x.size===g.size&&[...x].every(b=>g.has(b))?g:x})},{root:n,rootMargin:zA});t.current=p;for(let m of e.current.values())p.observe(m);return()=>{p.disconnect(),t.current=null}},[n]);let d=(0,Dn.useCallback)((p,m,g,x)=>{let b=i.current,y=b.get(p);if(y&&(b.delete(p),l.current-=y.bytes),!(g>Mw)){b.set(p,{value:m,bytes:g}),l.current+=g,x&&(u.current.delete(x),u.current.set(x,p)),u.current.size>Rw&&u.current.delete(u.current.keys().next().value);for(let[N,L]of b){if(b.size<=Rw&&l.current<=Mw)break;b.delete(N),l.current-=L.bytes}}},[]),f=(0,Dn.useCallback)((p,m,g)=>{if(g&&!g.fresh){let x=i.current.get(g.key);if(x)return i.current.delete(g.key),i.current.set(g.key,x),Promise.resolve(x.value)}return new Promise((x,b)=>{let y=()=>{s.current+=1;let N=()=>{s.current-=1,o.current.shift()?.()};if(!m()){N(),x(void 0);return}p().then(L=>{g&&d(g.key,L,g.bytes(L),g.family),N(),x(L)},L=>{N(),b(L)})};s.current<GA?y():o.current.push(y)})},[d]),h=(0,Dn.useCallback)((p,m)=>(i.current.get(p)??(m?i.current.get(u.current.get(m)??""):void 0))?.value,[]);return{register:c,visible:r,run:f,peek:h}}var gt=j(Ve(),1);var He=j(le()),St=j(Ve());function Tw(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);e&&(r=r.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),t.push.apply(t,r)}return t}function At(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Tw(Object(t),!0).forEach((function(r){Gh(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):Tw(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function Gh(n,e,t){return(e=(function(r){var a=(function(s,o){if(typeof s!="object"||s===null)return s;var i=s[Symbol.toPrimitive];if(i!==void 0){var l=i.call(s,o||"default");if(typeof l!="object")return l;throw new TypeError("@@toPrimitive must return a primitive value.")}return(o==="string"?String:Number)(s)})(r,"string");return typeof a=="symbol"?a:String(a)})(e))in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function Bs(n,e){if(n==null)return{};var t,r,a=(function(o,i){if(o==null)return{};var l,u,c={},d=Object.keys(o);for(u=0;u<d.length;u++)l=d[u],i.indexOf(l)>=0||(c[l]=o[l]);return c})(n,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);for(r=0;r<s.length;r++)t=s[r],e.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(n,t)&&(a[t]=n[t])}return a}function Jt(n,e){return iv(n)||(function(t,r){var a=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(a!=null){var s,o,i,l,u=[],c=!0,d=!1;try{if(i=(a=a.call(t)).next,r===0){if(Object(a)!==a)return;c=!1}else for(;!(c=(s=i.call(a)).done)&&(u.push(s.value),u.length!==r);c=!0);}catch(f){d=!0,o=f}finally{try{if(!c&&a.return!=null&&(l=a.return(),Object(l)!==l))return}finally{if(d)throw o}}return u}})(n,e)||Uc(n,e)||uv()}function WA(n){return iv(n)||lv(n)||Uc(n)||uv()}function Ar(n){return(function(e){if(Array.isArray(e))return zh(e)})(n)||lv(n)||Uc(n)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function iv(n){if(Array.isArray(n))return n}function lv(n){if(typeof Symbol<"u"&&n[Symbol.iterator]!=null||n["@@iterator"]!=null)return Array.from(n)}function Uc(n,e){if(n){if(typeof n=="string")return zh(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);return t==="Object"&&n.constructor&&(t=n.constructor.name),t==="Map"||t==="Set"?Array.from(n):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?zh(n,e):void 0}}function zh(n,e){(e==null||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function uv(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Yh(n,e){var t=typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(!t){if(Array.isArray(n)||(t=Uc(n))||e&&n&&typeof n.length=="number"){t&&(n=t);var r=0,a=function(){};return{s:a,n:function(){return r>=n.length?{done:!0}:{done:!1,value:n[r++]}},e:function(l){throw l},f:a}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
7
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,o=!0,i=!1;return{s:function(){t=t.call(n)},n:function(){var l=t.next();return o=l.done,l},e:function(l){i=!0,s=l},f:function(){try{o||t.return==null||t.return()}finally{if(i)throw s}}}}var Rc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function eu(n,e){return n(e={exports:{}},e.exports),e.exports}var yn=eu((function(n){(function(){var e={}.hasOwnProperty;function t(){for(var r=[],a=0;a<arguments.length;a++){var s=arguments[a];if(s){var o=typeof s;if(o==="string"||o==="number")r.push(s);else if(Array.isArray(s)){if(s.length){var i=t.apply(null,s);i&&r.push(i)}}else if(o==="object"){if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]")){r.push(s.toString());continue}for(var l in s)e.call(s,l)&&s[l]&&r.push(l)}}}return r.join(" ")}n.exports?(t.default=t,n.exports=t):window.classNames=t})()})),cr={hunkClassName:"",lineClassName:"",gutterClassName:"",codeClassName:"",monotonous:!1,gutterType:"default",viewType:"split",widgets:{},hideGutter:!1,selectedChanges:[],generateAnchorID:function(){},generateLineClassName:function(){},renderGutter:function(n){var e=n.renderDefault;return(0,n.wrapInAnchor)(e())},codeEvents:{},gutterEvents:{}},cv=(0,St.createContext)(cr),jA=cv.Provider,dv=function(){return(0,St.useContext)(cv)},qA=eu((function(n,e){(function(t){function r(s){var o=s.slice(11),i=null,l=null;switch(o.indexOf('"')){case-1:i=(d=o.split(" "))[0].slice(2),l=d[1].slice(2);break;case 0:var u=o.indexOf('"',2);i=o.slice(3,u);var c=o.indexOf('"',u+1);l=c<0?o.slice(u+4):o.slice(c+3,-1);break;default:var d;i=(d=o.split(" "))[0].slice(2),l=d[1].slice(3,-1)}return{oldPath:i,newPath:l}}var a={parse:function(s){for(var o,i,l,u,c,d=[],f=2,h=s.split(`
|
|
8
|
+
`),p=h.length,m=0;m<p;){var g=h[m];if(g.indexOf("diff --git")===0){o={hunks:[],oldEndingNewLine:!0,newEndingNewLine:!0,oldPath:(c=r(g)).oldPath,newPath:c.newPath},d.push(o);var x,b=null;e:for(;x=h[++m];){var y=x.indexOf(" "),N=y>-1?x.slice(0,y):N;switch(N){case"diff":m--;break e;case"deleted":case"new":var L=x.slice(y+1);L.indexOf("file mode")===0&&(o[N==="new"?"newMode":"oldMode"]=L.slice(10));break;case"similarity":o.similarity=parseInt(x.split(" ")[2],10);break;case"index":var A=x.slice(y+1).split(" "),w=A[0].split("..");o.oldRevision=w[0],o.newRevision=w[1],A[1]&&(o.oldMode=o.newMode=A[1]);break;case"copy":case"rename":var v=x.slice(y+1);v.indexOf("from")===0?o.oldPath=v.slice(5):o.newPath=v.slice(3),b=N;break;case"---":var T=x.slice(y+1),P=h[++m].slice(4);T==="/dev/null"?(P=P.slice(2),b="add"):P==="/dev/null"?(T=T.slice(2),b="delete"):(b="modify",T=T.slice(2),P=P.slice(2)),T&&(o.oldPath=T),P&&(o.newPath=P),f=5;break e}}o.type=b||"modify"}else if(g.indexOf("Binary")===0)o.isBinary=!0,o.type=g.indexOf("/dev/null and")>=0?"add":g.indexOf("and /dev/null")>=0?"delete":"modify",f=2,o=null;else if(f===5)if(g.indexOf("@@")===0){var O=/^@@\s+-([0-9]+)(,([0-9]+))?\s+\+([0-9]+)(,([0-9]+))?/.exec(g);i={content:g,oldStart:O[1]-0,newStart:O[4]-0,oldLines:O[3]-0||1,newLines:O[6]-0||1,changes:[]},o.hunks.push(i),l=i.oldStart,u=i.newStart}else{var C=g.slice(0,1),I={content:g.slice(1)};switch(C){case"+":I.type="insert",I.isInsert=!0,I.lineNumber=u,u++;break;case"-":I.type="delete",I.isDelete=!0,I.lineNumber=l,l++;break;case" ":I.type="normal",I.isNormal=!0,I.oldLineNumber=l,I.newLineNumber=u,l++,u++;break;case"\\":var H=i.changes[i.changes.length-1];H.isDelete||(o.newEndingNewLine=!1),H.isInsert||(o.oldEndingNewLine=!1)}I.type&&i.changes.push(I)}m++}return d}};n.exports=a})()}));function Hs(n){return n.type==="insert"}function ia(n){return n.type==="delete"}function Na(n){return n.type==="normal"}function VA(n,e){var t=e.nearbySequences==="zip"?(function(r){var a=r.reduce((function(s,o,i){var l=Jt(s,3),u=l[0],c=l[1],d=l[2];return c?Hs(o)&&d>=0?(u.splice(d+1,0,o),[u,o,d+2]):(u.push(o),[u,o,ia(o)&&ia(c)?d:i]):(u.push(o),[u,o,ia(o)?i:-1])}),[[],null,-1]);return Jt(a,1)[0]})(n.changes):n.changes;return At(At({},n),{},{isPlain:!1,changes:t})}function fv(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=(function(r){if(r.startsWith("diff --git"))return r;var a=r.indexOf(`
|
|
9
9
|
`),s=r.indexOf(`
|
|
10
10
|
`,a+1),o=r.slice(0,a),i=r.slice(a+1,s),l=o.split(" ").slice(1,-3).join(" "),u=i.split(" ").slice(1,-3).join(" ");return["diff --git a/".concat(l," b/").concat(u),"index 1111111..2222222 100644","--- a/".concat(l),"+++ b/".concat(u),r.slice(s+1)].join(`
|
|
11
|
-
`)})(n.trimStart());return FA.parse(t).map((function(r){return(function(a,s){var o=a.hunks.map((function(i){return EA(i,s)}));return At(At({},a),{},{hunks:o})})(r,e)}))}function uv(n){return n[0]}function cv(n){return n[n.length-1]}function Hh(n){return["".concat(n,"Start"),"".concat(n,"Lines")]}function Es(n){return n==="old"?function(e){return Bs(e)?-1:Ia(e)?e.oldLineNumber:e.lineNumber}:function(e){return sa(e)?-1:Ia(e)?e.newLineNumber:e.lineNumber}}function $h(n,e){return function(t,r){var a=t[n],s=a+t[e];return r>=a&&r<s}}function dv(n,e){return function(t,r,a){var s=t[n]+t[e],o=r[n];return a>=s&&a<o}}function fv(n){var e=Es(n),t=(function(r){var a=en(Hh(r),2),s=$h(a[0],a[1]);return function(o,i){return o.find((function(l){return s(l,i)}))}})(n);return function(r,a){var s=t(r,a);if(s)return s.changes.find((function(o){return e(o)===a}))}}function Kh(n){var e=n==="old"?"new":"old",t=en(Hh(n),2),r=t[0],a=t[1],s=en(Hh(e),2),o=s[0],i=s[1],l=Es(n),u=Es(e),c=$h(r,a),d=dv(r,a);return function(f,h){var p=uv(f);if(h<p[r]){var m=p[r]-h;return p[o]-m}var g=cv(f);if(g[r]+g[a]<=h){var x=h-g[r]-g[a];return g[o]+g[i]+x}for(var w=0;w<f.length;w++){var y=f[w],C=f[w+1];if(c(y,h)){var k=y.changes.findIndex((function(U){return l(U)===h})),v=y.changes[k];if(Ia(v))return u(v);var b=sa(v)?k+1:k-1,P=y.changes[b];if(!P)return-1;var N=Bs(v)?"delete":"insert";return P.type===N?u(P):-1}if(d(y,C,h)){var M=h-y[r]-y[a];return y[o]+y[i]+M}}throw new Error("Unexpected line position ".concat(h))}}var BA=function(n,e,t,r){for(var a=n.length,s=t+(r?1:-1);r?s--:++s<a;)if(e(n[s],s,n))return s;return-1},OA=function(){this.__data__=[],this.size=0},hv=function(n,e){return n===e||n!=n&&e!=e},Ec=function(n,e){for(var t=n.length;t--;)if(hv(n[t][0],e))return t;return-1},_A=Array.prototype.splice,HA=function(n){var e=this.__data__,t=Ec(e,n);return!(t<0)&&(t==e.length-1?e.pop():_A.call(e,t,1),--this.size,!0)},UA=function(n){var e=this.__data__,t=Ec(e,n);return t<0?void 0:e[t][1]},GA=function(n){return Ec(this.__data__,n)>-1},zA=function(n,e){var t=this.__data__,r=Ec(t,n);return r<0?(++this.size,t.push([n,e])):t[r][1]=e,this};function pi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}pi.prototype.clear=OA,pi.prototype.delete=HA,pi.prototype.get=UA,pi.prototype.has=GA,pi.prototype.set=zA;var Bc=pi,WA=function(){this.__data__=new Bc,this.size=0},jA=function(n){var e=this.__data__,t=e.delete(n);return this.size=e.size,t},qA=function(n){return this.__data__.get(n)},VA=function(n){return this.__data__.has(n)},pv=typeof Cc=="object"&&Cc&&Cc.Object===Object&&Cc,$A=typeof self=="object"&&self&&self.Object===Object&&self,Qa=pv||$A||Function("return this")(),Aa=Qa.Symbol,mv=Object.prototype,KA=mv.hasOwnProperty,XA=mv.toString,Vl=Aa?Aa.toStringTag:void 0,YA=function(n){var e=KA.call(n,Vl),t=n[Vl];try{n[Vl]=void 0;var r=!0}catch{}var a=XA.call(n);return r&&(e?n[Vl]=t:delete n[Vl]),a},JA=Object.prototype.toString,ZA=function(n){return JA.call(n)},Nw=Aa?Aa.toStringTag:void 0,bi=function(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Nw&&Nw in Object(n)?YA(n):ZA(n)},Kl=function(n){var e=typeof n;return n!=null&&(e=="object"||e=="function")},gv=function(n){if(!Kl(n))return!1;var e=bi(n);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Dh=Qa["__core-js_shared__"],Rw=(function(){var n=/[^.]+$/.exec(Dh&&Dh.keys&&Dh.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})(),QA=function(n){return!!Rw&&Rw in n},eP=Function.prototype.toString,mo=function(n){if(n!=null){try{return eP.call(n)}catch{}try{return n+""}catch{}}return""},tP=/^\[object .+?Constructor\]$/,nP=Function.prototype,rP=Object.prototype,aP=nP.toString,sP=rP.hasOwnProperty,oP=RegExp("^"+aP.call(sP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),iP=function(n){return!(!Kl(n)||QA(n))&&(gv(n)?oP:tP).test(mo(n))},lP=function(n,e){return n?.[e]},go=function(n,e){var t=lP(n,e);return iP(t)?t:void 0},Xl=go(Qa,"Map"),Yl=go(Object,"create"),uP=function(){this.__data__=Yl?Yl(null):{},this.size=0},cP=function(n){var e=this.has(n)&&delete this.__data__[n];return this.size-=e?1:0,e},dP=Object.prototype.hasOwnProperty,fP=function(n){var e=this.__data__;if(Yl){var t=e[n];return t==="__lodash_hash_undefined__"?void 0:t}return dP.call(e,n)?e[n]:void 0},hP=Object.prototype.hasOwnProperty,pP=function(n){var e=this.__data__;return Yl?e[n]!==void 0:hP.call(e,n)},mP=function(n,e){var t=this.__data__;return this.size+=this.has(n)?0:1,t[n]=Yl&&e===void 0?"__lodash_hash_undefined__":e,this};function mi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}mi.prototype.clear=uP,mi.prototype.delete=cP,mi.prototype.get=fP,mi.prototype.has=pP,mi.prototype.set=mP;var Mw=mi,gP=function(){this.size=0,this.__data__={hash:new Mw,map:new(Xl||Bc),string:new Mw}},xP=function(n){var e=typeof n;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?n!=="__proto__":n===null},Oc=function(n,e){var t=n.__data__;return xP(e)?t[typeof e=="string"?"string":"hash"]:t.map},yP=function(n){var e=Oc(this,n).delete(n);return this.size-=e?1:0,e},bP=function(n){return Oc(this,n).get(n)},wP=function(n){return Oc(this,n).has(n)},vP=function(n,e){var t=Oc(this,n),r=t.size;return t.set(n,e),this.size+=t.size==r?0:1,this};function gi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}gi.prototype.clear=gP,gi.prototype.delete=yP,gi.prototype.get=bP,gi.prototype.has=wP,gi.prototype.set=vP;var _c=gi,kP=function(n,e){var t=this.__data__;if(t instanceof Bc){var r=t.__data__;if(!Xl||r.length<199)return r.push([n,e]),this.size=++t.size,this;t=this.__data__=new _c(r)}return t.set(n,e),this.size=t.size,this};function xi(n){var e=this.__data__=new Bc(n);this.size=e.size}xi.prototype.clear=WA,xi.prototype.delete=jA,xi.prototype.get=qA,xi.prototype.has=VA,xi.prototype.set=kP;var Rc=xi,SP=function(n){return this.__data__.set(n,"__lodash_hash_undefined__"),this},CP=function(n){return this.__data__.has(n)};function Mc(n){var e=-1,t=n==null?0:n.length;for(this.__data__=new _c;++e<t;)this.add(n[e])}Mc.prototype.add=Mc.prototype.push=SP,Mc.prototype.has=CP;var LP=Mc,IP=function(n,e){for(var t=-1,r=n==null?0:n.length;++t<r;)if(e(n[t],t,n))return!0;return!1},AP=function(n,e){return n.has(e)},xv=function(n,e,t,r,a,s){var o=1&t,i=n.length,l=e.length;if(i!=l&&!(o&&l>i))return!1;var u=s.get(n),c=s.get(e);if(u&&c)return u==e&&c==n;var d=-1,f=!0,h=2&t?new LP:void 0;for(s.set(n,e),s.set(e,n);++d<i;){var p=n[d],m=e[d];if(r)var g=o?r(m,p,d,e,n,s):r(p,m,d,n,e,s);if(g!==void 0){if(g)continue;f=!1;break}if(h){if(!IP(e,(function(x,w){if(!AP(h,w)&&(p===x||a(p,x,t,r,s)))return h.push(w)}))){f=!1;break}}else if(p!==m&&!a(p,m,t,r,s)){f=!1;break}}return s.delete(n),s.delete(e),f},Tw=Qa.Uint8Array,PP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r,a){t[++e]=[a,r]})),t},NP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r){t[++e]=r})),t},Dw=Aa?Aa.prototype:void 0,Fh=Dw?Dw.valueOf:void 0,RP=function(n,e,t,r,a,s,o){switch(t){case"[object DataView]":if(n.byteLength!=e.byteLength||n.byteOffset!=e.byteOffset)return!1;n=n.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(n.byteLength!=e.byteLength||!s(new Tw(n),new Tw(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return hv(+n,+e);case"[object Error]":return n.name==e.name&&n.message==e.message;case"[object RegExp]":case"[object String]":return n==e+"";case"[object Map]":var i=PP;case"[object Set]":var l=1&r;if(i||(i=NP),n.size!=e.size&&!l)return!1;var u=o.get(n);if(u)return u==e;r|=2,o.set(n,e);var c=xv(i(n),i(e),r,a,s,o);return o.delete(n),c;case"[object Symbol]":if(Fh)return Fh.call(n)==Fh.call(e)}return!1},yv=function(n,e){for(var t=-1,r=e.length,a=n.length;++t<r;)n[a+t]=e[t];return n},_r=Array.isArray,MP=function(n,e,t){var r=e(n);return _r(n)?r:yv(r,t(n))},TP=function(n,e){for(var t=-1,r=n==null?0:n.length,a=0,s=[];++t<r;){var o=n[t];e(o,t,n)&&(s[a++]=o)}return s},DP=function(){return[]},FP=Object.prototype.propertyIsEnumerable,Fw=Object.getOwnPropertySymbols,EP=Fw?function(n){return n==null?[]:(n=Object(n),TP(Fw(n),(function(e){return FP.call(n,e)})))}:DP,BP=function(n,e){for(var t=-1,r=Array(n);++t<n;)r[t]=e(t);return r},yi=function(n){return n!=null&&typeof n=="object"},Ew=function(n){return yi(n)&&bi(n)=="[object Arguments]"},bv=Object.prototype,OP=bv.hasOwnProperty,_P=bv.propertyIsEnumerable,Xh=Ew((function(){return arguments})())?Ew:function(n){return yi(n)&&OP.call(n,"callee")&&!_P.call(n,"callee")},HP=function(){return!1},Uh=Zl((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t?Qa.Buffer:void 0,s=(a?a.isBuffer:void 0)||HP;n.exports=s})),UP=/^(?:0|[1-9]\d*)$/,wv=function(n,e){var t=typeof n;return!!(e=e??9007199254740991)&&(t=="number"||t!="symbol"&&UP.test(n))&&n>-1&&n%1==0&&n<e},Yh=function(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=9007199254740991},Vt={};Vt["[object Float32Array]"]=Vt["[object Float64Array]"]=Vt["[object Int8Array]"]=Vt["[object Int16Array]"]=Vt["[object Int32Array]"]=Vt["[object Uint8Array]"]=Vt["[object Uint8ClampedArray]"]=Vt["[object Uint16Array]"]=Vt["[object Uint32Array]"]=!0,Vt["[object Arguments]"]=Vt["[object Array]"]=Vt["[object ArrayBuffer]"]=Vt["[object Boolean]"]=Vt["[object DataView]"]=Vt["[object Date]"]=Vt["[object Error]"]=Vt["[object Function]"]=Vt["[object Map]"]=Vt["[object Number]"]=Vt["[object Object]"]=Vt["[object RegExp]"]=Vt["[object Set]"]=Vt["[object String]"]=Vt["[object WeakMap]"]=!1;var GP=function(n){return yi(n)&&Yh(n.length)&&!!Vt[bi(n)]},zP=function(n){return function(e){return n(e)}},Bw=Zl((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t&&pv.process,s=(function(){try{var o=r&&r.require&&r.require("util").types;return o||a&&a.binding&&a.binding("util")}catch{}})();n.exports=s})),Ow=Bw&&Bw.isTypedArray,vv=Ow?zP(Ow):GP,WP=Object.prototype.hasOwnProperty,jP=function(n,e){var t=_r(n),r=!t&&Xh(n),a=!t&&!r&&Uh(n),s=!t&&!r&&!a&&vv(n),o=t||r||a||s,i=o?BP(n.length,String):[],l=i.length;for(var u in n)!e&&!WP.call(n,u)||o&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||wv(u,l))||i.push(u);return i},qP=Object.prototype,VP=function(n){var e=n&&n.constructor;return n===(typeof e=="function"&&e.prototype||qP)},$P=(function(n,e){return function(t){return n(e(t))}})(Object.keys,Object),KP=Object.prototype.hasOwnProperty,XP=function(n){if(!VP(n))return $P(n);var e=[];for(var t in Object(n))KP.call(n,t)&&t!="constructor"&&e.push(t);return e},Jh=function(n){return n!=null&&Yh(n.length)&&!gv(n)},Zh=function(n){return Jh(n)?jP(n):XP(n)},_w=function(n){return MP(n,Zh,EP)},YP=Object.prototype.hasOwnProperty,JP=function(n,e,t,r,a,s){var o=1&t,i=_w(n),l=i.length;if(l!=_w(e).length&&!o)return!1;for(var u=l;u--;){var c=i[u];if(!(o?c in e:YP.call(e,c)))return!1}var d=s.get(n),f=s.get(e);if(d&&f)return d==e&&f==n;var h=!0;s.set(n,e),s.set(e,n);for(var p=o;++u<l;){var m=n[c=i[u]],g=e[c];if(r)var x=o?r(g,m,c,e,n,s):r(m,g,c,n,e,s);if(!(x===void 0?m===g||a(m,g,t,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var w=n.constructor,y=e.constructor;w==y||!("constructor"in n)||!("constructor"in e)||typeof w=="function"&&w instanceof w&&typeof y=="function"&&y instanceof y||(h=!1)}return s.delete(n),s.delete(e),h},Gh=go(Qa,"DataView"),zh=go(Qa,"Promise"),Wh=go(Qa,"Set"),jh=go(Qa,"WeakMap"),ZP=mo(Gh),QP=mo(Xl),eN=mo(zh),tN=mo(Wh),nN=mo(jh),po=bi;(Gh&&po(new Gh(new ArrayBuffer(1)))!="[object DataView]"||Xl&&po(new Xl)!="[object Map]"||zh&&po(zh.resolve())!="[object Promise]"||Wh&&po(new Wh)!="[object Set]"||jh&&po(new jh)!="[object WeakMap]")&&(po=function(n){var e=bi(n),t=e=="[object Object]"?n.constructor:void 0,r=t?mo(t):"";if(r)switch(r){case ZP:return"[object DataView]";case QP:return"[object Map]";case eN:return"[object Promise]";case tN:return"[object Set]";case nN:return"[object WeakMap]"}return e});var Hw=po,Lc="[object Object]",Uw=Object.prototype.hasOwnProperty,rN=function(n,e,t,r,a,s){var o=_r(n),i=_r(e),l=o?"[object Array]":Hw(n),u=i?"[object Array]":Hw(e),c=(l=l=="[object Arguments]"?Lc:l)==Lc,d=(u=u=="[object Arguments]"?Lc:u)==Lc,f=l==u;if(f&&Uh(n)){if(!Uh(e))return!1;o=!0,c=!1}if(f&&!c)return s||(s=new Rc),o||vv(n)?xv(n,e,t,r,a,s):RP(n,e,l,t,r,a,s);if(!(1&t)){var h=c&&Uw.call(n,"__wrapped__"),p=d&&Uw.call(e,"__wrapped__");if(h||p){var m=h?n.value():n,g=p?e.value():e;return s||(s=new Rc),a(m,g,t,r,s)}}return!!f&&(s||(s=new Rc),JP(n,e,t,r,a,s))},Hc=function n(e,t,r,a,s){return e===t||(e==null||t==null||!yi(e)&&!yi(t)?e!=e&&t!=t:rN(e,t,r,a,n,s))},aN=function(n,e,t,r){var a=t.length,s=a,o=!r;if(n==null)return!s;for(n=Object(n);a--;){var i=t[a];if(o&&i[2]?i[1]!==n[i[0]]:!(i[0]in n))return!1}for(;++a<s;){var l=(i=t[a])[0],u=n[l],c=i[1];if(o&&i[2]){if(u===void 0&&!(l in n))return!1}else{var d=new Rc;if(r)var f=r(u,c,l,n,e,d);if(!(f===void 0?Hc(c,u,3,r,d):f))return!1}}return!0},kv=function(n){return n==n&&!Kl(n)},sN=function(n){for(var e=Zh(n),t=e.length;t--;){var r=e[t],a=n[r];e[t]=[r,a,kv(a)]}return e},Sv=function(n,e){return function(t){return t!=null&&t[n]===e&&(e!==void 0||n in Object(t))}},oN=function(n){var e=sN(n);return e.length==1&&e[0][2]?Sv(e[0][0],e[0][1]):function(t){return t===n||aN(t,n,e)}},Uc=function(n){return typeof n=="symbol"||yi(n)&&bi(n)=="[object Symbol]"},iN=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,lN=/^\w*$/,Qh=function(n,e){if(_r(n))return!1;var t=typeof n;return!(t!="number"&&t!="symbol"&&t!="boolean"&&n!=null&&!Uc(n))||lN.test(n)||!iN.test(n)||e!=null&&n in Object(e)};function ep(n,e){if(typeof n!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var t=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=t.cache;if(s.has(a))return s.get(a);var o=n.apply(this,r);return t.cache=s.set(a,o)||s,o};return t.cache=new(ep.Cache||_c),t}ep.Cache=_c;var uN=ep,cN=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dN=/\\(\\)?/g,fN=(function(n){var e=uN(n,(function(r){return t.size===500&&t.clear(),r})),t=e.cache;return e})((function(n){var e=[];return n.charCodeAt(0)===46&&e.push(""),n.replace(cN,(function(t,r,a,s){e.push(a?s.replace(dN,"$1"):r||t)})),e})),Cv=function(n,e){for(var t=-1,r=n==null?0:n.length,a=Array(r);++t<r;)a[t]=e(n[t],t,n);return a},Gw=Aa?Aa.prototype:void 0,zw=Gw?Gw.toString:void 0,hN=function n(e){if(typeof e=="string")return e;if(_r(e))return Cv(e,n)+"";if(Uc(e))return zw?zw.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t},pN=function(n){return n==null?"":hN(n)},Lv=function(n,e){return _r(n)?n:Qh(n,e)?[n]:fN(pN(n))},Gc=function(n){if(typeof n=="string"||Uc(n))return n;var e=n+"";return e=="0"&&1/n==-1/0?"-0":e},Iv=function(n,e){for(var t=0,r=(e=Lv(e,n)).length;n!=null&&t<r;)n=n[Gc(e[t++])];return t&&t==r?n:void 0},mN=function(n,e,t){var r=n==null?void 0:Iv(n,e);return r===void 0?t:r},gN=function(n,e){return n!=null&&e in Object(n)},xN=function(n,e,t){for(var r=-1,a=(e=Lv(e,n)).length,s=!1;++r<a;){var o=Gc(e[r]);if(!(s=n!=null&&t(n,o)))break;n=n[o]}return s||++r!=a?s:!!(a=n==null?0:n.length)&&Yh(a)&&wv(o,a)&&(_r(n)||Xh(n))},yN=function(n,e){return n!=null&&xN(n,e,gN)},bN=function(n,e){return Qh(n)&&kv(e)?Sv(Gc(n),e):function(t){var r=mN(t,n);return r===void 0&&r===e?yN(t,n):Hc(e,r,3)}},wN=function(n){return n},vN=function(n){return function(e){return e?.[n]}},kN=function(n){return function(e){return Iv(e,n)}},SN=function(n){return Qh(n)?vN(Gc(n)):kN(n)},zc=function(n){return typeof n=="function"?n:n==null?wN:typeof n=="object"?_r(n)?bN(n[0],n[1]):oN(n):SN(n)},CN=/\s/,LN=function(n){for(var e=n.length;e--&&CN.test(n.charAt(e)););return e},IN=/^\s+/,AN=function(n){return n&&n.slice(0,LN(n)+1).replace(IN,"")},PN=/^[-+]0x[0-9a-f]+$/i,NN=/^0b[01]+$/i,RN=/^0o[0-7]+$/i,MN=parseInt,TN=function(n){if(typeof n=="number")return n;if(Uc(n))return NaN;if(Kl(n)){var e=typeof n.valueOf=="function"?n.valueOf():n;n=Kl(e)?e+"":e}if(typeof n!="string")return n===0?n:+n;n=AN(n);var t=NN.test(n);return t||RN.test(n)?MN(n.slice(2),t?2:8):PN.test(n)?NaN:+n},DN=function(n){return n?(n=TN(n))===1/0||n===-1/0?17976931348623157e292*(n<0?-1:1):n==n?n:0:n===0?n:0},FN=function(n){var e=DN(n),t=e%1;return e==e?t?e-t:e:0},EN=Math.max,BN=Math.min,Ww=function(n,e,t){var r=n==null?0:n.length;if(!r)return-1;var a=r-1;return t!==void 0&&(a=FN(t),a=t<0?EN(r+a,0):BN(a,r-1)),BA(n,zc(e),a,!0)},Jl=Es("old"),ON=Es("new");function jw(n){var e=n.oldStart;return[e,e+n.oldLines-1]}function Tc(n){if(!n.length)return null;var e=n.reduce((function(o,i){return Ia(i)||(o.isPlain=!1),Bs(i)||(o.oldLines=o.oldLines+1,o.oldStart===-1&&(o.oldStart=Jl(i))),sa(i)||(o.newLines=o.newLines+1,o.newStart===-1&&(o.newStart=ON(i))),o}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),t=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return At(At({},e),{},{content:"@@ -".concat(t,",").concat(r," +").concat(a,",").concat(s),changes:n})}function _N(n,e,t){return Tc(n.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:t+a,content:""+r}})))}function Ic(n,e,t){var r=n.changes,a=r.findIndex((function(i){return Jl(i)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var i=Ww(r,(function(l){return!Bs(l)}),a-1);return i===-1?a:i+1})();if(t===void 0)return Tc(r.slice(s));var o=Ww(r,(function(i){return Jl(i)<=t}));return Tc(r.slice(s,o===-1?void 0:o))}function $l(n,e){if(!n)return e;if(!e)return n;var t=en(jw(n),2),r=t[0],a=t[1],s=en(jw(e),2),o=s[0],i=s[1];if(a+1===o)return Tc([].concat(Sr(n.changes),Sr(e.changes)));if(r<=o&&a>=i){if(n.isPlain&&!e.isPlain){var l=Ic(n,r,o),u=Ic(n,i+1);return $l($l(l,e),u)}return n}return n.isPlain?$l(Ic(n,r,o),e):$l(n,Ic(e,a+1))}function HN(n,e){var t=cv(n);if(!t)return[e];if(t.oldStart+t.oldLines<e.oldStart)return n.concat(e);var r=$l(t,e);return r?[].concat(Sr(n.slice(0,-1)),[r]):n}function UN(n,e){var t=Jl(e.changes[0]),r=n.findIndex((function(a){var s=a.changes;return!!s.length&&Jl(s[0])>=t}));return(r===-1?n.concat(e):[].concat(Sr(n.slice(0,r)),[e],Sr(n.slice(r)))).reduce(HN,[])}function Ds(n){if(!n)throw new Error("change is not provided");if(Ia(n))return"N".concat(n.oldLineNumber);var e=Bs(n)?"I":"D";return"".concat(e).concat(n.lineNumber)}var GN=Kh("old"),Eh=Es("old"),qw=$h("oldStart","oldLines"),zN=dv("oldStart","oldLines");function qh(n,e,t){var r=(function(h,p){if(!h.length)return-1;var m=uv(h);if(p<m.oldStart||qw(m,p))return 0;for(var g=1;g<h.length;g++){var x=h[g];if(qw(x,p))return g;var w=h[g-1];if(zN(w,x,p))return g}return-1})(n,e);if(r===-1)return[[e,t]];var a=n[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Ia(h)})),o=a.oldStart+Math.max(s,0);return o>=t?[[e,t]]:[[e,o]].concat(Sr(qh(n,o+1,t)))}var i=a.changes,l=(function(h,p){var m=h.changes,g=m.findIndex((function(w){return Eh(w)===p}));if(g<0)return-1;for(var x=g;x<m.length;x++)if(Ia(m[x]))return x;return-1})(a,e);if(l===-1)return[];var u=i[l],c=Eh(u),d=i.slice(l+1).findIndex((function(h){return!Ia(h)})),f=Eh(u)+Math.max(d,0);return f>=t?[[c,t]]:[[c,f]].concat(Sr(qh(n,f+1,t)))}function Av(n,e,t,r){return qh(n,t,r).reduce((function(a,s){return(function(o,i,l){var u=en(l,2),c=u[0],d=u[1],f=(typeof i=="string"?i.split(`
|
|
12
|
-
`):i).slice(Math.max(c,1)-1,d-1);if(!f.length)return o;var h=_N(f,c,GN(o,c));return h?UN(o,h):o})(a,e,s)}),n)}function Pv(n,e){if(!n)return e.oldStart-1;var t=n.oldStart+n.oldLines;return e.oldStart-t}var Wc=Es("old"),jc=Es("new"),YG=fv("old"),JG=fv("new"),ZG=Kh("new"),QG=Kh("old"),Vw=(function(){try{var n=go(Object,"defineProperty");return n({},"",{}),n}catch{}})(),tp=function(n,e,t){e=="__proto__"&&Vw?Vw(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0}):n[e]=t},WN=function(n){return function(e,t,r){for(var a=-1,s=Object(e),o=r(e),i=o.length;i--;){var l=o[n?i:++a];if(t(s[l],l,s)===!1)break}return e}},jN=WN(),Nv=function(n,e){return n&&jN(n,e,Zh)},Rv=function(n,e){var t={};return e=zc(e),Nv(n,(function(r,a,s){tp(t,a,e(r,a,s))})),t},qN=["changeKey","text","tokens","renderToken"],$w=function n(e,t){var r=e.type,a=e.value,s=e.markType,o=e.properties,i=e.className,l=e.children,u=function(d){return(0,Oe.jsx)("span",{className:d,children:a||l&&l.map(n)},t)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=o&&o.className;return u(wn(i||c))}};function VN(n){if(!Array.isArray(n))return!0;if(n.length>1)return!1;if(n.length===1){var e=en(n,1)[0];return e.type==="text"&&!e.value}return!0}function $N(n){var e=n.changeKey,t=n.text,r=n.tokens,a=n.renderToken,s=Fs(n,qN),o=a?function(i,l){return a(i,$w,l)}:$w;return(0,Oe.jsx)("td",At(At({},s),{},{"data-change-key":e,children:r?VN(r)?" ":r.map(o):t||" "}))}var Mv=(0,kt.memo)($N);function Tv(n,e){return function(){var t=e==="old"?Wc(n):jc(n);return t===-1?void 0:t}}function Dv(n,e){return function(t){return n&&t?(0,Oe.jsx)("a",{href:e?"#"+e:void 0,children:t}):t}}function Dc(n,e){return e?function(t){n(),e(t)}:n}function Kw(n,e,t,r){return(0,kt.useMemo)((function(){var a=Rv(n,(function(s){return function(o){return s&&s(e,o)}}));return a.onMouseEnter=Dc(t,a.onMouseEnter),a.onMouseLeave=Dc(r,a.onMouseLeave),a}),[n,t,r,e])}function Xw(n,e,t,r,a,s,o,i,l){var u={change:e,side:r,inHoverState:i,renderDefault:Tv(e,r),wrapInAnchor:Dv(a,s)};return(0,Oe.jsx)("td",At(At({className:n},o),{},{"data-change-key":t,children:l(u)}))}function KN(n){var e,t,r,a=n.change,s=n.selected,o=n.tokens,i=n.className,l=n.generateLineClassName,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.gutterAnchor,m=n.generateAnchorID,g=n.renderToken,x=n.renderGutter,w=a.type,y=a.content,C=Ds(a),k=(e=en((0,kt.useState)(!1),2),t=e[0],r=e[1],[t,(0,kt.useCallback)((function(){return r(!0)}),[]),(0,kt.useCallback)((function(){return r(!1)}),[])]),v=en(k,3),b=v[0],P=v[1],N=v[2],M=(0,kt.useMemo)((function(){return{change:a}}),[a]),U=Kw(d,M,P,N),I=Kw(f,M,P,N),A=m(a),G=l({changes:[a],defaultGenerate:function(){return i}}),V=wn("diff-gutter","diff-gutter-".concat(w),u,{"diff-gutter-selected":s}),K=wn("diff-code","diff-code-".concat(w),c,{"diff-code-selected":s});return(0,Oe.jsxs)("tr",{id:A,className:wn("diff-line",G),children:[!h&&Xw(V,a,C,"old",p,A,U,b,x),!h&&Xw(V,a,C,"new",p,A,U,b,x),(0,Oe.jsx)(Mv,At({className:K,changeKey:C,text:y,tokens:o,renderToken:g},I))]})}var XN=(0,kt.memo)(KN);function YN(n){var e=n.hideGutter,t=n.element;return(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:t})})}var JN=["hideGutter","selectedChanges","tokens","lineClassName"],ZN=["hunk","widgets","className"];function QN(n){var e=n.hunk,t=n.widgets,r=n.className,a=Fs(n,ZN),s=(function(o,i){return o.reduce((function(l,u){var c=Ds(u);l.push(["change",c,u]);var d=i[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,t);return(0,Oe.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=en(i,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,m=l.tokens,g=l.lineClassName,x=Fs(l,JN);if(c==="change"){var w=sa(f)?"old":"new",y=sa(f)?Wc(f):jc(f),C=m?m[w][y-1]:null;return(0,Oe.jsx)(XN,At({className:g,change:f,hideGutter:h,selected:p.includes(d),tokens:C},x),"change".concat(d))}return c==="widget"?(0,Oe.jsx)(YN,{hideGutter:h,element:f},"widget".concat(d)):null})(o,a)}))})}var Fv=0;function Ac(n,e,t,r){var a=(0,kt.useCallback)((function(){return e(n)}),[n,e]),s=(0,kt.useCallback)((function(){return e("")}),[e]);return(0,kt.useMemo)((function(){var o=Rv(r,(function(i){return function(l){return i&&i({side:n,change:t},l)}}));return o.onMouseEnter=Dc(a,o.onMouseEnter),o.onMouseLeave=Dc(s,o.onMouseLeave),o}),[t,r,a,n,s])}function Bh(n){var e=n.change,t=n.side,r=n.selected,a=n.tokens,s=n.gutterClassName,o=n.codeClassName,i=n.gutterEvents,l=n.codeEvents,u=n.anchorID,c=n.gutterAnchor,d=n.gutterAnchorTarget,f=n.hideGutter,h=n.hover,p=n.renderToken,m=n.renderGutter;if(!e){var g=wn("diff-gutter","diff-gutter-omit",s),x=wn("diff-code","diff-code-omit",o);return[!f&&(0,Oe.jsx)("td",{className:g},"gutter"),(0,Oe.jsx)("td",{className:x},"code")]}var w=e.type,y=e.content,C=Ds(e),k=t===Fv?"old":"new",v=At({id:u||void 0,className:wn("diff-gutter","diff-gutter-".concat(w),Oh({"diff-gutter-selected":r},"diff-line-hover-"+k,h),s),children:m({change:e,side:k,inHoverState:h,renderDefault:Tv(e,k),wrapInAnchor:Dv(c,d)})},i),b=wn("diff-code","diff-code-".concat(w),Oh({"diff-code-selected":r},"diff-line-hover-"+k,h),o);return[!f&&(0,Oe.jsx)("td",At(At({},v),{},{"data-change-key":C}),"gutter"),(0,Oe.jsx)(Mv,At({className:b,changeKey:C,text:y,tokens:a,renderToken:p},l),"code")]}function eR(n){var e=n.className,t=n.oldChange,r=n.newChange,a=n.oldSelected,s=n.newSelected,o=n.oldTokens,i=n.newTokens,l=n.monotonous,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.generateAnchorID,m=n.generateLineClassName,g=n.gutterAnchor,x=n.renderToken,w=n.renderGutter,y=en((0,kt.useState)(""),2),C=y[0],k=y[1],v=Ac("old",k,t,d),b=Ac("new",k,r,d),P=Ac("old",k,t,f),N=Ac("new",k,r,f),M=t&&p(t),U=r&&p(r),I=m({changes:[t,r],defaultGenerate:function(){return e}}),A={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:w},G=At(At({},A),{},{change:t,side:Fv,selected:a,tokens:o,gutterEvents:v,codeEvents:P,anchorID:M,gutterAnchor:g,gutterAnchorTarget:M,hover:C==="old"}),V=At(At({},A),{},{change:r,side:1,selected:s,tokens:i,gutterEvents:b,codeEvents:N,anchorID:t===r?null:U,gutterAnchor:g,gutterAnchorTarget:t===r?M:U,hover:C==="new"});if(l)return(0,Oe.jsx)("tr",{className:wn("diff-line",I),children:Bh(t?G:V)});var K=(function(L,R){return L&&!R?"diff-line-old-only":!L&&R?"diff-line-new-only":L===R?"diff-line-normal":"diff-line-compare"})(t,r);return(0,Oe.jsxs)("tr",{className:wn("diff-line",K,I),children:[Bh(G),Bh(V)]})}var tR=(0,kt.memo)(eR);function nR(n){var e=n.hideGutter,t=n.oldElement,r=n.newElement;return n.monotonous?(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t||r})}):t===r?(0,Oe.jsx)("tr",{className:"diff-widget",children:(0,Oe.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:t})}):(0,Oe.jsxs)("tr",{className:"diff-widget",children:[(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t}),(0,Oe.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var rR=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],aR=["hunk","widgets","className"];function Pc(n,e){return(n?Ds(n):"00")+(e?Ds(e):"00")}function sR(n){var e=n.hunk,t=n.widgets,r=n.className,a=Fs(n,aR),s=(function(o,i){for(var l=function(x){if(!x)return null;var w=Ds(x);return i[w]||null},u=[],c=0;c<o.length;c++){var d=o[c];if(Ia(d))u.push(["change",Pc(d,d),d,d]);else if(sa(d)){var f=o[c+1];f&&Bs(f)?(c+=1,u.push(["change",Pc(d,f),d,f])):u.push(["change",Pc(d,null),d,null])}else u.push(["change",Pc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),m=l(h[3]);if(p||m){var g=h[1];u.push(["widget",g,p,m])}}return u})(e.changes,t);return(0,Oe.jsx)("tbody",{className:wn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=en(i,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,m=l.monotonous,g=l.hideGutter,x=l.tokens,w=l.lineClassName,y=Fs(l,rR);if(c==="change"){var C=!!f&&p.includes(Ds(f)),k=!!h&&p.includes(Ds(h)),v=f&&x?x.old[Wc(f)-1]:null,b=h&&x?x.new[jc(h)-1]:null;return(0,Oe.jsx)(tR,At({className:w,oldChange:f,newChange:h,monotonous:m,hideGutter:g,oldSelected:C,newSelected:k,oldTokens:v,newTokens:b},y),"change".concat(d))}return c==="widget"?(0,Oe.jsx)(nR,{monotonous:m,hideGutter:g,oldElement:f,newElement:h},"widget".concat(d)):null})(o,a)}))})}var oR=["gutterType","hunkClassName"];function np(n){var e=n.hunk,t=iv(),r=t.gutterType,a=t.hunkClassName,s=Fs(t,oR),o=r==="none",i=r==="anchor",l=s.viewType==="unified"?QN:sR;return(0,Oe.jsx)(l,At(At({},s),{},{hunk:e,hideGutter:o,gutterAnchor:i,className:a}))}function iR(){}function Yw(n,e){var t=e?"auto":"none";n instanceof HTMLElement&&n.style.userSelect!==t&&(n.style.userSelect=t)}function lR(n){return n.map((function(e){return(0,Oe.jsx)(np,{hunk:e},(function(t){return"-".concat(t.oldStart,",").concat(t.oldLines," +").concat(t.newStart,",").concat(t.newLines)})(e))}))}function uR(n){var e=n.diffType,t=n.hunks,r=n.optimizeSelection,a=n.className,s=n.hunkClassName,o=s===void 0?or.hunkClassName:s,i=n.lineClassName,l=i===void 0?or.lineClassName:i,u=n.generateLineClassName,c=u===void 0?or.generateLineClassName:u,d=n.gutterClassName,f=d===void 0?or.gutterClassName:d,h=n.codeClassName,p=h===void 0?or.codeClassName:h,m=n.gutterType,g=m===void 0?or.gutterType:m,x=n.viewType,w=x===void 0?or.viewType:x,y=n.gutterEvents,C=y===void 0?or.gutterEvents:y,k=n.codeEvents,v=k===void 0?or.codeEvents:k,b=n.generateAnchorID,P=b===void 0?or.generateAnchorID:b,N=n.selectedChanges,M=N===void 0?or.selectedChanges:N,U=n.widgets,I=U===void 0?or.widgets:U,A=n.renderGutter,G=A===void 0?or.renderGutter:A,V=n.tokens,K=n.renderToken,L=n.children,R=L===void 0?lR:L,z=(0,kt.useRef)(null),J=(0,kt.useCallback)((function(ue){var He=ue.target;if(ue.button===0){var De=(function(Pt,Ye){for(var Ne=Pt;Ne&&Ne!==document.documentElement&&!Ne.classList.contains(Ye);)Ne=Ne.parentElement;return Ne===document.documentElement?null:Ne})(He,"diff-code");if(De&&De.parentElement){var je=window.getSelection();je&&je.removeAllRanges();var et=Sr(De.parentElement.children).indexOf(De);if(et===1||et===3){var Dt,at=Vh(z.current?z.current.querySelectorAll(".diff-line"):[]);try{for(at.s();!(Dt=at.n()).done;){var vt=Dt.value.children;Yw(vt[1],et===1),Yw(vt[3],et===3)}}catch(Pt){at.e(Pt)}finally{at.f()}}}}}),[]),Q=g==="none",re=e==="add"||e==="delete",pe=w==="split"&&!re&&r?J:iR,ee=(0,kt.useMemo)((function(){return(0,Oe.jsxs)("colgroup",w==="unified"?{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]}:re?{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]}:{children:[!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{}),!Q&&(0,Oe.jsx)("col",{className:"diff-gutter-col"}),(0,Oe.jsx)("col",{})]})}),[w,re,Q]),ce=(0,kt.useMemo)((function(){return{hunkClassName:o,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:re,hideGutter:Q,viewType:w,gutterType:g,codeEvents:v,gutterEvents:C,generateAnchorID:P,selectedChanges:M,widgets:I,renderGutter:G,tokens:V,renderToken:K}}),[p,v,P,f,C,g,Q,o,l,c,re,G,K,M,V,w,I]);return(0,Oe.jsx)(DA,{value:ce,children:(0,Oe.jsxs)("table",{ref:z,className:wn("diff","diff-".concat(w),a),onMouseDown:pe,children:[ee,R(t)]})})}var Ev=(0,kt.memo)(uR),cR=function(){};var Jw=cR;function dR(n){var e=n.hideGutter,t=n.monotonous,r=n.className,a=n.gutterClassName,s=n.contentClassName,o=n.children,i=wn("diff-decoration",r),l=wn("diff-decoration-gutter",a),u=wn("diff-decoration-content",s),c=(e?2:4)/(t?2:1),d=c-(e?0:1);if(kt.Children.count(o)===1)return(0,Oe.jsx)("tbody",{className:i,children:(0,Oe.jsx)("tr",{children:(0,Oe.jsx)("td",{colSpan:c,className:u,children:o})})});var f=en(o,2),h=f[0],p=f[1];return(0,Oe.jsx)("tbody",{className:i,children:(0,Oe.jsxs)("tr",{children:[!e&&(0,Oe.jsx)("td",{className:l,children:h}),(0,Oe.jsx)("td",{colSpan:d,className:u,children:p})]})})}function fR(n){var e=n.hideGutter,t=n.className,r=n.gutterClassName,a=n.contentClassName,s=n.children,o=wn("diff-decoration",t),i=wn("diff-decoration-gutter",r),l=wn("diff-decoration-content",a);if(kt.Children.count(s)===1)return(0,Oe.jsx)("tbody",{className:o,children:(0,Oe.jsx)("tr",{children:(0,Oe.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=en(s,2),c=u[0],d=u[1];return(0,Oe.jsx)("tbody",{className:o,children:(0,Oe.jsxs)("tr",{children:[!e&&(0,Oe.jsx)("td",{colSpan:2,className:i,children:c}),(0,Oe.jsx)("td",{className:l,children:d})]})})}function qc(n){var e=n.className,t=e===void 0?"":e,r=n.gutterClassName,a=r===void 0?"":r,s=n.contentClassName,o=s===void 0?"":s,i=n.children,l=iv(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?dR:fR,h=kt.Children.count(i),p=c==="none";return Jw(h<=2,"Decoration only accepts a maxium of 2 children"),Jw(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,Oe.jsx)(f,{hideGutter:p,monotonous:d,className:t,gutterClassName:a,contentClassName:o,children:i})}var hR=function(n,e,t,r){for(var a=-1,s=n==null?0:n.length;++a<s;){var o=n[a];e(r,o,t(o),n)}return r},pR=function(n,e){return function(t,r){if(t==null)return t;if(!Jh(t))return n(t,r);for(var a=t.length,s=e?a:-1,o=Object(t);(e?s--:++s<a)&&r(o[s],s,o)!==!1;);return t}},Bv=pR(Nv),mR=function(n,e,t,r){return Bv(n,(function(a,s,o){e(r,a,t(a),o)})),r},Ov=function(n,e){return function(t,r){var a=_r(t)?hR:mR,s=e?e():{};return a(t,n,zc(r),s)}},gR=Ov((function(n,e,t){tp(n,t,e)})),Zw=Aa?Aa.isConcatSpreadable:void 0,xR=function(n){return _r(n)||Xh(n)||!!(Zw&&n&&n[Zw])},yR=function n(e,t,r,a,s){var o=-1,i=e.length;for(r||(r=xR),s||(s=[]);++o<i;){var l=e[o];t>0&&r(l)?t>1?n(l,t-1,r,a,s):yv(s,l):a||(s[s.length]=l)}return s},bR=function(n,e){var t=-1,r=Jh(n)?Array(n.length):[];return Bv(n,(function(a,s,o){r[++t]=e(a,s,o)})),r},wR=function(n,e){return(_r(n)?Cv:bR)(n,zc(e))},vR=function(n,e){return yR(wR(n,e),1)};function kR(n,e){var t=e.newStart,r=e.changes.reduce((function(a,s){var o=en(a,2),i=o[0],l=o[1];return sa(s)?(i.splice(l,1),[i,l]):(Bs(s)&&i.splice(l,0,s.content),[i,l+1])}),[n,t-1]);return en(r,1)[0]}function Qw(n,e,t){if(!n.length)return[];var r=e==="old"?Wc:jc,a=gR(n,r),s=r(n[n.length-1]);return Array.from({length:s}).map((function(o,i){return t(a[i+1])}))}function SR(n){var e=(function(o){return vR(o,(function(i){return i.changes})).reduce((function(i,l){var u=en(i,2),c=u[0],d=u[1];return Ia(l)?(c.push(l),d.push(l)):sa(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(n),t=en(e,2),r=t[0],a=t[1],s=function(o){return o?o.content:""};return[Qw(r,"old",s).join(`
|
|
13
|
-
`),
|
|
14
|
-
`)]}function
|
|
11
|
+
`)})(n.trimStart());return qA.parse(t).map((function(r){return(function(a,s){var o=a.hunks.map((function(i){return VA(i,s)}));return At(At({},a),{},{hunks:o})})(r,e)}))}function hv(n){return n[0]}function pv(n){return n[n.length-1]}function Wh(n){return["".concat(n,"Start"),"".concat(n,"Lines")]}function _s(n){return n==="old"?function(e){return Hs(e)?-1:Na(e)?e.oldLineNumber:e.lineNumber}:function(e){return ia(e)?-1:Na(e)?e.newLineNumber:e.lineNumber}}function Jh(n,e){return function(t,r){var a=t[n],s=a+t[e];return r>=a&&r<s}}function mv(n,e){return function(t,r,a){var s=t[n]+t[e],o=r[n];return a>=s&&a<o}}function gv(n){var e=_s(n),t=(function(r){var a=Jt(Wh(r),2),s=Jh(a[0],a[1]);return function(o,i){return o.find((function(l){return s(l,i)}))}})(n);return function(r,a){var s=t(r,a);if(s)return s.changes.find((function(o){return e(o)===a}))}}function Zh(n){var e=n==="old"?"new":"old",t=Jt(Wh(n),2),r=t[0],a=t[1],s=Jt(Wh(e),2),o=s[0],i=s[1],l=_s(n),u=_s(e),c=Jh(r,a),d=mv(r,a);return function(f,h){var p=hv(f);if(h<p[r]){var m=p[r]-h;return p[o]-m}var g=pv(f);if(g[r]+g[a]<=h){var x=h-g[r]-g[a];return g[o]+g[i]+x}for(var b=0;b<f.length;b++){var y=f[b],N=f[b+1];if(c(y,h)){var L=y.changes.findIndex((function(O){return l(O)===h})),A=y.changes[L];if(Na(A))return u(A);var w=ia(A)?L+1:L-1,v=y.changes[w];if(!v)return-1;var T=Hs(A)?"delete":"insert";return v.type===T?u(v):-1}if(d(y,N,h)){var P=h-y[r]-y[a];return y[o]+y[i]+P}}throw new Error("Unexpected line position ".concat(h))}}var $A=function(n,e,t,r){for(var a=n.length,s=t+(r?1:-1);r?s--:++s<a;)if(e(n[s],s,n))return s;return-1},KA=function(){this.__data__=[],this.size=0},xv=function(n,e){return n===e||n!=n&&e!=e},Gc=function(n,e){for(var t=n.length;t--;)if(xv(n[t][0],e))return t;return-1},XA=Array.prototype.splice,YA=function(n){var e=this.__data__,t=Gc(e,n);return!(t<0)&&(t==e.length-1?e.pop():XA.call(e,t,1),--this.size,!0)},JA=function(n){var e=this.__data__,t=Gc(e,n);return t<0?void 0:e[t][1]},ZA=function(n){return Gc(this.__data__,n)>-1},QA=function(n,e){var t=this.__data__,r=Gc(t,n);return r<0?(++this.size,t.push([n,e])):t[r][1]=e,this};function mi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}mi.prototype.clear=KA,mi.prototype.delete=YA,mi.prototype.get=JA,mi.prototype.has=ZA,mi.prototype.set=QA;var zc=mi,eP=function(){this.__data__=new zc,this.size=0},tP=function(n){var e=this.__data__,t=e.delete(n);return this.size=e.size,t},nP=function(n){return this.__data__.get(n)},rP=function(n){return this.__data__.has(n)},yv=typeof Rc=="object"&&Rc&&Rc.Object===Object&&Rc,aP=typeof self=="object"&&self&&self.Object===Object&&self,ns=yv||aP||Function("return this")(),Ra=ns.Symbol,bv=Object.prototype,sP=bv.hasOwnProperty,oP=bv.toString,Kl=Ra?Ra.toStringTag:void 0,iP=function(n){var e=sP.call(n,Kl),t=n[Kl];try{n[Kl]=void 0;var r=!0}catch{}var a=oP.call(n);return r&&(e?n[Kl]=t:delete n[Kl]),a},lP=Object.prototype.toString,uP=function(n){return lP.call(n)},Dw=Ra?Ra.toStringTag:void 0,wi=function(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Dw&&Dw in Object(n)?iP(n):uP(n)},Yl=function(n){var e=typeof n;return n!=null&&(e=="object"||e=="function")},wv=function(n){if(!Yl(n))return!1;var e=wi(n);return e=="[object Function]"||e=="[object GeneratorFunction]"||e=="[object AsyncFunction]"||e=="[object Proxy]"},Bh=ns["__core-js_shared__"],Fw=(function(){var n=/[^.]+$/.exec(Bh&&Bh.keys&&Bh.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""})(),cP=function(n){return!!Fw&&Fw in n},dP=Function.prototype.toString,go=function(n){if(n!=null){try{return dP.call(n)}catch{}try{return n+""}catch{}}return""},fP=/^\[object .+?Constructor\]$/,hP=Function.prototype,pP=Object.prototype,mP=hP.toString,gP=pP.hasOwnProperty,xP=RegExp("^"+mP.call(gP).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),yP=function(n){return!(!Yl(n)||cP(n))&&(wv(n)?xP:fP).test(go(n))},bP=function(n,e){return n?.[e]},xo=function(n,e){var t=bP(n,e);return yP(t)?t:void 0},Jl=xo(ns,"Map"),Zl=xo(Object,"create"),wP=function(){this.__data__=Zl?Zl(null):{},this.size=0},vP=function(n){var e=this.has(n)&&delete this.__data__[n];return this.size-=e?1:0,e},kP=Object.prototype.hasOwnProperty,SP=function(n){var e=this.__data__;if(Zl){var t=e[n];return t==="__lodash_hash_undefined__"?void 0:t}return kP.call(e,n)?e[n]:void 0},CP=Object.prototype.hasOwnProperty,LP=function(n){var e=this.__data__;return Zl?e[n]!==void 0:CP.call(e,n)},IP=function(n,e){var t=this.__data__;return this.size+=this.has(n)?0:1,t[n]=Zl&&e===void 0?"__lodash_hash_undefined__":e,this};function gi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}gi.prototype.clear=wP,gi.prototype.delete=vP,gi.prototype.get=SP,gi.prototype.has=LP,gi.prototype.set=IP;var Ew=gi,AP=function(){this.size=0,this.__data__={hash:new Ew,map:new(Jl||zc),string:new Ew}},PP=function(n){var e=typeof n;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?n!=="__proto__":n===null},Wc=function(n,e){var t=n.__data__;return PP(e)?t[typeof e=="string"?"string":"hash"]:t.map},NP=function(n){var e=Wc(this,n).delete(n);return this.size-=e?1:0,e},RP=function(n){return Wc(this,n).get(n)},MP=function(n){return Wc(this,n).has(n)},TP=function(n,e){var t=Wc(this,n),r=t.size;return t.set(n,e),this.size+=t.size==r?0:1,this};function xi(n){var e=-1,t=n==null?0:n.length;for(this.clear();++e<t;){var r=n[e];this.set(r[0],r[1])}}xi.prototype.clear=AP,xi.prototype.delete=NP,xi.prototype.get=RP,xi.prototype.has=MP,xi.prototype.set=TP;var jc=xi,DP=function(n,e){var t=this.__data__;if(t instanceof zc){var r=t.__data__;if(!Jl||r.length<199)return r.push([n,e]),this.size=++t.size,this;t=this.__data__=new jc(r)}return t.set(n,e),this.size=t.size,this};function yi(n){var e=this.__data__=new zc(n);this.size=e.size}yi.prototype.clear=eP,yi.prototype.delete=tP,yi.prototype.get=nP,yi.prototype.has=rP,yi.prototype.set=DP;var Oc=yi,FP=function(n){return this.__data__.set(n,"__lodash_hash_undefined__"),this},EP=function(n){return this.__data__.has(n)};function Bc(n){var e=-1,t=n==null?0:n.length;for(this.__data__=new jc;++e<t;)this.add(n[e])}Bc.prototype.add=Bc.prototype.push=FP,Bc.prototype.has=EP;var OP=Bc,BP=function(n,e){for(var t=-1,r=n==null?0:n.length;++t<r;)if(e(n[t],t,n))return!0;return!1},_P=function(n,e){return n.has(e)},vv=function(n,e,t,r,a,s){var o=1&t,i=n.length,l=e.length;if(i!=l&&!(o&&l>i))return!1;var u=s.get(n),c=s.get(e);if(u&&c)return u==e&&c==n;var d=-1,f=!0,h=2&t?new OP:void 0;for(s.set(n,e),s.set(e,n);++d<i;){var p=n[d],m=e[d];if(r)var g=o?r(m,p,d,e,n,s):r(p,m,d,n,e,s);if(g!==void 0){if(g)continue;f=!1;break}if(h){if(!BP(e,(function(x,b){if(!_P(h,b)&&(p===x||a(p,x,t,r,s)))return h.push(b)}))){f=!1;break}}else if(p!==m&&!a(p,m,t,r,s)){f=!1;break}}return s.delete(n),s.delete(e),f},Ow=ns.Uint8Array,HP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r,a){t[++e]=[a,r]})),t},UP=function(n){var e=-1,t=Array(n.size);return n.forEach((function(r){t[++e]=r})),t},Bw=Ra?Ra.prototype:void 0,_h=Bw?Bw.valueOf:void 0,GP=function(n,e,t,r,a,s,o){switch(t){case"[object DataView]":if(n.byteLength!=e.byteLength||n.byteOffset!=e.byteOffset)return!1;n=n.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(n.byteLength!=e.byteLength||!s(new Ow(n),new Ow(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return xv(+n,+e);case"[object Error]":return n.name==e.name&&n.message==e.message;case"[object RegExp]":case"[object String]":return n==e+"";case"[object Map]":var i=HP;case"[object Set]":var l=1&r;if(i||(i=UP),n.size!=e.size&&!l)return!1;var u=o.get(n);if(u)return u==e;r|=2,o.set(n,e);var c=vv(i(n),i(e),r,a,s,o);return o.delete(n),c;case"[object Symbol]":if(_h)return _h.call(n)==_h.call(e)}return!1},kv=function(n,e){for(var t=-1,r=e.length,a=n.length;++t<r;)n[a+t]=e[t];return n},Ur=Array.isArray,zP=function(n,e,t){var r=e(n);return Ur(n)?r:kv(r,t(n))},WP=function(n,e){for(var t=-1,r=n==null?0:n.length,a=0,s=[];++t<r;){var o=n[t];e(o,t,n)&&(s[a++]=o)}return s},jP=function(){return[]},qP=Object.prototype.propertyIsEnumerable,_w=Object.getOwnPropertySymbols,VP=_w?function(n){return n==null?[]:(n=Object(n),WP(_w(n),(function(e){return qP.call(n,e)})))}:jP,$P=function(n,e){for(var t=-1,r=Array(n);++t<n;)r[t]=e(t);return r},bi=function(n){return n!=null&&typeof n=="object"},Hw=function(n){return bi(n)&&wi(n)=="[object Arguments]"},Sv=Object.prototype,KP=Sv.hasOwnProperty,XP=Sv.propertyIsEnumerable,Qh=Hw((function(){return arguments})())?Hw:function(n){return bi(n)&&KP.call(n,"callee")&&!XP.call(n,"callee")},YP=function(){return!1},jh=eu((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t?ns.Buffer:void 0,s=(a?a.isBuffer:void 0)||YP;n.exports=s})),JP=/^(?:0|[1-9]\d*)$/,Cv=function(n,e){var t=typeof n;return!!(e=e??9007199254740991)&&(t=="number"||t!="symbol"&&JP.test(n))&&n>-1&&n%1==0&&n<e},ep=function(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=9007199254740991},Vt={};Vt["[object Float32Array]"]=Vt["[object Float64Array]"]=Vt["[object Int8Array]"]=Vt["[object Int16Array]"]=Vt["[object Int32Array]"]=Vt["[object Uint8Array]"]=Vt["[object Uint8ClampedArray]"]=Vt["[object Uint16Array]"]=Vt["[object Uint32Array]"]=!0,Vt["[object Arguments]"]=Vt["[object Array]"]=Vt["[object ArrayBuffer]"]=Vt["[object Boolean]"]=Vt["[object DataView]"]=Vt["[object Date]"]=Vt["[object Error]"]=Vt["[object Function]"]=Vt["[object Map]"]=Vt["[object Number]"]=Vt["[object Object]"]=Vt["[object RegExp]"]=Vt["[object Set]"]=Vt["[object String]"]=Vt["[object WeakMap]"]=!1;var ZP=function(n){return bi(n)&&ep(n.length)&&!!Vt[wi(n)]},QP=function(n){return function(e){return n(e)}},Uw=eu((function(n,e){var t=e&&!e.nodeType&&e,r=t&&n&&!n.nodeType&&n,a=r&&r.exports===t&&yv.process,s=(function(){try{var o=r&&r.require&&r.require("util").types;return o||a&&a.binding&&a.binding("util")}catch{}})();n.exports=s})),Gw=Uw&&Uw.isTypedArray,Lv=Gw?QP(Gw):ZP,eN=Object.prototype.hasOwnProperty,tN=function(n,e){var t=Ur(n),r=!t&&Qh(n),a=!t&&!r&&jh(n),s=!t&&!r&&!a&&Lv(n),o=t||r||a||s,i=o?$P(n.length,String):[],l=i.length;for(var u in n)!e&&!eN.call(n,u)||o&&(u=="length"||a&&(u=="offset"||u=="parent")||s&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||Cv(u,l))||i.push(u);return i},nN=Object.prototype,rN=function(n){var e=n&&n.constructor;return n===(typeof e=="function"&&e.prototype||nN)},aN=(function(n,e){return function(t){return n(e(t))}})(Object.keys,Object),sN=Object.prototype.hasOwnProperty,oN=function(n){if(!rN(n))return aN(n);var e=[];for(var t in Object(n))sN.call(n,t)&&t!="constructor"&&e.push(t);return e},tp=function(n){return n!=null&&ep(n.length)&&!wv(n)},np=function(n){return tp(n)?tN(n):oN(n)},zw=function(n){return zP(n,np,VP)},iN=Object.prototype.hasOwnProperty,lN=function(n,e,t,r,a,s){var o=1&t,i=zw(n),l=i.length;if(l!=zw(e).length&&!o)return!1;for(var u=l;u--;){var c=i[u];if(!(o?c in e:iN.call(e,c)))return!1}var d=s.get(n),f=s.get(e);if(d&&f)return d==e&&f==n;var h=!0;s.set(n,e),s.set(e,n);for(var p=o;++u<l;){var m=n[c=i[u]],g=e[c];if(r)var x=o?r(g,m,c,e,n,s):r(m,g,c,n,e,s);if(!(x===void 0?m===g||a(m,g,t,r,s):x)){h=!1;break}p||(p=c=="constructor")}if(h&&!p){var b=n.constructor,y=e.constructor;b==y||!("constructor"in n)||!("constructor"in e)||typeof b=="function"&&b instanceof b&&typeof y=="function"&&y instanceof y||(h=!1)}return s.delete(n),s.delete(e),h},qh=xo(ns,"DataView"),Vh=xo(ns,"Promise"),$h=xo(ns,"Set"),Kh=xo(ns,"WeakMap"),uN=go(qh),cN=go(Jl),dN=go(Vh),fN=go($h),hN=go(Kh),mo=wi;(qh&&mo(new qh(new ArrayBuffer(1)))!="[object DataView]"||Jl&&mo(new Jl)!="[object Map]"||Vh&&mo(Vh.resolve())!="[object Promise]"||$h&&mo(new $h)!="[object Set]"||Kh&&mo(new Kh)!="[object WeakMap]")&&(mo=function(n){var e=wi(n),t=e=="[object Object]"?n.constructor:void 0,r=t?go(t):"";if(r)switch(r){case uN:return"[object DataView]";case cN:return"[object Map]";case dN:return"[object Promise]";case fN:return"[object Set]";case hN:return"[object WeakMap]"}return e});var Ww=mo,Mc="[object Object]",jw=Object.prototype.hasOwnProperty,pN=function(n,e,t,r,a,s){var o=Ur(n),i=Ur(e),l=o?"[object Array]":Ww(n),u=i?"[object Array]":Ww(e),c=(l=l=="[object Arguments]"?Mc:l)==Mc,d=(u=u=="[object Arguments]"?Mc:u)==Mc,f=l==u;if(f&&jh(n)){if(!jh(e))return!1;o=!0,c=!1}if(f&&!c)return s||(s=new Oc),o||Lv(n)?vv(n,e,t,r,a,s):GP(n,e,l,t,r,a,s);if(!(1&t)){var h=c&&jw.call(n,"__wrapped__"),p=d&&jw.call(e,"__wrapped__");if(h||p){var m=h?n.value():n,g=p?e.value():e;return s||(s=new Oc),a(m,g,t,r,s)}}return!!f&&(s||(s=new Oc),lN(n,e,t,r,a,s))},qc=function n(e,t,r,a,s){return e===t||(e==null||t==null||!bi(e)&&!bi(t)?e!=e&&t!=t:pN(e,t,r,a,n,s))},mN=function(n,e,t,r){var a=t.length,s=a,o=!r;if(n==null)return!s;for(n=Object(n);a--;){var i=t[a];if(o&&i[2]?i[1]!==n[i[0]]:!(i[0]in n))return!1}for(;++a<s;){var l=(i=t[a])[0],u=n[l],c=i[1];if(o&&i[2]){if(u===void 0&&!(l in n))return!1}else{var d=new Oc;if(r)var f=r(u,c,l,n,e,d);if(!(f===void 0?qc(c,u,3,r,d):f))return!1}}return!0},Iv=function(n){return n==n&&!Yl(n)},gN=function(n){for(var e=np(n),t=e.length;t--;){var r=e[t],a=n[r];e[t]=[r,a,Iv(a)]}return e},Av=function(n,e){return function(t){return t!=null&&t[n]===e&&(e!==void 0||n in Object(t))}},xN=function(n){var e=gN(n);return e.length==1&&e[0][2]?Av(e[0][0],e[0][1]):function(t){return t===n||mN(t,n,e)}},Vc=function(n){return typeof n=="symbol"||bi(n)&&wi(n)=="[object Symbol]"},yN=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,bN=/^\w*$/,rp=function(n,e){if(Ur(n))return!1;var t=typeof n;return!(t!="number"&&t!="symbol"&&t!="boolean"&&n!=null&&!Vc(n))||bN.test(n)||!yN.test(n)||e!=null&&n in Object(e)};function ap(n,e){if(typeof n!="function"||e!=null&&typeof e!="function")throw new TypeError("Expected a function");var t=function(){var r=arguments,a=e?e.apply(this,r):r[0],s=t.cache;if(s.has(a))return s.get(a);var o=n.apply(this,r);return t.cache=s.set(a,o)||s,o};return t.cache=new(ap.Cache||jc),t}ap.Cache=jc;var wN=ap,vN=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kN=/\\(\\)?/g,SN=(function(n){var e=wN(n,(function(r){return t.size===500&&t.clear(),r})),t=e.cache;return e})((function(n){var e=[];return n.charCodeAt(0)===46&&e.push(""),n.replace(vN,(function(t,r,a,s){e.push(a?s.replace(kN,"$1"):r||t)})),e})),Pv=function(n,e){for(var t=-1,r=n==null?0:n.length,a=Array(r);++t<r;)a[t]=e(n[t],t,n);return a},qw=Ra?Ra.prototype:void 0,Vw=qw?qw.toString:void 0,CN=function n(e){if(typeof e=="string")return e;if(Ur(e))return Pv(e,n)+"";if(Vc(e))return Vw?Vw.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t},LN=function(n){return n==null?"":CN(n)},Nv=function(n,e){return Ur(n)?n:rp(n,e)?[n]:SN(LN(n))},$c=function(n){if(typeof n=="string"||Vc(n))return n;var e=n+"";return e=="0"&&1/n==-1/0?"-0":e},Rv=function(n,e){for(var t=0,r=(e=Nv(e,n)).length;n!=null&&t<r;)n=n[$c(e[t++])];return t&&t==r?n:void 0},IN=function(n,e,t){var r=n==null?void 0:Rv(n,e);return r===void 0?t:r},AN=function(n,e){return n!=null&&e in Object(n)},PN=function(n,e,t){for(var r=-1,a=(e=Nv(e,n)).length,s=!1;++r<a;){var o=$c(e[r]);if(!(s=n!=null&&t(n,o)))break;n=n[o]}return s||++r!=a?s:!!(a=n==null?0:n.length)&&ep(a)&&Cv(o,a)&&(Ur(n)||Qh(n))},NN=function(n,e){return n!=null&&PN(n,e,AN)},RN=function(n,e){return rp(n)&&Iv(e)?Av($c(n),e):function(t){var r=IN(t,n);return r===void 0&&r===e?NN(t,n):qc(e,r,3)}},MN=function(n){return n},TN=function(n){return function(e){return e?.[n]}},DN=function(n){return function(e){return Rv(e,n)}},FN=function(n){return rp(n)?TN($c(n)):DN(n)},Kc=function(n){return typeof n=="function"?n:n==null?MN:typeof n=="object"?Ur(n)?RN(n[0],n[1]):xN(n):FN(n)},EN=/\s/,ON=function(n){for(var e=n.length;e--&&EN.test(n.charAt(e)););return e},BN=/^\s+/,_N=function(n){return n&&n.slice(0,ON(n)+1).replace(BN,"")},HN=/^[-+]0x[0-9a-f]+$/i,UN=/^0b[01]+$/i,GN=/^0o[0-7]+$/i,zN=parseInt,WN=function(n){if(typeof n=="number")return n;if(Vc(n))return NaN;if(Yl(n)){var e=typeof n.valueOf=="function"?n.valueOf():n;n=Yl(e)?e+"":e}if(typeof n!="string")return n===0?n:+n;n=_N(n);var t=UN.test(n);return t||GN.test(n)?zN(n.slice(2),t?2:8):HN.test(n)?NaN:+n},jN=function(n){return n?(n=WN(n))===1/0||n===-1/0?17976931348623157e292*(n<0?-1:1):n==n?n:0:n===0?n:0},qN=function(n){var e=jN(n),t=e%1;return e==e?t?e-t:e:0},VN=Math.max,$N=Math.min,$w=function(n,e,t){var r=n==null?0:n.length;if(!r)return-1;var a=r-1;return t!==void 0&&(a=qN(t),a=t<0?VN(r+a,0):$N(a,r-1)),$A(n,Kc(e),a,!0)},Ql=_s("old"),KN=_s("new");function Kw(n){var e=n.oldStart;return[e,e+n.oldLines-1]}function _c(n){if(!n.length)return null;var e=n.reduce((function(o,i){return Na(i)||(o.isPlain=!1),Hs(i)||(o.oldLines=o.oldLines+1,o.oldStart===-1&&(o.oldStart=Ql(i))),ia(i)||(o.newLines=o.newLines+1,o.newStart===-1&&(o.newStart=KN(i))),o}),{isPlain:!0,content:"",oldStart:-1,oldLines:0,newStart:-1,newLines:0}),t=e.oldStart,r=e.oldLines,a=e.newStart,s=e.newLines;return At(At({},e),{},{content:"@@ -".concat(t,",").concat(r," +").concat(a,",").concat(s),changes:n})}function XN(n,e,t){return _c(n.map((function(r,a){return{type:"normal",isNormal:!0,oldLineNumber:e+a,newLineNumber:t+a,content:""+r}})))}function Tc(n,e,t){var r=n.changes,a=r.findIndex((function(i){return Ql(i)>=e}));if(a===-1)return null;var s=(function(){if(a===0)return a;var i=$w(r,(function(l){return!Hs(l)}),a-1);return i===-1?a:i+1})();if(t===void 0)return _c(r.slice(s));var o=$w(r,(function(i){return Ql(i)<=t}));return _c(r.slice(s,o===-1?void 0:o))}function Xl(n,e){if(!n)return e;if(!e)return n;var t=Jt(Kw(n),2),r=t[0],a=t[1],s=Jt(Kw(e),2),o=s[0],i=s[1];if(a+1===o)return _c([].concat(Ar(n.changes),Ar(e.changes)));if(r<=o&&a>=i){if(n.isPlain&&!e.isPlain){var l=Tc(n,r,o),u=Tc(n,i+1);return Xl(Xl(l,e),u)}return n}return n.isPlain?Xl(Tc(n,r,o),e):Xl(n,Tc(e,a+1))}function YN(n,e){var t=pv(n);if(!t)return[e];if(t.oldStart+t.oldLines<e.oldStart)return n.concat(e);var r=Xl(t,e);return r?[].concat(Ar(n.slice(0,-1)),[r]):n}function JN(n,e){var t=Ql(e.changes[0]),r=n.findIndex((function(a){var s=a.changes;return!!s.length&&Ql(s[0])>=t}));return(r===-1?n.concat(e):[].concat(Ar(n.slice(0,r)),[e],Ar(n.slice(r)))).reduce(YN,[])}function Os(n){if(!n)throw new Error("change is not provided");if(Na(n))return"N".concat(n.oldLineNumber);var e=Hs(n)?"I":"D";return"".concat(e).concat(n.lineNumber)}var ZN=Zh("old"),Hh=_s("old"),Xw=Jh("oldStart","oldLines"),QN=mv("oldStart","oldLines");function Xh(n,e,t){var r=(function(h,p){if(!h.length)return-1;var m=hv(h);if(p<m.oldStart||Xw(m,p))return 0;for(var g=1;g<h.length;g++){var x=h[g];if(Xw(x,p))return g;var b=h[g-1];if(QN(b,x,p))return g}return-1})(n,e);if(r===-1)return[[e,t]];var a=n[r];if(e<a.oldStart){var s=a.changes.findIndex((function(h){return!Na(h)})),o=a.oldStart+Math.max(s,0);return o>=t?[[e,t]]:[[e,o]].concat(Ar(Xh(n,o+1,t)))}var i=a.changes,l=(function(h,p){var m=h.changes,g=m.findIndex((function(b){return Hh(b)===p}));if(g<0)return-1;for(var x=g;x<m.length;x++)if(Na(m[x]))return x;return-1})(a,e);if(l===-1)return[];var u=i[l],c=Hh(u),d=i.slice(l+1).findIndex((function(h){return!Na(h)})),f=Hh(u)+Math.max(d,0);return f>=t?[[c,t]]:[[c,f]].concat(Ar(Xh(n,f+1,t)))}function Mv(n,e,t,r){return Xh(n,t,r).reduce((function(a,s){return(function(o,i,l){var u=Jt(l,2),c=u[0],d=u[1],f=(typeof i=="string"?i.split(`
|
|
12
|
+
`):i).slice(Math.max(c,1)-1,d-1);if(!f.length)return o;var h=XN(f,c,ZN(o,c));return h?JN(o,h):o})(a,e,s)}),n)}function Tv(n,e){if(!n)return e.oldStart-1;var t=n.oldStart+n.oldLines;return e.oldStart-t}var Xc=_s("old"),Yc=_s("new"),lz=gv("old"),uz=gv("new"),cz=Zh("new"),dz=Zh("old"),Yw=(function(){try{var n=xo(Object,"defineProperty");return n({},"",{}),n}catch{}})(),sp=function(n,e,t){e=="__proto__"&&Yw?Yw(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0}):n[e]=t},eR=function(n){return function(e,t,r){for(var a=-1,s=Object(e),o=r(e),i=o.length;i--;){var l=o[n?i:++a];if(t(s[l],l,s)===!1)break}return e}},tR=eR(),Dv=function(n,e){return n&&tR(n,e,np)},Fv=function(n,e){var t={};return e=Kc(e),Dv(n,(function(r,a,s){sp(t,a,e(r,a,s))})),t},nR=["changeKey","text","tokens","renderToken"],Jw=function n(e,t){var r=e.type,a=e.value,s=e.markType,o=e.properties,i=e.className,l=e.children,u=function(d){return(0,He.jsx)("span",{className:d,children:a||l&&l.map(n)},t)};switch(r){case"text":return a;case"mark":return u("diff-code-mark diff-code-mark-".concat(s));case"edit":return u("diff-code-edit");default:var c=o&&o.className;return u(yn(i||c))}};function rR(n){if(!Array.isArray(n))return!0;if(n.length>1)return!1;if(n.length===1){var e=Jt(n,1)[0];return e.type==="text"&&!e.value}return!0}function aR(n){var e=n.changeKey,t=n.text,r=n.tokens,a=n.renderToken,s=Bs(n,nR),o=a?function(i,l){return a(i,Jw,l)}:Jw;return(0,He.jsx)("td",At(At({},s),{},{"data-change-key":e,children:r?rR(r)?" ":r.map(o):t||" "}))}var Ev=(0,St.memo)(aR);function Ov(n,e){return function(){var t=e==="old"?Xc(n):Yc(n);return t===-1?void 0:t}}function Bv(n,e){return function(t){return n&&t?(0,He.jsx)("a",{href:e?"#"+e:void 0,children:t}):t}}function Hc(n,e){return e?function(t){n(),e(t)}:n}function Zw(n,e,t,r){return(0,St.useMemo)((function(){var a=Fv(n,(function(s){return function(o){return s&&s(e,o)}}));return a.onMouseEnter=Hc(t,a.onMouseEnter),a.onMouseLeave=Hc(r,a.onMouseLeave),a}),[n,t,r,e])}function Qw(n,e,t,r,a,s,o,i,l){var u={change:e,side:r,inHoverState:i,renderDefault:Ov(e,r),wrapInAnchor:Bv(a,s)};return(0,He.jsx)("td",At(At({className:n},o),{},{"data-change-key":t,children:l(u)}))}function sR(n){var e,t,r,a=n.change,s=n.selected,o=n.tokens,i=n.className,l=n.generateLineClassName,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.gutterAnchor,m=n.generateAnchorID,g=n.renderToken,x=n.renderGutter,b=a.type,y=a.content,N=Os(a),L=(e=Jt((0,St.useState)(!1),2),t=e[0],r=e[1],[t,(0,St.useCallback)((function(){return r(!0)}),[]),(0,St.useCallback)((function(){return r(!1)}),[])]),A=Jt(L,3),w=A[0],v=A[1],T=A[2],P=(0,St.useMemo)((function(){return{change:a}}),[a]),O=Zw(d,P,v,T),C=Zw(f,P,v,T),I=m(a),H=l({changes:[a],defaultGenerate:function(){return i}}),q=yn("diff-gutter","diff-gutter-".concat(b),u,{"diff-gutter-selected":s}),$=yn("diff-code","diff-code-".concat(b),c,{"diff-code-selected":s});return(0,He.jsxs)("tr",{id:I,className:yn("diff-line",H),children:[!h&&Qw(q,a,N,"old",p,I,O,w,x),!h&&Qw(q,a,N,"new",p,I,O,w,x),(0,He.jsx)(Ev,At({className:$,changeKey:N,text:y,tokens:o,renderToken:g},C))]})}var oR=(0,St.memo)(sR);function iR(n){var e=n.hideGutter,t=n.element;return(0,He.jsx)("tr",{className:"diff-widget",children:(0,He.jsx)("td",{colSpan:e?1:3,className:"diff-widget-content",children:t})})}var lR=["hideGutter","selectedChanges","tokens","lineClassName"],uR=["hunk","widgets","className"];function cR(n){var e=n.hunk,t=n.widgets,r=n.className,a=Bs(n,uR),s=(function(o,i){return o.reduce((function(l,u){var c=Os(u);l.push(["change",c,u]);var d=i[c];return d&&l.push(["widget",c,d]),l}),[])})(e.changes,t);return(0,He.jsx)("tbody",{className:yn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=Jt(i,3),c=u[0],d=u[1],f=u[2],h=l.hideGutter,p=l.selectedChanges,m=l.tokens,g=l.lineClassName,x=Bs(l,lR);if(c==="change"){var b=ia(f)?"old":"new",y=ia(f)?Xc(f):Yc(f),N=m?m[b][y-1]:null;return(0,He.jsx)(oR,At({className:g,change:f,hideGutter:h,selected:p.includes(d),tokens:N},x),"change".concat(d))}return c==="widget"?(0,He.jsx)(iR,{hideGutter:h,element:f},"widget".concat(d)):null})(o,a)}))})}var _v=0;function Dc(n,e,t,r){var a=(0,St.useCallback)((function(){return e(n)}),[n,e]),s=(0,St.useCallback)((function(){return e("")}),[e]);return(0,St.useMemo)((function(){var o=Fv(r,(function(i){return function(l){return i&&i({side:n,change:t},l)}}));return o.onMouseEnter=Hc(a,o.onMouseEnter),o.onMouseLeave=Hc(s,o.onMouseLeave),o}),[t,r,a,n,s])}function Uh(n){var e=n.change,t=n.side,r=n.selected,a=n.tokens,s=n.gutterClassName,o=n.codeClassName,i=n.gutterEvents,l=n.codeEvents,u=n.anchorID,c=n.gutterAnchor,d=n.gutterAnchorTarget,f=n.hideGutter,h=n.hover,p=n.renderToken,m=n.renderGutter;if(!e){var g=yn("diff-gutter","diff-gutter-omit",s),x=yn("diff-code","diff-code-omit",o);return[!f&&(0,He.jsx)("td",{className:g},"gutter"),(0,He.jsx)("td",{className:x},"code")]}var b=e.type,y=e.content,N=Os(e),L=t===_v?"old":"new",A=At({id:u||void 0,className:yn("diff-gutter","diff-gutter-".concat(b),Gh({"diff-gutter-selected":r},"diff-line-hover-"+L,h),s),children:m({change:e,side:L,inHoverState:h,renderDefault:Ov(e,L),wrapInAnchor:Bv(c,d)})},i),w=yn("diff-code","diff-code-".concat(b),Gh({"diff-code-selected":r},"diff-line-hover-"+L,h),o);return[!f&&(0,He.jsx)("td",At(At({},A),{},{"data-change-key":N}),"gutter"),(0,He.jsx)(Ev,At({className:w,changeKey:N,text:y,tokens:a,renderToken:p},l),"code")]}function dR(n){var e=n.className,t=n.oldChange,r=n.newChange,a=n.oldSelected,s=n.newSelected,o=n.oldTokens,i=n.newTokens,l=n.monotonous,u=n.gutterClassName,c=n.codeClassName,d=n.gutterEvents,f=n.codeEvents,h=n.hideGutter,p=n.generateAnchorID,m=n.generateLineClassName,g=n.gutterAnchor,x=n.renderToken,b=n.renderGutter,y=Jt((0,St.useState)(""),2),N=y[0],L=y[1],A=Dc("old",L,t,d),w=Dc("new",L,r,d),v=Dc("old",L,t,f),T=Dc("new",L,r,f),P=t&&p(t),O=r&&p(r),C=m({changes:[t,r],defaultGenerate:function(){return e}}),I={monotonous:l,hideGutter:h,gutterClassName:u,codeClassName:c,gutterEvents:d,codeEvents:f,renderToken:x,renderGutter:b},H=At(At({},I),{},{change:t,side:_v,selected:a,tokens:o,gutterEvents:A,codeEvents:v,anchorID:P,gutterAnchor:g,gutterAnchorTarget:P,hover:N==="old"}),q=At(At({},I),{},{change:r,side:1,selected:s,tokens:i,gutterEvents:w,codeEvents:T,anchorID:t===r?null:O,gutterAnchor:g,gutterAnchorTarget:t===r?P:O,hover:N==="new"});if(l)return(0,He.jsx)("tr",{className:yn("diff-line",C),children:Uh(t?H:q)});var $=(function(S,M){return S&&!M?"diff-line-old-only":!S&&M?"diff-line-new-only":S===M?"diff-line-normal":"diff-line-compare"})(t,r);return(0,He.jsxs)("tr",{className:yn("diff-line",$,C),children:[Uh(H),Uh(q)]})}var fR=(0,St.memo)(dR);function hR(n){var e=n.hideGutter,t=n.oldElement,r=n.newElement;return n.monotonous?(0,He.jsx)("tr",{className:"diff-widget",children:(0,He.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t||r})}):t===r?(0,He.jsx)("tr",{className:"diff-widget",children:(0,He.jsx)("td",{colSpan:e?2:4,className:"diff-widget-content",children:t})}):(0,He.jsxs)("tr",{className:"diff-widget",children:[(0,He.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:t}),(0,He.jsx)("td",{colSpan:e?1:2,className:"diff-widget-content",children:r})]})}var pR=["selectedChanges","monotonous","hideGutter","tokens","lineClassName"],mR=["hunk","widgets","className"];function Fc(n,e){return(n?Os(n):"00")+(e?Os(e):"00")}function gR(n){var e=n.hunk,t=n.widgets,r=n.className,a=Bs(n,mR),s=(function(o,i){for(var l=function(x){if(!x)return null;var b=Os(x);return i[b]||null},u=[],c=0;c<o.length;c++){var d=o[c];if(Na(d))u.push(["change",Fc(d,d),d,d]);else if(ia(d)){var f=o[c+1];f&&Hs(f)?(c+=1,u.push(["change",Fc(d,f),d,f])):u.push(["change",Fc(d,null),d,null])}else u.push(["change",Fc(null,d),null,d]);var h=u[u.length-1],p=l(h[2]),m=l(h[3]);if(p||m){var g=h[1];u.push(["widget",g,p,m])}}return u})(e.changes,t);return(0,He.jsx)("tbody",{className:yn("diff-hunk",r),children:s.map((function(o){return(function(i,l){var u=Jt(i,4),c=u[0],d=u[1],f=u[2],h=u[3],p=l.selectedChanges,m=l.monotonous,g=l.hideGutter,x=l.tokens,b=l.lineClassName,y=Bs(l,pR);if(c==="change"){var N=!!f&&p.includes(Os(f)),L=!!h&&p.includes(Os(h)),A=f&&x?x.old[Xc(f)-1]:null,w=h&&x?x.new[Yc(h)-1]:null;return(0,He.jsx)(fR,At({className:b,oldChange:f,newChange:h,monotonous:m,hideGutter:g,oldSelected:N,newSelected:L,oldTokens:A,newTokens:w},y),"change".concat(d))}return c==="widget"?(0,He.jsx)(hR,{monotonous:m,hideGutter:g,oldElement:f,newElement:h},"widget".concat(d)):null})(o,a)}))})}var xR=["gutterType","hunkClassName"];function op(n){var e=n.hunk,t=dv(),r=t.gutterType,a=t.hunkClassName,s=Bs(t,xR),o=r==="none",i=r==="anchor",l=s.viewType==="unified"?cR:gR;return(0,He.jsx)(l,At(At({},s),{},{hunk:e,hideGutter:o,gutterAnchor:i,className:a}))}function yR(){}function ev(n,e){var t=e?"auto":"none";n instanceof HTMLElement&&n.style.userSelect!==t&&(n.style.userSelect=t)}function bR(n){return n.map((function(e){return(0,He.jsx)(op,{hunk:e},(function(t){return"-".concat(t.oldStart,",").concat(t.oldLines," +").concat(t.newStart,",").concat(t.newLines)})(e))}))}function wR(n){var e=n.diffType,t=n.hunks,r=n.optimizeSelection,a=n.className,s=n.hunkClassName,o=s===void 0?cr.hunkClassName:s,i=n.lineClassName,l=i===void 0?cr.lineClassName:i,u=n.generateLineClassName,c=u===void 0?cr.generateLineClassName:u,d=n.gutterClassName,f=d===void 0?cr.gutterClassName:d,h=n.codeClassName,p=h===void 0?cr.codeClassName:h,m=n.gutterType,g=m===void 0?cr.gutterType:m,x=n.viewType,b=x===void 0?cr.viewType:x,y=n.gutterEvents,N=y===void 0?cr.gutterEvents:y,L=n.codeEvents,A=L===void 0?cr.codeEvents:L,w=n.generateAnchorID,v=w===void 0?cr.generateAnchorID:w,T=n.selectedChanges,P=T===void 0?cr.selectedChanges:T,O=n.widgets,C=O===void 0?cr.widgets:O,I=n.renderGutter,H=I===void 0?cr.renderGutter:I,q=n.tokens,$=n.renderToken,S=n.children,M=S===void 0?bR:S,W=(0,St.useRef)(null),ee=(0,St.useCallback)((function(ie){var Re=ie.target;if(ie.button===0){var De=(function(Nt,ot){for(var Me=Nt;Me&&Me!==document.documentElement&&!Me.classList.contains(ot);)Me=Me.parentElement;return Me===document.documentElement?null:Me})(Re,"diff-code");if(De&&De.parentElement){var Ye=window.getSelection();Ye&&Ye.removeAllRanges();var $e=Ar(De.parentElement.children).indexOf(De);if($e===1||$e===3){var Pt,Xe=Yh(W.current?W.current.querySelectorAll(".diff-line"):[]);try{for(Xe.s();!(Pt=Xe.n()).done;){var lt=Pt.value.children;ev(lt[1],$e===1),ev(lt[3],$e===3)}}catch(Nt){Xe.e(Nt)}finally{Xe.f()}}}}}),[]),te=g==="none",re=e==="add"||e==="delete",ce=b==="split"&&!re&&r?ee:yR,oe=(0,St.useMemo)((function(){return(0,He.jsxs)("colgroup",b==="unified"?{children:[!te&&(0,He.jsx)("col",{className:"diff-gutter-col"}),!te&&(0,He.jsx)("col",{className:"diff-gutter-col"}),(0,He.jsx)("col",{})]}:re?{children:[!te&&(0,He.jsx)("col",{className:"diff-gutter-col"}),(0,He.jsx)("col",{})]}:{children:[!te&&(0,He.jsx)("col",{className:"diff-gutter-col"}),(0,He.jsx)("col",{}),!te&&(0,He.jsx)("col",{className:"diff-gutter-col"}),(0,He.jsx)("col",{})]})}),[b,re,te]),ue=(0,St.useMemo)((function(){return{hunkClassName:o,lineClassName:l,generateLineClassName:c,gutterClassName:f,codeClassName:p,monotonous:re,hideGutter:te,viewType:b,gutterType:g,codeEvents:A,gutterEvents:N,generateAnchorID:v,selectedChanges:P,widgets:C,renderGutter:H,tokens:q,renderToken:$}}),[p,A,v,f,N,g,te,o,l,c,re,H,$,P,q,b,C]);return(0,He.jsx)(jA,{value:ue,children:(0,He.jsxs)("table",{ref:W,className:yn("diff","diff-".concat(b),a),onMouseDown:ce,children:[oe,M(t)]})})}var Hv=(0,St.memo)(wR),vR=function(){};var tv=vR;function kR(n){var e=n.hideGutter,t=n.monotonous,r=n.className,a=n.gutterClassName,s=n.contentClassName,o=n.children,i=yn("diff-decoration",r),l=yn("diff-decoration-gutter",a),u=yn("diff-decoration-content",s),c=(e?2:4)/(t?2:1),d=c-(e?0:1);if(St.Children.count(o)===1)return(0,He.jsx)("tbody",{className:i,children:(0,He.jsx)("tr",{children:(0,He.jsx)("td",{colSpan:c,className:u,children:o})})});var f=Jt(o,2),h=f[0],p=f[1];return(0,He.jsx)("tbody",{className:i,children:(0,He.jsxs)("tr",{children:[!e&&(0,He.jsx)("td",{className:l,children:h}),(0,He.jsx)("td",{colSpan:d,className:u,children:p})]})})}function SR(n){var e=n.hideGutter,t=n.className,r=n.gutterClassName,a=n.contentClassName,s=n.children,o=yn("diff-decoration",t),i=yn("diff-decoration-gutter",r),l=yn("diff-decoration-content",a);if(St.Children.count(s)===1)return(0,He.jsx)("tbody",{className:o,children:(0,He.jsx)("tr",{children:(0,He.jsx)("td",{colSpan:e?1:3,className:l,children:s})})});var u=Jt(s,2),c=u[0],d=u[1];return(0,He.jsx)("tbody",{className:o,children:(0,He.jsxs)("tr",{children:[!e&&(0,He.jsx)("td",{colSpan:2,className:i,children:c}),(0,He.jsx)("td",{className:l,children:d})]})})}function Jc(n){var e=n.className,t=e===void 0?"":e,r=n.gutterClassName,a=r===void 0?"":r,s=n.contentClassName,o=s===void 0?"":s,i=n.children,l=dv(),u=l.viewType,c=l.gutterType,d=l.monotonous,f=u==="split"?kR:SR,h=St.Children.count(i),p=c==="none";return tv(h<=2,"Decoration only accepts a maxium of 2 children"),tv(h<2||!p,"Gutter element in decoration will not be rendered since hideGutter prop is set to true"),(0,He.jsx)(f,{hideGutter:p,monotonous:d,className:t,gutterClassName:a,contentClassName:o,children:i})}var CR=function(n,e,t,r){for(var a=-1,s=n==null?0:n.length;++a<s;){var o=n[a];e(r,o,t(o),n)}return r},LR=function(n,e){return function(t,r){if(t==null)return t;if(!tp(t))return n(t,r);for(var a=t.length,s=e?a:-1,o=Object(t);(e?s--:++s<a)&&r(o[s],s,o)!==!1;);return t}},Uv=LR(Dv),IR=function(n,e,t,r){return Uv(n,(function(a,s,o){e(r,a,t(a),o)})),r},Gv=function(n,e){return function(t,r){var a=Ur(t)?CR:IR,s=e?e():{};return a(t,n,Kc(r),s)}},AR=Gv((function(n,e,t){sp(n,t,e)})),nv=Ra?Ra.isConcatSpreadable:void 0,PR=function(n){return Ur(n)||Qh(n)||!!(nv&&n&&n[nv])},NR=function n(e,t,r,a,s){var o=-1,i=e.length;for(r||(r=PR),s||(s=[]);++o<i;){var l=e[o];t>0&&r(l)?t>1?n(l,t-1,r,a,s):kv(s,l):a||(s[s.length]=l)}return s},RR=function(n,e){var t=-1,r=tp(n)?Array(n.length):[];return Uv(n,(function(a,s,o){r[++t]=e(a,s,o)})),r},MR=function(n,e){return(Ur(n)?Pv:RR)(n,Kc(e))},TR=function(n,e){return NR(MR(n,e),1)};function DR(n,e){var t=e.newStart,r=e.changes.reduce((function(a,s){var o=Jt(a,2),i=o[0],l=o[1];return ia(s)?(i.splice(l,1),[i,l]):(Hs(s)&&i.splice(l,0,s.content),[i,l+1])}),[n,t-1]);return Jt(r,1)[0]}function rv(n,e,t){if(!n.length)return[];var r=e==="old"?Xc:Yc,a=AR(n,r),s=r(n[n.length-1]);return Array.from({length:s}).map((function(o,i){return t(a[i+1])}))}function FR(n){var e=(function(o){return TR(o,(function(i){return i.changes})).reduce((function(i,l){var u=Jt(i,2),c=u[0],d=u[1];return Na(l)?(c.push(l),d.push(l)):ia(l)?c.push(l):d.push(l),[c,d]}),[[],[]])})(n),t=Jt(e,2),r=t[0],a=t[1],s=function(o){return o?o.content:""};return[rv(r,"old",s).join(`
|
|
13
|
+
`),rv(a,"new",s).join(`
|
|
14
|
+
`)]}function Ec(n){return{type:"root",children:n}}function ER(n,e){if(e.oldSource){var t=(function(l,u){return u.reduce(DR,l.split(`
|
|
15
15
|
`)).join(`
|
|
16
|
-
`)})(e.oldSource,n),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[
|
|
16
|
+
`)})(e.oldSource,n),r=e.highlight?function(l){return e.refractor.highlight(l,e.language)}:function(l){return[{type:"text",value:l}]};return[Ec(r(e.oldSource)),Ec(r(t))]}var a=Jt(FR(n),2),s=a[0],o=a[1],i=e.highlight?function(l){return Ec(e.refractor.highlight(l,e.language))}:function(l){return Ec([{type:"text",value:l}])};return[i(s),i(o)]}function zv(n){return n.map((function(e){return At({},e)}))}function OR(n,e){return[].concat(Ar(zv(n.slice(0,-1))),[e])}function BR(n){return n.type==="text"}function _R(n){var e=n[n.length-1];if(BR(e))return e;throw new Error("Invalid token path with leaf of type ".concat(e.type))}var HR=["children"];function Wv(n){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];if(n.children){var r=n.children,a=Bs(n,HR);t.push(a);var s,o=Yh(r);try{for(o.s();!(s=o.n()).done;)Wv(s.value,e,t)}catch(i){o.e(i)}finally{o.f()}t.pop()}else e.push(zv([].concat(Ar(t.slice(1)),[n])));return e}function UR(n){return n.reduce((function(e,t){var r=e[e.length-1],a=(function(l){var u=_R(l);return u.value.includes(`
|
|
17
17
|
`)?u.value.split(`
|
|
18
|
-
`).map((function(c){return
|
|
19
|
-
`,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==i&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var i=4e4,l=o(t);return i=65535,{chars1:l,chars2:o(r),lineArray:a}},e.prototype.diff_charsToLines_=function(t,r){for(var a=0;a<t.length;a++){for(var s=t[a][1],o=[],i=0;i<s.length;i++)o[i]=r[s.charCodeAt(i)];t[a][1]=o.join("")}},e.prototype.diff_commonPrefix=function(t,r){if(!t||!r||t.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(i,o)==r.substring(i,o)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonSuffix=function(t,r){if(!t||!r||t.charAt(t.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(t.length-o,t.length-i)==r.substring(r.length-o,r.length-i)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonOverlap_=function(t,r){var a=t.length,s=r.length;if(a==0||s==0)return 0;a>s?t=t.substring(a-s):a<s&&(r=r.substring(0,a));var o=Math.min(a,s);if(t==r)return o;for(var i=0,l=1;;){var u=t.substring(o-l),c=r.indexOf(u);if(c==-1)return i;l+=c,c!=0&&t.substring(o-l)!=r.substring(0,l)||(i=l,l++)}},e.prototype.diff_halfMatch_=function(t,r){if(this.Diff_Timeout<=0)return null;var a=t.length>r.length?t:r,s=t.length>r.length?r:t;if(a.length<4||2*s.length<a.length)return null;var o=this;function i(m,g,x){for(var w,y,C,k,v=m.substring(x,x+Math.floor(m.length/4)),b=-1,P="";(b=g.indexOf(v,b+1))!=-1;){var N=o.diff_commonPrefix(m.substring(x),g.substring(b)),M=o.diff_commonSuffix(m.substring(0,x),g.substring(0,b));P.length<M+N&&(P=g.substring(b-M,b)+g.substring(b,b+N),w=m.substring(0,x-M),y=m.substring(x+N),C=g.substring(0,b-M),k=g.substring(b+N))}return 2*P.length>=m.length?[w,y,C,k,P]:null}var l,u,c,d,f,h=i(a,s,Math.ceil(a.length/4)),p=i(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,t.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=0,u=0,c=0,d=0;i<t.length;)t[i][0]==0?(a[s++]=i,l=c,u=d,c=0,d=0,o=t[i][1]):(t[i][0]==1?c+=t[i][1].length:d+=t[i][1].length,o&&o.length<=Math.max(l,u)&&o.length<=Math.max(c,d)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,i=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,o=null,r=!0)),i++;for(r&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),i=1;i<t.length;){if(t[i-1][0]==-1&&t[i][0]==1){var f=t[i-1][1],h=t[i][1],p=this.diff_commonOverlap_(f,h),m=this.diff_commonOverlap_(h,f);p>=m?(p>=f.length/2||p>=h.length/2)&&(t.splice(i,0,new e.Diff(0,h.substring(0,p))),t[i-1][1]=f.substring(0,f.length-p),t[i+1][1]=h.substring(p),i++):(m>=f.length/2||m>=h.length/2)&&(t.splice(i,0,new e.Diff(0,f.substring(0,m))),t[i-1][0]=1,t[i-1][1]=h.substring(0,h.length-m),t[i+1][0]=-1,t[i+1][1]=f.substring(m),i++),i++}i++}},e.prototype.diff_cleanupSemanticLossless=function(t){function r(m,g){if(!m||!g)return 6;var x=m.charAt(m.length-1),w=g.charAt(0),y=x.match(e.nonAlphaNumericRegex_),C=w.match(e.nonAlphaNumericRegex_),k=y&&x.match(e.whitespaceRegex_),v=C&&w.match(e.whitespaceRegex_),b=k&&x.match(e.linebreakRegex_),P=v&&w.match(e.linebreakRegex_),N=b&&m.match(e.blanklineEndRegex_),M=P&&g.match(e.blanklineStartRegex_);return N||M?5:b||P?4:y&&!k&&v?3:k||v?2:y||C?1:0}for(var a=1;a<t.length-1;){if(t[a-1][0]==0&&t[a+1][0]==0){var s=t[a-1][1],o=t[a][1],i=t[a+1][1],l=this.diff_commonSuffix(s,o);if(l){var u=o.substring(o.length-l);s=s.substring(0,s.length-l),o=u+o.substring(0,o.length-l),i=u+i}for(var c=s,d=o,f=i,h=r(s,o)+r(o,i);o.charAt(0)===i.charAt(0);){s+=o.charAt(0),o=o.substring(1)+i.charAt(0),i=i.substring(1);var p=r(s,o)+r(o,i);p>=h&&(h=p,c=s,d=o,f=i)}t[a-1][1]!=c&&(c?t[a-1][1]=c:(t.splice(a-1,1),a--),t[a][1]=d,f?t[a+1][1]=f:(t.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=!1,u=!1,c=!1,d=!1;i<t.length;)t[i][0]==0?(t[i][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=i,l=c,u=d,o=t[i][1]):(s=0,o=null),c=d=!1):(t[i][0]==-1?d=!0:c=!0,o&&(l&&u&&c&&d||o.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,o=null,l&&u?(c=d=!0,s=0):(i=--s>0?a[s-1]:-1,c=d=!1),r=!0)),i++;r&&this.diff_cleanupMerge(t)},e.prototype.diff_cleanupMerge=function(t){t.push(new e.Diff(0,""));for(var r,a=0,s=0,o=0,i="",l="";a<t.length;)switch(t[a][0]){case 1:o++,l+=t[a][1],a++;break;case-1:s++,i+=t[a][1],a++;break;case 0:s+o>1?(s!==0&&o!==0&&((r=this.diff_commonPrefix(l,i))!==0&&(a-s-o>0&&t[a-s-o-1][0]==0?t[a-s-o-1][1]+=l.substring(0,r):(t.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),i=i.substring(r)),(r=this.diff_commonSuffix(l,i))!==0&&(t[a][1]=l.substring(l.length-r)+t[a][1],l=l.substring(0,l.length-r),i=i.substring(0,i.length-r))),a-=s+o,t.splice(a,s+o),i.length&&(t.splice(a,0,new e.Diff(-1,i)),a++),l.length&&(t.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&t[a-1][0]==0?(t[a-1][1]+=t[a][1],t.splice(a,1)):a++,o=0,s=0,i="",l=""}t[t.length-1][1]===""&&t.pop();var u=!1;for(a=1;a<t.length-1;)t[a-1][0]==0&&t[a+1][0]==0&&(t[a][1].substring(t[a][1].length-t[a-1][1].length)==t[a-1][1]?(t[a][1]=t[a-1][1]+t[a][1].substring(0,t[a][1].length-t[a-1][1].length),t[a+1][1]=t[a-1][1]+t[a+1][1],t.splice(a-1,1),u=!0):t[a][1].substring(0,t[a+1][1].length)==t[a+1][1]&&(t[a-1][1]+=t[a+1][1],t[a][1]=t[a][1].substring(t[a+1][1].length)+t[a+1][1],t.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(t)},e.prototype.diff_xIndex=function(t,r){var a,s=0,o=0,i=0,l=0;for(a=0;a<t.length&&(t[a][0]!==1&&(s+=t[a][1].length),t[a][0]!==-1&&(o+=t[a][1].length),!(s>r));a++)i=s,l=o;return t.length!=a&&t[a][0]===-1?l:l+(r-i)},e.prototype.diff_prettyHtml=function(t){for(var r=[],a=/&/g,s=/</g,o=/>/g,i=/\n/g,l=0;l<t.length;l++){var u=t[l][0],c=t[l][1].replace(a,"&").replace(s,"<").replace(o,">").replace(i,"¶<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_text2=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==-1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(t){for(var r=0,a=0,s=0,o=0;o<t.length;o++){var i=t[o][0],l=t[o][1];switch(i){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(t){for(var r=[],a=0;a<t.length;a++)switch(t[a][0]){case 1:r[a]="+"+encodeURI(t[a][1]);break;case-1:r[a]="-"+t[a][1].length;break;case 0:r[a]="="+t[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(t,r){for(var a=[],s=0,o=0,i=r.split(/\t/g),l=0;l<i.length;l++){var u=i[l].substring(1);switch(i[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=t.substring(o,o+=c);i[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(i[l])throw new Error("Invalid diff operation in diff_fromDelta: "+i[l])}}if(o!=t.length)throw new Error("Delta length ("+o+") does not equal source text length ("+t.length+").");return a},e.prototype.match_main=function(t,r,a){if(t==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,t.length)),t==r?0:t.length?t.substring(a,a+r.length)==r?a:this.match_bitap_(t,r,a):-1},e.prototype.match_bitap_=function(t,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),o=this;function i(v,b){var P=v/r.length,N=Math.abs(a-b);return o.Match_Distance?P+N/o.Match_Distance:N?1:P}var l=this.Match_Threshold,u=t.indexOf(r,a);u!=-1&&(l=Math.min(i(0,u),l),(u=t.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(i(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+t.length,m=0;m<r.length;m++){for(c=0,d=p;c<d;)i(m,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var g=Math.max(1,a-d+1),x=Math.min(a+d,t.length)+r.length,w=Array(x+2);w[x+1]=(1<<m)-1;for(var y=x;y>=g;y--){var C=s[t.charAt(y-1)];if(w[y]=m===0?(w[y+1]<<1|1)&C:(w[y+1]<<1|1)&C|(h[y+1]|h[y])<<1|1|h[y+1],w[y]&f){var k=i(m,y-1);if(k<=l){if(l=k,!((u=y-1)>a))break;g=Math.max(1,2*a-u)}}}if(i(m+1,a)>l)break;h=w}return u},e.prototype.match_alphabet_=function(t){for(var r={},a=0;a<t.length;a++)r[t.charAt(a)]=0;for(a=0;a<t.length;a++)r[t.charAt(a)]|=1<<t.length-a-1;return r},e.prototype.patch_addContext_=function(t,r){if(r.length!=0){if(t.start2===null)throw Error("patch not initialized");for(var a=r.substring(t.start2,t.start2+t.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(t.start2-s,t.start2+t.length1+s);s+=this.Patch_Margin;var o=r.substring(t.start2-s,t.start2);o&&t.diffs.unshift(new e.Diff(0,o));var i=r.substring(t.start2+t.length1,t.start2+t.length1+s);i&&t.diffs.push(new e.Diff(0,i)),t.start1-=o.length,t.start2-=o.length,t.length1+=o.length+i.length,t.length2+=o.length+i.length}},e.prototype.patch_make=function(t,r,a){var s,o;if(typeof t=="string"&&typeof r=="string"&&a===void 0)s=t,(o=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(o),this.diff_cleanupEfficiency(o));else if(t&&typeof t=="object"&&r===void 0&&a===void 0)o=t,s=this.diff_text1(o);else if(typeof t=="string"&&r&&typeof r=="object"&&a===void 0)s=t,o=r;else{if(typeof t!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=t,o=a}if(o.length===0)return[];for(var i=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<o.length;p++){var m=o[p][0],g=o[p][1];switch(u||m===0||(l.start1=c,l.start2=d),m){case 1:l.diffs[u++]=o[p],l.length2+=g.length,h=h.substring(0,d)+g+h.substring(d);break;case-1:l.length1+=g.length,l.diffs[u++]=o[p],h=h.substring(0,d)+h.substring(d+g.length);break;case 0:g.length<=2*this.Patch_Margin&&u&&o.length!=p+1?(l.diffs[u++]=o[p],l.length1+=g.length,l.length2+=g.length):g.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),i.push(l),l=new e.patch_obj,u=0,f=h,c=d)}m!==1&&(c+=g.length),m!==-1&&(d+=g.length)}return u&&(this.patch_addContext_(l,f),i.push(l)),i},e.prototype.patch_deepCopy=function(t){for(var r=[],a=0;a<t.length;a++){var s=t[a],o=new e.patch_obj;o.diffs=[];for(var i=0;i<s.diffs.length;i++)o.diffs[i]=new e.Diff(s.diffs[i][0],s.diffs[i][1]);o.start1=s.start1,o.start2=s.start2,o.length1=s.length1,o.length2=s.length2,r[a]=o}return r},e.prototype.patch_apply=function(t,r){if(t.length==0)return[r,[]];t=this.patch_deepCopy(t);var a=this.patch_addPadding(t);r=a+r+a,this.patch_splitMax(t);for(var s=0,o=[],i=0;i<t.length;i++){var l,u,c=t[i].start2+s,d=this.diff_text1(t[i].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)o[i]=!1,s-=t[i].length2-t[i].length1;else if(o[i]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(t[i].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)o[i]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,m=0,g=0;g<t[i].diffs.length;g++){var x=t[i].diffs[g];x[0]!==0&&(p=this.diff_xIndex(h,m)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,m+x[1].length))),x[0]!==-1&&(m+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),o]},e.prototype.patch_addPadding=function(t){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<t.length;s++)t[s].start1+=r,t[s].start2+=r;var o=t[0],i=o.diffs;if(i.length==0||i[0][0]!=0)i.unshift(new e.Diff(0,a)),o.start1-=r,o.start2-=r,o.length1+=r,o.length2+=r;else if(r>i[0][1].length){var l=r-i[0][1].length;i[0][1]=a.substring(i[0][1].length)+i[0][1],o.start1-=l,o.start2-=l,o.length1+=l,o.length2+=l}return(i=(o=t[t.length-1]).diffs).length==0||i[i.length-1][0]!=0?(i.push(new e.Diff(0,a)),o.length1+=r,o.length2+=r):r>i[i.length-1][1].length&&(l=r-i[i.length-1][1].length,i[i.length-1][1]+=a.substring(0,l),o.length1+=l,o.length2+=l),a},e.prototype.patch_splitMax=function(t){for(var r=this.Match_MaxBits,a=0;a<t.length;a++)if(!(t[a].length1<=r)){var s=t[a];t.splice(a--,1);for(var o=s.start1,i=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=o-l.length,u.start2=i-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,i+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,o+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,o+=f.length,d===0?(u.length2+=f.length,i+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||t.splice(++a,0,u)}}},e.prototype.patch_toText=function(t){for(var r=[],a=0;a<t.length;a++)r[a]=t[a];return r.join("")},e.prototype.patch_fromText=function(t){var r=[];if(!t)return r;for(var a=t.split(`
|
|
18
|
+
`).map((function(c){return OR(l,At(At({},u),{},{value:c}))})):[l]})(t),s=WA(a),o=s[0],i=s.slice(1);return[].concat(Ar(e.slice(0,-1)),[[].concat(Ar(r),[o])],Ar(i.map((function(l){return[l]}))))}),[[]])}function av(n){return UR(Wv(n))}var GR=function(n,e,t){var r=(t=typeof t=="function"?t:void 0)?t(n,e):void 0;return r===void 0?qc(n,e,void 0,t):!!r},zR=function(n,e){return qc(n,e)},WR=function(n){var e=n==null?0:n.length;return e?n[e-1]:void 0};function jR(n,e){if(!n.children)throw new Error("parent node missing children property");var t,r,a=WR(n.children);return a&&(r=e,(t=a).type===r.type&&(t.type==="text"||t.children&&r.children&&GR(t,r,(function(s,o,i){return i==="chlidren"||zR(s,o)}))))?n.children[n.children.length-1]=(function(s,o){return"value"in s&&"value"in o?At(At({},s),{},{value:"".concat(s.value).concat(o.value)}):s})(a,e):n.children.push(e),n.children[n.children.length-1]}function sv(n){var e,t={type:"root",children:[]},r=Yh(n);try{var a=function(){var s=e.value;s.reduce((function(o,i,l){return jR(o,l===s.length-1?At({},i):At(At({},i),{},{children:[]}))}),t)};for(r.s();!(e=r.n()).done;)a()}catch(s){r.e(s)}finally{r.f()}return t}var qR=Object.prototype.hasOwnProperty,fz=Gv((function(n,e,t){qR.call(n,t)?n[t].push(e):sp(n,t,[e])}));var ip=eu((function(n){var e=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32};e.Diff=function(t,r){return[t,r]},e.prototype.diff_main=function(t,r,a,s){s===void 0&&(s=this.Diff_Timeout<=0?Number.MAX_VALUE:new Date().getTime()+1e3*this.Diff_Timeout);var o=s;if(t==null||r==null)throw new Error("Null input. (diff_main)");if(t==r)return t?[new e.Diff(0,t)]:[];a===void 0&&(a=!0);var i=a,l=this.diff_commonPrefix(t,r),u=t.substring(0,l);t=t.substring(l),r=r.substring(l),l=this.diff_commonSuffix(t,r);var c=t.substring(t.length-l);t=t.substring(0,t.length-l),r=r.substring(0,r.length-l);var d=this.diff_compute_(t,r,i,o);return u&&d.unshift(new e.Diff(0,u)),c&&d.push(new e.Diff(0,c)),this.diff_cleanupMerge(d),d},e.prototype.diff_compute_=function(t,r,a,s){var o;if(!t)return[new e.Diff(1,r)];if(!r)return[new e.Diff(-1,t)];var i=t.length>r.length?t:r,l=t.length>r.length?r:t,u=i.indexOf(l);if(u!=-1)return o=[new e.Diff(1,i.substring(0,u)),new e.Diff(0,l),new e.Diff(1,i.substring(u+l.length))],t.length>r.length&&(o[0][0]=o[2][0]=-1),o;if(l.length==1)return[new e.Diff(-1,t),new e.Diff(1,r)];var c=this.diff_halfMatch_(t,r);if(c){var d=c[0],f=c[1],h=c[2],p=c[3],m=c[4],g=this.diff_main(d,h,a,s),x=this.diff_main(f,p,a,s);return g.concat([new e.Diff(0,m)],x)}return a&&t.length>100&&r.length>100?this.diff_lineMode_(t,r,s):this.diff_bisect_(t,r,s)},e.prototype.diff_lineMode_=function(t,r,a){var s=this.diff_linesToChars_(t,r);t=s.chars1,r=s.chars2;var o=s.lineArray,i=this.diff_main(t,r,!1,a);this.diff_charsToLines_(i,o),this.diff_cleanupSemantic(i),i.push(new e.Diff(0,""));for(var l=0,u=0,c=0,d="",f="";l<i.length;){switch(i[l][0]){case 1:c++,f+=i[l][1];break;case-1:u++,d+=i[l][1];break;case 0:if(u>=1&&c>=1){i.splice(l-u-c,u+c),l=l-u-c;for(var h=this.diff_main(d,f,!1,a),p=h.length-1;p>=0;p--)i.splice(l,0,h[p]);l+=h.length}c=0,u=0,d="",f=""}l++}return i.pop(),i},e.prototype.diff_bisect_=function(t,r,a){for(var s=t.length,o=r.length,i=Math.ceil((s+o)/2),l=i,u=2*i,c=new Array(u),d=new Array(u),f=0;f<u;f++)c[f]=-1,d[f]=-1;c[l+1]=0,d[l+1]=0;for(var h=s-o,p=h%2!=0,m=0,g=0,x=0,b=0,y=0;y<i&&!(new Date().getTime()>a);y++){for(var N=-y+m;N<=y-g;N+=2){for(var L=l+N,A=(O=N==-y||N!=y&&c[L-1]<c[L+1]?c[L+1]:c[L-1]+1)-N;O<s&&A<o&&t.charAt(O)==r.charAt(A);)O++,A++;if(c[L]=O,O>s)g+=2;else if(A>o)m+=2;else if(p&&(T=l+h-N)>=0&&T<u&&d[T]!=-1&&O>=(v=s-d[T]))return this.diff_bisectSplit_(t,r,O,A,a)}for(var w=-y+x;w<=y-b;w+=2){for(var v,T=l+w,P=(v=w==-y||w!=y&&d[T-1]<d[T+1]?d[T+1]:d[T-1]+1)-w;v<s&&P<o&&t.charAt(s-v-1)==r.charAt(o-P-1);)v++,P++;if(d[T]=v,v>s)b+=2;else if(P>o)x+=2;else if(!p&&(L=l+h-w)>=0&&L<u&&c[L]!=-1){var O;if(A=l+(O=c[L])-L,O>=(v=s-v))return this.diff_bisectSplit_(t,r,O,A,a)}}}return[new e.Diff(-1,t),new e.Diff(1,r)]},e.prototype.diff_bisectSplit_=function(t,r,a,s,o){var i=t.substring(0,a),l=r.substring(0,s),u=t.substring(a),c=r.substring(s),d=this.diff_main(i,l,!1,o),f=this.diff_main(u,c,!1,o);return d.concat(f)},e.prototype.diff_linesToChars_=function(t,r){var a=[],s={};function o(u){for(var c="",d=0,f=-1,h=a.length;f<u.length-1;){(f=u.indexOf(`
|
|
19
|
+
`,d))==-1&&(f=u.length-1);var p=u.substring(d,f+1);(s.hasOwnProperty?s.hasOwnProperty(p):s[p]!==void 0)?c+=String.fromCharCode(s[p]):(h==i&&(p=u.substring(d),f=u.length),c+=String.fromCharCode(h),s[p]=h,a[h++]=p),d=f+1}return c}a[0]="";var i=4e4,l=o(t);return i=65535,{chars1:l,chars2:o(r),lineArray:a}},e.prototype.diff_charsToLines_=function(t,r){for(var a=0;a<t.length;a++){for(var s=t[a][1],o=[],i=0;i<s.length;i++)o[i]=r[s.charCodeAt(i)];t[a][1]=o.join("")}},e.prototype.diff_commonPrefix=function(t,r){if(!t||!r||t.charAt(0)!=r.charAt(0))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(i,o)==r.substring(i,o)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonSuffix=function(t,r){if(!t||!r||t.charAt(t.length-1)!=r.charAt(r.length-1))return 0;for(var a=0,s=Math.min(t.length,r.length),o=s,i=0;a<o;)t.substring(t.length-o,t.length-i)==r.substring(r.length-o,r.length-i)?i=a=o:s=o,o=Math.floor((s-a)/2+a);return o},e.prototype.diff_commonOverlap_=function(t,r){var a=t.length,s=r.length;if(a==0||s==0)return 0;a>s?t=t.substring(a-s):a<s&&(r=r.substring(0,a));var o=Math.min(a,s);if(t==r)return o;for(var i=0,l=1;;){var u=t.substring(o-l),c=r.indexOf(u);if(c==-1)return i;l+=c,c!=0&&t.substring(o-l)!=r.substring(0,l)||(i=l,l++)}},e.prototype.diff_halfMatch_=function(t,r){if(this.Diff_Timeout<=0)return null;var a=t.length>r.length?t:r,s=t.length>r.length?r:t;if(a.length<4||2*s.length<a.length)return null;var o=this;function i(m,g,x){for(var b,y,N,L,A=m.substring(x,x+Math.floor(m.length/4)),w=-1,v="";(w=g.indexOf(A,w+1))!=-1;){var T=o.diff_commonPrefix(m.substring(x),g.substring(w)),P=o.diff_commonSuffix(m.substring(0,x),g.substring(0,w));v.length<P+T&&(v=g.substring(w-P,w)+g.substring(w,w+T),b=m.substring(0,x-P),y=m.substring(x+T),N=g.substring(0,w-P),L=g.substring(w+T))}return 2*v.length>=m.length?[b,y,N,L,v]:null}var l,u,c,d,f,h=i(a,s,Math.ceil(a.length/4)),p=i(a,s,Math.ceil(a.length/2));return h||p?(l=p?h&&h[4].length>p[4].length?h:p:h,t.length>r.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]),[u,c,d,f,l[4]]):null},e.prototype.diff_cleanupSemantic=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=0,u=0,c=0,d=0;i<t.length;)t[i][0]==0?(a[s++]=i,l=c,u=d,c=0,d=0,o=t[i][1]):(t[i][0]==1?c+=t[i][1].length:d+=t[i][1].length,o&&o.length<=Math.max(l,u)&&o.length<=Math.max(c,d)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,i=--s>0?a[s-1]:-1,l=0,u=0,c=0,d=0,o=null,r=!0)),i++;for(r&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),i=1;i<t.length;){if(t[i-1][0]==-1&&t[i][0]==1){var f=t[i-1][1],h=t[i][1],p=this.diff_commonOverlap_(f,h),m=this.diff_commonOverlap_(h,f);p>=m?(p>=f.length/2||p>=h.length/2)&&(t.splice(i,0,new e.Diff(0,h.substring(0,p))),t[i-1][1]=f.substring(0,f.length-p),t[i+1][1]=h.substring(p),i++):(m>=f.length/2||m>=h.length/2)&&(t.splice(i,0,new e.Diff(0,f.substring(0,m))),t[i-1][0]=1,t[i-1][1]=h.substring(0,h.length-m),t[i+1][0]=-1,t[i+1][1]=f.substring(m),i++),i++}i++}},e.prototype.diff_cleanupSemanticLossless=function(t){function r(m,g){if(!m||!g)return 6;var x=m.charAt(m.length-1),b=g.charAt(0),y=x.match(e.nonAlphaNumericRegex_),N=b.match(e.nonAlphaNumericRegex_),L=y&&x.match(e.whitespaceRegex_),A=N&&b.match(e.whitespaceRegex_),w=L&&x.match(e.linebreakRegex_),v=A&&b.match(e.linebreakRegex_),T=w&&m.match(e.blanklineEndRegex_),P=v&&g.match(e.blanklineStartRegex_);return T||P?5:w||v?4:y&&!L&&A?3:L||A?2:y||N?1:0}for(var a=1;a<t.length-1;){if(t[a-1][0]==0&&t[a+1][0]==0){var s=t[a-1][1],o=t[a][1],i=t[a+1][1],l=this.diff_commonSuffix(s,o);if(l){var u=o.substring(o.length-l);s=s.substring(0,s.length-l),o=u+o.substring(0,o.length-l),i=u+i}for(var c=s,d=o,f=i,h=r(s,o)+r(o,i);o.charAt(0)===i.charAt(0);){s+=o.charAt(0),o=o.substring(1)+i.charAt(0),i=i.substring(1);var p=r(s,o)+r(o,i);p>=h&&(h=p,c=s,d=o,f=i)}t[a-1][1]!=c&&(c?t[a-1][1]=c:(t.splice(a-1,1),a--),t[a][1]=d,f?t[a+1][1]=f:(t.splice(a+1,1),a--))}a++}},e.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,e.whitespaceRegex_=/\s/,e.linebreakRegex_=/[\r\n]/,e.blanklineEndRegex_=/\n\r?\n$/,e.blanklineStartRegex_=/^\r?\n\r?\n/,e.prototype.diff_cleanupEfficiency=function(t){for(var r=!1,a=[],s=0,o=null,i=0,l=!1,u=!1,c=!1,d=!1;i<t.length;)t[i][0]==0?(t[i][1].length<this.Diff_EditCost&&(c||d)?(a[s++]=i,l=c,u=d,o=t[i][1]):(s=0,o=null),c=d=!1):(t[i][0]==-1?d=!0:c=!0,o&&(l&&u&&c&&d||o.length<this.Diff_EditCost/2&&l+u+c+d==3)&&(t.splice(a[s-1],0,new e.Diff(-1,o)),t[a[s-1]+1][0]=1,s--,o=null,l&&u?(c=d=!0,s=0):(i=--s>0?a[s-1]:-1,c=d=!1),r=!0)),i++;r&&this.diff_cleanupMerge(t)},e.prototype.diff_cleanupMerge=function(t){t.push(new e.Diff(0,""));for(var r,a=0,s=0,o=0,i="",l="";a<t.length;)switch(t[a][0]){case 1:o++,l+=t[a][1],a++;break;case-1:s++,i+=t[a][1],a++;break;case 0:s+o>1?(s!==0&&o!==0&&((r=this.diff_commonPrefix(l,i))!==0&&(a-s-o>0&&t[a-s-o-1][0]==0?t[a-s-o-1][1]+=l.substring(0,r):(t.splice(0,0,new e.Diff(0,l.substring(0,r))),a++),l=l.substring(r),i=i.substring(r)),(r=this.diff_commonSuffix(l,i))!==0&&(t[a][1]=l.substring(l.length-r)+t[a][1],l=l.substring(0,l.length-r),i=i.substring(0,i.length-r))),a-=s+o,t.splice(a,s+o),i.length&&(t.splice(a,0,new e.Diff(-1,i)),a++),l.length&&(t.splice(a,0,new e.Diff(1,l)),a++),a++):a!==0&&t[a-1][0]==0?(t[a-1][1]+=t[a][1],t.splice(a,1)):a++,o=0,s=0,i="",l=""}t[t.length-1][1]===""&&t.pop();var u=!1;for(a=1;a<t.length-1;)t[a-1][0]==0&&t[a+1][0]==0&&(t[a][1].substring(t[a][1].length-t[a-1][1].length)==t[a-1][1]?(t[a][1]=t[a-1][1]+t[a][1].substring(0,t[a][1].length-t[a-1][1].length),t[a+1][1]=t[a-1][1]+t[a+1][1],t.splice(a-1,1),u=!0):t[a][1].substring(0,t[a+1][1].length)==t[a+1][1]&&(t[a-1][1]+=t[a+1][1],t[a][1]=t[a][1].substring(t[a+1][1].length)+t[a+1][1],t.splice(a+1,1),u=!0)),a++;u&&this.diff_cleanupMerge(t)},e.prototype.diff_xIndex=function(t,r){var a,s=0,o=0,i=0,l=0;for(a=0;a<t.length&&(t[a][0]!==1&&(s+=t[a][1].length),t[a][0]!==-1&&(o+=t[a][1].length),!(s>r));a++)i=s,l=o;return t.length!=a&&t[a][0]===-1?l:l+(r-i)},e.prototype.diff_prettyHtml=function(t){for(var r=[],a=/&/g,s=/</g,o=/>/g,i=/\n/g,l=0;l<t.length;l++){var u=t[l][0],c=t[l][1].replace(a,"&").replace(s,"<").replace(o,">").replace(i,"¶<br>");switch(u){case 1:r[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case-1:r[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case 0:r[l]="<span>"+c+"</span>"}}return r.join("")},e.prototype.diff_text1=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_text2=function(t){for(var r=[],a=0;a<t.length;a++)t[a][0]!==-1&&(r[a]=t[a][1]);return r.join("")},e.prototype.diff_levenshtein=function(t){for(var r=0,a=0,s=0,o=0;o<t.length;o++){var i=t[o][0],l=t[o][1];switch(i){case 1:a+=l.length;break;case-1:s+=l.length;break;case 0:r+=Math.max(a,s),a=0,s=0}}return r+=Math.max(a,s)},e.prototype.diff_toDelta=function(t){for(var r=[],a=0;a<t.length;a++)switch(t[a][0]){case 1:r[a]="+"+encodeURI(t[a][1]);break;case-1:r[a]="-"+t[a][1].length;break;case 0:r[a]="="+t[a][1].length}return r.join(" ").replace(/%20/g," ")},e.prototype.diff_fromDelta=function(t,r){for(var a=[],s=0,o=0,i=r.split(/\t/g),l=0;l<i.length;l++){var u=i[l].substring(1);switch(i[l].charAt(0)){case"+":try{a[s++]=new e.Diff(1,decodeURI(u))}catch{throw new Error("Illegal escape in diff_fromDelta: "+u)}break;case"-":case"=":var c=parseInt(u,10);if(isNaN(c)||c<0)throw new Error("Invalid number in diff_fromDelta: "+u);var d=t.substring(o,o+=c);i[l].charAt(0)=="="?a[s++]=new e.Diff(0,d):a[s++]=new e.Diff(-1,d);break;default:if(i[l])throw new Error("Invalid diff operation in diff_fromDelta: "+i[l])}}if(o!=t.length)throw new Error("Delta length ("+o+") does not equal source text length ("+t.length+").");return a},e.prototype.match_main=function(t,r,a){if(t==null||r==null||a==null)throw new Error("Null input. (match_main)");return a=Math.max(0,Math.min(a,t.length)),t==r?0:t.length?t.substring(a,a+r.length)==r?a:this.match_bitap_(t,r,a):-1},e.prototype.match_bitap_=function(t,r,a){if(r.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var s=this.match_alphabet_(r),o=this;function i(A,w){var v=A/r.length,T=Math.abs(a-w);return o.Match_Distance?v+T/o.Match_Distance:T?1:v}var l=this.Match_Threshold,u=t.indexOf(r,a);u!=-1&&(l=Math.min(i(0,u),l),(u=t.lastIndexOf(r,a+r.length))!=-1&&(l=Math.min(i(0,u),l)));var c,d,f=1<<r.length-1;u=-1;for(var h,p=r.length+t.length,m=0;m<r.length;m++){for(c=0,d=p;c<d;)i(m,a+d)<=l?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;var g=Math.max(1,a-d+1),x=Math.min(a+d,t.length)+r.length,b=Array(x+2);b[x+1]=(1<<m)-1;for(var y=x;y>=g;y--){var N=s[t.charAt(y-1)];if(b[y]=m===0?(b[y+1]<<1|1)&N:(b[y+1]<<1|1)&N|(h[y+1]|h[y])<<1|1|h[y+1],b[y]&f){var L=i(m,y-1);if(L<=l){if(l=L,!((u=y-1)>a))break;g=Math.max(1,2*a-u)}}}if(i(m+1,a)>l)break;h=b}return u},e.prototype.match_alphabet_=function(t){for(var r={},a=0;a<t.length;a++)r[t.charAt(a)]=0;for(a=0;a<t.length;a++)r[t.charAt(a)]|=1<<t.length-a-1;return r},e.prototype.patch_addContext_=function(t,r){if(r.length!=0){if(t.start2===null)throw Error("patch not initialized");for(var a=r.substring(t.start2,t.start2+t.length1),s=0;r.indexOf(a)!=r.lastIndexOf(a)&&a.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)s+=this.Patch_Margin,a=r.substring(t.start2-s,t.start2+t.length1+s);s+=this.Patch_Margin;var o=r.substring(t.start2-s,t.start2);o&&t.diffs.unshift(new e.Diff(0,o));var i=r.substring(t.start2+t.length1,t.start2+t.length1+s);i&&t.diffs.push(new e.Diff(0,i)),t.start1-=o.length,t.start2-=o.length,t.length1+=o.length+i.length,t.length2+=o.length+i.length}},e.prototype.patch_make=function(t,r,a){var s,o;if(typeof t=="string"&&typeof r=="string"&&a===void 0)s=t,(o=this.diff_main(s,r,!0)).length>2&&(this.diff_cleanupSemantic(o),this.diff_cleanupEfficiency(o));else if(t&&typeof t=="object"&&r===void 0&&a===void 0)o=t,s=this.diff_text1(o);else if(typeof t=="string"&&r&&typeof r=="object"&&a===void 0)s=t,o=r;else{if(typeof t!="string"||typeof r!="string"||!a||typeof a!="object")throw new Error("Unknown call format to patch_make.");s=t,o=a}if(o.length===0)return[];for(var i=[],l=new e.patch_obj,u=0,c=0,d=0,f=s,h=s,p=0;p<o.length;p++){var m=o[p][0],g=o[p][1];switch(u||m===0||(l.start1=c,l.start2=d),m){case 1:l.diffs[u++]=o[p],l.length2+=g.length,h=h.substring(0,d)+g+h.substring(d);break;case-1:l.length1+=g.length,l.diffs[u++]=o[p],h=h.substring(0,d)+h.substring(d+g.length);break;case 0:g.length<=2*this.Patch_Margin&&u&&o.length!=p+1?(l.diffs[u++]=o[p],l.length1+=g.length,l.length2+=g.length):g.length>=2*this.Patch_Margin&&u&&(this.patch_addContext_(l,f),i.push(l),l=new e.patch_obj,u=0,f=h,c=d)}m!==1&&(c+=g.length),m!==-1&&(d+=g.length)}return u&&(this.patch_addContext_(l,f),i.push(l)),i},e.prototype.patch_deepCopy=function(t){for(var r=[],a=0;a<t.length;a++){var s=t[a],o=new e.patch_obj;o.diffs=[];for(var i=0;i<s.diffs.length;i++)o.diffs[i]=new e.Diff(s.diffs[i][0],s.diffs[i][1]);o.start1=s.start1,o.start2=s.start2,o.length1=s.length1,o.length2=s.length2,r[a]=o}return r},e.prototype.patch_apply=function(t,r){if(t.length==0)return[r,[]];t=this.patch_deepCopy(t);var a=this.patch_addPadding(t);r=a+r+a,this.patch_splitMax(t);for(var s=0,o=[],i=0;i<t.length;i++){var l,u,c=t[i].start2+s,d=this.diff_text1(t[i].diffs),f=-1;if(d.length>this.Match_MaxBits?(l=this.match_main(r,d.substring(0,this.Match_MaxBits),c))!=-1&&((f=this.match_main(r,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))==-1||l>=f)&&(l=-1):l=this.match_main(r,d,c),l==-1)o[i]=!1,s-=t[i].length2-t[i].length1;else if(o[i]=!0,s=l-c,d==(u=f==-1?r.substring(l,l+d.length):r.substring(l,f+this.Match_MaxBits)))r=r.substring(0,l)+this.diff_text2(t[i].diffs)+r.substring(l+d.length);else{var h=this.diff_main(d,u,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(h)/d.length>this.Patch_DeleteThreshold)o[i]=!1;else{this.diff_cleanupSemanticLossless(h);for(var p,m=0,g=0;g<t[i].diffs.length;g++){var x=t[i].diffs[g];x[0]!==0&&(p=this.diff_xIndex(h,m)),x[0]===1?r=r.substring(0,l+p)+x[1]+r.substring(l+p):x[0]===-1&&(r=r.substring(0,l+p)+r.substring(l+this.diff_xIndex(h,m+x[1].length))),x[0]!==-1&&(m+=x[1].length)}}}}return[r=r.substring(a.length,r.length-a.length),o]},e.prototype.patch_addPadding=function(t){for(var r=this.Patch_Margin,a="",s=1;s<=r;s++)a+=String.fromCharCode(s);for(s=0;s<t.length;s++)t[s].start1+=r,t[s].start2+=r;var o=t[0],i=o.diffs;if(i.length==0||i[0][0]!=0)i.unshift(new e.Diff(0,a)),o.start1-=r,o.start2-=r,o.length1+=r,o.length2+=r;else if(r>i[0][1].length){var l=r-i[0][1].length;i[0][1]=a.substring(i[0][1].length)+i[0][1],o.start1-=l,o.start2-=l,o.length1+=l,o.length2+=l}return(i=(o=t[t.length-1]).diffs).length==0||i[i.length-1][0]!=0?(i.push(new e.Diff(0,a)),o.length1+=r,o.length2+=r):r>i[i.length-1][1].length&&(l=r-i[i.length-1][1].length,i[i.length-1][1]+=a.substring(0,l),o.length1+=l,o.length2+=l),a},e.prototype.patch_splitMax=function(t){for(var r=this.Match_MaxBits,a=0;a<t.length;a++)if(!(t[a].length1<=r)){var s=t[a];t.splice(a--,1);for(var o=s.start1,i=s.start2,l="";s.diffs.length!==0;){var u=new e.patch_obj,c=!0;for(u.start1=o-l.length,u.start2=i-l.length,l!==""&&(u.length1=u.length2=l.length,u.diffs.push(new e.Diff(0,l)));s.diffs.length!==0&&u.length1<r-this.Patch_Margin;){var d=s.diffs[0][0],f=s.diffs[0][1];d===1?(u.length2+=f.length,i+=f.length,u.diffs.push(s.diffs.shift()),c=!1):d===-1&&u.diffs.length==1&&u.diffs[0][0]==0&&f.length>2*r?(u.length1+=f.length,o+=f.length,c=!1,u.diffs.push(new e.Diff(d,f)),s.diffs.shift()):(f=f.substring(0,r-u.length1-this.Patch_Margin),u.length1+=f.length,o+=f.length,d===0?(u.length2+=f.length,i+=f.length):c=!1,u.diffs.push(new e.Diff(d,f)),f==s.diffs[0][1]?s.diffs.shift():s.diffs[0][1]=s.diffs[0][1].substring(f.length))}l=(l=this.diff_text2(u.diffs)).substring(l.length-this.Patch_Margin);var h=this.diff_text1(s.diffs).substring(0,this.Patch_Margin);h!==""&&(u.length1+=h.length,u.length2+=h.length,u.diffs.length!==0&&u.diffs[u.diffs.length-1][0]===0?u.diffs[u.diffs.length-1][1]+=h:u.diffs.push(new e.Diff(0,h))),c||t.splice(++a,0,u)}}},e.prototype.patch_toText=function(t){for(var r=[],a=0;a<t.length;a++)r[a]=t[a];return r.join("")},e.prototype.patch_fromText=function(t){var r=[];if(!t)return r;for(var a=t.split(`
|
|
20
20
|
`),s=0,o=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;s<a.length;){var i=a[s].match(o);if(!i)throw new Error("Invalid patch string: "+a[s]);var l=new e.patch_obj;for(r.push(l),l.start1=parseInt(i[1],10),i[2]===""?(l.start1--,l.length1=1):i[2]=="0"?l.length1=0:(l.start1--,l.length1=parseInt(i[2],10)),l.start2=parseInt(i[3],10),i[4]===""?(l.start2--,l.length2=1):i[4]=="0"?l.length2=0:(l.start2--,l.length2=parseInt(i[4],10)),s++;s<a.length;){var u=a[s].charAt(0);try{var c=decodeURI(a[s].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+c)}if(u=="-")l.diffs.push(new e.Diff(-1,c));else if(u=="+")l.diffs.push(new e.Diff(1,c));else if(u==" ")l.diffs.push(new e.Diff(0,c));else{if(u=="@")break;if(u!=="")throw new Error('Invalid patch mode "'+u+'" in: '+c)}s++}}return r},(e.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0}).prototype.toString=function(){for(var t,r=["@@ -"+(this.length1===0?this.start1+",0":this.length1==1?this.start1+1:this.start1+1+","+this.length1)+" +"+(this.length2===0?this.start2+",0":this.length2==1?this.start2+1:this.start2+1+","+this.length2)+` @@
|
|
21
21
|
`],a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case 1:t="+";break;case-1:t="-";break;case 0:t=" "}r[a+1]=t+encodeURI(this.diffs[a][1])+`
|
|
22
|
-
`}return r.join("").replace(/%20/g," ")},n.exports=e,n.exports.diff_match_patch=e,n.exports.DIFF_DELETE=-1,n.exports.DIFF_INSERT=1,n.exports.DIFF_EQUAL=0})),
|
|
22
|
+
`}return r.join("").replace(/%20/g," ")},n.exports=e,n.exports.diff_match_patch=e,n.exports.DIFF_DELETE=-1,n.exports.DIFF_INSERT=1,n.exports.DIFF_EQUAL=0})),hz=ip.DIFF_EQUAL,pz=ip.DIFF_DELETE,mz=ip.DIFF_INSERT;var VR=["enhancers"],jv=function(n){var e,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=t.enhancers,a=r===void 0?[]:r,s=Jt(ER(n,Bs(t,VR)),2),o=s[0],i=s[1],l=[av(o),av(i)],u=(e=[l[0],l[1]],a.reduce((function(m,g){return g(m)}),e)),c=Jt(u,2),d=c[0],f=c[1],h=[d.map(sv),f.map(sv)],p=h[1];return{old:h[0].map((function(m){var g;return(g=m.children)!==null&&g!==void 0?g:[]})),new:p.map((function(m){var g;return(g=m.children)!==null&&g!==void 0?g:[]}))}};var ov;var gz=(ov=0,function(){return ov+=1});var cp=j(ta(),1);function qv(n){let e=n.split(`
|
|
23
23
|
`),t=[],r=0;for(;r<e.length&&!e[r].startsWith("@@");)t.push(e[r]),r++;let a=[],s=null;for(;r<e.length;r++){let o=e[r];o.startsWith("@@")?(s&&a.push(s.join(`
|
|
24
24
|
`)),s=[o]):s&&s.push(o)}return s&&a.push(s.join(`
|
|
25
25
|
`)),{header:t.join(`
|
|
26
|
-
`),hunks:a}}function
|
|
26
|
+
`),hunks:a}}function Vv(n,e){let t=n.replace(/\n+$/,"");if(!t.trim())return null;let r=`${t}
|
|
27
27
|
${e}`;return r.endsWith(`
|
|
28
28
|
`)?r:`${r}
|
|
29
|
-
`}function
|
|
30
|
-
`);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function
|
|
31
|
-
`})}),a}}}function a1(n,e,t="dark-plus"){let r=vi(e);if(r&&Yc(r))try{return Uv(n,{highlight:!0,refractor:_R(t),language:r})}catch{return}}var s1=(n,e,t)=>{let r=n.color;return n.type==="element"&&typeof r=="string"?(0,r1.createElement)("span",{key:t,style:{color:r}},n.children?.map((a,s)=>e(a,s))):e(n,t)};function Zc(n){let e=yt(String(n||"")).toLowerCase().trim();if(!e)return;let t=e;if(t==="dockerfile")return"docker";let r=t.includes(".")?t.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var Qc=W($e(),1);function ed(n,e){let t=e?.wideThresholdPx??900,r=e?.hysteresisPx??60,[a,s]=(0,Qc.useState)(!1);return(0,Qc.useEffect)(()=>{let o=n.current;if(!o){s(!1);return}let i=()=>{let u=o.clientWidth;s(c=>c?u>=t-r:u>=t)};if(i(),typeof ResizeObserver>"u")return;let l=new ResizeObserver(()=>i());return l.observe(o),()=>l.disconnect()},[n,t,r]),a}var td=W(le(),1),HR=[{key:"auto",label:"Auto",Icon:Ps},{key:"unified",label:"Unified",Icon:As},{key:"split",label:"Split",Icon:gs}];function nd({className:n}){let e=B(r=>r.diffViewMode),t=B(r=>r.setDiffViewMode);return(0,td.jsx)("div",{className:q("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",n),children:HR.map(({key:r,label:a,Icon:s})=>(0,td.jsx)("button",{type:"button",onClick:()=>t(r),className:q("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,td.jsx)(s,{className:"w-3 h-3"})},r))})}var Qe=W(le(),1),UR={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function sp(n,e,t,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${n}\0${e}\0${t}\0${JSON.stringify(a)}`}function bo({source:n,repo:e="",path:t,mode:r,agentId:a,projectId:s,variant:o="tab",revision:i=0,canWrite:l=!1,runContent:u,peekContent:c}){let[d]=(0,gt.useState)(()=>c?.(`${sp(n,e,t,r)}\0${i}`,sp(n,e,t,r))),[f,h]=(0,gt.useState)(()=>d===void 0?null:d&&d.ok!==!1?d.diff:""),[p,m]=(0,gt.useState)(!1),[g,x]=(0,gt.useState)(null),[w,y]=(0,gt.useState)(()=>d!==void 0&&d.ok!==!1&&d.truncated===!0),[C,k]=(0,gt.useState)(()=>d!==void 0&&d.ok===!1),[v,b]=(0,gt.useState)(0),[P,N]=(0,gt.useState)(null),[M,U]=(0,gt.useState)(null),[I,A]=(0,gt.useState)([]),[G,V]=(0,gt.useState)(null),[K,L]=(0,gt.useState)(!1),R=(0,gt.useRef)(new Map),z=(0,gt.useRef)(0),J=B(te=>te.loadGitStatus),Q=r.kind,re=r.kind==="working"?r.staged:!1,pe=r.kind==="commit"?r.sha:null,ee=r.kind==="range"?r.base:null,ce=r.kind==="range"?r.head:null,ue=(0,gt.useMemo)(()=>Q==="working"?{kind:Q,staged:re}:Q==="commit"?{kind:Q,sha:pe??""}:{kind:Q,base:ee??"",head:ce??""},[Q,re,pe,ee,ce]),He=(0,gt.useMemo)(()=>Xv(ue),[ue]),De=B(te=>te.diffViewMode),je=(0,gt.useRef)(null),et=ed(je),Dt=De==="auto"?et?"split":"unified":De,at=(0,gt.useMemo)(()=>Zc(t),[t]),[vt,Pt]=(0,gt.useState)(!1);(0,gt.useEffect)(()=>{let te=vi(at);if(!te){Pt(!1);return}if(Yc(te)){Pt(!0);return}let Ce=!1;return Pt(!1),eu().then(()=>Jc(te)).then(Ge=>{Ce||Pt(Ge)}),()=>{Ce=!0}},[at]),(0,gt.useEffect)(()=>{if(R.current.clear(),A([]),V(null),L(!1),!a||!n||!t){y(!1),k(!1),h(null),x(null),m(!1);return}let te=++z.current;return m(!0),x(null),(async()=>{try{let Ce=()=>ec({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,...Kv(ue)}),Ge=sp(n,e,t,ue),Ke={key:`${Ge}\0${i}`,family:Ge,bytes:he=>he&&he.ok!==!1?he.diff.length*2:64,fresh:v>0},Ae=u?await u(Ce,()=>te===z.current,Ke):await Ce();if(!Ae||te!==z.current)return;Ae&&Ae.ok===!1?(h(""),k(!0),y(!1)):(h(typeof Ae?.diff=="string"?Ae.diff:""),k(!1),y(Ae?.truncated===!0)),m(!1)}catch(Ce){if(te!==z.current)return;x(Ce instanceof Error?Ce.message:"Diff failed"),h(null),k(!1),y(!1),m(!1)}})(),()=>{z.current++}},[a,s,n,e,t,ue,v,i,u]);let{files:Ye,truncated:Ne,hunkPatches:tt}=(0,gt.useMemo)(()=>Wv(f,w),[f,w]),Je=Ye.some(te=>te.hunks.length>0),Ft=yt(t)||t,Mt=Qv(g),Te=Ye.length===1?Ye[0]:null,oe=l&&Q==="working"&&!!a&&!!Te&&Te.type==="modify"&&!Ne&&!!tt&&tt.hunks.length===Te.hunks.length,jt=!!a&&!!Te&&!Ne&&Te.hunks.length>0,Kt=(0,gt.useCallback)(async()=>{if(!a)return null;let te=z.current,Ce=He.type==="worktree"?"wt":He.rev,Ge=`${n}\0${e}\0${t}\0${Ce}`,Ke=R.current.get(Ge),Ae=he=>(R.current.set(Ge,he),te===z.current&&(he.ok?V(he.content):L(!0)),he.ok?he.content:null);if(Ke)return Ae(Ke);try{if(He.type==="show"){let xn=()=>U0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,rev:He.rev}),yn=u?await u(xn,()=>te===z.current):await xn();return!yn||te!==z.current?null:Ae(yn.ok?{ok:!0,content:yn.content}:{ok:!1})}let he=()=>Ko({agentId:a,...s?{projectId:s}:{},files:[`${n}://${e?`${e}/`:""}${t}`]}),ut=u?await u(he,()=>te===z.current):await he();if(!ut||te!==z.current)return null;let Qt=Yo(ut)[0];return!Qt||typeof Qt.error=="string"?Ae({ok:!1}):Ae({ok:!0,content:Jo(Qt)})}catch{return Ae({ok:!1})}},[a,s,n,e,t,He,u]),de=(0,gt.useMemo)(()=>Te&&G!==null?$c(Te.hunks,G):null,[Te,G]),fe=(0,gt.useMemo)(()=>Ye.map(te=>te!==Te||!de||I.length===0?te.hunks:qv(te.hunks,de,I)),[Ye,Te,de,I]),qe=de?de.length:null,Re=(0,gt.useMemo)(()=>vt?Ye.map((te,Ce)=>a1(fe[Ce]??te.hunks,at)):Ye.map(()=>{}),[Ye,fe,at,vt]),Fe=(0,gt.useCallback)(async te=>{if(!jt)return;let Ce=z.current,Ge=G??await Kt();if(Ge===null||Ce!==z.current||!Te)return;let Ke;if(te.lines===null){let Ae=Ql(Te.hunks[Te.hunks.length-1]??null,$c(Te.hunks,Ge).length);if(!Ae||Ae.lines===null)return;Ke={start:Ae.start,end:Ae.end}}else Ke={start:te.start,end:te.end};A(Ae=>[...Ae,Ke])},[jt,G,Kt,Te]),Lt=(0,gt.useCallback)(async()=>{if(!jt||!Te)return;let te=z.current,Ce=G??await Kt();if(Ce===null||te!==z.current)return;let Ge=jv(Te.hunks,$c(Te.hunks,Ce).length);Ge.length>0&&A(Ke=>[...Ke,...Ge])},[jt,Te,G,Kt]),st=(0,gt.useMemo)(()=>{if(!jt||!Te)return!1;let te=Ye.indexOf(Te),Ce=fe[te]??Te.hunks;for(let Ge=0;Ge<Ce.length;Ge++)if(Vc(Ge===0?null:Ce[Ge-1],Ce[Ge]))return!0;return Ql(Ce[Ce.length-1]??null,qe)!==null},[jt,Te,Ye,fe,qe]),Le=(0,gt.useCallback)(async te=>{if(p||!oe||!tt||!a)return;let Ce=zv(tt.header,tt.hunks[te]);if(!Ce){U("Could not build a hunk patch for this change.");return}N(te),U(null);try{re?await j0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ce}):await W0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ce}),R.current.clear(),J({agentId:a,projectId:s}),b(Ge=>Ge+1)}catch(Ge){U(Ge instanceof Error?Ge.message:"Hunk apply failed")}finally{N(null)}},[p,oe,tt,a,s,n,e,re,J]),Ee=te=>{let Ce=te.lines===null?"Expand to end of file":`${te.lines} hidden ${te.lines===1?"line":"lines"}`;return K?te.lines===null?null:(0,Qe.jsx)(qc,{children:(0,Qe.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",Ce]})},`gap-${te.start}`):(0,Qe.jsx)(qc,{children:(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Fe(te)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",Ce]})},`gap-${te.start}`)},Et=(te,Ce)=>Ce.length===0?null:(0,Qe.jsx)(qc,{children:(0,Qe.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:Ce.map(Ge=>(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Le(Ge)},disabled:P!==null||p,className:q("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",re?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:re?"Unstage this hunk":"Stage this hunk",children:[P===Ge?(0,Qe.jsx)(op.LiveSpinner,{className:"h-3 w-3"}):re?(0,Qe.jsx)(ro,{className:"h-3 w-3"}):(0,Qe.jsx)(Fn,{className:"h-3 w-3"}),re?"Unstage hunk":"Stage hunk",Ce.length>1?(0,Qe.jsxs)("span",{className:"font-mono text-white/45",children:["@",Te?.hunks[Ge]?.oldStart]}):null]},Ge))})},`stage-${te.oldStart}`),qt=(0,Qe.jsxs)("button",{type:"button",onClick:()=>{Lt()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,Qe.jsx)(Hl,{className:"h-3 w-3"}),"Expand all"]}),Tn=g?Mt?(0,Qe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Qe.jsx)(no,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,Qe.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,Qe.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:g}):p&&!f?(0,Qe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Qe.jsx)(op.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):C?(0,Qe.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,Qe.jsx)(dt,{className:"h-3.5 w-3.5 shrink-0"}),(0,Qe.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):Je?(0,Qe.jsx)("div",{style:UR,className:q("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:Ye.map((te,Ce)=>{let Ge=te===Te&&jt;return(0,Qe.jsx)(Ev,{viewType:Dt,diffType:te.type,hunks:fe[Ce]??te.hunks,tokens:Re[Ce],renderToken:s1,children:Ke=>{let Ae=[],he=ut=>{ut&&Ae.push(ut)};if(Ke.forEach((ut,Qt)=>{if(Ge){let xn=Vc(Qt===0?null:Ke[Qt-1],ut);xn&&he(Ee(xn))}oe&&te===Te&&he(Et(ut,Vv(ut,te.hunks))),Ae.push((0,Qe.jsx)(np,{hunk:ut},`h-${ut.oldStart}-${ut.oldLines}`))}),Ge){let ut=Ql(Ke[Ke.length-1]??null,qe);ut&&he(Ee(ut))}return Ae}},`${te.oldRevision??""}-${te.newRevision??""}-${Ce}`)})}):(0,Qe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:Jv(ue)});return(0,Qe.jsxs)("div",{ref:je,className:q("flex w-full flex-col",o==="tab"&&"h-full min-h-0"),children:[o==="tab"?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Qe.jsx)(ar,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Qe.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:Ft}),(0,Qe.jsx)("span",{className:"truncate font-mono text-white/40",children:t}),(0,Qe.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:Yv(ue)}),(0,Qe.jsx)(nd,{}),st&&!K?qt:null]}):st&&!K?(0,Qe.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:qt}):null,Ne?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,Qe.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,Qe.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,M?(0,Qe.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,Qe.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,Qe.jsx)("span",{className:"truncate",children:M})]}):null,o==="tab"?(0,Qe.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Tn}):Tn]})}var nt=W(le(),1),ip={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},rd={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function GR(n){let e=new Date(n);return Number.isNaN(e.getTime())?n:e.toLocaleString()}var zR=(0,es.memo)(function({file:e,mode:t,source:r,repo:a,agentId:s,projectId:o,defaultExpanded:i,queue:l}){let[u,c]=(0,es.useState)(i),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,nt.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,nt.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,nt.jsx)(Tt,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,nt.jsx)(un,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,nt.jsx)("span",{className:q("shrink-0 text-[10px] font-bold leading-none tabular-nums",ip[d]??"text-white/60"),title:rd[d]??"Changed","aria-label":`Status: ${rd[d]??"Changed"}`,children:d}),(0,nt.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,nt.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,nt.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,nt.jsx)(La,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,nt.jsx)("div",{className:"border-t border-white/5",children:(0,nt.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,nt.jsx)(bo,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:t,agentId:s,projectId:o})})}):null]})});function lp({target:n,agentId:e,projectId:t}){let[r,a]=(0,es.useState)(null),s=Sc(r),[o,i]=(0,es.useState)({phase:"loading"}),[l,u]=(0,es.useState)(null),{source:c}=n,d=n.repo??"",f=n.kind==="commit"?`c:${d}:${n.sha}`:`o:${d}:${n.base}..${n.head}`;(0,es.useEffect)(()=>{if(i({phase:"loading"}),u(null),!e||!c)return;let g=!1;return(async()=>{try{if(n.kind==="commit"){let x=await nc({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},sha:n.sha});if(g)return;x.ok===!1?i({phase:"unavailable"}):i({phase:"ready",files:x.files,range:null});try{let w=await tc({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},maxCount:1,ref:n.sha}),y=Array.isArray(w?.commits)?w.commits[0]:void 0;!g&&y&&u({author:y.author,date:y.date})}catch{}}else{let x=await ol({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{}});if(g)return;!x.ok||!x.baseSha||!x.headSha?i({phase:"no-upstream"}):i({phase:"ready",files:Array.isArray(x.files)?x.files:[],range:{base:x.baseSha,head:x.headSha}})}}catch(x){if(g)return;i({phase:"error",message:x instanceof Error?x.message:"Change-set failed"})}})(),()=>{g=!0}},[e,t,c,f]);let h=n.kind==="commit"?n:null,p=h!==null,m=o.phase==="ready"&&o.range?`${tn(o.range.base)}..${tn(o.range.head)}`:n.kind==="outgoing"?`${tn(n.base)}..${tn(n.head)}`:"";return(0,nt.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,nt.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:h?(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,nt.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:tn(h.sha)}),(0,nt.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:h.subject}),l?(0,nt.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[l.author," \xB7 ",GR(l.date)]}):null]}):(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Er,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,nt.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,nt.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,nt.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,nt.jsx)("div",{ref:a,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,nt.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,nt.jsx)(ze,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,nt.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,nt.jsx)(dt,{className:"h-3.5 w-3.5 shrink-0"}),(0,nt.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,nt.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:p?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,nt.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(g=>(0,nt.jsx)(zR,{file:g,mode:h?{kind:"commit",sha:h.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:c,repo:d,agentId:e,projectId:t,defaultExpanded:!0,queue:s},g.path))})})]})}var ae=W(le(),1),Hr=30,d1=16,fp=14,o1=4.5,ad=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function cp(n){return ad[(n%ad.length+ad.length)%ad.length]}var dp=n=>fp+n*d1;function WR(){let n=null,e=new Set;return{get:()=>n,set:t=>{let r=typeof t=="function"?t(n):t;if(r!==n){n=r;for(let a of e)a()}},subscribe:t=>(e.add(t),()=>{e.delete(t)})}}var jR=null,qR=()=>jR;function VR({store:n,commits:e,expandedShas:t}){let r=it.default.useSyncExternalStore(n.subscribe,n.get,qR);if(!r||t.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ae.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:fp,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ae.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ae.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ae.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(a.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ae.jsx)("span",{children:Rh(a.date)})]})]}):null}function i1(n){let e=dp(n.fromLane),t=dp(n.toLane),r=n.fromY==="edge"?0:Hr/2,a=n.toY==="edge"?Hr:Hr/2;if(e===t)return`M${e} ${r} L${t} ${a}`;if(n.toY==="edge"){let o=2*t-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+o)/4} ${(r+3*a)/4} ${t} ${a}`}let s=2*e-t;return`M${e} ${r} C ${(s+3*t)/4} ${(3*r+a)/4} ${t} ${(r+a)/2} ${t} ${a}`}function $R(n){return(n.split("->").pop()??n).replace(/^tag:\s*/,"").trim()}function l1(n,e){(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),e())}function KR({file:n,onClick:e,showCounts:t}){let r=n.path.lastIndexOf("/"),a=r<0?n.path:n.path.slice(r+1),s=r<0?"":n.path.slice(0,r),o=(n.status[0]??"M").toUpperCase(),i=ci(n.path);return(0,ae.jsxs)("button",{type:"button",onClick:()=>e(n),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:n.renamedFrom?`${n.renamedFrom} \u2192 ${n.path}`:n.path,children:[(0,ae.jsx)(i,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ae.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ae.jsx)("span",{className:"flex-1"}),t?(0,ae.jsx)(La,{added:n.added,removed:n.removed,binary:n.binary,className:"mr-1"}):null,(0,ae.jsx)("span",{className:q("shrink-0 text-[10px] font-bold leading-none tabular-nums",ip[o]??"text-white/60"),"aria-label":`Status: ${rd[o]??"Changed"}`,children:o})]})}function u1({entry:n,emptyText:e,unavailableText:t,onFileClick:r,showCounts:a}){return n.status==="loading"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ae.jsx)(c1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):n.status==="error"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:n.message})]}):n.status==="unavailable"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:t}):n.files.length===0?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ae.jsx)("div",{className:"space-y-px",children:n.files.map(s=>(0,ae.jsx)(KR,{file:s,onClick:r,showCounts:a},s.path))})}function f1({source:n,repo:e="",agentId:t,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:o}){let[i,l]=(0,it.useState)(Ph),[u,c]=(0,it.useState)(!1),[d,f]=(0,it.useState)(null),h=(0,it.useRef)(0),p=(0,it.useRef)(!1),m=(0,it.useRef)(!1),g=(0,it.useRef)(i);g.current=i;let[x,w]=(0,it.useState)(()=>new Set),[y,C]=(0,it.useState)(!1),[k,v]=(0,it.useState)(()=>new Map),[b,P]=(0,it.useState)({status:"idle"}),N=(0,it.useRef)(null),M=(0,it.useRef)(null);M.current===null&&(M.current=WR());let U=M.current,I=(0,it.useRef)(0),A=(0,it.useRef)(0),G=B(de=>de.gitLogNonce),V=B(de=>de.setGitDiffTarget),K=B(de=>de.setGitCommitTarget),L=B(de=>de.setActiveWorkspaceTab),[R,z]=(0,it.useState)(null),[J,Q]=(0,it.useState)(null),[re,pe]=(0,it.useState)({}),ee=(0,it.useRef)(s);ee.current=s;let ce=(0,it.useRef)(o);ce.current=o;let ue=(0,it.useCallback)(async(de,fe,qe)=>{if(!t||!n)return;let Re=++h.current;p.current=!0,c(!0),f(null);try{let Fe=await tc({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:fe,skip:de});if(Re!==h.current)return;let Lt={commits:Array.isArray(Fe?.commits)?Fe.commits:[],hasMore:Fe?.hasMore===!0,outgoing:Array.isArray(Fe?.outgoing)?Fe.outgoing:void 0};l(st=>qe==="append"?yw(st,Lt):bw(Lt)),ee.current&&H0({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:fe,skip:de}).then(st=>{Re===h.current&&(pe(Le=>qe==="append"?{...Le,...st.stats}:{...st.stats}),qe==="replace"&&ce.current?.(st.outgoingStat??null))}).catch(()=>{}),qe==="replace"&&(A.current++,P(st=>st.status==="idle"?st:{status:"idle"})),c(!1)}catch(Fe){if(Re!==h.current)return;f(Fe instanceof Error?Fe.message:"Git log failed"),c(!1)}finally{Re===h.current&&(p.current=!1)}},[t,r,n,e]);(0,it.useEffect)(()=>{if(h.current++,p.current=!1,I.current++,A.current++,l(Ph),f(null),w(new Set),C(!1),v(new Map),P({status:"idle"}),!t||!n){c(!1);return}ue(0,200,"replace")},[t,r,n,ue]);let He=(0,it.useRef)(G);(0,it.useEffect)(()=>{G!==He.current&&(He.current=G,!(!t||!n)&&ue(0,Nh(g.current.commits.length),"replace"))},[G,t,n,ue]),(0,it.useEffect)(()=>{if(!R||!J||(m.current=!1,typeof IntersectionObserver>"u"))return;let de=new IntersectionObserver(fe=>{for(let Re of fe)m.current=Re.isIntersecting;if(!m.current)return;let qe=g.current;!qe.hasMore||p.current||ue(qe.nextSkip,200,"append")},{root:R,rootMargin:"120px"});return de.observe(J),()=>de.disconnect()},[R,J,ue]),(0,it.useEffect)(()=>{u||d!==null||!m.current||p.current||i.hasMore&&ue(i.nextSkip,200,"append")},[i,u,d,ue]);let De=(0,it.useCallback)(async de=>{if(!t||!n)return;let fe=I.current;v(qe=>new Map(qe).set(de,{status:"loading"}));try{let qe=await nc({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},sha:de});if(fe!==I.current)return;v(Re=>new Map(Re).set(de,qe.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(qe.files)?qe.files:[]}))}catch(qe){if(fe!==I.current)return;v(Re=>new Map(Re).set(de,{status:"error",message:qe instanceof Error?qe.message:"Commit files failed"}))}},[t,r,n,e]),je=i.commits,et=Ts(n,a),Dt=(0,it.useMemo)(()=>mw(je),[je]),at=Math.max(40,fp+Dt.laneCount*d1+8),vt=(0,it.useMemo)(()=>ww(je,i.outgoing),[je,i.outgoing]),Pt=(0,it.useMemo)(()=>new Set(i.outgoing??[]),[i.outgoing]),Ye=(0,it.useMemo)(()=>vt.some(de=>de.kind==="outgoing-divider"),[vt]);(0,it.useEffect)(()=>{if(!y||b.status!=="idle"||!Ye||!t||!n)return;let de=++A.current;P({status:"loading"}),(async()=>{try{let fe=await ol({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(de!==A.current)return;!fe.ok||!fe.baseSha||!fe.headSha?P({status:"no-upstream"}):P({status:"ready",base:fe.baseSha,head:fe.headSha,files:Array.isArray(fe.files)?fe.files:[]})}catch(fe){if(de!==A.current)return;P({status:"error",message:fe instanceof Error?fe.message:"Outgoing changes failed"})}})()},[y,b.status,Ye,t,r,n,e]);let Ne=ii({count:vt.length,getScrollElement:()=>R,estimateSize:()=>Hr,overscan:12,getItemKey:de=>vw(vt[de],je)}),tt=()=>{!t||!n||ue(0,Nh(g.current.commits.length),"replace")},Je=(de,fe)=>{if(x.has(de)){Ne.resizeItem(fe,Hr),w(Re=>{let Fe=new Set(Re);return Fe.delete(de),Fe});return}w(Re=>new Set(Re).add(de));let qe=k.get(de);(!qe||qe.status==="error")&&De(de)},Ft=de=>{let fe=!y;fe||Ne.resizeItem(de,Hr),fe&&b.status==="error"&&P({status:"idle"}),C(fe)},Mt=e?{repo:e}:{},Te=(de,fe)=>{n&&(V({source:n,...Mt,path:fe.path,commit:de}),L("git-diff"))},oe=de=>{n&&(K({source:n,...Mt,kind:"commit",sha:de.sha,subject:de.subject}),L("git-commit"))},jt=de=>{!n||b.status!=="ready"||(V({source:n,...Mt,path:de.path,base:b.base,head:b.head}),L("git-diff"))},Kt=()=>{if(!n||!t)return;if(b.status==="ready"){K({source:n,...Mt,kind:"outgoing",base:b.base,head:b.head}),L("git-commit");return}let de=++A.current;P({status:"loading"}),(async()=>{try{let fe=await ol({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(de!==A.current)return;if(!fe.ok||!fe.baseSha||!fe.headSha){P({status:"no-upstream"});return}P({status:"ready",base:fe.baseSha,head:fe.headSha,files:Array.isArray(fe.files)?fe.files:[]}),K({source:n,...Mt,kind:"outgoing",base:fe.baseSha,head:fe.headSha}),L("git-commit")}catch(fe){if(de!==A.current)return;P({status:"error",message:fe instanceof Error?fe.message:"Outgoing changes failed"})}})()};return(0,ae.jsxs)("div",{ref:N,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ae.jsx)(Or,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),et.prefix?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:et.prefix}),(0,ae.jsx)("span",{className:"truncate font-medium text-white/85",children:et.name})]}):(0,ae.jsx)("span",{className:"truncate font-mono text-white/40",children:et.name}),(0,ae.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[je.length,i.hasMore?"+":""," commit",je.length===1?"":"s"]}),(0,ae.jsx)("button",{type:"button",onClick:tt,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ae.jsx)(Ht,{className:q("h-3 w-3",u&&"animate-spin")})})]}),d&&je.length>0?(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:d})]}):null,(0,ae.jsx)("div",{ref:z,className:"min-h-0 flex-1 overflow-auto",children:d&&je.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ae.jsx)(dt,{className:"h-3 w-3 shrink-0"}),d]}):u&&je.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ae.jsx)(ze,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):je.length===0?(0,ae.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("div",{style:{height:Ne.getTotalSize(),width:"100%",position:"relative"},children:Ne.getVirtualItems().map(de=>{let fe=vt[de.index];if(!fe)return null;if(fe.kind==="outgoing-divider"){let te=b.status==="ready"?{status:"ready",files:b.files}:b.status==="error"?b:{status:"loading"},Ce=vt[de.index+1],Ge=gw(Dt.rowSegments,Ce?.kind==="commit"?Ce.row:-1);return(0,ae.jsxs)("div",{"data-index":de.index,ref:y?Ne.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${de.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>Ft(de.index),onKeyDown:Ke=>l1(Ke,()=>Ft(de.index)),className:q("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",Ge.length>0?"pr-2":"px-2"),style:{height:Hr},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[Ge.length>0?(0,ae.jsx)("svg",{"data-divider-lanes":!0,width:at,height:Hr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:Ge.map((Ke,Ae)=>(0,ae.jsx)("path",{d:i1(Ke),fill:"none",stroke:cp(Ke.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},Ae))}):null,y?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ae.jsx)(Er,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ae.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:i.outgoing?.length??0}),(0,ae.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ae.jsx)("button",{type:"button",onClick:Ke=>{Ke.stopPropagation(),Kt()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ae.jsx)(ni,{className:"h-3 w-3"})})]}),y?(0,ae.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:b.status==="no-upstream"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ae.jsx)(u1,{entry:te,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:jt,showCounts:s})}):null]},de.key)}let qe=Dt.nodes[fe.row];if(!qe)return null;let Re=qe.commit,Fe=Dt.rowSegments[fe.row]??[],Lt=dp(qe.lane),st=cp(qe.lane),Le=Re.refs??[],Ee=x.has(Re.sha),Et=Sw(qe.isMerge,Pt.has(Re.sha)),qt=Cw(Et,st),Tn=k.get(Re.sha);return(0,ae.jsxs)("div",{"data-index":de.index,ref:Ee?Ne.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${de.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Re.sha,onClick:()=>Je(Re.sha,de.index),onKeyDown:te=>l1(te,()=>Je(Re.sha,de.index)),onMouseEnter:te=>{if(Ee)return;let Ce=N.current;if(!Ce)return;let Ge=Ce.getBoundingClientRect(),Ke=te.currentTarget.getBoundingClientRect(),Ae=Ke.bottom-Ge.top,he=Ge.bottom-Ke.top;U.set({sha:Re.sha,below:Ae,above:he,flip:Ae>Ge.height*.55})},onMouseLeave:()=>U.set(te=>te&&te.sha===Re.sha?null:te),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Hr},children:[(0,ae.jsxs)("svg",{width:at,height:Hr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[Fe.map((te,Ce)=>(0,ae.jsx)("path",{d:i1(te),fill:"none",stroke:cp(te.colorLane),strokeWidth:1.5,strokeOpacity:te.kind==="stub"?.3:.55,strokeDasharray:te.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},Ce)),qe.isHead?(0,ae.jsx)("circle",{cx:Lt,cy:Hr/2,r:o1+2.5,fill:"none",stroke:qt,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ae.jsx)("circle",{cx:Lt,cy:Hr/2,r:o1,fill:Et==="outgoing"?"transparent":Et==="merge"?"rgba(0,0,0,0.35)":st,stroke:qt,strokeWidth:Et==="filled"?1:1.5,fillOpacity:Et==="filled"?.9:1})]}),(0,ae.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[Ee?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/25"}),Le.length?(0,ae.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Le.slice(0,3).map(te=>{let Ce=kw(te);return(0,ae.jsxs)("span",{className:q("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",Ce==="tag"?"bg-amber-400/15 text-amber-100/80":Ce==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[Ce==="remote"?(0,ae.jsx)(yl,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ae.jsx)("span",{className:"truncate",children:$R(te)})]},te)})}):null,(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Re.subject||"(no message)"}),(0,ae.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Re.author}),s&&re[Re.sha]?(0,ae.jsx)(La,{...re[Re.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ae.jsx)("button",{type:"button",onClick:te=>{te.stopPropagation(),oe(Re)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${tn(Re.sha)}`,children:(0,ae.jsx)(ni,{className:"h-3 w-3"})})]})]}),Ee?(0,ae.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:tn(Re.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:Re.author}),(0,ae.jsx)("span",{title:Re.date,children:Rh(Re.date)})]}),(0,ae.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ae.jsx)(u1,{entry:Tn??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:te=>Te(Re.sha,te),showCounts:s})})]}):null]},de.key)})}),i.hasMore?(0,ae.jsxs)("div",{ref:Q,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ae.jsx)(ze,{className:q("h-3 w-3",u&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ae.jsx)(VR,{store:U,commits:je,expandedShas:x})]})}var pn=W($e(),1);function tu(n){return Number.isFinite(n)?Math.min(20,Math.max(.05,n)):1}function h1(n){return n>0&&n<1?1/n:1}function p1(n){if(!n)return{};try{let e=JSON.parse(n);if(!e||typeof e!="object"||Array.isArray(e))return{};let t={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(t[r]={collapsed:s.collapsed,weight:tu(s.weight)})}return t}catch{return{}}}function m1(n){return JSON.stringify(n)}function nu(n,e,t,r=1){return n[e]??{collapsed:t,weight:tu(r)}}function g1(n,e,t,r,a=1){let s=nu(n,e,r,a),o=!t&&s.weight<.15?tu(a):s.weight;return{...n,[e]:{collapsed:t,weight:o}}}function x1(n){let e=n.minBodyPx??72,t=n.heightAbove+n.heightBelow,r=n.weightAbove+n.weightBelow;if(!(t>0)||!(r>0)||t<e*2)return{above:n.weightAbove,below:n.weightBelow};let a=Math.min(t-e,Math.max(e,n.heightAbove+n.deltaY)),s=tu(r*(a/t)),o=tu(r-s);return{above:s,below:o}}var Ur=W(le(),1),XR=4;function YR(n){if(typeof window>"u")return{};try{return p1(window.localStorage.getItem(n))}catch{return{}}}function y1({sections:n,storageKey:e}){let[t,r]=(0,pn.useState)(()=>YR(e)),[a,s]=(0,pn.useState)(!1),o=(0,pn.useRef)(t);o.current=t;let i=(0,pn.useRef)(new Map),l=(0,pn.useRef)(null),u=(0,pn.useRef)(!1),c=(0,pn.useCallback)(b=>{if(typeof window<"u")try{window.localStorage.setItem(e,m1(b))}catch{}},[e]),d=(0,pn.useCallback)((b,P,N)=>{r(M=>{let U=nu(M,b,P,N),I=g1(M,b,!U.collapsed,P,N);return c(I),I})},[c]),f=(0,pn.useCallback)((b,P,N,M,U,I,A)=>{let G=i.current.get(P),V=i.current.get(N);I&&b.preventDefault(),l.current={aboveId:P,belowId:N,startY:b.clientY,weightAbove:M,weightBelow:U,heightAbove:G?.getBoundingClientRect().height??0,heightBelow:V?.getBoundingClientRect().height??0,engaged:I,belowCollapsed:A,expanded:!1,rebaselined:!1},u.current=!1,s(I),b.currentTarget.setPointerCapture(b.pointerId)},[]),h=(0,pn.useCallback)((b,P,N,M,U,I)=>{f(b,P,N,M,U,!0,I)},[f]),p=(0,pn.useCallback)((b,P,N,M,U,I)=>{b.button===0&&f(b,P,N,M,U,!1,I)},[f]),m=(0,pn.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(o.current))},[c]);(0,pn.useEffect)(()=>{if(a)return window.addEventListener("pointerup",m),window.addEventListener("pointercancel",m),()=>{window.removeEventListener("pointerup",m),window.removeEventListener("pointercancel",m)}},[a,m]);let g=(0,pn.useCallback)(b=>{let P=l.current;if(!P)return;if((b.buttons&1)===0){m();return}let N=b.clientY-P.startY;if(!P.engaged){if(Math.abs(N)<XR)return;P.engaged=!0,u.current=!0,s(!0)}if(P.belowCollapsed&&!P.expanded){P.expanded=!0,r(I=>({...I,[P.belowId]:{collapsed:!1,weight:P.weightBelow}}));return}if(P.belowCollapsed&&!P.rebaselined){let I=i.current.get(P.belowId);if(!I)return;let A=i.current.get(P.aboveId);P.heightAbove=A?.getBoundingClientRect().height??P.heightAbove,P.heightBelow=I.getBoundingClientRect().height,P.startY=b.clientY,P.weightAbove=o.current[P.aboveId]?.weight??P.weightAbove,P.weightBelow=o.current[P.belowId]?.weight??P.weightBelow,P.rebaselined=!0;return}let{above:M,below:U}=x1({weightAbove:P.weightAbove,weightBelow:P.weightBelow,heightAbove:P.heightAbove,heightBelow:P.heightBelow,deltaY:N});r(I=>({...I,[P.aboveId]:{...I[P.aboveId]??{collapsed:!1,weight:1},weight:M},[P.belowId]:{...I[P.belowId]??{collapsed:!1,weight:1},weight:U}}))},[m]),x=(0,pn.useCallback)(b=>{b.currentTarget.hasPointerCapture(b.pointerId)&&b.currentTarget.releasePointerCapture(b.pointerId),m()},[m]),w=(0,pn.useCallback)((b,P,N,M)=>{let U=l.current?.engaged??!1,I=l.current!=null;b.currentTarget.hasPointerCapture(b.pointerId)&&b.currentTarget.releasePointerCapture(b.pointerId),m(),I&&!U&&d(P,N,M)},[m,d]),y=n.reduce((b,P)=>{let N=nu(t,P.id,P.defaultCollapsed??!1,P.defaultWeight??1);return N.collapsed?b:b+N.weight},0),C=h1(y),k=[],v=null;for(let b of n){let P=b.defaultCollapsed??!1,N=b.defaultWeight??1,M=nu(t,b.id,P,N),U=v&&!v.collapsed?v:null,I=M.collapsed?N:M.weight;U&&k.push((0,Ur.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:A=>h(A,U.id,b.id,U.weight,I,M.collapsed),onPointerMove:g,onPointerUp:x,onPointerCancel:m,onLostPointerCapture:m,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,Ur.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${U.id}:${b.id}`)),k.push((0,Ur.jsxs)("div",{onPointerDown:U?A=>{A.target.closest("[data-section-actions]")||p(A,U.id,b.id,U.weight,I,M.collapsed)}:void 0,onPointerMove:U?g:void 0,onPointerUp:U?A=>w(A,b.id,P,N):void 0,onPointerCancel:U?m:void 0,onLostPointerCapture:U?m:void 0,className:q("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",U&&"touch-none"),children:[(0,Ur.jsxs)("button",{type:"button",onClick:A=>{U&&A.detail!==0||d(b.id,P,N)},"aria-expanded":!M.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,Ur.jsx)(un,{className:q("h-3 w-3 shrink-0 text-white/40 transition-transform",!M.collapsed&&"rotate-90")}),(0,Ur.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:b.title}),typeof b.count=="number"?(0,Ur.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:b.count}):null,b.badge]}),b.actions?(0,Ur.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:b.actions}):null]},`s:${b.id}`)),M.collapsed||k.push((0,Ur.jsx)("div",{ref:A=>{A?i.current.set(b.id,A):i.current.delete(b.id)},className:"min-h-0 overflow-auto",style:{flexGrow:M.weight*C,flexBasis:0},children:b.content},`b:${b.id}`)),v={id:b.id,collapsed:M.collapsed,weight:M.weight}}return(0,Ur.jsx)("div",{className:q("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:k})}var _=W(le(),1);function hp(n,e,t){(0,ye.useEffect)(()=>{if(!n)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||t()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[n,e,t])}var JR="neuralis.filesystem.gitPanel.sections",b1="neuralis.filesystem.gitPanel.commitOpen",w1="neuralis.filesystem.gitPanel.diffCounts";function ZR(n){return typeof n!="string"||!n?"":n.includes("://")?Ve(n):n}function QR(n){let e=n.lastIndexOf("/");return e<0?{name:n,dir:""}:{name:n.slice(e+1),dir:n.slice(0,e)}}function eM(n){let e={name:"",path:"",children:new Map};for(let t of n){let r=t.path.split("/").filter(Boolean),a=e,s="";for(let o=0;o<r.length;o++){let i=r[o];s=s?`${s}/${i}`:i;let l=a.children.get(i);l||(l={name:i,path:s,children:new Map},a.children.set(i,l)),a=l,o===r.length-1&&(a.change=t)}}return e}function I1(n,e){let t=[],r=[...n.children.values()].sort((a,s)=>{let o=a.children.size>0,i=s.children.size>0;return o!==i?o?-1:1:a.name.localeCompare(s.name)});for(let a of r)t.push({node:a,depth:e}),a.children.size>0&&t.push(...I1(a,e+1));return t}var v1=Object.freeze({}),k1=ye.default.memo(function({change:e,onClick:t,actions:r,busy:a,showCounts:s}){let{name:o,dir:i}=QR(e.path),l=ci(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,_.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,_.jsxs)("button",{type:"button",onClick:()=>t(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,_.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,_.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:o}),i?(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:i}):(0,_.jsx)("span",{className:"flex-1"})]}),s?(0,_.jsx)(La,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,_.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,_.jsx)(vc,{code:e.code})}),c?(0,_.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${o}`,children:(0,_.jsx)(It,{className:"h-3 w-3"})}):null,r.onUnstage?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${o}`,children:(0,_.jsx)(ro,{className:"h-3 w-3"})}):null,r.onStage?(0,_.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${o}`,children:(0,_.jsx)(Fn,{className:"h-3 w-3"})}):null]}):null]})});function S1({changes:n,viewMode:e,staged:t,onRowClick:r,actionsFor:a,busy:s,showCounts:o}){let i=(0,ye.useMemo)(()=>e==="tree"?I1(eM(n),0):[],[n,e]),l=(0,ye.useCallback)(u=>r(u,t),[r,t]);return(0,_.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,_.jsx)("div",{className:"space-y-px",children:n.map(u=>(0,_.jsx)(k1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:o},`${u.code}:${u.path}`))}):(0,_.jsx)("div",{className:"space-y-px",children:i.map(({node:u,depth:c})=>u.change?(0,_.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,_.jsx)(k1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:o})},`f:${u.path}`):(0,_.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,_.jsx)(Br,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,_.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function pp({tone:n,onClick:e,disabled:t,title:r,children:a}){return(0,_.jsx)("button",{type:"button",onClick:e,disabled:t,className:q("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",n==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":n==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function A1({agentId:n}){let e=B(D=>D.sources),t=B(D=>D.activeProjectId),r=B(D=>D.activeSource),a=B(D=>D.activeRepoRel),s=B(D=>D.setActiveSource),o=B(D=>D.gitStatus),i=B(D=>D.gitTotals),l=B(D=>D.gitOutgoingStat),u=B(D=>D.setGitOutgoingStat),c=B(D=>D.gitLoading),d=B(D=>D.gitError),f=B(D=>D.gitViewMode),h=B(D=>D.setGitViewMode),p=B(D=>D.gitBranches),m=B(D=>D.loadGitStatus),g=B(D=>D.loadGitBranches),x=B(D=>D.setGitDiffTarget),w=B(D=>D.setActiveWorkspaceTab),y=B(D=>D.gitLogNonce),[C,k]=(0,ye.useState)(!1),[v,b]=(0,ye.useState)(!1),P=(0,ye.useRef)(null),N=(0,ye.useRef)(null),[M,U]=(0,ye.useState)(!1),[I,A]=(0,ye.useState)(!1),[G,V]=(0,ye.useState)(null),[K,L]=(0,ye.useState)(""),[R,z]=(0,ye.useState)(!1),[J,Q]=(0,ye.useState)(()=>Mh(b1,!1)),[re,pe]=(0,ye.useState)(()=>Mh(w1,!0)),ee=(0,ye.useCallback)(()=>{pe(D=>{let me=!D;return Th(w1,me),me})},[]),[ce,ue]=(0,ye.useState)(null),[He,De]=(0,ye.useState)(null),[je,et]=(0,ye.useState)(!1),Dt=(0,ye.useCallback)(()=>k(!1),[]),at=(0,ye.useCallback)(()=>{b(!1),et(!1)},[]),vt=(0,ye.useCallback)(()=>U(!1),[]);hp(C,P,Dt),hp(v,N,at),hp(M,N,vt);let[Pt,Ye]=(0,ye.useState)(""),[Ne,tt]=(0,ye.useState)(""),Je=(0,ye.useMemo)(()=>e.filter(D=>D.git?.isRepo||D.git?.containsRepos),[e]),Ft=(0,ye.useMemo)(()=>Je.map(D=>D.uri_root).join("|"),[Je]),Mt=(0,ye.useMemo)(()=>ZR(r),[r]),Te=(0,ye.useMemo)(()=>Je.find(D=>Ve(D.uri_root)===Mt)??Je[0]??null,[Je,Mt]),oe=Te?Ve(Te.uri_root):"",jt=Je.length>1||Je.some(D=>!D.git?.isRepo&&D.git?.containsRepos),Kt=(0,ye.useRef)(new Map),[de,fe]=(0,ye.useState)(()=>new Map),qe=(0,ye.useCallback)(async(D,me)=>{if(!n||!D)return[];let Yt=Kt.current.get(D);if(Yt&&(Yt instanceof Promise||!me?.force))return Yt;let Ot=(async()=>{try{let Cn=await Xo({agentId:n,...t?{projectId:t}:{},source:D}),Tr=Array.isArray(Cn?.repos)?Cn.repos:[];return Kt.current.set(D,Tr),fe(Gf=>new Map(Gf).set(D,Tr)),Tr}catch{return Kt.current.delete(D),fe(Cn=>Cn.has(D)?Cn:new Map(Cn).set(D,[])),[]}})();return Kt.current.set(D,Ot),Ot},[n,t]),Re=(0,ye.useMemo)(()=>a?de.get(oe)?.find(D=>D.rel===a)??null:null,[a,de,oe]),Fe=a?Re?.canWrite===!0:Te?.git?.canWrite===!0,Lt=a?Re?.canExec===!0:Te?.git?.canExec===!0,st=o?.staged.length??0,Le=Ts(oe,a?Re?.name??a:Te?.git?.repoName),Ee=(0,ye.useMemo)(()=>Lw(o),[o]);(0,ye.useEffect)(()=>{oe&&oe!==Mt&&s(oe)},[n,t,oe,Ft]),(0,ye.useEffect)(()=>{let D=Te?.git;if(!oe||!D||D.isRepo||!D.containsRepos)return;let me=!1;return qe(oe).then(Yt=>{me||a||Yt.length===0||s(oe,Yt[0].rel)}),()=>{me=!0}},[oe,Te,a,qe,s]);let Et=(0,ye.useRef)(y);(0,ye.useEffect)(()=>{if(y===Et.current)return;Et.current=y;let D=Te?.git;!oe||!D||D.isRepo||!D.containsRepos||qe(oe,{force:!0})},[y,oe,Te,qe]),(0,ye.useEffect)(()=>{oe&&m({agentId:n,projectId:t??null,source:oe,repo:a})},[n,t,oe,a,Ft]),(0,ye.useEffect)(()=>{if(!He)return;let D=setTimeout(()=>De(null),9e3);return()=>clearTimeout(D)},[He]);let qt=(0,ye.useCallback)((D,me)=>{k(!1),s(D,me)},[s]),Tn=(0,ye.useCallback)(()=>{b(!1),et(!1),U(!1),k(D=>{let me=!D;if(me)for(let Yt of Je){let Ot=Yt.git;Ot&&!Ot.isRepo&&Ot.containsRepos&&qe(Ve(Yt.uri_root),{force:!0})}return me})},[Je,qe]),te=(0,ye.useCallback)(()=>{Q(D=>{let me=!D;return Th(b1,me),me})},[]),Ge=(0,ye.useCallback)(()=>{oe&&m({agentId:n,projectId:t??null,source:oe,repo:a})},[n,t,oe,a,m]),Ke=(0,ye.useCallback)((D,me)=>{oe&&(x({source:oe,...a?{repo:a}:{},path:D.path,staged:me}),w("git-diff"))},[oe,a,x,w]),Ae=(0,ye.useCallback)(async D=>{if(oe){A(!0),V(null);try{let me=await D();return m({agentId:n,projectId:t??null,source:oe,repo:a}),me}catch(me){V(me instanceof Error?me.message:"Git operation failed");return}finally{A(!1)}}},[oe,a,n,t,m]),he=(0,ye.useMemo)(()=>({...t?{projectId:t}:{},...a?{repo:a}:{}}),[t,a]),ut=(0,ye.useCallback)(D=>{D.length!==0&&Ae(()=>G0({agentId:n,...he,source:oe,paths:D}))},[Ae,n,he,oe]),Qt=(0,ye.useCallback)(D=>{D.length!==0&&Ae(()=>z0({agentId:n,...he,source:oe,paths:D}))},[Ae,n,he,oe]),xn=(0,ye.useCallback)(D=>{(async()=>{let me=await Ae(()=>q0({agentId:n,...he,source:oe,paths:D}));me&&me.rescue&&De({message:`Discarded ${D.length} file${D.length===1?"":"s"} \u2014 recoverable`,rescue:me.rescue})})()},[Ae,n,he,oe]),yn=(0,ye.useCallback)(D=>{D.length!==0&&ue({title:"Discard changes",message:`Overwrite the working-tree version of ${D.length} file${D.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{ue(null),xn(D)}})},[xn]),Nr=(0,ye.useCallback)(D=>ut([D.path]),[ut]),Kn=(0,ye.useCallback)(D=>Qt([D.path]),[Qt]),Xn=(0,ye.useCallback)(D=>yn([D.path]),[yn]),Rr=(0,ye.useMemo)(()=>({onStage:Nr}),[Nr]),Yn=(0,ye.useMemo)(()=>({onStage:Nr,onDiscard:Xn}),[Nr,Xn]),Mr=(0,ye.useMemo)(()=>({onUnstage:Kn}),[Kn]),j=(0,ye.useCallback)(D=>Fe?D.code==="??"?Rr:Yn:v1,[Fe,Rr,Yn]),ie=(0,ye.useCallback)(()=>Fe?Mr:v1,[Fe,Mr]),Ue=(0,ye.useCallback)(()=>{let D=K.trim();D&&(async()=>{let me=await Ae(()=>V0({agentId:n,...he,source:oe,message:D,amend:R}));me&&me.ok&&(L(""),z(!1))})()},[K,R,Ae,n,he,oe]),Bt=(0,ye.useCallback)(()=>{k(!1),U(!1),b(D=>{let me=!D;return me&&oe&&g({agentId:n,projectId:t??null,source:oe,repo:a}),me}),et(!1)},[oe,a,n,t,g]),Xt=(0,ye.useCallback)(D=>{b(!1),(async()=>await Ae(()=>Jf({agentId:n,...he,source:oe,ref:D}))&&g({agentId:n,projectId:t??null,source:oe,repo:a}))()},[Ae,n,he,oe,a,g,t]),dn=(0,ye.useCallback)(()=>{let D=Pt.trim();if(!D)return;let me=Ne.trim();b(!1),et(!1),Ye(""),tt(""),(async()=>await Ae(()=>$0({agentId:n,...he,source:oe,name:D,...me?{startPoint:me}:{}}))&&(await Ae(()=>Jf({agentId:n,...he,source:oe,ref:D})),g({agentId:n,projectId:t??null,source:oe,repo:a})))()},[Pt,Ne,Ae,n,he,oe,a,g,t]),Sn=(0,ye.useCallback)(D=>{(async()=>{let me=await Ae(()=>K0({agentId:n,...he,source:oe,name:D}));me&&me.rescue&&De({message:`Deleted branch "${D}" \u2014 recoverable`,rescue:me.rescue}),g({agentId:n,projectId:t??null,source:oe,repo:a})})()},[Ae,n,he,oe,a,g,t]),hr=(0,ye.useCallback)(D=>{b(!1),ue({title:"Delete branch",message:`Delete the local branch "${D.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{ue(null),Sn(D.name)}})},[Sn]),Ua=(0,ye.useCallback)(()=>{if(!He)return;let D=He.rescue;De(null),Ae(()=>X0({agentId:n,...he,source:oe,rescue:D}))},[He,Ae,n,he,oe]),Jr=(0,ye.useCallback)(()=>{U(!1),Ae(()=>Y0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),Ys=(0,ye.useCallback)(()=>{U(!1),Ae(()=>J0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),Hn=(0,ye.useCallback)(()=>{U(!1),Ae(()=>Z0({agentId:n,...he,source:oe}))},[Ae,n,he,oe]),rn=o?.unstaged??[],Jn=o?.staged??[],pr=o?.untracked??[],E=(0,ye.useMemo)(()=>[...rn,...pr].sort((D,me)=>D.path.localeCompare(me.path)),[rn,pr]);if(Je.length===0)return(0,_.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,_.jsx)(Ln,{className:"h-5 w-5 text-white/25"}),(0,_.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,_.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let ne=Fe&&K.trim().length>0&&(st>0||R)&&!I,O=d?(0,_.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:d}):c&&!o?(0,_.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):E.length===0?(0,_.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,_.jsx)(S1,{changes:E,viewMode:f,staged:!1,showCounts:re,onRowClick:Ke,actionsFor:j,busy:I}),Pe=[{id:"changes",title:"Changes",count:E.length,badge:i?(0,_.jsx)(La,{...i.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Fe&&E.length>0?(0,_.jsxs)(_.Fragment,{children:[rn.length>0?(0,_.jsx)(pp,{tone:"discard",onClick:()=>yn(rn.map(D=>D.path)),disabled:I,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,_.jsx)(pp,{tone:"stage",onClick:()=>ut(E.map(D=>D.path)),disabled:I,title:"Stage all",children:"Stage all"})]}):void 0,content:O},...Jn.length>0?[{id:"staged",title:"Staged Changes",count:Jn.length,badge:i?(0,_.jsx)(La,{...i.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Fe?(0,_.jsx)(pp,{tone:"unstage",onClick:()=>Qt(Jn.map(D=>D.path)),disabled:I,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,_.jsx)(S1,{changes:Jn,viewMode:f,staged:!0,showCounts:re,onRowClick:Ke,actionsFor:ie,busy:I})}]:[],{id:"graph",title:"Graph",badge:l?(0,_.jsx)(La,{added:l.added,removed:l.removed,unknown:l.commits-l.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,_.jsx)(f1,{showCounts:re,onOutgoingStat:u,source:oe,repo:a,agentId:n,projectId:t??null,repoName:a?Re?.name??a:Te?.git?.repoName},`${oe}\0${a}`)}];return(0,_.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,_.jsxs)("div",{ref:P,className:"relative px-2 pt-1 pb-1.5",children:[(0,_.jsxs)("div",{className:"flex items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:Tn,disabled:!jt,className:q("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:oe?Le.title:"Select a repository",children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Le.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Le.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Le.name||"Select repository"}),jt?(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,_.jsx)("button",{type:"button",onClick:Ge,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,_.jsx)(Ht,{className:q("h-3.5 w-3.5",c&&"animate-spin")})}),(0,_.jsx)(L1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",scripts:["scripts/git.sh"],label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),C&&jt?(0,_.jsx)(_.Fragment,{children:(0,_.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:Je.map(D=>{let me=Ve(D.uri_root);if(D.git?.isRepo){let Ot=me===oe&&!a,Cn=Ts(me,D.git?.repoName);return(0,_.jsxs)("button",{type:"button",onClick:()=>qt(me,""),className:q("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Ot?"text-white/90":"text-white/65"),children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Cn.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Cn.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Cn.name}),D.git?.branch?(0,_.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:D.git.branch}):null,Ot?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},D.uri_root)}let Yt=de.get(me);return Yt?Yt.length===0?(0,_.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${me}://`}),(0,_.jsx)("span",{className:"truncate",children:"No repositories found."})]},D.uri_root):Yt.map(Ot=>{let Cn=me===oe&&a===Ot.rel,Tr=Ts(me,Ot.name||Ot.rel);return(0,_.jsxs)("button",{type:"button",onClick:()=>qt(me,Ot.rel),className:q("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Cn?"text-white/90":"text-white/65"),children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),Tr.prefix?(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Tr.prefix}):null,(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:Tr.name}),Ot.branch?(0,_.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:Ot.branch}):null,Cn?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${D.uri_root}\0${Ot.rel}`)}):(0,_.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,_.jsx)(ze,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,_.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${me}://`}),(0,_.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},D.uri_root)})})}):null]}),(0,_.jsxs)("div",{ref:N,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,_.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:Bt,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":v,children:[(0,_.jsx)(Ln,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,_.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}),Fe?(0,_.jsx)("button",{type:"button",onClick:()=>{k(!1),b(!1),et(!1),U(D=>!D)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":M,children:Ee?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.ahead} commits ahead of ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,_.jsx)("span",{className:"text-blue-200/90",children:Ee.ahead})]}),(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.behind} commits behind ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,_.jsx)("span",{className:"text-white/70",children:Ee.behind})]})]}):(0,_.jsx)(hl,{className:"h-3 w-3 text-white/40"})}):Ee?(0,_.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${Ee.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.ahead} commits ahead of ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,_.jsx)("span",{className:"text-blue-200/90",children:Ee.ahead})]}),(0,_.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ee.behind} commits behind ${Ee.upstream}`,children:[(0,_.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,_.jsx)("span",{className:"text-white/70",children:Ee.behind})]})]}):null,Fe?(0,_.jsxs)("button",{type:"button",onClick:te,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:J?"Hide the commit box":"Show the commit box","aria-expanded":J,children:[(0,_.jsx)("span",{children:"Commit"}),st>0?(0,_.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:st}):null,J?(0,_.jsx)(ja,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,_.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,_.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,_.jsx)("button",{type:"button",onClick:()=>h("list"),className:q("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":f==="list",children:(0,_.jsx)(to,{className:"h-3 w-3"})}),(0,_.jsx)("button",{type:"button",onClick:()=>h("tree"),className:q("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":f==="tree",children:(0,_.jsx)(Cl,{className:"h-3 w-3"})})]}),(0,_.jsx)("button",{type:"button",onClick:ee,className:q("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",re?"text-white/85":"text-white/35 hover:text-white/60"),title:re?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":re,children:(0,_.jsx)(Bl,{className:"h-3 w-3"})}),v?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,_.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),p.length===0?(0,_.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):p.map(D=>(0,_.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,_.jsxs)("button",{type:"button",onClick:()=>!D.current&&Xt(D.name),disabled:D.current||I,className:q("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",D.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:D.current?`${D.name} (current)`:`Switch to ${D.name}`,children:[(0,_.jsx)(Ln,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,_.jsx)("span",{className:"min-w-0 flex-1 truncate",children:D.name}),D.current?(0,_.jsx)(Dn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),Fe&&!D.current?(0,_.jsx)("button",{type:"button",onClick:()=>hr(D),disabled:I,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${D.name}`,"aria-label":`Delete branch ${D.name}`,children:(0,_.jsx)(It,{className:"h-3 w-3"})}):null]},D.name)),Fe?(0,_.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:je?(0,_.jsxs)("div",{className:"px-2 py-1.5",children:[(0,_.jsx)("input",{value:Pt,onChange:D=>Ye(D.target.value),onKeyDown:D=>{D.key==="Enter"&&dn()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,_.jsx)("input",{value:Ne,onChange:D=>tt(D.target.value),onKeyDown:D=>{D.key==="Enter"&&dn()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,_.jsxs)("div",{className:"flex items-center gap-1",children:[(0,_.jsxs)("button",{type:"button",onClick:dn,disabled:I||Pt.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,_.jsx)(Fn,{className:"h-3 w-3"})," Create & switch"]}),(0,_.jsx)("button",{type:"button",onClick:()=>{et(!1),Ye(""),tt("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,_.jsxs)("button",{type:"button",onClick:()=>et(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,_.jsx)(Fn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,_.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,M?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,_.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),Lt?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)("button",{type:"button",onClick:Ys,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,_.jsx)(fl,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),Ee&&Ee.behind>0?(0,_.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",Ee.behind]}):null]}),(0,_.jsxs)("button",{type:"button",onClick:Hn,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,_.jsx)(pl,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),Ee&&Ee.ahead>0?(0,_.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",Ee.ahead]}):null]}),(0,_.jsxs)("button",{type:"button",onClick:Jr,disabled:I,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,_.jsx)(Ht,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,_.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,_.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,_.jsx)(no,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,_.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,_.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),He?(0,_.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,_.jsx)(dt,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,_.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,_.jsx)("div",{className:"text-[11px] text-amber-100/85",children:He.message}),(0,_.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:He.rescue.ref,children:["rescue: ",He.rescue.ref]})]}),(0,_.jsx)("button",{type:"button",onClick:Ua,disabled:I,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,_.jsx)("button",{type:"button",onClick:()=>De(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,_.jsx)(Ut,{className:"h-3 w-3"})})]}):null,G?(0,_.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,_.jsx)(dt,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,_.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:G}),(0,_.jsx)("button",{type:"button",onClick:()=>V(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,_.jsx)(Ut,{className:"h-3 w-3"})})]}):null,Fe&&J?(0,_.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,_.jsx)("textarea",{value:K,onChange:D=>L(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&!D.nativeEvent.isComposing&&ne&&(D.preventDefault(),Ue())},placeholder:st>0?`Commit message (${st} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,_.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,_.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,_.jsx)("input",{type:"checkbox",checked:R,onChange:D=>z(D.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,_.jsxs)("button",{type:"button",onClick:Ue,disabled:!ne,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:R?"Amend the last commit":"Commit the staged changes",children:[I?(0,_.jsx)(ze,{className:"h-3 w-3 animate-spin"}):(0,_.jsx)(Dn,{className:"h-3 w-3"}),R?"Amend":"Commit"]})]})]}):null,(0,_.jsx)(y1,{storageKey:JR,sections:Pe}),ce&&typeof document<"u"?(0,C1.createPortal)((0,_.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,_.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>ue(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,_.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,_.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,_.jsx)(dt,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,_.jsx)("span",{className:"text-sm font-semibold text-white/90",children:ce.title})]}),(0,_.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:ce.message}),(0,_.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,_.jsx)("button",{type:"button",onClick:()=>ue(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,_.jsxs)("button",{type:"button",onClick:ce.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,_.jsx)(It,{className:"h-3 w-3"}),ce.confirmLabel]})]})]})]}),document.body):null]})}var St=W(le(),1),P1={},N1="brain://",tM=32,nM=28,rM=114;function aM(n){return n==="header"?tM:n==="empty"?rM:nM}function sM(n){return n!=="node"}function R1(n,e){return n.type===e.type?n.name.localeCompare(e.name):n.type==="folder"?-1:1}function oM(n){let e=new Map,t=new Set;for(let a of n)t.add(a.uri);for(let a of n){let s=a.parentUri??ot(a.uri);if(!s||a.uri===s)continue;let o=e.get(s);o?o.push(a):e.set(s,[a])}for(let a of e.values())a.sort(R1);let r=new Map;for(let a of n){let s=rr(a.uri);if(!s||a.uri===s)continue;let o=a.parentUri??ot(a.uri);if(!(!o||o===s||!t.has(o)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(R1);return{childrenByParent:e,rootsBySource:r}}function iM(n,e,t){let r=[],a=(o,i)=>{r.push({node:o,depth:i});let l=o.storeKey||Wa(o);if(o.type==="folder"&&t.has(l)){let u=n.childrenByParent.get(o.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],i+1)}},s=n.rootsBySource.get(e);if(s)for(let o=0;o<s.length;o++)a(s[o],0);return r}function mp(n){let{agentId:e,sidebarView:t="tree"}=n,r=hn(),a=B(E=>E.files),s=B(E=>E.folderBadges),o=B(E=>E.expandedFolders),i=B(E=>E.activeFile),l=B(E=>E.toggleFolder),u=B(E=>E.openFile),c=B(E=>E.activeProjectId),d=B(E=>E.setActiveFolderPath),f=B(E=>E.activeFolderPath),h=B(E=>E.uploadMany),p=B(E=>E.moveFileToFolder),m=B(E=>E.uploading),g=B(E=>E.sources),x=B(E=>E.sourcesLoading),w=B(E=>E.hydrationState),y=B(E=>E.dirtySources),C=B(E=>E.organizeError),k=B(E=>E.clearOrganizeError),v=B(E=>E.snapshotError),b=B(E=>E.clearSnapshotError),P=B(E=>E.loadList),N=B(E=>E.pendingReviewPaths),M=B(E=>E.renameNode),U=B(E=>E.deleteNodes),I=B(E=>E.createNode),A=B(E=>E.pasteNodes),[G,V]=(0,_e.useState)(null),[K,L]=(0,_e.useState)({}),[R,z]=(0,_e.useState)(()=>new Set),[J,Q]=(0,_e.useState)(null),[re,pe]=(0,_e.useState)(null),[ee,ce]=(0,_e.useState)(null),[ue,He]=(0,_e.useState)(null),[De,je]=(0,_e.useState)(null),[et,Dt]=(0,_e.useState)(null),[at,vt]=(0,_e.useState)(!1),[Pt,Ye]=(0,_e.useState)(!1),Ne=B(E=>E.setPendingSourceSuggestion),tt=B(E=>E.setWorkspacePanelOpen);(0,_e.useEffect)(()=>{if(!i)return;let E=`${Ve(i)}://`;L(ne=>ne[E]?ne:{...ne,[E]:!0})},[i]);let Je=r.useFileMarks(e),Ft=r.useAgents(),Mt=r.usePackageIconBySlug?.()??P1,Te=(0,_e.useMemo)(()=>Je||P1,[Je]),oe=(0,_e.useMemo)(()=>Ns(Ft),[Ft]),jt=(0,_e.useMemo)(()=>oe.byId.get(e)??null,[oe,e]),Kt=(0,_e.useMemo)(()=>{let E={};for(let ne of N){let O=ga(ne);for(let Pe of O)E[Pe]=(E[Pe]||0)+1}return E},[N]),de=g.length>0,fe=(0,_e.useMemo)(()=>Object.values(a),[a]),qe=(0,_e.useMemo)(()=>oM(fe),[fe]),Re=(0,_e.useMemo)(()=>{let E={uri_root:N1,source_kind:"brain",writable:!0};return de?g.length>0?g:[E]:[E]},[de,g]),Fe=t==="search",Lt=(0,_e.useMemo)(()=>{let E=f?rr(f):null;return E&&Re.some(O=>O.uri_root===E)?E:Re.find(O=>O.source_kind!=="brain")?.uri_root??Re[0]?.uri_root??N1},[f,Re]),st=(0,_e.useMemo)(()=>{if(Fe)return[];let E=[];for(let ne of Re){let O=K[ne.uri_root]??!1;if(E.push({kind:"header",key:`h:${ne.uri_root}`,info:ne,expanded:O}),!O)continue;let Pe=iM(qe,ne.uri_root,o);if(Pe.length===0)E.push({kind:"empty",key:`e:${ne.uri_root}`,sourceRoot:ne.uri_root});else for(let D of Pe)E.push({kind:"node",key:`n:${D.node.uri}`,node:D.node,depth:D.depth})}if(ee){let ne=ee.parentUri,O=-1,Pe=0;if(ne.endsWith("://"))O=E.findIndex(D=>D.kind==="header"&&D.info.uri_root===ne),Pe=0;else{let D=E.findIndex(me=>me.kind==="node"&&me.node.uri===ne);D>=0&&(O=D,Pe=E[D].depth+1)}O>=0&&E.splice(O+1,0,{kind:"creating",key:"creating-row",parentUri:ne,createKind:ee.kind,depth:Pe})}return E},[qe,o,Re,K,Fe,ee]),Le=(0,_e.useMemo)(()=>st.filter(E=>E.kind==="node").map(E=>E.node.uri),[st]),Ee=(0,_e.useCallback)(({node:E,additive:ne,range:O})=>{z(Pe=>{if(O&&J){let D=Le.indexOf(J),me=Le.indexOf(E.uri);if(D>=0&&me>=0){let[Yt,Ot]=D<=me?[D,me]:[me,D];return new Set(Le.slice(Yt,Ot+1))}}if(ne){let D=new Set(Pe);return D.has(E.uri)?D.delete(E.uri):D.add(E.uri),D}return new Set([E.uri])}),O||Q(E.uri)},[Le,J]),Et=(0,_e.useCallback)(({node:E,x:ne,y:O})=>{z(Pe=>Pe.has(E.uri)&&Pe.size>1?Pe:new Set([E.uri])),Q(E.uri),je({kind:"node",node:E,x:ne,y:O})},[]),qt=(0,_e.useCallback)((E,ne)=>{ne.preventDefault(),ne.stopPropagation(),L(O=>O[E]?O:{...O,[E]:!0}),je({kind:"source",sourceRoot:E,x:ne.clientX,y:ne.clientY})},[]),Tn=(0,_e.useCallback)(E=>{E.target.closest('button, input, textarea, [role="menu"]')||qt(Lt,E)},[Lt,qt]),te=(0,_e.useMemo)(()=>De?.kind!=="node"?[]:(R.has(De.node.uri)&&R.size>0?[...R]:[De.node.uri]).map(ne=>a[ne]).filter(Boolean),[De,R,a]),Ce=(0,_e.useMemo)(()=>oi({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[Ge,Ke]=(0,_e.useState)(null),Ae=(0,_e.useMemo)(()=>{if(De?.kind==="source")return{"new-file":!0,"new-folder":Ve(De.sourceRoot)!=="brain"};let E=te.length===1?te[0]:null,ne=E??te[0],O=ne?ne.type==="folder"?ne.uri:ot(ne.uri):null;return{"copy-path":!!E,"copy-relative-path":!!E,reembed:!!E&&Ce&&Ve(E.uri)!=="brain",rename:!!E,delete:te.length>0,"new-file":!!E,"new-folder":!!E&&Ve(E.uri)!=="brain",cut:te.length>0,copy:te.length>0,paste:!!ue&&ue.uris.length>0&&!!O}},[De,te,ue,Ce]),he=(0,_e.useCallback)(E=>{if(De?.kind==="source"){(E==="new-file"||E==="new-folder")&&ce({parentUri:De.sourceRoot,kind:E==="new-file"?"file":"folder"});return}let ne=te,O=ne.length===1?ne[0]:null;if(E==="copy-path"&&O)navigator.clipboard?.writeText(O.uri);else if(E==="copy-relative-path"&&O)navigator.clipboard?.writeText(O.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(E==="reembed"&&O){let Pe=Ve(O.uri);Pe&&Ke({source:Pe,...O.type==="folder"?{folder:O.uri}:{uri:O.uri},label:O.type==="folder"?`${O.name}/`:O.name})}else if(E==="rename"&&O)pe(O.uri);else if(E==="delete")ne.length&&Dt({targets:ne.map(Pe=>({uri:Pe.uri,id:Pe.id,name:Pe.name}))});else if(E==="cut"||E==="copy")ne.length&&He({op:E,uris:ne.map(Pe=>Pe.uri)});else if(E==="paste"){let Pe=O??ne[0];if(Pe&&ue){let D=Pe.type==="folder"?Pe.uri:ot(Pe.uri);D&&(A({agentId:e,projectId:c??null,targetFolderUri:D,op:ue.op,uris:ue.uris}),ue.op==="cut"&&He(null))}}else if(E==="new-file"||E==="new-folder"){let Pe=E==="new-file"?"file":"folder",D=O??ne[0];if(!D)return;let me=D.type==="folder"?D.uri:ot(D.uri);if(!me)return;!me.endsWith("://")&&!o.has(me)&&(l(me),B.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:me})),ce({parentUri:me,kind:Pe})}},[De,te,o,l,e,c,ue,A]),ut=(0,_e.useCallback)(async E=>{let ne=ee;if(ce(null),!ne)return;let O=(E??"").trim();O&&await I({agentId:e,projectId:c??null,parentUri:ne.parentUri,name:O,kind:ne.kind})},[ee,I,e,c]),Qt=(0,_e.useCallback)(()=>ce(null),[]),xn=(0,_e.useCallback)(async({node:E,newName:ne})=>{pe(null);let O=(ne??"").trim();!O||O===E.name||await M({agentId:e,projectId:c??null,uri:E.uri,id:E.id,newName:O})},[M,e,c]),yn=(0,_e.useCallback)(()=>pe(null),[]),Nr=(0,_e.useCallback)(async()=>{if(et){vt(!0);try{await U({agentId:e,projectId:c??null,targets:et.targets.map(E=>({uri:E.uri,id:E.id}))}),z(new Set)}finally{vt(!1),Dt(null)}}},[et,U,e,c]),Kn=(0,_e.useCallback)(E=>{if(!re)if(E.key==="F2"){let ne=R.size===1?[...R][0]:null;ne&&a[ne]&&(E.preventDefault(),pe(ne))}else if(E.key==="Delete"||E.key==="Backspace"){let ne=[...R].map(O=>a[O]).filter(O=>!!O);ne.length&&(E.preventDefault(),Dt({targets:ne.map(O=>({uri:O.uri,id:O.id,name:O.name}))}))}else E.key==="Escape"&&z(new Set)},[re,R,a]),Xn=(0,_e.useCallback)(async E=>{let ne=o.has(E.key);d(E.key),l(E.key),!ne&&await B.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:E.key})},[e,o,c,d,l]),Rr=(0,_e.useCallback)(E=>{E.uri&&d(ot(E.uri)),u(E)},[d,u]),Yn=(0,_e.useCallback)(E=>{r.clearFileMark(E)},[r]),Mr=(0,_e.useCallback)(E=>{L(ne=>({...ne,[E]:!ne[E]}))},[]),j=(0,_e.useCallback)(async E=>{if(!e)return;let ne=B.getState();if(L(O=>O[E]?O:{...O,[E]:!0}),ne.loadedFolders?.[E]){let O=Ve(E);O&&await ne.reconcileSourceFolders({agentId:e,projectId:c,source:O});return}await ne.ensureFolderLoaded({agentId:e,projectId:c,uri:E,force:!0})},[e,c]);(0,_e.useEffect)(()=>{if(!e)return;let E=B.getState(),ne=[];for(let O of Re)K[O.uri_root]&&ne.push(O.uri_root);for(let O of o)ne.push(O);for(let O of ne){if(E.loadedFolders?.[O])continue;let Pe=E.hydrationState?.[O];Pe&&Pe!=="idle"||E.ensureFolderLoaded({agentId:e,projectId:c,uri:O})}},[e,c,Re,K,o]);let ie=(0,_e.useCallback)(async({fromUri:E,id:ne,toFolderUri:O})=>{await p({agentId:e,projectId:c??null,fromUri:E,toFolderUri:O,id:ne})},[e,c,p]),Ue=(0,_e.useMemo)(()=>Re.every(E=>!K[E.uri_root]),[Re,K]),Bt=(0,_e.useMemo)(()=>oi({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),Xt=jb({agentId:e,projectId:c??void 0,enabled:Bt&&Ue}),dn=Ue&&Bt&&Xt.length>0,Sn=(0,_e.useCallback)(E=>{Ne(E),tt("sources",!0)},[Ne,tt]),hr=(0,_e.useCallback)(()=>Ye(E=>!E),[]),Ua=(0,_e.useRef)(null),Jr=(0,_e.useRef)(st);Jr.current=st;let Ys=(0,_e.useCallback)(E=>aM(Jr.current[E]?.kind??"node"),[]),Hn=(0,_e.useCallback)(E=>Jr.current[E]?.key??E,[]),rn=ii({count:st.length,getScrollElement:()=>Ua.current,estimateSize:Ys,overscan:8,getItemKey:Hn});if(t==="git")return(0,St.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,St.jsx)(A1,{agentId:e})});if(x&&!de&&!Fe)return(0,St.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let Jn=v&&!Fe?(0,St.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,St.jsx)("span",{className:"min-w-0 flex-1 break-words",children:v}),(0,St.jsx)("button",{type:"button",onClick:()=>{e&&P({agentId:e,projectId:c??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,St.jsx)("button",{type:"button",onClick:b,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!fe.length&&!Fe&&!de)return Jn??(0,St.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let pr=(E,ne)=>{let O=E.type==="folder",Pe=E.storeKey||Wa(E);return(0,St.jsx)(aw,{node:E,depth:ne,agentId:e,projectId:c,isActive:!O&&i===Pe,isExpanded:O&&o.has(Pe),badgeCount:O?s[Pe]:void 0,isDrop:G===Pe,isSelectedFolder:O&&f===Pe,mark:Te[E.uri],agentIndex:oe,fallbackAgent:jt,uploading:m,packageIconBySlug:Mt,onToggleFolder:Xn,onOpenFile:Rr,onClearFileMark:Yn,onSetDropTarget:V,onUploadMany:h,onMoveFileToFolder:ie,pendingReviewCount:O?Kt[Pe]:void 0,isSelected:R.has(E.uri),isCut:ue?.op==="cut"&&ue.uris.includes(E.uri),renaming:re===E.uri,onNodeClick:Ee,onNodeContextMenu:Et,onRenameCommit:xn,onRenameCancel:yn})};return(0,St.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,St.jsxs)("div",{ref:Ua,tabIndex:0,onKeyDown:Kn,onContextMenu:Tn,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[Jn,C&&!Fe?(0,St.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,St.jsx)("span",{className:"min-w-0 flex-1 break-words",children:C}),(0,St.jsx)("button",{type:"button",onClick:k,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,Fe?(0,St.jsx)(pw,{agentId:e}):null,Fe?null:(0,St.jsx)("div",{style:{height:rn.getTotalSize(),width:"100%",position:"relative"},children:rn.getVirtualItems().map(E=>{let ne=st[E.index];if(!ne)return null;let O=sM(ne.kind);return(0,St.jsx)("div",{"data-index":E.index,ref:O?rn.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${E.start}px)`},children:ne.kind==="header"?(0,St.jsx)(hw,{info:ne.info,expanded:ne.expanded,onToggle:Mr,onContextMenu:qt,onRefresh:j,hydration:w[ne.info.uri_root]??"idle",dirty:!!y[Ve(ne.info.uri_root)],hideChevron:!0,compact:!0}):ne.kind==="empty"?(0,St.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:Pe=>qt(ne.sourceRoot,Pe),children:[(0,St.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",Ve(ne.sourceRoot)]}),(0,St.jsx)(M1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):ne.kind==="creating"?(0,St.jsx)(lM,{kind:ne.createKind,depth:ne.depth,onCommit:ut,onCancel:Qt}):pr(ne.node,ne.depth)},E.key)})}),De?(0,St.jsx)(ow,{x:De.x,y:De.y,variant:De.kind==="source"?"source":"node",enabled:Ae,onAction:he,onClose:()=>je(null)}):null,Ge?(0,St.jsx)(kc,{agentId:e,...c?{projectId:c}:{},target:Ge,onClose:()=>Ke(null)}):null,et?(0,St.jsx)(uw,{names:et.targets.map(E=>E.name),busy:at,onCancel:()=>{at||Dt(null)},onConfirm:Nr}):null]}),dn&&!Fe?(0,St.jsx)(Yb,{suggestions:Xt,expanded:Pt,onToggleExpanded:hr,onPick:Sn,overlay:Pt}):null]})}function lM({kind:n,depth:e,onCommit:t,onCancel:r}){let a=(0,_e.useRef)(!1),s=n==="folder"?wr:ks;return(0,St.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,St.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,St.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,St.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:n==="folder"?"Folder name":"File name",onClick:o=>o.stopPropagation(),onMouseDown:o=>o.stopPropagation(),onKeyDown:o=>{o.stopPropagation(),o.key==="Enter"?a.current||(a.current=!0,t(o.currentTarget.value)):o.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:o=>{if(a.current)return;a.current=!0;let i=o.currentTarget.value.trim();i?t(i):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var bt=W($e(),1);function T1(n){if(!n)return{lines:new Map,deletedBefore:new Set};let e=new Map,t=new Set,r=0,a=!1,s=0,o=0,i=()=>{s>0&&o===0&&t.add(r),s=0,o=0};for(let l of n.split(`
|
|
32
|
-
`)){if(l.startsWith("@@")){i();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),o++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(i(),l.startsWith(" ")&&r++))}return i(),{lines:e,deletedBefore:t}}function sd(n){return n.lines.size===0&&n.deletedBefore.size===0}var zn=W($e(),1),F1=W(Ya(),1);var ru=W(le(),1);function gp({sourceType:n,className:e}){return n==="blob"?(0,ru.jsx)("span",{title:"Blob + Vector",children:(0,ru.jsx)(Gn,{className:q("w-3 h-3",e)})}):(0,ru.jsx)("span",{title:"Vector only",children:(0,ru.jsx)(br,{className:q("w-3 h-3",e)})})}var Gr=W(le(),1);function xp({node:n,active:e,mark:t,isDirty:r,hasPendingReview:a,preview:s,pinned:o,onTogglePin:i}){let l=B(h=>h.setActiveFile),u=B(h=>h.closeFile),c=B(h=>h.activeAgentId),d=hn(),f=n.status==="deleted";return(0,Gr.jsxs)("div",{className:q("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(n.storeKey||n.path),c&&t&&d.clearFileMark({agentId:c,path:n.path})},onDoubleClick:()=>i?.(),title:n.path,children:[(0,Gr.jsx)(gp,{sourceType:n.sourceType,className:q("shrink-0",n.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Gr.jsxs)("span",{className:q("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[n.name,r?(0,Gr.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Gr.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):t?(0,Gr.jsx)("span",{className:q("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",t==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:t==="new"?"NEW":"MOD"}):null,o?(0,Gr.jsx)("button",{onClick:h=>{h.stopPropagation(),i?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Gr.jsx)(so,{className:"w-3 h-3 fill-current"})}):(0,Gr.jsx)("button",{onClick:h=>{h.stopPropagation(),u(n.storeKey||n.path)},className:q("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Gr.jsx)(Ut,{className:"w-3 h-3"})})]})}var An=W(le(),1),od="data-tab-scroller",D1="data-tab-active";function uM(n,e){return e.left<n.left?e.left-n.left:e.right>n.right?Math.min(e.right-n.right,e.left-n.left):0}function cM(n,e){return e.scrollWidth<=e.clientWidth||Math.abs(n.deltaX)>=Math.abs(n.deltaY)?0:n.deltaY}function E1(){let n=B(y=>y.openFiles),e=B(y=>y.activeFile),t=B(y=>y.files),r=B(y=>y.tabMeta),a=B(y=>y.fileContentByPath),s=B(y=>y.fileBaseContentByPath),o=B(y=>y.filePrevByPath),i=B(y=>y.activeAgentId),l=B(y=>y.reorderOpenFiles),u=B(y=>y.toggleTabPin),d=hn().useFileMarks(i??void 0)||{},[f,h]=(0,zn.useState)(null),[p,m]=(0,zn.useState)(null),g=(0,zn.useRef)(null),x=n.length>0,w=(0,zn.useCallback)(()=>{let y=g.current,C=y?.closest(`[${od}]`),k=y?.querySelector(`[${D1}="true"]`);if(!C||!k)return;let v=uM(C.getBoundingClientRect(),k.getBoundingClientRect());v!==0&&(C.scrollLeft+=v)},[]);return(0,zn.useLayoutEffect)(()=>{w()},[e,n,w]),(0,zn.useEffect)(()=>{let y=g.current?.closest(`[${od}]`);if(!y)return;let C=v=>{let b=cM(v,y);b!==0&&(v.preventDefault(),y.scrollLeft+=b)};y.addEventListener("wheel",C,{passive:!1});let k=typeof ResizeObserver<"u"?new ResizeObserver(()=>{y.clientWidth>0&&w()}):null;return k?.observe(y),()=>{y.removeEventListener("wheel",C),k?.disconnect()}},[x,w]),n.length===0?null:(0,An.jsx)("div",{ref:g,className:"flex items-center",children:n.map(y=>{let C=t[y],k=r[y],v=C?.uri??y,b=C?.name??k?.name??yt(y),P=C?.status??k?.status,N=a[y]??"",M=s[y],U=typeof M=="string"&&M!==N,A=!!o[y]&&P==="pending_review";return(0,An.jsx)("div",{draggable:!0,[D1]:e===y?"true":void 0,onDragStart:G=>{h(y),G.dataTransfer.effectAllowed="move";try{G.dataTransfer.setData("text/plain",y)}catch{}},onDragOver:G=>{G.preventDefault(),G.dataTransfer.dropEffect="move",p!==y&&m(y)},onDrop:G=>{G.preventDefault(),f&&f!==y&&l(f,y),h(null),m(null)},onDragEnd:()=>{h(null),m(null)},className:q("shrink-0 rounded-lg",p===y&&f&&f!==y?"ring-1 ring-violet-400/50":"",f===y?"opacity-50":""),children:(0,An.jsx)(xp,{node:{storeKey:C?.storeKey??y,path:v,name:b,status:P,sourceAgentId:C?.sourceAgentId??k?.sourceAgentId,sourceType:C?.sourceType},active:e===y,mark:d[v]?.kind,isDirty:U,hasPendingReview:A,preview:!!k?.preview,pinned:!!k?.pinned,onTogglePin:()=>u(y)})},y)})})}function B1(){let n=B(p=>p.openFiles),e=B(p=>p.activeFile),t=B(p=>p.closeAllFiles),r=B(p=>p.closeSavedFiles),a=B(p=>p.closeOtherFiles),s=B(p=>p.previewEditorsEnabled),o=B(p=>p.setPreviewEditorsEnabled),[i,l]=(0,zn.useState)(!1),[u,c]=(0,zn.useState)(null),d=(0,zn.useRef)(null),f=(0,zn.useRef)(null);return(0,zn.useEffect)(()=>{if(!i)return;let p=x=>{let w=x.target;d.current?.contains(w)||f.current?.contains(w)||l(!1)},m=x=>{x.key==="Escape"&&l(!1)},g=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",m),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",m),window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[i]),n.length===0?null:(0,An.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,An.jsx)("button",{ref:d,type:"button",onClick:()=>{if(i){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:q("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",i?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":i,children:(0,An.jsx)(xs,{className:"w-4 h-4"})}),i&&u?(0,F1.createPortal)((0,An.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,An.jsx)(yp,{label:"Close All",onClick:()=>{t(),l(!1)}}),(0,An.jsx)(yp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,An.jsx)(yp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,An.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,An.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>o(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,An.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,An.jsx)(Dn,{className:"w-3.5 h-3.5"}):null}),(0,An.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function yp({label:n,onClick:e,disabled:t}){return(0,An.jsx)("button",{type:"button",role:"menuitem",disabled:t,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:n})}var wo=W($e(),1);var pt=W(le(),1);function dM(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function bp(n){if(!n)return null;try{return new Date(n).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return n}}function wp({node:n,className:e,hideVersionDiff:t=!1}){let{tags:r,category:a,createdAt:s,updatedAt:o,metadata:i,sourceAgentId:l,version:u,readSource:c}=n,d=n.uri?Ve(n.uri):void 0,h=hn().useAgents(),p=(0,wo.useMemo)(()=>Ns(h),[h]),m=(0,wo.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),g=m?.name||m?.slug,x=ui(m?.id,p);if(!vp(n))return null;let y=i&&typeof i.mimeType=="string"?i.mimeType:void 0,C=i&&typeof i.size=="number"?i.size:void 0,k=jl(n),v=u?.sync,b=fo(u?.changedAt),P=Ch(u?.changedAt),N=Ch(v?.syncedAt);return(0,pt.jsxs)("div",{className:q("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",k.highlightTone,"border-white/[0.07]",k.tone),children:[(0,pt.jsx)(k.icon,{className:q("w-3 h-3",k.iconTone)}),k.label]}),d?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,pt.jsx)($a,{className:"w-3 h-3 text-white/35"}),(0,pt.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,n.os_uri?(0,pt.jsx)(fM,{value:n.os_uri}):null,g?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${g}`,children:[(0,pt.jsx)(ml,{className:"w-3 h-3 text-white/35"}),(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,pt.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),g]})]}):null,a?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,pt.jsx)(Br,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,pt.jsx)(_l,{className:"w-3 h-3 text-white/35"}),r.map(M=>(0,pt.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:M},M))]}):null,y?(0,pt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:y}):null,C?(0,pt.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:dM(C)}):null,s?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,pt.jsx)(ya,{className:"w-3 h-3"}),bp(s)]}):null,o&&o!==s?(0,pt.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,pt.jsx)(Ht,{className:"w-2.5 h-2.5"}),bp(o)]}):null,u?.changedAt?(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",b.pillClassName),children:[(0,pt.jsx)(ya,{className:q("w-3 h-3",b.iconClassName)}),"changed ",P?`${P} ago`:bp(u.changedAt)]}):null,!t&&u?.diff?(0,pt.jsxs)("span",{className:q("inline-flex items-center gap-1 rounded-full border px-2 py-1",b.pillClassName),children:[(0,pt.jsx)(ar,{className:q("w-3 h-3",b.iconClassName)}),(0,pt.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,pt.jsx)("span",{className:"text-white/25",children:"/"}),(0,pt.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,N?(0,pt.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",N," ago"]}):null]})}function fM({value:n}){let[e,t]=(0,wo.useState)(!1),r=(0,wo.useCallback)(()=>{navigator.clipboard.writeText(n).then(()=>{t(!0),setTimeout(()=>t(!1),1500)}).catch(()=>{})},[n]),a=n.length>60?"..."+n.slice(-57):n;return(0,pt.jsxs)("button",{type:"button",onClick:r,title:n,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,pt.jsx)(ra,{className:"w-3 h-3 text-emerald-300/80"}):(0,pt.jsx)(Gn,{className:"w-3 h-3 text-white/35"}),(0,pt.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function vp(n){let{tags:e,category:t,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:o,version:i}=n,l=n.uri?Ve(n.uri):void 0;return!!o||!!e?.length||!!t||!!l||!!n.os_uri||!!r||!!a||!!i||!!(s&&Object.keys(s).length>0)}var pf=W($e(),1);var Sp=[],U1=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?U1:Sp).push(t=t+n[e])})();function hM(n){if(n<768)return!1;for(let e=0,t=Sp.length;;){let r=e+t>>1;if(n<Sp[r])t=r;else if(n>=U1[r])e=r+1;else return!0;if(e==t)return!1}}function O1(n){return n>=127462&&n<=127487}var _1=8205;function G1(n,e,t=!0,r=!0){return(t?z1:pM)(n,e,r)}function z1(n,e,t){if(e==n.length)return e;e&&W1(n.charCodeAt(e))&&j1(n.charCodeAt(e-1))&&e--;let r=kp(n,e);for(e+=H1(r);e<n.length;){let a=kp(n,e);if(r==_1||a==_1||t&&hM(a))e+=H1(a),r=a;else if(O1(a)){let s=0,o=e-2;for(;o>=0&&O1(kp(n,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function pM(n,e,t){for(;e>1;){let r=z1(n,e-2,t);if(r<e)return r;e--}return 0}function kp(n,e){let t=n.charCodeAt(e);if(!j1(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return W1(r)?(t-55296<<10)+(r-56320)+65536:t}function W1(n){return n>=56320&&n<57344}function j1(n){return n>=55296&&n<56320}function H1(n){return n<65536?1:2}var ct=class n{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,r){[e,t]=Ii(this,e,t);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(t,this.length,a,1),Si.from(a,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Ii(this,e,t);let r=[];return this.decompose(e,t,r,0),Si.from(r,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new Co(this),s=new Co(e);for(let o=t,i=t;;){if(a.next(o),s.next(o),o=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(i+=a.value.length,a.done||i>=r)return!0}}iter(e=1){return new Co(this,e)}iterRange(e,t=this.length){return new dd(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new fd(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?n.empty:e.length<=32?new Cr(e):Si.from(Cr.split(e,[]))}},Cr=class n extends ct{constructor(e,t=mM(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,a){for(let s=0;;s++){let o=this.text[s],i=a+o.length;if((t?r:i)>=e)return new Lp(a,i,r,o);a=i+1,r++}}decompose(e,t,r,a){let s=e<=0&&t>=this.length?this:new n(q1(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(a&1){let o=r.pop(),i=cd(s.text,o.text.slice(),0,s.length);if(i.length<=32)r.push(new n(i,o.length+s.length));else{let l=i.length>>1;r.push(new n(i.slice(0,l)),new n(i.slice(l)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof n))return super.replace(e,t,r);[e,t]=Ii(this,e,t);let a=cd(this.text,cd(r.text,q1(this.text,0,e)),t),s=this.length+r.length-(t-e);return a.length<=32?new n(a,s):Si.from(n.split(a,[]),s)}sliceString(e,t=this.length,r=`
|
|
33
|
-
`){[e,t]=
|
|
34
|
-
`){[e,t]=
|
|
35
|
-
`,this;e--}else if(a instanceof Cr){let l=a.text[o+(t<0?-1:0)];if(this.offsets[r]+=t,l.length>Math.max(0,e))return this.value=e==0?l:t>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[o+(t<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(t>0?1:(l instanceof Cr?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},dd=class{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Co(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*t,this.value=a.length<=r?a:t<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},fd=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:a}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(ct.prototype[Symbol.iterator]=function(){return this.iter()},Co.prototype[Symbol.iterator]=dd.prototype[Symbol.iterator]=fd.prototype[Symbol.iterator]=function(){return this});var Lp=class{constructor(e,t,r,a){this.from=e,this.to=t,this.number=r,this.text=a}get length(){return this.to-this.from}};function Ii(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Nn(n,e,t=!0,r=!0){return G1(n,e,t,r)}function gM(n){return n>=56320&&n<57344}function xM(n){return n>=55296&&n<56320}function Y1(n,e){let t=n.charCodeAt(e);if(!xM(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return gM(r)?(t-55296<<10)+(r-56320)+65536:t}function J1(n){return n<65536?1:2}var Ip=/\r\n?|\n/,ir=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(ir||(ir={})),ts=class n{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,a=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(r,a,s),a+=s):a+=o,r+=s}}iterChangedRanges(e,t=!1){Ap(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];a<0?e.push(r,a):e.push(a,r)}return new n(e)}composeDesc(e){return this.empty?e:e.empty?this:Z1(this,e)}mapDesc(e,t=!1){return e.empty?this:Pp(this,e,t)}mapPos(e,t=-1,r=ir.Simple){let a=0,s=0;for(let o=0;o<this.sections.length;){let i=this.sections[o++],l=this.sections[o++],u=a+i;if(l<0){if(u>e)return s+(e-a);s+=i}else{if(r!=ir.Simple&&u>=e&&(r==ir.TrackDel&&a<e&&u>e||r==ir.TrackBefore&&a<e||r==ir.TrackAfter&&u>e))return null;if(u>e||u==e&&t<0&&!i)return e==a||t<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,t=e){for(let r=0,a=0;r<this.sections.length&&a<=t;){let s=this.sections[r++],o=this.sections[r++],i=a+s;if(o>=0&&a<=t&&i>=e)return a<e&&i>t?"cover":!0;a=i}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new n(e)}static create(e){return new n(e)}},Rn=class n extends ts{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Ap(this,(t,r,a,s,o)=>e=e.replace(a,a+(r-t),o),!1),e}mapDesc(e,t=!1){return Pp(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let a=0,s=0;a<t.length;a+=2){let o=t[a],i=t[a+1];if(i>=0){t[a]=i,t[a+1]=o;let l=a>>1;for(;r.length<l;)r.push(ct.empty);r.push(o?e.slice(s,s+o):ct.empty)}s+=o}return new n(t,r)}compose(e){return this.empty?e:e.empty?this:Z1(this,e,!0)}map(e,t=!1){return e.empty?this:Pp(this,e,t,!0)}iterChanges(e,t=!1){Ap(this,e,t)}get desc(){return ts.create(this.sections)}filter(e){let t=[],r=[],a=[],s=new Lo(this);e:for(let o=0,i=0;;){let l=o==e.length?1e9:e[o++];for(;i<l||i==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-i);Wn(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;Wn(t,c,d),d>0&&Os(r,t,s.text),s.forward(c),i+=c}let u=e[o++];for(;i<u;){if(s.done)break e;let c=Math.min(s.len,u-i);Wn(t,c,-1),Wn(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),i+=c}}return{changes:new n(t,r),filtered:ts.create(a)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],a=this.sections[t+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let a=[],s=[],o=0,i=null;function l(c=!1){if(!c&&!a.length)return;o<t&&Wn(a,t-o,-1);let d=new n(a,s);i=i?i.compose(d.map(i)):d,a=[],s=[],o=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof n){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);l(),i=i?i.compose(c.map(i)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>t)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${t})`);let p=h?typeof h=="string"?ct.of(h.split(r||Ip)):h:ct.empty,m=p.length;if(d==f&&m==0)return;d<o&&l(),d>o&&Wn(a,d-o,-1),Wn(a,f-d,m),Os(s,a,p),o=f}}return u(e),l(!i),i}static empty(e){return new n(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,i)=>i&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<a;)r.push(ct.empty);r[a]=ct.of(s.slice(1)),t.push(s[0],r[a].length)}}}return new n(t,r)}static createSet(e,t){return new n(e,t)}};function Wn(n,e,t,r=!1){if(e==0&&t<=0)return;let a=n.length-2;a>=0&&t<=0&&t==n[a+1]?n[a]+=e:a>=0&&e==0&&n[a]==0?n[a+1]+=t:r?(n[a]+=e,n[a+1]+=t):n.push(e,t)}function Os(n,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<r;)n.push(ct.empty);n.push(t)}}function Ap(n,e,t){let r=n.inserted;for(let a=0,s=0,o=0;o<n.sections.length;){let i=n.sections[o++],l=n.sections[o++];if(l<0)a+=i,s+=i;else{let u=a,c=s,d=ct.empty;for(;u+=i,c+=l,l&&r&&(d=d.append(r[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)i=n.sections[o++],l=n.sections[o++];e(a,u,s,c,d),a=u,s=c}}}function Pp(n,e,t,r=!1){let a=[],s=r?[]:null,o=new Lo(n),i=new Lo(e);for(let l=-1;;){if(o.done&&i.len||i.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&i.ins==-1){let u=Math.min(o.len,i.len);Wn(a,u,-1),o.forward(u),i.forward(u)}else if(i.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(i.len<o.len||i.len==o.len&&!t))){let u=i.len;for(Wn(a,i.ins,-1);u;){let c=Math.min(o.len,u);o.ins>=0&&l<o.i&&o.len<=c&&(Wn(a,0,o.ins),s&&Os(s,a,o.text),l=o.i),o.forward(c),u-=c}i.next()}else if(o.ins>=0){let u=0,c=o.len;for(;c;)if(i.ins==-1){let d=Math.min(c,i.len);u+=d,c-=d,i.forward(d)}else if(i.ins==0&&i.len<c)c-=i.len,i.next();else break;Wn(a,u,l<o.i?o.ins:0),s&&l<o.i&&Os(s,a,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&i.done)return s?Rn.createSet(a,s):ts.create(a);throw new Error("Mismatched change set lengths")}}}function Z1(n,e,t=!1){let r=[],a=t?[]:null,s=new Lo(n),o=new Lo(e);for(let i=!1;;){if(s.done&&o.done)return a?Rn.createSet(r,a):ts.create(r);if(s.ins==0)Wn(r,s.len,0,i),s.next();else if(o.len==0&&!o.done)Wn(r,0,o.ins,i),a&&Os(a,r,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,o.len),u=r.length;if(s.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;Wn(r,l,c,i),a&&c&&Os(a,r,o.text)}else o.ins==-1?(Wn(r,s.off?0:s.len,l,i),a&&Os(a,r,s.textBit(l))):(Wn(r,s.off?0:s.len,o.off?0:o.ins,i),a&&!o.off&&Os(a,r,o.text));i=(s.ins>l||o.ins>=0&&o.len>l)&&(i||r.length>u),s.forward2(l),o.forward(l)}}}}var Lo=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?ct.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?ct.empty:t[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},vo=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,t=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new n(r,a,this.flags,this.goalColumn)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return se.range(e,t,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return se.range(this.anchor,a,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return se.range(e.anchor,e.head)}static create(e,t,r,a){return new n(e,t,r,a)}},se=class n{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:n.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new n([this.main],0)}addRange(e,t=!0){return n.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,n.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new n(e.ranges.map(t=>vo.fromJSON(t)),e.main)}static single(e,t=e){return new n([n.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return n.normalized(e.slice(),t);r=s.to}return new n(e,t)}static cursor(e,t=0,r,a){return vo.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,t,r,a,s){let o=a==null?7:Math.min(6,a);return!s&&e!=t&&(s=t<e?1:-1),s&&(o|=s<0?8:16),t<e?vo.create(t,e,o|32,r):vo.create(e,t,o,r)}static undirectionalRange(e,t){return vo.create(e,t,64,void 0)}static normalized(e,t=0){let r=e[t];e.sort((a,s)=>a.from-s.from),t=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],o=e[a-1];if(s.empty?s.from<=o.to:s.from<o.to){let i=o.from,l=Math.max(s.to,o.to);a<=t&&t--,e.splice(--a,2,s.anchor>s.head?n.range(l,i):n.range(i,l))}}return new n(e,t)}};function Q1(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var _p=0,Me=class n{constructor(e,t,r,a,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=a,this.id=_p++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new n(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:Hp),!!e.static,e.enables)}of(e){return new Ci([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ci(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ci(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}};function Hp(n,e){return n==e||n.length==e.length&&n.every((t,r)=>t===e[r])}var Ci=class{constructor(e,t,r,a){this.dependencies=e,this.facet=t,this.type=r,this.value=a,this.id=_p++}dynamicSlot(e){var t;let r=this.value,a=this.facet.compareInput,s=this.id,o=e[s]>>1,i=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((t=e[d.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[o]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Np(d,c)){let h=r(d);if(i?!V1(h,d.values[o],a):!a(h,d.values[o]))return d.values[o]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let m=md(f,p);if(this.dependencies.every(g=>g instanceof Me?f.facet(g)===d.facet(g):g instanceof vn?f.field(g,!1)==d.field(g,!1):!0)||(i?V1(h=r(d),m,a):a(h=r(d),m)))return d.values[o]=m,0}else h=r(d);return d.values[o]=h,1}}}get extension(){return this}};function V1(n,e,t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!t(n[r],e[r]))return!1;return!0}function Np(n,e){let t=!1;for(let r of e)su(n,r)&1&&(t=!0);return t}function yM(n,e,t){let r=t.map(l=>n[l.id]),a=t.map(l=>l.type),s=r.filter(l=>!(l&1)),o=n[e.id]>>1;function i(l){let u=[];for(let c=0;c<r.length;c++){let d=md(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)su(l,u);return l.values[o]=i(l),1},update(l,u){if(!Np(l,s))return 0;let c=i(l);return e.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,u){let c=Np(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&Hp(t,d))return l.values[o]=f,0;let h=i(l);return e.compare(h,f)?(l.values[o]=f,0):(l.values[o]=h,1)}}}var id=Me.define({static:!0}),vn=class n{constructor(e,t,r,a,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let t=new n(_p++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(id).find(r=>r.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,a)=>{let s=r.values[t],o=this.updateF(s,a);return this.compareF(s,o)?0:(r.values[t]=o,1)},reconfigure:(r,a)=>{let s=r.facet(id),o=a.facet(id),i;return(i=s.find(l=>l.field==this))&&i!=o.find(l=>l.field==this)?(r.values[t]=i.create(r),1):a.config.address[this.id]!=null?(r.values[t]=a.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,id.of({field:this,create:e})]}get extension(){return this}},ko={lowest:4,low:3,default:2,high:1,highest:0};function au(n){return e=>new hd(e,n)}var Na={highest:au(ko.highest),high:au(ko.high),default:au(ko.default),low:au(ko.low),lowest:au(ko.lowest)},hd=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},zr=class n{of(e){return new ou(this,e)}reconfigure(e){return n.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},ou=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},pd=class n{constructor(e,t,r,a,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,r){let a=[],s=Object.create(null),o=new Map;for(let f of bM(e,t,o))f instanceof vn?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let i=Object.create(null),l=[],u=[];for(let f of a)i[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,m=c&&c[f]||[];if(h.every(g=>g.type==0))if(i[p.id]=l.length<<1|1,Hp(m,h))l.push(r.facet(p));else{let g=p.combine(h.map(x=>x.value));l.push(r&&p.compare(g,r.facet(p))?r.facet(p):g)}else{for(let g of h)g.type==0?(i[g.id]=l.length<<1|1,l.push(g.value)):(i[g.id]=u.length<<1,u.push(x=>g.dynamicSlot(x)));i[p.id]=u.length<<1,u.push(g=>yM(g,p,h))}}let d=u.map(f=>f(i));return new n(e,o,d,i,l,s)}};function bM(n,e,t){let r=[[],[],[],[],[]],a=new Map;function s(o,i){let l=a.get(o);if(l!=null){if(l<=i)return;let u=r[l].indexOf(o);u>-1&&r[l].splice(u,1),o instanceof ou&&t.delete(o.compartment)}if(a.set(o,i),Array.isArray(o))for(let u of o)s(u,i);else if(o instanceof ou){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(o.compartment)||o.inner;t.set(o.compartment,u),s(u,i)}else if(o instanceof hd)s(o.inner,o.prec);else if(o instanceof vn)r[i].push(o),o.provides&&s(o.provides,i);else if(o instanceof Ci)r[i].push(o),o.facet.extensions&&s(o.facet.extensions,ko.default);else{let u=o.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(u==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,i)}}return s(n,ko.default),r.reduce((o,i)=>o.concat(i))}function su(n,e){if(e&1)return 2;let t=e>>1,r=n.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;n.status[t]=4;let a=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|a}function md(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}var ek=Me.define(),Rp=Me.define({combine:n=>n.some(e=>e),static:!0}),tk=Me.define({combine:n=>n.length?n[0]:void 0,static:!0}),nk=Me.define(),rk=Me.define(),ak=Me.define(),sk=Me.define({combine:n=>n.length?n[0]:!1}),Wr=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Mp}},Mp=class{of(e){return new Wr(this,e)}},Tp=class{constructor(e){this.map=e}of(e){return new xt(this,e)}},xt=class n{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new n(this.type,t)}is(e){return this.type==e}static define(e={}){return new Tp(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(t);s&&r.push(s)}return r}};xt.reconfigure=xt.define();xt.appendConfig=xt.define();var Pn=class n{constructor(e,t,r,a,s,o){this.startState=e,this.changes=t,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&Q1(r,t.newLength),s.some(i=>i.type==n.time)||(this.annotations=s.concat(n.time.of(Date.now())))}static create(e,t,r,a,s,o){return new n(e,t,r,a,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(n.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};Pn.time=Wr.define();Pn.userEvent=Wr.define();Pn.addToHistory=Wr.define();Pn.remote=Wr.define();function wM(n,e){let t=[];for(let r=0,a=0;;){let s,o;if(r<n.length&&(a==e.length||e[a]>=n[r]))s=n[r++],o=n[r++];else if(a<e.length)s=e[a++],o=e[a++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function ok(n,e,t){var r;let a,s,o;return t?(a=e.changes,s=Rn.empty(e.changes.length),o=n.changes.compose(e.changes)):(a=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(a)),{changes:o,selection:e.selection?e.selection.map(s):(r=n.selection)===null||r===void 0?void 0:r.map(a),effects:xt.mapEffects(n.effects,a).concat(xt.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Dp(n,e,t){let r=e.selection,a=Li(e.annotations);return e.userEvent&&(a=a.concat(Pn.userEvent.of(e.userEvent))),{changes:e.changes instanceof Rn?e.changes:Rn.of(e.changes||[],t,n.facet(tk)),selection:r&&(r instanceof se?r:se.single(r.anchor,r.head)),effects:Li(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function ik(n,e,t){let r=Dp(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;r=ok(r,Dp(n,e[s],o?r.changes.newLength:n.doc.length),o)}let a=Pn.create(n,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return kM(t?vM(a):a)}function vM(n){let e=n.startState,t=!0;for(let a of e.facet(nk)){let s=a(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:wM(t,s))}if(t!==!0){let a,s;if(t===!1)s=n.changes.invertedDesc,a=Rn.empty(e.doc.length);else{let o=n.changes.filter(t);a=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}n=Pn.create(e,a,n.selection&&n.selection.map(s),xt.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let r=e.facet(rk);for(let a=r.length-1;a>=0;a--){let s=r[a](n);s instanceof Pn?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Pn?n=s[0]:n=ik(e,Li(s),!1)}return n}function kM(n){let e=n.startState,t=e.facet(ak),r=n;for(let a=t.length-1;a>=0;a--){let s=t[a](n);s&&Object.keys(s).length&&(r=ok(r,Dp(e,s,n.changes.newLength),!0))}return r==n?n:Pn.create(e,n.changes,n.selection,r.effects,r.annotations,r.scrollIntoView)}var SM=[];function Li(n){return n==null?SM:Array.isArray(n)?n:[n]}var oa=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(oa||(oa={})),CM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Fp;try{Fp=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function LM(n){if(Fp)return Fp.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||CM.test(t)))return!0}return!1}function IM(n){return e=>{if(!/\S/.test(e))return oa.Space;if(LM(e))return oa.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return oa.Word;return oa.Other}}var Ct=class n{constructor(e,t,r,a,s,o){this.config=e,this.doc=t,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let i=0;i<this.config.dynamicSlots.length;i++)su(this,i<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return su(this,r),md(this,r)}update(...e){return ik(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:a}=t;for(let i of e.effects)i.is(zr.reconfigure)?(t&&(a=new Map,t.compartments.forEach((l,u)=>a.set(u,l)),t=null),a.set(i.value.compartment,i.value.extension)):i.is(xt.reconfigure)?(t=null,r=i.value):i.is(xt.appendConfig)&&(t=null,r=Li(r).concat(i.value));let s;t?s=e.startState.values.slice():(t=pd.resolve(r,a,this),s=new n(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let o=e.startState.facet(Rp)?e.newSelection:e.newSelection.asSingle();new n(t,e.newDoc,o,s,(i,l)=>l.update(i,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:se.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),a=this.changes(r.changes),s=[r.range],o=Li(r.effects);for(let i=1;i<t.ranges.length;i++){let l=e(t.ranges[i]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<i;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),o=xt.mapEffects(o,c).concat(xt.mapEffects(Li(l.effects),d))}return{changes:a,selection:se.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Rn?e:Rn.of(e,this.doc.length,this.facet(n.lineSeparator))}toText(e){return ct.of(e.split(this.facet(n.lineSeparator)||Ip))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(su(this,t),md(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof vn&&this.config.address[a.id]!=null&&(t[r]=a.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let o=r[s],i=e[s];a.push(o.init(l=>o.spec.fromJSON(i,l)))}}return n.create({doc:e.doc,selection:se.fromJSON(e.selection),extensions:t.extensions?a.concat([t.extensions]):a})}static create(e={}){let t=pd.resolve(e.extensions||[],new Map),r=e.doc instanceof ct?e.doc:ct.of((e.doc||"").split(t.staticFacet(n.lineSeparator)||Ip)),a=e.selection?e.selection instanceof se?e.selection:se.single(e.selection.anchor,e.selection.head):se.single(0);return Q1(a,r.length),t.staticFacet(Rp)||(a=a.asSingle()),new n(t,r,a,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(n.tabSize)}get lineBreak(){return this.facet(n.lineSeparator)||`
|
|
36
|
-
`}get readOnly(){return this.facet(sk)}phrase(e,...t){for(let r of this.facet(n.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>t.length?r:t[s-1]})),e}languageDataAt(e,t,r=-1){let a=[];for(let s of this.facet(ek))for(let o of s(this,t,r))Object.prototype.hasOwnProperty.call(o,e)&&a.push(o[e]);return a}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return IM(t.length?t[0]:"")}wordAt(e){let{text:t,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-r,i=e-r;for(;o>0;){let l=Nn(t,o,!1);if(s(t.slice(l,o))!=oa.Word)break;o=l}for(;i<a;){let l=Nn(t,i);if(s(t.slice(i,l))!=oa.Word)break;i=l}return o==i?null:se.range(o+r,i+r)}};Ct.allowMultipleSelections=Rp;Ct.tabSize=Me.define({combine:n=>n.length?n[0]:4});Ct.lineSeparator=tk;Ct.readOnly=sk;Ct.phrases=Me.define({compare(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length==r.length&&t.every(a=>n[a]==e[a])}});Ct.languageData=ek;Ct.changeFilter=nk;Ct.transactionFilter=rk;Ct.transactionExtender=ak;zr.reconfigure=xt.define();function Ai(n,e,t={}){let r={};for(let a of n)for(let s of Object.keys(a)){let o=a[s],i=r[s];if(i===void 0)r[s]=o;else if(!(i===o||o===void 0))if(Object.hasOwnProperty.call(t,s))r[s]=t[s](i,o);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var Pa=class{eq(e){return this==e}range(e,t=e){return iu.create(e,t,this)}};Pa.prototype.startSide=Pa.prototype.endSide=0;Pa.prototype.point=!1;Pa.prototype.mapMode=ir.TrackDel;function Up(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}var iu=class n{constructor(e,t,r){this.from=e,this.to=t,this.value=r}static create(e,t,r){return new n(e,t,r)}};function Ep(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}var Bp=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.value=r,this.maxPoint=a}get length(){return ki(this.to)}findIndex(e,t,r,a=0){let s=r?this.to:this.from;for(let o=a,i=s.length;;){if(o==i)return o;let l=o+i>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-t;if(l==o)return u>=0?o:i;u>=0?i=l:o=l+1}}between(e,t,r,a){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(r,1e9,!1,s);s<o;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t,r,a,s){let o=[],i=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,m,g;if(h==p){let x=t.mapPos(h,f.startSide,f.mapMode);if(x==null||(m=g=x,f.startSide!=f.endSide&&(g=t.mapPos(h,f.endSide),g<m)))continue}else if(m=t.mapPos(h,f.startSide),g=t.mapPos(p,f.endSide),m>g||m==g&&f.startSide>0&&f.endSide<=0)continue;if(!((g-m||f.endSide-f.startSide)<0))if(u<0&&(u=m),f.point&&(c=Math.max(c,g-m)),(m-r||f.startSide-a)>=0)o.push(f),i.push(m-u),l.push(g-u),r=g,a=f.endSide;else{if(m==g)for(let x=o.length;x>0;x--){if((m-(l[x-1]+u)||f.startSide-o[x-1].endSide)>=0){o.splice(x,0,f),i.splice(x,0,m-u),l.splice(x,0,g-u);continue e}if((m-(i[x-1]+u)||f.endSide-o[x-1].startSide)>0)break}s(m,g,f)}}return{mapped:o.length?new n(i,l,o,c):null,pos:u}}},wt=class n{constructor(e,t,r,a){this.chunkPos=e,this.chunk=t,this.nextLayer=r,this.maxPoint=a}static create(e,t,r,a){return new n(e,t,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(r&&(t=t.slice().sort(Ep)),this.isEmpty)return t.length?n.of(t):this;let i=new gd(this,null,-1).goto(0),l=0,u=[],c=new jn;for(;i.value||l<t.length;)if(l<t.length&&(i.from-t[l].from||i.startSide-t[l].value.startSide)>=0){let d=t[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else i.rangeIndex==1&&i.chunkIndex<this.chunk.length&&(l==t.length||this.chunkEnd(i.chunkIndex)<t[l].from)&&(!o||a>this.chunkEnd(i.chunkIndex)||s<this.chunkPos[i.chunkIndex])&&c.addChunk(this.chunkPos[i.chunkIndex],this.chunk[i.chunkIndex])?i.nextChunk():((!o||a>i.to||s<i.from||o(i.from,i.to,i.value))&&(c.addInner(i.from,i.to,i.value,!1)||u.push(iu.create(i.from,i.to,i.value))),i.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?n.empty:this.nextLayer.update({add:u,filter:o,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],r=[],a=-1,s,o=(l,u,c)=>{s||(s=new jn),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),t.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=t.length?[ki(r)+ki(t).length,ki(ki(t).value).endSide]:[-1,-1],{mapped:p,pos:m}=c.map(u,e,f,h,o);p&&(a=Math.max(a,p.maxPoint),t.push(p),r.push(m))}}let i=this.nextLayer.map(e);return s&&(i=s.finishInner(i)),t.length==0?i:new n(r,t,i||n.empty,a)}between(e,t,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],o=this.chunk[a];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,r)===!1)return}this.nextLayer.between(e,t,r)}}iter(e=0){return lu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return lu.from(e).goto(t)}static compare(e,t,r,a,s=-1){let o=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),i=t.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=$1(o,i,r),u=new So(o,l,s),c=new So(i,l,s);r.iterGaps((d,f,h)=>K1(u,d,c,f,h,a)),r.empty&&r.length==0&&K1(u,0,c,0,0,a)}static eq(e,t,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let i=$1(s,o),l=new So(s,i,0).goto(r),u=new So(o,i,0).goto(r);for(;;){if(l.to!=u.to||!Op(l.active,u.active)||l.point&&(!u.point||!Up(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,t,r,a,s=-1){let o=new So(e,null,s).goto(t),i=t,l=o.openStart;for(;;){let u=Math.min(o.to,r);if(o.point){let c=o.activeForPoint(o.to),d=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,l);a.point(i,u,o.point,c,d,o.pointRank),l=Math.min(o.openEnd(u),c.length)}else u>i&&(a.span(i,u,o.active,l),l=o.openEnd(u));if(o.to>r)return l+(o.point&&o.to>r?1:0);i=o.to,o.next()}}static of(e,t=!1){let r=new jn;for(let a of e instanceof iu?[e]:t?AM(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return n.empty;let t=ki(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=n.empty;a=a.nextLayer)t=new n(a.chunkPos,a.chunk,t,Math.max(a.maxPoint,t.maxPoint));return t}};wt.empty=new wt([],[],null,-1);function ki(n){return n[n.length-1]}function AM(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let r=n[t];if(Ep(e,r)>0)return n.slice().sort(Ep);e=r}return n}wt.empty.nextLayer=wt.empty;var jn=class n{finishChunk(e){this.chunks.push(new Bp(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,r){this.addRange(e,t,r,!0)}addRange(e,t,r,a){this.addInner(e,t,r,a)||(this.nextLayer||(this.nextLayer=new n)).addRange(e,t,r,a)}addInner(e,t,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=t,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let r=t.value.length-1;return this.last=t.value[r],this.lastFrom=t.from[r]+e,this.lastTo=t.to[r]+e,!0}finish(){return this.finishInner(wt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=wt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function $1(n,e,t){let r=new Map;for(let s of n)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&r.set(s.chunk[o],s.chunkPos[o]);let a=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let i=r.get(s.chunk[o]);i!=null&&(t?t.mapPos(i):i)==s.chunkPos[o]&&!t?.touchesRange(i,i+s.chunk[o].length)&&a.add(s.chunk[o])}return a}var gd=class{constructor(e,t,r,a=0){this.layer=e,this.skip=t,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],r=e+t.from[this.rangeIndex];if(this.from=r,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},lu=class n{constructor(e){this.heap=e}static from(e,t=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=r&&a.push(new gd(o,t,r,s));return a.length==1?a[0]:new n(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let r of this.heap)r.goto(e,t);for(let r=this.heap.length>>1;r>=0;r--)Cp(this.heap,r);return this.next(),this}forward(e,t){for(let r of this.heap)r.forward(e,t);for(let r=this.heap.length>>1;r>=0;r--)Cp(this.heap,r);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Cp(this.heap,0)}}};function Cp(n,e){for(let t=n[e];;){let r=(e<<1)+1;if(r>=n.length)break;let a=n[r];if(r+1<n.length&&a.compare(n[r+1])>=0&&(a=n[r+1],r++),t.compare(a)<0)break;n[r]=t,n[e]=a,e=r}}var So=class{constructor(e,t,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=lu.from(e,t,r)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ld(this.active,e),ld(this.activeTo,e),ld(this.activeRank,e),this.minActive=X1(this.active,this.activeTo)}addActive(e){let t=0,{value:r,to:a,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||a-this.activeTo[t])>0;)t++;ud(this.active,t,r),ud(this.activeTo,t,a),ud(this.activeRank,t,s),e&&ud(e,t,this.cursor.from),this.minActive=X1(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&ld(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&t.push(this.active[r]);return t.reverse()}openEnd(e){let t=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)t++;return t}};function K1(n,e,t,r,a,s){n.goto(e),t.goto(r);let o=r+a,i=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=n.to+l-t.to,f=d||n.endSide-t.endSide,h=f<0?n.to+l:t.to,p=Math.min(h,o);if(n.point||t.point?(n.point&&t.point&&Up(n.point,t.point)&&Op(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(i,p,n.point,t.point),c=!1):(c&&(s.boundChange(i),c=!1),p>i&&!Op(n.active,t.active)&&s.compareRange(i,p,n.active,t.active),u&&p<o&&(d||n.openEnd(h)!=t.openEnd(h))&&(c=!0)),h>o)break;i=h,f<=0&&n.next(),f>=0&&t.next()}}function Op(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!Up(n[t],e[t]))return!1;return!0}function ld(n,e){for(let t=e,r=n.length-1;t<r;t++)n[t]=n[t+1];n.pop()}function ud(n,e,t){for(let r=n.length-1;r>=e;r--)n[r+1]=n[r];n[e]=t}function X1(n,e){let t=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||n[a].endSide-n[t].endSide)<0&&(t=a,r=e[a]);return t}function Io(n,e,t=n.length){let r=0;for(let a=0;a<t&&a<n.length;)n.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=Nn(n,a));return r}function lk(n,e,t,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==n.length)break;s+=n.charCodeAt(a)==9?t-s%t:1,a=Nn(n,a)}return r===!0?-1:n.length}var uk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),Gp=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),ck=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},lr=class{constructor(e,t){this.rules=[];let{finish:r}=t||{};function a(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,i,l,u){let c=[],d=/^@(\w+)\b/.exec(o[0]),f=d&&d[1]=="keyframes";if(d&&i==null)return l.push(o[0]+";");for(let h in i){let p=i[h];if(/&/.test(h))s(h.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?o.map(r):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(a(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
37
|
-
`)}static newName(){let e=
|
|
38
|
-
`;this.styleTag.textContent=l}let i=t.head||t;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var ns={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Pi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},PM=typeof navigator<"u"&&/Mac/.test(navigator.platform),NM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(mn=0;mn<10;mn++)ns[48+mn]=ns[96+mn]=String(mn);var mn;for(mn=1;mn<=24;mn++)ns[mn+111]="F"+mn;var mn;for(mn=65;mn<=90;mn++)ns[mn]=String.fromCharCode(mn+32),Pi[mn]=String.fromCharCode(mn);var mn;for(xd in ns)Pi.hasOwnProperty(xd)||(Pi[xd]=ns[xd]);var xd;function fk(n){var e=PM&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||NM&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Pi:ns)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var er=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Xp=typeof document<"u"?document:{documentElement:{style:{}}},Yp=/Edge\/(\d+)/.exec(er.userAgent),jk=/MSIE \d/.test(er.userAgent),Jp=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(er.userAgent),zd=!!(jk||Jp||Yp),hk=!zd&&/gecko\/(\d+)/i.test(er.userAgent),Wp=!zd&&/Chrome\/(\d+)/.exec(er.userAgent),pk="webkitFontSmoothing"in Xp.documentElement.style,Zp=!zd&&/Apple Computer/.test(er.vendor),mk=Zp&&(/Mobile\/\w+/.test(er.userAgent)||er.maxTouchPoints>2),we={mac:mk||/Mac/.test(er.platform),windows:/Win/.test(er.platform),linux:/Linux|X11/.test(er.platform),ie:zd,ie_version:jk?Xp.documentMode||6:Jp?+Jp[1]:Yp?+Yp[1]:0,gecko:hk,gecko_version:hk?+(/Firefox\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,chrome:!!Wp,chrome_version:Wp?+Wp[1]:0,ios:mk,android:/Android\b/.test(er.userAgent),webkit:pk,webkit_version:pk?+(/\bAppleWebKit\/(\d+)/.exec(er.userAgent)||[0,0])[1]:0,safari:Zp,safari_version:Zp?+(/\bVersion\/(\d+(\.\d+)?)/.exec(er.userAgent)||[0,0])[1]:0,tabSize:Xp.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Hm(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}var Pd=Object.create(null);function Um(n,e,t){if(n==e)return!0;n||(n=Pd),e||(e=Pd);let r=Object.keys(n),a=Object.keys(e);if(r.length-(t&&r.indexOf(t)>-1?1:0)!=a.length-(t&&a.indexOf(t)>-1?1:0))return!1;for(let s of r)if(s!=t&&(a.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function RM(n,e){for(let t=n.attributes.length-1;t>=0;t--){let r=n.attributes[t].name;e[r]==null&&n.removeAttribute(r)}for(let t in e){let r=e[t];t=="style"?n.style.cssText=r:n.getAttribute(t)!=r&&n.setAttribute(t,r)}}function gk(n,e,t){let r=!1;if(e)for(let a in e)t&&a in t||(r=!0,a=="style"?n.style.cssText="":n.removeAttribute(a));if(t)for(let a in t)e&&e[a]==t[a]||(r=!0,a=="style"?n.style.cssText=t[a]:n.setAttribute(a,t[a]));return r}function MM(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let r=n.attributes[t];e[r.name]=r.value}return e}var Ir=class{eq(e){return!1}updateDOM(e,t,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},Bn=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(Bn||(Bn={})),Xe=class extends Pa{constructor(e,t,r,a){super(),this.startSide=e,this.endSide=t,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new vu(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return t+=r&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Ro(e,t,t,r,e.widget||null,!1)}static replace(e){let t=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:o}=qk(e,t);r=(s?t?-3e8:-1:5e8)-1,a=(o?t?2e8:1:-6e8)+1}return new Ro(e,r,a,t,e.widget||null,!0)}static line(e){return new ku(e)}static set(e,t=!1){return wt.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Xe.none=wt.empty;var vu=class n extends Xe{constructor(e){let{start:t,end:r}=qk(e);super(t?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Hm(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Pd}eq(e){return this==e||e instanceof n&&this.tagName==e.tagName&&Um(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};vu.prototype.point=!1;var ku=class n extends Xe{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof n&&this.spec.class==e.spec.class&&Um(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}};ku.prototype.mapMode=ir.TrackBefore;ku.prototype.point=!0;var Ro=class n extends Xe{constructor(e,t,r,a,s,o){super(t,r,s,e),this.block=a,this.isReplace=o,this.mapMode=a?t<=0?ir.TrackBefore:ir.TrackAfter:ir.TrackDel}get type(){return this.startSide!=this.endSide?Bn.WidgetRange:this.startSide<=0?Bn.WidgetBefore:Bn.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof n&&TM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}};Ro.prototype.point=!0;function qk(n,e=!1){let{inclusiveStart:t,inclusiveEnd:r}=n;return t==null&&(t=n.inclusive),r==null&&(r=n.inclusive),{start:t??e,end:r??e}}function TM(n,e){return n==e||!!(n&&e&&n.compare(e))}function Di(n,e,t,r=0){let a=t.length-1;a>=0&&t[a]+r>=n?t[a]=Math.max(t[a],e):t.push(n,e)}var Nd=class n extends Pa{constructor(e,t,r){super(),this.tagName=e,this.attributes=t,this.rank=r}eq(e){return e==this||e instanceof n&&this.tagName==e.tagName&&Um(this.attributes,e.attributes)}static create(e){return new n(e.tagName,e.attributes||Pd,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return wt.of(e,t)}};Nd.prototype.startSide=Nd.prototype.endSide=-1;function Su(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function Qp(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function du(n,e){if(!e.anchorNode)return!1;try{return Qp(n,e.anchorNode)}catch{return!1}}function fu(n){return n.nodeType==3?Lu(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function hu(n,e,t,r){return t?xk(n,e,t,r,-1)||xk(n,e,t,r,1):!1}function Us(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Rd(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function xk(n,e,t,r,a){for(;;){if(n==t&&e==r)return!0;if(e==(a<0?0:ss(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=Us(n)+(a<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(a<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=a<0?ss(n):0}else return!1}}function ss(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Cu(n,e){let{left:t,right:r}=n;if(t==r)return n;let a=e?t:r;return{left:a,right:a,top:n.top,bottom:n.bottom}}function DM(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Vk(n,e){let t=e.width/n.offsetWidth,r=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-n.offsetHeight)<1)&&(r=1),{scaleX:t,scaleY:r}}function FM(n,e,t,r,a,s,o,i){let l=n.ownerDocument,u=l.defaultView||window;for(let c=n,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,m=1;if(h)f=DM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Vk(c,w)),f={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let g=0,x=0;if(a=="nearest")e.top<f.top+o?(x=e.top-(f.top+o),t>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+o)):e.bottom>f.bottom-o&&(x=e.bottom-f.bottom+o,t<0&&e.top-x<f.top&&(x=e.top-(f.top+o)));else{let w=e.bottom-e.top,y=f.bottom-f.top;x=(a=="center"&&w<=y?e.top+w/2-y/2:a=="start"||a=="center"&&t<0?e.top-o:e.bottom-y+o)-f.top}if(r=="nearest"?e.left<f.left+s?(g=e.left-(f.left+s),t>0&&e.right>f.right+g&&(g=e.right-f.right+s)):e.right>f.right-s&&(g=e.right-f.right+s,t<0&&e.left<f.left+g&&(g=e.left-(f.left+s))):g=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==i?e.left-s:e.right-(f.right-f.left)+s)-f.left,g||x)if(h)u.scrollBy(g,x);else{let w=0,y=0;if(x){let C=c.scrollTop;c.scrollTop+=x/m,y=(c.scrollTop-C)*m}if(g){let C=c.scrollLeft;c.scrollLeft+=g/p,w=(c.scrollLeft-C)*p}e={left:e.left-w,top:e.top-y,right:e.right-w,bottom:e.bottom-y},w&&Math.abs(w-g)<1&&(r="nearest"),y&&Math.abs(y-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function $k(n,e=!0){let t=n.ownerDocument,r=null,a=null;for(let s=n.parentNode;s&&!(s==t.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var em=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:r}=e;this.set(t,Math.min(e.anchorOffset,t?ss(t):0),r,Math.min(e.focusOffset,r?ss(r):0))}set(e,t,r,a){this.anchorNode=e,this.anchorOffset=t,this.focusNode=r,this.focusOffset=a}};function Kk(n){let e=[];for(let t=n;t;t=t.nodeType==11?t.host:t.parentNode)t.nodeType==1&&e.push({node:t,left:t.scrollLeft,top:t.scrollTop});return e}function Xk(n,e=!0){for(let{node:t,left:r,top:a}of n)e&&t.scrollTop!=a&&(t.scrollTop=a),t.scrollLeft!=r&&(t.scrollLeft=r)}var Ao=null;we.safari&&we.safari_version>=26&&(Ao=!1);function Yk(n){if(n.setActive)return n.setActive();if(Ao)return n.focus(Ao);let e=Kk(n);n.focus(Ao==null?{get preventScroll(){return Ao={preventScroll:!0},!0}}:void 0),Ao||(Ao=!1,Xk(e))}var yk;function Lu(n,e,t=e){let r=yk||(yk=document.createRange());return r.setEnd(n,t),r.setStart(n,e),r}function Fi(n,e,t,r){let a={key:e,code:e,keyCode:t,which:t,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,n.dispatchEvent(s);let o=new KeyboardEvent("keyup",a);return o.synthetic=!0,n.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function EM(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function BM(n,e){let t=e.focusNode,r=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=r)return!1;for(r=Math.min(r,ss(t));;)if(r){if(t.nodeType!=1)return!1;let a=t.childNodes[r-1];a.contentEditable=="false"?r--:(t=a,r=ss(t))}else{if(t==n)return!0;r=Us(t),t=t.parentNode}}function Jk(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Zk(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r>0)return{node:t,offset:r};if(t.nodeType==1&&r>0){if(t.contentEditable=="false")return null;t=t.childNodes[r-1],r=ss(t)}else if(t.parentNode&&!Rd(t))r=Us(t),t=t.parentNode;else return null}}function Qk(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r<t.nodeValue.length)return{node:t,offset:r};if(t.nodeType==1&&r<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[r],r=0}else if(t.parentNode&&!Rd(t))r=Us(t)+1,t=t.parentNode;else return null}}var Ma=class n{constructor(e,t,r=!0){this.node=e,this.offset=t,this.precise=r}static before(e,t){return new n(e.parentNode,Us(e),t)}static after(e,t){return new n(e.parentNode,Us(e)+1,t)}},Wt=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(Wt||(Wt={})),Mo=Wt.LTR,Gm=Wt.RTL;function eS(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}var OM=eS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),_M=eS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),tm=Object.create(null),Ra=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);tm[e]=t,tm[t]=-e}function tS(n){return n<=247?OM[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?_M[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}var HM=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Vr=class{get dir(){return this.level%2?Gm:Mo}constructor(e,t,r){this.from=e,this.to=t,this.level=r}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,r,a){let s=-1;for(let o=0;o<e.length;o++){let i=e[o];if(i.from<=t&&i.to>=t){if(i.level==r)return o;(s<0||(a!=0?a<0?i.from<t:i.to>t:e[s].level>i.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}};function nS(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],a=e[t];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!nS(r.inner,a.inner))return!1}return!0}var Gt=[];function UM(n,e,t,r,a){for(let s=0;s<=r.length;s++){let o=s?r[s-1].to:e,i=s<r.length?r[s].from:t,l=s?256:a;for(let u=o,c=l,d=l;u<i;u++){let f=tS(n.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),Gt[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=o,c=l,d=l;u<i;u++){let f=Gt[u];if(f==128)u<i-1&&c==Gt[u+1]&&c&24?f=Gt[u]=c:Gt[u]=256;else if(f==64){let h=u+1;for(;h<i&&Gt[h]==64;)h++;let p=u&&c==8||h<t&&Gt[h]==8?d==1?1:8:256;for(let m=u;m<h;m++)Gt[m]=p;u=h-1}else f==8&&d==1&&(Gt[u]=1);c=f,f&7&&(d=f)}}}function GM(n,e,t,r,a){let s=a==1?2:1;for(let o=0,i=0,l=0;o<=r.length;o++){let u=o?r[o-1].to:e,c=o<r.length?r[o].from:t;for(let d=u,f,h,p;d<c;d++)if(h=tm[f=n.charCodeAt(d)])if(h<0){for(let m=i-3;m>=0;m-=3)if(Ra[m+1]==-h){let g=Ra[m+2],x=g&2?a:g&4?g&1?s:a:0;x&&(Gt[d]=Gt[Ra[m]]=x),i=m;break}}else{if(Ra.length==189)break;Ra[i++]=d,Ra[i++]=f,Ra[i++]=l}else if((p=Gt[d])==2||p==1){let m=p==a;l=m?0:1;for(let g=i-3;g>=0;g-=3){let x=Ra[g+2];if(x&2)break;if(m)Ra[g+2]|=2;else{if(x&4)break;Ra[g+2]|=4}}}}}function zM(n,e,t,r){for(let a=0,s=r;a<=t.length;a++){let o=a?t[a-1].to:n,i=a<t.length?t[a].from:e;for(let l=o;l<i;){let u=Gt[l];if(u==256){let c=l+1;for(;;)if(c==i){if(a==t.length)break;c=t[a++].to,i=a<t.length?t[a].from:e}else if(Gt[c]==256)c++;else break;let d=s==1,f=(c<e?Gt[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,m=a,g=m?t[m-1].to:n;p>l;)p==g&&(p=t[--m].from,g=m?t[m-1].to:n),Gt[--p]=h;l=c}else s=u,l++}}}function nm(n,e,t,r,a,s,o){let i=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<t;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let m=Gt[l];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let m=s[u];if(!c)for(let g=m.to,x=u+1;;){if(g==t)break e;if(x<s.length&&s[x].from==g)g=s[x++].to;else{if(Gt[g]==i)break e;break}}if(u++,f)f.push(m);else{m.from>l&&o.push(new Vr(l,m.from,h));let g=m.direction==Mo!=!(h%2);rm(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.to}p=m.to}else{if(p==t||(c?Gt[p]!=i:Gt[p]==i))break;p++}f?nm(n,l,p,r+1,a,f,o):l<p&&o.push(new Vr(l,p,h)),l=p}else for(let l=t,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let m=Gt[l-1];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let m=s[--u];if(!c)for(let g=m.from,x=u;;){if(g==e)break e;if(x&&s[x-1].to==g)g=s[--x].from;else{if(Gt[g-1]==i)break e;break}}if(f)f.push(m);else{m.to<l&&o.push(new Vr(m.to,l,h));let g=m.direction==Mo!=!(h%2);rm(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.from}p=m.from}else{if(p==e||(c?Gt[p-1]!=i:Gt[p-1]==i))break;p--}f?nm(n,p,l,r+1,a,f,o):p<l&&o.push(new Vr(p,l,h)),l=p}}function rm(n,e,t,r,a,s,o){let i=e%2?2:1;UM(n,a,s,r,i),GM(n,a,s,r,i),zM(a,s,r,i),nm(n,a,s,e,t,r,o)}function WM(n,e,t){if(!n)return[new Vr(0,0,e==Gm?1:0)];if(e==Mo&&!t.length&&!HM.test(n))return rS(n.length);if(t.length)for(;n.length>Gt.length;)Gt[Gt.length]=256;let r=[],a=e==Mo?0:1;return rm(n,a,a,t,0,n.length,r),r}function rS(n){return[new Vr(0,n,0)]}var aS="";function jM(n,e,t,r,a){var s;if(!n.length)return null;let o=r.head-n.from,i;if(r.head==n.from&&r.assoc<0){if(!a)return null;o=e[i=0].side(!1,t)}else if(r.head==n.to&&r.assoc>0){if(a)return null;o=e[i=e.length-1].side(!0,t)}else i=Vr.find(e,o,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[i],u=l.side(a,t);if(o==u){let f=i+=a?1:-1;if(f<0||f>=e.length)return null;l=e[i=f],o=l.side(!a,t),u=l.side(a,t)}let c=Nn(n.text,o,l.forward(a,t));(c<l.from||c>l.to)&&(c=u),aS=n.text.slice(Math.min(o,c),Math.max(o,c));let d=i==(a?e.length-1:0)?null:e[i+(a?1:-1)];if(c==u){if(!d)return a?se.cursor(n.to,1):se.cursor(n.from,-1);if(d.level+(a?0:1)<l.level)return se.cursor(d.side(!a,t)+n.from,d.forward(a,t)?1:-1,d.level)}return se.cursor(c+n.from,l.forward(a,t)?-1:1,l.level)}function qM(n,e,t){for(let r=e;r<t;r++){let a=tS(n.charCodeAt(r));if(a==1)return Mo;if(a==2||a==4)return Gm}return Mo}var sS=Me.define(),oS=Me.define(),iS=Me.define(),lS=Me.define(),am=Me.define(),uS=Me.define(),cS=Me.define(),zm=Me.define(),Wm=Me.define(),dS=Me.define({combine:n=>n.some(e=>e)}),fS=Me.define({combine:n=>n.some(e=>e)}),hS=Me.define(),pu=class n{constructor(e,t,r,a,s,o=!1){this.range=e,this.y=t,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new n(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new n(se.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},yd=xt.define({map:(n,e)=>n.map(e)}),pS=xt.define();function la(n,e,t){let r=n.facet(lS);r.length?r[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}var rs=Me.define({combine:n=>n.length?n[0]:!0}),VM=0,Ri=Me.define({combine(n){return n.filter((e,t)=>{for(let r=0;r<t;r++)if(n[r].plugin==e.plugin)return!1;return!0})}}),cr=class n{constructor(e,t,r,a,s){this.id=e,this.create=t,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Ri.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ri.of({plugin:this,arg:e}))}static define(e,t){let{eventHandlers:r,eventObservers:a,provide:s,decorations:o}=t||{};return new n(VM++,e,r,a,i=>{let l=[];return o&&l.push(Wd.of(u=>{let c=u.plugin(i);return c?o(c):Xe.none})),s&&l.push(s(i)),l})}static fromClass(e,t){return n.define((r,a)=>new e(r,a),t)}},mu=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(r){if(la(t.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){la(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(r){la(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},mS=Me.define(),jm=Me.define(),Wd=Me.define(),gS=Me.define(),qm=Me.define(),Iu=Me.define(),xS=Me.define();function bk(n,e){let t=n.state.facet(xS);if(!t.length)return t;let r=t.map(s=>s instanceof Function?s(n):s),a=[];return wt.spans(r,e.from,e.to,{point(){},span(s,o,i,l){let u=s-e.from,c=o-e.from,d=a;for(let f=i.length-1;f>=0;f--,l--){let h=i[f].spec.bidiIsolate,p;if(h==null&&(h=qM(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let m={from:u,to:c,direction:h,inner:[]};d.push(m),d=m.inner}}}}),a}var yS=Me.define();function bS(n){let e=0,t=0,r=0,a=0;for(let s of n.state.facet(yS)){let o=s(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(a=Math.max(a,o.bottom)))}return{left:e,right:t,top:r,bottom:a}}var uu=Me.define(),ua=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}join(e){return new n(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,r=this;for(;t>0;t--){let a=e[t-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(t-1,1)}}return e.splice(t,0,r),e}static extendWithRanges(e,t){if(t.length==0)return e;let r=[];for(let a=0,s=0,o=0;;){let i=a<e.length?e[a].fromB:1e9,l=s<t.length?t[s]:1e9,u=Math.min(i,l);if(u==1e9)break;let c=u+o,d=u,f=c;for(;;)if(s<t.length&&t[s]<=d){let h=t[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)o=e[p].toA-e[p].toB;f=Math.max(f,h+o)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),o=h.toA-h.toB}else break;r.push(new n(c,f,u,d))}return r}},Md=class n{constructor(e,t,r){this.view=e,this.state=t,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Rn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,o,i,l)=>a.push(new ua(s,o,i,l))),this.changedRanges=a}static create(e,t,r){return new n(e,t,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},$M=[],Zt=class{constructor(e,t,r=0){this.dom=e,this.length=t,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return $M}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&RM(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let r=t;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,r){return null}domPosFor(e,t){let r=Us(this.dom),a=this.length?e>0:t>0;return new Ma(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Bi)return e;return null}static get(e){return e.cmTile}},Ei=class extends Zt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,r=null,a,s=e?.node==t?e:null,o=0;for(let i of this.children){if(i.sync(e),o+=i.length+i.breakAfter,a=r?r.nextSibling:t.firstChild,s&&a!=i.dom&&(s.written=!0),i.dom.parentNode==t)for(;a&&a!=i.dom;)a=wk(a);else t.insertBefore(i.dom,a);r=i.dom}for(a=r?r.nextSibling:t.firstChild,s&&a&&(s.written=!0);a;)a=wk(a);this.length=o}};function wk(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Bi=class extends Ei{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Zt.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!t.length)return;r=r.parent,r.breakAfter&&s++,a=t.pop()}else{let o=r.children[a++];if(o instanceof as)t.push(a),r=o,a=0;else{let i=s+o.length,l=e(o,s);if(l!==void 0)return l;s=i+o.breakAfter}}}resolveBlock(e,t){let r,a=-1,s,o=-1;if(this.blockTiles((i,l)=>{let u=l+i.length;if(e>=l&&e<=u){if(i.isWidget()&&t>=-1&&t<=1){if(i.flags&32)return!0;i.flags&16&&(r=void 0)}(l<e||e==u&&(t<-1?i.length:i.covers(1)))&&(!r||!i.isWidget()&&r.isWidget())&&(r=i,a=e-l),(u>e||e==l&&(t>1?i.length:i.covers(-1)))&&(!s||!i.isWidget()&&s.isWidget())&&(s=i,o=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&t<0||!s?{tile:r,offset:a}:{tile:s,offset:o}}},as=class n extends Ei{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},Oi=class n extends Ei{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,r){let a=new n(t||document.createElement("div"),e);return(!t||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,t,r){let a=null,s=-1,o=null,i=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],m=h+p.length;m>=d&&(p.isComposite()?l(p,d-h):(!o||o.isHidden&&(t>0&&!(o.flags&32)||r&&XM(o,p)))&&(m>d||p.flags&32&&t<=1)?(o=p,i=d-h):(h<d||p.flags&16&&!p.isHidden&&t>=-1)&&(a=p,s=d-h)),h=m}}l(this,e);let u=(t<0?a:o)||a||o;return u?{tile:u,offset:u==a?s:i}:null}coordsIn(e,t,r){let a=this.resolveInline(e,t,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),t,r):KM(this)}domIn(e,t){let r=this.resolveInline(e,t);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new Ma(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:t);let o=r.tile.parent,i=!1;for(let l of o.children){if(i)return new Ma(l.dom,0);l==r.tile&&(i=!0)}}return new Ma(this.dom,0)}};function KM(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=fu(e);return t[t.length-1]||null}function XM(n,e){let t=n.coordsIn(0,1),r=e.coordsIn(0,1);return t&&r&&r.top<t.bottom}var ur=class n extends Ei{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},Po=class n extends Zt{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,o=e,i=0;e==0&&t<0||e==a&&t>=0?we.chrome||we.gecko||(e?(s--,i=1):o<a&&(o++,i=-1)):t<0?s--:o<a&&o++;let l=Lu(this.dom,s,o).getClientRects();if(!l.length)return null;let u=l[(i?i<0:t>=0)?0:l.length-1];return we.safari&&!i&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:Cu(u,(i?i>0:t<0)==r)}static of(e,t){let r=new n(t||document.createTextNode(e),e);return t||(r.flags|=2),r}},To=class n extends Zt{constructor(e,t,r,a){super(e,t,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,r){let a=this.widget.coordsAt(this.dom,e,t);if(a)return a;if(r)return Cu(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let i=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=i?s.length-1:0;o=s[l],!(e>0?l==0:l==s.length-1||o.top<o.bottom);l+=i?-1:1);return Cu(o,!i)}}get overrideDOMText(){if(!this.length)return ct.empty;let{root:e}=this;if(!e)return ct.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,r,a,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new n(s,r,e,a)}},_i=class extends Zt{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return ct.empty}coordsIn(e,t,r){let a=this.dom.getBoundingClientRect();return r==null?a:Cu(a,t>0==r)}},sm=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,r){let{tile:a,index:s,beforeBreak:o,parents:i}=this;for(;e||t>0;)if(a.isComposite())if(o){if(!e)break;r&&r.break(),e--,o=!1}else if(s==a.children.length){if(!e&&!i.length)break;r&&r.leave(a),o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(t>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(o=!!u,s++,e-=l.length):(i.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},om=class{constructor(e,t,r,a){this.from=e,this.to=t,this.wrapper=r,this.rank=a}},im=class{constructor(e,t,r){this.cache=e,this.root=t,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,r,a){var s;this.flushBuffer();let o=this.ensureMarks(t,r),i=o.lastChild;if(i&&i.isText()&&!(i.flags&8)&&i.length+e.length<512){this.cache.reused.set(i,2);let l=o.children[o.children.length-1]=new Po(i.dom,i.text+e);l.parent=o}else o.append(a||Po.of(e,(s=this.cache.find(Po))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let r=this.curLine;r.dom!=t.line.dom&&(r.setDOM(this.cache.reused.has(t.line)?jp(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let a=r;for(let i=t.marks.length-1;i>=0;i--){let l=t.marks[i],u=a.lastChild;if(u instanceof ur&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(jp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&Zt.get(l.dom)&&(c=jp(l.dom));let d=ur.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=Zt.get(e.text);s&&this.cache.reused.set(s,2);let o=new Po(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,a.append(o)}addInlineWidget(e,t,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(t,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,r){this.flushBuffer(),this.ensureMarks(t,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var r;e||(e=wS);let a=Oi.start(e,t||((r=this.cache.find(Oi))===null||r===void 0?void 0:r.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],i;if(t>0&&(i=a.lastChild)&&i instanceof ur&&i.mark.eq(o))a=i,t--;else{let l=ur.of(o,(r=this.cache.find(ur,u=>u.mark.eq(o)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,t=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!vk(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(we.ios&&vk(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(qp,0,32)||new To(qp.toDOM(),0,qp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,r=new om(e.from,e.to,e.value,t),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let r of this.wrappers){let a=t.lastChild;if(r.from<this.pos&&a instanceof as&&a.wrapper.eq(r.wrapper))t=a;else{let s=as.of(r.wrapper,(e=this.cache.find(as,o=>o.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),r=this.cache.find(_i,void 0,1);return r&&(r.flags=t),r||new _i(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},lm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=a;let i=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,t);return this.textOff=t,r}},Td=[To,Oi,Po,ur,_i,as,Bi];for(let n=0;n<Td.length;n++)Td[n].bucket=n;var um=class{constructor(e){this.view=e,this.buckets=Td.map(()=>[]),this.index=Td.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,r=this.buckets[t];r.length<6?r.push(e):r[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,r=2){let a=e.bucket,s=this.buckets[a],o=this.index[a];for(let i=0;i<s.length;i++){let l=(i+o)%s.length,u=s[l];if((!t||t(u))&&!this.reused.has(u))return s.splice(l,1),l<o&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,t,r){let a=this.buckets[0];if(a.length)for(let s=0,o=0;;s++){if(s==a.length){if(o)return null;o=1,s=0}let i=a[s];if(!this.reused.has(i)&&(o==0?i.widget.compare(e):i.widget.constructor==e.constructor&&e.updateDOM(i.dom,this.view,i.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,i.widget==e&&i.length==t&&(i.flags&497)==r?(this.reused.set(i,1),i):(this.reused.set(i,2),new To(i.dom,t,e,i.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},cm=class{constructor(e,t,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new um(e),this.text=new lm(e.state.doc),this.builder=new im(this.cache,new Bi(e,e.contentDOM),wt.iter(r)),this.cache.reused.set(t,2),this.old=new sm(t),this.reuseWalker={skip:(o,i,l)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let r=t&&this.getCompositionContext(t.text);for(let a=0,s=0,o=0;;){let i=o<e.length?e[o++]:null,l=i?i.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!o,!i),a=l,s+=u}if(!i)break;t&&i.fromA<=t.range.fromA&&i.toA>=t.range.toA?(this.forward(i.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,r),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,i.toA),this.emit(t.range.toB,i.toB)):(this.forward(i.fromA,i.toA),this.emit(s,i.toB)),s=i.toB,a=i.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,r){let a=ZM(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(o,i,l)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(l-i);else{let u=l>0||i<o.length?To.of(o.widget,this.view,l-i,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(o.isText())this.builder.ensureLine(null),!i&&l==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,a,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(i,l),a,s)),s=a.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof _i)this.cache.add(o);else if(o instanceof ur)this.builder.ensureLine(null),this.builder.addMark(o,a,s),this.cache.reused.set(o,1),s=a.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof ur&&a.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?a.length&&(a.length=s=0):o instanceof ur&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let r=null,a=this.builder,s=-1,o=wt.spans(this.decorations,e,t,{point:(i,l,u,c,d,f)=>{if(u instanceof Ro){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(i).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-i);else{let h=u.widget||(u.block?Gs.block:Gs.inline),p=YM(u),m=this.cache.findWidget(h,l-i,p)||To.of(h,this.view,l-i,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(m)):(a.ensureLine(r),a.addInlineWidget(m,c,d))}r=null}else r=JM(r,u);l>i&&this.text.skip(l-i)},span:(i,l,u,c)=>{for(let d=i;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==i?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=o>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=o}forward(e,t,r=1){t-e<=10?this.old.advance(t-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let t=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=Zt.get(a);if(a==this.view.contentDOM)break;s instanceof ur?t.push(s):s?.isLine()?r=s:s instanceof as||(a.nodeName=="DIV"&&!r?r=new Oi(a,wS):r||t.push(ur.of(new vu({tagName:a.nodeName.toLowerCase(),attributes:MM(a)}),a)))}return r?{line:r,marks:t}:null}};function vk(n,e){let t=r=>{for(let a of r.children)if((e?a.isText():a.length)||t(a))return!0;return!1};return t(n)}function YM(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}var wS={class:"cm-line"};function JM(n,e){let t=e.spec.attributes,r=e.spec.class;return!t&&!r||(n||(n={class:"cm-line"}),t&&Hm(t,n),r&&(n.class+=" "+r)),n}function ZM(n){let e=[];for(let t=n.parents.length;t>1;t--){let r=t==n.parents.length?n.tile:n.parents[t].tile;r instanceof ur&&e.push(r.mark)}return e}function jp(n){let e=Zt.get(n);return e&&e.setDOM(n.cloneNode()),n}var Gs=class extends Ir{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};Gs.inline=new Gs("span");Gs.block=new Gs("div");var qp=new class extends Ir{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Dd=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Xe.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Bi(e,e.contentDOM),this.updateInner([new ua(0,0,0,e.state.doc.length)],null)}update(e){var t;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?a=this.domChanged.newSel.head:!oT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?eT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new ua(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(we.ie||we.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,i=this.blockWrappers;this.updateDeco();let l=rT(o,this.decorations,e.changes);l.length&&(r=ua.extendWithRanges(r,l));let u=aT(i,this.blockWrappers,e.changes);return u.length&&(r=ua.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(t||e.length){let o=this.tile,i=new cm(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Zt.get(t.text)&&i.cache.reused.set(Zt.get(t.text),2),this.tile=i.run(e,t),dm(o,i.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=we.chrome||we.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof gu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let r of t.effects)r.is(pS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,o=!s&&!(this.view.state.facet(rs)||r.tabIndex>-1)&&du(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||t||o))return;let i=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),we.gecko&&l.empty&&!this.hasComposition&&QM(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new Ma(f,0),i=!0}let d=this.view.observer.selectionRange;(i||!d.focusNode||(!hu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!hu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{we.android&&we.chrome&&r.contains(d.focusNode)&&sT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Su(this.view.root);if(f)if(l.empty){if(we.gecko){let h=tT(u.node,u.offset);if(h&&h!=3){let p=(h==1?Zk:Qk)(u.node,u.offset);p&&(u=new Ma(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}o&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new Ma(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new Ma(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&hu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,r=Su(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!t.empty||!t.assoc||!r.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let i=o.posAtStart;if(t.head==i||t.head==i+o.length)return;let l=this.coordsAt(t.head,-1),u=this.coordsAt(t.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);r.collapse(c.node,c.offset),r.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&r.collapse(a,s)}posFromDOM(e,t){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[t];else{let o=ss(e)==0?0:t==0?-1:1;for(;;){let i=e.parentNode;if(i==r.dom)break;o==0&&i.firstChild!=i.lastChild&&(e==i.firstChild?o=-1:o=1),e=i}o<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!Zt.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let o=0,i=a;;o++){let l=r.children[o];if(l.dom==s)return i;i+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+t:a+(t?r.length:0):a}domAtPos(e,t){let{tile:r,offset:a}=this.tile.resolveBlock(e,t);return r.isWidget()?r.domPosFor(a,t):r.domIn(a,t)}inlineDOMNearPos(e,t){let r,a=-1,s=!1,o,i=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!o&&(o=u,i=e-c,l=c>e),c>e&&o)return!0}}),!r&&!o?this.domAtPos(e,t):(s&&o?r=null:l&&r&&(o=null),r&&t<0||!o?r.domIn(a,t):o.domIn(i,t))}coordsAt(e,t,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,t);return a.isWidget()?a.widget instanceof gu?null:a.coordsInWidget(s,t,!0):a.coordsIn(s,t,r)}lineAt(e,t){let{tile:r}=this.tile.resolveBlock(e,t);return r.isLine()?r:null}coordsForChar(e){let{tile:t,offset:r}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function a(s,o){if(s.isComposite())for(let i of s.children){if(i.length>=o){let l=a(i,o);if(l)return l}if(o-=i.length,o<0)break}else if(s.isText()&&o<s.length){let i=Nn(s.text,o);if(i==o)return null;let l=Lu(s.dom,o,i).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(t,r)}measureVisibleLineHeights(e){let t=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,i=-1,l=this.view.textDirection==Wt.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let m=d.children[p],g=f+m.length,x=m.dom.getBoundingClientRect(),{height:w}=x;if(h&&!p&&(u+=x.top-h.top),m instanceof as)g>r&&c(m,f,x);else if(f>=r&&(u>0&&t.push(-u),t.push(w+u),u=0,o)){let y=m.dom.lastChild,C=y?fu(y):[];if(C.length){let k=C[C.length-1],v=l?k.right-x.left:x.right-k.left;v>i&&(i=v,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=g)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?Wt.RTL:Wt.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let i=0,l;for(let u of o.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=fu(u.dom);if(c.length!=1)return;i+=c[0].width,l=c[0].height}if(i)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:i/o.length,textHeight:l}}});if(e)return e;let t=document.createElement("div"),r,a,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=fu(t.firstChild)[0];r=t.getBoundingClientRect().height,a=o&&o.width?o.width/27:7,s=o&&o.height?o.height:r,t.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let r=0,a=0;;a++){let s=a==t.viewports.length?null:t.viewports[a],o=s?s.from-1:this.view.state.doc.length;if(o>r){let i=(t.lineBlockAt(o).bottom-t.lineBlockAt(r).top)/this.view.scaleY;e.push(Xe.replace({widget:new gu(i),block:!0,inclusive:!0,isBlockGap:!0}).range(r,o))}if(!s)break;r=s.to+1}return Xe.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Wd).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(qm).map((s,o)=>{let i=typeof s=="function";return i&&(r=!0),i?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,t.push(wt.join(a))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(gS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(hS))try{if(u(this.view,e.range,e))return!0}catch(c){la(this.view.state,c,"scroll handler")}let{range:t}=e,r=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),a;if(!r)return;!t.empty&&(a=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=bS(this.view),o={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:i,offsetHeight:l}=this.view.scrollDOM;if(FM(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,i),-i),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==Wt.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(t.head,1);if(u){let c=Kk(u.dom);u.dom.scrollIntoView({block:"nearest"}),Xk(c,!1)}}}lineHasWidget(e){let t=r=>r.isWidget()||r.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){dm(this.tile)}};function dm(n,e){let t=e?.get(n);if(t!=1){t==null&&n.destroy();for(let r of n.children)dm(r,e)}}function QM(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function vS(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let r=Zk(t.focusNode,t.focusOffset),a=Qk(t.focusNode,t.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let i=Zt.get(a.node);if(!i||i.isText()&&i.text!=a.node.nodeValue)s=a;else if(n.docView.lastCompositionAfterCursor){let l=Zt.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(n.docView.lastCompositionAfterCursor=s!=r,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function eT(n,e,t){let r=vS(n,t);if(!r)return null;let{node:a,from:s,to:o}=r,i=a.nodeValue;if(/[\n\r]/.test(i)||n.state.doc.sliceString(r.from,r.to)!=i)return null;let l=e.invertedDesc;return{range:new ua(l.mapPos(s),l.mapPos(o),s,o),text:a}}function tT(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}var nT=class{constructor(){this.changes=[]}compareRange(e,t){Di(e,t,this.changes)}comparePoint(e,t){Di(e,t,this.changes)}boundChange(e){Di(e,e,this.changes)}};function rT(n,e,t){let r=new nT;return wt.compare(n,e,t,r),r.changes}var fm=class{constructor(){this.changes=[]}compareRange(e,t){Di(e,t,this.changes)}comparePoint(){}boundChange(e){Di(e,e,this.changes)}};function aT(n,e,t){let r=new fm;return wt.compare(n,e,t,r),r.changes}function sT(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function oT(n,e){let t=!1;return e&&n.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(t=!0)}),t}var gu=class extends Ir{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function iT(n,e,t=1){let r=n.charCategorizer(e),a=n.doc.lineAt(e),s=e-a.from;if(a.length==0)return se.cursor(e);s==0?t=1:s==a.length&&(t=-1);let o=s,i=s;t<0?o=Nn(a.text,s,!1):i=Nn(a.text,s);let l=r(a.text.slice(o,i));for(;o>0;){let u=Nn(a.text,o,!1);if(r(a.text.slice(u,o))!=l)break;o=u}for(;i<a.length;){let u=Nn(a.text,i);if(r(a.text.slice(i,u))!=l)break;i=u}return se.undirectionalRange(o+a.from,i+a.from)}function lT(n,e,t,r,a){let s=Math.round((r-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let i=n.viewState.heightOracle.textHeight,l=Math.floor((a-t.top-(n.defaultLineHeight-i)*.5)/i);s+=l*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+lk(o,s,n.state.tabSize)}function hm(n,e,t){let r=n.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==Bn.Text&&(a.type!=s.type||(t<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function uT(n,e,t,r){let a=hm(n,e.head,e.assoc||-1),s=!r||a.type!=Bn.Text||!(n.lineWrapping||a.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let o=n.dom.getBoundingClientRect(),i=n.textDirectionAt(a.from),l=n.posAtCoords({x:t==(i==Wt.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(l!=null)return se.cursor(l,t?-1:1)}return se.cursor(t?a.to:a.from,t?-1:1)}function kk(n,e,t,r){let a=n.state.doc.lineAt(e.head),s=n.bidiSpans(a),o=n.textDirectionAt(a.from);for(let i=e,l=null;;){let u=jM(a,s,o,i,t),c=aS;if(!u){if(a.number==(t?n.state.doc.lines:1))return i;c=`
|
|
39
|
-
`,a=n.state.doc.line(a.number+(t?1:-1)),s=n.bidiSpans(a),u=t?se.cursor(a.from,-1):se.cursor(a.to,1)}if(l){if(!l(c))return i}else{if(!r)return u;l=r(c)}i=u}}function cT(n,e,t){let r=n.state.charCategorizer(e),a=r(t);return s=>{let o=r(s);return a==oa.Space&&(a=o),a==o}}function dT(n,e,t,r){let a=e.head,s=t?1:-1;if(a==(t?n.state.doc.length:0))return se.cursor(a,e.assoc);let o=e.goalColumn,i,l=n.contentDOM.getBoundingClientRect(),u=n.coordsAtPos(a,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=n.documentTop;if(u)o==null&&(o=u.left-l.left),i=s<0?u.top:u.bottom;else{let p=n.viewState.lineBlockAt(a);o==null&&(o=Math.min(l.right-l.left,n.defaultCharacterWidth*(a-p.from))),i=(s<0?p.top:p.bottom)+c}let d=l.left+o,f=n.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let m=i+(h+p)*s,g=pm(n,{x:d,y:m},!1,s);if(t?m>l.bottom:m<l.top)return se.cursor(g.pos,g.assoc);let x=n.coordsAtPos(g.pos,g.assoc),w=x?(x.top+x.bottom)/2:0;if(!x||(t?w>i:w<i))return se.cursor(g.pos,g.assoc,void 0,o)}}function xu(n,e,t){for(;;){let r=0;for(let a of n)a.between(e-1,e+1,(s,o,i)=>{if(e>s&&e<o){let l=r||t||(e-s<o-e?-1:1);e=l<0?s:o,r=l}});if(!r)return e}}function kS(n,e){let t=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let o=xu(n,a.from,0);o!=a.from&&(s=se.cursor(o,-1))}else{let o=xu(n,a.from,-1),i=xu(n,a.to,1);(o!=a.from||i!=a.to)&&(a.undirectional?s=se.undirectionalRange(a.from,a.to):s=se.range(a.from==a.anchor?o:i,a.from==a.head?o:i))}s&&(t||(t=e.ranges.slice()),t[r]=s)}return t?se.create(t,e.mainIndex):e}function Vp(n,e,t){let r=xu(n.state.facet(Iu).map(a=>a(n)),t.from,e.head>t.from?-1:1);return r==t.from?t:se.cursor(r,r<t.from?1:-1)}var qr=class{constructor(e,t){this.pos=e,this.assoc=t}};function pm(n,e,t,r){let a=n.contentDOM.getBoundingClientRect(),s=a.top+n.viewState.paddingTop,{x:o,y:i}=e,l=i-s,u;for(;;){if(l<0)return new qr(0,1);if(l>n.viewState.docHeight)return new qr(n.state.doc.length,-1);if(u=n.elementAtHeight(l),r==null)break;if(u.type==Bn.Text){if(r<0?u.to<n.viewport.from:u.from>n.viewport.to)break;let f=n.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=n.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(n.viewport.from>=u.to||n.viewport.to<=u.from){if(t)return null;if(u.type==Bn.Text){let d=lT(n,a,u,o,i);return new qr(d,d==u.from?1:-1)}}if(u.type!=Bn.Text)return l<(u.top+u.bottom)/2?new qr(u.from,1):new qr(u.to,-1);let c=n.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=n.docView.lineAt(u.from,-2)),new mm(n,o,i,n.textDirectionAt(u.from)).scanTile(c,u.from)}var mm=class{constructor(e,t,r,a){this.view=e,this.x=t,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Vr.find(a,e-r.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Vr.find(a,e-r.from,-1,t)].dir}bidiIn(e,t){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<t)}scan(e,t,r=!1){let a=0,s=e.length-1,o=new Set,i=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,m=a+s>>1;t:if(o.has(m)){for(let w=1;w<p;w++){let y=m+w;if(y>=s&&(y-=p),!o.has(y)){m=y;break t}}break e}o.add(m);let g=t(m),x=0;if(g)for(let w=0;w<g.length;w++){let y=g[w];if(!(y.width==0&&g.length>1))if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!u||u.top>y.top)&&(u=y),x=-1;else{let C=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,k=Math.abs(C);k<d&&(c=m,d=k,f=y),C&&(x=C<0==(this.baseDir==Wt.LTR)?-1:1)}}x==-1&&(!i||this.baseDirAt(e[m],1))?s=m:x==1&&(!i||this.baseDirAt(e[m+1],-1))&&(a=m+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(d&&!r){let{top:p,bottom:m}=f;if(l&&l.bottom>(p+p+m)/3)return this.y=l.bottom-1,this.scan(e,t,!0);if(u&&u.top<(p+m+m)/3)return this.y=u.top+1,this.scan(e,t,!0)}let h=(i?this.dirAt(e[c],1):this.baseDir)==Wt.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,t){let r=[];for(let s=0;s<e.length;s=Nn(e.text,s))r.push(t+s);r.push(t+e.length);let a=this.scan(r,s=>{let o=r[s]-t,i=r[s+1]-t;return Lu(e.dom,o,i).getClientRects()});return a.after?new qr(r[a.i+1],-1):new qr(r[a.i],1)}scanTile(e,t){if(!e.length)return new qr(t,1);if(e.children.length==1){let i=e.children[0];if(i.isText())return this.scanText(i,t);if(i.isComposite())return this.scanTile(i,t)}let r=[t];for(let i=0,l=t;i<e.children.length;i++)r.push(l+=e.children[i].length);let a=this.scan(r,i=>{let l=e.children[i];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Lu(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],o=r[a.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):a.after?new qr(r[a.i+1],-1):new qr(o,1)}},Ni="\uFFFF",gm=class{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Ct.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Ni}readRange(e,t){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let o=Zt.get(a),i=a.nextSibling;if(i==t){o?.breakAfter&&!i&&r!=this.view.contentDOM&&this.lineBreak();break}let l=Zt.get(i);(o&&l?o.breakAfter:(o?o.breakAfter:Rd(a))||Rd(i)&&(a.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!hT(i,t)&&this.lineBreak(),a=i}return this.findPointBefore(r,t),this}readTextNode(e){let t=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,t.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,i;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,r),o=this.lineSeparator.length):(i=a.exec(t))&&(s=i.index,o=i[0].length),this.append(t.slice(r,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=o-1);r=s+o}}readNode(e){let t=Zt.get(e),r=t&&t.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==t&&(r.pos=this.text.length)}findPointInside(e,t){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(fT(e,r.node,r.offset)?t:0))}};function fT(n,e,t){for(;;){if(!e||t<ss(e))return!1;if(e==n)return!0;t=Us(e)+1,e=e.parentNode}}function hT(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let r=Zt.get(n);if(!r?.isWidget())return!1;r&&(t||(t=[])).push(r)}if(t)for(let r of t){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Fd=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},xm=class{constructor(e,t,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView,i=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=SS(e.docView.tile,t,r,0))){let l=s||o?[]:mT(e),u=new gm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=gT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Qp(e.contentDOM,l.focusNode)?i.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Qp(e.contentDOM,l.anchorNode)?i.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((we.ios||we.chrome)&&u!=c&&Math.min(u,c)<=i.main.from&&Math.max(u,c)>=i.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,m=d.to-h;(p==0||p==1||f==0)&&(m==0||m==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&i.ranges.length>1)this.newSel=i.replaceRange(se.range(c,u));else if(e.lineWrapping&&c==u&&!(i.main.empty&&i.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=se.create([se.cursor(u,h)])}else this.newSel=se.single(c,u)}}};function SS(n,e,t,r){if(n.isComposite()){let a=-1,s=-1,o=-1,i=-1;for(let l=0,u=r,c=r;l<n.children.length;l++){let d=n.children[l],f=u+d.length;if(u<e&&f>t)return SS(d,e,t,u);if(f>=e&&a==-1&&(a=l,s=u),u>t&&d.dom.parentNode==n.dom){o=l,i=c;break}c=f,u=f+d.breakAfter}return{from:s,to:i<0?r+n.length:i,startDOM:(a?n.children[a-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:r,to:r+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function CS(n,e){let t,{newSel:r}=e,{state:a}=n,s=a.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:i,to:l}=e.bounds,u=s.from,c=null;(o===8||we.android&&e.text.length<l-i)&&(u=s.to,c="end");let d=a.doc.sliceString(i,l,Ni),f,h;!s.empty&&s.from>=i&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-i)==e.text.slice(0,s.from-i)&&d.slice(s.to-i)==e.text.slice(f=e.text.length-(d.length-(s.to-i)))?t={from:s.from,to:s.to,insert:ct.of(e.text.slice(s.from-i,f).split(Ni))}:(h=LS(d,e.text,u-i,c))&&(we.chrome&&o==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Ni+Ni&&h.toB--,t={from:i+h.from,to:i+h.toA,insert:ct.of(e.text.slice(h.from,h.toB).split(Ni))})}else r&&(!n.hasFocus&&a.facet(rs)||Ed(r,s))&&(r=null);if(!t&&!r)return!1;if((we.mac||we.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(r&&t.insert.length==2&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:t.from,to:t.to,insert:ct.of([t.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:a.toText(n.inputState.insertingText)}:we.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
40
|
-
`&&n.lineWrapping&&(r&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:s.from,to:s.to,insert:ct.of([" "])}),t)return Vm(n,t,r,o);if(r&&!Ed(r,s)){let i=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(i=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=kS(a.facet(Iu).map(u=>u(n)),r))),n.dispatch({selection:r,scrollIntoView:i,userEvent:l}),!0}else return!1}function Vm(n,e,t,r=-1){if(we.ios&&n.inputState.flushIOSKey(e))return!0;let a=n.state.selection.main;if(we.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&n.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Fi(n.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Fi(n.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Fi(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,i=()=>o||(o=pT(n,e,t));return n.state.facet(uS).some(l=>l(n,e.from,e.to,s,i))||n.dispatch(i()),!0}function pT(n,e,t){let r,a=n.state,s=a.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=xu(a.facet(Iu).map(d=>d(n)),u,l);e.from==c&&(o=c)}if(o>-1)r={changes:e,selection:se.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+u))}else{let l=a.changes(e),u=t&&t.main.to<=l.newLength?t.main:void 0;if(a.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=n.state.sliceDoc(e.from,e.to),d,f=t&&vS(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=n.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let m=p.to-h,g=m-c.length;if(n.state.sliceDoc(g,m)!=c||m>=d.from&&g<=d.to)return{range:p};let x=a.changes({from:g,to:m,insert:e.insert}),w=p.to-s.to;return{changes:x,range:u?se.range(Math.max(0,u.anchor+w),Math.max(0,u.head+w)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let i="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,i+=".compose",n.inputState.compositionFirstChange&&(i+=".start",n.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:i,scrollIntoView:!0})}function LS(n,e,t,r){let a=Math.min(n.length,e.length),s=0;for(;s<a&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&n.length==e.length)return null;let o=n.length,i=e.length;for(;o>0&&i>0&&n.charCodeAt(o-1)==e.charCodeAt(i-1);)o--,i--;if(r=="end"){let l=Math.max(0,s-Math.min(o,i));t-=o+l-s}if(o<s&&n.length<e.length){let l=t<=s&&t>=o?s-t:0;s-=l,i=s+(i-o),o=s}else if(i<s){let l=t<=s&&t>=i?s-t:0;s-=l,o=s+(o-i),i=s}return{from:s,toA:o,toB:i}}function mT(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new Fd(t,r)),(a!=t||s!=r)&&e.push(new Fd(a,s))),e}function gT(n,e){if(n.length==0)return null;let t=n[0].pos,r=n.length==2?n[1].pos:t;return t<0||r<0?null:t==r?se.create([se.cursor(r+e,-1)]):se.single(t+e,r+e)}function Ed(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}var ym=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,we.safari&&e.contentDOM.addEventListener("input",()=>null),we.gecko&&MT(e.contentDOM.ownerDocument)}handleEvent(e){!CT(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,t);for(let a of r.handlers){if(t.defaultPrevented)break;if(a(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=yT(e),r=this.handlers,a=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,i=r[s];i&&o!=!i.handlers.length&&(a.removeEventListener(s,this.handleEvent),i=null),i||a.addEventListener(s,this.handleEvent,{passive:o})}for(let s in r)s!="scroll"&&!t[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&AS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),we.android&&we.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(we.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(IS.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||bT.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&we.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&xT(this.view.win)&&(t.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Fi(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:we.safari&&!we.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function xT(n){return n.visualViewport?n.visualViewport.height*n.visualViewport.scale/n.document.documentElement.clientHeight<.85:!1}function Sk(n,e){return(t,r)=>{try{return e.call(n,r,t)}catch(a){la(t.state,a)}}}function yT(n){let e=Object.create(null);function t(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of n){let a=r.spec,s=a&&a.plugin.domEventHandlers,o=a&&a.plugin.domEventObservers;if(s)for(let i in s){let l=s[i];l&&t(i).handlers.push(Sk(r.value,l))}if(o)for(let i in o){let l=o[i];l&&t(i).observers.push(Sk(r.value,l))}}for(let r in ca)t(r).handlers.push(ca[r]);for(let r in tr)t(r).observers.push(tr[r]);return e}var IS=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],bT="dthko",AS=[16,17,18,20,91,92,224,225],bd=6;function wd(n){return Math.max(0,n)*.7+8}function wT(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}var bm=class{constructor(e,t,r,a){this.view=e,this.startEvent=t,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=$k(e.contentDOM),this.atoms=e.state.facet(Iu).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Ct.allowMultipleSelections)&&vT(e,t),this.dragging=ST(e,t)&&RS(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&wT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,r=0,a=0,s=0,o=this.view.win.innerWidth,i=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:i}=this.scrollParents.y.getBoundingClientRect());let l=bS(this.view);e.clientX-l.left<=a+bd?t=-wd(a-e.clientX):e.clientX+l.right>=o-bd&&(t=wd(e.clientX-o)),e.clientY-l.top<=s+bd?r=-wd(s-e.clientY):e.clientY+l.bottom>=i-bd&&(r=wd(e.clientY-i)),this.setScrollSpeed(t,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,r=kS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function vT(n,e){let t=n.state.facet(sS);return t.length?t[0](e):we.mac?e.metaKey:e.ctrlKey}function kT(n,e){let t=n.state.facet(oS);return t.length?t[0](e):we.mac?!e.altKey:!e.ctrlKey}function ST(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let r=Su(n.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let o=a[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function CT(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,r;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(r=Zt.get(t))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var ca=Object.create(null),tr=Object.create(null),PS=we.ie&&we.ie_version<15||we.ios&&we.webkit_version<604;function LT(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),NS(n,t.value)},50)}function jd(n,e,t){for(let r of n.facet(e))t=r(t,n);return t}function NS(n,e){e=jd(n.state,zm,e);let{state:t}=n,r,a=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(wm!=null&&t.selection.ranges.every(l=>l.empty)&&wm==s.toString()){let l=-1;r=t.changeByRange(u=>{let c=t.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=t.toText((o?s.line(a++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:d},range:se.cursor(u.from+d.length,-1)}})}else o?r=t.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:se.cursor(l.from+u.length,-1)}}):r=t.replaceSelection(s);n.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}tr.scroll=n=>{let e=n.inputState;e.lastScrollTop=n.scrollDOM.scrollTop,e.lastScrollLeft=n.scrollDOM.scrollLeft,we.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};tr.wheel=tr.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};ca.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);tr.touchstart=(n,e)=>{let t=n.inputState,r=e.targetTouches[0];t.touchActive=!0,t.lastTouchTime=Date.now(),r&&(t.lastTouchX=r.clientX,t.lastTouchY=r.clientY),t.setSelectionOrigin("select.pointer")};tr.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};tr.touchend=(n,e)=>{n.inputState.touchActive=!1};ca.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let r of n.state.facet(iS))if(t=r(n,e),t)break;if(!t&&e.button==0&&(t=AT(n,e)),t){let r=!n.hasFocus;n.inputState.startMouseSelection(new bm(n,e,t,r)),r&&n.observer.ignore(()=>{Yk(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let a=n.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Ck(n,e,t,r){if(r==1)return se.cursor(e,t);if(r==2)return iT(n.state,e,t);{let a=n.docView.lineAt(e,t),s=n.state.doc.lineAt(a?a.posAtEnd:e),o=a?a.posAtStart:s.from,i=a?a.posAtEnd:s.to;return i<n.state.doc.length&&i==s.to&&i++,se.undirectionalRange(o,i)}}var IT=we.ie&&we.ie_version<=11,Lk=null,Ik=0,Ak=0;function RS(n){if(!IT)return n.detail;let e=Lk,t=Ak;return Lk=n,Ak=Date.now(),Ik=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Ik+1)%3:1}function AT(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=RS(e),a=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),a=a.map(s.changes))},get(s,o,i){let l=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Ck(n,l.pos,l.assoc,r);if(t.pos!=l.pos&&!o){let d=Ck(n,t.pos,t.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?se.range(f,h,c.assoc):se.range(h,f,c.assoc)}return o?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):i&&r==1&&a.ranges.length>1&&(u=PT(a,l.pos))?u:i?a.addRange(c):se.create([c])}}}function PT(n,e){for(let t=0;t<n.ranges.length;t++){let{from:r,to:a}=n.ranges[t];if(r<=e&&a>=e)return se.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}ca.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let a=n.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,o=s+a.length;(s>=t.to||o<=t.from)&&(t=se.undirectionalRange(s,o))}}let{inputState:r}=n;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",jd(n.state,Wm,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};ca.dragend=n=>(n.inputState.draggedContent=null,!1);function Pk(n,e,t,r){if(t=jd(n.state,zm,t),!t)return;let a=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,o=r&&s&&kT(n,e)?{from:s.from,to:s.to}:null,i={from:a,insert:t},l=n.state.changes(o?[o,i]:i);n.focus(),n.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}ca.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let r=Array(t.length),a=0,s=()=>{++a==t.length&&Pk(n,e,r.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let i=new FileReader;i.onerror=s,i.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(i.result)||(r[o]=i.result),s()},i.readAsText(t[o])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Pk(n,e,r,!0),!0}return!1};ca.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=PS?null:e.clipboardData;return t?(NS(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(LT(n),!1)};function NT(n,e){let t=n.dom.parentNode;if(!t)return;let r=t.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),n.focus()},50)}function RT(n){let e=[],t=[],r=!1;for(let a of n.selection.ranges)a.empty||(e.push(n.sliceDoc(a.from,a.to)),t.push(a));if(!e.length){let a=-1;for(let{from:s}of n.selection.ranges){let o=n.doc.lineAt(s);o.number>a&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),a=o.number}r=!0}return{text:jd(n,Wm,e.join(n.lineBreak)),ranges:t,linewise:r}}var wm=null;ca.copy=ca.cut=(n,e)=>{if(!du(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:r,linewise:a}=RT(n.state);if(!t&&!a)return!1;wm=a?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=PS?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(NT(n,t),!1)};var MS=Wr.define();function TS(n,e){let t=[];for(let r of n.facet(cS)){let a=r(n,e);a&&t.push(a)}return t.length?n.update({effects:t,annotations:MS.of(!0)}):null}function DS(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=TS(n.state,e);t?n.dispatch(t):n.update([])}},10)}tr.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),DS(n)};tr.blur=n=>{n.observer.clearSelectionRange(),DS(n)};tr.compositionstart=tr.compositionupdate=n=>{if(!n.observer.editContext&&(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0)){let{main:e}=n.state.selection;!e.empty&&n.lineBlockAt(e.from).from!=n.lineBlockAt(e.to).from&&n.dispatch({changes:n.state.selection.ranges.filter(t=>!t.empty).map(t=>({from:t.from,to:t.to})),userEvent:"input"}),n.inputState.composing=0}};tr.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,we.chrome&&we.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};tr.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};ca.beforeinput=(n,e)=>{var t,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let i=o[0],l=n.posAtDOM(i.startContainer,i.startOffset),u=n.posAtDOM(i.endContainer,i.endOffset);return Vm(n,{from:l,to:u,insert:n.state.toText(s)},null),!0}}let a;if(we.chrome&&we.android&&(a=IS.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return we.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),we.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>tr.compositionend(n,e),20),!1};var Nk=new Set;function MT(n){Nk.has(n)||(Nk.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}var Rk=["pre-wrap","normal","pre-line","break-spaces"],Hi=!1;function Mk(){Hi=!1}var vm=class{constructor(e){this.lineWrapping=e,this.doc=ct.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let r=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((t-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Rk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(t=!0,this.heightSamples[Math.floor(a*10)]=!0)}return t}refresh(e,t,r,a,s,o){let i=Rk.indexOf(e)>-1,l=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=i;if(this.lineWrapping=i,this.lineHeight=t,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<o.length;u++){let c=o[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},km=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},ia=class n{constructor(e,t,r,a,s){this.from=e,this.length=t,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?Bn.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Ro?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new n(this.from,this.length+e.length,this.top,this.height+e.height,t)}},zt=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(zt||(zt={})),Ld=.001,Lr=class n{constructor(e,t,r=2){this.length=e,this.height=t,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Ld&&(Hi=!0),this.height=e)}replace(e,t,r){return n.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,r,a){let s=this,o=r.doc;for(let i=a.length-1;i>=0;i--){let{fromA:l,toA:u,fromB:c,toB:d}=a[i],f=s.lineAt(l,zt.ByPosNoHeight,r.setDoc(t),0,0),h=f.to>=u?f:s.lineAt(u,zt.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;i>0&&f.from<=a[i-1].toA;)l=a[i-1].fromA,c=a[i-1].fromB,i--,l<f.from&&(f=s.lineAt(l,zt.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=Cm.build(r.setDoc(o),e,c,d);s=Bd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new jr(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,r=e.length,a=0,s=0;for(;;)if(t==r)if(a>s*2){let i=e[t-1];i.break?e.splice(--t,1,i.left,null,i.right):e.splice(--t,1,i.left,i.right),r+=1+i.break,a-=i.size}else if(s>a*2){let i=e[r];i.break?e.splice(r,1,i.left,null,i.right):e.splice(r,1,i.left,i.right),r+=2+i.break,s-=i.size}else break;else if(a<s){let i=e[t++];i&&(a+=i.size)}else{let i=e[--r];i&&(s+=i.size)}let o=!1;return e[t-1]==null?(o=!0,t--):e[t]==null&&(o=!0,r++),new Sm(n.of(e.slice(0,t)),o,n.of(e.slice(r)))}};function Bd(n,e){return n==e?n:(n.constructor!=e.constructor&&(Hi=!0),e)}Lr.prototype.size=1;var TT=Xe.replace({}),Od=class extends Lr{constructor(e,t,r){super(e,t),this.deco=r,this.spaceAbove=0}mainBlock(e,t){return new ia(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new ia(a,0,r,this.spaceAbove,TT):this.mainBlock(r,a)}lineAt(e,t,r,a,s){let o=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(o):o}forEachLine(e,t,r,a,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,zt.ByPos,r,a,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},jr=class n extends Od{constructor(e,t,r){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,t){return new ia(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,r){let a=r[0];return r.length==1&&(a instanceof n||a instanceof Hs&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof Hs?a=new n(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Lr.of(r)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Hs=class n extends Lr{constructor(e){super(e,0)}heightMetrics(e,t){let r=e.doc.lineAt(t).number,a=e.doc.lineAt(t+this.length).number,s=a-r+1,o,i=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);o=l/s,this.length>s+1&&(i=(this.height-l)/(this.length-s-1))}else o=this.height/s;return{firstLine:r,lastLine:a,perLine:o,perChar:i}}blockAt(e,t,r,a){let{firstLine:s,lastLine:o,perLine:i,perChar:l}=this.heightMetrics(t,a);if(t.lineWrapping){let u=a+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=t.doc.lineAt(u),d=i+c.length*l,f=Math.max(r,e-d/2);return new ia(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(o-s,Math.floor((e-r)/i))),{from:c,length:d}=t.doc.line(s+u);return new ia(c,d,r+i*u,i,0)}}lineAt(e,t,r,a,s){if(t==zt.ByHeight)return this.blockAt(e,r,a,s);if(t==zt.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new ia(h,p-h,0,0,0)}let{firstLine:o,perLine:i,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=i+u.length*l,d=u.number-o,f=a+i*d+l*(u.from-s-d);return new ia(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,t,r,a,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:i,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=t;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-i;d+=l*p+u*(e-s-p)}let h=l+u*f.length;o(new ia(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,t,r){let a=this.length-t;if(a>0){let s=r[r.length-1];s instanceof n?r[r.length-1]=new n(s.length+a):r.push(null,new n(a-1))}if(e>0){let s=r[0];s instanceof n?r[0]=new n(e+s.length):r.unshift(new n(e-1),null)}return Lr.of(r)}decomposeLeft(e,t){t.push(new n(e-1),null)}decomposeRight(e,t){t.push(null,new n(this.length-e-1))}updateHeight(e,t=0,r=!1,a){let s=t+this.length;if(a&&a.from<=t+this.length&&a.more){let o=[],i=Math.max(t,a.from),l=-1;for(a.from>t&&o.push(new n(a.from-t-1).updateHeight(e,t));i<=s&&a.more;){let c=e.doc.lineAt(i).length;o.length&&o.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Ld&&(l=-2);let h=new jr(c,d,f);h.outdated=!1,o.push(h),i+=c+1}i<=s&&o.push(null,new n(s-i).updateHeight(e,i));let u=Lr.of(o);return(l<0||Math.abs(u.height-this.height)>=Ld||Math.abs(l-this.heightMetrics(e,t).perLine)>=Ld)&&(Hi=!0),Bd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Sm=class extends Lr{constructor(e,t,r){super(e.length+(t?1:0)+r.length,e.height+r.height,(t?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,t,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,t,r,a):this.right.blockAt(e,t,s,a+this.left.length+this.break)}lineAt(e,t,r,a,s){let o=a+this.left.height,i=s+this.left.length+this.break,l=t==zt.ByHeight?e<o:e<i,u=l?this.left.lineAt(e,t,r,a,s):this.right.lineAt(e,t,r,o,i);if(this.break||(l?u.to<i:u.from>i))return u;let c=t==zt.ByPosNoHeight?zt.ByPosNoHeight:zt.ByPos;return l?u.join(this.right.lineAt(i,c,r,o,i)):this.left.lineAt(i,c,r,a,s).join(u)}forEachLine(e,t,r,a,s,o){let i=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,t,r,a,s,o),t>=l&&this.right.forEachLine(e,t,r,i,l,o);else{let u=this.lineAt(l,zt.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(t,u.from-1),r,a,s,o),u.to>=e&&u.from<=t&&o(u),t>u.to&&this.right.forEachLine(Math.max(e,u.to+1),t,r,i,l,o)}}replace(e,t,r){let a=this.left.length+this.break;if(t<a)return this.balanced(this.left.replace(e,t,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,t-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let i of r)s.push(i);if(e>0&&Tk(s,o-1),t<this.length){let i=s.length;this.decomposeRight(t,s),Tk(s,i)}return Lr.of(s)}decomposeLeft(e,t){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(r++,e>=r&&t.push(null)),e>r&&this.right.decomposeLeft(e-r,t)}decomposeRight(e,t){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,t);e<r&&this.left.decomposeRight(e,t),this.break&&e<a&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Lr.of(this.break?[e,null,t]:[e,t]):(this.left=Bd(this.left,e),this.right=Bd(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,r=!1,a){let{left:s,right:o}=this,i=t+s.length+this.break,l=null;return a&&a.from<=t+s.length&&a.more?l=s=s.updateHeight(e,t,r,a):s.updateHeight(e,t,r),a&&a.from<=i+o.length&&a.more?l=o=o.updateHeight(e,i,r,a):o.updateHeight(e,i,r),l?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Tk(n,e){let t,r;n[e]==null&&(t=n[e-1])instanceof Hs&&(r=n[e+1])instanceof Hs&&n.splice(e-1,3,new Hs(t.length+1+r.length))}var DT=5,Cm=class n{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let r=Math.min(t,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof jr?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new jr(r-this.pos,-1,0)),this.writtenTo=r,t>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,r){if(e<t||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let o=t-e;r.block?this.addBlock(new Od(o,a,r)):(o||s||a>=DT)&&this.addLineDeco(a,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new jr(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let r=new Hs(t-e);return this.oracle.doc.lineAt(e).to==t&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof jr)return e;let t=new jr(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=t,this.writtenTo=this.pos=this.pos+r}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof jr)&&!this.isCovered?this.nodes.push(new jr(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof jr&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,t,r,a){let s=new n(r,e);return wt.spans(t,r,a,s,0),s.finish(r)}};function FT(n,e,t){let r=new Lm;return wt.compare(n,e,t,r,0),r.changes}var Lm=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,r,a){(e<t||r&&r.heightRelevant||a&&a.heightRelevant)&&Di(e,t,this.changes,5)}};function ET(n,e){let t=n.getBoundingClientRect(),r=n.ownerDocument,a=r.defaultView||window,s=Math.max(0,t.left),o=Math.min(a.innerWidth,t.right),i=Math.max(0,t.top),l=Math.min(a.innerHeight,t.bottom);for(let u=n.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),i=Math.max(i,f.top),l=Math.min(u==n.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:i-(t.top+e),bottom:Math.max(i,l)-(t.top+e)}}function BT(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function OT(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var yu=class{constructor(e,t,r,a){this.from=e,this.to=t,this.size=r,this.displaySize=a}static same(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=t[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,t){return Xe.replace({widget:new Im(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},Im=class extends Ir{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},_d=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Dk,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Wt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=t.facet(jm).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new vm(r),this.stateDeco=Fk(t),this.heightMap=Lr.empty().applyChanges(this.stateDeco,ct.empty,this.heightOracle.setDoc(t.doc),[new ua(0,0,0,t.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Xe.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let r=0;r<=1;r++){let a=r?t.head:t.anchor;if(!e.some(({from:s,to:o})=>a>=s&&a<=o)){let{from:s,to:o}=this.lineBlockAt(a);e.push(new Mi(s,o))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Dk:new Am(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(cu(e,this.scaler))})}update(e,t=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Fk(this.state);let a=e.changedRanges,s=ua.extendWithRanges(a,FT(r,this.stateDeco,e?e.changes:Rn.empty(this.state.doc.length))),o=this.heightMap.height,i=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Mk(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||Hi)&&(e.flags|=2),i?(this.scrollAnchorPos=e.changes.mapPos(i.from,-1),this.scrollAnchorHeight=i.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<l.from||t.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(fS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,r=window.getComputedStyle(t),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Wt.RTL:Wt.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",i=t.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=i.height;this.contentDOMHeight=i.height,this.mustMeasureContent=!1;let u=0,c=0;if(i.width&&i.height){let{scaleX:k,scaleY:v}=Vk(t,i);(k>.005&&Math.abs(this.scaleX-k)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=k,this.scaleY=v,u|=16,o=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=$k(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Jk(this.scrollParent||e.win);let m=(this.printing?OT:ET)(t,this.paddingTop),g=m.top-this.pixelViewport.top,x=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(l=!0)),!this.inView&&!this.scrollTarget&&!BT(e.dom))return 0;let y=i.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=i.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let k=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(k)&&(o=!0),o||a.lineWrapping&&Math.abs(y-this.contentDOMWidth)>a.charWidth){let{lineHeight:v,charWidth:b,textHeight:P}=e.docView.measureTextSize();o=v>0&&a.refresh(s,v,b,P,Math.max(5,y/b),k),o&&(e.docView.minWidth=0,u|=16)}g>0&&x>0?c=Math.max(g,x):g<0&&x<0&&(c=Math.min(g,x)),Mk();for(let v of this.viewports){let b=v.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(v);this.heightMap=(o?Lr.empty().applyChanges(this.stateDeco,ct.empty,this.heightOracle,[new ua(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,o,new km(v.from,b))}Hi&&(u|=2)}let C=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return C&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:i}=this,l=new Mi(a.lineAt(o-r*1e3,zt.ByHeight,s,0,0).from,a.lineAt(i+(1-r)*1e3,zt.ByHeight,s,0,0).to);if(t){let{head:u}=t.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,zt.ByPos,s,0,0),f;t.y=="center"?f=(d.top+d.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Mi(a.lineAt(f-1e3/2,zt.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,zt.ByHeight,s,0,0).to)}}return l}mapViewport(e,t){let r=t.mapPos(e.from,-1),a=t.mapPos(e.to,1);return new Mi(this.heightMap.lineAt(r,zt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,zt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,zt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,zt.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:i}=this;return(e==0||a<=o-Math.max(10,Math.min(-r,250)))&&(t==this.state.doc.length||s>=i+Math.max(10,Math.min(r,250)))&&a>o-2*1e3&&s<i+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let r=[];for(let a of e)t.touchesRange(a.from,a.to)||r.push(new yu(t.mapPos(a.from),t.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,t){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,o=a<<1;if(this.defaultTextDirection!=Wt.LTR&&!r)return[];let i=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let x of m)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let g=HT(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!m.some(w=>x.from<w&&x.to>w));if(!g){if(d<f.to&&t&&r&&t.visibleRanges.some(y=>y.from<=d&&y.to>=d)){let y=t.moveToLineBoundary(se.cursor(d),!1,!0).head;y>c&&(d=y)}let x=this.gapSize(f,c,d,h),w=r||x<2e6?x:2e6;g=new yu(c,d,x,w)}i.push(g)},u=c=>{if(c.length<o||c.type!=Bn.Text)return;let d=_T(c.from,c.to,this.stateDeco);if(d.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let m=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,x;if(f!=null){let w=kd(d,f),y=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=w-y,x=w+y}else g=(this.visibleTop-c.top-m)/c.height,x=(this.visibleBottom-c.top+m)/c.height;h=vd(d,g),p=vd(d,x)}else{let m=d.total*this.heightOracle.charWidth,g=a*this.heightOracle.charWidth,x=0;if(m>2e6)for(let v of e)v.from>=c.from&&v.from<c.to&&v.size!=v.displaySize&&v.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=v.size-v.displaySize);let w=this.pixelViewport.left+x,y=this.pixelViewport.right+x,C,k;if(f!=null){let v=kd(d,f),b=((y-w)/2+g)/m;C=v-b,k=v+b}else C=(w-g)/m,k=(y+g)/m;h=vd(d,C),p=vd(d,k)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return i}gapSize(e,t,r,a){let s=kd(a,r)-kd(a,t);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){yu.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Xe.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let r=[];wt.spans(t,this.viewport.from,this.viewport.to,{span(s,o){r.push({from:s,to:o})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let o=this.visibleRanges[s],i=r[s];(o.from!=i.from||o.to!=i.to)&&(a|=4,e&&e.mapPos(o.from,-1)==i.from&&e.mapPos(o.to,1)==i.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||cu(this.heightMap.lineAt(e,zt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||cu(this.heightMap.lineAt(this.scaler.fromDOM(e),zt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return cu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Mi=class{constructor(e,t){this.from=e,this.to=t}};function _T(n,e,t){let r=[],a=n,s=0;return wt.spans(t,n,e,{span(){},point(o,i){o>a&&(r.push({from:a,to:o}),s+=o-a),a=i}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function vd({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let r=Math.floor(n*t);for(let a=0;;a++){let{from:s,to:o}=e[a],i=o-s;if(r<=i)return s+r;r-=i}}function kd(n,e){let t=0;for(let{from:r,to:a}of n.ranges){if(e<=a){t+=e-r;break}t+=a-r}return t/n.total}function HT(n,e){for(let t of n)if(e(t))return t}var Dk={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Fk(n){let e=n.facet(Wd).filter(r=>typeof r!="function"),t=n.facet(qm).filter(r=>typeof r!="function");return t.length&&e.push(wt.join(t)),e}var Am=class n{constructor(e,t,r){let a=0,s=0,o=0;this.viewports=r.map(({from:i,to:l})=>{let u=t.lineAt(i,zt.ByPos,e,0,0).top,c=t.lineAt(l,zt.ByPos,e,0,0).bottom;return a+=c-u,{from:i,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(t.height-a);for(let i of this.viewports)i.domTop=o+(i.top-s)*this.scale,o=i.domBottom=i.domTop+(i.bottom-i.top),s=i.bottom}toDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof n?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,r)=>t.from==e.viewports[r].from&&t.to==e.viewports[r].to):!1}};function cu(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),r=e.toDOM(n.bottom);return new ia(n.from,n.length,t,r-t,Array.isArray(n._content)?n._content.map(a=>cu(a,e)):n._content)}var Sd=Me.define({combine:n=>n.join(" ")}),Pm=Me.define({combine:n=>n.indexOf(!0)>-1}),Nm=lr.newName(),FS=lr.newName(),ES=lr.newName(),BS={"&light":"."+FS,"&dark":"."+ES};function Rm(n,e,t){return new lr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return n;if(!t||!t[a])throw new RangeError(`Unsupported selector: ${a}`);return t[a]}):n+" "+r}})}var UT=Rm("."+Nm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},BS),GT={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},$p=we.ie&&we.ie_version<=11,Mm=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new em,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let r of t)this.queue.push(r);(we.ie&&we.ie_version<=11||we.ios&&e.composing)&&t.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&we.android&&e.constructor.EDIT_CONTEXT!==!1&&!(we.chrome&&we.chrome_version<126)&&(this.editContext=new Tm(e),e.state.facet(rs)&&(e.contentDOM.editContext=this.editContext.editContext)),$p&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,r)=>t!=e[r]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(rs)?r.root.activeElement!=this.dom:!du(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(we.ie&&we.ie_version<=11||we.android&&we.chrome)&&!r.state.selection.main.empty&&a.focusNode&&hu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Su(e.root);if(!t)return!1;let r=we.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&zT(this.view,t)||t;if(!r||this.selectionRange.eq(r))return!1;let a=du(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&BM(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let r=this.dom;r;)if(r.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=t)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,GT),$p&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),$p&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Fi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,r=-1,a=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(a=!0),t==-1?{from:t,to:r}=o:(t=Math.min(o.from,t),r=Math.max(o.to,r)))}return{from:t,to:r,typeOver:a}}readChange(){let{from:e,to:t,typeOver:r}=this.processRecords(),a=this.selectionChanged&&du(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new xm(this.view,e,t,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let r=this.view.state,a=CS(this.view,t);return this.view.state==r&&(t.domChanged||t.newSel&&!Ed(this.view.state.selection,t.newSel.main))&&this.view.update([]),a}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let r=Ek(t,e.previousSibling||e.target.previousSibling,-1),a=Ek(t,e.nextSibling||e.target.nextSibling,1);return{from:r?t.posAfter(r):t.posAtStart,to:a?t.posBefore(a):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(rs)!=e.state.facet(rs)&&(e.view.contentDOM.editContext=e.state.facet(rs)?this.editContext.editContext:null))}destroy(){var e,t,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Ek(n,e,t){for(;e;){let r=Zt.get(e);if(r&&r.parent==n)return r;let a=e.parentNode;e=a!=n.dom?a:t>0?e.nextSibling:e.previousSibling}return null}function Bk(n,e){let t=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return hu(o.node,o.offset,a,s)&&([t,r,a,s]=[a,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}}function zT(n,e){if(e.getComposedRanges){let a=e.getComposedRanges(n.root)[0];if(a)return Bk(n,a)}let t=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),t=a.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",r,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",r,!0),t?Bk(n,t):null}var Tm=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:o}=a,i=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:i,drifted:!1});let u=l-i>r.text.length;i==this.from&&s<this.from?i=s:l==this.to&&s>this.to&&(l=s);let c=LS(e.state.sliceDoc(i,l),r.text,(u?a.from:a.to)-i,u?"end":null);if(!c){let f=se.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));Ed(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+i,to:c.toA+i,insert:ct.of(r.text.slice(c.from,c.toB).split(`
|
|
41
|
-
`))};if((we.mac||we.android)&&d.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:i,to:l,insert:ct.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);Vm(e,d,se.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(t.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let o=this.toEditorPos(r.rangeStart),i=this.toEditorPos(r.rangeEnd);o<i;o++){let l=e.coordsForChar(o);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}t.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let o=s.underlineStyle,i=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(i)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(i)?1:2}px`;a.push(Xe.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:pS.of(Xe.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)t.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Su(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,o,i,l,u)=>{if(r)return;let c=u.length-(o-s);if(a&&o>=a.to)if(a.from==s&&a.to==o&&a.insert.eq(u)){a=this.pendingContextChange=null,t+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),u.toString()),this.to+=c}t+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let t=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),a=this.toContextPos(t.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Ie=class n{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||EM(e.parent)||document,this.viewState=new _d(this,e.state||Ct.create(e)),e.scrollTo&&e.scrollTo.is(yd)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ri).map(a=>new mu(a));for(let a of this.plugins)a.update(this);this.observer=new Mm(this),this.inputState=new ym(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Dd(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Pn?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,i=0,l=null;e.some(f=>f.annotation(MS))?(this.inputState.notifiedFocused=o,i=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=TS(s,o),l||(i=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Ct.phrases)!=this.state.facet(Ct.phrases))return this.setState(s);a=Md.create(this,s,e),a.flags|=i;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:m}=this.state.facet(n.cursorScrollMargin);d=new pu(h.empty?h:se.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",m,p)}for(let h of f.effects)h.is(yd)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=Hd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),t=this.docView.update(a),this.state.facet(uu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Sd)!=a.state.facet(Sd)&&(this.viewState.mustMeasureContent=!0),(t||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(am))try{f(a)}catch(h){la(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!CS(this,c)&&u.force&&Fi(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new _d(this,e),this.plugins=e.facet(Ri).map(r=>new mu(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Dd(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ri),r=e.state.facet(Ri);if(t!=r){let a=[];for(let s of r){let o=t.indexOf(s);if(o<0)a.push(new mu(s));else{let i=this.plugins[o];i.mustUpdate=e,a.push(i)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);t!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(r){la(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:o,scaleY:i}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0){if(Jk(r||this.win))s=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,o=p.top}i=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(m){return la(this.state,m),Ok}}),f=Md.create(this,this.state,[]),h=!1;f.flags|=u,t?t.flags|=u:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Ok)try{let m=c[p];m.write&&m.write(d[p],this)}catch(m){la(this.state,m)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-o/i;if((m>1||m<-1)&&!(we.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+m,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(am))l(t)}get themeClasses(){return Nm+" "+(this.state.facet(Pm)?ES:FS)+" "+this.state.facet(Sd)}updateAttrs(){let e=_k(this,mS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(rs)?"true":"false",class:"cm-content",style:`${we.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),_k(this,jm,t);let r=this.observer.ignore(()=>{let a=gk(this.contentDOM,this.contentAttrs,t),s=gk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=t,r}showAnnouncements(e){let t=!0;for(let r of e)for(let a of r.effects)if(a.is(n.announce)){t&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),t=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(uu);let e=this.state.facet(n.cspNonce);lr.mount(this.root,this.styleModules.concat(UT).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(r=>r.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,r){return Vp(this,e,kk(this,e,t,r))}moveByGroup(e,t){return Vp(this,e,kk(this,e,t,r=>cT(this,e.head,r)))}visualLineSide(e,t){return t?se.cursor(e.to,1):se.cursor(e.from,-1)}moveToLineBoundary(e,t,r=!0){return uT(this,e,t,r)}moveVertically(e,t,r){return Vp(this,e,dT(this,e,t,r))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let r=pm(this,e,t);return r&&r.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),pm(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[Vr.find(a,e-r.from,-1,t)];return r.length&&(e==r.from&&t<0||e==r.to&&t>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,t=1):(e=r.from+s.to,t=-1)),this.docView.coordsAt(e,t,s.dir==Wt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(dS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>WT)return rS(e.length);let t=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||nS(s.isolates,r=bk(this,e))))return s.order;r||(r=bk(this,e));let a=WM(e.text,t,r);return this.bidiCache.push(new Hd(e.from,e.to,t,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||we.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Yk(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var r,a,s,o;return yd.of(new pu(typeof e=="number"?se.cursor(e):e,(r=t.y)!==null&&r!==void 0?r:"nearest",(a=t.x)!==null&&a!==void 0?a:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return yd.of(new pu(se.cursor(r.from),"start","start",r.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return cr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return cr.define(()=>({}),{eventObservers:e})}static theme(e,t){let r=lr.newName(),a=[Sd.of(r),uu.of(Rm(`.${r}`,e))];return t&&t.dark&&a.push(Pm.of(!0)),a}static baseTheme(e){return Na.lowest(uu.of(Rm("."+Nm,e,BS)))}static findFromDOM(e){var t;let r=e.querySelector(".cm-content"),a=r&&Zt.get(r)||Zt.get(e);return((t=a?.root)===null||t===void 0?void 0:t.view)||null}};Ie.styleModule=uu;Ie.inputHandler=uS;Ie.clipboardInputFilter=zm;Ie.clipboardOutputFilter=Wm;Ie.scrollHandler=hS;Ie.focusChangeEffect=cS;Ie.perLineTextDirection=dS;Ie.exceptionSink=lS;Ie.updateListener=am;Ie.editable=rs;Ie.mouseSelectionStyle=iS;Ie.dragMovesSelection=oS;Ie.clickAddsSelectionRange=sS;Ie.decorations=Wd;Ie.blockWrappers=gS;Ie.outerDecorations=qm;Ie.atomicRanges=Iu;Ie.bidiIsolatedRanges=xS;Ie.cursorScrollMargin=Me.define({combine:n=>{let e=5,t=5;for(let r of n)typeof r=="number"?e=t=r:{x:e,y:t}=r;return{x:e,y:t}}});Ie.scrollMargins=yS;Ie.darkTheme=Pm;Ie.cspNonce=Me.define({combine:n=>n.length?n[0]:""});Ie.contentAttributes=jm;Ie.editorAttributes=mS;Ie.lineWrapping=Ie.contentAttributes.of({class:"cm-lineWrapping"});Ie.announce=xt.define();var WT=4096,Ok={},Hd=class n{constructor(e,t,r,a,s,o){this.from=e,this.to=t,this.dir=r,this.isolates=a,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:Wt.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==a&&!t.touchesRange(o.from,o.to)&&r.push(new n(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function _k(n,e,t){for(let r=n.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],o=typeof s=="function"?s(n):s;o&&Hm(o,t)}return t}var jT=we.mac?"mac":we.windows?"win":we.linux?"linux":"key";function qT(n,e){let t=n.split(/-(?!$)/),r=t[t.length-1];r=="Space"&&(r=" ");let a,s,o,i;for(let l=0;l<t.length-1;++l){let u=t[l];if(/^(cmd|meta|m)$/i.test(u))i=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?i=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),i&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function Cd(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}var VT=Na.default(Ie.domEventHandlers({keydown(n,e){return YT($T(e.state),n,e,"editor")}})),$m=Me.define({enables:VT}),Hk=new WeakMap;function $T(n){let e=n.facet($m),t=Hk.get(e);return t||Hk.set(e,t=XT(e.reduce((r,a)=>r.concat(a),[]))),t}var _s=null,KT=4e3;function XT(n,e=jT){let t=Object.create(null),r=Object.create(null),a=(o,i)=>{let l=r[o];if(l==null)r[o]=i;else if(l!=i)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,i,l,u,c)=>{var d,f;let h=t[o]||(t[o]=Object.create(null)),p=i.split(/ (?!$)/).map(x=>qT(x,e));for(let x=1;x<p.length;x++){let w=p.slice(0,x).join(" ");a(w,!0),h[w]||(h[w]={preventDefault:!0,stopPropagation:!1,run:[y=>{let C=_s={view:y,prefix:w,scope:o};return setTimeout(()=>{_s==C&&(_s=null)},KT),!0}]})}let m=p.join(" ");a(m,!1);let g=h[m]||(h[m]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&g.run.push(l),u&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of n){let i=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of i){let c=t[u]||(t[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=o;for(let f in c)c[f].run.push(h=>d(h,Dm))}let l=o[e]||o.key;if(l)for(let u of i)s(u,l,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(u,"Shift-"+l,o.shift,o.preventDefault,o.stopPropagation)}return t}var Dm=null;function YT(n,e,t,r){Dm=e;let a=fk(e),s=Y1(a,0),o=J1(s)==a.length&&a!=" ",i="",l=!1,u=!1,c=!1;_s&&_s.view==t&&_s.scope==r&&(i=_s.prefix+" ",AS.indexOf(e.keyCode)<0&&(u=!0,_s=null));let d=new Set,f=g=>{if(g){for(let x of g.run)if(!d.has(x)&&(d.add(x),x(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),u=!0)}return!1},h=n[r],p,m;return h&&(f(h[i+Cd(a,e,!o)])?l=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(we.windows&&e.ctrlKey&&e.altKey)&&!(we.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ns[e.keyCode])&&p!=a?(f(h[i+Cd(p,e,!0)])||e.shiftKey&&(m=Pi[e.keyCode])!=a&&m!=p&&f(h[i+Cd(m,e,!1)]))&&(l=!0):o&&e.shiftKey&&f(h[i+Cd(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Dm=null,l}var No=class n{constructor(e,t,r,a,s){this.className=e,this.left=t,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=OS(e);return[new n(t,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return JT(e,t,r)}};function OS(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==Wt.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Uk(n,e,t,r){let a=n.coordsAtPos(e,t*2);if(!a)return r;let s=n.dom.getBoundingClientRect(),o=(a.top+a.bottom)/2,i=n.posAtCoords({x:s.left+1,y:o}),l=n.posAtCoords({x:s.right-1,y:o});return i==null||l==null?r:{from:Math.max(r.from,Math.min(i,l)),to:Math.min(r.to,Math.max(i,l))}}function JT(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let r=Math.max(t.from,n.viewport.from),a=Math.min(t.to,n.viewport.to),s=n.textDirection==Wt.LTR,o=n.contentDOM,i=o.getBoundingClientRect(),l=OS(n),u=o.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=i.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=i.right-(c?parseInt(c.paddingRight):0),h=hm(n,r,1),p=hm(n,a,-1),m=h.type==Bn.Text?h:null,g=p.type==Bn.Text?p:null;if(m&&(n.lineWrapping||h.widgetLineBreaks)&&(m=Uk(n,r,1,m)),g&&(n.lineWrapping||p.widgetLineBreaks)&&(g=Uk(n,a,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return w(y(t.from,t.to,m));{let k=m?y(t.from,null,m):C(h,!1),v=g?y(null,t.to,g):C(p,!0),b=[];return(m||h).to<(g||p).from-(m&&g?1:0)||h.widgetLineBreaks>1&&k.bottom+n.defaultLineHeight/2<v.top?b.push(x(d,k.bottom,f,v.top)):k.bottom<v.top&&n.elementAtHeight((k.bottom+v.top)/2).type==Bn.Text&&(k.bottom=v.top=(k.bottom+v.top)/2),w(k).concat(b).concat(w(v))}function x(k,v,b,P){return new No(e,k-l.left,v-l.top,Math.max(0,b-k),P-v)}function w({top:k,bottom:v,horizontal:b}){let P=[];for(let N=0;N<b.length;N+=2)P.push(x(b[N],k,b[N+1],v));return P}function y(k,v,b){let P=1e9,N=-1e9,M=[];function U(G,V,K,L,R){let z=n.coordsAtPos(G,G==b.to?-2:2),J=n.coordsAtPos(K,K==b.from?2:-2);!z||!J||(P=Math.min(z.top,J.top,P),N=Math.max(z.bottom,J.bottom,N),R==Wt.LTR?M.push(s&&V?d:z.left,s&&L?f:J.right):M.push(!s&&L?d:J.left,!s&&V?f:z.right))}let I=k??b.from,A=v??b.to;for(let G of n.visibleRanges)if(G.to>I&&G.from<A)for(let V=Math.max(G.from,I),K=Math.min(G.to,A);;){let L=n.state.doc.lineAt(V);for(let R of n.bidiSpans(L)){let z=R.from+L.from,J=R.to+L.from;if(z>=K)break;J>V&&U(Math.max(z,V),k==null&&z<=I,Math.min(J,K),v==null&&J>=A,R.dir)}if(V=L.to+1,V>=K)break}return M.length==0&&U(I,k==null,A,v==null,n.textDirection),{top:P,bottom:N,horizontal:M}}function C(k,v){let b=i.top+(v?k.top:k.bottom);return{top:b,bottom:b,horizontal:[]}}}function ZT(n,e){return n.constructor==e.constructor&&n.eq(e)}var Fm=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Id)!=e.state.facet(Id)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,r=e.facet(Id);for(;t<r.length&&r[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,r)=>!ZT(t,this.drawn[r]))){let t=this.dom.firstChild,r=0;for(let a of e)a.update&&t&&a.constructor&&this.drawn[r].constructor&&a.update(t,this.drawn[r])?(t=t.nextSibling,r++):this.dom.insertBefore(a.draw(),t);for(;t;){let a=t.nextSibling;t.remove(),t=a}this.drawn=e,we.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Id=Me.define();function _S(n){return[cr.define(e=>new Fm(e,n)),Id.of(n)]}var Ui=Me.define({combine(n){return Ai(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function HS(n={}){return[Ui.of(n),QT,eD,nD,fS.of(!0)]}function US(n){return n.startState.facet(Ui)!=n.state.facet(Ui)}var QT=_S({above:!0,markers(n){let{state:e}=n,t=e.facet(Ui),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||t.drawRangeCursor&&!(s&&we.ios&&t.iosSelectionHandles)){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=a.empty?a:se.cursor(a.head,a.assoc);for(let l of No.forRange(n,o,i))r.push(l)}}return r},update(n,e){n.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=US(n);return t&&Gk(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Gk(e.state,n)},class:"cm-cursorLayer"});function Gk(n,e){e.style.animationDuration=n.facet(Ui).cursorBlinkRate+"ms"}var eD=_S({above:!1,markers(n){let e=[],{main:t,ranges:r}=n.state.selection;for(let a of r)if(!a.empty)for(let s of No.forRange(n,"cm-selectionBackground",a))e.push(s);if(we.ios&&!t.empty&&n.state.facet(Ui).iosSelectionHandles){for(let a of No.forRange(n,"cm-selectionHandle cm-selectionHandle-start",se.cursor(t.from,1)))e.push(a);for(let a of No.forRange(n,"cm-selectionHandle cm-selectionHandle-end",se.cursor(t.to,1)))e.push(a)}return e},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||US(n)},class:"cm-selectionLayer"}),tD=we.gecko&&we.gecko_version==153?"#ffffff01":"transparent",nD=Na.highest(Ie.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${tD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var A6=/x/.unicode!=null?"gu":"g";function GS(){return aD}var rD=Xe.line({class:"cm-activeLine"}),aD=cr.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let r of n.state.selection.ranges){let a=n.lineBlockAt(r.head);a.from>e&&(t.push(rD.range(a.from)),e=a.from)}return Xe.set(t)}},{decorations:n=>n.decorations}),Em=class extends Ir{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?fu(e.firstChild):[];if(!t.length)return null;let r=window.getComputedStyle(e.parentNode),a=Cu(t[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function zS(n){let e=cr.fromClass(class{constructor(t){this.view=t,this.placeholder=n?Xe.set([Xe.widget({widget:new Em(n),side:1}).range(0)]):Xe.none}get decorations(){return this.view.state.doc.length?Xe.none:this.placeholder}},{decorations:t=>t.decorations});return typeof n=="string"?[e,Ie.contentAttributes.of({"aria-placeholder":n})]:e}var On=class extends Pa{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};On.prototype.elementClass="";On.prototype.toDOM=void 0;On.prototype.mapMode=ir.TrackBefore;On.prototype.startSide=On.prototype.endSide=-1;On.prototype.point=!0;var Ad=Me.define(),sD=Me.define(),oD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>wt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},bu=Me.define();function Gi(n){return[WS(),bu.of({...oD,...n})]}var Bm=Me.define({combine:n=>n.some(e=>e)});function WS(n){let e=[iD];return n&&n.fixed===!1&&e.push(Bm.of(!0)),e}var iD=cr.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(bu).map(e=>new Ud(n,e)),this.fixed=!n.state.facet(Bm);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,r=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(r<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Bm)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=wt.iter(this.view.state.facet(Ad),this.view.viewport.from),r=[],a=this.gutters.map(s=>new _m(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let o=!0;for(let i of s.type)if(i.type==Bn.Text&&o){Om(t,r,i.from);for(let l of a)l.line(this.view,i,r);o=!1}else if(i.widget)for(let l of a)l.widget(this.view,i)}else if(s.type==Bn.Text){Om(t,r,s.from);for(let o of a)o.line(this.view,s,r)}else if(s.widget)for(let o of a)o.widget(this.view,s);for(let s of a)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(bu),t=n.state.facet(bu),r=n.docChanged||n.heightChanged||n.viewportChanged||!wt.eq(n.startState.facet(Ad),n.state.facet(Ad),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let a of this.gutters)a.update(n)&&(r=!0);else{r=!0;let a=[];for(let s of t){let o=e.indexOf(s);o<0?a.push(new Ud(this.view,s)):(this.gutters[o].update(n),a.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>Ie.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let r=t.dom.offsetWidth*e.scaleX,a=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Wt.LTR?{left:r,right:a}:{right:r,left:a}})});function zk(n){return Array.isArray(n)?n:[n]}function Om(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var _m=class{constructor(e,t,r){this.gutter=e,this.height=r,this.i=0,this.cursor=wt.iter(e.markers,t.from)}addElement(e,t,r){let{gutter:a}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==a.elements.length){let i=new Gd(e,o,s,r);a.elements.push(i),a.dom.appendChild(i.dom)}else a.elements[this.i].update(e,o,s,r);this.height=t.bottom,this.i++}line(e,t,r){let a=[];Om(this.cursor,a,t.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,t,a);s&&a.unshift(s);let o=this.gutter;a.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,a)}widget(e,t){let r=this.gutter.config.widgetMarker(e,t.widget,t),a=r?[r]:null;for(let s of e.state.facet(sD)){let o=s(e,t.widget,t);o&&(a||(a=[])).push(o)}a&&this.addElement(e,t,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Ud=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in t.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();o=(l.top+l.bottom)/2}else o=a.clientY;let i=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[r](e,i,a)&&a.preventDefault()});this.markers=zk(t.markers(e)),t.initialSpacer&&(this.spacer=new Gd(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=zk(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!wt.eq(this.markers,t,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},Gd=class{constructor(e,t,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,r,a)}update(e,t,r,a){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),lD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,t){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,o=0;;){let i=o,l=s<t.length?t[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=o;d<this.markers.length;d++)if(this.markers[d].compare(l)){i=d,u=!0;break}}else i=this.markers.length;for(;o<i;){let c=this.markers[o++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&o++}this.dom.className=r,this.markers=t}destroy(){this.setMarkers(null,[])}};function lD(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}var uD=Me.define(),cD=Me.define(),Ti=Me.define({combine(n){return Ai(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let r=Object.assign({},e);for(let a in t){let s=r[a],o=t[a];r[a]=s?(i,l,u)=>s(i,l,u)||o(i,l,u):o}return r}})}}),wu=class extends On{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Kp(n,e){return n.state.facet(Ti).formatNumber(e,n.state)}var dD=bu.compute([Ti],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(uD)},lineMarker(e,t,r){return r.some(a=>a.toDOM)?null:new wu(Kp(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,r)=>{for(let a of e.state.facet(cD)){let s=a(e,t,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Ti)!=e.state.facet(Ti),initialSpacer(e){return new wu(Kp(e,Wk(e.state.doc.lines)))},updateSpacer(e,t){let r=Kp(t.view,Wk(t.view.state.doc.lines));return r==e.number?e:new wu(r)},domEventHandlers:n.facet(Ti).domEventHandlers,side:"before"}));function qd(n={}){return[Ti.of(n),WS(),dD]}function Wk(n){let e=9;for(;e<n;)e=e*10+9;return e}var fD=new class extends On{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},hD=Ad.compute(["selection"],n=>{let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head).from;a>t&&(t=a,e.push(fD.range(a)))}return wt.of(e)});function jS(){return hD}var pD=0,Au=class{constructor(e,t){this.from=e,this.to=t}},lt=class{constructor(e={}){this.id=pD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Ar.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}};lt.closedBy=new lt({deserialize:n=>n.split(" ")});lt.openedBy=new lt({deserialize:n=>n.split(" ")});lt.group=new lt({deserialize:n=>n.split(" ")});lt.isolate=new lt({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});lt.contextHash=new lt({perNode:!0});lt.lookAhead=new lt({perNode:!0});lt.mounted=new lt({perNode:!0});var Do=class{constructor(e,t,r,a=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[lt.mounted.id]}},mD=Object.create(null),Ar=class n{constructor(e,t,r,a=0){this.name=e,this.props=t,this.id=r,this.flags=a}static define(e){let t=e.props&&e.props.length?Object.create(null):mD,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new n(e.name||"",t,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(lt.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let a of r.split(" "))t[a]=e[r];return r=>{for(let a=r.prop(lt.group),s=-1;s<(a?a.length:0);s++){let o=t[s<0?r.name:a[s]];if(o)return o}}}};Ar.none=new Ar("",Object.create(null),0,8);var Vd=new WeakMap,qS=new WeakMap,on;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(on||(on={}));var _n=class n{constructor(e,t,r,a,s){if(this.type=e,this.children=t,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,i]of s)this.props[typeof o=="number"?o:o.id]=i}}toString(){let e=Do.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let a=r.toString();a&&(t&&(t+=","),t+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Ru(this.topNode,e)}cursorAt(e,t=0,r=0){let a=Vd.get(this)||this.topNode,s=new Ru(a);return s.moveTo(e,t),Vd.set(this,s._tree),s}get topNode(){return new Ta(this,0,0,null)}resolve(e,t=0){let r=Pu(Vd.get(this)||this.topNode,e,t,!1);return Vd.set(this,r),r}resolveInner(e,t=0){let r=Pu(qS.get(this)||this.topNode,e,t,!0);return qS.set(this,r),r}resolveStack(e,t=0){return gD(this,e,t)}iterate(e){let{enter:t,leave:r,from:a=0,to:s=this.length}=e,o=e.mode||0,i=(o&on.IncludeAnonymous)>0;for(let l=this.cursor(o|on.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!i&&l.type.isAnonymous||t(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(i||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:eg(Ar.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,a)=>new n(this.type,t,r,a,this.propValues),e.makeTree||((t,r,a)=>new n(Ar.none,t,r,a)))}static build(e){return xD(e)}};_n.empty=new _n(Ar.none,[],[],0);var Km=class n{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new n(this.buffer,this.index)}},zs=class n{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return Ar.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],r=this.buffer[e+3],a=this.set.types[t],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let o=[];for(;e<r;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,r,a,s){let{buffer:o}=this,i=-1;for(let l=e;l!=t&&!(KS(s,a,o[l+1],o[l+2])&&(i=l,r>0));l=o[l+3]);return i}slice(e,t,r){let a=this.buffer,s=new Uint16Array(t-e),o=0;for(let i=e,l=0;i<t;){s[l++]=a[i++],s[l++]=a[i++]-r;let u=s[l++]=a[i++]-r;s[l++]=a[i++]-e,o=Math.max(o,u)}return new n(s,o,this.set)}};function KS(n,e,t,r){switch(n){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function Pu(n,e,t,r){for(var a;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!r&&n instanceof Ta&&n.index<0?null:n.parent;if(!o)return n;n=o}let s=r?0:on.IgnoreOverlays;if(r)for(let o=n,i=o.parent;i;o=i,i=o.parent)o instanceof Ta&&o.index<0&&((a=i.enter(e,t,s))===null||a===void 0?void 0:a.from)!=o.from&&(n=i);for(;;){let o=n.enter(e,t,s);if(!o)return n;n=o}}var Kd=class{cursor(e=0){return new Ru(this,e)}getChild(e,t=null,r=null){let a=VS(this,e,t,r);return a.length?a[0]:null}getChildren(e,t=null,r=null){return VS(this,e,t,r)}resolve(e,t=0){return Pu(this,e,t,!1)}resolveInner(e,t=0){return Pu(this,e,t,!0)}matchContext(e){return Xm(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let a=t.lastChild;if(!a||a.to!=t.to)break;a.type.isError&&a.from==a.to?(r=t,t=a.prevSibling):t=a}return r}get node(){return this}get next(){return this.parent}},Ta=class n extends Kd{constructor(e,t,r,a){super(),this._tree=e,this.from=t,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,a,s=0){for(let o=this;;){for(let{children:i,positions:l}=o._tree,u=t>0?i.length:-1;e!=u;e+=t){let c=i[e],d=l[e]+o.from,f;if(!(!(s&on.EnterBracketed&&c instanceof _n&&(f=Do.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!KS(a,r,d,d+c.length))){if(c instanceof zs){if(s&on.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,t,r-d,a);if(h>-1)return new Nu(new Ym(o,c,e,d),null,h)}else if(s&on.IncludeAnonymous||!c.type.isAnonymous||Qm(c)){let h;if(!(s&on.IgnoreMounts)&&(h=Do.get(c))&&!h.overlay)return new n(h.tree,d,e,o);let p=new n(c,d,e,o);return s&on.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,r,a,s)}}}if(s&on.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let a;if(!(r&on.IgnoreOverlays)&&(a=Do.get(this._tree))&&a.overlay){let s=e-this.from,o=r&on.EnterBracketed&&a.bracketed;for(let{from:i,to:l}of a.overlay)if((t>0||o?i<=s:i<s)&&(t<0||o?l>=s:l>s))return new n(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function VS(n,e,t,r){let a=n.cursor(),s=[];if(!a.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=a.type.is(t),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function Xm(n,e,t=e.length-1){for(let r=n;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}var Ym=class{constructor(e,t,r,a){this.parent=e,this.buffer=t,this.index=r,this.start=a}},Nu=class n extends Kd{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.context.start,r);return s<0?null:new n(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&on.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new n(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new n(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new n(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let o=r.buffer[this.index+1];e.push(r.slice(a,s,o)),t.push(0)}return new _n(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function XS(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let o=n[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let r=t instanceof Ta&&t.index<0?null:t.parent,a=n.slice();return r?a[e]=r:a.splice(e,1),new Jm(a,t)}var Jm=class{constructor(e,t){this.heads=e,this.node=t}get next(){return XS(this.heads)}};function gD(n,e,t){let r=n.resolveInner(e,t),a=null;for(let s=r instanceof Ta?r:r.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(a||(a=[r])).push(o.resolve(e,t)),s=o}else{let o=Do.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let i=new Ta(o.tree,o.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Pu(i,e,t,!1))}}return a?XS(a):r}var Ru=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~on.EnterBracketed,e instanceof Ta)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=t||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Ta?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,r=this.mode){return this.buffer?r&on.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&on.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&on.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(t.findChild(a,this.index,-1,0,4))}else{let a=t.buffer[this.index+3];if(a<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:r}=a)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let s=t+e,o=e<0?-1:r._tree.children.length;s!=o;s+=e){let i=r._tree.children[s];if(this.mode&on.IncludeAnonymous||i instanceof zs||!i.type.isAnonymous||Qm(i))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==a){if(a==this.index)return o;t=o,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)t=new Nu(this.buffer,t,this.stack[a]);return this.bufferNode=new Nu(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&t&&t(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return Xm(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return Xm(this._tree,e,a);let o=r[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[a]&&e[a]!=o.name)return!1;a--}}return!0}};function Qm(n){return n.children.some(e=>e instanceof zs||!e.type.isAnonymous||Qm(e))}function xD(n){var e;let{buffer:t,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:o=r.types.length}=n,i=Array.isArray(t)?new Km(t,t.length):t,l=r.types,u=0,c=0;function d(k,v,b,P,N,M){let{id:U,start:I,end:A,size:G}=i,V=c,K=u;if(G<0)if(i.next(),G==-1){let Q=s[U];b.push(Q),P.push(I-k);return}else if(G==-3){u=U;return}else if(G==-4){c=U;return}else throw new RangeError(`Unrecognized record size: ${G}`);let L=l[U],R,z,J=I-k;if(A-I<=a&&(z=g(i.pos-v,N))){let Q=new Uint16Array(z.size-z.skip),re=i.pos-z.size,pe=Q.length;for(;i.pos>re;)pe=x(z.start,Q,pe);R=new zs(Q,A-z.start,r),J=z.start-k}else{let Q=i.pos-G;i.next();let re=[],pe=[],ee=U>=o?U:-1,ce=0,ue=A;for(;i.pos>Q;)ee>=0&&i.id==ee&&i.size>=0?(i.end<=ue-a&&(p(re,pe,I,ce,i.end,ue,ee,V,K),ce=re.length,ue=i.end),i.next()):M>2500?f(I,Q,re,pe):d(I,Q,re,pe,ee,M+1);if(ee>=0&&ce>0&&ce<re.length&&p(re,pe,I,ce,I,ue,ee,V,K),re.reverse(),pe.reverse(),ee>-1&&ce>0){let He=h(L,K);R=eg(L,re,pe,0,re.length,0,A-I,He,He)}else R=m(L,re,pe,A-I,V-A,K)}b.push(R),P.push(J)}function f(k,v,b,P){let N=[],M=0,U=-1;for(;i.pos>v;){let{id:I,start:A,end:G,size:V}=i;if(V>4)i.next();else{if(U>-1&&A<U)break;U<0&&(U=G-a),N.push(I,A,G),M++,i.next()}}if(M){let I=new Uint16Array(M*4),A=N[N.length-2];for(let G=N.length-3,V=0;G>=0;G-=3)I[V++]=N[G],I[V++]=N[G+1]-A,I[V++]=N[G+2]-A,I[V++]=V;b.push(new zs(I,N[2]-A,r)),P.push(A-k)}}function h(k,v){return(b,P,N)=>{let M=0,U=b.length-1,I,A;if(U>=0&&(I=b[U])instanceof _n){if(!U&&I.type==k&&I.length==N)return I;(A=I.prop(lt.lookAhead))&&(M=P[U]+I.length+A)}return m(k,b,P,N,M,v)}}function p(k,v,b,P,N,M,U,I,A){let G=[],V=[];for(;k.length>P;)G.push(k.pop()),V.push(v.pop()+b-N);k.push(m(r.types[U],G,V,M-N,I-M,A)),v.push(N-b)}function m(k,v,b,P,N,M,U){if(M){let I=[lt.contextHash,M];U=U?[I].concat(U):[I]}if(N>25){let I=[lt.lookAhead,N];U=U?[I].concat(U):[I]}return new _n(k,v,b,P,U)}function g(k,v){let b=i.fork(),P=0,N=0,M=0,U=b.end-a,I={size:0,start:0,skip:0};e:for(let A=b.pos-k;b.pos>A;){let G=b.size;if(b.id==v&&G>=0){I.size=P,I.start=N,I.skip=M,M+=4,P+=4,b.next();continue}let V=b.pos-G;if(G<0||V<A||b.start<U)break;let K=b.id>=o?4:0,L=b.start;for(b.next();b.pos>V;){if(b.size<0)if(b.size==-3||b.size==-4)K+=4;else break e;else b.id>=o&&(K+=4);b.next()}N=L,P+=G,M+=K}return(v<0||P==k)&&(I.size=P,I.start=N,I.skip=M),I.size>4?I:void 0}function x(k,v,b){let{id:P,start:N,end:M,size:U}=i;if(i.next(),U>=0&&P<o){let I=b;if(U>4){let A=i.pos-(U-4);for(;i.pos>A;)b=x(k,v,b)}v[--b]=I,v[--b]=M-k,v[--b]=N-k,v[--b]=P}else U==-3?u=P:U==-4&&(c=P);return b}let w=[],y=[];for(;i.pos>0;)d(n.start||0,n.bufferStart||0,w,y,-1,0);let C=(e=n.length)!==null&&e!==void 0?e:w.length?y[0]+w[0].length:0;return new _n(l[n.topID],w.reverse(),y.reverse(),C)}var $S=new WeakMap;function $d(n,e){if(!n.isAnonymous||e instanceof zs||e.type!=n)return 1;let t=$S.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=n||!(r instanceof _n)){t=1;break}t+=$d(n,r)}$S.set(e,t)}return t}function eg(n,e,t,r,a,s,o,i,l){let u=0;for(let p=r;p<a;p++)u+=$d(n,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,m,g,x,w){for(let y=g;y<x;){let C=y,k=m[y],v=$d(n,p[y]);for(y++;y<x;y++){let b=$d(n,p[y]);if(v+b>=c)break;v+=b}if(y==C+1){if(v>c){let b=p[C];h(b.children,b.positions,0,b.children.length,m[C]+w);continue}d.push(p[C])}else{let b=m[y-1]+p[y-1].length-k;d.push(eg(n,p,m,C,y,k,b,null,l))}f.push(k+w-s)}}return h(e,t,r,a,0),(i||l)(d,f,o)}var Fo=class n{constructor(e,t,r,a,s=!1,o=!1){this.from=e,this.to=t,this.tree=r,this.offset=a,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],r=!1){let a=[new n(0,e.length,e,0,!1,r)];for(let s of t)s.to>e.length&&a.push(s);return a}static applyChanges(e,t,r=128){if(!t.length)return e;let a=[],s=1,o=e.length?e[0]:null;for(let i=0,l=0,u=0;;i++){let c=i<t.length?t[i]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;o&&o.from<d;){let f=o;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new n(h,p,f.tree,f.offset+u,i>0,!!c)}if(f&&a.push(f),o.to>d)break;o=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},Xd=class{startParse(e,t,r){return typeof e=="string"&&(e=new Zm(e)),r=r?r.length?r.map(a=>new Au(a.from,a.to)):[new Au(0,0)]:[new Au(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let a=this.startParse(e,t,r);for(;;){let s=a.advance();if(s)return s}}},Zm=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var F6=new lt({perNode:!0});var yD=0,da=class n{constructor(e,t,r,a){this.name=e,this.set=t,this.base=r,this.modified=a,this.id=yD++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let r=typeof e=="string"?e:"?";if(e instanceof n&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let a=new n(r,[],null,[]);if(a.set.push(a),t)for(let s of t.set)a.set.push(s);return a}static defineModifier(e){let t=new Qd(e);return r=>r.modified.indexOf(t)>-1?r:Qd.get(r.base||r,r.modified.concat(t).sort((a,s)=>a.id-s.id))}},bD=0,Qd=class n{constructor(e){this.name=e,this.instances=[],this.id=bD++}static get(e,t){if(!t.length)return e;let r=t[0].instances.find(i=>i.base==e&&wD(t,i.modified));if(r)return r;let a=[],s=new da(e.name,a,e,t);for(let i of t)i.instances.push(s);let o=vD(t);for(let i of e.set)if(!i.modified.length)for(let l of o)a.push(n.get(i,l));return s}};function wD(n,e){return n.length==e.length&&n.every((t,r)=>t==e[r])}function vD(n){let e=[[]];for(let t=0;t<n.length;t++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(n[t]));return e.sort((t,r)=>r.length-t.length)}function ZS(n){let e=Object.create(null);for(let t in n){let r=n[t];Array.isArray(r)||(r=[r]);for(let a of t.split(" "))if(a){let s=[],o=2,i=a;for(let d=0;;){if(i=="..."&&d>0&&d+3==a.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(i);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){o=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);i=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Bo(r,o,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return QS.add(e)}var QS=new lt({combine(n,e){let t,r,a;for(;n||e;){if(!n||e&&n.depth<=e.depth?(a=e,e=e.next):(a=n,n=n.next),t&&t.mode==a.mode&&!a.context&&!t.context)continue;let s=new Bo(a.tags,a.mode,a.context);t?t.next=s:r=s,t=s}return r}}),Bo=class{constructor(e,t,r,a){this.tags=e,this.mode=t,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Bo.empty=new Bo([],2,null);function ag(n,e){let t=Object.create(null);for(let s of n)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let o=a;for(let i of s)for(let l of i.set){let u=t[l.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function kD(n,e){let t=null;for(let r of n){let a=r.style(e);a&&(t=t?t+" "+a:a)}return t}function sg(n,e,t,r=0,a=n.length){let s=new ng(r,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),r,a,"",s.highlighters),s.flush(a)}var ng=class{constructor(e,t,r){this.at=e,this.highlighters=t,this.span=r,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,r,a,s){let{type:o,from:i,to:l}=e;if(i>=r||l<=t)return;o.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(o)));let u=a,c=SD(e)||Bo.empty,d=kD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(t,i),u),c.opaque)return;let f=e.tree&&e.tree.prop(lt.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+i,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,x=i;;g++){let w=g<f.overlay.length?f.overlay[g]:null,y=w?w.from+i:l,C=Math.max(t,x),k=Math.min(r,y);if(C<k&&m)for(;e.from<k&&(this.highlightRange(e,C,k,a,s),this.startSpan(Math.min(k,e.to),u),!(e.to>=y||!e.nextSibling())););if(!w||y>r)break;x=w.to+i,x>t&&(this.highlightRange(h.cursor(),Math.max(t,w.from+i),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}m&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=t)){if(e.from>=r)break;this.highlightRange(e,t,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function SD(n){let e=n.type.prop(QS);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}var xe=da.define,Yd=xe(),Ws=xe(),YS=xe(Ws),JS=xe(Ws),js=xe(),Jd=xe(js),tg=xe(js),Ea=xe(),Eo=xe(Ea),Da=xe(),Fa=xe(),rg=xe(),Mu=xe(rg),Zd=xe(),be={comment:Yd,lineComment:xe(Yd),blockComment:xe(Yd),docComment:xe(Yd),name:Ws,variableName:xe(Ws),typeName:YS,tagName:xe(YS),propertyName:JS,attributeName:xe(JS),className:xe(Ws),labelName:xe(Ws),namespace:xe(Ws),macroName:xe(Ws),literal:js,string:Jd,docString:xe(Jd),character:xe(Jd),attributeValue:xe(Jd),number:tg,integer:xe(tg),float:xe(tg),bool:xe(js),regexp:xe(js),escape:xe(js),color:xe(js),url:xe(js),keyword:Da,self:xe(Da),null:xe(Da),atom:xe(Da),unit:xe(Da),modifier:xe(Da),operatorKeyword:xe(Da),controlKeyword:xe(Da),definitionKeyword:xe(Da),moduleKeyword:xe(Da),operator:Fa,derefOperator:xe(Fa),arithmeticOperator:xe(Fa),logicOperator:xe(Fa),bitwiseOperator:xe(Fa),compareOperator:xe(Fa),updateOperator:xe(Fa),definitionOperator:xe(Fa),typeOperator:xe(Fa),controlOperator:xe(Fa),punctuation:rg,separator:xe(rg),bracket:Mu,angleBracket:xe(Mu),squareBracket:xe(Mu),paren:xe(Mu),brace:xe(Mu),content:Ea,heading:Eo,heading1:xe(Eo),heading2:xe(Eo),heading3:xe(Eo),heading4:xe(Eo),heading5:xe(Eo),heading6:xe(Eo),contentSeparator:xe(Ea),list:xe(Ea),quote:xe(Ea),emphasis:xe(Ea),strong:xe(Ea),link:xe(Ea),monospace:xe(Ea),strikethrough:xe(Ea),inserted:xe(),deleted:xe(),changed:xe(),invalid:xe(),meta:Zd,documentMeta:xe(Zd),annotation:xe(Zd),processingInstruction:xe(Zd),definition:da.defineModifier("definition"),constant:da.defineModifier("constant"),function:da.defineModifier("function"),standard:da.defineModifier("standard"),local:da.defineModifier("local"),special:da.defineModifier("special")};for(let n in be){let e=be[n];e instanceof da&&(e.name=n)}var O6=ag([{tag:be.link,class:"tok-link"},{tag:be.heading,class:"tok-heading"},{tag:be.emphasis,class:"tok-emphasis"},{tag:be.strong,class:"tok-strong"},{tag:be.keyword,class:"tok-keyword"},{tag:be.atom,class:"tok-atom"},{tag:be.bool,class:"tok-bool"},{tag:be.url,class:"tok-url"},{tag:be.labelName,class:"tok-labelName"},{tag:be.inserted,class:"tok-inserted"},{tag:be.deleted,class:"tok-deleted"},{tag:be.literal,class:"tok-literal"},{tag:be.string,class:"tok-string"},{tag:be.number,class:"tok-number"},{tag:[be.regexp,be.escape,be.special(be.string)],class:"tok-string2"},{tag:be.variableName,class:"tok-variableName"},{tag:be.local(be.variableName),class:"tok-variableName tok-local"},{tag:be.definition(be.variableName),class:"tok-variableName tok-definition"},{tag:be.special(be.variableName),class:"tok-variableName2"},{tag:be.definition(be.propertyName),class:"tok-propertyName tok-definition"},{tag:be.typeName,class:"tok-typeName"},{tag:be.namespace,class:"tok-namespace"},{tag:be.className,class:"tok-className"},{tag:be.macroName,class:"tok-macroName"},{tag:be.propertyName,class:"tok-propertyName"},{tag:be.operator,class:"tok-operator"},{tag:be.comment,class:"tok-comment"},{tag:be.meta,class:"tok-meta"},{tag:be.invalid,class:"tok-invalid"},{tag:be.punctuation,class:"tok-punctuation"}]);var og,Du=new lt;var CD=new lt,$r=class{constructor(e,t,r=[],a=""){this.data=e,this.name=a,Ct.prototype.hasOwnProperty("tree")||Object.defineProperty(Ct.prototype,"tree",{get(){return os(this)}}),this.parser=t,this.extension=[qs.of(this),Ct.languageData.of((s,o,i)=>{let l=eC(s,o,i),u=l.type.prop(Du);if(!u)return[];let c=s.facet(u),d=l.type.prop(CD);if(d){let f=l.resolve(o-l.from,i);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,t,r=-1){return eC(e,t,r).type.prop(Du)==this.data}findRegions(e){let t=e.facet(qs);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],a=(s,o)=>{if(s.prop(Du)==this.data){r.push({from:o,to:o+s.length});return}let i=s.prop(lt.mounted);if(i){if(i.tree.prop(Du)==this.data){if(i.overlay)for(let l of i.overlay)r.push({from:l.from+o,to:l.to+o});else r.push({from:o,to:o+s.length});return}else if(i.overlay){let l=r.length;if(a(i.tree,i.overlay[0].from+o),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof _n&&a(u,s.positions[l]+o)}};return a(os(e),0),r}get allowsNesting(){return!0}};$r.setState=xt.define();function eC(n,e,t){let r=n.facet(qs),a=os(n).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,t,on.ExcludeBuffers|on.EnterBracketed))s.type.isTop&&(a=s);return a}function os(n){let e=n.field($r.state,!1);return e?e.tree:_n.empty}var ug=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}},Tu=null,cg=class n{constructor(e,t,r=[],a,s,o,i,l){this.parser=e,this.state=t,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=o,this.skipped=i,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new n(e,t,[],_n.empty,0,r,[],null)}startParse(){return this.parser.startParse(new ug(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=_n.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Fo.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Fo.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Tu;Tu=this;try{return e()}finally{Tu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=tC(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:a,treeLen:s,viewport:o,skipped:i}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Fo.applyChanges(r,l),a=_n.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){i=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&i.push({from:c,to:d})}}}return new n(this.parser,t,r,a,s,o,i,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=tC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Xd{createParse(t,r,a){let s=a[0].from,o=a[a.length-1].to;return{parsedPos:s,advance(){let l=Tu;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=o,new _n(Ar.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Tu}};function tC(n,e,t){return Fo.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Fu=class n{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new n(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=cg.create(e.facet(qs).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new n(r)}};$r.state=vn.define({create:Fu.init,update(n,e){for(let t of e.effects)if(t.is($r.setState))return t.value;return e.startState.facet(qs)!=e.state.facet(qs)?Fu.init(e.state):n.apply(e)}});var sC=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(sC=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var ig=typeof navigator<"u"&&(!((og=navigator.scheduling)===null||og===void 0)&&og.isInputPending)?()=>navigator.scheduling.isInputPending():null,LD=cr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field($r.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field($r.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=sC(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field($r.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!ig?Math.max(25,e.timeRemaining()-5):1e9),i=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>ig&&ig()||Date.now()>o,a+(i?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:$r.setState.of(new Fu(s.context))})),this.chunkBudget>0&&!(l&&!i)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>la(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),qs=Me.define({combine(n){return n.length?n[0]:null},enables:n=>[$r.state,LD,Ie.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});var ID=Me.define(),ef=Me.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Eu(n){let e=n.facet(ef);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Bu(n,e){let t="",r=n.tabSize,a=n.facet(ef)[0];if(a==" "){for(;e>=r;)t+=" ",e-=r;a=" "}for(let s=0;s<e;s++)t+=a;return t}function mg(n,e){n instanceof Ct&&(n=new Oo(n));for(let r of n.state.facet(ID)){let a=r(n,e);if(a!==void 0)return a}let t=os(n.state);return t.length>=e?PD(n,t,e):null}var Oo=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=Eu(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(t<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,t);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.countColumn(r,e-a),o=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return o>-1&&(s+=o-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,t=e.length){return Io(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(a);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},AD=new lt;function PD(n,e,t){let r=e.resolveStack(t),a=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(a!=r.node){let s=[];for(let o=a;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)r={node:s[o],next:r}}return oC(r,n,t)}function oC(n,e,t){for(let r=n;r;r=r.next){let a=RD(r.node);if(a)return a(dg.create(e,t,r))}return 0}function ND(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function RD(n){let e=n.type.prop(AD);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(lt.closedBy))){let a=n.lastChild,s=a&&r.indexOf(a.name)>-1;return o=>FD(o,!0,1,void 0,s&&!ND(o)?a.from:void 0)}return n.parent==null?MD:null}function MD(){return 0}var dg=class n extends Oo{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new n(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(TD(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return oC(this.context.next,this.base,this.pos)}};function TD(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function DD(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let a=n.options.simulateBreak,s=n.state.doc.lineAt(t.from),o=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let i=t.to;;){let l=e.childAfter(i);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=o)return null;let u=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+u}}i=l.to}}function FD(n,e,t,r,a){let s=n.textAfter,o=s.match(/^\s*/)[0].length,i=r&&s.slice(o,o+r.length)==r||a==n.pos+o,l=e?DD(n):null;return l?i?n.column(l.from):n.column(l.to):n.baseIndent+(i?0:n.unit*t)}var fg=class n{constructor(e,t){this.specs=e;let r;function a(i){let l=lr.newName();return(r||(r=Object.create(null)))["."+l]=i,l}let s=typeof t.all=="string"?t.all:t.all?a(t.all):void 0,o=t.scope;this.scope=o instanceof $r?i=>i.prop(Du)==o.data:o?i=>i==o:void 0,this.style=ag(e.map(i=>({tag:i.tag,class:i.class||a(Object.assign({},i,{tag:null}))})),{all:s}).style,this.module=r?new lr(r):null,this.themeType=t.themeType}static define(e,t){return new n(e,t||{})}},ED=Me.define(),BD=Me.define({combine(n){return n.length?[n[0]]:null}});function OD(n){let e=n.facet(ED);return e.length?e:n.facet(BD)}function iC(n,e,t){let r=OD(n),a=null;if(r){for(let s of r)if(!s.scope||t&&s.scope(t)){let o=s.style(e);o&&(a=a?a+" "+o:o)}}return a}var V6=fg.define([{tag:be.meta,color:"#404740"},{tag:be.link,textDecoration:"underline"},{tag:be.heading,textDecoration:"underline",fontWeight:"bold"},{tag:be.emphasis,fontStyle:"italic"},{tag:be.strong,fontWeight:"bold"},{tag:be.strikethrough,textDecoration:"line-through"},{tag:be.keyword,color:"#708"},{tag:[be.atom,be.bool,be.url,be.contentSeparator,be.labelName],color:"#219"},{tag:[be.literal,be.inserted],color:"#164"},{tag:[be.string,be.deleted],color:"#a11"},{tag:[be.regexp,be.escape,be.special(be.string)],color:"#e40"},{tag:be.definition(be.variableName),color:"#00f"},{tag:be.local(be.variableName),color:"#30a"},{tag:[be.typeName,be.namespace],color:"#085"},{tag:be.className,color:"#167"},{tag:[be.special(be.variableName),be.macroName],color:"#256"},{tag:be.definition(be.propertyName),color:"#00c"},{tag:be.comment,color:"#940"},{tag:be.invalid,color:"#f00"}]);var _D=1e4,HD="()[]{}";var UD=new lt;function hg(n,e,t){let r=n.prop(e<0?lt.openedBy:lt.closedBy);if(r)return r;if(n.name.length==1){let a=t.indexOf(n.name);if(a>-1&&a%2==(e<0?1:0))return[t[a+e]]}return null}function pg(n){let e=n.type.prop(UD);return e?e(n.node):n}function _o(n,e,t,r={}){let a=r.maxScanDistance||_D,s=r.brackets||HD,o=os(n),i=o.resolveInner(e,t);for(let l=i;l;l=l.parent){let u=hg(l.type,t,s);if(u&&l.from<l.to){let c=pg(l);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return GD(n,e,t,l,c,u,s)}}return zD(n,e,t,o,i.type,a,s)}function GD(n,e,t,r,a,s,o){let i=r.parent,l={from:a.from,to:a.to},u=0,c=i?.cursor();if(c&&(t<0?c.childBefore(r.from):c.childAfter(r.to)))do if(t<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=pg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(hg(c.type,t,o))u++;else if(hg(c.type,-t,o)){if(u==0){let d=pg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(t<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function zD(n,e,t,r,a,s,o){if(t<0?!e:e==n.doc.length)return null;let i=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),l=o.indexOf(i);if(l<0||l%2==0!=t>0)return null;let u={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;t<0&&(f+=h.length);let p=e+f*t;for(let m=t>0?0:h.length-1,g=t>0?h.length:-1;m!=g;m+=t){let x=o.indexOf(h[m]);if(!(x<0||r.resolveInner(p+m,1).type!=a))if(x%2==0==t>0)d++;else{if(d==1)return{start:u,end:{from:p+m,to:p+m+1},matched:x>>1==l>>1};d--}}t>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var WD=Object.create(null),nC=[Ar.none];var rC=[],aC=Object.create(null),jD=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])jD[n]=qD(WD,e);function lg(n,e){rC.indexOf(n)>-1||(rC.push(n),console.warn(e))}function qD(n,e){let t=[];for(let i of e.split(" ")){let l=[];for(let u of i.split(".")){let c=n[u]||be[u];c?typeof c=="function"?l.length?l=l.map(c):lg(u,`Modifier ${u} used at start of tag`):l.length?lg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:lg(u,`Unknown highlighting tag ${u}`)}for(let u of l)t.push(u)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+t.map(i=>i.id),s=aC[a];if(s)return s.id;let o=aC[a]=Ar.define({id:nC.length,name:r,props:[ZS({[r]:t})]});return nC.push(o),o.id}var $6={rtl:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:Wt.RTL}),ltr:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:Wt.LTR}),auto:Xe.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var gn=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}offset(e,t=e){return new n(this.fromA+e,this.toA+e,this.fromB+t,this.toB+t)}};function Uo(n,e,t,r,a,s){if(n==r)return[];let o=Lg(n,e,t,r,a,s),i=Ig(n,e+o,t,r,a+o,s);e+=o,t-=i,a+=o,s-=i;let l=t-e,u=s-a;if(!l||!u)return[new gn(e,t,a,s)];if(l>u){let d=n.slice(e,t).indexOf(r.slice(a,s));if(d>-1)return[new gn(e,e+d,a,a),new gn(e+d+u,t,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(n.slice(e,t));if(d>-1)return[new gn(e,e,a,a+d),new gn(t,t,a+d+l,s)]}if(l==1||u==1)return[new gn(e,t,a,s)];let c=PC(n,e,t,r,a,s);if(c){let[d,f,h]=c;return Uo(n,e,d,r,a,f).concat(Uo(n,d+h,t,r,f+h,s))}return VD(n,e,t,r,a,s)}var Ou=1e9,_u=0,Cg=!1;function VD(n,e,t,r,a,s){let o=t-e,i=s-a;if(Ou<1e9&&Math.min(o,i)>Ou*16||_u>0&&Date.now()>_u)return Math.min(o,i)>Ou*64?[new gn(e,t,a,s)]:lC(n,e,t,r,a,s);let l=Math.ceil((o+i)/2);gg.reset(l),xg.reset(l);let u=(h,p)=>n.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>n.charCodeAt(t-h-1)==r.charCodeAt(s-p-1),d=(o-i)%2!=0?xg:null,f=d?null:gg;for(let h=0;h<l;h++){if(h>Ou||_u>0&&!(h&63)&&Date.now()>_u)return lC(n,e,t,r,a,s);let p=gg.advance(h,o,i,l,d,!1,u)||xg.advance(h,o,i,l,f,!0,c);if(p)return $D(n,e,t,e+p[0],r,a,s,a+p[1])}return[new gn(e,t,a,s)]}var sf=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let t=0;t<this.len;t++)this.vec[t]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,r,a,s,o,i){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<t&&d<r&&i(c,d);)c++,d++;if(this.vec[u]=c,c>t)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(t-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(o){let h=s.vec[f];if(h>=t-c)return[h,a+h-f]}else{let h=t-s.vec[f];if(c>=h)return[c,d]}}}return null}},gg=new sf,xg=new sf;function $D(n,e,t,r,a,s,o,i){let l=!1;return!Wi(n,r)&&++r==t&&(l=!0),!Wi(a,i)&&++i==o&&(l=!0),l?[new gn(e,t,s,o)]:Uo(n,e,r,a,s,i).concat(Uo(n,r,t,a,i,o))}function AC(n,e){let t=1,r=Math.min(n,e);for(;t<r;)t=t<<1;return t}function Lg(n,e,t,r,a,s){if(e==t||e==s||n.charCodeAt(e)!=r.charCodeAt(a))return 0;let o=AC(t-e,s-a);for(let i=e,l=a;;){let u=i+o,c=l+o;if(u>t||c>s||n.slice(i,u)!=r.slice(l,c)){if(o==1)return i-e-(Wi(n,i)?0:1);o=o>>1}else{if(u==t||c==s)return u-e;i=u,l=c}}}function Ig(n,e,t,r,a,s){if(e==t||a==s||n.charCodeAt(t-1)!=r.charCodeAt(s-1))return 0;let o=AC(t-e,s-a);for(let i=t,l=s;;){let u=i-o,c=l-o;if(u<e||c<a||n.slice(u,i)!=r.slice(c,l)){if(o==1)return t-i-(Wi(n,i)?0:1);o=o>>1}else{if(u==e||c==a)return t-u;i=u,l=c}}}function yg(n,e,t,r,a,s,o,i){let l=r.slice(a,s),u=null;for(;;){if(u||o<i)return u;for(let c=e+o;;){Wi(n,c)||c++;let d=c+o;if(Wi(n,d)||(d+=d==c+1?1:-1),d>=t)break;let f=n.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=Lg(n,d,t,r,a+h+f.length,s),m=Ig(n,e,c,r,a,a+h),g=f.length+p+m;(!u||u[2]<g)&&(u=[c-m,a+h-m,g])}c=d}if(i<0)return u;o=o>>1}}function PC(n,e,t,r,a,s){let o=t-e,i=s-a;if(o<i){let l=PC(r,a,s,n,e,t);return l&&[l[1],l[0],l[2]]}return o<4||i*2<o?null:yg(n,e,t,r,a,s,Math.floor(o/4),-1)}function lC(n,e,t,r,a,s){Cg=!0;let o=t-e,i=s-a,l;if(o<i){let f=yg(r,a,s,n,e,t,Math.floor(o/6),50);l=f&&[f[1],f[0],f[2]]}else l=yg(n,e,t,r,a,s,Math.floor(i/6),50);if(!l)return[new gn(e,t,a,s)];let[u,c,d]=l;return Uo(n,e,u,r,a,c).concat(Uo(n,u+d,t,r,c+d,s))}function NC(n,e){for(let t=1;t<n.length;t++){let r=n[t-1],a=n[t];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(n[t-1]=new gn(r.fromA,a.toA,r.fromB,a.toB),n.splice(t--,1))}}function KD(n,e,t){for(;;){NC(t,1);let r=!1;for(let a=0;a<t.length;a++){let s=t[a],o,i;(o=Lg(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new gn(s.fromA+o,s.toA,s.fromB+o,s.toB)),(i=Ig(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new gn(s.fromA,s.toA-i,s.fromB,s.toB-i));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?t[a-1].toA:0),d=(a<t.length-1?t[a+1].fromA:n.length)-s.toA;if(!c||!d)continue;let f=l?n.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&n.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(t[a]=new gn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&n.slice(s.toA,s.toA+d)==f.slice(0,d)&&(t[a]=new gn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return t}function XD(n,e,t){for(let r=0,a=0;a<n.length;a++){let s=n[a],o=s.toA-s.fromA,i=s.toB-s.fromB;if(o&&i||o>3||i>3){let l=a==n.length-1?e.length:n[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=cC(e,s.fromA,u),f=uC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!o||!i)&&h&&p){let m=Math.max(o,i),[g,x,w]=o?[e,s.fromA,s.toA]:[t,s.fromB,s.toB];m>h&&e.slice(d,s.fromA)==g.slice(w-h,w)?(s=n[a]=new gn(d,d+o,s.fromB-h,s.toB-h),d=s.fromA,f=uC(e,s.toA,l-s.toA)):m>p&&e.slice(s.toA,f)==g.slice(x,x+p)&&(s=n[a]=new gn(f-o,f,s.fromB+p,s.toB+p),f=s.toA,d=cC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=n[a]=new gn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(o){if(!i){let m=fC(e,s.fromA,s.toA),g,x=m<0?-1:dC(e,s.toA,s.fromA);m>-1&&(g=m-s.fromA)<=c&&e.slice(s.fromA,m)==e.slice(s.toA,s.toA+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toA-x)<=u&&e.slice(s.fromA-g,s.fromA)==e.slice(x,s.toA)&&(s=n[a]=s.offset(-g))}}else{let m=fC(t,s.fromB,s.toB),g,x=m<0?-1:dC(t,s.toB,s.fromB);m>-1&&(g=m-s.fromB)<=c&&t.slice(s.fromB,m)==t.slice(s.toB,s.toB+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toB-x)<=u&&t.slice(s.fromB-g,s.fromB)==t.slice(x,s.toB)&&(s=n[a]=s.offset(-g))}}r=s.toA}return NC(n,3),n}var Ho;try{Ho=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function RC(n){return n>48&&n<58||n>64&&n<91||n>96&&n<123}function MC(n,e){if(e==n.length)return 0;let t=n.charCodeAt(e);return t<192?RC(t)?1:0:Ho?!FC(t)||e==n.length-1?Ho.test(String.fromCharCode(t))?1:0:Ho.test(n.slice(e,e+2))?2:0:0}function TC(n,e){if(!e)return 0;let t=n.charCodeAt(e-1);return t<192?RC(t)?1:0:Ho?!EC(t)||e==1?Ho.test(String.fromCharCode(t))?1:0:Ho.test(n.slice(e-2,e))?2:0:0}var DC=8;function uC(n,e,t){if(e==n.length||!TC(n,e))return e;for(let r=e,a=e+t,s=0;s<DC;s++){let o=MC(n,r);if(!o||r+o>a)return r;r+=o}return e}function cC(n,e,t){if(!e||!MC(n,e))return e;for(let r=e,a=e-t,s=0;s<DC;s++){let o=TC(n,r);if(!o||r-o<a)return r;r-=o}return e}function dC(n,e,t){for(;e!=t;e--)if(n.charCodeAt(e-1)==10)return e;return-1}function fC(n,e,t){for(;e!=t;e++)if(n.charCodeAt(e)==10)return e;return-1}var FC=n=>n>=55296&&n<=56319,EC=n=>n>=56320&&n<=57343;function Wi(n,e){return!e||e==n.length||!FC(n.charCodeAt(e-1))||!EC(n.charCodeAt(e))}function YD(n,e,t){var r;let a=t?.override;return a?a(n,e):(Ou=((r=t?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,_u=t?.timeout?Date.now()+t.timeout:0,Cg=!1,KD(n,e,Uo(n,0,n.length,e,0,e.length)))}function BC(){return!Cg}function OC(n,e,t){return XD(YD(n,e,t),n,e)}var dr=Me.define({combine:n=>n[0]}),bg=xt.define(),_C=Me.define(),nr=vn.define({create(n){return null},update(n,e){for(let t of e.effects)t.is(bg)&&(n=t.value);for(let t of e.state.facet(_C))n=t(n,e);return n}});var is=class n{constructor(e,t,r,a,s,o=!0){this.changes=e,this.fromA=t,this.toA=r,this.fromB=a,this.toB=s,this.precise=o}offset(e,t){return e||t?new n(this.changes,this.fromA+e,this.toA+e,this.fromB+t,this.toB+t,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,r){let a=OC(e.toString(),t.toString(),r);return HC(a,e,t,0,0,BC())}static updateA(e,t,r,a,s){return xC(gC(e,a,!0,r.length),e,t,r,s)}static updateB(e,t,r,a,s){return xC(gC(e,a,!1,t.length),e,t,r,s)}};function hC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.to==n&&s.to==e&&n<t.length&&e<r.length?[n+1,e+1]:[a.from,s.from]}function pC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.from==n&&s.from==e?[n,e]:[a.to+1,s.to+1]}function HC(n,e,t,r,a,s){let o=[];for(let i=0;i<n.length;i++){let l=n[i],[u,c]=hC(l.fromA+r,l.fromB+a,e,t),[d,f]=pC(l.toA+r,l.toB+a,e,t),h=[l.offset(-u+r,-c+a)];for(;i<n.length-1;){let p=n[i+1],[m,g]=hC(p.fromA+r,p.fromB+a,e,t);if(m>d+1&&g>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=pC(p.toA+r,p.toB+a,e,t),i++}o.push(new is(h,u,Math.max(u,d),c,Math.max(c,f),s))}return o}var tf=1e3;function mC(n,e,t,r){let a=0,s=n.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=n[a-1]);let f=e-(t?c:d);return[c+f,d+f]}let o=a+s>>1,i=n[o],[l,u]=t?[i.fromA,i.toA]:[i.fromB,i.toB];if(l>e)s=o;else if(u<=e)a=o+1;else return r?[i.fromA,i.fromB]:[i.toA,i.toB]}}function gC(n,e,t,r){let a=[];return e.iterChangedRanges((s,o,i,l)=>{let u=0,c=t?e.length:r,d=0,f=t?r:e.length;s>tf&&([u,d]=mC(n,s-tf,t,!0)),o<e.length-tf&&([c,f]=mC(n,o+tf,t,!1));let h=l-i-(o-s),p,[m,g]=t?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+m,diffB:p.diffB+g}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:m,diffB:g})}),a}function xC(n,e,t,r,a){if(!n.length)return e;let s=[];for(let o=0,i=0,l=0,u=0;;o++){let c=o==n.length?null:n[o],d=c?c.fromA+i:t.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let g=e[u];if(c&&(g.toA+i>d||g.toB+l>f))break;s.push(g.offset(i,l)),u++}if(!c)break;let h=c.toA+i+c.diffA,p=c.toB+l+c.diffB,m=OC(t.sliceString(d,h),r.sliceString(f,p),a);for(let g of HC(m,t,r,d,f,BC()))s.push(g);for(i+=c.diffA,l+=c.diffB;u<e.length;){let g=e[u];if(g.fromA+i>h&&g.fromB+l>p)break;u++}}return s}var UC={scanLimit:500},cf=cr.fromClass(class{constructor(n){({deco:this.deco,gutter:this.gutter}=wC(n))}update(n){(n.docChanged||n.viewportChanged||JD(n.startState,n.state)||ZD(n.startState,n.state))&&({deco:this.deco,gutter:this.gutter}=wC(n.view))}},{decorations:n=>n.deco}),nf=Na.low(Gi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(cf))===null||e===void 0?void 0:e.gutter)||wt.empty}}));function JD(n,e){return n.field(nr,!1)!=e.field(nr,!1)}function ZD(n,e){return n.facet(dr)!=e.facet(dr)}var yC=Xe.line({class:"cm-changedLine"}),GC=Xe.mark({class:"cm-changedText"}),QD=Xe.mark({tagName:"ins",class:"cm-insertedLine"}),eF=Xe.mark({tagName:"del",class:"cm-deletedLine"}),bC=new class extends On{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function tF(n,e,t,r,a,s){let o=t?n.fromA:n.fromB,i=t?n.toA:n.toB,l=0;if(o!=i){a.add(o,o,yC),a.add(o,i,t?eF:QD),s&&s.add(o,o,bC);for(let u=e.iterRange(o,i-1),c=o;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,yC),s&&s.add(c,c,bC);continue}let d=c+u.value.length;if(r)for(;l<n.changes.length;){let f=n.changes[l],h=o+(t?f.fromA:f.fromB),p=o+(t?f.toA:f.toB),m=Math.max(c,h),g=Math.min(d,p);if(m<g&&a.add(m,g,GC),p<d)l++;else break}c=d}}}function wC(n){let e=n.state.field(nr),{side:t,highlightChanges:r,markGutter:a,overrideChunk:s}=n.state.facet(dr),o=t=="a",i=new jn,l=a?new jn:null,{from:u,to:c}=n.viewport;for(let d of e){if((o?d.fromA:d.fromB)>=c)break;(o?d.toA:d.toB)>u&&(!s||!s(n.state,d,i,l))&&tF(d,n.state.doc,o,r,i,l)}return{deco:i.finish(),gutter:l&&l.finish()}}var zi=class extends Ir{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},of=xt.define({map:(n,e)=>n.map(e)}),Hu=vn.define({create:()=>Xe.none,update:(n,e)=>{for(let t of e.effects)if(t.is(of))return t.value;return n.map(e.changes)},provide:n=>Ie.decorations.from(n)}),rf=.01;function vC(n,e){if(n.size!=e.size)return!1;let t=n.iter(),r=e.iter();for(;t.value;){if(t.from!=r.from||Math.abs(t.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;t.next(),r.next()}return!0}function nF(n,e,t){let r=new jn,a=new jn,s=n.state.field(Hu).iter(),o=e.state.field(Hu).iter(),i=0,l=0,u=0,c=0,d=n.viewport,f=e.viewport;for(let g=0;;g++){let x=g<t.length?t[g]:null,w=x?x.fromA:n.state.doc.length,y=x?x.fromB:e.state.doc.length;if(i<w){let C=n.lineBlockAt(i).top+u,k=e.lineBlockAt(l).top+c,v=C-k;v<-rf?(u-=v,r.add(i,i,Xe.widget({widget:new zi(-v),block:!0,side:-1}))):v>rf&&(c+=v,a.add(l,l,Xe.widget({widget:new zi(v),block:!0,side:-1})))}if(w>i+1e3&&i<d.from&&w>d.from&&l<f.from&&y>f.from){let C=Math.min(d.from-i,f.from-l);i+=C,l+=C,g--}else if(x)i=x.toA,l=x.toB;else break;for(;s.value&&s.from<i;)u-=s.value.spec.widget.height,s.next();for(;o.value&&o.from<l;)c-=o.value.spec.widget.height,o.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;o.value;)c-=o.value.spec.widget.height,o.next();let h=n.contentHeight+u-(e.contentHeight+c);h<rf?r.add(n.state.doc.length,n.state.doc.length,Xe.widget({widget:new zi(-h),block:!0,side:1})):h>rf&&a.add(e.state.doc.length,e.state.doc.length,Xe.widget({widget:new zi(h),block:!0,side:1}));let p=r.finish(),m=a.finish();vC(p,n.state.field(Hu))||n.dispatch({effects:of.of(p)}),vC(m,e.state.field(Hu))||e.dispatch({effects:of.of(m)})}var wg=xt.define({map:(n,e)=>e.mapPos(n)});var vg=class extends Ir{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement("div");return t.className="cm-collapsedLines",t.textContent=e.state.phrase("$ unchanged lines",this.lines),t.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:wg.of(a)});let{side:s,sibling:o}=e.state.facet(dr);o&&o().dispatch({effects:wg.of(rF(a,e.state.field(nr),s=="a"))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function rF(n,e,t){let r=0,a=0;for(let s=0;;s++){let o=s<e.length?e[s]:null;if(!o||(t?o.fromA:o.fromB)>=n)return a+(n-r);[r,a]=t?[o.toA,o.toB]:[o.toB,o.toA]}}var aF=vn.define({create(n){return Xe.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)t.is(wg)&&(n=n.update({filter:r=>r!=t.value}));if(n.size&&e.state.field(nr)!=e.startState.field(nr,!1)){let t=e.state.facet(dr).side=="a",r=[];for(let a of e.state.field(nr))n.between(t?a.fromA:a.fromB,t?a.toA:a.toB,s=>{r.push(s)});r.length&&(n=n.update({filter:a=>r.indexOf(a)<0}))}return n},provide:n=>Ie.decorations.from(n)});function kg({margin:n=3,minSize:e=4}){return aF.init(t=>sF(t,n,e))}function sF(n,e,t){let r=new jn,a=n.facet(dr).side=="a",s=n.field(nr),o=1;for(let i=0;;i++){let l=i<s.length?s[i]:null,u=i?o+e:1,c=l?n.doc.lineAt(a?l.fromA:l.fromB).number-1-e:n.doc.lines,d=c-u+1;if(d>=t&&r.add(n.doc.line(u).from,n.doc.line(c).to,Xe.replace({widget:new vg(d),block:!0})),!l)break;o=n.doc.lineAt(Math.min(n.doc.length,a?l.toA:l.toB)).number}return r.finish()}var oF=Ie.styleModule.of(new lr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),zC=Ie.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),kC=new zr,af=new zr,lf=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||UC;let t=[Na.low(cf),zC,oF,Hu,Ie.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(of)))&&this.measure()})],r=[dr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(nf);let a=Ct.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Ie.editorAttributes.of({class:"cm-merge-a"}),af.of(r),t]}),s=[dr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(nf);let o=Ct.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Ie.editorAttributes.of({class:"cm-merge-b"}),af.of(s),t]});this.chunks=is.build(a.doc,o.doc,this.diffConf);let i=[nr.init(()=>this.chunks),kC.of(e.collapseUnchanged?kg(e.collapseUnchanged):[])];a=a.update({effects:xt.appendConfig.of(i)}).state,o=o.update({effects:xt.appendConfig.of(i)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Ie({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Ie({state:o,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((o,i)=>o.compose(i.changes),Rn.empty(e[0].startState.doc.length));this.chunks=t==this.a?is.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):is.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),t.update([...e,r.state.update({effects:bg.of(this.chunks)})]);let s=t==this.a?this.b:this.a;s.update([s.state.update({effects:bg.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let o=this.a.dom.parentNode,i=this.b.dom.parentNode;o.remove(),i.remove(),this.editorDOM.insertBefore(s?o:i,this.editorDOM.firstChild),this.editorDOM.appendChild(s?i:o),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,o=this.revertToA,i=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,o=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(i=e.renderRevertControl),this.setupRevertControls(s,o,i)}let t="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(t||r||a){let s=[],o=[];if(t||r){let i=this.a.state.facet(dr),l=r?e.gutter!==!1:i.markGutter,u=t?e.highlightChanges!==!1:i.highlightChanges;s.push(af.reconfigure([dr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?nf:[]])),o.push(af.reconfigure([dr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?nf:[]]))}if(a){let i=kC.reconfigure(e.collapseUnchanged?kg(e.collapseUnchanged):[]);s.push(i),o.push(i)}this.a.dispatch({effects:s}),this.b.dispatch({effects:o})}this.scheduleMeasure()}setupRevertControls(e,t,r){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){nF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let o=this.chunks[s];if(o.fromA>r.to||o.fromB>a.to)break;if(o.fromA<r.from||o.fromB<a.from)continue;let i=this.a.lineBlockAt(o.fromA).top+"px";for(;t&&+t.dataset.chunk<s;)t=SC(t);t&&t.dataset.chunk==String(s)?(t.style.top!=i&&(t.style.top=i),t=t.nextSibling):e.insertBefore(this.renderRevertButton(i,s),t)}for(;t;)t=SC(t)}renderRevertButton(e,t){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(t)),r}revertClicked(e){let t=e.target,r;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(r=this.chunks[t.dataset.chunk])){let[a,s,o,i,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(o,Math.max(o,i-1));o!=i&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function SC(n){let e=n.nextSibling;return n.remove(),e}var iF=new class extends On{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},lF=Na.low(Gi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(cf))===null||e===void 0?void 0:e.gutter)||wt.empty},widgetMarker:(n,e)=>e instanceof uf?iF:null}));function WC(n){var e;let t=typeof n.original=="string"?ct.of(n.original.split(/\r?\n/)):n.original,r=n.diffConfig||UC;return[Na.low(cf),fF,zC,Ie.editorAttributes.of({class:"cm-merge-b"}),_C.of((a,s)=>{let o=s.effects.find(i=>i.is(Ag));return o&&(a=is.updateA(a,o.value.doc,s.startState.doc,o.value.changes,r)),s.docChanged&&(a=is.updateB(a,s.state.field(ji),s.newDoc,s.changes,r)),a}),dr.of({highlightChanges:n.highlightChanges!==!1,markGutter:n.gutter!==!1,syntaxHighlightDeletions:n.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=n.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:n.allowInlineDiffs?mF:void 0,side:"b"}),ji.init(()=>t),n.gutter!==!1?lF:[],n.collapseUnchanged?kg(n.collapseUnchanged):[],nr.init(a=>is.build(t,a.doc,r))]}var Ag=xt.define();var ji=vn.define({create:()=>ct.empty,update(n,e){for(let t of e.effects)t.is(Ag)&&(n=t.value.doc);return n}});var CC=new WeakMap,uf=class extends Ir{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function uF(n,e,t){let r=CC.get(e.changes);if(r)return r;let a=o=>{let{highlightChanges:i,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=n.facet(dr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let C=d.appendChild(document.createElement("div"));C.className="cm-chunkButtons";let k=b=>{b.preventDefault(),cF(o,o.posAtDOM(d))},v=b=>{b.preventDefault(),dF(o,o.posAtDOM(d))};if(typeof c=="function")C.appendChild(c("accept",k)),C.appendChild(c("reject",v));else{let b=C.appendChild(document.createElement("button"));b.name="accept",b.textContent=n.phrase("Accept"),b.onmousedown=k;let P=C.appendChild(document.createElement("button"));P.name="reject",P.textContent=n.phrase("Reject"),P.onmousedown=v}}if(t||e.fromA>=e.toA)return d;let f=o.state.field(ji).sliceString(e.fromA,e.endA),h=l&&n.facet(qs),p=w(),m=e.changes,g=0,x=!1;function w(){let C=d.appendChild(document.createElement("div"));return C.className="cm-deletedLine",C.appendChild(document.createElement("del"))}function y(C,k,v){for(let b=C;b<k;){if(f.charAt(b)==`
|
|
42
|
-
`){p.firstChild||p.appendChild(document.createElement("br")),p=
|
|
43
|
-
`,b);if(U>-1&&U<k&&(P=U),i&&g<m.length){let I=Math.max(0,x?m[g].toA:m[g].fromA);I<=P&&(P=I,x&&g++,M=!0)}if(P>b){let I=document.createTextNode(f.slice(b,P));if(N){let A=p.appendChild(document.createElement("span"));A.className=N,A.appendChild(I)}else p.appendChild(I);b=P}M&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let C=h.parser.parse(f),k=0;sg(C,{style:v=>iC(n,v)},(v,b,P)=>{v>k&&y(k,v,""),y(v,b,P),k=b}),y(k,f.length,"")}else y(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Xe.widget({block:!0,side:-1,widget:new uf(a)});return CC.set(e.changes,s),s}function cF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=n.state.field(nr).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=n.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),o=n.state.field(ji);a.fromB!=a.toB&&a.toA<=o.length&&(s+=n.state.lineBreak);let i=Rn.of({from:a.fromA,to:Math.min(o.length,a.toA),insert:s},o.length);return n.dispatch({effects:Ag.of({doc:i.apply(o),changes:i}),userEvent:"accept"}),!0}function dF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=t.field(nr).find(i=>i.fromB<=r&&i.endB>=r);if(!a)return!1;let o=t.field(ji).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=t.doc.length&&(o+=t.lineBreak),n.dispatch({changes:{from:a.fromB,to:Math.min(t.doc.length,a.toB),insert:o},userEvent:"revert"}),!0}function LC(n){let e=new jn;for(let t of n.field(nr)){let r=n.facet(dr).overrideChunk&&jC(n,t);e.add(t.fromB,t.fromB,uF(n,t,!!r))}return e.finish()}var fF=vn.define({create:n=>LC(n),update(n,e){return e.state.field(nr,!1)!=e.startState.field(nr,!1)?LC(e.state):n},provide:n=>Ie.decorations.from(n)}),IC=new WeakMap;function jC(n,e){let t=IC.get(e);if(t!==void 0)return t;t=null;let r=n.field(ji),a=n.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,o=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==o&&s<10){let i=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;i.push(Xe.widget({widget:new Sg(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&i.push(GC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(t=i)}return IC.set(e,t),t}var Sg=class extends Ir{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let t=document.createElement("del");return t.className="cm-deletedText",t.textContent=this.text,t}},hF=new class extends On{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},pF=Xe.line({class:"cm-inlineChangedLine"});function mF(n,e,t,r){let a=jC(n,e),s=0;if(!a)return!1;for(let o=n.doc.lineAt(e.fromB);;){for(r&&r.add(o.from,o.from,hF),t.add(o.from,o.from,pF);s<a.length&&a[s].to<=o.to;){let i=a[s++];t.add(i.from,i.to,i.value)}if(o.to>=e.endB)break;o=n.doc.lineAt(o.to+1)}return!0}function qC(n,e){if(!n||!e)return!1;let t=n.getInternalStack(),r=e.getInternalStack();return!t||!r?!1:t.equals(r)}function gF(n,e){return{from:n,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var df=class{constructor(e,t,r,a,s=64,o=4096){this.hl=e;this.lang=t;this.theme=r;this.targetLines=s;this.targetChars=o;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,t,r){let a=[],s=t;for(;s<=r;){let o=e.line(s),i=o,l=1,u=o.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;i=c,u+=1+c.length,l+=1}a.push(gF(o.from,i.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let t=0,r=this.chunks.length-1;for(;t<r;){let a=t+r+1>>1;this.chunks[a].from<=e?t=a:r=a-1}return t}firstLineOf(e,t){return e.lineAt(t.from).number}tokensAt(e,t){return e.lines?.[t]??null}tokensForLine(e,t){let r=e.line(t),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,t-this.firstLineOf(e,a))}}lineCountOf(e,t){return e.lineAt(t.to).number-e.lineAt(t.from).number+1}hasPendingWork(e,t){let r=this.firstNonFinal(0);return r>=0&&r<=t||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let t=Math.max(0,e);t<this.chunks.length;t++)if(!this.chunks[t].final)return t;return-1}tokenize(e,t,r=!0){let a=this.chunks[t],s=t>0?this.chunks[t-1]:null,o=s?.endState??null,i=t===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...o?{grammarState:o}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=o,a.endState=d,a.final=i,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),i&&qC(u,d)}ensureRange(e,t,r,a=16384){let s=!1,o=0,i=this.chunkIndexAt(t),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=i;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&o+(c.to-c.from)>a)break;this.tokenize(e,u,!0),o+=c.to-c.from,s=!0}return s}idleStep(e,t,r,a=()=>performance.now()){let s=a(),o=null,i=u=>{o=o?{from:Math.min(o.from,u.from),to:Math.max(o.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(i(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&qC(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=t)break}return{more:this.hasPendingWork(e,r),touched:o}}applyChanges(e,t){let r=new Set;if(e.iterChangedRanges((i,l)=>{let u=this.chunkIndexAt(i);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),t.length===0){this.layout(t);return}let a=[],s=0;for(let i=0;i<this.chunks.length;i++){let l=this.chunks[i],u=e.mapPos(l.to,1);if(u>t.length&&(u=t.length),u=t.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let o=a[a.length-1];o&&o.to<t.length&&(o.to=t.length,r.add(o));for(let i of r)i.lines=null,i.startState=null,i.final=!1,i.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(t,r)}splitOversized(e,t){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!t.has(a))continue;let s=e.lineAt(a.from).number,o=e.lineAt(a.to).number;if(o-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,o);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let t=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],o=this.lineCountOf(e,a),i=a.to-a.from;if(!(o>=t/2||i>=this.targetChars/2)&&!(o+this.lineCountOf(e,s)>t*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let t=this.rebalanceTarget(e);if(t===null)return!1;let r=this.chunks[t],a=this.chunks[t+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(t+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(t=>t.lines);if(!(e.length<=32)){e.sort((t,r)=>t.lastUsed-r.lastUsed);for(let t=0;t<e.length-32;t++)e[t].lines=null}}};var Vs=Me.define({combine:n=>n.length?n[n.length-1]:{theme:"dark-plus"}}),KC=xt.define(),bF=8;function VC(n){setTimeout(()=>{try{n.dispatch({effects:KC.of(null)})}catch{}},0)}function wF(n){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(n,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let t=setTimeout(n,0);return{cancel:()=>clearTimeout(t)}}var $C=new Map;function vF(n){let e=$C.get(n);return e||(e=Xe.mark({attributes:{style:`color:${n}`}}),$C.set(n,e)),e}var Pg=class{constructor(e){this.decorations=Xe.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let t=e.startState.facet(Vs),r=e.state.facet(Vs),a=t.lang!==r.lang||t.theme!==r.theme,s=e.transactions.some(o=>o.effects.some(i=>i.is(KC)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let t=e.state.facet(Vs),r=vi(t.lang);if(!r)return this.engine=null,Xe.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Xe.none;let s=t1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,eu().then(()=>Jc(r)).then(c=>{c&&!this.disposed&&VC(e)})),Xe.none;let o=`${r} ${t.theme}`;(!this.engine||this.engineKey!==o)&&(this.engine=new df(s,r,t.theme,a),this.engineKey=o);let i=this.engine,l=new jn,u=0;for(let{from:c,to:d}of e.visibleRanges){i.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=i.chunkIndexAt(d);u=Math.max(u,p+4);for(let m=i.chunkIndexAt(c);m<=p;m++){let g=i.chunks[m],x=i.firstLineOf(a,g),w=a.lineAt(g.to).number;for(let y=Math.max(f,x);y<=Math.min(h,w);y++){let C=i.tokensAt(g,y-x);if(!C)continue;let k=a.line(y);for(let v of C){if(!v.content||!v.color)continue;let b=g.from+v.offset,P=b+v.content.length;b<k.from||b>=P||P>k.to||l.add(b,P,vF(v.color))}}}}return this.horizon=u,i.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=wF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let t=this.engine.idleStep(e.state.doc,bF,this.horizon),r=t.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?VC(e):t.more&&this.scheduleIdle(e)}))}},ff=cr.fromClass(Pg,{decorations:n=>n.decorations});var hf=Ie.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),XC=Ie.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var YC=W(le(),1);function Ng(n,e){return[qd(),Ct.readOnly.of(!0),Ie.editable.of(!1),hf,XC,Vs.of({lang:n,theme:e}),ff]}function Rg({oldContent:n,newContent:e,language:t,viewMode:r="unified",className:a,theme:s="dark-plus"}){let o=(0,pf.useRef)(null);return(0,pf.useEffect)(()=>{let i=o.current;if(!i)return;let l;if(r==="split"){let u=new lf({a:{doc:n,extensions:Ng(t,s)},b:{doc:e,extensions:Ng(t,s)},parent:i,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=Ct.create({doc:e,extensions:[...Ng(t,s),WC({original:n,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Ie({state:u,parent:i});l=()=>c.destroy()}return l},[n,e,t,r,s]),(0,YC.jsx)("div",{ref:o,className:a})}var Vn=W($e(),1);var kF=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),r=Og(n.state,t.from);return r.line?SF(n):r.block?LF(n):!1};function Bg(n,e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let a=n(e,t);return a?(r(t.update(a)),!0):!1}}var SF=Bg(PF,0);var CF=Bg(sL,0);var LF=Bg((n,e)=>sL(n,e,AF(e)),0);function Og(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}var Uu=50;function IF(n,{open:e,close:t},r,a){let s=n.sliceDoc(r-Uu,r),o=n.sliceDoc(a,a+Uu),i=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(o)[0].length,u=s.length-i;if(s.slice(u-e.length,u)==e&&o.slice(l,l+t.length)==t)return{open:{pos:r-i,margin:i&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*Uu?c=d=n.sliceDoc(r,a):(c=n.sliceDoc(r,r+Uu),d=n.sliceDoc(a-Uu,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-t.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+t.length)==t?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-t.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function AF(n){let e=[];for(let t of n.selection.ranges){let r=n.doc.lineAt(t.from),a=t.to<=r.to?r:n.doc.lineAt(t.to);a.from>r.from&&a.from==t.to&&(a=t.to==r.to+1?r:n.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function sL(n,e,t=e.selection.ranges){let r=t.map(s=>Og(e,s.from).block);if(!r.every(s=>s))return null;let a=t.map((s,o)=>IF(e,r[o],s.from,s.to));if(n!=2&&!a.every(s=>s))return{changes:e.changes(t.map((s,o)=>a[o]?[]:[{from:s.from,insert:r[o].open+" "},{from:s.to,insert:" "+r[o].close}]))};if(n!=1&&a.some(s=>s)){let s=[];for(let o=0,i;o<a.length;o++)if(i=a[o]){let l=r[o],{open:u,close:c}=i;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function PF(n,e,t=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:o}of t){let i=r.length,l=1e9,u;for(let c=s;c<=o;){let d=e.doc.lineAt(c);if(u==null&&(u=Og(e,d.from).line,!u))continue e;if(d.from>a&&(s==o||o>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=i;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==i+1&&(r[i].single=!0)}if(n!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:i,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:i.from+u,insert:l+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:i,token:l}of r)if(i>=0){let u=o.from+i,c=u+l.length;o.text[c-o.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Tg=Wr.define(),NF=Wr.define(),RF=Me.define(),oL=Me.define({combine(n){return Ai(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(r,a)=>e(r,a)||t(r,a)})}}),iL=vn.define({create(){return Go.empty},update(n,e){let t=e.state.facet(oL),r=e.annotation(Tg);if(r){let l=fa.fromTransaction(e,r.selection),u=r.side,c=u==0?n.undone:n.done;return l?c=gf(c,c.length,t.minDepth,l):c=dL(c,e.startState.selection),new Go(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(NF);if((a=="full"||a=="before")&&(n=n.isolate()),e.annotation(Pn.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let s=fa.fromTransaction(e),o=e.annotation(Pn.time),i=e.annotation(Pn.userEvent);return s?n=n.addChanges(s,o,i,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,i,t.newGroupDelay)),(a=="full"||a=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Go(n.done.map(fa.fromJSON),n.undone.map(fa.fromJSON))}});function lL(n={}){return[iL,oL.of(n),Ie.domEventHandlers({beforeinput(e,t){let r=e.inputType=="historyUndo"?uL:e.inputType=="historyRedo"?Dg:null;return r?(e.preventDefault(),r(t)):!1}})]}function xf(n,e){return function({state:t,dispatch:r}){if(!e&&t.readOnly)return!1;let a=t.field(iL,!1);if(!a)return!1;let s=a.pop(n,t,e);return s?(r(s),!0):!1}}var uL=xf(0,!1),Dg=xf(1,!1),MF=xf(0,!0),TF=xf(1,!0);var fa=class n{constructor(e,t,r,a,s){this.changes=e,this.effects=t,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new n(e.changes&&Rn.fromJSON(e.changes),[],e.mapped&&ts.fromJSON(e.mapped),e.startSelection&&se.fromJSON(e.startSelection),e.selectionsAfter.map(se.fromJSON))}static fromTransaction(e,t){let r=Kr;for(let a of e.startState.facet(RF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),r,void 0,t||e.startState.selection,Kr)}static selection(e){return new n(void 0,Kr,void 0,void 0,e)}};function gf(n,e,t,r){let a=e+1>t+20?e-t-1:0,s=n.slice(a,e);return s.push(r),s}function DF(n,e){let t=[],r=!1;return n.iterChangedRanges((a,s)=>t.push(a,s)),e.iterChangedRanges((a,s,o,i)=>{for(let l=0;l<t.length;){let u=t[l++],c=t[l++];i>=u&&o<=c&&(r=!0)}}),r}function FF(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,r)=>t.empty!=e.ranges[r].empty).length===0}function cL(n,e){return n.length?e.length?n.concat(e):n:e}var Kr=[],EF=200;function dL(n,e){if(n.length){let t=n[n.length-1],r=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-EF));return r.length&&r[r.length-1].eq(e)?n:(r.push(e),gf(n,n.length-1,1e9,t.setSelAfter(r)))}else return[fa.selection([e])]}function BF(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Mg(n,e){if(!n.length)return n;let t=n.length,r=Kr;for(;t;){let a=OF(n[t-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=n.slice(0,t);return s[t-1]=a,s}else e=a.mapped,t--,r=a.selectionsAfter}return r.length?[fa.selection(r)]:Kr}function OF(n,e,t){let r=cL(n.selectionsAfter.length?n.selectionsAfter.map(i=>i.map(e)):Kr,t);if(!n.changes)return fa.selection(r);let a=n.changes.map(e),s=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(s):s;return new fa(a,xt.mapEffects(n.effects,e),o,n.startSelection.map(s),r)}var _F=/^(input\.type|delete)($|\.)/,Go=class n{constructor(e,t,r=0,a=void 0){this.done=e,this.undone=t,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,r,a,s){let o=this.done,i=o[o.length-1];return i&&i.changes&&!i.changes.empty&&e.changes&&(!r||_F.test(r))&&(!i.selectionsAfter.length&&t-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,DF(i.changes,e.changes))||r=="input.type.compose")?o=gf(o,o.length-1,a.minDepth,new fa(e.changes.compose(i.changes),cL(xt.mapEffects(e.effects,i.changes),i.effects),i.mapped,i.startSelection,Kr)):o=gf(o,o.length,a.minDepth,e),new n(o,Kr,t,r)}addSelection(e,t,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Kr;return s.length>0&&t-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&FF(s[s.length-1],e)?this:new n(dL(this.done,e),this.undone,t,r)}addMapping(e){return new n(Mg(this.done,e),Mg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(r&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Tg.of({side:e,rest:BF(a),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=a.length==1?Kr:a.slice(0,a.length-1);return s.mapped&&(i=Mg(i,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Tg.of({side:e,rest:i,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};Go.empty=new Go(Kr,Kr);var fL=[{key:"Mod-z",run:uL,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Dg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Dg,preventDefault:!0},{key:"Mod-u",run:MF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:TF,preventDefault:!0}];function qi(n,e){return se.create(n.ranges.map(e),n.mainIndex)}function ha(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function pa({state:n,dispatch:e},t){let r=qi(n.selection,t);return r.eq(n.selection,!0)?!1:(e(ha(n,r)),!0)}function yf(n,e){return se.cursor(e?n.to:n.from)}function hL(n,e){return pa(n,t=>t.empty?n.moveByChar(t,e):yf(t,e))}function qn(n){return n.textDirectionAt(n.state.selection.main.head)==Wt.LTR}var pL=n=>hL(n,!qn(n)),mL=n=>hL(n,qn(n));function gL(n,e){return pa(n,t=>t.empty?n.moveByGroup(t,e):yf(t,e))}var HF=n=>gL(n,!qn(n)),UF=n=>gL(n,qn(n));var Cj=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function GF(n,e,t){if(e.type.prop(t))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function bf(n,e,t){let r=os(n).resolveInner(e.head),a=t?lt.closedBy:lt.openedBy;for(let l=e.head;;){let u=t?r.childAfter(l):r.childBefore(l);if(!u)break;GF(n,u,a)?r=u:l=t?u.to:u.from}let s=r.type.prop(a),o,i;return s&&(o=t?_o(n,r.from,1):_o(n,r.to,-1))&&o.matched?i=t?o.end.to:o.end.from:i=t?r.to:r.from,se.cursor(i,t?-1:1)}var zF=n=>pa(n,e=>bf(n.state,e,!qn(n))),WF=n=>pa(n,e=>bf(n.state,e,qn(n)));function xL(n,e){return pa(n,t=>{if(!t.empty)return yf(t,e);let r=n.moveVertically(t,e);return r.head!=t.head?r:n.moveToLineBoundary(t,e)})}var yL=n=>xL(n,!1),bL=n=>xL(n,!0);function wL(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,r=0,a;if(e){for(let s of n.state.facet(Ie.scrollMargins)){let o=s(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(r=Math.max(o?.bottom,r))}a=n.scrollDOM.clientHeight-t-r}else a=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:r,selfScroll:e,height:Math.max(n.defaultLineHeight,a-5)}}function vL(n,e){let t=wL(n),{state:r}=n,a=qi(r.selection,o=>o.empty?n.moveVertically(o,e,t.height):yf(o,e));if(a.eq(r.selection))return!1;let s;if(t.selfScroll){let o=n.coordsAtPos(r.selection.main.head),i=n.scrollDOM.getBoundingClientRect(),l=i.top+t.marginTop,u=i.bottom-t.marginBottom;o&&o.top>l&&o.bottom<u&&(s=Ie.scrollIntoView(a.main.head,{y:"start",yMargin:o.top-l}))}return n.dispatch(ha(r,a),{effects:s}),!0}var JC=n=>vL(n,!1),Fg=n=>vL(n,!0);function $s(n,e,t){let r=n.lineBlockAt(e.head),a=n.moveToLineBoundary(e,t);if(a.head==e.head&&a.head!=(t?r.to:r.from)&&(a=n.moveToLineBoundary(e,t,!1)),!t&&a.head==r.from&&r.length){let s=/^\s*/.exec(n.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=se.cursor(r.from+s))}return a}var jF=n=>pa(n,e=>$s(n,e,!0)),qF=n=>pa(n,e=>$s(n,e,!1)),VF=n=>pa(n,e=>$s(n,e,!qn(n))),$F=n=>pa(n,e=>$s(n,e,qn(n))),KF=n=>pa(n,e=>n.moveToLineBoundary(e,!1,!1)),XF=n=>pa(n,e=>n.moveToLineBoundary(e,!0,!1));function YF(n,e,t){let r=!1,a=qi(n.selection,s=>{let o=_o(n,s.head,-1)||_o(n,s.head,1)||s.head>0&&_o(n,s.head-1,1)||s.head<n.doc.length&&_o(n,s.head+1,-1);if(!o||!o.end)return s;r=!0;let i=o.start.from==s.head?o.end.to:o.end.from;return t?se.range(s.anchor,i):se.cursor(i)});return r?(e(ha(n,a)),!0):!1}var JF=({state:n,dispatch:e})=>YF(n,e,!1);function Xr(n,e,t){let r=qi(n.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=se.range(a.head,a.anchor));let s=t(a);return se.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(n.state.selection)?!1:(n.dispatch(ha(n.state,r)),!0)}function kL(n,e){return Xr(n,e,t=>n.moveByChar(t,e))}var SL=n=>kL(n,!qn(n)),CL=n=>kL(n,qn(n));function LL(n,e){return Xr(n,e,t=>n.moveByGroup(t,e))}var ZF=n=>LL(n,!qn(n)),QF=n=>LL(n,qn(n));var e5=n=>{let e=!qn(n);return Xr(n,e,t=>bf(n.state,t,e))},t5=n=>{let e=qn(n);return Xr(n,e,t=>bf(n.state,t,e))};function IL(n,e){return Xr(n,e,t=>n.moveVertically(t,e))}var AL=n=>IL(n,!1),PL=n=>IL(n,!0);function NL(n,e){return Xr(n,e,t=>n.moveVertically(t,e,wL(n).height))}var ZC=n=>NL(n,!1),QC=n=>NL(n,!0),n5=n=>Xr(n,!0,e=>$s(n,e,!0)),r5=n=>Xr(n,!1,e=>$s(n,e,!1)),a5=n=>{let e=!qn(n);return Xr(n,e,t=>$s(n,t,e))},s5=n=>{let e=qn(n);return Xr(n,e,t=>$s(n,t,e))},o5=n=>Xr(n,!1,e=>se.cursor(n.lineBlockAt(e.head).from)),i5=n=>Xr(n,!0,e=>se.cursor(n.lineBlockAt(e.head).to)),eL=({state:n,dispatch:e})=>(e(ha(n,{anchor:0})),!0),tL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.doc.length})),!0),nL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.selection.main.anchor,head:0})),!0),rL=({state:n,dispatch:e})=>(e(ha(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),l5=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),u5=({state:n,dispatch:e})=>{let t=wf(n).map(({from:r,to:a})=>se.undirectionalRange(r,Math.min(a+1,n.doc.length)));return e(n.update({selection:se.create(t),userEvent:"select"})),!0},c5=({state:n,dispatch:e})=>{let t=qi(n.selection,r=>{let a=os(n),s=a.resolveStack(r.from,1);if(r.empty){let o=a.resolveStack(r.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:i}=o;if((i.from<r.from&&i.to>=r.to||i.to>r.to&&i.from<=r.from)&&o.next)return se.undirectionalRange(i.from,i.to)}return r});return t.eq(n.selection)?!1:(e(ha(n,t)),!0)};function RL(n,e){let{state:t}=n,r=t.selection,a=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<n.state.doc.length:o.from>0)for(let i=s;;){let l=n.moveVertically(i,e);if(l.head<o.from||l.head>o.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==i.head)break;i=l}}}return a.length==r.ranges.length?!1:(n.dispatch(ha(t,se.create(a,a.length-1))),!0)}var d5=n=>RL(n,!1),f5=n=>RL(n,!0),h5=({state:n,dispatch:e})=>{let t=n.selection,r=null;return t.ranges.length>1?r=se.create([t.main]):t.main.empty||(r=se.create([se.cursor(t.main.head)])),r?(e(ha(n,r)),!0):!1};function Gu(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:r}=n,a=r.changeByRange(s=>{let{from:o,to:i}=s;if(o==i){let l=e(s);l<o?(t="delete.backward",l=mf(n,l,!1)):l>o&&(t="delete.forward",l=mf(n,l,!0)),o=Math.min(o,l),i=Math.max(i,l)}else o=mf(n,o,!1),i=mf(n,i,!0);return o==i?{range:s}:{changes:{from:o,to:i},range:se.cursor(o,o<s.head?-1:1)}});return a.changes.empty?!1:(n.dispatch(r.update(a,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?Ie.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function mf(n,e,t){if(n instanceof Ie)for(let r of n.state.facet(Ie.atomicRanges).map(a=>a(n)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=t?s:a)});return e}var ML=(n,e,t)=>Gu(n,r=>{let a=r.from,{state:s}=n,o=s.doc.lineAt(a),i,l;if(t&&!e&&a>o.from&&a<o.from+200&&!/[^ \t]/.test(i=o.text.slice(0,a-o.from))){if(i[i.length-1]==" ")return a-1;let u=Io(i,s.tabSize),c=u%Eu(s)||Eu(s);for(let d=0;d<c&&i[i.length-1-d]==" ";d++)a--;l=a}else l=Nn(o.text,a-o.from,e,e)+o.from,l==a&&o.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(l-o.from,a-o.from))&&(l=Nn(o.text,l-o.from,!1,!1)+o.from);return l}),Eg=n=>ML(n,!1,!0);var TL=n=>ML(n,!0,!1),DL=(n,e)=>Gu(n,t=>{let r=t.head,{state:a}=n,s=a.doc.lineAt(r),o=a.charCategorizer(r);for(let i=null;;){if(r==(e?s.to:s.from)){r==t.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=Nn(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=o(u);if(i!=null&&c!=i)break;(u!=" "||r!=t.head)&&(i=c),r=l}return r}),FL=n=>DL(n,!1),p5=n=>DL(n,!0);var m5=n=>Gu(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var g5=n=>Gu(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),x5=n=>Gu(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var y5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ct.of(["",""])},range:se.cursor(r.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},b5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>{if(!r.empty||r.from==0||r.from==n.doc.length)return{range:r};let a=r.from,s=n.doc.lineAt(a),o=a==s.from?a-1:Nn(s.text,a-s.from,!1)+s.from,i=a==s.to?a+1:Nn(s.text,a-s.from,!0)+s.from;return{changes:{from:o,to:i,insert:n.doc.slice(a,i).append(n.doc.slice(o,a))},range:se.cursor(i)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function wf(n){let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.from),s=n.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=n.doc.lineAt(r.to-1)),t>=a.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});t=s.number+1}return e}function EL(n,e,t){if(n.readOnly)return!1;let r=[],a=[];for(let s of wf(n)){if(t?s.to==n.doc.length:s.from==0)continue;let o=n.doc.lineAt(t?s.to+1:s.from-1),i=o.length+1;if(t){r.push({from:s.to,to:o.to},{from:s.from,insert:o.text+n.lineBreak});for(let l of s.ranges)a.push(se.range(Math.min(n.doc.length,l.anchor+i),Math.min(n.doc.length,l.head+i)))}else{r.push({from:o.from,to:s.from},{from:s.to,insert:n.lineBreak+o.text});for(let l of s.ranges)a.push(se.range(l.anchor-i,l.head-i))}}return r.length?(e(n.update({changes:r,scrollIntoView:!0,selection:se.create(a,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var w5=({state:n,dispatch:e})=>EL(n,e,!1),v5=({state:n,dispatch:e})=>EL(n,e,!0);function BL(n,e,t){if(n.readOnly)return!1;let r=[];for(let s of wf(n))t?r.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):r.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});let a=n.changes(r);return e(n.update({changes:a,selection:n.selection.map(a,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var k5=({state:n,dispatch:e})=>BL(n,e,!1),S5=({state:n,dispatch:e})=>BL(n,e,!0),C5=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(wf(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=qi(e.selection,a=>{let s;if(n.lineWrapping){let o=n.lineBlockAt(a.head),i=n.coordsAtPos(a.head,a.assoc||1);i&&(s=o.bottom+n.documentTop-i.bottom+n.defaultLineHeight/2)}return n.moveVertically(a,!0,s)}).map(t);return n.dispatch({changes:t,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function L5(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=os(n).resolveInner(e),r=t.childBefore(e),a=t.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(lt.closedBy))&&s.indexOf(a.name)>-1&&n.doc.lineAt(r.to).from==n.doc.lineAt(a.from).from&&!/\S/.test(n.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var aL=OL(!1),I5=OL(!0);function OL(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:o}=a,i=e.doc.lineAt(s),l=!n&&s==o&&L5(e,s);n&&(s=o=(o<=i.to?i:e.doc.lineAt(o)).to);let u=new Oo(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=mg(u,s);for(c==null&&(c=Io(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<i.to&&/\s/.test(i.text[o-i.from]);)o++;l?{from:s,to:o}=l:s>i.from&&s<i.from+100&&!/\S/.test(i.text.slice(0,s))&&(s=i.from);let d=["",Bu(e,c)];return l&&d.push(Bu(e,u.lineIndent(i.from,-1))),{changes:{from:s,to:o,insert:ct.of(d)},range:se.cursor(s+1+d[1].length)}});return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function _g(n,e){let t=-1;return n.changeByRange(r=>{let a=[];for(let o=r.from;o<=r.to;){let i=n.doc.lineAt(o);i.number>t&&(r.empty||r.to>i.from)&&(e(i,a,r),t=i.number),o=i.to+1}let s=n.changes(a);return{changes:a,range:se.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var A5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),r=new Oo(n,{overrideIndentation:s=>{let o=t[s];return o??-1}}),a=_g(n,(s,o,i)=>{let l=mg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=Bu(n,l);(u!=c||i.from<s.from+u.length)&&(t[s.from]=l,o.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(n.update(a,{userEvent:"indent"})),!0},_L=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(_g(n,(t,r)=>{r.push({from:t.from,insert:n.facet(ef)})}),{userEvent:"input.indent"})),!0),HL=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(_g(n,(t,r)=>{let a=/^\s*/.exec(t.text)[0];if(!a)return;let s=Io(a,n.tabSize),o=0,i=Bu(n,Math.max(0,s-Eu(n)));for(;o<a.length&&o<i.length&&a.charCodeAt(o)==i.charCodeAt(o);)o++;r.push({from:t.from+o,to:t.from+a.length,insert:i.slice(o)})}),{userEvent:"delete.dedent"})),!0),P5=n=>(n.setTabFocusMode(),!0);var N5=[{key:"Ctrl-b",run:pL,shift:SL,preventDefault:!0},{key:"Ctrl-f",run:mL,shift:CL},{key:"Ctrl-p",run:yL,shift:AL},{key:"Ctrl-n",run:bL,shift:PL},{key:"Ctrl-a",run:KF,shift:o5},{key:"Ctrl-e",run:XF,shift:i5},{key:"Ctrl-d",run:TL},{key:"Ctrl-h",run:Eg},{key:"Ctrl-k",run:m5},{key:"Ctrl-Alt-h",run:FL},{key:"Ctrl-o",run:y5},{key:"Ctrl-t",run:b5},{key:"Ctrl-v",run:Fg}],R5=[{key:"ArrowLeft",run:pL,shift:SL,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:HF,shift:ZF,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:VF,shift:a5,preventDefault:!0},{key:"ArrowRight",run:mL,shift:CL,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:UF,shift:QF,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$F,shift:s5,preventDefault:!0},{key:"ArrowUp",run:yL,shift:AL,preventDefault:!0},{mac:"Cmd-ArrowUp",run:eL,shift:nL},{mac:"Ctrl-ArrowUp",run:JC,shift:ZC},{key:"ArrowDown",run:bL,shift:PL,preventDefault:!0},{mac:"Cmd-ArrowDown",run:tL,shift:rL},{mac:"Ctrl-ArrowDown",run:Fg,shift:QC},{key:"PageUp",run:JC,shift:ZC},{key:"PageDown",run:Fg,shift:QC},{key:"Home",run:qF,shift:r5,preventDefault:!0},{key:"Mod-Home",run:eL,shift:nL},{key:"End",run:jF,shift:n5,preventDefault:!0},{key:"Mod-End",run:tL,shift:rL},{key:"Enter",run:aL,shift:aL},{key:"Mod-a",run:l5},{key:"Backspace",run:Eg,shift:Eg,preventDefault:!0},{key:"Delete",run:TL,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:FL,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:p5,preventDefault:!0},{mac:"Mod-Backspace",run:g5,preventDefault:!0},{mac:"Mod-Delete",run:x5,preventDefault:!0}].concat(N5.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),UL=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:zF,shift:e5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:WF,shift:t5},{key:"Alt-ArrowUp",run:w5},{key:"Shift-Alt-ArrowUp",run:k5},{key:"Alt-ArrowDown",run:v5},{key:"Shift-Alt-ArrowDown",run:S5},{key:"Mod-Alt-ArrowUp",run:d5},{key:"Mod-Alt-ArrowDown",run:f5},{key:"Escape",run:h5},{key:"Mod-Enter",run:I5},{key:"Alt-l",mac:"Ctrl-l",run:u5},{key:"Mod-i",run:c5,preventDefault:!0},{key:"Mod-[",run:HL},{key:"Mod-]",run:_L},{key:"Mod-Alt-\\",run:A5},{key:"Shift-Mod-k",run:C5},{key:"Shift-Mod-\\",run:JF},{key:"Mod-/",run:kF},{key:"Alt-A",mac:"Ctrl-A",run:CF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:P5}].concat(R5),GL={key:"Tab",run:_L,shift:HL};var M5={lines:new Map,deletedBefore:new Set},zL=xt.define(),WL=vn.define({create:()=>M5,update(n,e){for(let t of e.effects)if(t.is(zL))return t.value;return n}}),zu=class extends On{constructor(t){super();this.kind=t}eq(t){return t.kind===this.kind}toDOM(){let t=document.createElement("div");return this.kind==="deleted"?t.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":t.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,t}},T5=new zu("added"),D5=new zu("modified"),F5=new zu("deleted"),E5=Gi({class:"nrs-cm-git-gutter",lineMarker(n,e){let t=n.state.field(WL,!1);if(!t)return null;let r=n.state.doc.lineAt(e.from).number,a=t.lines.get(r);return a==="added"?T5:a==="modified"?D5:t.deletedBefore.has(r)?F5:null},lineMarkerChange:n=>n.transactions.some(e=>e.effects.some(t=>t.is(zL)))});function jL(n){return[WL.init(()=>n),E5]}var qL=W(le(),1);function Hg({value:n,language:e,readOnly:t=!1,wrap:r=!1,onChange:a,className:s,placeholder:o,ariaLabel:i,theme:l="dark-plus",gitLineStatus:u}){let c=(0,Vn.useRef)(null),d=(0,Vn.useRef)(null),f=(0,Vn.useRef)(a),h=(0,Vn.useRef)(!1),p=(0,Vn.useRef)(new zr),m=(0,Vn.useRef)(new zr),g=(0,Vn.useRef)(new zr),x=(0,Vn.useRef)(new zr);return f.current=a,(0,Vn.useEffect)(()=>{let w=c.current;if(!w)return;let y=Ct.create({doc:n,extensions:[qd(),GS(),jS(),HS(),lL(),$m.of([...UL,...fL,GL]),hf,p.current.of(Vs.of({lang:e,theme:l})),ff,m.current.of([Ct.readOnly.of(t),Ie.editable.of(!t)]),g.current.of(r?Ie.lineWrapping:[]),x.current.of([]),o?zS(o):[],Ie.updateListener.of(k=>{k.docChanged&&!h.current&&f.current?.(k.state.doc.toString())}),Ie.contentAttributes.of(i?{"aria-label":i}:{})]}),C=new Ie({state:y,parent:w});return d.current=C,()=>{C.destroy(),d.current=null}},[]),(0,Vn.useEffect)(()=>{let w=d.current;if(!w)return;let y=w.state.doc.toString();n!==y&&(h.current=!0,w.dispatch({changes:{from:0,to:y.length,insert:n}}),h.current=!1)},[n]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:p.current.reconfigure(Vs.of({lang:e,theme:l}))})},[e,l]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:m.current.reconfigure([Ct.readOnly.of(t),Ie.editable.of(!t)])})},[t]),(0,Vn.useEffect)(()=>{let w=d.current;w&&w.dispatch({effects:g.current.reconfigure(r?Ie.lineWrapping:[])})},[r]),(0,Vn.useEffect)(()=>{let w=d.current;if(!w)return;let y=u&&!sd(u)?jL(u):[];w.dispatch({effects:x.current.reconfigure(y)})},[u]),(0,qL.jsx)("div",{ref:c,className:s})}var Vi=W($e(),1);var VL=W(le(),1);function Ug({target:n,agentId:e,projectId:t}){let[r,a]=(0,Vi.useState)(!1),s=B(i=>i.sourceChangeRevision[n.source]??0);(0,Vi.useEffect)(()=>{let i=!0;return a(!1),e&&Xo({agentId:e,...t?{projectId:t}:{},source:n.source}).then(l=>{i&&a(l.repos.find(u=>u.rel===(n.repo??""))?.canWrite===!0)}).catch(()=>{i&&a(!1)}),()=>{i=!1}},[e,t,n.source,n.repo,s]);let o=(0,Vi.useMemo)(()=>$v(n),[n]);return(0,VL.jsx)(bo,{source:n.source,repo:n.repo??"",path:n.path,mode:o,agentId:e,projectId:t,variant:"tab",canWrite:r,revision:s})}var Ba=W($e(),1);var ft=W(le(),1),$L="brain://docs",Gg=q("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),B5=q(Gg,"pr-6");function zg(n){let{agentId:e,projectId:t}=n,r=B(b=>b.workspacePanels.upload),a=B(b=>b.setWorkspacePanelOpen),s=B(b=>b.uploading),o=B(b=>b.uploadMany),i=B(b=>b.files),l=B(b=>b.activeFolderPath),u=B(b=>b.setActiveFolderPath),[c,d]=(0,Ba.useState)(""),[f,h]=(0,Ba.useState)(""),[p,m]=(0,Ba.useState)(!1),[g,x]=(0,Ba.useState)(!1),w=(0,Ba.useRef)(null),y=(0,Ba.useMemo)(()=>{let b=c.trim();return b||l||$L},[l,c]),C=(0,Ba.useMemo)(()=>{let b=new Set;for(let P of Object.values(i||{})){if(P?.type!=="folder")continue;let N=String(P.uri||"");N&&b.add(N)}return b.add($L),Array.from(b).sort((P,N)=>P.localeCompare(N))},[i]),k=b=>{let P=b.trim();P&&(d(P),u(P))},v=async b=>{if(b.length!==0)try{await o({agentId:e,projectId:t,files:b,uri:y})}finally{w.current&&(w.current.value=""),m(!1),a("upload",!1)}};return r?(0,ft.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,ft.jsx)("input",{ref:w,type:"file",multiple:!0,className:"hidden",onChange:async b=>{let P=Array.from(b.target.files||[]);await v(P)}}),(0,ft.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,ft.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,ft.jsx)(ze,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,ft.jsx)(Sa,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,ft.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,ft.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:y})]}),(0,ft.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,ft.jsx)("div",{className:q("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:b=>{s||(b.preventDefault(),m(!0))},onDragOver:b=>{s||(b.preventDefault(),b.dataTransfer.dropEffect="copy",m(!0))},onDragLeave:b=>{b.currentTarget.contains(b.relatedTarget)||m(!1)},onDrop:async b=>{s||(b.preventDefault(),await v(Array.from(b.dataTransfer.files||[])))},children:(0,ft.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,ft.jsx)(ze,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,ft.jsx)(Sa,{className:"h-4 w-4 text-cyan-200/70"}),(0,ft.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,ft.jsxs)("button",{type:"button",onClick:()=>w.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,ft.jsx)(Pl,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,ft.jsxs)("div",{className:"mt-1",children:[(0,ft.jsxs)("button",{type:"button",onClick:()=>x(b=>!b),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,ft.jsx)(wr,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,ft.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,ft.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:y}),(0,ft.jsx)(Tt,{className:q("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",g&&"rotate-180")})]}),(0,ft.jsx)("div",{className:q("overflow-hidden transition-all duration-200",g?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,ft.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,ft.jsxs)("div",{className:"space-y-1",children:[(0,ft.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,ft.jsx)("select",{value:y,onChange:b=>k(b.target.value),disabled:s,className:B5,children:C.map(b=>(0,ft.jsx)("option",{value:b,className:"bg-[#1a1a1f]",children:b},b))})]}),(0,ft.jsxs)("div",{className:"space-y-1",children:[(0,ft.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,ft.jsx)("input",{value:c,onChange:b=>d(b.target.value),placeholder:y,disabled:s,className:Gg})]}),(0,ft.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ft.jsx)("input",{value:f,onChange:b=>h(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),k(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:q(Gg,"flex-1")}),(0,ft.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{k(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,ft.jsx)(wr,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Se=W($e(),1);var Xg=W(mr(),1);function O5(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var _5=new Set(["path","container-path","host-path"]);function KL(n){let e=O5(n),t=e.properties.root,r=t?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(t&&(e.required.includes("root")||a&&_5.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var ln=W($e(),1);var XL=W(mr(),1);var ke=W(le(),1),$i={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function YL({agentId:n,projectId:e}){let t=hn(),r=Xa({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),[a,s]=(0,ln.useState)(null),[o,i]=(0,ln.useState)(null),[l,u]=(0,ln.useState)(!1),[c,d]=(0,ln.useState)(!1),[f,h]=(0,ln.useState)(null),[p,m]=(0,ln.useState)(null),[g,x]=(0,ln.useState)(null),[w,y]=(0,ln.useState)(null),[C,k]=(0,ln.useState)(!1),[v,b]=(0,ln.useState)(!1),[P,N]=(0,ln.useState)(24),[M,U]=(0,ln.useState)(null),I=(0,ln.useRef)(null),A=(0,ln.useCallback)(async()=>{u(!0),x(null);try{let[L,R]=await Promise.all([ix({agentId:n,...e?{projectId:e}:{}}),yx({agentId:n,...e?{projectId:e}:{}}).catch(()=>[])]),z=new Map;for(let Q of R)z.set(Q.source,{...Q.last_sync?{last_sync:Q.last_sync}:{},sync_status:Q.sync_status});let J=L;J.perSource&&(J.perSource=J.perSource.map(Q=>{let re=z.get(Q.source);return re?{...Q,...re}:Q})),s(J)}catch(L){x(L instanceof Error?L.message:"Failed to fetch health report")}finally{u(!1)}},[n,e]),G=(0,ln.useCallback)(async()=>{k(!0),x(null);try{let L=await lx({agentId:n,...e?{projectId:e}:{}});y({orphanChunkCount:L.orphanChunkCount??0,duplicateGroups:L.duplicateGroups??0})}catch(L){x(L instanceof Error?L.message:"Scan failed")}finally{k(!1)}},[n,e]),V=(0,ln.useCallback)(async L=>{if(!v&&$i[L].destructive&&M!==L){U(L),I.current&&clearTimeout(I.current),I.current=setTimeout(()=>U(null),3e3);return}I.current&&(clearTimeout(I.current),I.current=null),U(null),d(!0),h(null),m(L),x(null),i(v?null:a);try{let R=await ux({agentId:n,...e?{projectId:e}:{},action:L,dryRun:v,retentionHours:P});h(R),v||(A(),w&&G())}catch(R){x(R instanceof Error?R.message:"Action failed")}finally{d(!1)}},[n,e,v,P,A,M,a,w,G]);(0,ln.useEffect)(()=>{A()},[A]),(0,ln.useEffect)(()=>()=>{I.current&&clearTimeout(I.current)},[]);function K(L){if(!o||!a)return null;let R=o[L]??0,z=a[L]??0;if(R===z)return null;let J=R-z,Q=J>0?"\u2212":"+";return`${R} \u2192 ${z} (${Q}${Math.abs(J)})`}return(0,ke.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[(0,ke.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,ke.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,ke.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,ke.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,ke.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),l&&(0,ke.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,ke.jsx)(Ht,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),g&&(0,ke.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:g}),a&&(0,ke.jsxs)(ke.Fragment,{children:[(0,ke.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:a.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:a.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:a.deletedCount??0,color:(a.deletedCount??0)>0?"text-red-400":"text-white/60",delta:p==="gc"?K("deletedCount"):null},{label:"Orphans",value:w?w.orphanChunkCount??0:"\u2014",color:(w?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(L=>(0,ke.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,ke.jsx)("div",{className:q("text-sm font-semibold",L.color),children:L.value}),(0,ke.jsx)("div",{className:"text-[9px] text-white/40",children:L.label}),L.delta&&(0,ke.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:L.delta})]},L.label))}),(0,ke.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,ke.jsxs)("span",{children:["Total points: ",a.totalPoints??"-"]}),(0,ke.jsxs)("span",{children:["Duplicate groups: ",w?w.duplicateGroups??0:"\u2014"]}),a.generatedAt&&(()=>{let L=Date.now()-new Date(a.generatedAt).getTime(),R=Math.floor(L/6e4),z=Math.floor(R/60),J=R<1?"just now":z<1?`${R}m ago`:`${z}h ${R%60}m ago`,Q=z<1?"text-emerald-400/60":"text-amber-400/60";return(0,ke.jsxs)("span",{className:Q,children:["Generated: ",J]})})()]}),a.perSource&&a.perSource.length>0&&(0,ke.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,ke.jsxs)("table",{className:"w-full text-[10px]",children:[(0,ke.jsx)("thead",{children:(0,ke.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,ke.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,ke.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,ke.jsx)("tbody",{children:a.perSource.map((L,R)=>{let z=L.source.includes(":")?L.source.split(":")[0]:L.source,J=z==="local"?"text-cyan-400/60":z==="github"?"text-amber-400/60":"text-violet-400/60",Q=(()=>{if(!L.last_sync)return L.sync_status==="idle"?"\u2014":L.sync_status??"\u2014";let pe=new Date(L.last_sync).getTime();if(Number.isNaN(pe))return L.last_sync;let ee=Math.floor((Date.now()-pe)/6e4);if(ee<1)return"just now";if(ee<60)return`${ee}m ago`;let ce=Math.floor(ee/60);return ce<24?`${ce}h ago`:`${Math.floor(ce/24)}d ago`})(),re=L.last_sync?L.sync_status==="error"?"text-rose-300/60":L.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,ke.jsxs)("tr",{className:q("border-b border-white/[0.03] last:border-0",R%2===1&&"bg-white/[0.02]"),children:[(0,ke.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,ke.jsx)(Gn,{className:q("h-2.5 w-2.5 shrink-0",J)}),L.source]}),(0,ke.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:L.documents}),(0,ke.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:L.chunks}),(0,ke.jsx)("td",{className:q("px-2 py-1 text-right",L.deleted>0?"text-red-300/60":"text-white/40"),children:L.deleted}),(0,ke.jsx)("td",{className:q("px-2 py-1 text-right",re),title:L.last_sync??`status: ${L.sync_status??"unknown"}`,children:Q})]},L.source)})})]})}),(0,ke.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,ke.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ke.jsxs)("button",{type:"button",onClick:()=>{A()},disabled:l,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,ke.jsx)(Ht,{className:q("h-3 w-3 text-blue-400",l&&"animate-spin")}),"Refresh"]}),(0,ke.jsxs)("button",{type:"button",onClick:()=>{G()},disabled:C,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,ke.jsx)(Ka,{className:q("h-3 w-3 text-amber-400",C&&"animate-pulse")}),w?"Re-scan":"Scan for problems"]}),(0,ke.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...r?["repair-pending"]:[],"deduplicate"].map(L=>{let R=$i[L],z=L==="gc"?It:L==="repair-orphans"?Al:L==="repair-pending"?ys:ra,J=L==="gc"?"text-amber-400":L==="repair-orphans"?"text-cyan-400":L==="repair-pending"?"text-rose-300":"text-violet-400",Q=M===L;return(0,ke.jsxs)("button",{type:"button",onClick:()=>{V(L)},disabled:c,title:R.tooltip,className:q("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",Q?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,ke.jsx)(z,{className:q("h-3 w-3",J)}),Q?"Click again to confirm":R.label]},L)}),(0,ke.jsx)("span",{className:"text-white/10",children:"|"}),(0,ke.jsx)(XL.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync-status.sh","scripts/reindex.sh"],label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,ke.jsxs)("div",{className:"flex items-center gap-3",children:[(0,ke.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,ke.jsx)("input",{type:"checkbox",checked:v,onChange:L=>b(L.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,ke.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,ke.jsx)("input",{type:"number",min:1,value:P,onChange:L=>N(Math.max(1,Number(L.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,ke.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",$i.gc.explainer]}),(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",$i["repair-orphans"].explainer]}),(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",$i.deduplicate.explainer]}),r?(0,ke.jsxs)("div",{children:[(0,ke.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",$i["repair-pending"].explainer]}):null]}),f&&(0,ke.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,ke.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,ke.jsx)("span",{children:"Last Action Result"}),typeof f.removed=="number"&&(0,ke.jsxs)("span",{className:q("font-mono tabular-nums",f.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[f.dryRun?"Would remove":"Removed",": ",f.removed]})]}),Object.entries(f).map(([L,R])=>(0,ke.jsxs)("div",{className:"flex justify-between",children:[(0,ke.jsx)("span",{className:"text-white/40",children:L}),(0,ke.jsx)("span",{className:"text-white/70 font-mono",children:typeof R=="object"?JSON.stringify(R):String(R)})]},L))]})]})]})}var nn=W($e(),1);var Be=W(le(),1),H5=["member","owner","admin"],vf=["read","write","exec"];function U5(n){return{default:{...n.default},...n.byRole?{byRole:Wg(n.byRole)}:{},...n.byUser?{byUser:Wg(n.byUser)}:{},...n.byAgent?{byAgent:Wg(n.byAgent)}:{},paths:(n.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function Wg(n){let e={};for(let[t,r]of Object.entries(n))e[t]={...r};return e}function G5(n){return{pattern:`${n}://`,permissions:{read:!0,write:!1,exec:!1}}}function jg({letter:n,state:e,onClick:t,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,Be.jsx)("button",{type:"button",title:a??`${n} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:t,className:q("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:n})}function qg(n){return n==="read"?"R":n==="write"?"W":"X"}function JL(n,e){if(!e)return!n;if(n===void 0)return!0;if(n===!0)return!1}function Vg({source:n,permissions:e,mode:t,onSave:r,knownRoles:a=H5}){let[s,o]=(0,nn.useState)(()=>U5(e)),[i,l]=(0,nn.useState)(!1),[u,c]=(0,nn.useState)(null),[d,f]=(0,nn.useState)(""),[h,p]=(0,nn.useState)(""),[m,g]=(0,nn.useState)(""),x=(0,nn.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),w=t==="view",y=(0,nn.useCallback)((L,R)=>{o(z=>({...z,default:{...z.default,[L]:R}}))},[]),C=L=>L,k=(0,nn.useCallback)((L,R)=>{let z=R.trim();z&&o(J=>{let Q={...J[C(L)]??{}};return z in Q?J:(Q[z]={},{...J,[C(L)]:Q})})},[]),v=(0,nn.useCallback)((L,R)=>{o(z=>{let J={...z[C(L)]??{}};return delete J[R],Object.keys(J).length===0?{...z,[C(L)]:void 0}:{...z,[C(L)]:J}})},[]),b=(0,nn.useCallback)((L,R,z)=>{o(J=>{let Q={...J[C(L)]??{}},re=Q[R]??{},pe=JL(re[z],!0),ee={...re};return pe===void 0?delete ee[z]:ee[z]=pe,Q[R]=ee,{...J,[C(L)]:Q}})},[]),P=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]];return J[L]={...J[L],...R},{...z,paths:J}})},[]),N=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]],Q=J[L],re=JL(Q.permissions[R],!0),pe={...Q.permissions};return re===void 0?delete pe[R]:pe[R]=re,J[L]={...Q,permissions:pe},{...z,paths:J}})},[]),M=(0,nn.useCallback)((L,R)=>{o(z=>{let J=[...z.paths??[]],Q=J[L],re=new Set(Q.roles??[]);return re.has(R)?re.delete(R):re.add(R),J[L]=re.size>0?{...Q,roles:[...re]}:{...Q,roles:void 0},{...z,paths:J}})},[]),U=(0,nn.useCallback)((L,R,z)=>{let J=z.trim();J&&o(Q=>{let re=[...Q.paths??[]],pe=re[L],ee=new Set(pe[R]??[]);return ee.add(J),re[L]={...pe,[R]:[...ee]},{...Q,paths:re}})},[]),I=(0,nn.useCallback)((L,R,z)=>{o(J=>{let Q=[...J.paths??[]],re=Q[L],pe=(re[R]??[]).filter(ee=>ee!==z);return Q[L]={...re,[R]:pe.length>0?pe:void 0},{...J,paths:Q}})},[]),A=(0,nn.useCallback)(()=>{o(L=>({...L,paths:[G5(n),...L.paths??[]]}))},[n]),G=(0,nn.useCallback)(L=>{o(R=>({...R,paths:(R.paths??[]).filter((z,J)=>J!==L)}))},[]),V=(0,nn.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(L){c(L instanceof Error?L.message:String(L))}finally{l(!1)}}},[s,r]),K=(L,R,z,J,Q)=>{let re=s[C(L)]??{},pe=Object.entries(re),[ee,ce]=Q;return(0,Be.jsxs)("div",{className:"space-y-1",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:R}),(0,Be.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:z})]}),pe.length===0&&w?(0,Be.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,pe.map(([ue,He])=>(0,Be.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,Be.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:ue}),vf.map(De=>(0,Be.jsx)(jg,{letter:qg(De),state:He[De],onClick:w?void 0:()=>b(L,ue,De),disabled:w},De)),!w&&(0,Be.jsx)("button",{type:"button",onClick:()=>v(L,ue),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,Be.jsx)(It,{className:"w-3 h-3"})})]},ue)),!w&&(0,Be.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,Be.jsx)("input",{type:"text",value:ee,onChange:ue=>ce(ue.target.value),onKeyDown:ue=>{ue.key==="Enter"&&(ue.preventDefault(),k(L,ee),ce(""))},placeholder:J,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,Be.jsxs)("button",{type:"button",onClick:()=>{k(L,ee),ce("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Be.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,Be.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,Be.jsx)("div",{className:"space-y-1",children:(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,Be.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",n,"://*"]}),(0,Be.jsx)("div",{className:"flex items-center gap-1",children:vf.map(L=>(0,Be.jsx)(jg,{letter:qg(L),state:s.default[L],onClick:w?void 0:()=>y(L,!s.default[L]),disabled:w},L))})]})}),K("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),K("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),K("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[m,g]),(0,Be.jsxs)("div",{className:"space-y-1",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Be.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,Be.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!w&&(0,Be.jsxs)("button",{type:"button",onClick:A,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Be.jsx)(Fn,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,Be.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,Be.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((L,R)=>(0,Be.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,Be.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Be.jsx)("input",{type:"text",disabled:w,value:L.pattern,onChange:z=>P(R,{pattern:z.target.value}),placeholder:`${n}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),vf.map(z=>(0,Be.jsx)(jg,{letter:qg(z),state:L.permissions[z],onClick:w?void 0:()=>N(R,z),disabled:w},z)),(0,Be.jsx)("button",{type:"button",disabled:w,onClick:()=>P(R,{override:L.override?void 0:!0}),title:"Override deny-wins precedence",className:q("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",L.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!w&&(0,Be.jsx)("button",{type:"button",onClick:()=>G(R),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,Be.jsx)(It,{className:"w-3 h-3"})})]}),(0,Be.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Be.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(z=>{let J=(L.roles??[]).includes(z);return(0,Be.jsx)("button",{type:"button",disabled:w,onClick:()=>M(R,z),className:q("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",J?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:z},z)}),(L.roles??[]).length===0&&(0,Be.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,Be.jsx)(ZL,{label:"Agents",values:L.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:w,onAdd:z=>U(R,"agents",z),onRemove:z=>I(R,"agents",z)}),(0,Be.jsx)(ZL,{label:"Users",values:L.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:w,onAdd:z=>U(R,"users",z),onRemove:z=>I(R,"users",z)}),(L.users??[]).length>0&&!z5(L)&&(0,Be.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},R))})]}),!w&&(0,Be.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,Be.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,Be.jsxs)("button",{type:"button",onClick:V,disabled:!x||i,className:q("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||i)&&"opacity-40 cursor-default"),children:[(0,Be.jsx)(io,{className:"w-3 h-3"}),i?"Saving\u2026":"Save policy"]})]})]})}function z5(n){let e=vf.map(t=>n.permissions[t]).filter(t=>t!==void 0);return n.override===!0&&e.length>0&&e.every(t=>t===!0)}function ZL({label:n,values:e,emptyLabel:t,placeholder:r,readOnly:a,onAdd:s,onRemove:o}){return(0,Be.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Be.jsxs)("span",{className:"text-white/35 mr-0.5",children:[n,":"]}),e.map(i=>(0,Be.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,Be.jsx)("span",{className:"font-mono",children:i}),!a&&(0,Be.jsx)("button",{type:"button",onClick:()=>o(i),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${i}`,children:"\xD7"})]},i)),e.length===0&&(0,Be.jsx)("span",{className:"italic text-white/30",children:t}),!a&&(0,Be.jsx)(W5,{placeholder:r,onAdd:s})]})}function W5({placeholder:n,onAdd:e}){let[t,r]=(0,nn.useState)("");return(0,Be.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,Be.jsx)("input",{type:"text",value:t,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(t),r(""))},placeholder:n,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,Be.jsx)("button",{type:"button",onClick:()=>{e(t),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,Be.jsx)(Fn,{className:"w-3 h-3"})})]})}var QL=W($e(),1);var $t=W(le(),1);function eI({source:n,vectorCount:e,isDockerMount:t,busy:r,onCancel:a,onConfirm:s}){let[o,i]=(0,QL.useState)(!1);return(0,$t.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,$t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,$t.jsx)(dt,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,$t.jsx)("span",{className:"font-mono text-rose-200",children:n}),"?"]}),(0,$t.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,$t.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,$t.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,$t.jsx)("input",{type:"checkbox",checked:o,onChange:l=>i(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,$t.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,$t.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,$t.jsxs)("code",{className:"font-mono text-white/55",children:[n,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),t&&(0,$t.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,$t.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["pnpm neuralis:mount remove ",n]})]}),(0,$t.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,$t.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,$t.jsx)(Ut,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,$t.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:o}),disabled:r,className:q("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,$t.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,$t.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete",o?" + Purge":""]})]})]})}var S=W(le(),1),$g={exclude:[],trigger:"manual"},j5=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],q5=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],Yg="Mounted (user-added)";function V5(n){return n&&n.trim().length>0?n:Yg}function $5(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Lf(n){return n.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function K5(n){return n.split(/[/\\]/).filter(Boolean).pop()??null}function X5(n){if(n?.name){let e=Lf(n.name);if(e)return e}if(n?.email){let e=Lf(n.email.split("@")[0]??"");if(e)return e}return"user"}function rI(n){let{baseName:e,meta:t,scope:r,ids:a}=n,o=(e?Lf(e):"")||(t?.urlScheme||t?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?o:r==="user"?`${o}-${a.userSlug||"user"}`:`${o}-${a.agentSlug||$5(a.agentId)}`}function Y5(n){return n?.allowedScopes?.length?n.allowedScopes:["project","user","agent"]}function Jg(n){return!!n?.capabilities.includes("scanDelta")}function Zg(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function J5(n){let e=Zg(n),t={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(t[r]=s)}return t}function aI(n){let e=n?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function Wu(n,e){let t=n?.defaultScope??"project",r=aI(n);return{key:rI({baseName:null,meta:n,scope:t,ids:e}),path:"",scope:t,...r,syncEnabled:Jg(n),exclude:Sf(n?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:J5(n),policies:[],recognizesPackages:!1}}function ju(n){return n.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Sf(n){return Array.isArray(n)?n.join(`
|
|
44
|
-
`):""}function
|
|
45
|
-
`);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function sI(n){if(n==="auto"||n==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(n);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function Cf(n){return n==="s"?30:1}function Kg(n,e,t){if(n!=="interval")return n;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,Cf(t)):5}${t}`}function tE(n){let e=sI(n);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function nE(n,e){let t=n.connection.config??{};for(let[r,a]of Object.entries(t)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??n.connection.kind}function rE(n,e){let t=n.permissions??aI(e);return{source:Ve(n.uri_root),source_kind:n.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:n.source_kind,config:{}},permissions:{default:t},sync_status:n.sync_status,last_updated:n.last_updated,kind_label:e?.label??n.source_kind,kind_trust:e?.trust??null,observed:!0,...n.origin_package?{origin_package:n.origin_package}:{},...n.live!==void 0?{live:n.live}:{},...n.live_reason?{live_reason:n.live_reason}:{}}}function aE(n,e){return JSON.stringify(Ki(n))!==JSON.stringify(e)}function nI(n){if(!n)return"never";let e=Date.now()-new Date(n).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var zo=q("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),kf=q(zo,"pr-6 font-mono"),qu=q("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function oI(n){let{agentId:e,projectId:t,isDocker:r}=n,a=B(T=>T.workspacePanels.sources),s=B(T=>T.setWorkspacePanelOpen),o=B(T=>T.pendingSourceSuggestion),i=B(T=>T.setPendingSourceSuggestion),l=B(T=>T.refresh),u=B(T=>T.sources),c=hn(),d=c.useAgents(),f=(0,Se.useMemo)(()=>X5(c.currentUser),[c.currentUser]),h=(c.currentRole?.priority??99)<=2,p=(0,Se.useMemo)(()=>oi({grantedFeatures:[...c.grantedFeatures??[]]},{features:["drive.mount"]}),[c.grantedFeatures]),m=(0,Se.useMemo)(()=>{let T=d.byId[e]?.name;return T?Lf(T):void 0},[d,e]),g=(0,Se.useMemo)(()=>({userSlug:f,agentSlug:m,agentId:e}),[f,m,e]),[x,w]=(0,Se.useState)([]),[y,C]=(0,Se.useState)({}),[k,v]=(0,Se.useState)({}),[b,P]=(0,Se.useState)({}),[N,M]=(0,Se.useState)(new Set),[U,I]=(0,Se.useState)({}),[A,G]=(0,Se.useState)(!1),[V,K]=(0,Se.useState)(null),[L,R]=(0,Se.useState)(null),[z,J]=(0,Se.useState)(null),[Q,re]=(0,Se.useState)(null),[pe,ee]=(0,Se.useState)(null),[ce,ue]=(0,Se.useState)(null),[He,De]=(0,Se.useState)(null),[je,et]=(0,Se.useState)(null),[Dt,at]=(0,Se.useState)(null),[vt,Pt]=(0,Se.useState)(null),[Ye,Ne]=(0,Se.useState)("source"),[tt,Je]=(0,Se.useState)(""),[Ft,Mt]=(0,Se.useState)(!0),[Te,oe]=(0,Se.useState)(null),[jt,Kt]=(0,Se.useState)(!1),de=(0,Se.useRef)(0);(0,Se.useEffect)(()=>{de.current++,Pt(null),oe(null)},[e,t]);let[fe,qe]=(0,Se.useState)(null),[Re,Fe]=(0,Se.useState)(!1),[Lt,st]=(0,Se.useState)("project"),[Le,Ee]=(0,Se.useState)(()=>Wu(null,g)),Et=(0,Se.useRef)(Le.key),qt=(0,Se.useRef)(!0);(0,Se.useEffect)(()=>(qt.current=!0,()=>{qt.current=!1}),[]);let[Tn,te]=(0,Se.useState)(!1),[Ce,Ge]=(0,Se.useState)(!1),[Ke,Ae]=(0,Se.useState)(!1),[he,ut]=(0,Se.useState)(!1),[Qt,xn]=(0,Se.useState)([]),[yn,Nr]=(0,Se.useState)("/"),[Kn,Xn]=(0,Se.useState)(!1),[Rr,Yn]=(0,Se.useState)(null),[Mr,j]=(0,Se.useState)([]),[ie,Ue]=(0,Se.useState)(!1),[Bt,Xt]=(0,Se.useState)([]),[dn,Sn]=(0,Se.useState)("local"),[hr,Ua]=(0,Se.useState)(null),[Jr,Ys]=(0,Se.useState)([]);(0,Se.useEffect)(()=>{let T=!1;return bx().then(Z=>{if(T)return;Xt(Z.kinds??[]),Ua(null);let F=Z.kinds?.find(ge=>ge.kind==="local")??Z.kinds?.[0]??null;if(F){Sn(F.kind);let ge=Wu(F,g);Et.current=ge.key,Ee(ge)}}).catch(Z=>{T||Ua(Z instanceof Error?Z.message:"Failed to load source kinds")}),()=>{T=!0}},[e]);let Hn=(0,Se.useMemo)(()=>{let T=new Map;for(let Z of Bt)T.set(Z.kind,Z);return T},[Bt]),rn=Hn.get(dn)??null,Jn=Jg(rn),pr=KL(rn),E=pr.needed,ne=E&&pr.container,O=(0,Se.useCallback)(T=>{let Z=Wu(Hn.get(T.suggestedKind)??null,g),F=T.suggestedConfig.root??"",ge=T.suggestedConfig.hostRoot;Sn(T.suggestedKind),Et.current=T.suggestedScheme,Ee({...Z,key:T.suggestedScheme,path:F,...T.suggestedScope?{scope:T.suggestedScope}:{},...T.syncDisabled?{syncEnabled:!1}:{},...T.suggestedSync?.include?{include:Sf(T.suggestedSync.include)}:{},...T.suggestedSync?.trigger?{trigger:T.suggestedSync.trigger}:{},...T.suggestedPolicies?.length?{policies:T.suggestedPolicies}:{},...T.description?{description:T.description}:{},...T.suggestedAccess??{},config:{...Z.config,...ge&&Zg(Hn.get(T.suggestedKind)??null).properties.hostRoot?{hostRoot:ge}:{}}}),Fe(!0)},[Hn,g]);(0,Se.useEffect)(()=>{o&&Hn.size!==0&&(i(null),O(o))},[o,Hn,O,i]);let Pe=(0,Se.useCallback)((T,Z)=>rI({baseName:Z?K5(Z):null,meta:rn,scope:T,ids:g}),[rn,g]),D=T=>T===""||T===Et.current,me=(0,Se.useCallback)(async()=>{if(t){G(!0),K(null);try{let[T,Z]=await Promise.all([F0({agentId:e,projectId:t,scope:Lt}),Zu({agentId:e,projectId:t}).catch(()=>({suggestions:[]}))]);w(T),C(Object.fromEntries(T.map(F=>[F.source,Ki(F)]))),v(F=>Object.fromEntries(T.map(ge=>[ge.source,F[ge.source]??!1]))),Ys(Z.suggestions??[])}catch(T){K(T instanceof Error?T.message:"Failed to load sources")}finally{G(!1)}}},[Lt,e,t]);(0,Se.useEffect)(()=>{a&&me()},[a,me]),(0,Se.useEffect)(()=>{a&&e&&l({agentId:e,projectId:t})},[a,e,t,l]);let Yt=(0,Se.useCallback)(async T=>{if(!e||b[T])return;let Z=!1;if(M(F=>{if(F.has(T))return Z=!0,F;let ge=new Set(F);return ge.add(T),ge}),!Z)try{let F=await D0(e,t??void 0,T);F&&P(ge=>({...ge,[T]:F}))}catch{}finally{M(F=>{if(!F.has(T))return F;let ge=new Set(F);return ge.delete(T),ge})}},[e,t,b]),Ot=(0,Se.useCallback)(T=>{P(Z=>{if(!(T in Z))return Z;let F={...Z};return delete F[T],F})},[]),Cn=(0,Se.useCallback)(T=>{v(Z=>{let F=!Z[T];return F&&Yt(T),{...Z,[T]:F}})},[Yt]);(0,Se.useEffect)(()=>{if(!He)return;let T=setTimeout(()=>De(null),4e3);return()=>clearTimeout(T)},[He]),(0,Se.useEffect)(()=>{!Re||!r||!p||(Ue(!0),Zf({path:"/mounts",agentId:e,...t?{projectId:t}:{}}).then(T=>{let Z=new Set(x.map(ge=>ge.source)),F=T.entries.filter(ge=>!Z.has(ge.name));j(F)}).catch(()=>j([])).finally(()=>Ue(!1)))},[Re,r,p,e,t,x]);let Tr=(0,Se.useMemo)(()=>{let T=new Set,Z=x.map(F=>{T.add(F.source);let ge=u.find(fn=>Ve(fn.uri_root)===F.source),an=b[F.source]??ge;return{...F,connector_count:an?.on_disk,connector_truncated:an?.truncated,indexed_count:an?.indexed_count,unindexed_count:an?.unindexed,last_updated:ge?.last_updated??F.last_updated,sync_status:F.sync?.status??ge?.sync_status??F.sync_status,live:ge?.live,live_reason:ge?.live_reason,kind_icon:ge?.kind_icon}});if(Lt==="project")for(let F of u){let ge=Ve(F.uri_root);if(!ge||T.has(ge))continue;let an=Hn.get(F.source_kind)??null,fn=b[ge]??F;Z.push({...rE(F,an),connector_count:fn.on_disk,connector_truncated:fn.truncated,indexed_count:fn.indexed_count,unindexed_count:fn.unindexed,kind_icon:F.kind_icon})}return Z},[Lt,x,Hn,u,b]),Gf=(0,Se.useMemo)(()=>{let T=new Map;for(let Z of Tr){let F=V5(Z.origin_package),ge=T.get(F);ge?ge.push(Z):T.set(F,[Z])}return[...T.entries()].sort(([Z],[F])=>Z===Yg?1:F===Yg?-1:Z.localeCompare(F))},[Tr]),Zr=(T,Z)=>{C(F=>({...F,[T]:Z(F[T])}))},zf=(T,Z)=>{I(F=>({...F,[T]:{...F[T]??{},[Z]:!(F[T]?.[Z]??!1)}}))},f2=async(T,Z)=>{R(T.source),K(null);try{let F=!Z.sync&&!!T.sync,ge=h&&T.connection.kind==="local",{recognizesPackages:an,...fn}=Z,us=await Yf({agentId:e,...t?{projectId:t}:{},config:{...ge?Z:fn,...F?{clearSync:!0}:{}}});w(Ga=>Ga.map(za=>za.source===us.source?us:za)),C(Ga=>({...Ga,[us.source]:Ki(us)})),eE(T,Z,F)?(await l({agentId:e,projectId:t,withCounts:!0}),Ot(T.source)):await l({agentId:e,projectId:t})}catch(F){K(F instanceof Error?F.message:"Save failed")}finally{R(null)}},h2=(0,Se.useCallback)(async(T,Z)=>{let F=y[T.source]??Ki(T);R(T.source),K(null);try{let ge=await Yf({agentId:e,...t?{projectId:t}:{},config:{...F,permissions:Z}});w(an=>an.map(fn=>fn.source===ge.source?ge:fn)),C(an=>({...an,[ge.source]:Ki(ge)})),await l({agentId:e,projectId:t})}catch(ge){throw K(ge instanceof Error?ge.message:"Save failed"),ge}finally{R(null)}},[e,y,t,l]),f0=(0,Se.useCallback)(async T=>{for(let ge=0;ge<2400;ge++){if(await new Promise(qo=>setTimeout(qo,1500)),!qt.current)return;let fn=(await B0({agentId:e,...t?{projectId:t}:{},source:T})).job;if(!fn)return;if(!(fn.status==="pending"||fn.status==="running")){if(fn.status==="failed")throw new Error(fn.error??fn.result?.error??"Sync failed");return}}},[e,t]);if(!a)return null;let p2=async T=>{J(T),K(null);try{await E0({agentId:e,...t?{projectId:t}:{},source:T}),await f0(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}),Ot(T)}catch(Z){K(Z instanceof Error?Z.message:"Sync failed")}finally{J(null)}},m2=async T=>{try{await xx({agentId:e,...t?{projectId:t}:{},...T?{source:T}:{}}),J(null),re(null)}catch(Z){K(Z instanceof Error?Z.message:"Cancel failed")}},h0=async(T,Z,F)=>{re(T),K(null);try{await Z(),await f0(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}),Ot(T)}catch(ge){K(ge instanceof Error?ge.message:F)}finally{re(null)}},g2=T=>h0(T,()=>hx({agentId:e,...t?{projectId:t}:{},source:T}),"Rescan failed"),p0=async(T,Z)=>{let F=++de.current,ge=Ye==="source"?{kind:"source"}:{kind:Ye,uri:tt};Kt(!0),K(null);try{let an=await px({agentId:e,...t?{projectId:t}:{},source:T,selector:ge,mode:Z,obsoleteOnly:Ft});if(F!==de.current)return;Z==="estimate"?oe(an):(Pt(null),oe(null),Ot(T),await me(),await l({agentId:e,projectId:t,withCounts:!0}))}catch(an){F===de.current&&K(an instanceof Error?an.message:"Index cleanup failed")}finally{F===de.current&&Kt(!1)}},x2=async T=>{et(T),K(null);try{await fx({agentId:e,...t?{projectId:t}:{},source:T}),await me()}catch(Z){K(Z instanceof Error?Z.message:"Reset failed")}finally{et(null)}},y2=async(T,Z)=>{qe(T),K(null);try{await O0({agentId:e,...t?{projectId:t}:{},source:T,enabled:Z}),await me()}catch(F){K(F instanceof Error?F.message:"Toggle failed")}finally{qe(null)}},b2=async(T,Z)=>{ee(T),K(null);try{let F=await dx({agentId:e,...t?{projectId:t}:{},source:T,...Z.purgeVectors?{purgeVectors:!0}:{}});await me(),await l({agentId:e,projectId:t}),Ot(T),De(Z.purgeVectors&&F?.purgeJob?`Deleted "${T}" (vector purge running in background)`:`Deleted "${T}"`),ue(null)}catch(F){K(F instanceof Error?F.message:"Delete failed")}finally{ee(null)}},Wf=async T=>{ut(!0),Xn(!0),Yn(null);try{let Z=await Zf({path:T,agentId:e,...t?{projectId:t}:{}});xn(Z.entries),Nr(T)}catch{Yn("That path is not available."),xn([])}finally{Xn(!1)}},m0=T=>{Ee(Z=>{if(!D(Z.key))return{...Z,path:T};let F=Pe(Z.scope,T);return Et.current=F,{...Z,path:T,key:F}}),ut(!1)},w2=async()=>{if(!(!Le.key||E&&!Le.path)){te(!0),K(null);try{let T={...Le.config,...E?{root:Le.path}:{}};await cx({agentId:e,...t?{projectId:t}:{},source:Le.key,scope:Le.scope,connection:{kind:dn,config:T},permissions:{default:{read:Le.read,write:Le.write,exec:Le.exec},...Le.policies.length>0?{paths:Le.policies}:{}},...Le.description.trim()?{description:Le.description.trim()}:{},...Jn&&Le.syncEnabled?{sync:{exclude:ju(Le.exclude),trigger:Le.trigger,...ju(Le.include).length>0?{include:ju(Le.include)}:{}}}:{},...h&&dn==="local"&&Le.recognizesPackages?{recognizesPackages:!0}:{}}),Fe(!1);{let Z=Wu(rn,g);Et.current=Z.key,Ee(Z)}await me(),await l({agentId:e,projectId:t})}catch(T){K(T instanceof Error?T.message:"Add source failed")}finally{te(!1)}}},v2=T=>T==="data"||T==="packages";return(0,S.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,S.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,S.jsx)(br,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,S.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:Tr.length})]}),(0,S.jsxs)("div",{className:"flex items-center gap-1",children:[(0,S.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Fe(T=>!T),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,S.jsx)(Fn,{className:"h-3 w-3"}),"Source"]}),(0,S.jsx)(Xg.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync.sh","scripts/reindex.sh","scripts/set-enabled.sh"],label:"Manage sources with the agent"})]}),(0,S.jsx)("button",{type:"button",onClick:()=>{me()},disabled:A,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,S.jsx)(Ht,{className:q("mx-auto h-3 w-3",A&&"animate-spin")})}),(0,S.jsx)("button",{type:"button",onClick:()=>s("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,S.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,S.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,S.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,S.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(T=>(0,S.jsx)("button",{type:"button",onClick:()=>st(T.id),className:q("h-6 rounded px-2 text-[9px] font-semibold transition",Lt===T.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:T.label},T.id))}),V&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:V}),Re&&(0,S.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,S.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),hr&&(0,S.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",hr,'. Falling back to "local".']}),Bt.length>1&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,S.jsx)("select",{value:dn,onChange:T=>{let Z=T.target.value,F=Hn.get(Z)??null;Sn(Z);let ge=Wu(F,g);Et.current=ge.key,Ee(ge)},className:kf,children:Bt.map(T=>(0,S.jsxs)("option",{value:T.kind,children:[T.label," \u2014 ",T.trust," (",T.packageId,")"]},T.kind))}),(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:rn?.description??""})]}),rn?.scopeSelectable&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,S.jsx)("select",{value:Le.scope,onChange:T=>{let Z=T.target.value;Ee(F=>{if(!D(F.key))return{...F,scope:Z};let ge=Pe(Z,F.path);return Et.current=ge,{...F,scope:Z,key:ge}})},className:kf,children:Y5(rn).map(T=>(0,S.jsx)("option",{value:T,children:T},T))})]}),ne&&r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,S.jsx)("code",{className:"text-amber-200/90 font-mono",children:"pnpm neuralis:mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),ie?(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsx)(ze,{className:"h-3 w-3 animate-spin text-white/30"}),(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):Mr.length>0?(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),Mr.map(T=>(0,S.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,S.jsx)(Br,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:T.name}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:T.path}),(0,S.jsx)("button",{type:"button",onClick:()=>{Ee(Z=>({...Z,key:T.name,path:T.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},T.path))]}):(0,S.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:E?pr.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsxs)("div",{className:q("grid gap-2",E?"grid-cols-2":"grid-cols-1"),children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,S.jsx)("input",{type:"text",value:Le.key,onChange:T=>Ee(Z=>({...Z,key:T.target.value})),placeholder:Pe(Le.scope,Le.path),className:zo}),(0,S.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Le.key||Pe(Le.scope,Le.path),"://"]})]}),E&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:pr.label}),(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"text",value:Le.path,onChange:T=>Ee(Z=>({...Z,path:T.target.value})),placeholder:pr.placeholder,className:q(zo,"flex-1")}),pr.container&&!r&&p&&(0,S.jsx)("button",{type:"button",onClick:()=>{Wf(Le.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,S.jsx)(Ss,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(Zg(rn).properties).filter(([T])=>T!=="root").map(([T,Z])=>(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:Z?.["x-neuralis"]?.ui?.label??T}),(0,S.jsx)("input",{type:Z.type==="number"||Z.type==="integer"?"number":"text",value:String(Le.config[T]??""),onChange:F=>Ee(ge=>({...ge,config:{...ge.config,[T]:F.target.value}})),placeholder:Z?.["x-neuralis"]?.ui?.placeholder??Z?.description??T,className:zo})]},T)),ne&&!r&&he&&(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,S.jsx)(Ss,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:yn}),(0,S.jsx)("button",{type:"button",onClick:()=>ut(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Rr&&(0,S.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Rr}),Kn?(0,S.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,S.jsx)(ze,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,S.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[yn!=="/"&&(0,S.jsxs)("button",{type:"button",onClick:()=>{let T=yn.replace(/[/\\][^/\\]+$/,"")||"/";Wf(T)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,S.jsx)(ja,{className:"h-3 w-3 text-white/30"}),(0,S.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),Qt.length===0&&!Kn&&(0,S.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),Qt.map(T=>(0,S.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>{Wf(T.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,S.jsx)(Br,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:T.name})]}),(0,S.jsx)("button",{type:"button",onClick:()=>m0(T.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},T.path)),(0,S.jsxs)("button",{type:"button",onClick:()=>m0(yn),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,S.jsx)(ea,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,S.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:yn})]})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center gap-2",children:[(0,S.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:wl},{key:"write",label:"Write",icon:ao},{key:"exec",label:"Exec",icon:si}].map(({key:T,label:Z,icon:F})=>(0,S.jsxs)("label",{className:q("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Le[T]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,S.jsx)("input",{type:"checkbox",className:"sr-only",checked:Le[T],onChange:ge=>Ee(an=>({...an,[T]:ge.target.checked}))}),(0,S.jsx)(F,{className:"h-2.5 w-2.5"}),Z,(0,S.jsx)("span",{className:q("h-1.5 w-1.5 rounded-full",Le[T]?"bg-emerald-300/80":"bg-white/20")})]},T))]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,S.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,S.jsx)("input",{value:Le.description,onChange:T=>Ee(Z=>({...Z,description:T.target.value})),className:zo,placeholder:rn?.description??"What this source is for\u2026",maxLength:200})]}),Jn&&(0,S.jsx)("div",{className:"flex items-center gap-2",children:(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Le.syncEnabled,onChange:T=>Ee(Z=>({...Z,syncEnabled:T.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),Jn&&Le.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,S.jsx)("textarea",{value:Le.exclude,onChange:T=>Ee(Z=>({...Z,exclude:T.target.value})),rows:2,className:qu,placeholder:"node_modules/**"})]}),Jn&&Le.syncEnabled&&(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,S.jsx)("textarea",{value:Le.include,onChange:T=>Ee(Z=>({...Z,include:T.target.value})),rows:2,className:q(qu,"font-mono"),placeholder:`# empty = everything
|
|
46
|
-
skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),dn==="local"&&h&&(0,S.jsx)("div",{className:"space-y-1",children:(0,S.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Le.recognizesPackages,onChange:T=>Ee(Z=>({...Z,recognizesPackages:T.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load WASM packages dropped in this folder (in addition to ",(0,S.jsx)("code",{children:"_packages/"}),"). Advertised only within this source's scope."]})]})]})}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,S.jsx)("button",{type:"button",onClick:()=>Fe(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,S.jsxs)("button",{type:"button",onClick:()=>{w2()},disabled:Tn||!Le.key||E&&!Le.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Tn?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(Fn,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),Tr.length===0&&!A?(0,S.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,S.jsx)("div",{className:"mt-1 space-y-3",children:Gf.map(([T,Z])=>(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,S.jsx)(vr,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,S.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:T}),(0,S.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:Z.length})]}),(0,S.jsx)("div",{className:"space-y-0.5 pl-2",children:Z.map(F=>{let ge=y[F.source]??Ki(F),an=L===F.source,fn=z===F.source,qo=Q===F.source,us=pe===F.source,Ga=Hn.get(F.connection.kind)??null,za=Jg(Ga),Ju=za&&!!ge.sync,Un=ge.sync??$g,g0=(0,sr.resolveIconWithFallback)(F.kind_icon??Ga?.icon??void 0,Gn),x0=bc(F),y0=F.live===!1,k2=y0||F.enabled===!1||F.enabled==="auto"&&F.enabled_effective===!1,b0=!!k[F.source],cs=!F.observed,jf=cs&&aE(F,ge),Dr=sI(Un.trigger),Js=U[F.source]??{};return(0,S.jsxs)("div",{className:"rounded-sm",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Cn(F.source),title:y0?Sh(F.live_reason):void 0,className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[F.git?.isRepo?(0,S.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,S.jsx)(g0,{className:q("h-4 w-4",x0.iconClassName)}),(0,S.jsx)(Ln,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,S.jsx)(g0,{className:q("h-4 w-4 shrink-0",x0.iconClassName)}),(0,S.jsx)("span",{className:q("min-w-0 flex-1 truncate text-[12.5px] font-semibold",k2?"text-white/45":"text-white/90"),children:F.source}),F.git?.isRepo&&F.git.branch?(0,S.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${F.git.branch}`,children:[(0,S.jsx)(Ln,{className:"h-2.5 w-2.5 shrink-0"}),(0,S.jsx)("span",{className:"truncate",children:F.git.branch})]}):null,F.observed&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),F.orphan&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:F.orphan_hint??"Package missing",children:"orphan"}),jf&&(0,S.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"}),(()=>{let We=F.enabled??!0,_t=F.enabled_effective??We===!0,Zn=(Ga?.kind??F.connection.kind)==="webtop",Zs=fe===F.source,S2=()=>Zn?We===!0?!1:We===!1?"auto":!0:We===!1,w0=We==="auto"?`Auto \xB7 ${_t?"Live":"Stopped"}`:We===!1?"Off":"On",C2=We===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":We==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,S.jsx)("button",{type:"button",title:`Source ${w0} \u2014 click to cycle`,onClick:L2=>{L2.stopPropagation(),!Zs&&y2(F.source,S2())},disabled:Zs||!!F.observed,className:q("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",C2),children:Zs?"\u2026":w0})})(),(0,S.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:nE(F,Ga)}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 shrink-0 transition-transform",b0&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("transition-all duration-200",b0?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,S.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,S.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[N.has(F.source)&&typeof F.indexed_count!="number"&&(0,S.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof F.connector_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsxs)("span",{className:"text-white/60 tabular-nums",children:[F.connector_count,F.connector_truncated?"+":""]})," connector"]}),typeof F.indexed_count=="number"&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:F.indexed_count})," indexed"]}),typeof F.unindexed_count=="number"&&F.unindexed_count>0&&(0,S.jsxs)("span",{children:[(0,S.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:F.unindexed_count})," unindexed"]}),za&&F.sync?.lastSync&&(0,S.jsxs)("span",{children:["Last sync: ",nI(F.sync.lastSync)]}),F.updatedAt&&(0,S.jsxs)("span",{children:["Updated: ",nI(F.updatedAt)]})]}),za&&!F.sync?.lastSync?(0,S.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,F.observed?(0,S.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(ba,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!Js.description&&((ge.description??"").trim()||F.description_effective)&&(0,S.jsx)("span",{className:q("text-[9px] truncate max-w-[200px]",(ge.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(ge.description??"").trim()||`${F.description_effective} (from the package)`}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.description&&"rotate-90")})]}),Js.description&&(0,S.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),cs?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("textarea",{value:ge.description??"",onChange:We=>Zr(F.source,_t=>({..._t,description:We.target.value})),rows:2,className:qu,placeholder:F.description_effective??"What this source is for\u2026",maxLength:200}),!(ge.description??"").trim()&&F.description_effective&&(0,S.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,S.jsx)("div",{className:"text-[10px] text-white/70",children:(ge.description??"").trim()||(F.description_effective?(0,S.jsxs)("span",{className:"text-white/40 italic",children:[F.description_effective," ",(0,S.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,S.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),cs&&h&&(Ga?.kind??F.connection.kind)==="local"&&(0,S.jsx)("div",{className:"pl-0",children:(0,S.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,S.jsx)(vr,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,S.jsx)("input",{type:"checkbox",checked:ge.recognizesPackages??!1,onChange:We=>Zr(F.source,_t=>({..._t,recognizesPackages:We.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,S.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,S.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load WASM packages dropped here (additive to ",(0,S.jsx)("code",{children:"_packages/"}),"); advertised only within this source's scope. Save to apply."]})]})]})}),(0,S.jsxs)("div",{children:[(0,S.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,S.jsx)(Is,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.perms&&"rotate-90")})]}),(0,S.jsx)(Xg.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",scripts:["scripts/show-uri.sh","scripts/set-uri.sh","scripts/manifests.sh"],label:`Edit URI policy for "${F.source}" with the agent`,icon:"shield"})]}),Js.perms&&(0,S.jsx)("div",{className:"pl-5 pt-1",children:(0,S.jsx)(Vg,{source:F.source,permissions:F.permissions,mode:cs?"edit":"view",onSave:cs?We=>h2(F,We):void 0})})]}),za&&(0,S.jsxs)("div",{children:[(0,S.jsxs)("button",{type:"button",onClick:()=>zf(F.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,S.jsx)(Ht,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,S.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),Ju&&(0,S.jsx)("span",{className:"text-[9px] text-white/35",children:tE(Un.trigger)}),(0,S.jsx)(un,{className:q("h-2.5 w-2.5 text-white/25 transition-transform",Js.sync&&"rotate-90")})]}),Js.sync&&(0,S.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,S.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ju,onChange:We=>Zr(F.source,_t=>({..._t,...We.target.checked?{sync:{...$g,exclude:[...F.defaultSyncExclude??$g.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),Ju&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,S.jsx)(ya,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,S.jsx)("select",{value:Dr.mode,onChange:We=>{let _t=We.target.value;Zr(F.source,Zn=>({...Zn,sync:{...Un,trigger:Kg(_t,Dr.val,Dr.unit)}}))},className:kf,children:j5.map(We=>(0,S.jsx)("option",{value:We.value,children:We.label},We.value))}),Dr.mode==="interval"&&(0,S.jsxs)("div",{className:"flex gap-1",children:[(0,S.jsx)("input",{type:"number",min:Cf(Dr.unit),value:Dr.val,onChange:We=>{let _t=We.target.value.replace(/\D/g,"")||String(Cf(Dr.unit));Zr(F.source,Zn=>({...Zn,sync:{...Un,trigger:Kg("interval",_t,Dr.unit)}}))},className:q(zo,"w-16")}),(0,S.jsx)("select",{value:Dr.unit,onChange:We=>{let _t=We.target.value,Zn=String(Math.max(Number.parseInt(Dr.val,10)||1,Cf(_t)));Zr(F.source,Zs=>({...Zs,sync:{...Un,trigger:Kg("interval",Zn,_t)}}))},className:q(kf,"flex-1"),children:q5.map(We=>(0,S.jsx)("option",{value:We.value,children:We.label},We.value))})]}),(0,S.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:Dr.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":Dr.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,S.jsx)("textarea",{value:Sf(Un.exclude),onChange:We=>{let _t=ju(We.target.value);Zr(F.source,Zn=>({...Zn,sync:{...Un,exclude:_t}}))},rows:5,className:q(qu,"font-mono"),placeholder:`# .gitignore syntax
|
|
29
|
+
`}function $v(n,e){if(!n)return{files:[],truncated:e,hunkPatches:null};let t=[];try{t=fv(n)}catch{t=[]}return{files:t,truncated:e,hunkPatches:qv(n)}}function Zc(n,e){let t=Tv(n,e);return t<=0?null:{start:n?n.oldStart+n.oldLines:1,end:e.oldStart,lines:t}}function tu(n,e){if(!n)return null;let t=n.oldStart+n.oldLines;if(e===null)return{start:t,end:t,lines:null};let r=e-t+1;return r<=0?null:{start:t,end:e+1,lines:r}}function Kv(n,e){let t=[];for(let a=0;a<n.length;a++){let s=Zc(a===0?null:n[a-1],n[a]);s&&t.push({start:s.start,end:s.end})}let r=tu(n[n.length-1]??null,e);return r&&r.lines!==null&&t.push({start:r.start,end:r.end}),t}function $R(n){let e=n.split(`
|
|
30
|
+
`);return e.length>1&&e[e.length-1]===""&&e.pop(),e}function Qc(n,e){let t=$R(e);if(n.length===0)return t.slice();let r=n[n.length-1],a=Math.max(r.oldStart+r.oldLines,1),s=Math.max(r.newStart+r.newLines,1),o=Math.max(t.length-s+1,0),i=Math.max(a-1+o,0),l=new Array(i).fill(""),u=1,c=1,d=f=>{for(let h=u,p=c;h<f;h++,p++)l[h-1]=t[p-1]??""};for(let f of n)d(f.oldStart),u=Math.max(f.oldStart+f.oldLines,1),c=Math.max(f.newStart+f.newLines,1);return d(i+1),l}function Xv(n,e,t){return t.reduce((r,a)=>Mv(r,e,a.start,a.end),n)}function Yv(n,e){let t=n.oldStart,r=n.oldStart+n.oldLines,a=[];for(let s=0;s<e.length;s++){let o=e[s];o.oldStart>=t&&o.oldStart+o.oldLines<=r&&a.push(s)}return a}function Jv(n){return"commit"in n?{kind:"commit",sha:n.commit}:"base"in n?{kind:"range",base:n.base,head:n.head}:{kind:"working",staged:n.staged}}function Zv(n){return n.kind==="working"?{staged:n.staged}:n.kind==="commit"?{commit:n.sha}:{base:n.base,head:n.head}}function Qv(n){return n.kind==="working"?n.staged?{type:"show",rev:"index"}:{type:"worktree"}:n.kind==="commit"?{type:"show",rev:n.sha}:{type:"show",rev:n.head}}function Zt(n){return n.slice(0,7)}function e1(n){return n.kind==="working"?n.staged?"Index \u2194 HEAD":"Working \u2194 Index":n.kind==="commit"?`${Zt(n.sha)}^ \u2194 ${Zt(n.sha)}`:`${Zt(n.base)} \u2194 ${Zt(n.head)}`}function t1(n){return n.kind==="working"?n.staged?"No staged changes for this file.":"No working-tree changes for this file.":n.kind==="commit"?"No changes for this file in this commit.":"No changes for this file in this range."}function n1(n){return"commit"in n?`commit ${Zt(n.commit)}`:"base"in n?`${Zt(n.base)}..${Zt(n.head)}`:n.staged?"staged":"working tree"}function yo(n,e){return n?`${n} \xB7 ${e}`:e}function r1(n){return!!n&&/uri.?policy.?denied/i.test(n)}var i1=j(Ve(),1);var lp={typescript:()=>import("./chunks/typescript-NEWOAB5Z.js"),tsx:()=>import("./chunks/tsx-S73GAE2L.js"),javascript:()=>import("./chunks/javascript-IH374YWG.js"),jsx:()=>import("./chunks/jsx-OTXJQD32.js"),json:()=>import("./chunks/json-WGGVVXSB.js"),markdown:()=>import("./chunks/markdown-LMWF6MQR.js"),python:()=>import("./chunks/python-CFG4FTQW.js"),bash:()=>import("./chunks/bash-KY6SAQTH.js"),yaml:()=>import("./chunks/yaml-UMWKDTK7.js"),html:()=>import("./chunks/html-F6FWTBSG.js"),css:()=>import("./chunks/css-MANZBYA4.js"),go:()=>import("./chunks/go-5UCPEC6S.js"),rust:()=>import("./chunks/rust-X7A37WU3.js"),sql:()=>import("./chunks/sql-B55MH6JJ.js"),toml:()=>import("./chunks/toml-ETQRDILP.js"),c:()=>import("./chunks/c-OBOPYVZ7.js"),cpp:()=>import("./chunks/cpp-TVWVOTEQ.js"),csharp:()=>import("./chunks/csharp-HQWR4N52.js"),java:()=>import("./chunks/java-ANIVV5H5.js"),kotlin:()=>import("./chunks/kotlin-MNR6XOEQ.js"),ruby:()=>import("./chunks/ruby-42NMJWAL.js"),php:()=>import("./chunks/php-AYGJ5WYZ.js"),swift:()=>import("./chunks/swift-PE7VNYW5.js"),scala:()=>import("./chunks/scala-OYHJSUG2.js"),r:()=>import("./chunks/r-4YFCFA4B.js"),powershell:()=>import("./chunks/powershell-7GSBBEFF.js"),ini:()=>import("./chunks/ini-BJIVD5MK.js"),xml:()=>import("./chunks/xml-UXKAGLDR.js"),scss:()=>import("./chunks/scss-XD7VU2CU.js"),less:()=>import("./chunks/less-KA5JURX6.js"),graphql:()=>import("./chunks/graphql-UGOPR3WU.js"),lua:()=>import("./chunks/lua-4CRZ64PU.js"),dart:()=>import("./chunks/dart-FO4TTVO2.js"),elm:()=>import("./chunks/elm-5WUUSTNB.js"),latex:()=>import("./chunks/latex-QCZNITGN.js"),clojure:()=>import("./chunks/clojure-4QCN4GHG.js"),elixir:()=>import("./chunks/elixir-S725Z7EH.js"),haskell:()=>import("./chunks/haskell-25PJ3OSG.js"),nix:()=>import("./chunks/nix-QGWLUUMZ.js"),perl:()=>import("./chunks/perl-BHTX7F5B.js"),proto:()=>import("./chunks/proto-7KDX5Z2U.js"),docker:()=>import("./chunks/docker-VX55HTDS.js"),mdx:()=>import("./chunks/mdx-WPMNN5BS.js"),vue:()=>import("./chunks/vue-CCDS4VZK.js"),svelte:()=>import("./chunks/svelte-WR3QPIJU.js"),astro:()=>import("./chunks/astro-B2J4AS2D.js"),diff:()=>import("./chunks/diff-SHANV4YC.js"),make:()=>import("./chunks/make-LPD5KOCO.js"),nginx:()=>import("./chunks/nginx-V4CYS7WR.js"),prisma:()=>import("./chunks/prisma-FPMPQISO.js")},KR=["typescript","tsx","javascript","jsx","json","markdown","python","bash","yaml","html","css","go","rust","sql","toml"];function ki(n){if(!n)return;let e=n.toLowerCase(),r={js:"javascript",ts:"typescript","c++":"cpp","c#":"csharp",cs:"csharp",shell:"bash",sh:"bash",zsh:"bash",yml:"yaml",protobuf:"proto",dockerfile:"docker",md:"markdown",htm:"html",py:"python",rs:"rust",kt:"kotlin",rb:"ruby"}[e]??e;return r in lp?r:void 0}var ed=null,bo=null,a1=new Map;function nu(){return ed||(ed=Promise.all([import("./chunks/core-ZHTX3P2Q.js"),import("./chunks/dist-WSDF34DM.js"),import("./chunks/dark-plus-GYPKKZES.js"),import("./chunks/light-plus-QXH2UUWZ.js"),Promise.all(KR.map(n=>lp[n]()))]).then(([n,e,t,r,a])=>n.createHighlighterCore({themes:[t.default,r.default],langs:a.map(s=>s.default),engine:e.createJavaScriptRegexEngine()})).then(n=>(bo=n,n),n=>{throw ed=null,n})),ed}function td(n,e){return n.getLoadedLanguages().includes(e)}function nd(n){return!!bo&&td(bo,n)}function s1(n){return bo&&td(bo,n)?bo:null}async function rd(n){let e=await nu();if(td(e,n))return!0;let t=lp[n];if(!t)return!1;let r=a1.get(n);return r||(r=t().then(a=>e.loadLanguage(a.default)).then(()=>!0).catch(()=>!1),a1.set(n,r)),r}var vi=null;function o1(n,e,t){let r=bo;if(!r||!td(r,e))return null;if(vi&&vi.text===n&&vi.lang===e&&vi.theme===t)return vi.lines;try{let a=r.codeToTokensBase(n,{lang:e,theme:t,includeExplanation:!1});return vi={text:n,lang:e,theme:t,lines:a},a}catch{return null}}function XR(n){return{highlight(e,t){let r=o1(e,t,n);if(!r)return[{type:"text",value:e}];let a=[];return r.forEach((s,o)=>{for(let i of s){if(!i.content)continue;let l={type:"element",tagName:"span",properties:{},color:i.color,children:[{type:"text",value:i.content}]};a.push(l)}o<r.length-1&&a.push({type:"text",value:`
|
|
31
|
+
`})}),a}}}function l1(n,e,t="dark-plus"){let r=ki(e);if(r&&nd(r))try{return jv(n,{highlight:!0,refractor:XR(t),language:r})}catch{return}}var u1=(n,e,t)=>{let r=n.color;return n.type==="element"&&typeof r=="string"?(0,i1.createElement)("span",{key:t,style:{color:r}},n.children?.map((a,s)=>e(a,s))):e(n,t)};function ad(n){let e=yt(String(n||"")).toLowerCase().trim();if(!e)return;let t=e;if(t==="dockerfile")return"docker";let r=t.includes(".")?t.split(".").pop():"";if(!r)return;let a={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",jsonl:"json",py:"python",rb:"ruby",php:"php",java:"java",kt:"kotlin",go:"go",rs:"rust",c:"c",h:"c",cpp:"cpp",cc:"cpp",cxx:"cpp",hpp:"cpp",cs:"csharp",swift:"swift",scala:"scala",r:"r",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",ps1:"powershell",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",xml:"xml",html:"html",css:"css",scss:"scss",less:"less",graphql:"graphql",gql:"graphql",lua:"lua",dart:"dart",elm:"elm",tex:"latex",clj:"clojure",ex:"elixir",exs:"elixir",hs:"haskell",nim:"nim",pl:"perl",proto:"protobuf",md:"markdown",mdx:"mdx"};return r==="env"?"bash":a[r]??r}var sd=j(Ve(),1);function od(n,e){let t=e?.wideThresholdPx??900,r=e?.hysteresisPx??60,[a,s]=(0,sd.useState)(!1);return(0,sd.useEffect)(()=>{let o=n.current;if(!o){s(!1);return}let i=()=>{let u=o.clientWidth;s(c=>c?u>=t-r:u>=t)};if(i(),typeof ResizeObserver>"u")return;let l=new ResizeObserver(()=>i());return l.observe(o),()=>l.disconnect()},[n,t,r]),a}var id=j(le(),1),YR=[{key:"auto",label:"Auto",Icon:Ms},{key:"unified",label:"Unified",Icon:Rs},{key:"split",label:"Split",Icon:bs}];function ld({className:n}){let e=_(r=>r.diffViewMode),t=_(r=>r.setDiffViewMode);return(0,id.jsx)("div",{className:V("inline-flex items-center gap-0.5 rounded-md bg-white/5 p-0.5",n),children:YR.map(({key:r,label:a,Icon:s})=>(0,id.jsx)("button",{type:"button",onClick:()=>t(r),className:V("inline-flex items-center justify-center rounded p-1 transition",e===r?"bg-white/12 text-white/90":"text-white/40 hover:text-white/70 hover:bg-white/[0.06]"),title:`Diff layout: ${a}${r==="auto"?" (by width)":""}`,"aria-label":`Diff layout ${a}`,"aria-pressed":e===r,children:(0,id.jsx)(s,{className:"w-3 h-3"})},r))})}var Ze=j(le(),1),JR={"--diff-background-color":"transparent","--diff-text-color":"rgba(255,255,255,0.82)","--diff-font-family":"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace","--diff-selection-background-color":"rgba(139,92,246,0.35)","--diff-gutter-insert-background-color":"rgba(16,185,129,0.16)","--diff-gutter-delete-background-color":"rgba(244,63,94,0.16)","--diff-gutter-selected-background-color":"rgba(139,92,246,0.22)","--diff-code-insert-background-color":"rgba(16,185,129,0.10)","--diff-code-delete-background-color":"rgba(244,63,94,0.10)","--diff-code-insert-edit-background-color":"rgba(16,185,129,0.30)","--diff-code-delete-edit-background-color":"rgba(244,63,94,0.32)","--diff-code-selected-background-color":"rgba(139,92,246,0.16)","--diff-omit-gutter-line-color":"transparent"};function up(n,e,t,r){let a=r.kind==="working"?{kind:r.kind,staged:r.staged}:r.kind==="commit"?{kind:r.kind,sha:r.sha}:{kind:r.kind,base:r.base,head:r.head};return`diff\0${n}\0${e}\0${t}\0${JSON.stringify(a)}`}function wo({source:n,repo:e="",path:t,mode:r,agentId:a,projectId:s,variant:o="tab",revision:i=0,canWrite:l=!1,runContent:u,peekContent:c}){let[d]=(0,gt.useState)(()=>c?.(`${up(n,e,t,r)}\0${i}`,up(n,e,t,r))),[f,h]=(0,gt.useState)(()=>d===void 0?null:d&&d.ok!==!1?d.diff:""),[p,m]=(0,gt.useState)(!1),[g,x]=(0,gt.useState)(null),[b,y]=(0,gt.useState)(()=>d!==void 0&&d.ok!==!1&&d.truncated===!0),[N,L]=(0,gt.useState)(()=>d!==void 0&&d.ok===!1),[A,w]=(0,gt.useState)(0),[v,T]=(0,gt.useState)(null),[P,O]=(0,gt.useState)(null),[C,I]=(0,gt.useState)([]),[H,q]=(0,gt.useState)(null),[$,S]=(0,gt.useState)(!1),M=(0,gt.useRef)(new Map),W=(0,gt.useRef)(0),ee=_(Y=>Y.loadGitStatus),te=r.kind,re=r.kind==="working"?r.staged:!1,ce=r.kind==="commit"?r.sha:null,oe=r.kind==="range"?r.base:null,ue=r.kind==="range"?r.head:null,ie=(0,gt.useMemo)(()=>te==="working"?{kind:te,staged:re}:te==="commit"?{kind:te,sha:ce??""}:{kind:te,base:oe??"",head:ue??""},[te,re,ce,oe,ue]),Re=(0,gt.useMemo)(()=>Qv(ie),[ie]),De=_(Y=>Y.diffViewMode),Ye=(0,gt.useRef)(null),$e=od(Ye),Pt=De==="auto"?$e?"split":"unified":De,Xe=(0,gt.useMemo)(()=>ad(t),[t]),[lt,Nt]=(0,gt.useState)(!1);(0,gt.useEffect)(()=>{let Y=ki(Xe);if(!Y){Nt(!1);return}if(nd(Y)){Nt(!0);return}let Ie=!1;return Nt(!1),nu().then(()=>rd(Y)).then(_e=>{Ie||Nt(_e)}),()=>{Ie=!0}},[Xe]),(0,gt.useEffect)(()=>{if(M.current.clear(),I([]),q(null),S(!1),!a||!n||!t){y(!1),L(!1),h(null),x(null),m(!1);return}let Y=++W.current;return m(!0),x(null),(async()=>{try{let Ie=()=>oc({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,...Zv(ie)}),_e=up(n,e,t,ie),ze={key:`${_e}\0${i}`,family:_e,bytes:de=>de&&de.ok!==!1?de.diff.length*2:64,fresh:A>0},Te=u?await u(Ie,()=>Y===W.current,ze):await Ie();if(!Te||Y!==W.current)return;Te&&Te.ok===!1?(h(""),L(!0),y(!1)):(h(typeof Te?.diff=="string"?Te.diff:""),L(!1),y(Te?.truncated===!0)),m(!1)}catch(Ie){if(Y!==W.current)return;x(Ie instanceof Error?Ie.message:"Diff failed"),h(null),L(!1),y(!1),m(!1)}})(),()=>{W.current++}},[a,s,n,e,t,ie,A,i,u]);let{files:ot,truncated:Me,hunkPatches:tt}=(0,gt.useMemo)(()=>$v(f,b),[f,b]),pt=ot.some(Y=>Y.hunks.length>0),Rt=yt(t)||t,kt=r1(g),Ee=ot.length===1?ot[0]:null,xe=l&&te==="working"&&!!a&&!!Ee&&Ee.type==="modify"&&!Me&&!!tt&&tt.hunks.length===Ee.hunks.length,Dt=!!a&&!!Ee&&!Me&&Ee.hunks.length>0,en=(0,gt.useCallback)(async()=>{if(!a)return null;let Y=W.current,Ie=Re.type==="worktree"?"wt":Re.rev,_e=`${n}\0${e}\0${t}\0${Ie}`,ze=M.current.get(_e),Te=de=>(M.current.set(_e,de),Y===W.current&&(de.ok?q(de.content):S(!0)),de.ok?de.content:null);if(ze)return Te(ze);try{if(Re.type==="show"){let nn=()=>j0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},path:t,rev:Re.rev}),$n=u?await u(nn,()=>Y===W.current):await nn();return!$n||Y!==W.current?null:Te($n.ok?{ok:!0,content:$n.content}:{ok:!1})}let de=()=>Ko({agentId:a,...s?{projectId:s}:{},files:[`${n}://${e?`${e}/`:""}${t}`]}),ut=u?await u(de,()=>Y===W.current):await de();if(!ut||Y!==W.current)return null;let Ft=Jo(ut)[0];return!Ft||typeof Ft.error=="string"?Te({ok:!1}):Te({ok:!0,content:Zo(Ft)})}catch{return Te({ok:!1})}},[a,s,n,e,t,Re,u]),he=(0,gt.useMemo)(()=>Ee&&H!==null?Qc(Ee.hunks,H):null,[Ee,H]),pe=(0,gt.useMemo)(()=>ot.map(Y=>Y!==Ee||!he||C.length===0?Y.hunks:Xv(Y.hunks,he,C)),[ot,Ee,he,C]),je=he?he.length:null,Pe=(0,gt.useMemo)(()=>lt?ot.map((Y,Ie)=>l1(pe[Ie]??Y.hunks,Xe)):ot.map(()=>{}),[ot,pe,Xe,lt]),Ce=(0,gt.useCallback)(async Y=>{if(!Dt)return;let Ie=W.current,_e=H??await en();if(_e===null||Ie!==W.current||!Ee)return;let ze;if(Y.lines===null){let Te=tu(Ee.hunks[Ee.hunks.length-1]??null,Qc(Ee.hunks,_e).length);if(!Te||Te.lines===null)return;ze={start:Te.start,end:Te.end}}else ze={start:Y.start,end:Y.end};I(Te=>[...Te,ze])},[Dt,H,en,Ee]),ln=(0,gt.useCallback)(async()=>{if(!Dt||!Ee)return;let Y=W.current,Ie=H??await en();if(Ie===null||Y!==W.current)return;let _e=Kv(Ee.hunks,Qc(Ee.hunks,Ie).length);_e.length>0&&I(ze=>[...ze,..._e])},[Dt,Ee,H,en]),mt=(0,gt.useMemo)(()=>{if(!Dt||!Ee)return!1;let Y=ot.indexOf(Ee),Ie=pe[Y]??Ee.hunks;for(let _e=0;_e<Ie.length;_e++)if(Zc(_e===0?null:Ie[_e-1],Ie[_e]))return!0;return tu(Ie[Ie.length-1]??null,je)!==null},[Dt,Ee,ot,pe,je]),Ht=(0,gt.useCallback)(async Y=>{if(p||!xe||!tt||!a)return;let Ie=Vv(tt.header,tt.hunks[Y]);if(!Ie){O("Could not build a hunk patch for this change.");return}T(Y),O(null);try{re?await K0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ie}):await $0({agentId:a,...s?{projectId:s}:{},source:n,...e?{repo:e}:{},hunk:Ie}),M.current.clear(),ee({agentId:a,projectId:s}),w(_e=>_e+1)}catch(_e){O(_e instanceof Error?_e.message:"Hunk apply failed")}finally{T(null)}},[p,xe,tt,a,s,n,e,re,ee]),Ge=Y=>{let Ie=Y.lines===null?"Expand to end of file":`${Y.lines} hidden ${Y.lines===1?"line":"lines"}`;return $?Y.lines===null?null:(0,Ze.jsx)(Jc,{children:(0,Ze.jsxs)("div",{className:"px-3 py-0.5 font-mono text-[10px] text-white/30",children:["\u22EF ",Ie]})},`gap-${Y.start}`):(0,Ze.jsx)(Jc,{children:(0,Ze.jsxs)("button",{type:"button",onClick:()=>{Ce(Y)},className:"block w-full px-3 py-0.5 text-left font-mono text-[10px] text-violet-300/70 transition-colors hover:bg-violet-500/10 hover:text-violet-200/90",title:"Expand this hidden region",children:["\u22EF ",Ie]})},`gap-${Y.start}`)},Wt=(Y,Ie)=>Ie.length===0?null:(0,Ze.jsx)(Jc,{children:(0,Ze.jsx)("div",{className:"flex items-center justify-end gap-2 px-2 py-1",children:Ie.map(_e=>(0,Ze.jsxs)("button",{type:"button",onClick:()=>{Ht(_e)},disabled:v!==null||p,className:V("inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[10px] transition-colors disabled:opacity-40",re?"border-white/12 bg-white/[0.04] text-white/70 hover:bg-white/[0.09]":"border-emerald-500/25 bg-emerald-500/12 text-emerald-100/90 hover:bg-emerald-500/18"),title:re?"Unstage this hunk":"Stage this hunk",children:[v===_e?(0,Ze.jsx)(cp.LiveSpinner,{className:"h-3 w-3"}):re?(0,Ze.jsx)(ao,{className:"h-3 w-3"}):(0,Ze.jsx)(Tn,{className:"h-3 w-3"}),re?"Unstage hunk":"Stage hunk",Ie.length>1?(0,Ze.jsxs)("span",{className:"font-mono text-white/45",children:["@",Ee?.hunks[_e]?.oldStart]}):null]},_e))})},`stage-${Y.oldStart}`),tn=(0,Ze.jsxs)("button",{type:"button",onClick:()=>{ln()},className:"inline-flex shrink-0 items-center gap-1 rounded-md border border-white/10 px-1.5 py-0.5 text-[10px] text-white/55 transition-colors hover:bg-white/[0.06] hover:text-white/80",title:"Expand all hidden regions",children:[(0,Ze.jsx)(Ul,{className:"h-3 w-3"}),"Expand all"]}),Be=g?kt?(0,Ze.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Ze.jsx)(ro,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,Ze.jsx)("span",{children:"You don't have permission to view this file's changes."})]}):(0,Ze.jsx)("div",{className:"px-3 py-4 text-[11px] text-rose-300/70",children:g}):p&&!f?(0,Ze.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Ze.jsx)(cp.LiveSpinner,{className:"h-3.5 w-3.5"}),"Loading diff\u2026"]}):N?(0,Ze.jsxs)("div",{className:"flex items-center justify-center gap-1.5 px-3 py-6 text-center text-[11px] text-amber-200/70",children:[(0,Ze.jsx)(ct,{className:"h-3.5 w-3.5 shrink-0"}),(0,Ze.jsx)("span",{children:"Diff too large to display \u2014 the change exceeds the server output bound."})]}):pt?(0,Ze.jsx)("div",{style:JR,className:V("nrs-git-diff px-1 py-1 text-[12px] leading-[18px]"),children:ot.map((Y,Ie)=>{let _e=Y===Ee&&Dt;return(0,Ze.jsx)(Hv,{viewType:Pt,diffType:Y.type,hunks:pe[Ie]??Y.hunks,tokens:Pe[Ie],renderToken:u1,children:ze=>{let Te=[],de=ut=>{ut&&Te.push(ut)};if(ze.forEach((ut,Ft)=>{if(_e){let nn=Zc(Ft===0?null:ze[Ft-1],ut);nn&&de(Ge(nn))}xe&&Y===Ee&&de(Wt(ut,Yv(ut,Y.hunks))),Te.push((0,Ze.jsx)(op,{hunk:ut},`h-${ut.oldStart}-${ut.oldLines}`))}),_e){let ut=tu(ze[ze.length-1]??null,je);ut&&de(Ge(ut))}return Te}},`${Y.oldRevision??""}-${Y.newRevision??""}-${Ie}`)})}):(0,Ze.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:t1(ie)});return(0,Ze.jsxs)("div",{ref:Ye,className:V("flex w-full flex-col",o==="tab"&&"h-full min-h-0"),children:[o==="tab"?(0,Ze.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,Ze.jsx)(lr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Ze.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:Rt}),(0,Ze.jsx)("span",{className:"truncate font-mono text-white/40",children:t}),(0,Ze.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-white/10 px-2 py-0.5 text-[9px] uppercase tracking-wider text-white/45",children:e1(ie)}),(0,Ze.jsx)(ld,{}),mt&&!$?tn:null]}):mt&&!$?(0,Ze.jsx)("div",{className:"flex shrink-0 items-center justify-end px-2 pt-1",children:tn}):null,Me?(0,Ze.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-amber-200/70",children:[(0,Ze.jsx)(ct,{className:"h-3 w-3 shrink-0"}),(0,Ze.jsx)("span",{children:"Diff truncated by the server (2 MB cap) \u2014 showing the leading hunks; hunk staging is disabled."})]}):null,P?(0,Ze.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 px-3 py-1 text-[10px] text-rose-300/75",children:[(0,Ze.jsx)(ct,{className:"h-3 w-3 shrink-0"}),(0,Ze.jsx)("span",{className:"truncate",children:P})]}):null,o==="tab"?(0,Ze.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:Be}):Be]})}var Qe=j(le(),1),dp={M:"text-amber-400",A:"text-emerald-400",D:"text-rose-400",R:"text-sky-400",C:"text-sky-400",T:"text-white/60"},ud={M:"Modified",A:"Added",D:"Deleted",R:"Renamed",C:"Copied",T:"Type changed"};function ZR(n){let e=new Date(n);return Number.isNaN(e.getTime())?n:e.toLocaleString()}var QR=(0,rs.memo)(function({file:e,mode:t,source:r,repo:a,agentId:s,projectId:o,defaultExpanded:i,queue:l}){let[u,c]=(0,rs.useState)(i),d=(e.status[0]??"M").toUpperCase(),f=e.path.includes("/")?e.path.slice(0,e.path.lastIndexOf("/")):"",h=e.path.includes("/")?e.path.slice(e.path.lastIndexOf("/")+1):e.path;return(0,Qe.jsxs)("div",{ref:p=>l.register(e.path,p),className:"overflow-hidden rounded-lg border border-white/8 bg-black/20",children:[(0,Qe.jsxs)("button",{type:"button",onClick:()=>c(p=>!p),className:"flex w-full items-center gap-2 px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.03]",title:e.path,"aria-expanded":u,children:[u?(0,Qe.jsx)(Tt,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}):(0,Qe.jsx)(un,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,Qe.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",dp[d]??"text-white/60"),title:ud[d]??"Changed","aria-label":`Status: ${ud[d]??"Changed"}`,children:d}),(0,Qe.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs text-white/85",children:[h,f?(0,Qe.jsxs)("span",{className:"ml-1.5 font-mono text-[10px] text-white/30",children:[f,"/"]}):null]}),e.renamedFrom?(0,Qe.jsxs)("span",{className:"shrink-0 truncate font-mono text-[10px] text-white/35",title:`Renamed from ${e.renamedFrom}`,children:["\u2190 ",e.renamedFrom]}):null,(0,Qe.jsx)(Pa,{added:e.added,removed:e.removed,binary:e.binary,className:"shrink-0"})]}),u&&l.visible.has(e.path)?(0,Qe.jsx)("div",{className:"border-t border-white/5",children:(0,Qe.jsx)("div",{className:"max-h-96 overflow-auto",style:{scrollbarGutter:"auto"},children:(0,Qe.jsx)(wo,{variant:"card",canWrite:!1,runContent:l.run,source:r,repo:a,path:e.path,mode:t,agentId:s,projectId:o})})}):null]})});function fp({target:n,agentId:e,projectId:t}){let[r,a]=(0,rs.useState)(null),s=Nc(r),[o,i]=(0,rs.useState)({phase:"loading"}),[l,u]=(0,rs.useState)(null),{source:c}=n,d=n.repo??"",f=n.kind==="commit"?`c:${d}:${n.sha}`:`o:${d}:${n.base}..${n.head}`;(0,rs.useEffect)(()=>{if(i({phase:"loading"}),u(null),!e||!c)return;let g=!1;return(async()=>{try{if(n.kind==="commit"){let x=await lc({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},sha:n.sha});if(g)return;x.ok===!1?i({phase:"unavailable"}):i({phase:"ready",files:x.files,range:null});try{let b=await ic({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{},maxCount:1,ref:n.sha}),y=Array.isArray(b?.commits)?b.commits[0]:void 0;!g&&y&&u({author:y.author,date:y.date})}catch{}}else{let x=await ll({agentId:e,...t?{projectId:t}:{},source:c,...d?{repo:d}:{}});if(g)return;!x.ok||!x.baseSha||!x.headSha?i({phase:"no-upstream"}):i({phase:"ready",files:Array.isArray(x.files)?x.files:[],range:{base:x.baseSha,head:x.headSha}})}}catch(x){if(g)return;i({phase:"error",message:x instanceof Error?x.message:"Change-set failed"})}})(),()=>{g=!0}},[e,t,c,f]);let h=n.kind==="commit"?n:null,p=h!==null,m=o.phase==="ready"&&o.range?`${Zt(o.range.base)}..${Zt(o.range.head)}`:n.kind==="outgoing"?`${Zt(n.base)}..${Zt(n.head)}`:"";return(0,Qe.jsxs)("div",{className:"flex h-full w-full min-h-0 flex-col",children:[(0,Qe.jsx)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:h?(0,Qe.jsxs)(Qe.Fragment,{children:[(0,Qe.jsx)(Hr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,Qe.jsx)("span",{className:"shrink-0 rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[10px] text-violet-200/90",children:Zt(h.sha)}),(0,Qe.jsx)("span",{className:"min-w-0 truncate font-medium text-white/85",children:h.subject}),l?(0,Qe.jsxs)("span",{className:"ml-auto shrink-0 text-[10px] text-white/40",children:[l.author," \xB7 ",ZR(l.date)]}):null]}):(0,Qe.jsxs)(Qe.Fragment,{children:[(0,Qe.jsx)(Br,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/80"}),(0,Qe.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Outgoing changes"}),(0,Qe.jsx)("span",{className:"truncate font-mono text-[10px] text-white/40",children:m}),(0,Qe.jsx)("span",{className:"ml-auto shrink-0 text-[10px] text-white/35",title:"Computed from local refs (last fetch) \u2014 fetching/pulling remotes lands in a later increment.",children:"Local refs only \u2014 fetch lands later"})]})}),(0,Qe.jsx)("div",{ref:a,className:"min-h-0 flex-1 overflow-auto px-2 py-2",children:o.phase==="loading"?(0,Qe.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,Qe.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading changes\u2026"]}):o.phase==="error"?(0,Qe.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,Qe.jsx)(ct,{className:"h-3.5 w-3.5 shrink-0"}),(0,Qe.jsx)("span",{className:"truncate",children:o.message})]}):o.phase==="unavailable"?(0,Qe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"Commit details unavailable \u2014 the commit may no longer exist in this repository."}):o.phase==="no-upstream"?(0,Qe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No upstream to compare against \u2014 everything here is local."}):o.files.length===0?(0,Qe.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:p?"This commit changed no files.":"Nothing outgoing \u2014 the upstream is up to date."}):(0,Qe.jsx)("div",{className:"flex flex-col gap-1.5",children:o.files.map(g=>(0,Qe.jsx)(QR,{file:g,mode:h?{kind:"commit",sha:h.sha}:{kind:"range",base:o.range?.base??"",head:o.range?.head??""},source:c,repo:d,agentId:e,projectId:t,defaultExpanded:!0,queue:s},g.path))})})]})}var ae=j(le(),1),Gr=30,m1=16,gp=14,c1=4.5,cd=["#cba6f7","#a6e3a1","#f9e2af","#f38ba8","#94e2d5","#fab387","#b4befe","#89b4fa"];function pp(n){return cd[(n%cd.length+cd.length)%cd.length]}var mp=n=>gp+n*m1;function eM(){let n=null,e=new Set;return{get:()=>n,set:t=>{let r=typeof t=="function"?t(n):t;if(r!==n){n=r;for(let a of e)a()}},subscribe:t=>(e.add(t),()=>{e.delete(t)})}}var tM=null,nM=()=>tM;function rM({store:n,commits:e,expandedShas:t}){let r=at.default.useSyncExternalStore(n.subscribe,n.get,nM);if(!r||t.has(r.sha))return null;let a=e.find(s=>s.sha===r.sha);return a?(0,ae.jsxs)("div",{className:"pointer-events-none absolute z-30 overflow-hidden rounded-md border border-white/10 bg-[#1b1b26] px-2.5 py-2 shadow-lg shadow-black/50",style:{left:gp,right:8,maxHeight:"55%",...r.flip?{bottom:r.above}:{top:r.below}},children:[(0,ae.jsx)("div",{className:"whitespace-pre-wrap break-words text-[11px] font-medium leading-snug text-white/90",children:a.subject||"(no message)"}),a.body?(0,ae.jsx)("div",{className:"mt-1 whitespace-pre-wrap break-words text-[10px] leading-snug text-white/55",children:a.body}):null,(0,ae.jsxs)("div",{className:"mt-1.5 flex items-center gap-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:Zt(a.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:a.author}),(0,ae.jsx)("span",{children:Fh(a.date)})]})]}):null}function d1(n){let e=mp(n.fromLane),t=mp(n.toLane),r=n.fromY==="edge"?0:Gr/2,a=n.toY==="edge"?Gr:Gr/2;if(e===t)return`M${e} ${r} L${t} ${a}`;if(n.toY==="edge"){let o=2*t-e;return`M${e} ${r} C ${e} ${(r+a)/2} ${(3*e+o)/4} ${(r+3*a)/4} ${t} ${a}`}let s=2*e-t;return`M${e} ${r} C ${(s+3*t)/4} ${(3*r+a)/4} ${t} ${(r+a)/2} ${t} ${a}`}function aM(n){return(n.split("->").pop()??n).replace(/^tag:\s*/,"").trim()}function f1(n,e){(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),e())}function sM({file:n,onClick:e,showCounts:t}){let r=n.path.lastIndexOf("/"),a=r<0?n.path:n.path.slice(r+1),s=r<0?"":n.path.slice(0,r),o=(n.status[0]??"M").toUpperCase(),i=di(n.path);return(0,ae.jsxs)("button",{type:"button",onClick:()=>e(n),className:"flex w-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md py-1 pl-2 pr-1.5 text-left transition-colors hover:bg-white/[0.05]",title:n.renamedFrom?`${n.renamedFrom} \u2192 ${n.path}`:n.path,children:[(0,ae.jsx)(i,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,ae.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:a}),s?(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:s}):(0,ae.jsx)("span",{className:"flex-1"}),t?(0,ae.jsx)(Pa,{added:n.added,removed:n.removed,binary:n.binary,className:"mr-1"}):null,(0,ae.jsx)("span",{className:V("shrink-0 text-[10px] font-bold leading-none tabular-nums",dp[o]??"text-white/60"),"aria-label":`Status: ${ud[o]??"Changed"}`,children:o})]})}function h1({entry:n,emptyText:e,unavailableText:t,onFileClick:r,showCounts:a}){return n.status==="loading"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-white/40",children:[(0,ae.jsx)(p1.LiveSpinner,{className:"h-3 w-3"}),"Loading files\u2026"]}):n.status==="error"?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ct,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:n.message})]}):n.status==="unavailable"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:t}):n.files.length===0?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:e}):(0,ae.jsx)("div",{className:"space-y-px",children:n.files.map(s=>(0,ae.jsx)(sM,{file:s,onClick:r,showCounts:a},s.path))})}function g1({source:n,repo:e="",agentId:t,projectId:r,repoName:a,showCounts:s=!0,onOutgoingStat:o}){let[i,l]=(0,at.useState)(Th),[u,c]=(0,at.useState)(!1),[d,f]=(0,at.useState)(null),h=(0,at.useRef)(0),p=(0,at.useRef)(!1),m=(0,at.useRef)(!1),g=(0,at.useRef)(i);g.current=i;let[x,b]=(0,at.useState)(()=>new Set),[y,N]=(0,at.useState)(!1),[L,A]=(0,at.useState)(()=>new Map),[w,v]=(0,at.useState)({status:"idle"}),T=(0,at.useRef)(null),P=(0,at.useRef)(null);P.current===null&&(P.current=eM());let O=P.current,C=(0,at.useRef)(0),I=(0,at.useRef)(0),H=_(he=>he.gitLogNonce),q=_(he=>he.setGitDiffTarget),$=_(he=>he.setGitCommitTarget),S=_(he=>he.setActiveWorkspaceTab),[M,W]=(0,at.useState)(null),[ee,te]=(0,at.useState)(null),[re,ce]=(0,at.useState)({}),oe=(0,at.useRef)(s);oe.current=s;let ue=(0,at.useRef)(o);ue.current=o;let ie=(0,at.useCallback)(async(he,pe,je)=>{if(!t||!n)return;let Pe=++h.current;p.current=!0,c(!0),f(null);try{let Ce=await ic({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:pe,skip:he});if(Pe!==h.current)return;let ln={commits:Array.isArray(Ce?.commits)?Ce.commits:[],hasMore:Ce?.hasMore===!0,outgoing:Array.isArray(Ce?.outgoing)?Ce.outgoing:void 0};l(mt=>je==="append"?kw(mt,ln):Sw(ln)),oe.current&&W0({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},maxCount:pe,skip:he}).then(mt=>{Pe===h.current&&(ce(Ht=>je==="append"?{...Ht,...mt.stats}:{...mt.stats}),je==="replace"&&ue.current?.(mt.outgoingStat??null))}).catch(()=>{}),je==="replace"&&(I.current++,v(mt=>mt.status==="idle"?mt:{status:"idle"})),c(!1)}catch(Ce){if(Pe!==h.current)return;f(Ce instanceof Error?Ce.message:"Git log failed"),c(!1)}finally{Pe===h.current&&(p.current=!1)}},[t,r,n,e]);(0,at.useEffect)(()=>{if(h.current++,p.current=!1,C.current++,I.current++,l(Th),f(null),b(new Set),N(!1),A(new Map),v({status:"idle"}),!t||!n){c(!1);return}ie(0,200,"replace")},[t,r,n,ie]);let Re=(0,at.useRef)(H);(0,at.useEffect)(()=>{H!==Re.current&&(Re.current=H,!(!t||!n)&&ie(0,Dh(g.current.commits.length),"replace"))},[H,t,n,ie]),(0,at.useEffect)(()=>{if(!M||!ee||(m.current=!1,typeof IntersectionObserver>"u"))return;let he=new IntersectionObserver(pe=>{for(let Pe of pe)m.current=Pe.isIntersecting;if(!m.current)return;let je=g.current;!je.hasMore||p.current||ie(je.nextSkip,200,"append")},{root:M,rootMargin:"120px"});return he.observe(ee),()=>he.disconnect()},[M,ee,ie]),(0,at.useEffect)(()=>{u||d!==null||!m.current||p.current||i.hasMore&&ie(i.nextSkip,200,"append")},[i,u,d,ie]);let De=(0,at.useCallback)(async he=>{if(!t||!n)return;let pe=C.current;A(je=>new Map(je).set(he,{status:"loading"}));try{let je=await lc({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{},sha:he});if(pe!==C.current)return;A(Pe=>new Map(Pe).set(he,je.ok===!1?{status:"unavailable"}:{status:"ready",files:Array.isArray(je.files)?je.files:[]}))}catch(je){if(pe!==C.current)return;A(Pe=>new Map(Pe).set(he,{status:"error",message:je instanceof Error?je.message:"Commit files failed"}))}},[t,r,n,e]),Ye=i.commits,$e=Es(n,a),Pt=(0,at.useMemo)(()=>bw(Ye),[Ye]),Xe=Math.max(40,gp+Pt.laneCount*m1+8),lt=(0,at.useMemo)(()=>Cw(Ye,i.outgoing),[Ye,i.outgoing]),Nt=(0,at.useMemo)(()=>new Set(i.outgoing??[]),[i.outgoing]),ot=(0,at.useMemo)(()=>lt.some(he=>he.kind==="outgoing-divider"),[lt]);(0,at.useEffect)(()=>{if(!y||w.status!=="idle"||!ot||!t||!n)return;let he=++I.current;v({status:"loading"}),(async()=>{try{let pe=await ll({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(he!==I.current)return;!pe.ok||!pe.baseSha||!pe.headSha?v({status:"no-upstream"}):v({status:"ready",base:pe.baseSha,head:pe.headSha,files:Array.isArray(pe.files)?pe.files:[]})}catch(pe){if(he!==I.current)return;v({status:"error",message:pe instanceof Error?pe.message:"Outgoing changes failed"})}})()},[y,w.status,ot,t,r,n,e]);let Me=li({count:lt.length,getScrollElement:()=>M,estimateSize:()=>Gr,overscan:12,getItemKey:he=>Lw(lt[he],Ye)}),tt=()=>{!t||!n||ie(0,Dh(g.current.commits.length),"replace")},pt=(he,pe)=>{if(x.has(he)){Me.resizeItem(pe,Gr),b(Pe=>{let Ce=new Set(Pe);return Ce.delete(he),Ce});return}b(Pe=>new Set(Pe).add(he));let je=L.get(he);(!je||je.status==="error")&&De(he)},Rt=he=>{let pe=!y;pe||Me.resizeItem(he,Gr),pe&&w.status==="error"&&v({status:"idle"}),N(pe)},kt=e?{repo:e}:{},Ee=(he,pe)=>{n&&(q({source:n,...kt,path:pe.path,commit:he}),S("git-diff"))},xe=he=>{n&&($({source:n,...kt,kind:"commit",sha:he.sha,subject:he.subject}),S("git-commit"))},Dt=he=>{!n||w.status!=="ready"||(q({source:n,...kt,path:he.path,base:w.base,head:w.head}),S("git-diff"))},en=()=>{if(!n||!t)return;if(w.status==="ready"){$({source:n,...kt,kind:"outgoing",base:w.base,head:w.head}),S("git-commit");return}let he=++I.current;v({status:"loading"}),(async()=>{try{let pe=await ll({agentId:t,...r?{projectId:r}:{},source:n,...e?{repo:e}:{}});if(he!==I.current)return;if(!pe.ok||!pe.baseSha||!pe.headSha){v({status:"no-upstream"});return}v({status:"ready",base:pe.baseSha,head:pe.headSha,files:Array.isArray(pe.files)?pe.files:[]}),$({source:n,...kt,kind:"outgoing",base:pe.baseSha,head:pe.headSha}),S("git-commit")}catch(pe){if(he!==I.current)return;v({status:"error",message:pe instanceof Error?pe.message:"Outgoing changes failed"})}})()};return(0,ae.jsxs)("div",{ref:T,className:"relative flex h-full w-full min-h-0 flex-col",children:[(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-[11px]",style:{borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ae.jsx)(Hr,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 font-medium text-white/85",children:"Commit graph"}),$e.prefix?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("span",{className:"shrink-0 font-mono text-white/40",children:$e.prefix}),(0,ae.jsx)("span",{className:"truncate font-medium text-white/85",children:$e.name})]}):(0,ae.jsx)("span",{className:"truncate font-mono text-white/40",children:$e.name}),(0,ae.jsxs)("span",{className:"ml-auto shrink-0 tabular-nums text-white/40",children:[Ye.length,i.hasMore?"+":""," commit",Ye.length===1?"":"s"]}),(0,ae.jsx)("button",{type:"button",onClick:tt,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh commit graph","aria-label":"Refresh commit graph",children:(0,ae.jsx)(Ot,{className:V("h-3 w-3",u&&"animate-spin")})})]}),d&&Ye.length>0?(0,ae.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-white/[0.05] px-3 py-1 text-[10px] text-rose-300/70",children:[(0,ae.jsx)(ct,{className:"h-3 w-3 shrink-0"}),(0,ae.jsx)("span",{className:"truncate",children:d})]}):null,(0,ae.jsx)("div",{ref:W,className:"min-h-0 flex-1 overflow-auto",children:d&&Ye.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-4 text-[11px] text-rose-300/70",children:[(0,ae.jsx)(ct,{className:"h-3 w-3 shrink-0"}),d]}):u&&Ye.length===0?(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:"h-3.5 w-3.5 animate-spin"}),"Loading commit graph\u2026"]}):Ye.length===0?(0,ae.jsx)("div",{className:"px-3 py-6 text-center text-[11px] text-white/35",children:"No commits yet."}):(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsx)("div",{style:{height:Me.getTotalSize(),width:"100%",position:"relative"},children:Me.getVirtualItems().map(he=>{let pe=lt[he.index];if(!pe)return null;if(pe.kind==="outgoing-divider"){let Y=w.status==="ready"?{status:"ready",files:w.files}:w.status==="error"?w:{status:"loading"},Ie=lt[he.index+1],_e=ww(Pt.rowSegments,Ie?.kind==="commit"?Ie.row:-1);return(0,ae.jsxs)("div",{"data-index":he.index,ref:y?Me.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${he.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,onClick:()=>Rt(he.index),onKeyDown:ze=>f1(ze,()=>Rt(he.index)),className:V("group flex w-full min-w-0 cursor-pointer items-center gap-1.5 text-[11px] transition-colors hover:bg-white/[0.04]",_e.length>0?"pr-2":"px-2"),style:{height:Gr},title:"The blue hollow dots mark commits not yet pushed to origin (local refs only, from the last known upstream). On a diverged/interleaved history this divider is an approximate boundary \u2014 the dots are the source of truth.",children:[_e.length>0?(0,ae.jsx)("svg",{"data-divider-lanes":!0,width:Xe,height:Gr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:_e.map((ze,Te)=>(0,ae.jsx)("path",{d:d1(ze),fill:"none",stroke:pp(ze.colorLane),strokeWidth:1.5,strokeOpacity:.55,strokeLinecap:"round"},Te))}):null,y?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,ae.jsx)(Br,{className:"h-3 w-3 shrink-0 text-blue-300/80"}),(0,ae.jsx)("span",{className:"shrink-0 text-[9px] font-bold uppercase tracking-wider text-blue-200/85",children:"Outgoing changes"}),(0,ae.jsx)("span",{className:"shrink-0 rounded bg-blue-400/15 px-1 py-0.5 text-[9px] leading-none tabular-nums text-blue-100/80",children:i.outgoing?.length??0}),(0,ae.jsx)("span",{className:"h-px min-w-0 flex-1 bg-blue-400/20","aria-hidden":!0}),(0,ae.jsx)("button",{type:"button",onClick:ze=>{ze.stopPropagation(),en()},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-white/40 opacity-0 transition group-hover:opacity-100 focus-visible:opacity-100 hover:bg-white/10 hover:text-white/75",title:"Open Changes (all outgoing files)","aria-label":"Open outgoing changes",children:(0,ae.jsx)(ri,{className:"h-3 w-3"})})]}),y?(0,ae.jsx)("div",{className:"border-t border-white/[0.05] pb-1.5 pl-1 pr-2 pt-1",children:w.status==="no-upstream"?(0,ae.jsx)("div",{className:"px-2 py-1 text-[10px] text-white/35",children:"No upstream to compare against."}):(0,ae.jsx)(h1,{entry:Y,emptyText:"Nothing outgoing \u2014 the upstream is up to date.",unavailableText:"Outgoing changes unavailable.",onFileClick:Dt,showCounts:s})}):null]},he.key)}let je=Pt.nodes[pe.row];if(!je)return null;let Pe=je.commit,Ce=Pt.rowSegments[pe.row]??[],ln=mp(je.lane),mt=pp(je.lane),Ht=Pe.refs??[],Ge=x.has(Pe.sha),Wt=Aw(je.isMerge,Nt.has(Pe.sha)),tn=Pw(Wt,mt),Be=L.get(Pe.sha);return(0,ae.jsxs)("div",{"data-index":he.index,ref:Ge?Me.measureElement:void 0,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${he.start}px)`},children:[(0,ae.jsxs)("div",{role:"button",tabIndex:0,"data-sha":Pe.sha,onClick:()=>pt(Pe.sha,he.index),onKeyDown:Y=>f1(Y,()=>pt(Pe.sha,he.index)),onMouseEnter:Y=>{if(Ge)return;let Ie=T.current;if(!Ie)return;let _e=Ie.getBoundingClientRect(),ze=Y.currentTarget.getBoundingClientRect(),Te=ze.bottom-_e.top,de=_e.bottom-ze.top;O.set({sha:Pe.sha,below:Te,above:de,flip:Te>_e.height*.55})},onMouseLeave:()=>O.set(Y=>Y&&Y.sha===Pe.sha?null:Y),className:"group/commit relative flex min-w-0 cursor-pointer items-center text-[11px] transition-colors hover:bg-white/[0.04]",style:{height:Gr},children:[(0,ae.jsxs)("svg",{width:Xe,height:Gr,className:"shrink-0",style:{display:"block"},"aria-hidden":!0,children:[Ce.map((Y,Ie)=>(0,ae.jsx)("path",{d:d1(Y),fill:"none",stroke:pp(Y.colorLane),strokeWidth:1.5,strokeOpacity:Y.kind==="stub"?.3:.55,strokeDasharray:Y.kind==="stub"?"2 3":void 0,strokeLinecap:"round"},Ie)),je.isHead?(0,ae.jsx)("circle",{cx:ln,cy:Gr/2,r:c1+2.5,fill:"none",stroke:tn,strokeWidth:1.5,strokeOpacity:.7}):null,(0,ae.jsx)("circle",{cx:ln,cy:Gr/2,r:c1,fill:Wt==="outgoing"?"transparent":Wt==="merge"?"rgba(0,0,0,0.35)":mt,stroke:tn,strokeWidth:Wt==="filled"?1:1.5,fillOpacity:Wt==="filled"?.9:1})]}),(0,ae.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 pr-1",children:[Ge?(0,ae.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/35"}):(0,ae.jsx)(un,{className:"h-3 w-3 shrink-0 text-white/25"}),Ht.length?(0,ae.jsx)("span",{className:"flex shrink-0 items-center gap-1",children:Ht.slice(0,3).map(Y=>{let Ie=Iw(Y);return(0,ae.jsxs)("span",{className:V("flex max-w-[120px] items-center gap-0.5 rounded px-1 py-0.5 text-[9px] font-medium leading-none",Ie==="tag"?"bg-amber-400/15 text-amber-100/80":Ie==="remote"?"border border-white/20 bg-transparent text-white/55":"bg-violet-400/20 text-violet-100/90"),children:[Ie==="remote"?(0,ae.jsx)(bl,{className:"h-2 w-2 shrink-0","aria-hidden":!0}):null,(0,ae.jsx)("span",{className:"truncate",children:aM(Y)})]},Y)})}):null,(0,ae.jsx)("span",{className:"min-w-0 flex-1 truncate text-white/82",children:Pe.subject||"(no message)"}),(0,ae.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/35 transition-opacity group-hover/commit:opacity-0",children:Zt(Pe.sha)}),(0,ae.jsx)("span",{className:"hidden shrink-0 max-w-[120px] truncate text-[10px] text-white/40 transition-opacity group-hover/commit:opacity-0 sm:inline",children:Pe.author}),s&&re[Pe.sha]?(0,ae.jsx)(Pa,{...re[Pe.sha],compact:!0,className:"transition-opacity group-hover/commit:opacity-0"}):null,(0,ae.jsx)("button",{type:"button",onClick:Y=>{Y.stopPropagation(),xe(Pe)},className:"absolute right-1 top-1/2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded bg-white/10 text-white/50 opacity-0 transition group-hover/commit:opacity-100 focus-visible:opacity-100 hover:bg-white/20 hover:text-white/85",title:"Open Changes (all files in this commit)","aria-label":`Open changes of commit ${Zt(Pe.sha)}`,children:(0,ae.jsx)(ri,{className:"h-3 w-3"})})]})]}),Ge?(0,ae.jsxs)("div",{className:"pb-1.5 pl-1 pr-2 pt-0.5",children:[(0,ae.jsxs)("div",{className:"flex items-center gap-2 px-2 text-[10px] text-white/40",children:[(0,ae.jsx)("span",{className:"font-mono",children:Zt(Pe.sha)}),(0,ae.jsx)("span",{className:"min-w-0 truncate",children:Pe.author}),(0,ae.jsx)("span",{title:Pe.date,children:Fh(Pe.date)})]}),(0,ae.jsx)("div",{className:"mt-1 border-t border-white/[0.05] pt-1",children:(0,ae.jsx)(h1,{entry:Be??{status:"loading"},emptyText:"This commit changed no files.",unavailableText:"Commit details unavailable \u2014 the commit may no longer exist.",onFileClick:Y=>Ee(Pe.sha,Y),showCounts:s})})]}):null]},he.key)})}),i.hasMore?(0,ae.jsxs)("div",{ref:te,className:"flex items-center justify-center gap-1.5 px-3 py-2 text-[11px] text-white/40",children:[(0,ae.jsx)(We,{className:V("h-3 w-3",u&&"animate-spin")}),"Loading more commits\u2026"]}):null]})}),(0,ae.jsx)(rM,{store:O,commits:Ye,expandedShas:x})]})}var hn=j(Ve(),1);function ru(n){return Number.isFinite(n)?Math.min(20,Math.max(.05,n)):1}function x1(n){return n>0&&n<1?1/n:1}function y1(n){if(!n)return{};try{let e=JSON.parse(n);if(!e||typeof e!="object"||Array.isArray(e))return{};let t={};for(let[r,a]of Object.entries(e)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a;typeof s.collapsed!="boolean"||typeof s.weight!="number"||(t[r]={collapsed:s.collapsed,weight:ru(s.weight)})}return t}catch{return{}}}function b1(n){return JSON.stringify(n)}function au(n,e,t,r=1){return n[e]??{collapsed:t,weight:ru(r)}}function w1(n,e,t,r,a=1){let s=au(n,e,r,a),o=!t&&s.weight<.15?ru(a):s.weight;return{...n,[e]:{collapsed:t,weight:o}}}function v1(n){let e=n.minBodyPx??72,t=n.heightAbove+n.heightBelow,r=n.weightAbove+n.weightBelow;if(!(t>0)||!(r>0)||t<e*2)return{above:n.weightAbove,below:n.weightBelow};let a=Math.min(t-e,Math.max(e,n.heightAbove+n.deltaY)),s=ru(r*(a/t)),o=ru(r-s);return{above:s,below:o}}var zr=j(le(),1),oM=4;function iM(n){if(typeof window>"u")return{};try{return y1(window.localStorage.getItem(n))}catch{return{}}}function k1({sections:n,storageKey:e}){let[t,r]=(0,hn.useState)(()=>iM(e)),[a,s]=(0,hn.useState)(!1),o=(0,hn.useRef)(t);o.current=t;let i=(0,hn.useRef)(new Map),l=(0,hn.useRef)(null),u=(0,hn.useRef)(!1),c=(0,hn.useCallback)(w=>{if(typeof window<"u")try{window.localStorage.setItem(e,b1(w))}catch{}},[e]),d=(0,hn.useCallback)((w,v,T)=>{r(P=>{let O=au(P,w,v,T),C=w1(P,w,!O.collapsed,v,T);return c(C),C})},[c]),f=(0,hn.useCallback)((w,v,T,P,O,C,I)=>{let H=i.current.get(v),q=i.current.get(T);C&&w.preventDefault(),l.current={aboveId:v,belowId:T,startY:w.clientY,weightAbove:P,weightBelow:O,heightAbove:H?.getBoundingClientRect().height??0,heightBelow:q?.getBoundingClientRect().height??0,engaged:C,belowCollapsed:I,expanded:!1,rebaselined:!1},u.current=!1,s(C),w.currentTarget.setPointerCapture(w.pointerId)},[]),h=(0,hn.useCallback)((w,v,T,P,O,C)=>{f(w,v,T,P,O,!0,C)},[f]),p=(0,hn.useCallback)((w,v,T,P,O,C)=>{w.button===0&&f(w,v,T,P,O,!1,C)},[f]),m=(0,hn.useCallback)(()=>{l.current&&(l.current=null,s(!1),c(o.current))},[c]);(0,hn.useEffect)(()=>{if(a)return window.addEventListener("pointerup",m),window.addEventListener("pointercancel",m),()=>{window.removeEventListener("pointerup",m),window.removeEventListener("pointercancel",m)}},[a,m]);let g=(0,hn.useCallback)(w=>{let v=l.current;if(!v)return;if((w.buttons&1)===0){m();return}let T=w.clientY-v.startY;if(!v.engaged){if(Math.abs(T)<oM)return;v.engaged=!0,u.current=!0,s(!0)}if(v.belowCollapsed&&!v.expanded){v.expanded=!0,r(C=>({...C,[v.belowId]:{collapsed:!1,weight:v.weightBelow}}));return}if(v.belowCollapsed&&!v.rebaselined){let C=i.current.get(v.belowId);if(!C)return;let I=i.current.get(v.aboveId);v.heightAbove=I?.getBoundingClientRect().height??v.heightAbove,v.heightBelow=C.getBoundingClientRect().height,v.startY=w.clientY,v.weightAbove=o.current[v.aboveId]?.weight??v.weightAbove,v.weightBelow=o.current[v.belowId]?.weight??v.weightBelow,v.rebaselined=!0;return}let{above:P,below:O}=v1({weightAbove:v.weightAbove,weightBelow:v.weightBelow,heightAbove:v.heightAbove,heightBelow:v.heightBelow,deltaY:T});r(C=>({...C,[v.aboveId]:{...C[v.aboveId]??{collapsed:!1,weight:1},weight:P},[v.belowId]:{...C[v.belowId]??{collapsed:!1,weight:1},weight:O}}))},[m]),x=(0,hn.useCallback)(w=>{w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),m()},[m]),b=(0,hn.useCallback)((w,v,T,P)=>{let O=l.current?.engaged??!1,C=l.current!=null;w.currentTarget.hasPointerCapture(w.pointerId)&&w.currentTarget.releasePointerCapture(w.pointerId),m(),C&&!O&&d(v,T,P)},[m,d]),y=n.reduce((w,v)=>{let T=au(t,v.id,v.defaultCollapsed??!1,v.defaultWeight??1);return T.collapsed?w:w+T.weight},0),N=x1(y),L=[],A=null;for(let w of n){let v=w.defaultCollapsed??!1,T=w.defaultWeight??1,P=au(t,w.id,v,T),O=A&&!A.collapsed?A:null,C=P.collapsed?T:P.weight;O&&L.push((0,zr.jsx)("div",{role:"separator","aria-orientation":"horizontal",onPointerDown:I=>h(I,O.id,w.id,O.weight,C,P.collapsed),onPointerMove:g,onPointerUp:x,onPointerCancel:m,onLostPointerCapture:m,className:"relative h-1.5 shrink-0 cursor-row-resize touch-none bg-white/0 transition hover:bg-white/[0.06]",children:(0,zr.jsx)("div",{className:"absolute inset-x-6 top-1/2 h-[2px] -translate-y-1/2 rounded-full bg-white/[0.07]"})},`h:${O.id}:${w.id}`)),L.push((0,zr.jsxs)("div",{onPointerDown:O?I=>{I.target.closest("[data-section-actions]")||p(I,O.id,w.id,O.weight,C,P.collapsed)}:void 0,onPointerMove:O?g:void 0,onPointerUp:O?I=>b(I,w.id,v,T):void 0,onPointerCancel:O?m:void 0,onLostPointerCapture:O?m:void 0,className:V("group/section flex h-7 shrink-0 items-center gap-1.5 border-t border-white/[0.04] px-1 first:border-t-0",O&&"touch-none"),children:[(0,zr.jsxs)("button",{type:"button",onClick:I=>{O&&I.detail!==0||d(w.id,v,T)},"aria-expanded":!P.collapsed,className:"flex h-full min-w-0 flex-1 items-center gap-1 rounded px-1 text-left transition-colors hover:bg-white/[0.04]",children:[(0,zr.jsx)(un,{className:V("h-3 w-3 shrink-0 text-white/40 transition-transform",!P.collapsed&&"rotate-90")}),(0,zr.jsx)("span",{className:"truncate text-[10px] font-bold uppercase tracking-wider text-white/40",children:w.title}),typeof w.count=="number"?(0,zr.jsx)("span",{className:"text-[9px] tabular-nums text-white/30",children:w.count}):null,w.badge]}),w.actions?(0,zr.jsx)("div",{"data-section-actions":!0,className:"ml-auto flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover/section:opacity-100",children:w.actions}):null]},`s:${w.id}`)),P.collapsed||L.push((0,zr.jsx)("div",{ref:I=>{I?i.current.set(w.id,I):i.current.delete(w.id)},className:"min-h-0 overflow-auto",style:{flexGrow:P.weight*N,flexBasis:0},children:w.content},`b:${w.id}`)),A={id:w.id,collapsed:P.collapsed,weight:P.weight}}return(0,zr.jsx)("div",{className:V("flex min-h-0 flex-1 flex-col overflow-hidden",a&&"cursor-row-resize select-none"),children:L})}var U=j(le(),1);function xp(n,e,t){(0,we.useEffect)(()=>{if(!n)return;let r=a=>{let s=a.target;s instanceof Node&&e.current?.contains(s)||t()};return document.addEventListener("mousedown",r,!0),()=>document.removeEventListener("mousedown",r,!0)},[n,e,t])}var lM="neuralis.filesystem.gitPanel.sections",S1="neuralis.filesystem.gitPanel.commitOpen",C1="neuralis.filesystem.gitPanel.diffCounts";function uM(n){return typeof n!="string"||!n?"":n.includes("://")?qe(n):n}function cM(n){let e=n.lastIndexOf("/");return e<0?{name:n,dir:""}:{name:n.slice(e+1),dir:n.slice(0,e)}}function dM(n){let e={name:"",path:"",children:new Map};for(let t of n){let r=t.path.split("/").filter(Boolean),a=e,s="";for(let o=0;o<r.length;o++){let i=r[o];s=s?`${s}/${i}`:i;let l=a.children.get(i);l||(l={name:i,path:s,children:new Map},a.children.set(i,l)),a=l,o===r.length-1&&(a.change=t)}}return e}function R1(n,e){let t=[],r=[...n.children.values()].sort((a,s)=>{let o=a.children.size>0,i=s.children.size>0;return o!==i?o?-1:1:a.name.localeCompare(s.name)});for(let a of r)t.push({node:a,depth:e}),a.children.size>0&&t.push(...R1(a,e+1));return t}var L1=Object.freeze({}),I1=we.default.memo(function({change:e,onClick:t,actions:r,busy:a,showCounts:s}){let{name:o,dir:i}=cM(e.path),l=di(e.path),u=d=>d.stopPropagation(),c=!!(r.onDiscard||r.onUnstage||r.onStage);return(0,U.jsxs)("div",{className:"group/row relative flex w-full items-center rounded-md pr-1.5 transition-colors hover:bg-white/[0.05]",children:[(0,U.jsxs)("button",{type:"button",onClick:()=>t(e),title:e.origPath?`${e.origPath} \u2192 ${e.path}`:e.path,className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden py-1 pl-2 pr-1 text-left",children:[(0,U.jsx)(l,{className:"h-4 w-4 shrink-0 text-white/55"}),(0,U.jsx)("span",{className:"shrink-0 truncate text-xs text-white/85",children:o}),i?(0,U.jsx)("span",{className:"min-w-0 flex-1 truncate text-[10px] text-white/35",children:i}):(0,U.jsx)("span",{className:"flex-1"})]}),s?(0,U.jsx)(Pa,{added:e.added,removed:e.removed,binary:e.binary,className:"mr-1 transition-opacity group-hover/row:opacity-0"}):null,(0,U.jsx)("span",{className:"flex w-3.5 shrink-0 items-center justify-center",children:(0,U.jsx)(Pc,{code:e.code})}),c?(0,U.jsxs)("div",{className:"absolute right-6 top-1/2 flex -translate-y-1/2 items-center gap-0.5 rounded bg-gradient-to-r from-transparent via-black/30 to-black/45 pl-4 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100",children:[r.onDiscard?(0,U.jsx)("button",{type:"button",onClick:d=>{u(d),r.onDiscard(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-rose-300/70 transition-colors hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:"Discard changes (destructive)","aria-label":`Discard changes to ${o}`,children:(0,U.jsx)(It,{className:"h-3 w-3"})}):null,r.onUnstage?(0,U.jsx)("button",{type:"button",onClick:d=>{u(d),r.onUnstage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-white/50 transition-colors hover:bg-white/10 hover:text-white/80 disabled:opacity-40",title:"Unstage","aria-label":`Unstage ${o}`,children:(0,U.jsx)(ao,{className:"h-3 w-3"})}):null,r.onStage?(0,U.jsx)("button",{type:"button",onClick:d=>{u(d),r.onStage(e)},disabled:a,className:"inline-flex h-5 w-5 items-center justify-center rounded text-emerald-300/80 transition-colors hover:bg-emerald-500/15 hover:text-emerald-200 disabled:opacity-40",title:"Stage","aria-label":`Stage ${o}`,children:(0,U.jsx)(Tn,{className:"h-3 w-3"})}):null]}):null]})});function A1({changes:n,viewMode:e,staged:t,onRowClick:r,actionsFor:a,busy:s,showCounts:o}){let i=(0,we.useMemo)(()=>e==="tree"?R1(dM(n),0):[],[n,e]),l=(0,we.useCallback)(u=>r(u,t),[r,t]);return(0,U.jsx)("div",{className:"px-1 py-0.5",children:e==="list"?(0,U.jsx)("div",{className:"space-y-px",children:n.map(u=>(0,U.jsx)(I1,{change:u,onClick:l,actions:a(u),busy:s,showCounts:o},`${u.code}:${u.path}`))}):(0,U.jsx)("div",{className:"space-y-px",children:i.map(({node:u,depth:c})=>u.change?(0,U.jsx)("div",{style:{paddingLeft:`${c*12}px`},children:(0,U.jsx)(I1,{change:u.change,onClick:l,actions:a(u.change),busy:s,showCounts:o})},`f:${u.path}`):(0,U.jsxs)("div",{style:{paddingLeft:`${c*12}px`},className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-white/45",children:[(0,U.jsx)(_r,{className:"h-3.5 w-3.5 shrink-0 text-white/35"}),(0,U.jsx)("span",{className:"truncate",children:u.name})]},`d:${u.path}`))})})}function yp({tone:n,onClick:e,disabled:t,title:r,children:a}){return(0,U.jsx)("button",{type:"button",onClick:e,disabled:t,className:V("rounded px-1 py-0.5 text-[9px] transition-colors disabled:opacity-40",n==="discard"?"text-rose-300/70 hover:bg-rose-500/15 hover:text-rose-200":n==="unstage"?"text-white/55 hover:bg-white/10 hover:text-white/85":"text-emerald-300/80 hover:bg-emerald-500/15 hover:text-emerald-200"),title:r,children:a})}function M1({agentId:n}){let e=_(E=>E.sources),t=_(E=>E.activeProjectId),r=_(E=>E.activeSource),a=_(E=>E.activeRepoRel),s=_(E=>E.setActiveSource),o=_(E=>E.gitStatus),i=_(E=>E.gitTotals),l=_(E=>E.gitOutgoingStat),u=_(E=>E.setGitOutgoingStat),c=_(E=>E.gitLoading),d=_(E=>E.gitError),f=_(E=>E.gitViewMode),h=_(E=>E.setGitViewMode),p=_(E=>E.gitBranches),m=_(E=>E.loadGitStatus),g=_(E=>E.loadGitBranches),x=_(E=>E.setGitDiffTarget),b=_(E=>E.setActiveWorkspaceTab),y=_(E=>E.gitLogNonce),[N,L]=(0,we.useState)(!1),[A,w]=(0,we.useState)(!1),v=(0,we.useRef)(null),T=(0,we.useRef)(null),[P,O]=(0,we.useState)(!1),[C,I]=(0,we.useState)(!1),[H,q]=(0,we.useState)(null),[$,S]=(0,we.useState)(""),[M,W]=(0,we.useState)(!1),[ee,te]=(0,we.useState)(()=>Eh(S1,!1)),[re,ce]=(0,we.useState)(()=>Eh(C1,!0)),oe=(0,we.useCallback)(()=>{ce(E=>{let ye=!E;return Oh(C1,ye),ye})},[]),[ue,ie]=(0,we.useState)(null),[Re,De]=(0,we.useState)(null),[Ye,$e]=(0,we.useState)(!1),Pt=(0,we.useCallback)(()=>L(!1),[]),Xe=(0,we.useCallback)(()=>{w(!1),$e(!1)},[]),lt=(0,we.useCallback)(()=>O(!1),[]);xp(N,v,Pt),xp(A,T,Xe),xp(P,T,lt);let[Nt,ot]=(0,we.useState)(""),[Me,tt]=(0,we.useState)(""),pt=(0,we.useMemo)(()=>e.filter(E=>E.git?.isRepo||E.git?.containsRepos),[e]),Rt=(0,we.useMemo)(()=>pt.map(E=>E.uri_root).join("|"),[pt]),kt=(0,we.useMemo)(()=>uM(r),[r]),Ee=(0,we.useMemo)(()=>pt.find(E=>qe(E.uri_root)===kt)??pt[0]??null,[pt,kt]),xe=Ee?qe(Ee.uri_root):"",Dt=pt.length>1||pt.some(E=>!E.git?.isRepo&&E.git?.containsRepos),en=(0,we.useRef)(new Map),[he,pe]=(0,we.useState)(()=>new Map),je=(0,we.useCallback)(async(E,ye)=>{if(!n||!E)return[];let jt=en.current.get(E);if(jt&&(jt instanceof Promise||!ye?.force))return jt;let Ut=(async()=>{try{let gn=await Xo({agentId:n,...t?{projectId:t}:{},source:E}),kn=Array.isArray(gn?.repos)?gn.repos:[];return en.current.set(E,kn),pe(ec=>new Map(ec).set(E,kn)),kn}catch{return en.current.delete(E),pe(gn=>gn.has(E)?gn:new Map(gn).set(E,[])),[]}})();return en.current.set(E,Ut),Ut},[n,t]),Pe=(0,we.useMemo)(()=>a?he.get(xe)?.find(E=>E.rel===a)??null:null,[a,he,xe]),Ce=a?Pe?.canWrite===!0:Ee?.git?.canWrite===!0,ln=a?Pe?.canExec===!0:Ee?.git?.canExec===!0,mt=o?.staged.length??0,Ht=Es(xe,a?Pe?.name??a:Ee?.git?.repoName),Ge=(0,we.useMemo)(()=>Nw(o),[o]);(0,we.useEffect)(()=>{xe&&xe!==kt&&s(xe)},[n,t,xe,Rt]),(0,we.useEffect)(()=>{let E=Ee?.git;if(!xe||!E||E.isRepo||!E.containsRepos)return;let ye=!1;return je(xe).then(jt=>{ye||a||jt.length===0||s(xe,jt[0].rel)}),()=>{ye=!0}},[xe,Ee,a,je,s]);let Wt=(0,we.useRef)(y);(0,we.useEffect)(()=>{if(y===Wt.current)return;Wt.current=y;let E=Ee?.git;!xe||!E||E.isRepo||!E.containsRepos||je(xe,{force:!0})},[y,xe,Ee,je]),(0,we.useEffect)(()=>{xe&&m({agentId:n,projectId:t??null,source:xe,repo:a})},[n,t,xe,a,Rt]),(0,we.useEffect)(()=>{if(!Re)return;let E=setTimeout(()=>De(null),9e3);return()=>clearTimeout(E)},[Re]);let tn=(0,we.useCallback)((E,ye)=>{L(!1),s(E,ye)},[s]),Be=(0,we.useCallback)(()=>{w(!1),$e(!1),O(!1),L(E=>{let ye=!E;if(ye)for(let jt of pt){let Ut=jt.git;Ut&&!Ut.isRepo&&Ut.containsRepos&&je(qe(jt.uri_root),{force:!0})}return ye})},[pt,je]),Y=(0,we.useCallback)(()=>{te(E=>{let ye=!E;return Oh(S1,ye),ye})},[]),_e=(0,we.useCallback)(()=>{xe&&m({agentId:n,projectId:t??null,source:xe,repo:a})},[n,t,xe,a,m]),ze=(0,we.useCallback)((E,ye)=>{xe&&(x({source:xe,...a?{repo:a}:{},path:E.path,staged:ye}),b("git-diff"))},[xe,a,x,b]),Te=(0,we.useCallback)(async E=>{if(xe){I(!0),q(null);try{let ye=await E();return m({agentId:n,projectId:t??null,source:xe,repo:a}),ye}catch(ye){q(ye instanceof Error?ye.message:"Git operation failed");return}finally{I(!1)}}},[xe,a,n,t,m]),de=(0,we.useMemo)(()=>({...t?{projectId:t}:{},...a?{repo:a}:{}}),[t,a]),ut=(0,we.useCallback)(E=>{E.length!==0&&Te(()=>q0({agentId:n,...de,source:xe,paths:E}))},[Te,n,de,xe]),Ft=(0,we.useCallback)(E=>{E.length!==0&&Te(()=>V0({agentId:n,...de,source:xe,paths:E}))},[Te,n,de,xe]),nn=(0,we.useCallback)(E=>{(async()=>{let ye=await Te(()=>X0({agentId:n,...de,source:xe,paths:E}));ye&&ye.rescue&&De({message:`Discarded ${E.length} file${E.length===1?"":"s"} \u2014 recoverable`,rescue:ye.rescue})})()},[Te,n,de,xe]),$n=(0,we.useCallback)(E=>{E.length!==0&&ie({title:"Discard changes",message:`Overwrite the working-tree version of ${E.length} file${E.length===1?"":"s"} with the last committed/indexed content? A rescue snapshot is saved server-side so it can be recovered.`,confirmLabel:"Discard",onConfirm:()=>{ie(null),nn(E)}})},[nn]),ar=(0,we.useCallback)(E=>ut([E.path]),[ut]),xr=(0,we.useCallback)(E=>Ft([E.path]),[Ft]),Kn=(0,we.useCallback)(E=>$n([E.path]),[$n]),Xn=(0,we.useMemo)(()=>({onStage:ar}),[ar]),Yn=(0,we.useMemo)(()=>({onStage:ar,onDiscard:Kn}),[ar,Kn]),xa=(0,we.useMemo)(()=>({onUnstage:xr}),[xr]),yr=(0,we.useCallback)(E=>Ce?E.code==="??"?Xn:Yn:L1,[Ce,Xn,Yn]),Jn=(0,we.useCallback)(()=>Ce?xa:L1,[Ce,xa]),dn=(0,we.useCallback)(()=>{let E=$.trim();E&&(async()=>{let ye=await Te(()=>Y0({agentId:n,...de,source:xe,message:E,amend:M}));ye&&ye.ok&&(S(""),W(!1))})()},[$,M,Te,n,de,xe]),Rn=(0,we.useCallback)(()=>{L(!1),O(!1),w(E=>{let ye=!E;return ye&&xe&&g({agentId:n,projectId:t??null,source:xe,repo:a}),ye}),$e(!1)},[xe,a,n,t,g]),rn=(0,we.useCallback)(E=>{w(!1),(async()=>await Te(()=>th({agentId:n,...de,source:xe,ref:E}))&&g({agentId:n,projectId:t??null,source:xe,repo:a}))()},[Te,n,de,xe,a,g,t]),Dr=(0,we.useCallback)(()=>{let E=Nt.trim();if(!E)return;let ye=Me.trim();w(!1),$e(!1),ot(""),tt(""),(async()=>await Te(()=>J0({agentId:n,...de,source:xe,name:E,...ye?{startPoint:ye}:{}}))&&(await Te(()=>th({agentId:n,...de,source:xe,ref:E})),g({agentId:n,projectId:t??null,source:xe,repo:a})))()},[Nt,Me,Te,n,de,xe,a,g,t]),Zn=(0,we.useCallback)(E=>{(async()=>{let ye=await Te(()=>Z0({agentId:n,...de,source:xe,name:E}));ye&&ye.rescue&&De({message:`Deleted branch "${E}" \u2014 recoverable`,rescue:ye.rescue}),g({agentId:n,projectId:t??null,source:xe,repo:a})})()},[Te,n,de,xe,a,g,t]),Fr=(0,we.useCallback)(E=>{w(!1),ie({title:"Delete branch",message:`Delete the local branch "${E.name}"? A rescue ref is saved so it can be recreated (git will refuse if it has unmerged commits).`,confirmLabel:"Delete branch",onConfirm:()=>{ie(null),Zn(E.name)}})},[Zn]),sr=(0,we.useCallback)(()=>{if(!Re)return;let E=Re.rescue;De(null),Te(()=>Q0({agentId:n,...de,source:xe,rescue:E}))},[Re,Te,n,de,xe]),_n=(0,we.useCallback)(()=>{O(!1),Te(()=>ex({agentId:n,...de,source:xe}))},[Te,n,de,xe]),Zr=(0,we.useCallback)(()=>{O(!1),Te(()=>tx({agentId:n,...de,source:xe}))},[Te,n,de,xe]),br=(0,we.useCallback)(()=>{O(!1),Te(()=>nx({agentId:n,...de,source:xe}))},[Te,n,de,xe]),vn=o?.unstaged??[],z=o?.staged??[],ne=o?.untracked??[],R=(0,we.useMemo)(()=>[...vn,...ne].sort((E,ye)=>E.path.localeCompare(ye.path)),[vn,ne]);if(pt.length===0)return(0,U.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10 text-center",children:[(0,U.jsx)(Sn,{className:"h-5 w-5 text-white/25"}),(0,U.jsx)("div",{className:"text-xs text-white/40",children:"No git repositories"}),(0,U.jsx)("div",{className:"max-w-[200px] text-[10px] text-white/30",children:"Sources whose root is \u2014 or whose folders contain \u2014 a git checkout appear here."})]});let X=Ce&&$.trim().length>0&&(mt>0||M)&&!C,B=d?(0,U.jsx)("div",{className:"px-2 py-3 text-[11px] text-rose-300/70",children:d}):c&&!o?(0,U.jsx)("div",{className:"px-2 py-3 text-[11px] text-white/35",children:"Loading git status\u2026"}):R.length===0?(0,U.jsx)("div",{className:"px-2 py-4 text-center text-[11px] text-white/35",children:"No changes"}):(0,U.jsx)(A1,{changes:R,viewMode:f,staged:!1,showCounts:re,onRowClick:ze,actionsFor:yr,busy:C}),me=[{id:"changes",title:"Changes",count:R.length,badge:i?(0,U.jsx)(Pa,{...i.changes,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Ce&&R.length>0?(0,U.jsxs)(U.Fragment,{children:[vn.length>0?(0,U.jsx)(yp,{tone:"discard",onClick:()=>$n(vn.map(E=>E.path)),disabled:C,title:"Discard all tracked changes in this group (destructive)",children:"Discard all"}):null,(0,U.jsx)(yp,{tone:"stage",onClick:()=>ut(R.map(E=>E.path)),disabled:C,title:"Stage all",children:"Stage all"})]}):void 0,content:B},...z.length>0?[{id:"staged",title:"Staged Changes",count:z.length,badge:i?(0,U.jsx)(Pa,{...i.staged,compact:!0,className:"ml-auto pr-1"}):void 0,actions:Ce?(0,U.jsx)(yp,{tone:"unstage",onClick:()=>Ft(z.map(E=>E.path)),disabled:C,title:"Unstage all",children:"Unstage all"}):void 0,content:(0,U.jsx)(A1,{changes:z,viewMode:f,staged:!0,showCounts:re,onRowClick:ze,actionsFor:Jn,busy:C})}]:[],{id:"graph",title:"Graph",badge:l?(0,U.jsx)(Pa,{added:l.added,removed:l.removed,unknown:l.commits-l.covered,compact:!0,className:"ml-auto pr-1"}):void 0,defaultCollapsed:!0,defaultWeight:2,content:(0,U.jsx)(g1,{showCounts:re,onOutgoingStat:u,source:xe,repo:a,agentId:n,projectId:t??null,repoName:a?Pe?.name??a:Ee?.git?.repoName},`${xe}\0${a}`)}];return(0,U.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,U.jsxs)("div",{ref:v,className:"relative px-2 pt-1 pb-1.5",children:[(0,U.jsxs)("div",{className:"flex items-center gap-1",children:[(0,U.jsxs)("button",{type:"button",onClick:Be,disabled:!Dt,className:V("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left transition-colors","bg-white/[0.03] hover:bg-white/[0.06] disabled:hover:bg-white/[0.03]"),title:xe?Ht.title:"Select a repository",children:[(0,U.jsx)(Sn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/80"}),Ht.prefix?(0,U.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:Ht.prefix}):null,(0,U.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-white/85",children:Ht.name||"Select repository"}),Dt?(0,U.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/40"}):null]}),(0,U.jsx)("button",{type:"button",onClick:_e,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-white/40 transition-colors hover:bg-white/[0.06] hover:text-white/70",title:"Refresh git status","aria-label":"Refresh git status",children:(0,U.jsx)(Ot,{className:V("h-3.5 w-3.5",c&&"animate-spin")})}),(0,U.jsx)(N1.SkillLauncher,{variant:"icon",size:"sm",skill:"git",packageId:"@neuralis/brain-core",scripts:["scripts/git.sh"],label:"Status, diff, commit, branch, fetch or push with the agent",icon:"GitBranch"})]}),N&&Dt?(0,U.jsx)(U.Fragment,{children:(0,U.jsx)("div",{className:"absolute left-2 right-2 z-50 mt-1 max-h-56 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.96)] py-1 shadow-lg",children:pt.map(E=>{let ye=qe(E.uri_root);if(E.git?.isRepo){let Ut=ye===xe&&!a,gn=Es(ye,E.git?.repoName);return(0,U.jsxs)("button",{type:"button",onClick:()=>tn(ye,""),className:V("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",Ut?"text-white/90":"text-white/65"),children:[(0,U.jsx)(Sn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),gn.prefix?(0,U.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:gn.prefix}):null,(0,U.jsx)("span",{className:"min-w-0 flex-1 truncate",children:gn.name}),E.git?.branch?(0,U.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:E.git.branch}):null,Ut?(0,U.jsx)(Mn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},E.uri_root)}let jt=he.get(ye);return jt?jt.length===0?(0,U.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,U.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${ye}://`}),(0,U.jsx)("span",{className:"truncate",children:"No repositories found."})]},E.uri_root):jt.map(Ut=>{let gn=ye===xe&&a===Ut.rel,kn=Es(ye,Ut.name||Ut.rel);return(0,U.jsxs)("button",{type:"button",onClick:()=>tn(ye,Ut.rel),className:V("flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-white/[0.06]",gn?"text-white/90":"text-white/65"),children:[(0,U.jsx)(Sn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),kn.prefix?(0,U.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:kn.prefix}):null,(0,U.jsx)("span",{className:"min-w-0 flex-1 truncate",children:kn.name}),Ut.branch?(0,U.jsx)("span",{className:"shrink-0 truncate text-[10px] text-white/35",children:Ut.branch}):null,gn?(0,U.jsx)(Mn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]},`${E.uri_root}\0${Ut.rel}`)}):(0,U.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-white/35",children:[(0,U.jsx)(We,{className:"h-3 w-3 shrink-0 animate-spin"}),(0,U.jsx)("span",{className:"shrink-0 font-mono text-[10px] text-white/40",children:`${ye}://`}),(0,U.jsx)("span",{className:"truncate",children:"Scanning repositories\u2026"})]},E.uri_root)})})}):null]}),(0,U.jsxs)("div",{ref:T,className:"relative flex items-center justify-between gap-2 px-2 pb-1.5",children:[(0,U.jsxs)("div",{className:"flex min-w-0 items-center gap-1",children:[(0,U.jsxs)("button",{type:"button",onClick:Rn,className:"flex min-w-0 items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:"Switch or create branch","aria-haspopup":"menu","aria-expanded":A,children:[(0,U.jsx)(Sn,{className:"h-3 w-3 shrink-0 text-white/40"}),(0,U.jsx)("span",{className:"truncate",children:o?.branch??"\u2014"}),(0,U.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}),Ce?(0,U.jsx)("button",{type:"button",onClick:()=>{L(!1),w(!1),$e(!1),O(E=>!E)},className:"flex shrink-0 items-center gap-1.5 rounded bg-white/[0.05] px-1.5 py-0.5 text-[10px] leading-none tabular-nums text-white/60 transition-colors hover:bg-white/[0.08] hover:text-white/85",title:"Fetch / pull / push","aria-haspopup":"menu","aria-expanded":P,children:Ge?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ge.ahead} commits ahead of ${Ge.upstream}`,children:[(0,U.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,U.jsx)("span",{className:"text-blue-200/90",children:Ge.ahead})]}),(0,U.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ge.behind} commits behind ${Ge.upstream}`,children:[(0,U.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,U.jsx)("span",{className:"text-white/70",children:Ge.behind})]})]}):(0,U.jsx)(pl,{className:"h-3 w-3 text-white/40"})}):Ge?(0,U.jsxs)("span",{className:"flex shrink-0 cursor-default items-center gap-1.5 rounded bg-white/[0.05] px-1 py-0.5 text-[10px] leading-none tabular-nums",title:`${Ge.upstream}: ahead/behind vs the tracked upstream (local refs)`,children:[(0,U.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ge.ahead} commits ahead of ${Ge.upstream}`,children:[(0,U.jsx)("span",{className:"text-blue-300/60",children:"\u2191"}),(0,U.jsx)("span",{className:"text-blue-200/90",children:Ge.ahead})]}),(0,U.jsxs)("span",{className:"flex items-center gap-0.5","aria-label":`${Ge.behind} commits behind ${Ge.upstream}`,children:[(0,U.jsx)("span",{className:"text-white/40",children:"\u2193"}),(0,U.jsx)("span",{className:"text-white/70",children:Ge.behind})]})]}):null,Ce?(0,U.jsxs)("button",{type:"button",onClick:Y,className:"flex shrink-0 items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-white/55 transition-colors hover:bg-white/[0.05] hover:text-white/80",title:ee?"Hide the commit box":"Show the commit box","aria-expanded":ee,children:[(0,U.jsx)("span",{children:"Commit"}),mt>0?(0,U.jsx)("span",{className:"rounded bg-white/[0.08] px-1 py-0.5 text-[9px] leading-none tabular-nums text-white/70",children:mt}):null,ee?(0,U.jsx)($a,{className:"h-3 w-3 shrink-0 text-white/30"}):(0,U.jsx)(Tt,{className:"h-3 w-3 shrink-0 text-white/30"})]}):null]}),(0,U.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 rounded-md bg-white/[0.03] p-0.5",children:[(0,U.jsx)("button",{type:"button",onClick:()=>h("list"),className:V("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="list"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Flat list","aria-label":"Flat list view","aria-pressed":f==="list",children:(0,U.jsx)(no,{className:"h-3 w-3"})}),(0,U.jsx)("button",{type:"button",onClick:()=>h("tree"),className:V("inline-flex h-5 w-5 items-center justify-center rounded transition-colors",f==="tree"?"bg-white/10 text-white/85":"text-white/40 hover:text-white/70"),title:"Folder tree","aria-label":"Folder tree view","aria-pressed":f==="tree",children:(0,U.jsx)(Ll,{className:"h-3 w-3"})})]}),(0,U.jsx)("button",{type:"button",onClick:oe,className:V("inline-flex h-5 w-5 shrink-0 items-center justify-center rounded transition-colors",re?"text-white/85":"text-white/35 hover:text-white/60"),title:re?"Hide per-row diff counts":"Show per-row diff counts","aria-label":"Toggle per-row diff counts","aria-pressed":re,children:(0,U.jsx)(Bl,{className:"h-3 w-3"})}),A?(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"absolute left-2 right-2 top-full z-50 mt-1 max-h-72 overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,U.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Branches"}),p.length===0?(0,U.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-white/35",children:"No branches loaded."}):p.map(E=>(0,U.jsxs)("div",{className:"group flex items-center gap-1.5 pr-1",children:[(0,U.jsxs)("button",{type:"button",onClick:()=>!E.current&&rn(E.name),disabled:E.current||C,className:V("flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1.5 text-left text-xs transition-colors",E.current?"text-violet-200/90":"text-white/70 hover:bg-white/[0.06]"),title:E.current?`${E.name} (current)`:`Switch to ${E.name}`,children:[(0,U.jsx)(Sn,{className:"h-3.5 w-3.5 shrink-0 text-white/40"}),(0,U.jsx)("span",{className:"min-w-0 flex-1 truncate",children:E.name}),E.current?(0,U.jsx)(Mn,{className:"h-3 w-3 shrink-0 text-violet-300/80"}):null]}),Ce&&!E.current?(0,U.jsx)("button",{type:"button",onClick:()=>Fr(E),disabled:C,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-rose-300/60 opacity-0 transition group-hover:opacity-100 hover:bg-rose-500/15 hover:text-rose-200 disabled:opacity-40",title:`Delete branch ${E.name}`,"aria-label":`Delete branch ${E.name}`,children:(0,U.jsx)(It,{className:"h-3 w-3"})}):null]},E.name)),Ce?(0,U.jsx)("div",{className:"mt-1 border-t border-white/[0.06] pt-1",children:Ye?(0,U.jsxs)("div",{className:"px-2 py-1.5",children:[(0,U.jsx)("input",{value:Nt,onChange:E=>ot(E.target.value),onKeyDown:E=>{E.key==="Enter"&&Dr()},placeholder:"new-branch-name",autoFocus:!0,className:"mb-1 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,U.jsx)("input",{value:Me,onChange:E=>tt(E.target.value),onKeyDown:E=>{E.key==="Enter"&&Dr()},placeholder:"from (optional ref \u2014 default HEAD)",className:"mb-1.5 h-6 w-full rounded border border-white/[0.12] bg-white/[0.04] px-1.5 text-[11px] text-white/85 outline-none placeholder:text-white/25 focus:border-white/25"}),(0,U.jsxs)("div",{className:"flex items-center gap-1",children:[(0,U.jsxs)("button",{type:"button",onClick:Dr,disabled:C||Nt.trim().length===0,className:"inline-flex items-center gap-1 rounded bg-violet-500/20 px-2 py-1 text-[10px] text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",children:[(0,U.jsx)(Tn,{className:"h-3 w-3"})," Create & switch"]}),(0,U.jsx)("button",{type:"button",onClick:()=>{$e(!1),ot(""),tt("")},className:"rounded px-2 py-1 text-[10px] text-white/50 transition-colors hover:bg-white/[0.06] hover:text-white/80",children:"Cancel"})]})]}):(0,U.jsxs)("button",{type:"button",onClick:()=>$e(!0),className:"flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-white/70 transition-colors hover:bg-white/[0.06]",children:[(0,U.jsx)(Tn,{className:"h-3.5 w-3.5 shrink-0 text-violet-300/70"}),(0,U.jsx)("span",{children:"Create new branch\u2026"})]})}):null]})}):null,P?(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"absolute right-2 top-full z-50 mt-1 w-52 max-w-[calc(100%-1rem)] overflow-auto rounded-md border border-white/10 bg-[rgba(var(--w-bg-rgb),0.97)] py-1 shadow-lg",children:[(0,U.jsx)("div",{className:"px-2 py-1 text-[9px] font-bold uppercase tracking-wider text-white/35",children:"Remote"}),ln?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("button",{type:"button",onClick:Zr,disabled:C,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch + fast-forward merge (git pull, ff-only)",children:[(0,U.jsx)(hl,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,U.jsx)("span",{className:"min-w-0 flex-1",children:"Pull"}),Ge&&Ge.behind>0?(0,U.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-white/50",children:["\u2193",Ge.behind]}):null]}),(0,U.jsxs)("button",{type:"button",onClick:br,disabled:C,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Push the current branch (git push origin HEAD)",children:[(0,U.jsx)(ml,{className:"h-3.5 w-3.5 shrink-0 text-blue-300/60"}),(0,U.jsx)("span",{className:"min-w-0 flex-1",children:"Push"}),Ge&&Ge.ahead>0?(0,U.jsxs)("span",{className:"shrink-0 tabular-nums text-[10px] text-blue-200/80",children:["\u2191",Ge.ahead]}):null]}),(0,U.jsxs)("button",{type:"button",onClick:_n,disabled:C,className:"flex w-full items-center gap-2 px-2 py-1.5 text-left text-xs text-white/75 transition-colors hover:bg-white/[0.06] disabled:opacity-40",title:"Fetch remote refs (git fetch origin)",children:[(0,U.jsx)(Ot,{className:"h-3.5 w-3.5 shrink-0 text-white/45"}),(0,U.jsx)("span",{className:"min-w-0 flex-1",children:"Fetch"})]})]}):(0,U.jsxs)("div",{className:"flex items-start gap-1.5 px-2 py-2",children:[(0,U.jsx)(ro,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/70"}),(0,U.jsxs)("div",{className:"min-w-0 text-[11px] leading-snug text-white/55",children:["Remote git operations need ",(0,U.jsx)("span",{className:"font-medium text-white/75",children:"exec"})," permission on this source. Ask an owner to grant it."]})]})]})}):null]}),Re?(0,U.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-amber-500/20 bg-amber-500/[0.07] px-2 py-1.5",children:[(0,U.jsx)(ct,{className:"mt-0.5 h-3 w-3 shrink-0 text-amber-300/80"}),(0,U.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,U.jsx)("div",{className:"text-[11px] text-amber-100/85",children:Re.message}),(0,U.jsxs)("div",{className:"truncate font-mono text-[9px] text-amber-100/45",title:Re.rescue.ref,children:["rescue: ",Re.rescue.ref]})]}),(0,U.jsx)("button",{type:"button",onClick:sr,disabled:C,className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold text-amber-100 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:"Undo"}),(0,U.jsx)("button",{type:"button",onClick:()=>De(null),className:"shrink-0 rounded p-0.5 text-amber-200/60 transition-colors hover:bg-amber-500/15 hover:text-amber-100","aria-label":"Dismiss recovery notice",children:(0,U.jsx)(Bt,{className:"h-3 w-3"})})]}):null,H?(0,U.jsxs)("div",{className:"mx-2 mb-1 flex items-start gap-1.5 rounded-md border border-rose-500/20 bg-rose-500/[0.06] px-2 py-1.5",children:[(0,U.jsx)(ct,{className:"mt-0.5 h-3 w-3 shrink-0 text-rose-300/80"}),(0,U.jsx)("div",{className:"min-w-0 flex-1 text-[11px] text-rose-200/85",children:H}),(0,U.jsx)("button",{type:"button",onClick:()=>q(null),className:"shrink-0 rounded p-0.5 text-rose-200/60 transition-colors hover:bg-rose-500/15 hover:text-rose-100","aria-label":"Dismiss error",children:(0,U.jsx)(Bt,{className:"h-3 w-3"})})]}):null,Ce&&ee?(0,U.jsxs)("div",{className:"mx-2 mb-1.5 rounded-md border border-white/[0.07] bg-white/[0.02] p-1",children:[(0,U.jsx)("textarea",{value:$,onChange:E=>S(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.metaKey||E.ctrlKey)&&!E.nativeEvent.isComposing&&X&&(E.preventDefault(),dn())},placeholder:mt>0?`Commit message (${mt} staged)`:"Commit message",rows:2,className:"w-full resize-none rounded bg-transparent px-1 text-[11px] text-white/85 outline-none placeholder:text-white/30"}),(0,U.jsxs)("div",{className:"mt-0.5 flex items-center justify-end gap-2",children:[(0,U.jsxs)("label",{className:"flex cursor-pointer select-none items-center gap-1 text-[10px] text-white/50",children:[(0,U.jsx)("input",{type:"checkbox",checked:M,onChange:E=>W(E.target.checked),className:"h-3 w-3 accent-violet-400"}),"Amend"]}),(0,U.jsxs)("button",{type:"button",onClick:dn,disabled:!X,className:"inline-flex items-center gap-1 rounded-md bg-violet-500/20 px-2.5 py-1 text-[11px] font-medium text-violet-100/90 transition-colors hover:bg-violet-500/30 disabled:opacity-40",title:M?"Amend the last commit":"Commit the staged changes",children:[C?(0,U.jsx)(We,{className:"h-3 w-3 animate-spin"}):(0,U.jsx)(Mn,{className:"h-3 w-3"}),M?"Amend":"Commit"]})]})]}):null,(0,U.jsx)(k1,{storageKey:lM,sections:me}),ue&&typeof document<"u"?(0,P1.createPortal)((0,U.jsxs)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center p-4",children:[(0,U.jsx)("button",{type:"button","aria-hidden":!0,tabIndex:-1,onClick:()=>ie(null),className:"absolute inset-0 cursor-default bg-black/50"}),(0,U.jsxs)("div",{className:"relative z-10 w-full max-w-xs rounded-lg border border-white/10 bg-[rgba(var(--w-bg-rgb),0.98)] p-4 shadow-xl",children:[(0,U.jsxs)("div",{className:"mb-1 flex items-center gap-2",children:[(0,U.jsx)(ct,{className:"h-4 w-4 shrink-0 text-rose-300/80"}),(0,U.jsx)("span",{className:"text-sm font-semibold text-white/90",children:ue.title})]}),(0,U.jsx)("p",{className:"mb-3 text-[11px] leading-relaxed text-white/55",children:ue.message}),(0,U.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,U.jsx)("button",{type:"button",onClick:()=>ie(null),className:"rounded-md px-3 py-1.5 text-[11px] text-white/60 transition-colors hover:bg-white/[0.06] hover:text-white/85",children:"Cancel"}),(0,U.jsxs)("button",{type:"button",onClick:ue.onConfirm,className:"inline-flex items-center gap-1 rounded-md border border-rose-500/30 bg-rose-500/15 px-3 py-1.5 text-[11px] font-semibold text-rose-100 transition-colors hover:bg-rose-500/25",children:[(0,U.jsx)(It,{className:"h-3 w-3"}),ue.confirmLabel]})]})]})]}),document.body):null]})}var Ct=j(le(),1),T1={},D1="brain://",fM=32,hM=28,pM=114;function mM(n){return n==="header"?fM:n==="empty"?pM:hM}function gM(n){return n!=="node"}function F1(n,e){return n.type===e.type?n.name.localeCompare(e.name):n.type==="folder"?-1:1}function xM(n){let e=new Map,t=new Set;for(let a of n)t.add(a.uri);for(let a of n){let s=a.parentUri??nt(a.uri);if(!s||a.uri===s)continue;let o=e.get(s);o?o.push(a):e.set(s,[a])}for(let a of e.values())a.sort(F1);let r=new Map;for(let a of n){let s=or(a.uri);if(!s||a.uri===s)continue;let o=a.parentUri??nt(a.uri);if(!(!o||o===s||!t.has(o)))continue;let l=r.get(s);l?l.push(a):r.set(s,[a])}for(let a of r.values())a.sort(F1);return{childrenByParent:e,rootsBySource:r}}function yM(n,e,t){let r=[],a=(o,i)=>{r.push({node:o,depth:i});let l=o.storeKey||Va(o);if(o.type==="folder"&&t.has(l)){let u=n.childrenByParent.get(o.uri);if(u)for(let c=0;c<u.length;c++)a(u[c],i+1)}},s=n.rootsBySource.get(e);if(s)for(let o=0;o<s.length;o++)a(s[o],0);return r}function bp(n){let{agentId:e,sidebarView:t="tree"}=n,r=fn(),a=_(R=>R.files),s=_(R=>R.folderBadges),o=_(R=>R.expandedFolders),i=_(R=>R.activeFile),l=_(R=>R.toggleFolder),u=_(R=>R.openFile),c=_(R=>R.activeProjectId),d=_(R=>R.setActiveFolderPath),f=_(R=>R.activeFolderPath),h=_(R=>R.uploadMany),p=_(R=>R.moveFileToFolder),m=_(R=>R.uploading),g=_(R=>R.sources),x=_(R=>R.sourcesLoading),b=_(R=>R.hydrationState),y=_(R=>R.dirtySources),N=_(R=>R.organizeError),L=_(R=>R.clearOrganizeError),A=_(R=>R.snapshotError),w=_(R=>R.clearSnapshotError),v=_(R=>R.loadList),T=_(R=>R.pendingReviewPaths),P=_(R=>R.renameNode),O=_(R=>R.deleteNodes),C=_(R=>R.createNode),I=_(R=>R.pasteNodes),[H,q]=(0,Ue.useState)(null),[$,S]=(0,Ue.useState)({}),[M,W]=(0,Ue.useState)(()=>new Set),[ee,te]=(0,Ue.useState)(null),[re,ce]=(0,Ue.useState)(null),[oe,ue]=(0,Ue.useState)(null),[ie,Re]=(0,Ue.useState)(null),[De,Ye]=(0,Ue.useState)(null),[$e,Pt]=(0,Ue.useState)(null),[Xe,lt]=(0,Ue.useState)(!1),[Nt,ot]=(0,Ue.useState)(!1),Me=_(R=>R.setPendingSourceSuggestion),tt=_(R=>R.setWorkspacePanelOpen);(0,Ue.useEffect)(()=>{if(!i)return;let R=`${qe(i)}://`;S(X=>X[R]?X:{...X,[R]:!0})},[i]);let pt=r.useFileMarks(e),Rt=r.useAgents(),kt=r.usePackageIconBySlug?.()??T1,Ee=(0,Ue.useMemo)(()=>pt||T1,[pt]),xe=(0,Ue.useMemo)(()=>Ts(Rt),[Rt]),Dt=(0,Ue.useMemo)(()=>xe.byId.get(e)??null,[xe,e]),en=(0,Ue.useMemo)(()=>{let R={};for(let X of T){let B=ba(X);for(let me of B)R[me]=(R[me]||0)+1}return R},[T]),he=g.length>0,pe=(0,Ue.useMemo)(()=>Object.values(a),[a]),je=(0,Ue.useMemo)(()=>xM(pe),[pe]),Pe=(0,Ue.useMemo)(()=>{let R={uri_root:D1,source_kind:"brain",writable:!0};return he?g.length>0?g:[R]:[R]},[he,g]),Ce=t==="search",ln=(0,Ue.useMemo)(()=>{let R=f?or(f):null;return R&&Pe.some(B=>B.uri_root===R)?R:Pe.find(B=>B.source_kind!=="brain")?.uri_root??Pe[0]?.uri_root??D1},[f,Pe]),mt=(0,Ue.useMemo)(()=>{if(Ce)return[];let R=[];for(let X of Pe){let B=$[X.uri_root]??!1;if(R.push({kind:"header",key:`h:${X.uri_root}`,info:X,expanded:B}),!B)continue;let me=yM(je,X.uri_root,o);if(me.length===0)R.push({kind:"empty",key:`e:${X.uri_root}`,sourceRoot:X.uri_root});else for(let E of me)R.push({kind:"node",key:`n:${E.node.uri}`,node:E.node,depth:E.depth})}if(oe){let X=oe.parentUri,B=-1,me=0;if(X.endsWith("://"))B=R.findIndex(E=>E.kind==="header"&&E.info.uri_root===X),me=0;else{let E=R.findIndex(ye=>ye.kind==="node"&&ye.node.uri===X);E>=0&&(B=E,me=R[E].depth+1)}B>=0&&R.splice(B+1,0,{kind:"creating",key:"creating-row",parentUri:X,createKind:oe.kind,depth:me})}return R},[je,o,Pe,$,Ce,oe]),Ht=(0,Ue.useMemo)(()=>mt.filter(R=>R.kind==="node").map(R=>R.node.uri),[mt]),Ge=(0,Ue.useCallback)(({node:R,additive:X,range:B})=>{W(me=>{if(B&&ee){let E=Ht.indexOf(ee),ye=Ht.indexOf(R.uri);if(E>=0&&ye>=0){let[jt,Ut]=E<=ye?[E,ye]:[ye,E];return new Set(Ht.slice(jt,Ut+1))}}if(X){let E=new Set(me);return E.has(R.uri)?E.delete(R.uri):E.add(R.uri),E}return new Set([R.uri])}),B||te(R.uri)},[Ht,ee]),Wt=(0,Ue.useCallback)(({node:R,x:X,y:B})=>{W(me=>me.has(R.uri)&&me.size>1?me:new Set([R.uri])),te(R.uri),Ye({kind:"node",node:R,x:X,y:B})},[]),tn=(0,Ue.useCallback)((R,X)=>{X.preventDefault(),X.stopPropagation(),S(B=>B[R]?B:{...B,[R]:!0}),Ye({kind:"source",sourceRoot:R,x:X.clientX,y:X.clientY})},[]),Be=(0,Ue.useCallback)(R=>{R.target.closest('button, input, textarea, [role="menu"]')||tn(ln,R)},[ln,tn]),Y=(0,Ue.useMemo)(()=>De?.kind!=="node"?[]:(M.has(De.node.uri)&&M.size>0?[...M]:[De.node.uri]).map(X=>a[X]).filter(Boolean),[De,M,a]),Ie=(0,Ue.useMemo)(()=>ii({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.sync"]}),[r.grantedFeatures]),[_e,ze]=(0,Ue.useState)(null),Te=(0,Ue.useMemo)(()=>{if(De?.kind==="source")return{"new-file":!0,"new-folder":qe(De.sourceRoot)!=="brain"};let R=Y.length===1?Y[0]:null,X=R??Y[0],B=X?X.type==="folder"?X.uri:nt(X.uri):null;return{"copy-path":!!R,"copy-relative-path":!!R,reembed:!!R&&Ie&&qe(R.uri)!=="brain",rename:!!R,delete:Y.length>0,"new-file":!!R,"new-folder":!!R&&qe(R.uri)!=="brain",cut:Y.length>0,copy:Y.length>0,paste:!!ie&&ie.uris.length>0&&!!B}},[De,Y,ie,Ie]),de=(0,Ue.useCallback)(R=>{if(De?.kind==="source"){(R==="new-file"||R==="new-folder")&&ue({parentUri:De.sourceRoot,kind:R==="new-file"?"file":"folder"});return}let X=Y,B=X.length===1?X[0]:null;if(R==="copy-path"&&B)navigator.clipboard?.writeText(B.uri);else if(R==="copy-relative-path"&&B)navigator.clipboard?.writeText(B.uri.replace(/^[a-z0-9_-]+:\/\//i,""));else if(R==="reembed"&&B){let me=qe(B.uri);me&&ze({source:me,...B.type==="folder"?{folder:B.uri}:{uri:B.uri},label:B.type==="folder"?`${B.name}/`:B.name})}else if(R==="rename"&&B)ce(B.uri);else if(R==="delete")X.length&&Pt({targets:X.map(me=>({uri:me.uri,id:me.id,name:me.name}))});else if(R==="cut"||R==="copy")X.length&&Re({op:R,uris:X.map(me=>me.uri)});else if(R==="paste"){let me=B??X[0];if(me&&ie){let E=me.type==="folder"?me.uri:nt(me.uri);E&&(I({agentId:e,projectId:c??null,targetFolderUri:E,op:ie.op,uris:ie.uris}),ie.op==="cut"&&Re(null))}}else if(R==="new-file"||R==="new-folder"){let me=R==="new-file"?"file":"folder",E=B??X[0];if(!E)return;let ye=E.type==="folder"?E.uri:nt(E.uri);if(!ye)return;!ye.endsWith("://")&&!o.has(ye)&&(l(ye),_.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:ye})),ue({parentUri:ye,kind:me})}},[De,Y,o,l,e,c,ie,I]),ut=(0,Ue.useCallback)(async R=>{let X=oe;if(ue(null),!X)return;let B=(R??"").trim();B&&await C({agentId:e,projectId:c??null,parentUri:X.parentUri,name:B,kind:X.kind})},[oe,C,e,c]),Ft=(0,Ue.useCallback)(()=>ue(null),[]),nn=(0,Ue.useCallback)(async({node:R,newName:X})=>{ce(null);let B=(X??"").trim();!B||B===R.name||await P({agentId:e,projectId:c??null,uri:R.uri,id:R.id,newName:B})},[P,e,c]),$n=(0,Ue.useCallback)(()=>ce(null),[]),ar=(0,Ue.useCallback)(async()=>{if($e){lt(!0);try{await O({agentId:e,projectId:c??null,targets:$e.targets.map(R=>({uri:R.uri,id:R.id}))}),W(new Set)}finally{lt(!1),Pt(null)}}},[$e,O,e,c]),xr=(0,Ue.useCallback)(R=>{if(!re)if(R.key==="F2"){let X=M.size===1?[...M][0]:null;X&&a[X]&&(R.preventDefault(),ce(X))}else if(R.key==="Delete"||R.key==="Backspace"){let X=[...M].map(B=>a[B]).filter(B=>!!B);X.length&&(R.preventDefault(),Pt({targets:X.map(B=>({uri:B.uri,id:B.id,name:B.name}))}))}else R.key==="Escape"&&W(new Set)},[re,M,a]),Kn=(0,Ue.useCallback)(async R=>{let X=o.has(R.key);d(R.key),l(R.key),!X&&await _.getState().ensureFolderLoaded({agentId:e,projectId:c,uri:R.key})},[e,o,c,d,l]),Xn=(0,Ue.useCallback)(R=>{R.uri&&d(nt(R.uri)),u(R)},[d,u]),Yn=(0,Ue.useCallback)(R=>{r.clearFileMark(R)},[r]),xa=(0,Ue.useCallback)(R=>{S(X=>({...X,[R]:!X[R]}))},[]),yr=(0,Ue.useCallback)(async R=>{if(!e)return;let X=_.getState();if(S(B=>B[R]?B:{...B,[R]:!0}),X.loadedFolders?.[R]){let B=qe(R);B&&await X.reconcileSourceFolders({agentId:e,projectId:c,source:B});return}await X.ensureFolderLoaded({agentId:e,projectId:c,uri:R,force:!0})},[e,c]);(0,Ue.useEffect)(()=>{if(!e)return;let R=_.getState(),X=[];for(let B of Pe)$[B.uri_root]&&X.push(B.uri_root);for(let B of o)X.push(B);for(let B of X){if(R.loadedFolders?.[B])continue;let me=R.hydrationState?.[B];me&&me!=="idle"||R.ensureFolderLoaded({agentId:e,projectId:c,uri:B})}},[e,c,Pe,$,o]);let Jn=(0,Ue.useCallback)(async({fromUri:R,id:X,toFolderUri:B})=>{await p({agentId:e,projectId:c??null,fromUri:R,toFolderUri:B,id:X})},[e,c,p]),dn=(0,Ue.useMemo)(()=>Pe.every(R=>!$[R.uri_root]),[Pe,$]),Rn=(0,Ue.useMemo)(()=>ii({grantedFeatures:[...r.grantedFeatures??[]]},{features:["drive.mount"]}),[r.grantedFeatures]),rn=Kb({agentId:e,projectId:c??void 0,enabled:Rn&&dn}),Dr=dn&&Rn&&rn.length>0,Zn=(0,Ue.useCallback)(R=>{Me(R),tt("sources",!0)},[Me,tt]),Fr=(0,Ue.useCallback)(()=>ot(R=>!R),[]),sr=(0,Ue.useRef)(null),_n=(0,Ue.useRef)(mt);_n.current=mt;let Zr=(0,Ue.useCallback)(R=>mM(_n.current[R]?.kind??"node"),[]),br=(0,Ue.useCallback)(R=>_n.current[R]?.key??R,[]),vn=li({count:mt.length,getScrollElement:()=>sr.current,estimateSize:Zr,overscan:8,getItemKey:br});if(t==="git")return(0,Ct.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,Ct.jsx)(M1,{agentId:e})});if(x&&!he&&!Ce)return(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/40 animate-pulse",children:"Loading sources"});let z=A&&!Ce?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-rose-400/30 bg-rose-500/10 px-2 py-1.5 text-[11px] text-rose-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:A}),(0,Ct.jsx)("button",{type:"button",onClick:()=>{e&&v({agentId:e,projectId:c??null})},className:"shrink-0 rounded px-1 font-medium text-rose-200/80 transition-colors hover:text-rose-100",children:"Retry"}),(0,Ct.jsx)("button",{type:"button",onClick:w,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-rose-200/70 transition-colors hover:text-rose-100",children:"\xD7"})]}):null;if(!pe.length&&!Ce&&!he)return z??(0,Ct.jsx)("div",{className:"p-4 text-center text-xs text-white/30",children:"Empty Drive"});let ne=(R,X)=>{let B=R.type==="folder",me=R.storeKey||Va(R);return(0,Ct.jsx)(lw,{node:R,depth:X,agentId:e,projectId:c,isActive:!B&&i===me,isExpanded:B&&o.has(me),badgeCount:B?s[me]:void 0,isDrop:H===me,isSelectedFolder:B&&f===me,mark:Ee[R.uri],agentIndex:xe,fallbackAgent:Dt,uploading:m,packageIconBySlug:kt,onToggleFolder:Kn,onOpenFile:Xn,onClearFileMark:Yn,onSetDropTarget:q,onUploadMany:h,onMoveFileToFolder:Jn,pendingReviewCount:B?en[me]:void 0,isSelected:M.has(R.uri),isCut:ie?.op==="cut"&&ie.uris.includes(R.uri),renaming:re===R.uri,onNodeClick:Ge,onNodeContextMenu:Wt,onRenameCommit:nn,onRenameCancel:$n})};return(0,Ct.jsxs)("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[(0,Ct.jsxs)("div",{ref:sr,tabIndex:0,onKeyDown:xr,onContextMenu:Be,className:"min-h-0 flex-1 overflow-auto pt-0 pb-2 outline-none",children:[z,N&&!Ce?(0,Ct.jsxs)("div",{role:"status",className:"mx-2 mb-1 mt-1 flex items-start gap-2 rounded-md border border-amber-400/30 bg-amber-500/10 px-2 py-1.5 text-[11px] text-amber-100/90",children:[(0,Ct.jsx)("span",{className:"min-w-0 flex-1 break-words",children:N}),(0,Ct.jsx)("button",{type:"button",onClick:L,"aria-label":"Dismiss",className:"shrink-0 rounded px-1 text-amber-200/70 transition-colors hover:text-amber-100",children:"\xD7"})]}):null,Ce?(0,Ct.jsx)(yw,{agentId:e}):null,Ce?null:(0,Ct.jsx)("div",{style:{height:vn.getTotalSize(),width:"100%",position:"relative"},children:vn.getVirtualItems().map(R=>{let X=mt[R.index];if(!X)return null;let B=gM(X.kind);return(0,Ct.jsx)("div",{"data-index":R.index,ref:B?vn.measureElement:void 0,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${R.start}px)`},children:X.kind==="header"?(0,Ct.jsx)(xw,{info:X.info,expanded:X.expanded,onToggle:xa,onContextMenu:tn,onRefresh:yr,hydration:b[X.info.uri_root]??"idle",dirty:!!y[qe(X.info.uri_root)],hideChevron:!0,compact:!0}):X.kind==="empty"?(0,Ct.jsxs)("div",{className:"flex flex-col items-start gap-1.5 px-4 py-2",onContextMenu:me=>tn(X.sourceRoot,me),children:[(0,Ct.jsxs)("span",{className:"text-xs text-white/35",children:["No files for ",qe(X.sourceRoot)]}),(0,Ct.jsx)(E1.SkillLauncher,{variant:"label",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/upload.sh","scripts/modify.sh"],label:"Populate this source with the agent"})]}):X.kind==="creating"?(0,Ct.jsx)(bM,{kind:X.createKind,depth:X.depth,onCommit:ut,onCancel:Ft}):ne(X.node,X.depth)},R.key)})}),De?(0,Ct.jsx)(cw,{x:De.x,y:De.y,variant:De.kind==="source"?"source":"node",enabled:Te,onAction:de,onClose:()=>Ye(null)}):null,_e?(0,Ct.jsx)($l,{agentId:e,...c?{projectId:c}:{},target:_e,onClose:()=>ze(null)}):null,$e?(0,Ct.jsx)(hw,{names:$e.targets.map(R=>R.name),busy:Xe,onCancel:()=>{Xe||Pt(null)},onConfirm:ar}):null]}),Dr&&!Ce?(0,Ct.jsx)(ew,{suggestions:rn,expanded:Nt,onToggleExpanded:Fr,onPick:Zn,overlay:Nt}):null]})}function bM({kind:n,depth:e,onCommit:t,onCancel:r}){let a=(0,Ue.useRef)(!1),s=n==="folder"?Cr:Ls;return(0,Ct.jsxs)("div",{className:"flex h-7 items-center gap-1.5 px-2",style:{paddingLeft:`${e*12+8}px`},children:[(0,Ct.jsx)("span",{className:"w-3.5 h-3.5 inline-block shrink-0"}),(0,Ct.jsx)(s,{className:"w-4 h-4 shrink-0 text-sky-300/80"}),(0,Ct.jsx)("input",{autoFocus:!0,spellCheck:!1,placeholder:n==="folder"?"Folder name":"File name",onClick:o=>o.stopPropagation(),onMouseDown:o=>o.stopPropagation(),onKeyDown:o=>{o.stopPropagation(),o.key==="Enter"?a.current||(a.current=!0,t(o.currentTarget.value)):o.key==="Escape"&&(a.current||(a.current=!0,r()))},onBlur:o=>{if(a.current)return;a.current=!0;let i=o.currentTarget.value.trim();i?t(i):r()},className:"min-w-0 flex-1 rounded border border-sky-400/60 bg-black/50 px-1 py-0 text-xs text-white outline-none placeholder:text-white/30"})]})}var wt=j(Ve(),1);function O1(n){if(!n)return{lines:new Map,deletedBefore:new Set};let e=new Map,t=new Set,r=0,a=!1,s=0,o=0,i=()=>{s>0&&o===0&&t.add(r),s=0,o=0};for(let l of n.split(`
|
|
32
|
+
`)){if(l.startsWith("@@")){i();let u=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(l);r=u?parseInt(u[1],10):0,a=r>0;continue}a&&(l.startsWith("+")&&!l.startsWith("+++")?(e.set(r,s>0?"modified":"added"),o++,r++):l.startsWith("-")&&!l.startsWith("---")?s++:(i(),l.startsWith(" ")&&r++))}return i(),{lines:e,deletedBefore:t}}function dd(n){return n.lines.size===0&&n.deletedBefore.size===0}var Gn=j(Ve(),1),_1=j(Qa(),1);var su=j(le(),1);function wp({sourceType:n,className:e}){return n==="blob"?(0,su.jsx)("span",{title:"Blob + Vector",children:(0,su.jsx)(Un,{className:V("w-3 h-3",e)})}):(0,su.jsx)("span",{title:"Vector only",children:(0,su.jsx)(ir,{className:V("w-3 h-3",e)})})}var Wr=j(le(),1);function vp({node:n,active:e,mark:t,isDirty:r,hasPendingReview:a,preview:s,pinned:o,onTogglePin:i}){let l=_(h=>h.setActiveFile),u=_(h=>h.closeFile),c=_(h=>h.activeAgentId),d=fn(),f=n.status==="deleted";return(0,Wr.jsxs)("div",{className:V("group flex items-center gap-1.5 px-3 py-2 text-xs cursor-pointer min-w-[120px] max-w-[240px] rounded-lg",e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>{l(n.storeKey||n.path),c&&t&&d.clearFileMark({agentId:c,path:n.path})},onDoubleClick:()=>i?.(),title:n.path,children:[(0,Wr.jsx)(wp,{sourceType:n.sourceType,className:V("shrink-0",n.sourceType==="blob"?"text-sky-400/60":"text-violet-400/60")}),(0,Wr.jsxs)("span",{className:V("truncate flex-1",s&&"italic",f&&"line-through text-white/45"),children:[n.name,r?(0,Wr.jsx)("span",{className:"ml-1",style:{color:"var(--warning)"},children:"*"}):null]}),a?(0,Wr.jsx)("span",{className:"inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold bg-amber-500/15 text-amber-200",children:"REVIEW"}):t?(0,Wr.jsx)("span",{className:V("inline-flex items-center rounded-full px-1.5 py-0.5 text-[9px] font-semibold",t==="new"?"bg-emerald-500/15 text-emerald-200":"bg-blue-500/15 text-blue-200"),children:t==="new"?"NEW":"MOD"}):null,o?(0,Wr.jsx)("button",{onClick:h=>{h.stopPropagation(),i?.()},className:"p-0.5 rounded text-amber-300/80 hover:bg-white/10",title:"Unpin tab",children:(0,Wr.jsx)(oo,{className:"w-3 h-3 fill-current"})}):(0,Wr.jsx)("button",{onClick:h=>{h.stopPropagation(),u(n.storeKey||n.path)},className:V("opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10"),title:"Close (double-click tab to pin)",children:(0,Wr.jsx)(Bt,{className:"w-3 h-3"})})]})}var Ln=j(le(),1),fd="data-tab-scroller",B1="data-tab-active";function wM(n,e){return e.left<n.left?e.left-n.left:e.right>n.right?Math.min(e.right-n.right,e.left-n.left):0}function vM(n,e){return e.scrollWidth<=e.clientWidth||Math.abs(n.deltaX)>=Math.abs(n.deltaY)?0:n.deltaY}function H1(){let n=_(y=>y.openFiles),e=_(y=>y.activeFile),t=_(y=>y.files),r=_(y=>y.tabMeta),a=_(y=>y.fileContentByPath),s=_(y=>y.fileBaseContentByPath),o=_(y=>y.filePrevByPath),i=_(y=>y.activeAgentId),l=_(y=>y.reorderOpenFiles),u=_(y=>y.toggleTabPin),d=fn().useFileMarks(i??void 0)||{},[f,h]=(0,Gn.useState)(null),[p,m]=(0,Gn.useState)(null),g=(0,Gn.useRef)(null),x=n.length>0,b=(0,Gn.useCallback)(()=>{let y=g.current,N=y?.closest(`[${fd}]`),L=y?.querySelector(`[${B1}="true"]`);if(!N||!L)return;let A=wM(N.getBoundingClientRect(),L.getBoundingClientRect());A!==0&&(N.scrollLeft+=A)},[]);return(0,Gn.useLayoutEffect)(()=>{b()},[e,n,b]),(0,Gn.useEffect)(()=>{let y=g.current?.closest(`[${fd}]`);if(!y)return;let N=A=>{let w=vM(A,y);w!==0&&(A.preventDefault(),y.scrollLeft+=w)};y.addEventListener("wheel",N,{passive:!1});let L=typeof ResizeObserver<"u"?new ResizeObserver(()=>{y.clientWidth>0&&b()}):null;return L?.observe(y),()=>{y.removeEventListener("wheel",N),L?.disconnect()}},[x,b]),n.length===0?null:(0,Ln.jsx)("div",{ref:g,className:"flex items-center",children:n.map(y=>{let N=t[y],L=r[y],A=N?.uri??y,w=N?.name??L?.name??yt(y),v=N?.status??L?.status,T=a[y]??"",P=s[y],O=typeof P=="string"&&P!==T,I=!!o[y]&&v==="pending_review";return(0,Ln.jsx)("div",{draggable:!0,[B1]:e===y?"true":void 0,onDragStart:H=>{h(y),H.dataTransfer.effectAllowed="move";try{H.dataTransfer.setData("text/plain",y)}catch{}},onDragOver:H=>{H.preventDefault(),H.dataTransfer.dropEffect="move",p!==y&&m(y)},onDrop:H=>{H.preventDefault(),f&&f!==y&&l(f,y),h(null),m(null)},onDragEnd:()=>{h(null),m(null)},className:V("shrink-0 rounded-lg",p===y&&f&&f!==y?"ring-1 ring-violet-400/50":"",f===y?"opacity-50":""),children:(0,Ln.jsx)(vp,{node:{storeKey:N?.storeKey??y,path:A,name:w,status:v,sourceAgentId:N?.sourceAgentId??L?.sourceAgentId,sourceType:N?.sourceType},active:e===y,mark:d[A]?.kind,isDirty:O,hasPendingReview:I,preview:!!L?.preview,pinned:!!L?.pinned,onTogglePin:()=>u(y)})},y)})})}function U1(){let n=_(p=>p.openFiles),e=_(p=>p.activeFile),t=_(p=>p.closeAllFiles),r=_(p=>p.closeSavedFiles),a=_(p=>p.closeOtherFiles),s=_(p=>p.previewEditorsEnabled),o=_(p=>p.setPreviewEditorsEnabled),[i,l]=(0,Gn.useState)(!1),[u,c]=(0,Gn.useState)(null),d=(0,Gn.useRef)(null),f=(0,Gn.useRef)(null);return(0,Gn.useEffect)(()=>{if(!i)return;let p=x=>{let b=x.target;d.current?.contains(b)||f.current?.contains(b)||l(!1)},m=x=>{x.key==="Escape"&&l(!1)},g=()=>l(!1);return document.addEventListener("mousedown",p),document.addEventListener("keydown",m),window.addEventListener("resize",g),window.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",m),window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0)}},[i]),n.length===0?null:(0,Ln.jsxs)("div",{className:"flex shrink-0 items-center border-l border-white/[0.05]",children:[(0,Ln.jsx)("button",{ref:d,type:"button",onClick:()=>{if(i){l(!1);return}let p=d.current?.getBoundingClientRect();p&&c({top:p.bottom+4,right:Math.max(4,window.innerWidth-p.right)}),l(!0)},className:V("flex items-center justify-center w-6 h-6 mx-1 rounded-md transition",i?"bg-white/10 text-white/80":"text-white/40 hover:bg-white/5 hover:text-white/70"),title:"Editor actions","aria-haspopup":"menu","aria-expanded":i,children:(0,Ln.jsx)(ws,{className:"w-4 h-4"})}),i&&u?(0,_1.createPortal)((0,Ln.jsxs)("div",{ref:f,role:"menu",style:{position:"fixed",top:u.top,right:u.right},className:"z-[1000] min-w-[190px] rounded-lg border border-white/10 bg-[#14141b] py-1 text-[11px] text-white/80 shadow-[0_18px_46px_-20px_rgba(0,0,0,0.8)]",children:[(0,Ln.jsx)(kp,{label:"Close All",onClick:()=>{t(),l(!1)}}),(0,Ln.jsx)(kp,{label:"Close Saved",onClick:()=>{r(),l(!1)}}),(0,Ln.jsx)(kp,{label:"Close Others",disabled:!e,onClick:()=>{e&&a(e),l(!1)}}),(0,Ln.jsx)("div",{className:"my-1 h-px bg-white/[0.06]"}),(0,Ln.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":s,onClick:()=>o(!s),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-white/[0.06]",children:[(0,Ln.jsx)("span",{className:"w-3.5 shrink-0 text-emerald-300",children:s?(0,Ln.jsx)(Mn,{className:"w-3.5 h-3.5"}):null}),(0,Ln.jsx)("span",{children:"Enable Preview Editors"})]})]}),document.body):null]})}function kp({label:n,onClick:e,disabled:t}){return(0,Ln.jsx)("button",{type:"button",role:"menuitem",disabled:t,onClick:e,className:"flex w-full items-center px-3 py-1.5 text-left hover:bg-white/[0.06] disabled:opacity-40 disabled:cursor-not-allowed",children:n})}var vo=j(Ve(),1);var ht=j(le(),1);function kM(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function Sp(n){if(!n)return null;try{return new Date(n).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch{return n}}function Cp({node:n,className:e,hideVersionDiff:t=!1}){let{tags:r,category:a,createdAt:s,updatedAt:o,metadata:i,sourceAgentId:l,version:u,readSource:c}=n,d=n.uri?qe(n.uri):void 0,h=fn().useAgents(),p=(0,vo.useMemo)(()=>Ts(h),[h]),m=(0,vo.useMemo)(()=>l?p.byId.get(l)??null:null,[p,l]),g=m?.name||m?.slug,x=ci(m?.id,p);if(!Lp(n))return null;let y=i&&typeof i.mimeType=="string"?i.mimeType:void 0,N=i&&typeof i.size=="number"?i.size:void 0,L=ql(n),A=u?.sync,w=ho(u?.changedAt),v=Ph(u?.changedAt),T=Ph(A?.syncedAt);return(0,ht.jsxs)("div",{className:V("flex flex-wrap items-center gap-1.5 px-2 py-2 text-[10px]",e),style:{background:"linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%)",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,ht.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",L.highlightTone,"border-white/[0.07]",L.tone),children:[(0,ht.jsx)(L.icon,{className:V("w-3 h-3",L.iconTone)}),L.label]}),d?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/60",children:[(0,ht.jsx)(Ya,{className:"w-3 h-3 text-white/35"}),(0,ht.jsx)("span",{className:"uppercase font-semibold tracking-wide",children:d})]}):null,n.os_uri?(0,ht.jsx)(SM,{value:n.os_uri}):null,g?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",title:`Created by ${g}`,children:[(0,ht.jsx)(gl,{className:"w-3 h-3 text-white/35"}),(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide",style:{color:x||"var(--icon-muted)",backgroundColor:x?`${x}20`:"rgba(255,255,255,0.04)"},children:[(0,ht.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x||"var(--icon-muted)"}}),g]})]}):null,a?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,ht.jsx)(_r,{className:"w-3 h-3 text-white/35"}),a]}):null,r&&r.length>0?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/55",children:[(0,ht.jsx)(Hl,{className:"w-3 h-3 text-white/35"}),r.map(P=>(0,ht.jsx)("span",{className:"inline-flex rounded-full px-1.5 py-0.5 text-[9px] font-medium bg-white/[0.06] text-white/70",children:P},P))]}):null,y?(0,ht.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:y}):null,N?(0,ht.jsx)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:kM(N)}):null,s?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:[(0,ht.jsx)(va,{className:"w-3 h-3"}),Sp(s)]}):null,o&&o!==s?(0,ht.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/40",children:[(0,ht.jsx)(Ot,{className:"w-2.5 h-2.5"}),Sp(o)]}):null,u?.changedAt?(0,ht.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,ht.jsx)(va,{className:V("w-3 h-3",w.iconClassName)}),"changed ",v?`${v} ago`:Sp(u.changedAt)]}):null,!t&&u?.diff?(0,ht.jsxs)("span",{className:V("inline-flex items-center gap-1 rounded-full border px-2 py-1",w.pillClassName),children:[(0,ht.jsx)(lr,{className:V("w-3 h-3",w.iconClassName)}),(0,ht.jsxs)("span",{className:"text-emerald-200/95",children:["+",u.diff.added]}),(0,ht.jsx)("span",{className:"text-white/25",children:"/"}),(0,ht.jsxs)("span",{className:"text-rose-200/95",children:["-",u.diff.removed]})]}):null,T?(0,ht.jsxs)("span",{className:"rounded-full border border-white/[0.06] bg-white/[0.02] px-2 py-1 text-white/38",children:["synced ",T," ago"]}):null]})}function SM({value:n}){let[e,t]=(0,vo.useState)(!1),r=(0,vo.useCallback)(()=>{navigator.clipboard.writeText(n).then(()=>{t(!0),setTimeout(()=>t(!1),1500)}).catch(()=>{})},[n]),a=n.length>60?"..."+n.slice(-57):n;return(0,ht.jsxs)("button",{type:"button",onClick:r,title:n,className:"inline-flex items-center gap-1 rounded-full border border-white/[0.06] bg-white/[0.03] px-2 py-1 text-white/45 hover:text-white/70 hover:bg-white/[0.06] transition-colors cursor-pointer",children:[e?(0,ht.jsx)(sa,{className:"w-3 h-3 text-emerald-300/80"}):(0,ht.jsx)(Un,{className:"w-3 h-3 text-white/35"}),(0,ht.jsx)("span",{className:"font-mono truncate max-w-[280px]",children:a})]})}function Lp(n){let{tags:e,category:t,createdAt:r,updatedAt:a,metadata:s,sourceAgentId:o,version:i}=n,l=n.uri?qe(n.uri):void 0;return!!o||!!e?.length||!!t||!!l||!!n.os_uri||!!r||!!a||!!i||!!(s&&Object.keys(s).length>0)}var wf=j(Ve(),1);var Ap=[],j1=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?j1:Ap).push(t=t+n[e])})();function CM(n){if(n<768)return!1;for(let e=0,t=Ap.length;;){let r=e+t>>1;if(n<Ap[r])t=r;else if(n>=j1[r])e=r+1;else return!0;if(e==t)return!1}}function G1(n){return n>=127462&&n<=127487}var z1=8205;function q1(n,e,t=!0,r=!0){return(t?V1:LM)(n,e,r)}function V1(n,e,t){if(e==n.length)return e;e&&$1(n.charCodeAt(e))&&K1(n.charCodeAt(e-1))&&e--;let r=Ip(n,e);for(e+=W1(r);e<n.length;){let a=Ip(n,e);if(r==z1||a==z1||t&&CM(a))e+=W1(a),r=a;else if(G1(a)){let s=0,o=e-2;for(;o>=0&&G1(Ip(n,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function LM(n,e,t){for(;e>1;){let r=V1(n,e-2,t);if(r<e)return r;e--}return 0}function Ip(n,e){let t=n.charCodeAt(e);if(!K1(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return $1(r)?(t-55296<<10)+(r-56320)+65536:t}function $1(n){return n>=56320&&n<57344}function K1(n){return n>=55296&&n<56320}function W1(n){return n<65536?1:2}var it=class n{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,r){[e,t]=Ai(this,e,t);let a=[];return this.decompose(0,e,a,2),r.length&&r.decompose(0,r.length,a,3),this.decompose(t,this.length,a,1),Ci.from(a,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Ai(this,e,t);let r=[];return this.decompose(e,t,r,0),Ci.from(r,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),a=new Lo(this),s=new Lo(e);for(let o=t,i=t;;){if(a.next(o),s.next(o),o=0,a.lineBreak!=s.lineBreak||a.done!=s.done||a.value!=s.value)return!1;if(i+=a.value.length,a.done||i>=r)return!0}}iter(e=1){return new Lo(this,e)}iterRange(e,t=this.length){return new xd(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let a=this.line(e).from;r=this.iterRange(a,Math.max(a,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new yd(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?n.empty:e.length<=32?new Pr(e):Ci.from(Pr.split(e,[]))}},Pr=class n extends it{constructor(e,t=IM(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,a){for(let s=0;;s++){let o=this.text[s],i=a+o.length;if((t?r:i)>=e)return new Np(a,i,r,o);a=i+1,r++}}decompose(e,t,r,a){let s=e<=0&&t>=this.length?this:new n(X1(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(a&1){let o=r.pop(),i=gd(s.text,o.text.slice(),0,s.length);if(i.length<=32)r.push(new n(i,o.length+s.length));else{let l=i.length>>1;r.push(new n(i.slice(0,l)),new n(i.slice(l)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof n))return super.replace(e,t,r);[e,t]=Ai(this,e,t);let a=gd(this.text,gd(r.text,X1(this.text,0,e)),t),s=this.length+r.length-(t-e);return a.length<=32?new n(a,s):Ci.from(n.split(a,[]),s)}sliceString(e,t=this.length,r=`
|
|
33
|
+
`){[e,t]=Ai(this,e,t);let a="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let i=this.text[o],l=s+i.length;s>e&&o&&(a+=r),e<l&&t>s&&(a+=i.slice(Math.max(0,e-s),t-s)),s=l+1}return a}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let r=[],a=-1;for(let s of e)r.push(s),a+=s.length+1,r.length==32&&(t.push(new n(r,a)),r=[],a=-1);return a>-1&&t.push(new n(r,a)),t}},Ci=class n extends it{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,t,r,a){for(let s=0;;s++){let o=this.children[s],i=a+o.length,l=r+o.lines-1;if((t?l:i)>=e)return o.lineInner(e,t,r,a);a=i+1,r=l+1}}decompose(e,t,r,a){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let i=this.children[s],l=o+i.length;if(e<=l&&t>=o){let u=a&((o<=e?1:0)|(l>=t?2:0));o>=e&&l<=t&&!u?r.push(i):i.decompose(e-o,t-o,r,u)}o=l+1}}replace(e,t,r){if([e,t]=Ai(this,e,t),r.lines<this.lines)for(let a=0,s=0;a<this.children.length;a++){let o=this.children[a],i=s+o.length;if(e>=s&&t<=i){let l=o.replace(e-s,t-s,r),u=this.lines-o.lines+l.lines;if(l.lines<u>>4&&l.lines>u>>6){let c=this.children.slice();return c[a]=l,new n(c,this.length-(t-e)+r.length)}return super.replace(s,i,l)}s=i+1}return super.replace(e,t,r)}sliceString(e,t=this.length,r=`
|
|
34
|
+
`){[e,t]=Ai(this,e,t);let a="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let i=this.children[s],l=o+i.length;o>e&&s&&(a+=r),e<l&&t>o&&(a+=i.sliceString(e-o,t-o,r)),o=l+1}return a}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof n))return 0;let r=0,[a,s,o,i]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;a+=t,s+=t){if(a==o||s==i)return r;let l=this.children[a],u=e.children[s];if(l!=u)return r+l.scanIdentical(u,t);r+=l.length+1}}static from(e,t=e.reduce((r,a)=>r+a.length+1,-1)){let r=0;for(let h of e)r+=h.lines;if(r<32){let h=[];for(let p of e)p.flatten(h);return new Pr(h,t)}let a=Math.max(32,r>>5),s=a<<1,o=a>>1,i=[],l=0,u=-1,c=[];function d(h){let p;if(h.lines>s&&h instanceof n)for(let m of h.children)d(m);else h.lines>o&&(l>o||!l)?(f(),i.push(h)):h instanceof Pr&&l&&(p=c[c.length-1])instanceof Pr&&h.lines+p.lines<=32?(l+=h.lines,u+=h.length+1,c[c.length-1]=new Pr(p.text.concat(h.text),p.length+1+h.length)):(l+h.lines>a&&f(),l+=h.lines,u+=h.length+1,c.push(h))}function f(){l!=0&&(i.push(c.length==1?c[0]:n.from(c,u)),u=-1,l=c.length=0)}for(let h of e)d(h);return f(),i.length==1?i[0]:new n(i,t)}};it.empty=new Pr([""],0);function IM(n){let e=-1;for(let t of n)e+=t.length+1;return e}function gd(n,e,t=0,r=1e9){for(let a=0,s=0,o=!0;s<n.length&&a<=r;s++){let i=n[s],l=a+i.length;l>=t&&(l>r&&(i=i.slice(0,r-a)),a<t&&(i=i.slice(t-a)),o?(e[e.length-1]+=i,o=!1):e.push(i)),a=l+1}return e}function X1(n,e,t){return gd(n,[""],e,t)}var Lo=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof Pr?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,a=this.nodes[r],s=this.offsets[r],o=s>>1,i=a instanceof Pr?a.text.length:a.children.length;if(o==(t>0?i:0)){if(r==0)return this.done=!0,this.value="",this;t>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[r]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
35
|
+
`,this;e--}else if(a instanceof Pr){let l=a.text[o+(t<0?-1:0)];if(this.offsets[r]+=t,l.length>Math.max(0,e))return this.value=e==0?l:t>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=a.children[o+(t<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(t>0?1:(l instanceof Pr?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},xd=class{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Lo(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:a}=this.cursor.next(e);return this.pos+=(a.length+e)*t,this.value=a.length<=r?a:t<0?a.slice(a.length-r):a.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}},yd=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:a}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=a,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<"u"&&(it.prototype[Symbol.iterator]=function(){return this.iter()},Lo.prototype[Symbol.iterator]=xd.prototype[Symbol.iterator]=yd.prototype[Symbol.iterator]=function(){return this});var Np=class{constructor(e,t,r,a){this.from=e,this.to=t,this.number=r,this.text=a}get length(){return this.to-this.from}};function Ai(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function An(n,e,t=!0,r=!0){return q1(n,e,t,r)}function AM(n){return n>=56320&&n<57344}function PM(n){return n>=55296&&n<56320}function ek(n,e){let t=n.charCodeAt(e);if(!PM(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return AM(r)?(t-55296<<10)+(r-56320)+65536:t}function tk(n){return n<65536?1:2}var Rp=/\r\n?|\n/,dr=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(dr||(dr={})),as=class n{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,a=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(r,a,s),a+=s):a+=o,r+=s}}iterChangedRanges(e,t=!1){Mp(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];a<0?e.push(r,a):e.push(a,r)}return new n(e)}composeDesc(e){return this.empty?e:e.empty?this:nk(this,e)}mapDesc(e,t=!1){return e.empty?this:Tp(this,e,t)}mapPos(e,t=-1,r=dr.Simple){let a=0,s=0;for(let o=0;o<this.sections.length;){let i=this.sections[o++],l=this.sections[o++],u=a+i;if(l<0){if(u>e)return s+(e-a);s+=i}else{if(r!=dr.Simple&&u>=e&&(r==dr.TrackDel&&a<e&&u>e||r==dr.TrackBefore&&a<e||r==dr.TrackAfter&&u>e))return null;if(u>e||u==e&&t<0&&!i)return e==a||t<0?s:s+l;s+=l}a=u}if(e>a)throw new RangeError(`Position ${e} is out of range for changeset of length ${a}`);return s}touchesRange(e,t=e){for(let r=0,a=0;r<this.sections.length&&a<=t;){let s=this.sections[r++],o=this.sections[r++],i=a+s;if(o>=0&&a<=t&&i>=e)return a<e&&i>t?"cover":!0;a=i}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],a=this.sections[t++];e+=(e?" ":"")+r+(a>=0?":"+a:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new n(e)}static create(e){return new n(e)}},Pn=class n extends as{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Mp(this,(t,r,a,s,o)=>e=e.replace(a,a+(r-t),o),!1),e}mapDesc(e,t=!1){return Tp(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let a=0,s=0;a<t.length;a+=2){let o=t[a],i=t[a+1];if(i>=0){t[a]=i,t[a+1]=o;let l=a>>1;for(;r.length<l;)r.push(it.empty);r.push(o?e.slice(s,s+o):it.empty)}s+=o}return new n(t,r)}compose(e){return this.empty?e:e.empty?this:nk(this,e,!0)}map(e,t=!1){return e.empty?this:Tp(this,e,t,!0)}iterChanges(e,t=!1){Mp(this,e,t)}get desc(){return as.create(this.sections)}filter(e){let t=[],r=[],a=[],s=new Io(this);e:for(let o=0,i=0;;){let l=o==e.length?1e9:e[o++];for(;i<l||i==l&&s.len==0;){if(s.done)break e;let c=Math.min(s.len,l-i);zn(a,c,-1);let d=s.ins==-1?-1:s.off==0?s.ins:0;zn(t,c,d),d>0&&Us(r,t,s.text),s.forward(c),i+=c}let u=e[o++];for(;i<u;){if(s.done)break e;let c=Math.min(s.len,u-i);zn(t,c,-1),zn(a,c,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(c),i+=c}}return{changes:new n(t,r),filtered:as.create(a)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],a=this.sections[t+1];a<0?e.push(r):a==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let a=[],s=[],o=0,i=null;function l(c=!1){if(!c&&!a.length)return;o<t&&zn(a,t-o,-1);let d=new n(a,s);i=i?i.compose(d.map(i)):d,a=[],s=[],o=0}function u(c){if(Array.isArray(c))for(let d of c)u(d);else if(c instanceof n){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);l(),i=i?i.compose(c.map(i)):c}else{let{from:d,to:f=d,insert:h}=c;if(d>f||d<0||f>t)throw new RangeError(`Invalid change range ${d} to ${f} (in doc of length ${t})`);let p=h?typeof h=="string"?it.of(h.split(r||Rp)):h:it.empty,m=p.length;if(d==f&&m==0)return;d<o&&l(),d>o&&zn(a,d-o,-1),zn(a,f-d,m),Us(s,a,p),o=f}}return u(e),l(!i),i}static empty(e){return new n(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let a=0;a<e.length;a++){let s=e[a];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,i)=>i&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<a;)r.push(it.empty);r[a]=it.of(s.slice(1)),t.push(s[0],r[a].length)}}}return new n(t,r)}static createSet(e,t){return new n(e,t)}};function zn(n,e,t,r=!1){if(e==0&&t<=0)return;let a=n.length-2;a>=0&&t<=0&&t==n[a+1]?n[a]+=e:a>=0&&e==0&&n[a]==0?n[a+1]+=t:r?(n[a]+=e,n[a+1]+=t):n.push(e,t)}function Us(n,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<r;)n.push(it.empty);n.push(t)}}function Mp(n,e,t){let r=n.inserted;for(let a=0,s=0,o=0;o<n.sections.length;){let i=n.sections[o++],l=n.sections[o++];if(l<0)a+=i,s+=i;else{let u=a,c=s,d=it.empty;for(;u+=i,c+=l,l&&r&&(d=d.append(r[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)i=n.sections[o++],l=n.sections[o++];e(a,u,s,c,d),a=u,s=c}}}function Tp(n,e,t,r=!1){let a=[],s=r?[]:null,o=new Io(n),i=new Io(e);for(let l=-1;;){if(o.done&&i.len||i.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&i.ins==-1){let u=Math.min(o.len,i.len);zn(a,u,-1),o.forward(u),i.forward(u)}else if(i.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(i.len<o.len||i.len==o.len&&!t))){let u=i.len;for(zn(a,i.ins,-1);u;){let c=Math.min(o.len,u);o.ins>=0&&l<o.i&&o.len<=c&&(zn(a,0,o.ins),s&&Us(s,a,o.text),l=o.i),o.forward(c),u-=c}i.next()}else if(o.ins>=0){let u=0,c=o.len;for(;c;)if(i.ins==-1){let d=Math.min(c,i.len);u+=d,c-=d,i.forward(d)}else if(i.ins==0&&i.len<c)c-=i.len,i.next();else break;zn(a,u,l<o.i?o.ins:0),s&&l<o.i&&Us(s,a,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&i.done)return s?Pn.createSet(a,s):as.create(a);throw new Error("Mismatched change set lengths")}}}function nk(n,e,t=!1){let r=[],a=t?[]:null,s=new Io(n),o=new Io(e);for(let i=!1;;){if(s.done&&o.done)return a?Pn.createSet(r,a):as.create(r);if(s.ins==0)zn(r,s.len,0,i),s.next();else if(o.len==0&&!o.done)zn(r,0,o.ins,i),a&&Us(a,r,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(s.len2,o.len),u=r.length;if(s.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;zn(r,l,c,i),a&&c&&Us(a,r,o.text)}else o.ins==-1?(zn(r,s.off?0:s.len,l,i),a&&Us(a,r,s.textBit(l))):(zn(r,s.off?0:s.len,o.off?0:o.ins,i),a&&!o.off&&Us(a,r,o.text));i=(s.ins>l||o.ins>=0&&o.len>l)&&(i||r.length>u),s.forward2(l),o.forward(l)}}}}var Io=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?it.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?it.empty:t[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},ko=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.flags=r,this.goalColumn=a}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,t=-1){let r,a;return this.empty?r=a=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),a=e.mapPos(this.to,-1)),r==this.from&&a==this.to?this:new n(r,a,this.flags,this.goalColumn)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return se.range(e,t,void 0,void 0,r);let a=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return se.range(this.anchor,a,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return se.range(e.anchor,e.head)}static create(e,t,r,a){return new n(e,t,r,a)}},se=class n{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:n.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new n([this.main],0)}addRange(e,t=!0){return n.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,n.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new n(e.ranges.map(t=>ko.fromJSON(t)),e.main)}static single(e,t=e){return new n([n.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,a=0;a<e.length;a++){let s=e[a];if(s.empty?s.from<=r:s.from<r)return n.normalized(e.slice(),t);r=s.to}return new n(e,t)}static cursor(e,t=0,r,a){return ko.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r)),a)}static range(e,t,r,a,s){let o=a==null?7:Math.min(6,a);return!s&&e!=t&&(s=t<e?1:-1),s&&(o|=s<0?8:16),t<e?ko.create(t,e,o|32,r):ko.create(e,t,o,r)}static undirectionalRange(e,t){return ko.create(e,t,64,void 0)}static normalized(e,t=0){let r=e[t];e.sort((a,s)=>a.from-s.from),t=e.indexOf(r);for(let a=1;a<e.length;a++){let s=e[a],o=e[a-1];if(s.empty?s.from<=o.to:s.from<o.to){let i=o.from,l=Math.max(s.to,o.to);a<=t&&t--,e.splice(--a,2,s.anchor>s.head?n.range(l,i):n.range(i,l))}}return new n(e,t)}};function rk(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}var zp=0,Ne=class n{constructor(e,t,r,a,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=a,this.id=zp++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new n(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:Wp),!!e.static,e.enables)}of(e){return new Li([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Li(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Li(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}};function Wp(n,e){return n==e||n.length==e.length&&n.every((t,r)=>t===e[r])}var Li=class{constructor(e,t,r,a){this.dependencies=e,this.facet=t,this.type=r,this.value=a,this.id=zp++}dynamicSlot(e){var t;let r=this.value,a=this.facet.compareInput,s=this.id,o=e[s]>>1,i=this.type==2,l=!1,u=!1,c=[];for(let d of this.dependencies)d=="doc"?l=!0:d=="selection"?u=!0:(((t=e[d.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[d.id]);return{create(d){return d.values[o]=r(d),1},update(d,f){if(l&&f.docChanged||u&&(f.docChanged||f.selection)||Dp(d,c)){let h=r(d);if(i?!Y1(h,d.values[o],a):!a(h,d.values[o]))return d.values[o]=h,1}return 0},reconfigure:(d,f)=>{let h,p=f.config.address[s];if(p!=null){let m=vd(f,p);if(this.dependencies.every(g=>g instanceof Ne?f.facet(g)===d.facet(g):g instanceof bn?f.field(g,!1)==d.field(g,!1):!0)||(i?Y1(h=r(d),m,a):a(h=r(d),m)))return d.values[o]=m,0}else h=r(d);return d.values[o]=h,1}}}get extension(){return this}};function Y1(n,e,t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!t(n[r],e[r]))return!1;return!0}function Dp(n,e){let t=!1;for(let r of e)iu(n,r)&1&&(t=!0);return t}function NM(n,e,t){let r=t.map(l=>n[l.id]),a=t.map(l=>l.type),s=r.filter(l=>!(l&1)),o=n[e.id]>>1;function i(l){let u=[];for(let c=0;c<r.length;c++){let d=vd(l,r[c]);if(a[c]==2)for(let f of d)u.push(f);else u.push(d)}return e.combine(u)}return{create(l){for(let u of r)iu(l,u);return l.values[o]=i(l),1},update(l,u){if(!Dp(l,s))return 0;let c=i(l);return e.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,u){let c=Dp(l,r),d=u.config.facets[e.id],f=u.facet(e);if(d&&!c&&Wp(t,d))return l.values[o]=f,0;let h=i(l);return e.compare(h,f)?(l.values[o]=f,0):(l.values[o]=h,1)}}}var hd=Ne.define({static:!0}),bn=class n{constructor(e,t,r,a,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=a,this.spec=s,this.provides=void 0}static define(e){let t=new n(zp++,e.create,e.update,e.compare||((r,a)=>r===a),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(hd).find(r=>r.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,a)=>{let s=r.values[t],o=this.updateF(s,a);return this.compareF(s,o)?0:(r.values[t]=o,1)},reconfigure:(r,a)=>{let s=r.facet(hd),o=a.facet(hd),i;return(i=s.find(l=>l.field==this))&&i!=o.find(l=>l.field==this)?(r.values[t]=i.create(r),1):a.config.address[this.id]!=null?(r.values[t]=a.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,hd.of({field:this,create:e})]}get extension(){return this}},So={lowest:4,low:3,default:2,high:1,highest:0};function ou(n){return e=>new bd(e,n)}var Ta={highest:ou(So.highest),high:ou(So.high),default:ou(So.default),low:ou(So.low),lowest:ou(So.lowest)},bd=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},jr=class n{of(e){return new lu(this,e)}reconfigure(e){return n.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}},lu=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},wd=class n{constructor(e,t,r,a,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=a,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,r){let a=[],s=Object.create(null),o=new Map;for(let f of RM(e,t,o))f instanceof bn?a.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let i=Object.create(null),l=[],u=[];for(let f of a)i[f.id]=u.length<<1,u.push(h=>f.slot(h));let c=r?.config.facets;for(let f in s){let h=s[f],p=h[0].facet,m=c&&c[f]||[];if(h.every(g=>g.type==0))if(i[p.id]=l.length<<1|1,Wp(m,h))l.push(r.facet(p));else{let g=p.combine(h.map(x=>x.value));l.push(r&&p.compare(g,r.facet(p))?r.facet(p):g)}else{for(let g of h)g.type==0?(i[g.id]=l.length<<1|1,l.push(g.value)):(i[g.id]=u.length<<1,u.push(x=>g.dynamicSlot(x)));i[p.id]=u.length<<1,u.push(g=>NM(g,p,h))}}let d=u.map(f=>f(i));return new n(e,o,d,i,l,s)}};function RM(n,e,t){let r=[[],[],[],[],[]],a=new Map;function s(o,i){let l=a.get(o);if(l!=null){if(l<=i)return;let u=r[l].indexOf(o);u>-1&&r[l].splice(u,1),o instanceof lu&&t.delete(o.compartment)}if(a.set(o,i),Array.isArray(o))for(let u of o)s(u,i);else if(o instanceof lu){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(o.compartment)||o.inner;t.set(o.compartment,u),s(u,i)}else if(o instanceof bd)s(o.inner,o.prec);else if(o instanceof bn)r[i].push(o),o.provides&&s(o.provides,i);else if(o instanceof Li)r[i].push(o),o.facet.extensions&&s(o.facet.extensions,So.default);else{let u=o.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(u==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(u,i)}}return s(n,So.default),r.reduce((o,i)=>o.concat(i))}function iu(n,e){if(e&1)return 2;let t=e>>1,r=n.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;n.status[t]=4;let a=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|a}function vd(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}var ak=Ne.define(),Fp=Ne.define({combine:n=>n.some(e=>e),static:!0}),sk=Ne.define({combine:n=>n.length?n[0]:void 0,static:!0}),ok=Ne.define(),ik=Ne.define(),lk=Ne.define(),uk=Ne.define({combine:n=>n.length?n[0]:!1}),qr=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Ep}},Ep=class{of(e){return new qr(this,e)}},Op=class{constructor(e){this.map=e}of(e){return new xt(this,e)}},xt=class n{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new n(this.type,t)}is(e){return this.type==e}static define(e={}){return new Op(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let a of e){let s=a.map(t);s&&r.push(s)}return r}};xt.reconfigure=xt.define();xt.appendConfig=xt.define();var In=class n{constructor(e,t,r,a,s,o){this.startState=e,this.changes=t,this.selection=r,this.effects=a,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&rk(r,t.newLength),s.some(i=>i.type==n.time)||(this.annotations=s.concat(n.time.of(Date.now())))}static create(e,t,r,a,s,o){return new n(e,t,r,a,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(n.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}};In.time=qr.define();In.userEvent=qr.define();In.addToHistory=qr.define();In.remote=qr.define();function MM(n,e){let t=[];for(let r=0,a=0;;){let s,o;if(r<n.length&&(a==e.length||e[a]>=n[r]))s=n[r++],o=n[r++];else if(a<e.length)s=e[a++],o=e[a++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function ck(n,e,t){var r;let a,s,o;return t?(a=e.changes,s=Pn.empty(e.changes.length),o=n.changes.compose(e.changes)):(a=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(a)),{changes:o,selection:e.selection?e.selection.map(s):(r=n.selection)===null||r===void 0?void 0:r.map(a),effects:xt.mapEffects(n.effects,a).concat(xt.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Bp(n,e,t){let r=e.selection,a=Ii(e.annotations);return e.userEvent&&(a=a.concat(In.userEvent.of(e.userEvent))),{changes:e.changes instanceof Pn?e.changes:Pn.of(e.changes||[],t,n.facet(sk)),selection:r&&(r instanceof se?r:se.single(r.anchor,r.head)),effects:Ii(e.effects),annotations:a,scrollIntoView:!!e.scrollIntoView}}function dk(n,e,t){let r=Bp(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;r=ck(r,Bp(n,e[s],o?r.changes.newLength:n.doc.length),o)}let a=In.create(n,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return DM(t?TM(a):a)}function TM(n){let e=n.startState,t=!0;for(let a of e.facet(ok)){let s=a(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:MM(t,s))}if(t!==!0){let a,s;if(t===!1)s=n.changes.invertedDesc,a=Pn.empty(e.doc.length);else{let o=n.changes.filter(t);a=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}n=In.create(e,a,n.selection&&n.selection.map(s),xt.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let r=e.facet(ik);for(let a=r.length-1;a>=0;a--){let s=r[a](n);s instanceof In?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof In?n=s[0]:n=dk(e,Ii(s),!1)}return n}function DM(n){let e=n.startState,t=e.facet(lk),r=n;for(let a=t.length-1;a>=0;a--){let s=t[a](n);s&&Object.keys(s).length&&(r=ck(r,Bp(e,s,n.changes.newLength),!0))}return r==n?n:In.create(e,n.changes,n.selection,r.effects,r.annotations,r.scrollIntoView)}var FM=[];function Ii(n){return n==null?FM:Array.isArray(n)?n:[n]}var la=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(la||(la={})),EM=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,_p;try{_p=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function OM(n){if(_p)return _p.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||EM.test(t)))return!0}return!1}function BM(n){return e=>{if(!/\S/.test(e))return la.Space;if(OM(e))return la.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return la.Word;return la.Other}}var Lt=class n{constructor(e,t,r,a,s,o){this.config=e,this.doc=t,this.selection=r,this.values=a,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let i=0;i<this.config.dynamicSlots.length;i++)iu(this,i<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return iu(this,r),vd(this,r)}update(...e){return dk(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:a}=t;for(let i of e.effects)i.is(jr.reconfigure)?(t&&(a=new Map,t.compartments.forEach((l,u)=>a.set(u,l)),t=null),a.set(i.value.compartment,i.value.extension)):i.is(xt.reconfigure)?(t=null,r=i.value):i.is(xt.appendConfig)&&(t=null,r=Ii(r).concat(i.value));let s;t?s=e.startState.values.slice():(t=wd.resolve(r,a,this),s=new n(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let o=e.startState.facet(Fp)?e.newSelection:e.newSelection.asSingle();new n(t,e.newDoc,o,s,(i,l)=>l.update(i,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:se.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),a=this.changes(r.changes),s=[r.range],o=Ii(r.effects);for(let i=1;i<t.ranges.length;i++){let l=e(t.ranges[i]),u=this.changes(l.changes),c=u.map(a);for(let f=0;f<i;f++)s[f]=s[f].map(c);let d=a.mapDesc(u,!0);s.push(l.range.map(d)),a=a.compose(c),o=xt.mapEffects(o,c).concat(xt.mapEffects(Ii(l.effects),d))}return{changes:a,selection:se.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Pn?e:Pn.of(e,this.doc.length,this.facet(n.lineSeparator))}toText(e){return it.of(e.split(this.facet(n.lineSeparator)||Rp))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(iu(this,t),vd(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let a=e[r];a instanceof bn&&this.config.address[a.id]!=null&&(t[r]=a.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let a=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let o=r[s],i=e[s];a.push(o.init(l=>o.spec.fromJSON(i,l)))}}return n.create({doc:e.doc,selection:se.fromJSON(e.selection),extensions:t.extensions?a.concat([t.extensions]):a})}static create(e={}){let t=wd.resolve(e.extensions||[],new Map),r=e.doc instanceof it?e.doc:it.of((e.doc||"").split(t.staticFacet(n.lineSeparator)||Rp)),a=e.selection?e.selection instanceof se?e.selection:se.single(e.selection.anchor,e.selection.head):se.single(0);return rk(a,r.length),t.staticFacet(Fp)||(a=a.asSingle()),new n(t,r,a,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(n.tabSize)}get lineBreak(){return this.facet(n.lineSeparator)||`
|
|
36
|
+
`}get readOnly(){return this.facet(uk)}phrase(e,...t){for(let r of this.facet(n.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(r,a)=>{if(a=="$")return"$";let s=+(a||1);return!s||s>t.length?r:t[s-1]})),e}languageDataAt(e,t,r=-1){let a=[];for(let s of this.facet(ak))for(let o of s(this,t,r))Object.prototype.hasOwnProperty.call(o,e)&&a.push(o[e]);return a}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return BM(t.length?t[0]:"")}wordAt(e){let{text:t,from:r,length:a}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-r,i=e-r;for(;o>0;){let l=An(t,o,!1);if(s(t.slice(l,o))!=la.Word)break;o=l}for(;i<a;){let l=An(t,i);if(s(t.slice(i,l))!=la.Word)break;i=l}return o==i?null:se.range(o+r,i+r)}};Lt.allowMultipleSelections=Fp;Lt.tabSize=Ne.define({combine:n=>n.length?n[0]:4});Lt.lineSeparator=sk;Lt.readOnly=uk;Lt.phrases=Ne.define({compare(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length==r.length&&t.every(a=>n[a]==e[a])}});Lt.languageData=ak;Lt.changeFilter=ok;Lt.transactionFilter=ik;Lt.transactionExtender=lk;jr.reconfigure=xt.define();function Pi(n,e,t={}){let r={};for(let a of n)for(let s of Object.keys(a)){let o=a[s],i=r[s];if(i===void 0)r[s]=o;else if(!(i===o||o===void 0))if(Object.hasOwnProperty.call(t,s))r[s]=t[s](i,o);else throw new Error("Config merge conflict for field "+s)}for(let a in e)r[a]===void 0&&(r[a]=e[a]);return r}var Ma=class{eq(e){return this==e}range(e,t=e){return uu.create(e,t,this)}};Ma.prototype.startSide=Ma.prototype.endSide=0;Ma.prototype.point=!1;Ma.prototype.mapMode=dr.TrackDel;function jp(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}var uu=class n{constructor(e,t,r){this.from=e,this.to=t,this.value=r}static create(e,t,r){return new n(e,t,r)}};function Hp(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}var Up=class n{constructor(e,t,r,a){this.from=e,this.to=t,this.value=r,this.maxPoint=a}get length(){return Si(this.to)}findIndex(e,t,r,a=0){let s=r?this.to:this.from;for(let o=a,i=s.length;;){if(o==i)return o;let l=o+i>>1,u=s[l]-e||(r?this.value[l].endSide:this.value[l].startSide)-t;if(l==o)return u>=0?o:i;u>=0?i=l:o=l+1}}between(e,t,r,a){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(r,1e9,!1,s);s<o;s++)if(a(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t,r,a,s){let o=[],i=[],l=[],u=-1,c=-1;e:for(let d=0;d<this.value.length;d++){let f=this.value[d],h=this.from[d]+e,p=this.to[d]+e,m,g;if(h==p){let x=t.mapPos(h,f.startSide,f.mapMode);if(x==null||(m=g=x,f.startSide!=f.endSide&&(g=t.mapPos(h,f.endSide),g<m)))continue}else if(m=t.mapPos(h,f.startSide),g=t.mapPos(p,f.endSide),m>g||m==g&&f.startSide>0&&f.endSide<=0)continue;if(!((g-m||f.endSide-f.startSide)<0))if(u<0&&(u=m),f.point&&(c=Math.max(c,g-m)),(m-r||f.startSide-a)>=0)o.push(f),i.push(m-u),l.push(g-u),r=g,a=f.endSide;else{if(m==g)for(let x=o.length;x>0;x--){if((m-(l[x-1]+u)||f.startSide-o[x-1].endSide)>=0){o.splice(x,0,f),i.splice(x,0,m-u),l.splice(x,0,g-u);continue e}if((m-(i[x-1]+u)||f.endSide-o[x-1].startSide)>0)break}s(m,g,f)}}return{mapped:o.length?new n(i,l,o,c):null,pos:u}}},vt=class n{constructor(e,t,r,a){this.chunkPos=e,this.chunk=t,this.nextLayer=r,this.maxPoint=a}static create(e,t,r,a){return new n(e,t,r,a)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:r=!1,filterFrom:a=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(r&&(t=t.slice().sort(Hp)),this.isEmpty)return t.length?n.of(t):this;let i=new kd(this,null,-1).goto(0),l=0,u=[],c=new Wn;for(;i.value||l<t.length;)if(l<t.length&&(i.from-t[l].from||i.startSide-t[l].value.startSide)>=0){let d=t[l++];c.addInner(d.from,d.to,d.value,!1)||u.push(d)}else i.rangeIndex==1&&i.chunkIndex<this.chunk.length&&(l==t.length||this.chunkEnd(i.chunkIndex)<t[l].from)&&(!o||a>this.chunkEnd(i.chunkIndex)||s<this.chunkPos[i.chunkIndex])&&c.addChunk(this.chunkPos[i.chunkIndex],this.chunk[i.chunkIndex])?i.nextChunk():((!o||a>i.to||s<i.from||o(i.from,i.to,i.value))&&(c.addInner(i.from,i.to,i.value,!1)||u.push(uu.create(i.from,i.to,i.value))),i.next());return c.finishInner(this.nextLayer.isEmpty&&!u.length?n.empty:this.nextLayer.update({add:u,filter:o,filterFrom:a,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],r=[],a=-1,s,o=(l,u,c)=>{s||(s=new Wn),s.addRange(l,u,c,!1)};for(let l=0;l<this.chunk.length;l++){let u=this.chunkPos[l],c=this.chunk[l],d=e.touchesRange(u,u+c.length);if(d===!1)a=Math.max(a,c.maxPoint),t.push(c),r.push(e.mapPos(u));else if(d===!0){let[f,h]=t.length?[Si(r)+Si(t).length,Si(Si(t).value).endSide]:[-1,-1],{mapped:p,pos:m}=c.map(u,e,f,h,o);p&&(a=Math.max(a,p.maxPoint),t.push(p),r.push(m))}}let i=this.nextLayer.map(e);return s&&(i=s.finishInner(i)),t.length==0?i:new n(r,t,i||n.empty,a)}between(e,t,r){if(!this.isEmpty){for(let a=0;a<this.chunk.length;a++){let s=this.chunkPos[a],o=this.chunk[a];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,r)===!1)return}this.nextLayer.between(e,t,r)}}iter(e=0){return cu.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return cu.from(e).goto(t)}static compare(e,t,r,a,s=-1){let o=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),i=t.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=J1(o,i,r),u=new Co(o,l,s),c=new Co(i,l,s);r.iterGaps((d,f,h)=>Z1(u,d,c,f,h,a)),r.empty&&r.length==0&&Z1(u,0,c,0,0,a)}static eq(e,t,r=0,a){a==null&&(a=999999999);let s=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let i=J1(s,o),l=new Co(s,i,0).goto(r),u=new Co(o,i,0).goto(r);for(;;){if(l.to!=u.to||!Gp(l.active,u.active)||l.point&&(!u.point||!jp(l.point,u.point)))return!1;if(l.to>a)return!0;l.next(),u.next()}}static spans(e,t,r,a,s=-1){let o=new Co(e,null,s).goto(t),i=t,l=o.openStart;for(;;){let u=Math.min(o.to,r);if(o.point){let c=o.activeForPoint(o.to),d=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,l);a.point(i,u,o.point,c,d,o.pointRank),l=Math.min(o.openEnd(u),c.length)}else u>i&&(a.span(i,u,o.active,l),l=o.openEnd(u));if(o.to>r)return l+(o.point&&o.to>r?1:0);i=o.to,o.next()}}static of(e,t=!1){let r=new Wn;for(let a of e instanceof uu?[e]:t?_M(e):e)r.add(a.from,a.to,a.value);return r.finish()}static join(e){if(!e.length)return n.empty;let t=Si(e);for(let r=e.length-2;r>=0;r--)for(let a=e[r];a!=n.empty;a=a.nextLayer)t=new n(a.chunkPos,a.chunk,t,Math.max(a.maxPoint,t.maxPoint));return t}};vt.empty=new vt([],[],null,-1);function Si(n){return n[n.length-1]}function _M(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let r=n[t];if(Hp(e,r)>0)return n.slice().sort(Hp);e=r}return n}vt.empty.nextLayer=vt.empty;var Wn=class n{finishChunk(e){this.chunks.push(new Up(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,r){this.addRange(e,t,r,!0)}addRange(e,t,r,a){this.addInner(e,t,r,a)||(this.nextLayer||(this.nextLayer=new n)).addRange(e,t,r,a)}addInner(e,t,r,a){let s=e-this.lastTo||r.startSide-this.last.endSide;if(a&&s<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=r,this.lastFrom=e,this.lastTo=t,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let r=t.value.length-1;return this.last=t.value[r],this.lastFrom=t.from[r]+e,this.lastTo=t.to[r]+e,!0}finish(){return this.finishInner(vt.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=vt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function J1(n,e,t){let r=new Map;for(let s of n)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&r.set(s.chunk[o],s.chunkPos[o]);let a=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let i=r.get(s.chunk[o]);i!=null&&(t?t.mapPos(i):i)==s.chunkPos[o]&&!t?.touchesRange(i,i+s.chunk[o].length)&&a.add(s.chunk[o])}return a}var kd=class{constructor(e,t,r,a=0){this.layer=e,this.skip=t,this.minPoint=r,this.rank=a}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,r){for(;this.chunkIndex<this.layer.chunk.length;){let a=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(a)||this.layer.chunkEnd(this.chunkIndex)<e||a.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let a=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!r||this.rangeIndex<a)&&this.setRangeIndex(a)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],r=e+t.from[this.rangeIndex];if(this.from=r,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},cu=class n{constructor(e){this.heap=e}static from(e,t=null,r=-1){let a=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=r&&a.push(new kd(o,t,r,s));return a.length==1?a[0]:new n(a)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let r of this.heap)r.goto(e,t);for(let r=this.heap.length>>1;r>=0;r--)Pp(this.heap,r);return this.next(),this}forward(e,t){for(let r of this.heap)r.forward(e,t);for(let r=this.heap.length>>1;r>=0;r--)Pp(this.heap,r);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Pp(this.heap,0)}}};function Pp(n,e){for(let t=n[e];;){let r=(e<<1)+1;if(r>=n.length)break;let a=n[r];if(r+1<n.length&&a.compare(n[r+1])>=0&&(a=n[r+1],r++),t.compare(a)<0)break;n[r]=t,n[e]=a,e=r}}var Co=class{constructor(e,t,r){this.minPoint=r,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=cu.from(e,t,r)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){pd(this.active,e),pd(this.activeTo,e),pd(this.activeRank,e),this.minActive=Q1(this.active,this.activeTo)}addActive(e){let t=0,{value:r,to:a,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||a-this.activeTo[t])>0;)t++;md(this.active,t,r),md(this.activeTo,t,a),md(this.activeRank,t,s),e&&md(e,t,this.cursor.from),this.minActive=Q1(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let a=this.minActive;if(a>-1&&(this.activeTo[a]-this.cursor.from||this.active[a].endSide-this.cursor.startSide)<0){if(this.activeTo[a]>e){this.to=this.activeTo[a],this.endSide=this.active[a].endSide;break}this.removeActive(a),r&&pd(r,a)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(r){this.openStart=0;for(let a=r.length-1;a>=0&&r[a]<e;a--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&t.push(this.active[r]);return t.reverse()}openEnd(e){let t=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)t++;return t}};function Z1(n,e,t,r,a,s){n.goto(e),t.goto(r);let o=r+a,i=r,l=r-e,u=!!s.boundChange;for(let c=!1;;){let d=n.to+l-t.to,f=d||n.endSide-t.endSide,h=f<0?n.to+l:t.to,p=Math.min(h,o);if(n.point||t.point?(n.point&&t.point&&jp(n.point,t.point)&&Gp(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(i,p,n.point,t.point),c=!1):(c&&(s.boundChange(i),c=!1),p>i&&!Gp(n.active,t.active)&&s.compareRange(i,p,n.active,t.active),u&&p<o&&(d||n.openEnd(h)!=t.openEnd(h))&&(c=!0)),h>o)break;i=h,f<=0&&n.next(),f>=0&&t.next()}}function Gp(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!jp(n[t],e[t]))return!1;return!0}function pd(n,e){for(let t=e,r=n.length-1;t<r;t++)n[t]=n[t+1];n.pop()}function md(n,e,t){for(let r=n.length-1;r>=e;r--)n[r+1]=n[r];n[e]=t}function Q1(n,e){let t=-1,r=1e9;for(let a=0;a<e.length;a++)(e[a]-r||n[a].endSide-n[t].endSide)<0&&(t=a,r=e[a]);return t}function Ao(n,e,t=n.length){let r=0;for(let a=0;a<t&&a<n.length;)n.charCodeAt(a)==9?(r+=e-r%e,a++):(r++,a=An(n,a));return r}function fk(n,e,t,r){for(let a=0,s=0;;){if(s>=e)return a;if(a==n.length)break;s+=n.charCodeAt(a)==9?t-s%t:1,a=An(n,a)}return r===!0?-1:n.length}var hk=typeof Symbol>"u"?"__\u037C":Symbol.for("\u037C"),qp=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),pk=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{},fr=class{constructor(e,t){this.rules=[];let{finish:r}=t||{};function a(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,i,l,u){let c=[],d=/^@(\w+)\b/.exec(o[0]),f=d&&d[1]=="keyframes";if(d&&i==null)return l.push(o[0]+";");for(let h in i){let p=i[h];if(/&/.test(h))s(h.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,l);else if(p&&typeof p=="object"){if(!d)throw new RangeError("The value of a property ("+h+") should be a primitive value.");s(a(h),p,c,f)}else p!=null&&c.push(h.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||f)&&l.push((r&&!d&&!u?o.map(r):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)s(a(o),e[o],this.rules)}getRules(){return this.rules.join(`
|
|
37
|
+
`)}static newName(){let e=pk[hk]||1;return pk[hk]=e+1,"\u037C"+e.toString(36)}static mount(e,t,r){let a=e[qp],s=r&&r.nonce;a?s&&a.setNonce(s):a=new Vp(e,s),a.mount(Array.isArray(t)?t:[t],e)}},mk=new Map,Vp=class{constructor(e,t){let r=e.ownerDocument||e,a=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&a.CSSStyleSheet){let s=mk.get(r);if(s)return e[qp]=s;this.sheet=new a.CSSStyleSheet,mk.set(r,this)}else this.styleTag=r.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[qp]=this}mount(e,t){let r=this.sheet,a=0,s=0,o=!1;for(let i=0;i<e.length;i++){let l=e[i],u=this.modules.indexOf(l);if(u<s&&u>-1&&(this.modules.splice(u,1),o=!0,s--,u=-1),u==-1){if(this.modules.splice(s++,0,l),o=!0,r)for(let c=0;c<l.rules.length;c++)r.insertRule(l.rules[c],a++)}else{for(;s<u;)a+=this.modules[s++].rules.length;a+=l.rules.length,s++}}if(r)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{if(o){let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
|
|
38
|
+
`;this.styleTag.textContent=l}let i=t.head||t;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}};var ss={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Ni={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},HM=typeof navigator<"u"&&/Mac/.test(navigator.platform),UM=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(pn=0;pn<10;pn++)ss[48+pn]=ss[96+pn]=String(pn);var pn;for(pn=1;pn<=24;pn++)ss[pn+111]="F"+pn;var pn;for(pn=65;pn<=90;pn++)ss[pn]=String.fromCharCode(pn+32),Ni[pn]=String.fromCharCode(pn);var pn;for(Sd in ss)Ni.hasOwnProperty(Sd)||(Ni[Sd]=ss[Sd]);var Sd;function gk(n){var e=HM&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||UM&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Ni:ss)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}var tr=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Qp=typeof document<"u"?document:{documentElement:{style:{}}},em=/Edge\/(\d+)/.exec(tr.userAgent),Kk=/MSIE \d/.test(tr.userAgent),tm=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(tr.userAgent),Kd=!!(Kk||tm||em),xk=!Kd&&/gecko\/(\d+)/i.test(tr.userAgent),$p=!Kd&&/Chrome\/(\d+)/.exec(tr.userAgent),yk="webkitFontSmoothing"in Qp.documentElement.style,nm=!Kd&&/Apple Computer/.test(tr.vendor),bk=nm&&(/Mobile\/\w+/.test(tr.userAgent)||tr.maxTouchPoints>2),ke={mac:bk||/Mac/.test(tr.platform),windows:/Win/.test(tr.platform),linux:/Linux|X11/.test(tr.platform),ie:Kd,ie_version:Kk?Qp.documentMode||6:tm?+tm[1]:em?+em[1]:0,gecko:xk,gecko_version:xk?+(/Firefox\/(\d+)/.exec(tr.userAgent)||[0,0])[1]:0,chrome:!!$p,chrome_version:$p?+$p[1]:0,ios:bk,android:/Android\b/.test(tr.userAgent),webkit:yk,webkit_version:yk?+(/\bAppleWebKit\/(\d+)/.exec(tr.userAgent)||[0,0])[1]:0,safari:nm,safari_version:nm?+(/\bVersion\/(\d+(\.\d+)?)/.exec(tr.userAgent)||[0,0])[1]:0,tabSize:Qp.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Wm(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}var Fd=Object.create(null);function jm(n,e,t){if(n==e)return!0;n||(n=Fd),e||(e=Fd);let r=Object.keys(n),a=Object.keys(e);if(r.length-(t&&r.indexOf(t)>-1?1:0)!=a.length-(t&&a.indexOf(t)>-1?1:0))return!1;for(let s of r)if(s!=t&&(a.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function GM(n,e){for(let t=n.attributes.length-1;t>=0;t--){let r=n.attributes[t].name;e[r]==null&&n.removeAttribute(r)}for(let t in e){let r=e[t];t=="style"?n.style.cssText=r:n.getAttribute(t)!=r&&n.setAttribute(t,r)}}function wk(n,e,t){let r=!1;if(e)for(let a in e)t&&a in t||(r=!0,a=="style"?n.style.cssText="":n.removeAttribute(a));if(t)for(let a in t)e&&e[a]==t[a]||(r=!0,a=="style"?n.style.cssText=t[a]:n.setAttribute(a,t[a]));return r}function zM(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let r=n.attributes[t];e[r.name]=r.value}return e}var Rr=class{eq(e){return!1}updateDOM(e,t,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},Fn=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(Fn||(Fn={})),Ke=class extends Ma{constructor(e,t,r,a){super(),this.startSide=e,this.endSide=t,this.widget=r,this.spec=a}get heightRelevant(){return!1}static mark(e){return new Su(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return t+=r&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Mo(e,t,t,r,e.widget||null,!1)}static replace(e){let t=!!e.block,r,a;if(e.isBlockGap)r=-5e8,a=4e8;else{let{start:s,end:o}=Xk(e,t);r=(s?t?-3e8:-1:5e8)-1,a=(o?t?2e8:1:-6e8)+1}return new Mo(e,r,a,t,e.widget||null,!0)}static line(e){return new Cu(e)}static set(e,t=!1){return vt.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};Ke.none=vt.empty;var Su=class n extends Ke{constructor(e){let{start:t,end:r}=Xk(e);super(t?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Wm(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Fd}eq(e){return this==e||e instanceof n&&this.tagName==e.tagName&&jm(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}};Su.prototype.point=!1;var Cu=class n extends Ke{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof n&&this.spec.class==e.spec.class&&jm(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}};Cu.prototype.mapMode=dr.TrackBefore;Cu.prototype.point=!0;var Mo=class n extends Ke{constructor(e,t,r,a,s,o){super(t,r,s,e),this.block=a,this.isReplace=o,this.mapMode=a?t<=0?dr.TrackBefore:dr.TrackAfter:dr.TrackDel}get type(){return this.startSide!=this.endSide?Fn.WidgetRange:this.startSide<=0?Fn.WidgetBefore:Fn.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof n&&WM(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}};Mo.prototype.point=!0;function Xk(n,e=!1){let{inclusiveStart:t,inclusiveEnd:r}=n;return t==null&&(t=n.inclusive),r==null&&(r=n.inclusive),{start:t??e,end:r??e}}function WM(n,e){return n==e||!!(n&&e&&n.compare(e))}function Fi(n,e,t,r=0){let a=t.length-1;a>=0&&t[a]+r>=n?t[a]=Math.max(t[a],e):t.push(n,e)}var Ed=class n extends Ma{constructor(e,t,r){super(),this.tagName=e,this.attributes=t,this.rank=r}eq(e){return e==this||e instanceof n&&this.tagName==e.tagName&&jm(this.attributes,e.attributes)}static create(e){return new n(e.tagName,e.attributes||Fd,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return vt.of(e,t)}};Ed.prototype.startSide=Ed.prototype.endSide=-1;function Lu(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function rm(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function hu(n,e){if(!e.anchorNode)return!1;try{return rm(n,e.anchorNode)}catch{return!1}}function pu(n){return n.nodeType==3?Au(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function mu(n,e,t,r){return t?vk(n,e,t,r,-1)||vk(n,e,t,r,1):!1}function Ws(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Od(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function vk(n,e,t,r,a){for(;;){if(n==t&&e==r)return!0;if(e==(a<0?0:ls(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=Ws(n)+(a<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(a<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=a<0?ls(n):0}else return!1}}function ls(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Iu(n,e){let{left:t,right:r}=n;if(t==r)return n;let a=e?t:r;return{left:a,right:a,top:n.top,bottom:n.bottom}}function jM(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Yk(n,e){let t=e.width/n.offsetWidth,r=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-n.offsetHeight)<1)&&(r=1),{scaleX:t,scaleY:r}}function qM(n,e,t,r,a,s,o,i){let l=n.ownerDocument,u=l.defaultView||window;for(let c=n,d=!1;c&&!d;)if(c.nodeType==1){let f,h=c==l.body,p=1,m=1;if(h)f=jM(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(d=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let b=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Yk(c,b)),f={left:b.left,right:b.left+c.clientWidth*p,top:b.top,bottom:b.top+c.clientHeight*m}}let g=0,x=0;if(a=="nearest")e.top<f.top+o?(x=e.top-(f.top+o),t>0&&e.bottom>f.bottom+x&&(x=e.bottom-f.bottom+o)):e.bottom>f.bottom-o&&(x=e.bottom-f.bottom+o,t<0&&e.top-x<f.top&&(x=e.top-(f.top+o)));else{let b=e.bottom-e.top,y=f.bottom-f.top;x=(a=="center"&&b<=y?e.top+b/2-y/2:a=="start"||a=="center"&&t<0?e.top-o:e.bottom-y+o)-f.top}if(r=="nearest"?e.left<f.left+s?(g=e.left-(f.left+s),t>0&&e.right>f.right+g&&(g=e.right-f.right+s)):e.right>f.right-s&&(g=e.right-f.right+s,t<0&&e.left<f.left+g&&(g=e.left-(f.left+s))):g=(r=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:r=="start"==i?e.left-s:e.right-(f.right-f.left)+s)-f.left,g||x)if(h)u.scrollBy(g,x);else{let b=0,y=0;if(x){let N=c.scrollTop;c.scrollTop+=x/m,y=(c.scrollTop-N)*m}if(g){let N=c.scrollLeft;c.scrollLeft+=g/p,b=(c.scrollLeft-N)*p}e={left:e.left-b,top:e.top-y,right:e.right-b,bottom:e.bottom-y},b&&Math.abs(b-g)<1&&(r="nearest"),y&&Math.abs(y-x)<1&&(a="nearest")}if(h)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Jk(n,e=!0){let t=n.ownerDocument,r=null,a=null;for(let s=n.parentNode;s&&!(s==t.body||(!e||r)&&a);)if(s.nodeType==1)!a&&s.scrollHeight>s.clientHeight&&(a=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:a}}var am=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:r}=e;this.set(t,Math.min(e.anchorOffset,t?ls(t):0),r,Math.min(e.focusOffset,r?ls(r):0))}set(e,t,r,a){this.anchorNode=e,this.anchorOffset=t,this.focusNode=r,this.focusOffset=a}};function Zk(n){let e=[];for(let t=n;t;t=t.nodeType==11?t.host:t.parentNode)t.nodeType==1&&e.push({node:t,left:t.scrollLeft,top:t.scrollTop});return e}function Qk(n,e=!0){for(let{node:t,left:r,top:a}of n)e&&t.scrollTop!=a&&(t.scrollTop=a),t.scrollLeft!=r&&(t.scrollLeft=r)}var Po=null;ke.safari&&ke.safari_version>=26&&(Po=!1);function eS(n){if(n.setActive)return n.setActive();if(Po)return n.focus(Po);let e=Zk(n);n.focus(Po==null?{get preventScroll(){return Po={preventScroll:!0},!0}}:void 0),Po||(Po=!1,Qk(e))}var kk;function Au(n,e,t=e){let r=kk||(kk=document.createRange());return r.setEnd(n,t),r.setStart(n,e),r}function Ei(n,e,t,r){let a={key:e,code:e,keyCode:t,which:t,cancelable:!0};r&&({altKey:a.altKey,ctrlKey:a.ctrlKey,shiftKey:a.shiftKey,metaKey:a.metaKey}=r);let s=new KeyboardEvent("keydown",a);s.synthetic=!0,n.dispatchEvent(s);let o=new KeyboardEvent("keyup",a);return o.synthetic=!0,n.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function VM(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function $M(n,e){let t=e.focusNode,r=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=r)return!1;for(r=Math.min(r,ls(t));;)if(r){if(t.nodeType!=1)return!1;let a=t.childNodes[r-1];a.contentEditable=="false"?r--:(t=a,r=ls(t))}else{if(t==n)return!0;r=Ws(t),t=t.parentNode}}function tS(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function nS(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r>0)return{node:t,offset:r};if(t.nodeType==1&&r>0){if(t.contentEditable=="false")return null;t=t.childNodes[r-1],r=ls(t)}else if(t.parentNode&&!Od(t))r=Ws(t),t=t.parentNode;else return null}}function rS(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r<t.nodeValue.length)return{node:t,offset:r};if(t.nodeType==1&&r<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[r],r=0}else if(t.parentNode&&!Od(t))r=Ws(t)+1,t=t.parentNode;else return null}}var Fa=class n{constructor(e,t,r=!0){this.node=e,this.offset=t,this.precise=r}static before(e,t){return new n(e.parentNode,Ws(e),t)}static after(e,t){return new n(e.parentNode,Ws(e)+1,t)}},zt=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(zt||(zt={})),To=zt.LTR,qm=zt.RTL;function aS(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}var KM=aS("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),XM=aS("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),sm=Object.create(null),Da=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);sm[e]=t,sm[t]=-e}function sS(n){return n<=247?KM[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?XM[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}var YM=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,Kr=class{get dir(){return this.level%2?qm:To}constructor(e,t,r){this.from=e,this.to=t,this.level=r}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,r,a){let s=-1;for(let o=0;o<e.length;o++){let i=e[o];if(i.from<=t&&i.to>=t){if(i.level==r)return o;(s<0||(a!=0?a<0?i.from<t:i.to>t:e[s].level>i.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}};function oS(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],a=e[t];if(r.from!=a.from||r.to!=a.to||r.direction!=a.direction||!oS(r.inner,a.inner))return!1}return!0}var _t=[];function JM(n,e,t,r,a){for(let s=0;s<=r.length;s++){let o=s?r[s-1].to:e,i=s<r.length?r[s].from:t,l=s?256:a;for(let u=o,c=l,d=l;u<i;u++){let f=sS(n.charCodeAt(u));f==512?f=c:f==8&&d==4&&(f=16),_t[u]=f==4?2:f,f&7&&(d=f),c=f}for(let u=o,c=l,d=l;u<i;u++){let f=_t[u];if(f==128)u<i-1&&c==_t[u+1]&&c&24?f=_t[u]=c:_t[u]=256;else if(f==64){let h=u+1;for(;h<i&&_t[h]==64;)h++;let p=u&&c==8||h<t&&_t[h]==8?d==1?1:8:256;for(let m=u;m<h;m++)_t[m]=p;u=h-1}else f==8&&d==1&&(_t[u]=1);c=f,f&7&&(d=f)}}}function ZM(n,e,t,r,a){let s=a==1?2:1;for(let o=0,i=0,l=0;o<=r.length;o++){let u=o?r[o-1].to:e,c=o<r.length?r[o].from:t;for(let d=u,f,h,p;d<c;d++)if(h=sm[f=n.charCodeAt(d)])if(h<0){for(let m=i-3;m>=0;m-=3)if(Da[m+1]==-h){let g=Da[m+2],x=g&2?a:g&4?g&1?s:a:0;x&&(_t[d]=_t[Da[m]]=x),i=m;break}}else{if(Da.length==189)break;Da[i++]=d,Da[i++]=f,Da[i++]=l}else if((p=_t[d])==2||p==1){let m=p==a;l=m?0:1;for(let g=i-3;g>=0;g-=3){let x=Da[g+2];if(x&2)break;if(m)Da[g+2]|=2;else{if(x&4)break;Da[g+2]|=4}}}}}function QM(n,e,t,r){for(let a=0,s=r;a<=t.length;a++){let o=a?t[a-1].to:n,i=a<t.length?t[a].from:e;for(let l=o;l<i;){let u=_t[l];if(u==256){let c=l+1;for(;;)if(c==i){if(a==t.length)break;c=t[a++].to,i=a<t.length?t[a].from:e}else if(_t[c]==256)c++;else break;let d=s==1,f=(c<e?_t[c]:r)==1,h=d==f?d?1:2:r;for(let p=c,m=a,g=m?t[m-1].to:n;p>l;)p==g&&(p=t[--m].from,g=m?t[m-1].to:n),_t[--p]=h;l=c}else s=u,l++}}}function om(n,e,t,r,a,s,o){let i=r%2?2:1;if(r%2==a%2)for(let l=e,u=0;l<t;){let c=!0,d=!1;if(u==s.length||l<s[u].from){let m=_t[l];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u<s.length&&p==s[u].from){if(d)break e;let m=s[u];if(!c)for(let g=m.to,x=u+1;;){if(g==t)break e;if(x<s.length&&s[x].from==g)g=s[x++].to;else{if(_t[g]==i)break e;break}}if(u++,f)f.push(m);else{m.from>l&&o.push(new Kr(l,m.from,h));let g=m.direction==To!=!(h%2);im(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.to}p=m.to}else{if(p==t||(c?_t[p]!=i:_t[p]==i))break;p++}f?om(n,l,p,r+1,a,f,o):l<p&&o.push(new Kr(l,p,h)),l=p}else for(let l=t,u=s.length;l>e;){let c=!0,d=!1;if(!u||l>s[u-1].to){let m=_t[l-1];m!=i&&(c=!1,d=m==16)}let f=!c&&i==1?[]:null,h=c?r:r+1,p=l;e:for(;;)if(u&&p==s[u-1].to){if(d)break e;let m=s[--u];if(!c)for(let g=m.from,x=u;;){if(g==e)break e;if(x&&s[x-1].to==g)g=s[--x].from;else{if(_t[g-1]==i)break e;break}}if(f)f.push(m);else{m.to<l&&o.push(new Kr(m.to,l,h));let g=m.direction==To!=!(h%2);im(n,g?r+1:r,a,m.inner,m.from,m.to,o),l=m.from}p=m.from}else{if(p==e||(c?_t[p-1]!=i:_t[p-1]==i))break;p--}f?om(n,p,l,r+1,a,f,o):p<l&&o.push(new Kr(p,l,h)),l=p}}function im(n,e,t,r,a,s,o){let i=e%2?2:1;JM(n,a,s,r,i),ZM(n,a,s,r,i),QM(a,s,r,i),om(n,a,s,e,t,r,o)}function eT(n,e,t){if(!n)return[new Kr(0,0,e==qm?1:0)];if(e==To&&!t.length&&!YM.test(n))return iS(n.length);if(t.length)for(;n.length>_t.length;)_t[_t.length]=256;let r=[],a=e==To?0:1;return im(n,a,a,t,0,n.length,r),r}function iS(n){return[new Kr(0,n,0)]}var lS="";function tT(n,e,t,r,a){var s;if(!n.length)return null;let o=r.head-n.from,i;if(r.head==n.from&&r.assoc<0){if(!a)return null;o=e[i=0].side(!1,t)}else if(r.head==n.to&&r.assoc>0){if(a)return null;o=e[i=e.length-1].side(!0,t)}else i=Kr.find(e,o,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc);let l=e[i],u=l.side(a,t);if(o==u){let f=i+=a?1:-1;if(f<0||f>=e.length)return null;l=e[i=f],o=l.side(!a,t),u=l.side(a,t)}let c=An(n.text,o,l.forward(a,t));(c<l.from||c>l.to)&&(c=u),lS=n.text.slice(Math.min(o,c),Math.max(o,c));let d=i==(a?e.length-1:0)?null:e[i+(a?1:-1)];if(c==u){if(!d)return a?se.cursor(n.to,1):se.cursor(n.from,-1);if(d.level+(a?0:1)<l.level)return se.cursor(d.side(!a,t)+n.from,d.forward(a,t)?1:-1,d.level)}return se.cursor(c+n.from,l.forward(a,t)?-1:1,l.level)}function nT(n,e,t){for(let r=e;r<t;r++){let a=sS(n.charCodeAt(r));if(a==1)return To;if(a==2||a==4)return qm}return To}var uS=Ne.define(),cS=Ne.define(),dS=Ne.define(),fS=Ne.define(),lm=Ne.define(),hS=Ne.define(),pS=Ne.define(),Vm=Ne.define(),$m=Ne.define(),mS=Ne.define({combine:n=>n.some(e=>e)}),gS=Ne.define({combine:n=>n.some(e=>e)}),xS=Ne.define(),gu=class n{constructor(e,t,r,a,s,o=!1){this.range=e,this.y=t,this.x=r,this.yMargin=a,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new n(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new n(se.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},Cd=xt.define({map:(n,e)=>n.map(e)}),yS=xt.define();function ca(n,e,t){let r=n.facet(fS);r.length?r[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}var os=Ne.define({combine:n=>n.length?n[0]:!0}),rT=0,Mi=Ne.define({combine(n){return n.filter((e,t)=>{for(let r=0;r<t;r++)if(n[r].plugin==e.plugin)return!1;return!0})}}),pr=class n{constructor(e,t,r,a,s){this.id=e,this.create=t,this.domEventHandlers=r,this.domEventObservers=a,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Mi.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Mi.of({plugin:this,arg:e}))}static define(e,t){let{eventHandlers:r,eventObservers:a,provide:s,decorations:o}=t||{};return new n(rT++,e,r,a,i=>{let l=[];return o&&l.push(Xd.of(u=>{let c=u.plugin(i);return c?o(c):Ke.none})),s&&l.push(s(i)),l})}static fromClass(e,t){return n.define((r,a)=>new e(r,a),t)}},xu=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(r){if(ca(t.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){ca(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(r){ca(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},bS=Ne.define(),Km=Ne.define(),Xd=Ne.define(),wS=Ne.define(),Xm=Ne.define(),Pu=Ne.define(),vS=Ne.define();function Sk(n,e){let t=n.state.facet(vS);if(!t.length)return t;let r=t.map(s=>s instanceof Function?s(n):s),a=[];return vt.spans(r,e.from,e.to,{point(){},span(s,o,i,l){let u=s-e.from,c=o-e.from,d=a;for(let f=i.length-1;f>=0;f--,l--){let h=i[f].spec.bidiIsolate,p;if(h==null&&(h=nT(e.text,u,c)),l>0&&d.length&&(p=d[d.length-1]).to==u&&p.direction==h)p.to=c,d=p.inner;else{let m={from:u,to:c,direction:h,inner:[]};d.push(m),d=m.inner}}}}),a}var kS=Ne.define();function SS(n){let e=0,t=0,r=0,a=0;for(let s of n.state.facet(kS)){let o=s(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(a=Math.max(a,o.bottom)))}return{left:e,right:t,top:r,bottom:a}}var du=Ne.define(),da=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}join(e){return new n(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,r=this;for(;t>0;t--){let a=e[t-1];if(!(a.fromA>r.toA)){if(a.toA<r.fromA)break;r=r.join(a),e.splice(t-1,1)}}return e.splice(t,0,r),e}static extendWithRanges(e,t){if(t.length==0)return e;let r=[];for(let a=0,s=0,o=0;;){let i=a<e.length?e[a].fromB:1e9,l=s<t.length?t[s]:1e9,u=Math.min(i,l);if(u==1e9)break;let c=u+o,d=u,f=c;for(;;)if(s<t.length&&t[s]<=d){let h=t[s+1];s+=2,d=Math.max(d,h);for(let p=a;p<e.length&&e[p].fromB<=d;p++)o=e[p].toA-e[p].toB;f=Math.max(f,h+o)}else if(a<e.length&&e[a].fromB<=d){let h=e[a++];d=Math.max(d,h.toB),f=Math.max(f,h.toA),o=h.toA-h.toB}else break;r.push(new n(c,f,u,d))}return r}},Bd=class n{constructor(e,t,r){this.view=e,this.state=t,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Pn.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let a=[];this.changes.iterChangedRanges((s,o,i,l)=>a.push(new da(s,o,i,l))),this.changedRanges=a}static create(e,t,r){return new n(e,t,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},aT=[],Xt=class{constructor(e,t,r=0){this.dom=e,this.length=t,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return aT}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&GM(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let r=t;for(let a of this.children){if(a==e)return r;r+=a.length+a.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,r){return null}domPosFor(e,t){let r=Ws(this.dom),a=this.length?e>0:t>0;return new Fa(this.parent.dom,r+(a?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Bi)return e;return null}static get(e){return e.cmTile}},Oi=class extends Xt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,r=null,a,s=e?.node==t?e:null,o=0;for(let i of this.children){if(i.sync(e),o+=i.length+i.breakAfter,a=r?r.nextSibling:t.firstChild,s&&a!=i.dom&&(s.written=!0),i.dom.parentNode==t)for(;a&&a!=i.dom;)a=Ck(a);else t.insertBefore(i.dom,a);r=i.dom}for(a=r?r.nextSibling:t.firstChild,s&&a&&(s.written=!0);a;)a=Ck(a);this.length=o}};function Ck(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}var Bi=class extends Oi{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Xt.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],r=this,a=0,s=0;;)if(a==r.children.length){if(!t.length)return;r=r.parent,r.breakAfter&&s++,a=t.pop()}else{let o=r.children[a++];if(o instanceof is)t.push(a),r=o,a=0;else{let i=s+o.length,l=e(o,s);if(l!==void 0)return l;s=i+o.breakAfter}}}resolveBlock(e,t){let r,a=-1,s,o=-1;if(this.blockTiles((i,l)=>{let u=l+i.length;if(e>=l&&e<=u){if(i.isWidget()&&t>=-1&&t<=1){if(i.flags&32)return!0;i.flags&16&&(r=void 0)}(l<e||e==u&&(t<-1?i.length:i.covers(1)))&&(!r||!i.isWidget()&&r.isWidget())&&(r=i,a=e-l),(u>e||e==l&&(t>1?i.length:i.covers(-1)))&&(!s||!i.isWidget()&&s.isWidget())&&(s=i,o=e-l)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&t<0||!s?{tile:r,offset:a}:{tile:s,offset:o}}},is=class n extends Oi{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},_i=class n extends Oi{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,r){let a=new n(t||document.createElement("div"),e);return(!t||!r)&&(a.flags|=4),a}get domAttrs(){return this.attrs}resolveInline(e,t,r){let a=null,s=-1,o=null,i=-1;function l(c,d){for(let f=0,h=0;f<c.children.length&&h<=d;f++){let p=c.children[f],m=h+p.length;m>=d&&(p.isComposite()?l(p,d-h):(!o||o.isHidden&&(t>0&&!(o.flags&32)||r&&oT(o,p)))&&(m>d||p.flags&32&&t<=1)?(o=p,i=d-h):(h<d||p.flags&16&&!p.isHidden&&t>=-1)&&(a=p,s=d-h)),h=m}}l(this,e);let u=(t<0?a:o)||a||o;return u?{tile:u,offset:u==a?s:i}:null}coordsIn(e,t,r){let a=this.resolveInline(e,t,!0);return a?a.tile.coordsIn(Math.max(0,a.offset),t,r):sT(this)}domIn(e,t){let r=this.resolveInline(e,t);if(r){let{tile:a,offset:s}=r;if(this.dom.contains(a.dom))return a.isText()?new Fa(a.dom,Math.min(a.dom.nodeValue.length,s)):a.domPosFor(s,a.flags&16?1:a.flags&32?-1:t);let o=r.tile.parent,i=!1;for(let l of o.children){if(i)return new Fa(l.dom,0);l==r.tile&&(i=!0)}}return new Fa(this.dom,0)}};function sT(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=pu(e);return t[t.length-1]||null}function oT(n,e){let t=n.coordsIn(0,1),r=e.coordsIn(0,1);return t&&r&&r.top<t.bottom}var hr=class n extends Oi{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let r=new n(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}},No=class n extends Xt{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,r){let a=this.dom.nodeValue.length;e>a&&(e=a);let s=e,o=e,i=0;e==0&&t<0||e==a&&t>=0?ke.chrome||ke.gecko||(e?(s--,i=1):o<a&&(o++,i=-1)):t<0?s--:o<a&&o++;let l=Au(this.dom,s,o).getClientRects();if(!l.length)return null;let u=l[(i?i<0:t>=0)?0:l.length-1];return ke.safari&&!i&&u.width==0&&(u=Array.prototype.find.call(l,c=>c.width)||u),r==null?u:Iu(u,(i?i>0:t<0)==r)}static of(e,t){let r=new n(t||document.createTextNode(e),e);return t||(r.flags|=2),r}},Do=class n extends Xt{constructor(e,t,r,a){super(e,t,a),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,r){let a=this.widget.coordsAt(this.dom,e,t);if(a)return a;if(r)return Iu(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let i=this.flags&16?!0:this.flags&32?!1:e>0;for(let l=i?s.length-1:0;o=s[l],!(e>0?l==0:l==s.length-1||o.top<o.bottom);l+=i?-1:1);return Iu(o,!i)}}get overrideDOMText(){if(!this.length)return it.empty;let{root:e}=this;if(!e)return it.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,r,a,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new n(s,r,e,a)}},Hi=class extends Xt{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return it.empty}coordsIn(e,t,r){let a=this.dom.getBoundingClientRect();return r==null?a:Iu(a,t>0==r)}},um=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,r){let{tile:a,index:s,beforeBreak:o,parents:i}=this;for(;e||t>0;)if(a.isComposite())if(o){if(!e)break;r&&r.break(),e--,o=!1}else if(s==a.children.length){if(!e&&!i.length)break;r&&r.leave(a),o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++}else{let l=a.children[s],u=l.breakAfter;(t>0?l.length<=e:l.length<e)&&(!r||r.skip(l,0,l.length)!==!1||!l.isComposite)?(o=!!u,s++,e-=l.length):(i.push({tile:a,index:s}),a=l,s=0,r&&l.isComposite()&&r.enter(l))}else{let l=a.length;if(s<l&&e){let u=Math.min(e,l-s);r&&r.skip(a,s,s+u),e-=u,s+=u}if(s==l)o=!!a.breakAfter,{tile:a,index:s}=i.pop(),s++;else if(!e)break}return this.tile=a,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},cm=class{constructor(e,t,r,a){this.from=e,this.to=t,this.wrapper=r,this.rank=a}},dm=class{constructor(e,t,r){this.cache=e,this.root=t,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,r,a){var s;this.flushBuffer();let o=this.ensureMarks(t,r),i=o.lastChild;if(i&&i.isText()&&!(i.flags&8)&&i.length+e.length<512){this.cache.reused.set(i,2);let l=o.children[o.children.length-1]=new No(i.dom,i.text+e);l.parent=o}else o.append(a||No.of(e,(s=this.cache.find(No))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let r=this.curLine;r.dom!=t.line.dom&&(r.setDOM(this.cache.reused.has(t.line)?Kp(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let a=r;for(let i=t.marks.length-1;i>=0;i--){let l=t.marks[i],u=a.lastChild;if(u instanceof hr&&u.mark.eq(l.mark))u.dom!=l.dom&&u.setDOM(Kp(l.dom)),a=u;else{let{dom:c}=l;this.cache.reused.get(l)&&Xt.get(l.dom)&&(c=Kp(l.dom));let d=hr.of(l.mark,c);a.append(d),a=d}this.cache.reused.set(l,2)}let s=Xt.get(e.text);s&&this.cache.reused.set(s,2);let o=new No(e.text,e.text.nodeValue);o.flags|=8,this.pos=e.range.toB,a.append(o)}addInlineWidget(e,t,r){let a=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);a||this.flushBuffer();let s=this.ensureMarks(t,r);!a&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,r){this.flushBuffer(),this.ensureMarks(t,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var r;e||(e=CS);let a=_i.start(e,t||((r=this.cache.find(_i))===null||r===void 0?void 0:r.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=a)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var r;let a=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],i;if(t>0&&(i=a.lastChild)&&i instanceof hr&&i.mark.eq(o))a=i,t--;else{let l=hr.of(o,(r=this.cache.find(hr,u=>u.mark.eq(o)))===null||r===void 0?void 0:r.dom);a.append(l),a=l,t=0}}return a}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Lk(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(ke.ios&&Lk(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Xp,0,32)||new Do(Xp.toDOM(),0,Xp,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,r=new cm(e.from,e.to,e.value,t),a=this.wrappers.length;for(;a>0&&(this.wrappers[a-1].rank-r.rank||this.wrappers[a-1].to-r.to)<0;)a--;this.wrappers.splice(a,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let r of this.wrappers){let a=t.lastChild;if(r.from<this.pos&&a instanceof is&&a.wrapper.eq(r.wrapper))t=a;else{let s=is.of(r.wrapper,(e=this.cache.find(is,o=>o.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),r=this.cache.find(Hi,void 0,1);return r&&(r.flags=t),r||new Hi(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},fm=class{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:a,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=a;let i=this.textOff=Math.min(e,a.length);return s?null:a.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,t);return this.textOff=t,r}},_d=[Do,_i,No,hr,Hi,is,Bi];for(let n=0;n<_d.length;n++)_d[n].bucket=n;var hm=class{constructor(e){this.view=e,this.buckets=_d.map(()=>[]),this.index=_d.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,r=this.buckets[t];r.length<6?r.push(e):r[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,r=2){let a=e.bucket,s=this.buckets[a],o=this.index[a];for(let i=0;i<s.length;i++){let l=(i+o)%s.length,u=s[l];if((!t||t(u))&&!this.reused.has(u))return s.splice(l,1),l<o&&this.index[a]--,this.reused.set(u,r),u}return null}findWidget(e,t,r){let a=this.buckets[0];if(a.length)for(let s=0,o=0;;s++){if(s==a.length){if(o)return null;o=1,s=0}let i=a[s];if(!this.reused.has(i)&&(o==0?i.widget.compare(e):i.widget.constructor==e.constructor&&e.updateDOM(i.dom,this.view,i.widget)))return a.splice(s,1),s<this.index[0]&&this.index[0]--,i.widget==e&&i.length==t&&(i.flags&497)==r?(this.reused.set(i,1),i):(this.reused.set(i,2),new Do(i.dom,t,e,i.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},pm=class{constructor(e,t,r,a,s){this.view=e,this.decorations=a,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new hm(e),this.text=new fm(e.state.doc),this.builder=new dm(this.cache,new Bi(e,e.contentDOM),vt.iter(r)),this.cache.reused.set(t,2),this.old=new um(t),this.reuseWalker={skip:(o,i,l)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let r=t&&this.getCompositionContext(t.text);for(let a=0,s=0,o=0;;){let i=o<e.length?e[o++]:null,l=i?i.fromA:this.old.root.length;if(l>a){let u=l-a;this.preserve(u,!o,!i),a=l,s+=u}if(!i)break;t&&i.fromA<=t.range.fromA&&i.toA>=t.range.toA?(this.forward(i.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,r),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,i.toA),this.emit(t.range.toB,i.toB)):(this.forward(i.fromA,i.toA),this.emit(s,i.toB)),s=i.toB,a=i.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,r){let a=uT(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(o,i,l)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(l-i);else{let u=l>0||i<o.length?Do.of(o.widget,this.view,l-i,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);u.flags&256?(u.flags&=-2,this.builder.addBlockWidget(u)):(this.builder.ensureLine(null),this.builder.addInlineWidget(u,a,s),s=a.length)}else if(o.isText())this.builder.ensureLine(null),!i&&l==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,a,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(i,l),a,s)),s=a.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Hi)this.cache.add(o);else if(o instanceof hr)this.builder.ensureLine(null),this.builder.addMark(o,a,s),this.cache.reused.set(o,1),s=a.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof hr&&a.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?a.length&&(a.length=s=0):o instanceof hr&&(a.shift(),s=Math.min(s,a.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let r=null,a=this.builder,s=-1,o=vt.spans(this.decorations,e,t,{point:(i,l,u,c,d,f)=>{if(u instanceof Mo){if(this.disallowBlockEffectsFor[f]){if(u.block)throw new RangeError("Block decorations may not be specified via plugins");if(l>this.view.state.doc.lineAt(i).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=c.length,d>c.length)a.continueWidget(l-i);else{let h=u.widget||(u.block?js.block:js.inline),p=iT(u),m=this.cache.findWidget(h,l-i,p)||Do.of(h,this.view,l-i,p);u.block?(u.startSide>0&&a.addLineStartIfNotCovered(r),a.addBlockWidget(m)):(a.ensureLine(r),a.addInlineWidget(m,c,d))}r=null}else r=lT(r,u);l>i&&this.text.skip(l-i)},span:(i,l,u,c)=>{for(let d=i;d<l;){let f=this.text.next(Math.min(512,l-d));f==null?(a.addLineStartIfNotCovered(r),a.addBreak(),d++):(a.ensureLine(r),a.addText(f,u,d==i?c:u.length),d+=f.length),r=null}s=u.length}});s>-1&&(this.openWidget=o>s),this.openWidget||a.addLineStartIfNotCovered(r),this.openMarks=o}forward(e,t,r=1){t-e<=10?this.old.advance(t-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let t=[],r=null;for(let a=e.parentNode;;a=a.parentNode){let s=Xt.get(a);if(a==this.view.contentDOM)break;s instanceof hr?t.push(s):s?.isLine()?r=s:s instanceof is||(a.nodeName=="DIV"&&!r?r=new _i(a,CS):r||t.push(hr.of(new Su({tagName:a.nodeName.toLowerCase(),attributes:zM(a)}),a)))}return r?{line:r,marks:t}:null}};function Lk(n,e){let t=r=>{for(let a of r.children)if((e?a.isText():a.length)||t(a))return!0;return!1};return t(n)}function iT(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}var CS={class:"cm-line"};function lT(n,e){let t=e.spec.attributes,r=e.spec.class;return!t&&!r||(n||(n={class:"cm-line"}),t&&Wm(t,n),r&&(n.class+=" "+r)),n}function uT(n){let e=[];for(let t=n.parents.length;t>1;t--){let r=t==n.parents.length?n.tile:n.parents[t].tile;r instanceof hr&&e.push(r.mark)}return e}function Kp(n){let e=Xt.get(n);return e&&e.setDOM(n.cloneNode()),n}var js=class extends Rr{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};js.inline=new js("span");js.block=new js("div");var Xp=new class extends Rr{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}},Hd=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Ke.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Bi(e,e.contentDOM),this.updateInner([new da(0,0,0,e.state.doc.length)],null)}update(e){var t;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:c,toA:d})=>d<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let a=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?a=this.domChanged.newSel.head:!xT(e.changes,this.hasComposition)&&!e.selectionSet&&(a=e.state.selection.main.head));let s=a>-1?dT(this.view,e.changes,a):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:d}=this.hasComposition;r=new da(c,d,e.changes.mapPos(c,-1),e.changes.mapPos(d,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(ke.ie||ke.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,i=this.blockWrappers;this.updateDeco();let l=pT(o,this.decorations,e.changes);l.length&&(r=da.extendWithRanges(r,l));let u=mT(i,this.blockWrappers,e.changes);return u.length&&(r=da.extendWithRanges(r,u)),s&&!r.some(c=>c.fromA<=s.range.fromA&&c.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(t||e.length){let o=this.tile,i=new pm(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Xt.get(t.text)&&i.cache.reused.set(Xt.get(t.text),2),this.tile=i.run(e,t),mm(o,i.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=ke.chrome||ke.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let a=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof yu&&a.push(s.dom);r.updateGaps(a)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let r of t.effects)r.is(yS)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,a=this.view.root.activeElement,s=a==r,o=!s&&!(this.view.state.facet(os)||r.tabIndex>-1)&&hu(r,this.view.observer.selectionRange)&&!(a&&r.contains(a));if(!(s||t||o))return;let i=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,u,c;if(l.empty?c=u=this.inlineDOMNearPos(l.anchor,l.assoc||1):(c=this.inlineDOMNearPos(l.head,l.head==l.from?1:-1),u=this.inlineDOMNearPos(l.anchor,l.anchor==l.from?1:-1)),ke.gecko&&l.empty&&!this.hasComposition&&cT(u)){let f=document.createTextNode("");this.view.observer.ignore(()=>u.node.insertBefore(f,u.node.childNodes[u.offset]||null)),u=c=new Fa(f,0),i=!0}let d=this.view.observer.selectionRange;(i||!d.focusNode||(!mu(u.node,u.offset,d.anchorNode,d.anchorOffset)||!mu(c.node,c.offset,d.focusNode,d.focusOffset))&&!this.suppressWidgetCursorChange(d,l))&&(this.view.observer.ignore(()=>{ke.android&&ke.chrome&&r.contains(d.focusNode)&&gT(d.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let f=Lu(this.view.root);if(f)if(l.empty){if(ke.gecko){let h=fT(u.node,u.offset);if(h&&h!=3){let p=(h==1?nS:rS)(u.node,u.offset);p&&(u=new Fa(p.node,p.offset))}}f.collapse(u.node,u.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(u.node,u.offset);try{f.extend(c.node,c.offset)}catch{}}else{let h=document.createRange();l.anchor>l.head&&([u,c]=[c,u]),h.setEnd(c.node,c.offset),h.setStart(u.node,u.offset),f.removeAllRanges(),f.addRange(h)}o&&this.view.root.activeElement==r&&(r.blur(),a&&a.focus())}),this.view.observer.setSelectionRange(u,c)),this.impreciseAnchor=u.precise?null:new Fa(d.anchorNode,d.anchorOffset),this.impreciseHead=c.precise?null:new Fa(d.focusNode,d.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&mu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,r=Lu(e.root),{anchorNode:a,anchorOffset:s}=e.observer.selectionRange;if(!r||!t.empty||!t.assoc||!r.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let i=o.posAtStart;if(t.head==i||t.head==i+o.length)return;let l=this.coordsAt(t.head,-1),u=this.coordsAt(t.head,1);if(!l||!u||l.bottom>u.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);r.collapse(c.node,c.offset),r.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&r.collapse(a,s)}posFromDOM(e,t){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let a=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[t];else{let o=ls(e)==0?0:t==0?-1:1;for(;;){let i=e.parentNode;if(i==r.dom)break;o==0&&i.firstChild!=i.lastChild&&(e==i.firstChild?o=-1:o=1),e=i}o<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return a;for(;s&&!Xt.get(s);)s=s.nextSibling;if(!s)return a+r.length;for(let o=0,i=a;;o++){let l=r.children[o];if(l.dom==s)return i;i+=l.length+l.breakAfter}}else return r.isText()?e==r.dom?a+t:a+(t?r.length:0):a}domAtPos(e,t){let{tile:r,offset:a}=this.tile.resolveBlock(e,t);return r.isWidget()?r.domPosFor(a,t):r.domIn(a,t)}inlineDOMNearPos(e,t){let r,a=-1,s=!1,o,i=-1,l=!1;return this.tile.blockTiles((u,c)=>{if(u.isWidget()){if(u.flags&32&&c>=e)return!0;u.flags&16&&(s=!0)}else{let d=c+u.length;if(c<=e&&(r=u,a=e-c,s=d<e),d>=e&&!o&&(o=u,i=e-c,l=c>e),c>e&&o)return!0}}),!r&&!o?this.domAtPos(e,t):(s&&o?r=null:l&&r&&(o=null),r&&t<0||!o?r.domIn(a,t):o.domIn(i,t))}coordsAt(e,t,r){let{tile:a,offset:s}=this.tile.resolveBlock(e,t);return a.isWidget()?a.widget instanceof yu?null:a.coordsInWidget(s,t,!0):a.coordsIn(s,t,r)}lineAt(e,t){let{tile:r}=this.tile.resolveBlock(e,t);return r.isLine()?r:null}coordsForChar(e){let{tile:t,offset:r}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function a(s,o){if(s.isComposite())for(let i of s.children){if(i.length>=o){let l=a(i,o);if(l)return l}if(o-=i.length,o<0)break}else if(s.isText()&&o<s.length){let i=An(s.text,o);if(i==o)return null;let l=Au(s.dom,o,i).getClientRects();for(let u=0;u<l.length;u++){let c=l[u];if(u==l.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return a(t,r)}measureVisibleLineHeights(e){let t=[],{from:r,to:a}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,i=-1,l=this.view.textDirection==zt.LTR,u=0,c=(d,f,h)=>{for(let p=0;p<d.children.length&&!(f>a);p++){let m=d.children[p],g=f+m.length,x=m.dom.getBoundingClientRect(),{height:b}=x;if(h&&!p&&(u+=x.top-h.top),m instanceof is)g>r&&c(m,f,x);else if(f>=r&&(u>0&&t.push(-u),t.push(b+u),u=0,o)){let y=m.dom.lastChild,N=y?pu(y):[];if(N.length){let L=N[N.length-1],A=l?L.right-x.left:x.right-L.left;A>i&&(i=A,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=g)}}h&&p==d.children.length-1&&(u+=h.bottom-x.bottom),f=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?zt.RTL:zt.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let i=0,l;for(let u of o.children){if(!u.isText()||/[^ -~]/.test(u.text))return;let c=pu(u.dom);if(c.length!=1)return;i+=c[0].width,l=c[0].height}if(i)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:i/o.length,textHeight:l}}});if(e)return e;let t=document.createElement("div"),r,a,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=pu(t.firstChild)[0];r=t.getBoundingClientRect().height,a=o&&o.width?o.width/27:7,s=o&&o.height?o.height:r,t.remove()}),{lineHeight:r,charWidth:a,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let r=0,a=0;;a++){let s=a==t.viewports.length?null:t.viewports[a],o=s?s.from-1:this.view.state.doc.length;if(o>r){let i=(t.lineBlockAt(o).bottom-t.lineBlockAt(r).top)/this.view.scaleY;e.push(Ke.replace({widget:new yu(i),block:!0,inclusive:!0,isBlockGap:!0}).range(r,o))}if(!s)break;r=s.to+1}return Ke.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Xd).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,a=this.view.state.facet(Xm).map((s,o)=>{let i=typeof s=="function";return i&&(r=!0),i?s(this.view):s});for(a.length&&(this.dynamicDecorationMap[e++]=r,t.push(vt.join(a))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(wS).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let u=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=u.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let u of this.view.state.facet(xS))try{if(u(this.view,e.range,e))return!0}catch(c){ca(this.view.state,c,"scroll handler")}let{range:t}=e,r=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),a;if(!r)return;!t.empty&&(a=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(r={left:Math.min(r.left,a.left),top:Math.min(r.top,a.top),right:Math.max(r.right,a.right),bottom:Math.max(r.bottom,a.bottom)});let s=SS(this.view),o={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:i,offsetHeight:l}=this.view.scrollDOM;if(qM(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,i),-i),Math.max(Math.min(e.yMargin,l),-l),this.view.textDirection==zt.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(r.top>window.visualViewport.offsetTop+window.visualViewport.height||r.bottom<window.visualViewport.offsetTop)){let u=this.view.docView.lineAt(t.head,1);if(u){let c=Zk(u.dom);u.dom.scrollIntoView({block:"nearest"}),Qk(c,!1)}}}lineHasWidget(e){let t=r=>r.isWidget()||r.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){mm(this.tile)}};function mm(n,e){let t=e?.get(n);if(t!=1){t==null&&n.destroy();for(let r of n.children)mm(r,e)}}function cT(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function LS(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let r=nS(t.focusNode,t.focusOffset),a=rS(t.focusNode,t.focusOffset),s=r||a;if(a&&r&&a.node!=r.node){let i=Xt.get(a.node);if(!i||i.isText()&&i.text!=a.node.nodeValue)s=a;else if(n.docView.lastCompositionAfterCursor){let l=Xt.get(r.node);!l||l.isText()&&l.text!=r.node.nodeValue||(s=a)}}if(n.docView.lastCompositionAfterCursor=s!=r,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function dT(n,e,t){let r=LS(n,t);if(!r)return null;let{node:a,from:s,to:o}=r,i=a.nodeValue;if(/[\n\r]/.test(i)||n.state.doc.sliceString(r.from,r.to)!=i)return null;let l=e.invertedDesc;return{range:new da(l.mapPos(s),l.mapPos(o),s,o),text:a}}function fT(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}var hT=class{constructor(){this.changes=[]}compareRange(e,t){Fi(e,t,this.changes)}comparePoint(e,t){Fi(e,t,this.changes)}boundChange(e){Fi(e,e,this.changes)}};function pT(n,e,t){let r=new hT;return vt.compare(n,e,t,r),r.changes}var gm=class{constructor(){this.changes=[]}compareRange(e,t){Fi(e,t,this.changes)}comparePoint(){}boundChange(e){Fi(e,e,this.changes)}};function mT(n,e,t){let r=new gm;return vt.compare(n,e,t,r),r.changes}function gT(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function xT(n,e){let t=!1;return e&&n.iterChangedRanges((r,a)=>{r<e.to&&a>e.from&&(t=!0)}),t}var yu=class extends Rr{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function yT(n,e,t=1){let r=n.charCategorizer(e),a=n.doc.lineAt(e),s=e-a.from;if(a.length==0)return se.cursor(e);s==0?t=1:s==a.length&&(t=-1);let o=s,i=s;t<0?o=An(a.text,s,!1):i=An(a.text,s);let l=r(a.text.slice(o,i));for(;o>0;){let u=An(a.text,o,!1);if(r(a.text.slice(u,o))!=l)break;o=u}for(;i<a.length;){let u=An(a.text,i);if(r(a.text.slice(i,u))!=l)break;i=u}return se.undirectionalRange(o+a.from,i+a.from)}function bT(n,e,t,r,a){let s=Math.round((r-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let i=n.viewState.heightOracle.textHeight,l=Math.floor((a-t.top-(n.defaultLineHeight-i)*.5)/i);s+=l*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+fk(o,s,n.state.tabSize)}function xm(n,e,t){let r=n.lineBlockAt(e);if(Array.isArray(r.type)){let a;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!a||s.type==Fn.Text&&(a.type!=s.type||(t<0?s.from<e:s.to>e)))&&(a=s)}}return a||r}return r}function wT(n,e,t,r){let a=xm(n,e.head,e.assoc||-1),s=!r||a.type!=Fn.Text||!(n.lineWrapping||a.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>a.from?e.head-1:e.head);if(s){let o=n.dom.getBoundingClientRect(),i=n.textDirectionAt(a.from),l=n.posAtCoords({x:t==(i==zt.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(l!=null)return se.cursor(l,t?-1:1)}return se.cursor(t?a.to:a.from,t?-1:1)}function Ik(n,e,t,r){let a=n.state.doc.lineAt(e.head),s=n.bidiSpans(a),o=n.textDirectionAt(a.from);for(let i=e,l=null;;){let u=tT(a,s,o,i,t),c=lS;if(!u){if(a.number==(t?n.state.doc.lines:1))return i;c=`
|
|
39
|
+
`,a=n.state.doc.line(a.number+(t?1:-1)),s=n.bidiSpans(a),u=t?se.cursor(a.from,-1):se.cursor(a.to,1)}if(l){if(!l(c))return i}else{if(!r)return u;l=r(c)}i=u}}function vT(n,e,t){let r=n.state.charCategorizer(e),a=r(t);return s=>{let o=r(s);return a==la.Space&&(a=o),a==o}}function kT(n,e,t,r){let a=e.head,s=t?1:-1;if(a==(t?n.state.doc.length:0))return se.cursor(a,e.assoc);let o=e.goalColumn,i,l=n.contentDOM.getBoundingClientRect(),u=n.coordsAtPos(a,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=n.documentTop;if(u)o==null&&(o=u.left-l.left),i=s<0?u.top:u.bottom;else{let p=n.viewState.lineBlockAt(a);o==null&&(o=Math.min(l.right-l.left,n.defaultCharacterWidth*(a-p.from))),i=(s<0?p.top:p.bottom)+c}let d=l.left+o,f=n.viewState.heightOracle.textHeight>>1,h=r??f;for(let p=0;;p+=f){let m=i+(h+p)*s,g=ym(n,{x:d,y:m},!1,s);if(t?m>l.bottom:m<l.top)return se.cursor(g.pos,g.assoc);let x=n.coordsAtPos(g.pos,g.assoc),b=x?(x.top+x.bottom)/2:0;if(!x||(t?b>i:b<i))return se.cursor(g.pos,g.assoc,void 0,o)}}function bu(n,e,t){for(;;){let r=0;for(let a of n)a.between(e-1,e+1,(s,o,i)=>{if(e>s&&e<o){let l=r||t||(e-s<o-e?-1:1);e=l<0?s:o,r=l}});if(!r)return e}}function IS(n,e){let t=null;for(let r=0;r<e.ranges.length;r++){let a=e.ranges[r],s=null;if(a.empty){let o=bu(n,a.from,0);o!=a.from&&(s=se.cursor(o,-1))}else{let o=bu(n,a.from,-1),i=bu(n,a.to,1);(o!=a.from||i!=a.to)&&(a.undirectional?s=se.undirectionalRange(a.from,a.to):s=se.range(a.from==a.anchor?o:i,a.from==a.head?o:i))}s&&(t||(t=e.ranges.slice()),t[r]=s)}return t?se.create(t,e.mainIndex):e}function Yp(n,e,t){let r=bu(n.state.facet(Pu).map(a=>a(n)),t.from,e.head>t.from?-1:1);return r==t.from?t:se.cursor(r,r<t.from?1:-1)}var $r=class{constructor(e,t){this.pos=e,this.assoc=t}};function ym(n,e,t,r){let a=n.contentDOM.getBoundingClientRect(),s=a.top+n.viewState.paddingTop,{x:o,y:i}=e,l=i-s,u;for(;;){if(l<0)return new $r(0,1);if(l>n.viewState.docHeight)return new $r(n.state.doc.length,-1);if(u=n.elementAtHeight(l),r==null)break;if(u.type==Fn.Text){if(r<0?u.to<n.viewport.from:u.from>n.viewport.to)break;let f=n.docView.coordsAt(r<0?u.from:u.to,r>0?-1:1);if(f&&(r<0?f.top<=l+s:f.bottom>=l+s))break}let d=n.viewState.heightOracle.textHeight/2;l=r>0?u.bottom+d:u.top-d}if(n.viewport.from>=u.to||n.viewport.to<=u.from){if(t)return null;if(u.type==Fn.Text){let d=bT(n,a,u,o,i);return new $r(d,d==u.from?1:-1)}}if(u.type!=Fn.Text)return l<(u.top+u.bottom)/2?new $r(u.from,1):new $r(u.to,-1);let c=n.docView.lineAt(u.from,2);return(!c||c.length!=u.length)&&(c=n.docView.lineAt(u.from,-2)),new bm(n,o,i,n.textDirectionAt(u.from)).scanTile(c,u.from)}var bm=class{constructor(e,t,r,a){this.view=e,this.x=t,this.y=r,this.baseDir=a,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Kr.find(a,e-r.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:r,spans:a}=this.bidiSpansAt(e);return a[Kr.find(a,e-r.from,-1,t)].dir}bidiIn(e,t){let{spans:r,line:a}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+a.from<t)}scan(e,t,r=!1){let a=0,s=e.length-1,o=new Set,i=this.bidiIn(e[0],e[s]),l,u,c=-1,d=1e9,f;e:for(;a<s;){let p=s-a,m=a+s>>1;t:if(o.has(m)){for(let b=1;b<p;b++){let y=m+b;if(y>=s&&(y-=p),!o.has(y)){m=y;break t}}break e}o.add(m);let g=t(m),x=0;if(g)for(let b=0;b<g.length;b++){let y=g[b];if(!(y.width==0&&g.length>1))if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),x=1;else if(y.top>this.y)(!u||u.top>y.top)&&(u=y),x=-1;else{let N=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,L=Math.abs(N);L<d&&(c=m,d=L,f=y),N&&(x=N<0==(this.baseDir==zt.LTR)?-1:1)}}x==-1&&(!i||this.baseDirAt(e[m],1))?s=m:x==1&&(!i||this.baseDirAt(e[m+1],-1))&&(a=m+1)}if(!f){if(!u&&!l)return{i:0,after:!1};let p=l&&(!u||this.y-l.bottom<u.top-this.y)?l:u;return this.y=(p.top+p.bottom)/2,this.scan(e,t,!0)}if(d&&!r){let{top:p,bottom:m}=f;if(l&&l.bottom>(p+p+m)/3)return this.y=l.bottom-1,this.scan(e,t,!0);if(u&&u.top<(p+m+m)/3)return this.y=u.top+1,this.scan(e,t,!0)}let h=(i?this.dirAt(e[c],1):this.baseDir)==zt.LTR;return{i:c,after:this.x>(f.left+f.right)/2==h}}scanText(e,t){let r=[];for(let s=0;s<e.length;s=An(e.text,s))r.push(t+s);r.push(t+e.length);let a=this.scan(r,s=>{let o=r[s]-t,i=r[s+1]-t;return Au(e.dom,o,i).getClientRects()});return a.after?new $r(r[a.i+1],-1):new $r(r[a.i],1)}scanTile(e,t){if(!e.length)return new $r(t,1);if(e.children.length==1){let i=e.children[0];if(i.isText())return this.scanText(i,t);if(i.isComposite())return this.scanTile(i,t)}let r=[t];for(let i=0,l=t;i<e.children.length;i++)r.push(l+=e.children[i].length);let a=this.scan(r,i=>{let l=e.children[i];return l.flags&48?null:(l.dom.nodeType==1?l.dom:Au(l.dom,0,l.length)).getClientRects()}),s=e.children[a.i],o=r[a.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):a.after?new $r(r[a.i+1],-1):new $r(o,1)}},Ri="\uFFFF",wm=class{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Lt.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Ri}readRange(e,t){if(!e)return this;let r=e.parentNode;for(let a=e;;){this.findPointBefore(r,a);let s=this.text.length;this.readNode(a);let o=Xt.get(a),i=a.nextSibling;if(i==t){o?.breakAfter&&!i&&r!=this.view.contentDOM&&this.lineBreak();break}let l=Xt.get(i);(o&&l?o.breakAfter:(o?o.breakAfter:Od(a))||Od(i)&&(a.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!CT(i,t)&&this.lineBreak(),a=i}return this.findPointBefore(r,t),this}readTextNode(e){let t=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,t.length));for(let r=0,a=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,i;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,r),o=this.lineSeparator.length):(i=a.exec(t))&&(s=i.index,o=i[0].length),this.append(t.slice(r,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let l of this.points)l.node==e&&l.pos>this.text.length&&(l.pos-=o-1);r=s+o}}readNode(e){let t=Xt.get(e),r=t&&t.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let a=r.iter();!a.next().done;)a.lineBreak?this.lineBreak():this.append(a.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let r of this.points)r.node==e&&e.childNodes[r.offset]==t&&(r.pos=this.text.length)}findPointInside(e,t){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(ST(e,r.node,r.offset)?t:0))}};function ST(n,e,t){for(;;){if(!e||t<ls(e))return!1;if(e==n)return!0;t=Ws(e)+1,e=e.parentNode}}function CT(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let r=Xt.get(n);if(!r?.isWidget())return!1;r&&(t||(t=[])).push(r)}if(t)for(let r of t){let a=r.overrideDOMText;if(a?.length)return!1}return!0}var Ud=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},vm=class{constructor(e,t,r,a){this.typeOver=a,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView,i=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=AS(e.docView.tile,t,r,0))){let l=s||o?[]:IT(e),u=new wm(l,e);u.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=u.text,this.newSel=AT(l,this.bounds.from)}else{let l=e.observer.selectionRange,u=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!rm(e.contentDOM,l.focusNode)?i.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!rm(e.contentDOM,l.anchorNode)?i.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),d=e.viewport;if((ke.ios||ke.chrome)&&u!=c&&Math.min(u,c)<=i.main.from&&Math.max(u,c)>=i.main.to&&(d.from>0||d.to<e.state.doc.length)){let f=Math.min(u,c),h=Math.max(u,c),p=d.from-f,m=d.to-h;(p==0||p==1||f==0)&&(m==0||m==-1||h==e.state.doc.length)&&(u=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&i.ranges.length>1)this.newSel=i.replaceRange(se.range(c,u));else if(e.lineWrapping&&c==u&&!(i.main.empty&&i.main.head==u)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(u,-1),h=0;f&&(h=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=se.create([se.cursor(u,h)])}else this.newSel=se.single(c,u)}}};function AS(n,e,t,r){if(n.isComposite()){let a=-1,s=-1,o=-1,i=-1;for(let l=0,u=r,c=r;l<n.children.length;l++){let d=n.children[l],f=u+d.length;if(u<e&&f>t)return AS(d,e,t,u);if(f>=e&&a==-1&&(a=l,s=u),u>t&&d.dom.parentNode==n.dom){o=l,i=c;break}c=f,u=f+d.breakAfter}return{from:s,to:i<0?r+n.length:i,startDOM:(a?n.children[a-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:r,to:r+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function PS(n,e){let t,{newSel:r}=e,{state:a}=n,s=a.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:i,to:l}=e.bounds,u=s.from,c=null;(o===8||ke.android&&e.text.length<l-i)&&(u=s.to,c="end");let d=a.doc.sliceString(i,l,Ri),f,h;!s.empty&&s.from>=i&&s.to<=l&&(e.typeOver||d!=e.text)&&d.slice(0,s.from-i)==e.text.slice(0,s.from-i)&&d.slice(s.to-i)==e.text.slice(f=e.text.length-(d.length-(s.to-i)))?t={from:s.from,to:s.to,insert:it.of(e.text.slice(s.from-i,f).split(Ri))}:(h=NS(d,e.text,u-i,c))&&(ke.chrome&&o==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==Ri+Ri&&h.toB--,t={from:i+h.from,to:i+h.toA,insert:it.of(e.text.slice(h.from,h.toB).split(Ri))})}else r&&(!n.hasFocus&&a.facet(os)||Gd(r,s))&&(r=null);if(!t&&!r)return!1;if((ke.mac||ke.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(r&&t.insert.length==2&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:t.from,to:t.to,insert:it.of([t.insert.toString().replace("."," ")])}):a.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:a.toText(n.inputState.insertingText)}:ke.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
40
|
+
`&&n.lineWrapping&&(r&&(r=se.single(r.main.anchor-1,r.main.head-1)),t={from:s.from,to:s.to,insert:it.of([" "])}),t)return Ym(n,t,r,o);if(r&&!Gd(r,s)){let i=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(i=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=IS(a.facet(Pu).map(u=>u(n)),r))),n.dispatch({selection:r,scrollIntoView:i,userEvent:l}),!0}else return!1}function Ym(n,e,t,r=-1){if(ke.ios&&n.inputState.flushIOSKey(e))return!0;let a=n.state.selection.main;if(ke.android&&(e.to==a.to&&(e.from==a.from||e.from==a.from-1&&n.state.sliceDoc(e.from,a.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Ei(n.contentDOM,"Enter",13)||(e.from==a.from-1&&e.to==a.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>a.head)&&Ei(n.contentDOM,"Backspace",8)||e.from==a.from&&e.to==a.to+1&&e.insert.length==0&&Ei(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,i=()=>o||(o=LT(n,e,t));return n.state.facet(hS).some(l=>l(n,e.from,e.to,s,i))||n.dispatch(i()),!0}function LT(n,e,t){let r,a=n.state,s=a.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let l=e.from<s.from?-1:1,u=l<0?s.from:s.to,c=bu(a.facet(Pu).map(d=>d(n)),u,l);e.from==c&&(o=c)}if(o>-1)r={changes:e,selection:se.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=s.from<e.from?a.sliceDoc(s.from,e.from):"",u=s.to>e.to?a.sliceDoc(e.to,s.to):"";r=a.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+u))}else{let l=a.changes(e),u=t&&t.main.to<=l.newLength?t.main:void 0;if(a.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let c=n.state.sliceDoc(e.from,e.to),d,f=t&&LS(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);d={from:f.from,to:f.to-p}}else d=n.state.doc.lineAt(s.head);let h=s.to-e.to;r=a.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:l,range:u||p.map(l)};let m=p.to-h,g=m-c.length;if(n.state.sliceDoc(g,m)!=c||m>=d.from&&g<=d.to)return{range:p};let x=a.changes({from:g,to:m,insert:e.insert}),b=p.to-s.to;return{changes:x,range:u?se.range(Math.max(0,u.anchor+b),Math.max(0,u.head+b)):p.map(x)}})}else r={changes:l,selection:u&&a.selection.replaceRange(u)}}let i="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,i+=".compose",n.inputState.compositionFirstChange&&(i+=".start",n.inputState.compositionFirstChange=!1)),a.update(r,{userEvent:i,scrollIntoView:!0})}function NS(n,e,t,r){let a=Math.min(n.length,e.length),s=0;for(;s<a&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==a&&n.length==e.length)return null;let o=n.length,i=e.length;for(;o>0&&i>0&&n.charCodeAt(o-1)==e.charCodeAt(i-1);)o--,i--;if(r=="end"){let l=Math.max(0,s-Math.min(o,i));t-=o+l-s}if(o<s&&n.length<e.length){let l=t<=s&&t>=o?s-t:0;s-=l,i=s+(i-o),o=s}else if(i<s){let l=t<=s&&t>=i?s-t:0;s-=l,o=s+(o-i),i=s}return{from:s,toA:o,toB:i}}function IT(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new Ud(t,r)),(a!=t||s!=r)&&e.push(new Ud(a,s))),e}function AT(n,e){if(n.length==0)return null;let t=n[0].pos,r=n.length==2?n[1].pos:t;return t<0||r<0?null:t==r?se.create([se.cursor(r+e,-1)]):se.single(t+e,r+e)}function Gd(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}var km=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,ke.safari&&e.contentDOM.addEventListener("input",()=>null),ke.gecko&&zT(e.contentDOM.ownerDocument)}handleEvent(e){!ET(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let r=this.handlers[e];if(r){for(let a of r.observers)a(this.view,t);for(let a of r.handlers){if(t.defaultPrevented)break;if(a(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=NT(e),r=this.handlers,a=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,i=r[s];i&&o!=!i.handlers.length&&(a.removeEventListener(s,this.handleEvent),i=null),i||a.addEventListener(s,this.handleEvent,{passive:o})}for(let s in r)s!="scroll"&&!t[s]&&a.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&MS.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),ke.android&&ke.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(ke.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(RS.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||RT.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&ke.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&PT(this.view.win)&&(t.shiftKey=!1);let r=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==r&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Ei(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:ke.safari&&!ke.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function PT(n){return n.visualViewport?n.visualViewport.height*n.visualViewport.scale/n.document.documentElement.clientHeight<.85:!1}function Ak(n,e){return(t,r)=>{try{return e.call(n,r,t)}catch(a){ca(t.state,a)}}}function NT(n){let e=Object.create(null);function t(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of n){let a=r.spec,s=a&&a.plugin.domEventHandlers,o=a&&a.plugin.domEventObservers;if(s)for(let i in s){let l=s[i];l&&t(i).handlers.push(Ak(r.value,l))}if(o)for(let i in o){let l=o[i];l&&t(i).observers.push(Ak(r.value,l))}}for(let r in fa)t(r).handlers.push(fa[r]);for(let r in nr)t(r).observers.push(nr[r]);return e}var RS=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],RT="dthko",MS=[16,17,18,20,91,92,224,225],Ld=6;function Id(n){return Math.max(0,n)*.7+8}function MT(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}var Sm=class{constructor(e,t,r,a){this.view=e,this.startEvent=t,this.style=r,this.mustSelect=a,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Jk(e.contentDOM),this.atoms=e.state.facet(Pu).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Lt.allowMultipleSelections)&&TT(e,t),this.dragging=FT(e,t)&&FS(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&MT(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,r=0,a=0,s=0,o=this.view.win.innerWidth,i=this.view.win.innerHeight;this.scrollParents.x&&({left:a,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:i}=this.scrollParents.y.getBoundingClientRect());let l=SS(this.view);e.clientX-l.left<=a+Ld?t=-Id(a-e.clientX):e.clientX+l.right>=o-Ld&&(t=Id(e.clientX-o)),e.clientY-l.top<=s+Ld?r=-Id(s-e.clientY):e.clientY+l.bottom>=i-Ld&&(r=Id(e.clientY-i)),this.setScrollSpeed(t,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,r=IS(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function TT(n,e){let t=n.state.facet(uS);return t.length?t[0](e):ke.mac?e.metaKey:e.ctrlKey}function DT(n,e){let t=n.state.facet(cS);return t.length?t[0](e):ke.mac?!e.altKey:!e.ctrlKey}function FT(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let r=Lu(n.root);if(!r||r.rangeCount==0)return!0;let a=r.getRangeAt(0).getClientRects();for(let s=0;s<a.length;s++){let o=a[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function ET(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,r;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(r=Xt.get(t))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}var fa=Object.create(null),nr=Object.create(null),TS=ke.ie&&ke.ie_version<15||ke.ios&&ke.webkit_version<604;function OT(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),DS(n,t.value)},50)}function Yd(n,e,t){for(let r of n.facet(e))t=r(t,n);return t}function DS(n,e){e=Yd(n.state,Vm,e);let{state:t}=n,r,a=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(Cm!=null&&t.selection.ranges.every(l=>l.empty)&&Cm==s.toString()){let l=-1;r=t.changeByRange(u=>{let c=t.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let d=t.toText((o?s.line(a++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:d},range:se.cursor(u.from+d.length,-1)}})}else o?r=t.changeByRange(l=>{let u=s.line(a++);return{changes:{from:l.from,to:l.to,insert:u.text},range:se.cursor(l.from+u.length,-1)}}):r=t.replaceSelection(s);n.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}nr.scroll=n=>{let e=n.inputState;e.lastScrollTop=n.scrollDOM.scrollTop,e.lastScrollLeft=n.scrollDOM.scrollLeft,ke.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};nr.wheel=nr.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};fa.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);nr.touchstart=(n,e)=>{let t=n.inputState,r=e.targetTouches[0];t.touchActive=!0,t.lastTouchTime=Date.now(),r&&(t.lastTouchX=r.clientX,t.lastTouchY=r.clientY),t.setSelectionOrigin("select.pointer")};nr.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};nr.touchend=(n,e)=>{n.inputState.touchActive=!1};fa.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let r of n.state.facet(dS))if(t=r(n,e),t)break;if(!t&&e.button==0&&(t=_T(n,e)),t){let r=!n.hasFocus;n.inputState.startMouseSelection(new Sm(n,e,t,r)),r&&n.observer.ignore(()=>{eS(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let a=n.inputState.mouseSelection;if(a)return a.start(e),a.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Pk(n,e,t,r){if(r==1)return se.cursor(e,t);if(r==2)return yT(n.state,e,t);{let a=n.docView.lineAt(e,t),s=n.state.doc.lineAt(a?a.posAtEnd:e),o=a?a.posAtStart:s.from,i=a?a.posAtEnd:s.to;return i<n.state.doc.length&&i==s.to&&i++,se.undirectionalRange(o,i)}}var BT=ke.ie&&ke.ie_version<=11,Nk=null,Rk=0,Mk=0;function FS(n){if(!BT)return n.detail;let e=Nk,t=Mk;return Nk=n,Mk=Date.now(),Rk=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Rk+1)%3:1}function _T(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=FS(e),a=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),a=a.map(s.changes))},get(s,o,i){let l=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),u,c=Pk(n,l.pos,l.assoc,r);if(t.pos!=l.pos&&!o){let d=Pk(n,t.pos,t.assoc,r),f=Math.min(d.from,c.from),h=Math.max(d.to,c.to);c=f<c.from?se.range(f,h,c.assoc):se.range(h,f,c.assoc)}return o?a.replaceRange(a.main.extend(c.from,c.to,c.assoc)):i&&r==1&&a.ranges.length>1&&(u=HT(a,l.pos))?u:i?a.addRange(c):se.create([c])}}}function HT(n,e){for(let t=0;t<n.ranges.length;t++){let{from:r,to:a}=n.ranges[t];if(r<=e&&a>=e)return se.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}fa.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let a=n.docView.tile.nearest(e.target);if(a&&a.isWidget()){let s=a.posAtStart,o=s+a.length;(s>=t.to||o<=t.from)&&(t=se.undirectionalRange(s,o))}}let{inputState:r}=n;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Yd(n.state,$m,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};fa.dragend=n=>(n.inputState.draggedContent=null,!1);function Tk(n,e,t,r){if(t=Yd(n.state,Vm,t),!t)return;let a=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,o=r&&s&&DT(n,e)?{from:s.from,to:s.to}:null,i={from:a,insert:t},l=n.state.changes(o?[o,i]:i);n.focus(),n.dispatch({changes:l,selection:{anchor:l.mapPos(a,-1),head:l.mapPos(a,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}fa.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let r=Array(t.length),a=0,s=()=>{++a==t.length&&Tk(n,e,r.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let i=new FileReader;i.onerror=s,i.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(i.result)||(r[o]=i.result),s()},i.readAsText(t[o])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Tk(n,e,r,!0),!0}return!1};fa.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=TS?null:e.clipboardData;return t?(DS(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(OT(n),!1)};function UT(n,e){let t=n.dom.parentNode;if(!t)return;let r=t.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),n.focus()},50)}function GT(n){let e=[],t=[],r=!1;for(let a of n.selection.ranges)a.empty||(e.push(n.sliceDoc(a.from,a.to)),t.push(a));if(!e.length){let a=-1;for(let{from:s}of n.selection.ranges){let o=n.doc.lineAt(s);o.number>a&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),a=o.number}r=!0}return{text:Yd(n,$m,e.join(n.lineBreak)),ranges:t,linewise:r}}var Cm=null;fa.copy=fa.cut=(n,e)=>{if(!hu(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:r,linewise:a}=GT(n.state);if(!t&&!a)return!1;Cm=a?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=TS?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(UT(n,t),!1)};var ES=qr.define();function OS(n,e){let t=[];for(let r of n.facet(pS)){let a=r(n,e);a&&t.push(a)}return t.length?n.update({effects:t,annotations:ES.of(!0)}):null}function BS(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=OS(n.state,e);t?n.dispatch(t):n.update([])}},10)}nr.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),BS(n)};nr.blur=n=>{n.observer.clearSelectionRange(),BS(n)};nr.compositionstart=nr.compositionupdate=n=>{if(!n.observer.editContext&&(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0)){let{main:e}=n.state.selection;!e.empty&&n.lineBlockAt(e.from).from!=n.lineBlockAt(e.to).from&&n.dispatch({changes:n.state.selection.ranges.filter(t=>!t.empty).map(t=>({from:t.from,to:t.to})),userEvent:"input"}),n.inputState.composing=0}};nr.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,ke.chrome&&ke.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};nr.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};fa.beforeinput=(n,e)=>{var t,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let i=o[0],l=n.posAtDOM(i.startContainer,i.startOffset),u=n.posAtDOM(i.endContainer,i.endOffset);return Ym(n,{from:l,to:u,insert:n.state.toText(s)},null),!0}}let a;if(ke.chrome&&ke.android&&(a=RS.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(a.key,a.keyCode),a.key=="Backspace"||a.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return ke.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),ke.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>nr.compositionend(n,e),20),!1};var Dk=new Set;function zT(n){Dk.has(n)||(Dk.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}var Fk=["pre-wrap","normal","pre-line","break-spaces"],Ui=!1;function Ek(){Ui=!1}var Lm=class{constructor(e){this.lineWrapping=e,this.doc=it.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let r=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((t-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Fk.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let r=0;r<e.length;r++){let a=e[r];a<0?r++:this.heightSamples[Math.floor(a*10)]||(t=!0,this.heightSamples[Math.floor(a*10)]=!0)}return t}refresh(e,t,r,a,s,o){let i=Fk.indexOf(e)>-1,l=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=i;if(this.lineWrapping=i,this.lineHeight=t,this.charWidth=r,this.textHeight=a,this.lineLength=s,l){this.heightSamples={};for(let u=0;u<o.length;u++){let c=o[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}},Im=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},ua=class n{constructor(e,t,r,a,s){this.from=e,this.length=t,this.top=r,this.height=a,this._content=s}get type(){return typeof this._content=="number"?Fn.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Mo?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new n(this.from,this.length+e.length,this.top,this.height+e.height,t)}},Gt=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(Gt||(Gt={})),Md=.001,Nr=class n{constructor(e,t,r=2){this.length=e,this.height=t,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Md&&(Ui=!0),this.height=e)}replace(e,t,r){return n.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,r,a){let s=this,o=r.doc;for(let i=a.length-1;i>=0;i--){let{fromA:l,toA:u,fromB:c,toB:d}=a[i],f=s.lineAt(l,Gt.ByPosNoHeight,r.setDoc(t),0,0),h=f.to>=u?f:s.lineAt(u,Gt.ByPosNoHeight,r,0,0);for(d+=h.to-u,u=h.to;i>0&&f.from<=a[i-1].toA;)l=a[i-1].fromA,c=a[i-1].fromB,i--,l<f.from&&(f=s.lineAt(l,Gt.ByPosNoHeight,r,0,0));c+=f.from-l,l=f.from;let p=Pm.build(r.setDoc(o),e,c,d);s=zd(s,s.replace(l,u,p))}return s.updateHeight(r,0)}static empty(){return new Vr(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,r=e.length,a=0,s=0;for(;;)if(t==r)if(a>s*2){let i=e[t-1];i.break?e.splice(--t,1,i.left,null,i.right):e.splice(--t,1,i.left,i.right),r+=1+i.break,a-=i.size}else if(s>a*2){let i=e[r];i.break?e.splice(r,1,i.left,null,i.right):e.splice(r,1,i.left,i.right),r+=2+i.break,s-=i.size}else break;else if(a<s){let i=e[t++];i&&(a+=i.size)}else{let i=e[--r];i&&(s+=i.size)}let o=!1;return e[t-1]==null?(o=!0,t--):e[t]==null&&(o=!0,r++),new Am(n.of(e.slice(0,t)),o,n.of(e.slice(r)))}};function zd(n,e){return n==e?n:(n.constructor!=e.constructor&&(Ui=!0),e)}Nr.prototype.size=1;var WT=Ke.replace({}),Wd=class extends Nr{constructor(e,t,r){super(e,t),this.deco=r,this.spaceAbove=0}mainBlock(e,t){return new ua(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,r,a){return this.spaceAbove&&e<r+this.spaceAbove?new ua(a,0,r,this.spaceAbove,WT):this.mainBlock(r,a)}lineAt(e,t,r,a,s){let o=this.mainBlock(a,s);return this.spaceAbove?this.blockAt(0,r,a,s).join(o):o}forEachLine(e,t,r,a,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,Gt.ByPos,r,a,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more&&this.setMeasuredHeight(a),this.outdated=!1,this}toString(){return`block(${this.length})`}},Vr=class n extends Wd{constructor(e,t,r){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,t){return new ua(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,r){let a=r[0];return r.length==1&&(a instanceof n||a instanceof zs&&a.flags&4)&&Math.abs(this.length-a.length)<10?(a instanceof zs?a=new n(a.length,this.height,this.spaceAbove):a.height=this.height,this.outdated||(a.outdated=!1),a):Nr.of(r)}updateHeight(e,t=0,r=!1,a){return a&&a.from<=t&&a.more?this.setMeasuredHeight(a):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},zs=class n extends Nr{constructor(e){super(e,0)}heightMetrics(e,t){let r=e.doc.lineAt(t).number,a=e.doc.lineAt(t+this.length).number,s=a-r+1,o,i=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*s);o=l/s,this.length>s+1&&(i=(this.height-l)/(this.length-s-1))}else o=this.height/s;return{firstLine:r,lastLine:a,perLine:o,perChar:i}}blockAt(e,t,r,a){let{firstLine:s,lastLine:o,perLine:i,perChar:l}=this.heightMetrics(t,a);if(t.lineWrapping){let u=a+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=t.doc.lineAt(u),d=i+c.length*l,f=Math.max(r,e-d/2);return new ua(c.from,c.length,f,d,0)}else{let u=Math.max(0,Math.min(o-s,Math.floor((e-r)/i))),{from:c,length:d}=t.doc.line(s+u);return new ua(c,d,r+i*u,i,0)}}lineAt(e,t,r,a,s){if(t==Gt.ByHeight)return this.blockAt(e,r,a,s);if(t==Gt.ByPosNoHeight){let{from:h,to:p}=r.doc.lineAt(e);return new ua(h,p-h,0,0,0)}let{firstLine:o,perLine:i,perChar:l}=this.heightMetrics(r,s),u=r.doc.lineAt(e),c=i+u.length*l,d=u.number-o,f=a+i*d+l*(u.from-s-d);return new ua(u.from,u.length,Math.max(a,Math.min(f,a+this.height-c)),c,0)}forEachLine(e,t,r,a,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:i,perLine:l,perChar:u}=this.heightMetrics(r,s);for(let c=e,d=a;c<=t;){let f=r.doc.lineAt(c);if(c==e){let p=f.number-i;d+=l*p+u*(e-s-p)}let h=l+u*f.length;o(new ua(f.from,f.length,d,h,0)),d+=h,c=f.to+1}}replace(e,t,r){let a=this.length-t;if(a>0){let s=r[r.length-1];s instanceof n?r[r.length-1]=new n(s.length+a):r.push(null,new n(a-1))}if(e>0){let s=r[0];s instanceof n?r[0]=new n(e+s.length):r.unshift(new n(e-1),null)}return Nr.of(r)}decomposeLeft(e,t){t.push(new n(e-1),null)}decomposeRight(e,t){t.push(null,new n(this.length-e-1))}updateHeight(e,t=0,r=!1,a){let s=t+this.length;if(a&&a.from<=t+this.length&&a.more){let o=[],i=Math.max(t,a.from),l=-1;for(a.from>t&&o.push(new n(a.from-t-1).updateHeight(e,t));i<=s&&a.more;){let c=e.doc.lineAt(i).length;o.length&&o.push(null);let d=a.heights[a.index++],f=0;d<0&&(f=-d,d=a.heights[a.index++]),l==-1?l=d:Math.abs(d-l)>=Md&&(l=-2);let h=new Vr(c,d,f);h.outdated=!1,o.push(h),i+=c+1}i<=s&&o.push(null,new n(s-i).updateHeight(e,i));let u=Nr.of(o);return(l<0||Math.abs(u.height-this.height)>=Md||Math.abs(l-this.heightMetrics(e,t).perLine)>=Md)&&(Ui=!0),zd(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Am=class extends Nr{constructor(e,t,r){super(e.length+(t?1:0)+r.length,e.height+r.height,(t?1:0)|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,t,r,a){let s=r+this.left.height;return e<s?this.left.blockAt(e,t,r,a):this.right.blockAt(e,t,s,a+this.left.length+this.break)}lineAt(e,t,r,a,s){let o=a+this.left.height,i=s+this.left.length+this.break,l=t==Gt.ByHeight?e<o:e<i,u=l?this.left.lineAt(e,t,r,a,s):this.right.lineAt(e,t,r,o,i);if(this.break||(l?u.to<i:u.from>i))return u;let c=t==Gt.ByPosNoHeight?Gt.ByPosNoHeight:Gt.ByPos;return l?u.join(this.right.lineAt(i,c,r,o,i)):this.left.lineAt(i,c,r,a,s).join(u)}forEachLine(e,t,r,a,s,o){let i=a+this.left.height,l=s+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,t,r,a,s,o),t>=l&&this.right.forEachLine(e,t,r,i,l,o);else{let u=this.lineAt(l,Gt.ByPos,r,a,s);e<u.from&&this.left.forEachLine(e,Math.min(t,u.from-1),r,a,s,o),u.to>=e&&u.from<=t&&o(u),t>u.to&&this.right.forEachLine(Math.max(e,u.to+1),t,r,i,l,o)}}replace(e,t,r){let a=this.left.length+this.break;if(t<a)return this.balanced(this.left.replace(e,t,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-a,t-a,r));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let i of r)s.push(i);if(e>0&&Ok(s,o-1),t<this.length){let i=s.length;this.decomposeRight(t,s),Ok(s,i)}return Nr.of(s)}decomposeLeft(e,t){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(r++,e>=r&&t.push(null)),e>r&&this.right.decomposeLeft(e-r,t)}decomposeRight(e,t){let r=this.left.length,a=r+this.break;if(e>=a)return this.right.decomposeRight(e-a,t);e<r&&this.left.decomposeRight(e,t),this.break&&e<a&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Nr.of(this.break?[e,null,t]:[e,t]):(this.left=zd(this.left,e),this.right=zd(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,r=!1,a){let{left:s,right:o}=this,i=t+s.length+this.break,l=null;return a&&a.from<=t+s.length&&a.more?l=s=s.updateHeight(e,t,r,a):s.updateHeight(e,t,r),a&&a.from<=i+o.length&&a.more?l=o=o.updateHeight(e,i,r,a):o.updateHeight(e,i,r),l?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Ok(n,e){let t,r;n[e]==null&&(t=n[e-1])instanceof zs&&(r=n[e+1])instanceof zs&&n.splice(e-1,3,new zs(t.length+1+r.length))}var jT=5,Pm=class n{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let r=Math.min(t,this.lineEnd),a=this.nodes[this.nodes.length-1];a instanceof Vr?a.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new Vr(r-this.pos,-1,0)),this.writtenTo=r,t>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,r){if(e<t||r.heightRelevant){let a=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;a<0&&(a=this.oracle.lineHeight);let o=t-e;r.block?this.addBlock(new Wd(o,a,r)):(o||s||a>=jT)&&this.addLineDeco(a,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Vr(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let r=new zs(t-e);return this.oracle.doc.lineAt(e).to==t&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Vr)return e;let t=new Vr(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,r){let a=this.ensureLine();a.length+=r,a.collapsed+=r,a.widgetHeight=Math.max(a.widgetHeight,e),a.breaks+=t,this.writtenTo=this.pos=this.pos+r}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Vr)&&!this.isCovered?this.nodes.push(new Vr(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let a of this.nodes)a instanceof Vr&&a.updateHeight(this.oracle,r),r+=a?a.length:1;return this.nodes}static build(e,t,r,a){let s=new n(r,e);return vt.spans(t,r,a,s,0),s.finish(r)}};function qT(n,e,t){let r=new Nm;return vt.compare(n,e,t,r,0),r.changes}var Nm=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,r,a){(e<t||r&&r.heightRelevant||a&&a.heightRelevant)&&Fi(e,t,this.changes,5)}};function VT(n,e){let t=n.getBoundingClientRect(),r=n.ownerDocument,a=r.defaultView||window,s=Math.max(0,t.left),o=Math.min(a.innerWidth,t.right),i=Math.max(0,t.top),l=Math.min(a.innerHeight,t.bottom);for(let u=n.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,d=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&d.overflow!="visible"){let f=c.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),i=Math.max(i,f.top),l=Math.min(u==n.parentNode?a.innerHeight:l,f.bottom)}u=d.position=="absolute"||d.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:i-(t.top+e),bottom:Math.max(i,l)-(t.top+e)}}function $T(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function KT(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var wu=class{constructor(e,t,r,a){this.from=e,this.to=t,this.size=r,this.displaySize=a}static same(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++){let a=e[r],s=t[r];if(a.from!=s.from||a.to!=s.to||a.size!=s.size)return!1}return!0}draw(e,t){return Ke.replace({widget:new Rm(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},Rm=class extends Rr{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}},jd=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Bk,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=zt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=t.facet(Km).some(a=>typeof a!="function"&&a.class=="cm-lineWrapping");this.heightOracle=new Lm(r),this.stateDeco=_k(t),this.heightMap=Nr.empty().applyChanges(this.stateDeco,it.empty,this.heightOracle.setDoc(t.doc),[new da(0,0,0,t.doc.length)]);for(let a=0;a<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());a++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ke.set(this.lineGaps.map(a=>a.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let r=0;r<=1;r++){let a=r?t.head:t.anchor;if(!e.some(({from:s,to:o})=>a>=s&&a<=o)){let{from:s,to:o}=this.lineBlockAt(a);e.push(new Ti(s,o))}}return this.viewports=e.sort((r,a)=>r.from-a.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Bk:new Mm(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(fu(e,this.scaler))})}update(e,t=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=_k(this.state);let a=e.changedRanges,s=da.extendWithRanges(a,qT(r,this.stateDeco,e?e.changes:Pn.empty(this.state.doc.length))),o=this.heightMap.height,i=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ek(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||Ui)&&(e.flags|=2),i?(this.scrollAnchorPos=e.changes.mapPos(i.from,-1),this.scrollAnchorHeight=i.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<l.from||t.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(gS)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,r=window.getComputedStyle(t),a=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?zt.RTL:zt.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",i=t.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=i.height;this.contentDOMHeight=i.height,this.mustMeasureContent=!1;let u=0,c=0;if(i.width&&i.height){let{scaleX:L,scaleY:A}=Yk(t,i);(L>.005&&Math.abs(this.scaleX-L)>.005||A>.005&&Math.abs(this.scaleY-A)>.005)&&(this.scaleX=L,this.scaleY=A,u|=16,o=l=!0)}let d=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=d||this.paddingBottom!=f)&&(this.paddingTop=d,this.paddingBottom=f,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(a.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let h=Jk(this.view.contentDOM,!1).y;h!=this.scrollParent&&(this.scrollParent=h,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=tS(this.scrollParent||e.win);let m=(this.printing?KT:VT)(t,this.paddingTop),g=m.top-this.pixelViewport.top,x=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(l=!0)),!this.inView&&!this.scrollTarget&&!$T(e.dom))return 0;let y=i.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=i.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let L=e.docView.measureVisibleLineHeights(this.viewport);if(a.mustRefreshForHeights(L)&&(o=!0),o||a.lineWrapping&&Math.abs(y-this.contentDOMWidth)>a.charWidth){let{lineHeight:A,charWidth:w,textHeight:v}=e.docView.measureTextSize();o=A>0&&a.refresh(s,A,w,v,Math.max(5,y/w),L),o&&(e.docView.minWidth=0,u|=16)}g>0&&x>0?c=Math.max(g,x):g<0&&x<0&&(c=Math.min(g,x)),Ek();for(let A of this.viewports){let w=A.from==this.viewport.from?L:e.docView.measureVisibleLineHeights(A);this.heightMap=(o?Nr.empty().applyChanges(this.stateDeco,it.empty,this.heightOracle,[new da(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(a,0,o,new Im(A.from,w))}Ui&&(u|=2)}let N=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return N&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||N)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),a=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:i}=this,l=new Ti(a.lineAt(o-r*1e3,Gt.ByHeight,s,0,0).from,a.lineAt(i+(1-r)*1e3,Gt.ByHeight,s,0,0).to);if(t){let{head:u}=t.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=a.lineAt(u,Gt.ByPos,s,0,0),f;t.y=="center"?f=(d.top+d.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&u<l.from?f=d.top:f=d.bottom-c,l=new Ti(a.lineAt(f-1e3/2,Gt.ByHeight,s,0,0).from,a.lineAt(f+c+1e3/2,Gt.ByHeight,s,0,0).to)}}return l}mapViewport(e,t){let r=t.mapPos(e.from,-1),a=t.mapPos(e.to,1);return new Ti(this.heightMap.lineAt(r,Gt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(a,Gt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},r=0){if(!this.inView)return!0;let{top:a}=this.heightMap.lineAt(e,Gt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,Gt.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:i}=this;return(e==0||a<=o-Math.max(10,Math.min(-r,250)))&&(t==this.state.doc.length||s>=i+Math.max(10,Math.min(r,250)))&&a>o-2*1e3&&s<i+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let r=[];for(let a of e)t.touchesRange(a.from,a.to)||r.push(new wu(t.mapPos(a.from),t.mapPos(a.to),a.size,a.displaySize));return r}ensureLineGaps(e,t){let r=this.heightOracle.lineWrapping,a=r?1e4:2e3,s=a>>1,o=a<<1;if(this.defaultTextDirection!=zt.LTR&&!r)return[];let i=[],l=(c,d,f,h)=>{if(d-c<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let x of m)if(x>c&&x<d){l(c,x-10,f,h),l(x+10,d,f,h);return}let g=YT(e,x=>x.from>=f.from&&x.to<=f.to&&Math.abs(x.from-c)<s&&Math.abs(x.to-d)<s&&!m.some(b=>x.from<b&&x.to>b));if(!g){if(d<f.to&&t&&r&&t.visibleRanges.some(y=>y.from<=d&&y.to>=d)){let y=t.moveToLineBoundary(se.cursor(d),!1,!0).head;y>c&&(d=y)}let x=this.gapSize(f,c,d,h),b=r||x<2e6?x:2e6;g=new wu(c,d,x,b)}i.push(g)},u=c=>{if(c.length<o||c.type!=Fn.Text)return;let d=XT(c.from,c.to,this.stateDeco);if(d.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,h,p;if(r){let m=a/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,x;if(f!=null){let b=Pd(d,f),y=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=b-y,x=b+y}else g=(this.visibleTop-c.top-m)/c.height,x=(this.visibleBottom-c.top+m)/c.height;h=Ad(d,g),p=Ad(d,x)}else{let m=d.total*this.heightOracle.charWidth,g=a*this.heightOracle.charWidth,x=0;if(m>2e6)for(let A of e)A.from>=c.from&&A.from<c.to&&A.size!=A.displaySize&&A.from*this.heightOracle.charWidth+x<this.pixelViewport.left&&(x=A.size-A.displaySize);let b=this.pixelViewport.left+x,y=this.pixelViewport.right+x,N,L;if(f!=null){let A=Pd(d,f),w=((y-b)/2+g)/m;N=A-w,L=A+w}else N=(b-g)/m,L=(y+g)/m;h=Ad(d,N),p=Ad(d,L)}h>c.from&&l(c.from,h,c,d),p<c.to&&l(p,c.to,c,d)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return i}gapSize(e,t,r,a){let s=Pd(a,r)-Pd(a,t);return this.heightOracle.lineWrapping?e.height*s:a.total*this.heightOracle.charWidth*s}updateLineGaps(e){wu.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Ke.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let r=[];vt.spans(t,this.viewport.from,this.viewport.to,{span(s,o){r.push({from:s,to:o})},point(){}},20);let a=0;if(r.length!=this.visibleRanges.length)a=12;else for(let s=0;s<r.length&&!(a&8);s++){let o=this.visibleRanges[s],i=r[s];(o.from!=i.from||o.to!=i.to)&&(a|=4,e&&e.mapPos(o.from,-1)==i.from&&e.mapPos(o.to,1)==i.to||(a|=8))}return this.visibleRanges=r,a}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||fu(this.heightMap.lineAt(e,Gt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||fu(this.heightMap.lineAt(this.scaler.fromDOM(e),Gt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return fu(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Ti=class{constructor(e,t){this.from=e,this.to=t}};function XT(n,e,t){let r=[],a=n,s=0;return vt.spans(t,n,e,{span(){},point(o,i){o>a&&(r.push({from:a,to:o}),s+=o-a),a=i}},20),a<e&&(r.push({from:a,to:e}),s+=e-a),{total:s,ranges:r}}function Ad({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let r=Math.floor(n*t);for(let a=0;;a++){let{from:s,to:o}=e[a],i=o-s;if(r<=i)return s+r;r-=i}}function Pd(n,e){let t=0;for(let{from:r,to:a}of n.ranges){if(e<=a){t+=e-r;break}t+=a-r}return t/n.total}function YT(n,e){for(let t of n)if(e(t))return t}var Bk={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function _k(n){let e=n.facet(Xd).filter(r=>typeof r!="function"),t=n.facet(Xm).filter(r=>typeof r!="function");return t.length&&e.push(vt.join(t)),e}var Mm=class n{constructor(e,t,r){let a=0,s=0,o=0;this.viewports=r.map(({from:i,to:l})=>{let u=t.lineAt(i,Gt.ByPos,e,0,0).top,c=t.lineAt(l,Gt.ByPos,e,0,0).bottom;return a+=c-u,{from:i,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-a)/(t.height-a);for(let i of this.viewports)i.domTop=o+(i.top-s)*this.scale,o=i.domBottom=i.domTop+(i.bottom-i.top),s=i.bottom}toDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return a+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,a=s.domBottom}}fromDOM(e){for(let t=0,r=0,a=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return r+(e-a)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,a=s.domBottom}}eq(e){return e instanceof n?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,r)=>t.from==e.viewports[r].from&&t.to==e.viewports[r].to):!1}};function fu(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),r=e.toDOM(n.bottom);return new ua(n.from,n.length,t,r-t,Array.isArray(n._content)?n._content.map(a=>fu(a,e)):n._content)}var Nd=Ne.define({combine:n=>n.join(" ")}),Tm=Ne.define({combine:n=>n.indexOf(!0)>-1}),Dm=fr.newName(),_S=fr.newName(),HS=fr.newName(),US={"&light":"."+_S,"&dark":"."+HS};function Fm(n,e,t){return new fr(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,a=>{if(a=="&")return n;if(!t||!t[a])throw new RangeError(`Unsupported selector: ${a}`);return t[a]}):n+" "+r}})}var JT=Fm("."+Dm,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{background:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat",backgroundSize:".4em",backgroundPosition:"calc(min(50%, 0px)) center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},US),ZT={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Jp=ke.ie&&ke.ie_version<=11,Em=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new am,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let r of t)this.queue.push(r);(ke.ie&&ke.ie_version<=11||ke.ios&&e.composing)&&t.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&ke.android&&e.constructor.EDIT_CONTEXT!==!1&&!(ke.chrome&&ke.chrome_version<126)&&(this.editContext=new Om(e),e.state.facet(os)&&(e.contentDOM.editContext=this.editContext.editContext)),Jp&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,r)=>t!=e[r]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,a=this.selectionRange;if(r.state.facet(os)?r.root.activeElement!=this.dom:!hu(this.dom,a))return;let s=a.anchorNode&&r.docView.tile.nearest(a.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(ke.ie&&ke.ie_version<=11||ke.android&&ke.chrome)&&!r.state.selection.main.empty&&a.focusNode&&mu(a.focusNode,a.focusOffset,a.anchorNode,a.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Lu(e.root);if(!t)return!1;let r=ke.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&QT(this.view,t)||t;if(!r||this.selectionRange.eq(r))return!1;let a=hu(this.dom,r);return a&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&$M(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),a&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let r=this.dom;r;)if(r.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=t)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,ZT),Jp&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Jp&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var r;if(!this.delayedAndroidKey){let a=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&Ei(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(a)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,r=-1,a=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(a=!0),t==-1?{from:t,to:r}=o:(t=Math.min(o.from,t),r=Math.max(o.to,r)))}return{from:t,to:r,typeOver:a}}readChange(){let{from:e,to:t,typeOver:r}=this.processRecords(),a=this.selectionChanged&&hu(this.dom,this.selectionRange);if(e<0&&!a)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new vm(this.view,e,t,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let r=this.view.state,a=PS(this.view,t);return this.view.state==r&&(t.domChanged||t.newSel&&!Gd(this.view.state.selection,t.newSel.main))&&this.view.update([]),a}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let r=Hk(t,e.previousSibling||e.target.previousSibling,-1),a=Hk(t,e.nextSibling||e.target.nextSibling,1);return{from:r?t.posAfter(r):t.posAtStart,to:a?t.posBefore(a):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(os)!=e.state.facet(os)&&(e.view.contentDOM.editContext=e.state.facet(os)?this.editContext.editContext:null))}destroy(){var e,t,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let a of this.scrollTargets)a.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Hk(n,e,t){for(;e;){let r=Xt.get(e);if(r&&r.parent==n)return r;let a=e.parentNode;e=a!=n.dom?a:t>0?e.nextSibling:e.previousSibling}return null}function Uk(n,e){let t=e.startContainer,r=e.startOffset,a=e.endContainer,s=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return mu(o.node,o.offset,a,s)&&([t,r,a,s]=[a,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:s}}function QT(n,e){if(e.getComposedRanges){let a=e.getComposedRanges(n.root)[0];if(a)return Uk(n,a)}let t=null;function r(a){a.preventDefault(),a.stopImmediatePropagation(),t=a.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",r,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",r,!0),t?Uk(n,t):null}var Om=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let a=e.state.selection.main,{anchor:s,head:o}=a,i=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:i,drifted:!1});let u=l-i>r.text.length;i==this.from&&s<this.from?i=s:l==this.to&&s>this.to&&(l=s);let c=NS(e.state.sliceDoc(i,l),r.text,(u?a.from:a.to)-i,u?"end":null);if(!c){let f=se.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));Gd(f,a)||e.dispatch({selection:f,userEvent:"select"});return}let d={from:c.from+i,to:c.toA+i,insert:it.of(r.text.slice(c.from,c.toB).split(`
|
|
41
|
+
`))};if((ke.mac||ke.android)&&d.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(d={from:i,to:l,insert:it.of([r.text.replace("."," ")])}),this.pendingContextChange=d,!e.state.readOnly){let f=this.to-this.from+(d.to-d.from+d.insert.length);Ym(e,d,se.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),d.from<d.to&&!d.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(t.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let a=[],s=null;for(let o=this.toEditorPos(r.rangeStart),i=this.toEditorPos(r.rangeEnd);o<i;o++){let l=e.coordsForChar(o);s=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||s||new DOMRect,a.push(s)}t.updateCharacterBounds(r.rangeStart,a)},this.handlers.textformatupdate=r=>{let a=[];for(let s of r.getTextFormats()){let o=s.underlineStyle,i=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(i)){let l=this.toEditorPos(s.rangeStart),u=this.toEditorPos(s.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(i)?1:2}px`;a.push(Ke.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:yS.of(Ke.set(a))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)t.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let a=Lu(r.root);a&&a.rangeCount&&this.editContext.updateSelectionBounds(a.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,r=!1,a=this.pendingContextChange;return e.changes.iterChanges((s,o,i,l,u)=>{if(r)return;let c=u.length-(o-s);if(a&&o>=a.to)if(a.from==s&&a.to==o&&a.insert.eq(u)){a=this.pendingContextChange=null,t+=c,this.to+=c;return}else a=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),u.toString()),this.to+=c}t+=c}),a&&!r&&this.revertPending(e.state),!r}update(e){let t=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(a=>!a.isUserEvent("input.type")&&a.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),a=this.toContextPos(t.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=a)&&this.editContext.updateSelection(r,a)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},Ae=class n{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(a=>a.forEach(s=>r(s,this)))||(a=>this.update(a)),this.dispatch=this.dispatch.bind(this),this._root=e.root||VM(e.parent)||document,this.viewState=new jd(this,e.state||Lt.create(e)),e.scrollTo&&e.scrollTo.is(Cd)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Mi).map(a=>new xu(a));for(let a of this.plugins)a.update(this);this.observer=new Em(this),this.inputState=new km(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Hd(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof In?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,r=!1,a,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,i=0,l=null;e.some(f=>f.annotation(ES))?(this.inputState.notifiedFocused=o,i=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=OS(s,o),l||(i=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(c=null)):this.observer.clear(),s.facet(Lt.phrases)!=this.state.facet(Lt.phrases))return this.setState(s);a=Bd.create(this,s,e),a.flags|=i;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(d&&(d=d.map(f.changes)),f.scrollIntoView){let{main:h}=f.state.selection,{x:p,y:m}=this.state.facet(n.cursorScrollMargin);d=new gu(h.empty?h:se.cursor(h.head,h.head>h.anchor?-1:1),"nearest","nearest",m,p)}for(let h of f.effects)h.is(Cd)&&(d=h.value.clip(this.state))}this.viewState.update(a,d),this.bidiCache=qd.update(this.bidiCache,a.changes),a.empty||(this.updatePlugins(a),this.inputState.update(a)),t=this.docView.update(a),this.state.facet(du)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(a.startState.facet(Nd)!=a.state.facet(Nd)&&(this.viewState.mustMeasureContent=!0),(t||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!a.empty)for(let f of this.state.facet(lm))try{f(a)}catch(h){ca(this.state,h,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!PS(this,c)&&u.force&&Ei(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new jd(this,e),this.plugins=e.facet(Mi).map(r=>new xu(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Hd(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Mi),r=e.state.facet(Mi);if(t!=r){let a=[];for(let s of r){let o=t.indexOf(s);if(o<0)a.push(new xu(s));else{let i=this.plugins[o];i.mustUpdate=e,a.push(i)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=a,this.pluginMap.clear()}else for(let a of this.plugins)a.mustUpdate=e;for(let a=0;a<this.plugins.length;a++)this.plugins[a].update(this);t!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(r){ca(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,r=this.viewState.scrollParent,a=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:o,scaleY:i}=this.viewState;Math.abs(a-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0){if(tS(r||this.win))s=-1,o=this.viewState.heightMap.height/this.viewState.scaleY;else{let p=this.viewState.scrollAnchorAt(a);s=p.from,o=p.top}i=this.viewState.scaleY}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];u&4||([this.measureRequests,c]=[c,this.measureRequests]);let d=c.map(p=>{try{return p.read(this)}catch(m){return ca(this.state,m),Gk}}),f=Bd.create(this,this.state,[]),h=!1;f.flags|=u,t?t.flags|=u:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let p=0;p<c.length;p++)if(d[p]!=Gk)try{let m=c[p];m.write&&m.write(d[p],this)}catch(m){ca(this.state,m)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)/this.viewState.scaleY-o/i;if((m>1||m<-1)&&!(ke.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){a=a+m,r?s<0?r.scrollTop=r.scrollHeight:r.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(lm))l(t)}get themeClasses(){return Dm+" "+(this.state.facet(Tm)?HS:_S)+" "+this.state.facet(Nd)}updateAttrs(){let e=zk(this,bS,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(os)?"true":"false",class:"cm-content",style:`${ke.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),zk(this,Km,t);let r=this.observer.ignore(()=>{let a=wk(this.contentDOM,this.contentAttrs,t),s=wk(this.dom,this.editorAttrs,e);return a||s});return this.editorAttrs=e,this.contentAttrs=t,r}showAnnouncements(e){let t=!0;for(let r of e)for(let a of r.effects)if(a.is(n.announce)){t&&(this.announceDOM.textContent="",this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent="\xA0"},200),t=!1);let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=a.value}}mountStyles(){this.styleModules=this.state.facet(du);let e=this.state.facet(n.cspNonce);fr.mount(this.root,this.styleModules.concat(JT).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(r=>r.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,r){return Yp(this,e,Ik(this,e,t,r))}moveByGroup(e,t){return Yp(this,e,Ik(this,e,t,r=>vT(this,e.head,r)))}visualLineSide(e,t){return t?se.cursor(e.to,1):se.cursor(e.from,-1)}moveToLineBoundary(e,t,r=!0){return wT(this,e,t,r)}moveVertically(e,t,r){return Yp(this,e,kT(this,e,t,r))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let r=ym(this,e,t);return r&&r.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),ym(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let r=this.state.doc.lineAt(e),a=this.bidiSpans(r),s=a[Kr.find(a,e-r.from,-1,t)];return r.length&&(e==r.from&&t<0||e==r.to&&t>0)&&s.dir!=this.textDirectionAt(r.from)&&(e==r.to?(e=r.from+s.from,t=1):(e=r.from+s.to,t=-1)),this.docView.coordsAt(e,t,s.dir==zt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(mS)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>eD)return iS(e.length);let t=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||oS(s.isolates,r=Sk(this,e))))return s.order;r||(r=Sk(this,e));let a=eT(e.text,t,r);return this.bidiCache.push(new qd(e.from,e.to,t,r,!0,a)),a}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||ke.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{eS(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var r,a,s,o;return Cd.of(new gu(typeof e=="number"?se.cursor(e):e,(r=t.y)!==null&&r!==void 0?r:"nearest",(a=t.x)!==null&&a!==void 0?a:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return Cd.of(new gu(se.cursor(r.from),"start","start",r.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return pr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return pr.define(()=>({}),{eventObservers:e})}static theme(e,t){let r=fr.newName(),a=[Nd.of(r),du.of(Fm(`.${r}`,e))];return t&&t.dark&&a.push(Tm.of(!0)),a}static baseTheme(e){return Ta.lowest(du.of(Fm("."+Dm,e,US)))}static findFromDOM(e){var t;let r=e.querySelector(".cm-content"),a=r&&Xt.get(r)||Xt.get(e);return((t=a?.root)===null||t===void 0?void 0:t.view)||null}};Ae.styleModule=du;Ae.inputHandler=hS;Ae.clipboardInputFilter=Vm;Ae.clipboardOutputFilter=$m;Ae.scrollHandler=xS;Ae.focusChangeEffect=pS;Ae.perLineTextDirection=mS;Ae.exceptionSink=fS;Ae.updateListener=lm;Ae.editable=os;Ae.mouseSelectionStyle=dS;Ae.dragMovesSelection=cS;Ae.clickAddsSelectionRange=uS;Ae.decorations=Xd;Ae.blockWrappers=wS;Ae.outerDecorations=Xm;Ae.atomicRanges=Pu;Ae.bidiIsolatedRanges=vS;Ae.cursorScrollMargin=Ne.define({combine:n=>{let e=5,t=5;for(let r of n)typeof r=="number"?e=t=r:{x:e,y:t}=r;return{x:e,y:t}}});Ae.scrollMargins=kS;Ae.darkTheme=Tm;Ae.cspNonce=Ne.define({combine:n=>n.length?n[0]:""});Ae.contentAttributes=Km;Ae.editorAttributes=bS;Ae.lineWrapping=Ae.contentAttributes.of({class:"cm-lineWrapping"});Ae.announce=xt.define();var eD=4096,Gk={},qd=class n{constructor(e,t,r,a,s,o){this.from=e,this.to=t,this.dir=r,this.isolates=a,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let r=[],a=e.length?e[e.length-1].dir:zt.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==a&&!t.touchesRange(o.from,o.to)&&r.push(new n(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function zk(n,e,t){for(let r=n.state.facet(e),a=r.length-1;a>=0;a--){let s=r[a],o=typeof s=="function"?s(n):s;o&&Wm(o,t)}return t}var tD=ke.mac?"mac":ke.windows?"win":ke.linux?"linux":"key";function nD(n,e){let t=n.split(/-(?!$)/),r=t[t.length-1];r=="Space"&&(r=" ");let a,s,o,i;for(let l=0;l<t.length-1;++l){let u=t[l];if(/^(cmd|meta|m)$/i.test(u))i=!0;else if(/^a(lt)?$/i.test(u))a=!0;else if(/^(c|ctrl|control)$/i.test(u))s=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?i=!0:s=!0;else throw new Error("Unrecognized modifier name: "+u)}return a&&(r="Alt-"+r),s&&(r="Ctrl-"+r),i&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function Rd(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}var rD=Ta.default(Ae.domEventHandlers({keydown(n,e){return iD(aD(e.state),n,e,"editor")}})),Jm=Ne.define({enables:rD}),Wk=new WeakMap;function aD(n){let e=n.facet(Jm),t=Wk.get(e);return t||Wk.set(e,t=oD(e.reduce((r,a)=>r.concat(a),[]))),t}var Gs=null,sD=4e3;function oD(n,e=tD){let t=Object.create(null),r=Object.create(null),a=(o,i)=>{let l=r[o];if(l==null)r[o]=i;else if(l!=i)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,i,l,u,c)=>{var d,f;let h=t[o]||(t[o]=Object.create(null)),p=i.split(/ (?!$)/).map(x=>nD(x,e));for(let x=1;x<p.length;x++){let b=p.slice(0,x).join(" ");a(b,!0),h[b]||(h[b]={preventDefault:!0,stopPropagation:!1,run:[y=>{let N=Gs={view:y,prefix:b,scope:o};return setTimeout(()=>{Gs==N&&(Gs=null)},sD),!0}]})}let m=p.join(" ");a(m,!1);let g=h[m]||(h[m]={preventDefault:!1,stopPropagation:!1,run:((f=(d=h._any)===null||d===void 0?void 0:d.run)===null||f===void 0?void 0:f.slice())||[]});l&&g.run.push(l),u&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of n){let i=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of i){let c=t[u]||(t[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:d}=o;for(let f in c)c[f].run.push(h=>d(h,Bm))}let l=o[e]||o.key;if(l)for(let u of i)s(u,l,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(u,"Shift-"+l,o.shift,o.preventDefault,o.stopPropagation)}return t}var Bm=null;function iD(n,e,t,r){Bm=e;let a=gk(e),s=ek(a,0),o=tk(s)==a.length&&a!=" ",i="",l=!1,u=!1,c=!1;Gs&&Gs.view==t&&Gs.scope==r&&(i=Gs.prefix+" ",MS.indexOf(e.keyCode)<0&&(u=!0,Gs=null));let d=new Set,f=g=>{if(g){for(let x of g.run)if(!d.has(x)&&(d.add(x),x(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),u=!0)}return!1},h=n[r],p,m;return h&&(f(h[i+Rd(a,e,!o)])?l=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(ke.windows&&e.ctrlKey&&e.altKey)&&!(ke.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=ss[e.keyCode])&&p!=a?(f(h[i+Rd(p,e,!0)])||e.shiftKey&&(m=Ni[e.keyCode])!=a&&m!=p&&f(h[i+Rd(m,e,!1)]))&&(l=!0):o&&e.shiftKey&&f(h[i+Rd(a,e,!0)])&&(l=!0),!l&&f(h._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Bm=null,l}var Ro=class n{constructor(e,t,r,a,s){this.className=e,this.left=t,this.top=r,this.width=a,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,r){if(r.empty){let a=e.coordsAtPos(r.head,r.assoc||1);if(!a)return[];let s=GS(e);return[new n(t,a.left-s.left,a.top-s.top,null,a.bottom-a.top)]}else return lD(e,t,r)}};function GS(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==zt.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function jk(n,e,t,r){let a=n.coordsAtPos(e,t*2);if(!a)return r;let s=n.dom.getBoundingClientRect(),o=(a.top+a.bottom)/2,i=n.posAtCoords({x:s.left+1,y:o}),l=n.posAtCoords({x:s.right-1,y:o});return i==null||l==null?r:{from:Math.max(r.from,Math.min(i,l)),to:Math.min(r.to,Math.max(i,l))}}function lD(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let r=Math.max(t.from,n.viewport.from),a=Math.min(t.to,n.viewport.to),s=n.textDirection==zt.LTR,o=n.contentDOM,i=o.getBoundingClientRect(),l=GS(n),u=o.querySelector(".cm-line"),c=u&&window.getComputedStyle(u),d=i.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=i.right-(c?parseInt(c.paddingRight):0),h=xm(n,r,1),p=xm(n,a,-1),m=h.type==Fn.Text?h:null,g=p.type==Fn.Text?p:null;if(m&&(n.lineWrapping||h.widgetLineBreaks)&&(m=jk(n,r,1,m)),g&&(n.lineWrapping||p.widgetLineBreaks)&&(g=jk(n,a,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return b(y(t.from,t.to,m));{let L=m?y(t.from,null,m):N(h,!1),A=g?y(null,t.to,g):N(p,!0),w=[];return(m||h).to<(g||p).from-(m&&g?1:0)||h.widgetLineBreaks>1&&L.bottom+n.defaultLineHeight/2<A.top?w.push(x(d,L.bottom,f,A.top)):L.bottom<A.top&&n.elementAtHeight((L.bottom+A.top)/2).type==Fn.Text&&(L.bottom=A.top=(L.bottom+A.top)/2),b(L).concat(w).concat(b(A))}function x(L,A,w,v){return new Ro(e,L-l.left,A-l.top,Math.max(0,w-L),v-A)}function b({top:L,bottom:A,horizontal:w}){let v=[];for(let T=0;T<w.length;T+=2)v.push(x(w[T],L,w[T+1],A));return v}function y(L,A,w){let v=1e9,T=-1e9,P=[];function O(H,q,$,S,M){let W=n.coordsAtPos(H,H==w.to?-2:2),ee=n.coordsAtPos($,$==w.from?2:-2);!W||!ee||(v=Math.min(W.top,ee.top,v),T=Math.max(W.bottom,ee.bottom,T),M==zt.LTR?P.push(s&&q?d:W.left,s&&S?f:ee.right):P.push(!s&&S?d:ee.left,!s&&q?f:W.right))}let C=L??w.from,I=A??w.to;for(let H of n.visibleRanges)if(H.to>C&&H.from<I)for(let q=Math.max(H.from,C),$=Math.min(H.to,I);;){let S=n.state.doc.lineAt(q);for(let M of n.bidiSpans(S)){let W=M.from+S.from,ee=M.to+S.from;if(W>=$)break;ee>q&&O(Math.max(W,q),L==null&&W<=C,Math.min(ee,$),A==null&&ee>=I,M.dir)}if(q=S.to+1,q>=$)break}return P.length==0&&O(C,L==null,I,A==null,n.textDirection),{top:v,bottom:T,horizontal:P}}function N(L,A){let w=i.top+(A?L.top:L.bottom);return{top:w,bottom:w,horizontal:[]}}}function uD(n,e){return n.constructor==e.constructor&&n.eq(e)}var _m=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Td)!=e.state.facet(Td)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,r=e.facet(Td);for(;t<r.length&&r[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,r)=>!uD(t,this.drawn[r]))){let t=this.dom.firstChild,r=0;for(let a of e)a.update&&t&&a.constructor&&this.drawn[r].constructor&&a.update(t,this.drawn[r])?(t=t.nextSibling,r++):this.dom.insertBefore(a.draw(),t);for(;t;){let a=t.nextSibling;t.remove(),t=a}this.drawn=e,ke.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Td=Ne.define();function zS(n){return[pr.define(e=>new _m(e,n)),Td.of(n)]}var Gi=Ne.define({combine(n){return Pi(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function WS(n={}){return[Gi.of(n),cD,dD,hD,gS.of(!0)]}function jS(n){return n.startState.facet(Gi)!=n.state.facet(Gi)}var cD=zS({above:!0,markers(n){let{state:e}=n,t=e.facet(Gi),r=[];for(let a of e.selection.ranges){let s=a==e.selection.main;if(a.empty||t.drawRangeCursor&&!(s&&ke.ios&&t.iosSelectionHandles)){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=a.empty?a:se.cursor(a.head,a.assoc);for(let l of Ro.forRange(n,o,i))r.push(l)}}return r},update(n,e){n.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=jS(n);return t&&qk(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){qk(e.state,n)},class:"cm-cursorLayer"});function qk(n,e){e.style.animationDuration=n.facet(Gi).cursorBlinkRate+"ms"}var dD=zS({above:!1,markers(n){let e=[],{main:t,ranges:r}=n.state.selection;for(let a of r)if(!a.empty)for(let s of Ro.forRange(n,"cm-selectionBackground",a))e.push(s);if(ke.ios&&!t.empty&&n.state.facet(Gi).iosSelectionHandles){for(let a of Ro.forRange(n,"cm-selectionHandle cm-selectionHandle-start",se.cursor(t.from,1)))e.push(a);for(let a of Ro.forRange(n,"cm-selectionHandle cm-selectionHandle-end",se.cursor(t.to,1)))e.push(a)}return e},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||jS(n)},class:"cm-selectionLayer"}),fD=ke.gecko&&ke.gecko_version==153?"#ffffff01":"transparent",hD=Ta.highest(Ae.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${fD} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));var H6=/x/.unicode!=null?"gu":"g";function qS(){return mD}var pD=Ke.line({class:"cm-activeLine"}),mD=pr.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let r of n.state.selection.ranges){let a=n.lineBlockAt(r.head);a.from>e&&(t.push(pD.range(a.from)),e=a.from)}return Ke.set(t)}},{decorations:n=>n.decorations}),Hm=class extends Rr{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?pu(e.firstChild):[];if(!t.length)return null;let r=window.getComputedStyle(e.parentNode),a=Iu(t[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return a.bottom-a.top>s*1.5?{left:a.left,right:a.right,top:a.top,bottom:a.top+s}:a}ignoreEvent(){return!1}};function VS(n){let e=pr.fromClass(class{constructor(t){this.view=t,this.placeholder=n?Ke.set([Ke.widget({widget:new Hm(n),side:1}).range(0)]):Ke.none}get decorations(){return this.view.state.doc.length?Ke.none:this.placeholder}},{decorations:t=>t.decorations});return typeof n=="string"?[e,Ae.contentAttributes.of({"aria-placeholder":n})]:e}var En=class extends Ma{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};En.prototype.elementClass="";En.prototype.toDOM=void 0;En.prototype.mapMode=dr.TrackBefore;En.prototype.startSide=En.prototype.endSide=-1;En.prototype.point=!0;var Dd=Ne.define(),gD=Ne.define(),xD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>vt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},vu=Ne.define();function zi(n){return[$S(),vu.of({...xD,...n})]}var Um=Ne.define({combine:n=>n.some(e=>e)});function $S(n){let e=[yD];return n&&n.fixed===!1&&e.push(Um.of(!0)),e}var yD=pr.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(vu).map(e=>new Vd(n,e)),this.fixed=!n.state.facet(Um);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,r=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(r<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Um)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=vt.iter(this.view.state.facet(Dd),this.view.viewport.from),r=[],a=this.gutters.map(s=>new zm(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let o=!0;for(let i of s.type)if(i.type==Fn.Text&&o){Gm(t,r,i.from);for(let l of a)l.line(this.view,i,r);o=!1}else if(i.widget)for(let l of a)l.widget(this.view,i)}else if(s.type==Fn.Text){Gm(t,r,s.from);for(let o of a)o.line(this.view,s,r)}else if(s.widget)for(let o of a)o.widget(this.view,s);for(let s of a)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(vu),t=n.state.facet(vu),r=n.docChanged||n.heightChanged||n.viewportChanged||!vt.eq(n.startState.facet(Dd),n.state.facet(Dd),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let a of this.gutters)a.update(n)&&(r=!0);else{r=!0;let a=[];for(let s of t){let o=e.indexOf(s);o<0?a.push(new Vd(this.view,s)):(this.gutters[o].update(n),a.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),a.indexOf(s)<0&&s.destroy();for(let s of a)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=a}return r}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>Ae.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let r=t.dom.offsetWidth*e.scaleX,a=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==zt.LTR?{left:r,right:a}:{right:r,left:a}})});function Vk(n){return Array.isArray(n)?n:[n]}function Gm(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var zm=class{constructor(e,t,r){this.gutter=e,this.height=r,this.i=0,this.cursor=vt.iter(e.markers,t.from)}addElement(e,t,r){let{gutter:a}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==a.elements.length){let i=new $d(e,o,s,r);a.elements.push(i),a.dom.appendChild(i.dom)}else a.elements[this.i].update(e,o,s,r);this.height=t.bottom,this.i++}line(e,t,r){let a=[];Gm(this.cursor,a,t.from),r.length&&(a=a.concat(r));let s=this.gutter.config.lineMarker(e,t,a);s&&a.unshift(s);let o=this.gutter;a.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,a)}widget(e,t){let r=this.gutter.config.widgetMarker(e,t.widget,t),a=r?[r]:null;for(let s of e.state.facet(gD)){let o=s(e,t.widget,t);o&&(a||(a=[])).push(o)}a&&this.addElement(e,t,a)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Vd=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in t.domEventHandlers)this.dom.addEventListener(r,a=>{let s=a.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let l=s.getBoundingClientRect();o=(l.top+l.bottom)/2}else o=a.clientY;let i=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[r](e,i,a)&&a.preventDefault()});this.markers=Vk(t.markers(e)),t.initialSpacer&&(this.spacer=new $d(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Vk(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let a=this.config.updateSpacer(this.spacer.markers[0],e);a!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[a])}let r=e.view.viewport;return!vt.eq(this.markers,t,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},$d=class{constructor(e,t,r,a){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,r,a)}update(e,t,r,a){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),bD(this.markers,a)||this.setMarkers(e,a)}setMarkers(e,t){let r="cm-gutterElement",a=this.dom.firstChild;for(let s=0,o=0;;){let i=o,l=s<t.length?t[s++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let d=o;d<this.markers.length;d++)if(this.markers[d].compare(l)){i=d,u=!0;break}}else i=this.markers.length;for(;o<i;){let c=this.markers[o++];if(c.toDOM){c.destroy(a);let d=a.nextSibling;a.remove(),a=d}}if(!l)break;l.toDOM&&(u?a=a.nextSibling:this.dom.insertBefore(l.toDOM(e),a)),u&&o++}this.dom.className=r,this.markers=t}destroy(){this.setMarkers(null,[])}};function bD(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}var wD=Ne.define(),vD=Ne.define(),Di=Ne.define({combine(n){return Pi(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let r=Object.assign({},e);for(let a in t){let s=r[a],o=t[a];r[a]=s?(i,l,u)=>s(i,l,u)||o(i,l,u):o}return r}})}}),ku=class extends En{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Zp(n,e){return n.state.facet(Di).formatNumber(e,n.state)}var kD=vu.compute([Di],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(wD)},lineMarker(e,t,r){return r.some(a=>a.toDOM)?null:new ku(Zp(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,r)=>{for(let a of e.state.facet(vD)){let s=a(e,t,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Di)!=e.state.facet(Di),initialSpacer(e){return new ku(Zp(e,$k(e.state.doc.lines)))},updateSpacer(e,t){let r=Zp(t.view,$k(t.view.state.doc.lines));return r==e.number?e:new ku(r)},domEventHandlers:n.facet(Di).domEventHandlers,side:"before"}));function Jd(n={}){return[Di.of(n),$S(),kD]}function $k(n){let e=9;for(;e<n;)e=e*10+9;return e}var SD=new class extends En{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},CD=Dd.compute(["selection"],n=>{let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head).from;a>t&&(t=a,e.push(SD.range(a)))}return vt.of(e)});function KS(){return CD}var LD=0,Nu=class{constructor(e,t){this.from=e,this.to=t}},st=class{constructor(e={}){this.id=LD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Mr.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}};st.closedBy=new st({deserialize:n=>n.split(" ")});st.openedBy=new st({deserialize:n=>n.split(" ")});st.group=new st({deserialize:n=>n.split(" ")});st.isolate=new st({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});st.contextHash=new st({perNode:!0});st.lookAhead=new st({perNode:!0});st.mounted=new st({perNode:!0});var Fo=class{constructor(e,t,r,a=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=a}static get(e){return e&&e.props&&e.props[st.mounted.id]}},ID=Object.create(null),Mr=class n{constructor(e,t,r,a=0){this.name=e,this.props=t,this.id=r,this.flags=a}static define(e){let t=e.props&&e.props.length?Object.create(null):ID,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),a=new n(e.name||"",t,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(a)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return a}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(st.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let a of r.split(" "))t[a]=e[r];return r=>{for(let a=r.prop(st.group),s=-1;s<(a?a.length:0);s++){let o=t[s<0?r.name:a[s]];if(o)return o}}}};Mr.none=new Mr("",Object.create(null),0,8);var Zd=new WeakMap,XS=new WeakMap,sn;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(sn||(sn={}));var On=class n{constructor(e,t,r,a,s){if(this.type=e,this.children=t,this.positions=r,this.length=a,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,i]of s)this.props[typeof o=="number"?o:o.id]=i}}toString(){let e=Fo.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let a=r.toString();a&&(t&&(t+=","),t+=a)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Tu(this.topNode,e)}cursorAt(e,t=0,r=0){let a=Zd.get(this)||this.topNode,s=new Tu(a);return s.moveTo(e,t),Zd.set(this,s._tree),s}get topNode(){return new Ea(this,0,0,null)}resolve(e,t=0){let r=Ru(Zd.get(this)||this.topNode,e,t,!1);return Zd.set(this,r),r}resolveInner(e,t=0){let r=Ru(XS.get(this)||this.topNode,e,t,!0);return XS.set(this,r),r}resolveStack(e,t=0){return AD(this,e,t)}iterate(e){let{enter:t,leave:r,from:a=0,to:s=this.length}=e,o=e.mode||0,i=(o&sn.IncludeAnonymous)>0;for(let l=this.cursor(o|sn.IncludeAnonymous);;){let u=!1;if(l.from<=s&&l.to>=a&&(!i&&l.type.isAnonymous||t(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(i||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:ag(Mr.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,a)=>new n(this.type,t,r,a,this.propValues),e.makeTree||((t,r,a)=>new n(Mr.none,t,r,a)))}static build(e){return PD(e)}};On.empty=new On(Mr.none,[],[],0);var Zm=class n{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new n(this.buffer,this.index)}},qs=class n{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return Mr.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],r=this.buffer[e+3],a=this.set.types[t],s=a.name;if(/\W/.test(s)&&!a.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let o=[];for(;e<r;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,r,a,s){let{buffer:o}=this,i=-1;for(let l=e;l!=t&&!(ZS(s,a,o[l+1],o[l+2])&&(i=l,r>0));l=o[l+3]);return i}slice(e,t,r){let a=this.buffer,s=new Uint16Array(t-e),o=0;for(let i=e,l=0;i<t;){s[l++]=a[i++],s[l++]=a[i++]-r;let u=s[l++]=a[i++]-r;s[l++]=a[i++]-e,o=Math.max(o,u)}return new n(s,o,this.set)}};function ZS(n,e,t,r){switch(n){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function Ru(n,e,t,r){for(var a;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!r&&n instanceof Ea&&n.index<0?null:n.parent;if(!o)return n;n=o}let s=r?0:sn.IgnoreOverlays;if(r)for(let o=n,i=o.parent;i;o=i,i=o.parent)o instanceof Ea&&o.index<0&&((a=i.enter(e,t,s))===null||a===void 0?void 0:a.from)!=o.from&&(n=i);for(;;){let o=n.enter(e,t,s);if(!o)return n;n=o}}var ef=class{cursor(e=0){return new Tu(this,e)}getChild(e,t=null,r=null){let a=YS(this,e,t,r);return a.length?a[0]:null}getChildren(e,t=null,r=null){return YS(this,e,t,r)}resolve(e,t=0){return Ru(this,e,t,!1)}resolveInner(e,t=0){return Ru(this,e,t,!0)}matchContext(e){return Qm(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let a=t.lastChild;if(!a||a.to!=t.to)break;a.type.isError&&a.from==a.to?(r=t,t=a.prevSibling):t=a}return r}get node(){return this}get next(){return this.parent}},Ea=class n extends ef{constructor(e,t,r,a){super(),this._tree=e,this.from=t,this.index=r,this._parent=a}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,a,s=0){for(let o=this;;){for(let{children:i,positions:l}=o._tree,u=t>0?i.length:-1;e!=u;e+=t){let c=i[e],d=l[e]+o.from,f;if(!(!(s&sn.EnterBracketed&&c instanceof On&&(f=Fo.get(c))&&!f.overlay&&f.bracketed&&r>=d&&r<=d+c.length)&&!ZS(a,r,d,d+c.length))){if(c instanceof qs){if(s&sn.ExcludeBuffers)continue;let h=c.findChild(0,c.buffer.length,t,r-d,a);if(h>-1)return new Mu(new eg(o,c,e,d),null,h)}else if(s&sn.IncludeAnonymous||!c.type.isAnonymous||rg(c)){let h;if(!(s&sn.IgnoreMounts)&&(h=Fo.get(c))&&!h.overlay)return new n(h.tree,d,e,o);let p=new n(c,d,e,o);return s&sn.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,r,a,s)}}}if(s&sn.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let a;if(!(r&sn.IgnoreOverlays)&&(a=Fo.get(this._tree))&&a.overlay){let s=e-this.from,o=r&sn.EnterBracketed&&a.bracketed;for(let{from:i,to:l}of a.overlay)if((t>0||o?i<=s:i<s)&&(t<0||o?l>=s:l>s))return new n(a.tree,a.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function YS(n,e,t,r){let a=n.cursor(),s=[];if(!a.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=a.type.is(t),!a.nextSibling())return s}for(;;){if(r!=null&&a.type.is(r))return s;if(a.type.is(e)&&s.push(a.node),!a.nextSibling())return r==null?s:[]}}function Qm(n,e,t=e.length-1){for(let r=n;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}var eg=class{constructor(e,t,r,a){this.parent=e,this.buffer=t,this.index=r,this.start=a}},Mu=class n extends ef{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.context.start,r);return s<0?null:new n(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&sn.ExcludeBuffers)return null;let{buffer:a}=this.context,s=a.findChild(this.index+4,a.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new n(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new n(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new n(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,a=this.index+4,s=r.buffer[this.index+3];if(s>a){let o=r.buffer[this.index+1];e.push(r.slice(a,s,o)),t.push(0)}return new On(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function QS(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let o=n[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let r=t instanceof Ea&&t.index<0?null:t.parent,a=n.slice();return r?a[e]=r:a.splice(e,1),new tg(a,t)}var tg=class{constructor(e,t){this.heads=e,this.node=t}get next(){return QS(this.heads)}};function AD(n,e,t){let r=n.resolveInner(e,t),a=null;for(let s=r instanceof Ea?r:r.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(a||(a=[r])).push(o.resolve(e,t)),s=o}else{let o=Fo.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let i=new Ea(o.tree,o.overlay[0].from+s.from,-1,s);(a||(a=[r])).push(Ru(i,e,t,!1))}}return a?QS(a):r}var Tu=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~sn.EnterBracketed,e instanceof Ea)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:r,buffer:a}=this.buffer;return this.type=t||a.set.types[a.buffer[e]],this.from=r+a.buffer[e+1],this.to=r+a.buffer[e+2],!0}yield(e){return e?e instanceof Ea?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:a}=this.buffer,s=a.findChild(this.index+4,a.buffer[this.index+3],e,t-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,r=this.mode){return this.buffer?r&sn.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&sn.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&sn.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,r=this.stack.length-1;if(e<0){let a=r<0?0:this.stack[r]+4;if(this.index!=a)return this.yieldBuf(t.findChild(a,this.index,-1,0,4))}else{let a=t.buffer[this.index+3];if(a<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(a)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,r,{buffer:a}=this;if(a){if(e>0){if(this.index<a.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(a.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:r}=a)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let s=t+e,o=e<0?-1:r._tree.children.length;s!=o;s+=e){let i=r._tree.children[s];if(this.mode&sn.IncludeAnonymous||i instanceof qs||!i.type.isAnonymous||rg(i))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,r=0;if(e&&e.context==this.buffer)e:for(let a=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==a){if(a==this.index)return o;t=o,r=s+1;break e}a=this.stack[--s]}for(let a=r;a<this.stack.length;a++)t=new Mu(this.buffer,t,this.stack[a]);return this.bufferNode=new Mu(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let a=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(a=!0)}for(;;){if(a&&t&&t(this),a=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,a=!0}}}matchContext(e){if(!this.buffer)return Qm(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let a=e.length-1,s=this.stack.length-1;a>=0;s--){if(s<0)return Qm(this._tree,e,a);let o=r[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[a]&&e[a]!=o.name)return!1;a--}}return!0}};function rg(n){return n.children.some(e=>e instanceof qs||!e.type.isAnonymous||rg(e))}function PD(n){var e;let{buffer:t,nodeSet:r,maxBufferLength:a=1024,reused:s=[],minRepeatType:o=r.types.length}=n,i=Array.isArray(t)?new Zm(t,t.length):t,l=r.types,u=0,c=0;function d(L,A,w,v,T,P){let{id:O,start:C,end:I,size:H}=i,q=c,$=u;if(H<0)if(i.next(),H==-1){let te=s[O];w.push(te),v.push(C-L);return}else if(H==-3){u=O;return}else if(H==-4){c=O;return}else throw new RangeError(`Unrecognized record size: ${H}`);let S=l[O],M,W,ee=C-L;if(I-C<=a&&(W=g(i.pos-A,T))){let te=new Uint16Array(W.size-W.skip),re=i.pos-W.size,ce=te.length;for(;i.pos>re;)ce=x(W.start,te,ce);M=new qs(te,I-W.start,r),ee=W.start-L}else{let te=i.pos-H;i.next();let re=[],ce=[],oe=O>=o?O:-1,ue=0,ie=I;for(;i.pos>te;)oe>=0&&i.id==oe&&i.size>=0?(i.end<=ie-a&&(p(re,ce,C,ue,i.end,ie,oe,q,$),ue=re.length,ie=i.end),i.next()):P>2500?f(C,te,re,ce):d(C,te,re,ce,oe,P+1);if(oe>=0&&ue>0&&ue<re.length&&p(re,ce,C,ue,C,ie,oe,q,$),re.reverse(),ce.reverse(),oe>-1&&ue>0){let Re=h(S,$);M=ag(S,re,ce,0,re.length,0,I-C,Re,Re)}else M=m(S,re,ce,I-C,q-I,$)}w.push(M),v.push(ee)}function f(L,A,w,v){let T=[],P=0,O=-1;for(;i.pos>A;){let{id:C,start:I,end:H,size:q}=i;if(q>4)i.next();else{if(O>-1&&I<O)break;O<0&&(O=H-a),T.push(C,I,H),P++,i.next()}}if(P){let C=new Uint16Array(P*4),I=T[T.length-2];for(let H=T.length-3,q=0;H>=0;H-=3)C[q++]=T[H],C[q++]=T[H+1]-I,C[q++]=T[H+2]-I,C[q++]=q;w.push(new qs(C,T[2]-I,r)),v.push(I-L)}}function h(L,A){return(w,v,T)=>{let P=0,O=w.length-1,C,I;if(O>=0&&(C=w[O])instanceof On){if(!O&&C.type==L&&C.length==T)return C;(I=C.prop(st.lookAhead))&&(P=v[O]+C.length+I)}return m(L,w,v,T,P,A)}}function p(L,A,w,v,T,P,O,C,I){let H=[],q=[];for(;L.length>v;)H.push(L.pop()),q.push(A.pop()+w-T);L.push(m(r.types[O],H,q,P-T,C-P,I)),A.push(T-w)}function m(L,A,w,v,T,P,O){if(P){let C=[st.contextHash,P];O=O?[C].concat(O):[C]}if(T>25){let C=[st.lookAhead,T];O=O?[C].concat(O):[C]}return new On(L,A,w,v,O)}function g(L,A){let w=i.fork(),v=0,T=0,P=0,O=w.end-a,C={size:0,start:0,skip:0};e:for(let I=w.pos-L;w.pos>I;){let H=w.size;if(w.id==A&&H>=0){C.size=v,C.start=T,C.skip=P,P+=4,v+=4,w.next();continue}let q=w.pos-H;if(H<0||q<I||w.start<O)break;let $=w.id>=o?4:0,S=w.start;for(w.next();w.pos>q;){if(w.size<0)if(w.size==-3||w.size==-4)$+=4;else break e;else w.id>=o&&($+=4);w.next()}T=S,v+=H,P+=$}return(A<0||v==L)&&(C.size=v,C.start=T,C.skip=P),C.size>4?C:void 0}function x(L,A,w){let{id:v,start:T,end:P,size:O}=i;if(i.next(),O>=0&&v<o){let C=w;if(O>4){let I=i.pos-(O-4);for(;i.pos>I;)w=x(L,A,w)}A[--w]=C,A[--w]=P-L,A[--w]=T-L,A[--w]=v}else O==-3?u=v:O==-4&&(c=v);return w}let b=[],y=[];for(;i.pos>0;)d(n.start||0,n.bufferStart||0,b,y,-1,0);let N=(e=n.length)!==null&&e!==void 0?e:b.length?y[0]+b[0].length:0;return new On(l[n.topID],b.reverse(),y.reverse(),N)}var JS=new WeakMap;function Qd(n,e){if(!n.isAnonymous||e instanceof qs||e.type!=n)return 1;let t=JS.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=n||!(r instanceof On)){t=1;break}t+=Qd(n,r)}JS.set(e,t)}return t}function ag(n,e,t,r,a,s,o,i,l){let u=0;for(let p=r;p<a;p++)u+=Qd(n,e[p]);let c=Math.ceil(u*1.5/8),d=[],f=[];function h(p,m,g,x,b){for(let y=g;y<x;){let N=y,L=m[y],A=Qd(n,p[y]);for(y++;y<x;y++){let w=Qd(n,p[y]);if(A+w>=c)break;A+=w}if(y==N+1){if(A>c){let w=p[N];h(w.children,w.positions,0,w.children.length,m[N]+b);continue}d.push(p[N])}else{let w=m[y-1]+p[y-1].length-L;d.push(ag(n,p,m,N,y,L,w,null,l))}f.push(L+b-s)}}return h(e,t,r,a,0),(i||l)(d,f,o)}var Eo=class n{constructor(e,t,r,a,s=!1,o=!1){this.from=e,this.to=t,this.tree=r,this.offset=a,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],r=!1){let a=[new n(0,e.length,e,0,!1,r)];for(let s of t)s.to>e.length&&a.push(s);return a}static applyChanges(e,t,r=128){if(!t.length)return e;let a=[],s=1,o=e.length?e[0]:null;for(let i=0,l=0,u=0;;i++){let c=i<t.length?t[i]:null,d=c?c.fromA:1e9;if(d-l>=r)for(;o&&o.from<d;){let f=o;if(l>=f.from||d<=f.to||u){let h=Math.max(f.from,l)-u,p=Math.min(f.to,d)-u;f=h>=p?null:new n(h,p,f.tree,f.offset+u,i>0,!!c)}if(f&&a.push(f),o.to>d)break;o=s<e.length?e[s++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return a}},tf=class{startParse(e,t,r){return typeof e=="string"&&(e=new ng(e)),r=r?r.length?r.map(a=>new Nu(a.from,a.to)):[new Nu(0,0)]:[new Nu(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let a=this.startParse(e,t,r);for(;;){let s=a.advance();if(s)return s}}},ng=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var V6=new st({perNode:!0});var ND=0,ha=class n{constructor(e,t,r,a){this.name=e,this.set=t,this.base=r,this.modified=a,this.id=ND++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let r=typeof e=="string"?e:"?";if(e instanceof n&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let a=new n(r,[],null,[]);if(a.set.push(a),t)for(let s of t.set)a.set.push(s);return a}static defineModifier(e){let t=new sf(e);return r=>r.modified.indexOf(t)>-1?r:sf.get(r.base||r,r.modified.concat(t).sort((a,s)=>a.id-s.id))}},RD=0,sf=class n{constructor(e){this.name=e,this.instances=[],this.id=RD++}static get(e,t){if(!t.length)return e;let r=t[0].instances.find(i=>i.base==e&&MD(t,i.modified));if(r)return r;let a=[],s=new ha(e.name,a,e,t);for(let i of t)i.instances.push(s);let o=TD(t);for(let i of e.set)if(!i.modified.length)for(let l of o)a.push(n.get(i,l));return s}};function MD(n,e){return n.length==e.length&&n.every((t,r)=>t==e[r])}function TD(n){let e=[[]];for(let t=0;t<n.length;t++)for(let r=0,a=e.length;r<a;r++)e.push(e[r].concat(n[t]));return e.sort((t,r)=>r.length-t.length)}function nC(n){let e=Object.create(null);for(let t in n){let r=n[t];Array.isArray(r)||(r=[r]);for(let a of t.split(" "))if(a){let s=[],o=2,i=a;for(let d=0;;){if(i=="..."&&d>0&&d+3==a.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(i);if(!f)throw new RangeError("Invalid path: "+a);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),d+=f[0].length,d==a.length)break;let h=a[d++];if(d==a.length&&h=="!"){o=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);i=a.slice(d)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let c=new Bo(r,o,l>0?s.slice(0,l):null);e[u]=c.sort(e[u])}}return rC.add(e)}var rC=new st({combine(n,e){let t,r,a;for(;n||e;){if(!n||e&&n.depth<=e.depth?(a=e,e=e.next):(a=n,n=n.next),t&&t.mode==a.mode&&!a.context&&!t.context)continue;let s=new Bo(a.tags,a.mode,a.context);t?t.next=s:r=s,t=s}return r}}),Bo=class{constructor(e,t,r,a){this.tags=e,this.mode=t,this.context=r,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};Bo.empty=new Bo([],2,null);function lg(n,e){let t=Object.create(null);for(let s of n)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:r,all:a=null}=e||{};return{style:s=>{let o=a;for(let i of s)for(let l of i.set){let u=t[l.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function DD(n,e){let t=null;for(let r of n){let a=r.style(e);a&&(t=t?t+" "+a:a)}return t}function ug(n,e,t,r=0,a=n.length){let s=new og(r,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),r,a,"",s.highlighters),s.flush(a)}var og=class{constructor(e,t,r){this.at=e,this.highlighters=t,this.span=r,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,r,a,s){let{type:o,from:i,to:l}=e;if(i>=r||l<=t)return;o.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(o)));let u=a,c=FD(e)||Bo.empty,d=DD(s,c.tags);if(d&&(u&&(u+=" "),u+=d,c.mode==1&&(a+=(a?" ":"")+d)),this.startSpan(Math.max(t,i),u),c.opaque)return;let f=e.tree&&e.tree.prop(st.mounted);if(f&&f.overlay){let h=e.node.enter(f.overlay[0].from+i,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,x=i;;g++){let b=g<f.overlay.length?f.overlay[g]:null,y=b?b.from+i:l,N=Math.max(t,x),L=Math.min(r,y);if(N<L&&m)for(;e.from<L&&(this.highlightRange(e,N,L,a,s),this.startSpan(Math.min(L,e.to),u),!(e.to>=y||!e.nextSibling())););if(!b||y>r)break;x=b.to+i,x>t&&(this.highlightRange(h.cursor(),Math.max(t,b.from+i),Math.min(r,x),"",p),this.startSpan(Math.min(r,x),u))}m&&e.parent()}else if(e.firstChild()){f&&(a="");do if(!(e.to<=t)){if(e.from>=r)break;this.highlightRange(e,t,r,a,s),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}};function FD(n){let e=n.type.prop(rC);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}var be=ha.define,nf=be(),Vs=be(),eC=be(Vs),tC=be(Vs),$s=be(),rf=be($s),sg=be($s),_a=be(),Oo=be(_a),Oa=be(),Ba=be(),ig=be(),Du=be(ig),af=be(),ve={comment:nf,lineComment:be(nf),blockComment:be(nf),docComment:be(nf),name:Vs,variableName:be(Vs),typeName:eC,tagName:be(eC),propertyName:tC,attributeName:be(tC),className:be(Vs),labelName:be(Vs),namespace:be(Vs),macroName:be(Vs),literal:$s,string:rf,docString:be(rf),character:be(rf),attributeValue:be(rf),number:sg,integer:be(sg),float:be(sg),bool:be($s),regexp:be($s),escape:be($s),color:be($s),url:be($s),keyword:Oa,self:be(Oa),null:be(Oa),atom:be(Oa),unit:be(Oa),modifier:be(Oa),operatorKeyword:be(Oa),controlKeyword:be(Oa),definitionKeyword:be(Oa),moduleKeyword:be(Oa),operator:Ba,derefOperator:be(Ba),arithmeticOperator:be(Ba),logicOperator:be(Ba),bitwiseOperator:be(Ba),compareOperator:be(Ba),updateOperator:be(Ba),definitionOperator:be(Ba),typeOperator:be(Ba),controlOperator:be(Ba),punctuation:ig,separator:be(ig),bracket:Du,angleBracket:be(Du),squareBracket:be(Du),paren:be(Du),brace:be(Du),content:_a,heading:Oo,heading1:be(Oo),heading2:be(Oo),heading3:be(Oo),heading4:be(Oo),heading5:be(Oo),heading6:be(Oo),contentSeparator:be(_a),list:be(_a),quote:be(_a),emphasis:be(_a),strong:be(_a),link:be(_a),monospace:be(_a),strikethrough:be(_a),inserted:be(),deleted:be(),changed:be(),invalid:be(),meta:af,documentMeta:be(af),annotation:be(af),processingInstruction:be(af),definition:ha.defineModifier("definition"),constant:ha.defineModifier("constant"),function:ha.defineModifier("function"),standard:ha.defineModifier("standard"),local:ha.defineModifier("local"),special:ha.defineModifier("special")};for(let n in ve){let e=ve[n];e instanceof ha&&(e.name=n)}var X6=lg([{tag:ve.link,class:"tok-link"},{tag:ve.heading,class:"tok-heading"},{tag:ve.emphasis,class:"tok-emphasis"},{tag:ve.strong,class:"tok-strong"},{tag:ve.keyword,class:"tok-keyword"},{tag:ve.atom,class:"tok-atom"},{tag:ve.bool,class:"tok-bool"},{tag:ve.url,class:"tok-url"},{tag:ve.labelName,class:"tok-labelName"},{tag:ve.inserted,class:"tok-inserted"},{tag:ve.deleted,class:"tok-deleted"},{tag:ve.literal,class:"tok-literal"},{tag:ve.string,class:"tok-string"},{tag:ve.number,class:"tok-number"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],class:"tok-string2"},{tag:ve.variableName,class:"tok-variableName"},{tag:ve.local(ve.variableName),class:"tok-variableName tok-local"},{tag:ve.definition(ve.variableName),class:"tok-variableName tok-definition"},{tag:ve.special(ve.variableName),class:"tok-variableName2"},{tag:ve.definition(ve.propertyName),class:"tok-propertyName tok-definition"},{tag:ve.typeName,class:"tok-typeName"},{tag:ve.namespace,class:"tok-namespace"},{tag:ve.className,class:"tok-className"},{tag:ve.macroName,class:"tok-macroName"},{tag:ve.propertyName,class:"tok-propertyName"},{tag:ve.operator,class:"tok-operator"},{tag:ve.comment,class:"tok-comment"},{tag:ve.meta,class:"tok-meta"},{tag:ve.invalid,class:"tok-invalid"},{tag:ve.punctuation,class:"tok-punctuation"}]);var cg,Eu=new st;var ED=new st,Xr=class{constructor(e,t,r=[],a=""){this.data=e,this.name=a,Lt.prototype.hasOwnProperty("tree")||Object.defineProperty(Lt.prototype,"tree",{get(){return us(this)}}),this.parser=t,this.extension=[Ks.of(this),Lt.languageData.of((s,o,i)=>{let l=aC(s,o,i),u=l.type.prop(Eu);if(!u)return[];let c=s.facet(u),d=l.type.prop(ED);if(d){let f=l.resolve(o-l.from,i);for(let h of d)if(h.test(f,s)){let p=s.facet(h.facet);return h.type=="replace"?p:p.concat(c)}}return c})].concat(r)}isActiveAt(e,t,r=-1){return aC(e,t,r).type.prop(Eu)==this.data}findRegions(e){let t=e.facet(Ks);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],a=(s,o)=>{if(s.prop(Eu)==this.data){r.push({from:o,to:o+s.length});return}let i=s.prop(st.mounted);if(i){if(i.tree.prop(Eu)==this.data){if(i.overlay)for(let l of i.overlay)r.push({from:l.from+o,to:l.to+o});else r.push({from:o,to:o+s.length});return}else if(i.overlay){let l=r.length;if(a(i.tree,i.overlay[0].from+o),r.length>l)return}}for(let l=0;l<s.children.length;l++){let u=s.children[l];u instanceof On&&a(u,s.positions[l]+o)}};return a(us(e),0),r}get allowsNesting(){return!0}};Xr.setState=xt.define();function aC(n,e,t){let r=n.facet(Ks),a=us(n).topNode;if(!r||r.allowsNesting)for(let s=a;s;s=s.enter(e,t,sn.ExcludeBuffers|sn.EnterBracketed))s.type.isTop&&(a=s);return a}function us(n){let e=n.field(Xr.state,!1);return e?e.tree:On.empty}var hg=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}},Fu=null,pg=class n{constructor(e,t,r=[],a,s,o,i,l){this.parser=e,this.state=t,this.fragments=r,this.tree=a,this.treeLen=s,this.viewport=o,this.skipped=i,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new n(e,t,[],On.empty,0,r,[],null)}startParse(){return this.parser.startParse(new hg(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=On.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let a=this.parse.advance();if(a)if(this.fragments=this.withoutTempSkipped(Eo.addTree(a,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=a,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Eo.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Fu;Fu=this;try{return e()}finally{Fu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=sC(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:a,treeLen:s,viewport:o,skipped:i}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,d,f)=>l.push({fromA:u,toA:c,fromB:d,toB:f})),r=Eo.applyChanges(r,l),a=On.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){i=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),d=e.mapPos(u.to,-1);c<d&&i.push({from:c,to:d})}}}return new n(this.parser,t,r,a,s,o,i,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:a,to:s}=this.skipped[r];a<e.to&&s>e.from&&(this.fragments=sC(this.fragments,a,s),this.skipped.splice(r--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends tf{createParse(t,r,a){let s=a[0].from,o=a[a.length-1].to;return{parsedPos:s,advance(){let l=Fu;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=o,new On(Mr.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Fu}};function sC(n,e,t){return Eo.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Ou=class n{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new n(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=pg.create(e.facet(Ks).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new n(r)}};Xr.state=bn.define({create:Ou.init,update(n,e){for(let t of e.effects)if(t.is(Xr.setState))return t.value;return e.startState.facet(Ks)!=e.state.facet(Ks)?Ou.init(e.state):n.apply(e)}});var uC=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(uC=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var dg=typeof navigator<"u"&&(!((cg=navigator.scheduling)===null||cg===void 0)&&cg.isInputPending)?()=>navigator.scheduling.isInputPending():null,OD=pr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Xr.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Xr.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=uC(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:a}}=this.view,s=r.field(Xr.state);if(s.tree==s.context.tree&&s.context.isDone(a+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!dg?Math.max(25,e.timeRemaining()-5):1e9),i=s.context.treeLen<a&&r.doc.length>a+1e3,l=s.context.work(()=>dg&&dg()||Date.now()>o,a+(i?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Xr.setState.of(new Ou(s.context))})),this.chunkBudget>0&&!(l&&!i)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>ca(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ks=Ne.define({combine(n){return n.length?n[0]:null},enables:n=>[Xr.state,OD,Ae.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});var BD=Ne.define(),of=Ne.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Bu(n){let e=n.facet(of);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function _u(n,e){let t="",r=n.tabSize,a=n.facet(of)[0];if(a==" "){for(;e>=r;)t+=" ",e-=r;a=" "}for(let s=0;s<e;s++)t+=a;return t}function bg(n,e){n instanceof Lt&&(n=new _o(n));for(let r of n.state.facet(BD)){let a=r(n,e);if(a!==void 0)return a}let t=us(n.state);return t.length>=e?HD(n,t,e):null}var _o=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=Bu(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=r.from&&a<=r.to?s&&a==e?{text:"",from:e}:(t<0?a<e:a<=e)?{text:r.text.slice(a-r.from),from:a}:{text:r.text.slice(0,a-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:a}=this.lineAt(e,t);return r.slice(e-a,Math.min(r.length,e+100-a))}column(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.countColumn(r,e-a),o=this.options.overrideIndentation?this.options.overrideIndentation(a):-1;return o>-1&&(s+=o-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,t=e.length){return Ao(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:a}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(a);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},_D=new st;function HD(n,e,t){let r=e.resolveStack(t),a=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(a!=r.node){let s=[];for(let o=a;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)r={node:s[o],next:r}}return cC(r,n,t)}function cC(n,e,t){for(let r=n;r;r=r.next){let a=GD(r.node);if(a)return a(mg.create(e,t,r))}return 0}function UD(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function GD(n){let e=n.type.prop(_D);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(st.closedBy))){let a=n.lastChild,s=a&&r.indexOf(a.name)>-1;return o=>qD(o,!0,1,void 0,s&&!UD(o)?a.from:void 0)}return n.parent==null?zD:null}function zD(){return 0}var mg=class n extends _o{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new n(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(WD(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return cC(this.context.next,this.base,this.pos)}};function WD(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function jD(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let a=n.options.simulateBreak,s=n.state.doc.lineAt(t.from),o=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let i=t.to;;){let l=e.childAfter(i);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=o)return null;let u=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+u}}i=l.to}}function qD(n,e,t,r,a){let s=n.textAfter,o=s.match(/^\s*/)[0].length,i=r&&s.slice(o,o+r.length)==r||a==n.pos+o,l=e?jD(n):null;return l?i?n.column(l.from):n.column(l.to):n.baseIndent+(i?0:n.unit*t)}var gg=class n{constructor(e,t){this.specs=e;let r;function a(i){let l=fr.newName();return(r||(r=Object.create(null)))["."+l]=i,l}let s=typeof t.all=="string"?t.all:t.all?a(t.all):void 0,o=t.scope;this.scope=o instanceof Xr?i=>i.prop(Eu)==o.data:o?i=>i==o:void 0,this.style=lg(e.map(i=>({tag:i.tag,class:i.class||a(Object.assign({},i,{tag:null}))})),{all:s}).style,this.module=r?new fr(r):null,this.themeType=t.themeType}static define(e,t){return new n(e,t||{})}},VD=Ne.define(),$D=Ne.define({combine(n){return n.length?[n[0]]:null}});function KD(n){let e=n.facet(VD);return e.length?e:n.facet($D)}function dC(n,e,t){let r=KD(n),a=null;if(r){for(let s of r)if(!s.scope||t&&s.scope(t)){let o=s.style(e);o&&(a=a?a+" "+o:o)}}return a}var aj=gg.define([{tag:ve.meta,color:"#404740"},{tag:ve.link,textDecoration:"underline"},{tag:ve.heading,textDecoration:"underline",fontWeight:"bold"},{tag:ve.emphasis,fontStyle:"italic"},{tag:ve.strong,fontWeight:"bold"},{tag:ve.strikethrough,textDecoration:"line-through"},{tag:ve.keyword,color:"#708"},{tag:[ve.atom,ve.bool,ve.url,ve.contentSeparator,ve.labelName],color:"#219"},{tag:[ve.literal,ve.inserted],color:"#164"},{tag:[ve.string,ve.deleted],color:"#a11"},{tag:[ve.regexp,ve.escape,ve.special(ve.string)],color:"#e40"},{tag:ve.definition(ve.variableName),color:"#00f"},{tag:ve.local(ve.variableName),color:"#30a"},{tag:[ve.typeName,ve.namespace],color:"#085"},{tag:ve.className,color:"#167"},{tag:[ve.special(ve.variableName),ve.macroName],color:"#256"},{tag:ve.definition(ve.propertyName),color:"#00c"},{tag:ve.comment,color:"#940"},{tag:ve.invalid,color:"#f00"}]);var XD=1e4,YD="()[]{}";var JD=new st;function xg(n,e,t){let r=n.prop(e<0?st.openedBy:st.closedBy);if(r)return r;if(n.name.length==1){let a=t.indexOf(n.name);if(a>-1&&a%2==(e<0?1:0))return[t[a+e]]}return null}function yg(n){let e=n.type.prop(JD);return e?e(n.node):n}function Ho(n,e,t,r={}){let a=r.maxScanDistance||XD,s=r.brackets||YD,o=us(n),i=o.resolveInner(e,t);for(let l=i;l;l=l.parent){let u=xg(l.type,t,s);if(u&&l.from<l.to){let c=yg(l);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return ZD(n,e,t,l,c,u,s)}}return QD(n,e,t,o,i.type,a,s)}function ZD(n,e,t,r,a,s,o){let i=r.parent,l={from:a.from,to:a.to},u=0,c=i?.cursor();if(c&&(t<0?c.childBefore(r.from):c.childAfter(r.to)))do if(t<0?c.to<=r.from:c.from>=r.to){if(u==0&&s.indexOf(c.type.name)>-1&&c.from<c.to){let d=yg(c);return{start:l,end:d?{from:d.from,to:d.to}:void 0,matched:!0}}else if(xg(c.type,t,o))u++;else if(xg(c.type,-t,o)){if(u==0){let d=yg(c);return{start:l,end:d&&d.from<d.to?{from:d.from,to:d.to}:void 0,matched:!1}}u--}}while(t<0?c.prevSibling():c.nextSibling());return{start:l,matched:!1}}function QD(n,e,t,r,a,s,o){if(t<0?!e:e==n.doc.length)return null;let i=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),l=o.indexOf(i);if(l<0||l%2==0!=t>0)return null;let u={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),d=0;for(let f=0;!c.next().done&&f<=s;){let h=c.value;t<0&&(f+=h.length);let p=e+f*t;for(let m=t>0?0:h.length-1,g=t>0?h.length:-1;m!=g;m+=t){let x=o.indexOf(h[m]);if(!(x<0||r.resolveInner(p+m,1).type!=a))if(x%2==0==t>0)d++;else{if(d==1)return{start:u,end:{from:p+m,to:p+m+1},matched:x>>1==l>>1};d--}}t>0&&(f+=h.length)}return c.done?{start:u,matched:!1}:null}var eF=Object.create(null),oC=[Mr.none];var iC=[],lC=Object.create(null),tF=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])tF[n]=nF(eF,e);function fg(n,e){iC.indexOf(n)>-1||(iC.push(n),console.warn(e))}function nF(n,e){let t=[];for(let i of e.split(" ")){let l=[];for(let u of i.split(".")){let c=n[u]||ve[u];c?typeof c=="function"?l.length?l=l.map(c):fg(u,`Modifier ${u} used at start of tag`):l.length?fg(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:fg(u,`Unknown highlighting tag ${u}`)}for(let u of l)t.push(u)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),a=r+" "+t.map(i=>i.id),s=lC[a];if(s)return s.id;let o=lC[a]=Mr.define({id:oC.length,name:r,props:[nC({[r]:t})]});return oC.push(o),o.id}var sj={rtl:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:zt.RTL}),ltr:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:zt.LTR}),auto:Ke.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var mn=class n{constructor(e,t,r,a){this.fromA=e,this.toA=t,this.fromB=r,this.toB=a}offset(e,t=e){return new n(this.fromA+e,this.toA+e,this.fromB+t,this.toB+t)}};function Go(n,e,t,r,a,s){if(n==r)return[];let o=Ng(n,e,t,r,a,s),i=Rg(n,e+o,t,r,a+o,s);e+=o,t-=i,a+=o,s-=i;let l=t-e,u=s-a;if(!l||!u)return[new mn(e,t,a,s)];if(l>u){let d=n.slice(e,t).indexOf(r.slice(a,s));if(d>-1)return[new mn(e,e+d,a,a),new mn(e+d+u,t,s,s)]}else if(u>l){let d=r.slice(a,s).indexOf(n.slice(e,t));if(d>-1)return[new mn(e,e,a,a+d),new mn(t,t,a+d+l,s)]}if(l==1||u==1)return[new mn(e,t,a,s)];let c=TC(n,e,t,r,a,s);if(c){let[d,f,h]=c;return Go(n,e,d,r,a,f).concat(Go(n,d+h,t,r,f+h,s))}return rF(n,e,t,r,a,s)}var Hu=1e9,Uu=0,Pg=!1;function rF(n,e,t,r,a,s){let o=t-e,i=s-a;if(Hu<1e9&&Math.min(o,i)>Hu*16||Uu>0&&Date.now()>Uu)return Math.min(o,i)>Hu*64?[new mn(e,t,a,s)]:fC(n,e,t,r,a,s);let l=Math.ceil((o+i)/2);wg.reset(l),vg.reset(l);let u=(h,p)=>n.charCodeAt(e+h)==r.charCodeAt(a+p),c=(h,p)=>n.charCodeAt(t-h-1)==r.charCodeAt(s-p-1),d=(o-i)%2!=0?vg:null,f=d?null:wg;for(let h=0;h<l;h++){if(h>Hu||Uu>0&&!(h&63)&&Date.now()>Uu)return fC(n,e,t,r,a,s);let p=wg.advance(h,o,i,l,d,!1,u)||vg.advance(h,o,i,l,f,!0,c);if(p)return aF(n,e,t,e+p[0],r,a,s,a+p[1])}return[new mn(e,t,a,s)]}var ff=class{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let t=0;t<this.len;t++)this.vec[t]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,t,r,a,s,o,i){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=a+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,d=c-l;for(;c<t&&d<r&&i(c,d);)c++,d++;if(this.vec[u]=c,c>t)this.end+=2;else if(d>r)this.start+=2;else if(s){let f=a+(t-r)-l;if(f>=0&&f<this.len&&s.vec[f]!=-1)if(o){let h=s.vec[f];if(h>=t-c)return[h,a+h-f]}else{let h=t-s.vec[f];if(c>=h)return[c,d]}}}return null}},wg=new ff,vg=new ff;function aF(n,e,t,r,a,s,o,i){let l=!1;return!ji(n,r)&&++r==t&&(l=!0),!ji(a,i)&&++i==o&&(l=!0),l?[new mn(e,t,s,o)]:Go(n,e,r,a,s,i).concat(Go(n,r,t,a,i,o))}function MC(n,e){let t=1,r=Math.min(n,e);for(;t<r;)t=t<<1;return t}function Ng(n,e,t,r,a,s){if(e==t||e==s||n.charCodeAt(e)!=r.charCodeAt(a))return 0;let o=MC(t-e,s-a);for(let i=e,l=a;;){let u=i+o,c=l+o;if(u>t||c>s||n.slice(i,u)!=r.slice(l,c)){if(o==1)return i-e-(ji(n,i)?0:1);o=o>>1}else{if(u==t||c==s)return u-e;i=u,l=c}}}function Rg(n,e,t,r,a,s){if(e==t||a==s||n.charCodeAt(t-1)!=r.charCodeAt(s-1))return 0;let o=MC(t-e,s-a);for(let i=t,l=s;;){let u=i-o,c=l-o;if(u<e||c<a||n.slice(u,i)!=r.slice(c,l)){if(o==1)return t-i-(ji(n,i)?0:1);o=o>>1}else{if(u==e||c==a)return t-u;i=u,l=c}}}function kg(n,e,t,r,a,s,o,i){let l=r.slice(a,s),u=null;for(;;){if(u||o<i)return u;for(let c=e+o;;){ji(n,c)||c++;let d=c+o;if(ji(n,d)||(d+=d==c+1?1:-1),d>=t)break;let f=n.slice(c,d),h=-1;for(;(h=l.indexOf(f,h+1))!=-1;){let p=Ng(n,d,t,r,a+h+f.length,s),m=Rg(n,e,c,r,a,a+h),g=f.length+p+m;(!u||u[2]<g)&&(u=[c-m,a+h-m,g])}c=d}if(i<0)return u;o=o>>1}}function TC(n,e,t,r,a,s){let o=t-e,i=s-a;if(o<i){let l=TC(r,a,s,n,e,t);return l&&[l[1],l[0],l[2]]}return o<4||i*2<o?null:kg(n,e,t,r,a,s,Math.floor(o/4),-1)}function fC(n,e,t,r,a,s){Pg=!0;let o=t-e,i=s-a,l;if(o<i){let f=kg(r,a,s,n,e,t,Math.floor(o/6),50);l=f&&[f[1],f[0],f[2]]}else l=kg(n,e,t,r,a,s,Math.floor(i/6),50);if(!l)return[new mn(e,t,a,s)];let[u,c,d]=l;return Go(n,e,u,r,a,c).concat(Go(n,u+d,t,r,c+d,s))}function DC(n,e){for(let t=1;t<n.length;t++){let r=n[t-1],a=n[t];r.toA>a.fromA-e&&r.toB>a.fromB-e&&(n[t-1]=new mn(r.fromA,a.toA,r.fromB,a.toB),n.splice(t--,1))}}function sF(n,e,t){for(;;){DC(t,1);let r=!1;for(let a=0;a<t.length;a++){let s=t[a],o,i;(o=Ng(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new mn(s.fromA+o,s.toA,s.fromB+o,s.toB)),(i=Rg(n,s.fromA,s.toA,e,s.fromB,s.toB))&&(s=t[a]=new mn(s.fromA,s.toA-i,s.fromB,s.toB-i));let l=s.toA-s.fromA,u=s.toB-s.fromB;if(l&&u)continue;let c=s.fromA-(a?t[a-1].toA:0),d=(a<t.length-1?t[a+1].fromA:n.length)-s.toA;if(!c||!d)continue;let f=l?n.slice(s.fromA,s.toA):e.slice(s.fromB,s.toB);c<=f.length&&n.slice(s.fromA-c,s.fromA)==f.slice(f.length-c)?(t[a]=new mn(s.fromA-c,s.toA-c,s.fromB-c,s.toB-c),r=!0):d<=f.length&&n.slice(s.toA,s.toA+d)==f.slice(0,d)&&(t[a]=new mn(s.fromA+d,s.toA+d,s.fromB+d,s.toB+d),r=!0)}if(!r)break}return t}function oF(n,e,t){for(let r=0,a=0;a<n.length;a++){let s=n[a],o=s.toA-s.fromA,i=s.toB-s.fromB;if(o&&i||o>3||i>3){let l=a==n.length-1?e.length:n[a+1].fromA,u=s.fromA-r,c=l-s.toA,d=pC(e,s.fromA,u),f=hC(e,s.toA,c),h=s.fromA-d,p=f-s.toA;if((!o||!i)&&h&&p){let m=Math.max(o,i),[g,x,b]=o?[e,s.fromA,s.toA]:[t,s.fromB,s.toB];m>h&&e.slice(d,s.fromA)==g.slice(b-h,b)?(s=n[a]=new mn(d,d+o,s.fromB-h,s.toB-h),d=s.fromA,f=hC(e,s.toA,l-s.toA)):m>p&&e.slice(s.toA,f)==g.slice(x,x+p)&&(s=n[a]=new mn(f-o,f,s.fromB+p,s.toB+p),f=s.toA,d=pC(e,s.fromA,s.fromA-r)),h=s.fromA-d,p=f-s.toA}if(h||p)s=n[a]=new mn(s.fromA-h,s.toA+p,s.fromB-h,s.toB+p);else if(o){if(!i){let m=gC(e,s.fromA,s.toA),g,x=m<0?-1:mC(e,s.toA,s.fromA);m>-1&&(g=m-s.fromA)<=c&&e.slice(s.fromA,m)==e.slice(s.toA,s.toA+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toA-x)<=u&&e.slice(s.fromA-g,s.fromA)==e.slice(x,s.toA)&&(s=n[a]=s.offset(-g))}}else{let m=gC(t,s.fromB,s.toB),g,x=m<0?-1:mC(t,s.toB,s.fromB);m>-1&&(g=m-s.fromB)<=c&&t.slice(s.fromB,m)==t.slice(s.toB,s.toB+g)?s=n[a]=s.offset(g):x>-1&&(g=s.toB-x)<=u&&t.slice(s.fromB-g,s.fromB)==t.slice(x,s.toB)&&(s=n[a]=s.offset(-g))}}r=s.toA}return DC(n,3),n}var Uo;try{Uo=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function FC(n){return n>48&&n<58||n>64&&n<91||n>96&&n<123}function EC(n,e){if(e==n.length)return 0;let t=n.charCodeAt(e);return t<192?FC(t)?1:0:Uo?!_C(t)||e==n.length-1?Uo.test(String.fromCharCode(t))?1:0:Uo.test(n.slice(e,e+2))?2:0:0}function OC(n,e){if(!e)return 0;let t=n.charCodeAt(e-1);return t<192?FC(t)?1:0:Uo?!HC(t)||e==1?Uo.test(String.fromCharCode(t))?1:0:Uo.test(n.slice(e-2,e))?2:0:0}var BC=8;function hC(n,e,t){if(e==n.length||!OC(n,e))return e;for(let r=e,a=e+t,s=0;s<BC;s++){let o=EC(n,r);if(!o||r+o>a)return r;r+=o}return e}function pC(n,e,t){if(!e||!EC(n,e))return e;for(let r=e,a=e-t,s=0;s<BC;s++){let o=OC(n,r);if(!o||r-o<a)return r;r-=o}return e}function mC(n,e,t){for(;e!=t;e--)if(n.charCodeAt(e-1)==10)return e;return-1}function gC(n,e,t){for(;e!=t;e++)if(n.charCodeAt(e)==10)return e;return-1}var _C=n=>n>=55296&&n<=56319,HC=n=>n>=56320&&n<=57343;function ji(n,e){return!e||e==n.length||!_C(n.charCodeAt(e-1))||!HC(n.charCodeAt(e))}function iF(n,e,t){var r;let a=t?.override;return a?a(n,e):(Hu=((r=t?.scanLimit)!==null&&r!==void 0?r:1e9)>>1,Uu=t?.timeout?Date.now()+t.timeout:0,Pg=!1,sF(n,e,Go(n,0,n.length,e,0,e.length)))}function UC(){return!Pg}function GC(n,e,t){return oF(iF(n,e,t),n,e)}var mr=Ne.define({combine:n=>n[0]}),Sg=xt.define(),zC=Ne.define(),rr=bn.define({create(n){return null},update(n,e){for(let t of e.effects)t.is(Sg)&&(n=t.value);for(let t of e.state.facet(zC))n=t(n,e);return n}});var cs=class n{constructor(e,t,r,a,s,o=!0){this.changes=e,this.fromA=t,this.toA=r,this.fromB=a,this.toB=s,this.precise=o}offset(e,t){return e||t?new n(this.changes,this.fromA+e,this.toA+e,this.fromB+t,this.toB+t,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,t,r){let a=GC(e.toString(),t.toString(),r);return WC(a,e,t,0,0,UC())}static updateA(e,t,r,a,s){return vC(wC(e,a,!0,r.length),e,t,r,s)}static updateB(e,t,r,a,s){return vC(wC(e,a,!1,t.length),e,t,r,s)}};function xC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.to==n&&s.to==e&&n<t.length&&e<r.length?[n+1,e+1]:[a.from,s.from]}function yC(n,e,t,r){let a=t.lineAt(n),s=r.lineAt(e);return a.from==n&&s.from==e?[n,e]:[a.to+1,s.to+1]}function WC(n,e,t,r,a,s){let o=[];for(let i=0;i<n.length;i++){let l=n[i],[u,c]=xC(l.fromA+r,l.fromB+a,e,t),[d,f]=yC(l.toA+r,l.toB+a,e,t),h=[l.offset(-u+r,-c+a)];for(;i<n.length-1;){let p=n[i+1],[m,g]=xC(p.fromA+r,p.fromB+a,e,t);if(m>d+1&&g>f+1)break;h.push(p.offset(-u+r,-c+a)),[d,f]=yC(p.toA+r,p.toB+a,e,t),i++}o.push(new cs(h,u,Math.max(u,d),c,Math.max(c,f),s))}return o}var lf=1e3;function bC(n,e,t,r){let a=0,s=n.length;for(;;){if(a==s){let c=0,d=0;a&&({toA:c,toB:d}=n[a-1]);let f=e-(t?c:d);return[c+f,d+f]}let o=a+s>>1,i=n[o],[l,u]=t?[i.fromA,i.toA]:[i.fromB,i.toB];if(l>e)s=o;else if(u<=e)a=o+1;else return r?[i.fromA,i.fromB]:[i.toA,i.toB]}}function wC(n,e,t,r){let a=[];return e.iterChangedRanges((s,o,i,l)=>{let u=0,c=t?e.length:r,d=0,f=t?r:e.length;s>lf&&([u,d]=bC(n,s-lf,t,!0)),o<e.length-lf&&([c,f]=bC(n,o+lf,t,!1));let h=l-i-(o-s),p,[m,g]=t?[h,0]:[0,h];a.length&&(p=a[a.length-1]).toA>=u?a[a.length-1]={fromA:p.fromA,fromB:p.fromB,toA:c,toB:f,diffA:p.diffA+m,diffB:p.diffB+g}:a.push({fromA:u,toA:c,fromB:d,toB:f,diffA:m,diffB:g})}),a}function vC(n,e,t,r,a){if(!n.length)return e;let s=[];for(let o=0,i=0,l=0,u=0;;o++){let c=o==n.length?null:n[o],d=c?c.fromA+i:t.length,f=c?c.fromB+l:r.length;for(;u<e.length;){let g=e[u];if(c&&(g.toA+i>d||g.toB+l>f))break;s.push(g.offset(i,l)),u++}if(!c)break;let h=c.toA+i+c.diffA,p=c.toB+l+c.diffB,m=GC(t.sliceString(d,h),r.sliceString(f,p),a);for(let g of WC(m,t,r,d,f,UC()))s.push(g);for(i+=c.diffA,l+=c.diffB;u<e.length;){let g=e[u];if(g.fromA+i>h&&g.fromB+l>p)break;u++}}return s}var jC={scanLimit:500},gf=pr.fromClass(class{constructor(n){({deco:this.deco,gutter:this.gutter}=CC(n))}update(n){(n.docChanged||n.viewportChanged||lF(n.startState,n.state)||uF(n.startState,n.state))&&({deco:this.deco,gutter:this.gutter}=CC(n.view))}},{decorations:n=>n.deco}),uf=Ta.low(zi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(gf))===null||e===void 0?void 0:e.gutter)||vt.empty}}));function lF(n,e){return n.field(rr,!1)!=e.field(rr,!1)}function uF(n,e){return n.facet(mr)!=e.facet(mr)}var kC=Ke.line({class:"cm-changedLine"}),qC=Ke.mark({class:"cm-changedText"}),cF=Ke.mark({tagName:"ins",class:"cm-insertedLine"}),dF=Ke.mark({tagName:"del",class:"cm-deletedLine"}),SC=new class extends En{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function fF(n,e,t,r,a,s){let o=t?n.fromA:n.fromB,i=t?n.toA:n.toB,l=0;if(o!=i){a.add(o,o,kC),a.add(o,i,t?dF:cF),s&&s.add(o,o,SC);for(let u=e.iterRange(o,i-1),c=o;!u.next().done;){if(u.lineBreak){c++,a.add(c,c,kC),s&&s.add(c,c,SC);continue}let d=c+u.value.length;if(r)for(;l<n.changes.length;){let f=n.changes[l],h=o+(t?f.fromA:f.fromB),p=o+(t?f.toA:f.toB),m=Math.max(c,h),g=Math.min(d,p);if(m<g&&a.add(m,g,qC),p<d)l++;else break}c=d}}}function CC(n){let e=n.state.field(rr),{side:t,highlightChanges:r,markGutter:a,overrideChunk:s}=n.state.facet(mr),o=t=="a",i=new Wn,l=a?new Wn:null,{from:u,to:c}=n.viewport;for(let d of e){if((o?d.fromA:d.fromB)>=c)break;(o?d.toA:d.toB)>u&&(!s||!s(n.state,d,i,l))&&fF(d,n.state.doc,o,r,i,l)}return{deco:i.finish(),gutter:l&&l.finish()}}var Wi=class extends Rr{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}},hf=xt.define({map:(n,e)=>n.map(e)}),Gu=bn.define({create:()=>Ke.none,update:(n,e)=>{for(let t of e.effects)if(t.is(hf))return t.value;return n.map(e.changes)},provide:n=>Ae.decorations.from(n)}),cf=.01;function LC(n,e){if(n.size!=e.size)return!1;let t=n.iter(),r=e.iter();for(;t.value;){if(t.from!=r.from||Math.abs(t.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;t.next(),r.next()}return!0}function hF(n,e,t){let r=new Wn,a=new Wn,s=n.state.field(Gu).iter(),o=e.state.field(Gu).iter(),i=0,l=0,u=0,c=0,d=n.viewport,f=e.viewport;for(let g=0;;g++){let x=g<t.length?t[g]:null,b=x?x.fromA:n.state.doc.length,y=x?x.fromB:e.state.doc.length;if(i<b){let N=n.lineBlockAt(i).top+u,L=e.lineBlockAt(l).top+c,A=N-L;A<-cf?(u-=A,r.add(i,i,Ke.widget({widget:new Wi(-A),block:!0,side:-1}))):A>cf&&(c+=A,a.add(l,l,Ke.widget({widget:new Wi(A),block:!0,side:-1})))}if(b>i+1e3&&i<d.from&&b>d.from&&l<f.from&&y>f.from){let N=Math.min(d.from-i,f.from-l);i+=N,l+=N,g--}else if(x)i=x.toA,l=x.toB;else break;for(;s.value&&s.from<i;)u-=s.value.spec.widget.height,s.next();for(;o.value&&o.from<l;)c-=o.value.spec.widget.height,o.next()}for(;s.value;)u-=s.value.spec.widget.height,s.next();for(;o.value;)c-=o.value.spec.widget.height,o.next();let h=n.contentHeight+u-(e.contentHeight+c);h<cf?r.add(n.state.doc.length,n.state.doc.length,Ke.widget({widget:new Wi(-h),block:!0,side:1})):h>cf&&a.add(e.state.doc.length,e.state.doc.length,Ke.widget({widget:new Wi(h),block:!0,side:1}));let p=r.finish(),m=a.finish();LC(p,n.state.field(Gu))||n.dispatch({effects:hf.of(p)}),LC(m,e.state.field(Gu))||e.dispatch({effects:hf.of(m)})}var Cg=xt.define({map:(n,e)=>e.mapPos(n)});var Lg=class extends Rr{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let t=document.createElement("div");return t.className="cm-collapsedLines",t.textContent=e.state.phrase("$ unchanged lines",this.lines),t.addEventListener("click",r=>{let a=e.posAtDOM(r.target);e.dispatch({effects:Cg.of(a)});let{side:s,sibling:o}=e.state.facet(mr);o&&o().dispatch({effects:Cg.of(pF(a,e.state.field(rr),s=="a"))})}),t}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}};function pF(n,e,t){let r=0,a=0;for(let s=0;;s++){let o=s<e.length?e[s]:null;if(!o||(t?o.fromA:o.fromB)>=n)return a+(n-r);[r,a]=t?[o.toA,o.toB]:[o.toB,o.toA]}}var mF=bn.define({create(n){return Ke.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)t.is(Cg)&&(n=n.update({filter:r=>r!=t.value}));if(n.size&&e.state.field(rr)!=e.startState.field(rr,!1)){let t=e.state.facet(mr).side=="a",r=[];for(let a of e.state.field(rr))n.between(t?a.fromA:a.fromB,t?a.toA:a.toB,s=>{r.push(s)});r.length&&(n=n.update({filter:a=>r.indexOf(a)<0}))}return n},provide:n=>Ae.decorations.from(n)});function Ig({margin:n=3,minSize:e=4}){return mF.init(t=>gF(t,n,e))}function gF(n,e,t){let r=new Wn,a=n.facet(mr).side=="a",s=n.field(rr),o=1;for(let i=0;;i++){let l=i<s.length?s[i]:null,u=i?o+e:1,c=l?n.doc.lineAt(a?l.fromA:l.fromB).number-1-e:n.doc.lines,d=c-u+1;if(d>=t&&r.add(n.doc.line(u).from,n.doc.line(c).to,Ke.replace({widget:new Lg(d),block:!0})),!l)break;o=n.doc.lineAt(Math.min(n.doc.length,a?l.toA:l.toB)).number}return r.finish()}var xF=Ae.styleModule.of(new fr({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),VC=Ae.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"\u299A"',marginInlineEnd:"7px"},"&:after":{content:'"\u299A"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),IC=new jr,df=new jr,pf=class{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||jC;let t=[Ta.low(gf),VC,xF,Gu,Ae.updateListener.of(d=>{this.measuring<0&&(d.heightChanged||d.viewportChanged)&&!d.transactions.some(f=>f.effects.some(h=>h.is(hf)))&&this.measure()})],r=[mr.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(uf);let a=Lt.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],Ae.editorAttributes.of({class:"cm-merge-a"}),df.of(r),t]}),s=[mr.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&s.push(uf);let o=Lt.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],Ae.editorAttributes.of({class:"cm-merge-b"}),df.of(s),t]});this.chunks=cs.build(a.doc,o.doc,this.diffConf);let i=[rr.init(()=>this.chunks),IC.of(e.collapseUnchanged?Ig(e.collapseUnchanged):[])];a=a.update({effects:xt.appendConfig.of(i)}).state,o=o.update({effects:xt.appendConfig.of(i)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new Ae({state:a,parent:u,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.a)}),this.b=new Ae({state:o,parent:c,root:e.root,dispatchTransactions:d=>this.dispatch(d,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,t){if(e.some(r=>r.docChanged)){let r=e[e.length-1],a=e.reduce((o,i)=>o.compose(i.changes),Pn.empty(e[0].startState.doc.length));this.chunks=t==this.a?cs.updateA(this.chunks,r.newDoc,this.b.state.doc,a,this.diffConf):cs.updateB(this.chunks,this.a.state.doc,r.newDoc,a,this.diffConf),t.update([...e,r.state.update({effects:Sg.of(this.chunks)})]);let s=t==this.a?this.b:this.a;s.update([s.state.update({effects:Sg.of(this.chunks)})]),this.scheduleMeasure()}else t.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let s=e.orientation!="b-a";if(s!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let o=this.a.dom.parentNode,i=this.b.dom.parentNode;o.remove(),i.remove(),this.editorDOM.insertBefore(s?o:i,this.editorDOM.firstChild),this.editorDOM.appendChild(s?i:o),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let s=!!this.revertDOM,o=this.revertToA,i=this.renderRevert;"revertControls"in e&&(s=!!e.revertControls,o=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(i=e.renderRevertControl),this.setupRevertControls(s,o,i)}let t="highlightChanges"in e,r="gutter"in e,a="collapseUnchanged"in e;if(t||r||a){let s=[],o=[];if(t||r){let i=this.a.state.facet(mr),l=r?e.gutter!==!1:i.markGutter,u=t?e.highlightChanges!==!1:i.highlightChanges;s.push(df.reconfigure([mr.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?uf:[]])),o.push(df.reconfigure([mr.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?uf:[]]))}if(a){let i=IC.reconfigure(e.collapseUnchanged?Ig(e.collapseUnchanged):[]);s.push(i),o.push(i)}this.a.dispatch({effects:s}),this.b.dispatch({effects:o})}this.scheduleMeasure()}setupRevertControls(e,t,r){this.revertToA=t,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",a=>this.revertClicked(a)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){hF(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,t=e.firstChild,r=this.a.viewport,a=this.b.viewport;for(let s=0;s<this.chunks.length;s++){let o=this.chunks[s];if(o.fromA>r.to||o.fromB>a.to)break;if(o.fromA<r.from||o.fromB<a.from)continue;let i=this.a.lineBlockAt(o.fromA).top+"px";for(;t&&+t.dataset.chunk<s;)t=AC(t);t&&t.dataset.chunk==String(s)?(t.style.top!=i&&(t.style.top=i),t=t.nextSibling):e.insertBefore(this.renderRevertButton(i,s),t)}for(;t;)t=AC(t)}renderRevertButton(e,t){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let a=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",a),r.setAttribute("title",a),r.textContent=this.revertToLeft?"\u21DC":"\u21DD"}return r.style.top=e,r.setAttribute("data-chunk",String(t)),r}revertClicked(e){let t=e.target,r;for(;t&&t.parentNode!=this.revertDOM;)t=t.parentNode;if(t&&(r=this.chunks[t.dataset.chunk])){let[a,s,o,i,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=a.state.sliceDoc(o,Math.max(o,i-1));o!=i&&u<=s.state.doc.length&&(c+=a.state.lineBreak),s.dispatch({changes:{from:l,to:Math.min(s.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}};function AC(n){let e=n.nextSibling;return n.remove(),e}var yF=new class extends En{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},bF=Ta.low(zi({class:"cm-changeGutter",markers:n=>{var e;return((e=n.plugin(gf))===null||e===void 0?void 0:e.gutter)||vt.empty},widgetMarker:(n,e)=>e instanceof mf?yF:null}));function $C(n){var e;let t=typeof n.original=="string"?it.of(n.original.split(/\r?\n/)):n.original,r=n.diffConfig||jC;return[Ta.low(gf),SF,VC,Ae.editorAttributes.of({class:"cm-merge-b"}),zC.of((a,s)=>{let o=s.effects.find(i=>i.is(Mg));return o&&(a=cs.updateA(a,o.value.doc,s.startState.doc,o.value.changes,r)),s.docChanged&&(a=cs.updateB(a,s.state.field(qi),s.newDoc,s.changes,r)),a}),mr.of({highlightChanges:n.highlightChanges!==!1,markGutter:n.gutter!==!1,syntaxHighlightDeletions:n.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=n.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:n.allowInlineDiffs?IF:void 0,side:"b"}),qi.init(()=>t),n.gutter!==!1?bF:[],n.collapseUnchanged?Ig(n.collapseUnchanged):[],rr.init(a=>cs.build(t,a.doc,r))]}var Mg=xt.define();var qi=bn.define({create:()=>it.empty,update(n,e){for(let t of e.effects)t.is(Mg)&&(n=t.value.doc);return n}});var PC=new WeakMap,mf=class extends Rr{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}};function wF(n,e,t){let r=PC.get(e.changes);if(r)return r;let a=o=>{let{highlightChanges:i,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=n.facet(mr),d=document.createElement("div");if(d.className="cm-deletedChunk",c){let N=d.appendChild(document.createElement("div"));N.className="cm-chunkButtons";let L=w=>{w.preventDefault(),vF(o,o.posAtDOM(d))},A=w=>{w.preventDefault(),kF(o,o.posAtDOM(d))};if(typeof c=="function")N.appendChild(c("accept",L)),N.appendChild(c("reject",A));else{let w=N.appendChild(document.createElement("button"));w.name="accept",w.textContent=n.phrase("Accept"),w.onmousedown=L;let v=N.appendChild(document.createElement("button"));v.name="reject",v.textContent=n.phrase("Reject"),v.onmousedown=A}}if(t||e.fromA>=e.toA)return d;let f=o.state.field(qi).sliceString(e.fromA,e.endA),h=l&&n.facet(Ks),p=b(),m=e.changes,g=0,x=!1;function b(){let N=d.appendChild(document.createElement("div"));return N.className="cm-deletedLine",N.appendChild(document.createElement("del"))}function y(N,L,A){for(let w=N;w<L;){if(f.charAt(w)==`
|
|
42
|
+
`){p.firstChild||p.appendChild(document.createElement("br")),p=b(),w++;continue}let v=L,T=A+(x?" cm-deletedText":""),P=!1,O=f.indexOf(`
|
|
43
|
+
`,w);if(O>-1&&O<L&&(v=O),i&&g<m.length){let C=Math.max(0,x?m[g].toA:m[g].fromA);C<=v&&(v=C,x&&g++,P=!0)}if(v>w){let C=document.createTextNode(f.slice(w,v));if(T){let I=p.appendChild(document.createElement("span"));I.className=T,I.appendChild(C)}else p.appendChild(C);w=v}P&&(x=!x)}}if(h&&e.toA-e.fromA<=u){let N=h.parser.parse(f),L=0;ug(N,{style:A=>dC(n,A)},(A,w,v)=>{A>L&&y(L,A,""),y(A,w,v),L=w}),y(L,f.length,"")}else y(0,f.length,"");return p.firstChild||p.appendChild(document.createElement("br")),d},s=Ke.widget({block:!0,side:-1,widget:new mf(a)});return PC.set(e.changes,s),s}function vF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=n.state.field(rr).find(l=>l.fromB<=r&&l.endB>=r);if(!a)return!1;let s=n.state.sliceDoc(a.fromB,Math.max(a.fromB,a.toB-1)),o=n.state.field(qi);a.fromB!=a.toB&&a.toA<=o.length&&(s+=n.state.lineBreak);let i=Pn.of({from:a.fromA,to:Math.min(o.length,a.toA),insert:s},o.length);return n.dispatch({effects:Mg.of({doc:i.apply(o),changes:i}),userEvent:"accept"}),!0}function kF(n,e){let{state:t}=n,r=e??t.selection.main.head,a=t.field(rr).find(i=>i.fromB<=r&&i.endB>=r);if(!a)return!1;let o=t.field(qi).sliceString(a.fromA,Math.max(a.fromA,a.toA-1));return a.fromA!=a.toA&&a.toB<=t.doc.length&&(o+=t.lineBreak),n.dispatch({changes:{from:a.fromB,to:Math.min(t.doc.length,a.toB),insert:o},userEvent:"revert"}),!0}function NC(n){let e=new Wn;for(let t of n.field(rr)){let r=n.facet(mr).overrideChunk&&KC(n,t);e.add(t.fromB,t.fromB,wF(n,t,!!r))}return e.finish()}var SF=bn.define({create:n=>NC(n),update(n,e){return e.state.field(rr,!1)!=e.startState.field(rr,!1)?NC(e.state):n},provide:n=>Ae.decorations.from(n)}),RC=new WeakMap;function KC(n,e){let t=RC.get(e);if(t!==void 0)return t;t=null;let r=n.field(qi),a=n.doc,s=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,o=a.lineAt(e.endB).number-a.lineAt(e.fromB).number+1;e:if(s==o&&s<10){let i=[],l=0,u=e.fromA,c=e.fromB;for(let d of e.changes){if(d.fromA<d.toA){l+=d.toA-d.fromA;let f=r.sliceString(u+d.fromA,u+d.toA);if(/\n/.test(f))break e;i.push(Ke.widget({widget:new Ag(f),side:-1}).range(c+d.fromB))}d.fromB<d.toB&&i.push(qC.range(c+d.fromB,c+d.toB))}l<e.endA-e.fromA-s*2&&(t=i)}return RC.set(e,t),t}var Ag=class extends Rr{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let t=document.createElement("del");return t.className="cm-deletedText",t.textContent=this.text,t}},CF=new class extends En{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},LF=Ke.line({class:"cm-inlineChangedLine"});function IF(n,e,t,r){let a=KC(n,e),s=0;if(!a)return!1;for(let o=n.doc.lineAt(e.fromB);;){for(r&&r.add(o.from,o.from,CF),t.add(o.from,o.from,LF);s<a.length&&a[s].to<=o.to;){let i=a[s++];t.add(i.from,i.to,i.value)}if(o.to>=e.endB)break;o=n.doc.lineAt(o.to+1)}return!0}function XC(n,e){if(!n||!e)return!1;let t=n.getInternalStack(),r=e.getInternalStack();return!t||!r?!1:t.equals(r)}function AF(n,e){return{from:n,to:e,lines:null,startState:null,endState:null,final:!1,stateKnown:!1,lastUsed:0}}var xf=class{constructor(e,t,r,a,s=64,o=4096){this.hl=e;this.lang=t;this.theme=r;this.targetLines=s;this.targetChars=o;this.chunks=[];this.tick=0;this.warned=!1;this.layoutDirty=!0;this.layout(a)}pieces(e,t,r){let a=[],s=t;for(;s<=r;){let o=e.line(s),i=o,l=1,u=o.length;for(;s+l<=r&&l<this.targetLines;){let c=e.line(s+l);if(u+1+c.length>this.targetChars)break;i=c,u+=1+c.length,l+=1}a.push(AF(o.from,i.to)),s+=l}return a}layout(e){this.chunks.length=0,this.chunks.push(...this.pieces(e,1,e.lines))}chunkIndexAt(e){let t=0,r=this.chunks.length-1;for(;t<r;){let a=t+r+1>>1;this.chunks[a].from<=e?t=a:r=a-1}return t}firstLineOf(e,t){return e.lineAt(t.from).number}tokensAt(e,t){return e.lines?.[t]??null}tokensForLine(e,t){let r=e.line(t),a=this.chunks[this.chunkIndexAt(r.from)];return{chunk:a,tokens:this.tokensAt(a,t-this.firstLineOf(e,a))}}lineCountOf(e,t){return e.lineAt(t.to).number-e.lineAt(t.from).number+1}hasPendingWork(e,t){let r=this.firstNonFinal(0);return r>=0&&r<=t||this.rebalanceTarget(e)!==null}firstNonFinal(e){for(let t=Math.max(0,e);t<this.chunks.length;t++)if(!this.chunks[t].final)return t;return-1}tokenize(e,t,r=!0){let a=this.chunks[t],s=t>0?this.chunks[t-1]:null,o=s?.endState??null,i=t===0||!!(s&&s.final&&s.stateKnown),l=e.sliceString(a.from,a.to),u=a.endState,c,d;try{let f=this.hl.codeToTokensBase(l,{lang:this.lang,theme:this.theme,includeExplanation:!1,tokenizeMaxLineLength:2e4,...o?{grammarState:o}:{}});d=this.hl.getLastGrammarState(f)??null,c=f}catch(f){this.warned||(this.warned=!0,console.warn("[Filesystem] shiki chunk tokenization failed",this.lang,f)),c=[],d=null}return a.lines=c,a.startState=o,a.endState=d,a.final=i,a.stateKnown=!0,r&&(a.lastUsed=++this.tick),this.trimWindow(),i&&XC(u,d)}ensureRange(e,t,r,a=16384){let s=!1,o=0,i=this.chunkIndexAt(t),l=Math.min(this.chunks.length-1,this.chunkIndexAt(r)+1);for(let u=i;u<=l;u++){let c=this.chunks[u];if(c.lines){c.lastUsed=++this.tick;continue}if(s&&o+(c.to-c.from)>a)break;this.tokenize(e,u,!0),o+=c.to-c.from,s=!0}return s}idleStep(e,t,r,a=()=>performance.now()){let s=a(),o=null,i=u=>{o=o?{from:Math.min(o.from,u.from),to:Math.max(o.to,u.to)}:{from:u.from,to:u.to}};this.rebalanceOnce(e);let l=this.firstNonFinal(0);for(;l>=0&&l<this.chunks.length&&l<=r;){let u=this.tokenize(e,l,!1);if(i(this.chunks[l]),u){let c=l+1;for(;c<this.chunks.length;c++){let d=this.chunks[c];if(!d.final)if(d.startState&&XC(d.startState,this.chunks[c-1].endState))d.final=!0;else break}l=this.firstNonFinal(c)}else{if(l+1<this.chunks.length&&(this.chunks[l+1].final=!1),l>=r)for(let c=l+2;c<this.chunks.length;c++)this.chunks[c].final=!1;l+=1}if(a()-s>=t)break}return{more:this.hasPendingWork(e,r),touched:o}}applyChanges(e,t){let r=new Set;if(e.iterChangedRanges((i,l)=>{let u=this.chunkIndexAt(i);for(;u<this.chunks.length&&this.chunks[u].from<=l;)r.add(this.chunks[u]),u++}),t.length===0){this.layout(t);return}let a=[],s=0;for(let i=0;i<this.chunks.length;i++){let l=this.chunks[i],u=e.mapPos(l.to,1);if(u>t.length&&(u=t.length),u=t.lineAt(u).to,u<s){let c=a[a.length-1];c&&r.add(c);continue}l.from=s,l.to=u,a.push(l),s=u+1}let o=a[a.length-1];o&&o.to<t.length&&(o.to=t.length,r.add(o));for(let i of r)i.lines=null,i.startState=null,i.final=!1,i.stateKnown=!1;this.chunks.length=0,this.chunks.push(...a),this.layoutDirty=!0,this.splitOversized(t,r)}splitOversized(e,t){for(let r=0;r<this.chunks.length;r++){let a=this.chunks[r];if(!t.has(a))continue;let s=e.lineAt(a.from).number,o=e.lineAt(a.to).number;if(o-s+1<=this.targetLines*2&&a.to-a.from<=this.targetChars*2)continue;let l=this.pieces(e,s,o);if(l.length<2)continue;let u=l[l.length-1];u.endState=a.endState,this.chunks.splice(r,1,...l),r+=l.length-1}}rebalanceTarget(e){if(!this.layoutDirty)return null;let t=this.targetLines;for(let r=0;r+1<this.chunks.length;r++){let a=this.chunks[r],s=this.chunks[r+1],o=this.lineCountOf(e,a),i=a.to-a.from;if(!(o>=t/2||i>=this.targetChars/2)&&!(o+this.lineCountOf(e,s)>t*2)&&!(s.to-a.from>this.targetChars*2))return r}return this.layoutDirty=!1,null}rebalanceOnce(e){let t=this.rebalanceTarget(e);if(t===null)return!1;let r=this.chunks[t],a=this.chunks[t+1];return r.to=a.to,r.endState=a.endState,r.lines=null,r.startState=null,r.final=!1,r.stateKnown=!1,this.chunks.splice(t+1,1),this.layoutDirty=!0,!0}trimWindow(){let e=this.chunks.filter(t=>t.lines);if(!(e.length<=32)){e.sort((t,r)=>t.lastUsed-r.lastUsed);for(let t=0;t<e.length-32;t++)e[t].lines=null}}};var Xs=Ne.define({combine:n=>n.length?n[n.length-1]:{theme:"dark-plus"}}),ZC=xt.define(),RF=8;function YC(n){setTimeout(()=>{try{n.dispatch({effects:ZC.of(null)})}catch{}},0)}function MF(n){let e=globalThis;if(typeof e.requestIdleCallback=="function"){let r=e.requestIdleCallback(n,{timeout:250});return{cancel:()=>e.cancelIdleCallback?.(r)}}let t=setTimeout(n,0);return{cancel:()=>clearTimeout(t)}}var JC=new Map;function TF(n){let e=JC.get(n);return e||(e=Ke.mark({attributes:{style:`color:${n}`}}),JC.set(n,e)),e}var Tg=class{constructor(e){this.decorations=Ke.none;this.engine=null;this.engineKey="";this.idle=null;this.disposed=!1;this.loadKicked=null;this.horizon=0;this.decorations=this.build(e)}update(e){e.docChanged&&this.engine&&this.engine.applyChanges(e.changes,e.state.doc);let t=e.startState.facet(Xs),r=e.state.facet(Xs),a=t.lang!==r.lang||t.theme!==r.theme,s=e.transactions.some(o=>o.effects.some(i=>i.is(ZC)));(e.docChanged||e.viewportChanged||a||s)&&(this.decorations=this.build(e.view))}destroy(){this.disposed=!0,this.idle?.cancel(),this.idle=null,this.engine=null}build(e){let t=e.state.facet(Xs),r=ki(t.lang);if(!r)return this.engine=null,Ke.none;let a=e.state.doc;if(a.length>2e6)return this.engine=null,Ke.none;let s=s1(r);if(!s)return this.loadKicked!==r&&(this.loadKicked=r,nu().then(()=>rd(r)).then(c=>{c&&!this.disposed&&YC(e)})),Ke.none;let o=`${r} ${t.theme}`;(!this.engine||this.engineKey!==o)&&(this.engine=new xf(s,r,t.theme,a),this.engineKey=o);let i=this.engine,l=new Wn,u=0;for(let{from:c,to:d}of e.visibleRanges){i.ensureRange(a,c,d);let f=a.lineAt(c).number,h=a.lineAt(d).number,p=i.chunkIndexAt(d);u=Math.max(u,p+4);for(let m=i.chunkIndexAt(c);m<=p;m++){let g=i.chunks[m],x=i.firstLineOf(a,g),b=a.lineAt(g.to).number;for(let y=Math.max(f,x);y<=Math.min(h,b);y++){let N=i.tokensAt(g,y-x);if(!N)continue;let L=a.line(y);for(let A of N){if(!A.content||!A.color)continue;let w=g.from+A.offset,v=w+A.content.length;w<L.from||w>=v||v>L.to||l.add(w,v,TF(A.color))}}}}return this.horizon=u,i.hasPendingWork(a,u)&&this.scheduleIdle(e),l.finish()}scheduleIdle(e){this.idle||this.disposed||(this.idle=MF(()=>{if(this.idle=null,this.disposed||!this.engine)return;let t=this.engine.idleStep(e.state.doc,RF,this.horizon),r=t.touched;!!r&&e.visibleRanges.some(s=>r.from<=s.to&&r.to>=s.from)?YC(e):t.more&&this.scheduleIdle(e)}))}},yf=pr.fromClass(Tg,{decorations:n=>n.decorations});var bf=Ae.theme({"&":{backgroundColor:"transparent",color:"#d4d4d4",height:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace',fontSize:"12px",lineHeight:"18px"},".cm-content":{padding:"6px 0",caretColor:"#e5e7eb"},".cm-gutters":{backgroundColor:"transparent",border:"none",color:"rgba(255,255,255,0.25)"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px 0 12px",minWidth:"2ch"},".cm-activeLine":{backgroundColor:"rgba(255,255,255,0.035)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"rgba(255,255,255,0.5)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#e5e7eb"},".cm-selectionBackground, .cm-content ::selection":{backgroundColor:"rgba(96,130,255,0.28)"},"&.cm-focused .cm-selectionBackground":{backgroundColor:"rgba(96,130,255,0.34)"},".cm-placeholder":{color:"rgba(255,255,255,0.22)"}},{dark:!0}),QC=Ae.theme({".cm-changedLine":{backgroundColor:"rgba(16,185,129,0.10)"},".cm-changedText":{background:"rgba(16,185,129,0.24)"},".cm-insertedLine":{backgroundColor:"rgba(16,185,129,0.12)"},".cm-deletedChunk":{backgroundColor:"rgba(244,63,94,0.10)"},".cm-deletedChunk .cm-deletedText, .cm-deletedText":{background:"rgba(244,63,94,0.30)"},".cm-changeGutter":{width:"3px"},".cm-changedLineGutter":{backgroundColor:"rgba(16,185,129,0.45)"},".cm-deletedLineGutter":{backgroundColor:"rgba(244,63,94,0.45)"},".cm-merge-a, .cm-merge-b":{backgroundColor:"transparent"},".cm-mergeSpacer":{backgroundColor:"rgba(255,255,255,0.02)"},".cm-merge-revert":{display:"none"}});var eL=j(le(),1);function Dg(n,e){return[Jd(),Lt.readOnly.of(!0),Ae.editable.of(!1),bf,QC,Xs.of({lang:n,theme:e}),yf]}function Fg({oldContent:n,newContent:e,language:t,viewMode:r="unified",className:a,theme:s="dark-plus"}){let o=(0,wf.useRef)(null);return(0,wf.useEffect)(()=>{let i=o.current;if(!i)return;let l;if(r==="split"){let u=new pf({a:{doc:n,extensions:Dg(t,s)},b:{doc:e,extensions:Dg(t,s)},parent:i,gutter:!0,highlightChanges:!0,revertControls:void 0});l=()=>u.destroy()}else{let u=Lt.create({doc:e,extensions:[...Dg(t,s),$C({original:n,mergeControls:!1,gutter:!0,highlightChanges:!0,syntaxHighlightDeletions:!1})]}),c=new Ae({state:u,parent:i});l=()=>c.destroy()}return l},[n,e,t,r,s]),(0,eL.jsx)("div",{ref:o,className:a})}var qn=j(Ve(),1);var DF=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),r=Gg(n.state,t.from);return r.line?FF(n):r.block?OF(n):!1};function Ug(n,e){return({state:t,dispatch:r})=>{if(t.readOnly)return!1;let a=n(e,t);return a?(r(t.update(a)),!0):!1}}var FF=Ug(HF,0);var EF=Ug(uL,0);var OF=Ug((n,e)=>uL(n,e,_F(e)),0);function Gg(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}var zu=50;function BF(n,{open:e,close:t},r,a){let s=n.sliceDoc(r-zu,r),o=n.sliceDoc(a,a+zu),i=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(o)[0].length,u=s.length-i;if(s.slice(u-e.length,u)==e&&o.slice(l,l+t.length)==t)return{open:{pos:r-i,margin:i&&1},close:{pos:a+l,margin:l&&1}};let c,d;a-r<=2*zu?c=d=n.sliceDoc(r,a):(c=n.sliceDoc(r,r+zu),d=n.sliceDoc(a-zu,a));let f=/^\s*/.exec(c)[0].length,h=/\s*$/.exec(d)[0].length,p=d.length-h-t.length;return c.slice(f,f+e.length)==e&&d.slice(p,p+t.length)==t?{open:{pos:r+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:a-h-t.length,margin:/\s/.test(d.charAt(p-1))?1:0}}:null}function _F(n){let e=[];for(let t of n.selection.ranges){let r=n.doc.lineAt(t.from),a=t.to<=r.to?r:n.doc.lineAt(t.to);a.from>r.from&&a.from==t.to&&(a=t.to==r.to+1?r:n.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>r.from?e[s].to=a.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:a.to})}return e}function uL(n,e,t=e.selection.ranges){let r=t.map(s=>Gg(e,s.from).block);if(!r.every(s=>s))return null;let a=t.map((s,o)=>BF(e,r[o],s.from,s.to));if(n!=2&&!a.every(s=>s))return{changes:e.changes(t.map((s,o)=>a[o]?[]:[{from:s.from,insert:r[o].open+" "},{from:s.to,insert:" "+r[o].close}]))};if(n!=1&&a.some(s=>s)){let s=[];for(let o=0,i;o<a.length;o++)if(i=a[o]){let l=r[o],{open:u,close:c}=i;s.push({from:u.pos-l.open.length,to:u.pos+u.margin},{from:c.pos-c.margin,to:c.pos+l.close.length})}return{changes:s}}return null}function HF(n,e,t=e.selection.ranges){let r=[],a=-1;e:for(let{from:s,to:o}of t){let i=r.length,l=1e9,u;for(let c=s;c<=o;){let d=e.doc.lineAt(c);if(u==null&&(u=Gg(e,d.from).line,!u))continue e;if(d.from>a&&(s==o||o>d.from)){a=d.from;let f=/^\s*/.exec(d.text)[0].length,h=f==d.length,p=d.text.slice(f,f+u.length)==u?f:-1;f<d.text.length&&f<l&&(l=f),r.push({line:d,comment:p,token:u,indent:f,empty:h,single:!1})}c=d.to+1}if(l<1e9)for(let c=i;c<r.length;c++)r[c].indent<r[c].line.text.length&&(r[c].indent=l);r.length==i+1&&(r[i].single=!0)}if(n!=2&&r.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:i,token:l,indent:u,empty:c,single:d}of r)(d||!c)&&s.push({from:i.from+u,insert:l+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&r.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:i,token:l}of r)if(i>=0){let u=o.from+i,c=u+l.length;o.text[c-o.from]==" "&&c++,s.push({from:u,to:c})}return{changes:s}}return null}var Og=qr.define(),UF=qr.define(),GF=Ne.define(),cL=Ne.define({combine(n){return Pi(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(r,a)=>e(r,a)||t(r,a)})}}),dL=bn.define({create(){return zo.empty},update(n,e){let t=e.state.facet(cL),r=e.annotation(Og);if(r){let l=pa.fromTransaction(e,r.selection),u=r.side,c=u==0?n.undone:n.done;return l?c=kf(c,c.length,t.minDepth,l):c=mL(c,e.startState.selection),new zo(u==0?r.rest:c,u==0?c:r.rest)}let a=e.annotation(UF);if((a=="full"||a=="before")&&(n=n.isolate()),e.annotation(In.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let s=pa.fromTransaction(e),o=e.annotation(In.time),i=e.annotation(In.userEvent);return s?n=n.addChanges(s,o,i,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,i,t.newGroupDelay)),(a=="full"||a=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new zo(n.done.map(pa.fromJSON),n.undone.map(pa.fromJSON))}});function fL(n={}){return[dL,cL.of(n),Ae.domEventHandlers({beforeinput(e,t){let r=e.inputType=="historyUndo"?hL:e.inputType=="historyRedo"?Bg:null;return r?(e.preventDefault(),r(t)):!1}})]}function Sf(n,e){return function({state:t,dispatch:r}){if(!e&&t.readOnly)return!1;let a=t.field(dL,!1);if(!a)return!1;let s=a.pop(n,t,e);return s?(r(s),!0):!1}}var hL=Sf(0,!1),Bg=Sf(1,!1),zF=Sf(0,!0),WF=Sf(1,!0);var pa=class n{constructor(e,t,r,a,s){this.changes=e,this.effects=t,this.mapped=r,this.startSelection=a,this.selectionsAfter=s}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(a=>a.toJSON())}}static fromJSON(e){return new n(e.changes&&Pn.fromJSON(e.changes),[],e.mapped&&as.fromJSON(e.mapped),e.startSelection&&se.fromJSON(e.startSelection),e.selectionsAfter.map(se.fromJSON))}static fromTransaction(e,t){let r=Yr;for(let a of e.startState.facet(GF)){let s=a(e);s.length&&(r=r.concat(s))}return!r.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),r,void 0,t||e.startState.selection,Yr)}static selection(e){return new n(void 0,Yr,void 0,void 0,e)}};function kf(n,e,t,r){let a=e+1>t+20?e-t-1:0,s=n.slice(a,e);return s.push(r),s}function jF(n,e){let t=[],r=!1;return n.iterChangedRanges((a,s)=>t.push(a,s)),e.iterChangedRanges((a,s,o,i)=>{for(let l=0;l<t.length;){let u=t[l++],c=t[l++];i>=u&&o<=c&&(r=!0)}}),r}function qF(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,r)=>t.empty!=e.ranges[r].empty).length===0}function pL(n,e){return n.length?e.length?n.concat(e):n:e}var Yr=[],VF=200;function mL(n,e){if(n.length){let t=n[n.length-1],r=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-VF));return r.length&&r[r.length-1].eq(e)?n:(r.push(e),kf(n,n.length-1,1e9,t.setSelAfter(r)))}else return[pa.selection([e])]}function $F(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Eg(n,e){if(!n.length)return n;let t=n.length,r=Yr;for(;t;){let a=KF(n[t-1],e,r);if(a.changes&&!a.changes.empty||a.effects.length){let s=n.slice(0,t);return s[t-1]=a,s}else e=a.mapped,t--,r=a.selectionsAfter}return r.length?[pa.selection(r)]:Yr}function KF(n,e,t){let r=pL(n.selectionsAfter.length?n.selectionsAfter.map(i=>i.map(e)):Yr,t);if(!n.changes)return pa.selection(r);let a=n.changes.map(e),s=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(s):s;return new pa(a,xt.mapEffects(n.effects,e),o,n.startSelection.map(s),r)}var XF=/^(input\.type|delete)($|\.)/,zo=class n{constructor(e,t,r=0,a=void 0){this.done=e,this.undone=t,this.prevTime=r,this.prevUserEvent=a}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,r,a,s){let o=this.done,i=o[o.length-1];return i&&i.changes&&!i.changes.empty&&e.changes&&(!r||XF.test(r))&&(!i.selectionsAfter.length&&t-this.prevTime<a.newGroupDelay&&a.joinToEvent(s,jF(i.changes,e.changes))||r=="input.type.compose")?o=kf(o,o.length-1,a.minDepth,new pa(e.changes.compose(i.changes),pL(xt.mapEffects(e.effects,i.changes),i.effects),i.mapped,i.startSelection,Yr)):o=kf(o,o.length,a.minDepth,e),new n(o,Yr,t,r)}addSelection(e,t,r,a){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Yr;return s.length>0&&t-this.prevTime<a&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&qF(s[s.length-1],e)?this:new n(mL(this.done,e),this.undone,t,r)}addMapping(e){return new n(Eg(this.done,e),Eg(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,r){let a=e==0?this.done:this.undone;if(a.length==0)return null;let s=a[a.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(r&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Og.of({side:e,rest:$F(a),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=a.length==1?Yr:a.slice(0,a.length-1);return s.mapped&&(i=Eg(i,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Og.of({side:e,rest:i,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}};zo.empty=new zo(Yr,Yr);var gL=[{key:"Mod-z",run:hL,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Bg,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Bg,preventDefault:!0},{key:"Mod-u",run:zF,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:WF,preventDefault:!0}];function Vi(n,e){return se.create(n.ranges.map(e),n.mainIndex)}function ma(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ga({state:n,dispatch:e},t){let r=Vi(n.selection,t);return r.eq(n.selection,!0)?!1:(e(ma(n,r)),!0)}function Cf(n,e){return se.cursor(e?n.to:n.from)}function xL(n,e){return ga(n,t=>t.empty?n.moveByChar(t,e):Cf(t,e))}function jn(n){return n.textDirectionAt(n.state.selection.main.head)==zt.LTR}var yL=n=>xL(n,!jn(n)),bL=n=>xL(n,jn(n));function wL(n,e){return ga(n,t=>t.empty?n.moveByGroup(t,e):Cf(t,e))}var YF=n=>wL(n,!jn(n)),JF=n=>wL(n,jn(n));var Oj=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function ZF(n,e,t){if(e.type.prop(t))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Lf(n,e,t){let r=us(n).resolveInner(e.head),a=t?st.closedBy:st.openedBy;for(let l=e.head;;){let u=t?r.childAfter(l):r.childBefore(l);if(!u)break;ZF(n,u,a)?r=u:l=t?u.to:u.from}let s=r.type.prop(a),o,i;return s&&(o=t?Ho(n,r.from,1):Ho(n,r.to,-1))&&o.matched?i=t?o.end.to:o.end.from:i=t?r.to:r.from,se.cursor(i,t?-1:1)}var QF=n=>ga(n,e=>Lf(n.state,e,!jn(n))),e5=n=>ga(n,e=>Lf(n.state,e,jn(n)));function vL(n,e){return ga(n,t=>{if(!t.empty)return Cf(t,e);let r=n.moveVertically(t,e);return r.head!=t.head?r:n.moveToLineBoundary(t,e)})}var kL=n=>vL(n,!1),SL=n=>vL(n,!0);function CL(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,r=0,a;if(e){for(let s of n.state.facet(Ae.scrollMargins)){let o=s(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(r=Math.max(o?.bottom,r))}a=n.scrollDOM.clientHeight-t-r}else a=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:r,selfScroll:e,height:Math.max(n.defaultLineHeight,a-5)}}function LL(n,e){let t=CL(n),{state:r}=n,a=Vi(r.selection,o=>o.empty?n.moveVertically(o,e,t.height):Cf(o,e));if(a.eq(r.selection))return!1;let s;if(t.selfScroll){let o=n.coordsAtPos(r.selection.main.head),i=n.scrollDOM.getBoundingClientRect(),l=i.top+t.marginTop,u=i.bottom-t.marginBottom;o&&o.top>l&&o.bottom<u&&(s=Ae.scrollIntoView(a.main.head,{y:"start",yMargin:o.top-l}))}return n.dispatch(ma(r,a),{effects:s}),!0}var tL=n=>LL(n,!1),_g=n=>LL(n,!0);function Ys(n,e,t){let r=n.lineBlockAt(e.head),a=n.moveToLineBoundary(e,t);if(a.head==e.head&&a.head!=(t?r.to:r.from)&&(a=n.moveToLineBoundary(e,t,!1)),!t&&a.head==r.from&&r.length){let s=/^\s*/.exec(n.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;s&&e.head!=r.from+s&&(a=se.cursor(r.from+s))}return a}var t5=n=>ga(n,e=>Ys(n,e,!0)),n5=n=>ga(n,e=>Ys(n,e,!1)),r5=n=>ga(n,e=>Ys(n,e,!jn(n))),a5=n=>ga(n,e=>Ys(n,e,jn(n))),s5=n=>ga(n,e=>n.moveToLineBoundary(e,!1,!1)),o5=n=>ga(n,e=>n.moveToLineBoundary(e,!0,!1));function i5(n,e,t){let r=!1,a=Vi(n.selection,s=>{let o=Ho(n,s.head,-1)||Ho(n,s.head,1)||s.head>0&&Ho(n,s.head-1,1)||s.head<n.doc.length&&Ho(n,s.head+1,-1);if(!o||!o.end)return s;r=!0;let i=o.start.from==s.head?o.end.to:o.end.from;return t?se.range(s.anchor,i):se.cursor(i)});return r?(e(ma(n,a)),!0):!1}var l5=({state:n,dispatch:e})=>i5(n,e,!1);function Jr(n,e,t){let r=Vi(n.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=se.range(a.head,a.anchor));let s=t(a);return se.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return r.eq(n.state.selection)?!1:(n.dispatch(ma(n.state,r)),!0)}function IL(n,e){return Jr(n,e,t=>n.moveByChar(t,e))}var AL=n=>IL(n,!jn(n)),PL=n=>IL(n,jn(n));function NL(n,e){return Jr(n,e,t=>n.moveByGroup(t,e))}var u5=n=>NL(n,!jn(n)),c5=n=>NL(n,jn(n));var d5=n=>{let e=!jn(n);return Jr(n,e,t=>Lf(n.state,t,e))},f5=n=>{let e=jn(n);return Jr(n,e,t=>Lf(n.state,t,e))};function RL(n,e){return Jr(n,e,t=>n.moveVertically(t,e))}var ML=n=>RL(n,!1),TL=n=>RL(n,!0);function DL(n,e){return Jr(n,e,t=>n.moveVertically(t,e,CL(n).height))}var nL=n=>DL(n,!1),rL=n=>DL(n,!0),h5=n=>Jr(n,!0,e=>Ys(n,e,!0)),p5=n=>Jr(n,!1,e=>Ys(n,e,!1)),m5=n=>{let e=!jn(n);return Jr(n,e,t=>Ys(n,t,e))},g5=n=>{let e=jn(n);return Jr(n,e,t=>Ys(n,t,e))},x5=n=>Jr(n,!1,e=>se.cursor(n.lineBlockAt(e.head).from)),y5=n=>Jr(n,!0,e=>se.cursor(n.lineBlockAt(e.head).to)),aL=({state:n,dispatch:e})=>(e(ma(n,{anchor:0})),!0),sL=({state:n,dispatch:e})=>(e(ma(n,{anchor:n.doc.length})),!0),oL=({state:n,dispatch:e})=>(e(ma(n,{anchor:n.selection.main.anchor,head:0})),!0),iL=({state:n,dispatch:e})=>(e(ma(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),b5=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),w5=({state:n,dispatch:e})=>{let t=If(n).map(({from:r,to:a})=>se.undirectionalRange(r,Math.min(a+1,n.doc.length)));return e(n.update({selection:se.create(t),userEvent:"select"})),!0},v5=({state:n,dispatch:e})=>{let t=Vi(n.selection,r=>{let a=us(n),s=a.resolveStack(r.from,1);if(r.empty){let o=a.resolveStack(r.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:i}=o;if((i.from<r.from&&i.to>=r.to||i.to>r.to&&i.from<=r.from)&&o.next)return se.undirectionalRange(i.from,i.to)}return r});return t.eq(n.selection)?!1:(e(ma(n,t)),!0)};function FL(n,e){let{state:t}=n,r=t.selection,a=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<n.state.doc.length:o.from>0)for(let i=s;;){let l=n.moveVertically(i,e);if(l.head<o.from||l.head>o.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==i.head)break;i=l}}}return a.length==r.ranges.length?!1:(n.dispatch(ma(t,se.create(a,a.length-1))),!0)}var k5=n=>FL(n,!1),S5=n=>FL(n,!0),C5=({state:n,dispatch:e})=>{let t=n.selection,r=null;return t.ranges.length>1?r=se.create([t.main]):t.main.empty||(r=se.create([se.cursor(t.main.head)])),r?(e(ma(n,r)),!0):!1};function Wu(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:r}=n,a=r.changeByRange(s=>{let{from:o,to:i}=s;if(o==i){let l=e(s);l<o?(t="delete.backward",l=vf(n,l,!1)):l>o&&(t="delete.forward",l=vf(n,l,!0)),o=Math.min(o,l),i=Math.max(i,l)}else o=vf(n,o,!1),i=vf(n,i,!0);return o==i?{range:s}:{changes:{from:o,to:i},range:se.cursor(o,o<s.head?-1:1)}});return a.changes.empty?!1:(n.dispatch(r.update(a,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?Ae.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function vf(n,e,t){if(n instanceof Ae)for(let r of n.state.facet(Ae.atomicRanges).map(a=>a(n)))r.between(e,e,(a,s)=>{a<e&&s>e&&(e=t?s:a)});return e}var EL=(n,e,t)=>Wu(n,r=>{let a=r.from,{state:s}=n,o=s.doc.lineAt(a),i,l;if(t&&!e&&a>o.from&&a<o.from+200&&!/[^ \t]/.test(i=o.text.slice(0,a-o.from))){if(i[i.length-1]==" ")return a-1;let u=Ao(i,s.tabSize),c=u%Bu(s)||Bu(s);for(let d=0;d<c&&i[i.length-1-d]==" ";d++)a--;l=a}else l=An(o.text,a-o.from,e,e)+o.from,l==a&&o.number!=(e?s.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(l-o.from,a-o.from))&&(l=An(o.text,l-o.from,!1,!1)+o.from);return l}),Hg=n=>EL(n,!1,!0);var OL=n=>EL(n,!0,!1),BL=(n,e)=>Wu(n,t=>{let r=t.head,{state:a}=n,s=a.doc.lineAt(r),o=a.charCategorizer(r);for(let i=null;;){if(r==(e?s.to:s.from)){r==t.head&&s.number!=(e?a.doc.lines:1)&&(r+=e?1:-1);break}let l=An(s.text,r-s.from,e)+s.from,u=s.text.slice(Math.min(r,l)-s.from,Math.max(r,l)-s.from),c=o(u);if(i!=null&&c!=i)break;(u!=" "||r!=t.head)&&(i=c),r=l}return r}),_L=n=>BL(n,!1),L5=n=>BL(n,!0);var I5=n=>Wu(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var A5=n=>Wu(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),P5=n=>Wu(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)});var N5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:it.of(["",""])},range:se.cursor(r.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},R5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(r=>{if(!r.empty||r.from==0||r.from==n.doc.length)return{range:r};let a=r.from,s=n.doc.lineAt(a),o=a==s.from?a-1:An(s.text,a-s.from,!1)+s.from,i=a==s.to?a+1:An(s.text,a-s.from,!0)+s.from;return{changes:{from:o,to:i,insert:n.doc.slice(a,i).append(n.doc.slice(o,a))},range:se.cursor(i)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function If(n){let e=[],t=-1;for(let r of n.selection.ranges){let a=n.doc.lineAt(r.from),s=n.doc.lineAt(r.to);if(!r.empty&&r.to==s.from&&(s=n.doc.lineAt(r.to-1)),t>=a.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(r)}else e.push({from:a.from,to:s.to,ranges:[r]});t=s.number+1}return e}function HL(n,e,t){if(n.readOnly)return!1;let r=[],a=[];for(let s of If(n)){if(t?s.to==n.doc.length:s.from==0)continue;let o=n.doc.lineAt(t?s.to+1:s.from-1),i=o.length+1;if(t){r.push({from:s.to,to:o.to},{from:s.from,insert:o.text+n.lineBreak});for(let l of s.ranges)a.push(se.range(Math.min(n.doc.length,l.anchor+i),Math.min(n.doc.length,l.head+i)))}else{r.push({from:o.from,to:s.from},{from:s.to,insert:n.lineBreak+o.text});for(let l of s.ranges)a.push(se.range(l.anchor-i,l.head-i))}}return r.length?(e(n.update({changes:r,scrollIntoView:!0,selection:se.create(a,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var M5=({state:n,dispatch:e})=>HL(n,e,!1),T5=({state:n,dispatch:e})=>HL(n,e,!0);function UL(n,e,t){if(n.readOnly)return!1;let r=[];for(let s of If(n))t?r.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):r.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});let a=n.changes(r);return e(n.update({changes:a,selection:n.selection.map(a,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var D5=({state:n,dispatch:e})=>UL(n,e,!1),F5=({state:n,dispatch:e})=>UL(n,e,!0),E5=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(If(e).map(({from:a,to:s})=>(a>0?a--:s<e.doc.length&&s++,{from:a,to:s}))),r=Vi(e.selection,a=>{let s;if(n.lineWrapping){let o=n.lineBlockAt(a.head),i=n.coordsAtPos(a.head,a.assoc||1);i&&(s=o.bottom+n.documentTop-i.bottom+n.defaultLineHeight/2)}return n.moveVertically(a,!0,s)}).map(t);return n.dispatch({changes:t,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function O5(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=us(n).resolveInner(e),r=t.childBefore(e),a=t.childAfter(e),s;return r&&a&&r.to<=e&&a.from>=e&&(s=r.type.prop(st.closedBy))&&s.indexOf(a.name)>-1&&n.doc.lineAt(r.to).from==n.doc.lineAt(a.from).from&&!/\S/.test(n.sliceDoc(r.to,a.from))?{from:r.to,to:a.from}:null}var lL=GL(!1),B5=GL(!0);function GL(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=e.changeByRange(a=>{let{from:s,to:o}=a,i=e.doc.lineAt(s),l=!n&&s==o&&O5(e,s);n&&(s=o=(o<=i.to?i:e.doc.lineAt(o)).to);let u=new _o(e,{simulateBreak:s,simulateDoubleBreak:!!l}),c=bg(u,s);for(c==null&&(c=Ao(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<i.to&&/\s/.test(i.text[o-i.from]);)o++;l?{from:s,to:o}=l:s>i.from&&s<i.from+100&&!/\S/.test(i.text.slice(0,s))&&(s=i.from);let d=["",_u(e,c)];return l&&d.push(_u(e,u.lineIndent(i.from,-1))),{changes:{from:s,to:o,insert:it.of(d)},range:se.cursor(s+1+d[1].length)}});return t(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function zg(n,e){let t=-1;return n.changeByRange(r=>{let a=[];for(let o=r.from;o<=r.to;){let i=n.doc.lineAt(o);i.number>t&&(r.empty||r.to>i.from)&&(e(i,a,r),t=i.number),o=i.to+1}let s=n.changes(a);return{changes:a,range:se.range(s.mapPos(r.anchor,1),s.mapPos(r.head,1))}})}var _5=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),r=new _o(n,{overrideIndentation:s=>{let o=t[s];return o??-1}}),a=zg(n,(s,o,i)=>{let l=bg(r,s.from);if(l==null)return;/\S/.test(s.text)||(l=0);let u=/^\s*/.exec(s.text)[0],c=_u(n,l);(u!=c||i.from<s.from+u.length)&&(t[s.from]=l,o.push({from:s.from,to:s.from+u.length,insert:c}))});return a.changes.empty||e(n.update(a,{userEvent:"indent"})),!0},zL=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(zg(n,(t,r)=>{r.push({from:t.from,insert:n.facet(of)})}),{userEvent:"input.indent"})),!0),WL=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(zg(n,(t,r)=>{let a=/^\s*/.exec(t.text)[0];if(!a)return;let s=Ao(a,n.tabSize),o=0,i=_u(n,Math.max(0,s-Bu(n)));for(;o<a.length&&o<i.length&&a.charCodeAt(o)==i.charCodeAt(o);)o++;r.push({from:t.from+o,to:t.from+a.length,insert:i.slice(o)})}),{userEvent:"delete.dedent"})),!0),H5=n=>(n.setTabFocusMode(),!0);var U5=[{key:"Ctrl-b",run:yL,shift:AL,preventDefault:!0},{key:"Ctrl-f",run:bL,shift:PL},{key:"Ctrl-p",run:kL,shift:ML},{key:"Ctrl-n",run:SL,shift:TL},{key:"Ctrl-a",run:s5,shift:x5},{key:"Ctrl-e",run:o5,shift:y5},{key:"Ctrl-d",run:OL},{key:"Ctrl-h",run:Hg},{key:"Ctrl-k",run:I5},{key:"Ctrl-Alt-h",run:_L},{key:"Ctrl-o",run:N5},{key:"Ctrl-t",run:R5},{key:"Ctrl-v",run:_g}],G5=[{key:"ArrowLeft",run:yL,shift:AL,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:YF,shift:u5,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:r5,shift:m5,preventDefault:!0},{key:"ArrowRight",run:bL,shift:PL,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:JF,shift:c5,preventDefault:!0},{mac:"Cmd-ArrowRight",run:a5,shift:g5,preventDefault:!0},{key:"ArrowUp",run:kL,shift:ML,preventDefault:!0},{mac:"Cmd-ArrowUp",run:aL,shift:oL},{mac:"Ctrl-ArrowUp",run:tL,shift:nL},{key:"ArrowDown",run:SL,shift:TL,preventDefault:!0},{mac:"Cmd-ArrowDown",run:sL,shift:iL},{mac:"Ctrl-ArrowDown",run:_g,shift:rL},{key:"PageUp",run:tL,shift:nL},{key:"PageDown",run:_g,shift:rL},{key:"Home",run:n5,shift:p5,preventDefault:!0},{key:"Mod-Home",run:aL,shift:oL},{key:"End",run:t5,shift:h5,preventDefault:!0},{key:"Mod-End",run:sL,shift:iL},{key:"Enter",run:lL,shift:lL},{key:"Mod-a",run:b5},{key:"Backspace",run:Hg,shift:Hg,preventDefault:!0},{key:"Delete",run:OL,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:_L,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:L5,preventDefault:!0},{mac:"Mod-Backspace",run:A5,preventDefault:!0},{mac:"Mod-Delete",run:P5,preventDefault:!0}].concat(U5.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),jL=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:QF,shift:d5},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:e5,shift:f5},{key:"Alt-ArrowUp",run:M5},{key:"Shift-Alt-ArrowUp",run:D5},{key:"Alt-ArrowDown",run:T5},{key:"Shift-Alt-ArrowDown",run:F5},{key:"Mod-Alt-ArrowUp",run:k5},{key:"Mod-Alt-ArrowDown",run:S5},{key:"Escape",run:C5},{key:"Mod-Enter",run:B5},{key:"Alt-l",mac:"Ctrl-l",run:w5},{key:"Mod-i",run:v5,preventDefault:!0},{key:"Mod-[",run:WL},{key:"Mod-]",run:zL},{key:"Mod-Alt-\\",run:_5},{key:"Shift-Mod-k",run:E5},{key:"Shift-Mod-\\",run:l5},{key:"Mod-/",run:DF},{key:"Alt-A",mac:"Ctrl-A",run:EF},{key:"Ctrl-m",mac:"Shift-Alt-m",run:H5}].concat(G5),qL={key:"Tab",run:zL,shift:WL};var z5={lines:new Map,deletedBefore:new Set},VL=xt.define(),$L=bn.define({create:()=>z5,update(n,e){for(let t of e.effects)if(t.is(VL))return t.value;return n}}),ju=class extends En{constructor(t){super();this.kind=t}eq(t){return t.kind===this.kind}toDOM(){let t=document.createElement("div");return this.kind==="deleted"?t.style.cssText="width:0;height:0;margin-left:2px;border-left:4px solid rgba(244,63,94,0.85);border-top:3px solid transparent;border-bottom:3px solid transparent;":t.style.cssText=`width:2px;height:100%;margin-left:3px;border-radius:1px;background:${this.kind==="added"?"rgba(16,185,129,0.9)":"rgba(59,130,246,0.9)"};`,t}},W5=new ju("added"),j5=new ju("modified"),q5=new ju("deleted"),V5=zi({class:"nrs-cm-git-gutter",lineMarker(n,e){let t=n.state.field($L,!1);if(!t)return null;let r=n.state.doc.lineAt(e.from).number,a=t.lines.get(r);return a==="added"?W5:a==="modified"?j5:t.deletedBefore.has(r)?q5:null},lineMarkerChange:n=>n.transactions.some(e=>e.effects.some(t=>t.is(VL)))});function KL(n){return[$L.init(()=>n),V5]}var XL=j(le(),1);function Wg({value:n,language:e,readOnly:t=!1,wrap:r=!1,onChange:a,className:s,placeholder:o,ariaLabel:i,theme:l="dark-plus",gitLineStatus:u}){let c=(0,qn.useRef)(null),d=(0,qn.useRef)(null),f=(0,qn.useRef)(a),h=(0,qn.useRef)(!1),p=(0,qn.useRef)(new jr),m=(0,qn.useRef)(new jr),g=(0,qn.useRef)(new jr),x=(0,qn.useRef)(new jr);return f.current=a,(0,qn.useEffect)(()=>{let b=c.current;if(!b)return;let y=Lt.create({doc:n,extensions:[Jd(),qS(),KS(),WS(),fL(),Jm.of([...jL,...gL,qL]),bf,p.current.of(Xs.of({lang:e,theme:l})),yf,m.current.of([Lt.readOnly.of(t),Ae.editable.of(!t)]),g.current.of(r?Ae.lineWrapping:[]),x.current.of([]),o?VS(o):[],Ae.updateListener.of(L=>{L.docChanged&&!h.current&&f.current?.(L.state.doc.toString())}),Ae.contentAttributes.of(i?{"aria-label":i}:{})]}),N=new Ae({state:y,parent:b});return d.current=N,()=>{N.destroy(),d.current=null}},[]),(0,qn.useEffect)(()=>{let b=d.current;if(!b)return;let y=b.state.doc.toString();n!==y&&(h.current=!0,b.dispatch({changes:{from:0,to:y.length,insert:n}}),h.current=!1)},[n]),(0,qn.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:p.current.reconfigure(Xs.of({lang:e,theme:l}))})},[e,l]),(0,qn.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:m.current.reconfigure([Lt.readOnly.of(t),Ae.editable.of(!t)])})},[t]),(0,qn.useEffect)(()=>{let b=d.current;b&&b.dispatch({effects:g.current.reconfigure(r?Ae.lineWrapping:[])})},[r]),(0,qn.useEffect)(()=>{let b=d.current;if(!b)return;let y=u&&!dd(u)?KL(u):[];b.dispatch({effects:x.current.reconfigure(y)})},[u]),(0,XL.jsx)("div",{ref:c,className:s})}var $i=j(Ve(),1);var YL=j(le(),1);function jg({target:n,agentId:e,projectId:t}){let[r,a]=(0,$i.useState)(!1),s=_(i=>i.sourceChangeRevision[n.source]??0);(0,$i.useEffect)(()=>{let i=!0;return a(!1),e&&Xo({agentId:e,...t?{projectId:t}:{},source:n.source}).then(l=>{i&&a(l.repos.find(u=>u.rel===(n.repo??""))?.canWrite===!0)}).catch(()=>{i&&a(!1)}),()=>{i=!1}},[e,t,n.source,n.repo,s]);let o=(0,$i.useMemo)(()=>Jv(n),[n]);return(0,YL.jsx)(wo,{source:n.source,repo:n.repo??"",path:n.path,mode:o,agentId:e,projectId:t,variant:"tab",canWrite:r,revision:s})}var Ha=j(Ve(),1);var dt=j(le(),1),JL="brain://docs",qg=V("h-7 w-full rounded-md px-2 text-[10px] outline-none transition font-mono","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),$5=V(qg,"pr-6");function Vg(n){let{agentId:e,projectId:t}=n,r=_(w=>w.workspacePanels.upload),a=_(w=>w.setWorkspacePanelOpen),s=_(w=>w.uploading),o=_(w=>w.uploadMany),i=_(w=>w.files),l=_(w=>w.activeFolderPath),u=_(w=>w.setActiveFolderPath),[c,d]=(0,Ha.useState)(""),[f,h]=(0,Ha.useState)(""),[p,m]=(0,Ha.useState)(!1),[g,x]=(0,Ha.useState)(!1),b=(0,Ha.useRef)(null),y=(0,Ha.useMemo)(()=>{let w=c.trim();return w||l||JL},[l,c]),N=(0,Ha.useMemo)(()=>{let w=new Set;for(let v of Object.values(i||{})){if(v?.type!=="folder")continue;let T=String(v.uri||"");T&&w.add(T)}return w.add(JL),Array.from(w).sort((v,T)=>v.localeCompare(T))},[i]),L=w=>{let v=w.trim();v&&(d(v),u(v))},A=async w=>{if(w.length!==0)try{await o({agentId:e,projectId:t,files:w,uri:y})}finally{b.current&&(b.current.value=""),m(!1),a("upload",!1)}};return r?(0,dt.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,dt.jsx)("input",{ref:b,type:"file",multiple:!0,className:"hidden",onChange:async w=>{let v=Array.from(w.target.files||[]);await A(v)}}),(0,dt.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,dt.jsxs)("div",{className:"flex items-center gap-2",children:[s?(0,dt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-300/70 shrink-0"}):(0,dt.jsx)(Ia,{className:"h-4 w-4 text-cyan-300/70 shrink-0"}),(0,dt.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Upload"}),(0,dt.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-white/45 bg-white/[0.04] font-mono truncate max-w-[160px]",children:y})]}),(0,dt.jsx)("button",{type:"button",onClick:()=>a("upload",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]}),(0,dt.jsx)("div",{className:V("mt-2 rounded-md border border-dashed px-4 py-5 text-center transition",p?"border-cyan-300/40 bg-cyan-400/[0.04]":"border-white/[0.10] bg-white/[0.02]",s&&"opacity-60"),onDragEnter:w=>{s||(w.preventDefault(),m(!0))},onDragOver:w=>{s||(w.preventDefault(),w.dataTransfer.dropEffect="copy",m(!0))},onDragLeave:w=>{w.currentTarget.contains(w.relatedTarget)||m(!1)},onDrop:async w=>{s||(w.preventDefault(),await A(Array.from(w.dataTransfer.files||[])))},children:(0,dt.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[s?(0,dt.jsx)(We,{className:"h-4 w-4 animate-spin text-cyan-200/80"}):(0,dt.jsx)(Ia,{className:"h-4 w-4 text-cyan-200/70"}),(0,dt.jsx)("span",{className:"text-[11px] text-white/60",children:s?"Uploading...":"Drop files here"}),(0,dt.jsxs)("button",{type:"button",onClick:()=>b.current?.click(),disabled:s,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/20 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed inline-flex items-center gap-1",children:[(0,dt.jsx)(Nl,{className:"h-2.5 w-2.5"}),"Choose files"]})]})}),(0,dt.jsxs)("div",{className:"mt-1",children:[(0,dt.jsxs)("button",{type:"button",onClick:()=>x(w=>!w),className:"w-full flex items-center gap-2 py-1.5 text-left hover:bg-white/[0.02] rounded-md px-1 transition",children:[(0,dt.jsx)(Cr,{className:"h-3.5 w-3.5 text-violet-400/70 shrink-0"}),(0,dt.jsx)("span",{className:"text-[11px] font-semibold text-white/88",children:"Destination"}),(0,dt.jsx)("span",{className:"text-[9px] text-white/35 font-mono truncate",children:y}),(0,dt.jsx)(Tt,{className:V("ml-auto h-3 w-3 text-white/25 shrink-0 transition-transform",g&&"rotate-180")})]}),(0,dt.jsx)("div",{className:V("overflow-hidden transition-all duration-200",g?"max-h-[300px] opacity-100":"max-h-0 opacity-0"),children:(0,dt.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-2.5 ml-5 mb-1 space-y-2",children:[(0,dt.jsxs)("div",{className:"space-y-1",children:[(0,dt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Folder"}),(0,dt.jsx)("select",{value:y,onChange:w=>L(w.target.value),disabled:s,className:$5,children:N.map(w=>(0,dt.jsx)("option",{value:w,className:"bg-[#1a1a1f]",children:w},w))})]}),(0,dt.jsxs)("div",{className:"space-y-1",children:[(0,dt.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Override"}),(0,dt.jsx)("input",{value:c,onChange:w=>d(w.target.value),placeholder:y,disabled:s,className:qg})]}),(0,dt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,dt.jsx)("input",{value:f,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&(w.preventDefault(),L(f),h(""))},placeholder:"brain://docs/new-folder",disabled:s,className:V(qg,"flex-1")}),(0,dt.jsxs)("button",{type:"button",disabled:s||!f.trim(),onClick:()=>{L(f),h("")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-white/60 hover:text-white/85 transition disabled:opacity-35 disabled:cursor-not-allowed inline-flex items-center gap-1 shrink-0",children:[(0,dt.jsx)(Cr,{className:"h-2.5 w-2.5"}),"Use"]})]})]})})]})]}):null}var Le=j(Ve(),1);var Qg=j(wr(),1);function K5(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}var X5=new Set(["path","container-path","host-path"]);function ZL(n){let e=K5(n),t=e.properties.root,r=t?.["x-neuralis"]?.ui,a=typeof r?.control=="string"?r.control:void 0;return{needed:!!(t&&(e.required.includes("root")||a&&X5.has(a))),container:a!=="host-path",label:typeof r?.label=="string"?r.label:"Path",placeholder:typeof r?.placeholder=="string"?r.placeholder:""}}var on=j(Ve(),1);var eI=j(wr(),1);var Se=j(le(),1);function QL(n){if(!n)return null;let e=`${n.missing} missing \xB7 ${n.stale} stale`;return n.enabled?n.mode!=="dense"?`Semantic: metadata only \u2014 no embedding model active (${e})`:`Semantic: dense (${e})`:`Semantic: off \u2014 text and field search only (${e} if turned on)`}var Ki={gc:{label:"GC",explainer:"Removes records marked as deleted, older than the retention window.",tooltip:"Garbage-collect deleted records past the retention threshold (default 24h). Keeps recent deletions in case you want to restore.",destructive:!0},"repair-orphans":{label:"Repair",explainer:"Removes chunks whose parent document no longer exists or is deleted.",tooltip:"Drops orphaned chunks (parent file gone / deleted). Safe to run anytime \u2014 these chunks have no path back to a real file.",destructive:!0},"repair-pending":{label:"Repair pending",explainer:"Discards your pending changes whose file is gone with nothing to restore; counts older changes that need a review in Changes.",tooltip:"Run with Dry run first to see the counts. Only your own visible pending changes are touched; older changes with an unknown original are only reported \u2014 confirm them in the Changes panel. Nothing is reindexed.",destructive:!0},deduplicate:{label:"Deduplicate",explainer:"Reports document groups with identical content hash (read-only \u2014 no delete).",tooltip:"Lists documents that share a content hash. Read-only; nothing is removed.",destructive:!1}};function tI({agentId:n,projectId:e}){let t=fn(),r=Za({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),[a,s]=(0,on.useState)(null),[o,i]=(0,on.useState)(null),[l,u]=(0,on.useState)(!1),[c,d]=(0,on.useState)(!1),[f,h]=(0,on.useState)(null),[p,m]=(0,on.useState)(null),[g,x]=(0,on.useState)(null),[b,y]=(0,on.useState)(null),[N,L]=(0,on.useState)(!1),[A,w]=(0,on.useState)(!1),[v,T]=(0,on.useState)(24),[P,O]=(0,on.useState)(null),C=(0,on.useRef)(null),I=(0,on.useCallback)(async()=>{u(!0),x(null);try{let[S,M]=await Promise.all([dx({agentId:n,...e?{projectId:e}:{}}),kx({agentId:n,...e?{projectId:e}:{}}).catch(()=>[])]),W=new Map;for(let te of M)W.set(te.source,{...te.last_sync?{last_sync:te.last_sync}:{},sync_status:te.sync_status});let ee=S;ee.perSource&&(ee.perSource=ee.perSource.map(te=>{let re=W.get(te.source);return re?{...te,...re}:te})),s(ee)}catch(S){x(S instanceof Error?S.message:"Failed to fetch health report")}finally{u(!1)}},[n,e]),H=(0,on.useCallback)(async()=>{L(!0),x(null);try{let S=await fx({agentId:n,...e?{projectId:e}:{}});y({orphanChunkCount:S.orphanChunkCount??0,duplicateGroups:S.duplicateGroups??0})}catch(S){x(S instanceof Error?S.message:"Scan failed")}finally{L(!1)}},[n,e]),q=(0,on.useCallback)(async S=>{if(!A&&Ki[S].destructive&&P!==S){O(S),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>O(null),3e3);return}C.current&&(clearTimeout(C.current),C.current=null),O(null),d(!0),h(null),m(S),x(null),i(A?null:a);try{let M=await hx({agentId:n,...e?{projectId:e}:{},action:S,dryRun:A,retentionHours:v});h(M),A||(I(),b&&H())}catch(M){x(M instanceof Error?M.message:"Action failed")}finally{d(!1)}},[n,e,A,v,I,P,a,b,H]);(0,on.useEffect)(()=>{I()},[I]),(0,on.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);function $(S){if(!o||!a)return null;let M=o[S]??0,W=a[S]??0;if(M===W)return null;let ee=M-W,te=ee>0?"\u2212":"+";return`${M} \u2192 ${W} (${te}${Math.abs(ee)})`}return(0,Se.jsxs)("div",{className:"space-y-3 px-2 pb-2",children:[(0,Se.jsxs)("div",{className:"text-[10px] text-white/40 italic leading-relaxed",children:["Cleanup tool for the vector index. Removes leftover records:"," ",(0,Se.jsx)("span",{className:"text-white/60",children:"deleted documents past retention"}),","," ",(0,Se.jsx)("span",{className:"text-white/60",children:"orphaned chunks (no parent file)"}),", and reports"," ",(0,Se.jsx)("span",{className:"text-white/60",children:"duplicate documents"})," (same content hash). To clear ALL vectors of a single source, use the"," ",(0,Se.jsx)("span",{className:"text-rose-300/80",children:"Delete"})," button on that source instead."]}),l&&(0,Se.jsxs)("div",{className:"text-[10px] text-white/40 flex items-center gap-1.5",children:[(0,Se.jsx)(Ot,{className:"h-3 w-3 animate-spin text-blue-400"})," Loading..."]}),g&&(0,Se.jsx)("div",{className:"rounded-md bg-red-500/8 px-2.5 py-1.5 text-[10px] text-red-200/80",children:g}),a&&(0,Se.jsxs)(Se.Fragment,{children:[(0,Se.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5",children:[{label:"Documents",value:a.documentCount??0,color:"text-emerald-400",delta:null},{label:"Chunks",value:a.chunkCount??0,color:"text-cyan-400",delta:null},{label:"Deleted",value:a.deletedCount??0,color:(a.deletedCount??0)>0?"text-red-400":"text-white/60",delta:p==="gc"?$("deletedCount"):null},{label:"Orphans",value:b?b.orphanChunkCount??0:"\u2014",color:(b?.orphanChunkCount??0)>0?"text-amber-400":"text-white/60",delta:null}].map(S=>(0,Se.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2 py-1.5 text-center",children:[(0,Se.jsx)("div",{className:V("text-sm font-semibold",S.color),children:S.value}),(0,Se.jsx)("div",{className:"text-[9px] text-white/40",children:S.label}),S.delta&&(0,Se.jsx)("div",{className:"text-[8px] text-emerald-300/70 mt-0.5 tabular-nums",children:S.delta})]},S.label))}),QL(a.embedding)&&(0,Se.jsx)("div",{className:"text-[9px] text-white/45",role:"status",children:QL(a.embedding)}),(0,Se.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/35",children:[(0,Se.jsxs)("span",{children:["Total points: ",a.totalPoints??"-"]}),(0,Se.jsxs)("span",{children:["Duplicate groups: ",b?b.duplicateGroups??0:"\u2014"]}),a.generatedAt&&(()=>{let S=Date.now()-new Date(a.generatedAt).getTime(),M=Math.floor(S/6e4),W=Math.floor(M/60),ee=M<1?"just now":W<1?`${M}m ago`:`${W}h ${M%60}m ago`,te=W<1?"text-emerald-400/60":"text-amber-400/60";return(0,Se.jsxs)("span",{className:te,children:["Generated: ",ee]})})()]}),a.perSource&&a.perSource.length>0&&(0,Se.jsx)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg overflow-hidden",children:(0,Se.jsxs)("table",{className:"w-full text-[10px]",children:[(0,Se.jsx)("thead",{children:(0,Se.jsxs)("tr",{className:"border-b border-white/[0.06]",children:[(0,Se.jsx)("th",{className:"text-left px-2 py-1.5 text-white/40 font-medium",children:"Source"}),(0,Se.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Docs"}),(0,Se.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Chunks"}),(0,Se.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Deleted"}),(0,Se.jsx)("th",{className:"text-right px-2 py-1.5 text-white/40 font-medium",children:"Last sync"})]})}),(0,Se.jsx)("tbody",{children:a.perSource.map((S,M)=>{let W=S.source.includes(":")?S.source.split(":")[0]:S.source,ee=W==="local"?"text-cyan-400/60":W==="github"?"text-amber-400/60":"text-violet-400/60",te=(()=>{if(!S.last_sync)return S.sync_status==="idle"?"\u2014":S.sync_status??"\u2014";let ce=new Date(S.last_sync).getTime();if(Number.isNaN(ce))return S.last_sync;let oe=Math.floor((Date.now()-ce)/6e4);if(oe<1)return"just now";if(oe<60)return`${oe}m ago`;let ue=Math.floor(oe/60);return ue<24?`${ue}h ago`:`${Math.floor(ue/24)}d ago`})(),re=S.last_sync?S.sync_status==="error"?"text-rose-300/60":S.sync_status==="paused"?"text-amber-300/60":"text-emerald-300/60":"text-white/35";return(0,Se.jsxs)("tr",{className:V("border-b border-white/[0.03] last:border-0",M%2===1&&"bg-white/[0.02]"),children:[(0,Se.jsxs)("td",{className:"px-2 py-1 text-white/70 font-mono flex items-center gap-1.5",children:[(0,Se.jsx)(Un,{className:V("h-2.5 w-2.5 shrink-0",ee)}),S.source]}),(0,Se.jsx)("td",{className:"px-2 py-1 text-right text-emerald-300/60",children:S.documents}),(0,Se.jsx)("td",{className:"px-2 py-1 text-right text-cyan-300/60",children:S.chunks}),(0,Se.jsx)("td",{className:V("px-2 py-1 text-right",S.deleted>0?"text-red-300/60":"text-white/40"),children:S.deleted}),(0,Se.jsx)("td",{className:V("px-2 py-1 text-right",re),title:S.last_sync??`status: ${S.sync_status??"unknown"}`,children:te})]},S.source)})})]})}),(0,Se.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,Se.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Se.jsxs)("button",{type:"button",onClick:()=>{I()},disabled:l,title:"Refresh the cheap count stats for this project.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Se.jsx)(Ot,{className:V("h-3 w-3 text-blue-400",l&&"animate-spin")}),"Refresh"]}),(0,Se.jsxs)("button",{type:"button",onClick:()=>{H()},disabled:N,title:"Scan the whole index for orphan chunks and duplicate documents. Expensive \u2014 walks every point, so it runs only when you ask.",className:"px-2 py-1 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] text-white/70 transition inline-flex items-center gap-1 disabled:opacity-40",children:[(0,Se.jsx)(Ja,{className:V("h-3 w-3 text-amber-400",N&&"animate-pulse")}),b?"Re-scan":"Scan for problems"]}),(0,Se.jsx)("span",{className:"text-white/10",children:"|"}),["gc","repair-orphans",...r?["repair-pending"]:[],"deduplicate"].map(S=>{let M=Ki[S],W=S==="gc"?It:S==="repair-orphans"?Pl:S==="repair-pending"?vs:sa,ee=S==="gc"?"text-amber-400":S==="repair-orphans"?"text-cyan-400":S==="repair-pending"?"text-rose-300":"text-violet-400",te=P===S;return(0,Se.jsxs)("button",{type:"button",onClick:()=>{q(S)},disabled:c,title:M.tooltip,className:V("px-2 py-1 rounded-md text-[10px] transition inline-flex items-center gap-1 disabled:opacity-40",te?"bg-rose-500/15 hover:bg-rose-500/25 text-rose-100 border border-rose-400/40":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70"),children:[(0,Se.jsx)(W,{className:V("h-3 w-3",ee)}),te?"Click again to confirm":M.label]},S)}),(0,Se.jsx)("span",{className:"text-white/10",children:"|"}),(0,Se.jsx)(eI.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync-status.sh","scripts/reindex.sh"],label:"Inspect sync status or reindex a source with the agent",icon:"Database"})]}),(0,Se.jsxs)("div",{className:"flex items-center gap-3",children:[(0,Se.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60 cursor-pointer",title:"Preview only \u2014 nothing will be deleted.",children:[(0,Se.jsx)("input",{type:"checkbox",checked:A,onChange:S=>w(S.target.checked),className:"accent-emerald-400 h-3 w-3"}),"Dry run"]}),(0,Se.jsxs)("label",{className:"inline-flex items-center gap-1 text-[10px] text-white/60",title:"Records marked as deleted within this many hours are kept (GC ignores them).",children:["Retention:",(0,Se.jsx)("input",{type:"number",min:1,value:v,onChange:S=>T(Math.max(1,Number(S.target.value)||24)),className:"w-12 h-5 rounded px-1 text-[10px] bg-white/[0.04] border border-white/[0.08] text-white/80 outline-none"}),"h"]})]})]}),(0,Se.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[9px] text-white/40 leading-snug",children:[(0,Se.jsxs)("div",{children:[(0,Se.jsx)("span",{className:"text-amber-300/70 font-medium",children:"GC:"})," ",Ki.gc.explainer]}),(0,Se.jsxs)("div",{children:[(0,Se.jsx)("span",{className:"text-cyan-300/70 font-medium",children:"Repair:"})," ",Ki["repair-orphans"].explainer]}),(0,Se.jsxs)("div",{children:[(0,Se.jsx)("span",{className:"text-violet-300/70 font-medium",children:"Deduplicate:"})," ",Ki.deduplicate.explainer]}),r?(0,Se.jsxs)("div",{children:[(0,Se.jsx)("span",{className:"text-rose-300/70 font-medium",children:"Repair pending:"})," ",Ki["repair-pending"].explainer]}):null]}),f&&(0,Se.jsxs)("div",{className:"bg-white/[0.04] border border-white/[0.06] rounded-lg px-2.5 py-2 text-[10px] text-white/60 space-y-0.5",children:[(0,Se.jsxs)("div",{className:"text-[10px] text-white/50 font-medium mb-1 flex items-center justify-between",children:[(0,Se.jsx)("span",{children:"Last Action Result"}),typeof f.removed=="number"&&(0,Se.jsxs)("span",{className:V("font-mono tabular-nums",f.dryRun?"text-amber-300/80":"text-emerald-300/85"),children:[f.dryRun?"Would remove":"Removed",": ",f.removed]})]}),Object.entries(f).map(([S,M])=>(0,Se.jsxs)("div",{className:"flex justify-between",children:[(0,Se.jsx)("span",{className:"text-white/40",children:S}),(0,Se.jsx)("span",{className:"text-white/70 font-mono",children:typeof M=="object"?JSON.stringify(M):String(M)})]},S))]})]})]})}var Qt=j(Ve(),1);var Fe=j(le(),1),Y5=["member","owner","admin"],Af=["read","write","exec"];function J5(n){return{default:{...n.default},...n.byRole?{byRole:$g(n.byRole)}:{},...n.byUser?{byUser:$g(n.byUser)}:{},...n.byAgent?{byAgent:$g(n.byAgent)}:{},paths:(n.paths??[]).map(e=>({...e,permissions:{...e.permissions},...e.roles?{roles:[...e.roles]}:{},...e.agents?{agents:[...e.agents]}:{},...e.users?{users:[...e.users]}:{}}))}}function $g(n){let e={};for(let[t,r]of Object.entries(n))e[t]={...r};return e}function Z5(n){return{pattern:`${n}://`,permissions:{read:!0,write:!1,exec:!1}}}function Kg({letter:n,state:e,onClick:t,disabled:r,title:a}){let s=e===!0?"bg-emerald-500/20 text-emerald-200 border-emerald-400/30":e===!1?"bg-rose-500/15 text-rose-200/80 border-rose-400/25":"bg-white/[0.04] text-white/35 border-white/[0.08]";return(0,Fe.jsx)("button",{type:"button",title:a??`${n} \u2014 ${e===!0?"allow":e===!1?"deny":"inherit"}`,disabled:r,onClick:t,className:V("inline-flex items-center justify-center w-5 h-5 rounded text-[9px] font-bold tabular-nums border transition disabled:cursor-default",s,!r&&"hover:brightness-125"),children:n})}function Xg(n){return n==="read"?"R":n==="write"?"W":"X"}function nI(n,e){if(!e)return!n;if(n===void 0)return!0;if(n===!0)return!1}function Yg({source:n,permissions:e,mode:t,onSave:r,knownRoles:a=Y5}){let[s,o]=(0,Qt.useState)(()=>J5(e)),[i,l]=(0,Qt.useState)(!1),[u,c]=(0,Qt.useState)(null),[d,f]=(0,Qt.useState)(""),[h,p]=(0,Qt.useState)(""),[m,g]=(0,Qt.useState)(""),x=(0,Qt.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(e),[s,e]),b=t==="view",y=(0,Qt.useCallback)((S,M)=>{o(W=>({...W,default:{...W.default,[S]:M}}))},[]),N=S=>S,L=(0,Qt.useCallback)((S,M)=>{let W=M.trim();W&&o(ee=>{let te={...ee[N(S)]??{}};return W in te?ee:(te[W]={},{...ee,[N(S)]:te})})},[]),A=(0,Qt.useCallback)((S,M)=>{o(W=>{let ee={...W[N(S)]??{}};return delete ee[M],Object.keys(ee).length===0?{...W,[N(S)]:void 0}:{...W,[N(S)]:ee}})},[]),w=(0,Qt.useCallback)((S,M,W)=>{o(ee=>{let te={...ee[N(S)]??{}},re=te[M]??{},ce=nI(re[W],!0),oe={...re};return ce===void 0?delete oe[W]:oe[W]=ce,te[M]=oe,{...ee,[N(S)]:te}})},[]),v=(0,Qt.useCallback)((S,M)=>{o(W=>{let ee=[...W.paths??[]];return ee[S]={...ee[S],...M},{...W,paths:ee}})},[]),T=(0,Qt.useCallback)((S,M)=>{o(W=>{let ee=[...W.paths??[]],te=ee[S],re=nI(te.permissions[M],!0),ce={...te.permissions};return re===void 0?delete ce[M]:ce[M]=re,ee[S]={...te,permissions:ce},{...W,paths:ee}})},[]),P=(0,Qt.useCallback)((S,M)=>{o(W=>{let ee=[...W.paths??[]],te=ee[S],re=new Set(te.roles??[]);return re.has(M)?re.delete(M):re.add(M),ee[S]=re.size>0?{...te,roles:[...re]}:{...te,roles:void 0},{...W,paths:ee}})},[]),O=(0,Qt.useCallback)((S,M,W)=>{let ee=W.trim();ee&&o(te=>{let re=[...te.paths??[]],ce=re[S],oe=new Set(ce[M]??[]);return oe.add(ee),re[S]={...ce,[M]:[...oe]},{...te,paths:re}})},[]),C=(0,Qt.useCallback)((S,M,W)=>{o(ee=>{let te=[...ee.paths??[]],re=te[S],ce=(re[M]??[]).filter(oe=>oe!==W);return te[S]={...re,[M]:ce.length>0?ce:void 0},{...ee,paths:te}})},[]),I=(0,Qt.useCallback)(()=>{o(S=>({...S,paths:[Z5(n),...S.paths??[]]}))},[n]),H=(0,Qt.useCallback)(S=>{o(M=>({...M,paths:(M.paths??[]).filter((W,ee)=>ee!==S)}))},[]),q=(0,Qt.useCallback)(async()=>{if(r){l(!0),c(null);try{await r(s)}catch(S){c(S instanceof Error?S.message:String(S))}finally{l(!1)}}},[s,r]),$=(S,M,W,ee,te)=>{let re=s[N(S)]??{},ce=Object.entries(re),[oe,ue]=te;return(0,Fe.jsxs)("div",{className:"space-y-1",children:[(0,Fe.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Fe.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:M}),(0,Fe.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:W})]}),ce.length===0&&b?(0,Fe.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No overrides."}):null,ce.map(([ie,Re])=>(0,Fe.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,Fe.jsx)("span",{className:"font-mono text-white/70 truncate min-w-[72px]",children:ie}),Af.map(De=>(0,Fe.jsx)(Kg,{letter:Xg(De),state:Re[De],onClick:b?void 0:()=>w(S,ie,De),disabled:b},De)),!b&&(0,Fe.jsx)("button",{type:"button",onClick:()=>A(S,ie),className:"ml-auto text-white/30 hover:text-rose-300 transition",title:"Remove override",children:(0,Fe.jsx)(It,{className:"w-3 h-3"})})]},ie)),!b&&(0,Fe.jsxs)("div",{className:"flex items-center gap-1.5 pt-0.5",children:[(0,Fe.jsx)("input",{type:"text",value:oe,onChange:ie=>ue(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&(ie.preventDefault(),L(S,oe),ue(""))},placeholder:ee,className:"h-6 flex-1 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] text-white/80 placeholder:text-white/25 outline-none focus:border-white/20"}),(0,Fe.jsxs)("button",{type:"button",onClick:()=>{L(S,oe),ue("")},className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Fe.jsx)(Tn,{className:"w-2.5 h-2.5"}),"Add"]})]})]})};return(0,Fe.jsxs)("div",{className:"flex flex-col gap-3 text-[10px]",children:[(0,Fe.jsx)("div",{className:"space-y-1",children:(0,Fe.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Fe.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Default"}),(0,Fe.jsxs)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:["Base access for ",n,"://*"]}),(0,Fe.jsx)("div",{className:"flex items-center gap-1",children:Af.map(S=>(0,Fe.jsx)(Kg,{letter:Xg(S),state:s.default[S],onClick:b?void 0:()=>y(S,!s.default[S]),disabled:b},S))})]})}),$("byRole","By Role","Override default for specific roles.","role (e.g. admin)",[d,f]),$("byUser","By User","Override for specific users (highest priority after paths).","userId",[h,p]),$("byAgent","By Agent","$self = the agent owning the file.","$self or agentId",[m,g]),(0,Fe.jsxs)("div",{className:"space-y-1",children:[(0,Fe.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Fe.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40",children:"Path Rules"}),(0,Fe.jsx)("span",{className:"text-[9px] text-white/30 italic flex-1 truncate",children:"Fine-grained rules per path/glob \u2014 first match wins."}),!b&&(0,Fe.jsxs)("button",{type:"button",onClick:I,className:"h-6 px-2 rounded bg-white/[0.05] border border-white/[0.08] text-[9px] font-semibold text-white/65 hover:text-white/90 hover:bg-white/[0.08] transition inline-flex items-center gap-1",children:[(0,Fe.jsx)(Tn,{className:"w-2.5 h-2.5"}),"Rule"]})]}),(s.paths??[]).length===0?(0,Fe.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"No rules \u2014 Default applies everywhere."}):(0,Fe.jsx)("ul",{className:"space-y-1",children:(s.paths??[]).map((S,M)=>(0,Fe.jsxs)("li",{className:"rounded bg-white/[0.02] border border-white/[0.05] px-2 py-1.5 space-y-1.5",children:[(0,Fe.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Fe.jsx)("input",{type:"text",disabled:b,value:S.pattern,onChange:W=>v(M,{pattern:W.target.value}),placeholder:`${n}://path/**`,className:"flex-1 min-w-0 h-6 rounded bg-white/[0.04] border border-white/[0.08] px-2 text-[10px] font-mono text-white/85 outline-none focus:border-white/20 disabled:opacity-70"}),Af.map(W=>(0,Fe.jsx)(Kg,{letter:Xg(W),state:S.permissions[W],onClick:b?void 0:()=>T(M,W),disabled:b},W)),(0,Fe.jsx)("button",{type:"button",disabled:b,onClick:()=>v(M,{override:S.override?void 0:!0}),title:"Override deny-wins precedence",className:V("h-5 px-1.5 rounded text-[8px] font-semibold border transition disabled:cursor-default",S.override?"bg-amber-500/15 text-amber-200 border-amber-400/30":"bg-white/[0.04] text-white/35 border-white/[0.08] hover:text-white/65"),children:"OVR"}),!b&&(0,Fe.jsx)("button",{type:"button",onClick:()=>H(M),title:"Remove rule",className:"text-white/30 hover:text-rose-300 transition",children:(0,Fe.jsx)(It,{className:"w-3 h-3"})})]}),(0,Fe.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Fe.jsx)("span",{className:"text-white/35 mr-0.5",children:"Roles:"}),a.map(W=>{let ee=(S.roles??[]).includes(W);return(0,Fe.jsx)("button",{type:"button",disabled:b,onClick:()=>P(M,W),className:V("h-5 px-1.5 rounded border text-[9px] font-medium capitalize transition disabled:cursor-default",ee?"bg-cyan-500/15 text-cyan-200 border-cyan-400/30":"bg-white/[0.04] text-white/40 border-white/[0.08] hover:text-white/70"),children:W},W)}),(S.roles??[]).length===0&&(0,Fe.jsx)("span",{className:"italic text-white/30",children:"all roles"})]}),(0,Fe.jsx)(rI,{label:"Agents",values:S.agents??[],emptyLabel:"any agent",placeholder:"$self / agentId",readOnly:b,onAdd:W=>O(M,"agents",W),onRemove:W=>C(M,"agents",W)}),(0,Fe.jsx)(rI,{label:"Users",values:S.users??[],emptyLabel:"any user",placeholder:"$owner / userId",readOnly:b,onAdd:W=>O(M,"users",W),onRemove:W=>C(M,"users",W)}),(S.users??[]).length>0&&!Q5(S)&&(0,Fe.jsx)("div",{className:"text-[9px] text-amber-200/80",children:"Users apply only to an allow rule: turn on OVR and set every bit to allow."})]},M))})]}),!b&&(0,Fe.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1",children:[u&&(0,Fe.jsx)("span",{className:"text-[9px] text-rose-300/80",children:u}),(0,Fe.jsxs)("button",{type:"button",onClick:q,disabled:!x||i,className:V("ml-auto inline-flex items-center gap-1 h-6 px-2.5 rounded bg-emerald-500/15 border border-emerald-400/30 text-[10px] font-semibold text-emerald-200 hover:bg-emerald-500/25 transition",(!x||i)&&"opacity-40 cursor-default"),children:[(0,Fe.jsx)(lo,{className:"w-3 h-3"}),i?"Saving\u2026":"Save policy"]})]})]})}function Q5(n){let e=Af.map(t=>n.permissions[t]).filter(t=>t!==void 0);return n.override===!0&&e.length>0&&e.every(t=>t===!0)}function rI({label:n,values:e,emptyLabel:t,placeholder:r,readOnly:a,onAdd:s,onRemove:o}){return(0,Fe.jsxs)("div",{className:"flex flex-wrap items-center gap-1 text-[9px] text-white/50",children:[(0,Fe.jsxs)("span",{className:"text-white/35 mr-0.5",children:[n,":"]}),e.map(i=>(0,Fe.jsxs)("span",{className:"inline-flex items-center gap-1 h-5 px-1.5 rounded bg-violet-500/12 text-violet-200 border border-violet-400/25",children:[(0,Fe.jsx)("span",{className:"font-mono",children:i}),!a&&(0,Fe.jsx)("button",{type:"button",onClick:()=>o(i),className:"text-violet-200/60 hover:text-rose-300",title:`Remove ${i}`,children:"\xD7"})]},i)),e.length===0&&(0,Fe.jsx)("span",{className:"italic text-white/30",children:t}),!a&&(0,Fe.jsx)(eE,{placeholder:r,onAdd:s})]})}function eE({placeholder:n,onAdd:e}){let[t,r]=(0,Qt.useState)("");return(0,Fe.jsxs)("div",{className:"inline-flex items-center gap-1",children:[(0,Fe.jsx)("input",{type:"text",value:t,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),e(t),r(""))},placeholder:n,className:"h-5 rounded bg-white/[0.04] border border-white/[0.08] px-1.5 text-[9px] font-mono text-white/75 placeholder:text-white/25 outline-none focus:border-white/20 w-[120px]"}),(0,Fe.jsx)("button",{type:"button",onClick:()=>{e(t),r("")},className:"text-white/40 hover:text-white/80 transition",title:"Add",children:(0,Fe.jsx)(Tn,{className:"w-3 h-3"})})]})}var aI=j(Ve(),1);var $t=j(le(),1);function sI({source:n,vectorCount:e,isDockerMount:t,busy:r,onCancel:a,onConfirm:s}){let[o,i]=(0,aI.useState)(!1);return(0,$t.jsxs)("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/5 p-2.5 mt-1.5 ml-5 mb-1 space-y-2",children:[(0,$t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,$t.jsx)(ct,{className:"h-3.5 w-3.5 text-rose-300 shrink-0 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[11px] font-semibold text-white/90",children:["Delete ",(0,$t.jsx)("span",{className:"font-mono text-rose-200",children:n}),"?"]}),(0,$t.jsxs)("div",{className:"text-[10px] text-white/55 mt-0.5",children:["The source config and connector binding are removed."," ",(0,$t.jsx)("span",{className:"text-white/75",children:"The host folder is not touched"})," ","\u2014 your files stay where they are."]})]})]}),(0,$t.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer rounded px-1.5 py-1 hover:bg-white/[0.03]",children:[(0,$t.jsx)("input",{type:"checkbox",checked:o,onChange:l=>i(l.target.checked),className:"accent-rose-400 h-3 w-3 mt-0.5"}),(0,$t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,$t.jsxs)("div",{className:"text-[10px] font-medium text-white/80",children:["Purge vector index entries",e!==null&&(0,$t.jsxs)("span",{className:"text-white/40 ml-1.5 tabular-nums",children:["(~",e," point",e===1?"":"s",")"]})]}),(0,$t.jsxs)("div",{className:"text-[9px] text-white/40 leading-relaxed",children:["Removes every Qdrant point whose URI maps back to"," ",(0,$t.jsxs)("code",{className:"font-mono text-white/55",children:[n,"://"]}),". Otherwise the vectors stay and Vector Health \u2192 Repair will mop them up later."]})]})]}),t&&(0,$t.jsxs)("div",{className:"rounded bg-amber-500/8 border border-amber-400/20 px-2 py-1.5 text-[9px] italic text-amber-100/70 leading-relaxed",children:["Docker bind-mount source. This deletes the source config (and vectors, if checked). To also drop the underlying compose bind, run the infra-only:"," ",(0,$t.jsxs)("code",{className:"font-mono not-italic text-amber-100/90",children:["neuralis mount remove ",n]})]}),(0,$t.jsxs)("div",{className:"flex items-center justify-end gap-1.5 pt-0.5",children:[(0,$t.jsxs)("button",{type:"button",onClick:a,disabled:r,className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[10px] font-medium text-white/70 transition disabled:opacity-40 inline-flex items-center gap-1",children:[(0,$t.jsx)(Bt,{className:"h-2.5 w-2.5"}),"Cancel"]}),(0,$t.jsxs)("button",{type:"button",onClick:()=>s({purgeVectors:o}),disabled:r,className:V("h-6 px-2.5 rounded-md text-[10px] font-semibold transition disabled:opacity-40 inline-flex items-center gap-1","bg-rose-500/20 hover:bg-rose-500/30 border border-rose-400/40 text-rose-100"),children:[r?(0,$t.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,$t.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete",o?" + Purge":""]})]})]})}var k=j(le(),1),Jg={exclude:[],trigger:"manual"},tE=[{value:"manual",label:"Manual"},{value:"auto",label:"Auto (watch + reconcile)"},{value:"interval",label:"On schedule"}],nE=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}],e0="Mounted (user-added)";function rE(n){return n&&n.trim().length>0?n:e0}function aE(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,24)||"agent"}function Mf(n){return n.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").slice(0,40)}function sE(n){return n.split(/[/\\]/).filter(Boolean).pop()??null}function oE(n){if(n?.name){let e=Mf(n.name);if(e)return e}if(n?.email){let e=Mf(n.email.split("@")[0]??"");if(e)return e}return"user"}function uI(n){let{baseName:e,meta:t,scope:r,ids:a}=n,o=(e?Mf(e):"")||(t?.urlScheme||t?.kind||"source").toLowerCase().replace(/[^a-z0-9-]+/g,"-");return r==="project"?o:r==="user"?`${o}-${a.userSlug||"user"}`:`${o}-${a.agentSlug||aE(a.agentId)}`}function iE(n){return n?.allowedScopes?.length?n.allowedScopes:["project","user","agent"]}function t0(n){return!!n?.capabilities.includes("scanDelta")}function n0(n){let e=n?.configSchema??{};return{required:Array.isArray(e.required)?e.required:[],properties:e.properties&&typeof e.properties=="object"?e.properties:{}}}function lE(n){let e=n0(n),t={};for(let[r,a]of Object.entries(e.properties)){if(r==="root")continue;let s=a.default;(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(t[r]=s)}return t}function cI(n){let e=n?.defaultPermissions?.default;return{read:typeof e?.read=="boolean"?e.read:!0,write:typeof e?.write=="boolean"?e.write:!1,exec:typeof e?.exec=="boolean"?e.exec:!1}}function qu(n,e){let t=n?.defaultScope??"project",r=cI(n);return{key:uI({baseName:null,meta:n,scope:t,ids:e}),path:"",scope:t,...r,syncEnabled:t0(n),exclude:Nf(n?.defaultSyncExcludes??[]),include:"",trigger:"manual",description:"",config:lE(n),policies:[],recognizesPackages:!1}}function Vu(n){return n.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Nf(n){return Array.isArray(n)?n.join(`
|
|
44
|
+
`):""}function uE(n){return n&&n.default&&typeof n.default=="object"?n:n&&typeof n.read=="boolean"?{default:{read:n.read,write:n.write??!1,exec:n.exec??!1}}:{default:{read:!0,write:!1,exec:!1}}}function Xi(n){return{source:n.source,permissions:uE(n.permissions),description:n.description??"",recognizesPackages:n.recognizesPackages??!1,...n.sync?{sync:{exclude:[...n.sync.exclude??[]],trigger:n.sync.trigger??"manual",...n.sync.include&&n.sync.include.length>0?{include:[...n.sync.include]}:{},...n.sync.alwaysActive!==void 0?{alwaysActive:n.sync.alwaysActive}:{},...n.sync.maxScanFiles!==void 0?{maxScanFiles:n.sync.maxScanFiles}:{},...n.sync.media?{media:{...n.sync.media}}:{}}}:{}}}var cE=[{key:"images",label:"Images",on:!0},{key:"pdf",label:"PDF pages",on:!0},{key:"video",label:"Video",on:!1},{key:"audio",label:"Audio",on:!1}];function oI(n){if(!n)return null;let e=[];return n.textOnlyModel>0&&e.push(`${n.textOnlyModel} media file${n.textOnlyModel===1?"":"s"} not embedded \u2014 the active embedding model is text-only`),n.off>0&&e.push(`${n.off} off in media settings`),n.tooLarge>0&&e.push(`${n.tooLarge} over the media size limit`),n.invalid>0&&e.push(`${n.invalid} structurally invalid PNG file${n.invalid===1?"":"s"}`),n.unavailable>0&&e.push(`${n.unavailable} unreadable as media`),e.length>0?e.join(" \xB7 "):null}function dE(n,e){if(e===!1)return{text:"Semantic embedding off \u2014 text and field search only",attention:!1};let t=(n??[]).filter(r=>r!=="disabled");return t.length===0?null:{text:`Semantic embedding pending: ${t.join(", ")} \u2014 files are indexed and text-searchable`,attention:!0}}function iI(n){return n?`${n} binary file${n===1?"":"s"} not indexed`:null}function fE(n,e,t){if(t)return!0;let r=n.sync,a=e.sync;if(!r||!a)return!!r!=!!a;let s=o=>(o??[]).join(`
|
|
45
|
+
`);return s(r.exclude)!==s(a.exclude)||s(r.include)!==s(a.include)||r.maxScanFiles!==a.maxScanFiles}function dI(n){if(n==="auto"||n==="on_change")return{mode:"auto",val:"5",unit:"m"};let e=/^interval:(\d+)([smhd])$/.exec(n);return e?{mode:"interval",val:e[1],unit:e[2]}:{mode:"manual",val:"5",unit:"m"}}function Rf(n){return n==="s"?30:1}function Zg(n,e,t){if(n!=="interval")return n;let r=Number.parseInt(e,10);return`interval:${Number.isFinite(r)?Math.max(r,Rf(t)):5}${t}`}function hE(n){let e=dI(n);return e.mode==="manual"?"Manual":e.mode==="auto"?"Auto":`Every ${e.val}${e.unit}`}function pE(n,e){let t=n.connection.config??{};for(let[r,a]of Object.entries(t)){if(typeof a=="string"&&a.length>0)return a;if(typeof a=="number")return String(a)}return e?.label??n.connection.kind}function mE(n,e){let t=n.permissions??cI(e);return{source:qe(n.uri_root),source_kind:n.source_kind,scope:{kind:"project"},createdBy:"runtime",connection:{kind:n.source_kind,config:{}},permissions:{default:t},sync_status:n.sync_status,last_updated:n.last_updated,kind_label:e?.label??n.source_kind,kind_trust:e?.trust??null,observed:!0,...n.origin_package?{origin_package:n.origin_package}:{},...n.live!==void 0?{live:n.live}:{},...n.live_reason?{live_reason:n.live_reason}:{}}}function gE(n,e){return JSON.stringify(Xi(n))!==JSON.stringify(e)}function lI(n){if(!n)return"never";let e=Date.now()-new Date(n).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:`${Math.floor(e/864e5)}d ago`}var Wo=V("h-7 w-full rounded-md px-2 text-[10px] outline-none transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28"),Pf=V(Wo,"pr-6 font-mono"),$u=V("w-full rounded-md px-2 py-1.5 text-[10px] font-mono outline-none resize-y transition","bg-white/[0.04] border border-white/[0.08] text-white/86","focus:border-white/[0.18] focus:bg-white/[0.06]","placeholder:text-white/28");function fI(n){let{agentId:e,projectId:t,isDocker:r}=n,a=_(F=>F.workspacePanels.sources),s=_(F=>F.setWorkspacePanelOpen),o=_(F=>F.pendingSourceSuggestion),i=_(F=>F.setPendingSourceSuggestion),l=_(F=>F.refresh),u=_(F=>F.sources),c=fn(),d=c.useAgents(),f=(0,Le.useMemo)(()=>oE(c.currentUser),[c.currentUser]),h=(c.currentRole?.priority??99)<=2,p=(0,Le.useMemo)(()=>ii({grantedFeatures:[...c.grantedFeatures??[]]},{features:["drive.mount"]}),[c.grantedFeatures]),m=(0,Le.useMemo)(()=>{let F=d.byId[e]?.name;return F?Mf(F):void 0},[d,e]),g=(0,Le.useMemo)(()=>({userSlug:f,agentSlug:m,agentId:e}),[f,m,e]),[x,b]=(0,Le.useState)([]),[y,N]=(0,Le.useState)({}),[L,A]=(0,Le.useState)({}),[w,v]=(0,Le.useState)({}),[T,P]=(0,Le.useState)(new Set),[O,C]=(0,Le.useState)({}),[I,H]=(0,Le.useState)(!1),[q,$]=(0,Le.useState)(null),[S,M]=(0,Le.useState)(null),[W,ee]=(0,Le.useState)(null),[te,re]=(0,Le.useState)(null),[ce,oe]=(0,Le.useState)(null),[ue,ie]=(0,Le.useState)(null),[Re,De]=(0,Le.useState)(null),[Ye,$e]=(0,Le.useState)(null),[Pt,Xe]=(0,Le.useState)(null),[lt,Nt]=(0,Le.useState)(null),[ot,Me]=(0,Le.useState)({}),[tt,pt]=(0,Le.useState)(null),[Rt,kt]=(0,Le.useState)("source"),[Ee,xe]=(0,Le.useState)(""),[Dt,en]=(0,Le.useState)(!0),[he,pe]=(0,Le.useState)(null),[je,Pe]=(0,Le.useState)(!1),Ce=(0,Le.useRef)(0);(0,Le.useEffect)(()=>{Ce.current++,pt(null),pe(null)},[e,t]);let[ln,mt]=(0,Le.useState)(null),[Ht,Ge]=(0,Le.useState)(!1),[Wt,tn]=(0,Le.useState)("project"),[Be,Y]=(0,Le.useState)(()=>qu(null,g)),Ie=(0,Le.useRef)(Be.key),_e=(0,Le.useRef)(!0);(0,Le.useEffect)(()=>(_e.current=!0,()=>{_e.current=!1}),[]);let[ze,Te]=(0,Le.useState)(!1),de=_(F=>F.vectorHealthOpen),ut=_(F=>F.setVectorHealthOpen),[Ft,nn]=(0,Le.useState)(!1),[$n,ar]=(0,Le.useState)(!1),[xr,Kn]=(0,Le.useState)([]),[Xn,Yn]=(0,Le.useState)("/"),[xa,yr]=(0,Le.useState)(!1),[Jn,dn]=(0,Le.useState)(null),[Rn,rn]=(0,Le.useState)([]),[Dr,Zn]=(0,Le.useState)(!1),[Fr,sr]=(0,Le.useState)([]),[_n,Zr]=(0,Le.useState)("local"),[br,vn]=(0,Le.useState)(null),[z,ne]=(0,Le.useState)([]);(0,Le.useEffect)(()=>{let F=!1;return Sx().then(Q=>{if(F)return;sr(Q.kinds??[]),vn(null);let D=Q.kinds?.find(ge=>ge.kind==="local")??Q.kinds?.[0]??null;if(D){Zr(D.kind);let ge=qu(D,g);Ie.current=ge.key,Y(ge)}}).catch(Q=>{F||vn(Q instanceof Error?Q.message:"Failed to load source kinds")}),()=>{F=!0}},[e]);let R=(0,Le.useMemo)(()=>{let F=new Map;for(let Q of Fr)F.set(Q.kind,Q);return F},[Fr]),X=R.get(_n)??null,B=t0(X),me=ZL(X),E=me.needed,ye=E&&me.container,jt=(0,Le.useCallback)(F=>{let Q=qu(R.get(F.suggestedKind)??null,g),D=F.suggestedConfig.root??"",ge=F.suggestedConfig.hostRoot;Zr(F.suggestedKind),Ie.current=F.suggestedScheme,Y({...Q,key:F.suggestedScheme,path:D,...F.suggestedScope?{scope:F.suggestedScope}:{},...F.syncDisabled?{syncEnabled:!1}:{},...F.suggestedSync?.include?{include:Nf(F.suggestedSync.include)}:{},...F.suggestedSync?.trigger?{trigger:F.suggestedSync.trigger}:{},...F.suggestedPolicies?.length?{policies:F.suggestedPolicies}:{},...F.description?{description:F.description}:{},...F.suggestedAccess??{},config:{...Q.config,...ge&&n0(R.get(F.suggestedKind)??null).properties.hostRoot?{hostRoot:ge}:{}}}),Ge(!0)},[R,g]);(0,Le.useEffect)(()=>{o&&R.size!==0&&(i(null),jt(o))},[o,R,jt,i]);let Ut=(0,Le.useCallback)((F,Q)=>uI({baseName:Q?sE(Q):null,meta:X,scope:F,ids:g}),[X,g]),gn=F=>F===""||F===Ie.current,kn=(0,Le.useCallback)(async()=>{if(t){H(!0),$(null);try{let[F,Q]=await Promise.all([_0({agentId:e,projectId:t,scope:Wt}),ac({agentId:e,projectId:t}).catch(()=>({suggestions:[]}))]);b(F),N(Object.fromEntries(F.map(D=>[D.source,Xi(D)]))),A(D=>Object.fromEntries(F.map(ge=>[ge.source,D[ge.source]??!1]))),ne(Q.suggestions??[])}catch(F){$(F instanceof Error?F.message:"Failed to load sources")}finally{H(!1)}}},[Wt,e,t]);(0,Le.useEffect)(()=>{a&&kn()},[a,kn]),(0,Le.useEffect)(()=>{a&&e&&l({agentId:e,projectId:t})},[a,e,t,l]);let ec=(0,Le.useCallback)(async F=>{if(!e||w[F])return;let Q=!1;if(P(D=>{if(D.has(F))return Q=!0,D;let ge=new Set(D);return ge.add(F),ge}),!Q)try{let D=await B0(e,t??void 0,F);D&&v(ge=>({...ge,[F]:D}))}catch{}finally{P(D=>{if(!D.has(F))return D;let ge=new Set(D);return ge.delete(F),ge})}},[e,t,w]),ol=(0,Le.useCallback)(F=>{v(Q=>{if(!(F in Q))return Q;let D={...Q};return delete D[F],D})},[]),b2=(0,Le.useCallback)(F=>{A(Q=>{let D=!Q[F];return D&&ec(F),{...Q,[F]:D}})},[ec]);(0,Le.useEffect)(()=>{if(!Re)return;let F=setTimeout(()=>De(null),4e3);return()=>clearTimeout(F)},[Re]),(0,Le.useEffect)(()=>{!Ht||!r||!p||(Zn(!0),nh({path:"/mounts",agentId:e,...t?{projectId:t}:{}}).then(F=>{let Q=new Set(x.map(ge=>ge.source)),D=F.entries.filter(ge=>!Q.has(ge.name));rn(D)}).catch(()=>rn([])).finally(()=>Zn(!1)))},[Ht,r,p,e,t,x]);let tc=(0,Le.useMemo)(()=>{let F=new Set,Q=x.map(D=>{F.add(D.source);let ge=u.find(Yt=>qe(Yt.uri_root)===D.source),qt=w[D.source]??ge;return{...D,connector_count:qt?.on_disk,connector_truncated:qt?.truncated,indexed_count:qt?.indexed_count,unindexed_count:qt?.unindexed,last_updated:ge?.last_updated??D.last_updated,sync_status:D.sync?.status??ge?.sync_status??D.sync_status,live:ge?.live,live_reason:ge?.live_reason,kind_icon:ge?.kind_icon}});if(Wt==="project")for(let D of u){let ge=qe(D.uri_root);if(!ge||F.has(ge))continue;let qt=R.get(D.source_kind)??null,Yt=w[ge]??D;Q.push({...mE(D,qt),connector_count:Yt.on_disk,connector_truncated:Yt.truncated,indexed_count:Yt.indexed_count,unindexed_count:Yt.unindexed,kind_icon:D.kind_icon})}return Q},[Wt,x,R,u,w]),w2=(0,Le.useMemo)(()=>{let F=new Map;for(let Q of tc){let D=rE(Q.origin_package),ge=F.get(D);ge?ge.push(Q):F.set(D,[Q])}return[...F.entries()].sort(([Q],[D])=>Q===e0?1:D===e0?-1:Q.localeCompare(D))},[tc]),Qr=(F,Q)=>{N(D=>({...D,[F]:Q(D[F])}))},Vf=(F,Q)=>{C(D=>({...D,[F]:{...D[F]??{},[Q]:!(D[F]?.[Q]??!1)}}))},v2=async(F,Q)=>{M(F.source),$(null);try{let D=!Q.sync&&!!F.sync,ge=h&&F.connection.kind==="local",{recognizesPackages:qt,...Yt}=Q,ea=await eh({agentId:e,...t?{projectId:t}:{},config:{...ge?Q:Yt,...D?{clearSync:!0}:{}}});b(ja=>ja.map(qa=>qa.source===ea.source?ea:qa)),N(ja=>({...ja,[ea.source]:Xi(ea)})),fE(F,Q,D)?(await l({agentId:e,projectId:t,withCounts:!0}),ol(F.source)):await l({agentId:e,projectId:t})}catch(D){$(D instanceof Error?D.message:"Save failed")}finally{M(null)}},k2=(0,Le.useCallback)(async(F,Q)=>{let D=y[F.source]??Xi(F);M(F.source),$(null);try{let ge=await eh({agentId:e,...t?{projectId:t}:{},config:{...D,permissions:Q}});b(qt=>qt.map(Yt=>Yt.source===ge.source?ge:Yt)),N(qt=>({...qt,[ge.source]:Xi(ge)})),await l({agentId:e,projectId:t})}catch(ge){throw $(ge instanceof Error?ge.message:"Save failed"),ge}finally{M(null)}},[e,y,t,l]),x0=(0,Le.useCallback)(async F=>{for(let ge=0;ge<2400;ge++){if(await new Promise(Wa=>setTimeout(Wa,1500)),!_e.current)return null;let Yt=(await U0({agentId:e,...t?{projectId:t}:{},source:F})).job;if(!Yt)return null;if(!(Yt.status==="pending"||Yt.status==="running")){if(Yt.status==="failed")throw new Error(Yt.error??Yt.result?.error??"Sync failed");return Yt}}return null},[e,t]);if(!a)return null;let S2=async F=>{ee(F),$(null);try{await H0({agentId:e,...t?{projectId:t}:{},source:F}),await x0(F),await kn(),await l({agentId:e,projectId:t,withCounts:!0}),ol(F)}catch(Q){$(Q instanceof Error?Q.message:"Sync failed")}finally{ee(null)}},C2=async F=>{try{await vx({agentId:e,...t?{projectId:t}:{},...F?{source:F}:{}}),ee(null),re(null)}catch(Q){$(Q instanceof Error?Q.message:"Cancel failed")}},nc=async(F,Q,D)=>{re(F),$(null);try{await Q();let ge=await x0(F),qt=ge?.status==="paused"?ge.result?.embedding?.pausedReason??"paused":null;Me(Yt=>{let{[F]:Wa,...ea}=Yt;return qt?{...ea,[F]:qt}:ea}),await kn(),await l({agentId:e,projectId:t,withCounts:!0}),ol(F)}catch(ge){$(ge instanceof Error?ge.message:D)}finally{re(null)}},L2=F=>nc(F,()=>dc({agentId:e,...t?{projectId:t}:{},source:F},"pending"),"Embedding failed"),I2=F=>nc(F,()=>xx({agentId:e,...t?{projectId:t}:{},source:F}),"Rescan failed"),y0=async(F,Q)=>{let D=++Ce.current,ge=Rt==="source"?{kind:"source"}:{kind:Rt,uri:Ee};Pe(!0),$(null);try{let qt=await yx({agentId:e,...t?{projectId:t}:{},source:F,selector:ge,mode:Q,obsoleteOnly:Dt});if(D!==Ce.current)return;Q==="estimate"?pe(qt):(pt(null),pe(null),ol(F),await kn(),await l({agentId:e,projectId:t,withCounts:!0}))}catch(qt){D===Ce.current&&$(qt instanceof Error?qt.message:"Index cleanup failed")}finally{D===Ce.current&&Pe(!1)}},A2=async F=>{$e(F),$(null);try{await gx({agentId:e,...t?{projectId:t}:{},source:F}),await kn()}catch(Q){$(Q instanceof Error?Q.message:"Reset failed")}finally{$e(null)}},P2=async(F,Q)=>{mt(F),$(null);try{await G0({agentId:e,...t?{projectId:t}:{},source:F,enabled:Q}),await kn()}catch(D){$(D instanceof Error?D.message:"Toggle failed")}finally{mt(null)}},N2=async(F,Q)=>{oe(F),$(null);try{let D=await mx({agentId:e,...t?{projectId:t}:{},source:F,...Q.purgeVectors?{purgeVectors:!0}:{}});await kn(),await l({agentId:e,projectId:t}),ol(F),De(Q.purgeVectors&&D?.purgeJob?`Deleted "${F}" (vector purge running in background)`:`Deleted "${F}"`),ie(null)}catch(D){$(D instanceof Error?D.message:"Delete failed")}finally{oe(null)}},$f=async F=>{ar(!0),yr(!0),dn(null);try{let Q=await nh({path:F,agentId:e,...t?{projectId:t}:{}});Kn(Q.entries),Yn(F)}catch{dn("That path is not available."),Kn([])}finally{yr(!1)}},b0=F=>{Y(Q=>{if(!gn(Q.key))return{...Q,path:F};let D=Ut(Q.scope,F);return Ie.current=D,{...Q,path:F,key:D}}),ar(!1)},R2=async()=>{if(!(!Be.key||E&&!Be.path)){Te(!0),$(null);try{let F={...Be.config,...E?{root:Be.path}:{}};await px({agentId:e,...t?{projectId:t}:{},source:Be.key,scope:Be.scope,connection:{kind:_n,config:F},permissions:{default:{read:Be.read,write:Be.write,exec:Be.exec},...Be.policies.length>0?{paths:Be.policies}:{}},...Be.description.trim()?{description:Be.description.trim()}:{},...B&&Be.syncEnabled?{sync:{exclude:Vu(Be.exclude),trigger:Be.trigger,...Vu(Be.include).length>0?{include:Vu(Be.include)}:{}}}:{},...h&&_n==="local"&&Be.recognizesPackages?{recognizesPackages:!0}:{}}),Ge(!1);{let Q=qu(X,g);Ie.current=Q.key,Y(Q)}await kn(),await l({agentId:e,projectId:t})}catch(F){$(F instanceof Error?F.message:"Add source failed")}finally{Te(!1)}}},M2=F=>F==="data"||F==="packages";return(0,k.jsxs)("div",{className:"w-full px-5 pt-3 pb-6 text-white/85",children:[(0,k.jsxs)("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-white/[0.06]",children:[(0,k.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,k.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,k.jsx)("span",{className:"text-sm font-semibold tracking-wide text-white/92",children:"Sources"}),(0,k.jsx)("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium text-cyan-300 bg-cyan-500/20",children:tc.length})]}),(0,k.jsxs)("div",{className:"flex items-center gap-1",children:[(0,k.jsxs)("div",{className:"inline-flex items-center gap-0.5",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>Ge(F=>!F),className:"h-7 px-2 rounded-l-md rounded-r-none text-cyan-300 hover:text-cyan-200 hover:bg-white/[0.05] transition inline-flex items-center gap-1 text-[10px] font-medium",title:"Add source",children:[(0,k.jsx)(Tn,{className:"h-3 w-3"}),"Source"]}),(0,k.jsx)(Qg.SkillLauncher,{variant:"icon",attached:"left",skill:"manage-sources",packageId:"@neuralis/brain-core",scripts:["scripts/sync.sh","scripts/reindex.sh","scripts/set-enabled.sh"],label:"Manage sources with the agent"})]}),(0,k.jsx)("button",{type:"button",onClick:()=>{kn()},disabled:I,className:"h-7 w-7 rounded-md text-white/35 hover:text-white/70 hover:bg-white/[0.05] transition",title:"Refresh",children:(0,k.jsx)(Ot,{className:V("mx-auto h-3 w-3",I&&"animate-spin")})}),(0,k.jsx)("button",{type:"button",onClick:()=>s("sources",!1),className:"h-7 px-2.5 rounded-md text-[10px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Close"})]})]}),(0,k.jsxs)("div",{className:"mt-2 text-[10px] text-white/35 italic",children:["Add filesystem-style sources from Neuralis packages. A source URI such as ",(0,k.jsx)("code",{className:"font-mono",children:"neuralis://"})," or ",(0,k.jsx)("code",{className:"font-mono",children:"machine-user://"})," is the stable handle agents use with fs_* tools."]}),(0,k.jsx)("div",{className:"mt-2 flex items-center gap-1 rounded-md bg-white/[0.025] p-1",children:[{id:"project",label:"Project"},{id:"user",label:"User"},{id:"agent",label:"Agent"}].map(F=>(0,k.jsx)("button",{type:"button",onClick:()=>tn(F.id),className:V("h-6 rounded px-2 text-[9px] font-semibold transition",Wt===F.id?"bg-cyan-500/15 text-cyan-200 border border-cyan-400/20":"text-white/35 hover:text-white/65 hover:bg-white/[0.04]"),children:F.label},F.id))}),q&&(0,k.jsx)("div",{className:"mt-2 rounded-md bg-red-500/8 px-3 py-2 text-[10px] text-red-200/80",children:q}),Ht&&(0,k.jsxs)("div",{className:"mt-2 rounded-lg bg-white/[0.03] border border-white/[0.08] p-3 space-y-2",children:[(0,k.jsx)("div",{className:"text-[11px] font-semibold text-white/80",children:"Add Source"}),br&&(0,k.jsxs)("div",{className:"text-[9px] text-rose-300/80 bg-rose-500/10 rounded px-2 py-1",children:["Could not load source kinds: ",br,'. Falling back to "local".']}),Fr.length>1&&(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Kind"}),(0,k.jsx)("select",{value:_n,onChange:F=>{let Q=F.target.value,D=R.get(Q)??null;Zr(Q);let ge=qu(D,g);Ie.current=ge.key,Y(ge)},className:Pf,children:Fr.map(F=>(0,k.jsxs)("option",{value:F.kind,children:[F.label," \u2014 ",F.trust," (",F.packageId,")"]},F.kind))}),(0,k.jsx)("div",{className:"text-[9px] text-white/30 italic",children:X?.description??""})]}),X?.scopeSelectable&&(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Scope"}),(0,k.jsx)("select",{value:Be.scope,onChange:F=>{let Q=F.target.value;Y(D=>{if(!gn(D.key))return{...D,scope:Q};let ge=Ut(Q,D.path);return Ie.current=ge,{...D,scope:Q,key:ge}})},className:Pf,children:iE(X).map(F=>(0,k.jsx)("option",{value:F,children:F},F))})]}),ye&&r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("div",{className:"text-[10px] text-amber-300/70 bg-amber-500/8 rounded px-2 py-1.5",children:["Docker mode: host folders still need the CLI mount script:"," ",(0,k.jsx)("code",{className:"text-amber-200/90 font-mono",children:"neuralis mount add"})," ","on the host, then restart the container. Package sources like Machine do not require a host path here."]}),Dr?(0,k.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,k.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"}),(0,k.jsx)("span",{className:"text-[9px] text-white/35",children:"Scanning volume mounts..."})]}):Rn.length>0?(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Available volume mounts (not yet configured)"}),Rn.map(F=>(0,k.jsxs)("div",{className:"flex items-center gap-2 rounded px-2 py-1.5 bg-white/[0.02] hover:bg-white/[0.04] transition",children:[(0,k.jsx)(_r,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] text-white/75 font-medium flex-1 truncate",children:F.name}),(0,k.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate max-w-[120px]",children:F.path}),(0,k.jsx)("button",{type:"button",onClick:()=>{Y(Q=>({...Q,key:F.name,path:F.path}))},className:"px-2 py-0.5 rounded text-[8px] font-semibold text-cyan-300/80 bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-400/20 transition shrink-0",children:"+ Add"})]},F.path))]}):(0,k.jsx)("div",{className:"text-[9px] text-white/30 italic",children:"All volume mounts are configured as sources."})]}):(0,k.jsx)("div",{className:"text-[10px] text-white/35 italic",children:E?me.container?"Mount any folder from your system. The path must be accessible to the server process.":"A path on the operator\u2019s host machine, reached through the host broker. It needs no volume mount here, and the broker ceiling still clamps what is reachable.":"This connector does not need a local path. Choose the scope and URI scheme; the package owns the runtime binding."}),(0,k.jsxs)("div",{className:"space-y-2",children:[(0,k.jsxs)("div",{className:V("grid gap-2",E?"grid-cols-2":"grid-cols-1"),children:[(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"URI scheme"}),(0,k.jsx)("input",{type:"text",value:Be.key,onChange:F=>Y(Q=>({...Q,key:F.target.value})),placeholder:Ut(Be.scope,Be.path),className:Wo}),(0,k.jsxs)("div",{className:"text-[8px] text-white/25 font-mono",children:[Be.key||Ut(Be.scope,Be.path),"://"]})]}),E&&(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:me.label}),(0,k.jsxs)("div",{className:"flex gap-1",children:[(0,k.jsx)("input",{type:"text",value:Be.path,onChange:F=>Y(Q=>({...Q,path:F.target.value})),placeholder:me.placeholder,className:V(Wo,"flex-1")}),me.container&&!r&&p&&(0,k.jsx)("button",{type:"button",onClick:()=>{$f(Be.path||"/")},className:"h-7 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 hover:text-white/90 transition shrink-0",title:"Browse directories",children:(0,k.jsx)(Is,{className:"h-3.5 w-3.5"})})]})]})]}),Object.entries(n0(X).properties).filter(([F])=>F!=="root").map(([F,Q])=>(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:Q?.["x-neuralis"]?.ui?.label??F}),(0,k.jsx)("input",{type:Q.type==="number"||Q.type==="integer"?"number":"text",value:String(Be.config[F]??""),onChange:D=>Y(ge=>({...ge,config:{...ge.config,[F]:D.target.value}})),placeholder:Q?.["x-neuralis"]?.ui?.placeholder??Q?.description??F,className:Wo})]},F)),ye&&!r&&$n&&(0,k.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/[0.1] overflow-hidden",children:[(0,k.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1.5 bg-white/[0.02] border-b border-white/[0.06]",children:[(0,k.jsx)(Is,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,k.jsx)("span",{className:"text-[9px] font-mono text-white/60 truncate flex-1",children:Xn}),(0,k.jsx)("button",{type:"button",onClick:()=>ar(!1),className:"text-[9px] text-white/40 hover:text-white/70 px-1",children:"Close"})]}),Jn&&(0,k.jsx)("div",{className:"px-2 py-1 text-[9px] text-red-300/80",children:Jn}),xa?(0,k.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,k.jsx)(We,{className:"h-3 w-3 animate-spin text-white/30"})}):(0,k.jsxs)("div",{className:"max-h-[180px] overflow-y-auto",children:[Xn!=="/"&&(0,k.jsxs)("button",{type:"button",onClick:()=>{let F=Xn.replace(/[/\\][^/\\]+$/,"")||"/";$f(F)},className:"w-full flex items-center gap-1.5 px-2 py-1 text-left hover:bg-white/[0.04] transition",children:[(0,k.jsx)($a,{className:"h-3 w-3 text-white/30"}),(0,k.jsx)("span",{className:"text-[10px] text-white/50",children:".."})]}),xr.length===0&&!xa&&(0,k.jsx)("div",{className:"px-2 py-2 text-[9px] text-white/30 italic",children:"No subdirectories"}),xr.map(F=>(0,k.jsxs)("div",{className:"flex items-center gap-0.5 hover:bg-white/[0.04] transition",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>{$f(F.path)},className:"flex items-center gap-1.5 px-2 py-1 flex-1 text-left min-w-0",children:[(0,k.jsx)(_r,{className:"h-3 w-3 text-cyan-400/70 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] text-white/75 truncate",children:F.name})]}),(0,k.jsx)("button",{type:"button",onClick:()=>b0(F.path),className:"px-2 py-1 text-[8px] font-medium text-cyan-300/70 hover:text-cyan-200 shrink-0",children:"Select"})]},F.path)),(0,k.jsxs)("button",{type:"button",onClick:()=>b0(Xn),className:"w-full flex items-center gap-1.5 px-2 py-1.5 text-left bg-cyan-500/5 hover:bg-cyan-500/10 border-t border-white/[0.06] transition",children:[(0,k.jsx)(na,{className:"h-3 w-3 text-cyan-400 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] font-medium text-cyan-300/80",children:"Select this folder"}),(0,k.jsx)("span",{className:"text-[9px] text-white/30 font-mono truncate ml-auto",children:Xn})]})]})]})]}),(0,k.jsxs)("div",{className:"flex items-center gap-2",children:[(0,k.jsx)("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 w-16 shrink-0",children:"Access"}),[{key:"read",label:"Read",icon:vl},{key:"write",label:"Write",icon:so},{key:"exec",label:"Exec",icon:oi}].map(({key:F,label:Q,icon:D})=>(0,k.jsxs)("label",{className:V("inline-flex items-center gap-1 rounded px-2 py-1 text-[9px] cursor-pointer transition",Be[F]?"bg-white/[0.06] text-white/85":"bg-white/[0.02] text-white/40"),children:[(0,k.jsx)("input",{type:"checkbox",className:"sr-only",checked:Be[F],onChange:ge=>Y(qt=>({...qt,[F]:ge.target.checked}))}),(0,k.jsx)(D,{className:"h-2.5 w-2.5"}),Q,(0,k.jsx)("span",{className:V("h-1.5 w-1.5 rounded-full",Be[F]?"bg-emerald-300/80":"bg-white/20")})]},F))]}),(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:["Description ",(0,k.jsx)("span",{className:"text-white/20 normal-case font-normal",children:"(optional \u2014 shown to the agent)"})]}),(0,k.jsx)("input",{value:Be.description,onChange:F=>Y(Q=>({...Q,description:F.target.value})),className:Wo,placeholder:X?.description??"What this source is for\u2026",maxLength:200})]}),B&&(0,k.jsx)("div",{className:"flex items-center gap-2",children:(0,k.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,k.jsx)("input",{type:"checkbox",checked:Be.syncEnabled,onChange:F=>Y(Q=>({...Q,syncEnabled:F.target.checked})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]})}),B&&Be.syncEnabled&&(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude patterns"}),(0,k.jsx)("textarea",{value:Be.exclude,onChange:F=>Y(Q=>({...Q,exclude:F.target.value})),rows:2,className:$u,placeholder:"node_modules/**"})]}),B&&Be.syncEnabled&&(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,k.jsx)("textarea",{value:Be.include,onChange:F=>Y(Q=>({...Q,include:F.target.value})),rows:2,className:V($u,"font-mono"),placeholder:`# empty = everything
|
|
46
|
+
skills/**`}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included. This narrows the INDEX, not what the agent can read: the source root does that."})]}),_n==="local"&&h&&(0,k.jsx)("div",{className:"space-y-1",children:(0,k.jsxs)("label",{className:"inline-flex items-start gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,k.jsx)("input",{type:"checkbox",checked:Be.recognizesPackages,onChange:F=>Y(Q=>({...Q,recognizesPackages:F.target.checked})),className:"accent-emerald-400 h-3 w-3 mt-0.5"}),(0,k.jsxs)("span",{children:["Recognize packages",(0,k.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,k.jsx)("code",{children:"_packages/"}),") as soon as the source is added. Advertised only within this source's scope."]})]})]})}),(0,k.jsxs)("div",{className:"flex items-center gap-1.5 pt-1",children:[(0,k.jsx)("button",{type:"button",onClick:()=>Ge(!1),className:"h-6 px-2.5 rounded-md text-[9px] font-medium text-white/50 hover:text-white/80 hover:bg-white/[0.05] transition",children:"Cancel"}),(0,k.jsxs)("button",{type:"button",onClick:()=>{R2()},disabled:ze||!Be.key||E&&!Be.path,className:"h-6 px-2.5 rounded-md bg-cyan-500/12 border border-cyan-400/25 text-[9px] font-semibold text-cyan-200/90 hover:bg-cyan-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[ze?(0,k.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,k.jsx)(Tn,{className:"h-2.5 w-2.5"}),"Create source"]})]})]}),tc.length===0&&!I?(0,k.jsx)("div",{className:"mt-3 text-[10px] text-white/40",children:"No sources configured."}):null,(0,k.jsx)("div",{className:"mt-1 space-y-3",children:w2.map(([F,Q])=>(0,k.jsxs)("div",{children:[(0,k.jsxs)("div",{className:"-ml-0.5 mb-0.5 flex items-center gap-1.5 px-1",children:[(0,k.jsx)(Lr,{className:"h-3 w-3 shrink-0 text-white/30"}),(0,k.jsx)("span",{className:"truncate font-mono text-[10px] font-medium text-white/40",children:F}),(0,k.jsx)("span",{className:"text-[9px] tabular-nums text-white/25",children:Q.length})]}),(0,k.jsx)("div",{className:"space-y-0.5 pl-2",children:Q.map(D=>{let ge=y[D.source]??Xi(D),qt=S===D.source,Yt=W===D.source,Wa=te===D.source,ea=ce===D.source,ja=R.get(D.connection.kind)??null,qa=t0(ja),rc=qa&&!!ge.sync,Hn=ge.sync??Jg,w0=(0,ur.resolveIconWithFallback)(D.kind_icon??ja?.icon??void 0,Un),v0=Ic(D),k0=D.live===!1,T2=k0||D.enabled===!1||D.enabled==="auto"&&D.enabled_effective===!1,S0=!!L[D.source],hs=!D.observed,Kf=hs&&gE(D,ge),Er=dI(Hn.trigger),Zs=O[D.source]??{};return(0,k.jsxs)("div",{className:"rounded-sm",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>b2(D.source),title:k0?Ah(D.live_reason):void 0,className:"w-full flex items-center gap-2 py-2 text-left group hover:bg-white/[0.02] rounded-md px-1 transition",children:[D.git?.isRepo?(0,k.jsxs)("span",{className:"relative inline-flex shrink-0 items-center justify-center",children:[(0,k.jsx)(w0,{className:V("h-4 w-4",v0.iconClassName)}),(0,k.jsx)(Sn,{className:"absolute -right-1.5 -top-1.5 h-2.5 w-2.5 rounded-full bg-black/80 p-[1px] text-violet-300/90"})]}):(0,k.jsx)(w0,{className:V("h-4 w-4 shrink-0",v0.iconClassName)}),(0,k.jsx)("span",{className:V("min-w-0 flex-1 truncate text-[12.5px] font-semibold",T2?"text-white/45":"text-white/90"),children:D.source}),D.git?.isRepo&&D.git.branch?(0,k.jsxs)("span",{className:"inline-flex max-w-[96px] shrink-0 items-center gap-0.5 text-[10px] text-violet-300/70",title:`Git branch: ${D.git.branch}`,children:[(0,k.jsx)(Sn,{className:"h-2.5 w-2.5 shrink-0"}),(0,k.jsx)("span",{className:"truncate",children:D.git.branch})]}):null,D.observed&&(0,k.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-orange-200/90 bg-orange-500/5 ring-1 ring-orange-300/30",children:"observed"}),D.orphan&&(0,k.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-rose-300/80 bg-rose-500/15",title:D.orphan_hint??"Package missing",children:"orphan"}),Kf&&(0,k.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[8px] font-medium text-amber-300/80 bg-amber-500/10",children:"unsaved"}),(()=>{let Oe=D.enabled??!0,Et=D.enabled_effective??Oe===!0,Qn=(ja?.kind??D.connection.kind)==="webtop",Qs=ln===D.source,D2=()=>Qn?Oe===!0?!1:Oe===!1?"auto":!0:Oe===!1,C0=Oe==="auto"?`Auto \xB7 ${Et?"Live":"Stopped"}`:Oe===!1?"Off":"On",F2=Oe===!1?"text-rose-300/85 bg-rose-500/10 border-rose-400/25":Oe==="auto"?"text-amber-200/85 bg-amber-500/10 border-amber-400/25":"text-emerald-300/85 bg-emerald-500/10 border-emerald-400/25";return(0,k.jsx)("button",{type:"button",title:`Source ${C0} \u2014 click to cycle`,onClick:E2=>{E2.stopPropagation(),!Qs&&P2(D.source,D2())},disabled:Qs||!!D.observed,className:V("shrink-0 rounded px-1 py-0.5 text-[8px] font-semibold border transition disabled:opacity-50",F2),children:Qs?"\u2026":C0})})(),(0,k.jsx)("span",{className:"text-[9px] text-white/30 truncate max-w-[140px] hidden sm:inline",children:pE(D,ja)}),(0,k.jsx)(Tt,{className:V("h-3 w-3 text-white/25 shrink-0 transition-transform",S0&&"rotate-180")})]}),(0,k.jsx)("div",{className:V("transition-all duration-200",S0?"opacity-100":"max-h-0 opacity-0 overflow-hidden"),children:(0,k.jsxs)("div",{className:"rounded-md bg-white/[0.02] p-3 ml-5 mb-1 space-y-2.5",children:[(0,k.jsxs)("div",{className:"flex items-center gap-3 text-[9px] text-white/40",children:[T.has(D.source)&&typeof D.indexed_count!="number"&&(0,k.jsx)("span",{className:"text-white/30",children:"Loading counts\u2026"}),typeof D.connector_count=="number"&&(0,k.jsxs)("span",{children:[(0,k.jsxs)("span",{className:"text-white/60 tabular-nums",children:[D.connector_count,D.connector_truncated?"+":""]})," connector"]}),typeof D.indexed_count=="number"&&(0,k.jsxs)("span",{children:[(0,k.jsx)("span",{className:"text-cyan-300/70 tabular-nums",children:D.indexed_count})," indexed"]}),typeof D.unindexed_count=="number"&&D.unindexed_count>0&&(0,k.jsxs)("span",{children:[(0,k.jsx)("span",{className:"text-amber-300/70 tabular-nums",children:D.unindexed_count})," unindexed"]}),qa&&D.sync?.lastSync&&(0,k.jsxs)("span",{children:["Last sync: ",lI(D.sync.lastSync)]}),D.updatedAt&&(0,k.jsxs)("span",{children:["Updated: ",lI(D.updatedAt)]})]}),qa&&!D.sync?.lastSync?(0,k.jsx)("div",{className:"rounded-md border border-sky-300/15 bg-sky-500/5 px-2 py-1.5 text-[10px] text-sky-100/70",children:"Never synced \u2014 run a sync to index this source and load its packages (skills, rules, instructions) for agents."}):null,D.observed?(0,k.jsx)("div",{className:"rounded-md border border-orange-300/15 bg-orange-500/5 px-2 py-1.5 text-[10px] text-orange-100/70",children:"Runtime-observed source. Create a source config to edit permissions, sync, or persistence settings."}):null,(0,k.jsxs)("div",{children:[(0,k.jsxs)("button",{type:"button",onClick:()=>Vf(D.source,"description"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,k.jsx)(ka,{className:"h-3 w-3 text-violet-400 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Description"}),!Zs.description&&((ge.description??"").trim()||D.description_effective)&&(0,k.jsx)("span",{className:V("text-[9px] truncate max-w-[200px]",(ge.description??"").trim()?"text-white/35":"text-white/25 italic"),children:(ge.description??"").trim()||`${D.description_effective} (from the package)`}),(0,k.jsx)(un,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",Zs.description&&"rotate-90")})]}),Zs.description&&(0,k.jsxs)("div",{className:"pl-5 pt-1 space-y-1",children:[(0,k.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"A one-line summary shown to the agent in its runtime source list."}),hs?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)("textarea",{value:ge.description??"",onChange:Oe=>Qr(D.source,Et=>({...Et,description:Oe.target.value})),rows:2,className:$u,placeholder:D.description_effective??"What this source is for\u2026",maxLength:200}),!(ge.description??"").trim()&&D.description_effective&&(0,k.jsx)("div",{className:"text-[9px] text-white/25 italic",children:"Shown above from the package. Leave this empty to keep following it."})]}):(0,k.jsx)("div",{className:"text-[10px] text-white/70",children:(ge.description??"").trim()||(D.description_effective?(0,k.jsxs)("span",{className:"text-white/40 italic",children:[D.description_effective," ",(0,k.jsx)("span",{className:"text-white/25 not-italic",children:"(from the package)"})]}):(0,k.jsx)("span",{className:"text-white/30 italic",children:"No description"}))})]})]}),hs&&h&&(ja?.kind??D.connection.kind)==="local"&&(0,k.jsx)("div",{className:"pl-0",children:(0,k.jsxs)("label",{className:"flex items-start gap-1.5 py-1 cursor-pointer",children:[(0,k.jsx)(Lr,{className:"h-3 w-3 text-cyan-400 shrink-0 mt-0.5"}),(0,k.jsx)("input",{type:"checkbox",checked:ge.recognizesPackages??!1,onChange:Oe=>Qr(D.source,Et=>({...Et,recognizesPackages:Oe.target.checked})),className:"accent-cyan-400 h-3 w-3 mt-0.5"}),(0,k.jsxs)("span",{className:"text-[10px] text-white/70 leading-tight",children:["Recognize packages",(0,k.jsxs)("span",{className:"block text-[9px] text-white/35 normal-case font-normal",children:["Load packages found in this folder (in addition to ",(0,k.jsx)("code",{children:"_packages/"}),") \u2014 applied on save; advertised only within this source's scope."]})]})]})}),(0,k.jsxs)("div",{children:[(0,k.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>Vf(D.source,"perms"),className:"flex items-center gap-1.5 flex-1 text-left",children:[(0,k.jsx)(Ns,{className:"h-3 w-3 text-emerald-400 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Permissions"}),(0,k.jsx)(un,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",Zs.perms&&"rotate-90")})]}),(0,k.jsx)(Qg.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-uri-policy",packageId:"@neuralis/brain-core",scripts:["scripts/show-uri.sh","scripts/set-uri.sh","scripts/manifests.sh"],label:`Edit URI policy for "${D.source}" with the agent`,icon:"shield"})]}),Zs.perms&&(0,k.jsx)("div",{className:"pl-5 pt-1",children:(0,k.jsx)(Yg,{source:D.source,permissions:D.permissions,mode:hs?"edit":"view",onSave:hs?Oe=>k2(D,Oe):void 0})})]}),qa&&(0,k.jsxs)("div",{children:[(0,k.jsxs)("button",{type:"button",onClick:()=>Vf(D.source,"sync"),className:"flex items-center gap-1.5 py-1 w-full text-left",children:[(0,k.jsx)(Ot,{className:"h-3 w-3 text-blue-400 shrink-0"}),(0,k.jsx)("span",{className:"text-[10px] font-semibold text-white/70 flex-1",children:"Sync"}),rc&&(0,k.jsx)("span",{className:"text-[9px] text-white/35",children:hE(Hn.trigger)}),(0,k.jsx)(un,{className:V("h-2.5 w-2.5 text-white/25 transition-transform",Zs.sync&&"rotate-90")})]}),Zs.sync&&(0,k.jsxs)("div",{className:"pl-5 space-y-2 pt-1",children:[(0,k.jsx)("div",{className:"text-[10px] text-white/35 italic",children:"Sync indexes files for AI search. Excluded patterns (logs/, node_modules/) are skipped automatically."}),(0,k.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,k.jsx)("input",{type:"checkbox",checked:rc,onChange:Oe=>Qr(D.source,Et=>({...Et,...Oe.target.checked?{sync:{...Jg,exclude:[...D.defaultSyncExclude??Jg.exclude]}}:{sync:void 0}})),className:"accent-emerald-400 h-3 w-3"}),"Enable sync"]}),rc&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsxs)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35 flex items-center gap-1",children:[(0,k.jsx)(va,{className:"h-2.5 w-2.5 text-cyan-300/60"})," Trigger"]}),(0,k.jsx)("select",{value:Er.mode,onChange:Oe=>{let Et=Oe.target.value;Qr(D.source,Qn=>({...Qn,sync:{...Hn,trigger:Zg(Et,Er.val,Er.unit)}}))},className:Pf,children:tE.map(Oe=>(0,k.jsx)("option",{value:Oe.value,children:Oe.label},Oe.value))}),Er.mode==="interval"&&(0,k.jsxs)("div",{className:"flex gap-1",children:[(0,k.jsx)("input",{type:"number",min:Rf(Er.unit),value:Er.val,onChange:Oe=>{let Et=Oe.target.value.replace(/\D/g,"")||String(Rf(Er.unit));Qr(D.source,Qn=>({...Qn,sync:{...Hn,trigger:Zg("interval",Et,Er.unit)}}))},className:V(Wo,"w-16")}),(0,k.jsx)("select",{value:Er.unit,onChange:Oe=>{let Et=Oe.target.value,Qn=String(Math.max(Number.parseInt(Er.val,10)||1,Rf(Et)));Qr(D.source,Qs=>({...Qs,sync:{...Hn,trigger:Zg("interval",Qn,Et)}}))},className:V(Pf,"flex-1"),children:nE.map(Oe=>(0,k.jsx)("option",{value:Oe.value,children:Oe.label},Oe.value))})]}),(0,k.jsx)("div",{className:"text-[8px] text-white/35 italic leading-relaxed",children:Er.mode==="manual"?"Manual: nothing triggers it automatically \u2014 indexes only when you click Sync below.":Er.mode==="auto"?"Auto: re-indexes on file changes (host edits, git, shell \u2014 anything) + a periodic full reconcile.":"Scheduled: runs a full reconcile every interval above."})]}),(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Exclude"}),(0,k.jsx)("textarea",{value:Nf(Hn.exclude),onChange:Oe=>{let Et=Vu(Oe.target.value);Qr(D.source,Qn=>({...Qn,sync:{...Hn,exclude:Et}}))},rows:5,className:V($u,"font-mono"),placeholder:`# .gitignore syntax
|
|
47
47
|
node_modules/**
|
|
48
48
|
.git/**
|
|
49
|
-
dist/**`}),(0,
|
|
49
|
+
dist/**`}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Uses .gitignore syntax. Lines starting with # are comments."})]}),(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Include (allowlist)"}),(0,k.jsx)("textarea",{value:Nf(Hn.include??[]),onChange:Oe=>{let Et=Vu(Oe.target.value);Qr(D.source,Qn=>({...Qn,sync:{...Hn,...Et.length>0?{include:Et}:{include:void 0}}}))},rows:3,className:V($u,"font-mono"),placeholder:`# empty = everything
|
|
50
50
|
docs/**
|
|
51
|
-
packages/*/skills/**`}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,S.jsx)("input",{type:"number",min:1,step:1e3,value:Un.maxScanFiles??"",onChange:We=>{let _t=Number(We.target.value),Zn=Number.isFinite(_t)&&_t>0?Math.floor(_t):void 0;Zr(F.source,Zs=>({...Zs,sync:{...Un,maxScanFiles:Zn}}))},className:q(zo,"w-28 font-mono"),placeholder:"200000"}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Un.alwaysActive??(F.source==="data"||F.source==="packages"),onChange:We=>Zr(F.source,_t=>({..._t,sync:{...Un,alwaysActive:We.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,S.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,S.jsxs)("div",{className:"space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:Q5.map(We=>(0,S.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,S.jsx)("input",{type:"checkbox",checked:Un.media?.[We.key]??We.on,onChange:_t=>Zr(F.source,Zn=>({...Zn,sync:{...Un,media:{...Un.media??{},[We.key]:_t.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),We.label]},We.key))}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),F.sync?.lastSyncResult&&(0,S.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,S.jsxs)("span",{children:["Last sync: +",F.sync.lastSyncResult.filesAdded," -",F.sync.lastSyncResult.filesRemoved," ~",F.sync.lastSyncResult.filesUpdated]}),(0,S.jsxs)("span",{children:["(",(F.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),F.sync.lastSyncResult.error&&(0,S.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:F.sync.lastSyncResult.error,children:"err"})]}),tI(F.sync?.lastSyncResult?.mediaSkipped)&&(0,S.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:tI(F.sync?.lastSyncResult?.mediaSkipped)})]})]})]}),(0,S.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,S.jsx)("span",{className:"text-[9px] text-white/30",children:F.observed?"Observed runtime source":jf?"Unsaved changes":"No pending changes"}),(0,S.jsxs)("div",{className:"flex items-center gap-1.5",children:[cs&&za&&(fn||qo)?(0,S.jsxs)("button",{type:"button",onClick:()=>{m2(F.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,S.jsx)(Ol,{className:"h-2.5 w-2.5"}),"Cancel"]}):cs&&za?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)("button",{type:"button",disabled:!Ju,onClick:()=>{p2(F.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(Tl,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,S.jsxs)("button",{type:"button",disabled:qo,onClick:()=>{g2(F.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(br,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,S.jsxs)("button",{type:"button",disabled:qo,onClick:()=>at(F.source),title:"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,S.jsx)(wa,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(0,S.jsxs)("button",{type:"button",disabled:je===F.source,onClick:()=>{x2(F.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[je===F.source?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(oo,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,F.canMaintain===!0&&(0,S.jsx)("button",{type:"button",onClick:()=>{de.current++,Pt(F.source),Ne("source"),Je(""),Mt(!0),oe(null),Kt(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),cs&&!v2(F.source)&&(0,S.jsxs)("button",{type:"button",disabled:us,onClick:()=>ue(F.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[us?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,S.jsxs)("button",{type:"button",disabled:an||!jf,onClick:()=>{f2(F,ge)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[an?(0,S.jsx)(ze,{className:"h-2.5 w-2.5 animate-spin"}):(0,S.jsx)(io,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),vt===F.source&&F.canMaintain===!0&&(0,S.jsxs)("fieldset",{disabled:jt,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,S.jsxs)("legend",{children:["Clean index for ",F.source]}),(0,S.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,S.jsxs)("label",{children:["Selection ",(0,S.jsxs)("select",{"aria-label":"Index cleanup selection",value:Ye,onChange:We=>{de.current++,Ne(We.target.value),oe(null)},className:"bg-[#15151d]",children:[(0,S.jsx)("option",{value:"source",children:"Whole source"}),(0,S.jsx)("option",{value:"folder",children:"Folder"}),(0,S.jsx)("option",{value:"file",children:"File"})]})]}),Ye!=="source"&&(0,S.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${F.source}://path`,value:tt,onChange:We=>{de.current++,Je(We.target.value),oe(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,S.jsxs)("label",{className:"block",children:[(0,S.jsx)("input",{type:"checkbox",checked:Ft,onChange:We=>{de.current++,Mt(We.target.checked),oe(null)}})," Only excluded files and disabled media lanes"]}),!Ft&&(0,S.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),Te&&(0,S.jsxs)("p",{children:[Te.removedParents," parents removed \xB7 ",Te.removedChunks," chunks removed \xB7 ",Te.retained," recovery payloads retained \xB7 ",Te.unresolved," unresolved points kept"]}),(0,S.jsxs)("div",{className:"flex gap-2",children:[(0,S.jsx)("button",{type:"button",onClick:()=>{de.current++,Pt(null),oe(null)},children:"Cancel"}),(0,S.jsx)("button",{type:"button",onClick:()=>{p0(F.source,"estimate")},children:jt?"Working\u2026":"Preview counts"}),Te?.canMaintain&&(0,S.jsx)("button",{type:"button",onClick:()=>{p0(F.source,"apply")},children:"Confirm cleanup"})]})]}),ce===F.source&&(0,S.jsx)(eI,{source:F.source,vectorCount:typeof F.indexed_count=="number"?F.indexed_count:null,isDockerMount:!!F.connection?.config?.hostRoot,busy:us,onCancel:()=>ue(null),onConfirm:We=>{b2(F.source,We)}}),Dt===F.source&&(0,S.jsx)(kc,{agentId:e,...t?{projectId:t}:{},target:{source:F.source,label:F.source},onClose:()=>at(null),onStarted:()=>{h0(F.source,()=>Promise.resolve(),"Re-embed failed")}})]},wx(rr(F.source)))})})]},T))}),He&&(0,S.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:He}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Ge(T=>!T),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(br,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 transition-transform",Ce&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("overflow-hidden transition-all duration-200",Ce?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:Ce&&(0,S.jsx)(YL,{agentId:e,projectId:t})})]}),(0,S.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,S.jsxs)("button",{type:"button",onClick:()=>Ae(T=>!T),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,S.jsx)(si,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,S.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,S.jsx)(Tt,{className:q("h-3 w-3 text-white/25 transition-transform",Ke&&"rotate-180")})]}),(0,S.jsx)("div",{className:q("overflow-hidden transition-all duration-200",Ke?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,S.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,S.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,S.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,S.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"pnpm neuralis:mount"})}),(0,S.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,S.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,S.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"pnpm neuralis:mount add <host-path> --slug <name>"}),(0,S.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),Jr.length>0?(0,S.jsxs)("div",{className:"pt-1.5",children:[(0,S.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,S.jsx)("ul",{className:"space-y-1",children:Jr.map(T=>{let Z=yc("unattached"),F=(0,sr.resolveLucideIcon)(T.icon??null)||Gn;return(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button",onClick:()=>O(T),className:q("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",Z.containerClassName),title:Z.title,children:[(0,S.jsx)(F,{className:q("h-3.5 w-3.5 mt-0.5 shrink-0",Z.iconClassName)}),(0,S.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,S.jsxs)("div",{className:q("text-[11px] font-semibold truncate",Z.labelClassName),children:[T.label,(0,S.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[T.suggestedScheme,"://"]})]}),(0,S.jsx)("div",{className:q("text-[9px] truncate",Z.detailClassName),children:T.description}),(0,S.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:T.root})]}),(0,S.jsx)(Fn,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},T.id)})})]}):(0,S.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var Rt=W($e(),1),t0=W(Ya(),1);var hI=W(mr(),1);async function Xi(n){let e=await n.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${n.status}): ${e.slice(0,200)}`)}}async function iI(n){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let t=await Xi(e),r=[...t.skills,...t.instructions,...t.rules,...t.agents,...t.docs],a=Qg(t.tools,i=>i.packageId),s=Qg(r,i=>i.packageId),o=Qg(t.commands,i=>i.packageId);return t.packages.map(i=>({slug:i.id,packageId:i.id,name:i.name,version:i.version,description:i.description,source:i.source,runtime:i.runtime,access:i.access,status:i.status,partialReason:i.partialReason,toolCount:a.get(i.id)??0,fileCount:s.get(i.id)??0,commandCount:o.get(i.id)??0,...i.accessFeature?{accessFeature:i.accessFeature,accessFeatureSource:i.accessFeatureSource}:{}}))}async function lI(n,e){let t=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return Xi(t)}async function uI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return Xi(r)}async function cI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return Xi(r)}async function dI(n){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let t=await Xi(e),r=new Set;for(let a of t.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function fI(n){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return Xi(e)}function Qg(n,e){let t=new Map;for(let r of n){let a=e(r);t.set(a,(t.get(a)??0)+1)}return t}var Y=W(le(),1),sE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function pI({projectId:n}){let t=(hn().currentRole?.priority??99)<=2,[r,a]=(0,Rt.useState)([]),[s,o]=(0,Rt.useState)(!0),[i,l]=(0,Rt.useState)(null),[u,c]=(0,Rt.useState)({}),[d,f]=(0,Rt.useState)({}),[h,p]=(0,Rt.useState)(null),[m,g]=(0,Rt.useState)(!1);(0,Rt.useEffect)(()=>{g(!0)},[]);let[x,w]=(0,Rt.useState)(null),[y,C]=(0,Rt.useState)([]),[k,v]=(0,Rt.useState)(null),[b,P]=(0,Rt.useState)([]),N=(0,Rt.useCallback)(async()=>{o(!0),l(null);try{let L=await iI(n);a(L)}catch(L){l(L instanceof Error?L.message:String(L))}finally{o(!1)}try{let L=await fI(n);C(L.entries),v(null)}catch(L){C([]),v(L instanceof Error?L.message:String(L))}},[n]);(0,Rt.useEffect)(()=>{N()},[N]),(0,Rt.useEffect)(()=>{if(!t)return;let L=!1;return dI(n).then(R=>{L||P(R)}).catch(()=>{}),()=>{L=!0}},[n,t]);let M=(0,Rt.useCallback)(L=>{c(R=>({...R,[L]:!R[L]}))},[]),U=(0,Rt.useCallback)(async L=>{let R=L.access?.trust??"untrusted";if(R==="first-party")return;let z=R==="trusted"?"untrusted":"trusted";f(J=>({...J,[L.slug]:"trust"}));try{await uI(n,L.slug,z),p(`Trust: ${L.slug} \u2192 ${z}`),await N()}catch(J){p(J instanceof Error?J.message:"Failed to set trust")}finally{f(J=>({...J,[L.slug]:"none"}))}},[n,N]),I=(0,Rt.useCallback)(async(L,R)=>{f(z=>({...z,[L.slug]:"access-feature"}));try{await cI(n,L.packageId,R),p(R?`Access feature: ${L.slug} \u2192 ${R}`:`Access feature cleared: ${L.slug}`),await N()}catch(z){p(z instanceof Error?z.message:"Failed to set access feature")}finally{f(z=>({...z,[L.slug]:"none"}))}},[n,N]),A=(0,Rt.useCallback)(async L=>{f(z=>({...z,[L.slug]:"build"})),w({slug:L.slug,logs:["Starting build\u2026"]});let R=null;try{R=await lI(n,L.slug),w({slug:L.slug,logs:R.logs,ok:R.ok,error:R.error,durationMs:R.durationMs}),R.ok?(p(`Build complete: ${L.slug} (${R.durationMs}ms)`),await N()):p(`Build failed: ${R.error??"unknown"}`)}catch(z){let J=z instanceof Error?z.message:String(z);w({slug:L.slug,logs:[`Request failed: ${J}`],ok:!1,error:J}),p(`Build request failed: ${J}`)}finally{f(z=>({...z,[L.slug]:"none"}))}},[n,N]),G=(0,Rt.useMemo)(()=>[...r].sort((L,R)=>L.name.localeCompare(R.name)),[r]),V=(0,Rt.useMemo)(()=>{let L=new Set(r.map(R=>R.packageId));return y.filter(R=>!L.has(R.packageId)||R.status==="missing"||R.status==="error")},[y,r]),K=(0,Rt.useMemo)(()=>{let L=new Map;for(let R of y)L.set(R.packageId,R);return L},[y]);return s?(0,Y.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,Y.jsx)(ze,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):i?(0,Y.jsx)("div",{className:"p-4",children:(0,Y.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,Y.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,Y.jsx)("div",{className:"font-mono opacity-80",children:i}),(0,Y.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{N()},children:[(0,Y.jsx)(Ht,{className:"w-3 h-3"})," Retry"]})]})}):(0,Y.jsxs)("div",{className:"p-3 space-y-2",children:[(0,Y.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Y.jsx)(vr,{className:"w-4 h-4 text-violet-300"}),(0,Y.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,Y.jsxs)("span",{className:"text-[10px] text-white/45",children:[G.length," installed"]})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Y.jsx)(hI.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,Y.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{N()},children:[(0,Y.jsx)(Ht,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,Y.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,Y.jsx)(Ll,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,Y.jsxs)("div",{className:"space-y-1",children:[(0,Y.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,Y.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,Y.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),V.length>0&&(0,Y.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,Y.jsx)(dt,{className:"w-3 h-3"}),V.length," package",V.length===1?"":"s"," failed to load"]}),V.map(L=>(0,Y.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,Y.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[L.packageId," ",(0,Y.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",L.status]}),L.reason&&(0,Y.jsxs)("span",{className:"text-rose-300/55",children:[" (",L.reason,")"]})]}),L.error&&(0,Y.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:L.error}),L.sourceRoot&&(0,Y.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,Y.jsx)("span",{className:"font-mono",children:L.sourceRoot})})]},L.packageId))]}),k&&(0,Y.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,Y.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",k]}),G.length===0?(0,Y.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,Y.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,Y.jsx)("div",{className:"space-y-1",children:G.map(L=>(0,Y.jsx)(oE,{row:L,expanded:!!u[L.slug],pending:d[L.slug]??"none",canGovern:t,featureIds:b,onToggle:()=>M(L.slug),onFlipTrust:()=>{U(L)},onBuild:()=>{A(L)},onSetAccessFeature:R=>{I(L,R)}},L.slug))}),h&&m?(0,t0.createPortal)((0,Y.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&m?(0,t0.createPortal)((0,Y.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>w(null),children:(0,Y.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:L=>L.stopPropagation(),children:[(0,Y.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,Y.jsx)(ze,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,Y.jsx)(ea,{className:"w-4 h-4 text-emerald-400"}):(0,Y.jsx)(dt,{className:"w-4 h-4 text-amber-300"}),(0,Y.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,Y.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,Y.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>w(null),children:"Close"})]}),(0,Y.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
|
|
52
|
-
`)})]})}),document.body):null]})}function oE(n){let{row:e,expanded:t,pending:r,canGovern:a,featureIds:s,onToggle:o,onFlipTrust:i,onBuild:l,onSetAccessFeature:u}=n,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?sE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",m=c==="first-party";return(0,Y.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,Y.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:o,children:[t?(0,Y.jsx)(Tt,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,Y.jsx)(un,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,Y.jsx)(vr,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,Y.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,Y.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,Y.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,Y.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,Y.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,Y.jsx)(lE,{status:e.status,partialLabel:h?.label}),(0,Y.jsx)(uE,{trust:c}),(0,Y.jsx)(cE,{type:d})]})]})]}),t?(0,Y.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,Y.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,Y.jsx)(dt,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,Y.jsxs)("div",{children:[(0,Y.jsx)("div",{className:"font-semibold",children:h.label}),(0,Y.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,Y.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,Y.jsx)(e0,{label:"Tools",value:e.toolCount}),(0,Y.jsx)(e0,{label:"Skills / files",value:e.fileCount}),(0,Y.jsx)(e0,{label:"Commands",value:e.commandCount})]}),(0,Y.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,Y.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",m?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:m||r!=="none",onClick:i,title:m?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,Y.jsx)(ai,{className:"w-3 h-3"}):(0,Y.jsx)(El,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,Y.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,Y.jsx)(uo,{className:"w-3 h-3"}),"Build"]}),(0,Y.jsx)(dE,{trust:c})]}),a?(0,Y.jsx)(iE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,Y.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,Y.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,Y.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function iE(n){let{row:e,featureIds:t,pending:r,disabled:a,onSetAccessFeature:s}=n,[o,i]=(0,Rt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,Rt.useEffect)(()=>{i(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=o.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,Y.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,Y.jsx)(Is,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,Y.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,Y.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,Y.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,Y.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Y.jsx)("input",{list:l,value:o,onChange:h=>i(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,Y.jsx)("datalist",{id:l,children:t.map(h=>(0,Y.jsx)("option",{value:h},h))}),(0,Y.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,Y.jsx)(ze,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,Y.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function lE(n){let{status:e,partialLabel:t}=n;return e==="partial"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,Y.jsx)(dt,{className:"w-2.5 h-2.5"})," ",t??"Partial"]}):e==="error"?(0,Y.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,Y.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Y.jsx)(ea,{className:"w-2.5 h-2.5"})," Active"]})}function uE(n){let{trust:e}=n;return e==="first-party"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,Y.jsx)(Is,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Y.jsx)(ai,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,Y.jsx)(va,{className:"w-2.5 h-2.5"})," Untrusted"]})}function cE(n){let{type:e}=n;return(0,Y.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,Y.jsx)(Gl,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function e0(n){return(0,Y.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,Y.jsx)("div",{className:"text-white/45",children:n.label}),(0,Y.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:n.value})]})}function dE(n){let[e,t]=(0,Rt.useState)(!1);return(0,Y.jsxs)("div",{className:"relative",children:[(0,Y.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>t(r=>!r),children:(0,Y.jsx)(ta,{className:"w-3 h-3"})}),e?(0,Y.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,Y.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:n.trust==="trusted"?"Trusted":n.trust==="first-party"?"First-party":"Untrusted"}),(0,Y.jsx)("div",{className:"text-white/60",children:n.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":n.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}function Wo(n){let e=n.trim();if(!e)return"";let t=e.indexOf("://"),r=t>=1?e.slice(0,t+3):"",a=t>=1?e.slice(t+3):e,s=a.length>0&&a.endsWith("/"),o=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){o.pop();continue}o.push(l)}let i=o.join("/");return i?`${r}${i}${s?"/":""}`:r}var Ff=W(Qr(),1);var fr=W($e(),1);function mI(n){let{agentId:e,projectId:t,sources:r,revisions:a,resetKey:s}=n,[o,i]=(0,fr.useState)([]),[l,u]=(0,fr.useState)(!1),c=(0,fr.useRef)(Promise.resolve()),d=(0,fr.useRef)(0),f=(0,fr.useRef)([]),h=(0,fr.useRef)({}),p=(0,fr.useRef)(!0),m=(0,fr.useCallback)(async g=>{if(!e)return;g&&(p.current=!0);let x=++d.current,w=t?{projectId:t}:{},y=c.current.then(async()=>{if(x!==d.current)return;let C=[...f.current],k=p.current;p.current=!1;let v=()=>{f.current=[...C],i([...C])};u(!0);try{for(let b of r){if(!b.git?.isRepo&&!b.git?.containsRepos)continue;let P=b.uri_root.replace("://",""),N=a[P]??0;if(!(!k&&h.current[P]===N))try{let M=await Xo({agentId:e,...w,source:P});if(x!==d.current)return;for(let U=C.length-1;U>=0;U--)C[U].source===P&&!M.repos.some(I=>I.rel===C[U].repo.rel)&&C.splice(U,1);for(let U of M.repos){let I={source:P,repo:U};try{let G=await Qu({agentId:e,...w,source:P,repo:U.rel});if(x!==d.current)return;G.ok===!1?I.error="Git status unavailable":I.status=G.status}catch(G){I.error=G instanceof Error?G.message:"Git status failed"}let A=C.findIndex(G=>G.source===P&&G.repo.rel===U.rel);A<0?C.push(I):C[A]=I,v()}h.current[P]=N}catch(M){if(x!==d.current)return;let U={source:P,repo:{rel:"",name:P},error:M instanceof Error?M.message:"Repository discovery failed"},I=C.findIndex(A=>A.source===P&&A.repo.rel==="");I>=0?C[I]=U:C.push(U),h.current[P]=N,v()}}x===d.current&&v()}finally{x===d.current&&u(!1)}});c.current=y.catch(()=>{}),await y},[e,t,r,a]);return(0,fr.useEffect)(()=>{d.current++,f.current=[],h.current={},p.current=!0,i([])},[s]),(0,fr.useEffect)(()=>(m(!1),()=>{d.current++}),[m]),{groups:o,loading:l,refresh:m}}var ve=W($e(),1);var _I=W(mr(),1);var If=W($e(),1);var gI=W($e(),1),Vu=W(le(),1),fE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},xI=(0,gI.memo)(function({lineNo:e,type:t,content:r}){return(0,Vu.jsxs)("div",{className:`flex h-[18px] min-w-full w-max ${fE[t]}`,children:[(0,Vu.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,Vu.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var Ks=W(le(),1),Yi=(0,If.memo)(function({hunks:e,isStreaming:t,maxLines:r=200}){let{elements:a,truncated:s}=(0,If.useMemo)(()=>{let o=[],i=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";o.push((0,Ks.jsx)(hE,{label:h},`skip-${i}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=t?"add":h.type,m=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),o.push((0,Ks.jsx)(xI,{lineNo:m,type:p,content:h.content},`line-${i}`)),i++,l++}if(u)break}return{elements:o,truncated:u}},[e,t,r]);return a.length===0?(0,Ks.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,Ks.jsxs)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:[a,s&&(0,Ks.jsxs)("div",{className:"text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((o,i)=>o+i.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})},(n,e)=>{if(n.isStreaming!==e.isStreaming||n.maxLines!==e.maxLines||n.language!==e.language)return!1;if(n.hunks===e.hunks)return!0;if(n.hunks.length!==e.hunks.length)return!1;for(let t=0;t<n.hunks.length;t++){let r=n.hunks[t],a=e.hunks[t];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],o=a.lines[0];if(s?.type!==o?.type||s?.content!==o?.content)return!1;let i=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(i?.type!==l?.type||i?.content!==l?.content)return!1}return!0});function hE({label:n}){return(0,Ks.jsx)("div",{className:"text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:n})}var Pf=W(Qr(),1);function yI(n){return n.snapshotHash?null:"originalDraftUnknown"}function n0(n){return String(n||"").replace(/\r\n/g,`
|
|
51
|
+
packages/*/skills/**`}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Non-empty: only matching files sync. Excludes always win \u2014 an excluded path can never be re-included."})]}),(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Max scan files"}),(0,k.jsx)("input",{type:"number",min:1,step:1e3,value:Hn.maxScanFiles??"",onChange:Oe=>{let Et=Number(Oe.target.value),Qn=Number.isFinite(Et)&&Et>0?Math.floor(Et):void 0;Qr(D.source,Qs=>({...Qs,sync:{...Hn,maxScanFiles:Qn}}))},className:V(Wo,"w-28 font-mono"),placeholder:"200000"}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Per-source cap on files walked during sync/count. Empty = inherit the platform default. When a walk hits the cap the count shows N+."})]}),(0,k.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,k.jsx)("input",{type:"checkbox",checked:Hn.alwaysActive??(D.source==="data"||D.source==="packages"),onChange:Oe=>Qr(D.source,Et=>({...Et,sync:{...Hn,alwaysActive:Oe.target.checked}})),className:"accent-cyan-400 h-3 w-3"}),"Always active",(0,k.jsx)("span",{className:"text-[8px] text-white/30 normal-case",children:'(pins this source in the auto-sync pool even when the platform Auto-Sync Mode is "packages-only"; no effect with the Manual trigger)'})]}),(0,k.jsxs)("div",{className:"space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/35",children:"Media"}),(0,k.jsx)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:cE.map(Oe=>(0,k.jsxs)("label",{className:"inline-flex items-center gap-1.5 text-[10px] text-white/80 cursor-pointer",children:[(0,k.jsx)("input",{type:"checkbox",checked:Hn.media?.[Oe.key]??Oe.on,onChange:Et=>Qr(D.source,Qn=>({...Qn,sync:{...Hn,media:{...Hn.media??{},[Oe.key]:Et.target.checked}}})),className:"accent-cyan-400 h-3 w-3"}),Oe.label]},Oe.key))}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 italic",children:"Embeds these files from their bytes \u2014 only while the active embedding model is multimodal (a text-only model skips them and the last-sync line says so). Each image or PDF page is one provider call; video and audio cost the most. Unticking a kind clears its searchable cache at the next full sync while preserving recovery content."})]}),D.sync?.lastSyncResult&&(0,k.jsxs)("div",{className:"text-[9px] text-white/40 flex items-center gap-2",children:[(0,k.jsxs)("span",{children:["Last sync: +",D.sync.lastSyncResult.filesAdded," -",D.sync.lastSyncResult.filesRemoved," ~",D.sync.lastSyncResult.filesUpdated]}),(0,k.jsxs)("span",{children:["(",(D.sync.lastSyncResult.durationMs/1e3).toFixed(1),"s)"]}),D.sync.lastSyncResult.error&&(0,k.jsx)("span",{className:"text-rose-300/80 truncate max-w-[200px]",title:D.sync.lastSyncResult.error,children:"err"})]}),oI(D.sync?.lastSyncResult?.mediaSkipped)&&(0,k.jsx)("div",{className:"text-[9px] text-amber-200/70",role:"status",children:oI(D.sync?.lastSyncResult?.mediaSkipped)}),iI(D.sync?.lastSyncResult?.binarySkipped)&&(0,k.jsx)("div",{className:"text-[9px] text-white/40",role:"status",children:iI(D.sync?.lastSyncResult?.binarySkipped)}),(()=>{let Oe=dE(D.sync?.lastSyncResult?.embeddingDegraded,D.embedding_enabled);return Oe?(0,k.jsx)("div",{className:Oe.attention?"text-[9px] text-amber-200/70":"text-[9px] text-white/40",role:"status",children:Oe.text}):null})(),ot[D.source]&&(0,k.jsxs)("div",{className:"text-[9px] text-amber-200/70 flex items-center gap-2",role:"status",children:[(0,k.jsxs)("span",{children:["Embedding paused: ",ot[D.source]]}),(0,k.jsx)("button",{type:"button",disabled:Wa,onClick:()=>{L2(D.source)},className:"h-5 px-1.5 rounded bg-white/[0.04] hover:bg-white/[0.08] text-amber-200/90 disabled:opacity-35",children:"Resume"})]})]})]})]}),(0,k.jsxs)("div",{className:"flex items-center justify-between gap-2 pt-1.5 border-t border-white/[0.06]",children:[(0,k.jsx)("span",{className:"text-[9px] text-white/30",children:D.observed?"Observed runtime source":Kf?"Unsaved changes":"No pending changes"}),(0,k.jsxs)("div",{className:"flex items-center gap-1.5",children:[hs&&qa&&(Yt||Wa)?(0,k.jsxs)("button",{type:"button",onClick:()=>{C2(D.source)},className:"h-6 px-2 rounded-md bg-rose-500/10 hover:bg-rose-500/20 border border-rose-400/25 text-[9px] font-medium text-rose-300/80 hover:text-rose-200 transition inline-flex items-center gap-1",children:[(0,k.jsx)(_l,{className:"h-2.5 w-2.5"}),"Cancel"]}):hs&&qa?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("button",{type:"button",disabled:!rc,onClick:()=>{S2(D.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-blue-300/80 hover:text-blue-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,k.jsx)(Dl,{className:"h-2.5 w-2.5"}),"Sync"]}),(0,k.jsxs)("button",{type:"button",disabled:Wa,onClick:()=>{I2(D.source)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,k.jsx)(ir,{className:"h-2.5 w-2.5"}),"Rescan changes"]}),(0,k.jsxs)("button",{type:"button",disabled:Wa||D.embedding_enabled===!1,onClick:()=>Xe(D.source),title:D.embedding_enabled===!1?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed every file of this source again with the active model \u2014 shows the estimated cost first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,k.jsx)(Sa,{className:"h-2.5 w-2.5"}),"Re-embed\u2026"]}),(()=>{let Oe=D.embedding_enabled===!1;return(0,k.jsxs)("button",{type:"button",disabled:Wa||Oe,onClick:()=>Nt(D.source),title:Oe?"Semantic embedding is off \u2014 turn it on in the platform settings first":"Embed only the files whose semantic embedding is missing or stale \u2014 shows the estimate first",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-cyan-300/80 hover:text-cyan-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[(0,k.jsx)(ir,{className:"h-2.5 w-2.5"}),"Embed pending\u2026"]})})(),(0,k.jsxs)("button",{type:"button",disabled:Ye===D.source,onClick:()=>{A2(D.source)},title:"Forgets what the last sync saw \u2014 the next sync compares every file again. Deletes no file and no vector.",className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-amber-300/80 hover:text-amber-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[Ye===D.source?(0,k.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,k.jsx)(io,{className:"h-2.5 w-2.5"}),"Forget sync state"]})]}):null,D.canMaintain===!0&&(0,k.jsx)("button",{type:"button",onClick:()=>{Ce.current++,pt(D.source),kt("source"),xe(""),en(!0),pe(null),Pe(!1)},className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] text-amber-300/80",children:"Clean index\u2026"}),hs&&!M2(D.source)&&(0,k.jsxs)("button",{type:"button",disabled:ea,onClick:()=>ie(D.source),className:"h-6 px-2 rounded-md bg-white/[0.04] hover:bg-white/[0.08] text-[9px] font-medium text-red-300/80 hover:text-red-200 transition disabled:opacity-35 inline-flex items-center gap-1",children:[ea?(0,k.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,k.jsx)(It,{className:"h-2.5 w-2.5"}),"Delete"]}),(0,k.jsxs)("button",{type:"button",disabled:qt||!Kf,onClick:()=>{v2(D,ge)},className:"h-6 px-2.5 rounded-md bg-emerald-500/12 border border-emerald-400/25 text-[9px] font-semibold text-emerald-200/90 hover:bg-emerald-500/20 transition disabled:opacity-35 inline-flex items-center gap-1",children:[qt?(0,k.jsx)(We,{className:"h-2.5 w-2.5 animate-spin"}):(0,k.jsx)(lo,{className:"h-2.5 w-2.5"}),"Save"]})]})]})]})}),tt===D.source&&D.canMaintain===!0&&(0,k.jsxs)("fieldset",{disabled:je,className:"ml-5 mb-2 rounded-md border border-amber-400/20 p-3 space-y-2 text-[10px] text-white/70",children:[(0,k.jsxs)("legend",{children:["Clean index for ",D.source]}),(0,k.jsx)("p",{children:"The source, files, pending changes and recovery history stay available. Cleanup makes no embedding calls."}),(0,k.jsxs)("label",{children:["Selection ",(0,k.jsxs)("select",{"aria-label":"Index cleanup selection",value:Rt,onChange:Oe=>{Ce.current++,kt(Oe.target.value),pe(null)},className:"bg-[#15151d]",children:[(0,k.jsx)("option",{value:"source",children:"Whole source"}),(0,k.jsx)("option",{value:"folder",children:"Folder"}),(0,k.jsx)("option",{value:"file",children:"File"})]})]}),Rt!=="source"&&(0,k.jsx)("input",{"aria-label":"Index cleanup URI",placeholder:`${D.source}://path`,value:Ee,onChange:Oe=>{Ce.current++,xe(Oe.target.value),pe(null)},className:"block w-full bg-white/5 rounded px-2 py-1"}),(0,k.jsxs)("label",{className:"block",children:[(0,k.jsx)("input",{type:"checkbox",checked:Dt,onChange:Oe=>{Ce.current++,en(Oe.target.checked),pe(null)}})," Only excluded files and disabled media lanes"]}),!Dt&&(0,k.jsx)("p",{children:"All selected searchable cache will be cleared. A later sync can rebuild it."}),he&&(0,k.jsxs)("p",{children:[he.removedParents," parents removed \xB7 ",he.removedChunks," chunks removed \xB7 ",he.retained," recovery payloads retained \xB7 ",he.unresolved," unresolved points kept"]}),(0,k.jsxs)("div",{className:"flex gap-2",children:[(0,k.jsx)("button",{type:"button",onClick:()=>{Ce.current++,pt(null),pe(null)},children:"Cancel"}),(0,k.jsx)("button",{type:"button",onClick:()=>{y0(D.source,"estimate")},children:je?"Working\u2026":"Preview counts"}),he?.canMaintain&&(0,k.jsx)("button",{type:"button",onClick:()=>{y0(D.source,"apply")},children:"Confirm cleanup"})]})]}),ue===D.source&&(0,k.jsx)(sI,{source:D.source,vectorCount:typeof D.indexed_count=="number"?D.indexed_count:null,isDockerMount:!!D.connection?.config?.hostRoot,busy:ea,onCancel:()=>ie(null),onConfirm:Oe=>{N2(D.source,Oe)}}),lt===D.source&&(0,k.jsx)($l,{kind:"pending",agentId:e,...t?{projectId:t}:{},target:{source:D.source,label:D.source},onClose:()=>Nt(null),onStarted:()=>{nc(D.source,()=>Promise.resolve(),"Embedding failed")}}),Pt===D.source&&(0,k.jsx)($l,{agentId:e,...t?{projectId:t}:{},target:{source:D.source,label:D.source},onClose:()=>Xe(null),onStarted:()=>{nc(D.source,()=>Promise.resolve(),"Re-embed failed")}})]},Cx(or(D.source)))})})]},F))}),Re&&(0,k.jsx)("div",{className:"mt-2 rounded-md bg-emerald-500/10 border border-emerald-400/25 px-2.5 py-1.5 text-[10px] text-emerald-200/85",children:Re}),(0,k.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>ut(!de),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,k.jsx)(ir,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,k.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Vector Health"}),(0,k.jsx)(Tt,{className:V("h-3 w-3 text-white/25 transition-transform",de&&"rotate-180")})]}),(0,k.jsx)("div",{className:V("overflow-hidden transition-all duration-200",de?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:de&&(0,k.jsx)(tI,{agentId:e,projectId:t})})]}),(0,k.jsxs)("div",{className:"border-t border-white/[0.06] pt-2 mt-3",children:[(0,k.jsxs)("button",{type:"button",onClick:()=>nn(F=>!F),className:"flex items-center gap-2 py-1.5 w-full text-left",children:[(0,k.jsx)(oi,{className:"h-4 w-4 text-cyan-400 shrink-0"}),(0,k.jsx)("span",{className:"text-sm font-semibold text-white/92 flex-1",children:"Mount & Discover"}),(0,k.jsx)(Tt,{className:V("h-3 w-3 text-white/25 transition-transform",Ft&&"rotate-180")})]}),(0,k.jsx)("div",{className:V("overflow-hidden transition-all duration-200",Ft?"max-h-[1600px] opacity-100":"max-h-0 opacity-0"),children:(0,k.jsxs)("div",{className:"mt-3 rounded-md bg-white/[0.02] border border-white/[0.06] p-3 space-y-2",children:[(0,k.jsx)("p",{className:"text-[10px] leading-relaxed text-white/55",children:"CLI helper for exposing host folders to the brain. Run it with no arguments to print usage:"}),(0,k.jsx)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2",children:(0,k.jsx)("pre",{className:"text-[11px] font-mono text-white/85 whitespace-pre-wrap break-all",children:"neuralis mount"})}),(0,k.jsxs)("div",{className:"rounded bg-black/30 border border-white/[0.05] p-2 space-y-1",children:[(0,k.jsx)("div",{className:"text-[9px] uppercase tracking-wider text-white/40 font-semibold",children:"Example \u2014 expose a host folder as a mount"}),(0,k.jsx)("pre",{className:"text-[10px] font-mono text-white/80 whitespace-pre-wrap break-all",children:"neuralis mount add <host-path> --slug <name>"}),(0,k.jsx)("div",{className:"text-[9px] text-white/35 italic",children:"The CLI is infra-only: it registers the bind mount + host-pair env in the machine-local compose override, never a source. After the container restarts, the mount appears in the Discoverable list below \u2014 click it to attach the source with a chosen scope (the host path resolves automatically)."})]}),z.length>0?(0,k.jsxs)("div",{className:"pt-1.5",children:[(0,k.jsx)("div",{className:"text-[9px] font-semibold uppercase tracking-wider text-white/40 mb-1",children:"Discoverable"}),(0,k.jsx)("ul",{className:"space-y-1",children:z.map(F=>{let Q=Lc("unattached"),D=(0,ur.resolveLucideIcon)(F.icon??null)||Un;return(0,k.jsx)("li",{children:(0,k.jsxs)("button",{type:"button",onClick:()=>jt(F),className:V("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md hover:bg-white/[0.04] transition",Q.containerClassName),title:Q.title,children:[(0,k.jsx)(D,{className:V("h-3.5 w-3.5 mt-0.5 shrink-0",Q.iconClassName)}),(0,k.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,k.jsxs)("div",{className:V("text-[11px] font-semibold truncate",Q.labelClassName),children:[F.label,(0,k.jsxs)("span",{className:"text-[9px] text-white/30 font-mono ml-1.5",children:[F.suggestedScheme,"://"]})]}),(0,k.jsx)("div",{className:V("text-[9px] truncate",Q.detailClassName),children:F.description}),(0,k.jsx)("div",{className:"text-[8px] text-white/25 font-mono truncate",children:F.root})]}),(0,k.jsx)(Tn,{className:"h-3 w-3 text-white/40 shrink-0 mt-1"})]})},F.id)})})]}):(0,k.jsx)("div",{className:"pt-1 text-[9px] italic text-white/35",children:"No discoverable mounts at the moment."})]})})]})]})}var Mt=j(Ve(),1),s0=j(Qa(),1);var bI=j(wr(),1);async function Yi(n){let e=await n.text();try{return JSON.parse(e)}catch{throw new Error(`Invalid JSON response (HTTP ${n.status}): ${e.slice(0,200)}`)}}async function hI(n){let e=await fetch("/api/packages/runtime",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages snapshot: HTTP ${e.status}`);let t=await Yi(e),r=[...t.skills,...t.instructions,...t.rules,...t.agents,...t.docs],a=r0(t.tools,i=>i.packageId),s=r0(r,i=>i.packageId),o=r0(t.commands,i=>i.packageId);return t.packages.map(i=>({slug:i.id,packageId:i.id,name:i.name,version:i.version,description:i.description,source:i.source,runtime:i.runtime,access:i.access,status:i.status,partialReason:i.partialReason,toolCount:a.get(i.id)??0,fileCount:s.get(i.id)??0,commandCount:o.get(i.id)??0,...i.accessFeature?{accessFeature:i.accessFeature,accessFeatureSource:i.accessFeatureSource}:{}}))}async function pI(n,e){let t=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/build`,{method:"POST",credentials:"same-origin"});return Yi(t)}async function mI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/trust`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({trust:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set trust (HTTP ${r.status}): ${a.slice(0,200)}`)}return Yi(r)}async function gI(n,e,t){let r=await fetch(`/api/projects/${encodeURIComponent(n)}/packages/${encodeURIComponent(e)}/access-feature`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({featureId:t})});if(!r.ok){let a=await r.text();throw new Error(`Failed to set access feature (HTTP ${r.status}): ${a.slice(0,200)}`)}return Yi(r)}async function xI(n){let e=await fetch("/api/admin/feature-catalog",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load feature catalog: HTTP ${e.status}`);let t=await Yi(e),r=new Set;for(let a of t.groups??[])for(let s of a.features??[])r.add(s);return Array.from(r).sort()}async function yI(n){let e=await fetch("/api/packages/agent-core/packages/diagnostics",{method:"GET",headers:{"x-project-id":n},credentials:"same-origin"});if(!e.ok)throw new Error(`Failed to load packages diagnostics: HTTP ${e.status}`);return Yi(e)}function r0(n,e){let t=new Map;for(let r of n){let a=e(r);t.set(a,(t.get(a)??0)+1)}return t}var Z=j(le(),1),xE={"build-missing":{label:"Needs build",hint:"The package has server-side code (src/) but the WASM binary is missing. Click Build to compile it."},"runtime-unavailable":{label:"Runtime unavailable",hint:"MCP subprocess failed to spawn or the code runtime crashed. Check host logs."},"untrusted-node":{label:"Declarative only",hint:'Untrusted packages cannot execute in-process code. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'},"untrusted-mcp":{label:"Declarative only",hint:'The "mcp" runtime spawns a subprocess as the host user and needs first-party trust, so no subprocess was started. Declare `runtime.type: "wasm"` in the manifest to enable handlers.'}};function wI({projectId:n}){let t=(fn().currentRole?.priority??99)<=2,[r,a]=(0,Mt.useState)([]),[s,o]=(0,Mt.useState)(!0),[i,l]=(0,Mt.useState)(null),[u,c]=(0,Mt.useState)({}),[d,f]=(0,Mt.useState)({}),[h,p]=(0,Mt.useState)(null),[m,g]=(0,Mt.useState)(!1);(0,Mt.useEffect)(()=>{g(!0)},[]);let[x,b]=(0,Mt.useState)(null),[y,N]=(0,Mt.useState)([]),[L,A]=(0,Mt.useState)(null),[w,v]=(0,Mt.useState)([]),T=(0,Mt.useCallback)(async()=>{o(!0),l(null);try{let S=await hI(n);a(S)}catch(S){l(S instanceof Error?S.message:String(S))}finally{o(!1)}try{let S=await yI(n);N(S.entries),A(null)}catch(S){N([]),A(S instanceof Error?S.message:String(S))}},[n]);(0,Mt.useEffect)(()=>{T()},[T]),(0,Mt.useEffect)(()=>{if(!t)return;let S=!1;return xI(n).then(M=>{S||v(M)}).catch(()=>{}),()=>{S=!0}},[n,t]);let P=(0,Mt.useCallback)(S=>{c(M=>({...M,[S]:!M[S]}))},[]),O=(0,Mt.useCallback)(async S=>{let M=S.access?.trust??"untrusted";if(M==="first-party")return;let W=M==="trusted"?"untrusted":"trusted";f(ee=>({...ee,[S.slug]:"trust"}));try{await mI(n,S.slug,W),p(`Trust: ${S.slug} \u2192 ${W}`),await T()}catch(ee){p(ee instanceof Error?ee.message:"Failed to set trust")}finally{f(ee=>({...ee,[S.slug]:"none"}))}},[n,T]),C=(0,Mt.useCallback)(async(S,M)=>{f(W=>({...W,[S.slug]:"access-feature"}));try{await gI(n,S.packageId,M),p(M?`Access feature: ${S.slug} \u2192 ${M}`:`Access feature cleared: ${S.slug}`),await T()}catch(W){p(W instanceof Error?W.message:"Failed to set access feature")}finally{f(W=>({...W,[S.slug]:"none"}))}},[n,T]),I=(0,Mt.useCallback)(async S=>{f(W=>({...W,[S.slug]:"build"})),b({slug:S.slug,logs:["Starting build\u2026"]});let M=null;try{M=await pI(n,S.slug),b({slug:S.slug,logs:M.logs,ok:M.ok,error:M.error,durationMs:M.durationMs}),M.ok?(p(`Build complete: ${S.slug} (${M.durationMs}ms)`),await T()):p(`Build failed: ${M.error??"unknown"}`)}catch(W){let ee=W instanceof Error?W.message:String(W);b({slug:S.slug,logs:[`Request failed: ${ee}`],ok:!1,error:ee}),p(`Build request failed: ${ee}`)}finally{f(W=>({...W,[S.slug]:"none"}))}},[n,T]),H=(0,Mt.useMemo)(()=>[...r].sort((S,M)=>S.name.localeCompare(M.name)),[r]),q=(0,Mt.useMemo)(()=>{let S=new Set(r.map(M=>M.packageId));return y.filter(M=>!S.has(M.packageId)||M.status==="missing"||M.status==="error")},[y,r]),$=(0,Mt.useMemo)(()=>{let S=new Map;for(let M of y)S.set(M.packageId,M);return S},[y]);return s?(0,Z.jsxs)("div",{className:"h-full flex items-center justify-center text-white/50 text-sm",children:[(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin mr-2"})," Loading packages\u2026"]}):i?(0,Z.jsx)("div",{className:"p-4",children:(0,Z.jsxs)("div",{className:"rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-100/85",children:[(0,Z.jsx)("div",{className:"font-semibold mb-1",children:"Failed to load packages"}),(0,Z.jsx)("div",{className:"font-mono opacity-80",children:i}),(0,Z.jsxs)("button",{className:"mt-2 inline-flex items-center gap-1 rounded-md bg-white/10 px-2 py-1 text-[11px] text-white/80 hover:bg-white/15",onClick:()=>{T()},children:[(0,Z.jsx)(Ot,{className:"w-3 h-3"})," Retry"]})]})}):(0,Z.jsxs)("div",{className:"p-3 space-y-2",children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Z.jsx)(Lr,{className:"w-4 h-4 text-violet-300"}),(0,Z.jsx)("h2",{className:"text-sm font-semibold text-white/85",children:"Packages"}),(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[H.length," installed"]})]}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)(bI.SkillLauncher,{variant:"label",size:"sm",skill:"create-package",packageId:"@neuralis/brain-core",alsoRequires:["packages.author"],label:"Scaffold a package with the agent",icon:"package"}),(0,Z.jsxs)("button",{className:"inline-flex items-center gap-1 rounded-md bg-white/5 px-2 py-1 text-[11px] text-white/60 hover:bg-white/10 hover:text-white/85",onClick:()=>{T()},children:[(0,Z.jsx)(Ot,{className:"w-3 h-3"}),"Refresh"]})]})]}),(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-violet-500/15 bg-violet-500/5 px-3 py-2 text-[11px] text-violet-100/80 flex items-start gap-2",children:[(0,Z.jsx)(Il,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"space-y-1",children:[(0,Z.jsx)("div",{children:"Untrusted packages register their declarative content (skills, tool schemas, commands) but cannot execute in-process code or call other packages."}),(0,Z.jsxs)("div",{className:"text-violet-100/60",children:["Flip trust when you know the author. Run Build only for packages with server-side code in ",(0,Z.jsx)("span",{className:"font-mono",children:"src/"}),"."]})]})]}),q.length>0&&(0,Z.jsxs)("div",{className:"mx-1 rounded-lg border border-rose-500/25 bg-rose-500/[0.06] px-3 py-2 text-[11px] text-rose-100/85 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-rose-200/95 font-semibold",children:[(0,Z.jsx)(ct,{className:"w-3 h-3"}),q.length," package",q.length===1?"":"s"," failed to load"]}),q.map(S=>(0,Z.jsxs)("div",{className:"rounded border border-rose-500/15 bg-rose-500/[0.04] px-2 py-1",children:[(0,Z.jsxs)("div",{className:"font-mono text-[10px] text-rose-200/95",children:[S.packageId," ",(0,Z.jsxs)("span",{className:"text-rose-300/80",children:["\xB7 ",S.status]}),S.reason&&(0,Z.jsxs)("span",{className:"text-rose-300/55",children:[" (",S.reason,")"]})]}),S.error&&(0,Z.jsx)("div",{className:"mt-0.5 font-mono text-[10px] text-rose-100/70 whitespace-pre-wrap break-all",children:S.error}),S.sourceRoot&&(0,Z.jsx)("div",{className:"mt-0.5 text-[9px] text-rose-200/50",children:(0,Z.jsx)("span",{className:"font-mono",children:S.sourceRoot})})]},S.packageId))]}),L&&(0,Z.jsxs)("div",{className:"mx-1 rounded-md border border-amber-500/25 bg-amber-500/[0.06] px-2 py-1 text-[10px] text-amber-100/80",children:[(0,Z.jsx)("span",{className:"font-mono",children:"/packages/diagnostics"})," unreachable: ",L]}),H.length===0?(0,Z.jsxs)("div",{className:"mx-1 mt-6 rounded-lg border border-white/10 bg-white/[0.02] p-6 text-center text-white/50 text-sm",children:["No packages installed yet. Drop packages into"," ",(0,Z.jsx)("span",{className:"font-mono text-white/70",children:"_packages/"})," to see them here."]}):(0,Z.jsx)("div",{className:"space-y-1",children:H.map(S=>(0,Z.jsx)(yE,{row:S,expanded:!!u[S.slug],pending:d[S.slug]??"none",canGovern:t,featureIds:w,onToggle:()=>P(S.slug),onFlipTrust:()=>{O(S)},onBuild:()=>{I(S)},onSetAccessFeature:M=>{C(S,M)}},S.slug))}),h&&m?(0,s0.createPortal)((0,Z.jsx)("div",{className:"fixed bottom-4 right-4 z-[100000] rounded-lg border border-white/15 bg-neutral-900/95 px-3 py-2 text-[11px] text-white/85 shadow-lg",onClick:()=>p(null),children:h}),document.body):null,x&&m?(0,s0.createPortal)((0,Z.jsx)("div",{className:"fixed inset-0 z-[100000] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:()=>b(null),children:(0,Z.jsxs)("div",{className:"w-full max-w-xl rounded-lg border border-white/15 bg-neutral-900/95 p-4 shadow-xl",onClick:S=>S.stopPropagation(),children:[(0,Z.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-2",children:[x.ok===void 0?(0,Z.jsx)(We,{className:"w-4 h-4 animate-spin text-white/60"}):x.ok?(0,Z.jsx)(na,{className:"w-4 h-4 text-emerald-400"}):(0,Z.jsx)(ct,{className:"w-4 h-4 text-amber-300"}),(0,Z.jsxs)("span",{className:"text-sm font-semibold text-white/85",children:["Build \u2014 ",x.slug]}),x.durationMs!==void 0?(0,Z.jsxs)("span",{className:"text-[10px] text-white/45",children:[x.durationMs,"ms"]}):null]}),(0,Z.jsx)("button",{className:"text-white/50 hover:text-white/80 text-xs",onClick:()=>b(null),children:"Close"})]}),(0,Z.jsx)("pre",{className:"max-h-80 overflow-y-auto rounded-md bg-black/40 border border-white/10 p-2 text-[11px] font-mono text-white/75 whitespace-pre-wrap",children:x.logs.join(`
|
|
52
|
+
`)})]})}),document.body):null]})}function yE(n){let{row:e,expanded:t,pending:r,canGovern:a,featureIds:s,onToggle:o,onFlipTrust:i,onBuild:l,onSetAccessFeature:u}=n,c=e.access?.trust??"untrusted",d=e.runtime?.type??"node",f=e.partialReason,h=f?xE[f]:void 0,p=d==="wasm"&&e.status==="partial"&&f==="build-missing",m=c==="first-party";return(0,Z.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] hover:bg-white/[0.035] transition-colors",children:[(0,Z.jsxs)("button",{type:"button",className:"w-full flex items-start gap-2 px-3 py-2 text-left",onClick:o,children:[t?(0,Z.jsx)(Tt,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}):(0,Z.jsx)(un,{className:"mt-0.5 w-3.5 h-3.5 shrink-0 text-white/50"}),(0,Z.jsx)(Lr,{className:"mt-0.5 w-4 h-4 shrink-0 text-violet-300/80"}),(0,Z.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,Z.jsxs)("div",{className:"flex items-baseline gap-1.5",children:[(0,Z.jsx)("span",{className:"min-w-0 flex-1 text-sm font-semibold text-white/90 truncate",children:e.name}),e.version?(0,Z.jsxs)("span",{className:"text-[10px] font-mono text-white/40 shrink-0",children:["v",e.version]}):null]}),e.description?(0,Z.jsx)("div",{className:"text-[10px] text-white/45 truncate",children:e.description}):null,(0,Z.jsxs)("div",{className:"flex flex-wrap items-center gap-1 pt-0.5",children:[(0,Z.jsx)(wE,{status:e.status,partialLabel:h?.label}),(0,Z.jsx)(vE,{trust:c}),(0,Z.jsx)(kE,{type:d})]})]})]}),t?(0,Z.jsxs)("div",{className:"px-3 pb-3 pt-1 border-t border-white/5 space-y-3",children:[f&&h?(0,Z.jsxs)("div",{className:"rounded-md border border-amber-500/20 bg-amber-500/5 p-2 text-[11px] text-amber-100/80 flex items-start gap-2",children:[(0,Z.jsx)(ct,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-amber-300/80"}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("div",{className:"font-semibold",children:h.label}),(0,Z.jsx)("div",{className:"text-amber-100/60",children:h.hint})]})]}):null,(0,Z.jsxs)("div",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[(0,Z.jsx)(a0,{label:"Tools",value:e.toolCount}),(0,Z.jsx)(a0,{label:"Skills / files",value:e.fileCount}),(0,Z.jsx)(a0,{label:"Commands",value:e.commandCount})]}),(0,Z.jsxs)("div",{className:"text-[10px] text-white/50 font-mono",children:[e.source?.kind?`source: ${e.source.kind}`:"",e.source?.kind&&d?" \xB7 ":"",`runtime: ${d}`]}),(0,Z.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",m?"bg-white/5 text-white/35 cursor-not-allowed":c==="trusted"?"bg-emerald-500/15 border border-emerald-500/25 text-emerald-100 hover:bg-emerald-500/20":"bg-white/5 border border-white/10 text-white/70 hover:bg-white/10"].join(" "),disabled:m||r!=="none",onClick:i,title:m?"First-party packages are trust-locked":void 0,children:[r==="trust"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):c==="trusted"?(0,Z.jsx)(si,{className:"w-3 h-3"}):(0,Z.jsx)(Ol,{className:"w-3 h-3"}),c==="trusted"?"Revert to untrusted":"Mark as trusted"]}),(0,Z.jsxs)("button",{type:"button",className:["inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] transition",p?"bg-violet-500/15 border border-violet-500/25 text-violet-100 hover:bg-violet-500/20":"bg-white/5 text-white/35 cursor-not-allowed"].join(" "),disabled:!p||r!=="none",onClick:l,title:p?"Compile src/ \u2192 dist/package.wasm on the server":d!=="wasm"?'Build is only required for runtime.type: "wasm" packages':"Build is only needed when status is partial / build-missing",children:[r==="build"?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,Z.jsx)(co,{className:"w-3 h-3"}),"Build"]}),(0,Z.jsx)(SE,{trust:c})]}),a?(0,Z.jsx)(bE,{row:e,featureIds:s,pending:r==="access-feature",disabled:r!=="none",onSetAccessFeature:u}):e.accessFeature?(0,Z.jsxs)("div",{className:"mt-2 text-[10px] text-white/45",children:["Access feature: ",(0,Z.jsx)("span",{className:"font-mono text-white/65",children:e.accessFeature}),(0,Z.jsxs)("span",{className:"text-white/30",children:[" (",e.accessFeatureSource,")"]})]}):null]}):null]})}function bE(n){let{row:e,featureIds:t,pending:r,disabled:a,onSetAccessFeature:s}=n,[o,i]=(0,Mt.useState)(e.accessFeature??""),l=`af-${e.slug}`;(0,Mt.useEffect)(()=>{i(e.accessFeature??"")},[e.accessFeature]);let u=e.accessFeatureSource==="manifest",c=o.trim(),d=e.accessFeatureSource==="override"?e.accessFeature??"":"",f=c!==d;return(0,Z.jsxs)("div",{className:"mt-2 rounded-md border border-white/10 bg-white/[0.02] px-2.5 py-2 space-y-1.5",children:[(0,Z.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] font-semibold text-white/60",children:[(0,Z.jsx)(Ns,{className:"w-3 h-3 text-cyan-300/80"}),"Base-access feature",e.accessFeature?(0,Z.jsxs)("span",{className:"ml-auto font-mono text-[9px] text-white/45",children:[e.accessFeature," ",(0,Z.jsxs)("span",{className:"text-white/30",children:["(",e.accessFeatureSource,")"]})]}):null]}),(0,Z.jsx)("div",{className:"text-[9px] text-white/40 leading-snug",children:u?"Declared in the manifest (requires.accessFeature) \u2014 not editable here. An override below adds an ADDITIONAL required feature.":"Pick a feature to hide this package from anyone who lacks it (restrict-only), then grant that feature to a role in Admin \u2192 Roles. Clear to remove."}),(0,Z.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,Z.jsx)("input",{list:l,value:o,onChange:h=>i(h.target.value),placeholder:"feature.id (e.g. labs.access)",disabled:a,className:"flex-1 min-w-0 rounded bg-black/30 border border-white/10 px-2 py-1 text-[10px] font-mono text-white/80 placeholder:text-white/25 focus:outline-none focus:border-cyan-400/40"}),(0,Z.jsx)("datalist",{id:l,children:t.map(h=>(0,Z.jsx)("option",{value:h},h))}),(0,Z.jsxs)("button",{type:"button",disabled:a||!f||c.length===0,onClick:()=>s(c),className:"inline-flex items-center gap-1 rounded-md bg-cyan-500/15 border border-cyan-400/25 px-2 py-1 text-[10px] text-cyan-100 hover:bg-cyan-500/20 transition disabled:opacity-35",children:[r?(0,Z.jsx)(We,{className:"w-3 h-3 animate-spin"}):null,"Set"]}),(0,Z.jsx)("button",{type:"button",disabled:a||e.accessFeatureSource!=="override",onClick:()=>s(null),title:e.accessFeatureSource==="manifest"?"Manifest-declared features cannot be cleared here":"Clear the override",className:"inline-flex items-center gap-1 rounded-md bg-white/5 border border-white/10 px-2 py-1 text-[10px] text-white/65 hover:bg-white/10 transition disabled:opacity-35",children:"Clear"})]})]})}function wE(n){let{status:e,partialLabel:t}=n;return e==="partial"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-500/25 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-100/85",children:[(0,Z.jsx)(ct,{className:"w-2.5 h-2.5"})," ",t??"Partial"]}):e==="error"?(0,Z.jsx)("span",{className:"inline-flex items-center gap-1 rounded-full border border-red-500/25 bg-red-500/10 px-2 py-0.5 text-[10px] text-red-100/85",children:"Error"}):e==="disabled"?(0,Z.jsx)("span",{className:"rounded-full bg-white/10 px-2 py-0.5 text-[10px] text-white/55",children:"Disabled"}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(na,{className:"w-2.5 h-2.5"})," Active"]})}function vE(n){let{trust:e}=n;return e==="first-party"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-sky-500/25 bg-sky-500/10 px-2 py-0.5 text-[10px] text-sky-100/85",children:[(0,Z.jsx)(Ns,{className:"w-2.5 h-2.5"})," First-party"]}):e==="trusted"?(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-emerald-500/25 bg-emerald-500/10 px-2 py-0.5 text-[10px] text-emerald-100/85",children:[(0,Z.jsx)(si,{className:"w-2.5 h-2.5"})," Trusted"]}):(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-white/15 bg-white/5 px-2 py-0.5 text-[10px] text-white/60",children:[(0,Z.jsx)(Ca,{className:"w-2.5 h-2.5"})," Untrusted"]})}function kE(n){let{type:e}=n;return(0,Z.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/5 px-2 py-0.5 text-[10px] font-mono text-white/55 border border-white/10",children:[(0,Z.jsx)(zl,{className:"w-2.5 h-2.5 text-violet-300/70"}),e]})}function a0(n){return(0,Z.jsxs)("div",{className:"rounded-md bg-white/[0.03] border border-white/5 px-2 py-1.5",children:[(0,Z.jsx)("div",{className:"text-white/45",children:n.label}),(0,Z.jsx)("div",{className:"text-white/85 font-mono mt-0.5",children:n.value})]})}function SE(n){let[e,t]=(0,Mt.useState)(!1);return(0,Z.jsxs)("div",{className:"relative",children:[(0,Z.jsx)("button",{type:"button",className:"inline-flex items-center rounded-md bg-white/5 p-1 text-white/40 hover:text-white/70 hover:bg-white/10",onClick:()=>t(r=>!r),children:(0,Z.jsx)(ra,{className:"w-3 h-3"})}),e?(0,Z.jsxs)("div",{className:"absolute right-0 bottom-full mb-2 w-64 rounded-lg border border-white/15 bg-neutral-900/95 p-2.5 text-[11px] text-white/75 shadow-xl z-10",children:[(0,Z.jsx)("div",{className:"font-semibold text-white/85 mb-1",children:n.trust==="trusted"?"Trusted":n.trust==="first-party"?"First-party":"Untrusted"}),(0,Z.jsx)("div",{className:"text-white/60",children:n.trust==="first-party"?"Built-in package, full access \u2014 trust is locked.":n.trust==="trusted"?"Full fs / network / cross-package API. Only flip this when you trust the author.":"Data-only filesystem, no network, no cross-package API. Safe default for unknown packages."})]}):null]})}function jo(n){let e=n.trim();if(!e)return"";let t=e.indexOf("://"),r=t>=1?e.slice(0,t+3):"",a=t>=1?e.slice(t+3):e,s=a.length>0&&a.endsWith("/"),o=[];for(let l of a.split("/"))if(!(l===""||l===".")){if(l===".."){o.pop();continue}o.push(l)}let i=o.join("/");return i?`${r}${i}${s?"/":""}`:r}var Hf=j(ta(),1);var gr=j(Ve(),1);function vI(n){let{agentId:e,projectId:t,sources:r,revisions:a,resetKey:s}=n,[o,i]=(0,gr.useState)([]),[l,u]=(0,gr.useState)(!1),c=(0,gr.useRef)(Promise.resolve()),d=(0,gr.useRef)(0),f=(0,gr.useRef)([]),h=(0,gr.useRef)({}),p=(0,gr.useRef)(!0),m=(0,gr.useCallback)(async g=>{if(!e)return;g&&(p.current=!0);let x=++d.current,b=t?{projectId:t}:{},y=c.current.then(async()=>{if(x!==d.current)return;let N=[...f.current],L=p.current;p.current=!1;let A=()=>{f.current=[...N],i([...N])};u(!0);try{for(let w of r){if(!w.git?.isRepo&&!w.git?.containsRepos)continue;let v=w.uri_root.replace("://",""),T=a[v]??0;if(!(!L&&h.current[v]===T))try{let P=await Xo({agentId:e,...b,source:v});if(x!==d.current)return;for(let O=N.length-1;O>=0;O--)N[O].source===v&&!P.repos.some(C=>C.rel===N[O].repo.rel)&&N.splice(O,1);for(let O of P.repos){let C={source:v,repo:O};try{let H=await sc({agentId:e,...b,source:v,repo:O.rel});if(x!==d.current)return;H.ok===!1?C.error="Git status unavailable":C.status=H.status}catch(H){C.error=H instanceof Error?H.message:"Git status failed"}let I=N.findIndex(H=>H.source===v&&H.repo.rel===O.rel);I<0?N.push(C):N[I]=C,A()}h.current[v]=T}catch(P){if(x!==d.current)return;let O={source:v,repo:{rel:"",name:v},error:P instanceof Error?P.message:"Repository discovery failed"},C=N.findIndex(I=>I.source===v&&I.repo.rel==="");C>=0?N[C]=O:N.push(O),h.current[v]=T,A()}}x===d.current&&A()}finally{x===d.current&&u(!1)}});c.current=y.catch(()=>{}),await y},[e,t,r,a]);return(0,gr.useEffect)(()=>{d.current++,f.current=[],h.current={},p.current=!0,i([])},[s]),(0,gr.useEffect)(()=>(m(!1),()=>{d.current++}),[m]),{groups:o,loading:l,refresh:m}}var fe=j(Ve(),1);var jI=j(wr(),1);var Tf=j(Ve(),1);var kI=j(Ve(),1),Ku=j(le(),1),CE={add:"bg-emerald-500/12",remove:"bg-red-500/18",context:""},SI=(0,kI.memo)(function({lineNo:e,type:t,content:r}){return(0,Ku.jsxs)("div",{className:`flex h-[18px] w-full ${CE[t]}`,children:[(0,Ku.jsx)("span",{className:"shrink-0 w-10 text-right pr-2 select-none text-white/25 tabular-nums",children:e??""}),(0,Ku.jsx)("span",{className:"shrink-0 whitespace-pre pr-3 text-white/78",children:r||" "})]})});var ds=j(le(),1),Ji=(0,Tf.memo)(function({hunks:e,isStreaming:t,maxLines:r=200}){let{elements:a,truncated:s}=(0,Tf.useMemo)(()=>{let o=[],i=0,l=0,u=!1,c=1,d=1;for(let f of e){if(f.skippedBefore!==0){let h=f.skippedBefore>0?`\xB7\xB7\xB7 ${f.skippedBefore} lines skipped \xB7\xB7\xB7`:"\xB7\xB7\xB7 \xB7\xB7\xB7 \xB7\xB7\xB7";o.push((0,ds.jsx)(LE,{label:h},`skip-${i}`)),f.skippedBefore>0&&(c+=f.skippedBefore,d+=f.skippedBefore)}for(let h of f.lines){if(l>=r){u=!0;break}let p=t?"add":h.type,m=p==="remove"?c:d;p==="remove"?c++:(p==="add"||c++,d++),o.push((0,ds.jsx)(SI,{lineNo:m,type:p,content:h.content},`line-${i}`)),i++,l++}if(u)break}return{elements:o,truncated:u}},[e,t,r]);return a.length===0?(0,ds.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"No content"}):(0,ds.jsx)("div",{className:"font-mono text-[11px] leading-[18px] overflow-x-auto overflow-y-clip",children:(0,ds.jsxs)("div",{className:"min-w-full w-max",children:[a,s&&(0,ds.jsxs)("div",{className:"w-full text-[10px] text-white/40 bg-white/4 px-3 py-1 text-center",children:["\xB7\xB7\xB7 ",e.reduce((o,i)=>o+i.lines.length,0)-r," more lines \xB7\xB7\xB7"]})]})})},(n,e)=>{if(n.isStreaming!==e.isStreaming||n.maxLines!==e.maxLines||n.language!==e.language)return!1;if(n.hunks===e.hunks)return!0;if(n.hunks.length!==e.hunks.length)return!1;for(let t=0;t<n.hunks.length;t++){let r=n.hunks[t],a=e.hunks[t];if(r===a)continue;if(r.skippedBefore!==a.skippedBefore||r.lines.length!==a.lines.length)return!1;let s=r.lines[0],o=a.lines[0];if(s?.type!==o?.type||s?.content!==o?.content)return!1;let i=r.lines[r.lines.length-1],l=a.lines[a.lines.length-1];if(i?.type!==l?.type||i?.content!==l?.content)return!1}return!0});function LE({label:n}){return(0,ds.jsx)("div",{className:"w-full text-[10px] text-white/35 bg-white/[0.03] px-3 py-0.5 text-center border-y border-white/6 select-none",children:n})}var Ff=j(ta(),1);function CI(n){return n.snapshotHash?null:"originalDraftUnknown"}function o0(n,e){return n.op!=="delete"&&n.op!=="create"&&!n.baselineMissing&&e.current.state==="missing"&&e.baselineProvenance==="journal-latest-write"&&(e.baseline.state==="text"||e.baseline.state==="binary"||e.baseline.state==="too-large")}function i0(n){return String(n||"").replace(/\r\n/g,`
|
|
53
53
|
`).split(`
|
|
54
|
-
`)}function
|
|
55
|
-
`):[]}function Qi(n){return xE((0,Pf.parseSettledObject)(n))}function Nf(n,e){let t=n0(n),r=n0(e),a=t.length,s=r.length,o=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)o[c][d]=t[c]===r[d]?o[c+1][d+1]+1:Math.max(o[c+1][d],o[c][d+1]);let i=[],l=0,u=0;for(;l<a&&u<s;)t[l]===r[u]?(i.push({type:"context",content:t[l]}),l++,u++):o[l+1][u]>=o[l][u+1]?(i.push({type:"remove",content:t[l]}),l++):(i.push({type:"add",content:r[u]}),u++);for(;l<a;)i.push({type:"remove",content:t[l++]});for(;u<s;)i.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:i}]}function Rf(n){let e=0,t=0;for(let r of n)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&t++;return{added:e,removed:t}}function $u(n){for(let e of["content","file_content","text"]){let t=n[e];if(typeof t=="string")return t}if(typeof n.content=="object"&&n.content!==null)try{return JSON.stringify(n.content,null,2)}catch{}return null}function a0(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n;if(e.ok===!1)return null;let t=e.version;if(!t||typeof t!="object"||Array.isArray(t))return null;let r=t.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,o=typeof a.removed=="number"?a.removed:null;return s==null||o==null?null:{added:s,removed:o}}function gE(n){let e=(0,Pf.extractPathsFromToolCall)(n);if(e.length===0){let r=Qi(n.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let t=a0(n.structuredContent);return e.map((r,a)=>a===0&&t?{path:r,diff:t}:{path:r})}var SI={tab:"changes",changes:gE},CI=["fs_write","fs_create","fs_modify"];function xE(n){if(!n||typeof n.action=="string"||!bE(n))return n;let e={};if(typeof n.uri=="string"&&(e.uri=n.uri),typeof n.id=="string"&&(e.id=n.id),typeof n.move=="string")return{...e,action:"move",destination:n.move};if(typeof n.copy=="string")return{...e,action:"copy",destination:n.copy};if(n.mkdir!==void 0)return{...e,action:"create_folder"};if(n.revert!==void 0)return{...e,action:"revert"};if(n.delete!==void 0)return{...e,action:"delete"};let t=Array.isArray(n.edit)?n.edit.filter(i=>!!i&&typeof i=="object").map(i=>({find:typeof i.old_string=="string"?i.old_string:"",replace:typeof i.new_string=="string"?i.new_string:""})).filter(i=>i.find.length>0):[];if(t.length>0)return{...e,action:"replace_text",edits:t};let r=Af(n.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Af(n.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Af(n.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let o=Af(n.create);return o&&o.content!==void 0?{...e,content:o.content}:n.fields!==void 0?{...e,action:"set_fields",fields:n.fields}:n}var yE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function bE(n){return yE.some(e=>n[e]!==void 0)}function Af(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function II(n){let e=new Map;for(let t of n)if(t.status)for(let[r,a]of[[!0,t.status.staged],[!1,[...t.status.unstaged,...t.status.untracked]]])for(let s of a){let o=`${t.source}://${[t.repo.rel,s.path].filter(Boolean).join("/")}`,i=e.get(o)??new Map,l=JSON.stringify([t.source,t.repo.rel,s.path]),u=i.get(l);u?(u.staged||=r,u.unstaged||=!r):i.set(l,{group:t,path:s.path,staged:r,unstaged:!r}),e.set(o,i)}return e}function Xu(n){return`${n.source}://${n.repo.rel}`}function s0(n){let e=Ts(n.source,n.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function AI(n,e){return e.kind==="pending"?[]:n.filter(t=>(!e.source||t.source===e.source)&&(!e.repo||Xu(t)===e.repo)&&(!e.branch||t.status?.branch===e.branch))}function PI(n,e,t){return t.kind==="git"?[]:n.filter(r=>!(t.source&&r.sourceSlug!==t.source||t.agent&&r.agentId!==t.agent||t.origin&&r.origin!==t.origin||(t.repo||t.branch)&&!e.some(s=>r.sourceSlug===s.source&&Wo(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!t.repo||Xu(s)===t.repo)&&(!t.branch||s.status?.branch===t.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function NI(n,e,t,r){let a=new Set(n.map(o=>Wo(o.uri))),s=[];for(let o of e.keys())(t==="git"||!a.has(o))&&s.push({kind:"git",key:`git:${o}`,uri:o});return n.forEach((o,i)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:o.id,rec:o,index:i})),s}var wE=32,vE=346;function RI(n){return n==="pending-row"?wE:vE}function MI(n){return n!=="pending-row"}function TI(n,e,t=100){let r=[],a=[];for(let s of n)e.has(s.id)||(yI(s)?a.push(s):r.length<t&&r.push(s));return{approvable:r,needsAck:a}}function o0(n){let e=n instanceof Error?n.message:String(n??"");return e.includes("PENDING_STATE_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var LI=new WeakMap;function Mf(n){if(n.diffState!=="readable")return null;let e=LI.get(n);return e||(e=Nf(n.baseline.state==="text"?n.baseline.text:"",n.current.state==="text"?n.current.text:""),LI.set(n,e)),e}var Yr=W($e(),1),EI=W(Ya(),1);var mt=W(le(),1),DI={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},FI={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 reopen it",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function Tf(n,e,t,r,a){let s={agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},id:e.id,expectedFingerprint:t.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let o=r==="approve"?await ac({...s,uri:e.uri}):r==="revert"?await nx(s):await ax(s);if(o&&o.ok===!1){let i="error"in o&&o.error?String(o.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:o0(i),detail:i}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(o){return{id:e.id,uri:e.uri,action:r,outcome:o0(o),detail:o instanceof Error?o.message:"Review refused"}}}function kE({rec:n,preview:e}){let t=(0,Yr.useMemo)(()=>Mf(e),[e]);return t?(0,mt.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,mt.jsx)(Yi,{hunks:t,language:Ji(n.uri),maxLines:400})}):(0,mt.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var Yu="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function BI({request:n,agentId:e,projectId:t,run:r,onClose:a,onDone:s,next:o=0,onNext:i}){let l=(0,Yr.useMemo)(()=>n.kind==="single"?[n.rec]:n.records,[n]),[u,c]=(0,Yr.useState)(()=>n.kind==="single"&&n.preview?{[n.rec.id]:n.preview}:{}),[d,f]=(0,Yr.useState)(!1),[h,p]=(0,Yr.useState)({});(0,Yr.useEffect)(()=>{let C=!0;for(let k of l)u[k.id]||r(()=>il({agentId:e,...t?{projectId:t}:{},id:k.id}),()=>C).then(v=>{C&&v&&c(b=>({...b,[k.id]:v}))},v=>{C&&c(b=>({...b,[k.id]:v instanceof Error?v:new Error("Preview failed")}))});return()=>{C=!1}},[l,e,t,r]);let m=(0,Yr.useMemo)(()=>{let C=new Map;for(let k of l){let v=u[k.id];if(!v||v instanceof Error)continue;let b=v.requiresAcknowledgement[0]??"fresh";C.set(b,[...C.get(b)??[],k])}return C},[l,u]),g=l.filter(C=>!u[C.id]).length,x=n.kind==="group"&&g===0&&!d&&l.every(C=>h[C.id]||u[C.id]instanceof Error),w=(0,Yr.useCallback)(async(C,k)=>{f(!0);let v=[];for(let b of C){let P=u[b.id];if(!P||P instanceof Error||h[b.id]?.outcome==="ok")continue;let N=await Tf({agentId:e,projectId:t},b,P,k,P.requiresAcknowledgement.length>0);v.push(N),p(M=>({...M,[b.id]:N}))}f(!1),s(v)},[u,h,e,t,s]);if(typeof document>"u")return null;let y=n.kind==="single"?n:null;return(0,EI.createPortal)((0,mt.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:d?void 0:a,children:(0,mt.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:C=>C.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,mt.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,mt.jsx)(va,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,mt.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,mt.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:y?`Review the current state \u2014 ${y.action}`:n.kind==="group"&&n.total>l.length?`${l.length} of ${n.total} changes need your confirmation`:`${l.length} changes need your confirmation`}),(0,mt.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),g>0?(0,mt.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,mt.jsx)(ze,{className:"h-3 w-3 animate-spin"})," Loading ",g," preview",g>1?"s":"","\u2026"]}):null]})]}),(0,mt.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...m].map(([C,k])=>(0,mt.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,mt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,mt.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${DI[C].chip}`,children:[DI[C].label," \xB7 ",k.length]}),y?null:(0,mt.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,mt.jsxs)("button",{type:"button",disabled:d||k.every(v=>h[v.id]),onClick:()=>{w(k,"dismiss")},className:`${Yu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,mt.jsx)(na,{className:"h-3 w-3"})," Confirm & dismiss ",k.length]}),(0,mt.jsxs)("button",{type:"button",disabled:d||k.every(v=>h[v.id]),onClick:()=>{w(k,"approve")},className:`${Yu} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,mt.jsx)(ps,{className:"h-3 w-3"})," Confirm & approve ",k.length]})]})]}),k.map(v=>{let b=u[v.id],P=h[v.id];return(0,mt.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,mt.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,mt.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:v.uri,children:v.uri}),P?(0,mt.jsx)("span",{className:FI[P.outcome].tone,title:P.detail,children:FI[P.outcome].label}):null]}),(0,mt.jsx)(kE,{rec:v,preview:b})]},v.id)})]},C)),l.filter(C=>u[C.id]instanceof Error).map(C=>(0,mt.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[C.uri,": ",u[C.id].message]},C.id))]}),(0,mt.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,mt.jsxs)("button",{type:"button",onClick:a,disabled:d,className:`${Yu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,mt.jsx)(Ut,{className:"h-3 w-3"})," ",Object.keys(h).length?"Close":"Cancel"]}),x&&i&&o>0?(0,mt.jsxs)("button",{type:"button",onClick:()=>i(l.map(C=>C.id)),className:`${Yu} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,mt.jsx)(va,{className:"h-3 w-3"})," Next batch (",o," left)"]}):null,y?["revert","dismiss","approve"].map(C=>{let k=C===y.action,v=C==="approve"?Dn:C==="revert"?ka:na,b=C==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":k?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,mt.jsxs)("button",{type:"button",disabled:d||g>0||h[y.rec.id]?.outcome==="ok",onClick:()=>{w([y.rec],C)},className:`${Yu} ${b}`,children:[(0,mt.jsx)(v,{className:"h-3 w-3"})," ",k?`Confirm & ${C}`:C[0].toUpperCase()+C.slice(1)]},C)}):null]})]})}),document.body)}var X=W(le(),1),HI={create:(0,X.jsx)(vs,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,X.jsx)(bs,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,X.jsx)(It,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,X.jsx)(Nl,{className:"w-3.5 h-3.5 text-violet-300/80"})},UI=n=>n==="approved"?"bg-emerald-400":n==="reverted"?"bg-white/30":"bg-amber-400";function GI({diff:n}){return!n||n.added===0&&n.removed===0?null:(0,X.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[n.added>0?(0,X.jsxs)("span",{className:"text-emerald-300",children:["+",n.added]}):null,n.added>0&&n.removed>0?" ":null,n.removed>0?(0,X.jsxs)("span",{className:"text-red-300",children:["\u2212",n.removed]}):null]})}var zI=(0,X.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,X.jsx)(Ul,{className:"w-3 h-3"})," Orphaned"]});function WI({orphaned:n,busy:e,onApprove:t,onRevert:r,onDiscard:a,onDismiss:s,className:o}){let i=(0,X.jsx)(Ff.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,X.jsx)("div",{className:o,children:n?(0,X.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?i:(0,X.jsx)(It,{className:"w-3.5 h-3.5"})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("button",{type:"button",onClick:t,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?i:(0,X.jsx)(Dn,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,X.jsx)(ka,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,X.jsx)(na,{className:"w-3.5 h-3.5"})})]})})}function OI({uri:n,rows:e,agentId:t,projectId:r,canWrite:a,revisions:s,queue:o}){let i=e.get(Wo(n));return i?(0,X.jsx)(X.Fragment,{children:[...i.values()].map(l=>(0,X.jsx)(ve.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,X.jsxs)("div",{children:[(0,X.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,X.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,X.jsx)(bo,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:t,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:o.run,peekContent:o.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var SE=n=>2*((n.baseline.state==="text"?n.baseline.text.length:0)+(n.current.state==="text"?n.current.text.length:0))+256,CE=(0,ve.memo)(function({rec:e,agentId:t,projectId:r,focused:a,orphaned:s,onOpen:o,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:m,onPreview:g,peekPreview:x,extra:w}){let[y,C]=(0,ve.useState)(!0),[k,v]=(0,ve.useState)(()=>x(e.id)??null),[b,P]=(0,ve.useState)(!1),[N,M]=(0,ve.useState)(null),[U,I]=(0,ve.useState)(""),A=(0,ve.useRef)(0),G=h.visible.has(e.id),V=(0,ve.useRef)(!1);V.current=y&&G;let K=`preview\0${e.id}\0${e.updatedAt}\0${p}`,L=(0,ve.useRef)("");(0,ve.useEffect)(()=>{let ee=++A.current;if(!y||!G||L.current===K){P(!1);return}return P(!0),h.run(()=>il({agentId:t,...r?{projectId:r}:{},id:e.id}),()=>ee===A.current&&V.current,{key:K,bytes:SE}).then(ce=>{!ce||ee!==A.current||!V.current||(g(ce),v(ce),M(null),I(K),L.current=K,P(!1))}).catch(ce=>{ee===A.current&&(M(ce instanceof Error?ce.message:"Failed to load review"),P(!1))}),()=>{A.current++}},[t,r,e.id,K,y,G,h.run]);let R=(0,ve.useMemo)(()=>k?Mf(k):null,[k]),z=(0,ve.useMemo)(()=>R?Rf(R):null,[R]),J=U===K?k?.indexState??null:null,Q=N??(k&&k.diffState!=="readable"?`Review diff unavailable: ${k.diffState}; current ${k.current.state}, baseline ${k.baseline.state}.`:null),re=(0,ve.useCallback)(()=>C(ee=>!ee),[]),pe=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:z??void 0;return(0,X.jsxs)("div",{ref:ee=>h.register(e.id,ee),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,X.jsx)("button",{type:"button",onClick:re,"aria-expanded":y,className:"text-white/40 hover:text-white/80 shrink-0",children:y?(0,X.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,X.jsx)(un,{className:"w-3.5 h-3.5"})}),HI[e.op],(0,X.jsxs)("button",{type:"button",onClick:()=>o(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[yt(e.uri)||e.uri,(0,X.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ot(e.uri),"/"]})]}),(0,X.jsx)(GI,{diff:pe}),J&&J!=="stored"?(0,X.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:J==="missing"?"Index missing":J==="stale"?"Index stale":"Recovery only"}):null,s?zI:e.status==="approved"||e.status==="reverted"?(0,X.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${UI(e.status)}`,title:e.status}):null,m?(0,X.jsx)(WI,{orphaned:s,busy:f,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),y?(0,X.jsxs)("div",{className:"border-t border-white/5",children:[(0,X.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",b&&k?(0,X.jsx)(Ff.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,X.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:b&&!k?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,X.jsx)(Ff.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):Q?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,X.jsx)(dt,{className:"w-3.5 h-3.5"})," ",Q]}):R?(0,X.jsx)(Yi,{hunks:R,language:Ji(e.uri),maxLines:600}):null})]}):null,y?w:null]})}),el="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",tl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},LE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},Df=100;function jI({agentId:n,projectId:e}){let t=hn(),r=Xa({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),a=B(j=>j.sources),s=B(j=>j.sourceChangeRevision),o=B(j=>j.pendingPanelFilter),i=B(j=>j.setPendingPanelFilter),l=B(j=>j.openFile),u=B(j=>j.removeFilePath),c=B(j=>j.setActiveWorkspaceTab),d=B(j=>j.refreshPendingCount),f=o.conversationId??"",[h,p]=(0,ve.useState)(null),m=Sc(h),g=(0,ve.useRef)(new Map),x=(0,ve.useCallback)(j=>g.current.get(j),[]),[w,y]=(0,ve.useState)(LE),C=j=>ie=>y(Ue=>({...Ue,[j]:ie.target.value})),[k,v]=(0,ve.useState)("cards"),[b,P]=(0,ve.useState)([]),[N,M]=(0,ve.useState)(new Set),[U,I]=(0,ve.useState)(!1),[A,G]=(0,ve.useState)(null),[V,K]=(0,ve.useState)(null),[L,R]=(0,ve.useState)(0),[z,J]=(0,ve.useState)(0),[Q,re]=(0,ve.useState)(null),[pe,ee]=(0,ve.useState)([]),[ce,ue]=(0,ve.useState)(!1),[He,De]=(0,ve.useState)(!1),[je,et]=(0,ve.useState)(!1),[Dt,at]=(0,ve.useState)(!1),[vt,Pt]=(0,ve.useState)(new Set),Ye=(0,ve.useRef)(null),Ne=(0,ve.useRef)(0),tt=mI({agentId:n,projectId:e,sources:a,revisions:s,resetKey:`${n}\0${e}\0${f}`}),Je=(0,ve.useCallback)(async j=>{if(!n)return;let ie=++Ne.current;I(!0),G(null);try{let Ue=await ex({agentId:n,...e?{projectId:e}:{},...f?{conversationId:f}:{},...j?{include_orphans:!0}:{}});if(ie!==Ne.current)return;let Bt=new Set(Ue.changes.map(Xt=>Xt.id));return P(Ue.changes),M(Xt=>j?new Set(Ue.orphanIds):new Set([...Xt].filter(dn=>Bt.has(dn)))),Ue.changes}catch(Ue){ie===Ne.current&&G(Ue instanceof Error?Ue.message:"Failed to load changes");return}finally{ie===Ne.current&&I(!1)}},[n,e,f]),Ft=(0,ve.useCallback)(async()=>{await Promise.all([Je(!0),tt.refresh(!0)]),d({agentId:n,projectId:e})},[Je,tt.refresh,d,n,e]);(0,ve.useEffect)(()=>(g.current.clear(),re(null),P([]),M(new Set),ee([]),Je(!0),()=>{Ne.current++,g.current.clear()}),[Je]);let Mt=(0,ve.useRef)(Je);Mt.current=Je;let Te=(0,ve.useRef)(!0);(0,ve.useEffect)(()=>{if(Te.current){Te.current=!1;return}Mt.current(!1)},[s]);let oe=tt.groups,jt=(0,ve.useMemo)(()=>Array.from(new Set([...b.map(j=>j.sourceSlug),...oe.map(j=>j.source)])).sort(),[b,oe]),Kt=(0,ve.useMemo)(()=>Array.from(new Set(b.map(j=>j.agentId).filter(Boolean))).sort(),[b]),de=(0,ve.useMemo)(()=>Array.from(new Set(b.map(j=>j.origin).filter(Boolean))).sort(),[b]),fe=(0,ve.useMemo)(()=>PI(b,oe,w),[b,oe,w]),qe=(0,ve.useMemo)(()=>AI(oe,w),[oe,w]),Re=(0,ve.useMemo)(()=>II(qe),[qe]),Fe=(0,ve.useMemo)(()=>NI(fe,Re,w.kind,k),[fe,Re,w.kind,k]),{approvable:Lt,needsAck:st}=(0,ve.useMemo)(()=>TI(fe,N,Df),[fe,N]),Le=(0,ve.useRef)(new Set),Ee=st.filter(j=>!Le.current.has(j.id)),Et=(0,ve.useCallback)(j=>{for(let Ue of j)Le.current.add(Ue);let ie=st.filter(Ue=>!Le.current.has(Ue.id));re({kind:"group",records:ie.slice(0,Df),total:ie.length})},[st]),qt=(0,ve.useRef)(Fe);qt.current=Fe;let Tn=(0,ve.useCallback)(j=>RI(qt.current[j]?.kind??"pending-card"),[]),te=(0,ve.useCallback)(j=>qt.current[j]?.key??j,[]),Ce=ii({count:Fe.length,getScrollElement:()=>h,estimateSize:Tn,getItemKey:te,overscan:4});Ce.shouldAdjustScrollPositionOnItemSizeChange=IE,(0,ve.useEffect)(()=>{J(j=>fe.length===0?0:Math.min(j,fe.length-1))},[fe.length]);let Ge=Fe.length-fe.length;(0,ve.useEffect)(()=>{fe.length>0&&Ce.scrollToIndex(Ge+z,{align:"auto"})},[z,k]);let Ke=(0,ve.useCallback)(j=>{l({agentId:n,projectId:e,uri:j}),c("file")},[n,e,l,c]),Ae=(0,ve.useCallback)(j=>{if(j.op!=="delete"||!j.uri)return;let ie=B.getState().files[j.uri];(!ie||ie.status==="deleted")&&u(j.uri)},[u]),he=(0,ve.useCallback)(async j=>{for(let ie of j){let Ue=b.find(Bt=>Bt.id===ie.id);Ue&&ie.outcome==="ok"&&ie.action!=="revert"&&Ae(Ue),ie.outcome!=="ok"&&g.current.delete(ie.id)}j.some(ie=>ie.outcome!=="ok")&&R(ie=>ie+1),ee(j),await Je(!1),d({agentId:n,projectId:e})},[b,Ae,Je,d,n,e]),ut=(0,ve.useCallback)(async(j,ie)=>{if(!r)return;let Ue=g.current.get(j.id);if(!Ue||Ue.requiresAcknowledgement.length){re({kind:"single",rec:j,action:ie,...Ue?{preview:Ue}:{}});return}K(j.id);try{await he([await Tf({agentId:n,projectId:e},j,Ue,ie,!1)])}finally{K(null)}},[r,n,e,he]),Qt=(0,ve.useCallback)(async j=>{K(j.id);try{let ie=await rx({agentId:n,...e?{projectId:e}:{},id:j.id});ie.ok?Ae(j):G(ie.error||"Discard failed"),await Je(!1),d({agentId:n,projectId:e})}catch(ie){G(ie instanceof Error?ie.message:"Discard failed")}finally{K(null)}},[n,e,Je,Ae,d]),xn=(0,ve.useCallback)(async()=>{Ye.current&&(clearTimeout(Ye.current),Ye.current=null),at(!0),et(!1),G(null);try{await sx({agentId:n,...e?{projectId:e}:{},...f?{conversationId:f}:{}});let j=b.filter(Ue=>N.has(Ue.id)),ie=await Je(!0);if(ie){let Ue=new Set(ie.map(Bt=>Bt.id));for(let Bt of j)Ue.has(Bt.id)||Ae(Bt)}d({agentId:n,projectId:e})}catch(j){G(j instanceof Error?j.message:"Repair failed")}finally{at(!1)}},[n,e,f,Je,b,N,Ae,d]),yn=(0,ve.useCallback)(()=>{if(je){xn();return}et(!0),Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>et(!1),3e3)},[je,xn]);(0,ve.useEffect)(()=>()=>{Ye.current&&clearTimeout(Ye.current)},[]);let Nr=(0,ve.useCallback)(async()=>{ue(!0),De(!1),G(null);let j=[];try{for(let ie of Lt){let Ue=g.current.get(ie.id);if(!Ue)try{Ue=await il({agentId:n,...e?{projectId:e}:{},id:ie.id})}catch(Bt){j.push({id:ie.id,uri:ie.uri,action:"approve",outcome:"error",detail:Bt instanceof Error?Bt.message:"Preview failed"});continue}if(Ue.requiresAcknowledgement.length){j.push({id:ie.id,uri:ie.uri,action:"approve",outcome:"needs-ack"});continue}j.push(await Tf({agentId:n,projectId:e},ie,Ue,"approve",!1))}}finally{ue(!1),await he(j)}},[Lt,n,e,he]),Kn=(0,ve.useCallback)(j=>J(ie=>fe.length===0?0:Math.max(0,Math.min(fe.length-1,ie+j))),[fe.length]),Xn=(0,ve.useCallback)(j=>{if(V||ce||!r||Q)return;let ie=fe[z],Ue=ie?N.has(ie.id):!1;j.key==="ArrowDown"||j.key==="ArrowRight"?(j.preventDefault(),Kn(1)):j.key==="ArrowUp"||j.key==="ArrowLeft"?(j.preventDefault(),Kn(-1)):Ue&&ie&&(j.key==="d"||j.key==="r"||j.key==="Enter")?(j.preventDefault(),Qt(ie)):(j.key==="a"||j.key==="Enter")&&ie?(j.preventDefault(),ut(ie,"approve")):j.key==="r"&&ie?(j.preventDefault(),ut(ie,"revert")):j.key==="x"&&!Ue&&ie&&(j.preventDefault(),ut(ie,"dismiss"))},[V,ce,r,Q,fe,z,N,Kn,Qt,ut]),Rr=j=>{if(j.kind==="git"){let dn=!vt.has(j.uri);return(0,X.jsxs)("div",{ref:Sn=>m.register(j.uri,Sn),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,X.jsx)("button",{type:"button","aria-expanded":dn,className:"px-3 py-2 text-xs text-white/85",onClick:()=>Pt(Sn=>{let hr=new Set(Sn);return hr.has(j.uri)?hr.delete(j.uri):hr.add(j.uri),hr}),children:j.uri}),dn?(0,X.jsx)(OI,{uri:j.uri,rows:Re,agentId:n,projectId:e,canWrite:r,revisions:s,queue:m}):null]})}let{rec:ie,index:Ue}=j,Bt=N.has(ie.id),Xt={onApprove:()=>{ut(ie,"approve")},onRevert:()=>{ut(ie,"revert")},onDiscard:()=>{Qt(ie)},onDismiss:()=>{ut(ie,"dismiss")}};return j.kind==="pending-card"?(0,X.jsx)(CE,{rec:ie,agentId:n,projectId:e,focused:Ue===z,orphaned:Bt,onOpen:Ke,...Xt,onFocus:()=>J(Ue),busy:V===ie.id,queue:m,revision:L+(s[ie.sourceSlug]??0),canWrite:r,onPreview:dn=>{g.current.set(ie.id,dn)},peekPreview:x,extra:w.kind==="all"?(0,X.jsx)(OI,{uri:ie.uri,rows:Re,agentId:n,projectId:e,canWrite:r,revisions:s,queue:m}):null}):(0,X.jsxs)("div",{onMouseDown:()=>J(Ue),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${Ue===z?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[HI[ie.op],(0,X.jsxs)("button",{type:"button",onClick:()=>Ke(ie.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:ie.uri,children:[yt(ie.uri)||ie.uri,(0,X.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[ot(ie.uri),"/"]})]}),(0,X.jsx)(GI,{diff:ie.diff}),Bt?zI:(0,X.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${UI(ie.status)}`,title:ie.status}),r?(0,X.jsx)(WI,{orphaned:Bt,busy:V===ie.id,...Xt,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},Yn=pe.filter(j=>j.outcome!=="ok"),Mr=U||tt.loading;return(0,X.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:Xn,children:[r&&Q?(0,X.jsx)(BI,{request:Q,agentId:n,projectId:e,run:m.run,onClose:()=>re(null),next:Q.kind==="group"?Ee.filter(j=>!Q.records.some(ie=>ie.id===j.id)).length:0,onNext:Et,onDone:j=>{for(let ie of j)Le.current.add(ie.id);he(j)}},Q.kind==="group"?`group\0${Q.records[0]?.id??""}`:`single\0${Q.rec.id}`):null,(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,X.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,X.jsx)("span",{className:"text-[10px] text-white/35",children:fe.length>0?`${Math.min(z+1,fe.length)}/${fe.length}`:"0"}),(0,X.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,X.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,X.jsx)("button",{type:"button",onClick:()=>Kn(-1),disabled:fe.length===0||z===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,X.jsx)(gl,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:()=>Kn(1),disabled:fe.length===0||z>=fe.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,X.jsx)(un,{className:"w-3.5 h-3.5"})})]}),r?He?(0,X.jsxs)("button",{type:"button",onClick:()=>{Nr()},disabled:ce||Lt.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${Lt.length} visible change(s) that need no confirmation`,children:[ce?(0,X.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,X.jsx)(ps,{className:"w-3 h-3"})," Approve ",Lt.length,"?"]}):(0,X.jsxs)("button",{type:"button",onClick:()=>De(!0),disabled:Lt.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,X.jsx)(ps,{className:"w-3 h-3"})," Approve ",Lt.length]}):null,r&&st.length>0?(0,X.jsxs)("button",{type:"button",onClick:()=>{Le.current.clear(),re({kind:"group",records:st.slice(0,Df),total:st.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${Df} at a time)`,children:[(0,X.jsx)(va,{className:"w-3 h-3"})," ",st.length," need confirmation"]}):null,(0,X.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,X.jsx)("button",{type:"button",onClick:()=>v("list"),title:"Compact list",className:`p-1.5 ${k==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,X.jsx)(to,{className:"w-3.5 h-3.5"})}),(0,X.jsx)("button",{type:"button",onClick:()=>v("cards"),title:"Diff cards",className:`p-1.5 ${k==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,X.jsx)(Va,{className:"w-3.5 h-3.5"})})]}),r&&N.size>0?(0,X.jsxs)("button",{type:"button",onClick:yn,disabled:Dt,className:je?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:je?`Discard all ${N.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[Dt?(0,X.jsx)(ze,{className:"w-3 h-3 animate-spin"}):je?(0,X.jsx)(It,{className:"w-3 h-3"}):(0,X.jsx)(uo,{className:"w-3 h-3"}),je?`Discard ${N.size}?`:`Repair ${N.size}`]}):null,(0,X.jsx)("button",{type:"button",onClick:()=>{Ft()},disabled:Mr,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,X.jsx)(Ht,{className:`w-3.5 h-3.5 ${Mr?"animate-spin":""}`})}),(0,X.jsx)(_I.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/pending.sh","scripts/approve.sh"],label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),(0,X.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[f?(0,X.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:f,children:["conversation ",(0,X.jsx)("button",{type:"button",onClick:()=>i({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,X.jsx)(Ut,{className:"w-3 h-3"})})]}):null,(0,X.jsxs)("select",{"aria-label":"Change type",value:w.kind,onChange:C("kind"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"all",children:"All changes"}),(0,X.jsx)("option",{value:"pending",children:"Pending review"}),(0,X.jsx)("option",{value:"git",children:"Git"})]}),(0,X.jsxs)("select",{"aria-label":"Source",value:w.source,onChange:C("source"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All sources"}),jt.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}),(0,X.jsxs)("select",{"aria-label":"Repository",value:w.repo,onChange:C("repo"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All repositories"}),oe.map(j=>(0,X.jsx)("option",{value:Xu(j),children:s0(j)},Xu(j)))]}),(0,X.jsxs)("select",{"aria-label":"Checked-out branch",value:w.branch,onChange:C("branch"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(oe.map(j=>j.status?.branch).filter(Boolean))].map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}),Kt.length>1?(0,X.jsxs)("select",{"aria-label":"Agent",value:w.agent,onChange:C("agent"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All agents"}),Kt.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}):null,de.length>1?(0,X.jsxs)("select",{"aria-label":"Origin",value:w.origin,onChange:C("origin"),className:el,style:tl,children:[(0,X.jsx)("option",{value:"",children:"All origins"}),de.map(j=>(0,X.jsx)("option",{value:j,children:j},j))]}):null]}),qe.filter(j=>j.error).map(j=>(0,X.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[s0(j),": ",j.error]},`${j.source}/${j.repo.rel}`)),A?(0,X.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,X.jsx)(dt,{className:"w-3.5 h-3.5"})," ",A]}):null,Yn.length?(0,X.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,X.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[pe.length-Yn.length," done \xB7 ",Yn.length," not done",(0,X.jsx)("button",{type:"button",onClick:()=>ee([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,X.jsx)(Ut,{className:"w-3 h-3"})})]}),Yn.map(j=>(0,X.jsxs)("div",{className:"truncate font-mono",title:j.detail,children:[j.action," ",j.uri,": ",j.outcome==="changed"?"changed since the preview (409)":j.outcome==="needs-ack"?"needs confirmation":j.detail??"refused"]},j.id))]}):null,(0,X.jsx)("div",{ref:p,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:Mr&&Fe.length===0?(0,X.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,X.jsx)(ze,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):Fe.length===0?(0,X.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,X.jsx)("div",{style:{height:Ce.getTotalSize(),width:"100%",position:"relative"},children:Ce.getVirtualItems().map(j=>{let ie=Fe[j.index];return ie?(0,X.jsx)("div",{"data-index":j.index,ref:MI(ie.kind)?Ce.measureElement:void 0,className:ie.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${j.start}px)`},children:Rr(ie)},j.key):null})})})]})}var IE=(n,e,t)=>n.end<=(t.scrollOffset??0);var $=W(le(),1),AE=2e5,PE=2500,NE=12e3;function qI(n,e){let t=String(n||"").trim().replace(/\\/g,"/");if(!t)return e;if(t.includes("://")){let s=t.indexOf("://"),o=t.slice(0,s),i=t.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${o}://${i}`}let r=rr(e),a=t.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function i0(){let n=B(O=>O.openFiles),e=B(O=>O.activeFile),t=B(O=>O.files),r=B(O=>O.fileContentByPath),a=B(O=>O.fileBaseContentByPath),s=B(O=>O.fileErrorByPath),o=B(O=>O.openFile),i=B(O=>O.patchFileNode),l=B(O=>O.saveFileInPlace),u=B(O=>O.markFileDeleted),c=B(O=>O.clearFilePrev),d=B(O=>O.refresh),f=B(O=>O.activeProjectId),h=B(O=>O.workspacePanels),p=B(O=>O.setWorkspacePanelOpen),m=B(O=>O.activeWorkspaceTab),g=B(O=>O.setActiveWorkspaceTab),x=B(O=>O.gitDiffTarget),w=B(O=>O.setGitDiffTarget),y=B(O=>O.gitCommitTarget),C=B(O=>O.setGitCommitTarget),k=B(O=>O.diffViewMode),v=B(O=>O.activeAgentId),b=hn(),P=b.useAgents(),N=(0,bt.useMemo)(()=>Ns(P),[P]),M=v?N.byId.get(v)??null:null,U=b.MarkdownRenderer,I=e?t[e]:null,A=e?r[e]??"":"",G=I?.uri??"",V=I?RE(G):!1,K=I?ME(G):!1,L=I?TE(G):!1,R=I?DE(G):!1,z=I?EE(G):!1,J=I?Zc(G):void 0,Q=I?FE(G):"Binary file",re=V,[pe,ee]=(0,bt.useState)(!1),[ce,ue]=(0,bt.useState)(""),[He,De]=(0,bt.useState)(""),[je,et]=(0,bt.useState)(!1),[Dt,at]=(0,bt.useState)(null),[vt,Pt]=(0,bt.useState)(!1),[Ye,Ne]=(0,bt.useState)(!1),[tt,Je]=(0,bt.useState)(!1),[Ft,Mt]=(0,bt.useState)(!1),[Te,oe]=(0,bt.useState)(!0),[jt,Kt]=(0,bt.useState)(!1),de=B(O=>O.filePrevByPath),fe=e?de[e]:void 0,qe=!!fe&&I?.status==="pending_review",Re=!!fe,Fe=(0,bt.useMemo)(()=>I?I.sourceAgentId?N.byId.get(I.sourceAgentId)??null:M:null,[I,N,M]),Lt=e?s[e]:void 0,st=!!e&&!oc({fileBaseContentByPath:a,fileErrorByPath:s},e),Le=Lt?`Read failed: ${Lt}`:st?"Loading\u2026":"Empty file",Ee=I?.status==="deleted",Et=h.upload&&m==="upload",qt=h.sources&&m==="sources",Tn=h.packages&&m==="packages",te=h.pending&&m==="pending",Ce=m==="git-diff"&&!!x,Ge=m==="git-commit"&&!!y,Ke=!Et&&!qt&&!Tn&&!te&&!Ce&&!Ge,Ae=I?.sourceAgentId??v??void 0,he=I?.sourceAgentId??v??null,ut=(0,bt.useMemo)(()=>!I?.uri||!Ae?null:ox(Ae,I.uri,f??void 0),[I?.uri,Ae,f]),Qt=(0,bt.useRef)(null),xn=(0,bt.useRef)(null),yn=ed(xn),Nr=k==="auto"?yn?"split":"unified":k,[Kn,Xn]=(0,bt.useState)(void 0),Rr=I?.git;(0,bt.useEffect)(()=>{let O=!1;if(!he||!G||!Rr||K||L||R){Xn(void 0);return}let Pe=Ve(G),D=G.indexOf("://"),me=D>=0?G.slice(D+3):"";if(!Pe||!me){Xn(void 0);return}return(async()=>{try{let Yt=await ec({agentId:he,...f?{projectId:f}:{},source:Pe,path:me,staged:!1});if(O)return;if(Yt&&Yt.ok===!1){Xn(void 0);return}let Ot=typeof Yt?.diff=="string"?Yt.diff:"",Cn=T1(Ot);Xn(sd(Cn)?void 0:Cn)}catch{O||Xn(void 0)}})(),()=>{O=!0}},[he,f,G,Rr,K,L,R]);let Yn=fo(I?.version?.changedAt),Mr=I?.version?.sync,j=!0,ie=!!I&&pe&&(He!==A||qI(ce,I.uri)!==I.uri),Ue=I?.version?.diff,Bt=!!Ue&&(Ue.added>0||Ue.removed>0),Xt=!!I&&vp(I),dn=(0,bt.useMemo)(()=>{if(!I)return"/";if(I.parentUri&&I.parentUri!==I.uri)return I.parentUri;let O=ot(I.uri);return O===I.uri?rr(I.uri):O},[I]),Sn=(0,bt.useMemo)(()=>BE(A),[A]),hr=I?.readSource==="live",Ua=!!I&&!pe&&!K&&!L&&(z||Sn.charCount>=AE||Sn.lineCount>=PE||hr&&Sn.charCount>=NE),Jr=(0,bt.useCallback)(async()=>{if(!(!he||!I||vt)){Pt(!0),at(null);try{await u({agentId:he,projectId:f??null,node:I})}catch(O){console.error("[Filesystem] delete failed",O),at(O instanceof Error?O.message:"Delete failed")}finally{Pt(!1)}}},[he,I,vt,f,u]),Ys=(0,bt.useCallback)(async()=>{if(!(!he||!I||Ye)){Ne(!0);try{let O=await yr({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri,fields:{status:"active"}});if(O&&O.ok===!1){at(ma(O,"Restore failed"));return}d({agentId:he,projectId:f??null}),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}catch(O){console.error("[Filesystem] restore failed",O)}finally{Ne(!1)}}},[he,I,Ye,f,d,o,Fe?.id]),Hn=(0,bt.useCallback)(async()=>{if(!(!he||!I||tt)){if(I.status==="pending_review"){p("pending",!0),g("pending");return}Je(!0);try{let O=await ac({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri});if(O&&O.ok){let Pe=I.storeKey||e||Wa(I);Pe&&(i(Pe,{status:"active"}),c(Pe)),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}}catch(O){console.error("[Filesystem] approve failed",O)}finally{Je(!1)}}},[he,I,tt,f,o,Fe?.id,e,i,c]),rn=(0,bt.useCallback)(async()=>{if(!(!he||!I||Ft)){if(I.status==="pending_review"){p("pending",!0),g("pending");return}Mt(!0);try{let O=await yr({agentId:he,...f?{projectId:f}:{},id:I.id,uri:I.uri,revert:!0});if(O&&O.ok===!1){at(ma(O,"Revert failed"));return}if(O&&O.ok){let Pe=I.storeKey||e||Wa(I);Pe&&(i(Pe,{status:fe?.status||"active"}),c(Pe)),o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})}}catch(O){console.error("[Filesystem] revert failed",O)}finally{Mt(!1)}}},[he,I,Ft,f,o,Fe?.id,e,fe,i,c]);(0,bt.useEffect)(()=>{if(!I){Qt.current=null,ee(!1),Kt(!1),ue(""),De(""),at(null);return}let O=I.storeKey||e||Wa(I),Pe=Qt.current!==O;if(Qt.current=O,Pe){ee(!1),Kt(!1),oe(!0),ue(I.uri),De(A),at(null);return}pe||(ue(I.uri),De(A),at(null))},[I?.storeKey,I?.uri,A,e,pe]);let Jn=(0,bt.useCallback)(()=>{Xt&&Kt(O=>!O)},[Xt]),pr=(0,bt.useCallback)(()=>{!I||Ee||(ue(I.uri),De(A),at(null),ee(!0))},[I,A,Ee]),E=(0,bt.useCallback)(()=>{I&&(ue(I.uri),De(A),at(null),ee(!1))},[I,A]),ne=(0,bt.useCallback)(async()=>{if(!I||!he||je)return;let O=I.uri,Pe=qI(ce,O);if(!Pe){at("Invalid target URI");return}et(!0),at(null);try{await l({agentId:he,projectId:f??null,readAgentId:Fe?.id,node:I,targetUri:Pe,content:He,currentContent:A}),oe(!0),ee(!1)}catch(D){at(D instanceof Error?D.message:"Save failed")}finally{et(!1)}},[I,he,je,ce,He,A,f,Fe?.id,l]);return(0,$.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[n.length>0||h.upload||j&&h.sources||h.packages||h.pending||x||y?(0,$.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,$.jsxs)("div",{[od]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,$.jsx)(E1,{}),h.upload?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Et?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("upload"),children:[(0,$.jsx)(Sa,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Upload"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("upload",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,j&&h.sources?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",qt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("sources"),children:[(0,$.jsx)(lo,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Sources"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("sources",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,h.packages?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Tn?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("packages"),children:[(0,$.jsx)(vr,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Packages"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("packages",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,h.pending?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",te?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("pending"),children:[(0,$.jsx)(Va,{className:"w-3.5 h-3.5 shrink-0"}),(0,$.jsx)("span",{className:"truncate flex-1",children:"Changes"}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),p("pending",!1)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,x?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ce?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-diff"),title:`Diff: ${xo(x.repo,x.path)} (${Zv(x)})`,children:[(0,$.jsx)(ar,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:xo(x.repo,yt(x.path)||x.path)}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),w(null),Ce&&g("file")},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null,y?(0,$.jsxs)("button",{type:"button",className:q("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ge?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-commit"),title:y.kind==="commit"?xo(y.repo,`Commit ${tn(y.sha)}: ${y.subject}`):xo(y.repo,`Outgoing changes (${tn(y.base)}..${tn(y.head)})`),children:[y.kind==="commit"?(0,$.jsx)(Or,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,$.jsx)(Er,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,$.jsx)("span",{className:"truncate flex-1",children:y.kind==="commit"?xo(y.repo,`${tn(y.sha)} ${y.subject}`):xo(y.repo,"Outgoing changes")}),(0,$.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:O=>{O.stopPropagation(),C(null)},children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):null]}),(0,$.jsx)(B1,{})]}):null,Ke&&I?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!jt||!Xt?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,$.jsxs)("div",{className:q("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",Xt?"cursor-pointer hover:bg-white/[0.04]":""),role:Xt?"button":void 0,tabIndex:Xt?0:void 0,"aria-expanded":Xt?jt:void 0,onClick:Jn,onKeyDown:O=>{Xt&&(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),Jn())},children:[Bt?(0,$.jsxs)("span",{className:q("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",Yn.pillClassName),children:[(0,$.jsx)(ar,{className:q("w-3 h-3",Yn.iconClassName)}),(0,$.jsxs)("span",{className:"text-emerald-200/95",children:["+",Ue.added]}),(0,$.jsx)("span",{className:"text-white/25",children:"/"}),(0,$.jsxs)("span",{className:"text-rose-200/95",children:["-",Ue.removed]})]}):null,(0,$.jsxs)("div",{className:"min-w-0 flex-1",children:[pe?(0,$.jsx)("input",{value:ce,onChange:O=>ue(O.target.value),onClick:O=>O.stopPropagation(),onKeyDown:O=>O.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:je}):(0,$.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${Ve(I.uri)} \xB7 ${I.uri}`,children:[(0,$.jsx)("span",{className:q("shrink-0 text-white/88 font-medium",I.status==="deleted"?"line-through text-red-200/70":""),children:I.name}),(0,$.jsx)("span",{className:"truncate font-mono text-white/42",children:dn})]}),Lt?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Lt,children:"Read failed"}):null,Dt?(0,$.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Dt,children:Dt}):null]}),Xt?(0,$.jsx)(Tt,{className:q("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",jt&&"rotate-180")}):null]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[pe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:ne,disabled:je||!he,"aria-label":"Save changes",children:je?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Dn,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:E,disabled:je,"aria-label":"Cancel edit",children:(0,$.jsx)(Ut,{className:"w-3 h-3"})})]}):(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:pr,disabled:!he||Ee||R,title:R?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,$.jsx)(ao,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:q("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:Jr,disabled:!he||vt||Ye,title:"Mark as deleted","aria-label":"Mark as deleted",children:vt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(It,{className:"w-3 h-3"})}),(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!he||!I||o({agentId:he,projectId:f??null,uri:I.uri,readAgentId:Fe?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,$.jsx)(Ht,{className:"w-3 h-3"})}),!pe&&Re&&I?.status!=="pending_review"?(0,$.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:rn,disabled:Ft||tt||!he,title:"Undo to previous version","aria-label":"Undo to previous version",children:Ft?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(ka,{className:"w-3 h-3"})}):null]})]}):null,Ke&&I&&jt&&Xt?(0,$.jsx)(wp,{node:I,hideVersionDiff:!0}):null,Ke&&I&&ie?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,$.jsx)($a,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,$.jsx)("span",{children:"Local draft in progress"})]}),(0,$.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,Ke&&I&&qe&&!pe?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,$.jsx)(ar,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,$.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:q("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Te?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>oe(!Te),children:[(0,$.jsx)(ar,{className:"w-3 h-3"}),"Diff"]}),Te?(0,$.jsx)(nd,{}):null,(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:Hn,disabled:tt||Ft||!he,title:"Accept current state",children:[tt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(Dn,{className:"w-3 h-3"}),"Approve"]}),(0,$.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:rn,disabled:tt||Ft||!he,title:"Revert to previous version",children:[Ft?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin"}):(0,$.jsx)(ka,{className:"w-3 h-3"}),"Revert"]})]})]}):null,Ke&&I&&!pe&&I.presence==="stale_indexed"?(0,$.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,$.jsx)(Ka,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,$.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,$.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,Ke&&I&&!pe&&I.presence==="unindexed"?(0,$.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,$.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,$.jsx)(dt,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,$.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,$.jsxs)("div",{ref:xn,className:"flex-1 min-h-0 relative",children:[Et&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(zg,{agentId:v,projectId:f??null})}):null,j&&qt&&v?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(oI,{agentId:v,projectId:f??null,isDocker:b.isDocker})}):null,Tn&&f?(0,$.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,$.jsx)(pI,{projectId:f})}):null,te&&v?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(jI,{agentId:v,projectId:f??null})}):null,Ce&&x?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(Ug,{target:x,agentId:v,projectId:f??null})}):null,Ge&&y?(0,$.jsx)("div",{className:"w-full h-full min-h-0",children:(0,$.jsx)(lp,{target:y,agentId:v,projectId:f??null})}):null,Ke&&Ee?(0,$.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,$.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,$.jsxs)("div",{className:"flex items-center gap-2",children:[(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Ys,disabled:!he||Ye||vt,children:[Ye?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,$.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Jr,disabled:!he||vt||Ye,children:[vt?(0,$.jsx)(ze,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,Ke&&I?qe&&Te&&fe&&!pe?(0,$.jsx)(Rg,{oldContent:fe.content,newContent:A,language:J,viewMode:Nr,className:"w-full h-full min-h-0"}):R&&!K&&!L&&!pe?(0,$.jsx)("div",{className:q("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",Ee&&"blur-[2px] opacity-65"),children:(0,$.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,$.jsx)(dt,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,$.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[Q," preview disabled"]}),(0,$.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):K&&ut&&!pe?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:q(Ee&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,$.jsx)("img",{src:ut,alt:I.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):L&&ut&&!pe?(0,$.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,$.jsxs)("div",{className:q(Ee&&"blur-[2px] opacity-65"),children:[(0,$.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,$.jsx)("video",{src:ut,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):V&&U&&!Ua&&!pe?(0,$.jsx)("div",{className:q("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",Ee&&"blur-[2px] opacity-65"),children:A?(0,$.jsx)("div",{className:"min-h-full min-w-0",children:(0,$.jsx)(U,{content:A})}):(0,$.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:Le})}):(0,$.jsx)(Hg,{value:pe?He:A,language:J,readOnly:!pe||Ee||je,wrap:re,onChange:pe?De:void 0,className:q("w-full h-full min-h-0",Ee&&"opacity-65"),placeholder:Le,ariaLabel:pe?"File content editor":"File content viewer",gitLineStatus:Kn}):Ke?(0,$.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,$.jsx)(vl,{className:"w-12 h-12 mb-2 opacity-50"}),(0,$.jsx)("div",{className:"text-sm",children:Et?"Upload files using this tab":"No file open"})]}):null,Ke&&I?(0,$.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,$.jsxs)("span",{children:[Sn.lineCount.toLocaleString()," lines"]}),(0,$.jsxs)("span",{className:"ml-3",children:[Sn.charCount.toLocaleString()," chars"]})]}):null]})]})}function RE(n){let e=yt(n).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function ME(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function TE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function DE(n){let e=yt(String(n||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function FE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function EE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function BE(n){if(!n)return{charCount:0,lineCount:0};let e=1;for(let t=0;t<n.length;t++)n.charCodeAt(t)===10&&(e+=1);return{charCount:n.length,lineCount:e}}var ls="brain://project-info",b$=[{kind:"docs",label:"Upload Docs",folderUri:`${ls}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${ls}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${ls}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${ls}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${ls}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${ls}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${ls}/misc`}];var cn=W($e(),1);var VI=250,OE=1e3,_E=2e3,HE=6e3,UE=1e3,GE=5e3,zE=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],WE=new Set(zE),jE=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function qE(n){return n.mode==="purge"?!1:jE.every(e=>n[e]===0)}function $I(n,e){let t=B(A=>A.refreshTree),r=B(A=>A.refresh),a=B(A=>A.ensureFolderLoaded),s=B(A=>A.reconcileSourceFolders),o=B(A=>A.reconcileFolders),i=B(A=>A.setSourceDirty),l=B(A=>A.upsertFileNodeFromEvent),u=B(A=>A.incrementFolderBadges),c=B(A=>A.replaceFilePath),d=B(A=>A.clearFilePrev),f=B(A=>A.autoExpandToFile),h=B(A=>A.loadGitStatus),p=B(A=>A.notifyGitLogChanged),m=B(A=>A.refreshPendingCount),g=(0,cn.useRef)(0),x=(0,cn.useRef)(new Map),w=(0,cn.useRef)(new Map),y=(0,cn.useRef)(new Map);(0,cn.useEffect)(()=>{let A=x.current,G=y.current;return()=>{for(let V of A.values())clearTimeout(V);A.clear();for(let V of G.values())clearTimeout(V);G.clear()}},[n,e]),(0,cn.useEffect)(()=>{let A=w.current;return()=>{g.current+=1;for(let G of A.values())clearTimeout(G.timer);A.clear()}},[n,e]);let C=(0,cn.useRef)(null),k=(0,cn.useCallback)(()=>{if(!n||!e)return;let A=Date.now(),G=C.current,V=G?G.deadline:A+GE;G&&clearTimeout(G.timer);let K=setTimeout(()=>{C.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:n,projectId:e})},Math.max(0,Math.min(UE,V-A)));C.current={timer:K,deadline:V}},[n,e,m]),v=(0,cn.useRef)(k);v.current=k;let b=B(A=>A.activeAgentId===n&&A.activeProjectId===e);(0,cn.useEffect)(()=>{n&&e&&b&&m({agentId:n,projectId:e})},[n,e,b,m]),(0,cn.useEffect)(()=>{if(!n||!e)return;let A=()=>{document.visibilityState!=="hidden"&&v.current()},G=()=>v.current();return document.addEventListener("visibilitychange",A),window.addEventListener("focus",G),()=>{document.removeEventListener("visibilitychange",A),window.removeEventListener("focus",G),C.current&&clearTimeout(C.current.timer),C.current=null}},[n,e,m]);let P=(0,cn.useCallback)(A=>{let{type:G,payload:V}=A,K=ee=>{if(!n||!ee)return;let ce=B.getState().activeSource,ue=typeof ce=="string"&&ce?ce.includes("://")?Ve(ce):ce:"",He=y.current,De=He.get(ee);De&&clearTimeout(De),He.set(ee,setTimeout(()=>{He.delete(ee),B.setState(je=>({sourceChangeRevision:{...je.sourceChangeRevision,[ee]:(je.sourceChangeRevision[ee]??0)+1}})),ue===ee&&h({agentId:n,projectId:e,source:ee})},VI))},L=ee=>{if(!n)return;let ce=w.current,ue=Date.now(),He=ce.get(ee),De=He?He.deadline:ue+HE;He&&clearTimeout(He.timer);let je=setTimeout(()=>{ce.delete(ee),s({agentId:n,projectId:e,source:ee})},Math.max(0,Math.min(_E,De-ue)));ce.set(ee,{timer:je,deadline:De})};if(G==="sync:completed"){if(!n)return;let ee=typeof V.source=="string"?V.source:void 0;if(ee&&qE(V)){K(ee);return}ee?(B.getState().loadedFolders?.[`${ee}://`]?L(ee):i(ee,!0),K(ee)):t({agentId:n,projectId:e});return}if(V.changeType==="badge"){if(!n)return;let ee=B.getState().activeAgentId;if(ee&&ee!==n)return;let ce=typeof V.source=="string"&&V.source?V.source:Ve(typeof V.uri=="string"?V.uri:"");if(!ce)return;let ue=x.current,He=ue.get(ce);He&&clearTimeout(He),ue.set(ce,setTimeout(()=>{ue.delete(ce),B.setState(et=>({sourceChangeRevision:{...et.sourceChangeRevision,[ce]:(et.sourceChangeRevision[ce]??0)+1}})),a({agentId:n,projectId:e,uri:`${ce}://`,force:!0}),r({agentId:n,projectId:e});let De=B.getState().activeSource;(typeof De=="string"&&De?De.includes("://")?Ve(De):De:"")===ce&&h({agentId:n,projectId:e,source:ce}),p(ce)},VI));return}if(V.external===!0){if(!n)return;let ee=B.getState().activeAgentId;if(ee&&ee!==n)return;let ce=typeof V.source=="string"&&V.source?V.source:Ve(typeof V.uri=="string"?V.uri:"");if(!ce)return;if(K(ce),!B.getState().loadedFolders?.[`${ce}://`]){i(ce,!0);return}L(ce);return}let R=V.uri;if(!R)return;let z=V.changeType,J=Array.isArray(V.folder_ancestors)&&V.folder_ancestors.length>0?V.folder_ancestors:ga(R);J.length>0&&u(J),Array.isArray(V.new_folder_ancestors)&&V.new_folder_ancestors.length>0&&u(V.new_folder_ancestors);let Q=typeof V.action=="string"?V.action:void 0,re={id:V.id,uri:R,folder_ancestors:J,sourceAgentId:A.agentId,sourceProjectId:A.projectId},pe=ee=>{if(!n)return;let ce=Array.from(new Set(ee.filter(ue=>typeof ue=="string"&&!!ue).map(ue=>ot(ue))));ce.length>0&&o({agentId:n,projectId:e,folders:ce})};switch(G){case"filesystem:created":case"filesystem:updated":l({...re,status:V.status}),V.status==="pending_review"&&f(R),V.newUri&&(c(R,V.newUri),l({...re,uri:V.newUri,folder_ancestors:V.new_folder_ancestors,status:V.status})),Q==="review_approved"&&V.status==="active"&&d(R),z==="structure"&&pe([R,V.newUri]);break;case"filesystem:deleted":l({...re,status:"deleted"}),z==="structure"&&pe([R]);break;case"filesystem:reverted":l({...re,status:V.status||"active"}),d(R),pe([R]);break}K(Ve(R))},[n,e,t,r,a,s,o,i,l,u,c,d,f,h,p]),N=(0,cn.useRef)(P);N.current=P;let M=(0,cn.useRef)(null),U=(0,cn.useCallback)(()=>{if(!n)return;let A=g.current;M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{M.current=null,A===g.current&&(async()=>{try{await r({agentId:n,projectId:e})}catch{return}if(A!==g.current)return;v.current();let G=B.getState();B.setState(K=>({sourceChangeRevision:Object.fromEntries(K.sources.map(L=>[Ve(L.uri_root),(K.sourceChangeRevision[Ve(L.uri_root)]??0)+1]))}));let V=new Set;for(let[K,L]of Object.entries(G.loadedFolders||{})){if(!L)continue;let R=Ve(K);R&&V.add(R)}await Promise.all(Array.from(V).map(K=>s({agentId:n,projectId:e,source:K})))})()},OE)},[n,e,r,s]),I=(0,cn.useRef)(U);I.current=U,(0,cn.useEffect)(()=>{let A=M;return()=>{A.current&&clearTimeout(A.current)}},[n,e]),(0,cn.useEffect)(()=>{if(!n||!e)return;let A=Zb();if(A?.subscribeFilesystemEvents)return A.subscribeFilesystemEvents(n,e,G=>{let V=G;if(!V||typeof V!="object"||!WE.has(V.type)||!V.payload||typeof V.payload!="object")return;if(V.type==="pending:changed"){v.current();return}let K=V.payload.changeType==="badge",L=V.payload.external===!0;!K&&!L&&V.agentId!==n||N.current(V)},()=>I.current())},[n,e])}var Ef=W(mr(),1);var kn=W(le(),1);function l0(n){let e=B(R=>R.sidebarOpen),t=B(R=>R.sidebarWidth),r=B(R=>R.setSidebarWidth),a=B(R=>R.loadList),s=B(R=>R.refreshTree),o=B(R=>R.applyNav),i=B(R=>R.searchQuery),l=B(R=>R.setSearchQuery),u=B(R=>R.clearSearch),c=B(R=>R.sidebarView),d=B(R=>R.setSidebarView),f=(0,Mn.useRef)(null),h=(0,Mn.useRef)(null),p=(0,Mn.useRef)(null),[m,g]=(0,Mn.useState)(!1),x=hn(),w=(0,Ef.useWorkspaceHostPort)(),y=B(R=>R.activeProjectId),C=n.projectId??y,k=x.useFileMarks(n.agentId),v=x.useAgents(),b=(0,Mn.useMemo)(()=>Ns(v),[v]),P=n.agentId?b.byId.get(n.agentId):null,N=P?.name||P?.slug,M=P?.config?.appearance?.icon,U=ui(P?.id,b),I=(0,Mn.useMemo)(()=>{let R=k||{},z=0;for(let J of Object.keys(R)){let Q=R[J]?.ts??0;Q>z&&(z=Q)}return z},[k]);$I(n.agentId,C),(0,Mn.useEffect)(()=>{n.agentId&&a({agentId:n.agentId,projectId:C,userId:n.userId??null})},[n.agentId,C,n.userId]),(0,Mn.useEffect)(()=>{if(!n.agentId)return;let R=n.state?.nav;if(!R)return;let z=JSON.stringify(R);f.current!==z&&(f.current=z,w&&n.widgetId&&(0,Ef.consumeWidgetNav)(w,{agentId:n.agentId,widgetId:n.widgetId}),o({agentId:n.agentId,projectId:C,nav:R,readAgentId:n.agentId}))},[o,n.agentId,C,n.state,w,n.widgetId]);let A=(0,Mn.useRef)(!1);(0,Mn.useEffect)(()=>{if(!n.agentId||!I||A.current)return;let R=setTimeout(()=>{A.current=!0,s({agentId:n.agentId,projectId:C}).finally(()=>{A.current=!1})},1500);return()=>clearTimeout(R)},[I,C,n.agentId,s]);let G=8,V=(0,Mn.useCallback)(R=>{R.preventDefault(),p.current={startX:R.clientX,startWidth:t},g(!0),R.currentTarget.setPointerCapture(R.pointerId)},[t]),K=(0,Mn.useCallback)(R=>{let z=p.current;if(!z)return;let J=h.current,Q=J?Math.max(ul,J.clientWidth-G):z.startWidth,re=Math.min(Q,Math.max(ul,z.startWidth+(R.clientX-z.startX)));r(re)},[r]),L=(0,Mn.useCallback)(R=>{p.current&&(p.current=null,g(!1),R.currentTarget.releasePointerCapture(R.pointerId))},[]);return(0,kn.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,kn.jsx)(gh,{agentId:n.agentId,agentName:N,agentIcon:M,agentAccent:U,supportsSources:!0,onOpenProjectFiles:()=>{o({agentId:n.agentId,projectId:C,nav:{kind:"filesystem",action:"list",uri:ls}})}}),(0,kn.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${m?"select-none cursor-col-resize":""}`,children:[(0,kn.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?t:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,kn.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,kn.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,kn.jsx)("input",{type:"text",value:i,onChange:R=>l(R.target.value),onKeyDown:R=>{R.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,kn.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,kn.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,kn.jsx)(Fl,{className:"w-3.5 h-3.5"})}),(0,kn.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,kn.jsx)(Ln,{className:"w-3.5 h-3.5"})})]})]}),(0,kn.jsx)(mp,{agentId:n.agentId,sidebarView:c})]}),e&&(0,kn.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:V,onPointerMove:K,onPointerUp:L,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,kn.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,kn.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,kn.jsx)(i0,{})})]})]})}var $n=W($e(),1),_f=W(Qr(),1),al=W(Qr(),1),s2=W(YI(),1);var jo=W($e(),1);var Bf=W(Qr(),1);var Oa=W(le(),1),VE=27,d0=90,$E=17,KE=12,XE=1.4,YE=18,c0=32,JI=new WeakMap;function ZI(n,e){let t=JI.get(n);if(t&&t.status===e)return t;let r={status:e};return JI.set(n,r),r}function JE(n,e){let t=ZI(n,e);if(t.compact!==void 0)return t.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=c0;else{let o=Qi(n.input),i=o&&typeof o.action=="string"?o.action:void 0;if(i&&!Zi(i))s=c0;else if(Zi(i))s=d0;else{let l=0;try{let u=o?Ku(o):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?c0:Math.min(d0,l*YE)}}return t.compact=s,s}function ZE(n,e){let t=ZI(n,e);if(t.expanded!==void 0)return t.expanded;let r=Qi(n.input)??{},a=0;try{let o=Ku(r);a=o?o.added+o.removed:0}catch{a=0}let s=Math.max(d0,KE+Math.ceil(a*XE)*$E);return t.expanded=s,s}function QI(n){let e=n.disclosure===!0?ZE(n.tool,n.status):JE(n.tool,n.status);return VE+e}var Of=(0,jo.memo)(function({uri:e,lineCounts:t,isPending:r,reviewPending:a,isError:s,isInterrupted:o,onUriClick:i,children:l}){let u=(0,jo.useMemo)(()=>r?"pending":o?"interrupted":s?"error":"committed",[r,s,o]),c=a&&u==="committed"?"pending review":u,d=(0,jo.useCallback)(()=>{e&&i&&i(e)},[e,i]),f=(0,jo.useCallback)(()=>(0,Oa.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&i?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&i?"button":void 0,title:e||void 0,children:[(0,Oa.jsx)(ba,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Oa.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),t&&(0,Oa.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[t.added>0&&(0,Oa.jsxs)("span",{className:"text-emerald-400",children:["+",t.added]}),t.removed>0&&(0,Oa.jsxs)("span",{className:"text-red-400",children:["-",t.removed]})]}),(0,Oa.jsx)(Bf.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:o,statusLabel:c})]}),[e,i,d,t,r,s,o,c]);return(0,Oa.jsx)(Bf.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var t2=W($e(),1);var rt=W(le(),1),n2=(0,t2.memo)(function({action:e,input:t}){switch(e){case"set_fields":return(0,rt.jsx)(QE,{fields:t.fields});case"move":return(0,rt.jsx)(eB,{uri:nl(t,"uri")||nl(t,"id"),destination:nl(t,"destination")});case"copy":return(0,rt.jsx)(tB,{uri:nl(t,"uri"),destination:nl(t,"destination")});case"create_folder":return(0,rt.jsx)(nB,{uri:nl(t,"uri")});case"delete":return(0,rt.jsx)(rB,{});case"revert":return(0,rt.jsx)(aB,{});default:return(0,rt.jsx)(sB,{action:e,input:t})}});function QE({fields:n}){if(!n||typeof n!="object")return(0,rt.jsx)(e2,{icon:(0,rt.jsx)(ri,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[t,r]of Object.entries(n))if(r!==void 0)if(t==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(o=>`+${o}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(o=>`-${o}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(t==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,o])=>o===null?`${s}: (removed)`:`${s}: ${String(o)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:t,value:r===null?"(cleared)":String(r)});return(0,rt.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(t=>(0,rt.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,rt.jsxs)("span",{className:"text-white/45 shrink-0",children:[t.key,":"]}),(0,rt.jsx)("span",{className:"text-white/75 break-all",children:t.value})]},t.key)),e.length===0&&(0,rt.jsx)(e2,{icon:(0,rt.jsx)(ri,{className:"w-3 h-3"}),text:"Updated fields"})]})}function eB({uri:n,destination:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,rt.jsx)(ti,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function tB({uri:n,destination:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)(ra,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,rt.jsx)(ti,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function nB({uri:n}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,rt.jsx)(wr,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,rt.jsx)("span",{className:"text-white/75 truncate",children:n||"?"})]})}function rB(){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,rt.jsx)(It,{className:"w-3 h-3 text-rose-400/70"}),(0,rt.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function aB(){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,rt.jsx)(oo,{className:"w-3 h-3 text-amber-400/70"}),(0,rt.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function sB({action:n,input:e}){let t=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,rt.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,rt.jsx)("span",{className:"text-white/45 mr-1",children:n}),t&&(0,rt.jsx)("span",{className:"text-white/50",children:t})]})}function e2({icon:n,text:e}){return(0,rt.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[n,(0,rt.jsx)("span",{children:e})]})}function nl(n,e){let t=n[e];return typeof t=="string"?t:void 0}var _a=W(le(),1),oB=200,rl=new Map;function r2(n,e){if(rl.size>=oB){let t=rl.keys().next().value;t!==void 0&&rl.delete(t)}rl.set(n,e)}var iB=8,lB=200,o2=(0,$n.memo)(function({tool:e,status:t,conversationId:r}){let a=(0,al.useChatHost)(),s=(0,s2.useWorkspaceChatStore)(A=>r?A.conversationsById?.[r]?.agentId:void 0),o=(0,al.useHasRowIdentity)(),i=(0,al.useRowDisclosureValue)("card"),u=o&&i!==!0?iB:lB,c=(0,$n.useMemo)(()=>Qi(e.input),[e.input]),d=(0,$n.useMemo)(()=>(0,_f.extractPathsFromToolCall)(e)[0]||(c?a2(c,"uri")||a2(c,"path"):void 0),[e,c]),f=String(t||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",m=!p&&(f==="error"||f.includes("error")||f.includes("fail")),g=c?.action,x=d?Ji(d):void 0,w=(0,$n.useMemo)(()=>a0(e.structuredContent),[e.structuredContent]),y=(0,$n.useMemo)(()=>{let A=e.structuredContent,G=A&&typeof A=="object"?String(A.status||"").toLowerCase():"";return G==="pending_review"||G.includes("pending")},[e.structuredContent]),C=(0,$n.useMemo)(()=>w??(c&&!h?Ku(c):null),[w,c,h]),k=(0,$n.useMemo)(()=>c?h?[]:uB(g,c):[],[g,c,h]),v=(0,$n.useCallback)(A=>{let G=s||void 0;!G||!A||a.openFilesystemWidget?.(G,A)},[s,a]),b=(0,$n.useMemo)(()=>{if(h)return(0,_f.previewInput)(e.input,!0)},[h,e.input]),P=!h&&!m&&!!g&&Zi(g),[N,M]=(0,$n.useState)(()=>P&&d&&s?rl.get(`${s}|${e.id}`)??null:null);(0,$n.useEffect)(()=>{if(!P||!d||!s){M(null);return}let A=`${s}|${e.id}`,G=rl.get(A);if(G!==void 0){M(G);return}let V=!1,K=()=>{V||(async()=>{try{let J=await Ko({agentId:s,files:[d]});if(V)return;let Q=Yo(J)[0],re=sc(Q?.version?.baseline);if(!re?.content){r2(A,null);return}let pe=Nf(re.content,Jo(Q));r2(A,pe),V||M(pe)}catch{}})()},L=globalThis,R=null,z=null;return typeof L.requestIdleCallback=="function"?R=L.requestIdleCallback(K,{timeout:1500}):z=setTimeout(K,200),()=>{V=!0,R!==null&&L.cancelIdleCallback?.(R),z!==null&&clearTimeout(z)}},[P,d,s,e.id]);let U=N??k,I=N?Rf(N):C;return h?(0,_a.jsx)(Of,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?v:void 0,children:(0,_a.jsx)(cB,{content:b})}):g&&!Zi(g)?(0,_a.jsx)(Of,{uri:d,lineCounts:null,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?v:void 0,children:(0,_a.jsx)(n2,{action:g,input:c||{}})}):(0,_a.jsx)(Of,{uri:d,lineCounts:I,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?v:void 0,children:U.length>0?(0,_a.jsx)(Yi,{hunks:U,language:x,maxLines:u}):(0,_a.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:m?"Operation failed":"Done"})})});function uB(n,e){if(!n){let t=$u(e);return t?r0(t):[]}if(n==="replace_text"){let t=e.edits;if(Array.isArray(t)&&t.length>0)return wI(t.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return bI(r,a)}if(n==="update"||n==="replace_lines"){let t=$u(e);return t?vI(t):[]}if(n==="append_text"||n==="prepend_text"||n==="insert"){let t=typeof e.text=="string"?e.text:"";return t?kI(t):[]}return[]}function cB({content:n}){return n?(0,_a.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:n}):(0,_a.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function a2(n,e){let t=n[e];return typeof t=="string"?t:void 0}var Ha=W($e(),1);function i2({port:n}){let e=n.useCurrentUser(),t=e?.name,r=e?.email,a=e?.role,s=e?.priority,o=(0,Ha.useMemo)(()=>t||r?{name:t,email:r}:void 0,[t,r]),i=(0,Ha.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=n.useProjectId(),u=n.useUserId(),c=n.getGrantedFeatures(l,u).join(","),d=(0,Ha.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,Ha.useMemo)(()=>({currentUser:o,currentRole:i,grantedFeatures:d,useAgents(){let f=n.useAgentIds(),h=n.useAgentsById();return(0,Ha.useMemo)(()=>{let p={};for(let m of f){let g=h[m];g&&(p[m]={id:g.id,slug:g.slug,name:g.name,config:g.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>n.useFileMarks(f),clearFileMark:f=>n.clearFileMark(f),getStreamUrl(f,h,p){return n.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,m){return n.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(g,x)=>p(x),...m?{onConnChange:m}:{}})},isDocker:n.isDocker,usePackageIconBySlug(){let f=n.useProjectId(),[h,p]=(0,Ha.useState)({});return(0,Ha.useEffect)(()=>{if(!f)return;let m=!1,g=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(g,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(m||!x?.packages)return;let w={};for(let y of x.packages){if(!y.id)continue;let C=(0,sr.resolveLucideIcon)(y.icon);if(!C)continue;let k=y.id.replace(/^@[^/]+\//,"");w[k]=C,w[y.id]=C}p(w)}).catch(()=>{}),()=>{m=!0}},[f]),h}}),[n,o,i,d])}var u2=W(le(),1);function l2({port:n,children:e}){let t=i2({port:n});return(0,u2.jsx)(Qb,{value:t,children:e})}var Xs=W(le(),1),dB="workspace.provider:@neuralis/brain-core",fB=(0,Xs.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),c2=!1;function hB(n){let{registry:e,port:t}=n;!c2&&t.onClientStateReset&&(c2=!0,t.onClientStateReset(o=>{B.getState().resetClientState(o)}));function r({children:o}){return(0,Xs.jsx)(l2,{port:t,children:o})}e.register({packageSlug:"@neuralis/brain-core",componentImport:dB,Component:r});function a({agentId:o,widgetId:i,state:l}){let u=t.useProjectId(),c=t.useUserId();return(0,Xs.jsx)(Uf.WorkspaceHostPortProvider,{port:t,children:(0,Xs.jsx)(Uf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:o,userId:c,children:(0,Xs.jsx)(l0,{agentId:o,projectId:u,userId:c,widgetId:i,state:l})})})}let s=Hf.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:o=>(0,Xs.jsx)(Hf.Suspense,{fallback:fB,children:(0,Xs.jsx)(s,{...o})})}),(0,d2.registerCardComponent)("filesystem.change",o2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:QI,composer:SI,matchTools:CI})}export{hB as installFilesystemHostComponents};
|
|
54
|
+
`)}function l0(n){let e=Tr(n);return e.length===0?[]:[{skippedBefore:0,lines:e.map(t=>({type:"add",content:t}))}]}function LI(n,e){let t=Tr(n).map(a=>({type:"remove",content:a})),r=Tr(e).map(a=>({type:"add",content:a}));return[{skippedBefore:0,lines:[...t,...r]}]}function II(n){return n.map((e,t)=>{let r=Tr(e.find).map(s=>({type:"remove",content:s})),a=Tr(e.replace??"").map(s=>({type:"add",content:s}));return{skippedBefore:t>0?-1:0,lines:[...r,...a]}}).filter(e=>e.lines.length>0)}function AI(n){return l0(n)}function PI(n){let e=Tr(n);return e.length===0?[]:[{skippedBefore:0,lines:e.map(t=>({type:"add",content:t}))}]}function Yu(n){let e=n.action;if(!e){let t=Xu(n);return t!=null?{added:Tr(t).length,removed:0}:null}if(e==="replace_text"){let t=n.edits;if(Array.isArray(t)){let s=0,o=0;for(let i of t){if(!i||typeof i!="object")continue;let l=i;typeof l.find=="string"&&(o+=Tr(l.find).length),typeof l.replace=="string"&&(s+=Tr(l.replace).length)}return{added:s,removed:o}}let r=typeof n.find=="string"?n.find:"",a=typeof n.replace=="string"?n.replace:"";return{added:Tr(a).length,removed:Tr(r).length}}if(e==="update"||e==="replace_lines"){let t=Xu(n);return t!=null?{added:Tr(t).length,removed:0}:null}if(e==="append_text"||e==="prepend_text"||e==="insert"){let t=typeof n.text=="string"?n.text:"";return{added:Tr(t).length,removed:0}}return null}var IE={".ts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"jsx",".json":"json",".md":"markdown",".py":"python",".css":"css",".html":"html",".yaml":"yaml",".yml":"yaml",".sh":"bash",".sql":"sql",".rs":"rust",".go":"go",".java":"java",".xml":"xml",".toml":"toml",".env":"bash",".scss":"scss",".less":"less",".graphql":"graphql",".vue":"markup",".svelte":"markup",".txt":"text"};function Zi(n){let e=n.match(/(\.[a-zA-Z0-9]+)$/)?.[1]?.toLowerCase();return e?IE[e]:void 0}var AE=new Set(["update","replace_text","append_text","prepend_text","insert","replace_lines"]);function Qi(n){return!!n&&AE.has(n)}function Tr(n){return n?n.split(`
|
|
55
|
+
`):[]}function el(n){return NE((0,Ff.parseSettledObject)(n))}function Ef(n,e){let t=i0(n),r=i0(e),a=t.length,s=r.length,o=Array.from({length:a+1},()=>new Array(s+1).fill(0));for(let c=a-1;c>=0;c--)for(let d=s-1;d>=0;d--)o[c][d]=t[c]===r[d]?o[c+1][d+1]+1:Math.max(o[c+1][d],o[c][d+1]);let i=[],l=0,u=0;for(;l<a&&u<s;)t[l]===r[u]?(i.push({type:"context",content:t[l]}),l++,u++):o[l+1][u]>=o[l][u+1]?(i.push({type:"remove",content:t[l]}),l++):(i.push({type:"add",content:r[u]}),u++);for(;l<a;)i.push({type:"remove",content:t[l++]});for(;u<s;)i.push({type:"add",content:r[u++]});return[{skippedBefore:0,lines:i}]}function Of(n){let e=0,t=0;for(let r of n)for(let a of r.lines)a.type==="add"?e++:a.type==="remove"&&t++;return{added:e,removed:t}}function Xu(n){for(let e of["content","file_content","text"]){let t=n[e];if(typeof t=="string")return t}if(typeof n.content=="object"&&n.content!==null)try{return JSON.stringify(n.content,null,2)}catch{}return null}function u0(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let e=n;if(e.ok===!1)return null;let t=e.version;if(!t||typeof t!="object"||Array.isArray(t))return null;let r=t.diff;if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r,s=typeof a.added=="number"?a.added:null,o=typeof a.removed=="number"?a.removed:null;return s==null||o==null?null:{added:s,removed:o}}function PE(n){let e=(0,Ff.extractPathsFromToolCall)(n);if(e.length===0){let r=el(n.input),a=typeof r?.uri=="string"&&r.uri||typeof r?.path=="string"&&r.path||"";if(!a)return[];e=[a]}let t=u0(n.structuredContent);return e.map((r,a)=>a===0&&t?{path:r,diff:t}:{path:r})}var NI={tab:"changes",changes:PE},RI=["fs_write","fs_create","fs_modify"];function NE(n){if(!n||typeof n.action=="string"||!ME(n))return n;let e={};if(typeof n.uri=="string"&&(e.uri=n.uri),typeof n.id=="string"&&(e.id=n.id),typeof n.move=="string")return{...e,action:"move",destination:n.move};if(typeof n.copy=="string")return{...e,action:"copy",destination:n.copy};if(n.mkdir!==void 0)return{...e,action:"create_folder"};if(n.revert!==void 0)return{...e,action:"revert"};if(n.delete!==void 0)return{...e,action:"delete"};let t=Array.isArray(n.edit)?n.edit.filter(i=>!!i&&typeof i=="object").map(i=>({find:typeof i.old_string=="string"?i.old_string:"",replace:typeof i.new_string=="string"?i.new_string:""})).filter(i=>i.find.length>0):[];if(t.length>0)return{...e,action:"replace_text",edits:t};let r=Df(n.lines);if(r&&typeof r.content=="string")return{...e,action:"replace_lines",content:r.content};let a=Df(n.insert);if(a&&typeof a.insert_text=="string")return{...e,action:"insert",text:a.insert_text};let s=Df(n.overwrite);if(s&&s.content!==void 0)return{...e,action:"update",content:s.content};let o=Df(n.create);return o&&o.content!==void 0?{...e,content:o.content}:n.fields!==void 0?{...e,action:"set_fields",fields:n.fields}:n}var RE=["create","overwrite","edit","insert","lines","fields","move","copy","mkdir","revert","delete"];function ME(n){return RE.some(e=>n[e]!==void 0)}function Df(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function TI(n){let e=new Map;for(let t of n)if(t.status)for(let[r,a]of[[!0,t.status.staged],[!1,[...t.status.unstaged,...t.status.untracked]]])for(let s of a){let o=`${t.source}://${[t.repo.rel,s.path].filter(Boolean).join("/")}`,i=e.get(o)??new Map,l=JSON.stringify([t.source,t.repo.rel,s.path]),u=i.get(l);u?(u.staged||=r,u.unstaged||=!r):i.set(l,{group:t,path:s.path,staged:r,unstaged:!r}),e.set(o,i)}return e}function Ju(n){return`${n.source}://${n.repo.rel}`}function c0(n){let e=Es(n.source,n.repo.name);return e.prefix?`${e.prefix} ${e.name}`:e.name}function DI(n,e){return e.kind==="pending"?[]:n.filter(t=>(!e.source||t.source===e.source)&&(!e.repo||Ju(t)===e.repo)&&(!e.branch||t.status?.branch===e.branch))}function FI(n,e,t){return t.kind==="git"?[]:n.filter(r=>!(t.source&&r.sourceSlug!==t.source||t.agent&&r.agentId!==t.agent||t.origin&&r.origin!==t.origin||(t.repo||t.branch)&&!e.some(s=>r.sourceSlug===s.source&&jo(r.uri).startsWith(`${s.source}://${s.repo.rel?`${s.repo.rel}/`:""}`)&&(!t.repo||Ju(s)===t.repo)&&(!t.branch||s.status?.branch===t.branch)))).sort((r,a)=>r.createdAt<a.createdAt?-1:r.createdAt>a.createdAt?1:0)}function EI(n,e,t,r){let a=new Set(n.map(o=>jo(o.uri))),s=[];for(let o of e.keys())(t==="git"||!a.has(o))&&s.push({kind:"git",key:`git:${o}`,uri:o});return n.forEach((o,i)=>s.push({kind:r==="cards"?"pending-card":"pending-row",key:o.id,rec:o,index:i})),s}var TE=32,DE=346;function OI(n){return n==="pending-row"?TE:DE}function BI(n){return n!=="pending-row"}function _I(n,e,t=100,r){let a=[],s=[];for(let o of n)e.has(o.id)||(CI(o)||r?.(o.id)?.requiresAcknowledgement.length?s.push(o):a.length<t&&a.push(o));return{approvable:a,needsAck:s}}function d0(n){let e=n instanceof Error?n.message:String(n??"");return e.includes("PENDING_STATE_CHANGED")||e.includes("PENDING_GENERATION_CHANGED")?"changed":e.includes("CURRENT_STATE_ACKNOWLEDGEMENT_REQUIRED")?"needs-ack":"error"}var MI=new WeakMap;function Bf(n){if(n.diffState!=="readable")return null;let e=MI.get(n);return e||(e=Ef(n.baseline.state==="text"?n.baseline.text:"",n.current.state==="text"?n.current.text:""),MI.set(n,e)),e}var Bn=j(Ve(),1),GI=j(Qa(),1);var ft=j(le(),1),HI={originalDraftUnknown:{label:"Older change \u2014 original draft unknown",chip:"bg-amber-500/15 text-amber-200 border-amber-400/30"},externalChanged:{label:"Changed outside the review",chip:"bg-rose-500/15 text-rose-200 border-rose-400/30"},unreviewable:{label:"Diff not readable",chip:"bg-sky-500/15 text-sky-200 border-sky-400/30"},fresh:{label:"No confirmation needed now",chip:"bg-emerald-500/15 text-emerald-200 border-emerald-400/30"}},UI={ok:{label:"Done",tone:"text-emerald-300"},changed:{label:"Changed since the preview \u2014 check the fresh state and confirm again",tone:"text-amber-300"},"needs-ack":{label:"Still needs a confirmation",tone:"text-amber-300"},error:{label:"Refused",tone:"text-rose-300"}};async function _f(n,e,t,r,a){let s={agentId:n.agentId,...n.projectId?{projectId:n.projectId}:{},id:e.id,expectedFingerprint:t.expectedFingerprint,...a?{acknowledgeCurrentState:!0}:{}};try{let o=r==="approve"?await cc({...s,uri:e.uri}):r==="revert"?await ox(s):await lx(s);if(o&&o.ok===!1){let i="error"in o&&o.error?String(o.error):"Review refused";return{id:e.id,uri:e.uri,action:r,outcome:d0(i),detail:i}}return{id:e.id,uri:e.uri,action:r,outcome:"ok"}}catch(o){return{id:e.id,uri:e.uri,action:r,outcome:d0(o),detail:o instanceof Error?o.message:"Review refused"}}}function FE({rec:n,preview:e}){let t=(0,Bn.useMemo)(()=>Bf(e),[e]);return o0(n,e)?(0,ft.jsx)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/60 leading-relaxed",children:"The file is gone. Approving or dismissing accepts that it stays gone \u2014 nothing is recreated and the saved earlier version stays in history. Revert restores that version."}):t?(0,ft.jsx)("div",{className:"max-h-56 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,ft.jsx)(Ji,{hunks:t,language:Zi(n.uri),maxLines:400})}):(0,ft.jsxs)("div",{className:"px-2.5 py-2 text-[10.5px] text-white/50",children:["Diff ",e.diffState,": current ",e.current.state,", baseline ",e.baseline.state," (",e.baselineProvenance,")."]})}var Zu="h-7 px-2.5 rounded-md text-[11px] font-medium transition disabled:opacity-40 inline-flex items-center gap-1.5";function zI({request:n,agentId:e,projectId:t,run:r,onClose:a,onDone:s,next:o=0,onNext:i,refetch:l,onBatchStart:u}){let c=(0,Bn.useMemo)(()=>n.kind==="single"?[n.rec]:n.records,[n]),[d,f]=(0,Bn.useState)(()=>n.kind==="single"&&n.preview?{[n.rec.id]:n.preview}:{}),[h,p]=(0,Bn.useState)(!1),[m,g]=(0,Bn.useState)({}),x=(0,Bn.useRef)(!0),b=(0,Bn.useRef)(new Map);(0,Bn.useEffect)(()=>(x.current=!0,()=>{x.current=!1}),[]);let y=(0,Bn.useCallback)((P,O=!1)=>{let C=(b.current.get(P.id)??0)+1;b.current.set(P.id,C);let I=()=>x.current&&b.current.get(P.id)===C;(O&&l?l(P):r(()=>Yo({agentId:e,...t?{projectId:t}:{},id:P.id}),I)).then(q=>{I()&&q&&f($=>({...$,[P.id]:q}))},q=>{I()&&f($=>({...$,[P.id]:q instanceof Error?q:new Error("Preview failed")}))})},[e,t,r,l]);(0,Bn.useEffect)(()=>{for(let P of c)!d[P.id]&&!b.current.has(P.id)&&y(P)},[c,y]);let N=(0,Bn.useMemo)(()=>{let P=new Map;for(let O of c){let C=d[O.id];if(!C||C instanceof Error)continue;let I=C.requiresAcknowledgement[0]??"fresh";P.set(I,[...P.get(I)??[],O])}return P},[c,d]),L=c.filter(P=>!d[P.id]).length,A=P=>m[P.id]!==void 0&&m[P.id].outcome!=="changed",w=n.kind==="group"&&L===0&&!h&&c.every(P=>A(P)||d[P.id]instanceof Error),v=(0,Bn.useCallback)(async(P,O)=>{p(!0),u?.();let C=[];for(let I of P){let H=d[I.id];if(!H||H instanceof Error||m[I.id]?.outcome==="ok")continue;let q=await _f({agentId:e,projectId:t},I,H,O,H.requiresAcknowledgement.length>0);C.push(q),g($=>({...$,[I.id]:q})),q.outcome==="changed"&&(f($=>{let{[I.id]:S,...M}=$;return M}),y(I,!0))}p(!1),s(C)},[d,m,e,t,s,y,u]);if(typeof document>"u")return null;let T=n.kind==="single"?n:null;return(0,GI.createPortal)((0,ft.jsx)("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/40 backdrop-blur-[1px]",onMouseDown:h?void 0:a,children:(0,ft.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Review pending changes",onMouseDown:P=>P.stopPropagation(),className:"w-[min(640px,92vw)] max-h-[82vh] flex flex-col rounded-xl border border-amber-400/25 bg-[#15151d] shadow-[0_30px_80px_-24px_rgba(0,0,0,0.85)]",children:[(0,ft.jsxs)("div",{className:"flex items-start gap-2.5 p-4 pb-2 shrink-0",children:[(0,ft.jsx)(Ca,{className:"h-4 w-4 text-amber-300 shrink-0 mt-0.5"}),(0,ft.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,ft.jsx)("div",{className:"text-[12px] font-semibold text-white/90",children:T?`Review the current state \u2014 ${T.action}`:n.kind==="group"&&n.total>c.length?`${c.length} of ${n.total} changes need your confirmation`:`${c.length} changes need your confirmation`}),(0,ft.jsx)("div",{className:"mt-1 text-[10.5px] text-white/55 leading-relaxed",children:"Each change is checked against its own fresh preview. Confirming accepts the state shown here; a change that moves again before you confirm is refused and stays in the list."}),L>0?(0,ft.jsxs)("div",{className:"mt-1.5 inline-flex items-center gap-1.5 text-[10.5px] text-white/45",children:[(0,ft.jsx)(We,{className:"h-3 w-3 animate-spin"})," Loading ",L," preview",L>1?"s":"","\u2026"]}):null]})]}),(0,ft.jsxs)("div",{className:"min-h-0 flex-1 overflow-auto overlay-scroll px-4 space-y-3",children:[[...N].map(([P,O])=>(0,ft.jsxs)("section",{className:"rounded-lg border border-white/8 bg-black/20",children:[(0,ft.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-white/5",children:[(0,ft.jsxs)("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${HI[P].chip}`,children:[HI[P].label," \xB7 ",O.length]}),T?null:(0,ft.jsxs)("div",{className:"ml-auto flex items-center gap-1.5",children:[(0,ft.jsxs)("button",{type:"button",disabled:h||O.every(A),onClick:()=>{v(O,"dismiss")},className:`${Zu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ft.jsx)(aa,{className:"h-3 w-3"})," Confirm & dismiss ",O.length]}),(0,ft.jsxs)("button",{type:"button",disabled:h||O.every(A),onClick:()=>{v(O,"approve")},className:`${Zu} bg-emerald-500/20 hover:bg-emerald-500/30 border border-emerald-400/40 text-emerald-100 font-semibold`,children:[(0,ft.jsx)(xs,{className:"h-3 w-3"})," Confirm & approve ",O.length]})]})]}),O.map(C=>{let I=d[C.id],H=m[C.id];return(0,ft.jsxs)("div",{className:"border-b border-white/5 last:border-0",children:[(0,ft.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1 text-[10.5px]",children:[(0,ft.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono text-white/70",title:C.uri,children:C.uri}),H?(0,ft.jsx)("span",{className:UI[H.outcome].tone,title:H.detail,children:UI[H.outcome].label}):null]}),(0,ft.jsx)(FE,{rec:C,preview:I})]},C.id)})]},P)),c.filter(P=>d[P.id]instanceof Error).map(P=>(0,ft.jsxs)("div",{className:"rounded-md bg-rose-500/10 px-2.5 py-1.5 text-[10.5px] text-rose-200/90",children:[P.uri,": ",d[P.id].message]},P.id))]}),(0,ft.jsxs)("div",{className:"flex items-center justify-end gap-2 p-4 pt-3 shrink-0",children:[(0,ft.jsxs)("button",{type:"button",onClick:a,disabled:h,className:`${Zu} bg-white/[0.04] hover:bg-white/[0.08] text-white/70`,children:[(0,ft.jsx)(Bt,{className:"h-3 w-3"})," ",Object.keys(m).length?"Close":"Cancel"]}),w&&i&&o>0?(0,ft.jsxs)("button",{type:"button",onClick:()=>i(c.map(P=>P.id)),className:`${Zu} border border-amber-400/40 bg-amber-500/15 hover:bg-amber-500/25 text-amber-100 font-semibold`,children:[(0,ft.jsx)(Ca,{className:"h-3 w-3"})," Next batch (",o," left)"]}):null,T?["revert","dismiss","approve"].map(P=>{let O=P===T.action,C=P==="approve"?Mn:P==="revert"?La:aa,I=P==="revert"?"border border-rose-400/40 bg-rose-500/15 hover:bg-rose-500/25 text-rose-100":O?"border border-emerald-400/40 bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-100 font-semibold":"bg-white/[0.04] hover:bg-white/[0.08] text-white/70";return(0,ft.jsxs)("button",{type:"button",disabled:h||L>0||m[T.rec.id]?.outcome==="ok",onClick:()=>{v([T.rec],P)},className:`${Zu} ${I}`,children:[(0,ft.jsx)(C,{className:"h-3 w-3"})," ",O?`Confirm & ${P}`:P[0].toUpperCase()+P.slice(1)]},P)}):null]})]})}),document.body)}var J=j(le(),1),qI={create:(0,J.jsx)(Cs,{className:"w-3.5 h-3.5 text-emerald-300/80"}),modify:(0,J.jsx)(ks,{className:"w-3.5 h-3.5 text-sky-300/80"}),delete:(0,J.jsx)(It,{className:"w-3.5 h-3.5 text-red-300/80"}),move:(0,J.jsx)(Rl,{className:"w-3.5 h-3.5 text-violet-300/80"})},VI=n=>n==="approved"?"bg-emerald-400":n==="reverted"?"bg-white/30":"bg-amber-400";function $I({diff:n}){return!n||n.added===0&&n.removed===0?null:(0,J.jsxs)("span",{className:"font-mono text-[10px] shrink-0",children:[n.added>0?(0,J.jsxs)("span",{className:"text-emerald-300",children:["+",n.added]}):null,n.added>0&&n.removed>0?" ":null,n.removed>0?(0,J.jsxs)("span",{className:"text-red-300",children:["\u2212",n.removed]}):null]})}var KI=(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-200/90 text-[10px] shrink-0",title:"The backing file no longer exists \u2014 this change can only be discarded.",children:[(0,J.jsx)(Gl,{className:"w-3 h-3"})," Orphaned"]});function XI({orphaned:n,busy:e,onApprove:t,onRevert:r,onDiscard:a,onDismiss:s,className:o}){let i=(0,J.jsx)(Hf.LiveSpinner,{className:"w-3.5 h-3.5"});return(0,J.jsx)("div",{className:o,children:n?(0,J.jsx)("button",{type:"button",onClick:a,disabled:e,title:"Discard (remove this un-actionable change)",className:"p-1 rounded hover:bg-rose-500/15 text-rose-300/80 disabled:opacity-40",children:e?i:(0,J.jsx)(It,{className:"w-3.5 h-3.5"})}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)("button",{type:"button",onClick:t,disabled:e,title:"Approve",className:"p-1 rounded hover:bg-emerald-500/15 text-emerald-300/80 disabled:opacity-40",children:e?i:(0,J.jsx)(Mn,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:r,disabled:e,title:"Revert",className:"p-1 rounded hover:bg-red-500/15 text-red-300/80 disabled:opacity-40",children:(0,J.jsx)(La,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:s,disabled:e,title:"Dismiss (stop reviewing \u2014 keep the change, no revert)",className:"p-1 rounded hover:bg-white/10 text-white/50 hover:text-white/80 disabled:opacity-40",children:(0,J.jsx)(aa,{className:"w-3.5 h-3.5"})})]})})}function WI({uri:n,rows:e,agentId:t,projectId:r,canWrite:a,revisions:s,queue:o}){let i=e.get(jo(n));return i?(0,J.jsx)(J.Fragment,{children:[...i.values()].map(l=>(0,J.jsx)(fe.default.Fragment,{children:[!0,!1].filter(u=>u?l.staged:l.unstaged).map(u=>(0,J.jsxs)("div",{children:[(0,J.jsxs)("div",{className:"px-3 py-1 text-[10px] text-white/40",children:[l.group.repo.name," (",l.group.repo.rel||"root",") \xB7 ",u?"Git HEAD \u2192 index (staged)":"Git index \u2192 working file (unstaged/untracked)"]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:(0,J.jsx)(wo,{source:l.group.source,repo:l.group.repo.rel,path:l.path,mode:{kind:"working",staged:u},agentId:t,projectId:r,variant:"card",canWrite:a&&l.group.repo.canWrite===!0,revision:s[l.group.source]??0,runContent:o.run,peekContent:o.peek})})]},String(u)))},`${l.group.source}/${l.group.repo.rel}/${l.path}`))}):null}var YI=(n,e)=>`preview\0${n.id}\0${n.updatedAt}\0${e}`,EE=n=>2*((n.baseline.state==="text"?n.baseline.text.length:0)+(n.current.state==="text"?n.current.text.length:0))+256,OE=(0,fe.memo)(function({rec:e,agentId:t,projectId:r,focused:a,orphaned:s,onOpen:o,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,onFocus:d,busy:f,queue:h,revision:p,canWrite:m,onPreview:g,peekPreview:x,takeRefetch:b,extra:y}){let[N,L]=(0,fe.useState)(!0),[A,w]=(0,fe.useState)(()=>x(e.id)??null),[v,T]=(0,fe.useState)(!1),[P,O]=(0,fe.useState)(null),[C,I]=(0,fe.useState)(""),H=(0,fe.useRef)(0),q=h.visible.has(e.id),$=(0,fe.useRef)(!1);$.current=N&&q;let S=YI(e,p),M=(0,fe.useRef)("");(0,fe.useEffect)(()=>{let ue=++H.current;if(!N||!q||M.current===S){T(!1);return}let ie=b(e.id,S);if(ie==="wait"){T(!0);return}if(ie){w(ie),O(null),I(S),M.current=S,T(!1);return}return T(!0),h.run(()=>Yo({agentId:t,...r?{projectId:r}:{},id:e.id}),()=>ue===H.current&&$.current,{key:S,bytes:EE}).then(Re=>{!Re||ue!==H.current||!$.current||(g(Re),w(Re),O(null),I(S),M.current=S,T(!1))}).catch(Re=>{ue===H.current&&(O(Re instanceof Error?Re.message:"Failed to load review"),T(!1))}),()=>{H.current++}},[t,r,e.id,S,N,q,h.run]);let W=(0,fe.useMemo)(()=>A?Bf(A):null,[A]),ee=(0,fe.useMemo)(()=>W?Of(W):null,[W]),te=C===S?A?.indexState??null:null,re=P??(A&&A.diffState!=="readable"?`Review diff unavailable: ${A.diffState}; current ${A.current.state}, baseline ${A.baseline.state}.`:null),ce=(0,fe.useCallback)(()=>L(ue=>!ue),[]),oe=e.diff&&(e.diff.added>0||e.diff.removed>0)?e.diff:ee??void 0;return(0,J.jsxs)("div",{ref:ue=>h.register(e.id,ue),onMouseDown:d,className:`rounded-lg border overflow-hidden transition-colors ${s?"border-rose-400/30 bg-rose-500/[0.04]":a?"border-amber-400/40 ring-1 ring-amber-400/25 bg-amber-400/[0.03]":"border-white/8 bg-black/20"}`,children:[(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-2.5 py-1.5",children:[(0,J.jsx)("button",{type:"button",onClick:ce,"aria-expanded":N,className:"text-white/40 hover:text-white/80 shrink-0",children:N?(0,J.jsx)(Tt,{className:"w-3.5 h-3.5"}):(0,J.jsx)(un,{className:"w-3.5 h-3.5"})}),qI[e.op],(0,J.jsxs)("button",{type:"button",onClick:()=>o(e.uri),className:"min-w-[6rem] flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:e.uri,children:[yt(e.uri)||e.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[nt(e.uri),"/"]})]}),(0,J.jsx)($I,{diff:oe}),te&&te!=="stored"?(0,J.jsx)("span",{className:"text-[10px] text-amber-200/80 shrink-0",children:te==="missing"?"Index missing":te==="stale"?"Index stale":"Recovery only"}):null,s?KI:e.status==="approved"||e.status==="reverted"?(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VI(e.status)}`,title:e.status}):null,m?(0,J.jsx)(XI,{orphaned:s,busy:f,onApprove:i,onRevert:l,onDiscard:u,onDismiss:c,className:"ml-auto flex items-center gap-1 shrink-0"}):null]}),N?(0,J.jsxs)("div",{className:"border-t border-white/5",children:[(0,J.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1 text-[10px] text-white/40",children:["Review baseline \u2192 current file",v&&A?(0,J.jsx)(Hf.LiveSpinner,{className:"w-3 h-3"}):null]}),(0,J.jsx)("div",{className:"max-h-72 overflow-auto overlay-scroll",style:{scrollbarGutter:"auto"},children:v&&!A?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-white/40",children:[(0,J.jsx)(Hf.LiveSpinner,{className:"w-3.5 h-3.5"})," Loading diff\u2026"]}):re?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-4 text-xs text-red-300/80",children:[(0,J.jsx)(ct,{className:"w-3.5 h-3.5"})," ",re]}):W?(0,J.jsx)(Ji,{hunks:W,language:Zi(e.uri),maxLines:600}):null})]}):null,N?y:null]})}),tl="bg-transparent border border-white/8 rounded px-1.5 py-0.5 text-white/70",nl={background:"var(--w-composer-bg-rgb, rgba(20,20,28,1))"},BE={kind:"all",source:"",repo:"",branch:"",agent:"",origin:""},Qu=100;function JI({agentId:n,projectId:e}){let t=fn(),r=Za({grantedFeatures:[...t.grantedFeatures??[]]},"drive.write"),a=_(z=>z.sources),s=_(z=>z.sourceChangeRevision),[o,i]=(0,fe.useState)(null),l=o??s,u=(0,fe.useRef)(s);u.current=s;let c=(0,fe.useRef)(s),d=(0,fe.useCallback)(()=>i(z=>z??u.current),[]),f=_(z=>z.pendingPanelFilter),h=_(z=>z.setPendingPanelFilter),p=_(z=>z.openFile),m=_(z=>z.removeFilePath),g=_(z=>z.setActiveWorkspaceTab),x=_(z=>z.refreshPendingCount),b=f.conversationId??"",[y,N]=(0,fe.useState)(null),L=Nc(y),A=(0,fe.useRef)(new Map),w=(0,fe.useCallback)(z=>A.current.get(z),[]),v=(0,fe.useRef)(new Map),T=(0,fe.useRef)(Promise.withResolvers()),P=(0,fe.useCallback)((z,ne)=>{let R=v.current.get(z);return R===null?"wait":(R&&v.current.delete(z),R?.key===ne?R.preview:void 0)},[]),[O,C]=(0,fe.useState)(BE),I=z=>ne=>C(R=>({...R,[z]:ne.target.value})),[H,q]=(0,fe.useState)("cards"),[$,S]=(0,fe.useState)([]),[M,W]=(0,fe.useState)(new Set),[ee,te]=(0,fe.useState)(!1),[re,ce]=(0,fe.useState)(null),[oe,ue]=(0,fe.useState)(null),[ie,Re]=(0,fe.useState)({}),De=(0,fe.useRef)({nonces:ie,revisions:l});De.current={nonces:ie,revisions:l};let Ye=(0,fe.useCallback)(async z=>{v.current.set(z.id,null);try{let ne=(await T.current.promise)?.find(B=>B.id===z.id)??z,R=await Yo({agentId:n,...e?{projectId:e}:{},id:z.id}),X=(De.current.nonces[z.id]??0)+1+(De.current.revisions[ne.sourceSlug]??0);return v.current.set(z.id,{key:YI(ne,X),preview:R}),A.current.set(z.id,R),R}catch(ne){throw v.current.delete(z.id),ne}finally{Re(ne=>({...ne,[z.id]:(ne[z.id]??0)+1}))}},[n,e]),[$e,Pt]=(0,fe.useState)(0),[Xe,lt]=(0,fe.useState)(null),[Nt,ot]=(0,fe.useState)([]),[Me,tt]=(0,fe.useState)(!1),[pt,Rt]=(0,fe.useState)(!1),[kt,Ee]=(0,fe.useState)(!1),[xe,Dt]=(0,fe.useState)(!1),[en,he]=(0,fe.useState)(new Set),pe=(0,fe.useRef)(null),je=(0,fe.useRef)(0),Pe=vI({agentId:n,projectId:e,sources:a,revisions:l,resetKey:`${n}\0${e}\0${b}`}),Ce=(0,fe.useCallback)(async z=>{if(!n)return;let ne=++je.current;te(!0),ce(null);try{let R=await ax({agentId:n,...e?{projectId:e}:{},...b?{conversationId:b}:{},...z?{include_orphans:!0}:{}});if(ne!==je.current)return;let X=new Set(R.changes.map(B=>B.id));return S(R.changes),W(B=>z?new Set(R.orphanIds):new Set([...B].filter(me=>X.has(me)))),R.changes}catch(R){ne===je.current&&ce(R instanceof Error?R.message:"Failed to load changes");return}finally{ne===je.current&&te(!1)}},[n,e,b]),ln=(0,fe.useCallback)(async()=>{await Promise.all([Ce(!0),Pe.refresh(!0)]),x({agentId:n,projectId:e})},[Ce,Pe.refresh,x,n,e]);(0,fe.useEffect)(()=>(A.current.clear(),lt(null),S([]),W(new Set),ot([]),Ce(!0),()=>{je.current++,A.current.clear()}),[Ce]);let mt=(0,fe.useRef)(Ce);mt.current=Ce;let Ht=(0,fe.useRef)(!0);(0,fe.useEffect)(()=>{if(Ht.current){Ht.current=!1;return}l!==c.current&&mt.current(!1)},[l]);let Ge=Pe.groups,Wt=(0,fe.useMemo)(()=>Array.from(new Set([...$.map(z=>z.sourceSlug),...Ge.map(z=>z.source)])).sort(),[$,Ge]),tn=(0,fe.useMemo)(()=>Array.from(new Set($.map(z=>z.agentId).filter(Boolean))).sort(),[$]),Be=(0,fe.useMemo)(()=>Array.from(new Set($.map(z=>z.origin).filter(Boolean))).sort(),[$]),Y=(0,fe.useMemo)(()=>FI($,Ge,O),[$,Ge,O]),Ie=(0,fe.useMemo)(()=>DI(Ge,O),[Ge,O]),_e=(0,fe.useMemo)(()=>TI(Ie),[Ie]),ze=(0,fe.useMemo)(()=>EI(Y,_e,O.kind,H),[Y,_e,O.kind,H]),[Te,de]=(0,fe.useState)(0),{approvable:ut,needsAck:Ft}=(0,fe.useMemo)(()=>_I(Y,M,Qu,w),[Y,M,w,Te]),nn=(0,fe.useRef)(new Set),$n=Ft.filter(z=>!nn.current.has(z.id)),ar=(0,fe.useCallback)(z=>{for(let R of z)nn.current.add(R);let ne=Ft.filter(R=>!nn.current.has(R.id));lt({kind:"group",records:ne.slice(0,Qu),total:ne.length})},[Ft]),xr=(0,fe.useRef)(ze);xr.current=ze;let Kn=(0,fe.useCallback)(z=>OI(xr.current[z]?.kind??"pending-card"),[]),Xn=(0,fe.useCallback)(z=>xr.current[z]?.key??z,[]),Yn=li({count:ze.length,getScrollElement:()=>y,estimateSize:Kn,getItemKey:Xn,overscan:4});Yn.shouldAdjustScrollPositionOnItemSizeChange=_E,(0,fe.useEffect)(()=>{Pt(z=>Y.length===0?0:Math.min(z,Y.length-1))},[Y.length]);let xa=ze.length-Y.length;(0,fe.useEffect)(()=>{Y.length>0&&Yn.scrollToIndex(xa+$e,{align:"auto"})},[$e,H]);let yr=(0,fe.useCallback)(z=>{p({agentId:n,projectId:e,uri:z}),g("file")},[n,e,p,g]),Jn=(0,fe.useCallback)(z=>{if(z.op!=="delete"||!z.uri)return;let ne=_.getState().files[z.uri];(!ne||ne.status==="deleted")&&m(z.uri)},[m]),dn=(0,fe.useCallback)(async z=>{for(let X of z){let B=$.find(me=>me.id===X.id);B&&X.outcome==="ok"&&X.action!=="revert"&&Jn(B),X.outcome!=="ok"&&X.outcome!=="needs-ack"&&!v.current.has(X.id)&&A.current.delete(X.id)}let ne=z.filter(X=>X.outcome!=="ok"&&X.outcome!=="needs-ack"&&!v.current.has(X.id));ne.length&&Re(X=>{let B={...X};for(let me of ne)B[me.id]=(B[me.id]??0)+1;return B}),ot(z);let R=await Ce(!1);c.current=_.getState().sourceChangeRevision,i(null),T.current.resolve(R),T.current=Promise.withResolvers(),x({agentId:n,projectId:e})},[$,Jn,Ce,x,n,e]),Rn=(0,fe.useCallback)(async(z,ne)=>{if(!r)return;let R=A.current.get(z.id);if(!R||R.requiresAcknowledgement.length){lt({kind:"single",rec:z,action:ne,...R?{preview:R}:{}});return}ue(z.id);try{await dn([await _f({agentId:n,projectId:e},z,R,ne,!1)])}finally{ue(null)}},[r,n,e,dn]),rn=(0,fe.useCallback)(async z=>{ue(z.id);try{let ne=await ix({agentId:n,...e?{projectId:e}:{},id:z.id});ne.ok?Jn(z):ce(ne.error||"Discard failed"),await Ce(!1),x({agentId:n,projectId:e})}catch(ne){ce(ne instanceof Error?ne.message:"Discard failed")}finally{ue(null)}},[n,e,Ce,Jn,x]),Dr=(0,fe.useCallback)(async()=>{pe.current&&(clearTimeout(pe.current),pe.current=null),Dt(!0),Ee(!1),ce(null);try{await ux({agentId:n,...e?{projectId:e}:{},...b?{conversationId:b}:{}});let z=$.filter(R=>M.has(R.id)),ne=await Ce(!0);if(ne){let R=new Set(ne.map(X=>X.id));for(let X of z)R.has(X.id)||Jn(X)}x({agentId:n,projectId:e})}catch(z){ce(z instanceof Error?z.message:"Repair failed")}finally{Dt(!1)}},[n,e,b,Ce,$,M,Jn,x]),Zn=(0,fe.useCallback)(()=>{if(kt){Dr();return}Ee(!0),pe.current&&clearTimeout(pe.current),pe.current=setTimeout(()=>Ee(!1),3e3)},[kt,Dr]);(0,fe.useEffect)(()=>()=>{pe.current&&clearTimeout(pe.current)},[]);let Fr=(0,fe.useCallback)(async()=>{tt(!0),Rt(!1),ce(null),d();let z=[];try{for(let ne of ut){let R=A.current.get(ne.id);if(!R){try{R=await Yo({agentId:n,...e?{projectId:e}:{},id:ne.id})}catch(X){z.push({id:ne.id,uri:ne.uri,action:"approve",outcome:"error",detail:X instanceof Error?X.message:"Preview failed"});continue}A.current.set(ne.id,R)}if(R.requiresAcknowledgement.length){z.push({id:ne.id,uri:ne.uri,action:"approve",outcome:"needs-ack"});continue}z.push(await _f({agentId:n,projectId:e},ne,R,"approve",!1))}}finally{tt(!1);let ne=ut.filter(R=>z.some(X=>X.id===R.id&&X.outcome==="needs-ack"));ne.length&&de(R=>R+1),await dn(z),ne.length&&r&&(nn.current.clear(),lt({kind:"group",records:ne.slice(0,Qu),total:ne.length}))}},[ut,n,e,dn,r]),sr=(0,fe.useCallback)(z=>Pt(ne=>Y.length===0?0:Math.max(0,Math.min(Y.length-1,ne+z))),[Y.length]),_n=(0,fe.useCallback)(z=>{if(oe||Me||!r||Xe)return;let ne=Y[$e],R=ne?M.has(ne.id):!1;z.key==="ArrowDown"||z.key==="ArrowRight"?(z.preventDefault(),sr(1)):z.key==="ArrowUp"||z.key==="ArrowLeft"?(z.preventDefault(),sr(-1)):R&&ne&&(z.key==="d"||z.key==="r"||z.key==="Enter")?(z.preventDefault(),rn(ne)):(z.key==="a"||z.key==="Enter")&&ne?(z.preventDefault(),Rn(ne,"approve")):z.key==="r"&&ne?(z.preventDefault(),Rn(ne,"revert")):z.key==="x"&&!R&&ne&&(z.preventDefault(),Rn(ne,"dismiss"))},[oe,Me,r,Xe,Y,$e,M,sr,rn,Rn]),Zr=z=>{if(z.kind==="git"){let me=!en.has(z.uri);return(0,J.jsxs)("div",{ref:E=>L.register(z.uri,E),className:"rounded-lg border border-white/8 bg-black/20",children:[(0,J.jsx)("button",{type:"button","aria-expanded":me,className:"px-3 py-2 text-xs text-white/85",onClick:()=>he(E=>{let ye=new Set(E);return ye.has(z.uri)?ye.delete(z.uri):ye.add(z.uri),ye}),children:z.uri}),me?(0,J.jsx)(WI,{uri:z.uri,rows:_e,agentId:n,projectId:e,canWrite:r,revisions:l,queue:L}):null]})}let{rec:ne,index:R}=z,X=M.has(ne.id),B={onApprove:()=>{Rn(ne,"approve")},onRevert:()=>{Rn(ne,"revert")},onDiscard:()=>{rn(ne)},onDismiss:()=>{Rn(ne,"dismiss")}};return z.kind==="pending-card"?(0,J.jsx)(OE,{rec:ne,agentId:n,projectId:e,focused:R===$e,orphaned:X,onOpen:yr,...B,onFocus:()=>Pt(R),busy:oe===ne.id,queue:L,revision:(ie[ne.id]??0)+(l[ne.sourceSlug]??0),canWrite:r,onPreview:me=>{A.current.set(ne.id,me),me.requiresAcknowledgement.length&&de(E=>E+1)},peekPreview:w,takeRefetch:P,extra:O.kind==="all"?(0,J.jsx)(WI,{uri:ne.uri,rows:_e,agentId:n,projectId:e,canWrite:r,revisions:l,queue:L}):null}):(0,J.jsxs)("div",{onMouseDown:()=>Pt(R),className:`group h-8 flex items-center gap-2 px-2 rounded-lg ${R===$e?"bg-amber-400/[0.06] ring-1 ring-amber-400/20":"hover:bg-white/5"}`,children:[qI[ne.op],(0,J.jsxs)("button",{type:"button",onClick:()=>yr(ne.uri),className:"min-w-0 flex-1 text-left truncate text-xs text-white/85 hover:text-white",title:ne.uri,children:[yt(ne.uri)||ne.uri,(0,J.jsxs)("span",{className:"ml-1.5 text-[10px] text-white/30 font-mono",children:[nt(ne.uri),"/"]})]}),(0,J.jsx)($I,{diff:ne.diff}),X?KI:(0,J.jsx)("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${VI(ne.status)}`,title:ne.status}),r?(0,J.jsx)(XI,{orphaned:X,busy:oe===ne.id,...B,className:"hidden group-hover:flex items-center gap-0.5 shrink-0"}):null]})},br=Nt.filter(z=>z.outcome!=="ok"),vn=ee||Pe.loading;return(0,J.jsxs)("div",{className:"w-full h-full flex flex-col min-h-0 outline-none",tabIndex:0,onKeyDown:_n,children:[r&&Xe?(0,J.jsx)(zI,{request:Xe,agentId:n,projectId:e,run:L.run,onClose:()=>lt(null),next:Xe.kind==="group"?$n.filter(z=>!Xe.records.some(ne=>ne.id===z.id)).length:0,onNext:ar,refetch:Ye,onBatchStart:d,onDone:z=>{for(let ne of z)nn.current.add(ne.id);dn(z)}},Xe.kind==="group"?`group\0${Xe.records[0]?.id??""}`:`single\0${Xe.rec.id}`):null,(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-2 border-b border-white/5 shrink-0",children:[(0,J.jsx)("span",{className:"text-xs font-semibold text-white/80",children:"Changes"}),(0,J.jsx)("span",{className:"text-[10px] text-white/35",children:Y.length>0?`${Math.min($e+1,Y.length)}/${Y.length}`:"0"}),(0,J.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>sr(-1),disabled:Y.length===0||$e===0,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Previous (\u2191)",children:(0,J.jsx)(xl,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>sr(1),disabled:Y.length===0||$e>=Y.length-1,className:"p-1.5 text-white/45 hover:text-white/80 disabled:opacity-30",title:"Next (\u2193)",children:(0,J.jsx)(un,{className:"w-3.5 h-3.5"})})]}),r?pt?(0,J.jsxs)("button",{type:"button",onClick:()=>{Fr()},disabled:Me||ut.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 px-2 py-1 text-[10px] text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-40",title:`Approve ${ut.length} visible change(s) that need no confirmation`,children:[Me?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,J.jsx)(xs,{className:"w-3 h-3"})," Approve ",ut.length,"?"]}):(0,J.jsxs)("button",{type:"button",onClick:()=>Rt(!0),disabled:ut.length===0,className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-white/8 px-2 py-1 text-[10px] text-white/55 hover:text-white/85 hover:bg-white/5 disabled:opacity-30",title:"Approve every visible change that needs no confirmation",children:[(0,J.jsx)(xs,{className:"w-3 h-3"})," Approve ",ut.length]}):null,r&&Ft.length>0?(0,J.jsxs)("button",{type:"button",onClick:()=>{nn.current.clear(),lt({kind:"group",records:Ft.slice(0,Qu),total:Ft.length})},className:"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-amber-400/30 px-2 py-1 text-[10px] text-amber-200/90 hover:bg-amber-500/10",title:`Review the changes that need your confirmation, grouped by reason (up to ${Qu} at a time)`,children:[(0,J.jsx)(Ca,{className:"w-3 h-3"})," ",Ft.length," need confirmation"]}):null,(0,J.jsxs)("div",{className:"flex items-center rounded-lg border border-white/8 overflow-hidden",children:[(0,J.jsx)("button",{type:"button",onClick:()=>q("list"),title:"Compact list",className:`p-1.5 ${H==="list"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(no,{className:"w-3.5 h-3.5"})}),(0,J.jsx)("button",{type:"button",onClick:()=>q("cards"),title:"Diff cards",className:`p-1.5 ${H==="cards"?"bg-white/10 text-white":"text-white/45 hover:text-white/80"}`,children:(0,J.jsx)(Xa,{className:"w-3.5 h-3.5"})})]}),r&&M.size>0?(0,J.jsxs)("button",{type:"button",onClick:Zn,disabled:xe,className:kt?"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-500/40 bg-rose-500/15 px-2 py-1 text-[10px] text-rose-100 hover:bg-rose-500/25 disabled:opacity-40":"inline-flex shrink-0 whitespace-nowrap items-center gap-1 rounded-lg border border-rose-400/25 px-2 py-1 text-[10px] text-rose-200/80 hover:text-rose-100 hover:bg-rose-500/10 disabled:opacity-40",title:kt?`Discard all ${M.size} orphaned change(s)`:"Repair \u2014 discard orphaned changes whose backing file no longer exists",children:[xe?(0,J.jsx)(We,{className:"w-3 h-3 animate-spin"}):kt?(0,J.jsx)(It,{className:"w-3 h-3"}):(0,J.jsx)(co,{className:"w-3 h-3"}),kt?`Discard ${M.size}?`:`Repair ${M.size}`]}):null,(0,J.jsx)("button",{type:"button",onClick:()=>{ln()},disabled:vn,title:"Refresh",className:"p-1.5 rounded-lg text-white/45 hover:text-white/80 hover:bg-white/5 disabled:opacity-40",children:(0,J.jsx)(Ot,{className:`w-3.5 h-3.5 ${vn?"animate-spin":""}`})}),(0,J.jsx)(jI.SkillLauncher,{variant:"icon",size:"sm",skill:"manage-files",packageId:"@neuralis/brain-core",scripts:["scripts/pending.sh","scripts/approve.sh"],label:"Review or approve pending changes with the agent",icon:"FileText"})]})]}),(0,J.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-white/5 shrink-0 text-[11px]",children:[b?(0,J.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-violet-500/15 text-violet-200/90",title:b,children:["conversation ",(0,J.jsx)("button",{type:"button",onClick:()=>h({}),className:"rounded hover:bg-violet-400/20 -mr-0.5",title:"Clear conversation filter",children:(0,J.jsx)(Bt,{className:"w-3 h-3"})})]}):null,(0,J.jsxs)("select",{"aria-label":"Change type",value:O.kind,onChange:I("kind"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"all",children:"All changes"}),(0,J.jsx)("option",{value:"pending",children:"Pending review"}),(0,J.jsx)("option",{value:"git",children:"Git"})]}),(0,J.jsxs)("select",{"aria-label":"Source",value:O.source,onChange:I("source"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"",children:"All sources"}),Wt.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),(0,J.jsxs)("select",{"aria-label":"Repository",value:O.repo,onChange:I("repo"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"",children:"All repositories"}),Ge.map(z=>(0,J.jsx)("option",{value:Ju(z),children:c0(z)},Ju(z)))]}),(0,J.jsxs)("select",{"aria-label":"Checked-out branch",value:O.branch,onChange:I("branch"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"",children:"All checked-out branches"}),[...new Set(Ge.map(z=>z.status?.branch).filter(Boolean))].map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}),tn.length>1?(0,J.jsxs)("select",{"aria-label":"Agent",value:O.agent,onChange:I("agent"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"",children:"All agents"}),tn.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null,Be.length>1?(0,J.jsxs)("select",{"aria-label":"Origin",value:O.origin,onChange:I("origin"),className:tl,style:nl,children:[(0,J.jsx)("option",{value:"",children:"All origins"}),Be.map(z=>(0,J.jsx)("option",{value:z,children:z},z))]}):null]}),Ie.filter(z=>z.error).map(z=>(0,J.jsxs)("div",{className:"px-3 py-2 text-xs text-red-300 shrink-0",children:[c0(z),": ",z.error]},`${z.source}/${z.repo.rel}`)),re?(0,J.jsxs)("div",{className:"mx-3 mt-2 flex items-center gap-2 rounded-lg border border-red-500/25 bg-red-500/10 px-2.5 py-1.5 text-[11px] text-red-200/85 shrink-0",children:[(0,J.jsx)(ct,{className:"w-3.5 h-3.5"})," ",re]}):null,br.length?(0,J.jsxs)("div",{className:"mx-3 mt-2 max-h-28 overflow-auto overlay-scroll rounded-lg border border-amber-500/25 bg-amber-500/[0.06] px-2.5 py-1.5 text-[10.5px] text-amber-100/85 shrink-0",children:[(0,J.jsxs)("div",{className:"flex items-center gap-2 font-semibold",children:[Nt.length-br.length," done \xB7 ",br.length," not done",(0,J.jsx)("button",{type:"button",onClick:()=>ot([]),className:"ml-auto rounded hover:bg-white/10",title:"Dismiss",children:(0,J.jsx)(Bt,{className:"w-3 h-3"})})]}),br.map(z=>(0,J.jsxs)("div",{className:"truncate font-mono",title:z.detail,children:[z.action," ",z.uri,": ",z.outcome==="changed"?"changed since the preview (409)":z.outcome==="needs-ack"?"needs confirmation \u2014 opened in the review dialog":z.detail??"refused"]},z.id))]}):null,(0,J.jsx)("div",{ref:N,className:"flex-1 min-h-0 overflow-auto overlay-scroll px-2 py-2",style:{overflowAnchor:"none"},children:vn&&ze.length===0?(0,J.jsxs)("div",{className:"flex items-center gap-2 px-3 py-6 text-xs text-white/40",children:[(0,J.jsx)(We,{className:"w-3.5 h-3.5 animate-spin"})," Loading\u2026"]}):ze.length===0?(0,J.jsx)("div",{className:"px-3 py-8 text-center text-xs text-white/35",children:"No pending review changes."}):(0,J.jsx)("div",{style:{height:Yn.getTotalSize(),width:"100%",position:"relative"},children:Yn.getVirtualItems().map(z=>{let ne=ze[z.index];return ne?(0,J.jsx)("div",{"data-index":z.index,ref:BI(ne.kind)?Yn.measureElement:void 0,className:ne.kind==="pending-row"?"":"pb-1.5",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${z.start}px)`},children:Zr(ne)},z.key):null})})})]})}var _E=(n,e,t)=>n.end<=(t.scrollOffset??0);var K=j(le(),1),HE=2e5,UE=2500,GE=12e3;function ZI(n,e){let t=String(n||"").trim().replace(/\\/g,"/");if(!t)return e;if(t.includes("://")){let s=t.indexOf("://"),o=t.slice(0,s),i=t.slice(s+3).replace(/\/+/g,"/").replace(/^\/+/,"");return`${o}://${i}`}let r=or(e),a=t.replace(/\/+/g,"/").replace(/^\/+/,"");return a?`${r}${a}`:e}function f0(){let n=_(B=>B.openFiles),e=_(B=>B.activeFile),t=_(B=>B.files),r=_(B=>B.fileContentByPath),a=_(B=>B.fileBaseContentByPath),s=_(B=>B.fileErrorByPath),o=_(B=>B.openFile),i=_(B=>B.patchFileNode),l=_(B=>B.saveFileInPlace),u=_(B=>B.markFileDeleted),c=_(B=>B.clearFilePrev),d=_(B=>B.refresh),f=_(B=>B.activeProjectId),h=_(B=>B.workspacePanels),p=_(B=>B.setWorkspacePanelOpen),m=_(B=>B.activeWorkspaceTab),g=_(B=>B.setActiveWorkspaceTab),x=_(B=>B.gitDiffTarget),b=_(B=>B.setGitDiffTarget),y=_(B=>B.gitCommitTarget),N=_(B=>B.setGitCommitTarget),L=_(B=>B.diffViewMode),A=_(B=>B.activeAgentId),w=fn(),v=w.useAgents(),T=(0,wt.useMemo)(()=>Ts(v),[v]),P=A?T.byId.get(A)??null:null,O=w.MarkdownRenderer,C=e?t[e]:null,I=e?r[e]??"":"",H=C?.uri??"",q=C?zE(H):!1,$=C?WE(H):!1,S=C?jE(H):!1,M=C?qE(H):!1,W=C?$E(H):!1,ee=C?ad(H):void 0,te=C?VE(H):"Binary file",re=q,[ce,oe]=(0,wt.useState)(!1),[ue,ie]=(0,wt.useState)(""),[Re,De]=(0,wt.useState)(""),[Ye,$e]=(0,wt.useState)(!1),[Pt,Xe]=(0,wt.useState)(null),[lt,Nt]=(0,wt.useState)(!1),[ot,Me]=(0,wt.useState)(!1),[tt,pt]=(0,wt.useState)(!1),[Rt,kt]=(0,wt.useState)(!1),[Ee,xe]=(0,wt.useState)(!0),[Dt,en]=(0,wt.useState)(!1),he=_(B=>B.filePrevByPath),pe=e?he[e]:void 0,je=!!pe&&C?.status==="pending_review",Pe=!!pe,Ce=(0,wt.useMemo)(()=>C?C.sourceAgentId?T.byId.get(C.sourceAgentId)??null:P:null,[C,T,P]),ln=e?s[e]:void 0,mt=!!e&&!hc({fileBaseContentByPath:a,fileErrorByPath:s},e),Ht=ln?`Read failed: ${ln}`:mt?"Loading\u2026":"Empty file",Ge=C?.status==="deleted",Wt=h.upload&&m==="upload",tn=h.sources&&m==="sources",Be=h.packages&&m==="packages",Y=h.pending&&m==="pending",Ie=m==="git-diff"&&!!x,_e=m==="git-commit"&&!!y,ze=!Wt&&!tn&&!Be&&!Y&&!Ie&&!_e,Te=C?.sourceAgentId??A??void 0,de=C?.sourceAgentId??A??null,ut=(0,wt.useMemo)(()=>!C?.uri||!Te?null:cx(Te,C.uri,f??void 0),[C?.uri,Te,f]),Ft=(0,wt.useRef)(null),nn=(0,wt.useRef)(null),$n=od(nn),ar=L==="auto"?$n?"split":"unified":L,[xr,Kn]=(0,wt.useState)(void 0),Xn=C?.git;(0,wt.useEffect)(()=>{let B=!1;if(!de||!H||!Xn||$||S||M){Kn(void 0);return}let me=qe(H),E=H.indexOf("://"),ye=E>=0?H.slice(E+3):"";if(!me||!ye){Kn(void 0);return}return(async()=>{try{let jt=await oc({agentId:de,...f?{projectId:f}:{},source:me,path:ye,staged:!1});if(B)return;if(jt&&jt.ok===!1){Kn(void 0);return}let Ut=typeof jt?.diff=="string"?jt.diff:"",gn=O1(Ut);Kn(dd(gn)?void 0:gn)}catch{B||Kn(void 0)}})(),()=>{B=!0}},[de,f,H,Xn,$,S,M]);let Yn=ho(C?.version?.changedAt),xa=C?.version?.sync,yr=!0,Jn=!!C&&ce&&(Re!==I||ZI(ue,C.uri)!==C.uri),dn=C?.version?.diff,Rn=!!dn&&(dn.added>0||dn.removed>0),rn=!!C&&Lp(C),Dr=(0,wt.useMemo)(()=>{if(!C)return"/";if(C.parentUri&&C.parentUri!==C.uri)return C.parentUri;let B=nt(C.uri);return B===C.uri?or(C.uri):B},[C]),Zn=(0,wt.useMemo)(()=>KE(I),[I]),Fr=C?.readSource==="live",sr=!!C&&!ce&&!$&&!S&&(W||Zn.charCount>=HE||Zn.lineCount>=UE||Fr&&Zn.charCount>=GE),_n=(0,wt.useCallback)(async()=>{if(!(!de||!C||lt)){Nt(!0),Xe(null);try{await u({agentId:de,projectId:f??null,node:C})}catch(B){console.error("[Filesystem] delete failed",B),Xe(B instanceof Error?B.message:"Delete failed")}finally{Nt(!1)}}},[de,C,lt,f,u]),Zr=(0,wt.useCallback)(async()=>{if(!(!de||!C||ot)){Me(!0);try{let B=await Sr({agentId:de,...f?{projectId:f}:{},id:C.id,uri:C.uri,fields:{status:"active"}});if(B&&B.ok===!1){Xe(ya(B,"Restore failed"));return}d({agentId:de,projectId:f??null}),o({agentId:de,projectId:f??null,uri:C.uri,readAgentId:Ce?.id,force:!0})}catch(B){console.error("[Filesystem] restore failed",B)}finally{Me(!1)}}},[de,C,ot,f,d,o,Ce?.id]),br=(0,wt.useCallback)(async()=>{if(!(!de||!C||tt)){if(C.status==="pending_review"){p("pending",!0),g("pending");return}pt(!0);try{let B=await cc({agentId:de,...f?{projectId:f}:{},id:C.id,uri:C.uri});if(B&&B.ok){let me=C.storeKey||e||Va(C);me&&(i(me,{status:"active"}),c(me)),o({agentId:de,projectId:f??null,uri:C.uri,readAgentId:Ce?.id,force:!0})}}catch(B){console.error("[Filesystem] approve failed",B)}finally{pt(!1)}}},[de,C,tt,f,o,Ce?.id,e,i,c]),vn=(0,wt.useCallback)(async()=>{if(!(!de||!C||Rt)){if(C.status==="pending_review"){p("pending",!0),g("pending");return}kt(!0);try{let B=await Sr({agentId:de,...f?{projectId:f}:{},id:C.id,uri:C.uri,revert:!0});if(B&&B.ok===!1){Xe(ya(B,"Revert failed"));return}if(B&&B.ok){let me=C.storeKey||e||Va(C);me&&(i(me,{status:pe?.status||"active"}),c(me)),o({agentId:de,projectId:f??null,uri:C.uri,readAgentId:Ce?.id,force:!0})}}catch(B){console.error("[Filesystem] revert failed",B)}finally{kt(!1)}}},[de,C,Rt,f,o,Ce?.id,e,pe,i,c]);(0,wt.useEffect)(()=>{if(!C){Ft.current=null,oe(!1),en(!1),ie(""),De(""),Xe(null);return}let B=C.storeKey||e||Va(C),me=Ft.current!==B;if(Ft.current=B,me){oe(!1),en(!1),xe(!0),ie(C.uri),De(I),Xe(null);return}ce||(ie(C.uri),De(I),Xe(null))},[C?.storeKey,C?.uri,I,e,ce]);let z=(0,wt.useCallback)(()=>{rn&&en(B=>!B)},[rn]),ne=(0,wt.useCallback)(()=>{!C||Ge||(ie(C.uri),De(I),Xe(null),oe(!0))},[C,I,Ge]),R=(0,wt.useCallback)(()=>{C&&(ie(C.uri),De(I),Xe(null),oe(!1))},[C,I]),X=(0,wt.useCallback)(async()=>{if(!C||!de||Ye)return;let B=C.uri,me=ZI(ue,B);if(!me){Xe("Invalid target URI");return}$e(!0),Xe(null);try{await l({agentId:de,projectId:f??null,readAgentId:Ce?.id,node:C,targetUri:me,content:Re,currentContent:I}),xe(!0),oe(!1)}catch(E){Xe(E instanceof Error?E.message:"Save failed")}finally{$e(!1)}},[C,de,Ye,ue,Re,I,f,Ce?.id,l]);return(0,K.jsxs)("div",{className:"h-full w-full flex flex-col min-w-0 min-h-0",children:[n.length>0||h.upload||yr&&h.sources||h.packages||h.pending||x||y?(0,K.jsxs)("div",{className:"flex shrink-0 items-stretch",style:{backgroundColor:"transparent",borderBottom:"1px solid rgba(255,255,255,0.05)"},children:[(0,K.jsxs)("div",{[fd]:"",className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:[(0,K.jsx)(H1,{}),h.upload?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Wt?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("upload"),children:[(0,K.jsx)(Ia,{className:"w-3.5 h-3.5 shrink-0"}),(0,K.jsx)("span",{className:"truncate flex-1",children:"Upload"}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),p("upload",!1)},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null,yr&&h.sources?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",tn?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("sources"),children:[(0,K.jsx)(uo,{className:"w-3.5 h-3.5 shrink-0"}),(0,K.jsx)("span",{className:"truncate flex-1",children:"Sources"}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),p("sources",!1)},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null,h.packages?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Be?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("packages"),children:[(0,K.jsx)(Lr,{className:"w-3.5 h-3.5 shrink-0"}),(0,K.jsx)("span",{className:"truncate flex-1",children:"Packages"}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),p("packages",!1)},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null,h.pending?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Y?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("pending"),children:[(0,K.jsx)(Xa,{className:"w-3.5 h-3.5 shrink-0"}),(0,K.jsx)("span",{className:"truncate flex-1",children:"Changes"}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),p("pending",!1)},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null,x?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",Ie?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-diff"),title:`Diff: ${yo(x.repo,x.path)} (${n1(x)})`,children:[(0,K.jsx)(lr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}),(0,K.jsx)("span",{className:"truncate flex-1",children:yo(x.repo,yt(x.path)||x.path)}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),b(null),Ie&&g("file")},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null,y?(0,K.jsxs)("button",{type:"button",className:V("group flex items-center gap-1.5 px-3 py-2 text-xs min-w-[120px] max-w-[240px] rounded-lg",_e?"bg-white/10 text-white":"text-white/50 hover:bg-white/5 hover:text-white/80"),onClick:()=>g("git-commit"),title:y.kind==="commit"?yo(y.repo,`Commit ${Zt(y.sha)}: ${y.subject}`):yo(y.repo,`Outgoing changes (${Zt(y.base)}..${Zt(y.head)})`),children:[y.kind==="commit"?(0,K.jsx)(Hr,{className:"w-3.5 h-3.5 shrink-0 text-violet-300/80"}):(0,K.jsx)(Br,{className:"w-3.5 h-3.5 shrink-0 text-blue-300/80"}),(0,K.jsx)("span",{className:"truncate flex-1",children:y.kind==="commit"?yo(y.repo,`${Zt(y.sha)} ${y.subject}`):yo(y.repo,"Outgoing changes")}),(0,K.jsx)("span",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-white/10",onClick:B=>{B.stopPropagation(),N(null)},children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):null]}),(0,K.jsx)(U1,{})]}):null,ze&&C?(0,K.jsxs)("div",{className:"flex items-center justify-between gap-2 px-2 py-1.5 text-[11px]",style:{backgroundColor:"transparent",borderBottom:!Dt||!rn?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,K.jsxs)("div",{className:V("min-w-0 flex-1 flex items-center gap-2 rounded-lg px-1.5 py-1 transition",rn?"cursor-pointer hover:bg-white/[0.04]":""),role:rn?"button":void 0,tabIndex:rn?0:void 0,"aria-expanded":rn?Dt:void 0,onClick:z,onKeyDown:B=>{rn&&(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),z())},children:[Rn?(0,K.jsxs)("span",{className:V("inline-flex shrink-0 items-center gap-1 rounded-full border px-2 py-1 text-[10px]",Yn.pillClassName),children:[(0,K.jsx)(lr,{className:V("w-3 h-3",Yn.iconClassName)}),(0,K.jsxs)("span",{className:"text-emerald-200/95",children:["+",dn.added]}),(0,K.jsx)("span",{className:"text-white/25",children:"/"}),(0,K.jsxs)("span",{className:"text-rose-200/95",children:["-",dn.removed]})]}):null,(0,K.jsxs)("div",{className:"min-w-0 flex-1",children:[ce?(0,K.jsx)("input",{value:ue,onChange:B=>ie(B.target.value),onClick:B=>B.stopPropagation(),onKeyDown:B=>B.stopPropagation(),className:"h-7 w-full rounded-md bg-white/[0.04] border border-white/[0.12] px-2 text-[11px] font-mono text-white/85 outline-none focus:border-white/[0.2]",disabled:Ye}):(0,K.jsxs)("div",{className:"min-w-0 flex items-center gap-2",title:`${qe(C.uri)} \xB7 ${C.uri}`,children:[(0,K.jsx)("span",{className:V("shrink-0 text-white/88 font-medium",C.status==="deleted"?"line-through text-red-200/70":""),children:C.name}),(0,K.jsx)("span",{className:"truncate font-mono text-white/42",children:Dr})]}),ln?(0,K.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:ln,children:"Read failed"}):null,Pt?(0,K.jsx)("div",{className:"text-[10px] text-red-300/80 truncate",title:Pt,children:Pt}):null]}),rn?(0,K.jsx)(Tt,{className:V("w-3.5 h-3.5 shrink-0 text-white/35 transition-transform",Dt&&"rotate-180")}):null]}),(0,K.jsxs)("div",{className:"flex items-center gap-2",children:[ce?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-emerald-500/15 border border-emerald-500/25 p-1.5 text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:X,disabled:Ye||!de,"aria-label":"Save changes",children:Ye?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,K.jsx)(Mn,{className:"w-3 h-3"})}),(0,K.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/70 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:R,disabled:Ye,"aria-label":"Cancel edit",children:(0,K.jsx)(Bt,{className:"w-3 h-3"})})]}):(0,K.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:ne,disabled:!de||Ge||M,title:M?"Binary files cannot be edited in-place":"Edit in-place","aria-label":"Edit in-place",children:(0,K.jsx)(so,{className:"w-3 h-3"})}),(0,K.jsx)("button",{type:"button",className:V("inline-flex items-center justify-center rounded-md p-1.5 transition","border border-red-500/15 bg-red-500/10 text-red-300/70 hover:text-red-200 hover:bg-red-500/15","disabled:opacity-40 disabled:cursor-not-allowed"),onClick:_n,disabled:!de||lt||ot,title:"Mark as deleted","aria-label":"Mark as deleted",children:lt?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,K.jsx)(It,{className:"w-3 h-3"})}),(0,K.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:()=>{!de||!C||o({agentId:de,projectId:f??null,uri:C.uri,readAgentId:Ce?.id,force:!0})},title:"Reload file","aria-label":"Reload file",children:(0,K.jsx)(Ot,{className:"w-3 h-3"})}),!ce&&Pe&&C?.status!=="pending_review"?(0,K.jsx)("button",{type:"button",className:"inline-flex items-center justify-center rounded-md bg-white/5 p-1.5 text-white/60 hover:text-white/80 hover:bg-white/10 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:vn,disabled:Rt||tt||!de,title:"Undo to previous version","aria-label":"Undo to previous version",children:Rt?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,K.jsx)(La,{className:"w-3 h-3"})}):null]})]}):null,ze&&C&&Dt&&rn?(0,K.jsx)(Cp,{node:C,hideVersionDiff:!0}):null,ze&&C&&Jn?(0,K.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(56,189,248,0.08) 0%, rgba(56,189,248,0.02) 100%)",borderBottom:"1px solid rgba(56,189,248,0.16)"},children:[(0,K.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-sky-100/85",children:[(0,K.jsx)(Ya,{className:"w-3.5 h-3.5 text-sky-300/75"}),(0,K.jsx)("span",{children:"Local draft in progress"})]}),(0,K.jsx)("div",{className:"text-[10px] text-sky-100/55",children:"Save or cancel to resolve the draft state"})]}):null,ze&&C&&je&&!ce?(0,K.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.08) 0%, rgba(244,63,94,0.03) 100%)",borderBottom:"1px solid rgba(251,191,36,0.18)"},children:[(0,K.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-200/80",children:[(0,K.jsx)(lr,{className:"w-3.5 h-3.5 text-amber-400/70"}),(0,K.jsx)("span",{children:"Pending changes \u2014 review and approve or revert"})]}),(0,K.jsxs)("div",{className:"flex items-center gap-2",children:[(0,K.jsxs)("button",{type:"button",className:V("inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] transition",Ee?"bg-amber-500/15 border border-amber-500/25 text-amber-100":"bg-white/5 text-white/50 hover:bg-white/10 hover:text-white/70"),onClick:()=>xe(!Ee),children:[(0,K.jsx)(lr,{className:"w-3 h-3"}),"Diff"]}),Ee?(0,K.jsx)(ld,{}):null,(0,K.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/15 border border-emerald-500/25 px-2 py-1 text-[11px] text-emerald-100 hover:bg-emerald-500/20 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:br,disabled:tt||Rt||!de,title:"Accept current state",children:[tt?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,K.jsx)(Mn,{className:"w-3 h-3"}),"Approve"]}),(0,K.jsxs)("button",{type:"button",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 border border-red-500/20 px-2 py-1 text-[11px] text-red-200/80 hover:bg-red-500/15 transition disabled:opacity-40 disabled:cursor-not-allowed",onClick:vn,disabled:tt||Rt||!de,title:"Revert to previous version",children:[Rt?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin"}):(0,K.jsx)(La,{className:"w-3 h-3"}),"Revert"]})]})]}):null,ze&&C&&!ce&&C.presence==="stale_indexed"?(0,K.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(244,114,182,0.08) 0%, rgba(251,191,36,0.03) 100%)",borderBottom:"1px solid rgba(244,114,182,0.15)"},children:[(0,K.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-rose-100/85",children:[(0,K.jsx)(Ja,{className:"w-3.5 h-3.5 text-rose-300/75"}),(0,K.jsx)("span",{children:"This indexed node is missing from the live source"})]}),(0,K.jsx)("div",{className:"text-[10px] text-rose-100/55",children:"Useful for spotting sync drift"})]}):null,ze&&C&&!ce&&C.presence==="unindexed"?(0,K.jsx)("div",{className:"flex items-center justify-between gap-3 px-2 py-2",style:{background:"linear-gradient(90deg, rgba(251,191,36,0.07) 0%, rgba(255,255,255,0.02) 100%)",borderBottom:"1px solid rgba(251,191,36,0.15)"},children:(0,K.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-amber-100/82",children:[(0,K.jsx)(ct,{className:"w-3.5 h-3.5 text-amber-300/75"}),(0,K.jsx)("span",{children:"Unindexed \u2014 file exists on the connector but is not yet vector-indexed"})]})}):null,(0,K.jsxs)("div",{ref:nn,className:"flex-1 min-h-0 relative",children:[Wt&&A?(0,K.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,K.jsx)(Vg,{agentId:A,projectId:f??null})}):null,yr&&tn&&A?(0,K.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,K.jsx)(fI,{agentId:A,projectId:f??null,isDocker:w.isDocker})}):null,Be&&f?(0,K.jsx)("div",{className:"w-full h-full overflow-y-auto",children:(0,K.jsx)(wI,{projectId:f})}):null,Y&&A?(0,K.jsx)("div",{className:"w-full h-full min-h-0",children:(0,K.jsx)(JI,{agentId:A,projectId:f??null})}):null,Ie&&x?(0,K.jsx)("div",{className:"w-full h-full min-h-0",children:(0,K.jsx)(jg,{target:x,agentId:A,projectId:f??null})}):null,_e&&y?(0,K.jsx)("div",{className:"w-full h-full min-h-0",children:(0,K.jsx)(fp,{target:y,agentId:A,projectId:f??null})}):null,ze&&Ge?(0,K.jsxs)("div",{className:"absolute inset-x-4 top-4 z-10 rounded-xl border border-red-500/25 bg-black/70 p-3 backdrop-blur-sm",children:[(0,K.jsx)("div",{className:"text-[11px] text-red-200/85 mb-2",children:"This file is marked as deleted."}),(0,K.jsxs)("div",{className:"flex items-center gap-2",children:[(0,K.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-emerald-500/30 bg-emerald-500/15 text-emerald-100 hover:bg-emerald-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Zr,disabled:!de||ot||lt,children:[ot?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Restore"]}),(0,K.jsxs)("button",{type:"button",className:"h-8 px-3 rounded-lg text-xs font-semibold border border-red-500/30 bg-red-500/15 text-red-100 hover:bg-red-500/20 disabled:opacity-50 disabled:cursor-not-allowed",onClick:_n,disabled:!de||lt||ot,children:[lt?(0,K.jsx)(We,{className:"w-3 h-3 animate-spin inline mr-1"}):null,"Delete"]})]})]}):null,ze&&C?je&&Ee&&pe&&!ce?(0,K.jsx)(Fg,{oldContent:pe.content,newContent:I,language:ee,viewMode:ar,className:"w-full h-full min-h-0"}):M&&!$&&!S&&!ce?(0,K.jsx)("div",{className:V("w-full h-full min-h-0 flex items-center justify-center px-6 text-center",Ge&&"blur-[2px] opacity-65"),children:(0,K.jsxs)("div",{className:"max-w-md rounded-2xl border border-white/10 bg-white/[0.035] px-5 py-4 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65)]",children:[(0,K.jsx)(ct,{className:"w-6 h-6 mx-auto mb-3 text-amber-300/75"}),(0,K.jsxs)("div",{className:"text-sm font-semibold text-white/82",children:[te," preview disabled"]}),(0,K.jsx)("div",{className:"mt-2 text-xs leading-5 text-white/45",children:"This file is treated as binary, so Neuralis will not decode it into the text editor."})]})}):$&&ut&&!ce?(0,K.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,K.jsxs)("div",{className:V(Ge&&"blur-[2px] opacity-65"),children:[(0,K.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Image preview"}),(0,K.jsx)("img",{src:ut,alt:C.name,className:"max-w-full max-h-[calc(100vh-220px)] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):S&&ut&&!ce?(0,K.jsx)("div",{className:"w-full h-full min-h-0 overflow-auto px-2 py-1.5",children:(0,K.jsxs)("div",{className:V(Ge&&"blur-[2px] opacity-65"),children:[(0,K.jsx)("div",{className:"text-[11px] text-white/45 mb-3",children:"Video preview"}),(0,K.jsx)("video",{src:ut,controls:!0,className:"w-full max-w-[1100px] rounded-xl bg-black/20 shadow-[0_18px_46px_-26px_rgba(0,0,0,0.65),inset_0_1px_0_rgba(255,255,255,0.06)]"})]})}):q&&O&&!sr&&!ce?(0,K.jsx)("div",{className:V("w-full h-full min-h-0 overflow-auto px-1 py-1 text-white/80",Ge&&"blur-[2px] opacity-65"),children:I?(0,K.jsx)("div",{className:"min-h-full min-w-0",children:(0,K.jsx)(O,{content:I})}):(0,K.jsx)("div",{className:"px-2 py-1.5 text-sm text-white/30",children:Ht})}):(0,K.jsx)(Wg,{value:ce?Re:I,language:ee,readOnly:!ce||Ge||Ye,wrap:re,onChange:ce?De:void 0,className:V("w-full h-full min-h-0",Ge&&"opacity-65"),placeholder:Ht,ariaLabel:ce?"File content editor":"File content viewer",gitLineStatus:xr}):ze?(0,K.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-white/20",children:[(0,K.jsx)(kl,{className:"w-12 h-12 mb-2 opacity-50"}),(0,K.jsx)("div",{className:"text-sm",children:Wt?"Upload files using this tab":"No file open"})]}):null,ze&&C?(0,K.jsxs)("div",{className:"pointer-events-none absolute bottom-2 right-3 z-10 text-[10px] text-white/42",children:[(0,K.jsxs)("span",{children:[Zn.lineCount.toLocaleString()," lines"]}),(0,K.jsxs)("span",{className:"ml-3",children:[Zn.charCount.toLocaleString()," chars"]})]}):null]})]})}function zE(n){let e=yt(n).toLowerCase();return e.endsWith(".md")||e.endsWith(".mdx")||e.endsWith(".markdown")}function WE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".png")||e.endsWith(".jpg")||e.endsWith(".jpeg")||e.endsWith(".webp")||e.endsWith(".gif")}function jE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".mp4")||e.endsWith(".webm")||e.endsWith(".mov")||e.endsWith(".m4v")}function qE(n){let e=yt(String(n||"")).toLowerCase();return/\.(wasm|png|jpe?g|gif|webp|ico|bmp|mp4|webm|avi|mov|m4v|mkv|mp3|wav|ogg|flac|aac|zip|tar|gz|bz2|7z|rar|pdf|docx?|xlsx?|pptx?|exe|dll|so|dylib|ttf|otf|woff2?|eot)$/.test(e)}function VE(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".wasm")?"WebAssembly binary":e.endsWith(".pdf")?"PDF":"Binary file"}function $E(n){let e=yt(String(n||"")).toLowerCase();return e.endsWith(".jsonl")||e.endsWith(".ndjson")||e.endsWith(".log")}function KE(n){if(!n)return{charCount:0,lineCount:0};let e=1;for(let t=0;t<n.length;t++)n.charCodeAt(t)===10&&(e+=1);return{charCount:n.length,lineCount:e}}var fs="brain://project-info",T$=[{kind:"docs",label:"Upload Docs",folderUri:`${fs}/docs`,accept:".md,.txt,.pdf,.doc,.docx"},{kind:"requirements",label:"Upload Requirements",folderUri:`${fs}/requirements`,accept:".md,.txt,.pdf"},{kind:"architecture",label:"Upload Architecture",folderUri:`${fs}/architecture`,accept:".md,.txt,.pdf,.drawio,.json,.yaml,.yml"},{kind:"design",label:"Upload Design",folderUri:`${fs}/design`,accept:".md,.txt,.pdf,.fig,.png,.jpg,.jpeg,.webp"},{kind:"assets",label:"Upload Assets",folderUri:`${fs}/assets`,accept:".png,.jpg,.jpeg,.webp,.svg,.gif"},{kind:"datasets",label:"Upload Datasets",folderUri:`${fs}/datasets`,accept:".csv,.json,.jsonl,.parquet,.txt,.zip"},{kind:"other",label:"Upload File",folderUri:`${fs}/misc`}];var cn=j(Ve(),1);var QI=250,XE=1e3,YE=2e3,JE=6e3,ZE=1e3,QE=5e3,eO=["filesystem:created","filesystem:updated","filesystem:deleted","filesystem:reverted","sync:completed","pending:changed"],tO=new Set(eO),nO=["filesAdded","filesUpdated","filesRemoved","filesMoved","chunksRemoved"];function rO(n){return n.mode==="purge"?!1:nO.every(e=>n[e]===0)}function e2(n,e){let t=_(I=>I.refreshTree),r=_(I=>I.refresh),a=_(I=>I.ensureFolderLoaded),s=_(I=>I.reconcileSourceFolders),o=_(I=>I.reconcileFolders),i=_(I=>I.setSourceDirty),l=_(I=>I.upsertFileNodeFromEvent),u=_(I=>I.incrementFolderBadges),c=_(I=>I.replaceFilePath),d=_(I=>I.clearFilePrev),f=_(I=>I.autoExpandToFile),h=_(I=>I.loadGitStatus),p=_(I=>I.notifyGitLogChanged),m=_(I=>I.refreshPendingCount),g=(0,cn.useRef)(0),x=(0,cn.useRef)(new Map),b=(0,cn.useRef)(new Map),y=(0,cn.useRef)(new Map);(0,cn.useEffect)(()=>{let I=x.current,H=y.current;return()=>{for(let q of I.values())clearTimeout(q);I.clear();for(let q of H.values())clearTimeout(q);H.clear()}},[n,e]),(0,cn.useEffect)(()=>{let I=b.current;return()=>{g.current+=1;for(let H of I.values())clearTimeout(H.timer);I.clear()}},[n,e]);let N=(0,cn.useRef)(null),L=(0,cn.useCallback)(()=>{if(!n||!e)return;let I=Date.now(),H=N.current,q=H?H.deadline:I+QE;H&&clearTimeout(H.timer);let $=setTimeout(()=>{N.current=null,!(typeof document<"u"&&document.visibilityState==="hidden")&&m({agentId:n,projectId:e})},Math.max(0,Math.min(ZE,q-I)));N.current={timer:$,deadline:q}},[n,e,m]),A=(0,cn.useRef)(L);A.current=L;let w=_(I=>I.activeAgentId===n&&I.activeProjectId===e);(0,cn.useEffect)(()=>{n&&e&&w&&m({agentId:n,projectId:e})},[n,e,w,m]),(0,cn.useEffect)(()=>{if(!n||!e)return;let I=()=>{document.visibilityState!=="hidden"&&A.current()},H=()=>A.current();return document.addEventListener("visibilitychange",I),window.addEventListener("focus",H),()=>{document.removeEventListener("visibilitychange",I),window.removeEventListener("focus",H),N.current&&clearTimeout(N.current.timer),N.current=null}},[n,e,m]);let v=(0,cn.useCallback)(I=>{let{type:H,payload:q}=I,$=oe=>{if(!n||!oe)return;let ue=_.getState().activeSource,ie=typeof ue=="string"&&ue?ue.includes("://")?qe(ue):ue:"",Re=y.current,De=Re.get(oe);De&&clearTimeout(De),Re.set(oe,setTimeout(()=>{Re.delete(oe),_.setState(Ye=>({sourceChangeRevision:{...Ye.sourceChangeRevision,[oe]:(Ye.sourceChangeRevision[oe]??0)+1}})),ie===oe&&h({agentId:n,projectId:e,source:oe})},QI))},S=oe=>{if(!n)return;let ue=b.current,ie=Date.now(),Re=ue.get(oe),De=Re?Re.deadline:ie+JE;Re&&clearTimeout(Re.timer);let Ye=setTimeout(()=>{ue.delete(oe),s({agentId:n,projectId:e,source:oe})},Math.max(0,Math.min(YE,De-ie)));ue.set(oe,{timer:Ye,deadline:De})};if(H==="sync:completed"){if(!n)return;let oe=typeof q.source=="string"?q.source:void 0;if(oe&&rO(q)){$(oe);return}oe?(_.getState().loadedFolders?.[`${oe}://`]?S(oe):i(oe,!0),$(oe)):t({agentId:n,projectId:e});return}if(q.changeType==="badge"){if(!n)return;let oe=_.getState().activeAgentId;if(oe&&oe!==n)return;let ue=typeof q.source=="string"&&q.source?q.source:qe(typeof q.uri=="string"?q.uri:"");if(!ue)return;let ie=x.current,Re=ie.get(ue);Re&&clearTimeout(Re),ie.set(ue,setTimeout(()=>{ie.delete(ue),_.setState($e=>({sourceChangeRevision:{...$e.sourceChangeRevision,[ue]:($e.sourceChangeRevision[ue]??0)+1}})),a({agentId:n,projectId:e,uri:`${ue}://`,force:!0}),r({agentId:n,projectId:e});let De=_.getState().activeSource;(typeof De=="string"&&De?De.includes("://")?qe(De):De:"")===ue&&h({agentId:n,projectId:e,source:ue}),p(ue)},QI));return}if(q.external===!0){if(!n)return;let oe=_.getState().activeAgentId;if(oe&&oe!==n)return;let ue=typeof q.source=="string"&&q.source?q.source:qe(typeof q.uri=="string"?q.uri:"");if(!ue)return;if($(ue),!_.getState().loadedFolders?.[`${ue}://`]){i(ue,!0);return}S(ue);return}let M=q.uri;if(!M)return;let W=q.changeType,ee=Array.isArray(q.folder_ancestors)&&q.folder_ancestors.length>0?q.folder_ancestors:ba(M);ee.length>0&&u(ee),Array.isArray(q.new_folder_ancestors)&&q.new_folder_ancestors.length>0&&u(q.new_folder_ancestors);let te=typeof q.action=="string"?q.action:void 0,re={id:q.id,uri:M,folder_ancestors:ee,sourceAgentId:I.agentId,sourceProjectId:I.projectId},ce=oe=>{if(!n)return;let ue=Array.from(new Set(oe.filter(ie=>typeof ie=="string"&&!!ie).map(ie=>nt(ie))));ue.length>0&&o({agentId:n,projectId:e,folders:ue})};switch(H){case"filesystem:created":case"filesystem:updated":l({...re,status:q.status}),q.status==="pending_review"&&f(M),q.newUri&&(c(M,q.newUri),l({...re,uri:q.newUri,folder_ancestors:q.new_folder_ancestors,status:q.status})),te==="review_approved"&&q.status==="active"&&d(M),W==="structure"&&ce([M,q.newUri]);break;case"filesystem:deleted":l({...re,status:"deleted"}),W==="structure"&&ce([M]);break;case"filesystem:reverted":l({...re,status:q.status||"active"}),d(M),ce([M]);break}$(qe(M))},[n,e,t,r,a,s,o,i,l,u,c,d,f,h,p]),T=(0,cn.useRef)(v);T.current=v;let P=(0,cn.useRef)(null),O=(0,cn.useCallback)(()=>{if(!n)return;let I=g.current;P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null,I===g.current&&(async()=>{try{await r({agentId:n,projectId:e})}catch{return}if(I!==g.current)return;A.current();let H=_.getState();_.setState($=>({sourceChangeRevision:Object.fromEntries($.sources.map(S=>[qe(S.uri_root),($.sourceChangeRevision[qe(S.uri_root)]??0)+1]))}));let q=new Set;for(let[$,S]of Object.entries(H.loadedFolders||{})){if(!S)continue;let M=qe($);M&&q.add(M)}await Promise.all(Array.from(q).map($=>s({agentId:n,projectId:e,source:$})))})()},XE)},[n,e,r,s]),C=(0,cn.useRef)(O);C.current=O,(0,cn.useEffect)(()=>{let I=P;return()=>{I.current&&clearTimeout(I.current)}},[n,e]),(0,cn.useEffect)(()=>{if(!n||!e)return;let I=nw();if(I?.subscribeFilesystemEvents)return I.subscribeFilesystemEvents(n,e,H=>{let q=H;if(!q||typeof q!="object"||!tO.has(q.type)||!q.payload||typeof q.payload!="object")return;if(q.type==="pending:changed"){A.current();return}let $=q.payload.changeType==="badge",S=q.payload.external===!0;!$&&!S&&q.agentId!==n||T.current(q)},()=>C.current())},[n,e])}var Uf=j(wr(),1);var wn=j(le(),1);function h0(n){let e=_(M=>M.sidebarOpen),t=_(M=>M.sidebarWidth),r=_(M=>M.setSidebarWidth),a=_(M=>M.loadList),s=_(M=>M.refreshTree),o=_(M=>M.applyNav),i=_(M=>M.searchQuery),l=_(M=>M.setSearchQuery),u=_(M=>M.clearSearch),c=_(M=>M.sidebarView),d=_(M=>M.setSidebarView),f=(0,Nn.useRef)(null),h=(0,Nn.useRef)(null),p=(0,Nn.useRef)(null),[m,g]=(0,Nn.useState)(!1),x=fn(),b=(0,Uf.useWorkspaceHostPort)(),y=_(M=>M.activeProjectId),N=n.projectId??y,L=x.useFileMarks(n.agentId),A=x.useAgents(),w=(0,Nn.useMemo)(()=>Ts(A),[A]),v=n.agentId?w.byId.get(n.agentId):null,T=v?.name||v?.slug,P=v?.config?.appearance?.icon,O=ci(v?.id,w),C=(0,Nn.useMemo)(()=>{let M=L||{},W=0;for(let ee of Object.keys(M)){let te=M[ee]?.ts??0;te>W&&(W=te)}return W},[L]);e2(n.agentId,N),(0,Nn.useEffect)(()=>{n.agentId&&a({agentId:n.agentId,projectId:N,userId:n.userId??null})},[n.agentId,N,n.userId]),(0,Nn.useEffect)(()=>{if(!n.agentId)return;let M=n.state?.nav;if(!M)return;let W=JSON.stringify(M);f.current!==W&&(f.current=W,b&&n.widgetId&&(0,Uf.consumeWidgetNav)(b,{agentId:n.agentId,widgetId:n.widgetId}),o({agentId:n.agentId,projectId:N,nav:M,readAgentId:n.agentId}))},[o,n.agentId,N,n.state,b,n.widgetId]);let I=(0,Nn.useRef)(!1);(0,Nn.useEffect)(()=>{if(!n.agentId||!C||I.current)return;let M=setTimeout(()=>{I.current=!0,s({agentId:n.agentId,projectId:N}).finally(()=>{I.current=!1})},1500);return()=>clearTimeout(M)},[C,N,n.agentId,s]);let H=8,q=(0,Nn.useCallback)(M=>{M.preventDefault(),p.current={startX:M.clientX,startWidth:t},g(!0),M.currentTarget.setPointerCapture(M.pointerId)},[t]),$=(0,Nn.useCallback)(M=>{let W=p.current;if(!W)return;let ee=h.current,te=ee?Math.max(cl,ee.clientWidth-H):W.startWidth,re=Math.min(te,Math.max(cl,W.startWidth+(M.clientX-W.startX)));r(re)},[r]),S=(0,Nn.useCallback)(M=>{p.current&&(p.current=null,g(!1),M.currentTarget.releasePointerCapture(M.pointerId))},[]);return(0,wn.jsxs)("div",{className:"flex flex-col w-full h-full overflow-hidden transition-colors duration-300",children:[(0,wn.jsx)(wh,{agentId:n.agentId,agentName:T,agentIcon:P,agentAccent:O,supportsSources:!0,onOpenProjectFiles:()=>{o({agentId:n.agentId,projectId:N,nav:{kind:"filesystem",action:"list",uri:fs}})}}),(0,wn.jsxs)("div",{ref:h,className:`flex-1 min-h-0 flex flex-row ${m?"select-none cursor-col-resize":""}`,children:[(0,wn.jsxs)("div",{className:"h-full flex flex-col min-h-0 shrink-0 overflow-hidden",style:{width:e?t:0,backgroundColor:"transparent",borderRight:e?"1px solid rgba(255,255,255,0.05)":"none"},children:[(0,wn.jsxs)("div",{className:"px-2 pt-2 pb-1 flex items-center justify-between",children:[(0,wn.jsx)("div",{className:"text-[10px] text-white/40 font-bold uppercase tracking-wider shrink-0",children:c==="git"?"Git Control":c==="search"?"Search":"Explorer"}),c==="search"?(0,wn.jsx)("input",{type:"text",value:i,onChange:M=>l(M.target.value),onKeyDown:M=>{M.key==="Escape"&&(u(),d("tree"))},placeholder:"Search\u2026",autoFocus:!0,"aria-label":"Search query",className:"flex-1 min-w-0 mx-2 h-6 bg-transparent border-0 text-xs text-white/85 placeholder:text-white/30 outline-none"}):null,(0,wn.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,wn.jsx)("button",{type:"button",onClick:()=>{c==="search"?(u(),d("tree")):d("search")},className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="search"?"text-white/85":"text-white/40 hover:text-white/70"}`,title:"Search in explorer","aria-label":"Toggle explorer search","aria-pressed":c==="search",children:(0,wn.jsx)(El,{className:"w-3.5 h-3.5"})}),(0,wn.jsx)("button",{type:"button",onClick:()=>d(c==="git"?"tree":"git"),className:`h-6 w-6 rounded-md inline-flex items-center justify-center transition-colors ${c==="git"?"text-violet-300/90":"text-white/40 hover:text-white/70"}`,title:"Git Control","aria-label":"Toggle Git Control panel","aria-pressed":c==="git",children:(0,wn.jsx)(Sn,{className:"w-3.5 h-3.5"})})]})]}),(0,wn.jsx)(bp,{agentId:n.agentId,sidebarView:c})]}),e&&(0,wn.jsx)("div",{role:"separator","aria-orientation":"vertical",onPointerDown:q,onPointerMove:$,onPointerUp:S,className:"w-2 shrink-0 cursor-col-resize bg-white/0 hover:bg-white/[0.06] transition relative touch-none",children:(0,wn.jsx)("div",{className:"absolute inset-y-6 left-1/2 -translate-x-1/2 w-[2px] rounded-full bg-white/[0.07]"})}),(0,wn.jsx)("div",{className:"flex-1 min-w-0 min-h-0",children:(0,wn.jsx)(f0,{})})]})]})}var Vn=j(Ve(),1),Wf=j(ta(),1),sl=j(ta(),1),f2=j(r2(),1);var qo=j(Ve(),1);var Gf=j(ta(),1);var Ua=j(le(),1),aO=27,g0=90,sO=17,oO=12,iO=1.4,lO=18,m0=32,a2=new WeakMap;function s2(n,e){let t=a2.get(n);if(t&&t.status===e)return t;let r={status:e};return a2.set(n,r),r}function uO(n,e){let t=s2(n,e);if(t.compact!==void 0)return t.compact;let r=String(e??"").toLowerCase(),a=r==="pending"||r.includes("pending"),s;if(a)s=m0;else{let o=el(n.input),i=o&&typeof o.action=="string"?o.action:void 0;if(i&&!Qi(i))s=m0;else if(Qi(i))s=g0;else{let l=0;try{let u=o?Yu(o):null;l=u?u.added+u.removed:0}catch{l=0}s=l<=0?m0:Math.min(g0,l*lO)}}return t.compact=s,s}function cO(n,e){let t=s2(n,e);if(t.expanded!==void 0)return t.expanded;let r=el(n.input)??{},a=0;try{let o=Yu(r);a=o?o.added+o.removed:0}catch{a=0}let s=Math.max(g0,oO+Math.ceil(a*iO)*sO);return t.expanded=s,s}function o2(n){let e=n.disclosure===!0?cO(n.tool,n.status):uO(n.tool,n.status);return aO+e}var zf=(0,qo.memo)(function({uri:e,lineCounts:t,isPending:r,reviewPending:a,isError:s,isInterrupted:o,onUriClick:i,children:l}){let u=(0,qo.useMemo)(()=>r?"pending":o?"interrupted":s?"error":"committed",[r,s,o]),c=a&&u==="committed"?"pending review":u,d=(0,qo.useCallback)(()=>{e&&i&&i(e)},[e,i]),f=(0,qo.useCallback)(()=>(0,Ua.jsxs)("div",{className:`px-3 py-1 flex items-center gap-2 min-w-0 ${e&&i?"cursor-pointer hover:bg-white/[0.04] transition":""}`,onClick:d,role:e&&i?"button":void 0,title:e||void 0,children:[(0,Ua.jsx)(ka,{className:"w-3 h-3 text-white/40 shrink-0"}),(0,Ua.jsx)("span",{className:"flex-1 min-w-0 text-[11px] text-white/60 font-mono truncate",children:e||"file"}),t&&(0,Ua.jsxs)("span",{className:"shrink-0 flex items-center gap-1.5 text-[10px] font-mono",children:[t.added>0&&(0,Ua.jsxs)("span",{className:"text-emerald-400",children:["+",t.added]}),t.removed>0&&(0,Ua.jsxs)("span",{className:"text-red-400",children:["-",t.removed]})]}),(0,Ua.jsx)(Gf.ToolStatusIcon,{isPending:r,isError:s,isInterrupted:o,statusLabel:c})]}),[e,i,d,t,r,s,o,c]);return(0,Ua.jsx)(Gf.CardShell,{label:e||"file",status:u,defaultMode:"compact",compactHeight:90,renderHeader:f,children:l})});var l2=j(Ve(),1);var et=j(le(),1),u2=(0,l2.memo)(function({action:e,input:t}){switch(e){case"set_fields":return(0,et.jsx)(dO,{fields:t.fields});case"move":return(0,et.jsx)(fO,{uri:rl(t,"uri")||rl(t,"id"),destination:rl(t,"destination")});case"copy":return(0,et.jsx)(hO,{uri:rl(t,"uri"),destination:rl(t,"destination")});case"create_folder":return(0,et.jsx)(pO,{uri:rl(t,"uri")});case"delete":return(0,et.jsx)(mO,{});case"revert":return(0,et.jsx)(gO,{});default:return(0,et.jsx)(xO,{action:e,input:t})}});function dO({fields:n}){if(!n||typeof n!="object")return(0,et.jsx)(i2,{icon:(0,et.jsx)(ai,{className:"w-3 h-3"}),text:"Updated fields"});let e=[];for(let[t,r]of Object.entries(n))if(r!==void 0)if(t==="tags"&&r&&typeof r=="object"){let a=r,s=[];Array.isArray(a.add)&&a.add.length&&s.push(a.add.map(o=>`+${o}`).join(" ")),Array.isArray(a.remove)&&a.remove.length&&s.push(a.remove.map(o=>`-${o}`).join(" ")),Array.isArray(a.set)&&s.push(a.set.join(", ")),e.push({key:"tags",value:s.join(" ")||"(cleared)"})}else if(t==="metadata"&&r&&typeof r=="object"){let a=Object.entries(r).map(([s,o])=>o===null?`${s}: (removed)`:`${s}: ${String(o)}`).join(", ");e.push({key:"metadata",value:a||"(empty)"})}else e.push({key:t,value:r===null?"(cleared)":String(r)});return(0,et.jsxs)("div",{className:"px-3 py-2 space-y-0.5",children:[e.map(t=>(0,et.jsxs)("div",{className:"flex gap-2 text-[11px]",children:[(0,et.jsxs)("span",{className:"text-white/45 shrink-0",children:[t.key,":"]}),(0,et.jsx)("span",{className:"text-white/75 break-all",children:t.value})]},t.key)),e.length===0&&(0,et.jsx)(i2,{icon:(0,et.jsx)(ai,{className:"w-3 h-3"}),text:"Updated fields"})]})}function fO({uri:n,destination:e}){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,et.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,et.jsx)(ni,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,et.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function hO({uri:n,destination:e}){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,et.jsx)(sa,{className:"w-3 h-3 text-sky-400/60 shrink-0"}),(0,et.jsx)("span",{className:"text-white/50 truncate",children:n||"?"}),(0,et.jsx)(ni,{className:"w-3 h-3 text-white/35 shrink-0"}),(0,et.jsx)("span",{className:"text-white/75 truncate",children:e||"?"})]})}function pO({uri:n}){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] font-mono",children:[(0,et.jsx)(Cr,{className:"w-3 h-3 text-sky-300/70 shrink-0"}),(0,et.jsx)("span",{className:"text-white/75 truncate",children:n||"?"})]})}function mO(){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,et.jsx)(It,{className:"w-3 h-3 text-rose-400/70"}),(0,et.jsx)("span",{className:"text-[11px] text-rose-300/80",children:"Deleted"})]})}function gO(){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2",children:[(0,et.jsx)(io,{className:"w-3 h-3 text-amber-400/70"}),(0,et.jsx)("span",{className:"text-[11px] text-white/70",children:"Reverted to previous version"})]})}function xO({action:n,input:e}){let t=Object.entries(e).filter(([r])=>r!=="action"&&r!=="id"&&r!=="uri").slice(0,5).map(([r,a])=>`${r}: ${typeof a=="string"?a.slice(0,60):JSON.stringify(a)?.slice(0,60)??"?"}`).join(", ");return(0,et.jsxs)("div",{className:"px-3 py-2 text-[11px] text-white/60",children:[(0,et.jsx)("span",{className:"text-white/45 mr-1",children:n}),t&&(0,et.jsx)("span",{className:"text-white/50",children:t})]})}function i2({icon:n,text:e}){return(0,et.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 text-[11px] text-white/60",children:[n,(0,et.jsx)("span",{children:e})]})}function rl(n,e){let t=n[e];return typeof t=="string"?t:void 0}var Ga=j(le(),1),yO=200,al=new Map;function c2(n,e){if(al.size>=yO){let t=al.keys().next().value;t!==void 0&&al.delete(t)}al.set(n,e)}var bO=8,wO=200,h2=(0,Vn.memo)(function({tool:e,status:t,conversationId:r}){let a=(0,sl.useChatHost)(),s=(0,f2.useWorkspaceChatStore)(I=>r?I.conversationsById?.[r]?.agentId:void 0),o=(0,sl.useHasRowIdentity)(),i=(0,sl.useRowDisclosureValue)("card"),u=o&&i!==!0?bO:wO,c=(0,Vn.useMemo)(()=>el(e.input),[e.input]),d=(0,Vn.useMemo)(()=>(0,Wf.extractPathsFromToolCall)(e)[0]||(c?d2(c,"uri")||d2(c,"path"):void 0),[e,c]),f=String(t||"").toLowerCase(),h=f==="pending"||f.includes("pending"),p=f==="interrupted",m=!p&&(f==="error"||f.includes("error")||f.includes("fail")),g=c?.action,x=d?Zi(d):void 0,b=(0,Vn.useMemo)(()=>u0(e.structuredContent),[e.structuredContent]),y=(0,Vn.useMemo)(()=>{let I=e.structuredContent,H=I&&typeof I=="object"?String(I.status||"").toLowerCase():"";return H==="pending_review"||H.includes("pending")},[e.structuredContent]),N=(0,Vn.useMemo)(()=>b??(c&&!h?Yu(c):null),[b,c,h]),L=(0,Vn.useMemo)(()=>c?h?[]:vO(g,c):[],[g,c,h]),A=(0,Vn.useCallback)(I=>{let H=s||void 0;!H||!I||a.openFilesystemWidget?.(H,I)},[s,a]),w=(0,Vn.useMemo)(()=>{if(h)return(0,Wf.previewInput)(e.input,!0)},[h,e.input]),v=!h&&!m&&!!g&&Qi(g),[T,P]=(0,Vn.useState)(()=>v&&d&&s?al.get(`${s}|${e.id}`)??null:null);(0,Vn.useEffect)(()=>{if(!v||!d||!s){P(null);return}let I=`${s}|${e.id}`,H=al.get(I);if(H!==void 0){P(H);return}let q=!1,$=()=>{q||(async()=>{try{let ee=await Ko({agentId:s,files:[d]});if(q)return;let te=Jo(ee)[0],re=fc(te?.version?.baseline);if(!re?.content){c2(I,null);return}let ce=Ef(re.content,Zo(te));c2(I,ce),q||P(ce)}catch{}})()},S=globalThis,M=null,W=null;return typeof S.requestIdleCallback=="function"?M=S.requestIdleCallback($,{timeout:1500}):W=setTimeout($,200),()=>{q=!0,M!==null&&S.cancelIdleCallback?.(M),W!==null&&clearTimeout(W)}},[v,d,s,e.id]);let O=T??L,C=T?Of(T):N;return h?(0,Ga.jsx)(zf,{uri:d,lineCounts:null,isPending:!0,reviewPending:!1,isError:!1,isInterrupted:!1,onUriClick:d?A:void 0,children:(0,Ga.jsx)(kO,{content:w})}):g&&!Qi(g)?(0,Ga.jsx)(zf,{uri:d,lineCounts:null,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?A:void 0,children:(0,Ga.jsx)(u2,{action:g,input:c||{}})}):(0,Ga.jsx)(zf,{uri:d,lineCounts:C,isPending:!1,reviewPending:y,isError:m,isInterrupted:p,onUriClick:d?A:void 0,children:O.length>0?(0,Ga.jsx)(Ji,{hunks:O,language:x,maxLines:u}):(0,Ga.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:m?"Operation failed":"Done"})})});function vO(n,e){if(!n){let t=Xu(e);return t?l0(t):[]}if(n==="replace_text"){let t=e.edits;if(Array.isArray(t)&&t.length>0)return II(t.filter(s=>!!s&&typeof s=="object"&&typeof s.find=="string"));let r=typeof e.find=="string"?e.find:"",a=typeof e.replace=="string"?e.replace:"";return LI(r,a)}if(n==="update"||n==="replace_lines"){let t=Xu(e);return t?AI(t):[]}if(n==="append_text"||n==="prepend_text"||n==="insert"){let t=typeof e.text=="string"?e.text:"";return t?PI(t):[]}return[]}function kO({content:n}){return n?(0,Ga.jsx)("pre",{className:"px-3 py-1.5 text-[11px] leading-[18px] whitespace-pre overflow-x-auto overflow-y-clip bg-emerald-500/8 text-white/70 font-mono",children:n}):(0,Ga.jsx)("div",{className:"px-3 py-2 text-[11px] text-white/40 italic",children:"Running..."})}function d2(n,e){let t=n[e];return typeof t=="string"?t:void 0}var za=j(Ve(),1);function p2({port:n}){let e=n.useCurrentUser(),t=e?.name,r=e?.email,a=e?.role,s=e?.priority,o=(0,za.useMemo)(()=>t||r?{name:t,email:r}:void 0,[t,r]),i=(0,za.useMemo)(()=>a!==void 0||s!==void 0?{role:a,priority:s}:void 0,[a,s]),l=n.useProjectId(),u=n.useUserId(),c=n.getGrantedFeatures(l,u).join(","),d=(0,za.useMemo)(()=>c.split(",").filter(Boolean),[c]);return(0,za.useMemo)(()=>({currentUser:o,currentRole:i,grantedFeatures:d,useAgents(){let f=n.useAgentIds(),h=n.useAgentsById();return(0,za.useMemo)(()=>{let p={};for(let m of f){let g=h[m];g&&(p[m]={id:g.id,slug:g.slug,name:g.name,config:g.config})}return{ids:f,byId:p}},[f,h])},useFileMarks:f=>n.useFileMarks(f),clearFileMark:f=>n.clearFileMark(f),getStreamUrl(f,h,p){return n.buildEventStreamUrl({packageSlug:"brain-core",agentId:f,projectId:h,types:p})},subscribeFilesystemEvents(f,h,p,m){return n.subscribeRealtime({channel:"filesystem",projectId:h,agentId:f,onEvent:(g,x)=>p(x),...m?{onConnChange:m}:{}})},isDocker:n.isDocker,usePackageIconBySlug(){let f=n.useProjectId(),[h,p]=(0,za.useState)({});return(0,za.useEffect)(()=>{if(!f)return;let m=!1,g=`/api/packages/agent-core/packages/overview?projectId=${encodeURIComponent(f)}`;return fetch(g,{credentials:"include"}).then(x=>x.ok?x.json():null).then(x=>{if(m||!x?.packages)return;let b={};for(let y of x.packages){if(!y.id)continue;let N=(0,ur.resolveLucideIcon)(y.icon);if(!N)continue;let L=y.id.replace(/^@[^/]+\//,"");b[L]=N,b[y.id]=N}p(b)}).catch(()=>{}),()=>{m=!0}},[f]),h}}),[n,o,i,d])}var g2=j(le(),1);function m2({port:n,children:e}){let t=p2({port:n});return(0,g2.jsx)(rw,{value:t,children:e})}var Js=j(le(),1),SO="workspace.provider:@neuralis/brain-core",CO=(0,Js.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-white/30",children:"Loading..."}),x2=!1;function LO(n){let{registry:e,port:t}=n;!x2&&t.onClientStateReset&&(x2=!0,t.onClientStateReset(o=>{_.getState().resetClientState(o)}));function r({children:o}){return(0,Js.jsx)(m2,{port:t,children:o})}e.register({packageSlug:"@neuralis/brain-core",componentImport:SO,Component:r});function a({agentId:o,widgetId:i,state:l}){let u=t.useProjectId(),c=t.useUserId();return(0,Js.jsx)(qf.WorkspaceHostPortProvider,{port:t,children:(0,Js.jsx)(qf.PackageApiProvider,{slug:"brain-core",projectId:u,agentId:o,userId:c,children:(0,Js.jsx)(h0,{agentId:o,projectId:u,userId:c,widgetId:i,state:l})})})}let s=jf.default.lazy(()=>Promise.resolve({default:a}));e.register({packageSlug:"@neuralis/brain-core",componentImport:"@neuralis/brain-core/app/filesystem",Component:o=>(0,Js.jsx)(jf.Suspense,{fallback:CO,children:(0,Js.jsx)(s,{...o})})}),(0,y2.registerCardComponent)("filesystem.change",h2,{owner:{kind:"package-direct",packageId:"@neuralis/brain-core"},renderer:"direct",mountPolicy:"virtualized",estimateHeight:o2,composer:NI,matchTools:RI})}export{LO as installFilesystemHostComponents};
|