forge-terminal 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -6
- package/dist/chunks/{about-credits-4DHA4HMT.js → about-credits-32BUKO4K.js} +1 -1
- package/dist/chunks/{args-5CQKOHYO.js → args-ZVZQR23M.js} +1 -1
- package/dist/chunks/{boot-XX2TLD3Q.js → boot-2YFTQOMG.js} +1 -1
- package/dist/chunks/{chunk-U3D3EU33.js → chunk-3374PCO5.js} +1 -1
- package/dist/chunks/{chunk-6FXF6ALB.js → chunk-6KUWZQGG.js} +1 -1
- package/dist/chunks/{chunk-GYERZAZU.js → chunk-6MWJO3GB.js} +2 -2
- package/dist/chunks/{chunk-RM3XA72H.js → chunk-6PEIZZNE.js} +1 -1
- package/dist/chunks/{chunk-JMIKUWLY.js → chunk-7FW7JX74.js} +2 -2
- package/dist/chunks/{chunk-NRMLO5TP.js → chunk-7XDMC7FL.js} +1 -1
- package/dist/chunks/{chunk-UGYBXR4V.js → chunk-AR3M2PLK.js} +1 -1
- package/dist/chunks/{chunk-7MC3LDNP.js → chunk-ASLKQXZ2.js} +1 -1
- package/dist/chunks/{chunk-VDQMK2B2.js → chunk-BKLPRILS.js} +1 -1
- package/dist/chunks/{chunk-6HQKTDGG.js → chunk-FBVRKMAF.js} +1 -1
- package/dist/chunks/{chunk-PUGNBNSV.js → chunk-GHYODKA3.js} +1 -1
- package/dist/chunks/{chunk-WMK3IKW6.js → chunk-GVVQP3LF.js} +1 -1
- package/dist/chunks/{chunk-RRVD63NF.js → chunk-K253E723.js} +1 -1
- package/dist/chunks/chunk-L44NRTP4.js +3 -0
- package/dist/chunks/{chunk-L57UZTYE.js → chunk-NDYMC3HY.js} +2 -2
- package/dist/chunks/{chunk-MPSLPE4C.js → chunk-OQBIYNGK.js} +1 -1
- package/dist/chunks/{chunk-4YK4XWYS.js → chunk-QQV7CCAY.js} +1 -1
- package/dist/chunks/{chunk-SUB2JM7G.js → chunk-RCWFUBTG.js} +1 -1
- package/dist/chunks/{chunk-P6JX5ZQT.js → chunk-TGC24JEW.js} +1 -1
- package/dist/chunks/{chunk-X6PZIFFX.js → chunk-VJMOZPHW.js} +1 -1
- package/dist/chunks/chunk-YPAFAG4W.js +6 -0
- package/dist/chunks/{chunk-AET63NOB.js → chunk-YRXJDFP3.js} +1 -1
- package/dist/chunks/{clip-command-3CMQ6A5D.js → clip-command-MDSM6KJP.js} +1 -1
- package/dist/chunks/{colour-VBHJAKAX.js → colour-2MYODUDY.js} +1 -1
- package/dist/chunks/{entry-SOHEQPXT.js → entry-BZYPZONY.js} +1 -1
- package/dist/chunks/{execute-KTLXJTU2.js → execute-7M6WA4W7.js} +1 -1
- package/dist/chunks/{extensions-YF2KGD66.js → extensions-E3OUBT36.js} +1 -1
- package/dist/chunks/{extensions-command-VT4M2JQW.js → extensions-command-JZSOQJEV.js} +1 -1
- package/dist/chunks/{ffmpeg-Q2WJH2OP.js → ffmpeg-KDZEPLNA.js} +1 -1
- package/dist/chunks/{launch-SOQTCV2D.js → launch-VNW4YQ4Z.js} +5 -5
- package/dist/chunks/{manager-HBAXHJL4.js → manager-L753MI7U.js} +1 -1
- package/dist/chunks/{needed-GMZEKBH4.js → needed-DYERJ72M.js} +1 -1
- package/dist/chunks/{own-IICGHC4K.js → own-2QGMHSKL.js} +1 -1
- package/dist/chunks/{preset-command-4OVFEH7Y.js → preset-command-UNMXHW5A.js} +1 -1
- package/dist/chunks/{registry-TO6HJQJ4.js → registry-RS7LQ3UA.js} +1 -1
- package/dist/chunks/server-PIXRL5PA.js +77 -0
- package/dist/chunks/{theme-ISNQEBTS.js → theme-P3ZE2ZYB.js} +1 -1
- package/dist/chunks/{transcribe-QC2E7ETQ.js → transcribe-KXQXEVBJ.js} +1 -1
- package/dist/chunks/transcribe-command-JHWN4RWU.js +3 -0
- package/dist/chunks/{update-note-T4LVCD25.js → update-note-CY3LCBCJ.js} +1 -1
- package/dist/chunks/{watch-command-EYEZKROF.js → watch-command-QGVXM23I.js} +1 -1
- package/dist/index.js +6 -6
- package/package.json +3 -7
- package/skills/forge/SKILL.md +67 -4
- package/dist/chunks/chunk-GBA5DFEO.js +0 -6
- package/dist/chunks/server-6275TY3O.js +0 -74
- package/dist/chunks/transcribe-command-GAKYFBWQ.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.
|
|
53
|
+
# 0.5.9
|
|
54
54
|
|
|
55
55
|
forge photo.jpg --to webp
|
|
56
56
|
```
|
|
@@ -1084,7 +1084,7 @@ Claude Desktop and Cursor:
|
|
|
1084
1084
|
{ "mcpServers": { "forge": { "command": "forge", "args": ["mcp"] } } }
|
|
1085
1085
|
```
|
|
1086
1086
|
|
|
1087
|
-
|
|
1087
|
+
Eleven tools, deliberately few:
|
|
1088
1088
|
|
|
1089
1089
|
| Tool | Does |
|
|
1090
1090
|
| --- | --- |
|
|
@@ -1097,10 +1097,15 @@ Nine tools, deliberately few:
|
|
|
1097
1097
|
| `forge_palette` | an image's main colours with their shares; `inside` gives one colour's shades; `svg` returns the card, `copy` puts it on the clipboard |
|
|
1098
1098
|
| `forge_scale` | a 50–950 tonal scale with the colour at 500, rated for white and black text; the colour as hex, `rgb()`, `hsl()`, `oklch()` or a name; `svg` returns the card, `copy` puts it on the clipboard |
|
|
1099
1099
|
| `forge_card` | named colours (`title`, `colours: [{ name, colour }]`, optional `subtitle` and `theme`) drawn as the SVG swatch card, or with `copy: true` put straight on the clipboard; paste into Figma for one layer per colour |
|
|
1100
|
+
| `forge_transcribe` | a video or sound file, or a YouTube link, into notes and a transcript (`to`, `detail`, `language`, `format`, `output`, `overwrite`); writes the file and returns its text |
|
|
1101
|
+
| `forge_read_text` | the text in a picture, screenshot, scan or PDF (`language`, `format`, `output`, `overwrite`); writes the file and returns its text |
|
|
1100
1102
|
|
|
1101
1103
|
Paths must be absolute. Results come back as structured content in the
|
|
1102
1104
|
`--json` shape below, with a `file://` link to every output, and never as
|
|
1103
|
-
file contents
|
|
1105
|
+
file contents, except from `forge_transcribe` and `forge_read_text`, whose
|
|
1106
|
+
text is the answer an agent asked for. Those two report progress as facts
|
|
1107
|
+
("heard 12:00 of 48:30") when the client asks for it, and a link's
|
|
1108
|
+
transcript goes to Forge's default folder. Nothing is overwritten unless the call passes
|
|
1104
1109
|
`overwrite: true`. An encrypted PDF takes a `password` argument to
|
|
1105
1110
|
`forge_convert`; there is no prompt. The server speaks MCP over stdio,
|
|
1106
1111
|
negotiates protocol revision 2025-11-25 with current Claude Code, writes
|
|
@@ -1136,7 +1141,7 @@ photo.png · PNG · 122 KB · 2756×774
|
|
|
1136
1141
|
With `--json`:
|
|
1137
1142
|
|
|
1138
1143
|
```json
|
|
1139
|
-
{"forge":"0.5.
|
|
1144
|
+
{"forge":"0.5.9","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":[]}
|
|
1140
1145
|
```
|
|
1141
1146
|
|
|
1142
1147
|
`targets` and `actions` come from the engines' own capabilities, so they are
|
|
@@ -1162,7 +1167,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
|
|
|
1162
1167
|
|
|
1163
1168
|
```jsonc
|
|
1164
1169
|
{
|
|
1165
|
-
"forge": "0.5.
|
|
1170
|
+
"forge": "0.5.9",
|
|
1166
1171
|
"ok": false,
|
|
1167
1172
|
"results": [
|
|
1168
1173
|
{
|
|
@@ -1497,7 +1502,7 @@ src/
|
|
|
1497
1502
|
│ └── report.ts stdout formatting (success, batch, errors, --formats)
|
|
1498
1503
|
│
|
|
1499
1504
|
├── mcp/ the MCP server — a third front end, loaded only by `forge mcp`
|
|
1500
|
-
│ ├── server.ts createForgeServer():
|
|
1505
|
+
│ ├── server.ts createForgeServer(): eleven tools; runMcpServer(): stdio
|
|
1501
1506
|
│ ├── tools.ts tool handlers → the same intents and runIntent() the CLI uses
|
|
1502
1507
|
│ ├── schemas.ts zod input/output schemas, vocabularies read from core/actions
|
|
1503
1508
|
│ └── stdout-guard.ts stdout belongs to the protocol; stray writes go to stderr
|
|
@@ -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-
|
|
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-L753MI7U.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-E3OUBT36.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-
|
|
3
|
+
import{a,b,c,d,e,f}from"./chunk-7XDMC7FL.js";import"./chunk-FBVRKMAF.js";import"./chunk-3374PCO5.js";import"./chunk-HZDYZ5RD.js";import"./chunk-N32JL4UI.js";import"./chunk-TGC24JEW.js";import"./chunk-K253E723.js";import"./chunk-EEQSUBBL.js";import"./chunk-OQBIYNGK.js";import"./chunk-FAUL5L2W.js";import"./chunk-HTA25PO2.js";import"./chunk-N6RCLJE6.js";import"./chunk-WE6KP4FR.js";import"./chunk-KH5DHZ2U.js";import"./chunk-HON4OV7M.js";import"./chunk-TLHUFIXD.js";import"./chunk-4MJEEEFA.js";import"./chunk-V6GWPR2A.js";import"./chunk-WBW6G4N6.js";import"./chunk-ZBMJTIYR.js";import"./chunk-J7FLFHQJ.js";import"./chunk-VLVNA4T3.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{r as a}from"./chunk-
|
|
3
|
+
import{r as a}from"./chunk-TGC24JEW.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-VNW4YQ4Z.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{f as a}from"./chunk-
|
|
3
|
+
import{f as a}from"./chunk-K253E723.js";import{c as i}from"./chunk-FAUL5L2W.js";import{a as e}from"./chunk-H3DIRJFE.js";function s(t){let o=Object.keys(e);return[...t].sort((r,n)=>o.indexOf(r)-o.indexOf(n))}function f(t){let o=new Set;for(let r of a)if(r.reads.has(t.format))for(let n of r.writesFor?.(t)??r.writes)e[n].keepsOnly&&n!==t.format||o.add(n);return s([...o])}function F(t){return f(t).map(o=>({id:o,label:e[o].label,hint:e[o].hint,lossy:e[o].lossy}))}function d(){let t=new Set;for(let o of a)for(let r of o.reads)t.add(r);return s([...t])}function l(){let t=new Set;for(let o of a)for(let r of o.writes)t.add(r);return s([...t])}function p(t){return i.writes.has(t)}function I(){let t=new Set(d()),o=new Set(l());return s([...new Set([...t,...o])]).map(r=>({id:r,label:e[r].label,extensions:[...e[r].extensions],read:t.has(r),write:o.has(r),lossy:e[r].lossy}))}export{f as a,F as b,d as c,l as d,p as e,I as f};
|
|
@@ -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 y,c as b}from"./chunk-
|
|
3
|
+
import{a as y,c as b}from"./chunk-AR3M2PLK.js";import{a as p}from"./chunk-3374PCO5.js";import{j as h}from"./chunk-K253E723.js";import{a as m}from"./chunk-ZBMJTIYR.js";import{a as c}from"./chunk-H3DIRJFE.js";import{open as g,readdir as w,stat as x}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 R=new Set(Object.values(c).flatMap(e=>e.extensions));async function O(e){let i=await g(e,"r"),t=Buffer.alloc(4096),r=0;try{r=(await i.read(t,0,t.length,0)).bytesRead}finally{await i.close()}let n=t.subarray(0,r),o=(d,f)=>n.subarray(d,d+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":n[0]===0&&n[1]===0&&n[2]===1&&(n[3]===186||n[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))||n[0]===255&&n[1]!==void 0&&(n[1]&224)===224?"audio":r>0&&!n.includes(0)&&M(n)?"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(t=>t==="text")?i.length===1?"a text file":"text files":"not supported"}async function V(e){let i=v(e),t=await w(i,{withFileTypes:!0}),r=[],n=[],o=new Map,d=[],f=0;for(let s of t.sort((a,u)=>a.name.localeCompare(u.name)))!s.isFile()||K(s.name)||d.push(k(i,s.name));for(let s of await E(d))if(s.kind==="source")r.push(s.source),f+=s.source.bytes;else if(s.kind==="failed")n.push(s.failure),f+=s.bytes;else{let a=s.kind,u=o.get(a)??{bytes:0,sniffed:[]};u.bytes+=s.bytes,u.sniffed.push(s.sniffed),o.set(a,u),f+=s.bytes}let l=I(r);for(let s of F){let a=o.get(s);if(!a)continue;let u=j(s,a.sniffed);l.push({id:s,count:a.sniffed.length,bytes:a.bytes,sources:[],...u===void 0?{}:{why:u}})}return{dir:i,sources:r,failures:n,kinds:l,bytes:f,paths:d}}async function E(e){let i=[];return await b(e,y(),async(t,r)=>{try{i[r]={read:await C(t)}}catch(n){i[r]={error:n}}}),i.map(t=>{if("error"in t)throw t.error;return t.read})}function I(e){let i=[];for(let t of F){let r=e.filter(n=>A(n)===t);r.length>0&&i.push({id:t,count:r.length,bytes:r.reduce((n,o)=>n+o.bytes,0),sources:r})}return i.sort((t,r)=>r.count-t.count)}function W(e,i=[]){let t=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),n=I(r);for(let o of["videos","audio"]){let d=t.filter(f=>c[f.format].media==="video"==(o==="videos"));if(d.length>0){let f=d.reduce((l,s)=>l+s.bytes,0);n.push({id:o,count:d.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:n,bytes:e.reduce((o,d)=>o+d.bytes,0),paths:e.map(o=>o.path)}}async function C(e){let i=()=>x(e).then(t=>t.size,()=>0);try{let t=await h(e);if(t.kind==="media"){let r=c[t.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:t.bytes}}return{kind:"source",source:t}}catch(t){let r=await i(),n=await O(e).catch(()=>"other");if(n==="video"||n==="audio")return{kind:n==="video"?"videos":"audio",sniffed:n,bytes:r};if(R.has(S(e).toLowerCase())){let o=m(t)?t:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:n,bytes:r}}}function D(e){let i=new Set(e.flatMap(t=>p(t).filter(r=>r!==t.format)));return Object.keys(c).filter(t=>i.has(t))}function _(e,i){let t=D(e),r=e[0],n=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=n&&t.includes(n)?n:t[0];if(o)return N(e,o,i)}function N(e,i,t){let r={target:i};return c[i].lossy&&(r.quality=t),e.some(n=>n.kind==="document"&&n.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{K as a,A as b,O as c,V as d,W as e,C as f,D as g,_ 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
|
-
import{c as ie,d as ue,e as pe,g as ce,h as de}from"./chunk-
|
|
4
|
-
`),r.close()}}function Ae(e){return e.kind==="preset"?e.name:e.kind==="pageop"?"PDF":e.kind==="compress"?"Compress":e.kind==="convert"?"Convert":"Edit"}function A(e){return e.length===0?0:e.some(t=>t.error.code==="invalid-arguments")?2:1}function De(e,t){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 r=t.find(n=>n.kind==="document"),o=r?.pages??0,s=e.split;if(!s)throw N("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:ue(o,s.n)};let a=Math.max(o-1,0);for(let n of s.after)if(!Number.isInteger(n)||n<1||n>a)throw V(String(n),`"${n}" is outside 1 and ${a} \u2014 ${r?w(r.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(n=>n-1)}}function We(e,t){let r;return()=>t?(r??=Fe({stdin:e}).then(o=>e&&o===""?void 0:o),r):Promise.resolve(void 0)}async function ze(e,t,r,o){let s;if(e.encrypted){if(s=t.password??await r(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Z(await Te(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let a;try{a=O.plan([e],{target:t.target,background:t.options.background,keepMetadata:t.options.keepMetadata,dpi:String(t.dpi??150),...t.options.quality===void 0?{}:{quality:t.options.quality},...t.pages===void 0?{}:{pages:t.pages},...t.output===void 0?{}:{destination:t.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!P(i))throw i;return{failure:{path:e.path,error:i}}}let n=a[0];if(n?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(n.options.password=s),{job:n}}function S(e,t){return r=>{if(r.type==="search:attempt"){t||e.onSearch?.(r.rung.dpi===void 0?`attempt ${r.attempt} of ${r.of}`:`${r.rung.dpi} dpi \xB7 attempt ${r.attempt} of ${r.of}`);return}if(r.type==="search:settled"){t&&e.onSearch?.(`${r.completed} of ${r.total} searched`);return}if(!t&&r.type==="job:phase"&&r.progress.phase==="time"){let o=r.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of ${o.pass.of} \xB7 ${s}`:s);return}t&&(r.type==="job:done"||r.type==="job:error")&&e.onProgress?.({completed:r.completed,total:r.total})}}var b=(e,t)=>({kind:e,results:[],failures:t,inputBytes:0,outputBytes:0});async function qe(e){let t=await y(e.inputs,{recursive:!1});if(t.sources.length===0)return b("pageop",t.failures);let r=pe.find(n=>n.id===e.action);if(!r)throw new Error(`no action registered for "${e.action}"`);let o=t.sources[0]?.path??"";if(!r.appliesTo(t.sources)){let n=de(r,t.sources)??"not available for these files";return b("pageop",[...t.failures,{path:o,error:k(e.action,n)}])}let s;try{s=r.plan(t.sources,De(e,t.sources))}catch(n){if(!P(n))throw n;return b("pageop",[...t.failures,{path:o,error:n}])}let a=await I(s,{force:e.force});return{kind:"pageop",results:a.results,failures:[...t.failures,...a.refusals,...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Ve(e,t){let r=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of r.sources){if(!M.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!Y(e.output)?Me(e.output):void 0,p=e.output===void 0||u!==void 0?Oe(i.path):Oe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:r.roots.get(i.path)})),[f]=M.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:p});f?.op==="convert"&&(u!==void 0&&(f.outputs=[u]),e.dpi!==void 0&&(f.options.dpi=e.dpi),o.push(f))}let a=o.length>1;a&&t.onProgress?.({completed:0,total:o.length});let n=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(t,a)});return{kind:"compress",results:n.results,failures:[...r.failures,...s,...n.refusals,...n.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Ge(e,t){let r=e.kind,o=e.op==="remove-background"?L(e.target):void 0;if(o)return b(r,[{path:"",error:o}]);let{installed:s}=await import("./paths-6OENILJ4.js"),a=await s(e.op);if(!a)return b(r,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:c}=await import("./catalog-FMHWWMUX.js"),m=c("boost"),v=m&&l(m)?.version,D=U(e.scale,a.version,v);if(D)return b(r,[{path:"",error:D}])}let n=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?oe:se,u=[],p=[];for(let l of n.sources){if(!i.appliesTo([l])){p.push({path:l.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let c=te(l,e.target);if(c){p.push({path:l.path,error:c});continue}u.push(...i.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:n.roots}))}let f=u.length>1;f&&t.onProgress?.({completed:0,total:u.length});let d=await I(u,{force:e.force,concurrency:1,...t.signal===void 0?{}:{signal:t.signal},onEvent:S(t,f)});return{kind:r,results:d.results,failures:[...n.failures,...p,...d.refusals,...d.failures],inputBytes:d.inputBytes,outputBytes:d.outputBytes}}async function He(e,t){let r=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:be(e.target,r);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),a=[],n=[],i=[];for(let c of s.sources)c.kind==="image"&&e.media===void 0?a.push(c):c.kind==="media"&&!e.trim?n.push(c):c.kind==="image"?i.push({path:c.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:c.path,error:k(r,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ne(n,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),f=[...ae(a,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],d=f.length>1;d&&t.onProgress?.({completed:0,total:f.length});let l=await I(f,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(t,d)});return{kind:e.kind,results:l.results,failures:[...s.failures,...i,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function Le(e,t){let r=await y(e.inputs,{recursive:e.recursive}),o=m=>m.kind==="document"&&m.format==="pdf",s=F(e.target),a=s?r.sources.filter(o):[],n=s?r.sources.filter(m=>!o(m)):r.sources,i=[],u=[],p=We(e.passwordStdin??!1,t.interactive??!0);for(let m of a){let v=await ze(m,e,p,r.roots.get(m.path));"failure"in v?u.push(v.failure):i.push(v.job)}let f=await we({resolved:{sources:n,failures:[],roots:r.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),d=[...f.jobs,...i],l=d.length>1;l&&t.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(t,l)});return{kind:"convert",results:c.results,failures:[...r.failures,...u,...f.failures,...c.refusals,...c.unreachable.map(m=>({path:m.job.sources[0].path,error:m.error})),...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ue(e,t={}){try{if(e.kind==="pageop")return await qe(e);if(e.kind==="extension-op")return await Ge(e,t);if(e.kind==="edit")return await He(e,t);if(e.kind==="preset"){let{runPresetCommand:r}=await import("./preset-command-4OVFEH7Y.js");return await r(e)}return e.kind==="compress"?await Ve(e,t):await Le(e,t)}catch(r){if(!P(r))throw r;return b(e.kind,[{path:"",error:r}])}}function Ye(e,t){let r=A(e.failures);if(t.json)return{exitCode:r,stdout:[JSON.stringify(fe(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?$e(e):e.results.length===1?Pe(e):ke(e);return{exitCode:r,stdout:o,stderr:B(e.failures,{debug:t.debug})}}function Ke(e,t){let r=[{path:"",error:e}],o=A(r);return t.json?{exitCode:o,stdout:[JSON.stringify(le(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:B(r,{debug:t.debug})}}async function Qe(e,t){let{runConfig:r}=await import("./config-command-CKPJXJEE.js"),o=await r(e);return t?{exitCode:0,stdout:[JSON.stringify(he(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function zr(e,t={}){let r=t.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Qe(e,r);if(e.kind==="clip"){let{runClipCommand:n}=await import("./clip-command-3CMQ6A5D.js");return await n(e,{...t,json:r,debug:o})}if(e.kind==="update"){let{runUpdate:n}=await import("./update-command-DWEBUFT5.js"),i=await n(g,{...t.onInstalling?{onInstalling:t.onInstalling}:{}});return{exitCode:0,stdout:r?[JSON.stringify({forge:g,ok:!0,...i.data})]:i.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:n}=await import("./entry-SOHEQPXT.js"),i=[];return{exitCode:await n(g,p=>i.push(p)),stdout:i,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:n}=await import("./extensions-command-VT4M2JQW.js"),i=await n(e,{onDownload:t.onDownload});return{exitCode:0,stdout:r?[JSON.stringify(ye(g,i.data))]:i.stdout,stderr:[]}}if(e.kind==="formats")return r?{exitCode:0,stdout:[JSON.stringify(me(g,re()))],stderr:[]}:{exitCode:0,stdout:Re(),stderr:[]};if(e.kind==="probe"){let{probes:n,failures:i}=await Ie(e.inputs),u=A(i);return r?{exitCode:u,stdout:[JSON.stringify(ge(g,{probes:n,failures:i}))],stderr:[]}:{exitCode:u,stdout:n.flatMap((p,f)=>[...f>0?[""]:[],...Ee(p)]),stderr:B(i,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"||e.kind==="card"){let{runCard:n,runPalette:i,runScale:u}=await import("./colour-VBHJAKAX.js"),p={json:r,colour:t.colour??!1};return e.kind==="card"?await n(e,p):e.kind==="palette"?await i(e,p):await u(e,p)}if(e.kind==="transcribe"){let{runTranscribeCommand:n}=await import("./transcribe-command-GAKYFBWQ.js"),i=[],u=[],p;return{exitCode:await n(e,{out:d=>i.push(d),err:d=>u.push(d),finished:d=>{p=T("Transcribe",d)}}),stdout:i,stderr:u,...p?{notice:p}:{}}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw N("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");let s=await Ue(e,t),a=T(Ae(e),X(s.results,s.failures));return{...Ye(s,{json:r,debug:o}),...a?{notice:a}:{}}}catch(s){if(!P(s))throw s;return Ke(s,{json:r,debug:o})}}export{Ie as a,xe as b,A as c,Ue as d,Ye as e,zr as f};
|
|
3
|
+
import{c as ie,d as ue,e as pe,g as ce,h as de}from"./chunk-ASLKQXZ2.js";import{a as te,b as oe,c as se,k as ne,m as M,n as O,s as ae}from"./chunk-BKLPRILS.js";import{b as X,c as T}from"./chunk-6RMRWBMB.js";import{a as y}from"./chunk-QQV7CCAY.js";import{b as I}from"./chunk-VJMOZPHW.js";import{e as be}from"./chunk-FBVRKMAF.js";import{a as C,c as _,d as ee,e as F,f as re}from"./chunk-3374PCO5.js";import{f as fe,g as le,h as me,i as ge,j as he,k as ye}from"./chunk-YJ6XLDRA.js";import{a as g}from"./chunk-TGC24JEW.js";import{d as $}from"./chunk-EEQSUBBL.js";import{a as Z}from"./chunk-FAUL5L2W.js";import{a as L,d as U}from"./chunk-TLHUFIXD.js";import{a as Y,c as K,d as E,e as Q}from"./chunk-V6GWPR2A.js";import{G as N,H as V,K as G,a as P,q as z,s as k,u as q,va as H,x as J}from"./chunk-ZBMJTIYR.js";import{a as h,b as W}from"./chunk-J7FLFHQJ.js";import{b as x,c as w}from"./chunk-VLVNA4T3.js";import{a as R}from"./chunk-H3DIRJFE.js";import{readFile as Te}from"node:fs/promises";import{dirname as Oe,resolve as Me}from"node:path";async function we(e){let t=[],r=[...e.resolved.failures];for(let o of e.resolved.sources){let s=C(o);if(!s.includes(e.target)){r.push({path:o.path,error:q(o,e.target,s)});continue}let a={sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)},n=E(a);K(n,o.path)&&e.target!==o.format&&(n=Q({...a,suffix:e.target})),t.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:t,failures:r}}import{resolve as je}from"node:path";function Be(e,t=new Set){let r={path:je(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:C(e).filter(a=>!o||F(a)),actions:ce([e],t).filter(a=>!o||a.id===O.id).map(a=>a.id)};if(e.kind==="image")return{...r,width:e.width,height:e.height,...s};if(e.kind==="media"){let a=e.facts;return{...r,...a?{duration:a.duration}:{},...a?.video?{width:a.video.width,height:a.video.height,fps:a.video.fps}:{},...s}}return{...r,pages:e.pages,encrypted:e.encrypted,...s}}async function Ie(e){let t=await y(e,{recursive:!1}),{installedExtensionIds:r}=await import("./available-TNMISSBA.js"),o=await r();return{probes:t.sources.map(s=>Be(s,o)),failures:t.failures}}import{dirname as Se}from"node:path";var j=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ve(e,t){let r=x(Se(e),j(t));return r==="."?"":` in ${r.endsWith("/")?r:`${r}/`}`}function xe(e,t){let{pct:r,direction:o}=W(e,t);return o==="same"?"same size":`${r}% ${o}`}function Pe(e,t={}){let r=e.results[0];if(!r)return[];let o=r.job.sources[0],s=r.job.outputs;if(s.length>1){let n=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ve(s[0],t)}`,` ${s.map(i=>w(i)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(r.outputBytes)} total`];for(let i of r.warnings)n.push("",`\u26A0 ${i.message}`);return n}let a=[`\u2713 ${w(o.path)} \u2192 ${x(s[0],j(t))}`,` ${h(o.bytes)} \u2192 ${h(r.outputBytes)} \xB7 ${xe(o.bytes,r.outputBytes)}`];for(let n of r.warnings)a.push("",`\u26A0 ${n.message}`);return a}function ke(e,t={}){let r=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${xe(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let a of s.job.outputs)r.push(` ${x(a,j(t))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){r.push("");for(let s of o)r.push(`\u26A0 ${s.message}`)}return r}function $e(e,t={}){let r=e.results.flatMap(u=>u.job.outputs),o=r.map(u=>w(u)).join(", "),s=r.length===1?"file":"files",a=r[0]===void 0?"":ve(r[0],t),n=[`\u2713 ${r.length} ${s} \xB7 ${o}${a}`],i=e.results.flatMap(u=>u.warnings);for(let u of i)n.push("",`\u26A0 ${u.message}`);return n}function B(e,t){if(e.length===0)return[];let r=[];for(let o of e)r.push(...H(o.error,{debug:t.debug}),"");return r}function Re(){let e=new Set(_()),t=new Set(ee()),r=["Formats",""];for(let s of e){let a=R[s],n=t.has(s)?"read and write":"read only";r.push(` ${a.label.padEnd(6)} ${a.extensions.join(" ").padEnd(12)} ${n}`)}let o=[...e].filter(s=>!t.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[a,n]=o.length===1?["is","it"]:["are","them"];r.push("",`${s} ${a} read only because Forge cannot yet write ${n}.`)}return r}function Ee(e,t={}){let r=[R[e.format].label,h(e.bytes)];return e.duration!==void 0&&r.push($(e.duration)),e.width!==void 0&&e.height!==void 0&&r.push(`${e.width}\xD7${e.height}`),e.fps!==void 0&&r.push(`${e.fps} fps`),e.pages!==void 0&&r.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&r.push("password-protected"),[`${x(e.path,j(t))} \xB7 ${r.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Ce}from"node:readline";import{PassThrough as Je}from"node:stream";function Ne(e){return new Promise(t=>{let r=Ce({input:e,terminal:!1}),o=!1,s=a=>{if(o)return;o=!0,r.close(),e.pause(),e.unref?.(),t(a.replace(/\r$/,""))};r.once("line",s),r.once("close",()=>s(""))})}async function Fe(e){if(e.stdin)return Ne(process.stdin);if(!process.stdin.isTTY)return;let t=new Je,r=Ce({input:process.stdin,output:t,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>r.question("",o))}finally{process.stderr.write(`
|
|
4
|
+
`),r.close()}}function Ae(e){return e.kind==="preset"?e.name:e.kind==="pageop"?"PDF":e.kind==="compress"?"Compress":e.kind==="convert"?"Convert":"Edit"}function A(e){return e.length===0?0:e.some(t=>t.error.code==="invalid-arguments")?2:1}function De(e,t){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 r=t.find(n=>n.kind==="document"),o=r?.pages??0,s=e.split;if(!s)throw N("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:ue(o,s.n)};let a=Math.max(o-1,0);for(let n of s.after)if(!Number.isInteger(n)||n<1||n>a)throw V(String(n),`"${n}" is outside 1 and ${a} \u2014 ${r?w(r.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(n=>n-1)}}function We(e,t){let r;return()=>t?(r??=Fe({stdin:e}).then(o=>e&&o===""?void 0:o),r):Promise.resolve(void 0)}async function ze(e,t,r,o){let s;if(e.encrypted){if(s=t.password??await r(),s===void 0)return{failure:{path:e.path,error:J(e.path)}};let i;try{i=await Z(await Te(e.path),s)}catch{return{failure:{path:e.path,error:J(e.path,{attempted:!0})}}}i.destroy()}let a;try{a=O.plan([e],{target:t.target,background:t.options.background,keepMetadata:t.options.keepMetadata,dpi:String(t.dpi??150),...t.options.quality===void 0?{}:{quality:t.options.quality},...t.pages===void 0?{}:{pages:t.pages},...t.output===void 0?{}:{destination:t.output},...o===void 0?{}:{sourceRoot:o}})}catch(i){if(!P(i))throw i;return{failure:{path:e.path,error:i}}}let n=a[0];if(n?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(n.options.password=s),{job:n}}function S(e,t){return r=>{if(r.type==="search:attempt"){t||e.onSearch?.(r.rung.dpi===void 0?`attempt ${r.attempt} of ${r.of}`:`${r.rung.dpi} dpi \xB7 attempt ${r.attempt} of ${r.of}`);return}if(r.type==="search:settled"){t&&e.onSearch?.(`${r.completed} of ${r.total} searched`);return}if(!t&&r.type==="job:phase"&&r.progress.phase==="time"){let o=r.progress,s=`${$(o.done)} of ${$(o.total)}`;e.onEncode?.(o.pass?`pass ${o.pass.at} of ${o.pass.of} \xB7 ${s}`:s);return}t&&(r.type==="job:done"||r.type==="job:error")&&e.onProgress?.({completed:r.completed,total:r.total})}}var b=(e,t)=>({kind:e,results:[],failures:t,inputBytes:0,outputBytes:0});async function qe(e){let t=await y(e.inputs,{recursive:!1});if(t.sources.length===0)return b("pageop",t.failures);let r=pe.find(n=>n.id===e.action);if(!r)throw new Error(`no action registered for "${e.action}"`);let o=t.sources[0]?.path??"";if(!r.appliesTo(t.sources)){let n=de(r,t.sources)??"not available for these files";return b("pageop",[...t.failures,{path:o,error:k(e.action,n)}])}let s;try{s=r.plan(t.sources,De(e,t.sources))}catch(n){if(!P(n))throw n;return b("pageop",[...t.failures,{path:o,error:n}])}let a=await I(s,{force:e.force});return{kind:"pageop",results:a.results,failures:[...t.failures,...a.refusals,...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Ve(e,t){let r=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let i of r.sources){if(!M.appliesTo([i])){s.push({path:i.path,error:z(i)});continue}let u=e.output!==void 0&&!Y(e.output)?Me(e.output):void 0,p=e.output===void 0||u!==void 0?Oe(i.path):Oe(E({sourcePath:i.path,target:i.format,output:e.output,sourceRoot:r.roots.get(i.path)})),[f]=M.plan([i],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},...e.options.media??{},destination:p});f?.op==="convert"&&(u!==void 0&&(f.outputs=[u]),e.dpi!==void 0&&(f.options.dpi=e.dpi),o.push(f))}let a=o.length>1;a&&t.onProgress?.({completed:0,total:o.length});let n=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(t,a)});return{kind:"compress",results:n.results,failures:[...r.failures,...s,...n.refusals,...n.unreachable.map(i=>({path:i.job.sources[0].path,error:i.error})),...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Ge(e,t){let r=e.kind,o=e.op==="remove-background"?L(e.target):void 0;if(o)return b(r,[{path:"",error:o}]);let{installed:s}=await import("./paths-6OENILJ4.js"),a=await s(e.op);if(!a)return b(r,[{path:"",error:G(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:c}=await import("./catalog-FMHWWMUX.js"),m=c("boost"),v=m&&l(m)?.version,D=U(e.scale,a.version,v);if(D)return b(r,[{path:"",error:D}])}let n=await y(e.inputs,{recursive:e.recursive}),i=e.op==="boost"?oe:se,u=[],p=[];for(let l of n.sources){if(!i.appliesTo([l])){p.push({path:l.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let c=te(l,e.target);if(c){p.push({path:l.path,error:c});continue}u.push(...i.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:n.roots}))}let f=u.length>1;f&&t.onProgress?.({completed:0,total:u.length});let d=await I(u,{force:e.force,concurrency:1,...t.signal===void 0?{}:{signal:t.signal},onEvent:S(t,f)});return{kind:r,results:d.results,failures:[...n.failures,...p,...d.refusals,...d.failures],inputBytes:d.inputBytes,outputBytes:d.outputBytes}}async function He(e,t){let r=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:be(e.target,r);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),a=[],n=[],i=[];for(let c of s.sources)c.kind==="image"&&e.media===void 0?a.push(c):c.kind==="media"&&!e.trim?n.push(c):c.kind==="image"?i.push({path:c.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:c.path,error:k(r,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ne(n,{...e.media===void 0?{}:{media:e.media},...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots}),f=[...ae(a,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),...u],d=f.length>1;d&&t.onProgress?.({completed:0,total:f.length});let l=await I(f,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:S(t,d)});return{kind:e.kind,results:l.results,failures:[...s.failures,...i,...l.refusals,...l.failures],inputBytes:l.inputBytes,outputBytes:l.outputBytes}}async function Le(e,t){let r=await y(e.inputs,{recursive:e.recursive}),o=m=>m.kind==="document"&&m.format==="pdf",s=F(e.target),a=s?r.sources.filter(o):[],n=s?r.sources.filter(m=>!o(m)):r.sources,i=[],u=[],p=We(e.passwordStdin??!1,t.interactive??!0);for(let m of a){let v=await ze(m,e,p,r.roots.get(m.path));"failure"in v?u.push(v.failure):i.push(v.job)}let f=await we({resolved:{sources:n,failures:[],roots:r.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),d=[...f.jobs,...i],l=d.length>1;l&&t.onProgress?.({completed:0,total:d.length});let c=await I(d,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:S(t,l)});return{kind:"convert",results:c.results,failures:[...r.failures,...u,...f.failures,...c.refusals,...c.unreachable.map(m=>({path:m.job.sources[0].path,error:m.error})),...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function Ue(e,t={}){try{if(e.kind==="pageop")return await qe(e);if(e.kind==="extension-op")return await Ge(e,t);if(e.kind==="edit")return await He(e,t);if(e.kind==="preset"){let{runPresetCommand:r}=await import("./preset-command-UNMXHW5A.js");return await r(e)}return e.kind==="compress"?await Ve(e,t):await Le(e,t)}catch(r){if(!P(r))throw r;return b(e.kind,[{path:"",error:r}])}}function Ye(e,t){let r=A(e.failures);if(t.json)return{exitCode:r,stdout:[JSON.stringify(fe(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?$e(e):e.results.length===1?Pe(e):ke(e);return{exitCode:r,stdout:o,stderr:B(e.failures,{debug:t.debug})}}function Ke(e,t){let r=[{path:"",error:e}],o=A(r);return t.json?{exitCode:o,stdout:[JSON.stringify(le(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:B(r,{debug:t.debug})}}async function Qe(e,t){let{runConfig:r}=await import("./config-command-CKPJXJEE.js"),o=await r(e);return t?{exitCode:0,stdout:[JSON.stringify(he(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function zr(e,t={}){let r=t.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Qe(e,r);if(e.kind==="clip"){let{runClipCommand:n}=await import("./clip-command-MDSM6KJP.js");return await n(e,{...t,json:r,debug:o})}if(e.kind==="update"){let{runUpdate:n}=await import("./update-command-DWEBUFT5.js"),i=await n(g,{...t.onInstalling?{onInstalling:t.onInstalling}:{}});return{exitCode:0,stdout:r?[JSON.stringify({forge:g,ok:!0,...i.data})]:i.stdout,stderr:[]}}if(e.kind==="uninstall"){let{runUninstall:n}=await import("./entry-BZYPZONY.js"),i=[];return{exitCode:await n(g,p=>i.push(p)),stdout:i,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:n}=await import("./extensions-command-JZSOQJEV.js"),i=await n(e,{onDownload:t.onDownload});return{exitCode:0,stdout:r?[JSON.stringify(ye(g,i.data))]:i.stdout,stderr:[]}}if(e.kind==="formats")return r?{exitCode:0,stdout:[JSON.stringify(me(g,re()))],stderr:[]}:{exitCode:0,stdout:Re(),stderr:[]};if(e.kind==="probe"){let{probes:n,failures:i}=await Ie(e.inputs),u=A(i);return r?{exitCode:u,stdout:[JSON.stringify(ge(g,{probes:n,failures:i}))],stderr:[]}:{exitCode:u,stdout:n.flatMap((p,f)=>[...f>0?[""]:[],...Ee(p)]),stderr:B(i,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"||e.kind==="card"){let{runCard:n,runPalette:i,runScale:u}=await import("./colour-2MYODUDY.js"),p={json:r,colour:t.colour??!1};return e.kind==="card"?await n(e,p):e.kind==="palette"?await i(e,p):await u(e,p)}if(e.kind==="transcribe"){let{runTranscribeCommand:n}=await import("./transcribe-command-JHWN4RWU.js"),i=[],u=[],p;return{exitCode:await n(e,{out:d=>i.push(d),err:d=>u.push(d),finished:d=>{p=T("Transcribe",d)}}),stdout:i,stderr:u,...p?{notice:p}:{}}}if(e.kind==="shell")return{exitCode:0,stdout:[],stderr:[]};if(e.kind==="watch")throw N("forge watch runs in a terminal until ctrl-c.","Try: forge watch ./images --to webp");let s=await Ue(e,t),a=T(Ae(e),X(s.results,s.failures));return{...Ye(s,{json:r,debug:o}),...a?{notice:a}:{}}}catch(s){if(!P(s))throw s;return Ke(s,{json:r,debug:o})}}export{Ie as a,xe as b,A as c,Ue as d,Ye as e,zr 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{j as l}from"./chunk-
|
|
3
|
+
import{j as l}from"./chunk-K253E723.js";import{g as c}from"./chunk-WBW6G4N6.js";import{a as m,j as n,v as f}from"./chunk-ZBMJTIYR.js";import{a as s}from"./chunk-H3DIRJFE.js";import{b as p}from"./chunk-KXKQDFHX.js";async function b(r,i=192){let t=await l(r);if(t.kind!=="image")throw n(r,`a ${s[t.format].label}`);let u=await c(r,t.format);try{let e=await p(),{data:o,info:a}=await e(u,{animated:!1}).rotate().resize(i,i,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0});return{source:t,pixels:{width:a.width,height:a.height,rgba:new Uint8Array(o.buffer,o.byteOffset,o.length)}}}catch(e){throw m(e)?e:f(r,e)}}export{b as a};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as he}from"./chunk-MF3KKEFB.js";import{b as je}from"./chunk-I25E2XDH.js";import{b as mt}from"./chunk-HZDYZ5RD.js";import{c as He}from"./chunk-
|
|
3
|
+
import{c as he}from"./chunk-MF3KKEFB.js";import{b as je}from"./chunk-I25E2XDH.js";import{b as mt}from"./chunk-HZDYZ5RD.js";import{c as He}from"./chunk-OQBIYNGK.js";import{f as dt,g as ee,h as gt,i as ht,j as pt}from"./chunk-KH5DHZ2U.js";import{ma as ge,na as $e,oa as Te,pa as ct,ra as _e,sa as Re}from"./chunk-ZBMJTIYR.js";import{c as lt,i as ut}from"./chunk-KXKQDFHX.js";import{spawn as rn}from"node:child_process";import{existsSync as Ie}from"node:fs";import{mkdtemp as st,readFile as ot,rm as at,writeFile as _r}from"node:fs/promises";import{tmpdir as ft}from"node:os";import{dirname as on,join as O}from"node:path";import{createInterface as jr}from"node:readline";import{fileURLToPath as Hr}from"node:url";var hn=new RegExp("\\p{M}","u"),Be=new RegExp("\\p{L}","u"),pn=new RegExp("\\p{Nd}","u");function ze(e){let n=String.fromCodePoint(e);return hn.test(n)?"NSM":e>=1632&&e<=1641||e===1643||e===1644?"AN":pn.test(n)?"EN":e>=1424&&e<=1535||e>=64285&&e<=64335?Be.test(n)?"R":"ON":e>=1536&&e<=1791||e>=1792&&e<=1983||e>=1872&&e<=1919||e>=2208&&e<=2303||e>=64336&&e<=65023||e>=65136&&e<=65279?Be.test(n)?"AL":"ON":Be.test(n)?"L":e===43||e===45?"ES":e===35||e===36||e===37||e===162||e===163||e===176?"ET":e===44||e===46||e===58||e===47||e===160?"CS":n===" "||n===" "||e===12288?"WS":"ON"}var mn={"(":")",")":"(","[":"]","]":"[","{":"}","}":"{","<":">",">":"<","\xAB":"\xBB","\xBB":"\xAB"};function pe(e){for(let n of e){let t=ze(n.codePointAt(0)??0);if(t==="R"||t==="AL")return!0;if(t==="L")return!1}return!1}function bn(e){for(let n of e){let t=ze(n.codePointAt(0)??0);if(t==="R"||t==="AL"||t==="AN")return!0}return!1}function bt(e,n){let t=[...e];if(!n&&!bn(e))return e;let i=t.length,r=t.map(a=>ze(a.codePointAt(0)??0)),o=n?1:0,s=o?"R":"L";for(let a=0;a<i;a++){r[a]==="NSM"&&(r[a]=a>0?r[a-1]??"ON":o?"R":"L");let u=r[a];u==="L"||u==="R"||u==="AL"?s=u:u==="EN"&&s==="AL"&&(r[a]="AN")}for(let a=0;a<i;a++)r[a]==="AL"&&(r[a]="R");for(let a=1;a<i-1;a++){let u=r[a],l=r[a-1],g=r[a+1];(u==="ES"||u==="CS")&&l==="EN"&&g==="EN"?r[a]="EN":u==="CS"&&l==="AN"&&g==="AN"&&(r[a]="AN")}for(let a=0;a<i;a++){if(r[a]!=="ET")continue;let u=a;for(;u<i&&r[u]==="ET";)u++;if(r[a-1]==="EN"||r[u]==="EN")for(let l=a;l<u;l++)r[l]="EN";a=u-1}for(let a=0;a<i;a++)(r[a]==="ES"||r[a]==="ET"||r[a]==="CS")&&(r[a]="ON");let f=o?"R":"L";for(let a=0;a<i;a++)r[a]==="L"||r[a]==="R"?f=r[a]:r[a]==="EN"&&f==="L"&&(r[a]="L");let c=a=>a==="L"?"L":a==="R"||a==="EN"||a==="AN"?"R":void 0;for(let a=0;a<i;a++){if(r[a]!=="WS"&&r[a]!=="ON")continue;let u=a;for(;u<i&&(r[u]==="WS"||r[u]==="ON");)u++;let l=a>0?c(r[a-1]):o?"R":"L",g=u<i?c(r[u]):o?"R":"L",m=l!==void 0&&l===g?l:o?"R":"L";for(let S=a;S<u;S++)r[S]=m;a=u-1}let d=r.map(a=>o===0?a==="R"?1:a==="EN"||a==="AN"?2:0:a==="L"||a==="EN"||a==="AN"?2:1),h=t.map((a,u)=>u),p=Math.max(...d),b=Math.min(...d.filter(a=>a%2===1),Number.POSITIVE_INFINITY);for(let a=p;a>=b&&a>0;a--)for(let u=0;u<i;u++){if((d[h[u]]??0)<a)continue;let l=u;for(;l<i&&(d[h[l]]??0)>=a;)l++;let g=h.slice(u,l).reverse();h.splice(u,l-u,...g),u=l-1}return h.map(a=>{let u=t[a];return(d[a]??0)%2===1?mn[u]??u:u}).join("")}var xn=(e,n)=>{let t=e[0]+e[2]/2,i=e[1]+e[3]/2;return t>=n[0]&&t<=n[0]+n[2]&&i>=n[1]&&i<=n[1]+n[3]};function yn(e){let n=e.filter(t=>t.kind!=="text").map(t=>t.box);return e.filter(t=>t.kind!=="text"||!n.some(i=>xn(t.box,i)))}var wn=.002;function wt(e,n){let t=f=>f.box[n],i=f=>f.box[n]+(n===0?f.box[2]:f.box[3]),r=[...e].sort((f,c)=>t(f)-t(c)),o=[],s=-1;for(let f of r){let c=o[o.length-1];c&&t(f)<=s+wn?(c.push(f),s=Math.max(s,i(f))):(o.push([f]),s=i(f))}return o}function Sn(e){let n=wt(e,1);if(n.length<2)return;let t=o=>Math.max(...o.map(s=>s.box[1]+s.box[3])),i=o=>Math.min(...o.map(s=>s.box[1])),r=1;for(let o=2;o<n.length;o++){let s=f=>i(n[f]??[])-t(n[f-1]??[]);s(o)>s(r)&&(r=o)}return[n.slice(0,r).flat(),n.slice(r).flat()]}function We(e){if(e.length<=1)return[...e];let n=wt(e,0);if(n.length>1)return n.flatMap(We);let t=Sn(e);return t?t.flatMap(We):[...e].sort((i,r)=>i.box[1]-r.box[1]||i.box[0]-r.box[0])}function An(e){let n=[];for(let t of e){let i=n[n.length-1],r=Math.max(t.lineHeight,i?.lineHeight??0);if(!(i!==void 0&&t.box[1]-(i.box[1]+i.box[3])<r&&Math.abs(t.box[0]-i.box[0])<2*r)){n.push({...t});continue}let s=Math.max(i.box[0]+i.box[2],t.box[0]+t.box[2]),f=t.box[1]+t.box[3];n[n.length-1]={...i,text:`${i.text} ${t.text}`,lines:i.lines+1,box:[i.box[0],i.box[1],s-i.box[0],f-i.box[1]]}}return n}function kn(e){let n=e.flatMap(t=>Array(Math.max(1,t.lines)).fill(t.lineHeight));return n.sort((t,i)=>t-i),n[Math.floor(n.length/2)]??0}var Pn=1.2,En=80,Ge=e=>e.replace(/\s*\n\s*/g," ").trim();function Tn(e,n,t){if(e.kind==="list")return{kind:"list",ordered:e.items.some(s=>s.marker==="decimal"||s.marker==="lowercase"||s.marker==="uppercase"),items:e.items.map(s=>Ge(s.text))};if(e.kind==="table"){let s=Math.max(...e.rows.map(f=>f.length));return{kind:"table",rows:e.rows.map(f=>Array.from({length:s},(c,d)=>Ge(f[d]??"")))}}let i=Ge(e.text);return!t&&e.lineHeight>=n*Pn&&e.lines===1&&i.length<=En&&!/[.,;:!?]$/.test(i)?{kind:"heading",level:e.title?1:2,text:i}:{kind:"paragraph",text:i}}function ci(e){return e.map(n=>{let t=We(yn(n.blocks.filter(o=>o.kind!=="text"||o.text.trim()!=="")));n.lines&&(t=An(t.filter(o=>o.kind==="text")));let i=t.filter(o=>o.kind==="text"),r=kn(i);return t.map(o=>Tn(o,r,t.length===1))})}var li=e=>e.some(n=>n.length>0);function Ke(e){return e.replace(/[\\`*[\]<]/g,n=>`\\${n}`).replace(/(^|[^\p{L}\p{N}])_|_(?=[^\p{L}\p{N}]|$)/gu,n=>n.replace("_","\\_"))}function Rn(e){return e.replace(/^(#|>|[-+](?= )|(?<=^\d+)\.(?= ))/,"\\$1").replace(/^(\d+)\.(?= )/,"$1\\.")}var xt=e=>Rn(Ke(e));function Fn(e){if(e.kind==="heading")return`${"#".repeat(e.level)} ${Ke(e.text)}`;if(e.kind==="paragraph")return xt(e.text);if(e.kind==="list")return e.items.map((o,s)=>`${e.ordered?`${s+1}.`:"-"} ${xt(o)}`).join(`
|
|
4
4
|
`);let n=o=>Ke(o).replace(/\|/g,"\\|"),t=o=>`| ${o.map(n).join(" | ")} |`,[i=[],...r]=e.rows;return[t(i),`| ${i.map(()=>"---").join(" | ")} |`,...r.map(t)].join(`
|
|
5
5
|
`)}var Ve=e=>e.filter(n=>n.length>0);function St(e){let n=Ve(e).map(t=>t.map(Fn).join(`
|
|
6
6
|
|
|
@@ -33,4 +33,4 @@ ${s.map(([f,c])=>`<${t(f)}> <${i(c.text)}>`).join(`
|
|
|
33
33
|
endbfchar`)}return["/CIDInit /ProcessSet findresource begin","12 dict begin","begincmap","/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def","/CMapName /Adobe-Identity-UCS def","/CMapType 2 def",`1 begincodespacerange
|
|
34
34
|
<0000> <FFFF>
|
|
35
35
|
endcodespacerange`,...r,"endcmap","CMapName currentdict /CMap defineresource pop","end","end"].join(`
|
|
36
|
-
`)}var De="forge-transcribe",rt="forge-transcribe-whisper.mjs",Br=["darwin","win32","linux"];function zr(e=process.platform,n=["whisper"]){let t=n.includes("whisper")||!n.includes("ffmpeg"),i=n.includes("ffmpeg"),r=[t&&"the whisper extension (forge extensions add whisper, or /extensions)",i&&(e==="darwin"?"ffmpeg (brew install ffmpeg)":e==="win32"?"ffmpeg (winget install ffmpeg)":"ffmpeg on your PATH")].filter(Boolean);return e==="darwin"?`Transcribe on this Mac needs ${r.join(" and ")}.`:e==="win32"?`Transcribe on Windows needs ${r.join(" and ")}.`:e==="linux"?`Transcribe on Linux needs ${r.join(" and ")}.`:"Transcribe needs macOS, Windows or Linux."}function Zi(e=process.platform,n=e==="darwin"?"off":"unsupported"){return n==="off"?"Summary and notes need Apple Intelligence, and it is off.":`Summary and notes need Apple Intelligence, which this ${je(e)} does not have.`}function Gr(e){return{apple:[O(e,"helpers",De),O(e,"..","helpers",De),O(e,"..","..","dist","helpers",De)],whisper:[O(e,"helpers",rt),O(e,"..","helpers",rt),O(e,"..","..","helpers","transcribe",rt)]}}function xe(e=process.platform,n=process.env){let t=n.FORGE_TRANSCRIBE_HELPER;if(t!==void 0)return Ie(t)?t.endsWith(".mjs")?{whisper:t}:{apple:t}:{};if(!Br.includes(e))return{};let i=Gr(on(Hr(import.meta.url))),r=e==="darwin"?i.apple.find(s=>Ie(s)):void 0,o=i.whisper.find(s=>Ie(s));return{...r?{apple:r}:{},...o?{whisper:o}:{}}}async function Wr(e){return e.apple!==void 0&&e.whisper===void 0?{path:e.apple,kind:"apple"}:e.apple!==void 0&&await e.appleHears(e.apple).catch(()=>!1)?{path:e.apple,kind:"apple"}:e.whisper===void 0?void 0:{path:e.whisper,kind:"whisper"}}var en=new Map;function ye(e,n={}){let{apple:t}=xe();if(t===void 0)return Promise.resolve(void 0);let i=`${t}\0${e??""}`,r=n.fresh?void 0:en.get(i);if(r)return r;let o=["status",...e?["--locale",e]:[]],s=oe({path:t,kind:"apple"},o,"").catch(()=>{});return en.set(i,s),s}var it;function Kr(){return process.env.FORGE_TRANSCRIBE_HELPER!==void 0&&(it=void 0),it??=Wr({...xe(),appleHears:async()=>(await ye())?.speech===!0}),it}function Vr(e){let{apple:n}=xe();if(n===void 0)throw e();return{path:n,kind:"apple"}}async function Jr(){let e={...process.env,FORGE_HELPER_STOP_ON_EOF:"1"};if(!e.FORGE_FFMPEG){let n=await He().catch(()=>{});n&&(e.FORGE_FFMPEG=n.ffmpeg)}if(!e.FORGE_WHISPER_CLI){let n=await he("whisper");n&&(e.FORGE_WHISPER_CLI=n.entry)}if(!e.FORGE_WHISPER_MODEL){let n=await he("whisper"),t=n&&O(on(n.entry),"model.bin");t&&Ie(t)&&(e.FORGE_WHISPER_MODEL=t)}return e}var Yr=5e3;async function oe(e,n,t,i={}){let{signal:r}=i;if(r?.aborted)throw r.reason??new Error("aborted");let o=e.kind==="whisper",s=o?await Jr():process.env;if(r?.aborted)throw r.reason??new Error("aborted");return new Promise((f,c)=>{let d=/\.[cm]?js$/.test(e.path),[h,p]=d?[process.execPath,[e.path,...n]]:[e.path,n],b=rn(h,p,{stdio:[o?"pipe":"ignore","pipe","ignore"],env:s,windowsHide:!0});b.stdin?.on("error",()=>{});let a,u=!1,l=m=>{u||(u=!0,r?.removeEventListener("abort",g),m())},g=()=>{o&&b.stdin?(b.stdin.end(),setTimeout(()=>b.kill("SIGKILL"),Yr).unref()):b.kill("SIGKILL"),l(()=>c(r?.reason??new Error("aborted")))};r?.addEventListener("abort",g,{once:!0}),jr({input:b.stdout}).on("line",m=>{let S;try{S=JSON.parse(m)}catch{return}"ok"in S?a=S:i.onLine?.(S)}),b.on("error",m=>l(()=>c(ge(t,m)))),b.on("close",()=>l(()=>{if(a===void 0)return c(ge(t,new Error(`${De} gave no result`)));if(a.ok===!0)return f(a);c(Xr(String(a.code??""),String(a.message??""),t,n,e.kind))}))})}function Xr(e,n,t,i,r){if(e==="no-sound")return $e(t);if(e==="unreadable")return Te(t,process.platform,r);if(e==="locale"){let o=i.indexOf("--locale");return ct(o>=0?i[o+1]??"this language":`this ${je()}'s language`,process.platform,r)}return e==="unsupported"||e==="runtime"?_e(n):ge(t,new Error(`${e}: ${n}`))}var qr=["whisper","ffmpeg"];async function Zr(e={}){let n=xe();if(n.apple===void 0&&n.whisper===void 0)return;let t=await ye(e.locale,{fresh:!0}),r={read:t?.read===!0||await he("read-text")!==void 0};if(t?.speech===!0)return{speech:!0,hears:"apple",locale:typeof t.locale=="string"?t.locale:null,notes:t.notes==="available"||t.notes==="off"?t.notes:"unsupported",...r};if(n.whisper===void 0)return t===void 0?void 0:{speech:!1,locale:null,notes:"unsupported",...r};let o=["status",...e.locale?["--locale",e.locale]:[]],s=await oe({path:n.whisper,kind:"whisper"},o,""),f=Array.isArray(s.missing)?qr.filter(c=>s.missing.includes(c)):[];return{speech:s.speech===!0,...s.speech===!0?{hears:"whisper"}:{},locale:typeof s.locale=="string"?s.locale:null,notes:"unsupported",...r,...f.length>0?{missing:f}:{}}}async function Qi(e=process.platform){return e!=="darwin"?!0:(await Zr().catch(()=>{}))?.hears!=="apple"}async function eo(e=process.platform){if(e!=="darwin")return{hears:!1,reads:!1};let n=await ye().catch(()=>{});return{hears:n?.speech===!0,reads:n?.read===!0}}async function sn(){let e=await Kr();if(e===void 0)throw _e(zr());return e}var Qr=new Set(["mp4","mov","m4a","mp3","wav","aiff"]);async function an(e,n){if(e.kind!=="apple")return;let{probe:t}=await import("./registry-TO6HJQJ4.js"),i=await t(n).catch(()=>{});if(i===void 0||i.kind!=="media"||Qr.has(i.format))return;let r=await He().catch(()=>{});return r?{tools:r}:void 0}async function ei(e,n,t){let i=await st(O(ft(),"forge-sound-")),r=()=>at(i,{recursive:!0,force:!0}),o=O(i,"sound.wav");try{return await new Promise((s,f)=>{let c=rn(n,["-nostdin","-v","error","-i",e,"-vn","-ac","1","-ar","16000","-c:a","pcm_s16le",o],{stdio:["ignore","ignore","pipe"],windowsHide:!0}),d="";c.stderr?.setEncoding("utf8").on("data",p=>{d+=p});let h=()=>c.kill("SIGKILL");t?.addEventListener("abort",h,{once:!0}),c.on("error",f),c.on("close",p=>{if(t?.removeEventListener("abort",h),t?.aborted)return f(t.reason??new Error("aborted"));p===0?s():f(ge(e,new Error(`ffmpeg: ${d.trim()}`)))})}),{path:o,cleanup:r}}catch(s){throw await r(),s}}async function to(e){let n=await sn(),t=await an(n,e);if(t){let{probeMedia:r}=await import("./ffmpeg-Q2WJH2OP.js"),o=await r(e,t.tools).catch(()=>{});if(o===void 0)throw Te(e);if(o.audio===void 0)throw $e(e);return{seconds:o.duration}}let i=await oe(n,["probe",e],e);return{seconds:Number(i.seconds)}}async function no(e,n){let t=await sn(),i=await an(t,e),r=i?await ei(e,i.tools.ffmpeg,n.signal):void 0;try{return await ti(t,r?.path??e,e,n)}finally{await r?.cleanup()}}async function ti(e,n,t,i){let r=["run",n,...i.locale?["--locale",i.locale]:[],...i.notes?["--notes"]:[],...i.notes&&i.detail&&i.detail!==mt?["--detail",i.detail]:[]],o=await oe(e,r,t,{signal:i.signal,onLine:s=>{let f=ni(s);f&&i.onEvent?.(f)}});return{locale:String(o.locale),seconds:Number(o.seconds),segments:o.segments,...o.notes?{notes:o.notes}:{}}}function ni(e){if(e.event==="model")return{kind:"model",fraction:Number(e.fraction)};if(e.event==="heard")return{kind:"heard",seconds:Number(e.seconds),of:Number(e.of)};if(e.event==="notes")return{kind:"notes",part:Number(e.part),of:Number(e.of)}}async function ro(e,n={}){if((await ye())?.read!==!0)return ii(e,n);let t=["read",e,...n.language?["--language",n.language]:[]];return(await oe(Vr(Re),t,e,{signal:n.signal,onLine:r=>{r.event==="page"&&n.onEvent?.({kind:"page",page:Number(r.page),of:Number(r.of)})}})).pages??[]}var ri=200,tn=4e3;async function io(){return Re(await fn())}async function fn(){let{catalogEntry:e,assetFor:n}=await import("./catalog-FMHWWMUX.js"),t=e("read-text");return t!==void 0&&n(t)!==void 0}async function ii(e,n){let t=await he("read-text");if(t===void 0)throw Re(await fn());let[{probe:i},{decodedInput:r},{loadSharp:o},{runExtension:s}]=await Promise.all([import("./registry-TO6HJQJ4.js"),import("./decoded-XWKU23RG.js"),import("./libs-EK64ACG3.js"),import("./run-GUFPETHF.js")]),f=await o(),c=await i(e),d=await st(O(ft(),"forge-read-")),h={width:tn,height:tn,fit:"inside",withoutEnlargement:!0};try{let p=[];if(c.kind==="document"&&c.format==="pdf"){let{openPdf:m}=await import("./pdfium-77L526HZ.js"),S=await m(await ot(e));try{for(let A=0;A<c.pages;A++){let w=await S.getPage(A).render({scale:ri/72,render:"bitmap"}),x=O(d,`page-${A+1}.png`);await f(Buffer.from(w.data),{raw:{width:w.width,height:w.height,channels:4}}).flatten({background:"#ffffff"}).resize(h).png().toFile(x),p.push(x)}}finally{S.destroy()}}else if(c.kind==="image"){let m=O(d,"page-1.png");await f(await r(e,c.format)).rotate().flatten({background:"#ffffff"}).resize(h).png().toFile(m),p.push(m)}else throw Te(e);let a=(await s({id:"read-text",entry:t.entry,kind:t.kind},p.flatMap(m=>["--in",m]),{subject:e,what:`Reading the text of ${e}`,...n.signal?{signal:n.signal}:{},onLine:m=>{m.event==="page"&&n.onEvent?.({kind:"page",page:Number(m.page),of:Number(m.of)})}})).pages??[];if(!(c.kind==="document"&&c.format==="pdf"))return a;let[{extractPdfText:u},{mendPage:l}]=await Promise.all([import("./pdfium-77L526HZ.js"),import("./text-layer-LHZNDMPZ.js")]),g=await u(await ot(e)).catch(()=>[]);return a.map((m,S)=>l(m,g[S]??""))}finally{await at(d,{recursive:!0,force:!0})}}async function cn(){let{apple:e}=xe();if(!(e===void 0||await ye()===void 0))return{path:e,kind:"apple"}}async function ln(e,n,t,i){let r=await st(O(ft(),"forge-render-"));try{let o=O(r,"transcript.html"),s=O(r,`transcript.${t}`);return await _r(o,n,"utf8"),await oe(e,["render",o,s,"--as",t],s,{signal:i.signal}),await ot(s)}finally{await at(r,{recursive:!0,force:!0})}}var nn=9026;async function un(e,n){let t=await ut(),{Document:i,Packer:r,Paragraph:o,TextRun:s,Table:f,TableRow:c,TableCell:d,HeadingLevel:h}=t,p="forge-numbers",b=0,a=(A,w=!1)=>Tt(A,n).map(x=>new s({text:x.text,...w?{bold:!0}:{},...x.kind==="eastAsia"?{font:{hint:"eastAsia"},language:x.lang?{eastAsia:x.lang}:{}}:{},...x.kind==="complex"?{font:{hint:"cs"},...x.rtl?{rightToLeft:!0}:{},...w?{boldComplexScript:!0}:{},...x.lang?{language:{bidirectional:x.lang}}:{}}:{}})),u=A=>pe(A)?{bidirectional:!0}:{},l=A=>A.flatMap(w=>{if(w.kind==="heading")return[new o({children:a(w.text),heading:w.level===1?h.HEADING_1:h.HEADING_2,...u(w.text)})];if(w.kind==="paragraph")return[new o({children:a(w.text),spacing:{after:160},...u(w.text)})];if(w.kind==="list"){let E=++b;return w.items.map(T=>w.ordered?new o({children:a(T),numbering:{reference:p,level:0,instance:E},...u(T)}):new o({children:a(T),bullet:{level:0},...u(T)}))}let x=w.rows[0]?.length??1;return[new f({width:{size:100,type:t.WidthType.PERCENTAGE},columnWidths:Array(x).fill(Math.floor(nn/x)),margins:{top:40,bottom:40,left:100,right:100},rows:w.rows.map((E,T)=>new c({tableHeader:T===0,children:E.map(R=>new d({width:{size:Math.floor(nn/x),type:t.WidthType.DXA},children:[new o({children:a(R,T===0),...u(R)})]}))}))}),new o({text:""})]}),m=e.filter(A=>A.length>0).flatMap((A,w)=>[...w>0?[new o({children:[new t.PageBreak]})]:[],...l(A)]),S=new i({numbering:{config:[{reference:p,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:"%1.",alignment:t.AlignmentType.START}]}]},sections:[{children:m}]});return r.toBuffer(S)}var dn=e=>({...e.lang!==void 0?{lang:e.lang}:{},...e.onMissing!==void 0?{onMissing:e.onMissing}:{}});async function oo(e,n,t,i={}){if(n==="md")return Buffer.from(St(e),"utf8");if(n==="txt")return Buffer.from(At(e),"utf8");if(n==="docx")return un(e,i.lang);let r=await cn();return r?ln(r,kt(e,t),"pdf",i):nt(e,{title:t,...dn(i)})}function oi(e){for(let n of e.flat())if(n.kind==="heading"&&n.level===1)return n.text;return"Transcript"}async function so(e,n,t={}){if(n==="md")return Buffer.from(e,"utf8");if(n==="txt")return Buffer.from(dt(e),"utf8");let i=await cn();if(i)return ln(i,pt(e),n,t);let r=ht(e);return n==="docx"?un(r,t.lang):nt(r,{title:oi(r),...dn(t)})}export{ci as a,li as b,At as c,kt as d,zr as e,Zi as f,Gr as g,xe as h,Wr as i,Zr as j,Qi as k,eo as l,to as m,no as n,ro as o,io as p,oo as q,so as r};
|
|
36
|
+
`)}var De="forge-transcribe",rt="forge-transcribe-whisper.mjs",Br=["darwin","win32","linux"];function zr(e=process.platform,n=["whisper"]){let t=n.includes("whisper")||!n.includes("ffmpeg"),i=n.includes("ffmpeg"),r=[t&&"the whisper extension (forge extensions add whisper, or /extensions)",i&&(e==="darwin"?"ffmpeg (brew install ffmpeg)":e==="win32"?"ffmpeg (winget install ffmpeg)":"ffmpeg on your PATH")].filter(Boolean);return e==="darwin"?`Transcribe on this Mac needs ${r.join(" and ")}.`:e==="win32"?`Transcribe on Windows needs ${r.join(" and ")}.`:e==="linux"?`Transcribe on Linux needs ${r.join(" and ")}.`:"Transcribe needs macOS, Windows or Linux."}function Zi(e=process.platform,n=e==="darwin"?"off":"unsupported"){return n==="off"?"Summary and notes need Apple Intelligence, and it is off.":`Summary and notes need Apple Intelligence, which this ${je(e)} does not have.`}function Gr(e){return{apple:[O(e,"helpers",De),O(e,"..","helpers",De),O(e,"..","..","dist","helpers",De)],whisper:[O(e,"helpers",rt),O(e,"..","helpers",rt),O(e,"..","..","helpers","transcribe",rt)]}}function xe(e=process.platform,n=process.env){let t=n.FORGE_TRANSCRIBE_HELPER;if(t!==void 0)return Ie(t)?t.endsWith(".mjs")?{whisper:t}:{apple:t}:{};if(!Br.includes(e))return{};let i=Gr(on(Hr(import.meta.url))),r=e==="darwin"?i.apple.find(s=>Ie(s)):void 0,o=i.whisper.find(s=>Ie(s));return{...r?{apple:r}:{},...o?{whisper:o}:{}}}async function Wr(e){return e.apple!==void 0&&e.whisper===void 0?{path:e.apple,kind:"apple"}:e.apple!==void 0&&await e.appleHears(e.apple).catch(()=>!1)?{path:e.apple,kind:"apple"}:e.whisper===void 0?void 0:{path:e.whisper,kind:"whisper"}}var en=new Map;function ye(e,n={}){let{apple:t}=xe();if(t===void 0)return Promise.resolve(void 0);let i=`${t}\0${e??""}`,r=n.fresh?void 0:en.get(i);if(r)return r;let o=["status",...e?["--locale",e]:[]],s=oe({path:t,kind:"apple"},o,"").catch(()=>{});return en.set(i,s),s}var it;function Kr(){return process.env.FORGE_TRANSCRIBE_HELPER!==void 0&&(it=void 0),it??=Wr({...xe(),appleHears:async()=>(await ye())?.speech===!0}),it}function Vr(e){let{apple:n}=xe();if(n===void 0)throw e();return{path:n,kind:"apple"}}async function Jr(){let e={...process.env,FORGE_HELPER_STOP_ON_EOF:"1"};if(!e.FORGE_FFMPEG){let n=await He().catch(()=>{});n&&(e.FORGE_FFMPEG=n.ffmpeg)}if(!e.FORGE_WHISPER_CLI){let n=await he("whisper");n&&(e.FORGE_WHISPER_CLI=n.entry)}if(!e.FORGE_WHISPER_MODEL){let n=await he("whisper"),t=n&&O(on(n.entry),"model.bin");t&&Ie(t)&&(e.FORGE_WHISPER_MODEL=t)}return e}var Yr=5e3;async function oe(e,n,t,i={}){let{signal:r}=i;if(r?.aborted)throw r.reason??new Error("aborted");let o=e.kind==="whisper",s=o?await Jr():process.env;if(r?.aborted)throw r.reason??new Error("aborted");return new Promise((f,c)=>{let d=/\.[cm]?js$/.test(e.path),[h,p]=d?[process.execPath,[e.path,...n]]:[e.path,n],b=rn(h,p,{stdio:[o?"pipe":"ignore","pipe","ignore"],env:s,windowsHide:!0});b.stdin?.on("error",()=>{});let a,u=!1,l=m=>{u||(u=!0,r?.removeEventListener("abort",g),m())},g=()=>{o&&b.stdin?(b.stdin.end(),setTimeout(()=>b.kill("SIGKILL"),Yr).unref()):b.kill("SIGKILL"),l(()=>c(r?.reason??new Error("aborted")))};r?.addEventListener("abort",g,{once:!0}),jr({input:b.stdout}).on("line",m=>{let S;try{S=JSON.parse(m)}catch{return}"ok"in S?a=S:i.onLine?.(S)}),b.on("error",m=>l(()=>c(ge(t,m)))),b.on("close",()=>l(()=>{if(a===void 0)return c(ge(t,new Error(`${De} gave no result`)));if(a.ok===!0)return f(a);c(Xr(String(a.code??""),String(a.message??""),t,n,e.kind))}))})}function Xr(e,n,t,i,r){if(e==="no-sound")return $e(t);if(e==="unreadable")return Te(t,process.platform,r);if(e==="locale"){let o=i.indexOf("--locale");return ct(o>=0?i[o+1]??"this language":`this ${je()}'s language`,process.platform,r)}return e==="unsupported"||e==="runtime"?_e(n):ge(t,new Error(`${e}: ${n}`))}var qr=["whisper","ffmpeg"];async function Zr(e={}){let n=xe();if(n.apple===void 0&&n.whisper===void 0)return;let t=await ye(e.locale,{fresh:!0}),r={read:t?.read===!0||await he("read-text")!==void 0};if(t?.speech===!0)return{speech:!0,hears:"apple",locale:typeof t.locale=="string"?t.locale:null,notes:t.notes==="available"||t.notes==="off"?t.notes:"unsupported",...r};if(n.whisper===void 0)return t===void 0?void 0:{speech:!1,locale:null,notes:"unsupported",...r};let o=["status",...e.locale?["--locale",e.locale]:[]],s=await oe({path:n.whisper,kind:"whisper"},o,""),f=Array.isArray(s.missing)?qr.filter(c=>s.missing.includes(c)):[];return{speech:s.speech===!0,...s.speech===!0?{hears:"whisper"}:{},locale:typeof s.locale=="string"?s.locale:null,notes:"unsupported",...r,...f.length>0?{missing:f}:{}}}async function Qi(e=process.platform){return e!=="darwin"?!0:(await Zr().catch(()=>{}))?.hears!=="apple"}async function eo(e=process.platform){if(e!=="darwin")return{hears:!1,reads:!1};let n=await ye().catch(()=>{});return{hears:n?.speech===!0,reads:n?.read===!0}}async function sn(){let e=await Kr();if(e===void 0)throw _e(zr());return e}var Qr=new Set(["mp4","mov","m4a","mp3","wav","aiff"]);async function an(e,n){if(e.kind!=="apple")return;let{probe:t}=await import("./registry-RS7LQ3UA.js"),i=await t(n).catch(()=>{});if(i===void 0||i.kind!=="media"||Qr.has(i.format))return;let r=await He().catch(()=>{});return r?{tools:r}:void 0}async function ei(e,n,t){let i=await st(O(ft(),"forge-sound-")),r=()=>at(i,{recursive:!0,force:!0}),o=O(i,"sound.wav");try{return await new Promise((s,f)=>{let c=rn(n,["-nostdin","-v","error","-i",e,"-vn","-ac","1","-ar","16000","-c:a","pcm_s16le",o],{stdio:["ignore","ignore","pipe"],windowsHide:!0}),d="";c.stderr?.setEncoding("utf8").on("data",p=>{d+=p});let h=()=>c.kill("SIGKILL");t?.addEventListener("abort",h,{once:!0}),c.on("error",f),c.on("close",p=>{if(t?.removeEventListener("abort",h),t?.aborted)return f(t.reason??new Error("aborted"));p===0?s():f(ge(e,new Error(`ffmpeg: ${d.trim()}`)))})}),{path:o,cleanup:r}}catch(s){throw await r(),s}}async function to(e){let n=await sn(),t=await an(n,e);if(t){let{probeMedia:r}=await import("./ffmpeg-KDZEPLNA.js"),o=await r(e,t.tools).catch(()=>{});if(o===void 0)throw Te(e);if(o.audio===void 0)throw $e(e);return{seconds:o.duration}}let i=await oe(n,["probe",e],e);return{seconds:Number(i.seconds)}}async function no(e,n){let t=await sn(),i=await an(t,e),r=i?await ei(e,i.tools.ffmpeg,n.signal):void 0;try{return await ti(t,r?.path??e,e,n)}finally{await r?.cleanup()}}async function ti(e,n,t,i){let r=["run",n,...i.locale?["--locale",i.locale]:[],...i.notes?["--notes"]:[],...i.notes&&i.detail&&i.detail!==mt?["--detail",i.detail]:[]],o=await oe(e,r,t,{signal:i.signal,onLine:s=>{let f=ni(s);f&&i.onEvent?.(f)}});return{locale:String(o.locale),seconds:Number(o.seconds),segments:o.segments,...o.notes?{notes:o.notes}:{}}}function ni(e){if(e.event==="model")return{kind:"model",fraction:Number(e.fraction)};if(e.event==="heard")return{kind:"heard",seconds:Number(e.seconds),of:Number(e.of)};if(e.event==="notes")return{kind:"notes",part:Number(e.part),of:Number(e.of)}}async function ro(e,n={}){if((await ye())?.read!==!0)return ii(e,n);let t=["read",e,...n.language?["--language",n.language]:[]];return(await oe(Vr(Re),t,e,{signal:n.signal,onLine:r=>{r.event==="page"&&n.onEvent?.({kind:"page",page:Number(r.page),of:Number(r.of)})}})).pages??[]}var ri=200,tn=4e3;async function io(){return Re(await fn())}async function fn(){let{catalogEntry:e,assetFor:n}=await import("./catalog-FMHWWMUX.js"),t=e("read-text");return t!==void 0&&n(t)!==void 0}async function ii(e,n){let t=await he("read-text");if(t===void 0)throw Re(await fn());let[{probe:i},{decodedInput:r},{loadSharp:o},{runExtension:s}]=await Promise.all([import("./registry-RS7LQ3UA.js"),import("./decoded-XWKU23RG.js"),import("./libs-EK64ACG3.js"),import("./run-GUFPETHF.js")]),f=await o(),c=await i(e),d=await st(O(ft(),"forge-read-")),h={width:tn,height:tn,fit:"inside",withoutEnlargement:!0};try{let p=[];if(c.kind==="document"&&c.format==="pdf"){let{openPdf:m}=await import("./pdfium-77L526HZ.js"),S=await m(await ot(e));try{for(let A=0;A<c.pages;A++){let w=await S.getPage(A).render({scale:ri/72,render:"bitmap"}),x=O(d,`page-${A+1}.png`);await f(Buffer.from(w.data),{raw:{width:w.width,height:w.height,channels:4}}).flatten({background:"#ffffff"}).resize(h).png().toFile(x),p.push(x)}}finally{S.destroy()}}else if(c.kind==="image"){let m=O(d,"page-1.png");await f(await r(e,c.format)).rotate().flatten({background:"#ffffff"}).resize(h).png().toFile(m),p.push(m)}else throw Te(e);let a=(await s({id:"read-text",entry:t.entry,kind:t.kind},p.flatMap(m=>["--in",m]),{subject:e,what:`Reading the text of ${e}`,...n.signal?{signal:n.signal}:{},onLine:m=>{m.event==="page"&&n.onEvent?.({kind:"page",page:Number(m.page),of:Number(m.of)})}})).pages??[];if(!(c.kind==="document"&&c.format==="pdf"))return a;let[{extractPdfText:u},{mendPage:l}]=await Promise.all([import("./pdfium-77L526HZ.js"),import("./text-layer-LHZNDMPZ.js")]),g=await u(await ot(e)).catch(()=>[]);return a.map((m,S)=>l(m,g[S]??""))}finally{await at(d,{recursive:!0,force:!0})}}async function cn(){let{apple:e}=xe();if(!(e===void 0||await ye()===void 0))return{path:e,kind:"apple"}}async function ln(e,n,t,i){let r=await st(O(ft(),"forge-render-"));try{let o=O(r,"transcript.html"),s=O(r,`transcript.${t}`);return await _r(o,n,"utf8"),await oe(e,["render",o,s,"--as",t],s,{signal:i.signal}),await ot(s)}finally{await at(r,{recursive:!0,force:!0})}}var nn=9026;async function un(e,n){let t=await ut(),{Document:i,Packer:r,Paragraph:o,TextRun:s,Table:f,TableRow:c,TableCell:d,HeadingLevel:h}=t,p="forge-numbers",b=0,a=(A,w=!1)=>Tt(A,n).map(x=>new s({text:x.text,...w?{bold:!0}:{},...x.kind==="eastAsia"?{font:{hint:"eastAsia"},language:x.lang?{eastAsia:x.lang}:{}}:{},...x.kind==="complex"?{font:{hint:"cs"},...x.rtl?{rightToLeft:!0}:{},...w?{boldComplexScript:!0}:{},...x.lang?{language:{bidirectional:x.lang}}:{}}:{}})),u=A=>pe(A)?{bidirectional:!0}:{},l=A=>A.flatMap(w=>{if(w.kind==="heading")return[new o({children:a(w.text),heading:w.level===1?h.HEADING_1:h.HEADING_2,...u(w.text)})];if(w.kind==="paragraph")return[new o({children:a(w.text),spacing:{after:160},...u(w.text)})];if(w.kind==="list"){let E=++b;return w.items.map(T=>w.ordered?new o({children:a(T),numbering:{reference:p,level:0,instance:E},...u(T)}):new o({children:a(T),bullet:{level:0},...u(T)}))}let x=w.rows[0]?.length??1;return[new f({width:{size:100,type:t.WidthType.PERCENTAGE},columnWidths:Array(x).fill(Math.floor(nn/x)),margins:{top:40,bottom:40,left:100,right:100},rows:w.rows.map((E,T)=>new c({tableHeader:T===0,children:E.map(R=>new d({width:{size:Math.floor(nn/x),type:t.WidthType.DXA},children:[new o({children:a(R,T===0),...u(R)})]}))}))}),new o({text:""})]}),m=e.filter(A=>A.length>0).flatMap((A,w)=>[...w>0?[new o({children:[new t.PageBreak]})]:[],...l(A)]),S=new i({numbering:{config:[{reference:p,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:"%1.",alignment:t.AlignmentType.START}]}]},sections:[{children:m}]});return r.toBuffer(S)}var dn=e=>({...e.lang!==void 0?{lang:e.lang}:{},...e.onMissing!==void 0?{onMissing:e.onMissing}:{}});async function oo(e,n,t,i={}){if(n==="md")return Buffer.from(St(e),"utf8");if(n==="txt")return Buffer.from(At(e),"utf8");if(n==="docx")return un(e,i.lang);let r=await cn();return r?ln(r,kt(e,t),"pdf",i):nt(e,{title:t,...dn(i)})}function oi(e){for(let n of e.flat())if(n.kind==="heading"&&n.level===1)return n.text;return"Transcript"}async function so(e,n,t={}){if(n==="md")return Buffer.from(e,"utf8");if(n==="txt")return Buffer.from(dt(e),"utf8");let i=await cn();if(i)return ln(i,pt(e),n,t);let r=ht(e);return n==="docx"?un(r,t.lang):nt(r,{title:oi(r),...dn(t)})}export{ci as a,li as b,St as c,At as d,kt as e,zr as f,Zi as g,Gr as h,xe as i,Wr as j,Zr as k,Qi as l,eo as m,to as n,no as o,ro as p,io as q,oo as r,so as s};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as D}from"./chunk-
|
|
3
|
+
import{b as D}from"./chunk-FBVRKMAF.js";import{a as X,b as Q}from"./chunk-HZDYZ5RD.js";import{j as M}from"./chunk-N32JL4UI.js";import{a as K}from"./chunk-TGC24JEW.js";import{b as J}from"./chunk-EEQSUBBL.js";import{a as W}from"./chunk-HTA25PO2.js";import{a as Y}from"./chunk-KH5DHZ2U.js";import{a as U}from"./chunk-TLHUFIXD.js";import{m as R}from"./chunk-4MJEEEFA.js";import{G as d,J as H}from"./chunk-ZBMJTIYR.js";import{d as L}from"./chunk-J7FLFHQJ.js";import{b as z}from"./chunk-H3DIRJFE.js";var O=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},k=class extends O{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var E=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new k(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function N(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as le}from"node:events";import G from"node:child_process";import C from"node:path";import F from"node:fs";import m from"node:process";import{stripVTControlCharacters as ce}from"node:util";import{stripVTControlCharacters as se}from"node:util";var T=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,r)=>i.name().localeCompare(r.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),r=n.long&&e._findOption(n.long);!i&&!r?t.push(n):n.long&&!r?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(r=>!r.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>N(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[])}),t.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[]),i.get(o).push(r)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function r(h,p){return t.formatItem(h,n,p,t)}let o=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(o=o.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let l=t.visibleArguments(e).map(h=>r(t.styleArgumentTerm(t.argumentTerm(h)),t.styleArgumentDescription(t.argumentDescription(h))));if(o=o.concat(this.formatItemList("Arguments:",l,t)),this.groupItems(e.options,t.visibleOptions(e),h=>h.helpGroupHeading??"Options:").forEach((h,p)=>{let x=h.map(_=>r(t.styleOptionTerm(t.optionTerm(_)),t.styleOptionDescription(t.optionDescription(_))));o=o.concat(this.formatItemList(p,x,t))}),t.showGlobalOptions){let h=t.visibleGlobalOptions(e).map(p=>r(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));o=o.concat(this.formatItemList("Global Options:",h,t))}return this.groupItems(e.commands,t.visibleCommands(e),h=>h.helpGroup()||"Commands:").forEach((h,p)=>{let x=h.map(_=>r(t.styleSubcommandTerm(t.subcommandTerm(_)),t.styleSubcommandDescription(t.subcommandDescription(_))));o=o.concat(this.formatItemList(p,x,t))}),o.join(`
|
|
4
4
|
`)}displayWidth(e){return se(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let o=" ".repeat(2);if(!n)return o+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),l=2,a=(this.helpWidth??80)-t-l-2,h;return a<this.minWidthToWrap||i.preformatted(n)?h=n:h=i.boxWrap(n,a).replace(/\n/g,`
|
|
5
5
|
`+" ".repeat(t+l)),o+u+" ".repeat(l)+h.replace(/\n/g,`
|
|
6
6
|
${o}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,r=[];return n.forEach(o=>{let u=o.match(i);if(u===null){r.push("");return}let l=[u.shift()],c=this.displayWidth(l[0]);u.forEach(a=>{let h=this.displayWidth(a);if(c+h<=t){l.push(a),c+=h;return}r.push(l.join(""));let p=a.trimStart();l=[p],c=this.displayWidth(p)}),r.push(l.join(""))}),r.join(`
|
|
@@ -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 E}from"./chunk-O7DK3GJT.js";import{i as R}from"./chunk-
|
|
3
|
+
import{a as E}from"./chunk-O7DK3GJT.js";import{i as R}from"./chunk-K253E723.js";import{a as F,ma as y}from"./chunk-ZBMJTIYR.js";function P(n=process.env){let r=Number(n.UV_THREADPOOL_SIZE),o=E();return Number.isInteger(r)&&r>0?Math.min(o,r):o}function w(n){let r=n!==void 0&&Number.isFinite(n)?n:void 0;return Math.max(1,r??P())}async function x(n,r,o,f){let b=[],l=[];for(let[i,u]of n.entries())(f?.(u)?l:b).push(i);let p=0,m=0,t,g=async()=>{for(;;){let i=b[p],u=t?void 0:l[m];if(i!==void 0&&(u===void 0||i<u))p++,await o(n[i],i);else if(u!==void 0)m++,t=o(n[u],u).finally(()=>{t=void 0}),await t;else if(t)await t;else return}},d=Math.min(w(r),n.length);await Promise.all(Array.from({length:d},g))}async function T(n,r){let o=r.onEvent??(()=>{}),f=r.engineFor??R,b=w(r.concurrency),l=n.length,p=[],m=[],t=0;await x(n,b,async(e,a)=>{if(r.signal?.aborted)return;o({type:"job:start",job:e,index:a,total:l});let h=f(e);if(!h){t++;let s=e.sources[0].path,c={path:s,error:y(s,new Error(`no engine runs ${e.op}`))};m[a]=c,o({type:"job:error",job:e,failure:c,completed:t,total:l});return}try{let s=await h.run(e,c=>o({type:"job:phase",job:e,progress:c}),r.signal);p[a]=s,t++,o({type:"job:done",job:e,result:s,completed:t,total:l})}catch(s){t++;let c=e.sources[0].path,J=F(s)?s:y(c,s),v={path:c,error:J};m[a]=v,o({type:"job:error",job:e,failure:v,completed:t,total:l})}},e=>f(e)?.alone===!0);let d=p.filter(e=>e!==void 0),i=m.filter(e=>e!==void 0),u={results:d,failures:i,inputBytes:d.reduce((e,a)=>e+a.job.sources[0].bytes,0),outputBytes:d.reduce((e,a)=>e+a.outputBytes,0)};return o({type:"batch:done",summary:u}),u}export{P as a,w as b,x as c,T as d};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as h,c as A,g as o,m as y,n as I,t as v,u as O,v as P}from"./chunk-
|
|
3
|
+
import{b as h,c as A,g as o,m as y,n as I,t as v,u as O,v as P}from"./chunk-BKLPRILS.js";import{a as x,b as u,d as S}from"./chunk-K253E723.js";import{g as s,h as f,j as g,k as b,l as c,m as a}from"./chunk-V6GWPR2A.js";import{G as d}from"./chunk-ZBMJTIYR.js";var l=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0,k={id:"split",label:"Split",verb:"Splitting",hint:"into several files",appliesTo:e=>(l(e)?.pages??0)>1,unavailable:e=>l(e)===void 0?"one PDF at a time":"only one page",options(e){let t=l(e);return t?[{kind:"select",id:"mode",label:"How",default:"every-page",choices:[{value:"every-page",label:"Every page",hint:`${t.pages} files`},{value:"every-n",label:"Every N pages",hint:"ask how many"},{value:"points",label:"At points I choose",hint:"grid"}]}]:[]},plan(e,t){let n=l(e);if(!n)return[];let r=Array.isArray(t.cuts)?t.cuts:[],i=S(r,n.pages).length,C=c(f(n.path,i),o(t.destination),o(t.name));return[{op:"split",sources:[n],outputs:C,cuts:r}]}};function $(e){return Array.from({length:Math.max(0,e-1)},(t,n)=>n)}function B(e,t){if(!Number.isInteger(t)||t<1)throw d("Splitting every N pages needs N to be a whole number, at least 1.");let n=[];for(let r=t;r<e;r+=t)n.push(r-1);return n}var p=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0;function D(e,t){return Array.isArray(t.pages)?u(t.pages):typeof t.pages=="string"?u(x(t.pages,e.pages)):[]}var w=e=>({kind:"text",id:"pages",label:"Pages",placeholder:`1-${e.pages}`}),T={id:"extract",label:"Extract",verb:"Extracting",hint:"keep only some pages",appliesTo:e=>p(e)!==void 0,unavailable:()=>"one PDF at a time",options:e=>{let t=p(e);return t?[w(t),{kind:"select",id:"separate",label:"Output",default:"one",choices:[{value:"one",label:"One file",hint:"all selected pages together"},{value:"many",label:"Separate files",hint:"one per page"}]}]:[]},plan(e,t){let n=p(e);if(!n)return[];let r=D(n,t),i=t.separate==="many";return[{op:"extract",sources:[n],outputs:c(g(n.path,r,i),o(t.destination),o(t.name)),pages:r,separate:i}]}},j={id:"delete",label:"Delete",verb:"Deleting",hint:"drop some pages",appliesTo:e=>p(e)!==void 0,unavailable:()=>"one PDF at a time",options:e=>{let t=p(e);return t?[w(t)]:[]},plan(e,t){let n=p(e);return n?[{op:"delete",sources:[n],outputs:[a(s(n.path,"trimmed"),o(t.destination),o(t.name))],pages:D(n,t)}]:[]}};var m=e=>e.filter(t=>t.kind==="document"&&t.format==="pdf"),J={id:"merge",label:"Merge",verb:"Merging",hint:"several files into one",appliesTo:e=>m(e).length>=2&&m(e).length===e.length,unavailable:e=>m(e).length!==e.length?"PDFs only":"needs 2+ files",options:()=>[],plan(e,t){let n=a(b(e.map(r=>r.path)),o(t.destination),o(t.name));return[{op:"merge",sources:e,outputs:[n]}]}};var N=e=>e.length===1&&e[0]?.kind==="document"&&e[0].format==="pdf"?e[0]:void 0,E={id:"rotate",label:"Rotate",verb:"Rotating",hint:"turn pages",appliesTo:e=>N(e)!==void 0,unavailable:()=>"one PDF at a time",options:()=>[{kind:"select",id:"degrees",label:"Turn",default:"90",choices:[{value:"90",label:"90\xB0 right",hint:"a quarter turn"},{value:"180",label:"180\xB0",hint:"upside down"},{value:"270",label:"90\xB0 left",hint:"a quarter turn back"}]}],plan(e,t){let n=N(e);if(!n)return[];let i=Number(t.degrees??90)/90%4||1;return[{op:"rotate",sources:[n],outputs:[a(s(n.path,"rotated"),o(t.destination),o(t.name))],turns:i}]}};var R=[I,y,J,k,T,j,E,v,O,P],se=R.filter(e=>!["convert","compress","trim","resize","crop"].includes(e.id)),F=[h,A];function ce(e,t=new Set){return[...R,...F.filter(n=>n.requires&&t.has(n.requires))].filter(n=>n.appliesTo(e))}function le(e,t){return e.appliesTo(t)?void 0:e.unavailable?.(t)}export{E as a,k as b,$ as c,B as d,R as e,se as f,ce as g,le as h};
|
|
@@ -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,c as G}from"./chunk-Q6KQWJ4J.js";import{d as W,f as y,g as K}from"./chunk-6HQKTDGG.js";import{a as Q,b as X,e as w}from"./chunk-U3D3EU33.js";import{a as H,b as P}from"./chunk-RRVD63NF.js";import{a as h,d as R}from"./chunk-N6RCLJE6.js";import{i as F,j as U,k as g}from"./chunk-TLHUFIXD.js";import{d as I,l as z}from"./chunk-4MJEEEFA.js";import{b as B,c as J,d as L,e as u,i as _,m as O}from"./chunk-V6GWPR2A.js";import{G as k,u as N}from"./chunk-ZBMJTIYR.js";import{a as s,b as D,c as $}from"./chunk-H3DIRJFE.js";var M=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0;function Gt(t,e){let n=Q(t);return n.includes(e)?void 0:N(t,e,n)}function V(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 Y=()=>({kind:"select",id:"target",label:"Save as",default:"png",choices:[{value:"png",label:"PNG",hint:s.png.hint}]}),dt=t=>t===1?"sharp":`${t}x`,ut=t=>t===1||t===3||t===4?t:2,Ht={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=>M(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"}]},Y()],plan(t,e){let n=M(t);if(!n)return[];let o=V(e),i=ut(Number(e.scale??2));return n.map(r=>({op:"boost",sources:[r],outputs:[u({sourcePath:r.path,target:o.target,suffix:dt(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}}}))}},Wt={id:"remove-background",label:"Remove background",verb:"Removing",hint:"cut out the subject",requires:"remove-background",appliesTo:t=>M(t)!==void 0,unavailable:()=>"images only",options:()=>[Y()],plan(t,e){let n=M(t);if(!n)return[];let o=V(e);return n.map(i=>({op:"remove-background",sources:[i],outputs:[u({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 ft=[{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"}],S=t=>t===90||t===180||t===270,Vt=(t,e)=>e===180?{...t}:{width:t.height,height:t.width},T=t=>ft.find(e=>e.degrees===t).suffix;import{dirname as ct,join as Z}from"node:path";var q="Same location",v="New subfolder";function mt(t,e,n){return t===e?q:t===h("Desktop")?"Desktop":t===h("Downloads")?"Downloads":e!==void 0&&n!==void 0&&t===Z(e,n)?v:b(t)||t}function A(t,e,n={}){return lt(ct(t.path),e,n)}function lt(t,e,{subfolder:n}={}){let o=R(e.defaultOutput),i=e.lastOutput?R(e.lastOutput):void 0,r=f=>({label:mt(f,t,n),path:f}),a=[r(o),...i?[r(i)]:[],r(h("Desktop")),...t===void 0?[]:[{label:q,path:t}],r(h("Downloads")),...n!==void 0&&t!==void 0?[{label:v,path:Z(t,n)}]:[]],p=new Set,d=a.filter(f=>p.has(f.path)?!1:(p.add(f.path),!0));return{kind:"path",id:"destination",label:"Save to",default:o,presets:d,...i&&i!==o?{last:i}:{}}}var c=t=>typeof t=="string"&&t!==""?t:void 0;var pe=[2,1.5,1.25,.75,.5],gt=.25,ht=4,tt=-16;function nt(t){return{wav:"m4a",aiff:"m4a",flac:"m4a",avi:"mp4",ogg:"opus"}[t]??t}var et=t=>t.length===1&&t[0]?.kind==="media"?t[0]:void 0,bt=t=>t==="cut"||t==="mute"||t==="speed"||t==="resize"||t==="crop"||t==="rotate"||t==="loudness"||t==="extract"||t==="cleanup";function yt(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(z(e.crop.aspect)),e.resize&&i.push(o?y(g(o,e.resize)):"resized"),e.rotate&&i.push(T(e.rotate)),i.length===1?i[0]:"edited"}function St(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??I(r,e.crop.aspect)});let a=e.roots?.get(n.path),p=u({sourcePath:n.path,target:o,suffix:yt(n,e),...e.output===void 0?{}:{output:e.output},...a===void 0?{}:{sourceRoot:a}});return{op:"convert",sources:[n],outputs:[O(p,c(e.destination),c(e.name))],target:o,options:i}})}function x(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 de={id:"media-edit",label:"Edit",verb:"Editing",hint:"trim, mute, speed, resize, rotate, crop",appliesTo:t=>et(t)!==void 0,unavailable:()=>"one video or audio file",options:()=>[],plan(t,e){let n=et(t);if(!n||!bt(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=x(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<gt||r>ht)return[];i.media={speed:r}}if(o==="loudness"&&(i.media={loudness:typeof e.loudness=="number"?e.loudness:tt}),o==="cleanup"){if(!n.facts?.audio)return[];i.media={cleanup:!0,loudness:tt}}if(o==="extract"){let r=n.facts?.audio;if(!r||!n.facts?.video)return[];i.extract=!0,i.target=G(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||!S(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 St([n],i)}};import{dirname as xt,join as kt}from"node:path";var It=t=>s[t.format].media==="video",zt=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,Ot=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,Mt="-small",m={min:30,max:100,step:35},Tt=t=>{let e=Math.ceil((t-m.min)/m.step);return Math.min(m.max,m.min+Math.max(0,e)*m.step)},ye={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=zt(t);if(e!==void 0){let o=s[e.format];return o.lossy||o.quantisable===!0}return(Ot(t)?.images?.compressible??0)>0},options(t,e,n){let o=t[0];if(!o)return[];let i=[{kind:"select",id:"mode",label:`Compress ${b(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"&&!It(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"&&s[o.format].quantisable===!0;i.push(r?{kind:"slider",id:"quality",label:"Quality",...m,default:Tt(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(A(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=(b(o.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:xt(o.path),a=o.kind==="media"?nt(o.format):o.format,p=kt(r,B(i,`${Mt}${$(a)}`)),d=o.kind==="media"?x(e):void 0;return[{op:"convert",sources:[o],target:a,outputs:[p],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...d?{media:d}:{}}}]}};function At(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 Ft(){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 Rt(t,e){return Array.isArray(e)?P(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?P(H(e,t.pages)):Array.from({length:t.pages},(n,o)=>o)}function wt(t,e){let n=s[t.format].lossy,o=s[e].lossy;if(n&&!o)return{hint:"likely bigger",tone:"warn"};if(!n&&o)return{hint:"likely smaller",tone:"ok"}}function Pt(t){let e=X(t).filter(o=>o.id!==t.format),n=e[0];return{kind:"select",id:"target",label:`Convert ${s[t.format].label} to`,choices:e.map(o=>{let i=wt(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 Et(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var Ct=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function jt(t){let e=t.target,n=typeof e=="string"?D(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 Ae={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=[Pt(o)],r=e.target;if(typeof r!="string")return i;o.kind==="document"&&w(r)&&i.push(At(o),Ft());let a=s[r];return o.kind==="media"?a?.media==="sound"&&a.lossy&&i.push(Et(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(A(o,n)),i},plan(t,e){let n=t[0];if(!n)return[];let o=jt(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 d=x(e);d&&(r.media=d),Ct(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&w(i)){let d=Number(e.dpi);r.dpi=Number.isFinite(d)&&d>0?d:150;let f=Rt(n,e.pages);r.pages=f;let st=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,pt=_(n.path,f,i,a,st);return[{op:"convert",sources:[n],outputs:pt,target:i,options:r}]}let p=L({sourcePath:n.path,target:i,...a===void 0?{}:{output:`${a}/`}});return J(p,n.path)&&(p=u({sourcePath:n.path,target:i,suffix:i,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[p],target:i,options:r}]}};var Dt=[16,4,2],E=t=>typeof t=="number"&&Dt.includes(t),ot=t=>`dithered-${t}`,we=t=>`${t} colours`,it=t=>s[t.format].quantisable?t.format:"png",C=t=>!(t.frames>1)||t.format==="gif";function $t(t,e){if(e.dither)return ot(e.dither);if(e.deband)return U(e.deband);if(!e.rotate)return rt(t,e);let n=T(e.rotate);return e.trim||e.crop||e.resize?`${rt(t,e)}-${n}`:n}function rt(t,e){if(e.crop){let n=z(e.crop.aspect);if(!e.resize)return n;let o=e.crop.box??I(t,e.crop.aspect);return`${n}-${y(g(o,e.resize))}`}return e.trim&&e.resize?`trimmed-${K(e.resize)}`:e.resize?y(g(t,e.resize)):"trimmed"}function Nt(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??(e.dither?it(n):W(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}:{},...e.dither?{dither:e.dither}:{},...e.deband?{deband:e.deband}:{},...e.deband&&e.quality===void 0&&s[o].lossy?{quality:95}:{}},r=e.roots?.get(n.path),a=u({sourcePath:n.path,target:o,suffix:$t(n,e),...e.output===void 0?{}:{output:e.output},...r===void 0?{}:{sourceRoot:r}});return{op:"convert",sources:[n],outputs:[O(a,c(e.destination),c(e.name))],target:o,options:i}})}var j=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0,Bt=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t),at=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 l(t,e,n,o){return{id:t,label:e,verb:n,hint:o,appliesTo:i=>j(i)?.every(r=>t==="resize"?!0:t==="dither"?C(r):r.frames<=1)===!0,unavailable:i=>j(i)?"animated":"images only",options:()=>[],plan(i,r){let a=j(i);return a?t==="crop"&&!at(r.crop)?[]:t==="turn"&&!S(r.turn)?[]:t==="deband"&&(!F(r.deband)||a.some(p=>p.frames>1))?[]:t==="dither"&&(!E(r.dither)||!a.every(C))?[]:Nt(a,{trim:t==="trim"||r.trim===!0,...S(r.turn)?{rotate:r.turn}:{},...t==="dither"&&E(r.dither)?{dither:r.dither}:{},...t==="deband"&&F(r.deband)?{deband:r.deband}:{},...Bt(r.resize)?{resize:r.resize}:{},...at(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 Le=l("trim","Trim edges","Trimming edges","cut empty borders"),_e=l("resize","Resize","Resizing","smaller or larger"),Ue=l("crop","Crop to shape","Cropping","change the shape"),Qe=l("turn","Rotate","Rotating","turn it"),Xe=l("dither","Dither","Dithering","fewer colours, scattered"),Ge=l("deband","Remove banding","Removing banding","smooth out stripes");export{Gt as a,Ht as b,Wt as c,v as d,A as e,lt as f,c as g,ft as h,Vt as i,pe as j,St as k,de as l,ye as m,Ae as n,Dt as o,we as p,it as q,C as r,Nt as s,Le as t,_e as u,Ue as v,Qe as w,Xe as x,Ge as y};
|
|
3
|
+
import{a as b,c as G}from"./chunk-Q6KQWJ4J.js";import{d as W,f as y,g as K}from"./chunk-FBVRKMAF.js";import{a as Q,b as X,e as w}from"./chunk-3374PCO5.js";import{a as H,b as P}from"./chunk-K253E723.js";import{a as h,d as R}from"./chunk-N6RCLJE6.js";import{i as F,j as U,k as g}from"./chunk-TLHUFIXD.js";import{d as I,l as z}from"./chunk-4MJEEEFA.js";import{b as B,c as J,d as L,e as u,i as _,m as O}from"./chunk-V6GWPR2A.js";import{G as k,u as N}from"./chunk-ZBMJTIYR.js";import{a as s,b as D,c as $}from"./chunk-H3DIRJFE.js";var M=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0;function Gt(t,e){let n=Q(t);return n.includes(e)?void 0:N(t,e,n)}function V(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 Y=()=>({kind:"select",id:"target",label:"Save as",default:"png",choices:[{value:"png",label:"PNG",hint:s.png.hint}]}),dt=t=>t===1?"sharp":`${t}x`,ut=t=>t===1||t===3||t===4?t:2,Ht={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=>M(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"}]},Y()],plan(t,e){let n=M(t);if(!n)return[];let o=V(e),i=ut(Number(e.scale??2));return n.map(r=>({op:"boost",sources:[r],outputs:[u({sourcePath:r.path,target:o.target,suffix:dt(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}}}))}},Wt={id:"remove-background",label:"Remove background",verb:"Removing",hint:"cut out the subject",requires:"remove-background",appliesTo:t=>M(t)!==void 0,unavailable:()=>"images only",options:()=>[Y()],plan(t,e){let n=M(t);if(!n)return[];let o=V(e);return n.map(i=>({op:"remove-background",sources:[i],outputs:[u({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 ft=[{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"}],S=t=>t===90||t===180||t===270,Vt=(t,e)=>e===180?{...t}:{width:t.height,height:t.width},T=t=>ft.find(e=>e.degrees===t).suffix;import{dirname as ct,join as Z}from"node:path";var q="Same location",v="New subfolder";function mt(t,e,n){return t===e?q:t===h("Desktop")?"Desktop":t===h("Downloads")?"Downloads":e!==void 0&&n!==void 0&&t===Z(e,n)?v:b(t)||t}function A(t,e,n={}){return lt(ct(t.path),e,n)}function lt(t,e,{subfolder:n}={}){let o=R(e.defaultOutput),i=e.lastOutput?R(e.lastOutput):void 0,r=f=>({label:mt(f,t,n),path:f}),a=[r(o),...i?[r(i)]:[],r(h("Desktop")),...t===void 0?[]:[{label:q,path:t}],r(h("Downloads")),...n!==void 0&&t!==void 0?[{label:v,path:Z(t,n)}]:[]],p=new Set,d=a.filter(f=>p.has(f.path)?!1:(p.add(f.path),!0));return{kind:"path",id:"destination",label:"Save to",default:o,presets:d,...i&&i!==o?{last:i}:{}}}var c=t=>typeof t=="string"&&t!==""?t:void 0;var pe=[2,1.5,1.25,.75,.5],gt=.25,ht=4,tt=-16;function nt(t){return{wav:"m4a",aiff:"m4a",flac:"m4a",avi:"mp4",ogg:"opus"}[t]??t}var et=t=>t.length===1&&t[0]?.kind==="media"?t[0]:void 0,bt=t=>t==="cut"||t==="mute"||t==="speed"||t==="resize"||t==="crop"||t==="rotate"||t==="loudness"||t==="extract"||t==="cleanup";function yt(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(z(e.crop.aspect)),e.resize&&i.push(o?y(g(o,e.resize)):"resized"),e.rotate&&i.push(T(e.rotate)),i.length===1?i[0]:"edited"}function St(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??I(r,e.crop.aspect)});let a=e.roots?.get(n.path),p=u({sourcePath:n.path,target:o,suffix:yt(n,e),...e.output===void 0?{}:{output:e.output},...a===void 0?{}:{sourceRoot:a}});return{op:"convert",sources:[n],outputs:[O(p,c(e.destination),c(e.name))],target:o,options:i}})}function x(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 de={id:"media-edit",label:"Edit",verb:"Editing",hint:"trim, mute, speed, resize, rotate, crop",appliesTo:t=>et(t)!==void 0,unavailable:()=>"one video or audio file",options:()=>[],plan(t,e){let n=et(t);if(!n||!bt(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=x(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<gt||r>ht)return[];i.media={speed:r}}if(o==="loudness"&&(i.media={loudness:typeof e.loudness=="number"?e.loudness:tt}),o==="cleanup"){if(!n.facts?.audio)return[];i.media={cleanup:!0,loudness:tt}}if(o==="extract"){let r=n.facts?.audio;if(!r||!n.facts?.video)return[];i.extract=!0,i.target=G(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||!S(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 St([n],i)}};import{dirname as xt,join as kt}from"node:path";var It=t=>s[t.format].media==="video",zt=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,Ot=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,Mt="-small",m={min:30,max:100,step:35},Tt=t=>{let e=Math.ceil((t-m.min)/m.step);return Math.min(m.max,m.min+Math.max(0,e)*m.step)},ye={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=zt(t);if(e!==void 0){let o=s[e.format];return o.lossy||o.quantisable===!0}return(Ot(t)?.images?.compressible??0)>0},options(t,e,n){let o=t[0];if(!o)return[];let i=[{kind:"select",id:"mode",label:`Compress ${b(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"&&!It(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"&&s[o.format].quantisable===!0;i.push(r?{kind:"slider",id:"quality",label:"Quality",...m,default:Tt(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(A(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=(b(o.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:xt(o.path),a=o.kind==="media"?nt(o.format):o.format,p=kt(r,B(i,`${Mt}${$(a)}`)),d=o.kind==="media"?x(e):void 0;return[{op:"convert",sources:[o],target:a,outputs:[p],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...d?{media:d}:{}}}]}};function At(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 Ft(){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 Rt(t,e){return Array.isArray(e)?P(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?P(H(e,t.pages)):Array.from({length:t.pages},(n,o)=>o)}function wt(t,e){let n=s[t.format].lossy,o=s[e].lossy;if(n&&!o)return{hint:"likely bigger",tone:"warn"};if(!n&&o)return{hint:"likely smaller",tone:"ok"}}function Pt(t){let e=X(t).filter(o=>o.id!==t.format),n=e[0];return{kind:"select",id:"target",label:`Convert ${s[t.format].label} to`,choices:e.map(o=>{let i=wt(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 Et(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var Ct=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function jt(t){let e=t.target,n=typeof e=="string"?D(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 Ae={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=[Pt(o)],r=e.target;if(typeof r!="string")return i;o.kind==="document"&&w(r)&&i.push(At(o),Ft());let a=s[r];return o.kind==="media"?a?.media==="sound"&&a.lossy&&i.push(Et(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(A(o,n)),i},plan(t,e){let n=t[0];if(!n)return[];let o=jt(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 d=x(e);d&&(r.media=d),Ct(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&w(i)){let d=Number(e.dpi);r.dpi=Number.isFinite(d)&&d>0?d:150;let f=Rt(n,e.pages);r.pages=f;let st=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,pt=_(n.path,f,i,a,st);return[{op:"convert",sources:[n],outputs:pt,target:i,options:r}]}let p=L({sourcePath:n.path,target:i,...a===void 0?{}:{output:`${a}/`}});return J(p,n.path)&&(p=u({sourcePath:n.path,target:i,suffix:i,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[p],target:i,options:r}]}};var Dt=[16,4,2],E=t=>typeof t=="number"&&Dt.includes(t),ot=t=>`dithered-${t}`,we=t=>`${t} colours`,it=t=>s[t.format].quantisable?t.format:"png",C=t=>!(t.frames>1)||t.format==="gif";function $t(t,e){if(e.dither)return ot(e.dither);if(e.deband)return U(e.deband);if(!e.rotate)return rt(t,e);let n=T(e.rotate);return e.trim||e.crop||e.resize?`${rt(t,e)}-${n}`:n}function rt(t,e){if(e.crop){let n=z(e.crop.aspect);if(!e.resize)return n;let o=e.crop.box??I(t,e.crop.aspect);return`${n}-${y(g(o,e.resize))}`}return e.trim&&e.resize?`trimmed-${K(e.resize)}`:e.resize?y(g(t,e.resize)):"trimmed"}function Nt(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??(e.dither?it(n):W(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}:{},...e.dither?{dither:e.dither}:{},...e.deband?{deband:e.deband}:{},...e.deband&&e.quality===void 0&&s[o].lossy?{quality:95}:{}},r=e.roots?.get(n.path),a=u({sourcePath:n.path,target:o,suffix:$t(n,e),...e.output===void 0?{}:{output:e.output},...r===void 0?{}:{sourceRoot:r}});return{op:"convert",sources:[n],outputs:[O(a,c(e.destination),c(e.name))],target:o,options:i}})}var j=t=>t.length>0&&t.every(e=>e.kind==="image")?t:void 0,Bt=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t),at=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 l(t,e,n,o){return{id:t,label:e,verb:n,hint:o,appliesTo:i=>j(i)?.every(r=>t==="resize"?!0:t==="dither"?C(r):r.frames<=1)===!0,unavailable:i=>j(i)?"animated":"images only",options:()=>[],plan(i,r){let a=j(i);return a?t==="crop"&&!at(r.crop)?[]:t==="turn"&&!S(r.turn)?[]:t==="deband"&&(!F(r.deband)||a.some(p=>p.frames>1))?[]:t==="dither"&&(!E(r.dither)||!a.every(C))?[]:Nt(a,{trim:t==="trim"||r.trim===!0,...S(r.turn)?{rotate:r.turn}:{},...t==="dither"&&E(r.dither)?{dither:r.dither}:{},...t==="deband"&&F(r.deband)?{deband:r.deband}:{},...Bt(r.resize)?{resize:r.resize}:{},...at(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 Le=l("trim","Trim edges","Trimming edges","cut empty borders"),_e=l("resize","Resize","Resizing","smaller or larger"),Ue=l("crop","Crop to shape","Cropping","change the shape"),Qe=l("turn","Rotate","Rotating","turn it"),Xe=l("dither","Dither","Dithering","fewer colours, scattered"),Ge=l("deband","Remove banding","Removing banding","smooth out stripes");export{Gt as a,Ht as b,Wt as c,v as d,A as e,lt as f,c as g,ft as h,Vt as i,pe as j,St as k,de as l,ye as m,Ae as n,Dt as o,we as p,it as q,C as r,Nt as s,Le as t,_e as u,Ue as v,Qe as w,Xe as x,Ge as y};
|
|
@@ -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 o}from"./chunk-
|
|
3
|
+
import{a as o}from"./chunk-3374PCO5.js";import{f as n}from"./chunk-K253E723.js";import{G as i}from"./chunk-ZBMJTIYR.js";import{a as r}from"./chunk-H3DIRJFE.js";var I=5,h=200,x=5;function z(t){return t.format==="heic"||t.format==="raw"?"jpeg":o(t).includes(t.format)?t.format:"png"}function E(t,m){let e=n.find(f=>f.id==="image")?.writes;if(!e?.has(t))return i(`Cannot ${m} into ${r[t].label}; only an image format can take the edit.`,`Choose one of: ${[...e??[]].join(", ")}.`)}var c=t=>`${t.width}x${t.height}`,u=t=>"percent"in t?`${t.percent}pct`:"width"in t?`${t.width}w`:`${t.height}h`;export{I as a,h as b,x as c,z as d,E as e,c as f,u as g};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a as w,b as I,d as k,e as m}from"./chunk-W53XNVNH.js";import{a as $,c as O}from"./chunk-SM735FG7.js";import{b as h,d as P,e as R}from"./chunk-
|
|
3
|
+
import{a as w,b as I,d as k,e as m}from"./chunk-W53XNVNH.js";import{a as $,c as O}from"./chunk-SM735FG7.js";import{b as h,d as P,e as R}from"./chunk-6MWJO3GB.js";import{f as x}from"./chunk-YJ6XLDRA.js";import{a as l}from"./chunk-TGC24JEW.js";import{j as B}from"./chunk-K253E723.js";import{$ as C,_ as g,ba as v}from"./chunk-ZBMJTIYR.js";import{a as f}from"./chunk-J7FLFHQJ.js";import{b as p}from"./chunk-VLVNA4T3.js";import{a as c}from"./chunk-H3DIRJFE.js";import{dirname as S,join as q}from"node:path";async function T(t){if(t.fallback!==void 0)return t.fallback;let{loadPreferences:r,expandTilde:e}=await import("./preferences-3P4V2EDX.js");return e((await r()).prefs.defaultOutput)}function F(t){if(t.pasteboard)return t.pasteboard;if(!$())throw C();return O()}function E(t,r,e,o){let a=q(r.outDir,`Copied image${c[o].extensions[0]}`),s={inputs:[r.source],output:a,force:!1,recursive:!1,debug:t.debug},n={background:"#ffffff",keepMetadata:!1,...t.quality===void 0?{}:{quality:t.quality}};return o===e?{kind:"compress",...s,options:n,...t.quality===void 0?{}:{quality:t.quality},...t.maxBytes===void 0?{}:{maxBytes:t.maxBytes}}:{kind:"convert",...s,target:o,options:n,...t.maxBytes===void 0?{}:{maxBytes:t.maxBytes}}}async function J(t,r={}){let e=r.clip??{},o=F(e),a=await w(o,e.root);if(!a)throw g((await o.peek()).text?"text":"nothing");let s=await B(a.source),n=t.target??s.format,b=E(t,a,s.format,n),i=await P(b,r),y=i.results[0];if(!y||i.failures.length>0)return{report:i,status:"failed"};let u=y.job.outputs[0],d={report:i,output:u,source:{format:s.format,bytes:s.bytes},target:n};if(await I(o,a,u,n)==="changed")return{...d,status:"changed",saved:await m(u,await T(e))};if(t.save===void 0)return{...d,status:"placed"};let j=t.save===!0?await T(e):t.save,{expandTilde:D}=await import("./preferences-3P4V2EDX.js");return{...d,status:"placed",saved:await m(u,D(j))}}function N(t){let r=t.target===t.source.format?"":` as ${c[t.target].label}`,e=` ${f(t.source.bytes)} \u2192 ${f(t.report.outputBytes)} \xB7 ${h(t.source.bytes,t.report.outputBytes)}`;if(t.status==="changed"){let a=t.target===t.source.format?"compressed":"converted";return[`\u2713 Copied image \u2192 ${p(t.saved)}${r}`,e,"","\u26A0 Clipboard changed"," The file you uploaded is no longer in the clipboard.",` The ${a} image is saved to ${p(S(t.saved))}.`]}let o=t.saved===void 0?"":` + ${p(t.saved)}`;return[`\u2713 Copied image \u2192 clipboard${r}${o}`,e]}async function U(t){if(!await k(F(t),t.root))throw v()}async function Z(t,r){if(t.undo)return await U(r.clip??{}),{exitCode:0,stdout:r.json?[JSON.stringify({forge:l,ok:!0,clipboard:"restored"})]:["\u2713 The original is back on the clipboard"],stderr:[]};let e=await J(t,r);if(e.status==="failed")return R(e.report,r);if(r.json){let o={...x(l,e.report),clipboard:e.status,...e.saved===void 0?{}:{saved:e.saved}};return{exitCode:0,stdout:[JSON.stringify(o)],stderr:[]}}return{exitCode:0,stdout:N(e),stderr:[]}}export{J as a,N as b,U as c,Z as d};
|
|
@@ -2,5 +2,5 @@ import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
3
|
import{a as l,c}from"./chunk-MF3KKEFB.js";import{e as p,f as u}from"./chunk-I25E2XDH.js";import{execFile as P}from"node:child_process";import{access as N,constants as A,mkdir as I,readFile as E,realpath as _,writeFile as F}from"node:fs/promises";import{homedir as B}from"node:os";import{dirname as C,join as f,posix as R,sep as m,win32 as S}from"node:path";import{promisify as T}from"node:util";var w=T(P),H=["yt-dlp","video"],X=e=>H.includes(e),a={"yt-dlp":{binary:"yt-dlp",name:"yt-dlp",formula:"yt-dlp",versionArgs:["--version"],version:e=>e.trim().split(`
|
|
4
4
|
`)[0]?.match(/^\d+(\.\d+)+$/)?.[0]},video:{binary:"ffmpeg",name:"ffmpeg",formula:"ffmpeg",versionArgs:["-hide_banner","-version"],version:e=>e.match(/ffmpeg version (\S+)/)?.[1],beside:["ffprobe"]}},Y=e=>a[e].name,q=e=>a[e].formula;function $(e,n){let r=e.split(".").map(Number),i=n.split(".").map(Number);for(let t=0;t<Math.max(r.length,i.length);t++){let o=r[t]??0,s=i[t]??0;if(Number.isNaN(o)||Number.isNaN(s))return e>n;if(o!==s)return o>s}return!1}function g(e){let n=p(e);return n&&(u(n)?.version??u(n,"darwin","universal")?.version)}function y({platform:e=process.platform,env:n=process.env,deep:r=!1}={}){let t=(n.PATH??n.Path??"").split(e==="win32"?";":":").filter(Boolean);if(e==="darwin"&&t.push("/opt/homebrew/bin","/usr/local/bin"),r){let o=n.HOME??B(),{join:s}=e==="win32"?S:R;t.push(s(o,".local","bin"),s(o,"bin"),"/opt/local/bin","/usr/bin")}return[...new Set(t)]}var O=(e,n=process.platform)=>n==="win32"?`${e}.exe`:e;async function d(e){try{return await N(e,A.X_OK),!0}catch{return!1}}async function b(e,n){let r=a[e];if(await d(n)){for(let i of r.beside??[])if(!await d(f(C(n),O(i))))return;try{let{stdout:i}=await w(n,r.versionArgs,{timeout:5e3}),t=r.version(i);if(t===void 0)return;let o=await _(n).catch(()=>n),s=g(e);return{id:e,path:n,version:t,homebrew:o.includes(`${m}Cellar${m}`),tooOld:e==="yt-dlp"&&s!==void 0&&$(s,t)}}catch{return}}}var h=()=>f(l(),"own.json");async function v(){try{let e=JSON.parse(await E(h(),"utf8"));return typeof e=="object"&&e!==null?e:{}}catch{return{}}}async function j(e){let n=(await v())[e];return typeof n=="string"&&n!==""?n:void 0}async function z(e,n){let r=await v();n===void 0?delete r[e]:r[e]=n,await I(l(),{recursive:!0}),await F(h(),`${JSON.stringify(r,null,2)}
|
|
5
|
-
`)}async function J(e,n={}){let r=await j(e);if(r!==void 0){let o=await b(e,r);if(o)return o}let t=process.env.FORGE_NO_OWN_TOOLS==="1"&&n.dirs===void 0?[]:n.dirs??y({deep:n.deep??!1});for(let o of t){let s=await b(e,f(o,O(a[e].binary)));if(s)return s}}async function k(e){if(await c(e)===void 0)return 0;try{let{removeExtension:n,extensionBytes:r}=await import("./manager-
|
|
5
|
+
`)}async function J(e,n={}){let r=await j(e);if(r!==void 0){let o=await b(e,r);if(o)return o}let t=process.env.FORGE_NO_OWN_TOOLS==="1"&&n.dirs===void 0?[]:n.dirs??y({deep:n.deep??!1});for(let o of t){let s=await b(e,f(o,O(a[e].binary)));if(s)return s}}async function k(e){if(await c(e)===void 0)return 0;try{let{removeExtension:n,extensionBytes:r}=await import("./manager-L753MI7U.js"),i=await r(e);return await n(e)?i:0}catch{return 0}}async function Q(e={}){let n=await J("yt-dlp",e);if(n&&!n.tooOld)return await k("yt-dlp"),{entry:n.path,own:!0};let r=await c("yt-dlp");return r?{entry:r.entry,own:!1}:void 0}async function x(e){if(e.brew!==void 0)return await d(e.brew)?e.brew:void 0;for(let n of y({env:{PATH:process.env.PATH??""}})){let r=f(n,"brew");if(await d(r))return r}}async function V(e,n={}){if(e.tooOld)return g(e.id);if(!e.homebrew)return;let r=await x(n);if(r!==void 0)try{let{stdout:i}=await w(r,["outdated","--json=v2","--formula",a[e.id].formula],{timeout:15e3,env:{...process.env,HOMEBREW_NO_AUTO_UPDATE:"1"}}),t=JSON.parse(i);if(!Array.isArray(t.formulae))return;let o=t.formulae[0]?.current_version;return typeof o=="string"?o:null}catch{return}}var Z=e=>e.homebrew?"Homebrew":e.id==="yt-dlp"?"yt-dlp":void 0;async function ee(e,n={}){let r,i;if(e.homebrew){let t=await x(n);if(t===void 0)throw new Error("Homebrew was not found");r=t,i=["upgrade",a[e.id].formula]}else if(e.id==="yt-dlp")r=e.path,i=["--update"];else throw new Error(`${a[e.id].name} cannot update itself`);try{await w(r,i,{timeout:10*6e4,maxBuffer:8<<20,...n.signal?{signal:n.signal}:{}})}catch(t){if(n.signal?.aborted)throw n.signal.reason??t;let o=t,s=(o.stderr??"").trim().split(`
|
|
6
6
|
`).filter(Boolean).at(-1)?.replace(/^Error:\s*/,"");throw new Error(s||o.message||"the update failed")}}export{H as a,X as b,Y as c,q as d,$ as e,y as f,b as g,j as h,z as i,J as j,k,Q as l,V as m,Z as n,ee as o};
|