forge-terminal 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +38 -7
  2. package/dist/chunks/{about-credits-XL2AIGQ7.js → about-credits-PWTKZG3Y.js} +1 -1
  3. package/dist/chunks/args-RHIBM3R3.js +3 -0
  4. package/dist/chunks/{available-TNMISSBA.js → available-FPBRQ3LS.js} +1 -1
  5. package/dist/chunks/{boot-QRKC4QBA.js → boot-PHDTJAFT.js} +1 -1
  6. package/dist/chunks/{catalog-FMHWWMUX.js → catalog-G44MXIAF.js} +1 -1
  7. package/dist/chunks/{check-HOITNMJX.js → check-BFHBPCGW.js} +1 -1
  8. package/dist/chunks/{chunk-EIPMQFIF.js → chunk-2YU4EI24.js} +1 -1
  9. package/dist/chunks/chunk-3IAJTXYM.js +3 -0
  10. package/dist/chunks/{chunk-ECA4PW5T.js → chunk-3OCPO5V6.js} +1 -1
  11. package/dist/chunks/chunk-42IEPG2K.js +3 -0
  12. package/dist/chunks/{chunk-BYUOU2Q2.js → chunk-4AL5QJLM.js} +1 -1
  13. package/dist/chunks/{chunk-UUTBDIFR.js → chunk-56B3VZCM.js} +1 -1
  14. package/dist/chunks/{chunk-QIMSNTKL.js → chunk-56QHX7QR.js} +1 -1
  15. package/dist/chunks/{chunk-HXKLYK3M.js → chunk-6NCN7OJ5.js} +1 -1
  16. package/dist/chunks/{chunk-YBA6DJQ4.js → chunk-6PUV4HSU.js} +1 -1
  17. package/dist/chunks/{chunk-2OSM4W4D.js → chunk-72UR37EG.js} +1 -1
  18. package/dist/chunks/{chunk-3IX3QA76.js → chunk-7NP76V4U.js} +1 -1
  19. package/dist/chunks/{chunk-5FJT4BNY.js → chunk-AETM2PCZ.js} +1 -1
  20. package/dist/chunks/{chunk-GIG4I2IC.js → chunk-BQV3DSUZ.js} +2 -2
  21. package/dist/chunks/chunk-DC2DHMXO.js +3 -0
  22. package/dist/chunks/{chunk-6HUYBVQA.js → chunk-DKHBJ52G.js} +1 -1
  23. package/dist/chunks/chunk-E5VPEBUQ.js +3 -0
  24. package/dist/chunks/chunk-F4TUCI6D.js +3 -0
  25. package/dist/chunks/{chunk-MF3KKEFB.js → chunk-FEJSM3E4.js} +1 -1
  26. package/dist/chunks/{chunk-JUA63KQK.js → chunk-G2V33TMN.js} +1 -1
  27. package/dist/chunks/{chunk-FXA45V4B.js → chunk-G4M2XYFJ.js} +1 -1
  28. package/dist/chunks/{chunk-WID72ZII.js → chunk-H332YFSO.js} +1 -1
  29. package/dist/chunks/chunk-HAOKWLD3.js +4 -0
  30. package/dist/chunks/{chunk-S7BZPV5T.js → chunk-I3C3SRF2.js} +1 -1
  31. package/dist/chunks/{chunk-NUTTDNTG.js → chunk-ID4GJZJ6.js} +1 -1
  32. package/dist/chunks/{chunk-X4QI2EYV.js → chunk-ID75X37Z.js} +1 -1
  33. package/dist/chunks/{chunk-FWVE3GNA.js → chunk-JPASVE56.js} +1 -1
  34. package/dist/chunks/{chunk-UN5DSJE2.js → chunk-JZM37DG2.js} +1 -1
  35. package/dist/chunks/{chunk-G6L5NIJ5.js → chunk-KPUKMAYK.js} +1 -1
  36. package/dist/chunks/{chunk-UEAZTRTL.js → chunk-M7HB4L6L.js} +1 -1
  37. package/dist/chunks/{chunk-NLM2SP3F.js → chunk-OK56WDPA.js} +1 -1
  38. package/dist/chunks/{chunk-I25E2XDH.js → chunk-OLKPV4WO.js} +1 -1
  39. package/dist/chunks/chunk-OPDC577C.js +3 -0
  40. package/dist/chunks/chunk-OQ6DTE56.js +3 -0
  41. package/dist/chunks/chunk-PNPAHKJR.js +3 -0
  42. package/dist/chunks/{chunk-3HG7RXC2.js → chunk-PXCEMDOY.js} +2 -2
  43. package/dist/chunks/{chunk-YJZEHJ6U.js → chunk-QMNERJL2.js} +1 -1
  44. package/dist/chunks/{chunk-TNIPRV6K.js → chunk-R6QVLPGC.js} +1 -1
  45. package/dist/chunks/{chunk-65Y7YCZZ.js → chunk-S44LAUHZ.js} +1 -1
  46. package/dist/chunks/{chunk-YYZYZWF5.js → chunk-SCJ2QXZF.js} +22 -22
  47. package/dist/chunks/{chunk-QO4JUY6B.js → chunk-SJIDFYPT.js} +1 -1
  48. package/dist/chunks/{chunk-PISCJKIG.js → chunk-TQEGSODD.js} +1 -1
  49. package/dist/chunks/chunk-ULX4ZD2Y.js +3 -0
  50. package/dist/chunks/{chunk-BWJNZT75.js → chunk-W6QOV4RP.js} +1 -1
  51. package/dist/chunks/chunk-WWWWXOM4.js +3 -0
  52. package/dist/chunks/{chunk-2JU3YZQU.js → chunk-XIR3VWQY.js} +1 -1
  53. package/dist/chunks/chunk-XUJLUOGD.js +6 -0
  54. package/dist/chunks/chunk-Y3DMALHT.js +66 -0
  55. package/dist/chunks/chunk-YXV3PYVI.js +3 -0
  56. package/dist/chunks/{chunk-QPUKPSPZ.js → chunk-Z3PQ5TMU.js} +1 -1
  57. package/dist/chunks/chunk-ZL7E7PZN.js +4 -0
  58. package/dist/chunks/clip-command-6Q7BTXR5.js +3 -0
  59. package/dist/chunks/{clipboard-W67Q22JG.js → clipboard-QWNPA3GM.js} +1 -1
  60. package/dist/chunks/colour-7HPH6KTY.js +3 -0
  61. package/dist/chunks/{command-ZX3L5VFO.js → command-JTK4IOS7.js} +1 -1
  62. package/dist/chunks/{config-command-VEGQPXVB.js → config-command-DIQTU7DM.js} +1 -1
  63. package/dist/chunks/{continue-editing-LTMIEFRD.js → continue-editing-FTUY6UFG.js} +1 -1
  64. package/dist/chunks/{decoded-SK6W44WW.js → decoded-IXLPWTGZ.js} +1 -1
  65. package/dist/chunks/{entry-3R2GK3IW.js → entry-ZF7D32ZI.js} +2 -2
  66. package/dist/chunks/execute-RP7ZMWLZ.js +3 -0
  67. package/dist/chunks/extensions-YOZ4IF4E.js +3 -0
  68. package/dist/chunks/{extensions-command-RNAPQYWV.js → extensions-command-O7UHUJ3Y.js} +1 -1
  69. package/dist/chunks/{ffmpeg-G4TRWUTV.js → ffmpeg-2ZP3GXJX.js} +1 -1
  70. package/dist/chunks/{image-67XO45NW.js → image-6A7FXKIR.js} +1 -1
  71. package/dist/chunks/{install-X7EEH5CQ.js → install-4L7JGP3X.js} +1 -1
  72. package/dist/chunks/{install-UN3YGSJW.js → install-XJAPLIH2.js} +1 -1
  73. package/dist/chunks/launch-2KSJ4GGN.js +18 -0
  74. package/dist/chunks/link-inputs-GTEW6ZH4.js +3 -0
  75. package/dist/chunks/{lock-5ZO5PCZP.js → lock-KNR7XS7Q.js} +1 -1
  76. package/dist/chunks/manager-YH5XAMZA.js +4 -0
  77. package/dist/chunks/{needed-7IUPDEJB.js → needed-TB3OC76N.js} +1 -1
  78. package/dist/chunks/{own-5BD5BVE7.js → own-KUGTZ3BV.js} +1 -1
  79. package/dist/chunks/{paths-6OENILJ4.js → paths-BBUKTDDP.js} +1 -1
  80. package/dist/chunks/pdfium-MJ65YOXW.js +3 -0
  81. package/dist/chunks/{preferences-E2CH2YSG.js → preferences-7S7YZOFK.js} +1 -1
  82. package/dist/chunks/preset-command-KMKR6KMG.js +3 -0
  83. package/dist/chunks/registry-657JRJR5.js +3 -0
  84. package/dist/chunks/{run-3DX3SROY.js → run-VJDF5WRF.js} +1 -1
  85. package/dist/chunks/{server-TF32DQEO.js → server-6PH2DSFW.js} +20 -20
  86. package/dist/chunks/{signals-QSXY3F2A.js → signals-VY2XE3LV.js} +1 -1
  87. package/dist/chunks/{theme-4Y66DDAO.js → theme-FVQOSLPB.js} +1 -1
  88. package/dist/chunks/{transcribe-HH5P3PV4.js → transcribe-FUN2SKRN.js} +1 -1
  89. package/dist/chunks/transcribe-command-KNSUHROE.js +3 -0
  90. package/dist/chunks/{update-command-6VVDG75Y.js → update-command-X4OSYETA.js} +1 -1
  91. package/dist/chunks/{update-note-XV2T2NNG.js → update-note-LV7G4CHE.js} +1 -1
  92. package/dist/chunks/video-link-CF7GUA6V.js +3 -0
  93. package/dist/chunks/watch-command-3C4AWM7A.js +3 -0
  94. package/dist/index.js +7 -7
  95. package/package.json +9 -13
  96. package/skills/forge/SKILL.md +7 -3
  97. package/dist/chunks/args-PS5SVBZY.js +0 -3
  98. package/dist/chunks/chunk-2L66A2X6.js +0 -3
  99. package/dist/chunks/chunk-3SVHRKQH.js +0 -6
  100. package/dist/chunks/chunk-4MZV4SRU.js +0 -4
  101. package/dist/chunks/chunk-4NDZTK22.js +0 -3
  102. package/dist/chunks/chunk-5XJCMMCM.js +0 -3
  103. package/dist/chunks/chunk-CCNRNCRU.js +0 -3
  104. package/dist/chunks/chunk-EEQSUBBL.js +0 -3
  105. package/dist/chunks/chunk-EJWTYDBJ.js +0 -3
  106. package/dist/chunks/chunk-JD3RB6IV.js +0 -66
  107. package/dist/chunks/chunk-NMGQGYVM.js +0 -3
  108. package/dist/chunks/chunk-SFN3LBB6.js +0 -3
  109. package/dist/chunks/chunk-UI4EUC3S.js +0 -3
  110. package/dist/chunks/chunk-X2YUHPOU.js +0 -4
  111. package/dist/chunks/clip-command-4ON3Q57W.js +0 -3
  112. package/dist/chunks/colour-2BGK2BFR.js +0 -3
  113. package/dist/chunks/execute-TC3QZ6GL.js +0 -3
  114. package/dist/chunks/extensions-3SG2LW7R.js +0 -3
  115. package/dist/chunks/launch-EGFNGHLN.js +0 -18
  116. package/dist/chunks/manager-272REVNF.js +0 -4
  117. package/dist/chunks/pdfium-MHPBLZY5.js +0 -3
  118. package/dist/chunks/preset-command-5I3NZ2OP.js +0 -3
  119. package/dist/chunks/registry-DWFV4GBG.js +0 -3
  120. package/dist/chunks/transcribe-command-VY5HYNXV.js +0 -3
  121. package/dist/chunks/watch-command-BMSMGIHK.js +0 -3
@@ -1,35 +1,35 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{b as L}from"./chunk-QPUKPSPZ.js";import{a as se,b as ae}from"./chunk-HZDYZ5RD.js";import{j as ee,k as te}from"./chunk-EYOO35US.js";import{a as j}from"./chunk-WID72ZII.js";import{b as re}from"./chunk-EEQSUBBL.js";import{a as z}from"./chunk-2OSM4W4D.js";import{a as ie}from"./chunk-FWVE3GNA.js";import{m as ne}from"./chunk-QO4JUY6B.js";import{a as oe}from"./chunk-UN5DSJE2.js";import{d as F}from"./chunk-4MZV4SRU.js";import{a as Z}from"./chunk-NUCGWLOY.js";import{P as h,Q as v,R as Q,W as P,b as Y,c as K}from"./chunk-CCNRNCRU.js";import{e as X}from"./chunk-FGR6QCG5.js";import{extname as Oe}from"node:path";var x=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},A=class extends x{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var I=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function W(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as xe}from"node:events";import U from"node:child_process";import C from"node:path";import q from"node:fs";import m from"node:process";import{stripVTControlCharacters as ye}from"node:util";import{stripVTControlCharacters as be}from"node:util";var H=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,o)=>i.name().localeCompare(o.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),o=n.long&&e._findOption(n.long);!i&&!o?t.push(n):n.long&&!o?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(o=>!o.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>W(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[])}),t.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[]),i.get(r).push(o)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function o(c,p){return t.formatItem(c,n,p,t)}let r=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(r=r.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let d=t.visibleArguments(e).map(c=>o(t.styleArgumentTerm(t.argumentTerm(c)),t.styleArgumentDescription(t.argumentDescription(c))));if(r=r.concat(this.formatItemList("Arguments:",d,t)),this.groupItems(e.options,t.visibleOptions(e),c=>c.helpGroupHeading??"Options:").forEach((c,p)=>{let y=c.map(O=>o(t.styleOptionTerm(t.optionTerm(O)),t.styleOptionDescription(t.optionDescription(O))));r=r.concat(this.formatItemList(p,y,t))}),t.showGlobalOptions){let c=t.visibleGlobalOptions(e).map(p=>o(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));r=r.concat(this.formatItemList("Global Options:",c,t))}return this.groupItems(e.commands,t.visibleCommands(e),c=>c.helpGroup()||"Commands:").forEach((c,p)=>{let y=c.map(O=>o(t.styleSubcommandTerm(t.subcommandTerm(O)),t.styleSubcommandDescription(t.subcommandDescription(O))));r=r.concat(this.formatItemList(p,y,t))}),r.join(`
4
- `)}displayWidth(e){return be(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let r=" ".repeat(2);if(!n)return r+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),d=2,a=(this.helpWidth??80)-t-d-2,c;return a<this.minWidthToWrap||i.preformatted(n)?c=n:c=i.boxWrap(n,a).replace(/\n/g,`
3
+ import{j as ie,k as oe}from"./chunk-EYOO35US.js";import{a as z}from"./chunk-72UR37EG.js";import{b as R}from"./chunk-Z3PQ5TMU.js";import{b as ue}from"./chunk-ULX4ZD2Y.js";import{a as de,b as ce}from"./chunk-HZDYZ5RD.js";import{a as j}from"./chunk-H332YFSO.js";import{c as le}from"./chunk-OQ6DTE56.js";import{a as se}from"./chunk-JPASVE56.js";import{m as re}from"./chunk-SJIDFYPT.js";import{a as ae}from"./chunk-JZM37DG2.js";import{d as P}from"./chunk-ZL7E7PZN.js";import{a as ne}from"./chunk-NUCGWLOY.js";import{S as h,T as v,U as te,Z as N,a as Y,b as X,e as Q,f as Z}from"./chunk-PNPAHKJR.js";import{e as ee}from"./chunk-FGR6QCG5.js";import{extname as Ae}from"node:path";var x=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},A=class extends x{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var T=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function W(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as ke}from"node:events";import J from"node:child_process";import C from"node:path";import B from"node:fs";import g from"node:process";import{stripVTControlCharacters as ve}from"node:util";import{stripVTControlCharacters as ye}from"node:util";var H=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,o)=>i.name().localeCompare(o.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),o=n.long&&e._findOption(n.long);!i&&!o?t.push(n):n.long&&!o?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(o=>!o.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>W(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[])}),t.forEach(o=>{let r=n(o);i.has(r)||i.set(r,[]),i.get(r).push(o)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function o(c,f){return t.formatItem(c,n,f,t)}let r=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(r=r.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let d=t.visibleArguments(e).map(c=>o(t.styleArgumentTerm(t.argumentTerm(c)),t.styleArgumentDescription(t.argumentDescription(c))));if(r=r.concat(this.formatItemList("Arguments:",d,t)),this.groupItems(e.options,t.visibleOptions(e),c=>c.helpGroupHeading??"Options:").forEach((c,f)=>{let O=c.map(y=>o(t.styleOptionTerm(t.optionTerm(y)),t.styleOptionDescription(t.optionDescription(y))));r=r.concat(this.formatItemList(f,O,t))}),t.showGlobalOptions){let c=t.visibleGlobalOptions(e).map(f=>o(t.styleOptionTerm(t.optionTerm(f)),t.styleOptionDescription(t.optionDescription(f))));r=r.concat(this.formatItemList("Global Options:",c,t))}return this.groupItems(e.commands,t.visibleCommands(e),c=>c.helpGroup()||"Commands:").forEach((c,f)=>{let O=c.map(y=>o(t.styleSubcommandTerm(t.subcommandTerm(y)),t.styleSubcommandDescription(t.subcommandDescription(y))));r=r.concat(this.formatItemList(f,O,t))}),r.join(`
4
+ `)}displayWidth(e){return ye(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let r=" ".repeat(2);if(!n)return r+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),d=2,a=(this.helpWidth??80)-t-d-2,c;return a<this.minWidthToWrap||i.preformatted(n)?c=n:c=i.boxWrap(n,a).replace(/\n/g,`
5
5
  `+" ".repeat(t+d)),r+u+" ".repeat(d)+c.replace(/\n/g,`
6
- ${r}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,o=[];return n.forEach(r=>{let u=r.match(i);if(u===null){o.push("");return}let d=[u.shift()],l=this.displayWidth(d[0]);u.forEach(a=>{let c=this.displayWidth(a);if(l+c<=t){d.push(a),l+=c;return}o.push(d.join(""));let p=a.trimStart();d=[p],l=this.displayWidth(p)}),o.push(d.join(""))}),o.join(`
7
- `)}};var $=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=_e(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?ue(this.name().replace(/^no-/,"")):ue(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},D=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let i=this.negativeOptions.get(n).presetArg,o=i!==void 0?i:!1;return t.negate===(o===e)}};function ue(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function _e(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,o=s.split(/[ |,]+/).concat("guard");if(n.test(o[0])&&(e=o.shift()),i.test(o[0])&&(t=o.shift()),!e&&n.test(o[0])&&(e=o.shift()),!e&&i.test(o[0])&&(e=t,t=o.shift()),o[0].startsWith("-")){let r=o[0],u=`option creation failed due to '${r}' in option flags '${s}'`;throw/^-[^-][^-]/.test(r)?new Error(`${u}
6
+ ${r}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,o=[];return n.forEach(r=>{let u=r.match(i);if(u===null){o.push("");return}let d=[u.shift()],l=this.displayWidth(d[0]);u.forEach(a=>{let c=this.displayWidth(a);if(l+c<=t){d.push(a),l+=c;return}o.push(d.join(""));let f=a.trimStart();d=[f],l=this.displayWidth(f)}),o.push(d.join(""))}),o.join(`
7
+ `)}};var $=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=Oe(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new A(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?he(this.name().replace(/^no-/,"")):he(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},D=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let i=this.negativeOptions.get(n).presetArg,o=i!==void 0?i:!1;return t.negate===(o===e)}};function he(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function Oe(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,o=s.split(/[ |,]+/).concat("guard");if(n.test(o[0])&&(e=o.shift()),i.test(o[0])&&(t=o.shift()),!e&&n.test(o[0])&&(e=o.shift()),!e&&i.test(o[0])&&(e=t,t=o.shift()),o[0].startsWith("-")){let r=o[0],u=`option creation failed due to '${r}' in option flags '${s}'`;throw/^-[^-][^-]/.test(r)?new Error(`${u}
8
8
  - a short flag is a single dash and a single character
9
9
  - either use a single dash and a single character (for a short flag)
10
10
  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(r)?new Error(`${u}
11
11
  - too many short flags`):i.test(r)?new Error(`${u}
12
12
  - too many long flags`):new Error(`${u}
13
- - unrecognised flag format`)}if(e===void 0&&t===void 0)throw new Error(`option creation failed due to no flags found in '${s}'.`);return{shortFlag:e,longFlag:t}}function we(s,e){if(Math.abs(s.length-e.length)>3)return Math.max(s.length,e.length);let t=[];for(let n=0;n<=s.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=s.length;i++){let o;s[i-1]===e[n-1]?o=0:o=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+o),i>1&&n>1&&s[i-1]===e[n-2]&&s[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[s.length][e.length]}function R(s,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=s.startsWith("--");t&&(s=s.slice(2),e=e.map(r=>r.slice(2)));let n=[],i=3,o=.4;return e.forEach(r=>{if(r.length<=1)return;let u=we(s,r),d=Math.max(s.length,r.length);(d-u)/d>o&&(u<i?(i=u,n=[r]):u===i&&n.push(r))}),n.sort((r,u)=>r.localeCompare(u)),t&&(n=n.map(r=>`--${r}`)),n.length>1?`
13
+ - unrecognised flag format`)}if(e===void 0&&t===void 0)throw new Error(`option creation failed due to no flags found in '${s}'.`);return{shortFlag:e,longFlag:t}}function Ce(s,e){if(Math.abs(s.length-e.length)>3)return Math.max(s.length,e.length);let t=[];for(let n=0;n<=s.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=s.length;i++){let o;s[i-1]===e[n-1]?o=0:o=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+o),i>1&&n>1&&s[i-1]===e[n-2]&&s[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[s.length][e.length]}function U(s,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=s.startsWith("--");t&&(s=s.slice(2),e=e.map(r=>r.slice(2)));let n=[],i=3,o=.4;return e.forEach(r=>{if(r.length<=1)return;let u=Ce(s,r),d=Math.max(s.length,r.length);(d-u)/d>o&&(u<i?(i=u,n=[r]):u===i&&n.push(r))}),n.sort((r,u)=>r.localeCompare(u)),t&&(n=n.map(r=>`--${r}`)),n.length>1?`
14
14
  (Did you mean one of ${n.join(", ")}?)`:n.length===1?`
15
- (Did you mean ${n[0]}?)`:""}var S=class s extends xe{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>m.stdout.write(t),writeErr:t=>m.stderr.write(t),outputError:(t,n)=>n(t),getOutHelpWidth:()=>m.stdout.isTTY?m.stdout.columns:void 0,getErrHelpWidth:()=>m.stderr.isTTY?m.stderr.columns:void 0,getOutHasColors:()=>de()??(m.stdout.isTTY&&m.stdout.hasColors?.()),getErrHasColors:()=>de()??(m.stderr.isTTY&&m.stderr.hasColors?.()),stripColor:t=>ye(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,o=n;typeof i=="object"&&i!==null&&(o=i,i=null),o=o||{};let[,r,u]=e.match(/([^ ]+) *(.*)/),d=this.createCommand(r);return i&&(d.description(i),d._executableHandler=!0),o.isDefault&&(this._defaultCommandName=d._name),d._hidden=!!(o.noHelp||o.hidden),d._executableFile=o.executableFile||null,u&&d.arguments(u),this._registerCommand(d),d.parent=this,d.copyInheritedSettings(this),i?this:d}createCommand(e){return new s(e)}createHelp(){return Object.assign(new H,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
16
- - specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new I(e,t)}argument(e,t,n,i){let o=this.createArgument(e,t);return typeof n=="function"?o.default(i).argParser(n):o.default(n),this.addArgument(o),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let n=e??"help [command]",[,i,o]=n.match(/([^ ]+) *(.*)/),r=t??"display help for command",u=this.createCommand(i);return u.helpOption(!1),o&&u.arguments(o),r&&u.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=u,(e||t)&&this._initCommandGroup(u),this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
17
- Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new x(e,t,n)),m.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,o=n.slice(0,i);return this._storeOptionsAsProperties?o[i]=this:o[i]=this.opts(),o.push(this),e.apply(this,o)};return this._actionHandler=t,this}createOption(e,t){return new $(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(o){if(o.code==="commander.invalidArgument"){let r=`${i} ${o.message}`;this.error(r,{exitCode:o.exitCode,code:o.code})}throw o}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
18
- - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=i=>[i.name()].concat(i.aliases()),n=t(e).find(i=>this._findCommand(i));if(n){let i=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");let i=(o,r,u)=>{o==null&&e.presetArg!==void 0&&(o=e.presetArg);let d=this.getOptionValue(n);o!==null&&e.parseArg?o=this._callParseArg(e,o,d,r):o!==null&&e.variadic&&(o=e._collectValue(o,d)),o==null&&(e.negate?o=!1:e.isBoolean()||e.optional?o=!0:o=""),this.setOptionValueWithSource(n,o,u)};return this.on("option:"+t,o=>{let r=`error: option '${e.flags}' argument '${o}' is invalid.`;i(o,r,"cli")}),e.envVar&&this.on("optionEnv:"+t,o=>{let r=`error: option '${e.flags}' value '${o}' from env '${e.envVar}' is invalid.`;i(o,r,"env")}),this}_optionEx(e,t,n,i,o){if(typeof t=="object"&&t instanceof $)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let r=this.createOption(t,n);if(r.makeOptionMandatory(!!e.mandatory),typeof i=="function")r.default(o).argParser(i);else if(i instanceof RegExp){let u=i;i=(d,l)=>{let a=u.exec(d);return a?a[0]:l},r.default(o).argParser(i)}else r.default(i);return this.addOption(r)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){m.versions?.electron&&(t.from="electron");let i=m.execArgv??[];(i.includes("-e")||i.includes("--eval")||i.includes("-p")||i.includes("--print"))&&(t.from="eval")}e===void 0&&(e=m.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":m.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;case"eval":n=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,"--");this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,"default")}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
19
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(q.existsSync(e))return;let i=t?`searched for local subcommand relative to directory '${t}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",o=`'${e}' does not exist
15
+ (Did you mean ${n[0]}?)`:""}var E=class s extends ke{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>g.stdout.write(t),writeErr:t=>g.stderr.write(t),outputError:(t,n)=>n(t),getOutHelpWidth:()=>g.stdout.isTTY?g.stdout.columns:void 0,getErrHelpWidth:()=>g.stderr.isTTY?g.stderr.columns:void 0,getOutHasColors:()=>pe()??(g.stdout.isTTY&&g.stdout.hasColors?.()),getErrHasColors:()=>pe()??(g.stderr.isTTY&&g.stderr.hasColors?.()),stripColor:t=>ve(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,o=n;typeof i=="object"&&i!==null&&(o=i,i=null),o=o||{};let[,r,u]=e.match(/([^ ]+) *(.*)/),d=this.createCommand(r);return i&&(d.description(i),d._executableHandler=!0),o.isDefault&&(this._defaultCommandName=d._name),d._hidden=!!(o.noHelp||o.hidden),d._executableFile=o.executableFile||null,u&&d.arguments(u),this._registerCommand(d),d.parent=this,d.copyInheritedSettings(this),i?this:d}createCommand(e){return new s(e)}createHelp(){return Object.assign(new H,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
16
+ - specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new T(e,t)}argument(e,t,n,i){let o=this.createArgument(e,t);return typeof n=="function"?o.default(i).argParser(n):o.default(n),this.addArgument(o),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let n=e??"help [command]",[,i,o]=n.match(/([^ ]+) *(.*)/),r=t??"display help for command",u=this.createCommand(i);return u.helpOption(!1),o&&u.arguments(o),r&&u.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=u,(e||t)&&this._initCommandGroup(u),this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
17
+ Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new x(e,t,n)),g.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,o=n.slice(0,i);return this._storeOptionsAsProperties?o[i]=this:o[i]=this.opts(),o.push(this),e.apply(this,o)};return this._actionHandler=t,this}createOption(e,t){return new $(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(o){if(o.code==="commander.invalidArgument"){let r=`${i} ${o.message}`;this.error(r,{exitCode:o.exitCode,code:o.code})}throw o}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
18
+ - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=i=>[i.name()].concat(i.aliases()),n=t(e).find(i=>this._findCommand(i));if(n){let i=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");let i=(o,r,u)=>{o==null&&e.presetArg!==void 0&&(o=e.presetArg);let d=this.getOptionValue(n);o!==null&&e.parseArg?o=this._callParseArg(e,o,d,r):o!==null&&e.variadic&&(o=e._collectValue(o,d)),o==null&&(e.negate?o=!1:e.isBoolean()||e.optional?o=!0:o=""),this.setOptionValueWithSource(n,o,u)};return this.on("option:"+t,o=>{let r=`error: option '${e.flags}' argument '${o}' is invalid.`;i(o,r,"cli")}),e.envVar&&this.on("optionEnv:"+t,o=>{let r=`error: option '${e.flags}' value '${o}' from env '${e.envVar}' is invalid.`;i(o,r,"env")}),this}_optionEx(e,t,n,i,o){if(typeof t=="object"&&t instanceof $)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let r=this.createOption(t,n);if(r.makeOptionMandatory(!!e.mandatory),typeof i=="function")r.default(o).argParser(i);else if(i instanceof RegExp){let u=i;i=(d,l)=>{let a=u.exec(d);return a?a[0]:l},r.default(o).argParser(i)}else r.default(i);return this.addOption(r)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){g.versions?.electron&&(t.from="electron");let i=g.execArgv??[];(i.includes("-e")||i.includes("--eval")||i.includes("-p")||i.includes("--print"))&&(t.from="eval")}e===void 0&&(e=g.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":g.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;case"eval":n=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,"--");this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,"default")}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
19
+ - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(B.existsSync(e))return;let i=t?`searched for local subcommand relative to directory '${t}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",o=`'${e}' does not exist
20
20
  - if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
21
21
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
22
- - ${i}`;throw new Error(o)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(a,c){let p=C.resolve(a,c);if(q.existsSync(p))return p;if(n.includes(C.extname(c)))return;let y=n.find(O=>q.existsSync(`${p}${O}`));if(y)return`${p}${y}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=e._executableFile||`${this._name}-${e._name}`,r=this._executableDir||"";if(this._scriptPath){let a;try{a=q.realpathSync(this._scriptPath)}catch{a=this._scriptPath}r=C.resolve(C.dirname(a),r)}if(r){let a=i(r,o);if(!a&&!e._executableFile&&this._scriptPath){let c=C.basename(this._scriptPath,C.extname(this._scriptPath));c!==this._name&&(a=i(r,`${c}-${e._name}`))}o=a||o}let u=n.includes(C.extname(o)),d;m.platform!=="win32"?u?(t.unshift(o),t=le(m.execArgv).concat(t),d=U.spawn(m.argv[0],t,{stdio:"inherit"})):d=U.spawn(o,t,{stdio:"inherit"}):(this._checkForMissingExecutable(o,r,e._name),t.unshift(o),t=le(m.execArgv).concat(t),d=U.spawn(m.execPath,t,{stdio:"inherit"})),d.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{m.on(c,()=>{d.killed===!1&&d.exitCode===null&&d.kill(c)})});let l=this._exitCallback;d.on("close",a=>{a=a??1,l?l(new x(a,"commander.executeSubCommandAsync","(close)")):m.exit(a)}),d.on("error",a=>{if(a.code==="ENOENT")this._checkForMissingExecutable(o,r,e._name);else if(a.code==="EACCES")throw new Error(`'${o}' not executable`);if(!l)m.exit(1);else{let c=new x(1,"commander.executeSubCommandAsync","(error)");c.nestedError=a,l(c)}}),this.runningCommand=d}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let o;return o=this._chainOrCallSubCommandHook(o,i,"preSubcommand"),o=this._chainOrCall(o,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),o}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(n,i,o)=>{let r=i;if(i!==null&&n.parseArg){let u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;r=this._callParseArg(n,i,o,u)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let o=n.defaultValue;n.variadic?i<this.args.length?(o=this.args.slice(i),n.parseArg&&(o=o.reduce((r,u)=>e(n,u,r),n.defaultValue))):o===void 0&&(o=[]):i<this.args.length&&(o=this.args[i],n.parseArg&&(o=e(n,o,n.defaultValue))),t[i]=o}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,i=[];return this._getCommandAndAncestors().reverse().filter(o=>o._lifeCycleHooks[t]!==void 0).forEach(o=>{o._lifeCycleHooks[t].forEach(r=>{i.push({hookedCommand:o,callback:r})})}),t==="postAction"&&i.reverse(),i.forEach(o=>{n=this._chainOrCall(n,()=>o.callback(o.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(o=>{i=this._chainOrCall(i,()=>o(this,t))}),i}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},o=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let r;return r=this._chainOrCallHooks(r,"preAction"),r=this._chainOrCall(r,()=>this._actionHandler(this.processedArgs)),this.parent&&(r=this._chainOrCall(r,()=>{this.parent.emit(o,e,t)})),r=this._chainOrCallHooks(r,"postAction"),r}if(this.parent?.listenerCount(o))i(),this._processArguments(),this.parent.emit(o,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(n=>{let i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{let i=e.find(o=>n.conflictsWith.includes(o.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function o(a){return a.length>1&&a[0]==="-"}let r=a=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(a)?!this._getCommandAndAncestors().some(c=>c.options.map(p=>p.short).some(p=>/^-\d$/.test(p))):!1,u=null,d=null,l=0;for(;l<e.length||d;){let a=d??e[l++];if(d=null,a==="--"){i===n&&i.push(a),i.push(...e.slice(l));break}if(u&&(!o(a)||r(a))){this.emit(`option:${u.name()}`,a);continue}if(u=null,o(a)){let c=this._findOption(a);if(c){if(c.required){let p=e[l++];p===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,p)}else if(c.optional){let p=null;l<e.length&&(!o(e[l])||r(e[l]))&&(p=e[l++]),this.emit(`option:${c.name()}`,p)}else this.emit(`option:${c.name()}`);u=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),d=`-${a.slice(2)}`);continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),p=this._findOption(a.slice(0,c));if(p&&(p.required||p.optional)){this.emit(`option:${p.name()}`,a.slice(c+1));continue}}if(i===t&&o(a)&&!(this.commands.length===0&&r(a))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(a)){t.push(a),n.push(...e.slice(l));break}else if(this._getHelpCommand()&&a===this._getHelpCommand().name()){t.push(a,...e.slice(l));break}else if(this._defaultCommandName){n.push(a,...e.slice(l));break}}if(this._passThroughOptions){i.push(a,...e.slice(l));break}i.push(a)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
22
+ - ${i}`;throw new Error(o)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(a,c){let f=C.resolve(a,c);if(B.existsSync(f))return f;if(n.includes(C.extname(c)))return;let O=n.find(y=>B.existsSync(`${f}${y}`));if(O)return`${f}${O}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=e._executableFile||`${this._name}-${e._name}`,r=this._executableDir||"";if(this._scriptPath){let a;try{a=B.realpathSync(this._scriptPath)}catch{a=this._scriptPath}r=C.resolve(C.dirname(a),r)}if(r){let a=i(r,o);if(!a&&!e._executableFile&&this._scriptPath){let c=C.basename(this._scriptPath,C.extname(this._scriptPath));c!==this._name&&(a=i(r,`${c}-${e._name}`))}o=a||o}let u=n.includes(C.extname(o)),d;g.platform!=="win32"?u?(t.unshift(o),t=fe(g.execArgv).concat(t),d=J.spawn(g.argv[0],t,{stdio:"inherit"})):d=J.spawn(o,t,{stdio:"inherit"}):(this._checkForMissingExecutable(o,r,e._name),t.unshift(o),t=fe(g.execArgv).concat(t),d=J.spawn(g.execPath,t,{stdio:"inherit"})),d.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{g.on(c,()=>{d.killed===!1&&d.exitCode===null&&d.kill(c)})});let l=this._exitCallback;d.on("close",a=>{a=a??1,l?l(new x(a,"commander.executeSubCommandAsync","(close)")):g.exit(a)}),d.on("error",a=>{if(a.code==="ENOENT")this._checkForMissingExecutable(o,r,e._name);else if(a.code==="EACCES")throw new Error(`'${o}' not executable`);if(!l)g.exit(1);else{let c=new x(1,"commander.executeSubCommandAsync","(error)");c.nestedError=a,l(c)}}),this.runningCommand=d}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let o;return o=this._chainOrCallSubCommandHook(o,i,"preSubcommand"),o=this._chainOrCall(o,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),o}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(n,i,o)=>{let r=i;if(i!==null&&n.parseArg){let u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;r=this._callParseArg(n,i,o,u)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let o=n.defaultValue;n.variadic?i<this.args.length?(o=this.args.slice(i),n.parseArg&&(o=o.reduce((r,u)=>e(n,u,r),n.defaultValue))):o===void 0&&(o=[]):i<this.args.length&&(o=this.args[i],n.parseArg&&(o=e(n,o,n.defaultValue))),t[i]=o}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,i=[];return this._getCommandAndAncestors().reverse().filter(o=>o._lifeCycleHooks[t]!==void 0).forEach(o=>{o._lifeCycleHooks[t].forEach(r=>{i.push({hookedCommand:o,callback:r})})}),t==="postAction"&&i.reverse(),i.forEach(o=>{n=this._chainOrCall(n,()=>o.callback(o.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(o=>{i=this._chainOrCall(i,()=>o(this,t))}),i}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},o=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let r;return r=this._chainOrCallHooks(r,"preAction"),r=this._chainOrCall(r,()=>this._actionHandler(this.processedArgs)),this.parent&&(r=this._chainOrCall(r,()=>{this.parent.emit(o,e,t)})),r=this._chainOrCallHooks(r,"postAction"),r}if(this.parent?.listenerCount(o))i(),this._processArguments(),this.parent.emit(o,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(n=>{let i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{let i=e.find(o=>n.conflictsWith.includes(o.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function o(a){return a.length>1&&a[0]==="-"}let r=a=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(a)?!this._getCommandAndAncestors().some(c=>c.options.map(f=>f.short).some(f=>/^-\d$/.test(f))):!1,u=null,d=null,l=0;for(;l<e.length||d;){let a=d??e[l++];if(d=null,a==="--"){i===n&&i.push(a),i.push(...e.slice(l));break}if(u&&(!o(a)||r(a))){this.emit(`option:${u.name()}`,a);continue}if(u=null,o(a)){let c=this._findOption(a);if(c){if(c.required){let f=e[l++];f===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,f)}else if(c.optional){let f=null;l<e.length&&(!o(e[l])||r(e[l]))&&(f=e[l++]),this.emit(`option:${c.name()}`,f)}else this.emit(`option:${c.name()}`);u=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),d=`-${a.slice(2)}`);continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),f=this._findOption(a.slice(0,c));if(f&&(f.required||f.optional)){this.emit(`option:${f.name()}`,a.slice(c+1));continue}}if(i===t&&o(a)&&!(this.commands.length===0&&r(a))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(a)){t.push(a),n.push(...e.slice(l));break}else if(this._getHelpCommand()&&a===this._getHelpCommand().name()){t.push(a,...e.slice(l));break}else if(this._defaultCommandName){n.push(a,...e.slice(l));break}}if(this._passThroughOptions){i.push(a,...e.slice(l));break}i.push(a)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
23
23
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
24
24
  `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
25
- `),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in m.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,m.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new D(this.options),t=n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=r=>{let u=r.attributeName(),d=this.getOptionValue(u),l=this.options.find(c=>c.negate&&u===c.attributeName()),a=this.options.find(c=>!c.negate&&u===c.attributeName());return l&&(l.presetArg===void 0&&d===!1||l.presetArg!==void 0&&d===l.presetArg)?l:a||r},i=r=>{let u=n(r),d=u.attributeName();return this.getOptionValueSource(d)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},o=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],o=this;do{let r=o.createHelp().visibleOptions(o).filter(u=>u.long).map(u=>u.long);i=i.concat(r),o=o.parent}while(o&&!o._enablePositionalOptions);t=R(e,i)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",i=e.length,o=this.parent?` for '${this.name()}'`:"",r=e.join(", "),u=`error: too many arguments${o}. Expected ${t} argument${n} but got ${i}: ${r}.`;this.error(u,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(o=>{i.push(o.name()),o.alias()&&i.push(o.alias())}),t=R(e,i)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
26
- `),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(n=>W(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=C.basename(e,C.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let i=t.formatHelp(this,t);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(e){e=e||{};let t=!!e.error,n,i,o;return t?(n=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),o=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),o=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),hasColors:i,helpWidth:o}}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let n=this._getOutputContext(e),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(r=>r.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let o=this.helpInformation({error:n.error});if(t&&(o=t(o),typeof o!="string"&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(o),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(r=>r.emit("afterAllHelp",i))}helpOption(e,t){return typeof e=="boolean"?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(m.exitCode??0);t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
25
+ `),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in g.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,g.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new D(this.options),t=n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=r=>{let u=r.attributeName(),d=this.getOptionValue(u),l=this.options.find(c=>c.negate&&u===c.attributeName()),a=this.options.find(c=>!c.negate&&u===c.attributeName());return l&&(l.presetArg===void 0&&d===!1||l.presetArg!==void 0&&d===l.presetArg)?l:a||r},i=r=>{let u=n(r),d=u.attributeName();return this.getOptionValueSource(d)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},o=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],o=this;do{let r=o.createHelp().visibleOptions(o).filter(u=>u.long).map(u=>u.long);i=i.concat(r),o=o.parent}while(o&&!o._enablePositionalOptions);t=U(e,i)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",i=e.length,o=this.parent?` for '${this.name()}'`:"",r=e.join(", "),u=`error: too many arguments${o}. Expected ${t} argument${n} but got ${i}: ${r}.`;this.error(u,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(o=>{i.push(o.name()),o.alias()&&i.push(o.alias())}),t=U(e,i)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
26
+ `),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(n=>W(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=C.basename(e,C.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let i=t.formatHelp(this,t);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(e){e=e||{};let t=!!e.error,n,i,o;return t?(n=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),o=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),o=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),hasColors:i,helpWidth:o}}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let n=this._getOutputContext(e),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(r=>r.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let o=this.helpInformation({error:n.error});if(t&&(o=t(o),typeof o!="string"&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(o),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(r=>r.emit("afterAllHelp",i))}helpOption(e,t){return typeof e=="boolean"?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(g.exitCode??0);t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
27
27
  Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,o=>{let r;typeof t=="function"?r=t({error:o.error,command:o.command}):r=t,r&&o.write(`${r}
28
- `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function le(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?i=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],i=o[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function de(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return!1;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return!0}var ft=new S;function Ce(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!z.includes(t))throw h(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${z.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw h(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw h(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var ke={jpg:"jpeg",tif:"tiff",heif:"heic"};function V(s){let e=s.toLowerCase().replace(/^\./,""),t=Y(ke[e]??e);if(!t)throw h(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function G(s,e,t,n,i){let o=Number(String(e).replace(/k$/i,""));if(!Number.isFinite(o)||o<t||o>n)throw h(`${s} takes ${t} to ${n}, not ${e}.`,`For example ${s} ${i}.`);return o}function ve(s){let e={};if(s.cut!==void 0){let t=re(String(s.cut));if(!t)throw h(`--cut takes a start and an end, the end after the start, not ${s.cut}.`,"For example --cut 0:03.2-0:41, or --cut 0:10- to keep from 0:10 to the end.");e.cut=t.end===void 0?{start:t.start}:{start:t.start,end:t.end}}return s.mute&&(e.mute=!0),s.speed!==void 0&&(e.speed=G("--speed",s.speed,.25,4,"2")),s.fps!==void 0&&(e.fps=G("--fps",s.fps,1,120,"30")),s.bitrate!==void 0&&(e.bitrate=Math.round(G("--bitrate",s.bitrate,32,320,"128k"))),s.loudness!==void 0&&(e.loudness=G("--loudness",s.loudness,-70,-5,"-16")),s.cleanAudio&&(e.cleanup=!0,e.loudness??=-16),Object.keys(e).length?e:void 0}function E(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw h(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function ce(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw h(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function Ae(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=L))throw h(`--resize takes a percent from 1 to ${L}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function M(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw h(`Concurrency must be a positive whole number, not ${s}.`);return e}var $e=`
28
+ `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function fe(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?i=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],i=o[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function pe(){if(g.env.NO_COLOR||g.env.FORCE_COLOR==="0"||g.env.FORCE_COLOR==="false")return!1;if(g.env.FORCE_COLOR||g.env.CLICOLOR_FORCE!==void 0)return!0}var _t=new E;function Se(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!z.includes(t))throw h(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${z.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw h(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw h(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var $e={jpg:"jpeg",tif:"tiff",heif:"heic"};function V(s){let e=s.toLowerCase().replace(/^\./,""),t=Q($e[e]??e);if(!t)throw h(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function q(s,e,t,n,i){let o=Number(String(e).replace(/k$/i,""));if(!Number.isFinite(o)||o<t||o>n)throw h(`${s} takes ${t} to ${n}, not ${e}.`,`For example ${s} ${i}.`);return o}function Ee(s){let e={};if(s.cut!==void 0){let t=ue(String(s.cut));if(!t)throw h(`--cut takes a start and an end, the end after the start, not ${s.cut}.`,"For example --cut 0:03.2-0:41, or --cut 0:10- to keep from 0:10 to the end.");e.cut=t.end===void 0?{start:t.start}:{start:t.start,end:t.end}}return s.mute&&(e.mute=!0),s.speed!==void 0&&(e.speed=q("--speed",s.speed,.25,4,"2")),s.fps!==void 0&&(e.fps=q("--fps",s.fps,1,120,"30")),s.bitrate!==void 0&&(e.bitrate=Math.round(q("--bitrate",s.bitrate,32,320,"128k"))),s.loudness!==void 0&&(e.loudness=q("--loudness",s.loudness,-70,-5,"-16")),s.cleanAudio&&(e.cleanup=!0,e.loudness??=-16),Object.keys(e).length?e:void 0}function I(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw h(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function me(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw h(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function Ie(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=R))throw h(`--resize takes a percent from 1 to ${R}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function G(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw h(`Concurrency must be a positive whole number, not ${s}.`);return e}var Te=`
29
29
  Exit codes:
30
30
  0 every input succeeded
31
31
  1 the command was understood, and at least one input failed or was refused
32
- 2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,he=`
32
+ 2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,ge=`
33
33
  Other commands:
34
34
  forge probe <files...> what each file is and what Forge can do with it
35
35
  forge palette <image> an image's main colours (--json, --svg, --inside <hex>)
@@ -39,7 +39,7 @@ Other commands:
39
39
  forge clip compress the copied image and put it back (--to, --quality,
40
40
  --max-size, --save [folder], --undo)
41
41
  forge transcribe <file | link>
42
- a video or audio file, or a YouTube link, into notes
42
+ a video or audio file, or a video link, into notes
43
43
  (--to all | notes | transcript, --detail brief | standard | detailed,
44
44
  --format md | docx | pdf | txt, --language <id>, -o <path>, --force)
45
45
  forge watch <folder> --to <format>
@@ -52,7 +52,7 @@ Other commands:
52
52
  the right-click menu, by hand
53
53
  forge update install a newer Forge, if there is one
54
54
  forge uninstall take Forge out of the right-click menu, then remove it
55
- forge mcp run as a local MCP server over stdio, for AI agents`;function fe(s=process.platform){if(s==="darwin")return he;let e=s==="win32"?"boost and whisper":"whisper and heic";return he.replace("a video or audio file, or a YouTube link, into notes","a video or audio file, or a YouTube link, into a transcript").replace("optional extras, such as boost and remove-background",`optional extras, such as ${e}`)}function J(s){let e=X(String(s));if(e===void 0)throw h(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function Se(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw h(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw v("Pass a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function Ee(s){let e={kind:"clip",undo:!1,debug:!1},t=s.slice(1),n=(i,o)=>{let r=t[o+1];if(r===void 0||r.startsWith("-"))throw h(`${i} needs a value.`);return r};for(let i=0;i<t.length;i++){let o=t[i];if(o!=="--json")if(o==="--debug")e.debug=!0;else if(o==="--undo")e.undo=!0;else if(o==="--to"||o==="-t")e.target=V(n(o,i++));else if(o==="--quality"||o==="-q")e.quality=E(n(o,i++));else if(o==="--max-size")e.maxBytes=J(n(o,i++));else if(o==="--save"){let r=t[i+1];e.save=r===void 0||r.startsWith("-")?!0:t[++i]}else throw o.startsWith("-")?h(`forge clip does not take ${o}.`,"Try: forge --help"):h(`forge clip takes no files: it reads the clipboard, not ${o}.`,`To compress a file, try: forge ${o} --quality 80`)}if(e.undo&&Object.keys(e).some(i=>!["kind","undo","debug"].includes(i)))throw h("--undo takes no other flag.","Try: forge clip --undo");if(e.quality!==void 0&&e.maxBytes!==void 0)throw h("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");return e}function Te(s){let e=s.slice(1),t=[],n={kind:"transcribe",input:"",notes:!0,transcript:!0,detail:ae,force:!1,debug:!1},i=(d,l)=>{let a=e[l+1];if(a===void 0||a.startsWith("-"))throw h(`${d} needs a value.`);return a},o="Try: forge transcribe talk.mp4";for(let d=0;d<e.length;d++){let l=e[d];if(l==="--debug")n.debug=!0;else if(l==="--force"||l==="-f")n.force=!0;else if(l==="--language"||l==="-l")n.language=i(l,d++);else if(l==="--output"||l==="-o")n.output=F(i(l,d++));else if(l==="--detail"){let a=i(l,d++).toLowerCase();if(!se.includes(a))throw h(`forge transcribe writes notes in brief, standard or detailed, not ${a}.`,"Try: forge transcribe talk.mp4 --detail brief");n.detail=a}else if(l==="--format"){let a=i(l,d++).toLowerCase(),c=Z.find(p=>p.id===a||p.label.toLowerCase()===a);if(c===void 0)throw h(`forge transcribe writes md, docx, pdf or txt, not ${a}.`,"Try: forge transcribe talk.mp4 --format pdf");n.format=c.id}else if(l==="--to"||l==="-t"){let a=i(l,d++).toLowerCase();if(a!=="all"&&a!=="notes"&&a!=="transcript")throw h(`forge transcribe makes all, notes or a transcript, not ${a}.`,"Try: forge transcribe talk.mp4 --to transcript");n.to=a,n.notes=a!=="transcript",n.transcript=a!=="notes"}else{if(l.startsWith("-"))throw h(`forge transcribe does not take ${l}.`,o);t.push(l)}}let[r,...u]=t;if(r===void 0)throw h("forge transcribe needs a file or a link.",o);if(u.length>0)throw h("forge transcribe takes one file or link at a time.",o);return{...n,input:r}}function Ie(s){let e=s.slice(1),t=[],n,i={kind:"watch",newOnly:!1,debug:!1},o={},r=(l,a)=>{let c=e[a+1];if(c===void 0||c.startsWith("-"))throw h(`${l} needs a value.`);return c};for(let l=0;l<e.length;l++){let a=e[l];if(a!=="--json")if(a==="--debug")i.debug=!0;else if(a==="--new-only")i.newOnly=!0;else if(a==="--to"||a==="-t")n=V(r(a,l++));else if(a==="--quality"||a==="-q")o.quality=E(r(a,l++));else if(a==="--output"||a==="-o")o.output=F(r(a,l++));else if(a==="--dpi"){let c=r(a,l++),p=Number(c);if(!Number.isInteger(p)||p<36||p>600)throw P(c);o.dpi=p}else{if(a.startsWith("-"))throw h(`forge watch does not take ${a}.`,"Try: forge watch ./images --to webp");t.push(a)}}let[u,...d]=t;if(u===void 0)throw h("forge watch needs a folder.","Try: forge watch ./images --to webp");if(d.length>0)throw h("forge watch watches one folder at a time.",`Try: forge watch ${u} --to webp`);if(n===void 0)throw h("forge watch needs a format to convert to.",`Try: forge watch ${u} --to webp`);return{kind:"watch",folder:u,target:n,...o.quality===void 0?{}:{quality:o.quality},...o.dpi===void 0?{}:{dpi:o.dpi},...o.output===void 0?{}:{output:o.output},newOnly:i.newOnly,debug:i.debug}}function He(s){let e=s.slice(1).filter(r=>r!=="--json"),t=e.find(r=>r.startsWith("-"));if(t!==void 0)throw h(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...o]=e;if(n===void 0||n==="list"&&i===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw h(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||o.length>0)throw h(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function pe(s){if(s===void 0)throw h("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=ee(s)?.rgb;if(!e)throw h(`${s} is not a colour.`,"Try a hex code (6579FD), rgb(), hsl(), oklch() or a colour name, quoted: 'rgb(101 121 253)'.");return e}function Ve(s,e=process.platform,t=process.env){let o=e==="linux"&&!t.WAYLAND_DISPLAY&&!!t.DISPLAY?" --svg a card of swatches; pipe to xclip -sel c, paste into Figma":` --svg a card of swatches; pipe to ${e==="win32"?"clip":e==="linux"?"wl-copy":"pbcopy"} and paste into Figma`;return s==="card"?`Usage: forge card <file> [--json] [--svg] [--title <text>]
55
+ forge mcp run as a local MCP server over stdio, for AI agents`;function _e(s=process.platform){if(s==="darwin")return ge;let e=s==="win32"?"boost and whisper":"whisper and heic";return ge.replace("a video or audio file, or a video link, into notes","a video or audio file, or a video link, into a transcript").replace("optional extras, such as boost and remove-background",`optional extras, such as ${e}`)}function K(s){let e=ee(String(s));if(e===void 0)throw h(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function He(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw h(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw v("Pass a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function Ve(s){let e={kind:"clip",undo:!1,debug:!1},t=s.slice(1),n=(i,o)=>{let r=t[o+1];if(r===void 0||r.startsWith("-"))throw h(`${i} needs a value.`);return r};for(let i=0;i<t.length;i++){let o=t[i];if(o!=="--json")if(o==="--debug")e.debug=!0;else if(o==="--undo")e.undo=!0;else if(o==="--to"||o==="-t")e.target=V(n(o,i++));else if(o==="--quality"||o==="-q")e.quality=I(n(o,i++));else if(o==="--max-size")e.maxBytes=K(n(o,i++));else if(o==="--save"){let r=t[i+1];e.save=r===void 0||r.startsWith("-")?!0:t[++i]}else throw o.startsWith("-")?h(`forge clip does not take ${o}.`,"Try: forge --help"):h(`forge clip takes no files: it reads the clipboard, not ${o}.`,`To compress a file, try: forge ${o} --quality 80`)}if(e.undo&&Object.keys(e).some(i=>!["kind","undo","debug"].includes(i)))throw h("--undo takes no other flag.","Try: forge clip --undo");if(e.quality!==void 0&&e.maxBytes!==void 0)throw h("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");return e}function Fe(s){let e=s.slice(1),t=[],n={kind:"transcribe",input:"",notes:!0,transcript:!0,detail:ce,force:!1,debug:!1},i=(d,l)=>{let a=e[l+1];if(a===void 0||a.startsWith("-"))throw h(`${d} needs a value.`);return a},o="Try: forge transcribe talk.mp4";for(let d=0;d<e.length;d++){let l=e[d];if(l==="--debug")n.debug=!0;else if(l==="--force"||l==="-f")n.force=!0;else if(l==="--language"||l==="-l")n.language=i(l,d++);else if(l==="--output"||l==="-o")n.output=P(i(l,d++));else if(l==="--detail"){let a=i(l,d++).toLowerCase();if(!de.includes(a))throw h(`forge transcribe writes notes in brief, standard or detailed, not ${a}.`,"Try: forge transcribe talk.mp4 --detail brief");n.detail=a}else if(l==="--format"){let a=i(l,d++).toLowerCase(),c=ne.find(f=>f.id===a||f.label.toLowerCase()===a);if(c===void 0)throw h(`forge transcribe writes md, docx, pdf or txt, not ${a}.`,"Try: forge transcribe talk.mp4 --format pdf");n.format=c.id}else if(l==="--to"||l==="-t"){let a=i(l,d++).toLowerCase();if(a!=="all"&&a!=="notes"&&a!=="transcript")throw h(`forge transcribe makes all, notes or a transcript, not ${a}.`,"Try: forge transcribe talk.mp4 --to transcript");n.to=a,n.notes=a!=="transcript",n.transcript=a!=="notes"}else{if(l.startsWith("-"))throw h(`forge transcribe does not take ${l}.`,o);t.push(l)}}let[r,...u]=t;if(r===void 0)throw h("forge transcribe needs a file or a link.",o);if(u.length>0)throw h("forge transcribe takes one file or link at a time.",o);return{...n,input:r}}function Ne(s){let e=s.slice(1),t=[],n,i={kind:"watch",newOnly:!1,debug:!1},o={},r=(l,a)=>{let c=e[a+1];if(c===void 0||c.startsWith("-"))throw h(`${l} needs a value.`);return c};for(let l=0;l<e.length;l++){let a=e[l];if(a!=="--json")if(a==="--debug")i.debug=!0;else if(a==="--new-only")i.newOnly=!0;else if(a==="--to"||a==="-t")n=V(r(a,l++));else if(a==="--quality"||a==="-q")o.quality=I(r(a,l++));else if(a==="--output"||a==="-o")o.output=P(r(a,l++));else if(a==="--dpi"){let c=r(a,l++),f=Number(c);if(!Number.isInteger(f)||f<36||f>600)throw N(c);o.dpi=f}else{if(a.startsWith("-"))throw h(`forge watch does not take ${a}.`,"Try: forge watch ./images --to webp");t.push(a)}}let[u,...d]=t;if(u===void 0)throw h("forge watch needs a folder.","Try: forge watch ./images --to webp");if(d.length>0)throw h("forge watch watches one folder at a time.",`Try: forge watch ${u} --to webp`);if(n===void 0)throw h("forge watch needs a format to convert to.",`Try: forge watch ${u} --to webp`);return{kind:"watch",folder:u,target:n,...o.quality===void 0?{}:{quality:o.quality},...o.dpi===void 0?{}:{dpi:o.dpi},...o.output===void 0?{}:{output:o.output},newOnly:i.newOnly,debug:i.debug}}function Pe(s){let e=s.slice(1).filter(r=>r!=="--json"),t=e.find(r=>r.startsWith("-"));if(t!==void 0)throw h(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...o]=e;if(n===void 0||n==="list"&&i===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw h(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||o.length>0)throw h(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function be(s){if(s===void 0)throw h("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=ie(s)?.rgb;if(!e)throw h(`${s} is not a colour.`,"Try a hex code (6579FD), rgb(), hsl(), oklch() or a colour name, quoted: 'rgb(101 121 253)'.");return e}function je(s,e=process.platform,t=process.env){let o=e==="linux"&&!t.WAYLAND_DISPLAY&&!!t.DISPLAY?" --svg a card of swatches; pipe to xclip -sel c, paste into Figma":` --svg a card of swatches; pipe to ${e==="win32"?"clip":e==="linux"?"wl-copy":"pbcopy"} and paste into Figma`;return s==="card"?`Usage: forge card <file> [--json] [--svg] [--title <text>]
56
56
 
57
57
  Named colours from design tokens, a CSV, CSS variables or one a line
58
58
  (bg #F8F1E6). - reads them from stdin.
@@ -70,11 +70,11 @@ An image's main colours, most of the image first.
70
70
  --json one JSON document: palette.colours[] with hex, rgb, oklch, share
71
71
  ${o}
72
72
  --inside <hex> the shades of the palette colour nearest <hex>
73
- `}var me=["clip","watch","transcribe","config","probe","extensions","palette","scale","card","update","uninstall","menu","mcp"];function Ne(s,e=process.platform){let[t,...n]=s;if(!me.includes(t??""))return;let i=n.indexOf("--"),o=i===-1?n:n.slice(0,i);if(!o.includes("--help")&&!o.includes("-h"))return;if(t==="palette"||t==="scale"||t==="card")return Ve(t,e);let r=fe(e).split(`
73
+ `}var we=["clip","watch","transcribe","config","probe","extensions","palette","scale","card","update","uninstall","menu","mcp"];function We(s,e=process.platform){let[t,...n]=s;if(!we.includes(t??""))return;let i=n.indexOf("--"),o=i===-1?n:n.slice(0,i);if(!o.includes("--help")&&!o.includes("-h"))return;if(t==="palette"||t==="scale"||t==="card")return je(t,e);let r=_e(e).split(`
74
74
  `),u=r.findIndex(l=>l.startsWith(` forge ${t} `)||l===` forge ${t}`),d=[r[u]];for(let l of r.slice(u+1)){if(!l.startsWith(" "))break;d.push(l)}return`Usage:
75
75
  ${d.join(`
76
76
  `)}
77
- `}function Pe(s){let[e,...t]=s;if(e==="card")return Fe(t);let n=t.filter(d=>d!=="--json"&&d!=="--svg"),i=t.includes("--svg"),o=n.indexOf("--inside"),r=o===-1?void 0:n[o+1];o!==-1&&n.splice(o,2);let u=n.find(d=>d.startsWith("-"));if(u!==void 0)throw h(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(o!==-1)throw h("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw h("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:pe(n[0]),svg:i}}if(n.length!==1)throw h(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...o===-1?{}:{inside:pe(r)}}}function Fe(s){let e=s.filter(r=>r!=="--json"&&r!=="--svg"),t=s.includes("--svg"),n=e.indexOf("--title"),i=n===-1?void 0:e[n+1];if(n!==-1){if(i===void 0||i.trim()==="")throw h("--title needs the heading.","Try: forge card palette.csv --title 'Cream blue'");e.splice(n,2)}let o=e.find(r=>r.startsWith("-")&&r!=="-");if(o!==void 0)throw h(`forge card does not take ${o}.`,"Try: forge card --help");if(e.length!==1)throw h(e.length===0?"No file given.":"forge card takes one file.","Try: forge card palette.csv --svg");return{kind:"card",input:e[0],svg:t,...i===void 0?{}:{title:i}}}function je(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function We(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],o;for(let r=0;r<t.length;r++){let u=t[r],d=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&d===void 0){i.push(u);continue}let l=d;if(l===void 0&&/^\d+$/.test(t[r+1]??"")&&(l=t[++r]),l!==void 0&&l!=="2"&&l!=="3"&&l!=="4")throw h(`--boost takes 2, 3 or 4, not ${l}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");o=l==="4"?4:l==="3"?3:2}return{rest:[...i,...n],...o===void 0?{}:{scale:o}}}function Ht(s){let e=s;if(me.includes(e[0]??"")){let i=Ne(e);if(i!==void 0)throw process.stdout.write(i),new x(0,"commander.helpDisplayed","(outputHelp)");return qe(e)}let t=e.includes("--")?e.slice(0,e.indexOf("--")):e;if(je(e)&&(t.includes("--version")||t.includes("-V")))throw process.stdout.write(`${JSON.stringify({forge:j,ok:!0})}
78
- `),new x(0,"commander.version",j);let n=We(De(e));return Ge(n.rest,n.scale)}function De(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e);return[...t.flatMap(i=>{let o=/^(-[toq])=(.*)$/s.exec(i);return o?[o[1],o[2]]:[i]}),...n]}function qe(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw h(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}if(s[0]==="uninstall"){let e=s.slice(1);if(e.length>0)throw h(`forge uninstall takes nothing else, got: ${e.join(" ")}.`,"Try: forge uninstall");return{kind:"uninstall"}}return s[0]==="clip"?Ee(s):s[0]==="watch"?Ie(s):s[0]==="transcribe"?Te(s):s[0]==="config"?Ce(s.filter(e=>e!=="--json")):s[0]==="probe"?Se(s):s[0]==="palette"||s[0]==="scale"||s[0]==="card"?Pe(s):He(s)}function Ge(s,e){let t=new S().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory; its extension sets the format").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs or images into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--cut <start-end>","video or audio: keep from start to end, e.g. 0:03.2-0:41").option("--mute","video: take the sound out").option("--speed <x>","video or audio: play faster or slower, 0.25-4").option("--fps <n>","video: frames per second").option("--bitrate <kbps>","audio: bitrate, e.g. 128k").option("--loudness <LUFS>","audio: even out loudness to this level, e.g. -16").option("--clean-audio","video or audio: take out rumble and hiss, then even the level").option("--preset <name>","run a preset saved from Done, e.g. --preset blog").option("--pages <ranges>","which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(j,"-V, --version","show the version").addHelpText("after",`${fe()}
79
- ${$e}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof x&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[g="",...b]=f.message.replace(/^error: /,"").split(`
80
- `),_=b.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw h(`${g.charAt(0).toUpperCase()}${g.slice(1).replace(/\.$/,"")}.`,_||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.output==="-")throw h("-o needs a file or folder, not -.");n.output!==void 0&&(n.output=F(String(n.output)));let o=n.output===void 0||oe(String(n.output))?void 0:K(Oe(String(n.output)))[0]?.id;if(n.formats)return{kind:"formats"};let r=ve(n);if(r!==void 0&&n.trim)throw h("--trim cuts the empty edges of an image.","To keep part of a video or audio file, use --cut, for example --cut 0:03-0:41.");if(n.preset!==void 0){let f=new Set(["preset","output","force","recursive","debug","json"]),g=t.options.filter(b=>!f.has(b.attributeName())).filter(b=>t.getOptionValueSource(b.attributeName())==="cli").map(b=>b.long??b.flags);if(e!==void 0&&g.push("--boost"),g.length>0)throw h(`--preset sets these options. Drop ${g.join(" and ")}.`,"Run the preset alone, or change it from Done with \u2192 continue editing.");if(i.length===0)throw v("Pass a file, for example: forge photo.jpg --preset blog");return{kind:"preset",inputs:i,name:String(n.preset),...n.output===void 0?{}:{output:String(n.output)},force:n.force===!0,recursive:n.recursive===!0,debug:n.debug===!0}}let u=te(String(n.background));if(u===void 0)throw Q(String(n.background));if(n.pages!==void 0&&n.to===void 0&&o===void 0)throw h("--pages needs --to: it chooses which pages to render.");let d=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(d.length>1)throw h(`Use one operation at a time \u2014 got ${d.map(f=>`--${f}`).join(" and ")}.`);let l=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],a=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]],c=r!==void 0&&!n.to&&n.quality===void 0&&n.maxSize===void 0;if(n.trim||n.crop!==void 0||a.length>0||c){if(a.length>1)throw h(`Use one of --resize, --width and --height \u2014 got ${a.join(" and ")}.`);let f=n.crop!==void 0?"--crop":a[0]??(n.trim?"--trim":"--cut"),g=[...n.crop!==void 0&&n.trim?["--trim"]:[],...l,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...d.map(ge=>`--${ge}`)][0];if(g!==void 0)throw h(`${f} cannot be combined with ${g}.`,g!=="--max-size"?"Run them one after the other.":f==="--crop"?"Crop first, then compress the result: forge photo-cropped-1x1.jpg --max-size 500kb":"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb");let b=n.crop!==void 0?{aspect:ne(String(n.crop))}:void 0,_=n.resize!==void 0?{percent:Ae(n.resize)}:n.width!==void 0?{width:ce("--width",n.width)}:n.height!==void 0?{height:ce("--height",n.height)}:void 0;if(i.length===0)throw v("Pass an image, for example: forge photo.jpg --resize 50%");let k={background:u,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(k.quality=E(String(n.quality)));let w={kind:"edit",inputs:i,trim:!!n.trim,options:k,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return b!==void 0&&(w.crop=b),_!==void 0&&(w.resize=_),r!==void 0&&(w.media=r),n.to&&(w.target=V(String(n.to))),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=M(String(n.concurrency))),w}let p=n.sharpen?1:e,y=p!==void 0?"boost":n.removeBg?"remove-background":null;if(y!==null){if(l.length>1)throw h(`Use one operation at a time \u2014 got ${l.join(" and ")}.`);let f=l[0];if(d.length>0)throw h(`${f} cannot be combined with --${d[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw h(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw v(`Pass an image, for example: forge photo.jpg ${f}`);let g=n.to?V(String(n.to)):void 0;if(y==="remove-background"&&g!==void 0){let k=ie(g);if(k)throw k}let b={background:u,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(b.quality=E(String(n.quality)));let _={kind:"extension-op",op:y,inputs:i,...g===void 0?{}:{target:g},options:b,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return p!==void 0&&(_.scale=p),n.output!==void 0&&(_.output=String(n.output)),n.concurrency!==void 0&&(_.concurrency=M(String(n.concurrency))),_}if(d.length===1){let f=d[0];if(i.length===0)throw v(`Pass a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw h(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw h(`--output does not apply to --${f}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let g={kind:"pageop",action:f,inputs:i,force:!!n.force,debug:!!n.debug};if(f==="rotate"){let b=Number(n.rotate);if(!Number.isInteger(b)||b%90!==0||b===0||b>=360)throw h(`--rotate takes a multiple of 90 below 360, not '${n.rotate}'.`);g.rotate=b}if((f==="extract"||f==="delete")&&(g.pages=String(n[f]),f==="extract"&&n.separate&&(g.separate=!0)),f==="split"){let b=String(n.split),_=b.match(/^every=(\d+)$/),k=b.match(/^at=(\s*\d+(?:\s*,\s*\d+)*\s*)$/);if(b==="every-page")g.split={mode:"every-page"};else if(_?.[1]!==void 0){let w=Number(_[1]);if(!Number.isInteger(w)||w<1)throw h(`--split every=N takes a whole number of pages, at least 1, not '${_[1]}'.`);g.split={mode:"every-n",n:w}}else if(k?.[1])g.split={mode:"points",after:k[1].split(",").map(w=>Number(w.trim()))};else throw h(`--split takes every-page, every=N or at=N,N \u2014 not '${b}'.`)}return g}if(i.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw h("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(i.length===0)throw v("Pass a file, for example: forge photo.jpg --max-size 500kb");let f={background:u,keepMetadata:!!n.keepMetadata};r!==void 0&&(f.media=r);let g={kind:"compress",inputs:i,options:f,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(g.quality=E(String(n.quality))),n.maxSize!==void 0&&(g.maxBytes=J(n.maxSize)),n.output!==void 0&&(g.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let b=Number(n.dpi);if(!Number.isInteger(b)||b<36||b>600)throw P(n.dpi);g.dpi=b}return n.concurrency!==void 0&&(g.concurrency=M(String(n.concurrency))),g}let O=n.to?V(String(n.to)):o;if(O===void 0)throw h("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw v("Pass a file, a folder or a glob, for example: forge photo.jpg --to webp");let B={background:u,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(B.quality=E(String(n.quality))),r!==void 0&&(B.media=r);let N=Number(n.dpi);if(!Number.isInteger(N)||N<36||N>600)throw P(n.dpi);let T={kind:"convert",inputs:i,target:O,options:B,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:N,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(T.output=String(n.output)),n.pages!==void 0&&(T.pages=String(n.pages)),n.maxSize!==void 0&&(T.maxBytes=J(n.maxSize)),n.concurrency!==void 0&&(T.concurrency=M(String(n.concurrency))),T}export{$e as a,he as b,fe as c,Ve as d,Ne as e,je as f,Ht as g};
77
+ `}function De(s){let[e,...t]=s;if(e==="card")return Be(t);let n=t.filter(d=>d!=="--json"&&d!=="--svg"),i=t.includes("--svg"),o=n.indexOf("--inside"),r=o===-1?void 0:n[o+1];o!==-1&&n.splice(o,2);let u=n.find(d=>d.startsWith("-"));if(u!==void 0)throw h(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(o!==-1)throw h("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw h("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:be(n[0]),svg:i}}if(n.length!==1)throw h(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...o===-1?{}:{inside:be(r)}}}function Be(s){let e=s.filter(r=>r!=="--json"&&r!=="--svg"),t=s.includes("--svg"),n=e.indexOf("--title"),i=n===-1?void 0:e[n+1];if(n!==-1){if(i===void 0||i.trim()==="")throw h("--title needs the heading.","Try: forge card palette.csv --title 'Cream blue'");e.splice(n,2)}let o=e.find(r=>r.startsWith("-")&&r!=="-");if(o!==void 0)throw h(`forge card does not take ${o}.`,"Try: forge card --help");if(e.length!==1)throw h(e.length===0?"No file given.":"forge card takes one file.","Try: forge card palette.csv --svg");return{kind:"card",input:e[0],svg:t,...i===void 0?{}:{title:i}}}function qe(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function Ge(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],o;for(let r=0;r<t.length;r++){let u=t[r],d=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&d===void 0){i.push(u);continue}let l=d;if(l===void 0&&/^\d+$/.test(t[r+1]??"")&&(l=t[++r]),l!==void 0&&l!=="2"&&l!=="3"&&l!=="4")throw h(`--boost takes 2, 3 or 4, not ${l}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");o=l==="4"?4:l==="3"?3:2}return{rest:[...i,...n],...o===void 0?{}:{scale:o}}}function Wt(s){let e=s;if(we.includes(e[0]??"")){let i=We(e);if(i!==void 0)throw process.stdout.write(i),new x(0,"commander.helpDisplayed","(outputHelp)");return Le(e)}let t=e.includes("--")?e.slice(0,e.indexOf("--")):e;if(qe(e)&&(t.includes("--version")||t.includes("-V")))throw process.stdout.write(`${JSON.stringify({forge:j,ok:!0})}
78
+ `),new x(0,"commander.version",j);let n=Ge(Me(e));return ze(n.rest,n.scale)}function Me(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e);return[...t.flatMap(i=>{let o=/^(-[toq])=(.*)$/s.exec(i);return o?[o[1],o[2]]:[i]}),...n]}function Le(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw h(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}if(s[0]==="uninstall"){let e=s.slice(1);if(e.length>0)throw h(`forge uninstall takes nothing else, got: ${e.join(" ")}.`,"Try: forge uninstall");return{kind:"uninstall"}}return s[0]==="clip"?Ve(s):s[0]==="watch"?Ne(s):s[0]==="transcribe"?Fe(s):s[0]==="config"?Se(s.filter(e=>e!=="--json")):s[0]==="probe"?He(s):s[0]==="palette"||s[0]==="scale"||s[0]==="card"?De(s):Pe(s)}function ze(s,e){let t=new E().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory; its extension sets the format").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs or images into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--cut <start-end>","video or audio: keep from start to end, e.g. 0:03.2-0:41").option("--mute","video: take the sound out").option("--speed <x>","video or audio: play faster or slower, 0.25-4").option("--fps <n>","video: frames per second").option("--bitrate <kbps>","audio: bitrate, e.g. 128k").option("--loudness <LUFS>","audio: even out loudness to this level, e.g. -16").option("--clean-audio","video or audio: take out rumble and hiss, then even the level").option("--cookies-from-browser <browser>","video links: use this browser's sign-in (chrome, safari, firefox, brave, edge)").option("--preset <name>","run a preset saved from Done, e.g. --preset blog").option("--pages <ranges>","which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(j,"-V, --version","show the version").addHelpText("after",`${_e()}
79
+ ${Te}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(p){if(p instanceof x&&p.code!=="commander.helpDisplayed"&&p.code!=="commander.version"){let[m="",...b]=p.message.replace(/^error: /,"").split(`
80
+ `),w=b.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw h(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,w||"Run forge --help to see what Forge accepts.")}throw p}let n=t.opts(),i=n.cookiesFromBrowser===void 0?void 0:X(String(n.cookiesFromBrowser).toLowerCase())?String(n.cookiesFromBrowser).toLowerCase():(()=>{throw h(`Forge cannot use ${String(n.cookiesFromBrowser)}'s sign-in.`,`Pass one of: ${Object.keys(Y).join(", ")}.`)})(),o=t.args;if(n.output==="-")throw h("-o needs a file or folder, not -.");n.output!==void 0&&(n.output=P(String(n.output)));let r=n.output===void 0||ae(String(n.output))?void 0:Z(Ae(String(n.output)))[0]?.id;if(n.formats)return{kind:"formats"};let u=Ee(n);if(u!==void 0&&n.trim)throw h("--trim cuts the empty edges of an image.","To keep part of a video or audio file, use --cut, for example --cut 0:03-0:41.");if(n.preset!==void 0){let p=new Set(["preset","output","force","recursive","debug","json"]),m=t.options.filter(b=>!p.has(b.attributeName())).filter(b=>t.getOptionValueSource(b.attributeName())==="cli").map(b=>b.long??b.flags);if(e!==void 0&&m.push("--boost"),m.length>0)throw h(`--preset sets these options. Drop ${m.join(" and ")}.`,"Run the preset alone, or change it from Done with \u2192 continue editing.");if(o.length===0)throw v("Pass a file, for example: forge photo.jpg --preset blog");return{kind:"preset",inputs:o,name:String(n.preset),...n.output===void 0?{}:{output:String(n.output)},force:n.force===!0,recursive:n.recursive===!0,debug:n.debug===!0}}let d=oe(String(n.background));if(d===void 0)throw te(String(n.background));if(n.pages!==void 0&&n.to===void 0&&r===void 0)throw h("--pages needs --to: it chooses which pages to render.");let l=["merge","split","extract","delete","rotate"].filter(p=>n[p]!==void 0);if(l.length>1)throw h(`Use one operation at a time \u2014 got ${l.map(p=>`--${p}`).join(" and ")}.`);let a=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],c=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]],f=u!==void 0&&!n.to&&n.quality===void 0&&n.maxSize===void 0;if(n.trim||n.crop!==void 0||c.length>0||f){if(c.length>1)throw h(`Use one of --resize, --width and --height \u2014 got ${c.join(" and ")}.`);let p=n.crop!==void 0?"--crop":c[0]??(n.trim?"--trim":"--cut"),m=[...n.crop!==void 0&&n.trim?["--trim"]:[],...a,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...l.map(xe=>`--${xe}`)][0];if(m!==void 0)throw h(`${p} cannot be combined with ${m}.`,m!=="--max-size"?"Run them one after the other.":p==="--crop"?"Crop first, then compress the result: forge photo-cropped-1x1.jpg --max-size 500kb":"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb");let b=n.crop!==void 0?{aspect:re(String(n.crop))}:void 0,w=n.resize!==void 0?{percent:Ie(n.resize)}:n.width!==void 0?{width:me("--width",n.width)}:n.height!==void 0?{height:me("--height",n.height)}:void 0;if(o.length===0)throw v("Pass an image, for example: forge photo.jpg --resize 50%");let k={background:d,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(k.quality=I(String(n.quality)));let _={kind:"edit",inputs:o,trim:!!n.trim,options:k,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return b!==void 0&&(_.crop=b),w!==void 0&&(_.resize=w),u!==void 0&&(_.media=u),i&&(_.signIn=i),n.to&&(_.target=V(String(n.to))),n.output!==void 0&&(_.output=String(n.output)),n.concurrency!==void 0&&(_.concurrency=G(String(n.concurrency))),_}let O=n.sharpen?1:e,y=O!==void 0?"boost":n.removeBg?"remove-background":null;if(y!==null){if(a.length>1)throw h(`Use one operation at a time \u2014 got ${a.join(" and ")}.`);let p=a[0];if(l.length>0)throw h(`${p} cannot be combined with --${l[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw h(`${p} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(o.length===0)throw v(`Pass an image, for example: forge photo.jpg ${p}`);let m=n.to?V(String(n.to)):void 0;if(y==="remove-background"&&m!==void 0){let k=se(m);if(k)throw k}let b={background:d,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(b.quality=I(String(n.quality)));let w={kind:"extension-op",op:y,inputs:o,...m===void 0?{}:{target:m},options:b,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return O!==void 0&&(w.scale=O),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=G(String(n.concurrency))),w}if(l.length===1){let p=l[0];if(o.length===0)throw v(`Pass a PDF, for example: forge doc.pdf --${p}`);if(n.separate&&p!=="extract")throw h(`--separate only applies to --extract, not --${p}.`);if(n.output!==void 0)throw h(`--output does not apply to --${p}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let m={kind:"pageop",action:p,inputs:o,force:!!n.force,debug:!!n.debug};if(p==="rotate"){let b=Number(n.rotate);if(!Number.isInteger(b)||b%90!==0||b===0||b>=360)throw h(`--rotate takes a multiple of 90 below 360, not '${n.rotate}'.`);m.rotate=b}if((p==="extract"||p==="delete")&&(m.pages=String(n[p]),p==="extract"&&n.separate&&(m.separate=!0)),p==="split"){let b=String(n.split),w=b.match(/^every=(\d+)$/),k=b.match(/^at=(\s*\d+(?:\s*,\s*\d+)*\s*)$/);if(b==="every-page")m.split={mode:"every-page"};else if(w?.[1]!==void 0){let _=Number(w[1]);if(!Number.isInteger(_)||_<1)throw h(`--split every=N takes a whole number of pages, at least 1, not '${w[1]}'.`);m.split={mode:"every-n",n:_}}else if(k?.[1])m.split={mode:"points",after:k[1].split(",").map(_=>Number(_.trim()))};else throw h(`--split takes every-page, every=N or at=N,N \u2014 not '${b}'.`)}return m}if(o.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw h("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(o.length===0)throw v("Pass a file, for example: forge photo.jpg --max-size 500kb");let p={background:d,keepMetadata:!!n.keepMetadata};u!==void 0&&(p.media=u);let m={kind:"compress",inputs:o,options:p,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(m.quality=I(String(n.quality))),n.maxSize!==void 0&&(m.maxBytes=K(n.maxSize)),i&&(m.signIn=i),n.output!==void 0&&(m.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let b=Number(n.dpi);if(!Number.isInteger(b)||b<36||b>600)throw N(n.dpi);m.dpi=b}return n.concurrency!==void 0&&(m.concurrency=G(String(n.concurrency))),m}let M=n.to?V(String(n.to)):r;if(M===void 0&&le(o)){let p={kind:"edit",inputs:o,trim:!1,download:!0,options:{background:d,keepMetadata:!!n.keepMetadata},force:!!n.force,recursive:!1,debug:!!n.debug};return i&&(p.signIn=i),n.output!==void 0&&(p.output=String(n.output)),p}if(M===void 0)throw h("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(o.length===0)throw v("Pass a file, a folder or a glob, for example: forge photo.jpg --to webp");let L={background:d,keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(L.quality=I(String(n.quality))),u!==void 0&&(L.media=u);let F=Number(n.dpi);if(!Number.isInteger(F)||F<36||F>600)throw N(n.dpi);let S={kind:"convert",inputs:o,target:M,options:L,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:F,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(S.output=String(n.output)),i&&(S.signIn=i),n.pages!==void 0&&(S.pages=String(n.pages)),n.maxSize!==void 0&&(S.maxBytes=K(n.maxSize)),n.concurrency!==void 0&&(S.concurrency=G(String(n.concurrency))),S}export{Te as a,ge as b,_e as c,je as d,We as e,qe as f,Wt as g};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{P as $}from"./chunk-CCNRNCRU.js";var _=[{w:1,h:1,label:"1:1"},{w:4,h:5,label:"4:5"},{w:16,h:9,label:"16:9"},{w:9,h:16,label:"9:16"}],v=20,D=10,p=t=>Math.max(1,Math.round(t)),u=(t,e,n)=>Math.min(Math.max(t,e),n);function P(t,e){let n=p(t.width*e.h/e.w),[r,i]=n<=t.height?[t.width,n]:[Math.min(t.width,p(t.height*e.w/e.h)),t.height];return{left:Math.floor((t.width-r)/2),top:Math.floor((t.height-i)/2),width:r,height:i}}var T=(t,e)=>e.width===t.width&&e.height===t.height;function N(t){return _.filter(e=>!T(t,P(t,e)))}function W(t,e,n,r){let i=P(t,e),o,h;return e.w>=e.h?(o=p(i.width*r/100),h=Math.min(t.height,p(o*e.h/e.w))):(h=p(i.height*r/100),o=Math.min(t.width,p(h*e.w/e.h))),{left:u(Math.round(n.x-o/2),0,t.width-o),top:u(Math.round(n.y-h/2),0,t.height-h),width:o,height:h}}function k(t,e,n,r){return{...e,left:u(e.left+n,0,t.width-e.width),top:u(e.top+r,0,t.height-e.height)}}function E(t,e){return{x:e.width<t.width,y:e.height<t.height}}function H(t){return{x:t.left+t.width/2,y:t.top+t.height/2}}function Z(t,e){return Math.round(e.width*e.height*100/(t.width*t.height))}var F=t=>`${t.w}:${t.h}`,I=t=>`cropped-${t.w}x${t.h}`;function L(t){let e=/^(\d{1,3}):(\d{1,3})$/.exec(t.trim()),n=Number(e?.[1]),r=Number(e?.[2]);if(!e||n<1||n>100||r<1||r>100)throw $(`'${t}' is not a shape; it takes two whole numbers from 1 to 100, as W:H.`,"Try --crop 1:1 or --crop 16:9.");return{w:n,h:r}}function q(t,e,n){let r=n*2,i=new Uint8Array(e*r*3),o=t.alpha?new Uint8Array(e*r):void 0,h=t.width/e,M=t.height/r;for(let c=0;c<r;c++){let w=c*M,y=w+M;for(let s=0;s<e;s++){let f=s*h,b=f+h,A=0,S=0,B=0,a=0,x=0;for(let d=Math.floor(w);d<Math.min(Math.ceil(y),t.height);d++){let R=Math.min(d+1,y)-Math.max(d,w);for(let l=Math.floor(f);l<Math.min(Math.ceil(b),t.width);l++){let C=d*t.width+l,U=(Math.min(l+1,b)-Math.max(l,f))*R,m=U*(t.alpha?(t.alpha[C]??0)/255:1),g=C*3;A+=(t.rgb[g]??0)*m,S+=(t.rgb[g+1]??0)*m,B+=(t.rgb[g+2]??0)*m,a+=m,x+=U}}let O=c*e+s;a>0&&i.set([A/a,S/a,B/a].map(Math.round),O*3),o&&x>0&&(o[O]=Math.round(a*255/x))}}return{cols:e,dotRows:r,rgb:i,...o?{alpha:o}:{}}}export{_ as a,v as b,D as c,P as d,N as e,W as f,k as g,E as h,H as i,Z as j,F as k,I as l,L as m,q as n};
3
+ import{S as $}from"./chunk-PNPAHKJR.js";var _=[{w:1,h:1,label:"1:1"},{w:4,h:5,label:"4:5"},{w:16,h:9,label:"16:9"},{w:9,h:16,label:"9:16"}],v=20,D=10,p=t=>Math.max(1,Math.round(t)),u=(t,e,n)=>Math.min(Math.max(t,e),n);function P(t,e){let n=p(t.width*e.h/e.w),[r,i]=n<=t.height?[t.width,n]:[Math.min(t.width,p(t.height*e.w/e.h)),t.height];return{left:Math.floor((t.width-r)/2),top:Math.floor((t.height-i)/2),width:r,height:i}}var T=(t,e)=>e.width===t.width&&e.height===t.height;function N(t){return _.filter(e=>!T(t,P(t,e)))}function W(t,e,n,r){let i=P(t,e),o,h;return e.w>=e.h?(o=p(i.width*r/100),h=Math.min(t.height,p(o*e.h/e.w))):(h=p(i.height*r/100),o=Math.min(t.width,p(h*e.w/e.h))),{left:u(Math.round(n.x-o/2),0,t.width-o),top:u(Math.round(n.y-h/2),0,t.height-h),width:o,height:h}}function k(t,e,n,r){return{...e,left:u(e.left+n,0,t.width-e.width),top:u(e.top+r,0,t.height-e.height)}}function E(t,e){return{x:e.width<t.width,y:e.height<t.height}}function H(t){return{x:t.left+t.width/2,y:t.top+t.height/2}}function Z(t,e){return Math.round(e.width*e.height*100/(t.width*t.height))}var F=t=>`${t.w}:${t.h}`,I=t=>`cropped-${t.w}x${t.h}`;function L(t){let e=/^(\d{1,3}):(\d{1,3})$/.exec(t.trim()),n=Number(e?.[1]),r=Number(e?.[2]);if(!e||n<1||n>100||r<1||r>100)throw $(`'${t}' is not a shape; it takes two whole numbers from 1 to 100, as W:H.`,"Try --crop 1:1 or --crop 16:9.");return{w:n,h:r}}function q(t,e,n){let r=n*2,i=new Uint8Array(e*r*3),o=t.alpha?new Uint8Array(e*r):void 0,h=t.width/e,M=t.height/r;for(let c=0;c<r;c++){let w=c*M,y=w+M;for(let s=0;s<e;s++){let f=s*h,b=f+h,A=0,S=0,B=0,a=0,x=0;for(let d=Math.floor(w);d<Math.min(Math.ceil(y),t.height);d++){let R=Math.min(d+1,y)-Math.max(d,w);for(let l=Math.floor(f);l<Math.min(Math.ceil(b),t.width);l++){let C=d*t.width+l,U=(Math.min(l+1,b)-Math.max(l,f))*R,m=U*(t.alpha?(t.alpha[C]??0)/255:1),g=C*3;A+=(t.rgb[g]??0)*m,S+=(t.rgb[g+1]??0)*m,B+=(t.rgb[g+2]??0)*m,a+=m,x+=U}}let O=c*e+s;a>0&&i.set([A/a,S/a,B/a].map(Math.round),O*3),o&&x>0&&(o[O]=Math.round(a*255/x))}}return{cols:e,dotRows:r,rgb:i,...o?{alpha:o}:{}}}export{_ as a,v as b,D as c,P as d,N as e,W as f,k as g,E as h,H as i,Z as j,F as k,I as l,L as m,q as n};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
- import{f as a}from"./chunk-NMGQGYVM.js";import{e as i}from"./chunk-3IX3QA76.js";import{a as e}from"./chunk-CCNRNCRU.js";function s(t){let o=Object.keys(e);return[...t].sort((r,n)=>o.indexOf(r)-o.indexOf(n))}function f(t){let o=new Set;for(let r of a)if(r.reads.has(t.format))for(let n of r.writesFor?.(t)??r.writes)e[n].keepsOnly&&n!==t.format||o.add(n);return s([...o])}function F(t){return f(t).map(o=>({id:o,label:e[o].label,hint:e[o].hint,lossy:e[o].lossy}))}function d(){let t=new Set;for(let o of a)for(let r of o.reads)t.add(r);return s([...t])}function l(){let t=new Set;for(let o of a)for(let r of o.writes)t.add(r);return s([...t])}function p(t){return i.writes.has(t)}function I(){let t=new Set(d()),o=new Set(l());return s([...new Set([...t,...o])]).map(r=>({id:r,label:e[r].label,extensions:[...e[r].extensions],read:t.has(r),write:o.has(r),lossy:e[r].lossy}))}export{f as a,F as b,d as c,l as d,p as e,I as f};
3
+ import{m as a}from"./chunk-ULX4ZD2Y.js";import{e as i}from"./chunk-7NP76V4U.js";import{d as e}from"./chunk-PNPAHKJR.js";function s(t){let o=Object.keys(e);return[...t].sort((r,n)=>o.indexOf(r)-o.indexOf(n))}function f(t){let o=new Set;for(let r of a)if(r.reads.has(t.format))for(let n of r.writesFor?.(t)??r.writes)e[n].keepsOnly&&n!==t.format||o.add(n);return s([...o])}function F(t){return f(t).map(o=>({id:o,label:e[o].label,hint:e[o].hint,lossy:e[o].lossy}))}function d(){let t=new Set;for(let o of a)for(let r of o.reads)t.add(r);return s([...t])}function l(){let t=new Set;for(let o of a)for(let r of o.writes)t.add(r);return s([...t])}function p(t){return i.writes.has(t)}function I(){let t=new Set(d()),o=new Set(l());return s([...new Set([...t,...o])]).map(r=>({id:r,label:e[r].label,extensions:[...e[r].extensions],read:t.has(r),write:o.has(r),lossy:e[r].lossy}))}export{f as a,F as b,d as c,l as d,p as e,I as f};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{c as ut,d as pt}from"./chunk-BSFBZBAI.js";import{c as ge,d as mt,f as he,g as lt,l as gt}from"./chunk-W6QOV4RP.js";import{c as dt,e as ft}from"./chunk-7NP76V4U.js";import{b as Ue,c as qe,d as Ke,f as Ve,m as W,n as rt,o as st,p as it,q as at,v as ct}from"./chunk-JPASVE56.js";import{n as He,o as Ge,p as le,s as Xe,u as Ye,w as M}from"./chunk-JZM37DG2.js";import{g as ot}from"./chunk-DKHBJ52G.js";import{a as Qe,b as re,c as T,e as Ze,f as je,g as et,h as tt,i as nt}from"./chunk-KXKQDFHX.js";import{a as Ce}from"./chunk-I2LPGKUU.js";import{Aa as Je,C as Ae,Ca as z,E as te,Ea as ze,Fa as We,G as ne,P as De,W as Y,X as me,_ as Te,ca as Be,d as I,i as D,la as Ne,sa as oe,za as Le}from"./chunk-PNPAHKJR.js";import{a as ke}from"./chunk-FGR6QCG5.js";import{c as J}from"./chunk-VLVNA4T3.js";import{mkdtemp as Zt,rm as jt}from"node:fs/promises";import{tmpdir as en}from"node:os";import{join as se}from"node:path";var wt=(e,t,n)=>Ve(e,t,n)===void 0;function ht(e,t,n=Number.POSITIVE_INFINITY,o=[2,4]){return[...o].reverse().find(s=>s<n&&wt(e,t,s))??0}async function tn(e,t,n){if(e.op!=="boost"&&e.op!=="remove-background")throw new Error(`the extension engine cannot ${e.op}`);if(n?.aborted)throw n.reason??new Error("aborted");let o=e.sources[0],s=e.outputs[0],r=e.op,{assetFor:i,catalogEntry:a,offeredHere:d}=await import("./catalog-G44MXIAF.js");if(!d(r,process.platform,process.arch))throw Be(a(r)?.title??r);let{installed:m,extensionsRoot:f}=await import("./paths-BBUKTDDP.js"),w=await m(r);if(!w)throw Te(r);let h=qe(w.version);if(e.op==="boost"){let l=a(r),y=Ke(e.scale,w.version,l&&i(l)?.version);if(y)throw y}if(e.op==="boost"&&!wt(o.width,o.height,e.scale))throw Ne(o.path,ht(o.width,o.height,Number.POSITIVE_INFINITY,h),e.scale);let{runExtension:x}=await import("./run-VJDF5WRF.js"),E=[];o.frames>1&&E.push({code:"animation-flattened",message:`${J(o.path)} has ${o.frames} frames. Only the first frame was used.`});let v=await Zt(se(en(),"forge-ext-"));try{t({phase:"decoding"});let l=se(v,"in.png"),y=se(v,"out.png");await at(o,l);let F=e.op==="boost"?["--in",l,"--out",y,"--scale",String(e.scale),"--cache",se(f(),"boost","cache")]:[l,y],$=e.op==="boost"&&Ue(w.version);await x({...w,serve:$},F,{subject:o.path,what:`${nn(e)} is running on ${J(o.path)}`,onWait:()=>t({phase:"waiting"}),onStart:()=>t({phase:"encoding"}),onProgress:(R,b)=>t({phase:"tiles",done:R,total:b}),...e.op==="boost"?{maxScale:ht(o.width,o.height,e.scale,h)}:{},...n===void 0?{}:{signal:n}});let P=(await re())(y);I[e.target].hasAlpha||(P=P.flatten({background:e.options.background}));let u=await st(P,e.target,e.options.quality).toBuffer();t({phase:"writing"});let g=await it(u,s);return{job:e,outputBytes:g,warnings:E}}catch(l){throw D(l)?l:z(o.path,l)}finally{await jt(v,{recursive:!0,force:!0}).catch(()=>{})}}function nn(e){return e.op!=="boost"?"Remove background":e.scale===1?"Sharpen":`Boost resolution ${e.scale}\xD7`}var bt={id:"extension",reads:new Set,writes:new Set,ops:new Set(["boost","remove-background"]),probe:()=>Promise.reject(new Error("the extension engine reads no files")),run:tn};import{randomBytes as _n}from"node:crypto";import{rm as kn,stat as U}from"node:fs/promises";import{dirname as An,join as Dn}from"node:path";function vt(e){let t=e.trim().split(":");if(t.length===0||t.length>3)return;let n=0;for(let[o,s]of t.entries()){if(!(o===t.length-1?/^\d+(\.\d+)?$/:/^\d+$/).test(s))return;let i=Number(s);if(o>0&&i>=60)return;n=n*60+i}return n}function Ko(e){let t=e.indexOf("-");if(t<0)return;let n=vt(e.slice(0,t)),o=e.slice(t+1).trim(),s=o===""?void 0:vt(o);if(!(n===void 0||o!==""&&s===void 0)&&!(s!==void 0&&s<=n))return{start:n,end:s}}var ie=e=>String(e).padStart(2,"0");function ae(e){let t=Math.round(e*10),n=t%600/10,o=Math.floor(t/600)%60,s=Math.floor(t/36e3),r=n.toFixed(1).padStart(4,"0");return s>0?`${s}:${ie(o)}:${r}`:`${o}:${r}`}function Vo(e){let t=Math.round(e),n=t%60,o=Math.floor(t/60)%60,s=Math.floor(t/3600);return s>0?`${s}:${ie(o)}:${ie(n)}`:`${o}:${ie(n)}`}var on=[1,5,10,30,60,300,600,1800];function Ho(e){return on.filter((t,n)=>n===0||t<=e/4)}function Go(e){return e<60?`${e} s`:`${e/60} min`}var rn=[1920,1280,854],sn=[30,24],an=15,cn=64,dn=32,fn=32,C=e=>Math.max(2,Math.round(e/2)*2);function yt(e,t){let n=e.width>=e.height,o=n?e.width:e.height;if(t>=o)return{width:C(e.width-1),height:C(e.height-1)};let s=t/o;return n?{width:C(t),height:C(e.height*s)}:{width:C(e.width*s),height:C(t)}}function xt(e){let t=Math.max(e.width,e.height),n=[t,...rn.filter(i=>i<t)],o=e.hasAudio?cn:0,s=[];for(let i of n){let{width:a,height:d}=yt(e,i),m=[...new Set([e.fps,...sn].filter(f=>f<=e.fps))];for(let f of m)s.push({width:a,height:d,fps:f,audioKbps:o})}let r=yt(e,n[n.length-1]??t);return s.push({...r,fps:Math.min(an,e.fps),audioKbps:e.hasAudio?fn:0}),s}var Pt=e=>e.width*e.height*e.fps*.02/1e3;function St(e){let t=xt(e),n=t[t.length-1];return n?Math.ceil((Pt(n)+n.audioKbps)*1e3/8/.98*e.duration):0}function Et(e){let t=e.targetBytes*8/e.duration/1e3*.98;for(let n of xt(e)){let o=t-n.audioKbps;if(o>=Pt(n))return{...n,videoKbps:Math.floor(o)}}return{floor:St(e)}}function Ft(e,t={}){let n=e.audio!==void 0&&t.mute!==!0;return e.video&&!t.soundOnly?St({duration:e.duration,width:e.video.width,height:e.video.height,fps:e.video.fps,hasAudio:n}):Math.ceil(dn*1e3/8/.98*e.duration)}var we="%NOISE_FLOOR%",un=["highpass=f=80",`afftdn=nr=12:nf=${we}`],pn="highpass=f=80,astats=measure_perchannel=none:measure_overall=RMS_trough";function Ot(e){let t=/RMS trough dB:\s*(-?[\d.]+|-?inf)/i.exec(e)?.[1],n=t===void 0?Number.NaN:Number(t);return Number.isFinite(n)?Math.min(-30,Math.max(-70,Math.round(n+8))):-50}var be="%LOUDNORM_MEASURED%",mn={mp4:"mp4",hevc:"mp4",mov:"mov",webm:"webm",mkv:"matroska",avi:"avi",gif:"gif",mp3:"mp3",m4a:"ipod",opus:"opus",flac:"flac",wav:"wav",aiff:"aiff",ogg:"ogg"},ln={mp4:["h264","hevc","mpeg4","av1"],mov:["h264","hevc","mpeg4","prores","av1"],mkv:["h264","hevc","mpeg4","vp8","vp9","av1"],hevc:["hevc"],webm:["vp8","vp9","av1"],avi:["mpeg4","h264","mjpeg","msmpeg4v3"]},gn={mp4:["aac","alac","mp3"],hevc:["aac","alac","mp3"],mov:["aac","alac","mp3","pcm_s16le","pcm_s16be","pcm_s24le"],m4a:["aac","alac"],mkv:["aac","mp3","opus","vorbis","flac","ac3","eac3"],webm:["opus","vorbis"],opus:["opus"],mp3:["mp3"],flac:["flac"],wav:["pcm_s16le","pcm_s24le"],aiff:["pcm_s16be","pcm_s24be"],ogg:["vorbis","opus","flac"],avi:["mp3","ac3","aac","pcm_s16le"]},It=[48e3,24e3,16e3,12e3,8e3],hn=[48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3];function wn(e,t){if(e.includes(t))return t;let n=Math.max(...e);return t>n?n:Math.min(...e.filter(o=>o>t))}function bn(e,t,n,o=16){let s=o>16,r={encoder:"opus",kbps:96,args:["-strict","-2"],rates:[48e3]};switch(e){case"webm":return n("libopus")?{encoder:"libopus",kbps:96,rates:It}:n("libvorbis")?{encoder:"libvorbis",kbps:128}:n("opus")?r:{codec:"Opus or Vorbis",encoders:["libopus","libvorbis","opus"],sound:!0};case"opus":return n("libopus")?{encoder:"libopus",kbps:96,rates:It}:n("opus")?r:{codec:"Opus",encoders:["libopus","opus"]};case"mp3":return n("libmp3lame")?{encoder:"libmp3lame",kbps:128}:{codec:"MP3",encoders:["libmp3lame"]};case"flac":return{encoder:"flac"};case"wav":return{encoder:s?"pcm_s24le":"pcm_s16le"};case"aiff":return{encoder:s?"pcm_s24be":"pcm_s16be"};case"ogg":return n("libvorbis")?{encoder:"libvorbis",kbps:128}:{encoder:"vorbis",kbps:128,args:["-strict","-2","-ac","2"]};default:return{encoder:t==="darwin"&&n("aac_at")?"aac_at":"aac",kbps:128,rates:hn}}}var Q=e=>Math.max(2,Math.floor(e/2)*2),vn=e=>String(Math.round(e*1e3)/1e3),yn=e=>String(Math.ceil(e*1e3)/1e3),xn=e=>Math.round(38-(e-1)*20/99),Pn=e=>Math.round(50-(e-1)*30/99),Sn=e=>Math.round(40-(e-1)*18/99),$t=e=>Math.round(20+e*60/100),En=e=>Math.round(31-(e-1)*29/99);function Fn(e,t){let n=.15*2**((18-e)/6);return Math.max(64,Math.round(t*n/1e3))}function In(e,t,n,o,s){let r=e.width,i=e.height;if(n)r=n.width,i=n.height;else{t.crop?.box&&(r=t.crop.box.width,i=t.crop.box.height);let a=t.resize;if(a&&"width"in a){let d=Math.min(a.width,r)/r;r*=d,i*=d}else if(a&&"height"in a){let d=Math.min(a.height,i)/i;r*=d,i*=d}else a&&(r*=a.percent/100,i*=a.percent/100)}return r*i*(o??e.fps*s)}var $n="zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p";function Rt(e){let t=[],n=e;for(;n>2;)t.push("atempo=2"),n/=2;for(;n<.5;)t.push("atempo=0.5"),n/=.5;return t.push(`atempo=${Math.round(n*1e3)/1e3}`),t}var Rn=800,Mn=15,Mt=32;function ve(e){let{facts:t,options:n,target:o,platform:s}=e,r=n.media??{},i=t.video,a=t.audio,d=I[o].media==="sound",m=o==="gif",f=n.compress!==void 0,w=s==="darwin",h=c=>e.has===void 0||e.has.has(c),x=c=>Je(o,c,e.os??s),E=r.cut?.start??0,v=Math.min(r.cut?.end??t.duration,t.duration),l=Math.max(0,v-E),y=r.speed??1,F=l/y,$=i!==void 0&&!d,O=a!==void 0&&!r.mute&&!m,P,u,g,R;if(r.targetBytes!==void 0&&F>0){if($&&i){let c=Et({duration:F,width:i.width,height:i.height,fps:i.fps,hasAudio:O,targetBytes:r.targetBytes});"videoKbps"in c&&(P={width:c.width,height:c.height,fps:c.fps},g=c.videoKbps,u=c.audioKbps)}else if(O){let c=Math.floor(r.targetBytes*8/F/1e3*.98);R=Math.max(Mt,Math.min(320,c))}}let b=[];if($&&i){if(i.hdr&&o!=="hevc"&&h("zscale")&&b.push($n),n.crop?.box){let c=n.crop.box;b.push(`crop=${Q(c.width)}:${Q(c.height)}:${c.left}:${c.top}`)}if(P)b.push(`scale=${P.width}:${P.height}`);else if(n.resize){let c=n.resize;"width"in c?b.push(`scale=trunc(min(${Q(c.width)}\\,iw)/2)*2:-2`):"height"in c?b.push(`scale=-2:trunc(min(${Q(c.height)}\\,ih)/2)*2`):b.push(`scale=trunc(iw*${c.percent/100}/2)*2:-2`)}if(n.rotate&&b.push(n.rotate===90?"transpose=1":n.rotate===270?"transpose=2":"hflip,vflip"),y!==1&&b.push(`setpts=PTS/${y}`),m){let c=Math.min(Rn,Q(i.width));b.push(`fps=${Math.min(Mn,i.fps)},scale=${c}:-2:flags=lanczos,split[s0][s1];[s0]palettegen=stats_mode=diff[p];[s1][p]paletteuse=dither=bayer:bayer_scale=4`)}}let S=P?.fps??r.fps,B=$&&i!==void 0&&b.length===0&&S===void 0&&!f&&r.targetBytes===void 0&&(ln[o]??[]).includes(i.codec),p=[],A=!1;if(!$)p.push("-vn");else if(B)p.push("-c:v","copy");else{if(b.length&&p.push("-vf",b.join(",")),m)p.push("-c:v","gif","-loop","0");else if(o==="webm"){if(!h("libvpx-vp9"))throw x({codec:"VP9",encoders:["libvpx-vp9"]});if(A=g!==void 0,p.push("-c:v","libvpx-vp9","-row-mt","1","-deadline","good","-cpu-used","4"),i?.codec==="gif"&&p.push("-pix_fmt","yuva420p"),g!==void 0)p.push("-b:v",`${g}k`);else{let c=f?Pn(n.quality??60):33;p.push("-crf",String(c),"-b:v","0")}}else if(o==="hevc"){let c=h("libx265"),k=w&&h("hevc_videotoolbox");if(!c&&!k)throw x({codec:"HEVC",encoders:["libx265",...w?["hevc_videotoolbox"]:[]]});if(g!==void 0)c?p.push("-c:v","libx265","-preset","fast","-b:v",`${g}k`):p.push("-c:v","hevc_videotoolbox","-b:v",`${g}k`);else if(k&&(!f||!c)){let X=f?$t(n.quality??60):60;p.push("-c:v","hevc_videotoolbox","-q:v",String(X))}else{let X=f?Sn(n.quality??60):26;p.push("-c:v","libx265","-crf",String(X),"-preset","fast")}p.push("-tag:v","hvc1","-pix_fmt",i?.hdr?"p010le":"yuv420p")}else{let c=f?xn(n.quality??60):21,k=()=>`${g??Fn(c,i?In(i,n,P,S,y):0)}k`;if(g===void 0&&!f&&w&&h("h264_videotoolbox"))p.push("-c:v","h264_videotoolbox","-q:v","65");else if(h("libx264"))A=g!==void 0,g!==void 0?p.push("-c:v","libx264","-preset","medium","-b:v",`${g}k`):f?p.push("-c:v","libx264","-preset","medium","-crf",String(c)):p.push("-c:v","libx264","-preset","veryfast","-crf","21");else if(w&&h("h264_videotoolbox"))g!==void 0?p.push("-c:v","h264_videotoolbox","-b:v",k()):p.push("-c:v","h264_videotoolbox","-q:v",String($t(n.quality??60)));else if(h("libopenh264"))p.push("-c:v","libopenh264","-b:v",k());else if(s==="win32"&&h("h264_mf"))p.push("-c:v","h264_mf","-b:v",k());else if(o==="avi")if(g!==void 0)p.push("-c:v","mpeg4","-b:v",`${g}k`);else{let X=f?En(n.quality??60):3;p.push("-c:v","mpeg4","-q:v",String(X))}else throw x({codec:"H.264",encoders:["libx264",...w?["h264_videotoolbox"]:[],"libopenh264",...s==="win32"?["h264_mf"]:[]]});p.push("-pix_fmt","yuv420p")}S!==void 0?p.push("-r",String(S)):o==="avi"?p.push("-fps_mode","cfr"):m||p.push("-fps_mode","passthrough")}let Ie=r.cleanup?[...un]:[],ee=[...Ie,...y!==1?Rt(y):[]],N=r.loudness;N!==void 0&&ee.push(`loudnorm=I=${N}:TP=-1.5:LRA=11:${be}:linear=true`);let $e=r.bitrate??u??R,Re=O&&a!==void 0&&ee.length===0&&$e===void 0&&!(f&&d)&&(gn[o]??[]).includes(a.codec),_=[];if(!O)_.push("-an");else if(Re)_.push("-c:a","copy");else{ee.length&&_.push("-af",ee.join(","));let c=bn(o,s,h,a?.bits);if("codec"in c)throw x(c);_.push("-c:a",c.encoder);let k=$e??c.kbps;k!==void 0&&c.kbps!==void 0&&_.push("-b:a",`${k}k`),c.args&&_.push(...c.args),!c.args?.includes("-ac")&&u!==void 0&&u<=Mt&&_.push("-ac","1"),a&&(N!==void 0||c.rates&&!c.rates.includes(a.sampleRate))&&_.push("-ar",String(c.rates?wn(c.rates,a.sampleRate):a.sampleRate))}let fe=[];E>0&&fe.push("-ss",yn(E)),r.cut&&fe.push("-t",vn(l));let H=[...fe,"-i",e.input],G=[],ue=[...$?["-map","0:v:0"]:[],...O?["-map","0:a:0"]:[]],Me=n.keepMetadata?[]:["-map_metadata","-1"],Qt=mn[o]??o,Oe=["mp4","hevc","mov","m4a"].includes(o)?["-movflags","+faststart"]:[],_e=["-f",Qt,"-y",e.output],pe=s==="win32"?"NUL":"/dev/null",L=[];return r.cleanup&&L.push({args:[...H,...G,"-vn","-af",pn,"-f","null",pe],measures:"noise"}),N!==void 0&&L.push({args:[...H,...G,"-vn","-af",`${[...Ie,...y!==1?Rt(y):[]].map(c=>`${c},`).join("")}loudnorm=I=${N}:TP=-1.5:LRA=11:print_format=json`,"-f","null",pe],measures:"loudness",pass:{at:1,of:2}}),A?(L.push({args:[...H,...G,...ue.slice(0,2),...p,"-pass","1","-passlogfile",e.passlog,"-an","-f","null",pe],pass:{at:1,of:2}}),L.push({args:[...H,...G,...ue,...p,"-pass","2","-passlogfile",e.passlog,..._,...Me,...Oe,..._e],pass:{at:2,of:2}})):L.push({args:[...H,...G,...ue,...p,..._,...Me,...Oe,..._e],...N!==void 0?{pass:{at:2,of:2}}:{}}),{steps:L,duration:F,copies:{video:B,audio:Re},...P?{fitted:P}:{}}}var Tn=["mp4","mov","webm","mkv","avi","gif"],kt=["mp4","mov","hevc","webm","mkv","avi","gif","mp3","m4a","wav"],Bn=["mp3","m4a","wav","aiff","flac","opus","ogg"],Nn=["mp3","m4a","opus","flac","aiff","wav"];function Ln(e){return W(e,64)}function Jn(e,t){return t&&!t.video&&(e==="mp4"||e==="mov")?"m4a":e}async function At(e,t){let n=rt(await Ln(e));if(!n)throw new Error("not video or sound");if(n!=="mp4"&&n!=="mov"&&I[n].media!==t)throw new Error(`not ${t}`);let o=(await U(e)).size,s=await ge(),r;if(s){try{r=await he(e,s)}catch(a){throw te(e,a)}if(r.duration<=0||!r.video&&!r.audio)throw te(e,r)}let i=Jn(n,r);if(I[i].media!==t)throw new Error(`not ${t}`);return{kind:"media",path:e,format:i,bytes:o,...r?{facts:r}:{}}}async function zn(){let{assetFor:e,catalogEntry:t}=await import("./catalog-G44MXIAF.js"),n=t("video");return n!==void 0&&e(n)!==void 0}async function Wn(e,t){if(e.kind==="media"&&e.facts)return e.facts;try{return await he(e.path,t)}catch(n){throw te(e.path,n)}}function Cn(e,t){let n=e.options.media??{},o=n.cut?.start??0,s=Math.min(n.cut?.end??t,t);return Math.max(0,s-o)/(n.speed??1)}function Dt(e,t){if(e.op!=="convert")return;let n=e.sources[0],o=n.kind==="media"?n.facts:void 0;if(!o)return;let s=e.options.media??{},r=Ft({...o,duration:Cn(e,o.duration)},{soundOnly:I[e.target].media==="sound",mute:s.mute===!0||e.target==="gif"});return t<r?{floor:r}:void 0}function Un(e){let t=e.slice(e.lastIndexOf("{"),e.lastIndexOf("}")+1),n=JSON.parse(t);return[`measured_I=${n.input_i}`,`measured_TP=${n.input_tp}`,`measured_LRA=${n.input_lra}`,`measured_thresh=${n.input_thresh}`,`offset=${n.target_offset}`].join(":")}async function _t(e){await Promise.all(e.map(t=>kn(t,{force:!0}).catch(()=>{})));for(let t of e)le(t)}async function Tt(e,t,n){if(e.op!=="convert")throw new Error(`media engines only convert, not ${e.op}`);if(n?.aborted)throw n.reason??new Error("aborted");let o=e.sources[0],s=e.outputs[0],r=await ge();if(!r)throw Le(o.path,process.platform,await zn());let i=await Wn(o,r),a=e.options.media;if((a?.cleanup||a?.loudness!==void 0)&&!i.audio)throw ze(o.path);let d=await U(o.path).catch(()=>{}),m=_n(6).toString("hex"),f=He(s,m),w=Dn(An(s),`.forge-pass-${m}`),h=[f,`${w}-0.log`,`${w}-0.log.temp`,`${w}-0.log.mbtree`,`${w}-0.log.mbtree.temp`],x=[],E=(u,g=e.options)=>ve({input:o.path,output:f,target:e.target,facts:i,options:g,platform:u,os:process.platform,passlog:w,...r.has?{has:r.has}:{}}),v=e.options,l=E(process.platform);if(l.duration<=0)throw De(o.path,ae(i.duration));await Xe(s);let y=process.platform,F=v.media?.cut;if(l.copies.video&&F&&F.start>0){let u=await lt(o.path,F.start,r);u!==void 0&&F.start-u>.05&&(v={...v,media:{...v.media,cut:{...F,start:u}}},l=E(process.platform,v),x.push({code:"media-cut-keyframe",message:`It starts at ${ae(u)}, the keyframe just before ${ae(F.start)}.`}))}let $=0,O=async u=>{let g=$,R="",b="";for(let S of u.steps){let B=S.args.map(A=>A.replace(be,R).replace(we,b)),p=await gt(B,{tools:r,signal:n,report:S.measures!==void 0,onTime:A=>t({phase:"time",done:Math.min(A,u.duration),total:u.duration,...S.pass?{pass:{at:g+S.pass.at,of:g+S.pass.of}}:{}})});S.measures==="loudness"&&(R=Un(p)),S.measures==="noise"&&(b=String(Ot(p)))}$=g+Math.max(0,...u.steps.map(S=>S.pass?.of??0))};for(let u of h)Ge(u);try{try{await O(l)}catch(b){if(n?.aborted||!l.steps.some(S=>S.args.some(B=>B.endsWith("_videotoolbox"))))throw b;y="linux",l=E(y,v),$=0,await O(l)}let u=v.media?.targetBytes;for(let b of[.95,.9]){if(u===void 0||(await U(f)).size<=u)break;v={...v,media:{...v.media,targetBytes:Math.floor(u*b)}},l=E(y,v),await O(l)}let g=(await U(f)).size;if(u!==void 0&&g>u)throw Ae(o,e.options.media?.targetBytes??u,g);if(e.options.compress!==void 0&&g>=o.bytes)throw oe(o.path,o.bytes,g);let R=await U(o.path).catch(()=>{});if(d&&R&&(R.size!==d.size||R.mtimeMs!==d.mtimeMs))throw We(o.path);await Ye(f,s),le(f)}catch(u){throw await _t(h),n?.aborted||D(u)?u:z(o.path,u,o.format)}await _t(h.slice(1));let P=i.video;if(l.fitted&&P&&(l.fitted.width<P.width-2||l.fitted.fps<P.fps)){let u=ke(e.options.media?.targetBytes??0);x.push({code:"media-fitted",message:`To fit ${u} it is now ${l.fitted.width}\xD7${l.fitted.height} at ${l.fitted.fps} fps.`})}return{job:e,outputBytes:(await U(s)).size,warnings:x}}function lr(e,t){if(e.kind!=="media"||!e.facts)return;let n=mt()?.has;if(n)try{ve({input:e.path,output:e.path,target:t,facts:e.facts,options:{background:"#ffffff",keepMetadata:!1},platform:process.platform,passlog:"",has:n});return}catch(o){return D(o)&&o.code==="encoder-missing"?o:void 0}}var Z=e=>new Set(e);function qn(e){let t=e.kind==="media"?e.facts:void 0,n=e.kind==="image"||t!==void 0&&t.audio===void 0;return Z(kt.filter(o=>!(n&&I[o].media==="sound"||o==="hevc"&&t?.video?.codec==="hevc")))}var Bt={id:"video",reads:Z(Tn),writes:Z(kt),ops:new Set(["convert"]),probe:e=>At(e,"video"),alone:!0,run:Tt,sizeTo:Dt,writesFor:qn},Nt={id:"sound",reads:Z(Bn),writes:Z(Nn),ops:new Set(["convert"]),probe:e=>At(e,"sound"),alone:!0,run:Tt,sizeTo:Dt};import{readFile as ce,rm as Wt,stat as Kn}from"node:fs/promises";function wr(e,t){let n=e.split(",").map(r=>r.trim()).filter(r=>r!=="");if(n.length===0)throw Y(e,"That selects no pages.",t);let o=new Set,s=(r,i)=>{if(!Number.isInteger(r)||r<1||r>t)throw Y(i,`'${i}' is outside 1 and ${t}.`,t);return r};for(let r of n){let i=r.match(/^(\d+)\s*-\s*(\d*)$/);if(i?.[1]!==void 0){let a=s(Number(i[1]),r),d=i[2]===""?t:s(Number(i[2]),r);if(d<a)throw Y(r,`'${r}' ends before it starts.`,t);for(let m=a;m<=d;m++)o.add(m-1);continue}if(!/^\d+$/.test(r))throw Y(r,`'${r}' is not a page number.`,t);o.add(s(Number(r),r)-1)}return[...o].sort((r,i)=>r-i)}function Lt(e){return[...new Set(e)].sort((t,n)=>t-n)}function br(e){if(e.length===0)return"";let t=[...new Set(e)].sort((r,i)=>r-i),n=[],o=t[0],s=o;for(let r of t.slice(1)){if(r===s+1){s=r;continue}n.push(o===s?`${o+1}`:`${o+1}-${s+1}`),o=r,s=r}return n.push(o===s?`${o+1}`:`${o+1}-${s+1}`),n.join(", ")}function Jt(e,t){let n=[...new Set(e)].sort((r,i)=>r-i).filter(r=>r>=0&&r<t-1),o=[],s=0;for(let r of n)o.push({from:s,to:r}),s=r+1;return o.push({from:s,to:t-1}),o}var xe=Qe(()=>import("./pdf-compress-U2E3CNXG.js")),Vn=new Set(["pdf","jpeg","png","webp","avif","gif","tiff","heic","raw"]),Hn=new Set(["pdf"]);async function q(e){return(await T()).PDFDocument.load(await ce(e),{ignoreEncryption:!0})}var Gn=1024,zt=Buffer.from("%PDF-","latin1");async function Xn(e){return(await W(e,Gn+zt.length)).indexOf(zt)!==-1}async function Yn(e){if(!await Xn(e))throw new Error(`${e} is not a PDF`);let{surveyDocument:t}=await xe(),n=await q(e),{size:o}=await Kn(e);return{kind:"document",path:e,format:"pdf",bytes:o,pages:n.getPageCount(),encrypted:n.isEncrypted,images:t(n)}}function K(e){for(let t of e)if(t.encrypted)throw ne(t.path)}async function Ct(e,t,n){let o=await re(),s=t.format==="jpeg"||t.format==="png",r=s?(await o(n).metadata()).orientation:void 0;if(s&&(r===void 0||r===1))return t.format==="jpeg"?e.embedJpg(n):e.embedPng(n);if(t.format==="jpeg"){let i=await o(n).rotate().jpeg({quality:I.jpeg.defaultQuality,mozjpeg:!0}).toBuffer();return e.embedJpg(i)}return e.embedPng(await o(n).rotate().png().toBuffer())}async function Ut(e){let t=await ot(e.path,e.format);return typeof t=="string"?ce(t):t}async function Qn(e,t){let n=e.sources[0];if(n.kind!=="image")throw new Error("the pdf engine cannot embed a document source");let o=[];n.frames>1&&o.push({code:"animation-flattened",message:`${J(n.path)} has ${n.frames} frames, and ${I.pdf.label} cannot animate. Only the first frame was converted.`}),t({phase:"reading"});let s=await Ut(n);t({phase:"encoding"});let i=await(await T()).PDFDocument.create(),a=await Ct(i,n,s);i.addPage([a.width,a.height]).drawImage(a,{x:0,y:0,width:a.width,height:a.height}),t({phase:"writing"});let m=await M(e.outputs[0],await i.save());return{job:e,outputBytes:m,warnings:o}}async function Zn(e,t){K(e.sources.filter(a=>a.kind==="document"));let o=await(await T()).PDFDocument.create(),s=[];for(let a of e.sources){if(t({phase:"reading"}),a.kind==="image"){a.frames>1&&s.push({code:"animation-flattened",message:`${J(a.path)} has ${a.frames} frames, and ${I.pdf.label} cannot animate. Only the first frame was merged.`});let f=await Ct(o,a,await Ut(a));o.addPage([f.width,f.height]).drawImage(f,{x:0,y:0,width:f.width,height:f.height});continue}let d=await q(a.path),m=await o.copyPages(d,d.getPageIndices());for(let f of m)o.addPage(f)}t({phase:"writing"});let r=await o.save(),i=await M(e.outputs[0],r);return{job:e,outputBytes:i,warnings:s}}async function jn(e,t){let n=e.sources[0];K([n]);let o=await T();t({phase:"reading"});let s=await q(n.path),r=Jt(e.cuts,s.getPageCount()),i=[],a=0;try{for(let[d,m]of r.entries()){let f=await o.PDFDocument.create(),w=Array.from({length:m.to-m.from+1},(E,v)=>m.from+v),h=await f.copyPages(s,w);for(let E of h)f.addPage(E);let x=e.outputs[d];if(x===void 0)throw new Error(`split produced ${r.length} parts but was given ${e.outputs.length} outputs`);a+=await M(x,await f.save()),i.push(x),t({phase:"page",done:d+1,total:r.length})}}catch(d){throw await Promise.all(i.map(m=>Wt(m,{force:!0}))),d}return{job:e,outputBytes:a,warnings:[]}}async function ye(e,t){let o=await(await T()).PDFDocument.create(),s=await o.copyPages(e,t);for(let r of s)o.addPage(r);return o.save()}async function eo(e,t){let n=e.sources[0];if(K([n]),e.pages.length===0)throw me("That extract selects no pages.");t({phase:"reading"});let o=await q(n.path),s=Lt(e.pages),r=[],i=0;try{if(e.separate)for(let[a,d]of s.entries()){let m=e.outputs[a];i+=await M(m,await ye(o,[d])),r.push(m),t({phase:"page",done:a+1,total:s.length})}else{t({phase:"writing"});let a=e.outputs[0];i=await M(a,await ye(o,s)),r.push(a)}}catch(a){throw await Promise.all(r.map(d=>Wt(d,{force:!0}))),a}return{job:e,outputBytes:i,warnings:[]}}async function to(e,t){let n=e.sources[0];K([n]),t({phase:"reading"});let o=await q(n.path),s=new Set(e.pages),r=o.getPageIndices().filter(a=>!s.has(a));if(r.length===0)throw me("That would delete every page.");t({phase:"writing"});let i=await M(e.outputs[0],await ye(o,r));return{job:e,outputBytes:i,warnings:[]}}async function no(e,t){let n=e.sources[0];K([n]);let o=await T();t({phase:"reading"});let s=await q(n.path);for(let i of s.getPages()){let d=((i.getRotation().angle+e.turns*90)%360+360)%360;i.setRotation(o.degrees(d))}t({phase:"writing"});let r=await M(e.outputs[0],await s.save());return{job:e,outputBytes:r,warnings:[]}}async function oo(e,t){let n=e.sources[0];K([n]);let{compressPdf:o}=await xe();t({phase:"reading"});let s=await ce(n.path);t({phase:"encoding"});let{bytes:r,recompressed:i,skipped:a,fromDpi:d,toDpi:m}=await o(s,{quality:e.options.quality??60,dpi:e.options.dpi??150});if(e.options.compress&&r.length>=n.bytes)throw oe(n.path,n.bytes,r.length);t({phase:"writing"});let f=await M(e.outputs[0],r),w=x=>x===1?"":"s",h=[];return i===0&&a===0?h.push({code:"pdf-no-images",message:"This PDF has no images to re-encode, so its size is almost unchanged."}):i===0?h.push({code:"pdf-no-images",message:`None of its ${a} image${w(a)} could be re-encoded \u2014 they are not JPEG data.`}):a>0&&h.push({code:"pdf-images-skipped",message:`${i} image${w(i)} recompressed, ${a} skipped (not JPEG).`}),d!==void 0&&m!==void 0&&h.push({code:"pdf-downsampled",message:`Images reduced from ${d} to ${m} dpi. Pass --dpi ${d} to keep them.`}),{job:e,outputBytes:f,warnings:h}}async function ro(e){if(e.op!=="convert")return;let t=e.sources[0];if(t.kind!=="document")return;let{compressPdf:n}=await xe(),o=await ce(t.path);return{ladder:[e.options.dpi??150,120,96,72].map(s=>({dpi:s})),measure:async s=>(await n(o,{quality:s.quality??60,...s.dpi===void 0?{}:{dpi:s.dpi}})).bytes.byteLength}}var qt={id:"pdf",measurer:ro,reads:Vn,writes:Hn,ops:new Set(["convert","merge","split","extract","delete","rotate"]),probe:Yn,async run(e,t){switch(e.op){case"convert":if(e.target!=="pdf")throw new Error("the pdf engine only converts to pdf");return e.sources[0].kind==="document"?oo(e,t):Qn(e,t);case"merge":return Zn(e,t);case"split":return jn(e,t);case"extract":return eo(e,t);case"delete":return to(e,t);case"rotate":return no(e,t);default:throw new Error(`the pdf engine cannot ${e.op}`)}}};import{execFile as so}from"node:child_process";import{mkdtemp as io,readFile as Ee,rm as ao}from"node:fs/promises";import{tmpdir as co}from"node:os";import{basename as Gt,extname as Xt,join as Kt,win32 as Pe}from"node:path";import{pathToFileURL as fo}from"node:url";import{promisify as uo}from"node:util";var Se=uo(so),V=Buffer.from([208,207,17,224,161,177,26,225]);async function po(e){if(e.length<V.length||!e.subarray(0,V.length).equals(V))return!1;let t=await tt();try{return t.find(t.parse(e),"WordDocument")!==null}catch{return!1}}async function mo(e){let t=await et();try{let n=new t(e);if(!n.getEntry("word/document.xml"))return;let o=0,s=n.getEntry("docProps/app.xml");if(s){let r=/<Pages>(\d+)<\/Pages>/.exec(n.readAsText(s));r?.[1]&&(o=Number(r[1]))}return{pages:o}}catch{return}}var Vt=Buffer.from([80,75,3,4]);async function lo(e){let t=await W(e,V.length);return t.subarray(0,Vt.length).equals(Vt)||t.subarray(0,V.length).equals(V)}async function go(e){if(!await lo(e))throw new Error(`${e} is not a Word document`);let t=await Ee(e),n=await mo(t);if(n)return{kind:"document",path:e,format:"docx",bytes:t.byteLength,pages:n.pages,encrypted:!1};if(await po(t))return{kind:"document",path:e,format:"doc",bytes:t.byteLength,pages:0,encrypted:!1};throw new Error(`${e} is not a Word document`)}function ho(e,t){return e==="win32"?[Pe.join(t.ProgramFiles??"C:\\Program Files","LibreOffice","program","soffice.exe"),Pe.join(t["ProgramFiles(x86)"]??"C:\\Program Files (x86)","LibreOffice","program","soffice.exe")]:["/Applications/LibreOffice.app/Contents/MacOS/soffice"]}var wo=0;async function bo(){wo++;try{return await Se("soffice",["--version"],{timeout:5e3}),"soffice"}catch{}for(let e of ho(process.platform,process.env))try{return await Se(e,["--version"],{timeout:5e3}),e}catch{}}var Ht,vo=!1,yo;async function xo(){return vo?yo:(Ht??=bo(),Ht)}var Fe="\f";function de(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)}async function Po(e){if(e.format==="docx"){let n=await Ze(),{value:o}=await n.extractRawText({path:e.path});return de(o)}if(e.format==="doc"){let n=await je(),s=await new n().extract(e.path);return de(s.getBody())}return(await dt(await Ee(e.path))).flatMap((n,o)=>o===0?de(n):[Fe,...de(n)])}var So={width:612,height:792,margin:54};async function Eo(e,t={}){let n=[[]];for(let o of e)o===Fe?n.push([]):n.at(-1)?.push({kind:"paragraph",text:o});return pt(n,{title:t.title??"",paper:So,...t.fonts?{fonts:t.fonts}:{},...t.onMissing?{onMissing:t.onMissing}:{}})}async function Fo(e){let{Document:t,Packer:n,PageBreak:o,Paragraph:s}=await nt(),r=e.map(a=>a===Fe?new s({children:[new o]}):new s(Ce(a))),i=new t({sections:[{children:r}]});return n.toBuffer(i)}var Io=new Set(["docx","doc","pdf"]),$o=new Set(["docx","pdf"]),Ro=new Set(["convert"]),Mo={code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice for full-fidelity conversion: brew install --cask libreoffice"};function Oo(e=process.platform){return e==="linux"?{code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice for full-fidelity conversion: sudo apt install libreoffice"}:e!=="win32"?Mo:{code:"word-basic-fidelity",message:"Converted with basic formatting only \u2014 tables, images, and complex layouts weren't preserved. Install LibreOffice from libreoffice.org for full-fidelity conversion."}}function _o(e,t,n,o=process.platform){return[`-env:UserInstallation=${o==="win32"?fo(Pe.join(e,"profile"),{windows:!0}).href:`file://${e}/profile`}`,"--headless","--convert-to",n,"--outdir",e,t]}async function ko(e,t,n){let o=await io(Kt(co(),"forge-word-"));try{await Se(e,_o(o,t,n),{timeout:12e4});let s=Gt(t,Xt(t));return await Ee(Kt(o,`${s}.${n}`))}finally{await ao(o,{recursive:!0,force:!0})}}async function Ao(e,t){if(e.op!=="convert")throw new Error(`the word engine cannot ${e.op}`);let n=e.sources[0];if(n.kind!=="document")throw new Error("the word engine can only convert a document source");if(n.encrypted)throw ne(n.path);t({phase:"reading"});let o=await xo();t({phase:"encoding"});let s=[],r;try{if(o!==void 0)r=await ko(o,n.path,e.target);else{let a=await Po(n);r=e.target==="pdf"?await Eo(a,{title:Gt(n.path,Xt(n.path)),onMissing:d=>s.push(ut(d))}):await Fo(a),s.push(Oo())}}catch(a){throw z(n.path,a)}t({phase:"writing"});let i=await M(e.outputs[0],r);return{job:e,outputBytes:i,warnings:s}}var Yt={id:"word",reads:Io,writes:$o,ops:Ro,probe:go,run:Ao};var j=[ct,Bt,Nt,qt,Yt,bt,ft];function Qr(e){return j.find(t=>t.reads.has(e))}function Zr(e){return j.find(t=>t.writes.has(e))}function jr(e){if(e.op==="convert"){let t=e.sources[0].format;return j.find(n=>n.reads.has(t)&&n.writes.has(e.target))}return j.find(t=>t.ops.has(e.op))}async function es(e){let t;for(let n of j)try{return await n.probe(e)}catch(o){D(t)||(t=o)}throw t}export{vt as a,Ko as b,ae as c,Vo as d,Ho as e,Go as f,Ft as g,wr as h,Lt as i,br as j,Jt as k,lr as l,j as m,Qr as n,Zr as o,jr as p,es as q};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __forgeCreateRequire } from 'node:module';
2
2
  const require = __forgeCreateRequire(import.meta.url);
3
3
  import{a as F}from"./chunk-PON65UTS.js";import{execFile as K,spawn as O}from"node:child_process";import{access as T,constants as C}from"node:fs/promises";import{dirname as $,join as L}from"node:path";import{promisify as D}from"node:util";function N(e){let[t,r]=(e??"").split("/").map(Number);return!t||!r?0:Math.round(t/r*100)/100}function I(e){let t=e.side_data_list?.find(n=>typeof n.rotation=="number")?.rotation,r=t!==void 0?-t:Number(e.tags?.rotate??0);return(Math.round(r/90)*90%360+360)%360}function A(e){let t=e,r=t.streams??[],n=r.find(o=>o.codec_type==="video"&&o.disposition?.attached_pic!==1),i=r.find(o=>o.codec_type==="audio"),s={duration:Number(t.format?.duration)||Math.max(0,...r.map(o=>Number(o.duration)||0))};if(n){let o=I(n),d=o===90||o===270,a=n.width??0,u=n.height??0;s.video={codec:n.codec_name??"",width:d?u:a,height:d?a:u,fps:N(n.avg_frame_rate)||N(n.r_frame_rate),rotation:o,hdr:n.color_transfer==="arib-std-b67"||n.color_transfer==="smpte2084"}}if(i){s.audio={codec:i.codec_name??"",channels:i.channels??0,sampleRate:Number(i.sample_rate)||0};let o=Number(i.bits_per_raw_sample)||i.bits_per_sample||0;o>0&&(s.audio.bits=o)}return s}var y=D(K);function G(e,t){let r=t.PATH??t.Path??"",n=e==="win32"?";":":",i=r.split(n).filter(Boolean);return e==="darwin"&&i.push("/opt/homebrew/bin","/usr/local/bin"),[...new Set(i)]}var k=e=>process.platform==="win32"?`${e}.exe`:e;async function B(e){try{return await T(e,C.X_OK),!0}catch{return!1}}function J(e){let t=new Set;for(let r of e.split(`
4
- `)){let n=r.match(/^\s*[A-Z.|]{3,6}\s+(\S+)\s/);n?.[1]&&n[1]!=="="&&t.add(n[1])}return t}async function j(){try{let{installed:e}=await import("./paths-6OENILJ4.js");return(await e("video"))?.dir}catch{return}}async function q(){try{let{chosenPath:e}=await import("./own-5BD5BVE7.js"),t=await e("video");return t===void 0?void 0:$(t)}catch{return}}async function H(){try{let{removeForgeCopy:e}=await import("./own-5BD5BVE7.js");await e("video")}catch{}}async function V(){let e=await j(),t=await q(),r=[...t?[t]:[],...G(process.platform,process.env),...e?[e]:[]];for(let n of r){let i=L(n,k("ffmpeg")),f=L(n,k("ffprobe"));if(!await B(i)||!await B(f))continue;try{await y(i,["-hide_banner","-version"],{timeout:5e3})}catch{continue}let[s,o]=await Promise.all(["-encoders","-filters"].map(a=>y(i,["-hide_banner",a],{timeout:5e3,maxBuffer:4<<20}).then(({stdout:u})=>J(u)).catch(()=>{}))),d=s&&o?new Set([...s,...o]):void 0;return e!==void 0&&n!==e&&await H(),{ffmpeg:i,ffprobe:f,...d?{has:d}:{}}}}var h,w=null,P;function v(){return w?Promise.resolve(w.value):(h=(h??V()).then(t=>(t||(h=void 0),P=t,t)),h)}function oe(){return w?w.value:P}function ie(e){w=e===null?null:{value:e},h=void 0,P=void 0}async function se(e,t){let r=t??await v();if(!r)throw new Error("ffmpeg is not installed");let{stdout:n}=await y(r.ffprobe,["-v","error","-print_format","json","-show_format","-show_streams",e],{timeout:3e4,maxBuffer:16*1024*1024});return A(JSON.parse(n))}async function ae(e,t,r){let n=r??await v();if(!n)return;let i=async f=>{let{stdout:s}=await y(n.ffprobe,["-v","error","-select_streams","v:0","-show_packets","-show_entries","packet=pts_time,dts_time,flags","-of","csv=p=0","-read_intervals",`${f}%${t+.01}`,e],{timeout:3e4,maxBuffer:16777216});return X(s).filter(o=>o<=t+.001)};try{let f=Math.max(0,t-15),s=await i(f);return!s.length&&f>0&&(s=await i(0)),s.length?Math.max(...s):void 0}catch{return}}function X(e){let t=[];for(let r of e.split(`
4
+ `)){let n=r.match(/^\s*[A-Z.|]{3,6}\s+(\S+)\s/);n?.[1]&&n[1]!=="="&&t.add(n[1])}return t}async function j(){try{let{installed:e}=await import("./paths-BBUKTDDP.js");return(await e("video"))?.dir}catch{return}}async function q(){try{let{chosenPath:e}=await import("./own-KUGTZ3BV.js"),t=await e("video");return t===void 0?void 0:$(t)}catch{return}}async function H(){try{let{removeForgeCopy:e}=await import("./own-KUGTZ3BV.js");await e("video")}catch{}}async function V(){let e=await j(),t=await q(),r=[...t?[t]:[],...G(process.platform,process.env),...e?[e]:[]];for(let n of r){let i=L(n,k("ffmpeg")),f=L(n,k("ffprobe"));if(!await B(i)||!await B(f))continue;try{await y(i,["-hide_banner","-version"],{timeout:5e3})}catch{continue}let[s,o]=await Promise.all(["-encoders","-filters"].map(a=>y(i,["-hide_banner",a],{timeout:5e3,maxBuffer:4<<20}).then(({stdout:u})=>J(u)).catch(()=>{}))),d=s&&o?new Set([...s,...o]):void 0;return e!==void 0&&n!==e&&await H(),{ffmpeg:i,ffprobe:f,...d?{has:d}:{}}}}var h,w=null,P;function v(){return w?Promise.resolve(w.value):(h=(h??V()).then(t=>(t||(h=void 0),P=t,t)),h)}function oe(){return w?w.value:P}function ie(e){w=e===null?null:{value:e},h=void 0,P=void 0}async function se(e,t){let r=t??await v();if(!r)throw new Error("ffmpeg is not installed");let{stdout:n}=await y(r.ffprobe,["-v","error","-print_format","json","-show_format","-show_streams",e],{timeout:3e4,maxBuffer:16*1024*1024});return A(JSON.parse(n))}async function ae(e,t,r){let n=r??await v();if(!n)return;let i=async f=>{let{stdout:s}=await y(n.ffprobe,["-v","error","-select_streams","v:0","-show_packets","-show_entries","packet=pts_time,dts_time,flags","-of","csv=p=0","-read_intervals",`${f}%${t+.01}`,e],{timeout:3e4,maxBuffer:16777216});return X(s).filter(o=>o<=t+.001)};try{let f=Math.max(0,t-15),s=await i(f);return!s.length&&f>0&&(s=await i(0)),s.length?Math.max(...s):void 0}catch{return}}function X(e){let t=[];for(let r of e.split(`
5
5
  `)){let[n,i,f]=r.split(",");if(!f?.includes("K"))continue;let s=Number.parseFloat(n??""),o=Number.isFinite(s)?s:Number.parseFloat(i??"");Number.isFinite(o)&&t.push(o)}return t}var R=4e3;async function fe(e,t,r,n={}){let i=n.tools??await v();if(!i)return null;let f=Math.max(1,Math.round(t*R)),s=Math.max(1,Math.ceil(f/r)),o=new Array(r).fill(0),d=0,a=Buffer.alloc(0);if(!await new Promise((p,c)=>{let m=F(O(i.ffmpeg,["-hide_banner","-nostdin","-loglevel","error","-i",e,"-map","0:a:0","-ac","1","-ar",String(R),"-f","s16le","-"],{stdio:["ignore","pipe","pipe"]})),b=()=>m.kill("SIGKILL");n.signal?.addEventListener("abort",b,{once:!0}),m.stdout.on("data",l=>{let _=a.length?Buffer.concat([a,l]):l,M=_.length-_.length%2;for(let x=0;x<M;x+=2){let E=Math.abs(_.readInt16LE(x)),S=Math.min(r-1,Math.floor(d/s));E>(o[S]??0)&&(o[S]=E),d++}a=_.subarray(M)}),m.stderr.resume(),m.on("error",c),m.on("close",l=>{n.signal?.removeEventListener("abort",b),n.signal?.aborted?c(n.signal.reason??new Error("aborted")):p(l===0&&d>0)})}))return null;let g=Math.max(1,...o);return o.map(p=>Math.sqrt(p/g))}async function de(e,t,r,n){await Q(["-ss",String(Math.max(0,t)),"-i",e,"-frames:v","1","-y",r],{tools:n})}function Z(e){let t;for(let r of e.matchAll(/out_time_us=(\d+)/g))t=Number(r[1])/1e6;return t}var z=4e3;async function Q(e,t={}){let{signal:r,onTime:n}=t;if(r?.aborted)throw r.reason??new Error("aborted");let i=t.tools??await v();if(!i)throw new Error("ffmpeg is not installed");let s=["-hide_banner","-nostdin","-loglevel",t.report?"info":"error","-progress","pipe:1","-nostats",...e];return new Promise((o,d)=>{let a=F(O(i.ffmpeg,s,{stdio:["ignore","pipe","pipe"]})),u="",g=()=>a.kill("SIGKILL");r?.addEventListener("abort",g,{once:!0}),a.stdout.setEncoding("utf8");let p="";a.stdout.on("data",c=>{let m=p+c,b=m.lastIndexOf(`
6
6
  `);p=m.slice(b+1);let l=Z(m.slice(0,b+1));l!==void 0&&n?.(l)}),a.stderr.setEncoding("utf8"),a.stderr.on("data",c=>{u=(u+c).slice(-z)}),a.on("error",c=>{r?.removeEventListener("abort",g),d(c)}),a.on("close",c=>{r?.removeEventListener("abort",g),r?.aborted?d(r.reason??new Error("aborted")):c===0?o(u):d(new Error(u.trim()||`ffmpeg exited with ${c}`))})})}export{G as a,J as b,v as c,oe as d,ie as e,se as f,ae as g,X as h,fe as i,de as j,Z as k,Q as l};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{q as h}from"./chunk-ULX4ZD2Y.js";import{g as l}from"./chunk-DKHBJ52G.js";import{b as c}from"./chunk-KXKQDFHX.js";import{E as p,d as s,i as m,q as n,s as f}from"./chunk-PNPAHKJR.js";async function x(r,i=192){let t=await h(r);if(t.kind!=="image")throw f(r,n(s[t.format].label));let u=await l(r,t.format);try{let e=await c(),{data:o,info:a}=await e(u,{animated:!1}).rotate().resize(i,i,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0});return{source:t,pixels:{width:a.width,height:a.height,rgba:new Uint8Array(o.buffer,o.byteOffset,o.length)}}}catch(e){throw m(e)?e:p(r,e)}}export{x as a};