@kabmo-labs/kabmo 0.32.1 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +542 -535
- package/dist/client/static/js/{CsvGrid-4gx0jevc.js → CsvGrid-fncjbg6j.js} +2 -2
- package/dist/client/static/js/{DocxView-0667nr8h.js → DocxView-c9v2vr3r.js} +2 -2
- package/dist/client/static/js/{DrawioView-522v0d0r.js → DrawioView-vxjksm12.js} +2 -2
- package/dist/client/static/js/{ImageView-t8xp60hm.js → ImageView-a3g5k226.js} +1 -1
- package/dist/client/static/js/LayoutWrapper-hnjfwsjh.js +2 -0
- package/dist/client/static/js/Modal-qtftcp2t.js +38 -0
- package/dist/client/static/js/{PdfView-3fx172xh.js → PdfView-ksaes53y.js} +1 -1
- package/dist/client/static/js/{SessionsView-n3agmf5t.js → SessionsView-30vcr95v.js} +1 -1
- package/dist/client/static/js/{SheetView-nmrdb1b8.js → SheetView-vc484scg.js} +6 -6
- package/dist/client/static/js/{SvgPreview-0xsc6xam.js → SvgPreview-tph89jet.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-jj31rs62.js → abnfDiagram-O67JEVCF-xbar278c.js} +1 -1
- package/dist/client/static/js/architecture-7GRP2DOG-tavtgb8a.js +1 -0
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-ay3yr7pf.js → architectureDiagram-NJMV4G6O-s171n2z6.js} +3 -3
- package/dist/client/static/js/{astro-qgx1r159.js → astro-80bs6hvg.js} +1 -1
- package/dist/client/static/js/bash-b3rwyg5p.js +1 -0
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-4x33e16k.js → blockDiagram-BEXU5L5S-gzx6rv9n.js} +2 -2
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-dtb81cgz.js → c4Diagram-YGBWAQC7-7f00skch.js} +2 -2
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-vk5a2n9w.js → classDiagram-v2-NBCMYWYE-j79v95nc.js} +4 -4
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-6rbjbe19.js → cose-bilkent-JH36ORCC-5fkn7ee5.js} +1 -1
- package/dist/client/static/js/css-6vj0d308.js +1 -0
- package/dist/client/static/js/cynefin-OW5HDTMX-cdh3n2z2.js +1 -0
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-vyjksedr.js → cynefinDiagram-VND7K2PF-cfs1yvrd.js} +2 -2
- package/dist/client/static/js/{dagre-6A5THRUB-7hey38z5.js → dagre-6A5THRUB-44bgc48p.js} +2 -2
- package/dist/client/static/js/{diagram-22UHCM2B-aes06jde.js → diagram-22UHCM2B-a4g4x83k.js} +14 -14
- package/dist/client/static/js/{diagram-3UASUU5V-3cfkgm3x.js → diagram-3UASUU5V-gm4rg5na.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-z8mfhwpy.js → diagram-ATOU4E4O-a95y41vk.js} +3 -3
- package/dist/client/static/js/{diagram-CDSNMT55-t4821ctz.js → diagram-CDSNMT55-t3j93mmc.js} +5 -5
- package/dist/client/static/js/{diagram-MLGK6HIB-23yxbfrx.js → diagram-MLGK6HIB-c2wdez02.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-chhtf7v0.js → diagram-MPIPVDR6-gya9jhs5.js} +2 -2
- package/dist/client/static/js/{dockerfile-5b87ghm7.js → dockerfile-a7q6174s.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-9jejcvfr.js → ebnfDiagram-ZINNZB2B-jjhkza6t.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-xhhtkf58.js → elk-276RUBZZ-f7re45mw.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-mt2apjjb.js → erDiagram-OPXOYQCR-tpm9g5te.js} +6 -6
- package/dist/client/static/js/{erlang-6m6tpt72.js → erlang-qt876zrq.js} +1 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-as97tpyp.js +1 -0
- package/dist/client/static/js/flowDiagram-KWPJA3E3-ggm06d12.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-8cm7a29w.js → ganttDiagram-FUAMR5RP-fz43n12d.js} +3 -3
- package/dist/client/static/js/gitGraph-4MIJSDKK-eqz7p9ng.js +1 -0
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-5s0gbnx2.js → gitGraphDiagram-X574FWY7-f61hgbn6.js} +9 -9
- package/dist/client/static/js/graphql-n43pd5fs.js +1 -0
- package/dist/client/static/js/{index-z5s27s26.js → index-03h3bkcf.js} +1 -1
- package/dist/client/static/js/{index-360d7j0d.js → index-0e40xskg.js} +1 -1
- package/dist/client/static/js/{index-z4v1xmh1.js → index-0n5wwe60.js} +2 -2
- package/dist/client/static/js/{index-pf7syd7t.js → index-0tf0arsp.js} +3 -3
- package/dist/client/static/js/{index-fdbfzshx.js → index-14vndmcr.js} +2 -2
- package/dist/client/static/js/{index-7n68yx6m.js → index-1a0zkj8h.js} +2 -2
- package/dist/client/static/js/{index-p7btwjvj.js → index-1xqs14fr.js} +3 -3
- package/dist/client/static/js/{index-brj8qwa6.js → index-1y9r4frb.js} +2 -2
- package/dist/client/static/js/{index-6q80csr0.js → index-2svnq5gg.js} +1 -1
- package/dist/client/static/js/{index-9sd0vjmh.js → index-2x5f66t6.js} +2 -2
- package/dist/client/static/js/{index-dt7e1328.js → index-354mqqra.js} +2 -2
- package/dist/client/static/js/{index-5x95n3hx.js → index-3rcjx70v.js} +1 -1
- package/dist/client/static/js/{index-532btjmp.js → index-3zc1b0dv.js} +2 -2
- package/dist/client/static/js/{index-wzma5n54.js → index-5tgq7aqx.js} +1 -1
- package/dist/client/static/js/{index-xya34x4v.js → index-76zb4m0n.js} +2 -2
- package/dist/client/static/js/{index-2xj14800.js → index-7y6rpsrp.js} +2 -2
- package/dist/client/static/js/{index-h06bcfds.js → index-8239j2v1.js} +1 -1
- package/dist/client/static/js/{index-dq1kdt03.js → index-9fjt5anh.js} +1 -1
- package/dist/client/static/js/{index-ehcpzk5b.js → index-9y3gjdj7.js} +1 -1
- package/dist/client/static/js/{index-sa9cp6km.js → index-ahv9y42z.js} +2 -2
- package/dist/client/static/js/{index-vd0e25p0.js → index-ajs3jj6j.js} +1 -1
- package/dist/client/static/js/{index-qnwqaczk.js → index-apvkd37e.js} +3 -3
- package/dist/client/static/js/index-at6bhjyf.js +1 -0
- package/dist/client/static/js/index-bkye8mz4.js +2 -0
- package/dist/client/static/js/{index-dnp07j57.js → index-d495kfm0.js} +1 -1
- package/dist/client/static/js/{index-gbfg0anm.js → index-dbe6afkf.js} +2 -2
- package/dist/client/static/js/{index-g33knza2.js → index-djmg1d7h.js} +1 -1
- package/dist/client/static/js/{index-629kfbcb.js → index-e4p4cd3r.js} +2 -2
- package/dist/client/static/js/{index-5y7c62sm.js → index-eyzeya95.js} +5 -5
- package/dist/client/static/js/{index-3vhznzgr.js → index-gcs49f3p.js} +1 -1
- package/dist/client/static/js/{index-59jb53v3.js → index-gs6f0qwa.js} +2 -2
- package/dist/client/static/js/{index-7fdp9c7m.js → index-hf52f59k.js} +2 -2
- package/dist/client/static/js/{index-qkscve6n.js → index-j0r5hj0j.js} +2 -2
- package/dist/client/static/js/{index-ay34b398.js → index-js7t1vb1.js} +17 -17
- package/dist/client/static/js/{index-a0bdavdr.js → index-km2zb6wk.js} +2 -2
- package/dist/client/static/js/{index-ye3sr7db.js → index-m73za75e.js} +2 -2
- package/dist/client/static/js/{index-kpspnztv.js → index-pbe4yed4.js} +2 -2
- package/dist/client/static/js/{index-a6k2hqke.js → index-pxv2nw9w.js} +1 -1
- package/dist/client/static/js/{index-jz9fpznk.js → index-q2w6s8n7.js} +5 -5
- package/dist/client/static/js/{index-h7pn9qw6.js → index-qckv9nte.js} +2 -2
- package/dist/client/static/js/{index-a733k69t.js → index-qsm2z36d.js} +2 -2
- package/dist/client/static/js/{index-pf5sbesf.js → index-rytaa8ca.js} +2 -2
- package/dist/client/static/js/{index-c0x6s6f7.js → index-sdtye3jy.js} +2 -2
- package/dist/client/static/js/index-sffjtm5w.js +12 -0
- package/dist/client/static/js/{index-ejgd8w3s.js → index-trm9x02n.js} +28 -28
- package/dist/client/static/js/{index-c93sp4yh.js → index-vw4brsdx.js} +1 -1
- package/dist/client/static/js/{index-hc2jmzpx.js → index-vw5k8csz.js} +46 -46
- package/dist/client/static/js/{index-2gfc25tq.js → index-w0fwb80e.js} +1 -1
- package/dist/client/static/js/{index-bbggh3f8.js → index-ypx3qmhq.js} +2 -2
- package/dist/client/static/js/{index-4s8ttfxj.js → index-zt75xpq0.js} +193 -193
- package/dist/client/static/js/{index-jppt5mgc.js → index-zvfvqvn9.js} +2 -2
- package/dist/client/static/js/info-A6RAGUB7-4pkzh1qx.js +1 -0
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-3w1yz32c.js → infoDiagram-VRGFBTTK-1qj804sn.js} +1 -1
- package/dist/client/static/js/ini-j5dyq6gm.js +1 -0
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-ckt471dy.js → ishikawaDiagram-OU5B5YK6-4j4qsnzw.js} +3 -3
- package/dist/client/static/js/java-g4dgwbfd.js +1 -0
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-kfvn4w7e.js → journeyDiagram-ZHPQQLJL-j0brnfft.js} +4 -4
- package/dist/client/static/js/jsx-7t5ecz9s.js +1 -0
- package/dist/client/static/js/{julia-0j0gsjvc.js → julia-4ghmfy3e.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-0q36cm83.js → kanban-definition-PNTS6WVX-qqc22br0.js} +2 -2
- package/dist/client/static/js/lua-1g6w30de.js +1 -0
- package/dist/client/static/js/markdown-afx21x8c.js +1 -0
- package/dist/client/static/js/{mermaid.core-b1ssa824.js → mermaid.core-vv3wbe65.js} +6 -6
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-e2ym5en8.js → mindmap-definition-NLK3R4M7-y5b2z8zp.js} +2 -2
- package/dist/client/static/js/one-dark-pro-hm3f56n1.js +1 -0
- package/dist/client/static/js/one-light-xrz49rct.js +1 -0
- package/dist/client/static/js/packet-AYTQ26CC-yg71sp88.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-t8bbdyhe.js → pegDiagram-GJSIUBJH-0be07mqs.js} +1 -1
- package/dist/client/static/js/{perl-7n7e9ncg.js → perl-sd00t4b4.js} +1 -1
- package/dist/client/static/js/{php-32vy69vd.js → php-2zfyqa61.js} +1 -1
- package/dist/client/static/js/pie-WAS4IAKB-89wd6np0.js +1 -0
- package/dist/client/static/js/{pieDiagram-5QR66LMP-envv4brj.js → pieDiagram-5QR66LMP-544w86jk.js} +2 -2
- package/dist/client/static/js/properties-thd83wey.js +1 -0
- package/dist/client/static/js/python-264ns4xw.js +1 -0
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-72rk137a.js → quadrantDiagram-O4NWA36T-p09e7z5s.js} +4 -4
- package/dist/client/static/js/r-qw82kkv9.js +1 -0
- package/dist/client/static/js/radar-RG4KPBEZ-avn0b8r9.js +1 -0
- package/dist/client/static/js/railroad-74A4TZTK-de27xv5w.js +1 -0
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-rg4zzj7x.js +1 -0
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-d84fhj8v.js +1 -0
- package/dist/client/static/js/railroad-peg-WCYAUIDC-dvf8xrmc.js +1 -0
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-1ej0f5hr.js → railroadDiagram-XR7U4H2S-de830ed2.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-rvdaknpd.js → requirementDiagram-PLB6GJNP-b47d74p1.js} +4 -4
- package/dist/client/static/js/{ruby-5ty7fys7.js → ruby-v9qaqhby.js} +1 -1
- package/dist/client/static/js/{rust-2geezrcs.js → rust-fkt0qyrs.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-nxvhtdaw.js → sankeyDiagram-IPEJSGJF-6ezc2fpj.js} +5 -5
- package/dist/client/static/js/{sass-mey5150f.js → sass-9bxped7y.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-n5cn5qrt.js → sequenceDiagram-PO4LG4MO-by5zqj6w.js} +18 -18
- package/dist/client/static/js/{sizeCapture-INFHLROL-r074kj7s.js → sizeCapture-INFHLROL-q85r06j6.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-vxghxdb0.js → stateDiagram-v2-GCMORJYK-ep5pyexs.js} +3 -3
- package/dist/client/static/js/{svelte-3ewx0hzx.js → svelte-mwtx07d9.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-qkkv894p.js → swimlanes-2SLR337P-95fcqkh8.js} +1 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-xs2en5dv.js +8 -0
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-5tbq4ex2.js → timeline-definition-EJHVYXUP-461e615g.js} +2 -2
- package/dist/client/static/js/treeView-Q6P3EWNA-mham0bh6.js +1 -0
- package/dist/client/static/js/treemap-WGGIJYW6-mxrxax86.js +1 -0
- package/dist/client/static/js/tsx-nm94hed6.js +1 -0
- package/dist/client/static/js/typescript-0s2t05jj.js +1 -0
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-6p8hf0b7.js → usecaseDiagram-POWQR4AR-ftqfnvhg.js} +37 -37
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-7k5jsxf9.js → vennDiagram-UO4OBE2U-7t96h6ez.js} +7 -7
- package/dist/client/static/js/{vue-06rdf4wh.js → vue-j8vb9d7r.js} +1 -1
- package/dist/client/static/js/wardley-WFR3VGLG-8vrvh9p3.js +1 -0
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-km2x4er8.js → wardleyDiagram-VNRHLVJA-0de8w8c6.js} +4 -4
- package/dist/client/static/js/xml-dz51p1m3.js +1 -0
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-kr3sgr4m.js → xychartDiagram-PMCCYNJV-dez9phkf.js} +5 -5
- package/dist/client/static/js/yaml-2cfkd30t.js +1 -0
- package/package.json +1 -1
- package/src/client/components/common/context-usage-button/McpSection.test.tsx +98 -0
- package/src/client/components/common/context-usage-button/McpSection.tsx +12 -5
- package/src/client/components/common/context-usage-button/SessionStats.tsx +80 -0
- package/src/client/components/common/context-usage-button/index.test.tsx +26 -0
- package/src/client/components/common/context-usage-button/index.tsx +36 -28
- package/src/client/components/common/harness-glyph/brands.ts +8 -0
- package/src/client/components/mobile/LayoutWrapper.tsx +12 -3
- package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +9 -2
- package/src/client/components/settings/apply-side-effects.test.ts +11 -0
- package/src/client/components/settings/apply-side-effects.ts +7 -0
- package/src/client/components/settings/categories/ChatSettings.test.tsx +1 -1
- package/src/client/components/settings/categories/ChatSettings.tsx +2 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +1 -1
- package/src/client/components/settings/categories/chat-settings/ChangedFilesSection.tsx +79 -0
- package/src/client/components/settings/categories/chat-settings/groups.ts +4 -3
- package/src/client/components/workspace/chat-timeline/ChangedFilesSummary.tsx +101 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +33 -1
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +1 -1
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +17 -51
- package/src/client/components/workspace/diff-panel/index.tsx +23 -4
- package/src/client/components/workspace/diff-panel/toolbar-git-actions.tsx +94 -0
- package/src/client/components/workspace/editor/Body.tsx +2 -0
- package/src/client/data/settings/omp-schema.json +73 -3
- package/src/client/hooks/chat/timeline/changed-files-setting.test.ts +31 -0
- package/src/client/hooks/chat/timeline/changed-files-setting.ts +60 -0
- package/src/client/hooks/chat/timeline/session-changes.ts +51 -0
- package/src/client/hooks/ui/notification-events.test.ts +3 -0
- package/src/client/hooks/ui/notification-events.ts +3 -1
- package/src/client/hooks/ui/notification-sound.ts +13 -6
- package/src/client/hooks/ui/ui-sounds.test.ts +15 -0
- package/src/client/hooks/workspace/diff-file.ts +11 -4
- package/src/client/hooks/workspace/file-tabs.ts +13 -4
- package/src/client/hooks/workspace/journal-diff.ts +97 -0
- package/src/client/lib/notifications/native-banner-sound.test.ts +93 -0
- package/src/client/lib/notifications/native-banner-sound.ts +46 -0
- package/src/client/lib/notifications/os.test.ts +14 -5
- package/src/client/lib/notifications/os.ts +8 -0
- package/src/server/lib/harness/launch-table.ts +10 -0
- package/src/server/lib/omp/session/changes.test.ts +138 -0
- package/src/server/lib/omp/session/changes.ts +220 -0
- package/src/server/lib/omp/session/session-discovery.test.ts +4 -4
- package/src/server/lib/omp/session/sidebar-activity.server.test.ts +6 -2
- package/src/server/lib/omp/session/subagent-presence-scan.ts +54 -0
- package/src/server/lib/omp/session/subagent-presence-store.test.ts +1 -1
- package/src/server/lib/omp/session/subagent-presence.test.ts +115 -0
- package/src/server/lib/omp/session/subagent-presence.ts +12 -3
- package/src/server/lib/omp/session/telemetry/compute.ts +68 -0
- package/src/server/lib/omp/session/telemetry.test.ts +81 -0
- package/src/server/routes/sessions/changes.test.ts +90 -0
- package/src/server/routes/sessions/changes.ts +55 -0
- package/src/server/routes/sessions/index.ts +6 -0
- package/src/shared/lib/chat/duration.ts +34 -0
- package/src/shared/lib/chat/timeline/changed-files.test.ts +121 -0
- package/src/shared/lib/chat/timeline/changed-files.ts +71 -0
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +3 -0
- package/src/shared/lib/format/duration.test.ts +31 -0
- package/src/shared/lib/format/duration.ts +27 -0
- package/src/shared/lib/fs/unified-diff.test.ts +53 -0
- package/src/shared/lib/fs/unified-diff.ts +127 -0
- package/src/shared/lib/harness/brand-color.ts +3 -0
- package/src/shared/lib/harness/catalog.test.ts +13 -0
- package/src/shared/lib/harness/catalog.ts +8 -1
- package/src/shared/lib/harness/fork.ts +4 -2
- package/src/shared/lib/harness/mcp-facts.ts +3 -0
- package/src/shared/lib/harness/provider-facts.ts +14 -0
- package/src/shared/lib/harness/updates.ts +5 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +27 -27
- package/src/shared/lib/omp/config/schema.test.ts +4 -2
- package/src/shared/lib/settings/defaults.ts +1 -0
- package/src/shared/lib/workspace/file-tab-id.ts +9 -0
- package/src/shared/types/context.ts +18 -0
- package/src/shared/types/fs.ts +21 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/omp/session.ts +6 -0
- package/src/shared/types/session-changes.ts +58 -0
- package/src/shared/types/settings/state.ts +8 -0
- package/dist/client/static/js/LayoutWrapper-xjnveecv.js +0 -2
- package/dist/client/static/js/Modal-k2jr9hc4.js +0 -38
- package/dist/client/static/js/architecture-7GRP2DOG-1y9zvsyt.js +0 -1
- package/dist/client/static/js/bash-m0qjsyy0.js +0 -1
- package/dist/client/static/js/css-t4ngafan.js +0 -1
- package/dist/client/static/js/cynefin-OW5HDTMX-k2188qcq.js +0 -1
- package/dist/client/static/js/eventmodeling-NTZA5JFV-pdr0qn0n.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-zvz0mxne.js +0 -1
- package/dist/client/static/js/gitGraph-4MIJSDKK-wmqf046s.js +0 -1
- package/dist/client/static/js/graphql-692h0n2x.js +0 -1
- package/dist/client/static/js/index-61tm0v57.js +0 -1
- package/dist/client/static/js/index-kg86e3sy.js +0 -12
- package/dist/client/static/js/index-nmmxb4va.js +0 -2
- package/dist/client/static/js/info-A6RAGUB7-zg3twte6.js +0 -1
- package/dist/client/static/js/ini-cg0a5wm3.js +0 -1
- package/dist/client/static/js/java-vcck089n.js +0 -1
- package/dist/client/static/js/jsx-ht9zyzwa.js +0 -1
- package/dist/client/static/js/lua-ke895s2q.js +0 -1
- package/dist/client/static/js/markdown-gwmsh53r.js +0 -1
- package/dist/client/static/js/one-dark-pro-4geyzhjj.js +0 -1
- package/dist/client/static/js/one-light-tqssjm9t.js +0 -1
- package/dist/client/static/js/packet-AYTQ26CC-3pav51g0.js +0 -1
- package/dist/client/static/js/pie-WAS4IAKB-wqfh7zdk.js +0 -1
- package/dist/client/static/js/properties-mzvvbqg5.js +0 -1
- package/dist/client/static/js/python-3w64wsyd.js +0 -1
- package/dist/client/static/js/r-32re2zwb.js +0 -1
- package/dist/client/static/js/radar-RG4KPBEZ-w7qjdr2g.js +0 -1
- package/dist/client/static/js/railroad-74A4TZTK-rhr99kkj.js +0 -1
- package/dist/client/static/js/railroad-abnf-HS5TGJTU-c4jeea3m.js +0 -1
- package/dist/client/static/js/railroad-ebnf-LZEXJU2U-x2ee66ex.js +0 -1
- package/dist/client/static/js/railroad-peg-WCYAUIDC-yw8wjfwg.js +0 -1
- package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-y81h9n27.js +0 -8
- package/dist/client/static/js/treeView-Q6P3EWNA-ekz05ccs.js +0 -1
- package/dist/client/static/js/treemap-WGGIJYW6-aq6qymjr.js +0 -1
- package/dist/client/static/js/tsx-0p183w2f.js +0 -1
- package/dist/client/static/js/typescript-t9a5jyvv.js +0 -1
- package/dist/client/static/js/wardley-WFR3VGLG-z34tj4y3.js +0 -1
- package/dist/client/static/js/xml-81hxjjt4.js +0 -1
- package/dist/client/static/js/yaml-yssayv8a.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n,i,o,si,a,Ts,e,w,Ze,$e,S,ir,or,s,m,Or,f,va,Ie,hn,OA,ln,kr,Np,Hl}from"./index-4s8ttfxj.js";import{Ss,fr,Iu}from"./index-a733k69t.js";function re(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return`t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function oe(t){return JSON.stringify(t)}function ce(t){let r=Qe(t);if(!w(r))return null;if(r.t==="ready"){if(typeof r.id!=="string"||typeof r.cwd!=="string")return null;let l=typeof r.replayBytes==="number"?r.replayBytes:0;return{...r,t:"ready",replayBytes:l}}if(r.t==="exit")return{t:"exit",exitCode:typeof r.exitCode==="number"?r.exitCode:null,signal:typeof r.signal==="string"?r.signal:null};if(r.t==="error"&&typeof r.message==="string")return{t:"error",code:Ve(r.code),message:r.message};return null}function ue(t){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/terminal/${encodeURIComponent(t)}/ws`}function Ve(t){return t==="capacity"||t==="cwd"||t==="shell"||t==="spawn"?t:"unknown"}function Qe(t){try{return JSON.parse(t)}catch{return null}}function me(t){if(t.buffer instanceof ArrayBuffer)return t;return new Uint8Array(t)}var Je=500,je=8000,et=4;function de(t,r){let l=null,c=null,d=0,u=!1,p=!1,h=!1,T=null,k=[],A=0,F=null,U=()=>{let b=new WebSocket(ue(t));b.binaryType="arraybuffer",l=b,b.onopen=()=>{if(p)return;if(d=0,u=!0,r.onConnectionChange(!0),T)b.send(oe(T))},b.onmessage=(y)=>{if(p)return;if(y.data instanceof ArrayBuffer){v(new Uint8Array(y.data));return}if(typeof y.data!=="string")return;let P=ce(y.data);if(P)B(P)},b.onclose=()=>{if(l=null,p)return;if(r.onConnectionChange(!1),h=!1,k=[],A=0,F=null,!u)return;if(d+=1,d>et)return;let y=Math.min(Je*2**(d-1),je);c=setTimeout(()=>{if(c=null,!p)U()},y)},b.onerror=()=>{}},B=(b)=>{if(b.t==="ready"){if(h=!0,F=b,A=b.replayBytes,k=[],r.onReady(b),A===0)M();return}if(b.t==="exit"){r.onExit(b.exitCode,b.signal);return}r.onError(b.code,b.message)},v=(b)=>{if(A<=0){r.onOutput(b);return}if(k.push(b),A-=b.length,A>0)return;M()},M=()=>{let b=F,y=k;if(F=null,k=[],A=0,!b)return;r.onReplay(y.length===1?y[0]:tt(y),b)};U();let O=(b)=>{let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(oe(b))};return{attach(b,y,P,E,D){if(h)return;let R={t:"attach",cols:b,rows:y};if(P)R.root=P;if(E)R.repo=E;if(D)R.theme=D;T=R,O(R)},resize(b,y){O({t:"resize",cols:b,rows:y})},input(b){let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(me(b))},close(){O({t:"close"})},release(){if(p=!0,c!==null)clearTimeout(c),c=null;let b=l;if(l=null,!b)return;b.onopen=null,b.onmessage=null,b.onclose=null,b.onerror=null,b.close()}}}function tt(t){let r=0;for(let d of t)r+=d.length;let l=new Uint8Array(r),c=0;for(let d of t)l.set(d,c),c+=d.length;return l}function pe(t){return{connect:t.visible||t.opened,persist:t.ready&&t.visible&&!t.opened}}function fe(t={}){let{sessionId:r,ready:l}=Ze(),[c,d]=S("terminal.id",""),[u,p]=S("terminal.opened",!1),h=pe({visible:t.visible===!0,ready:l,opened:u}),[T,k]=n("connecting"),[A,F]=n(""),[U,B]=n(null),[v,M]=n(null),[O,b]=n(0),y=o(null),P=o(null),E=o(t.onOutput);E.current=t.onOutput;let D=o(t.onReplay);D.current=t.onReplay;let R=o(t.onRestart);R.current=t.onRestart;let g=o(t.root);g.current=t.root;let x=o(t.repo);x.current=t.repo;let L=o(t.theme);L.current=t.theme;let N=o(d);N.current=d;let z=o(null);i(()=>{if(!h.persist)return;p(!0)},[h.persist]),i(()=>{if(!h.connect||!l)return;if($e(r,"terminal.id"))return;N.current(re())},[h.connect,l,r]),i(()=>{if(!h.connect||!l||!c)return;k("connecting"),M(null),B(null);let I=de(c,{onReady(K){k("running"),F(K.shell),B(null)},onReplay(K,G){D.current?.(K,G)},onOutput(K){E.current?.(K)},onExit(K){k("exited"),B(K)},onError(K,G){k("error"),M(`${K}: ${G}`)},onConnectionChange(K){if(!K)k("connecting")}});y.current=I;let q=P.current;if(q)I.attach(q.cols,q.rows,g.current,x.current,L.current);return()=>{I.release(),y.current=null}},[h.connect,l,c,O]);let H=a(()=>{y.current?.close(),R.current?.(),N.current(re())},[]);i(()=>{if(!l)return;let I=t.root;if(!I)return;let q=`${I}\x00${t.repo??"."}`;if(z.current===null){z.current=q;return}if(z.current===q)return;z.current=q,H()},[l,t.root,t.repo,H]);let Q=a((I,q)=>{P.current={cols:I,rows:q},y.current?.attach(I,q,g.current,x.current,L.current)},[]),Z=a((I,q)=>{P.current={cols:I,rows:q},y.current?.resize(I,q)},[]),ee=a((I)=>{y.current?.input(I)},[]),te=a(()=>{b((I)=>I+1)},[]);return{status:T,shell:A,exitCode:U,error:v,attach:Q,resize:Z,input:ee,restart:H,reattach:te}}var nt={name:"clipboard-copy",size:24,node:[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]},be=s(nt);var rt={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"}]]},he=s(rt);var ot={connecting:"CONNECTING",running:"LIVE",exited:"EXITED",error:"ERROR"},it={connecting:"bg-warning/10 text-warning border-warning/20",running:"bg-success/10 text-success border-success/20",exited:"bg-ink/5 text-ink/60 border-ink/15",error:"bg-error/10 text-error border-error/20"};function ye({status:t,exitCode:r,rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,reposScanning:p,onRefreshRepos:h,shell:T,onRestart:k}){let A=T?T.split("/").pop():"";return e("div",{className:"h-10 px-3 border-b border-ink/10 bg-paper flex items-center justify-between flex-shrink-0 select-none",children:[e("div",{className:"flex items-center space-x-2 min-w-0",children:[e("div",{className:"flex items-center space-x-1.5",children:[e(Ie,{size:14,className:"text-ink/80 flex-shrink-0"}),e("span",{className:"text-xs font-semibold tracking-wider text-ink uppercase",children:"Terminal"})]}),e("span",{className:`inline-flex items-center space-x-1 px-1.5 py-0.5 rounded text-[10px] font-mono border ${it[t]}`,title:t==="exited"&&r!==null?`Shell exited with code ${r}`:void 0,children:[t==="connecting"&&e(m,{size:10,className:"animate-spin"}),e("span",{children:t==="exited"&&r!==null?`EXIT ${r}`:ot[t]})]}),e(fr,{rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,scanning:p,onRefreshRepos:h}),e("button",{type:"button",onClick:k,title:"Kill this shell and start a new one",className:"p-1 rounded text-ink/50 hover:text-ink hover:bg-ink/5 transition-colors cursor-pointer flex-shrink-0",children:e(va,{size:12})})]}),A&&e("span",{className:"hidden sm:block text-[10px] font-mono text-ink/40 flex-shrink-0",children:A})]})}var at=[{label:"bun build",cmd:"bun run build"},{label:"bun test",cmd:"bun test"},{label:"git status",cmd:"git status -s"},{label:"git diff",cmd:"git diff"},{label:"ls -la",cmd:"ls -la"},{label:"pwd",cmd:"pwd"},{label:"bun -v",cmd:"bun --version"}];function ge({onSelectCommand:t,disabled:r}){return e("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-1.5 bg-paper border-b border-ink/10 flex-shrink-0",children:[e("div",{className:"flex items-center space-x-1 text-[10px] font-mono text-ink/50 uppercase tracking-wider flex-shrink-0 select-none",children:[e(he,{size:11,className:"text-warning"}),e("span",{children:"Quick:"})]}),at.map((l)=>e("button",{type:"button",disabled:r,onClick:()=>t(l.cmd),className:"px-2 py-0.5 rounded text-[10px] font-mono bg-canvas hover:bg-ink/5 active:bg-ink/10 text-ink/80 hover:text-ink border border-ink/15 transition-all whitespace-nowrap disabled:opacity-40 cursor-pointer shadow-2xs",children:l.label},l.cmd))]})}var X=Object.freeze({ctrl:!1,alt:!1}),ie=[{id:"escape",label:"Esc",name:"Escape",sequence:"\x1B"},{id:"tab",label:"Tab",name:"Tab",sequence:"\t"},{id:"interrupt",label:"^C",name:"Ctrl+C — interrupt",sequence:"\x03"},{id:"left",label:"←",name:"Left arrow",csi:{prefix:"1",final:"D",application:"OD"}},{id:"up",label:"↑",name:"Up arrow",csi:{prefix:"1",final:"A",application:"OA"}},{id:"down",label:"↓",name:"Down arrow",csi:{prefix:"1",final:"B",application:"OB"}},{id:"right",label:"→",name:"Right arrow",csi:{prefix:"1",final:"C",application:"OC"}},{id:"home",label:"Home",name:"Home",csi:{prefix:"1",final:"H",application:"OH",terminfo:"\x1BOH"}},{id:"end",label:"End",name:"End",csi:{prefix:"1",final:"F",application:"OF",terminfo:"\x1BOF"}},{id:"pageUp",label:"PgUp",name:"Page up",csi:{prefix:"5",final:"~"}},{id:"pageDown",label:"PgDn",name:"Page down",csi:{prefix:"6",final:"~"}},{id:"delete",label:"Del",name:"Delete",csi:{prefix:"3",final:"~"}},{id:"shiftTab",label:"⇧Tab",name:"Shift+Tab",sequence:"\x1B[Z"},{id:"eof",label:"^D",name:"Ctrl+D — end of input",sequence:"\x04"},{id:"clear",label:"^L",name:"Ctrl+L — clear screen",sequence:"\f"}],ae=[{id:"pipe",label:"|",name:"Pipe",sequence:"|"},{id:"tilde",label:"~",name:"Tilde",sequence:"~"},{id:"dollar",label:"$",name:"Dollar",sequence:"$"},{id:"asterisk",label:"*",name:"Asterisk",sequence:"*"},{id:"question",label:"?",name:"Question mark",sequence:"?"},{id:"underscore",label:"_",name:"Underscore",sequence:"_"},{id:"backslash",label:"\\",name:"Backslash",sequence:"\\"},{id:"slash",label:"/",name:"Slash",sequence:"/"},{id:"minus",label:"-",name:"Minus",sequence:"-"},{id:"equals",label:"=",name:"Equals",sequence:"="},{id:"plus",label:"+",name:"Plus",sequence:"+"},{id:"ampersand",label:"&",name:"Ampersand",sequence:"&"},{id:"semicolon",label:";",name:"Semicolon",sequence:";"},{id:"colon",label:":",name:"Colon",sequence:":"},{id:"comma",label:",",name:"Comma",sequence:","},{id:"dot",label:".",name:"Period",sequence:"."},{id:"at",label:"@",name:"At sign",sequence:"@"},{id:"percent",label:"%",name:"Percent",sequence:"%"},{id:"caret",label:"^",name:"Caret",sequence:"^"},{id:"hash",label:"#",name:"Hash",sequence:"#"},{id:"bang",label:"!",name:"Exclamation mark",sequence:"!"},{id:"parenOpen",label:"(",name:"Open parenthesis",sequence:"("},{id:"parenClose",label:")",name:"Close parenthesis",sequence:")"},{id:"bracketOpen",label:"[",name:"Open bracket",sequence:"["},{id:"bracketClose",label:"]",name:"Close bracket",sequence:"]"},{id:"braceOpen",label:"{",name:"Open brace",sequence:"{"},{id:"braceClose",label:"}",name:"Close brace",sequence:"}"},{id:"lessThan",label:"<",name:"Less than",sequence:"<"},{id:"greaterThan",label:">",name:"Greater than",sequence:">"},{id:"quote",label:"'",name:"Single quote",sequence:"'"},{id:"doubleQuote",label:'"',name:"Double quote",sequence:'"'},{id:"backtick",label:"`",name:"Backtick",sequence:"`"}],Te={};for(let t of[...ie,...ae])Te[t.id]=t;function xe(t,r={}){let l=Te[t];if(!l)return"";let c=r.modifiers??X;if(l.csi)return st(l.csi,c,r.applicationCursorKeys??!1);let d=l.sequence??"";return c.alt?`\x1B${d}`:d}function st(t,r,l){let c=lt(r);if(c!==null)return`\x1B[${t.prefix};${c}${t.final}`;if(t.terminfo)return t.terminfo;if(l&&t.application)return`\x1B${t.application}`;return`\x1B[${t.prefix==="1"?"":t.prefix}${t.final}`}function lt(t){let r=(t.alt?2:0)|(t.ctrl?4:0);return r===0?null:r+1}function we(t,r){if(t.length!==1)return t;let l=t;if(r.ctrl)l=ut(l)??l;if(r.alt)l=`\x1B${l}`;return l}var ct={"@":"\x00"," ":"\x00","":"\b","[":"\x1B","\\":"\x1C","]":"\x1D","^":"\x1E",_:"\x1F","?":""};function ut(t){if(t.length!==1)return null;let r=t.charCodeAt(0);if(r>=97&&r<=122)return String.fromCharCode(r-96);if(r>=65&&r<=90)return String.fromCharCode(r-64);return ct[t]??null}var mt=[{modifier:"ctrl",label:"Ctrl",name:"Ctrl — applies to the next key"},{modifier:"alt",label:"Alt",name:"Alt / meta — applies to the next key"}],W="flex items-center justify-center h-8 min-w-8 px-1.5 rounded border font-mono transition-colors cursor-pointer select-none disabled:opacity-40 disabled:cursor-default text-[11px] @[420px]:h-9 @[420px]:min-w-10 @[420px]:text-xs",V="bg-canvas text-ink/80 border-ink/15 hover:text-ink hover:bg-ink/5 active:bg-ink/10",ve="bg-ink text-canvas border-ink";function Re({modifiers:t,onToggleModifier:r,onKey:l,onCopy:c,onPaste:d,disabled:u}){let[p,h]=n(!1),[T,k]=n(null),A=t.ctrl||t.alt,F=(v)=>{k(v),setTimeout(()=>k((M)=>M===v?null:M),1500)},U=async()=>{F(await c()?"copied":"empty")},B=async()=>{if(!await d())F("pasteFailed")};return e("div",{className:"@container flex flex-col gap-1 px-2 py-1.5 border-t border-ink/10 bg-paper flex-shrink-0",onPointerDown:(v)=>v.preventDefault(),children:[e("div",{className:"flex flex-wrap items-center gap-1",children:[mt.map(({modifier:v,label:M,name:O})=>e("button",{type:"button",onClick:()=>r(v),"aria-pressed":t[v],title:O,"aria-label":O,className:`${W} ${t[v]?ve:V}`,children:M},v)),A&&e("span",{className:"text-[10px] font-mono text-ink/50 px-0.5 whitespace-nowrap","aria-hidden":!0,children:"next"}),e("span",{className:"w-px h-5 bg-ink/15 flex-shrink-0","aria-hidden":!0}),e("button",{type:"button",onClick:U,disabled:u,title:T==="empty"?"Nothing selected":"Copy selection","aria-label":"Copy selection",className:`${W} ${T==="empty"?"bg-warning/10 text-warning border-warning/30":V}`,children:[T==="copied"?e(f,{size:13}):e(be,{size:13}),e("span",{className:"pl-1",children:"Copy"})]}),e("button",{type:"button",onClick:B,disabled:u,title:T==="pasteFailed"?"Clipboard unavailable":"Paste into the shell","aria-label":"Paste into the shell",className:`${W} ${T==="pasteFailed"?"bg-error/10 text-error border-error/30":V}`,children:[e(Ss,{size:13}),e("span",{className:"pl-1",children:"Paste"})]}),e("button",{type:"button",onClick:()=>h((v)=>!v),"aria-pressed":p,title:p?"Show control keys":"Show symbols","aria-label":p?"Show control keys":"Show symbols",className:`${W} ml-auto ${p?ve:V}`,children:p?"ABC":"123"})]}),e("div",{className:"flex flex-wrap items-center gap-1",children:(p?ae:ie).map((v)=>e("button",{type:"button",disabled:u,onClick:()=>l(v.id),title:v.name,"aria-label":v.name,className:`${W} ${V}`,children:v.label},v.id))})]})}function Se(t){if(!t.startsWith("\x1B[M")||t.length<6)return{text:t};let r=new Uint8Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=t.charCodeAt(l)&255;return{bytes:r}}function Ce(t){let r=ln(t),{canvas:l,ink:c,paper:d}=r,u=(h)=>kr(h,c,0.2),p=(h)=>kr(l,c,h);return{background:"transparent",foreground:c,cursor:r.meta,cursorAccent:d,selectionBackground:p(0.28),selectionForeground:c,black:p(0.2),red:r.error,green:r.success,yellow:r.warning,blue:r.info,magenta:r.meta,cyan:kr(r.info,r.success,0.5),white:p(0.75),brightBlack:p(0.5),brightRed:u(r.error),brightGreen:u(r.success),brightYellow:u(r.warning),brightBlue:u(r.info),brightMagenta:u(r.meta),brightCyan:u(kr(r.info,r.success,0.5)),brightWhite:p(0.92)}}var J="Fira Code",dt="'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', 'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', 'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', 'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'",ke="Kabmo Nerd Symbols",Ae=[J,ke],j=`'${J}', ${dt}, '${ke}', Menlo, Monaco, 'Courier New', monospace`,Y=12,pt=16,ft=1e4;function bt(t,r){return Math.max(1,t)*Math.max(1,r)*pt}var Me=bt(ft,100);var ht=2000;async function Fe(){if(typeof document>"u"||!document.fonts?.load)return;let t=Promise.withResolvers(),r=setTimeout(t.resolve,ht);try{await Promise.race([document.fonts.load(`${Y}px "${J}"`).then(()=>{return},()=>{return}),t.promise])}finally{clearTimeout(r)}}function Le(t){if(typeof document>"u"||!document.fonts)return()=>{};let r=new Set(Ae),l=(c)=>{if([...c.fontfaces].some((u)=>r.has(u.family.replace(/['"]/g,"").trim())))t()};return document.fonts.addEventListener("loadingdone",l),()=>document.fonts.removeEventListener("loadingdone",l)}var Ee=2.5,yt=1;function gt(t,r){let l=t*0.8,c=t*0.2,d=Math.ceil(t*0.6),u=l,p=c,h=typeof document>"u"?null:document.createElement("canvas").getContext("2d");if(h){h.font=`${t}px ${r}`,d=Math.ceil(h.measureText("M").width)||d;let T=h.measureText("Mg");u=T.actualBoundingBoxAscent||l,p=T.actualBoundingBoxDescent||c}return{width:d,height:Math.ceil(u+p+Ee+yt),baseline:Math.round(u+Ee)}}function Ne(t){let r=t.renderer;if(!r)return;r.measureFont=()=>gt(t.options.fontSize??Y,t.options.fontFamily??j),r.remeasureFont()}function Tt(t,r,l){if(!l.width||!l.height)return null;return{cols:Math.max(2,Math.floor(t/l.width)),rows:Math.max(1,Math.floor(r/l.height))}}function _e(t,r){let l=t;l.proposeDimensions=()=>{let c=r.element,d=r.renderer?.getMetrics();if(!c||!d)return;let u=getComputedStyle(c),p=(parseFloat(u.paddingLeft)||0)+(parseFloat(u.paddingRight)||0),h=(parseFloat(u.paddingTop)||0)+(parseFloat(u.paddingBottom)||0);return Tt(c.clientWidth-p,c.clientHeight-h,d)??void 0}}function xt(t){let{cols:r,rows:l,attached:c,committed:d}=t;if(r<10||l<5)return{kind:"ignore"};if(!c)return{kind:"attach",cols:r,rows:l};if(r===d.cols&&l===d.rows)return{kind:"ignore"};return{kind:"change",cols:r,rows:l}}function Oe(t){let r={cols:0,rows:0},l=!1,c,d=()=>{if(!t.fit())return;let u=t.current();if(!u)return;let p=xt({cols:u.cols,rows:u.rows,attached:l,committed:r});if(p.kind==="ignore")return;if(r={cols:p.cols,rows:p.rows},p.kind==="attach"){l=!0,t.onReady(p.cols,p.rows);return}t.onGridChange(p.cols,p.rows)};return{schedule(){clearTimeout(c),c=setTimeout(d,120)},restate(){r={cols:0,rows:0}},isAttached:()=>l,dispose(){clearTimeout(c),c=void 0}}}function Pe(t,r){if(r.type!=="keydown"||!r.shiftKey)return!1;if(r.key==="PageUp")return t.scrollPages(-1),!0;if(r.key==="PageDown")return t.scrollPages(1),!0;if(r.key==="Home")return t.scrollToTop(),!0;if(r.key==="End")return t.scrollToBottom(),!0;if(r.key==="ArrowUp")return t.scrollLines(-1),!0;if(r.key==="ArrowDown")return t.scrollLines(1),!0;return!1}function Ue(t,r){let l=0,c=(u)=>{if(u.touches.length===1)l=u.touches[0].clientY},d=(u)=>{if(u.touches.length!==1)return;let p=l-u.touches[0].clientY;if(Math.abs(p)<16)return;r()?.scrollLines(Math.trunc(p/16)),l=u.touches[0].clientY};return t.addEventListener("touchstart",c,{passive:!0}),t.addEventListener("touchmove",d,{passive:!0}),()=>{t.removeEventListener("touchstart",c),t.removeEventListener("touchmove",d)}}function wt(t){if(t.viewportY<=0&&!t.hasSelection&&!t.pointerHeld)return null;return t.scrollback-t.viewportY}function vt(t){let r=t.scrollback-t.top;return r>0?r:null}function Be(t){let r={pointerHeld:!1},l=()=>{r.pointerHeld=!0},c=()=>{r.pointerHeld=!1};return t.addEventListener("pointerdown",l,!0),globalThis.addEventListener("pointerup",c),globalThis.addEventListener("pointercancel",c),{get pointerHeld(){return r.pointerHeld},stop(){t.removeEventListener("pointerdown",l,!0),globalThis.removeEventListener("pointerup",c),globalThis.removeEventListener("pointercancel",c)}}}function De(t,r,l){let c=wt({scrollback:t.getScrollbackLength(),viewportY:t.getViewportY(),hasSelection:t.hasSelection(),pointerHeld:r.pointerHeld});if(l(),c===null)return;let d=vt({scrollback:t.getScrollbackLength(),top:c});if(d===null)return;let u=d-t.getViewportY();if(u===0)return;try{t.scrollLines(-u)}catch{}}async function qe(t,r,l,c){let d=await import("./ghostty-web-2gt2tp72.js"),[u]=await Promise.all([d.Ghostty.load(),Fe()]);if(c())return null;let p=r,h=null,T=!1,k,A=null,F=!1,U=(g)=>{let{term:x}=g;x.attachCustomKeyEventHandler((L)=>Pe(x,L)),g.disposables.push(x.onScroll((L)=>l.onScrolledUpChange(L>0)),x.onData((L)=>{let N=Se(L);if(N.bytes)l.onBinaryInput(N.bytes);else l.onInput(N.text)}),x.onResize(()=>{if(T)return;y.schedule()}))},B=(g)=>{let x=new d.Terminal({cursorBlink:!0,cursorStyle:"block",fontSize:Y,fontFamily:j,theme:Ce(g),scrollback:Me,smoothScrollDuration:0,ghostty:u});x.open(t),Ne(x),x.clear();let L=new d.FitAddon;x.loadAddon(L),_e(L,x);let N={term:x,fitAddon:L,disposables:[]};return U(N),N},v=(g)=>{if(!g)return;for(let x of g.disposables)try{x.dispose()}catch{}try{g.fitAddon.dispose()}catch{}try{g.term.dispose()}catch{}},M=()=>{if(F)return!1;if(t.clientWidth<=0||t.clientHeight<=0)return!1;let g=h?.term.renderer?.getMetrics();if(!g?.width||!g.height)return!1;try{return h?.fitAddon.fit(),!0}catch{return!1}},O=()=>{if(F)return;T=!1,M(),y.restate(),y.schedule()},b=(g,x,L)=>{let N=h?.term;if(!N)return;if(T=!0,N.cols!==x||N.rows!==L)N.resize(x,L);if(g.length===0){requestAnimationFrame(O);return}N.write(g,O)},y=Oe({current:()=>h?.term,fit:M,onReady:l.onReady,onGridChange:l.onGridChange}),P=Be(t);h=B(p),M(),y.schedule();let E=new ResizeObserver(()=>{clearTimeout(k),k=setTimeout(()=>{M(),y.schedule()},35)});E.observe(t);let D=Le(()=>{let g=h?.term;if(!g)return;let x=g.options.fontSize??Y;g.options.fontSize=x+0.1,g.options.fontSize=x,M(),y.schedule()}),R=Ue(t,()=>h?.term??null);return A=requestAnimationFrame(()=>{M(),y.schedule()}),{write(g){let x=h?.term;if(!x)return;De(x,P,()=>x.write(g))},writeReplay:b,reset(){let g=h?.term;if(!g)return;g.reset(),g.clear(),M()},focus(){h?.term.focus()},applicationCursorKeys(){return h?.term.wasmTerm?.getMode(1,!1)??!1},getSelection(){return h?.term.getSelection()??""},paste(g){h?.term.paste(g)},scrollToBottom(){h?.term.scrollToBottom()},setTheme(g){if(F||g===p)return;p=g,v(h),h=B(g),M()},dispose(){if(F=!0,A!==null)cancelAnimationFrame(A);clearTimeout(k),y.dispose(),D(),R(),P.stop(),E.disconnect(),v(h),h=null}}}function Ke(){let t=null,r=!1;return{request(){if(t)t();else r=!0},attach(l){if(t=l,!r)return;r=!1,l()},detach(){t=null,r=!1}}}var se=Ts(({onInput:t,onBinaryInput:r,onGridChange:l,onReady:c,onReattach:d},u)=>{let{theme:p}=Np(),h=o(null),T=o(null),[k,A]=n(!1),F=o(null);if(!F.current)F.current=Ke();let U=F.current,B=o(t);B.current=t;let v=o(r);v.current=r;let M=o(l);M.current=l;let O=o(c);O.current=c;let b=o(d);b.current=d;let y=o(p);y.current=p,i(()=>{let E=T.current;if(!E)return;E.setTheme(p),b.current?.()},[p]),si(u,()=>({write(E){T.current?.write(E)},writeReplay(E,D,R){T.current?.writeReplay(E,D,R)},reset(){T.current?.reset()},focus(){U.request()},applicationCursorKeys(){return T.current?.applicationCursorKeys()??!1},getSelection(){return T.current?.getSelection()??""},paste(E){T.current?.paste(E)}}),[]);let P=a(()=>{T.current?.scrollToBottom(),A(!1)},[]);return i(()=>{let E=h.current;if(!E)return;let D=!1;return qe(E,y.current,{onInput:(R)=>B.current(R),onBinaryInput:(R)=>v.current(R),onGridChange:(R,g)=>M.current(R,g),onReady:(R,g)=>O.current(R,g),onScrolledUpChange:A},()=>D).then((R)=>{if(!R)return;if(D){R.dispose();return}T.current=R,E.querySelector("textarea")?.setAttribute("data-terminal-input",""),U.attach(()=>T.current?.focus())}),()=>{D=!0,U.detach(),T.current?.dispose(),T.current=null}},[]),e("div",{className:"relative flex-1 w-full h-full overflow-hidden p-2",children:[e("div",{ref:h,"data-terminal-root":"",className:"kabmo-terminal w-full h-full cursor-text",style:{height:"100%",width:"100%"}}),k&&e("button",{type:"button",onClick:P,className:"absolute bottom-3 right-4 z-20 flex items-center space-x-1.5 px-2.5 py-1 bg-paper hover:bg-canvas text-ink border border-ink/20 rounded-full shadow-lg text-[11px] font-mono transition-all animate-fade-in cursor-pointer active:scale-95",title:"Scroll to latest output (Shift+End)",children:[e(Or,{size:12,className:"text-warning"}),e("span",{children:"Latest"})]})]})});se.displayName="RealtimeTerminalView";var le=new TextEncoder;function $n({className:t="",enabled:r=!0,rootPath:l,showHeader:c=!0,active:d=!0}){let u=o(null),{isDark:p}=Np(),h=Iu(),T=o(null),k=Hl(T),[A,F]=n(X),{activeRepo:U,setActiveRepo:B}=ir(l),{repos:v,scanning:M,rescan:O}=or(l,r),b=o(null),y=o(A);y.current=A;let P=a((C)=>{u.current?.write(C)},[]);i(()=>{if(!d||!r)return;u.current?.focus()},[d,r]);let E=a((C,_)=>{u.current?.writeReplay(C,_.replayCols,_.replayRows)},[]),D=a(()=>{u.current?.reset()},[]),{status:R,shell:g,exitCode:x,error:L,attach:N,resize:z,input:H,restart:Q,reattach:Z}=fe({visible:d&&r,root:r?l:void 0,repo:U,theme:p?"dark":"light",onOutput:P,onReplay:E,onRestart:D}),ee=a((C,_)=>{b.current={cols:C,rows:_},N(C,_)},[N]),te=a((C,_)=>{let ne=b.current;if(b.current={cols:C,rows:_},!ne)return;z(C,_)},[z]),I=a((C)=>{let _=y.current,ne=_.ctrl||_.alt,We=we(C,_);if(ne&&C.length===1)F(X);H(le.encode(We))},[H]),q=a((C)=>{F((_)=>({..._,[C]:!_[C]})),u.current?.focus()},[]),K=a((C)=>{let _=xe(C,{applicationCursorKeys:u.current?.applicationCursorKeys()??!1,modifiers:y.current});if(!_)return;H(le.encode(_)),F(X),u.current?.focus()},[H]),G=a(async()=>{let C=u.current?.getSelection()??"";if(!C)return!1;return hn(C)},[]),He=a(async()=>{let C=await OA();if(C===null||C.length===0)return!1;return u.current?.paste(C),u.current?.focus(),!0},[]),ze=a((C)=>{H(C)},[H]),Ye=a((C)=>{H(le.encode(`${C}\r`)),u.current?.focus()},[H]),Ge=a(()=>{Q()},[Q]),Xe=a(()=>{Z()},[Z]);if(!r)return e("div",{className:`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${t}`,children:e("span",{className:"text-xs font-mono text-muted",children:"No session selected"})});return e("div",{ref:T,className:`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${t}`,"aria-hidden":!d,style:k>0?{paddingBottom:k}:void 0,children:[c&&e(ye,{status:R,exitCode:x,rootPath:l,activeRepo:U,onSelectRepo:B,repos:v,reposScanning:M,onRefreshRepos:O,shell:g,onRestart:Ge}),e(ge,{onSelectCommand:Ye,disabled:R!=="running"}),L&&e("div",{className:"px-3 py-1.5 border-b border-error/20 bg-error/5 text-[11px] font-mono text-error flex-shrink-0",children:L}),e("div",{className:"flex-1 w-full min-h-0 bg-canvas overflow-hidden",children:e(se,{ref:u,onInput:I,onBinaryInput:ze,onReady:ee,onGridChange:te,onReattach:Xe})}),h&&e(Re,{modifiers:A,onToggleModifier:q,onKey:K,onCopy:G,onPaste:He,disabled:R!=="running"})]})}export{$n as TerminalPanel};
|
|
1
|
+
import{n,i,o,si,a,Ts,e,w,Ze,$e,S,ir,or,s,m,Or,f,va,_e,hn,$A,ln,kr,Rp,Hl}from"./index-zt75xpq0.js";import{Ss,fr,_u}from"./index-qsm2z36d.js";function re(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return`t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function oe(t){return JSON.stringify(t)}function ce(t){let r=Qe(t);if(!w(r))return null;if(r.t==="ready"){if(typeof r.id!=="string"||typeof r.cwd!=="string")return null;let l=typeof r.replayBytes==="number"?r.replayBytes:0;return{...r,t:"ready",replayBytes:l}}if(r.t==="exit")return{t:"exit",exitCode:typeof r.exitCode==="number"?r.exitCode:null,signal:typeof r.signal==="string"?r.signal:null};if(r.t==="error"&&typeof r.message==="string")return{t:"error",code:Ve(r.code),message:r.message};return null}function ue(t){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/terminal/${encodeURIComponent(t)}/ws`}function Ve(t){return t==="capacity"||t==="cwd"||t==="shell"||t==="spawn"?t:"unknown"}function Qe(t){try{return JSON.parse(t)}catch{return null}}function me(t){if(t.buffer instanceof ArrayBuffer)return t;return new Uint8Array(t)}var Je=500,je=8000,et=4;function de(t,r){let l=null,c=null,d=0,u=!1,p=!1,h=!1,T=null,k=[],A=0,F=null,U=()=>{let b=new WebSocket(ue(t));b.binaryType="arraybuffer",l=b,b.onopen=()=>{if(p)return;if(d=0,u=!0,r.onConnectionChange(!0),T)b.send(oe(T))},b.onmessage=(y)=>{if(p)return;if(y.data instanceof ArrayBuffer){v(new Uint8Array(y.data));return}if(typeof y.data!=="string")return;let P=ce(y.data);if(P)B(P)},b.onclose=()=>{if(l=null,p)return;if(r.onConnectionChange(!1),h=!1,k=[],A=0,F=null,!u)return;if(d+=1,d>et)return;let y=Math.min(Je*2**(d-1),je);c=setTimeout(()=>{if(c=null,!p)U()},y)},b.onerror=()=>{}},B=(b)=>{if(b.t==="ready"){if(h=!0,F=b,A=b.replayBytes,k=[],r.onReady(b),A===0)M();return}if(b.t==="exit"){r.onExit(b.exitCode,b.signal);return}r.onError(b.code,b.message)},v=(b)=>{if(A<=0){r.onOutput(b);return}if(k.push(b),A-=b.length,A>0)return;M()},M=()=>{let b=F,y=k;if(F=null,k=[],A=0,!b)return;r.onReplay(y.length===1?y[0]:tt(y),b)};U();let O=(b)=>{let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(oe(b))};return{attach(b,y,P,E,D){if(h)return;let R={t:"attach",cols:b,rows:y};if(P)R.root=P;if(E)R.repo=E;if(D)R.theme=D;T=R,O(R)},resize(b,y){O({t:"resize",cols:b,rows:y})},input(b){let y=l;if(!y||y.readyState!==WebSocket.OPEN)return;y.send(me(b))},close(){O({t:"close"})},release(){if(p=!0,c!==null)clearTimeout(c),c=null;let b=l;if(l=null,!b)return;b.onopen=null,b.onmessage=null,b.onclose=null,b.onerror=null,b.close()}}}function tt(t){let r=0;for(let d of t)r+=d.length;let l=new Uint8Array(r),c=0;for(let d of t)l.set(d,c),c+=d.length;return l}function pe(t){return{connect:t.visible||t.opened,persist:t.ready&&t.visible&&!t.opened}}function fe(t={}){let{sessionId:r,ready:l}=Ze(),[c,d]=S("terminal.id",""),[u,p]=S("terminal.opened",!1),h=pe({visible:t.visible===!0,ready:l,opened:u}),[T,k]=n("connecting"),[A,F]=n(""),[U,B]=n(null),[v,M]=n(null),[O,b]=n(0),y=o(null),P=o(null),E=o(t.onOutput);E.current=t.onOutput;let D=o(t.onReplay);D.current=t.onReplay;let R=o(t.onRestart);R.current=t.onRestart;let g=o(t.root);g.current=t.root;let x=o(t.repo);x.current=t.repo;let L=o(t.theme);L.current=t.theme;let N=o(d);N.current=d;let z=o(null);i(()=>{if(!h.persist)return;p(!0)},[h.persist]),i(()=>{if(!h.connect||!l)return;if($e(r,"terminal.id"))return;N.current(re())},[h.connect,l,r]),i(()=>{if(!h.connect||!l||!c)return;k("connecting"),M(null),B(null);let I=de(c,{onReady(K){k("running"),F(K.shell),B(null)},onReplay(K,G){D.current?.(K,G)},onOutput(K){E.current?.(K)},onExit(K){k("exited"),B(K)},onError(K,G){k("error"),M(`${K}: ${G}`)},onConnectionChange(K){if(!K)k("connecting")}});y.current=I;let q=P.current;if(q)I.attach(q.cols,q.rows,g.current,x.current,L.current);return()=>{I.release(),y.current=null}},[h.connect,l,c,O]);let H=a(()=>{y.current?.close(),R.current?.(),N.current(re())},[]);i(()=>{if(!l)return;let I=t.root;if(!I)return;let q=`${I}\x00${t.repo??"."}`;if(z.current===null){z.current=q;return}if(z.current===q)return;z.current=q,H()},[l,t.root,t.repo,H]);let Q=a((I,q)=>{P.current={cols:I,rows:q},y.current?.attach(I,q,g.current,x.current,L.current)},[]),Z=a((I,q)=>{P.current={cols:I,rows:q},y.current?.resize(I,q)},[]),ee=a((I)=>{y.current?.input(I)},[]),te=a(()=>{b((I)=>I+1)},[]);return{status:T,shell:A,exitCode:U,error:v,attach:Q,resize:Z,input:ee,restart:H,reattach:te}}var nt={name:"clipboard-copy",size:24,node:[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]]},be=s(nt);var rt={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"}]]},he=s(rt);var ot={connecting:"CONNECTING",running:"LIVE",exited:"EXITED",error:"ERROR"},it={connecting:"bg-warning/10 text-warning border-warning/20",running:"bg-success/10 text-success border-success/20",exited:"bg-ink/5 text-ink/60 border-ink/15",error:"bg-error/10 text-error border-error/20"};function ye({status:t,exitCode:r,rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,reposScanning:p,onRefreshRepos:h,shell:T,onRestart:k}){let A=T?T.split("/").pop():"";return e("div",{className:"h-10 px-3 border-b border-ink/10 bg-paper flex items-center justify-between flex-shrink-0 select-none",children:[e("div",{className:"flex items-center space-x-2 min-w-0",children:[e("div",{className:"flex items-center space-x-1.5",children:[e(_e,{size:14,className:"text-ink/80 flex-shrink-0"}),e("span",{className:"text-xs font-semibold tracking-wider text-ink uppercase",children:"Terminal"})]}),e("span",{className:`inline-flex items-center space-x-1 px-1.5 py-0.5 rounded text-[10px] font-mono border ${it[t]}`,title:t==="exited"&&r!==null?`Shell exited with code ${r}`:void 0,children:[t==="connecting"&&e(m,{size:10,className:"animate-spin"}),e("span",{children:t==="exited"&&r!==null?`EXIT ${r}`:ot[t]})]}),e(fr,{rootPath:l,activeRepo:c,onSelectRepo:d,repos:u,scanning:p,onRefreshRepos:h}),e("button",{type:"button",onClick:k,title:"Kill this shell and start a new one",className:"p-1 rounded text-ink/50 hover:text-ink hover:bg-ink/5 transition-colors cursor-pointer flex-shrink-0",children:e(va,{size:12})})]}),A&&e("span",{className:"hidden sm:block text-[10px] font-mono text-ink/40 flex-shrink-0",children:A})]})}var at=[{label:"bun build",cmd:"bun run build"},{label:"bun test",cmd:"bun test"},{label:"git status",cmd:"git status -s"},{label:"git diff",cmd:"git diff"},{label:"ls -la",cmd:"ls -la"},{label:"pwd",cmd:"pwd"},{label:"bun -v",cmd:"bun --version"}];function ge({onSelectCommand:t,disabled:r}){return e("div",{className:"flex flex-wrap items-center gap-1.5 px-3 py-1.5 bg-paper border-b border-ink/10 flex-shrink-0",children:[e("div",{className:"flex items-center space-x-1 text-[10px] font-mono text-ink/50 uppercase tracking-wider flex-shrink-0 select-none",children:[e(he,{size:11,className:"text-warning"}),e("span",{children:"Quick:"})]}),at.map((l)=>e("button",{type:"button",disabled:r,onClick:()=>t(l.cmd),className:"px-2 py-0.5 rounded text-[10px] font-mono bg-canvas hover:bg-ink/5 active:bg-ink/10 text-ink/80 hover:text-ink border border-ink/15 transition-all whitespace-nowrap disabled:opacity-40 cursor-pointer shadow-2xs",children:l.label},l.cmd))]})}var X=Object.freeze({ctrl:!1,alt:!1}),ie=[{id:"escape",label:"Esc",name:"Escape",sequence:"\x1B"},{id:"tab",label:"Tab",name:"Tab",sequence:"\t"},{id:"interrupt",label:"^C",name:"Ctrl+C — interrupt",sequence:"\x03"},{id:"left",label:"←",name:"Left arrow",csi:{prefix:"1",final:"D",application:"OD"}},{id:"up",label:"↑",name:"Up arrow",csi:{prefix:"1",final:"A",application:"OA"}},{id:"down",label:"↓",name:"Down arrow",csi:{prefix:"1",final:"B",application:"OB"}},{id:"right",label:"→",name:"Right arrow",csi:{prefix:"1",final:"C",application:"OC"}},{id:"home",label:"Home",name:"Home",csi:{prefix:"1",final:"H",application:"OH",terminfo:"\x1BOH"}},{id:"end",label:"End",name:"End",csi:{prefix:"1",final:"F",application:"OF",terminfo:"\x1BOF"}},{id:"pageUp",label:"PgUp",name:"Page up",csi:{prefix:"5",final:"~"}},{id:"pageDown",label:"PgDn",name:"Page down",csi:{prefix:"6",final:"~"}},{id:"delete",label:"Del",name:"Delete",csi:{prefix:"3",final:"~"}},{id:"shiftTab",label:"⇧Tab",name:"Shift+Tab",sequence:"\x1B[Z"},{id:"eof",label:"^D",name:"Ctrl+D — end of input",sequence:"\x04"},{id:"clear",label:"^L",name:"Ctrl+L — clear screen",sequence:"\f"}],ae=[{id:"pipe",label:"|",name:"Pipe",sequence:"|"},{id:"tilde",label:"~",name:"Tilde",sequence:"~"},{id:"dollar",label:"$",name:"Dollar",sequence:"$"},{id:"asterisk",label:"*",name:"Asterisk",sequence:"*"},{id:"question",label:"?",name:"Question mark",sequence:"?"},{id:"underscore",label:"_",name:"Underscore",sequence:"_"},{id:"backslash",label:"\\",name:"Backslash",sequence:"\\"},{id:"slash",label:"/",name:"Slash",sequence:"/"},{id:"minus",label:"-",name:"Minus",sequence:"-"},{id:"equals",label:"=",name:"Equals",sequence:"="},{id:"plus",label:"+",name:"Plus",sequence:"+"},{id:"ampersand",label:"&",name:"Ampersand",sequence:"&"},{id:"semicolon",label:";",name:"Semicolon",sequence:";"},{id:"colon",label:":",name:"Colon",sequence:":"},{id:"comma",label:",",name:"Comma",sequence:","},{id:"dot",label:".",name:"Period",sequence:"."},{id:"at",label:"@",name:"At sign",sequence:"@"},{id:"percent",label:"%",name:"Percent",sequence:"%"},{id:"caret",label:"^",name:"Caret",sequence:"^"},{id:"hash",label:"#",name:"Hash",sequence:"#"},{id:"bang",label:"!",name:"Exclamation mark",sequence:"!"},{id:"parenOpen",label:"(",name:"Open parenthesis",sequence:"("},{id:"parenClose",label:")",name:"Close parenthesis",sequence:")"},{id:"bracketOpen",label:"[",name:"Open bracket",sequence:"["},{id:"bracketClose",label:"]",name:"Close bracket",sequence:"]"},{id:"braceOpen",label:"{",name:"Open brace",sequence:"{"},{id:"braceClose",label:"}",name:"Close brace",sequence:"}"},{id:"lessThan",label:"<",name:"Less than",sequence:"<"},{id:"greaterThan",label:">",name:"Greater than",sequence:">"},{id:"quote",label:"'",name:"Single quote",sequence:"'"},{id:"doubleQuote",label:'"',name:"Double quote",sequence:'"'},{id:"backtick",label:"`",name:"Backtick",sequence:"`"}],Te={};for(let t of[...ie,...ae])Te[t.id]=t;function xe(t,r={}){let l=Te[t];if(!l)return"";let c=r.modifiers??X;if(l.csi)return st(l.csi,c,r.applicationCursorKeys??!1);let d=l.sequence??"";return c.alt?`\x1B${d}`:d}function st(t,r,l){let c=lt(r);if(c!==null)return`\x1B[${t.prefix};${c}${t.final}`;if(t.terminfo)return t.terminfo;if(l&&t.application)return`\x1B${t.application}`;return`\x1B[${t.prefix==="1"?"":t.prefix}${t.final}`}function lt(t){let r=(t.alt?2:0)|(t.ctrl?4:0);return r===0?null:r+1}function we(t,r){if(t.length!==1)return t;let l=t;if(r.ctrl)l=ut(l)??l;if(r.alt)l=`\x1B${l}`;return l}var ct={"@":"\x00"," ":"\x00","":"\b","[":"\x1B","\\":"\x1C","]":"\x1D","^":"\x1E",_:"\x1F","?":""};function ut(t){if(t.length!==1)return null;let r=t.charCodeAt(0);if(r>=97&&r<=122)return String.fromCharCode(r-96);if(r>=65&&r<=90)return String.fromCharCode(r-64);return ct[t]??null}var mt=[{modifier:"ctrl",label:"Ctrl",name:"Ctrl — applies to the next key"},{modifier:"alt",label:"Alt",name:"Alt / meta — applies to the next key"}],W="flex items-center justify-center h-8 min-w-8 px-1.5 rounded border font-mono transition-colors cursor-pointer select-none disabled:opacity-40 disabled:cursor-default text-[11px] @[420px]:h-9 @[420px]:min-w-10 @[420px]:text-xs",V="bg-canvas text-ink/80 border-ink/15 hover:text-ink hover:bg-ink/5 active:bg-ink/10",ve="bg-ink text-canvas border-ink";function Re({modifiers:t,onToggleModifier:r,onKey:l,onCopy:c,onPaste:d,disabled:u}){let[p,h]=n(!1),[T,k]=n(null),A=t.ctrl||t.alt,F=(v)=>{k(v),setTimeout(()=>k((M)=>M===v?null:M),1500)},U=async()=>{F(await c()?"copied":"empty")},B=async()=>{if(!await d())F("pasteFailed")};return e("div",{className:"@container flex flex-col gap-1 px-2 py-1.5 border-t border-ink/10 bg-paper flex-shrink-0",onPointerDown:(v)=>v.preventDefault(),children:[e("div",{className:"flex flex-wrap items-center gap-1",children:[mt.map(({modifier:v,label:M,name:O})=>e("button",{type:"button",onClick:()=>r(v),"aria-pressed":t[v],title:O,"aria-label":O,className:`${W} ${t[v]?ve:V}`,children:M},v)),A&&e("span",{className:"text-[10px] font-mono text-ink/50 px-0.5 whitespace-nowrap","aria-hidden":!0,children:"next"}),e("span",{className:"w-px h-5 bg-ink/15 flex-shrink-0","aria-hidden":!0}),e("button",{type:"button",onClick:U,disabled:u,title:T==="empty"?"Nothing selected":"Copy selection","aria-label":"Copy selection",className:`${W} ${T==="empty"?"bg-warning/10 text-warning border-warning/30":V}`,children:[T==="copied"?e(f,{size:13}):e(be,{size:13}),e("span",{className:"pl-1",children:"Copy"})]}),e("button",{type:"button",onClick:B,disabled:u,title:T==="pasteFailed"?"Clipboard unavailable":"Paste into the shell","aria-label":"Paste into the shell",className:`${W} ${T==="pasteFailed"?"bg-error/10 text-error border-error/30":V}`,children:[e(Ss,{size:13}),e("span",{className:"pl-1",children:"Paste"})]}),e("button",{type:"button",onClick:()=>h((v)=>!v),"aria-pressed":p,title:p?"Show control keys":"Show symbols","aria-label":p?"Show control keys":"Show symbols",className:`${W} ml-auto ${p?ve:V}`,children:p?"ABC":"123"})]}),e("div",{className:"flex flex-wrap items-center gap-1",children:(p?ae:ie).map((v)=>e("button",{type:"button",disabled:u,onClick:()=>l(v.id),title:v.name,"aria-label":v.name,className:`${W} ${V}`,children:v.label},v.id))})]})}function Se(t){if(!t.startsWith("\x1B[M")||t.length<6)return{text:t};let r=new Uint8Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=t.charCodeAt(l)&255;return{bytes:r}}function Ce(t){let r=ln(t),{canvas:l,ink:c,paper:d}=r,u=(h)=>kr(h,c,0.2),p=(h)=>kr(l,c,h);return{background:"transparent",foreground:c,cursor:r.meta,cursorAccent:d,selectionBackground:p(0.28),selectionForeground:c,black:p(0.2),red:r.error,green:r.success,yellow:r.warning,blue:r.info,magenta:r.meta,cyan:kr(r.info,r.success,0.5),white:p(0.75),brightBlack:p(0.5),brightRed:u(r.error),brightGreen:u(r.success),brightYellow:u(r.warning),brightBlue:u(r.info),brightMagenta:u(r.meta),brightCyan:u(kr(r.info,r.success,0.5)),brightWhite:p(0.92)}}var J="Fira Code",dt="'FiraCode Nerd Font Mono', 'FiraCode Nerd Font', 'JetBrainsMono Nerd Font', 'JetBrainsMono NF', 'JetBrains Mono Nerd Font', 'Hack Nerd Font', 'MesloLGS NF', 'MesloLGM Nerd Font', 'CaskaydiaCove Nerd Font', 'SauceCodePro Nerd Font', 'Symbols Nerd Font Mono', 'Symbols Nerd Font', 'PowerlineSymbols'",ke="Kabmo Nerd Symbols",Ae=[J,ke],j=`'${J}', ${dt}, '${ke}', Menlo, Monaco, 'Courier New', monospace`,Y=12,pt=16,ft=1e4;function bt(t,r){return Math.max(1,t)*Math.max(1,r)*pt}var Me=bt(ft,100);var ht=2000;async function Fe(){if(typeof document>"u"||!document.fonts?.load)return;let t=Promise.withResolvers(),r=setTimeout(t.resolve,ht);try{await Promise.race([document.fonts.load(`${Y}px "${J}"`).then(()=>{return},()=>{return}),t.promise])}finally{clearTimeout(r)}}function Le(t){if(typeof document>"u"||!document.fonts)return()=>{};let r=new Set(Ae),l=(c)=>{if([...c.fontfaces].some((u)=>r.has(u.family.replace(/['"]/g,"").trim())))t()};return document.fonts.addEventListener("loadingdone",l),()=>document.fonts.removeEventListener("loadingdone",l)}var Ee=2.5,yt=1;function gt(t,r){let l=t*0.8,c=t*0.2,d=Math.ceil(t*0.6),u=l,p=c,h=typeof document>"u"?null:document.createElement("canvas").getContext("2d");if(h){h.font=`${t}px ${r}`,d=Math.ceil(h.measureText("M").width)||d;let T=h.measureText("Mg");u=T.actualBoundingBoxAscent||l,p=T.actualBoundingBoxDescent||c}return{width:d,height:Math.ceil(u+p+Ee+yt),baseline:Math.round(u+Ee)}}function Ne(t){let r=t.renderer;if(!r)return;r.measureFont=()=>gt(t.options.fontSize??Y,t.options.fontFamily??j),r.remeasureFont()}function Tt(t,r,l){if(!l.width||!l.height)return null;return{cols:Math.max(2,Math.floor(t/l.width)),rows:Math.max(1,Math.floor(r/l.height))}}function Ie(t,r){let l=t;l.proposeDimensions=()=>{let c=r.element,d=r.renderer?.getMetrics();if(!c||!d)return;let u=getComputedStyle(c),p=(parseFloat(u.paddingLeft)||0)+(parseFloat(u.paddingRight)||0),h=(parseFloat(u.paddingTop)||0)+(parseFloat(u.paddingBottom)||0);return Tt(c.clientWidth-p,c.clientHeight-h,d)??void 0}}function xt(t){let{cols:r,rows:l,attached:c,committed:d}=t;if(r<10||l<5)return{kind:"ignore"};if(!c)return{kind:"attach",cols:r,rows:l};if(r===d.cols&&l===d.rows)return{kind:"ignore"};return{kind:"change",cols:r,rows:l}}function Oe(t){let r={cols:0,rows:0},l=!1,c,d=()=>{if(!t.fit())return;let u=t.current();if(!u)return;let p=xt({cols:u.cols,rows:u.rows,attached:l,committed:r});if(p.kind==="ignore")return;if(r={cols:p.cols,rows:p.rows},p.kind==="attach"){l=!0,t.onReady(p.cols,p.rows);return}t.onGridChange(p.cols,p.rows)};return{schedule(){clearTimeout(c),c=setTimeout(d,120)},restate(){r={cols:0,rows:0}},isAttached:()=>l,dispose(){clearTimeout(c),c=void 0}}}function Pe(t,r){if(r.type!=="keydown"||!r.shiftKey)return!1;if(r.key==="PageUp")return t.scrollPages(-1),!0;if(r.key==="PageDown")return t.scrollPages(1),!0;if(r.key==="Home")return t.scrollToTop(),!0;if(r.key==="End")return t.scrollToBottom(),!0;if(r.key==="ArrowUp")return t.scrollLines(-1),!0;if(r.key==="ArrowDown")return t.scrollLines(1),!0;return!1}function Ue(t,r){let l=0,c=(u)=>{if(u.touches.length===1)l=u.touches[0].clientY},d=(u)=>{if(u.touches.length!==1)return;let p=l-u.touches[0].clientY;if(Math.abs(p)<16)return;r()?.scrollLines(Math.trunc(p/16)),l=u.touches[0].clientY};return t.addEventListener("touchstart",c,{passive:!0}),t.addEventListener("touchmove",d,{passive:!0}),()=>{t.removeEventListener("touchstart",c),t.removeEventListener("touchmove",d)}}function wt(t){if(t.viewportY<=0&&!t.hasSelection&&!t.pointerHeld)return null;return t.scrollback-t.viewportY}function vt(t){let r=t.scrollback-t.top;return r>0?r:null}function Be(t){let r={pointerHeld:!1},l=()=>{r.pointerHeld=!0},c=()=>{r.pointerHeld=!1};return t.addEventListener("pointerdown",l,!0),globalThis.addEventListener("pointerup",c),globalThis.addEventListener("pointercancel",c),{get pointerHeld(){return r.pointerHeld},stop(){t.removeEventListener("pointerdown",l,!0),globalThis.removeEventListener("pointerup",c),globalThis.removeEventListener("pointercancel",c)}}}function De(t,r,l){let c=wt({scrollback:t.getScrollbackLength(),viewportY:t.getViewportY(),hasSelection:t.hasSelection(),pointerHeld:r.pointerHeld});if(l(),c===null)return;let d=vt({scrollback:t.getScrollbackLength(),top:c});if(d===null)return;let u=d-t.getViewportY();if(u===0)return;try{t.scrollLines(-u)}catch{}}async function qe(t,r,l,c){let d=await import("./ghostty-web-2gt2tp72.js"),[u]=await Promise.all([d.Ghostty.load(),Fe()]);if(c())return null;let p=r,h=null,T=!1,k,A=null,F=!1,U=(g)=>{let{term:x}=g;x.attachCustomKeyEventHandler((L)=>Pe(x,L)),g.disposables.push(x.onScroll((L)=>l.onScrolledUpChange(L>0)),x.onData((L)=>{let N=Se(L);if(N.bytes)l.onBinaryInput(N.bytes);else l.onInput(N.text)}),x.onResize(()=>{if(T)return;y.schedule()}))},B=(g)=>{let x=new d.Terminal({cursorBlink:!0,cursorStyle:"block",fontSize:Y,fontFamily:j,theme:Ce(g),scrollback:Me,smoothScrollDuration:0,ghostty:u});x.open(t),Ne(x),x.clear();let L=new d.FitAddon;x.loadAddon(L),Ie(L,x);let N={term:x,fitAddon:L,disposables:[]};return U(N),N},v=(g)=>{if(!g)return;for(let x of g.disposables)try{x.dispose()}catch{}try{g.fitAddon.dispose()}catch{}try{g.term.dispose()}catch{}},M=()=>{if(F)return!1;if(t.clientWidth<=0||t.clientHeight<=0)return!1;let g=h?.term.renderer?.getMetrics();if(!g?.width||!g.height)return!1;try{return h?.fitAddon.fit(),!0}catch{return!1}},O=()=>{if(F)return;T=!1,M(),y.restate(),y.schedule()},b=(g,x,L)=>{let N=h?.term;if(!N)return;if(T=!0,N.cols!==x||N.rows!==L)N.resize(x,L);if(g.length===0){requestAnimationFrame(O);return}N.write(g,O)},y=Oe({current:()=>h?.term,fit:M,onReady:l.onReady,onGridChange:l.onGridChange}),P=Be(t);h=B(p),M(),y.schedule();let E=new ResizeObserver(()=>{clearTimeout(k),k=setTimeout(()=>{M(),y.schedule()},35)});E.observe(t);let D=Le(()=>{let g=h?.term;if(!g)return;let x=g.options.fontSize??Y;g.options.fontSize=x+0.1,g.options.fontSize=x,M(),y.schedule()}),R=Ue(t,()=>h?.term??null);return A=requestAnimationFrame(()=>{M(),y.schedule()}),{write(g){let x=h?.term;if(!x)return;De(x,P,()=>x.write(g))},writeReplay:b,reset(){let g=h?.term;if(!g)return;g.reset(),g.clear(),M()},focus(){h?.term.focus()},applicationCursorKeys(){return h?.term.wasmTerm?.getMode(1,!1)??!1},getSelection(){return h?.term.getSelection()??""},paste(g){h?.term.paste(g)},scrollToBottom(){h?.term.scrollToBottom()},setTheme(g){if(F||g===p)return;p=g,v(h),h=B(g),M()},dispose(){if(F=!0,A!==null)cancelAnimationFrame(A);clearTimeout(k),y.dispose(),D(),R(),P.stop(),E.disconnect(),v(h),h=null}}}function Ke(){let t=null,r=!1;return{request(){if(t)t();else r=!0},attach(l){if(t=l,!r)return;r=!1,l()},detach(){t=null,r=!1}}}var se=Ts(({onInput:t,onBinaryInput:r,onGridChange:l,onReady:c,onReattach:d},u)=>{let{theme:p}=Rp(),h=o(null),T=o(null),[k,A]=n(!1),F=o(null);if(!F.current)F.current=Ke();let U=F.current,B=o(t);B.current=t;let v=o(r);v.current=r;let M=o(l);M.current=l;let O=o(c);O.current=c;let b=o(d);b.current=d;let y=o(p);y.current=p,i(()=>{let E=T.current;if(!E)return;E.setTheme(p),b.current?.()},[p]),si(u,()=>({write(E){T.current?.write(E)},writeReplay(E,D,R){T.current?.writeReplay(E,D,R)},reset(){T.current?.reset()},focus(){U.request()},applicationCursorKeys(){return T.current?.applicationCursorKeys()??!1},getSelection(){return T.current?.getSelection()??""},paste(E){T.current?.paste(E)}}),[]);let P=a(()=>{T.current?.scrollToBottom(),A(!1)},[]);return i(()=>{let E=h.current;if(!E)return;let D=!1;return qe(E,y.current,{onInput:(R)=>B.current(R),onBinaryInput:(R)=>v.current(R),onGridChange:(R,g)=>M.current(R,g),onReady:(R,g)=>O.current(R,g),onScrolledUpChange:A},()=>D).then((R)=>{if(!R)return;if(D){R.dispose();return}T.current=R,E.querySelector("textarea")?.setAttribute("data-terminal-input",""),U.attach(()=>T.current?.focus())}),()=>{D=!0,U.detach(),T.current?.dispose(),T.current=null}},[]),e("div",{className:"relative flex-1 w-full h-full overflow-hidden p-2",children:[e("div",{ref:h,"data-terminal-root":"",className:"kabmo-terminal w-full h-full cursor-text",style:{height:"100%",width:"100%"}}),k&&e("button",{type:"button",onClick:P,className:"absolute bottom-3 right-4 z-20 flex items-center space-x-1.5 px-2.5 py-1 bg-paper hover:bg-canvas text-ink border border-ink/20 rounded-full shadow-lg text-[11px] font-mono transition-all animate-fade-in cursor-pointer active:scale-95",title:"Scroll to latest output (Shift+End)",children:[e(Or,{size:12,className:"text-warning"}),e("span",{children:"Latest"})]})]})});se.displayName="RealtimeTerminalView";var le=new TextEncoder;function $n({className:t="",enabled:r=!0,rootPath:l,showHeader:c=!0,active:d=!0}){let u=o(null),{isDark:p}=Rp(),h=_u(),T=o(null),k=Hl(T),[A,F]=n(X),{activeRepo:U,setActiveRepo:B}=ir(l),{repos:v,scanning:M,rescan:O}=or(l,r),b=o(null),y=o(A);y.current=A;let P=a((C)=>{u.current?.write(C)},[]);i(()=>{if(!d||!r)return;u.current?.focus()},[d,r]);let E=a((C,_)=>{u.current?.writeReplay(C,_.replayCols,_.replayRows)},[]),D=a(()=>{u.current?.reset()},[]),{status:R,shell:g,exitCode:x,error:L,attach:N,resize:z,input:H,restart:Q,reattach:Z}=fe({visible:d&&r,root:r?l:void 0,repo:U,theme:p?"dark":"light",onOutput:P,onReplay:E,onRestart:D}),ee=a((C,_)=>{b.current={cols:C,rows:_},N(C,_)},[N]),te=a((C,_)=>{let ne=b.current;if(b.current={cols:C,rows:_},!ne)return;z(C,_)},[z]),I=a((C)=>{let _=y.current,ne=_.ctrl||_.alt,We=we(C,_);if(ne&&C.length===1)F(X);H(le.encode(We))},[H]),q=a((C)=>{F((_)=>({..._,[C]:!_[C]})),u.current?.focus()},[]),K=a((C)=>{let _=xe(C,{applicationCursorKeys:u.current?.applicationCursorKeys()??!1,modifiers:y.current});if(!_)return;H(le.encode(_)),F(X),u.current?.focus()},[H]),G=a(async()=>{let C=u.current?.getSelection()??"";if(!C)return!1;return hn(C)},[]),He=a(async()=>{let C=await $A();if(C===null||C.length===0)return!1;return u.current?.paste(C),u.current?.focus(),!0},[]),ze=a((C)=>{H(C)},[H]),Ye=a((C)=>{H(le.encode(`${C}\r`)),u.current?.focus()},[H]),Ge=a(()=>{Q()},[Q]),Xe=a(()=>{Z()},[Z]);if(!r)return e("div",{className:`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${t}`,children:e("span",{className:"text-xs font-mono text-muted",children:"No session selected"})});return e("div",{ref:T,className:`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${t}`,"aria-hidden":!d,style:k>0?{paddingBottom:k}:void 0,children:[c&&e(ye,{status:R,exitCode:x,rootPath:l,activeRepo:U,onSelectRepo:B,repos:v,reposScanning:M,onRefreshRepos:O,shell:g,onRestart:Ge}),e(ge,{onSelectCommand:Ye,disabled:R!=="running"}),L&&e("div",{className:"px-3 py-1.5 border-b border-error/20 bg-error/5 text-[11px] font-mono text-error flex-shrink-0",children:L}),e("div",{className:"flex-1 w-full min-h-0 bg-canvas overflow-hidden",children:e(se,{ref:u,onInput:I,onBinaryInput:ze,onReady:ee,onGridChange:te,onReattach:Xe})}),h&&e(Re,{modifiers:A,onToggleModifier:q,onKey:K,onCopy:G,onPaste:He,disabled:R!=="running"})]})}export{$n as TerminalPanel};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{d,n,i,a,e,s,B,C,nt,Me}from"./index-4s8ttfxj.js";var M={name:"ticket",size:24,node:[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]},S=s(M);function P({providerName:t,providerSlug:r,iconUrl:o,credentialSources:l,error:p,note:c,children:m}){return e("section",{className:"bg-paper border border-ink/15 rounded-lg shadow-xs",children:[e("header",{className:"flex items-center justify-between gap-2 px-3.5 py-2.5 border-b border-ink/10",children:[e("span",{className:"flex min-w-0 items-center gap-2",children:[r&&e(Me,{provider:{slug:r,name:t,...o?{iconUrl:o}:{}},size:20}),e("span",{className:"truncate text-xs font-semibold text-ink",children:t})]}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/50 truncate",title:`Credentials from ${l.join(", ")}`,children:l.join(" · ")})]}),e("div",{className:"p-3.5 space-y-4",children:[p&&e("p",{className:"flex items-start gap-2 text-error text-xs leading-relaxed",children:[e(B,{size:14,className:"shrink-0 mt-0.5"}),e("span",{className:"break-words",children:p})]}),m,c&&e("p",{className:"text-[10px] text-ink/50 leading-relaxed border-t border-ink/10 pt-2.5",children:c})]})]})}var q=new Intl.NumberFormat("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0}),j=new Intl.NumberFormat("id-ID"),y=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2,useGrouping:!1}),G=new Intl.DateTimeFormat("id-ID",{dateStyle:"medium",timeStyle:"short"});function x(t){return q.format(t)}function b(t){return j.format(t)}function Xr(t){let r=new Date(t);if(Number.isNaN(r.getTime()))return t;return G.format(r)}function L(t,r){if(r<=0)return 0;return Math.min(100,Math.max(0,t/r*100))}function T(t,r){if(r<=0)return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t/r*100)}%`}function k(t){if(!Number.isFinite(t))return"0";let r=Math.abs(t);if(r>=1e9)return`${y.format(t/1e9)}B`;if(r>=1e6)return`${y.format(t/1e6)}M`;if(r>=1000)return`${y.format(t/1000)}K`;return b(t)}function N(t){let r=Number(t);if(t.trim()===""||!Number.isFinite(r))return t;return b(r)}var O=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2});function U(t){if(!Number.isFinite(t))return"$0,00";return`$${O.format(t)}`}function w(t,r){if(!Number.isFinite(t))return"—";switch(r){case"percent":return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t)}%`;case"usd":return U(t);case"tokens":case"bytes":return k(t);default:return b(t)}}function I(t){if(!Number.isFinite(t))return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t*100)}%`}function z({window:t}){let r=t.usedRp+t.remainingRp,o=L(t.usedRp,r);return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:t.label}),e("span",{className:"text-[10px] text-ink/50",children:["Resets ",Xr(t.resetsAt)]})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-ink/80 rounded-full",style:{width:`${o}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})," ·"," ",T(t.usedRp,r)]}),e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:x(t.remainingRp)})]})]})]})}function H({coupon:t}){return e("div",{className:"bg-ink/5 border border-ink/10 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e(S,{size:12,className:"text-ink/60"}),e("span",{className:"text-[11px] font-semibold text-ink",children:["Active coupon · ",t.name]})]}),e("div",{className:"text-[10px] text-ink/60 space-y-0.5",children:[e("div",{children:["Remaining"," ",e("span",{className:"font-semibold text-ink",children:t.remainingRp===null?"Unlimited":x(t.remainingRp)})," ","· Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})]}),e("div",{children:["Expires ",Xr(t.expiresAt)]}),t.scopeModels.length>0&&e("div",{children:["Models: ",t.scopeModels.join(", ")]})]})]})}function D({quota:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"Quota data is not available for this account."});return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),t.planName&&e("span",{className:"text-[10px] text-ink/60",children:["Plan ",e("span",{className:"font-semibold text-ink",children:t.planName})]})]}),t.windows.length===0?e("p",{className:"text-[11px] text-ink/50",children:"No quota windows reported."}):e("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2.5",children:t.windows.map((r)=>e(z,{window:r},r.key))}),t.coupon&&e(H,{coupon:t.coupon})]})}function A({usage:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"The 30-day usage report is not available."});let r=t.rows.reduce((l,p)=>l+p.inputTokens,0),o=t.rows.reduce((l,p)=>l+p.outputTokens,0);return e("div",{className:"space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"30-day usage by model"}),e("div",{className:"overflow-x-auto border border-ink/15 rounded-lg shadow-xs",children:e("table",{className:"w-full text-[11px]",children:[e("thead",{className:"bg-ink/5 text-ink/60",children:e("tr",{children:[e("th",{className:"text-left font-semibold px-3 py-2 whitespace-nowrap",children:"Model"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Requests"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Input tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Output tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Cost"})]})}),e("tbody",{className:"divide-y divide-ink/10",children:t.rows.length===0?e("tr",{children:e("td",{colSpan:5,className:"px-3 py-3 text-center text-ink/50",children:"No usage recorded in the last 30 days."})}):t.rows.map((l)=>e("tr",{children:[e("td",{className:"px-3 py-1.5 font-mono text-ink whitespace-nowrap",children:l.model}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:b(l.requests)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.inputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.outputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:x(l.costRp)})]},l.model))}),e("tfoot",{className:"bg-ink/5 border-t border-ink/15 font-semibold text-ink",children:e("tr",{children:[e("td",{className:"px-3 py-2",children:"Total"}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:b(t.totalRequests)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(r)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(o)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:x(t.totalCostRp)})]})})]})})]})}function F({report:t}){let{balance:r,usage:o,quota:l}=t;if(!r&&!o&&!l)return e("p",{className:"text-[11px] text-ink/50",children:"No kenari data was returned for this account."});let p=r?r.amountRp!==null?x(r.amountRp):r.raw:"–",c=r?r.amountRp!==null?r.raw:"Amount could not be parsed":"Balance unavailable",m=o?o.rows.reduce((g,u)=>g+u.inputTokens+u.outputTokens,0):0;return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(nt,{value:p,label:"Wallet balance",hint:c}),e(nt,{value:l?.planName??"–",label:"Active plan",hint:l?"kenari quota plan":"Quota unavailable"}),e(nt,{value:o?b(o.totalRequests):"–",label:"Requests (30 days)",hint:o?"Across all models":"Usage report unavailable"}),e(nt,{value:o?x(o.totalCostRp):"–",label:"Cost (30 days)",hint:o?"Billed in Rupiah":"Usage report unavailable"}),e(nt,{value:o?k(m):"–",label:"Tokens processed (30 days)",hint:o?"Input + output":"Usage report unavailable",tone:"muted",className:"col-span-2 @[540px]:col-span-1"})]})}),e(D,{quota:l}),e(A,{usage:o})]})}function E({report:t}){let r=t.balance;if(!r)return e("p",{className:"text-[11px] text-ink/50",children:"DeepSeek balance data is not available."});return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(nt,{value:r.isAvailable?"Available":"Unavailable",label:"Prepaid balance",hint:r.isAvailable?"Account can spend":"Top up required",tone:r.isAvailable?"default":"muted"}),e(nt,{value:b(r.entries.length),label:"Currency buckets",hint:r.entries.length>0?"From the balance endpoint":"No entries returned",tone:"muted"})]})}),r.entries.length===0?e("p",{className:"text-[11px] text-ink/50",children:"The balance endpoint returned no currency entries."}):e("div",{className:"grid grid-cols-1 gap-2.5",children:r.entries.map((o)=>e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:o.currency}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/40",children:"Balance"})]}),e("dl",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[e("div",{children:[e("dt",{className:"text-ink/50",children:"Total"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.totalBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Granted"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.grantedBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Topped up"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.toppedUpBalance)})]})]})]},o.currency))})]})}function R(t,r,o,l){let p=t.find((c)=>c.id===r);if(p){p.limits.push(l);return}t.push({id:r,title:o,limits:[l]})}function V(t){let r=(t.split(":")[1]??"").toLowerCase();if(r==="google")return{id:"google",title:"Google"};if(r==="anthropic"||r==="openai")return{id:"third-party",title:"Claude & GPT (shared)"};if(r==="default"||r==="")return{id:"default",title:"Usage"};return{id:r,title:r}}function X(t){let r=[];for(let o of t)if(o.id==="anthropic:extra")R(r,"balance","Balance",o);else R(r,"windows","Quota windows",o);return r}function J(t){let r=[];for(let o of t){let l=V(o.id);if(l.id==="third-party"){if(r.find((c)=>c.id==="third-party")?.limits.some((c)=>Z(c,o)))continue}R(r,l.id,l.title,o)}return r}function Z(t,r){return t.unit===r.unit&&t.label===r.label&&t.usedFraction===r.usedFraction&&t.remaining===r.remaining&&t.resetsAt===r.resetsAt}function W(t,r){if(r.length===0)return[];let o=t.trim().toLowerCase();if(o==="anthropic")return X(r);if(o==="google-antigravity")return J(r);return[{id:"all",title:"Quota windows",limits:[...r]}]}function Y({limit:t}){let r=Math.min(100,Math.max(0,(t.usedFraction??0)*100)),o=t.modelId??t.accountId,l=t.used!==void 0?w(t.used,t.unit):void 0,p=t.limit!==void 0?w(t.limit,t.unit):void 0,c=t.remaining!==void 0?w(t.remaining,t.unit):void 0;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[t.label,t.windowLabel&&e("span",{className:"ml-1.5 rounded border border-ink/15 px-1 py-px font-mono text-[9px] font-normal text-ink/50",children:t.windowLabel})]}),o&&e("div",{className:"text-[10px] text-ink/50 truncate",children:o})]}),e("span",{className:"text-[10px] text-ink/50 flex-shrink-0 whitespace-nowrap",children:t.resetsAt!==void 0?`Resets ${Xr(new Date(t.resetsAt).toISOString())}`:""})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:`h-full rounded-full ${t.status==="exhausted"?"bg-error/70":"bg-ink/80"}`,style:{width:`${r}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used"," ",e("span",{className:"font-semibold text-ink",children:t.unit==="percent"||!l?I(t.usedFraction??0):l}),t.unit!=="percent"&&l&&p?` of ${p}`:""]}),e("span",{className:"flex items-center gap-2",children:[t.status!=="ok"&&t.status!=="unknown"&&e("span",{className:"text-[10px] font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/70",children:t.status}),c&&e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:c})]})]})]}),t.notes&&t.notes.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:t.notes.map((m)=>e("li",{children:m},m))})]})}function _({providerId:t,limits:r,tracked:o,unavailable:l,notes:p}){let c=W(t,r);return e("div",{className:"space-y-2",children:[p&&p.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:p.map((m)=>e("li",{children:m},m))}),c.length===0?e(d,{children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),e("p",{className:"text-[11px] text-ink/50",children:!o?"No quota source for this provider: omp ships no usage adapter for it and it exposes no balance endpoint Kabmo knows.":l?"omp tracks this provider but its usage endpoint returned no data — an invalid or expired credential, an unreachable endpoint, or a plan without quota windows.":"No quota windows were reported for this provider."})]}):c.map((m)=>e("div",{className:"@container space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:m.title}),e("div",{className:"grid grid-cols-1 @[520px]:grid-cols-2 gap-2.5",children:m.limits.map((g)=>e(Y,{limit:g},g.id))})]},m.id))]})}var ee="DeepSeek exposes no usage or quota API — only the prepaid balance (and the web console at platform.deepseek.com) is available.";function iu({summary:t}){let r=Boolean(t.kenari||t.deepseek);return e(P,{providerName:t.name,providerSlug:t.id,iconUrl:t.iconUrl,credentialSources:t.credentialSources,error:t.error,note:t.deepseek?ee:void 0,children:[t.kenari&&e(F,{report:t.kenari}),t.deepseek&&e(E,{report:t.deepseek}),!r&&(t.limits.length>0||!t.error)&&e(_,{providerId:t.id,limits:t.limits,tracked:t.tracked,unavailable:t.limitsUnavailable,notes:t.notes})]})}function te(t){let r=t.filter((p)=>p.usedFraction!==void 0);if(r.length===0){let p=t.find((c)=>c.unit==="usd"&&c.remaining!==void 0);if(p)return`${U(p.remaining??0)} left`;return t[0]?.label}let o=r.reduce((p,c)=>(c.usedFraction??0)>(p.usedFraction??0)?c:p),l=Math.round((o.usedFraction??0)*100);return o.windowLabel?`${l}% · ${o.windowLabel}`:`${l}% used`}function ys(t){return t.providers.map((r)=>({id:r.id,name:r.name,...r.iconUrl?{iconUrl:r.iconUrl}:{},error:r.error,hint:ne(r),limits:r.limits,tracked:r.tracked,limitsUnavailable:r.limitsUnavailable,summary:r}))}function ne(t){let r=t.kenari?.quota?.planName;if(r)return r;let o=t.deepseek?.balance?.entries[0];if(o)return`${o.currency} ${N(o.totalBalance)}`;return te(t.limits)??"No quota reported"}function vs(t){return t.error?"Error":"Connected"}function Q(){let[t,r]=n([]),[o,l]=n(null),[p,c]=n(!0),m=a(()=>{c(!0),fetch("/api/settings/usage/reset").then((u)=>u.json()).then((u)=>{r(Array.isArray(u.accounts)?u.accounts:[]),l(typeof u.error==="string"?u.error:null)}).catch((u)=>{r([]),l(u instanceof Error?u.message:"Failed to load saved resets")}).finally(()=>c(!1))},[]);i(()=>{m()},[m]);let g=a(async(u)=>{try{let h=await(await fetch("/api/settings/usage/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:u})})).json();if(h.ok)m();return{ok:Boolean(h.ok),message:h.message||"No result reported."}}catch(f){return{ok:!1,message:f instanceof Error?f.message:"Failed to spend the saved reset"}}},[m]);return{accounts:t,error:o,isLoading:p,reload:m,spend:g}}function ae({account:t,onSpend:r,spending:o}){let l=`${t.provider}/${t.credentialId}`,p=t.email??t.accountId??t.credentialId,c=t.orgName??t.orgId,m=t.availableCount??t.credits.length,g=t.redeemableCount??0,u=t.error??t.unavailableReason;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[p,c?e("span",{className:"text-ink/50 font-normal",children:[" · ",c]}):null]}),e("div",{className:"text-[10px] text-ink/50 font-mono truncate",children:l})]}),e("span",{className:"text-[10px] text-ink/60 flex-shrink-0 whitespace-nowrap",children:g>0?`${g} of ${m} usable`:`${m} saved`})]}),t.soonestExpiry!==void 0&&e("div",{className:"text-[10px] text-ink/60",children:["Soonest expires ",Xr(new Date(t.soonestExpiry).toISOString())]}),t.credits.length>0&&e("div",{className:"space-y-1",children:t.credits.map((f)=>e("div",{className:"flex items-center justify-between gap-2 text-[10px] text-ink/70",children:[e("span",{className:"truncate",children:f.title??f.program??f.id}),e("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[f.clears&&f.clears.length>0&&e("span",{className:"font-mono text-ink/50",children:f.clears.join(", ")}),f.usable===!1&&e("span",{className:"font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/60",children:"blocked"})]})]},f.id))}),u&&e("div",{className:"text-[10px] text-ink/60 leading-snug",children:u}),e("button",{type:"button",onClick:()=>r(l),disabled:o||g===0,title:g===0?u??"Nothing to spend on this account right now.":`Spend a saved reset on ${l}`,className:"w-full rounded-md border border-ink/15 px-2 py-1 text-[11px] font-medium text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:o?"Spending…":"Spend saved reset"})]})}function ou(){let{accounts:t,error:r,isLoading:o,reload:l,spend:p}=Q(),[c,m]=n(null),[g,u]=n(null),f=(v)=>{m(v),u(null),p(v).then((K)=>{u(K),m(null)})},h=!o&&!r&&t.length===0;return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink",children:"Saved rate-limit resets"}),e("div",{className:"text-[10px] text-ink/50 leading-snug",children:"Provider-issued resets for Codex and Claude accounts. Spending one clears the window it covers."})]}),e("button",{type:"button",onClick:l,disabled:o,title:"Re-read saved resets",className:"p-1.5 bg-paper border border-ink/15 rounded-md hover:bg-ink/5 text-ink/80 transition-colors disabled:opacity-50 flex-shrink-0",children:e(C,{size:12,className:o?"animate-spin text-ink":""})})]}),r&&e("div",{className:"flex items-start gap-1.5 text-[10px] text-error leading-snug",children:[e(B,{size:12,className:"flex-shrink-0 mt-px"}),e("span",{children:r})]}),t.map((v)=>e(ae,{account:v,onSpend:f,spending:c===`${v.provider}/${v.credentialId}`},`${v.provider}/${v.credentialId}`)),h&&e("p",{className:"text-[10px] text-ink/50 leading-snug",children:"No saved resets on any account."}),g&&e("div",{className:`text-[10px] leading-snug ${g.ok?"text-ink/70":"text-error"}`,children:g.message})]})}function su(){let[t,r]=n(null),[o,l]=n(!0),[p,c]=n(null),m=a(async(g)=>{if(!g?.silent)l(!0);c(null);try{let u=g?.force?"/api/settings/usage?refresh=1":"/api/settings/usage",f=await fetch(u);if(!f.ok)throw Error(`Usage request failed (${f.status})`);let h=await f.json();r(h)}catch(u){c(u instanceof Error?u.message:"Failed to load provider usage")}finally{if(!g?.silent)l(!1)}},[]);return i(()=>{m()},[m]),{report:t,isLoading:o,error:p,reload:m}}
|
|
2
|
-
export{Xr,
|
|
1
|
+
import{d,n,i,a,e,s,I,C,nt,Le}from"./index-zt75xpq0.js";var q={name:"ticket",size:24,node:[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]},S=s(q);function P({providerName:t,providerSlug:r,iconUrl:o,credentialSources:l,error:p,note:c,children:m}){return e("section",{className:"bg-paper border border-ink/15 rounded-lg shadow-xs",children:[e("header",{className:"flex items-center justify-between gap-2 px-3.5 py-2.5 border-b border-ink/10",children:[e("span",{className:"flex min-w-0 items-center gap-2",children:[r&&e(Le,{provider:{slug:r,name:t,...o?{iconUrl:o}:{}},size:20}),e("span",{className:"truncate text-xs font-semibold text-ink",children:t})]}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/50 truncate",title:`Credentials from ${l.join(", ")}`,children:l.join(" · ")})]}),e("div",{className:"p-3.5 space-y-4",children:[p&&e("p",{className:"flex items-start gap-2 text-error text-xs leading-relaxed",children:[e(I,{size:14,className:"shrink-0 mt-0.5"}),e("span",{className:"break-words",children:p})]}),m,c&&e("p",{className:"text-[10px] text-ink/50 leading-relaxed border-t border-ink/10 pt-2.5",children:c})]})]})}var B=new Intl.NumberFormat("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0}),j=new Intl.NumberFormat("id-ID"),y=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2,useGrouping:!1}),G=new Intl.DateTimeFormat("id-ID",{dateStyle:"medium",timeStyle:"short"});function x(t){return B.format(t)}function b(t){return j.format(t)}function Xr(t){let r=new Date(t);if(Number.isNaN(r.getTime()))return t;return G.format(r)}function L(t,r){if(r<=0)return 0;return Math.min(100,Math.max(0,t/r*100))}function T(t,r){if(r<=0)return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t/r*100)}%`}function k(t){if(!Number.isFinite(t))return"0";let r=Math.abs(t);if(r>=1e9)return`${y.format(t/1e9)}B`;if(r>=1e6)return`${y.format(t/1e6)}M`;if(r>=1000)return`${y.format(t/1000)}K`;return b(t)}function N(t){let r=Number(t);if(t.trim()===""||!Number.isFinite(r))return t;return b(r)}var O=new Intl.NumberFormat("id-ID",{minimumFractionDigits:2,maximumFractionDigits:2});function U(t){if(!Number.isFinite(t))return"$0,00";return`$${O.format(t)}`}function w(t,r){if(!Number.isFinite(t))return"—";switch(r){case"percent":return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t)}%`;case"usd":return U(t);case"tokens":case"bytes":return k(t);default:return b(t)}}function D(t){if(!Number.isFinite(t))return"0%";return`${new Intl.NumberFormat("id-ID",{maximumFractionDigits:1}).format(t*100)}%`}function z({window:t}){let r=t.usedRp+t.remainingRp,o=L(t.usedRp,r);return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:t.label}),e("span",{className:"text-[10px] text-ink/50",children:["Resets ",Xr(t.resetsAt)]})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-ink/80 rounded-full",style:{width:`${o}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})," ·"," ",T(t.usedRp,r)]}),e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:x(t.remainingRp)})]})]})]})}function H({coupon:t}){return e("div",{className:"bg-ink/5 border border-ink/10 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e(S,{size:12,className:"text-ink/60"}),e("span",{className:"text-[11px] font-semibold text-ink",children:["Active coupon · ",t.name]})]}),e("div",{className:"text-[10px] text-ink/60 space-y-0.5",children:[e("div",{children:["Remaining"," ",e("span",{className:"font-semibold text-ink",children:t.remainingRp===null?"Unlimited":x(t.remainingRp)})," ","· Used ",e("span",{className:"font-semibold text-ink",children:x(t.usedRp)})]}),e("div",{children:["Expires ",Xr(t.expiresAt)]}),t.scopeModels.length>0&&e("div",{children:["Models: ",t.scopeModels.join(", ")]})]})]})}function A({quota:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"Quota data is not available for this account."});return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),t.planName&&e("span",{className:"text-[10px] text-ink/60",children:["Plan ",e("span",{className:"font-semibold text-ink",children:t.planName})]})]}),t.windows.length===0?e("p",{className:"text-[11px] text-ink/50",children:"No quota windows reported."}):e("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2.5",children:t.windows.map((r)=>e(z,{window:r},r.key))}),t.coupon&&e(H,{coupon:t.coupon})]})}function F({usage:t}){if(!t)return e("p",{className:"text-[11px] text-ink/50",children:"The 30-day usage report is not available."});let r=t.rows.reduce((l,p)=>l+p.inputTokens,0),o=t.rows.reduce((l,p)=>l+p.outputTokens,0);return e("div",{className:"space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"30-day usage by model"}),e("div",{className:"overflow-x-auto border border-ink/15 rounded-lg shadow-xs",children:e("table",{className:"w-full text-[11px]",children:[e("thead",{className:"bg-ink/5 text-ink/60",children:e("tr",{children:[e("th",{className:"text-left font-semibold px-3 py-2 whitespace-nowrap",children:"Model"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Requests"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Input tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Output tokens"}),e("th",{className:"text-right font-semibold px-3 py-2 whitespace-nowrap",children:"Cost"})]})}),e("tbody",{className:"divide-y divide-ink/10",children:t.rows.length===0?e("tr",{children:e("td",{colSpan:5,className:"px-3 py-3 text-center text-ink/50",children:"No usage recorded in the last 30 days."})}):t.rows.map((l)=>e("tr",{children:[e("td",{className:"px-3 py-1.5 font-mono text-ink whitespace-nowrap",children:l.model}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:b(l.requests)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.inputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:k(l.outputTokens)}),e("td",{className:"px-3 py-1.5 text-right tabular-nums text-ink/80",children:x(l.costRp)})]},l.model))}),e("tfoot",{className:"bg-ink/5 border-t border-ink/15 font-semibold text-ink",children:e("tr",{children:[e("td",{className:"px-3 py-2",children:"Total"}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:b(t.totalRequests)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(r)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:k(o)}),e("td",{className:"px-3 py-2 text-right tabular-nums",children:x(t.totalCostRp)})]})})]})})]})}function E({report:t}){let{balance:r,usage:o,quota:l}=t;if(!r&&!o&&!l)return e("p",{className:"text-[11px] text-ink/50",children:"No kenari data was returned for this account."});let p=r?r.amountRp!==null?x(r.amountRp):r.raw:"–",c=r?r.amountRp!==null?r.raw:"Amount could not be parsed":"Balance unavailable",m=o?o.rows.reduce((g,u)=>g+u.inputTokens+u.outputTokens,0):0;return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(nt,{value:p,label:"Wallet balance",hint:c}),e(nt,{value:l?.planName??"–",label:"Active plan",hint:l?"kenari quota plan":"Quota unavailable"}),e(nt,{value:o?b(o.totalRequests):"–",label:"Requests (30 days)",hint:o?"Across all models":"Usage report unavailable"}),e(nt,{value:o?x(o.totalCostRp):"–",label:"Cost (30 days)",hint:o?"Billed in Rupiah":"Usage report unavailable"}),e(nt,{value:o?k(m):"–",label:"Tokens processed (30 days)",hint:o?"Input + output":"Usage report unavailable",tone:"muted",className:"col-span-2 @[540px]:col-span-1"})]})}),e(A,{quota:l}),e(F,{usage:o})]})}function W({report:t}){let r=t.balance;if(!r)return e("p",{className:"text-[11px] text-ink/50",children:"DeepSeek balance data is not available."});return e(d,{children:[e("div",{className:"@container",children:e("div",{className:"grid grid-cols-3 @[540px]:grid-cols-5 gap-2.5 items-stretch",children:[e(nt,{value:r.isAvailable?"Available":"Unavailable",label:"Prepaid balance",hint:r.isAvailable?"Account can spend":"Top up required",tone:r.isAvailable?"default":"muted"}),e(nt,{value:b(r.entries.length),label:"Currency buckets",hint:r.entries.length>0?"From the balance endpoint":"No entries returned",tone:"muted"})]})}),r.entries.length===0?e("p",{className:"text-[11px] text-ink/50",children:"The balance endpoint returned no currency entries."}):e("div",{className:"grid grid-cols-1 gap-2.5",children:r.entries.map((o)=>e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs",children:[e("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e("span",{className:"text-[11px] font-semibold text-ink",children:o.currency}),e("span",{className:"text-[10px] font-mono uppercase tracking-wider text-ink/40",children:"Balance"})]}),e("dl",{className:"grid grid-cols-3 gap-2 text-[10px]",children:[e("div",{children:[e("dt",{className:"text-ink/50",children:"Total"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.totalBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Granted"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.grantedBalance)})]}),e("div",{children:[e("dt",{className:"text-ink/50",children:"Topped up"}),e("dd",{className:"font-semibold text-ink tabular-nums break-words",children:N(o.toppedUpBalance)})]})]})]},o.currency))})]})}function R(t,r,o,l){let p=t.find((c)=>c.id===r);if(p){p.limits.push(l);return}t.push({id:r,title:o,limits:[l]})}function V(t){let r=(t.split(":")[1]??"").toLowerCase();if(r==="google")return{id:"google",title:"Google"};if(r==="anthropic"||r==="openai")return{id:"third-party",title:"Claude & GPT (shared)"};if(r==="default"||r==="")return{id:"default",title:"Usage"};return{id:r,title:r}}function X(t){let r=[];for(let o of t)if(o.id==="anthropic:extra")R(r,"balance","Balance",o);else R(r,"windows","Quota windows",o);return r}function J(t){let r=[];for(let o of t){let l=V(o.id);if(l.id==="third-party"){if(r.find((c)=>c.id==="third-party")?.limits.some((c)=>Z(c,o)))continue}R(r,l.id,l.title,o)}return r}function Z(t,r){return t.unit===r.unit&&t.label===r.label&&t.usedFraction===r.usedFraction&&t.remaining===r.remaining&&t.resetsAt===r.resetsAt}function _(t,r){if(r.length===0)return[];let o=t.trim().toLowerCase();if(o==="anthropic")return X(r);if(o==="google-antigravity")return J(r);return[{id:"all",title:"Quota windows",limits:[...r]}]}function Y({limit:t}){let r=Math.min(100,Math.max(0,(t.usedFraction??0)*100)),o=t.modelId??t.accountId,l=t.used!==void 0?w(t.used,t.unit):void 0,p=t.limit!==void 0?w(t.limit,t.unit):void 0,c=t.remaining!==void 0?w(t.remaining,t.unit):void 0;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[t.label,t.windowLabel&&e("span",{className:"ml-1.5 rounded border border-ink/15 px-1 py-px font-mono text-[9px] font-normal text-ink/50",children:t.windowLabel})]}),o&&e("div",{className:"text-[10px] text-ink/50 truncate",children:o})]}),e("span",{className:"text-[10px] text-ink/50 flex-shrink-0 whitespace-nowrap",children:t.resetsAt!==void 0?`Resets ${Xr(new Date(t.resetsAt).toISOString())}`:""})]}),e("div",{className:"h-1.5 w-full bg-ink/10 rounded-full overflow-hidden",children:e("div",{className:`h-full rounded-full ${t.status==="exhausted"?"bg-error/70":"bg-ink/80"}`,style:{width:`${r}%`}})}),e("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-[10px] text-ink/60",children:[e("span",{children:["Used"," ",e("span",{className:"font-semibold text-ink",children:t.unit==="percent"||!l?D(t.usedFraction??0):l}),t.unit!=="percent"&&l&&p?` of ${p}`:""]}),e("span",{className:"flex items-center gap-2",children:[t.status!=="ok"&&t.status!=="unknown"&&e("span",{className:"text-[10px] font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/70",children:t.status}),c&&e("span",{children:["Remaining ",e("span",{className:"font-semibold text-ink",children:c})]})]})]}),t.notes&&t.notes.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:t.notes.map((m)=>e("li",{children:m},m))})]})}function Q({providerId:t,limits:r,tracked:o,unavailable:l,notes:p}){let c=_(t,r);return e("div",{className:"space-y-2",children:[p&&p.length>0&&e("ul",{className:"text-[10px] text-ink/50 leading-relaxed space-y-0.5",children:p.map((m)=>e("li",{children:m},m))}),c.length===0?e(d,{children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:"Quota windows"}),e("p",{className:"text-[11px] text-ink/50",children:!o?"No quota source for this provider: omp ships no usage adapter for it and it exposes no balance endpoint Kabmo knows.":l?"omp tracks this provider but its usage endpoint returned no data — an invalid or expired credential, an unreachable endpoint, or a plan without quota windows.":"No quota windows were reported for this provider."})]}):c.map((m)=>e("div",{className:"@container space-y-2",children:[e("h4",{className:"text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40",children:m.title}),e("div",{className:"grid grid-cols-1 @[520px]:grid-cols-2 gap-2.5",children:m.limits.map((g)=>e(Y,{limit:g},g.id))})]},m.id))]})}var ee="DeepSeek exposes no usage or quota API — only the prepaid balance (and the web console at platform.deepseek.com) is available.";function ou({summary:t}){let r=Boolean(t.kenari||t.deepseek);return e(P,{providerName:t.name,providerSlug:t.id,iconUrl:t.iconUrl,credentialSources:t.credentialSources,error:t.error,note:t.deepseek?ee:void 0,children:[t.kenari&&e(E,{report:t.kenari}),t.deepseek&&e(W,{report:t.deepseek}),!r&&(t.limits.length>0||!t.error)&&e(Q,{providerId:t.id,limits:t.limits,tracked:t.tracked,unavailable:t.limitsUnavailable,notes:t.notes})]})}function te(t){let r=t.filter((p)=>p.usedFraction!==void 0);if(r.length===0){let p=t.find((c)=>c.unit==="usd"&&c.remaining!==void 0);if(p)return`${U(p.remaining??0)} left`;return t[0]?.label}let o=r.reduce((p,c)=>(c.usedFraction??0)>(p.usedFraction??0)?c:p),l=Math.round((o.usedFraction??0)*100);return o.windowLabel?`${l}% · ${o.windowLabel}`:`${l}% used`}function ys(t){return t.providers.map((r)=>({id:r.id,name:r.name,...r.iconUrl?{iconUrl:r.iconUrl}:{},error:r.error,hint:ne(r),limits:r.limits,tracked:r.tracked,limitsUnavailable:r.limitsUnavailable,summary:r}))}function ne(t){let r=t.kenari?.quota?.planName;if(r)return r;let o=t.deepseek?.balance?.entries[0];if(o)return`${o.currency} ${N(o.totalBalance)}`;return te(t.limits)??"No quota reported"}function vs(t){return t.error?"Error":"Connected"}function K(){let[t,r]=n([]),[o,l]=n(null),[p,c]=n(!0),m=a(()=>{c(!0),fetch("/api/settings/usage/reset").then((u)=>u.json()).then((u)=>{r(Array.isArray(u.accounts)?u.accounts:[]),l(typeof u.error==="string"?u.error:null)}).catch((u)=>{r([]),l(u instanceof Error?u.message:"Failed to load saved resets")}).finally(()=>c(!1))},[]);i(()=>{m()},[m]);let g=a(async(u)=>{try{let h=await(await fetch("/api/settings/usage/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:u})})).json();if(h.ok)m();return{ok:Boolean(h.ok),message:h.message||"No result reported."}}catch(f){return{ok:!1,message:f instanceof Error?f.message:"Failed to spend the saved reset"}}},[m]);return{accounts:t,error:o,isLoading:p,reload:m,spend:g}}function ae({account:t,onSpend:r,spending:o}){let l=`${t.provider}/${t.credentialId}`,p=t.email??t.accountId??t.credentialId,c=t.orgName??t.orgId,m=t.availableCount??t.credits.length,g=t.redeemableCount??0,u=t.error??t.unavailableReason;return e("div",{className:"bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2",children:[e("div",{className:"flex items-start justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink truncate",children:[p,c?e("span",{className:"text-ink/50 font-normal",children:[" · ",c]}):null]}),e("div",{className:"text-[10px] text-ink/50 font-mono truncate",children:l})]}),e("span",{className:"text-[10px] text-ink/60 flex-shrink-0 whitespace-nowrap",children:g>0?`${g} of ${m} usable`:`${m} saved`})]}),t.soonestExpiry!==void 0&&e("div",{className:"text-[10px] text-ink/60",children:["Soonest expires ",Xr(new Date(t.soonestExpiry).toISOString())]}),t.credits.length>0&&e("div",{className:"space-y-1",children:t.credits.map((f)=>e("div",{className:"flex items-center justify-between gap-2 text-[10px] text-ink/70",children:[e("span",{className:"truncate",children:f.title??f.program??f.id}),e("span",{className:"flex items-center gap-1.5 flex-shrink-0",children:[f.clears&&f.clears.length>0&&e("span",{className:"font-mono text-ink/50",children:f.clears.join(", ")}),f.usable===!1&&e("span",{className:"font-mono uppercase px-1.5 py-0.5 rounded bg-ink/10 text-ink/60",children:"blocked"})]})]},f.id))}),u&&e("div",{className:"text-[10px] text-ink/60 leading-snug",children:u}),e("button",{type:"button",onClick:()=>r(l),disabled:o||g===0,title:g===0?u??"Nothing to spend on this account right now.":`Spend a saved reset on ${l}`,className:"w-full rounded-md border border-ink/15 px-2 py-1 text-[11px] font-medium text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:o?"Spending…":"Spend saved reset"})]})}function su(){let{accounts:t,error:r,isLoading:o,reload:l,spend:p}=K(),[c,m]=n(null),[g,u]=n(null),f=(v)=>{m(v),u(null),p(v).then((M)=>{u(M),m(null)})},h=!o&&!r&&t.length===0;return e("div",{className:"space-y-2",children:[e("div",{className:"flex items-center justify-between gap-2",children:[e("div",{className:"min-w-0",children:[e("div",{className:"text-[11px] font-semibold text-ink",children:"Saved rate-limit resets"}),e("div",{className:"text-[10px] text-ink/50 leading-snug",children:"Provider-issued resets for Codex and Claude accounts. Spending one clears the window it covers."})]}),e("button",{type:"button",onClick:l,disabled:o,title:"Re-read saved resets",className:"p-1.5 bg-paper border border-ink/15 rounded-md hover:bg-ink/5 text-ink/80 transition-colors disabled:opacity-50 flex-shrink-0",children:e(C,{size:12,className:o?"animate-spin text-ink":""})})]}),r&&e("div",{className:"flex items-start gap-1.5 text-[10px] text-error leading-snug",children:[e(I,{size:12,className:"flex-shrink-0 mt-px"}),e("span",{children:r})]}),t.map((v)=>e(ae,{account:v,onSpend:f,spending:c===`${v.provider}/${v.credentialId}`},`${v.provider}/${v.credentialId}`)),h&&e("p",{className:"text-[10px] text-ink/50 leading-snug",children:"No saved resets on any account."}),g&&e("div",{className:`text-[10px] leading-snug ${g.ok?"text-ink/70":"text-error"}`,children:g.message})]})}function lu(){let[t,r]=n(null),[o,l]=n(!0),[p,c]=n(null),m=a(async(g)=>{if(!g?.silent)l(!0);c(null);try{let u=g?.force?"/api/settings/usage?refresh=1":"/api/settings/usage",f=await fetch(u);if(!f.ok)throw Error(`Usage request failed (${f.status})`);let h=await f.json();r(h)}catch(u){c(u instanceof Error?u.message:"Failed to load provider usage")}finally{if(!g?.silent)l(!1)}},[]);return i(()=>{m()},[m]),{report:t,isLoading:o,error:p,reload:m}}
|
|
2
|
+
export{Xr,ou,ys,vs,su,lu};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{d,n,i,V,o,u,a,He,de,e,Gn,Ze,$e,S,s,B,m,Kt,D,f,I,ie,ft,he,wt,Ge,Ji,en,jr,C,F,y,Hr,Ke,le,dr,J,rt,Os,yi,$s,zs,wi,xg,Fg,Vs,Qe,re,jt,T,ye,Ri,lo,Um,Vf}from"./index-4s8ttfxj.js";import{yt,uo,Uc,Gc,qc,is,po,ld}from"./index-nmmxb4va.js";import{wc,Xu,ed,eA,tA,Cc,Zn,ts,Ec,Bc,Ic,_c,Sc,ns,Fi,rs,Dc,rl,al,Qc,Nc,Rc,Fc,Mc,Lc,Pc,Oc,$c}from"./index-kg86e3sy.js";import{_a,Sa,fo}from"./index-dq1kdt03.js";var fn={name:"git-commit-vertical",size:24,node:[["path",{d:"M12 3v6",key:"1holv5"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"M12 15v6",key:"a9ows0"}]]},Pe=s(fn);var bn={name:"maximize",size:24,node:[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]},xe=s(bn);var gn={name:"minimize",size:24,node:[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]},we=s(gn);var hn={name:"save-all",size:24,node:[["path",{d:"M10 2v3a1 1 0 0 0 1 1h5",key:"1xspal"}],["path",{d:"M18 18v-6a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6",key:"1ra60u"}],["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"M8 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9.172a2 2 0 0 1 1.414.586l2.828 2.828A2 2 0 0 1 22 6.828V16a2 2 0 0 1-2.01 2z",key:"1yve0x"}]]},ke=s(hn);var oe=new Set,Le=new Set,Ie=new Set;function Fe(){Ie=new Set(oe);for(let t of[...Le])t()}function ze(t){let r=new Set(t);if(r.size===oe.size){let l=!0;for(let c of r)if(!oe.has(c)){l=!1;break}if(l)return}oe.clear();for(let l of r)oe.add(l);Fe()}function Ve(t){let r=new Set(t),l=!1;for(let c of[...oe])if(!r.has(c))oe.delete(c),l=!0;if(l)Fe()}function We(t){return oe.has(t)}function Ue(){return oe.size>0}function vn(t){return Le.add(t),()=>{Le.delete(t)}}var yn=vn;function _e(){return He(yn,()=>Ie)}function qe({x:t,y:r,rows:l,onAction:c,onClose:p}){let b=o(null),[g,h]=n({left:t,top:r});return V(()=>{let x=b.current;if(!x)return;let{width:v,height:w}=x.getBoundingClientRect();h({left:Math.min(t,Math.max(0,window.innerWidth-v-8)),top:Math.min(r,Math.max(0,window.innerHeight-w-8))})},[t,r,l.length]),de(e("div",{className:"fixed inset-0 z-[70]",onClick:p,onContextMenu:(x)=>{x.preventDefault(),p()},children:e("div",{ref:b,role:"menu","aria-label":"Tab actions",className:"glass-popover absolute w-52 bg-paper border border-ink/15 rounded-md shadow-xl py-1 text-xs text-ink",style:{left:`${g.left}px`,top:`${g.top}px`},onClick:(x)=>x.stopPropagation(),children:l.map((x)=>e("button",{type:"button",role:"menuitem",onClick:()=>{c(x.action),p()},className:"w-full text-left px-3 py-1.5 hover:bg-ink/5 transition-colors cursor-pointer",children:x.label},x.action))})}),document.body)}var be={rightFileId:null,fraction:0.5};function Se(t,r,l){if(t===null)return!1;if(t===r)return!1;return l.includes(t)}function Xe(t,r){for(let l=r.length-1;l>=0;l-=1){let c=r[l];if(c!==t)return c}return null}function Ye(t,r){if(t.rightFileId===null)return t;if(t.rightFileId!==r)return t;return{...t,rightFileId:null}}function pe(t){if(!Number.isFinite(t))return be.fraction;return Math.max(0.2,Math.min(0.8,t))}function Je(t,r){if(typeof t!=="object"||t===null)return be;let l=t,c=typeof l.fraction==="number"?pe(l.fraction):be.fraction,p=typeof l.rightFileId==="string"||typeof l.rightFileId==="number"?l.rightFileId:null;if(p===null||!r.includes(p))return{rightFileId:null,fraction:c};return{rightFileId:p,fraction:c}}function je({tab:t,openedFiles:r,dirtyIds:l,reopenable:c,activeFileId:p,splitRightFileId:b}){let g=r.filter((w)=>w.id!==t.id),h=r.filter((w)=>!l.has(w.id)),x=r.map((w)=>w.id);return[{action:"split-right",label:"Split right",enabled:Se(t.id,p,x)},{action:"unsplit",label:"Unsplit",enabled:b!==null},{action:"close",label:"Close",enabled:!0},{action:"close-others",label:"Close others",enabled:g.length>0},{action:"close-all",label:"Close all",enabled:r.length>0},{action:"close-saved",label:"Close saved",enabled:h.some((w)=>w.id!==t.id)},{action:"copy-path",label:"Copy path",enabled:Boolean(t.path)},{action:"reveal-in-files",label:"Reveal in Files",enabled:Boolean(t.path)&&!t.isDiff},{action:"reopen-closed",label:"Reopen closed tab",enabled:c>0}].filter((w)=>w.enabled)}function tt({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,missingIds:p,onCopyPath:b,onRevealInFiles:g,onReopenClosed:h,reopenableCount:x,onSplitTo:v,onUnsplit:w,splitRightFileId:k=null}){let A=_e(),E=o(null),M=o(null),[H,K]=n(5),[W,z]=n(!1),[L,_]=n(null);le(M,()=>z(!1)),i(()=>{let N=new ResizeObserver((R)=>{for(let P of R){let Q=P.contentRect.width,X=Math.max(1,Math.floor((Q-60)/150));K(X)}});if(E.current)N.observe(E.current);return()=>N.disconnect()},[]);let O=Xe(r,t.map((N)=>N.id)),G=[],Z=[];if(t.length<=H)G=t;else{let N=t.findIndex((P)=>P.id===r),R=new Set;if(N!==-1&&r!==null)R.add(r);for(let P=t.length-1;P>=0;P--){if(R.size>=H)break;R.add(t[P].id)}G=t.filter((P)=>R.has(P.id)),Z=t.filter((P)=>!R.has(P.id))}return e("div",{className:"flex bg-ink/10 w-full relative border-b border-ink/10",ref:E,children:[e("div",{className:"flex overflow-hidden",children:G.map((N)=>{let R=N.id===r,P=Boolean(N.isDiff),Q=P?Gn(N.diffStatus||"M",N.diffStaged):null,X=Boolean(p?.has(N.id));return e("div",{onClick:()=>l(N.id),onContextMenu:(j)=>{j.preventDefault(),_({tab:N,x:j.clientX,y:j.clientY})},className:`flex items-center space-x-1.5 px-3 py-1.5 cursor-pointer border-r border-ink/10 min-w-[120px] max-w-[210px] group ${R?"bg-paper border-t-2 border-t-ink text-ink":"bg-transparent border-t-2 border-t-transparent text-ink/60 hover:bg-paper/50"}`,title:X?`${N.path} — file no longer exists`:N.path,children:[P?e(Ji,{size:14,className:R?"text-info flex-shrink-0":"text-info/70 flex-shrink-0"}):e(rt,{name:N.name,size:14,className:`flex-shrink-0${R||X?"":" opacity-60"}${X?" text-error":""}`}),e("span",{className:`text-xs font-mono truncate flex-1${X?" text-error line-through":""}`,children:N.name}),Q&&e("span",{className:`px-1 text-[10px] font-mono font-bold rounded ${Q.badgeBgClass}`,children:Q.charStatus}),e(et,{dirty:A.has(N.id),active:R,label:`Close ${N.name}`,onClose:()=>c(N.id)})]},N.id)})}),L?e(qe,{x:L.x,y:L.y,rows:je({tab:L.tab,openedFiles:t,dirtyIds:A,reopenable:x?.()??0,activeFileId:r,splitRightFileId:k}),onAction:(N)=>{let R=L.tab;switch(N){case"close":c(R.id);return;case"close-others":for(let P of[...t].reverse())if(P.id!==R.id)c(P.id);l(R.id);return;case"close-all":for(let P of[...t].reverse())c(P.id);return;case"close-saved":for(let P of[...t].reverse())if(!A.has(P.id))c(P.id);return;case"copy-path":b?.(R);return;case"reveal-in-files":g?.(R);return;case"reopen-closed":h?.();return;case"split-right":v?.(R.id);return;case"unsplit":w?.();return}},onClose:()=>_(null)}):null,e("div",{className:"ml-auto flex items-center",children:e("button",{type:"button",onClick:()=>k!==null?w?.():v?.(O),disabled:k===null&&O===null,"aria-pressed":k!==null,"aria-label":"Split editor",title:k!==null?"Close the split pane (the tab stays open)":O===null?"Open another file to split the editor":"Split the editor and show the newest other file",className:`p-1.5 mx-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-default ${k!==null?"bg-ink/10 text-ink":"text-ink/60 hover:bg-ink/10"}`,children:e(jr,{size:14})})}),Z.length>0&&e("div",{className:"relative flex items-center bg-ink/10",ref:M,children:[e("button",{className:`p-1.5 mx-1 rounded hover:bg-ink/10 text-ink/60 ${W?"bg-ink/10 text-ink":""}`,onClick:()=>z(!W),title:"More open files",children:e(I,{size:14})}),W&&e("div",{className:"glass-popover absolute right-0 top-full mt-1 w-52 bg-paper border border-ink/10 rounded shadow-lg z-50 py-1",children:[e("div",{className:"px-3 py-1 text-[10px] uppercase font-mono text-ink/40 border-b border-ink/10 mb-1",children:"Older Tabs"}),Z.map((N)=>{let R=Boolean(p?.has(N.id));return e("div",{onClick:()=>{l(N.id),z(!1)},className:"flex items-center space-x-2 px-3 py-1.5 hover:bg-ink/5 cursor-pointer group",children:[N.isDiff?e(Ji,{size:14,className:"text-info/80"}):e(rt,{name:N.name,size:14,className:R?"text-error":"opacity-60"}),e("span",{className:`text-xs font-mono truncate flex-1 ${R?"text-error line-through":"text-ink/80"}`,children:N.name}),e(et,{dirty:A.has(N.id),active:!1,label:`Close ${N.name}`,onClose:()=>{if(c(N.id),Z.length===1)z(!1)}})]},N.id)})]})]})]})}function et({dirty:t,active:r,label:l,onClose:c}){return e("div",{role:"button",tabIndex:-1,"aria-label":l,title:t?`${l} — unsaved changes`:l,className:`p-0.5 rounded hover:bg-ink/10 touch-visible ${r||t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:(p)=>{p.stopPropagation(),c()},children:t?e("span",{className:"block w-2 h-2 rounded-full bg-current mx-0.5","data-tab-dirty":"","aria-hidden":"true"}):e(y,{size:12})})}function xn(t){if(t===null)return null;let r=new Date(t);if(Number.isNaN(r.getTime()))return null;return r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Ce({diskMtimeMs:t,fileName:r,onReload:l,onKeepMine:c}){let p=xn(t);return e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-[11px] text-ink flex-shrink-0",role:"alert","data-conflict-strip":"",children:[e(D,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"font-medium",children:[e("span",{className:"font-mono",children:r})," changed on disk",p?e("span",{className:"text-ink/60",children:[" at ",p]}):null,"."]}),e("div",{className:"text-ink/60 mt-0.5",children:"Your save was refused so nothing was overwritten."})]}),e("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e("button",{type:"button",onClick:l,className:"px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer",title:"Discard my changes and take the file from disk",children:"Reload"}),e("button",{type:"button",onClick:c,className:"px-2 py-1 rounded border border-warning/50 text-warning hover:bg-warning/10 transition-colors cursor-pointer",title:"Write my buffer over the file on disk",children:"Keep mine"})]})]})}function nt(t){if(t.byteViewer)return[];return[{id:"save",pinned:!0,actions:[{label:"Save file",icon:ke,onSelect:t.onSave,disabled:t.saveDisabled}],children:t.saveButton},{id:"save-as",actions:[{label:"Save as…",icon:ke,onSelect:t.onSaveAs}],children:e("button",{type:"button",onClick:t.onSaveAs,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Save the buffer to a new file","aria-label":"Save as",children:e(ke,{size:14})})}]}function ot(t){if(!t.hasReview)return[];let r=t.isReviewing?"Exit review mode":"Review this document";return[{id:"review",actions:[{label:r,icon:en,onSelect:t.onToggleReview,active:t.isReviewing}],children:e(ts,{label:r,pressed:t.isReviewing,title:t.isReviewing?"Review mode is on — click a block to judge it":"Review: click blocks to mark them good or needing work",onClick:t.onToggleReview,children:e(en,{size:14})})}]}function it(t){if(!t.hasPreview)return[];return[{id:"preview",actions:[{label:t.previewLabel,icon:t.isPreview?wt:Ge,onSelect:t.onTogglePreview,active:t.isPreview}],children:e(ts,{label:t.previewLabel,pressed:t.isPreview,onClick:t.onTogglePreview,children:t.isPreview?e(wt,{size:14}):e(Ge,{size:14})})}]}function at(t){let r=[];if(r.push(...nt(t),...ot(t),...it(t)),!t.byteViewer)r.push({id:"find",actions:[{label:t.findLabel,icon:F,onSelect:t.onToggleFind,active:t.findOpen}],children:e(ts,{label:t.findLabel,pressed:t.findOpen,title:`${t.findLabel} (Ctrl+F)`,onClick:t.onToggleFind,children:e(F,{size:14})})}),r.push({id:"wrap",actions:[{label:t.wordWrapLabel,icon:Kt,onSelect:t.onToggleWordWrap,active:t.wordWrap}],children:e(ts,{label:t.wordWrapLabel,pressed:t.wordWrap,onClick:t.onToggleWordWrap,children:e(Kt,{size:14})})}),r.push({id:"blame",actions:[{label:t.blameInline?"Hide line blame":"Show line blame",icon:Pe,onSelect:t.onToggleBlameInline,active:t.blameInline}],children:e(ts,{label:t.blameInline?"Hide line blame":"Show line blame",pressed:t.blameInline,title:"Who last changed each block, from git (hover a line for the commit)",onClick:t.onToggleBlameInline,children:e(Pe,{size:14})})}),r.push({id:"zoom",actions:[{label:"Decrease font size",icon:Sa,onSelect:t.onZoomOut},{label:"Increase font size",icon:_a,onSelect:t.onZoomIn}],children:e(d,{children:[e("button",{type:"button",onClick:t.onZoomOut,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Decrease font size","aria-label":"Decrease font size",children:e(Sa,{size:14})}),e("button",{type:"button",onClick:t.onZoomIn,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Increase font size","aria-label":"Increase font size",children:e(_a,{size:14})})]})}),r.push({id:"reload",actions:[{label:"Reload from disk",icon:C,onSelect:t.onReload,disabled:!t.canReload}],children:e("button",{type:"button",onClick:t.onReload,disabled:!t.canReload||t.refreshing,"aria-busy":t.refreshing,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:!t.canReload?"Nothing to reload — this tab has no file on disk":t.reloadDiscardsEdits?"Discard my changes and reload from disk":"Reload from disk","aria-label":"Reload from disk",children:e(C,{size:14,className:t.refreshing?"animate-spin":void 0})})});return r.push({id:"copy",actions:[{label:t.copyLabel,icon:ie,onSelect:t.onCopy},{label:"Download file",icon:he,onSelect:t.onDownload}],children:e(d,{children:[e("button",{type:"button",onClick:t.onCopy,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:t.copyLabel,"aria-label":t.copyLabel,children:t.copied?e(ie,{size:14,className:"text-success"}):e(ie,{size:14})}),e("button",{type:"button",onClick:t.onDownload,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Download file","aria-label":"Download file",children:e(he,{size:14})})]})}),r.push({id:"view-modes",pinned:!0,actions:t.viewModeActions,children:t.viewModeButtons}),r.push({id:"maximize",pinned:!0,actions:[{label:t.maximizeLabel,icon:t.isMaximized?we:xe,onSelect:t.onToggleMaximize,active:t.isMaximized}],children:t.maximizeButton}),r}function st({path:t,saveStatus:r,wordWrap:l,hasPreview:c,isPreview:p,hasReview:b,isReviewing:g,copied:h,byteViewer:x=!1,saveDisabled:v=!1,unsupported:w=!1,handleMissing:k=!1,readOnly:A=!1,isMaximized:E=!1,findOpen:M=!1,onToggleFind:H,onSave:K,onTogglePreview:W,onToggleReview:z,onToggleWordWrap:L,onZoomIn:_,onZoomOut:O,onCopy:G,onDownload:Z,onReload:N,canReload:R,refreshing:P=!1,reloadDiscardsEdits:Q,onSaveAs:X,onToggleMaximize:j}){let ne=v?A?"Read-only — this file was opened from the phone, not from a workspace":k?"Cannot save — reopen the file from the system to restore write access":w?"Nothing to save — this file cannot be opened as a document":"Nothing to save — this file could not be read":r==="needs-permission"?"Click Save to allow writing this file":r==="saving"?"Saving…":r==="error"?"Save failed — the file on disk was not changed":"Save file (Ctrl+S)",me=e("button",{type:"button",onClick:K,disabled:v||r==="saving",className:`${Zn} hover:bg-ink/5`,title:ne,"aria-label":ne,children:r==="saving"?e(yt,{size:14,className:"text-warning animate-pulse"}):r==="saved"?e(f,{size:14,className:"text-success"}):r==="error"?e(B,{size:14,className:"text-error"}):r==="needs-permission"?e(yt,{size:14,className:"text-warning"}):e(yt,{size:14,className:"hover:text-ink"})}),ee=E?"Exit full screen":"Full screen",te=e("button",{type:"button",onClick:j,className:`${Zn} hover:bg-ink/5 hover:text-ink ${E?"text-ink":""}`,title:ee,"aria-label":ee,"aria-pressed":E,children:E?e(we,{size:14}):e(xe,{size:14})}),ue=ld(),ae=Xu(),se=at({byteViewer:x,hasPreview:c,isPreview:p,wordWrap:l,hasReview:b,isReviewing:g,blameInline:ue.inline,findOpen:M,copied:h,isMaximized:E,saveDisabled:v,canReload:R,refreshing:P,reloadDiscardsEdits:Q,saveButton:me,maximizeButton:te,viewModeButtons:e(ed,{size:14}),viewModeActions:ae,previewLabel:p?"Show source":"Show preview",findLabel:"Find and replace",wordWrapLabel:l?"Word wrap on":"Word wrap off",copyLabel:h?"Copied":x?"Copy image":"Copy content",maximizeLabel:ee,onTogglePreview:W,onToggleReview:z,onToggleFind:H,onToggleWordWrap:L,onToggleBlameInline:()=>{let fe={...po(),inline:!ue.inline};Hr({editorBlameInline:fe.inline}),window.dispatchEvent(new CustomEvent(is,{detail:fe}))},onZoomIn:_,onZoomOut:O,onCopy:G,onDownload:Z,onReload:N,onSaveAs:X,onToggleMaximize:j,onSave:K});return e("div",{className:"@container flex items-center justify-between gap-2 px-3 py-2 border-b border-ink/10 bg-paper flex-shrink-0",children:[e("div",{className:"hidden @[420px]:flex items-center space-x-2 text-xs font-mono text-ink/40 min-w-0",children:e("span",{className:"truncate max-w-[300px]",title:t,children:t})}),e(fo,{clusters:se,className:"text-ink/40 ml-auto"})]})}function lt({content:t,file:r,zoomLevel:l,reviewActive:c,onExitReview:p,scrollRef:b,onScroll:g}){return e("div",{ref:b,onScroll:g,"data-testid":"editor-scroller",className:"flex-1 overflow-auto bg-paper flex",children:e("div",{className:"p-6 max-w-4xl mx-auto font-sans flex-1",style:{fontSize:`${l}px`},children:e(Ec,{content:t,file:r,active:c,onExit:p})})})}function wn(t,r){return r?`Spaces: ${t}`:"Tabs"}function dt({caret:t,eol:r,onSetEol:l,indentWidth:c,insertSpaces:p,language:b,byteViewer:g,viewerKind:h,lineCount:x,conflicts:v=0}){return e("footer",{className:"flex bg-canvas border-t border-ink/10 px-3 items-center justify-between text-[10px] text-ink/50 flex-shrink-0 font-mono h-6","data-editor-status-bar":"",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:g?e("span",{className:"uppercase",children:Fi[h]}):e(d,{children:[e("span",{className:"tabular-nums",children:t?`Ln ${t.line}, Col ${t.column}`:"Ln —, Col —"}),e("span",{children:wn(c,p)}),e("button",{type:"button",onClick:()=>l(r==="lf"?"crlf":"lf"),className:"uppercase hover:text-ink transition-colors cursor-pointer",title:`Line endings: ${r.toUpperCase()} — click to switch`,"aria-label":`Line endings ${r.toUpperCase()}, switch`,children:r}),e("span",{children:[x," lines"]})]})}),e("div",{className:"flex items-center gap-3 min-w-0",children:[v>0&&e("span",{className:"text-error font-semibold tabular-nums",title:`${v} unresolved conflict${v===1?"":"s"} — markers are highlighted in the file`,children:["⚠ ",v," conflict",v===1?"":"s"]}),e("span",{className:"uppercase text-ink/40",children:b})]})]})}function kn(t){if(t===0)return 0;return Math.max(-1,Math.min(1,-Math.sign(t)))}function Sn(t,r,l=$s,c=zs){return Math.max(l,Math.min(c,t+r))}function Cn(t,r){let l=t instanceof HTMLElement?t:null;while(l&&l!==r){let c=getComputedStyle(l);if(/(auto|scroll)/.test(c.overflowY)&&l.scrollHeight>l.clientHeight)return!0;l=l.parentElement}return!1}function ct(t,r){i(()=>{if(!t)return;let l=t.closest("[data-code-surface]"),c=l instanceof HTMLElement?l:t,p=(b)=>{if(!b.ctrlKey&&!b.metaKey)return;if(b.preventDefault(),Cn(b.target,c))return;let g=kn(b.deltaY);if(g===0)return;r((h)=>Sn(h,g))};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[t,r])}function mt(t,r){let l=t.trim();if(!/^\d+$/.test(l))return null;let c=Number(l);if(c<1)return null;return Math.min(c,Math.max(r,1))}function ut({lineCount:t,onGo:r,onClose:l}){let[c,p]=n(""),b=o(null);i(()=>{b.current?.focus(),b.current?.select()},[]);let g=()=>{let v=mt(c,t);if(v===null)return;r(v)},h=(v)=>{if(v.key==="Enter"){v.preventDefault(),g();return}if(v.key==="Escape")v.preventDefault(),l()},x=mt(c,t);return e(J,{onClose:l,maxWidthClass:"max-w-xs",header:e("span",{className:"text-sm font-semibold text-ink",children:"Go to line"}),children:e("div",{className:"px-4 py-3 space-y-2",children:[e("div",{className:"flex items-center gap-2",children:[e("input",{ref:b,value:c,onInput:(v)=>p(v.target.value),onKeyDown:h,inputMode:"numeric",placeholder:"1","aria-label":"Line number",className:"flex-1 bg-paper border border-ink/20 rounded px-2 py-1 text-xs font-mono text-ink outline-none focus:border-ink/40"}),e("span",{className:"text-[10px] font-mono text-ink/40",children:["/ ",t]}),e("button",{type:"button",onClick:g,disabled:x===null,className:"flex items-center gap-1 px-2 py-1 rounded bg-ink text-paper text-xs disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[e(ft,{size:12}),"Go"]})]}),c&&x!==null&&String(x)!==c.trim()?e("div",{className:"text-[10px] text-ink/50 font-mono",children:["line ",x," (the last line)"]}):null,c&&x===null?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a line number"}):null]})})}var pt={status:"idle",payload:null,message:null};function bt(t){if(!t?.path)return"";return`${t.root??""}\x00${t.repo??""}\x00${t.path}`}function gt(t,r={}){let l=r.enabled!==!1&&Boolean(t?.path)&&t?.deviceFile!==!0,c=r.dirty===!0,p=bt(t),[b,g]=n({key:"",value:pt}),h=o(t);h.current=t;let x=o(p);x.current=p;let v=o(l);v.current=l;let w=o(c);w.current=c;let k=o(b);k.current=b;let A=o(0),E=o(""),M=o(new Map),H=o(new Set),K=a(async()=>{let O=h.current;if(!O?.path)return;let G=bt(O),Z=++A.current;E.current=G,g((R)=>({key:G,value:{status:"loading",payload:R.key===G?R.value.payload:null,message:null}}));let N=new URLSearchParams({blame:"1",file:O.path,repo:O.repo||"."});if(O.root)N.set("root",O.root);try{let R=await fetch(`/api/fs/git?${N.toString()}`),P=await R.json().catch(()=>null);if(Z!==A.current)return;if(!R.ok||!P){g({key:G,value:{status:"error",payload:null,message:P?.error??`Blame request failed (HTTP ${R.status})`}});return}g({key:G,value:P.available?{status:"ready",payload:P,message:null}:{status:"unavailable",payload:P,message:P.message??null}})}catch(R){if(Z!==A.current)return;g({key:G,value:{status:"error",payload:null,message:R instanceof Error?R.message:"Blame failed"}})}finally{if(E.current===G)E.current=""}},[]),W=a(async(O)=>{let G=M.current.get(O);if(G)return G;let Z=h.current;if(!Z?.path)return{entries:[],truncated:!1};let N=new URLSearchParams({blameHistory:"1",file:Z.path,line:String(O),repo:Z.repo||"."});if(Z.root)N.set("root",Z.root);try{let P=await(await fetch(`/api/fs/git?${N.toString()}`)).json().catch(()=>null),Q={entries:Array.isArray(P?.entries)?P.entries:[],truncated:P?.truncated===!0};return M.current.set(O,Q),Q}catch{return{entries:[],truncated:!1}}},[]),z=o(null);if(!z.current)z.current={ensure:()=>{if(!v.current||w.current)return;let O=k.current;if(O.key===x.current&&O.value.status!=="idle")return;if(E.current===x.current)return;K()},reload:()=>{M.current.clear(),K()},history:W,snapshot:()=>{let O=k.current;return O.key===x.current?O.value:pt},stale:()=>w.current,subscribe:(O)=>(H.current.add(O),()=>{H.current.delete(O)})};i(()=>{if(!l||c||!p)return;M.current.clear(),K()},[l,c,p,K]);let L=o(c);return i(()=>{if(L.current===c)return;L.current=c;for(let O of H.current)O()},[c]),i(()=>{for(let O of H.current)O()},[b]),z.current}var En="0".repeat(40);function Ee(t){return t===En}function ge(t,r=Date.now()){let l=Math.max(0,Math.floor(r/1000)-t);if(l<60)return"just now";let c=Math.floor(l/60);if(c<60)return`${c}m ago`;let p=Math.floor(c/60);if(p<24)return`${p}h ago`;let b=Math.floor(p/24);if(b<30)return`${b}d ago`;let g=Math.floor(b/30);if(g<12)return`${g}mo ago`;return`${Math.floor(b/365)}y ago`}function ht(t,r){switch(t){case"not-repo":return"This folder is not a git repository.";case"no-commit":return"This repository has no commits yet.";case"untracked":return"This file has never been committed, so it has no history.";case"too-large":return r??"This file is too large to blame.";case"empty":return"This file is empty.";default:return r??"git could not read this file."}}var St="fixed z-50 w-[min(340px,92vw)] rounded-xl border border-ink/20 bg-paper p-3 shadow-xl font-sans text-xs text-ink",vt="flex items-baseline justify-between gap-2",xt="truncate text-xs font-semibold text-ink",Tn="shrink-0 font-mono text-[10px] text-ink/40",Mn="mt-1 line-clamp-2 text-[11px] leading-snug text-ink/80",Nn="mt-2 border-t border-ink/10 pt-2",Rn="flex items-center gap-2 font-mono text-[10px] text-ink/40",kt="mt-1 text-[10px] leading-snug text-ink/50",Pn="mt-2 flex w-full items-center gap-1.5 text-left text-[10px] text-ink/50 hover:text-ink cursor-pointer",Ln="mt-1.5 space-y-1 border-t border-ink/10 pt-1.5",Te="flex items-center gap-1.5 font-mono text-[10px]";function q(t,r,l){let c=document.createElement(t);if(c.className=r,l!==void 0)c.textContent=l;return c}function Bn(t){return new Date(t*1000).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Dn(t){let r=t.payload;if(t.status==="error")return{title:"Blame failed",body:t.message??"git could not read this file."};if(t.status==="unavailable")return{title:r?.reason==="untracked"?"Not tracked":"No history",body:ht(r?.reason??"error",t.message??void 0)};if(!r)return null;if(t.stale)return{title:"Not committed yet",body:"This line changed in the editor. Save the file to see its blame."};if(t.line>r.lines)return{title:"Not committed yet",body:`Line ${t.line} is past the end of the file at HEAD (${r.lines} lines).`};let l=r.runs.length>0?Ct(r,t.line):null;if(!l)return{title:"Not committed yet",body:`git has no attribution for line ${t.line}.`};if(Ee(l.sha))return{title:"Not committed yet",body:"This line differs from the last commit."};return null}function Ct(t,r){for(let l of t.runs)if(r>=l.from&&r<=l.to)return t.commits[l.sha]??null;return null}function On(t,r){t.replaceChildren(),t.className=St;let l=Dn(r);if(l){let v=q("div",vt);if(v.append(q("span",xt,l.title)),r.status==="error"&&r.message){let w=q("button","shrink-0 cursor-pointer text-[10px] text-ink/50 hover:text-ink","Try again");w.type="button",w.setAttribute("aria-label","Read the blame again"),v.append(w)}t.append(v,q("p",kt,l.body));return}let c=r.payload;if(!c){t.append(q("p",kt,"Reading blame…"));return}let p=Ct(c,r.line),b=q("div",vt);if(b.append(q("span",xt,p.author.trim()||"Unknown"),q("span",Tn,ge(p.time))),t.append(b),p.summary)t.append(q("p",Mn,p.summary));let g=q("div",`${Rn} ${Nn}`);if(g.append(q("code","truncate",p.sha.slice(0,7)),q("span","",Bn(p.time))),p.mail){let v=q("span","truncate",p.mail);v.title=p.mail,g.append(v)}t.append(g);let h=q("button",Pn);if(h.type="button",h.setAttribute("aria-expanded",r.historyOpen?"true":"false"),h.textContent=`${r.historyOpen?"▾":"▸"} Line history`,t.append(h),!r.historyOpen)return;let x=q("ol",Ln);if(r.historyLoading)x.append(q("li",`${Te} text-ink/40`,"Reading history…"));else if(!r.history||r.history.entries.length===0)x.append(q("li",`${Te} text-ink/40`,"No commits touched this line."));else{let v=r.history.entries;if(v.forEach((w,k)=>{let A=q("li",Te),E=k===v.length-1?"new":"edit";A.append(q("span","text-ink/40",k===0?"●":"○"),q("code","text-ink/60",w.sha.slice(0,7)),q("span","truncate text-ink/80",w.author.trim()||"Unknown"),q("span","ml-auto shrink-0 text-ink/40",ge(w.time)),q("span","shrink-0 rounded bg-ink/5 px-1 text-[8.5px] uppercase tracking-wider text-ink/45",E)),x.append(A)}),r.history.truncated)x.append(q("li",`${Te} text-ink/40`,"Older commits are not shown."))}t.append(x)}function Et(t,r,l){let c=q("div",St);c.setAttribute("role","dialog"),c.setAttribute("aria-label","Line blame"),c.addEventListener("mousedown",(w)=>w.stopPropagation());let p=null,b=!1,g=!1,h=()=>{let w=r.snapshot();return{line:t,status:w.status,payload:w.payload,message:w.message,stale:r.stale(),history:p,historyOpen:b,historyLoading:g}},x=()=>{On(c,h());let w=c.querySelector('[aria-label="Read the blame again"]');if(w)w.addEventListener("click",(k)=>{k.stopPropagation(),l()});c.querySelector("button[aria-expanded]")?.addEventListener("click",(k)=>{if(k.stopPropagation(),b=!b,x(),!b||p||g)return;g=!0,x(),r.history(t).then((A)=>{p=A,g=!1,x()})})};x();let v=r.subscribe(x);return{element:c,place(w){let k=c.ownerDocument.defaultView,A=k?.innerWidth??1024,E=k?.innerHeight??768,M=c.offsetWidth||340,H=c.offsetHeight||120,K=8,W=Math.max(8,Math.min(w.left,A-M-8)),z=w.bottom+6,L=w.top-H-6,_=z+H>E-8&&L>8?L:z;c.style.left=`${W}px`,c.style.top=`${Math.max(8,_)}px`},destroy(){v(),c.remove()}}}function Tt(t){return ye.define((r)=>{let l=null,c=0,p,b=()=>{clearTimeout(p),p=void 0,l?.destroy(),l=null,c=0},g=(E,M)=>{let H=E.getBoundingClientRect();if(H.width>0)return{left:H.left,top:H.top,bottom:H.bottom};let K=r.state.doc.line(Math.min(M,r.state.doc.lines)),W=null;try{W=r.coordsAtPos(K.from)}catch{W=null}if(W)return W;let z=r.scrollDOM.getBoundingClientRect();return{left:z.left,top:z.top+24,bottom:z.top+24}},h=(E,M)=>{if(c===E&&l)return;b(),c=E,l=Et(E,t,()=>{t.reload(),b()}),document.body.append(l.element),l.place(M)},x=(E)=>{let M=E.target,H=M?.closest?.(".cm-blame-label");if(H){let z=Number(H.dataset.blameLine);return Number.isInteger(z)&&z>0?{line:z,anchor:H}:null}let K=M?.closest?.(".cm-lineNumbers .cm-gutterElement");if(!K)return null;let W=Number((K.textContent??"").trim());return Number.isInteger(W)&&W>0?{line:W,anchor:K}:null},v=(E)=>{let M=x(E);if(!M)return;h(M.line,g(M.anchor,M.line))},w=(E)=>{let M=x(E);if(M){E.preventDefault(),h(M.line,g(M.anchor,M.line));return}if(l&&!l.element.contains(E.target))b()},k=(E)=>{if(E.key==="Escape"&&l)b(),E.stopPropagation()},A=(E)=>{if(!l)return;let M=E.relatedTarget;if(M&&(l.element.contains(M)||r.scrollDOM.contains(M)))return;p=setTimeout(b,200)};return r.scrollDOM.addEventListener("mouseover",v),r.scrollDOM.addEventListener("mouseleave",A),r.scrollDOM.addEventListener("mousedown",w),document.addEventListener("mousedown",w),document.addEventListener("keydown",k,!0),{update(E){if(E.docChanged&&l)b()},destroy(){b(),r.scrollDOM.removeEventListener("mouseover",v),r.scrollDOM.removeEventListener("mouseleave",A),r.scrollDOM.removeEventListener("mousedown",w),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",k,!0)}}})}var Mt=40,Rt=re.define();function An(t){return Qe.define({create:()=>({payload:t.snapshot().payload,stale:!1}),update(r,l){let c=r;for(let p of l.effects){if(!p.is(Rt))continue;c=p.value.payload!==r.payload?{payload:p.value.payload,stale:!1}:{payload:r.payload,stale:r.stale}}if(l.docChanged&&!c.stale)c={payload:c.payload,stale:!0};return c}})}function In(t,r,l){let c=t.commits[r];if(!c||Ee(r))return null;let p=c.author.trim()||"Unknown";return l?p:`${p} · ${ge(c.time)}`}class Pt extends jt{constructor(t,r,l){super();this.line=t;this.text=r;this.title=l}eq(t){return t.line===this.line&&t.text===this.text&&t.title===this.title}toDOM(){let t=document.createElement("span");return t.className="cm-blame-label",t.dataset.blameLine=String(this.line),t.title=this.title,t.textContent=this.text,t}}function Nt(t,r,l){let{payload:c,stale:p}=t;if(!c?.available||p)return T.none;let b=Math.min(c.lines,r.state.doc.lines);if(b<1)return T.none;let g=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.from,r.state.doc.length))).number,h=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.to,r.state.doc.length))).number,x=Math.max(1,g-Mt),v=Math.min(b,h+Mt),w=[];for(let k of c.runs){let A=Math.max(k.from,x);if(A>k.to||A>v)continue;let E=In(c,k.sha,l);if(!E)continue;let M=c.commits[k.sha],H=r.state.doc.line(A);w.push({from:H.to,deco:T.widget({widget:new Pt(H.number,E,M.summary||M.sha),side:1})})}return T.set(w.map((k)=>k.deco.range(k.from)),!0)}function Fn(t,r){return ye.fromClass(class{constructor(l){this.view=l;this.decorations=Nt(l.state.field(t),l,r)}update(l){if(l.startState.field(t)===l.state.field(t)&&!l.docChanged&&!l.viewportChanged)return;this.decorations=Nt(l.state.field(t),l.view,r)}},{decorations:(l)=>l.decorations})}function zn(t){return ye.define((r)=>{let l=!0,c=()=>{if(!l)return;let b=t.snapshot();r.dispatch({effects:Rt.of({payload:b.payload,stale:!1})})},p=t.subscribe(c);return{destroy(){l=!1,p()}}})}function Lt({controller:t,inline:r=!0,compact:l=!1}){let c=An(t);return[c,zn(t),r?Fn(c,l):[],Tt(t)]}function Bt({activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:p,rootPath:b=null,repoPath:g=null,onRunCommand:h,wordWrap:x,zoomLevel:v,setZoomLevel:w,editorFontFamily:k,editorTheme:A,viewerKind:E,isPreview:M,reviewActive:H,onToggleReview:K,revealActive:W}){let z=E==="markdown",L=Gc(),_=qc(),O=ld(),G=gt({name:t.name,path:t.path,root:t.root??b??void 0,repo:t.repo??g??"."},{enabled:O.enabled,dirty:r.isDirty}),Z=u(()=>O.enabled?Lt({controller:G,inline:O.inline}):null,[O.enabled,O.inline,G]),[N,R]=n(null),P=u(()=>Bc(r.content),[r.content]),[Q,X]=n(!1);i(()=>{if(p>0)X(!0)},[p]);let[j,ne]=n(null),[me,ee]=n(null);ct(j,w);let te=Vs({tabKey:String(t.id),surface:z&&M?"rendered":"code",ready:r.loaded,element:z&&M?void 0:j}),ue=a((ae)=>{te.ref(ae),ee(ae)},[te.ref]);return Sc({path:t.path,scroller:me,preview:z&&M}),e("div",{className:"relative flex-1 min-h-0 flex flex-col",children:[l.open?e(_c,{find:l}):null,Q?e(ut,{lineCount:r.content?r.content.split(`
|
|
2
|
-
`).length:1,onGo:(ae)=>{X(!1);let se=dr(r.content,ae-1);c.current?.select(se,se,!0),c.current?.revealOffset(se)},onClose:()=>X(!1)}):null,z&&M?e(lt,{content:r.content,file:{name:t.name,path:t.path,root:t.root,repo:t.repo},zoomLevel:v,reviewActive:H,onExitReview:K,scrollRef:ue,onScroll:te.onScroll}):e(
|
|
3
|
-
`).length:0,conflicts:P}):null]})}function Dt({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W=null,repoPath:z=null,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N}){let R=h==="image"||h==="pdf"||h==="docx"||h==="spreadsheet",P=ns[h]===!0,Q=a(async(X)=>{let j=await Nc(t,X,{interactive:!0,baseMtimeMs:r.baseMtimeMs});if(j.status==="written")return{ok:!0};if(j.status==="conflict")return{ok:!1,error:"This file changed on disk since it was opened."};if(j.status==="needs-permission")return{ok:!1,error:"Click Save again to grant write access."};return{ok:!1,error:j.error}},[t,r.baseMtimeMs]);return e(d,{children:[e(st,{path:t.path,saveStatus:r.saveStatus,wordWrap:b,hasPreview:P,isPreview:x,hasReview:h==="markdown"&&x,isReviewing:v,copied:r.copied,byteViewer:R,saveDisabled:Boolean(r.loadError)||r.handleMissing||r.deviceBacked,unsupported:Boolean(r.unsupported),handleMissing:r.handleMissing,readOnly:r.deviceBacked,isMaximized:k,findOpen:l.open,onToggleFind:()=>l.open?l.close():l.openFind(),onSave:r.saveNow,onTogglePreview:G,onToggleReview:w,onToggleWordWrap:()=>g(!b),onZoomIn:()=>M((X)=>Math.min(zs,X+1)),onZoomOut:()=>M((X)=>Math.max($s,X-1)),onCopy:r.copy,onDownload:r.download,onReload:r.reloadFromDisk,onSaveAs:K,canReload:al(t)&&!r.loadError&&!r.unsupported,refreshing:r.isReading,reloadDiscardsEdits:r.isDirty,onToggleMaximize:()=>A(!k)}),N&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-error/30 bg-error/10 text-error",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was deleted from disk."}),e("div",{className:"text-[11px] font-sans text-error/80",children:"The buffer is still here. Saving recreates the file — autosave is off until then."})]})]}),r.conflict&&e(Ce,{diskMtimeMs:r.conflict.diskMtimeMs,fileName:t.name,onReload:r.resolveConflictByReload,onKeepMine:r.resolveConflictByKeepingMine}),r.handleMissing&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-warning",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was opened by the system, not from a workspace."}),e("div",{className:"text-[11px] font-sans text-warning/80",children:"Its write permission ended with the last page load. Reopen the file from the OS to edit it again."})]})]}),r.deviceBacked&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-ink/20 bg-ink/5 text-ink/70",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:r.deviceMissing?"The bytes for this file did not survive the reload.":"Opened from this device, so it is read-only here."}),e("div",{className:"text-[11px] font-sans text-ink/50",children:r.deviceMissing?"A phone's file lives only on the phone, so it cannot be re-read. Open it again from the app that shared it.":"The console cannot reach a file on your phone. Copy it into a workspace to edit it."})]})]}),r.isImage&&r.imageUrl?e(Ri,{src:r.imageUrl,name:t.name,className:"flex-1 min-h-0"}):r.isImage?e(rl,{kind:"image",path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision}):r.isLoading?e("div",{className:"flex-1 flex items-center justify-center gap-2 text-ink/40 text-xs font-mono",children:[e(m,{size:14,className:"animate-spin"}),e("span",{children:"Loading file content…"})]}):r.unsupported?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(wc,{size:20,className:"text-ink/40"}),e("span",{className:"text-xs text-ink/70 font-sans",children:[t.name," cannot be opened here"]}),e("span",{className:"text-[11px] text-ink/50 font-sans max-w-[42ch]",children:r.unsupported})]}):r.loadError?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(D,{size:20,className:"text-error"}),e("span",{className:"text-xs text-error font-sans",children:["Could not read ",t.name]}),e("span",{className:"text-[11px] text-ink/50 font-mono break-all",children:r.loadError})]}):p&&!r.isImage?e(tA,{view:p}):Dc(h)&&(R||x)?e(rl,{kind:h,path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision,onContentChange:r.onChange,onSaveBytes:r.deviceBacked?void 0:Q,onDirtyChange:r.setBinaryDirty}):e(Bt,{activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:H,rootPath:W,repoPath:z,onRunCommand:L,wordWrap:b,zoomLevel:E,setZoomLevel:M,editorFontFamily:_,editorTheme:O,isPreview:x,reviewActive:v,onToggleReview:w,viewerKind:h,revealActive:Z})]})}function Ot({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W=null,repoPath:z=null,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N,onConvertDiffToEditor:R,onFileSaved:P}){if(!t)return e("div",{className:"flex-1 flex items-center justify-center text-ink/40",children:e("p",{className:"font-mono text-sm",children:"Select a tab to view content"})});if(t.isDiff)return e(Cc,{filePath:t.path,status:t.diffStatus||"M",isStaged:Boolean(t.diffStaged),root:t.root,repo:t.repo||".",onOpenInEditor:()=>R(t.id),onFileSaved:P,className:"flex-1",tabKey:String(t.id)});return e(Dt,{activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W,repoPath:z,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N})}function At({pluginId:t,Component:r,sessionId:l,className:c=""}){return e("div",{className:`flex flex-col h-full bg-canvas ${c}`,children:e(Ke,{pluginId:t,children:e(r,{sessionId:l,workspacePath:null})})})}function It({className:t=""}){return e("div",{className:`flex flex-col h-full bg-canvas items-center justify-center text-muted ${t}`,children:[e(rt,{name:"placeholder.txt",size:48,className:"mb-4 opacity-20"}),e("p",{className:"font-mono text-sm",children:"Select a file to open"})]})}function Ft({searchReveal:t,revealMatch:r}){let l=o(r);l.current=r;let c=o(null);i(()=>{if(!t||c.current===t.request)return;c.current=t.request,l.current({query:t.request.query,options:t.request.options,line:t.request.line})},[t])}function zt({openedFiles:t,dirtyKeys:r,activeFile:l,previewReady:c,setPreviewMode:p,sessionId:b}){i(()=>{let g=new Set(t.filter((h)=>!h.isDiff&&h.content===void 0).map((h)=>h.id));ze([...r].filter((h)=>g.has(h)))},[r,t]),i(()=>{if(!c)return;let g=l?.id;if(!l||g===void 0||g===null)return;if(!ns[rs(l.name)])return;let h=$e(b,"editor.previewMode");if(h&&h[g]!==void 0)return;p((x)=>x[g]===void 0?{...x,[g]:!0}:x)},[c,l])}function Ht({activeFile:t,externalChange:r,conflict:l,onReload:c,onKeepMine:p}){if(!t)return null;if(l)return e(Ce,{diskMtimeMs:l.diskMtimeMs,fileName:t.name,onReload:c,onKeepMine:p});if(r)return e(Pc,{fileName:t.name,onReload:c,onKeepMine:p});return null}async function $t(t){let r=t.name.trim();if(!r)return{status:"failed",reason:"Enter a file name."};let l=new FormData;if(l.append("actionType","saveAs"),l.append("path",t.parent),l.append("name",r),l.append("content",t.content),l.append("eol",t.eol),t.root)l.append("root",t.root);if(t.repo&&t.repo!==".")l.append("repo",t.repo);try{let c=await fetch("/api/fs/action",{method:"POST",body:l}),p=await c.json().catch(()=>null),b=typeof p?.error==="string"?p.error:null;if(c.status===409)return{status:"exists",reason:b??`${r} already exists.`};if(c.ok&&p?.success&&typeof p.path==="string")return{status:"written",path:p.path};return{status:"failed",reason:b??"The file could not be written."}}catch{return{status:"failed",reason:"The file could not be written."}}}function Vt(t){let r=t.lastIndexOf(".");if(r<=0)return`${t} copy`;return`${t.slice(0,r)} copy${t.slice(r)}`}function Wt(t){let r=t.trim();if(!r)return!1;if(r==="."||r==="..")return!1;return!r.includes("/")&&!r.includes("\\")}function Hn(t){let r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function Ut({fileName:t,filePath:r,content:l,eol:c,root:p,repo:b,onSaved:g,onClose:h}){let[x,v]=n(()=>Hn(r)),[w,k]=n(()=>Vt(t)),[A,E]=n(!1),[M,H]=n(null),K=o(null);i(()=>{K.current?.focus(),K.current?.select()},[]);let W=Wt(w),z=async()=>{if(!W||A)return;E(!0),H(null);let _=await $t({parent:x,name:w,content:l,eol:c,root:p,repo:b});if(E(!1),_.status==="written"){g({path:_.path});return}H(_.reason)},L=(_)=>{if(_.key==="Enter"){_.preventDefault(),z();return}if(_.key==="Escape")_.preventDefault(),h()};return e(J,{onClose:h,maxWidthClass:"max-w-md",header:e("span",{className:"text-sm font-semibold text-ink",children:"Save as"}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:h,className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>void z(),disabled:!W||A,className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-ink text-paper disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[A?e(m,{size:12,className:"animate-spin"}):e(ft,{size:12}),"Save"]})]}),children:e("div",{className:"px-4 py-3 space-y-2 text-xs",children:[e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Folder"}),e("input",{value:x,onInput:(_)=>v(_.target.value),onKeyDown:L,placeholder:"(workspace root)","aria-label":"Destination folder",className:"w-full bg-paper border border-ink/20 rounded px-2 py-1 font-mono text-ink outline-none focus:border-ink/40"})]}),e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Name"}),e("input",{ref:K,value:w,onInput:(_)=>k(_.target.value),onKeyDown:L,"aria-label":"File name","aria-invalid":!W,className:`w-full bg-paper border rounded px-2 py-1 font-mono text-ink outline-none ${W?"border-ink/20 focus:border-ink/40":"border-error text-error"}`})]}),!W?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a file name without a path separator"}):null,M?e("div",{className:"text-[10px] text-error font-mono",children:M}):null,e("div",{className:"text-[10px] text-ink/40",children:"The original file stays where it is, and its tab stays open."})]})})}function _t(){i(()=>{let t=(r)=>{if(!Ue())return;r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[])}function Gt({fileName:t,onAnswer:r}){return e(J,{onClose:()=>r("cancel"),header:e("div",{className:"flex items-center gap-2",children:[e(D,{size:15,className:"text-warning"}),e("span",{className:"text-sm font-semibold text-ink",children:"Unsaved changes"})]}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:()=>r("cancel"),className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>r("discard"),className:"px-3 py-1.5 rounded border border-error/40 text-error hover:bg-error/10 transition-colors cursor-pointer",children:"Discard"}),e("button",{type:"button",onClick:()=>r("save"),className:"px-3 py-1.5 rounded bg-ink text-paper hover:bg-ink/90 transition-colors cursor-pointer",children:"Save & close"})]}),children:e("div",{className:"px-4 py-3 text-xs text-ink/80",children:[e("span",{className:"font-mono text-ink",children:t})," has changes that are not on disk.",e("div",{className:"mt-1 text-ink/50",children:"Discarding them cannot be undone."})]})})}function qt({closeGuard:t,activeFile:r,saveMissingConfirm:l,onCancelSaveMissing:c,onConfirmSaveMissing:p}){if(t.pending)return e(Gt,{fileName:t.pending.name,onAnswer:t.answer});if(l&&r)return e(Oc,{fileName:r.name,filePath:r.path,onClose:c,onConfirm:p});return null}function Zt({className:t="",isMaximized:r,onKeyDownCapture:l,onFocusCapture:c,asSplitPane:p,tabs:b,activeFile:g,editor:h,externalChange:x,conflict:v,onReload:w,onKeepMine:k,body:A,saveAsOpen:E,onSaveAsClose:M,onSavedAs:H,closeGuard:K}){let W=r?"fixed inset-0 z-50 flex flex-col bg-canvas":`flex flex-col h-full bg-canvas ${t}`;return e("div",{className:W,onKeyDownCapture:l,onFocusCapture:c,children:[p?null:b,e(Ht,{activeFile:g,externalChange:x,conflict:v,onReload:w,onKeepMine:k}),A,E&&g?e(Ut,{fileName:g.name,filePath:g.path,content:h.content,eol:h.eol,root:g.root,repo:g.repo,onSaved:({path:z})=>H(z),onClose:M}):null,e(qt,{closeGuard:K,activeFile:g,saveMissingConfirm:h.saveMissingConfirm,onCancelSaveMissing:h.cancelSaveMissing,onConfirmSaveMissing:h.confirmSaveMissing})]})}function Xt({fileName:t,onClose:r,children:l}){return e("div",{className:"flex flex-col h-full min-w-0","data-split-pane":"",children:[e("div",{className:"flex items-center justify-between gap-2 px-3 py-1 border-b border-ink/10 bg-canvas flex-shrink-0",children:[e("span",{className:"text-[11px] font-mono text-ink/60 truncate",title:t,children:t}),e("button",{type:"button",onClick:r,className:"p-0.5 rounded hover:bg-ink/10 text-ink/50 hover:text-ink transition-colors cursor-pointer flex-shrink-0",title:"Close this pane (the tab stays open)","aria-label":"Close split pane",children:e(y,{size:12})})]}),e("div",{className:"flex-1 min-h-0",children:l})]})}function Yt({fraction:t,onFraction:r,rightPaneName:l,onClosePane:c,rightPane:p,children:b}){let g=o(null),h=(x)=>{let v=x.currentTarget,w=g.current;if(!v||!w)return;v.setPointerCapture(x.pointerId);let k=(E)=>{let M=w.getBoundingClientRect();if(M.width===0)return;r(pe((E.clientX-M.left)/M.width))},A=()=>{v.releasePointerCapture(x.pointerId),v.removeEventListener("pointermove",k),v.removeEventListener("pointerup",A)};v.addEventListener("pointermove",k),v.addEventListener("pointerup",A)};return e("div",{ref:g,className:"flex w-full h-full","data-split-column":"",children:[e("div",{className:"flex flex-col min-w-0 h-full",style:{width:`${Math.round(pe(t)*100)}%`},children:b}),e("div",{className:"w-[3px] flex-shrink-0 cursor-col-resize bg-ink/10 hover:bg-ink/40 transition-colors",role:"separator","aria-orientation":"vertical","aria-label":"Resize split panes",onPointerDown:h}),e("div",{className:"flex-1 min-w-0 h-full",children:e(Xt,{fileName:l,onClose:c,children:p})})]})}function Jt({openedFiles:t,activeFileId:r,enabled:l}){let[c,p]=S("editor.split",be),b=t.map((k)=>k.id),g=Ye(Je(c,b),r),h=l&&g.rightFileId!==null?t.find((k)=>k.id===g.rightFileId)??null:null,x=a((k)=>{if(k!==null&&!Se(k,r,b))return;p({...g,rightFileId:k})},[g,p,r,b]),v=a(()=>p({...g,rightFileId:null}),[g,p]),w=a((k)=>p({...g,fraction:pe(k)}),[g,p]);return{rightFile:h,fraction:g.fraction,splitTo:x,close:v,setFraction:w}}function Qt({find:t,runCommand:r,reopenClosed:l}){let c=o(t);c.current=t;let p=o(r);p.current=r;let b=o(l);return b.current=l,{onKeyDownCapture:a((h)=>{let x=c.current;if(h.key==="Escape"){if(!x.open)return;h.preventDefault(),h.stopPropagation(),x.close();return}if((h.metaKey||h.ctrlKey)&&h.shiftKey&&h.code==="KeyT"){if(b.current?.())h.preventDefault(),h.stopPropagation();return}let v=xg(lo,h);if(!v||!Um(v))return;h.preventDefault(),h.stopPropagation(),p.current(v)},[])}}function tn(t){let r=o(t);r.current=t;let l=o(null);if(!l.current)l.current={saveNow:()=>r.current.saveNow(),runCommand:(p)=>r.current.runCommand(p)};return i(()=>{let p=l.current;if(!p)return;return Vf(p)},[]),{onFocusCapture:a(()=>{if(l.current)Vf(l.current)},[])}}function nn({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,saveNow:p}){let[b,g]=n(null);_t();let h=a((v)=>{let w=t.find((k)=>k.id===v);if(w&&We(v)){g(w);return}c(v)},[t,c]),x=a((v)=>{let w=b;if(!w)return;if(v==="cancel"){g(null);return}if(v==="save"){if(w.id!==r)l(w.id);p()}g(null),c(w.id)},[b,r,l,p,c]);return{requestClose:h,pending:b,answer:x}}function on(){let[t,r]=n(0),[l,c]=n(!1),p=a(()=>r((b)=>b+1),[]);return{goToLineRequest:t,openGoToLine:p,saveAsOpen:l,setSaveAsOpen:c}}function $n({className:t="",openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:b,refreshKey:g=0,onFileSaved:h,onOpenPath:x,onReopenClosed:v,reopenableCount:w,onCopyPath:k,onRevealInFiles:A,rootPath:E=null,repoPath:M=null,activeEditorPanelKey:H=null,forcedActiveFileId:K=null,asSplitPane:W=!1}){let z=W?K:l,L=r.find((U)=>U.id===z),[_,O,G]=S("editor.previewMode",{}),Z=$c(String(z??"")),[N,R]=S("editor.zoomLevel",yi),[P,Q]=n(!1),[X,j]=S("editor.wordWrap",!0),ne=on(),{sessionId:me}=Ze(),ee=Jt({openedFiles:r,activeFileId:z,enabled:!W}),te=o(null),ue=wi(),ae=uo(),se=Qc(r,g),fe=Boolean(L&&se.has(L.id)),Y=Rc(L??null,{reportSaveError:!0,onFileSaved:h,missing:fe}),rn=eA({path:L?.path??"",content:Y.content,language:Y.language}),an=Y.diskChange,Be=nn({openedFiles:r,activeFileId:z,onSelectFile:c,onCloseFile:p,saveNow:Y.saveNow}),ve=Fc({text:Y.content,documentKey:`${L?.id??""}\x00${Y.language}`,readSelection:()=>te.current?.getSelection()??null,select:(U,ce,Re=!0)=>te.current?.select(U,ce,Re),reveal:(U)=>te.current?.revealOffset(U),applyDocument:(U,ce,Re)=>te.current?.applyDocument(U,ce,Re),toggleWordWrap:()=>j((U)=>!U)}),De=Mc(L?.path??null,Y.content,Y.loaded&&!Y.loadError);Ft({searchReveal:De,revealMatch:ve.revealMatch}),Lc({file:L,editor:Y,surfaceRef:te,isPreview:L?_[L.id]===!0:!1,exitPreview:()=>{let U=L?.id;if(U===void 0||U===null)return;O((ce)=>({...ce,[U]:!1}))}}),i(()=>{if(g>0)Y.reset()},[g]),i(()=>{Y.retain(r.map((U)=>U.id)),Ve(r.map((U)=>U.id))},[r]),zt({openedFiles:r,dirtyKeys:Y.dirtyKeys,activeFile:L,previewReady:G,setPreviewMode:O,sessionId:me});let sn=()=>{if(!L)return;O((U)=>({...U,[L.id]:!U[L.id]}))},Me=(U)=>{if(Um(U)){ve.runCommand(U);return}if(U==="toggleWordWrap"){j((ce)=>!ce);return}if(U==="goToLine"){ne.openGoToLine();return}te.current?.runCommand(U)},ln=Qt({find:ve,runCommand:Me,reopenClosed:v}),dn=tn({saveNow:Y.saveNow,runCommand:Me}),Ne=Fg(H);if(Ne)return e(At,{pluginId:Ne.pluginId,Component:Ne.Component,sessionId:me,className:t});if(r.length===0)return e(It,{className:t});let cn=Y.viewerKind,Oe=L?_[L.id]:!1,mn={activeFile:L,editor:Y,find:ve,surfaceRef:te,pluginFileView:rn,wordWrap:X,setWordWrap:j,viewerKind:cn,isPreview:Boolean(Oe),isReviewing:Boolean(Oe)&&Z.active,onToggleReview:Z.toggle,isMaximized:P,setIsMaximized:Q,zoomLevel:N,setZoomLevel:R,goToLineRequest:ne.goToLineRequest,onSaveAs:()=>ne.setSaveAsOpen(!0),onOpenPath:x,rootPath:E,repoPath:M,runCommand:Me,editorFontFamily:ue,editorTheme:ae,togglePreview:sn,revealActive:Boolean(De),missing:fe,onConvertDiffToEditor:b,onFileSaved:h},un=(U)=>({openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:b,refreshKey:g,onFileSaved:h,onOpenPath:x,rootPath:E,repoPath:M,forcedActiveFileId:U,asSplitPane:!0}),pn=e(tt,{openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:Be.requestClose,missingIds:se,onCopyPath:k,onRevealInFiles:A,onReopenClosed:v,reopenableCount:w,onSplitTo:ee.splitTo,onUnsplit:ee.close,splitRightFileId:ee.rightFile?.id??null}),Ae=e(Zt,{className:t,isMaximized:P,onKeyDownCapture:ln.onKeyDownCapture,onFocusCapture:dn.onFocusCapture,asSplitPane:W,tabs:pn,activeFile:L,editor:Y,externalChange:an,conflict:Y.conflict,onReload:Y.resolveConflictByReload,onKeepMine:Y.keepMineAgainstDisk,body:e(Ot,{...mn}),saveAsOpen:ne.saveAsOpen,onSaveAsClose:()=>ne.setSaveAsOpen(!1),onSavedAs:(U)=>{ne.setSaveAsOpen(!1),x?.(U)},closeGuard:Be});if(!ee.rightFile)return Ae;return e(Yt,{fraction:ee.fraction,onFraction:ee.setFraction,rightPaneName:ee.rightFile.name,onClosePane:ee.close,rightPane:e($n,{...un(ee.rightFile.id)}),children:Ae})}export{$n as Editor};
|
|
1
|
+
import{d,n,i,V,o,u,a,He,de,e,Gn,Ze,$e,S,s,I,m,Kt,D,f,B,oe,ft,he,wt,Ge,Ji,en,jr,C,F,y,Hr,Ke,le,dr,J,rt,Os,yi,$s,zs,wi,Cg,Mg,Vs,Qe,re,jt,T,ye,Ri,lo,Gm,Yf}from"./index-zt75xpq0.js";import{yt,uo,Gc,jc,Hc,is,po,cd}from"./index-bkye8mz4.js";import{Cc,ed,td,tA,nA,Ec,Zn,ts,Bc,Ic,_c,Sc,Tc,ns,Fi,rs,Qc,rl,al,Nc,Rc,Fc,Lc,Mc,Pc,Oc,$c,zc}from"./index-sffjtm5w.js";import{_a,Sa,fo}from"./index-9fjt5anh.js";var fn={name:"git-commit-vertical",size:24,node:[["path",{d:"M12 3v6",key:"1holv5"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["path",{d:"M12 15v6",key:"a9ows0"}]]},Pe=s(fn);var bn={name:"maximize",size:24,node:[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]},xe=s(bn);var gn={name:"minimize",size:24,node:[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]},we=s(gn);var hn={name:"save-all",size:24,node:[["path",{d:"M10 2v3a1 1 0 0 0 1 1h5",key:"1xspal"}],["path",{d:"M18 18v-6a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6",key:"1ra60u"}],["path",{d:"M18 22H4a2 2 0 0 1-2-2V6",key:"pblm9e"}],["path",{d:"M8 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9.172a2 2 0 0 1 1.414.586l2.828 2.828A2 2 0 0 1 22 6.828V16a2 2 0 0 1-2.01 2z",key:"1yve0x"}]]},ke=s(hn);var ie=new Set,Le=new Set,Ie=new Set;function Fe(){Ie=new Set(ie);for(let t of[...Le])t()}function ze(t){let r=new Set(t);if(r.size===ie.size){let l=!0;for(let c of r)if(!ie.has(c)){l=!1;break}if(l)return}ie.clear();for(let l of r)ie.add(l);Fe()}function Ve(t){let r=new Set(t),l=!1;for(let c of[...ie])if(!r.has(c))ie.delete(c),l=!0;if(l)Fe()}function We(t){return ie.has(t)}function Ue(){return ie.size>0}function vn(t){return Le.add(t),()=>{Le.delete(t)}}var yn=vn;function _e(){return He(yn,()=>Ie)}function qe({x:t,y:r,rows:l,onAction:c,onClose:p}){let b=o(null),[g,h]=n({left:t,top:r});return V(()=>{let x=b.current;if(!x)return;let{width:v,height:w}=x.getBoundingClientRect();h({left:Math.min(t,Math.max(0,window.innerWidth-v-8)),top:Math.min(r,Math.max(0,window.innerHeight-w-8))})},[t,r,l.length]),de(e("div",{className:"fixed inset-0 z-[70]",onClick:p,onContextMenu:(x)=>{x.preventDefault(),p()},children:e("div",{ref:b,role:"menu","aria-label":"Tab actions",className:"glass-popover absolute w-52 bg-paper border border-ink/15 rounded-md shadow-xl py-1 text-xs text-ink",style:{left:`${g.left}px`,top:`${g.top}px`},onClick:(x)=>x.stopPropagation(),children:l.map((x)=>e("button",{type:"button",role:"menuitem",onClick:()=>{c(x.action),p()},className:"w-full text-left px-3 py-1.5 hover:bg-ink/5 transition-colors cursor-pointer",children:x.label},x.action))})}),document.body)}var be={rightFileId:null,fraction:0.5};function Se(t,r,l){if(t===null)return!1;if(t===r)return!1;return l.includes(t)}function Xe(t,r){for(let l=r.length-1;l>=0;l-=1){let c=r[l];if(c!==t)return c}return null}function Ye(t,r){if(t.rightFileId===null)return t;if(t.rightFileId!==r)return t;return{...t,rightFileId:null}}function pe(t){if(!Number.isFinite(t))return be.fraction;return Math.max(0.2,Math.min(0.8,t))}function je(t,r){if(typeof t!=="object"||t===null)return be;let l=t,c=typeof l.fraction==="number"?pe(l.fraction):be.fraction,p=typeof l.rightFileId==="string"||typeof l.rightFileId==="number"?l.rightFileId:null;if(p===null||!r.includes(p))return{rightFileId:null,fraction:c};return{rightFileId:p,fraction:c}}function Je({tab:t,openedFiles:r,dirtyIds:l,reopenable:c,activeFileId:p,splitRightFileId:b}){let g=r.filter((w)=>w.id!==t.id),h=r.filter((w)=>!l.has(w.id)),x=r.map((w)=>w.id);return[{action:"split-right",label:"Split right",enabled:Se(t.id,p,x)},{action:"unsplit",label:"Unsplit",enabled:b!==null},{action:"close",label:"Close",enabled:!0},{action:"close-others",label:"Close others",enabled:g.length>0},{action:"close-all",label:"Close all",enabled:r.length>0},{action:"close-saved",label:"Close saved",enabled:h.some((w)=>w.id!==t.id)},{action:"copy-path",label:"Copy path",enabled:Boolean(t.path)},{action:"reveal-in-files",label:"Reveal in Files",enabled:Boolean(t.path)&&!t.isDiff},{action:"reopen-closed",label:"Reopen closed tab",enabled:c>0}].filter((w)=>w.enabled)}function tt({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,missingIds:p,onCopyPath:b,onRevealInFiles:g,onReopenClosed:h,reopenableCount:x,onSplitTo:v,onUnsplit:w,splitRightFileId:k=null}){let A=_e(),E=o(null),M=o(null),[H,K]=n(5),[W,z]=n(!1),[L,_]=n(null);le(M,()=>z(!1)),i(()=>{let N=new ResizeObserver((R)=>{for(let P of R){let Q=P.contentRect.width,X=Math.max(1,Math.floor((Q-60)/150));K(X)}});if(E.current)N.observe(E.current);return()=>N.disconnect()},[]);let O=Xe(r,t.map((N)=>N.id)),G=[],Z=[];if(t.length<=H)G=t;else{let N=t.findIndex((P)=>P.id===r),R=new Set;if(N!==-1&&r!==null)R.add(r);for(let P=t.length-1;P>=0;P--){if(R.size>=H)break;R.add(t[P].id)}G=t.filter((P)=>R.has(P.id)),Z=t.filter((P)=>!R.has(P.id))}return e("div",{className:"flex bg-ink/10 w-full relative border-b border-ink/10",ref:E,children:[e("div",{className:"flex overflow-hidden",children:G.map((N)=>{let R=N.id===r,P=Boolean(N.isDiff),Q=P?Gn(N.diffStatus||"M",N.diffStaged):null,X=Boolean(p?.has(N.id));return e("div",{onClick:()=>l(N.id),onContextMenu:(j)=>{j.preventDefault(),_({tab:N,x:j.clientX,y:j.clientY})},className:`flex items-center space-x-1.5 px-3 py-1.5 cursor-pointer border-r border-ink/10 min-w-[120px] max-w-[210px] group ${R?"bg-paper border-t-2 border-t-ink text-ink":"bg-transparent border-t-2 border-t-transparent text-ink/60 hover:bg-paper/50"}`,title:X?`${N.path} — file no longer exists`:N.path,children:[P?e(Ji,{size:14,className:R?"text-info flex-shrink-0":"text-info/70 flex-shrink-0"}):e(rt,{name:N.name,size:14,className:`flex-shrink-0${R||X?"":" opacity-60"}${X?" text-error":""}`}),e("span",{className:`text-xs font-mono truncate flex-1${X?" text-error line-through":""}`,children:N.name}),Q&&e("span",{className:`px-1 text-[10px] font-mono font-bold rounded ${Q.badgeBgClass}`,children:Q.charStatus}),e(et,{dirty:A.has(N.id),active:R,label:`Close ${N.name}`,onClose:()=>c(N.id)})]},N.id)})}),L?e(qe,{x:L.x,y:L.y,rows:Je({tab:L.tab,openedFiles:t,dirtyIds:A,reopenable:x?.()??0,activeFileId:r,splitRightFileId:k}),onAction:(N)=>{let R=L.tab;switch(N){case"close":c(R.id);return;case"close-others":for(let P of[...t].reverse())if(P.id!==R.id)c(P.id);l(R.id);return;case"close-all":for(let P of[...t].reverse())c(P.id);return;case"close-saved":for(let P of[...t].reverse())if(!A.has(P.id))c(P.id);return;case"copy-path":b?.(R);return;case"reveal-in-files":g?.(R);return;case"reopen-closed":h?.();return;case"split-right":v?.(R.id);return;case"unsplit":w?.();return}},onClose:()=>_(null)}):null,e("div",{className:"ml-auto flex items-center",children:e("button",{type:"button",onClick:()=>k!==null?w?.():v?.(O),disabled:k===null&&O===null,"aria-pressed":k!==null,"aria-label":"Split editor",title:k!==null?"Close the split pane (the tab stays open)":O===null?"Open another file to split the editor":"Split the editor and show the newest other file",className:`p-1.5 mx-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-default ${k!==null?"bg-ink/10 text-ink":"text-ink/60 hover:bg-ink/10"}`,children:e(jr,{size:14})})}),Z.length>0&&e("div",{className:"relative flex items-center bg-ink/10",ref:M,children:[e("button",{className:`p-1.5 mx-1 rounded hover:bg-ink/10 text-ink/60 ${W?"bg-ink/10 text-ink":""}`,onClick:()=>z(!W),title:"More open files",children:e(B,{size:14})}),W&&e("div",{className:"glass-popover absolute right-0 top-full mt-1 w-52 bg-paper border border-ink/10 rounded shadow-lg z-50 py-1",children:[e("div",{className:"px-3 py-1 text-[10px] uppercase font-mono text-ink/40 border-b border-ink/10 mb-1",children:"Older Tabs"}),Z.map((N)=>{let R=Boolean(p?.has(N.id));return e("div",{onClick:()=>{l(N.id),z(!1)},className:"flex items-center space-x-2 px-3 py-1.5 hover:bg-ink/5 cursor-pointer group",children:[N.isDiff?e(Ji,{size:14,className:"text-info/80"}):e(rt,{name:N.name,size:14,className:R?"text-error":"opacity-60"}),e("span",{className:`text-xs font-mono truncate flex-1 ${R?"text-error line-through":"text-ink/80"}`,children:N.name}),e(et,{dirty:A.has(N.id),active:!1,label:`Close ${N.name}`,onClose:()=>{if(c(N.id),Z.length===1)z(!1)}})]},N.id)})]})]})]})}function et({dirty:t,active:r,label:l,onClose:c}){return e("div",{role:"button",tabIndex:-1,"aria-label":l,title:t?`${l} — unsaved changes`:l,className:`p-0.5 rounded hover:bg-ink/10 touch-visible ${r||t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:(p)=>{p.stopPropagation(),c()},children:t?e("span",{className:"block w-2 h-2 rounded-full bg-current mx-0.5","data-tab-dirty":"","aria-hidden":"true"}):e(y,{size:12})})}function xn(t){if(t===null)return null;let r=new Date(t);if(Number.isNaN(r.getTime()))return null;return r.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Ce({diskMtimeMs:t,fileName:r,onReload:l,onKeepMine:c}){let p=xn(t);return e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-[11px] text-ink flex-shrink-0",role:"alert","data-conflict-strip":"",children:[e(D,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e("div",{className:"min-w-0 flex-1",children:[e("div",{className:"font-medium",children:[e("span",{className:"font-mono",children:r})," changed on disk",p?e("span",{className:"text-ink/60",children:[" at ",p]}):null,"."]}),e("div",{className:"text-ink/60 mt-0.5",children:"Your save was refused so nothing was overwritten."})]}),e("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e("button",{type:"button",onClick:l,className:"px-2 py-1 rounded border border-ink/20 hover:bg-ink/5 transition-colors cursor-pointer",title:"Discard my changes and take the file from disk",children:"Reload"}),e("button",{type:"button",onClick:c,className:"px-2 py-1 rounded border border-warning/50 text-warning hover:bg-warning/10 transition-colors cursor-pointer",title:"Write my buffer over the file on disk",children:"Keep mine"})]})]})}function nt(t){if(t.byteViewer)return[];return[{id:"save",pinned:!0,actions:[{label:"Save file",icon:ke,onSelect:t.onSave,disabled:t.saveDisabled}],children:t.saveButton},{id:"save-as",actions:[{label:"Save as…",icon:ke,onSelect:t.onSaveAs}],children:e("button",{type:"button",onClick:t.onSaveAs,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Save the buffer to a new file","aria-label":"Save as",children:e(ke,{size:14})})}]}function ot(t){if(!t.hasReview)return[];let r=t.isReviewing?"Exit review mode":"Review this document";return[{id:"review",actions:[{label:r,icon:en,onSelect:t.onToggleReview,active:t.isReviewing}],children:e(ts,{label:r,pressed:t.isReviewing,title:t.isReviewing?"Review mode is on — click a block to judge it":"Review: click blocks to mark them good or needing work",onClick:t.onToggleReview,children:e(en,{size:14})})}]}function it(t){if(!t.hasPreview)return[];return[{id:"preview",actions:[{label:t.previewLabel,icon:t.isPreview?wt:Ge,onSelect:t.onTogglePreview,active:t.isPreview}],children:e(ts,{label:t.previewLabel,pressed:t.isPreview,onClick:t.onTogglePreview,children:t.isPreview?e(wt,{size:14}):e(Ge,{size:14})})}]}function at(t){let r=[];if(r.push(...nt(t),...ot(t),...it(t)),!t.byteViewer)r.push({id:"find",actions:[{label:t.findLabel,icon:F,onSelect:t.onToggleFind,active:t.findOpen}],children:e(ts,{label:t.findLabel,pressed:t.findOpen,title:`${t.findLabel} (Ctrl+F)`,onClick:t.onToggleFind,children:e(F,{size:14})})}),r.push({id:"wrap",actions:[{label:t.wordWrapLabel,icon:Kt,onSelect:t.onToggleWordWrap,active:t.wordWrap}],children:e(ts,{label:t.wordWrapLabel,pressed:t.wordWrap,onClick:t.onToggleWordWrap,children:e(Kt,{size:14})})}),r.push({id:"blame",actions:[{label:t.blameInline?"Hide line blame":"Show line blame",icon:Pe,onSelect:t.onToggleBlameInline,active:t.blameInline}],children:e(ts,{label:t.blameInline?"Hide line blame":"Show line blame",pressed:t.blameInline,title:"Who last changed each block, from git (hover a line for the commit)",onClick:t.onToggleBlameInline,children:e(Pe,{size:14})})}),r.push({id:"zoom",actions:[{label:"Decrease font size",icon:Sa,onSelect:t.onZoomOut},{label:"Increase font size",icon:_a,onSelect:t.onZoomIn}],children:e(d,{children:[e("button",{type:"button",onClick:t.onZoomOut,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Decrease font size","aria-label":"Decrease font size",children:e(Sa,{size:14})}),e("button",{type:"button",onClick:t.onZoomIn,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Increase font size","aria-label":"Increase font size",children:e(_a,{size:14})})]})}),r.push({id:"reload",actions:[{label:"Reload from disk",icon:C,onSelect:t.onReload,disabled:!t.canReload}],children:e("button",{type:"button",onClick:t.onReload,disabled:!t.canReload||t.refreshing,"aria-busy":t.refreshing,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:!t.canReload?"Nothing to reload — this tab has no file on disk":t.reloadDiscardsEdits?"Discard my changes and reload from disk":"Reload from disk","aria-label":"Reload from disk",children:e(C,{size:14,className:t.refreshing?"animate-spin":void 0})})});return r.push({id:"copy",actions:[{label:t.copyLabel,icon:oe,onSelect:t.onCopy},{label:"Download file",icon:he,onSelect:t.onDownload}],children:e(d,{children:[e("button",{type:"button",onClick:t.onCopy,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:t.copyLabel,"aria-label":t.copyLabel,children:t.copied?e(oe,{size:14,className:"text-success"}):e(oe,{size:14})}),e("button",{type:"button",onClick:t.onDownload,className:`${Zn} hover:bg-ink/5 hover:text-ink`,title:"Download file","aria-label":"Download file",children:e(he,{size:14})})]})}),r.push({id:"view-modes",pinned:!0,actions:t.viewModeActions,children:t.viewModeButtons}),r.push({id:"maximize",pinned:!0,actions:[{label:t.maximizeLabel,icon:t.isMaximized?we:xe,onSelect:t.onToggleMaximize,active:t.isMaximized}],children:t.maximizeButton}),r}function st({path:t,saveStatus:r,wordWrap:l,hasPreview:c,isPreview:p,hasReview:b,isReviewing:g,copied:h,byteViewer:x=!1,saveDisabled:v=!1,unsupported:w=!1,handleMissing:k=!1,readOnly:A=!1,isMaximized:E=!1,findOpen:M=!1,onToggleFind:H,onSave:K,onTogglePreview:W,onToggleReview:z,onToggleWordWrap:L,onZoomIn:_,onZoomOut:O,onCopy:G,onDownload:Z,onReload:N,canReload:R,refreshing:P=!1,reloadDiscardsEdits:Q,onSaveAs:X,onToggleMaximize:j}){let ne=v?A?"Read-only — this file was opened from the phone, not from a workspace":k?"Cannot save — reopen the file from the system to restore write access":w?"Nothing to save — this file cannot be opened as a document":"Nothing to save — this file could not be read":r==="needs-permission"?"Click Save to allow writing this file":r==="saving"?"Saving…":r==="error"?"Save failed — the file on disk was not changed":"Save file (Ctrl+S)",me=e("button",{type:"button",onClick:K,disabled:v||r==="saving",className:`${Zn} hover:bg-ink/5`,title:ne,"aria-label":ne,children:r==="saving"?e(yt,{size:14,className:"text-warning animate-pulse"}):r==="saved"?e(f,{size:14,className:"text-success"}):r==="error"?e(I,{size:14,className:"text-error"}):r==="needs-permission"?e(yt,{size:14,className:"text-warning"}):e(yt,{size:14,className:"hover:text-ink"})}),ee=E?"Exit full screen":"Full screen",te=e("button",{type:"button",onClick:j,className:`${Zn} hover:bg-ink/5 hover:text-ink ${E?"text-ink":""}`,title:ee,"aria-label":ee,"aria-pressed":E,children:E?e(we,{size:14}):e(xe,{size:14})}),ue=cd(),ae=ed(),se=at({byteViewer:x,hasPreview:c,isPreview:p,wordWrap:l,hasReview:b,isReviewing:g,blameInline:ue.inline,findOpen:M,copied:h,isMaximized:E,saveDisabled:v,canReload:R,refreshing:P,reloadDiscardsEdits:Q,saveButton:me,maximizeButton:te,viewModeButtons:e(td,{size:14}),viewModeActions:ae,previewLabel:p?"Show source":"Show preview",findLabel:"Find and replace",wordWrapLabel:l?"Word wrap on":"Word wrap off",copyLabel:h?"Copied":x?"Copy image":"Copy content",maximizeLabel:ee,onTogglePreview:W,onToggleReview:z,onToggleFind:H,onToggleWordWrap:L,onToggleBlameInline:()=>{let fe={...po(),inline:!ue.inline};Hr({editorBlameInline:fe.inline}),window.dispatchEvent(new CustomEvent(is,{detail:fe}))},onZoomIn:_,onZoomOut:O,onCopy:G,onDownload:Z,onReload:N,onSaveAs:X,onToggleMaximize:j,onSave:K});return e("div",{className:"@container flex items-center justify-between gap-2 px-3 py-2 border-b border-ink/10 bg-paper flex-shrink-0",children:[e("div",{className:"hidden @[420px]:flex items-center space-x-2 text-xs font-mono text-ink/40 min-w-0",children:e("span",{className:"truncate max-w-[300px]",title:t,children:t})}),e(fo,{clusters:se,className:"text-ink/40 ml-auto"})]})}function lt({content:t,file:r,zoomLevel:l,reviewActive:c,onExitReview:p,scrollRef:b,onScroll:g}){return e("div",{ref:b,onScroll:g,"data-testid":"editor-scroller",className:"flex-1 overflow-auto bg-paper flex",children:e("div",{className:"p-6 max-w-4xl mx-auto font-sans flex-1",style:{fontSize:`${l}px`},children:e(Bc,{content:t,file:r,active:c,onExit:p})})})}function wn(t,r){return r?`Spaces: ${t}`:"Tabs"}function dt({caret:t,eol:r,onSetEol:l,indentWidth:c,insertSpaces:p,language:b,byteViewer:g,viewerKind:h,lineCount:x,conflicts:v=0}){return e("footer",{className:"flex bg-canvas border-t border-ink/10 px-3 items-center justify-between text-[10px] text-ink/50 flex-shrink-0 font-mono h-6","data-editor-status-bar":"",children:[e("div",{className:"flex items-center gap-3 min-w-0",children:g?e("span",{className:"uppercase",children:Fi[h]}):e(d,{children:[e("span",{className:"tabular-nums",children:t?`Ln ${t.line}, Col ${t.column}`:"Ln —, Col —"}),e("span",{children:wn(c,p)}),e("button",{type:"button",onClick:()=>l(r==="lf"?"crlf":"lf"),className:"uppercase hover:text-ink transition-colors cursor-pointer",title:`Line endings: ${r.toUpperCase()} — click to switch`,"aria-label":`Line endings ${r.toUpperCase()}, switch`,children:r}),e("span",{children:[x," lines"]})]})}),e("div",{className:"flex items-center gap-3 min-w-0",children:[v>0&&e("span",{className:"text-error font-semibold tabular-nums",title:`${v} unresolved conflict${v===1?"":"s"} — markers are highlighted in the file`,children:["⚠ ",v," conflict",v===1?"":"s"]}),e("span",{className:"uppercase text-ink/40",children:b})]})]})}function kn(t){if(t===0)return 0;return Math.max(-1,Math.min(1,-Math.sign(t)))}function Sn(t,r,l=$s,c=zs){return Math.max(l,Math.min(c,t+r))}function Cn(t,r){let l=t instanceof HTMLElement?t:null;while(l&&l!==r){let c=getComputedStyle(l);if(/(auto|scroll)/.test(c.overflowY)&&l.scrollHeight>l.clientHeight)return!0;l=l.parentElement}return!1}function ct(t,r){i(()=>{if(!t)return;let l=t.closest("[data-code-surface]"),c=l instanceof HTMLElement?l:t,p=(b)=>{if(!b.ctrlKey&&!b.metaKey)return;if(b.preventDefault(),Cn(b.target,c))return;let g=kn(b.deltaY);if(g===0)return;r((h)=>Sn(h,g))};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[t,r])}function mt(t,r){let l=t.trim();if(!/^\d+$/.test(l))return null;let c=Number(l);if(c<1)return null;return Math.min(c,Math.max(r,1))}function ut({lineCount:t,onGo:r,onClose:l}){let[c,p]=n(""),b=o(null);i(()=>{b.current?.focus(),b.current?.select()},[]);let g=()=>{let v=mt(c,t);if(v===null)return;r(v)},h=(v)=>{if(v.key==="Enter"){v.preventDefault(),g();return}if(v.key==="Escape")v.preventDefault(),l()},x=mt(c,t);return e(J,{onClose:l,maxWidthClass:"max-w-xs",header:e("span",{className:"text-sm font-semibold text-ink",children:"Go to line"}),children:e("div",{className:"px-4 py-3 space-y-2",children:[e("div",{className:"flex items-center gap-2",children:[e("input",{ref:b,value:c,onInput:(v)=>p(v.target.value),onKeyDown:h,inputMode:"numeric",placeholder:"1","aria-label":"Line number",className:"flex-1 bg-paper border border-ink/20 rounded px-2 py-1 text-xs font-mono text-ink outline-none focus:border-ink/40"}),e("span",{className:"text-[10px] font-mono text-ink/40",children:["/ ",t]}),e("button",{type:"button",onClick:g,disabled:x===null,className:"flex items-center gap-1 px-2 py-1 rounded bg-ink text-paper text-xs disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[e(ft,{size:12}),"Go"]})]}),c&&x!==null&&String(x)!==c.trim()?e("div",{className:"text-[10px] text-ink/50 font-mono",children:["line ",x," (the last line)"]}):null,c&&x===null?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a line number"}):null]})})}var pt={status:"idle",payload:null,message:null};function bt(t){if(!t?.path)return"";return`${t.root??""}\x00${t.repo??""}\x00${t.path}`}function gt(t,r={}){let l=r.enabled!==!1&&Boolean(t?.path)&&t?.deviceFile!==!0,c=r.dirty===!0,p=bt(t),[b,g]=n({key:"",value:pt}),h=o(t);h.current=t;let x=o(p);x.current=p;let v=o(l);v.current=l;let w=o(c);w.current=c;let k=o(b);k.current=b;let A=o(0),E=o(""),M=o(new Map),H=o(new Set),K=a(async()=>{let O=h.current;if(!O?.path)return;let G=bt(O),Z=++A.current;E.current=G,g((R)=>({key:G,value:{status:"loading",payload:R.key===G?R.value.payload:null,message:null}}));let N=new URLSearchParams({blame:"1",file:O.path,repo:O.repo||"."});if(O.root)N.set("root",O.root);try{let R=await fetch(`/api/fs/git?${N.toString()}`),P=await R.json().catch(()=>null);if(Z!==A.current)return;if(!R.ok||!P){g({key:G,value:{status:"error",payload:null,message:P?.error??`Blame request failed (HTTP ${R.status})`}});return}g({key:G,value:P.available?{status:"ready",payload:P,message:null}:{status:"unavailable",payload:P,message:P.message??null}})}catch(R){if(Z!==A.current)return;g({key:G,value:{status:"error",payload:null,message:R instanceof Error?R.message:"Blame failed"}})}finally{if(E.current===G)E.current=""}},[]),W=a(async(O)=>{let G=M.current.get(O);if(G)return G;let Z=h.current;if(!Z?.path)return{entries:[],truncated:!1};let N=new URLSearchParams({blameHistory:"1",file:Z.path,line:String(O),repo:Z.repo||"."});if(Z.root)N.set("root",Z.root);try{let P=await(await fetch(`/api/fs/git?${N.toString()}`)).json().catch(()=>null),Q={entries:Array.isArray(P?.entries)?P.entries:[],truncated:P?.truncated===!0};return M.current.set(O,Q),Q}catch{return{entries:[],truncated:!1}}},[]),z=o(null);if(!z.current)z.current={ensure:()=>{if(!v.current||w.current)return;let O=k.current;if(O.key===x.current&&O.value.status!=="idle")return;if(E.current===x.current)return;K()},reload:()=>{M.current.clear(),K()},history:W,snapshot:()=>{let O=k.current;return O.key===x.current?O.value:pt},stale:()=>w.current,subscribe:(O)=>(H.current.add(O),()=>{H.current.delete(O)})};i(()=>{if(!l||c||!p)return;M.current.clear(),K()},[l,c,p,K]);let L=o(c);return i(()=>{if(L.current===c)return;L.current=c;for(let O of H.current)O()},[c]),i(()=>{for(let O of H.current)O()},[b]),z.current}var En="0".repeat(40);function Ee(t){return t===En}function ge(t,r=Date.now()){let l=Math.max(0,Math.floor(r/1000)-t);if(l<60)return"just now";let c=Math.floor(l/60);if(c<60)return`${c}m ago`;let p=Math.floor(c/60);if(p<24)return`${p}h ago`;let b=Math.floor(p/24);if(b<30)return`${b}d ago`;let g=Math.floor(b/30);if(g<12)return`${g}mo ago`;return`${Math.floor(b/365)}y ago`}function ht(t,r){switch(t){case"not-repo":return"This folder is not a git repository.";case"no-commit":return"This repository has no commits yet.";case"untracked":return"This file has never been committed, so it has no history.";case"too-large":return r??"This file is too large to blame.";case"empty":return"This file is empty.";default:return r??"git could not read this file."}}var St="fixed z-50 w-[min(340px,92vw)] rounded-xl border border-ink/20 bg-paper p-3 shadow-xl font-sans text-xs text-ink",vt="flex items-baseline justify-between gap-2",xt="truncate text-xs font-semibold text-ink",Tn="shrink-0 font-mono text-[10px] text-ink/40",Mn="mt-1 line-clamp-2 text-[11px] leading-snug text-ink/80",Nn="mt-2 border-t border-ink/10 pt-2",Rn="flex items-center gap-2 font-mono text-[10px] text-ink/40",kt="mt-1 text-[10px] leading-snug text-ink/50",Pn="mt-2 flex w-full items-center gap-1.5 text-left text-[10px] text-ink/50 hover:text-ink cursor-pointer",Ln="mt-1.5 space-y-1 border-t border-ink/10 pt-1.5",Te="flex items-center gap-1.5 font-mono text-[10px]";function q(t,r,l){let c=document.createElement(t);if(c.className=r,l!==void 0)c.textContent=l;return c}function Bn(t){return new Date(t*1000).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function Dn(t){let r=t.payload;if(t.status==="error")return{title:"Blame failed",body:t.message??"git could not read this file."};if(t.status==="unavailable")return{title:r?.reason==="untracked"?"Not tracked":"No history",body:ht(r?.reason??"error",t.message??void 0)};if(!r)return null;if(t.stale)return{title:"Not committed yet",body:"This line changed in the editor. Save the file to see its blame."};if(t.line>r.lines)return{title:"Not committed yet",body:`Line ${t.line} is past the end of the file at HEAD (${r.lines} lines).`};let l=r.runs.length>0?Ct(r,t.line):null;if(!l)return{title:"Not committed yet",body:`git has no attribution for line ${t.line}.`};if(Ee(l.sha))return{title:"Not committed yet",body:"This line differs from the last commit."};return null}function Ct(t,r){for(let l of t.runs)if(r>=l.from&&r<=l.to)return t.commits[l.sha]??null;return null}function On(t,r){t.replaceChildren(),t.className=St;let l=Dn(r);if(l){let v=q("div",vt);if(v.append(q("span",xt,l.title)),r.status==="error"&&r.message){let w=q("button","shrink-0 cursor-pointer text-[10px] text-ink/50 hover:text-ink","Try again");w.type="button",w.setAttribute("aria-label","Read the blame again"),v.append(w)}t.append(v,q("p",kt,l.body));return}let c=r.payload;if(!c){t.append(q("p",kt,"Reading blame…"));return}let p=Ct(c,r.line),b=q("div",vt);if(b.append(q("span",xt,p.author.trim()||"Unknown"),q("span",Tn,ge(p.time))),t.append(b),p.summary)t.append(q("p",Mn,p.summary));let g=q("div",`${Rn} ${Nn}`);if(g.append(q("code","truncate",p.sha.slice(0,7)),q("span","",Bn(p.time))),p.mail){let v=q("span","truncate",p.mail);v.title=p.mail,g.append(v)}t.append(g);let h=q("button",Pn);if(h.type="button",h.setAttribute("aria-expanded",r.historyOpen?"true":"false"),h.textContent=`${r.historyOpen?"▾":"▸"} Line history`,t.append(h),!r.historyOpen)return;let x=q("ol",Ln);if(r.historyLoading)x.append(q("li",`${Te} text-ink/40`,"Reading history…"));else if(!r.history||r.history.entries.length===0)x.append(q("li",`${Te} text-ink/40`,"No commits touched this line."));else{let v=r.history.entries;if(v.forEach((w,k)=>{let A=q("li",Te),E=k===v.length-1?"new":"edit";A.append(q("span","text-ink/40",k===0?"●":"○"),q("code","text-ink/60",w.sha.slice(0,7)),q("span","truncate text-ink/80",w.author.trim()||"Unknown"),q("span","ml-auto shrink-0 text-ink/40",ge(w.time)),q("span","shrink-0 rounded bg-ink/5 px-1 text-[8.5px] uppercase tracking-wider text-ink/45",E)),x.append(A)}),r.history.truncated)x.append(q("li",`${Te} text-ink/40`,"Older commits are not shown."))}t.append(x)}function Et(t,r,l){let c=q("div",St);c.setAttribute("role","dialog"),c.setAttribute("aria-label","Line blame"),c.addEventListener("mousedown",(w)=>w.stopPropagation());let p=null,b=!1,g=!1,h=()=>{let w=r.snapshot();return{line:t,status:w.status,payload:w.payload,message:w.message,stale:r.stale(),history:p,historyOpen:b,historyLoading:g}},x=()=>{On(c,h());let w=c.querySelector('[aria-label="Read the blame again"]');if(w)w.addEventListener("click",(k)=>{k.stopPropagation(),l()});c.querySelector("button[aria-expanded]")?.addEventListener("click",(k)=>{if(k.stopPropagation(),b=!b,x(),!b||p||g)return;g=!0,x(),r.history(t).then((A)=>{p=A,g=!1,x()})})};x();let v=r.subscribe(x);return{element:c,place(w){let k=c.ownerDocument.defaultView,A=k?.innerWidth??1024,E=k?.innerHeight??768,M=c.offsetWidth||340,H=c.offsetHeight||120,K=8,W=Math.max(8,Math.min(w.left,A-M-8)),z=w.bottom+6,L=w.top-H-6,_=z+H>E-8&&L>8?L:z;c.style.left=`${W}px`,c.style.top=`${Math.max(8,_)}px`},destroy(){v(),c.remove()}}}function Tt(t){return ye.define((r)=>{let l=null,c=0,p,b=()=>{clearTimeout(p),p=void 0,l?.destroy(),l=null,c=0},g=(E,M)=>{let H=E.getBoundingClientRect();if(H.width>0)return{left:H.left,top:H.top,bottom:H.bottom};let K=r.state.doc.line(Math.min(M,r.state.doc.lines)),W=null;try{W=r.coordsAtPos(K.from)}catch{W=null}if(W)return W;let z=r.scrollDOM.getBoundingClientRect();return{left:z.left,top:z.top+24,bottom:z.top+24}},h=(E,M)=>{if(c===E&&l)return;b(),c=E,l=Et(E,t,()=>{t.reload(),b()}),document.body.append(l.element),l.place(M)},x=(E)=>{let M=E.target,H=M?.closest?.(".cm-blame-label");if(H){let z=Number(H.dataset.blameLine);return Number.isInteger(z)&&z>0?{line:z,anchor:H}:null}let K=M?.closest?.(".cm-lineNumbers .cm-gutterElement");if(!K)return null;let W=Number((K.textContent??"").trim());return Number.isInteger(W)&&W>0?{line:W,anchor:K}:null},v=(E)=>{let M=x(E);if(!M)return;h(M.line,g(M.anchor,M.line))},w=(E)=>{let M=x(E);if(M){E.preventDefault(),h(M.line,g(M.anchor,M.line));return}if(l&&!l.element.contains(E.target))b()},k=(E)=>{if(E.key==="Escape"&&l)b(),E.stopPropagation()},A=(E)=>{if(!l)return;let M=E.relatedTarget;if(M&&(l.element.contains(M)||r.scrollDOM.contains(M)))return;p=setTimeout(b,200)};return r.scrollDOM.addEventListener("mouseover",v),r.scrollDOM.addEventListener("mouseleave",A),r.scrollDOM.addEventListener("mousedown",w),document.addEventListener("mousedown",w),document.addEventListener("keydown",k,!0),{update(E){if(E.docChanged&&l)b()},destroy(){b(),r.scrollDOM.removeEventListener("mouseover",v),r.scrollDOM.removeEventListener("mouseleave",A),r.scrollDOM.removeEventListener("mousedown",w),document.removeEventListener("mousedown",w),document.removeEventListener("keydown",k,!0)}}})}var Mt=40,Rt=re.define();function An(t){return Qe.define({create:()=>({payload:t.snapshot().payload,stale:!1}),update(r,l){let c=r;for(let p of l.effects){if(!p.is(Rt))continue;c=p.value.payload!==r.payload?{payload:p.value.payload,stale:!1}:{payload:r.payload,stale:r.stale}}if(l.docChanged&&!c.stale)c={payload:c.payload,stale:!0};return c}})}function In(t,r,l){let c=t.commits[r];if(!c||Ee(r))return null;let p=c.author.trim()||"Unknown";return l?p:`${p} · ${ge(c.time)}`}class Pt extends jt{constructor(t,r,l){super();this.line=t;this.text=r;this.title=l}eq(t){return t.line===this.line&&t.text===this.text&&t.title===this.title}toDOM(){let t=document.createElement("span");return t.className="cm-blame-label",t.dataset.blameLine=String(this.line),t.title=this.title,t.textContent=this.text,t}}function Nt(t,r,l){let{payload:c,stale:p}=t;if(!c?.available||p)return T.none;let b=Math.min(c.lines,r.state.doc.lines);if(b<1)return T.none;let g=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.from,r.state.doc.length))).number,h=r.state.doc.lineAt(Math.max(0,Math.min(r.viewport.to,r.state.doc.length))).number,x=Math.max(1,g-Mt),v=Math.min(b,h+Mt),w=[];for(let k of c.runs){let A=Math.max(k.from,x);if(A>k.to||A>v)continue;let E=In(c,k.sha,l);if(!E)continue;let M=c.commits[k.sha],H=r.state.doc.line(A);w.push({from:H.to,deco:T.widget({widget:new Pt(H.number,E,M.summary||M.sha),side:1})})}return T.set(w.map((k)=>k.deco.range(k.from)),!0)}function Fn(t,r){return ye.fromClass(class{constructor(l){this.view=l;this.decorations=Nt(l.state.field(t),l,r)}update(l){if(l.startState.field(t)===l.state.field(t)&&!l.docChanged&&!l.viewportChanged)return;this.decorations=Nt(l.state.field(t),l.view,r)}},{decorations:(l)=>l.decorations})}function zn(t){return ye.define((r)=>{let l=!0,c=()=>{if(!l)return;let b=t.snapshot();r.dispatch({effects:Rt.of({payload:b.payload,stale:!1})})},p=t.subscribe(c);return{destroy(){l=!1,p()}}})}function Lt({controller:t,inline:r=!0,compact:l=!1}){let c=An(t);return[c,zn(t),r?Fn(c,l):[],Tt(t)]}function Bt({activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:p,rootPath:b=null,repoPath:g=null,onRunCommand:h,wordWrap:x,zoomLevel:v,setZoomLevel:w,editorFontFamily:k,editorTheme:A,viewerKind:E,isPreview:M,reviewActive:H,onToggleReview:K,revealActive:W}){let z=E==="markdown",L=jc(),_=Hc(),O=cd(),G=gt({name:t.name,path:t.path,root:t.root??b??void 0,repo:t.repo??g??"."},{enabled:O.enabled,dirty:r.isDirty}),Z=u(()=>O.enabled?Lt({controller:G,inline:O.inline}):null,[O.enabled,O.inline,G]),[N,R]=n(null),P=u(()=>Ic(r.content),[r.content]),[Q,X]=n(!1);i(()=>{if(p>0)X(!0)},[p]);let[j,ne]=n(null),[me,ee]=n(null);ct(j,w);let te=Vs({tabKey:String(t.id),surface:z&&M?"rendered":"code",ready:r.loaded,element:z&&M?void 0:j}),ue=a((ae)=>{te.ref(ae),ee(ae)},[te.ref]);return Tc({path:t.path,scroller:me,preview:z&&M}),e("div",{className:"relative flex-1 min-h-0 flex flex-col",children:[l.open?e(Sc,{find:l}):null,Q?e(ut,{lineCount:r.content?r.content.split(`
|
|
2
|
+
`).length:1,onGo:(ae)=>{X(!1);let se=dr(r.content,ae-1);c.current?.select(se,se,!0),c.current?.revealOffset(se)},onClose:()=>X(!1)}):null,z&&M?e(lt,{content:r.content,file:{name:t.name,path:t.path,root:t.root,repo:t.repo},zoomLevel:v,reviewActive:H,onExitReview:K,scrollRef:ue,onScroll:te.onScroll}):e(_c,{ref:c,value:r.content,onValueChange:r.onChange,language:r.language,wordWrap:x,documentKey:String(t.id),marks:l.open||W?l.matches:void 0,currentMark:l.currentIndex,onCommand:h,onScroller:ne,onCaret:R,scrollTestId:"editor-scroller",className:"flex-1 min-h-0 text-ink select-text",blame:Z,themeVars:A.vars,themes:A.themes,indentUnitText:Gc(L),typing:_,padding:16,placeholder:"This file is empty",style:{fontFamily:k,fontSize:`${v}px`,lineHeight:Os}}),!z||!M?e(dt,{caret:N,eol:r.eol,onSetEol:r.setEol,indentWidth:L.width,insertSpaces:L.insertSpaces,language:r.language,byteViewer:r.isBinaryViewer,viewerKind:E,lineCount:r.content?r.content.split(`
|
|
3
|
+
`).length:0,conflicts:P}):null]})}function Dt({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W=null,repoPath:z=null,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N}){let R=h==="image"||h==="pdf"||h==="docx"||h==="spreadsheet",P=ns[h]===!0,Q=a(async(X)=>{let j=await Rc(t,X,{interactive:!0,baseMtimeMs:r.baseMtimeMs});if(j.status==="written")return{ok:!0};if(j.status==="conflict")return{ok:!1,error:"This file changed on disk since it was opened."};if(j.status==="needs-permission")return{ok:!1,error:"Click Save again to grant write access."};return{ok:!1,error:j.error}},[t,r.baseMtimeMs]);return e(d,{children:[e(st,{path:t.path,saveStatus:r.saveStatus,wordWrap:b,hasPreview:P,isPreview:x,hasReview:h==="markdown"&&x,isReviewing:v,copied:r.copied,byteViewer:R,saveDisabled:Boolean(r.loadError)||r.handleMissing||r.deviceBacked,unsupported:Boolean(r.unsupported),handleMissing:r.handleMissing,readOnly:r.deviceBacked,isMaximized:k,findOpen:l.open,onToggleFind:()=>l.open?l.close():l.openFind(),onSave:r.saveNow,onTogglePreview:G,onToggleReview:w,onToggleWordWrap:()=>g(!b),onZoomIn:()=>M((X)=>Math.min(zs,X+1)),onZoomOut:()=>M((X)=>Math.max($s,X-1)),onCopy:r.copy,onDownload:r.download,onReload:r.reloadFromDisk,onSaveAs:K,canReload:al(t)&&!r.loadError&&!r.unsupported,refreshing:r.isReading,reloadDiscardsEdits:r.isDirty,onToggleMaximize:()=>A(!k)}),N&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-error/30 bg-error/10 text-error",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was deleted from disk."}),e("div",{className:"text-[11px] font-sans text-error/80",children:"The buffer is still here. Saving recreates the file — autosave is off until then."})]})]}),r.conflict&&e(Ce,{diskMtimeMs:r.conflict.diskMtimeMs,fileName:t.name,onReload:r.resolveConflictByReload,onKeepMine:r.resolveConflictByKeepingMine}),r.handleMissing&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-warning/30 bg-warning/10 text-warning",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:"This file was opened by the system, not from a workspace."}),e("div",{className:"text-[11px] font-sans text-warning/80",children:"Its write permission ended with the last page load. Reopen the file from the OS to edit it again."})]})]}),r.deviceBacked&&e("div",{className:"flex items-start gap-2 px-3 py-2 border-b border-ink/20 bg-ink/5 text-ink/70",children:[e(D,{size:14,className:"shrink-0 mt-0.5"}),e("div",{className:"min-w-0",children:[e("div",{className:"text-[11.5px] font-sans",children:r.deviceMissing?"The bytes for this file did not survive the reload.":"Opened from this device, so it is read-only here."}),e("div",{className:"text-[11px] font-sans text-ink/50",children:r.deviceMissing?"A phone's file lives only on the phone, so it cannot be re-read. Open it again from the app that shared it.":"The console cannot reach a file on your phone. Copy it into a workspace to edit it."})]})]}),r.isImage&&r.imageUrl?e(Ri,{src:r.imageUrl,name:t.name,className:"flex-1 min-h-0"}):r.isImage?e(rl,{kind:"image",path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision}):r.isLoading?e("div",{className:"flex-1 flex items-center justify-center gap-2 text-ink/40 text-xs font-mono",children:[e(m,{size:14,className:"animate-spin"}),e("span",{children:"Loading file content…"})]}):r.unsupported?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(Cc,{size:20,className:"text-ink/40"}),e("span",{className:"text-xs text-ink/70 font-sans",children:[t.name," cannot be opened here"]}),e("span",{className:"text-[11px] text-ink/50 font-sans max-w-[42ch]",children:r.unsupported})]}):r.loadError?e("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 px-6 text-center",children:[e(D,{size:20,className:"text-error"}),e("span",{className:"text-xs text-error font-sans",children:["Could not read ",t.name]}),e("span",{className:"text-[11px] text-ink/50 font-mono break-all",children:r.loadError})]}):p&&!r.isImage?e(nA,{view:p}):Qc(h)&&(R||x)?e(rl,{kind:h,path:t.path,name:t.name,source:r.byteSource,content:r.content,revision:r.revision,onContentChange:r.onChange,onSaveBytes:r.deviceBacked?void 0:Q,onDirtyChange:r.setBinaryDirty}):e(Bt,{activeFile:t,editor:r,find:l,surfaceRef:c,goToLineRequest:H,rootPath:W,repoPath:z,onRunCommand:L,wordWrap:b,zoomLevel:E,setZoomLevel:M,editorFontFamily:_,editorTheme:O,isPreview:x,reviewActive:v,onToggleReview:w,viewerKind:h,revealActive:Z})]})}function Ot({activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W=null,repoPath:z=null,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N,onConvertDiffToEditor:R,onFileSaved:P}){if(!t)return e("div",{className:"flex-1 flex items-center justify-center text-ink/40",children:e("p",{className:"font-mono text-sm",children:"Select a tab to view content"})});if(t.isDiff)return e(Ec,{filePath:t.path,status:t.diffStatus||"M",isStaged:Boolean(t.diffStaged),root:t.root,repo:t.repo||".",journalDiff:t.journalDiff,readOnly:t.diffSource==="journal",onOpenInEditor:()=>R(t.id),onFileSaved:P,className:"flex-1",tabKey:String(t.id)});return e(Dt,{activeFile:t,editor:r,find:l,surfaceRef:c,pluginFileView:p,wordWrap:b,setWordWrap:g,viewerKind:h,isPreview:x,isReviewing:v,onToggleReview:w,isMaximized:k,setIsMaximized:A,zoomLevel:E,setZoomLevel:M,goToLineRequest:H,onSaveAs:K,rootPath:W,repoPath:z,runCommand:L,editorFontFamily:_,editorTheme:O,togglePreview:G,revealActive:Z,missing:N})}function At({pluginId:t,Component:r,sessionId:l,className:c=""}){return e("div",{className:`flex flex-col h-full bg-canvas ${c}`,children:e(Ke,{pluginId:t,children:e(r,{sessionId:l,workspacePath:null})})})}function It({className:t=""}){return e("div",{className:`flex flex-col h-full bg-canvas items-center justify-center text-muted ${t}`,children:[e(rt,{name:"placeholder.txt",size:48,className:"mb-4 opacity-20"}),e("p",{className:"font-mono text-sm",children:"Select a file to open"})]})}function Ft({searchReveal:t,revealMatch:r}){let l=o(r);l.current=r;let c=o(null);i(()=>{if(!t||c.current===t.request)return;c.current=t.request,l.current({query:t.request.query,options:t.request.options,line:t.request.line})},[t])}function zt({openedFiles:t,dirtyKeys:r,activeFile:l,previewReady:c,setPreviewMode:p,sessionId:b}){i(()=>{let g=new Set(t.filter((h)=>!h.isDiff&&h.content===void 0).map((h)=>h.id));ze([...r].filter((h)=>g.has(h)))},[r,t]),i(()=>{if(!c)return;let g=l?.id;if(!l||g===void 0||g===null)return;if(!ns[rs(l.name)])return;let h=$e(b,"editor.previewMode");if(h&&h[g]!==void 0)return;p((x)=>x[g]===void 0?{...x,[g]:!0}:x)},[c,l])}function Ht({activeFile:t,externalChange:r,conflict:l,onReload:c,onKeepMine:p}){if(!t)return null;if(l)return e(Ce,{diskMtimeMs:l.diskMtimeMs,fileName:t.name,onReload:c,onKeepMine:p});if(r)return e(Oc,{fileName:t.name,onReload:c,onKeepMine:p});return null}async function $t(t){let r=t.name.trim();if(!r)return{status:"failed",reason:"Enter a file name."};let l=new FormData;if(l.append("actionType","saveAs"),l.append("path",t.parent),l.append("name",r),l.append("content",t.content),l.append("eol",t.eol),t.root)l.append("root",t.root);if(t.repo&&t.repo!==".")l.append("repo",t.repo);try{let c=await fetch("/api/fs/action",{method:"POST",body:l}),p=await c.json().catch(()=>null),b=typeof p?.error==="string"?p.error:null;if(c.status===409)return{status:"exists",reason:b??`${r} already exists.`};if(c.ok&&p?.success&&typeof p.path==="string")return{status:"written",path:p.path};return{status:"failed",reason:b??"The file could not be written."}}catch{return{status:"failed",reason:"The file could not be written."}}}function Vt(t){let r=t.lastIndexOf(".");if(r<=0)return`${t} copy`;return`${t.slice(0,r)} copy${t.slice(r)}`}function Wt(t){let r=t.trim();if(!r)return!1;if(r==="."||r==="..")return!1;return!r.includes("/")&&!r.includes("\\")}function Hn(t){let r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function Ut({fileName:t,filePath:r,content:l,eol:c,root:p,repo:b,onSaved:g,onClose:h}){let[x,v]=n(()=>Hn(r)),[w,k]=n(()=>Vt(t)),[A,E]=n(!1),[M,H]=n(null),K=o(null);i(()=>{K.current?.focus(),K.current?.select()},[]);let W=Wt(w),z=async()=>{if(!W||A)return;E(!0),H(null);let _=await $t({parent:x,name:w,content:l,eol:c,root:p,repo:b});if(E(!1),_.status==="written"){g({path:_.path});return}H(_.reason)},L=(_)=>{if(_.key==="Enter"){_.preventDefault(),z();return}if(_.key==="Escape")_.preventDefault(),h()};return e(J,{onClose:h,maxWidthClass:"max-w-md",header:e("span",{className:"text-sm font-semibold text-ink",children:"Save as"}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:h,className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>void z(),disabled:!W||A,className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-ink text-paper disabled:opacity-40 disabled:cursor-default cursor-pointer",children:[A?e(m,{size:12,className:"animate-spin"}):e(ft,{size:12}),"Save"]})]}),children:e("div",{className:"px-4 py-3 space-y-2 text-xs",children:[e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Folder"}),e("input",{value:x,onInput:(_)=>v(_.target.value),onKeyDown:L,placeholder:"(workspace root)","aria-label":"Destination folder",className:"w-full bg-paper border border-ink/20 rounded px-2 py-1 font-mono text-ink outline-none focus:border-ink/40"})]}),e("label",{className:"block",children:[e("span",{className:"block text-[10px] uppercase tracking-wide text-ink/50 mb-1",children:"Name"}),e("input",{ref:K,value:w,onInput:(_)=>k(_.target.value),onKeyDown:L,"aria-label":"File name","aria-invalid":!W,className:`w-full bg-paper border rounded px-2 py-1 font-mono text-ink outline-none ${W?"border-ink/20 focus:border-ink/40":"border-error text-error"}`})]}),!W?e("div",{className:"text-[10px] text-error font-mono",children:"Enter a file name without a path separator"}):null,M?e("div",{className:"text-[10px] text-error font-mono",children:M}):null,e("div",{className:"text-[10px] text-ink/40",children:"The original file stays where it is, and its tab stays open."})]})})}function _t(){i(()=>{let t=(r)=>{if(!Ue())return;r.preventDefault(),r.returnValue=""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[])}function Gt({fileName:t,onAnswer:r}){return e(J,{onClose:()=>r("cancel"),header:e("div",{className:"flex items-center gap-2",children:[e(D,{size:15,className:"text-warning"}),e("span",{className:"text-sm font-semibold text-ink",children:"Unsaved changes"})]}),footer:e("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-ink/10",children:[e("button",{type:"button",onClick:()=>r("cancel"),className:"px-3 py-1.5 rounded border border-ink/20 text-ink/80 hover:bg-ink/5 transition-colors cursor-pointer",children:"Cancel"}),e("button",{type:"button",onClick:()=>r("discard"),className:"px-3 py-1.5 rounded border border-error/40 text-error hover:bg-error/10 transition-colors cursor-pointer",children:"Discard"}),e("button",{type:"button",onClick:()=>r("save"),className:"px-3 py-1.5 rounded bg-ink text-paper hover:bg-ink/90 transition-colors cursor-pointer",children:"Save & close"})]}),children:e("div",{className:"px-4 py-3 text-xs text-ink/80",children:[e("span",{className:"font-mono text-ink",children:t})," has changes that are not on disk.",e("div",{className:"mt-1 text-ink/50",children:"Discarding them cannot be undone."})]})})}function qt({closeGuard:t,activeFile:r,saveMissingConfirm:l,onCancelSaveMissing:c,onConfirmSaveMissing:p}){if(t.pending)return e(Gt,{fileName:t.pending.name,onAnswer:t.answer});if(l&&r)return e($c,{fileName:r.name,filePath:r.path,onClose:c,onConfirm:p});return null}function Zt({className:t="",isMaximized:r,onKeyDownCapture:l,onFocusCapture:c,asSplitPane:p,tabs:b,activeFile:g,editor:h,externalChange:x,conflict:v,onReload:w,onKeepMine:k,body:A,saveAsOpen:E,onSaveAsClose:M,onSavedAs:H,closeGuard:K}){let W=r?"fixed inset-0 z-50 flex flex-col bg-canvas":`flex flex-col h-full bg-canvas ${t}`;return e("div",{className:W,onKeyDownCapture:l,onFocusCapture:c,children:[p?null:b,e(Ht,{activeFile:g,externalChange:x,conflict:v,onReload:w,onKeepMine:k}),A,E&&g?e(Ut,{fileName:g.name,filePath:g.path,content:h.content,eol:h.eol,root:g.root,repo:g.repo,onSaved:({path:z})=>H(z),onClose:M}):null,e(qt,{closeGuard:K,activeFile:g,saveMissingConfirm:h.saveMissingConfirm,onCancelSaveMissing:h.cancelSaveMissing,onConfirmSaveMissing:h.confirmSaveMissing})]})}function Xt({fileName:t,onClose:r,children:l}){return e("div",{className:"flex flex-col h-full min-w-0","data-split-pane":"",children:[e("div",{className:"flex items-center justify-between gap-2 px-3 py-1 border-b border-ink/10 bg-canvas flex-shrink-0",children:[e("span",{className:"text-[11px] font-mono text-ink/60 truncate",title:t,children:t}),e("button",{type:"button",onClick:r,className:"p-0.5 rounded hover:bg-ink/10 text-ink/50 hover:text-ink transition-colors cursor-pointer flex-shrink-0",title:"Close this pane (the tab stays open)","aria-label":"Close split pane",children:e(y,{size:12})})]}),e("div",{className:"flex-1 min-h-0",children:l})]})}function Yt({fraction:t,onFraction:r,rightPaneName:l,onClosePane:c,rightPane:p,children:b}){let g=o(null),h=(x)=>{let v=x.currentTarget,w=g.current;if(!v||!w)return;v.setPointerCapture(x.pointerId);let k=(E)=>{let M=w.getBoundingClientRect();if(M.width===0)return;r(pe((E.clientX-M.left)/M.width))},A=()=>{v.releasePointerCapture(x.pointerId),v.removeEventListener("pointermove",k),v.removeEventListener("pointerup",A)};v.addEventListener("pointermove",k),v.addEventListener("pointerup",A)};return e("div",{ref:g,className:"flex w-full h-full","data-split-column":"",children:[e("div",{className:"flex flex-col min-w-0 h-full",style:{width:`${Math.round(pe(t)*100)}%`},children:b}),e("div",{className:"w-[3px] flex-shrink-0 cursor-col-resize bg-ink/10 hover:bg-ink/40 transition-colors",role:"separator","aria-orientation":"vertical","aria-label":"Resize split panes",onPointerDown:h}),e("div",{className:"flex-1 min-w-0 h-full",children:e(Xt,{fileName:l,onClose:c,children:p})})]})}function Jt({openedFiles:t,activeFileId:r,enabled:l}){let[c,p]=S("editor.split",be),b=t.map((k)=>k.id),g=Ye(je(c,b),r),h=l&&g.rightFileId!==null?t.find((k)=>k.id===g.rightFileId)??null:null,x=a((k)=>{if(k!==null&&!Se(k,r,b))return;p({...g,rightFileId:k})},[g,p,r,b]),v=a(()=>p({...g,rightFileId:null}),[g,p]),w=a((k)=>p({...g,fraction:pe(k)}),[g,p]);return{rightFile:h,fraction:g.fraction,splitTo:x,close:v,setFraction:w}}function Qt({find:t,runCommand:r,reopenClosed:l}){let c=o(t);c.current=t;let p=o(r);p.current=r;let b=o(l);return b.current=l,{onKeyDownCapture:a((h)=>{let x=c.current;if(h.key==="Escape"){if(!x.open)return;h.preventDefault(),h.stopPropagation(),x.close();return}if((h.metaKey||h.ctrlKey)&&h.shiftKey&&h.code==="KeyT"){if(b.current?.())h.preventDefault(),h.stopPropagation();return}let v=Cg(lo,h);if(!v||!Gm(v))return;h.preventDefault(),h.stopPropagation(),p.current(v)},[])}}function tn(t){let r=o(t);r.current=t;let l=o(null);if(!l.current)l.current={saveNow:()=>r.current.saveNow(),runCommand:(p)=>r.current.runCommand(p)};return i(()=>{let p=l.current;if(!p)return;return Yf(p)},[]),{onFocusCapture:a(()=>{if(l.current)Yf(l.current)},[])}}function nn({openedFiles:t,activeFileId:r,onSelectFile:l,onCloseFile:c,saveNow:p}){let[b,g]=n(null);_t();let h=a((v)=>{let w=t.find((k)=>k.id===v);if(w&&We(v)){g(w);return}c(v)},[t,c]),x=a((v)=>{let w=b;if(!w)return;if(v==="cancel"){g(null);return}if(v==="save"){if(w.id!==r)l(w.id);p()}g(null),c(w.id)},[b,r,l,p,c]);return{requestClose:h,pending:b,answer:x}}function on(){let[t,r]=n(0),[l,c]=n(!1),p=a(()=>r((b)=>b+1),[]);return{goToLineRequest:t,openGoToLine:p,saveAsOpen:l,setSaveAsOpen:c}}function $n({className:t="",openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:b,refreshKey:g=0,onFileSaved:h,onOpenPath:x,onReopenClosed:v,reopenableCount:w,onCopyPath:k,onRevealInFiles:A,rootPath:E=null,repoPath:M=null,activeEditorPanelKey:H=null,forcedActiveFileId:K=null,asSplitPane:W=!1}){let z=W?K:l,L=r.find((U)=>U.id===z),[_,O,G]=S("editor.previewMode",{}),Z=zc(String(z??"")),[N,R]=S("editor.zoomLevel",yi),[P,Q]=n(!1),[X,j]=S("editor.wordWrap",!0),ne=on(),{sessionId:me}=Ze(),ee=Jt({openedFiles:r,activeFileId:z,enabled:!W}),te=o(null),ue=wi(),ae=uo(),se=Nc(r,g),fe=Boolean(L&&se.has(L.id)),Y=Fc(L??null,{reportSaveError:!0,onFileSaved:h,missing:fe}),rn=tA({path:L?.path??"",content:Y.content,language:Y.language}),an=Y.diskChange,Be=nn({openedFiles:r,activeFileId:z,onSelectFile:c,onCloseFile:p,saveNow:Y.saveNow}),ve=Lc({text:Y.content,documentKey:`${L?.id??""}\x00${Y.language}`,readSelection:()=>te.current?.getSelection()??null,select:(U,ce,Re=!0)=>te.current?.select(U,ce,Re),reveal:(U)=>te.current?.revealOffset(U),applyDocument:(U,ce,Re)=>te.current?.applyDocument(U,ce,Re),toggleWordWrap:()=>j((U)=>!U)}),De=Mc(L?.path??null,Y.content,Y.loaded&&!Y.loadError);Ft({searchReveal:De,revealMatch:ve.revealMatch}),Pc({file:L,editor:Y,surfaceRef:te,isPreview:L?_[L.id]===!0:!1,exitPreview:()=>{let U=L?.id;if(U===void 0||U===null)return;O((ce)=>({...ce,[U]:!1}))}}),i(()=>{if(g>0)Y.reset()},[g]),i(()=>{Y.retain(r.map((U)=>U.id)),Ve(r.map((U)=>U.id))},[r]),zt({openedFiles:r,dirtyKeys:Y.dirtyKeys,activeFile:L,previewReady:G,setPreviewMode:O,sessionId:me});let sn=()=>{if(!L)return;O((U)=>({...U,[L.id]:!U[L.id]}))},Me=(U)=>{if(Gm(U)){ve.runCommand(U);return}if(U==="toggleWordWrap"){j((ce)=>!ce);return}if(U==="goToLine"){ne.openGoToLine();return}te.current?.runCommand(U)},ln=Qt({find:ve,runCommand:Me,reopenClosed:v}),dn=tn({saveNow:Y.saveNow,runCommand:Me}),Ne=Mg(H);if(Ne)return e(At,{pluginId:Ne.pluginId,Component:Ne.Component,sessionId:me,className:t});if(r.length===0)return e(It,{className:t});let cn=Y.viewerKind,Oe=L?_[L.id]:!1,mn={activeFile:L,editor:Y,find:ve,surfaceRef:te,pluginFileView:rn,wordWrap:X,setWordWrap:j,viewerKind:cn,isPreview:Boolean(Oe),isReviewing:Boolean(Oe)&&Z.active,onToggleReview:Z.toggle,isMaximized:P,setIsMaximized:Q,zoomLevel:N,setZoomLevel:R,goToLineRequest:ne.goToLineRequest,onSaveAs:()=>ne.setSaveAsOpen(!0),onOpenPath:x,rootPath:E,repoPath:M,runCommand:Me,editorFontFamily:ue,editorTheme:ae,togglePreview:sn,revealActive:Boolean(De),missing:fe,onConvertDiffToEditor:b,onFileSaved:h},un=(U)=>({openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:p,onConvertDiffToEditor:b,refreshKey:g,onFileSaved:h,onOpenPath:x,rootPath:E,repoPath:M,forcedActiveFileId:U,asSplitPane:!0}),pn=e(tt,{openedFiles:r,activeFileId:l,onSelectFile:c,onCloseFile:Be.requestClose,missingIds:se,onCopyPath:k,onRevealInFiles:A,onReopenClosed:v,reopenableCount:w,onSplitTo:ee.splitTo,onUnsplit:ee.close,splitRightFileId:ee.rightFile?.id??null}),Ae=e(Zt,{className:t,isMaximized:P,onKeyDownCapture:ln.onKeyDownCapture,onFocusCapture:dn.onFocusCapture,asSplitPane:W,tabs:pn,activeFile:L,editor:Y,externalChange:an,conflict:Y.conflict,onReload:Y.resolveConflictByReload,onKeepMine:Y.keepMineAgainstDisk,body:e(Ot,{...mn}),saveAsOpen:ne.saveAsOpen,onSaveAsClose:()=>ne.setSaveAsOpen(!1),onSavedAs:(U)=>{ne.setSaveAsOpen(!1),x?.(U)},closeGuard:Be});if(!ee.rightFile)return Ae;return e(Yt,{fraction:ee.fraction,onFraction:ee.setFraction,rightPaneName:ee.rightFile.name,onClosePane:ee.close,rightPane:e($n,{...un(ee.rightFile.id)}),children:Ae})}export{$n as Editor};
|