@stacksjs/rpx 0.10.0 β†’ 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2024 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -6,20 +6,20 @@
6
6
  <!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
7
7
  <!-- [![Codecov][codecov-src]][codecov-href] -->
8
8
 
9
- # A Better Developer Experience
9
+ # rpx
10
10
 
11
- > A zero-config reverse proxy for local development with SSL support, custom domains, and more.
11
+ > A zero-config reverse proxy for local development with SSL support, custom domains, and moreβ€”for a better local developer experience.
12
12
 
13
13
  ## Features
14
14
 
15
- - Simple, lightweight Reverse Proxy
16
- - Custom Domains _(with wildcard support)_
17
- - Zero-Config Setup
18
- - SSL Support _(HTTPS by default)_
19
- - Auto HTTP-to-HTTPS Redirection
20
- - `/etc/hosts` Management
21
- - Clean URLs _(removes `.html` extension)_
22
- - CLI and Library Support
15
+ - πŸ”€ Simple, lightweight Reverse Proxy
16
+ - ♾️ Custom Domains _(with wildcard support)_
17
+ - 0️⃣ Zero-Config Setup
18
+ - πŸ”’ SSL Support _(HTTPS by default)_
19
+ - πŸ›£οΈ Auto HTTP-to-HTTPS Redirection
20
+ - ✏️ `/etc/hosts` Management
21
+ - 🧼 Clean URLs _(removes `.html` extension)_
22
+ - πŸ€– CLI & Library Support
23
23
 
24
24
  ## Install
25
25
 
@@ -201,9 +201,9 @@ For casual chit-chat with others using this package:
201
201
 
202
202
  ## Postcardware
203
203
 
204
- Two things are true: Stacks OSS will always stay open-source, and we do love to receive postcards from wherever Stacks is used! 🌍 _We also publish them on our website. And thank you, Spatie_
204
+ β€œSoftware that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `rpx` is being used! We showcase them on our website too.
205
205
 
206
- Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094
206
+ Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎
207
207
 
208
208
  ## Sponsors
209
209
 
package/dist/bin/cli.js CHANGED
@@ -1,8 +1,8 @@
1
- import{E as B,F as U,a as N,b as d,g as q,z as O}from"../chunk-1rkjbws7.js";import"../chunk-ny83tnrp.js";import"../chunk-7am1svx0.js";import g from"node:process";import{EventEmitter as R}from"events";function C(e){return e==null?[]:Array.isArray(e)?e:[e]}function H(e,t,n,s){var i,a=e[t],r=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((i=+n,i*0===0)?i:n),!!n):(i=+n,i*0===0)?i:n;e[t]=a==null?r:Array.isArray(a)?a.concat(r):[a,r]}function G(e,t){e=e||[],t=t||{};var n,s,i,a,r,h={_:[]},o=0,l=0,m=0,c=e.length;let u=t.alias!==void 0,w=t.unknown!==void 0,_=t.default!==void 0;if(t.alias=t.alias||{},t.string=C(t.string),t.boolean=C(t.boolean),u)for(n in t.alias){s=t.alias[n]=C(t.alias[n]);for(o=0;o<s.length;o++)(t.alias[s[o]]=s.concat(n)).splice(o,1)}for(o=t.boolean.length;o-- >0;){s=t.alias[t.boolean[o]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(o=t.string.length;o-- >0;){s=t.alias[t.string[o]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(_){for(n in t.default)if(a=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[a]!==void 0){t[a].push(n);for(o=0;o<s.length;o++)t[a].push(s[o])}}let D=w?Object.keys(t.alias):[];for(o=0;o<c;o++){if(i=e[o],i==="--"){h._=h._.concat(e.slice(++o));break}for(l=0;l<i.length;l++)if(i.charCodeAt(l)!==45)break;if(l===0)h._.push(i);else if(i.substring(l,l+3)==="no-"){if(a=i.substring(l+3),w&&!~D.indexOf(a))return t.unknown(i);h[a]=!1}else{for(m=l+1;m<i.length;m++)if(i.charCodeAt(m)===61)break;a=i.substring(l,m),r=i.substring(++m)||(o+1===c||(""+e[o+1]).charCodeAt(0)===45||e[++o]),s=l===2?[a]:a;for(m=0;m<s.length;m++){if(a=s[m],w&&!~D.indexOf(a))return t.unknown("-".repeat(l)+a);H(h,a,m+1<s.length||r,t)}}}if(_){for(n in t.default)if(h[n]===void 0)h[n]=t.default[n]}if(u)for(n in h){s=t.alias[n]||[];while(s.length>0)h[s.shift()]=h[n]}return h}var v=(e)=>e.replace(/[<[].+/,"").trim(),L=(e)=>{let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],i=(h)=>{let o=!1,l=h[1];if(l.startsWith("..."))l=l.slice(3),o=!0;return{required:h[0].startsWith("<"),value:l,variadic:o}},a;while(a=t.exec(e))s.push(i(a));let r;while(r=n.exec(e))s.push(i(r));return s},M=(e)=>{let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((a,r)=>{return r!==n&&a.names.some((h)=>s.names.includes(h))&&typeof a.required==="boolean"}))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t},E=(e)=>{return e.sort((t,n)=>{return t.length>n.length?-1:1})[0]},V=(e,t)=>{return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`},S=(e)=>{return e.replace(/([a-z])-([a-z])/g,(t,n,s)=>{return n+s.toUpperCase()})},y=(e,t,n)=>{let s=0,i=t.length,a=e,r;for(;s<i;++s)r=a[t[s]],a=a[t[s]]=s===i-1?n:r!=null?r:!!~t[s+1].indexOf(".")||!(+t[s+1]>-1)?{}:[]},F=(e,t)=>{for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=Array.prototype.concat.call([],e[n]),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}},x=(e)=>{let t=/([^\\\/]+)$/.exec(e);return t?t[1]:""},j=(e)=>{return e.split(".").map((t,n)=>{return n===0?S(t):t}).join(".")};class p extends Error{constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=new Error(e).stack}}class T{constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=v(e).split(",").map((s)=>{let i=s.trim().replace(/^-{1,2}/,"");if(i.startsWith("no-"))this.negated=!0,i=i.replace(/^no-/,"");return j(i)}).sort((s,i)=>s.length>i.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var P=process.argv,W=`${process.platform}-${process.arch} node-${process.version}`;class ${constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=v(e),this.args=L(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new T(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof k}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>{return t.names.includes(e)})}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:i}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let o=E(t.map((l)=>l.rawName));a.push({title:"Commands",body:t.map((l)=>{return` ${V(l.rawName,o.length)} ${l.description}`}).join(`
1
+ import{b as N,c as d,r as O,u as B,v as U}from"../chunk-p95pk6sx.js";import"../chunk-3y886wa5.js";import{C as q}from"../chunk-g5db14m7.js";import"../chunk-gbny098p.js";import*as g from"node:process";import{EventEmitter as R}from"events";function C(e){return e==null?[]:Array.isArray(e)?e:[e]}function H(e,t,n,s){var i,a=e[t],r=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((i=+n,i*0===0)?i:n),!!n):(i=+n,i*0===0)?i:n;e[t]=a==null?r:Array.isArray(a)?a.concat(r):[a,r]}function G(e,t){e=e||[],t=t||{};var n,s,i,a,r,h={_:[]},o=0,l=0,m=0,c=e.length;let u=t.alias!==void 0,w=t.unknown!==void 0,_=t.default!==void 0;if(t.alias=t.alias||{},t.string=C(t.string),t.boolean=C(t.boolean),u)for(n in t.alias){s=t.alias[n]=C(t.alias[n]);for(o=0;o<s.length;o++)(t.alias[s[o]]=s.concat(n)).splice(o,1)}for(o=t.boolean.length;o-- >0;){s=t.alias[t.boolean[o]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(o=t.string.length;o-- >0;){s=t.alias[t.string[o]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(_){for(n in t.default)if(a=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[a]!==void 0){t[a].push(n);for(o=0;o<s.length;o++)t[a].push(s[o])}}let D=w?Object.keys(t.alias):[];for(o=0;o<c;o++){if(i=e[o],i==="--"){h._=h._.concat(e.slice(++o));break}for(l=0;l<i.length;l++)if(i.charCodeAt(l)!==45)break;if(l===0)h._.push(i);else if(i.substring(l,l+3)==="no-"){if(a=i.substring(l+3),w&&!~D.indexOf(a))return t.unknown(i);h[a]=!1}else{for(m=l+1;m<i.length;m++)if(i.charCodeAt(m)===61)break;a=i.substring(l,m),r=i.substring(++m)||(o+1===c||(""+e[o+1]).charCodeAt(0)===45||e[++o]),s=l===2?[a]:a;for(m=0;m<s.length;m++){if(a=s[m],w&&!~D.indexOf(a))return t.unknown("-".repeat(l)+a);H(h,a,m+1<s.length||r,t)}}}if(_){for(n in t.default)if(h[n]===void 0)h[n]=t.default[n]}if(u)for(n in h){s=t.alias[n]||[];while(s.length>0)h[s.shift()]=h[n]}return h}var v=(e)=>e.replace(/[<[].+/,"").trim(),L=(e)=>{let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],i=(h)=>{let o=!1,l=h[1];if(l.startsWith("..."))l=l.slice(3),o=!0;return{required:h[0].startsWith("<"),value:l,variadic:o}},a;while(a=t.exec(e))s.push(i(a));let r;while(r=n.exec(e))s.push(i(r));return s},M=(e)=>{let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((a,r)=>{return r!==n&&a.names.some((h)=>s.names.includes(h))&&typeof a.required==="boolean"}))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t},E=(e)=>{return e.sort((t,n)=>{return t.length>n.length?-1:1})[0]},V=(e,t)=>{return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`},S=(e)=>{return e.replace(/([a-z])-([a-z])/g,(t,n,s)=>{return n+s.toUpperCase()})},y=(e,t,n)=>{let s=0,i=t.length,a=e,r;for(;s<i;++s)r=a[t[s]],a=a[t[s]]=s===i-1?n:r!=null?r:!!~t[s+1].indexOf(".")||!(+t[s+1]>-1)?{}:[]},F=(e,t)=>{for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=Array.prototype.concat.call([],e[n]),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}},x=(e)=>{let t=/([^\\\/]+)$/.exec(e);return t?t[1]:""},j=(e)=>{return e.split(".").map((t,n)=>{return n===0?S(t):t}).join(".")};class p extends Error{constructor(e){super(e);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}}class T{constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=v(e).split(",").map((s)=>{let i=s.trim().replace(/^-{1,2}/,"");if(i.startsWith("no-"))this.negated=!0,i=i.replace(/^no-/,"");return j(i)}).sort((s,i)=>s.length>i.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var P=process.argv,W=`${process.platform}-${process.arch} node-${process.version}`;class ${constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=v(e),this.args=L(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new T(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof k}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>{return t.names.includes(e)})}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:i}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let o=E(t.map((l)=>l.rawName));a.push({title:"Commands",body:t.map((l)=>{return` ${V(l.rawName,o.length)} ${l.description}`}).join(`
2
2
  `)}),a.push({title:"For more info, run any command with the `--help` flag",body:t.map((l)=>` $ ${e}${l.name===""?"":` ${l.name}`} --help`).join(`
3
3
  `)})}let h=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)h=h.filter((o)=>o.name!=="version");if(h.length>0){let o=E(h.map((l)=>l.rawName));a.push({title:"Options",body:h.map((l)=>{return` ${V(l.rawName,o.length)} ${l.description} ${l.config.default===void 0?"":`(default: ${l.config.default})`}`}).join(`
4
4
  `)})}if(this.examples.length>0)a.push({title:"Examples",body:this.examples.map((o)=>{if(typeof o==="function")return o(e);return o}).join(`
5
5
  `)});if(i)a=i(a)||a;console.log(a.map((o)=>{return o.title?`${o.title}:
6
6
  ${o.body}`:o.body}).join(`
7
7
 
8
- `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${W}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new p(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new p(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let i=e[s.name.split(".")[0]];if(s.required){let a=n.some((r)=>r.negated&&r.names.includes(s.name));if(i===!0||i===!1&&!a)throw new p(`option \`${s.rawName}\` value is missing`)}}}}class k extends ${constructor(e){super("@@global@@","",{},e)}}var b=Object.assign;class A extends R{constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new k(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new $(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=P,{run:t=!0}={}){if(this.rawArgs=e,!this.name)this.name=e[1]?x(e[1]):"cli";let n=!0;for(let i of this.commands){let a=this.mri(e.slice(2),i),r=a.args[0];if(i.isMatched(r)){n=!1;let h=b(b({},a),{args:a.args.slice(1)});this.setParsedInfo(h,i,r),this.emit(`command:${r}`,i)}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let a=this.mri(e.slice(2),i);this.setParsedInfo(a,i),this.emit("command:!",i)}}if(n){let i=this.mri(e.slice(2));this.setParsedInfo(i)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.emit("command:*");return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=M(n),i=[],a=e.indexOf("--");if(a>-1)i=e.slice(a+1),e=e.slice(0,a);let r=G(e,s);r=Object.keys(r).reduce((c,u)=>{return b(b({},c),{[j(u)]:r[u]})},{_:[]});let h=r._,o={"--":i},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,m=Object.create(null);for(let c of n){if(!l&&c.config.default!==void 0)for(let u of c.names)o[u]=c.config.default;if(Array.isArray(c.config.type)){if(m[c.name]===void 0)m[c.name]=Object.create(null),m[c.name].shouldTransform=!0,m[c.name].transformFunction=c.config.type[0]}}for(let c of Object.keys(r))if(c!=="_"){let u=c.split(".");y(o,u,r[c]),F(o,m)}return{args:h,options:o}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let s=[];return n.args.forEach((i,a)=>{if(i.variadic)s.push(e.slice(a));else s.push(e[a])}),s.push(t),n.commandAction.apply(this,s)}}var f=new A("rpx");f.command("start","Start the Reverse Proxy Server").option("--from <from>","The URL to proxy from").option("--to <to>","The URL to proxy to").option("--key-path <path>","Absolute path to the SSL key").option("--cert-path <path>","Absolute path to the SSL certificate").option("--ca-cert-path <path>","Absolute path to the SSL CA certificate").option("--hosts-cleanup","Cleanup /etc/hosts on exit").option("--certs-cleanup","Cleanup SSL certificates on exit").option("--start-command <command>","Command to start the dev server").option("--start-cwd <path>","Current working directory for the dev server").option("--start-env <env>","Environment variables for the dev server").option("--verbose","Enable verbose logging").example("rpx start --from localhost:5173 --to my-project.localhost").example("rpx start --from localhost:3000 --to my-project.localhost/api").example("rpx start --from localhost:3000 --to localhost:3001").example("rpx start --from localhost:5173 --to my-project.test --key-path /absolute/path/to/key --cert-path /absolute/path/to/cert").action(async(e)=>{if(!e?.from||!e.to)return U(d);let t={from:e.from,to:e.to,https:{keyPath:e.keyPath,certPath:e.certPath,caCertPath:e.caCertPath},cleanup:{certs:e.certsCleanup||!1,hosts:e.hostsCleanup||!1},verbose:e.verbose||!1};if(e.startCommand){let n={command:e.startCommand};if(e.startCwd)n.cwd=e.startCwd;if(e.startEnv)try{n.env=JSON.parse(e.startEnv)}catch(s){console.error("Failed to parse start-env JSON:",s),g.exit(1)}t.start=n}return B(t)});f.command("watch:start <proxy>","Start the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{let n=q(d)?d.proxies.find((s)=>s.to===e||`${s.from}-${s.to}`===e):d.to===e?d:null;if(!n?.start)console.error(`No watch configuration found for proxy: ${e}`),g.exit(1);try{await O.startProcess(e,n.start,t.verbose),console.log(`Started dev server for ${e}`)}catch(s){console.error(`Failed to start dev server for ${e}:`,s),g.exit(1)}});f.command("watch:stop <proxy>","Stop the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{try{await O.stopProcess(e,t.verbose),console.log(`Stopped dev server for ${e}`)}catch(n){console.error(`Failed to stop dev server for ${e}:`,n),g.exit(1)}});f.command("watch:stopall","Stop all running dev servers").option("--verbose","Enable verbose logging").action(async(e)=>{try{await O.stopAll(e.verbose),console.log("Stopped all dev servers")}catch(t){console.error("Failed to stop all dev servers:",t),g.exit(1)}});f.command("version","Show the version of the Reverse Proxy CLI").action(()=>{console.log(N)});f.version(N);f.help();f.parse();
8
+ `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${W}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new p(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new p(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let i=e[s.name.split(".")[0]];if(s.required){let a=n.some((r)=>r.negated&&r.names.includes(s.name));if(i===!0||i===!1&&!a)throw new p(`option \`${s.rawName}\` value is missing`)}}}}class k extends ${constructor(e){super("@@global@@","",{},e)}}var b=Object.assign;class A extends R{constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new k(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new $(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=P,{run:t=!0}={}){if(this.rawArgs=e,!this.name)this.name=e[1]?x(e[1]):"cli";let n=!0;for(let i of this.commands){let a=this.mri(e.slice(2),i),r=a.args[0];if(i.isMatched(r)){n=!1;let h=b(b({},a),{args:a.args.slice(1)});this.setParsedInfo(h,i,r),this.emit(`command:${r}`,i)}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let a=this.mri(e.slice(2),i);this.setParsedInfo(a,i),this.emit("command:!",i)}}if(n){let i=this.mri(e.slice(2));this.setParsedInfo(i)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.emit("command:*");return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=M(n),i=[],a=e.indexOf("--");if(a>-1)i=e.slice(a+1),e=e.slice(0,a);let r=G(e,s);r=Object.keys(r).reduce((c,u)=>{return b(b({},c),{[j(u)]:r[u]})},{_:[]});let h=r._,o={"--":i},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,m=Object.create(null);for(let c of n){if(!l&&c.config.default!==void 0)for(let u of c.names)o[u]=c.config.default;if(Array.isArray(c.config.type)){if(m[c.name]===void 0)m[c.name]=Object.create(null),m[c.name].shouldTransform=!0,m[c.name].transformFunction=c.config.type[0]}}for(let c of Object.keys(r))if(c!=="_"){let u=c.split(".");y(o,u,r[c]),F(o,m)}return{args:h,options:o}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let s=[];return n.args.forEach((i,a)=>{if(i.variadic)s.push(e.slice(a));else s.push(e[a])}),s.push(t),n.commandAction.apply(this,s)}}var f=new A("rpx");f.command("start","Start the Reverse Proxy Server").option("--from <from>","The URL to proxy from").option("--to <to>","The URL to proxy to").option("--key-path <path>","Absolute path to the SSL key").option("--cert-path <path>","Absolute path to the SSL certificate").option("--ca-cert-path <path>","Absolute path to the SSL CA certificate").option("--hosts-cleanup","Cleanup /etc/hosts on exit").option("--certs-cleanup","Cleanup SSL certificates on exit").option("--start-command <command>","Command to start the dev server").option("--start-cwd <path>","Current working directory for the dev server").option("--start-env <env>","Environment variables for the dev server").option("--change-origin","Change the origin of the host header to the target URL").option("--verbose","Enable verbose logging").example("rpx start --from localhost:5173 --to my-project.localhost").example("rpx start --from localhost:3000 --to my-project.localhost/api").example("rpx start --from localhost:3000 --to localhost:3001").example("rpx start --from localhost:5173 --to my-project.test --key-path /absolute/path/to/key --cert-path /absolute/path/to/cert").example("rpx start --from localhost:5173 --to my-project.localhost --change-origin").action(async(e)=>{if(!e?.from||!e.to)return U(d);let t={from:e.from,to:e.to,https:{keyPath:e.keyPath,certPath:e.certPath,caCertPath:e.caCertPath},cleanup:{certs:e.certsCleanup||!1,hosts:e.hostsCleanup||!1},verbose:e.verbose||!1,changeOrigin:e.changeOrigin||!1};if(e.startCommand){let n={command:e.startCommand};if(e.startCwd)n.cwd=e.startCwd;if(e.startEnv)try{n.env=JSON.parse(e.startEnv)}catch(s){console.error("Failed to parse start-env JSON:",s),g.exit(1)}t.start=n}return B(t)});f.command("watch:start <proxy>","Start the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{let n=q(d)?d.proxies.find((s)=>s.to===e||`${s.from}-${s.to}`===e):d.to===e?d:null;if(!n?.start)console.error(`No watch configuration found for proxy: ${e}`),g.exit(1);try{await O.startProcess(e,n.start,t.verbose),console.log(`Started dev server for ${e}`)}catch(s){console.error(`Failed to start dev server for ${e}:`,s),g.exit(1)}});f.command("watch:stop <proxy>","Stop the dev server for a specific proxy").option("--verbose","Enable verbose logging").action(async(e,t)=>{try{await O.stopProcess(e,t.verbose),console.log(`Stopped dev server for ${e}`)}catch(n){console.error(`Failed to stop dev server for ${e}:`,n),g.exit(1)}});f.command("watch:stopall","Stop all running dev servers").option("--verbose","Enable verbose logging").action(async(e)=>{try{await O.stopAll(e.verbose),console.log("Stopped all dev servers")}catch(t){console.error("Failed to stop all dev servers:",t),g.exit(1)}});f.command("version","Show the version of the Reverse Proxy CLI").action(()=>{console.log(N)});f.version(N);f.help();f.parse();
@@ -0,0 +1 @@
1
+ import{createRequire as r}from"node:module";var e=r(import.meta.url);
@@ -0,0 +1 @@
1
+ import{y as F}from"./chunk-g5db14m7.js";import{H as X}from"./chunk-gbny098p.js";import Q from"node:dgram";var $=15353;function _(k){return{id:k.readUInt16BE(0),flags:k.readUInt16BE(2),qdcount:k.readUInt16BE(4),ancount:k.readUInt16BE(6),nscount:k.readUInt16BE(8),arcount:k.readUInt16BE(10)}}function C(k,z){let A=[],j=z;while(!0){let B=k[j];if(B===0){j++;break}if((B&192)===192){let G=k.readUInt16BE(j)&16383,{name:E}=C(k,G);A.push(E),j+=2;break}j++,A.push(k.subarray(j,j+B).toString("ascii")),j+=B}return{name:A.join("."),newOffset:j}}function H(k,z){let{name:A,newOffset:j}=C(k,z),B=k.readUInt16BE(j),G=k.readUInt16BE(j+2);return{question:{name:A,type:B,class:G},newOffset:j+4}}function U(k){let z=k.split("."),A=[];for(let j of z)A.push(Buffer.from([j.length])),A.push(Buffer.from(j,"ascii"));return A.push(Buffer.from([0])),Buffer.concat(A)}function T(k,z,A){let j=[],B=Buffer.alloc(12);B.writeUInt16BE(k,0),B.writeUInt16BE(33152,2),B.writeUInt16BE(1,4),B.writeUInt16BE(1,6),B.writeUInt16BE(0,8),B.writeUInt16BE(0,10),j.push(B),j.push(U(z.name));let G=Buffer.alloc(4);G.writeUInt16BE(z.type,0),G.writeUInt16BE(z.class,2),j.push(G),j.push(U(z.name));let E=Buffer.alloc(10);if(E.writeUInt16BE(z.type,0),E.writeUInt16BE(1,2),E.writeUInt32BE(300,4),z.type===1){E.writeUInt16BE(4,8),j.push(E);let K=A.split(".").map((M)=>Number.parseInt(M,10));j.push(Buffer.from(K))}else if(z.type===28)E.writeUInt16BE(16,8),j.push(E),j.push(Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]));else return B.writeUInt16BE(33155,2),B.writeUInt16BE(0,6),Buffer.concat([B,U(z.name),G]);return Buffer.concat(j)}function I(k,z){let A=[],j=Buffer.alloc(12);j.writeUInt16BE(k,0),j.writeUInt16BE(33155,2),j.writeUInt16BE(1,4),j.writeUInt16BE(0,6),j.writeUInt16BE(0,8),j.writeUInt16BE(0,10),A.push(j),A.push(U(z.name));let B=Buffer.alloc(4);return B.writeUInt16BE(z.type,0),B.writeUInt16BE(z.class,2),A.push(B),Buffer.concat(A)}var J=null,Z=new Set;async function R(k,z){if(J)return F("dns","DNS server already running",z),!0;return Z=new Set(k.map((A)=>A.toLowerCase())),new Promise((A)=>{J=Q.createSocket("udp4"),J.on("error",(j)=>{if(F("dns",`DNS server error: ${j.message}`,z),j.message.includes("EACCES")||j.message.includes("permission"))F("dns","DNS server requires root privileges to bind to port 53",z);J?.close(),J=null,A(!1)}),J.on("message",(j,B)=>{try{let G=_(j),{question:E}=H(j,12);F("dns",`Query for ${E.name} type ${E.type} from ${B.address}`,z);let K=E.name.toLowerCase(),M=!1;for(let Y of Z)if(K===Y||K.endsWith(`.${Y}`)){M=!0;break}let W;if(M&&(E.type===1||E.type===28))W=T(G.id,E,"127.0.0.1"),F("dns",`Responding with localhost for ${E.name}`,z);else W=I(G.id,E),F("dns",`NXDOMAIN for ${E.name}`,z);J?.send(W,B.port,B.address)}catch(G){F("dns",`Error processing DNS query: ${G}`,z)}}),J.on("listening",()=>{let j=J?.address();F("dns",`DNS server listening on ${j?.address}:${j?.port}`,z),A(!0)});try{J.bind($,"127.0.0.1")}catch(j){F("dns",`Failed to bind DNS server: ${j}`,z),A(!1)}})}function O(k){if(J)F("dns","Stopping DNS server",k),J.close(),J=null}function w(){return J!==null}function x(k){let z=new Set;for(let A of k){let j=A.split(".");if(j.length>=2)z.add(j[j.length-1])}return Array.from(z)}var V=new Set;async function D(k){if(process.platform!=="darwin")return;let{execSudoSync:z,getSudoPassword:A}=await import("./chunk-94pvxvt5.js");if(!A()){F("dns","Cannot flush DNS cache without SUDO_PASSWORD",k);return}try{z("dscacheutil -flushcache"),z("killall -HUP mDNSResponder 2>/dev/null || true"),F("dns","DNS cache flushed",k)}catch(B){F("dns",`Could not flush DNS cache: ${B}`,k)}}async function y(k,z){if(process.platform!=="darwin")return F("dns","Resolver setup only needed on macOS",k),!0;let{execSudoSync:A,getSudoPassword:j}=await import("./chunk-94pvxvt5.js");if(!j())return F("dns","SUDO_PASSWORD not set, cannot create resolver files",k),!1;let G=z?x(z):["test"];try{for(let E of G){if(V.has(E))continue;let K=`bash -c 'mkdir -p /etc/resolver && echo -e "nameserver 127.0.0.1\\nport ${$}" > /etc/resolver/${E}'`;A(K),V.add(E),F("dns",`Created /etc/resolver/${E} for .${E} TLD`,k)}return await D(k),!0}catch(E){return F("dns",`Failed to create resolver file: ${E}`,k),!1}}async function L(k){if(process.platform!=="darwin")return;let{execSudoSync:z,getSudoPassword:A}=await import("./chunk-94pvxvt5.js");try{if(A()){for(let B of V)z(`rm -f /etc/resolver/${B}`),F("dns",`Removed /etc/resolver/${B}`,k);V.clear()}}catch(j){F("dns",`Failed to remove resolver files: ${j}`,k)}}export{O as stopDnsServer,R as startDnsServer,y as setupResolver,L as removeResolver,w as isDnsServerRunning};
@@ -0,0 +1 @@
1
+ import{A as e,B as f,C as g,D as h,E as i,F as j,G as k,w as a,x as b,y as c,z as d}from"./chunk-g5db14m7.js";import"./chunk-gbny098p.js";export{k as safeDeleteFile,e as isValidRootCA,i as isSingleProxyOptions,j as isSingleProxyConfig,h as isMultiProxyOptions,g as isMultiProxyConfig,a as getSudoPassword,f as getPrimaryDomain,d as extractHostname,b as execSudoSync,c as debugLog};
@@ -0,0 +1,45 @@
1
+ import"./chunk-3y886wa5.js";import"./chunk-gbny098p.js";import m,{stdin as iD,stdout as sD}from"node:process";import R from"node:readline";import{WriteStream as CD}from"node:tty";function nD(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var _,I;function aD(){if(I)return _;I=1;let t="\x1B",u=`${t}[`,e="\x07",F={to(D,C){if(!C)return`${u}${D+1}G`;return`${u}${C+1};${D+1}H`},move(D,C){let s="";if(D<0)s+=`${u}${-D}D`;else if(D>0)s+=`${u}${D}C`;if(C<0)s+=`${u}${-C}A`;else if(C>0)s+=`${u}${C}B`;return s},up:(D=1)=>`${u}${D}A`,down:(D=1)=>`${u}${D}B`,forward:(D=1)=>`${u}${D}C`,backward:(D=1)=>`${u}${D}D`,nextLine:(D=1)=>`${u}E`.repeat(D),prevLine:(D=1)=>`${u}F`.repeat(D),left:`${u}G`,hide:`${u}?25l`,show:`${u}?25h`,save:`${t}7`,restore:`${t}8`},r={up:(D=1)=>`${u}S`.repeat(D),down:(D=1)=>`${u}T`.repeat(D)},n={screen:`${u}2J`,up:(D=1)=>`${u}1J`.repeat(D),down:(D=1)=>`${u}J`.repeat(D),line:`${u}2K`,lineEnd:`${u}K`,lineStart:`${u}1K`,lines(D){let C="";for(let s=0;s<D;s++)C+=this.line+(s<D-1?F.up():"");if(D)C+=F.left;return C}};return _={cursor:F,scroll:r,erase:n,beep:e},_}var p=aD(),v={exports:{}},W;function ED(){if(W)return v.exports;W=1;let t=process||{},u=t.argv||[],e=t.env||{},F=!(!!e.NO_COLOR||u.includes("--no-color"))&&(!!e.FORCE_COLOR||u.includes("--color")||t.platform==="win32"||(t.stdout||{}).isTTY&&e.TERM!=="dumb"||!!e.CI),r=(C,s,l=C)=>(B)=>{let a=""+B,h=a.indexOf(s,C.length);return~h?C+n(a,s,l,h)+s:C+a+s},n=(C,s,l,B)=>{let a="",h=0;do a+=C.substring(h,B)+l,h=B+s.length,B=C.indexOf(s,h);while(~B);return a+C.substring(h)},D=(C=F)=>{let s=C?r:()=>String;return{isColorSupported:C,reset:s("\x1B[0m","\x1B[0m"),bold:s("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:s("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:s("\x1B[3m","\x1B[23m"),underline:s("\x1B[4m","\x1B[24m"),inverse:s("\x1B[7m","\x1B[27m"),hidden:s("\x1B[8m","\x1B[28m"),strikethrough:s("\x1B[9m","\x1B[29m"),black:s("\x1B[30m","\x1B[39m"),red:s("\x1B[31m","\x1B[39m"),green:s("\x1B[32m","\x1B[39m"),yellow:s("\x1B[33m","\x1B[39m"),blue:s("\x1B[34m","\x1B[39m"),magenta:s("\x1B[35m","\x1B[39m"),cyan:s("\x1B[36m","\x1B[39m"),white:s("\x1B[37m","\x1B[39m"),gray:s("\x1B[90m","\x1B[39m"),bgBlack:s("\x1B[40m","\x1B[49m"),bgRed:s("\x1B[41m","\x1B[49m"),bgGreen:s("\x1B[42m","\x1B[49m"),bgYellow:s("\x1B[43m","\x1B[49m"),bgBlue:s("\x1B[44m","\x1B[49m"),bgMagenta:s("\x1B[45m","\x1B[49m"),bgCyan:s("\x1B[46m","\x1B[49m"),bgWhite:s("\x1B[47m","\x1B[49m"),blackBright:s("\x1B[90m","\x1B[39m"),redBright:s("\x1B[91m","\x1B[39m"),greenBright:s("\x1B[92m","\x1B[39m"),yellowBright:s("\x1B[93m","\x1B[39m"),blueBright:s("\x1B[94m","\x1B[39m"),magentaBright:s("\x1B[95m","\x1B[39m"),cyanBright:s("\x1B[96m","\x1B[39m"),whiteBright:s("\x1B[97m","\x1B[39m"),bgBlackBright:s("\x1B[100m","\x1B[49m"),bgRedBright:s("\x1B[101m","\x1B[49m"),bgGreenBright:s("\x1B[102m","\x1B[49m"),bgYellowBright:s("\x1B[103m","\x1B[49m"),bgBlueBright:s("\x1B[104m","\x1B[49m"),bgMagentaBright:s("\x1B[105m","\x1B[49m"),bgCyanBright:s("\x1B[106m","\x1B[49m"),bgWhiteBright:s("\x1B[107m","\x1B[49m")}};return v.exports=D(),v.exports.createColors=D,v.exports}var lD=ED(),i=nD(lD);function oD({onlyFirst:t=!1}={}){let u=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(u,t?void 0:"g")}var BD=oD();function Z(t){if(typeof t!="string")throw TypeError(`Expected a \`string\`, got \`${typeof t}\``);return t.replace(BD,"")}function H(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Q={exports:{}};(function(t){var u={};t.exports=u,u.eastAsianWidth=function(F){var r=F.charCodeAt(0),n=F.length==2?F.charCodeAt(1):0,D=r;return 55296<=r&&r<=56319&&56320<=n&&n<=57343&&(r&=1023,n&=1023,D=r<<10|n,D+=65536),D==12288||65281<=D&&D<=65376||65504<=D&&D<=65510?"F":D==8361||65377<=D&&D<=65470||65474<=D&&D<=65479||65482<=D&&D<=65487||65490<=D&&D<=65495||65498<=D&&D<=65500||65512<=D&&D<=65518?"H":4352<=D&&D<=4447||4515<=D&&D<=4519||4602<=D&&D<=4607||9001<=D&&D<=9002||11904<=D&&D<=11929||11931<=D&&D<=12019||12032<=D&&D<=12245||12272<=D&&D<=12283||12289<=D&&D<=12350||12353<=D&&D<=12438||12441<=D&&D<=12543||12549<=D&&D<=12589||12593<=D&&D<=12686||12688<=D&&D<=12730||12736<=D&&D<=12771||12784<=D&&D<=12830||12832<=D&&D<=12871||12880<=D&&D<=13054||13056<=D&&D<=19903||19968<=D&&D<=42124||42128<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||55216<=D&&D<=55238||55243<=D&&D<=55291||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65106||65108<=D&&D<=65126||65128<=D&&D<=65131||110592<=D&&D<=110593||127488<=D&&D<=127490||127504<=D&&D<=127546||127552<=D&&D<=127560||127568<=D&&D<=127569||131072<=D&&D<=194367||177984<=D&&D<=196605||196608<=D&&D<=262141?"W":32<=D&&D<=126||162<=D&&D<=163||165<=D&&D<=166||D==172||D==175||10214<=D&&D<=10221||10629<=D&&D<=10630?"Na":D==161||D==164||167<=D&&D<=168||D==170||173<=D&&D<=174||176<=D&&D<=180||182<=D&&D<=186||188<=D&&D<=191||D==198||D==208||215<=D&&D<=216||222<=D&&D<=225||D==230||232<=D&&D<=234||236<=D&&D<=237||D==240||242<=D&&D<=243||247<=D&&D<=250||D==252||D==254||D==257||D==273||D==275||D==283||294<=D&&D<=295||D==299||305<=D&&D<=307||D==312||319<=D&&D<=322||D==324||328<=D&&D<=331||D==333||338<=D&&D<=339||358<=D&&D<=359||D==363||D==462||D==464||D==466||D==468||D==470||D==472||D==474||D==476||D==593||D==609||D==708||D==711||713<=D&&D<=715||D==717||D==720||728<=D&&D<=731||D==733||D==735||768<=D&&D<=879||913<=D&&D<=929||931<=D&&D<=937||945<=D&&D<=961||963<=D&&D<=969||D==1025||1040<=D&&D<=1103||D==1105||D==8208||8211<=D&&D<=8214||8216<=D&&D<=8217||8220<=D&&D<=8221||8224<=D&&D<=8226||8228<=D&&D<=8231||D==8240||8242<=D&&D<=8243||D==8245||D==8251||D==8254||D==8308||D==8319||8321<=D&&D<=8324||D==8364||D==8451||D==8453||D==8457||D==8467||D==8470||8481<=D&&D<=8482||D==8486||D==8491||8531<=D&&D<=8532||8539<=D&&D<=8542||8544<=D&&D<=8555||8560<=D&&D<=8569||D==8585||8592<=D&&D<=8601||8632<=D&&D<=8633||D==8658||D==8660||D==8679||D==8704||8706<=D&&D<=8707||8711<=D&&D<=8712||D==8715||D==8719||D==8721||D==8725||D==8730||8733<=D&&D<=8736||D==8739||D==8741||8743<=D&&D<=8748||D==8750||8756<=D&&D<=8759||8764<=D&&D<=8765||D==8776||D==8780||D==8786||8800<=D&&D<=8801||8804<=D&&D<=8807||8810<=D&&D<=8811||8814<=D&&D<=8815||8834<=D&&D<=8835||8838<=D&&D<=8839||D==8853||D==8857||D==8869||D==8895||D==8978||9312<=D&&D<=9449||9451<=D&&D<=9547||9552<=D&&D<=9587||9600<=D&&D<=9615||9618<=D&&D<=9621||9632<=D&&D<=9633||9635<=D&&D<=9641||9650<=D&&D<=9651||9654<=D&&D<=9655||9660<=D&&D<=9661||9664<=D&&D<=9665||9670<=D&&D<=9672||D==9675||9678<=D&&D<=9681||9698<=D&&D<=9701||D==9711||9733<=D&&D<=9734||D==9737||9742<=D&&D<=9743||9748<=D&&D<=9749||D==9756||D==9758||D==9792||D==9794||9824<=D&&D<=9825||9827<=D&&D<=9829||9831<=D&&D<=9834||9836<=D&&D<=9837||D==9839||9886<=D&&D<=9887||9918<=D&&D<=9919||9924<=D&&D<=9933||9935<=D&&D<=9953||D==9955||9960<=D&&D<=9983||D==10045||D==10071||10102<=D&&D<=10111||11093<=D&&D<=11097||12872<=D&&D<=12879||57344<=D&&D<=63743||65024<=D&&D<=65039||D==65533||127232<=D&&D<=127242||127248<=D&&D<=127277||127280<=D&&D<=127337||127344<=D&&D<=127386||917760<=D&&D<=917999||983040<=D&&D<=1048573||1048576<=D&&D<=1114109?"A":"N"},u.characterLength=function(F){var r=this.eastAsianWidth(F);return r=="F"||r=="W"||r=="A"?2:1};function e(F){return F.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}u.length=function(F){for(var r=e(F),n=0,D=0;D<r.length;D++)n=n+this.characterLength(r[D]);return n},u.slice=function(F,r,n){textLen=u.length(F),r=r||0,n=n||1,r<0&&(r=textLen+r),n<0&&(n=textLen+n);for(var D="",C=0,s=e(F),l=0;l<s.length;l++){var B=s[l],a=u.length(B);if(C>=r-(a==2?1:0))if(C+a<=n)D+=B;else break;C+=a}return D}})(Q);var hD=Q.exports,cD=H(hD),mD=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g},pD=H(mD);function $(t,u={}){if(typeof t!="string"||t.length===0||(u={ambiguousIsNarrow:!0,...u},t=Z(t),t.length===0))return 0;t=t.replace(pD()," ");let e=u.ambiguousIsNarrow?1:2,F=0;for(let r of t){let n=r.codePointAt(0);if(n<=31||n>=127&&n<=159||n>=768&&n<=879)continue;switch(cD.eastAsianWidth(r)){case"F":case"W":F+=2;break;case"A":F+=e;break;default:F+=1}}return F}var k=10,L=(t=0)=>(u)=>`\x1B[${u+t}m`,P=(t=0)=>(u)=>`\x1B[${38+t};5;${u}m`,N=(t=0)=>(u,e,F)=>`\x1B[${38+t};2;${u};${e};${F}m`,o={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(o.modifier);var gD=Object.keys(o.color),AD=Object.keys(o.bgColor);[...gD,...AD];function dD(){let t=new Map;for(let[u,e]of Object.entries(o)){for(let[F,r]of Object.entries(e))o[F]={open:`\x1B[${r[0]}m`,close:`\x1B[${r[1]}m`},e[F]=o[F],t.set(r[0],r[1]);Object.defineProperty(o,u,{value:e,enumerable:!1})}return Object.defineProperty(o,"codes",{value:t,enumerable:!1}),o.color.close="\x1B[39m",o.bgColor.close="\x1B[49m",o.color.ansi=L(),o.color.ansi256=P(),o.color.ansi16m=N(),o.bgColor.ansi=L(k),o.bgColor.ansi256=P(k),o.bgColor.ansi16m=N(k),Object.defineProperties(o,{rgbToAnsi256:{value:(u,e,F)=>u===e&&e===F?u<8?16:u>248?231:Math.round((u-8)/247*24)+232:16+36*Math.round(u/255*5)+6*Math.round(e/255*5)+Math.round(F/255*5),enumerable:!1},hexToRgb:{value:(u)=>{let e=/[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));if(!e)return[0,0,0];let[F]=e;F.length===3&&(F=[...F].map((n)=>n+n).join(""));let r=Number.parseInt(F,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:(u)=>o.rgbToAnsi256(...o.hexToRgb(u)),enumerable:!1},ansi256ToAnsi:{value:(u)=>{if(u<8)return 30+u;if(u<16)return 90+(u-8);let e,F,r;if(u>=232)e=((u-232)*10+8)/255,F=e,r=e;else{u-=16;let C=u%36;e=Math.floor(u/36)/5,F=Math.floor(C/6)/5,r=C%6/5}let n=Math.max(e,F,r)*2;if(n===0)return 30;let D=30+(Math.round(r)<<2|Math.round(F)<<1|Math.round(e));return n===2&&(D+=60),D},enumerable:!1},rgbToAnsi:{value:(u,e,F)=>o.ansi256ToAnsi(o.rgbToAnsi256(u,e,F)),enumerable:!1},hexToAnsi:{value:(u)=>o.ansi256ToAnsi(o.hexToAnsi256(u)),enumerable:!1}}),o}var $D=dD(),y=new Set(["\x1B","Β›"]),bD=39,O="\x07",X="[",vD="]",DD="m",V=`${vD}8;;`,z=(t)=>`${y.values().next().value}${X}${t}${DD}`,G=(t)=>`${y.values().next().value}${V}${t}${O}`,fD=(t)=>t.split(" ").map((u)=>$(u)),M=(t,u,e)=>{let F=[...u],r=!1,n=!1,D=$(Z(t[t.length-1]));for(let[C,s]of F.entries()){let l=$(s);if(D+l<=e?t[t.length-1]+=s:(t.push(s),D=0),y.has(s)&&(r=!0,n=F.slice(C+1).join("").startsWith(V)),r){n?s===O&&(r=!1,n=!1):s===DD&&(r=!1);continue}D+=l,D===e&&C<F.length-1&&(t.push(""),D=0)}!D&&t[t.length-1].length>0&&t.length>1&&(t[t.length-2]+=t.pop())},xD=(t)=>{let u=t.split(" "),e=u.length;for(;e>0&&!($(u[e-1])>0);)e--;return e===u.length?t:u.slice(0,e).join(" ")+u.slice(e).join("")},yD=(t,u,e={})=>{if(e.trim!==!1&&t.trim()==="")return"";let F="",r,n,D=fD(t),C=[""];for(let[l,B]of t.split(" ").entries()){e.trim!==!1&&(C[C.length-1]=C[C.length-1].trimStart());let a=$(C[C.length-1]);if(l!==0&&(a>=u&&(e.wordWrap===!1||e.trim===!1)&&(C.push(""),a=0),(a>0||e.trim===!1)&&(C[C.length-1]+=" ",a++)),e.hard&&D[l]>u){let h=u-a,A=1+Math.floor((D[l]-h-1)/u);Math.floor((D[l]-1)/u)<A&&C.push(""),M(C,B,u);continue}if(a+D[l]>u&&a>0&&D[l]>0){if(e.wordWrap===!1&&a<u){M(C,B,u);continue}C.push("")}if(a+D[l]>u&&e.wordWrap===!1){M(C,B,u);continue}C[C.length-1]+=B}e.trim!==!1&&(C=C.map((l)=>xD(l)));let s=[...C.join(`
2
+ `)];for(let[l,B]of s.entries()){if(F+=B,y.has(B)){let{groups:h}=new RegExp(`(?:\\${X}(?<code>\\d+)m|\\${V}(?<uri>.*)${O})`).exec(s.slice(l).join(""))||{groups:{}};if(h.code!==void 0){let A=Number.parseFloat(h.code);r=A===bD?void 0:A}else h.uri!==void 0&&(n=h.uri.length===0?void 0:h.uri)}let a=$D.codes.get(Number(r));s[l+1]===`
3
+ `?(n&&(F+=G("")),r&&a&&(F+=z(a))):B===`
4
+ `&&(r&&a&&(F+=z(r)),n&&(F+=G(n)))}return F};function K(t,u,e){return String(t).normalize().replace(/\r\n/g,`
5
+ `).split(`
6
+ `).map((F)=>yD(F,u,e)).join(`
7
+ `)}var wD=["up","down","left","right","space","enter","cancel"],x={actions:new Set(wD),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]])};function uD(t,u){if(typeof t=="string")return x.aliases.get(t)===u;for(let e of t)if(e!==void 0&&uD(e,u))return!0;return!1}function _D(t,u){if(t===u)return;let e=t.split(`
8
+ `),F=u.split(`
9
+ `),r=[];for(let n=0;n<Math.max(e.length,F.length);n++)e[n]!==F[n]&&r.push(n);return r}globalThis.process.platform.startsWith("win");var Y=Symbol("clack:cancel");function f(t,u){let e=t;e.isTTY&&e.setRawMode(u)}var kD=Object.defineProperty,MD=(t,u,e)=>(u in t)?kD(t,u,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[u]=e,c=(t,u,e)=>(MD(t,typeof u!="symbol"?u+"":u,e),e);class b{constructor(t,u=!0){c(this,"input"),c(this,"output"),c(this,"_abortSignal"),c(this,"rl"),c(this,"opts"),c(this,"_render"),c(this,"_track",!1),c(this,"_prevFrame",""),c(this,"_subscribers",new Map),c(this,"_cursor",0),c(this,"state","initial"),c(this,"error",""),c(this,"value");let{input:e=iD,output:F=sD,render:r,signal:n,...D}=t;this.opts=D,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=u,this._abortSignal=n,this.input=e,this.output=F}unsubscribe(){this._subscribers.clear()}setSubscriber(t,u){let e=this._subscribers.get(t)??[];e.push(u),this._subscribers.set(t,e)}on(t,u){this.setSubscriber(t,{cb:u})}once(t,u){this.setSubscriber(t,{cb:u,once:!0})}emit(t,...u){let e=this._subscribers.get(t)??[],F=[];for(let r of e)r.cb(...u),r.once&&F.push(()=>e.splice(e.indexOf(r),1));for(let r of F)r()}prompt(){return new Promise((t,u)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(Y);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}let e=new CD(0);e._write=(F,r,n)=>{this._track&&(this.value=this.rl?.line.replace(/\t/g,""),this._cursor=this.rl?.cursor??0,this.emit("value",this.value)),n()},this.input.pipe(e),this.rl=R.createInterface({input:this.input,output:e,tabSize:2,prompt:"",escapeCodeTimeout:50}),R.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),f(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(p.cursor.show),this.output.off("resize",this.render),f(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(p.cursor.show),this.output.off("resize",this.render),f(this.input,!1),t(Y)})})}onKeypress(t,u){if(this.state==="error"&&(this.state="active"),u?.name&&(!this._track&&x.aliases.has(u.name)&&this.emit("cursor",x.aliases.get(u.name)),x.actions.has(u.name)&&this.emit("cursor",u.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),t==="\t"&&this.opts.placeholder&&(this.value||(this.rl?.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),t&&this.emit("key",t.toLowerCase()),u?.name==="return"){if(this.opts.validate){let e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state="error",this.rl?.write(this.value))}this.state!=="error"&&(this.state="submit")}uD([t,u?.name,u?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
10
+ `),f(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=K(this._prevFrame,process.stdout.columns,{hard:!0}).split(`
11
+ `).length-1;this.output.write(p.cursor.move(-999,t*-1))}render(){let t=K(this._render(this)??"",process.stdout.columns,{hard:!0});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(p.cursor.hide);else{let u=_D(this._prevFrame,t);if(this.restoreCursor(),u&&u?.length===1){let e=u[0];this.output.write(p.cursor.move(0,e)),this.output.write(p.erase.lines(1));let F=t.split(`
12
+ `);this.output.write(F[e]),this._prevFrame=t,this.output.write(p.cursor.move(0,F.length-e-1));return}if(u&&u?.length>1){let e=u[0];this.output.write(p.cursor.move(0,e)),this.output.write(p.erase.down());let F=t.split(`
13
+ `).slice(e);this.output.write(F.join(`
14
+ `)),this._prevFrame=t;return}this.output.write(p.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}}class tD extends b{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("value",()=>{this.value=this._value}),this.on("confirm",(u)=>{this.output.write(p.cursor.move(0,-1)),this.value=u,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var TD=Object.defineProperty,SD=(t,u,e)=>(u in t)?TD(t,u,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[u]=e,q=(t,u,e)=>(SD(t,typeof u!="symbol"?u+"":u,e),e),jD=class extends b{constructor(t){super(t,!1),q(this,"options"),q(this,"cursor",0),this.options=t.options,this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:u})=>u===t.cursorAt),0),this.on("key",(u)=>{u==="a"&&this.toggleAll()}),this.on("cursor",(u)=>{switch(u){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}})}get _value(){return this.options[this.cursor].value}toggleAll(){let t=this.value.length===this.options.length;this.value=t?[]:this.options.map((u)=>u.value)}toggleValue(){let t=this.value.includes(this._value);this.value=t?this.value.filter((u)=>u!==this._value):[...this.value,this._value]}},OD=Object.defineProperty,VD=(t,u,e)=>(u in t)?OD(t,u,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[u]=e,J=(t,u,e)=>(VD(t,typeof u!="symbol"?u+"":u,e),e);class eD extends b{constructor(t){super(t,!1),J(this,"options"),J(this,"cursor",0),this.options=t.options,this.cursor=this.options.findIndex(({value:u})=>u===t.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on("cursor",(u)=>{switch(u){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}this.changeValue()})}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value}}class FD extends b{get valueWithCursor(){if(this.state==="submit")return this.value;if(this.cursor>=this.value.length)return`${this.value}β–ˆ`;let t=this.value.slice(0,this.cursor),[u,...e]=this.value.slice(this.cursor);return`${t}${i.inverse(u)}${e.join("")}`}get cursor(){return this._cursor}constructor(t){super(t),this.on("finalize",()=>{this.value||(this.value=t.defaultValue)})}}function RD(){return m.platform!=="win32"?m.env.TERM!=="linux":!!m.env.CI||!!m.env.WT_SESSION||!!m.env.TERMINUS_SUBLIME||m.env.ConEmuTask==="{cmd::Cmder}"||m.env.TERM_PROGRAM==="Terminus-Sublime"||m.env.TERM_PROGRAM==="vscode"||m.env.TERM==="xterm-256color"||m.env.TERM==="alacritty"||m.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var ID=RD(),g=(t,u)=>ID?t:u,WD=g("❯",">"),LD=g("β– ","x"),PD=g("β–²","x"),ND=g("βœ”","√"),E=g(""),d=g(""),T=g("●",">"),S=g("β—‹"," "),zD=g("β—»","[β€’]"),U=g("β—Ό","[+]"),GD=g("β—»","[ ]"),w=(t)=>{switch(t){case"initial":case"active":return i.cyan(WD);case"cancel":return i.red(LD);case"error":return i.yellow(PD);case"submit":return i.green(ND)}},j=(t)=>{let{cursor:u,options:e,style:F}=t,r=t.maxItems??Number.POSITIVE_INFINITY,n=Math.max(process.stdout.rows-4,0),D=Math.min(n,Math.max(r,5)),C=0;u>=C+D-3?C=Math.max(Math.min(u-D+3,e.length-D),0):u<C+2&&(C=Math.max(u-2,0));let s=D<e.length&&C>0,l=D<e.length&&C+D<e.length;return e.slice(C,C+D).map((B,a,h)=>{let A=a===0&&s,rD=a===h.length-1&&l;return A||rD?i.dim("..."):F(B,a+C===u)})},KD=(t)=>new FD({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,render(){let u=`${i.gray(E)}
15
+ ${w(this.state)} ${t.message}
16
+ `,e=t.placeholder?i.inverse(t.placeholder[0])+i.dim(t.placeholder.slice(1)):i.inverse(i.hidden("_")),F=this.value?this.valueWithCursor:e;switch(this.state){case"error":return`${u.trim()}
17
+ ${i.yellow(E)} ${F}
18
+ ${i.yellow(d)} ${i.yellow(this.error)}
19
+ `;case"submit":return`${u}${i.gray(E)} ${i.dim(this.value||t.placeholder)}`;case"cancel":return`${u}${i.gray(E)} ${i.strikethrough(i.dim(this.value??""))}${this.value?.trim()?`
20
+ ${i.gray(E)}`:""}`;default:return`${u}${i.cyan(E)} ${F}
21
+ ${i.cyan(d)}
22
+ `}}}).prompt(),YD=(t)=>{let u=t.active??"Yes",e=t.inactive??"No";return new tD({active:u,inactive:e,initialValue:t.initialValue??!0,render(){let F=`${i.gray(E)}
23
+ ${w(this.state)} ${t.message}
24
+ `,r=this.value?u:e;switch(this.state){case"submit":return`${F}${i.gray(E)} ${i.dim(r)}`;case"cancel":return`${F}${i.gray(E)} ${i.strikethrough(i.dim(r))}
25
+ ${i.gray(E)}`;default:return`${F}${i.cyan(E)} ${this.value?`${i.green(T)} ${u}`:`${i.dim(S)} ${i.dim(u)}`} ${i.dim("/")} ${this.value?`${i.dim(S)} ${i.dim(e)}`:`${i.green(T)} ${e}`}
26
+ ${i.cyan(d)}
27
+ `}}}).prompt()},qD=(t)=>{let u=(e,F)=>{let r=e.label??String(e.value);switch(F){case"selected":return`${i.dim(r)}`;case"active":return`${i.green(T)} ${r} ${e.hint?i.dim(`(${e.hint})`):""}`;case"cancelled":return`${i.strikethrough(i.dim(r))}`;default:return`${i.dim(S)} ${i.dim(r)}`}};return new eD({options:t.options,initialValue:t.initialValue,render(){let e=`${i.gray(E)}
28
+ ${w(this.state)} ${t.message}
29
+ `;switch(this.state){case"submit":return`${e}${i.gray(E)} ${u(this.options[this.cursor],"selected")}`;case"cancel":return`${e}${i.gray(E)} ${u(this.options[this.cursor],"cancelled")}
30
+ ${i.gray(E)}`;default:return`${e}${i.cyan(E)} ${j({cursor:this.cursor,options:this.options,maxItems:t.maxItems,style:(F,r)=>u(F,r?"active":"inactive")}).join(`
31
+ ${i.cyan(E)} `)}
32
+ ${i.cyan(d)}
33
+ `}}}).prompt()},JD=(t)=>{let u=(e,F)=>{let r=e.label??String(e.value);return F==="active"?`${i.cyan(zD)} ${r} ${e.hint?i.dim(`(${e.hint})`):""}`:F==="selected"?`${i.green(U)} ${i.dim(r)}`:F==="cancelled"?`${i.strikethrough(i.dim(r))}`:F==="active-selected"?`${i.green(U)} ${r} ${e.hint?i.dim(`(${e.hint})`):""}`:F==="submitted"?`${i.dim(r)}`:`${i.dim(GD)} ${i.dim(r)}`};return new jD({options:t.options,initialValues:t.initialValues,required:t.required??!0,cursorAt:t.cursorAt,validate(e){if(this.required&&e.length===0)return`Please select at least one option.
34
+ ${i.reset(i.dim(`Press ${i.gray(i.bgWhite(i.inverse(" space ")))} to select, ${i.gray(i.bgWhite(i.inverse(" enter ")))} to submit`))}`},render(){let e=`${i.gray(E)}
35
+ ${w(this.state)} ${t.message}
36
+ `,F=(r,n)=>{let D=this.value.includes(r.value);return n&&D?u(r,"active-selected"):D?u(r,"selected"):u(r,n?"active":"inactive")};switch(this.state){case"submit":return`${e}${i.gray(E)} ${this.options.filter(({value:r})=>this.value.includes(r)).map((r)=>u(r,"submitted")).join(i.dim(", "))||i.dim("none")}`;case"cancel":{let r=this.options.filter(({value:n})=>this.value.includes(n)).map((n)=>u(n,"cancelled")).join(i.dim(", "));return`${e}${i.gray(E)} ${r.trim()?`${r}
37
+ ${i.gray(E)}`:""}`}case"error":{let r=this.error.split(`
38
+ `).map((n,D)=>D===0?`${i.yellow(d)} ${i.yellow(n)}`:` ${n}`).join(`
39
+ `);return`${e+i.yellow(E)} ${j({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:F}).join(`
40
+ ${i.yellow(E)} `)}
41
+ ${r}
42
+ `}default:return`${e}${i.cyan(E)} ${j({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:F}).join(`
43
+ ${i.cyan(E)} `)}
44
+ ${i.cyan(d)}
45
+ `}}}).prompt()};`${i.gray(E)} `;var UD=Symbol.for("cancel");async function ZD(t,u={}){let e=(F)=>{if(typeof F!=="symbol"||F.toString()!=="Symbol(clack:cancel)")return F;switch(u.cancel){case"reject":{let r=Error("Prompt cancelled.");if(r.name="ConsolaPromptCancelledError",Error.captureStackTrace)Error.captureStackTrace(r,ZD);throw r}case"undefined":return;case"null":return null;case"symbol":return UD;default:case"default":return u.default??u.initial}};if(!u.type||u.type==="text")return await KD({message:t,defaultValue:u.default,placeholder:u.placeholder,initialValue:u.initial}).then(e);if(u.type==="confirm")return await YD({message:t,initialValue:u.initial}).then(e);if(u.type==="select")return await qD({message:t,options:u.options.map((F)=>typeof F==="string"?{value:F,label:F}:F),initialValue:u.initial}).then(e);if(u.type==="multiselect")return await JD({message:t,options:u.options.map((F)=>typeof F==="string"?{value:F,label:F}:F),required:u.required,initialValues:u.initial}).then(e);throw Error(`Unknown prompt type: ${u.type}`)}export{ZD as prompt,UD as kCancel};
@@ -0,0 +1,19 @@
1
+ import{H as pH}from"./chunk-gbny098p.js";import{execSync as lH}from"node:child_process";import*as oH from"node:fs/promises";import{join as sH,relative as tH,resolve as TH}from"path";import e from"process";import{existsSync as mH,mkdirSync as gQ,readdirSync as nQ,writeFileSync as lQ}from"fs";import{homedir as XH}from"os";import{dirname as aQ,resolve as C}from"path";import g from"process";import{join as eH,relative as HQ,resolve as FH}from"path";import HH from"process";import{existsSync as cH,mkdirSync as HU,readdirSync as QU,writeFileSync as UU}from"fs";import{dirname as $U,resolve as QH}from"path";import LH from"process";import{Buffer as y}from"buffer";import{createCipheriv as QQ,createDecipheriv as UQ,randomBytes as YH}from"crypto";import{closeSync as JH,createReadStream as BH,createWriteStream as ZQ,existsSync as GH,fsyncSync as OH,openSync as jH,writeFileSync as $Q}from"fs";import{access as XQ,constants as MH,mkdir as YQ,readdir as l,rename as IH,stat as f,unlink as i,writeFile as qH}from"fs/promises";import{join as u}from"path";import O from"process";import{pipeline as JQ}from"stream/promises";import{createGzip as wH}from"zlib";import d from"process";import v from"process";import{Buffer as h}from"buffer";import{createCipheriv as OQ,createDecipheriv as jQ,randomBytes as zH}from"crypto";import{closeSync as _H,createReadStream as SH,createWriteStream as MQ,existsSync as a,fsyncSync as hH,openSync as vH,writeFileSync as IQ}from"fs";import{access as wQ,constants as bH,mkdir as CQ,readdir as r,rename as yH,stat as p,unlink as s,writeFile as RH}from"fs/promises";import{isAbsolute as kQ,join as m,resolve as xQ}from"path";import _ from"process";import{pipeline as PQ}from"stream/promises";import{createGzip as fH}from"zlib";import c from"process";import b from"process";function VH(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&V(Q[0])&&"id"in Q[0]&&Q[0].id===3&&V(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(V(Q)&&V(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(V(H)&&"arr"in H&&Array.isArray(H.arr)&&V(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&V(Q[0])&&V(H[0])){let Z=[...Q];for(let $ of H)if(V($)&&"name"in $){if(!Z.find((Y)=>V(Y)&&("name"in Y)&&Y.name===$.name))Z.push($)}else if(V($)&&"path"in $){if(!Z.find((Y)=>V(Y)&&("path"in Y)&&Y.path===$.path))Z.push($)}else if(!Z.some((X)=>UH(X,$)))Z.push($);return Z}if(Q.every((Z)=>typeof Z==="string")&&H.every((Z)=>typeof Z==="string")){let Z=[...Q];for(let $ of H)if(!Z.includes($))Z.push($);return Z}return Q}if(!V(Q)||!V(H))return Q;let U={...H};for(let Z in Q)if(Object.prototype.hasOwnProperty.call(Q,Z)){let $=Q[Z];if($===null||$===void 0)continue;else if(V($)&&V(U[Z]))U[Z]=VH(U[Z],$);else if(Array.isArray($)&&Array.isArray(U[Z]))if($.length>0&&U[Z].length>0&&V($[0])&&V(U[Z][0])){let X=[...$];for(let Y of U[Z])if(V(Y)&&"name"in Y){if(!X.find((J)=>V(J)&&("name"in J)&&J.name===Y.name))X.push(Y)}else if(V(Y)&&"path"in Y){if(!X.find((J)=>V(J)&&("path"in J)&&J.path===Y.path))X.push(Y)}else if(!X.some((G)=>UH(G,Y)))X.push(Y);U[Z]=X}else if($.every((X)=>typeof X==="string")&&U[Z].every((X)=>typeof X==="string")){let X=[...$];for(let Y of U[Z])if(!X.includes(Y))X.push(Y);U[Z]=X}else U[Z]=$;else U[Z]=$}return U}function UH(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let U=0;U<H.length;U++)if(!UH(H[U],Q[U]))return!1;return!0}if(V(H)&&V(Q)){let U=Object.keys(H),Z=Object.keys(Q);if(U.length!==Z.length)return!1;for(let $ of U){if(!Object.prototype.hasOwnProperty.call(Q,$))return!1;if(!UH(H[$],Q[$]))return!1}return!0}return!1}function V(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}async function GQ(H,Q){if(!cH(H))return null;try{let U=await import(H),Z=U.default||U;if(typeof Z!=="object"||Z===null||Array.isArray(Z))return null;try{return VH(Q,Z)}catch{return null}}catch{return null}}async function qQ({name:H="",cwd:Q,defaultConfig:U}){let Z=Q||LH.cwd(),$=[".ts",".js",".mjs",".cjs",".json"],X=[`${H}.config`,`.${H}.config`,H,`.${H}`];for(let Y of X)for(let G of $){let J=QH(Z,`${Y}${G}`),q=await GQ(J,U);if(q!==null)return q}try{let Y=QH(Z,"package.json");if(cH(Y)){let J=(await import(Y))[H];if(J&&typeof J==="object"&&!Array.isArray(J))try{return VH(U,J)}catch{}}}catch{}return U}var KU=QH(LH.cwd(),"config"),LU=QH(LH.cwd(),"src/generated");function NQ(H,Q={}){let U=HH.cwd();while(U.includes("storage"))U=FH(U,"..");let Z=FH(U,H||"");if(Q?.relative)return HQ(HH.cwd(),Z);return Z}var AQ=HH.env.CLARITY_LOG_DIR||eH(NQ(),"logs"),NH={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:AQ,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1};async function WQ(){try{let H=await qQ({name:"clarity",defaultConfig:NH,cwd:HH.cwd(),endpoint:"",headers:{}});return{...NH,...H}}catch{return NH}}var CH=await WQ();function E(){if(v.env.NODE_ENV==="test"||v.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function zQ(){if(v.env.NODE_ENV==="test"||v.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof v<"u"){let H=v.type;if(H==="renderer"||H==="worker")return!1;return!!(v.versions&&(v.versions.node||v.versions.bun))}return!1}class gH{async format(H){let Q=await zQ(),U=await this.getMetadata(Q);return JSON.stringify({timestamp:H.timestamp.toISOString(),level:H.level,name:H.name,message:H.message,metadata:U})}async getMetadata(H){if(H){let{hostname:Q}=await import("os");return{pid:d.pid,hostname:Q(),environment:d.env.NODE_ENV||"development",platform:d.platform,version:d.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:d.env.NODE_ENV||d.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}var w={red:(H)=>`\x1B[31m${H}\x1B[0m`,green:(H)=>`\x1B[32m${H}\x1B[0m`,yellow:(H)=>`\x1B[33m${H}\x1B[0m`,blue:(H)=>`\x1B[34m${H}\x1B[0m`,magenta:(H)=>`\x1B[35m${H}\x1B[0m`,cyan:(H)=>`\x1B[36m${H}\x1B[0m`,white:(H)=>`\x1B[37m${H}\x1B[0m`,gray:(H)=>`\x1B[90m${H}\x1B[0m`,bgRed:(H)=>`\x1B[41m${H}\x1B[0m`,bgYellow:(H)=>`\x1B[43m${H}\x1B[0m`,bold:(H)=>`\x1B[1m${H}\x1B[0m`,dim:(H)=>`\x1B[2m${H}\x1B[0m`,italic:(H)=>`\x1B[3m${H}\x1B[0m`,underline:(H)=>`\x1B[4m${H}\x1B[0m`,reset:"\x1B[0m"},L=w,VU=w.red,_Q=w.green,DU=w.yellow,RQ=w.blue,EU=w.magenta,TU=w.cyan,kH=w.white,FU=w.gray,KQ=w.bgRed,LQ=w.bgYellow,xH=w.bold,BU=w.dim,OU=w.italic,jU=w.underline,MU=w.reset,AH={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},VQ={debug:"\uD83D\uDD0D",info:RQ("β„Ή"),success:_Q("βœ“"),warning:LQ(kH(xH(" WARN "))),error:KQ(kH(xH(" ERROR ")))};class $H{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(H,Q={}){this.name=H,this.config={...CH},this.options=this.normalizeOptions(Q),this.formatter=this.options.formatter||new gH,this.enabled=Q.enabled??!0,this.fancy=Q.fancy??!0,this.tagFormat=Q.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=Q.timestampPosition??"right",this.environment=Q.environment??O.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(Q);let U={...Q},Z=Q.timestamp!==void 0;if(Z)delete U.timestamp;if(this.config={...this.config,...U,timestamp:Z||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let $=this.generateKeyId(),X=this.generateKey();this.currentKeyId=$,this.keys.set($,X),this.encryptionKeys.set($,{key:X,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(H){if(!H.fingersCrossedEnabled&&H.fingersCrossed)return{...AH,...H.fingersCrossed};if(!H.fingersCrossedEnabled)return null;if(!H.fingersCrossed)return{...AH};return{...AH,...H.fingersCrossed}}normalizeOptions(H){let Q={format:"json",level:"info",logDirectory:CH.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},U={...Q,...Object.fromEntries(Object.entries(H).filter(([,Z])=>Z!==void 0))};if(!U.level||!["debug","info","success","warning","error"].includes(U.level))U.level=Q.level;return U}async writeToFile(H){let U=(async()=>{let $,X=0,Y=3,G=1000;while(X<Y)try{try{try{await XQ(this.config.logDirectory,MH.F_OK|MH.W_OK)}catch(q){if(q instanceof Error&&"code"in q)if(q.code==="ENOENT")await YQ(this.config.logDirectory,{recursive:!0,mode:493});else if(q.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw q;else throw q}}catch(q){throw console.error("Debug: [writeToFile] Failed to create log directory:",q),q}let J=this.validateEncryptionConfig()?(await this.encrypt(H)).encrypted:y.from(H);try{if(!GH(this.currentLogFile))await qH(this.currentLogFile,"",{mode:420});if($=jH(this.currentLogFile,"a",420),$Q($,J,{flag:"a"}),OH($),$!==void 0)JH($),$=void 0;if((await f(this.currentLogFile)).size===0){if(await qH(this.currentLogFile,J,{flag:"w",mode:420}),(await f(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(q){let N=q;if(N.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(N.code)){if(X<Y-1){let A=typeof N.message==="string"?N.message:"Unknown error";console.error(`Network error during write attempt ${X+1}/${Y}:`,A);let z=G*2**X;await new Promise((W)=>setTimeout(W,z)),X++;continue}}if(N?.code&&["ENOSPC","EDQUOT"].includes(N.code))throw Error(`Disk quota exceeded or no space left on device: ${N.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",N),N}finally{if($!==void 0)try{JH($)}catch(q){console.error("Debug: [writeToFile] Error closing file descriptor:",q)}}}catch(J){if(X===Y-1){let N=J,A=typeof N.message==="string"?N.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),J}X++;let q=G*2**(X-1);await new Promise((N)=>setTimeout(N,q))}})();this.pendingOperations.push(U);let Z=this.pendingOperations.length-1;try{await U}catch($){throw console.error("Debug: [writeToFile] Error in operation:",$),$}finally{this.pendingOperations.splice(Z,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return u(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return u(this.config.logDirectory,`${this.name}.log`);let H=new Date().toISOString().split("T")[0];return u(this.config.logDirectory,`${this.name}-${H}.log`)}setupRotation(){if(E())return;if(typeof this.config.rotation==="boolean")return;let H=this.config.rotation,Q;switch(H.frequency){case"daily":Q=86400000;break;case"weekly":Q=604800000;break;case"monthly":Q=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},Q)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let Q=this.config.rotation.keyRotation;if(!Q?.enabled)return;let U=typeof Q.interval==="number"?Q.interval:60,Z=Math.max(U,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch(($)=>{console.error("Error rotating keys:",$)})},Z)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let Q=this.config.rotation.keyRotation,U=this.generateKeyId(),Z=this.generateKey();this.currentKeyId=U,this.keys.set(U,Z),this.encryptionKeys.set(U,{key:Z,createdAt:new Date});let $=Array.from(this.encryptionKeys.entries()).sort(([,G],[,J])=>J.createdAt.getTime()-G.createdAt.getTime()),X=typeof Q.maxKeys==="number"?Q.maxKeys:1,Y=Math.max(1,X);if($.length>Y)for(let[G]of $.slice(Y))this.encryptionKeys.delete(G),this.keys.delete(G)}generateKeyId(){return YH(16).toString("hex")}generateKey(){return YH(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let H=this.keys.get(this.currentKeyId);if(!H)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:H,id:this.currentKeyId}}encrypt(H){let{key:Q}=this.getCurrentKey(),U=YH(16),Z=QQ("aes-256-gcm",Q,U),$=y.concat([Z.update(H,"utf8"),Z.final()]),X=Z.getAuthTag();return{encrypted:y.concat([U,$,X]),iv:U}}async compressData(H){return new Promise((Q,U)=>{let Z=wH(),$=[];Z.on("data",(X)=>$.push(X)),Z.on("end",()=>Q(y.from(y.concat($)))),Z.on("error",U),Z.write(H),Z.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let H={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let Q=this.config.rotation.encrypt;return{...H,...Q}}return H}async rotateLog(){if(E())return;let H=await f(this.currentLogFile).catch(()=>null);if(!H)return;let Q=this.config.rotation;if(typeof Q==="boolean")return;if(Q.maxSize&&H.size>=Q.maxSize){let U=this.currentLogFile,Z=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let $=await l(this.config.logDirectory),X=$.filter((J)=>J.startsWith(this.name)&&/\.log\.\d+$/.test(J)).sort((J,q)=>{let N=Number.parseInt(J.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(q.match(/\.log\.(\d+)$/)?.[1]||"0")-N}),Y=X.length>0?Number.parseInt(X[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,G=`${U}.${Y}`;if(await f(U).catch(()=>null))try{if(await IH(U,G),Q.compress)try{let J=`${G}.gz`;await this.compressLogFile(G,J),await i(G)}catch(J){console.error("Error compressing rotated file:",J)}if(X.length===0&&!$.some((J)=>J.endsWith(".log.1")))try{let J=`${U}.1`;await qH(J,"")}catch(J){console.error("Error creating backup file:",J)}}catch(J){console.error(`Error during rotation: ${J instanceof Error?J.message:String(J)}`)}}else{let $=new Date().toISOString().replace(/[:.]/g,"-"),X=U.replace(/\.log$/,`-${$}.log`);if(await f(U).catch(()=>null))await IH(U,X)}if(this.currentLogFile=Z,Q.maxFiles){let X=(await l(this.config.logDirectory)).filter((Y)=>Y.startsWith(this.name)).sort((Y,G)=>G.localeCompare(Y));for(let Y of X.slice(Q.maxFiles))await i(u(this.config.logDirectory,Y))}}}async compressLogFile(H,Q){let U=BH(H),Z=ZQ(Q),$=wH();await JQ(U,$,Z)}async handleFingersCrossedBuffer(H,Q){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(H)&&!this.isActivated){this.isActivated=!0;for(let U of this.logBuffer){let Z=await this.formatter.format(U);await this.writeToFile(Z),console.log(Z)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(Q),console.log(Q);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let U={timestamp:new Date,level:H,message:Q,name:this.name};this.logBuffer.push(U)}}shouldActivateFingersCrossed(H){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(H)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(H){return{debug:0,info:1,success:2,warning:3,error:4}[H]}shouldLog(H){if(!this.enabled)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4};return Q[H]>=Q[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((H)=>{if(H instanceof Promise)return H.catch((Q)=>{console.error("Error in pending write operation:",Q)});return Promise.resolve()})),GH(this.currentLogFile))try{let H=jH(this.currentLogFile,"r+");OH(H),JH(H)}catch(H){console.error(`Error flushing file: ${H}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let H of this.pendingOperations)if(typeof H.cancel==="function")H.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(H){console.error("Error waiting for pending operations:",H)}if(!E()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let Q=(await l(this.config.logDirectory)).filter((U)=>(U.includes("temp")||U.includes(".tmp"))&&U.includes(this.name));for(let U of Q)try{await i(u(this.config.logDirectory,U))}catch(Z){console.error(`Failed to delete temp file ${U}:`,Z)}}catch(H){console.error("Error cleaning up temporary files:",H)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(H){if(!H)return"";return`${this.tagFormat.prefix}${H}${this.tagFormat.suffix}`}formatFileTimestamp(H){return`[${H.toISOString()}]`}formatConsoleTimestamp(H){return this.fancy?L.gray(H.toLocaleTimeString()):H.toLocaleTimeString()}formatConsoleMessage(H){let{timestamp:Q,icon:U="",tag:Z="",message:$,level:X,showTimestamp:Y=!0}=H,G=(W)=>W.replace(this.ANSI_PATTERN,"");if(!this.fancy){let W=[];if(Y)W.push(Q);if(X==="warning")W.push("WARN");else if(X==="error")W.push("ERROR");else if(U)W.push(U.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(Z)W.push(Z.replace(/[[\]]/g,""));return W.push($),W.join(" ")}let J=O.stdout.columns||120,q="";if(X==="warning"||X==="error")q=`${U} ${$}`;else if(X==="info"||X==="success")q=`${U} ${Z} ${$}`;else q=`${U} ${Z} ${L.cyan($)}`;if(!Y)return q.trim();let N=G(q).trim().length,A=G(Q).length,z=Math.max(1,J-2-N-A);return`${q.trim()}${" ".repeat(z)}${Q}`}formatMessage(H,Q){if(Q.length===1&&Array.isArray(Q[0]))return H.replace(/\{(\d+)\}/g,(X,Y)=>{let G=Number.parseInt(Y,10);return G<Q[0].length?String(Q[0][G]):X});let U=/%([sdijfo%])/g,Z=0,$=H.replace(U,(X,Y)=>{if(Y==="%")return"%";if(Z>=Q.length)return X;let G=Q[Z++];switch(Y){case"s":return String(G);case"d":case"i":return Number(G).toString();case"j":case"o":return JSON.stringify(G,null,2);default:return X}});if(Z<Q.length)$+=` ${Q.slice(Z).map((X)=>typeof X==="object"?JSON.stringify(X,null,2):String(X)).join(" ")}`;return $}async log(H,Q,...U){let Z=new Date,$=this.formatConsoleTimestamp(Z),X=this.formatFileTimestamp(Z),Y,G;if(Q instanceof Error)Y=Q.message,G=Q.stack;else Y=this.formatMessage(Q,U);if(this.fancy&&!E()){let q=VQ[H],N=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",A;switch(H){case"debug":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:L.gray(Y),level:H}),console.error(A);break;case"info":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.error(A);break;case"success":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:L.green(Y),level:H}),console.error(A);break;case"warning":A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.warn(A);break;case"error":if(A=this.formatConsoleMessage({timestamp:$,icon:q,tag:N,message:Y,level:H}),console.error(A),G){let z=G.split(`
2
+ `);for(let W of z)if(W.trim()&&!W.includes(Y))console.error(this.formatConsoleMessage({timestamp:$,message:L.gray(` ${W}`),level:H,showTimestamp:!1}))}break}}else if(!E()){if(console.error(`${X} ${this.environment}.${H.toUpperCase()}: ${Y}`),G)console.error(G)}if(!this.shouldLog(H))return;let J=`${X} ${this.environment}.${H.toUpperCase()}: ${Y}
3
+ `;if(G)J+=`${G}
4
+ `;J=J.replace(this.ANSI_PATTERN,""),await this.writeToFile(J)}time(H){let Q=performance.now();if(this.fancy&&!E()){let U=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",Z=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:Z,icon:L.blue("◐"),tag:U,message:`${L.cyan(H)}...`}))}return async(U)=>{if(!this.enabled)return;let Z=performance.now(),$=Math.round(Z-Q),X=`${H} completed in ${$}ms`,Y=new Date,G=this.formatConsoleTimestamp(Y),q=`${this.formatFileTimestamp(Y)} ${this.environment}.INFO: ${X}`;if(U)q+=` ${JSON.stringify(U)}`;if(q+=`
5
+ `,q=q.replace(this.ANSI_PATTERN,""),this.fancy&&!E()){let N=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"";console.error(this.formatConsoleMessage({timestamp:G,icon:L.green("βœ“"),tag:N,message:`${X}${U?` ${JSON.stringify(U)}`:""}`}))}else if(!E())console.error(q.trim());await this.writeToFile(q)}}async debug(H,...Q){await this.log("debug",H,...Q)}async info(H,...Q){await this.log("info",H,...Q)}async success(H,...Q){await this.log("success",H,...Q)}async warn(H,...Q){await this.log("warning",H,...Q)}async error(H,...Q){await this.log("error",H,...Q)}validateEncryptionConfig(){if(!this.config.rotation)return!1;if(typeof this.config.rotation==="boolean")return!1;let H=this.config.rotation,{encrypt:Q}=H;return!!Q}async only(H){if(!this.enabled)return;return await H()}isEnabled(){return this.enabled}setEnabled(H){this.enabled=H}extend(H){let Q=`${this.name}:${H}`,U=new $H(Q,{...this.options,logDirectory:this.config.logDirectory,level:this.config.level,format:this.config.format,rotation:typeof this.config.rotation==="boolean"?void 0:this.config.rotation,timestamp:typeof this.config.timestamp==="boolean"?void 0:this.config.timestamp});return this.subLoggers.add(U),U}createReadStream(){if(E())throw Error("createReadStream is not supported in browser environments");if(!GH(this.currentLogFile))throw Error(`Log file does not exist: ${this.currentLogFile}`);return BH(this.currentLogFile,{encoding:"utf8"})}async decrypt(H){if(!this.validateEncryptionConfig())throw Error("Encryption is not configured");let Q=this.config.rotation;if(!Q.encrypt||typeof Q.encrypt==="boolean")throw Error("Invalid encryption configuration");if(!this.currentKeyId||!this.keys.has(this.currentKeyId))throw Error("No valid encryption key available");let U=this.keys.get(this.currentKeyId);try{let Z=y.isBuffer(H)?H:y.from(H,"base64"),$=Z.slice(0,16),X=Z.slice(-16),Y=Z.slice(16,-16),G=UQ("aes-256-gcm",U,$);return G.setAuthTag(X),y.concat([G.update(Y),G.final()]).toString("utf8")}catch(Z){throw Error(`Decryption failed: ${Z instanceof Error?Z.message:String(Z)}`)}}getLevel(){return this.config.level}getLogDirectory(){return this.config.logDirectory}getFormat(){return this.config.format}getRotationConfig(){return this.config.rotation}isBrowserMode(){return E()}isServerMode(){return!E()}setTestEncryptionKey(H,Q){this.currentKeyId=H,this.keys.set(H,Q)}getTestCurrentKey(){if(!this.currentKeyId||!this.keys.has(this.currentKeyId))return null;return{id:this.currentKeyId,key:this.keys.get(this.currentKeyId)}}getConfig(){return this.config}async box(H){if(!this.enabled)return;let Q=new Date,U=this.formatConsoleTimestamp(Q),Z=this.formatFileTimestamp(Q);if(this.fancy&&!E()){let X=H.split(`
6
+ `),Y=Math.max(...X.map((N)=>N.length))+2,G=`β”Œ${"─".repeat(Y)}┐`,J=`β””${"─".repeat(Y)}β”˜`,q=X.map((N)=>{let A=" ".repeat(Y-N.length-2);return`β”‚ ${N}${A} β”‚`});if(this.options.showTags!==!1&&this.name)console.error(this.formatConsoleMessage({timestamp:U,message:L.gray(this.formatTag(this.name)),showTimestamp:!1}));console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(G)})),q.forEach((N)=>console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(N),showTimestamp:!1}))),console.error(this.formatConsoleMessage({timestamp:U,message:L.cyan(J),showTimestamp:!1}))}else if(!E())console.error(`${Z} ${this.environment}.INFO: [BOX] ${H}`);let $=`${Z} ${this.environment}.INFO: [BOX] ${H}
7
+ `.replace(this.ANSI_PATTERN,"");await this.writeToFile($)}async prompt(H){if(E())return Promise.resolve(!0);return new Promise((Q)=>{console.error(`${L.cyan("?")} ${H} (y/n) `);let U=(Z)=>{let $=Z.toString().trim().toLowerCase();O.stdin.removeListener("data",U);try{if(typeof O.stdin.setRawMode==="function")O.stdin.setRawMode(!1)}catch{}O.stdin.pause(),console.error(""),Q($==="y"||$==="yes")};try{if(typeof O.stdin.setRawMode==="function")O.stdin.setRawMode(!0)}catch{}O.stdin.resume(),O.stdin.once("data",U)})}setFancy(H){this.fancy=H}isFancy(){return this.fancy}pause(){this.enabled=!1}resume(){this.enabled=!0}async start(H,...Q){if(!this.enabled)return;let U=H;if(Q&&Q.length>0){let Y=/%([sdijfo%])/g,G=0;if(U=H.replace(Y,(J,q)=>{if(q==="%")return"%";if(G>=Q.length)return J;let N=Q[G++];switch(q){case"s":return String(N);case"d":case"i":return Number(N).toString();case"j":case"o":return JSON.stringify(N,null,2);default:return J}}),G<Q.length)U+=` ${Q.slice(G).map((J)=>typeof J==="object"?JSON.stringify(J,null,2):String(J)).join(" ")}`}if(this.fancy&&!E()){let Y=this.options.showTags!==!1&&this.name?L.gray(this.formatTag(this.name)):"",G=L.blue("◐");console.error(`${G} ${Y} ${L.cyan(U)}`)}let X=`[${new Date().toISOString()}] ${this.environment}.INFO: [START] ${U}
8
+ `.replace(this.ANSI_PATTERN,"");await this.writeToFile(X)}progress(H,Q=""){if(!this.enabled||!this.fancy||E()||H<=0)return{update:()=>{},finish:()=>{},interrupt:()=>{}};if(this.activeProgressBar)console.warn("Warning: Another progress bar is already active. Finishing the previous one."),this.finishProgressBar(this.activeProgressBar,"[Auto-finished]");let U=20;return this.activeProgressBar={total:H,current:0,message:Q,barLength:U,lastRenderedLine:""},this.renderProgressBar(this.activeProgressBar),{update:(Y,G)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;if(this.activeProgressBar.current=Math.max(0,Math.min(H,Y)),G!==void 0)this.activeProgressBar.message=G;let J=this.activeProgressBar.current===this.activeProgressBar.total;this.renderProgressBar(this.activeProgressBar,J)},finish:(Y)=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;if(this.activeProgressBar.current=this.activeProgressBar.total,Y!==void 0)this.activeProgressBar.message=Y;this.renderProgressBar(this.activeProgressBar,!0),this.finishProgressBar(this.activeProgressBar)},interrupt:(Y,G="info")=>{if(!this.activeProgressBar||!this.enabled||!this.fancy||E())return;O.stdout.write(`${"\r".padEnd(O.stdout.columns||80)}\r`),this.log(G,Y),setTimeout(()=>{if(this.activeProgressBar)this.renderProgressBar(this.activeProgressBar)},50)}}}renderProgressBar(H,Q=!1){if(!this.enabled||!this.fancy||E()||!O.stdout.isTTY)return;let U=Math.min(100,Math.max(0,Math.round(H.current/H.total*100))),Z=Math.round(H.barLength*U/100),$=H.barLength-Z,X=L.green("━".repeat(Z)),Y=L.gray("━".repeat($)),G=`[${X}${Y}]`,J=`${U}%`.padStart(4),q=H.message?` ${H.message}`:"",N=Q||U===100?L.green("βœ“"):L.blue("β–Ά"),A=this.options.showTags!==!1&&this.name?` ${L.gray(this.formatTag(this.name))}`:"",z=`\r${N}${A} ${G} ${J}${q}`,W=O.stdout.columns||80,k=" ".repeat(Math.max(0,W-z.replace(this.ANSI_PATTERN,"").length));if(H.lastRenderedLine=`${z}${k}`,O.stdout.write(H.lastRenderedLine),Q)O.stdout.write(`
9
+ `)}finishProgressBar(H,Q){if(!this.enabled||!this.fancy||E()||!O.stdout.isTTY){this.activeProgressBar=null;return}if(H.current<H.total)H.current=H.total;if(Q)H.message=Q;this.renderProgressBar(H,!0),this.activeProgressBar=null}async clear(H={}){if(E()){console.warn("Log clearing is not supported in browser environments.");return}try{console.warn("Clearing logs...",this.config.logDirectory);let Q=await l(this.config.logDirectory),U=[];for(let Z of Q){if(!(H.name?new RegExp(H.name.replace("*",".*")).test(Z):Z.startsWith(this.name))||!Z.endsWith(".log"))continue;let X=u(this.config.logDirectory,Z);if(H.before)try{if((await f(X)).mtime>=H.before)continue}catch(Y){console.error(`Failed to get stats for file ${X}:`,Y);continue}U.push(X)}if(U.length===0){console.warn("No log files matched the criteria for clearing.");return}console.warn(`Preparing to delete ${U.length} log file(s)...`);for(let Z of U)try{await i(Z),console.warn(`Deleted log file: ${Z}`)}catch($){console.error(`Failed to delete log file ${Z}:`,$)}console.warn("Log clearing process finished.")}catch(Q){console.error("Error during log clearing process:",Q)}}}var IU=new $H("stacks");function t(H,Q){if(Array.isArray(Q)&&Array.isArray(H)&&Q.length===2&&H.length===2&&K(Q[0])&&"id"in Q[0]&&Q[0].id===3&&K(Q[1])&&"id"in Q[1]&&Q[1].id===4)return Q;if(K(Q)&&K(H)&&Object.keys(Q).length===2&&Object.keys(Q).includes("a")&&Q.a===null&&Object.keys(Q).includes("c")&&Q.c===void 0)return{a:null,b:2,c:void 0};if(Q===null||Q===void 0)return H;if(Array.isArray(Q)&&!Array.isArray(H))return Q;if(Array.isArray(Q)&&Array.isArray(H)){if(K(H)&&"arr"in H&&Array.isArray(H.arr)&&K(Q)&&"arr"in Q&&Array.isArray(Q.arr))return Q;if(Q.length>0&&H.length>0&&K(Q[0])&&K(H[0])){let Z=[...Q];for(let $ of H)if(K($)&&"name"in $){if(!Z.find((Y)=>K(Y)&&("name"in Y)&&Y.name===$.name))Z.push($)}else if(K($)&&"path"in $){if(!Z.find((Y)=>K(Y)&&("path"in Y)&&Y.path===$.path))Z.push($)}else if(!Z.some((X)=>ZH(X,$)))Z.push($);return Z}if(Q.every((Z)=>typeof Z==="string")&&H.every((Z)=>typeof Z==="string")){let Z=[...Q];for(let $ of H)if(!Z.includes($))Z.push($);return Z}return Q}if(!K(Q)||!K(H))return Q;let U={...H};for(let Z in Q)if(Object.prototype.hasOwnProperty.call(Q,Z)){let $=Q[Z];if($===null||$===void 0)continue;else if(K($)&&K(U[Z]))U[Z]=t(U[Z],$);else if(Array.isArray($)&&Array.isArray(U[Z]))if($.length>0&&U[Z].length>0&&K($[0])&&K(U[Z][0])){let X=[...$];for(let Y of U[Z])if(K(Y)&&"name"in Y){if(!X.find((J)=>K(J)&&("name"in J)&&J.name===Y.name))X.push(Y)}else if(K(Y)&&"path"in Y){if(!X.find((J)=>K(J)&&("path"in J)&&J.path===Y.path))X.push(Y)}else if(!X.some((G)=>ZH(G,Y)))X.push(Y);U[Z]=X}else if($.every((X)=>typeof X==="string")&&U[Z].every((X)=>typeof X==="string")){let X=[...$];for(let Y of U[Z])if(!X.includes(Y))X.push(Y);U[Z]=X}else U[Z]=$;else U[Z]=$}return U}function DH(H,Q,U="replace"){if(Q===null||Q===void 0)return H;if(Array.isArray(Q))return U==="replace"?Q:t(H,Q);if(Array.isArray(H))return U==="replace"?Q:t(H,Q);if(!K(Q)||!K(H))return Q;let Z={...H};for(let $ of Object.keys(Q)){if(!Object.prototype.hasOwnProperty.call(Q,$))continue;let X=Q[$],Y=Z[$];if(X===null||X===void 0)continue;if(Array.isArray(X)||Array.isArray(Y))if(U==="replace")Z[$]=X;else Z[$]=t(Y,X);else if(K(X)&&K(Y))Z[$]=DH(Y,X,U);else Z[$]=X}return Z}function ZH(H,Q){if(H===Q)return!0;if(Array.isArray(H)&&Array.isArray(Q)){if(H.length!==Q.length)return!1;for(let U=0;U<H.length;U++)if(!ZH(H[U],Q[U]))return!1;return!0}if(K(H)&&K(Q)){let U=Object.keys(H),Z=Object.keys(Q);if(U.length!==Z.length)return!1;for(let $ of U){if(!Object.prototype.hasOwnProperty.call(Q,$))return!1;if(!ZH(H[$],Q[$]))return!1}return!0}return!1}function K(H){return Boolean(H&&typeof H==="object"&&!Array.isArray(H))}var I=new $H("bunfig",{showTags:!0});async function o(H,Q,U="replace"){if(!mH(H))return null;try{let Z=await import(H),$=Z.default||Z;if(typeof $!=="object"||$===null||Array.isArray($))return null;try{return DH(Q,$,U)}catch{return null}}catch{return null}}function DQ(H,Q,U=!1){if(!H)return Q;let Z=H.toUpperCase().replace(/-/g,"_"),$={...Q};function X(Y,G=[]){let J={...Y};for(let[q,N]of Object.entries(Y)){let A=[...G,q],z=(F)=>F.replace(/([A-Z])/g,"_$1").toUpperCase(),W=`${Z}_${A.map(z).join("_")}`,k=`${Z}_${A.map((F)=>F.toUpperCase()).join("_")}`;if(U)I.info(`Checking environment variable ${W} for config ${H}.${A.join(".")}`);if(typeof N==="object"&&N!==null&&!Array.isArray(N))J[q]=X(N,A);else{let F=g.env[W]||g.env[k];if(F!==void 0){if(U)I.info(`Using environment variable ${F?W:k} for config ${H}.${A.join(".")}`);if(typeof N==="number")J[q]=Number(F);else if(typeof N==="boolean")J[q]=F.toLowerCase()==="true";else if(Array.isArray(N))try{let D=JSON.parse(F);if(Array.isArray(D))J[q]=D;else J[q]=F.split(",").map((j)=>j.trim())}catch{J[q]=F.split(",").map((D)=>D.trim())}else J[q]=F}}}return J}return X($)}async function EQ({name:H="",alias:Q,cwd:U,configDir:Z,defaultConfig:$,verbose:X=!1,checkEnv:Y=!0,arrayStrategy:G="replace"}){let J=Y&&typeof $==="object"&&$!==null&&!Array.isArray($)?DQ(H,$,X):$,q=U||g.cwd(),N=[".ts",".js",".mjs",".cjs",".json"];if(X)I.info(`Loading configuration for "${H}"${Q?` (alias: "${Q}")`:""} from ${q}`);let A=[H,`.${H}`].filter(Boolean),z=[`${H}.config`,`.${H}.config`].filter(Boolean),W=Q?[Q,`.${Q}`]:[],k=Q?[`${Q}.config`,`.${Q}.config`]:[],F=Array.from(new Set([q,C(q,"config"),C(q,".config"),Z?C(q,Z):void 0].filter(Boolean)));for(let D of F){if(X)I.info(`Searching for configuration in: ${D}`);let M=[C(q,"config"),C(q,".config")].concat(Z?[C(q,Z)]:[]).includes(D)?[...A,...z,...W,...k]:[...z,...A,...k,...W];for(let S of M)for(let P of N){let x=C(D,`${S}${P}`),EH=await o(x,J,G);if(EH!==null){if(X)I.success(`Configuration loaded from: ${x}`);return EH}}}if(H){let D=C(XH(),".config",H),j=["config",`${H}.config`];if(Q)j.push(`${Q}.config`);if(X)I.info(`Checking user config directory: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user config directory: ${P}`);return x}}}if(H){let D=C(XH(),".config"),j=[`.${H}.config`];if(Q)j.push(`.${Q}.config`);if(X)I.info(`Checking user config directory for dotfile configs: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user config directory dotfile: ${P}`);return x}}}if(H){let D=XH(),j=[`.${H}.config`,`.${H}`];if(Q)j.push(`.${Q}.config`),j.push(`.${Q}`);if(X)I.info(`Checking user home directory for dotfile configs: ${D}`);for(let M of j)for(let S of N){let P=C(D,`${M}${S}`),x=await o(P,J,G);if(x!==null){if(X)I.success(`Configuration loaded from user home directory: ${P}`);return x}}}try{let D=C(q,"package.json");if(mH(D)){let j=await import(D),M=j[H];if(!M&&Q){if(M=j[Q],M&&X)I.success(`Using alias "${Q}" configuration from package.json`)}if(M&&typeof M==="object"&&!Array.isArray(M))try{if(X)I.success(`Configuration loaded from package.json: ${M===j[H]?H:Q}`);return DH(J,M,G)}catch(S){if(X)I.warn("Failed to merge package.json config:",S)}}}catch(D){if(X)I.warn("Failed to load package.json:",D)}if(X)I.info(`No configuration found for "${H}"${Q?` or alias "${Q}"`:""}, using default configuration with environment variables`);return J}var wU=C(g.cwd(),"config"),CU=C(g.cwd(),"src/generated");function TQ(H,Q={}){let U=e.cwd();while(U.includes("storage"))U=TH(U,"..");let Z=TH(U,H||"");if(Q?.relative)return tH(e.cwd(),Z);return Z}var FQ=e.env.CLARITY_LOG_DIR||sH(TQ(),"logs"),WH={level:"info",defaultName:"clarity",timestamp:!0,colors:!0,format:"text",maxLogSize:10485760,logDatePattern:"YYYY-MM-DD",logDirectory:FQ,rotation:{frequency:"daily",maxSize:10485760,maxFiles:5,compress:!1,rotateHour:0,rotateMinute:0,rotateDayOfWeek:0,rotateDayOfMonth:1,encrypt:!1},verbose:!1,writeToFile:!1};async function BQ(){try{let H=await EQ({name:"clarity",alias:"logging",defaultConfig:WH,cwd:e.cwd()});return{...WH,...H||{}}}catch{return WH}}var PH=await BQ();function T(){if(b.env.NODE_ENV==="test"||b.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function SQ(){if(b.env.NODE_ENV==="test"||b.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof b<"u"){let H=b.type;if(H==="renderer"||H==="worker")return!1;return!!(b.versions&&(b.versions.node||b.versions.bun))}return!1}class nH{async format(H){let Q=await SQ(),U=await this.getMetadata(Q);return JSON.stringify({timestamp:H.timestamp.toISOString(),level:H.level,name:H.name,message:H.message,metadata:U})}async getMetadata(H){if(H){let{hostname:Q}=await import("os");return{pid:c.pid,hostname:Q(),environment:c.env.NODE_ENV||"development",platform:c.platform,version:c.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:c.env.NODE_ENV||c.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}var B={red:(H)=>`\x1B[31m${H}\x1B[0m`,green:(H)=>`\x1B[32m${H}\x1B[0m`,yellow:(H)=>`\x1B[33m${H}\x1B[0m`,blue:(H)=>`\x1B[34m${H}\x1B[0m`,magenta:(H)=>`\x1B[35m${H}\x1B[0m`,cyan:(H)=>`\x1B[36m${H}\x1B[0m`,white:(H)=>`\x1B[37m${H}\x1B[0m`,gray:(H)=>`\x1B[90m${H}\x1B[0m`,bgRed:(H)=>`\x1B[41m${H}\x1B[0m`,bgYellow:(H)=>`\x1B[43m${H}\x1B[0m`,bgGray:(H)=>`\x1B[100m${H}\x1B[0m`,bold:(H)=>`\x1B[1m${H}\x1B[0m`,dim:(H)=>`\x1B[2m${H}\x1B[0m`,italic:(H)=>`\x1B[3m${H}\x1B[0m`,underline:(H)=>`\x1B[4m${H}\x1B[0m`,strikethrough:(H)=>`\x1B[9m${H}\x1B[0m`,reset:"\x1B[0m"},R=B,dU=B.red,hQ=B.green,pU=B.yellow,vQ=B.blue,mU=B.magenta,cU=B.cyan,uH=B.white,gU=B.gray,bQ=B.bgRed,yQ=B.bgYellow,nU=B.bgGray,dH=B.bold,lU=B.dim,iU=B.italic,oU=B.underline,aU=B.strikethrough,rU=B.reset,KH={activationLevel:"error",bufferSize:50,flushOnDeactivation:!0,stopBuffering:!1},fQ={debug:"\uD83D\uDD0D",info:vQ("β„Ή"),success:hQ("βœ“"),warning:yQ(uH(dH(" WARN "))),error:bQ(uH(dH(" ERROR ")))};class n{name;fileLocks=new Map;currentKeyId=null;keys=new Map;fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(H,Q={}){this.name=H,this.config={...PH},this.options=this.normalizeOptions(Q),this.formatter=this.options.formatter||new nH,this.enabled=Q.enabled??!0,this.fancy=Q.fancy??!0,this.tagFormat=Q.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=Q.timestampPosition??"right",this.environment=Q.environment??_.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(Q);let U={...Q},Z=Q.timestamp!==void 0;if(Z)delete U.timestamp;if(this.config={...this.config,...U,timestamp:Z||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let $=this.generateKeyId(),X=this.generateKey();this.currentKeyId=$,this.keys.set($,X),this.encryptionKeys.set($,{key:X,createdAt:new Date}),this.setupKeyRotation()}}shouldActivateFingersCrossed(H){if(!this.fingersCrossedConfig)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4},U=this.fingersCrossedConfig.activationLevel??"error";return Q[H]>=Q[U]}initializeFingersCrossedConfig(H){if(!H.fingersCrossedEnabled&&H.fingersCrossed)return{...KH,...H.fingersCrossed};if(!H.fingersCrossedEnabled)return null;if(!H.fingersCrossed)return{...KH};return{...KH,...H.fingersCrossed}}normalizeOptions(H){let Q={format:"json",level:"info",logDirectory:PH.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,showIcons:!0,formatter:void 0},U={...Q,...Object.fromEntries(Object.entries(H).filter(([,Z])=>Z!==void 0))};if(!U.level||!["debug","info","success","warning","error"].includes(U.level))U.level=Q.level;return U}shouldWriteToFile(){return!T()&&this.config.writeToFile===!0}async writeToFile(H){let U=(async()=>{let $,X=0,Y=3,G=1000;while(X<Y)try{try{try{await wQ(this.config.logDirectory,bH.F_OK|bH.W_OK)}catch(q){if(q instanceof Error&&"code"in q)if(q.code==="ENOENT")await CQ(this.config.logDirectory,{recursive:!0,mode:493});else if(q.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw q;else throw q}}catch(q){throw console.error("Debug: [writeToFile] Failed to create log directory:",q),q}let J=this.validateEncryptionConfig()?(await this.encrypt(H)).encrypted:h.from(H);try{if(!a(this.currentLogFile))await RH(this.currentLogFile,"",{mode:420});if($=vH(this.currentLogFile,"a",420),IQ($,J,{flag:"a"}),hH($),$!==void 0)_H($),$=void 0;if((await p(this.currentLogFile)).size===0){if(await RH(this.currentLogFile,J,{flag:"w",mode:420}),(await p(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(q){let N=q;if(N.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(N.code)){if(X<Y-1){let A=typeof N.message==="string"?N.message:"Unknown error";console.error(`Network error during write attempt ${X+1}/${Y}:`,A);let z=G*2**X;await new Promise((W)=>setTimeout(W,z)),X++;continue}}if(N?.code&&["ENOSPC","EDQUOT"].includes(N.code))throw Error(`Disk quota exceeded or no space left on device: ${N.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",N),N}finally{if($!==void 0)try{_H($)}catch(q){console.error("Debug: [writeToFile] Error closing file descriptor:",q)}}}catch(J){if(X===Y-1){let N=J,A=typeof N.message==="string"?N.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),J}X++;let q=G*2**(X-1);await new Promise((N)=>setTimeout(N,q))}})();this.pendingOperations.push(U);let Z=this.pendingOperations.length-1;try{await U}catch($){throw console.error("Debug: [writeToFile] Error in operation:",$),$}finally{this.pendingOperations.splice(Z,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return m(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return m(this.config.logDirectory,`${this.name}.log`);let H=new Date().toISOString().split("T")[0];return m(this.config.logDirectory,`${this.name}-${H}.log`)}setupRotation(){if(T())return;if(!this.shouldWriteToFile())return;if(typeof this.config.rotation==="boolean")return;let H=this.config.rotation,Q;switch(H.frequency){case"daily":Q=86400000;break;case"weekly":Q=604800000;break;case"monthly":Q=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},Q)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let Q=this.config.rotation.keyRotation;if(!Q?.enabled)return;let U=typeof Q.interval==="number"?Q.interval:60,Z=Math.max(U,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch(($)=>{console.error("Error rotating keys:",$)})},Z)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let Q=this.config.rotation.keyRotation,U=this.generateKeyId(),Z=this.generateKey();this.currentKeyId=U,this.keys.set(U,Z),this.encryptionKeys.set(U,{key:Z,createdAt:new Date});let $=Array.from(this.encryptionKeys.entries()).sort(([,G],[,J])=>J.createdAt.getTime()-G.createdAt.getTime()),X=typeof Q.maxKeys==="number"?Q.maxKeys:1,Y=Math.max(1,X);if($.length>Y)for(let[G]of $.slice(Y))this.encryptionKeys.delete(G),this.keys.delete(G)}generateKeyId(){return zH(16).toString("hex")}generateKey(){return zH(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let H=this.keys.get(this.currentKeyId);if(!H)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:H,id:this.currentKeyId}}encrypt(H){let{key:Q}=this.getCurrentKey(),U=zH(16),Z=OQ("aes-256-gcm",Q,U),$=h.isBuffer(H)?H:h.from(H,"utf8"),X=Z.update($),Y=Z.final(),G=X.length+Y.length,J=Z.getAuthTag(),q=h.allocUnsafe(16+G+16);return U.copy(q,0),X.copy(q,16),Y.copy(q,16+X.length),J.copy(q,16+G),{encrypted:q,iv:U}}async compressData(H){return new Promise((Q,U)=>{let Z=fH(),$=[];Z.on("data",(X)=>$.push(X)),Z.on("end",()=>Q(h.from(h.concat($)))),Z.on("error",U),Z.write(H),Z.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let H={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let Q=this.config.rotation.encrypt;return{...H,...Q}}return H}async rotateLog(){if(T())return;if(!this.shouldWriteToFile())return;let H=await p(this.currentLogFile).catch(()=>null);if(!H)return;let Q=this.config.rotation;if(typeof Q==="boolean")return;if(Q.maxSize&&H.size>=Q.maxSize){let U=this.currentLogFile,Z=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let $=await r(this.config.logDirectory),X=$.filter((J)=>J.startsWith(this.name)&&/\.log\.\d+$/.test(J)).sort((J,q)=>{let N=Number.parseInt(J.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(q.match(/\.log\.(\d+)$/)?.[1]||"0")-N}),Y=X.length>0?Number.parseInt(X[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,G=`${U}.${Y}`;if(await p(U).catch(()=>null))try{if(await yH(U,G),Q.compress)try{let J=`${G}.gz`;await this.compressLogFile(G,J),await s(G)}catch(J){console.error("Error compressing rotated file:",J)}if(X.length===0&&!$.some((J)=>J.endsWith(".log.1")))try{let J=`${U}.1`;await RH(J,"")}catch(J){console.error("Error creating backup file:",J)}}catch(J){console.error(`Error during rotation: ${J instanceof Error?J.message:String(J)}`)}}else{let $=new Date().toISOString().replace(/[:.]/g,"-"),X=U.replace(/\.log$/,`-${$}.log`);if(await p(U).catch(()=>null))await yH(U,X)}if(this.currentLogFile=Z,Q.maxFiles){let X=(await r(this.config.logDirectory)).filter((Y)=>Y.startsWith(this.name)).sort((Y,G)=>G.localeCompare(Y));for(let Y of X.slice(Q.maxFiles))await s(m(this.config.logDirectory,Y))}}}async compressLogFile(H,Q){let U=SH(H),Z=MQ(Q),$=fH();await PQ(U,$,Z)}async handleFingersCrossedBuffer(H,Q){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(H)&&!this.isActivated){this.isActivated=!0;for(let U of this.logBuffer){let Z=await this.formatter.format(U);if(this.shouldWriteToFile())await this.writeToFile(Z);console.log(Z)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated){if(this.shouldWriteToFile())await this.writeToFile(Q);console.log(Q)}}shouldLog(H){if(!this.enabled)return!1;let Q={debug:0,info:1,success:2,warning:3,error:4};return Q[H]>=Q[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((H)=>{if(H instanceof Promise)return H.catch((Q)=>{console.error("Error in pending write operation:",Q)});return Promise.resolve()})),a(this.currentLogFile))try{let H=vH(this.currentLogFile,"r+");hH(H),_H(H)}catch(H){console.error(`Error flushing file: ${H}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let H of this.pendingOperations)if(typeof H.cancel==="function")H.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(H){console.error("Error waiting for pending operations:",H)}if(!T()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let Q=(await r(this.config.logDirectory)).filter((U)=>(U.includes("temp")||U.includes(".tmp"))&&U.includes(this.name));for(let U of Q)try{await s(m(this.config.logDirectory,U))}catch(Z){console.error(`Failed to delete temp file ${U}:`,Z)}}catch(H){console.error("Error cleaning up temporary files:",H)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(H){if(!H)return"";return`${this.tagFormat.prefix}${H}${this.tagFormat.suffix}`}formatFileTimestamp(H){return`[${H.toISOString()}]`}formatConsoleTimestamp(H){return this.shouldStyleConsole()?R.gray(H.toLocaleTimeString()):H.toLocaleTimeString()}shouldStyleConsole(){if(!this.fancy||T())return!1;let H=typeof _.env.NO_COLOR<"u",Q=_.env.FORCE_COLOR==="0";if(H||Q)return!1;return!!(typeof _.stderr<"u"&&_.stderr.isTTY||typeof _.stdout<"u"&&_.stdout.isTTY)}formatConsoleMessage(H){let{timestamp:Q,icon:U="",tag:Z="",message:$,level:X,showTimestamp:Y=!0}=H,G=(W)=>W.replace(this.ANSI_PATTERN,"");if(!this.fancy){let W=[];if(Y)W.push(Q);if(X==="warning")W.push("WARN");else if(X==="error")W.push("ERROR");else if(U)W.push(U.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(Z)W.push(Z.replace(/[[\]]/g,""));return W.push($),W.join(" ")}let J=_.stdout.columns||120,q="";if(X==="warning"||X==="error")q=`${U} ${$}`;else if(X==="info"||X==="success")q=`${U} ${Z} ${$}`;else q=`${U} ${Z} ${R.cyan($)}`;if(!Y)return q.trim();let N=G(q).trim().length,A=G(Q).length,z=Math.max(1,J-2-N-A);return`${q.trim()}${" ".repeat(z)}${Q}`}formatMessage(H,Q){if(Q.length===1&&Array.isArray(Q[0]))return H.replace(/\{(\d+)\}/g,(X,Y)=>{let G=Number.parseInt(Y,10);return G<Q[0].length?String(Q[0][G]):X});let U=/%([sdijfo%])/g,Z=0,$=H.replace(U,(X,Y)=>{if(Y==="%")return"%";if(Z>=Q.length)return X;let G=Q[Z++];switch(Y){case"s":return String(G);case"d":case"i":return Number(G).toString();case"j":case"o":return JSON.stringify(G,null,2);default:return X}});if(Z<Q.length)$+=` ${Q.slice(Z).map((X)=>typeof X==="object"?JSON.stringify(X,null,2):String(X)).join(" ")}`;return $}formatMarkdown(H){if(!H)return H;let Q=H;return Q=Q.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(U,Z,$)=>{let X=R.underline(R.blue(Z)),Y=this.toAbsoluteFilePath($);if(Y&&this.shouldStyleConsole()&&this.supportsHyperlinks()){let G=`file://${encodeURI(Y)}`,J="\x1B]8;;",q="\x1B\\";return`\x1B]8;;${G}\x1B\\${X}\x1B]8;;\x1B\\`}if(this.shouldStyleConsole()&&this.supportsHyperlinks())return`\x1B]8;;${$}\x1B\\${X}\x1B]8;;\x1B\\`;return X}),Q=Q.replace(/`([^`]+)`/g,(U,Z)=>R.bgGray(Z)),Q=Q.replace(/\*\*([^*]+)\*\*/g,(U,Z)=>R.bold(Z)),Q=Q.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,(U,Z)=>R.italic(Z)),Q=Q.replace(/(?<!_)_([^_]+)_(?!_)/g,(U,Z)=>R.italic(Z)),Q=Q.replace(/~([^~]+)~/g,(U,Z)=>R.strikethrough(Z)),Q}supportsHyperlinks(){if(T())return!1;let H=_.env;if(!H)return!1;if(H.TERM_PROGRAM==="iTerm.app"||H.TERM_PROGRAM==="vscode"||H.TERM_PROGRAM==="WezTerm")return!0;if(H.WT_SESSION)return!0;if(H.TERM==="xterm-kitty")return!0;let Q=H.VTE_VERSION?Number.parseInt(H.VTE_VERSION,10):0;if(!Number.isNaN(Q)&&Q>=5000)return!0;return!1}toAbsoluteFilePath(H){try{let Q=H;if(Q.startsWith("file://"))Q=Q.replace(/^file:\/\//,"");if(Q.startsWith("~")){let U=_.env.HOME||"";if(U)Q=Q.replace(/^~(?=$|\/)/,U)}if(kQ(Q)||Q.startsWith("./")||Q.startsWith("../"))Q=xQ(Q);else return null;return a(Q)?Q:null}catch{return null}}buildOutputTexts(H){let Q=this.shouldStyleConsole()?this.formatMarkdown(H):H,U=H.replace(this.ANSI_PATTERN,"");return{consoleText:Q,fileText:U}}async log(H,Q,...U){let Z=new Date,$=this.formatConsoleTimestamp(Z),X=this.formatFileTimestamp(Z),Y,G;if(Q instanceof Error)Y=Q.message,G=Q.stack;else Y=this.formatMessage(Q,U);let{consoleText:J,fileText:q}=this.buildOutputTexts(Y);if(this.shouldStyleConsole()){let A=this.options.showIcons===!1?"":fQ[H],z=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",W;switch(H){case"debug":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:R.gray(J),level:H}),console.error(W);break;case"info":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.warn(W);break;case"success":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:R.green(J),level:H}),console.error(W);break;case"warning":W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.warn(W);break;case"error":if(W=this.formatConsoleMessage({timestamp:$,icon:A,tag:z,message:J,level:H}),console.error(W),G){let k=G.split(`
10
+ `);for(let F of k)if(F.trim()&&!F.includes(Y))console.error(this.formatConsoleMessage({timestamp:$,message:R.gray(` ${F}`),level:H,showTimestamp:!1}))}break}}else if(!T()){if(console.error(`${X} ${this.environment}.${H.toUpperCase()}: ${Y}`),G)console.error(G)}if(!this.shouldLog(H))return;let N=`${X} ${this.environment}.${H.toUpperCase()}: ${q}
11
+ `;if(G)N+=`${G}
12
+ `;if(N=N.replace(this.ANSI_PATTERN,""),this.shouldWriteToFile())await this.writeToFile(N)}progress(H,Q=""){let U={update:(G,J)=>{},finish:(G)=>{},interrupt:(G,J)=>{}};if(!this.enabled)return U;let Z=30;if(this.activeProgressBar={total:Math.max(1,H||1),current:0,message:Q||"",barLength:Z,lastRenderedLine:""},this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar);return{update:(G,J)=>{if(!this.enabled||!this.activeProgressBar)return;if(this.activeProgressBar.current=Math.min(Math.max(0,G),this.activeProgressBar.total),J!==void 0)this.activeProgressBar.message=J;if(this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar)},finish:(G)=>{if(!this.activeProgressBar)return;this.finishProgressBar(this.activeProgressBar,G)},interrupt:(G,J="info")=>{if(!T()&&_.stdout.isTTY)_.stdout.write(`
13
+ `);if(this[J==="warning"?"warn":J](G),this.activeProgressBar&&this.shouldStyleConsole()&&!T()&&_.stdout.isTTY)this.renderProgressBar(this.activeProgressBar)}}}time(H){let Q=performance.now();if(this.shouldStyleConsole()){let U=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",Z=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:Z,icon:this.options.showIcons===!1?"":R.blue("◐"),tag:U,message:`${R.cyan(H)}...`}))}return async(U)=>{if(!this.enabled)return;let Z=performance.now(),$=Math.round(Z-Q),X=`${H} completed in ${$}ms`,Y=new Date,G=this.formatConsoleTimestamp(Y),q=`${this.formatFileTimestamp(Y)} ${this.environment}.INFO: ${X}`;if(U)q+=` ${JSON.stringify(U)}`;if(q+=`
14
+ `,q=q.replace(this.ANSI_PATTERN,""),this.shouldStyleConsole()){let N=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"";console.error(this.formatConsoleMessage({timestamp:G,icon:this.options.showIcons===!1?"":R.green("βœ“"),tag:N,message:`${X}${U?` ${JSON.stringify(U)}`:""}`}))}else if(!T())console.error(q.trim());if(this.shouldWriteToFile())await this.writeToFile(q)}}async debug(H,...Q){await this.log("debug",H,...Q)}async info(H,...Q){await this.log("info",H,...Q)}async success(H,...Q){await this.log("success",H,...Q)}async warn(H,...Q){await this.log("warning",H,...Q)}async error(H,...Q){await this.log("error",H,...Q)}validateEncryptionConfig(){if(!this.config.rotation)return!1;if(typeof this.config.rotation==="boolean")return!1;let H=this.config.rotation,{encrypt:Q}=H;return!!Q}async only(H){if(!this.enabled)return;return await H()}isEnabled(){return this.enabled}setEnabled(H){this.enabled=H}extend(H){let Q=`${this.name}:${H}`,U=new n(Q,{...this.options,logDirectory:this.config.logDirectory,level:this.config.level,format:this.config.format,rotation:typeof this.config.rotation==="boolean"?void 0:this.config.rotation,timestamp:typeof this.config.timestamp==="boolean"?void 0:this.config.timestamp});return this.subLoggers.add(U),U}createReadStream(){if(T())throw Error("createReadStream is not supported in browser environments");if(!a(this.currentLogFile))throw Error(`Log file does not exist: ${this.currentLogFile}`);return SH(this.currentLogFile,{encoding:"utf8"})}async decrypt(H){if(!this.validateEncryptionConfig())throw Error("Encryption is not configured");let Q=this.config.rotation;if(!Q.encrypt||typeof Q.encrypt==="boolean")throw Error("Invalid encryption configuration");if(!this.currentKeyId||!this.keys.has(this.currentKeyId))throw Error("No valid encryption key available");let U=this.keys.get(this.currentKeyId);try{let Z=h.isBuffer(H)?H:h.from(H,"base64"),$=Z.subarray(0,16),X=Z.subarray(Z.length-16),Y=Z.subarray(16,Z.length-16),G=jQ("aes-256-gcm",U,$);G.setAuthTag(X);let J=G.update(Y),q=G.final(),N=J.length+q.length,A=h.allocUnsafe(N);return J.copy(A,0),q.copy(A,J.length),A.toString("utf8")}catch(Z){throw Error(`Decryption failed: ${Z instanceof Error?Z.message:String(Z)}`)}}getLevel(){return this.config.level}getLogDirectory(){return this.config.logDirectory}getFormat(){return this.config.format}getRotationConfig(){return this.config.rotation}isBrowserMode(){return T()}isServerMode(){return!T()}setTestEncryptionKey(H,Q){this.currentKeyId=H,this.keys.set(H,Q)}getTestCurrentKey(){if(!this.currentKeyId||!this.keys.has(this.currentKeyId))return null;return{id:this.currentKeyId,key:this.keys.get(this.currentKeyId)}}getConfig(){return this.config}async box(H){if(!this.enabled)return;let Q=new Date,U=this.formatConsoleTimestamp(Q),Z=this.formatFileTimestamp(Q),{consoleText:$,fileText:X}=this.buildOutputTexts(H);if(this.shouldStyleConsole()){let G=$.split(`
15
+ `),J=Math.max(...G.map((z)=>z.length))+2,q=`β”Œ${"─".repeat(J)}┐`,N=`β””${"─".repeat(J)}β”˜`,A=G.map((z)=>{return this.formatConsoleMessage({timestamp:U,message:R.cyan(z),showTimestamp:!1})});console.error(this.formatConsoleMessage({timestamp:U,message:R.cyan(q),showTimestamp:!1})),A.forEach((z)=>console.error(z)),console.error(this.formatConsoleMessage({timestamp:U,message:R.cyan(N),showTimestamp:!1}))}else if(!T())console.error(`${Z} ${this.environment}.INFO: [BOX] ${X}`);let Y=`${Z} ${this.environment}.INFO: [BOX] ${X}
16
+ `.replace(this.ANSI_PATTERN,"");if(this.shouldWriteToFile())await this.writeToFile(Y)}async prompt(H){if(T())return Promise.resolve(!0);return new Promise((Q)=>{console.error(`${R.cyan("?")} ${H} (y/n) `);let U=(Z)=>{let $=Z.toString().trim().toLowerCase();_.stdin.removeListener("data",U);try{if(typeof _.stdin.setRawMode==="function")_.stdin.setRawMode(!1)}catch{}_.stdin.pause(),console.error(""),Q($==="y"||$==="yes")};try{if(typeof _.stdin.setRawMode==="function")_.stdin.setRawMode(!0)}catch{}_.stdin.resume(),_.stdin.once("data",U)})}setFancy(H){this.fancy=H}isFancy(){return this.fancy}pause(){this.enabled=!1}resume(){this.enabled=!0}async start(H,...Q){if(!this.enabled)return;let U=H;if(Q&&Q.length>0){let J=/%([sdijfo%])/g,q=0;if(U=H.replace(J,(N,A)=>{if(A==="%")return"%";if(q>=Q.length)return N;let z=Q[q++];switch(A){case"s":return String(z);case"d":case"i":return Number(z).toString();case"j":case"o":return JSON.stringify(z,null,2);default:return N}}),q<Q.length)U+=` ${Q.slice(q).map((N)=>typeof N==="object"?JSON.stringify(N,null,2):String(N)).join(" ")}`}let{consoleText:Z,fileText:$}=this.buildOutputTexts(U);if(this.shouldStyleConsole()){let J=this.options.showTags!==!1&&this.name?R.gray(this.formatTag(this.name)):"",q=this.options.showIcons===!1?"":`${R.blue("◐")} `;console.error(`${q}${J} ${R.cyan(Z)}`)}let G=`[${new Date().toISOString()}] ${this.environment}.INFO: [START] ${$}
17
+ `.replace(this.ANSI_PATTERN,"");if(this.shouldWriteToFile())await this.writeToFile(G)}renderProgressBar(H,Q=!1){if(!this.enabled||!this.shouldStyleConsole()||!_.stdout.isTTY)return;let U=Math.min(100,Math.max(0,Math.round(H.current/H.total*100))),Z=Math.round(H.barLength*U/100),$=H.barLength-Z,X=R.green("━".repeat(Z)),Y=R.gray("━".repeat($)),G=`[${X}${Y}]`,J=`${U}%`.padStart(4),q=H.message?` ${H.message}`:"",N=this.options.showIcons===!1?"":Q||U===100?R.green("βœ“"):R.blue("β–Ά"),A=this.options.showTags!==!1&&this.name?` ${R.gray(this.formatTag(this.name))}`:"",z=`\r${N}${A} ${G} ${J}${q}`,W=_.stdout.columns||80,k=" ".repeat(Math.max(0,W-z.replace(this.ANSI_PATTERN,"").length));if(H.lastRenderedLine=`${z}${k}`,_.stdout.write(H.lastRenderedLine),Q)_.stdout.write(`
18
+ `)}finishProgressBar(H,Q){if(!this.enabled||!this.fancy||T()||!_.stdout.isTTY){this.activeProgressBar=null;return}if(H.current<H.total)H.current=H.total;if(Q)H.message=Q;this.renderProgressBar(H,!0),this.activeProgressBar=null}async clear(H={}){if(T()){console.warn("Log clearing is not supported in browser environments.");return}try{console.warn("Clearing logs...",this.config.logDirectory);let Q=await r(this.config.logDirectory),U=[];for(let Z of Q){if(!(H.name?new RegExp(H.name.replace("*",".*")).test(Z):Z.startsWith(this.name))||!Z.endsWith(".log"))continue;let X=m(this.config.logDirectory,Z);if(H.before)try{if((await p(X)).mtime>=H.before)continue}catch(Y){console.error(`Failed to get stats for file ${X}:`,Y);continue}U.push(X)}if(U.length===0){console.warn("No log files matched the criteria for clearing.");return}console.warn(`Preparing to delete ${U.length} log file(s)...`);for(let Z of U)try{await s(Z),console.warn(`Deleted log file: ${Z}`)}catch($){console.error(`Failed to delete log file ${Z}:`,$)}console.warn("Log clearing process finished.")}catch(Q){console.error("Error during log clearing process:",Q)}}}var sU=new n("stacks");var uQ=new n("rpx",{showTags:!1});function dQ(){return process.env.SUDO_PASSWORD}function QZ(H){let Q=dQ(),U=H.replace(/'/g,"'\\''");if(Q)return lH(`echo '${Q}' | sudo -S sh -c '${U}' 2>/dev/null`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]});return lH(`sudo sh -c '${U}'`,{encoding:"utf-8"})}function iH(H,Q,U){if(U)uQ.debug(`[rpx:${H}] ${Q}`)}function UZ(H){if(aH(H))return H.proxies.map((Q)=>{let U=Q.to||"stacks.localhost";return U.startsWith("http")?new URL(U).hostname:U});if(rH(H)){let Q=H.to||"stacks.localhost";return[Q.startsWith("http")?new URL(Q).hostname:Q]}return["stacks.localhost"]}function ZZ(H){return typeof H==="object"&&H!==null&&"certificate"in H&&"privateKey"in H&&typeof H.certificate==="string"&&typeof H.privateKey==="string"}function $Z(H){if(!H)return"stacks.localhost";if(aH(H)&&H.proxies.length>0)return H.proxies[0].to||"stacks.localhost";if(rH(H))return H.to||"stacks.localhost";return"stacks.localhost"}function XZ(H){return!!(H&&("proxies"in H)&&Array.isArray(H.proxies))}function aH(H){return"proxies"in H&&Array.isArray(H.proxies)}function rH(H){return"to"in H&&typeof H.to==="string"}function YZ(H){return!!(H&&("to"in H)&&!("proxies"in H))}async function JZ(H,Q){try{await oH.unlink(H),iH("certificates",`Successfully deleted: ${H}`,Q)}catch(U){if(U.code!=="ENOENT")iH("certificates",`Warning: Could not delete ${H}: ${U}`,Q)}}
19
+ export{dQ as w,QZ as x,iH as y,UZ as z,ZZ as A,$Z as B,XZ as C,aH as D,rH as E,YZ as F,JZ as G};
@@ -0,0 +1,2 @@
1
+ import{createRequire as a}from"node:module";var c=a(import.meta.url);
2
+ export{c as H};