forge-terminal 0.5.3 → 0.5.5
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 +7 -5
- package/dist/chunks/{about-credits-DBQHH5HA.js → about-credits-VRRE6342.js} +1 -1
- package/dist/chunks/{args-TZMA4ZR6.js → args-5BPKCNTL.js} +1 -1
- package/dist/chunks/{boot-E57BKWEC.js → boot-MX7UP2M2.js} +1 -1
- package/dist/chunks/{chunk-N3X3H4IZ.js → chunk-2NSUAERD.js} +1 -1
- package/dist/chunks/{chunk-6LMVOQQA.js → chunk-2ZZXIDYX.js} +1 -1
- package/dist/chunks/{chunk-FLMQ5VFR.js → chunk-3YWAVKDZ.js} +1 -1
- package/dist/chunks/{chunk-TYWGB767.js → chunk-45BFQHJB.js} +1 -1
- package/dist/chunks/{chunk-5YUOG3A5.js → chunk-7IWX5VSI.js} +1 -1
- package/dist/chunks/{chunk-3GHHQNR6.js → chunk-BI2E72HM.js} +1 -1
- package/dist/chunks/{chunk-E2BYNETT.js → chunk-BONMSCKD.js} +1 -1
- package/dist/chunks/{chunk-EITGK5OI.js → chunk-BU4YYGUJ.js} +1 -1
- package/dist/chunks/{chunk-7VR6LODN.js → chunk-D4R7UACU.js} +1 -1
- package/dist/chunks/{chunk-IE6NFN3N.js → chunk-HACM3MAD.js} +1 -1
- package/dist/chunks/chunk-HFQOGB4T.js +4 -0
- package/dist/chunks/{chunk-ZOQA3JAR.js → chunk-HGJXGAGJ.js} +1 -1
- package/dist/chunks/{chunk-AFEYLHDD.js → chunk-HVMQTKP6.js} +1 -1
- package/dist/chunks/{chunk-IKZTH2RL.js → chunk-HYMPLIHW.js} +1 -1
- package/dist/chunks/{chunk-MNI6IKIU.js → chunk-JJV2YXZQ.js} +1 -1
- package/dist/chunks/{chunk-4YFFT5CZ.js → chunk-KDBKDURW.js} +2 -2
- package/dist/chunks/{chunk-IJRLRAC5.js → chunk-L5JBHB4G.js} +1 -1
- package/dist/chunks/chunk-MES4FVLR.js +3 -0
- package/dist/chunks/{chunk-Z2H2GT2X.js → chunk-MMLROWBQ.js} +2 -2
- package/dist/chunks/{chunk-TFOEI5VF.js → chunk-OGYSMKRM.js} +1 -1
- package/dist/chunks/{chunk-EURVTBPH.js → chunk-OUXPGAQL.js} +1 -1
- package/dist/chunks/{chunk-QPJ2LNXB.js → chunk-R7BEV6PR.js} +1 -1
- package/dist/chunks/chunk-RLOJSZ6W.js +3 -0
- package/dist/chunks/{chunk-5IZBFF6Y.js → chunk-SZCSV3PX.js} +1 -1
- package/dist/chunks/chunk-TRJXZLR6.js +82 -0
- package/dist/chunks/{chunk-TDYKRRZH.js → chunk-UGATQHEE.js} +1 -1
- package/dist/chunks/{chunk-ZYIW4MAG.js → chunk-WCOFUMZU.js} +1 -1
- package/dist/chunks/{chunk-AIINYKXW.js → chunk-ZBETH6BR.js} +1 -1
- package/dist/chunks/chunk-ZX5FDZZW.js +55 -0
- package/dist/chunks/clip-command-WJ5P4DTN.js +3 -0
- package/dist/chunks/{clipboard-7KSZNWWT.js → clipboard-3VFHDKYE.js} +1 -1
- package/dist/chunks/{colour-PZOAKNTH.js → colour-5YBDFXXX.js} +1 -1
- package/dist/chunks/command-BKAPI4A5.js +3 -0
- package/dist/chunks/{entry-REXB6JNP.js → entry-7GW4RIK2.js} +2 -2
- package/dist/chunks/execute-LBGFY5TG.js +3 -0
- package/dist/chunks/{extensions-UV4X2UUA.js → extensions-HTBACHMC.js} +1 -1
- package/dist/chunks/{extensions-command-TLW53BUK.js → extensions-command-VXZL55KR.js} +1 -1
- package/dist/chunks/{ffmpeg-32EEMAZS.js → ffmpeg-Z7JQT53Y.js} +1 -1
- package/dist/chunks/{image-YMCS4PTS.js → image-FYCF2AVH.js} +1 -1
- package/dist/chunks/{install-7ZRVQKCF.js → install-5YXQ6YV3.js} +1 -1
- package/dist/chunks/{launch-IVBMNYNY.js → launch-U63VZQXC.js} +5 -5
- package/dist/chunks/{manager-XPO4ZIRY.js → manager-QUTR3RYR.js} +2 -2
- package/dist/chunks/{needed-NOGBHTHE.js → needed-X5D4E5X5.js} +1 -1
- package/dist/chunks/{notify-YEBP67MP.js → notify-NQNNOBFC.js} +1 -1
- package/dist/chunks/{own-G4G4MRGM.js → own-5JN35AUV.js} +1 -1
- package/dist/chunks/{pdfium-BAMNBCNW.js → pdfium-GKF4ES7K.js} +1 -1
- package/dist/chunks/{preset-command-XXKLUJOS.js → preset-command-H6G22SZD.js} +1 -1
- package/dist/chunks/{registry-PKOPEG3Z.js → registry-LLAHKI4G.js} +1 -1
- package/dist/chunks/{server-AR73FWWG.js → server-CIGFNW7X.js} +3 -3
- package/dist/chunks/{theme-D4AMWFFW.js → theme-HAB66OAL.js} +1 -1
- package/dist/chunks/{transcribe-EFVJPBPG.js → transcribe-FVCOCTGA.js} +1 -1
- package/dist/chunks/{transcribe-command-Q4J3WTOB.js → transcribe-command-XCBGAQMI.js} +1 -1
- package/dist/chunks/{update-note-2YR3TLPK.js → update-note-47IPWQKY.js} +1 -1
- package/dist/chunks/{watch-command-2D7NLDAM.js → watch-command-VL6LOERU.js} +1 -1
- package/dist/index.js +9 -9
- package/package.json +5 -9
- package/dist/chunks/chunk-3CLPUPJT.js +0 -55
- package/dist/chunks/chunk-BIBDLXCG.js +0 -3
- package/dist/chunks/chunk-EPDF4NQI.js +0 -3
- package/dist/chunks/chunk-ITJZ7ODJ.js +0 -4
- package/dist/chunks/chunk-NHMACTW3.js +0 -82
- package/dist/chunks/clip-command-QPLYCGJ2.js +0 -3
- package/dist/chunks/command-DMGGGAPS.js +0 -3
- package/dist/chunks/execute-GKO4THUK.js +0 -3
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as ne,g as at,h as ct}from"./chunk-EEQSUBBL.js";import{c as le,d as ft,f as ge,g as dt,k as pt}from"./chunk-E2BYNETT.js";import{b as st,c as it}from"./chunk-IE6NFN3N.js";import{b as Ue,c as ze,d as qe,f as He,m as tt,n as ot,o as nt,t as rt}from"./chunk-TFOEI5VF.js";import{n as Ge,o as Ve,q as Ke,r as R}from"./chunk-BIBDLXCG.js";import{E as Te,F as V,G as me,I as Ne,M as Le,V as Je,a as B,aa as te,ha as We,ia as Ce,ka as J,r as Be,t as j,v as ee}from"./chunk-CVNYUROW.js";import{a as Ae}from"./chunk-J7FLFHQJ.js";import{c as A}from"./chunk-VLVNA4T3.js";import{a as S}from"./chunk-H3DIRJFE.js";import{a as Ye,b as oe,c as M,e as Ze,f as Qe,g as Xe,h as je,i as et}from"./chunk-KXKQDFHX.js";import{mkdtemp as Jt,rm as Wt}from"node:fs/promises";import{tmpdir as Ct}from"node:os";import{join as re}from"node:path";var mt=(e,t,o)=>He(e,t,o)===void 0;function ut(e,t,o=Number.POSITIVE_INFINITY,n=[2,4]){return[...n].reverse().find(s=>s<o&&mt(e,t,s))??0}async function Ut(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-FMHWWMUX.js");if(!f(r,process.platform,process.arch))throw Le(a(r)?.title??r);let{installed:d,extensionsRoot:u}=await import("./paths-6OENILJ4.js"),h=await d(r);if(!h)throw Ne(r);let l=ze(h.version);if(e.op==="boost"){let v=a(r),x=qe(e.scale,h.version,v&&i(v)?.version);if(x)throw x}if(e.op==="boost"&&!mt(n.width,n.height,e.scale))throw Je(n.path,ut(n.width,n.height,Number.POSITIVE_INFINITY,l),e.scale);let{runExtension:w}=await import("./run-WSETTQXP.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 Jt(re(Ct(),"forge-ext-"));try{t({phase:"decoding"});let v=re(I,"in.png"),x=re(I,"out.png");await nt(n,v);let $=e.op==="boost"?["--in",v,"--out",x,"--scale",String(e.scale),"--cache",re(u(),"boost","cache")]:[v,x],p=e.op==="boost"&&Ue(h.version);await w({...h,serve:p},$,{subject:n.path,what:`${zt(e)} is running on ${A(n.path)}`,onWait:()=>t({phase:"waiting"}),onStart:()=>t({phase:"encoding"}),onProgress:(O,P)=>t({phase:"tiles",done:O,total:P}),...e.op==="boost"?{maxScale:ut(n.width,n.height,e.scale,l)}:{},...o===void 0?{}:{signal:o}});let y=(await oe())(x);S[e.target].hasAlpha||(y=y.flatten({background:e.options.background}));let F=await tt(y,e.target,e.options.quality).toBuffer();t({phase:"writing"});let b=await ot(F,s);return{job:e,outputBytes:b,warnings:g}}catch(v){throw B(v)?v:J(n.path,v)}finally{await Wt(I,{recursive:!0,force:!0}).catch(()=>{})}}function zt(e){return e.op!=="boost"?"Remove background":e.scale===1?"Sharpen":`Boost resolution ${e.scale}\xD7`}var lt={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:Ut};import{randomBytes as mo}from"node:crypto";import{rm as lo,stat as se}from"node:fs/promises";import{dirname as go,join as ho}from"node:path";import{open as qt}from"node:fs/promises";async function W(e,t){let o=await qt(e,"r");try{let n=Buffer.alloc(t),{bytesRead:s}=await o.read(n,0,t,0);return n.subarray(0,s)}finally{await o.close()}}var he="%NOISE_FLOOR%",Ht=["highpass=f=80",`afftdn=nr=12:nf=${he}`],Gt="highpass=f=80,astats=measure_perchannel=none:measure_overall=RMS_trough";function vt(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 we="%LOUDNORM_MEASURED%",Vt={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"},Kt={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"]},Yt={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"]},gt=[48e3,24e3,16e3,12e3,8e3];function Zt(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:gt}: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:gt}: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 K=e=>Math.max(2,Math.floor(e/2)*2),Qt=e=>String(Math.round(e*1e3)/1e3),Xt=e=>String(Math.ceil(e*1e3)/1e3),jt=e=>Math.round(38-(e-1)*20/99),eo=e=>Math.round(50-(e-1)*30/99),to=e=>Math.round(40-(e-1)*18/99),ht=e=>Math.round(20+e*60/100),oo=e=>Math.round(31-(e-1)*29/99);function no(e,t){let o=.15*2**((18-e)/6);return Math.max(64,Math.round(t*o/1e3))}function ro(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 so="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 wt(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 io=800,ao=15,bt=32;function be(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",d=n==="gif",u=o.compress!==void 0,h=s==="darwin",l=c=>e.has===void 0||e.has.has(c),w=c=>Ce(n,c,e.os??s),g=r.cut?.start??0,I=Math.min(r.cut?.end??t.duration,t.duration),v=Math.max(0,I-g),x=r.speed??1,$=v/x,p=i!==void 0&&!f,E=a!==void 0&&!r.mute&&!d,y,F,b,O;if(r.targetBytes!==void 0&&$>0){if(p&&i){let c=at({duration:$,width:i.width,height:i.height,fps:i.fps,hasAudio:E,targetBytes:r.targetBytes});"videoKbps"in c&&(y={width:c.width,height:c.height,fps:c.fps},b=c.videoKbps,F=c.audioKbps)}else if(E){let c=Math.floor(r.targetBytes*8/$/1e3*.98);O=Math.max(bt,Math.min(320,c))}}let P=[];if(p&&i){if(i.hdr&&n!=="hevc"&&l("zscale")&&P.push(so),o.crop?.box){let c=o.crop.box;P.push(`crop=${K(c.width)}:${K(c.height)}:${c.left}:${c.top}`)}if(y)P.push(`scale=${y.width}:${y.height}`);else if(o.resize){let c=o.resize;"width"in c?P.push(`scale=trunc(min(${K(c.width)}\\,iw)/2)*2:-2`):"height"in c?P.push(`scale=-2:trunc(min(${K(c.height)}\\,ih)/2)*2`):P.push(`scale=trunc(iw*${c.percent/100}/2)*2:-2`)}if(o.rotate&&P.push(o.rotate===90?"transpose=1":o.rotate===270?"transpose=2":"hflip,vflip"),x!==1&&P.push(`setpts=PTS/${x}`),d){let c=Math.min(io,K(i.width));P.push(`fps=${Math.min(ao,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 Q=y?.fps??r.fps,Re=p&&i!==void 0&&P.length===0&&Q===void 0&&!u&&r.targetBytes===void 0&&(Kt[n]??[]).includes(i.codec),m=[],fe=!1;if(!p)m.push("-vn");else if(Re)m.push("-c:v","copy");else{if(P.length&&m.push("-vf",P.join(",")),d)m.push("-c:v","gif","-loop","0");else if(n==="webm"){if(!l("libvpx-vp9"))throw w({codec:"VP9",encoders:["libvpx-vp9"]});if(fe=b!==void 0,m.push("-c:v","libvpx-vp9","-row-mt","1","-deadline","good","-cpu-used","4"),i?.codec==="gif"&&m.push("-pix_fmt","yuva420p"),b!==void 0)m.push("-b:v",`${b}k`);else{let c=u?eo(o.quality??60):33;m.push("-crf",String(c),"-b:v","0")}}else if(n==="hevc"){let c=l("libx265"),k=h&&l("hevc_videotoolbox");if(!c&&!k)throw w({codec:"HEVC",encoders:["libx265",...h?["hevc_videotoolbox"]:[]]});if(b!==void 0)c?m.push("-c:v","libx265","-preset","fast","-b:v",`${b}k`):m.push("-c:v","hevc_videotoolbox","-b:v",`${b}k`);else if(k&&(!u||!c)){let D=u?ht(o.quality??60):60;m.push("-c:v","hevc_videotoolbox","-q:v",String(D))}else{let D=u?to(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=u?jt(o.quality??60):21,k=()=>`${b??no(c,i?ro(i,o,y,Q,x):0)}k`;if(b===void 0&&!u&&h&&l("h264_videotoolbox"))m.push("-c:v","h264_videotoolbox","-q:v","65");else if(l("libx264"))fe=b!==void 0,b!==void 0?m.push("-c:v","libx264","-preset","medium","-b:v",`${b}k`):u?m.push("-c:v","libx264","-preset","medium","-crf",String(c)):m.push("-c:v","libx264","-preset","veryfast","-crf","21");else if(h&&l("h264_videotoolbox"))b!==void 0?m.push("-c:v","h264_videotoolbox","-b:v",k()):m.push("-c:v","h264_videotoolbox","-q:v",String(ht(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(b!==void 0)m.push("-c:v","mpeg4","-b:v",`${b}k`);else{let D=u?oo(o.quality??60):3;m.push("-c:v","mpeg4","-q:v",String(D))}else throw w({codec:"H.264",encoders:["libx264",...h?["h264_videotoolbox"]:[],"libopenh264",...s==="win32"?["h264_mf"]:[]]});m.push("-pix_fmt","yuv420p")}Q!==void 0?m.push("-r",String(Q)):n==="avi"?m.push("-fps_mode","cfr"):d||m.push("-fps_mode","passthrough")}let $e=r.cleanup?[...Ht]:[],X=[...$e,...x!==1?wt(x):[]],N=r.loudness;N!==void 0&&X.push(`loudnorm=I=${N}:TP=-1.5:LRA=11:${we}:linear=true`);let _e=r.bitrate??F??O,ke=E&&a!==void 0&&X.length===0&&_e===void 0&&!(u&&f)&&(Yt[n]??[]).includes(a.codec),_=[];if(!E)_.push("-an");else if(ke)_.push("-c:a","copy");else{X.length&&_.push("-af",X.join(","));let c=Zt(n,s,l);if("codec"in c)throw w(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")&&F!==void 0&&F<=bt&&_.push("-ac","1"),N!==void 0&&a){let D=!c.rates||c.rates.includes(a.sampleRate);_.push("-ar",String(D?a.sampleRate:c.rates?.[0]))}}let de=[];g>0&&de.push("-ss",Xt(g)),r.cut&&de.push("-t",Qt(v));let H=[...de,"-i",e.input],G=[],pe=[...p?["-map","0:v:0"]:[],...E?["-map","0:a:0"]:[]],Me=o.keepMetadata?[]:["-map_metadata","-1"],Lt=Vt[n]??n,Oe=["mp4","hevc","mov","m4a"].includes(n)?["-movflags","+faststart"]:[],De=["-f",Lt,"-y",e.output],ue=s==="win32"?"NUL":"/dev/null",L=[];return r.cleanup&&L.push({args:[...H,...G,"-vn","-af",Gt,"-f","null",ue],measures:"noise"}),N!==void 0&&L.push({args:[...H,...G,"-vn","-af",`${[...$e,...x!==1?wt(x):[]].map(c=>`${c},`).join("")}loudnorm=I=${N}:TP=-1.5:LRA=11:print_format=json`,"-f","null",ue],measures:"loudness",pass:{at:1,of:2}}),fe?(L.push({args:[...H,...G,...pe.slice(0,2),...m,"-pass","1","-passlogfile",e.passlog,"-an","-f","null",ue],pass:{at:1,of:2}}),L.push({args:[...H,...G,...pe,...m,"-pass","2","-passlogfile",e.passlog,..._,...Me,...Oe,...De],pass:{at:2,of:2}})):L.push({args:[...H,...G,...pe,...m,..._,...Me,...Oe,...De],...N!==void 0?{pass:{at:2,of:2}}:{}}),{steps:L,duration:$,copies:{video:Re,audio:ke},...y?{fitted:y}:{}}}var C=(e,t,o)=>e.subarray(t,t+o).toString("latin1"),co=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1","avif","avis","crx "]),fo=new Set(["M4A ","M4B ","M4P ","F4A ","F4B "]);function po(e){let t=C(e,8,4);if(!co.has(t))return t==="qt "?"mov":fo.has(t)?"m4a":"mp4"}function yt(e){if(e.length<4)return;if(C(e,4,4)==="ftyp")return po(e);if(e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163)return e.includes("webm",0,"latin1")?"webm":"mkv";let t=C(e,0,4);if(t==="RIFF"){let o=C(e,8,4);return o==="WAVE"?"wav":o==="AVI "?"avi":void 0}if(t==="FORM"){let o=C(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(C(e,0,3)==="ID3"||e[0]===255&&((e[1]??0)&224)===224&&((e[1]??0)&6)===2)return"mp3"}var wo=["mp4","mov","webm","mkv","avi","gif"],Pt=["mp4","mov","hevc","webm","mkv","avi","gif","mp3","m4a","wav"],bo=["mp3","m4a","wav","aiff","flac","opus","ogg"],vo=["mp3","m4a","opus","flac","aiff","wav"];function yo(e){return W(e,64)}function xo(e,t){return t&&!t.video&&(e==="mp4"||e==="mov")?"m4a":e}async function Et(e,t){let o=yt(await yo(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 se(e)).size,s=await le(),r;if(s){try{r=await ge(e,s)}catch(a){throw j(e,a)}if(r.duration<=0||!r.video&&!r.audio)throw j(e,r)}let i=xo(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 Po(){let{assetFor:e,catalogEntry:t}=await import("./catalog-FMHWWMUX.js"),o=t("video");return o!==void 0&&e(o)!==void 0}async function Eo(e,t){if(e.kind==="media"&&e.facts)return e.facts;try{return await ge(e.path,t)}catch(o){throw j(e.path,o)}}function Fo(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 Ft(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=ct({...n,duration:Fo(e,n.duration)},{soundOnly:S[e.target].media==="sound",mute:s.mute===!0||e.target==="gif"});return t<r?{floor:r}:void 0}function So(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 xt(e){await Promise.all(e.map(t=>lo(t,{force:!0}).catch(()=>{})))}async function St(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 le();if(!r)throw We(n.path,process.platform,await Po());let i=await Eo(n,r),a=mo(6).toString("hex"),f=Ge(s,a),d=ho(go(s),`.forge-pass-${a}`),u=[f,`${d}-0.log`,`${d}-0.log.temp`,`${d}-0.log.mbtree`,`${d}-0.log.mbtree.temp`],h=[],l=(p,E=e.options)=>be({input:n.path,output:f,target:e.target,facts:i,options:E,platform:p,os:process.platform,passlog:d,...r.has?{has:r.has}:{}}),w=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 ${ne(i.duration)} long.`);await Ve(s);let I=process.platform,v=w.media?.cut;if(g.copies.video&&v&&v.start>0){let p=await dt(n.path,v.start,r);p!==void 0&&v.start-p>.05&&(w={...w,media:{...w.media,cut:{...v,start:p}}},g=l(process.platform,w),h.push({code:"media-cut-keyframe",message:`It starts at ${ne(p)}, the keyframe just before ${ne(v.start)}.`}))}let x=async p=>{let E="",y="";for(let F of p.steps){let b=F.args.map(P=>P.replace(we,E).replace(he,y)),O=await pt(b,{tools:r,signal:o,report:F.measures!==void 0,onTime:P=>t({phase:"time",done:Math.min(P,p.duration),total:p.duration,...F.pass?{pass:F.pass}:{}})});F.measures==="loudness"&&(E=So(O)),F.measures==="noise"&&(y=String(vt(O)))}};try{try{await x(g)}catch(y){if(o?.aborted||!g.steps.some(F=>F.args.some(b=>b.endsWith("_videotoolbox"))))throw y;I="linux",g=l(I,w),await x(g)}let p=w.media?.targetBytes;for(let y of[.95,.9]){if(p===void 0||(await se(f)).size<=p)break;w={...w,media:{...w.media,targetBytes:Math.floor(p*y)}},g=l(I,w),await x(g)}let E=(await se(f)).size;if(p!==void 0&&E>p)throw Be(n,e.options.media?.targetBytes??p,E);if(e.options.compress!==void 0&&E>=n.bytes)throw te(n.path,n.bytes,E);await Ke(f,s)}catch(p){throw await xt(u),o?.aborted||B(p)?p:J(n.path,p)}await xt(u.slice(1));let $=i.video;if(g.fitted&&$&&(g.fitted.width<$.width-2||g.fitted.fps<$.fps)){let p=Ae(e.options.media?.targetBytes??0);h.push({code:"media-fitted",message:`To fit ${p} it is now ${g.fitted.width}\xD7${g.fitted.height} at ${g.fitted.fps} fps.`})}return{job:e,outputBytes:(await se(s)).size,warnings:h}}function Zn(e,t){if(e.kind!=="media"||!e.facts)return;let o=ft()?.has;if(o)try{be({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 B(n)&&n.code==="encoder-missing"?n:void 0}}var Y=e=>new Set(e);function Io(e){let t=e.kind==="media"?e.facts:void 0,o=e.kind==="image"||t!==void 0&&t.audio===void 0;return Y(Pt.filter(n=>!(o&&S[n].media==="sound"||n==="hevc"&&t?.video?.codec==="hevc")))}var It={id:"video",reads:Y(wo),writes:Y(Pt),ops:new Set(["convert"]),probe:e=>Et(e,"video"),alone:!0,run:St,sizeTo:Ft,writesFor:Io},Rt={id:"sound",reads:Y(bo),writes:Y(vo),ops:new Set(["convert"]),probe:e=>Et(e,"sound"),alone:!0,run:St,sizeTo:Ft};import{readFile as ie,rm as Mt,stat as Ro}from"node:fs/promises";function jn(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 d=a;d<=f;d++)n.add(d-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 $t(e){return[...new Set(e)].sort((t,o)=>t-o)}function er(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 _t(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 ye=Ye(()=>import("./pdf-compress-U2E3CNXG.js")),$o=new Set(["pdf","jpeg","png","webp","avif","gif","tiff"]),_o=new Set(["pdf"]);async function U(e){return(await M()).PDFDocument.load(await ie(e),{ignoreEncryption:!0})}var ko=1024,kt=Buffer.from("%PDF-","latin1");async function Mo(e){return(await W(e,ko+kt.length)).indexOf(kt)!==-1}async function Oo(e){if(!await Mo(e))throw new Error(`${e} is not a PDF`);let{surveyDocument:t}=await ye(),o=await U(e),{size:n}=await Ro(e);return{kind:"document",path:e,format:"pdf",bytes:n,pages:o.getPageCount(),encrypted:o.isEncrypted,images:t(o)}}function z(e){for(let t of e)if(t.encrypted)throw ee(t.path)}async function Do(e,t,o){let n=await oe(),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 Ao(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 ie(o.path);t({phase:"encoding"});let i=await(await M()).PDFDocument.create(),a=await Do(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 d=await R(e.outputs[0],await i.save());return{job:e,outputBytes:d,warnings:n}}async function Bo(e,t){z(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 U(i.path),f=await n.copyPages(a,a.getPageIndices());for(let d of f)n.addPage(d)}t({phase:"writing"});let s=await n.save(),r=await R(e.outputs[0],s);return{job:e,outputBytes:r,warnings:[]}}async function To(e,t){let o=e.sources[0];z([o]);let n=await M();t({phase:"reading"});let s=await U(o.path),r=_t(e.cuts,s.getPageCount()),i=[],a=0;try{for(let[f,d]of r.entries()){let u=await n.PDFDocument.create(),h=Array.from({length:d.to-d.from+1},(g,I)=>d.from+I),l=await u.copyPages(s,h);for(let g of l)u.addPage(g);let w=e.outputs[f];if(w===void 0)throw new Error(`split produced ${r.length} parts but was given ${e.outputs.length} outputs`);a+=await R(w,await u.save()),i.push(w),t({phase:"page",done:f+1,total:r.length})}}catch(f){throw await Promise.all(i.map(d=>Mt(d,{force:!0}))),f}return{job:e,outputBytes:a,warnings:[]}}async function ve(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 No(e,t){let o=e.sources[0];if(z([o]),e.pages.length===0)throw me("That extract selects no pages.");t({phase:"reading"});let n=await U(o.path),s=$t(e.pages),r=[],i=0;try{if(e.separate)for(let[a,f]of s.entries()){let d=e.outputs[a];i+=await R(d,await ve(n,[f])),r.push(d),t({phase:"page",done:a+1,total:s.length})}else{t({phase:"writing"});let a=e.outputs[0];i=await R(a,await ve(n,s)),r.push(a)}}catch(a){throw await Promise.all(r.map(f=>Mt(f,{force:!0}))),a}return{job:e,outputBytes:i,warnings:[]}}async function Lo(e,t){let o=e.sources[0];z([o]),t({phase:"reading"});let n=await U(o.path),s=new Set(e.pages),r=n.getPageIndices().filter(a=>!s.has(a));if(r.length===0)throw me("That would delete every page.");t({phase:"writing"});let i=await R(e.outputs[0],await ve(n,r));return{job:e,outputBytes:i,warnings:[]}}async function Jo(e,t){let o=e.sources[0];z([o]);let n=await M();t({phase:"reading"});let s=await U(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 Wo(e,t){let o=e.sources[0];z([o]);let{compressPdf:n}=await ye();t({phase:"reading"});let s=await ie(o.path);t({phase:"encoding"});let{bytes:r,recompressed:i,skipped:a,fromDpi:f,toDpi:d}=await n(s,{quality:e.options.quality??60,dpi:e.options.dpi??150});if(e.options.compress&&r.length>=o.bytes)throw te(o.path,o.bytes,r.length);t({phase:"writing"});let u=await R(e.outputs[0],r),h=w=>w===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${h(a)} could be re-encoded \u2014 they are not JPEG data.`}):a>0&&l.push({code:"pdf-images-skipped",message:`${i} image${h(i)} recompressed, ${a} skipped (not JPEG).`}),f!==void 0&&d!==void 0&&l.push({code:"pdf-downsampled",message:`Images reduced from ${f} to ${d} dpi. Pass --dpi ${f} to keep them.`}),{job:e,outputBytes:u,warnings:l}}async function Co(e){if(e.op!=="convert")return;let t=e.sources[0];if(t.kind!=="document")return;let{compressPdf:o}=await ye(),n=await ie(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 Ot={id:"pdf",measurer:Co,reads:$o,writes:_o,ops:new Set(["convert","merge","split","extract","delete","rotate"]),probe:Oo,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"?Wo(e,t):Ao(e,t);case"merge":return Bo(e,t);case"split":return To(e,t);case"extract":return No(e,t);case"delete":return Lo(e,t);case"rotate":return Jo(e,t);default:throw new Error(`the pdf engine cannot ${e.op}`)}}};import{execFile as Uo}from"node:child_process";import{mkdtemp as zo,readFile as Se,rm as qo}from"node:fs/promises";import{tmpdir as Ho}from"node:os";import{basename as Go,extname as Vo,join as Dt,win32 as Ee}from"node:path";import{pathToFileURL as Ko}from"node:url";import{promisify as Yo}from"node:util";var Fe=Yo(Uo),q=Buffer.from([208,207,17,224,161,177,26,225]);async function Zo(e){if(e.length<q.length||!e.subarray(0,q.length).equals(q))return!1;let t=await je();try{return t.find(t.parse(e),"WordDocument")!==null}catch{return!1}}async function Qo(e){let t=await Xe();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}}var At=Buffer.from([80,75,3,4]);async function Xo(e){let t=await W(e,q.length);return t.subarray(0,At.length).equals(At)||t.subarray(0,q.length).equals(q)}async function jo(e){if(!await Xo(e))throw new Error(`${e} is not a Word document`);let t=await Se(e),o=await Qo(t);if(o)return{kind:"document",path:e,format:"docx",bytes:t.byteLength,pages:o.pages,encrypted:!1};if(await Zo(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 en(e,t){return e==="win32"?[Ee.join(t.ProgramFiles??"C:\\Program Files","LibreOffice","program","soffice.exe"),Ee.join(t["ProgramFiles(x86)"]??"C:\\Program Files (x86)","LibreOffice","program","soffice.exe")]:["/Applications/LibreOffice.app/Contents/MacOS/soffice"]}var tn=0;async function on(){tn++;try{return await Fe("soffice",["--version"],{timeout:5e3}),"soffice"}catch{}for(let e of en(process.platform,process.env))try{return await Fe(e,["--version"],{timeout:5e3}),e}catch{}}var Bt,nn=!1,rn;async function sn(){return nn?rn:(Bt??=on(),Bt)}var Ie="\f";function ae(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)}async function an(e){if(e.format==="docx"){let o=await Ze(),{value:n}=await o.extractRawText({path:e.path});return ae(n)}if(e.format==="doc"){let o=await Qe(),s=await new o().extract(e.path);return ae(s.getBody())}return(await st(await Se(e.path))).flatMap((o,n)=>n===0?ae(o):[Ie,...ae(o)])}var xe=612,ce=792,T=54,Pe=11,Tt=14;async function cn(e){let{PDFDocument:t,StandardFonts:o}=await M(),n=await t.create(),s=await n.embedFont(o.Helvetica),r=xe-T*2,i=n.addPage([xe,ce]),a=ce-T,f=()=>{i=n.addPage([xe,ce]),a=ce-T};for(let d of e){if(d===Ie){f();continue}let u="";for(let h of d.split(/\s+/).filter(Boolean)){let l=u?`${u} ${h}`:h;u&&s.widthOfTextAtSize(l,Pe)>r?(a<T&&f(),i.drawText(u,{x:T,y:a,size:Pe,font:s}),a-=Tt,u=h):u=l}u&&(a<T&&f(),i.drawText(u,{x:T,y:a,size:Pe,font:s}),a-=Tt)}return n.save()}async function fn(e){let{Document:t,Packer:o,PageBreak:n,Paragraph:s}=await et(),r=e.map(a=>a===Ie?new s({children:[new n]}):new s(a)),i=new t({sections:[{children:r}]});return o.toBuffer(i)}var dn=new Set(["docx","doc","pdf"]),pn=new Set(["docx","pdf"]),un=new Set(["convert"]),mn={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 ln(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"?mn:{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 gn(e,t,o,n=process.platform){return[`-env:UserInstallation=${n==="win32"?Ko(Ee.join(e,"profile"),{windows:!0}).href:`file://${e}/profile`}`,"--headless","--convert-to",o,"--outdir",e,t]}async function hn(e,t,o){let n=await zo(Dt(Ho(),"forge-word-"));try{await Fe(e,gn(n,t,o),{timeout:12e4});let s=Go(t,Vo(t));return await Se(Dt(n,`${s}.${o}`))}finally{await qo(n,{recursive:!0,force:!0})}}async function wn(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 ee(o.path);t({phase:"reading"});let n=await sn();t({phase:"encoding"});let s=[],r;try{if(n!==void 0)r=await hn(n,o.path,e.target);else{let a=await an(o);r=e.target==="pdf"?await cn(a):await fn(a),s.push(ln())}}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 Nt={id:"word",reads:dn,writes:pn,ops:un,probe:jo,run:wn};var Z=[rt,It,Rt,Ot,Nt,lt,it];function kr(e){return Z.find(t=>t.reads.has(e))}function Mr(e){return Z.find(t=>t.writes.has(e))}function Or(e){if(e.op==="convert"){let t=e.sources[0].format;return Z.find(o=>o.reads.has(t)&&o.writes.has(e.target))}return Z.find(t=>t.ops.has(e.op))}async function Dr(e){let t;for(let o of Z)try{return await o.probe(e)}catch(n){B(t)||(t=n)}throw t}export{jn as a,$t as b,er as c,_t as d,Zn as e,Z as f,kr as g,Mr as h,Or as i,Dr as j};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as ie,d as ue,e as pe,g as ce,h as de}from"./chunk-EURVTBPH.js";import{a as re,b as oe,c as se,k as ne,m as M,n as O,s as ae}from"./chunk-3GHHQNR6.js";import{b as X,c as T}from"./chunk-6RMRWBMB.js";import{a as y}from"./chunk-IKZTH2RL.js";import{b as I}from"./chunk-ZYIW4MAG.js";import{e as be}from"./chunk-7VR6LODN.js";import{a as F,c as _,d as ee,e as C,f as te}from"./chunk-5IZBFF6Y.js";import{e as fe,f as le,g as me,h as ge,i as he,j as ye}from"./chunk-57M4J2BR.js";import{a as g}from"./chunk-AFEYLHDD.js";import{d as $}from"./chunk-EEQSUBBL.js";import{a as Z}from"./chunk-IE6NFN3N.js";import{a as L,d as U}from"./chunk-TFOEI5VF.js";import{a as Y,c as K,d as E,e as Q}from"./chunk-BIBDLXCG.js";import{E as N,F as V,I as G,a as P,o as z,q as k,s as q,ta as H,v as J}from"./chunk-CVNYUROW.js";import{a as h,b as W}from"./chunk-J7FLFHQJ.js";import{b as x,c as w}from"./chunk-VLVNA4T3.js";import{a as R}from"./chunk-H3DIRJFE.js";import{readFile as Te}from"node:fs/promises";import{dirname as Oe,resolve as Me}from"node:path";async function we(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:q(o,e.target,s)});continue}let a={sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)},n=E(a);K(n,o.path)&&e.target!==o.format&&(n=Q({...a,suffix:e.target})),r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as je}from"node:path";function Be(e,r=new Set){let t={path:je(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:F(e).filter(a=>!o||C(a)),actions:ce([e],r).filter(a=>!o||a.id===O.id).map(a=>a.id)};if(e.kind==="image")return{...t,width:e.width,height:e.height,...s};if(e.kind==="media"){let a=e.facts;return{...t,...a?{duration:a.duration}:{},...a?.video?{width:a.video.width,height:a.video.height,fps:a.video.fps}:{},...s}}return{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function Ie(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-TNMISSBA.js"),o=await t();return{probes:r.sources.map(s=>Be(s,o)),failures:r.failures}}import{dirname as Se}from"node:path";var j=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ve(e,r){let t=x(Se(e),j(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function xe(e,r){let{pct:t,direction:o}=W(e,r);return o==="same"?"same size":`${t}% ${o}`}function Pe(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 n=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ve(s[0],r)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let i of t.warnings)n.push("",`\u26A0 ${i.message}`);return n}let a=[`\u2713 ${w(o.path)} \u2192 ${x(s[0],j(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${xe(o.bytes,t.outputBytes)}`];for(let n of t.warnings)a.push("",`\u26A0 ${n.message}`);return a}function ke(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${xe(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let a of s.job.outputs)t.push(` ${x(a,j(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 $e(e,r={}){let t=e.results.flatMap(u=>u.job.outputs),o=t.map(u=>w(u)).join(", "),s=t.length===1?"file":"files",a=t[0]===void 0?"":ve(t[0],r),n=[`\u2713 ${t.length} ${s} \xB7 ${o}${a}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)n.push("",`\u26A0 ${u.message}`);return n}function B(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...H(o.error,{debug:r.debug}),"");return t}function Re(){let e=new Set(_()),r=new Set(ee()),t=["Formats",""];for(let s of e){let a=R[s],n=r.has(s)?"read and write":"read only";t.push(` ${a.label.padEnd(6)} ${a.extensions.join(" ").padEnd(12)} ${n}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[a,n]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${a} read only because Forge cannot yet write ${n}.`)}return t}function Ee(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"),[`${x(e.path,j(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Fe}from"node:readline";import{PassThrough as Je}from"node:stream";function Ne(e){return new Promise(r=>{let t=Fe({input:e,terminal:!1}),o=!1,s=a=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(a.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function Ce(e){if(e.stdin)return Ne(process.stdin);if(!process.stdin.isTTY)return;let r=new Je,t=Fe({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 Ae(e){return e.kind==="preset"?e.name:e.kind==="pageop"?"PDF":e.kind==="compress"?"Compress":e.kind==="convert"?"Convert":"Edit"}function A(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function De(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(n=>n.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw N("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:ue(o,s.n)};let a=Math.max(o-1,0);for(let n of s.after)if(!Number.isInteger(n)||n<1||n>a)throw V(String(n),`"${n}" is outside 1 and ${a} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(n=>n-1)}}function We(e,r){let t;return()=>r?(t??=Ce({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function ze(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 Z(await Te(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let a;try{a=O.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(!P(i))throw i;return{failure:{path:e.path,error:i}}}let n=a[0];if(n?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(n.options.password=s),{job:n}}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 qe(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=pe.find(n=>n.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 n=de(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,n)}])}let s;try{s=t.plan(r.sources,De(e,r.sources))}catch(n){if(!P(n))throw n;return b("pageop",[...r.failures,{path:o,error:n}])}let a=await I(s,{force:e.force});return{kind:"pageop",results:a.results,failures:[...r.failures,...a.refusals,...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Ve(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!M.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!Y(e.output)?Me(e.output):void 0,f=e.output===void 0||u!==void 0?Oe(i.path):Oe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[d]=M.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:f});d?.op==="convert"&&(u!==void 0&&(d.outputs=[u]),e.dpi!==void 0&&(d.options.dpi=e.dpi),o.push(d))}let a=o.length>1;a&&r.onProgress?.({completed:0,total:o.length});let n=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,a)});return{kind:"compress",results:n.results,failures:[...t.failures,...s,...n.refusals,...n.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Ge(e,r){let t=e.kind,o=e.op==="remove-background"?L(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-6OENILJ4.js"),a=await s(e.op);if(!a)return b(t,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:p}=await import("./catalog-FMHWWMUX.js"),m=p("boost"),v=m&&l(m)?.version,D=U(e.scale,a.version,v);if(D)return b(t,[{path:"",error:D}])}let n=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?oe:se,u=[],f=[];for(let l of n.sources){if(!i.appliesTo([l])){f.push({path:l.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=re(l,e.target);if(p){f.push({path:l.path,error:p});continue}u.push(...i.plan([l],{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:n.roots}))}let d=u.length>1;d&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:S(r,d)});return{kind:t,results:c.results,failures:[...n.failures,...f,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function He(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:be(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),a=[],n=[],i=[];for(let p of s.sources)p.kind==="image"&&e.media===void 0?a.push(p):p.kind==="media"&&!e.trim?n.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=ne(n,{...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=[...ae(a,{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],c=d.length>1;c&&r.onProgress?.({completed:0,total:d.length});let l=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(r,c)});return{kind:e.kind,results:l.results,failures:[...s.failures,...i,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function Le(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=m=>m.kind==="document"&&m.format==="pdf",s=C(e.target),a=s?t.sources.filter(o):[],n=s?t.sources.filter(m=>!o(m)):t.sources,i=[],u=[],f=We(e.passwordStdin??!1,r.interactive??!0);for(let m of a){let v=await ze(m,e,f,t.roots.get(m.path));"failure"in v?u.push(v.failure):i.push(v.job)}let d=await we({resolved:{sources:n,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),c=[...d.jobs,...i],l=c.length>1;l&&r.onProgress?.({completed:0,total:c.length});let p=await I(c,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,l)});return{kind:"convert",results:p.results,failures:[...t.failures,...u,...d.failures,...p.refusals,...p.unreachable.map(m=>({path:m.job.sources[0].path,error:m.error})),...p.failures],inputBytes:p.inputBytes,outputBytes:p.outputBytes}}async function Ue(e,r={}){try{if(e.kind==="pageop")return await qe(e);if(e.kind==="extension-op")return await Ge(e,r);if(e.kind==="edit")return await He(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-XXKLUJOS.js");return await t(e)}return e.kind==="compress"?await Ve(e,r):await Le(e,r)}catch(t){if(!P(t))throw t;return b(e.kind,[{path:"",error:t}])}}function Ye(e,r){let t=A(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(fe(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?$e(e):e.results.length===1?Pe(e):ke(e);return{exitCode:t,stdout:o,stderr:B(e.failures,{debug:r.debug})}}function Ke(e,r){let t=[{path:"",error:e}],o=A(t);return r.json?{exitCode:o,stdout:[JSON.stringify(le(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:B(t,{debug:r.debug})}}async function Qe(e,r){let{runConfig:t}=await import("./config-command-6GXRV627.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(he(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function zt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Qe(e,t);if(e.kind==="clip"){let{runClipCommand:n}=await import("./clip-command-QPLYCGJ2.js");return await n(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:n}=await import("./update-command-DJLYU6AB.js"),i=await n(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...i.data})]:i.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:n}=await import("./entry-REXB6JNP.js"),i=[];return{exitCode:await n(g,f=>i.push(f)),stdout:i,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:n}=await import("./extensions-command-TLW53BUK.js"),i=await n(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(ye(g,i.data))]:i.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(me(g,te()))],stderr:[]}:{exitCode:0,stdout:Re(),stderr:[]};if(e.kind==="probe"){let{probes:n,failures:i}=await Ie(e.inputs),u=A(i);return t?{exitCode:u,stdout:[JSON.stringify(ge(g,{probes:n,failures:i}))],stderr:[]}:{exitCode:u,stdout:n.flatMap((f,d)=>[...d>0?[""]:[],...Ee(f)]),stderr:B(i,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:n,runScale:i}=await import("./colour-PZOAKNTH.js"),u={json:t,colour:r.colour??!1};return e.kind==="palette"?await n(e,u):await i(e,u)}if(e.kind==="transcribe"){let{runTranscribeCommand:n}=await import("./transcribe-command-Q4J3WTOB.js"),i=[],u=[],f;return{exitCode:await n(e,{out:c=>i.push(c),err:c=>u.push(c),finished:c=>{f=T("Transcribe",c)}}),stdout:i,stderr:u,...f?{notice:f}:{}}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw N("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");let s=await Ue(e,r),a=T(Ae(e),X(s.results,s.failures));return{...Ye(s,{json:t,debug:o}),...a?{notice:a}:{}}}catch(s){if(!P(s))throw s;return Ke(s,{json:t,debug:o})}}export{Ie as a,xe as b,A as c,Ue as d,Ye as e,zt as f};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{A as ge,B as le,C as pe,D as he,a,b as te,c as re,d as k,e as $,f as O,g as D,h as ie,j as oe,k as l,l as A,m as se,n as x,o as H,p as ae,q as E,r as L,s as R,t as ce,u as I,v as ue,w as fe,x as me,y as de,z as B}from"./chunk-3CLPUPJT.js";import{r as M}from"./chunk-BIBDLXCG.js";import{execFile as Ye}from"node:child_process";import{chmodSync as Q,existsSync as Ie,mkdirSync as Z,readdirSync as be,readFileSync as N,rmdirSync as qe,rmSync as p,writeFileSync as We}from"node:fs";import{dirname as P,join as c}from"node:path";var je={convert:"#55c7d9",compress:"#79c98b",edit:"#b39ae8",pdf:"#ff6b4a"},_e="#55c7d9",Ge="#a68ce0",Te=4/5,Je=(e,n,t,i)=>`<path fill="${i}" d="M${e} ${n}h${4*t}v${t}h${-3*t}v${t}h${2*t}v${t}h${-2*t}v${2*t}h${-t}z"/>`;function Ke(e,n){let t=n<=20,i=t?3:4,r=t?6:4.6,o=t?51:51.5,m=Array.from({length:i},(g,w)=>o-(i-1-w)*r).map(g=>`<line x1="${g}" y1="66" x2="${g+66*Te}" y2="0"/>`).join(""),u=e==="forge"?"url(#w)":je[e];return`<svg width="${n}" height="${n}" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="w" gradientUnits="userSpaceOnUse" x1="34" y1="0" x2="62" y2="0"><stop offset="0" stop-color="${_e}"/><stop offset="1" stop-color="${Ge}"/></linearGradient><clipPath id="c"><rect width="64" height="64" rx="14"/></clipPath><clipPath id="i"><rect x="1.5" y="1.5" width="61" height="61" rx="12.5"/></clipPath></defs><g clip-path="url(#c)"><rect width="64" height="64" fill="#1e1e1e"/><g clip-path="url(#i)" stroke="${u}" stroke-width="${t?3.6:2.4}">${m}</g>${Je(16,12,8,"#e7e7e7")}</g><rect x=".75" y=".75" width="62.5" height="62.5" rx="13.5" fill="none" stroke="#3a3a3a" stroke-width="1.5"/></svg>`}async function v(e,n){let{default:t}=await import("sharp");return t(Buffer.from(Ke(e,n))).png().toBuffer()}function ye(e){let n=Buffer.alloc(6);n.writeUInt16LE(0,0),n.writeUInt16LE(1,2),n.writeUInt16LE(e.length,4);let t=6+16*e.length,i=e.map(({size:r,png:o})=>{let s=Buffer.alloc(16);return s[0]=r>=256?0:r,s[1]=r>=256?0:r,s.writeUInt16LE(1,4),s.writeUInt16LE(32,6),s.writeUInt32LE(o.length,8),s.writeUInt32LE(t,12),t+=o.length,s});return Buffer.concat([n,...i,...e.map(r=>r.png)])}function h(e){let n=[{action:"open",label:"Open Forge",kinds:["image","folder"],window:!0,paint:"forge"},{action:"convert",label:"Convert in Forge",kinds:["image","folder"],window:!0,paint:"convert"},{action:"compress",label:"Compress in Forge",kinds:["image","folder"],window:!0,paint:"compress"},{action:"sharpen",label:"Sharpen in Forge",kinds:["image"],window:!1,paint:"edit"},{action:"open-pdf",label:"Open in Forge",kinds:["pdf"],window:!0,paint:"pdf"}],t=(e.presets??[]).map(i=>({action:"preset",preset:i,label:`${i} in Forge`,kinds:["image"],window:!1,paint:"forge"}));return[...e.sharpen?n:n.filter(i=>i.action!=="sharpen"),...t]}var U="Forge was uninstalled",j="Its menu items are removed.",we="Forge could not start",$e="Run forge in a terminal once to set its menu up again.";function xe(e){let{osascript:n,pbs:t}=e.tools??{osascript:"/usr/bin/osascript",pbs:"/System/Library/CoreServices/pbs"},i=[e.node,...e.execArgv,e.forge].map(a).join(" "),[r,o]=$({on:[],off:e.services,osascript:n}),s=[r,...o].map(a).join(" "),m=(u,g)=>`${a(n)} -e 'display notification "${g}" with title "${u}"'`;return`#!/bin/sh
|
|
4
|
-
# Forge's right-click menu. Rewritten by Forge whenever it sets the menu up.
|
|
5
|
-
if [ ! -f ${a(e.forge)} ]; then
|
|
6
|
-
# Forge is gone: take its menu with it, and say so once.
|
|
7
|
-
${e.bundles.map(u=>` rm -rf ${a(u)}`).join(`
|
|
8
|
-
`)}
|
|
9
|
-
rm -rf ${a(e.menuDir)}
|
|
10
|
-
${s}
|
|
11
|
-
${a(t)} -update
|
|
12
|
-
${m(U,j)}
|
|
13
|
-
exit 0
|
|
14
|
-
fi
|
|
15
|
-
if [ ! -x ${a(e.node)} ]; then
|
|
16
|
-
${m(we,$e)}
|
|
17
|
-
exit 1
|
|
18
|
-
fi
|
|
19
|
-
${e.xdgConfigHome===void 0?"":`export XDG_CONFIG_HOME=${a(e.xdgConfigHome)}
|
|
20
|
-
`}exec ${i} menu run "$@"
|
|
21
|
-
`}function ve(e){let n=e.xdgConfigHome===void 0?{}:{XDG_CONFIG_HOME:e.xdgConfigHome};return`// Forge's right-click menu. Rewritten by Forge whenever it sets the menu up.
|
|
22
|
-
import { execFileSync, spawn } from 'node:child_process'
|
|
23
|
-
import { existsSync, rmSync } from 'node:fs'
|
|
24
|
-
|
|
25
|
-
const FORGE = ${JSON.stringify(e.forge)}
|
|
26
|
-
const ARGS = ${JSON.stringify(e.execArgv)}
|
|
27
|
-
const MENU = ${JSON.stringify(e.menuDir)}
|
|
28
|
-
const KEYS = ${JSON.stringify(e.keys)}
|
|
29
|
-
const ENV = ${JSON.stringify(n)}
|
|
30
|
-
|
|
31
|
-
if (existsSync(FORGE)) {
|
|
32
|
-
const child = spawn(process.execPath, [...ARGS, FORGE, 'menu', 'run', ...process.argv.slice(2)], {
|
|
33
|
-
stdio: 'inherit',
|
|
34
|
-
windowsHide: true,
|
|
35
|
-
env: { ...process.env, ...ENV },
|
|
36
|
-
})
|
|
37
|
-
child.on('exit', (code) => process.exit(code ?? 0))
|
|
38
|
-
} else {
|
|
39
|
-
// Forge is gone: say so while its app ID still exists, then take the menu with it.
|
|
40
|
-
try {
|
|
41
|
-
execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', ${JSON.stringify(he(U,j))}], { windowsHide: true })
|
|
42
|
-
} catch {}
|
|
43
|
-
for (const key of KEYS) {
|
|
44
|
-
try {
|
|
45
|
-
execFileSync('reg.exe', ['delete', key, '/f'], { windowsHide: true, stdio: 'ignore' })
|
|
46
|
-
} catch {}
|
|
47
|
-
}
|
|
48
|
-
rmSync(MENU, { recursive: true, force: true })
|
|
49
|
-
}
|
|
50
|
-
`}function Ve(){return`say() {
|
|
51
|
-
if command -v notify-send >/dev/null 2>&1; then
|
|
52
|
-
notify-send --app-name=Forge -- "$1" "$2" >/dev/null 2>&1
|
|
53
|
-
elif command -v gdbus >/dev/null 2>&1; then
|
|
54
|
-
${["gdbus call --session --dest org.freedesktop.Notifications","--object-path /org/freedesktop/Notifications","--method org.freedesktop.Notifications.Notify",`Forge 0 "''" "\\"$1\\"" "\\"$2\\"" '[]' '{}' -1`].join(" ")} >/dev/null 2>&1
|
|
55
|
-
fi
|
|
56
|
-
}`}function Se(e){let n=[e.node,...e.execArgv,e.forge].map(a).join(" "),t=e.files.map(a).join(` \\
|
|
57
|
-
`),i="";if(e.thunar!==void 0){let r=a(e.thunar.file),o=a(`${e.thunar.file}.forge-tmp`),s=a(e.thunar.seed),m=['/<action>/ { held = ""; holding = 1 }',`holding { held = held $0 "\\n"; if (/<\\/action>/) { holding = 0; if (held !~ /<unique-id>${e.marker}-/) printf "%s", held }; next }`,"{ print }"].join(`
|
|
58
|
-
`);i=` if [ -f ${r} ] && grep -qF '<unique-id>${e.marker}-' ${r}; then
|
|
59
|
-
awk ${a(m)} ${r} > ${o} && mv -f ${o} ${r}
|
|
60
|
-
if [ -f ${s} ] && cmp -s ${s} ${r}; then rm -f ${r}; fi
|
|
61
|
-
fi
|
|
62
|
-
`}return`#!/bin/sh
|
|
63
|
-
# Forge's right-click menu. Rewritten by Forge whenever it sets the menu up.
|
|
64
|
-
${Ve()}
|
|
65
|
-
if [ ! -f ${a(e.forge)} ]; then
|
|
66
|
-
# Forge is gone: take its menu with it, and say so once.
|
|
67
|
-
for f in ${t}; do
|
|
68
|
-
if [ -f "$f" ] && grep -qF ${a(e.marker)} "$f"; then rm -f "$f"; fi
|
|
69
|
-
done
|
|
70
|
-
${i}${e.folders.map(r=>` rmdir ${a(r)} 2>/dev/null
|
|
71
|
-
`).join("")} rm -rf ${a(e.menuDir)}
|
|
72
|
-
say ${a(U)} ${a(j)}
|
|
73
|
-
exit 0
|
|
74
|
-
fi
|
|
75
|
-
if [ ! -x ${a(e.node)} ]; then
|
|
76
|
-
say ${a(we)} ${a($e)}
|
|
77
|
-
exit 1
|
|
78
|
-
fi
|
|
79
|
-
${e.xdgConfigHome===void 0?"":`export XDG_CONFIG_HOME=${a(e.xdgConfigHome)}
|
|
80
|
-
`}exec ${n} menu run "$@"
|
|
81
|
-
`}var b="HKCU\\Software\\Classes",Me=`${b}\\SystemFileAssociations\\image\\shell\\Forge`,ke=`${b}\\Directory\\shell\\Forge`,G=`${b}\\SystemFileAssociations\\.pdf\\shell\\ForgeOpen`,De=`${b}\\AppUserModelId\\${le}`,J=()=>[Me,ke,G,De],K=e=>`${e.paint}.ico`;function Ee(e){let n=o=>`conhost.exe --headless "${e.node}" "${e.menuDir}\\run.mjs" ${o.action}${o.preset===void 0?"":` ${o.preset}`} "%1"`,t=o=>`${e.menuDir}\\${K(o)}`,i=(o,s)=>{let m=e.items.filter(u=>u.kinds.includes(s));return m.length===0?[]:[{key:o,values:{MUIVerb:"Forge",Icon:t({paint:"forge"}),SubCommands:""}},...m.flatMap((u,g)=>{let w=u.preset===void 0?u.action:`preset-${u.preset}`,f=`${o}\\shell\\${g+1}${w}`;return[{key:f,values:{MUIVerb:u.label,Icon:t(u)}},{key:`${f}\\command`,values:{"":n(u)}}]})]},r=e.items.find(o=>o.kinds.includes("pdf"));return[...i(Me,"image"),...i(ke,"folder"),...r?[{key:G,values:{MUIVerb:r.label,Icon:t(r)}},{key:`${G}\\command`,values:{"":n(r)}}]:[],{key:De,values:{DisplayName:"Forge",IconUri:`${e.menuDir}\\forge.png`}}]}var T=e=>`'${pe(e)}'`,_=e=>T(`Registry::${e.replace(/^HKCU\\/,"HKEY_CURRENT_USER\\")}`);function V(e){return["$ErrorActionPreference = 'Stop'",...J().map(t=>`Remove-Item -Path ${_(t)} -Recurse -Force -ErrorAction SilentlyContinue`),...e.flatMap(({key:t,values:i})=>[`New-Item -Path ${_(t)} -Force | Out-Null`,...Object.entries(i).map(([r,o])=>`Set-ItemProperty -LiteralPath ${_(t)} -Name ${T(r===""?"(default)":r)} -Value ${T(o)}`)])].join(`
|
|
82
|
-
`)}var vn=(e,n)=>e.version===n.version&&e.forge===n.forge&&e.node===n.node&&e.execArgv.join("\0")===n.execArgv.join("\0")&&e.xdgConfigHome===n.xdgConfigHome&&(e.presets??[]).join("\0")===(n.presets??[]).join("\0"),Fe="/System/Library/CoreServices/pbs",Pe=e=>c(e.menuDir,"state.json"),S=e=>c(e.home,"Library","Services"),q=e=>h({sharpen:!0}).map(n=>c(S(e),`${n.label}.workflow`)),W=()=>h({sharpen:!0}).map(k);function Ne(e){let n;try{n=be(S(e)).filter(t=>t.endsWith(".workflow"))}catch{return[]}return n.flatMap(t=>{let i=c(S(e),t);try{let r=N(c(i,"Contents","Info.plist"),"utf8"),o=/<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(r)?.[1],s=/<key>CFBundleName<\/key>\s*<string>([^<]*)<\/string>/.exec(r)?.[1];return!o?.startsWith(re)||s===void 0?[]:[{path:i,key:`${o} - ${(u=>u.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"))(s)} - runWorkflowAsService`}]}catch{return[]}})}function Xe(e){try{return JSON.parse(N(Pe(e),"utf8"))}catch{return}}var Sn=e=>Xe(e)!==void 0,d=(e,n)=>{Z(P(e),{recursive:!0}),We(e,n)};async function Mn(e){if(!Qe(e.platform))return;let n=h({sharpen:e.sharpen,presets:e.presets??[]});if(Z(e.menuDir,{recursive:!0}),e.platform==="linux")await nn(e,n);else if(e.platform==="darwin"){let i=c(e.menuDir,"run"),r=n.filter(f=>f.preset!==void 0),o=r.map(f=>c(S(e),O(f,i).name));d(i,xe({...e,bundles:[...q(e),...o],services:[...W(),...r.map(k)]})),Q(i,493);let s=Ne(e);for(let f of[...q(e),...s.map(C=>C.path)])p(f,{recursive:!0,force:!0});let m=new Map,{default:u}=await import("sharp");for(let f of n){m.has(f.paint)||m.set(f.paint,await u(await v(f.paint,64)).tiff().toBuffer());let{name:C,files:Re}=O(f,i),ne=c(S(e),C);for(let[Be,Ue]of Object.entries(Re))d(c(ne,Be),Ue);d(c(ne,"Contents","Resources",`${te}.tiff`),m.get(f.paint))}let g=n.map(k),w=new Set([...W(),...s.map(f=>f.key)]);await e.run(...$({on:g,off:[...w].filter(f=>!g.includes(f))})),await e.run(Fe,["-update"])}else{d(c(e.menuDir,"run.mjs"),ve({...e,keys:J()}));for(let i of Ce){let r=await Promise.all([16,24,32,48,256].map(async o=>({size:o,png:await v(i,o)})));d(c(e.menuDir,K({paint:i})),ye(r))}d(c(e.menuDir,"forge.png"),await v("forge",256)),await e.run("powershell.exe",Le(V(Ee({...e,items:n}))))}let t={version:e.version,forge:e.forge,node:e.node,execArgv:e.execArgv,...e.xdgConfigHome===void 0?{}:{xdgConfigHome:e.xdgConfigHome},...e.presets&&e.presets.length>0?{presets:[...e.presets]}:{}};d(Pe(e),JSON.stringify(t))}var Qe=e=>e==="darwin"||e==="win32"||e==="linux",Ce=["forge","convert","compress","edit","pdf"],Oe=e=>ie({home:e.home,...e.xdgDataHome===void 0?{}:{xdgDataHome:e.xdgDataHome},...e.xdgConfigHome===void 0?{}:{xdgConfigHome:e.xdgConfigHome},...e.xdgConfigDirs===void 0?{}:{xdgConfigDirs:e.xdgConfigDirs}});function X(e){let n=h({sharpen:!0}),t=n.map(r=>r.action),i=(r,o)=>{try{return be(r).filter(o).map(s=>c(r,s))}catch{return[]}};return[...new Set([...n.map(r=>c(l(e),A(r))),...i(l(e),()=>!0),...n.map(r=>c(x(e),H(r,t))),...i(x(e),r=>r.startsWith("forge-")&&r.endsWith(".nemo_action")),...R.map(r=>c(E(e),L(r)))])]}var y=e=>{try{return N(e,"utf8")}catch{return}};function Ae(e){for(let n of e)y(n)?.includes(D)&&p(n,{force:!0})}var He=e=>c(e.menuDir,"made.json"),z=e=>{try{return JSON.parse(N(He(e),"utf8"))}catch{return[]}};function F(e,n){let t=[];for(let i=n;!Ie(i)&&P(i)!==i;i=P(i))t.push(i);t.length!==0&&(Z(n,{recursive:!0}),d(He(e),JSON.stringify([...new Set([...z(e),...t])])))}function Ze(e){for(let n of[...e].sort((t,i)=>i.length-t.length))try{qe(n)}catch{}}var ee=e=>c(e.menuDir,"thunar-seed.xml");async function ze(e,n,t,i){let r=I(n),o=y(r);if(o===void 0){if(!ge(n,e.path,Ie))return;o=ue(n).map(y).find(m=>m!==void 0&&B(m,"")!==void 0)??fe,d(ee(e),o),F(e,P(r))}let s=B(o,me(t,{launcher:i,menuDir:e.menuDir}));s!==void 0&&s!==y(r)&&await M(r,Buffer.from(s))}async function en(e,n){let t=I(n),i=y(t);if(i===void 0||!i.includes(`<unique-id>${D}-`))return;let r=de(i);r===y(ee(e))?p(t,{force:!0}):await M(t,Buffer.from(r))}async function Y(e,n,t=!1){await M(e,Buffer.from(n)),t&&Q(e,493)}async function nn(e,n){let t=Oe(e),i=c(e.menuDir,"run");for(let o of Ce)d(c(e.menuDir,oe({paint:o})),await v(o,128));Ae(X(t));let r=h({sharpen:!0}).map(o=>o.action);F(e,l(t));for(let o of n)await Y(c(l(t),A(o)),se(o,i),!0);F(e,x(t));for(let o of n)await Y(c(x(t),H(o,r)),ae(o,i));F(e,E(t));for(let o of R){let s=ce(o,n,{launcher:i,menuDir:e.menuDir});s!==void 0&&await Y(c(E(t),L(o)),s,!0)}await ze(e,t,n,i),d(i,Se({...e,files:X(t),folders:[...new Set([l(t),...z(e)])].sort((o,s)=>s.length-o.length),marker:D,thunar:{file:I(t),seed:ee(e)}})),Q(i,493)}async function tn(e){let n=Oe(e);Ae(X(n)),await en(e,n),Ze([l(n),...z(e)]),p(e.menuDir,{recursive:!0,force:!0})}async function kn(e){if(e.platform==="linux")await tn(e);else if(e.platform==="darwin"){let n=Ne(e);for(let i of[...q(e),...n.map(r=>r.path)])p(i,{recursive:!0,force:!0});p(e.menuDir,{recursive:!0,force:!0});let t=new Set([...W(),...n.map(i=>i.key)]);await e.run(...$({on:[],off:[...t]})),await e.run(Fe,["-update"])}else e.platform==="win32"&&(p(e.menuDir,{recursive:!0,force:!0}),await e.run("powershell.exe",Le(V([]))))}var Le=e=>["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",e],Dn=(e,n)=>new Promise((t,i)=>{Ye(e,n,{timeout:6e4,windowsHide:!0},r=>r?i(r):t())});export{vn as a,Xe as b,Sn as c,Mn as d,Qe as e,kn as f,Dn as g};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a,b,c,d}from"./chunk-N3X3H4IZ.js";import"./chunk-ZOQA3JAR.js";import"./chunk-TYWGB767.js";import"./chunk-ITJZ7ODJ.js";import"./chunk-EURVTBPH.js";import"./chunk-3GHHQNR6.js";import"./chunk-Q6KQWJ4J.js";import"./chunk-6RMRWBMB.js";import"./chunk-IKZTH2RL.js";import"./chunk-ZYIW4MAG.js";import"./chunk-IJRLRAC5.js";import"./chunk-7VR6LODN.js";import"./chunk-5IZBFF6Y.js";import"./chunk-57M4J2BR.js";import"./chunk-63XCSYHM.js";import"./chunk-AFEYLHDD.js";import"./chunk-O7DK3GJT.js";import"./chunk-EPDF4NQI.js";import"./chunk-EEQSUBBL.js";import"./chunk-E2BYNETT.js";import"./chunk-IE6NFN3N.js";import"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-TFOEI5VF.js";import"./chunk-J6AZTW62.js";import"./chunk-BIBDLXCG.js";import"./chunk-7KYO62XK.js";import"./chunk-CVNYUROW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-VLVNA4T3.js";import"./chunk-H3DIRJFE.js";import"./chunk-KXKQDFHX.js";import"./chunk-TMUK2DD3.js";export{b as clipLines,a as runClip,d as runClipCommand,c as runUndo};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a as s}from"./chunk-WE6KP4FR.js";import{E as o}from"./chunk-CVNYUROW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-VLVNA4T3.js";import"./chunk-H3DIRJFE.js";import"./chunk-TMUK2DD3.js";var c=["open","convert","compress","sharpen","open-pdf","preset"];function u(r){let[e,n,...i]=r;if(e==="install"||e==="remove")return{kind:e};if(e==="run"||e==="open"){if(!c.includes(n))throw o(`No menu action called "${n??""}".`);if(n==="preset"){let[t,...a]=i;if(e!=="run"||t===void 0||!s(t))throw o(`No preset called "${t??""}".`);return{kind:"run",action:n,preset:t,paths:a}}return{kind:e,action:n,paths:i}}throw o(`No menu command called "${e??""}".`)}function m(r,e){switch(r){case"convert":return{paths:e,mode:"convert",advance:!0};case"compress":return{paths:e,mode:"compress",advance:!0};case"open-pdf":return{paths:e,mode:"pdf",advance:!1};default:return{paths:[],mode:"convert",advance:!1}}}export{m as openedFor,u as parseMenuArgs};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as a,d as b,e as c,f as d}from"./chunk-ITJZ7ODJ.js";import"./chunk-EURVTBPH.js";import"./chunk-3GHHQNR6.js";import"./chunk-Q6KQWJ4J.js";import"./chunk-6RMRWBMB.js";import"./chunk-IKZTH2RL.js";import"./chunk-ZYIW4MAG.js";import"./chunk-IJRLRAC5.js";import"./chunk-7VR6LODN.js";import"./chunk-5IZBFF6Y.js";import"./chunk-57M4J2BR.js";import"./chunk-63XCSYHM.js";import"./chunk-AFEYLHDD.js";import"./chunk-O7DK3GJT.js";import"./chunk-EPDF4NQI.js";import"./chunk-EEQSUBBL.js";import"./chunk-E2BYNETT.js";import"./chunk-IE6NFN3N.js";import"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-TFOEI5VF.js";import"./chunk-J6AZTW62.js";import"./chunk-BIBDLXCG.js";import"./chunk-7KYO62XK.js";import"./chunk-CVNYUROW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-VLVNA4T3.js";import"./chunk-H3DIRJFE.js";import"./chunk-KXKQDFHX.js";import"./chunk-TMUK2DD3.js";export{d as execute,a as exitCodeFor,c as renderRun,b as runIntent};
|