forge-terminal 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -19
- package/dist/chunks/{about-credits-TJBWWNH6.js → about-credits-5UQU5WHE.js} +2 -2
- package/dist/chunks/args-QKAIL3E4.js +3 -0
- package/dist/chunks/{available-GYIHVSRX.js → available-M6Z62OWE.js} +1 -1
- package/dist/chunks/boot-MGR26CBU.js +3 -0
- package/dist/chunks/catalog-VPSTQTFD.js +3 -0
- package/dist/chunks/check-B6NP7BEM.js +3 -0
- package/dist/chunks/chunk-37P6QZ5Q.js +3 -0
- package/dist/chunks/chunk-3GJ7GV3V.js +19 -0
- package/dist/chunks/{chunk-EHARO6IS.js → chunk-57M4J2BR.js} +1 -1
- package/dist/chunks/chunk-63XCSYHM.js +3 -0
- package/dist/chunks/{chunk-JFJ3ZJQL.js → chunk-63ZK5SRQ.js} +1 -1
- package/dist/chunks/chunk-C4UCCBCX.js +3 -0
- package/dist/chunks/{chunk-DERIWZAT.js → chunk-CKZBBDAW.js} +1 -1
- package/dist/chunks/chunk-DZOBIUV6.js +3 -0
- package/dist/chunks/chunk-EKTUUKDP.js +80 -0
- package/dist/chunks/chunk-F34DPQFQ.js +63 -0
- package/dist/chunks/chunk-G46QQBT3.js +3 -0
- package/dist/chunks/chunk-GSK2A3TN.js +3 -0
- package/dist/chunks/chunk-H3DIRJFE.js +3 -0
- package/dist/chunks/chunk-HKINXTUW.js +3 -0
- package/dist/chunks/chunk-HOZ6XGQQ.js +6 -0
- package/dist/chunks/chunk-I6754KTB.js +36 -0
- package/dist/chunks/{chunk-YYB3TTGT.js → chunk-JMBEZPYC.js} +1 -1
- package/dist/chunks/chunk-K7KKCR7V.js +6 -0
- package/dist/chunks/chunk-KH5DHZ2U.js +8 -0
- package/dist/chunks/chunk-KXKQDFHX.js +3 -0
- package/dist/chunks/chunk-LVYQVJOF.js +3 -0
- package/dist/chunks/chunk-N6RCLJE6.js +4 -0
- package/dist/chunks/chunk-N72E43Z3.js +3 -0
- package/dist/chunks/chunk-NDECMPOM.js +3 -0
- package/dist/chunks/chunk-NXJGO66P.js +3 -0
- package/dist/chunks/chunk-OK7XOZFO.js +3 -0
- package/dist/chunks/chunk-P4RAYEM7.js +6 -0
- package/dist/chunks/{chunk-EX7KZBI6.js → chunk-PE5LAYGF.js} +1 -1
- package/dist/chunks/chunk-PPR7B5AR.js +3 -0
- package/dist/chunks/chunk-Q6KQWJ4J.js +3 -0
- package/dist/chunks/{chunk-GJ2GZHRI.js → chunk-RMD7F3QX.js} +1 -1
- package/dist/chunks/chunk-SK2UZ25Y.js +3 -0
- package/dist/chunks/chunk-SNDFMJIX.js +3 -0
- package/dist/chunks/{chunk-IGF6ZFTM.js → chunk-SZRSAL64.js} +1 -1
- package/dist/chunks/chunk-THDAQBQ3.js +3 -0
- package/dist/chunks/chunk-TL5MACSF.js +3 -0
- package/dist/chunks/chunk-V3I6DSF4.js +3 -0
- package/dist/chunks/{chunk-A6RK5ALT.js → chunk-W6SY5PPG.js} +2 -2
- package/dist/chunks/chunk-WC6SJN5Y.js +3 -0
- package/dist/chunks/chunk-WE6KP4FR.js +3 -0
- package/dist/chunks/chunk-WIPP5TWQ.js +3 -0
- package/dist/chunks/{chunk-GKECNCKO.js → chunk-XBOMWF34.js} +1 -1
- package/dist/chunks/chunk-XRI5XKEB.js +66 -0
- package/dist/chunks/chunk-Y7LOIHFU.js +3 -0
- package/dist/chunks/chunk-YINYF6C7.js +3 -0
- package/dist/chunks/chunk-ZRHYGR2L.js +134 -0
- package/dist/chunks/chunk-ZZZAPVKM.js +3 -0
- package/dist/chunks/clip-command-R2NKW4TI.js +3 -0
- package/dist/chunks/clipboard-GICOXMMN.js +3 -0
- package/dist/chunks/colour-APVBMEJQ.js +3 -0
- package/dist/chunks/command-GYCYLUHN.js +3 -0
- package/dist/chunks/config-command-6YUMMZF3.js +3 -0
- package/dist/chunks/continue-editing-QE5RRIMG.js +3 -0
- package/dist/chunks/decoded-UNCEUPNW.js +3 -0
- package/dist/chunks/entry-TSLQHDP7.js +6 -0
- package/dist/chunks/execute-S5WN34PS.js +3 -0
- package/dist/chunks/extensions-XI5R74TS.js +3 -0
- package/dist/chunks/{extensions-command-ABJSGDPK.js → extensions-command-25JOL47P.js} +1 -1
- package/dist/chunks/ffmpeg-3CJ6C37W.js +3 -0
- package/dist/chunks/image-QSTDWHJ4.js +3 -0
- package/dist/chunks/install-IDUHZTTS.js +3 -0
- package/dist/chunks/{install-V62EEK54.js → install-L5C2UT6M.js} +1 -1
- package/dist/chunks/install-size-PZUFEDGI.js +3 -0
- package/dist/chunks/launch-LFFWVTFE.js +17 -0
- package/dist/chunks/libs-EK64ACG3.js +3 -0
- package/dist/chunks/lock-PTQUMNYX.js +3 -0
- package/dist/chunks/manager-CQ6NNQY4.js +4 -0
- package/dist/chunks/needed-MYXIUZI4.js +3 -0
- package/dist/chunks/own-WNA6BFYL.js +3 -0
- package/dist/chunks/{paths-5XI5L4KW.js → paths-EOYKOUBC.js} +1 -1
- package/dist/chunks/pdfium-WFGSET5S.js +3 -0
- package/dist/chunks/preferences-3P4V2EDX.js +3 -0
- package/dist/chunks/preset-command-HMOFTZSG.js +3 -0
- package/dist/chunks/registry-4IOXO6DT.js +3 -0
- package/dist/chunks/{reveal-L6TBFOMV.js → reveal-D5FCZYOA.js} +1 -1
- package/dist/chunks/run-HGZVOXRW.js +5 -0
- package/dist/chunks/{server-TUWDAECT.js → server-KKF3XBQG.js} +8 -8
- package/dist/chunks/text-layer-LHZNDMPZ.js +3 -0
- package/dist/chunks/{theme-7IVYHKTP.js → theme-NAWQ77WF.js} +1 -1
- package/dist/chunks/transcribe-Q5NLWSSR.js +3 -0
- package/dist/chunks/transcribe-command-2L7F7MCG.js +3 -0
- package/dist/chunks/{update-command-GMBG7BK6.js → update-command-JCTCRPCS.js} +1 -1
- package/dist/chunks/update-note-FRMHMUMD.js +3 -0
- package/dist/chunks/watch-command-XCCMIQIM.js +3 -0
- package/dist/fonts/NotoSans-Bold.ttf.gz +0 -0
- package/dist/fonts/NotoSans-Regular.ttf.gz +0 -0
- package/dist/fonts/OFL.txt +93 -0
- package/dist/helpers/forge-transcribe +0 -0
- package/dist/helpers/forge-transcribe-whisper.mjs +525 -0
- package/dist/index.js +8 -8
- package/dist/third-party-licenses.txt +98 -0
- package/package.json +43 -12
- package/dist/chunks/args-MGXWV4UD.js +0 -3
- package/dist/chunks/boot-AE6XH7Z3.js +0 -3
- package/dist/chunks/catalog-YSMT3PXT.js +0 -3
- package/dist/chunks/check-KAR72Y4X.js +0 -3
- package/dist/chunks/chunk-3UEQ2OX6.js +0 -3
- package/dist/chunks/chunk-5B5XXH22.js +0 -3
- package/dist/chunks/chunk-5IS7O673.js +0 -6
- package/dist/chunks/chunk-6FUVEO3A.js +0 -78
- package/dist/chunks/chunk-6L6C3GJU.js +0 -3
- package/dist/chunks/chunk-7S5DBC3J.js +0 -66
- package/dist/chunks/chunk-AAXBN572.js +0 -4
- package/dist/chunks/chunk-BZXDNDPG.js +0 -3
- package/dist/chunks/chunk-CEULBUUM.js +0 -63
- package/dist/chunks/chunk-DOWMSJ6R.js +0 -3
- package/dist/chunks/chunk-EXLXSKRH.js +0 -3
- package/dist/chunks/chunk-FH3R2YYD.js +0 -19
- package/dist/chunks/chunk-FWIXOYXE.js +0 -3
- package/dist/chunks/chunk-I63TO22X.js +0 -3
- package/dist/chunks/chunk-IWFVEMDN.js +0 -3
- package/dist/chunks/chunk-JSMGNA55.js +0 -3
- package/dist/chunks/chunk-KAHWYWNT.js +0 -3
- package/dist/chunks/chunk-LDKF7KIZ.js +0 -6
- package/dist/chunks/chunk-LNB5D67B.js +0 -3
- package/dist/chunks/chunk-M66BUNYO.js +0 -3
- package/dist/chunks/chunk-PSEIJXGT.js +0 -3
- package/dist/chunks/chunk-QR6QHTC3.js +0 -3
- package/dist/chunks/chunk-QXTXBMTM.js +0 -3
- package/dist/chunks/chunk-SMBK6BTC.js +0 -3
- package/dist/chunks/chunk-TDW6KQH6.js +0 -3
- package/dist/chunks/chunk-TMQDQLY7.js +0 -21
- package/dist/chunks/chunk-XSOCV3F2.js +0 -3
- package/dist/chunks/chunk-YWKMG5WO.js +0 -3
- package/dist/chunks/clip-command-D3DE2WUR.js +0 -3
- package/dist/chunks/clipboard-CPHPA4FH.js +0 -3
- package/dist/chunks/colour-U6QBTJTQ.js +0 -3
- package/dist/chunks/command-I5M275ZV.js +0 -3
- package/dist/chunks/config-command-TYNYVUMP.js +0 -3
- package/dist/chunks/entry-4GMHXHST.js +0 -6
- package/dist/chunks/execute-D4H7QWGR.js +0 -3
- package/dist/chunks/extensions-DOTV7SIR.js +0 -3
- package/dist/chunks/ffmpeg-PF3VLTHK.js +0 -3
- package/dist/chunks/image-J4FT4ACZ.js +0 -3
- package/dist/chunks/install-2A5BGKQU.js +0 -3
- package/dist/chunks/launch-XVWOLOXM.js +0 -15
- package/dist/chunks/lock-KN7CF4YN.js +0 -3
- package/dist/chunks/manager-TVGSLNBE.js +0 -4
- package/dist/chunks/preferences-4VETUGMN.js +0 -3
- package/dist/chunks/preset-command-HORY7KZQ.js +0 -3
- package/dist/chunks/run-6BK4REXK.js +0 -4
- package/dist/chunks/transcribe-command-YUSBCQEQ.js +0 -3
- package/dist/chunks/update-note-A7C2OJKU.js +0 -3
- package/dist/chunks/watch-command-NOMNFJ75.js +0 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{execFile as I,spawn as R}from"node:child_process";import{access as T,constants as K}from"node:fs/promises";import{dirname as $,join as L}from"node:path";import{promisify as C}from"node:util";function S(e){let[t,r]=(e??"").split("/").map(Number);return!t||!r?0:Math.round(t/r*100)/100}function O(e){let t=e.side_data_list?.find(n=>typeof n.rotation=="number")?.rotation,r=t!==void 0?-t:Number(e.tags?.rotate??0);return(Math.round(r/90)*90%360+360)%360}function A(e){let t=e,r=t.streams??[],n=r.find(o=>o.codec_type==="video"&&o.disposition?.attached_pic!==1),i=r.find(o=>o.codec_type==="audio"),a={duration:Number(t.format?.duration)||Math.max(0,...r.map(o=>Number(o.duration)||0))};if(n){let o=O(n),f=o===90||o===270,s=n.width??0,c=n.height??0;a.video={codec:n.codec_name??"",width:f?c:s,height:f?s:c,fps:S(n.avg_frame_rate)||S(n.r_frame_rate),rotation:o,hdr:n.color_transfer==="arib-std-b67"||n.color_transfer==="smpte2084"}}return i&&(a.audio={codec:i.codec_name??"",channels:i.channels??0,sampleRate:Number(i.sample_rate)||0}),a}var v=C(I);function D(e,t){let r=t.PATH??t.Path??"",n=e==="win32"?";":":",i=r.split(n).filter(Boolean);return e==="darwin"&&i.push("/opt/homebrew/bin","/usr/local/bin"),[...new Set(i)]}var k=e=>process.platform==="win32"?`${e}.exe`:e;async function N(e){try{return await T(e,K.X_OK),!0}catch{return!1}}function G(e){let t=new Set;for(let r of e.split(`
|
|
4
|
+
`)){let n=r.match(/^\s*[A-Z.|]{3,6}\s+(\S+)\s/);n?.[1]&&n[1]!=="="&&t.add(n[1])}return t}async function J(){try{let{installed:e}=await import("./paths-EOYKOUBC.js");return(await e("video"))?.dir}catch{return}}async function j(){try{let{chosenPath:e}=await import("./own-WNA6BFYL.js"),t=await e("video");return t===void 0?void 0:$(t)}catch{return}}async function q(){try{let{removeForgeCopy:e}=await import("./own-WNA6BFYL.js");await e("video")}catch{}}async function H(){let e=await J(),t=await j(),r=[...t?[t]:[],...D(process.platform,process.env),...e?[e]:[]];for(let n of r){let i=L(n,k("ffmpeg")),m=L(n,k("ffprobe"));if(!await N(i)||!await N(m))continue;try{await v(i,["-hide_banner","-version"],{timeout:5e3})}catch{continue}let[a,o]=await Promise.all(["-encoders","-filters"].map(s=>v(i,["-hide_banner",s],{timeout:5e3,maxBuffer:4<<20}).then(({stdout:c})=>G(c)).catch(()=>{}))),f=a&&o?new Set([...a,...o]):void 0;return e!==void 0&&n!==e&&await q(),{ffmpeg:i,ffprobe:m,...f?{has:f}:{}}}}var b,w=null,F;function y(){return w?Promise.resolve(w.value):(b=(b??H()).then(t=>(t||(b=void 0),F=t,t)),b)}function te(){return w?w.value:F}function ne(e){w=e===null?null:{value:e},b=void 0,F=void 0}async function re(e,t){let r=t??await y();if(!r)throw new Error("ffmpeg is not installed");let{stdout:n}=await v(r.ffprobe,["-v","error","-print_format","json","-show_format","-show_streams",e],{timeout:3e4,maxBuffer:16*1024*1024});return A(JSON.parse(n))}async function oe(e,t,r){let n=r??await y();if(!n)return;let i=Math.max(0,t-15),{stdout:m}=await v(n.ffprobe,["-v","error","-select_streams","v:0","-skip_frame","nokey","-show_entries","frame=pts_time","-of","csv=p=0","-read_intervals",`${i}%${t+.01}`,e],{timeout:3e4,maxBuffer:4*1024*1024}),a=m.split(`
|
|
5
|
+
`).map(o=>Number.parseFloat(o)).filter(o=>Number.isFinite(o)&&o<=t+.001);return a.length?Math.max(...a):void 0}var B=4e3;async function ie(e,t,r,n={}){let i=n.tools??await y();if(!i)return null;let m=Math.max(1,Math.round(t*B)),a=Math.max(1,Math.ceil(m/r)),o=new Array(r).fill(0),f=0,s=Buffer.alloc(0);if(!await new Promise((p,d)=>{let u=R(i.ffmpeg,["-hide_banner","-nostdin","-loglevel","error","-i",e,"-map","0:a:0","-ac","1","-ar",String(B),"-f","s16le","-"],{stdio:["ignore","pipe","pipe"]}),h=()=>u.kill("SIGKILL");n.signal?.addEventListener("abort",h,{once:!0}),u.stdout.on("data",l=>{let _=s.length?Buffer.concat([s,l]):l,P=_.length-_.length%2;for(let x=0;x<P;x+=2){let M=Math.abs(_.readInt16LE(x)),E=Math.min(r-1,Math.floor(f/a));M>(o[E]??0)&&(o[E]=M),f++}s=_.subarray(P)}),u.stderr.resume(),u.on("error",d),u.on("close",l=>{n.signal?.removeEventListener("abort",h),n.signal?.aborted?d(n.signal.reason??new Error("aborted")):p(l===0&&f>0)})}))return null;let g=Math.max(1,...o);return o.map(p=>Math.sqrt(p/g))}async function se(e,t,r,n){await Z(["-ss",String(Math.max(0,t)),"-i",e,"-frames:v","1","-y",r],{tools:n})}function V(e){let t;for(let r of e.matchAll(/out_time_us=(\d+)/g))t=Number(r[1])/1e6;return t}var X=4e3;async function Z(e,t={}){let{signal:r,onTime:n}=t;if(r?.aborted)throw r.reason??new Error("aborted");let i=t.tools??await y();if(!i)throw new Error("ffmpeg is not installed");let a=["-hide_banner","-nostdin","-loglevel",t.report?"info":"error","-progress","pipe:1","-nostats",...e];return new Promise((o,f)=>{let s=R(i.ffmpeg,a,{stdio:["ignore","pipe","pipe"]}),c="",g=()=>s.kill("SIGKILL");r?.addEventListener("abort",g,{once:!0}),s.stdout.setEncoding("utf8");let p="";s.stdout.on("data",d=>{let u=p+d,h=u.lastIndexOf(`
|
|
6
|
+
`);p=u.slice(h+1);let l=V(u.slice(0,h+1));l!==void 0&&n?.(l)}),s.stderr.setEncoding("utf8"),s.stderr.on("data",d=>{c=(c+d).slice(-X)}),s.on("error",d=>{r?.removeEventListener("abort",g),f(d)}),s.on("close",d=>{r?.removeEventListener("abort",g),r?.aborted?f(r.reason??new Error("aborted")):d===0?o(c):f(new Error(c.trim()||`ffmpeg exited with ${d}`))})})}export{D as a,G as b,y as c,te as d,ne as e,re as f,oe as g,ie as h,se as i,V as j,Z as k};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
var p=[{id:"md",label:"Markdown",ext:".md"},{id:"docx",label:"Word",ext:".docx"},{id:"pdf",label:"PDF",ext:".pdf"},{id:"txt",label:"Text",ext:".txt"}],f="md",g=t=>p.some(e=>e.id===t),c=t=>p.find(e=>e.id===t)?.ext??".md",m=t=>p.find(e=>e.id===t)?.label??"Markdown";function o(t){let e=/^(#{1,3}) (.*)$/.exec(t);if(e)return{kind:"heading",level:e[1]?.length,text:e[2]??""};let s=/^<(https?:\/\/\S+)>$/.exec(t);if(s)return{kind:"link",url:s[1]??""};if(t.startsWith("- "))return{kind:"point",text:t.slice(2)};let r=/^\*\*([0-9:]+)\*\* (.*)$/.exec(t);if(r)return{kind:"timed",time:r[1]??"",text:r[2]??""};let i=/^_(.*)_$/.exec(t);return i?{kind:"aside",text:i[1]??""}:t.trim()===""?{kind:"blank"}:{kind:"text",text:t}}function u(t){return t.kind==="blank"?"":t.kind==="link"?t.url:t.kind==="point"?`- ${t.text}`:t.kind==="timed"?`${t.time} ${t.text}`:t.text}function h(t){return t.split(`
|
|
4
|
+
`).map(e=>u(o(e))).join(`
|
|
5
|
+
`)}var d=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),x=['body{font-family:-apple-system,"Helvetica Neue",Helvetica,sans-serif;font-size:11pt;line-height:1.45;color:#1d1d1f}',"h1{font-size:20pt;margin:0 0 6pt}","h2{font-size:15pt;margin:18pt 0 6pt}","h3{font-size:12pt;margin:12pt 0 4pt}","p,ul{margin:0 0 8pt}","li{margin-bottom:4pt}","a{color:#0b57d0}","i{color:#6e6e73}"].join("");function $(t){let e=[],s=[],r=()=>{s.length&&e.push({kind:"list",ordered:!1,items:s}),s=[]};for(let i of t.split(`
|
|
6
|
+
`).map(o)){if(i.kind==="point"){s.push(i.text);continue}r(),i.kind==="heading"?e.push({kind:"heading",level:i.level===1?1:2,text:i.text}):i.kind==="link"?e.push({kind:"paragraph",text:i.url}):i.kind==="timed"?e.push({kind:"paragraph",text:`${i.time} ${i.text}`}):(i.kind==="aside"||i.kind==="text")&&e.push({kind:"paragraph",text:i.text})}return r(),[e]}function b(t){let e=t.split(`
|
|
7
|
+
`).map(o),s=e.find(n=>n.kind==="heading"&&n.level===1),r=[],i=[],a=()=>{i.length&&r.push(`<ul>${i.map(n=>`<li>${n}</li>`).join("")}</ul>`),i=[]};for(let n of e){if(n.kind==="point"){i.push(d(n.text));continue}if(a(),n.kind==="heading")r.push(`<h${n.level}>${d(n.text)}</h${n.level}>`);else if(n.kind==="link"){let l=d(n.url);r.push(`<p><a href="${l}">${l}</a></p>`)}else n.kind==="timed"?r.push(`<p><b>${d(n.time)}</b> ${d(n.text)}</p>`):n.kind==="aside"?r.push(`<p><i>${d(n.text)}</i></p>`):n.kind==="text"&&r.push(`<p>${d(n.text)}</p>`)}return a(),["<!doctype html>",`<html><head><meta charset="utf-8"><title>${s?.kind==="heading"?d(s.text):"Transcript"}</title><style>${x}</style></head><body>`,...r,"</body></html>"].join(`
|
|
8
|
+
`)}export{p as a,f as b,g as c,c as d,m as e,h as f,d as g,x as h,$ as i,b as j};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
function o(t){let e;return()=>(e??=t(),e)}var a=o(async()=>(await import("sharp")).default),i=o(()=>import("./es-T2U7NBLD.js")),l=o(()=>import("@hyzyla/pdfium")),n=o(async()=>(await import("./lib-TPEJ5CJJ.js")).default),c=o(async()=>(await import("./word-OGQ2KZAJ.js")).default),p=o(async()=>(await import("./adm-zip-SQKLKBDP.js")).default),d=o(async()=>(await import("./cfb-V6M2PYOD.js")).default);async function r(){let t=Object.getOwnPropertyDescriptor(globalThis,"localStorage");if(!t?.configurable)return import("./dist-J2V6ITHG.js");Object.defineProperty(globalThis,"localStorage",{value:void 0,configurable:!0,enumerable:t.enumerable??!1,writable:!0});try{return await import("./dist-J2V6ITHG.js")}finally{Object.defineProperty(globalThis,"localStorage",t)}}var s=o(r);export{o as a,a as b,i as c,l as d,n as e,c as f,p as g,d as h,s as i};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{h as l}from"./chunk-SNDFMJIX.js";import{r as f}from"./chunk-DZOBIUV6.js";import{y as m}from"./chunk-WIPP5TWQ.js";import{b as g,d as w}from"./chunk-KXKQDFHX.js";import{readFile as D,rm as E}from"node:fs/promises";var b=new Set(["pdf"]),x=new Set(["jpeg","png"]),I=new Set(["convert"]),y;function R(){return y??=w().then(t=>t.PDFiumLibrary.init()),y}async function h(t,r){return await(await R()).loadDocument(t,r)}async function J(t){let r=await h(t);try{let e=[];for(let n=0;n<r.getPageCount();n++)e.push(r.getPage(n).getText());return e}finally{r.destroy()}}var T={id:"pdfium",reads:b,writes:x,ops:I,probe(){throw new Error("pdfium does not probe; engines/pdf.ts classifies PDFs")},async run(t,r){if(t.op!=="convert")throw new Error(`pdfium cannot ${t.op}`);let e=t.sources[0];if(e.kind!=="document")throw new Error("the pdfium engine can only rasterise a document source");if(e.encrypted&&t.options.password===void 0)throw m(e.path);let n=t.options.dpi??150,i=t.options.pages??Array.from({length:e.pages},(o,a)=>a);if(i.length!==t.outputs.length)throw new Error(`pdfium was given ${i.length} pages but ${t.outputs.length} outputs`);for(let o of i)if(o<0||o>=e.pages)throw new Error(`pdfium was asked for page ${o}, but ${e.path} has ${e.pages} pages`);let P=await g(),d=await h(await D(e.path),t.options.password);try{let o=[],a=0;try{for(let[s,p]of i.entries()){let u=await d.getPage(p).render({scale:n/72,render:"bitmap",transparent:!0}),F=P(u.data,{raw:{width:u.width,height:u.height,channels:4}}).flatten({background:t.options.background}),S=await l(F,t.target,t.options.quality).toBuffer(),c=t.outputs[s];a+=await f(c,S),o.push(c),r({phase:"page",done:s+1,total:i.length})}}catch(s){throw await Promise.all(o.map(p=>E(p,{force:!0}))),s}return{job:t,outputBytes:a,warnings:[]}}finally{d.destroy()}}};export{h as a,J as b,T as c};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as p}from"./chunk-WE6KP4FR.js";import{c as l}from"./chunk-KH5DHZ2U.js";import{a}from"./chunk-HON4OV7M.js";import{mkdir as E,readFile as k,rename as M,unlink as v,writeFile as N}from"node:fs/promises";import{homedir as y}from"node:os";import{dirname as S,join as F}from"node:path";import{execFileSync as C}from"node:child_process";import{homedir as g}from"node:os";import{join as h}from"node:path";var b={Desktop:"[Environment]::GetFolderPath('Desktop')",Downloads:"(Get-ItemProperty 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders').'{374DE290-123F-4565-9164-39C4925E467B}'"};function w(e){try{let n=C("powershell.exe",["-NoProfile","-NonInteractive","-Command",`[Console]::OutputEncoding=[Text.Encoding]::UTF8; ${b[e]}`],{encoding:"buffer",timeout:5e3,stdio:["ignore","pipe","ignore"]}).toString("utf8").trim();return n.length>0?n:void 0}catch{return}}var m=new Map;function f(e,t=process.platform,n=w){if(t!=="win32")return h(g(),e);let r=m.get(e);if(r!==void 0)return r;let o=n(e)?.replace(/%([^%]+)%/g,(P,x)=>process.env[x]??P),d=(o!==void 0&&!o.includes("%")?o:void 0)??h(g(),e);return m.set(e,d),d}var s={defaultOutput:"~/Desktop",quality:80};function c(){return F(a(),"forge","config.json")}function W(e,t=process.platform){if(t==="win32"){if(e==="~/Desktop")return f("Desktop",t);if(e==="~/Downloads")return f("Downloads",t)}return e==="~"?y():e.startsWith("~/")?F(y(),e.slice(2)):e}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e){let t={...s},n=[];if(e.theme!==void 0&&(e.theme==="dark"||e.theme==="light"?t.theme=e.theme:n.push("theme")),e.defaultOutput!==void 0&&(typeof e.defaultOutput=="string"&&e.defaultOutput.trim().length>0?t.defaultOutput=e.defaultOutput:n.push("defaultOutput")),e.quality!==void 0){let r=e.quality;typeof r=="number"&&Number.isInteger(r)&&r>=1&&r<=100?t.quality=r:n.push("quality")}if(e.updateCheck!==void 0&&(typeof e.updateCheck=="boolean"?t.updateCheck=e.updateCheck:n.push("updateCheck")),e.rightClickMenu!==void 0&&(typeof e.rightClickMenu=="boolean"?t.rightClickMenu=e.rightClickMenu:n.push("rightClickMenu")),e.searchMac!==void 0&&(typeof e.searchMac=="boolean"?t.searchMac=e.searchMac:n.push("searchMac")),e.lastOutput!==void 0&&(typeof e.lastOutput=="string"&&e.lastOutput.trim().length>0?t.lastOutput=e.lastOutput:n.push("lastOutput")),e.transcribeFormat!==void 0&&(l(e.transcribeFormat)?t.transcribeFormat=e.transcribeFormat:n.push("transcribeFormat")),e.presets!==void 0)if(Array.isArray(e.presets)){let r=e.presets.map(p);t.presets=r.filter(i=>i!==void 0),t.presets.length<r.length&&n.push("presets")}else n.push("presets");return{prefs:t,rejected:n}}async function j(){let e;try{e=await k(c(),"utf8")}catch{return}try{let t=JSON.parse(e);return O(t)?t:void 0}catch{return}}async function H(){let e=c(),t;try{t=await k(e,"utf8")}catch(o){return o.code==="ENOENT"?{prefs:s}:{prefs:s,warning:`Could not read the config at ${e} \u2014 using defaults.`}}let n;try{n=JSON.parse(t)}catch{return{prefs:s,warning:`The config at ${e} is not valid JSON \u2014 using defaults.`}}if(!O(n))return{prefs:s,warning:`The config at ${e} is not an object \u2014 using defaults.`};let{prefs:r,rejected:i}=D(n);return i.length===0?{prefs:r}:{prefs:r,warning:`Ignored invalid config ${i.length===1?"setting":"settings"}: ${i.join(", ")}.`}}async function L(e){let t=c();await E(S(t),{recursive:!0});let r={...await j()??{}};for(let[o,u]of Object.entries(e))u!==void 0&&(r[o]=u);let i=`${t}.${process.pid}.tmp`;try{await N(i,`${JSON.stringify(r,null,2)}
|
|
4
|
+
`,"utf8"),await M(i,t)}catch(o){throw await v(i).catch(()=>{}),o}}export{f as a,s as b,c,W as d,H as e,L as f};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{execFile as f,spawn as d}from"node:child_process";import{access as u}from"node:fs/promises";import{dirname as w,win32 as l}from"node:path";import{pathToFileURL as m}from"node:url";import{promisify as p}from"node:util";var i=p(f);async function s(r){try{await i("explorer.exe",r)}catch(e){if(typeof e.code=="number")return;throw e}}var c=r=>l.normalize(r);async function t(r){try{await u(r)}catch{throw new Error(`The file ${r} does not exist.`)}}function a(r){return new Promise((e,n)=>{let o=d("xdg-open",[r],{detached:!0,stdio:"ignore"});o.once("error",n),o.once("spawn",()=>{o.unref(),e()})})}async function F(r,e=process.platform){if(e==="win32")return await t(r),s([c(r)]);if(e==="linux")return await t(r),a(r);await i("open",[r])}async function E(r,e=process.platform){if(e==="win32")return s([r]);if(e==="linux")return a(r);await i("open",[r])}async function g(r){let e=m(r).href.replace(/,/g,"%2C"),n=["/org/freedesktop/FileManager1","org.freedesktop.FileManager1.ShowItems"];try{await i("gdbus",["call","--session","--dest","org.freedesktop.FileManager1","--object-path",n[0],"--method",n[1],`['${e.replace(/'/g,"%27")}']`,"''"],{timeout:5e3})}catch(o){if(o.code!=="ENOENT")throw o;await i("dbus-send",["--session","--print-reply","--reply-timeout=5000","--dest=org.freedesktop.FileManager1",...n,`array:string:${e}`,"string:"],{timeout:6e3})}}async function S(r,e=process.platform){if(e==="win32")return await t(r),s(["/select,",c(r)]);if(e==="linux"){await t(r);try{await g(r)}catch{await a(w(r))}return}await i("open",["-R",r])}function k(r=process.platform){return r==="darwin"?"Show in Finder":r==="win32"?"Show in Explorer":"Show in Files"}export{F as a,E as b,S as c,k as d};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as L,b as O,f as T}from"./chunk-NXJGO66P.js";import{b as K,c as P,m as j,n as z,p as J,q as W,s as $}from"./chunk-OK7XOZFO.js";import{a as q,c as w}from"./chunk-GSK2A3TN.js";import{d as R}from"./chunk-Y7LOIHFU.js";import{a as M}from"./chunk-PPR7B5AR.js";import{e as B}from"./chunk-SNDFMJIX.js";import{b as I}from"./chunk-DZOBIUV6.js";import{a as k}from"./chunk-J7FLFHQJ.js";import{a as v}from"./chunk-H3DIRJFE.js";import{existsSync as E}from"node:fs";import{basename as G,dirname as H,extname as Q,join as U}from"node:path";var V={images:"an image",pdfs:"a PDF",documents:"a document",videos:"a video",audio:"audio",other:"a file Forge reads"};function X(e){let t=Object.keys(e).filter(s=>e[s]);if(t.length===0)return"not supported";let n=t.map(s=>V[s]);return`not ${n.length===1?n[0]:`${n.slice(0,-1).join(", ")} or ${n.at(-1)}`}`}function Y(e){return e.kind==="document"?e.format==="pdf"?"no images to shrink":"nothing to compress":`${v[e.format].label} is lossless`}function Z(e,t,n){if(e.kind!=="image")return{left:"images only"};let s=e,r=n===void 0?{}:{output:n};if(t.tool==="sharpen"||t.tool==="boost"){let c=t.tool==="sharpen"?1:t.scale??2;if(B(s.width,s.height,c))return{left:c===1?"too large":`too large for ${c}\xD7`};let[f]=K.plan([s],{scale:String(c),target:R(s),...r});return f?{job:f}:{left:"not supported"}}if(t.tool==="cutout"){let[c]=P.plan([s],{target:"png",...r});return c?{job:c}:{left:"not supported"}}if(t.tool==="rotate"){if(s.frames>1)return{left:"animated"};let[c]=$.plan([s],{turn:t.turn??90,...r});return c?{job:c}:{left:"not supported"}}if(t.tool==="trim"&&s.frames>1)return{left:"animated"};let o=t.tool==="trim"?J:W,[i]=o.plan([s],{target:R(s),...t.resize?{resize:t.resize}:{},...r});return i?{job:i}:{left:"not supported"}}function ee(e,t,n){if(t.op==="edit")return Z(e,t,n);if(e.kind==="media")return{left:"one at a time"};let s=n===void 0?{}:{destination:n};if(t.op==="compress"){if(!j.appliesTo([e]))return{left:Y(e)};if(t.targetBytes!==void 0&&e.bytes<=t.targetBytes)return{left:"already under that size"};let[i]=j.plan([e],{mode:t.targetBytes===void 0?"quality":"size",...t.quality===void 0?{}:{quality:t.quality},...s});return i?{job:i}:{left:"not supported"}}let r=t.answers[O(e)];if(!r)return{left:X(t.answers)};if(e.format===r.target)return{left:`already ${v[r.target].label}`};if(!M(e).includes(r.target))return{left:`can\u2019t become ${v[r.target].label}`};let[o]=z.plan([e],{target:r.target,...r.quality===void 0?{}:{quality:r.quality},...r.dpi===void 0?{}:{dpi:String(r.dpi)},pages:"all",...s});return o?.op==="convert"?{job:o}:{left:"not supported"}}function te(e,t){if(!t(e))return e;let n=Q(e),s=G(e,n);for(let r=1;;r++){let o=U(H(e),I(s,` (${r})${n}`));if(!t(o)&&!E(o))return o}}function ne(e,t,n,s={}){let r=s.existing??"leave",o=ee(e,t,s.destination);if(!("job"in o))return o;let{job:i}=o,c=i.outputs.some(a=>E(a)&&!n.has(a));if(c&&r==="leave")return{left:t.op==="compress"?"already compressed":t.op==="edit"?"already edited":"already converted"};let f=r==="number"?a=>n.has(a)||E(a):a=>n.has(a);i.outputs=i.outputs.map(a=>te(a,f));for(let a of i.outputs)n.add(a);return c&&r==="ask"?{job:i,taken:!0}:{job:i}}function S(e,t,n,s={}){let r=[],o=[],i=[];for(let c of e){let f=ne(c,t,n,s);"job"in f?(r.push(f.job),f.taken&&i.push(f.job)):o.push({path:c.path,reason:f.left})}return{jobs:r,left:o,taken:i}}async function D(e,t,n={}){let s=new Set,r=n.existing??"leave",{jobs:o,left:i}=S(e,t,s,{destination:n.destination,existing:r});return{outcome:await w(o,{force:r==="replace",...t.op==="compress"&&t.targetBytes!==void 0?{targetBytes:t.targetBytes}:{},...n.concurrency===void 0?{}:{concurrency:n.concurrency},...n.onEvent?{onEvent:n.onEvent}:{},...n.signal?{signal:n.signal}:{}}),left:i,claimed:s,jobs:o}}function C(e,t){let{outcome:n,left:s}=t,r=new Map;for(let o of n.results){let i=o.job.sources[0].path;r.set(i,{path:i,state:"done",result:o})}for(let o of[...n.refusals,...n.failures])if(o.error.code==="cannot-compress-more"){let i=o.error.short==="nothing written"?"can\u2019t get smaller":"already under that size";r.set(o.path,{path:o.path,state:"left",reason:i})}else o.error.code==="nothing-to-trim"?r.set(o.path,{path:o.path,state:"left",reason:"no empty edges"}):r.set(o.path,{path:o.path,state:"failed",reason:o.error.title.toLowerCase()});for(let o of n.unreachable){let i=o.job.sources[0].path;r.set(i,{path:i,state:"left",reason:`can\u2019t get below ${k(o.smallest)}`})}for(let o of s)r.set(o.path,{path:o.path,state:"left",reason:o.reason});return e.map(o=>r.get(o.path)??{path:o.path,state:"left",reason:n.cancelled?"stopped":"not run"})}import{watch as oe}from"node:fs";import{readdir as re,stat as se}from"node:fs/promises";import{join as ie,resolve as N}from"node:path";function _(e,t,n){let s=N(e),r=n.settleMs??1e3,o=n.pollMs??500,i=new Set([...t].map(m=>N(m))),c=new Map,f=!1,a=!1,d=!1,p=async()=>{if(!f){if(a){d=!0;return}a=!0;try{let m=await re(s,{withFileTypes:!0}).catch(()=>[]),g=new Set;for(let l of m){if(!l.isFile()||L(l.name))continue;let u=ie(s,l.name);if(g.add(u),i.has(u)||n.ignore?.(u))continue;let y=await se(u).catch(()=>{});if(!y||f)continue;let F=Date.now(),b=c.get(u);if(!b||b.size!==y.size||b.mtimeMs!==y.mtimeMs){c.set(u,{size:y.size,mtimeMs:y.mtimeMs,since:F});continue}F-b.since<r||(c.delete(u),i.add(u),n.onFile(u))}for(let l of[...i,...c.keys()])g.has(l)||(i.delete(l),c.delete(l))}finally{a=!1,d&&!f&&(d=!1,p())}}},x=setInterval(()=>{p()},o),h;try{h=oe(s,{persistent:!1},()=>{p()}),h.on("error",()=>{})}catch{}return p(),{close(){f=!0,clearInterval(x),h?.close()}}}var A=e=>"op"in e&&(e.op==="convert"||e.op==="compress"||e.op==="edit")?e:{op:"convert",answers:e};function ae(e,t,n,s){let{jobs:r,left:o}=S(e,A(t),n,{destination:s});return{jobs:r,left:o}}async function ze(e,t,n={}){return D(e.sources,A(t),n)}var ce=(e,t)=>e==="other"?t==="text"?"a text file":"not supported":"not yet supported";function Je(e){let t=q(e.concurrency),n=A(e.answers),s=[],r=new Set,o=!1,i=async a=>{e.onEvent({type:"arrived",path:a}),e.onEvent({type:"phase",path:a,phase:"reading"});let d=await T(a);if(d.kind==="failed"){e.onEvent({type:"failed",path:a,error:d.failure.error});return}if(d.kind!=="source"){e.onEvent({type:"left",path:a,reason:ce(d.kind,d.sniffed)});return}let{jobs:p,left:x}=ae([d.source],n,e.claimed,e.destination),[h]=x;if(h){e.onEvent({type:"left",path:a,reason:h.reason});return}let m=await w(p,{force:!1,concurrency:1,...n.op==="compress"&&n.targetBytes!==void 0?{targetBytes:n.targetBytes}:{},onEvent:l=>{l.type==="job:phase"&&"phase"in l.progress&&l.progress.phase!=="page"&&l.progress.phase!=="time"&&l.progress.phase!=="tiles"&&e.onEvent({type:"phase",path:a,phase:l.progress.phase,job:l.job})}}),[g]=C([d.source],{outcome:m,left:[],claimed:e.claimed,jobs:p});if(g?.result)e.onEvent({type:"converted",path:a,result:g.result});else if(g?.state==="left")e.onEvent({type:"left",path:a,reason:g.reason??""});else{let l=[...m.refusals,...m.failures][0];l&&e.onEvent({type:"failed",path:a,error:l.error})}},c=()=>{for(;!o&&r.size<t&&s.length>0;){let a=s.shift(),d=i(a).catch(()=>{}).finally(()=>{r.delete(d),c()});r.add(d)}},f=_(e.dir,e.known,{...e.settleMs===void 0?{}:{settleMs:e.settleMs},...e.pollMs===void 0?{}:{pollMs:e.pollMs},ignore:a=>e.claimed.has(a),onFile:a=>{s.push(a),c()}});return{async stop(){o=!0,f.close(),s.length=0,await Promise.all([...r])}}}export{S as a,C as b,ze as c,Je as d};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as b}from"./chunk-PPR7B5AR.js";import{j as h}from"./chunk-V3I6DSF4.js";import{d as y}from"./chunk-WIPP5TWQ.js";import{a as c}from"./chunk-H3DIRJFE.js";import{open as g,readdir as x,stat as w}from"node:fs/promises";import{extname as S,join as k,resolve as v}from"node:path";function K(e){return e.startsWith(".")||/\.(crdownload|part|download|tmp)$/i.test(e)}function A(e){return e.kind==="image"?"images":e.format==="pdf"?"pdfs":"documents"}var O=new Set(Object.values(c).flatMap(e=>e.extensions));async function R(e){let i=await g(e,"r"),n=Buffer.alloc(4096),r=0;try{r=(await i.read(n,0,n.length,0)).bytesRead}finally{await i.close()}let t=n.subarray(0,r),o=(d,f)=>t.subarray(d,d+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":t[0]===26&&t[1]===69&&t[2]===223&&t[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":t[0]===0&&t[1]===0&&t[2]===1&&(t[3]===186||t[3]===179)?"video":o(0,3)==="ID3"||o(0,4)==="fLaC"||o(0,4)==="OggS"||o(0,4)==="FORM"&&/^AIF[FC]$/.test(o(8,4))||t[0]===255&&t[1]!==void 0&&(t[1]&224)===224?"audio":r>0&&!t.includes(0)&&M(t)?"text":"other"}function M(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e,{stream:!0}),!0}catch{return!1}}var F=["images","pdfs","documents","videos","audio","other"];function j(e,i){if(e==="videos"||e==="audio")return"not yet supported";if(e==="other")return i.every(n=>n==="text")?i.length===1?"a text file":"text files":"not supported"}async function z(e){let i=v(e),n=await x(i,{withFileTypes:!0}),r=[],t=[],o=new Map,d=[],f=0;for(let u of n.sort((a,s)=>a.name.localeCompare(s.name))){if(!u.isFile()||K(u.name))continue;let a=k(i,u.name);d.push(a);let s=await E(a);if(s.kind==="source")r.push(s.source),f+=s.source.bytes;else if(s.kind==="failed")t.push(s.failure),f+=s.bytes;else{let m=s.kind,p=o.get(m)??{bytes:0,sniffed:[]};p.bytes+=s.bytes,p.sniffed.push(s.sniffed),o.set(m,p),f+=s.bytes}}let l=I(r);for(let u of F){let a=o.get(u);if(!a)continue;let s=j(u,a.sniffed);l.push({id:u,count:a.sniffed.length,bytes:a.bytes,sources:[],...s===void 0?{}:{why:s}})}return{dir:i,sources:r,failures:t,kinds:l,bytes:f,paths:d}}function I(e){let i=[];for(let n of F){let r=e.filter(t=>A(t)===n);r.length>0&&i.push({id:n,count:r.length,bytes:r.reduce((t,o)=>t+o.bytes,0),sources:r})}return i.sort((n,r)=>r.count-n.count)}function L(e,i=[]){let n=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),t=I(r);for(let o of["videos","audio"]){let d=n.filter(f=>c[f.format].media==="video"==(o==="videos"));if(d.length>0){let f=d.reduce((l,u)=>l+u.bytes,0);t.push({id:o,count:d.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:t,bytes:e.reduce((o,d)=>o+d.bytes,0),paths:e.map(o=>o.path)}}async function E(e){let i=()=>w(e).then(n=>n.size,()=>0);try{let n=await h(e);if(n.kind==="media"){let r=c[n.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:n.bytes}}return{kind:"source",source:n}}catch(n){let r=await i(),t=await R(e).catch(()=>"other");if(t==="video"||t==="audio")return{kind:t==="video"?"videos":"audio",sniffed:t,bytes:r};if(O.has(S(e).toLowerCase())){let o=y(n)?n:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:t,bytes:r}}}function D(e){let i=new Set(e.flatMap(n=>b(n).filter(r=>r!==n.format)));return Object.keys(c).filter(n=>i.has(n))}function V(e,i){let n=D(e),r=e[0],t=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=t&&n.includes(t)?t:n[0];if(o)return N(e,o,i)}function N(e,i,n){let r={target:i};return c[i].lossy&&(r.quality=n),e.some(t=>t.kind==="document"&&t.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{K as a,A as b,R as c,z as d,L as e,E as f,D as g,V as h,N as i};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as h,c as Q}from"./chunk-Q6KQWJ4J.js";import{d as L,f as b,g as X}from"./chunk-Y7LOIHFU.js";import{a as J,b as _,e as R}from"./chunk-PPR7B5AR.js";import{a as U,b as w}from"./chunk-V3I6DSF4.js";import{a as g,d as A}from"./chunk-N6RCLJE6.js";import{f as l}from"./chunk-SNDFMJIX.js";import{d as x,l as I}from"./chunk-THDAQBQ3.js";import{b as $,c as N,d as D,e as d,i as B,m as z}from"./chunk-DZOBIUV6.js";import{H as k,v as C}from"./chunk-WIPP5TWQ.js";import{a as p,b as E,c as j}from"./chunk-H3DIRJFE.js";var O=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0;function Bt(t,e){let n=J(t);return n.includes(e)?void 0:C(t,e,n)}function G(t){return{target:t.target??"png",background:typeof t.background=="string"?t.background:"#ffffff",keepMetadata:t.keepMetadata===!0,...typeof t.output=="string"?{output:t.output}:{},...t.roots instanceof Map?{roots:t.roots}:{},...typeof t.quality=="number"?{quality:t.quality}:{}}}var W=()=>({kind:"select",id:"target",label:"Save as",default:"png",choices:[{value:"png",label:"PNG",hint:p.png.hint}]}),ot=t=>t===1?"sharp":`${t}x`,it=t=>t===1||t===3||t===4?t:2,Jt={id:"boost",label:"Boost resolution",verb:"Boosting",hint:"sharper, at its size or at 2\xD7, 3\xD7 or 4\xD7",requires:"boost",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[{kind:"select",id:"scale",label:"Scale",default:"2",choices:[{value:"1",label:"Sharpen",hint:"the same size, sharper"},{value:"2",label:"2\xD7",hint:"twice the width and height"},{value:"3",label:"3\xD7",hint:"three times the width and height"},{value:"4",label:"4\xD7",hint:"four times the width and height"}]},W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e),i=it(Number(e.scale??2));return n.map(r=>({op:"boost",sources:[r],outputs:[d({sourcePath:r.path,target:o.target,suffix:ot(i),...o.output===void 0?{}:{output:o.output},...o.roots?.get(r.path)===void 0?{}:{sourceRoot:o.roots.get(r.path)}})],scale:i,target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}},_t={id:"remove-background",label:"Remove background",verb:"Removing",hint:"cut out the subject",requires:"remove-background",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e);return n.map(i=>({op:"remove-background",sources:[i],outputs:[d({sourcePath:i.path,target:o.target,suffix:"cutout",...o.output===void 0?{}:{output:o.output},...o.roots?.get(i.path)===void 0?{}:{sourceRoot:o.roots.get(i.path)}})],target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}};var rt=[{degrees:90,label:"90\xB0 right",suffix:"rotated-right"},{degrees:180,label:"180\xB0",suffix:"rotated-180"},{degrees:270,label:"90\xB0 left",suffix:"rotated-left"}],y=t=>t===90||t===180||t===270,Ut=(t,e)=>e===180?{...t}:{width:t.height,height:t.width},M=t=>rt.find(e=>e.degrees===t).suffix;import{dirname as at,join as H}from"node:path";var K="Same location",V="New subfolder";function st(t,e,n){return t===e?K:t===g("Desktop")?"Desktop":t===g("Downloads")?"Downloads":e!==void 0&&n!==void 0&&t===H(e,n)?V:h(t)||t}function T(t,e,n={}){return pt(at(t.path),e,n)}function pt(t,e,{subfolder:n}={}){let o=A(e.defaultOutput),i=e.lastOutput?A(e.lastOutput):void 0,r=f=>({label:st(f,t,n),path:f}),a=[r(o),...i?[r(i)]:[],r(g("Desktop")),...t===void 0?[]:[{label:K,path:t}],r(g("Downloads")),...n!==void 0&&t!==void 0?[{label:V,path:H(t,n)}]:[]],u=new Set,s=a.filter(f=>u.has(f.path)?!1:(u.add(f.path),!0));return{kind:"path",id:"destination",label:"Save to",default:o,presets:s,...i&&i!==o?{last:i}:{}}}var c=t=>typeof t=="string"&&t!==""?t:void 0;var ee=[2,1.5,1.25,.75,.5],ut=.25,dt=4,Y=-16;function q(t){return{wav:"m4a",aiff:"m4a",flac:"m4a",avi:"mp4",ogg:"opus"}[t]??t}var Z=t=>t.length===1&&t[0]?.kind==="media"?t[0]:void 0,ft=t=>t==="cut"||t==="mute"||t==="speed"||t==="resize"||t==="crop"||t==="rotate"||t==="loudness"||t==="extract"||t==="cleanup";function ct(t,e){let n=e.media??{},o=t.facts?.video,i=[];return e.extract&&i.push("audio"),n.cut&&i.push("trimmed"),n.mute&&i.push("muted"),n.cleanup?i.push("cleaned"):n.loudness!==void 0&&i.push("levelled"),n.speed!==void 0&&i.push(`${n.speed}x`),n.fps!==void 0&&i.push(`${n.fps}fps`),n.bitrate!==void 0&&i.push(`${n.bitrate}k`),e.crop&&i.push(I(e.crop.aspect)),e.resize&&i.push(o?b(l(o,e.resize)):"resized"),e.rotate&&i.push(M(e.rotate)),i.length===1?i[0]:"edited"}function mt(t,e){return t.map(n=>{let o=e.target??n.format,i={background:"#ffffff",keepMetadata:!1};e.media&&Object.keys(e.media).length&&(i.media=e.media),e.resize&&(i.resize=e.resize),e.rotate&&(i.rotate=e.rotate);let r=n.facts?.video;e.crop&&r&&(i.crop={aspect:e.crop.aspect,box:e.crop.box??x(r,e.crop.aspect)});let a=e.roots?.get(n.path),u=d({sourcePath:n.path,target:o,suffix:ct(n,e),...e.output===void 0?{}:{output:e.output},...a===void 0?{}:{sourceRoot:a}});return{op:"convert",sources:[n],outputs:[z(u,c(e.destination),c(e.name))],target:o,options:i}})}function S(t){let e={},n=t.cut;return n&&typeof n.start=="number"&&(e.cut={start:n.start,...typeof n.end=="number"?{end:n.end}:{}}),t.mute===!0&&(e.mute=!0),typeof t.speed=="number"&&(e.speed=t.speed),typeof t.fps=="number"&&(e.fps=t.fps),typeof t.bitrate=="number"&&(e.bitrate=t.bitrate),typeof t.loudness=="number"&&(e.loudness=t.loudness),t.cleanup===!0&&(e.cleanup=!0),Object.keys(e).length?e:void 0}var ne={id:"media-edit",label:"Edit",verb:"Editing",hint:"trim, mute, speed, resize, rotate, crop",appliesTo:t=>Z(t)!==void 0,unavailable:()=>"one video or audio file",options:()=>[],plan(t,e){let n=Z(t);if(!n||!ft(e.tool))return[];let o=e.tool,i={...typeof e.output=="string"?{output:e.output}:{},destination:e.destination,name:e.name};if(o==="cut"){let r=S(e)?.cut;if(!r)return[];i.media={cut:r}}if(o==="mute"&&(i.media={mute:!0}),o==="speed"){let r=e.speed;if(typeof r!="number"||r===1||r<ut||r>dt)return[];i.media={speed:r}}if(o==="loudness"&&(i.media={loudness:typeof e.loudness=="number"?e.loudness:Y}),o==="cleanup"){if(!n.facts?.audio)return[];i.media={cleanup:!0,loudness:Y}}if(o==="extract"){let r=n.facts?.audio;if(!r||!n.facts?.video)return[];i.extract=!0,i.target=Q(r.codec)}if(o==="resize"){if(typeof e.resize!="object"||e.resize===null)return[];i.resize=e.resize}if(o==="rotate"){if(!n.facts?.video||!y(e.turn))return[];i.rotate=e.turn}if(o==="crop"){let r=e.crop;if(!r?.aspect||!n.facts?.video)return[];i.crop=r}return mt([n],i)}};import{dirname as lt,join as gt}from"node:path";var ht=t=>p[t.format].media==="video",bt=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,yt=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,St="-small",m={min:30,max:100,step:35},kt=t=>{let e=Math.ceil((t-m.min)/m.step);return Math.min(m.max,m.min+Math.max(0,e)*m.step)},fe={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=bt(t);if(e!==void 0){let o=p[e.format];return o.lossy||o.quantisable===!0}return(yt(t)?.images?.compressible??0)>0},options(t,e,n){let o=t[0];if(!o)return[];let i=[{kind:"select",id:"mode",label:`Compress ${h(o.path)??"this file"}`,choices:[o.kind==="media"?{value:"quality",label:"By quality"}:{value:"quality",label:"By quality",hint:"pick a level, see the result"},{value:"size",label:"To a target size",hint:"smallest quality that fits"}],default:"quality"}];if(e.mode==="quality"&&o.kind==="media"&&!ht(o))i.push({kind:"slider",id:"bitrate",label:"Quality",min:32,max:320,step:32,default:96});else if(e.mode==="quality"){let r=o.kind==="image"&&p[o.format].quantisable===!0;i.push(r?{kind:"slider",id:"quality",label:"Quality",...m,default:kt(n.quality),points:!0}:{kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality})}else if(e.mode==="size")i.push({kind:"text",id:"size",label:"Target size",placeholder:"e.g. 500kb or 2mb"});else return i;return i.push(T(o,n)),i},plan(t,e){let n=e.mode;if(n!=="quality"&&n!=="size")throw k(`compressAction.plan() needs a mode of "quality" or "size", got ${JSON.stringify(n)}.`,"This is a caller bug, not a user-facing condition: walk options() before calling plan().");let o=t[0];if(!o)return[];let i=(h(o.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:lt(o.path),a=o.kind==="media"?q(o.format):o.format,u=gt(r,$(i,`${St}${j(a)}`)),s=o.kind==="media"?S(e):void 0;return[{op:"convert",sources:[o],target:a,outputs:[u],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...s?{media:s}:{}}}]}};function xt(t){return{kind:"select",id:"pages",label:"Pages",default:"all",choices:[{value:"all",label:"All pages",hint:`${t.pages} pages`},{value:"first",label:"First page only"},{value:"choose",label:"Choose pages",hint:"pick which ones"}]}}function It(){return{kind:"select",id:"dpi",label:"Resolution",default:"150",choices:[{value:"72",label:"72 dpi",hint:"screen"},{value:"150",label:"150 dpi",badge:"default"},{value:"300",label:"300 dpi",hint:"print"}]}}function zt(t,e){return Array.isArray(e)?w(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?w(U(e,t.pages)):Array.from({length:t.pages},(n,o)=>o)}function Ot(t,e){let n=p[t.format].lossy,o=p[e].lossy;if(n&&!o)return{hint:"likely bigger",tone:"warn"};if(!n&&o)return{hint:"likely smaller",tone:"ok"}}function Mt(t){let e=_(t).filter(o=>o.id!==t.format),n=e[0];return{kind:"select",id:"target",label:`Convert ${p[t.format].label} to`,choices:e.map(o=>{let i=Ot(t,o.id);return{value:o.id,label:o.label,hint:i?.hint??o.hint,...i===void 0?{}:{tone:i.tone}}}),default:n?n.id:""}}function Tt(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var Ft=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function At(t){let e=t.target,n=typeof e=="string"?E(e):void 0;if(!n)throw k(`convertAction.plan() requires a valid target format, got ${JSON.stringify(e)}.`,"This is a caller bug, not a user-facing condition: call options() and pass one of the target select choices before calling plan().");return n}var ke={id:"convert",label:"Convert",verb:"Converting",hint:"to another format",appliesTo:t=>t.length>=1,options(t,e,n){let o=t[0];if(!o)return[];let i=[Mt(o)],r=e.target;if(typeof r!="string")return i;o.kind==="document"&&R(r)&&i.push(xt(o),It());let a=p[r];return o.kind==="media"?a?.media==="sound"&&a.lossy&&i.push(Tt(r)):a?.lossy&&a.media===void 0&&i.push({kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality}),i.push(T(o,n)),i},plan(t,e){let n=t[0];if(!n)return[];let o=At(e),i=o.id,r={background:typeof e.background=="string"?e.background:"#ffffff",keepMetadata:e.keepMetadata===!0};if(o.lossy&&typeof e.quality=="number"&&(r.quality=e.quality),n.kind==="media"){let s=S(e);s&&(r.media=s),Ft(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&R(i)){let s=Number(e.dpi);r.dpi=Number.isFinite(s)&&s>0?s:150;let f=zt(n,e.pages);r.pages=f;let et=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,nt=B(n.path,f,i,a,et);return[{op:"convert",sources:[n],outputs:nt,target:i,options:r}]}let u=D({sourcePath:n.path,target:i,...a===void 0?{}:{output:`${a}/`}});return N(u,n.path)&&(u=d({sourcePath:n.path,target:i,suffix:i,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[u],target:i,options:r}]}};function Rt(t,e){if(!e.rotate)return v(t,e);let n=M(e.rotate);return e.trim||e.crop||e.resize?`${v(t,e)}-${n}`:n}function v(t,e){if(e.crop){let n=I(e.crop.aspect);if(!e.resize)return n;let o=e.crop.box??x(t,e.crop.aspect);return`${n}-${b(l(o,e.resize))}`}return e.trim&&e.resize?`trimmed-${X(e.resize)}`:e.resize?b(l(t,e.resize)):"trimmed"}function wt(t,e){if(e.trim&&e.crop)throw new Error("planEdit cannot trim and crop the same image");return t.map(n=>{let o=e.target??L(n),i={background:e.background,keepMetadata:e.keepMetadata,...e.quality===void 0?{}:{quality:e.quality},...e.trim?{trim:!0}:{},...e.resize?{resize:e.resize}:{},...e.crop?{crop:e.crop}:{},...e.rotate?{rotate:e.rotate}:{}},r=e.roots?.get(n.path),a=d({sourcePath:n.path,target:o,suffix:Rt(n,e),...e.output===void 0?{}:{output:e.output},...r===void 0?{}:{sourceRoot:r}});return{op:"convert",sources:[n],outputs:[z(a,c(e.destination),c(e.name))],target:o,options:i}})}var P=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0,Pt=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t),tt=t=>typeof t=="object"&&t!==null&&"aspect"in t&&typeof t.aspect=="object"&&t.aspect!==null&&"w"in t.aspect&&"h"in t.aspect;function F(t,e,n,o){return{id:t,label:e,verb:n,hint:o,appliesTo:i=>P(i)?.every(r=>t==="resize"||r.frames<=1)===!0,unavailable:i=>P(i)?"animated":"images only",options:()=>[],plan(i,r){let a=P(i);return a?t==="crop"&&!tt(r.crop)?[]:t==="turn"&&!y(r.turn)?[]:wt(a,{trim:t==="trim"||r.trim===!0,...y(r.turn)?{rotate:r.turn}:{},...Pt(r.resize)?{resize:r.resize}:{},...tt(r.crop)?{crop:r.crop}:{},...typeof r.target=="string"?{target:r.target}:{},...typeof r.output=="string"?{output:r.output}:{},...r.roots instanceof Map?{roots:r.roots}:{},destination:r.destination,name:r.name,background:typeof r.background=="string"?r.background:"#ffffff",keepMetadata:r.keepMetadata===!0,...typeof r.quality=="number"?{quality:r.quality}:{}}):[]}}}var Fe=F("trim","Trim edges","Trimming edges","cut empty borders"),Ae=F("resize","Resize","Resizing","smaller or larger"),Re=F("crop","Crop to shape","Cropping","change the shape"),we=F("turn","Rotate","Rotating","turn it");export{Bt as a,Jt as b,_t as c,V as d,T as e,pt as f,c as g,rt as h,Ut as i,ee as j,mt as k,ne as l,fe as m,ke as n,wt as o,Fe as p,Ae as q,Re as r,we as s};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{l as P}from"./chunk-HOZ6XGQQ.js";import{c as k,e as I,f as $}from"./chunk-HKINXTUW.js";import{L as S,pa as E,ra as m,y as x}from"./chunk-WIPP5TWQ.js";var D=new Set(["youtube.com","www.youtube.com","m.youtube.com","music.youtube.com"]),M=/^[A-Za-z0-9_-]{11}$/,w=t=>t&&M.test(t)?{kind:"video",id:t,url:`https://www.youtube.com/watch?v=${t}`}:void 0;function Z(t){let r=t.trim();if(r==="")return;let e;try{e=new URL(/^[a-z]+:\/\//i.test(r)?r:`https://${r}`)}catch{return}let n=e.hostname.toLowerCase();if(n==="youtu.be")return w(e.pathname.slice(1).split("/")[0]);if(!D.has(n))return;let[s,o]=e.pathname.split("/").filter(Boolean);if(s==="watch")return w(e.searchParams.get("v"));if(s==="shorts"||s==="live")return w(o);if(s==="playlist"&&e.searchParams.get("list"))return{kind:"playlist"}}var R="Summary and notes by Apple Intelligence. They may contain mistakes.";function N(t){let r=Math.floor(t),e=o=>String(o).padStart(2,"0"),n=Math.floor(r/3600),s=Math.floor(r/60)%60;return n>0?`${n}:${e(s)}:${e(r%60)}`:`${s}:${e(r%60)}`}var L=t=>t.split(/\s+/).filter(Boolean).length,V=60,j=140,Y=1,W=10;function H(t){let r=[],e;for(let n of t){if(e){let s=n.start-e.end;if(!(s>W||s>Y&&e.words>=V||e.words>=j)){e.text+=` ${n.text}`,e.end=n.end,e.words+=L(n.text);continue}r.push({start:e.start,text:e.text})}e={start:n.start,end:n.end,text:n.text,words:L(n.text)}}return e&&r.push({start:e.start,text:e.text}),r}var T=t=>H(t).flatMap(r=>[`**${N(r.start)}** ${r.text}`,""]),B=t=>/^https?:\/\/\S+$/.test(t)?`<${t}>`:t;function Q(t,r,{transcript:e=!0}={}){let n=[`# ${r.title}`,"",B(r.from),""],s=t.notes;if(!s)return[...n,...T(t.segments)].join(`
|
|
4
|
+
`);let o=s.parts,p=a=>{let d=o[a];return d?`### ${d.refused?`Part ${a+1}`:d.heading} \xB7 ${N(d.start)}`:""};n.push(s.summary,"","## Notes",""),o.forEach((a,d)=>{n.push(p(d),""),a.points.length>0&&n.push(...a.points.map(l=>`- ${l}`),"")});let c=[`_${R}_`,""];return e?(n.push("## Transcript",""),o.forEach((a,d)=>{let l=o[d+1]?.start??Number.POSITIVE_INFINITY,b=t.segments.filter(h=>h.start>=a.start&&h.start<l);n.push(p(d),"",...T(b))}),[...n,...c].join(`
|
|
5
|
+
`)):[...n,...c].join(`
|
|
6
|
+
`)}function tt(t){let r=[...t].map(e=>(e.codePointAt(0)??0)<32?" ":e).join("").replace(/[/\\:*?"<>|]/g,"-").replace(/\s+/g," ").trim().slice(0,120).replace(/^\.+/,"");return r===""?"transcript":r}function nt(t){if(t.kind!=="media"){if(t.kind==="image"){let{path:r,format:e,bytes:n,width:s,height:o}=t;return{what:"image",path:r,format:e,bytes:n,width:s,height:o}}if(t.format!=="pdf")throw E(t.path);if(t.encrypted)throw x(t.path);return{what:"pdf",path:t.path,bytes:t.bytes,pages:t.pages}}}import{spawn as _}from"node:child_process";import{mkdtemp as C,rm as K}from"node:fs/promises";import{tmpdir as U}from"node:os";import{join as A}from"node:path";import{createInterface as G}from"node:readline";var z=[[/private video/i,"This video is private."],[/confirm your age/i,"This video is age-restricted."],[/members-only|join this channel/i,"This video is for channel members only."],[/live event will begin|premieres in/i,"This video has not started yet."],[/unavailable|has been removed|does not exist/i,"This video is unavailable."]],g=class extends Error{};function J(t=process.platform,r=process.arch){let e=I("yt-dlp");return e!==void 0&&$(e,t,r)!==void 0?S("yt-dlp"):m(`YouTube links on ${k(t)} need yt-dlp on your PATH.`,void 0,{hint:"Install yt-dlp (https://github.com/yt-dlp/yt-dlp) and put it on your PATH.",shellHint:"Install yt-dlp and put it on your PATH."})}async function ft(t,r={}){let e=await P();if(e===void 0)throw J();let n=await C(A(U(),"forge-yt-"));r.onDir?.(n);let s=()=>K(n,{recursive:!0,force:!0});try{let o;try{o=await F(e.entry,t,n,r)}catch(p){if(!(p instanceof g))throw p;if(e.own)throw m(`yt-dlp could not fetch this video: ${p.message}`,p);await X(e.entry,r.signal);try{o=await F(e.entry,t,n,r)}catch(c){throw c instanceof g?m(`yt-dlp could not fetch this video: ${c.message}`,c):c}}return{...o,dispose:s}}catch(o){throw await s(),o}}function F(t,r,e,n){let{signal:s}=n;if(s?.aborted)return Promise.reject(s.reason??new Error("aborted"));let o=["--js-runtimes",`node:${process.execPath}`,"--no-playlist","--no-warnings","--newline","--progress","-f","bestaudio[ext=m4a]/bestaudio","--print","before_dl:forge-facts %(.{title,uploader,duration,is_live})j","--progress-template","download:forge-bytes %(progress.downloaded_bytes)s %(progress.total_bytes,progress.total_bytes_estimate)s","--print","after_move:forge-file %(filepath)s","--no-simulate","-o",A(e,"sound.%(ext)s"),r];return new Promise((p,c)=>{let a=_(t,o,{stdio:["ignore","pipe","pipe"]}),d,l,b="",h=!1,y=i=>{h||(h=!0,s?.removeEventListener("abort",v),i())},v=()=>{a.kill("SIGKILL"),y(()=>c(s?.reason??new Error("aborted")))};s?.addEventListener("abort",v,{once:!0}),G({input:a.stdout}).on("line",i=>{if(i.startsWith("forge-facts ")){let u=JSON.parse(i.slice(12));if(u.is_live===!0){a.kill("SIGKILL"),y(()=>c(m("Live streams cannot be transcribed.")));return}d={title:String(u.title??""),uploader:String(u.uploader??""),seconds:Number(u.duration??0)},n.onEvent?.({kind:"facts",facts:d})}else if(i.startsWith("forge-bytes ")){let[u,f]=i.slice(12).split(" ").map(Number);Number.isFinite(u)&&Number.isFinite(f)&&(f??0)>0&&n.onEvent?.({kind:"bytes",done:u,total:f})}else i.startsWith("forge-file ")&&(l=i.slice(11))}),a.stderr.on("data",i=>{b+=i.toString()}),a.on("error",i=>y(()=>c(new g(i.message)))),a.on("close",i=>y(()=>{if(i===0&&d!==void 0&&l!==void 0)return p({path:l,facts:d});let u=b.match(/ERROR: (?:\[[^\]]*\] )?(?:[\w-]+: )?(.*)/)?.[1]?.trim()??"",f=z.find(([O])=>O.test(u));c(f?m(f[1]):new g(u||`yt-dlp exited ${i}`))}))})}function X(t,r){return new Promise((e,n)=>{let s=_(t,["--update"],{stdio:"ignore"}),o=()=>s.kill("SIGKILL");r?.addEventListener("abort",o,{once:!0}),s.on("error",()=>e()),s.on("close",()=>{r?.removeEventListener("abort",o),r?.aborted?n(r.reason??new Error("aborted")):e()})})}export{Z as a,N as b,Q as c,tt as d,nt as e,J as f,ft as g};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{e as c}from"./chunk-HKINXTUW.js";import{a}from"./chunk-HON4OV7M.js";import{access as x,readFile as p}from"node:fs/promises";import{join as n,sep as y}from"node:path";function g(){return n(a(),"forge","extensions")}var E=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;async function v(e){if(c(e)!==void 0)try{let u=n(g(),e),t=(await p(n(u,"current"),"utf8")).trim();if(!E.test(t))return;let r=n(u,t),i=JSON.parse(await p(n(r,"manifest.json"),"utf8"));if(typeof i!="object"||i===null)return;let{id:m,version:l,entry:o,kind:s,files:d}=i;if(m!==e||l!==t||s!=="node"&&s!=="exec"||typeof o!="string"||typeof d!="object"||d===null||!(o in d))return;let f=n(r,o);return f.startsWith(`${r}${y}`)?(await x(f),{id:e,version:t,dir:r,entry:f,kind:s}):void 0}catch{return}}export{g as a,E as b,v as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{f as a}from"./chunk-V3I6DSF4.js";import{c as i}from"./chunk-LVYQVJOF.js";import{a as e}from"./chunk-H3DIRJFE.js";function s(t){let o=Object.keys(e);return[...t].sort((r,n)=>o.indexOf(r)-o.indexOf(n))}function f(t){let o=new Set;for(let r of a)if(r.reads.has(t.format))for(let n of r.writesFor?.(t)??r.writes)e[n].keepsOnly&&n!==t.format||o.add(n);return s([...o])}function F(t){return f(t).map(o=>({id:o,label:e[o].label,hint:e[o].hint,lossy:e[o].lossy}))}function d(){let t=new Set;for(let o of a)for(let r of o.reads)t.add(r);return s([...t])}function l(){let t=new Set;for(let o of a)for(let r of o.writes)t.add(r);return s([...t])}function p(t){return i.writes.has(t)}function I(){let t=new Set(d()),o=new Set(l());return s([...new Set([...t,...o])]).map(r=>({id:r,label:e[r].label,extensions:[...e[r].extensions],read:t.has(r),write:o.has(r),lossy:e[r].lossy}))}export{f as a,F as b,d as c,l as d,p as e,I as f};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{d as s,h as a}from"./chunk-EEQSUBBL.js";import{a as r}from"./chunk-J7FLFHQJ.js";import{a as i}from"./chunk-H3DIRJFE.js";import{win32 as d}from"node:path";function l(n,e=process.platform){return e==="win32"?d.basename(n):n.split("/").pop()}function f(n){return n.facts?n.facts.video!==void 0:i[n.format].media==="video"}function v(n){return n==="mp3"?"mp3":n==="opus"?"opus":"m4a"}var u=n=>n===1?"mono":n===2?"stereo":`${n} channels`,m=n=>`${Math.round(n/100)/10} kHz`;function F(n){let e=r(n.bytes),o=n.facts;if(!o)return`${f(n)?"video":"sound"} \xB7 ${e}`;let t=[s(o.duration)];return o.video?(t.push(`${o.video.width}\xD7${o.video.height}`,`${o.video.fps} fps`),o.video.hdr&&t.push("HDR")):o.audio&&t.push(u(o.audio.channels),m(o.audio.sampleRate)),t.push(e),t.join(" \xB7 ")}function p(n){return n.facts?a(n.facts):void 0}function $(n){let e=p(n)??0;return[...e<1e6?["kb"]:[],...n.bytes>=1e6||e>=1e6?["mb"]:[],...n.bytes>1e9?["gb"]:[]]}var c=n=>n==="opus"?96:128;function k(n,e){let o=n.facts;if(!(!o?.audio||i[e].media!=="sound")){if(i[e].lossy)return Math.round(c(e)*1e3*o.duration/8);if(e==="wav"||e==="aiff")return Math.round(o.audio.sampleRate*o.audio.channels*2*o.duration)}}export{l as a,f as b,v as c,F as d,p as e,$ as f,k as g};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a as m}from"./chunk-
|
|
3
|
+
import{a as m}from"./chunk-PE5LAYGF.js";import{W as l}from"./chunk-WIPP5TWQ.js";import{randomBytes as h}from"node:crypto";import{link as y,mkdir as p,readdir as x,readFile as P,rename as E,rm as c,stat as L,writeFile as S}from"node:fs/promises";import{join as u}from"node:path";var b=720*60*1e3,k=600*1e3,M=200,F=600*1e3;function a(){return u(m(),".locks")}function f(t){return u(a(),`${t}.lock`)}function v(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function s(t){try{let n=JSON.parse(await P(t,"utf8"));return typeof n.pid!="number"||typeof n.token!="string"?void 0:n}catch{return}}async function d(t,n){if(n===void 0||!v(n.pid))return!0;let e=await L(t).catch(()=>{});return e!==void 0&&Date.now()-e.mtimeMs>b}async function D(t){let n=`${t}.stale-${h(4).toString("hex")}`;try{await E(t,n)}catch{return}let e=await s(n);e!==void 0&&!await d(n,e)&&await y(n,t).catch(()=>{}),await c(n,{force:!0})}async function A(){let t=await x(a()).catch(()=>[]);for(let n of t){if(!/\.lock\.(stale-)?[0-9a-f]+$/.test(n))continue;let e=u(a(),n),i=await L(e).catch(()=>{});i&&Date.now()-i.mtimeMs>F&&await c(e,{force:!0})}}async function g(t,n){await p(a(),{recursive:!0});let e=f(t),i={pid:process.pid,token:h(8).toString("hex"),at:Date.now(),...n!==void 0?{what:n}:{}},r=`${e}.${i.token}`;await S(r,JSON.stringify(i),{flag:"wx"});try{for(let o=0;o<2;o++){try{return await y(r,e),i}catch(w){if(w.code!=="EEXIST")throw w}if(!await d(e,await s(e)))return;await D(e)}return}finally{await c(r,{force:!0})}}async function T(t,n){let e=f(t);(await s(e))?.token===n.token&&await c(e,{force:!0})}async function _(t){let n=f(t),e=await s(n);if(!(e===void 0||await d(n,e)))return{pid:e.pid,...e.what!==void 0?{what:e.what}:{}}}async function H(t,n,e={}){let i=Date.now()+(e.waitMs??k);await p(a(),{recursive:!0}),await A();let r=await g(t,e.what);for(r===void 0&&(e.waitMs??k)>0&&e.onWait?.();r===void 0;){if(e.signal?.aborted)throw e.signal.reason??new Error("aborted");if(Date.now()>=i)throw l(t,await _(t),e.action??"run");await new Promise(o=>setTimeout(o,M)),r=await g(t,e.what)}try{return await n()}finally{await T(t,r)}}export{k as a,_ as b,H as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as f}from"./chunk-EKTUUKDP.js";import{execFile as s,execFileSync as i,spawn as d}from"node:child_process";var u=()=>({...process.env,LANG:process.env.LANG??"en_US.UTF-8"});function m(e,r=process.platform,n=process.env){if(e!==""){if(r==="linux"){c(Buffer.from(e,"utf8"),p(n,"copy"));return}if(r==="win32"){try{let t=s("clip.exe",()=>{});t.on("error",()=>{}),t.stdin?.end(Buffer.concat([Buffer.from([255,254]),Buffer.from(e,"utf16le")]))}catch{}return}try{let t=s("pbcopy",{env:u()},()=>{});t.on("error",()=>{}),t.stdin?.end(Buffer.from(e,"utf8"))}catch{}}}function y(e=process.platform,r=process.env){if(e==="linux")return l(p(r,"paste"));if(e==="win32")try{return i("powershell.exe",["-NoProfile","-NonInteractive","-Command","[Console]::OutputEncoding=[Text.Encoding]::UTF8; Get-Clipboard -Raw"],{encoding:"buffer",maxBuffer:67108864,timeout:5e3}).toString("utf8").replace(/\r\n$/,"")}catch{return""}try{return i("pbpaste",{encoding:"buffer",env:u(),maxBuffer:67108864,timeout:2e3}).toString("utf8")}catch{return""}}function p(e,r){return f(e).flatMap(n=>n.name==="wayland"?r==="copy"?[["wl-copy",["--type","text/plain;charset=utf-8"]]]:[["wl-paste",["--no-newline","--type","text"]]]:r==="copy"?[["xclip",["-selection","clipboard","-i"]],["xsel",["--clipboard","--input"]]]:[["xclip",["-selection","clipboard","-o"]],["xsel",["--clipboard","--output"]]])}function c(e,r){let[n,...t]=r;if(n)try{let o=d(n[0],n[1],{stdio:["pipe","ignore","ignore"],detached:!0});o.on("error",a=>{a.code==="ENOENT"&&c(e,t)}),o.stdin?.on("error",()=>{}),o.stdin?.end(e),o.unref()}catch{c(e,t)}}function l(e){for(let[r,n]of e)try{return i(r,n,{encoding:"buffer",maxBuffer:67108864,timeout:2e3,stdio:["ignore","pipe","ignore"]}).toString("utf8")}catch(t){if(t.code!=="ENOENT")return""}return""}export{m as a,y as b,p as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{d as I,k as A}from"./chunk-THDAQBQ3.js";import{n as re,o as M,q as ie}from"./chunk-DZOBIUV6.js";import{a as ae,b as ne,c as oe,d as se,e as he,f as ce,g as E}from"./chunk-TL5MACSF.js";import{E as X,H as F,M as G,_ as H,c as b,d as S,da as K,e as L,f as N,fa as Q,g as O,ga as Y,h as _,ha as Z,i as $,ia as ee,j as D,ja as te,k as q,l as U,na as x,o as W,p as J,q as V,w as j,x as v}from"./chunk-WIPP5TWQ.js";import{a as d}from"./chunk-H3DIRJFE.js";import{b as g}from"./chunk-KXKQDFHX.js";import{constants as be}from"node:fs";import{access as Se,readFile as ve,rm as xe,stat as Ie,writeFile as Ee}from"node:fs/promises";import{dirname as ze}from"node:path";function Ue(e){if(d[e].hasAlpha)return;let r=Object.keys(d).filter(t=>d[t].hasAlpha&&t!=="heic").join(", ");return F(`${d[e].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${r}.`)}var fe="1.1.0";function ge(e,r){let t=e.split(".").map(i=>Number.parseInt(i,10)||0),a=r.split(".").map(i=>Number.parseInt(i,10)||0);for(let i=0;i<Math.max(t.length,a.length);i++){let n=(t[i]??0)-(a[i]??0);if(n!==0)return n>0}return!0}function T(e){return e!==void 0&&ge(e,fe)?[2,3,4]:[2,4]}function We(e,r,t){if(e===1||T(r).some(i=>i===e))return;if(t!==void 0&&T(t).some(i=>i===e))return G("boost",`boost ${e}\xD7`,r,fe);let a=T(r).map(i=>`--boost ${i}`);return F(`No released boost makes ${e}\xD7 yet.`,`Try ${a.slice(0,-1).join(", ")} or ${a.at(-1)}.`)}var le=16384,ye=1e8;function de(e,r,t){let a=Math.max(e,r)*t;if(a>le)return{side:a};let i=e*t*r*t;if(i>ye)return{megapixels:Math.round(i/1e6)}}var w=e=>Math.max(1,Math.round(e));function k(e,r){return"percent"in r?{width:w(e.width*r.percent/100),height:w(e.height*r.percent/100)}:"width"in r?{width:w(r.width),height:w(e.height*r.width/e.width)}:{width:w(e.width*r.height/e.height),height:w(r.height)}}function pe(e){return de(e.width,e.height,1)}var Oe=new Set(["jpeg","png","webp","avif","heic","raw","gif","tiff"]),Fe=new Set(["jpeg","png","webp","avif","gif","tiff"]),Ae={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function Me(e,r){if(r.format==="heif")return r.compression==="av1"?"avif":"heic";let t=Ae[r.format??""];if(!t)throw U(e,r.format??"an unknown format");return t}async function Te(e){let r;try{r=await Ie(e)}catch(n){let h=n.code;throw h==="ENOENT"?L(e):h==="EACCES"||h==="EPERM"?O(e):h==="ENOTDIR"?_(e):h==="ELOOP"?$(e):h==="ENAMETOOLONG"?D(e):q(e,n)}if(!r.isFile())throw N(e);try{await Se(e,be.R_OK)}catch{throw O(e)}if(await ne(e)){if(!await ae())throw W(e);let n;try{n=await oe(e)}catch(h){throw v(e,"heic",h)}if(n.width===0||n.height===0)throw v(e,"heic",void 0);return{kind:"image",path:e,format:"heic",width:n.width,height:n.height,bytes:r.size,hasAlpha:n.hasAlpha,frames:1}}let t=await se(e);if(t){if(!await he())throw J(e);let n;try{n=await ce(e,t)}catch(h){throw v(e,"raw",h)}if(!n)throw V(e);return{kind:"image",path:e,format:"raw",width:n.width,height:n.height,bytes:r.size,hasAlpha:!1,frames:1}}let a=await g(),i;try{i=await a(e).metadata()}catch(n){throw j(e,n)}return{kind:"image",path:e,format:Me(e,i),width:i.autoOrient?.width??i.width??0,height:i.autoOrient?.height??i.height??0,bytes:r.size,hasAlpha:i.hasAlpha??!1,frames:i.pages??1}}function R(e,r,t,a){let i=t??d[r].defaultQuality;if(a&&d[r].quantisable)return ke(e,r,t,a);switch(r){case"jpeg":return e.jpeg({quality:i,mozjpeg:!0});case"webp":return e.webp({quality:i});case"avif":return e.avif({quality:i});case"png":return e.png({compressionLevel:9});case"gif":return e.gif();case"tiff":return e.tiff({compression:"deflate"});case"heic":throw new Error("heic is not writable; the capability graph should have prevented this");case"raw":throw new Error("raw is not writable; the capability graph should have prevented this");case"pdf":throw new Error("pdf is not an image target; the capability graph should have prevented this");case"docx":throw new Error("docx is not an image target; the capability graph should have prevented this");case"doc":throw new Error("doc is not an image target; the capability graph should have prevented this");default:throw new Error(`${r} is not an image target; the capability graph should have prevented this`)}}function ke(e,r,t,{dither:a}){let i=t??100,n=a?1:0;return r==="gif"?e.gif({interFrameMaxError:Math.round(32*(100-i)/100),dither:n}):e.png({palette:!0,quality:i,dither:n,compressionLevel:9,effort:10})}var B=(e,r)=>e.kind==="image"&&e.frames>1&&d[r].animatable;async function Re(e,r){let t=ze(r);await M(r);let a=re(r);try{return await Ee(a,e),await ie(a,r),e.length}catch(i){throw await xe(a,{force:!0}).catch(()=>{}),X(r,i)}}async function l(e,r,t,a,i,n){if(e.kind!=="image")throw new Error("pipelineFor received a non-image source");let h=i===void 0?await E(e.path,e.format):void 0,f=async()=>{await h?.cleanup()},s=(await g())(i??h?.path??e.path,a?{animated:!0}:{});if(s=s.rotate(),t.trim&&(s=s.trim()),t.crop){if(!t.crop.box)throw new Error("pipelineFor needs the crop placed (run does it)");s=s.extract(t.crop.box)}if(t.resize){if(!n&&(t.trim||t.crop))throw new Error("pipelineFor needs the resolved size to resize a cut image");let u=n??k(e,t.resize);s=s.resize(u.width,u.height,{fit:"fill"})}return t.rotate&&(s=s.rotate(t.rotate)),e.hasAlpha&&!d[r].hasAlpha&&(s=s.flatten({background:t.background})),s=t.keepMetadata?s.keepMetadata():s.keepIccProfile(),{pipeline:s,cleanup:f}}async function ot(e,r){let t={background:"#ffffff",keepMetadata:!1},{pipeline:a,cleanup:i}=await l(e,"png",t,!1);try{await a.png({compressionLevel:1}).toFile(r)}finally{await i()}}async function st(e,r,t){let{pipeline:a,cleanup:i}=await l(e,r,t,B(e,r));try{return await R(a,r,t.quality,t.compress).toBuffer()}finally{await i()}}async function Be(e){let r={width:e.width,height:e.height};if(e.frames>1)return{upright:r,trimmed:"animated"};let t=await E(e.path,e.format);try{let a=await g(),{info:i}=await a(t.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return i.width===r.width&&i.height===r.height?{upright:r,trimmed:"nothing"}:{upright:r,trimmed:{width:i.width,height:i.height}}}catch(a){throw S(a)?a:x(e.path,a)}finally{await t.cleanup()}}var me=1024;async function Ce(e){let r={background:"#ffffff",keepMetadata:!1},{pipeline:t,cleanup:a}=await l(e,"png",r,!1);try{let{data:i,info:n}=await t.resize(me,me,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0}),h=n.width*n.height,f=n.channels,o=new Uint8Array(h*3),s=new Uint8Array(h),u=!1;for(let m=0;m<h;m++){for(let c=0;c<3;c++)o[m*3+c]=i[m*f+(f>=4?c:0)]??0;s[m]=i[m*f+f-1]??255,s[m]!==255&&(u=!0)}return{size:{width:e.width,height:e.height},thumb:{width:n.width,height:n.height,rgb:o,...u?{alpha:s}:{}}}}catch(i){throw S(i)?i:x(e.path,i)}finally{await a()}}var ue=128;async function Pe(e,r){let{thumb:t,size:a}=e,i=I(t,r),n=await g(),{info:h}=await n(Le(t),{raw:{width:t.width,height:t.height,channels:3}}).resize(i.width,i.height,{fit:"cover",position:n.strategy.attention}).raw().toBuffer({resolveWithObject:!0}),f=I(a,r),o=Math.round(-(h.cropOffsetLeft??0)*a.width/t.width),s=Math.round(-(h.cropOffsetTop??0)*a.height/t.height);return{...f,left:Math.min(Math.max(o,0),a.width-f.width),top:Math.min(Math.max(s,0),a.height-f.height)}}function Le(e){let{alpha:r}=e;if(!r)return e.rgb;let t=new Uint8Array(e.rgb.length);for(let a=0;a<t.length;a++){let i=(r[Math.floor(a/3)]??255)/255;t[a]=Math.round(ue+((e.rgb[a]??0)-ue)*i)}return t}async function Ne(e,r){if(e.op!=="convert")throw new Error(`image engine cannot ${e.op}`);let t=e.sources[0],a=e.outputs[0];if(t.kind!=="image")throw new Error("the image engine cannot convert a document source");let i=d[e.target],n=[];r({phase:"reading"});let h=t.frames>1,f=B(t,e.target);h&&!i.animatable&&n.push({code:"animation-flattened",message:`${b(t.path)} has ${t.frames} frames, and ${i.label} cannot animate. Only the first frame was converted.`});let o=e.options,s;if(o.rotate&&h)throw te(t.path);if(o.trim||o.crop||o.resize){let c={width:t.width,height:t.height};if(o.trim&&o.crop)throw new Error("a job cannot both trim and crop");if(o.crop){if(h)throw ee(t.path);let{aspect:p}=o.crop,C=z=>z.width===t.width&&z.height===t.height,P=I(c,p),y=o.crop.box??(C(P)?P:await Pe(await Ce(t),p));if(C(y)){if(!o.resize)throw Z(t.path,A(p));n.push({code:"nothing-cropped",message:`${b(t.path)} is already ${A(p)}; resized only.`});let{crop:z,...we}=o;o=we}else o={...o,crop:{aspect:p,box:y}},c={width:y.width,height:y.height}}if(o.trim){if(h)throw Y(t.path);let{trimmed:p}=await Be(t);if(p==="nothing"){if(!o.resize)throw Q(t.path);n.push({code:"nothing-trimmed",message:`${b(t.path)} has no empty edges; resized only.`})}else p!=="animated"&&(c=p)}if(o.resize&&(s=k(c,o.resize),pe(s)))throw H(t.path,s)}r({phase:"decoding"});let{pipeline:u,cleanup:m}=await l(t,e.target,o,f,void 0,s);try{await M(a),r({phase:"encoding"});let c=await R(u,e.target,o.quality,o.compress).toBuffer();if(o.compress&&c.length>=t.bytes)throw K(t.path,t.bytes,c.length);r({phase:"writing"});let p=await Re(c,a);return{job:e,outputBytes:p,warnings:n}}catch(c){throw S(c)?c:x(t.path,c)}finally{await m()}}async function _e(e){let r=await E(e.path,e.format);try{return await ve(r.path)}finally{await r.cleanup()}}async function $e(e){if(e.op!=="convert")return;let r=d[e.target];if(!r.lossy&&!(r.quantisable&&e.options.compress))return;let t=e.sources[0];if(t.kind!=="image")return;let a=await _e(t);return{ladder:[{}],measure:async i=>{let{pipeline:n}=await l(t,e.target,i,B(t,e.target),a);return(await R(n,e.target,i.quality,i.compress).toBuffer()).length}}}var ht={id:"image",reads:Oe,writes:Fe,ops:new Set(["convert"]),probe:Te,run:Ne,measurer:$e};export{Ue as a,T as b,We as c,le as d,de as e,k as f,pe as g,R as h,Re as i,ot as j,st as k,Be as l,Ce as m,Pe as n,ht as o};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{c as f}from"./chunk-N6RCLJE6.js";import{randomBytes as g}from"node:crypto";import{mkdir as N,readFile as b,rename as x,rm as y,writeFile as k}from"node:fs/promises";import{dirname as l,join as E}from"node:path";var A="https://registry.npmjs.org/forge-terminal/latest",C=1440*60*1e3,R=3e3,O=/^(\d+)\.(\d+)\.(\d+)$/;function a(t){let e=O.exec(t);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:void 0}function P(t,e){let n=a(t),o=a(e);if(!n||!o)return!1;for(let r=0;r<3;r++)if(n[r]!==o[r])return n[r]>o[r];return!1}function D(t,e=process.env){return!(t.updateCheck===!1||e.CI!==void 0&&e.CI!==""&&e.CI!=="false"||e.FORGE_NO_UPDATE_CHECK!==void 0&&e.FORGE_NO_UPDATE_CHECK!=="")}var S=20,_=22,T=200;function U(t){let e=t.codePointAt(0)??0;return e>=32&&(e<127||e>159)}var d=(t,e)=>typeof t=="string"?[...t].filter(U).join("").trim().slice(0,e):"";function p(t){if(!Array.isArray(t))return;let e=t.map(n=>{let{title:o,text:r}=typeof n=="object"&&n!==null?n:{};return{title:d(o,_),text:d(r,T)}}).filter(n=>n.title!==""&&n.text!=="").slice(0,S);return e.length>0?e:void 0}function h(){return E(l(f()),"update-check.json")}async function c(){try{let t=JSON.parse(await b(h(),"utf8"));if(typeof t!="object"||t===null)return;let{checkedAt:e,latest:n,notifiedAt:o,whatsNew:r}=t;if(typeof e!="number")return;let s=typeof n=="string"&&a(n)!==void 0,i=s?p(r):void 0;return{checkedAt:e,...s?{latest:n}:{},...typeof o=="number"?{notifiedAt:o}:{},...i?{whatsNew:i}:{}}}catch{return}}async function F(t){let e=h();await N(l(e),{recursive:!0});let n=`${e}.${g(4).toString("hex")}.tmp`;try{await k(n,`${JSON.stringify(t)}
|
|
4
4
|
`),await x(n,e)}catch(o){throw await y(n,{force:!0}).catch(()=>{}),o}}function L(t,e=Date.now()){return t===void 0?!0:t.checkedAt>e||e-t.checkedAt>C}async function $(t={}){return(await w(t))?.version}async function w(t){let e=t.fetchImpl??fetch,n=AbortSignal.timeout(t.timeoutMs??R),o=t.signal?AbortSignal.any([t.signal,n]):n;try{let r=await e(A,{signal:o,headers:{accept:"application/json"}});if(!r.ok)return;let s=await r.json(),{version:i,whatsNew:m}=s??{};if(typeof i!="string"||!a(i))return;let u=p(m);return u?{version:i,whatsNew:u}:{version:i}}catch{return}}async function G(t={}){let e=await w(t),n=await c(),o=e??(n?.latest!==void 0?n:void 0),r=e?.version??n?.latest,s={checkedAt:t.now??Date.now(),...r!==void 0?{latest:r}:{},...n?.notifiedAt!==void 0?{notifiedAt:n.notifiedAt}:{},...o?.whatsNew!==void 0?{whatsNew:o.whatsNew}:{}};return await F(s).catch(()=>{}),e?.version}async function H(t){let e=await c();return e?.latest===t?e.whatsNew??[]:[]}async function J(t){let e=(await c())?.latest;return e!==void 0&&P(e,t)?e:void 0}export{A as a,C as b,P as c,D as d,S as e,_ as f,T as g,h,c as i,F as j,L as k,$ as l,G as m,H as n,J as o};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{H as $}from"./chunk-WIPP5TWQ.js";var _=[{w:1,h:1,label:"1:1"},{w:4,h:5,label:"4:5"},{w:16,h:9,label:"16:9"},{w:9,h:16,label:"9:16"}],v=20,D=10,p=t=>Math.max(1,Math.round(t)),u=(t,e,n)=>Math.min(Math.max(t,e),n);function P(t,e){let n=p(t.width*e.h/e.w),[r,i]=n<=t.height?[t.width,n]:[Math.min(t.width,p(t.height*e.w/e.h)),t.height];return{left:Math.floor((t.width-r)/2),top:Math.floor((t.height-i)/2),width:r,height:i}}var T=(t,e)=>e.width===t.width&&e.height===t.height;function N(t){return _.filter(e=>!T(t,P(t,e)))}function W(t,e,n,r){let i=P(t,e),o,h;return e.w>=e.h?(o=p(i.width*r/100),h=Math.min(t.height,p(o*e.h/e.w))):(h=p(i.height*r/100),o=Math.min(t.width,p(h*e.w/e.h))),{left:u(Math.round(n.x-o/2),0,t.width-o),top:u(Math.round(n.y-h/2),0,t.height-h),width:o,height:h}}function k(t,e,n,r){return{...e,left:u(e.left+n,0,t.width-e.width),top:u(e.top+r,0,t.height-e.height)}}function E(t,e){return{x:e.width<t.width,y:e.height<t.height}}function H(t){return{x:t.left+t.width/2,y:t.top+t.height/2}}function Z(t,e){return Math.round(e.width*e.height*100/(t.width*t.height))}var F=t=>`${t.w}:${t.h}`,I=t=>`cropped-${t.w}x${t.h}`;function L(t){let e=/^(\d{1,3}):(\d{1,3})$/.exec(t.trim()),n=Number(e?.[1]),r=Number(e?.[2]);if(!e||n<1||n>100||r<1||r>100)throw $(`"${t}" is not a shape; it takes two whole numbers from 1 to 100, as W:H.`,"Try --crop 1:1 or --crop 16:9.");return{w:n,h:r}}function q(t,e,n){let r=n*2,i=new Uint8Array(e*r*3),o=t.alpha?new Uint8Array(e*r):void 0,h=t.width/e,M=t.height/r;for(let c=0;c<r;c++){let w=c*M,y=w+M;for(let s=0;s<e;s++){let f=s*h,b=f+h,A=0,S=0,B=0,a=0,x=0;for(let d=Math.floor(w);d<Math.min(Math.ceil(y),t.height);d++){let R=Math.min(d+1,y)-Math.max(d,w);for(let l=Math.floor(f);l<Math.min(Math.ceil(b),t.width);l++){let C=d*t.width+l,U=(Math.min(l+1,b)-Math.max(l,f))*R,m=U*(t.alpha?(t.alpha[C]??0)/255:1),g=C*3;A+=(t.rgb[g]??0)*m,S+=(t.rgb[g+1]??0)*m,B+=(t.rgb[g+2]??0)*m,a+=m,x+=U}}let O=c*e+s;a>0&&i.set([A/a,S/a,B/a].map(Math.round),O*3),o&&x>0&&(o[O]=Math.round(a*255/x))}}return{cols:e,dotRows:r,rgb:i,...o?{alpha:o}:{}}}export{_ as a,v as b,D as c,P as d,N as e,W as f,k as g,E as h,H as i,Z as j,F as k,I as l,L as m,q as n};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{o as S,p as B}from"./chunk-WIPP5TWQ.js";import{b as E}from"./chunk-KXKQDFHX.js";import{execFile as X}from"node:child_process";import{randomBytes as Y}from"node:crypto";import{mkdtemp as tt,open as H,readFile as et,rm as U}from"node:fs/promises";import{tmpdir as F}from"node:os";import{join as P}from"node:path";import{promisify as nt}from"node:util";var M=nt(X),J=async()=>({...await import("./paths-EOYKOUBC.js"),...await import("./run-HGZVOXRW.js")}),I,N=t=>t!=="darwin";async function C(t=process.platform){return N(t)?await(await J()).installed("heic")!==void 0:D()}async function D(){if(I!==void 0)return I;try{await M("/usr/bin/sips",["--help"],{timeout:5e3}),I=!0}catch{I=!1}return I}async function O(t,n=process.platform){if(N(n))return rt(t,n);let e=P(F(),`forge-heic-${Y(8).toString("hex")}.png`),i=async()=>{await U(e,{force:!0}).catch(()=>{})};try{return await M("/usr/bin/sips",["-s","format","png",t,"--out",e],{timeout:12e4}),{path:e,cleanup:i}}catch(r){throw await i(),r}}async function W(t,n){let{installed:e,runExtension:i}=await J(),r=await e("heic");if(r===void 0)throw S(t,n);return{ext:r,runExtension:i}}async function rt(t,n){let e=await tt(P(F(),"forge-heic-")),i=async()=>{await U(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await W(t,n),a=P(e,"decoded.rgba"),d=P(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t});return await(await E())(await et(a),{raw:{width:m,height:y,channels:4}}).png().toFile(d),await U(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}var it=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),ot=new Set(["avif","avis"]);async function At(t){let n;try{n=await H(t,"r")}catch{return!1}try{let e=Buffer.alloc(64),{bytesRead:i}=await n.read(e,0,64,0);if(i<12||e.toString("latin1",4,8)!=="ftyp")return!1;let r=Math.min(e.readUInt32BE(0),i),o=[];for(let a=8;a+4<=r;a+=4)o.push(e.toString("latin1",a,a+4));return o.some(a=>ot.has(a))?!1:o.some(a=>it.has(a))}catch{return!1}finally{await n.close().catch(()=>{})}}async function kt(t,n=process.platform){if(N(n)){let{ext:a,runExtension:d}=await W(t,n),m=await d(a,["--info","--in",t],{subject:t});return{width:m.width,height:m.height,hasAlpha:m.hasAlpha??!0}}let{stdout:e}=await M("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",t],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(e)?.[1]??0),r=Number(/pixelHeight:\s*(\d+)/.exec(e)?.[1]??0),o=await at(t);return{width:o?r:i,height:o?i:r,hasAlpha:/hasAlpha:\s*yes/i.test(e)}}function*g(t,n,e){let i=n;for(;i+8<=e;){let r=t.readUInt32BE(i),o=8;if(r===1&&i+16<=e?(r=Number(t.readBigUInt64BE(i+8)),o=16):r===0&&(r=e-i),r<o)return;yield{type:t.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+r,e)},i+=r}}async function at(t){let n=await H(t,"r");try{let e=Buffer.alloc(262144),{bytesRead:i}=await n.read(e,0,e.length,0),r=[...g(e,0,i)].find(l=>l.type==="meta");if(!r)return!1;let o=[...g(e,r.start+4,r.end)],a=o.find(l=>l.type==="pitm"),d=o.find(l=>l.type==="iprp");if(!a||!d)return!1;let m=e.readUInt8(a.start)===0?e.readUInt16BE(a.start+4):e.readUInt32BE(a.start+4),y=[...g(e,d.start,d.end)],s=y.find(l=>l.type==="ipco"),c=y.find(l=>l.type==="ipma");if(!s||!c)return!1;let f=new Map;if([...g(e,s.start,s.end)].forEach((l,x)=>{l.type==="irot"&&f.set(x+1,e.readUInt8(l.start)&3)}),f.size===0)return!1;let h=e.readUInt8(c.start),w=(e.readUInt8(c.start+3)&1)===1,u=c.start+4,p=e.readUInt32BE(u);u+=4;for(let l=0;l<p&&u<c.end;l++){let x=h<1?e.readUInt16BE(u):e.readUInt32BE(u);u+=h<1?2:4;let G=e.readUInt8(u);u+=1;for(let k=0;k<G;k++){let Q=w?e.readUInt16BE(u)&32767:e.readUInt8(u)&127;if(u+=w?2:1,x===m&&(f.get(Q)??0)%2===1)return!0}}return!1}catch{return!1}finally{await n.close().catch(()=>{})}}import{execFile as st}from"node:child_process";import{randomBytes as ct}from"node:crypto";import{copyFile as ft,mkdtemp as _,open as ut,readFile as dt,rm as R}from"node:fs/promises";import{tmpdir as v}from"node:os";import{extname as L,join as b}from"node:path";import{promisify as mt}from"node:util";var z=mt(st),K=async()=>({...await import("./paths-EOYKOUBC.js"),...await import("./run-HGZVOXRW.js")}),A=t=>t!=="darwin",lt={".nef":[".nef",".nrw"],".arw":[".arw",".srf",".sr2"],".rw2":[".rw2",".rwl"],".3fr":[".3fr",".fff"],".dcr":[".dcr",".kdc"]},ht=[["nikon",".nef"],["sony",".arw"],["pentax",".pef"],["ricoh",".pef"],["samsung",".srw"],["hasselblad",".3fr"],["seiko epson",".erf"],["epson",".erf"],["kodak",".dcr"],["eastman kodak",".dcr"],["leaf",".mos"]],wt=new Set([32803,34892]),pt=new Set([32767,32769,32770,34316,34713,65e3,65535]),yt="85c0b687820f11e08111f4ce462b6a48";function T(t,n){let e=(s,c)=>n?s.readUInt16LE(c):s.readUInt16BE(c),i=(s,c)=>n?s.readUInt32LE(c):s.readUInt32BE(c),r={1:1,2:1,3:2,4:4,7:1,13:4};async function o(s){if(s<=0)return;let c=await t(s,2);if(c.length<2)return;let f=e(c,0);if(f===0||f>1e3)return;let h=await t(s+2,f*12+4);if(h.length<f*12+4)return;let w=new Map;for(let u=0;u<f;u++){let p=u*12;w.set(e(h,p),{type:e(h,p+2),count:i(h,p+4),inline:h.subarray(p+8,p+12),offset:i(h,p+8)})}return{entries:w,next:i(h,f*12)}}async function a(s,c=16){if(!s)return[];let f=r[s.type]===2?2:4,h=Math.min(s.count,c),w=h*f<=4?s.inline:await t(s.offset,h*f),u=[];for(let p=0;p<h&&(p+1)*f<=w.length;p++)u.push(f===2?e(w,p*f):i(w,p*f));return u}async function d(s){if(s?.type!==2)return"";let c=Math.min(s.count,64);return(c<=4?s.inline.subarray(0,c):await t(s.offset,c)).toString("latin1").replace(/\0.*$/s,"").trim()}async function m(s){let[c]=await a(s.entries.get(274),1);return c!==void 0&&c>=1&&c<=8?c:1}async function y(s){let c=[s],f=new Set;for(let h=0;c.length>0&&h<12;h++){let w=c.shift(),[u]=await a(w.entries.get(262),1),[p]=await a(w.entries.get(259),1);if(u!==void 0&&wt.has(u)||p!==void 0&&pt.has(p))return!0;for(let l of[...await a(w.entries.get(330),8),w.next]){if(l===0||f.has(l))continue;f.add(l);let x=await o(l);x&&c.push(x)}}return!1}return{directory:o,text:d,orientation:m,hasMosaic:y,u32:i}}function $(t){let n=t.toString("latin1",0,2);return n==="II"?!0:n==="MM"?!1:void 0}async function q(t,n){let e=$(t.subarray(n,n+2));if(e===void 0)return 1;let r=T(async(a,d)=>t.subarray(n+a,n+a+d),e),o=await r.directory(r.u32(t,n+4));return o?r.orientation(o):1}async function gt(t){if(t[0]!==255||t[1]!==216)return 1;let n=2;for(;n+4<=t.length&&t[n]===255;){let e=t[n+1],i=t.readUInt16BE(n+2);if(e===225&&t.toString("latin1",n+4,n+10)==="Exif\0\0")return q(t,n+10);if(e===218)break;n+=2+i}return 1}async function xt(t,n){let e=await t(0,Math.min(n,1048576)),i=[...g(e,0,e.length)].find(r=>r.type==="moov");if(!i)return 1;for(let r of g(e,i.start,i.end)){if(r.type!=="uuid"||e.toString("hex",r.start,r.start+16)!==yt)continue;let o=[...g(e,r.start+16,r.end)].find(a=>a.type==="CMT1");return o?q(e,o.start):1}return 1}async function bt(t,n){if(n.length<92)return 1;let e=n.readUInt32BE(84),i=n.readUInt32BE(88);return e===0||i===0?1:gt(await t(e,Math.min(i,65536)))}async function It(t){let n;try{n=await ut(t,"r")}catch{return}try{let{size:e}=await n.stat(),i=async(f,h)=>{let w=Math.max(0,Math.min(h,e-f)),u=Buffer.alloc(w);return w>0&&await n.read(u,0,w,f),u},r=await i(0,96);if(r.length<16)return;let o=r.toString("latin1",0,4);if(r.toString("latin1",0,15)==="FUJIFILMCCD-RAW")return{ext:".raf",orientation:await bt(i,r)};if(r.toString("latin1",4,12)==="ftypcrx ")return{ext:".cr3",orientation:await xt(i,e)};let a=$(r);if(a===void 0)return;let d=T(i,a),m=await d.directory(d.u32(r,4));if(!m)return;let y=await d.orientation(m);if(o==="IIRO"||o==="IIRS"||o==="MMOR")return{ext:".orf",orientation:y};if(o==="IIU\0")return{ext:".rw2",orientation:y};if(o!=="II*\0"&&o!=="MM\0*")return;if(m.entries.has(50706))return{ext:".dng",orientation:y};if(r.toString("latin1",8,11)==="CR")return{ext:".cr2",orientation:y};let s=(await d.text(m.entries.get(271))).toLowerCase(),c=ht.find(([f])=>s.startsWith(f));return!c||!await d.hasMosaic(m)?void 0:{ext:c[1],orientation:y}}catch{return}finally{await n.close().catch(()=>{})}}async function St(t=process.platform){return A(t)?await(await K()).installed("raw")!==void 0:D()}async function j(t,n){let{installed:e,runExtension:i}=await K(),r=await e("raw");if(r===void 0)throw B(t,n);return{ext:r,runExtension:i}}async function V(t,n,e){let i=L(t).toLowerCase();if((lt[n.ext]??[n.ext]).includes(i))return e(t);let r=await _(b(v(),"forge-raw-"));try{let o=b(r,`photo${n.ext}`);return await ft(t,o),await e(o)}finally{await R(r,{recursive:!0,force:!0}).catch(()=>{})}}async function Tt(t,n,e=process.platform){if(A(e)){let{ext:a,runExtension:d}=await j(t,e),m=await d(a,["--info","--in",t],{subject:t,platform:e});if(!(m.width>0&&m.height>0))throw new Error("the raw extension reported no size");return{width:m.width,height:m.height}}let{stdout:i}=await V(t,n,a=>z("/usr/bin/sips",["-g","typeIdentifier","-g","pixelWidth","-g","pixelHeight",a],{timeout:3e4}));if(!/typeIdentifier:\s*\S*raw-image/.test(i))return;let r=Number(/pixelWidth:\s*(\d+)/.exec(i)?.[1]??0),o=Number(/pixelHeight:\s*(\d+)/.exec(i)?.[1]??0);if(!(r===0||o===0))return n.orientation>=5?{width:o,height:r}:{width:r,height:o}}async function Z(t,n=process.platform){if(A(n))return Et(t,n);if(!await St(n))throw B(t,n);let e=await It(t)??{ext:L(t).toLowerCase(),orientation:1},i=b(v(),`forge-raw-${ct(8).toString("hex")}.png`),r=async()=>{await R(i,{force:!0}).catch(()=>{})};try{return await V(t,e,o=>z("/usr/bin/sips",["-s","format","png",o,"--out",i],{timeout:3e5})),{path:i,cleanup:r}}catch(o){throw await r(),o}}async function Et(t,n){let e=await _(b(v(),"forge-raw-")),i=async()=>{await R(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await j(t,n),a=b(e,"decoded.rgb"),d=b(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t,platform:n});return await(await E())(await dt(a),{raw:{width:m,height:y,channels:3}}).png().toFile(d),await R(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}async function Zt(t,n){if(n==="heic"){if(!await C())throw S(t);return O(t)}return n==="raw"?Z(t):{path:t,cleanup:async()=>{}}}export{C as a,At as b,kt as c,It as d,St as e,Tt as f,Zt as g};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{c as te,g as st,h as it}from"./chunk-EEQSUBBL.js";import{c as ue,d as at,f as me,g as ct,k as ft}from"./chunk-K7KKCR7V.js";import{b as nt,c as rt}from"./chunk-LVYQVJOF.js";import{b as Ce,c as Ue,e as ze,h as je,i as et,j as tt,o as ot}from"./chunk-SNDFMJIX.js";import{n as qe,o as Ve,q as Ge,r as R}from"./chunk-DZOBIUV6.js";import{H as Te,I as V,J as de,L as Ne,P as Be,Y as Le,c as A,d as T,da as j,ka as Je,la as We,na as J,u as Ae,w as Z,y as X}from"./chunk-WIPP5TWQ.js";import{a as De}from"./chunk-J7FLFHQJ.js";import{a as S}from"./chunk-H3DIRJFE.js";import{a as He,b as ee,c as M,e as Ke,f as Ye,g as Qe,h as Ze,i as Xe}from"./chunk-KXKQDFHX.js";import{mkdtemp as Tt,rm as Nt}from"node:fs/promises";import{tmpdir as Bt}from"node:os";import{join as oe}from"node:path";var dt=(e,t,o)=>ze(e,t,o)===void 0;function pt(e,t,o=Number.POSITIVE_INFINITY,n=[2,4]){return[...n].reverse().find(s=>s<o&&dt(e,t,s))??0}async function Lt(e,t,o){if(e.op!=="boost"&&e.op!=="remove-background")throw new Error(`the extension engine cannot ${e.op}`);if(o?.aborted)throw o.reason??new Error("aborted");let n=e.sources[0],s=e.outputs[0],r=e.op,{assetFor:i,catalogEntry:a,offeredHere:f}=await import("./catalog-VPSTQTFD.js");if(!f(r,process.platform,process.arch))throw Be(a(r)?.title??r);let{installed:p,extensionsRoot:d}=await import("./paths-EOYKOUBC.js"),w=await p(r);if(!w)throw Ne(r);let l=Ce(w.version);if(e.op==="boost"){let b=a(r),y=Ue(e.scale,w.version,b&&i(b)?.version);if(y)throw y}if(e.op==="boost"&&!dt(n.width,n.height,e.scale))throw Le(n.path,pt(n.width,n.height,Number.POSITIVE_INFINITY,l),e.scale);let{runExtension:h}=await import("./run-HGZVOXRW.js"),g=[];n.frames>1&&g.push({code:"animation-flattened",message:`${A(n.path)} has ${n.frames} frames. Only the first frame was used.`});let I=await Tt(oe(Bt(),"forge-ext-"));try{t({phase:"decoding"});let b=oe(I,"in.png"),y=oe(I,"out.png");await tt(n,b);let $=e.op==="boost"?["--in",b,"--out",y,"--scale",String(e.scale),"--cache",oe(d(),"boost","cache")]:[b,y];await h(w,$,{subject:n.path,what:`${Jt(e)} is running on ${A(n.path)}`,onWait:()=>t({phase:"waiting"}),onStart:()=>t({phase:"encoding"}),onProgress:(v,O)=>t({phase:"tiles",done:v,total:O}),...e.op==="boost"?{maxScale:pt(n.width,n.height,e.scale,l)}:{},...o===void 0?{}:{signal:o}});let x=(await ee())(y);S[e.target].hasAlpha||(x=x.flatten({background:e.options.background}));let P=await je(x,e.target,e.options.quality).toBuffer();t({phase:"writing"});let E=await et(P,s);return{job:e,outputBytes:E,warnings:g}}catch(b){throw T(b)?b:J(n.path,b)}finally{await Nt(I,{recursive:!0,force:!0}).catch(()=>{})}}function Jt(e){return e.op!=="boost"?"Remove background":e.scale===1?"Sharpen":`Boost resolution ${e.scale}\xD7`}var ut={id:"extension",reads:new Set,writes:new Set,ops:new Set(["boost","remove-background"]),probe:()=>Promise.reject(new Error("the extension engine reads no files")),run:Lt};import{randomBytes as ao}from"node:crypto";import{open as co,rm as fo,stat as ne}from"node:fs/promises";import{dirname as po,join as uo}from"node:path";var le="%NOISE_FLOOR%",Wt=["highpass=f=80",`afftdn=nr=12:nf=${le}`],Ct="highpass=f=80,astats=measure_perchannel=none:measure_overall=RMS_trough";function wt(e){let t=/RMS trough dB:\s*(-?[\d.]+|-?inf)/i.exec(e)?.[1],o=t===void 0?Number.NaN:Number(t);return Number.isFinite(o)?Math.min(-30,Math.max(-70,Math.round(o+8))):-50}var ge="%LOUDNORM_MEASURED%",Ut={mp4:"mp4",hevc:"mp4",mov:"mov",webm:"webm",mkv:"matroska",avi:"avi",gif:"gif",mp3:"mp3",m4a:"ipod",opus:"opus",flac:"flac",wav:"wav",aiff:"aiff",ogg:"ogg"},zt={mp4:["h264","hevc","mpeg4","av1"],mov:["h264","hevc","mpeg4","prores","av1"],mkv:["h264","hevc","mpeg4","vp8","vp9","av1"],hevc:["hevc"],webm:["vp8","vp9","av1"],avi:["mpeg4","h264","mjpeg","msmpeg4v3"]},qt={mp4:["aac","alac","mp3"],hevc:["aac","alac","mp3"],mov:["aac","alac","mp3","pcm_s16le","pcm_s16be","pcm_s24le"],m4a:["aac","alac"],mkv:["aac","mp3","opus","vorbis","flac","ac3","eac3"],webm:["opus","vorbis"],opus:["opus"],mp3:["mp3"],flac:["flac"],wav:["pcm_s16le"],aiff:["pcm_s16be"],ogg:["vorbis","opus","flac"],avi:["mp3","ac3","aac","pcm_s16le"]},mt=[48e3,24e3,16e3,12e3,8e3];function Vt(e,t,o){let n={encoder:"opus",kbps:96,args:["-strict","-2"],rates:[48e3]};switch(e){case"webm":return o("libopus")?{encoder:"libopus",kbps:96,rates:mt}:o("libvorbis")?{encoder:"libvorbis",kbps:128}:o("opus")?n:{codec:"Opus or Vorbis",encoders:["libopus","libvorbis","opus"],sound:!0};case"opus":return o("libopus")?{encoder:"libopus",kbps:96,rates:mt}:o("opus")?n:{codec:"Opus",encoders:["libopus","opus"]};case"mp3":return o("libmp3lame")?{encoder:"libmp3lame",kbps:128}:{codec:"MP3",encoders:["libmp3lame"]};case"flac":return{encoder:"flac"};case"wav":return{encoder:"pcm_s16le"};case"aiff":return{encoder:"pcm_s16be"};case"ogg":return o("libvorbis")?{encoder:"libvorbis",kbps:128}:{encoder:"vorbis",kbps:128,args:["-strict","-2","-ac","2"]};default:return{encoder:t==="darwin"&&o("aac_at")?"aac_at":"aac",kbps:128}}}var G=e=>Math.max(2,Math.floor(e/2)*2),Gt=e=>String(Math.round(e*1e3)/1e3),Ht=e=>String(Math.ceil(e*1e3)/1e3),Kt=e=>Math.round(38-(e-1)*20/99),Yt=e=>Math.round(50-(e-1)*30/99),Qt=e=>Math.round(40-(e-1)*18/99),lt=e=>Math.round(20+e*60/100),Zt=e=>Math.round(31-(e-1)*29/99);function Xt(e,t){let o=.15*2**((18-e)/6);return Math.max(64,Math.round(t*o/1e3))}function jt(e,t,o,n,s){let r=e.width,i=e.height;if(o)r=o.width,i=o.height;else{t.crop?.box&&(r=t.crop.box.width,i=t.crop.box.height);let a=t.resize;if(a&&"width"in a){let f=Math.min(a.width,r)/r;r*=f,i*=f}else if(a&&"height"in a){let f=Math.min(a.height,i)/i;r*=f,i*=f}else a&&(r*=a.percent/100,i*=a.percent/100)}return r*i*(n??e.fps*s)}var eo="zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p";function gt(e){let t=[],o=e;for(;o>2;)t.push("atempo=2"),o/=2;for(;o<.5;)t.push("atempo=0.5"),o/=.5;return t.push(`atempo=${Math.round(o*1e3)/1e3}`),t}var to=800,oo=15,ht=32;function he(e){let{facts:t,options:o,target:n,platform:s}=e,r=o.media??{},i=t.video,a=t.audio,f=S[n].media==="sound",p=n==="gif",d=o.compress!==void 0,w=s==="darwin",l=c=>e.has===void 0||e.has.has(c),h=c=>We(n,c,e.os??s),g=r.cut?.start??0,I=Math.min(r.cut?.end??t.duration,t.duration),b=Math.max(0,I-g),y=r.speed??1,$=b/y,u=i!==void 0&&!f,x=a!==void 0&&!r.mute&&!p,P,E,v,O;if(r.targetBytes!==void 0&&$>0){if(u&&i){let c=st({duration:$,width:i.width,height:i.height,fps:i.fps,hasAudio:x,targetBytes:r.targetBytes});"videoKbps"in c&&(P={width:c.width,height:c.height,fps:c.fps},v=c.videoKbps,E=c.audioKbps)}else if(x){let c=Math.floor(r.targetBytes*8/$/1e3*.98);O=Math.max(ht,Math.min(320,c))}}let F=[];if(u&&i){if(i.hdr&&n!=="hevc"&&l("zscale")&&F.push(eo),o.crop?.box){let c=o.crop.box;F.push(`crop=${G(c.width)}:${G(c.height)}:${c.left}:${c.top}`)}if(P)F.push(`scale=${P.width}:${P.height}`);else if(o.resize){let c=o.resize;"width"in c?F.push(`scale=trunc(min(${G(c.width)}\\,iw)/2)*2:-2`):"height"in c?F.push(`scale=-2:trunc(min(${G(c.height)}\\,ih)/2)*2`):F.push(`scale=trunc(iw*${c.percent/100}/2)*2:-2`)}if(o.rotate&&F.push(o.rotate===90?"transpose=1":o.rotate===270?"transpose=2":"hflip,vflip"),y!==1&&F.push(`setpts=PTS/${y}`),p){let c=Math.min(to,G(i.width));F.push(`fps=${Math.min(oo,i.fps)},scale=${c}:-2:flags=lanczos,split[s0][s1];[s0]palettegen=stats_mode=diff[p];[s1][p]paletteuse=dither=bayer:bayer_scale=4`)}}let Y=P?.fps??r.fps,Ie=u&&i!==void 0&&F.length===0&&Y===void 0&&!d&&r.targetBytes===void 0&&(zt[n]??[]).includes(i.codec),m=[],ae=!1;if(!u)m.push("-vn");else if(Ie)m.push("-c:v","copy");else{if(F.length&&m.push("-vf",F.join(",")),p)m.push("-c:v","gif","-loop","0");else if(n==="webm"){if(!l("libvpx-vp9"))throw h({codec:"VP9",encoders:["libvpx-vp9"]});if(ae=v!==void 0,m.push("-c:v","libvpx-vp9","-row-mt","1","-deadline","good","-cpu-used","4"),i?.codec==="gif"&&m.push("-pix_fmt","yuva420p"),v!==void 0)m.push("-b:v",`${v}k`);else{let c=d?Yt(o.quality??60):33;m.push("-crf",String(c),"-b:v","0")}}else if(n==="hevc"){let c=l("libx265"),k=w&&l("hevc_videotoolbox");if(!c&&!k)throw h({codec:"HEVC",encoders:["libx265",...w?["hevc_videotoolbox"]:[]]});if(v!==void 0)c?m.push("-c:v","libx265","-preset","fast","-b:v",`${v}k`):m.push("-c:v","hevc_videotoolbox","-b:v",`${v}k`);else if(k&&(!d||!c)){let D=d?lt(o.quality??60):60;m.push("-c:v","hevc_videotoolbox","-q:v",String(D))}else{let D=d?Qt(o.quality??60):26;m.push("-c:v","libx265","-crf",String(D),"-preset","fast")}m.push("-tag:v","hvc1","-pix_fmt",i?.hdr?"p010le":"yuv420p")}else{let c=d?Kt(o.quality??60):21,k=()=>`${v??Xt(c,i?jt(i,o,P,Y,y):0)}k`;if(v===void 0&&!d&&w&&l("h264_videotoolbox"))m.push("-c:v","h264_videotoolbox","-q:v","65");else if(l("libx264"))ae=v!==void 0,v!==void 0?m.push("-c:v","libx264","-preset","medium","-b:v",`${v}k`):d?m.push("-c:v","libx264","-preset","medium","-crf",String(c)):m.push("-c:v","libx264","-preset","veryfast","-crf","21");else if(w&&l("h264_videotoolbox"))v!==void 0?m.push("-c:v","h264_videotoolbox","-b:v",k()):m.push("-c:v","h264_videotoolbox","-q:v",String(lt(o.quality??60)));else if(l("libopenh264"))m.push("-c:v","libopenh264","-b:v",k());else if(s==="win32"&&l("h264_mf"))m.push("-c:v","h264_mf","-b:v",k());else if(n==="avi")if(v!==void 0)m.push("-c:v","mpeg4","-b:v",`${v}k`);else{let D=d?Zt(o.quality??60):3;m.push("-c:v","mpeg4","-q:v",String(D))}else throw h({codec:"H.264",encoders:["libx264",...w?["h264_videotoolbox"]:[],"libopenh264",...s==="win32"?["h264_mf"]:[]]});m.push("-pix_fmt","yuv420p")}Y!==void 0?m.push("-r",String(Y)):n==="avi"?m.push("-fps_mode","cfr"):p||m.push("-fps_mode","passthrough")}let Re=r.cleanup?[...Wt]:[],Q=[...Re,...y!==1?gt(y):[]],B=r.loudness;B!==void 0&&Q.push(`loudnorm=I=${B}:TP=-1.5:LRA=11:${ge}:linear=true`);let $e=r.bitrate??E??O,_e=x&&a!==void 0&&Q.length===0&&$e===void 0&&!(d&&f)&&(qt[n]??[]).includes(a.codec),_=[];if(!x)_.push("-an");else if(_e)_.push("-c:a","copy");else{Q.length&&_.push("-af",Q.join(","));let c=Vt(n,s,l);if("codec"in c)throw h(c);_.push("-c:a",c.encoder);let k=$e??c.kbps;if(k!==void 0&&c.kbps!==void 0&&_.push("-b:a",`${k}k`),c.args&&_.push(...c.args),!c.args?.includes("-ac")&&E!==void 0&&E<=ht&&_.push("-ac","1"),B!==void 0&&a){let D=!c.rates||c.rates.includes(a.sampleRate);_.push("-ar",String(D?a.sampleRate:c.rates?.[0]))}}let ce=[];g>0&&ce.push("-ss",Ht(g)),r.cut&&ce.push("-t",Gt(b));let z=[...ce,"-i",e.input],q=[],fe=[...u?["-map","0:v:0"]:[],...x?["-map","0:a:0"]:[]],ke=o.keepMetadata?[]:["-map_metadata","-1"],At=Ut[n]??n,Me=["mp4","hevc","mov","m4a"].includes(n)?["-movflags","+faststart"]:[],Oe=["-f",At,"-y",e.output],pe=s==="win32"?"NUL":"/dev/null",L=[];return r.cleanup&&L.push({args:[...z,...q,"-vn","-af",Ct,"-f","null",pe],measures:"noise"}),B!==void 0&&L.push({args:[...z,...q,"-vn","-af",`${[...Re,...y!==1?gt(y):[]].map(c=>`${c},`).join("")}loudnorm=I=${B}:TP=-1.5:LRA=11:print_format=json`,"-f","null",pe],measures:"loudness",pass:{at:1,of:2}}),ae?(L.push({args:[...z,...q,...fe.slice(0,2),...m,"-pass","1","-passlogfile",e.passlog,"-an","-f","null",pe],pass:{at:1,of:2}}),L.push({args:[...z,...q,...fe,...m,"-pass","2","-passlogfile",e.passlog,..._,...ke,...Me,...Oe],pass:{at:2,of:2}})):L.push({args:[...z,...q,...fe,...m,..._,...ke,...Me,...Oe],...B!==void 0?{pass:{at:2,of:2}}:{}}),{steps:L,duration:$,copies:{video:Ie,audio:_e},...P?{fitted:P}:{}}}var W=(e,t,o)=>e.subarray(t,t+o).toString("latin1"),no=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1","avif","avis","crx "]),ro=new Set(["M4A ","M4B ","M4P ","F4A ","F4B "]);function so(e){let t=W(e,8,4);if(!no.has(t))return t==="qt "?"mov":ro.has(t)?"m4a":"mp4"}function vt(e){if(e.length<4)return;if(W(e,4,4)==="ftyp")return so(e);if(e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163)return e.includes("webm",0,"latin1")?"webm":"mkv";let t=W(e,0,4);if(t==="RIFF"){let o=W(e,8,4);return o==="WAVE"?"wav":o==="AVI "?"avi":void 0}if(t==="FORM"){let o=W(e,8,4);return o==="AIFF"||o==="AIFC"?"aiff":void 0}if(t==="fLaC")return"flac";if(t==="OggS")return e.includes("OpusHead",0,"latin1")?"opus":"ogg";if(W(e,0,3)==="ID3"||e[0]===255&&((e[1]??0)&224)===224&&((e[1]??0)&6)===2)return"mp3"}var mo=["mp4","mov","webm","mkv","avi","gif"],yt=["mp4","mov","hevc","webm","mkv","avi","gif","mp3","m4a","wav"],lo=["mp3","m4a","wav","aiff","flac","opus","ogg"],go=["mp3","m4a","opus","flac","aiff","wav"];async function ho(e){let t=await co(e,"r");try{let o=Buffer.alloc(64),{bytesRead:n}=await t.read(o,0,o.length,0);return o.subarray(0,n)}finally{await t.close()}}function wo(e,t){return t&&!t.video&&(e==="mp4"||e==="mov")?"m4a":e}async function xt(e,t){let o=vt(await ho(e));if(!o)throw new Error("not video or sound");if(o!=="mp4"&&o!=="mov"&&S[o].media!==t)throw new Error(`not ${t}`);let n=(await ne(e)).size,s=await ue(),r;if(s){try{r=await me(e,s)}catch(a){throw Z(e,a)}if(r.duration<=0||!r.video&&!r.audio)throw Z(e,r)}let i=wo(o,r);if(S[i].media!==t)throw new Error(`not ${t}`);return{kind:"media",path:e,format:i,bytes:n,...r?{facts:r}:{}}}async function vo(){let{assetFor:e,catalogEntry:t}=await import("./catalog-VPSTQTFD.js"),o=t("video");return o!==void 0&&e(o)!==void 0}async function bo(e,t){if(e.kind==="media"&&e.facts)return e.facts;try{return await me(e.path,t)}catch(o){throw Z(e.path,o)}}function yo(e,t){let o=e.options.media??{},n=o.cut?.start??0,s=Math.min(o.cut?.end??t,t);return Math.max(0,s-n)/(o.speed??1)}function Pt(e,t){if(e.op!=="convert")return;let o=e.sources[0],n=o.kind==="media"?o.facts:void 0;if(!n)return;let s=e.options.media??{},r=it({...n,duration:yo(e,n.duration)},{soundOnly:S[e.target].media==="sound",mute:s.mute===!0||e.target==="gif"});return t<r?{floor:r}:void 0}function xo(e){let t=e.slice(e.lastIndexOf("{"),e.lastIndexOf("}")+1),o=JSON.parse(t);return[`measured_I=${o.input_i}`,`measured_TP=${o.input_tp}`,`measured_LRA=${o.input_lra}`,`measured_thresh=${o.input_thresh}`,`offset=${o.target_offset}`].join(":")}async function bt(e){await Promise.all(e.map(t=>fo(t,{force:!0}).catch(()=>{})))}async function Ft(e,t,o){if(e.op!=="convert")throw new Error(`media engines only convert, not ${e.op}`);if(o?.aborted)throw o.reason??new Error("aborted");let n=e.sources[0],s=e.outputs[0],r=await ue();if(!r)throw Je(n.path,process.platform,await vo());let i=await bo(n,r),a=ao(6).toString("hex"),f=qe(s,a),p=uo(po(s),`.forge-pass-${a}`),d=[f,`${p}-0.log`,`${p}-0.log.temp`,`${p}-0.log.mbtree`,`${p}-0.log.mbtree.temp`],w=[],l=(u,x=e.options)=>he({input:n.path,output:f,target:e.target,facts:i,options:x,platform:u,os:process.platform,passlog:p,...r.has?{has:r.has}:{}}),h=e.options,g=l(process.platform);if(g.duration<=0)throw Te(`The cut keeps nothing of ${A(n.path)}: it starts at or after its end.`,`It is ${te(i.duration)} long.`);await Ve(s);let I=process.platform,b=h.media?.cut;if(g.copies.video&&b&&b.start>0){let u=await ct(n.path,b.start,r);u!==void 0&&b.start-u>.05&&(h={...h,media:{...h.media,cut:{...b,start:u}}},g=l(process.platform,h),w.push({code:"media-cut-keyframe",message:`It starts at ${te(u)}, the keyframe just before ${te(b.start)}.`}))}let y=async u=>{let x="",P="";for(let E of u.steps){let v=E.args.map(F=>F.replace(ge,x).replace(le,P)),O=await ft(v,{tools:r,signal:o,report:E.measures!==void 0,onTime:F=>t({phase:"time",done:Math.min(F,u.duration),total:u.duration,...E.pass?{pass:E.pass}:{}})});E.measures==="loudness"&&(x=xo(O)),E.measures==="noise"&&(P=String(wt(O)))}};try{try{await y(g)}catch(P){if(o?.aborted||!g.steps.some(E=>E.args.some(v=>v.endsWith("_videotoolbox"))))throw P;I="linux",g=l(I,h),await y(g)}let u=h.media?.targetBytes;for(let P of[.95,.9]){if(u===void 0||(await ne(f)).size<=u)break;h={...h,media:{...h.media,targetBytes:Math.floor(u*P)}},g=l(I,h),await y(g)}let x=(await ne(f)).size;if(u!==void 0&&x>u)throw Ae(n,e.options.media?.targetBytes??u,x);if(e.options.compress!==void 0&&x>=n.bytes)throw j(n.path,n.bytes,x);await Ge(f,s)}catch(u){throw await bt(d),o?.aborted||T(u)?u:J(n.path,u)}await bt(d.slice(1));let $=i.video;if(g.fitted&&$&&(g.fitted.width<$.width-2||g.fitted.fps<$.fps)){let u=De(e.options.media?.targetBytes??0);w.push({code:"media-fitted",message:`To fit ${u} it is now ${g.fitted.width}\xD7${g.fitted.height} at ${g.fitted.fps} fps.`})}return{job:e,outputBytes:(await ne(s)).size,warnings:w}}function Wn(e,t){if(e.kind!=="media"||!e.facts)return;let o=at()?.has;if(o)try{he({input:e.path,output:e.path,target:t,facts:e.facts,options:{background:"#ffffff",keepMetadata:!1},platform:process.platform,passlog:"",has:o});return}catch(n){return T(n)&&n.code==="encoder-missing"?n:void 0}}var H=e=>new Set(e);function Po(e){let t=e.kind==="media"?e.facts:void 0,o=e.kind==="image"||t!==void 0&&t.audio===void 0;return H(yt.filter(n=>!(o&&S[n].media==="sound"||n==="hevc"&&t?.video?.codec==="hevc")))}var Et={id:"video",reads:H(mo),writes:H(yt),ops:new Set(["convert"]),probe:e=>xt(e,"video"),run:Ft,sizeTo:Pt,writesFor:Po},St={id:"sound",reads:H(lo),writes:H(go),ops:new Set(["convert"]),probe:e=>xt(e,"sound"),run:Ft,sizeTo:Pt};import{readFile as re,rm as $t,stat as Fo}from"node:fs/promises";function zn(e,t){let o=e.split(",").map(r=>r.trim()).filter(r=>r!=="");if(o.length===0)throw V(e,"That selects no pages.",t);let n=new Set,s=(r,i)=>{if(!Number.isInteger(r)||r<1||r>t)throw V(i,`"${i}" is outside 1 and ${t}.`,t);return r};for(let r of o){let i=r.match(/^(\d+)\s*-\s*(\d*)$/);if(i?.[1]!==void 0){let a=s(Number(i[1]),r),f=i[2]===""?t:s(Number(i[2]),r);if(f<a)throw V(r,`"${r}" ends before it starts.`,t);for(let p=a;p<=f;p++)n.add(p-1);continue}if(!/^\d+$/.test(r))throw V(r,`"${r}" is not a page number.`,t);n.add(s(Number(r),r)-1)}return[...n].sort((r,i)=>r-i)}function It(e){return[...new Set(e)].sort((t,o)=>t-o)}function qn(e){if(e.length===0)return"";let t=[...new Set(e)].sort((r,i)=>r-i),o=[],n=t[0],s=n;for(let r of t.slice(1)){if(r===s+1){s=r;continue}o.push(n===s?`${n+1}`:`${n+1}-${s+1}`),n=r,s=r}return o.push(n===s?`${n+1}`:`${n+1}-${s+1}`),o.join(", ")}function Rt(e,t){let o=[...new Set(e)].sort((r,i)=>r-i).filter(r=>r>=0&&r<t-1),n=[],s=0;for(let r of o)n.push({from:s,to:r}),s=r+1;return n.push({from:s,to:t-1}),n}var ve=He(()=>import("./pdf-compress-U2E3CNXG.js")),Eo=new Set(["pdf","jpeg","png","webp","avif","gif","tiff"]),So=new Set(["pdf"]);async function C(e){return(await M()).PDFDocument.load(await re(e),{ignoreEncryption:!0})}async function Io(e){let{surveyDocument:t}=await ve(),o=await C(e),{size:n}=await Fo(e);return{kind:"document",path:e,format:"pdf",bytes:n,pages:o.getPageCount(),encrypted:o.isEncrypted,images:t(o)}}function U(e){for(let t of e)if(t.encrypted)throw X(t.path)}async function Ro(e,t,o){let n=await ee(),s=t.format==="jpeg"||t.format==="png",r=s?(await n(o).metadata()).orientation:void 0;if(s&&(r===void 0||r===1))return t.format==="jpeg"?e.embedJpg(o):e.embedPng(o);if(t.format==="jpeg"){let i=await n(o).rotate().jpeg({quality:S.jpeg.defaultQuality,mozjpeg:!0}).toBuffer();return e.embedJpg(i)}return e.embedPng(await n(o).rotate().png().toBuffer())}async function $o(e,t){let o=e.sources[0];if(o.kind!=="image")throw new Error("the pdf engine cannot embed a document source");let n=[];o.frames>1&&n.push({code:"animation-flattened",message:`${A(o.path)} has ${o.frames} frames, and ${S.pdf.label} cannot animate. Only the first frame was converted.`}),t({phase:"reading"});let s=await re(o.path);t({phase:"encoding"});let i=await(await M()).PDFDocument.create(),a=await Ro(i,o,s);i.addPage([a.width,a.height]).drawImage(a,{x:0,y:0,width:a.width,height:a.height}),t({phase:"writing"});let p=await R(e.outputs[0],await i.save());return{job:e,outputBytes:p,warnings:n}}async function _o(e,t){U(e.sources.filter(i=>i.kind==="document"));let n=await(await M()).PDFDocument.create();for(let i of e.sources){t({phase:"reading"});let a=await C(i.path),f=await n.copyPages(a,a.getPageIndices());for(let p of f)n.addPage(p)}t({phase:"writing"});let s=await n.save(),r=await R(e.outputs[0],s);return{job:e,outputBytes:r,warnings:[]}}async function ko(e,t){let o=e.sources[0];U([o]);let n=await M();t({phase:"reading"});let s=await C(o.path),r=Rt(e.cuts,s.getPageCount()),i=[],a=0;try{for(let[f,p]of r.entries()){let d=await n.PDFDocument.create(),w=Array.from({length:p.to-p.from+1},(g,I)=>p.from+I),l=await d.copyPages(s,w);for(let g of l)d.addPage(g);let h=e.outputs[f];if(h===void 0)throw new Error(`split produced ${r.length} parts but was given ${e.outputs.length} outputs`);a+=await R(h,await d.save()),i.push(h),t({phase:"page",done:f+1,total:r.length})}}catch(f){throw await Promise.all(i.map(p=>$t(p,{force:!0}))),f}return{job:e,outputBytes:a,warnings:[]}}async function we(e,t){let n=await(await M()).PDFDocument.create(),s=await n.copyPages(e,t);for(let r of s)n.addPage(r);return n.save()}async function Mo(e,t){let o=e.sources[0];if(U([o]),e.pages.length===0)throw de("That extract selects no pages.");t({phase:"reading"});let n=await C(o.path),s=It(e.pages),r=[],i=0;try{if(e.separate)for(let[a,f]of s.entries()){let p=e.outputs[a];i+=await R(p,await we(n,[f])),r.push(p),t({phase:"page",done:a+1,total:s.length})}else{t({phase:"writing"});let a=e.outputs[0];i=await R(a,await we(n,s)),r.push(a)}}catch(a){throw await Promise.all(r.map(f=>$t(f,{force:!0}))),a}return{job:e,outputBytes:i,warnings:[]}}async function Oo(e,t){let o=e.sources[0];U([o]),t({phase:"reading"});let n=await C(o.path),s=new Set(e.pages),r=n.getPageIndices().filter(a=>!s.has(a));if(r.length===0)throw de("That would delete every page.");t({phase:"writing"});let i=await R(e.outputs[0],await we(n,r));return{job:e,outputBytes:i,warnings:[]}}async function Do(e,t){let o=e.sources[0];U([o]);let n=await M();t({phase:"reading"});let s=await C(o.path);for(let i of s.getPages()){let f=((i.getRotation().angle+e.turns*90)%360+360)%360;i.setRotation(n.degrees(f))}t({phase:"writing"});let r=await R(e.outputs[0],await s.save());return{job:e,outputBytes:r,warnings:[]}}async function Ao(e,t){let o=e.sources[0];U([o]);let{compressPdf:n}=await ve();t({phase:"reading"});let s=await re(o.path);t({phase:"encoding"});let{bytes:r,recompressed:i,skipped:a,fromDpi:f,toDpi:p}=await n(s,{quality:e.options.quality??60,dpi:e.options.dpi??150});if(e.options.compress&&r.length>=o.bytes)throw j(o.path,o.bytes,r.length);t({phase:"writing"});let d=await R(e.outputs[0],r),w=h=>h===1?"":"s",l=[];return i===0&&a===0?l.push({code:"pdf-no-images",message:"This PDF has no images to re-encode, so its size is almost unchanged."}):i===0?l.push({code:"pdf-no-images",message:`None of its ${a} image${w(a)} could be re-encoded \u2014 they are not JPEG data.`}):a>0&&l.push({code:"pdf-images-skipped",message:`${i} image${w(i)} recompressed, ${a} skipped (not JPEG).`}),f!==void 0&&p!==void 0&&l.push({code:"pdf-downsampled",message:`Images reduced from ${f} to ${p} dpi. Pass --dpi ${f} to keep them.`}),{job:e,outputBytes:d,warnings:l}}async function To(e){if(e.op!=="convert")return;let t=e.sources[0];if(t.kind!=="document")return;let{compressPdf:o}=await ve(),n=await re(t.path);return{ladder:[e.options.dpi??150,120,96,72].map(s=>({dpi:s})),measure:async s=>(await o(n,{quality:s.quality??60,...s.dpi===void 0?{}:{dpi:s.dpi}})).bytes.byteLength}}var _t={id:"pdf",measurer:To,reads:Eo,writes:So,ops:new Set(["convert","merge","split","extract","delete","rotate"]),probe:Io,async run(e,t){switch(e.op){case"convert":if(e.target!=="pdf")throw new Error("the pdf engine only converts to pdf");return e.sources[0].kind==="document"?Ao(e,t):$o(e,t);case"merge":return _o(e,t);case"split":return ko(e,t);case"extract":return Mo(e,t);case"delete":return Oo(e,t);case"rotate":return Do(e,t);default:throw new Error(`the pdf engine cannot ${e.op}`)}}};import{execFile as No}from"node:child_process";import{mkdtemp as Bo,readFile as Ee,rm as Lo}from"node:fs/promises";import{tmpdir as Jo}from"node:os";import{basename as Wo,extname as Co,join as kt,win32 as Pe}from"node:path";import{pathToFileURL as Uo}from"node:url";import{promisify as zo}from"node:util";var Fe=zo(No),be=Buffer.from([208,207,17,224,161,177,26,225]);async function qo(e){if(e.length<be.length||!e.subarray(0,be.length).equals(be))return!1;let t=await Ze();try{return t.find(t.parse(e),"WordDocument")!==null}catch{return!1}}async function Vo(e){let t=await Qe();try{let o=new t(e);if(!o.getEntry("word/document.xml"))return;let n=0,s=o.getEntry("docProps/app.xml");if(s){let r=/<Pages>(\d+)<\/Pages>/.exec(o.readAsText(s));r?.[1]&&(n=Number(r[1]))}return{pages:n}}catch{return}}async function Go(e){let t=await Ee(e),o=await Vo(t);if(o)return{kind:"document",path:e,format:"docx",bytes:t.byteLength,pages:o.pages,encrypted:!1};if(await qo(t))return{kind:"document",path:e,format:"doc",bytes:t.byteLength,pages:0,encrypted:!1};throw new Error(`${e} is not a Word document`)}function Ho(e,t){return e==="win32"?[Pe.join(t.ProgramFiles??"C:\\Program Files","LibreOffice","program","soffice.exe"),Pe.join(t["ProgramFiles(x86)"]??"C:\\Program Files (x86)","LibreOffice","program","soffice.exe")]:["/Applications/LibreOffice.app/Contents/MacOS/soffice"]}var Ko=0;async function Yo(){Ko++;try{return await Fe("soffice",["--version"],{timeout:5e3}),"soffice"}catch{}for(let e of Ho(process.platform,process.env))try{return await Fe(e,["--version"],{timeout:5e3}),e}catch{}}var Mt,Qo=!1,Zo;async function Xo(){return Qo?Zo:(Mt??=Yo(),Mt)}var Se="\f";function se(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)}async function jo(e){if(e.format==="docx"){let o=await Ke(),{value:n}=await o.extractRawText({path:e.path});return se(n)}if(e.format==="doc"){let o=await Ye(),s=await new o().extract(e.path);return se(s.getBody())}return(await nt(await Ee(e.path))).flatMap((o,n)=>n===0?se(o):[Se,...se(o)])}var ye=612,ie=792,N=54,xe=11,Ot=14;async function en(e){let{PDFDocument:t,StandardFonts:o}=await M(),n=await t.create(),s=await n.embedFont(o.Helvetica),r=ye-N*2,i=n.addPage([ye,ie]),a=ie-N,f=()=>{i=n.addPage([ye,ie]),a=ie-N};for(let p of e){if(p===Se){f();continue}let d="";for(let w of p.split(/\s+/).filter(Boolean)){let l=d?`${d} ${w}`:w;d&&s.widthOfTextAtSize(l,xe)>r?(a<N&&f(),i.drawText(d,{x:N,y:a,size:xe,font:s}),a-=Ot,d=w):d=l}d&&(a<N&&f(),i.drawText(d,{x:N,y:a,size:xe,font:s}),a-=Ot)}return n.save()}async function tn(e){let{Document:t,Packer:o,PageBreak:n,Paragraph:s}=await Xe(),r=e.map(a=>a===Se?new s({children:[new n]}):new s(a)),i=new t({sections:[{children:r}]});return o.toBuffer(i)}var on=new Set(["docx","doc","pdf"]),nn=new Set(["docx","pdf"]),rn=new Set(["convert"]),sn={code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice for full-fidelity conversion: brew install --cask libreoffice"};function an(e=process.platform){return e==="linux"?{code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice for full-fidelity conversion: sudo apt install libreoffice"}:e!=="win32"?sn:{code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice from libreoffice.org for full-fidelity conversion."}}function cn(e,t,o,n=process.platform){return[`-env:UserInstallation=${n==="win32"?Uo(Pe.join(e,"profile"),{windows:!0}).href:`file://${e}/profile`}`,"--headless","--convert-to",o,"--outdir",e,t]}async function fn(e,t,o){let n=await Bo(kt(Jo(),"forge-word-"));try{await Fe(e,cn(n,t,o),{timeout:12e4});let s=Wo(t,Co(t));return await Ee(kt(n,`${s}.${o}`))}finally{await Lo(n,{recursive:!0,force:!0})}}async function pn(e,t){if(e.op!=="convert")throw new Error(`the word engine cannot ${e.op}`);let o=e.sources[0];if(o.kind!=="document")throw new Error("the word engine can only convert a document source");if(o.encrypted)throw X(o.path);t({phase:"reading"});let n=await Xo();t({phase:"encoding"});let s=[],r;try{if(n!==void 0)r=await fn(n,o.path,e.target);else{let a=await jo(o);r=e.target==="pdf"?await en(a):await tn(a),s.push(an())}}catch(a){throw J(o.path,a)}t({phase:"writing"});let i=await R(e.outputs[0],r);return{job:e,outputBytes:i,warnings:s}}var Dt={id:"word",reads:on,writes:nn,ops:rn,probe:Go,run:pn};var K=[ot,Et,St,_t,Dt,ut,rt];function vr(e){return K.find(t=>t.reads.has(e))}function br(e){return K.find(t=>t.writes.has(e))}function yr(e){if(e.op==="convert"){let t=e.sources[0].format;return K.find(o=>o.reads.has(t)&&o.writes.has(e.target))}return K.find(t=>t.ops.has(e.op))}async function xr(e){let t;for(let o of K)try{return await o.probe(e)}catch(n){T(t)||(t=n)}throw t}export{zn as a,It as b,qn as c,Rt as d,Wn as e,K as f,vr as g,br as h,yr as i,xr as j};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
4
|
-
`),t.close()}}function T(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Ne(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw M("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:fe(o)};if(s.mode==="every-n")return{cuts:le(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Te(e,r){let t;return()=>r?(t??=Ee({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Ae(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Q(await Je(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let n;try{n=j.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!v(i))throw i;return{failure:{path:e.path,error:i}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function S(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}if(!r&&t.type==="job:phase"&&t.progress.phase==="time"){let o=t.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of 2 \xB7 ${s}`:s);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function We(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=me.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=he(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Ne(e,r.sources))}catch(a){if(!v(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function ze(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!N.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!U(e.output)?Me(e.output):void 0,g=e.output===void 0||u!==void 0?Fe(i.path):Fe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[d]=N.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:g});d?.op==="convert"&&(u!==void 0&&(d.outputs=[u]),e.dpi!==void 0&&(d.options.dpi=e.dpi),o.push(d))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function De(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-5XI5L4KW.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:c,catalogEntry:p}=await import("./catalog-YSMT3PXT.js"),f=p("boost"),x=f&&c(f)?.version,A=L(e.scale,n.version,x);if(A)return b(t,[{path:"",error:A}])}let a=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?ue:pe,u=[],g=[];for(let c of a.sources){if(!i.appliesTo([c])){g.push({path:c.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let p=ie(c,e.target);if(p){g.push({path:c.path,error:p});continue}u.push(...i.plan([c],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let d=u.length>1;d&&r.onProgress?.({completed:0,total:u.length});let l=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:S(r,d)});return{kind:t,results:l.results,failures:[...a.failures,...g,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function qe(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:ee(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[],i=[];for(let p of s.sources)p.kind==="image"&&e.media===void 0?n.push(p):p.kind==="media"&&!e.trim?a.push(p):p.kind==="image"?i.push({path:p.path,error:k("cut","it works on video and sound, not images","Try a video or sound file, such as a MOV, MP4 or WAV.")}):i.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ce(a,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),d=[...de(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],l=d.length>1;l&&r.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(r,l)});return{kind:e.kind,results:c.results,failures:[...s.failures,...i,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ge(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=f=>f.kind==="document"&&f.format==="pdf",s=C(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(f=>!o(f)):t.sources,i=[],u=[],g=Te(e.passwordStdin??!1,r.interactive??!0);for(let f of n){let x=await Ae(f,e,g,t.roots.get(f.path));"failure"in x?u.push(x.failure):i.push(x.job)}let d=await ye({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),l=[...d.jobs,...i],c=l.length>1;c&&r.onProgress?.({completed:0,total:l.length});let p=await I(l,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,c)});return{kind:"convert",results:p.results,failures:[...t.failures,...u,...d.failures,...p.refusals,...p.unreachable.map(f=>({path:f.job.sources[0].path,error:f.error})),...p.failures],inputBytes:p.inputBytes,outputBytes:p.outputBytes}}async function Ve(e,r={}){try{if(e.kind==="pageop")return await We(e);if(e.kind==="extension-op")return await De(e,r);if(e.kind==="edit")return await qe(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-HORY7KZQ.js");return await t(e)}return e.kind==="compress"?await ze(e,r):await Ge(e,r)}catch(t){if(!v(t))throw t;return b(e.kind,[{path:"",error:t}])}}function He(e,r){let t=T(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(te(m,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?ve(e):e.results.length===1?xe(e):Pe(e);return{exitCode:t,stdout:o,stderr:O(e.failures,{debug:r.debug})}}function Le(e,r){let t=[{path:"",error:e}],o=T(t);return r.json?{exitCode:o,stdout:[JSON.stringify(re(m,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:O(t,{debug:r.debug})}}async function Ue(e,r){let{runConfig:t}=await import("./config-command-TYNYVUMP.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(ne(m,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function Tt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ue(e,t);if(e.kind==="clip"){let{runClipCommand:s}=await import("./clip-command-D3DE2WUR.js");return await s(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-GMBG7BK6.js"),n=await s(m,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:m,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:s}=await import("./entry-4GMHXHST.js"),n=[];return{exitCode:await s(m,i=>n.push(i)),stdout:n,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-ABJSGDPK.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(ae(m,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(oe(m,_()))],stderr:[]}:{exitCode:0,stdout:ke(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await be(e.inputs),a=T(n);return t?{exitCode:a,stdout:[JSON.stringify(se(m,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((i,u)=>[...u>0?[""]:[],...$e(i)]),stderr:O(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-U6QBTJTQ.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}if(e.kind==="transcribe"){let{runTranscribeCommand:s}=await import("./transcribe-command-YUSBCQEQ.js"),n=[],a=[];return{exitCode:await s(e,{out:u=>n.push(u),err:u=>a.push(u)}),stdout:n,stderr:a}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw M("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");return He(await Ve(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return Le(s,{json:t,debug:o})}}export{be as a,Ie as b,T as c,Ve as d,He as e,Tt as f};
|
|
3
|
+
import{c as ne,d as ae,e as ie,g as ue,h as pe}from"./chunk-WC6SJN5Y.js";import{a as ee,b as te,c as re,k as oe,m as N,n as j,o as se}from"./chunk-OK7XOZFO.js";import{a as y}from"./chunk-CKZBBDAW.js";import{c as I}from"./chunk-GSK2A3TN.js";import{e as he}from"./chunk-Y7LOIHFU.js";import{e as ce,f as de,g as fe,h as le,i as me,j as ge}from"./chunk-57M4J2BR.js";import{a as F,c as X,d as Z,e as C,f as _}from"./chunk-PPR7B5AR.js";import{a as m}from"./chunk-XBOMWF34.js";import{d as $}from"./chunk-EEQSUBBL.js";import{a as Q}from"./chunk-LVYQVJOF.js";import{a as H,c as L}from"./chunk-SNDFMJIX.js";import{a as U,c as Y,d as E,e as K}from"./chunk-DZOBIUV6.js";import{H as M,I as q,L as G,b as P,c as w,d as v,r as z,t as k,v as D,wa as V,y as J}from"./chunk-WIPP5TWQ.js";import{a as h,b as W}from"./chunk-J7FLFHQJ.js";import{a as R}from"./chunk-H3DIRJFE.js";import{readFile as Je}from"node:fs/promises";import{dirname as Fe,resolve as Me}from"node:path";async function ye(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=F(o);if(!s.includes(e.target)){t.push({path:o.path,error:D(o,e.target,s)});continue}let n={sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)},a=E(n);Y(a,o.path)&&e.target!==o.format&&(a=K({...n,suffix:e.target})),r.push({op:"convert",sources:[o],outputs:[a],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as Ce}from"node:path";function je(e,r=new Set){let t={path:Ce(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:F(e).filter(n=>!o||C(n)),actions:ue([e],r).filter(n=>!o||n.id===j.id).map(n=>n.id)};if(e.kind==="image")return{...t,width:e.width,height:e.height,...s};if(e.kind==="media"){let n=e.facts;return{...t,...n?{duration:n.duration}:{},...n?.video?{width:n.video.width,height:n.video.height,fps:n.video.fps}:{},...s}}return{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function be(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-M6Z62OWE.js"),o=await t();return{probes:r.sources.map(s=>je(s,o)),failures:r.failures}}import{dirname as Be}from"node:path";var B=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function we(e,r){let t=P(Be(e),B(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function Ie(e,r){let{pct:t,direction:o}=W(e,r);return o==="same"?"same size":`${t}% ${o}`}function xe(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${we(s[0],r)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let i of t.warnings)a.push("",`\u26A0 ${i.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],B(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${Ie(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function Pe(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${Ie(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,B(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function ve(e,r={}){let t=e.results.flatMap(u=>u.job.outputs),o=t.map(u=>w(u)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":we(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)a.push("",`\u26A0 ${u.message}`);return a}function O(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...V(o.error,{debug:r.debug}),"");return t}function ke(){let e=new Set(X()),r=new Set(Z()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function $e(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.duration!==void 0&&t.push($(e.duration)),e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.fps!==void 0&&t.push(`${e.fps} fps`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,B(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Re}from"node:readline";import{PassThrough as Oe}from"node:stream";function Se(e){return new Promise(r=>{let t=Re({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function Ee(e){if(e.stdin)return Se(process.stdin);if(!process.stdin.isTTY)return;let r=new Oe,t=Re({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
|
|
4
|
+
`),t.close()}}function T(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Ne(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw M("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ne(o)};if(s.mode==="every-n")return{cuts:ae(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Te(e,r){let t;return()=>r?(t??=Ee({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Ae(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Q(await Je(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let n;try{n=j.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!v(i))throw i;return{failure:{path:e.path,error:i}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function S(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}if(!r&&t.type==="job:phase"&&t.progress.phase==="time"){let o=t.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of 2 \xB7 ${s}`:s);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function We(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ie.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=pe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Ne(e,r.sources))}catch(a){if(!v(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function ze(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!N.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!U(e.output)?Me(e.output):void 0,g=e.output===void 0||u!==void 0?Fe(i.path):Fe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[d]=N.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:g});d?.op==="convert"&&(u!==void 0&&(d.outputs=[u]),e.dpi!==void 0&&(d.options.dpi=e.dpi),o.push(d))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function De(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-EOYKOUBC.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:c,catalogEntry:p}=await import("./catalog-VPSTQTFD.js"),f=p("boost"),x=f&&c(f)?.version,A=L(e.scale,n.version,x);if(A)return b(t,[{path:"",error:A}])}let a=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?te:re,u=[],g=[];for(let c of a.sources){if(!i.appliesTo([c])){g.push({path:c.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let p=ee(c,e.target);if(p){g.push({path:c.path,error:p});continue}u.push(...i.plan([c],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let d=u.length>1;d&&r.onProgress?.({completed:0,total:u.length});let l=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:S(r,d)});return{kind:t,results:l.results,failures:[...a.failures,...g,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function qe(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:he(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[],i=[];for(let p of s.sources)p.kind==="image"&&e.media===void 0?n.push(p):p.kind==="media"&&!e.trim?a.push(p):p.kind==="image"?i.push({path:p.path,error:k("cut","it works on video and sound, not images","Try a video or sound file, such as a MOV, MP4 or WAV.")}):i.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=oe(a,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),d=[...se(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],l=d.length>1;l&&r.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(r,l)});return{kind:e.kind,results:c.results,failures:[...s.failures,...i,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ge(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=f=>f.kind==="document"&&f.format==="pdf",s=C(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(f=>!o(f)):t.sources,i=[],u=[],g=Te(e.passwordStdin??!1,r.interactive??!0);for(let f of n){let x=await Ae(f,e,g,t.roots.get(f.path));"failure"in x?u.push(x.failure):i.push(x.job)}let d=await ye({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),l=[...d.jobs,...i],c=l.length>1;c&&r.onProgress?.({completed:0,total:l.length});let p=await I(l,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,c)});return{kind:"convert",results:p.results,failures:[...t.failures,...u,...d.failures,...p.refusals,...p.unreachable.map(f=>({path:f.job.sources[0].path,error:f.error})),...p.failures],inputBytes:p.inputBytes,outputBytes:p.outputBytes}}async function Ve(e,r={}){try{if(e.kind==="pageop")return await We(e);if(e.kind==="extension-op")return await De(e,r);if(e.kind==="edit")return await qe(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-HMOFTZSG.js");return await t(e)}return e.kind==="compress"?await ze(e,r):await Ge(e,r)}catch(t){if(!v(t))throw t;return b(e.kind,[{path:"",error:t}])}}function He(e,r){let t=T(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(ce(m,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?ve(e):e.results.length===1?xe(e):Pe(e);return{exitCode:t,stdout:o,stderr:O(e.failures,{debug:r.debug})}}function Le(e,r){let t=[{path:"",error:e}],o=T(t);return r.json?{exitCode:o,stdout:[JSON.stringify(de(m,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:O(t,{debug:r.debug})}}async function Ue(e,r){let{runConfig:t}=await import("./config-command-6YUMMZF3.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(me(m,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function Tt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ue(e,t);if(e.kind==="clip"){let{runClipCommand:s}=await import("./clip-command-R2NKW4TI.js");return await s(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-JCTCRPCS.js"),n=await s(m,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:m,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:s}=await import("./entry-TSLQHDP7.js"),n=[];return{exitCode:await s(m,i=>n.push(i)),stdout:n,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-25JOL47P.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(ge(m,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(fe(m,_()))],stderr:[]}:{exitCode:0,stdout:ke(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await be(e.inputs),a=T(n);return t?{exitCode:a,stdout:[JSON.stringify(le(m,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((i,u)=>[...u>0?[""]:[],...$e(i)]),stderr:O(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-APVBMEJQ.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}if(e.kind==="transcribe"){let{runTranscribeCommand:s}=await import("./transcribe-command-2L7F7MCG.js"),n=[],a=[];return{exitCode:await s(e,{out:u=>n.push(u),err:u=>a.push(u)}),stdout:n,stderr:a}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw M("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");return He(await Ve(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return Le(s,{json:t,debug:o})}}export{be as a,Ie as b,T as c,Ve as d,He as e,Tt as f};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as h,c as A,g as o,m as y,n as I,p as v,q as O,r as P}from"./chunk-OK7XOZFO.js";import{a as x,b as u,d as S}from"./chunk-V3I6DSF4.js";import{g as s,h as f,j as g,k as b,l as c,m as a}from"./chunk-DZOBIUV6.js";import{H as d}from"./chunk-WIPP5TWQ.js";var l=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0,k={id:"split",label:"Split",verb:"Splitting",hint:"into several files",appliesTo:e=>(l(e)?.pages??0)>1,unavailable:e=>l(e)===void 0?"one PDF at a time":"only one page",options(e){let t=l(e);return t?[{kind:"select",id:"mode",label:"How",default:"every-page",choices:[{value:"every-page",label:"Every page",hint:`${t.pages} files`},{value:"every-n",label:"Every N pages",hint:"ask how many"},{value:"points",label:"At points I choose",hint:"grid"}]}]:[]},plan(e,t){let n=l(e);if(!n)return[];let r=Array.isArray(t.cuts)?t.cuts:[],i=S(r,n.pages).length,C=c(f(n.path,i),o(t.destination),o(t.name));return[{op:"split",sources:[n],outputs:C,cuts:r}]}};function $(e){return Array.from({length:Math.max(0,e-1)},(t,n)=>n)}function B(e,t){if(!Number.isInteger(t)||t<1)throw d("Splitting every N pages needs N to be a whole number, at least 1.");let n=[];for(let r=t;r<e;r+=t)n.push(r-1);return n}var p=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0;function D(e,t){return Array.isArray(t.pages)?u(t.pages):typeof t.pages=="string"?u(x(t.pages,e.pages)):[]}var w=e=>({kind:"text",id:"pages",label:"Pages",placeholder:`1-${e.pages}`}),T={id:"extract",label:"Extract",verb:"Extracting",hint:"keep only some pages",appliesTo:e=>p(e)!==void 0,unavailable:()=>"one PDF at a time",options:e=>{let t=p(e);return t?[w(t),{kind:"select",id:"separate",label:"Output",default:"one",choices:[{value:"one",label:"One file",hint:"all selected pages together"},{value:"many",label:"Separate files",hint:"one per page"}]}]:[]},plan(e,t){let n=p(e);if(!n)return[];let r=D(n,t),i=t.separate==="many";return[{op:"extract",sources:[n],outputs:c(g(n.path,r,i),o(t.destination),o(t.name)),pages:r,separate:i}]}},j={id:"delete",label:"Delete",verb:"Deleting",hint:"drop some pages",appliesTo:e=>p(e)!==void 0,unavailable:()=>"one PDF at a time",options:e=>{let t=p(e);return t?[w(t)]:[]},plan(e,t){let n=p(e);return n?[{op:"delete",sources:[n],outputs:[a(s(n.path,"trimmed"),o(t.destination),o(t.name))],pages:D(n,t)}]:[]}};var m=e=>e.filter(t=>t.kind==="document"&&t.format==="pdf"),J={id:"merge",label:"Merge",verb:"Merging",hint:"several files into one",appliesTo:e=>m(e).length>=2&&m(e).length===e.length,unavailable:e=>m(e).length!==e.length?"PDFs only":"needs 2+ files",options:()=>[],plan(e,t){let n=a(b(e.map(r=>r.path)),o(t.destination),o(t.name));return[{op:"merge",sources:e,outputs:[n]}]}};var N=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0,E={id:"rotate",label:"Rotate",verb:"Rotating",hint:"turn pages",appliesTo:e=>N(e)!==void 0,unavailable:()=>"one PDF at a time",options:()=>[{kind:"select",id:"degrees",label:"Turn",default:"90",choices:[{value:"90",label:"90\xB0 right",hint:"a quarter turn"},{value:"180",label:"180\xB0",hint:"upside down"},{value:"270",label:"90\xB0 left",hint:"a quarter turn back"}]}],plan(e,t){let n=N(e);if(!n)return[];let i=Number(t.degrees??90)/90%4||1;return[{op:"rotate",sources:[n],outputs:[a(s(n.path,"rotated"),o(t.destination),o(t.name))],turns:i}]}};var R=[I,y,J,k,T,j,E,v,O,P],se=R.filter(e=>!["convert","compress","trim","resize","crop"].includes(e.id)),F=[h,A];function ce(e,t=new Set){return[...R,...F.filter(n=>n.requires&&t.has(n.requires))].filter(n=>n.appliesTo(e))}function le(e,t){return e.appliesTo(t)?void 0:e.unavailable?.(t)}export{E as a,k as b,$ as c,B as d,R as e,se as f,ce as g,le as h};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as d}from"./chunk-H3DIRJFE.js";var m=e=>/^[A-Za-z0-9][A-Za-z0-9-]*$/.test(e),u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),s=e=>typeof e=="number"&&Number.isInteger(e)&&e>0;function h(e){if(!(!u(e)||Object.keys(e).length!==1)){if(s(e.width))return{width:e.width};if(s(e.height))return{height:e.height};if(s(e.percent))return{percent:e.percent}}}function b(e){if(!u(e))return;let t={};if(e.to!==void 0){if(typeof e.to!="string"||!d(e.to))return;t.to=e.to}if(e.quality!==void 0){if(!s(e.quality)||e.quality>100)return;t.quality=e.quality}if(e.maxBytes!==void 0){if(!s(e.maxBytes))return;t.maxBytes=e.maxBytes}if(e.resize!==void 0){let i=h(e.resize);if(!i)return;t.resize=i}for(let i of["trim","sharpen","removeBackground"])if(e[i]!==void 0){if(typeof e[i]!="boolean")return;t[i]=e[i]}if(e.crop!==void 0){if(!u(e.crop)||!s(e.crop.w)||!s(e.crop.h))return;t.crop={w:e.crop.w,h:e.crop.h}}if(e.boost!==void 0){if(e.boost!==2&&e.boost!==3&&e.boost!==4)return;t.boost=e.boost}if(e.compress!==void 0){if(!u(e.compress)||typeof e.compress.dither!="boolean")return;t.compress={dither:e.compress.dither}}if(e.behind!==void 0){if(e.behind!=="white"&&e.behind!=="black")return;t.behind=e.behind}return t}function z(e){if(!u(e)||typeof e.name!="string"||!m(e.name)||typeof e.saveTo!="string"||e.saveTo.trim()==="")return;let t=b(e.steps);if(t)return{name:e.name,steps:t,saveTo:e.saveTo,...e.quickAction===!0?{quickAction:!0}:{}}}var l={white:"#ffffff",black:"#000000"};function x(e,t){let i=[];e.removeBackground&&i.push({kind:"cutout"}),e.boost?i.push({kind:"boost",scale:e.boost}):e.sharpen&&i.push({kind:"boost",scale:1});let o=[];e.trim&&o.push({kind:"cut",trim:!0}),e.crop&&o.push({kind:"cut",crop:e.crop});let c=e.to??t,n={kind:"encode",target:c};if(e.quality!==void 0&&(n.quality=e.quality),e.maxBytes&&(n.maxBytes=e.maxBytes),(e.compress||e.maxBytes)&&(n.compress=e.compress??{dither:!1}),e.resize&&(n.resize=e.resize),i.length===0){let r=o.pop();r?.kind==="cut"&&(r.trim&&(n.trim=!0),r.crop&&(n.crop=r.crop))}if(n.maxBytes&&(n.trim||n.crop||n.resize)){let{trim:r,crop:a,resize:p}=n;o.push({kind:"cut",...r?{trim:r}:{},...a?{crop:a}:{},...p?{resize:p}:{}}),delete n.trim,delete n.crop,delete n.resize}if(e.removeBackground&&!d(c)?.hasAlpha&&(n.background=l[e.behind??"white"]),o.length===0&&i.length===0&&Object.keys(n).length===2&&e.to===void 0)return[];let f=o.filter(r=>r.kind==="cut"&&r.resize);return[...o.filter(r=>!f.includes(r)),...i,...f,n]}export{m as a,z as b,x as c};
|