phirepass-widgets 0.0.115 → 0.0.117

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 (36) hide show
  1. package/README.md +13 -12
  2. package/dist/cjs/{index-BCgmMoIq.js → index-DehquNXP.js} +1 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/phirepass-downloader_3.cjs.entry.js +20 -9
  5. package/dist/cjs/phirepass-rdp.cjs.entry.js +2 -2
  6. package/dist/cjs/phirepass-terminal.cjs.entry.js +2 -2
  7. package/dist/cjs/phirepass-widgets.cjs.js +2 -2
  8. package/dist/cjs/{protocol-CYh109n2.js → protocol-BjOgJZ9-.js} +34 -9
  9. package/dist/collection/collection-manifest.json +1 -1
  10. package/dist/collection/components/phirepass-downloader/phirepass-downloader.js +18 -7
  11. package/dist/collection/phirepass-channel_bg.wasm +0 -0
  12. package/dist/components/{p-DqT-qhTU.js → p-B4kFfbHE.js} +1 -1
  13. package/dist/components/p-BekUePpu.js +1 -0
  14. package/dist/components/phirepass-downloader.js +1 -1
  15. package/dist/components/phirepass-rdp.js +1 -1
  16. package/dist/components/phirepass-sftp-client.js +1 -1
  17. package/dist/components/phirepass-terminal.js +4 -4
  18. package/dist/esm/{index-Dd9o0CbU.js → index-BinptKL7.js} +1 -1
  19. package/dist/esm/loader.js +2 -2
  20. package/dist/esm/phirepass-downloader_3.entry.js +20 -9
  21. package/dist/esm/phirepass-rdp.entry.js +2 -2
  22. package/dist/esm/phirepass-terminal.entry.js +2 -2
  23. package/dist/esm/phirepass-widgets.js +3 -3
  24. package/dist/esm/{protocol-BtMWUitf.js → protocol-BekUePpu.js} +33 -8
  25. package/dist/phirepass-widgets/p-6a192c8d.entry.js +1 -0
  26. package/dist/phirepass-widgets/{p-705501d4.entry.js → p-9e6f9220.entry.js} +4 -4
  27. package/dist/phirepass-widgets/p-BekUePpu.js +1 -0
  28. package/dist/phirepass-widgets/{p-2fd32ec5.entry.js → p-fe1ce8da.entry.js} +1 -1
  29. package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
  30. package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
  31. package/dist/types/components/phirepass-downloader/phirepass-downloader.d.ts +7 -0
  32. package/package.json +9 -9
  33. package/dist/components/p-BtMWUitf.js +0 -1
  34. package/dist/phirepass-widgets/p-BtMWUitf.js +0 -1
  35. package/dist/phirepass-widgets/p-b8caf9e1.entry.js +0 -1
  36. /package/dist/phirepass-widgets/{p-Dd9o0CbU.js → p-BinptKL7.js} +0 -0
@@ -1 +1 @@
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-DIf-Ru26.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 R=new Set(["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused","Stopped","Unknown"]);function T(e){return"Stopped"===e.state&&"Torrent"===e.kind&&!!e.seeding_since}function I(e){return["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused"].includes(e.state)}function N(e){return("Completed"===e.state||"Cancelled"===e.state)&&!e.deleting}const A={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 j(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 O=/\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;function M(e){return O.test(e)}function B(e){const t=function(e){const t=e.files.filter((e=>e.media||M(e.name)));return t.length?t.reduce(((e,t)=>t.size>e.size?t:e)):!e.files.length&&M(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&&!T(e)}:{play:!1,file:null,switchToInOrder:!1}}function U(...e){const t=e.filter((e=>!!e)).join("/").replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/+$/,""):t}function E(e){return U(e.dest_root,e.sub_dir)}function V(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 W=({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)),q=({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)),L=({row:t,discard:n,onDiscard:o,...s})=>e(W,{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(q,{cancel:"Keep downloading",confirm:"Stop download",danger:!0,...s}))),Q=({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(W,{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 ",E(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 ",E(t)," and only the download is removed."))):e("p",{class:"dtx"},"The part already downloaded is deleted."),e(q,{cancel:"Cancel",confirm:"Delete",danger:!0,...i})))},H=({row:t,...n})=>e(W,{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(q,{cancel:"Keep in order",confirm:"Switch and stop playback",danger:!0,...n}))),K=({nodeName:t,dontAsk:n,onDontAsk:o,...s})=>e(W,{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(q,{cancel:"Cancel",confirm:"Start torrent",...s}))),Y=({reason:t,onClose:n})=>e(W,{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")))),X=t=>e(W,{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")))),Z=({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 G({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 J=({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."))},ee=({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"))),te=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(G,{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(Z,{note:o.note}),t.refusal&&e(Z,{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(J,{auth:n.auth,onChange:t.onAuth}),o.authError&&e("span",{class:"hint err",role:"alert"},o.authError)),o.needsOrder&&e(ee,{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 ne(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 oe=({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})),se=({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:T(e)?"Seeding paused":"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=B(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":if(T(e)){r(`${h(e.up_total)} uploaded`),r(e.reason??"Seeding paused by you"),r("Resume shares it again");break}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(oe,{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(oe,{icon:"pause",label:"Pause",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Scheduled":case"Paused":"Scheduled"!==t.state&&"Window"!==t.pause_reason||y.push(e(oe,{icon:"play",label:"Start now",onClick:()=>n.resume(t,!0)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Retrying":y.push(e(oe,{icon:"retry",label:"Try now",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Stopped":y.push(e(oe,{icon:"play",label:"Resume",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Seeding":y.push(e(oe,{icon:"pause",label:"Pause seeding",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Completed":y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}));break;case"Cancelled":y.push(e(oe,{icon:"retry",label:"Start again",onClick:()=>n.resume(t)})),y.push(e(oe,{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:ne(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")))},ie={started:"fetch",queued:"fetch",stuck:"warn",renamed:"file",completed:"check",error:"warn"},re=({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:ie[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,ae=({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)),le=()=>e(ae,{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."}),de=({nodeName:t,folder:n})=>e(ae,{icon:"fetch",title:"Nothing downloading",body:`Paste a link above. It downloads onto ${t}${n?`, into ${n}`:""}.`}),ce=({onSignIn:t})=>e(ae,{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}}),he=({nodeName:t,onRetry:n})=>e(ae,{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}),pe=()=>e(ae,{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."}),ue=()=>e("div",{class:"empty",role:"status"},e("span",{class:"spin","aria-hidden":"true"}),e("span",null,"Loading downloads…")),fe=({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))),be="phirepass.downloader.torrent-ack",ge=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(be)}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} → ${E(e)}`,{label:"Show",run:()=>this.showInFolder.emit({path:E(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} → ${E(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 ${E(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`${U(E(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)||V(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:U(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:E(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=B(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(N).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(L,{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(Q,{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(H,{row:t.row,onCancel:n,onConfirm:()=>{this.player=null,this.sendOrder(t.row,!1),this.confirm=null}});case"torrent":return e(K,{nodeName:this.name,dontAsk:t.dontAsk,onDontAsk:e=>this.confirm={...t,dontAsk:e},onCancel:n,onConfirm:()=>{t.dontAsk&&(function(){try{window.localStorage.setItem(be,"1")}catch{}}(),this.torrentAcked=!0),this.confirm=null,this.start(!0)}});case"space":return e(Y,{reason:t.reason,onClose:n})}}renderForm(t){const n=this.caps?V(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(fe,{blocker:n,onAction:o,onClose:()=>this.closeDialog()})):e(fe,{blocker:n,onAction:o});const s=F(this.form,this.caps,this.formReady());return e(te,{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)=>A[e.state]-A[t.state]||(t.finished_at??t.started_at)-(e.finished_at??e.started_at)))}(t).map((t=>e(se,{row:t,actions:this.actions,running:n,compact:this.compact}))))}renderStatus(){switch(this.connection){case"unsupported":return e(pe,null);case"signed-out":return e(ce,{onSignIn:()=>this.signIn.emit()});case"unreachable":return e(he,{nodeName:this.name,onRetry:()=>this.reconnect()});case"connecting":return e(ue,null);default:return null}}renderCompact(){const t=Object.values(this.jobs),n=j(t),o=this.renderStatus();if("unsupported"===this.connection)return null;const s=t.some(N),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(le,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(W,{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(t)?"finished":R.has(t.state)?"active":"finished")].push(e);var t}));const s=j(n),i=o[this.tab],r=this.caps?.folder?U(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&&!V(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(N)&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished")),i.length?this.renderRows(i):0===n.length?e(de,{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(X,{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(re,{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=B(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 me(){"undefined"!=typeof customElements&&["phirepass-downloader","phirepass-media-player"].forEach((e=>{switch(e){case"phirepass-downloader":customElements.get(t(e))||customElements.define(t(e),ge);break;case"phirepass-media-player":customElements.get(t(e))||w()}}))}me();export{y as D,ge as P,me as d,C as i,x as s}
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-BekUePpu.js";import{f as h,a as c,b as p,c as u,e as f,g as b,I as g,p as m,d as w}from"./p-DIf-Ru26.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,h=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 c;return r?c=e.saveAs.trim()||o.name:"magnet"===o.kind&&(c=o.name),{detected:o,isTorrent:s,needsOrder:d,showSaveAs:"http"===o.kind,showAuth:r,note:a,canStart:h,askedName:c,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 R=new Set(["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused","Stopped","Unknown"]);function T(e){return"Stopped"===e.state&&"Torrent"===e.kind&&!!e.seeding_since}function I(e){return["Queued","Scheduled","Resolving","FetchingMetadata","Downloading","Verifying","Paused"].includes(e.state)}function N(e){return("Completed"===e.state||"Cancelled"===e.state)&&!e.deleting}const A={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 j(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 O=/\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;function M(e){return O.test(e)}function B(e){const t=function(e){const t=e.files.filter((e=>e.media||M(e.name)));return t.length?t.reduce(((e,t)=>t.size>e.size?t:e)):!e.files.length&&M(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&&!T(e)}:{play:!1,file:null,switchToInOrder:!1}}function U(...e){const t=e.filter((e=>!!e)).join("/").replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/+$/,""):t}function E(e){return U(e.dest_root,e.sub_dir)}function V(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 W=({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)),q=({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)),L=({row:t,discard:n,onDiscard:o,...s})=>e(W,{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?`${c(t.done_bytes)} of ${c(t.total_bytes)} downloaded`:`${c(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(q,{cancel:"Keep downloading",confirm:"Stop download",danger:!0,...s}))),Q=({row:t,deleteFile:n,onDeleteFile:o,nodeName:s,...i})=>{const r=P(t.state),a=t.files.length>1?`${t.files.length} files · ${c(t.total_bytes??t.done_bytes)}`:c(t.total_bytes??t.done_bytes);return e(W,{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 ",E(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 ",E(t)," and only the download is removed."))):e("p",{class:"dtx"},"The part already downloaded is deleted."),e(q,{cancel:"Cancel",confirm:"Delete",danger:!0,...i})))},H=({row:t,...n})=>e(W,{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(q,{cancel:"Keep in order",confirm:"Switch and stop playback",danger:!0,...n}))),K=({nodeName:t,dontAsk:n,onDontAsk:o,...s})=>e(W,{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(q,{cancel:"Cancel",confirm:"Start torrent",...s}))),Y=({reason:t,onClose:n})=>e(W,{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")))),X=t=>e(W,{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")))),Z=({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 G({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 J=({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."))},ee=({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"))),te=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,c(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(G,{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(Z,{note:o.note}),t.refusal&&e(Z,{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(J,{auth:n.auth,onChange:t.onAuth}),o.authError&&e("span",{class:"hint err",role:"alert"},o.authError)),o.needsOrder&&e(ee,{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 ne(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 oe=({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})),se=({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:T(e)?"Seeding paused":"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=B(t),v=function(e,t={}){const n=t.now??Date.now(),o=h(e.done_bytes,e.total_bytes),s=e.total_bytes?`${c(e.done_bytes)} of ${c(e.total_bytes)}`:e.done_bytes?c(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(`${c(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(`${c(e.done_bytes)} kept`);break;case"Seeding":r(u(e.up_bps,"↑")),r(`${c(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 · ${c(e.total_bytes??e.done_bytes)}`:c(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 ${c((e.total_bytes??e.done_bytes)/t)}/s`)}break;case"Stopped":if(T(e)){r(`${c(e.up_total)} uploaded`),r(e.reason??"Seeding paused by you"),r("Resume shares it again");break}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(oe,{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(oe,{icon:"pause",label:"Pause",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Scheduled":case"Paused":"Scheduled"!==t.state&&"Window"!==t.pause_reason||y.push(e(oe,{icon:"play",label:"Start now",onClick:()=>n.resume(t,!0)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Retrying":y.push(e(oe,{icon:"retry",label:"Try now",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"x",label:"Stop",onClick:()=>n.stop(t)}));break;case"Stopped":y.push(e(oe,{icon:"play",label:"Resume",onClick:()=>n.resume(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Seeding":y.push(e(oe,{icon:"pause",label:"Pause seeding",onClick:()=>n.pause(t)})),y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"trash",label:"Delete",onClick:()=>n.remove(t)}));break;case"Completed":y.push(e(oe,{icon:"locate",label:"Show in folder",onClick:()=>n.showInFolder(t)})),y.push(e(oe,{icon:"x",label:"Remove from list",onClick:()=>n.remove(t)}));break;case"Cancelled":y.push(e(oe,{icon:"retry",label:"Start again",onClick:()=>n.resume(t)})),y.push(e(oe,{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:ne(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")))},ie={started:"fetch",queued:"fetch",stuck:"warn",renamed:"file",completed:"check",error:"warn"},re=({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:ie[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,ae=({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)),le=()=>e(ae,{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."}),de=({nodeName:t,folder:n})=>e(ae,{icon:"fetch",title:"Nothing downloading",body:`Paste a link above. It downloads onto ${t}${n?`, into ${n}`:""}.`}),he=({onSignIn:t})=>e(ae,{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(ae,{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}),pe=()=>e(ae,{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."}),ue=()=>e("div",{class:"empty",role:"status"},e("span",{class:"spin","aria-hidden":"true"}),e("span",null,"Loading downloads…")),fe=({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))),be="phirepass.downloader.torrent-ack",ge=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(be)}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} → ${E(e)}`,{label:"Show",run:()=>this.showInFolder.emit({path:E(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} → ${E(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 ${E(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`${U(E(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)||V(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:U(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:E(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=B(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(N).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}latest(e){return this.confirm?.kind===e.kind?this.confirm:e}renderConfirm(){const t=this.confirm;if(!t)return null;const n=()=>this.confirm=null;switch(t.kind){case"stop":return e(L,{row:t.row,discard:t.discard,onDiscard:e=>this.confirm={...this.latest(t),discard:e},onCancel:n,onConfirm:()=>{const e=this.latest(t);this.sendStop(e.row,e.discard),this.confirm=null}});case"delete":return e(Q,{row:t.row,nodeName:this.name,deleteFile:t.deleteFile,onDeleteFile:e=>this.confirm={...this.latest(t),deleteFile:e},onCancel:n,onConfirm:()=>{const e=this.latest(t);this.sendDelete(e.row,e.deleteFile),this.confirm=null}});case"fastest":return e(H,{row:t.row,onCancel:n,onConfirm:()=>{this.player=null,this.sendOrder(t.row,!1),this.confirm=null}});case"torrent":return e(K,{nodeName:this.name,dontAsk:t.dontAsk,onDontAsk:e=>this.confirm={...this.latest(t),dontAsk:e},onCancel:n,onConfirm:()=>{this.latest(t).dontAsk&&(function(){try{window.localStorage.setItem(be,"1")}catch{}}(),this.torrentAcked=!0),this.confirm=null,this.start(!0)}});case"space":return e(Y,{reason:t.reason,onClose:n})}}renderForm(t){const n=this.caps?V(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(fe,{blocker:n,onAction:o,onClose:()=>this.closeDialog()})):e(fe,{blocker:n,onAction:o});const s=F(this.form,this.caps,this.formReady());return e(te,{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)=>A[e.state]-A[t.state]||(t.finished_at??t.started_at)-(e.finished_at??e.started_at)))}(t).map((t=>e(se,{row:t,actions:this.actions,running:n,compact:this.compact}))))}renderStatus(){switch(this.connection){case"unsupported":return e(pe,null);case"signed-out":return e(he,{onSignIn:()=>this.signIn.emit()});case"unreachable":return e(ce,{nodeName:this.name,onRetry:()=>this.reconnect()});case"connecting":return e(ue,null);default:return null}}renderCompact(){const t=Object.values(this.jobs),n=j(t),o=this.renderStatus();if("unsupported"===this.connection)return null;const s=t.some(N),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(le,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(W,{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(t)?"finished":R.has(t.state)?"active":"finished")].push(e);var t}));const s=j(n),i=o[this.tab],r=this.caps?.folder?U(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"}," · ",c(this.caps.folder_free_bytes)," free"))),t??[e("div",{class:"sa-add"},this.renderForm("inline"),r&&!V(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(N)&&e("button",{type:"button",class:"lnk",onClick:()=>this.clearFinished()},"Clear finished")),i.length?this.renderRows(i):0===n.length?e(de,{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:"b7f751d7107ff8f00d791e5c54f4261e2d7cd580",class:{compact:this.compact,standalone:!this.compact}},this.compact?this.renderCompact():this.renderStandalone(),this.renderConfirm(),this.picker&&e(X,{key:"538f0f433863e0fbd79a8e66c0b7a45c93a8bd28",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:"b9d3ade696c6079d6a2e3bc2206c19a6bdd7d640",class:"overlay player"},e("phirepass-media-player",{key:"c5fa1244ea9766ff37d08478dbc2d096430f2081",src:this.player.src,name:this.player.name,status:this.playerStatus(),ready:this.playerReady(),positionKey:`dl:${this.player.downloadId}`,onPhirepassPlayerClose:()=>this.player=null})),e(re,{key:"34a34a810001815a890a0995aab44f29f34aab61",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=B(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 me(){"undefined"!=typeof customElements&&["phirepass-downloader","phirepass-media-player"].forEach((e=>{switch(e){case"phirepass-downloader":customElements.get(t(e))||customElements.define(t(e),ge);break;case"phirepass-media-player":customElements.get(t(e))||w()}}))}me();export{y as D,ge as P,me as d,C as i,x as s}
@@ -0,0 +1 @@
1
+ class n{__destroy_into_raw(){const n=this.__wbg_ptr;return this.__wbg_ptr=0,i.unregister(this),n}free(){const n=this.__destroy_into_raw();j.__wbg_channel_free(n,0)}authenticate(n,t,e){const r=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0);let _,o,c,i;try{_=v(n,j.__wbindgen_export,j.__wbindgen_export2),o=T,c=v(t,j.__wbindgen_export,j.__wbindgen_export2),i=T}catch(n){throw c&&j.__wbindgen_export3(c,1*i,1),_&&j.__wbindgen_export3(_,1*o,1),n}j.channel_authenticate(this.__wbg_ptr,_,o,c,i,r)}connect(){j.channel_connect(this.__wbg_ptr)}create_service(n,t,e,r,_,o,c,i,s){const u=+_,a=+(y(s)?Number.MAX_SAFE_INTEGER:s>>>0);let f,b,d,w,l,g,h,m,p,N,A,R,S,O;try{f=v(n,j.__wbindgen_export,j.__wbindgen_export2),b=T,d=v(t,j.__wbindgen_export,j.__wbindgen_export2),w=T,l=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),g=T,h=v(r,j.__wbindgen_export,j.__wbindgen_export2),m=T,p=y(o)?0:v(o,j.__wbindgen_export,j.__wbindgen_export2),N=T,A=y(c)?0:v(c,j.__wbindgen_export,j.__wbindgen_export2),R=T,S=y(i)?0:v(i,j.__wbindgen_export,j.__wbindgen_export2),O=T}catch(n){throw S&&j.__wbindgen_export3(S,1*O,1),A&&j.__wbindgen_export3(A,1*R,1),p&&j.__wbindgen_export3(p,1*N,1),h&&j.__wbindgen_export3(h,1*m,1),l&&j.__wbindgen_export3(l,1*g,1),d&&j.__wbindgen_export3(d,1*w,1),f&&j.__wbindgen_export3(f,1*b,1),n}j.channel_create_service(this.__wbg_ptr,f,b,d,w,l,g,h,m,u,p,N,A,R,S,O,a)}delete_service(n,t,e){const r=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0);let _,o,c,i;try{_=v(n,j.__wbindgen_export,j.__wbindgen_export2),o=T,c=v(t,j.__wbindgen_export,j.__wbindgen_export2),i=T}catch(n){throw c&&j.__wbindgen_export3(c,1*i,1),_&&j.__wbindgen_export3(_,1*o,1),n}j.channel_delete_service(this.__wbg_ptr,_,o,c,i,r)}disconnect(){j.channel_disconnect(this.__wbg_ptr)}is_connected(){return 0!==j.channel_is_connected(this.__wbg_ptr)}is_disconnected(){return 0!==j.channel_is_disconnected(this.__wbg_ptr)}constructor(n,t,e){let r,_,o,c,s,u;try{r=v(n,j.__wbindgen_export,j.__wbindgen_export2),_=T,o=v(t,j.__wbindgen_export,j.__wbindgen_export2),c=T,s=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),u=T}catch(n){throw s&&j.__wbindgen_export3(s,1*u,1),o&&j.__wbindgen_export3(o,1*c,1),r&&j.__wbindgen_export3(r,1*_,1),n}const a=j.channel_new(r,_,o,c,s,u);return this.__wbg_ptr=a,i.register(this,this.__wbg_ptr,this),this}on_connection_close(n){j.channel_on_connection_close(this.__wbg_ptr,y(n)?0:s(n))}on_connection_error(n){j.channel_on_connection_error(this.__wbg_ptr,y(n)?0:s(n))}on_connection_message(n){j.channel_on_connection_message(this.__wbg_ptr,y(n)?0:s(n))}on_connection_open(n){j.channel_on_connection_open(this.__wbg_ptr,y(n)?0:s(n))}on_protocol_message(n){j.channel_on_protocol_message(this.__wbg_ptr,y(n)?0:s(n))}on_protocol_message_type(n,t){const e=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_on_protocol_message_type(this.__wbg_ptr,e,T,y(t)?0:s(t))}open_rdp_tunnel(n,t,e,r,_){const o=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let c,i,s,u,a,f,b,d;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(t,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T,b=y(r)?0:v(r,j.__wbindgen_export,j.__wbindgen_export2),d=T}catch(n){throw b&&j.__wbindgen_export3(b,1*d,1),a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_open_rdp_tunnel(this.__wbg_ptr,c,i,s,u,a,f,b,d,o)}open_sftp_tunnel(n,t,e,r,_){const o=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let c,i,s,u,a,f,b,d;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(t,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T,b=y(r)?0:v(r,j.__wbindgen_export,j.__wbindgen_export2),d=T}catch(n){throw b&&j.__wbindgen_export3(b,1*d,1),a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_open_sftp_tunnel(this.__wbg_ptr,c,i,s,u,a,f,b,d,o)}open_ssh_tunnel(n,t,e,r,_){const o=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let c,i,s,u,a,f,b,d;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(t,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T,b=y(r)?0:v(r,j.__wbindgen_export,j.__wbindgen_export2),d=T}catch(n){throw b&&j.__wbindgen_export3(b,1*d,1),a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_open_ssh_tunnel(this.__wbg_ptr,c,i,s,u,a,f,b,d,o)}send_download_delete(n,t,e){const r=+t,_=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),o=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_delete(this.__wbg_ptr,o,T,r,_)}send_download_resume(n,t,e){const r=+t,_=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),o=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_resume(this.__wbg_ptr,o,T,r,_)}send_download_set_order(n,t,e){const r=+t,_=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),o=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_set_order(this.__wbg_ptr,o,T,r,_)}send_download_settings_get(n,t){const e=+(y(t)?Number.MAX_SAFE_INTEGER:t>>>0),r=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_settings_get(this.__wbg_ptr,r,T,e)}send_download_settings_save(n,t,e){const r=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),_=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_settings_save(this.__wbg_ptr,_,T,t,r)}send_download_start(n,t,e,r,_,o,c){const i=+(y(c)?Number.MAX_SAFE_INTEGER:c>>>0);let s,u,a,f;try{s=v(n,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T}catch(n){throw a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),n}j.channel_send_download_start(this.__wbg_ptr,s,u,t,a,f,r,y(_)?16777215:_?1:0,o,i)}send_download_stop(n,t,e){const r=+t,_=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),o=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_stop(this.__wbg_ptr,o,T,r,_)}send_download_subscribe(n){j.channel_send_download_subscribe(this.__wbg_ptr,n)}send_download_where(n,t,e){const r=+(y(e)?Number.MAX_SAFE_INTEGER:e>>>0),_=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_download_where(this.__wbg_ptr,_,T,t,r)}send_sftp_chmod(n,t,e,r,_){const o=+t,c=+r,i=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let s,u,a,f;try{s=v(n,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T}catch(n){throw a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),n}j.channel_send_sftp_chmod(this.__wbg_ptr,s,u,o,a,f,c,i)}send_sftp_delete(n,t,e,r,_){const o=+t,c=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let i,s,u,a,f,b;try{i=v(n,j.__wbindgen_export,j.__wbindgen_export2),s=T,u=v(e,j.__wbindgen_export,j.__wbindgen_export2),a=T,f=v(r,j.__wbindgen_export,j.__wbindgen_export2),b=T}catch(n){throw f&&j.__wbindgen_export3(f,1*b,1),u&&j.__wbindgen_export3(u,1*a,1),i&&j.__wbindgen_export3(i,1*s,1),n}j.channel_send_sftp_delete(this.__wbg_ptr,i,s,o,u,a,f,b,c)}send_sftp_download_ack(n,t,e,r){const _=+t,o=+e,c=+r,i=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_sftp_download_ack(this.__wbg_ptr,i,T,_,o,c)}send_sftp_download_chunk(n,t,e,r,_){const o=+t,c=+e,i=+r,s=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0),u=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_sftp_download_chunk(this.__wbg_ptr,u,T,o,c,i,s)}send_sftp_download_start(n,t,e,r,_){const o=+t,c=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let i,s,u,a,f,b;try{i=v(n,j.__wbindgen_export,j.__wbindgen_export2),s=T,u=v(e,j.__wbindgen_export,j.__wbindgen_export2),a=T,f=v(r,j.__wbindgen_export,j.__wbindgen_export2),b=T}catch(n){throw f&&j.__wbindgen_export3(f,1*b,1),u&&j.__wbindgen_export3(u,1*a,1),i&&j.__wbindgen_export3(i,1*s,1),n}j.channel_send_sftp_download_start(this.__wbg_ptr,i,s,o,u,a,f,b,c)}send_sftp_list_data(n,t,e,r){const _=+t,o=+(y(r)?Number.MAX_SAFE_INTEGER:r>>>0);let c,i,s,u;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(e,j.__wbindgen_export,j.__wbindgen_export2),u=T}catch(n){throw s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_send_sftp_list_data(this.__wbg_ptr,c,i,_,s,u,o)}send_sftp_mkdir(n,t,e,r){const _=+t,o=+(y(r)?Number.MAX_SAFE_INTEGER:r>>>0);let c,i,s,u;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(e,j.__wbindgen_export,j.__wbindgen_export2),u=T}catch(n){throw s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_send_sftp_mkdir(this.__wbg_ptr,c,i,_,s,u,o)}send_sftp_open_stream(n,t,e,r){const _=+t,o=+(y(r)?Number.MAX_SAFE_INTEGER:r>>>0);let c,i,s,u;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(e,j.__wbindgen_export,j.__wbindgen_export2),u=T}catch(n){throw s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_send_sftp_open_stream(this.__wbg_ptr,c,i,_,s,u,o)}send_sftp_read_file(n,t,e,r){const _=+t,o=+(y(r)?Number.MAX_SAFE_INTEGER:r>>>0);let c,i,s,u;try{c=v(n,j.__wbindgen_export,j.__wbindgen_export2),i=T,s=v(e,j.__wbindgen_export,j.__wbindgen_export2),u=T}catch(n){throw s&&j.__wbindgen_export3(s,1*u,1),c&&j.__wbindgen_export3(c,1*i,1),n}j.channel_send_sftp_read_file(this.__wbg_ptr,c,i,_,s,u,o)}send_sftp_remove(n,t,e,r,_){const o=+t,c=+r,i=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let s,u,a,f;try{s=v(n,j.__wbindgen_export,j.__wbindgen_export2),u=T,a=v(e,j.__wbindgen_export,j.__wbindgen_export2),f=T}catch(n){throw a&&j.__wbindgen_export3(a,1*f,1),s&&j.__wbindgen_export3(s,1*u,1),n}j.channel_send_sftp_remove(this.__wbg_ptr,s,u,o,a,f,c,i)}send_sftp_rename(n,t,e,r,_){const o=+t,c=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let i,s,u,a,f,b;try{i=v(n,j.__wbindgen_export,j.__wbindgen_export2),s=T,u=v(e,j.__wbindgen_export,j.__wbindgen_export2),a=T,f=v(r,j.__wbindgen_export,j.__wbindgen_export2),b=T}catch(n){throw f&&j.__wbindgen_export3(f,1*b,1),u&&j.__wbindgen_export3(u,1*a,1),i&&j.__wbindgen_export3(i,1*s,1),n}j.channel_send_sftp_rename(this.__wbg_ptr,i,s,o,u,a,f,b,c)}send_sftp_upload_chunk(n,t,e,r,_,o,c){const i=+t,s=+e,u=+r,a=+_,f=+(y(c)?Number.MAX_SAFE_INTEGER:c>>>0);let b,d,w,l;try{b=v(n,j.__wbindgen_export,j.__wbindgen_export2),d=T,w=p(o,j.__wbindgen_export),l=T}catch(n){throw w&&j.__wbindgen_export3(w,1*l,1),b&&j.__wbindgen_export3(b,1*d,1),n}j.channel_send_sftp_upload_chunk(this.__wbg_ptr,b,d,i,s,u,a,w,l,f)}send_sftp_upload_start(n,t,e,r,_,o,c){const i=+t,s=+_,u=BigInt.asIntN(64,o),a=+(y(c)?Number.MAX_SAFE_INTEGER:c>>>0);let f,b,d,w,l,g;try{f=v(n,j.__wbindgen_export,j.__wbindgen_export2),b=T,d=v(e,j.__wbindgen_export,j.__wbindgen_export2),w=T,l=v(r,j.__wbindgen_export,j.__wbindgen_export2),g=T}catch(n){throw l&&j.__wbindgen_export3(l,1*g,1),d&&j.__wbindgen_export3(d,1*w,1),f&&j.__wbindgen_export3(f,1*b,1),n}j.channel_send_sftp_upload_start(this.__wbg_ptr,f,b,i,d,w,l,g,s,u,a)}send_sftp_write_file(n,t,e,r,_){const o=+t,c=+(y(_)?Number.MAX_SAFE_INTEGER:_>>>0);let i,s,u,a,f,b;try{i=v(n,j.__wbindgen_export,j.__wbindgen_export2),s=T,u=v(e,j.__wbindgen_export,j.__wbindgen_export2),a=T,f=p(r,j.__wbindgen_export),b=T}catch(n){throw f&&j.__wbindgen_export3(f,1*b,1),u&&j.__wbindgen_export3(u,1*a,1),i&&j.__wbindgen_export3(i,1*s,1),n}j.channel_send_sftp_write_file(this.__wbg_ptr,i,s,o,u,a,f,b,c)}send_ssh_terminal_resize(n,t,e,r,_,o){const c=+t,i=+e,s=+r,u=+_,a=+o,f=v(n,j.__wbindgen_export,j.__wbindgen_export2);j.channel_send_ssh_terminal_resize(this.__wbg_ptr,f,T,c,i,s,u,a)}send_ssh_tunnel_data(n,t,e){const r=+t;let _,o,c,i;try{_=v(n,j.__wbindgen_export,j.__wbindgen_export2),o=T,c=v(e,j.__wbindgen_export,j.__wbindgen_export2),i=T}catch(n){throw c&&j.__wbindgen_export3(c,1*i,1),_&&j.__wbindgen_export3(_,1*o,1),n}j.channel_send_ssh_tunnel_data(this.__wbg_ptr,_,o,r,c,i)}start_heartbeat(n){j.channel_start_heartbeat(this.__wbg_ptr,n)}stop_heartbeat(){j.channel_stop_heartbeat(this.__wbg_ptr)}update_service(n,t,e,r,_,o,c,i,s,u){const a=+o,f=+(y(u)?Number.MAX_SAFE_INTEGER:u>>>0);let b,d,w,l,g,h,m,p,N,A,R,S,O,U,F,P;try{b=v(n,j.__wbindgen_export,j.__wbindgen_export2),d=T,w=v(t,j.__wbindgen_export,j.__wbindgen_export2),l=T,g=v(e,j.__wbindgen_export,j.__wbindgen_export2),h=T,m=y(r)?0:v(r,j.__wbindgen_export,j.__wbindgen_export2),p=T,N=v(_,j.__wbindgen_export,j.__wbindgen_export2),A=T,R=y(c)?0:v(c,j.__wbindgen_export,j.__wbindgen_export2),S=T,O=y(i)?0:v(i,j.__wbindgen_export,j.__wbindgen_export2),U=T,F=y(s)?0:v(s,j.__wbindgen_export,j.__wbindgen_export2),P=T}catch(n){throw F&&j.__wbindgen_export3(F,1*P,1),O&&j.__wbindgen_export3(O,1*U,1),R&&j.__wbindgen_export3(R,1*S,1),N&&j.__wbindgen_export3(N,1*A,1),m&&j.__wbindgen_export3(m,1*p,1),g&&j.__wbindgen_export3(g,1*h,1),w&&j.__wbindgen_export3(w,1*l,1),b&&j.__wbindgen_export3(b,1*d,1),n}j.channel_update_service(this.__wbg_ptr,b,d,w,l,g,h,m,p,N,A,a,R,S,O,U,F,P,f)}}Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);const t=Object.freeze({Generic:0,0:"Generic",Authentication:10,10:"Authentication",RequiresUsername:100,100:"RequiresUsername",RequiresPassword:110,110:"RequiresPassword",RequiresUsernamePassword:120,120:"RequiresUsernamePassword"});function e(n,t){j.__wasm_bindgen_func_elem_100(n,t)}function r(n,t,e){j.__wasm_bindgen_func_elem_96(n,t,e)}function _(n,t,e){j.__wasm_bindgen_func_elem_96_47(n,t,e)}function o(n,t,e){j.__wasm_bindgen_func_elem_96_48(n,t,e)}const c=["blob","arraybuffer"],i="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>j.__wbg_channel_free(n,1)));function s(n){const t=j.__wbindgen_export5();return j.__wbindgen_externrefs.set(t,n),t}const u="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>j.__wbindgen_export6(n.a,n.b)));function a(n){switch(typeof n){case"number":case"boolean":case"undefined":return`${n}`;case"string":return JSON.stringify(n);case"bigint":return`${n}n`;case"symbol":return void 0!==n.description?`Symbol(${n.description})`:"Symbol";case"function":return"string"==typeof n.name&&""!==n.name?`Function(${n.name})`:"Function";case"object":{if(null===n)return"null";if(Array.isArray(n))return"["+Array.from(n,a).join(", ")+"]";if(n instanceof Error)return`${n.name}: ${n.message}\n${n.stack}`;const t=toString.call(n),e=/\[object ([^\]]+)\]/.exec(t)?.[1];if(void 0===e)return t;if("Object"===e)try{return"Object("+JSON.stringify(n)+")"}catch(n){return"Object"}return e}}}function f(n,t){return n>>>=0,g().subarray(n/1,n/1+t)}let b=null;function d(){return(null===b||!0===b.buffer.detached||void 0===b.buffer.detached&&b.buffer!==j.memory.buffer)&&(b=new DataView(j.memory.buffer)),b}function w(n,t){return n>>>=0,e=g().subarray(n,n+t),R+=e.length,R>=A&&(N=new TextDecoder("utf-8",{ignoreBOM:!0}),N.decode(),R=e.length),N.decode(e);var e}let l=null;function g(){return null!==l&&0!==l.byteLength||(l=new Uint8Array(j.memory.buffer)),l}function h(n,t){try{return n.apply(this,t)}catch(n){const t=s(n);j.__wbindgen_export4(t)}}function y(n){return null==n}function m(n,t,e){const r={a:n,b:t,cnt:1},_=(...n)=>{r.cnt++;const t=r.a;r.a=0;try{return e(t,r.b,...n)}finally{r.a=t,_._wbg_cb_unref()}};return _._wbg_cb_unref=()=>{0==--r.cnt&&(j.__wbindgen_export6(r.a,r.b),r.a=0,u.unregister(r))},u.register(_,r,r),_}function p(n,t){const e=t(1*n.length,1)>>>0;return g().set(n,e/1),T=n.length,e}function v(n,t,e){if(void 0===e){const e=S.encode(n),r=t(e.length,1)>>>0;return g().subarray(r,r+e.length).set(e),T=e.length,r}let r=n.length,_=t(r,1)>>>0;const o=g();let c=0;for(;c<r;c++){const t=n.charCodeAt(c);if(t>127)break;o[_+c]=t}if(c!==r){0!==c&&(n=n.slice(c)),_=e(_,r,r=c+3*n.length,1)>>>0;const t=g().subarray(_+c,_+r);c+=S.encodeInto(n,t).written,_=e(_,r,c,1)>>>0}return T=c,_}let N=new TextDecoder("utf-8",{ignoreBOM:!0});N.decode();const A=2146435072;let R=0;const S=new TextEncoder;"encodeInto"in S||(S.encodeInto=function(n,t){const e=S.encode(n);return t.set(e),{read:n.length,written:e.length}});let j,O,T=0;async function U(n){return void 0!==j?j:(void 0===O&&(O=async function(n){void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module_or_path:n}=n):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===n&&(n=new URL("phirepass-channel_bg.wasm",import.meta.url));const t=function(){const n={__proto__:null,__wbg_Error_208446807d0d1e30:function(n,t){return Error(w(n,t))},__wbg_Number_ff192a72a0dcdf6d:function(n){return Number(n)},__wbg_String_8564e559799eccda:function(n,t){const e=v(String(t),j.__wbindgen_export,j.__wbindgen_export2),r=T;d().setInt32(4+(n>>>0),r,!0),d().setInt32(0+(n>>>0),e,!0)},__wbg___wbindgen_bigint_get_as_i64_11da4b52cd0aedef:function(n,t){const e="bigint"==typeof t?t:void 0;d().setBigInt64(8+(n>>>0),y(e)?BigInt(0):e,!0),d().setInt32(0+(n>>>0),!y(e),!0)},__wbg___wbindgen_boolean_get_4f1baf9a00be3c74:function(n){const t="boolean"==typeof n?n:void 0;return y(t)?16777215:t?1:0},__wbg___wbindgen_debug_string_f249a2a76caa9a55:function(n,t){const e=v(a(t),j.__wbindgen_export,j.__wbindgen_export2),r=T;d().setInt32(4+(n>>>0),r,!0),d().setInt32(0+(n>>>0),e,!0)},__wbg___wbindgen_in_3f58a9d3b3a7eed2:function(n,t){return n in t},__wbg___wbindgen_is_bigint_5fa10641e039d3ef:function(n){return"bigint"==typeof n},__wbg___wbindgen_is_function_741ff2bb612836f5:function(n){return"function"==typeof n},__wbg___wbindgen_is_null_c22311b1cc228e3a:function(n){return null===n},__wbg___wbindgen_is_object_8b968c3ab8e96595:function(n){return"object"==typeof n&&null!==n},__wbg___wbindgen_is_string_fc456fee5d3317de:function(n){return"string"==typeof n},__wbg___wbindgen_is_undefined_be5b34249ff1fc15:function(n){return void 0===n},__wbg___wbindgen_jsval_eq_38d7bfbe4cc84039:function(n,t){return n===t},__wbg___wbindgen_jsval_loose_eq_b2f214e2e4b30e36:function(n,t){return n==t},__wbg___wbindgen_number_get_934b640d0889af78:function(n,t){const e="number"==typeof t?t:void 0;d().setFloat64(8+(n>>>0),y(e)?0:e,!0),d().setInt32(0+(n>>>0),!y(e),!0)},__wbg___wbindgen_string_get_7ce8eee7fd327545:function(n,t){const e="string"==typeof t?t:void 0;var r=y(e)?0:v(e,j.__wbindgen_export,j.__wbindgen_export2),_=T;d().setInt32(4+(n>>>0),_,!0),d().setInt32(0+(n>>>0),r,!0)},__wbg___wbindgen_throw_4c88d8bf264fd984:function(n,t){throw new Error(w(n,t))},__wbg__wbg_cb_unref_09736879a3f67559:function(n){n._wbg_cb_unref()},__wbg_call_40b008ba32f73991:function(){return h((function(n,t){return n.call(t)}),arguments)},__wbg_call_a410eb4b59ed5965:function(){return h((function(n,t,e){return n.call(t,e)}),arguments)},__wbg_call_fc92fee6137d452d:function(){return h((function(n,t,e,r){return n.call(t,e,r)}),arguments)},__wbg_clearInterval_2ed00e80b9bdc143:function(n){return clearInterval(n)},__wbg_close_5ee9c5fe4e8754a4:function(){return h((function(n){n.close()}),arguments)},__wbg_data_c7e5e8500f1bca2f:function(n){return n.data},__wbg_done_57e08d0be6e30c02:function(n){return n.done},__wbg_entries_7bb1459bd9b5c2b9:function(n){return Object.entries(n)},__wbg_from_eac91875c8a5ffa4:function(n){return Array.from(n)},__wbg_getRandomValues_5d8c030b527203a6:function(){return h((function(n,t){globalThis.crypto.getRandomValues(f(n,t))}),arguments)},__wbg_get_2080c49015e35254:function(){return h((function(n,t){return Reflect.get(n,t)}),arguments)},__wbg_get_635eea311fa1a291:function(){return h((function(n,t){return Reflect.get(n,t)}),arguments)},__wbg_get_d7176cfb76d71114:function(n,t){return n[t>>>0]},__wbg_get_unchecked_e6325ad374eff861:function(n,t){return n[t>>>0]},__wbg_get_with_ref_key_fc601247060b7204:function(n,t){return n[t]},__wbg_info_386f00b314475db5:function(n,t){console.info(w(n,t))},__wbg_instanceof_ArrayBuffer_12cdaa4161423e6b:function(n){let t;try{t=n instanceof ArrayBuffer}catch(n){t=!1}return t},__wbg_instanceof_Uint8Array_d7aeb0dcb3108fea:function(n){let t;try{t=n instanceof Uint8Array}catch(n){t=!1}return t},__wbg_isArray_bcf1376d0d732d08:function(n){return Array.isArray(n)},__wbg_isSafeInteger_1a35ba4d31e71d38:function(n){return Number.isSafeInteger(n)},__wbg_iterator_e4c5e8f68ada7b58:function(){return Symbol.iterator},__wbg_length_186163212ffe79c3:function(n){return n.length},__wbg_length_b03a0fabb109b1e9:function(n){return n.length},__wbg_new_13de428334042d26:function(n){return new Uint8Array(n)},__wbg_new_37eb45aaf5eeb820:function(){return new Array},__wbg_new_cd4348290afae586:function(){return new Object},__wbg_new_with_str_sequence_75b26d88172889d0:function(){return h((function(n,t,e){return new WebSocket(w(n,t),e)}),arguments)},__wbg_next_178c1651c11432b3:function(n){return n.next},__wbg_next_af5ac6a08bb0a717:function(){return h((function(n){return n.next()}),arguments)},__wbg_prototypesetcall_13162965d1fe7aa3:function(n,t,e){Uint8Array.prototype.set.call(f(n,t),e)},__wbg_push_c9f4893fc209f768:function(n,t){return n.push(t)},__wbg_readyState_039bc047141a5f6d:function(n){return n.readyState},__wbg_send_d83d0891cf698779:function(){return h((function(n,t,e){n.send(f(t,e))}),arguments)},__wbg_setInterval_ef738bbfe8cc0974:function(){return h((function(n,t){return setInterval(n,t)}),arguments)},__wbg_set_binaryType_d5b4dafd0f127fb2:function(n,t){n.binaryType=c[t]},__wbg_set_d2d33b52458e984a:function(n,t,e){n[t>>>0]=e},__wbg_set_e4b9a833d288759a:function(n,t,e){n[t]=e},__wbg_set_onclose_078935cf8d0fb024:function(n,t){n.onclose=t},__wbg_set_onerror_f7f089f7f059501c:function(n,t){n.onerror=t},__wbg_set_onmessage_26abc49cfa5f9ffc:function(n,t){n.onmessage=t},__wbg_set_onopen_757be120cc7b1ea6:function(n,t){n.onopen=t},__wbg_value_e0f328965e184931:function(n){return n.value},__wbg_warn_4f0851b2fd19b28b:function(n,t){console.warn(w(n,t))},__wbindgen_generic_0000000000000001:function(n,t){return m(n,t,r)},__wbindgen_generic_0000000000000002:function(n,t){return m(n,t,_)},__wbindgen_generic_0000000000000003:function(n,t){return m(n,t,o)},__wbindgen_generic_0000000000000004:function(n,t){return m(n,t,e)},__wbindgen_generic_0000000000000005:function(n){return n},__wbindgen_generic_0000000000000006:function(n,t){return f(n,t)},__wbindgen_generic_0000000000000007:function(n,t){return w(n,t)},__wbindgen_generic_0000000000000008:function(n){return BigInt.asUintN(64,n)},__wbindgen_init_externref_table:function(){const n=j.__wbindgen_externrefs;n.set(0,void 0),n.set(1024,void 0),n.set(1025,null),n.set(1026,!0),n.set(1027,!1)}};return{__proto__:null,"./phirepass-channel_bg.js":n}}();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:i}=await async function(n,t){if("function"==typeof Response&&n instanceof Response){if(!n.ok)throw new Error(`failed to fetch Wasm: ${n.status} ${n.statusText} fetching '${n.url}'`);if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(n,t)}catch(t){if(!function(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}(n.type)||"application/wasm"===n.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}const e=await n.arrayBuffer();return await WebAssembly.instantiate(e,t)}{const e=await WebAssembly.instantiate(n,t);return e instanceof WebAssembly.Instance?{instance:e,module:n}:e}}(await n,t);return function(n){return j=n.exports,b=null,l=null,j.__wbindgen_start(),j}(i)}(n),O.catch((()=>{O=void 0}))),O)}var F,P,k;!function(n){n.Error="Error",n.AuthSuccess="AuthSuccess",n.TunnelOpened="TunnelOpened",n.TunnelClosed="TunnelClosed",n.TunnelData="TunnelData",n.RDPAuthorized="RDPAuthorized",n.SFTPListItems="SFTPListItems",n.SFTPDownloadStartResponse="SFTPDownloadStartResponse",n.SFTPDownloadChunk="SFTPDownloadChunk",n.SFTPUploadStartResponse="SFTPUploadStartResponse",n.SFTPUploadChunkAck="SFTPUploadChunkAck",n.SFTPOpResult="SFTPOpResult"}(F||(F={})),function(n){n[n.Username=0]="Username",n[n.Password=1]="Password",n[n.Default=2]="Default"}(P||(P={})),function(n){n.Disconnected="disconnected",n.Connected="connected",n.Error="error"}(k||(k={}));export{n as C,t as E,P as I,F as P,U as _,k as a}
@@ -1 +1 @@
1
- import{P as o,d as s}from"./p-DqT-qhTU.js";const p=o,r=s;export{p as PhirepassDownloader,r as defineCustomElement}
1
+ import{P as o,d as s}from"./p-B4kFfbHE.js";const p=o,r=s;export{p as PhirepassDownloader,r as defineCustomElement}
@@ -1 +1 @@
1
- import{t,p as e,H as s,c as i,h as o,a as n}from"./index.js";import{_ as r,C as h,a,P as c}from"./p-BtMWUitf.js";const d=200;function l(t){return!Number.isFinite(t)||t<=0?d:Math.min(8192,Math.max(d,Math.floor(t)))}function u(t){return t-t%2}function p(t){const e=t.getBoundingClientRect();return function(t,e){return{width:u(l(t)),height:u(l(e))}}(e.width,e.height)}class m{onResize;debounceMs;observer;handle;reported;constructor(t,e=250){this.onResize=t,this.debounceMs=e}observe(t,e){this.disconnect(),this.reported=e,this.report(p(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(p(t))),this.debounceMs)})),this.observer.observe(t))}disconnect(){clearTimeout(this.handle),this.handle=void 0,this.observer?.disconnect(),this.observer=void 0,this.reported=void 0}report(t){(function(t,e){return!!t&&!!e&&t.width===e.width&&t.height===e.height})(t,this.reported)||(this.reported=t,this.onResize(t))}}function f(){return navigator.keyboard}function b(){return"function"==typeof f()?.lock}function y(t){return document.fullscreenElement===t}function w(t){return document.fullscreenElement?.contains(t)??!1}function g(){if(b())try{f().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const v=e(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.connectionStateChanged=i(this,"connectionStateChanged")}channel;containerEl;ironEl;userInteraction;viewport;domReady=!1;runtimeReady=!1;connected=!1;disposed=!1;session_id;onFullscreenChange=()=>this.sync_keyboard_lock();credentials;credentialsPrompt=!1;statusMessage;usernameBuffer="";passwordBuffer="";get el(){return this}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;clipboard=!0;onNodeIdChange(t,e){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;channelFactory;onServerIdChange(t,e){this.onNodeIdChange(this.nodeId,this.nodeId)}connectionStateChanged;create_web_socket_endpoint(){const t=this.allowInsecure?"ws":"wss";return this.allowInsecure||443!==this.serverPort?this.allowInsecure&&80===this.serverPort?`${t}://${this.serverHost}`:`${t}://${this.serverHost}:${this.serverPort}`:`${t}://${this.serverHost}`}async connectedCallback(){document.addEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!1,this.channelFactory||await r(),this.open_comms(),this.runtimeReady=!0,this.nodeId?this.try_connect():console.warn("Prop node_id is not set. Cannot connect to RDP.")}componentDidLoad(){this.domReady=!0,this.try_connect()}async disconnectedCallback(){document.removeEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!0,this.session_id=void 0,this.connected=!1,this.domReady=!1,this.runtimeReady=!1,this.close_comms()}async toggleFullscreen(){const t=await async function(t){try{return y(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(e){return console.warn("Failed to change the fullscreen state of the RDP session:",e),y(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return b()}async focusDesktop(){this.focus_desktop()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}try_connect(){!this.connected&&this.domReady&&this.runtimeReady&&this.containerEl&&this.channel&&this.connect()}connect(){this.connected=!0,this.channel.connect()}open_comms(){this.channel=this.channelFactory?this.channelFactory(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId||void 0):this.serverId?new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId):new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId),this.channel.on_connection_open((()=>{this.connectionStateChanged.emit([a.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([a.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([a.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:e}=t.data;switch(e.type){case c.Error:this.handle_error(e);break;case c.AuthSuccess:this.handle_auth_success(e);break;case c.RDPAuthorized:this.handle_rdp_authorized(e);break;case c.TunnelClosed:this.handle_tunnel_closed(e);break;default:console.warn("Unknown protocol message type:",e)}}))}close_comms(){this.teardown_client(),this.channel&&(this.channel.stop_heartbeat(),this.channel.disconnect())}reset_session_state(){this.session_id=void 0,this.credentials=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer="",this.statusMessage=void 0}handle_auth_success(t){if(this.channel.start_heartbeat(this.heartbeatInterval<=15e3?3e4:this.heartbeatInterval),this.username&&this.password)return this.credentials={username:this.username,password:this.password},void this.request_tunnel();this.credentialsPrompt=!0}request_tunnel(){this.credentials&&(this.statusMessage=void 0,this.channel.open_rdp_tunnel(this.nodeId,this.serviceId,this.credentials.username,this.credentials.password))}async handle_rdp_authorized(t){this.session_id=t.sid,this.statusMessage="Connecting…";const[e]=await Promise.all([import("@devolutions/iron-remote-desktop-rdp"),import("@devolutions/iron-remote-desktop")]);if(this.disposed||!this.containerEl||this.session_id!==t.sid)return;if(await e.init("info"),this.disposed||!this.containerEl||this.session_id!==t.sid)return;const s=document.createElement("iron-remote-desktop");s.module=e.Backend,s.scale=this.scale,s.flexcenter=!0,s.verbose=!1;const i=[e.enableCredssp(!0)];this.dynamicResize&&i.push(e.displayControl(!0)),s.addEventListener("ready",(e=>{this.start_session(e.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",t)}));const i=t.configBuilder().withUsername(this.credentials?.username??"").withPassword(this.credentials?.password??"").withDestination(this.destination??this.nodeId).withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`).withAuthToken(e);for(const t of s)i.withExtension(t);let o;this.dynamicResize&&(o=function(t){const e=t.getBoundingClientRect();if(Number.isFinite(e.width)&&Number.isFinite(e.height)&&!(e.width<d||e.height<d))return{width:u(Math.min(Math.floor(e.width),4096)),height:u(Math.min(Math.floor(e.height),4096))}}(this.el),o&&i.withDesktopSize(o));try{const e=await t.connect(i.build());if(this.disposed)return this.shutdown_session(t),void await e.run();t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.sync_keyboard_lock();const s=e.run();this.start_viewport_sync(o);const n=await s;this.statusMessage=n.reason()}catch(t){const e=this.describe_error(t);this.statusMessage=e,this.connectionStateChanged.emit([a.Error,t])}}start_viewport_sync(t){this.dynamicResize&&(this.viewport=new m((t=>this.resize_desktop(t))),this.viewport.observe(this.el,t))}stop_viewport_sync(){this.viewport?.disconnect(),this.viewport=void 0}resize_desktop(t){try{this.userInteraction?.resize(t.width,t.height)}catch(t){console.warn("The remote host would not resize its desktop:",t)}}focus_desktop(){!function(t){t?.focus({preventScroll:!0})}(this.ironEl)}async sync_keyboard_lock(){this.captureKeyboard&&w(this.el)?(await async function(t){if(b()&&w(t))try{await f().lock()}catch(t){console.warn("Failed to lock the keyboard for the RDP session:",t)}}(this.el),this.focus_desktop()):g()}describe_error(t){return t&&"function"==typeof t.backtrace?t.backtrace():t instanceof Error?t.message:"Connection failed."}handle_tunnel_closed(t){this.session_id=void 0,this.statusMessage=this.statusMessage??"Connection closed.",this.teardown_client(),this.close_comms()}handle_error(t){this.statusMessage=t.message,this.connectionStateChanged.emit([a.Error,t])}shutdown_session(t){try{t.shutdown()}catch(t){console.warn("Failed to shut the RDP session down cleanly:",t)}}teardown_client(){this.stop_viewport_sync(),g(),this.userInteraction&&(this.shutdown_session(this.userInteraction),this.userInteraction=void 0),this.ironEl?.remove(),this.ironEl=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer=""}submit_credentials(t){t.preventDefault(),this.credentialsPrompt=!1,this.credentials={username:this.usernameBuffer,password:this.passwordBuffer},this.usernameBuffer="",this.passwordBuffer="",this.request_tunnel()}render(){return o(n,{key:"9db127da5dbe168ef5f7a021767e5cedeb8305e6"},o("div",{key:"06d2de6763ec479198389032ab65033eefab21d6",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"7842ca9fd64795794e1b90e15319ddaa599f85b8"})),this.credentialsPrompt&&o("form",{key:"ce53830ced182740f139a318f099918c31013d9f",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"2b55341b9cfc2e08a847e26985000f5e1bc86eca",htmlFor:"rdp-username"},"Username"),o("input",{key:"243500ff59de6f16cc67acc5ddf9e15e3c0de0f6",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"5a346aa6a730c4cb0dd550eab9a65db9f2e74bc6",htmlFor:"rdp-password"},"Password"),o("input",{key:"0f1081b05f94e15a7f04df4de390a33a021ffe53",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"e9657c9df124176210508f5125fc526e3c78c5f1",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"3c59dbae63b7c5c5ef80344abad4b1a2b4c0b79d",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}static get style(){return':host{display:block;width:100%;height:100%;min-width:0;min-height:0;overflow:hidden;position:relative;background:#0b1021;container-type:inline-size}.screen{width:100%;height:100%;display:flex}::slotted(iron-remote-desktop){display:block;flex:1 1 auto;min-width:0;min-height:0;width:100%;height:100%}:host(:fullscreen){width:100vw;height:100vh;background:#000}.prompt{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.5rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.875rem}.prompt input{padding:0.5rem 0.75rem;border:1px solid #334155;border-radius:0.375rem;background:#0f172a;color:inherit;font:inherit;min-width:16rem}.prompt input:focus{outline:2px solid #67e8f9;outline-offset:1px}.prompt button{margin-top:0.5rem;padding:0.5rem 1.25rem;border:0;border-radius:0.375rem;background:#67e8f9;color:#0b1021;font:inherit;font-weight:600;cursor:pointer}.status{position:absolute;inset-inline:0;bottom:0;padding:0.5rem 0.75rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.8125rem;text-align:center}@container (max-width: 640px){.prompt{padding:1rem;gap:0.4rem}.prompt input{min-width:0;width:100%;max-width:22rem;font-size:16px;padding:0.625rem 0.75rem}.prompt button{width:100%;max-width:22rem;padding:0.75rem 1.25rem}.status{font-size:0.75rem;padding:0.5rem;padding-bottom:calc(0.5rem + env(safe-area-inset-bottom))}}'}},[769,"phirepass-rdp",{serverHost:[1,"server-host"],serverPort:[2,"server-port"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],nodeId:[1,"node-id"],serviceId:[1,"service-id"],token:[1],username:[1],password:[1],destination:[1],scale:[1],dynamicResize:[4,"dynamic-resize"],captureKeyboard:[4,"capture-keyboard"],clipboard:[4],serverId:[1,"server-id"],channelFactory:[16],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[64]},void 0,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]);function k(){"undefined"!=typeof customElements&&["phirepass-rdp"].forEach((e=>{"phirepass-rdp"===e&&(customElements.get(t(e))||customElements.define(t(e),v))}))}k();const _=v,I=k;export{_ as PhirepassRdp,I as defineCustomElement}
1
+ import{t,p as e,H as s,c as i,h as o,a as n}from"./index.js";import{_ as r,C as h,a,P as c}from"./p-BekUePpu.js";const d=200;function u(t){return!Number.isFinite(t)||t<=0?d:Math.min(8192,Math.max(d,Math.floor(t)))}function l(t){return t-t%2}function p(t){const e=t.getBoundingClientRect();return function(t,e){return{width:l(u(t)),height:l(u(e))}}(e.width,e.height)}class m{onResize;debounceMs;observer;handle;reported;constructor(t,e=250){this.onResize=t,this.debounceMs=e}observe(t,e){this.disconnect(),this.reported=e,this.report(p(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(p(t))),this.debounceMs)})),this.observer.observe(t))}disconnect(){clearTimeout(this.handle),this.handle=void 0,this.observer?.disconnect(),this.observer=void 0,this.reported=void 0}report(t){(function(t,e){return!!t&&!!e&&t.width===e.width&&t.height===e.height})(t,this.reported)||(this.reported=t,this.onResize(t))}}function f(){return navigator.keyboard}function b(){return"function"==typeof f()?.lock}function y(t){return document.fullscreenElement===t}function w(t){return document.fullscreenElement?.contains(t)??!1}function g(){if(b())try{f().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const v=e(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.connectionStateChanged=i(this,"connectionStateChanged")}channel;containerEl;ironEl;userInteraction;viewport;domReady=!1;runtimeReady=!1;connected=!1;disposed=!1;session_id;onFullscreenChange=()=>this.sync_keyboard_lock();credentials;credentialsPrompt=!1;statusMessage;usernameBuffer="";passwordBuffer="";get el(){return this}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;clipboard=!0;onNodeIdChange(t,e){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;channelFactory;onServerIdChange(t,e){this.onNodeIdChange(this.nodeId,this.nodeId)}connectionStateChanged;create_web_socket_endpoint(){const t=this.allowInsecure?"ws":"wss";return this.allowInsecure||443!==this.serverPort?this.allowInsecure&&80===this.serverPort?`${t}://${this.serverHost}`:`${t}://${this.serverHost}:${this.serverPort}`:`${t}://${this.serverHost}`}async connectedCallback(){document.addEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!1,this.channelFactory||await r(),this.open_comms(),this.runtimeReady=!0,this.nodeId?this.try_connect():console.warn("Prop node_id is not set. Cannot connect to RDP.")}componentDidLoad(){this.domReady=!0,this.try_connect()}async disconnectedCallback(){document.removeEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!0,this.session_id=void 0,this.connected=!1,this.domReady=!1,this.runtimeReady=!1,this.close_comms()}async toggleFullscreen(){const t=await async function(t){try{return y(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(e){return console.warn("Failed to change the fullscreen state of the RDP session:",e),y(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return b()}async focusDesktop(){this.focus_desktop()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}try_connect(){!this.connected&&this.domReady&&this.runtimeReady&&this.containerEl&&this.channel&&this.connect()}connect(){this.connected=!0,this.channel.connect()}open_comms(){this.channel=this.channelFactory?this.channelFactory(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId||void 0):this.serverId?new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId):new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId),this.channel.on_connection_open((()=>{this.connectionStateChanged.emit([a.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([a.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([a.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:e}=t.data;switch(e.type){case c.Error:this.handle_error(e);break;case c.AuthSuccess:this.handle_auth_success(e);break;case c.RDPAuthorized:this.handle_rdp_authorized(e);break;case c.TunnelClosed:this.handle_tunnel_closed(e);break;default:console.warn("Unknown protocol message type:",e)}}))}close_comms(){this.teardown_client(),this.channel&&(this.channel.stop_heartbeat(),this.channel.disconnect())}reset_session_state(){this.session_id=void 0,this.credentials=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer="",this.statusMessage=void 0}handle_auth_success(t){if(this.channel.start_heartbeat(this.heartbeatInterval<=15e3?3e4:this.heartbeatInterval),this.username&&this.password)return this.credentials={username:this.username,password:this.password},void this.request_tunnel();this.credentialsPrompt=!0}request_tunnel(){this.credentials&&(this.statusMessage=void 0,this.channel.open_rdp_tunnel(this.nodeId,this.serviceId,this.credentials.username,this.credentials.password))}async handle_rdp_authorized(t){this.session_id=t.sid,this.statusMessage="Connecting…";const[e]=await Promise.all([import("@devolutions/iron-remote-desktop-rdp"),import("@devolutions/iron-remote-desktop")]);if(this.disposed||!this.containerEl||this.session_id!==t.sid)return;if(await e.init("info"),this.disposed||!this.containerEl||this.session_id!==t.sid)return;const s=document.createElement("iron-remote-desktop");s.module=e.Backend,s.scale=this.scale,s.flexcenter=!0,s.verbose=!1;const i=[e.enableCredssp(!0)];this.dynamicResize&&i.push(e.displayControl(!0)),s.addEventListener("ready",(e=>{this.start_session(e.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",t)}));const i=t.configBuilder().withUsername(this.credentials?.username??"").withPassword(this.credentials?.password??"").withDestination(this.destination??this.nodeId).withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`).withAuthToken(e);for(const t of s)i.withExtension(t);let o;this.dynamicResize&&(o=function(t){const e=t.getBoundingClientRect();if(Number.isFinite(e.width)&&Number.isFinite(e.height)&&!(e.width<d||e.height<d))return{width:l(Math.min(Math.floor(e.width),4096)),height:l(Math.min(Math.floor(e.height),4096))}}(this.el),o&&i.withDesktopSize(o));try{const e=await t.connect(i.build());if(this.disposed)return this.shutdown_session(t),void await e.run();t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.sync_keyboard_lock();const s=e.run();this.start_viewport_sync(o);const n=await s;this.statusMessage=n.reason()}catch(t){const e=this.describe_error(t);this.statusMessage=e,this.connectionStateChanged.emit([a.Error,t])}}start_viewport_sync(t){this.dynamicResize&&(this.viewport=new m((t=>this.resize_desktop(t))),this.viewport.observe(this.el,t))}stop_viewport_sync(){this.viewport?.disconnect(),this.viewport=void 0}resize_desktop(t){try{this.userInteraction?.resize(t.width,t.height)}catch(t){console.warn("The remote host would not resize its desktop:",t)}}focus_desktop(){!function(t){t?.focus({preventScroll:!0})}(this.ironEl)}async sync_keyboard_lock(){this.captureKeyboard&&w(this.el)?(await async function(t){if(b()&&w(t))try{await f().lock()}catch(t){console.warn("Failed to lock the keyboard for the RDP session:",t)}}(this.el),this.focus_desktop()):g()}describe_error(t){return t&&"function"==typeof t.backtrace?t.backtrace():t instanceof Error?t.message:"Connection failed."}handle_tunnel_closed(t){this.session_id=void 0,this.statusMessage=this.statusMessage??"Connection closed.",this.teardown_client(),this.close_comms()}handle_error(t){this.statusMessage=t.message,this.connectionStateChanged.emit([a.Error,t])}shutdown_session(t){try{t.shutdown()}catch(t){console.warn("Failed to shut the RDP session down cleanly:",t)}}teardown_client(){this.stop_viewport_sync(),g(),this.userInteraction&&(this.shutdown_session(this.userInteraction),this.userInteraction=void 0),this.ironEl?.remove(),this.ironEl=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer=""}submit_credentials(t){t.preventDefault(),this.credentialsPrompt=!1,this.credentials={username:this.usernameBuffer,password:this.passwordBuffer},this.usernameBuffer="",this.passwordBuffer="",this.request_tunnel()}render(){return o(n,{key:"9db127da5dbe168ef5f7a021767e5cedeb8305e6"},o("div",{key:"06d2de6763ec479198389032ab65033eefab21d6",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"7842ca9fd64795794e1b90e15319ddaa599f85b8"})),this.credentialsPrompt&&o("form",{key:"ce53830ced182740f139a318f099918c31013d9f",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"2b55341b9cfc2e08a847e26985000f5e1bc86eca",htmlFor:"rdp-username"},"Username"),o("input",{key:"243500ff59de6f16cc67acc5ddf9e15e3c0de0f6",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"5a346aa6a730c4cb0dd550eab9a65db9f2e74bc6",htmlFor:"rdp-password"},"Password"),o("input",{key:"0f1081b05f94e15a7f04df4de390a33a021ffe53",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"e9657c9df124176210508f5125fc526e3c78c5f1",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"3c59dbae63b7c5c5ef80344abad4b1a2b4c0b79d",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}static get style(){return':host{display:block;width:100%;height:100%;min-width:0;min-height:0;overflow:hidden;position:relative;background:#0b1021;container-type:inline-size}.screen{width:100%;height:100%;display:flex}::slotted(iron-remote-desktop){display:block;flex:1 1 auto;min-width:0;min-height:0;width:100%;height:100%}:host(:fullscreen){width:100vw;height:100vh;background:#000}.prompt{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.5rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.875rem}.prompt input{padding:0.5rem 0.75rem;border:1px solid #334155;border-radius:0.375rem;background:#0f172a;color:inherit;font:inherit;min-width:16rem}.prompt input:focus{outline:2px solid #67e8f9;outline-offset:1px}.prompt button{margin-top:0.5rem;padding:0.5rem 1.25rem;border:0;border-radius:0.375rem;background:#67e8f9;color:#0b1021;font:inherit;font-weight:600;cursor:pointer}.status{position:absolute;inset-inline:0;bottom:0;padding:0.5rem 0.75rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.8125rem;text-align:center}@container (max-width: 640px){.prompt{padding:1rem;gap:0.4rem}.prompt input{min-width:0;width:100%;max-width:22rem;font-size:16px;padding:0.625rem 0.75rem}.prompt button{width:100%;max-width:22rem;padding:0.75rem 1.25rem}.status{font-size:0.75rem;padding:0.5rem;padding-bottom:calc(0.5rem + env(safe-area-inset-bottom))}}'}},[769,"phirepass-rdp",{serverHost:[1,"server-host"],serverPort:[2,"server-port"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],nodeId:[1,"node-id"],serviceId:[1,"service-id"],token:[1],username:[1],password:[1],destination:[1],scale:[1],dynamicResize:[4,"dynamic-resize"],captureKeyboard:[4,"capture-keyboard"],clipboard:[4],serverId:[1,"server-id"],channelFactory:[16],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[64]},void 0,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]);function k(){"undefined"!=typeof customElements&&["phirepass-rdp"].forEach((e=>{"phirepass-rdp"===e&&(customElements.get(t(e))||customElements.define(t(e),v))}))}k();const _=v,I=k;export{_ as PhirepassRdp,I as defineCustomElement}