{"version":3,"sources":["../src/alignTransform.js"],"names":["rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","Markers","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","intoTags","alignTokens","nothingAfter","delim","description","postName","postType","postTag","spacings","postDelimiter","update","line","isEmpty","end","fields","reduce","map"],"mappings":";;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AASA,MAAM;AAACA,EAAAA;AAAD,IAAiBC,mBAAvB;AAEA,MAAMC,SAAS,GAAG;AAChBC,EAAAA,IAAI,EAAE,CADU;AAEhBC,EAAAA,KAAK,EAAE,CAFS;AAGhBC,EAAAA,GAAG,EAAE,CAHW;AAIhBC,EAAAA,IAAI,EAAE;AAJU,CAAlB;;AAOA,MAAMC,WAAW,GAAG,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAd,KAAyB;AAC3C,QAAML,GAAG,GAAGK,MAAM,CAACD,KAAD,CAAN,CAAcE,MAAd,CAAqBN,GAArB,CAAyBO,OAAzB,CAAiC,GAAjC,EAAsC,EAAtC,CAAZ;AACA,QAAMC,WAAW,GAAGL,IAAI,CAACM,QAAL,CAAcT,GAAd,CAApB;;AAEA,MAAIQ,WAAJ,EAAiB;AACf,WAAO,IAAP;AACD;;AAED,MAAIR,GAAG,KAAK,EAAZ,EAAgB;AACd,WAAO,KAAP;AACD;;AAED,OAAK,IAAIU,QAAQ,GAAGN,KAApB,EAA2BM,QAAQ,IAAI,CAAvC,EAA0CA,QAAQ,EAAlD,EAAsD;AACpD,UAAMC,WAAW,GAAGN,MAAM,CAACK,QAAD,CAAN,CAAiBJ,MAAjB,CAAwBN,GAAxB,CAA4BO,OAA5B,CAAoC,GAApC,EAAyC,EAAzC,CAApB;;AAEA,QAAII,WAAW,KAAK,EAApB,EAAwB;AACtB,UAAIR,IAAI,CAACM,QAAL,CAAcE,WAAd,CAAJ,EAAgC;AAC9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,OAAGmC;AAAZ,GAAD,KAAyB;AAC9B3B,IAAAA,KAAK,GAAGR,MAAM,CAACoC,MAAP,CAAc7B,QAAQ,CAACT,IAAD,CAAtB,EAA8B,EAAC,GAAGN;AAAJ,KAA9B,CAAR;AAEA,WAAOF,YAAY,CAAC,EAClB,GAAG6C,MADe;AAElBnC,MAAAA,MAAM,EAAEA,MAAM,CAACqC,GAAP,CAAWN,MAAX;AAFU,KAAD,CAAnB;AAID,GAPD;AAQD,CA1ID;;eA4Ied,c","sourcesContent":["/**\n * Transform based on https://github.com/syavorsky/comment-parser/blob/master/src/transforms/align.ts\n *\n * It contains some customizations to align based on the tags, and some custom options.\n */\n\nimport {\n\n // `comment-parser/primitives` export\n Markers,\n util,\n} from 'comment-parser';\n\nconst {rewireSource} = util;\n\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\n\nconst shouldAlign = (tags, index, source) => {\n const tag = source[index].tokens.tag.replace('@', '');\n const includesTag = tags.includes(tag);\n\n if (includesTag) {\n return true;\n }\n\n if (tag !== '') {\n return false;\n }\n\n for (let iterator = index; iterator >= 0; iterator--) {\n const previousTag = source[iterator].tokens.tag.replace('@', '');\n\n if (previousTag !== '') {\n if (tags.includes(previousTag)) {\n return true;\n }\n\n return false;\n }\n }\n\n return true;\n};\n\nconst getWidth = (tags) => {\n return (width, {tokens}, index, source) => {\n if (!shouldAlign(tags, index, source)) {\n return width;\n }\n\n return {\n name: Math.max(width.name, tokens.name.length),\n start: tokens.delimiter === Markers.start ? tokens.start.length : width.start,\n tag: Math.max(width.tag, tokens.tag.length),\n type: Math.max(width.type, tokens.type.length),\n };\n };\n};\n\nconst space = (len) => {\n return ''.padStart(len, ' ');\n};\n\nconst alignTransform = ({\n customSpacings,\n tags,\n indent,\n preserveMainDescriptionPostDelimiter,\n}) => {\n let intoTags = false;\n let width;\n\n const alignTokens = (tokens) => {\n const nothingAfter = {\n delim: false,\n name: false,\n tag: false,\n type: false,\n };\n\n if (tokens.description === '') {\n nothingAfter.name = true;\n tokens.postName = '';\n\n if (tokens.name === '') {\n nothingAfter.type = true;\n tokens.postType = '';\n\n if (tokens.type === '') {\n nothingAfter.tag = true;\n tokens.postTag = '';\n\n /* istanbul ignore next: Never happens because the !intoTags return. But it's here for consistency with the original align transform */\n if (tokens.tag === '') {\n nothingAfter.delim = true;\n }\n }\n }\n }\n\n // Todo: Avoid fixing alignment of blocks with multiline wrapping of type\n if (tokens.tag === '' && tokens.type) {\n return tokens;\n }\n\n const spacings = {\n postDelimiter: customSpacings?.postDelimiter || 1,\n postName: customSpacings?.postName || 1,\n postTag: customSpacings?.postTag || 1,\n postType: customSpacings?.postType || 1,\n };\n\n tokens.postDelimiter = nothingAfter.delim ? '' : space(spacings.postDelimiter);\n\n if (!nothingAfter.tag) {\n tokens.postTag = space(width.tag - tokens.tag.length + spacings.postTag);\n }\n if (!nothingAfter.type) {\n tokens.postType = space(width.type - tokens.type.length + spacings.postType);\n }\n if (!nothingAfter.name) {\n // If post name is empty for all lines (name width 0), don't add post name spacing.\n tokens.postName = width.name === 0 ? '' : space(width.name - tokens.name.length + spacings.postName);\n }\n\n return tokens;\n };\n\n const update = (line, index, source) => {\n const tokens = {...line.tokens};\n if (tokens.tag !== '') {\n intoTags = true;\n }\n\n const isEmpty =\n tokens.tag === '' &&\n tokens.name === '' &&\n tokens.type === '' &&\n tokens.description === '';\n\n // dangling '*/'\n if (tokens.end === Markers.end && isEmpty) {\n tokens.start = indent + ' ';\n\n return {\n ...line,\n tokens,\n };\n }\n\n /* eslint-disable indent */\n switch (tokens.delimiter) {\n case Markers.start:\n tokens.start = indent;\n break;\n case Markers.delim:\n tokens.start = indent + ' ';\n break;\n default:\n tokens.delimiter = '';\n\n // compensate delimiter\n tokens.start = indent + ' ';\n }\n /* eslint-enable */\n\n if (!intoTags) {\n if (tokens.description === '') {\n tokens.postDelimiter = '';\n } else if (!preserveMainDescriptionPostDelimiter) {\n tokens.postDelimiter = ' ';\n }\n\n return {\n ...line,\n tokens,\n };\n }\n\n // Not align.\n if (!shouldAlign(tags, index, source)) {\n return {\n ...line,\n tokens,\n };\n }\n\n return {\n ...line,\n tokens: alignTokens(tokens),\n };\n };\n\n return ({source, ...fields}) => {\n width = source.reduce(getWidth(tags), {...zeroWidth});\n\n return rewireSource({\n ...fields,\n source: source.map(update),\n });\n };\n};\n\nexport default alignTransform;\n"],"file":"alignTransform.js"}