blocklypy
Version:
BlocklyPy: SPIKE to Pybricks - word-block converter to Pybricks python code
33 lines • 1.19 MB
JavaScript
#!/usr/bin/env node
"use strict";var ta=Object.defineProperty;var ea=(e,t,r)=>t in e?ta(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Re=(e,t,r)=>ea(e,typeof t!="symbol"?t+"":t,r);const ra=require("node:events"),Ts=require("node:child_process"),na=require("node:path"),ia=require("node:fs"),sa=require("node:process"),Gi=require("canvas"),ys=require("path"),Ze=require("fs");var kr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Rs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var he={},$r={},Yr={},Vi;function dn(){if(Vi)return Yr;Vi=1;class e extends Error{constructor(s,i,o){super(o),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=i,this.exitCode=s,this.nestedError=void 0}}class t extends e{constructor(s){super(1,"commander.invalidArgument",s),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}return Yr.CommanderError=e,Yr.InvalidArgumentError=t,Yr}var ki;function qn(){if(ki)return $r;ki=1;const{InvalidArgumentError:e}=dn();class t{constructor(i,o){switch(this.description=o||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,i[0]){case"<":this.required=!0,this._name=i.slice(1,-1);break;case"[":this.required=!1,this._name=i.slice(1,-1);break;default:this.required=!0,this._name=i;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(i,o){return o===this.defaultValue||!Array.isArray(o)?[i]:o.concat(i)}default(i,o){return this.defaultValue=i,this.defaultValueDescription=o,this}argParser(i){return this.parseArg=i,this}choices(i){return this.argChoices=i.slice(),this.parseArg=(o,l)=>{if(!this.argChoices.includes(o))throw new e(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(o,l):o},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function r(s){const i=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+i+">":"["+i+"]"}return $r.Argument=t,$r.humanReadableArgName=r,$r}var Wr={},Hr={},$i;function vs(){if($i)return Hr;$i=1;const{humanReadableArgName:e}=qn();class t{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(i){this.helpWidth=this.helpWidth??i.helpWidth??80}visibleCommands(i){const o=i.commands.filter(a=>!a._hidden),l=i._getHelpCommand();return l&&!l._hidden&&o.push(l),this.sortSubcommands&&o.sort((a,u)=>a.name().localeCompare(u.name())),o}compareOptions(i,o){const l=a=>a.short?a.short.replace(/^-/,""):a.long.replace(/^--/,"");return l(i).localeCompare(l(o))}visibleOptions(i){const o=i.options.filter(a=>!a.hidden),l=i._getHelpOption();if(l&&!l.hidden){const a=l.short&&i._findOption(l.short),u=l.long&&i._findOption(l.long);!a&&!u?o.push(l):l.long&&!u?o.push(i.createOption(l.long,l.description)):l.short&&!a&&o.push(i.createOption(l.short,l.description))}return this.sortOptions&&o.sort(this.compareOptions),o}visibleGlobalOptions(i){if(!this.showGlobalOptions)return[];const o=[];for(let l=i.parent;l;l=l.parent){const a=l.options.filter(u=>!u.hidden);o.push(...a)}return this.sortOptions&&o.sort(this.compareOptions),o}visibleArguments(i){return i._argsDescription&&i.registeredArguments.forEach(o=>{o.description=o.description||i._argsDescription[o.name()]||""}),i.registeredArguments.find(o=>o.description)?i.registeredArguments:[]}subcommandTerm(i){const o=i.registeredArguments.map(l=>e(l)).join(" ");return i._name+(i._aliases[0]?"|"+i._aliases[0]:"")+(i.options.length?" [options]":"")+(o?" "+o:"")}optionTerm(i){return i.flags}argumentTerm(i){return i.name()}longestSubcommandTermLength(i,o){return o.visibleCommands(i).reduce((l,a)=>Math.max(l,this.displayWidth(o.styleSubcommandTerm(o.subcommandTerm(a)))),0)}longestOptionTermLength(i,o){return o.visibleOptions(i).reduce((l,a)=>Math.max(l,this.displayWidth(o.styleOptionTerm(o.optionTerm(a)))),0)}longestGlobalOptionTermLength(i,o){return o.visibleGlobalOptions(i).reduce((l,a)=>Math.max(l,this.displayWidth(o.styleOptionTerm(o.optionTerm(a)))),0)}longestArgumentTermLength(i,o){return o.visibleArguments(i).reduce((l,a)=>Math.max(l,this.displayWidth(o.styleArgumentTerm(o.argumentTerm(a)))),0)}commandUsage(i){let o=i._name;i._aliases[0]&&(o=o+"|"+i._aliases[0]);let l="";for(let a=i.parent;a;a=a.parent)l=a.name()+" "+l;return l+o+" "+i.usage()}commandDescription(i){return i.description()}subcommandDescription(i){return i.summary()||i.description()}optionDescription(i){const o=[];return i.argChoices&&o.push(`choices: ${i.argChoices.map(l=>JSON.stringify(l)).join(", ")}`),i.defaultValue!==void 0&&(i.required||i.optional||i.isBoolean()&&typeof i.defaultValue=="boolean")&&o.push(`default: ${i.defaultValueDescription||JSON.stringify(i.defaultValue)}`),i.presetArg!==void 0&&i.optional&&o.push(`preset: ${JSON.stringify(i.presetArg)}`),i.envVar!==void 0&&o.push(`env: ${i.envVar}`),o.length>0?`${i.description} (${o.join(", ")})`:i.description}argumentDescription(i){const o=[];if(i.argChoices&&o.push(`choices: ${i.argChoices.map(l=>JSON.stringify(l)).join(", ")}`),i.defaultValue!==void 0&&o.push(`default: ${i.defaultValueDescription||JSON.stringify(i.defaultValue)}`),o.length>0){const l=`(${o.join(", ")})`;return i.description?`${i.description} ${l}`:l}return i.description}formatHelp(i,o){const l=o.padWidth(i,o),a=o.helpWidth??80;function u(y,O){return o.formatItem(y,l,O,o)}let f=[`${o.styleTitle("Usage:")} ${o.styleUsage(o.commandUsage(i))}`,""];const m=o.commandDescription(i);m.length>0&&(f=f.concat([o.boxWrap(o.styleCommandDescription(m),a),""]));const C=o.visibleArguments(i).map(y=>u(o.styleArgumentTerm(o.argumentTerm(y)),o.styleArgumentDescription(o.argumentDescription(y))));C.length>0&&(f=f.concat([o.styleTitle("Arguments:"),...C,""]));const w=o.visibleOptions(i).map(y=>u(o.styleOptionTerm(o.optionTerm(y)),o.styleOptionDescription(o.optionDescription(y))));if(w.length>0&&(f=f.concat([o.styleTitle("Options:"),...w,""])),o.showGlobalOptions){const y=o.visibleGlobalOptions(i).map(O=>u(o.styleOptionTerm(o.optionTerm(O)),o.styleOptionDescription(o.optionDescription(O))));y.length>0&&(f=f.concat([o.styleTitle("Global Options:"),...y,""]))}const g=o.visibleCommands(i).map(y=>u(o.styleSubcommandTerm(o.subcommandTerm(y)),o.styleSubcommandDescription(o.subcommandDescription(y))));return g.length>0&&(f=f.concat([o.styleTitle("Commands:"),...g,""])),f.join(`
`)}displayWidth(i){return r(i).length}styleTitle(i){return i}styleUsage(i){return i.split(" ").map(o=>o==="[options]"?this.styleOptionText(o):o==="[command]"?this.styleSubcommandText(o):o[0]==="["||o[0]==="<"?this.styleArgumentText(o):this.styleCommandText(o)).join(" ")}styleCommandDescription(i){return this.styleDescriptionText(i)}styleOptionDescription(i){return this.styleDescriptionText(i)}styleSubcommandDescription(i){return this.styleDescriptionText(i)}styleArgumentDescription(i){return this.styleDescriptionText(i)}styleDescriptionText(i){return i}styleOptionTerm(i){return this.styleOptionText(i)}styleSubcommandTerm(i){return i.split(" ").map(o=>o==="[options]"?this.styleOptionText(o):o[0]==="["||o[0]==="<"?this.styleArgumentText(o):this.styleSubcommandText(o)).join(" ")}styleArgumentTerm(i){return this.styleArgumentText(i)}styleOptionText(i){return i}styleArgumentText(i){return i}styleSubcommandText(i){return i}styleCommandText(i){return i}padWidth(i,o){return Math.max(o.longestOptionTermLength(i,o),o.longestGlobalOptionTermLength(i,o),o.longestSubcommandTermLength(i,o),o.longestArgumentTermLength(i,o))}preformatted(i){return/\n[^\S\r\n]/.test(i)}formatItem(i,o,l,a){const f=" ".repeat(2);if(!l)return f+i;const m=i.padEnd(o+i.length-a.displayWidth(i)),C=2,g=(this.helpWidth??80)-o-C-2;let y;return g<this.minWidthToWrap||a.preformatted(l)?y=l:y=a.boxWrap(l,g).replace(/\n/g,`
`+" ".repeat(o+C)),f+m+" ".repeat(C)+y.replace(/\n/g,`
${f}`)}boxWrap(i,o){if(o<this.minWidthToWrap)return i;const l=i.split(/\r\n|\n/),a=/[\s]*[^\s]+/g,u=[];return l.forEach(f=>{const m=f.match(a);if(m===null){u.push("");return}let C=[m.shift()],w=this.displayWidth(C[0]);m.forEach(g=>{const y=this.displayWidth(g);if(w+y<=o){C.push(g),w+=y;return}u.push(C.join(""));const O=g.trimStart();C=[O],w=this.displayWidth(O)}),u.push(C.join(""))}),u.join(`
`)}}function r(s){const i=/\x1b\[\d*(;\d*)*m/g;return s.replace(i,"")}return Hr.Help=t,Hr.stripColor=r,Hr}var zr={},Yi;function ws(){if(Yi)return zr;Yi=1;const{InvalidArgumentError:e}=dn();class t{constructor(l,a){this.flags=l,this.description=a||"",this.required=l.includes("<"),this.optional=l.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(l),this.mandatory=!1;const u=i(l);this.short=u.shortFlag,this.long=u.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}default(l,a){return this.defaultValue=l,this.defaultValueDescription=a,this}preset(l){return this.presetArg=l,this}conflicts(l){return this.conflictsWith=this.conflictsWith.concat(l),this}implies(l){let a=l;return typeof l=="string"&&(a={[l]:!0}),this.implied=Object.assign(this.implied||{},a),this}env(l){return this.envVar=l,this}argParser(l){return this.parseArg=l,this}makeOptionMandatory(l=!0){return this.mandatory=!!l,this}hideHelp(l=!0){return this.hidden=!!l,this}_concatValue(l,a){return a===this.defaultValue||!Array.isArray(a)?[l]:a.concat(l)}choices(l){return this.argChoices=l.slice(),this.parseArg=(a,u)=>{if(!this.argChoices.includes(a))throw new e(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(a,u):a},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?s(this.name().replace(/^no-/,"")):s(this.name())}is(l){return this.short===l||this.long===l}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class r{constructor(l){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,l.forEach(a=>{a.negate?this.negativeOptions.set(a.attributeName(),a):this.positiveOptions.set(a.attributeName(),a)}),this.negativeOptions.forEach((a,u)=>{this.positiveOptions.has(u)&&this.dualOptions.add(u)})}valueFromOption(l,a){const u=a.attributeName();if(!this.dualOptions.has(u))return!0;const f=this.negativeOptions.get(u).presetArg,m=f!==void 0?f:!1;return a.negate===(m===l)}}function s(o){return o.split("-").reduce((l,a)=>l+a[0].toUpperCase()+a.slice(1))}function i(o){let l,a;const u=/^-[^-]$/,f=/^--[^-]/,m=o.split(/[ |,]+/).concat("guard");if(u.test(m[0])&&(l=m.shift()),f.test(m[0])&&(a=m.shift()),!l&&u.test(m[0])&&(l=m.shift()),!l&&f.test(m[0])&&(l=a,a=m.shift()),m[0].startsWith("-")){const C=m[0],w=`option creation failed due to '${C}' in option flags '${o}'`;throw/^-[^-][^-]/.test(C)?new Error(`${w}
- 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')`):u.test(C)?new Error(`${w}
- too many short flags`):f.test(C)?new Error(`${w}
- too many long flags`):new Error(`${w}
- unrecognised flag format`)}if(l===void 0&&a===void 0)throw new Error(`option creation failed due to no flags found in '${o}'.`);return{shortFlag:l,longFlag:a}}return zr.Option=t,zr.DualOptions=r,zr}var Ln={},Wi;function oa(){if(Wi)return Ln;Wi=1;const e=3;function t(s,i){if(Math.abs(s.length-i.length)>e)return Math.max(s.length,i.length);const o=[];for(let l=0;l<=s.length;l++)o[l]=[l];for(let l=0;l<=i.length;l++)o[0][l]=l;for(let l=1;l<=i.length;l++)for(let a=1;a<=s.length;a++){let u=1;s[a-1]===i[l-1]?u=0:u=1,o[a][l]=Math.min(o[a-1][l]+1,o[a][l-1]+1,o[a-1][l-1]+u),a>1&&l>1&&s[a-1]===i[l-2]&&s[a-2]===i[l-1]&&(o[a][l]=Math.min(o[a][l],o[a-2][l-2]+1))}return o[s.length][i.length]}function r(s,i){if(!i||i.length===0)return"";i=Array.from(new Set(i));const o=s.startsWith("--");o&&(s=s.slice(2),i=i.map(f=>f.slice(2)));let l=[],a=e;const u=.4;return i.forEach(f=>{if(f.length<=1)return;const m=t(s,f),C=Math.max(s.length,f.length);(C-m)/C>u&&(m<a?(a=m,l=[f]):m===a&&l.push(f))}),l.sort((f,m)=>f.localeCompare(m)),o&&(l=l.map(f=>`--${f}`)),l.length>1?`
(Did you mean one of ${l.join(", ")}?)`:l.length===1?`
(Did you mean ${l[0]}?)`:""}return Ln.suggestSimilar=r,Ln}var Hi;function aa(){if(Hi)return Wr;Hi=1;const e=ra.EventEmitter,t=Ts,r=na,s=ia,i=sa,{Argument:o,humanReadableArgName:l}=qn(),{CommanderError:a}=dn(),{Help:u,stripColor:f}=vs(),{Option:m,DualOptions:C}=ws(),{suggestSimilar:w}=oa();class g extends e{constructor(h){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=h||"",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:p=>i.stdout.write(p),writeErr:p=>i.stderr.write(p),outputError:(p,v)=>v(p),getOutHelpWidth:()=>i.stdout.isTTY?i.stdout.columns:void 0,getErrHelpWidth:()=>i.stderr.isTTY?i.stderr.columns:void 0,getOutHasColors:()=>{var p,v;return O()??(i.stdout.isTTY&&((v=(p=i.stdout).hasColors)==null?void 0:v.call(p)))},getErrHasColors:()=>{var p,v;return O()??(i.stderr.isTTY&&((v=(p=i.stderr).hasColors)==null?void 0:v.call(p)))},stripColor:p=>f(p)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(h){return this._outputConfiguration=h._outputConfiguration,this._helpOption=h._helpOption,this._helpCommand=h._helpCommand,this._helpConfiguration=h._helpConfiguration,this._exitCallback=h._exitCallback,this._storeOptionsAsProperties=h._storeOptionsAsProperties,this._combineFlagAndOptionalValue=h._combineFlagAndOptionalValue,this._allowExcessArguments=h._allowExcessArguments,this._enablePositionalOptions=h._enablePositionalOptions,this._showHelpAfterError=h._showHelpAfterError,this._showSuggestionAfterError=h._showSuggestionAfterError,this}_getCommandAndAncestors(){const h=[];for(let p=this;p;p=p.parent)h.push(p);return h}command(h,p,v){let I=p,N=v;typeof I=="object"&&I!==null&&(N=I,I=null),N=N||{};const[,F,x]=h.match(/([^ ]+) *(.*)/),U=this.createCommand(F);return I&&(U.description(I),U._executableHandler=!0),N.isDefault&&(this._defaultCommandName=U._name),U._hidden=!!(N.noHelp||N.hidden),U._executableFile=N.executableFile||null,x&&U.arguments(x),this._registerCommand(U),U.parent=this,U.copyInheritedSettings(this),I?this:U}createCommand(h){return new g(h)}createHelp(){return Object.assign(new u,this.configureHelp())}configureHelp(h){return h===void 0?this._helpConfiguration:(this._helpConfiguration=h,this)}configureOutput(h){return h===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,h),this)}showHelpAfterError(h=!0){return typeof h!="string"&&(h=!!h),this._showHelpAfterError=h,this}showSuggestionAfterError(h=!0){return this._showSuggestionAfterError=!!h,this}addCommand(h,p){if(!h._name)throw new Error(`Command passed to .addCommand() must have a name
- specify the name in Command constructor or using .name()`);return p=p||{},p.isDefault&&(this._defaultCommandName=h._name),(p.noHelp||p.hidden)&&(h._hidden=!0),this._registerCommand(h),h.parent=this,h._checkForBrokenPassThrough(),this}createArgument(h,p){return new o(h,p)}argument(h,p,v,I){const N=this.createArgument(h,p);return typeof v=="function"?N.default(I).argParser(v):N.default(v),this.addArgument(N),this}arguments(h){return h.trim().split(/ +/).forEach(p=>{this.argument(p)}),this}addArgument(h){const p=this.registeredArguments.slice(-1)[0];if(p&&p.variadic)throw new Error(`only the last argument can be variadic '${p.name()}'`);if(h.required&&h.defaultValue!==void 0&&h.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${h.name()}'`);return this.registeredArguments.push(h),this}helpCommand(h,p){if(typeof h=="boolean")return this._addImplicitHelpCommand=h,this;h=h??"help [command]";const[,v,I]=h.match(/([^ ]+) *(.*)/),N=p??"display help for command",F=this.createCommand(v);return F.helpOption(!1),I&&F.arguments(I),N&&F.description(N),this._addImplicitHelpCommand=!0,this._helpCommand=F,this}addHelpCommand(h,p){return typeof h!="object"?(this.helpCommand(h,p),this):(this._addImplicitHelpCommand=!0,this._helpCommand=h,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(h,p){const v=["preSubcommand","preAction","postAction"];if(!v.includes(h))throw new Error(`Unexpected value for event passed to hook : '${h}'.
Expecting one of '${v.join("', '")}'`);return this._lifeCycleHooks[h]?this._lifeCycleHooks[h].push(p):this._lifeCycleHooks[h]=[p],this}exitOverride(h){return h?this._exitCallback=h:this._exitCallback=p=>{if(p.code!=="commander.executeSubCommandAsync")throw p},this}_exit(h,p,v){this._exitCallback&&this._exitCallback(new a(h,p,v)),i.exit(h)}action(h){const p=v=>{const I=this.registeredArguments.length,N=v.slice(0,I);return this._storeOptionsAsProperties?N[I]=this:N[I]=this.opts(),N.push(this),h.apply(this,N)};return this._actionHandler=p,this}createOption(h,p){return new m(h,p)}_callParseArg(h,p,v,I){try{return h.parseArg(p,v)}catch(N){if(N.code==="commander.invalidArgument"){const F=`${I} ${N.message}`;this.error(F,{exitCode:N.exitCode,code:N.code})}throw N}}_registerOption(h){const p=h.short&&this._findOption(h.short)||h.long&&this._findOption(h.long);if(p){const v=h.long&&this._findOption(h.long)?h.long:h.short;throw new Error(`Cannot add option '${h.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${v}'
- already used by option '${p.flags}'`)}this.options.push(h)}_registerCommand(h){const p=I=>[I.name()].concat(I.aliases()),v=p(h).find(I=>this._findCommand(I));if(v){const I=p(this._findCommand(v)).join("|"),N=p(h).join("|");throw new Error(`cannot add command '${N}' as already have command '${I}'`)}this.commands.push(h)}addOption(h){this._registerOption(h);const p=h.name(),v=h.attributeName();if(h.negate){const N=h.long.replace(/^--no-/,"--");this._findOption(N)||this.setOptionValueWithSource(v,h.defaultValue===void 0?!0:h.defaultValue,"default")}else h.defaultValue!==void 0&&this.setOptionValueWithSource(v,h.defaultValue,"default");const I=(N,F,x)=>{N==null&&h.presetArg!==void 0&&(N=h.presetArg);const U=this.getOptionValue(v);N!==null&&h.parseArg?N=this._callParseArg(h,N,U,F):N!==null&&h.variadic&&(N=h._concatValue(N,U)),N==null&&(h.negate?N=!1:h.isBoolean()||h.optional?N=!0:N=""),this.setOptionValueWithSource(v,N,x)};return this.on("option:"+p,N=>{const F=`error: option '${h.flags}' argument '${N}' is invalid.`;I(N,F,"cli")}),h.envVar&&this.on("optionEnv:"+p,N=>{const F=`error: option '${h.flags}' value '${N}' from env '${h.envVar}' is invalid.`;I(N,F,"env")}),this}_optionEx(h,p,v,I,N){if(typeof p=="object"&&p instanceof m)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const F=this.createOption(p,v);if(F.makeOptionMandatory(!!h.mandatory),typeof I=="function")F.default(N).argParser(I);else if(I instanceof RegExp){const x=I;I=(U,V)=>{const $=x.exec(U);return $?$[0]:V},F.default(N).argParser(I)}else F.default(I);return this.addOption(F)}option(h,p,v,I){return this._optionEx({},h,p,v,I)}requiredOption(h,p,v,I){return this._optionEx({mandatory:!0},h,p,v,I)}combineFlagAndOptionalValue(h=!0){return this._combineFlagAndOptionalValue=!!h,this}allowUnknownOption(h=!0){return this._allowUnknownOption=!!h,this}allowExcessArguments(h=!0){return this._allowExcessArguments=!!h,this}enablePositionalOptions(h=!0){return this._enablePositionalOptions=!!h,this}passThroughOptions(h=!0){return this._passThroughOptions=!!h,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(h=!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=!!h,this}getOptionValue(h){return this._storeOptionsAsProperties?this[h]:this._optionValues[h]}setOptionValue(h,p){return this.setOptionValueWithSource(h,p,void 0)}setOptionValueWithSource(h,p,v){return this._storeOptionsAsProperties?this[h]=p:this._optionValues[h]=p,this._optionValueSources[h]=v,this}getOptionValueSource(h){return this._optionValueSources[h]}getOptionValueSourceWithGlobals(h){let p;return this._getCommandAndAncestors().forEach(v=>{v.getOptionValueSource(h)!==void 0&&(p=v.getOptionValueSource(h))}),p}_prepareUserArgs(h,p){var I;if(h!==void 0&&!Array.isArray(h))throw new Error("first parameter to parse must be array or undefined");if(p=p||{},h===void 0&&p.from===void 0){(I=i.versions)!=null&&I.electron&&(p.from="electron");const N=i.execArgv??[];(N.includes("-e")||N.includes("--eval")||N.includes("-p")||N.includes("--print"))&&(p.from="eval")}h===void 0&&(h=i.argv),this.rawArgs=h.slice();let v;switch(p.from){case void 0:case"node":this._scriptPath=h[1],v=h.slice(2);break;case"electron":i.defaultApp?(this._scriptPath=h[1],v=h.slice(2)):v=h.slice(1);break;case"user":v=h.slice(0);break;case"eval":v=h.slice(1);break;default:throw new Error(`unexpected parse option { from: '${p.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",v}parse(h,p){this._prepareForParse();const v=this._prepareUserArgs(h,p);return this._parseCommand([],v),this}async parseAsync(h,p){this._prepareForParse();const v=this._prepareUserArgs(h,p);return await this._parseCommand([],v),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(h,p,v){if(s.existsSync(h))return;const I=p?`searched for local subcommand relative to directory '${p}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",N=`'${h}' does not exist
- if '${v}' 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
- ${I}`;throw new Error(N)}_executeSubCommand(h,p){p=p.slice();let v=!1;const I=[".js",".ts",".tsx",".mjs",".cjs"];function N($,tt){const D=r.resolve($,tt);if(s.existsSync(D))return D;if(I.includes(r.extname(tt)))return;const H=I.find(P=>s.existsSync(`${D}${P}`));if(H)return`${D}${H}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let F=h._executableFile||`${this._name}-${h._name}`,x=this._executableDir||"";if(this._scriptPath){let $;try{$=s.realpathSync(this._scriptPath)}catch{$=this._scriptPath}x=r.resolve(r.dirname($),x)}if(x){let $=N(x,F);if(!$&&!h._executableFile&&this._scriptPath){const tt=r.basename(this._scriptPath,r.extname(this._scriptPath));tt!==this._name&&($=N(x,`${tt}-${h._name}`))}F=$||F}v=I.includes(r.extname(F));let U;i.platform!=="win32"?v?(p.unshift(F),p=y(i.execArgv).concat(p),U=t.spawn(i.argv[0],p,{stdio:"inherit"})):U=t.spawn(F,p,{stdio:"inherit"}):(this._checkForMissingExecutable(F,x,h._name),p.unshift(F),p=y(i.execArgv).concat(p),U=t.spawn(i.execPath,p,{stdio:"inherit"})),U.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(tt=>{i.on(tt,()=>{U.killed===!1&&U.exitCode===null&&U.kill(tt)})});const V=this._exitCallback;U.on("close",$=>{$=$??1,V?V(new a($,"commander.executeSubCommandAsync","(close)")):i.exit($)}),U.on("error",$=>{if($.code==="ENOENT")this._checkForMissingExecutable(F,x,h._name);else if($.code==="EACCES")throw new Error(`'${F}' not executable`);if(!V)i.exit(1);else{const tt=new a(1,"commander.executeSubCommandAsync","(error)");tt.nestedError=$,V(tt)}}),this.runningCommand=U}_dispatchSubcommand(h,p,v){const I=this._findCommand(h);I||this.help({error:!0}),I._prepareForParse();let N;return N=this._chainOrCallSubCommandHook(N,I,"preSubcommand"),N=this._chainOrCall(N,()=>{if(I._executableHandler)this._executeSubCommand(I,p.concat(v));else return I._parseCommand(p,v)}),N}_dispatchHelpCommand(h){var v,I;h||this.help();const p=this._findCommand(h);return p&&!p._executableHandler&&p.help(),this._dispatchSubcommand(h,[],[((v=this._getHelpOption())==null?void 0:v.long)??((I=this._getHelpOption())==null?void 0:I.short)??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((h,p)=>{h.required&&this.args[p]==null&&this.missingArgument(h.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const h=(v,I,N)=>{let F=I;if(I!==null&&v.parseArg){const x=`error: command-argument value '${I}' is invalid for argument '${v.name()}'.`;F=this._callParseArg(v,I,N,x)}return F};this._checkNumberOfArguments();const p=[];this.registeredArguments.forEach((v,I)=>{let N=v.defaultValue;v.variadic?I<this.args.length?(N=this.args.slice(I),v.parseArg&&(N=N.reduce((F,x)=>h(v,x,F),v.defaultValue))):N===void 0&&(N=[]):I<this.args.length&&(N=this.args[I],v.parseArg&&(N=h(v,N,v.defaultValue))),p[I]=N}),this.processedArgs=p}_chainOrCall(h,p){return h&&h.then&&typeof h.then=="function"?h.then(()=>p()):p()}_chainOrCallHooks(h,p){let v=h;const I=[];return this._getCommandAndAncestors().reverse().filter(N=>N._lifeCycleHooks[p]!==void 0).forEach(N=>{N._lifeCycleHooks[p].forEach(F=>{I.push({hookedCommand:N,callback:F})})}),p==="postAction"&&I.reverse(),I.forEach(N=>{v=this._chainOrCall(v,()=>N.callback(N.hookedCommand,this))}),v}_chainOrCallSubCommandHook(h,p,v){let I=h;return this._lifeCycleHooks[v]!==void 0&&this._lifeCycleHooks[v].forEach(N=>{I=this._chainOrCall(I,()=>N(this,p))}),I}_parseCommand(h,p){const v=this.parseOptions(p);if(this._parseOptionsEnv(),this._parseOptionsImplied(),h=h.concat(v.operands),p=v.unknown,this.args=h.concat(p),h&&this._findCommand(h[0]))return this._dispatchSubcommand(h[0],h.slice(1),p);if(this._getHelpCommand()&&h[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(h[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(p),this._dispatchSubcommand(this._defaultCommandName,h,p);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(v.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const I=()=>{v.unknown.length>0&&this.unknownOption(v.unknown[0])},N=`command:${this.name()}`;if(this._actionHandler){I(),this._processArguments();let F;return F=this._chainOrCallHooks(F,"preAction"),F=this._chainOrCall(F,()=>this._actionHandler(this.processedArgs)),this.parent&&(F=this._chainOrCall(F,()=>{this.parent.emit(N,h,p)})),F=this._chainOrCallHooks(F,"postAction"),F}if(this.parent&&this.parent.listenerCount(N))I(),this._processArguments(),this.parent.emit(N,h,p);else if(h.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",h,p);this.listenerCount("command:*")?this.emit("command:*",h,p):this.commands.length?this.unknownCommand():(I(),this._processArguments())}else this.commands.length?(I(),this.help({error:!0})):(I(),this._processArguments())}_findCommand(h){if(h)return this.commands.find(p=>p._name===h||p._aliases.includes(h))}_findOption(h){return this.options.find(p=>p.is(h))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(h=>{h.options.forEach(p=>{p.mandatory&&h.getOptionValue(p.attributeName())===void 0&&h.missingMandatoryOptionValue(p)})})}_checkForConflictingLocalOptions(){const h=this.options.filter(v=>{const I=v.attributeName();return this.getOptionValue(I)===void 0?!1:this.getOptionValueSource(I)!=="default"});h.filter(v=>v.conflictsWith.length>0).forEach(v=>{const I=h.find(N=>v.conflictsWith.includes(N.attributeName()));I&&this._conflictingOption(v,I)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(h=>{h._checkForConflictingLocalOptions()})}parseOptions(h){const p=[],v=[];let I=p;const N=h.slice();function F(U){return U.length>1&&U[0]==="-"}let x=null;for(;N.length;){const U=N.shift();if(U==="--"){I===v&&I.push(U),I.push(...N);break}if(x&&!F(U)){this.emit(`option:${x.name()}`,U);continue}if(x=null,F(U)){const V=this._findOption(U);if(V){if(V.required){const $=N.shift();$===void 0&&this.optionMissingArgument(V),this.emit(`option:${V.name()}`,$)}else if(V.optional){let $=null;N.length>0&&!F(N[0])&&($=N.shift()),this.emit(`option:${V.name()}`,$)}else this.emit(`option:${V.name()}`);x=V.variadic?V:null;continue}}if(U.length>2&&U[0]==="-"&&U[1]!=="-"){const V=this._findOption(`-${U[1]}`);if(V){V.required||V.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${V.name()}`,U.slice(2)):(this.emit(`option:${V.name()}`),N.unshift(`-${U.slice(2)}`));continue}}if(/^--[^=]+=/.test(U)){const V=U.indexOf("="),$=this._findOption(U.slice(0,V));if($&&($.required||$.optional)){this.emit(`option:${$.name()}`,U.slice(V+1));continue}}if(F(U)&&(I=v),(this._enablePositionalOptions||this._passThroughOptions)&&p.length===0&&v.length===0){if(this._findCommand(U)){p.push(U),N.length>0&&v.push(...N);break}else if(this._getHelpCommand()&&U===this._getHelpCommand().name()){p.push(U),N.length>0&&p.push(...N);break}else if(this._defaultCommandName){v.push(U),N.length>0&&v.push(...N);break}}if(this._passThroughOptions){I.push(U),N.length>0&&I.push(...N);break}I.push(U)}return{operands:p,unknown:v}}opts(){if(this._storeOptionsAsProperties){const h={},p=this.options.length;for(let v=0;v<p;v++){const I=this.options[v].attributeName();h[I]=I===this._versionOptionName?this._version:this[I]}return h}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((h,p)=>Object.assign(h,p.opts()),{})}error(h,p){this._outputConfiguration.outputError(`${h}
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
`),this.outputHelp({error:!0}));const v=p||{},I=v.exitCode||1,N=v.code||"commander.error";this._exit(I,N,h)}_parseOptionsEnv(){this.options.forEach(h=>{if(h.envVar&&h.envVar in i.env){const p=h.attributeName();(this.getOptionValue(p)===void 0||["default","config","env"].includes(this.getOptionValueSource(p)))&&(h.required||h.optional?this.emit(`optionEnv:${h.name()}`,i.env[h.envVar]):this.emit(`optionEnv:${h.name()}`))}})}_parseOptionsImplied(){const h=new C(this.options),p=v=>this.getOptionValue(v)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(v));this.options.filter(v=>v.implied!==void 0&&p(v.attributeName())&&h.valueFromOption(this.getOptionValue(v.attributeName()),v)).forEach(v=>{Object.keys(v.implied).filter(I=>!p(I)).forEach(I=>{this.setOptionValueWithSource(I,v.implied[I],"implied")})})}missingArgument(h){const p=`error: missing required argument '${h}'`;this.error(p,{code:"commander.missingArgument"})}optionMissingArgument(h){const p=`error: option '${h.flags}' argument missing`;this.error(p,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(h){const p=`error: required option '${h.flags}' not specified`;this.error(p,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(h,p){const v=F=>{const x=F.attributeName(),U=this.getOptionValue(x),V=this.options.find(tt=>tt.negate&&x===tt.attributeName()),$=this.options.find(tt=>!tt.negate&&x===tt.attributeName());return V&&(V.presetArg===void 0&&U===!1||V.presetArg!==void 0&&U===V.presetArg)?V:$||F},I=F=>{const x=v(F),U=x.attributeName();return this.getOptionValueSource(U)==="env"?`environment variable '${x.envVar}'`:`option '${x.flags}'`},N=`error: ${I(h)} cannot be used with ${I(p)}`;this.error(N,{code:"commander.conflictingOption"})}unknownOption(h){if(this._allowUnknownOption)return;let p="";if(h.startsWith("--")&&this._showSuggestionAfterError){let I=[],N=this;do{const F=N.createHelp().visibleOptions(N).filter(x=>x.long).map(x=>x.long);I=I.concat(F),N=N.parent}while(N&&!N._enablePositionalOptions);p=w(h,I)}const v=`error: unknown option '${h}'${p}`;this.error(v,{code:"commander.unknownOption"})}_excessArguments(h){if(this._allowExcessArguments)return;const p=this.registeredArguments.length,v=p===1?"":"s",N=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${p} argument${v} but got ${h.length}.`;this.error(N,{code:"commander.excessArguments"})}unknownCommand(){const h=this.args[0];let p="";if(this._showSuggestionAfterError){const I=[];this.createHelp().visibleCommands(this).forEach(N=>{I.push(N.name()),N.alias()&&I.push(N.alias())}),p=w(h,I)}const v=`error: unknown command '${h}'${p}`;this.error(v,{code:"commander.unknownCommand"})}version(h,p,v){if(h===void 0)return this._version;this._version=h,p=p||"-V, --version",v=v||"output the version number";const I=this.createOption(p,v);return this._versionOptionName=I.attributeName(),this._registerOption(I),this.on("option:"+I.name(),()=>{this._outputConfiguration.writeOut(`${h}
`),this._exit(0,"commander.version",h)}),this}description(h,p){return h===void 0&&p===void 0?this._description:(this._description=h,p&&(this._argsDescription=p),this)}summary(h){return h===void 0?this._summary:(this._summary=h,this)}alias(h){var I;if(h===void 0)return this._aliases[0];let p=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(p=this.commands[this.commands.length-1]),h===p._name)throw new Error("Command alias can't be the same as its name");const v=(I=this.parent)==null?void 0:I._findCommand(h);if(v){const N=[v.name()].concat(v.aliases()).join("|");throw new Error(`cannot add alias '${h}' to command '${this.name()}' as already have command '${N}'`)}return p._aliases.push(h),this}aliases(h){return h===void 0?this._aliases:(h.forEach(p=>this.alias(p)),this)}usage(h){if(h===void 0){if(this._usage)return this._usage;const p=this.registeredArguments.map(v=>l(v));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?p:[]).join(" ")}return this._usage=h,this}name(h){return h===void 0?this._name:(this._name=h,this)}nameFromFilename(h){return this._name=r.basename(h,r.extname(h)),this}executableDir(h){return h===void 0?this._executableDir:(this._executableDir=h,this)}helpInformation(h){const p=this.createHelp(),v=this._getOutputContext(h);p.prepareContext({error:v.error,helpWidth:v.helpWidth,outputHasColors:v.hasColors});const I=p.formatHelp(this,p);return v.hasColors?I:this._outputConfiguration.stripColor(I)}_getOutputContext(h){h=h||{};const p=!!h.error;let v,I,N;return p?(v=x=>this._outputConfiguration.writeErr(x),I=this._outputConfiguration.getErrHasColors(),N=this._outputConfiguration.getErrHelpWidth()):(v=x=>this._outputConfiguration.writeOut(x),I=this._outputConfiguration.getOutHasColors(),N=this._outputConfiguration.getOutHelpWidth()),{error:p,write:x=>(I||(x=this._outputConfiguration.stripColor(x)),v(x)),hasColors:I,helpWidth:N}}outputHelp(h){var F;let p;typeof h=="function"&&(p=h,h=void 0);const v=this._getOutputContext(h),I={error:v.error,write:v.write,command:this};this._getCommandAndAncestors().reverse().forEach(x=>x.emit("beforeAllHelp",I)),this.emit("beforeHelp",I);let N=this.helpInformation({error:v.error});if(p&&(N=p(N),typeof N!="string"&&!Buffer.isBuffer(N)))throw new Error("outputHelp callback must return a string or a Buffer");v.write(N),(F=this._getHelpOption())!=null&&F.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",I),this._getCommandAndAncestors().forEach(x=>x.emit("afterAllHelp",I))}helpOption(h,p){return typeof h=="boolean"?(h?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(h=h??"-h, --help",p=p??"display help for command",this._helpOption=this.createOption(h,p),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(h){return this._helpOption=h,this}help(h){this.outputHelp(h);let p=Number(i.exitCode??0);p===0&&h&&typeof h!="function"&&h.error&&(p=1),this._exit(p,"commander.help","(outputHelp)")}addHelpText(h,p){const v=["beforeAll","before","after","afterAll"];if(!v.includes(h))throw new Error(`Unexpected value for position to addHelpText.
Expecting one of '${v.join("', '")}'`);const I=`${h}Help`;return this.on(I,N=>{let F;typeof p=="function"?F=p({error:N.error,command:N.command}):F=p,F&&N.write(`${F}
`)}),this}_outputHelpIfRequested(h){const p=this._getHelpOption();p&&h.find(I=>p.is(I))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function y(S){return S.map(h=>{if(!h.startsWith("--inspect"))return h;let p,v="127.0.0.1",I="9229",N;return(N=h.match(/^(--inspect(-brk)?)$/))!==null?p=N[1]:(N=h.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(p=N[1],/^\d+$/.test(N[3])?I=N[3]:v=N[3]):(N=h.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(p=N[1],v=N[3],I=N[4]),p&&I!=="0"?`${p}=${v}:${parseInt(I)+1}`:h})}function O(){if(i.env.NO_COLOR||i.env.FORCE_COLOR==="0"||i.env.FORCE_COLOR==="false")return!1;if(i.env.FORCE_COLOR||i.env.CLICOLOR_FORCE!==void 0)return!0}return Wr.Command=g,Wr.useColor=O,Wr}var zi;function la(){if(zi)return he;zi=1;const{Argument:e}=qn(),{Command:t}=aa(),{CommanderError:r,InvalidArgumentError:s}=dn(),{Help:i}=vs(),{Option:o}=ws();return he.program=new t,he.createCommand=l=>new t(l),he.createOption=(l,a)=>new o(l,a),he.createArgument=(l,a)=>new e(l,a),he.Command=t,he.Option=o,he.Argument=e,he.Help=i,he.CommanderError=r,he.InvalidArgumentError=s,he.InvalidOptionArgumentError=s,he}var ca=la();const ua=Rs(ca),{program:Kf,createCommand:Qf,createArgument:Xf,createOption:Zf,CommanderError:Jf,InvalidArgumentError:qf,InvalidOptionArgumentError:td,Command:ha,Argument:ed,Option:jr,Help:rd}=ua;class De{constructor(t,r){this.id=De.idToString(t),this.payload=r}static idToString(t){return typeof t=="string"?t:JSON.stringify(t)}}function fa(e){return!!e&&typeof e.use=="function"}function da(e){return!!e}function pa(e){return!!e}class Sr{constructor(t,r){this.context=t,this.factory=r,this.registry=new Map}get(t){var r;return(r=this.registry.get(De.idToString(t)))==null?void 0:r.payload}has(t){return this.registry.has(De.idToString(t))}use(t,...r){let s=this.registry.get(De.idToString(t));if(!s){const i=typeof this.factory=="function"?this.factory(...r):r[0];da(i)&&(i.id=t),pa(i)&&(i.parent=this),s=new De(t,i),this.registry.set(De.idToString(t),s)}return s.payload&&fa(s.payload)&&s.payload.use(...r),s.payload}entries(){return[...this.registry.entries()]}values(){return[...this.registry.values()]}payloads(){return[...this.registry.values()].map(t=>t.payload)}clear(){this.registry.clear()}}const rn=" ",nn="cm",sn="inches",Le="rotations",pn="degrees",Lr="seconds",we="AUTO";var Ge=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARNING=2]="WARNING",e[e.ERROR=3]="ERROR",e[e.CRITICAL=4]="CRITICAL",e))(Ge||{});let Is=0,Vn;function _a(e){Is=e}function ji(e){Vn=e}function kn(e,t,r="-",s=80){const i=s-e.length-6-(t==null?void 0:t.length);return`#${t} ${r.repeat(Math.floor(i/2))} ${e} ${r.repeat(Math.ceil(i/2))} #`}function ma(e,...t){if(Is<=e)if(Vn)Vn(e,...t);else switch(e){case 4:case 3:console.error(`::${Ge[e]}::`,...t);break;case 2:console.warn(`::${Ge[e]}::`,...t);break;case 1:console.info(`::${Ge[e]}::`,...t);break;case 0:default:console.debug(`::${Ge[e]}::`,...t);break}}const Kt=(...e)=>ma(2,...e);function jt(e,t=1){let r=[];return e===void 0?r=[]:Array.isArray(e)?r=e.reduce((s,i)=>[...s,...jt(i,t)],[]):e.includes(`
`)?r=jt(e.split(/\r?\n/),t):r=[rn.repeat(t)+e],r}function Xe(e,t=!0){if(!e.filter(r=>!r.match(/^\s*$|^\s*#.*$/)).length){e.push("pass");//!!
}return e}function Be(e){return e==null?void 0:e.trim().toLowerCase().replaceAll(/[ .-]/gi,"_").replace(/^(\d)/im,"_$1").replaceAll(/[áéíóöőúüű]/g,t=>({á:"a",é:"e",í:"i",ó:"o",ö:"o",ő:"o",ú:"u",ü:"u",ű:"u"})[t]??t).replace(/[^a-zA-Z0-9_]/g,"")}function Ae(e){return e==null?void 0:e.replace(/\.[^/.]+$/,"").replaceAll(" ","_")}function fe(e,t=!0){return e=e==null?void 0:e.replaceAll(/\\(.)/g,"$1").replaceAll(" ","_").replaceAll(/[\/,.]/g,""),t&&(e=e==null?void 0:e.toUpperCase()),e}function Ea(e){return typeof e=="number"}function Me(e){const t=e==null?void 0:e.lastIndexOf(".");return e===void 0||t===-1||t===void 0?"":e.substring(t)}function de(e){return e==null?void 0:e.replace(/^.*[\\/]/,"")}function on(e){return e==null?void 0:e.split(".").slice(0,-1).join(".")}function ti(e){const t=e==null?void 0:e.trim().toLowerCase();return t==="true"||t==="1"}function oe(e){return parseInt(e??"0")}function ei(e){return`"""\r
`+e.map(([t,r])=>`${(t+":").padEnd(12," ")}${r}`).join(`\r
`)+`\r
"""\r
`}function ri(e,t){return t.extra||(t.extra={}),t.extra[e]||(t.extra[e]={}),t.extra[e]}class ni{constructor(t){this.name=t}get_code(t){const r=t.map(s=>Be(s));return`${this.get_pyname()} = Message([${r.join(", ")}])`}get_pyname(){return`message_${Be(this.name)}`}static createRegistry(t){return new Sr(t,(...r)=>new ni(r[0]))}}var Lt=(e=>(e[e.NONE=0]="NONE",e[e.SPIKE=1]="SPIKE",e[e.ROBOTINVENTOR=2]="ROBOTINVENTOR",e[e._GEN_EV5=3]="_GEN_EV5",e[e.EV3CLASSROOM=4]="EV3CLASSROOM",e[e._SB3_FORMAT=7]="_SB3_FORMAT",e[e.EV3G=8]="EV3G",e[e.EV3B=16]="EV3B",e[e._GEN_EV3=28]="_GEN_EV3",e[e._EV3Lab_FORMAT=24]="_EV3Lab_FORMAT",e[e.PYTHON=32]="PYTHON",e[e.WEDO2=64]="WEDO2",e))(Lt||{}),Mt=(e=>(e[e.SIMPLE=0]="SIMPLE",e[e.PARENTHESIS=1]="PARENTHESIS",e[e.REFERENCE=2]="REFERENCE",e[e.EXPONENTIATION=3]="EXPONENTIATION",e[e.UNARY=4]="UNARY",e[e.BINARYOP_MUL=5]="BINARYOP_MUL",e[e.BINARY_ADD=6]="BINARY_ADD",e[e.BINARY_SHIFT=7]="BINARY_SHIFT",e[e.BINARY_AND=8]="BINARY_AND",e[e.BINARY_XOR=9]="BINARY_XOR",e[e.BINARY_OR=10]="BINARY_OR",e[e.BINARY_COMPARISON=11]="BINARY_COMPARISON",e[e.BOOLEAN_NOT=12]="BOOLEAN_NOT",e[e.BOOLEAN_AND=13]="BOOLEAN_AND",e[e.BOOLEAN_OR=14]="BOOLEAN_OR",e[e.WEAKEST=99]="WEAKEST",e))(Mt||{}),rt=(e=>(e[e.UNKNOWN=0]="UNKNOWN",e[e.NUMBER=10]="NUMBER",e[e.STRING=11]="STRING",e[e.BOOLEAN=12]="BOOLEAN",e[e.ENUM=13]="ENUM",e[e.NUMBERARRAY=20]="NUMBERARRAY",e[e.BOOLEANARRAY=21]="BOOLEANARRAY",e[e.ENUMARRAY=23]="ENUMARRAY",e))(rt||{});class Q{constructor(t,r){this.options=r,t&&Q.is(t)?this.value=t.value:this.value=t}get is_string(){var t;return((t=this.options)==null?void 0:t.type)===rt.STRING}get is_numeric(){var t,r;return((t=this.options)==null?void 0:t.type)===rt.NUMBER||!((r=this.options)!=null&&r.is_dynamic)&&!this.is_string&&typeof this.value=="number"}get raw(){var t;return!this.is_string||(t=this.options)!=null&&t.is_dynamic?this.value:`"${this.value}"`}toString(){return Q.toString(this)}toInt(){return Q.toInt(this)}toFloat(){return Q.toFloat(this)}toBool(){return Q.toBool(this)}ensureString(t){return $n(t,this,rt.STRING)}ensureNumber(t,r=!1){var s;if(this.is_numeric){if((s=this.options)!=null&&s.is_dynamic)return this;{const i=r?this.toInt():this.toFloat();return new Q(i,{type:rt.NUMBER})}}else return $n(t,this,rt.NUMBER,r)}static is(t){return t instanceof Q}static is_dynamic(t){var r;return Q.is(t)&&!!((r=t.options)!=null&&r.is_dynamic)}static raw(t){return Q.is(t)?t.raw:t}static value(t){return Q.is(t)?t.value:t}static toString(t){var r;return((r=Q.value(t))==null?void 0:r.toString())??""}static toInt(t){const r=Q.is(t)?t.value:t;return parseInt((r==null?void 0:r.toString())??"")}static toFloat(t){const r=Q.is(t)?t.value:t;return parseFloat((r==null?void 0:r.toString())??"")}static toBool(t){const r=Q.is(t)?t.value:t;return ti(r==null?void 0:r.toString())}static ensureNumber(t,r,s=!1){return Q.is(r)?r.ensureNumber(t):t.helpers.use(s?"int_safe":"float_safe").call(r)}static isEqual(t,r){return Q.is(t)&&Q.is(r)?t.value===r.value&&JSON.stringify(t.options)===JSON.stringify(r.options):t===r}}function zt(e,t,r=!1){var l,a,u;const[s,i,o]=Array.isArray(t)?t:[t,void 0,void 0];if(i===void 0){if(Array.isArray(s))return zt(e,s,r);if(!Q.is_dynamic(s)){const f=Math.round(parseFloat((s==null?void 0:s.toString())??"")*1e3)/1e3;return new Q(f,{type:rt.NUMBER})}return!Q.is(s)||((l=s.options)==null?void 0:l.type)!==rt.NUMBER?Q.ensureNumber(e,s,r):new Q(s,{type:rt.NUMBER,is_dynamic:s.options.is_dynamic,precedence:s.options.precedence})}else if(o===void 0){const f=zt(e,i,r),m=!Q.is_dynamic(f);if(s==="-"||s==="+")if(m){const w=(s==="-"?-1:1)*Q.toFloat(f);return new Q(w,{type:rt.NUMBER})}else{const C=`${s}${Q.raw(f)}`;return new Q(C,{is_dynamic:!0,type:rt.NUMBER,precedence:Mt.UNARY})}else if(s==="abs")return m?new Q(Math.abs(Q.toFloat(f)),{type:rt.NUMBER}):(e.imports.use("umath",null),new Q(`umath.fabs(${Q.raw(f)})`,{is_dynamic:!0,type:rt.NUMBER,precedence:Mt.SIMPLE}))}else{const f=zt(e,s,r),m=zt(e,o,r);let C=Q.raw(f),w=Q.raw(m);if(!Q.is_dynamic(f)&&!Q.is_dynamic(m)){const y=(S,h,p)=>{switch(h){case"+":return S+p;case"-":return S-p;case"*":return S*p;case"/":return S/p;case"%":return S%p}};if(C===void 0||i===void 0||w===void 0)return;const O=zt(e,y(Q.toFloat(C),i==null?void 0:i.toString(),Q.toFloat(w)));return new Q(O,{type:rt.NUMBER,precedence:Mt.SIMPLE})}else{const y=zt(e,s,r),O=zt(e,o,r),S=i==null?void 0:i.toString(),h=N=>(N==null?void 0:N.toString())==="0",p=N=>(N==null?void 0:N.toString())==="1",v=N=>(N==null?void 0:N.toString())==="-1";if(S==="*"){if(h(y)||p(O))return y;if(h(O)||p(y))return O;if(v(y))return zt(e,["-",O]);if(v(O))return zt(e,["-",y])}else if(S==="/"){if(h(y)||p(O))return y;if(v(O))return zt(e,["-",y])}else if(S==="+"){if(h(y))return O;if(h(O))return y}else if(S==="-"){if(h(y))return zt(e,["-",O]);if(h(O))return y}const I=(()=>{switch(i.toString()){case"-":case"+":return Mt.BINARY_ADD;case"*":case"/":case"%":return Mt.BINARYOP_MUL;default:return Mt.WEAKEST}})();return I<(((a=y==null?void 0:y.options)==null?void 0:a.precedence)??0)&&(C=`(${C})`),I<(((u=O==null?void 0:O.options)==null?void 0:u.precedence)??0)&&(w=`(${w})`),new Q(`${C} ${i} ${w}`,{is_dynamic:!0,type:rt.NUMBER,precedence:I})}}}function $n(e,t,r,s=!1){var o;const i=(o=t==null?void 0:t.options)==null?void 0:o.type;if(r!==i)switch(r){case rt.NUMBER:t=s?e.helpers.use("int_safe").call(t):e.helpers.use("float_safe").call(t);break;case rt.STRING:t=e.helpers.use("str").call(t);break;case rt.NUMBERARRAY:switch(i){case rt.NUMBER:t=new Q(`[${t==null?void 0:t.raw}]`,{is_dynamic:!0,is_variable:!0,type:rt.NUMBERARRAY});break}break;case rt.BOOLEANARRAY:switch(i){case rt.BOOLEAN:t=new Q(`[${t==null?void 0:t.raw}]`,{is_dynamic:!0,is_variable:!0,type:rt.BOOLEANARRAY});break}break}return t}const Ki=new Map([[0,"Stop.COAST"],[1,"Stop.BRAKE"],[2,"Stop.HOLD"]]),Ns=new Map([[0,"Stop.COAST"],[1,"Stop.HOLD"]]),ga=new Map([[1,"Side.TOP"],[2,"Side.LEFT"],[3,"Side.RIGHT"],[4,"Side.BOTTOM"]]),Bn=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"]]),ii=new Map([[0,"Button.NONE"],[1,"Button.LEFT"],[2,"Button.CENTER"],[3,"Button.RIGHT"],[4,"Button.UP"],[5,"Button.DOWN"]]),Oa=new Map([[0,"RELEASED"],[1,"PRESSED"]]);var Ps=(e=>(e[e.OFF=0]="OFF",e[e.GREEN=1]="GREEN",e[e.RED=2]="RED",e[e.ORANGE=3]="ORANGE",e[e.GREEN_PULSE=4]="GREEN_PULSE",e[e.RED_PULSE=5]="RED_PULSE",e[e.ORANGE_PULSE=6]="ORANGE_PULSE",e))(Ps||{});const Ca=new Map([[0,"Color.NONE"],[1,"Color.GREEN"],[2,"Color.RED"],[3,"Color.ORANGE"],[4,"Color.GREEN_PULSE"],[5,"Color.RED_PULSE"],[6,"Color.ORANGE_PULSE"]]),Ta=new Map([[0,"Color.GREEN"],[1,"Color.RED"],[2,"Color.ORANGE"]]),si=new Map([[0,"Color.NONE"],[1,"Color.BLACK"],[2,"Color.BLUE"],[3,"Color.GREEN"],[4,"Color.YELLOW"],[5,"Color.RED"],[6,"Color.WHITE"],[7,"Color.BROWN"]]);function Ss(e,t=-1){if(e.imports.use("pybricks.parameters","Stop"),Ki.has(t))return Ki.get(t)}function Kr(e,t=0){const r=10**t;return Math.round(e*r)/r}function Ls(e){var t;return(e==null?void 0:e.value)==="="?"==":(t=e==null?void 0:e.value)==null?void 0:t.toString()}function wr(e){return["==","!=",">",">=","<","<="][(e==null?void 0:e.toInt())??-1]}class _n{constructor(){this.isPyFnEnabled=!1}call(...t){var s,i;const r=this.parent.helperFunctions