forge-terminal 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -10
- package/dist/chunks/available-QN6QAGCU.js +3 -0
- package/dist/chunks/boot-ISMRSTLL.js +3 -0
- package/dist/chunks/catalog-O3V24DK7.js +3 -0
- package/dist/chunks/check-DN7SEN44.js +3 -0
- package/dist/chunks/chunk-4L6HNYSN.js +4 -0
- package/dist/chunks/{chunk-XFEHJ4C7.js → chunk-6ZEGAH36.js} +1 -1
- package/dist/chunks/chunk-775ILWZI.js +3 -0
- package/dist/chunks/chunk-CKWYIU2N.js +4 -0
- package/dist/chunks/{chunk-G2D6BKOS.js → chunk-CXVYIBCA.js} +2 -2
- package/dist/chunks/chunk-E5QDHFKQ.js +3 -0
- package/dist/chunks/{chunk-VH5RWPGZ.js → chunk-GDQQDHXJ.js} +2 -2
- package/dist/chunks/chunk-HON4OV7M.js +3 -0
- package/dist/chunks/chunk-IBPGC4N2.js +3 -0
- package/dist/chunks/chunk-LI2JPLF7.js +3 -0
- package/dist/chunks/{chunk-5B7WODWH.js → chunk-M6LD6DHO.js} +1 -1
- package/dist/chunks/chunk-NY6BX7QS.js +5 -0
- package/dist/chunks/chunk-OIZCRBLT.js +3 -0
- package/dist/chunks/chunk-Q45MSMTN.js +3 -0
- package/dist/chunks/chunk-RE7E6NA7.js +3 -0
- package/dist/chunks/{chunk-PN73WK2S.js → chunk-VNAIHACR.js} +1 -1
- package/dist/chunks/chunk-W42HVOBD.js +3 -0
- package/dist/chunks/chunk-XSOCV3F2.js +3 -0
- package/dist/chunks/chunk-YILLB45O.js +3 -0
- package/dist/chunks/chunk-YZG5A3GA.js +4 -0
- package/dist/chunks/chunk-ZRP5CWIK.js +3 -0
- package/dist/chunks/{catalog-NTACQH5V.js → clipboard-CPHPA4FH.js} +1 -1
- package/dist/chunks/colour-LZ7EJ6H4.js +3 -0
- package/dist/chunks/config-command-UW6BYQ2K.js +3 -0
- package/dist/chunks/execute-JRS6RQZA.js +3 -0
- package/dist/chunks/extensions-command-5QO6YX6O.js +3 -0
- package/dist/chunks/image-ESDL7GZU.js +3 -0
- package/dist/chunks/install-HCF5BIA6.js +3 -0
- package/dist/chunks/launch-BWYE27OQ.js +65 -0
- package/dist/chunks/lock-RZ6NVZFD.js +3 -0
- package/dist/chunks/manager-7HNOLCYH.js +4 -0
- package/dist/chunks/paths-H2WS22BA.js +3 -0
- package/dist/chunks/preferences-AKDCPHJ5.js +3 -0
- package/dist/chunks/restart-6ONEYN6T.js +3 -0
- package/dist/chunks/run-C475RRUL.js +4 -0
- package/dist/chunks/{server-DU7QWDAH.js → server-A327QWB6.js} +6 -6
- package/dist/chunks/theme-YG3CRJBG.js +3 -0
- package/dist/chunks/update-command-HT2RBFLR.js +3 -0
- package/dist/chunks/update-note-6GBF5AE4.js +3 -0
- package/dist/index.js +33 -29
- package/package.json +7 -4
- package/skills/forge/SKILL.md +3 -0
- package/dist/chunks/available-HEUREG6L.js +0 -3
- package/dist/chunks/boot-BUGERSEB.js +0 -3
- package/dist/chunks/chunk-2WYHI73Y.js +0 -3
- package/dist/chunks/chunk-4YCO7S4K.js +0 -3
- package/dist/chunks/chunk-C2WYXNRM.js +0 -4
- package/dist/chunks/chunk-C7OOWUMU.js +0 -3
- package/dist/chunks/chunk-EOYBXOCV.js +0 -4
- package/dist/chunks/chunk-HUAEVW2A.js +0 -3
- package/dist/chunks/chunk-L76Q54MB.js +0 -3
- package/dist/chunks/chunk-PD5DFBCU.js +0 -3
- package/dist/chunks/chunk-TEGB7JRM.js +0 -3
- package/dist/chunks/chunk-YXDEOLNA.js +0 -3
- package/dist/chunks/colour-DE6N6AZO.js +0 -3
- package/dist/chunks/config-command-SQXRTBRO.js +0 -3
- package/dist/chunks/execute-M3C3TTWB.js +0 -3
- package/dist/chunks/extensions-command-HJDBUBYO.js +0 -3
- package/dist/chunks/image-GYUUMS6H.js +0 -3
- package/dist/chunks/launch-WBUFRVQ7.js +0 -65
- package/dist/chunks/lock-XD4L3WFM.js +0 -3
- package/dist/chunks/manager-KBJTXZ27.js +0 -4
- package/dist/chunks/paths-JUM6GKQU.js +0 -3
- package/dist/chunks/run-RXVQD4DZ.js +0 -4
- package/dist/chunks/theme-DESCJOCE.js +0 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Forge
|
|
2
2
|
|
|
3
|
-
**Convert** — a terminal-native file converter for macOS. Command: `forge`.
|
|
3
|
+
**Convert** — a terminal-native file converter for macOS and Windows. Command: `forge`.
|
|
4
4
|
|
|
5
5
|
## What it is
|
|
6
6
|
|
|
@@ -30,8 +30,10 @@ and arrow keys instead of flags. See [Interactive shell](#interactive-shell).
|
|
|
30
30
|
|
|
31
31
|
## Installation
|
|
32
32
|
|
|
33
|
-
**Requires macOS and Node 20 or newer** (developed and
|
|
34
|
-
Check with `node --version`; if you don't have it,
|
|
33
|
+
**Requires macOS or Windows 10/11, and Node 20 or newer** (developed and
|
|
34
|
+
tested on Node 24). Check with `node --version`; if you don't have it,
|
|
35
|
+
`brew install node` on a Mac, or the LTS installer from nodejs.org on Windows.
|
|
36
|
+
On Windows, use Windows Terminal for the full experience.
|
|
35
37
|
|
|
36
38
|
```bash
|
|
37
39
|
npm install -g forge-terminal
|
|
@@ -41,7 +43,7 @@ That puts `forge` on your `PATH`, so it works from any directory. Verify:
|
|
|
41
43
|
|
|
42
44
|
```bash
|
|
43
45
|
forge --version
|
|
44
|
-
# 0.
|
|
46
|
+
# 0.3.0
|
|
45
47
|
|
|
46
48
|
forge photo.jpg --to webp
|
|
47
49
|
```
|
|
@@ -104,6 +106,7 @@ forge config list # show every setting and where it lives
|
|
|
104
106
|
forge config set output ~/Desktop # default output folder
|
|
105
107
|
forge config set theme light # dark or light
|
|
106
108
|
forge config set quality 80 # what the quality slider opens on
|
|
109
|
+
forge config set update-check off # stop the once-a-day update check
|
|
107
110
|
forge config path # print the file location
|
|
108
111
|
```
|
|
109
112
|
|
|
@@ -112,6 +115,28 @@ defaults, says so once, and carries on — and it validates key by key, so one
|
|
|
112
115
|
bad setting does not cost you the ones that are fine. Keys written by a newer
|
|
113
116
|
version of Forge survive a write from an older one.
|
|
114
117
|
|
|
118
|
+
### Updates
|
|
119
|
+
|
|
120
|
+
Once a day, in the background, Forge asks the npm registry for the latest
|
|
121
|
+
version number of `forge-terminal`. That is the whole request: nothing about
|
|
122
|
+
your files or your Mac is sent. When a newer Forge is out, home's band says
|
|
123
|
+
`/update is available`, and a one-off command run in a terminal ends with a
|
|
124
|
+
short note, at most once a day. Neither ever slows anything down: the check
|
|
125
|
+
reads a cached answer, refreshes it after the command has finished, and is
|
|
126
|
+
silent when offline. It is never printed with `--json`, into a pipe, or over
|
|
127
|
+
MCP.
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
forge update # install a newer Forge now, if there is one
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
In the shell, `/update` checks on the spot, and ↵ installs the new version and
|
|
134
|
+
restarts Forge. If npm needs permission (Node installed for the whole Mac), it
|
|
135
|
+
shows the `sudo` command to run yourself instead.
|
|
136
|
+
|
|
137
|
+
Turn the automatic check off with `forge config set update-check off`, the
|
|
138
|
+
switch on `/update`, or `FORGE_NO_UPDATE_CHECK=1`. It is always off on CI.
|
|
139
|
+
|
|
115
140
|
### Themes
|
|
116
141
|
|
|
117
142
|
Forge ships two palettes, built separately rather than one dimmed: a colour
|
|
@@ -243,13 +268,16 @@ is optional.
|
|
|
243
268
|
## Boost resolution and remove background
|
|
244
269
|
|
|
245
270
|
Two image operations that need a model, so they are optional extensions rather
|
|
246
|
-
than part of the install.
|
|
247
|
-
|
|
271
|
+
than part of the install. On a Mac both need macOS 14 or later; on Windows,
|
|
272
|
+
Boost runs on DirectML and remove background is not available yet. Windows
|
|
273
|
+
also has a `heic` extension, because macOS opens iPhone photos itself and
|
|
274
|
+
Windows needs a decoder. Nothing downloads until you ask:
|
|
248
275
|
|
|
249
276
|
```bash
|
|
250
277
|
forge extensions # list: installed or not, size, licence
|
|
251
|
-
forge extensions add boost # about 15 MB
|
|
252
|
-
forge extensions add remove-background # about 32 KB
|
|
278
|
+
forge extensions add boost # about 15 MB on Apple Silicon (no Intel Mac build), 23 MB on Windows
|
|
279
|
+
forge extensions add remove-background # about 32 KB; macOS only
|
|
280
|
+
forge extensions add heic # about 0.5 MB; Windows only
|
|
253
281
|
forge extensions remove boost
|
|
254
282
|
```
|
|
255
283
|
|
|
@@ -863,7 +891,7 @@ photo.png · PNG · 122 KB · 2756×774
|
|
|
863
891
|
With `--json`:
|
|
864
892
|
|
|
865
893
|
```json
|
|
866
|
-
{"forge":"0.
|
|
894
|
+
{"forge":"0.3.0","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
|
|
867
895
|
```
|
|
868
896
|
|
|
869
897
|
`targets` and `actions` come from the engines' own capabilities, so they are
|
|
@@ -889,7 +917,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
|
|
|
889
917
|
|
|
890
918
|
```jsonc
|
|
891
919
|
{
|
|
892
|
-
"forge": "0.
|
|
920
|
+
"forge": "0.3.0",
|
|
893
921
|
"ok": false,
|
|
894
922
|
"results": [
|
|
895
923
|
{
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{c as t}from"./chunk-ZRP5CWIK.js";import"./chunk-HON4OV7M.js";import{a as i}from"./chunk-YILLB45O.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{q as l}from"./chunk-CXVYIBCA.js";import{e as a}from"./chunk-4L6HNYSN.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";var i={loadPreferences:a,loadShell:()=>import("./launch-BWYE27OQ.js")};async function p(e=i){let o=e.loadShell();o.catch(()=>{});let{prefs:t,warning:r}=await e.loadPreferences(),n=l(t.theme),{launchShell:s}=await o;await s({prefs:t,palette:n,...r===void 0?{}:{warning:r}})}export{p as bootShell};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a,b,c,d,e}from"./chunk-YILLB45O.js";import"./chunk-TMUK2DD3.js";export{a as CATALOG,c as assetFor,b as catalogEntry,e as offeredHere,d as offeredOn};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-YZG5A3GA.js";import"./chunk-4L6HNYSN.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";export{b as CHECK_EVERY_MS,a as REGISTRY_URL,k as availableUpdate,e as cachePath,j as checkNow,i as fetchLatest,c as isNewer,h as isStale,f as readCache,d as updateChecksEnabled,g as writeCache};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a}from"./chunk-HON4OV7M.js";import{mkdir as O,readFile as h,rename as C,unlink as v,writeFile as N}from"node:fs/promises";import{homedir as m}from"node:os";import{dirname as S,join as w}from"node:path";import{execFileSync as P}from"node:child_process";import{homedir as l}from"node:os";import{join as p}from"node:path";var F={Desktop:"[Environment]::GetFolderPath('Desktop')",Downloads:"(Get-ItemProperty 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders').'{374DE290-123F-4565-9164-39C4925E467B}'"};function E(e){try{let t=P("powershell.exe",["-NoProfile","-NonInteractive","-Command",`[Console]::OutputEncoding=[Text.Encoding]::UTF8; ${F[e]}`],{encoding:"buffer",timeout:5e3,stdio:["ignore","pipe","ignore"]}).toString("utf8").trim();return t.length>0?t:void 0}catch{return}}var g=new Map;function d(e,n=process.platform,t=E){if(n!=="win32")return p(l(),e);let r=g.get(e);if(r!==void 0)return r;let o=t(e)?.replace(/%([^%]+)%/g,(k,x)=>process.env[x]??k),c=(o!==void 0&&!o.includes("%")?o:void 0)??p(l(),e);return g.set(e,c),c}var s={defaultOutput:"~/Desktop",quality:80};function f(){return w(a(),"forge","config.json")}function A(e,n=process.platform){if(n==="win32"){if(e==="~/Desktop")return d("Desktop",n);if(e==="~/Downloads")return d("Downloads",n)}return e==="~"?m():e.startsWith("~/")?w(m(),e.slice(2)):e}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e){let n={...s},t=[];if(e.theme!==void 0&&(e.theme==="dark"||e.theme==="light"?n.theme=e.theme:t.push("theme")),e.defaultOutput!==void 0&&(typeof e.defaultOutput=="string"&&e.defaultOutput.trim().length>0?n.defaultOutput=e.defaultOutput:t.push("defaultOutput")),e.quality!==void 0){let r=e.quality;typeof r=="number"&&Number.isInteger(r)&&r>=1&&r<=100?n.quality=r:t.push("quality")}return e.updateCheck!==void 0&&(typeof e.updateCheck=="boolean"?n.updateCheck=e.updateCheck:t.push("updateCheck")),{prefs:n,rejected:t}}async function j(){let e;try{e=await h(f(),"utf8")}catch{return}try{let n=JSON.parse(e);return y(n)?n:void 0}catch{return}}async function B(){let e=f(),n;try{n=await h(e,"utf8")}catch(o){return o.code==="ENOENT"?{prefs:s}:{prefs:s,warning:`Could not read the config at ${e} \u2014 using defaults.`}}let t;try{t=JSON.parse(n)}catch{return{prefs:s,warning:`The config at ${e} is not valid JSON \u2014 using defaults.`}}if(!y(t))return{prefs:s,warning:`The config at ${e} is not an object \u2014 using defaults.`};let{prefs:r,rejected:i}=D(t);return i.length===0?{prefs:r}:{prefs:r,warning:`Ignored invalid config ${i.length===1?"setting":"settings"}: ${i.join(", ")}.`}}async function G(e){let n=f();await O(S(n),{recursive:!0});let r={...await j()??{}};for(let[o,u]of Object.entries(e))u!==void 0&&(r[o]=u);let i=`${n}.${process.pid}.tmp`;try{await N(i,`${JSON.stringify(r,null,2)}
|
|
4
|
+
`,"utf8"),await C(i,n)}catch(o){throw await v(i).catch(()=>{}),o}}export{d as a,s as b,f as c,A as d,B as e,G 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 m}from"./chunk-
|
|
3
|
+
import{a as m}from"./chunk-ZRP5CWIK.js";import{X as l}from"./chunk-E5QDHFKQ.js";import{randomBytes as h}from"node:crypto";import{link as y,mkdir as p,readdir as x,readFile as P,rename as E,rm as c,stat as L,writeFile as S}from"node:fs/promises";import{join as u}from"node:path";var b=720*60*1e3,k=600*1e3,M=200,F=600*1e3;function a(){return u(m(),".locks")}function f(t){return u(a(),`${t}.lock`)}function v(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function s(t){try{let n=JSON.parse(await P(t,"utf8"));return typeof n.pid!="number"||typeof n.token!="string"?void 0:n}catch{return}}async function d(t,n){if(n===void 0||!v(n.pid))return!0;let e=await L(t).catch(()=>{});return e!==void 0&&Date.now()-e.mtimeMs>b}async function D(t){let n=`${t}.stale-${h(4).toString("hex")}`;try{await E(t,n)}catch{return}let e=await s(n);e!==void 0&&!await d(n,e)&&await y(n,t).catch(()=>{}),await c(n,{force:!0})}async function A(){let t=await x(a()).catch(()=>[]);for(let n of t){if(!/\.lock\.(stale-)?[0-9a-f]+$/.test(n))continue;let e=u(a(),n),i=await L(e).catch(()=>{});i&&Date.now()-i.mtimeMs>F&&await c(e,{force:!0})}}async function g(t,n){await p(a(),{recursive:!0});let e=f(t),i={pid:process.pid,token:h(8).toString("hex"),at:Date.now(),...n!==void 0?{what:n}:{}},r=`${e}.${i.token}`;await S(r,JSON.stringify(i),{flag:"wx"});try{for(let o=0;o<2;o++){try{return await y(r,e),i}catch(w){if(w.code!=="EEXIST")throw w}if(!await d(e,await s(e)))return;await D(e)}return}finally{await c(r,{force:!0})}}async function T(t,n){let e=f(t);(await s(e))?.token===n.token&&await c(e,{force:!0})}async function _(t){let n=f(t),e=await s(n);if(!(e===void 0||await d(n,e)))return{pid:e.pid,...e.what!==void 0?{what:e.what}:{}}}async function H(t,n,e={}){let i=Date.now()+(e.waitMs??k);await p(a(),{recursive:!0}),await A();let r=await g(t,e.what);for(r===void 0&&(e.waitMs??k)>0&&e.onWait?.();r===void 0;){if(e.signal?.aborted)throw e.signal.reason??new Error("aborted");if(Date.now()>=i)throw l(t,await _(t),e.action??"run");await new Promise(o=>setTimeout(o,M)),r=await g(t,e.what)}try{return await n()}finally{await T(t,r)}}export{k as a,_ as b,H as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as R,c as te}from"./chunk-OIZCRBLT.js";import{$ as Y,F as Q,I as T,N as V,_ as Z,aa as ee,ba as M,c as F,d as m,g as A,h as C,i as W,j as P,k as q,l as J,m as j,n as X,o as G,r as w,x as K,y as B}from"./chunk-E5QDHFKQ.js";import{randomBytes as Ae}from"node:crypto";import{constants as Pe}from"node:fs";import{access as Be,readFile as he,rm as Te,stat as Me,writeFile as Re}from"node:fs/promises";import{basename as ke,dirname as De,join as Ne}from"node:path";function Ke(e){if(m[e].hasAlpha)return;let i=Object.keys(m).filter(t=>m[t].hasAlpha&&t!=="heic").join(", ");return T(`${m[e].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${i}.`)}var ie="1.1.0";function le(e,i){let t=e.split(".").map(n=>Number.parseInt(n,10)||0),r=i.split(".").map(n=>Number.parseInt(n,10)||0);for(let n=0;n<Math.max(t.length,r.length);n++){let a=(t[n]??0)-(r[n]??0);if(a!==0)return a>0}return!0}function k(e){return e!==void 0&&le(e,ie)?[2,3,4]:[2,4]}function Qe(e,i,t){if(e===1||k(i).some(n=>n===e))return;if(t!==void 0&&k(t).some(n=>n===e))return V("boost",`boost ${e}\xD7`,i,ie);let r=k(i).map(n=>`--boost ${n}`);return T(`No released boost makes ${e}\xD7 yet.`,`Try ${r.slice(0,-1).join(", ")} or ${r.at(-1)}.`)}var ge=16384,we=1e8;function re(e,i,t){let r=Math.max(e,i)*t;if(r>ge)return{side:r};let n=e*t*i*t;if(n>we)return{megapixels:Math.round(n/1e6)}}var y=e=>Math.max(1,Math.round(e));function D(e,i){return"percent"in i?{width:y(e.width*i.percent/100),height:y(e.height*i.percent/100)}:"width"in i?{width:y(i.width),height:y(e.height*i.width/e.width)}:{width:y(e.width*i.height/e.height),height:y(i.height)}}function ne(e){return re(e.width,e.height,1)}import{execFile as be}from"node:child_process";import{randomBytes as xe}from"node:crypto";import{mkdtemp as Se,open as ae,readFile as Ie,rm as N}from"node:fs/promises";import{tmpdir as oe}from"node:os";import{join as E}from"node:path";import{promisify as Ee}from"node:util";function g(e){let i;return()=>(i??=e(),i)}var b=g(async()=>(await import("sharp")).default),et=g(()=>import("./es-T2U7NBLD.js")),tt=g(()=>import("@hyzyla/pdfium")),it=g(async()=>(await import("./lib-TPEJ5CJJ.js")).default),rt=g(async()=>(await import("./word-OGQ2KZAJ.js")).default),nt=g(async()=>(await import("./adm-zip-SQKLKBDP.js")).default),at=g(async()=>(await import("./cfb-V6M2PYOD.js")).default);async function ye(){let e=Object.getOwnPropertyDescriptor(globalThis,"localStorage");if(!e?.configurable)return import("./dist-J2V6ITHG.js");Object.defineProperty(globalThis,"localStorage",{value:void 0,configurable:!0,enumerable:e.enumerable??!1,writable:!0});try{return await import("./dist-J2V6ITHG.js")}finally{Object.defineProperty(globalThis,"localStorage",e)}}var ot=g(ye);var L=Ee(be),se=async()=>({...await import("./paths-H2WS22BA.js"),...await import("./run-C475RRUL.js")}),x;async function S(e=process.platform){if(e==="win32")return await(await se()).installed("heic")!==void 0;if(x!==void 0)return x;try{await L("/usr/bin/sips",["--help"],{timeout:5e3}),x=!0}catch{x=!1}return x}async function v(e,i=process.platform){if(i==="win32")return ve(e);let t=E(oe(),`forge-heic-${xe(8).toString("hex")}.png`),r=async()=>{await N(t,{force:!0}).catch(()=>{})};try{return await L("/usr/bin/sips",["-s","format","png",e,"--out",t],{timeout:12e4}),{path:t,cleanup:r}}catch(n){throw await r(),n}}async function ce(e){let{installed:i,runExtension:t}=await se(),r=await i("heic");if(r===void 0)throw w(e,"win32");return{ext:r,runExtension:t}}async function ve(e){let i=await Se(E(oe(),"forge-heic-")),t=async()=>{await N(i,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:n}=await ce(e),a=E(i,"decoded.rgba"),o=E(i,"decoded.png"),{width:h,height:d}=await n(r,["--in",e,"--out",a],{subject:e});return await(await b())(await Ie(a),{raw:{width:h,height:d,channels:4}}).png().toFile(o),await N(a,{force:!0}),{path:o,cleanup:t}}catch(r){throw await t(),r}}var ze=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),Oe=new Set(["avif","avis"]);async function fe(e){let i;try{i=await ae(e,"r")}catch{return!1}try{let t=Buffer.alloc(64),{bytesRead:r}=await i.read(t,0,64,0);if(r<12||t.toString("latin1",4,8)!=="ftyp")return!1;let n=Math.min(t.readUInt32BE(0),r),a=[];for(let o=8;o+4<=n;o+=4)a.push(t.toString("latin1",o,o+4));return a.some(o=>Oe.has(o))?!1:a.some(o=>ze.has(o))}catch{return!1}finally{await i.close().catch(()=>{})}}async function de(e,i=process.platform){if(i==="win32"){let{ext:o,runExtension:h}=await ce(e),d=await h(o,["--info","--in",e],{subject:e});return{width:d.width,height:d.height,hasAlpha:d.hasAlpha??!0}}let{stdout:t}=await L("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",e],{timeout:3e4}),r=Number(/pixelWidth:\s*(\d+)/.exec(t)?.[1]??0),n=Number(/pixelHeight:\s*(\d+)/.exec(t)?.[1]??0),a=await Fe(e);return{width:a?n:r,height:a?r:n,hasAlpha:/hasAlpha:\s*yes/i.test(t)}}function*I(e,i,t){let r=i;for(;r+8<=t;){let n=e.readUInt32BE(r),a=8;if(n===1&&r+16<=t?(n=Number(e.readBigUInt64BE(r+8)),a=16):n===0&&(n=t-r),n<a)return;yield{type:e.toString("latin1",r+4,r+8),start:r+a,end:Math.min(r+n,t)},r+=n}}async function Fe(e){let i=await ae(e,"r");try{let t=Buffer.alloc(262144),{bytesRead:r}=await i.read(t,0,t.length,0),n=[...I(t,0,r)].find(c=>c.type==="meta");if(!n)return!1;let a=[...I(t,n.start+4,n.end)],o=a.find(c=>c.type==="pitm"),h=a.find(c=>c.type==="iprp");if(!o||!h)return!1;let d=t.readUInt8(o.start)===0?t.readUInt16BE(o.start+4):t.readUInt32BE(o.start+4),s=[...I(t,h.start,h.end)],l=s.find(c=>c.type==="ipco"),f=s.find(c=>c.type==="ipma");if(!l||!f)return!1;let u=new Map;if([...I(t,l.start,l.end)].forEach((c,O)=>{c.type==="irot"&&u.set(O+1,t.readUInt8(c.start)&3)}),u.size===0)return!1;let $=t.readUInt8(f.start),H=(t.readUInt8(f.start+3)&1)===1,p=f.start+4,pe=t.readUInt32BE(p);p+=4;for(let c=0;c<pe&&p<f.end;c++){let O=$<1?t.readUInt16BE(p):t.readUInt32BE(p);p+=$<1?2:4;let me=t.readUInt8(p);p+=1;for(let _=0;_<me;_++){let ue=H?t.readUInt16BE(p)&32767:t.readUInt8(p)&127;if(p+=H?2:1,O===d&&(u.get(ue)??0)%2===1)return!0}}return!1}catch{return!1}finally{await i.close().catch(()=>{})}}var Le=new Set(["jpeg","png","webp","avif","heic","gif","tiff"]),Ue=new Set(["jpeg","png","webp","avif","gif","tiff"]),$e={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function He(e,i){if(i.format==="heif")return i.compression==="av1"?"avif":"heic";let t=$e[i.format??""];if(!t)throw G(e,i.format??"an unknown format");return t}async function _e(e){let i;try{i=await Me(e)}catch(n){let a=n.code;throw a==="ENOENT"?C(e):a==="EACCES"||a==="EPERM"?P(e):a==="ENOTDIR"?q(e):a==="ELOOP"?J(e):a==="ENAMETOOLONG"?j(e):X(e,n)}if(!i.isFile())throw W(e);try{await Be(e,Pe.R_OK)}catch{throw P(e)}if(await fe(e)){if(!await S())throw w(e);let n;try{n=await de(e)}catch(a){throw B(e,"heic",a)}if(n.width===0||n.height===0)throw B(e,"heic",void 0);return{kind:"image",path:e,format:"heic",width:n.width,height:n.height,bytes:i.size,hasAlpha:n.hasAlpha,frames:1}}let t=await b(),r;try{r=await t(e).metadata()}catch(n){throw K(e,n)}return{kind:"image",path:e,format:He(e,r),width:r.autoOrient?.width??r.width??0,height:r.autoOrient?.height??r.height??0,bytes:i.size,hasAlpha:r.hasAlpha??!1,frames:r.pages??1}}function U(e,i,t){let r=t??m[i].defaultQuality;switch(i){case"jpeg":return e.jpeg({quality:r,mozjpeg:!0});case"webp":return e.webp({quality:r});case"avif":return e.avif({quality:r});case"png":return e.png({compressionLevel:9});case"gif":return e.gif();case"tiff":return e.tiff({compression:"deflate"});case"heic":throw new Error("heic is not writable; the capability graph should have prevented this");case"pdf":throw new Error("pdf is not an image target; the capability graph should have prevented this");case"docx":throw new Error("docx is not an image target; the capability graph should have prevented this");case"doc":throw new Error("doc is not an image target; the capability graph should have prevented this")}}async function Ce(e,i){let t=De(i);await R(i);let r=Ne(t,`.forge-tmp-${Ae(6).toString("hex")}-${ke(i)}`);try{return await Re(r,e),await te(r,i),e.length}catch(n){throw await Te(r,{force:!0}).catch(()=>{}),Q(i,n)}}async function z(e,i,t,r,n,a){if(e.kind!=="image")throw new Error("pipelineFor received a non-image source");if(n===void 0&&e.format==="heic"&&!await S())throw w(e.path);let o=n===void 0&&e.format==="heic"?await v(e.path):void 0,h=async()=>{await o?.cleanup()},s=(await b())(n??o?.path??e.path,r?{animated:!0}:{});if(s=s.rotate(),t.trim&&(s=s.trim()),t.resize){if(!a&&t.trim)throw new Error("pipelineFor needs the resolved size to resize a trimmed image");let l=a??D(e,t.resize);s=s.resize(l.width,l.height,{fit:"fill"})}return e.hasAlpha&&!m[i].hasAlpha&&(s=s.flatten({background:t.background})),s=t.keepMetadata?s.keepMetadata():s.keepIccProfile(),{pipeline:s,cleanup:h}}async function At(e,i){let t={background:"#ffffff",keepMetadata:!1},{pipeline:r,cleanup:n}=await z(e,"png",t,!1);try{await r.png({compressionLevel:1}).toFile(i)}finally{await n()}}async function Pt(e,i,t){let{pipeline:r,cleanup:n}=await z(e,i,t,!1);try{return await U(r,i,t.quality).toBuffer()}finally{await n()}}async function We(e){let i={width:e.width,height:e.height};if(e.frames>1)return{upright:i,trimmed:"animated"};if(e.format==="heic"&&!await S())throw w(e.path);let t=e.format==="heic"?await v(e.path):void 0;try{let r=await b(),{info:n}=await r(t?.path??e.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return n.width===i.width&&n.height===i.height?{upright:i,trimmed:"nothing"}:{upright:i,trimmed:{width:n.width,height:n.height}}}catch(r){throw A(r)?r:M(e.path,r)}finally{await t?.cleanup()}}async function qe(e,i){if(e.op!=="convert")throw new Error(`image engine cannot ${e.op}`);let t=e.sources[0],r=e.outputs[0];if(t.kind!=="image")throw new Error("the image engine cannot convert a document source");let n=m[e.target],a=[];i({phase:"reading"});let o=t.frames>1,h=o&&n.animatable;o&&!n.animatable&&a.push({code:"animation-flattened",message:`${F(t.path)} has ${t.frames} frames, and ${n.label} cannot animate. Only the first frame was converted.`});let d;if(e.options.trim||e.options.resize){let f={width:t.width,height:t.height};if(e.options.trim){if(o)throw ee(t.path);let{trimmed:u}=await We(t);if(u==="nothing"){if(!e.options.resize)throw Y(t.path);a.push({code:"nothing-trimmed",message:`${F(t.path)} has no empty edges; resized only.`})}else u!=="animated"&&(f=u)}if(e.options.resize&&(d=D(f,e.options.resize),ne(d)))throw Z(t.path,d)}i({phase:"decoding"});let{pipeline:s,cleanup:l}=await z(t,e.target,e.options,h,void 0,d);try{await R(r),i({phase:"encoding"});let f=await U(s,e.target,e.options.quality).toBuffer();i({phase:"writing"});let u=await Ce(f,r);return{job:e,outputBytes:u,warnings:a}}catch(f){throw A(f)?f:M(t.path,f)}finally{await l()}}async function Je(e){if(e.format!=="heic")return he(e.path);if(!await S())throw w(e.path);let i=await v(e.path);try{return await he(i.path)}finally{await i.cleanup()}}async function je(e){if(e.op!=="convert"||!m[e.target].lossy)return;let i=e.sources[0];if(i.kind!=="image")return;let t=await Je(i);return{ladder:[{}],measure:async r=>{let{pipeline:n}=await z(i,e.target,r,!1,t);return(await U(n,e.target,r.quality).toBuffer()).length}}}var Bt={id:"image",reads:Le,writes:Ue,ops:new Set(["convert"]),probe:_e,run:qe,measurer:je};export{Ke as a,k as b,Qe as c,ge as d,re as e,D as f,ne as g,g as h,b as i,et as j,tt as k,it as l,rt as m,nt as n,at as o,ot as p,S as q,v as r,fe as s,U as t,Ce as u,At as v,Pt as w,We as x,Bt as y};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{c as J,d as oe,e as E,g as B,h as se,i as ne,j as ae,k as ue,p as ie,q as pe,r as ce,t as de,u as fe,w as I,y}from"./chunk-RE7E6NA7.js";import{a as $,c as U,d as Y,e as F,f as K,k as Q}from"./chunk-M6LD6DHO.js";import{c as X,d as Z,e as _,f as ee,g as te,h as re}from"./chunk-VNAIHACR.js";import{e as V}from"./chunk-LI2JPLF7.js";import{a as H,c as L}from"./chunk-775ILWZI.js";import{a as g}from"./chunk-CXVYIBCA.js";import{I as D,J as q,M as z,b as P,c as w,d as R,da as G,g as x,s as A,u as k,w as W,z as C}from"./chunk-E5QDHFKQ.js";import{a as h,b as M}from"./chunk-J7FLFHQJ.js";import{readFile as Se}from"node:fs/promises";import{dirname as Re,resolve as je}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as ke}from"node:path";function $e(e,r=new Set){let t={path:ke(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===B.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-QN6QAGCU.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var S=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=P(Fe(e),S(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=M(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ge(s[0],r)}`,` ${s.map(u=>w(u)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let u of t.warnings)a.push("",`\u26A0 ${u.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],S(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,S(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function we(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>w(i)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)a.push("",`\u26A0 ${i.message}`);return a}function j(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function ve(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,S(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Be(e){return new Promise(r=>{let t=Pe({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function xe(e){if(e.stdin)return Be(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
|
|
4
|
+
`),t.close()}}function N(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Oe(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw D("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:pe(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Ce(e,r){let t;return()=>r?(t??=xe({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await V(await Se(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let n;try{n=B.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(u){if(!x(u))throw u;return{failure:{path:e.path,error:u}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function O(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=fe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Oe(e,r.sources))}catch(a){if(!x(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:A(u)});continue}let i=e.output!==void 0&&!oe(e.output)?je(e.output):void 0,c=e.output===void 0||i!==void 0?Re(u.path):Re(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-H2WS22BA.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-O3V24DK7.js"),d=f("boost"),v=d&&l(d)?.version,T=L(e.scale,n.version,v);if(T)return b(t,[{path:"",error:T}])}let a=await y(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?ne:ae,i=[],c=[];for(let l of a.sources){if(!u.appliesTo([l])){c.push({path:l.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}i.push(...u.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:O(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ue(n,{trim:e.trim,...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:O(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function We(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,u=[],i=[],c=Ce(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let v=await Je(d,e,c,t.roots.get(d.path));"failure"in v?i.push(v.failure):u.push(v.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...i,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function De(e,r={}){try{return e.kind==="pageop"?await Ne(e):e.kind==="extension-op"?await Me(e,r):e.kind==="edit"?await Ae(e,r):e.kind==="compress"?await Te(e,r):await We(e,r)}catch(t){if(!x(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:j(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:j(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-UW6BYQ2K.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function St(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-HT2RBFLR.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-5QO6YX6O.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=N(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...ve(u)]),stderr:j(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-LZ7EJ6H4.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:qe(await De(e,r),{json:t,debug:o})}catch(s){if(!x(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,N as b,De as c,qe as d,St as e};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
var C="0.
|
|
4
|
-
\u25BC`,dotFilled:"\u25CF",dotEmpty:"\u25CB"},r={name:"dark",fg:"#e7e7e7",dim:"#b0b0b0",accent:"#e5a23c",ok:"#6fcf7f",warn:"#e5c07b",fail:"#e8796d",failTint:"#2e2020",failTintDim:"#b0b0b0",larger:"#f2994a",shedHatch:"#47774f",grownFill:"#403225",tag:"#63c1d8",label:"#a68ce0",modeConvert:"#55c7d9",modeConvertBg:"#122c33",modeCompress:"#79c98b",modeCompressBg:"#182c1e",modePdf:"#ff6b4a",modePdfBg:"#361c16",modeColour:"#f27ba8",modeColourBg:"#3a1e2b",modeEnhance:"#b39ae8",modeEnhanceBg:"#2a2238",border:"#808080",selectionBg:"#2c2c2c",band:"#2c2c2c",canvas:"#1e1e1e",textSelectionBg:"#3f5c86",brand:"#e5a23c",keycapBg:"#333333",violet:"#a68ce0",faint:"#4d4d4d",listBand:"#323232",shelf:"#242424",tabChip:"#262626",panelBand:"#404040",ink:"#0c1d22",track:"#2e2e2e",trackFill:"#515151",thumb:"#e7e7e7",folderChip:"#414141",pill:"#e7e7e7",fieldBand:"#3d3d3d",defaultTagBg:"#33261a",defaultTag:"#c98a4b",newTagBg:"#2a3448",newTag:"#4f77c5"},
|
|
3
|
+
var C="0.3.0",T={ok:"\u2713",fail:"\u2715",warn:"\u26A0",cursor:"\u276F",strip:"\u258C",star:"\u2605",arrow:"\u2192",tip:"\u2727",longArrow:"\u2500\u2500\u2192",longArrowDown:`\u2502
|
|
4
|
+
\u25BC`,dotFilled:"\u25CF",dotEmpty:"\u25CB"},r={name:"dark",fg:"#e7e7e7",dim:"#b0b0b0",accent:"#e5a23c",ok:"#6fcf7f",warn:"#e5c07b",fail:"#e8796d",failTint:"#2e2020",failTintDim:"#b0b0b0",larger:"#f2994a",shedHatch:"#47774f",grownFill:"#403225",tag:"#63c1d8",label:"#a68ce0",modeConvert:"#55c7d9",modeConvertBg:"#122c33",modeCompress:"#79c98b",modeCompressBg:"#182c1e",modePdf:"#ff6b4a",modePdfBg:"#361c16",modeColour:"#f27ba8",modeColourBg:"#3a1e2b",modeEnhance:"#b39ae8",modeEnhanceBg:"#2a2238",border:"#808080",selectionBg:"#2c2c2c",band:"#2c2c2c",canvas:"#1e1e1e",textSelectionBg:"#3f5c86",brand:"#e5a23c",keycapBg:"#333333",violet:"#a68ce0",faint:"#4d4d4d",listBand:"#323232",shelf:"#242424",tabChip:"#262626",panelBand:"#404040",ink:"#0c1d22",track:"#2e2e2e",trackFill:"#515151",thumb:"#e7e7e7",folderChip:"#414141",pill:"#e7e7e7",fieldBand:"#3d3d3d",defaultTagBg:"#33261a",defaultTag:"#c98a4b",newTagBg:"#2a3448",newTag:"#4f77c5"},o={name:"light",fg:"#262626",dim:"#4f4f4f",accent:"#915a01",ok:"#0e702c",warn:"#8a6100",fail:"#a43c32",failTint:"#f9e3df",failTintDim:"#4a4a4a",larger:"#8b4d01",shedHatch:"#87b896",grownFill:"#ece3d6",tag:"#0a6b86",label:"#5e4b99",modeConvert:"#036b7b",modeConvertBg:"#e6f7fa",modeCompress:"#24733a",modeCompressBg:"#eaf5ec",modePdf:"#b82a06",modePdfBg:"#fceee9",modeColour:"#b0306a",modeColourBg:"#f7e3ec",modeEnhance:"#64569f",modeEnhanceBg:"#f0ebfa",border:"#767676",selectionBg:"#e4e4e4",band:"#e4e4e4",canvas:"#ffffff",textSelectionBg:"#b9cfe8",brand:"#915a01",keycapBg:"#e1e1e1",violet:"#5e4b99",faint:"#b2b2b2",listBand:"#dcdcdc",shelf:"#f3f3f3",tabChip:"#f0f0f0",panelBand:"#d5d5d5",ink:"#ffffff",track:"#e4e4e4",trackFill:"#afafaf",thumb:"#262626",folderChip:"#d0d0d0",pill:"#262626",fieldBand:"#d7d7d7",defaultTagBg:"#f5e2cc",defaultTag:"#8f5000",newTagBg:"#e1e7f4",newTag:"#3358a3"},f={name:"neutral",fg:"",dim:"gray",accent:"yellow",ok:"green",warn:"yellow",fail:"red",failTint:"",failTintDim:"gray",larger:"yellow",shedHatch:"green",grownFill:"",tag:"cyan",label:"magenta",modeConvert:"cyan",modeConvertBg:"",modeCompress:"green",modeCompressBg:"",modePdf:"red",modePdfBg:"",modeColour:"magenta",modeColourBg:"",modeEnhance:"magenta",modeEnhanceBg:"",border:"gray",selectionBg:"",band:"",canvas:"",textSelectionBg:"",brand:"yellow",keycapBg:"",violet:"magenta",faint:"gray",listBand:"",shelf:"",tabChip:"",panelBand:"",ink:"",track:"",trackFill:"",thumb:"",folderChip:"",pill:"",fieldBand:"",defaultTagBg:"",defaultTag:"",newTagBg:"",newTag:""},a=["convert","compress","pdf","enhance","colour"],v=`1\u2013${a.length}`;function P(e){return/^[1-9]$/.test(e)?a[Number(e)-1]:void 0}var S={convert:"\u2194",compress:"\u2193",pdf:"\u25A3",colour:"\u25D0",enhance:"\u2726"},c="#7d6ad0";function l(e,n){return n==="compress"?{fg:e.modeCompress,bg:e.modeCompressBg}:n==="pdf"?{fg:e.modePdf,bg:e.modePdfBg}:n==="colour"?{fg:e.modeColour,bg:e.modeColourBg}:n==="enhance"?{fg:e.modeEnhance,bg:e.modeEnhanceBg}:{fg:e.modeConvert,bg:e.modeConvertBg}}var i=["#f26e69","#e5a23c","#ace02c","#55c7d9","#6579fd","#ad95e9"],g=["#e5a23c","#f2cf6b"],s={convert:["#1e96a7","#1e94b3","#1e92c0","#1d8ed2","#1b86ef","#4a7df8","#6974f8","#816af8","#995cf8"],compress:["#24b459","#22ab6d","#21a479","#209f81","#1f9c89","#1f9a91","#1e9998","#1e97a0","#1e96a7"],pdf:["#eb4319","#e3541a","#de601b","#db6a1c","#d9731d","#d87c1e","#d8841f","#d98c20","#d99522"],enhance:["#9b5af8","#985cf8","#965ef8","#945ff8","#9161f8","#8f62f8","#8d64f8","#8a65f8","#8867f8"],colour:["#f42335","#e05b1a","#d87d1e","#da9b23","#d2b427","#b4c027","#5bbf23","#20a27c","#1e989b","#1e94b6","#1c8cd9","#577af8","#7371f8","#8568f8","#965df8"]},m=["#d99522","#da9822","#da9b23","#da9f24","#d9a224","#d9a525","#d8a825","#d7ab26","#d6ad26"],b={convert:["#d6f7fd","#ddf5fe","#e1f4fe","#e4f2fe","#e7f1fe","#eaf0fe","#eceffe","#efeefe","#f1edfe"],compress:["#e0f7e4","#def8e7","#dcf8ea","#daf8ed","#d8f8f1","#d7f8f4","#d6f8f7","#d6f8fa","#d6f7fd"],pdf:["#feece7","#feece6","#feece5","#feece3","#feece2","#feede0","#feedde","#feeddc","#feeed9"],enhance:["#f2edfe","#f1edfe","#f1edfe","#f1eefe","#f0eefe","#f0eefe","#f0eefe","#f0eefe","#efeefe"],colour:["#feebe9","#feece5","#feede0","#feeed7","#f7f1d6","#eff3d9","#e5f6df","#dbf8eb","#d6f8f8","#def5fe","#e5f2fe","#ebf0fe","#edeffe","#efeefe","#f1edfe"]},u=["#feeed9","#feeed8","#feeed7","#fdeed6","#fcefd6","#fbefd6","#fbefd6","#faefd6","#f9f0d6"],B={convert:["#138291","#8467bd"],compress:["#2b8748","#138291"],pdf:["#d54322","#a06c10"],enhance:["#8567bc","#7b67cd"],colour:["#cb4b49","#a06c10","#618110","#138291","#5869ec","#8268bd"]};function h(e,n){return e.name==="light"?n==="commands"?m:s[n]:n==="commands"?e.name==="dark"?g:[e.brand]:n==="compress"?[e.modeCompress,e.modeConvert]:n==="pdf"?[e.modePdf,e.brand]:n==="colour"?e.name==="dark"?i:[e.modeColour,e.violet]:n==="enhance"?[e.modeEnhance,e.name==="dark"?c:e.violet]:[e.modeConvert,e.violet]}function k(e,n){if(e.name==="light")return n==="commands"?u:b[n]}function x(e,n){return e.name==="light"?B[n]:h(e,n)}function y(e){return{...e,accent:e.brand,tag:e.brand,label:e.brand}}function E(e,n){let{fg:t,bg:d}=l(e,n);return{...e,accent:t,tag:t,label:t,band:d===""?e.band:d}}function w(e){return e.name==="light"&&e.canvas!==""}function M(e){return e==="dark"?r:e==="light"?o:f}function O(e){return e===""?void 0:e}var R={filled:"\u2501",empty:"\u2501",knob:"\u25CF"};function p(){return process.env.NO_COLOR!==void 0&&process.env.NO_COLOR!==""?!1:process.stdout.isTTY===!0}function D(){p()||(process.env.FORCE_COLOR="0")}export{C as a,T as b,r as c,o as d,f as e,a as f,v as g,P as h,S as i,l as j,h as k,k as l,x as m,y as n,E as o,w as p,M as q,O as r,R as s,p as t,D as u};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as l}from"./chunk-J7FLFHQJ.js";import{homedir as f}from"node:os";import{posix as c,win32 as h}from"node:path";var g=/[\u0000-\u001f\u007f-\u009f--]/g;function d(e){return e.replace(g,"?")}function p(e,t,n){let i=n.relative(t,e);if(i==="")return"";if(!(i===".."||i.startsWith(`..${n.sep}`)||n.isAbsolute(i)))return i}function k(e,t={}){return d(m(e,t))}function m(e,t){let n=(t.platform??process.platform)==="win32"?h:c;if(t.cwd!==void 0){let a=p(e,t.cwd,n);if(a!==void 0)return a===""?".":a}let i=p(e,t.home??f(),n);return i!==void 0?i===""?"~":`~${n.sep}${i}`:e}function r(e,t=process.platform){return d((t==="win32"?h:c).basename(e))}var s={jpeg:{id:"jpeg",label:"JPEG",extensions:[".jpg",".jpeg"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"universal",defaultQuality:82},png:{id:"png",label:"PNG",extensions:[".png"],hasAlpha:!0,animatable:!1,lossy:!1,hint:"lossless"},webp:{id:"webp",label:"WebP",extensions:[".webp"],hasAlpha:!0,animatable:!0,lossy:!0,hint:"smaller, modern",defaultQuality:80},avif:{id:"avif",label:"AVIF",extensions:[".avif"],hasAlpha:!0,animatable:!0,lossy:!0,hint:"smallest",defaultQuality:50},heic:{id:"heic",label:"HEIC",extensions:[".heic",".heif"],hasAlpha:!0,animatable:!1,lossy:!0,hint:"Apple photos"},gif:{id:"gif",label:"GIF",extensions:[".gif"],hasAlpha:!0,animatable:!0,lossy:!1,hint:"animation"},tiff:{id:"tiff",label:"TIFF",extensions:[".tif",".tiff"],hasAlpha:!0,animatable:!1,lossy:!1,hint:"archival"},pdf:{id:"pdf",label:"PDF",extensions:[".pdf"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"document"},docx:{id:"docx",label:"DOCX",extensions:[".docx"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"Word document"},doc:{id:"doc",label:"DOC",extensions:[".doc"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"legacy Word"}},I=Object.keys(s);function S(e){return s[e.toLowerCase()]}function T(e){let t=s[e].extensions[0];if(!t)throw new Error(`format ${e} declares no extensions`);return t}import{dirname as w}from"node:path";var o=class extends Error{code;title;detail;short;hint;shellHint;constructor(t){super(`${t.title}: ${t.detail}`,t.cause===void 0?void 0:{cause:t.cause}),this.name="ForgeError",this.code=t.code,this.title=t.title,this.detail=t.detail,this.short=t.short,this.hint=t.hint,this.shellHint=t.shellHint}};function x(e){return e instanceof o}function O(e){return new o({code:"file-not-found",title:"File not found",detail:`${r(e)} could not be found.`,short:`${r(e)} could not be found.`,hint:"Check the filename and try again."})}function j(e){return new o({code:"not-a-file",title:"Not a file",detail:`${r(e)} is not a file.`,short:`${r(e)} is not a file.`,hint:"Point Forge at an image, or at a directory of images."})}function R(e){return new o({code:"permission-denied",title:"Permission denied",detail:`${r(e)} could not be read.`,short:`${r(e)} could not be read.`,hint:"Check the file permissions and try again."})}function U(e){return new o({code:"not-a-directory",title:"Invalid path",detail:`${r(e)} could not be found: part of its path is not a directory.`,short:`part of ${r(e)}'s path is not a folder.`,hint:"Check the path and try again."})}function z(e){return new o({code:"symlink-loop",title:"Too many symbolic links",detail:`${r(e)} could not be resolved: its path contains a symbolic-link loop.`,short:`${r(e)}'s path loops back on itself.`,hint:"Check for a circular symlink somewhere in the path."})}function J(e){return new o({code:"path-too-long",title:"Path too long",detail:`${r(e)}'s path is too long for the filesystem to resolve.`,short:`${r(e)}'s path is too long.`,hint:"Use a shorter path and try again."})}function W(e,t){return new o({code:"unreadable-path",title:"Could not read path",detail:`${r(e)} could not be checked.`,short:`${r(e)} could not be checked.`,hint:"Check the path and try again.",cause:t})}function M(e,t){return new o({code:"unsupported-source",title:"Unsupported file type",detail:`${r(e)} is ${t}, which Forge cannot read.`,short:`${r(e)} is ${t}, which Forge cannot read.`,hint:"Forge 0.1 handles images only."})}function L(e,t){return new o({code:"unsupported-source",title:"Not an image",detail:`${r(e)} is ${t}, not an image.`,hint:"A palette is taken from a photo, a screenshot or artwork."})}function _(e){return new o({code:"unsupported-source",title:"Nothing to take colours from",detail:`${r(e)} has no visible pixels.`})}function B(e,t=process.platform){return t==="win32"?new o({code:"heic-decoder-unavailable",title:"Cannot read HEIC here",detail:`${r(e,t)} is a HEIC photo, which needs Forge's free HEIC extension on Windows.`,short:"HEIC needs the heic extension.",hint:"Install it with: forge extensions add heic",shellHint:"Open /extensions to install it."}):new o({code:"heic-decoder-unavailable",title:"Cannot read HEIC here",detail:`${r(e)} is a HEIC photo, which Forge decodes with the macOS sips tool.`,short:"HEIC needs sips, which could not be run.",hint:"sips could not be run. It ships with macOS at /usr/bin/sips."})}function G(e,t){let n=r(e.path);if(t!==void 0&&t!==e.format){let i=s[t].label;return s[t].lossy?new o({code:"unsupported-compress",title:"Cannot fit that to a size",detail:`Forge cannot search ${n} \u2192 ${i} toward a size yet.`,hint:"Convert it first, then compress the result with --max-size.",shellHint:"Convert it first, then /compress the result to a size."}):new o({code:"unsupported-compress",title:"Cannot fit that to a size",detail:`${i} is lossless \u2014 there is no quality to trade away, so ${n} cannot be made to fit as ${i}.`,hint:"Drop --max-size, or choose a lossy target. forge --formats lists them.",shellHint:"Choose a lossy target to aim for a size."})}if(e.kind==="document"&&e.format==="pdf"){let i=e.images?.skipped??0;return new o({code:"unsupported-compress",title:"Nothing to compress",detail:i>0?`${n}'s images are a kind Forge cannot re-encode, so there is nothing to make smaller.`:`${n} has no images \u2014 it is text and layout, which compression cannot shrink.`,hint:"Try a page operation such as --extract to keep fewer pages, or --to <format> to turn its pages into images.",shellHint:"Try /pdf to keep fewer pages, or /convert to turn its pages into images."})}return e.kind==="document"?new o({code:"unsupported-compress",title:"Nothing to compress",detail:`${n} is ${s[e.format].label}, which has no images Forge can re-encode.`,hint:`Use --to pdf to change it to PDF instead: forge ${n} --to pdf`,shellHint:"Use /convert to change it to PDF instead."}):new o({code:"unsupported-compress",title:"Nothing to compress",detail:`${n} is ${s[e.format].label}, which is lossless \u2014 there is no quality to trade away.`,hint:"Use --to to change it to a smaller format instead. forge --formats lists them.",shellHint:"Use /convert to change it to a smaller format instead."})}function q(e){let t=r(e.path);return new o({code:"unsupported-pdf",title:"/pdf needs a PDF",detail:`${t} is ${s[e.format].label}, not a PDF.`,hint:"Converting it instead."})}function Q(e,t,n){return new o({code:"unsupported-operation",title:`Cannot ${e} these files`,detail:`Not available for these files: ${t}.`,hint:n??"Page operations work on PDFs: --merge takes two or more, the others take one.",shellHint:n??"Use /pdf with a PDF staged \u2014 two or more for merge."})}function X(e,t,n){return new o({code:"target-unreachable",title:"Cannot get that small",detail:`${r(e.path)} is ${l(n)} even at the lowest quality, which is still over ${l(t)}.`,hint:"Try a larger --max-size, or --to a smaller format.",shellHint:"Try a larger target, or /convert to a smaller format."})}function V(e,t,n){return new o({code:"unsupported-target",title:`Can't convert ${r(e.path)} to ${t}`,detail:`${r(e.path)} is a ${s[e.format].label} ${e.kind==="image"?"image":"document"}.`,hint:`Available: ${n.join(", ")}`})}function Y(e,t){return new o({code:"corrupt-source",title:"Damaged file",detail:`${r(e)} could not be read. It may be damaged, or not a format Forge recognises.`,short:`${r(e)} could not be read.`,hint:"The file may be incomplete or corrupted.",cause:t})}function K(e,t,n){return new o({code:"corrupt-source",title:`Damaged ${s[t].label}`,detail:`${r(e)} is a ${s[t].label} file, but its content could not be read.`,short:`${r(e)} could not be read.`,hint:"The file may be incomplete or corrupted.",cause:n})}function Z(e,t={}){let n=r(e);return new o({code:"encrypted-source",title:"This PDF is password-protected",detail:`${n} is password-protected.`,short:`${n} is password-protected.`,hint:t.attempted?"That password didn't open it. Check it and try again.":`Convert it to images instead: forge ${n} --to jpeg --password-stdin`})}var u=e=>e==="convert"||e==="boost"||e==="remove-background";function ee(e,t="convert"){return new o({code:"output-exists",title:"File already exists",detail:`${r(e)} is already there.`,hint:u(t)?"Pass --force to replace it, or choose a different --output.":"Pass --force to replace it, or move the existing file out of the way.",shellHint:"Run it again and Forge will ask before replacing it."})}function te(e,t){return new o({code:"output-collision",title:"Two files want the same output",detail:`${r(e[0])} and ${r(e[1])} would both become ${r(t)}.`,hint:"Convert them separately, or use --output to send them to different folders.",shellHint:"Convert them one at a time."})}function oe(e,t){return new o({code:"output-collision",title:"One output, written twice",detail:`${r(e)} would write ${r(t)} twice, and only the second would survive.`,hint:"Every output has to be its own file. Check the selection for a repeated page."})}function ne(e,t="convert"){return new o({code:"output-is-input",title:"Output would replace the original",detail:`${r(e)} is both the input and the output.`,hint:u(t)?"Choose a different --output, or pass --force to overwrite in place.":"Move or rename that file first, or pass --force to overwrite it in place.",shellHint:u(t)?"Choose a different folder to save it in.":"Move or rename that file first."})}function b(e,t){return new o({code:"permission-denied",title:"Permission denied",detail:`${r(w(e))} is not a folder you can write to.`,hint:"Choose a different --output, or check the folder permissions.",shellHint:"Choose a different folder, or check its permissions.",cause:t})}var y=new Set(["EACCES","EPERM","EROFS"]);function re(e,t){if(x(t))return t;let n=t?.code;return n!==void 0&&y.has(n)?b(e,t):t}function ie(e,t){return new o({code:"output-invalid",title:"Cannot write there",detail:`${e} could not be written to.`,hint:"Check that the path is valid and that you have permission to write to it.",cause:t})}function se(e){return new o({code:"empty-directory",title:"No images found",detail:`${r(e)} contains no images Forge can convert.`,hint:"Try --recursive to look inside subfolders.",shellHint:"Only files directly inside a folder are read \u2014 drop the files themselves, or the folder that holds them."})}function ae(e,t){return new o({code:"invalid-arguments",title:"Invalid arguments",detail:e,hint:t})}function le(e,t,n){return new o({code:"invalid-page-range",title:"Page range not understood",detail:t,hint:`This document has ${n} pages. Use numbers and spans, like "3-7, 12, 20-".`})}function de(e){return new o({code:"empty-selection",title:"Nothing to write",detail:e,hint:"Select at least one page to keep."})}function ue(e){return new o({code:"invalid-dpi",title:"Invalid resolution",detail:`${String(e)} is not a resolution Forge can use.`,hint:"Give a number between 36 and 600. The default is 150."})}function pe(e){return new o({code:"extension-missing",title:"Extension not installed",detail:`${e} is an optional extension and is not installed.`,hint:`Install it with: forge extensions add ${e}`,shellHint:"Open /extensions to install it."})}function ce(e,t,n,i){return new o({code:"extension-outdated",title:"Extension out of date",detail:`${e} ${n} cannot ${t}; that needs ${i} or later.`,hint:`Update it with: forge extensions add ${e}`,shellHint:"Open /extensions to update it."})}function he(e,t){return new o({code:"extension-corrupt",title:"Extension failed verification",detail:`${e}: ${t}`,hint:`Nothing was installed. Try again with: forge extensions add ${e}`,shellHint:"Nothing was installed. Try again from /extensions."})}function ge(e,t,n=process.platform){let i=n==="win32"?"PC":"Mac";return new o({code:"extension-unsupported",title:"Extension not available here",detail:`${e} cannot be installed on this ${i}: ${t}`,hint:"See what is available with: forge extensions",shellHint:"See what is available in /extensions."})}function fe(e,t=process.platform){let n=t==="win32"?"Windows":t==="darwin"?"macOS":"this system";return new o({code:"extension-unsupported",title:"Extension not available here",detail:`${e} is not available on ${n}.`,hint:"See what is available with: forge extensions",shellHint:"See what is available in /extensions."})}function me(e){return new o({code:"update-unavailable",title:"Cannot update this Forge",detail:`This copy of Forge was not installed with npm i -g, so ${e} cannot be installed over it.`,hint:"npm i -g forge-terminal"})}function we(e,t=process.platform){return t==="win32"?new o({code:"update-denied",title:"Forge is in use",detail:`npm could not replace Forge's files to update it to ${e}. Windows keeps them locked while Forge runs: close every Forge window, then run the command below. If Node is installed for every user, run it in a terminal opened as administrator.`,short:"Windows locks Forge while it runs: close it, then run this",hint:`npm i -g forge-terminal@${e}`}):new o({code:"update-denied",title:"npm needs permission",detail:`npm needs permission to update Forge to ${e}.`,short:"npm needs permission to update Forge",hint:`sudo npm i -g forge-terminal@${e}`})}function xe(e,t){return new o({code:"update-failed",title:"Update failed",detail:`npm could not install Forge ${e}: ${t}`,short:"npm could not install the update",hint:`npm i -g forge-terminal@${e}`})}function be(){return new o({code:"update-unreachable",title:"Could not check for updates",detail:"The npm registry could not be reached.",short:"could not reach npm",hint:"Check your connection (and HTTPS_PROXY if you use a proxy), then run: forge update",shellHint:"Check your connection, then try again."})}function ye(e,t){return new o({code:"extension-download-failed",title:"Download failed",detail:`${e}: ${t}`,hint:`Check your connection (and HTTPS_PROXY if you use a proxy), then run: forge extensions add ${e}`,shellHint:"Check your connection, then try again from /extensions."})}function $e(e,t){return new o({code:"extension-download-failed",title:"Not enough disk space",detail:`${e}: ${t}`,hint:`Free some disk space, then run: forge extensions add ${e}`,shellHint:"Free some disk space, then try again from /extensions."})}function Fe(e,t,n){let i=t?t.what?`${t.what} (forge, pid ${t.pid})`:`another forge (pid ${t.pid}) is using it`:"another forge is using it";return new o({code:"extension-in-use",title:"Extension in use",detail:`${e} is in use: ${i}.`,hint:n==="remove"?`Wait for that job to finish, then run: forge extensions remove ${e}`:"Wait for that job to finish, then try again.",shellHint:n==="remove"?"It can be removed when that job finishes.":"Try again when that job finishes."})}function Ee(e){return new o({code:"no-subject",title:"No subject found",detail:`${r(e)} has no clear subject to cut out.`,hint:"Try a photo where the subject stands apart from the background."})}function ve(e,t,n){return n===1?new o({code:"boost-too-large",title:"Too large to sharpen",detail:`${r(e)} is too large to sharpen.`,hint:"Sharpen works on images up to 16,384 px a side and 100 megapixels."}):new o({code:"boost-too-large",title:"Too large to boost",detail:t>=2?`${r(e)} is too large to boost that far; ${t}x is the most it can take.`:`${r(e)} is already too large to boost.`,hint:t>=2?`Try --boost ${t}.`:"Boost works on images up to 100 megapixels.",shellHint:t>=2?`Choose ${t}x instead.`:void 0})}function ke(e,t){return new o({code:"resize-too-large",title:"Too large to resize to",detail:`${r(e)} would be ${t.width} \xD7 ${t.height}.`,hint:"Resize works up to 16,384 px a side and 100 megapixels."})}function Ce(e){return new o({code:"nothing-to-trim",title:"Nothing to trim",detail:`${r(e)} has no empty edges.`,short:"no empty edges"})}function Ie(e){return new o({code:"animated-trim",title:"Can't trim an animation",detail:`${r(e)} is animated; trimming works on still images.`})}function Se(e,t){return new o({code:"conversion-failed",title:"Conversion failed",detail:`${r(e)} could not be converted.`,hint:"Run again with --debug for the underlying error.",shellHint:"Run the same conversion with forge --debug from the command line to see why.",cause:t})}function Te(e){return new o({code:"unexpected",title:"Something went wrong",detail:e instanceof Error?e.message:String(e),hint:"This was not expected. Try again \u2014 if it keeps happening, it may be worth reporting.",cause:e})}function Pe(e,t={}){let n=[`\u2715 ${e.title}`,"",` ${e.detail}`];return e.hint&&n.push("",` ${e.hint}`),t.debug&&e.cause instanceof Error&&n.push("",` ${e.cause.stack??e.cause.message}`),n}export{d as a,k as b,r as c,s as d,S as e,T as f,x as g,O as h,j as i,R as j,U as k,z as l,J as m,W as n,M as o,L as p,_ as q,B as r,G as s,q as t,Q as u,X as v,V as w,Y as x,K as y,Z as z,ee as A,te as B,oe as C,ne as D,b as E,re as F,ie as G,se as H,ae as I,le as J,de as K,ue as L,pe as M,ce as N,he as O,ge as P,fe as Q,me as R,we as S,xe as T,be as U,ye as V,$e as W,Fe as X,Ee as Y,ve as Z,ke as _,Ce as $,Ie as aa,Se as ba,Te as ca,Pe as da};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as h,c as b,d as A,e as F,f as x,g as w,h as R}from"./chunk-QVACE4IE.js";import{i as M}from"./chunk-
|
|
3
|
+
import{b as h,c as b,d as A,e as F,f as x,g as w,h as R}from"./chunk-QVACE4IE.js";import{i as M}from"./chunk-LI2JPLF7.js";import{i as L,q as O,r as j}from"./chunk-775ILWZI.js";import{d as k,g as C,p as v,r as I,x as S}from"./chunk-E5QDHFKQ.js";var D=[[15,"rose"],[45,"red"],[70,"orange"],[95,"amber"],[120,"yellow"],[140,"lime"],[165,"green"],[185,"teal"],[215,"cyan"],[250,"sky"],[280,"blue"],[295,"indigo"],[315,"violet"],[340,"purple"],[355,"pink"],[360,"rose"]];function T(t){let{C:e,h:r}=x(b(t));return e<.03?"grey":(D.find(([n])=>r<n)??[360,"rose"])[1]}var d=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),z=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"colour",$='font-family="Inter"';function P(t,e,r,n="light"){let o=n==="dark",i=o?"#FAFAFA":"#111111",s=o?"#A1A1AA":"#71717A",c=o?"#FFFFFF":"#000000",a=r.length>8?64:104,l=10,g=48+r.length*a+Math.max(0,r.length-1)*l,m=84+a+56,p=a>80?12:10,f=`<text id="title" x="24" y="38" ${$} font-size="15" font-weight="600" fill="${i}">${d(t)}</text><text id="subtitle" x="24" y="58" ${$} font-size="12" fill="${s}">${d(e)}</text>`,U=r.map((u,W)=>`<g id="${z(u.id)}" transform="translate(${24+W*(a+l)} 80)"><rect id="swatch" width="${a}" height="${a}" rx="${p}" fill="${u.hex}" stroke="${c}" stroke-opacity="0.08"/><text id="name" x="1" y="${a+22}" ${$} font-size="13" font-weight="600" fill="${i}">${d(u.name)}</text><text id="value" x="1" y="${a+40}" ${$} font-size="11" fill="${s}">${d(u.value)}</text></g>`).join(`
|
|
4
4
|
`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${g}" height="${m}" viewBox="0 0 ${g} ${m}">
|
|
5
5
|
<g id="${z(t)}">
|
|
6
6
|
<rect id="card" width="${g}" height="${m}" rx="0" fill="${o?"#18181B":"#FFFFFF"}"/>
|
|
7
7
|
${f}
|
|
8
8
|
${U}
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`}function Z(t,e,r="light",n){let o=t.replace(/\.[^.]+$/,""),i=e.length;return P(t,n?`${i} shade${i===1?"":"s"} of ${n}`:`${i} colour${i===1?"":"s"}, most of the image first`,e.map((s,c)=>({id:`${o}-${c+1}`,name:s.hex,value:R(s.rgb),hex:s.hex})),r)}function _(t,e,r="light"){let n=T(t);return P(`${n[0]?.toUpperCase()??""}${n.slice(1)}`,`from ${h(t)} \xB7 50\u2013950 in OKLCH`,e.map(o=>({id:`${n}-${o.step}`,name:String(o.step),value:o.hex,hex:o.hex})),r)}var y=t=>{let e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4},B=({r:t,g:e,b:r})=>.2126*y(t)+.7152*y(e)+.0722*y(r);function E(t,e){let[r,n]=[B(t),B(e)].sort((o,i)=>i-o);return(r+.05)/(n+.05)}function et(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"large":"fails"}var G={r:255,g:255,b:255},N={r:0,g:0,b:0},H=t=>Math.floor(t*10)/10;function rt(t){return{white:H(E(t,G)),black:H(E(t,N))}}var K=[50,100,200,300,400,500,600,700,800,900,950],q=[1,.86,.68,.46,.22],J=[.2,.4,.6,.8,1];function it(t){let{L:e,C:r,h:n}=x(b(t)),o=r<.015,i=Math.max(.975,e),s=e<.16?.42*e:Math.max(.16,.42*e);return K.map((c,a)=>{if(a===5)return{step:c,rgb:{...t},hex:h(t),reference:!0};let l=a<5,g=l?q[a]:J[a-6],m=l?e+(i-e)*g:e-(e-s)*g,p=o?0:r*(l?1-.88*g:1-.45*g);for(;p>0&&!F(w({L:m,C:p,h:n}));)p-=.002;let f=A(w({L:m,C:Math.max(0,p),h:n}));return{step:c,rgb:f,hex:h(f),reference:!1}})}async function pt(t,e=192){let r=await M(t);if(r.kind!=="image")throw v(t,`a ${k[r.format].label}`);let n=r.format==="heic";if(n&&!await
|
|
10
|
+
</svg>`}function Z(t,e,r="light",n){let o=t.replace(/\.[^.]+$/,""),i=e.length;return P(t,n?`${i} shade${i===1?"":"s"} of ${n}`:`${i} colour${i===1?"":"s"}, most of the image first`,e.map((s,c)=>({id:`${o}-${c+1}`,name:s.hex,value:R(s.rgb),hex:s.hex})),r)}function _(t,e,r="light"){let n=T(t);return P(`${n[0]?.toUpperCase()??""}${n.slice(1)}`,`from ${h(t)} \xB7 50\u2013950 in OKLCH`,e.map(o=>({id:`${n}-${o.step}`,name:String(o.step),value:o.hex,hex:o.hex})),r)}var y=t=>{let e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4},B=({r:t,g:e,b:r})=>.2126*y(t)+.7152*y(e)+.0722*y(r);function E(t,e){let[r,n]=[B(t),B(e)].sort((o,i)=>i-o);return(r+.05)/(n+.05)}function et(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"large":"fails"}var G={r:255,g:255,b:255},N={r:0,g:0,b:0},H=t=>Math.floor(t*10)/10;function rt(t){return{white:H(E(t,G)),black:H(E(t,N))}}var K=[50,100,200,300,400,500,600,700,800,900,950],q=[1,.86,.68,.46,.22],J=[.2,.4,.6,.8,1];function it(t){let{L:e,C:r,h:n}=x(b(t)),o=r<.015,i=Math.max(.975,e),s=e<.16?.42*e:Math.max(.16,.42*e);return K.map((c,a)=>{if(a===5)return{step:c,rgb:{...t},hex:h(t),reference:!0};let l=a<5,g=l?q[a]:J[a-6],m=l?e+(i-e)*g:e-(e-s)*g,p=o?0:r*(l?1-.88*g:1-.45*g);for(;p>0&&!F(w({L:m,C:p,h:n}));)p-=.002;let f=A(w({L:m,C:Math.max(0,p),h:n}));return{step:c,rgb:f,hex:h(f),reference:!1}})}async function pt(t,e=192){let r=await M(t);if(r.kind!=="image")throw v(t,`a ${k[r.format].label}`);let n=r.format==="heic";if(n&&!await O())throw I(t);let o=n?await j(t):void 0;try{let s=(await L())(o?.path??t,{animated:!1}),{data:c,info:a}=await(n?s:s.rotate()).resize(e,e,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0});return{source:r,pixels:{width:a.width,height:a.height,rgba:new Uint8Array(c.buffer,c.byteOffset,c.length)}}}catch(i){throw C(i)?i:S(t,i)}finally{await o?.cleanup()}}export{Z as a,_ as b,E as c,et as d,rt as e,it as f,pt as g};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{homedir as e}from"node:os";import{join as t}from"node:path";function s(i=process.platform,r=process.env){let n=r.XDG_CONFIG_HOME;if(n!==void 0&&n.length>0)return n;if(i==="win32"){let o=r.APPDATA;return o!==void 0&&o.length>0?o:t(e(),"AppData","Roaming")}return t(e(),".config")}export{s as a};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
var u=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function d(t,a){if(t.isTTY!==!0)return{update:()=>{},tick:()=>{},stop:()=>{}};let r=0,n="",e=!1,i=60,o=()=>{e||t.write(`\r${" ".repeat(i)}\r${u[r%u.length]} ${a}${n}`)};return{update(s){n=s===""?"":` \xB7 ${s}`,r++,o()},tick(){r++,o()},stop(){e||(e=!0,t.write(`\r${" ".repeat(i)}\r`))}}}var R=new Set(["iTerm.app","WezTerm","ghostty","vscode"]),O=new Set(["xterm-kitty","xterm-ghostty"]),f=t=>t.WT_SESSION!==void 0&&t.WT_SESSION!=="";function E(t=process.env){return t.FORGE_POWERLINE==="1"?!0:t.FORGE_POWERLINE==="0"||t.NO_COLOR!==void 0&&t.NO_COLOR!==""?!1:f(t)?!0:R.has(t.TERM_PROGRAM??"")||O.has(t.TERM??"")}function c(t=process.env){return t.FORGE_TRUECOLOR==="1"?!0:t.FORGE_TRUECOLOR==="0"||t.NO_COLOR!==void 0&&t.NO_COLOR!==""?!1:t.COLORTERM==="truecolor"||t.COLORTERM==="24bit"||f(t)?!0:R.has(t.TERM_PROGRAM??"")||O.has(t.TERM??"")}export{u as a,d as b,E as c,c as d};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{b as K,c as Q,e as X,h as j,i as b,j as w,k as ee,l as te,m as re,n as oe,o as ne,p as se,t as T,u as ie,v as ae,y as ce}from"./chunk-775ILWZI.js";import{d as m}from"./chunk-OIZCRBLT.js";import{J as R,K as N,M as V,Q as Y,Z,ba as $,c as S,d as I,g as D,z as x}from"./chunk-E5QDHFKQ.js";import{readFile as Re,rm as De}from"node:fs/promises";var $e=new Set(["pdf"]),Te=new Set(["jpeg","png"]),Je=new Set(["convert"]),pe;function Ae(){return pe??=ee().then(e=>e.PDFiumLibrary.init()),pe}async function ue(e,t){return await(await Ae()).loadDocument(e,t)}async function fe(e){let t=await ue(e);try{let r=[];for(let o=0;o<t.getPageCount();o++)r.push(t.getPage(o).getText());return r}finally{t.destroy()}}var de={id:"pdfium",reads:$e,writes:Te,ops:Je,probe(){throw new Error("pdfium does not probe; engines/pdf.ts classifies PDFs")},async run(e,t){if(e.op!=="convert")throw new Error(`pdfium cannot ${e.op}`);let r=e.sources[0];if(r.kind!=="document")throw new Error("the pdfium engine can only rasterise a document source");if(r.encrypted&&e.options.password===void 0)throw x(r.path);let o=e.options.dpi??150,s=e.options.pages??Array.from({length:r.pages},(i,c)=>c);if(s.length!==e.outputs.length)throw new Error(`pdfium was given ${s.length} pages but ${e.outputs.length} outputs`);for(let i of s)if(i<0||i>=r.pages)throw new Error(`pdfium was asked for page ${i}, but ${r.path} has ${r.pages} pages`);let n=await b(),a=await ue(await Re(r.path),e.options.password);try{let i=[],c=0;try{for(let[p,u]of s.entries()){let f=await a.getPage(u).render({scale:o/72,render:"bitmap",transparent:!0}),d=n(f.data,{raw:{width:f.width,height:f.height,channels:4}}).flatten({background:e.options.background}),l=await T(d,e.target,e.options.quality).toBuffer(),h=e.outputs[p];c+=await m(h,l),i.push(h),t({phase:"page",done:p+1,total:s.length})}}catch(p){throw await Promise.all(i.map(u=>De(u,{force:!0}))),p}return{job:e,outputBytes:c,warnings:[]}}finally{a.destroy()}}};function Bt(e,t){let r=e.split(",").map(n=>n.trim()).filter(n=>n!=="");if(r.length===0)throw R(e,"That selects no pages.",t);let o=new Set,s=(n,a)=>{if(!Number.isInteger(n)||n<1||n>t)throw R(a,`"${a}" is outside 1 and ${t}.`,t);return n};for(let n of r){let a=n.match(/^(\d+)\s*-\s*(\d*)$/);if(a?.[1]!==void 0){let i=s(Number(a[1]),n),c=a[2]===""?t:s(Number(a[2]),n);if(c<i)throw R(n,`"${n}" ends before it starts.`,t);for(let p=i;p<=c;p++)o.add(p-1);continue}if(!/^\d+$/.test(n))throw R(n,`"${n}" is not a page number.`,t);o.add(s(Number(n),n)-1)}return[...o].sort((n,a)=>n-a)}function me(e){return[...new Set(e)].sort((t,r)=>t-r)}function kt(e){if(e.length===0)return"";let t=[...new Set(e)].sort((n,a)=>n-a),r=[],o=t[0],s=o;for(let n of t.slice(1)){if(n===s+1){s=n;continue}r.push(o===s?`${o+1}`:`${o+1}-${s+1}`),o=n,s=n}return r.push(o===s?`${o+1}`:`${o+1}-${s+1}`),r.join(", ")}function ge(e,t){let r=[...new Set(e)].sort((n,a)=>n-a).filter(n=>n>=0&&n<t-1),o=[],s=0;for(let n of r)o.push({from:s,to:n}),s=n+1;return o.push({from:s,to:t-1}),o}import{mkdtemp as Le,rm as Be}from"node:fs/promises";import{tmpdir as ke}from"node:os";import{join as J}from"node:path";var we=(e,t,r)=>X(e,t,r)===void 0;function le(e,t,r=Number.POSITIVE_INFINITY,o=[2,4]){return[...o].reverse().find(s=>s<r&&we(e,t,s))??0}async function Ne(e,t,r){if(e.op!=="boost"&&e.op!=="remove-background")throw new Error(`the extension engine cannot ${e.op}`);if(r?.aborted)throw r.reason??new Error("aborted");let o=e.sources[0],s=e.outputs[0],n=e.op,{assetFor:a,catalogEntry:i,offeredHere:c}=await import("./catalog-O3V24DK7.js");if(!c(n))throw Y(i(n)?.title??n);let{installed:p,extensionsRoot:u}=await import("./paths-H2WS22BA.js"),f=await p(n);if(!f)throw V(n);let d=K(f.version);if(e.op==="boost"){let g=i(n),P=Q(e.scale,f.version,g&&a(g)?.version);if(P)throw P}if(e.op==="boost"&&!we(o.width,o.height,e.scale))throw Z(o.path,le(o.width,o.height,Number.POSITIVE_INFINITY,d),e.scale);let{runExtension:l}=await import("./run-C475RRUL.js"),h=[];o.frames>1&&h.push({code:"animation-flattened",message:`${S(o.path)} has ${o.frames} frames. Only the first frame was used.`});let F=await Le(J(ke(),"forge-ext-"));try{t({phase:"decoding"});let g=J(F,"in.png"),P=J(F,"out.png");await ae(o,g);let Fe=e.op==="boost"?["--in",g,"--out",P,"--scale",String(e.scale),"--cache",J(u(),"boost","cache")]:[g,P];await l(f,Fe,{subject:o.path,what:`${Oe(e)} is running on ${S(o.path)}`,onWait:()=>t({phase:"waiting"}),onStart:()=>t({phase:"encoding"}),...e.op==="boost"?{maxScale:le(o.width,o.height,e.scale,d)}:{},...r===void 0?{}:{signal:r}});let k=(await b())(P);I[e.target].hasAlpha||(k=k.flatten({background:e.options.background}));let Se=await T(k,e.target,e.options.quality).toBuffer();t({phase:"writing"});let Ie=await ie(Se,s);return{job:e,outputBytes:Ie,warnings:h}}catch(g){throw D(g)?g:$(o.path,g)}finally{await Be(F,{recursive:!0,force:!0}).catch(()=>{})}}function Oe(e){return e.op!=="boost"?"Remove background":e.scale===1?"Sharpen":`Boost resolution ${e.scale}\xD7`}var he={id:"extension",reads:new Set,writes:new Set,ops:new Set(["boost","remove-background"]),probe:()=>Promise.reject(new Error("the extension engine reads no files")),run:Ne};import{readFile as A,rm as ye,stat as We}from"node:fs/promises";var W=j(()=>import("./pdf-compress-IMRFBLZF.js")),_e=new Set(["pdf","jpeg","png","webp","avif","gif","tiff"]),ze=new Set(["pdf"]);async function E(e){return(await w()).PDFDocument.load(await A(e),{ignoreEncryption:!0})}async function Ce(e){let{surveyDocument:t}=await W(),r=await E(e),{size:o}=await We(e);return{kind:"document",path:e,format:"pdf",bytes:o,pages:r.getPageCount(),encrypted:r.isEncrypted,images:t(r)}}function v(e){for(let t of e)if(t.encrypted)throw x(t.path)}async function Ge(e,t,r){let o=await b(),s=t.format==="jpeg"||t.format==="png",n=s?(await o(r).metadata()).orientation:void 0;if(s&&(n===void 0||n===1))return t.format==="jpeg"?e.embedJpg(r):e.embedPng(r);if(t.format==="jpeg"){let a=await o(r).rotate().jpeg({quality:I.jpeg.defaultQuality,mozjpeg:!0}).toBuffer();return e.embedJpg(a)}return e.embedPng(await o(r).rotate().png().toBuffer())}async function Me(e,t){let r=e.sources[0];if(r.kind!=="image")throw new Error("the pdf engine cannot embed a document source");let o=[];r.frames>1&&o.push({code:"animation-flattened",message:`${S(r.path)} has ${r.frames} frames, and ${I.pdf.label} cannot animate. Only the first frame was converted.`}),t({phase:"reading"});let s=await A(r.path);t({phase:"encoding"});let a=await(await w()).PDFDocument.create(),i=await Ge(a,r,s);a.addPage([i.width,i.height]).drawImage(i,{x:0,y:0,width:i.width,height:i.height}),t({phase:"writing"});let p=await m(e.outputs[0],await a.save());return{job:e,outputBytes:p,warnings:o}}async function qe(e,t){v(e.sources.filter(a=>a.kind==="document"));let o=await(await w()).PDFDocument.create();for(let a of e.sources){t({phase:"reading"});let i=await E(a.path),c=await o.copyPages(i,i.getPageIndices());for(let p of c)o.addPage(p)}t({phase:"writing"});let s=await o.save(),n=await m(e.outputs[0],s);return{job:e,outputBytes:n,warnings:[]}}async function Ue(e,t){let r=e.sources[0];v([r]);let o=await w();t({phase:"reading"});let s=await E(r.path),n=ge(e.cuts,s.getPageCount()),a=[],i=0;try{for(let[c,p]of n.entries()){let u=await o.PDFDocument.create(),f=Array.from({length:p.to-p.from+1},(h,F)=>p.from+F),d=await u.copyPages(s,f);for(let h of d)u.addPage(h);let l=e.outputs[c];if(l===void 0)throw new Error(`split produced ${n.length} parts but was given ${e.outputs.length} outputs`);i+=await m(l,await u.save()),a.push(l),t({phase:"page",done:c+1,total:n.length})}}catch(c){throw await Promise.all(a.map(p=>ye(p,{force:!0}))),c}return{job:e,outputBytes:i,warnings:[]}}async function O(e,t){let o=await(await w()).PDFDocument.create(),s=await o.copyPages(e,t);for(let n of s)o.addPage(n);return o.save()}async function He(e,t){let r=e.sources[0];if(v([r]),e.pages.length===0)throw N("That extract selects no pages.");t({phase:"reading"});let o=await E(r.path),s=me(e.pages),n=[],a=0;try{if(e.separate)for(let[i,c]of s.entries()){let p=e.outputs[i];a+=await m(p,await O(o,[c])),n.push(p),t({phase:"page",done:i+1,total:s.length})}else{t({phase:"writing"});let i=e.outputs[0];a=await m(i,await O(o,s)),n.push(i)}}catch(i){throw await Promise.all(n.map(c=>ye(c,{force:!0}))),i}return{job:e,outputBytes:a,warnings:[]}}async function Ve(e,t){let r=e.sources[0];v([r]),t({phase:"reading"});let o=await E(r.path),s=new Set(e.pages),n=o.getPageIndices().filter(i=>!s.has(i));if(n.length===0)throw N("That would delete every page.");t({phase:"writing"});let a=await m(e.outputs[0],await O(o,n));return{job:e,outputBytes:a,warnings:[]}}async function Ye(e,t){let r=e.sources[0];v([r]);let o=await w();t({phase:"reading"});let s=await E(r.path);for(let a of s.getPages()){let c=((a.getRotation().angle+e.turns*90)%360+360)%360;a.setRotation(o.degrees(c))}t({phase:"writing"});let n=await m(e.outputs[0],await s.save());return{job:e,outputBytes:n,warnings:[]}}async function Ze(e,t){let r=e.sources[0];v([r]);let{compressPdf:o}=await W();t({phase:"reading"});let s=await A(r.path);t({phase:"encoding"});let{bytes:n,recompressed:a,skipped:i,fromDpi:c,toDpi:p}=await o(s,{quality:e.options.quality??60,dpi:e.options.dpi??150});t({phase:"writing"});let u=await m(e.outputs[0],n),f=l=>l===1?"":"s",d=[];return a===0&&i===0?d.push({code:"pdf-no-images",message:"This PDF has no images to re-encode, so its size is almost unchanged."}):a===0?d.push({code:"pdf-no-images",message:`None of its ${i} image${f(i)} could be re-encoded \u2014 they are not JPEG data.`}):i>0&&d.push({code:"pdf-images-skipped",message:`${a} image${f(a)} recompressed, ${i} skipped (not JPEG).`}),c!==void 0&&p!==void 0&&d.push({code:"pdf-downsampled",message:`Images reduced from ${c} to ${p} dpi. Pass --dpi ${c} to keep them.`}),{job:e,outputBytes:u,warnings:d}}async function Ke(e){if(e.op!=="convert")return;let t=e.sources[0];if(t.kind!=="document")return;let{compressPdf:r}=await W(),o=await A(t.path);return{ladder:[e.options.dpi??150,120,96,72].map(s=>({dpi:s})),measure:async s=>(await r(o,{quality:s.quality??60,...s.dpi===void 0?{}:{dpi:s.dpi}})).bytes.byteLength}}var Pe={id:"pdf",measurer:Ke,reads:_e,writes:ze,ops:new Set(["convert","merge","split","extract","delete","rotate"]),probe:Ce,async run(e,t){switch(e.op){case"convert":if(e.target!=="pdf")throw new Error("the pdf engine only converts to pdf");return e.sources[0].kind==="document"?Ze(e,t):Me(e,t);case"merge":return qe(e,t);case"split":return Ue(e,t);case"extract":return He(e,t);case"delete":return Ve(e,t);case"rotate":return Ye(e,t);default:throw new Error(`the pdf engine cannot ${e.op}`)}}};import{execFile as Qe}from"node:child_process";import{mkdtemp as Xe,readFile as q,rm as je}from"node:fs/promises";import{tmpdir as et}from"node:os";import{basename as tt,extname as rt,join as xe,win32 as G}from"node:path";import{pathToFileURL as ot}from"node:url";import{promisify as nt}from"node:util";var M=nt(Qe),_=Buffer.from([208,207,17,224,161,177,26,225]);async function st(e){if(e.length<_.length||!e.subarray(0,_.length).equals(_))return!1;let t=await ne();try{return t.find(t.parse(e),"WordDocument")!==null}catch{return!1}}async function it(e){let t=await oe();try{let r=new t(e);if(!r.getEntry("word/document.xml"))return;let o=0,s=r.getEntry("docProps/app.xml");if(s){let n=/<Pages>(\d+)<\/Pages>/.exec(r.readAsText(s));n?.[1]&&(o=Number(n[1]))}return{pages:o}}catch{return}}async function at(e){let t=await q(e),r=await it(t);if(r)return{kind:"document",path:e,format:"docx",bytes:t.byteLength,pages:r.pages,encrypted:!1};if(await st(t))return{kind:"document",path:e,format:"doc",bytes:t.byteLength,pages:0,encrypted:!1};throw new Error(`${e} is not a Word document`)}function ct(e,t){return e==="win32"?[G.join(t.ProgramFiles??"C:\\Program Files","LibreOffice","program","soffice.exe"),G.join(t["ProgramFiles(x86)"]??"C:\\Program Files (x86)","LibreOffice","program","soffice.exe")]:["/Applications/LibreOffice.app/Contents/MacOS/soffice"]}var pt=0;async function ut(){pt++;try{return await M("soffice",["--version"],{timeout:5e3}),"soffice"}catch{}for(let e of ct(process.platform,process.env))try{return await M(e,["--version"],{timeout:5e3}),e}catch{}}var be,ft=!1,dt;async function mt(){return ft?dt:(be??=ut(),be)}var U="\f";function L(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)}async function gt(e){if(e.format==="docx"){let r=await te(),{value:o}=await r.extractRawText({path:e.path});return L(o)}if(e.format==="doc"){let r=await re(),s=await new r().extract(e.path);return L(s.getBody())}return(await fe(await q(e.path))).flatMap((r,o)=>o===0?L(r):[U,...L(r)])}var z=612,B=792,y=54,C=11,Ee=14;async function lt(e){let{PDFDocument:t,StandardFonts:r}=await w(),o=await t.create(),s=await o.embedFont(r.Helvetica),n=z-y*2,a=o.addPage([z,B]),i=B-y,c=()=>{a=o.addPage([z,B]),i=B-y};for(let p of e){if(p===U){c();continue}let u="";for(let f of p.split(/\s+/).filter(Boolean)){let d=u?`${u} ${f}`:f;u&&s.widthOfTextAtSize(d,C)>n?(i<y&&c(),a.drawText(u,{x:y,y:i,size:C,font:s}),i-=Ee,u=f):u=d}u&&(i<y&&c(),a.drawText(u,{x:y,y:i,size:C,font:s}),i-=Ee)}return o.save()}async function wt(e){let{Document:t,Packer:r,PageBreak:o,Paragraph:s}=await se(),n=e.map(i=>i===U?new s({children:[new o]}):new s(i)),a=new t({sections:[{children:n}]});return r.toBuffer(a)}var ht=new Set(["docx","doc","pdf"]),yt=new Set(["docx","pdf"]),Pt=new Set(["convert"]),xt={code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice for full-fidelity conversion: brew install --cask libreoffice"};function bt(e=process.platform){return e!=="win32"?xt:{code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice from libreoffice.org for full-fidelity conversion."}}function Et(e,t,r,o=process.platform){return[`-env:UserInstallation=${o==="win32"?ot(G.join(e,"profile"),{windows:!0}).href:`file://${e}/profile`}`,"--headless","--convert-to",r,"--outdir",e,t]}async function vt(e,t,r){let o=await Xe(xe(et(),"forge-word-"));try{await M(e,Et(o,t,r),{timeout:12e4});let s=tt(t,rt(t));return await q(xe(o,`${s}.${r}`))}finally{await je(o,{recursive:!0,force:!0})}}async function Ft(e,t){if(e.op!=="convert")throw new Error(`the word engine cannot ${e.op}`);let r=e.sources[0];if(r.kind!=="document")throw new Error("the word engine can only convert a document source");if(r.encrypted)throw x(r.path);t({phase:"reading"});let o=await mt();t({phase:"encoding"});let s=[],n;try{if(o!==void 0)n=await vt(o,r.path,e.target);else{let i=await gt(r);n=e.target==="pdf"?await lt(i):await wt(i),s.push(bt())}}catch(i){throw $(r.path,i)}t({phase:"writing"});let a=await m(e.outputs[0],n);return{job:e,outputBytes:a,warnings:s}}var ve={id:"word",reads:ht,writes:yt,ops:Pt,probe:at,run:Ft};var H=[ce,Pe,ve,he,de];function yr(e){if(e.op==="convert"){let t=e.sources[0].format;return H.find(r=>r.reads.has(t)&&r.writes.has(e.target))}return H.find(t=>t.ops.has(e.op))}async function Pr(e){let t;for(let r of H)try{return await r.probe(e)}catch(o){D(t)||(t=o)}throw t}function St(e){switch(e.op){case"convert":return e.options.trim&&e.options.resize?"trimmed and resized":e.options.resize?"resized":e.options.trim?"trimmed":e.target===e.sources[0].format?"compressed":"converted";case"merge":return"merged";case"split":return"split";case"extract":return"extracted";case"delete":return"deleted from";case"rotate":return"rotated";case"boost":return e.scale===1?"sharpened":"boosted";case"remove-background":return"cut out";default:{let t=e;throw new Error(`describeResult has no verb for ${JSON.stringify(t)}`)}}}function br(e){let{job:t}=e,r=t.sources.map(s=>({path:s.path,bytes:s.bytes})),o=r.length===1&&t.outputs.length===1?r[0]:void 0;return{verb:St(t),sources:r,outputs:[...t.outputs],outputBytes:e.outputBytes,...o?{size:{from:o.bytes,to:e.outputBytes}}:{},warnings:e.warnings}}export{Bt as a,me as b,kt as c,ge as d,ue as e,de as f,H as g,yr as h,Pr as i,br as j};
|
|
@@ -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 m,g as n}from"./chunk-
|
|
3
|
+
import{f as m,g as n}from"./chunk-LI2JPLF7.js";import{I as f,d as r}from"./chunk-E5QDHFKQ.js";function a(t){let e=Object.keys(r);return[...t].sort((o,i)=>e.indexOf(o)-e.indexOf(i))}function s(t){let e=new Set;for(let o of n)if(o.reads.has(t.format))for(let i of o.writes)e.add(i);return a([...e])}function I(t){return s(t).map(e=>({id:e,label:r[e].label,hint:r[e].hint,lossy:r[e].lossy}))}function d(){let t=new Set;for(let e of n)for(let o of e.reads)t.add(o);return a([...t])}function p(){let t=new Set;for(let e of n)for(let o of e.writes)t.add(o);return a([...t])}function F(t){return m.writes.has(t)}function g(){let t=new Set(d()),e=new Set(p());return a([...new Set([...t,...e])]).map(o=>({id:o,label:r[o].label,extensions:[...r[o].extensions],read:t.has(o),write:e.has(o),lossy:r[o].lossy}))}var z=5,R=200,$=5;function O(t){return t.format==="heic"?"jpeg":s(t).includes(t.format)?t.format:"png"}function j(t,e){let o=n.find(i=>i.id==="image")?.writes;if(!o?.has(t))return f(`Cannot ${e} into ${r[t].label}; only an image format can take the edit.`,`Choose one of: ${[...o??[]].join(", ")}.`)}var T=t=>`${t.width}x${t.height}`,C=t=>"percent"in t?`${t.percent}pct`:"width"in t?`${t.width}w`:`${t.height}h`;export{s as a,I as b,d as c,p as d,F as e,g as f,z as g,R as h,$ as i,O as j,j as k,T as l,C as m};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{R as a,S as u,T as l}from"./chunk-E5QDHFKQ.js";import{spawn as x}from"node:child_process";import{existsSync as c,realpathSync as b}from"node:fs";import{dirname as h,join as E,win32 as d}from"node:path";function f(n,t=process.platform,e=c){if(n===void 0)return!1;if(t==="win32"){let r=/^(.*)[\\/]node_modules[\\/]forge-terminal[\\/]/.exec(n)?.[1];return r!==void 0&&e(d.join(r,"forge.cmd"))}return/\/lib\/node_modules\/forge-terminal\//.test(n)&&!n.includes("/_npx/")}function m(n){if(n!==void 0)try{return b(n)}catch{return n}}function P(n,t=c){let e=E(h(n),"npm");return t(e)?e:"npm"}function R(n,t=c){let e=d.join(d.dirname(n),"node_modules","npm","bin","npm-cli.js");return t(e)?e:void 0}var g=(n,t,e)=>new Promise(r=>{let o="",s=x(n,t,{stdio:["ignore","pipe","pipe"],...e?{signal:e}:{}});s.stdout.setEncoding("utf8").on("data",i=>{o+=i}),s.stderr.setEncoding("utf8").on("data",i=>{o+=i}),s.on("error",i=>r({code:null,output:`${o}
|
|
4
|
+
${i.message}`})),s.on("close",i=>r({code:i,output:o}))});function w(n){return n.split(`
|
|
5
|
+
`).map(e=>e.replace(/^npm (error|ERR!)\s*/,"").trim()).filter(e=>e!==""&&!/^(code|errno|syscall|path|dest|A complete log)/.test(e)).at(-1)??"npm exited without saying why"}async function _(n,t={}){let e=t.platform??process.platform;if(e==="win32")return S(n,t);let r=t.script??m(process.argv[1]);if(!f(r,e))throw a(n);let o=t.npm??P(process.execPath),s=t.run??g,{code:i,output:p}=await s(o,["install","--global",`forge-terminal@${n}`],t.signal);if(i!==0)throw/EACCES|EPERM|permission denied/i.test(p)?u(n,e):l(n,w(p))}async function S(n,t){let e=t.script??m(process.argv[1]);if(!f(e,"win32",t.exists))throw a(n);let r=R(process.execPath,t.exists);if(r===void 0)throw l(n,"npm was not found beside Node");let o=t.run??g,{code:s,output:i}=await o(process.execPath,[r,"install","--global",`forge-terminal@${n}`],t.signal);if(s!==0)throw/EACCES|EPERM|EBUSY|permission denied/i.test(i)?u(n,"win32"):l(n,w(i))}export{f as a,m as b,P as c,R as d,_ as e};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{E as s,F as a,G as m}from"./chunk-E5QDHFKQ.js";import{randomBytes as f}from"node:crypto";import{constants as u}from"node:fs";import{access as d,mkdir as p,rename as w,rm as S,writeFile as h}from"node:fs/promises";import{dirname as y}from"node:path";async function P(t){let e=y(t);try{await p(e,{recursive:!0})}catch(r){let i=a(t,r);throw i===r?m(t,r):i}try{await d(e,u.W_OK)}catch(r){throw s(t,r)}}var A=new Set(["EPERM","EBUSY","EACCES"]),N=5,M=9;async function T(t,e,r=process.platform,i=o=>new Promise(n=>setTimeout(n,o)),E=N){if(r!=="win32"){await w(t,e);return}for(let o=1;;o++)try{await w(t,e);return}catch(n){let c=n.code;if(o>=E||!c||!A.has(c))throw n;await i(Math.min(50*2**(o-1),1e3))}}async function O(t,e){await P(t);let r=`${t}.${f(6).toString("hex")}.tmp`;try{return await h(r,e),await T(r,t),e.byteLength}catch(i){throw await S(r,{force:!0}).catch(()=>{}),a(t,i)}}export{P as a,M as b,T as c,O as d};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{I as n}from"./chunk-E5QDHFKQ.js";import{c as i,e as s,f as o}from"./chunk-4L6HNYSN.js";var g=["output","theme","quality","update-check"];async function p(a){if(a.action==="path")return{stdout:[i()],exitCode:0,config:{path:i()},warnings:[]};if(a.action==="list"){let{prefs:e,warning:u}=await s(),f=[`output ${e.defaultOutput}`,`theme ${e.theme??"not set"}`,`quality ${e.quality}`,`update-check ${e.updateCheck===!1?"off":"on"}`,"",i()];return u!==void 0&&f.unshift(`\u26A0 ${u}`,""),{stdout:f,exitCode:0,config:{output:e.defaultOutput,theme:e.theme??null,quality:e.quality,"update-check":e.updateCheck===!1?"off":"on",path:i()},warnings:u===void 0?[]:[{code:"config-unreadable",message:u}]}}let{key:r,value:t}=a;if(r==="theme"){if(t!=="dark"&&t!=="light")throw n(`Theme must be dark or light, not ${t}.`);return await o({theme:t}),{stdout:[`theme is now ${t}`],exitCode:0,config:{theme:t},warnings:[]}}if(r==="quality"){let e=Number(t);if(!Number.isInteger(e)||e<1||e>100)throw n(`Quality must be a whole number between 1 and 100, not ${t}.`);return await o({quality:e}),{stdout:[`quality is now ${e}`],exitCode:0,config:{quality:e},warnings:[]}}if(r==="update-check"){if(t!=="on"&&t!=="off")throw n(`update-check must be on or off, not ${t}.`);return await o({updateCheck:t==="on"}),{stdout:[`update-check is now ${t}`],exitCode:0,config:{"update-check":t},warnings:[]}}if(t.trim().length===0)throw n("Output must be a folder path.");return await o({defaultOutput:t}),{stdout:[`output is now ${t}`],exitCode:0,config:{output:t},warnings:[]}}export{g as a,p as b};
|