forge-terminal 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/chunks/about-credits-U3MMRRXR.js +4 -0
- package/dist/chunks/{boot-ISMRSTLL.js → boot-FBULFF7S.js} +1 -1
- package/dist/chunks/{check-DN7SEN44.js → check-BRP6EKSA.js} +1 -1
- package/dist/chunks/{chunk-OIZCRBLT.js → chunk-32VJ2RDH.js} +1 -1
- package/dist/chunks/{chunk-VNAIHACR.js → chunk-3GVFOZ7M.js} +1 -1
- package/dist/chunks/{chunk-W42HVOBD.js → chunk-4QQEJ6YG.js} +1 -1
- package/dist/chunks/chunk-6HCXF53X.js +64 -0
- package/dist/chunks/chunk-6OMZ6PFV.js +4 -0
- package/dist/chunks/chunk-ASXMESA4.js +4 -0
- package/dist/chunks/{chunk-LI2JPLF7.js → chunk-GGBNT4WI.js} +1 -1
- package/dist/chunks/chunk-GNLE6JXL.js +3 -0
- package/dist/chunks/chunk-H2IUSPAK.js +4 -0
- package/dist/chunks/chunk-HBVSGQOK.js +10 -0
- package/dist/chunks/chunk-HHBJZMKO.js +3 -0
- package/dist/chunks/{chunk-Q45MSMTN.js → chunk-I6QBBRCE.js} +1 -1
- package/dist/chunks/{chunk-M6LD6DHO.js → chunk-LW2QEXDT.js} +1 -1
- package/dist/chunks/{chunk-E5QDHFKQ.js → chunk-MMRDELHW.js} +1 -1
- package/dist/chunks/chunk-QXTXBMTM.js +3 -0
- package/dist/chunks/{chunk-NY6BX7QS.js → chunk-SAWVMQAD.js} +1 -1
- package/dist/chunks/{chunk-6ZEGAH36.js → chunk-TEO2EUS3.js} +1 -1
- package/dist/chunks/{chunk-YZG5A3GA.js → chunk-X54KIHCN.js} +1 -1
- package/dist/chunks/chunk-YVWRISPE.js +3 -0
- package/dist/chunks/colour-SRIDFG7U.js +3 -0
- package/dist/chunks/{config-command-UW6BYQ2K.js → config-command-TXQUYFA6.js} +1 -1
- package/dist/chunks/execute-T6VXZC33.js +3 -0
- package/dist/chunks/extensions-2XAKBZ43.js +3 -0
- package/dist/chunks/{extensions-command-5QO6YX6O.js → extensions-command-UGXZIFRI.js} +1 -1
- package/dist/chunks/image-F5D73JPQ.js +3 -0
- package/dist/chunks/{install-HCF5BIA6.js → install-YG43OJ7P.js} +1 -1
- package/dist/chunks/launch-UICFGGX4.js +4 -0
- package/dist/chunks/{lock-RZ6NVZFD.js → lock-6KTGUFBY.js} +1 -1
- package/dist/chunks/{manager-7HNOLCYH.js → manager-XN7WNMEW.js} +1 -1
- package/dist/chunks/{preferences-AKDCPHJ5.js → preferences-YL6SRNZR.js} +1 -1
- package/dist/chunks/{restart-6ONEYN6T.js → restart-RO6DM5N3.js} +1 -1
- package/dist/chunks/reveal-L6TBFOMV.js +3 -0
- package/dist/chunks/{run-C475RRUL.js → run-XQYPVWFI.js} +1 -1
- package/dist/chunks/{server-A327QWB6.js → server-3L4NCTNR.js} +15 -15
- package/dist/chunks/theme-JJC6JKR3.js +3 -0
- package/dist/chunks/{update-command-HT2RBFLR.js → update-command-6VNVMAYO.js} +1 -1
- package/dist/chunks/{update-note-6GBF5AE4.js → update-note-X6FJOR5C.js} +1 -1
- package/dist/index.js +24 -24
- package/package.json +1 -1
- package/skills/forge/SKILL.md +17 -1
- package/dist/chunks/chunk-4L6HNYSN.js +0 -4
- package/dist/chunks/chunk-775ILWZI.js +0 -3
- package/dist/chunks/chunk-CKWYIU2N.js +0 -4
- package/dist/chunks/chunk-CXVYIBCA.js +0 -4
- package/dist/chunks/chunk-GDQQDHXJ.js +0 -10
- package/dist/chunks/chunk-RE7E6NA7.js +0 -3
- package/dist/chunks/colour-LZ7EJ6H4.js +0 -3
- package/dist/chunks/execute-JRS6RQZA.js +0 -3
- package/dist/chunks/image-ESDL7GZU.js +0 -3
- package/dist/chunks/launch-BWYE27OQ.js +0 -65
- package/dist/chunks/theme-YG3CRJBG.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v}from"./chunk-6OMZ6PFV.js";import"./chunk-TMUK2DD3.js";export{t as BAR,c as DARK,d as LIGHT,g as MODE_KEYS,j as MODE_MARKERS,f as MODE_ORDER,e as NEUTRAL,b as SYMBOLS,a as VERSION,v as applyColourPreference,u as colourEnabled,s as colourProp,o as commandsPalette,n as dotGradient,k as modeColours,i as modeForKey,l as modeGradient,p as modePalette,m as modeWash,q as paintsCanvas,r as paletteFor,h as tabStep};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{U as a}from"./chunk-
|
|
3
|
+
import{U as a}from"./chunk-MMRDELHW.js";import"./chunk-J7FLFHQJ.js";import"./chunk-TMUK2DD3.js";async function d(i,n={}){let e=n.check??(async()=>(await import("./check-BRP6EKSA.js")).checkNow()),s=n.install??(async r=>(await import("./install-YG43OJ7P.js")).installUpdate(r)),t=await e();if(t===void 0)throw a();let{isNewer:o}=await import("./check-BRP6EKSA.js");return o(t,i)?(n.onInstalling?.(t),await s(t),{stdout:[`\u2713 Forge ${t} is installed. It runs from your next forge.`],data:{current:i,latest:t,installed:!0}}):{stdout:[`\u2713 Forge ${i} is the latest.`],data:{current:i,latest:t,installed:!1}}}export{d as runUpdate};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
2
|
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as m,c as w,d as h,f as l,g as p,h as b}from"./chunk-
|
|
3
|
+
import{b as m,c as w,d as h,f as l,g as p,h as b}from"./chunk-X54KIHCN.js";import{c as u,d as $}from"./chunk-6OMZ6PFV.js";import{e as g}from"./chunk-H2IUSPAK.js";import"./chunk-HON4OV7M.js";import"./chunk-TMUK2DD3.js";import{spawn as x}from"node:child_process";var P=60;function v(t,n){let e=Number.parseInt(t.slice(1),16);return`\x1B[${n};2;${e>>16&255};${e>>8&255};${e&255}m`}function C(t,n,e){let i=[" \u2191 ",`Forge ${t} is available`,` \xB7 your version ${n}`],r=[" In terminal: ","forge update"];if(e===void 0)return[i.join(""),r.join("")];let s=v(e.newTagBg,48),o=f=>v(f,38),c="\x1B[1m",a="\x1B[0m",d=f=>" ".repeat(Math.max(0,P-f.join("").length));return[`${s}${o(e.newTag)}${c}${i[0]}${o(e.fg)}${i[1]}${a}${s}${o(e.dim)}${i[2]}${d(i)}${a}`,`${s}${o(e.dim)}${r[0]}${o(e.fg)}${c}${r[1]}${a}${s}${d(r)}${a}`]}async function I(t,n){let e=n.now??Date.now(),{prefs:i}=await g();if(!h(i,n.env??process.env))return[];let r=await l();b(r,e)&&n.refresh();let s=r?.latest;if(r===void 0||s===void 0||!w(s,t))return[];let o=r.notifiedAt;if(o!==void 0&&o<=e&&e-o<=m)return[];await p({...r,notifiedAt:e}).catch(()=>{});let c=n.colour?i.theme==="light"?$:u:void 0;return C(s,t,c)}function N(t,n=process.platform,e=x){if(t!==void 0)try{e(process.execPath,[...process.execArgv,t,"__update-check"],{detached:!0,stdio:"ignore",...n==="win32"?{windowsHide:!0}:{}}).unref()}catch{}}export{I as afterCommand,C as noteLines,N as spawnRefresh};
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
3
3
|
const require = __forgeCreateRequire(import.meta.url);
|
|
4
|
-
import{b as W,d as B}from"./chunks/chunk-IBPGC4N2.js";import{a as U}from"./chunks/chunk-QVACE4IE.js";import{h as j}from"./chunks/chunk-
|
|
5
|
-
`)}displayWidth(e){return
|
|
4
|
+
import{b as W,d as B}from"./chunks/chunk-IBPGC4N2.js";import{a as U}from"./chunks/chunk-QVACE4IE.js";import{h as j}from"./chunks/chunk-LW2QEXDT.js";import{d as G}from"./chunks/chunk-3GVFOZ7M.js";import"./chunks/chunk-GGBNT4WI.js";import{k as X,m as Q}from"./chunks/chunk-GNLE6JXL.js";import"./chunks/chunk-32VJ2RDH.js";import{a as v}from"./chunks/chunk-6OMZ6PFV.js";import{a as D}from"./chunks/chunk-I6QBBRCE.js";import{I as d,L as P,e as J,ea as K,fa as T,g as E}from"./chunks/chunk-MMRDELHW.js";import{d as Y}from"./chunks/chunk-J7FLFHQJ.js";import"./chunks/chunk-H2IUSPAK.js";import"./chunks/chunk-HON4OV7M.js";import"./chunks/chunk-TMUK2DD3.js";import*as ue from"node:module";var O=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}},y=class extends O{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var S=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 y(`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 H(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as me}from"node:events";import q from"node:child_process";import x from"node:path";import V from"node:fs";import g from"node:process";import{stripVTControlCharacters as ge}from"node:util";import{stripVTControlCharacters as pe}from"node:util";var $=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,r)=>i.name().localeCompare(r.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),r=n.long&&e._findOption(n.long);!i&&!r?t.push(n):n.long&&!r?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(r=>!r.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=>H(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(r=>{let o=n(r);i.has(o)||i.set(o,[])}),t.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[]),i.get(o).push(r)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function r(a,p){return t.formatItem(a,n,p,t)}let o=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(o=o.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let h=t.visibleArguments(e).map(a=>r(t.styleArgumentTerm(t.argumentTerm(a)),t.styleArgumentDescription(t.argumentDescription(a))));if(o=o.concat(this.formatItemList("Arguments:",h,t)),this.groupItems(e.options,t.visibleOptions(e),a=>a.helpGroupHeading??"Options:").forEach((a,p)=>{let f=a.map(m=>r(t.styleOptionTerm(t.optionTerm(m)),t.styleOptionDescription(t.optionDescription(m))));o=o.concat(this.formatItemList(p,f,t))}),t.showGlobalOptions){let a=t.visibleGlobalOptions(e).map(p=>r(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));o=o.concat(this.formatItemList("Global Options:",a,t))}return this.groupItems(e.commands,t.visibleCommands(e),a=>a.helpGroup()||"Commands:").forEach((a,p)=>{let f=a.map(m=>r(t.styleSubcommandTerm(t.subcommandTerm(m)),t.styleSubcommandDescription(t.subcommandDescription(m))));o=o.concat(this.formatItemList(p,f,t))}),o.join(`
|
|
5
|
+
`)}displayWidth(e){return pe(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 o=" ".repeat(2);if(!n)return o+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),h=2,l=(this.helpWidth??80)-t-h-2,a;return l<this.minWidthToWrap||i.preformatted(n)?a=n:a=i.boxWrap(n,l).replace(/\n/g,`
|
|
6
6
|
`+" ".repeat(t+h)),o+u+" ".repeat(h)+a.replace(/\n/g,`
|
|
7
7
|
${o}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,r=[];return n.forEach(o=>{let u=o.match(i);if(u===null){r.push("");return}let h=[u.shift()],c=this.displayWidth(h[0]);u.forEach(l=>{let a=this.displayWidth(l);if(c+a<=t){h.push(l),c+=a;return}r.push(h.join(""));let p=l.trimStart();h=[p],c=this.displayWidth(p)}),r.push(h.join(""))}),r.join(`
|
|
8
|
-
`)}};var
|
|
8
|
+
`)}};var A=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=de(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 y(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?Z(this.name().replace(/^no-/,"")):Z(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},I=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,r=i!==void 0?i:!1;return t.negate===(r===e)}};function Z(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function de(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,r=s.split(/[ |,]+/).concat("guard");if(n.test(r[0])&&(e=r.shift()),i.test(r[0])&&(t=r.shift()),!e&&n.test(r[0])&&(e=r.shift()),!e&&i.test(r[0])&&(e=t,t=r.shift()),r[0].startsWith("-")){let o=r[0],u=`option creation failed due to '${o}' in option flags '${s}'`;throw/^-[^-][^-]/.test(o)?new Error(`${u}
|
|
9
9
|
- a short flag is a single dash and a single character
|
|
10
10
|
- either use a single dash and a single character (for a short flag)
|
|
11
11
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(o)?new Error(`${u}
|
|
12
12
|
- too many short flags`):i.test(o)?new Error(`${u}
|
|
13
13
|
- too many long flags`):new Error(`${u}
|
|
14
|
-
- 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
|
|
14
|
+
- 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 fe(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 r;s[i-1]===e[n-1]?r=0:r=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+r),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 M(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(o=>o.slice(2)));let n=[],i=3,r=.4;return e.forEach(o=>{if(o.length<=1)return;let u=fe(s,o),h=Math.max(s.length,o.length);(h-u)/h>r&&(u<i?(i=u,n=[o]):u===i&&n.push(o))}),n.sort((o,u)=>o.localeCompare(u)),t&&(n=n.map(o=>`--${o}`)),n.length>1?`
|
|
15
15
|
(Did you mean one of ${n.join(", ")}?)`:n.length===1?`
|
|
16
|
-
(Did you mean ${n[0]}?)`:""}var
|
|
17
|
-
- 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
|
|
18
|
-
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
|
|
19
|
-
- 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("|"),r=t(e).join("|");throw new Error(`cannot add command '${r}' 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=(r,o,u)=>{r==null&&e.presetArg!==void 0&&(r=e.presetArg);let h=this.getOptionValue(n);r!==null&&e.parseArg?r=this._callParseArg(e,r,h,o):r!==null&&e.variadic&&(r=e._collectValue(r,h)),r==null&&(e.negate?r=!1:e.isBoolean()||e.optional?r=!0:r=""),this.setOptionValueWithSource(n,r,u)};return this.on("option:"+t,r=>{let o=`error: option '${e.flags}' argument '${r}' is invalid.`;i(r,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,r=>{let o=`error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;i(r,o,"env")}),this}_optionEx(e,t,n,i,r){if(typeof t=="object"&&t instanceof
|
|
16
|
+
(Did you mean ${n[0]}?)`:""}var k=class s extends me{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:()=>te()??(g.stdout.isTTY&&g.stdout.hasColors?.()),getErrHasColors:()=>te()??(g.stderr.isTTY&&g.stderr.hasColors?.()),stripColor:t=>ge(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,r=n;typeof i=="object"&&i!==null&&(r=i,i=null),r=r||{};let[,o,u]=e.match(/([^ ]+) *(.*)/),h=this.createCommand(o);return i&&(h.description(i),h._executableHandler=!0),r.isDefault&&(this._defaultCommandName=h._name),h._hidden=!!(r.noHelp||r.hidden),h._executableFile=r.executableFile||null,u&&h.arguments(u),this._registerCommand(h),h.parent=this,h.copyInheritedSettings(this),i?this:h}createCommand(e){return new s(e)}createHelp(){return Object.assign(new $,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
|
|
17
|
+
- 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 S(e,t)}argument(e,t,n,i){let r=this.createArgument(e,t);return typeof n=="function"?r.default(i).argParser(n):r.default(n),this.addArgument(r),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,r]=n.match(/([^ ]+) *(.*)/),o=t??"display help for command",u=this.createCommand(i);return u.helpOption(!1),r&&u.arguments(r),o&&u.description(o),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}'.
|
|
18
|
+
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 O(e,t,n)),g.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,r=n.slice(0,i);return this._storeOptionsAsProperties?r[i]=this:r[i]=this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new A(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(r){if(r.code==="commander.invalidArgument"){let o=`${i} ${r.message}`;this.error(o,{exitCode:r.exitCode,code:r.code})}throw r}}_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}'
|
|
19
|
+
- 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("|"),r=t(e).join("|");throw new Error(`cannot add command '${r}' 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=(r,o,u)=>{r==null&&e.presetArg!==void 0&&(r=e.presetArg);let h=this.getOptionValue(n);r!==null&&e.parseArg?r=this._callParseArg(e,r,h,o):r!==null&&e.variadic&&(r=e._collectValue(r,h)),r==null&&(e.negate?r=!1:e.isBoolean()||e.optional?r=!0:r=""),this.setOptionValueWithSource(n,r,u)};return this.on("option:"+t,r=>{let o=`error: option '${e.flags}' argument '${r}' is invalid.`;i(r,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,r=>{let o=`error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;i(r,o,"env")}),this}_optionEx(e,t,n,i,r){if(typeof t=="object"&&t instanceof A)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(t,n);if(o.makeOptionMandatory(!!e.mandatory),typeof i=="function")o.default(r).argParser(i);else if(i instanceof RegExp){let u=i;i=(h,c)=>{let l=u.exec(h);return l?l[0]:c},o.default(r).argParser(i)}else o.default(i);return this.addOption(o)}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.
|
|
20
20
|
- 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(V.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",r=`'${e}' does not exist
|
|
21
21
|
- if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
22
22
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
23
|
-
- ${i}`;throw new Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(l,a){let p=
|
|
23
|
+
- ${i}`;throw new Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(l,a){let p=x.resolve(l,a);if(V.existsSync(p))return p;if(n.includes(x.extname(a)))return;let f=n.find(m=>V.existsSync(`${p}${m}`));if(f)return`${p}${f}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=e._executableFile||`${this._name}-${e._name}`,o=this._executableDir||"";if(this._scriptPath){let l;try{l=V.realpathSync(this._scriptPath)}catch{l=this._scriptPath}o=x.resolve(x.dirname(l),o)}if(o){let l=i(o,r);if(!l&&!e._executableFile&&this._scriptPath){let a=x.basename(this._scriptPath,x.extname(this._scriptPath));a!==this._name&&(l=i(o,`${a}-${e._name}`))}r=l||r}let u=n.includes(x.extname(r)),h;g.platform!=="win32"?u?(t.unshift(r),t=ee(g.execArgv).concat(t),h=q.spawn(g.argv[0],t,{stdio:"inherit"})):h=q.spawn(r,t,{stdio:"inherit"}):(this._checkForMissingExecutable(r,o,e._name),t.unshift(r),t=ee(g.execArgv).concat(t),h=q.spawn(g.execPath,t,{stdio:"inherit"})),h.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(a=>{g.on(a,()=>{h.killed===!1&&h.exitCode===null&&h.kill(a)})});let c=this._exitCallback;h.on("close",l=>{l=l??1,c?c(new O(l,"commander.executeSubCommandAsync","(close)")):g.exit(l)}),h.on("error",l=>{if(l.code==="ENOENT")this._checkForMissingExecutable(r,o,e._name);else if(l.code==="EACCES")throw new Error(`'${r}' not executable`);if(!c)g.exit(1);else{let a=new O(1,"commander.executeSubCommandAsync","(error)");a.nestedError=l,c(a)}}),this.runningCommand=h}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let r;return r=this._chainOrCallSubCommandHook(r,i,"preSubcommand"),r=this._chainOrCall(r,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),r}_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,r)=>{let o=i;if(i!==null&&n.parseArg){let u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;o=this._callParseArg(n,i,r,u)}return o};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let r=n.defaultValue;n.variadic?i<this.args.length?(r=this.args.slice(i),n.parseArg&&(r=r.reduce((o,u)=>e(n,u,o),n.defaultValue))):r===void 0&&(r=[]):i<this.args.length&&(r=this.args[i],n.parseArg&&(r=e(n,r,n.defaultValue))),t[i]=r}),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(r=>r._lifeCycleHooks[t]!==void 0).forEach(r=>{r._lifeCycleHooks[t].forEach(o=>{i.push({hookedCommand:r,callback:o})})}),t==="postAction"&&i.reverse(),i.forEach(r=>{n=this._chainOrCall(n,()=>r.callback(r.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(r=>{i=this._chainOrCall(i,()=>r(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])},r=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(r,e,t)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent?.listenerCount(r))i(),this._processArguments(),this.parent.emit(r,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(r=>n.conflictsWith.includes(r.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function r(l){return l.length>1&&l[0]==="-"}let o=l=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(l)?!this._getCommandAndAncestors().some(a=>a.options.map(p=>p.short).some(p=>/^-\d$/.test(p))):!1,u=null,h=null,c=0;for(;c<e.length||h;){let l=h??e[c++];if(h=null,l==="--"){i===n&&i.push(l),i.push(...e.slice(c));break}if(u&&(!r(l)||o(l))){this.emit(`option:${u.name()}`,l);continue}if(u=null,r(l)){let a=this._findOption(l);if(a){if(a.required){let p=e[c++];p===void 0&&this.optionMissingArgument(a),this.emit(`option:${a.name()}`,p)}else if(a.optional){let p=null;c<e.length&&(!r(e[c])||o(e[c]))&&(p=e[c++]),this.emit(`option:${a.name()}`,p)}else this.emit(`option:${a.name()}`);u=a.variadic?a:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let a=this._findOption(`-${l[1]}`);if(a){a.required||a.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${a.name()}`,l.slice(2)):(this.emit(`option:${a.name()}`),h=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let a=l.indexOf("="),p=this._findOption(l.slice(0,a));if(p&&(p.required||p.optional)){this.emit(`option:${p.name()}`,l.slice(a+1));continue}}if(i===t&&r(l)&&!(this.commands.length===0&&o(l))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}else if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){i.push(l,...e.slice(c));break}i.push(l)}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}
|
|
24
24
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
25
25
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
26
26
|
`),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,r=n.code||"commander.error";this._exit(i,r,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 I(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=o=>{let u=o.attributeName(),h=this.getOptionValue(u),c=this.options.find(a=>a.negate&&u===a.attributeName()),l=this.options.find(a=>!a.negate&&u===a.attributeName());return c&&(c.presetArg===void 0&&h===!1||c.presetArg!==void 0&&h===c.presetArg)?c:l||o},i=o=>{let u=n(o),h=u.attributeName();return this.getOptionValueSource(h)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},r=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],r=this;do{let o=r.createHelp().visibleOptions(r).filter(u=>u.long).map(u=>u.long);i=i.concat(o),r=r.parent}while(r&&!r._enablePositionalOptions);t=M(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,r=this.parent?` for '${this.name()}'`:"",o=e.join(", "),u=`error: too many arguments${r}. Expected ${t} argument${n} but got ${i}: ${o}.`;this.error(u,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(r=>{i.push(r.name()),r.alias()&&i.push(r.alias())}),t=M(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}
|
|
27
|
-
`),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=>H(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=
|
|
27
|
+
`),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=>H(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=x.basename(e,x.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,r;return t?(n=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),hasColors:i,helpWidth:r}}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(o=>o.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let r=this.helpInformation({error:n.error});if(t&&(r=t(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(o=>o.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.
|
|
28
28
|
Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,r=>{let o;typeof t=="function"?o=t({error:r.error,command:r.command}):o=t,o&&r.write(`${o}
|
|
29
|
-
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function
|
|
29
|
+
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function ee(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",r;return(r=e.match(/^(--inspect(-brk)?)$/))!==null?t=r[1]:(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=r[1],/^\d+$/.test(r[3])?i=r[3]:n=r[3]):(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=r[1],n=r[3],i=r[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function te(){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 it=new k;function _e(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!D.includes(t))throw d(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${D.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw d(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw d(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var be={jpg:"jpeg",tif:"tiff",heif:"heic"};function z(s){let e=s.toLowerCase().replace(/^\./,""),t=J(be[e]??e);if(!t)throw d(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function N(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw d(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function ne(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw d(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function we(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=j))throw d(`--resize takes a percent from 1 to ${j}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function F(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw d(`Concurrency must be a positive whole number, not ${s}.`);return e}var Oe=`
|
|
30
30
|
Exit codes:
|
|
31
31
|
0 every input succeeded
|
|
32
32
|
1 the command was understood, and at least one input failed or was refused
|
|
33
|
-
2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,
|
|
33
|
+
2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,xe=`
|
|
34
34
|
Other commands:
|
|
35
35
|
forge probe <files...> what each file is and what Forge can do with it
|
|
36
36
|
forge palette <image> an image's main colours (--json, --svg, --inside <hex>)
|
|
@@ -38,7 +38,7 @@ Other commands:
|
|
|
38
38
|
forge config [list | path | set <setting> <value>]
|
|
39
39
|
forge extensions [add | remove <id>] optional extras, such as boost and remove-background
|
|
40
40
|
forge update install a newer Forge, if there is one
|
|
41
|
-
forge mcp run as a local MCP server over stdio, for AI agents`;function
|
|
41
|
+
forge mcp run as a local MCP server over stdio, for AI agents`;function ie(s){let e=Y(String(s));if(e===void 0)throw d(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function Ce(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw d(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw d("No files given.","Name a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function ye(s){let e=s.slice(1).filter(o=>o!=="--json"),t=e.find(o=>o.startsWith("-"));if(t!==void 0)throw d(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...r]=e;if(n===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw d(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||r.length>0)throw d(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function re(s){if(s===void 0)throw d("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=U(s);if(!e)throw d(`${s} is not a colour.`,"Try a hex code, for example 6579FD or #6579FD.");return e}var ve={palette:`Usage: forge palette <image> [--json] [--svg] [--inside <hex>]
|
|
42
42
|
|
|
43
43
|
An image's main colours, most of the image first.
|
|
44
44
|
--json one JSON document: palette.colours[] with hex, rgb, oklch, share
|
|
@@ -49,24 +49,24 @@ An image's main colours, most of the image first.
|
|
|
49
49
|
50\u2013950 built in OKLCH, with <colour> at 500. Pass the hex without #, or quote it.
|
|
50
50
|
--json one JSON document: scale.steps[] with hex, oklch, white, black
|
|
51
51
|
--svg a card of swatches; pipe to pbcopy and paste into Figma
|
|
52
|
-
`};function
|
|
53
|
-
${
|
|
54
|
-
`),b=_.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,b||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.formats)return{kind:"formats"};if(n.pages!==void 0&&n.to===void 0)throw d("--pages needs --to: it chooses which pages to render.");let r=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(r.length>1)throw d(`Use one operation at a time \u2014 got ${r.map(f=>`--${f}`).join(" and ")}.`);let o=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],u=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]];if(n.trim||u.length>0){if(u.length>1)throw d(`Use one of --resize, --width and --height \u2014 got ${u.join(" and ")}.`);let f=[...o,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...r.map(
|
|
52
|
+
`};function Ae(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write(ve[e==="scale"?"scale":"palette"]),new O(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(h=>h!=="--json"&&h!=="--svg"),i=t.includes("--svg"),r=n.indexOf("--inside"),o=r===-1?void 0:n[r+1];r!==-1&&n.splice(r,2);let u=n.find(h=>h.startsWith("-"));if(u!==void 0)throw d(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(r!==-1)throw d("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw d("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:re(n[0]),svg:i}}if(n.length!==1)throw d(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...r===-1?{}:{inside:re(o)}}}function R(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function ke(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],r;for(let o=0;o<t.length;o++){let u=t[o],h=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&h===void 0){i.push(u);continue}let c=h;if(c===void 0&&/^\d+$/.test(t[o+1]??"")&&(c=t[++o]),c!==void 0&&c!=="2"&&c!=="3"&&c!=="4")throw d(`--boost takes 2, 3 or 4, not ${c}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");r=c==="4"?4:c==="3"?3:2}return{rest:[...i,...n],...r===void 0?{}:{scale:r}}}function oe(s){let e=s;if(e[0]==="config"||e[0]==="probe"||e[0]==="extensions"||e[0]==="palette"||e[0]==="scale"||e[0]==="update")return Se(e);let t=ke(e);return $e(t.rest,t.scale)}function Se(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw d(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}return s[0]==="config"?_e(s.filter(e=>e!=="--json")):s[0]==="probe"?Ce(s):s[0]==="palette"||s[0]==="scale"?Ae(s):ye(s)}function $e(s,e){let t=new k().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--pages <ranges>","with --to, which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(v,"-V, --version","show the version").addHelpText("after",`${xe}
|
|
53
|
+
${Oe}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof O&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[m="",..._]=f.message.replace(/^error: /,"").split(`
|
|
54
|
+
`),b=_.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${m.charAt(0).toUpperCase()}${m.slice(1).replace(/\.$/,"")}.`,b||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.formats)return{kind:"formats"};if(n.pages!==void 0&&n.to===void 0)throw d("--pages needs --to: it chooses which pages to render.");let r=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(r.length>1)throw d(`Use one operation at a time \u2014 got ${r.map(f=>`--${f}`).join(" and ")}.`);let o=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],u=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]];if(n.trim||n.crop!==void 0||u.length>0){if(u.length>1)throw d(`Use one of --resize, --width and --height \u2014 got ${u.join(" and ")}.`);let f=n.crop!==void 0?"--crop":u[0]??"--trim",m=[...n.crop!==void 0&&n.trim?["--trim"]:[],...o,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...r.map(ce=>`--${ce}`)][0];if(m!==void 0)throw d(`${f} cannot be combined with ${m}.`,m!=="--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 _=n.crop!==void 0?{aspect:X(String(n.crop))}:void 0,b=n.resize!==void 0?{percent:we(n.resize)}:n.width!==void 0?{width:ne("--width",n.width)}:n.height!==void 0?{height:ne("--height",n.height)}:void 0;if(i.length===0)throw d("No files given.","Name an image, for example: forge photo.jpg --resize 50%");let C={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(C.quality=N(String(n.quality)));let w={kind:"edit",inputs:i,trim:!!n.trim,options:C,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return _!==void 0&&(w.crop=_),b!==void 0&&(w.resize=b),n.to&&(w.target=z(String(n.to))),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=F(String(n.concurrency))),w}let h=n.sharpen?1:e,c=h!==void 0?"boost":n.removeBg?"remove-background":null;if(c!==null){if(o.length>1)throw d(`Use one operation at a time \u2014 got ${o.join(" and ")}.`);let f=o[0];if(r.length>0)throw d(`${f} cannot be combined with --${r[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw d(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw d("No files given.",`Name an image, for example: forge photo.jpg ${f}`);let m=n.to?z(String(n.to)):"png";if(c==="remove-background"){let C=Q(m);if(C)throw C}let _={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(_.quality=N(String(n.quality)));let b={kind:"extension-op",op:c,inputs:i,target:m,options:_,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return h!==void 0&&(b.scale=h),n.output!==void 0&&(b.output=String(n.output)),n.concurrency!==void 0&&(b.concurrency=F(String(n.concurrency))),b}if(r.length===1){let f=r[0];if(i.length===0)throw d("No files given.",`Name a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw d(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw d(`--output does not apply to --${f}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let m={kind:"pageop",action:f,inputs:i,force:!!n.force,debug:!!n.debug};if(f==="rotate"){let _=Number(n.rotate);if(!Number.isInteger(_)||_%90!==0||_===0||_>=360)throw d(`--rotate takes a multiple of 90 below 360, not "${n.rotate}".`);m.rotate=_}if((f==="extract"||f==="delete")&&(m.pages=String(n[f]),f==="extract"&&n.separate&&(m.separate=!0)),f==="split"){let _=String(n.split),b=_.match(/^every=(\d+)$/),C=_.match(/^at=([\d,\s]+)$/);if(_==="every-page")m.split={mode:"every-page"};else if(b?.[1]!==void 0){let w=Number(b[1]);if(!Number.isInteger(w)||w<1)throw d(`--split every=N takes a whole number of pages, at least 1, not "${b[1]}".`);m.split={mode:"every-n",n:w}}else if(C?.[1])m.split={mode:"points",after:C[1].split(",").map(w=>Number(w.trim()))};else throw d(`--split takes every-page, every=N or at=N,N \u2014 not "${_}".`)}return m}if(i.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw d("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(i.length===0)throw d("No files given.","Name a file, for example: forge photo.jpg --max-size 500kb");let f={background:String(n.background),keepMetadata:!!n.keepMetadata},m={kind:"compress",inputs:i,options:f,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(m.quality=N(String(n.quality))),n.maxSize!==void 0&&(m.maxBytes=ie(n.maxSize)),n.output!==void 0&&(m.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let _=Number(n.dpi);if(!Number.isInteger(_)||_<36||_>600)throw P(n.dpi);m.dpi=_}return n.concurrency!==void 0&&(m.concurrency=F(String(n.concurrency))),m}if(!n.to)throw d("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw d("No files given.","Name a file, a folder or a glob, for example: forge photo.jpg --to webp");let l={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(l.quality=N(String(n.quality)));let a=Number(n.dpi);if(!Number.isInteger(a)||a<36||a>600)throw P(n.dpi);let p={kind:"convert",inputs:i,target:z(String(n.to)),options:l,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:a,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(p.output=String(n.output)),n.pages!==void 0&&(p.pages=String(n.pages)),n.maxSize!==void 0&&(p.maxBytes=ie(n.maxSize)),n.concurrency!==void 0&&(p.concurrency=F(String(n.concurrency))),p}function L(s){return E(s)?s:K(s)}function se(s,e){return T(L(s),{debug:e})}function ae(s,e){process.once("beforeExit",()=>{s()||(e(new Error("Forge stopped before it finished: it was waiting for input that never came.")),process.exitCode=1)})}ue.enableCompileCache?.();function Ee({completed:s,total:e}){s===0?process.stderr.write(`Converting ${e} files
|
|
55
55
|
`):process.stderr.write(` ${s}/${e}
|
|
56
|
-
`)}async function
|
|
56
|
+
`)}async function Te(){let s=process.argv.slice(2),e=s.includes("--debug"),t=R(s);try{if(s[0]==="__update-check"){let{checkNow:a}=await import("./chunks/check-BRP6EKSA.js");await a();return}if(s[0]==="mcp"){let{runMcpServer:a}=await import("./chunks/server-3L4NCTNR.js");await a(s.slice(1));return}let n=oe(s);if(n.kind==="shell"){if(t)throw d("No files given.","Name a file, for example: forge photo.jpg --to webp --json");if(!process.stdout.isTTY||!process.stdin.isTTY){process.stderr.write(`Forge needs a file and a target format.
|
|
57
57
|
Try: forge photo.jpg --to webp
|
|
58
|
-
`),process.exitCode=2;return}let{applyColourPreference:a}=await import("./chunks/theme-
|
|
59
|
-
`:""}`)},h=!!process.stderr.isTTY&&!t,c=new AbortController;n.kind==="extension-op"&&process.once("SIGINT",()=>c.abort());let l=await i(n,{json:t,...h?{onInstalling:a=>{r=W(process.stderr,`installing Forge ${a}`)}}:{},signal:c.signal,...h?{onDownload:u}:{},colour:!!process.stdout.isTTY&&!t&&B(),onProgress:h?a=>{a.completed>0&&r?.stop()
|
|
58
|
+
`),process.exitCode=2;return}let{applyColourPreference:a}=await import("./chunks/theme-JJC6JKR3.js");a();let{bootShell:p}=await import("./chunks/boot-FBULFF7S.js");await p();return}let{execute:i}=await import("./chunks/execute-T6VXZC33.js"),r,o=0,u=(a,p)=>{let f=Date.now();if(a<p&&f-o<100)return;o=f;let m=_=>(_/1e6).toFixed(1);process.stderr.write(`\r downloading ${m(a)} / ${m(p)} MB${a>=p?`
|
|
59
|
+
`:""}`)},h=!!process.stderr.isTTY&&!t,c=new AbortController;n.kind==="extension-op"&&process.once("SIGINT",()=>c.abort());let l=await i(n,{json:t,...h?{onInstalling:a=>{r=W(process.stderr,`installing Forge ${a}`)}}:{},signal:c.signal,...h?{onDownload:u}:{},colour:!!process.stdout.isTTY&&!t&&B(),onProgress:h?a=>{a.completed>0&&r?.stop(),Ee(a)}:void 0,...h?{onSearch:a=>{r??=W(process.stderr,"finding the smallest that fits"),r.update(a)}}:{}});if(r?.stop(),l.stdout.length>0&&process.stdout.write(`${l.stdout.join(`
|
|
60
60
|
`)}
|
|
61
61
|
`),l.stderr.length>0&&process.stderr.write(`${l.stderr.join(`
|
|
62
62
|
`)}
|
|
63
|
-
`),process.exitCode=c.signal.aborted?130:l.exitCode,h&&process.stdout.isTTY&&n.kind!=="update")try{let{afterCommand:a,spawnRefresh:p}=await import("./chunks/update-note-
|
|
63
|
+
`),process.exitCode=c.signal.aborted?130:l.exitCode,h&&process.stdout.isTTY&&n.kind!=="update")try{let{afterCommand:a,spawnRefresh:p}=await import("./chunks/update-note-X6FJOR5C.js"),{runningScript:f}=await import("./chunks/install-YG43OJ7P.js"),m=await a(v,{refresh:()=>p(f(process.argv[1])),colour:B()});m.length>0&&process.stderr.write(`
|
|
64
64
|
${m.join(`
|
|
65
65
|
`)}
|
|
66
|
-
`)}catch{}}catch(n){if(E(n)){t?process.stdout.write(`${JSON.stringify(G(
|
|
66
|
+
`)}catch{}}catch(n){if(E(n)){t?process.stdout.write(`${JSON.stringify(G(v,n))}
|
|
67
67
|
`):process.stderr.write(`${T(n,{debug:e}).join(`
|
|
68
68
|
`)}
|
|
69
|
-
`),process.exitCode=2;return}if(n instanceof Error&&"code"in n&&"exitCode"in n){let i=n.code;process.exitCode=i==="commander.helpDisplayed"||i==="commander.version"?0:2;return}throw n}}function
|
|
70
|
-
`);return}process.stderr.write(`${
|
|
69
|
+
`),process.exitCode=2;return}if(n instanceof Error&&"code"in n&&"exitCode"in n){let i=n.code;process.exitCode=i==="commander.helpDisplayed"||i==="commander.version"?0:2;return}throw n}}function le(s){let e=process.argv.slice(2);if(R(e)){process.stdout.write(`${JSON.stringify(G(v,L(s)))}
|
|
70
|
+
`);return}process.stderr.write(`${se(s,e.includes("--debug")).join(`
|
|
71
71
|
`)}
|
|
72
|
-
`)}var
|
|
72
|
+
`)}var he=!1;ae(()=>he,le);try{await Te()}catch(s){le(s),process.exitCode=1}finally{he=!0}export{v as VERSION};
|
package/package.json
CHANGED
package/skills/forge/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: forge
|
|
3
|
-
description: Convert, compress and edit local files on macOS with the Forge CLI (`forge`) — images (HEIC, JPEG, PNG, WebP, AVIF, GIF, TIFF), PDFs and Word documents. Use when the user wants a file in another format, smaller or under a size, or a PDF merged, split, trimmed or rotated, or an image's colour palette or a tonal scale from a colour, and `forge` is installed (`npm i -g forge-terminal`).
|
|
3
|
+
description: Convert, compress and edit local files on macOS with the Forge CLI (`forge`) — images (HEIC, JPEG, PNG, WebP, AVIF, GIF, TIFF), PDFs and Word documents. Use when the user wants a file in another format, smaller or under a size, or cropped to a shape, or a PDF merged, split, trimmed or rotated, or an image's colour palette or a tonal scale from a colour, and `forge` is installed (`npm i -g forge-terminal`).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Forge
|
|
@@ -84,6 +84,22 @@ Runtime refusals: `resize-too-large` (over 16,384 px a side or 100 MP),
|
|
|
84
84
|
`nothing-to-trim`, `animated-trim`. MCP: `forge_convert` with `trim: true`
|
|
85
85
|
and/or `resize: { percent | width | height }`; `to` is then optional.
|
|
86
86
|
|
|
87
|
+
## Crop to shape
|
|
88
|
+
|
|
89
|
+
Built in, images only, format kept unless `--to` is given. The largest box of
|
|
90
|
+
the shape, placed to keep the subject:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
forge photo.jpg --crop 1:1 --json # photo-cropped-1x1.jpg
|
|
94
|
+
forge photo.jpg --crop 4:5 --width 1080 --to webp --json # photo-cropped-4x5-1080x1350.webp
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Any `W:H` of whole numbers 1-100. A resize flag applies to the cropped image.
|
|
98
|
+
Not with `--trim`, `--max-size`, `--sharpen`, `--boost`, `--remove-bg` or page
|
|
99
|
+
operations (`invalid-arguments`). Runtime refusals: `nothing-to-crop` (already
|
|
100
|
+
that shape; with a resize it is the warning `nothing-cropped` instead),
|
|
101
|
+
`animated-crop`. MCP: `forge_convert` with `crop: "1:1"`; `to` is then optional.
|
|
102
|
+
|
|
87
103
|
## Optional extensions: boost and remove background
|
|
88
104
|
|
|
89
105
|
Two image operations are not built in. They are small downloads, installed once,
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a}from"./chunk-HON4OV7M.js";import{mkdir as O,readFile as h,rename as C,unlink as v,writeFile as N}from"node:fs/promises";import{homedir as m}from"node:os";import{dirname as S,join as w}from"node:path";import{execFileSync as P}from"node:child_process";import{homedir as l}from"node:os";import{join as p}from"node:path";var F={Desktop:"[Environment]::GetFolderPath('Desktop')",Downloads:"(Get-ItemProperty 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders').'{374DE290-123F-4565-9164-39C4925E467B}'"};function E(e){try{let t=P("powershell.exe",["-NoProfile","-NonInteractive","-Command",`[Console]::OutputEncoding=[Text.Encoding]::UTF8; ${F[e]}`],{encoding:"buffer",timeout:5e3,stdio:["ignore","pipe","ignore"]}).toString("utf8").trim();return t.length>0?t:void 0}catch{return}}var g=new Map;function d(e,n=process.platform,t=E){if(n!=="win32")return p(l(),e);let r=g.get(e);if(r!==void 0)return r;let o=t(e)?.replace(/%([^%]+)%/g,(k,x)=>process.env[x]??k),c=(o!==void 0&&!o.includes("%")?o:void 0)??p(l(),e);return g.set(e,c),c}var s={defaultOutput:"~/Desktop",quality:80};function f(){return w(a(),"forge","config.json")}function A(e,n=process.platform){if(n==="win32"){if(e==="~/Desktop")return d("Desktop",n);if(e==="~/Downloads")return d("Downloads",n)}return e==="~"?m():e.startsWith("~/")?w(m(),e.slice(2)):e}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e){let n={...s},t=[];if(e.theme!==void 0&&(e.theme==="dark"||e.theme==="light"?n.theme=e.theme:t.push("theme")),e.defaultOutput!==void 0&&(typeof e.defaultOutput=="string"&&e.defaultOutput.trim().length>0?n.defaultOutput=e.defaultOutput:t.push("defaultOutput")),e.quality!==void 0){let r=e.quality;typeof r=="number"&&Number.isInteger(r)&&r>=1&&r<=100?n.quality=r:t.push("quality")}return e.updateCheck!==void 0&&(typeof e.updateCheck=="boolean"?n.updateCheck=e.updateCheck:t.push("updateCheck")),{prefs:n,rejected:t}}async function j(){let e;try{e=await h(f(),"utf8")}catch{return}try{let n=JSON.parse(e);return y(n)?n:void 0}catch{return}}async function B(){let e=f(),n;try{n=await h(e,"utf8")}catch(o){return o.code==="ENOENT"?{prefs:s}:{prefs:s,warning:`Could not read the config at ${e} \u2014 using defaults.`}}let t;try{t=JSON.parse(n)}catch{return{prefs:s,warning:`The config at ${e} is not valid JSON \u2014 using defaults.`}}if(!y(t))return{prefs:s,warning:`The config at ${e} is not an object \u2014 using defaults.`};let{prefs:r,rejected:i}=D(t);return i.length===0?{prefs:r}:{prefs:r,warning:`Ignored invalid config ${i.length===1?"setting":"settings"}: ${i.join(", ")}.`}}async function G(e){let n=f();await O(S(n),{recursive:!0});let r={...await j()??{}};for(let[o,u]of Object.entries(e))u!==void 0&&(r[o]=u);let i=`${n}.${process.pid}.tmp`;try{await N(i,`${JSON.stringify(r,null,2)}
|
|
4
|
-
`,"utf8"),await C(i,n)}catch(o){throw await v(i).catch(()=>{}),o}}export{d as a,s as b,f as c,A as d,B as e,G as f};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{a as R,c as te}from"./chunk-OIZCRBLT.js";import{$ as Y,F as Q,I as T,N as V,_ as Z,aa as ee,ba as M,c as F,d as m,g as A,h as C,i as W,j as P,k as q,l as J,m as j,n as X,o as G,r as w,x as K,y as B}from"./chunk-E5QDHFKQ.js";import{randomBytes as Ae}from"node:crypto";import{constants as Pe}from"node:fs";import{access as Be,readFile as he,rm as Te,stat as Me,writeFile as Re}from"node:fs/promises";import{basename as ke,dirname as De,join as Ne}from"node:path";function Ke(e){if(m[e].hasAlpha)return;let i=Object.keys(m).filter(t=>m[t].hasAlpha&&t!=="heic").join(", ");return T(`${m[e].label} cannot hold transparency, so a cutout cannot be saved as one.`,`Choose a format that can: ${i}.`)}var ie="1.1.0";function le(e,i){let t=e.split(".").map(n=>Number.parseInt(n,10)||0),r=i.split(".").map(n=>Number.parseInt(n,10)||0);for(let n=0;n<Math.max(t.length,r.length);n++){let a=(t[n]??0)-(r[n]??0);if(a!==0)return a>0}return!0}function k(e){return e!==void 0&&le(e,ie)?[2,3,4]:[2,4]}function Qe(e,i,t){if(e===1||k(i).some(n=>n===e))return;if(t!==void 0&&k(t).some(n=>n===e))return V("boost",`boost ${e}\xD7`,i,ie);let r=k(i).map(n=>`--boost ${n}`);return T(`No released boost makes ${e}\xD7 yet.`,`Try ${r.slice(0,-1).join(", ")} or ${r.at(-1)}.`)}var ge=16384,we=1e8;function re(e,i,t){let r=Math.max(e,i)*t;if(r>ge)return{side:r};let n=e*t*i*t;if(n>we)return{megapixels:Math.round(n/1e6)}}var y=e=>Math.max(1,Math.round(e));function D(e,i){return"percent"in i?{width:y(e.width*i.percent/100),height:y(e.height*i.percent/100)}:"width"in i?{width:y(i.width),height:y(e.height*i.width/e.width)}:{width:y(e.width*i.height/e.height),height:y(i.height)}}function ne(e){return re(e.width,e.height,1)}import{execFile as be}from"node:child_process";import{randomBytes as xe}from"node:crypto";import{mkdtemp as Se,open as ae,readFile as Ie,rm as N}from"node:fs/promises";import{tmpdir as oe}from"node:os";import{join as E}from"node:path";import{promisify as Ee}from"node:util";function g(e){let i;return()=>(i??=e(),i)}var b=g(async()=>(await import("sharp")).default),et=g(()=>import("./es-T2U7NBLD.js")),tt=g(()=>import("@hyzyla/pdfium")),it=g(async()=>(await import("./lib-TPEJ5CJJ.js")).default),rt=g(async()=>(await import("./word-OGQ2KZAJ.js")).default),nt=g(async()=>(await import("./adm-zip-SQKLKBDP.js")).default),at=g(async()=>(await import("./cfb-V6M2PYOD.js")).default);async function ye(){let e=Object.getOwnPropertyDescriptor(globalThis,"localStorage");if(!e?.configurable)return import("./dist-J2V6ITHG.js");Object.defineProperty(globalThis,"localStorage",{value:void 0,configurable:!0,enumerable:e.enumerable??!1,writable:!0});try{return await import("./dist-J2V6ITHG.js")}finally{Object.defineProperty(globalThis,"localStorage",e)}}var ot=g(ye);var L=Ee(be),se=async()=>({...await import("./paths-H2WS22BA.js"),...await import("./run-C475RRUL.js")}),x;async function S(e=process.platform){if(e==="win32")return await(await se()).installed("heic")!==void 0;if(x!==void 0)return x;try{await L("/usr/bin/sips",["--help"],{timeout:5e3}),x=!0}catch{x=!1}return x}async function v(e,i=process.platform){if(i==="win32")return ve(e);let t=E(oe(),`forge-heic-${xe(8).toString("hex")}.png`),r=async()=>{await N(t,{force:!0}).catch(()=>{})};try{return await L("/usr/bin/sips",["-s","format","png",e,"--out",t],{timeout:12e4}),{path:t,cleanup:r}}catch(n){throw await r(),n}}async function ce(e){let{installed:i,runExtension:t}=await se(),r=await i("heic");if(r===void 0)throw w(e,"win32");return{ext:r,runExtension:t}}async function ve(e){let i=await Se(E(oe(),"forge-heic-")),t=async()=>{await N(i,{recursive:!0,force:!0}).catch(()=>{})};try{let{ext:r,runExtension:n}=await ce(e),a=E(i,"decoded.rgba"),o=E(i,"decoded.png"),{width:h,height:d}=await n(r,["--in",e,"--out",a],{subject:e});return await(await b())(await Ie(a),{raw:{width:h,height:d,channels:4}}).png().toFile(o),await N(a,{force:!0}),{path:o,cleanup:t}}catch(r){throw await t(),r}}var ze=new Set(["heic","heix","hevc","hevx","heim","heis","mif1","msf1"]),Oe=new Set(["avif","avis"]);async function fe(e){let i;try{i=await ae(e,"r")}catch{return!1}try{let t=Buffer.alloc(64),{bytesRead:r}=await i.read(t,0,64,0);if(r<12||t.toString("latin1",4,8)!=="ftyp")return!1;let n=Math.min(t.readUInt32BE(0),r),a=[];for(let o=8;o+4<=n;o+=4)a.push(t.toString("latin1",o,o+4));return a.some(o=>Oe.has(o))?!1:a.some(o=>ze.has(o))}catch{return!1}finally{await i.close().catch(()=>{})}}async function de(e,i=process.platform){if(i==="win32"){let{ext:o,runExtension:h}=await ce(e),d=await h(o,["--info","--in",e],{subject:e});return{width:d.width,height:d.height,hasAlpha:d.hasAlpha??!0}}let{stdout:t}=await L("/usr/bin/sips",["-g","pixelWidth","-g","pixelHeight","-g","hasAlpha",e],{timeout:3e4}),r=Number(/pixelWidth:\s*(\d+)/.exec(t)?.[1]??0),n=Number(/pixelHeight:\s*(\d+)/.exec(t)?.[1]??0),a=await Fe(e);return{width:a?n:r,height:a?r:n,hasAlpha:/hasAlpha:\s*yes/i.test(t)}}function*I(e,i,t){let r=i;for(;r+8<=t;){let n=e.readUInt32BE(r),a=8;if(n===1&&r+16<=t?(n=Number(e.readBigUInt64BE(r+8)),a=16):n===0&&(n=t-r),n<a)return;yield{type:e.toString("latin1",r+4,r+8),start:r+a,end:Math.min(r+n,t)},r+=n}}async function Fe(e){let i=await ae(e,"r");try{let t=Buffer.alloc(262144),{bytesRead:r}=await i.read(t,0,t.length,0),n=[...I(t,0,r)].find(c=>c.type==="meta");if(!n)return!1;let a=[...I(t,n.start+4,n.end)],o=a.find(c=>c.type==="pitm"),h=a.find(c=>c.type==="iprp");if(!o||!h)return!1;let d=t.readUInt8(o.start)===0?t.readUInt16BE(o.start+4):t.readUInt32BE(o.start+4),s=[...I(t,h.start,h.end)],l=s.find(c=>c.type==="ipco"),f=s.find(c=>c.type==="ipma");if(!l||!f)return!1;let u=new Map;if([...I(t,l.start,l.end)].forEach((c,O)=>{c.type==="irot"&&u.set(O+1,t.readUInt8(c.start)&3)}),u.size===0)return!1;let $=t.readUInt8(f.start),H=(t.readUInt8(f.start+3)&1)===1,p=f.start+4,pe=t.readUInt32BE(p);p+=4;for(let c=0;c<pe&&p<f.end;c++){let O=$<1?t.readUInt16BE(p):t.readUInt32BE(p);p+=$<1?2:4;let me=t.readUInt8(p);p+=1;for(let _=0;_<me;_++){let ue=H?t.readUInt16BE(p)&32767:t.readUInt8(p)&127;if(p+=H?2:1,O===d&&(u.get(ue)??0)%2===1)return!0}}return!1}catch{return!1}finally{await i.close().catch(()=>{})}}var Le=new Set(["jpeg","png","webp","avif","heic","gif","tiff"]),Ue=new Set(["jpeg","png","webp","avif","gif","tiff"]),$e={jpeg:"jpeg",png:"png",webp:"webp",gif:"gif",tiff:"tiff"};function He(e,i){if(i.format==="heif")return i.compression==="av1"?"avif":"heic";let t=$e[i.format??""];if(!t)throw G(e,i.format??"an unknown format");return t}async function _e(e){let i;try{i=await Me(e)}catch(n){let a=n.code;throw a==="ENOENT"?C(e):a==="EACCES"||a==="EPERM"?P(e):a==="ENOTDIR"?q(e):a==="ELOOP"?J(e):a==="ENAMETOOLONG"?j(e):X(e,n)}if(!i.isFile())throw W(e);try{await Be(e,Pe.R_OK)}catch{throw P(e)}if(await fe(e)){if(!await S())throw w(e);let n;try{n=await de(e)}catch(a){throw B(e,"heic",a)}if(n.width===0||n.height===0)throw B(e,"heic",void 0);return{kind:"image",path:e,format:"heic",width:n.width,height:n.height,bytes:i.size,hasAlpha:n.hasAlpha,frames:1}}let t=await b(),r;try{r=await t(e).metadata()}catch(n){throw K(e,n)}return{kind:"image",path:e,format:He(e,r),width:r.autoOrient?.width??r.width??0,height:r.autoOrient?.height??r.height??0,bytes:i.size,hasAlpha:r.hasAlpha??!1,frames:r.pages??1}}function U(e,i,t){let r=t??m[i].defaultQuality;switch(i){case"jpeg":return e.jpeg({quality:r,mozjpeg:!0});case"webp":return e.webp({quality:r});case"avif":return e.avif({quality:r});case"png":return e.png({compressionLevel:9});case"gif":return e.gif();case"tiff":return e.tiff({compression:"deflate"});case"heic":throw new Error("heic is not writable; the capability graph should have prevented this");case"pdf":throw new Error("pdf is not an image target; the capability graph should have prevented this");case"docx":throw new Error("docx is not an image target; the capability graph should have prevented this");case"doc":throw new Error("doc is not an image target; the capability graph should have prevented this")}}async function Ce(e,i){let t=De(i);await R(i);let r=Ne(t,`.forge-tmp-${Ae(6).toString("hex")}-${ke(i)}`);try{return await Re(r,e),await te(r,i),e.length}catch(n){throw await Te(r,{force:!0}).catch(()=>{}),Q(i,n)}}async function z(e,i,t,r,n,a){if(e.kind!=="image")throw new Error("pipelineFor received a non-image source");if(n===void 0&&e.format==="heic"&&!await S())throw w(e.path);let o=n===void 0&&e.format==="heic"?await v(e.path):void 0,h=async()=>{await o?.cleanup()},s=(await b())(n??o?.path??e.path,r?{animated:!0}:{});if(s=s.rotate(),t.trim&&(s=s.trim()),t.resize){if(!a&&t.trim)throw new Error("pipelineFor needs the resolved size to resize a trimmed image");let l=a??D(e,t.resize);s=s.resize(l.width,l.height,{fit:"fill"})}return e.hasAlpha&&!m[i].hasAlpha&&(s=s.flatten({background:t.background})),s=t.keepMetadata?s.keepMetadata():s.keepIccProfile(),{pipeline:s,cleanup:h}}async function At(e,i){let t={background:"#ffffff",keepMetadata:!1},{pipeline:r,cleanup:n}=await z(e,"png",t,!1);try{await r.png({compressionLevel:1}).toFile(i)}finally{await n()}}async function Pt(e,i,t){let{pipeline:r,cleanup:n}=await z(e,i,t,!1);try{return await U(r,i,t.quality).toBuffer()}finally{await n()}}async function We(e){let i={width:e.width,height:e.height};if(e.frames>1)return{upright:i,trimmed:"animated"};if(e.format==="heic"&&!await S())throw w(e.path);let t=e.format==="heic"?await v(e.path):void 0;try{let r=await b(),{info:n}=await r(t?.path??e.path).rotate().trim().jpeg({quality:1}).toBuffer({resolveWithObject:!0});return n.width===i.width&&n.height===i.height?{upright:i,trimmed:"nothing"}:{upright:i,trimmed:{width:n.width,height:n.height}}}catch(r){throw A(r)?r:M(e.path,r)}finally{await t?.cleanup()}}async function qe(e,i){if(e.op!=="convert")throw new Error(`image engine cannot ${e.op}`);let t=e.sources[0],r=e.outputs[0];if(t.kind!=="image")throw new Error("the image engine cannot convert a document source");let n=m[e.target],a=[];i({phase:"reading"});let o=t.frames>1,h=o&&n.animatable;o&&!n.animatable&&a.push({code:"animation-flattened",message:`${F(t.path)} has ${t.frames} frames, and ${n.label} cannot animate. Only the first frame was converted.`});let d;if(e.options.trim||e.options.resize){let f={width:t.width,height:t.height};if(e.options.trim){if(o)throw ee(t.path);let{trimmed:u}=await We(t);if(u==="nothing"){if(!e.options.resize)throw Y(t.path);a.push({code:"nothing-trimmed",message:`${F(t.path)} has no empty edges; resized only.`})}else u!=="animated"&&(f=u)}if(e.options.resize&&(d=D(f,e.options.resize),ne(d)))throw Z(t.path,d)}i({phase:"decoding"});let{pipeline:s,cleanup:l}=await z(t,e.target,e.options,h,void 0,d);try{await R(r),i({phase:"encoding"});let f=await U(s,e.target,e.options.quality).toBuffer();i({phase:"writing"});let u=await Ce(f,r);return{job:e,outputBytes:u,warnings:a}}catch(f){throw A(f)?f:M(t.path,f)}finally{await l()}}async function Je(e){if(e.format!=="heic")return he(e.path);if(!await S())throw w(e.path);let i=await v(e.path);try{return await he(i.path)}finally{await i.cleanup()}}async function je(e){if(e.op!=="convert"||!m[e.target].lossy)return;let i=e.sources[0];if(i.kind!=="image")return;let t=await Je(i);return{ladder:[{}],measure:async r=>{let{pipeline:n}=await z(i,e.target,r,!1,t);return(await U(n,e.target,r.quality).toBuffer()).length}}}var Bt={id:"image",reads:Le,writes:Ue,ops:new Set(["convert"]),probe:_e,run:qe,measurer:je};export{Ke as a,k as b,Qe as c,ge as d,re as e,D as f,ne as g,g as h,b as i,et as j,tt as k,it as l,rt as m,nt as n,at as o,ot as p,S as q,v as r,fe as s,U as t,Ce as u,At as v,Pt as w,We as x,Bt as y};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{c as J,d as oe,e as E,g as B,h as se,i as ne,j as ae,k as ue,p as ie,q as pe,r as ce,t as de,u as fe,w as I,y}from"./chunk-RE7E6NA7.js";import{a as $,c as U,d as Y,e as F,f as K,k as Q}from"./chunk-M6LD6DHO.js";import{c as X,d as Z,e as _,f as ee,g as te,h as re}from"./chunk-VNAIHACR.js";import{e as V}from"./chunk-LI2JPLF7.js";import{a as H,c as L}from"./chunk-775ILWZI.js";import{a as g}from"./chunk-CXVYIBCA.js";import{I as D,J as q,M as z,b as P,c as w,d as R,da as G,g as x,s as A,u as k,w as W,z as C}from"./chunk-E5QDHFKQ.js";import{a as h,b as M}from"./chunk-J7FLFHQJ.js";import{readFile as Se}from"node:fs/promises";import{dirname as Re,resolve as je}from"node:path";async function le(e){let r=[],t=[...e.resolved.failures];for(let o of e.resolved.sources){let s=$(o);if(!s.includes(e.target)){t.push({path:o.path,error:W(o,e.target,s)});continue}let n=E({sourcePath:o.path,target:e.target,output:e.output,sourceRoot:e.resolved.roots.get(o.path)});r.push({op:"convert",sources:[o],outputs:[n],target:e.target,options:e.options})}return{jobs:r,failures:t}}import{resolve as ke}from"node:path";function $e(e,r=new Set){let t={path:ke(e.path),kind:e.kind,format:e.format,bytes:e.bytes},o=e.kind==="document"&&e.encrypted===!0,s={targets:$(e).filter(n=>!o||F(n)),actions:de([e],r).filter(n=>!o||n.id===B.id).map(n=>n.id)};return e.kind==="image"?{...t,width:e.width,height:e.height,...s}:{...t,pages:e.pages,encrypted:e.encrypted,...s}}async function me(e){let r=await y(e,{recursive:!1}),{installedExtensionIds:t}=await import("./available-QN6QAGCU.js"),o=await t();return{probes:r.sources.map(s=>$e(s,o)),failures:r.failures}}import{dirname as Fe}from"node:path";var S=e=>({cwd:e.cwd??process.cwd(),...e.home===void 0?{}:{home:e.home}});function ge(e,r){let t=P(Fe(e),S(r));return t==="."?"":` in ${t.endsWith("/")?t:`${t}/`}`}function he(e,r){let{pct:t,direction:o}=M(e,r);return o==="same"?"same size":`${t}% ${o}`}function ye(e,r={}){let t=e.results[0];if(!t)return[];let o=t.job.sources[0],s=t.job.outputs;if(s.length>1){let a=[`\u2713 ${w(o.path)} \u2192 ${s.length} files${ge(s[0],r)}`,` ${s.map(u=>w(u)).join(", ")}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} total`];for(let u of t.warnings)a.push("",`\u26A0 ${u.message}`);return a}let n=[`\u2713 ${w(o.path)} \u2192 ${P(s[0],S(r))}`,` ${h(o.bytes)} \u2192 ${h(t.outputBytes)} \xB7 ${he(o.bytes,t.outputBytes)}`];for(let a of t.warnings)n.push("",`\u26A0 ${a.message}`);return n}function be(e,r={}){let t=[`\u2713 ${e.results.length} converted`,` ${h(e.inputBytes)} \u2192 ${h(e.outputBytes)} \xB7 ${he(e.inputBytes,e.outputBytes)}`];for(let s of e.results)for(let n of s.job.outputs)t.push(` ${P(n,S(r))}`);let o=e.results.flatMap(s=>s.warnings);if(o.length>0){t.push("");for(let s of o)t.push(`\u26A0 ${s.message}`)}return t}function we(e,r={}){let t=e.results.flatMap(i=>i.job.outputs),o=t.map(i=>w(i)).join(", "),s=t.length===1?"file":"files",n=t[0]===void 0?"":ge(t[0],r),a=[`\u2713 ${t.length} ${s} \xB7 ${o}${n}`],u=e.results.flatMap(i=>i.warnings);for(let i of u)a.push("",`\u26A0 ${i.message}`);return a}function j(e,r){if(e.length===0)return[];let t=[];for(let o of e)t.push(...G(o.error,{debug:r.debug}),"");return t}function Ie(){let e=new Set(U()),r=new Set(Y()),t=["Formats",""];for(let s of e){let n=R[s],a=r.has(s)?"read and write":"read only";t.push(` ${n.label.padEnd(6)} ${n.extensions.join(" ").padEnd(12)} ${a}`)}let o=[...e].filter(s=>!r.has(s)).map(s=>R[s].label);if(o.length>0){let s=o.join(", "),[n,a]=o.length===1?["is","it"]:["are","them"];t.push("",`${s} ${n} read only because Forge cannot yet write ${a}.`)}return t}function ve(e,r={}){let t=[R[e.format].label,h(e.bytes)];return e.width!==void 0&&e.height!==void 0&&t.push(`${e.width}\xD7${e.height}`),e.pages!==void 0&&t.push(`${e.pages} ${e.pages===1?"page":"pages"}`),e.encrypted&&t.push("password-protected"),[`${P(e.path,S(r))} \xB7 ${t.join(" \xB7 ")}`,` converts to ${e.targets.join(", ")}`,` actions ${e.actions.join(", ")}`]}import{createInterface as Pe}from"node:readline";import{PassThrough as Ee}from"node:stream";function Be(e){return new Promise(r=>{let t=Pe({input:e,terminal:!1}),o=!1,s=n=>{if(o)return;o=!0,t.close(),e.pause(),e.unref?.(),r(n.replace(/\r$/,""))};t.once("line",s),t.once("close",()=>s(""))})}async function xe(e){if(e.stdin)return Be(process.stdin);if(!process.stdin.isTTY)return;let r=new Ee,t=Pe({input:process.stdin,output:r,terminal:!0});try{return process.stderr.write("Password: "),await new Promise(o=>t.question("",o))}finally{process.stderr.write(`
|
|
4
|
-
`),t.close()}}function N(e){return e.length===0?0:e.some(r=>r.error.code==="invalid-arguments")?2:1}function Oe(e,r){if(e.action==="merge")return{};if(e.action==="rotate")return{degrees:e.rotate};if(e.action==="extract")return{pages:e.pages,separate:e.separate?"many":"one"};if(e.action==="delete")return{pages:e.pages};let t=r.find(a=>a.kind==="document"),o=t?.pages??0,s=e.split;if(!s)throw D("--split needs a mode: every-page, every=N or at=N,N.");if(s.mode==="every-page")return{cuts:ie(o)};if(s.mode==="every-n")return{cuts:pe(o,s.n)};let n=Math.max(o-1,0);for(let a of s.after)if(!Number.isInteger(a)||a<1||a>n)throw q(String(a),`"${a}" is outside 1 and ${n} \u2014 ${t?w(t.path):"the document"} has ${o} pages.`,o);return{cuts:s.after.map(a=>a-1)}}function Ce(e,r){let t;return()=>r?(t??=xe({stdin:e}).then(o=>e&&o===""?void 0:o),t):Promise.resolve(void 0)}async function Je(e,r,t,o){let s;if(e.encrypted){if(s=r.password??await t(),s===void 0)return{failure:{path:e.path,error:C(e.path)}};let u;try{u=await V(await Se(e.path),s)}catch{return{failure:{path:e.path,error:C(e.path,{attempted:!0})}}}u.destroy()}let n;try{n=B.plan([e],{target:r.target,background:r.options.background,keepMetadata:r.options.keepMetadata,dpi:String(r.dpi??150),...r.options.quality===void 0?{}:{quality:r.options.quality},...r.pages===void 0?{}:{pages:r.pages},...r.output===void 0?{}:{destination:r.output},...o===void 0?{}:{sourceRoot:o}})}catch(u){if(!x(u))throw u;return{failure:{path:e.path,error:u}}}let a=n[0];if(a?.op!=="convert")throw new Error(`convertAction.plan() did not return a convert job for ${e.path}`);return s!==void 0&&(a.options.password=s),{job:a}}function O(e,r){return t=>{if(t.type==="search:attempt"){r||e.onSearch?.(t.rung.dpi===void 0?`attempt ${t.attempt} of ${t.of}`:`${t.rung.dpi} dpi \xB7 attempt ${t.attempt} of ${t.of}`);return}if(t.type==="search:settled"){r&&e.onSearch?.(`${t.completed} of ${t.total} searched`);return}r&&(t.type==="job:done"||t.type==="job:error")&&e.onProgress?.({completed:t.completed,total:t.total})}}var b=(e,r)=>({kind:e,results:[],failures:r,inputBytes:0,outputBytes:0});async function Ne(e){let r=await y(e.inputs,{recursive:!1});if(r.sources.length===0)return b("pageop",r.failures);let t=ce.find(a=>a.id===e.action);if(!t)throw new Error(`no action registered for "${e.action}"`);let o=r.sources[0]?.path??"";if(!t.appliesTo(r.sources)){let a=fe(t,r.sources)??"not available for these files";return b("pageop",[...r.failures,{path:o,error:k(e.action,a)}])}let s;try{s=t.plan(r.sources,Oe(e,r.sources))}catch(a){if(!x(a))throw a;return b("pageop",[...r.failures,{path:o,error:a}])}let n=await I(s,{force:e.force});return{kind:"pageop",results:n.results,failures:[...r.failures,...n.refusals,...n.failures],inputBytes:n.inputBytes,outputBytes:n.outputBytes}}async function Te(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=[],s=[];for(let u of t.sources){if(!J.appliesTo([u])){s.push({path:u.path,error:A(u)});continue}let i=e.output!==void 0&&!oe(e.output)?je(e.output):void 0,c=e.output===void 0||i!==void 0?Re(u.path):Re(E({sourcePath:u.path,target:u.format,output:e.output,sourceRoot:t.roots.get(u.path)})),[p]=J.plan([u],{mode:e.maxBytes===void 0?"quality":"size",...e.quality===void 0?{}:{quality:e.quality},destination:c});p?.op==="convert"&&(i!==void 0&&(p.outputs=[i]),e.dpi!==void 0&&(p.options.dpi=e.dpi),o.push(p))}let n=o.length>1;n&&r.onProgress?.({completed:0,total:o.length});let a=await I(o,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,n)});return{kind:"compress",results:a.results,failures:[...t.failures,...s,...a.refusals,...a.unreachable.map(u=>({path:u.job.sources[0].path,error:u.error})),...a.failures],inputBytes:a.inputBytes,outputBytes:a.outputBytes}}async function Me(e,r){let t=e.kind,o=e.op==="remove-background"?H(e.target):void 0;if(o)return b(t,[{path:"",error:o}]);let{installed:s}=await import("./paths-H2WS22BA.js"),n=await s(e.op);if(!n)return b(t,[{path:"",error:z(e.op)}]);if(e.op==="boost"&&e.scale!==void 0){let{assetFor:l,catalogEntry:f}=await import("./catalog-O3V24DK7.js"),d=f("boost"),v=d&&l(d)?.version,T=L(e.scale,n.version,v);if(T)return b(t,[{path:"",error:T}])}let a=await y(e.inputs,{recursive:e.recursive}),u=e.op==="boost"?ne:ae,i=[],c=[];for(let l of a.sources){if(!u.appliesTo([l])){c.push({path:l.path,error:k(e.op,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});continue}let f=se(l,e.target);if(f){c.push({path:l.path,error:f});continue}i.push(...u.plan([l],{target:e.target,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.scale===void 0?{}:{scale:e.scale},...e.options.quality===void 0?{}:{quality:e.options.quality},...e.output===void 0?{}:{output:e.output},roots:a.roots}))}let p=i.length>1;p&&r.onProgress?.({completed:0,total:i.length});let m=await I(i,{force:e.force,concurrency:1,...r.signal===void 0?{}:{signal:r.signal},onEvent:O(r,p)});return{kind:t,results:m.results,failures:[...a.failures,...c,...m.refusals,...m.failures],inputBytes:m.inputBytes,outputBytes:m.outputBytes}}async function Ae(e,r){let t=e.resize!==void 0?"resize":"trim",o=e.target===void 0?void 0:Q(e.target,t);if(o)return b(e.kind,[{path:"",error:o}]);let s=await y(e.inputs,{recursive:e.recursive}),n=[],a=[];for(let p of s.sources)p.kind==="image"?n.push(p):a.push({path:p.path,error:k(t,"it works on images, not documents","Try an image such as a JPEG, PNG, WebP or HEIC file.")});let u=ue(n,{trim:e.trim,...e.resize===void 0?{}:{resize:e.resize},...e.target===void 0?{}:{target:e.target},...e.output===void 0?{}:{output:e.output},roots:s.roots,background:e.options.background,keepMetadata:e.options.keepMetadata,...e.options.quality===void 0?{}:{quality:e.options.quality}}),i=u.length>1;i&&r.onProgress?.({completed:0,total:u.length});let c=await I(u,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},onEvent:O(r,i)});return{kind:e.kind,results:c.results,failures:[...s.failures,...a,...c.refusals,...c.failures],inputBytes:c.inputBytes,outputBytes:c.outputBytes}}async function We(e,r){let t=await y(e.inputs,{recursive:e.recursive}),o=d=>d.kind==="document"&&d.format==="pdf",s=F(e.target),n=s?t.sources.filter(o):[],a=s?t.sources.filter(d=>!o(d)):t.sources,u=[],i=[],c=Ce(e.passwordStdin??!1,r.interactive??!0);for(let d of n){let v=await Je(d,e,c,t.roots.get(d.path));"failure"in v?i.push(v.failure):u.push(v.job)}let p=await le({resolved:{sources:a,failures:[],roots:t.roots},target:e.target,options:e.options,force:e.force,...e.output===void 0?{}:{output:e.output}}),m=[...p.jobs,...u],l=m.length>1;l&&r.onProgress?.({completed:0,total:m.length});let f=await I(m,{force:e.force,...e.concurrency===void 0?{}:{concurrency:e.concurrency},...e.maxBytes===void 0?{}:{targetBytes:e.maxBytes},onEvent:O(r,l)});return{kind:"convert",results:f.results,failures:[...t.failures,...i,...p.failures,...f.refusals,...f.unreachable.map(d=>({path:d.job.sources[0].path,error:d.error})),...f.failures],inputBytes:f.inputBytes,outputBytes:f.outputBytes}}async function De(e,r={}){try{return e.kind==="pageop"?await Ne(e):e.kind==="extension-op"?await Me(e,r):e.kind==="edit"?await Ae(e,r):e.kind==="compress"?await Te(e,r):await We(e,r)}catch(t){if(!x(t))throw t;return b(e.kind,[{path:"",error:t}])}}function qe(e,r){let t=N(e.failures);if(r.json)return{exitCode:t,stdout:[JSON.stringify(X(g,e))],stderr:[]};let o=e.results.length===0?[]:e.kind==="pageop"?we(e):e.results.length===1?ye(e):be(e);return{exitCode:t,stdout:o,stderr:j(e.failures,{debug:r.debug})}}function ze(e,r){let t=[{path:"",error:e}],o=N(t);return r.json?{exitCode:o,stdout:[JSON.stringify(Z(g,e))],stderr:[]}:{exitCode:o,stdout:[],stderr:j(t,{debug:r.debug})}}async function Ge(e,r){let{runConfig:t}=await import("./config-command-UW6BYQ2K.js"),o=await t(e);return r?{exitCode:0,stdout:[JSON.stringify(te(g,o.config,o.warnings))],stderr:[]}:{exitCode:0,stdout:o.stdout,stderr:[]}}async function St(e,r={}){let t=r.json??!1,o="debug"in e?e.debug:!1;try{if(e.kind==="config")return await Ge(e,t);if(e.kind==="update"){let{runUpdate:s}=await import("./update-command-HT2RBFLR.js"),n=await s(g,{...r.onInstalling?{onInstalling:r.onInstalling}:{}});return{exitCode:0,stdout:t?[JSON.stringify({forge:g,ok:!0,...n.data})]:n.stdout,stderr:[]}}if(e.kind==="extensions"){let{runExtensions:s}=await import("./extensions-command-5QO6YX6O.js"),n=await s(e,{onDownload:r.onDownload});return{exitCode:0,stdout:t?[JSON.stringify(re(g,n.data))]:n.stdout,stderr:[]}}if(e.kind==="formats")return t?{exitCode:0,stdout:[JSON.stringify(_(g,K()))],stderr:[]}:{exitCode:0,stdout:Ie(),stderr:[]};if(e.kind==="probe"){let{probes:s,failures:n}=await me(e.inputs),a=N(n);return t?{exitCode:a,stdout:[JSON.stringify(ee(g,{probes:s,failures:n}))],stderr:[]}:{exitCode:a,stdout:s.flatMap((u,i)=>[...i>0?[""]:[],...ve(u)]),stderr:j(n,{debug:o})}}if(e.kind==="palette"||e.kind==="scale"){let{runPalette:s,runScale:n}=await import("./colour-LZ7EJ6H4.js"),a={json:t,colour:r.colour??!1};return e.kind==="palette"?await s(e,a):await n(e,a)}return e.kind==="shell"?{exitCode:0,stdout:[],stderr:[]}:qe(await De(e,r),{json:t,debug:o})}catch(s){if(!x(s))throw s;return ze(s,{json:t,debug:o})}}export{me as a,N as b,De as c,qe as d,St as e};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
var C="0.3.0",T={ok:"\u2713",fail:"\u2715",warn:"\u26A0",cursor:"\u276F",strip:"\u258C",star:"\u2605",arrow:"\u2192",tip:"\u2727",longArrow:"\u2500\u2500\u2192",longArrowDown:`\u2502
|
|
4
|
-
\u25BC`,dotFilled:"\u25CF",dotEmpty:"\u25CB"},r={name:"dark",fg:"#e7e7e7",dim:"#b0b0b0",accent:"#e5a23c",ok:"#6fcf7f",warn:"#e5c07b",fail:"#e8796d",failTint:"#2e2020",failTintDim:"#b0b0b0",larger:"#f2994a",shedHatch:"#47774f",grownFill:"#403225",tag:"#63c1d8",label:"#a68ce0",modeConvert:"#55c7d9",modeConvertBg:"#122c33",modeCompress:"#79c98b",modeCompressBg:"#182c1e",modePdf:"#ff6b4a",modePdfBg:"#361c16",modeColour:"#f27ba8",modeColourBg:"#3a1e2b",modeEnhance:"#b39ae8",modeEnhanceBg:"#2a2238",border:"#808080",selectionBg:"#2c2c2c",band:"#2c2c2c",canvas:"#1e1e1e",textSelectionBg:"#3f5c86",brand:"#e5a23c",keycapBg:"#333333",violet:"#a68ce0",faint:"#4d4d4d",listBand:"#323232",shelf:"#242424",tabChip:"#262626",panelBand:"#404040",ink:"#0c1d22",track:"#2e2e2e",trackFill:"#515151",thumb:"#e7e7e7",folderChip:"#414141",pill:"#e7e7e7",fieldBand:"#3d3d3d",defaultTagBg:"#33261a",defaultTag:"#c98a4b",newTagBg:"#2a3448",newTag:"#4f77c5"},o={name:"light",fg:"#262626",dim:"#4f4f4f",accent:"#915a01",ok:"#0e702c",warn:"#8a6100",fail:"#a43c32",failTint:"#f9e3df",failTintDim:"#4a4a4a",larger:"#8b4d01",shedHatch:"#87b896",grownFill:"#ece3d6",tag:"#0a6b86",label:"#5e4b99",modeConvert:"#036b7b",modeConvertBg:"#e6f7fa",modeCompress:"#24733a",modeCompressBg:"#eaf5ec",modePdf:"#b82a06",modePdfBg:"#fceee9",modeColour:"#b0306a",modeColourBg:"#f7e3ec",modeEnhance:"#64569f",modeEnhanceBg:"#f0ebfa",border:"#767676",selectionBg:"#e4e4e4",band:"#e4e4e4",canvas:"#ffffff",textSelectionBg:"#b9cfe8",brand:"#915a01",keycapBg:"#e1e1e1",violet:"#5e4b99",faint:"#b2b2b2",listBand:"#dcdcdc",shelf:"#f3f3f3",tabChip:"#f0f0f0",panelBand:"#d5d5d5",ink:"#ffffff",track:"#e4e4e4",trackFill:"#afafaf",thumb:"#262626",folderChip:"#d0d0d0",pill:"#262626",fieldBand:"#d7d7d7",defaultTagBg:"#f5e2cc",defaultTag:"#8f5000",newTagBg:"#e1e7f4",newTag:"#3358a3"},f={name:"neutral",fg:"",dim:"gray",accent:"yellow",ok:"green",warn:"yellow",fail:"red",failTint:"",failTintDim:"gray",larger:"yellow",shedHatch:"green",grownFill:"",tag:"cyan",label:"magenta",modeConvert:"cyan",modeConvertBg:"",modeCompress:"green",modeCompressBg:"",modePdf:"red",modePdfBg:"",modeColour:"magenta",modeColourBg:"",modeEnhance:"magenta",modeEnhanceBg:"",border:"gray",selectionBg:"",band:"",canvas:"",textSelectionBg:"",brand:"yellow",keycapBg:"",violet:"magenta",faint:"gray",listBand:"",shelf:"",tabChip:"",panelBand:"",ink:"",track:"",trackFill:"",thumb:"",folderChip:"",pill:"",fieldBand:"",defaultTagBg:"",defaultTag:"",newTagBg:"",newTag:""},a=["convert","compress","pdf","enhance","colour"],v=`1\u2013${a.length}`;function P(e){return/^[1-9]$/.test(e)?a[Number(e)-1]:void 0}var S={convert:"\u2194",compress:"\u2193",pdf:"\u25A3",colour:"\u25D0",enhance:"\u2726"},c="#7d6ad0";function l(e,n){return n==="compress"?{fg:e.modeCompress,bg:e.modeCompressBg}:n==="pdf"?{fg:e.modePdf,bg:e.modePdfBg}:n==="colour"?{fg:e.modeColour,bg:e.modeColourBg}:n==="enhance"?{fg:e.modeEnhance,bg:e.modeEnhanceBg}:{fg:e.modeConvert,bg:e.modeConvertBg}}var i=["#f26e69","#e5a23c","#ace02c","#55c7d9","#6579fd","#ad95e9"],g=["#e5a23c","#f2cf6b"],s={convert:["#1e96a7","#1e94b3","#1e92c0","#1d8ed2","#1b86ef","#4a7df8","#6974f8","#816af8","#995cf8"],compress:["#24b459","#22ab6d","#21a479","#209f81","#1f9c89","#1f9a91","#1e9998","#1e97a0","#1e96a7"],pdf:["#eb4319","#e3541a","#de601b","#db6a1c","#d9731d","#d87c1e","#d8841f","#d98c20","#d99522"],enhance:["#9b5af8","#985cf8","#965ef8","#945ff8","#9161f8","#8f62f8","#8d64f8","#8a65f8","#8867f8"],colour:["#f42335","#e05b1a","#d87d1e","#da9b23","#d2b427","#b4c027","#5bbf23","#20a27c","#1e989b","#1e94b6","#1c8cd9","#577af8","#7371f8","#8568f8","#965df8"]},m=["#d99522","#da9822","#da9b23","#da9f24","#d9a224","#d9a525","#d8a825","#d7ab26","#d6ad26"],b={convert:["#d6f7fd","#ddf5fe","#e1f4fe","#e4f2fe","#e7f1fe","#eaf0fe","#eceffe","#efeefe","#f1edfe"],compress:["#e0f7e4","#def8e7","#dcf8ea","#daf8ed","#d8f8f1","#d7f8f4","#d6f8f7","#d6f8fa","#d6f7fd"],pdf:["#feece7","#feece6","#feece5","#feece3","#feece2","#feede0","#feedde","#feeddc","#feeed9"],enhance:["#f2edfe","#f1edfe","#f1edfe","#f1eefe","#f0eefe","#f0eefe","#f0eefe","#f0eefe","#efeefe"],colour:["#feebe9","#feece5","#feede0","#feeed7","#f7f1d6","#eff3d9","#e5f6df","#dbf8eb","#d6f8f8","#def5fe","#e5f2fe","#ebf0fe","#edeffe","#efeefe","#f1edfe"]},u=["#feeed9","#feeed8","#feeed7","#fdeed6","#fcefd6","#fbefd6","#fbefd6","#faefd6","#f9f0d6"],B={convert:["#138291","#8467bd"],compress:["#2b8748","#138291"],pdf:["#d54322","#a06c10"],enhance:["#8567bc","#7b67cd"],colour:["#cb4b49","#a06c10","#618110","#138291","#5869ec","#8268bd"]};function h(e,n){return e.name==="light"?n==="commands"?m:s[n]:n==="commands"?e.name==="dark"?g:[e.brand]:n==="compress"?[e.modeCompress,e.modeConvert]:n==="pdf"?[e.modePdf,e.brand]:n==="colour"?e.name==="dark"?i:[e.modeColour,e.violet]:n==="enhance"?[e.modeEnhance,e.name==="dark"?c:e.violet]:[e.modeConvert,e.violet]}function k(e,n){if(e.name==="light")return n==="commands"?u:b[n]}function x(e,n){return e.name==="light"?B[n]:h(e,n)}function y(e){return{...e,accent:e.brand,tag:e.brand,label:e.brand}}function E(e,n){let{fg:t,bg:d}=l(e,n);return{...e,accent:t,tag:t,label:t,band:d===""?e.band:d}}function w(e){return e.name==="light"&&e.canvas!==""}function M(e){return e==="dark"?r:e==="light"?o:f}function O(e){return e===""?void 0:e}var R={filled:"\u2501",empty:"\u2501",knob:"\u25CF"};function p(){return process.env.NO_COLOR!==void 0&&process.env.NO_COLOR!==""?!1:process.stdout.isTTY===!0}function D(){p()||(process.env.FORCE_COLOR="0")}export{C as a,T as b,r as c,o as d,f as e,a as f,v as g,P as h,S as i,l as j,h as k,k as l,x as m,y as n,E as o,w as p,M as q,O as r,R as s,p as t,D as u};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createRequire as __forgeCreateRequire } from 'node:module';
|
|
2
|
-
const require = __forgeCreateRequire(import.meta.url);
|
|
3
|
-
import{b as h,c as b,d as A,e as F,f as x,g as w,h as R}from"./chunk-QVACE4IE.js";import{i as M}from"./chunk-LI2JPLF7.js";import{i as L,q as O,r as j}from"./chunk-775ILWZI.js";import{d as k,g as C,p as v,r as I,x as S}from"./chunk-E5QDHFKQ.js";var D=[[15,"rose"],[45,"red"],[70,"orange"],[95,"amber"],[120,"yellow"],[140,"lime"],[165,"green"],[185,"teal"],[215,"cyan"],[250,"sky"],[280,"blue"],[295,"indigo"],[315,"violet"],[340,"purple"],[355,"pink"],[360,"rose"]];function T(t){let{C:e,h:r}=x(b(t));return e<.03?"grey":(D.find(([n])=>r<n)??[360,"rose"])[1]}var d=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),z=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"colour",$='font-family="Inter"';function P(t,e,r,n="light"){let o=n==="dark",i=o?"#FAFAFA":"#111111",s=o?"#A1A1AA":"#71717A",c=o?"#FFFFFF":"#000000",a=r.length>8?64:104,l=10,g=48+r.length*a+Math.max(0,r.length-1)*l,m=84+a+56,p=a>80?12:10,f=`<text id="title" x="24" y="38" ${$} font-size="15" font-weight="600" fill="${i}">${d(t)}</text><text id="subtitle" x="24" y="58" ${$} font-size="12" fill="${s}">${d(e)}</text>`,U=r.map((u,W)=>`<g id="${z(u.id)}" transform="translate(${24+W*(a+l)} 80)"><rect id="swatch" width="${a}" height="${a}" rx="${p}" fill="${u.hex}" stroke="${c}" stroke-opacity="0.08"/><text id="name" x="1" y="${a+22}" ${$} font-size="13" font-weight="600" fill="${i}">${d(u.name)}</text><text id="value" x="1" y="${a+40}" ${$} font-size="11" fill="${s}">${d(u.value)}</text></g>`).join(`
|
|
4
|
-
`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${g}" height="${m}" viewBox="0 0 ${g} ${m}">
|
|
5
|
-
<g id="${z(t)}">
|
|
6
|
-
<rect id="card" width="${g}" height="${m}" rx="0" fill="${o?"#18181B":"#FFFFFF"}"/>
|
|
7
|
-
${f}
|
|
8
|
-
${U}
|
|
9
|
-
</g>
|
|
10
|
-
</svg>`}function Z(t,e,r="light",n){let o=t.replace(/\.[^.]+$/,""),i=e.length;return P(t,n?`${i} shade${i===1?"":"s"} of ${n}`:`${i} colour${i===1?"":"s"}, most of the image first`,e.map((s,c)=>({id:`${o}-${c+1}`,name:s.hex,value:R(s.rgb),hex:s.hex})),r)}function _(t,e,r="light"){let n=T(t);return P(`${n[0]?.toUpperCase()??""}${n.slice(1)}`,`from ${h(t)} \xB7 50\u2013950 in OKLCH`,e.map(o=>({id:`${n}-${o.step}`,name:String(o.step),value:o.hex,hex:o.hex})),r)}var y=t=>{let e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4},B=({r:t,g:e,b:r})=>.2126*y(t)+.7152*y(e)+.0722*y(r);function E(t,e){let[r,n]=[B(t),B(e)].sort((o,i)=>i-o);return(r+.05)/(n+.05)}function et(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"large":"fails"}var G={r:255,g:255,b:255},N={r:0,g:0,b:0},H=t=>Math.floor(t*10)/10;function rt(t){return{white:H(E(t,G)),black:H(E(t,N))}}var K=[50,100,200,300,400,500,600,700,800,900,950],q=[1,.86,.68,.46,.22],J=[.2,.4,.6,.8,1];function it(t){let{L:e,C:r,h:n}=x(b(t)),o=r<.015,i=Math.max(.975,e),s=e<.16?.42*e:Math.max(.16,.42*e);return K.map((c,a)=>{if(a===5)return{step:c,rgb:{...t},hex:h(t),reference:!0};let l=a<5,g=l?q[a]:J[a-6],m=l?e+(i-e)*g:e-(e-s)*g,p=o?0:r*(l?1-.88*g:1-.45*g);for(;p>0&&!F(w({L:m,C:p,h:n}));)p-=.002;let f=A(w({L:m,C:Math.max(0,p),h:n}));return{step:c,rgb:f,hex:h(f),reference:!1}})}async function pt(t,e=192){let r=await M(t);if(r.kind!=="image")throw v(t,`a ${k[r.format].label}`);let n=r.format==="heic";if(n&&!await O())throw I(t);let o=n?await j(t):void 0;try{let s=(await L())(o?.path??t,{animated:!1}),{data:c,info:a}=await(n?s:s.rotate()).resize(e,e,{fit:"inside",withoutEnlargement:!0}).ensureAlpha().raw().toBuffer({resolveWithObject:!0});return{source:r,pixels:{width:a.width,height:a.height,rgba:new Uint8Array(c.buffer,c.byteOffset,c.length)}}}catch(i){throw C(i)?i:S(t,i)}finally{await o?.cleanup()}}export{Z as a,_ as b,E as c,et as d,rt as e,it as f,pt as g};
|