{"version":3,"sources":["../lib/index.ts"],"sourcesContent":["import * as minify from \"minify-literals\";\nimport type { Plugin, SourceMapInput } from \"rollup\";\nimport { createFilter } from \"@rollup/pluginutils\";\n\n/**\n * Plugin options.\n */\nexport interface Options {\n\t/**\n\t * Pattern or array of patterns of files to minify.\n\t */\n\tinclude?: string | string[];\n\t/**\n\t * Pattern or array of patterns of files not to minify.\n\t */\n\texclude?: string | string[];\n\t/**\n\t * Minify options, see\n\t * https://github.com/explodingcamera/esm/tree/main/packages/minify-literals#options.\n\t */\n\toptions?: Partial<minify.Options>;\n\t/**\n\t * If true, any errors while parsing or minifying will abort the bundle\n\t * process. Defaults to false, which will only show a warning.\n\t */\n\tfailOnError?: boolean;\n\t/**\n\t * Override minify-html-literals function.\n\t */\n\tminifyHTMLLiterals?: typeof minify.minifyHTMLLiterals;\n\t/**\n\t * Override include/exclude filter.\n\t */\n\tfilter?: (id: string) => boolean;\n}\n\nexport const minifyTemplateLiterals = function RollupPluginMinifyHTMLLiterals(options: Options = {}): Plugin {\n\toptions.minifyHTMLLiterals = options.minifyHTMLLiterals || minify.minifyHTMLLiterals;\n\toptions.filter = options.filter || createFilter(options.include, options.exclude);\n\tconst minifyOptions = options.options || {};\n\n\treturn {\n\t\tname: \"minify-literals\",\n\t\tasync transform(code, id) {\n\t\t\tif (!options.filter?.(id)) return;\n\n\t\t\ttry {\n\t\t\t\t// <SourceDescription>\n\t\t\t\tconst res = await options.minifyHTMLLiterals!(code, {\n\t\t\t\t\t...minifyOptions,\n\t\t\t\t\tfileName: id,\n\t\t\t\t});\n\n\t\t\t\tif (res === null || res?.code === code) return {};\n\n\t\t\t\treturn {\n\t\t\t\t\tcode: res.code,\n\t\t\t\t\tmap: res.map as SourceMapInput,\n\t\t\t\t};\n\t\t\t} catch (error: unknown) {\n\t\t\t\tif (!(error instanceof Error)) return;\n\t\t\t\t(options.failOnError ? this.error : this.warn)(error.message);\n\t\t\t}\n\n\t\t\treturn {};\n\t\t},\n\t};\n};\n\nexport default minifyTemplateLiterals;\nexport const RollupPluginMinifyHTMLLiterals = minifyTemplateLiterals;\n\n/**\n * @deprecated Use `minifyTemplateLiterals` instead.\n * @see {@link minifyTemplateLiterals}\n * @see {@link Options}\n * Remove in v2.0.0.\n */\nexport const minifyHTMLLiterals = minifyTemplateLiterals;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wCAAAA;AAAA,EAAA;AAAA,4BAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,aAAwB;AAExB,yBAA6B;AAkCtB,IAAM,yBAAyB,SAAS,+BAA+B,UAAmB,CAAC,GAAW;AAC5G,UAAQ,qBAAqB,QAAQ,sBAA6B;AAClE,UAAQ,SAAS,QAAQ,cAAU,iCAAa,QAAQ,SAAS,QAAQ,OAAO;AAChF,QAAM,gBAAgB,QAAQ,WAAW,CAAC;AAE1C,SAAO;AAAA,IACN,MAAM;AAAA,IACN,MAAM,UAAU,MAAM,IAAI;AACzB,UAAI,CAAC,QAAQ,SAAS,EAAE;AAAG;AAE3B,UAAI;AAEH,cAAM,MAAM,MAAM,QAAQ,mBAAoB,MAAM;AAAA,UACnD,GAAG;AAAA,UACH,UAAU;AAAA,QACX,CAAC;AAED,YAAI,QAAQ,QAAQ,KAAK,SAAS;AAAM,iBAAO,CAAC;AAEhD,eAAO;AAAA,UACN,MAAM,IAAI;AAAA,UACV,KAAK,IAAI;AAAA,QACV;AAAA,MACD,SAAS,OAAgB;AACxB,YAAI,EAAE,iBAAiB;AAAQ;AAC/B,SAAC,QAAQ,cAAc,KAAK,QAAQ,KAAK,MAAM,MAAM,OAAO;AAAA,MAC7D;AAEA,aAAO,CAAC;AAAA,IACT;AAAA,EACD;AACD;AAEA,IAAO,cAAQ;AACR,IAAMD,kCAAiC;AAQvC,IAAMC,sBAAqB;","names":["RollupPluginMinifyHTMLLiterals","minifyHTMLLiterals"]}