forge-terminal 0.3.1 → 0.3.3
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 +59 -17
- package/dist/chunks/about-credits-2XUFRHGQ.js +4 -0
- package/dist/chunks/{boot-3M2WUSSL.js → boot-NP6SNVTV.js} +1 -1
- package/dist/chunks/{check-DN7SEN44.js → check-BRP6EKSA.js} +1 -1
- package/dist/chunks/{chunk-OIZCRBLT.js → chunk-32VJ2RDH.js} +1 -1
- package/dist/chunks/{chunk-VNAIHACR.js → chunk-3GVFOZ7M.js} +1 -1
- package/dist/chunks/{chunk-W42HVOBD.js → chunk-4QQEJ6YG.js} +1 -1
- package/dist/chunks/chunk-BZXDNDPG.js +3 -0
- package/dist/chunks/chunk-DG4IXNWJ.js +4 -0
- package/dist/chunks/{chunk-Z5PQWCG5.js → chunk-G4DU5ADF.js} +2 -2
- package/dist/chunks/{chunk-LI2JPLF7.js → chunk-GGBNT4WI.js} +1 -1
- package/dist/chunks/chunk-GNLE6JXL.js +3 -0
- package/dist/chunks/chunk-H2IUSPAK.js +4 -0
- package/dist/chunks/{chunk-Q45MSMTN.js → chunk-I6QBBRCE.js} +1 -1
- package/dist/chunks/chunk-K2ABBIR4.js +19 -0
- package/dist/chunks/chunk-KSRGJD2E.js +66 -0
- package/dist/chunks/{chunk-M6LD6DHO.js → chunk-LW2QEXDT.js} +1 -1
- package/dist/chunks/chunk-MBTGANIR.js +3 -0
- package/dist/chunks/{chunk-E5QDHFKQ.js → chunk-MMRDELHW.js} +1 -1
- package/dist/chunks/chunk-QXTXBMTM.js +3 -0
- package/dist/chunks/{chunk-NY6BX7QS.js → chunk-SAWVMQAD.js} +1 -1
- package/dist/chunks/{chunk-6ZEGAH36.js → chunk-TEO2EUS3.js} +1 -1
- package/dist/chunks/chunk-U5TEGDGH.js +3 -0
- package/dist/chunks/chunk-WFD6OWQY.js +3 -0
- package/dist/chunks/{chunk-YZG5A3GA.js → chunk-X54KIHCN.js} +1 -1
- package/dist/chunks/colour-D7L5VGQC.js +3 -0
- package/dist/chunks/{config-command-UW6BYQ2K.js → config-command-TXQUYFA6.js} +1 -1
- package/dist/chunks/execute-75YNMBFF.js +3 -0
- package/dist/chunks/extensions-4OWNFLEI.js +3 -0
- package/dist/chunks/{extensions-command-5QO6YX6O.js → extensions-command-UGXZIFRI.js} +1 -1
- package/dist/chunks/image-F5D73JPQ.js +3 -0
- package/dist/chunks/{install-HCF5BIA6.js → install-YG43OJ7P.js} +1 -1
- package/dist/chunks/launch-OVBNYIQE.js +4 -0
- package/dist/chunks/{lock-RZ6NVZFD.js → lock-6KTGUFBY.js} +1 -1
- package/dist/chunks/{manager-7HNOLCYH.js → manager-XN7WNMEW.js} +1 -1
- package/dist/chunks/{preferences-AKDCPHJ5.js → preferences-YL6SRNZR.js} +1 -1
- package/dist/chunks/{restart-6ONEYN6T.js → restart-RO6DM5N3.js} +1 -1
- package/dist/chunks/reveal-L6TBFOMV.js +3 -0
- package/dist/chunks/{run-C475RRUL.js → run-XQYPVWFI.js} +1 -1
- package/dist/chunks/{server-ETHSTOP6.js → server-3VV7IJPS.js} +15 -15
- package/dist/chunks/{theme-TYCKAIEA.js → theme-RVWVYUCH.js} +1 -1
- package/dist/chunks/{update-command-HT2RBFLR.js → update-command-6VNVMAYO.js} +1 -1
- package/dist/chunks/{update-note-ES7TWSUT.js → update-note-UA3267X2.js} +1 -1
- package/dist/index.js +31 -31
- package/package.json +1 -1
- package/skills/forge/SKILL.md +19 -1
- package/dist/chunks/chunk-4L6HNYSN.js +0 -4
- package/dist/chunks/chunk-775ILWZI.js +0 -3
- package/dist/chunks/chunk-GDQQDHXJ.js +0 -10
- package/dist/chunks/chunk-RE7E6NA7.js +0 -3
- package/dist/chunks/chunk-XYYVNUE6.js +0 -4
- package/dist/chunks/colour-6YGDI44N.js +0 -3
- package/dist/chunks/execute-BRPAGFUR.js +0 -3
- package/dist/chunks/image-ESDL7GZU.js +0 -3
- package/dist/chunks/launch-ILBEFGNR.js +0 -65
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ That puts `forge` on your `PATH`, so it works from any directory. Verify:
|
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
45
|
forge --version
|
|
46
|
-
# 0.3.
|
|
46
|
+
# 0.3.3
|
|
47
47
|
|
|
48
48
|
forge photo.jpg --to webp
|
|
49
49
|
```
|
|
@@ -265,6 +265,27 @@ warns. `forge_convert` takes
|
|
|
265
265
|
`trim: true` and `resize: { percent } | { width } | { height }`, and then `to`
|
|
266
266
|
is optional.
|
|
267
267
|
|
|
268
|
+
## Crop to shape
|
|
269
|
+
|
|
270
|
+
Cut a photo to a shape — the largest box of that shape it holds, placed to
|
|
271
|
+
keep the subject. Built in, images only, and the format is kept unless `--to`
|
|
272
|
+
says otherwise:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
forge photo.jpg --crop 1:1 # photo-cropped-1x1.jpg
|
|
276
|
+
forge photo.jpg --crop 4:5 --width 1080 --to webp # photo-cropped-4x5-1080x1350.webp
|
|
277
|
+
forge *.jpg --crop 16:9 -o out/
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The shape is `W:H`, two whole numbers from 1 to 100. A `--resize`, `--width`
|
|
281
|
+
or `--height` applies to the cropped image. `--crop` combines with the same
|
|
282
|
+
flags resize does, and is refused with the same ones — and with `--trim`: run
|
|
283
|
+
one, then the other. Cropping an animated image is refused; so is cropping one
|
|
284
|
+
that already has the shape, unless it is also resized, which then only warns.
|
|
285
|
+
`forge_convert` takes `crop: "1:1"` (any `W:H`), and then `to` is optional.
|
|
286
|
+
In the app, Crop to shape is an Enhance row with a preview you can move and
|
|
287
|
+
zoom.
|
|
288
|
+
|
|
268
289
|
## Boost resolution and remove background
|
|
269
290
|
|
|
270
291
|
Two image operations that need a model, so they are optional extensions rather
|
|
@@ -584,28 +605,47 @@ colour. Both are in the shell as its fourth mode, and on the command line.
|
|
|
584
605
|
|
|
585
606
|
### In the shell
|
|
586
607
|
|
|
587
|
-
Press **
|
|
588
|
-
**Scale**. Choose one with ←→ and open it with ↵. You can
|
|
589
|
-
straight onto colour's home, or press `#`
|
|
608
|
+
Press **5** (or type `/colour`). Home shows three cards: **Extract**,
|
|
609
|
+
**Scale** and **Palette**. Choose one with ←→ and open it with ↵. You can
|
|
610
|
+
also drop an image straight onto colour's home, or press `#` (or paste a
|
|
611
|
+
colour) to type one.
|
|
590
612
|
|
|
591
|
-
|
|
613
|
+
The colour box takes a hex code, `rgb()`, `hsl()`, `oklch()` or a colour
|
|
614
|
+
name: CSS's 148 and the xkcd colour survey's 949 everyday ones, so
|
|
615
|
+
`cherry red` works. Something it can't read turns red, marked `wrong input`.
|
|
616
|
+
|
|
617
|
+
- **Extract.** Drop an image, or type its path into the field at the top. The
|
|
592
618
|
photo is drawn in its own colours next to the list, with each colour's share
|
|
593
619
|
of the image.
|
|
594
620
|
- ↑↓ choose a colour; it stays lit in the photo and the rest dim.
|
|
595
621
|
- → goes inside a colour: its shades, lit where they are in the photo.
|
|
596
622
|
← comes back.
|
|
597
623
|
- `s` makes a scale from the chosen colour.
|
|
598
|
-
- **Scale.** Type a
|
|
624
|
+
- **Scale.** Type a colour. You get 50–950 with your colour at 500, and a
|
|
599
625
|
preview of the chosen step: "Aa" in white and black, with each rated
|
|
600
626
|
(AAA, AA, large, fails).
|
|
601
|
-
- ←→ choose a step.
|
|
627
|
+
- ←→ choose a step; `s` chooses the steps (Tailwind, Even, Radix).
|
|
628
|
+
- `tab` switches between three tabs. **Colour** is the scale itself.
|
|
629
|
+
**Neutral** is a grey scale tinted with your colour's hue (tint: none,
|
|
630
|
+
faint, soft, strong). **Alpha** is each step as the most see-through
|
|
631
|
+
`#RRGGBBAA` that looks the same over white (or black), drawn over a
|
|
632
|
+
checkerboard with its opacity on it.
|
|
602
633
|
- `r` makes that step the new centre and rebuilds the scale around it.
|
|
603
|
-
-
|
|
604
|
-
|
|
605
|
-
|
|
634
|
+
- `→` at the end of a colour in the box asks for a second: ↵ **mixes**
|
|
635
|
+
the two, in OKLab or OKLCH, in 3 to 21 steps.
|
|
636
|
+
- **Palette.** Type one colour and get a whole palette that goes with it:
|
|
637
|
+
red, orange, yellow, green, teal, blue, purple and pink, each a 50–950
|
|
638
|
+
scale, and a neutral.
|
|
639
|
+
- `m` chooses a mode: Full set, Monochromatic, Analogous, Complementary,
|
|
640
|
+
Split complementary, Triadic or Pastel.
|
|
641
|
+
- `t` tweaks the whole palette: brightness, saturation and contrast from
|
|
642
|
+
−100 to +100, hue from −180° to +180°. ←→ moves by 1, ⇧←→ by 10, and `r`
|
|
643
|
+
resets.
|
|
644
|
+
|
|
645
|
+
On every screen, ↵ copies the chosen hex and `c` copies the whole set. Paste
|
|
606
646
|
it into Figma with ⌘V: you get real shapes and text layers, named
|
|
607
647
|
`blue-500` and so on. esc goes back one step, and the bar at the top shows
|
|
608
|
-
the way back. Under `NO_COLOR`,
|
|
648
|
+
the way back. Under `NO_COLOR`, the screens are plain text with every key
|
|
609
649
|
still working.
|
|
610
650
|
|
|
611
651
|
### On the command line
|
|
@@ -636,8 +676,10 @@ $ forge scale 6579FD
|
|
|
636
676
|
- **`forge scale <colour>`** gives 50–950 built in OKLCH, with your colour
|
|
637
677
|
exactly at 500. Each step is rated for white and black text (WCAG: AAA, AA,
|
|
638
678
|
large, fails). Ratios are rounded down, so 4.48:1 shows as `4.4 large` and
|
|
639
|
-
is never passed off as AA.
|
|
640
|
-
|
|
679
|
+
is never passed off as AA. The colour can be written as the colour box
|
|
680
|
+
takes it (`forge scale crimson`, `forge scale 'rgb(210 4 45)'`). Pass a hex
|
|
681
|
+
without the `#`, or quote it (`'#6579FD'`): an unquoted `#` starts a
|
|
682
|
+
comment in the shell.
|
|
641
683
|
- **`--svg`** prints a card of swatches. Pipe it to `pbcopy` and press ⌘V in
|
|
642
684
|
Figma to get real shapes and text layers: `forge scale 6579FD --svg | pbcopy`.
|
|
643
685
|
- **`--json`** returns `palette` (`source`, `colours[]` with `hex`, `rgb`,
|
|
@@ -847,11 +889,11 @@ Seven tools, deliberately few:
|
|
|
847
889
|
| --- | --- |
|
|
848
890
|
| `forge_probe` | what files are and what Forge can do with them |
|
|
849
891
|
| `forge_formats` | the capability matrix |
|
|
850
|
-
| `forge_convert` | convert to a target format (`quality`, `dpi`, `pages`, `background`, `password`, `overwrite`; images also `sharpen`, `boost: 2 \| 3 \| 4` and `removeBackground`,
|
|
892
|
+
| `forge_convert` | convert to a target format (`quality`, `dpi`, `pages`, `background`, `password`, `overwrite`; images also `trim`, `crop`, `resize`, `sharpen`, `boost: 2 \| 3 \| 4` and `removeBackground`, the last two needing the optional extensions) |
|
|
851
893
|
| `forge_compress` | compress by `quality` or to a `maxSize` (also `dpi` for PDFs, `output`, `overwrite`; no `password`: compression refuses encrypted PDFs) |
|
|
852
894
|
| `forge_pdf` | `merge`, `split`, `extract`, `delete`, `rotate` |
|
|
853
895
|
| `forge_palette` | an image's main colours with their shares; `inside` gives one colour's shades (read-only) |
|
|
854
|
-
| `forge_scale` | a 50–950 tonal scale with the colour at 500, rated for white and black text (read-only) |
|
|
896
|
+
| `forge_scale` | a 50–950 tonal scale with the colour at 500, rated for white and black text; the colour as hex, `rgb()`, `hsl()`, `oklch()` or a name (read-only) |
|
|
855
897
|
|
|
856
898
|
Paths must be absolute. Results come back as structured content in the
|
|
857
899
|
`--json` shape below, with a `file://` link to every output, and never as
|
|
@@ -891,7 +933,7 @@ photo.png · PNG · 122 KB · 2756×774
|
|
|
891
933
|
With `--json`:
|
|
892
934
|
|
|
893
935
|
```json
|
|
894
|
-
{"forge":"0.3.
|
|
936
|
+
{"forge":"0.3.3","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":[]}
|
|
895
937
|
```
|
|
896
938
|
|
|
897
939
|
`targets` and `actions` come from the engines' own capabilities, so they are
|
|
@@ -917,7 +959,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
|
|
|
917
959
|
|
|
918
960
|
```jsonc
|
|
919
961
|
{
|
|
920
|
-
"forge": "0.3.
|
|
962
|
+
"forge": "0.3.3",
|
|
921
963
|
"ok": false,
|
|
922
964
|
"results": [
|
|
923
965
|
{
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import"./chunk-TMUK2DD3.js";import{readFile as x}from"node:fs/promises";import{dirname as m,join as u}from"node:path";import{fileURLToPath as C}from"node:url";var c=[{name:"sharp \xB7 libvips",licence:"Apache-2.0 \xB7 LGPL-3.0",does:"images",packages:["sharp"]},{name:"PDFium",licence:"BSD-3-Clause",does:"PDF pages",packages:[]},{name:"pdf-lib",licence:"MIT",does:"writing PDFs",packages:["pdf-lib"]},{name:"mammoth \xB7 docx",licence:"BSD-2-Clause \xB7 MIT",does:"Word documents",packages:["mammoth","docx"]},{name:"Ink \xB7 React",licence:"MIT",does:"this screen",packages:["ink","react"]}],g=[{name:"@hyzyla/pdfium",licence:"MIT"}],h=[{name:"xkcd colour survey",licence:"CC0-1.0"}];function l(n){let t=[];for(let e of n.split(`
|
|
4
|
+
`)){let i=/^((?:@[^/\s]+\/)?[^@\s]+)@\S+ — (.+)$/.exec(e);i&&t.push({name:i[1],licence:i[2].replace(/^\((.*)\)$/,"$1")})}return t}var d=n=>n.name.replace(/^@/,"");function p({bundled:n,extensions:t}){let e=new Set(c.flatMap(s=>s.packages)),i=[...n.filter(s=>!e.has(s.name)),...g,...h].sort((s,r)=>d(s).localeCompare(d(r)));return[{title:"App",credits:c.map(({packages:s,...r})=>r)},...t.length>0?[{title:"Extensions",credits:t}]:[],{title:"Others",credits:i}]}var f="third-party-licenses.txt";function y(n){let t=[],e=m(n);for(let i=0;i<4;i++)t.push(u(e,f),u(e,"dist",f)),e=m(e);return t}async function k(n){for(let t of y(C(n))){let e=await x(t,"utf8").catch(()=>{});if(e!==void 0)return{path:t,text:e}}}async function I({from:n=import.meta.url,list:t=async()=>(await import("./manager-XN7WNMEW.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-4OWNFLEI.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{I as loadCredits};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{r as l}from"./chunk-
|
|
3
|
+
import{r as l}from"./chunk-G4DU5ADF.js";import{e as a}from"./chunk-H2IUSPAK.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";var i={loadPreferences:a,loadShell:()=>import("./launch-OVBNYIQE.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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-
|
|
3
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-X54KIHCN.js";import"./chunk-H2IUSPAK.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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{E as s,F as a,G as m}from"./chunk-
|
|
3
|
+
import{E as s,F as a,G as m}from"./chunk-MMRDELHW.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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{j as t}from"./chunk-
|
|
3
|
+
import{j as t}from"./chunk-GGBNT4WI.js";import{resolve as s}from"node:path";function c(r,e){return{forge:r,ok:!0,palette:e,failures:[]}}function f(r,e){return{forge:r,ok:!0,scale:e,failures:[]}}function a(r){let e=t(r),n=e.sources.map(o=>s(o.path));return{op:r.job.op,source:n[0]??"",sources:n,outputs:e.outputs.map(o=>s(o)),inputBytes:e.sources.reduce((o,u)=>o+u.bytes,0),outputBytes:e.outputBytes,warnings:e.warnings.map(o=>({code:o.code,message:o.message}))}}function i(r){let{error:e}=r;return{...r.path?{path:s(r.path)}:{},code:e.code,title:e.title,detail:e.detail,...e.hint===void 0?{}:{hint:e.hint}}}function l(r,e){return{forge:r,ok:e.failures.length===0,results:e.results.map(a),failures:e.failures.map(i)}}function J(r,e){return l(r,{results:[],failures:[{error:e}]})}function m(r,e){return{forge:r,ok:!0,formats:e,failures:[]}}function b(r,e){return{forge:r,ok:e.failures.length===0,probes:e.probes,failures:e.failures.map(i)}}function x(r,e,n){return{forge:r,ok:!0,config:e,warnings:n.map(o=>({code:o.code,message:o.message})),failures:[]}}function d(r,e){return{forge:r,ok:!0,extensions:e.extensions,...e.changed?{changed:e.changed}:{},failures:[]}}export{c as a,f as b,l as c,J as d,m as e,b as f,x as g,d as h};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as t}from"./chunk-
|
|
3
|
+
import{b as t}from"./chunk-SAWVMQAD.js";import{spawnSync as n}from"node:child_process";var r=!1;function c(){r=!0}function p(){return r}function u(){let e=t(process.argv[1]);if(e===void 0)return;let o=n(process.execPath,[...process.execArgv,e],{stdio:"inherit"});process.exitCode=o.status??0}export{c as a,p as b,u as c};
|
|
@@ -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,q as ie,r as pe,s as ce,u as de,v as fe,x as I,z as y}from"./chunk-WFD6OWQY.js";import{a as $,c as U,d as Y,e as F,f as K,k as Q}from"./chunk-LW2QEXDT.js";import{c as X,d as Z,e as _,f as ee,g as te,h as re}from"./chunk-3GVFOZ7M.js";import{e as V}from"./chunk-GGBNT4WI.js";import{m as H,o as L}from"./chunk-GNLE6JXL.js";import{a as g}from"./chunk-G4DU5ADF.js";import{I as D,J as q,M as z,b as P,c as w,d as R,fa as G,g as x,s as A,u as k,w as W,z as C}from"./chunk-MMRDELHW.js";import{a as h,b as M}from"./chunk-J7FLFHQJ.js";import{readFile as Se}from"node:fs/promises";import{dirname as Re,resolve as je}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as ke}from"node:path";function $e(e,r=new Set){let t={path:ke(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===B.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-QN6QAGCU.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var S=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=P(Fe(e),S(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=M(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ge(s[0],r)}`,` ${s.map(u=>w(u)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let u of t.warnings)a.push("",`\u26A0 ${u.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],S(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,S(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function we(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>w(i)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)a.push("",`\u26A0 ${i.message}`);return a}function j(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function ve(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,S(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Be(e){return new Promise(r=>{let t=Pe({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function xe(e){if(e.stdin)return Be(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
|
|
4
|
+
`),t.close()}}function N(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Oe(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw D("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:pe(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Ce(e,r){let t;return()=>r?(t??=xe({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await V(await Se(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let n;try{n=B.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(u){if(!x(u))throw u;return{failure:{path:e.path,error:u}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function O(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=fe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Oe(e,r.sources))}catch(a){if(!x(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:A(u)});continue}let i=e.output!==void 0&&!oe(e.output)?je(e.output):void 0,c=e.output===void 0||i!==void 0?Re(u.path):Re(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-H2WS22BA.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-O3V24DK7.js"),d=f("boost"),v=d&&l(d)?.version,T=L(e.scale,n.version,v);if(T)return b(t,[{path:"",error:T}])}let a=await y(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?ne:ae,i=[],c=[];for(let l of a.sources){if(!u.appliesTo([l])){c.push({path:l.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}i.push(...u.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:O(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.crop!==void 0?"crop":e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ue(n,{trim:e.trim,...e.crop===void 0?{}:{crop:e.crop},...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:O(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function We(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,u=[],i=[],c=Ce(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let v=await Je(d,e,c,t.roots.get(d.path));"failure"in v?i.push(v.failure):u.push(v.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...i,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function De(e,r={}){try{return e.kind==="pageop"?await Ne(e):e.kind==="extension-op"?await Me(e,r):e.kind==="edit"?await Ae(e,r):e.kind==="compress"?await Te(e,r):await We(e,r)}catch(t){if(!x(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:j(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:j(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-TXQUYFA6.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function St(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-6VNVMAYO.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-UGXZIFRI.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=N(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...ve(u)]),stderr:j(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-D7L5VGQC.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:qe(await De(e,r),{json:t,debug:o})}catch(s){if(!x(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,N as b,De as c,qe as d,St as e};
|
|
@@ -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.3.
|
|
4
|
-
\u25BC`,dotFilled:"\u25CF",dotEmpty:"\u25CB"},o={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"},r={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 S(e,n){let t=[...a,"commands"];return t[(t.indexOf(e)+n+t.length)%t.length]}function x(e){return/^[1-9]$/.test(e)?a[Number(e)-1]:void 0}var P={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"],h={convert:["#138291","#8467bd"],compress:["#2b8748","#138291"],pdf:["#d54322","#a06c10"],enhance:["#8567bc","#7b67cd"],colour:["#cb4b49","#a06c10","#618110","#138291","#5869ec","#8268bd"]};function
|
|
3
|
+
var C="0.3.3",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"},o={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"},r={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 S(e,n){let t=[...a,"commands"];return t[(t.indexOf(e)+n+t.length)%t.length]}function x(e){return/^[1-9]$/.test(e)?a[Number(e)-1]:void 0}var P={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"],h={convert:["#138291","#8467bd"],compress:["#2b8748","#138291"],pdf:["#d54322","#a06c10"],enhance:["#8567bc","#7b67cd"],colour:["#cb4b49","#a06c10","#618110","#138291","#5869ec","#8268bd"]};function p(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 y(e,n){return e.name==="light"?h[n]:p(e,n)}function E(e){return{...e,accent:e.brand,tag:e.brand,label:e.brand}}function w(e,n){let{fg:t,bg:d}=l(e,n);return{...e,accent:t,tag:t,label:t,band:d===""?e.band:d}}function M(e){return e.canvas!==""}function O(e){return e==="dark"?o:e==="light"?r:f}function H(e){return e===""?void 0:e}var R={filled:"\u2501",empty:"\u2501",knob:"\u25CF"};function B(){return process.env.NO_COLOR!==void 0&&process.env.NO_COLOR!==""?!1:process.stdout.isTTY===!0}function D(){B()||(process.env.FORCE_COLOR="0")}export{C as a,T as b,o as c,r as d,f as e,a as f,v as g,S as h,x as i,P as j,l as k,p as l,k as m,y as n,E as o,w as p,M as q,O as r,H as s,R as t,B as u,D as v};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{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};
|
|
3
|
+
import{A as ne,B as se,F as T,G as ie,H as ae,M as ce,n as K,o as Q,q as X,t as j,u as b,v as w,w as ee,x as te,y as re,z as oe}from"./chunk-GNLE6JXL.js";import{d as m}from"./chunk-32VJ2RDH.js";import{J as R,K as N,M as V,Q as Y,Z,c as S,d as I,da as $,g as D,z as x}from"./chunk-MMRDELHW.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-XQYPVWFI.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.crop&&e.options.resize?"cropped and resized":e.options.crop?"cropped":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};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as q,c as lt}from"./chunk-32VJ2RDH.js";import{$ as dt,F as ht,I as O,N as ct,_ as ft,aa as pt,ba as ut,c as k,ca as mt,d as w,da as C,g as U,h as tt,i as et,j as H,k as rt,l as it,m as nt,n as ot,o as at,r as I,x as st,y as W}from"./chunk-MMRDELHW.js";import{randomBytes as Ht}from"node:crypto";import{constants as Wt}from"node:fs";import{access as qt,readFile as At,rm as Jt,stat as Vt,writeFile as Xt}from"node:fs/promises";import{basename as Zt,dirname as Gt,join as Kt}from"node:path";var Ot=[{w:1,h:1,label:"1:1"},{w:4,h:5,label:"4:5"},{w:16,h:9,label:"16:9"},{w:9,h:16,label:"9:16"}],pe=20,ue=10,E=t=>Math.max(1,Math.round(t)),N=(t,e,r)=>Math.min(Math.max(t,e),r);function A(t,e){let r=E(t.width*e.h/e.w),[i,n]=r<=t.height?[t.width,r]:[Math.min(t.width,E(t.height*e.w/e.h)),t.height];return{left:Math.floor((t.width-i)/2),top:Math.floor((t.height-n)/2),width:i,height:n}}var Tt=(t,e)=>e.width===t.width&&e.height===t.height;function me(t){return Ot.filter(e=>!Tt(t,A(t,e)))}function le(t,e,r,i){let n=A(t,e),o,a;return e.w>=e.h?(o=E(n.width*i/100),a=Math.min(t.height,E(o*e.h/e.w))):(a=E(n.height*i/100),o=Math.min(t.width,E(a*e.w/e.h))),{left:N(Math.round(r.x-o/2),0,t.width-o),top:N(Math.round(r.y-a/2),0,t.height-a),width:o,height:a}}function we(t,e,r,i){return{...e,left:N(e.left+r,0,t.width-e.width),top:N(e.top+i,0,t.height-e.height)}}function ge(t,e){return{x:e.width<t.width,y:e.height<t.height}}function ye(t){return{x:t.left+t.width/2,y:t.top+t.height/2}}function xe(t,e){return Math.round(e.width*e.height*100/(t.width*t.height))}var J=t=>`${t.w}:${t.h}`,be=t=>`cropped-${t.w}x${t.h}`;function Se(t){let e=/^(\d{1,3}):(\d{1,3})$/.exec(t.trim()),r=Number(e?.[1]),i=Number(e?.[2]);if(!e||r<1||r>100||i<1||i>100)throw O(`"${t}" is not a shape; it takes two whole numbers from 1 to 100, as W:H.`,"Try --crop 1:1 or --crop 16:9.");return{w:r,h:i}}function Ie(t,e,r){let i=r*2,n=new Uint8Array(e*i*3),o=t.alpha?new Uint8Array(e*i):void 0,a=t.width/e,f=t.height/i;for(let s=0;s<i;s++){let h=s*f,l=h+f;for(let p=0;p<e;p++){let d=p*a,u=d+a,x=0,m=0,g=0,c=0,y=0;for(let b=Math.floor(h);b<Math.min(Math.ceil(l),t.height);b++){let L=Math.min(b+1,l)-Math.max(b,h);for(let B=Math.floor(d);B<Math.min(Math.ceil(u),t.width);B++){let Q=b*t.width+B,Y=(Math.min(B+1,u)-Math.max(B,d))*L,R=Y*(t.alpha?(t.alpha[Q]??0)/255:1),j=Q*3;x+=(t.rgb[j]??0)*R,m+=(t.rgb[j+1]??0)*R,g+=(t.rgb[j+2]??0)*R,c+=R,y+=Y}}let F=s*e+p;c>0&&n.set([x/c,m/c,g/c].map(Math.round),F*3),o&&y>0&&(o[F]=Math.round(c*255/y))}}return{cols:e,dotRows:i,rgb:n,...o?{alpha:o}:{}}}function ve(t){if(w[t].hasAlpha)return;let e=Object.keys(w).filter(r=>w[r].hasAlpha&&r!=="heic").join(", ");return O(`${w[t].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${e}.`)}var wt="1.1.0";function Pt(t,e){let r=t.split(".").map(n=>Number.parseInt(n,10)||0),i=e.split(".").map(n=>Number.parseInt(n,10)||0);for(let n=0;n<Math.max(r.length,i.length);n++){let o=(r[n]??0)-(i[n]??0);if(o!==0)return o>0}return!0}function V(t){return t!==void 0&&Pt(t,wt)?[2,3,4]:[2,4]}function Be(t,e,r){if(t===1||V(e).some(n=>n===t))return;if(r!==void 0&&V(r).some(n=>n===t))return ct("boost",`boost ${t}\xD7`,e,wt);let i=V(e).map(n=>`--boost ${n}`);return O(`No released boost makes ${t}\xD7 yet.`,`Try ${i.slice(0,-1).join(", ")} or ${i.at(-1)}.`)}var zt=16384,Ft=1e8;function gt(t,e,r){let i=Math.max(t,e)*r;if(i>zt)return{side:i};let n=t*r*e*r;if(n>Ft)return{megapixels:Math.round(n/1e6)}}var v=t=>Math.max(1,Math.round(t));function X(t,e){return"percent"in e?{width:v(t.width*e.percent/100),height:v(t.height*e.percent/100)}:"width"in e?{width:v(e.width),height:v(t.height*e.width/t.width)}:{width:v(t.width*e.height/t.height),height:v(e.height)}}function yt(t){return gt(t.width,t.height,1)}import{execFile as kt}from"node:child_process";import{randomBytes as Ut}from"node:crypto";import{mkdtemp as Ct,open as xt,readFile as Nt,rm as Z}from"node:fs/promises";import{tmpdir as bt}from"node:os";import{join as _}from"node:path";import{promisify as Dt}from"node:util";function S(t){let e;return()=>(e??=t(),e)}var M=S(async()=>(await import("sharp")).default),ze=S(()=>import("./es-T2U7NBLD.js")),Fe=S(()=>import("@hyzyla/pdfium")),Re=S(async()=>(await import("./lib-TPEJ5CJJ.js")).default),ke=S(async()=>(await import("./word-OGQ2KZAJ.js")).default),Ue=S(async()=>(await import("./adm-zip-SQKLKBDP.js")).default),Ce=S(async()=>(await import("./cfb-V6M2PYOD.js")).default);async function Rt(){let t=Object.getOwnPropertyDescriptor(globalThis,"localStorage");if(!t?.configurable)return import("./dist-J2V6ITHG.js");Object.defineProperty(globalThis,"localStorage",{value:void 0,configurable:!0,enumerable:t.enumerable??!1,writable:!0});try{return await import("./dist-J2V6ITHG.js")}finally{Object.defineProperty(globalThis,"localStorage",t)}}var Ne=S(Rt);var G=Dt(kt),St=async()=>({...await import("./paths-H2WS22BA.js"),...await import("./run-XQYPVWFI.js")}),T;async function P(t=process.platform){if(t==="win32")return await(await St()).installed("heic")!==void 0;if(T!==void 0)return T;try{await G("/usr/bin/sips",["--help"],{timeout:5e3}),T=!0}catch{T=!1}return T}async function $(t,e=process.platform){if(e==="win32")return _t(t);let r=_(bt(),`forge-heic-${Ut(8).toString("hex")}.png`),i=async()=>{await Z(r,{force:!0}).catch(()=>{})};try{return await G("/usr/bin/sips",["-s","format","png",t,"--out",r],{timeout:12e4}),{path:r,cleanup:i}}catch(n){throw await i(),n}}async function It(t){let{installed:e,runExtension:r}=await St(),i=await e("heic");if(i===void 0)throw I(t,"win32");return{ext:i,runExtension:r}}async function _t(t){let e=await Ct(_(bt(),"forge-heic-")),r=async()=>{await Z(e,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:i,runExtension:n}=await It(t),o=_(e,"decoded.rgba"),a=_(e,"decoded.png"),{width:f,height:s}=await n(i,["--in",t,"--out",o],{subject:t});return await(await M())(await Nt(o),{raw:{width:f,height:s,channels:4}}).png().toFile(a),await Z(o,{force:!0}),{path:a,cleanup:r}}catch(i){throw await r(),i}}var $t=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),Lt=new Set(["avif","avis"]);async function Mt(t){let e;try{e=await xt(t,"r")}catch{return!1}try{let r=Buffer.alloc(64),{bytesRead:i}=await e.read(r,0,64,0);if(i<12||r.toString("latin1",4,8)!=="ftyp")return!1;let n=Math.min(r.readUInt32BE(0),i),o=[];for(let a=8;a+4<=n;a+=4)o.push(r.toString("latin1",a,a+4));return o.some(a=>Lt.has(a))?!1:o.some(a=>$t.has(a))}catch{return!1}finally{await e.close().catch(()=>{})}}async function Et(t,e=process.platform){if(e==="win32"){let{ext:a,runExtension:f}=await It(t),s=await f(a,["--info","--in",t],{subject:t});return{width:s.width,height:s.height,hasAlpha:s.hasAlpha??!0}}let{stdout:r}=await G("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",t],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(r)?.[1]??0),n=Number(/pixelHeight:\s*(\d+)/.exec(r)?.[1]??0),o=await jt(t);return{width:o?n:i,height:o?i:n,hasAlpha:/hasAlpha:\s*yes/i.test(r)}}function*D(t,e,r){let i=e;for(;i+8<=r;){let n=t.readUInt32BE(i),o=8;if(n===1&&i+16<=r?(n=Number(t.readBigUInt64BE(i+8)),o=16):n===0&&(n=r-i),n<o)return;yield{type:t.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+n,r)},i+=n}}async function jt(t){let e=await xt(t,"r");try{let r=Buffer.alloc(262144),{bytesRead:i}=await e.read(r,0,r.length,0),n=[...D(r,0,i)].find(c=>c.type==="meta");if(!n)return!1;let o=[...D(r,n.start+4,n.end)],a=o.find(c=>c.type==="pitm"),f=o.find(c=>c.type==="iprp");if(!a||!f)return!1;let s=r.readUInt8(a.start)===0?r.readUInt16BE(a.start+4):r.readUInt32BE(a.start+4),h=[...D(r,f.start,f.end)],l=h.find(c=>c.type==="ipco"),p=h.find(c=>c.type==="ipma");if(!l||!p)return!1;let d=new Map;if([...D(r,l.start,l.end)].forEach((c,y)=>{c.type==="irot"&&d.set(y+1,r.readUInt8(c.start)&3)}),d.size===0)return!1;let u=r.readUInt8(p.start),x=(r.readUInt8(p.start+3)&1)===1,m=p.start+4,g=r.readUInt32BE(m);m+=4;for(let c=0;c<g&&m<p.end;c++){let y=u<1?r.readUInt16BE(m):r.readUInt32BE(m);m+=u<1?2:4;let F=r.readUInt8(m);m+=1;for(let b=0;b<F;b++){let L=x?r.readUInt16BE(m)&32767:r.readUInt8(m)&127;if(m+=x?2:1,y===s&&(d.get(L)??0)%2===1)return!0}}return!1}catch{return!1}finally{await e.close().catch(()=>{})}}var Qt=new Set(["jpeg","png","webp","avif","heic","gif","tiff"]),Yt=new Set(["jpeg","png","webp","avif","gif","tiff"]),te={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function ee(t,e){if(e.format==="heif")return e.compression==="av1"?"avif":"heic";let r=te[e.format??""];if(!r)throw at(t,e.format??"an unknown format");return r}async function re(t){let e;try{e=await Vt(t)}catch(n){let o=n.code;throw o==="ENOENT"?tt(t):o==="EACCES"||o==="EPERM"?H(t):o==="ENOTDIR"?rt(t):o==="ELOOP"?it(t):o==="ENAMETOOLONG"?nt(t):ot(t,n)}if(!e.isFile())throw et(t);try{await qt(t,Wt.R_OK)}catch{throw H(t)}if(await Mt(t)){if(!await P())throw I(t);let n;try{n=await Et(t)}catch(o){throw W(t,"heic",o)}if(n.width===0||n.height===0)throw W(t,"heic",void 0);return{kind:"image",path:t,format:"heic",width:n.width,height:n.height,bytes:e.size,hasAlpha:n.hasAlpha,frames:1}}let r=await M(),i;try{i=await r(t).metadata()}catch(n){throw st(t,n)}return{kind:"image",path:t,format:ee(t,i),width:i.autoOrient?.width??i.width??0,height:i.autoOrient?.height??i.height??0,bytes:e.size,hasAlpha:i.hasAlpha??!1,frames:i.pages??1}}function K(t,e,r){let i=r??w[e].defaultQuality;switch(e){case"jpeg":return t.jpeg({quality:i,mozjpeg:!0});case"webp":return t.webp({quality:i});case"avif":return t.avif({quality:i});case"png":return t.png({compressionLevel:9});case"gif":return t.gif();case"tiff":return t.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 ie(t,e){let r=Gt(e);await q(e);let i=Kt(r,`.forge-tmp-${Ht(6).toString("hex")}-${Zt(e)}`);try{return await Xt(i,t),await lt(i,e),t.length}catch(n){throw await Jt(i,{force:!0}).catch(()=>{}),ht(e,n)}}async function z(t,e,r,i,n,o){if(t.kind!=="image")throw new Error("pipelineFor received a non-image source");if(n===void 0&&t.format==="heic"&&!await P())throw I(t.path);let a=n===void 0&&t.format==="heic"?await $(t.path):void 0,f=async()=>{await a?.cleanup()},h=(await M())(n??a?.path??t.path,i?{animated:!0}:{});if(h=h.rotate(),r.trim&&(h=h.trim()),r.crop){if(!r.crop.box)throw new Error("pipelineFor needs the crop placed (run does it)");h=h.extract(r.crop.box)}if(r.resize){if(!o&&(r.trim||r.crop))throw new Error("pipelineFor needs the resolved size to resize a cut image");let l=o??X(t,r.resize);h=h.resize(l.width,l.height,{fit:"fill"})}return t.hasAlpha&&!w[e].hasAlpha&&(h=h.flatten({background:r.background})),h=r.keepMetadata?h.keepMetadata():h.keepIccProfile(),{pipeline:h,cleanup:f}}async function ar(t,e){let r={background:"#ffffff",keepMetadata:!1},{pipeline:i,cleanup:n}=await z(t,"png",r,!1);try{await i.png({compressionLevel:1}).toFile(e)}finally{await n()}}async function sr(t,e,r){let{pipeline:i,cleanup:n}=await z(t,e,r,!1);try{return await K(i,e,r.quality).toBuffer()}finally{await n()}}async function ne(t){let e={width:t.width,height:t.height};if(t.frames>1)return{upright:e,trimmed:"animated"};if(t.format==="heic"&&!await P())throw I(t.path);let r=t.format==="heic"?await $(t.path):void 0;try{let i=await M(),{info:n}=await i(r?.path??t.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return n.width===e.width&&n.height===e.height?{upright:e,trimmed:"nothing"}:{upright:e,trimmed:{width:n.width,height:n.height}}}catch(i){throw U(i)?i:C(t.path,i)}finally{await r?.cleanup()}}var vt=1024;async function oe(t){let e={background:"#ffffff",keepMetadata:!1},{pipeline:r,cleanup:i}=await z(t,"png",e,!1);try{let{data:n,info:o}=await r.resize(vt,vt,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0}),a=o.width*o.height,f=o.channels,s=new Uint8Array(a*3),h=new Uint8Array(a),l=!1;for(let p=0;p<a;p++){for(let d=0;d<3;d++)s[p*3+d]=n[p*f+(f>=4?d:0)]??0;h[p]=n[p*f+f-1]??255,h[p]!==255&&(l=!0)}return{size:{width:t.width,height:t.height},thumb:{width:o.width,height:o.height,rgb:s,...l?{alpha:h}:{}}}}catch(n){throw U(n)?n:C(t.path,n)}finally{await i()}}var Bt=128;async function ae(t,e){let{thumb:r,size:i}=t,n=A(r,e),o=await M(),{info:a}=await o(se(r),{raw:{width:r.width,height:r.height,channels:3}}).resize(n.width,n.height,{fit:"cover",position:o.strategy.attention}).raw().toBuffer({resolveWithObject:!0}),f=A(i,e),s=Math.round(-(a.cropOffsetLeft??0)*i.width/r.width),h=Math.round(-(a.cropOffsetTop??0)*i.height/r.height);return{...f,left:Math.min(Math.max(s,0),i.width-f.width),top:Math.min(Math.max(h,0),i.height-f.height)}}function se(t){let{alpha:e}=t;if(!e)return t.rgb;let r=new Uint8Array(t.rgb.length);for(let i=0;i<r.length;i++){let n=(e[Math.floor(i/3)]??255)/255;r[i]=Math.round(Bt+((t.rgb[i]??0)-Bt)*n)}return r}async function he(t,e){if(t.op!=="convert")throw new Error(`image engine cannot ${t.op}`);let r=t.sources[0],i=t.outputs[0];if(r.kind!=="image")throw new Error("the image engine cannot convert a document source");let n=w[t.target],o=[];e({phase:"reading"});let a=r.frames>1,f=a&&n.animatable;a&&!n.animatable&&o.push({code:"animation-flattened",message:`${k(r.path)} has ${r.frames} frames, and ${n.label} cannot animate. Only the first frame was converted.`});let s=t.options,h;if(s.trim||s.crop||s.resize){let d={width:r.width,height:r.height};if(s.trim&&s.crop)throw new Error("a job cannot both trim and crop");if(s.crop){if(a)throw mt(r.path);let{aspect:u}=s.crop,x=c=>c.width===r.width&&c.height===r.height,m=A(d,u),g=s.crop.box??(x(m)?m:await ae(await oe(r),u));if(x(g)){if(!s.resize)throw ut(r.path,J(u));o.push({code:"nothing-cropped",message:`${k(r.path)} is already ${J(u)}; resized only.`});let{crop:c,...y}=s;s=y}else s={...s,crop:{aspect:u,box:g}},d={width:g.width,height:g.height}}if(s.trim){if(a)throw pt(r.path);let{trimmed:u}=await ne(r);if(u==="nothing"){if(!s.resize)throw dt(r.path);o.push({code:"nothing-trimmed",message:`${k(r.path)} has no empty edges; resized only.`})}else u!=="animated"&&(d=u)}if(s.resize&&(h=X(d,s.resize),yt(h)))throw ft(r.path,h)}e({phase:"decoding"});let{pipeline:l,cleanup:p}=await z(r,t.target,s,f,void 0,h);try{await q(i),e({phase:"encoding"});let d=await K(l,t.target,s.quality).toBuffer();e({phase:"writing"});let u=await ie(d,i);return{job:t,outputBytes:u,warnings:o}}catch(d){throw U(d)?d:C(r.path,d)}finally{await p()}}async function ce(t){if(t.format!=="heic")return At(t.path);if(!await P())throw I(t.path);let e=await $(t.path);try{return await At(e.path)}finally{await e.cleanup()}}async function fe(t){if(t.op!=="convert"||!w[t.target].lossy)return;let e=t.sources[0];if(e.kind!=="image")return;let r=await ce(e);return{ladder:[{}],measure:async i=>{let{pipeline:n}=await z(e,t.target,i,!1,r);return(await K(n,t.target,i.quality).toBuffer()).length}}}var hr={id:"image",reads:Qt,writes:Yt,ops:new Set(["convert"]),probe:re,run:he,measurer:fe};export{pe as a,ue as b,A as c,me as d,le as e,we as f,ge as g,ye as h,xe as i,be as j,Se as k,Ie as l,ve as m,V as n,Be as o,zt as p,gt as q,X as r,yt as s,S as t,M as u,ze as v,Fe as w,Re as x,ke as y,Ue as z,Ce as A,Ne as B,P as C,$ as D,Mt as E,K as F,ie as G,ar as H,sr as I,ne as J,oe as K,ae as L,hr as M};
|
|
@@ -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 E,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 x}from"node:child_process";import{homedir as l}from"node:os";import{join as p}from"node:path";var P={Desktop:"[Environment]::GetFolderPath('Desktop')",Downloads:"(Get-ItemProperty 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders').'{374DE290-123F-4565-9164-39C4925E467B}'"};function F(e){try{let n=x("powershell.exe",["-NoProfile","-NonInteractive","-Command",`[Console]::OutputEncoding=[Text.Encoding]::UTF8; ${P[e]}`],{encoding:"buffer",timeout:5e3,stdio:["ignore","pipe","ignore"]}).toString("utf8").trim();return n.length>0?n:void 0}catch{return}}var g=new Map;function d(e,t=process.platform,n=F){if(t!=="win32")return p(l(),e);let r=g.get(e);if(r!==void 0)return r;let o=n(e)?.replace(/%([^%]+)%/g,(k,O)=>process.env[O]??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,t=process.platform){if(t==="win32"){if(e==="~/Desktop")return d("Desktop",t);if(e==="~/Downloads")return d("Downloads",t)}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 t={...s},n=[];if(e.theme!==void 0&&(e.theme==="dark"||e.theme==="light"?t.theme=e.theme:n.push("theme")),e.defaultOutput!==void 0&&(typeof e.defaultOutput=="string"&&e.defaultOutput.trim().length>0?t.defaultOutput=e.defaultOutput:n.push("defaultOutput")),e.quality!==void 0){let r=e.quality;typeof r=="number"&&Number.isInteger(r)&&r>=1&&r<=100?t.quality=r:n.push("quality")}return e.updateCheck!==void 0&&(typeof e.updateCheck=="boolean"?t.updateCheck=e.updateCheck:n.push("updateCheck")),e.lastOutput!==void 0&&(typeof e.lastOutput=="string"&&e.lastOutput.trim().length>0?t.lastOutput=e.lastOutput:n.push("lastOutput")),{prefs:t,rejected:n}}async function j(){let e;try{e=await h(f(),"utf8")}catch{return}try{let t=JSON.parse(e);return y(t)?t:void 0}catch{return}}async function B(){let e=f(),t;try{t=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 n;try{n=JSON.parse(t)}catch{return{prefs:s,warning:`The config at ${e} is not valid JSON \u2014 using defaults.`}}if(!y(n))return{prefs:s,warning:`The config at ${e} is not an object \u2014 using defaults.`};let{prefs:r,rejected:i}=D(n);return i.length===0?{prefs:r}:{prefs:r,warning:`Ignored invalid config ${i.length===1?"setting":"settings"}: ${i.join(", ")}.`}}async function G(e){let t=f();await E(S(t),{recursive:!0});let r={...await j()??{}};for(let[o,u]of Object.entries(e))u!==void 0&&(r[o]=u);let i=`${t}.${process.pid}.tmp`;try{await N(i,`${JSON.stringify(r,null,2)}
|
|
4
|
+
`,"utf8"),await C(i,t)}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{I as n}from"./chunk-
|
|
3
|
+
import{I as n}from"./chunk-MMRDELHW.js";import{c as i,e as s,f as o}from"./chunk-H2IUSPAK.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};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as $,h as it,i as P}from"./chunk-MBTGANIR.js";import{b,c as R,d as j,f as v,g as H,h as V}from"./chunk-QVACE4IE.js";import{i as st}from"./chunk-GGBNT4WI.js";import{C as ot,D as at,u as rt}from"./chunk-GNLE6JXL.js";import{d as X,g as Z,p as tt,r as et,x as nt}from"./chunk-MMRDELHW.js";var bt=[[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 w(t){let{C:e,h:n}=v(R(t));return e<.03?"grey":D(n)}function D(t){let e=(t%360+360)%360;return(bt.find(([n])=>e<n)??[360,"rose"])[1]}var At=["full","mono","analogous","opposite","split","triad","pastel"],ct={full:"Full set",mono:"Monochromatic",analogous:"Analogous",opposite:"Complementary",split:"Split complementary",triad:"Triadic",pastel:"Pastel"},K={brightness:0,saturation:0,hue:0,contrast:0},Tt=t=>!!(t.brightness||t.saturation||t.hue||t.contrast),B=[{name:"red",hex:{r:251,g:44,b:54},role:"danger"},{name:"orange",hex:{r:255,g:105,b:0}},{name:"yellow",hex:{r:239,g:177,b:0},role:"warning"},{name:"green",hex:{r:0,g:201,b:80},role:"success"},{name:"teal",hex:{r:0,g:187,b:167}},{name:"blue",hex:{r:43,g:127,b:255},role:"info"},{name:"purple",hex:{r:173,g:70,b:255}},{name:"pink",hex:{r:246,g:51,b:154}}],$t={analogous:[-30,0,30],opposite:[0,180],split:[0,150,210],triad:[0,120,240]},wt=.553,yt=.024,x=t=>v(R(t)),C=(t,e,n)=>j(H({L:t,C:Math.max(0,e),h:(n+360)%360})),_=(t,e)=>(t-e+540)%360-180;function ht(t,e,n){let r=H({L:t,C:e,h:n}),a=R(j(r));return Math.hypot(a.L-r.L,a.a-r.a,a.b-r.b)<.003}function L(t,e){let n=0,r=.4;for(let a=0;a<30;a++){let o=(n+r)/2;ht(t,o,e)?n=o:r=o}return n}function G({L:t,C:e,h:n}){let r=L(t,n);return r>0?Math.min(1,e/r):0}var A=(t,e)=>e>=0?t+(.98-t)*(e/100):t+(t-.05)*(e/100),Y=(t,e,n)=>n>=0?t+(Math.max(t,e)-t)*(n/100):t*(1+n/100);function W(t,e){if(!(e.brightness||e.saturation||e.hue))return t;let{L:n,C:r,h:a}=x(t),o=A(n,e.brightness),i=(a+e.hue+360)%360,l=Y(r,L(o,i),e.saturation);for(let s=0;s<40&&l>0&&!ht(o,l,i);s++)l-=.005;return C(o,l,i)}function k(t,e,n,r){let a=A(t,r.brightness),o=(n+r.hue+360)%360,i=L(a,o);return C(a,Math.min(i,Y(e,i,r.saturation)),o)}function lt(t,e,n){if(!e)return t;let r=x(t[n].rgb).L;return t.map((a,o)=>{if(o===n)return a;let i=x(a.rgb),l=Math.max(.02,Math.min(.995,r+(i.L-r)*(1+e/100))),s=C(l,Math.min(i.C,L(l,i.h)),i.h);return{...a,rgb:s,hex:b(s)}})}function ut(t,e){let n=x(t),r=B.map(s=>x(s.hex)),a=0;r.forEach((s,c)=>{Math.abs(_(n.h,s.h))<Math.abs(_(n.h,r[a].h))&&(a=c)});let o=r[a],i=Math.max(-10,Math.min(10,_(n.h,o.h)/2)),l=G(n);return B.map((s,c)=>{if(c===a)return{name:s.name,role:s.role,rgb:W(t,e),yours:!0};let h=r[c],p=n.L>=o.L?h.L+(n.L-o.L)*(1-h.L)/(1-o.L):h.L*n.L/o.L,f=A(p,e.brightness),g=(h.h+i+e.hue+360)%360,d=L(f,g),u=Math.min(1,G(h)),S=Math.min(d,Y(l*u*d,d,e.saturation));return{name:s.name,role:s.role,rgb:C(f,S,g),yours:!1}})}function St(t,e,n){let r=x(t),a=w(t);if(e==="mono")return[{name:a,rgb:W(t,n),yours:!0},{name:`${a} soft`,rgb:k(r.L,r.C*.5,r.h,n),yours:!1},{name:`${a} dusty`,rgb:k(r.L,r.C*.22,r.h,n),yours:!1}];if(e==="pastel")return ut(t,K).map((l,s)=>{let c=x(l.rgb),h=c.C<.01?x(B[s].hex).h:c.h;return{...l,rgb:k(.86,Math.min(.1,L(.86,h))*.85,h,n)}});let o=G(r);return($t[e]??[0]).map(l=>{if(l===0)return{name:a,rgb:W(t,n),yours:!0};let s=(r.h+l+360)%360,c=o*L(r.L,s);return{name:o>0?D(s):w(k(r.L,c,s,K)),rgb:k(r.L,c,s,n),yours:!1}}).sort((l,s)=>Number(s.yours)-Number(l.yours))}function Lt(t,e,n){let r=x(t).h+e.hue,a=Math.max(0,yt*(1+e.saturation/100));return P(C(A(wt,e.brightness),a,r),n)}function Et(t,e,n=K,r=$){let a=it(r);return{rows:(e==="full"?ut(t,n):St(t,e,n)).map(({name:l,role:s,rgb:c,yours:h})=>({name:l,...s?{role:s}:{},steps:lt(P(c,r),n.contrast,a),yours:h})),neutral:lt(Lt(t,n,r),n.contrast,a)}}var M=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),T=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"colour",y='font-family="Inter"',E=t=>`${t[0]?.toUpperCase()??""}${t.slice(1)}`;function mt(t){let e=t==="dark";return{ink:e?"#FAFAFA":"#111111",grey:e?"#A1A1AA":"#71717A",edge:e?"#FFFFFF":"#000000",paper:e?"#18181B":"#FFFFFF"}}var Mt=`<defs><pattern id="checker" width="16" height="16" patternUnits="userSpaceOnUse"><rect width="16" height="16" fill="#FFFFFF"/><rect width="8" height="8" fill="#E5E5E5"/><rect x="8" y="8" width="8" height="8" fill="#E5E5E5"/></pattern></defs>
|
|
4
|
+
`;function O(t,e,n,r="light"){let{ink:a,grey:o,edge:i,paper:l}=mt(r),s=n.length>8?64:104,c=10,h=48+n.length*s+Math.max(0,n.length-1)*c,p=84+s+56,f=s>80?12:10,g=`<text id="title" x="24" y="38" ${y} font-size="15" font-weight="600" fill="${a}">${M(t)}</text><text id="subtitle" x="24" y="58" ${y} font-size="12" fill="${o}">${M(e)}</text>`,d=n.map((u,S)=>`<g id="${T(u.id)}" transform="translate(${24+S*(s+c)} 80)">`+(u.alpha===void 0?"":`<rect id="checker" width="${s}" height="${s}" rx="${f}" fill="url(#checker)"/>`)+`<rect id="swatch" width="${s}" height="${s}" rx="${f}" fill="${u.hex}"`+(u.alpha===void 0?"":` fill-opacity="${u.alpha.toFixed(3)}"`)+` stroke="${i}" stroke-opacity="0.08"/><text id="name" x="1" y="${s+22}" ${y} font-size="13" font-weight="600" fill="${a}">${M(u.name)}</text><text id="value" x="1" y="${s+40}" ${y} font-size="11" fill="${o}">${M(u.value)}</text></g>`).join(`
|
|
5
|
+
`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${h}" height="${p}" viewBox="0 0 ${h} ${p}">
|
|
6
|
+
`+(n.some(u=>u.alpha!==void 0)?Mt:"")+`<g id="${T(t)}">
|
|
7
|
+
<rect id="card" width="${h}" height="${p}" rx="0" fill="${l}"/>
|
|
8
|
+
${g}
|
|
9
|
+
${d}
|
|
10
|
+
</g>
|
|
11
|
+
</svg>`}function jt(t,e,n="light",r){let a=t.replace(/\.[^.]+$/,""),o=e.length;return O(t,r?`${o} shade${o===1?"":"s"} of ${r}`:`${o} colour${o===1?"":"s"}, most of the image first`,e.map((i,l)=>({id:`${a}-${l+1}`,name:i.hex,value:V(i.rgb),hex:i.hex})),n)}function I(t){if(t.set==="radix")return"Radix 1\u201312";if(t.set==="even")return`${t.start}\u2013${t.end}, ${t.count} even steps`;let e=$;return t.start===e.start&&t.end===e.end?"50\u2013950":`Tailwind ${t.start}\u2013${t.end}`}function Ht(t,e,n="light",r=$){let a=w(t);return O(E(a),`from ${b(t)} \xB7 ${I(r)} in OKLCH`,e.map(o=>({id:`${a}-${o.step}`,name:String(o.step),value:o.hex,hex:o.hex})),n)}function Pt(t,e,n,r=$,a="light"){let{ink:o,grey:i,edge:l,paper:s}=mt(a),c=`${E(w(t))} palette`,h=`from ${b(t)} \xB7 ${ct[n]} \xB7 ${I(r)} in OKLCH`,p=[...e.rows.map(m=>({name:m.name,steps:m.steps})),{name:"neutral",steps:e.neutral}],f=p[0]?.steps.map(m=>m.step)??[],g=44,d=6,u=g+10,S=92,N=24+Math.max(92,...p.map(m=>m.name.length*8+12)),gt=N+f.length*g+Math.max(0,f.length-1)*d+24,z=Math.max(gt,48+Math.ceil(h.length*6.5)),U=S+p.length*u+24+10,pt=`<text id="title" x="24" y="38" ${y} font-size="15" font-weight="600" fill="${o}">${M(c)}</text><text id="subtitle" x="24" y="58" ${y} font-size="12" fill="${i}">${M(h)}</text>`,ft=f.map((m,F)=>`<text id="step-${m}" x="${N+F*(g+d)+1}" y="${S-10}" ${y} font-size="11" font-weight="600" fill="${i}">${m}</text>`).join(""),dt=p.map((m,F)=>{let q=S+F*u+(F===p.length-1?10:0),J=T(m.name);return`<g id="${J}"><text id="name" x="24" y="${q+g/2+4}" ${y} font-size="13" font-weight="600" fill="${o}">${M(m.name)}</text>`+m.steps.map((Q,xt)=>`<g id="${J}-${Q.step}"><rect id="swatch" x="${N+xt*(g+d)}" y="${q}" width="${g}" height="${g}" rx="8" fill="${Q.hex}" stroke="${l}" stroke-opacity="0.08"/></g>`).join("")+"</g>"}).join(`
|
|
12
|
+
`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${z}" height="${U}" viewBox="0 0 ${z} ${U}">
|
|
13
|
+
<g id="${T(c)}">
|
|
14
|
+
<rect id="card" width="${z}" height="${U}" rx="0" fill="${s}"/>
|
|
15
|
+
${pt}
|
|
16
|
+
<g id="steps">${ft}</g>
|
|
17
|
+
${dt}
|
|
18
|
+
</g>
|
|
19
|
+
</svg>`}function Dt(t,e,n,r="light",a=$){return O(`${E(w(t))} neutral`,`from ${b(t)} \xB7 ${n} tint \xB7 ${I(a)} in OKLCH`,e.map(o=>({id:`neutral-${o.step}`,name:String(o.step),value:o.hex,hex:o.hex})),r)}function _t(t,e,n,r="light",a=$){let o=w(t);return O(`${E(o)} alpha`,`from ${b(t)} \xB7 over ${n} \xB7 ${I(a)}`,e.map(i=>({id:`${o}-alpha-${i.step}`,name:String(i.step),value:i.hex8,hex:b(i.rgb),alpha:i.a})),r)}async function Jt(t,e=192){let n=await st(t);if(n.kind!=="image")throw tt(t,`a ${X[n.format].label}`);let r=n.format==="heic";if(r&&!await ot())throw et(t);let a=r?await at(t):void 0;try{let i=(await rt())(a?.path??t,{animated:!1}),{data:l,info:s}=await(r?i:i.rotate()).resize(e,e,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0});return{source:n,pixels:{width:s.width,height:s.height,rgba:new Uint8Array(l.buffer,l.byteOffset,l.length)}}}catch(o){throw Z(o)?o:nt(t,o)}finally{await a?.cleanup()}}export{At as a,ct as b,K as c,Tt as d,Et as e,O as f,jt as g,Ht as h,Pt as i,Dt as j,_t as k,Jt as l};
|