forge-terminal 0.3.3 → 0.3.4

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.
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as J,d as oe,e as E,g as B,h as se,i as ne,j as ae,k as ue,q as ie,r as pe,s as ce,u as de,v as fe,x as I,z as y}from"./chunk-WFD6OWQY.js";import{a as $,c as U,d as Y,e as F,f as K,k as Q}from"./chunk-LW2QEXDT.js";import{c as X,d as Z,e as _,f as ee,g as te,h as re}from"./chunk-3GVFOZ7M.js";import{e as V}from"./chunk-GGBNT4WI.js";import{m as H,o as L}from"./chunk-GNLE6JXL.js";import{a as g}from"./chunk-G4DU5ADF.js";import{I as D,J as q,M as z,b as P,c as w,d as R,fa as G,g as x,s as A,u as k,w as W,z as C}from"./chunk-MMRDELHW.js";import{a as h,b as M}from"./chunk-J7FLFHQJ.js";import{readFile as Se}from"node:fs/promises";import{dirname as Re,resolve as je}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as ke}from"node:path";function $e(e,r=new Set){let t={path:ke(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===B.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-QN6QAGCU.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var S=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=P(Fe(e),S(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=M(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(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${ge(s[0],r)}`,` ${s.map(u=>w(u)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let u of t.warnings)a.push("",`\u26A0 ${u.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],S(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,S(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 we(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>w(i)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)a.push("",`\u26A0 ${i.message}`);return a}function j(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),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 ve(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,S(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Be(e){return new Promise(r=>{let t=Pe({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 xe(e){if(e.stdin)return Be(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({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 N(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Oe(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 D("--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:pe(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 Ce(e,r){let t;return()=>r?(t??=xe({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await V(await Se(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let n;try{n=B.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(u){if(!x(u))throw u;return{failure:{path:e.path,error:u}}}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 O(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}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 Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.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=fe(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,Oe(e,r.sources))}catch(a){if(!x(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 Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:A(u)});continue}let i=e.output!==void 0&&!oe(e.output)?je(e.output):void 0,c=e.output===void 0||i!==void 0?Re(u.path):Re(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}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:O(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(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-H2WS22BA.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-O3V24DK7.js"),d=f("boost"),v=d&&l(d)?.version,T=L(e.scale,n.version,v);if(T)return b(t,[{path:"",error:T}])}let a=await y(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?ne:ae,i=[],c=[];for(let l of a.sources){if(!u.appliesTo([l])){c.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 f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}i.push(...u.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:a.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:O(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.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=ue(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}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:O(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function We(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,u=[],i=[],c=Ce(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let v=await Je(d,e,c,t.roots.get(d.path));"failure"in v?i.push(v.failure):u.push(v.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...i,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function De(e,r={}){try{return e.kind==="pageop"?await Ne(e):e.kind==="extension-op"?await Me(e,r):e.kind==="edit"?await Ae(e,r):e.kind==="compress"?await Te(e,r):await We(e,r)}catch(t){if(!x(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:j(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:j(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-TXQUYFA6.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function St(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-6VNVMAYO.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-UGXZIFRI.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=N(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...ve(u)]),stderr:j(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-D7L5VGQC.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:qe(await De(e,r),{json:t,debug:o})}catch(s){if(!x(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,N as b,De as c,qe as d,St as e};
3
+ import{c as J,d as oe,e as E,g as B,h as se,i as ne,j as ae,k as ue,q as ie,r as pe,s as ce,u as de,v as fe,x as I,z as y}from"./chunk-WFD6OWQY.js";import{a as $,c as U,d as Y,e as F,f as K,k as Q}from"./chunk-LW2QEXDT.js";import{c as X,d as Z,e as _,f as ee,g as te,h as re}from"./chunk-3GVFOZ7M.js";import{e as V}from"./chunk-GGBNT4WI.js";import{m as H,o as L}from"./chunk-GNLE6JXL.js";import{a as g}from"./chunk-7TUTDL4W.js";import{I as D,J as q,M as z,b as P,c as w,d as R,fa as G,g as x,s as A,u as k,w as W,z as C}from"./chunk-MMRDELHW.js";import{a as h,b as M}from"./chunk-J7FLFHQJ.js";import{readFile as Se}from"node:fs/promises";import{dirname as Re,resolve as je}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as ke}from"node:path";function $e(e,r=new Set){let t={path:ke(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===B.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-QN6QAGCU.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var S=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=P(Fe(e),S(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=M(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(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${ge(s[0],r)}`,` ${s.map(u=>w(u)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let u of t.warnings)a.push("",`\u26A0 ${u.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],S(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,S(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 we(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>w(i)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)a.push("",`\u26A0 ${i.message}`);return a}function j(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),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 ve(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,S(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Be(e){return new Promise(r=>{let t=Pe({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 xe(e){if(e.stdin)return Be(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({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 N(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Oe(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 D("--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:pe(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 Ce(e,r){let t;return()=>r?(t??=xe({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await V(await Se(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let n;try{n=B.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(u){if(!x(u))throw u;return{failure:{path:e.path,error:u}}}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 O(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}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 Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.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=fe(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,Oe(e,r.sources))}catch(a){if(!x(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 Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:A(u)});continue}let i=e.output!==void 0&&!oe(e.output)?je(e.output):void 0,c=e.output===void 0||i!==void 0?Re(u.path):Re(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}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:O(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(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-H2WS22BA.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-O3V24DK7.js"),d=f("boost"),v=d&&l(d)?.version,T=L(e.scale,n.version,v);if(T)return b(t,[{path:"",error:T}])}let a=await y(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?ne:ae,i=[],c=[];for(let l of a.sources){if(!u.appliesTo([l])){c.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 f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}i.push(...u.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:a.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:O(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.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=ue(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}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:O(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function We(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,u=[],i=[],c=Ce(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let v=await Je(d,e,c,t.roots.get(d.path));"failure"in v?i.push(v.failure):u.push(v.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...i,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function De(e,r={}){try{return e.kind==="pageop"?await Ne(e):e.kind==="extension-op"?await Me(e,r):e.kind==="edit"?await Ae(e,r):e.kind==="compress"?await Te(e,r):await We(e,r)}catch(t){if(!x(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:j(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:j(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-TXQUYFA6.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function St(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-6VNVMAYO.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-UGXZIFRI.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=N(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...ve(u)]),stderr:j(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-Y7XF4ZUS.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:qe(await De(e,r),{json:t,debug:o})}catch(s){if(!x(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,N as b,De as c,qe as d,St as e};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{g as S,h as k,l as C}from"./chunk-K2ABBIR4.js";import{i as $,k as u,l as w}from"./chunk-MBTGANIR.js";import{c as I,d as y,f as O}from"./chunk-PBIS2ONZ.js";import{b as m,c as d,h as f,i as p}from"./chunk-QVACE4IE.js";import{a as h,b as g}from"./chunk-3GVFOZ7M.js";import"./chunk-GGBNT4WI.js";import"./chunk-GNLE6JXL.js";import"./chunk-32VJ2RDH.js";import{a as l}from"./chunk-G4DU5ADF.js";import{c as b,q as x}from"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-TMUK2DD3.js";import{resolve as R}from"node:path";var P=({r:t,g:n,b:o},s)=>s?`\x1B[38;2;${t};${n};${o}m\u2588\u2588\x1B[39m `:"";function N(t,n){let o=d(n),s,e=Number.POSITIVE_INFINITY;for(let r of t){let a=(r.centre.L-o.L)**2+(r.centre.a-o.a)**2+(r.centre.b-o.b)**2;a<e&&(e=a,s=r)}return s}async function D(t,n){let{pixels:o}=await C(t.input),s=I(o);if(s.length===0)throw x(t.input);let e=t.inside?N(s,t.inside):void 0,r=e?y(o,e):s;if(t.svg)return{exitCode:0,stdout:[S(b(t.input),r,"light",e?.hex)],stderr:[]};if(n.json){let i=h(l,{source:R(t.input),...e?{inside:e.hex}:{},colours:r.map(c=>({hex:c.hex,rgb:f(c.rgb),oklch:p(c.rgb),share:c.share}))});return{exitCode:0,stdout:[JSON.stringify(i)],stderr:[]}}let a=O(r.map(i=>i.share));return{exitCode:0,stdout:r.map((i,c)=>`${P(i.rgb,n.colour)}${i.hex} ${String(a[c]).padStart(3)}%`),stderr:[]}}async function H(t,n){let o=$(t.colour);if(t.svg)return{exitCode:0,stdout:[k(t.colour,o)],stderr:[]};let s=o.map(e=>({...e,...w(e.rgb)}));if(n.json){let e=g(l,{reference:m(t.colour),steps:s.map(r=>({step:r.step,hex:r.hex,oklch:p(r.rgb),white:r.white,black:r.black}))});return{exitCode:0,stdout:[JSON.stringify(e)],stderr:[]}}return{exitCode:0,stdout:s.map(e=>`${String(e.step).padStart(4)} ${P(e.rgb,n.colour)}${e.hex} white ${e.white.toFixed(1)} ${u(e.white)} \xB7 black ${e.black.toFixed(1)} ${u(e.black)}`),stderr:[]}}export{D as runPalette,H as runScale};
3
+ import{g as S,h as k,l as C}from"./chunk-K2ABBIR4.js";import{i as $,k as u,l as w}from"./chunk-MBTGANIR.js";import{c as I,d as y,f as O}from"./chunk-PBIS2ONZ.js";import{b as m,c as d,h as f,i as p}from"./chunk-QVACE4IE.js";import{a as h,b as g}from"./chunk-3GVFOZ7M.js";import"./chunk-GGBNT4WI.js";import"./chunk-GNLE6JXL.js";import"./chunk-32VJ2RDH.js";import{a as l}from"./chunk-7TUTDL4W.js";import{c as b,q as x}from"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-TMUK2DD3.js";import{resolve as R}from"node:path";var P=({r:t,g:n,b:o},s)=>s?`\x1B[38;2;${t};${n};${o}m\u2588\u2588\x1B[39m `:"";function N(t,n){let o=d(n),s,e=Number.POSITIVE_INFINITY;for(let r of t){let a=(r.centre.L-o.L)**2+(r.centre.a-o.a)**2+(r.centre.b-o.b)**2;a<e&&(e=a,s=r)}return s}async function D(t,n){let{pixels:o}=await C(t.input),s=I(o);if(s.length===0)throw x(t.input);let e=t.inside?N(s,t.inside):void 0,r=e?y(o,e):s;if(t.svg)return{exitCode:0,stdout:[S(b(t.input),r,"light",e?.hex)],stderr:[]};if(n.json){let i=h(l,{source:R(t.input),...e?{inside:e.hex}:{},colours:r.map(c=>({hex:c.hex,rgb:f(c.rgb),oklch:p(c.rgb),share:c.share}))});return{exitCode:0,stdout:[JSON.stringify(i)],stderr:[]}}let a=O(r.map(i=>i.share));return{exitCode:0,stdout:r.map((i,c)=>`${P(i.rgb,n.colour)}${i.hex} ${String(a[c]).padStart(3)}%`),stderr:[]}}async function H(t,n){let o=$(t.colour);if(t.svg)return{exitCode:0,stdout:[k(t.colour,o)],stderr:[]};let s=o.map(e=>({...e,...w(e.rgb)}));if(n.json){let e=g(l,{reference:m(t.colour),steps:s.map(r=>({step:r.step,hex:r.hex,oklch:p(r.rgb),white:r.white,black:r.black}))});return{exitCode:0,stdout:[JSON.stringify(e)],stderr:[]}}return{exitCode:0,stdout:s.map(e=>`${String(e.step).padStart(4)} ${P(e.rgb,n.colour)}${e.hex} white ${e.white.toFixed(1)} ${u(e.white)} \xB7 black ${e.black.toFixed(1)} ${u(e.black)}`),stderr:[]}}export{D as runPalette,H as runScale};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as a,c as b,d as c,e as d}from"./chunk-DG4IXNWJ.js";import"./chunk-WFD6OWQY.js";import"./chunk-BZXDNDPG.js";import"./chunk-LW2QEXDT.js";import"./chunk-3GVFOZ7M.js";import"./chunk-GGBNT4WI.js";import"./chunk-GNLE6JXL.js";import"./chunk-32VJ2RDH.js";import"./chunk-G4DU5ADF.js";import"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-H2IUSPAK.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";export{d as execute,a as exitCodeFor,c as renderRun,b as runIntent};
3
+ import{b as a,c as b,d as c,e as d}from"./chunk-ONPOKE45.js";import"./chunk-WFD6OWQY.js";import"./chunk-BZXDNDPG.js";import"./chunk-LW2QEXDT.js";import"./chunk-3GVFOZ7M.js";import"./chunk-GGBNT4WI.js";import"./chunk-GNLE6JXL.js";import"./chunk-32VJ2RDH.js";import"./chunk-7TUTDL4W.js";import"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-H2IUSPAK.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";export{d as execute,a as exitCodeFor,c as renderRun,b as runIntent};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{Aa as b,Ba as c,Ca as d,Da as e,za as a}from"./chunk-KSRGJD2E.js";import"./chunk-MBTGANIR.js";import"./chunk-PBIS2ONZ.js";import"./chunk-BZXDNDPG.js";import"./chunk-IBPGC4N2.js";import"./chunk-QVACE4IE.js";import"./chunk-G4DU5ADF.js";import"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-YILLB45O.js";import"./chunk-TMUK2DD3.js";export{e as ExtensionsFlow,c as byteCount,b as extensionCredits,d as extensionsChip,a as realManager};
3
+ import{Aa as b,Ba as c,Ca as d,Da as e,za as a}from"./chunk-FMJBEZKO.js";import"./chunk-MBTGANIR.js";import"./chunk-PBIS2ONZ.js";import"./chunk-BZXDNDPG.js";import"./chunk-IBPGC4N2.js";import"./chunk-QVACE4IE.js";import"./chunk-7TUTDL4W.js";import"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-YILLB45O.js";import"./chunk-TMUK2DD3.js";export{e as ExtensionsFlow,c as byteCount,b as extensionCredits,d as extensionsChip,a as realManager};