phirepass-widgets 0.0.114 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/phirepass-downloader_3.cjs.entry.js +133 -38
  3. package/dist/cjs/phirepass-rdp.cjs.entry.js +1 -1
  4. package/dist/cjs/phirepass-terminal.cjs.entry.js +2 -2
  5. package/dist/cjs/phirepass-widgets.cjs.js +1 -1
  6. package/dist/collection/components/phirepass-downloader/jobs.js +22 -2
  7. package/dist/collection/components/phirepass-downloader/views/icons.js +1 -0
  8. package/dist/collection/components/phirepass-media-player/phirepass-media-player.css +9 -0
  9. package/dist/collection/components/phirepass-media-player/phirepass-media-player.js +79 -3
  10. package/dist/collection/components/phirepass-media-player/player.js +24 -0
  11. package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +1 -1
  12. package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +33 -33
  13. package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +2 -2
  14. package/dist/components/p-DIf-Ru26.js +1 -0
  15. package/dist/components/p-DqT-qhTU.js +1 -0
  16. package/dist/components/phirepass-downloader.js +1 -1
  17. package/dist/components/phirepass-media-player.js +1 -1
  18. package/dist/components/phirepass-rdp.js +1 -1
  19. package/dist/components/phirepass-sftp-client.js +1 -1
  20. package/dist/components/phirepass-terminal.js +1 -1
  21. package/dist/esm/loader.js +1 -1
  22. package/dist/esm/phirepass-downloader_3.entry.js +133 -38
  23. package/dist/esm/phirepass-rdp.entry.js +1 -1
  24. package/dist/esm/phirepass-terminal.entry.js +2 -2
  25. package/dist/esm/phirepass-widgets.js +1 -1
  26. package/dist/phirepass-widgets/{p-a4a5e5f5.entry.js → p-2fd32ec5.entry.js} +1 -1
  27. package/dist/phirepass-widgets/{p-a5ce104d.entry.js → p-705501d4.entry.js} +1 -1
  28. package/dist/phirepass-widgets/p-b8caf9e1.entry.js +1 -0
  29. package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
  30. package/dist/types/components/phirepass-downloader/jobs.d.ts +7 -0
  31. package/dist/types/components/phirepass-media-player/phirepass-media-player.d.ts +16 -1
  32. package/dist/types/components/phirepass-media-player/player.d.ts +10 -0
  33. package/dist/types/components.d.ts +10 -2
  34. package/package.json +4 -4
  35. package/dist/components/p-C4cmk3bS.js +0 -1
  36. package/dist/components/p-CKnb-oeB.js +0 -1
  37. package/dist/phirepass-widgets/p-97d84225.entry.js +0 -1
@@ -1 +0,0 @@
1
- import{h as t,t as a,p as e,H as s,c as i,a as n}from"./index.js";const r=["B","KB","MB","GB","TB"];function o(t){if(null==t||!Number.isFinite(t)||t<0)return"—";let a=t,e=0;for(;a>=1e3&&e<r.length-1;)a/=1e3,e++;if(0===e)return`${Math.round(a)} B`;const s=a>=100?0:a>=10?1:e>=3?2:1,i=a.toFixed(s);return`${s?i.replace(/\.?0+$/,""):i} ${r[e]}`}function h(t,a="↓"){return!t||t<=0?"":`${a} ${o(t)}/s`}function d(t){const a=Math.max(0,Math.round(t));if(a<60)return`${a}s`;const e=Math.floor(a/60);if(e<10){const t=a%60;return t?`${e}m ${t}s`:`${e}m`}if(e<60)return`${e}m`;const s=Math.floor(e/60),i=e%60;return s<24?i?`${s}h ${i}m`:`${s}h`:`${Math.floor(s/24)}d ${s%24}h`}function l(t,a,e){return!a||!e||e<=0||t>=a?"":`${d((a-t)/e)} left`}function c(t,a){if(!a||a<=0)return"";const e=Math.min(100,t/a*100);return e>=100?"100%":`${e.toFixed(1)}%`}function p(t,a){return!a||a<=0?0:Math.max(0,Math.min(100,t/a*100))}function u(t){if(!Number.isFinite(t)||t<0)return"0:00";const a=Math.floor(t),e=Math.floor(a/3600),s=Math.floor(a%3600/60),i=String(a%60).padStart(2,"0");return e?`${e}:${String(s).padStart(2,"0")}:${i}`:`${s}:${i}`}const g={fetch:()=>[t("path",{d:"M17.5 19a4.5 4.5 0 1 0-1.4-8.8A6 6 0 0 0 4.3 12.7 4 4 0 0 0 6 19.9"}),t("path",{d:"M12 12v8"}),t("path",{d:"m8.5 16.5 3.5 3.5 3.5-3.5"})],magnet:()=>[t("path",{d:"M6 3v8a6 6 0 0 0 12 0V3"}),t("path",{d:"M6 7h4M14 7h4"}),t("path",{d:"M10 3v8a2 2 0 0 0 4 0V3"})],globe:()=>[t("circle",{cx:"12",cy:"12",r:"9"}),t("path",{d:"M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"})],torrent:()=>[t("path",{d:"M6 3h8l4 4v14H6z"}),t("path",{d:"M14 3v4h4"}),t("path",{d:"M9.5 11.5 12 14l2.5-2.5M12 14v3"})],node:()=>[t("rect",{x:"3",y:"4",width:"18",height:"7",rx:"1.5"}),t("rect",{x:"3",y:"13",width:"18",height:"7",rx:"1.5"}),t("path",{d:"M7 7.5h.01M7 16.5h.01"})],x:()=>[t("path",{d:"M6 6l12 12M18 6 6 18"})],retry:()=>[t("path",{d:"M3 12a9 9 0 0 0 15.4 6.4L21 16"}),t("path",{d:"M21 21v-5h-5"}),t("path",{d:"M21 12A9 9 0 0 0 5.6 5.6L3 8"}),t("path",{d:"M3 3v5h5"})],check:()=>[t("circle",{cx:"12",cy:"12",r:"9.5"}),t("path",{d:"m8 12.5 2.7 2.7L16.5 9.5"})],locate:()=>[t("path",{d:"M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2 2h8.4A1.5 1.5 0 0 1 21 8.5v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z"}),t("path",{d:"m11 13 2 2 3-3"})],file:()=>[t("path",{d:"M6 3h8l4 4v14H6z"}),t("path",{d:"M14 3v4h4"})],folder:()=>[t("path",{d:"M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2 2h8.4A1.5 1.5 0 0 1 21 8.5v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z"})],warn:()=>[t("path",{d:"M12 3 2.5 20h19z"}),t("path",{d:"M12 10v4.5"}),t("path",{d:"M12 17.5v.01"})],trash:()=>[t("path",{d:"M3 6h18"}),t("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),t("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"})],chevron:()=>[t("path",{d:"m6 9 6 6 6-6"})],up:()=>[t("path",{d:"m6 15 6-6 6 6"})],cast:()=>[t("path",{d:"M3 8V6a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-5"}),t("path",{d:"M3 12a8 8 0 0 1 8 8"}),t("path",{d:"M3 16a4 4 0 0 1 4 4"}),t("path",{d:"M3 20h.01"})],lock:()=>[t("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2"}),t("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})],signal:()=>[t("path",{d:"M2 20h.01M7 20v-4M12 20v-8M17 20V8M22 4v16"})],plus:()=>[t("path",{d:"M12 5v14M5 12h14"})]},f={pause:()=>[t("rect",{x:"6",y:"5",width:"4",height:"14",rx:"1"}),t("rect",{x:"14",y:"5",width:"4",height:"14",rx:"1"})],play:()=>[t("path",{d:"M7 5v14l12-7z"})]},m=({name:a,size:e=16,label:s})=>{const i=f[a];return t("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 24 24",fill:i?"currentColor":"none",stroke:i?"none":"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":s?void 0:"true",role:s?"img":void 0,"aria-label":s},(i??g[a])?.()??null)},b={mp4:"video/mp4",m4v:"video/mp4",webm:"video/webm",mkv:"video/x-matroska",mov:"video/quicktime",mp3:"audio/mpeg",m4a:"audio/mp4",flac:"audio/flac",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",wav:"audio/wav"};function y(t){return b[function(t){const a=/\.([a-z0-9]+)$/i.exec(t);return a?a[1].toLowerCase():""}(t)]??"application/octet-stream"}function v(t,a){return function(t,a){return!(!Number.isFinite(a)||a<=0)&&(t>=.95*a||a-t<=120)}(t,a)?"clear":t<30?"skip":"save"}const x="phirepass.player.position.",w={async get(t){try{const a=window.localStorage.getItem(x+t);if(!a)return null;const e=JSON.parse(a);return"number"==typeof e?.secs?e:null}catch{return null}},async set(t,a,e){try{window.localStorage.setItem(x+t,JSON.stringify({secs:a,duration:e,at:Date.now()}))}catch{}},async clear(t){try{window.localStorage.removeItem(x+t)}catch{}}},M=e(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.playerClose=i(this,"phirepassPlayerClose")}get el(){return this}media;lastSave=0;resumeAt=0;everPlayed=!1;positionPrompted=!1;availabilityId;onRemoteConnect=()=>this.phase="casting";onRemoteDisconnect=()=>{"casting"===this.phase&&(this.phase=this.everPlayed?"playing":"buffering")};src;name;mime;status;ready;positionStore;positionKey;remotePlayback;castDevice;playerClose;phase="buffering";stored=null;castAvailable=!1;currentTime=0;duration=0;get store(){return this.positionStore??w}get audio(){return(this.mime??y(this.name)).startsWith("audio/")}async componentWillLoad(){if(this.positionKey){const t=await this.store.get(this.positionKey).catch((()=>null));t&&"save"===v(t.secs,t.duration)&&(this.stored=t,this.positionPrompted=!0,this.phase="prompt")}}componentDidLoad(){this.watchRemote()}disconnectedCallback(){this.savePosition(!0);const t=this.remote();t&&(t.removeEventListener("connect",this.onRemoteConnect),t.removeEventListener("disconnect",this.onRemoteDisconnect),void 0!==this.availabilityId&&t.cancelWatchAvailability(this.availabilityId).catch((()=>{})))}onSrc(){this.everPlayed=!1,this.phase="buffering"}async close(){await this.savePosition(!0),this.media?.pause?.(),this.playerClose.emit()}remote(){return this.remotePlayback??this.media?.remote}async watchRemote(){const t=this.remote();if(t&&!this.audio){t.addEventListener("connect",this.onRemoteConnect),t.addEventListener("disconnect",this.onRemoteDisconnect),"connected"===t.state&&(this.phase="casting");try{this.availabilityId=await t.watchAvailability((t=>this.castAvailable=t))}catch{this.castAvailable=!0}}}async savePosition(t=!1){const a=this.media;if(!a||!this.positionKey||!this.everPlayed)return;const e=Date.now();if(!t&&e-this.lastSave<1e4)return;this.lastSave=e;const s=v(a.currentTime,a.duration);"save"===s?await this.store.set(this.positionKey,a.currentTime,a.duration).catch((()=>{})):"clear"===s&&await(this.store.clear?.(this.positionKey).catch((()=>{})))}startAt(t){this.stored=null,this.phase="buffering",this.resumeAt=t;const a=this.media;a&&(t>0&&(a.currentTime=t),a.play?.()?.catch?.((()=>{})))}retry(){const t=this.media,a=t?.currentTime||this.resumeAt;this.phase="buffering",t&&(t.load?.(),this.startAt(a))}onError(){const t=this.media?.error?.code;this.phase=2===t?"stopped":"unsupported"}bindMedia(t){t&&t!==this.media&&(this.media=t)}renderStage(){switch(this.phase){case"prompt":return t("div",{class:"stage-msg","data-phase":"prompt"},t("b",null,"Resume from ",u(this.stored.secs),"?"),t("span",null,"You stopped here on ",function(t){const a=new Date(t);return`${a.getDate()} ${a.toLocaleString("en-GB",{month:"short"})}`}(this.stored.at),". ",u(this.stored.duration)," in total."),t("div",{class:"row"},t("button",{type:"button",class:"btn",onClick:()=>this.startAt(0)},"Start over"),t("button",{type:"button",class:"btn pri",onClick:()=>this.startAt(this.stored.secs)},"Resume")));case"buffering":return t("div",{class:"stage-msg overlay-msg","data-phase":"buffering"},t("span",{class:"spin","aria-hidden":"true"}),t("b",null,"Buffering"),void 0!==this.ready&&t("span",null,o(this.ready)," ready from the start"));case"waiting":return t("div",{class:"stage-msg overlay-msg","data-phase":"waiting"},t("span",{class:"spin","aria-hidden":"true"}),t("b",null,"Waiting for this part to download"),t("span",null,"You skipped ahead of what the node has. Playback resumes by itself."));case"unsupported":return t("div",{class:"stage-msg","data-phase":"unsupported"},t(m,{name:"warn",size:28}),t("b",null,"This browser cannot play this format"),t("span",null,"The download is not affected. Download the file to play it in another app."),t("a",{class:"btn pri",href:this.src,download:this.name},"Download file"));case"stopped":return t("div",{class:"stage-msg","data-phase":"stopped"},t(m,{name:"signal",size:28}),t("b",null,"Playback stopped"),t("span",null,"The connection to the node was lost."),t("button",{type:"button",class:"btn pri",onClick:()=>this.retry()},"Try again"));case"casting":return t("div",{class:"stage-msg","data-phase":"casting"},t(m,{name:"cast",size:28}),t("b",null,"Playing on ",this.castDevice??"your TV"),t("span",null,"The TV reads the file from the node. You can close this tab."),t("span",{class:"clock"},u(this.currentTime)," / ",u(this.duration)),t("button",{type:"button",class:"btn",onClick:()=>{this.remote()?.prompt().catch((()=>{}))}},"Stop casting"));default:return null}}render(){const a=this.audio,e=function(t,a){const e=a??y(t);return"video/x-matroska"===e?"TVs cannot play MKV files. Download it and play it with VLC.":"video/quicktime"===e?"TVs cannot play MOV files.":null}(this.name,this.mime),s="function"==typeof this.media?.webkitShowPlaybackTargetPicker,i={ref:t=>this.bindMedia(t),src:this.src,controls:!0,preload:"prompt"===this.phase?"metadata":"auto",autoplay:!this.positionPrompted,playsInline:!0,class:{hidden:"prompt"===this.phase||"unsupported"===this.phase||"stopped"===this.phase||"casting"===this.phase},onCanPlay:()=>{"buffering"!==this.phase&&"waiting"!==this.phase||(this.phase="playing")},onPlaying:()=>{this.everPlayed=!0,"casting"!==this.phase&&(this.phase="playing")},onWaiting:()=>{"playing"===this.phase&&(this.phase=this.everPlayed?"waiting":"buffering")},onTimeUpdate:t=>{this.currentTime=t.target.currentTime,this.savePosition()},onDurationChange:t=>this.duration=t.target.duration||0,onPause:()=>{this.savePosition(!0)},onError:()=>this.onError()};return t(n,{key:"941b4e81590e1144fc0bd424f4a5156ca047624d",class:{audio:a}},t("header",{key:"c1866c6dce284c49a17918c6d0e86d132ea9824a",class:"bar"},t("span",{key:"645cf1ec23df722e4b479e2d0b9f78aad9c339f1",class:"nm",title:this.name},this.name),this.status&&t("span",{key:"db77564456be6b4b52b78c709041924b97b930fc",class:"pill"},this.status),t("span",{key:"4f3203babb8f002bf3b783947a01ff6b06cfdb13",class:"sp"}),!a&&(this.castAvailable||e)&&t("button",{key:"3174885867db39af25d328d1bf69879e2e9e5ea5",type:"button",class:"ib",disabled:!!e,title:e??"Cast","aria-label":e?`Cast unavailable: ${e}`:"Cast",onClick:()=>{this.remote()?.prompt().catch((()=>{}))}},t(m,{key:"c36b4847aa20e6b37da23b8b124bc5a679fcfdf1",name:"cast",size:15})),!a&&s&&t("button",{key:"7f1932ac452b57518c608e4723329dac0b9c5698",type:"button",class:"ib",title:"AirPlay","aria-label":"AirPlay",onClick:()=>this.media.webkitShowPlaybackTargetPicker()},t(m,{key:"6814c32ae5b0276260164131f7d017ce24c5063d",name:"cast",size:15})),t("button",{key:"dfcf1c345b01bd30f8274e637e03a0a7e97a0bb8",type:"button",class:"ib","aria-label":"Close player",title:"Close",onClick:()=>{this.close()}},t(m,{key:"2d056a662ae56d4e70ff90cd08ab05cb6c2cf386",name:"x",size:14}))),t("div",{key:"bd610362589f488b395081ae4d12b06da92e8372",class:{stage:!0,audio:a},"data-phase":this.phase},t(a?"audio":"video",{...i}),this.renderStage()))}static get watchers(){return{src:[{onSrc:0}]}}static get style(){return":host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;display:flex;flex-direction:column;background:hsl(var(--card));color:hsl(var(--foreground));border:1px solid hsl(var(--border));border-radius:8px;overflow:hidden;font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}*{box-sizing:border-box}button,a.btn{font:inherit;color:inherit;cursor:pointer}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.bar{display:flex;align-items:center;gap:8px;padding:8px 10px;border-bottom:1px solid hsl(var(--border));min-width:0}.nm{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;background:hsl(var(--primary) / 0.18);color:hsl(var(--primary));flex:none}.sp{flex:1}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));padding:0;flex:none}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4;cursor:not-allowed}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));text-decoration:none;display:inline-flex;align-items:center}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.stage{position:relative;background:#000;min-height:220px;display:grid}.stage.audio{min-height:0;background:hsl(var(--bg));padding:14px}.stage>video,.stage>audio{grid-area:1 / 1;width:100%;max-height:70vh;display:block}.stage>audio{align-self:center}.stage>.hidden{visibility:hidden}.stage-msg{grid-area:1 / 1;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:8px;padding:22px;z-index:1}.stage.audio .stage-msg{padding:8px}.overlay-msg{background:rgba(0, 0, 0, 0.55);pointer-events:none}.stage-msg>svg{color:hsl(var(--amber))}.stage-msg[data-phase='casting']>svg{color:hsl(var(--primary))}.stage-msg b{font-size:14px;font-weight:600}.stage-msg span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.stage-msg .clock{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-variant-numeric:tabular-nums}.stage-msg .row{display:flex;gap:8px;margin-top:4px}.spin{width:26px;height:26px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion: reduce){.spin{animation:none}}"}},[513,"phirepass-media-player",{src:[1],name:[1],mime:[1],status:[1],ready:[2],positionStore:[16],positionKey:[1,"position-key"],remotePlayback:[16],castDevice:[1,"cast-device"],phase:[32],stored:[32],castAvailable:[32],currentTime:[32],duration:[32],close:[64]},void 0,{src:[{onSrc:0}]}]);function k(){"undefined"!=typeof customElements&&["phirepass-media-player"].forEach((t=>{"phirepass-media-player"===t&&(customElements.get(a(t))||customElements.define(a(t),M))}))}k();export{m as I,M as P,o as a,d as b,h as c,k as d,l as e,c as f,u as g,p}
@@ -1 +0,0 @@
1
- import{h as e,t,p as n,H as o,c as s,a as i}from"./index.js";import{_ as r,C as a,P as l,E as d}from"./p-BtMWUitf.js";import{f as c,a as h,b as p,c as u,e as f,g as b,I as g,p as m,d as w}from"./p-C4cmk3bS.js";const v=["send_download_start","send_download_stop","send_download_resume","send_download_set_order","send_download_delete","send_download_subscribe","send_download_where"];function x(e){return!(!e||"object"!=typeof e)&&v.every((t=>"function"==typeof e[t]))}const y=1073741824,k=new Set(["DownloadProgress","DownloadAccepted","DownloadWhereAnswer","DownloadCaps","DownloadFoldersAnswer"]);function C(e){return k.has(e.type)}const S=new Set(["host","content-length","range","if-range","transfer-encoding","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailer","upgrade"]);function $(e){const t=e.trim();if(!t)return{kind:"empty"};if(/^magnet:\?/i.test(t)){const e=t.slice(t.indexOf("?")+1),n=new URLSearchParams(e),o=n.getAll("xt").find((e=>/^urn:btih:/i.test(e)));if(!o)return{kind:"invalid"};const s=o.slice(9),i=n.get("dn")?.trim();return{kind:"magnet",uri:t,infoHash:s,...i?{name:i}:{}}}let n;try{n=new URL(t)}catch{return{kind:"invalid"}}if("http:"!==n.protocol&&"https:"!==n.protocol)return{kind:"invalid"};if(!n.hostname)return{kind:"invalid"};if(n.username||n.password)return{kind:"invalid"};const o="https:"===n.protocol?"HTTPS":"HTTP",s=function(e){const t=e.split("/").filter(Boolean),n=t[t.length-1]??"";try{return decodeURIComponent(n)}catch{return n}}(n.pathname)||"download";return{kind:/\.torrent$/i.test(n.pathname)?"torrent-url":"http",url:t,host:n.hostname,name:s,scheme:o}}function D(e){const t=(...e)=>e.some((e=>/[\r\n\0]/.test(e)));switch(e.mode){case"none":return{auth:null};case"basic":return e.username?e.username.includes(":")?{auth:null,error:"A username cannot contain a colon."}:t(e.username,e.password)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Basic:{username:e.username,password:e.password}}}:{auth:null,error:"Enter a username."};case"bearer":return e.token.trim()?t(e.token)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Bearer:{token:e.token.trim()}}}:{auth:null,error:"Enter a token."};case"header":{const n=e.headerName.trim();return/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(n)?S.has(n.toLowerCase())?{auth:null,error:`${n} cannot be set here.`}:t(e.headerValue)?{auth:null,error:"A login cannot contain line breaks."}:{auth:{Header:{name:n,value:e.headerValue}}}:{auth:null,error:"Enter a valid header name."}}}}const z={text:"",saveAs:"",torrent:null,order:null,auth:{mode:"none",username:"",password:"",token:"",headerName:"",headerValue:""},authOpen:!1};function F(e,t,n){const o=e.torrent?{kind:"empty"}:$(e.text),s=!!e.torrent||"magnet"===o.kind,i=s&&!!t&&!t.torrents,r="http"===o.kind||"torrent-url"===o.kind;let a=null;"too-large"===e.torrent?.error?a={tone:"err",title:"Too large",body:"A .torrent file can be up to 2 MB. Use its magnet link instead."}:"not-torrent"===e.torrent?.error?a={tone:"err",title:"Not a .torrent",body:"Choose a file that ends in .torrent."}:"invalid"===o.kind?a={tone:"err",title:"Not a link",body:"Use http://, https:// or magnet:"}:i&&(a={tone:"warn",title:"Torrents are off",body:"This node only allows ordinary links. Its owner can allow torrents in the node's settings."});const l=D(e.auth),d=s&&!i,c=n&&!!t&&(r||"magnet"===o.kind||!!e.torrent&&!e.torrent.error&&!!e.torrent.contents)&&!a&&(!d||null!==e.order)&&(!r||!e.authOpen||!l.error);let h;return r?h=e.saveAs.trim()||o.name:"magnet"===o.kind&&(h=o.name),{detected:o,isTorrent:s,needsOrder:d,showSaveAs:"http"===o.kind,showAuth:r,note:a,canStart:c,askedName:h,authError:r&&e.authOpen&&(e.auth.username||e.auth.token||e.auth.headerName||e.auth.headerValue)?l.error:void 0}}const _=new Set(["Completed","Seeding"]);function P(e){return _.has(e)}const T=new Set(["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused","Stopped","Unknown"]);function I(e){return["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused"].includes(e.state)}function R(e){return("Completed"===e.state||"Cancelled"===e.state)&&!e.deleting}const N={Downloading:0,Verifying:1,FetchingMetadata:2,Resolving:3,Paused:4,Queued:5,Scheduled:6,Retrying:7,Stopped:8,Seeding:9,Completed:10,Cancelled:11,Deleted:12,Unknown:13};function A(e){const t=e.filter(I),n=t.reduce(((e,t)=>e+(t.down_bps||0)),0),o=t.filter((e=>e.total_bytes)),s=o.reduce(((e,t)=>e+t.done_bytes),0),i=o.reduce(((e,t)=>e+(t.total_bytes??0)),0);return{active:t.length,downBps:n,done:s,total:i,percent:i?s/i*100:null}}const j=/\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;function O(e){return j.test(e)}function M(e){const t=function(e){const t=e.files.filter((e=>e.media||O(e.name)));return t.length?t.reduce(((e,t)=>t.size>e.size?t:e)):!e.files.length&&O(e.name)?{index:0,name:e.name,size:e.total_bytes??0,done_bytes:e.done_bytes,media:!0,ready_from_start:e.in_order?e.done_bytes:0}:null}(e);return!t||e.deleting?{play:!1,file:null,switchToInOrder:!1}:P(e.state)?{play:!0,file:t,switchToInOrder:!1}:["Downloading","Verifying","Paused","Stopped","Retrying"].includes(e.state)&&t.size?e.in_order?{play:!0,file:t,switchToInOrder:!1}:{play:!1,file:null,switchToInOrder:"Torrent"===e.kind}:{play:!1,file:null,switchToInOrder:!1}}function B(...e){const t=e.filter((e=>!!e)).join("/").replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/+$/,""):t}function U(e){return B(e.dest_root,e.sub_dir)}function E(e,t,n){return e.agent_supported?"Organisation"===e.lock?{id:"blocked",title:"Blocked",body:`Your organisation does not allow downloads on ${t}.`,secondary:"An owner or admin of the organisation can change this under Organisation → Downloads."}:e.http?"NoFolder"===e.lock?{id:"no-folder",title:"No download folder",body:"The download folder on this node is missing or can't be written.",secondary:"Someone who can configure the node can pick another one.",action:n?"Open node settings":void 0}:null:{id:"off",title:"Downloads are off",body:`Downloads are turned off for ${t}.`,secondary:n?"You can turn them on in the node's settings.":"Ask the node's owner to turn them on.",action:n?"Open node settings":void 0}:{id:"too-old",title:"Too old",body:`${t} runs an agent that cannot download. Update the agent on that machine, then try again.`}}const V=({label:t,onClose:n,wide:o},s)=>e("div",{class:"overlay",onClick:e=>{e.target===e.currentTarget&&n()}},e("div",{class:{modal:!0,wide:!!o},role:"dialog","aria-modal":"true","aria-label":t,tabindex:-1,onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),n())}},s)),W=({cancel:t,confirm:n,danger:o,onCancel:s,onConfirm:i})=>e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:s},t),e("button",{type:"button",class:{btn:!0,pri:!o,dng:!!o},onClick:i},n)),q=({row:t,discard:n,onDiscard:o,...s})=>e(V,{label:"Stop this download?",onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Stop this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,t.total_bytes?`${h(t.done_bytes)} of ${h(t.total_bytes)} downloaded`:`${h(t.done_bytes)} downloaded`))),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the part already downloaded",e("span",{class:"hint block"},"Leave this off and Resume continues from here."))),e(W,{cancel:"Keep downloading",confirm:"Stop download",danger:!0,...s}))),L=({row:t,deleteFile:n,onDeleteFile:o,nodeName:s,...i})=>{const r=P(t.state),a=t.files.length>1?`${t.files.length} files · ${h(t.total_bytes??t.done_bytes)}`:h(t.total_bytes??t.done_bytes);return e(V,{label:"Delete this download?",onClose:i.onCancel},e("div",{class:"dlg"},e("h4",null,"Delete this download?"),e("div",{class:"filechip"},e(g,{name:"file",size:20}),e("div",null,e("b",null,t.name),e("span",null,"Seeding"===t.state?"Seeding · ":"",a," in ",U(t)))),"Seeding"===t.state&&e("p",{class:"dtx"},s," stops sharing it with peers."),r?e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Also delete the files",e("span",{class:"hint block"},"Off: the files stay in ",U(t)," and only the download is removed."))):e("p",{class:"dtx"},"The part already downloaded is deleted."),e(W,{cancel:"Cancel",confirm:"Delete",danger:!0,...i})))},Q=({row:t,...n})=>e(V,{label:"Switch to fastest?",onClose:n.onCancel},e("div",{class:"dlg"},e("h4",null,"Switch to fastest?"),e("p",{class:"dtx"},e("b",null,t.name)," is playing. Fastest downloads pieces in any order, so playback stops until it finishes or you switch back."),e(W,{cancel:"Keep in order",confirm:"Switch and stop playback",danger:!0,...n}))),H=({nodeName:t,dontAsk:n,onDontAsk:o,...s})=>e(V,{label:`Start a torrent on ${t}?`,onClose:s.onCancel},e("div",{class:"dlg"},e("h4",null,"Start a torrent on ",t,"?"),e("div",{class:"note warn"},e(g,{name:"warn",size:14}),e("div",null,"The node will connect to public peers. They can see its internet address, and it uploads to them while it downloads.")),e("p",{class:"dtx"},"When it finishes, ",t," keeps sharing it with other peers until you delete it."),e("label",{class:"checkline"},e("input",{type:"checkbox",checked:n,onChange:e=>o(e.target.checked)}),e("span",null,"Do not ask again on this browser")),e(W,{cancel:"Cancel",confirm:"Start torrent",...s}))),K=({reason:t,onClose:n})=>e(V,{label:"Not enough space",onClose:n},e("div",{class:"dlg"},e("h4",null,"Not enough space"),e("p",{class:"dtx"},t),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn pri",onClick:n},"OK")))),Y=t=>e(V,{label:"Save downloads to",onClose:t.onCancel,wide:!0},e("div",{class:"dlg"},e("h4",null,"Save downloads to"),e("nav",{class:"crumbs","aria-label":"Folder"},e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(0)},t.root),t.path.map(((n,o)=>[e("span",{class:"sep"},"/"),e("button",{type:"button",class:"lnk",onClick:()=>t.onUp(o+1)},n)]))),e("div",{class:"folders",role:"list"},null===t.folders&&e("div",{class:"muted"},"Loading…"),0===t.folders?.length&&e("div",{class:"muted"},"No folders here."),t.folders?.map((n=>e("button",{type:"button",class:"folder-row",role:"listitem",onClick:()=>t.onOpen(n)},e(g,{name:"folder",size:14}),e("span",null,n))))),t.error&&e("div",{class:"note err"},t.error),null!==t.newName&&e("input",{class:"inp",type:"text","aria-label":"New folder name",placeholder:"New folder name",value:t.newName,onInput:e=>t.onNewName(e.target.value)}),e("p",{class:"hint"},"Folders only, and only inside the node's download folder. A new folder is created by the node when the first download lands in it."),e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn left",onClick:()=>t.onNewName(null===t.newName?"":null)},e(g,{name:"plus",size:12})," New folder"),e("button",{type:"button",class:"btn",onClick:t.onCancel},"Cancel"),e("button",{type:"button",class:"btn pri",disabled:null!==t.newName&&!/^[^/\\\0]+$/.test(t.newName.trim()),onClick:t.onSave},"Save here")))),X=({note:t})=>e("div",{class:`note ${t.tone}`,role:"err"===t.tone?"alert":"status"},e(g,{name:"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body));function Z({model:t}){const n=t.detected;return"http"===n.kind||"torrent-url"===n.kind?e("div",{class:"detect","data-kind":n.kind},e("span",{class:"pill meta"},"torrent-url"===n.kind?".torrent link":n.scheme),e("span",{class:"host"},n.host)):"magnet"===n.kind?e("div",{class:"detect","data-kind":"magnet"},e("span",{class:"pill meta"},"Magnet"),e("span",{class:"host"},n.name??"name arrives with the metadata")):e("div",{class:"detect"})}const G=({auth:t,onChange:n})=>{const o=n,s=(n,s,i="text")=>e("label",{class:"fld"},e("span",null,n),e("input",{class:"inp",type:i,autocomplete:"off",spellcheck:!1,value:t[s],onInput:e=>o({[s]:e.target.value})}));return e("div",{class:"auth"},e("div",{class:"seg",role:"radiogroup","aria-label":"Login for the link"},[["none","No login"],["basic","Username and password"],["bearer","Bearer token"],["header","Custom header"]].map((([n,s])=>e("label",{class:{on:t.mode===n}},e("input",{type:"radio",name:"auth-mode",checked:t.mode===n,onChange:()=>o({mode:n})}),s)))),"basic"===t.mode&&[s("Username","username"),s("Password","password","password")],"bearer"===t.mode&&s("Token","token","password"),"header"===t.mode&&[s("Header name","headerName"),s("Value","headerValue","password")],"none"!==t.mode&&e("p",{class:"hint"},"Sent only to this link's own site, and dropped if it redirects elsewhere. The node seals it and deletes it when the download finishes."))},J=({order:t,onChange:n})=>e("fieldset",{class:"order"},e("legend",null,"How should it download? (required for torrents)"),e("label",{class:{opt:!0,on:"in"===t}},e("input",{type:"radio",name:"order",value:"in",checked:"in"===t,onChange:()=>n("in")}),e("span",null,e("b",null,"In order")," · watch while it downloads, a little slower")),e("label",{class:{opt:!0,on:"fast"===t}},e("input",{type:"radio",name:"order",value:"fast",checked:"fast"===t,onChange:()=>n("fast")}),e("span",null,e("b",null,"Fastest")," · any order; switch to in order later if you want to watch"))),ee=t=>{const{form:n,model:o,caps:s}=t;let i;const r=!!s?.torrents,a="dialog"===t.layout,l=e("input",{type:"file",accept:".torrent,application/x-bittorrent",class:"hidden-input",ref:e=>i=e,onChange:e=>{const n=e.target,o=n.files?.[0];o&&t.onPickTorrent(o),n.value=""}}),d=n.torrent?e("div",{class:{filechip:!0,bad:!!n.torrent.error}},e(g,{name:"torrent",size:20}),e("div",null,e("b",null,n.torrent.name),e("span",null,h(n.torrent.size)," · from this computer")),e("button",{type:"button",class:"ib","aria-label":"Remove the .torrent file",title:"Remove",onClick:()=>t.onChange({torrent:null,order:null})},e(g,{name:"x",size:14}))):e("div",{class:"fld"},e("label",{htmlFor:"fetch-link"},"Link or magnet"),e("div",{class:"inline-row"},e("input",{id:"fetch-link",class:"inp",type:"text",inputMode:"url",autocomplete:"off",autocapitalize:"none",spellcheck:!1,placeholder:"https://… or magnet:?xt=…",value:n.text,disabled:t.starting,onInput:e=>t.onChange({text:e.target.value}),onKeyDown:e=>{"Enter"===e.key&&o.canStart&&(e.preventDefault(),t.onStart())}}),!a&&r&&e("button",{type:"button",class:"btn",onClick:()=>i?.click()},".torrent…"),!a&&e("button",{type:"button",class:"btn pri",disabled:!o.canStart||t.starting,onClick:()=>t.onStart()},t.starting?"Starting…":"Download")),e(Z,{model:o}));return e("form",{class:{"fetch-form":!0,[t.layout]:!0},onSubmit:e=>{e.preventDefault(),o.canStart&&t.onStart()},onDragOver:e=>r&&e.preventDefault(),onDrop:e=>r&&(e=>{e.preventDefault();const n=e.dataTransfer?.files?.[0];n&&t.onPickTorrent(n)})(e)},a&&e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,t.title)),l,d,o.note&&e(X,{note:o.note}),t.refusal&&e(X,{note:t.refusal}),o.showSaveAs&&e("div",{class:"fld"},e("label",{htmlFor:"fetch-save-as"},"Save as"),e("input",{id:"fetch-save-as",class:"inp",type:"text",autocomplete:"off",spellcheck:!1,placeholder:o.askedName,value:n.saveAs,disabled:t.starting,onInput:e=>t.onChange({saveAs:e.target.value})}),e("span",{class:"hint"},"Taken from the server's filename when it sends one. An existing file is never overwritten; the new one gets “(1)” added.")),o.showAuth&&e("div",{class:"login"},e("button",{type:"button",class:"lnk","aria-expanded":n.authOpen?"true":"false",onClick:()=>t.onChange({authOpen:!n.authOpen})},e(g,{name:n.authOpen?"up":"chevron",size:12})," This link needs a login"),n.authOpen&&e(G,{auth:n.auth,onChange:t.onAuth}),o.authError&&e("span",{class:"hint err",role:"alert"},o.authError)),o.needsOrder&&e(J,{order:n.order,onChange:e=>t.onChange({order:e})}),("http"===o.detected.kind||"torrent-url"===o.detected.kind)&&e("p",{class:"hint"},"A link always downloads in order, so you can watch while it arrives."),a&&r&&!n.torrent&&[e("div",{class:"or"},"or"),e("button",{type:"button",class:"drop",onClick:()=>i?.click()},e(g,{name:"torrent",size:22}),e("span",null,e("b",null,"Choose a .torrent file")," or drop it here",e("br",null),e("span",{class:"hint"},"Up to 2 MB, read in the browser and sent to the node")))],t.destination&&e("div",{class:"fld"},a&&e("label",null,"Destination"),e("div",{class:"dest-row"},e("div",{class:"dest",title:t.destination.path},e(g,{name:"folder",size:14}),e("span",null,t.destination.path)),t.onChooseFolder&&e("button",{type:"button",class:"btn",onClick:()=>t.onChooseFolder?.()},"Choose folder…")),t.destination.hint&&e("span",{class:"hint where"},t.destination.hint)),a&&e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>t.onCancel?.()},"Cancel"),e("button",{type:"submit",class:"btn pri",disabled:!o.canStart||t.starting},t.starting?"Starting…":"Start download")))};function te(e){return"FetchingMetadata"===e.state||"Resolving"===e.state?"bar indet":"Retrying"===e.state||"Paused"===e.state?"bar moving":"Stopped"===e.state||"Queued"===e.state||"Scheduled"===e.state||e.deleting?"bar paused":"Cancelled"===e.state?"bar fail":"Seeding"===e.state?"bar seed":"bar"}const ne=({icon:t,label:n,onClick:o,primary:s})=>e("button",{type:"button",class:{ib:!0,new:!!s},title:n,"aria-label":n,onClick:o},e(g,{name:t,size:14})),oe=({row:t,actions:n,running:o,source:s,compact:i})=>{const{icon:r,tone:a}=function(e){return"Torrent"===e.kind?{icon:e.name.startsWith("magnet:")?"magnet":"torrent",tone:"t"}:"Node"===e.kind?{icon:"node",tone:"n"}:{icon:"globe",tone:"h"}}(t),l=function(e){if(e.deleting)return{text:"Deleting…",tone:"ps"};if(e.waitingForNode)return{text:"Waiting for the node",tone:"q"};switch(e.state){case"Queued":return{text:"Queued",tone:"q"};case"Scheduled":return{text:"Scheduled",tone:"q"};case"Resolving":return{text:"Connecting",tone:"meta"};case"FetchingMetadata":return{text:"Fetching metadata",tone:"meta"};case"Downloading":return{text:"Downloading",tone:"dl"};case"Verifying":return{text:"Checking pieces",tone:"meta"};case"Paused":return{text:"DiskFull"===e.pause_reason?"Paused · disk almost full":"Paused",tone:"mv"};case"Retrying":return{text:"Retrying",tone:"mv"};case"Seeding":return{text:"Seeding",tone:"sd"};case"Completed":return{text:"Completed",tone:"ok"};case"Stopped":return{text:"Stopped",tone:"ps"};case"Cancelled":return{text:"Cancelled",tone:"err"};default:return{text:e.state,tone:"ps"}}}(t),d=function(e){return"Torrent"===e.kind&&["Downloading","Verifying","Paused"].includes(e.state)?e.in_order?"In order":"Fastest":null}(t),w=M(t),v=function(e,t={}){const n=t.now??Date.now(),o=c(e.done_bytes,e.total_bytes),s=e.total_bytes?`${h(e.done_bytes)} of ${h(e.total_bytes)}`:e.done_bytes?h(e.done_bytes):"",i=[],r=(e,t={})=>e&&i.push({text:e,...t});if(e.deleting)return r("Waiting for the node to confirm"),i;if(e.waitingForNode)return r("Starts when the node reports in"),r("It keeps going after you close this tab"),i;switch(e.state){case"Queued":r("Waiting for a free slot"),t.running&&r(`${t.running} ${1===t.running?"is":"are"} running`);break;case"Scheduled":r("Waits for the download window"),e.next_attempt_at&&e.next_attempt_at>n&&r(`starts in ${p((e.next_attempt_at-n)/1e3)}`);break;case"Resolving":r(t.source?`Contacting ${t.source}`:"Contacting the server");break;case"FetchingMetadata":r("Asking peers for the torrent info"),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),r(b((n-e.started_at)/1e3));break;case"Downloading":r(o,{strong:!0}),r(s),r(u(e.down_bps)),"Torrent"===e.kind&&(r(u(e.up_bps,"↑")),r(`${e.peers} ${1===e.peers?"peer":"peers"}`)),r(f(e.done_bytes,e.total_bytes,e.down_bps)),e.restarted_from_zero&&r("The file changed on the server, so it started over"),t.source&&r(t.source);break;case"Verifying":r(o,{strong:!0}),r("Checking downloaded pieces after a restart"),r(`${h(e.done_bytes)} already on disk`);break;case"Paused":"DiskFull"===e.pause_reason?(r(e.reason??"Free space is below the floor"),r("Resumes by itself when there is room")):(r(o,{strong:!0}),r("Outside the download window"),r("Resumes by itself"));break;case"Retrying":r(e.retry_reason??e.reason??"Something went wrong",{error:!0}),r(`attempt ${e.attempt}`),e.next_attempt_at&&r(e.next_attempt_at>n?`Next try in ${p((e.next_attempt_at-n)/1e3)}`:"Trying again now"),e.done_bytes&&r(`${h(e.done_bytes)} kept`);break;case"Seeding":r(u(e.up_bps,"↑")),r(`${h(e.up_total)} uploaded`),r(`${e.peers} ${1===e.peers?"peer":"peers"}`),e.seeding_since&&r(`seeding for ${p((n-e.seeding_since)/1e3).replace(/ \d+[hm]$/,"")}, until you delete it`);break;case"Completed":if(r("100%",{strong:!0}),r(e.files.length>1?`${e.files.length} files · ${h(e.total_bytes??e.done_bytes)}`:h(e.total_bytes??e.done_bytes)),e.finished_at&&e.started_at){const t=(e.finished_at-e.started_at)/1e3;r(`took ${p(t)}`),t>0&&(e.total_bytes??e.done_bytes)&&r(`avg ${h((e.total_bytes??e.done_bytes)/t)}/s`)}break;case"Stopped":r(o,{strong:!0}),r(e.reason??"Stopped by you"),r("Resume continues from here");break;case"Cancelled":r(e.reason??"Stopped and its part deleted",{error:!!e.reason}),r("Resume starts from zero")}return i}(t,{running:o,source:s}),x="Completed"===t.state||"Seeding"===t.state?100:m(t.done_bytes,t.total_bytes),y=[];if(!t.deleting)switch(w.play&&y.push(e(ne,{icon:"play",label:P(t.state)?"Play":"Play while downloading",primary:!0,onClick:()=>n.play(t)})),t.state){case"Downloading":case"Verifying":case"Resolving":case"FetchingMetadata":case"Queued":"Downloading"!==t.state&&"Verifying"!==t.state||y.push(e(ne,{icon:"pause",label:"Pause",onClick:()=>n.pause(t)})),y.push(e(ne,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Scheduled":case"Paused":"Scheduled"!==t.state&&"Window"!==t.pause_reason||y.push(e(ne,{icon:"play",label:"Start now",onClick:()=>n.resume(t,!0)})),y.push(e(ne,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Retrying":y.push(e(ne,{icon:"retry",label:"Try now",onClick:()=>n.resume(t)})),y.push(e(ne,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Stopped":y.push(e(ne,{icon:"play",label:"Resume",onClick:()=>n.resume(t)})),y.push(e(ne,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Seeding":y.push(e(ne,{icon:"pause",label:"Pause seeding",onClick:()=>n.pause(t)})),y.push(e(ne,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(ne,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Completed":y.push(e(ne,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(ne,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}));break;case"Cancelled":y.push(e(ne,{icon:"retry",label:"Start again",onClick:()=>n.resume(t)})),y.push(e(ne,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}))}return e("div",{key:t.download_id,class:{job:!0,compact:!!i},"data-state":t.deleting?"Deleting":t.state,"data-id":t.download_id,role:"listitem","aria-label":`${t.name}, ${l.text}`},e("span",{class:`kind ${a}`},e(g,{name:r,size:15})),e("div",{class:"title"},e("span",{class:"nm",title:t.name},t.name),e("span",{class:`pill ${l.tone}`},l.text),d&&e("span",{class:"pill meta"},d)),e("div",{class:"acts"},y),e("div",{class:te(t),role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(x),"aria-label":`${t.name} progress`},e("i",{style:{width:`${x}%`}})),e("div",{class:"stats"},v.map((t=>t.strong?e("b",null,t.text):e("span",{class:{err:!!t.error}},t.text))),!w.play&&w.switchToInOrder&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!0)},"Switch to in order to watch"),w.play&&"Torrent"===t.kind&&t.in_order&&!P(t.state)&&e("button",{type:"button",class:"lnk inline",onClick:()=>n.setOrder(t,!1)},"Switch to fastest")))},se={started:"fetch",queued:"fetch",stuck:"warn",renamed:"file",completed:"check",error:"warn"},ie=({notices:t,onDismiss:n})=>t.length?e("div",{class:"toasts","aria-live":"polite"},t.map((t=>e("div",{class:{toast:!0,bad:"stuck"===t.kind||"error"===t.kind},"data-notice":t.kind,key:t.id},e(g,{name:se[t.kind],size:18}),e("div",{class:"t"},e("b",null,t.title),e("span",{title:t.detail},t.detail)),t.action&&e("button",{type:"button",class:"btn",onClick:()=>{t.action.run(),n(t.id)}},t.action.label),e("button",{type:"button",class:"ib","aria-label":"Dismiss",onClick:()=>n(t.id)},e(g,{name:"x",size:12})))))):null,re=({icon:t,title:n,body:o,action:s})=>e("div",{class:"empty",role:"status"},e(g,{name:t,size:28}),e("b",null,n),e("span",null,o),s&&e("button",{type:"button",class:"btn pri",onClick:s.onClick},s.label)),ae=()=>e(re,{icon:"fetch",title:"No downloads yet",body:"Press Fetch and paste a link. Downloads keep running after you close this tab, and they show here when you come back."}),le=({nodeName:t,folder:n})=>e(re,{icon:"fetch",title:"Nothing downloading",body:`Paste a link above. It downloads onto ${t}${n?`, into ${n}`:""}.`}),de=({onSignIn:t})=>e(re,{icon:"lock",title:"Sign in to PhirePass",body:"Your downloads are tied to your account and the nodes you can reach.",action:{label:"Sign in",onClick:t}}),ce=({nodeName:t,onRetry:n})=>e(re,{icon:"signal",title:`Can't reach ${t}`,body:"If the machine is still running, its downloads carry on. They will show here when it reconnects.",action:n?{label:"Try again",onClick:n}:void 0}),he=()=>e(re,{icon:"warn",title:"Downloads are not available here",body:"This page's connection library is too old to start downloads. Reload after the site updates."}),pe=()=>e("div",{class:"empty",role:"status"},e("span",{class:"spin","aria-hidden":"true"}),e("span",null,"Loading downloads…")),ue=({blocker:t,onAction:n,onClose:o})=>e("div",{class:"blocker","data-blocker":t.id},e("div",{class:"note "+("off"===t.id?"info":"warn"),role:"status"},e(g,{name:"off"===t.id?"fetch":"warn",size:14}),e("div",null,e("b",null,t.title)," ",t.body)),t.secondary&&e("p",{class:"hint"},t.secondary),(o||t.action&&n)&&e("div",{class:"dlg-f"},o&&e("button",{type:"button",class:"btn",onClick:o},"Close"),t.action&&n&&e("button",{type:"button",class:"btn pri",onClick:n},t.action))),fe="phirepass.downloader.torrent-ack",be=n(class extends o{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.fetchCompleted=s(this,"phirepassFetchCompleted"),this.play=s(this,"phirepassPlay"),this.activeCount=s(this,"phirepassActiveCount"),this.showInFolder=s(this,"phirepassShowInFolder"),this.openNodeSettings=s(this,"phirepassOpenNodeSettings"),this.signIn=s(this,"phirepassSignIn")}get el(){return this}ownChannel=!1;msgId=y;noticeId=1;seenNotices=new Set;torrentAcked=function(){try{return"1"===window.localStorage.getItem(fe)}catch{return!1}}();noticeTimers=new Map;whereMsgId;nodeId;nodeLabel;token;channel;connected=!1;channelFactory;browsingService;browsingPath;compact=!1;streamBase;canConfigure=!1;inlinePlayer=!0;serverHost="phirepass.com";serverPort=443;serverId;allowInsecure=!1;heartbeatInterval=3e4;fetchCompleted;play;activeCount;showInFolder;openNodeSettings;signIn;connection="connecting";caps=null;jobs={};tab="active";drawerOpen=!1;dialogOpen=!1;unread=0;form=z;where=null;starting=null;refusal=null;confirm=null;notices=[];subDir=null;picker=null;player=null;get name(){return this.nodeLabel||this.nodeId}get ch(){return this.channel??this.ownedChannel}ownedChannel;async componentWillLoad(){this.channel?this.adoptChannel():await this.openOwnChannel()}disconnectedCallback(){this.noticeTimers.forEach((e=>window.clearTimeout(e))),this.noticeTimers.clear(),this.starting?.silence&&window.clearTimeout(this.starting.silence),this.ownChannel&&this.ownedChannel&&(this.ownedChannel.stop_heartbeat(),this.ownedChannel.disconnect())}onChannel(){this.channel&&this.adoptChannel()}onConnected(e,t){this.channel&&(e&&!t?this.subscribe():!e&&t&&(this.connection="unreachable"))}onBrowsing(){this.where=null,this.dialogOpen&&this.askWhere()}onNode(e,t){e!==t&&(this.jobs={},this.caps=null,this.where=null,this.channel?this.connected&&this.subscribe():this.ownedChannel&&(this.ownedChannel.disconnect(),this.openOwnChannel()))}adoptChannel(){this.ownChannel=!1,x(this.channel)?(this.connection="connecting",this.connected&&this.subscribe()):this.connection="unsupported"}endpoint(){return`${this.allowInsecure?"ws":"wss"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}/api/web/ws`}defaultStreamBase(){return`${this.allowInsecure?"http":"https"}://${this.serverHost}${!this.allowInsecure&&443===this.serverPort||this.allowInsecure&&80===this.serverPort?"":`:${this.serverPort}`}`}async openOwnChannel(){if(this.ownChannel=!0,!this.token)return void(this.connection="signed-out");if(!this.nodeId)return;this.channelFactory||await r();const e=this.channelFactory?this.channelFactory(this.endpoint(),this.nodeId,this.serverId):this.serverId?new a(this.endpoint(),this.nodeId,this.serverId):new a(this.endpoint(),this.nodeId);this.ownedChannel=e,x(e)?(e.on_connection_open((()=>e.authenticate(this.token,this.nodeId))),e.on_connection_close((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_error((()=>{"signed-out"!==this.connection&&(this.connection="unreachable")})),e.on_connection_message((()=>{})),e.on_protocol_message((e=>this.dispatch(e.data.web))),this.connection="connecting",e.connect()):this.connection="unsupported"}reconnect(){this.ownChannel?(this.ownedChannel?.disconnect(),this.openOwnChannel()):this.connected&&this.subscribe()}async receive(e){this.dispatch(e.data.web)}dispatch(e){if(e.type===l.AuthSuccess)return this.ownedChannel?.start_heartbeat(Math.max(3e4,this.heartbeatInterval)),void this.subscribe();if(e.type!==l.Error){if(C(e))switch(e.type){case"DownloadCaps":e.node_id===this.nodeId&&(this.caps=e.caps,this.connection="ready");break;case"DownloadProgress":e.node_id===this.nodeId&&this.onProgress(e.job);break;case"DownloadAccepted":this.onAccepted(e.msg_id,e.download_id);break;case"DownloadWhereAnswer":e.msg_id===this.whereMsgId&&(this.where={saves_to:e.saves_to,mapped:e.mapped});break;case"DownloadFoldersAnswer":this.picker&&e.msg_id===this.picker.msgId&&(this.picker={...this.picker,folders:[...e.folders].sort(((e,t)=>e.localeCompare(t)))})}}else this.handleError(e)}handleError(e){if(void 0!==e.msg_id&&e.msg_id===this.starting?.msgId)return this.clearStarting(),void(this.refusal={tone:"err",title:"Refused",body:e.message||"The server refused this download."});this.picker&&e.msg_id===this.picker.msgId?this.picker={...this.picker,folders:[],error:e.message}:void 0!==e.msg_id&&e.msg_id>=y?this.notify("error","That did not work",e.message||"The server refused it."):this.ownChannel&&e.kind===d.Authentication&&(this.connection="signed-out")}subscribe(){const e=this.ch;x(e)?(this.jobs={},e.send_download_subscribe({Node:this.nodeId}),this.dialogOpen&&this.askWhere()):this.connection="unsupported"}onProgress(e){const t=this.jobs[e.download_id],{jobs:n,completed:o}=function(e,t){const n=e[t.download_id];if("Deleted"===t.state){if(!n)return{jobs:e,first:!1};const{[t.download_id]:o,...s}=e;return{jobs:s,first:!1}}const o=t.deleting||n?.deleting||void 0;return{jobs:{...e,[t.download_id]:{...t,deleting:o}},completed:n&&!P(n.state)&&P(t.state)?t:void 0,first:!n}}(this.jobs,e);this.jobs=n,this.emitCount(),this.starting?.downloadId!==e.download_id||t||this.onFirstProgress(e),o&&(this.fetchCompleted.emit({download_id:e.download_id,dest_root:e.dest_root,sub_dir:e.sub_dir,name:e.name}),!this.drawerOpen&&this.compact&&this.unread++,this.notify("completed","Download complete",`${e.name} → ${U(e)}`,{label:"Show",run:()=>this.showInFolder.emit({path:U(e),name:e.name})}));const s=this.jobs[e.download_id];s&&function(e,t=3600){return"Retrying"===e.state&&function(e,t=3600){let n=0;for(let o=0;o<e;o++)n+=Math.min(10*2**o,t);return n}(e.attempt,t)>=86400}(s)&&!this.seenNotices.has(`stuck:${e.download_id}`)&&(this.seenNotices.add(`stuck:${e.download_id}`),this.notify("stuck","Still retrying after a day",`${e.name} · ${e.retry_reason??"no answer"}`,{label:"Show",run:()=>this.showRetrying()},!0))}onAccepted(e,t){if(!this.starting||this.starting.msgId!==e)return;if(this.jobs[t])return void this.onFirstProgress(this.jobs[t]);const n=window.setTimeout((()=>this.nodeSilent(t)),8e3);this.starting={...this.starting,downloadId:t,silence:n}}nodeSilent(e){if(this.starting?.downloadId!==e||this.jobs[e])return;const t=this.starting.askedName??"Download",n=Date.now(),o={download_id:e,kind:"Unknown",name:t,dest_root:this.where?.saves_to??this.caps?.folder??"",sub_dir:null,state:"Queued",done_bytes:0,total_bytes:null,down_bps:0,up_bps:0,peers:0,in_order:!0,started_at:n,finished_at:null,reason:null,requested_by:null,files:[],up_total:0,pause_reason:null,seeding_since:null,info_hash:null,retry_reason:null,attempt:0,next_attempt_at:null,restarted_from_zero:!1,waitingForNode:!0};this.jobs={...this.jobs,[e]:o},this.clearStarting(),this.closeDialog(!0),this.notify("queued",`Waiting for ${this.name}`,`${t} starts when the node reports in.`)}onFirstProgress(e){const t=this.starting?.askedName;if(this.clearStarting(),"Cancelled"!==e.state){if(this.closeDialog(!0),"Queued"===e.state){const e=Object.values(this.jobs).filter((e=>"Downloading"===e.state)).length;this.notify("queued","Added to the queue",`${e} ${1===e?"download is":"downloads are"} already running on this node`)}else this.notify("started","Download started",`${e.name} → ${U(e)}`);(function(e,t){return!!e&&e!==t&&/ \(\d+\)(\.[^.]*)?$/.test(t)})(t,e.name)&&this.notify("renamed",`Saved as ${e.name}`,`A file named ${t} was already in ${U(e)}`)}else{const t=e.reason??"The node refused this download.";!function(e){return!!e&&/not enough (disk )?space|disk (is )?full|needs [\d.]+ ?[kmgt]?b\b.*\bfree\b/i.test(e)}(t)?!this.dialogOpen&&this.compact||(this.refusal={tone:"err",title:"Refused",body:t}):this.confirm={kind:"space",reason:t}}}clearStarting(){this.starting?.silence&&window.clearTimeout(this.starting.silence),this.starting=null}emitCount(){this.activeCount.emit({n:Object.values(this.jobs).filter(I).length})}notify(e,t,n,o,s=!1){const i=this.noticeId++;this.notices=[...this.notices.slice(-2),{id:i,kind:e,title:t,detail:n,action:o,sticky:s}],s||this.noticeTimers.set(i,window.setTimeout((()=>this.dismiss(i)),6e3))}dismiss(e){const t=this.noticeTimers.get(e);t&&(window.clearTimeout(t),this.noticeTimers.delete(e)),this.notices=this.notices.filter((t=>t.id!==e))}showRetrying(){this.tab="retrying",this.drawerOpen=!0}async openFetch(e){void 0!==e&&e!==this.browsingPath&&(this.browsingPath=e),this.drawerOpen=!0,this.unread=0,this.dialogOpen=!0,this.refusal=null,this.askWhere()}async toggleDrawer(e){this.drawerOpen=e??!this.drawerOpen,this.drawerOpen&&(this.unread=0)}async jobForPath(e){const t=Object.values(this.jobs).find((t=>!P(t.state)&&"Cancelled"!==t.state&&function(e){return`${B(U(e),e.name)}.phirepass-part`}(t)===e));return t?{download_id:t.download_id,name:t.name}:null}async deleteDownload(e,t=!1){const n=this.jobs[e];n&&this.sendDelete(n,t)}async torrentPathFor(e){const t=this.caps?.folder;if(!t||!this.caps?.torrents||!/\.torrent$/i.test(e)||E(this.caps,this.name,this.canConfigure))return null;const n=t.endsWith("/")?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):null}async startTorrentPath(e,t=!1){const n=await this.torrentPathFor(e),o=this.ch;if(null===n||!x(o))return!1;const s=this.nextMsgId();this.starting={msgId:s,askedName:n.split("/").pop()?.replace(/\.torrent$/i,"")};const i=n.includes("/")?n.slice(0,n.lastIndexOf("/")):null;return o.send_download_start(this.nodeId,{TorrentPath:{path:n}},i,null,t,{source_auth:null,ignore_window:!1},s),this.drawerOpen=!0,!0}nextMsgId(){return this.msgId=this.msgId>=4294967280?y:this.msgId+1,this.msgId}browsing(){return this.compact&&this.browsingService&&this.browsingPath?{service_id:this.browsingService,path:this.browsingPath}:null}askWhere(){const e=this.browsing(),t=this.ch;e&&x(t)&&"ready"===this.connection&&(this.whereMsgId=this.nextMsgId(),t.send_download_where(this.nodeId,e,this.whereMsgId))}destination(){if(this.browsing())return this.where?this.where.mapped?{path:this.where.saves_to}:{path:this.where.saves_to,hint:`This folder is outside ${this.name}'s download folder. The file will be saved to ${this.where.saves_to}.`}:{path:this.browsingPath,hint:"Asking the node where this lands…"};const e=this.caps?.folder;return e?{path:B(e,this.subDir)}:null}formReady(){return!(this.starting||"ready"!==this.connection||this.browsing()&&!this.where)}async pickTorrent(e){const t=function(e){const t=function(e){return/\.torrent$/i.test(e.name)?e.size>2097152?{ok:!1,reason:"too-large"}:{ok:!0}:{ok:!1,reason:"not-torrent"}}(e);return t.ok?{name:e.name,size:e.size}:{name:e.name,size:e.size,error:t.reason}}(e);t.error||(t.contents=new Uint8Array(await e.arrayBuffer())),this.form={...this.form,torrent:t,text:"",order:null},this.refusal=null}start(e=!1){const t=F(this.form,this.caps,this.formReady()),n=function(e){const t={source_auth:null,ignore_window:!1};if(e.torrent)return!e.torrent.contents||e.torrent.error?null:{source:{TorrentFile:{name:e.torrent.name,contents:e.torrent.contents}},inOrder:"in"===e.order,options:t};const n=$(e.text);if("magnet"===n.kind)return{source:{Magnet:{uri:n.uri}},inOrder:"in"===e.order,options:t};if("http"===n.kind||"torrent-url"===n.kind){const o=e.authOpen?D(e.auth):{auth:null};if("error"in o&&o.error)return null;const s=e.saveAs.trim();return{source:{Http:{url:n.url,save_as:s||null}},inOrder:!0,options:{...t,source_auth:o.auth}}}return null}(this.form),o=this.ch;if(!t.canStart||!n||!x(o))return;if(t.isTorrent&&!this.torrentAcked&&!e)return void(this.confirm={kind:"torrent",dontAsk:!1});const s=this.nextMsgId(),i=t.askedName??(this.form.torrent?this.form.torrent.name.replace(/\.torrent$/i,""):"magnet"===t.detected.kind?function(e){const t=/urn:btih:([a-z0-9]+)/i.exec(e);if(!t)return e.length>40?`${e.slice(0,37)}…`:e;const n=t[1];return`magnet:?xt=urn:btih:${n.slice(0,4)}…${n.slice(-4)}`}(t.detected.uri):void 0);this.starting={msgId:s,askedName:i},this.refusal=null;const r=this.browsing();o.send_download_start(this.nodeId,n.source,r?null:this.subDir,r,n.inOrder,n.options,s)}closeDialog(e=!1){this.dialogOpen=!1,this.refusal=null,e&&(this.form=z,this.drawerOpen=!0)}sendStop(e,t){const n=this.ch;x(n)&&n.send_download_stop(e.download_id,t,this.nextMsgId())}sendDelete(e,t){const n=this.ch;x(n)&&(n.send_download_delete(e.download_id,t,this.nextMsgId()),this.jobs={...this.jobs,[e.download_id]:{...e,deleting:!0}})}actions={play:e=>this.playRow(e),pause:e=>this.sendStop(e,!1),resume:(e,t=!1)=>{const n=this.ch;x(n)&&n.send_download_resume(e.download_id,t,this.nextMsgId())},stop:e=>this.confirm={kind:"stop",row:e,discard:!1},remove:e=>{"Completed"===e.state||"Seeding"===e.state||"Stopped"===e.state?this.confirm={kind:"delete",row:e,deleteFile:!1}:this.sendDelete(e,!1)},setOrder:(e,t)=>{t||this.player?.downloadId!==e.download_id?this.sendOrder(e,t):this.confirm={kind:"fastest",row:e}},showInFolder:e=>this.showInFolder.emit({path:U(e),name:e.name})};sendOrder(e,t){const n=this.ch;x(n)&&n.send_download_set_order(e.download_id,t,this.nextMsgId())}playRow(e){const t=M(e);if(!t.play||!t.file)return;const n=(o=this.streamBase||this.defaultStreamBase(),s=this.nodeId,i=e.download_id,r=t.file.index,`${o.replace(/\/+$/,"")}/api/web/stream/${encodeURIComponent(s)}/${encodeURIComponent(i)}/${r}`);var o,s,i,r;!this.play.emit({src:n,name:t.file.name,downloadId:e.download_id}).defaultPrevented&&this.inlinePlayer&&(this.player={src:n,name:t.file.name,downloadId:e.download_id})}clearFinished(){Object.values(this.jobs).filter(R).forEach((e=>this.sendDelete(e,!1)))}canPickFolder(){return!!this.caps?.folder&&"function"==typeof this.ch?.send_download_folders}listFolders(e){const t=this.nextMsgId();this.picker={path:e,folders:null,msgId:t,newName:null},this.ch?.send_download_folders?.(this.nodeId,e.length?e.join("/"):null,t)}savePicker(){if(!this.picker)return;const e=[...this.picker.path],t=this.picker.newName?.trim();t&&e.push(t),this.subDir=e.length?e.join("/"):null,this.picker=null}renderConfirm(){const t=this.confirm;if(!t)return null;const n=()=>this.confirm=null;switch(t.kind){case"stop":return e(q,{row:t.row,discard:t.discard,onDiscard:e=>this.confirm={...t,discard:e},onCancel:n,onConfirm:()=>{this.sendStop(t.row,t.discard),this.confirm=null}});case"delete":return e(L,{row:t.row,nodeName:this.name,deleteFile:t.deleteFile,onDeleteFile:e=>this.confirm={...t,deleteFile:e},onCancel:n,onConfirm:()=>{this.sendDelete(t.row,t.deleteFile),this.confirm=null}});case"fastest":return e(Q,{row:t.row,onCancel:n,onConfirm:()=>{this.player=null,this.sendOrder(t.row,!1),this.confirm=null}});case"torrent":return e(H,{nodeName:this.name,dontAsk:t.dontAsk,onDontAsk:e=>this.confirm={...t,dontAsk:e},onCancel:n,onConfirm:()=>{t.dontAsk&&(function(){try{window.localStorage.setItem(fe,"1")}catch{}}(),this.torrentAcked=!0),this.confirm=null,this.start(!0)}});case"space":return e(K,{reason:t.reason,onClose:n})}}renderForm(t){const n=this.caps?E(this.caps,this.name,this.canConfigure):null,o=()=>this.openNodeSettings.emit({nodeId:this.nodeId});if(n)return"dialog"===t?e("div",{class:"dlg"},e("div",{class:"dlg-h"},e(g,{name:"fetch"}),e("h4",null,"Fetch into this folder")),e(ue,{blocker:n,onAction:o,onClose:()=>this.closeDialog()})):e(ue,{blocker:n,onAction:o});const s=F(this.form,this.caps,this.formReady());return e(ee,{form:this.form,model:s,caps:this.caps,layout:t,title:this.browsing()?"Fetch into this folder":"Add download",destination:"dialog"===t||this.browsing()?this.destination():null,starting:!!this.starting,refusal:this.refusal,onChange:e=>{this.form={...this.form,...e},("text"in e||"torrent"in e)&&(this.refusal=null)},onAuth:e=>this.form={...this.form,auth:{...this.form.auth,...e}},onPickTorrent:e=>{this.pickTorrent(e)},onStart:()=>this.start(),onCancel:()=>this.closeDialog()})}renderRows(t){const n=t.filter((e=>"Downloading"===e.state)).length;return e("div",{class:"jobs",role:"list"},function(e){return[...e].sort(((e,t)=>N[e.state]-N[t.state]||(t.finished_at??t.started_at)-(e.finished_at??e.started_at)))}(t).map((t=>e(oe,{row:t,actions:this.actions,running:n,compact:this.compact}))))}renderStatus(){switch(this.connection){case"unsupported":return e(he,null);case"signed-out":return e(de,{onSignIn:()=>this.signIn.emit()});case"unreachable":return e(ce,{nodeName:this.name,onRetry:()=>this.reconnect()});case"connecting":return e(pe,null);default:return null}}renderCompact(){const t=Object.values(this.jobs),n=A(t),o=this.renderStatus();if("unsupported"===this.connection)return null;const s=t.some(R),i=!this.drawerOpen&&(n.active>0||this.unread>0),r=[`${n.active} active`,null===n.percent||this.drawerOpen?"":`${Math.round(n.percent)}%`,u(n.downBps)].filter(Boolean).join(" · ");return[this.drawerOpen&&e("section",{class:"drawer","aria-label":"Transfers"},e("div",{class:"drawer-h"},e("h4",null,"Transfers"),e("span",{class:"sum"},r),e("span",{class:"sp"}),s&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished"),e("button",{type:"button",class:"ib","aria-label":"Collapse transfers",title:"Collapse",onClick:()=>this.drawerOpen=!1},e(g,{name:"chevron",size:12}))),e("div",{class:"drawer-b"},o??(t.length?this.renderRows(t):e(ae,null)))),i&&e("button",{type:"button",class:"strip","aria-label":"Show transfers",onClick:()=>this.toggleDrawer(!0)},e("h4",null,"Transfers"),e("span",{class:"bar"},e("i",{style:{width:`${n.percent??0}%`}})),e("span",{class:"sum"},this.unread&&!n.active?`${this.unread} finished`:r),e(g,{name:"up",size:12})),this.dialogOpen&&e(V,{label:"Fetch into this folder",onClose:()=>this.closeDialog()},o&&"ready"!==this.connection?e("div",{class:"dlg"},o,e("div",{class:"dlg-f"},e("button",{type:"button",class:"btn",onClick:()=>this.closeDialog()},"Close"))):this.renderForm("dialog"))]}renderStandalone(){const t=this.renderStatus(),n=Object.values(this.jobs),o={active:[],finished:[],retrying:[]};n.forEach((e=>{return o[(t=e,"Retrying"===t.state?"retrying":T.has(t.state)?"active":"finished")].push(e);var t}));const s=A(n),i=o[this.tab],r=this.caps?.folder?B(this.caps.folder,this.subDir):null;return e("section",{class:"standalone"},e("header",{class:"sa-head"},e("div",{class:"sa-title"},e("h3",null,"Downloads"),e("span",{class:"node"},this.name),s.downBps>0&&e("span",{class:"sum"},u(s.downBps))),r&&e("span",{class:"saving"},"saving to ",e("code",null,r),this.caps&&this.caps.folder_free_bytes>0&&e("span",{class:"free"}," · ",h(this.caps.folder_free_bytes)," free"))),t??[e("div",{class:"sa-add"},this.renderForm("inline"),r&&!E(this.caps,this.name,this.canConfigure)&&e("div",{class:"sa-dest"},e("span",{class:"dest"},e(g,{name:"folder",size:14}),e("span",null,r)),this.canPickFolder()&&e("button",{type:"button",class:"btn",onClick:()=>this.listFolders(this.subDir?this.subDir.split("/"):[])},"Choose folder…"))),e("div",{class:"tabs",role:"tablist","aria-label":"Downloads"},[["active","Active"],["finished","Finished"],["retrying","Retrying"]].map((([t,n])=>e("button",{type:"button",role:"tab","aria-selected":this.tab===t?"true":"false",class:{on:this.tab===t},onClick:()=>this.tab=t},n,e("b",null,o[t].length))))),"finished"===this.tab&&o.finished.length>0&&e("div",{class:"tab-h"},e("span",null,o.finished.length," finished"),o.finished.some(R)&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished")),i.length?this.renderRows(i):0===n.length?e(le,{nodeName:this.name,folder:r}):e("div",{class:"muted pad"},"retrying"===this.tab?"Nothing is retrying.":"finished"===this.tab?"Nothing has finished yet.":"Nothing is running.")])}render(){return e(i,{key:"6a7316df730c5bc4bc588f7d05e19033d98a9d0a",class:{compact:this.compact,standalone:!this.compact}},this.compact?this.renderCompact():this.renderStandalone(),this.renderConfirm(),this.picker&&e(Y,{key:"412dc8107ea30420f022a49f188ea020eabd46f5",root:this.caps?.folder??"",path:this.picker.path,folders:this.picker.folders,error:this.picker.error,newName:this.picker.newName,onOpen:e=>this.listFolders([...this.picker.path,e]),onUp:e=>this.listFolders(this.picker.path.slice(0,e)),onNewName:e=>this.picker={...this.picker,newName:e},onCancel:()=>this.picker=null,onSave:()=>this.savePicker()}),this.player&&e("div",{key:"61bc6c3ab32346d87c0ed02280182fdae234eb71",class:"overlay player"},e("phirepass-media-player",{key:"59d99ac6289a146ba106e9cb8682d5f7b4383e26",src:this.player.src,name:this.player.name,status:this.playerStatus(),ready:this.playerReady(),positionKey:`dl:${this.player.downloadId}`,onPhirepassPlayerClose:()=>this.player=null})),e(ie,{key:"fa27f16c8f72435939e51b48d92b6f10b0535d80",notices:this.notices,onDismiss:e=>this.dismiss(e)}))}playerRow(){return this.player?this.jobs[this.player.downloadId]:void 0}playerStatus(){const e=this.playerRow();if(!e)return this.player?"On the node":void 0;if(P(e.state))return"On the node";const t=e.total_bytes?` · ${(e.done_bytes/e.total_bytes*100).toFixed(1)}%`:"";return`${"Downloading"===e.state?"Downloading":e.state}${t}`}playerReady(){const e=this.playerRow();if(!e||P(e.state))return;const t=M(e);return t.file?.ready_from_start}static get watchers(){return{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}}static get style(){return":host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--destructive:0 70% 50%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;--blue:206 72% 63%;--radius:0.375rem;display:block;color:hsl(var(--foreground));font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;container-type:inline-size}:host(.standalone){position:relative;height:100%;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:var(--radius);overflow:auto}:host(.compact){flex:none}*{box-sizing:border-box}button{font:inherit;color:inherit;cursor:pointer}button:disabled{cursor:not-allowed}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.hidden-input{display:none}.mono,code,.stats,.sum,.inp,.dest,.detect .host{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace}code{font-size:12px}.muted{color:hsl(var(--muted-foreground))}.pad{padding:18px 14px}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));flex:none;padding:0}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4}.ib.new{color:hsl(var(--primary));border-color:hsl(var(--primary) / 0.55);background:hsl(var(--primary) / 0.12)}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));white-space:nowrap;display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:hsl(var(--foreground))}.btn:hover:not(:disabled){border-color:hsl(var(--muted-foreground))}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.btn.dng{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:#fff}.btn:disabled{opacity:0.45}.lnk{background:none;border:0;color:hsl(var(--muted-foreground));font-size:11px;padding:2px 4px;display:inline-flex;align-items:center;gap:4px}.lnk:hover{color:hsl(var(--foreground))}.lnk.inline{color:hsl(var(--primary));padding:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;flex:none}.pill.dl{background:hsl(var(--primary) / 0.18);color:hsl(var(--primary))}.pill.meta,.pill.sd{background:hsl(var(--blue) / 0.18);color:hsl(var(--blue))}.pill.mv{background:hsl(var(--amber) / 0.18);color:hsl(var(--amber))}.pill.ok{background:hsl(var(--primary));color:hsl(var(--primary-foreground))}.pill.err{background:hsl(var(--destructive) / 0.2);color:hsl(var(--destructive))}.pill.ps,.pill.q{background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.bar{display:block;height:5px;border-radius:3px;background:hsl(var(--muted));overflow:hidden;position:relative}.bar i{display:block;height:100%;background:hsl(var(--primary));border-radius:3px;transition:width 0.6s linear}.bar.indet i{width:30% !important;animation:slide 1.3s ease-in-out infinite;background:hsl(var(--blue))}.bar.paused i{background:hsl(var(--muted-foreground))}.bar.fail i{background:hsl(var(--destructive))}.bar.moving i{background:hsl(var(--amber))}.bar.seed i{background:hsl(var(--blue))}@keyframes slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}.jobs{display:flex;flex-direction:column}.job{display:grid;grid-template-columns:28px minmax(0, 1fr) auto;gap:4px 10px;padding:10px 12px;border-bottom:1px solid hsl(var(--border) / 0.6);align-items:center}.job:last-child{border-bottom:0}.job .kind{grid-row:span 3;align-self:start;width:28px;height:28px;border-radius:6px;display:grid;place-items:center;background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.job .kind.t{color:hsl(var(--blue))}.job .kind.h{color:hsl(var(--primary))}.job .kind.n{color:hsl(var(--amber))}.job .title{display:flex;gap:8px;align-items:center;min-width:0}.job .title .nm{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.job .acts{display:flex;gap:2px;grid-row:1;grid-column:3}.job .bar,.job .stats{grid-column:2 / 4}.stats{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:11px;color:hsl(var(--muted-foreground));font-variant-numeric:tabular-nums}.stats b{color:hsl(var(--foreground));font-weight:500}.stats .err{color:hsl(var(--destructive))}.job[data-state='Deleting']{opacity:0.6}.drawer{border-top:1px solid hsl(var(--border));background:hsl(var(--bg));display:flex;flex-direction:column;max-height:min(46vh, 380px)}.drawer-h{display:flex;align-items:center;gap:10px;padding:6px 12px;border-bottom:1px solid hsl(var(--border));flex:none}.drawer-h h4,.strip h4{margin:0;font-size:12px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase}.sum{color:hsl(var(--muted-foreground));font-size:11px;font-variant-numeric:tabular-nums}.sp{flex:1}.drawer-b{overflow:auto;min-height:0}.strip{display:flex;align-items:center;gap:10px;padding:7px 12px;border:0;border-top:1px solid hsl(var(--border));background:hsl(var(--bg));width:100%;text-align:left}.strip .bar{flex:1 1 120px}.overlay{position:absolute;inset:0;background:rgba(5, 7, 9, 0.6);display:grid;place-items:center;padding:14px;z-index:20}:host(.standalone) .overlay{position:fixed}.modal{width:min(100%, 420px);max-height:100%;overflow:auto;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:8px;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}.modal.wide{width:min(100%, 480px)}.dlg,.fetch-form.dialog{padding:16px;display:flex;flex-direction:column;gap:14px}.dlg h4,.dlg-h h4{margin:0;font-size:14px;font-weight:600}.dlg-h{display:flex;align-items:center;gap:10px;color:hsl(var(--primary))}.dlg-h h4{color:hsl(var(--foreground))}.dlg-f{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}.dlg-f .left{margin-right:auto}.dtx{margin:0;font-size:13px}.hint{font-size:11px;color:hsl(var(--muted-foreground));margin:0}.hint.block{display:block;margin-top:2px}.hint.err{color:hsl(var(--destructive))}.hint.where{color:hsl(var(--amber))}.fld{display:flex;flex-direction:column;gap:6px;min-width:0}.fld>label,.fld>span:first-child,legend{font-size:11px;text-transform:uppercase;letter-spacing:0.05em;color:hsl(var(--muted-foreground))}.inp{width:100%;min-width:0;background:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:4px;color:hsl(var(--foreground));padding:8px 10px;font-size:12px}.inp:focus{outline:none;border-color:hsl(var(--primary))}.inline-row{display:flex;gap:8px;align-items:stretch}.detect{display:flex;align-items:center;gap:8px;font-size:12px;color:hsl(var(--muted-foreground));min-height:20px;min-width:0}.detect .host{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.note{display:flex;gap:8px;align-items:flex-start;font-size:12px;line-height:1.45;padding:8px 10px;border-radius:4px;border:1px solid hsl(var(--border));background:hsl(var(--muted))}.note svg{flex:none;margin-top:2px}.note.err{border-color:hsl(var(--destructive) / 0.5)}.note.err svg{color:hsl(var(--destructive))}.note.warn{border-color:hsl(var(--amber) / 0.5)}.note.warn svg{color:hsl(var(--amber))}.note.info svg{color:hsl(var(--primary))}.or{display:flex;align-items:center;gap:10px;color:hsl(var(--muted-foreground));font-size:11px;text-transform:uppercase;letter-spacing:0.06em}.or::before,.or::after{content:'';flex:1;height:1px;background:hsl(var(--border))}.drop{border:1px dashed hsl(var(--border));border-radius:6px;padding:14px;display:flex;align-items:center;gap:12px;color:hsl(var(--muted-foreground));font-size:12px;background:transparent;text-align:left}.drop svg{color:hsl(var(--blue));flex:none}.drop b{color:hsl(var(--foreground));font-weight:500}.filechip{display:flex;gap:10px;align-items:center;padding:10px;border:1px solid hsl(var(--border));border-radius:4px;background:hsl(var(--muted))}.filechip>svg{color:hsl(var(--blue));flex:none}.filechip>div{flex:1;min-width:0}.filechip b{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.filechip span{color:hsl(var(--muted-foreground));font-size:11px}.filechip.bad{border-color:hsl(var(--destructive) / 0.55)}.filechip.bad>svg{color:hsl(var(--destructive))}.dest-row,.sa-dest{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.dest{display:flex;align-items:center;gap:8px;background:hsl(var(--bg));border:1px solid hsl(var(--border));border-radius:4px;padding:7px 10px;font-size:12px;min-width:0;flex:1 1 200px}.dest span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dest svg{color:hsl(var(--primary));flex:none}fieldset.order{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}fieldset.order legend{margin-bottom:6px}.opt{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border:1px solid hsl(var(--border));border-radius:4px;font-size:12px;cursor:pointer}.opt.on{border-color:hsl(var(--primary));background:hsl(var(--primary) / 0.08)}.opt input,.checkline input,.seg input{accent-color:hsl(var(--primary));margin:2px 0 0}.checkline{display:flex;gap:8px;align-items:flex-start;font-size:12px;cursor:pointer}.login{display:flex;flex-direction:column;gap:8px}.login>.lnk{align-self:flex-start;padding-left:0}.auth{display:flex;flex-direction:column;gap:10px;padding:10px;border:1px solid hsl(var(--border));border-radius:4px}.seg{display:flex;flex-wrap:wrap;gap:6px}.seg label{display:flex;gap:6px;align-items:center;font-size:11px;padding:4px 8px;border:1px solid hsl(var(--border));border-radius:999px;cursor:pointer}.seg label.on{border-color:hsl(var(--primary));color:hsl(var(--primary))}.seg input{margin:0}.crumbs{display:flex;flex-wrap:wrap;align-items:center;gap:2px;font-family:ui-monospace, SFMono-Regular, Menlo, monospace}.crumbs .lnk{font-size:12px}.crumbs .sep{color:hsl(var(--muted-foreground))}.folders{display:flex;flex-direction:column;border:1px solid hsl(var(--border));border-radius:4px;max-height:220px;overflow:auto}.folders .muted{padding:10px}.folder-row{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-bottom:1px solid hsl(var(--border) / 0.6);background:transparent;text-align:left;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px}.folder-row:hover{background:hsl(var(--muted))}.folder-row svg{color:hsl(var(--primary))}.blocker{display:flex;flex-direction:column;gap:10px}.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:30px 20px}.empty>svg{color:hsl(var(--muted-foreground))}.empty b{font-size:14px;font-weight:600}.empty span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.spin{width:22px;height:22px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.standalone{display:flex;flex-direction:column;min-height:100%}.sa-head{padding:14px 16px 10px;display:flex;flex-direction:column;gap:4px}.sa-title{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.sa-title h3{margin:0;font-size:16px;font-weight:600}.sa-title .node{color:hsl(var(--muted-foreground))}.saving{font-size:12px;color:hsl(var(--muted-foreground))}.sa-add{padding:0 16px 14px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid hsl(var(--border))}.fetch-form.inline{display:flex;flex-direction:column;gap:10px}.tabs{display:flex;gap:4px;padding:0 10px;border-bottom:1px solid hsl(var(--border));overflow-x:auto}.tabs button{padding:9px 10px;font-size:12px;color:hsl(var(--muted-foreground));border:0;border-bottom:2px solid transparent;background:none;white-space:nowrap}.tabs button.on{color:hsl(var(--foreground));border-bottom-color:hsl(var(--primary))}.tabs b{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-weight:500;color:hsl(var(--muted-foreground));margin-left:6px}.tab-h{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;font-size:12px;color:hsl(var(--muted-foreground));border-bottom:1px solid hsl(var(--border) / 0.6)}.toasts{position:absolute;left:12px;right:12px;bottom:12px;display:flex;flex-direction:column;gap:8px;z-index:30;pointer-events:none;align-items:flex-end}:host(.standalone) .toasts{position:sticky;margin:12px}.toast{pointer-events:auto;display:flex;gap:10px;align-items:center;padding:10px 12px;background:hsl(var(--bg));border:1px solid hsl(var(--primary) / 0.5);border-radius:6px;width:min(100%, 420px);box-shadow:0 12px 30px -12px rgba(0, 0, 0, 0.7)}.toast>svg{color:hsl(var(--primary));flex:none}.toast.bad{border-color:hsl(var(--destructive) / 0.55)}.toast.bad>svg{color:hsl(var(--destructive))}.toast .t{flex:1;min-width:0}.toast .t b{display:block;font-weight:600}.toast .t span{color:hsl(var(--muted-foreground));font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block}.overlay.player{padding:10px}.overlay.player phirepass-media-player{width:min(100%, 880px)}@container (max-width: 480px){.job{padding:9px 10px}.job .title .pill.meta{display:none}.inline-row{flex-wrap:wrap}.inline-row .inp{flex-basis:100%}.inline-row .btn.pri{flex:1;justify-content:center}.stats{gap:2px 10px}}@media (prefers-reduced-motion: reduce){.bar i{transition:none}.bar.indet i{animation:none;width:100% !important;opacity:0.5}.spin{animation:none}}"}},[513,"phirepass-downloader",{nodeId:[1,"node-id"],nodeLabel:[1,"node-label"],token:[1],channel:[16],connected:[4],channelFactory:[16],browsingService:[1,"browsing-service"],browsingPath:[1025,"browsing-path"],compact:[516],streamBase:[1,"stream-base"],canConfigure:[4,"can-configure"],inlinePlayer:[4,"inline-player"],serverHost:[1,"server-host"],serverPort:[2,"server-port"],serverId:[1,"server-id"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],connection:[32],caps:[32],jobs:[32],tab:[32],drawerOpen:[32],dialogOpen:[32],unread:[32],form:[32],where:[32],starting:[32],refusal:[32],confirm:[32],notices:[32],subDir:[32],picker:[32],player:[32],receive:[64],openFetch:[64],toggleDrawer:[64],jobForPath:[64],deleteDownload:[64],torrentPathFor:[64],startTorrentPath:[64]},void 0,{channel:[{onChannel:0}],connected:[{onConnected:0}],browsingPath:[{onBrowsing:0}],browsingService:[{onBrowsing:0}],nodeId:[{onNode:0}]}]);function ge(){"undefined"!=typeof customElements&&["phirepass-downloader","phirepass-media-player"].forEach((e=>{switch(e){case"phirepass-downloader":customElements.get(t(e))||customElements.define(t(e),be);break;case"phirepass-media-player":customElements.get(t(e))||w()}}))}ge();export{y as D,be as P,ge as d,C as i,x as s}