forge-terminal 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +14 -8
  2. package/dist/chunks/{about-credits-5UQU5WHE.js → about-credits-FZ35HUFP.js} +1 -1
  3. package/dist/chunks/{args-QKAIL3E4.js → args-FSQFXDIX.js} +1 -1
  4. package/dist/chunks/{available-M6Z62OWE.js → available-TNMISSBA.js} +1 -1
  5. package/dist/chunks/{boot-MGR26CBU.js → boot-PCZBPNFR.js} +1 -1
  6. package/dist/chunks/{catalog-VPSTQTFD.js → catalog-FMHWWMUX.js} +1 -1
  7. package/dist/chunks/{chunk-ZZZAPVKM.js → chunk-2CX33C6H.js} +1 -1
  8. package/dist/chunks/{chunk-SNDFMJIX.js → chunk-2J2PTA5O.js} +1 -1
  9. package/dist/chunks/{chunk-NXJGO66P.js → chunk-2MLASXG5.js} +1 -1
  10. package/dist/chunks/{chunk-XBOMWF34.js → chunk-3KWAO2N2.js} +1 -1
  11. package/dist/chunks/{chunk-TL5MACSF.js → chunk-5TEAR5XH.js} +1 -1
  12. package/dist/chunks/{chunk-W6SY5PPG.js → chunk-63BBFKT2.js} +2 -2
  13. package/dist/chunks/{chunk-OK7XOZFO.js → chunk-655UG277.js} +1 -1
  14. package/dist/chunks/{chunk-I6754KTB.js → chunk-72TNSFL5.js} +2 -2
  15. package/dist/chunks/{chunk-NDECMPOM.js → chunk-AYB5AJ4E.js} +1 -1
  16. package/dist/chunks/{chunk-PPR7B5AR.js → chunk-BD3OLIVT.js} +1 -1
  17. package/dist/chunks/{chunk-GSK2A3TN.js → chunk-C32KGH4S.js} +1 -1
  18. package/dist/chunks/{chunk-RMD7F3QX.js → chunk-GLAD7GP2.js} +1 -1
  19. package/dist/chunks/{chunk-Y7LOIHFU.js → chunk-HCLEHCAR.js} +1 -1
  20. package/dist/chunks/chunk-I25E2XDH.js +3 -0
  21. package/dist/chunks/{chunk-WC6SJN5Y.js → chunk-JOIHR724.js} +1 -1
  22. package/dist/chunks/{chunk-37P6QZ5Q.js → chunk-LBDSFSYP.js} +1 -1
  23. package/dist/chunks/{chunk-PE5LAYGF.js → chunk-MF3KKEFB.js} +1 -1
  24. package/dist/chunks/{chunk-3GJ7GV3V.js → chunk-MTDCDKPU.js} +1 -1
  25. package/dist/chunks/{chunk-CKZBBDAW.js → chunk-OY4EGSPE.js} +1 -1
  26. package/dist/chunks/{chunk-K7KKCR7V.js → chunk-QXNB5DQ2.js} +1 -1
  27. package/dist/chunks/{chunk-P4RAYEM7.js → chunk-S2M4XESA.js} +1 -1
  28. package/dist/chunks/{chunk-XRI5XKEB.js → chunk-UXRQ4UBQ.js} +2 -2
  29. package/dist/chunks/{chunk-V3I6DSF4.js → chunk-WZWK3PEZ.js} +1 -1
  30. package/dist/chunks/{chunk-HOZ6XGQQ.js → chunk-X26WUHWB.js} +2 -2
  31. package/dist/chunks/{chunk-LVYQVJOF.js → chunk-XURW53YK.js} +1 -1
  32. package/dist/chunks/{chunk-F34DPQFQ.js → chunk-YNZIN42P.js} +1 -1
  33. package/dist/chunks/clip-command-NZNC46H2.js +3 -0
  34. package/dist/chunks/{colour-APVBMEJQ.js → colour-GSDOHCFK.js} +1 -1
  35. package/dist/chunks/{decoded-UNCEUPNW.js → decoded-NBZ335RZ.js} +1 -1
  36. package/dist/chunks/{entry-TSLQHDP7.js → entry-2XJD7UCY.js} +2 -2
  37. package/dist/chunks/execute-FYEXZ7EY.js +3 -0
  38. package/dist/chunks/{extensions-XI5R74TS.js → extensions-V5O4NIHI.js} +1 -1
  39. package/dist/chunks/{extensions-command-25JOL47P.js → extensions-command-MGPRISPH.js} +1 -1
  40. package/dist/chunks/{ffmpeg-3CJ6C37W.js → ffmpeg-2UZXAB3C.js} +1 -1
  41. package/dist/chunks/{image-QSTDWHJ4.js → image-3CMUB2P4.js} +1 -1
  42. package/dist/chunks/{launch-LFFWVTFE.js → launch-GUHDBMSJ.js} +5 -5
  43. package/dist/chunks/{lock-PTQUMNYX.js → lock-UQJ66TZ3.js} +1 -1
  44. package/dist/chunks/{manager-CQ6NNQY4.js → manager-UKTMRXKE.js} +2 -2
  45. package/dist/chunks/{needed-MYXIUZI4.js → needed-YEXRZMZX.js} +1 -1
  46. package/dist/chunks/{own-WNA6BFYL.js → own-WOK6H277.js} +1 -1
  47. package/dist/chunks/{paths-EOYKOUBC.js → paths-6OENILJ4.js} +1 -1
  48. package/dist/chunks/{pdfium-WFGSET5S.js → pdfium-LYHOU6WV.js} +1 -1
  49. package/dist/chunks/{preset-command-HMOFTZSG.js → preset-command-6A2C6VPQ.js} +1 -1
  50. package/dist/chunks/registry-2YU7NW4P.js +3 -0
  51. package/dist/chunks/{run-HGZVOXRW.js → run-U2CU6VGE.js} +1 -1
  52. package/dist/chunks/{server-KKF3XBQG.js → server-QNWPC2CC.js} +16 -16
  53. package/dist/chunks/{theme-NAWQ77WF.js → theme-EHFY7DT6.js} +1 -1
  54. package/dist/chunks/{transcribe-Q5NLWSSR.js → transcribe-SCL3LFZU.js} +1 -1
  55. package/dist/chunks/{transcribe-command-2L7F7MCG.js → transcribe-command-BX2VVUI3.js} +1 -1
  56. package/dist/chunks/{update-note-FRMHMUMD.js → update-note-GYJWUDFS.js} +1 -1
  57. package/dist/chunks/{watch-command-XCCMIQIM.js → watch-command-ZLZAWTNJ.js} +1 -1
  58. package/dist/index.js +6 -6
  59. package/dist/third-party-licenses.txt +1 -1
  60. package/package.json +11 -35
  61. package/dist/chunks/chunk-HKINXTUW.js +0 -3
  62. package/dist/chunks/clip-command-R2NKW4TI.js +0 -3
  63. package/dist/chunks/execute-S5WN34PS.js +0 -3
  64. package/dist/chunks/registry-4IOXO6DT.js +0 -3
package/README.md CHANGED
@@ -50,7 +50,7 @@ That puts `forge` on your `PATH`, so it works from any directory. Verify:
50
50
 
51
51
  ```bash
52
52
  forge --version
53
- # 0.5.0
53
+ # 0.5.1
54
54
 
55
55
  forge photo.jpg --to webp
56
56
  ```
@@ -164,7 +164,8 @@ every OS):
164
164
  forge extensions add whisper # every OS (Linux x64 needs AVX2)
165
165
  winget install ffmpeg # Windows
166
166
  sudo apt install ffmpeg # Linux, or your distro's ffmpeg
167
- brew install ffmpeg # Mac
167
+ brew install ffmpeg # Intel Mac
168
+ forge extensions add video # Apple-silicon Mac: Forge's own ffmpeg (25 MB)
168
169
 
169
170
  forge transcribe talk.mp4
170
171
  forge transcribe "https://www.youtube.com/watch?v=..." --language en
@@ -462,9 +463,13 @@ zoom.
462
463
  Two image operations that need a model, so they are optional extensions rather
463
464
  than part of the install. On a Mac both need macOS 14 or later. Boost runs on
464
465
  the graphics card: CoreML on Apple silicon, DirectML on Windows (any DirectX 12
465
- graphics), WebGPU on Intel Macs (Metal) and on Linux x64 (Vulkan, so it needs a
466
- Vulkan driver for the card). Where that would leave the processor to do it and
467
- a photo would take over about three minutes, Boost stops and says so. Remove
466
+ graphics), WebGPU on Intel Macs (Metal). On Linux, x64 and arm64 alike, it runs
467
+ the same model through ncnn: on a Vulkan graphics card when there is a real one
468
+ (a software "graphics card" such as llvmpipe is turned away by its name, and a
469
+ card slower than the processor is passed over), otherwise on the processor,
470
+ which every Linux computer has. Where the processor is all there is and a photo
471
+ would take too long (over about three minutes on an Intel Mac, fifteen on
472
+ Linux), Boost stops and says so. Remove
468
473
  background uses Apple Vision on a Mac, and on Windows and Linux a small model
469
474
  (BiRefNet-lite, 54 MB, on the processor: about two seconds a photo and 2 GB of
470
475
  memory at its peak). Windows and Linux also have a `heic` extension, because macOS opens
@@ -472,11 +477,12 @@ iPhone photos itself and they need a decoder. Nothing downloads until you ask:
472
477
 
473
478
  ```bash
474
479
  forge extensions # list: installed or not, size, licence
475
- forge extensions add boost # about 15 MB on Apple silicon, 16 MB on an Intel Mac, 17 MB on Linux x64, 23 MB on Windows
480
+ forge extensions add boost # about 15 MB on Apple silicon, 16 MB on an Intel Mac, 7 to 8 MB on Linux, 23 MB on Windows
476
481
  forge extensions add remove-background # 32 KB on a Mac (Apple Vision); 46 to 52 MB on Windows and Linux
477
482
  forge extensions add heic # about 0.5 MB; Windows and Linux
478
483
  forge extensions add whisper # transcribe where Apple's recogniser is not (see above)
479
484
  forge extensions add yt-dlp # YouTube links for transcribe, every OS
485
+ forge extensions add video # Forge's own ffmpeg, 25 MB; Apple-silicon Macs
480
486
  forge extensions remove boost
481
487
  ```
482
488
 
@@ -1111,7 +1117,7 @@ photo.png · PNG · 122 KB · 2756×774
1111
1117
  With `--json`:
1112
1118
 
1113
1119
  ```json
1114
- {"forge":"0.5.0","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
1120
+ {"forge":"0.5.1","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
1115
1121
  ```
1116
1122
 
1117
1123
  `targets` and `actions` come from the engines' own capabilities, so they are
@@ -1137,7 +1143,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
1137
1143
 
1138
1144
  ```jsonc
1139
1145
  {
1140
- "forge": "0.5.0",
1146
+ "forge": "0.5.1",
1141
1147
  "ok": false,
1142
1148
  "results": [
1143
1149
  {
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
3
  import"./chunk-TMUK2DD3.js";import{readFile as x}from"node:fs/promises";import{dirname as m,join as u}from"node:path";import{fileURLToPath as C}from"node:url";var c=[{name:"sharp \xB7 libvips",licence:"Apache-2.0 \xB7 LGPL-3.0",does:"images",packages:["sharp"]},{name:"PDFium",licence:"BSD-3-Clause",does:"PDF pages",packages:[]},{name:"pdf-lib",licence:"MIT",does:"writing PDFs",packages:["pdf-lib"]},{name:"mammoth \xB7 docx",licence:"BSD-2-Clause \xB7 MIT",does:"Word documents",packages:["mammoth","docx"]},{name:"Ink \xB7 React",licence:"MIT",does:"this screen",packages:["ink","react"]}],g=[{name:"@hyzyla/pdfium",licence:"MIT"}],h=[{name:"Noto Sans",licence:"OFL-1.1"},{name:"xkcd colour survey",licence:"CC0-1.0"}];function l(n){let t=[];for(let e of n.split(`
4
- `)){let i=/^((?:@[^/\s]+\/)?[^@\s]+)@\S+ — (.+)$/.exec(e);i&&t.push({name:i[1],licence:i[2].replace(/^\((.*)\)$/,"$1")})}return t}var d=n=>n.name.replace(/^@/,"");function p({bundled:n,extensions:t}){let e=new Set(c.flatMap(s=>s.packages)),i=[...n.filter(s=>!e.has(s.name)),...g,...h].sort((s,r)=>d(s).localeCompare(d(r)));return[{title:"App",credits:c.map(({packages:s,...r})=>r)},...t.length>0?[{title:"Extensions",credits:t}]:[],{title:"Others",credits:i}]}var f="third-party-licenses.txt";function y(n){let t=[],e=m(n);for(let i=0;i<4;i++)t.push(u(e,f),u(e,"dist",f)),e=m(e);return t}async function k(n){for(let t of y(C(n))){let e=await x(t,"utf8").catch(()=>{});if(e!==void 0)return{path:t,text:e}}}async function F({from:n=import.meta.url,list:t=async()=>(await import("./manager-CQ6NNQY4.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-XI5R74TS.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{F as loadCredits};
4
+ `)){let i=/^((?:@[^/\s]+\/)?[^@\s]+)@\S+ — (.+)$/.exec(e);i&&t.push({name:i[1],licence:i[2].replace(/^\((.*)\)$/,"$1")})}return t}var d=n=>n.name.replace(/^@/,"");function p({bundled:n,extensions:t}){let e=new Set(c.flatMap(s=>s.packages)),i=[...n.filter(s=>!e.has(s.name)),...g,...h].sort((s,r)=>d(s).localeCompare(d(r)));return[{title:"App",credits:c.map(({packages:s,...r})=>r)},...t.length>0?[{title:"Extensions",credits:t}]:[],{title:"Others",credits:i}]}var f="third-party-licenses.txt";function y(n){let t=[],e=m(n);for(let i=0;i<4;i++)t.push(u(e,f),u(e,"dist",f)),e=m(e);return t}async function k(n){for(let t of y(C(n))){let e=await x(t,"utf8").catch(()=>{});if(e!==void 0)return{path:t,text:e}}}async function F({from:n=import.meta.url,list:t=async()=>(await import("./manager-UKTMRXKE.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-V5O4NIHI.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{F as loadCredits};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a,b,c,d,e,f}from"./chunk-F34DPQFQ.js";import"./chunk-U5TEGDGH.js";import"./chunk-QVACE4IE.js";import"./chunk-HZDYZ5RD.js";import"./chunk-JMBEZPYC.js";import"./chunk-Y7LOIHFU.js";import"./chunk-PPR7B5AR.js";import"./chunk-XBOMWF34.js";import"./chunk-V3I6DSF4.js";import"./chunk-EEQSUBBL.js";import"./chunk-K7KKCR7V.js";import"./chunk-LVYQVJOF.js";import"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-SNDFMJIX.js";import"./chunk-THDAQBQ3.js";import"./chunk-DZOBIUV6.js";import"./chunk-TL5MACSF.js";import"./chunk-WIPP5TWQ.js";import"./chunk-J7FLFHQJ.js";import"./chunk-H3DIRJFE.js";import"./chunk-KXKQDFHX.js";import"./chunk-TMUK2DD3.js";export{b as COMMANDS_HELP,a as EXIT_CODES_HELP,d as colourUsage,c as commandsHelp,f as parseArgs,e as wantsJson};
3
+ import{a,b,c,d,e,f}from"./chunk-YNZIN42P.js";import"./chunk-U5TEGDGH.js";import"./chunk-QVACE4IE.js";import"./chunk-HZDYZ5RD.js";import"./chunk-JMBEZPYC.js";import"./chunk-HCLEHCAR.js";import"./chunk-BD3OLIVT.js";import"./chunk-3KWAO2N2.js";import"./chunk-WZWK3PEZ.js";import"./chunk-EEQSUBBL.js";import"./chunk-QXNB5DQ2.js";import"./chunk-XURW53YK.js";import"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-2J2PTA5O.js";import"./chunk-THDAQBQ3.js";import"./chunk-DZOBIUV6.js";import"./chunk-5TEAR5XH.js";import"./chunk-WIPP5TWQ.js";import"./chunk-J7FLFHQJ.js";import"./chunk-H3DIRJFE.js";import"./chunk-KXKQDFHX.js";import"./chunk-TMUK2DD3.js";export{b as COMMANDS_HELP,a as EXIT_CODES_HELP,d as colourUsage,c as commandsHelp,f as parseArgs,e as wantsJson};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as t}from"./chunk-PE5LAYGF.js";import{a as i}from"./chunk-HKINXTUW.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
3
+ import{c as t}from"./chunk-MF3KKEFB.js";import{a as i}from"./chunk-I25E2XDH.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{r as a}from"./chunk-XBOMWF34.js";import{e as l}from"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-H3DIRJFE.js";import"./chunk-TMUK2DD3.js";var c={loadPreferences:l,loadShell:()=>import("./launch-LFFWVTFE.js")};async function f(e=c,n={}){let t=e.loadShell();t.catch(()=>{});let{prefs:o,warning:r}=await e.loadPreferences(),s=a(o.theme),{launchShell:i}=await t;await i({prefs:o,palette:s,...r===void 0?{}:{warning:r},...n})}export{f as bootShell};
3
+ import{r as a}from"./chunk-3KWAO2N2.js";import{e as l}from"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-H3DIRJFE.js";import"./chunk-TMUK2DD3.js";var c={loadPreferences:l,loadShell:()=>import("./launch-GUHDBMSJ.js")};async function f(e=c,n={}){let t=e.loadShell();t.catch(()=>{});let{prefs:o,warning:r}=await e.loadPreferences(),s=a(o.theme),{launchShell:i}=await t;await i({prefs:o,palette:s,...r===void 0?{}:{warning:r},...n})}export{f as bootShell};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a,b,c,d,e,f,g,h}from"./chunk-HKINXTUW.js";import"./chunk-TMUK2DD3.js";export{a as CATALOG,d as EXTENSION_PLATFORMS,f as assetFor,e as catalogEntry,b as machineName,h as offeredHere,g as offeredOn,c as osName};
3
+ import{a,b,c,d,e,f,g,h}from"./chunk-I25E2XDH.js";import"./chunk-TMUK2DD3.js";export{a as CATALOG,d as EXTENSION_PLATFORMS,f as assetFor,e as catalogEntry,b as machineName,h as offeredHere,g as offeredOn,c as osName};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as P}from"./chunk-GSK2A3TN.js";import{j as v}from"./chunk-V3I6DSF4.js";import{d as y,na as s}from"./chunk-WIPP5TWQ.js";import{mkdtemp as x,rm as F}from"node:fs/promises";import{tmpdir as z}from"node:os";import{join as h}from"node:path";var f={background:"#ffffff",keepMetadata:!1};function q(e,r,n){switch(e.kind){case"cut":return{op:"convert",sources:[r],outputs:[n],target:"png",options:{...f,...e.trim?{trim:!0}:{},...e.crop?{crop:{aspect:e.crop}}:{},...e.resize?{resize:e.resize}:{}}};case"cutout":return{op:"remove-background",sources:[r],outputs:[n],target:"png",options:f};case"boost":return{op:"boost",sources:[r],outputs:[n],scale:e.scale,target:"png",options:f};case"encode":return{op:"convert",sources:[r],outputs:[n],target:e.target,options:{...f,...e.background?{background:e.background}:{},...e.quality!==void 0?{quality:e.quality}:{},...e.compress?{compress:e.compress}:{},...e.trim?{trim:!0}:{},...e.crop?{crop:{aspect:e.crop}}:{},...e.resize?{resize:e.resize}:{}}}}}async function C(e,r,n,o){let E=o.probe??v,d=await x(h(z(),"forge-preset-")),I={force:o.force,...o.signal?{signal:o.signal}:{},...o.onEvent?{onEvent:o.onEvent}:{}};try{let i=e;for(let[l,t]of r.entries()){o.onPass?.(l);let u=l===r.length-1,m=u?n:h(d,`${l}.png`),a=await P([q(t,i,m)],{...I,...u?{}:{force:!0},...u&&t.kind==="encode"&&t.maxBytes?{targetBytes:t.maxBytes,...t.quality===void 0?{}:{maxQuality:t.quality}}:{}});if(a.cancelled)return{kind:"cancelled"};let g=a.refusals[0];if(g)return{kind:"refused",error:g.error};let p=a.unreachable[0];if(p)return{kind:"unreachable",entry:p};let b=a.failures[0];if(b)return{kind:"failed",pass:t,error:b.error};let c=a.results[0];if(!c)return{kind:"failed",pass:t,error:s(e.path,"no result")};if(u){let j=c.job.op==="convert"?{...c.job,sources:[e]}:c.job;return{kind:"done",result:{...c,job:j}}}let k=await E(m);if(k.kind!=="image")return{kind:"failed",pass:t,error:s(e.path,"not an image")};i=k}return{kind:"failed",pass:{kind:"encode",target:e.format},error:s(e.path,"nothing to run")}}catch(i){return{kind:"failed",pass:r[r.length-1]??{kind:"encode",target:e.format},error:y(i)?i:s(e.path,i)}}finally{await F(d,{recursive:!0,force:!0})}}export{C as a};
3
+ import{c as P}from"./chunk-C32KGH4S.js";import{j as v}from"./chunk-WZWK3PEZ.js";import{d as y,na as s}from"./chunk-WIPP5TWQ.js";import{mkdtemp as x,rm as F}from"node:fs/promises";import{tmpdir as z}from"node:os";import{join as h}from"node:path";var f={background:"#ffffff",keepMetadata:!1};function q(e,r,n){switch(e.kind){case"cut":return{op:"convert",sources:[r],outputs:[n],target:"png",options:{...f,...e.trim?{trim:!0}:{},...e.crop?{crop:{aspect:e.crop}}:{},...e.resize?{resize:e.resize}:{}}};case"cutout":return{op:"remove-background",sources:[r],outputs:[n],target:"png",options:f};case"boost":return{op:"boost",sources:[r],outputs:[n],scale:e.scale,target:"png",options:f};case"encode":return{op:"convert",sources:[r],outputs:[n],target:e.target,options:{...f,...e.background?{background:e.background}:{},...e.quality!==void 0?{quality:e.quality}:{},...e.compress?{compress:e.compress}:{},...e.trim?{trim:!0}:{},...e.crop?{crop:{aspect:e.crop}}:{},...e.resize?{resize:e.resize}:{}}}}}async function C(e,r,n,o){let E=o.probe??v,d=await x(h(z(),"forge-preset-")),I={force:o.force,...o.signal?{signal:o.signal}:{},...o.onEvent?{onEvent:o.onEvent}:{}};try{let i=e;for(let[l,t]of r.entries()){o.onPass?.(l);let u=l===r.length-1,m=u?n:h(d,`${l}.png`),a=await P([q(t,i,m)],{...I,...u?{}:{force:!0},...u&&t.kind==="encode"&&t.maxBytes?{targetBytes:t.maxBytes,...t.quality===void 0?{}:{maxQuality:t.quality}}:{}});if(a.cancelled)return{kind:"cancelled"};let g=a.refusals[0];if(g)return{kind:"refused",error:g.error};let p=a.unreachable[0];if(p)return{kind:"unreachable",entry:p};let b=a.failures[0];if(b)return{kind:"failed",pass:t,error:b.error};let c=a.results[0];if(!c)return{kind:"failed",pass:t,error:s(e.path,"no result")};if(u){let j=c.job.op==="convert"?{...c.job,sources:[e]}:c.job;return{kind:"done",result:{...c,job:j}}}let k=await E(m);if(k.kind!=="image")return{kind:"failed",pass:t,error:s(e.path,"not an image")};i=k}return{kind:"failed",pass:{kind:"encode",target:e.format},error:s(e.path,"nothing to run")}}catch(i){return{kind:"failed",pass:r[r.length-1]??{kind:"encode",target:e.format},error:y(i)?i:s(e.path,i)}}finally{await F(d,{recursive:!0,force:!0})}}export{C as a};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{d as I,k as A}from"./chunk-THDAQBQ3.js";import{n as re,o as M,q as ie}from"./chunk-DZOBIUV6.js";import{a as ae,b as ne,c as oe,d as se,e as he,f as ce,g as E}from"./chunk-TL5MACSF.js";import{E as X,H as F,M as G,_ as H,c as b,d as S,da as K,e as L,f as N,fa as Q,g as O,ga as Y,h as _,ha as Z,i as $,ia as ee,j as D,ja as te,k as q,l as U,na as x,o as W,p as J,q as V,w as j,x as v}from"./chunk-WIPP5TWQ.js";import{a as d}from"./chunk-H3DIRJFE.js";import{b as g}from"./chunk-KXKQDFHX.js";import{constants as be}from"node:fs";import{access as Se,readFile as ve,rm as xe,stat as Ie,writeFile as Ee}from"node:fs/promises";import{dirname as ze}from"node:path";function Ue(e){if(d[e].hasAlpha)return;let r=Object.keys(d).filter(t=>d[t].hasAlpha&&t!=="heic").join(", ");return F(`${d[e].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${r}.`)}var fe="1.1.0";function ge(e,r){let t=e.split(".").map(i=>Number.parseInt(i,10)||0),a=r.split(".").map(i=>Number.parseInt(i,10)||0);for(let i=0;i<Math.max(t.length,a.length);i++){let n=(t[i]??0)-(a[i]??0);if(n!==0)return n>0}return!0}function T(e){return e!==void 0&&ge(e,fe)?[2,3,4]:[2,4]}function We(e,r,t){if(e===1||T(r).some(i=>i===e))return;if(t!==void 0&&T(t).some(i=>i===e))return G("boost",`boost ${e}\xD7`,r,fe);let a=T(r).map(i=>`--boost ${i}`);return F(`No released boost makes ${e}\xD7 yet.`,`Try ${a.slice(0,-1).join(", ")} or ${a.at(-1)}.`)}var le=16384,ye=1e8;function de(e,r,t){let a=Math.max(e,r)*t;if(a>le)return{side:a};let i=e*t*r*t;if(i>ye)return{megapixels:Math.round(i/1e6)}}var w=e=>Math.max(1,Math.round(e));function k(e,r){return"percent"in r?{width:w(e.width*r.percent/100),height:w(e.height*r.percent/100)}:"width"in r?{width:w(r.width),height:w(e.height*r.width/e.width)}:{width:w(e.width*r.height/e.height),height:w(r.height)}}function pe(e){return de(e.width,e.height,1)}var Oe=new Set(["jpeg","png","webp","avif","heic","raw","gif","tiff"]),Fe=new Set(["jpeg","png","webp","avif","gif","tiff"]),Ae={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function Me(e,r){if(r.format==="heif")return r.compression==="av1"?"avif":"heic";let t=Ae[r.format??""];if(!t)throw U(e,r.format??"an unknown format");return t}async function Te(e){let r;try{r=await Ie(e)}catch(n){let h=n.code;throw h==="ENOENT"?L(e):h==="EACCES"||h==="EPERM"?O(e):h==="ENOTDIR"?_(e):h==="ELOOP"?$(e):h==="ENAMETOOLONG"?D(e):q(e,n)}if(!r.isFile())throw N(e);try{await Se(e,be.R_OK)}catch{throw O(e)}if(await ne(e)){if(!await ae())throw W(e);let n;try{n=await oe(e)}catch(h){throw v(e,"heic",h)}if(n.width===0||n.height===0)throw v(e,"heic",void 0);return{kind:"image",path:e,format:"heic",width:n.width,height:n.height,bytes:r.size,hasAlpha:n.hasAlpha,frames:1}}let t=await se(e);if(t){if(!await he())throw J(e);let n;try{n=await ce(e,t)}catch(h){throw v(e,"raw",h)}if(!n)throw V(e);return{kind:"image",path:e,format:"raw",width:n.width,height:n.height,bytes:r.size,hasAlpha:!1,frames:1}}let a=await g(),i;try{i=await a(e).metadata()}catch(n){throw j(e,n)}return{kind:"image",path:e,format:Me(e,i),width:i.autoOrient?.width??i.width??0,height:i.autoOrient?.height??i.height??0,bytes:r.size,hasAlpha:i.hasAlpha??!1,frames:i.pages??1}}function R(e,r,t,a){let i=t??d[r].defaultQuality;if(a&&d[r].quantisable)return ke(e,r,t,a);switch(r){case"jpeg":return e.jpeg({quality:i,mozjpeg:!0});case"webp":return e.webp({quality:i});case"avif":return e.avif({quality:i});case"png":return e.png({compressionLevel:9});case"gif":return e.gif();case"tiff":return e.tiff({compression:"deflate"});case"heic":throw new Error("heic is not writable; the capability graph should have prevented this");case"raw":throw new Error("raw is not writable; the capability graph should have prevented this");case"pdf":throw new Error("pdf is not an image target; the capability graph should have prevented this");case"docx":throw new Error("docx is not an image target; the capability graph should have prevented this");case"doc":throw new Error("doc is not an image target; the capability graph should have prevented this");default:throw new Error(`${r} is not an image target; the capability graph should have prevented this`)}}function ke(e,r,t,{dither:a}){let i=t??100,n=a?1:0;return r==="gif"?e.gif({interFrameMaxError:Math.round(32*(100-i)/100),dither:n}):e.png({palette:!0,quality:i,dither:n,compressionLevel:9,effort:10})}var B=(e,r)=>e.kind==="image"&&e.frames>1&&d[r].animatable;async function Re(e,r){let t=ze(r);await M(r);let a=re(r);try{return await Ee(a,e),await ie(a,r),e.length}catch(i){throw await xe(a,{force:!0}).catch(()=>{}),X(r,i)}}async function l(e,r,t,a,i,n){if(e.kind!=="image")throw new Error("pipelineFor received a non-image source");let h=i===void 0?await E(e.path,e.format):void 0,f=async()=>{await h?.cleanup()},s=(await g())(i??h?.path??e.path,a?{animated:!0}:{});if(s=s.rotate(),t.trim&&(s=s.trim()),t.crop){if(!t.crop.box)throw new Error("pipelineFor needs the crop placed (run does it)");s=s.extract(t.crop.box)}if(t.resize){if(!n&&(t.trim||t.crop))throw new Error("pipelineFor needs the resolved size to resize a cut image");let u=n??k(e,t.resize);s=s.resize(u.width,u.height,{fit:"fill"})}return t.rotate&&(s=s.rotate(t.rotate)),e.hasAlpha&&!d[r].hasAlpha&&(s=s.flatten({background:t.background})),s=t.keepMetadata?s.keepMetadata():s.keepIccProfile(),{pipeline:s,cleanup:f}}async function ot(e,r){let t={background:"#ffffff",keepMetadata:!1},{pipeline:a,cleanup:i}=await l(e,"png",t,!1);try{await a.png({compressionLevel:1}).toFile(r)}finally{await i()}}async function st(e,r,t){let{pipeline:a,cleanup:i}=await l(e,r,t,B(e,r));try{return await R(a,r,t.quality,t.compress).toBuffer()}finally{await i()}}async function Be(e){let r={width:e.width,height:e.height};if(e.frames>1)return{upright:r,trimmed:"animated"};let t=await E(e.path,e.format);try{let a=await g(),{info:i}=await a(t.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return i.width===r.width&&i.height===r.height?{upright:r,trimmed:"nothing"}:{upright:r,trimmed:{width:i.width,height:i.height}}}catch(a){throw S(a)?a:x(e.path,a)}finally{await t.cleanup()}}var me=1024;async function Ce(e){let r={background:"#ffffff",keepMetadata:!1},{pipeline:t,cleanup:a}=await l(e,"png",r,!1);try{let{data:i,info:n}=await t.resize(me,me,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0}),h=n.width*n.height,f=n.channels,o=new Uint8Array(h*3),s=new Uint8Array(h),u=!1;for(let m=0;m<h;m++){for(let c=0;c<3;c++)o[m*3+c]=i[m*f+(f>=4?c:0)]??0;s[m]=i[m*f+f-1]??255,s[m]!==255&&(u=!0)}return{size:{width:e.width,height:e.height},thumb:{width:n.width,height:n.height,rgb:o,...u?{alpha:s}:{}}}}catch(i){throw S(i)?i:x(e.path,i)}finally{await a()}}var ue=128;async function Pe(e,r){let{thumb:t,size:a}=e,i=I(t,r),n=await g(),{info:h}=await n(Le(t),{raw:{width:t.width,height:t.height,channels:3}}).resize(i.width,i.height,{fit:"cover",position:n.strategy.attention}).raw().toBuffer({resolveWithObject:!0}),f=I(a,r),o=Math.round(-(h.cropOffsetLeft??0)*a.width/t.width),s=Math.round(-(h.cropOffsetTop??0)*a.height/t.height);return{...f,left:Math.min(Math.max(o,0),a.width-f.width),top:Math.min(Math.max(s,0),a.height-f.height)}}function Le(e){let{alpha:r}=e;if(!r)return e.rgb;let t=new Uint8Array(e.rgb.length);for(let a=0;a<t.length;a++){let i=(r[Math.floor(a/3)]??255)/255;t[a]=Math.round(ue+((e.rgb[a]??0)-ue)*i)}return t}async function Ne(e,r){if(e.op!=="convert")throw new Error(`image engine cannot ${e.op}`);let t=e.sources[0],a=e.outputs[0];if(t.kind!=="image")throw new Error("the image engine cannot convert a document source");let i=d[e.target],n=[];r({phase:"reading"});let h=t.frames>1,f=B(t,e.target);h&&!i.animatable&&n.push({code:"animation-flattened",message:`${b(t.path)} has ${t.frames} frames, and ${i.label} cannot animate. Only the first frame was converted.`});let o=e.options,s;if(o.rotate&&h)throw te(t.path);if(o.trim||o.crop||o.resize){let c={width:t.width,height:t.height};if(o.trim&&o.crop)throw new Error("a job cannot both trim and crop");if(o.crop){if(h)throw ee(t.path);let{aspect:p}=o.crop,C=z=>z.width===t.width&&z.height===t.height,P=I(c,p),y=o.crop.box??(C(P)?P:await Pe(await Ce(t),p));if(C(y)){if(!o.resize)throw Z(t.path,A(p));n.push({code:"nothing-cropped",message:`${b(t.path)} is already ${A(p)}; resized only.`});let{crop:z,...we}=o;o=we}else o={...o,crop:{aspect:p,box:y}},c={width:y.width,height:y.height}}if(o.trim){if(h)throw Y(t.path);let{trimmed:p}=await Be(t);if(p==="nothing"){if(!o.resize)throw Q(t.path);n.push({code:"nothing-trimmed",message:`${b(t.path)} has no empty edges; resized only.`})}else p!=="animated"&&(c=p)}if(o.resize&&(s=k(c,o.resize),pe(s)))throw H(t.path,s)}r({phase:"decoding"});let{pipeline:u,cleanup:m}=await l(t,e.target,o,f,void 0,s);try{await M(a),r({phase:"encoding"});let c=await R(u,e.target,o.quality,o.compress).toBuffer();if(o.compress&&c.length>=t.bytes)throw K(t.path,t.bytes,c.length);r({phase:"writing"});let p=await Re(c,a);return{job:e,outputBytes:p,warnings:n}}catch(c){throw S(c)?c:x(t.path,c)}finally{await m()}}async function _e(e){let r=await E(e.path,e.format);try{return await ve(r.path)}finally{await r.cleanup()}}async function $e(e){if(e.op!=="convert")return;let r=d[e.target];if(!r.lossy&&!(r.quantisable&&e.options.compress))return;let t=e.sources[0];if(t.kind!=="image")return;let a=await _e(t);return{ladder:[{}],measure:async i=>{let{pipeline:n}=await l(t,e.target,i,B(t,e.target),a);return(await R(n,e.target,i.quality,i.compress).toBuffer()).length}}}var ht={id:"image",reads:Oe,writes:Fe,ops:new Set(["convert"]),probe:Te,run:Ne,measurer:$e};export{Ue as a,T as b,We as c,le as d,de as e,k as f,pe as g,R as h,Re as i,ot as j,st as k,Be as l,Ce as m,Pe as n,ht as o};
3
+ import{d as I,k as A}from"./chunk-THDAQBQ3.js";import{n as re,o as M,q as ie}from"./chunk-DZOBIUV6.js";import{a as ae,b as ne,c as oe,d as se,e as he,f as ce,g as E}from"./chunk-5TEAR5XH.js";import{E as X,H as F,M as G,_ as H,c as b,d as S,da as K,e as L,f as N,fa as Q,g as O,ga as Y,h as _,ha as Z,i as $,ia as ee,j as D,ja as te,k as q,l as U,na as x,o as W,p as J,q as V,w as j,x as v}from"./chunk-WIPP5TWQ.js";import{a as d}from"./chunk-H3DIRJFE.js";import{b as g}from"./chunk-KXKQDFHX.js";import{constants as be}from"node:fs";import{access as Se,readFile as ve,rm as xe,stat as Ie,writeFile as Ee}from"node:fs/promises";import{dirname as ze}from"node:path";function Ue(e){if(d[e].hasAlpha)return;let r=Object.keys(d).filter(t=>d[t].hasAlpha&&t!=="heic").join(", ");return F(`${d[e].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${r}.`)}var fe="1.1.0";function ge(e,r){let t=e.split(".").map(i=>Number.parseInt(i,10)||0),a=r.split(".").map(i=>Number.parseInt(i,10)||0);for(let i=0;i<Math.max(t.length,a.length);i++){let n=(t[i]??0)-(a[i]??0);if(n!==0)return n>0}return!0}function T(e){return e!==void 0&&ge(e,fe)?[2,3,4]:[2,4]}function We(e,r,t){if(e===1||T(r).some(i=>i===e))return;if(t!==void 0&&T(t).some(i=>i===e))return G("boost",`boost ${e}\xD7`,r,fe);let a=T(r).map(i=>`--boost ${i}`);return F(`No released boost makes ${e}\xD7 yet.`,`Try ${a.slice(0,-1).join(", ")} or ${a.at(-1)}.`)}var le=16384,ye=1e8;function de(e,r,t){let a=Math.max(e,r)*t;if(a>le)return{side:a};let i=e*t*r*t;if(i>ye)return{megapixels:Math.round(i/1e6)}}var w=e=>Math.max(1,Math.round(e));function k(e,r){return"percent"in r?{width:w(e.width*r.percent/100),height:w(e.height*r.percent/100)}:"width"in r?{width:w(r.width),height:w(e.height*r.width/e.width)}:{width:w(e.width*r.height/e.height),height:w(r.height)}}function pe(e){return de(e.width,e.height,1)}var Oe=new Set(["jpeg","png","webp","avif","heic","raw","gif","tiff"]),Fe=new Set(["jpeg","png","webp","avif","gif","tiff"]),Ae={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function Me(e,r){if(r.format==="heif")return r.compression==="av1"?"avif":"heic";let t=Ae[r.format??""];if(!t)throw U(e,r.format??"an unknown format");return t}async function Te(e){let r;try{r=await Ie(e)}catch(n){let h=n.code;throw h==="ENOENT"?L(e):h==="EACCES"||h==="EPERM"?O(e):h==="ENOTDIR"?_(e):h==="ELOOP"?$(e):h==="ENAMETOOLONG"?D(e):q(e,n)}if(!r.isFile())throw N(e);try{await Se(e,be.R_OK)}catch{throw O(e)}if(await ne(e)){if(!await ae())throw W(e);let n;try{n=await oe(e)}catch(h){throw v(e,"heic",h)}if(n.width===0||n.height===0)throw v(e,"heic",void 0);return{kind:"image",path:e,format:"heic",width:n.width,height:n.height,bytes:r.size,hasAlpha:n.hasAlpha,frames:1}}let t=await se(e);if(t){if(!await he())throw J(e);let n;try{n=await ce(e,t)}catch(h){throw v(e,"raw",h)}if(!n)throw V(e);return{kind:"image",path:e,format:"raw",width:n.width,height:n.height,bytes:r.size,hasAlpha:!1,frames:1}}let a=await g(),i;try{i=await a(e).metadata()}catch(n){throw j(e,n)}return{kind:"image",path:e,format:Me(e,i),width:i.autoOrient?.width??i.width??0,height:i.autoOrient?.height??i.height??0,bytes:r.size,hasAlpha:i.hasAlpha??!1,frames:i.pages??1}}function R(e,r,t,a){let i=t??d[r].defaultQuality;if(a&&d[r].quantisable)return ke(e,r,t,a);switch(r){case"jpeg":return e.jpeg({quality:i,mozjpeg:!0});case"webp":return e.webp({quality:i});case"avif":return e.avif({quality:i});case"png":return e.png({compressionLevel:9});case"gif":return e.gif();case"tiff":return e.tiff({compression:"deflate"});case"heic":throw new Error("heic is not writable; the capability graph should have prevented this");case"raw":throw new Error("raw is not writable; the capability graph should have prevented this");case"pdf":throw new Error("pdf is not an image target; the capability graph should have prevented this");case"docx":throw new Error("docx is not an image target; the capability graph should have prevented this");case"doc":throw new Error("doc is not an image target; the capability graph should have prevented this");default:throw new Error(`${r} is not an image target; the capability graph should have prevented this`)}}function ke(e,r,t,{dither:a}){let i=t??100,n=a?1:0;return r==="gif"?e.gif({interFrameMaxError:Math.round(32*(100-i)/100),dither:n}):e.png({palette:!0,quality:i,dither:n,compressionLevel:9,effort:10})}var B=(e,r)=>e.kind==="image"&&e.frames>1&&d[r].animatable;async function Re(e,r){let t=ze(r);await M(r);let a=re(r);try{return await Ee(a,e),await ie(a,r),e.length}catch(i){throw await xe(a,{force:!0}).catch(()=>{}),X(r,i)}}async function l(e,r,t,a,i,n){if(e.kind!=="image")throw new Error("pipelineFor received a non-image source");let h=i===void 0?await E(e.path,e.format):void 0,f=async()=>{await h?.cleanup()},s=(await g())(i??h?.path??e.path,a?{animated:!0}:{});if(s=s.rotate(),t.trim&&(s=s.trim()),t.crop){if(!t.crop.box)throw new Error("pipelineFor needs the crop placed (run does it)");s=s.extract(t.crop.box)}if(t.resize){if(!n&&(t.trim||t.crop))throw new Error("pipelineFor needs the resolved size to resize a cut image");let u=n??k(e,t.resize);s=s.resize(u.width,u.height,{fit:"fill"})}return t.rotate&&(s=s.rotate(t.rotate)),e.hasAlpha&&!d[r].hasAlpha&&(s=s.flatten({background:t.background})),s=t.keepMetadata?s.keepMetadata():s.keepIccProfile(),{pipeline:s,cleanup:f}}async function ot(e,r){let t={background:"#ffffff",keepMetadata:!1},{pipeline:a,cleanup:i}=await l(e,"png",t,!1);try{await a.png({compressionLevel:1}).toFile(r)}finally{await i()}}async function st(e,r,t){let{pipeline:a,cleanup:i}=await l(e,r,t,B(e,r));try{return await R(a,r,t.quality,t.compress).toBuffer()}finally{await i()}}async function Be(e){let r={width:e.width,height:e.height};if(e.frames>1)return{upright:r,trimmed:"animated"};let t=await E(e.path,e.format);try{let a=await g(),{info:i}=await a(t.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return i.width===r.width&&i.height===r.height?{upright:r,trimmed:"nothing"}:{upright:r,trimmed:{width:i.width,height:i.height}}}catch(a){throw S(a)?a:x(e.path,a)}finally{await t.cleanup()}}var me=1024;async function Ce(e){let r={background:"#ffffff",keepMetadata:!1},{pipeline:t,cleanup:a}=await l(e,"png",r,!1);try{let{data:i,info:n}=await t.resize(me,me,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0}),h=n.width*n.height,f=n.channels,o=new Uint8Array(h*3),s=new Uint8Array(h),u=!1;for(let m=0;m<h;m++){for(let c=0;c<3;c++)o[m*3+c]=i[m*f+(f>=4?c:0)]??0;s[m]=i[m*f+f-1]??255,s[m]!==255&&(u=!0)}return{size:{width:e.width,height:e.height},thumb:{width:n.width,height:n.height,rgb:o,...u?{alpha:s}:{}}}}catch(i){throw S(i)?i:x(e.path,i)}finally{await a()}}var ue=128;async function Pe(e,r){let{thumb:t,size:a}=e,i=I(t,r),n=await g(),{info:h}=await n(Le(t),{raw:{width:t.width,height:t.height,channels:3}}).resize(i.width,i.height,{fit:"cover",position:n.strategy.attention}).raw().toBuffer({resolveWithObject:!0}),f=I(a,r),o=Math.round(-(h.cropOffsetLeft??0)*a.width/t.width),s=Math.round(-(h.cropOffsetTop??0)*a.height/t.height);return{...f,left:Math.min(Math.max(o,0),a.width-f.width),top:Math.min(Math.max(s,0),a.height-f.height)}}function Le(e){let{alpha:r}=e;if(!r)return e.rgb;let t=new Uint8Array(e.rgb.length);for(let a=0;a<t.length;a++){let i=(r[Math.floor(a/3)]??255)/255;t[a]=Math.round(ue+((e.rgb[a]??0)-ue)*i)}return t}async function Ne(e,r){if(e.op!=="convert")throw new Error(`image engine cannot ${e.op}`);let t=e.sources[0],a=e.outputs[0];if(t.kind!=="image")throw new Error("the image engine cannot convert a document source");let i=d[e.target],n=[];r({phase:"reading"});let h=t.frames>1,f=B(t,e.target);h&&!i.animatable&&n.push({code:"animation-flattened",message:`${b(t.path)} has ${t.frames} frames, and ${i.label} cannot animate. Only the first frame was converted.`});let o=e.options,s;if(o.rotate&&h)throw te(t.path);if(o.trim||o.crop||o.resize){let c={width:t.width,height:t.height};if(o.trim&&o.crop)throw new Error("a job cannot both trim and crop");if(o.crop){if(h)throw ee(t.path);let{aspect:p}=o.crop,C=z=>z.width===t.width&&z.height===t.height,P=I(c,p),y=o.crop.box??(C(P)?P:await Pe(await Ce(t),p));if(C(y)){if(!o.resize)throw Z(t.path,A(p));n.push({code:"nothing-cropped",message:`${b(t.path)} is already ${A(p)}; resized only.`});let{crop:z,...we}=o;o=we}else o={...o,crop:{aspect:p,box:y}},c={width:y.width,height:y.height}}if(o.trim){if(h)throw Y(t.path);let{trimmed:p}=await Be(t);if(p==="nothing"){if(!o.resize)throw Q(t.path);n.push({code:"nothing-trimmed",message:`${b(t.path)} has no empty edges; resized only.`})}else p!=="animated"&&(c=p)}if(o.resize&&(s=k(c,o.resize),pe(s)))throw H(t.path,s)}r({phase:"decoding"});let{pipeline:u,cleanup:m}=await l(t,e.target,o,f,void 0,s);try{await M(a),r({phase:"encoding"});let c=await R(u,e.target,o.quality,o.compress).toBuffer();if(o.compress&&c.length>=t.bytes)throw K(t.path,t.bytes,c.length);r({phase:"writing"});let p=await Re(c,a);return{job:e,outputBytes:p,warnings:n}}catch(c){throw S(c)?c:x(t.path,c)}finally{await m()}}async function _e(e){let r=await E(e.path,e.format);try{return await ve(r.path)}finally{await r.cleanup()}}async function $e(e){if(e.op!=="convert")return;let r=d[e.target];if(!r.lossy&&!(r.quantisable&&e.options.compress))return;let t=e.sources[0];if(t.kind!=="image")return;let a=await _e(t);return{ladder:[{}],measure:async i=>{let{pipeline:n}=await l(t,e.target,i,B(t,e.target),a);return(await R(n,e.target,i.quality,i.compress).toBuffer()).length}}}var ht={id:"image",reads:Oe,writes:Fe,ops:new Set(["convert"]),probe:Te,run:Ne,measurer:$e};export{Ue as a,T as b,We as c,le as d,de as e,k as f,pe as g,R as h,Re as i,ot as j,st as k,Be as l,Ce as m,Pe as n,ht as o};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a as b}from"./chunk-PPR7B5AR.js";import{j as h}from"./chunk-V3I6DSF4.js";import{d as y}from"./chunk-WIPP5TWQ.js";import{a as c}from"./chunk-H3DIRJFE.js";import{open as g,readdir as x,stat as w}from"node:fs/promises";import{extname as S,join as k,resolve as v}from"node:path";function K(e){return e.startsWith(".")||/\.(crdownload|part|download|tmp)$/i.test(e)}function A(e){return e.kind==="image"?"images":e.format==="pdf"?"pdfs":"documents"}var O=new Set(Object.values(c).flatMap(e=>e.extensions));async function R(e){let i=await g(e,"r"),n=Buffer.alloc(4096),r=0;try{r=(await i.read(n,0,n.length,0)).bytesRead}finally{await i.close()}let t=n.subarray(0,r),o=(d,f)=>t.subarray(d,d+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":t[0]===26&&t[1]===69&&t[2]===223&&t[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":t[0]===0&&t[1]===0&&t[2]===1&&(t[3]===186||t[3]===179)?"video":o(0,3)==="ID3"||o(0,4)==="fLaC"||o(0,4)==="OggS"||o(0,4)==="FORM"&&/^AIF[FC]$/.test(o(8,4))||t[0]===255&&t[1]!==void 0&&(t[1]&224)===224?"audio":r>0&&!t.includes(0)&&M(t)?"text":"other"}function M(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e,{stream:!0}),!0}catch{return!1}}var F=["images","pdfs","documents","videos","audio","other"];function j(e,i){if(e==="videos"||e==="audio")return"not yet supported";if(e==="other")return i.every(n=>n==="text")?i.length===1?"a text file":"text files":"not supported"}async function z(e){let i=v(e),n=await x(i,{withFileTypes:!0}),r=[],t=[],o=new Map,d=[],f=0;for(let u of n.sort((a,s)=>a.name.localeCompare(s.name))){if(!u.isFile()||K(u.name))continue;let a=k(i,u.name);d.push(a);let s=await E(a);if(s.kind==="source")r.push(s.source),f+=s.source.bytes;else if(s.kind==="failed")t.push(s.failure),f+=s.bytes;else{let m=s.kind,p=o.get(m)??{bytes:0,sniffed:[]};p.bytes+=s.bytes,p.sniffed.push(s.sniffed),o.set(m,p),f+=s.bytes}}let l=I(r);for(let u of F){let a=o.get(u);if(!a)continue;let s=j(u,a.sniffed);l.push({id:u,count:a.sniffed.length,bytes:a.bytes,sources:[],...s===void 0?{}:{why:s}})}return{dir:i,sources:r,failures:t,kinds:l,bytes:f,paths:d}}function I(e){let i=[];for(let n of F){let r=e.filter(t=>A(t)===n);r.length>0&&i.push({id:n,count:r.length,bytes:r.reduce((t,o)=>t+o.bytes,0),sources:r})}return i.sort((n,r)=>r.count-n.count)}function L(e,i=[]){let n=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),t=I(r);for(let o of["videos","audio"]){let d=n.filter(f=>c[f.format].media==="video"==(o==="videos"));if(d.length>0){let f=d.reduce((l,u)=>l+u.bytes,0);t.push({id:o,count:d.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:t,bytes:e.reduce((o,d)=>o+d.bytes,0),paths:e.map(o=>o.path)}}async function E(e){let i=()=>w(e).then(n=>n.size,()=>0);try{let n=await h(e);if(n.kind==="media"){let r=c[n.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:n.bytes}}return{kind:"source",source:n}}catch(n){let r=await i(),t=await R(e).catch(()=>"other");if(t==="video"||t==="audio")return{kind:t==="video"?"videos":"audio",sniffed:t,bytes:r};if(O.has(S(e).toLowerCase())){let o=y(n)?n:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:t,bytes:r}}}function D(e){let i=new Set(e.flatMap(n=>b(n).filter(r=>r!==n.format)));return Object.keys(c).filter(n=>i.has(n))}function V(e,i){let n=D(e),r=e[0],t=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=t&&n.includes(t)?t:n[0];if(o)return N(e,o,i)}function N(e,i,n){let r={target:i};return c[i].lossy&&(r.quality=n),e.some(t=>t.kind==="document"&&t.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{K as a,A as b,R as c,z as d,L as e,E as f,D as g,V as h,N as i};
3
+ import{a as b}from"./chunk-BD3OLIVT.js";import{j as h}from"./chunk-WZWK3PEZ.js";import{d as y}from"./chunk-WIPP5TWQ.js";import{a as c}from"./chunk-H3DIRJFE.js";import{open as g,readdir as x,stat as w}from"node:fs/promises";import{extname as S,join as k,resolve as v}from"node:path";function K(e){return e.startsWith(".")||/\.(crdownload|part|download|tmp)$/i.test(e)}function A(e){return e.kind==="image"?"images":e.format==="pdf"?"pdfs":"documents"}var O=new Set(Object.values(c).flatMap(e=>e.extensions));async function R(e){let i=await g(e,"r"),n=Buffer.alloc(4096),r=0;try{r=(await i.read(n,0,n.length,0)).bytesRead}finally{await i.close()}let t=n.subarray(0,r),o=(d,f)=>t.subarray(d,d+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":t[0]===26&&t[1]===69&&t[2]===223&&t[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":t[0]===0&&t[1]===0&&t[2]===1&&(t[3]===186||t[3]===179)?"video":o(0,3)==="ID3"||o(0,4)==="fLaC"||o(0,4)==="OggS"||o(0,4)==="FORM"&&/^AIF[FC]$/.test(o(8,4))||t[0]===255&&t[1]!==void 0&&(t[1]&224)===224?"audio":r>0&&!t.includes(0)&&M(t)?"text":"other"}function M(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e,{stream:!0}),!0}catch{return!1}}var F=["images","pdfs","documents","videos","audio","other"];function j(e,i){if(e==="videos"||e==="audio")return"not yet supported";if(e==="other")return i.every(n=>n==="text")?i.length===1?"a text file":"text files":"not supported"}async function z(e){let i=v(e),n=await x(i,{withFileTypes:!0}),r=[],t=[],o=new Map,d=[],f=0;for(let u of n.sort((a,s)=>a.name.localeCompare(s.name))){if(!u.isFile()||K(u.name))continue;let a=k(i,u.name);d.push(a);let s=await E(a);if(s.kind==="source")r.push(s.source),f+=s.source.bytes;else if(s.kind==="failed")t.push(s.failure),f+=s.bytes;else{let m=s.kind,p=o.get(m)??{bytes:0,sniffed:[]};p.bytes+=s.bytes,p.sniffed.push(s.sniffed),o.set(m,p),f+=s.bytes}}let l=I(r);for(let u of F){let a=o.get(u);if(!a)continue;let s=j(u,a.sniffed);l.push({id:u,count:a.sniffed.length,bytes:a.bytes,sources:[],...s===void 0?{}:{why:s}})}return{dir:i,sources:r,failures:t,kinds:l,bytes:f,paths:d}}function I(e){let i=[];for(let n of F){let r=e.filter(t=>A(t)===n);r.length>0&&i.push({id:n,count:r.length,bytes:r.reduce((t,o)=>t+o.bytes,0),sources:r})}return i.sort((n,r)=>r.count-n.count)}function L(e,i=[]){let n=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),t=I(r);for(let o of["videos","audio"]){let d=n.filter(f=>c[f.format].media==="video"==(o==="videos"));if(d.length>0){let f=d.reduce((l,u)=>l+u.bytes,0);t.push({id:o,count:d.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:t,bytes:e.reduce((o,d)=>o+d.bytes,0),paths:e.map(o=>o.path)}}async function E(e){let i=()=>w(e).then(n=>n.size,()=>0);try{let n=await h(e);if(n.kind==="media"){let r=c[n.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:n.bytes}}return{kind:"source",source:n}}catch(n){let r=await i(),t=await R(e).catch(()=>"other");if(t==="video"||t==="audio")return{kind:t==="video"?"videos":"audio",sniffed:t,bytes:r};if(O.has(S(e).toLowerCase())){let o=y(n)?n:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:t,bytes:r}}}function D(e){let i=new Set(e.flatMap(n=>b(n).filter(r=>r!==n.format)));return Object.keys(c).filter(n=>i.has(n))}function V(e,i){let n=D(e),r=e[0],t=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=t&&n.includes(t)?t:n[0];if(o)return N(e,o,i)}function N(e,i,n){let r={target:i};return c[i].lossy&&(r.quality=n),e.some(t=>t.kind==="document"&&t.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{K as a,A as b,R as c,z as d,L as e,E as f,D as g,V as h,N as i};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- var v="0.5.0",x={ok:"\u2713",fail:"\u2715",warn:"\u26A0",cursor:"\u276F",strip:"\u258C",star:"\u2605",arrow:"\u2192",tip:"\u2727",longArrow:"\u2500\u2500\u2192",longArrowDown:`\u2502
3
+ var v="0.5.1",x={ok:"\u2713",fail:"\u2715",warn:"\u26A0",cursor:"\u276F",strip:"\u258C",star:"\u2605",arrow:"\u2192",tip:"\u2727",longArrow:"\u2500\u2500\u2192",longArrowDown:`\u2502
4
4
  \u25BC`,dotFilled:"\u25CF",dotEmpty:"\u25CB"},f={name:"dark",fg:"#e7e7e7",dim:"#b0b0b0",accent:"#e5a23c",ok:"#6fcf7f",warn:"#e5c07b",fail:"#e8796d",failTint:"#2e2020",failTintDim:"#b0b0b0",larger:"#f2994a",shedHatch:"#47774f",grownFill:"#403225",tag:"#63c1d8",label:"#a68ce0",modeConvert:"#55c7d9",modeConvertBg:"#122c33",modeCompress:"#79c98b",modeCompressBg:"#182c1e",modePdf:"#ff6b4a",modePdfBg:"#361c16",modeColour:"#f27ba8",modeColourBg:"#3a1e2b",modeEdit:"#b39ae8",modeEditBg:"#2a2238",modeTranscribe:"#e63946",modeTranscribeBg:"#3a1a1d",border:"#808080",selectionBg:"#2c2c2c",band:"#2c2c2c",canvas:"#1e1e1e",textSelectionBg:"#3f5c86",brand:"#e5a23c",keycapBg:"#333333",violet:"#a68ce0",faint:"#4d4d4d",listBand:"#323232",shelf:"#242424",tabChip:"#262626",panelBand:"#404040",ink:"#0c1d22",track:"#2e2e2e",trackFill:"#515151",thumb:"#e7e7e7",folderChip:"#414141",pill:"#e7e7e7",fieldBand:"#3d3d3d",defaultTagBg:"#33261a",defaultTag:"#c98a4b",newTagBg:"#2a3448",newTag:"#4f77c5"},o={name:"light",fg:"#262626",dim:"#4f4f4f",accent:"#915a01",ok:"#0e702c",warn:"#8a6100",fail:"#a43c32",failTint:"#f9e3df",failTintDim:"#4a4a4a",larger:"#8b4d01",shedHatch:"#87b896",grownFill:"#ece3d6",tag:"#0a6b86",label:"#5e4b99",modeConvert:"#036b7b",modeConvertBg:"#e6f7fa",modeCompress:"#24733a",modeCompressBg:"#eaf5ec",modePdf:"#b82a06",modePdfBg:"#fceee9",modeColour:"#b0306a",modeColourBg:"#f7e3ec",modeEdit:"#64569f",modeEditBg:"#f0ebfa",modeTranscribe:"#c0102c",modeTranscribeBg:"#fef0ef",border:"#767676",selectionBg:"#e4e4e4",band:"#e4e4e4",canvas:"#ffffff",textSelectionBg:"#b9cfe8",brand:"#915a01",keycapBg:"#e1e1e1",violet:"#5e4b99",faint:"#b2b2b2",listBand:"#dcdcdc",shelf:"#f3f3f3",tabChip:"#f0f0f0",panelBand:"#d5d5d5",ink:"#ffffff",track:"#e4e4e4",trackFill:"#afafaf",thumb:"#262626",folderChip:"#d0d0d0",pill:"#262626",fieldBand:"#d7d7d7",defaultTagBg:"#f5e2cc",defaultTag:"#8f5000",newTagBg:"#e1e7f4",newTag:"#3358a3"},i={name:"neutral",fg:"",dim:"gray",accent:"yellow",ok:"green",warn:"yellow",fail:"red",failTint:"",failTintDim:"gray",larger:"yellow",shedHatch:"green",grownFill:"",tag:"cyan",label:"magenta",modeConvert:"cyan",modeConvertBg:"",modeCompress:"green",modeCompressBg:"",modePdf:"red",modePdfBg:"",modeColour:"magenta",modeColourBg:"",modeEdit:"magenta",modeEditBg:"",modeTranscribe:"redBright",modeTranscribeBg:"",border:"gray",selectionBg:"",band:"",canvas:"",textSelectionBg:"",brand:"yellow",keycapBg:"",violet:"magenta",faint:"gray",listBand:"",shelf:"",tabChip:"",panelBand:"",ink:"",track:"",trackFill:"",thumb:"",folderChip:"",pill:"",fieldBand:"",defaultTagBg:"",defaultTag:"",newTagBg:"",newTag:""},d=["convert","compress","pdf","edit","transcribe","colour"],k=`1\u2013${d.length}`;function E(e,t){let r=d,n=e==="menu"?r.length:r.indexOf(e),a=Math.max(0,Math.min(r.length-1,n+t));return r[a]}function P(e){return/^[1-9]$/.test(e)?d[Number(e)-1]:void 0}var S={convert:"\u2194",compress:"\u2193",pdf:"\u25A3",colour:"\u25D0",edit:"\u2726",transcribe:"\xB6"},c="#7d6ad0",l="#cc8ae2";function s(e,t){return t==="compress"?{fg:e.modeCompress,bg:e.modeCompressBg}:t==="pdf"?{fg:e.modePdf,bg:e.modePdfBg}:t==="colour"?{fg:e.modeColour,bg:e.modeColourBg}:t==="edit"?{fg:e.modeEdit,bg:e.modeEditBg}:t==="transcribe"?{fg:e.modeTranscribe,bg:e.modeTranscribeBg}:{fg:e.modeConvert,bg:e.modeConvertBg}}var g=["#f26e69","#e5a23c","#ace02c","#55c7d9","#6579fd","#ad95e9"],b=["#e5a23c","#f2cf6b"],m={convert:["#1e96a7","#1e94b3","#1e92c0","#1d8ed2","#1b86ef","#4a7df8","#6974f8","#816af8","#995cf8"],compress:["#24b459","#22ab6d","#21a479","#209f81","#1f9c89","#1f9a91","#1e9998","#1e97a0","#1e96a7"],pdf:["#eb4319","#e3541a","#de601b","#db6a1c","#d9731d","#d87c1e","#d8841f","#d98c20","#d99522"],edit:["#9b5af8","#985cf8","#965ef8","#945ff8","#9161f8","#8f62f8","#8d64f8","#8a65f8","#8867f8"],transcribe:["#f3233e","#f12259","#ee2270","#ea2186","#e6219b","#e121b0","#da22c6","#d122dc","#c723f2"],colour:["#f42335","#e05b1a","#d87d1e","#da9b23","#d2b427","#b4c027","#5bbf23","#20a27c","#1e989b","#1e94b6","#1c8cd9","#577af8","#7371f8","#8568f8","#965df8"]},u=["#d99522","#da9822","#da9b23","#da9f24","#d9a224","#d9a525","#d8a825","#d7ab26","#d6ad26"],B={convert:["#d6f7fd","#ddf5fe","#e1f4fe","#e4f2fe","#e7f1fe","#eaf0fe","#eceffe","#efeefe","#f1edfe"],compress:["#e0f7e4","#def8e7","#dcf8ea","#daf8ed","#d8f8f1","#d7f8f4","#d6f8f7","#d6f8fa","#d6f7fd"],pdf:["#feece7","#feece6","#feece5","#feece3","#feece2","#feede0","#feedde","#feeddc","#feeed9"],edit:["#f2edfe","#f1edfe","#f1edfe","#f1eefe","#f0eefe","#f0eefe","#f0eefe","#f0eefe","#efeefe"],transcribe:["#feebea","#feebec","#feebee","#feeaf0","#feeaf2","#feeaf5","#fee9f9","#fde9fd","#f9eafe"],colour:["#feebe9","#feece5","#feede0","#feeed7","#f7f1d6","#eff3d9","#e5f6df","#dbf8eb","#d6f8f8","#def5fe","#e5f2fe","#ebf0fe","#edeffe","#efeefe","#f1edfe"]},p=["#feeed9","#feeed8","#feeed7","#fdeed6","#fcefd6","#fbefd6","#fbefd6","#faefd6","#f9f0d6"],T={convert:["#138291","#8467bd"],compress:["#2b8748","#138291"],pdf:["#d54322","#a06c10"],edit:["#8567bc","#7b67cd"],transcribe:["#df3140","#9c5cb1"],colour:["#cb4b49","#a06c10","#618110","#138291","#5869ec","#8268bd"]};function C(e,t){return e.name==="light"?t==="menu"?u:m[t]:t==="menu"?e.name==="dark"?b:[e.brand]:t==="compress"?[e.modeCompress,e.modeConvert]:t==="pdf"?[e.modePdf,e.brand]:t==="colour"?e.name==="dark"?g:[e.modeColour,e.violet]:t==="edit"?[e.modeEdit,e.name==="dark"?c:e.violet]:t==="transcribe"?[e.modeTranscribe,e.name==="dark"?l:e.violet]:[e.modeConvert,e.violet]}function y(e,t){if(e.name==="light")return t==="menu"?p:B[t]}function w(e,t){return e.name==="light"?T[t]:C(e,t)}function M(e){return{...e,accent:e.brand,tag:e.brand,label:e.brand}}function R(e,t){let{fg:r,bg:n}=s(e,t);return{...e,accent:r,tag:r,label:r,band:n===""?e.band:n}}function H(e){return e.canvas!==""}function O(e){return e==="dark"?f:e==="light"?o:i}function D(e){return e===""?void 0:e}var _={filled:"\u2501",empty:"\u2501",knob:"\u25CF"};function h(){return process.env.NO_COLOR!==void 0&&process.env.NO_COLOR!==""?!1:process.stdout.isTTY===!0}function F(){h()||(process.env.FORCE_COLOR="0")}export{v as a,x as b,f as c,o as d,i as e,d as f,k as g,E as h,P as i,S as j,s as k,C as l,y as m,w as n,M as o,R as p,H as q,O as r,D as s,_ as t,h as u,F as v};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{o as S,p as B}from"./chunk-WIPP5TWQ.js";import{b as E}from"./chunk-KXKQDFHX.js";import{execFile as X}from"node:child_process";import{randomBytes as Y}from"node:crypto";import{mkdtemp as tt,open as H,readFile as et,rm as U}from"node:fs/promises";import{tmpdir as F}from"node:os";import{join as P}from"node:path";import{promisify as nt}from"node:util";var M=nt(X),J=async()=>({...await import("./paths-EOYKOUBC.js"),...await import("./run-HGZVOXRW.js")}),I,N=t=>t!=="darwin";async function C(t=process.platform){return N(t)?await(await J()).installed("heic")!==void 0:D()}async function D(){if(I!==void 0)return I;try{await M("/usr/bin/sips",["--help"],{timeout:5e3}),I=!0}catch{I=!1}return I}async function O(t,n=process.platform){if(N(n))return rt(t,n);let e=P(F(),`forge-heic-${Y(8).toString("hex")}.png`),i=async()=>{await U(e,{force:!0}).catch(()=>{})};try{return await M("/usr/bin/sips",["-s","format","png",t,"--out",e],{timeout:12e4}),{path:e,cleanup:i}}catch(r){throw await i(),r}}async function W(t,n){let{installed:e,runExtension:i}=await J(),r=await e("heic");if(r===void 0)throw S(t,n);return{ext:r,runExtension:i}}async function rt(t,n){let e=await tt(P(F(),"forge-heic-")),i=async()=>{await U(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await W(t,n),a=P(e,"decoded.rgba"),d=P(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t});return await(await E())(await et(a),{raw:{width:m,height:y,channels:4}}).png().toFile(d),await U(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}var it=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),ot=new Set(["avif","avis"]);async function At(t){let n;try{n=await H(t,"r")}catch{return!1}try{let e=Buffer.alloc(64),{bytesRead:i}=await n.read(e,0,64,0);if(i<12||e.toString("latin1",4,8)!=="ftyp")return!1;let r=Math.min(e.readUInt32BE(0),i),o=[];for(let a=8;a+4<=r;a+=4)o.push(e.toString("latin1",a,a+4));return o.some(a=>ot.has(a))?!1:o.some(a=>it.has(a))}catch{return!1}finally{await n.close().catch(()=>{})}}async function kt(t,n=process.platform){if(N(n)){let{ext:a,runExtension:d}=await W(t,n),m=await d(a,["--info","--in",t],{subject:t});return{width:m.width,height:m.height,hasAlpha:m.hasAlpha??!0}}let{stdout:e}=await M("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",t],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(e)?.[1]??0),r=Number(/pixelHeight:\s*(\d+)/.exec(e)?.[1]??0),o=await at(t);return{width:o?r:i,height:o?i:r,hasAlpha:/hasAlpha:\s*yes/i.test(e)}}function*g(t,n,e){let i=n;for(;i+8<=e;){let r=t.readUInt32BE(i),o=8;if(r===1&&i+16<=e?(r=Number(t.readBigUInt64BE(i+8)),o=16):r===0&&(r=e-i),r<o)return;yield{type:t.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+r,e)},i+=r}}async function at(t){let n=await H(t,"r");try{let e=Buffer.alloc(262144),{bytesRead:i}=await n.read(e,0,e.length,0),r=[...g(e,0,i)].find(l=>l.type==="meta");if(!r)return!1;let o=[...g(e,r.start+4,r.end)],a=o.find(l=>l.type==="pitm"),d=o.find(l=>l.type==="iprp");if(!a||!d)return!1;let m=e.readUInt8(a.start)===0?e.readUInt16BE(a.start+4):e.readUInt32BE(a.start+4),y=[...g(e,d.start,d.end)],s=y.find(l=>l.type==="ipco"),c=y.find(l=>l.type==="ipma");if(!s||!c)return!1;let f=new Map;if([...g(e,s.start,s.end)].forEach((l,x)=>{l.type==="irot"&&f.set(x+1,e.readUInt8(l.start)&3)}),f.size===0)return!1;let h=e.readUInt8(c.start),w=(e.readUInt8(c.start+3)&1)===1,u=c.start+4,p=e.readUInt32BE(u);u+=4;for(let l=0;l<p&&u<c.end;l++){let x=h<1?e.readUInt16BE(u):e.readUInt32BE(u);u+=h<1?2:4;let G=e.readUInt8(u);u+=1;for(let k=0;k<G;k++){let Q=w?e.readUInt16BE(u)&32767:e.readUInt8(u)&127;if(u+=w?2:1,x===m&&(f.get(Q)??0)%2===1)return!0}}return!1}catch{return!1}finally{await n.close().catch(()=>{})}}import{execFile as st}from"node:child_process";import{randomBytes as ct}from"node:crypto";import{copyFile as ft,mkdtemp as _,open as ut,readFile as dt,rm as R}from"node:fs/promises";import{tmpdir as v}from"node:os";import{extname as L,join as b}from"node:path";import{promisify as mt}from"node:util";var z=mt(st),K=async()=>({...await import("./paths-EOYKOUBC.js"),...await import("./run-HGZVOXRW.js")}),A=t=>t!=="darwin",lt={".nef":[".nef",".nrw"],".arw":[".arw",".srf",".sr2"],".rw2":[".rw2",".rwl"],".3fr":[".3fr",".fff"],".dcr":[".dcr",".kdc"]},ht=[["nikon",".nef"],["sony",".arw"],["pentax",".pef"],["ricoh",".pef"],["samsung",".srw"],["hasselblad",".3fr"],["seiko epson",".erf"],["epson",".erf"],["kodak",".dcr"],["eastman kodak",".dcr"],["leaf",".mos"]],wt=new Set([32803,34892]),pt=new Set([32767,32769,32770,34316,34713,65e3,65535]),yt="85c0b687820f11e08111f4ce462b6a48";function T(t,n){let e=(s,c)=>n?s.readUInt16LE(c):s.readUInt16BE(c),i=(s,c)=>n?s.readUInt32LE(c):s.readUInt32BE(c),r={1:1,2:1,3:2,4:4,7:1,13:4};async function o(s){if(s<=0)return;let c=await t(s,2);if(c.length<2)return;let f=e(c,0);if(f===0||f>1e3)return;let h=await t(s+2,f*12+4);if(h.length<f*12+4)return;let w=new Map;for(let u=0;u<f;u++){let p=u*12;w.set(e(h,p),{type:e(h,p+2),count:i(h,p+4),inline:h.subarray(p+8,p+12),offset:i(h,p+8)})}return{entries:w,next:i(h,f*12)}}async function a(s,c=16){if(!s)return[];let f=r[s.type]===2?2:4,h=Math.min(s.count,c),w=h*f<=4?s.inline:await t(s.offset,h*f),u=[];for(let p=0;p<h&&(p+1)*f<=w.length;p++)u.push(f===2?e(w,p*f):i(w,p*f));return u}async function d(s){if(s?.type!==2)return"";let c=Math.min(s.count,64);return(c<=4?s.inline.subarray(0,c):await t(s.offset,c)).toString("latin1").replace(/\0.*$/s,"").trim()}async function m(s){let[c]=await a(s.entries.get(274),1);return c!==void 0&&c>=1&&c<=8?c:1}async function y(s){let c=[s],f=new Set;for(let h=0;c.length>0&&h<12;h++){let w=c.shift(),[u]=await a(w.entries.get(262),1),[p]=await a(w.entries.get(259),1);if(u!==void 0&&wt.has(u)||p!==void 0&&pt.has(p))return!0;for(let l of[...await a(w.entries.get(330),8),w.next]){if(l===0||f.has(l))continue;f.add(l);let x=await o(l);x&&c.push(x)}}return!1}return{directory:o,text:d,orientation:m,hasMosaic:y,u32:i}}function $(t){let n=t.toString("latin1",0,2);return n==="II"?!0:n==="MM"?!1:void 0}async function q(t,n){let e=$(t.subarray(n,n+2));if(e===void 0)return 1;let r=T(async(a,d)=>t.subarray(n+a,n+a+d),e),o=await r.directory(r.u32(t,n+4));return o?r.orientation(o):1}async function gt(t){if(t[0]!==255||t[1]!==216)return 1;let n=2;for(;n+4<=t.length&&t[n]===255;){let e=t[n+1],i=t.readUInt16BE(n+2);if(e===225&&t.toString("latin1",n+4,n+10)==="Exif\0\0")return q(t,n+10);if(e===218)break;n+=2+i}return 1}async function xt(t,n){let e=await t(0,Math.min(n,1048576)),i=[...g(e,0,e.length)].find(r=>r.type==="moov");if(!i)return 1;for(let r of g(e,i.start,i.end)){if(r.type!=="uuid"||e.toString("hex",r.start,r.start+16)!==yt)continue;let o=[...g(e,r.start+16,r.end)].find(a=>a.type==="CMT1");return o?q(e,o.start):1}return 1}async function bt(t,n){if(n.length<92)return 1;let e=n.readUInt32BE(84),i=n.readUInt32BE(88);return e===0||i===0?1:gt(await t(e,Math.min(i,65536)))}async function It(t){let n;try{n=await ut(t,"r")}catch{return}try{let{size:e}=await n.stat(),i=async(f,h)=>{let w=Math.max(0,Math.min(h,e-f)),u=Buffer.alloc(w);return w>0&&await n.read(u,0,w,f),u},r=await i(0,96);if(r.length<16)return;let o=r.toString("latin1",0,4);if(r.toString("latin1",0,15)==="FUJIFILMCCD-RAW")return{ext:".raf",orientation:await bt(i,r)};if(r.toString("latin1",4,12)==="ftypcrx ")return{ext:".cr3",orientation:await xt(i,e)};let a=$(r);if(a===void 0)return;let d=T(i,a),m=await d.directory(d.u32(r,4));if(!m)return;let y=await d.orientation(m);if(o==="IIRO"||o==="IIRS"||o==="MMOR")return{ext:".orf",orientation:y};if(o==="IIU\0")return{ext:".rw2",orientation:y};if(o!=="II*\0"&&o!=="MM\0*")return;if(m.entries.has(50706))return{ext:".dng",orientation:y};if(r.toString("latin1",8,11)==="CR")return{ext:".cr2",orientation:y};let s=(await d.text(m.entries.get(271))).toLowerCase(),c=ht.find(([f])=>s.startsWith(f));return!c||!await d.hasMosaic(m)?void 0:{ext:c[1],orientation:y}}catch{return}finally{await n.close().catch(()=>{})}}async function St(t=process.platform){return A(t)?await(await K()).installed("raw")!==void 0:D()}async function j(t,n){let{installed:e,runExtension:i}=await K(),r=await e("raw");if(r===void 0)throw B(t,n);return{ext:r,runExtension:i}}async function V(t,n,e){let i=L(t).toLowerCase();if((lt[n.ext]??[n.ext]).includes(i))return e(t);let r=await _(b(v(),"forge-raw-"));try{let o=b(r,`photo${n.ext}`);return await ft(t,o),await e(o)}finally{await R(r,{recursive:!0,force:!0}).catch(()=>{})}}async function Tt(t,n,e=process.platform){if(A(e)){let{ext:a,runExtension:d}=await j(t,e),m=await d(a,["--info","--in",t],{subject:t,platform:e});if(!(m.width>0&&m.height>0))throw new Error("the raw extension reported no size");return{width:m.width,height:m.height}}let{stdout:i}=await V(t,n,a=>z("/usr/bin/sips",["-g","typeIdentifier","-g","pixelWidth","-g","pixelHeight",a],{timeout:3e4}));if(!/typeIdentifier:\s*\S*raw-image/.test(i))return;let r=Number(/pixelWidth:\s*(\d+)/.exec(i)?.[1]??0),o=Number(/pixelHeight:\s*(\d+)/.exec(i)?.[1]??0);if(!(r===0||o===0))return n.orientation>=5?{width:o,height:r}:{width:r,height:o}}async function Z(t,n=process.platform){if(A(n))return Et(t,n);if(!await St(n))throw B(t,n);let e=await It(t)??{ext:L(t).toLowerCase(),orientation:1},i=b(v(),`forge-raw-${ct(8).toString("hex")}.png`),r=async()=>{await R(i,{force:!0}).catch(()=>{})};try{return await V(t,e,o=>z("/usr/bin/sips",["-s","format","png",o,"--out",i],{timeout:3e5})),{path:i,cleanup:r}}catch(o){throw await r(),o}}async function Et(t,n){let e=await _(b(v(),"forge-raw-")),i=async()=>{await R(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await j(t,n),a=b(e,"decoded.rgb"),d=b(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t,platform:n});return await(await E())(await dt(a),{raw:{width:m,height:y,channels:3}}).png().toFile(d),await R(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}async function Zt(t,n){if(n==="heic"){if(!await C())throw S(t);return O(t)}return n==="raw"?Z(t):{path:t,cleanup:async()=>{}}}export{C as a,At as b,kt as c,It as d,St as e,Tt as f,Zt as g};
3
+ import{o as S,p as B}from"./chunk-WIPP5TWQ.js";import{b as E}from"./chunk-KXKQDFHX.js";import{execFile as X}from"node:child_process";import{randomBytes as Y}from"node:crypto";import{mkdtemp as tt,open as H,readFile as et,rm as U}from"node:fs/promises";import{tmpdir as F}from"node:os";import{join as P}from"node:path";import{promisify as nt}from"node:util";var M=nt(X),J=async()=>({...await import("./paths-6OENILJ4.js"),...await import("./run-U2CU6VGE.js")}),I,N=t=>t!=="darwin";async function C(t=process.platform){return N(t)?await(await J()).installed("heic")!==void 0:D()}async function D(){if(I!==void 0)return I;try{await M("/usr/bin/sips",["--help"],{timeout:5e3}),I=!0}catch{I=!1}return I}async function O(t,n=process.platform){if(N(n))return rt(t,n);let e=P(F(),`forge-heic-${Y(8).toString("hex")}.png`),i=async()=>{await U(e,{force:!0}).catch(()=>{})};try{return await M("/usr/bin/sips",["-s","format","png",t,"--out",e],{timeout:12e4}),{path:e,cleanup:i}}catch(r){throw await i(),r}}async function W(t,n){let{installed:e,runExtension:i}=await J(),r=await e("heic");if(r===void 0)throw S(t,n);return{ext:r,runExtension:i}}async function rt(t,n){let e=await tt(P(F(),"forge-heic-")),i=async()=>{await U(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await W(t,n),a=P(e,"decoded.rgba"),d=P(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t});return await(await E())(await et(a),{raw:{width:m,height:y,channels:4}}).png().toFile(d),await U(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}var it=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),ot=new Set(["avif","avis"]);async function At(t){let n;try{n=await H(t,"r")}catch{return!1}try{let e=Buffer.alloc(64),{bytesRead:i}=await n.read(e,0,64,0);if(i<12||e.toString("latin1",4,8)!=="ftyp")return!1;let r=Math.min(e.readUInt32BE(0),i),o=[];for(let a=8;a+4<=r;a+=4)o.push(e.toString("latin1",a,a+4));return o.some(a=>ot.has(a))?!1:o.some(a=>it.has(a))}catch{return!1}finally{await n.close().catch(()=>{})}}async function kt(t,n=process.platform){if(N(n)){let{ext:a,runExtension:d}=await W(t,n),m=await d(a,["--info","--in",t],{subject:t});return{width:m.width,height:m.height,hasAlpha:m.hasAlpha??!0}}let{stdout:e}=await M("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",t],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(e)?.[1]??0),r=Number(/pixelHeight:\s*(\d+)/.exec(e)?.[1]??0),o=await at(t);return{width:o?r:i,height:o?i:r,hasAlpha:/hasAlpha:\s*yes/i.test(e)}}function*g(t,n,e){let i=n;for(;i+8<=e;){let r=t.readUInt32BE(i),o=8;if(r===1&&i+16<=e?(r=Number(t.readBigUInt64BE(i+8)),o=16):r===0&&(r=e-i),r<o)return;yield{type:t.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+r,e)},i+=r}}async function at(t){let n=await H(t,"r");try{let e=Buffer.alloc(262144),{bytesRead:i}=await n.read(e,0,e.length,0),r=[...g(e,0,i)].find(l=>l.type==="meta");if(!r)return!1;let o=[...g(e,r.start+4,r.end)],a=o.find(l=>l.type==="pitm"),d=o.find(l=>l.type==="iprp");if(!a||!d)return!1;let m=e.readUInt8(a.start)===0?e.readUInt16BE(a.start+4):e.readUInt32BE(a.start+4),y=[...g(e,d.start,d.end)],s=y.find(l=>l.type==="ipco"),c=y.find(l=>l.type==="ipma");if(!s||!c)return!1;let f=new Map;if([...g(e,s.start,s.end)].forEach((l,x)=>{l.type==="irot"&&f.set(x+1,e.readUInt8(l.start)&3)}),f.size===0)return!1;let h=e.readUInt8(c.start),w=(e.readUInt8(c.start+3)&1)===1,u=c.start+4,p=e.readUInt32BE(u);u+=4;for(let l=0;l<p&&u<c.end;l++){let x=h<1?e.readUInt16BE(u):e.readUInt32BE(u);u+=h<1?2:4;let G=e.readUInt8(u);u+=1;for(let k=0;k<G;k++){let Q=w?e.readUInt16BE(u)&32767:e.readUInt8(u)&127;if(u+=w?2:1,x===m&&(f.get(Q)??0)%2===1)return!0}}return!1}catch{return!1}finally{await n.close().catch(()=>{})}}import{execFile as st}from"node:child_process";import{randomBytes as ct}from"node:crypto";import{copyFile as ft,mkdtemp as _,open as ut,readFile as dt,rm as R}from"node:fs/promises";import{tmpdir as v}from"node:os";import{extname as L,join as b}from"node:path";import{promisify as mt}from"node:util";var z=mt(st),K=async()=>({...await import("./paths-6OENILJ4.js"),...await import("./run-U2CU6VGE.js")}),A=t=>t!=="darwin",lt={".nef":[".nef",".nrw"],".arw":[".arw",".srf",".sr2"],".rw2":[".rw2",".rwl"],".3fr":[".3fr",".fff"],".dcr":[".dcr",".kdc"]},ht=[["nikon",".nef"],["sony",".arw"],["pentax",".pef"],["ricoh",".pef"],["samsung",".srw"],["hasselblad",".3fr"],["seiko epson",".erf"],["epson",".erf"],["kodak",".dcr"],["eastman kodak",".dcr"],["leaf",".mos"]],wt=new Set([32803,34892]),pt=new Set([32767,32769,32770,34316,34713,65e3,65535]),yt="85c0b687820f11e08111f4ce462b6a48";function T(t,n){let e=(s,c)=>n?s.readUInt16LE(c):s.readUInt16BE(c),i=(s,c)=>n?s.readUInt32LE(c):s.readUInt32BE(c),r={1:1,2:1,3:2,4:4,7:1,13:4};async function o(s){if(s<=0)return;let c=await t(s,2);if(c.length<2)return;let f=e(c,0);if(f===0||f>1e3)return;let h=await t(s+2,f*12+4);if(h.length<f*12+4)return;let w=new Map;for(let u=0;u<f;u++){let p=u*12;w.set(e(h,p),{type:e(h,p+2),count:i(h,p+4),inline:h.subarray(p+8,p+12),offset:i(h,p+8)})}return{entries:w,next:i(h,f*12)}}async function a(s,c=16){if(!s)return[];let f=r[s.type]===2?2:4,h=Math.min(s.count,c),w=h*f<=4?s.inline:await t(s.offset,h*f),u=[];for(let p=0;p<h&&(p+1)*f<=w.length;p++)u.push(f===2?e(w,p*f):i(w,p*f));return u}async function d(s){if(s?.type!==2)return"";let c=Math.min(s.count,64);return(c<=4?s.inline.subarray(0,c):await t(s.offset,c)).toString("latin1").replace(/\0.*$/s,"").trim()}async function m(s){let[c]=await a(s.entries.get(274),1);return c!==void 0&&c>=1&&c<=8?c:1}async function y(s){let c=[s],f=new Set;for(let h=0;c.length>0&&h<12;h++){let w=c.shift(),[u]=await a(w.entries.get(262),1),[p]=await a(w.entries.get(259),1);if(u!==void 0&&wt.has(u)||p!==void 0&&pt.has(p))return!0;for(let l of[...await a(w.entries.get(330),8),w.next]){if(l===0||f.has(l))continue;f.add(l);let x=await o(l);x&&c.push(x)}}return!1}return{directory:o,text:d,orientation:m,hasMosaic:y,u32:i}}function $(t){let n=t.toString("latin1",0,2);return n==="II"?!0:n==="MM"?!1:void 0}async function q(t,n){let e=$(t.subarray(n,n+2));if(e===void 0)return 1;let r=T(async(a,d)=>t.subarray(n+a,n+a+d),e),o=await r.directory(r.u32(t,n+4));return o?r.orientation(o):1}async function gt(t){if(t[0]!==255||t[1]!==216)return 1;let n=2;for(;n+4<=t.length&&t[n]===255;){let e=t[n+1],i=t.readUInt16BE(n+2);if(e===225&&t.toString("latin1",n+4,n+10)==="Exif\0\0")return q(t,n+10);if(e===218)break;n+=2+i}return 1}async function xt(t,n){let e=await t(0,Math.min(n,1048576)),i=[...g(e,0,e.length)].find(r=>r.type==="moov");if(!i)return 1;for(let r of g(e,i.start,i.end)){if(r.type!=="uuid"||e.toString("hex",r.start,r.start+16)!==yt)continue;let o=[...g(e,r.start+16,r.end)].find(a=>a.type==="CMT1");return o?q(e,o.start):1}return 1}async function bt(t,n){if(n.length<92)return 1;let e=n.readUInt32BE(84),i=n.readUInt32BE(88);return e===0||i===0?1:gt(await t(e,Math.min(i,65536)))}async function It(t){let n;try{n=await ut(t,"r")}catch{return}try{let{size:e}=await n.stat(),i=async(f,h)=>{let w=Math.max(0,Math.min(h,e-f)),u=Buffer.alloc(w);return w>0&&await n.read(u,0,w,f),u},r=await i(0,96);if(r.length<16)return;let o=r.toString("latin1",0,4);if(r.toString("latin1",0,15)==="FUJIFILMCCD-RAW")return{ext:".raf",orientation:await bt(i,r)};if(r.toString("latin1",4,12)==="ftypcrx ")return{ext:".cr3",orientation:await xt(i,e)};let a=$(r);if(a===void 0)return;let d=T(i,a),m=await d.directory(d.u32(r,4));if(!m)return;let y=await d.orientation(m);if(o==="IIRO"||o==="IIRS"||o==="MMOR")return{ext:".orf",orientation:y};if(o==="IIU\0")return{ext:".rw2",orientation:y};if(o!=="II*\0"&&o!=="MM\0*")return;if(m.entries.has(50706))return{ext:".dng",orientation:y};if(r.toString("latin1",8,11)==="CR")return{ext:".cr2",orientation:y};let s=(await d.text(m.entries.get(271))).toLowerCase(),c=ht.find(([f])=>s.startsWith(f));return!c||!await d.hasMosaic(m)?void 0:{ext:c[1],orientation:y}}catch{return}finally{await n.close().catch(()=>{})}}async function St(t=process.platform){return A(t)?await(await K()).installed("raw")!==void 0:D()}async function j(t,n){let{installed:e,runExtension:i}=await K(),r=await e("raw");if(r===void 0)throw B(t,n);return{ext:r,runExtension:i}}async function V(t,n,e){let i=L(t).toLowerCase();if((lt[n.ext]??[n.ext]).includes(i))return e(t);let r=await _(b(v(),"forge-raw-"));try{let o=b(r,`photo${n.ext}`);return await ft(t,o),await e(o)}finally{await R(r,{recursive:!0,force:!0}).catch(()=>{})}}async function Tt(t,n,e=process.platform){if(A(e)){let{ext:a,runExtension:d}=await j(t,e),m=await d(a,["--info","--in",t],{subject:t,platform:e});if(!(m.width>0&&m.height>0))throw new Error("the raw extension reported no size");return{width:m.width,height:m.height}}let{stdout:i}=await V(t,n,a=>z("/usr/bin/sips",["-g","typeIdentifier","-g","pixelWidth","-g","pixelHeight",a],{timeout:3e4}));if(!/typeIdentifier:\s*\S*raw-image/.test(i))return;let r=Number(/pixelWidth:\s*(\d+)/.exec(i)?.[1]??0),o=Number(/pixelHeight:\s*(\d+)/.exec(i)?.[1]??0);if(!(r===0||o===0))return n.orientation>=5?{width:o,height:r}:{width:r,height:o}}async function Z(t,n=process.platform){if(A(n))return Et(t,n);if(!await St(n))throw B(t,n);let e=await It(t)??{ext:L(t).toLowerCase(),orientation:1},i=b(v(),`forge-raw-${ct(8).toString("hex")}.png`),r=async()=>{await R(i,{force:!0}).catch(()=>{})};try{return await V(t,e,o=>z("/usr/bin/sips",["-s","format","png",o,"--out",i],{timeout:3e5})),{path:i,cleanup:r}}catch(o){throw await r(),o}}async function Et(t,n){let e=await _(b(v(),"forge-raw-")),i=async()=>{await R(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await j(t,n),a=b(e,"decoded.rgb"),d=b(e,"decoded.png"),{width:m,height:y}=await o(r,["--in",t,"--out",a],{subject:t,platform:n});return await(await E())(await dt(a),{raw:{width:m,height:y,channels:3}}).png().toFile(d),await R(a,{force:!0}),{path:d,cleanup:i}}catch(r){throw await i(),r}}async function Zt(t,n){if(n==="heic"){if(!await C())throw S(t);return O(t)}return n==="raw"?Z(t):{path:t,cleanup:async()=>{}}}export{C as a,At as b,kt as c,It as d,St as e,Tt as f,Zt as g};
@@ -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 ne,d as ae,e as ie,g as ue,h as pe}from"./chunk-WC6SJN5Y.js";import{a as ee,b as te,c as re,k as oe,m as N,n as j,o as se}from"./chunk-OK7XOZFO.js";import{a as y}from"./chunk-CKZBBDAW.js";import{c as I}from"./chunk-GSK2A3TN.js";import{e as he}from"./chunk-Y7LOIHFU.js";import{e as ce,f as de,g as fe,h as le,i as me,j as ge}from"./chunk-57M4J2BR.js";import{a as F,c as X,d as Z,e as C,f as _}from"./chunk-PPR7B5AR.js";import{a as m}from"./chunk-XBOMWF34.js";import{d as $}from"./chunk-EEQSUBBL.js";import{a as Q}from"./chunk-LVYQVJOF.js";import{a as H,c as L}from"./chunk-SNDFMJIX.js";import{a as U,c as Y,d as E,e as K}from"./chunk-DZOBIUV6.js";import{H as M,I as q,L as G,b as P,c as w,d as v,r as z,t as k,v as D,wa as V,y as J}from"./chunk-WIPP5TWQ.js";import{a as h,b as W}from"./chunk-J7FLFHQJ.js";import{a as R}from"./chunk-H3DIRJFE.js";import{readFile as Je}from"node:fs/promises";import{dirname as Fe,resolve as Me}from"node:path";async function ye(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=F(o);if(!s.includes(e.target)){t.push({path:o.path,error:D(o,e.target,s)});continue}let n={sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)},a=E(n);Y(a,o.path)&&e.target!==o.format&&(a=K({...n,suffix:e.target})),r.push({op:"convert",sources:[o],outputs:[a],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as Ce}from"node:path";function je(e,r=new Set){let t={path:Ce(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:F(e).filter(n=>!o||C(n)),actions:ue([e],r).filter(n=>!o||n.id===j.id).map(n=>n.id)};if(e.kind==="image")return{...t,width:e.width,height:e.height,...s};if(e.kind==="media"){let n=e.facts;return{...t,...n?{duration:n.duration}:{},...n?.video?{width:n.video.width,height:n.video.height,fps:n.video.fps}:{},...s}}return{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function be(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-M6Z62OWE.js"),o=await t();return{probes:r.sources.map(s=>je(s,o)),failures:r.failures}}import{dirname as Be}from"node:path";var B=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function we(e,r){let t=P(Be(e),B(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function Ie(e,r){let{pct:t,direction:o}=W(e,r);return o==="same"?"same size":`${t}% ${o}`}function xe(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${we(s[0],r)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let i of t.warnings)a.push("",`\u26A0 ${i.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],B(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${Ie(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function Pe(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${Ie(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,B(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function ve(e,r={}){let t=e.results.flatMap(u=>u.job.outputs),o=t.map(u=>w(u)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":we(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)a.push("",`\u26A0 ${u.message}`);return a}function O(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...V(o.error,{debug:r.debug}),"");return t}function ke(){let e=new Set(X()),r=new Set(Z()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function $e(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.duration!==void 0&&t.push($(e.duration)),e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.fps!==void 0&&t.push(`${e.fps} fps`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,B(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Re}from"node:readline";import{PassThrough as Oe}from"node:stream";function Se(e){return new Promise(r=>{let t=Re({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function Ee(e){if(e.stdin)return Se(process.stdin);if(!process.stdin.isTTY)return;let r=new Oe,t=Re({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
4
- `),t.close()}}function T(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Ne(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw M("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ne(o)};if(s.mode==="every-n")return{cuts:ae(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Te(e,r){let t;return()=>r?(t??=Ee({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Ae(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Q(await Je(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let n;try{n=j.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!v(i))throw i;return{failure:{path:e.path,error:i}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function S(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}if(!r&&t.type==="job:phase"&&t.progress.phase==="time"){let o=t.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of 2 \xB7 ${s}`:s);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function We(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ie.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=pe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Ne(e,r.sources))}catch(a){if(!v(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function ze(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!N.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!U(e.output)?Me(e.output):void 0,g=e.output===void 0||u!==void 0?Fe(i.path):Fe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[d]=N.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:g});d?.op==="convert"&&(u!==void 0&&(d.outputs=[u]),e.dpi!==void 0&&(d.options.dpi=e.dpi),o.push(d))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function De(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-EOYKOUBC.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:c,catalogEntry:p}=await import("./catalog-VPSTQTFD.js"),f=p("boost"),x=f&&c(f)?.version,A=L(e.scale,n.version,x);if(A)return b(t,[{path:"",error:A}])}let a=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?te:re,u=[],g=[];for(let c of a.sources){if(!i.appliesTo([c])){g.push({path:c.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let p=ee(c,e.target);if(p){g.push({path:c.path,error:p});continue}u.push(...i.plan([c],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let d=u.length>1;d&&r.onProgress?.({completed:0,total:u.length});let l=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:S(r,d)});return{kind:t,results:l.results,failures:[...a.failures,...g,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function qe(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:he(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[],i=[];for(let p of s.sources)p.kind==="image"&&e.media===void 0?n.push(p):p.kind==="media"&&!e.trim?a.push(p):p.kind==="image"?i.push({path:p.path,error:k("cut","it works on video and sound, not images","Try a video or sound file, such as a MOV, MP4 or WAV.")}):i.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=oe(a,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),d=[...se(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],l=d.length>1;l&&r.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(r,l)});return{kind:e.kind,results:c.results,failures:[...s.failures,...i,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ge(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=f=>f.kind==="document"&&f.format==="pdf",s=C(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(f=>!o(f)):t.sources,i=[],u=[],g=Te(e.passwordStdin??!1,r.interactive??!0);for(let f of n){let x=await Ae(f,e,g,t.roots.get(f.path));"failure"in x?u.push(x.failure):i.push(x.job)}let d=await ye({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),l=[...d.jobs,...i],c=l.length>1;c&&r.onProgress?.({completed:0,total:l.length});let p=await I(l,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,c)});return{kind:"convert",results:p.results,failures:[...t.failures,...u,...d.failures,...p.refusals,...p.unreachable.map(f=>({path:f.job.sources[0].path,error:f.error})),...p.failures],inputBytes:p.inputBytes,outputBytes:p.outputBytes}}async function Ve(e,r={}){try{if(e.kind==="pageop")return await We(e);if(e.kind==="extension-op")return await De(e,r);if(e.kind==="edit")return await qe(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-HMOFTZSG.js");return await t(e)}return e.kind==="compress"?await ze(e,r):await Ge(e,r)}catch(t){if(!v(t))throw t;return b(e.kind,[{path:"",error:t}])}}function He(e,r){let t=T(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(ce(m,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?ve(e):e.results.length===1?xe(e):Pe(e);return{exitCode:t,stdout:o,stderr:O(e.failures,{debug:r.debug})}}function Le(e,r){let t=[{path:"",error:e}],o=T(t);return r.json?{exitCode:o,stdout:[JSON.stringify(de(m,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:O(t,{debug:r.debug})}}async function Ue(e,r){let{runConfig:t}=await import("./config-command-6YUMMZF3.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(me(m,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function Tt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ue(e,t);if(e.kind==="clip"){let{runClipCommand:s}=await import("./clip-command-R2NKW4TI.js");return await s(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-JCTCRPCS.js"),n=await s(m,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:m,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:s}=await import("./entry-TSLQHDP7.js"),n=[];return{exitCode:await s(m,i=>n.push(i)),stdout:n,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-25JOL47P.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(ge(m,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(fe(m,_()))],stderr:[]}:{exitCode:0,stdout:ke(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await be(e.inputs),a=T(n);return t?{exitCode:a,stdout:[JSON.stringify(le(m,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((i,u)=>[...u>0?[""]:[],...$e(i)]),stderr:O(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-APVBMEJQ.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}if(e.kind==="transcribe"){let{runTranscribeCommand:s}=await import("./transcribe-command-2L7F7MCG.js"),n=[],a=[];return{exitCode:await s(e,{out:u=>n.push(u),err:u=>a.push(u)}),stdout:n,stderr:a}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw M("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");return He(await Ve(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return Le(s,{json:t,debug:o})}}export{be as a,Ie as b,T as c,Ve as d,He as e,Tt as f};
3
+ import{c as ne,d as ae,e as ie,g as ue,h as pe}from"./chunk-JOIHR724.js";import{a as ee,b as te,c as re,k as oe,m as N,n as j,o as se}from"./chunk-655UG277.js";import{a as y}from"./chunk-OY4EGSPE.js";import{c as I}from"./chunk-C32KGH4S.js";import{e as he}from"./chunk-HCLEHCAR.js";import{e as ce,f as de,g as fe,h as le,i as me,j as ge}from"./chunk-57M4J2BR.js";import{a as F,c as X,d as Z,e as C,f as _}from"./chunk-BD3OLIVT.js";import{a as m}from"./chunk-3KWAO2N2.js";import{d as $}from"./chunk-EEQSUBBL.js";import{a as Q}from"./chunk-XURW53YK.js";import{a as H,c as L}from"./chunk-2J2PTA5O.js";import{a as U,c as Y,d as E,e as K}from"./chunk-DZOBIUV6.js";import{H as M,I as q,L as G,b as P,c as w,d as v,r as z,t as k,v as D,wa as V,y as J}from"./chunk-WIPP5TWQ.js";import{a as h,b as W}from"./chunk-J7FLFHQJ.js";import{a as R}from"./chunk-H3DIRJFE.js";import{readFile as Je}from"node:fs/promises";import{dirname as Fe,resolve as Me}from"node:path";async function ye(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=F(o);if(!s.includes(e.target)){t.push({path:o.path,error:D(o,e.target,s)});continue}let n={sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)},a=E(n);Y(a,o.path)&&e.target!==o.format&&(a=K({...n,suffix:e.target})),r.push({op:"convert",sources:[o],outputs:[a],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as Ce}from"node:path";function je(e,r=new Set){let t={path:Ce(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:F(e).filter(n=>!o||C(n)),actions:ue([e],r).filter(n=>!o||n.id===j.id).map(n=>n.id)};if(e.kind==="image")return{...t,width:e.width,height:e.height,...s};if(e.kind==="media"){let n=e.facts;return{...t,...n?{duration:n.duration}:{},...n?.video?{width:n.video.width,height:n.video.height,fps:n.video.fps}:{},...s}}return{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function be(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-TNMISSBA.js"),o=await t();return{probes:r.sources.map(s=>je(s,o)),failures:r.failures}}import{dirname as Be}from"node:path";var B=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function we(e,r){let t=P(Be(e),B(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function Ie(e,r){let{pct:t,direction:o}=W(e,r);return o==="same"?"same size":`${t}% ${o}`}function xe(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${we(s[0],r)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let i of t.warnings)a.push("",`\u26A0 ${i.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],B(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${Ie(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function Pe(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${Ie(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,B(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function ve(e,r={}){let t=e.results.flatMap(u=>u.job.outputs),o=t.map(u=>w(u)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":we(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)a.push("",`\u26A0 ${u.message}`);return a}function O(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...V(o.error,{debug:r.debug}),"");return t}function ke(){let e=new Set(X()),r=new Set(Z()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function $e(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.duration!==void 0&&t.push($(e.duration)),e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.fps!==void 0&&t.push(`${e.fps} fps`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,B(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Re}from"node:readline";import{PassThrough as Oe}from"node:stream";function Se(e){return new Promise(r=>{let t=Re({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function Ee(e){if(e.stdin)return Se(process.stdin);if(!process.stdin.isTTY)return;let r=new Oe,t=Re({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
4
+ `),t.close()}}function T(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Ne(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw M("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ne(o)};if(s.mode==="every-n")return{cuts:ae(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Te(e,r){let t;return()=>r?(t??=Ee({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Ae(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Q(await Je(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let n;try{n=j.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!v(i))throw i;return{failure:{path:e.path,error:i}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function S(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}if(!r&&t.type==="job:phase"&&t.progress.phase==="time"){let o=t.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of 2 \xB7 ${s}`:s);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function We(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ie.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=pe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Ne(e,r.sources))}catch(a){if(!v(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function ze(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of t.sources){if(!N.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!U(e.output)?Me(e.output):void 0,g=e.output===void 0||u!==void 0?Fe(i.path):Fe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:t.roots.get(i.path)})),[d]=N.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:g});d?.op==="convert"&&(u!==void 0&&(d.outputs=[u]),e.dpi!==void 0&&(d.options.dpi=e.dpi),o.push(d))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function De(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-6OENILJ4.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:c,catalogEntry:p}=await import("./catalog-FMHWWMUX.js"),f=p("boost"),x=f&&c(f)?.version,A=L(e.scale,n.version,x);if(A)return b(t,[{path:"",error:A}])}let a=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?te:re,u=[],g=[];for(let c of a.sources){if(!i.appliesTo([c])){g.push({path:c.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let p=ee(c,e.target);if(p){g.push({path:c.path,error:p});continue}u.push(...i.plan([c],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let d=u.length>1;d&&r.onProgress?.({completed:0,total:u.length});let l=await I(u,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:S(r,d)});return{kind:t,results:l.results,failures:[...a.failures,...g,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function qe(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:he(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[],i=[];for(let p of s.sources)p.kind==="image"&&e.media===void 0?n.push(p):p.kind==="media"&&!e.trim?a.push(p):p.kind==="image"?i.push({path:p.path,error:k("cut","it works on video and sound, not images","Try a video or sound file, such as a MOV, MP4 or WAV.")}):i.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=oe(a,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),d=[...se(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],l=d.length>1;l&&r.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(r,l)});return{kind:e.kind,results:c.results,failures:[...s.failures,...i,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ge(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=f=>f.kind==="document"&&f.format==="pdf",s=C(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(f=>!o(f)):t.sources,i=[],u=[],g=Te(e.passwordStdin??!1,r.interactive??!0);for(let f of n){let x=await Ae(f,e,g,t.roots.get(f.path));"failure"in x?u.push(x.failure):i.push(x.job)}let d=await ye({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),l=[...d.jobs,...i],c=l.length>1;c&&r.onProgress?.({completed:0,total:l.length});let p=await I(l,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(r,c)});return{kind:"convert",results:p.results,failures:[...t.failures,...u,...d.failures,...p.refusals,...p.unreachable.map(f=>({path:f.job.sources[0].path,error:f.error})),...p.failures],inputBytes:p.inputBytes,outputBytes:p.outputBytes}}async function Ve(e,r={}){try{if(e.kind==="pageop")return await We(e);if(e.kind==="extension-op")return await De(e,r);if(e.kind==="edit")return await qe(e,r);if(e.kind==="preset"){let{runPresetCommand:t}=await import("./preset-command-6A2C6VPQ.js");return await t(e)}return e.kind==="compress"?await ze(e,r):await Ge(e,r)}catch(t){if(!v(t))throw t;return b(e.kind,[{path:"",error:t}])}}function He(e,r){let t=T(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(ce(m,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?ve(e):e.results.length===1?xe(e):Pe(e);return{exitCode:t,stdout:o,stderr:O(e.failures,{debug:r.debug})}}function Le(e,r){let t=[{path:"",error:e}],o=T(t);return r.json?{exitCode:o,stdout:[JSON.stringify(de(m,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:O(t,{debug:r.debug})}}async function Ue(e,r){let{runConfig:t}=await import("./config-command-6YUMMZF3.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(me(m,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function Tt(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ue(e,t);if(e.kind==="clip"){let{runClipCommand:s}=await import("./clip-command-NZNC46H2.js");return await s(e,{...r,json:t,debug:o})}if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-JCTCRPCS.js"),n=await s(m,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:m,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:s}=await import("./entry-2XJD7UCY.js"),n=[];return{exitCode:await s(m,i=>n.push(i)),stdout:n,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-MGPRISPH.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(ge(m,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(fe(m,_()))],stderr:[]}:{exitCode:0,stdout:ke(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await be(e.inputs),a=T(n);return t?{exitCode:a,stdout:[JSON.stringify(le(m,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((i,u)=>[...u>0?[""]:[],...$e(i)]),stderr:O(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-GSDOHCFK.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}if(e.kind==="transcribe"){let{runTranscribeCommand:s}=await import("./transcribe-command-BX2VVUI3.js"),n=[],a=[];return{exitCode:await s(e,{out:u=>n.push(u),err:u=>a.push(u)}),stdout:n,stderr:a}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw M("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");return He(await Ve(e,r),{json:t,debug:o})}catch(s){if(!v(s))throw s;return Le(s,{json:t,debug:o})}}export{be as a,Ie as b,T as c,Ve as d,He as e,Tt as f};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a as h,c as Q}from"./chunk-Q6KQWJ4J.js";import{d as L,f as b,g as X}from"./chunk-Y7LOIHFU.js";import{a as J,b as _,e as R}from"./chunk-PPR7B5AR.js";import{a as U,b as w}from"./chunk-V3I6DSF4.js";import{a as g,d as A}from"./chunk-N6RCLJE6.js";import{f as l}from"./chunk-SNDFMJIX.js";import{d as x,l as I}from"./chunk-THDAQBQ3.js";import{b as $,c as N,d as D,e as d,i as B,m as z}from"./chunk-DZOBIUV6.js";import{H as k,v as C}from"./chunk-WIPP5TWQ.js";import{a as p,b as E,c as j}from"./chunk-H3DIRJFE.js";var O=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0;function Bt(t,e){let n=J(t);return n.includes(e)?void 0:C(t,e,n)}function G(t){return{target:t.target??"png",background:typeof t.background=="string"?t.background:"#ffffff",keepMetadata:t.keepMetadata===!0,...typeof t.output=="string"?{output:t.output}:{},...t.roots instanceof Map?{roots:t.roots}:{},...typeof t.quality=="number"?{quality:t.quality}:{}}}var W=()=>({kind:"select",id:"target",label:"Save as",default:"png",choices:[{value:"png",label:"PNG",hint:p.png.hint}]}),ot=t=>t===1?"sharp":`${t}x`,it=t=>t===1||t===3||t===4?t:2,Jt={id:"boost",label:"Boost resolution",verb:"Boosting",hint:"sharper, at its size or at 2\xD7, 3\xD7 or 4\xD7",requires:"boost",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[{kind:"select",id:"scale",label:"Scale",default:"2",choices:[{value:"1",label:"Sharpen",hint:"the same size, sharper"},{value:"2",label:"2\xD7",hint:"twice the width and height"},{value:"3",label:"3\xD7",hint:"three times the width and height"},{value:"4",label:"4\xD7",hint:"four times the width and height"}]},W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e),i=it(Number(e.scale??2));return n.map(r=>({op:"boost",sources:[r],outputs:[d({sourcePath:r.path,target:o.target,suffix:ot(i),...o.output===void 0?{}:{output:o.output},...o.roots?.get(r.path)===void 0?{}:{sourceRoot:o.roots.get(r.path)}})],scale:i,target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}},_t={id:"remove-background",label:"Remove background",verb:"Removing",hint:"cut out the subject",requires:"remove-background",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e);return n.map(i=>({op:"remove-background",sources:[i],outputs:[d({sourcePath:i.path,target:o.target,suffix:"cutout",...o.output===void 0?{}:{output:o.output},...o.roots?.get(i.path)===void 0?{}:{sourceRoot:o.roots.get(i.path)}})],target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}};var rt=[{degrees:90,label:"90\xB0 right",suffix:"rotated-right"},{degrees:180,label:"180\xB0",suffix:"rotated-180"},{degrees:270,label:"90\xB0 left",suffix:"rotated-left"}],y=t=>t===90||t===180||t===270,Ut=(t,e)=>e===180?{...t}:{width:t.height,height:t.width},M=t=>rt.find(e=>e.degrees===t).suffix;import{dirname as at,join as H}from"node:path";var K="Same location",V="New subfolder";function st(t,e,n){return t===e?K:t===g("Desktop")?"Desktop":t===g("Downloads")?"Downloads":e!==void 0&&n!==void 0&&t===H(e,n)?V:h(t)||t}function T(t,e,n={}){return pt(at(t.path),e,n)}function pt(t,e,{subfolder:n}={}){let o=A(e.defaultOutput),i=e.lastOutput?A(e.lastOutput):void 0,r=f=>({label:st(f,t,n),path:f}),a=[r(o),...i?[r(i)]:[],r(g("Desktop")),...t===void 0?[]:[{label:K,path:t}],r(g("Downloads")),...n!==void 0&&t!==void 0?[{label:V,path:H(t,n)}]:[]],u=new Set,s=a.filter(f=>u.has(f.path)?!1:(u.add(f.path),!0));return{kind:"path",id:"destination",label:"Save to",default:o,presets:s,...i&&i!==o?{last:i}:{}}}var c=t=>typeof t=="string"&&t!==""?t:void 0;var ee=[2,1.5,1.25,.75,.5],ut=.25,dt=4,Y=-16;function q(t){return{wav:"m4a",aiff:"m4a",flac:"m4a",avi:"mp4",ogg:"opus"}[t]??t}var Z=t=>t.length===1&&t[0]?.kind==="media"?t[0]:void 0,ft=t=>t==="cut"||t==="mute"||t==="speed"||t==="resize"||t==="crop"||t==="rotate"||t==="loudness"||t==="extract"||t==="cleanup";function ct(t,e){let n=e.media??{},o=t.facts?.video,i=[];return e.extract&&i.push("audio"),n.cut&&i.push("trimmed"),n.mute&&i.push("muted"),n.cleanup?i.push("cleaned"):n.loudness!==void 0&&i.push("levelled"),n.speed!==void 0&&i.push(`${n.speed}x`),n.fps!==void 0&&i.push(`${n.fps}fps`),n.bitrate!==void 0&&i.push(`${n.bitrate}k`),e.crop&&i.push(I(e.crop.aspect)),e.resize&&i.push(o?b(l(o,e.resize)):"resized"),e.rotate&&i.push(M(e.rotate)),i.length===1?i[0]:"edited"}function mt(t,e){return t.map(n=>{let o=e.target??n.format,i={background:"#ffffff",keepMetadata:!1};e.media&&Object.keys(e.media).length&&(i.media=e.media),e.resize&&(i.resize=e.resize),e.rotate&&(i.rotate=e.rotate);let r=n.facts?.video;e.crop&&r&&(i.crop={aspect:e.crop.aspect,box:e.crop.box??x(r,e.crop.aspect)});let a=e.roots?.get(n.path),u=d({sourcePath:n.path,target:o,suffix:ct(n,e),...e.output===void 0?{}:{output:e.output},...a===void 0?{}:{sourceRoot:a}});return{op:"convert",sources:[n],outputs:[z(u,c(e.destination),c(e.name))],target:o,options:i}})}function S(t){let e={},n=t.cut;return n&&typeof n.start=="number"&&(e.cut={start:n.start,...typeof n.end=="number"?{end:n.end}:{}}),t.mute===!0&&(e.mute=!0),typeof t.speed=="number"&&(e.speed=t.speed),typeof t.fps=="number"&&(e.fps=t.fps),typeof t.bitrate=="number"&&(e.bitrate=t.bitrate),typeof t.loudness=="number"&&(e.loudness=t.loudness),t.cleanup===!0&&(e.cleanup=!0),Object.keys(e).length?e:void 0}var ne={id:"media-edit",label:"Edit",verb:"Editing",hint:"trim, mute, speed, resize, rotate, crop",appliesTo:t=>Z(t)!==void 0,unavailable:()=>"one video or audio file",options:()=>[],plan(t,e){let n=Z(t);if(!n||!ft(e.tool))return[];let o=e.tool,i={...typeof e.output=="string"?{output:e.output}:{},destination:e.destination,name:e.name};if(o==="cut"){let r=S(e)?.cut;if(!r)return[];i.media={cut:r}}if(o==="mute"&&(i.media={mute:!0}),o==="speed"){let r=e.speed;if(typeof r!="number"||r===1||r<ut||r>dt)return[];i.media={speed:r}}if(o==="loudness"&&(i.media={loudness:typeof e.loudness=="number"?e.loudness:Y}),o==="cleanup"){if(!n.facts?.audio)return[];i.media={cleanup:!0,loudness:Y}}if(o==="extract"){let r=n.facts?.audio;if(!r||!n.facts?.video)return[];i.extract=!0,i.target=Q(r.codec)}if(o==="resize"){if(typeof e.resize!="object"||e.resize===null)return[];i.resize=e.resize}if(o==="rotate"){if(!n.facts?.video||!y(e.turn))return[];i.rotate=e.turn}if(o==="crop"){let r=e.crop;if(!r?.aspect||!n.facts?.video)return[];i.crop=r}return mt([n],i)}};import{dirname as lt,join as gt}from"node:path";var ht=t=>p[t.format].media==="video",bt=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,yt=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,St="-small",m={min:30,max:100,step:35},kt=t=>{let e=Math.ceil((t-m.min)/m.step);return Math.min(m.max,m.min+Math.max(0,e)*m.step)},fe={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=bt(t);if(e!==void 0){let o=p[e.format];return o.lossy||o.quantisable===!0}return(yt(t)?.images?.compressible??0)>0},options(t,e,n){let o=t[0];if(!o)return[];let i=[{kind:"select",id:"mode",label:`Compress ${h(o.path)??"this file"}`,choices:[o.kind==="media"?{value:"quality",label:"By quality"}:{value:"quality",label:"By quality",hint:"pick a level, see the result"},{value:"size",label:"To a target size",hint:"smallest quality that fits"}],default:"quality"}];if(e.mode==="quality"&&o.kind==="media"&&!ht(o))i.push({kind:"slider",id:"bitrate",label:"Quality",min:32,max:320,step:32,default:96});else if(e.mode==="quality"){let r=o.kind==="image"&&p[o.format].quantisable===!0;i.push(r?{kind:"slider",id:"quality",label:"Quality",...m,default:kt(n.quality),points:!0}:{kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality})}else if(e.mode==="size")i.push({kind:"text",id:"size",label:"Target size",placeholder:"e.g. 500kb or 2mb"});else return i;return i.push(T(o,n)),i},plan(t,e){let n=e.mode;if(n!=="quality"&&n!=="size")throw k(`compressAction.plan() needs a mode of "quality" or "size", got ${JSON.stringify(n)}.`,"This is a caller bug, not a user-facing condition: walk options() before calling plan().");let o=t[0];if(!o)return[];let i=(h(o.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:lt(o.path),a=o.kind==="media"?q(o.format):o.format,u=gt(r,$(i,`${St}${j(a)}`)),s=o.kind==="media"?S(e):void 0;return[{op:"convert",sources:[o],target:a,outputs:[u],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...s?{media:s}:{}}}]}};function xt(t){return{kind:"select",id:"pages",label:"Pages",default:"all",choices:[{value:"all",label:"All pages",hint:`${t.pages} pages`},{value:"first",label:"First page only"},{value:"choose",label:"Choose pages",hint:"pick which ones"}]}}function It(){return{kind:"select",id:"dpi",label:"Resolution",default:"150",choices:[{value:"72",label:"72 dpi",hint:"screen"},{value:"150",label:"150 dpi",badge:"default"},{value:"300",label:"300 dpi",hint:"print"}]}}function zt(t,e){return Array.isArray(e)?w(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?w(U(e,t.pages)):Array.from({length:t.pages},(n,o)=>o)}function Ot(t,e){let n=p[t.format].lossy,o=p[e].lossy;if(n&&!o)return{hint:"likely bigger",tone:"warn"};if(!n&&o)return{hint:"likely smaller",tone:"ok"}}function Mt(t){let e=_(t).filter(o=>o.id!==t.format),n=e[0];return{kind:"select",id:"target",label:`Convert ${p[t.format].label} to`,choices:e.map(o=>{let i=Ot(t,o.id);return{value:o.id,label:o.label,hint:i?.hint??o.hint,...i===void 0?{}:{tone:i.tone}}}),default:n?n.id:""}}function Tt(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var Ft=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function At(t){let e=t.target,n=typeof e=="string"?E(e):void 0;if(!n)throw k(`convertAction.plan() requires a valid target format, got ${JSON.stringify(e)}.`,"This is a caller bug, not a user-facing condition: call options() and pass one of the target select choices before calling plan().");return n}var ke={id:"convert",label:"Convert",verb:"Converting",hint:"to another format",appliesTo:t=>t.length>=1,options(t,e,n){let o=t[0];if(!o)return[];let i=[Mt(o)],r=e.target;if(typeof r!="string")return i;o.kind==="document"&&R(r)&&i.push(xt(o),It());let a=p[r];return o.kind==="media"?a?.media==="sound"&&a.lossy&&i.push(Tt(r)):a?.lossy&&a.media===void 0&&i.push({kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality}),i.push(T(o,n)),i},plan(t,e){let n=t[0];if(!n)return[];let o=At(e),i=o.id,r={background:typeof e.background=="string"?e.background:"#ffffff",keepMetadata:e.keepMetadata===!0};if(o.lossy&&typeof e.quality=="number"&&(r.quality=e.quality),n.kind==="media"){let s=S(e);s&&(r.media=s),Ft(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&R(i)){let s=Number(e.dpi);r.dpi=Number.isFinite(s)&&s>0?s:150;let f=zt(n,e.pages);r.pages=f;let et=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,nt=B(n.path,f,i,a,et);return[{op:"convert",sources:[n],outputs:nt,target:i,options:r}]}let u=D({sourcePath:n.path,target:i,...a===void 0?{}:{output:`${a}/`}});return N(u,n.path)&&(u=d({sourcePath:n.path,target:i,suffix:i,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[u],target:i,options:r}]}};function Rt(t,e){if(!e.rotate)return v(t,e);let n=M(e.rotate);return e.trim||e.crop||e.resize?`${v(t,e)}-${n}`:n}function v(t,e){if(e.crop){let n=I(e.crop.aspect);if(!e.resize)return n;let o=e.crop.box??x(t,e.crop.aspect);return`${n}-${b(l(o,e.resize))}`}return e.trim&&e.resize?`trimmed-${X(e.resize)}`:e.resize?b(l(t,e.resize)):"trimmed"}function wt(t,e){if(e.trim&&e.crop)throw new Error("planEdit cannot trim and crop the same image");return t.map(n=>{let o=e.target??L(n),i={background:e.background,keepMetadata:e.keepMetadata,...e.quality===void 0?{}:{quality:e.quality},...e.trim?{trim:!0}:{},...e.resize?{resize:e.resize}:{},...e.crop?{crop:e.crop}:{},...e.rotate?{rotate:e.rotate}:{}},r=e.roots?.get(n.path),a=d({sourcePath:n.path,target:o,suffix:Rt(n,e),...e.output===void 0?{}:{output:e.output},...r===void 0?{}:{sourceRoot:r}});return{op:"convert",sources:[n],outputs:[z(a,c(e.destination),c(e.name))],target:o,options:i}})}var P=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0,Pt=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t),tt=t=>typeof t=="object"&&t!==null&&"aspect"in t&&typeof t.aspect=="object"&&t.aspect!==null&&"w"in t.aspect&&"h"in t.aspect;function F(t,e,n,o){return{id:t,label:e,verb:n,hint:o,appliesTo:i=>P(i)?.every(r=>t==="resize"||r.frames<=1)===!0,unavailable:i=>P(i)?"animated":"images only",options:()=>[],plan(i,r){let a=P(i);return a?t==="crop"&&!tt(r.crop)?[]:t==="turn"&&!y(r.turn)?[]:wt(a,{trim:t==="trim"||r.trim===!0,...y(r.turn)?{rotate:r.turn}:{},...Pt(r.resize)?{resize:r.resize}:{},...tt(r.crop)?{crop:r.crop}:{},...typeof r.target=="string"?{target:r.target}:{},...typeof r.output=="string"?{output:r.output}:{},...r.roots instanceof Map?{roots:r.roots}:{},destination:r.destination,name:r.name,background:typeof r.background=="string"?r.background:"#ffffff",keepMetadata:r.keepMetadata===!0,...typeof r.quality=="number"?{quality:r.quality}:{}}):[]}}}var Fe=F("trim","Trim edges","Trimming edges","cut empty borders"),Ae=F("resize","Resize","Resizing","smaller or larger"),Re=F("crop","Crop to shape","Cropping","change the shape"),we=F("turn","Rotate","Rotating","turn it");export{Bt as a,Jt as b,_t as c,V as d,T as e,pt as f,c as g,rt as h,Ut as i,ee as j,mt as k,ne as l,fe as m,ke as n,wt as o,Fe as p,Ae as q,Re as r,we as s};
3
+ import{a as h,c as Q}from"./chunk-Q6KQWJ4J.js";import{d as L,f as b,g as X}from"./chunk-HCLEHCAR.js";import{a as J,b as _,e as R}from"./chunk-BD3OLIVT.js";import{a as U,b as w}from"./chunk-WZWK3PEZ.js";import{a as g,d as A}from"./chunk-N6RCLJE6.js";import{f as l}from"./chunk-2J2PTA5O.js";import{d as x,l as I}from"./chunk-THDAQBQ3.js";import{b as $,c as N,d as D,e as d,i as B,m as z}from"./chunk-DZOBIUV6.js";import{H as k,v as C}from"./chunk-WIPP5TWQ.js";import{a as p,b as E,c as j}from"./chunk-H3DIRJFE.js";var O=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0;function Bt(t,e){let n=J(t);return n.includes(e)?void 0:C(t,e,n)}function G(t){return{target:t.target??"png",background:typeof t.background=="string"?t.background:"#ffffff",keepMetadata:t.keepMetadata===!0,...typeof t.output=="string"?{output:t.output}:{},...t.roots instanceof Map?{roots:t.roots}:{},...typeof t.quality=="number"?{quality:t.quality}:{}}}var W=()=>({kind:"select",id:"target",label:"Save as",default:"png",choices:[{value:"png",label:"PNG",hint:p.png.hint}]}),ot=t=>t===1?"sharp":`${t}x`,it=t=>t===1||t===3||t===4?t:2,Jt={id:"boost",label:"Boost resolution",verb:"Boosting",hint:"sharper, at its size or at 2\xD7, 3\xD7 or 4\xD7",requires:"boost",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[{kind:"select",id:"scale",label:"Scale",default:"2",choices:[{value:"1",label:"Sharpen",hint:"the same size, sharper"},{value:"2",label:"2\xD7",hint:"twice the width and height"},{value:"3",label:"3\xD7",hint:"three times the width and height"},{value:"4",label:"4\xD7",hint:"four times the width and height"}]},W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e),i=it(Number(e.scale??2));return n.map(r=>({op:"boost",sources:[r],outputs:[d({sourcePath:r.path,target:o.target,suffix:ot(i),...o.output===void 0?{}:{output:o.output},...o.roots?.get(r.path)===void 0?{}:{sourceRoot:o.roots.get(r.path)}})],scale:i,target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}},_t={id:"remove-background",label:"Remove background",verb:"Removing",hint:"cut out the subject",requires:"remove-background",appliesTo:t=>O(t)!==void 0,unavailable:()=>"images only",options:()=>[W()],plan(t,e){let n=O(t);if(!n)return[];let o=G(e);return n.map(i=>({op:"remove-background",sources:[i],outputs:[d({sourcePath:i.path,target:o.target,suffix:"cutout",...o.output===void 0?{}:{output:o.output},...o.roots?.get(i.path)===void 0?{}:{sourceRoot:o.roots.get(i.path)}})],target:o.target,options:{background:o.background,keepMetadata:o.keepMetadata,...o.quality===void 0?{}:{quality:o.quality}}}))}};var rt=[{degrees:90,label:"90\xB0 right",suffix:"rotated-right"},{degrees:180,label:"180\xB0",suffix:"rotated-180"},{degrees:270,label:"90\xB0 left",suffix:"rotated-left"}],y=t=>t===90||t===180||t===270,Ut=(t,e)=>e===180?{...t}:{width:t.height,height:t.width},M=t=>rt.find(e=>e.degrees===t).suffix;import{dirname as at,join as H}from"node:path";var K="Same location",V="New subfolder";function st(t,e,n){return t===e?K:t===g("Desktop")?"Desktop":t===g("Downloads")?"Downloads":e!==void 0&&n!==void 0&&t===H(e,n)?V:h(t)||t}function T(t,e,n={}){return pt(at(t.path),e,n)}function pt(t,e,{subfolder:n}={}){let o=A(e.defaultOutput),i=e.lastOutput?A(e.lastOutput):void 0,r=f=>({label:st(f,t,n),path:f}),a=[r(o),...i?[r(i)]:[],r(g("Desktop")),...t===void 0?[]:[{label:K,path:t}],r(g("Downloads")),...n!==void 0&&t!==void 0?[{label:V,path:H(t,n)}]:[]],u=new Set,s=a.filter(f=>u.has(f.path)?!1:(u.add(f.path),!0));return{kind:"path",id:"destination",label:"Save to",default:o,presets:s,...i&&i!==o?{last:i}:{}}}var c=t=>typeof t=="string"&&t!==""?t:void 0;var ee=[2,1.5,1.25,.75,.5],ut=.25,dt=4,Y=-16;function q(t){return{wav:"m4a",aiff:"m4a",flac:"m4a",avi:"mp4",ogg:"opus"}[t]??t}var Z=t=>t.length===1&&t[0]?.kind==="media"?t[0]:void 0,ft=t=>t==="cut"||t==="mute"||t==="speed"||t==="resize"||t==="crop"||t==="rotate"||t==="loudness"||t==="extract"||t==="cleanup";function ct(t,e){let n=e.media??{},o=t.facts?.video,i=[];return e.extract&&i.push("audio"),n.cut&&i.push("trimmed"),n.mute&&i.push("muted"),n.cleanup?i.push("cleaned"):n.loudness!==void 0&&i.push("levelled"),n.speed!==void 0&&i.push(`${n.speed}x`),n.fps!==void 0&&i.push(`${n.fps}fps`),n.bitrate!==void 0&&i.push(`${n.bitrate}k`),e.crop&&i.push(I(e.crop.aspect)),e.resize&&i.push(o?b(l(o,e.resize)):"resized"),e.rotate&&i.push(M(e.rotate)),i.length===1?i[0]:"edited"}function mt(t,e){return t.map(n=>{let o=e.target??n.format,i={background:"#ffffff",keepMetadata:!1};e.media&&Object.keys(e.media).length&&(i.media=e.media),e.resize&&(i.resize=e.resize),e.rotate&&(i.rotate=e.rotate);let r=n.facts?.video;e.crop&&r&&(i.crop={aspect:e.crop.aspect,box:e.crop.box??x(r,e.crop.aspect)});let a=e.roots?.get(n.path),u=d({sourcePath:n.path,target:o,suffix:ct(n,e),...e.output===void 0?{}:{output:e.output},...a===void 0?{}:{sourceRoot:a}});return{op:"convert",sources:[n],outputs:[z(u,c(e.destination),c(e.name))],target:o,options:i}})}function S(t){let e={},n=t.cut;return n&&typeof n.start=="number"&&(e.cut={start:n.start,...typeof n.end=="number"?{end:n.end}:{}}),t.mute===!0&&(e.mute=!0),typeof t.speed=="number"&&(e.speed=t.speed),typeof t.fps=="number"&&(e.fps=t.fps),typeof t.bitrate=="number"&&(e.bitrate=t.bitrate),typeof t.loudness=="number"&&(e.loudness=t.loudness),t.cleanup===!0&&(e.cleanup=!0),Object.keys(e).length?e:void 0}var ne={id:"media-edit",label:"Edit",verb:"Editing",hint:"trim, mute, speed, resize, rotate, crop",appliesTo:t=>Z(t)!==void 0,unavailable:()=>"one video or audio file",options:()=>[],plan(t,e){let n=Z(t);if(!n||!ft(e.tool))return[];let o=e.tool,i={...typeof e.output=="string"?{output:e.output}:{},destination:e.destination,name:e.name};if(o==="cut"){let r=S(e)?.cut;if(!r)return[];i.media={cut:r}}if(o==="mute"&&(i.media={mute:!0}),o==="speed"){let r=e.speed;if(typeof r!="number"||r===1||r<ut||r>dt)return[];i.media={speed:r}}if(o==="loudness"&&(i.media={loudness:typeof e.loudness=="number"?e.loudness:Y}),o==="cleanup"){if(!n.facts?.audio)return[];i.media={cleanup:!0,loudness:Y}}if(o==="extract"){let r=n.facts?.audio;if(!r||!n.facts?.video)return[];i.extract=!0,i.target=Q(r.codec)}if(o==="resize"){if(typeof e.resize!="object"||e.resize===null)return[];i.resize=e.resize}if(o==="rotate"){if(!n.facts?.video||!y(e.turn))return[];i.rotate=e.turn}if(o==="crop"){let r=e.crop;if(!r?.aspect||!n.facts?.video)return[];i.crop=r}return mt([n],i)}};import{dirname as lt,join as gt}from"node:path";var ht=t=>p[t.format].media==="video",bt=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,yt=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,St="-small",m={min:30,max:100,step:35},kt=t=>{let e=Math.ceil((t-m.min)/m.step);return Math.min(m.max,m.min+Math.max(0,e)*m.step)},fe={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=bt(t);if(e!==void 0){let o=p[e.format];return o.lossy||o.quantisable===!0}return(yt(t)?.images?.compressible??0)>0},options(t,e,n){let o=t[0];if(!o)return[];let i=[{kind:"select",id:"mode",label:`Compress ${h(o.path)??"this file"}`,choices:[o.kind==="media"?{value:"quality",label:"By quality"}:{value:"quality",label:"By quality",hint:"pick a level, see the result"},{value:"size",label:"To a target size",hint:"smallest quality that fits"}],default:"quality"}];if(e.mode==="quality"&&o.kind==="media"&&!ht(o))i.push({kind:"slider",id:"bitrate",label:"Quality",min:32,max:320,step:32,default:96});else if(e.mode==="quality"){let r=o.kind==="image"&&p[o.format].quantisable===!0;i.push(r?{kind:"slider",id:"quality",label:"Quality",...m,default:kt(n.quality),points:!0}:{kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality})}else if(e.mode==="size")i.push({kind:"text",id:"size",label:"Target size",placeholder:"e.g. 500kb or 2mb"});else return i;return i.push(T(o,n)),i},plan(t,e){let n=e.mode;if(n!=="quality"&&n!=="size")throw k(`compressAction.plan() needs a mode of "quality" or "size", got ${JSON.stringify(n)}.`,"This is a caller bug, not a user-facing condition: walk options() before calling plan().");let o=t[0];if(!o)return[];let i=(h(o.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:lt(o.path),a=o.kind==="media"?q(o.format):o.format,u=gt(r,$(i,`${St}${j(a)}`)),s=o.kind==="media"?S(e):void 0;return[{op:"convert",sources:[o],target:a,outputs:[u],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...s?{media:s}:{}}}]}};function xt(t){return{kind:"select",id:"pages",label:"Pages",default:"all",choices:[{value:"all",label:"All pages",hint:`${t.pages} pages`},{value:"first",label:"First page only"},{value:"choose",label:"Choose pages",hint:"pick which ones"}]}}function It(){return{kind:"select",id:"dpi",label:"Resolution",default:"150",choices:[{value:"72",label:"72 dpi",hint:"screen"},{value:"150",label:"150 dpi",badge:"default"},{value:"300",label:"300 dpi",hint:"print"}]}}function zt(t,e){return Array.isArray(e)?w(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?w(U(e,t.pages)):Array.from({length:t.pages},(n,o)=>o)}function Ot(t,e){let n=p[t.format].lossy,o=p[e].lossy;if(n&&!o)return{hint:"likely bigger",tone:"warn"};if(!n&&o)return{hint:"likely smaller",tone:"ok"}}function Mt(t){let e=_(t).filter(o=>o.id!==t.format),n=e[0];return{kind:"select",id:"target",label:`Convert ${p[t.format].label} to`,choices:e.map(o=>{let i=Ot(t,o.id);return{value:o.id,label:o.label,hint:i?.hint??o.hint,...i===void 0?{}:{tone:i.tone}}}),default:n?n.id:""}}function Tt(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var Ft=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function At(t){let e=t.target,n=typeof e=="string"?E(e):void 0;if(!n)throw k(`convertAction.plan() requires a valid target format, got ${JSON.stringify(e)}.`,"This is a caller bug, not a user-facing condition: call options() and pass one of the target select choices before calling plan().");return n}var ke={id:"convert",label:"Convert",verb:"Converting",hint:"to another format",appliesTo:t=>t.length>=1,options(t,e,n){let o=t[0];if(!o)return[];let i=[Mt(o)],r=e.target;if(typeof r!="string")return i;o.kind==="document"&&R(r)&&i.push(xt(o),It());let a=p[r];return o.kind==="media"?a?.media==="sound"&&a.lossy&&i.push(Tt(r)):a?.lossy&&a.media===void 0&&i.push({kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:n.quality}),i.push(T(o,n)),i},plan(t,e){let n=t[0];if(!n)return[];let o=At(e),i=o.id,r={background:typeof e.background=="string"?e.background:"#ffffff",keepMetadata:e.keepMetadata===!0};if(o.lossy&&typeof e.quality=="number"&&(r.quality=e.quality),n.kind==="media"){let s=S(e);s&&(r.media=s),Ft(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&R(i)){let s=Number(e.dpi);r.dpi=Number.isFinite(s)&&s>0?s:150;let f=zt(n,e.pages);r.pages=f;let et=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,nt=B(n.path,f,i,a,et);return[{op:"convert",sources:[n],outputs:nt,target:i,options:r}]}let u=D({sourcePath:n.path,target:i,...a===void 0?{}:{output:`${a}/`}});return N(u,n.path)&&(u=d({sourcePath:n.path,target:i,suffix:i,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[u],target:i,options:r}]}};function Rt(t,e){if(!e.rotate)return v(t,e);let n=M(e.rotate);return e.trim||e.crop||e.resize?`${v(t,e)}-${n}`:n}function v(t,e){if(e.crop){let n=I(e.crop.aspect);if(!e.resize)return n;let o=e.crop.box??x(t,e.crop.aspect);return`${n}-${b(l(o,e.resize))}`}return e.trim&&e.resize?`trimmed-${X(e.resize)}`:e.resize?b(l(t,e.resize)):"trimmed"}function wt(t,e){if(e.trim&&e.crop)throw new Error("planEdit cannot trim and crop the same image");return t.map(n=>{let o=e.target??L(n),i={background:e.background,keepMetadata:e.keepMetadata,...e.quality===void 0?{}:{quality:e.quality},...e.trim?{trim:!0}:{},...e.resize?{resize:e.resize}:{},...e.crop?{crop:e.crop}:{},...e.rotate?{rotate:e.rotate}:{}},r=e.roots?.get(n.path),a=d({sourcePath:n.path,target:o,suffix:Rt(n,e),...e.output===void 0?{}:{output:e.output},...r===void 0?{}:{sourceRoot:r}});return{op:"convert",sources:[n],outputs:[z(a,c(e.destination),c(e.name))],target:o,options:i}})}var P=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0,Pt=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t),tt=t=>typeof t=="object"&&t!==null&&"aspect"in t&&typeof t.aspect=="object"&&t.aspect!==null&&"w"in t.aspect&&"h"in t.aspect;function F(t,e,n,o){return{id:t,label:e,verb:n,hint:o,appliesTo:i=>P(i)?.every(r=>t==="resize"||r.frames<=1)===!0,unavailable:i=>P(i)?"animated":"images only",options:()=>[],plan(i,r){let a=P(i);return a?t==="crop"&&!tt(r.crop)?[]:t==="turn"&&!y(r.turn)?[]:wt(a,{trim:t==="trim"||r.trim===!0,...y(r.turn)?{rotate:r.turn}:{},...Pt(r.resize)?{resize:r.resize}:{},...tt(r.crop)?{crop:r.crop}:{},...typeof r.target=="string"?{target:r.target}:{},...typeof r.output=="string"?{output:r.output}:{},...r.roots instanceof Map?{roots:r.roots}:{},destination:r.destination,name:r.name,background:typeof r.background=="string"?r.background:"#ffffff",keepMetadata:r.keepMetadata===!0,...typeof r.quality=="number"?{quality:r.quality}:{}}):[]}}}var Fe=F("trim","Trim edges","Trimming edges","cut empty borders"),Ae=F("resize","Resize","Resizing","smaller or larger"),Re=F("crop","Crop to shape","Cropping","change the shape"),we=F("turn","Rotate","Rotating","turn it");export{Bt as a,Jt as b,_t as c,V as d,T as e,pt as f,c as g,rt as h,Ut as i,ee as j,mt as k,ne as l,fe as m,ke as n,wt as o,Fe as p,Ae as q,Re as r,we as s};