forge-terminal 0.6.0 → 0.7.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.
Files changed (121) hide show
  1. package/README.md +38 -7
  2. package/dist/chunks/{about-credits-XL2AIGQ7.js → about-credits-PWTKZG3Y.js} +1 -1
  3. package/dist/chunks/args-RHIBM3R3.js +3 -0
  4. package/dist/chunks/{available-TNMISSBA.js → available-FPBRQ3LS.js} +1 -1
  5. package/dist/chunks/{boot-QRKC4QBA.js → boot-PHDTJAFT.js} +1 -1
  6. package/dist/chunks/{catalog-FMHWWMUX.js → catalog-G44MXIAF.js} +1 -1
  7. package/dist/chunks/{check-HOITNMJX.js → check-BFHBPCGW.js} +1 -1
  8. package/dist/chunks/{chunk-EIPMQFIF.js → chunk-2YU4EI24.js} +1 -1
  9. package/dist/chunks/chunk-3IAJTXYM.js +3 -0
  10. package/dist/chunks/{chunk-ECA4PW5T.js → chunk-3OCPO5V6.js} +1 -1
  11. package/dist/chunks/chunk-42IEPG2K.js +3 -0
  12. package/dist/chunks/{chunk-BYUOU2Q2.js → chunk-4AL5QJLM.js} +1 -1
  13. package/dist/chunks/{chunk-UUTBDIFR.js → chunk-56B3VZCM.js} +1 -1
  14. package/dist/chunks/{chunk-QIMSNTKL.js → chunk-56QHX7QR.js} +1 -1
  15. package/dist/chunks/{chunk-HXKLYK3M.js → chunk-6NCN7OJ5.js} +1 -1
  16. package/dist/chunks/{chunk-YBA6DJQ4.js → chunk-6PUV4HSU.js} +1 -1
  17. package/dist/chunks/{chunk-2OSM4W4D.js → chunk-72UR37EG.js} +1 -1
  18. package/dist/chunks/{chunk-3IX3QA76.js → chunk-7NP76V4U.js} +1 -1
  19. package/dist/chunks/{chunk-5FJT4BNY.js → chunk-AETM2PCZ.js} +1 -1
  20. package/dist/chunks/{chunk-GIG4I2IC.js → chunk-BQV3DSUZ.js} +2 -2
  21. package/dist/chunks/chunk-DC2DHMXO.js +3 -0
  22. package/dist/chunks/{chunk-6HUYBVQA.js → chunk-DKHBJ52G.js} +1 -1
  23. package/dist/chunks/chunk-E5VPEBUQ.js +3 -0
  24. package/dist/chunks/chunk-F4TUCI6D.js +3 -0
  25. package/dist/chunks/{chunk-MF3KKEFB.js → chunk-FEJSM3E4.js} +1 -1
  26. package/dist/chunks/{chunk-JUA63KQK.js → chunk-G2V33TMN.js} +1 -1
  27. package/dist/chunks/{chunk-FXA45V4B.js → chunk-G4M2XYFJ.js} +1 -1
  28. package/dist/chunks/{chunk-WID72ZII.js → chunk-H332YFSO.js} +1 -1
  29. package/dist/chunks/chunk-HAOKWLD3.js +4 -0
  30. package/dist/chunks/{chunk-S7BZPV5T.js → chunk-I3C3SRF2.js} +1 -1
  31. package/dist/chunks/{chunk-NUTTDNTG.js → chunk-ID4GJZJ6.js} +1 -1
  32. package/dist/chunks/{chunk-X4QI2EYV.js → chunk-ID75X37Z.js} +1 -1
  33. package/dist/chunks/{chunk-FWVE3GNA.js → chunk-JPASVE56.js} +1 -1
  34. package/dist/chunks/{chunk-UN5DSJE2.js → chunk-JZM37DG2.js} +1 -1
  35. package/dist/chunks/{chunk-G6L5NIJ5.js → chunk-KPUKMAYK.js} +1 -1
  36. package/dist/chunks/{chunk-UEAZTRTL.js → chunk-M7HB4L6L.js} +1 -1
  37. package/dist/chunks/{chunk-NLM2SP3F.js → chunk-OK56WDPA.js} +1 -1
  38. package/dist/chunks/{chunk-I25E2XDH.js → chunk-OLKPV4WO.js} +1 -1
  39. package/dist/chunks/chunk-OPDC577C.js +3 -0
  40. package/dist/chunks/chunk-OQ6DTE56.js +3 -0
  41. package/dist/chunks/chunk-PNPAHKJR.js +3 -0
  42. package/dist/chunks/{chunk-3HG7RXC2.js → chunk-PXCEMDOY.js} +2 -2
  43. package/dist/chunks/{chunk-YJZEHJ6U.js → chunk-QMNERJL2.js} +1 -1
  44. package/dist/chunks/{chunk-TNIPRV6K.js → chunk-R6QVLPGC.js} +1 -1
  45. package/dist/chunks/{chunk-65Y7YCZZ.js → chunk-S44LAUHZ.js} +1 -1
  46. package/dist/chunks/{chunk-YYZYZWF5.js → chunk-SCJ2QXZF.js} +22 -22
  47. package/dist/chunks/{chunk-QO4JUY6B.js → chunk-SJIDFYPT.js} +1 -1
  48. package/dist/chunks/{chunk-PISCJKIG.js → chunk-TQEGSODD.js} +1 -1
  49. package/dist/chunks/chunk-ULX4ZD2Y.js +3 -0
  50. package/dist/chunks/{chunk-BWJNZT75.js → chunk-W6QOV4RP.js} +1 -1
  51. package/dist/chunks/chunk-WWWWXOM4.js +3 -0
  52. package/dist/chunks/{chunk-2JU3YZQU.js → chunk-XIR3VWQY.js} +1 -1
  53. package/dist/chunks/chunk-XUJLUOGD.js +6 -0
  54. package/dist/chunks/chunk-Y3DMALHT.js +66 -0
  55. package/dist/chunks/chunk-YXV3PYVI.js +3 -0
  56. package/dist/chunks/{chunk-QPUKPSPZ.js → chunk-Z3PQ5TMU.js} +1 -1
  57. package/dist/chunks/chunk-ZL7E7PZN.js +4 -0
  58. package/dist/chunks/clip-command-6Q7BTXR5.js +3 -0
  59. package/dist/chunks/{clipboard-W67Q22JG.js → clipboard-QWNPA3GM.js} +1 -1
  60. package/dist/chunks/colour-7HPH6KTY.js +3 -0
  61. package/dist/chunks/{command-ZX3L5VFO.js → command-JTK4IOS7.js} +1 -1
  62. package/dist/chunks/{config-command-VEGQPXVB.js → config-command-DIQTU7DM.js} +1 -1
  63. package/dist/chunks/{continue-editing-LTMIEFRD.js → continue-editing-FTUY6UFG.js} +1 -1
  64. package/dist/chunks/{decoded-SK6W44WW.js → decoded-IXLPWTGZ.js} +1 -1
  65. package/dist/chunks/{entry-3R2GK3IW.js → entry-ZF7D32ZI.js} +2 -2
  66. package/dist/chunks/execute-RP7ZMWLZ.js +3 -0
  67. package/dist/chunks/extensions-YOZ4IF4E.js +3 -0
  68. package/dist/chunks/{extensions-command-RNAPQYWV.js → extensions-command-O7UHUJ3Y.js} +1 -1
  69. package/dist/chunks/{ffmpeg-G4TRWUTV.js → ffmpeg-2ZP3GXJX.js} +1 -1
  70. package/dist/chunks/{image-67XO45NW.js → image-6A7FXKIR.js} +1 -1
  71. package/dist/chunks/{install-X7EEH5CQ.js → install-4L7JGP3X.js} +1 -1
  72. package/dist/chunks/{install-UN3YGSJW.js → install-XJAPLIH2.js} +1 -1
  73. package/dist/chunks/launch-2KSJ4GGN.js +18 -0
  74. package/dist/chunks/link-inputs-GTEW6ZH4.js +3 -0
  75. package/dist/chunks/{lock-5ZO5PCZP.js → lock-KNR7XS7Q.js} +1 -1
  76. package/dist/chunks/manager-YH5XAMZA.js +4 -0
  77. package/dist/chunks/{needed-7IUPDEJB.js → needed-TB3OC76N.js} +1 -1
  78. package/dist/chunks/{own-5BD5BVE7.js → own-KUGTZ3BV.js} +1 -1
  79. package/dist/chunks/{paths-6OENILJ4.js → paths-BBUKTDDP.js} +1 -1
  80. package/dist/chunks/pdfium-MJ65YOXW.js +3 -0
  81. package/dist/chunks/{preferences-E2CH2YSG.js → preferences-7S7YZOFK.js} +1 -1
  82. package/dist/chunks/preset-command-KMKR6KMG.js +3 -0
  83. package/dist/chunks/registry-657JRJR5.js +3 -0
  84. package/dist/chunks/{run-3DX3SROY.js → run-VJDF5WRF.js} +1 -1
  85. package/dist/chunks/{server-TF32DQEO.js → server-6PH2DSFW.js} +20 -20
  86. package/dist/chunks/{signals-QSXY3F2A.js → signals-VY2XE3LV.js} +1 -1
  87. package/dist/chunks/{theme-4Y66DDAO.js → theme-FVQOSLPB.js} +1 -1
  88. package/dist/chunks/{transcribe-HH5P3PV4.js → transcribe-FUN2SKRN.js} +1 -1
  89. package/dist/chunks/transcribe-command-KNSUHROE.js +3 -0
  90. package/dist/chunks/{update-command-6VVDG75Y.js → update-command-X4OSYETA.js} +1 -1
  91. package/dist/chunks/{update-note-XV2T2NNG.js → update-note-LV7G4CHE.js} +1 -1
  92. package/dist/chunks/video-link-CF7GUA6V.js +3 -0
  93. package/dist/chunks/watch-command-3C4AWM7A.js +3 -0
  94. package/dist/index.js +7 -7
  95. package/package.json +9 -13
  96. package/skills/forge/SKILL.md +7 -3
  97. package/dist/chunks/args-PS5SVBZY.js +0 -3
  98. package/dist/chunks/chunk-2L66A2X6.js +0 -3
  99. package/dist/chunks/chunk-3SVHRKQH.js +0 -6
  100. package/dist/chunks/chunk-4MZV4SRU.js +0 -4
  101. package/dist/chunks/chunk-4NDZTK22.js +0 -3
  102. package/dist/chunks/chunk-5XJCMMCM.js +0 -3
  103. package/dist/chunks/chunk-CCNRNCRU.js +0 -3
  104. package/dist/chunks/chunk-EEQSUBBL.js +0 -3
  105. package/dist/chunks/chunk-EJWTYDBJ.js +0 -3
  106. package/dist/chunks/chunk-JD3RB6IV.js +0 -66
  107. package/dist/chunks/chunk-NMGQGYVM.js +0 -3
  108. package/dist/chunks/chunk-SFN3LBB6.js +0 -3
  109. package/dist/chunks/chunk-UI4EUC3S.js +0 -3
  110. package/dist/chunks/chunk-X2YUHPOU.js +0 -4
  111. package/dist/chunks/clip-command-4ON3Q57W.js +0 -3
  112. package/dist/chunks/colour-2BGK2BFR.js +0 -3
  113. package/dist/chunks/execute-TC3QZ6GL.js +0 -3
  114. package/dist/chunks/extensions-3SG2LW7R.js +0 -3
  115. package/dist/chunks/launch-EGFNGHLN.js +0 -18
  116. package/dist/chunks/manager-272REVNF.js +0 -4
  117. package/dist/chunks/pdfium-MHPBLZY5.js +0 -3
  118. package/dist/chunks/preset-command-5I3NZ2OP.js +0 -3
  119. package/dist/chunks/registry-DWFV4GBG.js +0 -3
  120. package/dist/chunks/transcribe-command-VY5HYNXV.js +0 -3
  121. package/dist/chunks/watch-command-BMSMGIHK.js +0 -3
package/README.md CHANGED
@@ -50,7 +50,7 @@ That puts `forge` on your `PATH`, so it works from any directory. Verify:
50
50
 
51
51
  ```bash
52
52
  forge --version
53
- # 0.6.0
53
+ # 0.7.0
54
54
 
55
55
  forge photo.jpg --to webp
56
56
  ```
@@ -198,8 +198,8 @@ forge transcribe "https://www.youtube.com/watch?v=..." --language en
198
198
  transcript.
199
199
  - On Windows the upstream whisper.cpp build needs the Microsoft Visual C++
200
200
  Redistributable; if it is missing, Forge says so and links it.
201
- - YouTube links need yt-dlp: `forge extensions add yt-dlp` installs upstream's
202
- own build on every OS (and updates it when YouTube breaks it). A yt-dlp of
201
+ - Video links need yt-dlp: `forge extensions add yt-dlp` installs upstream's
202
+ own build on every OS (and updates it when a site breaks it). A yt-dlp of
203
203
  your own on PATH also works; Forge never updates that one.
204
204
  - Overrides: `FORGE_WHISPER_CLI`, `FORGE_FFMPEG`, `FORGE_WHISPER_MODEL` (any
205
205
  ggml `.bin`, e.g. a larger model for accuracy).
@@ -357,6 +357,37 @@ so — and it encodes a candidate to find out rather than guessing:
357
357
  ↵ convert another · c convert to WebP · o open · s show in finder · ctrl-c close app
358
358
  ```
359
359
 
360
+ ## Video links
361
+
362
+ Paste a video's link on home — YouTube, Instagram, TikTok, X, Vimeo, Reddit
363
+ or any of the sites yt-dlp reads — and it becomes the video, as if you had
364
+ dropped the file. Its card shows the site, the title and who posted it.
365
+
366
+ - **Edit → Download** saves it as the site sent it, named after its title.
367
+ Download is the first row in edit, and only for a link.
368
+ - **Convert, compress, edit and transcribe** work on it as on any video:
369
+ a GIF, a smaller copy for WhatsApp, a clip, its notes. Only the result is
370
+ saved.
371
+ - It downloads while you choose. If it is not in yet when you confirm,
372
+ Working says "Downloading", in real bytes, then carries on.
373
+ - The first link needs yt-dlp, and ffmpeg to join the picture and the sound;
374
+ your own copies count. Forge offers both in the field, in one install.
375
+ - A site that wants you signed in (Instagram, mostly) can borrow your
376
+ browser's sign-in. Forge offers your default browser's, once, and remembers
377
+ it for that site. Safari's needs Full Disk Access for your terminal: Forge
378
+ opens that setting.
379
+ - One video per link: playlists, and posts with several videos, are refused.
380
+
381
+ On the command line a link goes anywhere a file goes; a link alone downloads
382
+ it. Results go to the current folder unless `-o` says:
383
+
384
+ ```bash
385
+ forge 'https://www.instagram.com/reel/…' # download it, under its title
386
+ forge 'https://www.tiktok.com/@…/video/…' --to gif # a GIF of it
387
+ forge compress 'https://youtu.be/…' --max-size 25mb # small enough for Discord
388
+ forge 'https://…' --cookies-from-browser chrome # a site that wants you signed in
389
+ ```
390
+
360
391
  ## The clipboard
361
392
 
362
393
  On a Mac, a copied image can be the file. Copy a screenshot (⌃⇧⌘4) or an
@@ -484,7 +515,7 @@ forge extensions add boost # about 15 MB on Apple silicon, 16 MB on
484
515
  forge extensions add remove-background # 32 KB on a Mac (Apple Vision); 46 to 52 MB on Windows and Linux
485
516
  forge extensions add heic # about 0.5 MB; Windows and Linux
486
517
  forge extensions add whisper # transcribe where Apple's recogniser is not (see above)
487
- forge extensions add yt-dlp # YouTube links for transcribe, every OS
518
+ forge extensions add yt-dlp # video links, every OS
488
519
  forge extensions add video # Forge's own ffmpeg, 25 MB; Apple-silicon Macs
489
520
  forge extensions remove boost
490
521
  ```
@@ -1103,7 +1134,7 @@ Eleven tools, deliberately few:
1103
1134
  | `forge_palette` | an image's main colours with their shares; `inside` gives one colour's shades; `svg` returns the card, `copy` puts it on the clipboard |
1104
1135
  | `forge_scale` | a 50–950 tonal scale with the colour at 500, rated for white and black text; the colour as hex, `rgb()`, `hsl()`, `oklch()` or a name; `svg` returns the card, `copy` puts it on the clipboard |
1105
1136
  | `forge_card` | named colours (`title`, `colours: [{ name, colour }]`, optional `subtitle` and `theme`) drawn as the SVG swatch card, or with `copy: true` put straight on the clipboard; paste into Figma for one layer per colour |
1106
- | `forge_transcribe` | a video or sound file, or a YouTube link, into notes and a transcript (`to`, `detail`, `language`, `format`, `output`, `overwrite`); writes the file and returns its text |
1137
+ | `forge_transcribe` | a video or sound file, or a video link, into notes and a transcript (`to`, `detail`, `language`, `format`, `output`, `overwrite`); writes the file and returns its text |
1107
1138
  | `forge_read_text` | the text in a picture, screenshot, scan or PDF (`language`, `format`, `output`, `overwrite`); writes the file and returns its text |
1108
1139
 
1109
1140
  Paths must be absolute. Results come back as structured content in the
@@ -1147,7 +1178,7 @@ photo.png · PNG · 122 KB · 2756×774
1147
1178
  With `--json`:
1148
1179
 
1149
1180
  ```json
1150
- {"forge":"0.6.0","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
1181
+ {"forge":"0.7.0","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
1151
1182
  ```
1152
1183
 
1153
1184
  `targets` and `actions` come from the engines' own capabilities, so they are
@@ -1173,7 +1204,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
1173
1204
 
1174
1205
  ```jsonc
1175
1206
  {
1176
- "forge": "0.6.0",
1207
+ "forge": "0.7.0",
1177
1208
  "ok": false,
1178
1209
  "results": [
1179
1210
  {
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
3
  import"./chunk-TMUK2DD3.js";import{readFile as x}from"node:fs/promises";import{dirname as m,join as u}from"node:path";import{fileURLToPath as C}from"node:url";var c=[{name:"sharp \xB7 libvips",licence:"Apache-2.0 \xB7 LGPL-3.0",does:"images",packages:["sharp"]},{name:"PDFium",licence:"BSD-3-Clause",does:"PDF pages",packages:[]},{name:"pdf-lib",licence:"MIT",does:"writing PDFs",packages:["pdf-lib"]},{name:"mammoth \xB7 docx",licence:"BSD-2-Clause \xB7 MIT",does:"Word documents",packages:["mammoth","docx"]},{name:"Ink \xB7 React",licence:"MIT",does:"this screen",packages:["ink","react"]}],g=[{name:"@hyzyla/pdfium",licence:"MIT"}],h=[{name:"Noto Sans",licence:"OFL-1.1"},{name:"xkcd colour survey",licence:"CC0-1.0"}];function l(n){let t=[];for(let e of n.split(`
4
- `)){let i=/^((?:@[^/\s]+\/)?[^@\s]+)@\S+ — (.+)$/.exec(e);i&&t.push({name:i[1],licence:i[2].replace(/^\((.*)\)$/,"$1")})}return t}var d=n=>n.name.replace(/^@/,"");function p({bundled:n,extensions:t}){let e=new Set(c.flatMap(s=>s.packages)),i=[...n.filter(s=>!e.has(s.name)),...g,...h].sort((s,r)=>d(s).localeCompare(d(r)));return[{title:"App",credits:c.map(({packages:s,...r})=>r)},...t.length>0?[{title:"Extensions",credits:t}]:[],{title:"Others",credits:i}]}var f="third-party-licenses.txt";function y(n){let t=[],e=m(n);for(let i=0;i<4;i++)t.push(u(e,f),u(e,"dist",f)),e=m(e);return t}async function k(n){for(let t of y(C(n))){let e=await x(t,"utf8").catch(()=>{});if(e!==void 0)return{path:t,text:e}}}async function F({from:n=import.meta.url,list:t=async()=>(await import("./manager-272REVNF.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-3SG2LW7R.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{F as loadCredits};
4
+ `)){let i=/^((?:@[^/\s]+\/)?[^@\s]+)@\S+ — (.+)$/.exec(e);i&&t.push({name:i[1],licence:i[2].replace(/^\((.*)\)$/,"$1")})}return t}var d=n=>n.name.replace(/^@/,"");function p({bundled:n,extensions:t}){let e=new Set(c.flatMap(s=>s.packages)),i=[...n.filter(s=>!e.has(s.name)),...g,...h].sort((s,r)=>d(s).localeCompare(d(r)));return[{title:"App",credits:c.map(({packages:s,...r})=>r)},...t.length>0?[{title:"Extensions",credits:t}]:[],{title:"Others",credits:i}]}var f="third-party-licenses.txt";function y(n){let t=[],e=m(n);for(let i=0;i<4;i++)t.push(u(e,f),u(e,"dist",f)),e=m(e);return t}async function k(n){for(let t of y(C(n))){let e=await x(t,"utf8").catch(()=>{});if(e!==void 0)return{path:t,text:e}}}async function F({from:n=import.meta.url,list:t=async()=>(await import("./manager-YH5XAMZA.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-YOZ4IF4E.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{F as loadCredits};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{a,b,c,d,e,f,g}from"./chunk-SCJ2QXZF.js";import"./chunk-EYOO35US.js";import"./chunk-72UR37EG.js";import"./chunk-Z3PQ5TMU.js";import"./chunk-TQEGSODD.js";import"./chunk-ULX4ZD2Y.js";import"./chunk-HZDYZ5RD.js";import"./chunk-BSFBZBAI.js";import"./chunk-W6QOV4RP.js";import"./chunk-H332YFSO.js";import"./chunk-7NP76V4U.js";import"./chunk-OQ6DTE56.js";import"./chunk-DC2DHMXO.js";import"./chunk-PON65UTS.js";import"./chunk-JPASVE56.js";import"./chunk-SJIDFYPT.js";import"./chunk-JZM37DG2.js";import"./chunk-DKHBJ52G.js";import"./chunk-KXKQDFHX.js";import"./chunk-ZL7E7PZN.js";import"./chunk-4AL5QJLM.js";import"./chunk-NUCGWLOY.js";import"./chunk-I2LPGKUU.js";import"./chunk-HON4OV7M.js";import"./chunk-PNPAHKJR.js";import"./chunk-FGR6QCG5.js";import"./chunk-VLVNA4T3.js";import"./chunk-TMUK2DD3.js";export{b as COMMANDS_HELP,a as EXIT_CODES_HELP,d as colourUsage,c as commandsHelp,g as parseArgs,e as subcommandHelp,f as wantsJson};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as t}from"./chunk-MF3KKEFB.js";import{a as i}from"./chunk-I25E2XDH.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
3
+ import{c as t}from"./chunk-FEJSM3E4.js";import{a as i}from"./chunk-OLKPV4WO.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";async function l(){let e=await Promise.all(i.map(async n=>await t(n.id)?n.id:null));return new Set(e.filter(n=>n!==null))}export{l as installedExtensionIds};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{s as a}from"./chunk-WID72ZII.js";import{e as l}from"./chunk-4MZV4SRU.js";import"./chunk-BYUOU2Q2.js";import"./chunk-NUCGWLOY.js";import"./chunk-I2LPGKUU.js";import"./chunk-HON4OV7M.js";import"./chunk-CCNRNCRU.js";import"./chunk-FGR6QCG5.js";import"./chunk-VLVNA4T3.js";import"./chunk-TMUK2DD3.js";var c={loadPreferences:l,loadShell:()=>import("./launch-EGFNGHLN.js")};async function f(e=c,n={}){let t=e.loadShell();t.catch(()=>{});let{prefs:o,warning:r}=await e.loadPreferences(),s=a(o.theme),{launchShell:i}=await t;await i({prefs:o,palette:s,...r===void 0?{}:{warning:r},...n})}export{f as bootShell};
3
+ import{s as a}from"./chunk-H332YFSO.js";import{e as l}from"./chunk-ZL7E7PZN.js";import"./chunk-4AL5QJLM.js";import"./chunk-NUCGWLOY.js";import"./chunk-I2LPGKUU.js";import"./chunk-HON4OV7M.js";import"./chunk-PNPAHKJR.js";import"./chunk-FGR6QCG5.js";import"./chunk-VLVNA4T3.js";import"./chunk-TMUK2DD3.js";var c={loadPreferences:l,loadShell:()=>import("./launch-2KSJ4GGN.js")};async function f(e=c,n={}){let t=e.loadShell();t.catch(()=>{});let{prefs:o,warning:r}=await e.loadPreferences(),s=a(o.theme),{launchShell:i}=await t;await i({prefs:o,palette:s,...r===void 0?{}:{warning:r},...n})}export{f as bootShell};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a,b,c,d,e,f,g,h}from"./chunk-I25E2XDH.js";import"./chunk-TMUK2DD3.js";export{a as CATALOG,d as EXTENSION_PLATFORMS,f as assetFor,e as catalogEntry,b as machineName,h as offeredHere,g as offeredOn,c as osName};
3
+ import{a,b,c,d,e,f,g,h}from"./chunk-OLKPV4WO.js";import"./chunk-TMUK2DD3.js";export{a as CATALOG,d as EXTENSION_PLATFORMS,f as assetFor,e as catalogEntry,b as machineName,h as offeredHere,g as offeredOn,c as osName};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-UEAZTRTL.js";import"./chunk-4MZV4SRU.js";import"./chunk-BYUOU2Q2.js";import"./chunk-NUCGWLOY.js";import"./chunk-I2LPGKUU.js";import"./chunk-HON4OV7M.js";import"./chunk-CCNRNCRU.js";import"./chunk-FGR6QCG5.js";import"./chunk-VLVNA4T3.js";import"./chunk-TMUK2DD3.js";export{b as CHECK_EVERY_MS,e as MAX_NOTES,g as NOTE_TEXT,f as NOTE_TITLE,a as REGISTRY_URL,o as availableUpdate,h as cachePath,m as checkNow,l as fetchLatest,c as isNewer,k as isStale,i as readCache,d as updateChecksEnabled,n as whatsNewFor,j as writeCache};
3
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-M7HB4L6L.js";import"./chunk-ZL7E7PZN.js";import"./chunk-4AL5QJLM.js";import"./chunk-NUCGWLOY.js";import"./chunk-I2LPGKUU.js";import"./chunk-HON4OV7M.js";import"./chunk-PNPAHKJR.js";import"./chunk-FGR6QCG5.js";import"./chunk-VLVNA4T3.js";import"./chunk-TMUK2DD3.js";export{b as CHECK_EVERY_MS,e as MAX_NOTES,g as NOTE_TEXT,f as NOTE_TITLE,a as REGISTRY_URL,o as availableUpdate,h as cachePath,m as checkNow,l as fetchLatest,c as isNewer,k as isStale,i as readCache,d as updateChecksEnabled,n as whatsNewFor,j as writeCache};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as c,c as a}from"./chunk-65Y7YCZZ.js";var p=["SIGINT","SIGTERM","SIGHUP"],m={SIGHUP:129,SIGINT:130,SIGTERM:143};function d(n,o=process.platform){if(process.removeAllListeners(n),o!=="win32")try{process.kill(process.pid,n);return}catch{}process.exit(m[n])}function T(n,o={}){let r=o.die??(e=>d(e)),s=o.on??((e,t)=>process.on(e,t)),f=o.off??((e,t)=>process.removeListener(e,t)),g=new Set(o.graceful??p),l=!1,i,S=e=>{a(),r(e)},u=p.map(e=>{let t=()=>{if(l||!g.has(e))return S(e);l=!0,n(e),o.graceMs!==void 0&&(i=setTimeout(()=>S(e),o.graceMs),i.unref())};return s(e,t),[e,t]});return()=>{i&&clearTimeout(i);for(let[e,t]of u)f(e,t)}}var I={inFlight:c,abandon:a,die:n=>d(n),graceMs:1e3,pollMs:25};async function G(n={}){let o={...I,...n},r=Date.now()+o.graceMs;for(;o.inFlight()&&Date.now()<r;)await new Promise(s=>setTimeout(s,o.pollMs));o.inFlight()&&(o.abandon(),o.die("SIGINT"))}export{m as a,d as b,T as c,G as d};
3
+ import{b as c,c as a}from"./chunk-S44LAUHZ.js";var p=["SIGINT","SIGTERM","SIGHUP"],m={SIGHUP:129,SIGINT:130,SIGTERM:143};function d(n,o=process.platform){if(process.removeAllListeners(n),o!=="win32")try{process.kill(process.pid,n);return}catch{}process.exit(m[n])}function T(n,o={}){let r=o.die??(e=>d(e)),s=o.on??((e,t)=>process.on(e,t)),f=o.off??((e,t)=>process.removeListener(e,t)),g=new Set(o.graceful??p),l=!1,i,S=e=>{a(),r(e)},u=p.map(e=>{let t=()=>{if(l||!g.has(e))return S(e);l=!0,n(e),o.graceMs!==void 0&&(i=setTimeout(()=>S(e),o.graceMs),i.unref())};return s(e,t),[e,t]});return()=>{i&&clearTimeout(i);for(let[e,t]of u)f(e,t)}}var I={inFlight:c,abandon:a,die:n=>d(n),graceMs:1e3,pollMs:25};async function G(n={}){let o={...I,...n},r=Date.now()+o.graceMs;for(;o.inFlight()&&Date.now()<r;)await new Promise(s=>setTimeout(s,o.pollMs));o.inFlight()&&(o.abandon(),o.die("SIGINT"))}export{m as a,d as b,T as c,G as d};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{l as T}from"./chunk-PXCEMDOY.js";import{c as N,e as _,f as L}from"./chunk-OLKPV4WO.js";import{a as P,d as O}from"./chunk-DC2DHMXO.js";import{a as y}from"./chunk-PON65UTS.js";import{Ia as g,Pa as S,Qa as I,_ as E}from"./chunk-PNPAHKJR.js";import{spawn as B}from"node:child_process";import{mkdtemp as D,rename as K,rm as $}from"node:fs/promises";import{tmpdir as z}from"node:os";import{extname as G,join as b}from"node:path";import{createInterface as H}from"node:readline";var M=[[/private video|this account is private/i,"This video is private."],[/confirm your age|age-restricted/i,"This video is age-restricted."],[/members-only|join this channel/i,"This video is for channel members only."],[/live event will begin|premieres in/i,"This video has not started yet."],[/unsupported url/i,"No video at this link."],[/no video formats found|no video could be found|there is no video/i,"No video in this post."],[/unavailable|has been removed|does not exist|not found|404/i,"This video is unavailable."]],J=/login required|log in|sign in|logged-in|--cookies|cookies-from-browser|authentication|rate-limit reached/i,U=/operation not permitted|permission ?error|permission denied|could not copy .* cookie|failed to (?:decrypt|read) .*cookies/i,m=class extends Error{},Y=e=>{try{return P(new URL(e).hostname)}catch{return"This site"}};function j(e=process.platform,t=process.arch){let o=_("yt-dlp");return o!==void 0&&L(o,e,t)!==void 0?E("yt-dlp"):g(`Video links on ${N(e)} need yt-dlp on your PATH.`,void 0,{hint:"Install yt-dlp (https://github.com/yt-dlp/yt-dlp) and put it on your PATH.",shellHint:"Install yt-dlp and put it on your PATH."})}function ce(e,t={}){return C(e,{what:"sound"},t)}function ue(e,t,o={}){return C(e,{what:"video",ffmpeg:t},o)}async function C(e,t,o){let r=await T();if(r===void 0)throw j();let n=await D(b(z(),"forge-link-"));o.onDir?.(n);let d=()=>$(n,{recursive:!0,force:!0});try{let i;try{i=await W(r.entry,e,n,t,o)}catch(c){if(!(c instanceof m))throw c;if(r.own)throw V(c);await X(r.entry,o.signal);try{i=await W(r.entry,e,n,t,o)}catch(s){throw s instanceof m?V(s):s}}if(t.what==="video"){let c=b(n,`${O({title:i.facts.title,uploader:i.facts.uploader,id:i.facts.id??""})}${G(i.path)||".mp4"}`);c!==i.path&&await K(i.path,c),i={...i,path:c}}return{...i,dispose:d}}catch(i){throw await d(),i}}var V=e=>g(`yt-dlp could not fetch this video: ${e.message}`,e,{title:"Cannot get this video"});function q(e,t,o,r){let n=o.what==="sound"?["-f","bestaudio[ext=m4a]/bestaudio/best","-o",b(t,"sound.%(ext)s")]:["-f","bv*[vcodec^=avc1]+ba[acodec^=mp4a]/b[vcodec^=avc1][acodec^=mp4a]/bv*+ba/b","--merge-output-format","mp4","--remux-video","mp4","--ffmpeg-location",o.ffmpeg,"--concurrent-fragments","4","-o",b(t,"video.%(ext)s")];return["--js-runtimes",`node:${process.execPath}`,"--no-playlist","--no-warnings","--newline","--progress",...n,...r?["--cookies-from-browser",r]:[],"--print","before_dl:forge-facts %(.{title,uploader,duration,is_live,extractor_key,id,filesize,filesize_approx})j","--progress-template","download:forge-bytes %(info.format_id)s %(progress.downloaded_bytes)s %(progress.total_bytes,progress.total_bytes_estimate)s","--print","after_move:forge-file %(filepath)s","--no-simulate","--",e]}function Q(e){let t=Number(e.filesize??e.filesize_approx);return{title:String(e.title??""),uploader:String(e.uploader??""),seconds:Number(e.duration??0),...typeof e.extractor_key=="string"&&e.extractor_key!==""?{site:e.extractor_key}:{},...typeof e.id=="string"&&e.id!==""?{id:e.id}:{},...Number.isFinite(t)&&t>0?{bytes:t}:{}}}function A(e){let t=new Map;return o=>{let r=o.split(" "),[n,d,i]=r.length>=3?r:["",r[0],r[1]],c=Number(d),s=Number(i);if(!Number.isFinite(c)||!Number.isFinite(s)||s<=0)return;t.set(n??"",{done:c,total:s});let l=0,f=0;for(let p of t.values())l+=p.done,f+=p.total;return{done:l,total:Math.max(f,e??0)}}}function W(e,t,o,r,n){let{signal:d}=n;if(d?.aborted)return Promise.reject(d.reason??new Error("aborted"));let i=q(t,o,r,n.signIn);return new Promise((c,s)=>{let l=y(B(e,i,{stdio:["ignore","pipe","pipe"]})),f,p,v="",w=!1,k=A(),h=a=>{w||(w=!0,d?.removeEventListener("abort",x),a())},x=()=>{l.kill("SIGKILL"),h(()=>s(d?.reason??new Error("aborted")))};d?.addEventListener("abort",x,{once:!0}),H({input:l.stdout}).on("line",a=>{if(a.startsWith("forge-facts ")){let u;try{u=JSON.parse(a.slice(12))}catch{return}if(u.is_live===!0){l.kill("SIGKILL"),h(()=>s(g("This is a live stream.",void 0,{title:"Cannot get this video"})));return}f=Q(u),k=A(f.bytes),n.onEvent?.({kind:"facts",facts:f})}else if(a.startsWith("forge-bytes ")){let u=k(a.slice(12));u&&n.onEvent?.({kind:"bytes",...u})}else a.startsWith("forge-file ")&&(p=a.slice(11))}),l.stderr.on("data",a=>{v+=a.toString()}),l.on("error",a=>h(()=>s(new m(a.message)))),l.on("close",a=>h(()=>{if(a===0&&f!==void 0&&p!==void 0)return c({path:p,facts:f});let u=v.match(/ERROR: (?:\[[^\]]*\] )?(?:[\w-]+: )?(.*)/)?.[1]?.trim()??"";if(n.signIn&&U.test(v))return s(I(n.signIn));let F=M.find(([R])=>R.test(u));if(F)return s(g(F[1],void 0,{title:"Cannot get this video"}));if(J.test(u))return s(S(Y(t),n.signIn));s(new m(u||`yt-dlp exited ${a}`))}))})}function X(e,t){return new Promise((o,r)=>{let n=y(B(e,["--update"],{stdio:"ignore"})),d=()=>n.kill("SIGKILL");t?.addEventListener("abort",d,{once:!0}),n.on("error",()=>o()),n.on("close",()=>{t?.removeEventListener("abort",d),t?.aborted?r(t.reason??new Error("aborted")):o()})})}export{j as a,ce as b,ue as c,q as d,Q as e,A as f};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a as J}from"./chunk-O7DK3GJT.js";import{a as E}from"./chunk-65Y7YCZZ.js";import{i as R}from"./chunk-NMGQGYVM.js";import{f as F,za as y}from"./chunk-CCNRNCRU.js";function x(n=process.env){let r=Number(n.UV_THREADPOOL_SIZE),o=J();return Number.isInteger(r)&&r>0?Math.min(o,r):o}function w(n){let r=n!==void 0&&Number.isFinite(n)?n:void 0;return Math.max(1,r??x())}async function I(n,r,o,d){let b=[],l=[];for(let[i,u]of n.entries())(d?.(u)?l:b).push(i);let p=0,m=0,t,g=async()=>{for(;;){let i=b[p],u=t?void 0:l[m];if(i!==void 0&&(u===void 0||i<u))p++,await o(n[i],i);else if(u!==void 0)m++,t=o(n[u],u).finally(()=>{t=void 0}),await t;else if(t)await t;else return}},f=Math.min(w(r),n.length);await Promise.all(Array.from({length:f},g))}async function B(n,r){let o=r.onEvent??(()=>{}),d=r.engineFor??R,b=w(r.concurrency),l=n.length,p=[],m=[],t=0;await I(n,b,async(e,a)=>{if(r.signal?.aborted)return;o({type:"job:start",job:e,index:a,total:l});let h=d(e);if(!h){t++;let s=e.sources[0].path,c={path:s,error:y(s,new Error(`no engine runs ${e.op}`))};m[a]=c,o({type:"job:error",job:e,failure:c,completed:t,total:l});return}try{let s=await E(h.run(e,c=>o({type:"job:phase",job:e,progress:c}),r.signal));p[a]=s,t++,o({type:"job:done",job:e,result:s,completed:t,total:l})}catch(s){t++;let c=e.sources[0].path,P=F(s)?s:y(c,s,e.sources[0].format),v={path:c,error:P};m[a]=v,o({type:"job:error",job:e,failure:v,completed:t,total:l})}},e=>d(e)?.alone===!0);let f=p.filter(e=>e!==void 0),i=m.filter(e=>e!==void 0),u={results:f,failures:i,inputBytes:f.reduce((e,a)=>e+a.job.sources[0].bytes,0),outputBytes:f.reduce((e,a)=>e+a.outputBytes,0)};return o({type:"batch:done",summary:u}),u}export{x as a,w as b,I as c,B as d};
3
+ import{a as J}from"./chunk-O7DK3GJT.js";import{a as E}from"./chunk-S44LAUHZ.js";import{p as R}from"./chunk-ULX4ZD2Y.js";import{Ca as y,i as F}from"./chunk-PNPAHKJR.js";function x(n=process.env){let r=Number(n.UV_THREADPOOL_SIZE),o=J();return Number.isInteger(r)&&r>0?Math.min(o,r):o}function w(n){let r=n!==void 0&&Number.isFinite(n)?n:void 0;return Math.max(1,r??x())}async function I(n,r,o,d){let b=[],l=[];for(let[i,u]of n.entries())(d?.(u)?l:b).push(i);let p=0,m=0,t,g=async()=>{for(;;){let i=b[p],u=t?void 0:l[m];if(i!==void 0&&(u===void 0||i<u))p++,await o(n[i],i);else if(u!==void 0)m++,t=o(n[u],u).finally(()=>{t=void 0}),await t;else if(t)await t;else return}},f=Math.min(w(r),n.length);await Promise.all(Array.from({length:f},g))}async function B(n,r){let o=r.onEvent??(()=>{}),d=r.engineFor??R,b=w(r.concurrency),l=n.length,p=[],m=[],t=0;await I(n,b,async(e,a)=>{if(r.signal?.aborted)return;o({type:"job:start",job:e,index:a,total:l});let h=d(e);if(!h){t++;let s=e.sources[0].path,c={path:s,error:y(s,new Error(`no engine runs ${e.op}`))};m[a]=c,o({type:"job:error",job:e,failure:c,completed:t,total:l});return}try{let s=await E(h.run(e,c=>o({type:"job:phase",job:e,progress:c}),r.signal));p[a]=s,t++,o({type:"job:done",job:e,result:s,completed:t,total:l})}catch(s){t++;let c=e.sources[0].path,P=F(s)?s:y(c,s,e.sources[0].format),v={path:c,error:P};m[a]=v,o({type:"job:error",job:e,failure:v,completed:t,total:l})}},e=>d(e)?.alone===!0);let f=p.filter(e=>e!==void 0),i=m.filter(e=>e!==void 0),u={results:f,failures:i,inputBytes:f.reduce((e,a)=>e+a.job.sources[0].bytes,0),outputBytes:f.reduce((e,a)=>e+a.outputBytes,0)};return o({type:"batch:done",summary:u}),u}export{x as a,w as b,I as c,B as d};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{d as h,f,s as z,u as g}from"./chunk-YXV3PYVI.js";import{b as A,e as m}from"./chunk-TQEGSODD.js";import{h as C,i as y}from"./chunk-ULX4ZD2Y.js";import{b as q,c as S,d as O,e as F,i as x}from"./chunk-JZM37DG2.js";import{S as c,d as l,e as k,g as I,h as u}from"./chunk-PNPAHKJR.js";import{dirname as T,join as $}from"node:path";var R=t=>l[t.format].media==="video",N=t=>t.length===1&&t[0]?.kind==="image"?t[0]:void 0,Q=t=>t.length===1&&t[0]?.kind==="document"?t[0]:void 0,j="-small",d={min:30,max:100,step:35},v=t=>{let e=Math.ceil((t-d.min)/d.step);return Math.min(d.max,d.min+Math.max(0,e)*d.step)},Z={id:"compress",label:"Compress",verb:"Compressing",hint:"make it smaller",appliesTo:t=>{if(t.length===1&&t[0]?.kind==="media")return!0;let e=N(t);if(e!==void 0){let i=l[e.format];return i.lossy||i.quantisable===!0}return(Q(t)?.images?.compressible??0)>0},options(t,e,n){let i=t[0];if(!i)return[];let o=[{kind:"select",id:"mode",label:`Compress ${h(i.path)??"this file"}`,choices:[i.kind==="media"?{value:"quality",label:"By quality"}:{value:"quality",label:"By quality",hint:"pick a level, see the result"},{value:"size",label:"To a target size",hint:"smallest quality that fits"}],default:"quality"}];if(e.mode==="quality"&&i.kind==="media"&&!R(i))o.push({kind:"slider",id:"bitrate",label:"Quality",min:32,max:320,step:32,default:96});else if(e.mode==="quality"){let r=i.kind==="image"&&l[i.format].quantisable===!0;o.push(r?{kind:"slider",id:"quality",label:"Quality",...d,default:v(u(i.format,n.quality)),points:!0}:{kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:u(i.format,n.quality)})}else if(e.mode==="size")o.push({kind:"text",id:"size",label:"Target size",placeholder:"e.g. 500kb or 2mb"});else return o;return o.push(f(i,n)),o},plan(t,e){let n=e.mode;if(n!=="quality"&&n!=="size")throw c(`compressAction.plan() needs a mode of "quality" or "size", got ${JSON.stringify(n)}.`,"This is a caller bug, not a user-facing condition: walk options() before calling plan().");let i=t[0];if(!i)return[];let o=(h(i.path)??"file").replace(/\.[^.]+$/,""),r=typeof e.destination=="string"?e.destination:T(i.path),a=i.kind==="media"?z(i.format):i.format,p=$(r,q(o,`${j}${I(a)}`)),s=i.kind==="media"?g(e):void 0;return[{op:"convert",sources:[i],target:a,outputs:[p],options:{background:"#ffffff",keepMetadata:!1,...n==="quality"&&typeof e.quality=="number"?{quality:e.quality}:{},compress:{dither:e.dither===!0},...s?{media:s}:{}}}]}};function D(t){return{kind:"select",id:"pages",label:"Pages",default:"all",choices:[{value:"all",label:"All pages",hint:`${t.pages} pages`},{value:"first",label:"First page only"},{value:"choose",label:"Choose pages",hint:"pick which ones"}]}}function w(){return{kind:"select",id:"dpi",label:"Resolution",default:"150",choices:[{value:"72",label:"72 dpi",hint:"screen"},{value:"150",label:"150 dpi",badge:"default"},{value:"300",label:"300 dpi",hint:"print"}]}}function B(t,e){return Array.isArray(e)?y(e):e==="first"?[0]:typeof e=="string"&&e!=="all"&&e!==""?y(C(e,t.pages)):Array.from({length:t.pages},(n,i)=>i)}function E(t,e){let n=l[t.format].lossy,i=l[e].lossy;if(n&&!i)return{hint:"likely bigger",tone:"warn"};if(!n&&i)return{hint:"likely smaller",tone:"ok"}}function J(t){let e=t.kind==="document"&&t.encrypted,n=A(t).filter(o=>o.id!==t.format&&(!e||m(o.id))),i=n[0];return{kind:"select",id:"target",label:`Convert ${l[t.format].label} to`,choices:n.map(o=>{let r=E(t,o.id);return{value:o.id,label:o.label,hint:r?.hint??o.hint,...r===void 0?{}:{tone:r.tone}}}),default:i?i.id:""}}function U(t){return{kind:"slider",id:"bitrate",label:"Quality",min:64,max:320,step:32,default:t==="opus"?96:128}}var X=t=>typeof t=="object"&&t!==null&&("percent"in t||"width"in t||"height"in t);function _(t){let e=t.target,n=typeof e=="string"?k(e):void 0;if(!n)throw c(`convertAction.plan() requires a valid target format, got ${JSON.stringify(e)}.`,"This is a caller bug, not a user-facing condition: call options() and pass one of the target select choices before calling plan().");return n}var lt={id:"convert",label:"Convert",verb:"Converting",hint:"to another format",appliesTo:t=>t.length>=1,options(t,e,n){let i=t[0];if(!i)return[];let o=[J(i)],r=e.target;if(typeof r!="string")return o;i.kind==="document"&&m(r)&&o.push(D(i),w());let a=l[r];return i.kind==="media"?a?.media==="sound"&&a.lossy&&o.push(U(r)):a?.lossy&&a.media===void 0&&o.push({kind:"slider",id:"quality",label:"Quality",min:1,max:100,step:5,default:u(r,n.quality)}),o.push(f(i,n)),o},plan(t,e){let n=t[0];if(!n)return[];let i=_(e),o=i.id,r={background:typeof e.background=="string"?e.background:"#ffffff",keepMetadata:e.keepMetadata===!0};if(i.lossy&&typeof e.quality=="number"&&(r.quality=e.quality),n.kind==="media"){let s=g(e);s&&(r.media=s),X(e.resize)&&(r.resize=e.resize)}let a=typeof e.destination=="string"?e.destination:void 0;if(n.kind==="document"&&m(o)){let s=Number(e.dpi);r.dpi=Number.isFinite(s)&&s>0?s:150;let b=B(n,e.pages);r.pages=b;let M=typeof e.sourceRoot=="string"?e.sourceRoot:void 0,P=x(n.path,b,o,a,M);return[{op:"convert",sources:[n],outputs:P,target:o,options:r}]}let p=O({sourcePath:n.path,target:o,...a===void 0?{}:{output:`${a}/`}});return S(p,n.path)&&(p=F({sourcePath:n.path,target:o,suffix:o,...a===void 0?{}:{output:`${a}/`}})),[{op:"convert",sources:[n],outputs:[p],target:o,options:r}]}};export{Z as a,lt as b};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as d}from"./chunk-CCNRNCRU.js";var m=e=>/^[A-Za-z0-9][A-Za-z0-9-]*$/.test(e),u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),s=e=>typeof e=="number"&&Number.isInteger(e)&&e>0;function h(e){if(!(!u(e)||Object.keys(e).length!==1)){if(s(e.width))return{width:e.width};if(s(e.height))return{height:e.height};if(s(e.percent))return{percent:e.percent}}}function b(e){if(!u(e))return;let t={};if(e.to!==void 0){if(typeof e.to!="string"||!d(e.to))return;t.to=e.to}if(e.quality!==void 0){if(!s(e.quality)||e.quality>100)return;t.quality=e.quality}if(e.maxBytes!==void 0){if(!s(e.maxBytes))return;t.maxBytes=e.maxBytes}if(e.resize!==void 0){let i=h(e.resize);if(!i)return;t.resize=i}for(let i of["trim","sharpen","removeBackground"])if(e[i]!==void 0){if(typeof e[i]!="boolean")return;t[i]=e[i]}if(e.crop!==void 0){if(!u(e.crop)||!s(e.crop.w)||!s(e.crop.h))return;t.crop={w:e.crop.w,h:e.crop.h}}if(e.boost!==void 0){if(e.boost!==2&&e.boost!==3&&e.boost!==4)return;t.boost=e.boost}if(e.compress!==void 0){if(!u(e.compress)||typeof e.compress.dither!="boolean")return;t.compress={dither:e.compress.dither}}if(e.behind!==void 0){if(e.behind!=="white"&&e.behind!=="black")return;t.behind=e.behind}return t}function z(e){if(!u(e)||typeof e.name!="string"||!m(e.name)||typeof e.saveTo!="string"||e.saveTo.trim()==="")return;let t=b(e.steps);if(t)return{name:e.name,steps:t,saveTo:e.saveTo,...e.quickAction===!0?{quickAction:!0}:{}}}var l={white:"#ffffff",black:"#000000"};function x(e,t){let i=[];e.removeBackground&&i.push({kind:"cutout"}),e.boost?i.push({kind:"boost",scale:e.boost}):e.sharpen&&i.push({kind:"boost",scale:1});let o=[];e.trim&&o.push({kind:"cut",trim:!0}),e.crop&&o.push({kind:"cut",crop:e.crop});let c=e.to??t,n={kind:"encode",target:c};if(e.quality!==void 0&&(n.quality=e.quality),e.maxBytes&&(n.maxBytes=e.maxBytes),(e.compress||e.maxBytes)&&(n.compress=e.compress??{dither:!1}),e.resize&&(n.resize=e.resize),i.length===0){let r=o.pop();r?.kind==="cut"&&(r.trim&&(n.trim=!0),r.crop&&(n.crop=r.crop))}if(n.maxBytes&&(n.trim||n.crop||n.resize)){let{trim:r,crop:a,resize:p}=n;o.push({kind:"cut",...r?{trim:r}:{},...a?{crop:a}:{},...p?{resize:p}:{}}),delete n.trim,delete n.crop,delete n.resize}if(e.removeBackground&&!d(c)?.hasAlpha&&(n.background=l[e.behind??"white"]),o.length===0&&i.length===0&&Object.keys(n).length===2&&e.to===void 0)return[];let f=o.filter(r=>r.kind==="cut"&&r.resize);return[...o.filter(r=>!f.includes(r)),...i,...f,n]}export{m as a,z as b,x as c};
3
+ import{e as d}from"./chunk-PNPAHKJR.js";var m=e=>/^[A-Za-z0-9][A-Za-z0-9-]*$/.test(e),u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),s=e=>typeof e=="number"&&Number.isInteger(e)&&e>0;function h(e){if(!(!u(e)||Object.keys(e).length!==1)){if(s(e.width))return{width:e.width};if(s(e.height))return{height:e.height};if(s(e.percent))return{percent:e.percent}}}function b(e){if(!u(e))return;let t={};if(e.to!==void 0){if(typeof e.to!="string"||!d(e.to))return;t.to=e.to}if(e.quality!==void 0){if(!s(e.quality)||e.quality>100)return;t.quality=e.quality}if(e.maxBytes!==void 0){if(!s(e.maxBytes))return;t.maxBytes=e.maxBytes}if(e.resize!==void 0){let i=h(e.resize);if(!i)return;t.resize=i}for(let i of["trim","sharpen","removeBackground"])if(e[i]!==void 0){if(typeof e[i]!="boolean")return;t[i]=e[i]}if(e.crop!==void 0){if(!u(e.crop)||!s(e.crop.w)||!s(e.crop.h))return;t.crop={w:e.crop.w,h:e.crop.h}}if(e.boost!==void 0){if(e.boost!==2&&e.boost!==3&&e.boost!==4)return;t.boost=e.boost}if(e.compress!==void 0){if(!u(e.compress)||typeof e.compress.dither!="boolean")return;t.compress={dither:e.compress.dither}}if(e.behind!==void 0){if(e.behind!=="white"&&e.behind!=="black")return;t.behind=e.behind}return t}function z(e){if(!u(e)||typeof e.name!="string"||!m(e.name)||typeof e.saveTo!="string"||e.saveTo.trim()==="")return;let t=b(e.steps);if(t)return{name:e.name,steps:t,saveTo:e.saveTo,...e.quickAction===!0?{quickAction:!0}:{}}}var l={white:"#ffffff",black:"#000000"};function x(e,t){let i=[];e.removeBackground&&i.push({kind:"cutout"}),e.boost?i.push({kind:"boost",scale:e.boost}):e.sharpen&&i.push({kind:"boost",scale:1});let o=[];e.trim&&o.push({kind:"cut",trim:!0}),e.crop&&o.push({kind:"cut",crop:e.crop});let c=e.to??t,n={kind:"encode",target:c};if(e.quality!==void 0&&(n.quality=e.quality),e.maxBytes&&(n.maxBytes=e.maxBytes),(e.compress||e.maxBytes)&&(n.compress=e.compress??{dither:!1}),e.resize&&(n.resize=e.resize),i.length===0){let r=o.pop();r?.kind==="cut"&&(r.trim&&(n.trim=!0),r.crop&&(n.crop=r.crop))}if(n.maxBytes&&(n.trim||n.crop||n.resize)){let{trim:r,crop:a,resize:p}=n;o.push({kind:"cut",...r?{trim:r}:{},...a?{crop:a}:{},...p?{resize:p}:{}}),delete n.trim,delete n.crop,delete n.resize}if(e.removeBackground&&!d(c)?.hasAlpha&&(n.background=l[e.behind??"white"]),o.length===0&&i.length===0&&Object.keys(n).length===2&&e.to===void 0)return[];let f=o.filter(r=>r.kind==="cut"&&r.resize);return[...o.filter(r=>!f.includes(r)),...i,...f,n]}export{m as a,z as b,x as c};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a as m}from"./chunk-MF3KKEFB.js";import{ga as l}from"./chunk-CCNRNCRU.js";import{randomBytes as h}from"node:crypto";import{link as y,mkdir as p,readdir as x,readFile as P,rename as E,rm as c,stat as L,writeFile as S}from"node:fs/promises";import{join as u}from"node:path";var b=720*60*1e3,k=600*1e3,M=200,F=600*1e3;function a(){return u(m(),".locks")}function f(t){return u(a(),`${t}.lock`)}function v(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function s(t){try{let n=JSON.parse(await P(t,"utf8"));return typeof n.pid!="number"||typeof n.token!="string"?void 0:n}catch{return}}async function d(t,n){if(n===void 0||!v(n.pid))return!0;let e=await L(t).catch(()=>{});return e!==void 0&&Date.now()-e.mtimeMs>b}async function D(t){let n=`${t}.stale-${h(4).toString("hex")}`;try{await E(t,n)}catch{return}let e=await s(n);e!==void 0&&!await d(n,e)&&await y(n,t).catch(()=>{}),await c(n,{force:!0})}async function A(){let t=await x(a()).catch(()=>[]);for(let n of t){if(!/\.lock\.(stale-)?[0-9a-f]+$/.test(n))continue;let e=u(a(),n),i=await L(e).catch(()=>{});i&&Date.now()-i.mtimeMs>F&&await c(e,{force:!0})}}async function g(t,n){await p(a(),{recursive:!0});let e=f(t),i={pid:process.pid,token:h(8).toString("hex"),at:Date.now(),...n!==void 0?{what:n}:{}},r=`${e}.${i.token}`;await S(r,JSON.stringify(i),{flag:"wx"});try{for(let o=0;o<2;o++){try{return await y(r,e),i}catch(w){if(w.code!=="EEXIST")throw w}if(!await d(e,await s(e)))return;await D(e)}return}finally{await c(r,{force:!0})}}async function T(t,n){let e=f(t);(await s(e))?.token===n.token&&await c(e,{force:!0})}async function _(t){let n=f(t),e=await s(n);if(!(e===void 0||await d(n,e)))return{pid:e.pid,...e.what!==void 0?{what:e.what}:{}}}async function H(t,n,e={}){let i=Date.now()+(e.waitMs??k);await p(a(),{recursive:!0}),await A();let r=await g(t,e.what);for(r===void 0&&(e.waitMs??k)>0&&e.onWait?.();r===void 0;){if(e.signal?.aborted)throw e.signal.reason??new Error("aborted");if(Date.now()>=i)throw l(t,await _(t),e.action??"run");await new Promise(o=>setTimeout(o,M)),r=await g(t,e.what)}try{return await n()}finally{await T(t,r)}}export{k as a,_ as b,H as c};
3
+ import{a as m}from"./chunk-FEJSM3E4.js";import{ja as l}from"./chunk-PNPAHKJR.js";import{randomBytes as h}from"node:crypto";import{link as y,mkdir as p,readdir as x,readFile as P,rename as E,rm as c,stat as L,writeFile as S}from"node:fs/promises";import{join as u}from"node:path";var b=720*60*1e3,k=600*1e3,M=200,F=600*1e3;function a(){return u(m(),".locks")}function f(t){return u(a(),`${t}.lock`)}function v(t){if(!Number.isInteger(t)||t<=0)return!1;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function s(t){try{let n=JSON.parse(await P(t,"utf8"));return typeof n.pid!="number"||typeof n.token!="string"?void 0:n}catch{return}}async function d(t,n){if(n===void 0||!v(n.pid))return!0;let e=await L(t).catch(()=>{});return e!==void 0&&Date.now()-e.mtimeMs>b}async function D(t){let n=`${t}.stale-${h(4).toString("hex")}`;try{await E(t,n)}catch{return}let e=await s(n);e!==void 0&&!await d(n,e)&&await y(n,t).catch(()=>{}),await c(n,{force:!0})}async function A(){let t=await x(a()).catch(()=>[]);for(let n of t){if(!/\.lock\.(stale-)?[0-9a-f]+$/.test(n))continue;let e=u(a(),n),i=await L(e).catch(()=>{});i&&Date.now()-i.mtimeMs>F&&await c(e,{force:!0})}}async function g(t,n){await p(a(),{recursive:!0});let e=f(t),i={pid:process.pid,token:h(8).toString("hex"),at:Date.now(),...n!==void 0?{what:n}:{}},r=`${e}.${i.token}`;await S(r,JSON.stringify(i),{flag:"wx"});try{for(let o=0;o<2;o++){try{return await y(r,e),i}catch(w){if(w.code!=="EEXIST")throw w}if(!await d(e,await s(e)))return;await D(e)}return}finally{await c(r,{force:!0})}}async function T(t,n){let e=f(t);(await s(e))?.token===n.token&&await c(e,{force:!0})}async function _(t){let n=f(t),e=await s(n);if(!(e===void 0||await d(n,e)))return{pid:e.pid,...e.what!==void 0?{what:e.what}:{}}}async function H(t,n,e={}){let i=Date.now()+(e.waitMs??k);await p(a(),{recursive:!0}),await A();let r=await g(t,e.what);for(r===void 0&&(e.waitMs??k)>0&&e.onWait?.();r===void 0;){if(e.signal?.aborted)throw e.signal.reason??new Error("aborted");if(Date.now()>=i)throw l(t,await _(t),e.action??"run");await new Promise(o=>setTimeout(o,M)),r=await g(t,e.what)}try{return await n()}finally{await T(t,r)}}export{k as a,_ as b,H as c};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as C,c as U,d as q}from"./chunk-ECA4PW5T.js";import{i as O}from"./chunk-NMGQGYVM.js";import{c as T,v as B}from"./chunk-UN5DSJE2.js";import{E as I,F as J,G as M,H as P,f as w,pa as v,qa as R,w as x,z as E,za as A}from"./chunk-CCNRNCRU.js";function L(e=1,t=100){let r=Math.max(1,t-e+1);return r<=2?r:2+Math.ceil(Math.log2(r))}async function _(e){let t=e.min??1,r=e.max??100,c=L(t,r),l=0,n=new Map,o=async m=>{let f=n.get(m);if(f!==void 0)return f;l+=1,e.onAttempt?.(l,c);let F=await e.encode(m);return n.set(m,F),F},i=()=>e.signal?.aborted===!0,y=await o(r);if(i())return{quality:r,bytes:y,missed:!1,cancelled:!0};if(y<=e.targetBytes)return{quality:r,bytes:y,missed:!1};let d=await o(t);if(i())return{quality:t,bytes:d,missed:!1,cancelled:!0};if(d>e.targetBytes)return{quality:t,bytes:d,missed:!0};let h=t,b=r,g;for(;h<=b;){let m=Math.floor((h+b)/2),f=await o(m);if(i())return{quality:m,bytes:f,missed:!1,cancelled:!0};f<=e.targetBytes?(g={quality:m,bytes:f,missed:!1},h=m+1):b=m-1}return g??{quality:t,bytes:d,missed:!1}}import{existsSync as N}from"node:fs";import{resolve as S}from"node:path";function W(e){let t=e.sources[0]?.path??e.outputs[0]??"",r=new Set;for(let c of e.outputs){let l=S(c);if(r.has(l))return{output:c,error:M(t,c)};r.add(l)}}function z(e,t,r){let c=W(e);if(c)return c;let l=e.sources[0]?.path??e.outputs[0]??"";for(let n of e.outputs){let o=S(n);if(e.sources.some(y=>T(y.path,o))&&!r)return{output:n,error:P(n,e.op)};let i=t.get(o);if(i){let y=i.sources[0]?.path??i.outputs[0]??"";return{output:n,error:J([y,l],n)}}if(N(o)&&!r)return{output:n,error:I(n,e.op)}}}function D(e,t){let r=[],c=[],l=new Map;for(let n of e){let o=z(n,l,t.force);if(o){let i=n.sources[0]?.path??o.output;c.push({path:i,error:o.error});continue}for(let i of n.outputs)l.set(S(i),n);r.push(n)}return{jobs:r,failures:c}}async function Q(e,t,r,c,l,n){let o=e.sources[0].path,i=u=>({kind:"failed",failure:{path:o,error:w(u)?u:A(o,u,e.sources[0].format)}}),y=r(e);if(y?.sizeTo){let u=e.sources[0],s=e.options.compress!==void 0;if(s&&u.bytes<=t)return{kind:"failed",failure:{path:o,error:R(o,u.bytes,t)}};let p=t,a=y.sizeTo(e,p);return a&&s&&a.floor>=u.bytes?{kind:"failed",failure:{path:o,error:v(o,u.bytes,a.floor,!0)}}:a?{kind:"unreachable",entry:{job:e,smallest:a.floor,settings:{quality:1,media:{...e.options.media,targetBytes:a.floor}},error:E(u,t,a.floor)}}:(e.options={...e.options,media:{...e.options.media,targetBytes:p}},{kind:"ready"})}let d;try{d=await r(e)?.measurer?.(e)}catch(u){return i(u)}if(!d||d.ladder.length===0)return{kind:"refused",failure:{path:o,error:x(e.sources[0],e.target)}};let h=d,b=e.sources[0],g=e.options.compress!==void 0&&b.bytes<=t,m=g?b.bytes-1:t;if(l?.aborted)return{kind:"cancelled"};let f=Number.POSITIVE_INFINITY,F;try{for(let u of h.ladder){let s=await _({encode:p=>h.measure({...e.options,...u,quality:p}),targetBytes:m,...n===void 0?{}:{max:n},onAttempt:(p,a)=>c({type:"search:attempt",job:e,attempt:p,of:a,rung:u}),...l===void 0?{}:{signal:l}});if(s.cancelled)return{kind:"cancelled"};if(s.bytes<f&&(f=s.bytes,F={...u,quality:s.quality}),!s.missed)return e.options={...e.options,...u,quality:s.quality},{kind:"ready"}}}catch(u){return i(u)}return g?{kind:"failed",failure:{path:o,error:v(o,b.bytes,f,!0)}}:{kind:"unreachable",entry:{job:e,smallest:f,settings:F??{quality:1},error:E(e.sources[0],t,f)}}}async function ne(e,t){let r=t.onEvent??(()=>{}),c=t.engineFor??O,l=t.targetBytes,n=D(e,{force:t.force}),o=l===void 0?0:n.jobs.filter(s=>s.op==="convert").length,i=[],y=0;await U(n.jobs,C(t.concurrency),async(s,p)=>{if(l===void 0||s.op!=="convert"){i[p]={kind:"ready"};return}if(t.signal?.aborted){i[p]={kind:"cancelled"};return}let a=await Q(s,l,c,r,t.signal,t.maxQuality);i[p]=a,a.kind!=="cancelled"&&(y+=1,r({type:"search:settled",job:s,completed:y,total:o}))});let d=[...n.failures],h=[],b=[],g=[],m=!1;for(let[s,p]of n.jobs.entries()){let a=i[s]??{kind:"ready"};a.kind==="ready"?g.push(p):a.kind==="refused"?d.push(a.failure):a.kind==="failed"?b.push(a.failure):a.kind==="unreachable"?h.push(a.entry):m=!0}if(m)return{results:[],refusals:d,unreachable:[],failures:[],inputBytes:0,outputBytes:0,cancelled:!0};let f=new Set,F=()=>q(g,{...t.concurrency===void 0?{}:{concurrency:t.concurrency},...t.engineFor===void 0?{}:{engineFor:t.engineFor},...t.signal===void 0?{}:{signal:t.signal},onEvent:s=>{s.type==="job:error"&&!t.signal?.aborted&&f.add(s.failure),r(s)}}),k=t.force?await F():await B(F),u=g.length-k.results.length;if(t.signal?.aborted&&u>0){let s=k.failures.filter(p=>f.has(p));return{...k,refusals:d,unreachable:h,failures:[...b,...s],cancelled:!0}}return{results:k.results,refusals:d,unreachable:h,failures:[...b,...k.failures],inputBytes:k.inputBytes,outputBytes:k.outputBytes}}export{D as a,ne as b};
3
+ import{b as C,c as U,d as q}from"./chunk-3OCPO5V6.js";import{p as O}from"./chunk-ULX4ZD2Y.js";import{c as T,v as B}from"./chunk-JZM37DG2.js";import{C as E,Ca as A,H as I,I as J,J as M,K as P,i as w,sa as v,ta as R,z as x}from"./chunk-PNPAHKJR.js";function L(e=1,t=100){let r=Math.max(1,t-e+1);return r<=2?r:2+Math.ceil(Math.log2(r))}async function _(e){let t=e.min??1,r=e.max??100,c=L(t,r),l=0,n=new Map,o=async m=>{let f=n.get(m);if(f!==void 0)return f;l+=1,e.onAttempt?.(l,c);let F=await e.encode(m);return n.set(m,F),F},i=()=>e.signal?.aborted===!0,y=await o(r);if(i())return{quality:r,bytes:y,missed:!1,cancelled:!0};if(y<=e.targetBytes)return{quality:r,bytes:y,missed:!1};let d=await o(t);if(i())return{quality:t,bytes:d,missed:!1,cancelled:!0};if(d>e.targetBytes)return{quality:t,bytes:d,missed:!0};let h=t,b=r,g;for(;h<=b;){let m=Math.floor((h+b)/2),f=await o(m);if(i())return{quality:m,bytes:f,missed:!1,cancelled:!0};f<=e.targetBytes?(g={quality:m,bytes:f,missed:!1},h=m+1):b=m-1}return g??{quality:t,bytes:d,missed:!1}}import{existsSync as N}from"node:fs";import{resolve as S}from"node:path";function W(e){let t=e.sources[0]?.path??e.outputs[0]??"",r=new Set;for(let c of e.outputs){let l=S(c);if(r.has(l))return{output:c,error:M(t,c)};r.add(l)}}function z(e,t,r){let c=W(e);if(c)return c;let l=e.sources[0]?.path??e.outputs[0]??"";for(let n of e.outputs){let o=S(n);if(e.sources.some(y=>T(y.path,o))&&!r)return{output:n,error:P(n,e.op)};let i=t.get(o);if(i){let y=i.sources[0]?.path??i.outputs[0]??"";return{output:n,error:J([y,l],n)}}if(N(o)&&!r)return{output:n,error:I(n,e.op)}}}function D(e,t){let r=[],c=[],l=new Map;for(let n of e){let o=z(n,l,t.force);if(o){let i=n.sources[0]?.path??o.output;c.push({path:i,error:o.error});continue}for(let i of n.outputs)l.set(S(i),n);r.push(n)}return{jobs:r,failures:c}}async function Q(e,t,r,c,l,n){let o=e.sources[0].path,i=u=>({kind:"failed",failure:{path:o,error:w(u)?u:A(o,u,e.sources[0].format)}}),y=r(e);if(y?.sizeTo){let u=e.sources[0],s=e.options.compress!==void 0;if(s&&u.bytes<=t)return{kind:"failed",failure:{path:o,error:R(o,u.bytes,t)}};let p=t,a=y.sizeTo(e,p);return a&&s&&a.floor>=u.bytes?{kind:"failed",failure:{path:o,error:v(o,u.bytes,a.floor,!0)}}:a?{kind:"unreachable",entry:{job:e,smallest:a.floor,settings:{quality:1,media:{...e.options.media,targetBytes:a.floor}},error:E(u,t,a.floor)}}:(e.options={...e.options,media:{...e.options.media,targetBytes:p}},{kind:"ready"})}let d;try{d=await r(e)?.measurer?.(e)}catch(u){return i(u)}if(!d||d.ladder.length===0)return{kind:"refused",failure:{path:o,error:x(e.sources[0],e.target)}};let h=d,b=e.sources[0],g=e.options.compress!==void 0&&b.bytes<=t,m=g?b.bytes-1:t;if(l?.aborted)return{kind:"cancelled"};let f=Number.POSITIVE_INFINITY,F;try{for(let u of h.ladder){let s=await _({encode:p=>h.measure({...e.options,...u,quality:p}),targetBytes:m,...n===void 0?{}:{max:n},onAttempt:(p,a)=>c({type:"search:attempt",job:e,attempt:p,of:a,rung:u}),...l===void 0?{}:{signal:l}});if(s.cancelled)return{kind:"cancelled"};if(s.bytes<f&&(f=s.bytes,F={...u,quality:s.quality}),!s.missed)return e.options={...e.options,...u,quality:s.quality},{kind:"ready"}}}catch(u){return i(u)}return g?{kind:"failed",failure:{path:o,error:v(o,b.bytes,f,!0)}}:{kind:"unreachable",entry:{job:e,smallest:f,settings:F??{quality:1},error:E(e.sources[0],t,f)}}}async function ne(e,t){let r=t.onEvent??(()=>{}),c=t.engineFor??O,l=t.targetBytes,n=D(e,{force:t.force}),o=l===void 0?0:n.jobs.filter(s=>s.op==="convert").length,i=[],y=0;await U(n.jobs,C(t.concurrency),async(s,p)=>{if(l===void 0||s.op!=="convert"){i[p]={kind:"ready"};return}if(t.signal?.aborted){i[p]={kind:"cancelled"};return}let a=await Q(s,l,c,r,t.signal,t.maxQuality);i[p]=a,a.kind!=="cancelled"&&(y+=1,r({type:"search:settled",job:s,completed:y,total:o}))});let d=[...n.failures],h=[],b=[],g=[],m=!1;for(let[s,p]of n.jobs.entries()){let a=i[s]??{kind:"ready"};a.kind==="ready"?g.push(p):a.kind==="refused"?d.push(a.failure):a.kind==="failed"?b.push(a.failure):a.kind==="unreachable"?h.push(a.entry):m=!0}if(m)return{results:[],refusals:d,unreachable:[],failures:[],inputBytes:0,outputBytes:0,cancelled:!0};let f=new Set,F=()=>q(g,{...t.concurrency===void 0?{}:{concurrency:t.concurrency},...t.engineFor===void 0?{}:{engineFor:t.engineFor},...t.signal===void 0?{}:{signal:t.signal},onEvent:s=>{s.type==="job:error"&&!t.signal?.aborted&&f.add(s.failure),r(s)}}),k=t.force?await F():await B(F),u=g.length-k.results.length;if(t.signal?.aborted&&u>0){let s=k.failures.filter(p=>f.has(p));return{...k,refusals:d,unreachable:h,failures:[...b,...s],cancelled:!0}}return{results:k.results,refusals:d,unreachable:h,failures:[...b,...k.failures],inputBytes:k.inputBytes,outputBytes:k.outputBytes}}export{D as a,ne as b};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as O}from"./chunk-UUTBDIFR.js";import{a as E}from"./chunk-PON65UTS.js";import{ha as k,ia as P,ja as L,za as b}from"./chunk-CCNRNCRU.js";import{spawn as N}from"node:child_process";var A=new Map;function q(e,n,t={}){let r=()=>(t.onStart?.(),e.serve?C(e,n,t):$(e,n,t)),o=(t.platform??process.platform)==="darwin"?void 0:e.id,s=(A.get(o)??Promise.resolve()).then(()=>e.id===void 0?r():O(e.id,r,{...t.what!==void 0?{what:t.what}:{},...t.signal!==void 0?{signal:t.signal}:{},...t.onWait!==void 0?{onWait:t.onWait}:{}}));return A.set(o,s.catch(()=>{})),s}function J(e){let n=e.indexOf("--in");return(n>=0?e[n+1]:e[0])??""}function W(e){if(e.startsWith('{"progress"'))try{let n=JSON.parse(e);return typeof n.progress!="number"||typeof n.of!="number"||n.of<=0?void 0:{done:n.progress,of:n.of}}catch{return}}function F(e,n,t,r,o,i){return e==="no-subject"?k(t):e==="boost-too-large"?P(t,r.maxScale??0):e==="boost-too-slow"?L(t,i??0,Number(o[o.indexOf("--scale")+1])):b(t,new Error(n))}function T(e){return{width:Number(e.width),height:Number(e.height),ms:Number(e.ms),...typeof e.hasAlpha=="boolean"?{hasAlpha:e.hasAlpha}:{},...Array.isArray(e.pages)?{pages:e.pages}:{}}}function I(e,n,t,r){return F(String(e.code??""),String(e.message??""),n,t,r,typeof e.seconds=="number"?e.seconds:void 0)}function $(e,n,t){let{signal:r}=t,o=t.subject??J(n);return r?.aborted?Promise.reject(r.reason??new Error("aborted")):new Promise((i,s)=>{let[f,w]=e.kind==="node"?[process.execPath,[e.entry,...n]]:[e.entry,n],l=E(N(f,w,{stdio:["ignore","pipe","pipe"]})),m="",d="",g=!1,a=u=>{g||(g=!0,r?.removeEventListener("abort",R),u())},R=()=>l.kill("SIGKILL");l.on("exit",()=>{r?.aborted&&a(()=>s(r.reason??new Error("aborted")))}),r?.addEventListener("abort",R,{once:!0});let S="";l.stdout.setEncoding("utf8").on("data",u=>{if(m+=u,!t.onProgress&&!t.onLine)return;let v=(S+u).split(`
3
+ import{c as O}from"./chunk-56B3VZCM.js";import{a as E}from"./chunk-PON65UTS.js";import{Ca as b,ka as k,la as P,ma as L}from"./chunk-PNPAHKJR.js";import{spawn as N}from"node:child_process";var A=new Map;function q(e,n,t={}){let r=()=>(t.onStart?.(),e.serve?C(e,n,t):$(e,n,t)),o=(t.platform??process.platform)==="darwin"?void 0:e.id,s=(A.get(o)??Promise.resolve()).then(()=>e.id===void 0?r():O(e.id,r,{...t.what!==void 0?{what:t.what}:{},...t.signal!==void 0?{signal:t.signal}:{},...t.onWait!==void 0?{onWait:t.onWait}:{}}));return A.set(o,s.catch(()=>{})),s}function J(e){let n=e.indexOf("--in");return(n>=0?e[n+1]:e[0])??""}function W(e){if(e.startsWith('{"progress"'))try{let n=JSON.parse(e);return typeof n.progress!="number"||typeof n.of!="number"||n.of<=0?void 0:{done:n.progress,of:n.of}}catch{return}}function F(e,n,t,r,o,i){return e==="no-subject"?k(t):e==="boost-too-large"?P(t,r.maxScale??0):e==="boost-too-slow"?L(t,i??0,Number(o[o.indexOf("--scale")+1])):b(t,new Error(n))}function T(e){return{width:Number(e.width),height:Number(e.height),ms:Number(e.ms),...typeof e.hasAlpha=="boolean"?{hasAlpha:e.hasAlpha}:{},...Array.isArray(e.pages)?{pages:e.pages}:{}}}function I(e,n,t,r){return F(String(e.code??""),String(e.message??""),n,t,r,typeof e.seconds=="number"?e.seconds:void 0)}function $(e,n,t){let{signal:r}=t,o=t.subject??J(n);return r?.aborted?Promise.reject(r.reason??new Error("aborted")):new Promise((i,s)=>{let[f,w]=e.kind==="node"?[process.execPath,[e.entry,...n]]:[e.entry,n],l=E(N(f,w,{stdio:["ignore","pipe","pipe"]})),m="",d="",g=!1,a=u=>{g||(g=!0,r?.removeEventListener("abort",R),u())},R=()=>l.kill("SIGKILL");l.on("exit",()=>{r?.aborted&&a(()=>s(r.reason??new Error("aborted")))}),r?.addEventListener("abort",R,{once:!0});let S="";l.stdout.setEncoding("utf8").on("data",u=>{if(m+=u,!t.onProgress&&!t.onLine)return;let v=(S+u).split(`
4
4
  `);S=v.pop()??"";for(let h of v){let c=W(h);if(c){t.onProgress?.(c.done,c.of);continue}if(!(!t.onLine||!h.trim().startsWith("{")))try{let y=JSON.parse(h);"ok"in y||t.onLine(y)}catch{}}}),l.stderr.setEncoding("utf8").on("data",u=>{d+=u}),l.on("error",u=>a(()=>s(b(o,u)))),l.on("close",u=>a(()=>{let v=m.split(`
5
5
  `).filter(y=>y.trim().startsWith("{")).at(-1),h;try{h=v?JSON.parse(v):void 0}catch{h=void 0}let c=h;if(c&&c.ok===!0&&u===0)return i(T(c));if(c&&c.ok===!1)return s(I(c,o,t,n));s(b(o,new Error(`extension exited ${u} without a result: ${(d||m).trim().slice(-500)}`)))}))})}var M=5e3,x=class{constructor(n){this.ext=n;let[t,r]=n.kind==="node"?[process.execPath,[n.entry,"--serve"]]:[n.entry,["--serve"]];this.child=E(N(t,r,{stdio:["pipe","pipe","pipe"]}),{pooled:!0});let o="";this.child.stdout.setEncoding("utf8").on("data",i=>{let s=(o+i).split(`
6
6
  `);o=s.pop()??"";for(let f of s)this.listener?.line(f)}),this.child.stderr.setEncoding("utf8").on("data",i=>{this.said=(this.said+i).slice(-2e3)}),this.child.stdin.on("error",()=>{}),this.child.on("error",i=>{this.gone(),this.listener?.error(i)}),this.child.on("exit",()=>{this.gone(),this.listener?.exit()}),this.child.on("close",(i,s)=>this.listener?.close(s??`exit ${i}`))}ext;child;listener;exited=!1;said="";idle;gone(){this.exited=!0,clearTimeout(this.idle),p.get(this.ext.entry)===this&&p.delete(this.ext.entry)}holdAll(n){for(let t of[this.child,this.child.stdin,this.child.stdout,this.child.stderr])t[n]?.()}hold(n){clearTimeout(this.idle),this.said="",this.listener=n,this.holdAll("ref")}rest(n){this.listener=void 0,this.holdAll("unref"),this.idle=setTimeout(()=>{this.close()},n),this.idle.unref()}close(){return new Promise(n=>{if(this.exited)return n();this.gone();let t=setTimeout(()=>this.child.kill("SIGKILL"),3e3);t.unref(),this.child.once("exit",()=>{clearTimeout(t),n()}),this.child.stdin.end()})}},p=new Map;function j(e){for(let r of[...p.values()])e.id!==void 0&&r.ext.id===e.id&&r.ext.entry!==e.entry&&!r.listener&&r.close();let n=p.get(e.entry);if(n&&!n.exited&&!n.listener)return n;let t=new x(e);return p.set(e.entry,t),t}async function D(e){await Promise.all([...p.values()].filter(n=>(e===void 0||n.ext.id===e)&&!n.listener).map(n=>n.close()))}function C(e,n,t){let{signal:r}=t,o=t.subject??J(n);if(r?.aborted)return Promise.reject(r.reason??new Error("aborted"));let i=j(e);return new Promise((s,f)=>{let w=!1,l=d=>{w||(w=!0,r?.removeEventListener("abort",m),d())},m=()=>i.child.kill("SIGKILL");r?.addEventListener("abort",m,{once:!0}),i.hold({line(d){let g=W(d);if(g)return t.onProgress?.(g.done,g.of);if(!d.trim().startsWith("{"))return;let a;try{a=JSON.parse(d)}catch{return}if(!("ok"in a))return t.onLine?.(a);l(()=>{i.rest(t.idleMs??M),a.ok===!0?s(T(a)):f(I(a,o,t,n))})},exit(){r?.aborted&&l(()=>f(r.reason??new Error("aborted")))},close(d){l(()=>f(b(o,new Error(`extension exited ${d} without a result: ${i.said.trim().slice(-500)}`))))},error(d){l(()=>f(b(o,d)))}}),i.child.stdin.write(`${JSON.stringify({args:n})}
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{a as b,c as F}from"./chunk-ECA4PW5T.js";import{a as y}from"./chunk-PISCJKIG.js";import{j as h}from"./chunk-NMGQGYVM.js";import{a as c,e as m,f as p}from"./chunk-CCNRNCRU.js";import{open as w,readdir as x,stat as k}from"node:fs/promises";import{extname as S,join as v,resolve as K}from"node:path";function A(e){return e.startsWith(".")||/\.(crdownload|part|download|tmp)$/i.test(e)}function R(e){return e.kind==="image"?"images":e.format==="pdf"?"pdfs":"documents"}var O=new Set(Object.values(c).flatMap(e=>e.extensions));async function M(e){let i=await w(e,"r"),t=Buffer.alloc(4096),r=0;try{r=(await i.read(t,0,t.length,0)).bytesRead}finally{await i.close()}let n=t.subarray(0,r),o=(s,f)=>n.subarray(s,s+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":n[0]===0&&n[1]===0&&n[2]===1&&(n[3]===186||n[3]===179)?"video":o(0,3)==="ID3"||o(0,4)==="fLaC"||o(0,4)==="OggS"||o(0,4)==="FORM"&&/^AIF[FC]$/.test(o(8,4))||n[0]===255&&n[1]!==void 0&&(n[1]&224)===224?"audio":r>0&&!n.includes(0)&&j(n)?"text":"other"}function j(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e,{stream:!0}),!0}catch{return!1}}var I=["images","pdfs","documents","videos","audio","other"];function E(e,i){if(e==="videos"||e==="audio")return"not yet supported";if(e==="other")return i.every(t=>t==="text")?i.length===1?"a text file":"text files":"not supported"}async function W(e){let i=K(e),t=await x(i,{withFileTypes:!0}),r=[],n=[],o=new Map,s=[],f=0;for(let d of t.sort((u,a)=>u.name.localeCompare(a.name)))!d.isFile()||A(d.name)||s.push(v(i,d.name));for(let d of await C(s))if(d.kind==="source")r.push(d.source),f+=d.source.bytes;else if(d.kind==="failed")n.push(d.failure),f+=d.bytes;else{let u=d.kind,a=o.get(u)??{bytes:0,sniffed:[]};a.bytes+=d.bytes,a.sniffed.push(d.sniffed),o.set(u,a),f+=d.bytes}let l=g(r);for(let d of I){let u=o.get(d);if(!u)continue;let a=E(d,u.sniffed);l.push({id:d,count:u.sniffed.length,bytes:u.bytes,sources:[],...a===void 0?{}:{why:a}})}return{dir:i,sources:r,failures:n,kinds:l,bytes:f,paths:s}}async function C(e){let i=[];return await F(e,b(),async(t,r)=>{try{i[r]={read:await D(t)}}catch(n){i[r]={error:n}}}),i.map(t=>{if("error"in t)throw t.error;return t.read})}function g(e){let i=[];for(let t of I){let r=e.filter(n=>R(n)===t);r.length>0&&i.push({id:t,count:r.length,bytes:r.reduce((n,o)=>n+o.bytes,0),sources:r})}return i.sort((t,r)=>r.count-t.count)}function _(e,i=[]){let t=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),n=g(r);for(let o of["videos","audio"]){let s=t.filter(f=>c[f.format].media==="video"==(o==="videos"));if(s.length>0){let f=s.reduce((l,d)=>l+d.bytes,0);n.push({id:o,count:s.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:n,bytes:e.reduce((o,s)=>o+s.bytes,0),paths:e.map(o=>o.path)}}async function D(e){let i=()=>k(e).then(t=>t.size,()=>0);try{let t=await h(e);if(t.kind==="media"){let r=c[t.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:t.bytes}}return{kind:"source",source:t}}catch(t){let r=await i(),n=await M(e).catch(()=>"other");if(n==="video"||n==="audio")return{kind:n==="video"?"videos":"audio",sniffed:n,bytes:r};if(O.has(S(e).toLowerCase())){let o=p(t)?t:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:n,bytes:r}}}function N(e){let i=t=>e.every(r=>r.format===t||y(r).includes(t))&&e.some(r=>r.format!==t);return Object.keys(c).filter(i)}function Q(e,i){let t=N(e),r=e[0],n=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=n&&t.includes(n)?n:t[0];if(o)return P(e,o,i)}function P(e,i,t){let r={target:i};return c[i].lossy&&(r.quality=m(i,t)),e.some(n=>n.kind==="document"&&n.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{A as a,R as b,M as c,W as d,_ as e,D as f,N as g,Q as h,P as i};
3
+ import{a as b,c as F}from"./chunk-3OCPO5V6.js";import{a as y}from"./chunk-TQEGSODD.js";import{q as h}from"./chunk-ULX4ZD2Y.js";import{d as c,h as m,i as p}from"./chunk-PNPAHKJR.js";import{open as w,readdir as x,stat as k}from"node:fs/promises";import{extname as S,join as v,resolve as K}from"node:path";function A(e){return e.startsWith(".")||/\.(crdownload|part|download|tmp)$/i.test(e)}function R(e){return e.kind==="image"?"images":e.format==="pdf"?"pdfs":"documents"}var O=new Set(Object.values(c).flatMap(e=>e.extensions));async function M(e){let i=await w(e,"r"),t=Buffer.alloc(4096),r=0;try{r=(await i.read(t,0,t.length,0)).bytesRead}finally{await i.close()}let n=t.subarray(0,r),o=(s,f)=>n.subarray(s,s+f).toString("latin1");return o(4,4)==="ftyp"?/^(M4A |M4B |M4P )$/.test(o(8,4))?"audio":"video":n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163?"video":o(0,4)==="RIFF"?o(8,4)==="WAVE"?"audio":o(8,3)==="AVI"?"video":"other":n[0]===0&&n[1]===0&&n[2]===1&&(n[3]===186||n[3]===179)?"video":o(0,3)==="ID3"||o(0,4)==="fLaC"||o(0,4)==="OggS"||o(0,4)==="FORM"&&/^AIF[FC]$/.test(o(8,4))||n[0]===255&&n[1]!==void 0&&(n[1]&224)===224?"audio":r>0&&!n.includes(0)&&j(n)?"text":"other"}function j(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e,{stream:!0}),!0}catch{return!1}}var I=["images","pdfs","documents","videos","audio","other"];function E(e,i){if(e==="videos"||e==="audio")return"not yet supported";if(e==="other")return i.every(t=>t==="text")?i.length===1?"a text file":"text files":"not supported"}async function W(e){let i=K(e),t=await x(i,{withFileTypes:!0}),r=[],n=[],o=new Map,s=[],f=0;for(let d of t.sort((u,a)=>u.name.localeCompare(a.name)))!d.isFile()||A(d.name)||s.push(v(i,d.name));for(let d of await C(s))if(d.kind==="source")r.push(d.source),f+=d.source.bytes;else if(d.kind==="failed")n.push(d.failure),f+=d.bytes;else{let u=d.kind,a=o.get(u)??{bytes:0,sniffed:[]};a.bytes+=d.bytes,a.sniffed.push(d.sniffed),o.set(u,a),f+=d.bytes}let l=g(r);for(let d of I){let u=o.get(d);if(!u)continue;let a=E(d,u.sniffed);l.push({id:d,count:u.sniffed.length,bytes:u.bytes,sources:[],...a===void 0?{}:{why:a}})}return{dir:i,sources:r,failures:n,kinds:l,bytes:f,paths:s}}async function C(e){let i=[];return await F(e,b(),async(t,r)=>{try{i[r]={read:await D(t)}}catch(n){i[r]={error:n}}}),i.map(t=>{if("error"in t)throw t.error;return t.read})}function g(e){let i=[];for(let t of I){let r=e.filter(n=>R(n)===t);r.length>0&&i.push({id:t,count:r.length,bytes:r.reduce((n,o)=>n+o.bytes,0),sources:r})}return i.sort((t,r)=>r.count-t.count)}function _(e,i=[]){let t=e.filter(o=>o.kind==="media"),r=e.filter(o=>o.kind!=="media"),n=g(r);for(let o of["videos","audio"]){let s=t.filter(f=>c[f.format].media==="video"==(o==="videos"));if(s.length>0){let f=s.reduce((l,d)=>l+d.bytes,0);n.push({id:o,count:s.length,bytes:f,sources:[],why:"one at a time"})}}return{dir:"",sources:r,failures:i,kinds:n,bytes:e.reduce((o,s)=>o+s.bytes,0),paths:e.map(o=>o.path)}}async function D(e){let i=()=>k(e).then(t=>t.size,()=>0);try{let t=await h(e);if(t.kind==="media"){let r=c[t.format].media==="video";return{kind:r?"videos":"audio",sniffed:r?"video":"audio",bytes:t.bytes}}return{kind:"source",source:t}}catch(t){let r=await i(),n=await M(e).catch(()=>"other");if(n==="video"||n==="audio")return{kind:n==="video"?"videos":"audio",sniffed:n,bytes:r};if(O.has(S(e).toLowerCase())){let o=p(t)?t:void 0;if(o)return{kind:"failed",failure:{path:e,error:o},bytes:r}}return{kind:"other",sniffed:n,bytes:r}}}function N(e){let i=t=>e.every(r=>r.format===t||y(r).includes(t))&&e.some(r=>r.format!==t);return Object.keys(c).filter(i)}function Q(e,i){let t=N(e),r=e[0],n=r?.kind==="image"?"webp":r?.format==="pdf"?"png":void 0,o=n&&t.includes(n)?n:t[0];if(o)return P(e,o,i)}function P(e,i,t){let r={target:i};return c[i].lossy&&(r.quality=m(i,t)),e.some(n=>n.kind==="document"&&n.format==="pdf")&&(i==="png"||i==="jpeg")&&(r.dpi=150),r}export{A as a,R as b,M as c,W as d,_ as e,D as f,N as g,Q as h,P as i};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as i,d,e as p,f as a}from"./chunk-4MZV4SRU.js";import{P as n}from"./chunk-CCNRNCRU.js";import{stat as l}from"node:fs/promises";import{dirname as h,resolve as g}from"node:path";var C=["output","theme","quality","update-check"];async function b(s){if(s.action==="path")return{stdout:[i()],exitCode:0,config:{path:i()},warnings:[]};if(s.action==="list"){let{prefs:t,warning:o}=await p(),f=[`output ${t.defaultOutput}`,`theme ${t.theme??"not set"}`,`quality ${t.quality??"not set"}`,`update-check ${t.updateCheck===!1?"off":"on"}`,"",i()];return o!==void 0&&f.unshift(`\u26A0 ${o}`,""),{stdout:f,exitCode:0,config:{output:t.defaultOutput,theme:t.theme??null,quality:t.quality??null,"update-check":t.updateCheck===!1?"off":"on",path:i()},warnings:o===void 0?[]:[{code:"config-unreadable",message:o}]}}let{key:c,value:e}=s;if(c==="theme"){if(e!=="dark"&&e!=="light")throw n(`Theme must be dark or light, not ${e}.`);return await a({theme:e}),{stdout:[`theme is now ${e}`],exitCode:0,config:{theme:e},warnings:[]}}if(c==="quality"){let t=Number(e);if(!Number.isInteger(t)||t<1||t>100)throw n(`Quality must be a whole number between 1 and 100, not ${e}.`);return await a({quality:t}),{stdout:[`quality is now ${t}`],exitCode:0,config:{quality:t},warnings:[]}}if(c==="update-check"){if(e!=="on"&&e!=="off")throw n(`update-check must be on or off, not ${e}.`);return await a({updateCheck:e==="on"}),{stdout:[`update-check is now ${e}`],exitCode:0,config:{"update-check":e},warnings:[]}}if(e.trim().length===0)throw n("Output must be a folder path.");let u=g(d(e)),r=u;for(;;){let t=await l(r).catch(f=>f);if(!(t instanceof Error)){if(!t.isDirectory())throw n("Output must be a folder path.");break}if(t.code==="ENOTDIR")throw n("Output must be a folder path.");let o=h(r);if(o===r)break;r=o}return await a({defaultOutput:u}),{stdout:[`output is now ${u}`],exitCode:0,config:{output:u},warnings:[]}}export{C as a,b};
3
+ import{c as i,d,e as p,f as a}from"./chunk-ZL7E7PZN.js";import{S as n}from"./chunk-PNPAHKJR.js";import{stat as l}from"node:fs/promises";import{dirname as h,resolve as g}from"node:path";var C=["output","theme","quality","update-check"];async function b(s){if(s.action==="path")return{stdout:[i()],exitCode:0,config:{path:i()},warnings:[]};if(s.action==="list"){let{prefs:t,warning:o}=await p(),f=[`output ${t.defaultOutput}`,`theme ${t.theme??"not set"}`,`quality ${t.quality??"not set"}`,`update-check ${t.updateCheck===!1?"off":"on"}`,"",i()];return o!==void 0&&f.unshift(`\u26A0 ${o}`,""),{stdout:f,exitCode:0,config:{output:t.defaultOutput,theme:t.theme??null,quality:t.quality??null,"update-check":t.updateCheck===!1?"off":"on",path:i()},warnings:o===void 0?[]:[{code:"config-unreadable",message:o}]}}let{key:c,value:e}=s;if(c==="theme"){if(e!=="dark"&&e!=="light")throw n(`Theme must be dark or light, not ${e}.`);return await a({theme:e}),{stdout:[`theme is now ${e}`],exitCode:0,config:{theme:e},warnings:[]}}if(c==="quality"){let t=Number(e);if(!Number.isInteger(t)||t<1||t>100)throw n(`Quality must be a whole number between 1 and 100, not ${e}.`);return await a({quality:t}),{stdout:[`quality is now ${t}`],exitCode:0,config:{quality:t},warnings:[]}}if(c==="update-check"){if(e!=="on"&&e!=="off")throw n(`update-check must be on or off, not ${e}.`);return await a({updateCheck:e==="on"}),{stdout:[`update-check is now ${e}`],exitCode:0,config:{"update-check":e},warnings:[]}}if(e.trim().length===0)throw n("Output must be a folder path.");let u=g(d(e)),r=u;for(;;){let t=await l(r).catch(f=>f);if(!(t instanceof Error)){if(!t.isDirectory())throw n("Output must be a folder path.");break}if(t.code==="ENOTDIR")throw n("Output must be a folder path.");let o=h(r);if(o===r)break;r=o}return await a({defaultOutput:u}),{stdout:[`output is now ${u}`],exitCode:0,config:{output:u},warnings:[]}}export{C as a,b};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{o as x}from"./chunk-FWVE3GNA.js";import{w as _}from"./chunk-UN5DSJE2.js";import{b as y,d as h}from"./chunk-KXKQDFHX.js";import{D as l}from"./chunk-CCNRNCRU.js";import{readFile as D,rm as L}from"node:fs/promises";var S=new Set(["pdf"]),C=new Set(["jpeg","png"]),R=new Set(["convert"]),w;function A(){return w??=h().then(e=>e.PDFiumLibrary.init()),w}async function F(e,n){return await(await A()).loadDocument(e,n)}async function H(e,n){let r;try{r=await F(await D(e),n)}catch{return!1}return r.destroy(),!0}async function J(e){let n=await F(e);try{let r=[];for(let i=0;i<n.getPageCount();i++)r.push(n.getPage(i).getText());return r}finally{n.destroy()}}var O=3,U=3;function j(e,n,r,i){let t=r*i;if(t<=0)return 0;let o=e.wasmExports.malloc(16);try{let c=0;for(let a=0;a<e._FPDFPage_CountObjects(n);a++){let u=e._FPDFPage_GetObject(n,a);if(!u||e._FPDFPageObj_GetType(u)!==U||!e._FPDFPageObj_GetBounds(u,o,o+4,o+8,o+12))continue;let[s=0,p=0,P=0,m=0]=new Float32Array(e.HEAPU8.buffer,o,4),g=Math.min(P,r)-Math.max(s,0),d=Math.min(m,i)-Math.max(p,0);g>0&&d>0&&(c=Math.max(c,g*d/t))}return c}finally{e.wasmExports.free(o)}}async function W(e){let n=await F(e);try{let r=[];for(let i=0;i<n.getPageCount();i++){let{module:t,pageIdx:o}=n.getPage(i),c=t._FPDF_GetPageWidthF(o),a=t._FPDF_GetPageHeightF(o),u=[],s=t._FPDFPage_GetRotation(o)===0?t._FPDFText_LoadPage(o):0;if(s){let p=t.wasmExports.malloc(16);try{let P=t._FPDFText_CountChars(s);for(let m=0;m<P;m++){let g=t._FPDFText_GetUnicode(s,m),d=g>0&&g<=1114111?String.fromCodePoint(g):"\uFFFD";if(t._FPDFText_IsGenerated(s,m)||!t._FPDFText_GetLooseCharBox(s,m,p)){u.push({char:d});continue}let[T=0,G=0,E=0,I=0]=new Float32Array(t.HEAPU8.buffer,p,4),b=t._FPDFText_GetTextObject(s,m),f=b!==0&&t._FPDFTextObj_GetTextRenderMode(b)===O;u.push({char:d,box:[T,G,E,I],...f?{hidden:f}:{}})}}finally{t.wasmExports.free(p),t._FPDFText_ClosePage(s)}}r.push({width:c,height:a,chars:u,picture:j(t,o,c,a)})}return r}finally{n.destroy()}}var q={id:"pdfium",reads:S,writes:C,ops:R,probe(){throw new Error("pdfium does not probe; engines/pdf.ts classifies PDFs")},async run(e,n){if(e.op!=="convert")throw new Error(`pdfium cannot ${e.op}`);let r=e.sources[0];if(r.kind!=="document")throw new Error("the pdfium engine can only rasterise a document source");if(r.encrypted&&e.options.password===void 0)throw l(r.path);let i=e.options.dpi??150,t=e.options.pages??Array.from({length:r.pages},(a,u)=>u);if(t.length!==e.outputs.length)throw new Error(`pdfium was given ${t.length} pages but ${e.outputs.length} outputs`);for(let a of t)if(a<0||a>=r.pages)throw new Error(`pdfium was asked for page ${a}, but ${r.path} has ${r.pages} pages`);let o=await y(),c=await F(await D(r.path),e.options.password);try{let a=[],u=0;try{for(let[s,p]of t.entries()){let P=await c.getPage(p).render({scale:i/72,render:"bitmap",transparent:!0}),m=o(P.data,{raw:{width:P.width,height:P.height,channels:4}}).flatten({background:e.options.background}),g=await x(m,e.target,e.options.quality).toBuffer(),d=e.outputs[s];u+=await _(d,g),a.push(d),n({phase:"page",done:s+1,total:t.length})}}catch(s){throw await Promise.all(a.map(p=>L(p,{force:!0}))),s}return{job:e,outputBytes:u,warnings:[]}}finally{c.destroy()}}};export{F as a,H as b,J as c,W as d,q as e};
3
+ import{o as x}from"./chunk-JPASVE56.js";import{w as _}from"./chunk-JZM37DG2.js";import{b as y,d as h}from"./chunk-KXKQDFHX.js";import{G as l}from"./chunk-PNPAHKJR.js";import{readFile as D,rm as L}from"node:fs/promises";var S=new Set(["pdf"]),C=new Set(["jpeg","png"]),R=new Set(["convert"]),w;function A(){return w??=h().then(e=>e.PDFiumLibrary.init()),w}async function F(e,n){return await(await A()).loadDocument(e,n)}async function H(e,n){let r;try{r=await F(await D(e),n)}catch{return!1}return r.destroy(),!0}async function J(e){let n=await F(e);try{let r=[];for(let i=0;i<n.getPageCount();i++)r.push(n.getPage(i).getText());return r}finally{n.destroy()}}var O=3,U=3;function j(e,n,r,i){let t=r*i;if(t<=0)return 0;let o=e.wasmExports.malloc(16);try{let c=0;for(let a=0;a<e._FPDFPage_CountObjects(n);a++){let u=e._FPDFPage_GetObject(n,a);if(!u||e._FPDFPageObj_GetType(u)!==U||!e._FPDFPageObj_GetBounds(u,o,o+4,o+8,o+12))continue;let[s=0,p=0,P=0,m=0]=new Float32Array(e.HEAPU8.buffer,o,4),g=Math.min(P,r)-Math.max(s,0),d=Math.min(m,i)-Math.max(p,0);g>0&&d>0&&(c=Math.max(c,g*d/t))}return c}finally{e.wasmExports.free(o)}}async function W(e){let n=await F(e);try{let r=[];for(let i=0;i<n.getPageCount();i++){let{module:t,pageIdx:o}=n.getPage(i),c=t._FPDF_GetPageWidthF(o),a=t._FPDF_GetPageHeightF(o),u=[],s=t._FPDFPage_GetRotation(o)===0?t._FPDFText_LoadPage(o):0;if(s){let p=t.wasmExports.malloc(16);try{let P=t._FPDFText_CountChars(s);for(let m=0;m<P;m++){let g=t._FPDFText_GetUnicode(s,m),d=g>0&&g<=1114111?String.fromCodePoint(g):"\uFFFD";if(t._FPDFText_IsGenerated(s,m)||!t._FPDFText_GetLooseCharBox(s,m,p)){u.push({char:d});continue}let[T=0,G=0,E=0,I=0]=new Float32Array(t.HEAPU8.buffer,p,4),b=t._FPDFText_GetTextObject(s,m),f=b!==0&&t._FPDFTextObj_GetTextRenderMode(b)===O;u.push({char:d,box:[T,G,E,I],...f?{hidden:f}:{}})}}finally{t.wasmExports.free(p),t._FPDFText_ClosePage(s)}}r.push({width:c,height:a,chars:u,picture:j(t,o,c,a)})}return r}finally{n.destroy()}}var q={id:"pdfium",reads:S,writes:C,ops:R,probe(){throw new Error("pdfium does not probe; engines/pdf.ts classifies PDFs")},async run(e,n){if(e.op!=="convert")throw new Error(`pdfium cannot ${e.op}`);let r=e.sources[0];if(r.kind!=="document")throw new Error("the pdfium engine can only rasterise a document source");if(r.encrypted&&e.options.password===void 0)throw l(r.path);let i=e.options.dpi??150,t=e.options.pages??Array.from({length:r.pages},(a,u)=>u);if(t.length!==e.outputs.length)throw new Error(`pdfium was given ${t.length} pages but ${e.outputs.length} outputs`);for(let a of t)if(a<0||a>=r.pages)throw new Error(`pdfium was asked for page ${a}, but ${r.path} has ${r.pages} pages`);let o=await y(),c=await F(await D(r.path),e.options.password);try{let a=[],u=0;try{for(let[s,p]of t.entries()){let P=await c.getPage(p).render({scale:i/72,render:"bitmap",transparent:!0}),m=o(P.data,{raw:{width:P.width,height:P.height,channels:4}}).flatten({background:e.options.background}),g=await x(m,e.target,e.options.quality).toBuffer(),d=e.outputs[s];u+=await _(d,g),a.push(d),n({phase:"page",done:s+1,total:t.length})}}catch(s){throw await Promise.all(a.map(p=>L(p,{force:!0}))),s}return{job:e,outputBytes:u,warnings:[]}}finally{c.destroy()}}};export{F as a,H as b,J as c,W as d,q as e};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as d,c as S,d as y,e as T,f as R,g as w}from"./chunk-EYOO35US.js";import{P as A}from"./chunk-CCNRNCRU.js";var I={set:"tailwind",start:50,end:950,count:11},C=["tailwind","even","radix"],F=[0,50,100,150,200,250,300,350,400,450],_=[550,600,650,700,750,800,850,900,950,1e3],D=Array.from({length:19},(e,r)=>r+3),v=[20,50,100,150,200,260,330,420,500,560,750,920],U=8;function k({set:e,start:r,end:t,count:o}){if(!C.includes(e))return`The set must be tailwind, even or radix; got ${e}.`;if(e!=="radix"){if(!F.includes(r))return r%50===0?`The start must be from 0 to 450, so the colour (500) stays in the scale; got ${r}.`:`The start must be a multiple of 50; got ${r}.`;if(!_.includes(t))return t%50===0?`The end must be from 550 to 1000, so the colour (500) stays in the scale; got ${t}.`:`The end must be a multiple of 50; got ${t}.`;if(e==="even"&&!D.includes(o))return`An even set has 3 to 21 steps; got ${o}.`}}function x(e){let{set:r,start:t,end:o,count:n}=e;if(r==="radix")return v.map((m,l)=>({step:l+1,at:m}));if(r==="tailwind"){let m=new Set([t,o,500]);for(let l=Math.ceil((t+1)/100)*100;l<o;l+=100)m.add(l);return[...m].sort((l,c)=>l-c).map(l=>({step:l,at:l}))}let s=n-1,b=Math.round(s*(500-t)/(o-t)),a=Math.max(1,Math.min(s-1,b)),i=s-a,u=[];for(let m=0;m<=a;m++)u.push(t+(500-t)*m/a);for(let m=1;m<=i;m++)u.push(500+(o-500)*m/i);for(let m of[10,5,1]){let l=u.map(c=>Math.round(c/m)*m);if(new Set(l).size===l.length)return u.map((c,f)=>({step:l[f],at:c}))}return u.map(m=>({step:m,at:m}))}function B(e){return x(e).map(r=>r.step)}var oe=B(I);function se(e){return e.set==="radix"?U:x(e).findIndex(r=>r.at===500)}var $=[[50,1],[100,.86],[200,.68],[300,.46],[400,.22],[500,0]],Y=[[500,0],[600,.2],[700,.4],[800,.6],[900,.8],[950,1]];function G(e,r){for(let t=1;t<e.length;t++){let[o,n]=e[t-1],[s,b]=e[t];if(r<=s)return n+(b-n)*(r-o)/(s-o)}return e[e.length-1][1]}var H=.995,V=.35,W=5e-4;function ae(e,r=I){let t=k(r);if(t)throw A(t,"Try: Tailwind, from 50 to 950.");let{L:o,C:n,h:s}=R(S(e)),b=n<W,a=Math.max(.975,o),i=o<.16?.42*o:Math.max(.16,.42*o),u=x(r),m=u[u.length-1]?.at===1e3;return u.map(({step:l,at:c})=>{if(c===500)return{step:l,at:c,rgb:{...e},hex:d(e),reference:!0};let f,p;if(c>=50&&c<500){let h=G($,c);f=o+(a-o)*h,p=n*(1-.88*h)}else if(c<50){let h=(50-c)/50;f=a+(Math.max(H,a)-a)*h,p=n*.12*(1-h)}else if(c<=950||m){let h=m?(c-500)/500:G(Y,c);f=o-(o-i)*h,p=n*(1-.45*h)}else{let h=(c-950)/50;f=i*(1-V*h),p=n*.55*(1-.4*h)}for(b&&(p=0);p>0&&!T(w({L:f,C:p,h:s}));)p-=.002;let g=y(w({L:f,C:Math.max(0,p),h:s}));return{step:l,at:c,rgb:g,hex:d(g),reference:!1}})}var E=(e,r,t)=>(e.L[r]-t[0])**2+(e.A[r]-t[1])**2+(e.B[r]-t[2])**2;function X(e,r){let t=e.L.length,o=[0,0,0];for(let b=0;b<t;b++)o[0]+=e.L[b],o[1]+=e.A[b],o[2]+=e.B[b];let n=[[o[0]/t,o[1]/t,o[2]/t]],s=new Float64Array(t).fill(Number.POSITIVE_INFINITY);for(;n.length<r;){let b=n[n.length-1],a=0,i=-1;for(let u=0;u<t;u++){let m=E(e,u,b);m<s[u]&&(s[u]=m),s[u]>i&&(i=s[u],a=u)}n.push([e.L[a],e.A[a],e.B[a]])}return n}function P(e,r,t){let o=0,n=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s++){let b=E(e,r,t[s]);b<n&&(n=b,o=s)}return o}function q(e,r){let t=e.L.length,o=X(e,r),n=new Int32Array(t).fill(-1);for(let b=0;b<30;b++){let a=0;for(let u=0;u<t;u++){let m=P(e,u,o);n[u]!==m&&(n[u]=m,a++)}let i=o.map(()=>[0,0,0,0]);for(let u=0;u<t;u++){let m=i[n[u]];m[0]=m[0]+e.L[u],m[1]=m[1]+e.A[u],m[2]=m[2]+e.B[u],m[3]=m[3]+1}if(i.forEach(([u,m,l,c],f)=>{c&&(o[f]=[u/c,m/c,l/c])}),a===0)break}let s=o.map(b=>({centre:b,members:[]}));for(let b=0;b<t;b++)s[n[b]]?.members.push(b);return s.filter(b=>b.members.length>0)}function z(e,r){let t=e;for(;;){let o,n=r**2;for(let c=0;c<t.length;c++)for(let f=c+1;f<t.length;f++){let p=t[c].centre,g=t[f].centre,h=(p[0]-g[0])**2+(p[1]-g[1])**2+(p[2]-g[2])**2;h<n&&(n=h,o=[c,f])}if(!o)return t;let[s,b]=o,a=t[s],i=t[b],u=a.members.length,m=i.members.length,l=a.centre.map((c,f)=>(c*u+i.centre[f]*m)/(u+m));t=t.filter((c,f)=>f!==s&&f!==b),t.push({centre:l,members:[...a.members,...i.members]})}}function Q(e,r,t){let o=e.L.length,n=[...r].sort((a,i)=>i.members.length-a.members.length),s=n.filter((a,i)=>i===0||a.members.length/o>=t),b=s.map(a=>a.centre);for(let a of n)if(!s.includes(a))for(let i of a.members)s[P(e,i,b)].members.push(i);return s}function M(e,r,t,o){let n=e.length;if(n===0)return[];let s={L:e,A:r,B:t},b=z(q(s,Math.min(o.k,n)),o.merge);return Q(s,b,o.minShare)}var j={k:8,merge:.06,minShare:.015},J={k:4,merge:.03,minShare:.02},K=-1,Z=-2,L=128,ee=64,O=(e,r)=>({r:e.rgba[r*4],g:e.rgba[r*4+1],b:e.rgba[r*4+2]});function N(e,r,t){let o=r.length,n=new Float64Array(o),s=new Float64Array(o),b=new Float64Array(o);return r.forEach((a,i)=>{let u=S(O(e,a));n[i]=u.L,s[i]=u.a,b[i]=u.b}),M(n,s,b,t).map(a=>{let i=a.members[0],u=Number.POSITIVE_INFINITY;for(let l of a.members){let c=(n[l]-a.centre[0])**2+(s[l]-a.centre[1])**2+(b[l]-a.centre[2])**2;c<u&&(u=c,i=l)}let m=O(e,r[i]);return{rgb:m,hex:d(m),share:a.members.length/o,centre:{L:a.centre[0],a:a.centre[1],b:a.centre[2]},members:Uint32Array.from(a.members.map(l=>r[l])).sort()}}).sort((a,i)=>i.share-a.share||(a.hex<i.hex?-1:1))}function ce(e){let r=[];for(let t=0;t<e.width*e.height;t++)e.rgba[t*4+3]>=L&&r.push(t);return N(e,r,j)}function te(e,r){return N(e,[...r.members],J)}function le(e,r){return r.members.length>=ee&&te(e,r).length>1}function fe(e){let r=e.map(n=>n*100),t=r.map(Math.floor),o=Math.round(r.reduce((n,s)=>n+s,0))-t.reduce((n,s)=>n+s,0);return r.map((n,s)=>[n-Math.floor(n),s]).sort((n,s)=>s[0]-n[0]||n[1]-s[1]).forEach(([,n])=>{o-- >0&&(t[n]=t[n]+1)}),t}function he(e,r,t=24){let o=new Int32Array(e.width*e.height).fill(Z);r.forEach((a,i)=>{for(let u of a.members)o[u]=i});let n=e.width>=e.height,s=n?t:Math.max(1,Math.round(t*e.width/e.height)),b=n?Math.max(1,Math.round(t*e.height/e.width)):t;return Array.from({length:b},(a,i)=>Array.from({length:s},(u,m)=>{let l=Math.min(e.width-1,Math.floor((m+.5)*e.width/s)),f=Math.min(e.height-1,Math.floor((i+.5)*e.height/b))*e.width+l;return e.rgba[f*4+3]<L?K:o[f]}))}export{I as a,C as b,F as c,_ as d,D as e,x as f,B as g,se as h,ae as i,K as j,Z as k,ce as l,te as m,le as n,fe as o,he as p};
3
+ import{b as d,c as S,d as y,e as T,f as R,g as w}from"./chunk-EYOO35US.js";import{S as A}from"./chunk-PNPAHKJR.js";var I={set:"tailwind",start:50,end:950,count:11},C=["tailwind","even","radix"],F=[0,50,100,150,200,250,300,350,400,450],_=[550,600,650,700,750,800,850,900,950,1e3],D=Array.from({length:19},(e,r)=>r+3),v=[20,50,100,150,200,260,330,420,500,560,750,920],U=8;function k({set:e,start:r,end:t,count:o}){if(!C.includes(e))return`The set must be tailwind, even or radix; got ${e}.`;if(e!=="radix"){if(!F.includes(r))return r%50===0?`The start must be from 0 to 450, so the colour (500) stays in the scale; got ${r}.`:`The start must be a multiple of 50; got ${r}.`;if(!_.includes(t))return t%50===0?`The end must be from 550 to 1000, so the colour (500) stays in the scale; got ${t}.`:`The end must be a multiple of 50; got ${t}.`;if(e==="even"&&!D.includes(o))return`An even set has 3 to 21 steps; got ${o}.`}}function x(e){let{set:r,start:t,end:o,count:n}=e;if(r==="radix")return v.map((m,l)=>({step:l+1,at:m}));if(r==="tailwind"){let m=new Set([t,o,500]);for(let l=Math.ceil((t+1)/100)*100;l<o;l+=100)m.add(l);return[...m].sort((l,c)=>l-c).map(l=>({step:l,at:l}))}let s=n-1,b=Math.round(s*(500-t)/(o-t)),a=Math.max(1,Math.min(s-1,b)),i=s-a,u=[];for(let m=0;m<=a;m++)u.push(t+(500-t)*m/a);for(let m=1;m<=i;m++)u.push(500+(o-500)*m/i);for(let m of[10,5,1]){let l=u.map(c=>Math.round(c/m)*m);if(new Set(l).size===l.length)return u.map((c,f)=>({step:l[f],at:c}))}return u.map(m=>({step:m,at:m}))}function B(e){return x(e).map(r=>r.step)}var oe=B(I);function se(e){return e.set==="radix"?U:x(e).findIndex(r=>r.at===500)}var $=[[50,1],[100,.86],[200,.68],[300,.46],[400,.22],[500,0]],Y=[[500,0],[600,.2],[700,.4],[800,.6],[900,.8],[950,1]];function G(e,r){for(let t=1;t<e.length;t++){let[o,n]=e[t-1],[s,b]=e[t];if(r<=s)return n+(b-n)*(r-o)/(s-o)}return e[e.length-1][1]}var H=.995,V=.35,W=5e-4;function ae(e,r=I){let t=k(r);if(t)throw A(t,"Try: Tailwind, from 50 to 950.");let{L:o,C:n,h:s}=R(S(e)),b=n<W,a=Math.max(.975,o),i=o<.16?.42*o:Math.max(.16,.42*o),u=x(r),m=u[u.length-1]?.at===1e3;return u.map(({step:l,at:c})=>{if(c===500)return{step:l,at:c,rgb:{...e},hex:d(e),reference:!0};let f,p;if(c>=50&&c<500){let h=G($,c);f=o+(a-o)*h,p=n*(1-.88*h)}else if(c<50){let h=(50-c)/50;f=a+(Math.max(H,a)-a)*h,p=n*.12*(1-h)}else if(c<=950||m){let h=m?(c-500)/500:G(Y,c);f=o-(o-i)*h,p=n*(1-.45*h)}else{let h=(c-950)/50;f=i*(1-V*h),p=n*.55*(1-.4*h)}for(b&&(p=0);p>0&&!T(w({L:f,C:p,h:s}));)p-=.002;let g=y(w({L:f,C:Math.max(0,p),h:s}));return{step:l,at:c,rgb:g,hex:d(g),reference:!1}})}var E=(e,r,t)=>(e.L[r]-t[0])**2+(e.A[r]-t[1])**2+(e.B[r]-t[2])**2;function X(e,r){let t=e.L.length,o=[0,0,0];for(let b=0;b<t;b++)o[0]+=e.L[b],o[1]+=e.A[b],o[2]+=e.B[b];let n=[[o[0]/t,o[1]/t,o[2]/t]],s=new Float64Array(t).fill(Number.POSITIVE_INFINITY);for(;n.length<r;){let b=n[n.length-1],a=0,i=-1;for(let u=0;u<t;u++){let m=E(e,u,b);m<s[u]&&(s[u]=m),s[u]>i&&(i=s[u],a=u)}n.push([e.L[a],e.A[a],e.B[a]])}return n}function P(e,r,t){let o=0,n=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s++){let b=E(e,r,t[s]);b<n&&(n=b,o=s)}return o}function q(e,r){let t=e.L.length,o=X(e,r),n=new Int32Array(t).fill(-1);for(let b=0;b<30;b++){let a=0;for(let u=0;u<t;u++){let m=P(e,u,o);n[u]!==m&&(n[u]=m,a++)}let i=o.map(()=>[0,0,0,0]);for(let u=0;u<t;u++){let m=i[n[u]];m[0]=m[0]+e.L[u],m[1]=m[1]+e.A[u],m[2]=m[2]+e.B[u],m[3]=m[3]+1}if(i.forEach(([u,m,l,c],f)=>{c&&(o[f]=[u/c,m/c,l/c])}),a===0)break}let s=o.map(b=>({centre:b,members:[]}));for(let b=0;b<t;b++)s[n[b]]?.members.push(b);return s.filter(b=>b.members.length>0)}function z(e,r){let t=e;for(;;){let o,n=r**2;for(let c=0;c<t.length;c++)for(let f=c+1;f<t.length;f++){let p=t[c].centre,g=t[f].centre,h=(p[0]-g[0])**2+(p[1]-g[1])**2+(p[2]-g[2])**2;h<n&&(n=h,o=[c,f])}if(!o)return t;let[s,b]=o,a=t[s],i=t[b],u=a.members.length,m=i.members.length,l=a.centre.map((c,f)=>(c*u+i.centre[f]*m)/(u+m));t=t.filter((c,f)=>f!==s&&f!==b),t.push({centre:l,members:[...a.members,...i.members]})}}function Q(e,r,t){let o=e.L.length,n=[...r].sort((a,i)=>i.members.length-a.members.length),s=n.filter((a,i)=>i===0||a.members.length/o>=t),b=s.map(a=>a.centre);for(let a of n)if(!s.includes(a))for(let i of a.members)s[P(e,i,b)].members.push(i);return s}function M(e,r,t,o){let n=e.length;if(n===0)return[];let s={L:e,A:r,B:t},b=z(q(s,Math.min(o.k,n)),o.merge);return Q(s,b,o.minShare)}var j={k:8,merge:.06,minShare:.015},J={k:4,merge:.03,minShare:.02},K=-1,Z=-2,L=128,ee=64,O=(e,r)=>({r:e.rgba[r*4],g:e.rgba[r*4+1],b:e.rgba[r*4+2]});function N(e,r,t){let o=r.length,n=new Float64Array(o),s=new Float64Array(o),b=new Float64Array(o);return r.forEach((a,i)=>{let u=S(O(e,a));n[i]=u.L,s[i]=u.a,b[i]=u.b}),M(n,s,b,t).map(a=>{let i=a.members[0],u=Number.POSITIVE_INFINITY;for(let l of a.members){let c=(n[l]-a.centre[0])**2+(s[l]-a.centre[1])**2+(b[l]-a.centre[2])**2;c<u&&(u=c,i=l)}let m=O(e,r[i]);return{rgb:m,hex:d(m),share:a.members.length/o,centre:{L:a.centre[0],a:a.centre[1],b:a.centre[2]},members:Uint32Array.from(a.members.map(l=>r[l])).sort()}}).sort((a,i)=>i.share-a.share||(a.hex<i.hex?-1:1))}function ce(e){let r=[];for(let t=0;t<e.width*e.height;t++)e.rgba[t*4+3]>=L&&r.push(t);return N(e,r,j)}function te(e,r){return N(e,[...r.members],J)}function le(e,r){return r.members.length>=ee&&te(e,r).length>1}function fe(e){let r=e.map(n=>n*100),t=r.map(Math.floor),o=Math.round(r.reduce((n,s)=>n+s,0))-t.reduce((n,s)=>n+s,0);return r.map((n,s)=>[n-Math.floor(n),s]).sort((n,s)=>s[0]-n[0]||n[1]-s[1]).forEach(([,n])=>{o-- >0&&(t[n]=t[n]+1)}),t}function he(e,r,t=24){let o=new Int32Array(e.width*e.height).fill(Z);r.forEach((a,i)=>{for(let u of a.members)o[u]=i});let n=e.width>=e.height,s=n?t:Math.max(1,Math.round(t*e.width/e.height)),b=n?Math.max(1,Math.round(t*e.height/e.width)):t;return Array.from({length:b},(a,i)=>Array.from({length:s},(u,m)=>{let l=Math.min(e.width-1,Math.floor((m+.5)*e.width/s)),f=Math.min(e.height-1,Math.floor((i+.5)*e.height/b))*e.width+l;return e.rgba[f*4+3]<L?K:o[f]}))}export{I as a,C as b,F as c,_ as d,D as e,x as f,B as g,se as h,ae as i,K as j,Z as k,ce as l,te as m,le as n,fe as o,he as p};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{c as A}from"./chunk-MF3KKEFB.js";import{b as F}from"./chunk-I25E2XDH.js";import{b as se}from"./chunk-HZDYZ5RD.js";import{a as ae,b as de,d as D}from"./chunk-BSFBZBAI.js";import{c as G}from"./chunk-BWJNZT75.js";import{a as j}from"./chunk-PON65UTS.js";import{i as oe}from"./chunk-KXKQDFHX.js";import{f as ne,g as v,h as te,i as re,j as ie}from"./chunk-NUCGWLOY.js";import{a as ee}from"./chunk-I2LPGKUU.js";import{Aa as O,Da as B,Ea as V,Ga as I,Ha as H,Ja as Z,za as S}from"./chunk-CCNRNCRU.js";import{spawn as xe}from"node:child_process";import{existsSync as M}from"node:fs";import{mkdtemp as K,readFile as _,rm as Y,writeFile as We}from"node:fs/promises";import{tmpdir as q}from"node:os";import{dirname as ye,join as g}from"node:path";import{createInterface as Ce}from"node:readline";import{fileURLToPath as Je}from"node:url";var Ae=(e,n)=>{let t=e[0]+e[2]/2,r=e[1]+e[3]/2;return t>=n[0]&&t<=n[0]+n[2]&&r>=n[1]&&r<=n[1]+n[3]};function Le(e){let n=e.filter(t=>t.kind!=="text").map(t=>t.box);return e.filter(t=>t.kind!=="text"||!n.some(r=>Ae(t.box,r)))}var $e=.002;function fe(e,n){let t=d=>d.box[n],r=d=>d.box[n]+(n===0?d.box[2]:d.box[3]),o=[...e].sort((d,s)=>t(d)-t(s)),i=[],a=-1;for(let d of o){let s=i[i.length-1];s&&t(d)<=a+$e?(s.push(d),a=Math.max(a,r(d))):(i.push([d]),a=r(d))}return i}function Be(e){let n=fe(e,1);if(n.length<2)return;let t=i=>Math.max(...i.map(a=>a.box[1]+a.box[3])),r=i=>Math.min(...i.map(a=>a.box[1])),o=1;for(let i=2;i<n.length;i++){let a=d=>r(n[d]??[])-t(n[d-1]??[]);a(i)>a(o)&&(o=i)}return[n.slice(0,o).flat(),n.slice(o).flat()]}function C(e){if(e.length<=1)return[...e];let n=fe(e,0);if(n.length>1)return n.flatMap(C);let t=Be(e);return t?t.flatMap(C):[...e].sort((r,o)=>r.box[1]-o.box[1]||r.box[0]-o.box[0])}function He(e){let n=[];for(let t of e){let r=n[n.length-1],o=Math.max(t.lineHeight,r?.lineHeight??0);if(!(r!==void 0&&t.box[1]-(r.box[1]+r.box[3])<o&&Math.abs(t.box[0]-r.box[0])<2*o)){n.push({...t});continue}let a=Math.max(r.box[0]+r.box[2],t.box[0]+t.box[2]),d=t.box[1]+t.box[3];n[n.length-1]={...r,text:`${r.text} ${t.text}`,lines:r.lines+1,box:[r.box[0],r.box[1],a-r.box[0],d-r.box[1]]}}return n}function Me(e){let n=e.flatMap(t=>Array(Math.max(1,t.lines)).fill(t.lineHeight));return n.sort((t,r)=>t-r),n[Math.floor(n.length/2)]??0}var Ne=1.2,_e=80,W=e=>e.replace(/\s*\n\s*/g," ").trim();function Oe(e,n,t){if(e.kind==="list")return{kind:"list",ordered:e.items.some(a=>a.marker==="decimal"||a.marker==="lowercase"||a.marker==="uppercase"),items:e.items.map(a=>W(a.text))};if(e.kind==="table"){let a=Math.max(...e.rows.map(d=>d.length));return{kind:"table",rows:e.rows.map(d=>Array.from({length:a},(s,m)=>W(d[m]??"")))}}let r=W(e.text);return!t&&e.lineHeight>=n*Ne&&e.lines===1&&r.length<=_e&&!/[.,;:!?]$/.test(r)?{kind:"heading",level:e.title?1:2,text:r}:{kind:"paragraph",text:r}}function un(e){return e.map(n=>{let t=C(Le(n.blocks.filter(i=>i.kind!=="text"||i.text.trim()!=="")));n.lines&&(t=He(t.filter(i=>i.kind==="text")));let r=t.filter(i=>i.kind==="text"),o=Me(r);return t.map(i=>Oe(i,o,t.length===1))})}var pn=e=>e.some(n=>n.length>0);function J(e){return e.replace(/[\\`*[\]<]/g,n=>`\\${n}`).replace(/(^|[^\p{L}\p{N}])_|_(?=[^\p{L}\p{N}]|$)/gu,n=>n.replace("_","\\_"))}function Ie(e){return e.replace(/^(#|>|[-+](?= )|(?<=^\d+)\.(?= ))/,"\\$1").replace(/^(\d+)\.(?= )/,"$1\\.")}var le=e=>Ie(J(e));function Fe(e){if(e.kind==="heading")return`${"#".repeat(e.level)} ${J(e.text)}`;if(e.kind==="paragraph")return le(e.text);if(e.kind==="list")return e.items.map((i,a)=>`${e.ordered?`${a+1}.`:"-"} ${le(i)}`).join(`
3
+ import{c as A}from"./chunk-FEJSM3E4.js";import{b as F}from"./chunk-OLKPV4WO.js";import{b as se}from"./chunk-HZDYZ5RD.js";import{a as ae,b as de,d as D}from"./chunk-BSFBZBAI.js";import{c as G}from"./chunk-W6QOV4RP.js";import{a as j}from"./chunk-PON65UTS.js";import{i as oe}from"./chunk-KXKQDFHX.js";import{f as ne,g as v,h as te,i as re,j as ie}from"./chunk-NUCGWLOY.js";import{a as ee}from"./chunk-I2LPGKUU.js";import{Ca as S,Da as O,Ga as B,Ha as V,Ja as I,Ka as H,Ma as Z}from"./chunk-PNPAHKJR.js";import{spawn as xe}from"node:child_process";import{existsSync as M}from"node:fs";import{mkdtemp as K,readFile as _,rm as Y,writeFile as We}from"node:fs/promises";import{tmpdir as q}from"node:os";import{dirname as ye,join as g}from"node:path";import{createInterface as Ce}from"node:readline";import{fileURLToPath as Je}from"node:url";var Ae=(e,n)=>{let t=e[0]+e[2]/2,r=e[1]+e[3]/2;return t>=n[0]&&t<=n[0]+n[2]&&r>=n[1]&&r<=n[1]+n[3]};function Le(e){let n=e.filter(t=>t.kind!=="text").map(t=>t.box);return e.filter(t=>t.kind!=="text"||!n.some(r=>Ae(t.box,r)))}var $e=.002;function fe(e,n){let t=d=>d.box[n],r=d=>d.box[n]+(n===0?d.box[2]:d.box[3]),o=[...e].sort((d,s)=>t(d)-t(s)),i=[],a=-1;for(let d of o){let s=i[i.length-1];s&&t(d)<=a+$e?(s.push(d),a=Math.max(a,r(d))):(i.push([d]),a=r(d))}return i}function Be(e){let n=fe(e,1);if(n.length<2)return;let t=i=>Math.max(...i.map(a=>a.box[1]+a.box[3])),r=i=>Math.min(...i.map(a=>a.box[1])),o=1;for(let i=2;i<n.length;i++){let a=d=>r(n[d]??[])-t(n[d-1]??[]);a(i)>a(o)&&(o=i)}return[n.slice(0,o).flat(),n.slice(o).flat()]}function C(e){if(e.length<=1)return[...e];let n=fe(e,0);if(n.length>1)return n.flatMap(C);let t=Be(e);return t?t.flatMap(C):[...e].sort((r,o)=>r.box[1]-o.box[1]||r.box[0]-o.box[0])}function He(e){let n=[];for(let t of e){let r=n[n.length-1],o=Math.max(t.lineHeight,r?.lineHeight??0);if(!(r!==void 0&&t.box[1]-(r.box[1]+r.box[3])<o&&Math.abs(t.box[0]-r.box[0])<2*o)){n.push({...t});continue}let a=Math.max(r.box[0]+r.box[2],t.box[0]+t.box[2]),d=t.box[1]+t.box[3];n[n.length-1]={...r,text:`${r.text} ${t.text}`,lines:r.lines+1,box:[r.box[0],r.box[1],a-r.box[0],d-r.box[1]]}}return n}function Me(e){let n=e.flatMap(t=>Array(Math.max(1,t.lines)).fill(t.lineHeight));return n.sort((t,r)=>t-r),n[Math.floor(n.length/2)]??0}var Ne=1.2,_e=80,W=e=>e.replace(/\s*\n\s*/g," ").trim();function Oe(e,n,t){if(e.kind==="list")return{kind:"list",ordered:e.items.some(a=>a.marker==="decimal"||a.marker==="lowercase"||a.marker==="uppercase"),items:e.items.map(a=>W(a.text))};if(e.kind==="table"){let a=Math.max(...e.rows.map(d=>d.length));return{kind:"table",rows:e.rows.map(d=>Array.from({length:a},(s,m)=>W(d[m]??"")))}}let r=W(e.text);return!t&&e.lineHeight>=n*Ne&&e.lines===1&&r.length<=_e&&!/[.,;:!?]$/.test(r)?{kind:"heading",level:e.title?1:2,text:r}:{kind:"paragraph",text:r}}function un(e){return e.map(n=>{let t=C(Le(n.blocks.filter(i=>i.kind!=="text"||i.text.trim()!=="")));n.lines&&(t=He(t.filter(i=>i.kind==="text")));let r=t.filter(i=>i.kind==="text"),o=Me(r);return t.map(i=>Oe(i,o,t.length===1))})}var pn=e=>e.some(n=>n.length>0);function J(e){return e.replace(/[\\`*[\]<]/g,n=>`\\${n}`).replace(/(^|[^\p{L}\p{N}])_|_(?=[^\p{L}\p{N}]|$)/gu,n=>n.replace("_","\\_"))}function Ie(e){return e.replace(/^(#|>|[-+](?= )|(?<=^\d+)\.(?= ))/,"\\$1").replace(/^(\d+)\.(?= )/,"$1\\.")}var le=e=>Ie(J(e));function Fe(e){if(e.kind==="heading")return`${"#".repeat(e.level)} ${J(e.text)}`;if(e.kind==="paragraph")return le(e.text);if(e.kind==="list")return e.items.map((i,a)=>`${e.ordered?`${a+1}.`:"-"} ${le(i)}`).join(`
4
4
  `);let n=i=>J(i).replace(/\|/g,"\\|"),t=i=>`| ${i.map(n).join(" | ")} |`,[r=[],...o]=e.rows;return[t(r),`| ${r.map(()=>"---").join(" | ")} |`,...o.map(t)].join(`
5
5
  `)}var U=e=>e.filter(n=>n.length>0);function ue(e){let n=U(e).map(t=>t.map(Fe).join(`
6
6
 
@@ -20,4 +20,4 @@ import{c as A}from"./chunk-MF3KKEFB.js";import{b as F}from"./chunk-I25E2XDH.js";
20
20
  `));return["<!doctype html>",`<html><head><meta charset="utf-8"><title>${v(n)}</title><style>${te}${De}</style></head><body>`,t.join(`
21
21
  <hr>
22
22
  `),"</body></html>"].join(`
23
- `)}var N="forge-transcribe",z="forge-transcribe-whisper.mjs",Ue=["darwin","win32","linux"];function ze(e=process.platform,n=["whisper"]){let t=n.includes("whisper")||!n.includes("ffmpeg"),r=n.includes("ffmpeg"),o=[t&&"the whisper extension (forge extensions add whisper, or /extensions)",r&&(e==="darwin"?"ffmpeg (brew install ffmpeg)":e==="win32"?"ffmpeg (winget install ffmpeg)":"ffmpeg on your PATH")].filter(Boolean);return e==="darwin"?`Transcribe on this Mac needs ${o.join(" and ")}.`:e==="win32"?`Transcribe on Windows needs ${o.join(" and ")}.`:e==="linux"?`Transcribe on Linux needs ${o.join(" and ")}.`:"Transcribe needs macOS, Windows or Linux."}function _n(e=process.platform,n=e==="darwin"?"off":"unsupported"){return n==="off"?"Summary and notes need Apple Intelligence, and it is off.":`Summary and notes need Apple Intelligence, which this ${F(e)} does not have.`}function Xe(e){return{apple:[g(e,"helpers",N),g(e,"..","helpers",N),g(e,"..","..","dist","helpers",N)],whisper:[g(e,"helpers",z),g(e,"..","helpers",z),g(e,"..","..","helpers","transcribe",z)]}}function L(e=process.platform,n=process.env){let t=n.FORGE_TRANSCRIBE_HELPER;if(t!==void 0)return M(t)?t.endsWith(".mjs")?{whisper:t}:{apple:t}:{};if(!Ue.includes(e))return{};let r=Xe(ye(Je(import.meta.url))),o=e==="darwin"?r.apple.find(a=>M(a)):void 0,i=r.whisper.find(a=>M(a));return{...o?{apple:o}:{},...i?{whisper:i}:{}}}async function Ke(e){return e.apple!==void 0&&e.whisper===void 0?{path:e.apple,kind:"apple"}:e.apple!==void 0&&await e.appleHears(e.apple).catch(()=>!1)?{path:e.apple,kind:"apple"}:e.whisper===void 0?void 0:{path:e.whisper,kind:"whisper"}}var me=new Map;function $(e,n={}){let{apple:t}=L();if(t===void 0)return Promise.resolve(void 0);let r=`${t}\0${e??""}`,o=n.fresh?void 0:me.get(r);if(o)return o;let i=["status",...e?["--locale",e]:[]],a=R({path:t,kind:"apple"},i,"").catch(()=>{});return me.set(r,a),a}var X;function Ye(){return process.env.FORGE_TRANSCRIBE_HELPER!==void 0&&(X=void 0),X??=Ke({...L(),appleHears:async()=>(await $())?.speech===!0}),X}function qe(e){let{apple:n}=L();if(n===void 0)throw e();return{path:n,kind:"apple"}}async function Qe(){let e={...process.env,FORGE_HELPER_STOP_ON_EOF:"1"};if(!e.FORGE_FFMPEG){let n=await G().catch(()=>{});n&&(e.FORGE_FFMPEG=n.ffmpeg)}if(!e.FORGE_WHISPER_CLI){let n=await A("whisper");n&&(e.FORGE_WHISPER_CLI=n.entry)}if(!e.FORGE_WHISPER_MODEL){let n=await A("whisper"),t=n&&g(ye(n.entry),"model.bin");t&&M(t)&&(e.FORGE_WHISPER_MODEL=t)}return e}var Ve=5e3;async function R(e,n,t,r={}){let{signal:o}=r;if(o?.aborted)throw o.reason??new Error("aborted");let i=e.kind==="whisper",a=i?await Qe():process.env;if(o?.aborted)throw o.reason??new Error("aborted");return new Promise((d,s)=>{let m=/\.[cm]?js$/.test(e.path),[w,h]=m?[process.execPath,[e.path,...n]]:[e.path,n],u=j(xe(w,h,{stdio:[i?"pipe":"ignore","pipe","ignore"],env:a,windowsHide:!0}));u.stdin?.on("error",()=>{});let f,x=!1,P=y=>{x||(x=!0,o?.removeEventListener("abort",T),y())},T=()=>{i&&u.stdin?(u.stdin.end(),setTimeout(()=>u.kill("SIGKILL"),Ve).unref()):u.kill("SIGKILL"),P(()=>s(o?.reason??new Error("aborted")))};o?.addEventListener("abort",T,{once:!0}),Ce({input:u.stdout}).on("line",y=>{let k;try{k=JSON.parse(y)}catch{return}"ok"in k?f=k:r.onLine?.(k)}),u.on("error",y=>P(()=>s(S(t,y)))),u.on("close",()=>P(()=>{if(f===void 0)return s(S(t,new Error(`${N} gave no result`)));if(f.ok===!0)return d(f);s(Ze(String(f.code??""),String(f.message??""),t,n,e.kind))}))})}function Ze(e,n,t,r,o){if(e==="no-sound")return O(t);if(e==="unreadable")return B(t,process.platform,o);if(e==="locale"){let i=r.indexOf("--locale");return V(i>=0?r[i+1]??"this language":`this ${F()}'s language`,process.platform,o)}return e==="unsupported"||e==="runtime"?I(n):S(t,new Error(`${e}: ${n}`))}var en=["whisper","ffmpeg"];async function nn(e={}){let n=L();if(n.apple===void 0&&n.whisper===void 0)return;let t=await $(e.locale,{fresh:!0}),o={read:t?.read===!0||await A("read-text")!==void 0};if(t?.speech===!0)return{speech:!0,hears:"apple",locale:typeof t.locale=="string"?t.locale:null,...Array.isArray(t.locales)?{locales:t.locales.filter(s=>typeof s=="string")}:{},notes:t.notes==="available"||t.notes==="off"?t.notes:"unsupported",...o};if(n.whisper===void 0)return t===void 0?void 0:{speech:!1,locale:null,notes:"unsupported",...o};let i=["status",...e.locale?["--locale",e.locale]:[]],a=await R({path:n.whisper,kind:"whisper"},i,""),d=Array.isArray(a.missing)?en.filter(s=>a.missing.includes(s)):[];return{speech:a.speech===!0,...a.speech===!0?{hears:"whisper"}:{},locale:typeof a.locale=="string"?a.locale:null,notes:"unsupported",...o,...d.length>0?{missing:d}:{}}}async function On(e=process.platform){return e!=="darwin"?!0:(await nn().catch(()=>{}))?.hears!=="apple"}async function In(e=process.platform){if(e!=="darwin")return{hears:!1,reads:!1};let n=await $().catch(()=>{});return{hears:n?.speech===!0,reads:n?.read===!0}}async function Pe(){let e=await Ye();if(e===void 0)throw I(ze());return e}var tn=new Set(["mp4","mov","m4a","mp3","wav","aiff"]);async function ke(e,n){if(e.kind!=="apple")return;let{probe:t}=await import("./registry-DWFV4GBG.js"),r=await t(n).catch(()=>{});if(r===void 0||r.kind!=="media"||tn.has(r.format))return;let o=await G().catch(()=>{});return o?{tools:o}:void 0}async function rn(e,n,t){let r=await K(g(q(),"forge-sound-")),o=()=>Y(r,{recursive:!0,force:!0}),i=g(r,"sound.wav");try{return await new Promise((a,d)=>{let s=j(xe(n,["-nostdin","-v","error","-i",e,"-vn","-ac","1","-ar","16000","-c:a","pcm_s16le",i],{stdio:["ignore","ignore","pipe"],windowsHide:!0})),m="";s.stderr?.setEncoding("utf8").on("data",h=>{m+=h});let w=()=>s.kill("SIGKILL");t?.addEventListener("abort",w,{once:!0}),s.on("error",d),s.on("close",h=>{if(t?.removeEventListener("abort",w),t?.aborted)return d(t.reason??new Error("aborted"));h===0?a():d(S(e,new Error(`ffmpeg: ${m.trim()}`)))})}),{path:i,cleanup:o}}catch(a){throw await o(),a}}async function Fn(e){let n=await Pe(),t=await ke(n,e);if(t){let{probeMedia:o}=await import("./ffmpeg-G4TRWUTV.js"),i=await o(e,t.tools).catch(()=>{});if(i===void 0)throw B(e);if(i.audio===void 0)throw O(e);return{seconds:i.duration}}let r=await R(n,["probe",e],e);return{seconds:Number(r.seconds)}}async function jn(e,n){let t=await Pe(),r=await ke(t,e),o=r?await rn(e,r.tools.ffmpeg,n.signal):void 0;try{return await on(t,o?.path??e,e,n)}finally{await o?.cleanup()}}async function on(e,n,t,r){let o=["run",n,...r.locale?["--locale",r.locale]:[],...r.notes?["--notes"]:[],...r.notes&&r.detail&&r.detail!==se?["--detail",r.detail]:[]],i=await R(e,o,t,{signal:r.signal,onLine:d=>{let s=an(d);s&&r.onEvent?.(s)}}),a=i.segments??[];if(!a.some(d=>/\S/.test(d.text)))throw Z(t);return{locale:String(i.locale),seconds:Number(i.seconds),segments:a,...i.notes?{notes:i.notes}:{}}}function an(e){if(e.event==="model")return{kind:"model",fraction:Number(e.fraction)};if(e.event==="heard")return{kind:"heard",seconds:Number(e.seconds),of:Number(e.of)};if(e.event==="notes")return{kind:"notes",part:Number(e.part),of:Number(e.of)}}async function sn(e){let n=await _(e).catch(()=>{});if(n?.subarray(0,5).toString("latin1")!=="%PDF-")return;let[{pdfTextLayer:t},{layerPage:r}]=await Promise.all([import("./pdfium-MHPBLZY5.js"),import("./text-layer-PFIDCTEL.js")]);return(await t(n).catch(()=>{}))?.map(r)}function he(e,n,t){let r=(o,i)=>(t.length===e.length?t[o]:t[i])??{blocks:[]};return e.map((o,i)=>o??r(i,n.indexOf(i)))}async function Dn(e,n={}){let t=await sn(e);if(t&&t.length>0&&t.every(s=>s!==void 0))return t;let r=t?.flatMap((s,m)=>s===void 0?[m]:[])??[],o=t!==void 0&&r.length<t.length;if((await $())?.read!==!0){let s=await ln(e,{...n,...o?{pages:r}:{}});return t&&o?he(t,r,s):s}let i=["read",e,...o?["--pages",r.map(s=>s+1).join(",")]:[],...n.language?["--language",n.language]:[]],d=(await R(qe(H),i,e,{signal:n.signal,onLine:s=>{s.event==="page"&&n.onEvent?.({kind:"page",page:Number(s.page),of:Number(s.of)})}})).pages??[];return t&&o?he(t,r,d):d}var dn=200,we=4e3;async function Gn(){return H(await Ee())}async function Ee(){let{catalogEntry:e,assetFor:n}=await import("./catalog-FMHWWMUX.js"),t=e("read-text");return t!==void 0&&n(t)!==void 0}async function ln(e,n){let t=await A("read-text");if(t===void 0)throw H(await Ee());let[{probe:r},{decodedInput:o},{loadSharp:i},{runExtension:a}]=await Promise.all([import("./registry-DWFV4GBG.js"),import("./decoded-SK6W44WW.js"),import("./libs-EK64ACG3.js"),import("./run-3DX3SROY.js")]),d=await i(),s=await r(e),m=await K(g(q(),"forge-read-")),w={width:we,height:we,fit:"inside",withoutEnlargement:!0};try{let h=[],u=s.kind==="document"&&s.format==="pdf",f=u?n.pages??Array.from({length:s.pages},(c,l)=>l):[0];if(s.kind==="document"&&s.format==="pdf"){let{openPdf:c}=await import("./pdfium-MHPBLZY5.js"),l=await c(await _(e));try{for(let p of f){let E=await l.getPage(p).render({scale:dn/72,render:"bitmap"}),b=g(m,`page-${p+1}.png`);await d(Buffer.from(E.data),{raw:{width:E.width,height:E.height,channels:4}}).flatten({background:"#ffffff"}).resize(w).png().toFile(b),h.push(b)}}finally{l.destroy()}}else if(s.kind==="image"){let c=g(m,"page-1.png");await d(await o(e,s.format)).rotate().flatten({background:"#ffffff"}).resize(w).png().toFile(c),h.push(c)}else throw B(e);let P=(await a({id:"read-text",entry:t.entry,kind:t.kind},h.flatMap(c=>["--in",c]),{subject:e,what:`Reading the text of ${e}`,...n.signal?{signal:n.signal}:{},onLine:c=>{if(c.event!=="page")return;let l=u?(f[Number(c.page)-1]??0)+1:Number(c.page);n.onEvent?.({kind:"page",page:l,of:u?s.pages:Number(c.of)})}})).pages??[];if(!u)return P;let[{extractPdfText:T},{mendPage:y}]=await Promise.all([import("./pdfium-MHPBLZY5.js"),import("./text-layer-PFIDCTEL.js")]),k=await T(await _(e)).catch(()=>[]);return P.map((c,l)=>y(c,k[f[l]??l]??""))}finally{await Y(m,{recursive:!0,force:!0})}}async function ve(){let{apple:e}=L();if(!(e===void 0||await $()===void 0))return{path:e,kind:"apple"}}async function Re(e,n,t,r){let o=await K(g(q(),"forge-render-"));try{let i=g(o,"transcript.html"),a=g(o,`transcript.${t}`);return await We(i,n,"utf8"),await R(e,["render",i,a,"--as",t],a,{signal:r.signal}),await _(a)}finally{await Y(o,{recursive:!0,force:!0})}}var be=9026;async function Te(e,n){let t=await oe(),{Document:r,Packer:o,Paragraph:i,TextRun:a,Table:d,TableRow:s,TableCell:m,HeadingLevel:w}=t,h="forge-numbers",u=0,f=(c,l=!1)=>de(c,n).map(p=>new a({text:ee(p.text),...l?{bold:!0}:{},...p.kind==="eastAsia"?{font:{hint:"eastAsia"},language:p.lang?{eastAsia:p.lang}:{}}:{},...p.kind==="complex"?{font:{hint:"cs"},...p.rtl?{rightToLeft:!0}:{},...l?{boldComplexScript:!0}:{},...p.lang?{language:{bidirectional:p.lang}}:{}}:{}})),x=c=>ae(c)?{bidirectional:!0}:{},P=c=>c.flatMap(l=>{if(l.kind==="heading")return[new i({children:f(l.text),heading:l.level===1?w.HEADING_1:w.HEADING_2,...x(l.text)})];if(l.kind==="paragraph")return[new i({children:f(l.text),spacing:{after:160},...x(l.text)})];if(l.kind==="list"){let E=++u;return l.items.map(b=>l.ordered?new i({children:f(b),numbering:{reference:h,level:0,instance:E},...x(b)}):new i({children:f(b),bullet:{level:0},...x(b)}))}let p=l.rows[0]?.length??1;return[new d({width:{size:100,type:t.WidthType.PERCENTAGE},columnWidths:Array(p).fill(Math.floor(be/p)),margins:{top:40,bottom:40,left:100,right:100},rows:l.rows.map((E,b)=>new s({tableHeader:b===0,children:E.map(Q=>new m({width:{size:Math.floor(be/p),type:t.WidthType.DXA},children:[new i({children:f(Q,b===0),...x(Q)})]}))}))}),new i({text:""})]}),y=e.filter(c=>c.length>0).flatMap((c,l)=>[...l>0?[new i({children:[new t.PageBreak]})]:[],...P(c)]),k=new r({numbering:{config:[{reference:h,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:"%1.",alignment:t.AlignmentType.START}]}]},sections:[{children:y}]});return o.toBuffer(k)}var Se=e=>({...e.lang!==void 0?{lang:e.lang}:{},...e.onMissing!==void 0?{onMissing:e.onMissing}:{}});async function Wn(e,n,t,r={}){if(n==="md")return Buffer.from(ue(e),"utf8");if(n==="txt")return Buffer.from(pe(e),"utf8");if(n==="docx")return Te(e,r.lang);let o=await ve();return o?Re(o,ge(e,t),"pdf",r):D(e,{title:t,...Se(r)})}function cn(e){for(let n of e.flat())if(n.kind==="heading"&&n.level===1)return n.text;return"Transcript"}async function Cn(e,n,t={}){if(n==="md")return Buffer.from(e,"utf8");if(n==="txt")return Buffer.from(ne(e),"utf8");let r=await ve();if(r)return Re(r,ie(e),n,t);let o=re(e);return n==="docx"?Te(o,t.lang):D(o,{title:cn(o),...Se(t)})}export{un as a,pn as b,ue as c,pe as d,ge as e,ze as f,_n as g,Xe as h,L as i,Ke as j,nn as k,On as l,In as m,Fn as n,jn as o,Dn as p,Gn as q,Wn as r,Cn as s};
23
+ `)}var N="forge-transcribe",z="forge-transcribe-whisper.mjs",Ue=["darwin","win32","linux"];function ze(e=process.platform,n=["whisper"]){let t=n.includes("whisper")||!n.includes("ffmpeg"),r=n.includes("ffmpeg"),o=[t&&"the whisper extension (forge extensions add whisper, or /extensions)",r&&(e==="darwin"?"ffmpeg (brew install ffmpeg)":e==="win32"?"ffmpeg (winget install ffmpeg)":"ffmpeg on your PATH")].filter(Boolean);return e==="darwin"?`Transcribe on this Mac needs ${o.join(" and ")}.`:e==="win32"?`Transcribe on Windows needs ${o.join(" and ")}.`:e==="linux"?`Transcribe on Linux needs ${o.join(" and ")}.`:"Transcribe needs macOS, Windows or Linux."}function _n(e=process.platform,n=e==="darwin"?"off":"unsupported"){return n==="off"?"Summary and notes need Apple Intelligence, and it is off.":`Summary and notes need Apple Intelligence, which this ${F(e)} does not have.`}function Xe(e){return{apple:[g(e,"helpers",N),g(e,"..","helpers",N),g(e,"..","..","dist","helpers",N)],whisper:[g(e,"helpers",z),g(e,"..","helpers",z),g(e,"..","..","helpers","transcribe",z)]}}function L(e=process.platform,n=process.env){let t=n.FORGE_TRANSCRIBE_HELPER;if(t!==void 0)return M(t)?t.endsWith(".mjs")?{whisper:t}:{apple:t}:{};if(!Ue.includes(e))return{};let r=Xe(ye(Je(import.meta.url))),o=e==="darwin"?r.apple.find(a=>M(a)):void 0,i=r.whisper.find(a=>M(a));return{...o?{apple:o}:{},...i?{whisper:i}:{}}}async function Ke(e){return e.apple!==void 0&&e.whisper===void 0?{path:e.apple,kind:"apple"}:e.apple!==void 0&&await e.appleHears(e.apple).catch(()=>!1)?{path:e.apple,kind:"apple"}:e.whisper===void 0?void 0:{path:e.whisper,kind:"whisper"}}var me=new Map;function $(e,n={}){let{apple:t}=L();if(t===void 0)return Promise.resolve(void 0);let r=`${t}\0${e??""}`,o=n.fresh?void 0:me.get(r);if(o)return o;let i=["status",...e?["--locale",e]:[]],a=R({path:t,kind:"apple"},i,"").catch(()=>{});return me.set(r,a),a}var X;function Ye(){return process.env.FORGE_TRANSCRIBE_HELPER!==void 0&&(X=void 0),X??=Ke({...L(),appleHears:async()=>(await $())?.speech===!0}),X}function qe(e){let{apple:n}=L();if(n===void 0)throw e();return{path:n,kind:"apple"}}async function Qe(){let e={...process.env,FORGE_HELPER_STOP_ON_EOF:"1"};if(!e.FORGE_FFMPEG){let n=await G().catch(()=>{});n&&(e.FORGE_FFMPEG=n.ffmpeg)}if(!e.FORGE_WHISPER_CLI){let n=await A("whisper");n&&(e.FORGE_WHISPER_CLI=n.entry)}if(!e.FORGE_WHISPER_MODEL){let n=await A("whisper"),t=n&&g(ye(n.entry),"model.bin");t&&M(t)&&(e.FORGE_WHISPER_MODEL=t)}return e}var Ve=5e3;async function R(e,n,t,r={}){let{signal:o}=r;if(o?.aborted)throw o.reason??new Error("aborted");let i=e.kind==="whisper",a=i?await Qe():process.env;if(o?.aborted)throw o.reason??new Error("aborted");return new Promise((d,s)=>{let m=/\.[cm]?js$/.test(e.path),[w,h]=m?[process.execPath,[e.path,...n]]:[e.path,n],u=j(xe(w,h,{stdio:[i?"pipe":"ignore","pipe","ignore"],env:a,windowsHide:!0}));u.stdin?.on("error",()=>{});let f,x=!1,P=y=>{x||(x=!0,o?.removeEventListener("abort",T),y())},T=()=>{i&&u.stdin?(u.stdin.end(),setTimeout(()=>u.kill("SIGKILL"),Ve).unref()):u.kill("SIGKILL"),P(()=>s(o?.reason??new Error("aborted")))};o?.addEventListener("abort",T,{once:!0}),Ce({input:u.stdout}).on("line",y=>{let k;try{k=JSON.parse(y)}catch{return}"ok"in k?f=k:r.onLine?.(k)}),u.on("error",y=>P(()=>s(S(t,y)))),u.on("close",()=>P(()=>{if(f===void 0)return s(S(t,new Error(`${N} gave no result`)));if(f.ok===!0)return d(f);s(Ze(String(f.code??""),String(f.message??""),t,n,e.kind))}))})}function Ze(e,n,t,r,o){if(e==="no-sound")return O(t);if(e==="unreadable")return B(t,process.platform,o);if(e==="locale"){let i=r.indexOf("--locale");return V(i>=0?r[i+1]??"this language":`this ${F()}'s language`,process.platform,o)}return e==="unsupported"||e==="runtime"?I(n):S(t,new Error(`${e}: ${n}`))}var en=["whisper","ffmpeg"];async function nn(e={}){let n=L();if(n.apple===void 0&&n.whisper===void 0)return;let t=await $(e.locale,{fresh:!0}),o={read:t?.read===!0||await A("read-text")!==void 0};if(t?.speech===!0)return{speech:!0,hears:"apple",locale:typeof t.locale=="string"?t.locale:null,...Array.isArray(t.locales)?{locales:t.locales.filter(s=>typeof s=="string")}:{},notes:t.notes==="available"||t.notes==="off"?t.notes:"unsupported",...o};if(n.whisper===void 0)return t===void 0?void 0:{speech:!1,locale:null,notes:"unsupported",...o};let i=["status",...e.locale?["--locale",e.locale]:[]],a=await R({path:n.whisper,kind:"whisper"},i,""),d=Array.isArray(a.missing)?en.filter(s=>a.missing.includes(s)):[];return{speech:a.speech===!0,...a.speech===!0?{hears:"whisper"}:{},locale:typeof a.locale=="string"?a.locale:null,notes:"unsupported",...o,...d.length>0?{missing:d}:{}}}async function On(e=process.platform){return e!=="darwin"?!0:(await nn().catch(()=>{}))?.hears!=="apple"}async function In(e=process.platform){if(e!=="darwin")return{hears:!1,reads:!1};let n=await $().catch(()=>{});return{hears:n?.speech===!0,reads:n?.read===!0}}async function Pe(){let e=await Ye();if(e===void 0)throw I(ze());return e}var tn=new Set(["mp4","mov","m4a","mp3","wav","aiff"]);async function ke(e,n){if(e.kind!=="apple")return;let{probe:t}=await import("./registry-657JRJR5.js"),r=await t(n).catch(()=>{});if(r===void 0||r.kind!=="media"||tn.has(r.format))return;let o=await G().catch(()=>{});return o?{tools:o}:void 0}async function rn(e,n,t){let r=await K(g(q(),"forge-sound-")),o=()=>Y(r,{recursive:!0,force:!0}),i=g(r,"sound.wav");try{return await new Promise((a,d)=>{let s=j(xe(n,["-nostdin","-v","error","-i",e,"-vn","-ac","1","-ar","16000","-c:a","pcm_s16le",i],{stdio:["ignore","ignore","pipe"],windowsHide:!0})),m="";s.stderr?.setEncoding("utf8").on("data",h=>{m+=h});let w=()=>s.kill("SIGKILL");t?.addEventListener("abort",w,{once:!0}),s.on("error",d),s.on("close",h=>{if(t?.removeEventListener("abort",w),t?.aborted)return d(t.reason??new Error("aborted"));h===0?a():d(S(e,new Error(`ffmpeg: ${m.trim()}`)))})}),{path:i,cleanup:o}}catch(a){throw await o(),a}}async function Fn(e){let n=await Pe(),t=await ke(n,e);if(t){let{probeMedia:o}=await import("./ffmpeg-2ZP3GXJX.js"),i=await o(e,t.tools).catch(()=>{});if(i===void 0)throw B(e);if(i.audio===void 0)throw O(e);return{seconds:i.duration}}let r=await R(n,["probe",e],e);return{seconds:Number(r.seconds)}}async function jn(e,n){let t=await Pe(),r=await ke(t,e),o=r?await rn(e,r.tools.ffmpeg,n.signal):void 0;try{return await on(t,o?.path??e,e,n)}finally{await o?.cleanup()}}async function on(e,n,t,r){let o=["run",n,...r.locale?["--locale",r.locale]:[],...r.notes?["--notes"]:[],...r.notes&&r.detail&&r.detail!==se?["--detail",r.detail]:[]],i=await R(e,o,t,{signal:r.signal,onLine:d=>{let s=an(d);s&&r.onEvent?.(s)}}),a=i.segments??[];if(!a.some(d=>/\S/.test(d.text)))throw Z(t);return{locale:String(i.locale),seconds:Number(i.seconds),segments:a,...i.notes?{notes:i.notes}:{}}}function an(e){if(e.event==="model")return{kind:"model",fraction:Number(e.fraction)};if(e.event==="heard")return{kind:"heard",seconds:Number(e.seconds),of:Number(e.of)};if(e.event==="notes")return{kind:"notes",part:Number(e.part),of:Number(e.of)}}async function sn(e){let n=await _(e).catch(()=>{});if(n?.subarray(0,5).toString("latin1")!=="%PDF-")return;let[{pdfTextLayer:t},{layerPage:r}]=await Promise.all([import("./pdfium-MJ65YOXW.js"),import("./text-layer-PFIDCTEL.js")]);return(await t(n).catch(()=>{}))?.map(r)}function he(e,n,t){let r=(o,i)=>(t.length===e.length?t[o]:t[i])??{blocks:[]};return e.map((o,i)=>o??r(i,n.indexOf(i)))}async function Dn(e,n={}){let t=await sn(e);if(t&&t.length>0&&t.every(s=>s!==void 0))return t;let r=t?.flatMap((s,m)=>s===void 0?[m]:[])??[],o=t!==void 0&&r.length<t.length;if((await $())?.read!==!0){let s=await ln(e,{...n,...o?{pages:r}:{}});return t&&o?he(t,r,s):s}let i=["read",e,...o?["--pages",r.map(s=>s+1).join(",")]:[],...n.language?["--language",n.language]:[]],d=(await R(qe(H),i,e,{signal:n.signal,onLine:s=>{s.event==="page"&&n.onEvent?.({kind:"page",page:Number(s.page),of:Number(s.of)})}})).pages??[];return t&&o?he(t,r,d):d}var dn=200,we=4e3;async function Gn(){return H(await Ee())}async function Ee(){let{catalogEntry:e,assetFor:n}=await import("./catalog-G44MXIAF.js"),t=e("read-text");return t!==void 0&&n(t)!==void 0}async function ln(e,n){let t=await A("read-text");if(t===void 0)throw H(await Ee());let[{probe:r},{decodedInput:o},{loadSharp:i},{runExtension:a}]=await Promise.all([import("./registry-657JRJR5.js"),import("./decoded-IXLPWTGZ.js"),import("./libs-EK64ACG3.js"),import("./run-VJDF5WRF.js")]),d=await i(),s=await r(e),m=await K(g(q(),"forge-read-")),w={width:we,height:we,fit:"inside",withoutEnlargement:!0};try{let h=[],u=s.kind==="document"&&s.format==="pdf",f=u?n.pages??Array.from({length:s.pages},(c,l)=>l):[0];if(s.kind==="document"&&s.format==="pdf"){let{openPdf:c}=await import("./pdfium-MJ65YOXW.js"),l=await c(await _(e));try{for(let p of f){let E=await l.getPage(p).render({scale:dn/72,render:"bitmap"}),b=g(m,`page-${p+1}.png`);await d(Buffer.from(E.data),{raw:{width:E.width,height:E.height,channels:4}}).flatten({background:"#ffffff"}).resize(w).png().toFile(b),h.push(b)}}finally{l.destroy()}}else if(s.kind==="image"){let c=g(m,"page-1.png");await d(await o(e,s.format)).rotate().flatten({background:"#ffffff"}).resize(w).png().toFile(c),h.push(c)}else throw B(e);let P=(await a({id:"read-text",entry:t.entry,kind:t.kind},h.flatMap(c=>["--in",c]),{subject:e,what:`Reading the text of ${e}`,...n.signal?{signal:n.signal}:{},onLine:c=>{if(c.event!=="page")return;let l=u?(f[Number(c.page)-1]??0)+1:Number(c.page);n.onEvent?.({kind:"page",page:l,of:u?s.pages:Number(c.of)})}})).pages??[];if(!u)return P;let[{extractPdfText:T},{mendPage:y}]=await Promise.all([import("./pdfium-MJ65YOXW.js"),import("./text-layer-PFIDCTEL.js")]),k=await T(await _(e)).catch(()=>[]);return P.map((c,l)=>y(c,k[f[l]??l]??""))}finally{await Y(m,{recursive:!0,force:!0})}}async function ve(){let{apple:e}=L();if(!(e===void 0||await $()===void 0))return{path:e,kind:"apple"}}async function Re(e,n,t,r){let o=await K(g(q(),"forge-render-"));try{let i=g(o,"transcript.html"),a=g(o,`transcript.${t}`);return await We(i,n,"utf8"),await R(e,["render",i,a,"--as",t],a,{signal:r.signal}),await _(a)}finally{await Y(o,{recursive:!0,force:!0})}}var be=9026;async function Te(e,n){let t=await oe(),{Document:r,Packer:o,Paragraph:i,TextRun:a,Table:d,TableRow:s,TableCell:m,HeadingLevel:w}=t,h="forge-numbers",u=0,f=(c,l=!1)=>de(c,n).map(p=>new a({text:ee(p.text),...l?{bold:!0}:{},...p.kind==="eastAsia"?{font:{hint:"eastAsia"},language:p.lang?{eastAsia:p.lang}:{}}:{},...p.kind==="complex"?{font:{hint:"cs"},...p.rtl?{rightToLeft:!0}:{},...l?{boldComplexScript:!0}:{},...p.lang?{language:{bidirectional:p.lang}}:{}}:{}})),x=c=>ae(c)?{bidirectional:!0}:{},P=c=>c.flatMap(l=>{if(l.kind==="heading")return[new i({children:f(l.text),heading:l.level===1?w.HEADING_1:w.HEADING_2,...x(l.text)})];if(l.kind==="paragraph")return[new i({children:f(l.text),spacing:{after:160},...x(l.text)})];if(l.kind==="list"){let E=++u;return l.items.map(b=>l.ordered?new i({children:f(b),numbering:{reference:h,level:0,instance:E},...x(b)}):new i({children:f(b),bullet:{level:0},...x(b)}))}let p=l.rows[0]?.length??1;return[new d({width:{size:100,type:t.WidthType.PERCENTAGE},columnWidths:Array(p).fill(Math.floor(be/p)),margins:{top:40,bottom:40,left:100,right:100},rows:l.rows.map((E,b)=>new s({tableHeader:b===0,children:E.map(Q=>new m({width:{size:Math.floor(be/p),type:t.WidthType.DXA},children:[new i({children:f(Q,b===0),...x(Q)})]}))}))}),new i({text:""})]}),y=e.filter(c=>c.length>0).flatMap((c,l)=>[...l>0?[new i({children:[new t.PageBreak]})]:[],...P(c)]),k=new r({numbering:{config:[{reference:h,levels:[{level:0,format:t.LevelFormat.DECIMAL,text:"%1.",alignment:t.AlignmentType.START}]}]},sections:[{children:y}]});return o.toBuffer(k)}var Se=e=>({...e.lang!==void 0?{lang:e.lang}:{},...e.onMissing!==void 0?{onMissing:e.onMissing}:{}});async function Wn(e,n,t,r={}){if(n==="md")return Buffer.from(ue(e),"utf8");if(n==="txt")return Buffer.from(pe(e),"utf8");if(n==="docx")return Te(e,r.lang);let o=await ve();return o?Re(o,ge(e,t),"pdf",r):D(e,{title:t,...Se(r)})}function cn(e){for(let n of e.flat())if(n.kind==="heading"&&n.level===1)return n.text;return"Transcript"}async function Cn(e,n,t={}){if(n==="md")return Buffer.from(e,"utf8");if(n==="txt")return Buffer.from(ne(e),"utf8");let r=await ve();if(r)return Re(r,ie(e),n,t);let o=re(e);return n==="docx"?Te(o,t.lang):D(o,{title:cn(o),...Se(t)})}export{un as a,pn as b,ue as c,pe as d,ge as e,ze as f,_n as g,Xe as h,L as i,Ke as j,nn as k,On as l,In as m,Fn as n,jn as o,Dn as p,Gn as q,Wn as r,Cn as s};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{Ia as d}from"./chunk-PNPAHKJR.js";var c=new Set(["youtube.com","www.youtube.com","m.youtube.com","music.youtube.com"]),m=/^[A-Za-z0-9_-]{11}$/,f=[[["youtube.com","youtu.be"],"YouTube"],[["instagram.com"],"Instagram"],[["tiktok.com"],"TikTok"],[["x.com","twitter.com"],"X"],[["facebook.com","fb.watch"],"Facebook"],[["vimeo.com"],"Vimeo"],[["reddit.com","redd.it"],"Reddit"],[["twitch.tv"],"Twitch"],[["dailymotion.com","dai.ly"],"Dailymotion"],[["threads.net"],"Threads"],[["bsky.app"],"Bluesky"],[["linkedin.com"],"LinkedIn"],[["pinterest.com","pin.it"],"Pinterest"],[["soundcloud.com"],"SoundCloud"]],l=e=>f.find(([t])=>t.some(n=>e===n||e.endsWith(`.${n}`)));function k(e){let t=e.toLowerCase();return l(t)?.[1]??t.replace(/^www\./,"")}var u=e=>e&&m.test(e)?{kind:"video",id:e,url:`https://www.youtube.com/watch?v=${e}`,site:"YouTube"}:void 0;function y(e){let t=e.trim();if(t==="")return;let n=/^https?:\/\//i.test(t);if(/\s/.test(t))return n?{kind:"other"}:void 0;let s;try{s=new URL(n?t:`https://${t}`)}catch{return n?{kind:"other"}:void 0}let i=s.hostname.toLowerCase();if(!(!n&&(/^[a-z]+:\/\//i.test(t)||l(i)===void 0))){if(i==="youtu.be"||c.has(i)){let[o,r]=s.pathname.split("/").filter(Boolean);return(i==="youtu.be"?u(o):o==="watch"?u(s.searchParams.get("v")):o==="shorts"||o==="live"?u(r):o==="playlist"&&s.searchParams.get("list")?{kind:"playlist"}:void 0)??{kind:"other"}}return i.includes(".")?{kind:"video",url:n?t:`https://${t}`,site:k(i)}:{kind:"other"}}}function g(e){if(e?.kind==="playlist")return d("This is a playlist.",void 0,{hint:"Pass one video's link.",shellHint:"Paste one video's link."});if(e?.kind==="other")return d("This link names no video.",void 0,{hint:"Pass a video's link.",shellHint:"Paste a video's link."})}var a=60;function w(e){let t=o=>o.replace(/[/\\:*?"<>|]/g,"").split("").filter(r=>r.charCodeAt(0)>=32).join("").replace(/\s+/g," ").trim().replace(/^\.+/,""),n=t(e.title.split(/(?:^|\s)#/)[0]??"");if([...n].length>a){let o=[...n].slice(0,a+1).join(""),r=o.lastIndexOf(" ");n=(r>0?o.slice(0,r):[...n].slice(0,a).join("")).trim()}if(/^(con|prn|aux|nul|com\d|lpt\d)$/i.test(n))return`${n} video`;if(n!=="")return n;let s=t(e.uploader),i=t(e.id);return s&&i?`${s} \u2013 ${i}`:s||i||"video"}export{k as a,y as b,g as c,w as d};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as P}from"./chunk-KXKQDFHX.js";import{t as S,u as U}from"./chunk-CCNRNCRU.js";import{readFile as ve,stat as Ne}from"node:fs/promises";import{execFile as ie}from"node:child_process";import{randomBytes as oe}from"node:crypto";import{mkdtemp as ae,open as H,readFile as se,rm as D}from"node:fs/promises";import{tmpdir as J}from"node:os";import{join as B}from"node:path";import{promisify as ce}from"node:util";var v=ce(ie),z=async()=>({...await import("./paths-6OENILJ4.js"),...await import("./run-3DX3SROY.js")}),E,N=e=>e!=="darwin";async function _(e=process.platform){return N(e)?await(await z()).installed("heic")!==void 0:k()}async function k(){if(E!==void 0)return E;try{await v("/usr/bin/sips",["--help"],{timeout:5e3}),E=!0}catch{E=!1}return E}async function O(e,n=process.platform){if(N(n))return fe(e,n);let t=B(J(),`forge-heic-${oe(8).toString("hex")}.png`),i=async()=>{await D(t,{force:!0}).catch(()=>{})};try{return await v("/usr/bin/sips",["-s","format","png",e,"--out",t],{timeout:12e4}),{path:t,cleanup:i}}catch(r){throw await i(),r}}async function L(e,n){let{installed:t,runExtension:i}=await z(),r=await t("heic");if(r===void 0)throw S(e,n);return{ext:r,runExtension:i}}async function fe(e,n){let t=await ae(B(J(),"forge-heic-")),i=async()=>{await D(t,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await L(e,n),a=B(t,"decoded.rgba"),f=B(t,"decoded.png"),{width:m,height:y}=await o(r,["--in",e,"--out",a],{subject:e});return await(await P())(await se(a),{raw:{width:m,height:y,channels:4}}).png().toFile(f),await D(a,{force:!0}),{path:f,cleanup:i}}catch(r){throw await i(),r}}var ue=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),de=new Set(["avif","avis"]);async function $e(e){let n;try{n=await H(e,"r")}catch{return!1}try{let t=Buffer.alloc(64),{bytesRead:i}=await n.read(t,0,64,0);if(i<12||t.toString("latin1",4,8)!=="ftyp")return!1;let r=Math.min(t.readUInt32BE(0),i),o=[];for(let a=8;a+4<=r;a+=4)o.push(t.toString("latin1",a,a+4));return o.some(a=>de.has(a))?!1:o.some(a=>ue.has(a))}catch{return!1}finally{await n.close().catch(()=>{})}}async function qe(e,n=process.platform){if(N(n)){let{ext:a,runExtension:f}=await L(e,n),m=await f(a,["--info","--in",e],{subject:e});return{width:m.width,height:m.height,hasAlpha:m.hasAlpha??!0}}let{stdout:t}=await v("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",e],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(t)?.[1]??0),r=Number(/pixelHeight:\s*(\d+)/.exec(t)?.[1]??0),o=await me(e);return{width:o?r:i,height:o?i:r,hasAlpha:/hasAlpha:\s*yes/i.test(t)}}function*x(e,n,t){let i=n;for(;i+8<=t;){let r=e.readUInt32BE(i),o=8;if(r===1&&i+16<=t?(r=Number(e.readBigUInt64BE(i+8)),o=16):r===0&&(r=t-i),r<o)return;yield{type:e.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+r,t)},i+=r}}async function me(e){let n=await H(e,"r");try{let t=Buffer.alloc(262144),{bytesRead:i}=await n.read(t,0,t.length,0),r=[...x(t,0,i)].find(l=>l.type==="meta");if(!r)return!1;let o=[...x(t,r.start+4,r.end)],a=o.find(l=>l.type==="pitm"),f=o.find(l=>l.type==="iprp");if(!a||!f)return!1;let m=t.readUInt8(a.start)===0?t.readUInt16BE(a.start+4):t.readUInt32BE(a.start+4),y=[...x(t,f.start,f.end)],s=y.find(l=>l.type==="ipco"),c=y.find(l=>l.type==="ipma");if(!s||!c)return!1;let u=new Map;if([...x(t,s.start,s.end)].forEach((l,b)=>{l.type==="irot"&&u.set(b+1,t.readUInt8(l.start)&3)}),u.size===0)return!1;let h=t.readUInt8(c.start),w=(t.readUInt8(c.start+3)&1)===1,d=c.start+4,p=t.readUInt32BE(d);d+=4;for(let l=0;l<p&&d<c.end;l++){let b=h<1?t.readUInt16BE(d):t.readUInt32BE(d);d+=h<1?2:4;let ne=t.readUInt8(d);d+=1;for(let C=0;C<ne;C++){let re=w?t.readUInt16BE(d)&32767:t.readUInt8(d)&127;if(d+=w?2:1,b===m&&(u.get(re)??0)%2===1)return!0}}return!1}catch{return!1}finally{await n.close().catch(()=>{})}}import{execFile as le}from"node:child_process";import{randomBytes as he}from"node:crypto";import{copyFile as we,mkdtemp as W,open as pe,readFile as ye,rm as R}from"node:fs/promises";import{tmpdir as A}from"node:os";import{extname as K,join as I}from"node:path";import{promisify as ge}from"node:util";var $=ge(le),q=async()=>({...await import("./paths-6OENILJ4.js"),...await import("./run-3DX3SROY.js")}),F=e=>e!=="darwin",xe={".nef":[".nef",".nrw"],".arw":[".arw",".srf",".sr2"],".rw2":[".rw2",".rwl"],".3fr":[".3fr",".fff"],".dcr":[".dcr",".kdc"]},be=[["nikon",".nef"],["sony",".arw"],["pentax",".pef"],["ricoh",".pef"],["samsung",".srw"],["hasselblad",".3fr"],["seiko epson",".erf"],["epson",".erf"],["kodak",".dcr"],["eastman kodak",".dcr"],["leaf",".mos"]],Ie=new Set([32803,34892]),Ee=new Set([32767,32769,32770,34316,34713,65e3,65535]),Se="85c0b687820f11e08111f4ce462b6a48";function j(e,n){let t=(s,c)=>n?s.readUInt16LE(c):s.readUInt16BE(c),i=(s,c)=>n?s.readUInt32LE(c):s.readUInt32BE(c),r={1:1,2:1,3:2,4:4,7:1,13:4};async function o(s){if(s<=0)return;let c=await e(s,2);if(c.length<2)return;let u=t(c,0);if(u===0||u>1e3)return;let h=await e(s+2,u*12+4);if(h.length<u*12+4)return;let w=new Map;for(let d=0;d<u;d++){let p=d*12;w.set(t(h,p),{type:t(h,p+2),count:i(h,p+4),inline:h.subarray(p+8,p+12),offset:i(h,p+8)})}return{entries:w,next:i(h,u*12)}}async function a(s,c=16){if(!s)return[];let u=r[s.type]===2?2:4,h=Math.min(s.count,c),w=h*u<=4?s.inline:await e(s.offset,h*u),d=[];for(let p=0;p<h&&(p+1)*u<=w.length;p++)d.push(u===2?t(w,p*u):i(w,p*u));return d}async function f(s){if(s?.type!==2)return"";let c=Math.min(s.count,64);return(c<=4?s.inline.subarray(0,c):await e(s.offset,c)).toString("latin1").replace(/\0.*$/s,"").trim()}async function m(s){let[c]=await a(s.entries.get(274),1);return c!==void 0&&c>=1&&c<=8?c:1}async function y(s){let c=[s],u=new Set;for(let h=0;c.length>0&&h<12;h++){let w=c.shift(),[d]=await a(w.entries.get(262),1),[p]=await a(w.entries.get(259),1);if(d!==void 0&&Ie.has(d)||p!==void 0&&Ee.has(p))return!0;for(let l of[...await a(w.entries.get(330),8),w.next]){if(l===0||u.has(l))continue;u.add(l);let b=await o(l);b&&c.push(b)}}return!1}return{directory:o,text:f,orientation:m,hasMosaic:y,u32:i}}function V(e){let n=e.toString("latin1",0,2);return n==="II"?!0:n==="MM"?!1:void 0}async function Y(e,n){let t=V(e.subarray(n,n+2));if(t===void 0)return 1;let r=j(async(a,f)=>e.subarray(n+a,n+a+f),t),o=await r.directory(r.u32(e,n+4));return o?r.orientation(o):1}async function Pe(e){if(e[0]!==255||e[1]!==216)return 1;let n=2;for(;n+4<=e.length&&e[n]===255;){let t=e[n+1],i=e.readUInt16BE(n+2);if(t===225&&e.toString("latin1",n+4,n+10)==="Exif\0\0")return Y(e,n+10);if(t===218)break;n+=2+i}return 1}async function Be(e,n){let t=await e(0,Math.min(n,1048576)),i=[...x(t,0,t.length)].find(r=>r.type==="moov");if(!i)return 1;for(let r of x(t,i.start,i.end)){if(r.type!=="uuid"||t.toString("hex",r.start,r.start+16)!==Se)continue;let o=[...x(t,r.start+16,r.end)].find(a=>a.type==="CMT1");return o?Y(t,o.start):1}return 1}async function Re(e,n){if(n.length<92)return 1;let t=n.readUInt32BE(84),i=n.readUInt32BE(88);return t===0||i===0?1:Pe(await e(t,Math.min(i,65536)))}async function Me(e){let n;try{n=await pe(e,"r")}catch{return}try{let{size:t}=await n.stat(),i=async(u,h)=>{let w=Math.max(0,Math.min(h,t-u)),d=Buffer.alloc(w);return w>0&&await n.read(d,0,w,u),d},r=await i(0,96);if(r.length<16)return;let o=r.toString("latin1",0,4);if(r.toString("latin1",0,15)==="FUJIFILMCCD-RAW")return{ext:".raf",orientation:await Re(i,r)};if(r.toString("latin1",4,12)==="ftypcrx ")return{ext:".cr3",orientation:await Be(i,t)};let a=V(r);if(a===void 0)return;let f=j(i,a),m=await f.directory(f.u32(r,4));if(!m)return;let y=await f.orientation(m);if(o==="IIRO"||o==="IIRS"||o==="MMOR")return{ext:".orf",orientation:y};if(o==="IIU\0")return{ext:".rw2",orientation:y};if(o!=="II*\0"&&o!=="MM\0*")return;if(m.entries.has(50706))return{ext:".dng",orientation:y};if(r.toString("latin1",8,11)==="CR")return{ext:".cr2",orientation:y};let s=(await f.text(m.entries.get(271))).toLowerCase(),c=be.find(([u])=>s.startsWith(u));return!c||!await f.hasMosaic(m)?void 0:{ext:c[1],orientation:y}}catch{return}finally{await n.close().catch(()=>{})}}async function Ue(e=process.platform){return F(e)?await(await q()).installed("raw")!==void 0:k()}async function Z(e,n){let{installed:t,runExtension:i}=await q(),r=await t("raw");if(r===void 0)throw U(e,n);return{ext:r,runExtension:i}}async function G(e,n,t){let i=K(e).toLowerCase();if((xe[n.ext]??[n.ext]).includes(i))return t(e);let r=await W(I(A(),"forge-raw-"));try{let o=I(r,`photo${n.ext}`);return await we(e,o),await t(o)}finally{await R(r,{recursive:!0,force:!0}).catch(()=>{})}}async function rt(e,n,t=process.platform){if(F(t)){let{ext:a,runExtension:f}=await Z(e,t),m=await f(a,["--info","--in",e],{subject:e,platform:t});if(!(m.width>0&&m.height>0))throw new Error("the raw extension reported no size");return{width:m.width,height:m.height}}let{stdout:i}=await G(e,n,a=>$("/usr/bin/sips",["-g","typeIdentifier","-g","pixelWidth","-g","pixelHeight",a],{timeout:3e4}));if(!/typeIdentifier:\s*\S*raw-image/.test(i))return;let r=Number(/pixelWidth:\s*(\d+)/.exec(i)?.[1]??0),o=Number(/pixelHeight:\s*(\d+)/.exec(i)?.[1]??0);if(!(r===0||o===0))return n.orientation>=5?{width:o,height:r}:{width:r,height:o}}async function Q(e,n=process.platform){if(F(n))return De(e,n);if(!await Ue(n))throw U(e,n);let t=await Me(e)??{ext:K(e).toLowerCase(),orientation:1},i=I(A(),`forge-raw-${he(8).toString("hex")}.png`),r=async()=>{await R(i,{force:!0}).catch(()=>{})};try{return await G(e,t,o=>$("/usr/bin/sips",["-s","format","png",o,"--out",i],{timeout:3e5})),{path:i,cleanup:r}}catch(o){throw await r(),o}}async function De(e,n){let t=await W(I(A(),"forge-raw-")),i=async()=>{await R(t,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await Z(e,n),a=I(t,"decoded.rgb"),f=I(t,"decoded.png"),{width:m,height:y}=await o(r,["--in",e,"--out",a],{subject:e,platform:n});return await(await P())(await ye(a),{raw:{width:m,height:y,channels:3}}).png().toFile(f),await R(a,{force:!0}),{path:f,cleanup:i}}catch(r){throw await i(),r}}async function ft(e,n){return n!=="heic"&&n!=="raw"?e:Fe(e,n)}var ke=4,X=256*1024*1024,T=X,ee=6e4,te=ee,M;function Ae(){clearTimeout(M),M=setTimeout(()=>g.clear(),te),M.unref?.()}var g=new Map;async function Fe(e,n){let{size:t,mtimeMs:i}=await Ne(e);Ae();let r=`${n}\0${e}`,o=g.get(r);if(g.delete(r),o&&o.size===t&&o.mtimeMs===i)return g.set(r,o),o.png;let a={size:t,mtimeMs:i,png:Ce(e,n),bytes:0};return g.set(r,a),a.png.then(f=>{a.bytes=f.length,f.length>T&&g.get(r)===a&&g.delete(r),Te()},()=>{g.get(r)===a&&g.delete(r)}),a.png}function Te(){let e=0;for(let n of g.values())e+=n.bytes;for(let[n,t]of g){if(g.size<=ke&&e<=T)break;g.delete(n),e-=t.bytes}}async function Ce(e,n){if(n==="heic"&&!await _())throw S(e);let t=n==="heic"?await O(e):await Q(e);try{return await ve(t.path)}finally{await t.cleanup()}}function ut(){g.clear(),clearTimeout(M)}function dt(e){te=e??ee}function mt(e){T=e??X}export{_ as a,$e as b,qe as c,Me as d,Ue as e,rt as f,ft as g,ut as h,dt as i,mt as j};
3
+ import{b as P}from"./chunk-KXKQDFHX.js";import{w as S,x as U}from"./chunk-PNPAHKJR.js";import{readFile as ve,stat as Ne}from"node:fs/promises";import{execFile as ie}from"node:child_process";import{randomBytes as oe}from"node:crypto";import{mkdtemp as ae,open as H,readFile as se,rm as D}from"node:fs/promises";import{tmpdir as J}from"node:os";import{join as B}from"node:path";import{promisify as ce}from"node:util";var v=ce(ie),z=async()=>({...await import("./paths-BBUKTDDP.js"),...await import("./run-VJDF5WRF.js")}),E,N=e=>e!=="darwin";async function _(e=process.platform){return N(e)?await(await z()).installed("heic")!==void 0:k()}async function k(){if(E!==void 0)return E;try{await v("/usr/bin/sips",["--help"],{timeout:5e3}),E=!0}catch{E=!1}return E}async function O(e,n=process.platform){if(N(n))return fe(e,n);let t=B(J(),`forge-heic-${oe(8).toString("hex")}.png`),i=async()=>{await D(t,{force:!0}).catch(()=>{})};try{return await v("/usr/bin/sips",["-s","format","png",e,"--out",t],{timeout:12e4}),{path:t,cleanup:i}}catch(r){throw await i(),r}}async function L(e,n){let{installed:t,runExtension:i}=await z(),r=await t("heic");if(r===void 0)throw S(e,n);return{ext:r,runExtension:i}}async function fe(e,n){let t=await ae(B(J(),"forge-heic-")),i=async()=>{await D(t,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await L(e,n),a=B(t,"decoded.rgba"),f=B(t,"decoded.png"),{width:m,height:y}=await o(r,["--in",e,"--out",a],{subject:e});return await(await P())(await se(a),{raw:{width:m,height:y,channels:4}}).png().toFile(f),await D(a,{force:!0}),{path:f,cleanup:i}}catch(r){throw await i(),r}}var ue=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),de=new Set(["avif","avis"]);async function $e(e){let n;try{n=await H(e,"r")}catch{return!1}try{let t=Buffer.alloc(64),{bytesRead:i}=await n.read(t,0,64,0);if(i<12||t.toString("latin1",4,8)!=="ftyp")return!1;let r=Math.min(t.readUInt32BE(0),i),o=[];for(let a=8;a+4<=r;a+=4)o.push(t.toString("latin1",a,a+4));return o.some(a=>de.has(a))?!1:o.some(a=>ue.has(a))}catch{return!1}finally{await n.close().catch(()=>{})}}async function qe(e,n=process.platform){if(N(n)){let{ext:a,runExtension:f}=await L(e,n),m=await f(a,["--info","--in",e],{subject:e});return{width:m.width,height:m.height,hasAlpha:m.hasAlpha??!0}}let{stdout:t}=await v("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",e],{timeout:3e4}),i=Number(/pixelWidth:\s*(\d+)/.exec(t)?.[1]??0),r=Number(/pixelHeight:\s*(\d+)/.exec(t)?.[1]??0),o=await me(e);return{width:o?r:i,height:o?i:r,hasAlpha:/hasAlpha:\s*yes/i.test(t)}}function*x(e,n,t){let i=n;for(;i+8<=t;){let r=e.readUInt32BE(i),o=8;if(r===1&&i+16<=t?(r=Number(e.readBigUInt64BE(i+8)),o=16):r===0&&(r=t-i),r<o)return;yield{type:e.toString("latin1",i+4,i+8),start:i+o,end:Math.min(i+r,t)},i+=r}}async function me(e){let n=await H(e,"r");try{let t=Buffer.alloc(262144),{bytesRead:i}=await n.read(t,0,t.length,0),r=[...x(t,0,i)].find(l=>l.type==="meta");if(!r)return!1;let o=[...x(t,r.start+4,r.end)],a=o.find(l=>l.type==="pitm"),f=o.find(l=>l.type==="iprp");if(!a||!f)return!1;let m=t.readUInt8(a.start)===0?t.readUInt16BE(a.start+4):t.readUInt32BE(a.start+4),y=[...x(t,f.start,f.end)],s=y.find(l=>l.type==="ipco"),c=y.find(l=>l.type==="ipma");if(!s||!c)return!1;let u=new Map;if([...x(t,s.start,s.end)].forEach((l,b)=>{l.type==="irot"&&u.set(b+1,t.readUInt8(l.start)&3)}),u.size===0)return!1;let h=t.readUInt8(c.start),w=(t.readUInt8(c.start+3)&1)===1,d=c.start+4,p=t.readUInt32BE(d);d+=4;for(let l=0;l<p&&d<c.end;l++){let b=h<1?t.readUInt16BE(d):t.readUInt32BE(d);d+=h<1?2:4;let ne=t.readUInt8(d);d+=1;for(let C=0;C<ne;C++){let re=w?t.readUInt16BE(d)&32767:t.readUInt8(d)&127;if(d+=w?2:1,b===m&&(u.get(re)??0)%2===1)return!0}}return!1}catch{return!1}finally{await n.close().catch(()=>{})}}import{execFile as le}from"node:child_process";import{randomBytes as he}from"node:crypto";import{copyFile as we,mkdtemp as W,open as pe,readFile as ye,rm as R}from"node:fs/promises";import{tmpdir as A}from"node:os";import{extname as K,join as I}from"node:path";import{promisify as ge}from"node:util";var $=ge(le),q=async()=>({...await import("./paths-BBUKTDDP.js"),...await import("./run-VJDF5WRF.js")}),F=e=>e!=="darwin",xe={".nef":[".nef",".nrw"],".arw":[".arw",".srf",".sr2"],".rw2":[".rw2",".rwl"],".3fr":[".3fr",".fff"],".dcr":[".dcr",".kdc"]},be=[["nikon",".nef"],["sony",".arw"],["pentax",".pef"],["ricoh",".pef"],["samsung",".srw"],["hasselblad",".3fr"],["seiko epson",".erf"],["epson",".erf"],["kodak",".dcr"],["eastman kodak",".dcr"],["leaf",".mos"]],Ie=new Set([32803,34892]),Ee=new Set([32767,32769,32770,34316,34713,65e3,65535]),Se="85c0b687820f11e08111f4ce462b6a48";function j(e,n){let t=(s,c)=>n?s.readUInt16LE(c):s.readUInt16BE(c),i=(s,c)=>n?s.readUInt32LE(c):s.readUInt32BE(c),r={1:1,2:1,3:2,4:4,7:1,13:4};async function o(s){if(s<=0)return;let c=await e(s,2);if(c.length<2)return;let u=t(c,0);if(u===0||u>1e3)return;let h=await e(s+2,u*12+4);if(h.length<u*12+4)return;let w=new Map;for(let d=0;d<u;d++){let p=d*12;w.set(t(h,p),{type:t(h,p+2),count:i(h,p+4),inline:h.subarray(p+8,p+12),offset:i(h,p+8)})}return{entries:w,next:i(h,u*12)}}async function a(s,c=16){if(!s)return[];let u=r[s.type]===2?2:4,h=Math.min(s.count,c),w=h*u<=4?s.inline:await e(s.offset,h*u),d=[];for(let p=0;p<h&&(p+1)*u<=w.length;p++)d.push(u===2?t(w,p*u):i(w,p*u));return d}async function f(s){if(s?.type!==2)return"";let c=Math.min(s.count,64);return(c<=4?s.inline.subarray(0,c):await e(s.offset,c)).toString("latin1").replace(/\0.*$/s,"").trim()}async function m(s){let[c]=await a(s.entries.get(274),1);return c!==void 0&&c>=1&&c<=8?c:1}async function y(s){let c=[s],u=new Set;for(let h=0;c.length>0&&h<12;h++){let w=c.shift(),[d]=await a(w.entries.get(262),1),[p]=await a(w.entries.get(259),1);if(d!==void 0&&Ie.has(d)||p!==void 0&&Ee.has(p))return!0;for(let l of[...await a(w.entries.get(330),8),w.next]){if(l===0||u.has(l))continue;u.add(l);let b=await o(l);b&&c.push(b)}}return!1}return{directory:o,text:f,orientation:m,hasMosaic:y,u32:i}}function V(e){let n=e.toString("latin1",0,2);return n==="II"?!0:n==="MM"?!1:void 0}async function Y(e,n){let t=V(e.subarray(n,n+2));if(t===void 0)return 1;let r=j(async(a,f)=>e.subarray(n+a,n+a+f),t),o=await r.directory(r.u32(e,n+4));return o?r.orientation(o):1}async function Pe(e){if(e[0]!==255||e[1]!==216)return 1;let n=2;for(;n+4<=e.length&&e[n]===255;){let t=e[n+1],i=e.readUInt16BE(n+2);if(t===225&&e.toString("latin1",n+4,n+10)==="Exif\0\0")return Y(e,n+10);if(t===218)break;n+=2+i}return 1}async function Be(e,n){let t=await e(0,Math.min(n,1048576)),i=[...x(t,0,t.length)].find(r=>r.type==="moov");if(!i)return 1;for(let r of x(t,i.start,i.end)){if(r.type!=="uuid"||t.toString("hex",r.start,r.start+16)!==Se)continue;let o=[...x(t,r.start+16,r.end)].find(a=>a.type==="CMT1");return o?Y(t,o.start):1}return 1}async function Re(e,n){if(n.length<92)return 1;let t=n.readUInt32BE(84),i=n.readUInt32BE(88);return t===0||i===0?1:Pe(await e(t,Math.min(i,65536)))}async function Me(e){let n;try{n=await pe(e,"r")}catch{return}try{let{size:t}=await n.stat(),i=async(u,h)=>{let w=Math.max(0,Math.min(h,t-u)),d=Buffer.alloc(w);return w>0&&await n.read(d,0,w,u),d},r=await i(0,96);if(r.length<16)return;let o=r.toString("latin1",0,4);if(r.toString("latin1",0,15)==="FUJIFILMCCD-RAW")return{ext:".raf",orientation:await Re(i,r)};if(r.toString("latin1",4,12)==="ftypcrx ")return{ext:".cr3",orientation:await Be(i,t)};let a=V(r);if(a===void 0)return;let f=j(i,a),m=await f.directory(f.u32(r,4));if(!m)return;let y=await f.orientation(m);if(o==="IIRO"||o==="IIRS"||o==="MMOR")return{ext:".orf",orientation:y};if(o==="IIU\0")return{ext:".rw2",orientation:y};if(o!=="II*\0"&&o!=="MM\0*")return;if(m.entries.has(50706))return{ext:".dng",orientation:y};if(r.toString("latin1",8,11)==="CR")return{ext:".cr2",orientation:y};let s=(await f.text(m.entries.get(271))).toLowerCase(),c=be.find(([u])=>s.startsWith(u));return!c||!await f.hasMosaic(m)?void 0:{ext:c[1],orientation:y}}catch{return}finally{await n.close().catch(()=>{})}}async function Ue(e=process.platform){return F(e)?await(await q()).installed("raw")!==void 0:k()}async function Z(e,n){let{installed:t,runExtension:i}=await q(),r=await t("raw");if(r===void 0)throw U(e,n);return{ext:r,runExtension:i}}async function G(e,n,t){let i=K(e).toLowerCase();if((xe[n.ext]??[n.ext]).includes(i))return t(e);let r=await W(I(A(),"forge-raw-"));try{let o=I(r,`photo${n.ext}`);return await we(e,o),await t(o)}finally{await R(r,{recursive:!0,force:!0}).catch(()=>{})}}async function rt(e,n,t=process.platform){if(F(t)){let{ext:a,runExtension:f}=await Z(e,t),m=await f(a,["--info","--in",e],{subject:e,platform:t});if(!(m.width>0&&m.height>0))throw new Error("the raw extension reported no size");return{width:m.width,height:m.height}}let{stdout:i}=await G(e,n,a=>$("/usr/bin/sips",["-g","typeIdentifier","-g","pixelWidth","-g","pixelHeight",a],{timeout:3e4}));if(!/typeIdentifier:\s*\S*raw-image/.test(i))return;let r=Number(/pixelWidth:\s*(\d+)/.exec(i)?.[1]??0),o=Number(/pixelHeight:\s*(\d+)/.exec(i)?.[1]??0);if(!(r===0||o===0))return n.orientation>=5?{width:o,height:r}:{width:r,height:o}}async function Q(e,n=process.platform){if(F(n))return De(e,n);if(!await Ue(n))throw U(e,n);let t=await Me(e)??{ext:K(e).toLowerCase(),orientation:1},i=I(A(),`forge-raw-${he(8).toString("hex")}.png`),r=async()=>{await R(i,{force:!0}).catch(()=>{})};try{return await G(e,t,o=>$("/usr/bin/sips",["-s","format","png",o,"--out",i],{timeout:3e5})),{path:i,cleanup:r}}catch(o){throw await r(),o}}async function De(e,n){let t=await W(I(A(),"forge-raw-")),i=async()=>{await R(t,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:o}=await Z(e,n),a=I(t,"decoded.rgb"),f=I(t,"decoded.png"),{width:m,height:y}=await o(r,["--in",e,"--out",a],{subject:e,platform:n});return await(await P())(await ye(a),{raw:{width:m,height:y,channels:3}}).png().toFile(f),await R(a,{force:!0}),{path:f,cleanup:i}}catch(r){throw await i(),r}}async function ft(e,n){return n!=="heic"&&n!=="raw"?e:Fe(e,n)}var ke=4,X=256*1024*1024,T=X,ee=6e4,te=ee,M;function Ae(){clearTimeout(M),M=setTimeout(()=>g.clear(),te),M.unref?.()}var g=new Map;async function Fe(e,n){let{size:t,mtimeMs:i}=await Ne(e);Ae();let r=`${n}\0${e}`,o=g.get(r);if(g.delete(r),o&&o.size===t&&o.mtimeMs===i)return g.set(r,o),o.png;let a={size:t,mtimeMs:i,png:Ce(e,n),bytes:0};return g.set(r,a),a.png.then(f=>{a.bytes=f.length,f.length>T&&g.get(r)===a&&g.delete(r),Te()},()=>{g.get(r)===a&&g.delete(r)}),a.png}function Te(){let e=0;for(let n of g.values())e+=n.bytes;for(let[n,t]of g){if(g.size<=ke&&e<=T)break;g.delete(n),e-=t.bytes}}async function Ce(e,n){if(n==="heic"&&!await _())throw S(e);let t=n==="heic"?await O(e):await Q(e);try{return await ve(t.path)}finally{await t.cleanup()}}function ut(){g.clear(),clearTimeout(M)}function dt(e){te=e??ee}function mt(e){T=e??X}export{_ as a,$e as b,qe as c,Me as d,Ue as e,rt as f,ft as g,ut as h,dt as i,mt as j};