UNPKG

blocklypy

Version:

BlocklyPy: SPIKE to Pybricks - word-block converter to Pybricks python code

33 lines 1.26 MB
#!/usr/bin/env node "use strict";const b1=require("node:events"),gh=require("node:child_process"),F1=require("node:path"),D1=require("node:fs"),A1=require("node:process"),bf=require("canvas"),Eh=require("path"),di=require("fs");var gn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function dl(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Or={},No={},Io={},Ff;function Zo(){if(Ff)return Io;Ff=1;class n extends Error{constructor(a,o,u){super(u),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=o,this.exitCode=a,this.nestedError=void 0}}class e extends n{constructor(a){super(1,"commander.invalidArgument",a),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}return Io.CommanderError=n,Io.InvalidArgumentError=e,Io}var Df;function _l(){if(Df)return No;Df=1;const{InvalidArgumentError:n}=Zo();class e{constructor(o,u){switch(this.description=u||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,o[0]){case"<":this.required=!0,this._name=o.slice(1,-1);break;case"[":this.required=!1,this._name=o.slice(1,-1);break;default:this.required=!0,this._name=o;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(o,u){return u===this.defaultValue||!Array.isArray(u)?[o]:u.concat(o)}default(o,u){return this.defaultValue=o,this.defaultValueDescription=u,this}argParser(o){return this.parseArg=o,this}choices(o){return this.argChoices=o.slice(),this.parseArg=(u,c)=>{if(!this.argChoices.includes(u))throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(u,c):u},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function t(a){const o=a.name()+(a.variadic===!0?"...":"");return a.required?"<"+o+">":"["+o+"]"}return No.Argument=e,No.humanReadableArgName=t,No}var Lo={},Po={},Af;function Oh(){if(Af)return Po;Af=1;const{humanReadableArgName:n}=_l();class e{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(o){this.helpWidth=this.helpWidth??o.helpWidth??80}visibleCommands(o){const u=o.commands.filter(l=>!l._hidden),c=o._getHelpCommand();return c&&!c._hidden&&u.push(c),this.sortSubcommands&&u.sort((l,p)=>l.name().localeCompare(p.name())),u}compareOptions(o,u){const c=l=>l.short?l.short.replace(/^-/,""):l.long.replace(/^--/,"");return c(o).localeCompare(c(u))}visibleOptions(o){const u=o.options.filter(l=>!l.hidden),c=o._getHelpOption();if(c&&!c.hidden){const l=c.short&&o._findOption(c.short),p=c.long&&o._findOption(c.long);!l&&!p?u.push(c):c.long&&!p?u.push(o.createOption(c.long,c.description)):c.short&&!l&&u.push(o.createOption(c.short,c.description))}return this.sortOptions&&u.sort(this.compareOptions),u}visibleGlobalOptions(o){if(!this.showGlobalOptions)return[];const u=[];for(let c=o.parent;c;c=c.parent){const l=c.options.filter(p=>!p.hidden);u.push(...l)}return this.sortOptions&&u.sort(this.compareOptions),u}visibleArguments(o){return o._argsDescription&&o.registeredArguments.forEach(u=>{u.description=u.description||o._argsDescription[u.name()]||""}),o.registeredArguments.find(u=>u.description)?o.registeredArguments:[]}subcommandTerm(o){const u=o.registeredArguments.map(c=>n(c)).join(" ");return o._name+(o._aliases[0]?"|"+o._aliases[0]:"")+(o.options.length?" [options]":"")+(u?" "+u:"")}optionTerm(o){return o.flags}argumentTerm(o){return o.name()}longestSubcommandTermLength(o,u){return u.visibleCommands(o).reduce((c,l)=>Math.max(c,this.displayWidth(u.styleSubcommandTerm(u.subcommandTerm(l)))),0)}longestOptionTermLength(o,u){return u.visibleOptions(o).reduce((c,l)=>Math.max(c,this.displayWidth(u.styleOptionTerm(u.optionTerm(l)))),0)}longestGlobalOptionTermLength(o,u){return u.visibleGlobalOptions(o).reduce((c,l)=>Math.max(c,this.displayWidth(u.styleOptionTerm(u.optionTerm(l)))),0)}longestArgumentTermLength(o,u){return u.visibleArguments(o).reduce((c,l)=>Math.max(c,this.displayWidth(u.styleArgumentTerm(u.argumentTerm(l)))),0)}commandUsage(o){let u=o._name;o._aliases[0]&&(u=u+"|"+o._aliases[0]);let c="";for(let l=o.parent;l;l=l.parent)c=l.name()+" "+c;return c+u+" "+o.usage()}commandDescription(o){return o.description()}subcommandDescription(o){return o.summary()||o.description()}optionDescription(o){const u=[];if(o.argChoices&&u.push(`choices: ${o.argChoices.map(c=>JSON.stringify(c)).join(", ")}`),o.defaultValue!==void 0&&(o.required||o.optional||o.isBoolean()&&typeof o.defaultValue=="boolean")&&u.push(`default: ${o.defaultValueDescription||JSON.stringify(o.defaultValue)}`),o.presetArg!==void 0&&o.optional&&u.push(`preset: ${JSON.stringify(o.presetArg)}`),o.envVar!==void 0&&u.push(`env: ${o.envVar}`),u.length>0){const c=`(${u.join(", ")})`;return o.description?`${o.description} ${c}`:c}return o.description}argumentDescription(o){const u=[];if(o.argChoices&&u.push(`choices: ${o.argChoices.map(c=>JSON.stringify(c)).join(", ")}`),o.defaultValue!==void 0&&u.push(`default: ${o.defaultValueDescription||JSON.stringify(o.defaultValue)}`),u.length>0){const c=`(${u.join(", ")})`;return o.description?`${o.description} ${c}`:c}return o.description}formatItemList(o,u,c){return u.length===0?[]:[c.styleTitle(o),...u,""]}groupItems(o,u,c){const l=new Map;return o.forEach(p=>{const m=c(p);l.has(m)||l.set(m,[])}),u.forEach(p=>{const m=c(p);l.has(m)||l.set(m,[]),l.get(m).push(p)}),l}formatHelp(o,u){const c=u.padWidth(o,u),l=u.helpWidth??80;function p(I,R){return u.formatItem(I,c,R,u)}let m=[`${u.styleTitle("Usage:")} ${u.styleUsage(u.commandUsage(o))}`,""];const v=u.commandDescription(o);v.length>0&&(m=m.concat([u.boxWrap(u.styleCommandDescription(v),l),""]));const w=u.visibleArguments(o).map(I=>p(u.styleArgumentTerm(u.argumentTerm(I)),u.styleArgumentDescription(u.argumentDescription(I))));if(m=m.concat(this.formatItemList("Arguments:",w,u)),this.groupItems(o.options,u.visibleOptions(o),I=>I.helpGroupHeading??"Options:").forEach((I,R)=>{const M=I.map(d=>p(u.styleOptionTerm(u.optionTerm(d)),u.styleOptionDescription(u.optionDescription(d))));m=m.concat(this.formatItemList(R,M,u))}),u.showGlobalOptions){const I=u.visibleGlobalOptions(o).map(R=>p(u.styleOptionTerm(u.optionTerm(R)),u.styleOptionDescription(u.optionDescription(R))));m=m.concat(this.formatItemList("Global Options:",I,u))}return this.groupItems(o.commands,u.visibleCommands(o),I=>I.helpGroup()||"Commands:").forEach((I,R)=>{const M=I.map(d=>p(u.styleSubcommandTerm(u.subcommandTerm(d)),u.styleSubcommandDescription(u.subcommandDescription(d))));m=m.concat(this.formatItemList(R,M,u))}),m.join(` `)}displayWidth(o){return t(o).length}styleTitle(o){return o}styleUsage(o){return o.split(" ").map(u=>u==="[options]"?this.styleOptionText(u):u==="[command]"?this.styleSubcommandText(u):u[0]==="["||u[0]==="<"?this.styleArgumentText(u):this.styleCommandText(u)).join(" ")}styleCommandDescription(o){return this.styleDescriptionText(o)}styleOptionDescription(o){return this.styleDescriptionText(o)}styleSubcommandDescription(o){return this.styleDescriptionText(o)}styleArgumentDescription(o){return this.styleDescriptionText(o)}styleDescriptionText(o){return o}styleOptionTerm(o){return this.styleOptionText(o)}styleSubcommandTerm(o){return o.split(" ").map(u=>u==="[options]"?this.styleOptionText(u):u[0]==="["||u[0]==="<"?this.styleArgumentText(u):this.styleSubcommandText(u)).join(" ")}styleArgumentTerm(o){return this.styleArgumentText(o)}styleOptionText(o){return o}styleArgumentText(o){return o}styleSubcommandText(o){return o}styleCommandText(o){return o}padWidth(o,u){return Math.max(u.longestOptionTermLength(o,u),u.longestGlobalOptionTermLength(o,u),u.longestSubcommandTermLength(o,u),u.longestArgumentTermLength(o,u))}preformatted(o){return/\n[^\S\r\n]/.test(o)}formatItem(o,u,c,l){const m=" ".repeat(2);if(!c)return m+o;const v=o.padEnd(u+o.length-l.displayWidth(o)),w=2,C=(this.helpWidth??80)-u-w-2;let I;return C<this.minWidthToWrap||l.preformatted(c)?I=c:I=l.boxWrap(c,C).replace(/\n/g,` `+" ".repeat(u+w)),m+v+" ".repeat(w)+I.replace(/\n/g,` ${m}`)}boxWrap(o,u){if(u<this.minWidthToWrap)return o;const c=o.split(/\r\n|\n/),l=/[\s]*[^\s]+/g,p=[];return c.forEach(m=>{const v=m.match(l);if(v===null){p.push("");return}let w=[v.shift()],S=this.displayWidth(w[0]);v.forEach(C=>{const I=this.displayWidth(C);if(S+I<=u){w.push(C),S+=I;return}p.push(w.join(""));const R=C.trimStart();w=[R],S=this.displayWidth(R)}),p.push(w.join(""))}),p.join(` `)}}function t(a){const o=/\x1b\[\d*(;\d*)*m/g;return a.replace(o,"")}return Po.Help=e,Po.stripColor=t,Po}var So={},Uf;function Ch(){if(Uf)return So;Uf=1;const{InvalidArgumentError:n}=Zo();class e{constructor(c,l){this.flags=c,this.description=l||"",this.required=c.includes("<"),this.optional=c.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(c),this.mandatory=!1;const p=o(c);this.short=p.shortFlag,this.long=p.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(c,l){return this.defaultValue=c,this.defaultValueDescription=l,this}preset(c){return this.presetArg=c,this}conflicts(c){return this.conflictsWith=this.conflictsWith.concat(c),this}implies(c){let l=c;return typeof c=="string"&&(l={[c]:!0}),this.implied=Object.assign(this.implied||{},l),this}env(c){return this.envVar=c,this}argParser(c){return this.parseArg=c,this}makeOptionMandatory(c=!0){return this.mandatory=!!c,this}hideHelp(c=!0){return this.hidden=!!c,this}_concatValue(c,l){return l===this.defaultValue||!Array.isArray(l)?[c]:l.concat(c)}choices(c){return this.argChoices=c.slice(),this.parseArg=(l,p)=>{if(!this.argChoices.includes(l))throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(l,p):l},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?a(this.name().replace(/^no-/,"")):a(this.name())}helpGroup(c){return this.helpGroupHeading=c,this}is(c){return this.short===c||this.long===c}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class t{constructor(c){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,c.forEach(l=>{l.negate?this.negativeOptions.set(l.attributeName(),l):this.positiveOptions.set(l.attributeName(),l)}),this.negativeOptions.forEach((l,p)=>{this.positiveOptions.has(p)&&this.dualOptions.add(p)})}valueFromOption(c,l){const p=l.attributeName();if(!this.dualOptions.has(p))return!0;const m=this.negativeOptions.get(p).presetArg,v=m!==void 0?m:!1;return l.negate===(v===c)}}function a(u){return u.split("-").reduce((c,l)=>c+l[0].toUpperCase()+l.slice(1))}function o(u){let c,l;const p=/^-[^-]$/,m=/^--[^-]/,v=u.split(/[ |,]+/).concat("guard");if(p.test(v[0])&&(c=v.shift()),m.test(v[0])&&(l=v.shift()),!c&&p.test(v[0])&&(c=v.shift()),!c&&m.test(v[0])&&(c=l,l=v.shift()),v[0].startsWith("-")){const w=v[0],S=`option creation failed due to '${w}' in option flags '${u}'`;throw/^-[^-][^-]/.test(w)?new Error(`${S} - a short flag is a single dash and a single character - either use a single dash and a single character (for a short flag) - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):p.test(w)?new Error(`${S} - too many short flags`):m.test(w)?new Error(`${S} - too many long flags`):new Error(`${S} - unrecognised flag format`)}if(c===void 0&&l===void 0)throw new Error(`option creation failed due to no flags found in '${u}'.`);return{shortFlag:c,longFlag:l}}return So.Option=e,So.DualOptions=t,So}var Hu={},kf;function U1(){if(kf)return Hu;kf=1;const n=3;function e(a,o){if(Math.abs(a.length-o.length)>n)return Math.max(a.length,o.length);const u=[];for(let c=0;c<=a.length;c++)u[c]=[c];for(let c=0;c<=o.length;c++)u[0][c]=c;for(let c=1;c<=o.length;c++)for(let l=1;l<=a.length;l++){let p=1;a[l-1]===o[c-1]?p=0:p=1,u[l][c]=Math.min(u[l-1][c]+1,u[l][c-1]+1,u[l-1][c-1]+p),l>1&&c>1&&a[l-1]===o[c-2]&&a[l-2]===o[c-1]&&(u[l][c]=Math.min(u[l][c],u[l-2][c-2]+1))}return u[a.length][o.length]}function t(a,o){if(!o||o.length===0)return"";o=Array.from(new Set(o));const u=a.startsWith("--");u&&(a=a.slice(2),o=o.map(m=>m.slice(2)));let c=[],l=n;const p=.4;return o.forEach(m=>{if(m.length<=1)return;const v=e(a,m),w=Math.max(a.length,m.length);(w-v)/w>p&&(v<l?(l=v,c=[m]):v===l&&c.push(m))}),c.sort((m,v)=>m.localeCompare(v)),u&&(c=c.map(m=>`--${m}`)),c.length>1?` (Did you mean one of ${c.join(", ")}?)`:c.length===1?` (Did you mean ${c[0]}?)`:""}return Hu.suggestSimilar=t,Hu}var Vf;function k1(){if(Vf)return Lo;Vf=1;const n=b1.EventEmitter,e=gh,t=F1,a=D1,o=A1,{Argument:u,humanReadableArgName:c}=_l(),{CommanderError:l}=Zo(),{Help:p,stripColor:m}=Oh(),{Option:v,DualOptions:w}=Ch(),{suggestSimilar:S}=U1();class C extends n{constructor(d){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=d||"",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:O=>o.stdout.write(O),writeErr:O=>o.stderr.write(O),outputError:(O,N)=>N(O),getOutHelpWidth:()=>o.stdout.isTTY?o.stdout.columns:void 0,getErrHelpWidth:()=>o.stderr.isTTY?o.stderr.columns:void 0,getOutHasColors:()=>R()??(o.stdout.isTTY&&o.stdout.hasColors?.()),getErrHasColors:()=>R()??(o.stderr.isTTY&&o.stderr.hasColors?.()),stripColor:O=>m(O)},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(d){return this._outputConfiguration=d._outputConfiguration,this._helpOption=d._helpOption,this._helpCommand=d._helpCommand,this._helpConfiguration=d._helpConfiguration,this._exitCallback=d._exitCallback,this._storeOptionsAsProperties=d._storeOptionsAsProperties,this._combineFlagAndOptionalValue=d._combineFlagAndOptionalValue,this._allowExcessArguments=d._allowExcessArguments,this._enablePositionalOptions=d._enablePositionalOptions,this._showHelpAfterError=d._showHelpAfterError,this._showSuggestionAfterError=d._showSuggestionAfterError,this}_getCommandAndAncestors(){const d=[];for(let O=this;O;O=O.parent)d.push(O);return d}command(d,O,N){let b=O,B=N;typeof b=="object"&&b!==null&&(B=b,b=null),B=B||{};const[,V,Y]=d.match(/([^ ]+) *(.*)/),rt=this.createCommand(V);return b&&(rt.description(b),rt._executableHandler=!0),B.isDefault&&(this._defaultCommandName=rt._name),rt._hidden=!!(B.noHelp||B.hidden),rt._executableFile=B.executableFile||null,Y&&rt.arguments(Y),this._registerCommand(rt),rt.parent=this,rt.copyInheritedSettings(this),b?this:rt}createCommand(d){return new C(d)}createHelp(){return Object.assign(new p,this.configureHelp())}configureHelp(d){return d===void 0?this._helpConfiguration:(this._helpConfiguration=d,this)}configureOutput(d){return d===void 0?this._outputConfiguration:(this._outputConfiguration=Object.assign({},this._outputConfiguration,d),this)}showHelpAfterError(d=!0){return typeof d!="string"&&(d=!!d),this._showHelpAfterError=d,this}showSuggestionAfterError(d=!0){return this._showSuggestionAfterError=!!d,this}addCommand(d,O){if(!d._name)throw new Error(`Command passed to .addCommand() must have a name - specify the name in Command constructor or using .name()`);return O=O||{},O.isDefault&&(this._defaultCommandName=d._name),(O.noHelp||O.hidden)&&(d._hidden=!0),this._registerCommand(d),d.parent=this,d._checkForBrokenPassThrough(),this}createArgument(d,O){return new u(d,O)}argument(d,O,N,b){const B=this.createArgument(d,O);return typeof N=="function"?B.default(b).argParser(N):B.default(N),this.addArgument(B),this}arguments(d){return d.trim().split(/ +/).forEach(O=>{this.argument(O)}),this}addArgument(d){const O=this.registeredArguments.slice(-1)[0];if(O&&O.variadic)throw new Error(`only the last argument can be variadic '${O.name()}'`);if(d.required&&d.defaultValue!==void 0&&d.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${d.name()}'`);return this.registeredArguments.push(d),this}helpCommand(d,O){if(typeof d=="boolean")return this._addImplicitHelpCommand=d,d&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;const N=d??"help [command]",[,b,B]=N.match(/([^ ]+) *(.*)/),V=O??"display help for command",Y=this.createCommand(b);return Y.helpOption(!1),B&&Y.arguments(B),V&&Y.description(V),this._addImplicitHelpCommand=!0,this._helpCommand=Y,(d||O)&&this._initCommandGroup(Y),this}addHelpCommand(d,O){return typeof d!="object"?(this.helpCommand(d,O),this):(this._addImplicitHelpCommand=!0,this._helpCommand=d,this._initCommandGroup(d),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(d,O){const N=["preSubcommand","preAction","postAction"];if(!N.includes(d))throw new Error(`Unexpected value for event passed to hook : '${d}'. Expecting one of '${N.join("', '")}'`);return this._lifeCycleHooks[d]?this._lifeCycleHooks[d].push(O):this._lifeCycleHooks[d]=[O],this}exitOverride(d){return d?this._exitCallback=d:this._exitCallback=O=>{if(O.code!=="commander.executeSubCommandAsync")throw O},this}_exit(d,O,N){this._exitCallback&&this._exitCallback(new l(d,O,N)),o.exit(d)}action(d){const O=N=>{const b=this.registeredArguments.length,B=N.slice(0,b);return this._storeOptionsAsProperties?B[b]=this:B[b]=this.opts(),B.push(this),d.apply(this,B)};return this._actionHandler=O,this}createOption(d,O){return new v(d,O)}_callParseArg(d,O,N,b){try{return d.parseArg(O,N)}catch(B){if(B.code==="commander.invalidArgument"){const V=`${b} ${B.message}`;this.error(V,{exitCode:B.exitCode,code:B.code})}throw B}}_registerOption(d){const O=d.short&&this._findOption(d.short)||d.long&&this._findOption(d.long);if(O){const N=d.long&&this._findOption(d.long)?d.long:d.short;throw new Error(`Cannot add option '${d.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${N}' - already used by option '${O.flags}'`)}this._initOptionGroup(d),this.options.push(d)}_registerCommand(d){const O=b=>[b.name()].concat(b.aliases()),N=O(d).find(b=>this._findCommand(b));if(N){const b=O(this._findCommand(N)).join("|"),B=O(d).join("|");throw new Error(`cannot add command '${B}' as already have command '${b}'`)}this._initCommandGroup(d),this.commands.push(d)}addOption(d){this._registerOption(d);const O=d.name(),N=d.attributeName();if(d.negate){const B=d.long.replace(/^--no-/,"--");this._findOption(B)||this.setOptionValueWithSource(N,d.defaultValue===void 0?!0:d.defaultValue,"default")}else d.defaultValue!==void 0&&this.setOptionValueWithSource(N,d.defaultValue,"default");const b=(B,V,Y)=>{B==null&&d.presetArg!==void 0&&(B=d.presetArg);const rt=this.getOptionValue(N);B!==null&&d.parseArg?B=this._callParseArg(d,B,rt,V):B!==null&&d.variadic&&(B=d._concatValue(B,rt)),B==null&&(d.negate?B=!1:d.isBoolean()||d.optional?B=!0:B=""),this.setOptionValueWithSource(N,B,Y)};return this.on("option:"+O,B=>{const V=`error: option '${d.flags}' argument '${B}' is invalid.`;b(B,V,"cli")}),d.envVar&&this.on("optionEnv:"+O,B=>{const V=`error: option '${d.flags}' value '${B}' from env '${d.envVar}' is invalid.`;b(B,V,"env")}),this}_optionEx(d,O,N,b,B){if(typeof O=="object"&&O instanceof v)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const V=this.createOption(O,N);if(V.makeOptionMandatory(!!d.mandatory),typeof b=="function")V.default(B).argParser(b);else if(b instanceof RegExp){const Y=b;b=(rt,j)=>{const at=Y.exec(rt);return at?at[0]:j},V.default(B).argParser(b)}else V.default(b);return this.addOption(V)}option(d,O,N,b){return this._optionEx({},d,O,N,b)}requiredOption(d,O,N,b){return this._optionEx({mandatory:!0},d,O,N,b)}combineFlagAndOptionalValue(d=!0){return this._combineFlagAndOptionalValue=!!d,this}allowUnknownOption(d=!0){return this._allowUnknownOption=!!d,this}allowExcessArguments(d=!0){return this._allowExcessArguments=!!d,this}enablePositionalOptions(d=!0){return this._enablePositionalOptions=!!d,this}passThroughOptions(d=!0){return this._passThroughOptions=!!d,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(d=!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=!!d,this}getOptionValue(d){return this._storeOptionsAsProperties?this[d]:this._optionValues[d]}setOptionValue(d,O){return this.setOptionValueWithSource(d,O,void 0)}setOptionValueWithSource(d,O,N){return this._storeOptionsAsProperties?this[d]=O:this._optionValues[d]=O,this._optionValueSources[d]=N,this}getOptionValueSource(d){return this._optionValueSources[d]}getOptionValueSourceWithGlobals(d){let O;return this._getCommandAndAncestors().forEach(N=>{N.getOptionValueSource(d)!==void 0&&(O=N.getOptionValueSource(d))}),O}_prepareUserArgs(d,O){if(d!==void 0&&!Array.isArray(d))throw new Error("first parameter to parse must be array or undefined");if(O=O||{},d===void 0&&O.from===void 0){o.versions?.electron&&(O.from="electron");const b=o.execArgv??[];(b.includes("-e")||b.includes("--eval")||b.includes("-p")||b.includes("--print"))&&(O.from="eval")}d===void 0&&(d=o.argv),this.rawArgs=d.slice();let N;switch(O.from){case void 0:case"node":this._scriptPath=d[1],N=d.slice(2);break;case"electron":o.defaultApp?(this._scriptPath=d[1],N=d.slice(2)):N=d.slice(1);break;case"user":N=d.slice(0);break;case"eval":N=d.slice(1);break;default:throw new Error(`unexpected parse option { from: '${O.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",N}parse(d,O){this._prepareForParse();const N=this._prepareUserArgs(d,O);return this._parseCommand([],N),this}async parseAsync(d,O){this._prepareForParse();const N=this._prepareUserArgs(d,O);return await this._parseCommand([],N),this}_prepareForParse(){this._savedState===null?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. - 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(d,O,N){if(a.existsSync(d))return;const b=O?`searched for local subcommand relative to directory '${O}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",B=`'${d}' does not exist - if '${N}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead - if the default executable name is not suitable, use the executableFile option to supply a custom name or path - ${b}`;throw new Error(B)}_executeSubCommand(d,O){O=O.slice();let N=!1;const b=[".js",".ts",".tsx",".mjs",".cjs"];function B(at,Ot){const X=t.resolve(at,Ot);if(a.existsSync(X))return X;if(b.includes(t.extname(Ot)))return;const ct=b.find(F=>a.existsSync(`${X}${F}`));if(ct)return`${X}${ct}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let V=d._executableFile||`${this._name}-${d._name}`,Y=this._executableDir||"";if(this._scriptPath){let at;try{at=a.realpathSync(this._scriptPath)}catch{at=this._scriptPath}Y=t.resolve(t.dirname(at),Y)}if(Y){let at=B(Y,V);if(!at&&!d._executableFile&&this._scriptPath){const Ot=t.basename(this._scriptPath,t.extname(this._scriptPath));Ot!==this._name&&(at=B(Y,`${Ot}-${d._name}`))}V=at||V}N=b.includes(t.extname(V));let rt;o.platform!=="win32"?N?(O.unshift(V),O=I(o.execArgv).concat(O),rt=e.spawn(o.argv[0],O,{stdio:"inherit"})):rt=e.spawn(V,O,{stdio:"inherit"}):(this._checkForMissingExecutable(V,Y,d._name),O.unshift(V),O=I(o.execArgv).concat(O),rt=e.spawn(o.execPath,O,{stdio:"inherit"})),rt.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(Ot=>{o.on(Ot,()=>{rt.killed===!1&&rt.exitCode===null&&rt.kill(Ot)})});const j=this._exitCallback;rt.on("close",at=>{at=at??1,j?j(new l(at,"commander.executeSubCommandAsync","(close)")):o.exit(at)}),rt.on("error",at=>{if(at.code==="ENOENT")this._checkForMissingExecutable(V,Y,d._name);else if(at.code==="EACCES")throw new Error(`'${V}' not executable`);if(!j)o.exit(1);else{const Ot=new l(1,"commander.executeSubCommandAsync","(error)");Ot.nestedError=at,j(Ot)}}),this.runningCommand=rt}_dispatchSubcommand(d,O,N){const b=this._findCommand(d);b||this.help({error:!0}),b._prepareForParse();let B;return B=this._chainOrCallSubCommandHook(B,b,"preSubcommand"),B=this._chainOrCall(B,()=>{if(b._executableHandler)this._executeSubCommand(b,O.concat(N));else return b._parseCommand(O,N)}),B}_dispatchHelpCommand(d){d||this.help();const O=this._findCommand(d);return O&&!O._executableHandler&&O.help(),this._dispatchSubcommand(d,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((d,O)=>{d.required&&this.args[O]==null&&this.missingArgument(d.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const d=(N,b,B)=>{let V=b;if(b!==null&&N.parseArg){const Y=`error: command-argument value '${b}' is invalid for argument '${N.name()}'.`;V=this._callParseArg(N,b,B,Y)}return V};this._checkNumberOfArguments();const O=[];this.registeredArguments.forEach((N,b)=>{let B=N.defaultValue;N.variadic?b<this.args.length?(B=this.args.slice(b),N.parseArg&&(B=B.reduce((V,Y)=>d(N,Y,V),N.defaultValue))):B===void 0&&(B=[]):b<this.args.length&&(B=this.args[b],N.parseArg&&(B=d(N,B,N.defaultValue))),O[b]=B}),this.processedArgs=O}_chainOrCall(d,O){return d&&d.then&&typeof d.then=="function"?d.then(()=>O()):O()}_chainOrCallHooks(d,O){let N=d;const b=[];return this._getCommandAndAncestors().reverse().filter(B=>B._lifeCycleHooks[O]!==void 0).forEach(B=>{B._lifeCycleHooks[O].forEach(V=>{b.push({hookedCommand:B,callback:V})})}),O==="postAction"&&b.reverse(),b.forEach(B=>{N=this._chainOrCall(N,()=>B.callback(B.hookedCommand,this))}),N}_chainOrCallSubCommandHook(d,O,N){let b=d;return this._lifeCycleHooks[N]!==void 0&&this._lifeCycleHooks[N].forEach(B=>{b=this._chainOrCall(b,()=>B(this,O))}),b}_parseCommand(d,O){const N=this.parseOptions(O);if(this._parseOptionsEnv(),this._parseOptionsImplied(),d=d.concat(N.operands),O=N.unknown,this.args=d.concat(O),d&&this._findCommand(d[0]))return this._dispatchSubcommand(d[0],d.slice(1),O);if(this._getHelpCommand()&&d[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(d[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(O),this._dispatchSubcommand(this._defaultCommandName,d,O);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(N.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const b=()=>{N.unknown.length>0&&this.unknownOption(N.unknown[0])},B=`command:${this.name()}`;if(this._actionHandler){b(),this._processArguments();let V;return V=this._chainOrCallHooks(V,"preAction"),V=this._chainOrCall(V,()=>this._actionHandler(this.processedArgs)),this.parent&&(V=this._chainOrCall(V,()=>{this.parent.emit(B,d,O)})),V=this._chainOrCallHooks(V,"postAction"),V}if(this.parent&&this.parent.listenerCount(B))b(),this._processArguments(),this.parent.emit(B,d,O);else if(d.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",d,O);this.listenerCount("command:*")?this.emit("command:*",d,O):this.commands.length?this.unknownCommand():(b(),this._processArguments())}else this.commands.length?(b(),this.help({error:!0})):(b(),this._processArguments())}_findCommand(d){if(d)return this.commands.find(O=>O._name===d||O._aliases.includes(d))}_findOption(d){return this.options.find(O=>O.is(d))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(d=>{d.options.forEach(O=>{O.mandatory&&d.getOptionValue(O.attributeName())===void 0&&d.missingMandatoryOptionValue(O)})})}_checkForConflictingLocalOptions(){const d=this.options.filter(N=>{const b=N.attributeName();return this.getOptionValue(b)===void 0?!1:this.getOptionValueSource(b)!=="default"});d.filter(N=>N.conflictsWith.length>0).forEach(N=>{const b=d.find(B=>N.conflictsWith.includes(B.attributeName()));b&&this._conflictingOption(N,b)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(d=>{d._checkForConflictingLocalOptions()})}parseOptions(d){const O=[],N=[];let b=O;const B=d.slice();function V(j){return j.length>1&&j[0]==="-"}const Y=j=>/^-\d*\.?\d+(e[+-]?\d+)?$/.test(j)?!this._getCommandAndAncestors().some(at=>at.options.map(Ot=>Ot.short).some(Ot=>/^-\d$/.test(Ot))):!1;let rt=null;for(;B.length;){const j=B.shift();if(j==="--"){b===N&&b.push(j),b.push(...B);break}if(rt&&(!V(j)||Y(j))){this.emit(`option:${rt.name()}`,j);continue}if(rt=null,V(j)){const at=this._findOption(j);if(at){if(at.required){const Ot=B.shift();Ot===void 0&&this.optionMissingArgument(at),this.emit(`option:${at.name()}`,Ot)}else if(at.optional){let Ot=null;B.length>0&&(!V(B[0])||Y(B[0]))&&(Ot=B.shift()),this.emit(`option:${at.name()}`,Ot)}else this.emit(`option:${at.name()}`);rt=at.variadic?at:null;continue}}if(j.length>2&&j[0]==="-"&&j[1]!=="-"){const at=this._findOption(`-${j[1]}`);if(at){at.required||at.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${at.name()}`,j.slice(2)):(this.emit(`option:${at.name()}`),B.unshift(`-${j.slice(2)}`));continue}}if(/^--[^=]+=/.test(j)){const at=j.indexOf("="),Ot=this._findOption(j.slice(0,at));if(Ot&&(Ot.required||Ot.optional)){this.emit(`option:${Ot.name()}`,j.slice(at+1));continue}}if(b===O&&V(j)&&!(this.commands.length===0&&Y(j))&&(b=N),(this._enablePositionalOptions||this._passThroughOptions)&&O.length===0&&N.length===0){if(this._findCommand(j)){O.push(j),B.length>0&&N.push(...B);break}else if(this._getHelpCommand()&&j===this._getHelpCommand().name()){O.push(j),B.length>0&&O.push(...B);break}else if(this._defaultCommandName){N.push(j),B.length>0&&N.push(...B);break}}if(this._passThroughOptions){b.push(j),B.length>0&&b.push(...B);break}b.push(j)}return{operands:O,unknown:N}}opts(){if(this._storeOptionsAsProperties){const d={},O=this.options.length;for(let N=0;N<O;N++){const b=this.options[N].attributeName();d[b]=b===this._versionOptionName?this._version:this[b]}return d}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((d,O)=>Object.assign(d,O.opts()),{})}error(d,O){this._outputConfiguration.outputError(`${d} `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError} `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(` `),this.outputHelp({error:!0}));const N=O||{},b=N.exitCode||1,B=N.code||"commander.error";this._exit(b,B,d)}_parseOptionsEnv(){this.options.forEach(d=>{if(d.envVar&&d.envVar in o.env){const O=d.attributeName();(this.getOptionValue(O)===void 0||["default","config","env"].includes(this.getOptionValueSource(O)))&&(d.required||d.optional?this.emit(`optionEnv:${d.name()}`,o.env[d.envVar]):this.emit(`optionEnv:${d.name()}`))}})}_parseOptionsImplied(){const d=new w(this.options),O=N=>this.getOptionValue(N)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(N));this.options.filter(N=>N.implied!==void 0&&O(N.attributeName())&&d.valueFromOption(this.getOptionValue(N.attributeName()),N)).forEach(N=>{Object.keys(N.implied).filter(b=>!O(b)).forEach(b=>{this.setOptionValueWithSource(b,N.implied[b],"implied")})})}missingArgument(d){const O=`error: missing required argument '${d}'`;this.error(O,{code:"commander.missingArgument"})}optionMissingArgument(d){const O=`error: option '${d.flags}' argument missing`;this.error(O,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(d){const O=`error: required option '${d.flags}' not specified`;this.error(O,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(d,O){const N=V=>{const Y=V.attributeName(),rt=this.getOptionValue(Y),j=this.options.find(Ot=>Ot.negate&&Y===Ot.attributeName()),at=this.options.find(Ot=>!Ot.negate&&Y===Ot.attributeName());return j&&(j.presetArg===void 0&&rt===!1||j.presetArg!==void 0&&rt===j.presetArg)?j:at||V},b=V=>{const Y=N(V),rt=Y.attributeName();return this.getOptionValueSource(rt)==="env"?`environment variable '${Y.envVar}'`:`option '${Y.flags}'`},B=`error: ${b(d)} cannot be used with ${b(O)}`;this.error(B,{code:"commander.conflictingOption"})}unknownOption(d){if(this._allowUnknownOption)return;let O="";if(d.startsWith("--")&&this._showSuggestionAfterError){let b=[],B=this;do{const V=B.createHelp().visibleOptions(B).filter(Y=>Y.long).map(Y=>Y.long);b=b.concat(V),B=B.parent}while(B&&!B._enablePositionalOptions);O=S(d,b)}const N=`error: unknown option '${d}'${O}`;this.error(N,{code:"commander.unknownOption"})}_excessArguments(d){if(this._allowExcessArguments)return;const O=this.registeredArguments.length,N=O===1?"":"s",B=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${O} argument${N} but got ${d.length}.`;this.error(B,{code:"commander.excessArguments"})}unknownCommand(){const d=this.args[0];let O="";if(this._showSuggestionAfterError){const b=[];this.createHelp().visibleCommands(this).forEach(B=>{b.push(B.name()),B.alias()&&b.push(B.alias())}),O=S(d,b)}const N=`error: unknown command '${d}'${O}`;this.error(N,{code:"commander.unknownCommand"})}version(d,O,N){if(d===void 0)return this._version;this._version=d,O=O||"-V, --version",N=N||"output the version number";const b=this.createOption(O,N);return this._versionOptionName=b.attributeName(),this._registerOption(b),this.on("option:"+b.name(),()=>{this._outputConfiguration.writeOut(`${d} `),this._exit(0,"commander.version",d)}),this}description(d,O){return d===void 0&&O===void 0?this._description:(this._description=d,O&&(this._argsDescription=O),this)}summary(d){return d===void 0?this._summary:(this._summary=d,this)}alias(d){if(d===void 0)return this._aliases[0];let O=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(O=this.commands[this.commands.length-1]),d===O._name)throw new Error("Command alias can't be the same as its name");const N=this.parent?._findCommand(d);if(N){const b=[N.name()].concat(N.aliases()).join("|");throw new Error(`cannot add alias '${d}' to command '${this.name()}' as already have command '${b}'`)}return O._aliases.push(d),this}aliases(d){return d===void 0?this._aliases:(d.forEach(O=>this.alias(O)),this)}usage(d){if(d===void 0){if(this._usage)return this._usage;const O=this.registeredArguments.map(N=>c(N));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?O:[]).join(" ")}return this._usage=d,this}name(d){return d===void 0?this._name:(this._name=d,this)}helpGroup(d){return d===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=d,this)}commandsGroup(d){return d===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=d,this)}optionsGroup(d){return d===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=d,this)}_initOptionGroup(d){this._defaultOptionGroup&&!d.helpGroupHeading&&d.helpGroup(this._defaultOptionGroup)}_initCommandGroup(d){this._defaultCommandGroup&&!d.helpGroup()&&d.helpGroup(this._defaultCommandGroup)}nameFromFilename(d){return this._name=t.basename(d,t.extname(d)),this}executableDir(d){return d===void 0?this._executableDir:(this._executableDir=d,this)}helpInformation(d){const O=this.createHelp(),N=this._getOutputContext(d);O.prepareContext({error:N.error,helpWidth:N.helpWidth,outputHasColors:N.hasColors});const b=O.formatHelp(this,O);return N.hasColors?b:this._outputConfiguration.stripColor(b)}_getOutputContext(d){d=d||{};const O=!!d.error;let N,b,B;return O?(N=Y=>this._outputConfiguration.writeErr(Y),b=this._outputConfiguration.getErrHasColors(),B=this._outputConfiguration.getErrHelpWidth()):(N=Y=>this._outputConfiguration.writeOut(Y),b=this._outputConfiguration.getOutHasColors(),B=this._outputConfiguration.getOutHelpWidth()),{error:O,write:Y=>(b||(Y=this._outputConfiguration.stripColor(Y)),N(Y)),hasColors:b,helpWidth:B}}outputHelp(d){let O;typeof d=="function"&&(O=d,d=void 0);const N=this._getOutputContext(d),b={error:N.error,write:N.write,command:this};this._getCommandAndAncestors().reverse().forEach(V=>V.emit("beforeAllHelp",b)),this.emit("beforeHelp",b);let B=this.helpInformation({error:N.error});if(O&&(B=O(B),typeof B!="string"&&!Buffer.isBuffer(B)))throw new Error("outputHelp callback must return a string or a Buffer");N.write(B),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",b),this._getCommandAndAncestors().forEach(V=>V.emit("afterAllHelp",b))}helpOption(d,O){return typeof d=="boolean"?(d?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(d??"-h, --help",O??"display help for command"),(d||O)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(d){return this._helpOption=d,this._initOptionGroup(d),this}help(d){this.outputHelp(d);let O=Number(o.exitCode??0);O===0&&d&&typeof d!="function"&&d.error&&(O=1),this._exit(O,"commander.help","(outputHelp)")}addHelpText(d,O){const N=["beforeAll","before","after","afterAll"];if(!N.includes(d))throw new Error(`Unexpected value for position to addHelpText. Expecting one of '${N.join("', '")}'`);const b=`${d}Help`;return this.on(b,B=>{let V;typeof O=="function"?V=O({error:B.error,command:B.command}):V=O,V&&B.write(`${V} `)}),this}_outputHelpIfRequested(d){const O=this._getHelpOption();O&&d.find(b=>O.is(b))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function I(M){return M.map(d=>{if(!d.startsWith("--inspect"))return d;let O,N="127.0.0.1",b="9229",B;return(B=d.match(/^(--inspect(-brk)?)$/))!==null?O=B[1]:(B=d.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(O=B[1],/^\d+$/.test(B[3])?b=B[3]:N=B[3]):(B=d.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(O=B[1],N=B[3],b=B[4]),O&&b!=="0"?`${O}=${N}:${parseInt(b)+1}`:d})}function R(){if(o.env.NO_COLOR||o.env.FORCE_COLOR==="0"||o.env.FORCE_COLOR==="false")return!1;if(o.env.FORCE_COLOR||o.env.CLICOLOR_FORCE!==void 0)return!0}return Lo.Command=C,Lo.useColor=R,Lo}var Gf;function V1(){if(Gf)return Or;Gf=1;const{Argument:n}=_l(),{Command:e}=k1(),{CommanderError:t,InvalidArgumentError:a}=Zo(),{Help:o}=Oh(),{Option:u}=Ch();return Or.program=new e,Or.createCommand=c=>new e(c),Or.createOption=(c,l)=>new u(c,l),Or.createArgument=(c,l)=>new n(c,l),Or.Command=e,Or.Option=u,Or.Argument=n,Or.Help=o,Or.CommanderError=t,Or.InvalidArgumentError=a,Or.InvalidOptionArgumentError=a,Or}var G1=V1();const $1=dl(G1),{program:wR,createCommand:NR,createArgument:IR,createOption:LR,CommanderError:PR,InvalidArgumentError:SR,InvalidOptionArgumentError:BR,Command:W1,Argument:MR,Option:Bo,Help:xR}=$1;class bn{constructor(e,t){this.id=bn.idToString(e),this.payload=t}static idToString(e){return typeof e=="string"?e:JSON.stringify(e)}}function H1(n){return!!n&&typeof n.use=="function"}function Y1(n){return!!n}function z1(n){return!!n}class Cs{constructor(e,t){this.context=e,this.factory=t,this.registry=new Map}get(e){return this.registry.get(bn.idToString(e))?.payload}has(e){return this.registry.has(bn.idToString(e))}use(e,...t){let a=this.registry.get(bn.idToString(e));if(!a){const o=typeof this.factory=="function"?this.factory(...t):t[0];Y1(o)&&(o.id=e),z1(o)&&(o.parent=this),a=new bn(e,o),this.registry.set(bn.idToString(e),a)}return a.payload&&H1(a.payload)&&a.payload.use(...t),a.payload}entries(){return[...this.registry.entries()]}values(){return[...this.registry.values()]}payloads(){return[...this.registry.values()].map(e=>e.payload)}clear(){this.registry.clear()}}const Vo=" ",Go="cm",$o="inches",rn="rotations",qo="degrees",Ts="seconds",Ur="AUTO";var kn=(n=>(n[n.DEBUG=0]="DEBUG",n[n.INFO=1]="INFO",n[n.WARNING=2]="WARNING",n[n.ERROR=3]="ERROR",n[n.CRITICAL=4]="CRITICAL",n))(kn||{});let Th=0,el;function X1(n){Th=n}function $f(n){el=n}function rl(n,e,t="-",a=80){const o=a-n.length-6-e?.length;return`#${e} ${t.repeat(Math.floor(o/2))} ${n} ${t.repeat(Math.ceil(o/2))} #`}function j1(n,...e){if(Th<=n)if(el)el(n,...e);else switch(n){case 4:case 3:console.error(`::${kn[n]}::`,...e);break;case 2:console.warn(`::${kn[n]}::`,...e);break;case 1:console.info(`::${kn[n]}::`,...e);break;case 0:default:console.debug(`::${kn[n]}::`,...e);break}}const Se=(...n)=>j1(2,...n);function Ie(n,e=1){let t=[];return n===void 0?t=[]:Array.isArray(n)?t=n.reduce((a,o)=>[...a,...Ie(o,e)],[]):n.includes(` `)?t=Ie(n.split(/\r?\n/),e):t=[Vo.repeat(e)+n],t}function pi(n,e=!0){if(!n.filter(t=>!t.match(/^\s*$|^\s*#.*$/)).length){n.push("pass");//!! }return n}function On(n){return n?.trim().toLowerCase().replaceAll(/[ .-]/gi,"_").replace(/^(\d)/im,"_$1").replaceAll(/[áéíóöőúüű]/g,e=>({á:"a",é:"e",í:"i",ó:"o",ö:"o",ő:"o",ú:"u",ü:"u",ű:"u"})[e]??e).replace(/[^a-zA-Z0-9_]/g,"")}function Fn(n){return n?.replace(/\.[^/.]+$/,"").replaceAll(" ","_")}function Cr(n,e=!0){return n=n?.replaceAll(/\\(.)/g,"$1").replaceAll(" ","_").replaceAll(/[\/,.]/g,""),e&&(n=n?.toUpperCase()),n}function Q1(n){return typeof n=="number"}function Cn(n){const e=n?.lastIndexOf(".");return n===void 0||e===-1||e===void 0?"":n.substring(e)}function Tr(n){return n?.replace(/^.*[\\/]/,"")}function Ho(n){return n?.split(".").slice(0,-1).join(".")}function ml(n){const e=n?.trim().toLowerCase();return e==="true"||e==="1"}function Ze(n){return parseInt(n??"0")}function gl(n){return`"""\r `+n.map(([e,t])=>`${(e+":").padEnd(12," ")}${t}`).join(`\r `)+`\r """\r `}function El(n,e){return e.extra||(e.extra={}),e.extra[n]||(e.extra[n]={}),e.extra[n]}class Ol{constructor(e){this.name=e}get_code(e){const t=e.map(a=>On(a));return`${this.get_pyname()} = Message([${t.join(", ")}])`}get_pyname(){return`message_${On(this.name)}`}static createRegistry(e){return new Cs(e,(...t)=>new Ol(t[0]))}}var ne=(n=>(n[n.NONE=0]="NONE",n[n.SPIKE=1]="SPIKE",n[n.ROBOTINVENTOR=2]="ROBOTINVENTOR",n[n._GEN_EV5=3]="_GEN_EV5",n[n.EV3CLASSROOM=4]="EV3CLASSROOM",n[n._SB3_FORMAT=7]="_SB3_FORMAT",n[n.EV3G=8]="EV3G",n[n.EV3B=16]="EV3B",n[n._GEN_EV3=28]="_GEN_EV3",n[n._EV3Lab_FORMAT=24]="_EV3Lab_FORMAT",n[n.PYTHON=32]="PYTHON",n[n.WEDO2=64]="WEDO2",n))(ne||{}),ce=(n=>(n[n.SIMPLE=0]="SIMPLE",n[n.PARENTHESIS=1]="PARENTHESIS",n[n.REFERENCE=2]="REFERENCE",n[n.EXPONENTIATION=3]="EXPONENTIATION",n[n.UNARY=4]="UNARY",n[n.BINARYOP_MUL=5]="BINARYOP_MUL",n[n.BINARY_ADD=6]="BINARY_ADD",n[n.BINARY_SHIFT=7]="BINARY_SHIFT",n[n.BINARY_AND=8]="BINARY_AND",n[n.BINARY_XOR=9]="BINARY_XOR",n[n.BINARY_OR=10]="BINARY_OR",n[n.BINARY_COMPARISON=11]="BINARY_COMPARISON",n[n.BOOLEAN_NOT=12]="BOOLEAN_NOT",n[n.BOOLEAN_AND=13]="BOOLEAN_AND",n[n.BOOLEAN_OR=14]="BOOLEAN_OR",n[n.WEAKEST=99]="WEAKEST",n))(ce||{}),ft=(n=>(n[n.UNKNOWN=0]="UNKNOWN",n[n.NUMBER=10]="NUMBER",n[n.STRING=11]="STRING",n[n.BOOLEAN=12]="BOOLEAN",n[n.ENUM=13]="ENUM",n[n.NUMBERARRAY=20]="NUMBERARRAY",n[n.BOOLEANARRAY=21]="BOOLEANARRAY",n[n.ENUMARRAY=23]="ENUMARRAY",n))(ft||{});class st{constructor(e,t){this.options=t,e&&st.is(e)?this.value=e.value:this.value=e}get is_string(){return this.options?.type===ft.STRING}get is_numeric(){return this.options?.type===ft.NUMBER||!this.options?.is_dynamic&&!this.is_string&&typeof this.value=="number"}get raw(){return!this.is_string||this.options?.is_dynamic?this.value:`"${this.value}"`}toString(){return st.toString(this)}toInt(){return st.toInt(this)}toFloat(){return st.toFloat(this)}toBool(){return st.toBool(this)}ensureString(e){return nl(e,this,ft.STRING)}ensureNumber(e,t=!1){if(this.is_numeric){if(this.options?.is_dynamic)return this;{const a=t?this.toInt():this.toFloat();return new st(a,{type:ft.NUMBER})}}else return nl(e,this,ft.NUMBER,t)}static is(e){return e instanceof st}static is_dynamic(e){return st.is(e)&&!!e.options?.is_dynamic}static raw(e){return st.is(e)?e.raw:e}static value(e){return st.is(e)?e.value:e}static toString(e){return st.value(e)?.toString()??""}static toInt(e){const t=st.is(e)?e.value:e;return parseInt(t?.toString()??"")}static toFloat(e){const t=st.is(e)?e.value:e;return parseFloat(t?.toString()??"")}static toBool(e){const t=st.is(e)?e.value:e;return ml(t?.toString())}static ensureNumber(e,t,a=!1){return st.is(t)?t.ensureNumber(e):e.helpers.use(a?"int_safe":"float_safe").call(t)}static isEqual(e,t){return st.is(e)&&st.is(t)?e.value===t.value&&JSON.stringify(e.options)===JSON.stringify(t.options):e===t}}function we(n,e,t=!1){const[a,o,u]=Array.isArray(e)?e:[e,void 0,void 0];if(o===void 0){if(Array.isArray(a))return we(n,a,t);if(!st.is_dynamic(a)){const c=Math.round(parseFloat(a?.toString()??"")*1e3)/1e3;return new st(c,{type:ft.NUMBER})}return!st.is(a)||a.options?.type!==ft.NUMBER?st.ensureNumber(n,a,t):new st(a,{type:ft.NUMBER,is_dynamic:a.options.is_dynamic,precedence:a.options.precedence})}else if(u===void 0){const c=we(n,o,t),l=!st.is_dynamic(c);if(a==="-"||a==="+")if(l){const m=(a==="-"?-1:1)*st.toFloat(c);return new st(m,{type:ft.NUMBER})}else{const p=`${a}${st.raw(c)}`;return new st(p,{is_dynamic:!0,type:ft.NUMBER,precedence:ce.UNARY})}else if(a==="abs")return l?new st(Math.abs(st.toFloat(c)),{type:ft.NUMBER}):(n.imports.use("umath",null),new st(`umath.fabs(${st.raw(c)})`,{is_dynamic:!0,type:ft.NUMBER,precedence:ce.SIMPLE}))}else{const c=we(n,a,t),l=we(n,u,t);let p=st.raw(c),m=st.raw(l);if(!st.is_dynamic(c)&&!st.is_dynamic(l)){const w=(C,I,R)=>{switch(I){case"+":return C+R;case"-":return C-R;case"*":return C*R;case"/":return C/R;case"%":return C%R}};if(p===void 0||o===void 0||m===void 0)return;const S=we(n,w(st.toFloat(p),o?.toString(),st.toFloat(m)));return new st(S,{type:ft.NUMBER,precedence:ce.SIMPLE})}else{const w=we(n,a,t),S=we(n,u,t),C=o?.toString(),I=O=>O?.toString()==="0",R=O=>O?.toString()==="1",M=O=>O?.toString()==="-1";if(C==="*"){if(I(w)||R(S))return w;if(I(S)||R(w))return S;if(M(w))return we(n,["-",S]);if(M(S))return we(n,["-",w])}else if(C==="/"){if(I(w)||R(S))return w;if(M(S))return we(n,["-",w])}else if(C==="+"){if(I(w))return S;if(I(S))return w}else if(C==="-"){if(I(w))return we(n,["-",S]);if(I(S))return w}const d=(()=>{switch(o.toString()){case"-":case"+":return ce.BINARY_ADD;case"*":case"/":case"%":return ce.BINARYOP_MUL;default:return ce.WEAKEST}})();return d<(w?.options?.precedence??0)&&(p=`(${p})`),d<(S?.options?.precedence??0)&&(m=`(${m})`),new st(`${p} ${o} ${m}`,{is_dynamic:!0,type:ft.NUMBER,precedence:d})}}}function nl(n,e,t,a=!1){const o=e?.options?.type;if(t!==o)switch(t){case ft.NUMBER:e=a?n.helpers.use("int_safe").call(e):n.helpers.use("float_safe").call(e);break;case ft.STRING:e=n.helpers.use("str").call(e);break;case ft.NUMBERARRAY:switch(o){case ft.NUMBER:e=new st(`[${e?.raw}]`,{is_dynamic:!0,is_variable:!0,type:ft.NUMBERARRAY});break}break;case ft.BOOLEANARRAY:switch(o){case ft.BOOLEAN:e=new st(`[${e?.raw}]`,{is_dynamic:!0,is_variable:!0,type:ft.BOOLEANARRAY});break}break}return e}const Wf=new Map([[0,"Stop.COAST"],[1,"Stop.BRAKE"],[2,"Stop.HOLD"]]),yh=new Map([[0,"Stop.COAST"],[1,"Stop.HOLD"]]),K1=new Map([[1,"Side.TOP"],[2,"Side.LEFT"],[3,"Side.RIGHT"],[4,"Side.BOTTOM"]]),Yu=new Map([[0,"Color.BLACK"],[1,"Color.MAGENTA"],[2,"Color.VIOLET"],[3,"Color.BLUE"],[4,"Color.CYAN"],[5,"Color.GREEN"],[6,"Color.GREEN"],[7,"Color.YELLOW"],[8,"Color.ORANGE"],[9,"Color.RED"],[10,"Color.WHITE"]]),Cl=new Map([[0,"Button.NONE"],[1,"Button.LEFT"],[2,"Button.CENTER"],[3,"Button.RIGHT"],[4,"Button.UP"],[5,"Button.DOWN"]]),J1=new Map([[0,"RELEASED"],[1,"PRESSED"]]);var Rh=(n=>(n[n.OFF=0]="OFF",n[n.GREEN=1]="GREEN",n[n.RED=2]="RED",n[n.ORANGE=3]="ORANGE",n[n.GREEN_PULSE=4]="GREEN_PULSE",n[n.RED_PULSE=5]="RED_PULSE",n[n.ORANGE_PULSE=6]="ORANGE_PULSE",n))(Rh||{});const Z1=new Map([[0,"Color.NONE"],[1,"Color.GREEN"],[2,"Color