forge-terminal 0.5.9 → 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 (173) hide show
  1. package/README.md +53 -16
  2. package/dist/chunks/{about-credits-32BUKO4K.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-PHDTJAFT.js +3 -0
  6. package/dist/chunks/{catalog-FMHWWMUX.js → catalog-G44MXIAF.js} +1 -1
  7. package/dist/chunks/check-BFHBPCGW.js +3 -0
  8. package/dist/chunks/chunk-2YU4EI24.js +3 -0
  9. package/dist/chunks/chunk-3IAJTXYM.js +3 -0
  10. package/dist/chunks/chunk-3OCPO5V6.js +3 -0
  11. package/dist/chunks/chunk-42IEPG2K.js +3 -0
  12. package/dist/chunks/{chunk-WE6KP4FR.js → chunk-4AL5QJLM.js} +1 -1
  13. package/dist/chunks/chunk-56B3VZCM.js +3 -0
  14. package/dist/chunks/chunk-56QHX7QR.js +3 -0
  15. package/dist/chunks/chunk-6NCN7OJ5.js +7 -0
  16. package/dist/chunks/chunk-6PUV4HSU.js +3 -0
  17. package/dist/chunks/chunk-72UR37EG.js +3 -0
  18. package/dist/chunks/chunk-7NP76V4U.js +3 -0
  19. package/dist/chunks/{chunk-7XFLG32B.js → chunk-AETM2PCZ.js} +1 -1
  20. package/dist/chunks/chunk-BQV3DSUZ.js +23 -0
  21. package/dist/chunks/chunk-BSFBZBAI.js +16 -0
  22. package/dist/chunks/chunk-DC2DHMXO.js +3 -0
  23. package/dist/chunks/{chunk-WBW6G4N6.js → chunk-DKHBJ52G.js} +1 -1
  24. package/dist/chunks/chunk-E5VPEBUQ.js +3 -0
  25. package/dist/chunks/chunk-EYOO35US.js +3 -0
  26. package/dist/chunks/chunk-F4TUCI6D.js +3 -0
  27. package/dist/chunks/{chunk-MF3KKEFB.js → chunk-FEJSM3E4.js} +1 -1
  28. package/dist/chunks/chunk-FGR6QCG5.js +3 -0
  29. package/dist/chunks/{chunk-W53XNVNH.js → chunk-G2V33TMN.js} +1 -1
  30. package/dist/chunks/{chunk-ILQDMVJR.js → chunk-G4M2XYFJ.js} +1 -1
  31. package/dist/chunks/chunk-H332YFSO.js +4 -0
  32. package/dist/chunks/chunk-HAOKWLD3.js +4 -0
  33. package/dist/chunks/chunk-I2LPGKUU.js +3 -0
  34. package/dist/chunks/{chunk-YRXJDFP3.js → chunk-I3C3SRF2.js} +1 -1
  35. package/dist/chunks/{chunk-SM735FG7.js → chunk-ID4GJZJ6.js} +1 -1
  36. package/dist/chunks/chunk-ID75X37Z.js +3 -0
  37. package/dist/chunks/chunk-JPASVE56.js +3 -0
  38. package/dist/chunks/chunk-JZM37DG2.js +3 -0
  39. package/dist/chunks/chunk-KPUKMAYK.js +19 -0
  40. package/dist/chunks/{chunk-SZRSAL64.js → chunk-M7HB4L6L.js} +1 -1
  41. package/dist/chunks/chunk-NUCGWLOY.js +8 -0
  42. package/dist/chunks/{chunk-4KGC5ZBZ.js → chunk-OK56WDPA.js} +1 -1
  43. package/dist/chunks/{chunk-I25E2XDH.js → chunk-OLKPV4WO.js} +1 -1
  44. package/dist/chunks/chunk-OPDC577C.js +3 -0
  45. package/dist/chunks/chunk-OQ6DTE56.js +3 -0
  46. package/dist/chunks/chunk-PA7AG2NK.js +55 -0
  47. package/dist/chunks/chunk-PNPAHKJR.js +3 -0
  48. package/dist/chunks/chunk-PON65UTS.js +3 -0
  49. package/dist/chunks/{chunk-GVVQP3LF.js → chunk-PXCEMDOY.js} +2 -2
  50. package/dist/chunks/chunk-QMNERJL2.js +3 -0
  51. package/dist/chunks/{chunk-OXDRJO4V.js → chunk-R6QVLPGC.js} +1 -1
  52. package/dist/chunks/chunk-S44LAUHZ.js +3 -0
  53. package/dist/chunks/chunk-SCJ2QXZF.js +80 -0
  54. package/dist/chunks/{chunk-4MJEEEFA.js → chunk-SJIDFYPT.js} +1 -1
  55. package/dist/chunks/{chunk-3374PCO5.js → chunk-TQEGSODD.js} +1 -1
  56. package/dist/chunks/chunk-ULX4ZD2Y.js +3 -0
  57. package/dist/chunks/chunk-W6QOV4RP.js +6 -0
  58. package/dist/chunks/chunk-WWWWXOM4.js +3 -0
  59. package/dist/chunks/{chunk-6RCS3KBP.js → chunk-XIR3VWQY.js} +1 -1
  60. package/dist/chunks/chunk-XUJLUOGD.js +6 -0
  61. package/dist/chunks/chunk-Y3DMALHT.js +66 -0
  62. package/dist/chunks/chunk-YXV3PYVI.js +3 -0
  63. package/dist/chunks/chunk-Z3PQ5TMU.js +3 -0
  64. package/dist/chunks/chunk-ZL7E7PZN.js +4 -0
  65. package/dist/chunks/clip-command-6Q7BTXR5.js +3 -0
  66. package/dist/chunks/clipboard-QWNPA3GM.js +3 -0
  67. package/dist/chunks/colour-7HPH6KTY.js +3 -0
  68. package/dist/chunks/command-JTK4IOS7.js +3 -0
  69. package/dist/chunks/config-command-DIQTU7DM.js +3 -0
  70. package/dist/chunks/continue-editing-FTUY6UFG.js +3 -0
  71. package/dist/chunks/decoded-IXLPWTGZ.js +3 -0
  72. package/dist/chunks/{entry-BZYPZONY.js → entry-ZF7D32ZI.js} +2 -2
  73. package/dist/chunks/execute-RP7ZMWLZ.js +3 -0
  74. package/dist/chunks/extensions-YOZ4IF4E.js +3 -0
  75. package/dist/chunks/{extensions-command-JZSOQJEV.js → extensions-command-O7UHUJ3Y.js} +1 -1
  76. package/dist/chunks/ffmpeg-2ZP3GXJX.js +3 -0
  77. package/dist/chunks/image-6A7FXKIR.js +3 -0
  78. package/dist/chunks/{install-KGFOAQCU.js → install-4L7JGP3X.js} +1 -1
  79. package/dist/chunks/install-XJAPLIH2.js +3 -0
  80. package/dist/chunks/launch-2KSJ4GGN.js +18 -0
  81. package/dist/chunks/link-inputs-GTEW6ZH4.js +3 -0
  82. package/dist/chunks/lock-KNR7XS7Q.js +3 -0
  83. package/dist/chunks/manager-YH5XAMZA.js +4 -0
  84. package/dist/chunks/{needed-DYERJ72M.js → needed-TB3OC76N.js} +1 -1
  85. package/dist/chunks/notify-UD7FQAWX.js +3 -0
  86. package/dist/chunks/{own-2QGMHSKL.js → own-KUGTZ3BV.js} +1 -1
  87. package/dist/chunks/{paths-6OENILJ4.js → paths-BBUKTDDP.js} +1 -1
  88. package/dist/chunks/pdfium-MJ65YOXW.js +3 -0
  89. package/dist/chunks/preferences-7S7YZOFK.js +3 -0
  90. package/dist/chunks/preset-command-KMKR6KMG.js +3 -0
  91. package/dist/chunks/registry-657JRJR5.js +3 -0
  92. package/dist/chunks/run-VJDF5WRF.js +3 -0
  93. package/dist/chunks/server-6PH2DSFW.js +81 -0
  94. package/dist/chunks/signals-VY2XE3LV.js +3 -0
  95. package/dist/chunks/text-layer-PFIDCTEL.js +5 -0
  96. package/dist/chunks/theme-FVQOSLPB.js +3 -0
  97. package/dist/chunks/transcribe-FUN2SKRN.js +3 -0
  98. package/dist/chunks/transcribe-command-KNSUHROE.js +3 -0
  99. package/dist/chunks/update-command-X4OSYETA.js +3 -0
  100. package/dist/chunks/update-note-LV7G4CHE.js +3 -0
  101. package/dist/chunks/video-link-CF7GUA6V.js +3 -0
  102. package/dist/chunks/watch-command-3C4AWM7A.js +3 -0
  103. package/dist/helpers/forge-transcribe +0 -0
  104. package/dist/index.js +16 -15
  105. package/package.json +15 -3
  106. package/skills/forge/SKILL.md +7 -3
  107. package/dist/chunks/args-ZVZQR23M.js +0 -3
  108. package/dist/chunks/boot-2YFTQOMG.js +0 -3
  109. package/dist/chunks/check-B6NP7BEM.js +0 -3
  110. package/dist/chunks/chunk-4RNVZQRC.js +0 -3
  111. package/dist/chunks/chunk-6KUWZQGG.js +0 -3
  112. package/dist/chunks/chunk-6MWJO3GB.js +0 -4
  113. package/dist/chunks/chunk-6PEIZZNE.js +0 -3
  114. package/dist/chunks/chunk-7FW7JX74.js +0 -36
  115. package/dist/chunks/chunk-7XDMC7FL.js +0 -72
  116. package/dist/chunks/chunk-AR3M2PLK.js +0 -3
  117. package/dist/chunks/chunk-ASLKQXZ2.js +0 -3
  118. package/dist/chunks/chunk-BKLPRILS.js +0 -3
  119. package/dist/chunks/chunk-EEQSUBBL.js +0 -3
  120. package/dist/chunks/chunk-FAUL5L2W.js +0 -3
  121. package/dist/chunks/chunk-FBVRKMAF.js +0 -3
  122. package/dist/chunks/chunk-GHYODKA3.js +0 -3
  123. package/dist/chunks/chunk-H3DIRJFE.js +0 -3
  124. package/dist/chunks/chunk-HTA25PO2.js +0 -3
  125. package/dist/chunks/chunk-J7FLFHQJ.js +0 -3
  126. package/dist/chunks/chunk-K253E723.js +0 -3
  127. package/dist/chunks/chunk-KH5DHZ2U.js +0 -8
  128. package/dist/chunks/chunk-L44NRTP4.js +0 -3
  129. package/dist/chunks/chunk-N32JL4UI.js +0 -3
  130. package/dist/chunks/chunk-N6RCLJE6.js +0 -4
  131. package/dist/chunks/chunk-NDYMC3HY.js +0 -66
  132. package/dist/chunks/chunk-NMECUMJD.js +0 -7
  133. package/dist/chunks/chunk-OQBIYNGK.js +0 -6
  134. package/dist/chunks/chunk-Q6KQWJ4J.js +0 -3
  135. package/dist/chunks/chunk-QQV7CCAY.js +0 -3
  136. package/dist/chunks/chunk-RCWFUBTG.js +0 -3
  137. package/dist/chunks/chunk-TFGK7IRZ.js +0 -19
  138. package/dist/chunks/chunk-TGC24JEW.js +0 -4
  139. package/dist/chunks/chunk-TLHUFIXD.js +0 -3
  140. package/dist/chunks/chunk-V6GWPR2A.js +0 -3
  141. package/dist/chunks/chunk-VJMOZPHW.js +0 -3
  142. package/dist/chunks/chunk-YPAFAG4W.js +0 -6
  143. package/dist/chunks/chunk-ZBMJTIYR.js +0 -3
  144. package/dist/chunks/chunk-ZX5FDZZW.js +0 -55
  145. package/dist/chunks/clip-command-MDSM6KJP.js +0 -3
  146. package/dist/chunks/clipboard-IZJTBTSW.js +0 -3
  147. package/dist/chunks/colour-2MYODUDY.js +0 -3
  148. package/dist/chunks/command-GAGAD65W.js +0 -3
  149. package/dist/chunks/config-command-CKPJXJEE.js +0 -3
  150. package/dist/chunks/continue-editing-M6WESEVB.js +0 -3
  151. package/dist/chunks/decoded-XWKU23RG.js +0 -3
  152. package/dist/chunks/execute-7M6WA4W7.js +0 -3
  153. package/dist/chunks/extensions-E3OUBT36.js +0 -3
  154. package/dist/chunks/ffmpeg-KDZEPLNA.js +0 -3
  155. package/dist/chunks/image-R5C3AWHT.js +0 -3
  156. package/dist/chunks/install-MFYGS5TG.js +0 -3
  157. package/dist/chunks/launch-VNW4YQ4Z.js +0 -17
  158. package/dist/chunks/lock-BG3CLOHA.js +0 -3
  159. package/dist/chunks/manager-L753MI7U.js +0 -4
  160. package/dist/chunks/notify-NQNNOBFC.js +0 -3
  161. package/dist/chunks/pdfium-77L526HZ.js +0 -3
  162. package/dist/chunks/preferences-3P4V2EDX.js +0 -3
  163. package/dist/chunks/preset-command-UNMXHW5A.js +0 -3
  164. package/dist/chunks/registry-RS7LQ3UA.js +0 -3
  165. package/dist/chunks/run-GUFPETHF.js +0 -3
  166. package/dist/chunks/server-PIXRL5PA.js +0 -77
  167. package/dist/chunks/text-layer-LHZNDMPZ.js +0 -3
  168. package/dist/chunks/theme-P3ZE2ZYB.js +0 -3
  169. package/dist/chunks/transcribe-KXQXEVBJ.js +0 -3
  170. package/dist/chunks/transcribe-command-JHWN4RWU.js +0 -3
  171. package/dist/chunks/update-command-DWEBUFT5.js +0 -3
  172. package/dist/chunks/update-note-CY3LCBCJ.js +0 -3
  173. package/dist/chunks/watch-command-QGVXM23I.js +0 -3
package/README.md CHANGED
@@ -50,7 +50,7 @@ That puts `forge` on your `PATH`, so it works from any directory. Verify:
50
50
 
51
51
  ```bash
52
52
  forge --version
53
- # 0.5.9
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).
@@ -211,7 +211,7 @@ Forge stores preferences at `~/.config/forge/config.json`, or
211
211
 
212
212
  ```bash
213
213
  forge config list # show every setting and where it lives
214
- forge config set output ~/Desktop # default output folder
214
+ forge config set output ~/Desktop # default output folder, made on first save
215
215
  forge config set theme light # dark or light
216
216
  forge config set quality 80 # what the quality slider opens on
217
217
  forge config set update-check off # stop the once-a-day update check
@@ -331,7 +331,8 @@ forge *.jpg --max-size 1mb # a whole folder
331
331
  ```
332
332
 
333
333
  `--quality` without `--to` compresses; with `--to` it converts, as it always
334
- has. `--quality` and `--max-size` are mutually exclusive — they ask the same
334
+ has. So does an `-o` whose extension names another format: `forge photo.jpg
335
+ --max-size 100kb -o small.webp` writes a WebP that fits. `--quality` and `--max-size` are mutually exclusive — they ask the same
335
336
  question two ways, and Forge will not guess which wins.
336
337
 
337
338
  A PNG or GIF is compressed by cutting it to fewer colours, which is what
@@ -356,6 +357,37 @@ so — and it encodes a candidate to find out rather than guessing:
356
357
  ↵ convert another · c convert to WebP · o open · s show in finder · ctrl-c close app
357
358
  ```
358
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
+
359
391
  ## The clipboard
360
392
 
361
393
  On a Mac, a copied image can be the file. Copy a screenshot (⌃⇧⌘4) or an
@@ -483,21 +515,22 @@ forge extensions add boost # about 15 MB on Apple silicon, 16 MB on
483
515
  forge extensions add remove-background # 32 KB on a Mac (Apple Vision); 46 to 52 MB on Windows and Linux
484
516
  forge extensions add heic # about 0.5 MB; Windows and Linux
485
517
  forge extensions add whisper # transcribe where Apple's recogniser is not (see above)
486
- forge extensions add yt-dlp # YouTube links for transcribe, every OS
518
+ forge extensions add yt-dlp # video links, every OS
487
519
  forge extensions add video # Forge's own ffmpeg, 25 MB; Apple-silicon Macs
488
520
  forge extensions remove boost
489
521
  ```
490
522
 
491
523
  ```bash
492
- forge photo.jpg --sharpen # photo-sharp.png (the same size, sharper)
493
- forge photo.jpg --boost # photo-2x.png (2x, the default)
494
- forge photo.jpg --boost 3 # photo-3x.png (needs boost 1.1.0 or later)
495
- forge photo.jpg --boost 4 # photo-4x.png
524
+ forge photo.jpg --sharpen # photo-sharp.jpg (the same size, sharper)
525
+ forge photo.jpg --boost # photo-2x.jpg (2x, the default)
526
+ forge photo.jpg --boost 3 # photo-3x.jpg (needs boost 1.1.0 or later)
527
+ forge photo.jpg --boost 4 # photo-4x.jpg
496
528
  forge photo.jpg --remove-bg # photo-cutout.png
497
529
  forge photo.jpg --remove-bg --to webp
498
530
  ```
499
531
 
500
- Output goes beside the source unless `-o` says otherwise. Boost keeps
532
+ Output goes beside the source unless `-o` says otherwise. Boost keeps the
533
+ image's format unless `--to` or `-o`'s extension names another, and keeps
501
534
  transparency, and flattens it onto `--background` only when `--to` names a
502
535
  format that cannot carry it. A cutout must be saved in a format that holds
503
536
  transparency (PNG, WebP, AVIF, TIFF); JPEG is refused, because flattening would
@@ -682,6 +715,10 @@ $ forge big.pdf --to png --pages 1,2 # big.pdf has 300 pages
682
715
  4.2 KB → 928 B total
683
716
  ```
684
717
 
718
+ `-o` naming a file numbers the pages after it, in its folder: `-o
719
+ out/pages.png` writes `out/pages-1.png`, `out/pages-2.png`… One page out is
720
+ `out/pages.png` itself.
721
+
685
722
  ### image → PDF
686
723
 
687
724
  ```
@@ -898,8 +935,8 @@ forge <inputs...> --to <format> [options]
898
935
 
899
936
  | Flag | Meaning |
900
937
  | --- | --- |
901
- | `-t, --to <format>` | target format (required) |
902
- | `-o, --output <path>` | output file or directory |
938
+ | `-t, --to <format>` | target format (without it, the format `-o`'s extension names) |
939
+ | `-o, --output <path>` | output file or directory; a leading `~` is home |
903
940
  | `-q, --quality <n>` | 1–100, lossy targets only, **requires `--to`** |
904
941
  | `--background <css>` | fill colour when flattening alpha (default white) |
905
942
  | `--keep-metadata` | preserve EXIF/GPS instead of stripping it |
@@ -1097,7 +1134,7 @@ Eleven tools, deliberately few:
1097
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 |
1098
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 |
1099
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 |
1100
- | `forge_transcribe` | a video or sound file, or a YouTube link, into notes and a transcript (`to`, `detail`, `language`, `format`, `output`, `overwrite`); writes the file and returns its text |
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 |
1101
1138
  | `forge_read_text` | the text in a picture, screenshot, scan or PDF (`language`, `format`, `output`, `overwrite`); writes the file and returns its text |
1102
1139
 
1103
1140
  Paths must be absolute. Results come back as structured content in the
@@ -1141,7 +1178,7 @@ photo.png · PNG · 122 KB · 2756×774
1141
1178
  With `--json`:
1142
1179
 
1143
1180
  ```json
1144
- {"forge":"0.5.9","ok":true,"probes":[{"path":"/Users/me/photo.png","kind":"image","format":"png","bytes":122449,"width":2756,"height":774,"targets":["jpeg","png","webp","avif","gif","tiff","pdf"],"actions":["convert"]}],"failures":[]}
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":[]}
1145
1182
  ```
1146
1183
 
1147
1184
  `targets` and `actions` come from the engines' own capabilities, so they are
@@ -1167,7 +1204,7 @@ succeeded) and `failures`. A conversion, compression or page operation adds
1167
1204
 
1168
1205
  ```jsonc
1169
1206
  {
1170
- "forge": "0.5.9",
1207
+ "forge": "0.7.0",
1171
1208
  "ok": false,
1172
1209
  "results": [
1173
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-L753MI7U.js")).listExtensions()}={}){let[e,i]=await Promise.all([k(n),t().catch(()=>[])]),{extensionCredits:s}=await import("./extensions-E3OUBT36.js"),r=i.filter(o=>o.installed!==void 0).flatMap(o=>s(o.entry)),a=p({bundled:l(e?.text??""),extensions:r});return e?{sections:a,file:e.path}:{sections:a}}export{F as loadCredits};
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{a,b,c,d,e,f,g,h,i,j,k,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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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-H3DIRJFE.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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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
+ `);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
+ `).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
+ `);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})}
7
+ `)})}export{q as a,D as b};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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 A,e as y,f as T,g as w}from"./chunk-N32JL4UI.js";import{G as R}from"./chunk-ZBMJTIYR.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 R(t,"Try: Tailwind, from 50 to 950.");let{L:o,C:n,h:s}=T(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&&!y(w({L:f,C:p,h:s}));)p-=.002;let g=A(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};
@@ -0,0 +1,23 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
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
+ `);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
+ `)}var U=e=>e.filter(n=>n.length>0);function ue(e){let n=U(e).map(t=>t.map(Fe).join(`
6
+
7
+ `));return n.length?`${n.join(`
8
+
9
+ ---
10
+
11
+ `)}
12
+ `:""}function je(e){return e.kind==="heading"||e.kind==="paragraph"?e.text:e.kind==="list"?e.items.map((n,t)=>`${e.ordered?`${t+1}.`:"-"} ${n}`).join(`
13
+ `):e.rows.map(n=>n.join(" ")).join(`
14
+ `)}function pe(e){let n=U(e).map(t=>t.map(je).join(`
15
+
16
+ `));return n.length?`${n.join(`
17
+
18
+ `)}
19
+ `:""}var De="table{border-collapse:collapse;width:100%;margin:0 0 8pt}th,td{border:1px solid #c7c7cc;padding:2pt 6pt;text-align:left;vertical-align:top}ol{margin:0 0 8pt}",ce='<p style="margin:0;font-size:5pt">&nbsp;</p>';function Ge(e){if(e.kind==="heading")return`<h${e.level}>${v(e.text)}</h${e.level}>`;if(e.kind==="paragraph")return`<p>${v(e.text)}</p>`;if(e.kind==="list"){let i=e.ordered?"ol":"ul";return`<${i}>${e.items.map(a=>`<li>${v(a)}</li>`).join("")}</${i}>`}let[n=[],...t]=e.rows,r=(i,a)=>`<tr>${i.map(d=>`<${a}>${v(d)}</${a}>`).join("")}</tr>`,o=`<table>${r(n,"th")}${t.map(i=>r(i,"td")).join("")}</table>`;return`${ce}${o}${ce}`}function ge(e,n){let t=U(e).map(r=>r.map(Ge).join(`
20
+ `));return["<!doctype html>",`<html><head><meta charset="utf-8"><title>${v(n)}</title><style>${te}${De}</style></head><body>`,t.join(`
21
+ <hr>
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-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,16 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{c as Mt}from"./chunk-KXKQDFHX.js";var ln=new RegExp("\\p{M}","u"),Ut=new RegExp("\\p{L}","u"),hn=new RegExp("\\p{Nd}","u");function Ft(t){let r=String.fromCodePoint(t);return ln.test(r)?"NSM":t>=1632&&t<=1641||t===1643||t===1644?"AN":hn.test(r)?"EN":t>=1424&&t<=1535||t>=64285&&t<=64335?Ut.test(r)?"R":"ON":t>=1536&&t<=1791||t>=1792&&t<=1983||t>=1872&&t<=1919||t>=2208&&t<=2303||t>=64336&&t<=65023||t>=65136&&t<=65279?Ut.test(r)?"AL":"ON":Ut.test(r)?"L":t===43||t===45?"ES":t===35||t===36||t===37||t===162||t===163||t===176?"ET":t===44||t===46||t===58||t===47||t===160?"CS":r===" "||r===" "||t===12288?"WS":"ON"}var dn={"(":")",")":"(","[":"]","]":"[","{":"}","}":"{","<":">",">":"<","\xAB":"\xBB","\xBB":"\xAB"};function kt(t){for(let r of t){let n=Ft(r.codePointAt(0)??0);if(n==="R"||n==="AL")return!0;if(n==="L")return!1}return!1}function gn(t){for(let r of t){let n=Ft(r.codePointAt(0)??0);if(n==="R"||n==="AL"||n==="AN")return!0}return!1}function Dt(t,r){let n=[...t];if(!r&&!gn(t))return t;let i=n.length,e=n.map(s=>Ft(s.codePointAt(0)??0)),o=r?1:0,a=o?"R":"L";for(let s=0;s<i;s++){e[s]==="NSM"&&(e[s]=s>0?e[s-1]??"ON":o?"R":"L");let l=e[s];l==="L"||l==="R"||l==="AL"?a=l:l==="EN"&&a==="AL"&&(e[s]="AN")}for(let s=0;s<i;s++)e[s]==="AL"&&(e[s]="R");for(let s=1;s<i-1;s++){let l=e[s],d=e[s-1],u=e[s+1];(l==="ES"||l==="CS")&&d==="EN"&&u==="EN"?e[s]="EN":l==="CS"&&d==="AN"&&u==="AN"&&(e[s]="AN")}for(let s=0;s<i;s++){if(e[s]!=="ET")continue;let l=s;for(;l<i&&e[l]==="ET";)l++;if(e[s-1]==="EN"||e[l]==="EN")for(let d=s;d<l;d++)e[d]="EN";s=l-1}for(let s=0;s<i;s++)(e[s]==="ES"||e[s]==="ET"||e[s]==="CS")&&(e[s]="ON");let c=o?"R":"L";for(let s=0;s<i;s++)e[s]==="L"||e[s]==="R"?c=e[s]:e[s]==="EN"&&c==="L"&&(e[s]="L");let f=s=>s==="L"?"L":s==="R"||s==="EN"||s==="AN"?"R":void 0;for(let s=0;s<i;s++){if(e[s]!=="WS"&&e[s]!=="ON")continue;let l=s;for(;l<i&&(e[l]==="WS"||e[l]==="ON");)l++;let d=s>0?f(e[s-1]):o?"R":"L",u=l<i?f(e[l]):o?"R":"L",b=d!==void 0&&d===u?d:o?"R":"L";for(let y=s;y<l;y++)e[y]=b;s=l-1}let h=e.map(s=>o===0?s==="R"?1:s==="EN"||s==="AN"?2:0:s==="L"||s==="EN"||s==="AN"?2:1),g=n.map((s,l)=>l),m=Math.max(...h),p=Math.min(...h.filter(s=>s%2===1),Number.POSITIVE_INFINITY);for(let s=m;s>=p&&s>0;s--)for(let l=0;l<i;l++){if((h[g[l]]??0)<s)continue;let d=l;for(;d<i&&(h[g[d]]??0)>=s;)d++;let u=g.slice(l,d).reverse();g.splice(l,d-l,...u),l=d-1}return g.map(s=>{let l=n[s];return(h[s]??0)%2===1?dn[l]??l:l}).join("")}var mn=[[65,90,"latin"],[97,122,"latin"],[170,170,"latin"],[186,186,"latin"],[192,591,"latin"],[7680,7935,"latin"],[11360,11391,"latin"],[42784,43007,"latin"],[65313,65338,"latin"],[65345,65370,"latin"],[880,1023,"greek"],[7936,8191,"greek"],[1024,1327,"cyrillic"],[7296,7311,"cyrillic"],[11744,11775,"cyrillic"],[42560,42655,"cyrillic"],[1328,1423,"armenian"],[1424,1535,"hebrew"],[64285,64335,"hebrew"],[1536,1791,"arabic"],[1872,1919,"arabic"],[2208,2303,"arabic"],[64336,65023,"arabic"],[65136,65279,"arabic"],[1792,1871,"syriac"],[1920,1983,"thaana"],[2304,2431,"devanagari"],[2432,2559,"bengali"],[2560,2687,"gurmukhi"],[2688,2815,"gujarati"],[2816,2943,"oriya"],[2944,3071,"tamil"],[3072,3199,"telugu"],[3200,3327,"kannada"],[3328,3455,"malayalam"],[3456,3583,"sinhala"],[3584,3711,"thai"],[3712,3839,"lao"],[3840,4095,"tibetan"],[4096,4255,"myanmar"],[4256,4351,"georgian"],[4352,4607,"hangul"],[4608,5023,"ethiopic"],[6016,6143,"khmer"],[6144,6319,"mongolian"],[12352,12447,"kana"],[12448,12543,"kana"],[12784,12799,"kana"],[65382,65439,"kana"],[110592,110959,"kana"],[12592,12687,"hangul"],[43360,43391,"hangul"],[44032,55295,"hangul"],[65440,65500,"hangul"],[11904,12255,"han"],[12288,12351,"han"],[12544,12591,"han"],[12704,12735,"han"],[12800,13311,"han"],[13312,19903,"han"],[19968,40959,"han"],[63744,64255,"han"],[65072,65103,"han"],[65281,65312,"han"],[65371,65381,"han"],[65504,65510,"han"],[131072,205743,"han"],[127744,129791,"emoji"],[9728,10175,"symbols"]];function Q(t){if(t<128)return t>=65&&t<=90||t>=97&&t<=122?"latin":void 0;for(let[r,n,i]of mn)if(t>=r&&t<=n)return i}var pn=new Set(["latin","greek","cyrillic","han","kana","hangul","armenian","georgian","ethiopic","emoji","symbols"]),It=new Set([...pn,"arabic","hebrew","thai","lao"]),bn={latin:"Latin",greek:"Greek",cyrillic:"Cyrillic",han:"Chinese",kana:"Japanese",hangul:"Korean",arabic:"Arabic",hebrew:"Hebrew",thai:"Thai",lao:"Lao",armenian:"Armenian",georgian:"Georgian",devanagari:"Devanagari",bengali:"Bengali",gurmukhi:"Gurmukhi",gujarati:"Gujarati",oriya:"Odia",tamil:"Tamil",telugu:"Telugu",kannada:"Kannada",malayalam:"Malayalam",sinhala:"Sinhala",tibetan:"Tibetan",myanmar:"Burmese",khmer:"Khmer",ethiopic:"Ethiopic",mongolian:"Mongolian",syriac:"Syriac",thaana:"Thaana",emoji:"emoji",symbols:"symbols"};function vt(t){return bn[t]}function xn(t){let r=new Set;for(let n of t){let i=Q(n.codePointAt(0)??0);i!==void 0&&r.add(i)}return[...r]}function Nt(t,r){let n=r?.toLowerCase().replace("_","-");if(n?.startsWith("ja"))return"ja";if(n?.startsWith("ko"))return"ko";if(n==="zh-tw"||n==="zh-hant"||n==="zh-hk")return"zh-TW";if(n?.startsWith("zh"))return"zh";let i=xn(t);return i.includes("kana")?"ja":i.includes("hangul")?"ko":"zh"}var yn={ja:"ja-JP",ko:"ko-KR",zh:"zh-CN","zh-TW":"zh-TW"},Sn={arabic:"ar-SA",hebrew:"he-IL",thai:"th-TH",lao:"lo-LA",devanagari:"hi-IN",bengali:"bn-IN",gurmukhi:"pa-IN",gujarati:"gu-IN",oriya:"or-IN",tamil:"ta-IN",telugu:"te-IN",kannada:"kn-IN",malayalam:"ml-IN",sinhala:"si-LK",khmer:"km-KH",myanmar:"my-MM",tibetan:"bo-CN",armenian:"hy-AM",georgian:"ka-GE",ethiopic:"am-ET",syriac:"syr-SY",thaana:"dv-MV"},An=new Set(["latin","greek","cyrillic","armenian","georgian","ethiopic","mongolian","emoji","symbols"]);function wn(t){return t===void 0?"neutral":t==="han"||t==="kana"||t==="hangul"?"eastAsia":An.has(t)?"latin":"complex"}var Un=new Set(["arabic","hebrew","syriac","thaana"]);function ke(t,r){let n=yn[Nt(t,r)],i=[],e="";for(let o of t){let a=Q(o.codePointAt(0)??0),c=wn(a);if(c==="neutral"){let m=i.at(-1);m?m.text+=o:e+=o;continue}let f=a!==void 0&&Un.has(a),h=c==="eastAsia"?n:c==="complex"&&a?Sn[a]:void 0,g=i.at(-1);g&&g.kind===c&&g.rtl===f&&g.lang===h?g.text+=o:i.push({text:e+o,kind:c,rtl:f,...h?{lang:h}:{}}),e=""}return e&&i.push({text:e,kind:"latin",rtl:!1}),i}import{existsSync as Jn,readFileSync as Xn}from"node:fs";import{dirname as qn,join as ct}from"node:path";import{fileURLToPath as Zn}from"node:url";import{gunzipSync as Qn}from"node:zlib";var tt=new Map;function Fn(){let t=new Map,r=[[64336,64511],[65152,65276]];for(let[n,i]of r)for(let e=n;e<=i;e++){let o=String.fromCodePoint(e).normalize("NFKD");if(o===String.fromCodePoint(e))continue;let a=t.get(o);a?a.push(e):t.set(o,[e])}for(let[n,i]of t)i.length===4?tt.set(n,{isolated:i[0]??0,final:i[1]??0,initial:i[2]??0,medial:i[3]??0}):i.length===2&&tt.set(n,{isolated:i[0]??0,final:i[1]??0,initial:0,medial:0})}Fn();var Ot=t=>t>=1611&&t<=1631||t===1648||t>=1750&&t<=1756||t>=1759&&t<=1764||t===1767||t===1768||t>=1770&&t<=1773,jt=1604,kn=new Set([1570,1571,1573,1575]),_t=t=>tt.has(String.fromCodePoint(t)),zt=t=>(tt.get(String.fromCodePoint(t))?.initial??0)!==0;function Wt(t){for(let r of t)if(_t(r.codePointAt(0)??0))return!0;return!1}function $t(t,r=()=>!0){let n=[...t].map(o=>o.codePointAt(0)??0),i=[],e=!1;for(let o=0;o<n.length;o++){let a=n[o]??0;if(a===8204||a===8205){e=a===8205?e:!1,i.push(a);continue}if(Ot(a)){i.push(a);continue}let c=tt.get(String.fromCodePoint(a));if(!c){e=!1,i.push(a);continue}let f=n[o+1]??0;if(a===jt&&kn.has(f)){let s=tt.get(String.fromCodePoint(jt,f)),l=s?e?s.final:s.isolated:0;if(l!==0&&r(l)){i.push(l),e=!1,o++;continue}}let h=o+1;for(;h<n.length&&Ot(n[h]??0);)h++;let g=n[h]??0,m=zt(a)&&g!==8204&&(_t(g)||g===8205),p=e?m?c.medial:c.final:m?c.initial:c.isolated;i.push(p!==0&&r(p)?p:a),e=zt(a)}return String.fromCodePoint(...i)}function Ht(t){return String.fromCodePoint(t).normalize("NFKD")}import{execFile as vn}from"node:child_process";import{existsSync as On,readdirSync as jn,readFileSync as zn,statSync as _n}from"node:fs";import{homedir as Wn}from"node:os";import{posix as Rt,win32 as en}from"node:path";var E={charset:15,encoding:16,charStrings:17,private:18,subrs:19,ros:1230,fdArray:1236,fdSelect:1237};function J(t,r){let n=(t[r]??0)*256+(t[r+1]??0);if(n===0)return{items:[],end:r+2};let i=t[r+2]??1,e=[],o=r+3;for(let f=0;f<=n;f++){let h=0;for(let g=0;g<i;g++)h=h*256+(t[o+g]??0);e.push(h),o+=i}let a=o-1,c=[];for(let f=0;f<n;f++)c.push(t.subarray(a+(e[f]??0),a+(e[f+1]??0)));return{items:c,end:a+(e[n]??1)}}function X(t){if(t.length===0)return new Uint8Array([0,0]);let r=t.reduce((c,f)=>c+f.length,0)+1,n=r<256?1:r<65536?2:r<16777216?3:4,i=new Uint8Array(3+(t.length+1)*n+r-1);i[0]=t.length>>8,i[1]=t.length&255,i[2]=n;let e=1,o=3,a=c=>{for(let f=n-1;f>=0;f--)i[o++]=c>>8*f&255};a(e);for(let c of t)e+=c.length,a(e);for(let c of t)i.set(c,o),o+=c.length;return i}function Pt(t){let r=[],n=[],i=0,e=0;for(;e<t.length;){let o=t[e]??0;if(o<=21){let a=o;e++,o===12&&(a=1200+(t[e]??0),e++),r.push({op:a,operands:n,raw:t.subarray(i,e)}),n=[],i=e}else if(o===28)n.push(((t[e+1]??0)<<8|(t[e+2]??0))<<16>>16),e+=3;else if(o===29)n.push((t[e+1]??0)<<24|(t[e+2]??0)<<16|(t[e+3]??0)<<8|(t[e+4]??0)),e+=5;else if(o===30){for(e++;e<t.length&&((t[e]??0)&15)!==15&&(t[e]??0)>>4!==15;)e++;e++,n.push(0)}else o>=32&&o<=246?(n.push(o-139),e++):o>=247&&o<=250?(n.push((o-247)*256+(t[e+1]??0)+108),e+=2):o>=251&&o<=254?(n.push(-(o-251)*256-(t[e+1]??0)-108),e+=2):e++}return r}function Nn(t){return[29,t>>24&255,t>>16&255,t>>8&255,t&255]}function Pn(t){return t>=1200?[12,t-1200]:[t]}function B(t,r){return Uint8Array.from([...r.flatMap(Nn),...Pn(t)])}function pt(t){let r=new Uint8Array(t.reduce((i,e)=>i+e.length,0)),n=0;for(let i of t)r.set(i,n),n+=i.length;return r}var q=(t,r)=>t.find(n=>n.op===r);function Gt(t){return t<1240?107:t<33900?1131:32768}function Bt(t){let r=t[2]??4,n=J(t,r),i=J(t,n.end),e=J(t,i.end),o=J(t,e.end),a=Pt(i.items[0]??new Uint8Array),c=q(a,E.ros)!==void 0,f=q(a,E.charStrings)?.operands[0]??0,h=J(t,f),g=h.items.length,m=q(a,E.charset)?.operands[0]??0,p=new Array(g).fill(0);if(m<=2)for(let F=0;F<g;F++)p[F]=F;else{let F=t[m]??0,S=m+1,U=1;if(F===0)for(;U<g;U++,S+=2)p[U]=(t[S]??0)<<8|(t[S+1]??0);else for(;U<g;){let C=(t[S]??0)<<8|(t[S+1]??0),N=t[S+2]??0;S+=3,F===2&&(N=N<<8|(t[S]??0),S++);for(let D=0;D<=N&&U<g;D++,U++)p[U]=C+D}}let s=q(a,E.fdArray)?.operands[0],l=q(a,E.fdSelect)?.operands[0],d=s===void 0?[]:J(t,s).items.map(Pt),u=new Array(g).fill(0);if(l!==void 0)if((t[l]??0)===0)for(let S=0;S<g;S++)u[S]=t[l+1+S]??0;else{let S=(t[l+1]??0)<<8|(t[l+2]??0),U=l+3;for(let C=0;C<S;C++,U+=3){let N=(t[U]??0)<<8|(t[U+1]??0),D=(t[U+3]??0)<<8|(t[U+4]??0);for(let v=N;v<D&&v<g;v++)u[v]=t[U+2]??0}}let b=F=>{let[S,U]=q(F,E.private)?.operands??[];if(S===void 0||U===void 0)return{dict:[],subrs:[]};let C=Pt(t.subarray(U,U+S)),N=q(C,E.subrs)?.operands[0];return{dict:C,subrs:N===void 0?[]:J(t,U+N).items}},y=b(a),k=d.length>0?d.map(b):[y];return{cidKeyed:c,glyphCount:g,codeOf:F=>c?p[F]??0:F,subset(F){let S=new Set([0]);for(let x of F)x>=0&&x<g&&S.add(x);let U=Math.max(...S)+1,C=new Map;for(let x of S){let R=Tn(h.items[x]??new Uint8Array,(k[u[x]??0]??y).subrs,o.items);if(!R){C.clear();break}C.set(x,R)}let N=C.size===S.size,D=k.map(()=>new Set),v=new Set;if(!N)for(let x of S)Cn(h.items[x]??new Uint8Array,k[u[x]??0]??y,{local:D[u[x]??0]??new Set,global:v,gsubrs:o.items});let H=x=>N?C.get(x):h.items[x],K=new Uint8Array([14]),A=new Uint8Array([11]),w=c?[...S].sort((x,R)=>x-R):Array.from({length:U},(x,R)=>R),W=(x,R)=>{if(R.size===0)return[];let _=x.length>=33900?33900:x.length>=1240?1240:0,Y=Math.max(...R)+1;return x.slice(0,Math.max(Y,_)).map((ft,At)=>R.has(At)?ft:A)},L=X(N?[]:W(o.items,v)),$=X(w.map(x=>S.has(x)?H(x)??K:K)),T=Rn(w.map(x=>p[x]??0)),I=d.length>0?En(w.map(x=>u[x]??0)):void 0,G=k.map((x,R)=>{let _=X(N?[]:W(x.subrs,D[R]??new Set)),Y=x.dict.filter(wt=>wt.op!==E.subrs).map(wt=>wt.raw),ft=!N&&x.subrs.length>0,At=ft?B(E.subrs,[0]):new Uint8Array,un=pt([...Y]).length+At.length;return{dict:pt([...Y,...ft?[B(E.subrs,[un])]:[]]),subrs:ft?_:new Uint8Array}}),et=Uint8Array.from([1,0,4,4]),rt=X(n.items),it=X(e.items),ut=x=>{let R=[];for(let _ of a)_.op===E.charset?R.push(B(E.charset,[x.charset])):_.op===E.charStrings?R.push(B(E.charStrings,[x.charStrings])):_.op===E.fdArray?R.push(B(E.fdArray,[x.fdArray])):_.op===E.fdSelect?R.push(B(E.fdSelect,[x.fdSelect])):_.op===E.private?R.push(B(E.private,[...x.priv])):_.op===E.encoding?R.push(B(E.encoding,[0])):R.push(_.raw);return X([pt(R)])},lt=ut({charset:0,charStrings:0,fdArray:0,fdSelect:0,priv:[0,0]}).length,z=et.length+rt.length+lt+it.length+L.length,ht=z;z+=T.length;let dt=z;z+=I?.length??0;let gt=z;z+=$.length;let ot=x=>X(d.map((R,_)=>pt(R.map(Y=>Y.op===E.private?B(E.private,[...x[_]??[0,0]]):Y.raw)))),mt=z;z+=d.length>0?ot(d.map(()=>[0,0])).length:0;let P=[];for(let x of G)P.push([x.dict.length,z]),z+=x.dict.length+x.subrs.length;let O=ut({charset:ht,charStrings:gt,fdArray:mt,fdSelect:dt,priv:P[0]??[0,0]}),st=[et,rt,O,it,L,T,...I?[I]:[],$,...d.length>0?[ot(P)]:[],...G.flatMap(x=>[x.dict,x.subrs])],at=new Uint8Array(st.reduce((x,R)=>x+R.length,0)),V=0;for(let x of st)at.set(x,V),V+=x.length;return at}}}function Rn(t){let r=[2],n=1;for(;n<t.length;){let o=t[n]??0,a=0;for(;n+a+1<t.length&&(t[n+a+1]??0)===o+a+1;)a++;r.push(o>>8,o&255,a>>8,a&255),n+=a+1}let i=1+2*Math.max(0,t.length-1);if(r.length<=i)return Uint8Array.from(r);let e=[0];for(let o=1;o<t.length;o++)e.push((t[o]??0)>>8,(t[o]??0)&255);return Uint8Array.from(e)}function En(t){let r=[],n=-1,i=0;return t.forEach((e,o)=>{e!==n&&(r.push(o>>8,o&255,e),n=e,i++)}),Uint8Array.from([3,i>>8,i&255,...r,t.length>>8,t.length&255])}function Tn(t,r,n){let i=[],e=[],o=[],a=[],c=0,f=!1,h=()=>{e.length=0,o.length=0,a.length=0},g=(s,l)=>{e.push(i.length),o.push(l.length),a.push(s),i.push(...l)},m=(s,l)=>{if(l>10)return f=!0,!0;let d=0;for(;d<s.length&&!f;){let u=s[d]??0;if(d++,u===28){let b=[28,s[d]??0,s[d+1]??0];g(((s[d]??0)<<8|(s[d+1]??0))<<16>>16,b),d+=2}else if(u>=32&&u<=246)g(u-139,[u]);else if(u>=247&&u<=250)g((u-247)*256+(s[d]??0)+108,[u,s[d]??0]),d++;else if(u>=251&&u<=254)g(-(u-251)*256-(s[d]??0)-108,[u,s[d]??0]),d++;else if(u===255)g(0,[255,s[d]??0,s[d+1]??0,s[d+2]??0,s[d+3]??0]),d+=4;else if(u===10||u===29){let b=u===10?r:n,y=a.pop(),k=e.pop(),F=o.pop();if(y===void 0||k===void 0||F===void 0||k+F!==i.length)return f=!0,!0;let S=b[y+Gt(b.length)];if(S===void 0)return f=!0,!0;if(i.length=k,m(S,l+1))return!0}else{if(u===11)return!1;if(u===14)return i.push(14),!0;if(u===1||u===3||u===18||u===23)c+=a.length>>1,h(),i.push(u);else if(u===19||u===20){c+=a.length>>1,h();let b=c+7>>3;i.push(u,...Array.from(s.subarray(d,d+b))),d+=b}else if(u===12){let b=s[d++]??0;if(b>=34&&b<=37)h(),i.push(12,b);else return f=!0,!0}else h(),i.push(u)}}return!1},p=m(t,0);if(!f)return p||i.push(14),Uint8Array.from(i)}function Cn(t,r,n){let i=new Set,e=!1,o=0,a=[],c=(f,h)=>{if(h>10)return e=!0,!0;let g=0;for(;g<f.length;){let m=f[g]??0;if(g++,m>=32||m===28){m===28?(a.push(((f[g]??0)<<8|(f[g+1]??0))<<16>>16),g+=2):m<=246?a.push(m-139):m<=250?a.push((m-247)*256+(f[g++]??0)+108):m<=254?a.push(-(m-251)*256-(f[g++]??0)-108):(a.push(((f[g]??0)<<24|(f[g+1]??0)<<16|(f[g+2]??0)<<8|(f[g+3]??0))/65536),g+=4);continue}if(m===10||m===29){let p=m===10?r.subrs:n.gsubrs,s=a.pop();if(s===void 0)return e=!0,!0;let l=s+Gt(p.length),d=p[l];if(d===void 0)return e=!0,!0;let u=`${m}:${l}:${o}`;if(!i.has(u)&&(i.add(u),(m===10?n.local:n.global).add(l),c(d,h+1)))return!0;continue}if(m===11)return!1;if(m===14)return!0;if(m===1||m===3||m===18||m===23){o+=a.length>>1,a.length=0;continue}if(m===19||m===20){o+=a.length>>1,a.length=0,g+=o+7>>3;continue}if(m===12){let p=f[g++]??0;if(p>=34&&p<=37)a.length=0;else return e=!0,!0;continue}a.length=0}return!1};c(t,0),e&&(r.subrs.forEach((f,h)=>{n.local.add(h)}),n.gsubrs.forEach((f,h)=>{n.global.add(h)}))}var Vt=32,Yt=1,Jt=8,Xt=64,qt=128;function Zt(t){let r=new DataView(t.buffer,t.byteOffset,t.byteLength);return String.fromCharCode(...t.subarray(0,4))==="ttcf"?r.getUint32(8):1}function bt(t,r=0){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),i=String.fromCharCode(...t.subarray(0,4))==="ttcf"?n.getUint32(12+r*4):0,e=new Map,o=n.getUint16(i+4);for(let A=0;A<o;A++){let w=i+12+A*16,W=String.fromCharCode(...t.subarray(w,w+4));e.set(W,{offset:n.getUint32(w+8),length:n.getUint32(w+12)})}let a=A=>{let w=e.get(A);if(!w)throw new Error(`font has no ${A} table`);return w},c=a("head").offset,f=n.getUint16(c+18),h=n.getInt16(c+50)===1,g=[n.getInt16(c+36),n.getInt16(c+38),n.getInt16(c+40),n.getInt16(c+42)],m=a("hhea").offset,p=n.getInt16(m+4),s=n.getInt16(m+6),l=n.getUint16(m+34),d=n.getUint16(a("maxp").offset+4),u=a("hmtx").offset,b=e.get("OS/2"),y=b&&n.getUint16(b.offset)>=2?n.getInt16(b.offset+88):Math.round(f*.714),k=Mn(n,a("cmap").offset),F=A=>n.getUint16(u+Math.min(A,l-1)*4),S=A=>A<l?n.getInt16(u+A*4+2):n.getInt16(u+l*4+(A-l)*2),U=A=>{let w=k(A);return w===void 0||w===0||w>=d?void 0:w},C=A=>{let w=a(A);return t.subarray(w.offset,w.offset+w.length)},N=e.get("CFF ");if(N){let A=Bt(t.subarray(N.offset,N.offset+N.length));return{unitsPerEm:f,ascent:p,descent:s,capHeight:y,bbox:g,outlines:"cff",variable:e.has("fvar"),cidKeyed:A.cidKeyed,glyphOf:U,codeOf:w=>A.codeOf(w),advance:F,subset:w=>({data:A.subset(w)})}}let D=a("loca").offset,v=a("glyf"),H=A=>h?[n.getUint32(D+A*4),n.getUint32(D+A*4+4)]:[n.getUint16(D+A*2)*2,n.getUint16(D+A*2+2)*2],K=A=>{let[w,W]=H(A);if(W<=w)return[];let L=v.offset+w;if(n.getInt16(L)>=0)return[];let $=[],T=L+10;for(;;){let I=n.getUint16(T);if($.push(n.getUint16(T+2)),T+=4+(I&Yt?4:2),I&Jt?T+=2:I&Xt?T+=4:I&qt&&(T+=8),!(I&Vt))break}return $};return{unitsPerEm:f,ascent:p,descent:s,capHeight:y,bbox:g,outlines:"glyf",variable:e.has("fvar"),cidKeyed:!1,glyphOf:U,codeOf:A=>A,advance:F,subset(A){let w=new Set,W=[0,...A];for(let P=W.pop();P!==void 0;P=W.pop())w.has(P)||(w.add(P),W.push(...K(P)));let L=[...w].sort((P,O)=>P-O),$=new Map(L.map((P,O)=>[P,O])),T=new Uint32Array(L.length+1),I=[],G=0;L.forEach((P,O)=>{T[O]=G;let[st,at]=H(P);if(at>st){let V=Uint8Array.from(t.subarray(v.offset+st,v.offset+at));new DataView(V.buffer).getInt16(0)<0&&Ln(V,$),I.push(V),G+=V.length;let x=(4-G%4)%4;x&&(I.push(new Uint8Array(x)),G+=x)}}),T[L.length]=G;let et=new Uint8Array(G),rt=0;for(let P of I)et.set(P,rt),rt+=P.length;let it=new Uint8Array((L.length+1)*4),ut=new DataView(it.buffer);T.forEach((P,O)=>{ut.setUint32(O*4,P)});let lt=new Uint8Array(L.length*4),z=new DataView(lt.buffer);L.forEach((P,O)=>{z.setUint16(O*4,F(P)),z.setInt16(O*4+2,S(P))});let ht=Uint8Array.from(t.subarray(c,c+a("head").length)),dt=new DataView(ht.buffer);dt.setUint32(8,0),dt.setInt16(50,1);let gt=Uint8Array.from(C("hhea"));new DataView(gt.buffer).setUint16(34,L.length);let ot=Uint8Array.from(C("maxp"));new DataView(ot.buffer).setUint16(4,L.length);let mt=new Uint16Array((L.at(-1)??0)+1);for(let[P,O]of $)mt[P]=O;return{data:In([["glyf",et],["head",ht],["hhea",gt],["hmtx",lt],["loca",it],["maxp",ot]]),cidToGid:mt}}}}function Ln(t,r){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),i=10;for(;;){let e=n.getUint16(i);if(n.setUint16(i+2,r.get(n.getUint16(i+2))??0),i+=4+(e&Yt?4:2),e&Jt?i+=2:e&Xt?i+=4:e&qt&&(i+=8),!(e&Vt))break}}function Kt(t,r){let n=0,i=t.length-1,e=-1;for(;n<=i;){let o=n+i>>1;(t[o]??0)<=r?(e=o,n=o+1):i=o-1}return e}function Mn(t,r){let n=t.getUint16(r+2),i;for(let e=0;e<n;e++){let o=t.getUint16(r+4+e*8),a=t.getUint16(r+4+e*8+2),c=r+t.getUint32(r+4+e*8+4),f=t.getUint16(c);if(o===3&&(a===1||a===10)||o===0){if(f===12){let g=t.getUint32(c+12),m=new Uint32Array(g);for(let p=0;p<g;p++)m[p]=t.getUint32(c+16+p*12);return p=>{let s=Kt(m,p);if(s<0)return;let l=t.getUint32(c+16+s*12+4);if(!(p>l))return t.getUint32(c+16+s*12+8)+(p-(m[s]??0))}}if(f===4&&i===void 0){let g=t.getUint16(c+6)/2,m=c+14,p=m+g*2+2,s=p+g*2,l=s+g*2,d=new Uint32Array(g);for(let u=0;u<g;u++)d[u]=t.getUint16(p+u*2);i=u=>{if(u>65535)return;let b=Kt(d,u);if(b<0||u>t.getUint16(m+b*2))return;let y=t.getUint16(l+b*2);if(y===0)return u+t.getInt16(s+b*2)&65535;let k=t.getUint16(l+b*2+y+(u-(d[b]??0))*2);return k===0?void 0:k+t.getInt16(s+b*2)&65535}}}}if(i)return i;throw new Error("font has no Unicode cmap")}function Dn(t){let r=new Uint8Array(Math.ceil(t.length/4)*4);r.set(t);let n=new DataView(r.buffer),i=0;for(let e=0;e<r.length;e+=4)i=i+n.getUint32(e)>>>0;return i}function In(t){let r=[...t].sort(([f],[h])=>f<h?-1:1),n=12+r.length*16,i=r.reduce((f,[,h])=>f+Math.ceil(h.length/4)*4,n),e=new Uint8Array(i),o=new DataView(e.buffer);o.setUint32(0,65536),o.setUint16(4,r.length);let a=Math.floor(Math.log2(r.length));o.setUint16(6,2**a*16),o.setUint16(8,a),o.setUint16(10,r.length*16-2**a*16);let c=n;return r.forEach(([f,h],g)=>{let m=12+g*16;e.set(new TextEncoder().encode(f),m),o.setUint32(m+4,Dn(h)),o.setUint32(m+8,c),o.setUint32(m+12,h.length),e.set(h,c),c+=Math.ceil(h.length/4)*4}),e}var xt={platform:process.platform,env:process.env,home:Wn(),exists:t=>On(t),list:t=>{try{return jn(t)}catch{return[]}},run:(t,r)=>new Promise(n=>{vn(t,r,{timeout:5e3,windowsHide:!0,maxBuffer:4e6},(i,e)=>n(i?void 0:e))}),read:t=>{try{return _n(t).size>1e8?void 0:zn(t)}catch{return}}},$n={zh:[["msyh.ttc",0],["simsun.ttc",0],["simhei.ttf",0],["Deng.ttf",0],["arialuni.ttf",0]],"zh-TW":[["msjh.ttc",0],["mingliu.ttc",0],["msyh.ttc",0],["arialuni.ttf",0]],ja:[["YuGothR.ttc",0],["YuGothM.ttc",0],["meiryo.ttc",0],["msgothic.ttc",0],["msmincho.ttc",0],["arialuni.ttf",0]],ko:[["malgun.ttf",0],["gulim.ttc",0],["batang.ttc",0],["arialuni.ttf",0]],arabic:[["segoeui.ttf",0],["arial.ttf",0],["tahoma.ttf",0],["times.ttf",0],["arialuni.ttf",0]],hebrew:[["segoeui.ttf",0],["arial.ttf",0],["tahoma.ttf",0],["times.ttf",0],["arialuni.ttf",0]],thai:[["LeelawUI.ttf",0],["leelawad.ttf",0],["tahoma.ttf",0],["arialuni.ttf",0]],other:[["seguisym.ttf",0],["segoeui.ttf",0],["arial.ttf",0],["arialuni.ttf",0],["malgun.ttf",0],["msyh.ttc",0]]},Hn={zh:[["PingFang.ttc",0],["STHeiti Light.ttc",1],["Hiragino Sans GB.ttc",0],["Arial Unicode.ttf",0]],"zh-TW":[["PingFang.ttc",2],["STHeiti Light.ttc",0],["Hiragino Sans GB.ttc",0],["Arial Unicode.ttf",0]],ja:[["\u30D2\u30E9\u30AE\u30CE\u89D2\u30B4\u30B7\u30C3\u30AF W3.ttc",0],["Hiragino Sans GB.ttc",0],["AquaKana.ttc",0],["Arial Unicode.ttf",0]],ko:[["AppleSDGothicNeo.ttc",0],["Arial Unicode.ttf",0]],arabic:[["GeezaPro.ttc",0],["SFArabic.ttf",0],["Arial Unicode.ttf",0]],hebrew:[["ArialHB.ttc",0],["Arial Unicode.ttf",0]],thai:[["Thonburi.ttc",0],["Arial Unicode.ttf",0]],other:[["Arial Unicode.ttf",0],["Apple Symbols.ttf",0],["Arial.ttf",0]]},Qt={zh:[["NotoSansCJK-Regular.ttc",2],["NotoSansCJKsc-Regular.otf",0],["wqy-zenhei.ttc",0],["wqy-microhei.ttc",0],["DroidSansFallbackFull.ttf",0],["DroidSansFallback.ttf",0]],"zh-TW":[["NotoSansCJK-Regular.ttc",3],["NotoSansCJKtc-Regular.otf",0],["wqy-zenhei.ttc",0],["DroidSansFallbackFull.ttf",0]],ja:[["NotoSansCJK-Regular.ttc",0],["NotoSansCJKjp-Regular.otf",0],["DroidSansFallbackFull.ttf",0],["TakaoGothic.ttf",0]],ko:[["NotoSansCJK-Regular.ttc",1],["NotoSansCJKkr-Regular.otf",0],["NanumGothic.ttf",0],["DroidSansFallbackFull.ttf",0]],arabic:[["NotoSansArabic-Regular.ttf",0],["NotoNaskhArabic-Regular.ttf",0],["DejaVuSans.ttf",0],["FreeSans.ttf",0]],hebrew:[["NotoSansHebrew-Regular.ttf",0],["DejaVuSans.ttf",0],["FreeSans.ttf",0]],thai:[["NotoSansThai-Regular.ttf",0],["Garuda.ttf",0],["Loma.ttf",0],["DejaVuSans.ttf",0]],other:[["DejaVuSans.ttf",0],["NotoSansSymbols-Regular.ttf",0],["NotoSansSymbols2-Regular.ttf",0],["FreeSans.ttf",0],["LiberationSans-Regular.ttf",0]]},Gn={zh:"zh-cn","zh-TW":"zh-tw",ja:"ja",ko:"ko",arabic:"ar",hebrew:"he",thai:"th"};function Bn(t){return t.script==="han"||t.script==="kana"||t.script==="hangul"?t.script==="kana"?"ja":t.script==="hangul"?"ko":t.lang??"zh":t.script==="arabic"||t.script==="hebrew"||t.script==="thai"?t.script:"other"}var Et=t=>t.platform==="win32"?en:Rt;function Kn(t){let r=en.join,n=t.env.WINDIR??t.env.SystemRoot??"C:\\Windows";return[r(n,"Fonts"),...t.env.LOCALAPPDATA?[r(t.env.LOCALAPPDATA,"Microsoft","Windows","Fonts")]:[]]}function Vn(t){let r=Rt.join;return["/System/Library/Fonts","/System/Library/Fonts/Supplemental","/Library/Fonts",r(t.home,"Library","Fonts")]}function Yn(t){let r=Rt.join,n=t.env.XDG_DATA_HOME??r(t.home,".local","share");return["/usr/share/fonts","/usr/local/share/fonts","/usr/share/fonts/opentype/noto","/usr/share/fonts/truetype",r(n,"fonts"),r(t.home,".fonts")]}function rn(t,r,n,i=3){let{join:e}=Et(n),o=n.list(t),a=r.toLowerCase(),c=o.find(f=>f.toLowerCase()===a);if(c)return e(t,c);if(i!==0)for(let f of o){if(f.includes("."))continue;let h=rn(e(t,f),r,n,i-1);if(h)return h}}async function tn(t,r){let n=await r.run("fc-match",["-s","-f",`%{file} %{index}
4
+ `,t]);return n===void 0?[]:n.split(`
5
+ `).map(i=>i.split(" ")).filter(([i])=>i!==void 0&&i!=="").slice(0,8).map(([i,e])=>({path:i,index:(Number(e)||0)&65535}))}async function on(t,r=xt){let n=Bn(t),{join:i}=Et(r),e=[],o=c=>{c&&!e.some(f=>f.path===c.path&&f.index===c.index)&&e.push(c)};if(r.platform==="win32"||r.platform==="darwin"){let c=r.platform==="win32"?$n:Hn,f=r.platform==="win32"?Kn(r):Vn(r);for(let[h,g]of c[n]??c.other??[])for(let m of f){let p=i(m,h);if(r.exists(p)){o({path:p,index:g});break}}return e}let a=Gn[n];if(a)for(let c of await tn(`:lang=${a}`,r))o(c);else if(t.codePoint!==void 0)for(let c of await tn(`:charset=${t.codePoint.toString(16)}`,r))o(c);for(let[c,f]of Qt[n]??Qt.other??[])for(let h of Yn(r)){let g=rn(h,c,r);if(g){o({path:g,index:f});break}}return e}var nn=new WeakMap;function sn(t,r=xt){let n=nn.get(r)??new Map;nn.set(r,n);let i=`${t.path}#${t.index}`,e=Et(r).basename(t.path).replace(/\.[^.]+$/,""),o=n.get(i);if(o!==void 0)return o===null?void 0:{font:o,ref:t,name:e};try{let a=r.read(t.path);if(!a)throw new Error("unreadable");let c=bt(a,Math.min(t.index,Math.max(0,Zt(a)-1)));return n.set(i,c),{font:c,ref:t,name:e}}catch{n.set(i,null);return}}var te={width:595.28,height:841.89,margin:72},Z={size:11,leading:16,after:8},ne={size:20,leading:26,before:0,after:6},ee={size:15,leading:20,before:18,after:6},re=4,ie=24,M={size:10,leading:14,padX:6,padY:3},oe=12,yt=.114,se=.78,ae=.95,an={regular:"NotoSans-Regular.ttf.gz",bold:"NotoSans-Bold.ttf.gz"};function fe(t){return[ct(t,"fonts"),ct(t,"..","fonts"),ct(t,"..","..","assets","fonts")]}var St;function ce(){if(St)return St;let t=fe(qn(Zn(import.meta.url))).find(n=>Jn(ct(n,an.regular)));if(t===void 0)throw new Error("the PDF fonts are missing from this install");let r=n=>bt(Qn(Xn(ct(t,an[n]))));return St={regular:r("regular"),bold:r("bold")},St}var nt=class{constructor(r,n,i,e,o){this.font=r;this.resource=n;this.name=i;this.synthetic=e;this.isBold=o}font;resource;name;synthetic;isBold;used=new Map;widths=new Map;advance(r){let n=this.widths.get(r);return n===void 0&&(n=this.font.advance(r)/this.font.unitsPerEm,this.widths.set(r,n)),n}code(r,n){let i=this.font.codeOf(r);return this.used.has(i)||this.used.set(i,{gid:r,text:n}),i}},Ct=class{fonts=[];picks=new Map;count=0;missing=new Set;notdef;constructor(r){let n={regular:new nt(r.regular,this.next(),"NotoSans-Regular",!1,!1),bold:new nt(r.bold,this.next(),"NotoSans-Bold",!1,!0)};this.fonts.push(n),this.notdef=n}next(){return`F${++this.count}`}get primary(){return this.notdef.regular.font}all(){return this.fonts.flatMap(r=>[r.regular,r.bold])}add(r,n){this.fonts.push({regular:new nt(n,this.next(),r,!1,!1),bold:new nt(n,this.next(),r,!0,!0)}),this.picks.clear()}get fontCount(){return this.fonts.length}has(r){return this.fonts.some(n=>n.regular.font.glyphOf(r)!==void 0)}pick(r,n){let i=this.picks.get(r);if(i===void 0){i=null;for(let o=0;o<this.fonts.length;o++){let a=this.fonts[o]?.regular.font.glyphOf(r);if(a!==void 0){i=[o,a];break}}this.picks.set(r,i)}if(i===null)return this.missing.add(Q(r)??"other"),{pf:n?this.notdef.bold:this.notdef.regular,gid:0};let e=this.fonts[i[0]];return{pf:(n?e?.bold:e?.regular)??this.notdef.regular,gid:i[1]}}width(r,n,i){let e=0;for(let o of r){let{pf:a,gid:c}=this.pick(o.codePointAt(0)??0,i);e+=a.advance(c)}return e*n}runs(r,n){let i=[];for(let e of r){let o=e.codePointAt(0)??0,{pf:a,gid:c}=this.pick(o,n),f=c===0?"\uFFFD":o>=64336&&o<=65279?Ht(o):e,h=a.code(c,f).toString(16).padStart(4,"0"),g=i.at(-1);g&&g.pf===a?(g.hex+=h,g.width+=a.advance(c)):i.push({pf:a,hex:h,width:a.advance(c)})}return i}},ue=/[\u00AD\u200B\u200E\u200F\u2028\u2029\u202A-\u202E\u2060\u2066-\u2069\uFEFF]/g,le=/[\t\u00A0\u2000-\u200A\u202F\u205F\u3000]/g,he=/[^\P{Cc}\n]/gu;function cn(t){return t.replace(le," ").replace(ue,"").replace(he,"").normalize("NFC")}function de(t,r){let n=cn(t);Wt(n)&&(n=$t(n,r)),n=n.replace(/[\u200C\u200D]/g,"");let i=[];for(let e of n){let o=e.codePointAt(0)??0;if(e===`
6
+ `||r(o)){i.push(e);continue}let a=e.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"");i.push(a!==""&&[...a].every(c=>r(c.codePointAt(0)??0))?a:e)}return i.join("")}var ge=new Set(["han","kana","hangul"]),me=new Set([12289,12290,65292,65294,65306,65307,65281,65311,65289,65341,65373,12309,12297,12299,12301,12303,12305,12313,12311,12319,8217,8221,8252,12540,12293,12539,8230,8229,37,12445,12446,12541,12542].map(t=>String.fromCodePoint(t))),pe=new Set([65288,65339,65371,12308,12296,12298,12300,12302,12304,12312,12310,12317,8216,8220].map(t=>String.fromCodePoint(t)));function Tt(t,r,n,i,e){let o=[],a=c=>r.width(c,i,n);for(let c of t.split(`
7
+ `)){let f="",h=0,g=a(" ");for(let m of c.split(" ").filter(Boolean)){let p=a(m),s=[...m].some(l=>ge.has(Q(l.codePointAt(0)??0)));if(p>e||s&&f!==""&&h+g+p>e){f!==""&&(h+g+a([...m][0]??"")<=e?(f+=" ",h+=g):(o.push(f),f="",h=0));for(let l of m){let d=a(l),u=[...f].at(-1),b=me.has(l)&&h+d<=e*1.15;h+d>e&&f!==""&&!b&&(u!==void 0&&pe.has(u)?(o.push([...f].slice(0,-1).join("")),f=u,h=a(u)):(o.push(f),f="",h=0)),f+=l,h+=d}}else f===""?(f=m,h=p):h+g+p<=e?(f+=` ${m}`,h+=g+p):(o.push(f),f=m,h=p)}o.push(f)}return o}var j=t=>(Math.round(t*100)/100).toString(),Lt=class{constructor(r,n){this.chain=r;this.margin=n.margin,this.pageHeight=n.height,this.textWidth=n.width-2*n.margin,this.textHeight=n.height-2*n.margin}chain;pages=[];ops=[];y=0;owed=0;margin;pageHeight;textWidth;textHeight;get remaining(){return this.textHeight-this.y}get atTop(){return this.y===0}newPage(){this.ops=[`${j(yt)} g ${j(yt)} G`],this.pages.push(this.ops),this.y=0,this.owed=0}gap(r){this.y>0&&(this.y+=Math.max(this.owed,r)),this.owed=0}bottom(r){this.owed=r}advance(r){this.y+=r}text(r,n,i,e,o,a,c){if(a==="")return;let{primary:f}=this.chain,h=(f.ascent-f.descent)*n/f.unitsPerEm,g=o+(i-h)/2+f.ascent*n/f.unitsPerEm,m=this.chain.runs(Dt(a,c),r),p=m.reduce((d,u)=>d+u.width,0)*n,s=this.margin+(c?e.left+e.width-p:e.left),l=j(this.pageHeight-this.margin-g);for(let d of m){let u=d.pf.synthetic?`2 Tr ${j(n*.035)} w `:"",b=d.pf.synthetic?" 0 Tr":"";this.ops.push(`BT /${d.pf.resource} ${j(n)} Tf ${u}${j(s)} ${l} Td <${d.hex}> Tj${b} ET`),s+=d.width*n}}rect(r,n,i,e,o){let a=`${j(this.margin+r)} ${j(this.pageHeight-this.margin-n-e)} ${j(i)} ${j(e)} re`;o==="fill"?this.ops.push(`${j(ae)} g ${a} f ${j(yt)} g`):this.ops.push(`${j(se)} G 0.5 w ${a} S ${j(yt)} G`)}lines(r,n,i,e,o,a){let c=kt(o),f=a?.indent??0,h={left:c?e.left:e.left+f,width:e.width-f};Tt(o,this.chain,r,n,h.width).forEach((g,m)=>{if(this.remaining<i&&this.newPage(),m===0&&a!==void 0){let p=this.chain.width(a.text,n,r),s=c?{left:e.left+e.width-p,width:p}:{left:h.left-p,width:p};this.text(r,n,i,s,this.y,a.text,!1)}this.text(r,n,i,h,this.y,g,c),this.advance(i)})}heading(r,n){let i=r===1?ne:ee,e=Tt(n,this.chain,!0,i.size,this.textWidth);this.gap(i.before),this.remaining<e.length*i.leading+i.after+2*Z.leading&&this.newPage(),this.lines(!0,i.size,i.leading,{left:0,width:this.textWidth},n),this.bottom(i.after)}paragraph(r){this.gap(0),this.lines(!1,Z.size,Z.leading,{left:0,width:this.textWidth},r),this.bottom(Z.after)}list(r,n){this.gap(0),n.forEach((i,e)=>{e>0&&this.advance(re);let o=r?`${e+1}. `:"\u2022 ";this.lines(!1,Z.size,Z.leading,{left:0,width:this.textWidth},i,{text:o,indent:ie})}),this.bottom(Z.after)}table(r){if(r.length===0)return;this.gap(0);let n=Math.max(...r.map(s=>s.length)),i=M.padX*2,e=Array(n).fill(0),o=Array(n).fill(0);for(let[s,l]of r.entries()){let d=s===0;for(let u=0;u<n;u++){let b=l[u]??"";e[u]=Math.max(e[u]??0,this.chain.width(b.replace(/\n/g," "),M.size,d)+i);let y=Math.max(0,...b.split(/\s+/).map(k=>Math.min(this.chain.width(k,M.size,d),M.size*3)));o[u]=Math.max(o[u]??0,y+i)}}let a=be(e,o,this.textWidth),c=a.map((s,l)=>a.slice(0,l).reduce((d,u)=>d+u,0)),f=s=>a.map((l,d)=>Tt(r[s]?.[d]??"",this.chain,s===0,M.size,l-i)),h=f(0),g=Math.max(...h.map(s=>s.length))*M.leading+2*M.padY,m=(s,l,d,u)=>{let b=u*M.leading+2*M.padY;for(let y=0;y<n;y++){let k=c[y]??0,F=a[y]??0;s===0&&this.rect(k,this.y,F,b,"fill"),this.rect(k,this.y,F,b,"stroke");let S=r[s]?.[y]??"",U=kt(S);(l[y]??[]).slice(d,d+u).forEach((C,N)=>{this.text(s===0,M.size,M.leading,{left:k+M.padX,width:F-i},this.y+M.padY+N*M.leading,C,U)})}this.advance(b)},p=s=>{this.newPage(),s>0&&g<this.textHeight/2&&m(0,h,0,Math.max(...h.map(l=>l.length)))};for(let s=0;s<r.length;s++){let l=s===0?h:f(s),d=Math.max(...l.map(b=>b.length)),u=0;for(;u<d;){let b=Math.floor((this.remaining-2*M.padY)/M.leading),y=(d-u)*M.leading+2*M.padY;if(b<1||b<d-u&&!this.atTop&&y<=this.textHeight-g){p(s);continue}let k=Math.min(d-u,b);m(s,l,u,k),u+=k,u<d&&p(s)}}this.bottom(oe)}};function be(t,r,n){let i=t.reduce((a,c)=>a+c,0);if(i<=n)return t.map(a=>a*n/i);let e=r.reduce((a,c)=>a+c,0);if(e>=n)return r.map(a=>a*n/e);let o=(n-e)/(i-e);return t.map((a,c)=>(r[c]??0)+(a-(r[c]??0))*o)}function xe(t){return t.flatMap(r=>r.flatMap(n=>n.kind==="heading"||n.kind==="paragraph"?[n.text]:n.kind==="list"?n.items:n.rows.flat()))}var fn=8;async function ye(t,r,n,i){let e=new Map;for(let c of new Set(r)){let f=c.codePointAt(0)??0;if(f<128||c===`
8
+ `||t.has(f)||f>=64336&&f<=65279)continue;let h=Q(f)??"other";if(h!=="other"&&h!=="symbols"&&h!=="emoji"&&!It.has(h)){t.missing.add(h);continue}e.set(h,[...e.get(h)??[],f])}let o=Nt(r,n),a=0;for(let[c,f]of e){let h=f,g={script:c,lang:o,codePoint:f[0]??0},m=[],p=s=>{let l=h.filter(d=>s.font.glyphOf(d)!==void 0);l.length!==0&&(t.add(s.name,s.font),a++,h=h.filter(d=>!l.includes(d)))};for(let s of await on(g,i)){if(h.length===0||a>=fn)break;let l=sn(s,i);l&&(l.font.variable?m.push(l):p(l))}for(let s of m){if(h.length===0||a>=fn)break;p(s)}}}function Ve(t){return{code:"missing-glyphs",message:`Some characters have no font: ${t.join(", ")}.`}}async function Ye(t,r){let{PDFDocument:n,PDFName:i,PDFString:e}=await Mt(),o=new Ct(ce()),a=xe(t).map(cn).join(`
9
+ `);await ye(o,a,r.lang,r.fonts??xt);let c=r.paper??te,f=new Lt(o,c),h=u=>de(u,b=>o.has(b)),g=u=>{u.kind==="heading"?f.heading(u.level,h(u.text)):u.kind==="paragraph"?f.paragraph(h(u.text)):u.kind==="list"?f.list(u.ordered,u.items.map(h)):f.table(u.rows.map(b=>b.map(h)))};for(let u of t.filter(b=>b.length>0)){f.newPage();for(let b of u)g(b)}f.pages.length===0&&f.newPage();let m=await n.create({updateMetadata:!1});m.setTitle(r.title),m.setProducer("Forge"),m.setCreator("Forge");let{context:p}=m,s=new Map,l=new Map,d=0;for(let u of o.all()){if(u.used.size===0)continue;let b=p.nextRef();s.set(u,b);let{font:y}=u,k=[...u.used.keys()].sort((T,I)=>T-I),F=k.map(T=>u.used.get(T)?.gid??0),S=u.synthetic?l.get(y):void 0,U=1e3/y.unitsPerEm,C=`F${String.fromCharCode(65+(d>>8)%26,65+(d>>4)%26,65+(d>>2)%26,65+d%26,65+d*7%26)}`;d++;let N=`${C}+${u.name.replace(/[^A-Za-z0-9-]/g,"")}`,{data:D,cidToGid:v}=y.subset(F),H=y.outlines==="cff",K=p.register(H?p.flateStream(D,{Subtype:"CIDFontType0C"}):p.flateStream(D,{Length1:D.length})),A=p.register(p.obj({Type:"FontDescriptor",FontName:N,Flags:4,FontBBox:y.bbox.map(T=>Math.round(T*U)),ItalicAngle:0,Ascent:Math.round(y.ascent*U),Descent:Math.round(y.descent*U),CapHeight:Math.round(y.capHeight*U),StemV:u.isBold?140:80,...H?{FontFile3:K}:{FontFile2:K}})),w=k.flatMap((T,I)=>[T,[Math.round(y.advance(F[I]??0)*U)]]),W=v?p.register(p.flateStream(new Uint8Array(new Uint16Array(Ae(v)).buffer))):void 0,L=p.register(p.obj({Type:"Font",Subtype:H?"CIDFontType0":"CIDFontType2",BaseFont:N,CIDSystemInfo:p.obj({Registry:e.of("Adobe"),Ordering:e.of("Identity"),Supplement:0}),FontDescriptor:A,DW:0,W:w,...H?{}:{CIDToGIDMap:W??"Identity"}})),$=p.register(p.flateStream(we(u.used)));p.assign(b,p.obj({Type:"Font",Subtype:"Type0",BaseFont:N,Encoding:"Identity-H",DescendantFonts:[L],ToUnicode:$})),u.synthetic||l.set(y,u)}for(let u of f.pages){let b=m.addPage([c.width,c.height]);for(let[y,k]of s)b.node.setFontDictionary(i.of(y.resource),k);b.node.set(i.of("Contents"),p.register(p.flateStream(u.join(`
10
+ `))))}return o.missing.size>0&&r.onMissing?.([...o.missing].map(Se)),Buffer.from(await m.save())}var Se=t=>t==="other"?"symbols":vt(t);function Ae(t){let r=new Uint16Array(t.length);for(let n=0;n<t.length;n++)r[n]=((t[n]??0)&255)<<8|(t[n]??0)>>8;return r}function we(t){let r=[...t].sort(([o],[a])=>o-a),n=o=>o.toString(16).padStart(4,"0"),i=o=>[...o].flatMap(a=>{let c=a.codePointAt(0)??65533;if(c<65536)return[n(c)];let f=c-65536;return[n(55296+(f>>10)),n(56320+(f&1023))]}).join(""),e=[];for(let o=0;o<r.length;o+=100){let a=r.slice(o,o+100);e.push(`${a.length} beginbfchar
11
+ ${a.map(([c,f])=>`<${n(c)}> <${i(f.text)}>`).join(`
12
+ `)}
13
+ endbfchar`)}return["/CIDInit /ProcessSet findresource begin","12 dict begin","begincmap","/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def","/CMapName /Adobe-Identity-UCS def","/CMapType 2 def",`1 begincodespacerange
14
+ <0000> <FFFF>
15
+ endcodespacerange`,...e,"endcmap","CMapName currentdict /CMap defineresource pop","end","end"].join(`
16
+ `)}export{kt as a,ke as b,Ve as c,Ye as d};