Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typal

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typal - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 21 April 2020
### [2.0.2](https://gitlab.com/artdeco/typal/compare/v2.0.1...v2.0.2)
- [feature] Generate `props` for an interface.
## 16 April 2020

@@ -2,0 +8,0 @@

127

compile/bin/typal.js

@@ -10,4 +10,4 @@ #!/usr/bin/env node

boolean:!0,short:"u"},externs:{description:"Whether to generate externs for _GCC_.",boolean:!0,short:"e"},types:{description:"Comma-separated location of files to read types from.",short:"t"},template:{description:"Scans the input file for `@type` comment in functions' JSDoc, and inserts the annotations from types' files.",short:"T"},migrate:{description:"Extracts types from JavaScript source code and saves them\ninto the types.xml file specified in the output option.",boolean:!0,short:"m"},help:{description:"Print the help information and exit.",
boolean:!0,short:"h"},version:{description:"Show the version's number and exit.",boolean:!0,short:"v"}},p=function(a={},b=process.argv){let [,,...c]=b;const d=fa(c);c=c.slice(d.length);a=Object.entries(a).reduce((f,[h,k])=>{f[h]="string"==typeof k?{short:k}:k;return f},{});const e=[];a=Object.entries(a).reduce((f,[h,k])=>{let l;try{const n=k.short,m=k.boolean,q=k.number,r=k.command,t=k.multiple;if(r&&t&&d.length)l=d;else if(r&&d.length)l=d[0];else{const u=ea(c,h,n,m,q);({value:l}=u);const v=u.index,
w=u.length;void 0!==v&&w&&e.push({index:v,length:w})}}catch(n){return f}return void 0===l?f:{...f,[h]:l}},{});let g=c;e.forEach(({index:f,length:h})=>{Array.from({length:h}).forEach((k,l)=>{g[f+l]=null})});g=g.filter(f=>null!==f);Object.assign(a,{$:g});return a}(ha),x=p.source,ja=p.output,ka=p.closure,la=p.useNamespace,ma=p.externs,na=p.types,oa=p.template,pa=p.migrate,qa=p.version;function ra(a={usage:{}}){const {usage:b={},description:c,line:d,example:e}=a;a=Object.keys(b);const g=Object.values(b),[f]=a.reduce(([l=0,n=0],m)=>{const q=b[m].split("\n").reduce((r,t)=>t.length>r?t.length:r,0);q>n&&(n=q);m.length>l&&(l=m.length);return[l,n]},[]),h=(l,n)=>{n=" ".repeat(n-l.length);return`${l}${n}`};a=a.reduce((l,n,m)=>{m=g[m].split("\n");n=h(n,f);const [q,...r]=m;n=`${n}\t${q}`;const t=h("",f);m=r.map(u=>`${t}\t${u}`);return[...l,n,...m]},[]).map(l=>`\t${l}`);const k=[c,` ${d||
boolean:!0,short:"h"},version:{description:"Show the version's number and exit.",boolean:!0,short:"v"}},r=function(a={},b=process.argv){let [,,...c]=b;const d=fa(c);c=c.slice(d.length);a=Object.entries(a).reduce((f,[h,k])=>{f[h]="string"==typeof k?{short:k}:k;return f},{});const e=[];a=Object.entries(a).reduce((f,[h,k])=>{let l;try{const m=k.short,n=k.boolean,p=k.number,q=k.command,t=k.multiple;if(q&&t&&d.length)l=d;else if(q&&d.length)l=d[0];else{const u=ea(c,h,m,n,p);({value:l}=u);const v=u.index,
w=u.length;void 0!==v&&w&&e.push({index:v,length:w})}}catch(m){return f}return void 0===l?f:{...f,[h]:l}},{});let g=c;e.forEach(({index:f,length:h})=>{Array.from({length:h}).forEach((k,l)=>{g[f+l]=null})});g=g.filter(f=>null!==f);Object.assign(a,{$:g});return a}(ha),x=r.source,ja=r.output,ka=r.closure,la=r.useNamespace,ma=r.externs,na=r.types,oa=r.template,pa=r.migrate,qa=r.version;function ra(a={usage:{}}){const {usage:b={},description:c,line:d,example:e}=a;a=Object.keys(b);const g=Object.values(b),[f]=a.reduce(([l=0,m=0],n)=>{const p=b[n].split("\n").reduce((q,t)=>t.length>q?t.length:q,0);p>m&&(m=p);n.length>l&&(l=n.length);return[l,m]},[]),h=(l,m)=>{m=" ".repeat(m-l.length);return`${l}${m}`};a=a.reduce((l,m,n)=>{n=g[n].split("\n");m=h(m,f);const [p,...q]=n;m=`${m}\t${p}`;const t=h("",f);n=q.map(u=>`${t}\t${u}`);return[...l,m,...n]},[]).map(l=>`\t${l}`);const k=[c,` ${d||
""}`].filter(l=>l?l.trim():l).join("\n\n");a=`${k?`${k}\n`:""}

@@ -20,66 +20,67 @@ ${a.join("\n")}

`:a};const sa=fs.createReadStream,ta=fs.createWriteStream,z=fs.lstat,ua=fs.readFileSync,va=fs.readdir;var wa=stream;const A=stream.Transform,xa=stream.Writable;const ya=(a,b=0,c=!1)=>{if(0===b&&!c)return a;a=a.split("\n",c?b+1:void 0);return c?a[a.length-1]:a.slice(b).join("\n")},za=(a,b=!1)=>ya(a,2+(b?1:0)),Aa=a=>{({callee:{caller:a}}=a);return a};const B=os.EOL,Ba=os.homedir;const Ca=/\s+at.*(?:\(|\s)(.*)\)?/,Da=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/,Ea=a=>{const {pretty:b=!1,ignoredModules:c=["pirates","@artdeco/pirates"]}={},d=c.join("|"),e=new RegExp(Da.source.replace("IGNORED_MODULES",d));return a.replace(/\\/g,"/").split("\n").filter(g=>{g=g.match(Ca);if(null===g||!g[1])return!0;g=g[1];return g.includes(".app/Contents/Resources/electron.asar")||g.includes(".app/Contents/Resources/default_app.asar")?
!1:!e.test(g)}).filter(g=>g.trim()).map(g=>{if(b){const f=Ba().replace(/\\/g,"/");return g.replace(/\s+at.*(?:\(|\s)(.*)\)?/,(h,k)=>h.replace(k,k.replace(f,"~")))}return g}).join("\n")};function Fa(a,b,c=!1){return function(d){var e=Aa(arguments),{stack:g}=Error();const f=ya(g,2,!0),h=(g=d instanceof Error)?d.message:d;e=[`Error: ${h}`,...null!==e&&a===e||c?[b]:[f,b]].join("\n");e=Ea(e);return Object.assign(g?d:Error(),{message:h,stack:e})}};function C(a){var {stack:b}=Error();const c=Aa(arguments);b=za(b,a);return Fa(c,b,a)};const Ga=(a,b)=>{b.once("error",c=>{a.emit("error",c)});return b};class Ha extends xa{constructor(a){const {binary:b=!1,rs:c=null,...d}=a||{},{T:e=C(!0),proxyError:g}=a||{},f=(h,k)=>e(k);super(d);this.b=[];this.P=new Promise((h,k)=>{this.on("finish",()=>{let l;b?l=Buffer.concat(this.b):l=this.b.join("");h(l);this.b=[]});this.once("error",l=>{if(-1==l.stack.indexOf("\n"))f`${l}`;else{const n=Ea(l.stack);l.stack=n;g&&f`${l}`}k(l)});c&&Ga(this,c).pipe(this)})}_write(a,b,c){this.b.push(a);c()}get f(){return this.P}}const D=async a=>{({f:a}=new Ha({rs:a,T:C(!0)}));return await a};async function F(a){a=sa(a);return await D(a)};async function G(a,b){if(!a)throw Error("No path is given.");const c=C(!0),d=ta(a);await new Promise((e,g)=>{d.on("error",f=>{f=c(f);g(f)}).on("close",e).end(b)})};async function H(a,b,c){const d=C(!0);if("function"!=typeof a)throw Error("Function must be passed.");if(!a.length)throw Error(`Function${a.name?` ${a.name}`:""} does not accept any arguments.`);return await new Promise((e,g)=>{const f=(k,l)=>k?(k=d(k),g(k)):e(c||l);let h=[f];Array.isArray(b)?h=[...b,f]:1<Array.from(arguments).length&&(h=[b,f]);a(...h)})};const Ia=path.dirname,Ja=path.join,Ka=path.relative,La=path.resolve;async function Ma(a,b){b=b.map(async c=>{const d=Ja(a,c);return{lstat:await H(z,d),path:d,relativePath:c}});return await Promise.all(b)}const Na=a=>a.lstat.isDirectory(),Oa=a=>!a.lstat.isDirectory();
!1:!e.test(g)}).filter(g=>g.trim()).map(g=>{if(b){const f=Ba().replace(/\\/g,"/");return g.replace(/\s+at.*(?:\(|\s)(.*)\)?/,(h,k)=>h.replace(k,k.replace(f,"~")))}return g}).join("\n")};function Fa(a,b,c=!1){return function(d){var e=Aa(arguments),{stack:g}=Error();const f=ya(g,2,!0),h=(g=d instanceof Error)?d.message:d;e=[`Error: ${h}`,...null!==e&&a===e||c?[b]:[f,b]].join("\n");e=Ea(e);return Object.assign(g?d:Error(),{message:h,stack:e})}};function C(a){var {stack:b}=Error();const c=Aa(arguments);b=za(b,a);return Fa(c,b,a)};const Ga=(a,b)=>{b.once("error",c=>{a.emit("error",c)});return b};class Ha extends xa{constructor(a){const {binary:b=!1,rs:c=null,...d}=a||{},{T:e=C(!0),proxyError:g}=a||{},f=(h,k)=>e(k);super(d);this.b=[];this.P=new Promise((h,k)=>{this.on("finish",()=>{let l;b?l=Buffer.concat(this.b):l=this.b.join("");h(l);this.b=[]});this.once("error",l=>{if(-1==l.stack.indexOf("\n"))f`${l}`;else{const m=Ea(l.stack);l.stack=m;g&&f`${l}`}k(l)});c&&Ga(this,c).pipe(this)})}_write(a,b,c){this.b.push(a);c()}get f(){return this.P}}const D=async a=>{({f:a}=new Ha({rs:a,T:C(!0)}));return await a};async function F(a){a=sa(a);return await D(a)};async function G(a,b){if(!a)throw Error("No path is given.");const c=C(!0),d=ta(a);await new Promise((e,g)=>{d.on("error",f=>{f=c(f);g(f)}).on("close",e).end(b)})};async function H(a,b,c){const d=C(!0);if("function"!=typeof a)throw Error("Function must be passed.");if(!a.length)throw Error(`Function${a.name?` ${a.name}`:""} does not accept any arguments.`);return await new Promise((e,g)=>{const f=(k,l)=>k?(k=d(k),g(k)):e(c||l);let h=[f];Array.isArray(b)?h=[...b,f]:1<Array.from(arguments).length&&(h=[b,f]);a(...h)})};const Ia=path.dirname,Ja=path.join,Ka=path.relative,La=path.resolve;async function Ma(a,b){b=b.map(async c=>{const d=Ja(a,c);return{lstat:await H(z,d),path:d,relativePath:c}});return await Promise.all(b)}const Na=a=>a.lstat.isDirectory(),Oa=a=>!a.lstat.isDirectory();
async function I(a){if(!a)throw Error("Please specify a path to the directory");const {ignore:b=[]}={};if(!(await H(z,a)).isDirectory()){var c=Error("Path is not a directory");c.code="ENOTDIR";throw c;}c=await H(va,a);var d=await Ma(a,c);c=d.filter(Na);d=d.filter(Oa).reduce((e,g)=>{var f=g.lstat.isDirectory()?"Directory":g.lstat.isFile()?"File":g.lstat.isSymbolicLink()?"SymbolicLink":void 0;return{...e,[g.relativePath]:{type:f}}},{});c=await c.reduce(async(e,{path:g,relativePath:f})=>{const h=Ka(a,
g);if(b.includes(h))return e;e=await e;g=await I(g);return{...e,[f]:g}},{});return{content:{...d,...c},type:"Directory"}}const J=(a,b)=>{let c=[],d=[];Object.keys(a).forEach(g=>{const {type:f}=a[g];"File"==f?c.push(Ja(b,g)):"Directory"==f&&d.push(g)});const e=d.reduce((g,f)=>{const {content:h}=a[f];f=J(h,Ja(b,f));return[...g,...f]},[]);return[...c,...e]};function Pa(a){if("object"!=typeof a)return!1;const b=a.re instanceof RegExp;a=-1!=["string","function"].indexOf(typeof a.replacement);return b&&a}const Qa=(a,b)=>{if(!(b instanceof Error))throw b;[,,a]=a.stack.split("\n",3);a=b.stack.indexOf(a);if(-1==a)throw b;a=b.stack.substr(0,a-1);const c=a.lastIndexOf("\n");b.stack=a.substr(0,c);throw b;};function Ra(a,b){function c(){return b.filter(Pa).reduce((d,{re:e,replacement:g})=>{if(this.j)return d;if("string"==typeof g)return d=d.replace(e,g);{let f;return d.replace(e,(h,...k)=>{f=Error();try{return this.j?h:g.call(this,h,...k)}catch(l){Qa(f,l)}})}},`${a}`)}c.b=()=>{c.j=!0};return c.call(c)};const Sa=a=>new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`,"g"),Ta=(a,b)=>`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`,Ua=()=>{var a={U:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\r?\n(?:([^\r\n][\s\S]+?\r?\n))?$/mg};return Object.keys(a).reduce((b,c)=>{{var d=a[c];const {getReplacement:e=Ta,getRegex:g=Sa}={},f=g(c);d={name:c,re:d,regExp:f,getReplacement:e,map:{},lastIndex:0}}return{...b,[c]:d}},{})},Va=a=>{var b=[];const c=a.map;return{re:a.regExp,replacement(d,
g);if(b.includes(h))return e;e=await e;g=await I(g);return{...e,[f]:g}},{});return{content:{...d,...c},type:"Directory"}}const J=(a,b)=>{let c=[],d=[];Object.keys(a).forEach(g=>{const {type:f}=a[g];"File"==f?c.push(Ja(b,g)):"Directory"==f&&d.push(g)});const e=d.reduce((g,f)=>{const {content:h}=a[f];f=J(h,Ja(b,f));return[...g,...f]},[]);return[...c,...e]};function Pa(a){if("object"!=typeof a)return!1;const b=a.re instanceof RegExp;a=-1!=["string","function"].indexOf(typeof a.replacement);return b&&a}const Qa=(a,b)=>{if(!(b instanceof Error))throw b;[,,a]=a.stack.split("\n",3);a=b.stack.indexOf(a);if(-1==a)throw b;a=b.stack.substr(0,a-1);const c=a.lastIndexOf("\n");b.stack=a.substr(0,c);throw b;};function Ra(a,b){function c(){return b.filter(Pa).reduce((d,{re:e,replacement:g})=>{if(this.l)return d;if("string"==typeof g)return d=d.replace(e,g);{let f;return d.replace(e,(h,...k)=>{f=Error();try{return this.l?h:g.call(this,h,...k)}catch(l){Qa(f,l)}})}},`${a}`)}c.b=()=>{c.l=!0};return c.call(c)};const Sa=a=>new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`,"g"),Ta=(a,b)=>`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`,Ua=()=>{var a={U:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\r?\n(?:([^\r\n][\s\S]+?\r?\n))?$/mg};return Object.keys(a).reduce((b,c)=>{{var d=a[c];const {getReplacement:e=Ta,getRegex:g=Sa}={},f=g(c);d={name:c,re:d,regExp:f,getReplacement:e,map:{},lastIndex:0}}return{...b,[c]:d}},{})},Va=a=>{var b=[];const c=a.map;return{re:a.regExp,replacement(d,
e){d=c[e];delete c[e];return Ra(d,Array.isArray(b)?b:[b])}}},Wa=a=>{const b=a.map,c=a.getReplacement,d=a.name;return{re:a.re,replacement(e){const g=a.lastIndex;b[g]=e;a.lastIndex+=1;return c(d,g)}}};async function Xa(a,b){return Ya(a,b)}
class Za extends A{constructor(a,b){super(b);this.g=(Array.isArray(a)?a:[a]).filter(Pa);this.j=!1;this.h=b}async replace(a,b){const c=new Za(this.g,this.h);b&&Object.assign(c,b);a=await Xa(c,a);c.j&&(this.j=!0);b&&Object.keys(b).forEach(d=>{b[d]=c[d]});return a}async reduce(a){return await this.g.reduce(async(b,{re:c,replacement:d})=>{b=await b;if(this.j)return b;if("string"==typeof d)b=b.replace(c,d);else{const e=[];let g;const f=b.replace(c,(h,...k)=>{g=Error();try{if(this.j)return e.length?e.push(Promise.resolve(h)):
h;const l=d.call(this,h,...k);l instanceof Promise&&e.push(l);return l}catch(l){Qa(g,l)}});if(e.length)try{const h=await Promise.all(e);b=b.replace(c,()=>h.shift())}catch(h){Qa(g,h)}else b=f}return b},`${a}`)}async _transform(a,b,c){try{const d=await this.reduce(a);this.push(d);c()}catch(d){a=Ea(d.stack),d.stack=a,c(d)}}}async function Ya(a,b){b instanceof wa?b.pipe(a):a.end(b);return await D(a)};function $a(){var a=ab;let b="";const c=new A({transform(d,e,g){let f;for(b+=d.toString();(d=a.exec(b))&&(c.push(d),f=d,a.global););f&&(b=b.slice(f.index+f[0].length));g()},objectMode:!0});return c};const bb=(a,b,c,d)=>{if(!a)throw Error("The name of the property is not given");a=`${d?`${d}.`:""}${a}`;if(null===b)return a;b=Number.isInteger(b)||[!0,!1,"null"].includes(b)||["number","boolean"].includes(c)?b:`"${b}"`;return`${a}=${b}`},cb=({number:a,N:b,boolean:c,type:d})=>b?"string":a?"number":c?"boolean":d?d:"*",db=a=>`${/[^\w\d._]/.test(a)?`(${a})`:a}|undefined`,K=a=>a?`/**${B}${a}${B} */${B}`:`/**${B} */${B}`,L=a=>` * @suppress {nonStandardJsDocs}${B}${a}`,eb=(a,b,c)=>{let d=a?`${a}.`:"";a=
a?"":"var ";b.includes("-")&&(b=`['${b}']`,d=d.replace(/\.$/,""));b=`${a}${d}${b}`;c&&(b+=` = ${c}`);return b},fb=a=>{const b=a.split(/\r?\n/).map(c=>{let d=Infinity;c.replace(/\S/,(e,g)=>{d=g});return d}).reduce((c,d)=>d<c?d:c,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},M=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return fb(a)},gb=(a,b,c=null)=>{const {async:d,"void":e,"return":g=e?"void":"",...f}=a;({args:a=""}=a);a||(a=b.map(({J:h,name:k})=>"this"==k?`${k}: ${h}`:k.startsWith("...")?
`...${h}`:h).join(","));b=g.replace(/\r?\n\s*/g," ");d&&b?b=`!Promise<${b}>`:d&&(b="!Promise");c=`function(${"constructor"==f.name?`new: ${c}, `:""}${a})`;b&&(c+=`: ${b}`);return{X:{...f,async:d,return:b},I:c}};function N(a,b){const c=a.example;c&&c.startsWith(".")&&b&&(a.example=La(Ia(b),c))}const O=(...a)=>a.join(B);function hb(a,b,c){const d=[];b.replace(a,(e,...g)=>{e=g.slice(0,g.length-2).reduce((f,h,k)=>{k=c[k];if(!k||void 0===h)return f;f[k]=h;return f},{});d.push(e)});return d};const ib=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),jb=new RegExp(`(?:\\s+((?:${ib.source}\\s*)*))`);const P=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return hb(new RegExp(`<(${a})${jb.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:c,a:d="",c:e=""})=>{d=d.replace(/\/$/,"").trim();d=kb(d);return{content:e,props:d,tag:c}})},kb=a=>hb(ib,a,["key","val","def","f"]).reduce((b,{key:c,val:d})=>{if(void 0===d)return b[c]=!0,b;b[c]="true"==d?!0:"false"==d?!1:/^\d+$/.test(d)?parseInt(d,10):d;return b},{});const lb=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b});
function mb(a){let b=0;const c=(e=1)=>a[b+e],d=(e=!0,g=[])=>{var f={};let h=a[b];if(["nullable","nonNullable"].includes(h)){if(!e)throw Error(`${h} not allowed after .`);f.nullable="nullable"===h;b++}h=a[b];if("("==h){b++;f={...d(!0,[]),...f};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return f}else if("{"==h){b++;g=f;for(e={};"}"!=a[b];){var k=a[b];b++;e[k]=null;if(":"==a[b]){b++;try{var l=d();e[k]=l}catch(m){throw m.message+=`(when parsing ${k} property)`,m;}}if("}"==a[b]){b++;
break}if(","!=a[b])throw Error(`Expecting , for record after ${k}`);b++}g.record=e;return f}if(["nonNullable","nullable"].includes(h))throw Error("Nullability already defined.");if(/[=),:.<>}|]/.test(h))throw Error(`Unexpected token ${h}.`);"|"!=a[b]&&(f.name=a[b],b++);if("function"==h){l=f;k={return:null,args:[]};if("("!=a[b])throw Error("Expecting opening (");b++;for(var n;")"!=a[b];){if(n&&"this"==a[b])throw Error("this must come first in function arguments");if(n&&"new"==a[b])throw Error("new must come first in function arguments");
if("this"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.this=d()}else if("new"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.new=d()}else if("."==a[b]&&"."==c()&&"."==c(2)){b++;b++;b++;n=d();if(")"!=a[b])throw Error("Variable args must come last");k.variableArgs=n}else n=d(),k.args.push(n),"="==a[b]&&(n.optional=!0,b++);n=!0;if(")"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between arguments");}b++;":"==a[b]&&(b++,n=d(),void 0==n.name&&n.nullable&&(n.name=""),
k.return=n);l.function=k}else if("<"==a[b]||(k="."==a[b]&&"<"==c())){b++;k&&b++;l=f;for(k=[];">"!=a[b];){n=d();k.push(n);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=k}for(;"."==a[b];){f.name+=".";b++;({name:l}=d(!1));if(!l)throw Error("Expected to see the name after .");f.name+=l}if("|"!=a[b]||!e)return f;for(g.push(f);"|"==a[b];)b++,f=d(!0,g),f.union!==g&&g.push(f);return{union:g}};return d()};function nb(a){a=lb(a);return mb(a)};function ob(a,b,{name:c,string:d,"boolean":e,opt:g,number:f,type:h},k){if(!c)throw Error("Argument does not have a name.");a.name=c;b&&(a.description=M(b));b=cb({number:f,N:d,boolean:e,type:h});k&&(b=b.replace(new RegExp(`([!?])?${k}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),g=!0);a.type=b;g&&(a.optional=!0)}class pb{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get J(){return this.optional?`${this.type}=`:this.type}}
const qb=(a,b)=>{let c=a.lastIndexOf("</arg>"),d=a;var e=[];-1!=c&&(c+=6,e=a.slice(0,c),d=a.slice(c),e=P("arg",e),e=e.map(({content:g,props:f})=>{const h=new pb;ob(h,g,f,b);return h}));return{K:d,G:e}};function S(a){if(""==a.name&&a.nullable)return"?";var b="";a.nullable?b="?":!1===a.nullable&&(b="!");if(a.function){b+=a.name+"(";const d=[];if(a.function.this){var c="this: "+S(a.function.this);d.push(c)}a.function.new&&(c="new: "+S(a.function.new),d.push(c));a.function.args.forEach(e=>{let g=S(e);e.optional&&(g+="=");d.push(g)});a.function.variableArgs&&(c="..."+S(a.function.variableArgs),d.push(c));c=d.join(", ");b+=c+")";a.function.return&&(b+=": "+S(a.function.return))}else if(a.record)b+="{ ",
c=Object.keys(a.record).map(d=>{var e=a.record[d];if(!e)return d;e=S(e);return`${d}: ${e}`}),b+=c.join(", "),b+=" }";else if(a.application){if("Promise"==a.name&&!a.application.some(d=>"void"!=d.name))return b+"Promise";b+=a.name+"<";c=a.application.map(d=>S(d));b+=c.join(", ");b+=">"}else a.union?(b+="(",c=a.union.map(d=>S(d)),b+=c.join("|"),b+=")"):b+="any"==a.name?"*":a.name;return b};const T=(a,b=!1)=>a.split("\n").map((c,d)=>{if(b&&!d)return c;d=" *";c.length&&"\r"!=c&&(d+=" ");return d+c}).join("\n"),rb=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((c,d)=>{[{length:d=0}={}]=/^\s*/.exec(d)||[];return d<c?d:c},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")};
function sb(a,b=""){const c=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(d=>{let e=d=ua(d,"utf8");if(d=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(d))[,d]=d,e=rb(d);c.forEach(g=>{const [f,h]=g.split(/\s*=>\s*/);e=e.replace(`'${f}'`,`'${h}'`);e=e.replace(`"${f}"`,`"${h}"`)});return e=e.replace(/@/g,"\uff20")})}
function tb(a,{R:b=!0,V:c=!0}={}){const d=[];b&&d.push(" * @example");a.forEach(e=>{let g=[],f=[],h="",k;e=e.split(B).reduce((l,n)=>{n.startsWith("///")?(k="comment",g.push(n)):(k="block",f.push(n));h||(h=k);k!=h&&("block"==k?(l.push(g.join(B)),g=[]):(l.push(f.join(B)),f=[]),h=k);return l},[]);g.length?e.push(g.join(B)):f.length&&e.push(f.join(B));e=e.reduce((l,n)=>{n.startsWith("///")?(n=n.replace(/^\/\/\/\s+/gm,""),l.push(...n.split(/\r?\n/))):(l.push("```js"),l.push(...n.split(/\r?\n/)),l.push("```"));
return l},[]);c&&(e=e.map(l=>T(l)));d.push(...e)});return d}function ub(a,b,c=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(c,"$1")),a.type=a.type.replace(c,"$1"))}function vb(a,b=!1){return b?a.closureType:a.isParsedFunction?a.toTypeScriptFunction(S):a.type}
function wb(a,b=null,c=!1,d=!1){if(!a.name)throw Error("Property does not have a name. Has it been constructed using fromXML?");b=bb(a.name,a.optional?a.default:null,a.type,b);b=a.optional?`[${b}]`:b;var e=a.o;e=e?` ${e}`:"";c=`{${vb(a,c)}} ${b}${e}`;d&&(a=tb(a.examples,{R:!1,V:!1}).join(B).replace(/\*/g,"\uff0a"))&&(c+=`${B}${a}`);return c}function xb(a,b=!1){a=wb(a,null,b,!0);return` * @prop ${T(a,!0)}`}
function yb(a,b){const c=[],{function:{args:d,return:e,variableArgs:g,this:f}}=a.parsed;d.map(h=>S(h)).forEach((h,k)=>{const {optional:l}=d[k],{name:n=`arg${k}`,description:m}=a.args[k]||{};c.push(` * @param {${h}${l?"=":""}} ${l?`[${n}]`:n}${m?` ${m}`:""}`)});if(g){const {O:h,Z:k}=zb(a.args||[]),l=[h,k].filter(Boolean).join(" ");c.push(` * @param {...${S(g)}} ${l}`)}f&&c.push(` * @this {${S(f)}}`);if(e&&"void"!=e.name){if(b&&a.v)return c;b=S(e);c.push(` * @return {${b}}`)}return c}
function Ab(a){if(a.isParsedFunction){const {function:{args:b,variableArgs:c}}=a.parsed,d=b.map((e,g)=>{({name:e=`arg${g}`}=a.l[g]||{});return e});if(c){const {O:e}=zb(a.args||[]);d.push(`...${e}`)}return` = function(${d.join(", ")}) {}`}return a.type.startsWith("function(")?" = function() {}":""}function Bb(a,b){const c=Object.assign(Object.create(Object.getPrototypeOf(a)),a);c.description=`An alias for \`${a.name}\`.`;c.name=b;return c}
class Cb{constructor(a=null){this.h=this.description=this.name=null;this.closureType="";this.default=this.f=null;this.optional=!1;this.aliases=[];this.u=!1;this.parsed=null;this.args=a;this.g=!1;this.examples=[];this.v=!1}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:c,return:d,this:e,variableArgs:g}}=this.parsed;b&&(d=b);var f=c.map(k=>a(k)).map((k,l)=>{const {optional:n}=c[l];let {name:m=`arg${l}`,optional:q=n}=this.l[l]||{};return`${`${m}${q?
"?":""}`}: ${k}`});if(e){var h=a(e);f.unshift(`this: ${h}`)}if(g){h=a(g);let k="...args";try{k=`${this.args[this.args.length-1].name}`}catch(l){}f.push(`${k}: ${h}[]`)}f=f.join(", ");h=d?a(d):"?";f=`(${f}) => ${h}`;b&&(f="new "+f);return f}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:c,"boolean":d,opt:e,number:g,type:f,"default":h,closure:k,alias:l,aliases:n,example:m,"example-override":q="",noParams:r,"static":t,initial:u,"template-no-return":v}){if(!b)throw Error("Property does not have a name.");
this.name=b;a&&(this.description=M(a));a=cb({number:g,N:c,boolean:d,type:f});r&&(this.u=r);k&&(this.f=k);this.type=a;void 0!==h?this.default=h:void 0!==u&&(this.default=u);if(e||void 0!==h)this.optional=!0;l&&(this.aliases=[l]);n&&(this.aliases=n.split(/\s*,\s*/));t&&(this.g=!0);m&&(this.examples=sb(m,q));v&&(this.v=!0)}get type(){return this.h||"*"}set type(a){this.h=a||null;this.closureType=this.f||this.h||"";if(!this.u)try{this.parsed=nb(this.closureType),this.isParsedFunction&&!this.args&&(this.args=
[])}catch(b){this.parsed=null}}get o(){let a=this.description||"";return`${a}${this.hasDefault?`${/``` */.test(this.description)?B:a?" ":""}Default \`${this.default}\`.`:""}`}get l(){var a=this.args;this.args&&this.args[0]&&"this"==this.args[0].name&&([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}m(a="",b=!1){let c=[];var d=this.o;d&&(d=T(d),c.push(...d.split(B)));!this.optional&&this.isParsedFunction?(d=yb(this,b),c.push(...d)):c.push(` * @type {${this.optional?
db(this.closureType):this.closureType}}`);b&&this.examples.length&&(b=tb(this.examples),c.push(...b));a&&(c=c.map(e=>`${a}${e}`));return c.join(B)}D(a,b="",c=!1){a=wb(this,a,c);const [d,...e]=a.split(B);return[`@param ${d}`,...e].map(g=>`${b} * ${g}`).join(B)}}const zb=a=>{let b="args";const {name:c="",description:d}=a[a.length-1]||{};c.startsWith("...")&&(b=c.replace("...",""));return{O:b,Z:d}};class U extends Cb{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function Db(a,b,c,d){var e=P("prop",a).map(({content:k,props:l})=>{const n=new Cb;N(l,c);n.b(k,l);return n});a=P(["function","fn","static"],a).map(({content:k,props:l,tag:n})=>{n="static"==n;const {K:m,G:q}=qb(k,b);k=new U(q);const {X:r,I:t}=gb(l,q,d);r.type=t;N(r,c);k.b(m,r);n&&(k.g=!0);return k});e=[...e,...a];const {H:g,M:f,n:h}=e.reduce((k,l)=>{l.isConstructor?k.H.push(l):l.static?k.M.push(l):k.n.push(l);return k},{H:[],M:[],n:[]});return{constructor:g[0]||null,properties:[...g,...f,...h]}};const Eb=(a,b,c={})=>{let d;if("object"==typeof b)d=b;else try{(d=nb(b))||console.log("Could not parse %s",b)}catch(e){console.log("Could not parse %s",b),console.error(e.message)}return d?V(d,a,c):b},V=(a,b,c={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:d=!0}=c;let e="";var g="";a.nullable?g="?":!1===a.nullable&&(g="!");if(a.function){e=e+g+(a.name+"(");const f=[];a.function.this&&(d="this: "+V(a.function.this,b,c),f.push(d));a.function.new&&(d="new: "+V(a.function.new,b,c),f.push(d));
a.function.args.forEach(h=>{let k=V(h,b,c);h.optional&&(k+="=");f.push(k)});a.function.variableArgs&&(d="..."+V(a.function.variableArgs,b,c),f.push(d));d=f.join(", ");e+=d+")";a.function.return&&(e+=": "+V(a.function.return,b,c))}else a.record?(e+="{ ",d=Object.keys(a.record).map(f=>{var h=a.record[f];if(!h)return f;h=V(h,b,c);return`${f}: ${h}`}),e+=d.join(", "),e+=" }"):a.application?(e+=Fb(a.name,b,g,c)+"&lt;",d=a.application.map(f=>V(f,b,c)),e+=d.join(", "),e+="&gt;"):a.union?(e=e+g+"(",g=a.union.map(f=>
V(f,b,c)),e+=g.join(d?" \\| ":" | "),e+=")"):e+=Fb("any"==a.name?"*":a.name,b,g,c);return e},Fb=(a,b,c="",d={})=>{const {flatten:e=!1,nameProcess:g,link:f=({link:l})=>`#${l}`}=d;d=Gb(b,a);c=`${c}${a}`;if(!d)return c;let {link:h,type:{description:k}}=d;e&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(h=b.link),!k&&b.description&&(k=b.description),"function"==typeof e&&e(a));d.link==h&&(h=f(d));b=g?g(c):c;return k?`<a href="${h}" title="${k.replace(/"/g,"&quot;")}">${b}</a>`:`[${b}](${h})`},Gb=(a,b)=>
{a=a.filter(({fullName:d})=>d==b);if(a.length){var c=a.find(({import:d})=>d||!1);a=a.find(({import:d})=>!d)||c;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/&nbsp;/g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function Hb(a,b=[],c=[],d={}){const {narrow:e=!1,preprocessDesc:g}=d;if(!b.length)return"";const f=a.isConstructor||a.isInterface,h=b.some(({hasDefault:m})=>m),k={escapePipe:!e,...d};let l;const n=m=>Eb(c,m,{...k,nameProcess:d.nameProcess?q=>d.nameProcess(q,l):void 0});a=b.map((m,q)=>{l=0<(q+1)%2;q=m.args&&m.isParsedFunction?m.toTypeScriptFunction(n):n(m.parsed||m.type);const r=f||m.optional?m.name:`${m.name}*`,t=m.hasDefault?`\`${m.default}\``:"-",u=g?g(m.description):m.description;return{prop:m,
typeName:q,name:r,de:Ib(u,!e),d:t,aa:l}});if(e)return{props:a,anyHaveDefault:h,constr:f};a=a.map(({name:m,typeName:q,de:r,d:t,prop:u})=>[u.optional?m:`__${m}__`,`<em>${q}</em>`,r,...h?[t]:[]]);b=["Name",...e?["Type & Description"]:["Type","Description"],...h?[f?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const Ib=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"&lt;").replace(/>/g,"&gt;")};const Jb=(a,b,c={})=>{function d(e){e.replace(/^!?/,"");return`\`${e}\``}return a.split(/,\s*/).map(e=>Eb(b,e,{flatten:!0,...c,nameProcess:c.nameProcess?g=>{g=c.nameProcess(g);return/[_*~>]/.test(g)?`<code>${g}</code>`:d(g)}:d})).join(", ")};function Kb(a){var b=a.h();b=K(b.join(B));b+=eb(a.namespace,a.name,Lb(a));const c=a.properties.reduce((d,e)=>{d.push(e);const g=e.aliases.map(f=>Bb(e,f));d.push(...g);return d},[]).filter(d=>d instanceof U&&d.isConstructor?!1:!0).map(d=>{let e=d.m();e=K(e);e+=eb(`${a.fullName}${d.static?"":".prototype"}`,d.name);return e+=Ab(d)});return[b,...c].join(B)}function Mb(a,b=!1){const c=`${a.extends?"$":""}${a.name}`;return b?`${a.ns}${c}`:c}
function Nb(a,b=!1,c=!1,d=b){d=` * @typedef {${(b?a.closureType:a.type)||a.u()}}${` ${Mb(a,d)}${a.l}`}`;a=(a.properties?a.properties.reduce((e,g)=>{if(g.g)return e;e.push(g);const f=g.aliases.map(h=>Bb(g,h));e.push(...f);return e},[]):[]).filter(e=>e instanceof U?!e.isConstructor:!0).map(e=>xb(e,b));a=[d,...a].join(B);b&&!c&&(a=L(a));return a=K(a)}function Lb(a){return a.args?`function(${a.args.filter(({name:b})=>"this"!=b).map(({name:b})=>b).join(", ")}) {}`:null}
class W{constructor(){this.name="";this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.extends=null;this.examples=[];this.file=null}get import(){return!1}b(a,{name:b,type:c,desc:d,noToc:e,spread:g,noExpand:f,link:h,closure:k,constructor:l,"extends":n,"interface":m,record:q,example:r,"example-override":t},u,v=null){if(!b)throw Error("Type does not have a name.");
this.name=b;c&&(this.type=c);k?this.closureType=k:this.closureType=this.type;d&&(this.description=M(d));this.noToc=!!e;this.spread=!!g;this.noExpand=!!f;h&&(this.link=h);!0===l&&(this.isConstructor=l);!0===m&&(this.isInterface=m);!0===q&&(this.isRecord=q);n&&(this.extends=n);u&&(this.namespace=u);if(a){const {properties:w,constructor:y}=Db(a,v,this.file,this.fullName);y&&(this.args=y.args);this.properties=w}r&&(a={example:r},N(a,this.file),this.examples=sb(a.example,t))}get L(){return this.isConstructor||
this.isInterface||this.isRecord}m(){let a;this.closureType?a=` * @typedef {${this.closureType}}`:this.L||(a=` * @typedef {${Ob(this.properties,!0)}}`);return a?(this.description&&(a=` * ${this.description}${B}${a}`),a=K(a),a+=eb(this.namespace,this.name)):Kb(this)}u(){return"Object"}o(a,b=new RegExp(`([!?])?${a}\\.`,"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get l(){return`${this.tag?` \`\uff20${this.tag}\``:""}${this.description?
` ${this.description}`:""}`}g(a=!1,b=!1,c=a){const d=!!this.extends,e=Nb(this,a,b,c),g=[];if(this.namespace&&a){var f=` * @typedef {${this.fullName}} ${this.name}${this.l}`;a&&!b&&(f=L(f));f=K(f);g.push(f)}else this.namespace&&c&&(f=` * @typedef {${this.fullName}} ${this.name}${this.l}`,f=K(f),g.push(f));d&&(c=` * @typedef {${Mb(this,c)} & ${this.extends.split(/,\s*/).join(" & ")}} ${c?this.fullName:this.name}${this.l}`,a&&!b&&(c=L(c)),c=K(c),g.push(c));g.push(e);return g.join("")}get Y(){const a=
class Za extends A{constructor(a,b){super(b);this.g=(Array.isArray(a)?a:[a]).filter(Pa);this.l=!1;this.h=b}async replace(a,b){const c=new Za(this.g,this.h);b&&Object.assign(c,b);a=await Xa(c,a);c.l&&(this.l=!0);b&&Object.keys(b).forEach(d=>{b[d]=c[d]});return a}async reduce(a){return await this.g.reduce(async(b,{re:c,replacement:d})=>{b=await b;if(this.l)return b;if("string"==typeof d)b=b.replace(c,d);else{const e=[];let g;const f=b.replace(c,(h,...k)=>{g=Error();try{if(this.l)return e.length?e.push(Promise.resolve(h)):
h;const l=d.call(this,h,...k);l instanceof Promise&&e.push(l);return l}catch(l){Qa(g,l)}});if(e.length)try{const h=await Promise.all(e);b=b.replace(c,()=>h.shift())}catch(h){Qa(g,h)}else b=f}return b},`${a}`)}async _transform(a,b,c){try{const d=await this.reduce(a);this.push(d);c()}catch(d){a=Ea(d.stack),d.stack=a,c(d)}}}async function Ya(a,b){b instanceof wa?b.pipe(a):a.end(b);return await D(a)};function $a(){var a=ab;let b="";const c=new A({transform(d,e,g){let f;for(b+=d.toString();(d=a.exec(b))&&(c.push(d),f=d,a.global););f&&(b=b.slice(f.index+f[0].length));g()},objectMode:!0});return c};const cb=(a,b,c,d)=>{if(!a)throw Error("The name of the property is not given");a=`${d?`${d}.`:""}${a}`;if(null===b)return a;b=bb(c,b);return`${a}=${b}`},bb=(a,b,c='"')=>Number.isInteger(b)||[!0,!1,"null"].includes(b)||["number","boolean"].includes(a)?b:`${c}${b}${c}`,db=({number:a,N:b,boolean:c,type:d})=>b?"string":a?"number":c?"boolean":d?d:"*",eb=a=>`${/[^\w\d._]/.test(a)?`(${a})`:a}|undefined`,K=a=>a?`/**${B}${a}${B} */${B}`:`/**${B} */${B}`,L=a=>` * @suppress {nonStandardJsDocs}${B}${a}`,fb=
(a,b,c)=>{let d=a?`${a}.`:"";a=a?"":"var ";b.includes("-")&&(b=`['${b}']`,d=d.replace(/\.$/,""));b=`${a}${d}${b}`;c&&(b+=` = ${c}`);return b},gb=a=>{const b=a.split(/\r?\n/).map(c=>{let d=Infinity;c.replace(/\S/,(e,g)=>{d=g});return d}).reduce((c,d)=>d<c?d:c,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},M=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return gb(a)},hb=(a,b,c=null)=>{const {async:d,"void":e,"return":g=e?"void":"",...f}=a;({args:a=""}=a);a||(a=b.map(({J:h,name:k})=>
"this"==k?`${k}: ${h}`:k.startsWith("...")?`...${h}`:h).join(","));b=g.replace(/\r?\n\s*/g," ");d&&b?b=`!Promise<${b}>`:d&&(b="!Promise");c=`function(${"constructor"==f.name?`new: ${c}, `:""}${a})`;b&&(c+=`: ${b}`);return{X:{...f,async:d,return:b},I:c}};function N(a,b){const c=a.example;c&&c.startsWith(".")&&b&&(a.example=La(Ia(b),c))}const O=(...a)=>a.join(B);function ib(a,b,c){const d=[];b.replace(a,(e,...g)=>{e=g.slice(0,g.length-2).reduce((f,h,k)=>{k=c[k];if(!k||void 0===h)return f;f[k]=h;return f},{});d.push(e)});return d};const jb=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),kb=new RegExp(`(?:\\s+((?:${jb.source}\\s*)*))`);const P=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return ib(new RegExp(`<(${a})${kb.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:c,a:d="",c:e=""})=>{d=d.replace(/\/$/,"").trim();d=lb(d);return{content:e,props:d,tag:c}})},lb=a=>ib(jb,a,["key","val","def","f"]).reduce((b,{key:c,val:d})=>{if(void 0===d)return b[c]=!0,b;b[c]="true"==d?!0:"false"==d?!1:/^\d+$/.test(d)?parseInt(d,10):d;return b},{});const mb=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b});
function nb(a){let b=0;const c=(e=1)=>a[b+e],d=(e=!0,g=[])=>{var f={};let h=a[b];if(["nullable","nonNullable"].includes(h)){if(!e)throw Error(`${h} not allowed after .`);f.nullable="nullable"===h;b++}h=a[b];if("("==h){b++;f={...d(!0,[]),...f};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return f}else if("{"==h){b++;g=f;for(e={};"}"!=a[b];){var k=a[b];b++;e[k]=null;if(":"==a[b]){b++;try{var l=d();e[k]=l}catch(n){throw n.message+=`(when parsing ${k} property)`,n;}}if("}"==a[b]){b++;
break}if(","!=a[b])throw Error(`Expecting , for record after ${k}`);b++}g.record=e;return f}if(["nonNullable","nullable"].includes(h))throw Error("Nullability already defined.");if(/[=),:.<>}|]/.test(h))throw Error(`Unexpected token ${h}.`);"|"!=a[b]&&(f.name=a[b],b++);if("function"==h){l=f;k={return:null,args:[]};if("("!=a[b])throw Error("Expecting opening (");b++;for(var m;")"!=a[b];){if(m&&"this"==a[b])throw Error("this must come first in function arguments");if(m&&"new"==a[b])throw Error("new must come first in function arguments");
if("this"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.this=d()}else if("new"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.new=d()}else if("."==a[b]&&"."==c()&&"."==c(2)){b++;b++;b++;m=d();if(")"!=a[b])throw Error("Variable args must come last");k.variableArgs=m}else m=d(),k.args.push(m),"="==a[b]&&(m.optional=!0,b++);m=!0;if(")"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between arguments");}b++;":"==a[b]&&(b++,m=d(),void 0==m.name&&m.nullable&&(m.name=""),
k.return=m);l.function=k}else if("<"==a[b]||(k="."==a[b]&&"<"==c())){b++;k&&b++;l=f;for(k=[];">"!=a[b];){m=d();k.push(m);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=k}for(;"."==a[b];){f.name+=".";b++;({name:l}=d(!1));if(!l)throw Error("Expected to see the name after .");f.name+=l}if("|"!=a[b]||!e)return f;for(g.push(f);"|"==a[b];)b++,f=d(!0,g),f.union!==g&&g.push(f);return{union:g}};return d()};function ob(a){a=mb(a);return nb(a)};function pb(a,b,{name:c,string:d,"boolean":e,opt:g,number:f,type:h},k){if(!c)throw Error("Argument does not have a name.");a.name=c;b&&(a.description=M(b));b=db({number:f,N:d,boolean:e,type:h});k&&(b=b.replace(new RegExp(`([!?])?${k}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),g=!0);a.type=b;g&&(a.optional=!0)}class qb{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get J(){return this.optional?`${this.type}=`:this.type}}
const rb=(a,b)=>{let c=a.lastIndexOf("</arg>"),d=a;var e=[];-1!=c&&(c+=6,e=a.slice(0,c),d=a.slice(c),e=P("arg",e),e=e.map(({content:g,props:f})=>{const h=new qb;pb(h,g,f,b);return h}));return{K:d,G:e}};function S(a){if(""==a.name&&a.nullable)return"?";var b="";a.nullable?b="?":!1===a.nullable&&(b="!");if(a.function){b+=a.name+"(";const d=[];if(a.function.this){var c="this: "+S(a.function.this);d.push(c)}a.function.new&&(c="new: "+S(a.function.new),d.push(c));a.function.args.forEach(e=>{let g=S(e);e.optional&&(g+="=");d.push(g)});a.function.variableArgs&&(c="..."+S(a.function.variableArgs),d.push(c));c=d.join(", ");b+=c+")";a.function.return&&(b+=": "+S(a.function.return))}else if(a.record)b+="{ ",
c=Object.keys(a.record).map(d=>{var e=a.record[d];if(!e)return d;e=S(e);return`${d}: ${e}`}),b+=c.join(", "),b+=" }";else if(a.application){if("Promise"==a.name&&!a.application.some(d=>"void"!=d.name))return b+"Promise";b+=a.name+"<";c=a.application.map(d=>S(d));b+=c.join(", ");b+=">"}else a.union?(b+="(",c=a.union.map(d=>S(d)),b+=c.join("|"),b+=")"):b+="any"==a.name?"*":a.name;return b};const T=(a,b=!1)=>a.split("\n").map((c,d)=>{if(b&&!d)return c;d=" *";c.length&&"\r"!=c&&(d+=" ");return d+c}).join("\n"),sb=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((c,d)=>{[{length:d=0}={}]=/^\s*/.exec(d)||[];return d<c?d:c},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")};
function tb(a,b=""){const c=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(d=>{let e=d=ua(d,"utf8");if(d=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(d))[,d]=d,e=sb(d);c.forEach(g=>{const [f,h]=g.split(/\s*=>\s*/);e=e.replace(`'${f}'`,`'${h}'`);e=e.replace(`"${f}"`,`"${h}"`)});return e=e.replace(/@/g,"\uff20")})}
function ub(a,{R:b=!0,V:c=!0}={}){const d=[];b&&d.push(" * @example");a.forEach(e=>{let g=[],f=[],h="",k;e=e.split(B).reduce((l,m)=>{m.startsWith("///")?(k="comment",g.push(m)):(k="block",f.push(m));h||(h=k);k!=h&&("block"==k?(l.push(g.join(B)),g=[]):(l.push(f.join(B)),f=[]),h=k);return l},[]);g.length?e.push(g.join(B)):f.length&&e.push(f.join(B));e=e.reduce((l,m)=>{m.startsWith("///")?(m=m.replace(/^\/\/\/\s+/gm,""),l.push(...m.split(/\r?\n/))):(l.push("```js"),l.push(...m.split(/\r?\n/)),l.push("```"));
return l},[]);c&&(e=e.map(l=>T(l)));d.push(...e)});return d}function vb(a,b,c=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(c,"$1")),a.type=a.type.replace(c,"$1"))}function wb(a,b=!1){return b?a.closureType:a.isParsedFunction?a.toTypeScriptFunction(S):a.type}
function xb(a,b=null,c=!1,d=!1){if(!a.name)throw Error("Property does not have a name. Has it been constructed using fromXML?");b=cb(a.name,a.optional?a.default:null,a.type,b);b=a.optional?`[${b}]`:b;var e=a.o;e=e?` ${e}`:"";c=`{${wb(a,c)}} ${b}${e}`;d&&(a=ub(a.examples,{R:!1,V:!1}).join(B).replace(/\*/g,"\uff0a"))&&(c+=`${B}${a}`);return c}function yb(a,b=!1){a=xb(a,null,b,!0);return` * @prop ${T(a,!0)}`}
function zb(a,b){const c=[],{function:{args:d,return:e,variableArgs:g,this:f}}=a.parsed;d.map(h=>S(h)).forEach((h,k)=>{const {optional:l}=d[k],{name:m=`arg${k}`,description:n}=a.args[k]||{};c.push(` * @param {${h}${l?"=":""}} ${l?`[${m}]`:m}${n?` ${n}`:""}`)});if(g){const {O:h,Z:k}=Ab(a.args||[]),l=[h,k].filter(Boolean).join(" ");c.push(` * @param {...${S(g)}} ${l}`)}f&&c.push(` * @this {${S(f)}}`);if(e&&"void"!=e.name){if(b&&a.v)return c;b=S(e);c.push(` * @return {${b}}`)}return c}
function Bb(a){if(a.isParsedFunction){const {function:{args:b,variableArgs:c}}=a.parsed,d=b.map((e,g)=>{({name:e=`arg${g}`}=a.m[g]||{});return e});if(c){const {O:e}=Ab(a.args||[]);d.push(`...${e}`)}return` = function(${d.join(", ")}) {}`}return a.type.startsWith("function(")?" = function() {}":""}function Cb(a,b){const c=Object.assign(Object.create(Object.getPrototypeOf(a)),a);c.description=`An alias for \`${a.name}\`.`;c.name=b;return c}
class Db{constructor(a=null){this.h=this.description=this.name=null;this.closureType="";this.default=this.f=null;this.optional=!1;this.aliases=[];this.u=!1;this.parsed=null;this.args=a;this.g=!1;this.examples=[];this.v=!1}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:c,return:d,this:e,variableArgs:g}}=this.parsed;b&&(d=b);var f=c.map(k=>a(k)).map((k,l)=>{const {optional:m}=c[l];let {name:n=`arg${l}`,optional:p=m}=this.m[l]||{};return`${`${n}${p?
"?":""}`}: ${k}`});if(e){var h=a(e);f.unshift(`this: ${h}`)}if(g){h=a(g);let k="...args";try{k=`${this.args[this.args.length-1].name}`}catch(l){}f.push(`${k}: ${h}[]`)}f=f.join(", ");h=d?a(d):"?";f=`(${f}) => ${h}`;b&&(f="new "+f);return f}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:c,"boolean":d,opt:e,number:g,type:f,"default":h,closure:k,alias:l,aliases:m,example:n,"example-override":p="",noParams:q,"static":t,initial:u,"template-no-return":v}){if(!b)throw Error("Property does not have a name.");
this.name=b;a&&(this.description=M(a));a=db({number:g,N:c,boolean:d,type:f});q&&(this.u=q);k&&(this.f=k);this.type=a;void 0!==h?this.default=h:void 0!==u&&(this.default=u);if(e||void 0!==h)this.optional=!0;l&&(this.aliases=[l]);m&&(this.aliases=m.split(/\s*,\s*/));t&&(this.g=!0);n&&(this.examples=tb(n,p));v&&(this.v=!0)}get type(){return this.h||"*"}set type(a){this.h=a||null;this.closureType=this.f||this.h||"";if(!this.u)try{this.parsed=ob(this.closureType),this.isParsedFunction&&!this.args&&(this.args=
[])}catch(b){this.parsed=null}}get o(){let a=this.description||"";return`${a}${this.hasDefault?`${/``` */.test(this.description)?B:a?" ":""}Default \`${this.default}\`.`:""}`}get m(){var a=this.args;this.args&&this.args[0]&&"this"==this.args[0].name&&([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}j(a="",b=!1){let c=[];var d=this.o;d&&(d=T(d),c.push(...d.split(B)));!this.optional&&this.isParsedFunction?(d=zb(this,b),c.push(...d)):c.push(` * @type {${this.optional?
eb(this.closureType):this.closureType}}`);b&&this.examples.length&&(b=ub(this.examples),c.push(...b));a&&(c=c.map(e=>`${a}${e}`));return c.join(B)}D(a,b="",c=!1){a=xb(this,a,c);const [d,...e]=a.split(B);return[`@param ${d}`,...e].map(g=>`${b} * ${g}`).join(B)}}const Ab=a=>{let b="args";const {name:c="",description:d}=a[a.length-1]||{};c.startsWith("...")&&(b=c.replace("...",""));return{O:b,Z:d}};class U extends Db{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function Eb(a,b,c,d){var e=P("prop",a).map(({content:k,props:l})=>{const m=new Db;N(l,c);m.b(k,l);return m});a=P(["function","fn","static"],a).map(({content:k,props:l,tag:m})=>{m="static"==m;const {K:n,G:p}=rb(k,b);k=new U(p);const {X:q,I:t}=hb(l,p,d);q.type=t;N(q,c);k.b(n,q);m&&(k.g=!0);return k});e=[...e,...a];const {H:g,M:f,n:h}=e.reduce((k,l)=>{l.isConstructor?k.H.push(l):l.static?k.M.push(l):k.n.push(l);return k},{H:[],M:[],n:[]});return{constructor:g[0]||null,properties:[...g,...f,...h]}};const Fb=(a,b,c={})=>{let d;if("object"==typeof b)d=b;else try{(d=ob(b))||console.log("Could not parse %s",b)}catch(e){console.log("Could not parse %s",b),console.error(e.message)}return d?V(d,a,c):b},V=(a,b,c={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:d=!0}=c;let e="";var g="";a.nullable?g="?":!1===a.nullable&&(g="!");if(a.function){e=e+g+(a.name+"(");const f=[];a.function.this&&(d="this: "+V(a.function.this,b,c),f.push(d));a.function.new&&(d="new: "+V(a.function.new,b,c),f.push(d));
a.function.args.forEach(h=>{let k=V(h,b,c);h.optional&&(k+="=");f.push(k)});a.function.variableArgs&&(d="..."+V(a.function.variableArgs,b,c),f.push(d));d=f.join(", ");e+=d+")";a.function.return&&(e+=": "+V(a.function.return,b,c))}else a.record?(e+="{ ",d=Object.keys(a.record).map(f=>{var h=a.record[f];if(!h)return f;h=V(h,b,c);return`${f}: ${h}`}),e+=d.join(", "),e+=" }"):a.application?(e+=Gb(a.name,b,g,c)+"&lt;",d=a.application.map(f=>V(f,b,c)),e+=d.join(", "),e+="&gt;"):a.union?(e=e+g+"(",g=a.union.map(f=>
V(f,b,c)),e+=g.join(d?" \\| ":" | "),e+=")"):e+=Gb("any"==a.name?"*":a.name,b,g,c);return e},Gb=(a,b,c="",d={})=>{const {flatten:e=!1,nameProcess:g,link:f=({link:l})=>`#${l}`}=d;d=Hb(b,a);c=`${c}${a}`;if(!d)return c;let {link:h,type:{description:k}}=d;e&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(h=b.link),!k&&b.description&&(k=b.description),"function"==typeof e&&e(a));d.link==h&&(h=f(d));b=g?g(c):c;return k?`<a href="${h}" title="${k.replace(/"/g,"&quot;")}">${b}</a>`:`[${b}](${h})`},Hb=(a,b)=>
{a=a.filter(({fullName:d})=>d==b);if(a.length){var c=a.find(({import:d})=>d||!1);a=a.find(({import:d})=>!d)||c;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/&nbsp;/g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function Ib(a,b=[],c=[],d={}){const {narrow:e=!1,preprocessDesc:g}=d;if(!b.length)return"";const f=a.isConstructor||a.isInterface,h=b.some(({hasDefault:n})=>n),k={escapePipe:!e,...d};let l;const m=n=>Fb(c,n,{...k,nameProcess:d.nameProcess?p=>d.nameProcess(p,l):void 0});a=b.map((n,p)=>{l=0<(p+1)%2;p=n.args&&n.isParsedFunction?n.toTypeScriptFunction(m):m(n.parsed||n.type);const q=f||n.optional?n.name:`${n.name}*`,t=n.hasDefault?`\`${n.default}\``:"-",u=g?g(n.description):n.description;return{prop:n,
typeName:p,name:q,de:Jb(u,!e),d:t,aa:l}});if(e)return{props:a,anyHaveDefault:h,constr:f};a=a.map(({name:n,typeName:p,de:q,d:t,prop:u})=>[u.optional?n:`__${n}__`,`<em>${p}</em>`,q,...h?[t]:[]]);b=["Name",...e?["Type & Description"]:["Type","Description"],...h?[f?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const Jb=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"&lt;").replace(/>/g,"&gt;")};const Kb=(a,b,c={})=>{function d(e){e.replace(/^!?/,"");return`\`${e}\``}return a.split(/,\s*/).map(e=>Fb(b,e,{flatten:!0,...c,nameProcess:c.nameProcess?g=>{g=c.nameProcess(g);return/[_*~>]/.test(g)?`<code>${g}</code>`:d(g)}:d})).join(", ")};function Lb(a){var b=a.h();b=K(b.join(B));b+=fb(a.namespace,a.name,Mb(a));const c=a.properties.reduce((d,e)=>{d.push(e);const g=e.aliases.map(f=>Cb(e,f));d.push(...g);return d},[]).filter(d=>d instanceof U&&d.isConstructor?!1:!0).map(d=>{let e=d.j();e=K(e);e+=fb(`${a.fullName}${d.static?"":".prototype"}`,d.name);return e+=Bb(d)});return[b,...c].join(B)}function Nb(a,b=!1){const c=`${a.extends?"$":""}${a.name}`;return b?`${a.ns}${c}`:c}
function Ob(a,b=!1,c=!1,d=b){d=` * @typedef {${(b?a.closureType:a.type)||a.u()}}${` ${Nb(a,d)}${a.m}`}`;a=(a.properties?a.properties.reduce((e,g)=>{if(g.g)return e;e.push(g);const f=g.aliases.map(h=>Cb(g,h));e.push(...f);return e},[]):[]).filter(e=>e instanceof U?!e.isConstructor:!0).map(e=>yb(e,b));a=[d,...a].join(B);b&&!c&&(a=L(a));return a=K(a)}function Mb(a){return a.args?`function(${a.args.filter(({name:b})=>"this"!=b).map(({name:b})=>b).join(", ")}) {}`:null}
class W{constructor(){this.name="";this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.extends=null;this.examples=[];this.file=null}get import(){return!1}b(a,{name:b,type:c,desc:d,noToc:e,spread:g,noExpand:f,link:h,closure:k,constructor:l,"extends":m,"interface":n,record:p,example:q,"example-override":t},u,v=null){if(!b)throw Error("Type does not have a name.");
this.name=b;c&&(this.type=c);k?this.closureType=k:this.closureType=this.type;d&&(this.description=M(d));this.noToc=!!e;this.spread=!!g;this.noExpand=!!f;h&&(this.link=h);!0===l&&(this.isConstructor=l);!0===n&&(this.isInterface=n);!0===p&&(this.isRecord=p);m&&(this.extends=m);u&&(this.namespace=u);if(a){const {properties:w,constructor:y}=Eb(a,v,this.file,this.fullName);y&&(this.args=y.args);this.properties=w}q&&(a={example:q},N(a,this.file),this.examples=tb(a.example,t))}get L(){return this.isConstructor||
this.isInterface||this.isRecord}j(){let a;this.closureType?a=` * @typedef {${this.closureType}}`:this.L||(a=` * @typedef {${Pb(this.properties,!0)}}`);return a?(this.description&&(a=` * ${this.description}${B}${a}`),a=K(a),a+=fb(this.namespace,this.name)):Lb(this)}u(){return"Object"}o(a,b=new RegExp(`([!?])?${a}\\.`,"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get m(){return`${this.tag?` \`\uff20${this.tag}\``:""}${this.description?
` ${this.description}`:""}`}g(a=!1,b=!1,c=a){const d=!!this.extends,e=Ob(this,a,b,c),g=[];if(this.namespace&&a){var f=` * @typedef {${this.fullName}} ${this.name}${this.m}`;a&&!b&&(f=L(f));f=K(f);g.push(f)}else this.namespace&&c&&(f=` * @typedef {${this.fullName}} ${this.name}${this.m}`,f=K(f),g.push(f));d&&(c=` * @typedef {${Nb(this,c)} & ${this.extends.split(/,\s*/).join(" & ")}} ${c?this.fullName:this.name}${this.m}`,a&&!b&&(c=L(c)),c=K(c),g.push(c));g.push(e);return g.join("")}get Y(){const a=
this.tag;if(!a)throw Error("Unknown prototype type (not constructor or interface).");return a}get tag(){return this.isConstructor?"constructor":this.isInterface?"interface":this.isRecord?"record":""}h(a="",b=!0,c=!1){let d=[];this.description&&d.push(` * ${this.description}`);const e=this.properties[0];e instanceof U&&e.isConstructor&&e.description&&d.push(T(e.description));this.extends&&this.extends.split(/,\s*/).forEach(g=>{d.push(` * @extends {${g}}`)});this.args&&this.args.forEach(g=>{let {name:f,
description:h,optional:k,type:l}=g;g=h?` ${h}`:"";if(f.startsWith("..."))f=f.slice(3),l=`...${l}`;else if("this"==f){d.push(` * @this {${l}}${g}`);return}d.push(` * @param {${l}${k?"=":""}} ${k?`[${f}]`:f}${g}`)});b&&d.push(` * @${this.Y}`);c&&this.examples.length&&(b=tb(this.examples),d.push(...b));a&&(d=d.map(g=>`${a}${g}`));return d}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}D(a,b,c,d,e=!1,g=!1){var f="";!0===d?f="?":!1===d&&(f="!");d=this.description?
` ${this.description}`:"";const h=this.spread?Ob(this.properties):e||g?this.fullName:this.name;b=`${c||""} * @param {${f}${h}} ${b?`[${a}]`:a}${d}`;f=this.properties&&!this.noExpand?this.properties.map(k=>k.D(a,c,e,g)):[];return[b,...f].join(B)}toMarkdown(a=[],b={}){const {flatten:c,details:d=[]}=b,e=d.includes(this.name);var g=this.type?`\`${this.type}\``:"",f=g;this.link?f=`[${g}](${this.link})`:!this.import&&this.type&&(f=Eb(a,this.type,b),g=f!=this.type,f=Pb(f,g));g=Pb(this.fullName);g=this.import?
`[${g}](l-type)`:this.noToc?`[${g}](l-type)`:`[${g}](t-type)`;const h=this.description?`: ${this.description}`:"";f=f?`${f} `:"";let k=/_/.test(g);if(this.extends){const l=Jb(this.extends,a,b),n=` extends ${l}`;k=k||/_/.test(l);f=(k?f+"<strong>":f+"__")+(g+n);"function"==typeof c&&c(this.extends)}else f=(k?f+"<strong>":f+"__")+g;f=(k?f+"</strong>":f+"__")+h;a=Hb(this,this.properties,a,b);return{LINE:f,table:a,displayInDetails:e}}}
const Pb=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`,Ob=(a=[],b=!1)=>{a=a.reduce((c,d)=>{c.push(d);const e=d.aliases.map(g=>({...d,name:g}));c.push(...e);return c},[]);return`{ ${a.map(c=>{const d=b?c.closureType:c.type;let e=c.name,g=d;c.optional&&!b?e=`${c.name}?`:c.optional&&b&&(g=`(${db(d)})`);return`${e}: ${g}`}).join(", ")} }`};class Qb extends W{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:c,...d},e,g){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=M(a);super.b("",{...d,noToc:!0,name:c,type:`import('${b}').${c}`},e!=g?e:null)}g(a=!0){return` * @typedef {import('${this.from}').${this.name}} ${a?this.fullName:this.name}`}};function Rb(a,b){b=b.reduce((c,d)=>({...c,[d.fullName]:d}),{});a.B={...a.B,...b}}class Sb extends Za{constructor(a,b={}){super(a);this.B={};this.on("types",c=>{Rb(this,c)});this.on("namespace",c=>{this.b.includes(c)||this.b.push(c)});this.f=b;this.b=[];this.i=console.log;this.file=null;this.lines=[]}static get Type(){return W}static get Import(){return Qb}get types(){return this.B}};class Tb extends W{constructor(){super();this.f=null;this.async=!1}get L(){return!1}get isMethod(){return!0}b(a,{async:b,"return":c,"void":d,...e},...g){this.description=M(a);super.b("",e,...g);c&&(this.f=c.replace(/\r?\n\s*/g," "));d&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a=""){const b=super.h(a,!1),c=this.v;c&&b.push(`${a} * @return {${c}}`);return b}get v(){let a="";this.f&&(a=this.return);this.async&&a?a=`Promise<${a}>`:this.async&&(a="Promise");return a}u(){return`(${this.args.map(({name:a,
type:b,optional:c})=>`${a}${c?"?":""}: ${b}`).join(", ")}) => ${this.v}`}o(a){a=super.o(a);this.f&&(this.f=this.f.replace(a,"$1"))}};const Ub=(a,b)=>{const c=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(d=>{ub(d,a,c)});b.o(a)},Vb=(a,b)=>{var {args:c=[]}=a,d=c.map(({J:g})=>g).join(", ");let e=`new: ${a.fullName}`;d.length&&(e=`${e}, `);d=`function(${e}${d})`;c=new U(c);c.isConstructor=!0;c.b("Constructor method.",{type:d,name:"constructor"});c.examples=a.examples;ub(c,b);a.properties.unshift(c)},Xb=(a,b,c=null)=>{a=P("types",a);if(!a.length)throw Error("XML file should contain root types element.");const [{content:d,props:{namespace:e,
ns:g=e}}]=a,f=b==g?void 0:g;a=P(["embed"],d).map(({props:l})=>l);const h=[],k=P("type interface constructor method import record".split(" "),d).reduce((l,{content:n,props:m,tag:q})=>{"record"==q&&(q="type",m.record=!0);const {alias:r,aliases:t,...u}=m;c&&N(u,c);var v=r?[r]:t?t.split(/, */):[];switch(q){case "type":q=new W;c&&(q.file=c);q.b(n,m,f,b);l.push(q);v.forEach(w=>{const y=new W;c&&(y.file=c);y.b(n,{...u,name:w},f,b);l.push(y)});break;case "interface":m=Wb({content:n,props:m,ns:f,C:b,location:c});
m.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Vb(w,b);w.isInterface=!0});l.push(...m);break;case "constructor":m=Wb({content:n,props:m,ns:f,C:b,location:c});m.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Vb(w,b);w.isConstructor=!0});l.push(...m);break;case "method":m=Wb({content:n,props:m,ns:f,C:b,isMethod:!0,location:c});l.push(...m);break;case "import":v=new Qb,v.b(n,m,m.ns||m.from,b),h.push(v)}return l},[]);b&&k.forEach(l=>Ub(b,l));return{namespace:g,types:k,imports:h,embeds:a}},
Yb=(a,b,c,d,e=!1,g=null)=>{const f=e?new Tb:new W;f.file=g;g=a.search(/<(prop|function|fn|static) /);let h="",k=a;1!=g&&(h=a.slice(0,g),k=a.slice(g));const {G:l,K:n}=qb(h,d);f.b(e?n:k,b,c,d);({I:a}=gb(b,l));e&&(f.closureType=a);f.args||(f.args=l);return f},Wb=({content:a,props:b,ns:c,C:d,isMethod:e=!1,location:g=null})=>{const f=[],{alias:h,aliases:k,...l}=b;b=Yb(a,b,c,d,e,g);f.push(b);(h?[h]:k?k.split(/, */):[]).forEach(n=>{n=Yb(a,{...l,name:n},c,d,e,g);n.description=`${n.description}${n.description?
" ":""}Alias of \`${l.name}\`.`;f.push(n)});return f},Zb=()=>{Object.keys(X).forEach(a=>{delete X[a]});Object.keys(Y).forEach(a=>{delete Y[a]})},X={},Y={},ac=async a=>{var b=Y[a];b?b=await b:(b=F(a),Y[a]=b,b=await b);return $b(b,a,[])},bc=(a,b=[])=>{a in X||(X[a]=ua(a,"utf8"));return $b(X[a],a,b)},$b=(a,b,c)=>{let d,e,g,f;try{({namespace:d=null,types:e,imports:g,embeds:f}=Xb(a,void 0,b))}catch(h){throw h.message=`Error while reading ${b}${B}${h.message}`,h;}e=e.filter(({fullName:h})=>c.includes(h)?
!1:!0);g=g.filter(({fullName:h})=>c.includes(h)?!1:!0);return{types:e,imports:g,namespace:d,embeds:f}};const cc=(a,b,c)=>{b=b.map(d=>d.g(!0,c));a=a.map(d=>{d=d.g();return K(c?d:L(d))});return[...b,...a].join("")},dc=(a,b,c,d=!1)=>{a=a.map(e=>e.m());a=O(...a,...[]);return`${!b||d||c.includes(b)?"":["/** @const */",`var ${b} = {}`,""].join(B)}${a}`};function ec(a,b,c){const [d,...e]=c.split(/\s+/);var g=e.includes("closure");const f=e.includes("externs"),h=e.includes("noSuppress"),k=e.includes("skipNsDecl"),l=e.includes("namespace"),n=e.includes("noEmbed")||e.includes("no-embed");let m=e.find(t=>t.startsWith("ignore:"));m=m?m.replace("ignore:","").split(","):[];let {s:q,A:r}=this.f;g&&(q=!0);f&&(r=!0);try{this.i("Detected type marker: %s",c);const {types:t,imports:u,namespace:v,embeds:w}=bc(d,m);this.emit("types",t);this.emit("types",u);g=[];
!n&&w.length&&(g=w.map(({src:E,path:mc=E,ignore:Q=m.join(","),namespace:nc=l,s:oc=q,A:pc=r,"no-suppress":qc=h})=>{E=[mc];Q&&E.push(`ignore:${Q}`);nc&&E.push("namespace");oc&&E.push("closure");pc&&E.push("ext");qc&&E.push("noSuppress");Q=E.join(" ");return ec.call(this,`${B} /* typal-embed ${Q} */${B}`,"typal-embed",Q)}));let y=g.join(""),R;q?R=cc(u,t,h):r?(R=dc(t,v,this.b,k)+B,v&&this.emit("namespace",v)):l?(v&&this.emit("namespace",v),R=fc(u,t,!0)):R=fc(u,t);return`/* ${b} ${c} */${B}${R}${y}`}catch(t){return this.i("(%s) Could not process typedef-js: %s",
c,t.message),process.env.b&&console.error(t.stack),a}}const gc={re:/^\/\*\*? (documentary|typal) (.+?) \*\/\r?\n(?:((?!\r?\n)[\s\S]+?\r?\n))?$/mg,replacement:ec},fc=(a,b,c=!1)=>{b=b.map(d=>d.g(!1,!1,c));a=a.map(d=>d.g(c)).map(K).join("");b=b.join("");return`${a}${b}`.replace(hc," * @typedef")},hc=/ \*\/\r?\n\/\*\*\r?\n \* @typedef/g;const jc={re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\r?\n(?: +)\* @param {(?:.+?)} \[?\4\]?(?:(?!\r?\n\s*\*(?:\/|\s*@))[\s\S])*)*)/gm,replacement:ic};
function ic(a,b,c,d,e,g,f){const h=this.f.s,k=this.f.F;let l;g=()=>{if(this.lines&&this.file){var m;{let t=m=0;for(;t<f;)t+=this.lines[m].length,m++;m={line:m,S:b.length+11}}const {line:q,S:r}=m;this.i("%s:%s:%s",this.file,q,r)}};try{l=nb(c)}catch(m){return this.i("Error while parsing the type %s",c),this.i(process.env.DEBUG?m.stack:m.message),g(),a}if(!l)return this.i("Could not parse the type %s",c),g(),a;const n=Object.values(this.types).map(({name:m,fullName:q})=>h||k?q:m);if(!Z(l,n,this.i,c,
g))return a;c=Object.values(this.types).find(({name:m,fullName:q})=>h||k?q==l.name:m==l.name);return!c||c instanceof Sb.Import?a:c.D(e,d,b,l.nullable,h,k)}
const Z=(a,b,c,d,e)=>{if(a){var g=a.name;if(!g||!"string number boolean null undefined symbol any".split(" ").includes(g)){if(g&&!a.application&&!a.function){let h=b.includes(g);h||(h=kc.includes(g));if(h)return!0;c("Type %s%s was not found.",g,d!=g?` in ${d}`:"");e()}var f=[b,c,d,e];a.application?a.application.forEach(h=>{Z(h,...f)}):a.record?Object.keys(a.record).forEach(h=>{Z(a.record[h],...f)}):a.union?a.union.forEach(h=>{Z(h,...f)}):a.function&&(Z(a.function.this,...f),Z(a.function.new,...f),
a.function.args.forEach(h=>{Z(h,...f)}),Z(a.function.variableArgs,...f),Z(a.function.return,...f))}}},kc="String Boolean Object Date Number Symbol Buffer Function RegExp".split(" ");var lc=(a,b=!1)=>{Zb();var {U:c}=Ua();const d=Wa(c);c=Va(c);return new Sb(b?[gc]:[gc,d,jc,c],a)};const rc=/( *) \* @(fnType|methodType) {(.+?)}/gm,sc=(a,b,c,d,e,g,f=d)=>{c=`${b?"static ":""}${c?"async ":""}${d}(${e}) {`;return O("/**",a," */",...null===g?[`${c} }`]:[c,` return ${`${b?g:"super"}.${f}`}(${e})`,"}"])};
function tc(a,b,c){return a.map(d=>{const e=d.name;var g=d.aliases;const f=d.static,h=d.async;let k=d.m("",!0);k=uc(k,c);const l=d.args.map(({name:n})=>n).join(", ");d=sc(k,f,h,e,l,b);g=g.map(n=>sc(k+`${B} * @alias ${e} An alias for **${e}**.`,f,h,n,l,b,e));return[d,...g].join(B)})}
class vc extends Za{constructor(a,b){super([{re:/\/\*\*(?:\s+( *) \*)? @constructor {(.+?)}[\s\S]+?(class\s+.+?\s+extends\s+(.+?)\s*){\s*}/gm,replacement(c,d,e,g,f){d=a.find(({fullName:k})=>k==e);if(!d)return console.error("Type %s in %s not found",e,b),c;c=d.properties.filter(k=>k instanceof U&&!k.isConstructor);f=tc(c,f,e);c=d.properties.find(k=>k instanceof U&&k.isConstructor);const h=c.args.map(({name:k})=>k).join(", ");f=O("/**",uc(c.m("",!0),e)," */",`constructor(${h}) {`,` super(${h})`,"}",
...f).replace(/(^|(?:\r?\n))/g,"$1 ");return O(...d.description?["/**",T(d.description)," */"]:[],`${g}{`,f,"}")}},{re:/(\/\*\*[\s\S]+?)( *\* *@implements {(.+?)})[\s\S]+?((?:export\s+(?:default\s+)?)?class\s+(\S+).*?){\s*}/gm,replacement(c,d,e,g,f,h){const k=a.find(({fullName:m})=>m==g);if(!k)return console.error("Type %s in %s not found",g,b),c;c=k.properties.filter(m=>m instanceof U&&!m.isConstructor);c=tc(c,null,g);const l=k.properties.find(m=>m instanceof U&&m.isConstructor),n=l.args.map(({name:m})=>
m).join(", ");h=O("/**",uc(l.m("",!0),g)," */",`constructor(${n}) { }`,"/**"," * Sets the implementation on the interface.",` * @param {!${h}} Implementation`," */","static __implement(Implementation) {"," Object.defineProperties(",` ${h}.prototype,`," Object.getOwnPropertyDescriptors(Implementation)"," )","}",...c).replace(/(^|(?:\r?\n))/g,"$1 ");return O(d.trimRight(),...k.description?[T(k.description)]:[],e," */",`${f}{`,h,"}")}},{re:rc,async replacement(c,d,e,g){const f=g.split(".");
let h,k;if("methodType"==e)h=g;else if(2==f.length)[h,k]=f;else if(3==f.length)h=`${f[0]}.${f[1]}`,k=f[2];else throw Error("The @fnType should consist of _namespace.Type.propName or Type.propName");g=a.find(({fullName:l})=>l==h);if(!g)return console.error("Type %s in %s not found",h,b),c;if("constructor"==k||"methodType"==e)return g.h(d,!1,!0).join(B);e=g.properties.find(({name:l})=>l==k);return e?e.parsed?e.m(d,!0):(console.error("Property %s of type %s in %s wasn't parsed, possibly parser bug.",
k,h,b),c):(console.error("Property %s of type %s in %s not found",k,h,b),c)}}])}}const uc=(a,b)=>a.replace(`${B} * @return {${b}}`,"").replace(`${B} * @return {!${b}}`,"").replace(`${B} * @return {?${b}}`,"");const wc=async a=>a?(await Promise.all(a.split(",").map(async b=>{var c=[];const d=await H(z,b);d.isFile()?c=[b]:d.isDirectory()&&(c=await I(b),c=J(c.content,b),c=c.filter(e=>e.endsWith(".xml")));return c}))).reduce((b,c)=>[...b,...c],[]):[],xc=async a=>(await Promise.all(a.map(async b=>({...await ac(b),location:b})))).reduce((b,{imports:c,types:d})=>{b.push(...c);b.push(...d);return b},[]);
async function yc(){Zb();const a=await wc(na),b=await xc(a);await Promise.all(x.map(async c=>{var d=await H(z,c);let e;d.isFile()?e=[c]:d.isDirectory()&&(d=await I(c),e=J(d.content,c));await zc(e,b,oa)}))}const zc=async(a,b=[],c=null)=>{await Promise.all(a.map(async d=>{var e=await F(d);const g=new vc(b,d);g.end(e);e=await D(g);"-"==c?console.log(e):c?await G(c,e):await G(d,e)}))};var Bc=async()=>{const {s:a=!1,F:b=!1,A:c=!1,W:d,types:e}={s:ka,A:ma,W:ja,types:na,F:la},g=await wc(e);await Promise.all(x.map(async f=>{var h=await H(z,f);let k;h.isFile()?k=[f]:h.isDirectory()&&(h=await I(f),k=J(h.content,f));await Ac(k,a,c,d,g,b)}))};
const Ac=async(a,b=!1,c=!1,d="",e=[],g=!1)=>{const f=[];await Promise.all(e.map(async h=>{h=await F(h);const {types:k,imports:l}=Xb(h);f.push(k,l)}));await Promise.all(a.map(async h=>{var k=await F(h);const l=lc({s:b,A:c,F:g},c);f.forEach(n=>l.emit("types",n));l.file=h;l.i=console.error;l.lines=k.split(B);l.end(k);k=await D(l);"-"==d?console.log(k):d?await G(d,k):await G(h,k)}))};const Cc=a=>{let b;"true"==a?b=!0:"false"==a?b=!1:/^\d+$/.test(a)&&(b=parseInt(a,10));return void 0!==b?b:a},Dc=/^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm,Ec="type opt name quote defaultValue description Default".split(" "),ab=new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\r?\\n((?:${/ \* @prop(?:erty)? .+\r?\n/.source})*)`,"gm"),Fc=(a,b,c,d)=>{d=d.length;a=a&&"Object"!=a?` type="${a}"`:"";c=c?` desc="${c}"`:"";return`${" ".repeat(2)}<type name="${b}"${a}${c}${d?
description:h,optional:k,type:l}=g;g=h?` ${h}`:"";if(f.startsWith("..."))f=f.slice(3),l=`...${l}`;else if("this"==f){d.push(` * @this {${l}}${g}`);return}d.push(` * @param {${l}${k?"=":""}} ${k?`[${f}]`:f}${g}`)});b&&d.push(` * @${this.Y}`);c&&this.examples.length&&(b=ub(this.examples),d.push(...b));a&&(d=d.map(g=>`${a}${g}`));return d}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}D(a,b,c,d,e=!1,g=!1){var f="";!0===d?f="?":!1===d&&(f="!");d=this.description?
` ${this.description}`:"";const h=this.spread?Pb(this.properties):e||g?this.fullName:this.name;b=`${c||""} * @param {${f}${h}} ${b?`[${a}]`:a}${d}`;f=this.properties&&!this.noExpand?this.properties.map(k=>k.D(a,c,e,g)):[];return[b,...f].join(B)}toMarkdown(a=[],b={}){const {flatten:c,details:d=[]}=b,e=d.includes(this.name);var g=this.type?`\`${this.type}\``:"",f=g;this.link?f=`[${g}](${this.link})`:!this.import&&this.type&&(f=Fb(a,this.type,b),g=f!=this.type,f=Qb(f,g));g=Qb(this.fullName);g=this.import?
`[${g}](l-type)`:this.noToc?`[${g}](l-type)`:`[${g}](t-type)`;const h=this.description?`: ${this.description}`:"";f=f?`${f} `:"";let k=/_/.test(g);if(this.extends){const l=Kb(this.extends,a,b),m=` extends ${l}`;k=k||/_/.test(l);f=(k?f+"<strong>":f+"__")+(g+m);"function"==typeof c&&c(this.extends)}else f=(k?f+"<strong>":f+"__")+g;f=(k?f+"</strong>":f+"__")+h;a=Ib(this,this.properties,a,b);return{LINE:f,table:a,displayInDetails:e}}}
const Qb=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`,Pb=(a=[],b=!1)=>{a=a.reduce((c,d)=>{c.push(d);const e=d.aliases.map(g=>({...d,name:g}));c.push(...e);return c},[]);return`{ ${a.map(c=>{const d=b?c.closureType:c.type;let e=c.name,g=d;c.optional&&!b?e=`${c.name}?`:c.optional&&b&&(g=`(${eb(d)})`);return`${e}: ${g}`}).join(", ")} }`};class Rb extends W{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:c,...d},e,g){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=M(a);super.b("",{...d,noToc:!0,name:c,type:`import('${b}').${c}`},e!=g?e:null)}g(a=!0){return` * @typedef {import('${this.from}').${this.name}} ${a?this.fullName:this.name}`}};function Sb(a,b){b=b.reduce((c,d)=>({...c,[d.fullName]:d}),{});a.B={...a.B,...b}}class Tb extends Za{constructor(a,b={}){super(a);this.B={};this.on("types",c=>{Sb(this,c)});this.on("namespace",c=>{this.b.includes(c)||this.b.push(c)});this.f=b;this.b=[];this.i=console.log;this.file=null;this.lines=[]}static get Type(){return W}static get Import(){return Rb}get types(){return this.B}};class Ub extends W{constructor(){super();this.f=null;this.async=!1}get L(){return!1}get isMethod(){return!0}b(a,{async:b,"return":c,"void":d,...e},...g){this.description=M(a);super.b("",e,...g);c&&(this.f=c.replace(/\r?\n\s*/g," "));d&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a=""){const b=super.h(a,!1),c=this.v;c&&b.push(`${a} * @return {${c}}`);return b}get v(){let a="";this.f&&(a=this.return);this.async&&a?a=`Promise<${a}>`:this.async&&(a="Promise");return a}u(){return`(${this.args.map(({name:a,
type:b,optional:c})=>`${a}${c?"?":""}: ${b}`).join(", ")}) => ${this.v}`}o(a){a=super.o(a);this.f&&(this.f=this.f.replace(a,"$1"))}};const Vb=(a,b)=>{const c=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(d=>{vb(d,a,c)});b.o(a)},Wb=(a,b)=>{var {args:c=[]}=a,d=c.map(({J:g})=>g).join(", ");let e=`new: ${a.fullName}`;d.length&&(e=`${e}, `);d=`function(${e}${d})`;c=new U(c);c.isConstructor=!0;c.b("Constructor method.",{type:d,name:"constructor"});c.examples=a.examples;vb(c,b);a.properties.unshift(c)},Yb=(a,b,c=null)=>{a=P("types",a);if(!a.length)throw Error("XML file should contain root types element.");const [{content:d,props:{namespace:e,
ns:g=e}}]=a,f=b==g?void 0:g;a=P(["embed"],d).map(({props:l})=>l);const h=[],k=P("type interface constructor method import record".split(" "),d).reduce((l,{content:m,props:n,tag:p})=>{"record"==p&&(p="type",n.record=!0);const {alias:q,aliases:t,...u}=n;c&&N(u,c);var v=q?[q]:t?t.split(/, */):[];switch(p){case "type":p=new W;c&&(p.file=c);p.b(m,n,f,b);l.push(p);v.forEach(w=>{const y=new W;c&&(y.file=c);y.b(m,{...u,name:w},f,b);l.push(y)});break;case "interface":n=Xb({content:m,props:n,ns:f,C:b,location:c});
n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Wb(w,b);w.isInterface=!0});l.push(...n);break;case "constructor":n=Xb({content:m,props:n,ns:f,C:b,location:c});n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Wb(w,b);w.isConstructor=!0});l.push(...n);break;case "method":n=Xb({content:m,props:n,ns:f,C:b,isMethod:!0,location:c});l.push(...n);break;case "import":v=new Rb,v.b(m,n,n.ns||n.from,b),h.push(v)}return l},[]);b&&k.forEach(l=>Vb(b,l));return{namespace:g,types:k,imports:h,embeds:a}},
Zb=(a,b,c,d,e=!1,g=null)=>{const f=e?new Ub:new W;f.file=g;g=a.search(/<(prop|function|fn|static) /);let h="",k=a;1!=g&&(h=a.slice(0,g),k=a.slice(g));const {G:l,K:m}=rb(h,d);f.b(e?m:k,b,c,d);({I:a}=hb(b,l));e&&(f.closureType=a);f.args||(f.args=l);return f},Xb=({content:a,props:b,ns:c,C:d,isMethod:e=!1,location:g=null})=>{const f=[],{alias:h,aliases:k,...l}=b;b=Zb(a,b,c,d,e,g);f.push(b);(h?[h]:k?k.split(/, */):[]).forEach(m=>{m=Zb(a,{...l,name:m},c,d,e,g);m.description=`${m.description}${m.description?
" ":""}Alias of \`${l.name}\`.`;f.push(m)});return f},$b=()=>{Object.keys(X).forEach(a=>{delete X[a]});Object.keys(Y).forEach(a=>{delete Y[a]})},X={},Y={},bc=async a=>{var b=Y[a];b?b=await b:(b=F(a),Y[a]=b,b=await b);return ac(b,a,[])},cc=(a,b=[])=>{a in X||(X[a]=ua(a,"utf8"));return ac(X[a],a,b)},ac=(a,b,c)=>{let d,e,g,f;try{({namespace:d=null,types:e,imports:g,embeds:f}=Yb(a,void 0,b))}catch(h){throw h.message=`Error while reading ${b}${B}${h.message}`,h;}e=e.filter(({fullName:h})=>c.includes(h)?
!1:!0);g=g.filter(({fullName:h})=>c.includes(h)?!1:!0);return{types:e,imports:g,namespace:d,embeds:f}};const dc=(a,b,c)=>{b=b.map(d=>d.g(!0,c));a=a.map(d=>{d=d.g();return K(c?d:L(d))});return[...b,...a].join("")},ec=(a,b,c,d=!1)=>{a=a.map(e=>e.j());a=O(...a,...[]);return`${!b||d||c.includes(b)?"":["/** @const */",`var ${b} = {}`,""].join(B)}${a}`};function fc(a,b,c){const [d,...e]=c.split(/\s+/);var g=e.includes("closure");const f=e.includes("externs"),h=e.includes("noSuppress"),k=e.includes("skipNsDecl"),l=e.includes("namespace"),m=e.includes("noEmbed")||e.includes("no-embed");let n=e.find(t=>t.startsWith("ignore:"));n=n?n.replace("ignore:","").split(","):[];let {s:p,A:q}=this.f;g&&(p=!0);f&&(q=!0);try{this.i("Detected type marker: %s",c);const {types:t,imports:u,namespace:v,embeds:w}=cc(d,n);this.emit("types",t);this.emit("types",u);g=[];
!m&&w.length&&(g=w.map(({src:E,path:nc=E,ignore:Q=n.join(","),namespace:oc=l,s:pc=p,A:qc=q,"no-suppress":rc=h})=>{E=[nc];Q&&E.push(`ignore:${Q}`);oc&&E.push("namespace");pc&&E.push("closure");qc&&E.push("ext");rc&&E.push("noSuppress");Q=E.join(" ");return fc.call(this,`${B} /* typal-embed ${Q} */${B}`,"typal-embed",Q)}));let y=g.join(""),R;p?R=dc(u,t,h):q?(R=ec(t,v,this.b,k)+B,v&&this.emit("namespace",v)):l?(v&&this.emit("namespace",v),R=gc(u,t,!0)):R=gc(u,t);return`/* ${b} ${c} */${B}${R}${y}`}catch(t){return this.i("(%s) Could not process typedef-js: %s",
c,t.message),process.env.b&&console.error(t.stack),a}}const hc={re:/^\/\*\*? (documentary|typal) (.+?) \*\/\r?\n(?:((?!\r?\n)[\s\S]+?\r?\n))?$/mg,replacement:fc},gc=(a,b,c=!1)=>{b=b.map(d=>d.g(!1,!1,c));a=a.map(d=>d.g(c)).map(K).join("");b=b.join("");return`${a}${b}`.replace(ic," * @typedef")},ic=/ \*\/\r?\n\/\*\*\r?\n \* @typedef/g;const kc={re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\r?\n(?: +)\* @param {(?:.+?)} \[?\4\]?(?:(?!\r?\n\s*\*(?:\/|\s*@))[\s\S])*)*)/gm,replacement:jc};
function jc(a,b,c,d,e,g,f){const h=this.f.s,k=this.f.F;let l;g=()=>{if(this.lines&&this.file){var n;{let t=n=0;for(;t<f;)t+=this.lines[n].length,n++;n={line:n,S:b.length+11}}const {line:p,S:q}=n;this.i("%s:%s:%s",this.file,p,q)}};try{l=ob(c)}catch(n){return this.i("Error while parsing the type %s",c),this.i(process.env.DEBUG?n.stack:n.message),g(),a}if(!l)return this.i("Could not parse the type %s",c),g(),a;const m=Object.values(this.types).map(({name:n,fullName:p})=>h||k?p:n);if(!Z(l,m,this.i,c,
g))return a;c=Object.values(this.types).find(({name:n,fullName:p})=>h||k?p==l.name:n==l.name);return!c||c instanceof Tb.Import?a:c.D(e,d,b,l.nullable,h,k)}
const Z=(a,b,c,d,e)=>{if(a){var g=a.name;if(!g||!"string number boolean null undefined symbol any".split(" ").includes(g)){if(g&&!a.application&&!a.function){let h=b.includes(g);h||(h=lc.includes(g));if(h)return!0;c("Type %s%s was not found.",g,d!=g?` in ${d}`:"");e()}var f=[b,c,d,e];a.application?a.application.forEach(h=>{Z(h,...f)}):a.record?Object.keys(a.record).forEach(h=>{Z(a.record[h],...f)}):a.union?a.union.forEach(h=>{Z(h,...f)}):a.function&&(Z(a.function.this,...f),Z(a.function.new,...f),
a.function.args.forEach(h=>{Z(h,...f)}),Z(a.function.variableArgs,...f),Z(a.function.return,...f))}}},lc="String Boolean Object Date Number Symbol Buffer Function RegExp".split(" ");var mc=(a,b=!1)=>{$b();var {U:c}=Ua();const d=Wa(c);c=Va(c);return new Tb(b?[hc]:[hc,d,kc,c],a)};const sc=/( *) \* @(fnType|methodType) {(.+?)}/gm,tc=(a,b,c,d,e,g,f=d)=>{c=`${b?"static ":""}${c?"async ":""}${d}(${e}) {`;return O("/**",a," */",...null===g?[`${c} }`]:[c,` return ${`${b?g:"super"}.${f}`}(${e})`,"}"])};
function uc(a,b,c){return a.map(d=>{const e=d.name;var g=d.aliases;const f=d.static,h=d.async;let k=d.j("",!0);k=vc(k,c);const l=d.args.map(({name:m})=>m).join(", ");d=tc(k,f,h,e,l,b);g=g.map(m=>tc(k+`${B} * @alias ${e} An alias for **${e}**.`,f,h,m,l,b,e));return[d,...g].join(B)})}function wc(a){return a.map(b=>{const c=b.name,d=b.default,e=b.type;return["/**",b.j("",!0)," */",`this.${c}${d?` = ${bb(e,d,"'")}`:""}`].join(B)})}
const xc=(a,b)=>({re:/(\/\*\*[\s\S]+?)( *\* *@implements {(.+?)})[\s\S]+?((?:export\s+(?:default\s+)?)?class\s+(\S+).*?){\s*}/gm,replacement(c,d,e,g,f,h){const k=a.find(({fullName:q})=>q==g);if(!k)return console.error("Type %s in %s not found",g,b),c;c=k.properties.filter(q=>q instanceof U&&!q.isConstructor);var l=k.properties.filter(q=>q instanceof Db&&!(q instanceof U));c=uc(c,null,g);l=wc(l).map(q=>q.replace(/(^|(?:\r?\n))/g,"$1 "));const m=k.properties.find(q=>q instanceof U&&q.isConstructor),
n=m.args.map(({name:q})=>q).join(", "),p=0<l.length;h=O("/**",vc(m.j("",!0),g)," */",`constructor(${n}) {${p||k.extends?"":" }"}`,...k.extends?[" super([arguments])"]:[],...l,p?"}"+B+"/**":"/**"," * Sets the implementation on the interface.",` * @param {!${h}} Implementation`," */","static __implement(Implementation) {"," Object.defineProperties(",` ${h}.prototype,`," Object.getOwnPropertyDescriptors(Implementation)"," )","}",...c);h=h.replace(/(^|(?:\r?\n))/g,"$1 ");return O(d.trimRight(),
...k.description?[T(k.description)]:[],e," */",`${f}{`,h,"}")}});
class yc extends Za{constructor(a,b){super([{re:/\/\*\*(?:\s+( *) \*)? @constructor {(.+?)}[\s\S]+?(class\s+.+?\s+extends\s+(.+?)\s*){\s*}/gm,replacement(c,d,e,g,f){d=a.find(({fullName:k})=>k==e);if(!d)return console.error("Type %s in %s not found",e,b),c;c=d.properties.filter(k=>k instanceof U&&!k.isConstructor);f=uc(c,f,e);c=d.properties.find(k=>k instanceof U&&k.isConstructor);const h=c.args.map(({name:k})=>k).join(", ");f=O("/**",vc(c.j("",!0),e)," */",`constructor(${h}) {`,` super(${h})`,"}",
...f);f=f.replace(/(^|(?:\r?\n))/g,"$1 ");return O(...d.description?["/**",T(d.description)," */"]:[],`${g}{`,f,"}")}},xc(a,b),{re:sc,async replacement(c,d,e,g){const f=g.split(".");let h,k;if("methodType"==e)h=g;else if(2==f.length)[h,k]=f;else if(3==f.length)h=`${f[0]}.${f[1]}`,k=f[2];else throw Error("The @fnType should consist of _namespace.Type.propName or Type.propName");g=a.find(({fullName:l})=>l==h);if(!g)return console.error("Type %s in %s not found",h,b),c;if("constructor"==k||"methodType"==
e)return g.h(d,!1,!0).join(B);e=g.properties.find(({name:l})=>l==k);return e?e.parsed?e.j(d,!0):(console.error("Property %s of type %s in %s wasn't parsed, possibly parser bug.",k,h,b),c):(console.error("Property %s of type %s in %s not found",k,h,b),c)}}])}}const vc=(a,b)=>a.replace(`${B} * @return {${b}}`,"").replace(`${B} * @return {!${b}}`,"").replace(`${B} * @return {?${b}}`,"");const zc=async a=>a?(await Promise.all(a.split(",").map(async b=>{var c=[];const d=await H(z,b);d.isFile()?c=[b]:d.isDirectory()&&(c=await I(b),c=J(c.content,b),c=c.filter(e=>e.endsWith(".xml")));return c}))).reduce((b,c)=>[...b,...c],[]):[],Ac=async a=>(await Promise.all(a.map(async b=>({...await bc(b),location:b})))).reduce((b,{imports:c,types:d})=>{b.push(...c);b.push(...d);return b},[]);
async function Bc(){$b();const a=await zc(na),b=await Ac(a);await Promise.all(x.map(async c=>{var d=await H(z,c);let e;d.isFile()?e=[c]:d.isDirectory()&&(d=await I(c),e=J(d.content,c));await Cc(e,b,oa)}))}const Cc=async(a,b=[],c=null)=>{await Promise.all(a.map(async d=>{var e=await F(d);const g=new yc(b,d);g.end(e);e=await D(g);"-"==c?console.log(e):c?await G(c,e):await G(d,e)}))};var Ec=async()=>{const {s:a=!1,F:b=!1,A:c=!1,W:d,types:e}={s:ka,A:ma,W:ja,types:na,F:la},g=await zc(e);await Promise.all(x.map(async f=>{var h=await H(z,f);let k;h.isFile()?k=[f]:h.isDirectory()&&(h=await I(f),k=J(h.content,f));await Dc(k,a,c,d,g,b)}))};
const Dc=async(a,b=!1,c=!1,d="",e=[],g=!1)=>{const f=[];await Promise.all(e.map(async h=>{h=await F(h);const {types:k,imports:l}=Yb(h);f.push(k,l)}));await Promise.all(a.map(async h=>{var k=await F(h);const l=mc({s:b,A:c,F:g},c);f.forEach(m=>l.emit("types",m));l.file=h;l.i=console.error;l.lines=k.split(B);l.end(k);k=await D(l);"-"==d?console.log(k):d?await G(d,k):await G(h,k)}))};const Fc=a=>{let b;"true"==a?b=!0:"false"==a?b=!1:/^\d+$/.test(a)&&(b=parseInt(a,10));return void 0!==b?b:a},Gc=/^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm,Hc="type opt name quote defaultValue description Default".split(" "),ab=new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\r?\\n((?:${/ \* @prop(?:erty)? .+\r?\n/.source})*)`,"gm"),Ic=(a,b,c,d)=>{d=d.length;a=a&&"Object"!=a?` type="${a}"`:"";c=c?` desc="${c}"`:"";return`${" ".repeat(2)}<type name="${b}"${a}${c}${d?
"":" /"}>${B}`};
class Gc extends A{constructor(){super({writableObjectMode:!0})}_transform({type:a,name:b,description:c,properties:d},e,g){a=a&&a.startsWith("import")?Hc(a,b):Fc(a,b,c,d);this.push(a);d.forEach(({type:f,name:h,default:k,description:l,optional:n})=>{{f=["string","number","boolean"].includes(f)?` ${f}`:` type="${f}"`;var m=void 0!==k;k=m?` default="${k}"`:"";n=n&&!m?" opt":"";m=" ".repeat(4);const q=" ".repeat(6);h=`${m}<prop${n}${f} name="${h}"${k}${l?`>${B}${q}${l}${B}${m}</prop>`:"/>"}${B}`}this.push(h)});
d.length&&this.push(` </type>${B}`);g()}}const Hc=(a,b)=>{const c=/import\((['"])(.+?)\1\)/.exec(a);if(!c)throw Error(`Could not extract package from "${a}"`);[,,a]=c;return`${" ".repeat(2)}<import name="${b}" from="${a}" />${B}`};
class Ic extends A{constructor(){super({objectMode:!0})}_transform([,a,b,c,d],e,g){d=hb(Dc,d,Ec).map(f=>{const {defaultValue:h,Default:k,opt:l,name:n,type:m,...q}=f;f={...q,name:n,type:m,...h?{defaultValue:Cc(h)}:{},...k?{w:Cc(k)}:{},...l?{optional:!0}:{}};if(h||k){if(h)h!==k&&void 0!==f.w&&(r=bb(n,k,m),console.error("%s[%s] does not match Default `%s`.",b,r,f.w));else{var r=bb(n,k,m);console.error("%s[%s] got from Default.",b,r)}f.default="defaultValue"in f?f.defaultValue:f.w;delete f.defaultValue;
delete f.w}return f});this.push({type:a,name:b,description:c,properties:d});g()}}async function Jc(a){const b=$a(),c=new Ic,d=new Gc;b.pipe(c).pipe(d);b.end(a);b.on("error",e=>{console.error("Error in Transform");d.emit("error",e)});c.on("error",e=>{console.error("Error in RegexTransform");d.emit("error",e)});d.on("error",e=>{console.error("Error in XML");d.emit("error",e)});return["<types>",` ${(await D(d)).trim()}`,"</types>"].join(B)};var Kc=async()=>{await Promise.all(x.map(async a=>{a=await F(a);a=await Jc(a);ja?await G(ja,a):console.log(a)}))};/*
class Jc extends A{constructor(){super({writableObjectMode:!0})}_transform({type:a,name:b,description:c,properties:d},e,g){a=a&&a.startsWith("import")?Kc(a,b):Ic(a,b,c,d);this.push(a);d.forEach(({type:f,name:h,default:k,description:l,optional:m})=>{{f=["string","number","boolean"].includes(f)?` ${f}`:` type="${f}"`;var n=void 0!==k;k=n?` default="${k}"`:"";m=m&&!n?" opt":"";n=" ".repeat(4);const p=" ".repeat(6);h=`${n}<prop${m}${f} name="${h}"${k}${l?`>${B}${p}${l}${B}${n}</prop>`:"/>"}${B}`}this.push(h)});
d.length&&this.push(` </type>${B}`);g()}}const Kc=(a,b)=>{const c=/import\((['"])(.+?)\1\)/.exec(a);if(!c)throw Error(`Could not extract package from "${a}"`);[,,a]=c;return`${" ".repeat(2)}<import name="${b}" from="${a}" />${B}`};
class Lc extends A{constructor(){super({objectMode:!0})}_transform([,a,b,c,d],e,g){d=ib(Gc,d,Hc).map(f=>{const {defaultValue:h,Default:k,opt:l,name:m,type:n,...p}=f;f={...p,name:m,type:n,...h?{defaultValue:Fc(h)}:{},...k?{w:Fc(k)}:{},...l?{optional:!0}:{}};if(h||k){if(h)h!==k&&void 0!==f.w&&(q=cb(m,k,n),console.error("%s[%s] does not match Default `%s`.",b,q,f.w));else{var q=cb(m,k,n);console.error("%s[%s] got from Default.",b,q)}f.default="defaultValue"in f?f.defaultValue:f.w;delete f.defaultValue;
delete f.w}return f});this.push({type:a,name:b,description:c,properties:d});g()}}async function Mc(a){const b=$a(),c=new Lc,d=new Jc;b.pipe(c).pipe(d);b.end(a);b.on("error",e=>{console.error("Error in Transform");d.emit("error",e)});c.on("error",e=>{console.error("Error in RegexTransform");d.emit("error",e)});d.on("error",e=>{console.error("Error in XML");d.emit("error",e)});return["<types>",` ${(await D(d)).trim()}`,"</types>"].join(B)};var Nc=async()=>{await Promise.all(x.map(async a=>{a=await F(a);a=await Mc(a);ja?await G(ja,a):console.log(a)}))};/*

@@ -104,2 +105,2 @@ Typal: keep types information in XML files to embed as typedefs,

*/
if(p.help){const a=ia();console.log(ra({usage:a,description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.",line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]",example:"typal src/index.js -c"}));process.exit()}else qa&&(console.log(require("../../package.json").version),process.exit());(async()=>{try{return pa?await Kc():oa?await yc():await Bc()}catch(a){process.env.DEBUG?console.log(a.stack):console.log(a.message)}})();
if(r.help){const a=ia();console.log(ra({usage:a,description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.",line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]",example:"typal src/index.js -c"}));process.exit()}else qa&&(console.log(require("../../package.json").version),process.exit());(async()=>{try{return pa?await Nc():oa?await Bc():await Ec()}catch(a){process.env.DEBUG?console.log(a.stack):console.log(a.message)}})();
{
"name": "typal",
"version": "2.0.1",
"version": "2.0.2",
"description": "Organises TypeDefs By Placing Them Into Types.Xml File To Be Embedded Into Source Code Compatible With VSCode And Google Closure Compiler, Generates Externs And Allows To Place Documentation In README Markdown.",

@@ -33,6 +33,31 @@ "main": "compile/index.js",

"bugs": {
"url": "https://gitlab.com/artdeco/issues/-/issues/",
"url": "https://github.com/art-deco/Issues",
"email": "issues+typal@adc.sh"
},
"homepage": "https://www.artd.eco"
"homepage": "https://www.artd.eco",
"devDependencies": {
"@artdeco/clean-stack": "^1.2.1",
"@artdeco/scripts.json": "^1.0.1",
"@typedefs/parser": "^1.3.4",
"@wrote/read": "^1.0.4",
"@wrote/read-dir-structure": "^1.3.1",
"@wrote/write": "^1.0.4",
"@zoroaster/mask": "^2.7.2",
"alamode": "^3.7.1",
"argufy": "^1.7.5",
"catchment": "^3.3.0",
"depack": "^1.1.2",
"documentary": "^1.38.7",
"erotic": "^2.1.1",
"erte": "^1.3.0",
"eslint-config-artdeco": "1.0.1",
"makepromise": "^3.2.0",
"mismatch": "^1.2.0",
"restream": "^3.7.4",
"rexml": "^2.2.2",
"temp-context": "^2.2.0",
"usually": "^1.2.0",
"yarn-s": "1.2.3",
"zoroaster": "^4.4.0"
}
}

@@ -20,5 +20,5 @@ <div align="center">

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/0.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/0.svg">
</a></p></div>

@@ -44,5 +44,5 @@ ## Table Of Contents

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/1.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/1.svg">
</a></p></div>

@@ -65,5 +65,5 @@ ## Purpose

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/2.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/2.svg">
</a></p></div>

@@ -148,5 +148,5 @@ ## CLI

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/3.svg?sanitize=true" width="25">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img width="25" alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/3.svg">
</a></p></div>

@@ -239,5 +239,5 @@ ### _Typal_ Arguments

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/4.svg?sanitize=true" width="25">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img width="25" alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/4.svg">
</a></p></div>

@@ -295,5 +295,5 @@ ### Missing Types Warnings

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/5.svg?sanitize=true" width="25">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img width="25" alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/5.svg">
</a></p></div>

@@ -375,5 +375,5 @@ ### Keeping Types In Separate File

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/6.svg?sanitize=true" width="25">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img width="25" alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/6.svg">
</a></p></div>

@@ -447,5 +447,5 @@ ### Migration

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/7.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/7.svg">
</a></p></div>

@@ -476,5 +476,5 @@ ## Schema

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/8.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/8.svg">
</a></p></div>

@@ -487,3 +487,2 @@ ## Markdown Documentation

__<a name="type-example">`Example`</a>__: An example type which can link to other types.

@@ -570,5 +569,5 @@ <table>

<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/9.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/9.svg">
</a></p></div>

@@ -588,8 +587,10 @@ ## Copyright & License

<th>© <a href="https://www.artd.eco">Art Deco™</a> 2020</th>
<th><a href="LICENSE"><img src=".documentary/agpl-3.0.svg" alt="AGPL-3.0"></a></th>
<th>
<a href="LICENSE"><img src="https://artdeco.gitlab.io/assets/licenses/agpl-3.0.svg" alt="AGPL-3.0"></a>
</th>
</tr>
</table>
<div align="center"><a href="#table-of-contents">
<img src="/.documentary/section-breaks/-1.svg?sanitize=true">
</a></div>
<div align="center"><p align="center"><a href="#table-of-contents">
<img alt="section break" src="https://artdeco.gitlab.io/typal/section-breaks/-1.svg">
</a></p></div>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc