forge-terminal 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -19
- package/dist/chunks/{about-credits-TJBWWNH6.js → about-credits-5UQU5WHE.js} +2 -2
- package/dist/chunks/args-QKAIL3E4.js +3 -0
- package/dist/chunks/{available-GYIHVSRX.js → available-M6Z62OWE.js} +1 -1
- package/dist/chunks/boot-MGR26CBU.js +3 -0
- package/dist/chunks/catalog-VPSTQTFD.js +3 -0
- package/dist/chunks/check-B6NP7BEM.js +3 -0
- package/dist/chunks/chunk-37P6QZ5Q.js +3 -0
- package/dist/chunks/chunk-3GJ7GV3V.js +19 -0
- package/dist/chunks/{chunk-EHARO6IS.js → chunk-57M4J2BR.js} +1 -1
- package/dist/chunks/chunk-63XCSYHM.js +3 -0
- package/dist/chunks/{chunk-JFJ3ZJQL.js → chunk-63ZK5SRQ.js} +1 -1
- package/dist/chunks/chunk-C4UCCBCX.js +3 -0
- package/dist/chunks/{chunk-DERIWZAT.js → chunk-CKZBBDAW.js} +1 -1
- package/dist/chunks/chunk-DZOBIUV6.js +3 -0
- package/dist/chunks/chunk-EKTUUKDP.js +80 -0
- package/dist/chunks/chunk-F34DPQFQ.js +63 -0
- package/dist/chunks/chunk-G46QQBT3.js +3 -0
- package/dist/chunks/chunk-GSK2A3TN.js +3 -0
- package/dist/chunks/chunk-H3DIRJFE.js +3 -0
- package/dist/chunks/chunk-HKINXTUW.js +3 -0
- package/dist/chunks/chunk-HOZ6XGQQ.js +6 -0
- package/dist/chunks/chunk-I6754KTB.js +36 -0
- package/dist/chunks/{chunk-YYB3TTGT.js → chunk-JMBEZPYC.js} +1 -1
- package/dist/chunks/chunk-K7KKCR7V.js +6 -0
- package/dist/chunks/chunk-KH5DHZ2U.js +8 -0
- package/dist/chunks/chunk-KXKQDFHX.js +3 -0
- package/dist/chunks/chunk-LVYQVJOF.js +3 -0
- package/dist/chunks/chunk-N6RCLJE6.js +4 -0
- package/dist/chunks/chunk-N72E43Z3.js +3 -0
- package/dist/chunks/chunk-NDECMPOM.js +3 -0
- package/dist/chunks/chunk-NXJGO66P.js +3 -0
- package/dist/chunks/chunk-OK7XOZFO.js +3 -0
- package/dist/chunks/chunk-P4RAYEM7.js +6 -0
- package/dist/chunks/{chunk-EX7KZBI6.js → chunk-PE5LAYGF.js} +1 -1
- package/dist/chunks/chunk-PPR7B5AR.js +3 -0
- package/dist/chunks/chunk-Q6KQWJ4J.js +3 -0
- package/dist/chunks/{chunk-GJ2GZHRI.js → chunk-RMD7F3QX.js} +1 -1
- package/dist/chunks/chunk-SK2UZ25Y.js +3 -0
- package/dist/chunks/chunk-SNDFMJIX.js +3 -0
- package/dist/chunks/{chunk-IGF6ZFTM.js → chunk-SZRSAL64.js} +1 -1
- package/dist/chunks/chunk-THDAQBQ3.js +3 -0
- package/dist/chunks/chunk-TL5MACSF.js +3 -0
- package/dist/chunks/chunk-V3I6DSF4.js +3 -0
- package/dist/chunks/{chunk-A6RK5ALT.js → chunk-W6SY5PPG.js} +2 -2
- package/dist/chunks/chunk-WC6SJN5Y.js +3 -0
- package/dist/chunks/chunk-WE6KP4FR.js +3 -0
- package/dist/chunks/chunk-WIPP5TWQ.js +3 -0
- package/dist/chunks/{chunk-GKECNCKO.js → chunk-XBOMWF34.js} +1 -1
- package/dist/chunks/chunk-XRI5XKEB.js +66 -0
- package/dist/chunks/chunk-Y7LOIHFU.js +3 -0
- package/dist/chunks/chunk-YINYF6C7.js +3 -0
- package/dist/chunks/chunk-ZRHYGR2L.js +134 -0
- package/dist/chunks/chunk-ZZZAPVKM.js +3 -0
- package/dist/chunks/clip-command-R2NKW4TI.js +3 -0
- package/dist/chunks/clipboard-GICOXMMN.js +3 -0
- package/dist/chunks/colour-APVBMEJQ.js +3 -0
- package/dist/chunks/command-GYCYLUHN.js +3 -0
- package/dist/chunks/config-command-6YUMMZF3.js +3 -0
- package/dist/chunks/continue-editing-QE5RRIMG.js +3 -0
- package/dist/chunks/decoded-UNCEUPNW.js +3 -0
- package/dist/chunks/entry-TSLQHDP7.js +6 -0
- package/dist/chunks/execute-S5WN34PS.js +3 -0
- package/dist/chunks/extensions-XI5R74TS.js +3 -0
- package/dist/chunks/{extensions-command-ABJSGDPK.js → extensions-command-25JOL47P.js} +1 -1
- package/dist/chunks/ffmpeg-3CJ6C37W.js +3 -0
- package/dist/chunks/image-QSTDWHJ4.js +3 -0
- package/dist/chunks/install-IDUHZTTS.js +3 -0
- package/dist/chunks/{install-V62EEK54.js → install-L5C2UT6M.js} +1 -1
- package/dist/chunks/install-size-PZUFEDGI.js +3 -0
- package/dist/chunks/launch-LFFWVTFE.js +17 -0
- package/dist/chunks/libs-EK64ACG3.js +3 -0
- package/dist/chunks/lock-PTQUMNYX.js +3 -0
- package/dist/chunks/manager-CQ6NNQY4.js +4 -0
- package/dist/chunks/needed-MYXIUZI4.js +3 -0
- package/dist/chunks/own-WNA6BFYL.js +3 -0
- package/dist/chunks/{paths-5XI5L4KW.js → paths-EOYKOUBC.js} +1 -1
- package/dist/chunks/pdfium-WFGSET5S.js +3 -0
- package/dist/chunks/preferences-3P4V2EDX.js +3 -0
- package/dist/chunks/preset-command-HMOFTZSG.js +3 -0
- package/dist/chunks/registry-4IOXO6DT.js +3 -0
- package/dist/chunks/{reveal-L6TBFOMV.js → reveal-D5FCZYOA.js} +1 -1
- package/dist/chunks/run-HGZVOXRW.js +5 -0
- package/dist/chunks/{server-TUWDAECT.js → server-KKF3XBQG.js} +8 -8
- package/dist/chunks/text-layer-LHZNDMPZ.js +3 -0
- package/dist/chunks/{theme-7IVYHKTP.js → theme-NAWQ77WF.js} +1 -1
- package/dist/chunks/transcribe-Q5NLWSSR.js +3 -0
- package/dist/chunks/transcribe-command-2L7F7MCG.js +3 -0
- package/dist/chunks/{update-command-GMBG7BK6.js → update-command-JCTCRPCS.js} +1 -1
- package/dist/chunks/update-note-FRMHMUMD.js +3 -0
- package/dist/chunks/watch-command-XCCMIQIM.js +3 -0
- package/dist/fonts/NotoSans-Bold.ttf.gz +0 -0
- package/dist/fonts/NotoSans-Regular.ttf.gz +0 -0
- package/dist/fonts/OFL.txt +93 -0
- package/dist/helpers/forge-transcribe +0 -0
- package/dist/helpers/forge-transcribe-whisper.mjs +525 -0
- package/dist/index.js +8 -8
- package/dist/third-party-licenses.txt +98 -0
- package/package.json +43 -12
- package/dist/chunks/args-MGXWV4UD.js +0 -3
- package/dist/chunks/boot-AE6XH7Z3.js +0 -3
- package/dist/chunks/catalog-YSMT3PXT.js +0 -3
- package/dist/chunks/check-KAR72Y4X.js +0 -3
- package/dist/chunks/chunk-3UEQ2OX6.js +0 -3
- package/dist/chunks/chunk-5B5XXH22.js +0 -3
- package/dist/chunks/chunk-5IS7O673.js +0 -6
- package/dist/chunks/chunk-6FUVEO3A.js +0 -78
- package/dist/chunks/chunk-6L6C3GJU.js +0 -3
- package/dist/chunks/chunk-7S5DBC3J.js +0 -66
- package/dist/chunks/chunk-AAXBN572.js +0 -4
- package/dist/chunks/chunk-BZXDNDPG.js +0 -3
- package/dist/chunks/chunk-CEULBUUM.js +0 -63
- package/dist/chunks/chunk-DOWMSJ6R.js +0 -3
- package/dist/chunks/chunk-EXLXSKRH.js +0 -3
- package/dist/chunks/chunk-FH3R2YYD.js +0 -19
- package/dist/chunks/chunk-FWIXOYXE.js +0 -3
- package/dist/chunks/chunk-I63TO22X.js +0 -3
- package/dist/chunks/chunk-IWFVEMDN.js +0 -3
- package/dist/chunks/chunk-JSMGNA55.js +0 -3
- package/dist/chunks/chunk-KAHWYWNT.js +0 -3
- package/dist/chunks/chunk-LDKF7KIZ.js +0 -6
- package/dist/chunks/chunk-LNB5D67B.js +0 -3
- package/dist/chunks/chunk-M66BUNYO.js +0 -3
- package/dist/chunks/chunk-PSEIJXGT.js +0 -3
- package/dist/chunks/chunk-QR6QHTC3.js +0 -3
- package/dist/chunks/chunk-QXTXBMTM.js +0 -3
- package/dist/chunks/chunk-SMBK6BTC.js +0 -3
- package/dist/chunks/chunk-TDW6KQH6.js +0 -3
- package/dist/chunks/chunk-TMQDQLY7.js +0 -21
- package/dist/chunks/chunk-XSOCV3F2.js +0 -3
- package/dist/chunks/chunk-YWKMG5WO.js +0 -3
- package/dist/chunks/clip-command-D3DE2WUR.js +0 -3
- package/dist/chunks/clipboard-CPHPA4FH.js +0 -3
- package/dist/chunks/colour-U6QBTJTQ.js +0 -3
- package/dist/chunks/command-I5M275ZV.js +0 -3
- package/dist/chunks/config-command-TYNYVUMP.js +0 -3
- package/dist/chunks/entry-4GMHXHST.js +0 -6
- package/dist/chunks/execute-D4H7QWGR.js +0 -3
- package/dist/chunks/extensions-DOTV7SIR.js +0 -3
- package/dist/chunks/ffmpeg-PF3VLTHK.js +0 -3
- package/dist/chunks/image-J4FT4ACZ.js +0 -3
- package/dist/chunks/install-2A5BGKQU.js +0 -3
- package/dist/chunks/launch-XVWOLOXM.js +0 -15
- package/dist/chunks/lock-KN7CF4YN.js +0 -3
- package/dist/chunks/manager-TVGSLNBE.js +0 -4
- package/dist/chunks/preferences-4VETUGMN.js +0 -3
- package/dist/chunks/preset-command-HORY7KZQ.js +0 -3
- package/dist/chunks/run-6BK4REXK.js +0 -4
- package/dist/chunks/transcribe-command-YUSBCQEQ.js +0 -3
- package/dist/chunks/update-note-A7C2OJKU.js +0 -3
- package/dist/chunks/watch-command-NOMNFJ75.js +0 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{r as E}from"./chunk-DZOBIUV6.js";import{ba as O}from"./chunk-WIPP5TWQ.js";import{execFile as F,spawn as W}from"node:child_process";import{createHash as v}from"node:crypto";import{mkdir as k,mkdtemp as P,open as D,readFile as J,rename as A,rm as w,writeFile as $}from"node:fs/promises";import{tmpdir as h}from"node:os";import{join as m}from"node:path";import{promisify as B}from"node:util";var H=B(F),U=async(t,e)=>{let{stdout:c}=await H("osascript",["-l","JavaScript","-e",t,...e],{timeout:5e3});return c.trim()},S={darwin:{images:[{type:"public.png",ext:"png",format:"png"},{type:"public.jpeg",ext:"jpg",format:"jpeg"},{type:"org.webmproject.webp",ext:"webp",format:"webp"},{type:"public.heic",ext:"heic",format:"heic"},{type:"public.avif",ext:"avif",format:"avif"},{type:"com.compuserve.gif",ext:"gif",format:"gif"},{type:"public.tiff",ext:"tiff",format:"tiff"}],file:"public.file-url",standIn:"public.tiff",text:["public.utf8-plain-text"]},win32:{images:[{type:"PNG",ext:"png",format:"png"},{type:"image/png",ext:"png",format:"png"},{type:"JFIF",ext:"jpg",format:"jpeg"},{type:"image/jpeg",ext:"jpg",format:"jpeg"},{type:"image/webp",ext:"webp",format:"webp"},{type:"image/heic",ext:"heic",format:"heic"},{type:"image/avif",ext:"avif",format:"avif"},{type:"GIF",ext:"gif",format:"gif"},{type:"image/gif",ext:"gif",format:"gif"},{type:"Bitmap",ext:"png",format:"png"}],file:"FileDrop",standIn:"Bitmap",text:["UnicodeText","Text"]},linux:{images:[{type:"image/png",ext:"png",format:"png"},{type:"image/jpeg",ext:"jpg",format:"jpeg"},{type:"image/webp",ext:"webp",format:"webp"},{type:"image/heic",ext:"heic",format:"heic"},{type:"image/avif",ext:"avif",format:"avif"},{type:"image/gif",ext:"gif",format:"gif"},{type:"image/tiff",ext:"tiff",format:"tiff"}],file:"text/uri-list",standIn:null,text:["text/plain;charset=utf-8","UTF8_STRING","text/plain","STRING","TEXT"]}};function _(t,e){let c=t.includes(e.file);return e.images.find(i=>t.includes(i.type)&&!(c&&i.type===e.standIn))}function T(t,e){return e.text.some(c=>t.includes(c))}function bt(t=process.platform,e=process.env){return e.SSH_CONNECTION||e.SSH_TTY?!1:t==="linux"?j(e).length>0:t==="darwin"||t==="win32"}var M=Object.fromEntries(S.darwin.images.map(t=>[t.format,t.type]));function Y(t){return M[t]??"public.data"}var I={changeCount:-1,image:null,text:!1};function y(t,e){return v("sha256").update(t.join(`
|
|
4
|
+
`)).update("\0").update(e).digest().readUIntBE(0,6)}function x(t){return v("sha256").update(t).digest("hex")}async function L(t,e){let{default:c}=await import("sharp"),i=m(e,"Copied image.png");return await c(t).keepIccProfile().png().toFile(`${i}.part`),await A(`${i}.part`,i),await w(t,{force:!0}),i}var X=`ObjC.import('AppKit')
|
|
5
|
+
const pb = $.NSPasteboard.generalPasteboard
|
|
6
|
+
JSON.stringify({ types: ObjC.deepUnwrap(pb.types) || [], count: Number(pb.changeCount) })`,K=`function run(argv) {
|
|
7
|
+
ObjC.import('AppKit')
|
|
8
|
+
const pb = $.NSPasteboard.generalPasteboard
|
|
9
|
+
const data = pb.dataForType(argv[0])
|
|
10
|
+
if (data.isNil()) return JSON.stringify({ ok: false })
|
|
11
|
+
const ok = data.writeToFileAtomically(argv[1], true)
|
|
12
|
+
return JSON.stringify({ ok: ok, count: Number(pb.changeCount) })
|
|
13
|
+
}`,q=`function run(argv) {
|
|
14
|
+
ObjC.import('AppKit')
|
|
15
|
+
const pb = $.NSPasteboard.generalPasteboard
|
|
16
|
+
const item = $.NSPasteboardItem.alloc.init
|
|
17
|
+
item.setDataForType($.NSData.dataWithContentsOfFile(argv[0]), argv[1])
|
|
18
|
+
item.setStringForType($.NSURL.fileURLWithPath(argv[0]).absoluteString, 'public.file-url')
|
|
19
|
+
pb.clearContents
|
|
20
|
+
pb.writeObjects($.NSArray.arrayWithObject(item))
|
|
21
|
+
return JSON.stringify({ count: Number(pb.changeCount) })
|
|
22
|
+
}`,z=`function run(argv) {
|
|
23
|
+
ObjC.import('AppKit')
|
|
24
|
+
const pb = $.NSPasteboard.generalPasteboard
|
|
25
|
+
const read = (p) => $.NSString.stringWithContentsOfFileEncodingError(p, $.NSUTF8StringEncoding, null)
|
|
26
|
+
const item = $.NSPasteboardItem.alloc.init
|
|
27
|
+
item.setStringForType(read(argv[0]), 'public.utf8-plain-text')
|
|
28
|
+
item.setStringForType(read(argv[1]), 'public.html')
|
|
29
|
+
pb.clearContents
|
|
30
|
+
pb.writeObjects($.NSArray.arrayWithObject(item))
|
|
31
|
+
return JSON.stringify({ count: Number(pb.changeCount) })
|
|
32
|
+
}`;function Q(t=U){let e=S.darwin,c=async()=>{try{let{types:i,count:p}=JSON.parse(await t(X,[]));return{changeCount:p,image:_(i,e)?.type??null,text:T(i,e)}}catch{return I}};return{peek:c,async read(i){let{image:p}=await c(),n=e.images.find(g=>g.type===p);if(!n)return null;await k(i,{recursive:!0});let r=m(i,`Copied image.${n.ext}`),a=JSON.parse(await t(K,[n.type,r]));return!a.ok||a.count===void 0?null:n.format!=="tiff"?{path:r,changeCount:a.count}:{path:await L(r,i),changeCount:a.count}},async write(i,p){let{count:n}=JSON.parse(await t(q,[i,Y(p)]));return n},async writeText(i,p){let n=await P(m(h(),"forge-text-"));try{let r=m(n,"text.txt"),a=m(n,"text.html");await $(r,i,"utf8"),await $(a,p,"utf8");let{count:g}=JSON.parse(await t(z,[r,a]));return g}finally{await w(n,{recursive:!0,force:!0})}}}}function R(t,e,c){return new Promise((i,p)=>{F(t,e,{...c,encoding:"buffer"},(n,r)=>n?p(n):i(r))})}var V=async(t,e)=>(await R("powershell.exe",["-NoProfile","-NonInteractive","-STA","-EncodedCommand",Buffer.from(t,"utf16le").toString("base64")],{env:{...process.env,...e},timeout:15e3,windowsHide:!0})).toString("utf8").trim(),Z=`$ErrorActionPreference = 'Stop'
|
|
33
|
+
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
34
|
+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
35
|
+
$data = [Windows.Forms.Clipboard]::GetDataObject()
|
|
36
|
+
$types = @()
|
|
37
|
+
if ($null -ne $data) { $types = @($data.GetFormats()) }
|
|
38
|
+
$file = $types -contains $env:FORGE_CLIP_FILE
|
|
39
|
+
$pick = $null
|
|
40
|
+
foreach ($t in $env:FORGE_CLIP_ORDER.Split('|')) {
|
|
41
|
+
if (($types -contains $t) -and -not ($file -and $t -eq $env:FORGE_CLIP_STAND_IN)) { $pick = $t; break }
|
|
42
|
+
}
|
|
43
|
+
$digest = ''
|
|
44
|
+
if ($null -ne $pick) {
|
|
45
|
+
$bytes = $null
|
|
46
|
+
if ($pick -eq 'Bitmap') {
|
|
47
|
+
$image = [Windows.Forms.Clipboard]::GetImage()
|
|
48
|
+
if ($null -ne $image) {
|
|
49
|
+
$stream = New-Object IO.MemoryStream
|
|
50
|
+
$image.Save($stream, [Drawing.Imaging.ImageFormat]::Png)
|
|
51
|
+
$bytes = $stream.ToArray()
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
$value = $data.GetData($pick)
|
|
55
|
+
if ($value -is [IO.MemoryStream]) { $bytes = $value.ToArray() }
|
|
56
|
+
elseif ($value -is [byte[]]) { $bytes = $value }
|
|
57
|
+
}
|
|
58
|
+
if ($null -eq $bytes -or $bytes.Length -eq 0) { $pick = $null }
|
|
59
|
+
else {
|
|
60
|
+
$digest = [BitConverter]::ToString([Security.Cryptography.SHA256]::Create().ComputeHash($bytes)).Replace('-', '')
|
|
61
|
+
if ($env:FORGE_CLIP_PATH) { [IO.File]::WriteAllBytes($env:FORGE_CLIP_PATH, $bytes) }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
ConvertTo-Json -Compress @{ types = $types; image = $pick; digest = $digest }`,tt=`$ErrorActionPreference = 'Stop'
|
|
65
|
+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
66
|
+
$path = $env:FORGE_CLIP_PATH
|
|
67
|
+
$bytes = [IO.File]::ReadAllBytes($path)
|
|
68
|
+
$data = New-Object Windows.Forms.DataObject
|
|
69
|
+
foreach ($t in $env:FORGE_CLIP_TYPES.Split('|')) {
|
|
70
|
+
$data.SetData($t, $false, (New-Object IO.MemoryStream(, $bytes)))
|
|
71
|
+
}
|
|
72
|
+
try { $data.SetImage([Drawing.Image]::FromStream((New-Object IO.MemoryStream(, $bytes)))) } catch {}
|
|
73
|
+
$files = New-Object Collections.Specialized.StringCollection
|
|
74
|
+
[void]$files.Add($path)
|
|
75
|
+
$data.SetFileDropList($files)
|
|
76
|
+
[Windows.Forms.Clipboard]::SetDataObject($data, $true)`,et=`$ErrorActionPreference = 'Stop'
|
|
77
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
78
|
+
$text = [IO.File]::ReadAllText($env:FORGE_CLIP_TEXT, [Text.Encoding]::UTF8)
|
|
79
|
+
[Windows.Forms.Clipboard]::SetText($text)`;function nt(t){return Array.isArray(t)?t.map(String):typeof t=="string"?[t]:[]}function rt(t=V){let e=S.win32,c={FORGE_CLIP_ORDER:e.images.map(n=>n.type).join("|"),FORGE_CLIP_FILE:e.file,FORGE_CLIP_STAND_IN:e.standIn??""},i=async n=>{let r=JSON.parse(await t(Z,{...c,...n===void 0?{}:{FORGE_CLIP_PATH:n}})),a=nt(r.types),g=typeof r.image=="string"&&r.image!==""?r.image:null;return{types:a,image:g,digest:typeof r.digest=="string"?r.digest:""}},p=async()=>{try{let n=await i();return{changeCount:y(n.types,n.digest),image:n.image,text:T(n.types,e)}}catch{return I}};return{peek:p,async read(n){await k(n,{recursive:!0});let r=m(n,".Copied image.part"),a=await i(r),g=e.images.find(s=>s.type===a.image);if(!g)return await w(r,{force:!0}),null;let u=m(n,`Copied image.${g.ext}`);return await A(r,u),{path:u,changeCount:y(a.types,a.digest)}},async write(n,r){let a=e.images.filter(g=>g.format===r&&g.type!==e.standIn);return await t(tt,{FORGE_CLIP_PATH:n,FORGE_CLIP_TYPES:(a.length>0?a.map(g=>g.type):[`image/${r}`]).join("|")}),(await p()).changeCount},async writeText(n){let r=await P(m(h(),"forge-text-"));try{let a=m(r,"text.txt");return await $(a,n,"utf8"),await t(et,{FORGE_CLIP_TEXT:a}),(await p()).changeCount}finally{await w(r,{recursive:!0,force:!0})}}}}var it={run(t,e){return R(t,e,{maxBuffer:512*1024*1024,timeout:5e3})},async copy(t,e,c){let i=await D(c,"r");try{await new Promise((p,n)=>{let r=W(t,e,{stdio:[i.fd,"ignore","ignore"],detached:!0});r.on("error",n),r.on("exit",a=>a===0?p():n(new Error(`${t} exited with ${a}`)))})}finally{await i.close()}}},at={name:"wayland",tool:"wl-clipboard",types:["wl-paste",["--list-types"]],read:t=>["wl-paste",["--type",t]],write:t=>["wl-copy",["--type",t]]},ot={name:"x11",tool:"xclip",types:["xclip",["-selection","clipboard","-t","TARGETS","-o"]],read:t=>["xclip",["-selection","clipboard","-t",t,"-o"]],write:t=>["xclip",["-selection","clipboard","-t",t,"-i"]]};function j(t=process.env){return[...t.WAYLAND_DISPLAY?[at]:[],...t.DISPLAY?[ot]:[]]}var st=40,ct=50;function C(t){return t?.code==="ENOENT"}function pt(t=process.env,e=it){let c=S.linux,i=j(t),p,n=async u=>{if(p)return u(p);for(let s of i)try{let o=await u(s);return p=s,o}catch(o){if(!C(o))throw p=s,o}throw O(i[0]?.tool??"xclip")},r=async u=>{try{return(await e.run(...u.types)).toString("utf8").split(`
|
|
80
|
+
`).map(o=>o.trim()).filter(o=>o!=="")}catch(s){if(C(s))throw s;return[]}},a=u=>n(async s=>{let o=await r(s),l=_(o,c),f=l&&u?await e.run(...s.read(l.type)):void 0;return{types:o,image:l,bytes:f}}),g=async()=>{try{let{types:u,image:s,bytes:o}=await a(!0);return{changeCount:y(u,o?x(o):""),image:s?.type??null,text:T(u,c)}}catch{return I}};return{peek:g,async read(u){let{types:s,image:o,bytes:l}=await a(!0);if(!o||!l||l.length===0)return null;let f=m(u,`Copied image.${o.ext}`);await E(f,l);let d=y(s,x(l));return o.format!=="tiff"?{path:f,changeCount:d}:{path:await L(f,u),changeCount:d}},async write(u,s){let o=c.images.find(d=>d.format===s)?.type??`image/${s}`;await n(d=>e.copy(...d.write(o),u));let l=x(await J(u)),f=-1;for(let d=0;d<st;d++){let b=await a(!0).catch(()=>null),N=b?.bytes?x(b.bytes):"";if(b&&(f=y(b.types,N)),N===l)return f;await new Promise(G=>setTimeout(G,ct))}return f},async writeText(u){let s=await P(m(h(),"forge-text-"));try{let o=m(s,"text.txt");return await $(o,u,"utf8"),await n(l=>e.copy(...l.write(l.name==="x11"?"UTF8_STRING":"text/plain;charset=utf-8"),o)),(await g()).changeCount}finally{await w(s,{recursive:!0,force:!0})}}}}function xt(t=process.platform,e=process.env){return t==="win32"?rt():t==="linux"?pt(e):Q()}export{bt as a,j as b,xt as c};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as M}from"./chunk-U5TEGDGH.js";import{a as X,b as Q}from"./chunk-HZDYZ5RD.js";import{a as D}from"./chunk-JMBEZPYC.js";import{b as W}from"./chunk-Y7LOIHFU.js";import{a as K}from"./chunk-XBOMWF34.js";import{b as J}from"./chunk-EEQSUBBL.js";import{a as Y}from"./chunk-KH5DHZ2U.js";import{a as U}from"./chunk-SNDFMJIX.js";import{m as R}from"./chunk-THDAQBQ3.js";import{H as d,K as H}from"./chunk-WIPP5TWQ.js";import{d as L}from"./chunk-J7FLFHQJ.js";import{b as z}from"./chunk-H3DIRJFE.js";var x=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},v=class extends x{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var E=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new v(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function N(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as le}from"node:events";import G from"node:child_process";import C from"node:path";import F from"node:fs";import m from"node:process";import{stripVTControlCharacters as he}from"node:util";import{stripVTControlCharacters as se}from"node:util";var T=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,o)=>i.name().localeCompare(o.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),o=n.long&&e._findOption(n.long);!i&&!o?t.push(n):n.long&&!o?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(o=>!o.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>N(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[])}),t.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[]),i.get(r).push(o)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function o(c,p){return t.formatItem(c,n,p,t)}let r=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(r=r.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let l=t.visibleArguments(e).map(c=>o(t.styleArgumentTerm(t.argumentTerm(c)),t.styleArgumentDescription(t.argumentDescription(c))));if(r=r.concat(this.formatItemList("Arguments:",l,t)),this.groupItems(e.options,t.visibleOptions(e),c=>c.helpGroupHeading??"Options:").forEach((c,p)=>{let O=c.map(_=>o(t.styleOptionTerm(t.optionTerm(_)),t.styleOptionDescription(t.optionDescription(_))));r=r.concat(this.formatItemList(p,O,t))}),t.showGlobalOptions){let c=t.visibleGlobalOptions(e).map(p=>o(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));r=r.concat(this.formatItemList("Global Options:",c,t))}return this.groupItems(e.commands,t.visibleCommands(e),c=>c.helpGroup()||"Commands:").forEach((c,p)=>{let O=c.map(_=>o(t.styleSubcommandTerm(t.subcommandTerm(_)),t.styleSubcommandDescription(t.subcommandDescription(_))));r=r.concat(this.formatItemList(p,O,t))}),r.join(`
|
|
4
|
+
`)}displayWidth(e){return se(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let r=" ".repeat(2);if(!n)return r+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),l=2,a=(this.helpWidth??80)-t-l-2,c;return a<this.minWidthToWrap||i.preformatted(n)?c=n:c=i.boxWrap(n,a).replace(/\n/g,`
|
|
5
|
+
`+" ".repeat(t+l)),r+u+" ".repeat(l)+c.replace(/\n/g,`
|
|
6
|
+
${r}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,o=[];return n.forEach(r=>{let u=r.match(i);if(u===null){o.push("");return}let l=[u.shift()],h=this.displayWidth(l[0]);u.forEach(a=>{let c=this.displayWidth(a);if(h+c<=t){l.push(a),h+=c;return}o.push(l.join(""));let p=a.trimStart();l=[p],h=this.displayWidth(p)}),o.push(l.join(""))}),o.join(`
|
|
7
|
+
`)}};var A=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=ae(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new v(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?Z(this.name().replace(/^no-/,"")):Z(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},V=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let i=this.negativeOptions.get(n).presetArg,o=i!==void 0?i:!1;return t.negate===(o===e)}};function Z(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function ae(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,o=s.split(/[ |,]+/).concat("guard");if(n.test(o[0])&&(e=o.shift()),i.test(o[0])&&(t=o.shift()),!e&&n.test(o[0])&&(e=o.shift()),!e&&i.test(o[0])&&(e=t,t=o.shift()),o[0].startsWith("-")){let r=o[0],u=`option creation failed due to '${r}' in option flags '${s}'`;throw/^-[^-][^-]/.test(r)?new Error(`${u}
|
|
8
|
+
- a short flag is a single dash and a single character
|
|
9
|
+
- either use a single dash and a single character (for a short flag)
|
|
10
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(r)?new Error(`${u}
|
|
11
|
+
- too many short flags`):i.test(r)?new Error(`${u}
|
|
12
|
+
- too many long flags`):new Error(`${u}
|
|
13
|
+
- unrecognised flag format`)}if(e===void 0&&t===void 0)throw new Error(`option creation failed due to no flags found in '${s}'.`);return{shortFlag:e,longFlag:t}}function ue(s,e){if(Math.abs(s.length-e.length)>3)return Math.max(s.length,e.length);let t=[];for(let n=0;n<=s.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=s.length;i++){let o;s[i-1]===e[n-1]?o=0:o=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+o),i>1&&n>1&&s[i-1]===e[n-2]&&s[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[s.length][e.length]}function q(s,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=s.startsWith("--");t&&(s=s.slice(2),e=e.map(r=>r.slice(2)));let n=[],i=3,o=.4;return e.forEach(r=>{if(r.length<=1)return;let u=ue(s,r),l=Math.max(s.length,r.length);(l-u)/l>o&&(u<i?(i=u,n=[r]):u===i&&n.push(r))}),n.sort((r,u)=>r.localeCompare(u)),t&&(n=n.map(r=>`--${r}`)),n.length>1?`
|
|
14
|
+
(Did you mean one of ${n.join(", ")}?)`:n.length===1?`
|
|
15
|
+
(Did you mean ${n[0]}?)`:""}var $=class s extends le{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>m.stdout.write(t),writeErr:t=>m.stderr.write(t),outputError:(t,n)=>n(t),getOutHelpWidth:()=>m.stdout.isTTY?m.stdout.columns:void 0,getErrHelpWidth:()=>m.stderr.isTTY?m.stderr.columns:void 0,getOutHasColors:()=>te()??(m.stdout.isTTY&&m.stdout.hasColors?.()),getErrHasColors:()=>te()??(m.stderr.isTTY&&m.stderr.hasColors?.()),stripColor:t=>he(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,o=n;typeof i=="object"&&i!==null&&(o=i,i=null),o=o||{};let[,r,u]=e.match(/([^ ]+) *(.*)/),l=this.createCommand(r);return i&&(l.description(i),l._executableHandler=!0),o.isDefault&&(this._defaultCommandName=l._name),l._hidden=!!(o.noHelp||o.hidden),l._executableFile=o.executableFile||null,u&&l.arguments(u),this._registerCommand(l),l.parent=this,l.copyInheritedSettings(this),i?this:l}createCommand(e){return new s(e)}createHelp(){return Object.assign(new T,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
16
|
+
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new E(e,t)}argument(e,t,n,i){let o=this.createArgument(e,t);return typeof n=="function"?o.default(i).argParser(n):o.default(n),this.addArgument(o),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let n=e??"help [command]",[,i,o]=n.match(/([^ ]+) *(.*)/),r=t??"display help for command",u=this.createCommand(i);return u.helpOption(!1),o&&u.arguments(o),r&&u.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=u,(e||t)&&this._initCommandGroup(u),this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
|
|
17
|
+
Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new x(e,t,n)),m.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,o=n.slice(0,i);return this._storeOptionsAsProperties?o[i]=this:o[i]=this.opts(),o.push(this),e.apply(this,o)};return this._actionHandler=t,this}createOption(e,t){return new A(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(o){if(o.code==="commander.invalidArgument"){let r=`${i} ${o.message}`;this.error(r,{exitCode:o.exitCode,code:o.code})}throw o}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
|
|
18
|
+
- already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=i=>[i.name()].concat(i.aliases()),n=t(e).find(i=>this._findCommand(i));if(n){let i=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");let i=(o,r,u)=>{o==null&&e.presetArg!==void 0&&(o=e.presetArg);let l=this.getOptionValue(n);o!==null&&e.parseArg?o=this._callParseArg(e,o,l,r):o!==null&&e.variadic&&(o=e._collectValue(o,l)),o==null&&(e.negate?o=!1:e.isBoolean()||e.optional?o=!0:o=""),this.setOptionValueWithSource(n,o,u)};return this.on("option:"+t,o=>{let r=`error: option '${e.flags}' argument '${o}' is invalid.`;i(o,r,"cli")}),e.envVar&&this.on("optionEnv:"+t,o=>{let r=`error: option '${e.flags}' value '${o}' from env '${e.envVar}' is invalid.`;i(o,r,"env")}),this}_optionEx(e,t,n,i,o){if(typeof t=="object"&&t instanceof A)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let r=this.createOption(t,n);if(r.makeOptionMandatory(!!e.mandatory),typeof i=="function")r.default(o).argParser(i);else if(i instanceof RegExp){let u=i;i=(l,h)=>{let a=u.exec(l);return a?a[0]:h},r.default(o).argParser(i)}else r.default(i);return this.addOption(r)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){m.versions?.electron&&(t.from="electron");let i=m.execArgv??[];(i.includes("-e")||i.includes("--eval")||i.includes("-p")||i.includes("--print"))&&(t.from="eval")}e===void 0&&(e=m.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":m.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;case"eval":n=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,"--");this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,"default")}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
19
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(F.existsSync(e))return;let i=t?`searched for local subcommand relative to directory '${t}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",o=`'${e}' does not exist
|
|
20
|
+
- if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
21
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
22
|
+
- ${i}`;throw new Error(o)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(a,c){let p=C.resolve(a,c);if(F.existsSync(p))return p;if(n.includes(C.extname(c)))return;let O=n.find(_=>F.existsSync(`${p}${_}`));if(O)return`${p}${O}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=e._executableFile||`${this._name}-${e._name}`,r=this._executableDir||"";if(this._scriptPath){let a;try{a=F.realpathSync(this._scriptPath)}catch{a=this._scriptPath}r=C.resolve(C.dirname(a),r)}if(r){let a=i(r,o);if(!a&&!e._executableFile&&this._scriptPath){let c=C.basename(this._scriptPath,C.extname(this._scriptPath));c!==this._name&&(a=i(r,`${c}-${e._name}`))}o=a||o}let u=n.includes(C.extname(o)),l;m.platform!=="win32"?u?(t.unshift(o),t=ee(m.execArgv).concat(t),l=G.spawn(m.argv[0],t,{stdio:"inherit"})):l=G.spawn(o,t,{stdio:"inherit"}):(this._checkForMissingExecutable(o,r,e._name),t.unshift(o),t=ee(m.execArgv).concat(t),l=G.spawn(m.execPath,t,{stdio:"inherit"})),l.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{m.on(c,()=>{l.killed===!1&&l.exitCode===null&&l.kill(c)})});let h=this._exitCallback;l.on("close",a=>{a=a??1,h?h(new x(a,"commander.executeSubCommandAsync","(close)")):m.exit(a)}),l.on("error",a=>{if(a.code==="ENOENT")this._checkForMissingExecutable(o,r,e._name);else if(a.code==="EACCES")throw new Error(`'${o}' not executable`);if(!h)m.exit(1);else{let c=new x(1,"commander.executeSubCommandAsync","(error)");c.nestedError=a,h(c)}}),this.runningCommand=l}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let o;return o=this._chainOrCallSubCommandHook(o,i,"preSubcommand"),o=this._chainOrCall(o,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),o}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(n,i,o)=>{let r=i;if(i!==null&&n.parseArg){let u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;r=this._callParseArg(n,i,o,u)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let o=n.defaultValue;n.variadic?i<this.args.length?(o=this.args.slice(i),n.parseArg&&(o=o.reduce((r,u)=>e(n,u,r),n.defaultValue))):o===void 0&&(o=[]):i<this.args.length&&(o=this.args[i],n.parseArg&&(o=e(n,o,n.defaultValue))),t[i]=o}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,i=[];return this._getCommandAndAncestors().reverse().filter(o=>o._lifeCycleHooks[t]!==void 0).forEach(o=>{o._lifeCycleHooks[t].forEach(r=>{i.push({hookedCommand:o,callback:r})})}),t==="postAction"&&i.reverse(),i.forEach(o=>{n=this._chainOrCall(n,()=>o.callback(o.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(o=>{i=this._chainOrCall(i,()=>o(this,t))}),i}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},o=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let r;return r=this._chainOrCallHooks(r,"preAction"),r=this._chainOrCall(r,()=>this._actionHandler(this.processedArgs)),this.parent&&(r=this._chainOrCall(r,()=>{this.parent.emit(o,e,t)})),r=this._chainOrCallHooks(r,"postAction"),r}if(this.parent?.listenerCount(o))i(),this._processArguments(),this.parent.emit(o,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(n=>{let i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{let i=e.find(o=>n.conflictsWith.includes(o.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function o(a){return a.length>1&&a[0]==="-"}let r=a=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(a)?!this._getCommandAndAncestors().some(c=>c.options.map(p=>p.short).some(p=>/^-\d$/.test(p))):!1,u=null,l=null,h=0;for(;h<e.length||l;){let a=l??e[h++];if(l=null,a==="--"){i===n&&i.push(a),i.push(...e.slice(h));break}if(u&&(!o(a)||r(a))){this.emit(`option:${u.name()}`,a);continue}if(u=null,o(a)){let c=this._findOption(a);if(c){if(c.required){let p=e[h++];p===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,p)}else if(c.optional){let p=null;h<e.length&&(!o(e[h])||r(e[h]))&&(p=e[h++]),this.emit(`option:${c.name()}`,p)}else this.emit(`option:${c.name()}`);u=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),l=`-${a.slice(2)}`);continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),p=this._findOption(a.slice(0,c));if(p&&(p.required||p.optional)){this.emit(`option:${p.name()}`,a.slice(c+1));continue}}if(i===t&&o(a)&&!(this.commands.length===0&&r(a))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(a)){t.push(a),n.push(...e.slice(h));break}else if(this._getHelpCommand()&&a===this._getHelpCommand().name()){t.push(a,...e.slice(h));break}else if(this._defaultCommandName){n.push(a,...e.slice(h));break}}if(this._passThroughOptions){i.push(a,...e.slice(h));break}i.push(a)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
|
|
23
|
+
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
24
|
+
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
25
|
+
`),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in m.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,m.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new V(this.options),t=n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=r=>{let u=r.attributeName(),l=this.getOptionValue(u),h=this.options.find(c=>c.negate&&u===c.attributeName()),a=this.options.find(c=>!c.negate&&u===c.attributeName());return h&&(h.presetArg===void 0&&l===!1||h.presetArg!==void 0&&l===h.presetArg)?h:a||r},i=r=>{let u=n(r),l=u.attributeName();return this.getOptionValueSource(l)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},o=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],o=this;do{let r=o.createHelp().visibleOptions(o).filter(u=>u.long).map(u=>u.long);i=i.concat(r),o=o.parent}while(o&&!o._enablePositionalOptions);t=q(e,i)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",i=e.length,o=this.parent?` for '${this.name()}'`:"",r=e.join(", "),u=`error: too many arguments${o}. Expected ${t} argument${n} but got ${i}: ${r}.`;this.error(u,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(o=>{i.push(o.name()),o.alias()&&i.push(o.alias())}),t=q(e,i)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
|
|
26
|
+
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(n=>N(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=C.basename(e,C.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let i=t.formatHelp(this,t);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(e){e=e||{};let t=!!e.error,n,i,o;return t?(n=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),o=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),o=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),hasColors:i,helpWidth:o}}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let n=this._getOutputContext(e),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(r=>r.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let o=this.helpInformation({error:n.error});if(t&&(o=t(o),typeof o!="string"&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(o),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(r=>r.emit("afterAllHelp",i))}helpOption(e,t){return typeof e=="boolean"?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(m.exitCode??0);t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
|
|
27
|
+
Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,o=>{let r;typeof t=="function"?r=t({error:o.error,command:o.command}):r=t,r&&o.write(`${r}
|
|
28
|
+
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function ee(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?i=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],i=o[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function te(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return!1;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return!0}var Ze=new $;function ce(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!D.includes(t))throw d(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${D.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw d(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw d(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var de={jpg:"jpeg",tif:"tiff",heif:"heic"};function I(s){let e=s.toLowerCase().replace(/^\./,""),t=z(de[e]??e);if(!t)throw d(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function P(s,e,t,n,i){let o=Number(String(e).replace(/k$/i,""));if(!Number.isFinite(o)||o<t||o>n)throw d(`${s} takes ${t} to ${n}, not ${e}.`,`For example ${s} ${i}.`);return o}function pe(s){let e={};if(s.cut!==void 0){let t=J(String(s.cut));if(!t)throw d(`--cut takes a start and an end, the end after the start, not ${s.cut}.`,"For example --cut 0:03.2-0:41, or --cut 0:10- to keep from 0:10 to the end.");e.cut=t.end===void 0?{start:t.start}:{start:t.start,end:t.end}}return s.mute&&(e.mute=!0),s.speed!==void 0&&(e.speed=P("--speed",s.speed,.25,4,"2")),s.fps!==void 0&&(e.fps=P("--fps",s.fps,1,120,"30")),s.bitrate!==void 0&&(e.bitrate=Math.round(P("--bitrate",s.bitrate,32,320,"128k"))),s.loudness!==void 0&&(e.loudness=P("--loudness",s.loudness,-70,-5,"-16")),s.cleanAudio&&(e.cleanup=!0,e.loudness??=-16),Object.keys(e).length?e:void 0}function S(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw d(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function ne(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw d(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function fe(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=W))throw d(`--resize takes a percent from 1 to ${W}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function j(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw d(`Concurrency must be a positive whole number, not ${s}.`);return e}var me=`
|
|
29
|
+
Exit codes:
|
|
30
|
+
0 every input succeeded
|
|
31
|
+
1 the command was understood, and at least one input failed or was refused
|
|
32
|
+
2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,ie=`
|
|
33
|
+
Other commands:
|
|
34
|
+
forge probe <files...> what each file is and what Forge can do with it
|
|
35
|
+
forge palette <image> an image's main colours (--json, --svg, --inside <hex>)
|
|
36
|
+
forge scale <colour> 50\u2013950 from one colour, with it at 500 (--json, --svg)
|
|
37
|
+
forge clip compress the copied image and put it back (--to, --quality,
|
|
38
|
+
--max-size, --save [folder], --undo)
|
|
39
|
+
forge transcribe <file | link>
|
|
40
|
+
a video or audio file, or a YouTube link, into notes
|
|
41
|
+
(--to all | notes | transcript, --detail brief | standard | detailed,
|
|
42
|
+
--format md | docx | pdf | txt, --language <id>, -o <path>, --force)
|
|
43
|
+
forge watch <folder> --to <format>
|
|
44
|
+
convert the folder, then every file added to it, until ctrl-c
|
|
45
|
+
(--quality, --dpi, -o <folder>, --new-only, --json)
|
|
46
|
+
forge config [list | path | set <setting> <value>]
|
|
47
|
+
forge extensions [add | remove <id>] optional extras, such as boost and remove-background
|
|
48
|
+
forge update install a newer Forge, if there is one
|
|
49
|
+
forge uninstall take Forge out of the right-click menu, then remove it
|
|
50
|
+
forge mcp run as a local MCP server over stdio, for AI agents`;function ge(s=process.platform){if(s==="darwin")return ie;let e=s==="win32"?"boost and whisper":"whisper and heic";return ie.replace("a video or audio file, or a YouTube link, into notes","a video or audio file, or a YouTube link, into a transcript").replace("optional extras, such as boost and remove-background",`optional extras, such as ${e}`)}function B(s){let e=L(String(s));if(e===void 0)throw d(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function be(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw d(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw d("No files given.","Name a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function _e(s){let e={kind:"clip",undo:!1,debug:!1},t=s.slice(1),n=(i,o)=>{let r=t[o+1];if(r===void 0||r.startsWith("-"))throw d(`${i} needs a value.`);return r};for(let i=0;i<t.length;i++){let o=t[i];if(o!=="--json")if(o==="--debug")e.debug=!0;else if(o==="--undo")e.undo=!0;else if(o==="--to"||o==="-t")e.target=I(n(o,i++));else if(o==="--quality"||o==="-q")e.quality=S(n(o,i++));else if(o==="--max-size")e.maxBytes=B(n(o,i++));else if(o==="--save"){let r=t[i+1];e.save=r===void 0||r.startsWith("-")?!0:t[++i]}else throw o.startsWith("-")?d(`forge clip does not take ${o}.`,"Try: forge --help"):d(`forge clip takes no files: it reads the clipboard, not ${o}.`,`To compress a file, try: forge ${o} --quality 80`)}if(e.undo&&Object.keys(e).some(i=>!["kind","undo","debug"].includes(i)))throw d("--undo takes no other flag.","Try: forge clip --undo");if(e.quality!==void 0&&e.maxBytes!==void 0)throw d("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");return e}function we(s){let e=s.slice(1),t=[],n={kind:"transcribe",input:"",notes:!0,transcript:!0,detail:Q,force:!1,debug:!1},i=(l,h)=>{let a=e[h+1];if(a===void 0||a.startsWith("-"))throw d(`${l} needs a value.`);return a},o="Try: forge transcribe talk.mp4";for(let l=0;l<e.length;l++){let h=e[l];if(h==="--debug")n.debug=!0;else if(h==="--force"||h==="-f")n.force=!0;else if(h==="--language"||h==="-l")n.language=i(h,l++);else if(h==="--output"||h==="-o")n.output=i(h,l++);else if(h==="--detail"){let a=i(h,l++).toLowerCase();if(!X.includes(a))throw d(`forge transcribe writes notes in brief, standard or detailed, not ${a}.`,"Try: forge transcribe talk.mp4 --detail brief");n.detail=a}else if(h==="--format"){let a=i(h,l++).toLowerCase(),c=Y.find(p=>p.id===a||p.label.toLowerCase()===a);if(c===void 0)throw d(`forge transcribe writes md, docx, pdf or txt, not ${a}.`,"Try: forge transcribe talk.mp4 --format pdf");n.format=c.id}else if(h==="--to"||h==="-t"){let a=i(h,l++).toLowerCase();if(a!=="all"&&a!=="notes"&&a!=="transcript")throw d(`forge transcribe makes all, notes or a transcript, not ${a}.`,"Try: forge transcribe talk.mp4 --to transcript");n.to=a,n.notes=a!=="transcript",n.transcript=a!=="notes"}else{if(h.startsWith("-"))throw d(`forge transcribe does not take ${h}.`,o);t.push(h)}}let[r,...u]=t;if(r===void 0)throw d("forge transcribe needs a file or a link.",o);if(u.length>0)throw d("forge transcribe takes one file or link at a time.",o);return{...n,input:r}}function ye(s){let e=s.slice(1),t=[],n,i={kind:"watch",newOnly:!1,debug:!1},o={},r=(h,a)=>{let c=e[a+1];if(c===void 0||c.startsWith("-"))throw d(`${h} needs a value.`);return c};for(let h=0;h<e.length;h++){let a=e[h];if(a!=="--json")if(a==="--debug")i.debug=!0;else if(a==="--new-only")i.newOnly=!0;else if(a==="--to"||a==="-t")n=I(r(a,h++));else if(a==="--quality"||a==="-q")o.quality=S(r(a,h++));else if(a==="--output"||a==="-o")o.output=r(a,h++);else if(a==="--dpi"){let c=r(a,h++),p=Number(c);if(!Number.isInteger(p)||p<36||p>600)throw H(c);o.dpi=p}else{if(a.startsWith("-"))throw d(`forge watch does not take ${a}.`,"Try: forge watch ./images --to webp");t.push(a)}}let[u,...l]=t;if(u===void 0)throw d("forge watch needs a folder.","Try: forge watch ./images --to webp");if(l.length>0)throw d("forge watch watches one folder at a time.",`Try: forge watch ${u} --to webp`);if(n===void 0)throw d("forge watch needs a format to convert to.",`Try: forge watch ${u} --to webp`);return{kind:"watch",folder:u,target:n,...o.quality===void 0?{}:{quality:o.quality},...o.dpi===void 0?{}:{dpi:o.dpi},...o.output===void 0?{}:{output:o.output},newOnly:i.newOnly,debug:i.debug}}function Oe(s){let e=s.slice(1).filter(r=>r!=="--json"),t=e.find(r=>r.startsWith("-"));if(t!==void 0)throw d(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...o]=e;if(n===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw d(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||o.length>0)throw d(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function oe(s){if(s===void 0)throw d("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=M(s)?.rgb;if(!e)throw d(`${s} is not a colour.`,"Try a hex code (6579FD), rgb(), hsl(), oklch() or a colour name, quoted: 'rgb(101 121 253)'.");return e}function xe(s,e=process.platform,t=process.env){let o=e==="linux"&&!t.WAYLAND_DISPLAY&&!!t.DISPLAY?" --svg a card of swatches; pipe to xclip -sel c, paste into Figma":` --svg a card of swatches; pipe to ${e==="win32"?"clip":e==="linux"?"wl-copy":"pbcopy"} and paste into Figma`;return s==="scale"?`Usage: forge scale <colour> [--json] [--svg]
|
|
51
|
+
|
|
52
|
+
50\u2013950 built in OKLCH, with <colour> at 500. Pass the hex without #, or quote it.
|
|
53
|
+
--json one JSON document: scale.steps[] with hex, oklch, white, black
|
|
54
|
+
${o}
|
|
55
|
+
`:`Usage: forge palette <image> [--json] [--svg] [--inside <hex>]
|
|
56
|
+
|
|
57
|
+
An image's main colours, most of the image first.
|
|
58
|
+
--json one JSON document: palette.colours[] with hex, rgb, oklch, share
|
|
59
|
+
${o}
|
|
60
|
+
--inside <hex> the shades of the palette colour nearest <hex>
|
|
61
|
+
`}function Ce(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write(xe(e==="scale"?"scale":"palette")),new x(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(l=>l!=="--json"&&l!=="--svg"),i=t.includes("--svg"),o=n.indexOf("--inside"),r=o===-1?void 0:n[o+1];o!==-1&&n.splice(o,2);let u=n.find(l=>l.startsWith("-"));if(u!==void 0)throw d(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(o!==-1)throw d("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw d("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:oe(n[0]),svg:i}}if(n.length!==1)throw d(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...o===-1?{}:{inside:oe(r)}}}function ft(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function ke(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],o;for(let r=0;r<t.length;r++){let u=t[r],l=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&l===void 0){i.push(u);continue}let h=l;if(h===void 0&&/^\d+$/.test(t[r+1]??"")&&(h=t[++r]),h!==void 0&&h!=="2"&&h!=="3"&&h!=="4")throw d(`--boost takes 2, 3 or 4, not ${h}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");o=h==="4"?4:h==="3"?3:2}return{rest:[...i,...n],...o===void 0?{}:{scale:o}}}function mt(s){let e=s;if(e[0]==="clip"||e[0]==="watch"||e[0]==="transcribe"||e[0]==="config"||e[0]==="probe"||e[0]==="extensions"||e[0]==="palette"||e[0]==="scale"||e[0]==="update"||e[0]==="uninstall")return ve(e);let t=ke(e);return Ae(t.rest,t.scale)}function ve(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw d(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}if(s[0]==="uninstall"){let e=s.slice(1);if(e.length>0)throw d(`forge uninstall takes nothing else, got: ${e.join(" ")}.`,"Try: forge uninstall");return{kind:"uninstall"}}return s[0]==="clip"?_e(s):s[0]==="watch"?ye(s):s[0]==="transcribe"?we(s):s[0]==="config"?ce(s.filter(e=>e!=="--json")):s[0]==="probe"?be(s):s[0]==="palette"||s[0]==="scale"?Ce(s):Oe(s)}function Ae(s,e){let t=new $().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--cut <start-end>","video or audio: keep from start to end, e.g. 0:03.2-0:41").option("--mute","video: take the sound out").option("--speed <x>","video or audio: play faster or slower, 0.25-4").option("--fps <n>","video: frames per second").option("--bitrate <kbps>","audio: bitrate, e.g. 128k").option("--loudness <LUFS>","audio: even out loudness to this level, e.g. -16").option("--clean-audio","video or audio: take out rumble and hiss, then even the level").option("--preset <name>","run a preset saved from Done, e.g. --preset blog").option("--pages <ranges>","with --to, which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(K,"-V, --version","show the version").addHelpText("after",`${ge()}
|
|
62
|
+
${me}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof x&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[g="",...b]=f.message.replace(/^error: /,"").split(`
|
|
63
|
+
`),w=b.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${g.charAt(0).toUpperCase()}${g.slice(1).replace(/\.$/,"")}.`,w||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.formats)return{kind:"formats"};let o=pe(n);if(o!==void 0&&n.trim)throw d("--trim cuts the empty edges of an image.","To keep part of a video or audio file, use --cut, for example --cut 0:03-0:41.");if(n.preset!==void 0){let f=[["to","--to"],["quality","--quality"],["maxSize","--max-size"],["merge","--merge"],["split","--split"],["extract","--extract"],["delete","--delete"],["rotate","--rotate"],["sharpen","--sharpen"],["trim","--trim"],["crop","--crop"],["resize","--resize"],["width","--width"],["height","--height"],["removeBg","--remove-bg"],["pages","--pages"]].filter(([g])=>n[g]!==void 0&&n[g]!==!1).map(([,g])=>g);if(e!==void 0&&f.push("--boost"),f.length>0)throw d(`--preset already says what to do \u2014 leave out ${f.join(" and ")}.`,"Run the preset alone, or change it from Done with \u2192 continue editing.");return{kind:"preset",inputs:i,name:String(n.preset),...n.output===void 0?{}:{output:String(n.output)},force:n.force===!0,recursive:n.recursive===!0,debug:n.debug===!0}}if(n.pages!==void 0&&n.to===void 0)throw d("--pages needs --to: it chooses which pages to render.");let r=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(r.length>1)throw d(`Use one operation at a time \u2014 got ${r.map(f=>`--${f}`).join(" and ")}.`);let u=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],l=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]],h=o!==void 0&&!n.to&&n.quality===void 0&&n.maxSize===void 0;if(n.trim||n.crop!==void 0||l.length>0||h){if(l.length>1)throw d(`Use one of --resize, --width and --height \u2014 got ${l.join(" and ")}.`);let f=n.crop!==void 0?"--crop":l[0]??(n.trim?"--trim":"--cut"),g=[...n.crop!==void 0&&n.trim?["--trim"]:[],...u,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...r.map(re=>`--${re}`)][0];if(g!==void 0)throw d(`${f} cannot be combined with ${g}.`,g!=="--max-size"?"Run them one after the other.":f==="--crop"?"Crop first, then compress the result: forge photo-cropped-1x1.jpg --max-size 500kb":"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb");let b=n.crop!==void 0?{aspect:R(String(n.crop))}:void 0,w=n.resize!==void 0?{percent:fe(n.resize)}:n.width!==void 0?{width:ne("--width",n.width)}:n.height!==void 0?{height:ne("--height",n.height)}:void 0;if(i.length===0)throw d("No files given.","Name an image, for example: forge photo.jpg --resize 50%");let k={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(k.quality=S(String(n.quality)));let y={kind:"edit",inputs:i,trim:!!n.trim,options:k,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return b!==void 0&&(y.crop=b),w!==void 0&&(y.resize=w),o!==void 0&&(y.media=o),n.to&&(y.target=I(String(n.to))),n.output!==void 0&&(y.output=String(n.output)),n.concurrency!==void 0&&(y.concurrency=j(String(n.concurrency))),y}let a=n.sharpen?1:e,c=a!==void 0?"boost":n.removeBg?"remove-background":null;if(c!==null){if(u.length>1)throw d(`Use one operation at a time \u2014 got ${u.join(" and ")}.`);let f=u[0];if(r.length>0)throw d(`${f} cannot be combined with --${r[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw d(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw d("No files given.",`Name an image, for example: forge photo.jpg ${f}`);let g=n.to?I(String(n.to)):"png";if(c==="remove-background"){let k=U(g);if(k)throw k}let b={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(b.quality=S(String(n.quality)));let w={kind:"extension-op",op:c,inputs:i,target:g,options:b,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return a!==void 0&&(w.scale=a),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=j(String(n.concurrency))),w}if(r.length===1){let f=r[0];if(i.length===0)throw d("No files given.",`Name a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw d(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw d(`--output does not apply to --${f}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let g={kind:"pageop",action:f,inputs:i,force:!!n.force,debug:!!n.debug};if(f==="rotate"){let b=Number(n.rotate);if(!Number.isInteger(b)||b%90!==0||b===0||b>=360)throw d(`--rotate takes a multiple of 90 below 360, not "${n.rotate}".`);g.rotate=b}if((f==="extract"||f==="delete")&&(g.pages=String(n[f]),f==="extract"&&n.separate&&(g.separate=!0)),f==="split"){let b=String(n.split),w=b.match(/^every=(\d+)$/),k=b.match(/^at=([\d,\s]+)$/);if(b==="every-page")g.split={mode:"every-page"};else if(w?.[1]!==void 0){let y=Number(w[1]);if(!Number.isInteger(y)||y<1)throw d(`--split every=N takes a whole number of pages, at least 1, not "${w[1]}".`);g.split={mode:"every-n",n:y}}else if(k?.[1])g.split={mode:"points",after:k[1].split(",").map(y=>Number(y.trim()))};else throw d(`--split takes every-page, every=N or at=N,N \u2014 not "${b}".`)}return g}if(i.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw d("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(i.length===0)throw d("No files given.","Name a file, for example: forge photo.jpg --max-size 500kb");let f={background:String(n.background),keepMetadata:!!n.keepMetadata};o!==void 0&&(f.media=o);let g={kind:"compress",inputs:i,options:f,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(g.quality=S(String(n.quality))),n.maxSize!==void 0&&(g.maxBytes=B(n.maxSize)),n.output!==void 0&&(g.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let b=Number(n.dpi);if(!Number.isInteger(b)||b<36||b>600)throw H(n.dpi);g.dpi=b}return n.concurrency!==void 0&&(g.concurrency=j(String(n.concurrency))),g}if(!n.to)throw d("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw d("No files given.","Name a file, a folder or a glob, for example: forge photo.jpg --to webp");let p={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(p.quality=S(String(n.quality))),o!==void 0&&(p.media=o);let O=Number(n.dpi);if(!Number.isInteger(O)||O<36||O>600)throw H(n.dpi);let _={kind:"convert",inputs:i,target:I(String(n.to)),options:p,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:O,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(_.output=String(n.output)),n.pages!==void 0&&(_.pages=String(n.pages)),n.maxSize!==void 0&&(_.maxBytes=B(n.maxSize)),n.concurrency!==void 0&&(_.concurrency=j(String(n.concurrency))),_}export{me as a,ie as b,ge as c,xe as d,ft as e,mt as f};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{e as a}from"./chunk-THDAQBQ3.js";import{a as t}from"./chunk-H3DIRJFE.js";var p=[{op:"compress",label:"Compress"},{op:"resize",label:"Resize"},{op:"crop",label:"Crop to shape"},{op:"trim",label:"Trim edges"},{op:"format",label:"Convert to another format"},{op:"sharpen",label:"Sharpen"},{op:"boost",label:"Boost resolution"},{op:"cutout",label:"Remove background"}],n=r=>t[r]?.label??r.toUpperCase(),i=r=>`under ${Math.round(r/1e3)} KB`,u=r=>"width"in r?`${r.width} wide`:"height"in r?`${r.height} high`:`${r.percent}%`;function l(r,e){let o={...r};switch(e.op){case"compress":return"quality"in e?(delete o.maxBytes,o.quality=e.quality,o.compress=r.compress??{dither:!1}):o.maxBytes=e.bytes,o;case"resize":return o.resize=e.spec,o;case"crop":return o.crop=e.aspect,o;case"trim":return o.trim=!0,o;case"format":return o.to=e.to,e.quality===void 0?delete o.quality:o.quality=e.quality,o;case"sharpen":return o.sharpen=!0,o;case"boost":return o.boost=e.scale,o;case"cutout":return o.removeBackground=!0,o}}function d(r){switch(r.op){case"compress":return"quality"in r?`quality ${r.quality}`:i(r.bytes);case"resize":return u(r.spec);case"crop":return`${r.aspect.w}:${r.aspect.h}`;case"trim":return"Trim";case"format":return`${n(r.to)}${r.quality===void 0?"":` ${r.quality}`}`;case"sharpen":return"Sharpen";case"boost":return`Boost ${r.scale}\xD7`;case"cutout":return"Remove background"}}function b(r,e){return[...!(e.to===void 0||e.to===r)&&e.to?[`${n(e.to)}${e.quality===void 0?"":` ${e.quality}`}`]:e.quality!==void 0?[`quality ${e.quality}`]:[],...e.resize?[u(e.resize)]:[],...e.trim?["Trim"]:[],...e.crop?[`${e.crop.w}:${e.crop.h}`]:[],...e.sharpen&&!e.boost?["Sharpen"]:[],...e.boost?[`Boost ${e.boost}\xD7`]:[],...e.removeBackground?["Remove background"]:[],...e.maxBytes?[i(e.maxBytes)]:[]]}function h(r,e){if(r.frames>1)return{trim:"animated",crop:"animated"};let o={};return e?.trimmed==="nothing"&&(o.trim="no empty edges"),a(r).length===0&&(o.crop="no shape to cut"),o}export{p as a,l as b,d as c,b as d,h as e};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{i as x}from"./chunk-V3I6DSF4.js";import{c as U}from"./chunk-DZOBIUV6.js";import{A,B as T,C as B,d as k,da as S,ea as C,na as E,r as w,u as I,z as M}from"./chunk-WIPP5TWQ.js";function _(e=1,t=100){let o=Math.max(1,t-e+1);return 1+Math.max(0,Math.ceil(Math.log2(o)))}async function q(e){let t=e.min??1,o=e.max??100,l=_(t,o),a=0,s=async n=>(a+=1,e.onAttempt?.(a,l),e.encode(n)),u=()=>e.signal?.aborted===!0,i=await s(o);if(u())return{quality:o,bytes:i,missed:!1,cancelled:!0};if(i<=e.targetBytes)return{quality:o,bytes:i,missed:!1};let c=t,m=o,b;for(;c<=m;){let n=Math.floor((c+m)/2),p=await s(n);if(u())return{quality:n,bytes:p,missed:!1,cancelled:!0};p<=e.targetBytes?(b={quality:n,bytes:p,missed:!1},c=n+1):m=n-1}if(b)return b;let h=await e.encode(t);return{quality:t,bytes:h,missed:!0}}import{cpus as D}from"node:os";function L(){return Math.max(1,Math.min(D().length,4))}function J(e){let t=e!==void 0&&Number.isFinite(e)?e:void 0;return Math.max(1,t??L())}async function R(e,t,o){let l=0,a=async()=>{for(;l<e.length;){let u=l++;await o(e[u],u)}},s=Math.min(J(t),e.length);await Promise.all(Array.from({length:s},a))}async function O(e,t){let o=t.onEvent??(()=>{}),l=t.engineFor??x,a=J(t.concurrency),s=e.length,u=[],i=[],c=0;await R(e,a,async(n,p)=>{if(t.signal?.aborted)return;o({type:"job:start",job:n,index:p,total:s});let g=l(n);if(!g){c++;let f=n.sources[0].path,F={path:f,error:E(f,new Error(`no engine runs ${n.op}`))};i[p]=F,o({type:"job:error",job:n,failure:F,completed:c,total:s});return}try{let f=await g.run(n,F=>o({type:"job:phase",job:n,progress:F}),t.signal);u[p]=f,c++,o({type:"job:done",job:n,result:f,completed:c,total:s})}catch(f){c++;let F=n.sources[0].path,r=k(f)?f:E(F,f),d={path:F,error:r};i[p]=d,o({type:"job:error",job:n,failure:d,completed:c,total:s})}});let m=u.filter(n=>n!==void 0),b=i.filter(n=>n!==void 0),h={results:m,failures:b,inputBytes:m.reduce((n,p)=>n+p.job.sources[0].bytes,0),outputBytes:m.reduce((n,p)=>n+p.outputBytes,0)};return o({type:"batch:done",summary:h}),h}import{existsSync as W}from"node:fs";import{resolve as P}from"node:path";function z(e){let t=e.sources[0]?.path??e.outputs[0]??"",o=new Set;for(let l of e.outputs){let a=P(l);if(o.has(a))return{output:l,error:T(t,l)};o.add(a)}}function Q(e,t,o){let l=z(e);if(l)return l;let a=e.sources[0]?.path??e.outputs[0]??"";for(let s of e.outputs){let u=P(s);if(e.sources.some(c=>U(c.path,u))&&!o)return{output:s,error:B(s,e.op)};let i=t.get(u);if(i){let c=i.sources[0]?.path??i.outputs[0]??"";return{output:s,error:A([c,a],s)}}if(W(u)&&!o)return{output:s,error:M(s,e.op)}}}function N(e,t){let o=[],l=[],a=new Map;for(let s of e){let u=Q(s,a,t.force);if(u){let i=s.sources[0]?.path??u.output;l.push({path:i,error:u.error});continue}for(let i of s.outputs)a.set(P(i),s);o.push(s)}return{jobs:o,failures:l}}async function X(e,t,o,l,a,s){let u=e.sources[0].path,i=r=>({kind:"failed",failure:{path:u,error:k(r)?r:E(u,r)}}),c=o(e);if(c?.sizeTo){let r=e.sources[0],d=e.options.compress!==void 0;if(d&&r.bytes<=t)return{kind:"failed",failure:{path:u,error:C(u,r.bytes,t)}};let y=t,v=c.sizeTo(e,y);return v&&d&&v.floor>=r.bytes?{kind:"failed",failure:{path:u,error:S(u,r.bytes,v.floor,!0)}}:v?{kind:"unreachable",entry:{job:e,smallest:v.floor,settings:{quality:1,media:{...e.options.media,targetBytes:v.floor}},error:I(r,t,v.floor)}}:(e.options={...e.options,media:{...e.options.media,targetBytes:y}},{kind:"ready"})}let m;try{m=await o(e)?.measurer?.(e)}catch(r){return i(r)}if(!m||m.ladder.length===0)return{kind:"refused",failure:{path:u,error:w(e.sources[0],e.target)}};let b=m,h=e.sources[0],n=e.options.compress!==void 0&&h.bytes<=t,p=n?h.bytes-1:t;if(a?.aborted)return{kind:"cancelled"};let g=Number.POSITIVE_INFINITY,f;try{for(let r of b.ladder){let d=await q({encode:y=>b.measure({...e.options,...r,quality:y}),targetBytes:p,...s===void 0?{}:{max:s},onAttempt:(y,v)=>l({type:"search:attempt",job:e,attempt:y,of:v,rung:r}),...a===void 0?{}:{signal:a}});if(d.cancelled)return{kind:"cancelled"};if(d.bytes<g&&(g=d.bytes,f={...r,quality:d.quality}),!d.missed)return e.options={...e.options,...r,quality:d.quality},{kind:"ready"}}}catch(r){return i(r)}return n?{kind:"failed",failure:{path:u,error:S(u,h.bytes,g,!0)}}:{kind:"unreachable",entry:{job:e,smallest:g,settings:f??{quality:1},error:I(e.sources[0],t,g)}}}async function ie(e,t){let o=t.onEvent??(()=>{}),l=t.engineFor??x,a=t.targetBytes,s=N(e,{force:t.force}),u=a===void 0?0:s.jobs.filter(r=>r.op==="convert").length,i=[],c=0;await R(s.jobs,J(t.concurrency),async(r,d)=>{if(a===void 0||r.op!=="convert"){i[d]={kind:"ready"};return}if(t.signal?.aborted){i[d]={kind:"cancelled"};return}let y=await X(r,a,l,o,t.signal,t.maxQuality);i[d]=y,y.kind!=="cancelled"&&(c+=1,o({type:"search:settled",job:r,completed:c,total:u}))});let m=[...s.failures],b=[],h=[],n=[],p=!1;for(let[r,d]of s.jobs.entries()){let y=i[r]??{kind:"ready"};y.kind==="ready"?n.push(d):y.kind==="refused"?m.push(y.failure):y.kind==="failed"?h.push(y.failure):y.kind==="unreachable"?b.push(y.entry):p=!0}if(p)return{results:[],refusals:m,unreachable:[],failures:[],inputBytes:0,outputBytes:0,cancelled:!0};let g=new Set,f=await O(n,{...t.concurrency===void 0?{}:{concurrency:t.concurrency},...t.engineFor===void 0?{}:{engineFor:t.engineFor},...t.signal===void 0?{}:{signal:t.signal},onEvent:r=>{r.type==="job:error"&&!t.signal?.aborted&&g.add(r.failure),o(r)}}),F=n.length-f.results.length;if(t.signal?.aborted&&F>0){let r=f.failures.filter(d=>g.has(d));return{...f,refusals:m,unreachable:b,failures:[...h,...r],cancelled:!0}}return{results:f.results,refusals:m,unreachable:b,failures:[...h,...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}export{J as a,N as b,ie as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
var a={jpeg:{id:"jpeg",label:"JPEG",extensions:[".jpg",".jpeg"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"universal",defaultQuality:82},png:{id:"png",label:"PNG",extensions:[".png"],hasAlpha:!0,animatable:!1,lossy:!1,hint:"lossless",quantisable:!0},webp:{id:"webp",label:"WebP",extensions:[".webp"],hasAlpha:!0,animatable:!0,lossy:!0,hint:"smaller, modern",defaultQuality:80},avif:{id:"avif",label:"AVIF",extensions:[".avif"],hasAlpha:!0,animatable:!1,lossy:!0,hint:"smallest",defaultQuality:50},heic:{id:"heic",label:"HEIC",extensions:[".heic",".heif"],hasAlpha:!0,animatable:!1,lossy:!0,hint:"Apple photos"},raw:{id:"raw",label:"RAW",extensions:[".dng",".cr2",".cr3",".nef",".nrw",".arw",".srf",".sr2",".raf",".orf",".rw2",".rwl",".pef",".srw",".3fr",".fff",".erf",".dcr",".kdc",".mos"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"camera photos"},mp4:{id:"mp4",label:"MP4",extensions:[".mp4",".m4v"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"H.264 \xB7 AAC",media:"video"},mov:{id:"mov",label:"MOV",extensions:[".mov",".qt"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"QuickTime",media:"video",keepsOnly:!0},hevc:{id:"hevc",label:"HEVC",extensions:[".mp4"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"H.265 \xB7 AAC",media:"video"},webm:{id:"webm",label:"WebM",extensions:[".webm"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"VP9 \xB7 Opus",media:"video"},gif:{id:"gif",label:"GIF",extensions:[".gif"],hasAlpha:!0,animatable:!0,lossy:!1,hint:"animation",quantisable:!0,media:"video"},tiff:{id:"tiff",label:"TIFF",extensions:[".tif",".tiff"],hasAlpha:!0,animatable:!1,lossy:!1,hint:"archival"},pdf:{id:"pdf",label:"PDF",extensions:[".pdf"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"document"},docx:{id:"docx",label:"DOCX",extensions:[".docx"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"Word document"},doc:{id:"doc",label:"DOC",extensions:[".doc"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"legacy Word"},mkv:{id:"mkv",label:"MKV",extensions:[".mkv"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"Matroska",media:"video",keepsOnly:!0},avi:{id:"avi",label:"AVI",extensions:[".avi"],hasAlpha:!1,animatable:!0,lossy:!0,hint:"legacy video",media:"video",keepsOnly:!0},mp3:{id:"mp3",label:"MP3",extensions:[".mp3"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"plays anywhere",media:"sound"},m4a:{id:"m4a",label:"M4A",extensions:[".m4a",".m4b"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"AAC",media:"sound"},opus:{id:"opus",label:"Opus",extensions:[".opus"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"smallest",media:"sound"},flac:{id:"flac",label:"FLAC",extensions:[".flac"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"lossless",media:"sound"},aiff:{id:"aiff",label:"AIFF",extensions:[".aiff",".aif",".aifc"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"uncompressed",media:"sound"},wav:{id:"wav",label:"WAV",extensions:[".wav"],hasAlpha:!1,animatable:!1,lossy:!1,hint:"uncompressed",media:"sound"},ogg:{id:"ogg",label:"OGG",extensions:[".ogg",".oga"],hasAlpha:!1,animatable:!1,lossy:!0,hint:"Vorbis",media:"sound",keepsOnly:!0}},l=Object.keys(a);function i(e){return a[e.toLowerCase()]}function t(e){let s=a[e].extensions[0];if(!s)throw new Error(`format ${e} declares no extensions`);return s}export{a,i as b,t as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
var e="https://github.com/AtharvaN16/forge-terminal/releases/download",n="https://github.com/yt-dlp/yt-dlp/releases/download/2026.08.19",i=[{id:"boost",title:"Boost resolution",summary:"Sharpen, or boost resolution 2x or 4x, with a local AI model",minMacos:14,assets:{"darwin-arm64":{version:"1.0.0",url:`${e}/ext-boost-v1.0.0/forge-ext-boost-1.0.0-arm64.tar.gz`,bytes:14866325,sha256:"7af24c92f95b1cd34618adde4a90926c91a8db4347d640be4921f1dc706a9a2e"},"darwin-x64":{version:"1.2.0",url:`${e}/ext-boost-v1.2.0/forge-ext-boost-1.2.0-x64.tar.gz`,bytes:16062122,sha256:"4770833905b4b6c348d1eb18bb735ace9a4f63ace51097c4a7c4b74ec1787998"},"win32-x64":{version:"1.1.0",url:`${e}/ext-boost-v1.1.0/forge-ext-boost-1.1.0-win32-x64.tar.gz`,bytes:22993151,sha256:"abac81a9efe616f33b3bce98db2c0ff0b5597b43a7e3d5ea98968761a2b7a0ce"},"win32-arm64":{version:"1.1.0",url:`${e}/ext-boost-v1.1.0/forge-ext-boost-1.1.0-win32-arm64.tar.gz`,bytes:22936985,sha256:"7d39d93cae52f298423db0b185b0ae3a3bac65464abeb23561d9bcb2ebb3f026"},"linux-x64":{version:"1.2.0",url:`${e}/ext-boost-v1.2.0/forge-ext-boost-1.2.0-linux-x64.tar.gz`,bytes:17020821,sha256:"fca6232c38c05469e255ba2900ab32f993c1b8588f0a3569b24977ab657ff4cb"}},licence:"Real-ESRGAN general-x4v3 (BSD-3-Clause), ONNX Runtime (MIT), Dawn (BSD-3-Clause)"},{id:"remove-background",title:"Remove background",summary:"Cut the subject out of a photo, on your own computer",minMacos:14,assets:{"darwin-universal":{version:"1.0.0",url:`${e}/ext-remove-background-v1.0.0/forge-ext-remove-background-1.0.0-universal.tar.gz`,bytes:32489,sha256:"9f6e055c0ce25f7504e10c7871e506a813bc75d6536396a675a8c075c4eb4686"},"win32-x64":{version:"1.1.0",url:`${e}/ext-remove-background-v1.1.0/forge-ext-remove-background-1.1.0-win32-x64.tar.gz`,bytes:47185054,sha256:"50e8ec4df513d491fa5c1a08e92919426d78f021aa7641e0e0e8b958fd5ebb32"},"win32-arm64":{version:"1.1.0",url:`${e}/ext-remove-background-v1.1.0/forge-ext-remove-background-1.1.0-win32-arm64.tar.gz`,bytes:47167233,sha256:"1210707480f0119019be21d9bfefe80faa472ebb345e9ae3e560bb7b5c1989a3"},"linux-x64":{version:"1.1.0",url:`${e}/ext-remove-background-v1.1.0/forge-ext-remove-background-1.1.0-linux-x64.tar.gz`,bytes:51958081,sha256:"d3c6cf5e02bd1dfdc73c564acf679d9e4ec0e218386573347e17d2392237c123"},"linux-arm64":{version:"1.1.0",url:`${e}/ext-remove-background-v1.1.0/forge-ext-remove-background-1.1.0-linux-arm64.tar.gz`,bytes:45516645,sha256:"97ebaaad5ee7b13696bfc1e7bf8203942370987d828625e25e095c3f9d350a5c"}},licence:"Apple Vision on a Mac (the helper is MIT); BiRefNet-lite (MIT) and ONNX Runtime (MIT) on Windows and Linux"},{id:"heic",title:"HEIC photos",summary:"Open iPhone photos (HEIC)",assets:{"win32-universal":{version:"1.0.0",url:`${e}/ext-heic-v1.0.0/forge-ext-heic-1.0.0-win32-universal.tar.gz`,bytes:532364,sha256:"6c5f86c1a896d84264fb19371117e6ca6ec9b8726afec03f8c30aa5125a3ad97"},"linux-universal":{version:"1.0.0",url:`${e}/ext-heic-v1.0.0/forge-ext-heic-1.0.0-linux-universal.tar.gz`,bytes:532362,sha256:"fccac1de0c707c18778e7909237747fdd47602f9c6861e600a24d23ac3f5b63c"}},licence:"libheif and libde265 (LGPL-3.0), via libheif-js"},{id:"raw",title:"Camera RAW photos",summary:"Open camera RAW photos",assets:{"win32-universal":{version:"1.0.0",url:`${e}/ext-raw-v1.0.0/forge-ext-raw-1.0.0-win32-universal.tar.gz`,bytes:529983,sha256:"def170f48e004240c0cd23a539e4345d8056ea1f4d9c90f45c2a07573bfad199"},"linux-universal":{version:"1.0.0",url:`${e}/ext-raw-v1.0.0/forge-ext-raw-1.0.0-linux-universal.tar.gz`,bytes:529982,sha256:"35c21be2691cecfcadca944ee8c61736b7d6149130e42492c097115467facd36"}},licence:"LibRaw (LGPL-2.1 or CDDL-1.0), via libraw-wasm (ISC)"},{id:"video",title:"Video and audio",summary:"Convert, compress and trim video and audio (ffmpeg)",minMacos:13,assets:{},licence:"FFmpeg (GPL-2.0-or-later) with x264 (GPL-2.0), LAME (LGPL-2.0), Opus and libvpx (BSD), zimg (WTFPL)"},{id:"yt-dlp",title:"YouTube links",summary:"Transcribe YouTube videos: yt-dlp fetches their sound",minMacos:13,assets:{"darwin-universal":{version:"2026.08.19",url:`${n}/yt-dlp_macos`,bytes:37146048,sha256:"0f192b7ec147ab6288885d6351d9ab67367640029b4377576ef46dd79cf7b202",binary:"yt-dlp"},"linux-x64":{version:"2026.08.19",url:`${n}/yt-dlp_linux`,bytes:40446224,sha256:"58162f9bfdc27458ea47bfcb311cf47028f17d8154a8bf7d689861d46399230a",binary:"yt-dlp"},"linux-arm64":{version:"2026.08.19",url:`${n}/yt-dlp_linux_aarch64`,bytes:40167448,sha256:"b16e4dab368a816cd05d477d698a605a6ae87ccee1c8ffd38fa21d7254141fcc",binary:"yt-dlp"},"win32-x64":{version:"2026.08.19",url:`${n}/yt-dlp.exe`,bytes:17840399,sha256:"66674953fe251b89f4d08c5f0e35e0728679bd67ab3d7d05c0562af101dd3e7a",binary:"yt-dlp.exe"},"win32-arm64":{version:"2026.08.19",url:`${n}/yt-dlp_arm64.exe`,bytes:21159286,sha256:"05b438997bafc3affdfda9d041353c9d73e04dc842207254b655b0887c4445b0",binary:"yt-dlp.exe"}},licence:"yt-dlp (Unlicense); its bundled Python and libraries under their own licences"},{id:"whisper",title:"Speech to text (whisper.cpp)",summary:"Transcribe video and sound on this computer, with whisper.cpp",minMacos:13,assets:{"darwin-universal":{version:"1.0.0",url:`${e}/ext-whisper-v1.0.0/forge-ext-whisper-1.0.0-universal.tar.gz`,bytes:61123538,sha256:"f521e829afdbcf56da901bd9df5f7644d9903489a2167c3cf75c72cab98629ad"},"win32-x64":{version:"1.0.0",url:`${e}/ext-whisper-v1.0.0/forge-ext-whisper-1.0.0-win32-x64.tar.gz`,bytes:60751383,sha256:"930014128158e14903413dce5b15b1a9853d6257fd6998da5ecedffb8a435c2f"},"win32-arm64":{version:"1.0.0",url:`${e}/ext-whisper-v1.0.0/forge-ext-whisper-1.0.0-win32-arm64.tar.gz`,bytes:58197088,sha256:"f11f1fdcc07816033558ebc89d19e31f60a4672b0e239a67e18160d205cc4460"},"linux-arm64":{version:"1.0.0",url:`${e}/ext-whisper-v1.0.0/forge-ext-whisper-1.0.0-linux-arm64.tar.gz`,bytes:57902587,sha256:"17f793a111809b81f7761a7c226be1f9c71aa23701030e0616663ed411d0b827"},"linux-x64":{version:"1.0.0",url:`${e}/ext-whisper-v1.0.0/forge-ext-whisper-1.0.0-linux-x64.tar.gz`,bytes:58051297,sha256:"23ef0a03fa46364a85b485f03234327e6a6cc9c8b31e8ac86f6abb9dfad8f82e"}},licence:"whisper.cpp and ggml (MIT), OpenAI Whisper base model (MIT)"},{id:"read-text",title:"Read text",summary:"Read the text of pictures and PDFs on this computer",minMacos:13,assets:{"darwin-arm64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-arm64.tar.gz`,bytes:42705161,sha256:"5fea76dcbe7ea8b52feb2f42796ca831de8237db14cc13f541fcecf310552599"},"darwin-x64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-x64.tar.gz`,bytes:43898855,sha256:"028e8643d7d96c90dc030124a5c2a2348a9549560017f10b5b49aff50382bb1e"},"win32-x64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-win32-x64.tar.gz`,bytes:41461196,sha256:"39a1da83498d9858cebc3202f884ca852954ffee01383af90efd9e99dd752e6d"},"win32-arm64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-win32-arm64.tar.gz`,bytes:41540477,sha256:"ee551378b14c199b4528511d5a0066e29a11397caf4f5c7fb801eeb40544cb25"},"linux-x64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-linux-x64.tar.gz`,bytes:44859772,sha256:"b5d1158d06dc008e1986a0684049911194e97b72f35d01c2110d71e0d39b446a"},"linux-arm64":{version:"1.1.0",url:`${e}/ext-read-text-v1.1.0/forge-ext-read-text-1.1.0-linux-arm64.tar.gz`,bytes:39842973,sha256:"bfa94581c43f9d9760d6ca33f7e19dc31e58732ac6c07bf89fe433ac594d8176"}},licence:"PP-OCRv4 detection and PP-OCRv5 and PP-OCRv6 recognition (Apache-2.0, PaddlePaddle; ONNX by RapidOCR and PaddlePaddle), ONNX Runtime (MIT)"}];function b(a=process.platform){return a==="win32"?"PC":a==="darwin"?"Mac":"computer"}function f(a=process.platform){return a==="win32"?"Windows":a==="darwin"?"macOS":a==="linux"?"Linux":"this system"}var l=["darwin","win32","linux"];function o(a){return i.find(r=>r.id===a)}function d(a,r=process.platform,t=process.arch){let s=a.assets;return s[`${r}-${t}`]??s[`${r}-universal`]}function c(a,r=process.platform){return Object.keys(a.assets).some(t=>t.startsWith(`${r}-`))}function u(a,r=process.platform,t){let s=o(a);return s===void 0||!c(s,r)?!1:t===void 0||d(s,r,t)!==void 0}export{i as a,b,f as c,l as d,o as e,d as f,c as g,u as h};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a as l,c}from"./chunk-PE5LAYGF.js";import{e as p,f as u}from"./chunk-HKINXTUW.js";import{execFile as P}from"node:child_process";import{access as N,constants as A,mkdir as I,readFile as E,realpath as _,writeFile as F}from"node:fs/promises";import{homedir as B}from"node:os";import{dirname as C,join as f,posix as R,sep as m,win32 as S}from"node:path";import{promisify as T}from"node:util";var w=T(P),H=["yt-dlp","video"],X=e=>H.includes(e),a={"yt-dlp":{binary:"yt-dlp",name:"yt-dlp",formula:"yt-dlp",versionArgs:["--version"],version:e=>e.trim().split(`
|
|
4
|
+
`)[0]?.match(/^\d+(\.\d+)+$/)?.[0]},video:{binary:"ffmpeg",name:"ffmpeg",formula:"ffmpeg",versionArgs:["-hide_banner","-version"],version:e=>e.match(/ffmpeg version (\S+)/)?.[1],beside:["ffprobe"]}},Y=e=>a[e].name,q=e=>a[e].formula;function $(e,n){let r=e.split(".").map(Number),i=n.split(".").map(Number);for(let t=0;t<Math.max(r.length,i.length);t++){let o=r[t]??0,s=i[t]??0;if(Number.isNaN(o)||Number.isNaN(s))return e>n;if(o!==s)return o>s}return!1}function g(e){let n=p(e);return n&&(u(n)?.version??u(n,"darwin","universal")?.version)}function y({platform:e=process.platform,env:n=process.env,deep:r=!1}={}){let t=(n.PATH??n.Path??"").split(e==="win32"?";":":").filter(Boolean);if(e==="darwin"&&t.push("/opt/homebrew/bin","/usr/local/bin"),r){let o=n.HOME??B(),{join:s}=e==="win32"?S:R;t.push(s(o,".local","bin"),s(o,"bin"),"/opt/local/bin","/usr/bin")}return[...new Set(t)]}var O=(e,n=process.platform)=>n==="win32"?`${e}.exe`:e;async function d(e){try{return await N(e,A.X_OK),!0}catch{return!1}}async function b(e,n){let r=a[e];if(await d(n)){for(let i of r.beside??[])if(!await d(f(C(n),O(i))))return;try{let{stdout:i}=await w(n,r.versionArgs,{timeout:5e3}),t=r.version(i);if(t===void 0)return;let o=await _(n).catch(()=>n),s=g(e);return{id:e,path:n,version:t,homebrew:o.includes(`${m}Cellar${m}`),tooOld:e==="yt-dlp"&&s!==void 0&&$(s,t)}}catch{return}}}var h=()=>f(l(),"own.json");async function v(){try{let e=JSON.parse(await E(h(),"utf8"));return typeof e=="object"&&e!==null?e:{}}catch{return{}}}async function j(e){let n=(await v())[e];return typeof n=="string"&&n!==""?n:void 0}async function z(e,n){let r=await v();n===void 0?delete r[e]:r[e]=n,await I(l(),{recursive:!0}),await F(h(),`${JSON.stringify(r,null,2)}
|
|
5
|
+
`)}async function J(e,n={}){let r=await j(e);if(r!==void 0){let o=await b(e,r);if(o)return o}let t=process.env.FORGE_NO_OWN_TOOLS==="1"&&n.dirs===void 0?[]:n.dirs??y({deep:n.deep??!1});for(let o of t){let s=await b(e,f(o,O(a[e].binary)));if(s)return s}}async function k(e){if(await c(e)===void 0)return 0;try{let{removeExtension:n,extensionBytes:r}=await import("./manager-CQ6NNQY4.js"),i=await r(e);return await n(e)?i:0}catch{return 0}}async function Q(e={}){let n=await J("yt-dlp",e);if(n&&!n.tooOld)return await k("yt-dlp"),{entry:n.path,own:!0};let r=await c("yt-dlp");return r?{entry:r.entry,own:!1}:void 0}async function x(e){if(e.brew!==void 0)return await d(e.brew)?e.brew:void 0;for(let n of y({env:{PATH:process.env.PATH??""}})){let r=f(n,"brew");if(await d(r))return r}}async function V(e,n={}){if(e.tooOld)return g(e.id);if(!e.homebrew)return;let r=await x(n);if(r!==void 0)try{let{stdout:i}=await w(r,["outdated","--json=v2","--formula",a[e.id].formula],{timeout:15e3,env:{...process.env,HOMEBREW_NO_AUTO_UPDATE:"1"}}),t=JSON.parse(i);if(!Array.isArray(t.formulae))return;let o=t.formulae[0]?.current_version;return typeof o=="string"?o:null}catch{return}}var Z=e=>e.homebrew?"Homebrew":e.id==="yt-dlp"?"yt-dlp":void 0;async function ee(e,n={}){let r,i;if(e.homebrew){let t=await x(n);if(t===void 0)throw new Error("Homebrew was not found");r=t,i=["upgrade",a[e.id].formula]}else if(e.id==="yt-dlp")r=e.path,i=["--update"];else throw new Error(`${a[e.id].name} cannot update itself`);try{await w(r,i,{timeout:10*6e4,maxBuffer:8<<20,...n.signal?{signal:n.signal}:{}})}catch(t){if(n.signal?.aborted)throw n.signal.reason??t;let o=t,s=(o.stderr??"").trim().split(`
|
|
6
|
+
`).filter(Boolean).at(-1)?.replace(/^Error:\s*/,"");throw new Error(s||o.message||"the update failed")}}export{H as a,X as b,Y as c,q as d,$ as e,y as f,b as g,j as h,z as i,J as j,k,Q as l,V as m,Z as n,ee as o};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{c as ht}from"./chunk-PE5LAYGF.js";import{b as jt}from"./chunk-HKINXTUW.js";import{b as me}from"./chunk-HZDYZ5RD.js";import{c as Ht}from"./chunk-K7KKCR7V.js";import{f as de,g as tt,h as ge,i as he,j as pe}from"./chunk-KH5DHZ2U.js";import{na as gt,oa as $t,pa as Tt,qa as ce,sa as _t,ta as Rt}from"./chunk-WIPP5TWQ.js";import{c as le,i as ue}from"./chunk-KXKQDFHX.js";import{spawn as nn}from"node:child_process";import{existsSync as It}from"node:fs";import{mkdtemp as se,readFile as oe,rm as ae,writeFile as $r}from"node:fs/promises";import{tmpdir as fe}from"node:os";import{dirname as rn,join as O}from"node:path";import{createInterface as _r}from"node:readline";import{fileURLToPath as jr}from"node:url";var gn=new RegExp("\\p{M}","u"),Bt=new RegExp("\\p{L}","u"),hn=new RegExp("\\p{Nd}","u");function zt(t){let n=String.fromCodePoint(t);return gn.test(n)?"NSM":t>=1632&&t<=1641||t===1643||t===1644?"AN":hn.test(n)?"EN":t>=1424&&t<=1535||t>=64285&&t<=64335?Bt.test(n)?"R":"ON":t>=1536&&t<=1791||t>=1792&&t<=1983||t>=1872&&t<=1919||t>=2208&&t<=2303||t>=64336&&t<=65023||t>=65136&&t<=65279?Bt.test(n)?"AL":"ON":Bt.test(n)?"L":t===43||t===45?"ES":t===35||t===36||t===37||t===162||t===163||t===176?"ET":t===44||t===46||t===58||t===47||t===160?"CS":n===" "||n===" "||t===12288?"WS":"ON"}var pn={"(":")",")":"(","[":"]","]":"[","{":"}","}":"{","<":">",">":"<","\xAB":"\xBB","\xBB":"\xAB"};function pt(t){for(let n of t){let e=zt(n.codePointAt(0)??0);if(e==="R"||e==="AL")return!0;if(e==="L")return!1}return!1}function mn(t){for(let n of t){let e=zt(n.codePointAt(0)??0);if(e==="R"||e==="AL"||e==="AN")return!0}return!1}function be(t,n){let e=[...t];if(!n&&!mn(t))return t;let i=e.length,r=e.map(a=>zt(a.codePointAt(0)??0)),o=n?1:0,s=o?"R":"L";for(let a=0;a<i;a++){r[a]==="NSM"&&(r[a]=a>0?r[a-1]??"ON":o?"R":"L");let u=r[a];u==="L"||u==="R"||u==="AL"?s=u:u==="EN"&&s==="AL"&&(r[a]="AN")}for(let a=0;a<i;a++)r[a]==="AL"&&(r[a]="R");for(let a=1;a<i-1;a++){let u=r[a],l=r[a-1],g=r[a+1];(u==="ES"||u==="CS")&&l==="EN"&&g==="EN"?r[a]="EN":u==="CS"&&l==="AN"&&g==="AN"&&(r[a]="AN")}for(let a=0;a<i;a++){if(r[a]!=="ET")continue;let u=a;for(;u<i&&r[u]==="ET";)u++;if(r[a-1]==="EN"||r[u]==="EN")for(let l=a;l<u;l++)r[l]="EN";a=u-1}for(let a=0;a<i;a++)(r[a]==="ES"||r[a]==="ET"||r[a]==="CS")&&(r[a]="ON");let f=o?"R":"L";for(let a=0;a<i;a++)r[a]==="L"||r[a]==="R"?f=r[a]:r[a]==="EN"&&f==="L"&&(r[a]="L");let c=a=>a==="L"?"L":a==="R"||a==="EN"||a==="AN"?"R":void 0;for(let a=0;a<i;a++){if(r[a]!=="WS"&&r[a]!=="ON")continue;let u=a;for(;u<i&&(r[u]==="WS"||r[u]==="ON");)u++;let l=a>0?c(r[a-1]):o?"R":"L",g=u<i?c(r[u]):o?"R":"L",m=l!==void 0&&l===g?l:o?"R":"L";for(let S=a;S<u;S++)r[S]=m;a=u-1}let d=r.map(a=>o===0?a==="R"?1:a==="EN"||a==="AN"?2:0:a==="L"||a==="EN"||a==="AN"?2:1),h=e.map((a,u)=>u),p=Math.max(...d),b=Math.min(...d.filter(a=>a%2===1),Number.POSITIVE_INFINITY);for(let a=p;a>=b&&a>0;a--)for(let u=0;u<i;u++){if((d[h[u]]??0)<a)continue;let l=u;for(;l<i&&(d[h[l]]??0)>=a;)l++;let g=h.slice(u,l).reverse();h.splice(u,l-u,...g),u=l-1}return h.map(a=>{let u=e[a];return(d[a]??0)%2===1?pn[u]??u:u}).join("")}var bn=(t,n)=>{let e=t[0]+t[2]/2,i=t[1]+t[3]/2;return e>=n[0]&&e<=n[0]+n[2]&&i>=n[1]&&i<=n[1]+n[3]};function xn(t){let n=t.filter(e=>e.kind!=="text").map(e=>e.box);return t.filter(e=>e.kind!=="text"||!n.some(i=>bn(e.box,i)))}var yn=.002;function we(t,n){let e=f=>f.box[n],i=f=>f.box[n]+(n===0?f.box[2]:f.box[3]),r=[...t].sort((f,c)=>e(f)-e(c)),o=[],s=-1;for(let f of r){let c=o[o.length-1];c&&e(f)<=s+yn?(c.push(f),s=Math.max(s,i(f))):(o.push([f]),s=i(f))}return o}function wn(t){let n=we(t,1);if(n.length<2)return;let e=o=>Math.max(...o.map(s=>s.box[1]+s.box[3])),i=o=>Math.min(...o.map(s=>s.box[1])),r=1;for(let o=2;o<n.length;o++){let s=f=>i(n[f]??[])-e(n[f-1]??[]);s(o)>s(r)&&(r=o)}return[n.slice(0,r).flat(),n.slice(r).flat()]}function Wt(t){if(t.length<=1)return[...t];let n=we(t,0);if(n.length>1)return n.flatMap(Wt);let e=wn(t);return e?e.flatMap(Wt):[...t].sort((i,r)=>i.box[1]-r.box[1]||i.box[0]-r.box[0])}function Sn(t){let n=[];for(let e of t){let i=n[n.length-1],r=Math.max(e.lineHeight,i?.lineHeight??0);if(!(i!==void 0&&e.box[1]-(i.box[1]+i.box[3])<r&&Math.abs(e.box[0]-i.box[0])<2*r)){n.push({...e});continue}let s=Math.max(i.box[0]+i.box[2],e.box[0]+e.box[2]),f=e.box[1]+e.box[3];n[n.length-1]={...i,text:`${i.text} ${e.text}`,lines:i.lines+1,box:[i.box[0],i.box[1],s-i.box[0],f-i.box[1]]}}return n}function An(t){let n=t.flatMap(e=>Array(Math.max(1,e.lines)).fill(e.lineHeight));return n.sort((e,i)=>e-i),n[Math.floor(n.length/2)]??0}var kn=1.2,Pn=80,Gt=t=>t.replace(/\s*\n\s*/g," ").trim();function En(t,n,e){if(t.kind==="list")return{kind:"list",ordered:t.items.some(s=>s.marker==="decimal"||s.marker==="lowercase"||s.marker==="uppercase"),items:t.items.map(s=>Gt(s.text))};if(t.kind==="table"){let s=Math.max(...t.rows.map(f=>f.length));return{kind:"table",rows:t.rows.map(f=>Array.from({length:s},(c,d)=>Gt(f[d]??"")))}}let i=Gt(t.text);return!e&&t.lineHeight>=n*kn&&t.lines===1&&i.length<=Pn&&!/[.,;:!?]$/.test(i)?{kind:"heading",level:t.title?1:2,text:i}:{kind:"paragraph",text:i}}function fi(t){return t.map(n=>{let e=Wt(xn(n.blocks.filter(o=>o.kind!=="text"||o.text.trim()!=="")));n.lines&&(e=Sn(e.filter(o=>o.kind==="text")));let i=e.filter(o=>o.kind==="text"),r=An(i);return e.map(o=>En(o,r,e.length===1))})}var ci=t=>t.some(n=>n.length>0);function Kt(t){return t.replace(/[\\`*[\]<]/g,n=>`\\${n}`).replace(/(^|[^\p{L}\p{N}])_|_(?=[^\p{L}\p{N}]|$)/gu,n=>n.replace("_","\\_"))}function Tn(t){return t.replace(/^(#|>|[-+](?= )|(?<=^\d+)\.(?= ))/,"\\$1").replace(/^(\d+)\.(?= )/,"$1\\.")}var xe=t=>Tn(Kt(t));function Rn(t){if(t.kind==="heading")return`${"#".repeat(t.level)} ${Kt(t.text)}`;if(t.kind==="paragraph")return xe(t.text);if(t.kind==="list")return t.items.map((o,s)=>`${t.ordered?`${s+1}.`:"-"} ${xe(o)}`).join(`
|
|
4
|
+
`);let n=o=>Kt(o).replace(/\|/g,"\\|"),e=o=>`| ${o.map(n).join(" | ")} |`,[i=[],...r]=t.rows;return[e(i),`| ${i.map(()=>"---").join(" | ")} |`,...r.map(e)].join(`
|
|
5
|
+
`)}var Vt=t=>t.filter(n=>n.length>0);function Se(t){let n=Vt(t).map(e=>e.map(Rn).join(`
|
|
6
|
+
|
|
7
|
+
`));return n.length?`${n.join(`
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`)}
|
|
12
|
+
`:""}function Fn(t){return t.kind==="heading"||t.kind==="paragraph"?t.text:t.kind==="list"?t.items.map((n,e)=>`${t.ordered?`${e+1}.`:"-"} ${n}`).join(`
|
|
13
|
+
`):t.rows.map(n=>n.join(" ")).join(`
|
|
14
|
+
`)}function Ae(t){let n=Vt(t).map(e=>e.map(Fn).join(`
|
|
15
|
+
|
|
16
|
+
`));return n.length?`${n.join(`
|
|
17
|
+
|
|
18
|
+
`)}
|
|
19
|
+
`:""}var Nn="table{border-collapse:collapse;width:100%;margin:0 0 8pt}th,td{border:1px solid #c7c7cc;padding:2pt 6pt;text-align:left;vertical-align:top}ol{margin:0 0 8pt}",ye='<p style="margin:0;font-size:5pt"> </p>';function vn(t){if(t.kind==="heading")return`<h${t.level}>${tt(t.text)}</h${t.level}>`;if(t.kind==="paragraph")return`<p>${tt(t.text)}</p>`;if(t.kind==="list"){let o=t.ordered?"ol":"ul";return`<${o}>${t.items.map(s=>`<li>${tt(s)}</li>`).join("")}</${o}>`}let[n=[],...e]=t.rows,i=(o,s)=>`<tr>${o.map(f=>`<${s}>${tt(f)}</${s}>`).join("")}</tr>`,r=`<table>${i(n,"th")}${e.map(o=>i(o,"td")).join("")}</table>`;return`${ye}${r}${ye}`}function ke(t,n){let e=Vt(t).map(i=>i.map(vn).join(`
|
|
20
|
+
`));return["<!doctype html>",`<html><head><meta charset="utf-8"><title>${tt(n)}</title><style>${ge}${Nn}</style></head><body>`,e.join(`
|
|
21
|
+
<hr>
|
|
22
|
+
`),"</body></html>"].join(`
|
|
23
|
+
`)}var Un=[[65,90,"latin"],[97,122,"latin"],[170,170,"latin"],[186,186,"latin"],[192,591,"latin"],[7680,7935,"latin"],[11360,11391,"latin"],[42784,43007,"latin"],[65313,65338,"latin"],[65345,65370,"latin"],[880,1023,"greek"],[7936,8191,"greek"],[1024,1327,"cyrillic"],[7296,7311,"cyrillic"],[11744,11775,"cyrillic"],[42560,42655,"cyrillic"],[1328,1423,"armenian"],[1424,1535,"hebrew"],[64285,64335,"hebrew"],[1536,1791,"arabic"],[1872,1919,"arabic"],[2208,2303,"arabic"],[64336,65023,"arabic"],[65136,65279,"arabic"],[1792,1871,"syriac"],[1920,1983,"thaana"],[2304,2431,"devanagari"],[2432,2559,"bengali"],[2560,2687,"gurmukhi"],[2688,2815,"gujarati"],[2816,2943,"oriya"],[2944,3071,"tamil"],[3072,3199,"telugu"],[3200,3327,"kannada"],[3328,3455,"malayalam"],[3456,3583,"sinhala"],[3584,3711,"thai"],[3712,3839,"lao"],[3840,4095,"tibetan"],[4096,4255,"myanmar"],[4256,4351,"georgian"],[4352,4607,"hangul"],[4608,5023,"ethiopic"],[6016,6143,"khmer"],[6144,6319,"mongolian"],[12352,12447,"kana"],[12448,12543,"kana"],[12784,12799,"kana"],[65382,65439,"kana"],[110592,110959,"kana"],[12592,12687,"hangul"],[43360,43391,"hangul"],[44032,55295,"hangul"],[65440,65500,"hangul"],[11904,12255,"han"],[12288,12351,"han"],[12544,12591,"han"],[12704,12735,"han"],[12800,13311,"han"],[13312,19903,"han"],[19968,40959,"han"],[63744,64255,"han"],[65072,65103,"han"],[65281,65312,"han"],[65371,65381,"han"],[65504,65510,"han"],[131072,205743,"han"],[127744,129791,"emoji"],[9728,10175,"symbols"]];function et(t){if(t<128)return t>=65&&t<=90||t>=97&&t<=122?"latin":void 0;for(let[n,e,i]of Un)if(t>=n&&t<=e)return i}var Ln=new Set(["latin","greek","cyrillic","han","kana","hangul","armenian","georgian","ethiopic","emoji","symbols"]),Pe=new Set([...Ln,"arabic","hebrew","thai","lao"]),Mn={latin:"Latin",greek:"Greek",cyrillic:"Cyrillic",han:"Chinese",kana:"Japanese",hangul:"Korean",arabic:"Arabic",hebrew:"Hebrew",thai:"Thai",lao:"Lao",armenian:"Armenian",georgian:"Georgian",devanagari:"Devanagari",bengali:"Bengali",gurmukhi:"Gurmukhi",gujarati:"Gujarati",oriya:"Odia",tamil:"Tamil",telugu:"Telugu",kannada:"Kannada",malayalam:"Malayalam",sinhala:"Sinhala",tibetan:"Tibetan",myanmar:"Burmese",khmer:"Khmer",ethiopic:"Ethiopic",mongolian:"Mongolian",syriac:"Syriac",thaana:"Thaana",emoji:"emoji",symbols:"symbols"};function Ee(t){return Mn[t]}function In(t){let n=new Set;for(let e of t){let i=et(e.codePointAt(0)??0);i!==void 0&&n.add(i)}return[...n]}function Jt(t,n){let e=n?.toLowerCase().replace("_","-");if(e?.startsWith("ja"))return"ja";if(e?.startsWith("ko"))return"ko";if(e==="zh-tw"||e==="zh-hant"||e==="zh-hk")return"zh-TW";if(e?.startsWith("zh"))return"zh";let i=In(t);return i.includes("kana")?"ja":i.includes("hangul")?"ko":"zh"}var Dn={ja:"ja-JP",ko:"ko-KR",zh:"zh-CN","zh-TW":"zh-TW"},Cn={arabic:"ar-SA",hebrew:"he-IL",thai:"th-TH",lao:"lo-LA",devanagari:"hi-IN",bengali:"bn-IN",gurmukhi:"pa-IN",gujarati:"gu-IN",oriya:"or-IN",tamil:"ta-IN",telugu:"te-IN",kannada:"kn-IN",malayalam:"ml-IN",sinhala:"si-LK",khmer:"km-KH",myanmar:"my-MM",tibetan:"bo-CN",armenian:"hy-AM",georgian:"ka-GE",ethiopic:"am-ET",syriac:"syr-SY",thaana:"dv-MV"},On=new Set(["latin","greek","cyrillic","armenian","georgian","ethiopic","mongolian","emoji","symbols"]);function $n(t){return t===void 0?"neutral":t==="han"||t==="kana"||t==="hangul"?"eastAsia":On.has(t)?"latin":"complex"}var _n=new Set(["arabic","hebrew","syriac","thaana"]);function Te(t,n){let e=Dn[Jt(t,n)],i=[],r="";for(let o of t){let s=et(o.codePointAt(0)??0),f=$n(s);if(f==="neutral"){let p=i.at(-1);p?p.text+=o:r+=o;continue}let c=s!==void 0&&_n.has(s),d=f==="eastAsia"?e:f==="complex"&&s?Cn[s]:void 0,h=i.at(-1);h&&h.kind===f&&h.rtl===c&&h.lang===d?h.text+=o:i.push({text:r+o,kind:f,rtl:c,...d?{lang:d}:{}}),r=""}return r&&i.push({text:r,kind:"latin",rtl:!1}),i}import{existsSync as ur,readFileSync as dr}from"node:fs";import{dirname as gr,join as bt}from"node:path";import{fileURLToPath as hr}from"node:url";import{gunzipSync as pr}from"node:zlib";var nt=new Map;function jn(){let t=new Map,n=[[64336,64511],[65152,65276]];for(let[e,i]of n)for(let r=e;r<=i;r++){let o=String.fromCodePoint(r).normalize("NFKD");if(o===String.fromCodePoint(r))continue;let s=t.get(o);s?s.push(r):t.set(o,[r])}for(let[e,i]of t)i.length===4?nt.set(e,{isolated:i[0]??0,final:i[1]??0,initial:i[2]??0,medial:i[3]??0}):i.length===2&&nt.set(e,{isolated:i[0]??0,final:i[1]??0,initial:0,medial:0})}jn();var Re=t=>t>=1611&&t<=1631||t===1648||t>=1750&&t<=1756||t>=1759&&t<=1764||t===1767||t===1768||t>=1770&&t<=1773,Fe=1604,Hn=new Set([1570,1571,1573,1575]),ve=t=>nt.has(String.fromCodePoint(t)),Ne=t=>(nt.get(String.fromCodePoint(t))?.initial??0)!==0;function Ue(t){for(let n of t)if(ve(n.codePointAt(0)??0))return!0;return!1}function Le(t,n=()=>!0){let e=[...t].map(o=>o.codePointAt(0)??0),i=[],r=!1;for(let o=0;o<e.length;o++){let s=e[o]??0;if(s===8204||s===8205){r=s===8205?r:!1,i.push(s);continue}if(Re(s)){i.push(s);continue}let f=nt.get(String.fromCodePoint(s));if(!f){r=!1,i.push(s);continue}let c=e[o+1]??0;if(s===Fe&&Hn.has(c)){let a=nt.get(String.fromCodePoint(Fe,c)),u=a?r?a.final:a.isolated:0;if(u!==0&&n(u)){i.push(u),r=!1,o++;continue}}let d=o+1;for(;d<e.length&&Re(e[d]??0);)d++;let h=e[d]??0,p=Ne(s)&&h!==8204&&(ve(h)||h===8205),b=r?p?f.medial:f.final:p?f.initial:f.isolated;i.push(b!==0&&n(b)?b:s),r=Ne(s)}return String.fromCodePoint(...i)}function Me(t){return String.fromCodePoint(t).normalize("NFKD")}import{execFile as Zn}from"node:child_process";import{existsSync as Qn,readdirSync as tr,readFileSync as er,statSync as nr}from"node:fs";import{homedir as rr}from"node:os";import{posix as Xt,win32 as Ke}from"node:path";var v={charset:15,encoding:16,charStrings:17,private:18,subrs:19,ros:1230,fdArray:1236,fdSelect:1237};function Y(t,n){let e=(t[n]??0)*256+(t[n+1]??0);if(e===0)return{items:[],end:n+2};let i=t[n+2]??1,r=[],o=n+3;for(let c=0;c<=e;c++){let d=0;for(let h=0;h<i;h++)d=d*256+(t[o+h]??0);r.push(d),o+=i}let s=o-1,f=[];for(let c=0;c<e;c++)f.push(t.subarray(s+(r[c]??0),s+(r[c+1]??0)));return{items:f,end:s+(r[e]??1)}}function X(t){if(t.length===0)return new Uint8Array([0,0]);let n=t.reduce((f,c)=>f+c.length,0)+1,e=n<256?1:n<65536?2:n<16777216?3:4,i=new Uint8Array(3+(t.length+1)*e+n-1);i[0]=t.length>>8,i[1]=t.length&255,i[2]=e;let r=1,o=3,s=f=>{for(let c=e-1;c>=0;c--)i[o++]=f>>8*c&255};s(r);for(let f of t)r+=f.length,s(r);for(let f of t)i.set(f,o),o+=f.length;return i}function Yt(t){let n=[],e=[],i=0,r=0;for(;r<t.length;){let o=t[r]??0;if(o<=21){let s=o;r++,o===12&&(s=1200+(t[r]??0),r++),n.push({op:s,operands:e,raw:t.subarray(i,r)}),e=[],i=r}else if(o===28)e.push(((t[r+1]??0)<<8|(t[r+2]??0))<<16>>16),r+=3;else if(o===29)e.push((t[r+1]??0)<<24|(t[r+2]??0)<<16|(t[r+3]??0)<<8|(t[r+4]??0)),r+=5;else if(o===30){for(r++;r<t.length&&((t[r]??0)&15)!==15&&(t[r]??0)>>4!==15;)r++;r++,e.push(0)}else o>=32&&o<=246?(e.push(o-139),r++):o>=247&&o<=250?(e.push((o-247)*256+(t[r+1]??0)+108),r+=2):o>=251&&o<=254?(e.push(-(o-251)*256-(t[r+1]??0)-108),r+=2):r++}return n}function Bn(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]}function zn(t){return t>=1200?[12,t-1200]:[t]}function W(t,n){return Uint8Array.from([...n.flatMap(Bn),...zn(t)])}function Ft(t){let n=new Uint8Array(t.reduce((i,r)=>i+r.length,0)),e=0;for(let i of t)n.set(i,e),e+=i.length;return n}var q=(t,n)=>t.find(e=>e.op===n);function Ie(t){return t<1240?107:t<33900?1131:32768}function De(t){let n=t[2]??4,e=Y(t,n),i=Y(t,e.end),r=Y(t,i.end),o=Y(t,r.end),s=Yt(i.items[0]??new Uint8Array),f=q(s,v.ros)!==void 0,c=q(s,v.charStrings)?.operands[0]??0,d=Y(t,c),h=d.items.length,p=q(s,v.charset)?.operands[0]??0,b=new Array(h).fill(0);if(p<=2)for(let w=0;w<h;w++)b[w]=w;else{let w=t[p]??0,x=p+1,E=1;if(w===0)for(;E<h;E++,x+=2)b[E]=(t[x]??0)<<8|(t[x+1]??0);else for(;E<h;){let T=(t[x]??0)<<8|(t[x+1]??0),R=t[x+2]??0;x+=3,w===2&&(R=R<<8|(t[x]??0),x++);for(let I=0;I<=R&&E<h;I++,E++)b[E]=T+I}}let a=q(s,v.fdArray)?.operands[0],u=q(s,v.fdSelect)?.operands[0],l=a===void 0?[]:Y(t,a).items.map(Yt),g=new Array(h).fill(0);if(u!==void 0)if((t[u]??0)===0)for(let x=0;x<h;x++)g[x]=t[u+1+x]??0;else{let x=(t[u+1]??0)<<8|(t[u+2]??0),E=u+3;for(let T=0;T<x;T++,E+=3){let R=(t[E]??0)<<8|(t[E+1]??0),I=(t[E+3]??0)<<8|(t[E+4]??0);for(let D=R;D<I&&D<h;D++)g[D]=t[E+2]??0}}let m=w=>{let[x,E]=q(w,v.private)?.operands??[];if(x===void 0||E===void 0)return{dict:[],subrs:[]};let T=Yt(t.subarray(E,E+x)),R=q(T,v.subrs)?.operands[0];return{dict:T,subrs:R===void 0?[]:Y(t,E+R).items}},S=m(s),A=l.length>0?l.map(m):[S];return{cidKeyed:f,glyphCount:h,codeOf:w=>f?b[w]??0:w,subset(w){let x=new Set([0]);for(let y of w)y>=0&&y<h&&x.add(y);let E=Math.max(...x)+1,T=new Map;for(let y of x){let N=Kn(d.items[y]??new Uint8Array,(A[g[y]??0]??S).subrs,o.items);if(!N){T.clear();break}T.set(y,N)}let R=T.size===x.size,I=A.map(()=>new Set),D=new Set;if(!R)for(let y of x)Vn(d.items[y]??new Uint8Array,A[g[y]??0]??S,{local:I[g[y]??0]??new Set,global:D,gsubrs:o.items});let K=y=>R?T.get(y):d.items[y],Q=new Uint8Array([14]),k=new Uint8Array([11]),P=f?[...x].sort((y,N)=>y-N):Array.from({length:E},(y,N)=>N),z=(y,N)=>{if(N.size===0)return[];let B=y.length>=33900?33900:y.length>=1240?1240:0,J=Math.max(...N)+1;return y.slice(0,Math.max(J,B)).map((dt,Ct)=>N.has(Ct)?dt:k)},U=X(R?[]:z(o.items,D)),C=X(P.map(y=>x.has(y)?K(y)??Q:Q)),M=Gn(P.map(y=>b[y]??0)),j=l.length>0?Wn(P.map(y=>g[y]??0)):void 0,G=A.map((y,N)=>{let B=X(R?[]:z(y.subrs,I[N]??new Set)),J=y.dict.filter(Ot=>Ot.op!==v.subrs).map(Ot=>Ot.raw),dt=!R&&y.subrs.length>0,Ct=dt?W(v.subrs,[0]):new Uint8Array,dn=Ft([...J]).length+Ct.length;return{dict:Ft([...J,...dt?[W(v.subrs,[dn])]:[]]),subrs:dt?B:new Uint8Array}}),st=Uint8Array.from([1,0,4,4]),at=X(e.items),ft=X(r.items),wt=y=>{let N=[];for(let B of s)B.op===v.charset?N.push(W(v.charset,[y.charset])):B.op===v.charStrings?N.push(W(v.charStrings,[y.charStrings])):B.op===v.fdArray?N.push(W(v.fdArray,[y.fdArray])):B.op===v.fdSelect?N.push(W(v.fdSelect,[y.fdSelect])):B.op===v.private?N.push(W(v.private,[...y.priv])):B.op===v.encoding?N.push(W(v.encoding,[0])):N.push(B.raw);return X([Ft(N)])},St=wt({charset:0,charStrings:0,fdArray:0,fdSelect:0,priv:[0,0]}).length,H=st.length+at.length+St+ft.length+U.length,At=H;H+=M.length;let kt=H;H+=j?.length??0;let Pt=H;H+=C.length;let ct=y=>X(l.map((N,B)=>Ft(N.map(J=>J.op===v.private?W(v.private,[...y[B]??[0,0]]):J.raw)))),Et=H;H+=l.length>0?ct(l.map(()=>[0,0])).length:0;let F=[];for(let y of G)F.push([y.dict.length,H]),H+=y.dict.length+y.subrs.length;let $=wt({charset:At,charStrings:Pt,fdArray:Et,fdSelect:kt,priv:F[0]??[0,0]}),lt=[st,at,$,ft,U,M,...j?[j]:[],C,...l.length>0?[ct(F)]:[],...G.flatMap(y=>[y.dict,y.subrs])],ut=new Uint8Array(lt.reduce((y,N)=>y+N.length,0)),V=0;for(let y of lt)ut.set(y,V),V+=y.length;return ut}}}function Gn(t){let n=[2],e=1;for(;e<t.length;){let o=t[e]??0,s=0;for(;e+s+1<t.length&&(t[e+s+1]??0)===o+s+1;)s++;n.push(o>>8,o&255,s>>8,s&255),e+=s+1}let i=1+2*Math.max(0,t.length-1);if(n.length<=i)return Uint8Array.from(n);let r=[0];for(let o=1;o<t.length;o++)r.push((t[o]??0)>>8,(t[o]??0)&255);return Uint8Array.from(r)}function Wn(t){let n=[],e=-1,i=0;return t.forEach((r,o)=>{r!==e&&(n.push(o>>8,o&255,r),e=r,i++)}),Uint8Array.from([3,i>>8,i&255,...n,t.length>>8,t.length&255])}function Kn(t,n,e){let i=[],r=[],o=[],s=[],f=0,c=!1,d=()=>{r.length=0,o.length=0,s.length=0},h=(a,u)=>{r.push(i.length),o.push(u.length),s.push(a),i.push(...u)},p=(a,u)=>{if(u>10)return c=!0,!0;let l=0;for(;l<a.length&&!c;){let g=a[l]??0;if(l++,g===28){let m=[28,a[l]??0,a[l+1]??0];h(((a[l]??0)<<8|(a[l+1]??0))<<16>>16,m),l+=2}else if(g>=32&&g<=246)h(g-139,[g]);else if(g>=247&&g<=250)h((g-247)*256+(a[l]??0)+108,[g,a[l]??0]),l++;else if(g>=251&&g<=254)h(-(g-251)*256-(a[l]??0)-108,[g,a[l]??0]),l++;else if(g===255)h(0,[255,a[l]??0,a[l+1]??0,a[l+2]??0,a[l+3]??0]),l+=4;else if(g===10||g===29){let m=g===10?n:e,S=s.pop(),A=r.pop(),w=o.pop();if(S===void 0||A===void 0||w===void 0||A+w!==i.length)return c=!0,!0;let x=m[S+Ie(m.length)];if(x===void 0)return c=!0,!0;if(i.length=A,p(x,u+1))return!0}else{if(g===11)return!1;if(g===14)return i.push(14),!0;if(g===1||g===3||g===18||g===23)f+=s.length>>1,d(),i.push(g);else if(g===19||g===20){f+=s.length>>1,d();let m=f+7>>3;i.push(g,...Array.from(a.subarray(l,l+m))),l+=m}else if(g===12){let m=a[l++]??0;if(m>=34&&m<=37)d(),i.push(12,m);else return c=!0,!0}else d(),i.push(g)}}return!1},b=p(t,0);if(!c)return b||i.push(14),Uint8Array.from(i)}function Vn(t,n,e){let i=new Set,r=!1,o=0,s=[],f=(c,d)=>{if(d>10)return r=!0,!0;let h=0;for(;h<c.length;){let p=c[h]??0;if(h++,p>=32||p===28){p===28?(s.push(((c[h]??0)<<8|(c[h+1]??0))<<16>>16),h+=2):p<=246?s.push(p-139):p<=250?s.push((p-247)*256+(c[h++]??0)+108):p<=254?s.push(-(p-251)*256-(c[h++]??0)-108):(s.push(((c[h]??0)<<24|(c[h+1]??0)<<16|(c[h+2]??0)<<8|(c[h+3]??0))/65536),h+=4);continue}if(p===10||p===29){let b=p===10?n.subrs:e.gsubrs,a=s.pop();if(a===void 0)return r=!0,!0;let u=a+Ie(b.length),l=b[u];if(l===void 0)return r=!0,!0;let g=`${p}:${u}:${o}`;if(!i.has(g)&&(i.add(g),(p===10?e.local:e.global).add(u),f(l,d+1)))return!0;continue}if(p===11)return!1;if(p===14)return!0;if(p===1||p===3||p===18||p===23){o+=s.length>>1,s.length=0;continue}if(p===19||p===20){o+=s.length>>1,s.length=0,h+=o+7>>3;continue}if(p===12){let b=c[h++]??0;if(b>=34&&b<=37)s.length=0;else return r=!0,!0;continue}s.length=0}return!1};f(t,0),r&&(n.subrs.forEach((c,d)=>{e.local.add(d)}),e.gsubrs.forEach((c,d)=>{e.global.add(d)}))}var Oe=32,$e=1,_e=8,je=64,He=128;function Be(t){let n=new DataView(t.buffer,t.byteOffset,t.byteLength);return String.fromCharCode(...t.subarray(0,4))==="ttcf"?n.getUint32(8):1}function Nt(t,n=0){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),i=String.fromCharCode(...t.subarray(0,4))==="ttcf"?e.getUint32(12+n*4):0,r=new Map,o=e.getUint16(i+4);for(let k=0;k<o;k++){let P=i+12+k*16,z=String.fromCharCode(...t.subarray(P,P+4));r.set(z,{offset:e.getUint32(P+8),length:e.getUint32(P+12)})}let s=k=>{let P=r.get(k);if(!P)throw new Error(`font has no ${k} table`);return P},f=s("head").offset,c=e.getUint16(f+18),d=e.getInt16(f+50)===1,h=[e.getInt16(f+36),e.getInt16(f+38),e.getInt16(f+40),e.getInt16(f+42)],p=s("hhea").offset,b=e.getInt16(p+4),a=e.getInt16(p+6),u=e.getUint16(p+34),l=e.getUint16(s("maxp").offset+4),g=s("hmtx").offset,m=r.get("OS/2"),S=m&&e.getUint16(m.offset)>=2?e.getInt16(m.offset+88):Math.round(c*.714),A=Yn(e,s("cmap").offset),w=k=>e.getUint16(g+Math.min(k,u-1)*4),x=k=>k<u?e.getInt16(g+k*4+2):e.getInt16(g+u*4+(k-u)*2),E=k=>{let P=A(k);return P===void 0||P===0||P>=l?void 0:P},T=k=>{let P=s(k);return t.subarray(P.offset,P.offset+P.length)},R=r.get("CFF ");if(R){let k=De(t.subarray(R.offset,R.offset+R.length));return{unitsPerEm:c,ascent:b,descent:a,capHeight:S,bbox:h,outlines:"cff",variable:r.has("fvar"),cidKeyed:k.cidKeyed,glyphOf:E,codeOf:P=>k.codeOf(P),advance:w,subset:P=>({data:k.subset(P)})}}let I=s("loca").offset,D=s("glyf"),K=k=>d?[e.getUint32(I+k*4),e.getUint32(I+k*4+4)]:[e.getUint16(I+k*2)*2,e.getUint16(I+k*2+2)*2],Q=k=>{let[P,z]=K(k);if(z<=P)return[];let U=D.offset+P;if(e.getInt16(U)>=0)return[];let C=[],M=U+10;for(;;){let j=e.getUint16(M);if(C.push(e.getUint16(M+2)),M+=4+(j&$e?4:2),j&_e?M+=2:j&je?M+=4:j&He&&(M+=8),!(j&Oe))break}return C};return{unitsPerEm:c,ascent:b,descent:a,capHeight:S,bbox:h,outlines:"glyf",variable:r.has("fvar"),cidKeyed:!1,glyphOf:E,codeOf:k=>k,advance:w,subset(k){let P=new Set,z=[0,...k];for(let F=z.pop();F!==void 0;F=z.pop())P.has(F)||(P.add(F),z.push(...Q(F)));let U=[...P].sort((F,$)=>F-$),C=new Map(U.map((F,$)=>[F,$])),M=new Uint32Array(U.length+1),j=[],G=0;U.forEach((F,$)=>{M[$]=G;let[lt,ut]=K(F);if(ut>lt){let V=Uint8Array.from(t.subarray(D.offset+lt,D.offset+ut));new DataView(V.buffer).getInt16(0)<0&&Jn(V,C),j.push(V),G+=V.length;let y=(4-G%4)%4;y&&(j.push(new Uint8Array(y)),G+=y)}}),M[U.length]=G;let st=new Uint8Array(G),at=0;for(let F of j)st.set(F,at),at+=F.length;let ft=new Uint8Array((U.length+1)*4),wt=new DataView(ft.buffer);M.forEach((F,$)=>{wt.setUint32($*4,F)});let St=new Uint8Array(U.length*4),H=new DataView(St.buffer);U.forEach((F,$)=>{H.setUint16($*4,w(F)),H.setInt16($*4+2,x(F))});let At=Uint8Array.from(t.subarray(f,f+s("head").length)),kt=new DataView(At.buffer);kt.setUint32(8,0),kt.setInt16(50,1);let Pt=Uint8Array.from(T("hhea"));new DataView(Pt.buffer).setUint16(34,U.length);let ct=Uint8Array.from(T("maxp"));new DataView(ct.buffer).setUint16(4,U.length);let Et=new Uint16Array((U.at(-1)??0)+1);for(let[F,$]of C)Et[F]=$;return{data:qn([["glyf",st],["head",At],["hhea",Pt],["hmtx",St],["loca",ft],["maxp",ct]]),cidToGid:Et}}}}function Jn(t,n){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),i=10;for(;;){let r=e.getUint16(i);if(e.setUint16(i+2,n.get(e.getUint16(i+2))??0),i+=4+(r&$e?4:2),r&_e?i+=2:r&je?i+=4:r&He&&(i+=8),!(r&Oe))break}}function Ce(t,n){let e=0,i=t.length-1,r=-1;for(;e<=i;){let o=e+i>>1;(t[o]??0)<=n?(r=o,e=o+1):i=o-1}return r}function Yn(t,n){let e=t.getUint16(n+2),i;for(let r=0;r<e;r++){let o=t.getUint16(n+4+r*8),s=t.getUint16(n+4+r*8+2),f=n+t.getUint32(n+4+r*8+4),c=t.getUint16(f);if(o===3&&(s===1||s===10)||o===0){if(c===12){let h=t.getUint32(f+12),p=new Uint32Array(h);for(let b=0;b<h;b++)p[b]=t.getUint32(f+16+b*12);return b=>{let a=Ce(p,b);if(a<0)return;let u=t.getUint32(f+16+a*12+4);if(!(b>u))return t.getUint32(f+16+a*12+8)+(b-(p[a]??0))}}if(c===4&&i===void 0){let h=t.getUint16(f+6)/2,p=f+14,b=p+h*2+2,a=b+h*2,u=a+h*2,l=new Uint32Array(h);for(let g=0;g<h;g++)l[g]=t.getUint16(b+g*2);i=g=>{if(g>65535)return;let m=Ce(l,g);if(m<0||g>t.getUint16(p+m*2))return;let S=t.getUint16(u+m*2);if(S===0)return g+t.getInt16(a+m*2)&65535;let A=t.getUint16(u+m*2+S+(g-(l[m]??0))*2);return A===0?void 0:A+t.getInt16(a+m*2)&65535}}}}if(i)return i;throw new Error("font has no Unicode cmap")}function Xn(t){let n=new Uint8Array(Math.ceil(t.length/4)*4);n.set(t);let e=new DataView(n.buffer),i=0;for(let r=0;r<n.length;r+=4)i=i+e.getUint32(r)>>>0;return i}function qn(t){let n=[...t].sort(([c],[d])=>c<d?-1:1),e=12+n.length*16,i=n.reduce((c,[,d])=>c+Math.ceil(d.length/4)*4,e),r=new Uint8Array(i),o=new DataView(r.buffer);o.setUint32(0,65536),o.setUint16(4,n.length);let s=Math.floor(Math.log2(n.length));o.setUint16(6,2**s*16),o.setUint16(8,s),o.setUint16(10,n.length*16-2**s*16);let f=e;return n.forEach(([c,d],h)=>{let p=12+h*16;r.set(new TextEncoder().encode(c),p),o.setUint32(p+4,Xn(d)),o.setUint32(p+8,f),o.setUint32(p+12,d.length),r.set(d,f),f+=Math.ceil(d.length/4)*4}),r}var vt={platform:process.platform,env:process.env,home:rr(),exists:t=>Qn(t),list:t=>{try{return tr(t)}catch{return[]}},run:(t,n)=>new Promise(e=>{Zn(t,n,{timeout:5e3,windowsHide:!0,maxBuffer:4e6},(i,r)=>e(i?void 0:r))}),read:t=>{try{return nr(t).size>1e8?void 0:er(t)}catch{return}}},ir={zh:[["msyh.ttc",0],["simsun.ttc",0],["simhei.ttf",0],["Deng.ttf",0],["arialuni.ttf",0]],"zh-TW":[["msjh.ttc",0],["mingliu.ttc",0],["msyh.ttc",0],["arialuni.ttf",0]],ja:[["YuGothR.ttc",0],["YuGothM.ttc",0],["meiryo.ttc",0],["msgothic.ttc",0],["msmincho.ttc",0],["arialuni.ttf",0]],ko:[["malgun.ttf",0],["gulim.ttc",0],["batang.ttc",0],["arialuni.ttf",0]],arabic:[["segoeui.ttf",0],["arial.ttf",0],["tahoma.ttf",0],["times.ttf",0],["arialuni.ttf",0]],hebrew:[["segoeui.ttf",0],["arial.ttf",0],["tahoma.ttf",0],["times.ttf",0],["arialuni.ttf",0]],thai:[["LeelawUI.ttf",0],["leelawad.ttf",0],["tahoma.ttf",0],["arialuni.ttf",0]],other:[["seguisym.ttf",0],["segoeui.ttf",0],["arial.ttf",0],["arialuni.ttf",0],["malgun.ttf",0],["msyh.ttc",0]]},or={zh:[["PingFang.ttc",0],["STHeiti Light.ttc",1],["Hiragino Sans GB.ttc",0],["Arial Unicode.ttf",0]],"zh-TW":[["PingFang.ttc",2],["STHeiti Light.ttc",0],["Hiragino Sans GB.ttc",0],["Arial Unicode.ttf",0]],ja:[["\u30D2\u30E9\u30AE\u30CE\u89D2\u30B4\u30B7\u30C3\u30AF W3.ttc",0],["Hiragino Sans GB.ttc",0],["AquaKana.ttc",0],["Arial Unicode.ttf",0]],ko:[["AppleSDGothicNeo.ttc",0],["Arial Unicode.ttf",0]],arabic:[["GeezaPro.ttc",0],["SFArabic.ttf",0],["Arial Unicode.ttf",0]],hebrew:[["ArialHB.ttc",0],["Arial Unicode.ttf",0]],thai:[["Thonburi.ttc",0],["Arial Unicode.ttf",0]],other:[["Arial Unicode.ttf",0],["Apple Symbols.ttf",0],["Arial.ttf",0]]},ze={zh:[["NotoSansCJK-Regular.ttc",2],["NotoSansCJKsc-Regular.otf",0],["wqy-zenhei.ttc",0],["wqy-microhei.ttc",0],["DroidSansFallbackFull.ttf",0],["DroidSansFallback.ttf",0]],"zh-TW":[["NotoSansCJK-Regular.ttc",3],["NotoSansCJKtc-Regular.otf",0],["wqy-zenhei.ttc",0],["DroidSansFallbackFull.ttf",0]],ja:[["NotoSansCJK-Regular.ttc",0],["NotoSansCJKjp-Regular.otf",0],["DroidSansFallbackFull.ttf",0],["TakaoGothic.ttf",0]],ko:[["NotoSansCJK-Regular.ttc",1],["NotoSansCJKkr-Regular.otf",0],["NanumGothic.ttf",0],["DroidSansFallbackFull.ttf",0]],arabic:[["NotoSansArabic-Regular.ttf",0],["NotoNaskhArabic-Regular.ttf",0],["DejaVuSans.ttf",0],["FreeSans.ttf",0]],hebrew:[["NotoSansHebrew-Regular.ttf",0],["DejaVuSans.ttf",0],["FreeSans.ttf",0]],thai:[["NotoSansThai-Regular.ttf",0],["Garuda.ttf",0],["Loma.ttf",0],["DejaVuSans.ttf",0]],other:[["DejaVuSans.ttf",0],["NotoSansSymbols-Regular.ttf",0],["NotoSansSymbols2-Regular.ttf",0],["FreeSans.ttf",0],["LiberationSans-Regular.ttf",0]]},sr={zh:"zh-cn","zh-TW":"zh-tw",ja:"ja",ko:"ko",arabic:"ar",hebrew:"he",thai:"th"};function ar(t){return t.script==="han"||t.script==="kana"||t.script==="hangul"?t.script==="kana"?"ja":t.script==="hangul"?"ko":t.lang??"zh":t.script==="arabic"||t.script==="hebrew"||t.script==="thai"?t.script:"other"}var qt=t=>t.platform==="win32"?Ke:Xt;function fr(t){let n=Ke.join,e=t.env.WINDIR??t.env.SystemRoot??"C:\\Windows";return[n(e,"Fonts"),...t.env.LOCALAPPDATA?[n(t.env.LOCALAPPDATA,"Microsoft","Windows","Fonts")]:[]]}function cr(t){let n=Xt.join;return["/System/Library/Fonts","/System/Library/Fonts/Supplemental","/Library/Fonts",n(t.home,"Library","Fonts")]}function lr(t){let n=Xt.join,e=t.env.XDG_DATA_HOME??n(t.home,".local","share");return["/usr/share/fonts","/usr/local/share/fonts","/usr/share/fonts/opentype/noto","/usr/share/fonts/truetype",n(e,"fonts"),n(t.home,".fonts")]}function Ve(t,n,e,i=3){let{join:r}=qt(e),o=e.list(t),s=n.toLowerCase(),f=o.find(c=>c.toLowerCase()===s);if(f)return r(t,f);if(i!==0)for(let c of o){if(c.includes("."))continue;let d=Ve(r(t,c),n,e,i-1);if(d)return d}}async function Ge(t,n){let e=await n.run("fc-match",["-s","-f",`%{file} %{index}
|
|
24
|
+
`,t]);return e===void 0?[]:e.split(`
|
|
25
|
+
`).map(i=>i.split(" ")).filter(([i])=>i!==void 0&&i!=="").slice(0,8).map(([i,r])=>({path:i,index:(Number(r)||0)&65535}))}async function Je(t,n=vt){let e=ar(t),{join:i}=qt(n),r=[],o=f=>{f&&!r.some(c=>c.path===f.path&&c.index===f.index)&&r.push(f)};if(n.platform==="win32"||n.platform==="darwin"){let f=n.platform==="win32"?ir:or,c=n.platform==="win32"?fr(n):cr(n);for(let[d,h]of f[e]??f.other??[])for(let p of c){let b=i(p,d);if(n.exists(b)){o({path:b,index:h});break}}return r}let s=sr[e];if(s)for(let f of await Ge(`:lang=${s}`,n))o(f);else if(t.codePoint!==void 0)for(let f of await Ge(`:charset=${t.codePoint.toString(16)}`,n))o(f);for(let[f,c]of ze[e]??ze.other??[])for(let d of lr(n)){let h=Ve(d,f,n);if(h){o({path:h,index:c});break}}return r}var We=new WeakMap;function Ye(t,n=vt){let e=We.get(n)??new Map;We.set(n,e);let i=`${t.path}#${t.index}`,r=qt(n).basename(t.path).replace(/\.[^.]+$/,""),o=e.get(i);if(o!==void 0)return o===null?void 0:{font:o,ref:t,name:r};try{let s=n.read(t.path);if(!s)throw new Error("unreadable");let f=Nt(s,Math.min(t.index,Math.max(0,Be(s)-1)));return e.set(i,f),{font:f,ref:t,name:r}}catch{e.set(i,null);return}}var Ze=595.28,Mt=841.89,rt=72,mt=Ze-2*rt,Zt=Mt-2*rt,Z={size:11,leading:16,after:8},mr={size:20,leading:26,before:0,after:6},br={size:15,leading:20,before:18,after:6},xr=4,yr=24,L={size:10,leading:14,padX:6,padY:3},wr=12,Ut=.114,Sr=.78,Ar=.95,Xe={regular:"NotoSans-Regular.ttf.gz",bold:"NotoSans-Bold.ttf.gz"};function kr(t){return[bt(t,"fonts"),bt(t,"..","fonts"),bt(t,"..","..","assets","fonts")]}var Lt;function Pr(){if(Lt)return Lt;let t=kr(gr(hr(import.meta.url))).find(e=>ur(bt(e,Xe.regular)));if(t===void 0)throw new Error("the PDF fonts are missing from this install");let n=e=>Nt(pr(dr(bt(t,Xe[e]))));return Lt={regular:n("regular"),bold:n("bold")},Lt}var it=class{constructor(n,e,i,r,o){this.font=n;this.resource=e;this.name=i;this.synthetic=r;this.isBold=o}font;resource;name;synthetic;isBold;used=new Map;widths=new Map;advance(n){let e=this.widths.get(n);return e===void 0&&(e=this.font.advance(n)/this.font.unitsPerEm,this.widths.set(n,e)),e}code(n,e){let i=this.font.codeOf(n);return this.used.has(i)||this.used.set(i,{gid:n,text:e}),i}},te=class{fonts=[];picks=new Map;count=0;missing=new Set;notdef;constructor(n){let e={regular:new it(n.regular,this.next(),"NotoSans-Regular",!1,!1),bold:new it(n.bold,this.next(),"NotoSans-Bold",!1,!0)};this.fonts.push(e),this.notdef=e}next(){return`F${++this.count}`}get primary(){return this.notdef.regular.font}all(){return this.fonts.flatMap(n=>[n.regular,n.bold])}add(n,e){this.fonts.push({regular:new it(e,this.next(),n,!1,!1),bold:new it(e,this.next(),n,!0,!0)}),this.picks.clear()}get fontCount(){return this.fonts.length}has(n){return this.fonts.some(e=>e.regular.font.glyphOf(n)!==void 0)}pick(n,e){let i=this.picks.get(n);if(i===void 0){i=null;for(let o=0;o<this.fonts.length;o++){let s=this.fonts[o]?.regular.font.glyphOf(n);if(s!==void 0){i=[o,s];break}}this.picks.set(n,i)}if(i===null)return this.missing.add(et(n)??"other"),{pf:e?this.notdef.bold:this.notdef.regular,gid:0};let r=this.fonts[i[0]];return{pf:(e?r?.bold:r?.regular)??this.notdef.regular,gid:i[1]}}width(n,e,i){let r=0;for(let o of n){let{pf:s,gid:f}=this.pick(o.codePointAt(0)??0,i);r+=s.advance(f)}return r*e}runs(n,e){let i=[];for(let r of n){let o=r.codePointAt(0)??0,{pf:s,gid:f}=this.pick(o,e),c=f===0?"\uFFFD":o>=64336&&o<=65279?Me(o):r,d=s.code(f,c).toString(16).padStart(4,"0"),h=i.at(-1);h&&h.pf===s?(h.hex+=d,h.width+=s.advance(f)):i.push({pf:s,hex:d,width:s.advance(f)})}return i}},Er=/[\u00AD\u200B\u200E\u200F\u2028\u2029\u202A-\u202E\u2060\u2066-\u2069\uFEFF]/g,Tr=/[\t\u00A0\u2000-\u200A\u202F\u205F\u3000]/g,Rr=/[^\P{Cc}\n]/gu;function Qe(t){return t.replace(Tr," ").replace(Er,"").replace(Rr,"").normalize("NFC")}function Fr(t,n){let e=Qe(t);Ue(e)&&(e=Le(e,n)),e=e.replace(/[\u200C\u200D]/g,"");let i=[];for(let r of e){let o=r.codePointAt(0)??0;if(r===`
|
|
26
|
+
`||n(o)){i.push(r);continue}let s=r.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"");i.push(s!==""&&[...s].every(f=>n(f.codePointAt(0)??0))?s:r)}return i.join("")}var Nr=new Set(["han","kana","hangul"]),vr=new Set([12289,12290,65292,65294,65306,65307,65281,65311,65289,65341,65373,12309,12297,12299,12301,12303,12305,12313,12311,12319,8217,8221,8252,12540,12293,12539,8230,8229,37,12445,12446,12541,12542].map(t=>String.fromCodePoint(t))),Ur=new Set([65288,65339,65371,12308,12296,12298,12300,12302,12304,12312,12310,12317,8216,8220].map(t=>String.fromCodePoint(t)));function Qt(t,n,e,i,r){let o=[],s=f=>n.width(f,i,e);for(let f of t.split(`
|
|
27
|
+
`)){let c="",d=0,h=s(" ");for(let p of f.split(" ").filter(Boolean)){let b=s(p),a=[...p].some(u=>Nr.has(et(u.codePointAt(0)??0)));if(b>r||a&&c!==""&&d+h+b>r){c!==""&&(d+h+s([...p][0]??"")<=r?(c+=" ",d+=h):(o.push(c),c="",d=0));for(let u of p){let l=s(u),g=[...c].at(-1),m=vr.has(u)&&d+l<=r*1.15;d+l>r&&c!==""&&!m&&(g!==void 0&&Ur.has(g)?(o.push([...c].slice(0,-1).join("")),c=g,d=s(g)):(o.push(c),c="",d=0)),c+=u,d+=l}}else c===""?(c=p,d=b):d+h+b<=r?(c+=` ${p}`,d+=h+b):(o.push(c),c=p,d=b)}o.push(c)}return o}var _=t=>(Math.round(t*100)/100).toString(),ee=class{constructor(n){this.chain=n}chain;pages=[];ops=[];y=0;owed=0;get remaining(){return Zt-this.y}get atTop(){return this.y===0}newPage(){this.ops=[`${_(Ut)} g ${_(Ut)} G`],this.pages.push(this.ops),this.y=0,this.owed=0}gap(n){this.y>0&&(this.y+=Math.max(this.owed,n)),this.owed=0}bottom(n){this.owed=n}advance(n){this.y+=n}text(n,e,i,r,o,s,f){if(s==="")return;let{primary:c}=this.chain,d=(c.ascent-c.descent)*e/c.unitsPerEm,h=o+(i-d)/2+c.ascent*e/c.unitsPerEm,p=this.chain.runs(be(s,f),n),b=p.reduce((l,g)=>l+g.width,0)*e,a=rt+(f?r.left+r.width-b:r.left),u=_(Mt-rt-h);for(let l of p){let g=l.pf.synthetic?`2 Tr ${_(e*.035)} w `:"",m=l.pf.synthetic?" 0 Tr":"";this.ops.push(`BT /${l.pf.resource} ${_(e)} Tf ${g}${_(a)} ${u} Td <${l.hex}> Tj${m} ET`),a+=l.width*e}}rect(n,e,i,r,o){let s=`${_(rt+n)} ${_(Mt-rt-e-r)} ${_(i)} ${_(r)} re`;o==="fill"?this.ops.push(`${_(Ar)} g ${s} f ${_(Ut)} g`):this.ops.push(`${_(Sr)} G 0.5 w ${s} S ${_(Ut)} G`)}lines(n,e,i,r,o,s){let f=pt(o),c=s?.indent??0,d={left:f?r.left:r.left+c,width:r.width-c};Qt(o,this.chain,n,e,d.width).forEach((h,p)=>{if(this.remaining<i&&this.newPage(),p===0&&s!==void 0){let b=this.chain.width(s.text,e,n),a=f?{left:r.left+r.width-b,width:b}:{left:d.left-b,width:b};this.text(n,e,i,a,this.y,s.text,!1)}this.text(n,e,i,d,this.y,h,f),this.advance(i)})}heading(n,e){let i=n===1?mr:br,r=Qt(e,this.chain,!0,i.size,mt);this.gap(i.before),this.remaining<r.length*i.leading+i.after+2*Z.leading&&this.newPage(),this.lines(!0,i.size,i.leading,{left:0,width:mt},e),this.bottom(i.after)}paragraph(n){this.gap(0),this.lines(!1,Z.size,Z.leading,{left:0,width:mt},n),this.bottom(Z.after)}list(n,e){this.gap(0),e.forEach((i,r)=>{r>0&&this.advance(xr);let o=n?`${r+1}. `:"\u2022 ";this.lines(!1,Z.size,Z.leading,{left:0,width:mt},i,{text:o,indent:yr})}),this.bottom(Z.after)}table(n){if(n.length===0)return;this.gap(0);let e=Math.max(...n.map(a=>a.length)),i=L.padX*2,r=Array(e).fill(0),o=Array(e).fill(0);for(let[a,u]of n.entries()){let l=a===0;for(let g=0;g<e;g++){let m=u[g]??"";r[g]=Math.max(r[g]??0,this.chain.width(m.replace(/\n/g," "),L.size,l)+i);let S=Math.max(0,...m.split(/\s+/).map(A=>Math.min(this.chain.width(A,L.size,l),L.size*3)));o[g]=Math.max(o[g]??0,S+i)}}let s=Lr(r,o,mt),f=s.map((a,u)=>s.slice(0,u).reduce((l,g)=>l+g,0)),c=a=>s.map((u,l)=>Qt(n[a]?.[l]??"",this.chain,a===0,L.size,u-i)),d=c(0),h=Math.max(...d.map(a=>a.length))*L.leading+2*L.padY,p=(a,u,l,g)=>{let m=g*L.leading+2*L.padY;for(let S=0;S<e;S++){let A=f[S]??0,w=s[S]??0;a===0&&this.rect(A,this.y,w,m,"fill"),this.rect(A,this.y,w,m,"stroke");let x=n[a]?.[S]??"",E=pt(x);(u[S]??[]).slice(l,l+g).forEach((T,R)=>{this.text(a===0,L.size,L.leading,{left:A+L.padX,width:w-i},this.y+L.padY+R*L.leading,T,E)})}this.advance(m)},b=a=>{this.newPage(),a>0&&h<Zt/2&&p(0,d,0,Math.max(...d.map(u=>u.length)))};for(let a=0;a<n.length;a++){let u=a===0?d:c(a),l=Math.max(...u.map(m=>m.length)),g=0;for(;g<l;){let m=Math.floor((this.remaining-2*L.padY)/L.leading),S=(l-g)*L.leading+2*L.padY;if(m<1||m<l-g&&!this.atTop&&S<=Zt-h){b(a);continue}let A=Math.min(l-g,m);p(a,u,g,A),g+=A,g<l&&b(a)}}this.bottom(wr)}};function Lr(t,n,e){let i=t.reduce((s,f)=>s+f,0);if(i<=e)return t.map(s=>s*e/i);let r=n.reduce((s,f)=>s+f,0);if(r>=e)return n.map(s=>s*e/r);let o=(e-r)/(i-r);return t.map((s,f)=>(n[f]??0)+(s-(n[f]??0))*o)}function Mr(t){return t.flatMap(n=>n.flatMap(e=>e.kind==="heading"||e.kind==="paragraph"?[e.text]:e.kind==="list"?e.items:e.rows.flat()))}var qe=8;async function Ir(t,n,e,i){let r=new Map;for(let f of new Set(n)){let c=f.codePointAt(0)??0;if(c<128||f===`
|
|
28
|
+
`||t.has(c)||c>=64336&&c<=65279)continue;let d=et(c)??"other";if(d!=="other"&&d!=="symbols"&&d!=="emoji"&&!Pe.has(d)){t.missing.add(d);continue}r.set(d,[...r.get(d)??[],c])}let o=Jt(n,e),s=0;for(let[f,c]of r){let d=c,h={script:f,lang:o,codePoint:c[0]??0},p=[],b=a=>{let u=d.filter(l=>a.font.glyphOf(l)!==void 0);u.length!==0&&(t.add(a.name,a.font),s++,d=d.filter(l=>!u.includes(l)))};for(let a of await Je(h,i)){if(d.length===0||s>=qe)break;let u=Ye(a,i);u&&(u.font.variable?p.push(u):b(u))}for(let a of p){if(d.length===0||s>=qe)break;b(a)}}}async function ne(t,n){let{PDFDocument:e,PDFName:i,PDFString:r}=await le(),o=new te(Pr()),s=Mr(t).map(Qe).join(`
|
|
29
|
+
`);await Ir(o,s,n.lang,n.fonts??vt);let f=new ee(o),c=l=>Fr(l,g=>o.has(g)),d=l=>{l.kind==="heading"?f.heading(l.level,c(l.text)):l.kind==="paragraph"?f.paragraph(c(l.text)):l.kind==="list"?f.list(l.ordered,l.items.map(c)):f.table(l.rows.map(g=>g.map(c)))};for(let l of t.filter(g=>g.length>0)){f.newPage();for(let g of l)d(g)}f.pages.length===0&&f.newPage();let h=await e.create({updateMetadata:!1});h.setTitle(n.title),h.setProducer("Forge"),h.setCreator("Forge");let{context:p}=h,b=new Map,a=new Map,u=0;for(let l of o.all()){if(l.used.size===0)continue;let g=p.nextRef();b.set(l,g);let{font:m}=l,S=[...l.used.keys()].sort((C,M)=>C-M),A=S.map(C=>l.used.get(C)?.gid??0),w=l.synthetic?a.get(m):void 0,x=1e3/m.unitsPerEm,E=`F${String.fromCharCode(65+(u>>8)%26,65+(u>>4)%26,65+(u>>2)%26,65+u%26,65+u*7%26)}`;u++;let T=`${E}+${l.name.replace(/[^A-Za-z0-9-]/g,"")}`,{data:R,cidToGid:I}=m.subset(A),D=m.outlines==="cff",K=p.register(D?p.flateStream(R,{Subtype:"CIDFontType0C"}):p.flateStream(R,{Length1:R.length})),Q=p.register(p.obj({Type:"FontDescriptor",FontName:T,Flags:4,FontBBox:m.bbox.map(C=>Math.round(C*x)),ItalicAngle:0,Ascent:Math.round(m.ascent*x),Descent:Math.round(m.descent*x),CapHeight:Math.round(m.capHeight*x),StemV:l.isBold?140:80,...D?{FontFile3:K}:{FontFile2:K}})),k=S.flatMap((C,M)=>[C,[Math.round(m.advance(A[M]??0)*x)]]),P=I?p.register(p.flateStream(new Uint8Array(new Uint16Array(Cr(I)).buffer))):void 0,z=p.register(p.obj({Type:"Font",Subtype:D?"CIDFontType0":"CIDFontType2",BaseFont:T,CIDSystemInfo:p.obj({Registry:r.of("Adobe"),Ordering:r.of("Identity"),Supplement:0}),FontDescriptor:Q,DW:0,W:k,...D?{}:{CIDToGIDMap:P??"Identity"}})),U=p.register(p.flateStream(Or(l.used)));p.assign(g,p.obj({Type:"Font",Subtype:"Type0",BaseFont:T,Encoding:"Identity-H",DescendantFonts:[z],ToUnicode:U})),l.synthetic||a.set(m,l)}for(let l of f.pages){let g=h.addPage([Ze,Mt]);for(let[m,S]of b)g.node.setFontDictionary(i.of(m.resource),S);g.node.set(i.of("Contents"),p.register(p.flateStream(l.join(`
|
|
30
|
+
`))))}return o.missing.size>0&&n.onMissing?.([...o.missing].map(Dr)),Buffer.from(await h.save())}var Dr=t=>t==="other"?"symbols":Ee(t);function Cr(t){let n=new Uint16Array(t.length);for(let e=0;e<t.length;e++)n[e]=((t[e]??0)&255)<<8|(t[e]??0)>>8;return n}function Or(t){let n=[...t].sort(([o],[s])=>o-s),e=o=>o.toString(16).padStart(4,"0"),i=o=>[...o].flatMap(s=>{let f=s.codePointAt(0)??65533;if(f<65536)return[e(f)];let c=f-65536;return[e(55296+(c>>10)),e(56320+(c&1023))]}).join(""),r=[];for(let o=0;o<n.length;o+=100){let s=n.slice(o,o+100);r.push(`${s.length} beginbfchar
|
|
31
|
+
${s.map(([f,c])=>`<${e(f)}> <${i(c.text)}>`).join(`
|
|
32
|
+
`)}
|
|
33
|
+
endbfchar`)}return["/CIDInit /ProcessSet findresource begin","12 dict begin","begincmap","/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def","/CMapName /Adobe-Identity-UCS def","/CMapType 2 def",`1 begincodespacerange
|
|
34
|
+
<0000> <FFFF>
|
|
35
|
+
endcodespacerange`,...r,"endcmap","CMapName currentdict /CMap defineresource pop","end","end"].join(`
|
|
36
|
+
`)}var Dt="forge-transcribe",re="forge-transcribe-whisper.mjs",Hr=["darwin","win32","linux"];function Br(t=process.platform,n=["whisper"]){let e=n.includes("whisper")||!n.includes("ffmpeg"),i=n.includes("ffmpeg"),r=[e&&"the whisper extension (forge extensions add whisper, or /extensions)",i&&(t==="darwin"?"ffmpeg (brew install ffmpeg)":t==="win32"?"ffmpeg (winget install ffmpeg)":"ffmpeg on your PATH")].filter(Boolean);return t==="darwin"?`Transcribe on this Mac needs ${r.join(" and ")}.`:t==="win32"?`Transcribe on Windows needs ${r.join(" and ")}.`:t==="linux"?`Transcribe on Linux needs ${r.join(" and ")}.`:"Transcribe needs macOS, Windows or Linux."}function qi(t=process.platform,n=t==="darwin"?"off":"unsupported"){return n==="off"?"Summary and notes need Apple Intelligence, and it is off.":`Summary and notes need Apple Intelligence, which this ${jt(t)} does not have.`}function zr(t){return{apple:[O(t,"helpers",Dt),O(t,"..","helpers",Dt),O(t,"..","..","dist","helpers",Dt)],whisper:[O(t,"helpers",re),O(t,"..","helpers",re),O(t,"..","..","helpers","transcribe",re)]}}function xt(t=process.platform,n=process.env){let e=n.FORGE_TRANSCRIBE_HELPER;if(e!==void 0)return It(e)?e.endsWith(".mjs")?{whisper:e}:{apple:e}:{};if(!Hr.includes(t))return{};let i=zr(rn(jr(import.meta.url))),r=t==="darwin"?i.apple.find(s=>It(s)):void 0,o=i.whisper.find(s=>It(s));return{...r?{apple:r}:{},...o?{whisper:o}:{}}}async function Gr(t){return t.apple!==void 0&&t.whisper===void 0?{path:t.apple,kind:"apple"}:t.apple!==void 0&&await t.appleHears(t.apple).catch(()=>!1)?{path:t.apple,kind:"apple"}:t.whisper===void 0?void 0:{path:t.whisper,kind:"whisper"}}async function yt(t){let{apple:n}=xt();if(n===void 0)return;let e=["status",...t?["--locale",t]:[]];return ot({path:n,kind:"apple"},e,"").catch(()=>{})}var ie;function Wr(){return process.env.FORGE_TRANSCRIBE_HELPER!==void 0&&(ie=void 0),ie??=Gr({...xt(),appleHears:async()=>(await yt())?.speech===!0}),ie}function Kr(t){let{apple:n}=xt();if(n===void 0)throw t();return{path:n,kind:"apple"}}async function Vr(){let t={...process.env,FORGE_HELPER_STOP_ON_EOF:"1"};if(!t.FORGE_FFMPEG){let n=await Ht().catch(()=>{});n&&(t.FORGE_FFMPEG=n.ffmpeg)}if(!t.FORGE_WHISPER_CLI){let n=await ht("whisper");n&&(t.FORGE_WHISPER_CLI=n.entry)}if(!t.FORGE_WHISPER_MODEL){let n=await ht("whisper"),e=n&&O(rn(n.entry),"model.bin");e&&It(e)&&(t.FORGE_WHISPER_MODEL=e)}return t}var Jr=5e3;async function ot(t,n,e,i={}){let{signal:r}=i;if(r?.aborted)throw r.reason??new Error("aborted");let o=t.kind==="whisper",s=o?await Vr():process.env;if(r?.aborted)throw r.reason??new Error("aborted");return new Promise((f,c)=>{let d=/\.[cm]?js$/.test(t.path),[h,p]=d?[process.execPath,[t.path,...n]]:[t.path,n],b=nn(h,p,{stdio:[o?"pipe":"ignore","pipe","ignore"],env:s,windowsHide:!0});b.stdin?.on("error",()=>{});let a,u=!1,l=m=>{u||(u=!0,r?.removeEventListener("abort",g),m())},g=()=>{o&&b.stdin?(b.stdin.end(),setTimeout(()=>b.kill("SIGKILL"),Jr).unref()):b.kill("SIGKILL"),l(()=>c(r?.reason??new Error("aborted")))};r?.addEventListener("abort",g,{once:!0}),_r({input:b.stdout}).on("line",m=>{let S;try{S=JSON.parse(m)}catch{return}"ok"in S?a=S:i.onLine?.(S)}),b.on("error",m=>l(()=>c(gt(e,m)))),b.on("close",()=>l(()=>{if(a===void 0)return c(gt(e,new Error(`${Dt} gave no result`)));if(a.ok===!0)return f(a);c(Yr(String(a.code??""),String(a.message??""),e,n,t.kind))}))})}function Yr(t,n,e,i,r){if(t==="no-sound")return $t(e);if(t==="unreadable")return Tt(e,process.platform,r);if(t==="locale"){let o=i.indexOf("--locale");return ce(o>=0?i[o+1]??"this language":`this ${jt()}'s language`,process.platform,r)}return t==="unsupported"||t==="runtime"?_t(n):gt(e,new Error(`${t}: ${n}`))}var Xr=["whisper","ffmpeg"];async function qr(t={}){let n=xt();if(n.apple===void 0&&n.whisper===void 0)return;let e=await yt(t.locale),r={read:e?.read===!0||await ht("read-text")!==void 0};if(e?.speech===!0)return{speech:!0,hears:"apple",locale:typeof e.locale=="string"?e.locale:null,notes:e.notes==="available"||e.notes==="off"?e.notes:"unsupported",...r};if(n.whisper===void 0)return e===void 0?void 0:{speech:!1,locale:null,notes:"unsupported",...r};let o=["status",...t.locale?["--locale",t.locale]:[]],s=await ot({path:n.whisper,kind:"whisper"},o,""),f=Array.isArray(s.missing)?Xr.filter(c=>s.missing.includes(c)):[];return{speech:s.speech===!0,...s.speech===!0?{hears:"whisper"}:{},locale:typeof s.locale=="string"?s.locale:null,notes:"unsupported",...r,...f.length>0?{missing:f}:{}}}async function Zi(t=process.platform){return t!=="darwin"?!0:(await qr().catch(()=>{}))?.hears!=="apple"}async function Qi(t=process.platform){if(t!=="darwin")return{hears:!1,reads:!1};let n=await yt().catch(()=>{});return{hears:n?.speech===!0,reads:n?.read===!0}}async function on(){let t=await Wr();if(t===void 0)throw _t(Br());return t}var Zr=new Set(["mp4","mov","m4a","mp3","wav","aiff"]);async function sn(t,n){if(t.kind!=="apple")return;let{probe:e}=await import("./registry-4IOXO6DT.js"),i=await e(n).catch(()=>{});if(i===void 0||i.kind!=="media"||Zr.has(i.format))return;let r=await Ht().catch(()=>{});return r?{tools:r}:void 0}async function Qr(t,n,e){let i=await se(O(fe(),"forge-sound-")),r=()=>ae(i,{recursive:!0,force:!0}),o=O(i,"sound.wav");try{return await new Promise((s,f)=>{let c=nn(n,["-nostdin","-v","error","-i",t,"-vn","-ac","1","-ar","16000","-c:a","pcm_s16le",o],{stdio:["ignore","ignore","pipe"],windowsHide:!0}),d="";c.stderr?.setEncoding("utf8").on("data",p=>{d+=p});let h=()=>c.kill("SIGKILL");e?.addEventListener("abort",h,{once:!0}),c.on("error",f),c.on("close",p=>{if(e?.removeEventListener("abort",h),e?.aborted)return f(e.reason??new Error("aborted"));p===0?s():f(gt(t,new Error(`ffmpeg: ${d.trim()}`)))})}),{path:o,cleanup:r}}catch(s){throw await r(),s}}async function to(t){let n=await on(),e=await sn(n,t);if(e){let{probeMedia:r}=await import("./ffmpeg-3CJ6C37W.js"),o=await r(t,e.tools).catch(()=>{});if(o===void 0)throw Tt(t);if(o.audio===void 0)throw $t(t);return{seconds:o.duration}}let i=await ot(n,["probe",t],t);return{seconds:Number(i.seconds)}}async function eo(t,n){let e=await on(),i=await sn(e,t),r=i?await Qr(t,i.tools.ffmpeg,n.signal):void 0;try{return await ti(e,r?.path??t,t,n)}finally{await r?.cleanup()}}async function ti(t,n,e,i){let r=["run",n,...i.locale?["--locale",i.locale]:[],...i.notes?["--notes"]:[],...i.notes&&i.detail&&i.detail!==me?["--detail",i.detail]:[]],o=await ot(t,r,e,{signal:i.signal,onLine:s=>{let f=ei(s);f&&i.onEvent?.(f)}});return{locale:String(o.locale),seconds:Number(o.seconds),segments:o.segments,...o.notes?{notes:o.notes}:{}}}function ei(t){if(t.event==="model")return{kind:"model",fraction:Number(t.fraction)};if(t.event==="heard")return{kind:"heard",seconds:Number(t.seconds),of:Number(t.of)};if(t.event==="notes")return{kind:"notes",part:Number(t.part),of:Number(t.of)}}async function no(t,n={}){if((await yt())?.read!==!0)return ri(t,n);let e=["read",t,...n.language?["--language",n.language]:[]];return(await ot(Kr(Rt),e,t,{signal:n.signal,onLine:r=>{r.event==="page"&&n.onEvent?.({kind:"page",page:Number(r.page),of:Number(r.of)})}})).pages??[]}var ni=200,tn=4e3;async function ro(){return Rt(await an())}async function an(){let{catalogEntry:t,assetFor:n}=await import("./catalog-VPSTQTFD.js"),e=t("read-text");return e!==void 0&&n(e)!==void 0}async function ri(t,n){let e=await ht("read-text");if(e===void 0)throw Rt(await an());let[{probe:i},{openable:r},{loadSharp:o},{runExtension:s}]=await Promise.all([import("./registry-4IOXO6DT.js"),import("./decoded-UNCEUPNW.js"),import("./libs-EK64ACG3.js"),import("./run-HGZVOXRW.js")]),f=await o(),c=await i(t),d=await se(O(fe(),"forge-read-")),h={width:tn,height:tn,fit:"inside",withoutEnlargement:!0};try{let p=[];if(c.kind==="document"&&c.format==="pdf"){let{openPdf:m}=await import("./pdfium-WFGSET5S.js"),S=await m(await oe(t));try{for(let A=0;A<c.pages;A++){let w=await S.getPage(A).render({scale:ni/72,render:"bitmap"}),x=O(d,`page-${A+1}.png`);await f(Buffer.from(w.data),{raw:{width:w.width,height:w.height,channels:4}}).flatten({background:"#ffffff"}).resize(h).png().toFile(x),p.push(x)}}finally{S.destroy()}}else if(c.kind==="image"){let m=await r(t,c.format);try{let S=O(d,"page-1.png");await f(m.path).rotate().flatten({background:"#ffffff"}).resize(h).png().toFile(S),p.push(S)}finally{await m.cleanup()}}else throw Tt(t);let a=(await s({id:"read-text",entry:e.entry,kind:e.kind},p.flatMap(m=>["--in",m]),{subject:t,what:`Reading the text of ${t}`,...n.signal?{signal:n.signal}:{},onLine:m=>{m.event==="page"&&n.onEvent?.({kind:"page",page:Number(m.page),of:Number(m.of)})}})).pages??[];if(!(c.kind==="document"&&c.format==="pdf"))return a;let[{extractPdfText:u},{mendPage:l}]=await Promise.all([import("./pdfium-WFGSET5S.js"),import("./text-layer-LHZNDMPZ.js")]),g=await u(await oe(t)).catch(()=>[]);return a.map((m,S)=>l(m,g[S]??""))}finally{await ae(d,{recursive:!0,force:!0})}}async function fn(){let{apple:t}=xt();if(!(t===void 0||await yt()===void 0))return{path:t,kind:"apple"}}async function cn(t,n,e,i){let r=await se(O(fe(),"forge-render-"));try{let o=O(r,"transcript.html"),s=O(r,`transcript.${e}`);return await $r(o,n,"utf8"),await ot(t,["render",o,s,"--as",e],s,{signal:i.signal}),await oe(s)}finally{await ae(r,{recursive:!0,force:!0})}}var en=9026;async function ln(t,n){let e=await ue(),{Document:i,Packer:r,Paragraph:o,TextRun:s,Table:f,TableRow:c,TableCell:d,HeadingLevel:h}=e,p="forge-numbers",b=0,a=(A,w=!1)=>Te(A,n).map(x=>new s({text:x.text,...w?{bold:!0}:{},...x.kind==="eastAsia"?{font:{hint:"eastAsia"},language:x.lang?{eastAsia:x.lang}:{}}:{},...x.kind==="complex"?{font:{hint:"cs"},...x.rtl?{rightToLeft:!0}:{},...w?{boldComplexScript:!0}:{},...x.lang?{language:{bidirectional:x.lang}}:{}}:{}})),u=A=>pt(A)?{bidirectional:!0}:{},l=A=>A.flatMap(w=>{if(w.kind==="heading")return[new o({children:a(w.text),heading:w.level===1?h.HEADING_1:h.HEADING_2,...u(w.text)})];if(w.kind==="paragraph")return[new o({children:a(w.text),spacing:{after:160},...u(w.text)})];if(w.kind==="list"){let E=++b;return w.items.map(T=>w.ordered?new o({children:a(T),numbering:{reference:p,level:0,instance:E},...u(T)}):new o({children:a(T),bullet:{level:0},...u(T)}))}let x=w.rows[0]?.length??1;return[new f({width:{size:100,type:e.WidthType.PERCENTAGE},columnWidths:Array(x).fill(Math.floor(en/x)),margins:{top:40,bottom:40,left:100,right:100},rows:w.rows.map((E,T)=>new c({tableHeader:T===0,children:E.map(R=>new d({width:{size:Math.floor(en/x),type:e.WidthType.DXA},children:[new o({children:a(R,T===0),...u(R)})]}))}))}),new o({text:""})]}),m=t.filter(A=>A.length>0).flatMap((A,w)=>[...w>0?[new o({children:[new e.PageBreak]})]:[],...l(A)]),S=new i({numbering:{config:[{reference:p,levels:[{level:0,format:e.LevelFormat.DECIMAL,text:"%1.",alignment:e.AlignmentType.START}]}]},sections:[{children:m}]});return r.toBuffer(S)}var un=t=>({...t.lang!==void 0?{lang:t.lang}:{},...t.onMissing!==void 0?{onMissing:t.onMissing}:{}});async function io(t,n,e,i={}){if(n==="md")return Buffer.from(Se(t),"utf8");if(n==="txt")return Buffer.from(Ae(t),"utf8");if(n==="docx")return ln(t,i.lang);let r=await fn();return r?cn(r,ke(t,e),"pdf",i):ne(t,{title:e,...un(i)})}function ii(t){for(let n of t.flat())if(n.kind==="heading"&&n.level===1)return n.text;return"Transcript"}async function oo(t,n,e={}){if(n==="md")return Buffer.from(t,"utf8");if(n==="txt")return Buffer.from(de(t),"utf8");let i=await fn();if(i)return cn(i,pe(t),n,e);let r=he(t);return n==="docx"?ln(r,e.lang):ne(r,{title:ii(r),...un(e)})}export{fi as a,ci as b,Ae as c,ke as d,Br as e,qi as f,zr as g,xt as h,Gr as i,qr as j,Zi as k,Qi as l,to as m,eo as n,no as o,ro as p,io as q,oo as r};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
3
|
+
import{c as i,e as s,f as o}from"./chunk-N6RCLJE6.js";import{H as n}from"./chunk-WIPP5TWQ.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};
|