{"version":3,"sources":["jsdelivr-header.js","/npm/@petitchevalroux/base64-img-to-url@2.0.2/src/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aACA,MAAM,QAAU,QAAQ,WACpB,QAAU,QAAQ,YACtB,MAAM,UACF,WAAA,CAAY,GACJ,EAAQ,UACR,KAAK,SAAW,EAAQ,SACpB,EAAQ,oBACR,KAAK,kBAAoB,EAAQ,oBAGrC,KAAK,SAAW,EAEpB,KAAK,kBAAoB,KAAK,kBAAoB,KAAK,kBACnD,CACI,gBAAgB,EAE5B,CACA,OAAA,CAAQ,GACJ,MAAM,EAAO,KACb,IACI,MAAM,EAAI,QAAQ,KAAK,EAAM,EAAK,mBAC9B,EAAW,GACX,EAAU,EAAK,QAAQ,WAAa,EAoBxC,OAnBA,EAAE,qBACG,MAAK,CAAC,EAAO,KACV,MAAM,EAAO,EAAE,GACT,EAAQ,EAAK,KAAK,OACnB,MAAM,4BACP,GACA,EAAS,KACL,EACK,SACA,OAAO,IAAI,OAAO,EAAM,GAAI,UACzB,EAAM,IACT,MAAK,IAEF,EAAK,KAAK,MAAO,GACV,KAGvB,IAED,QACF,IAAI,GACJ,MAAK,IAEM,EACM,EAAE,OADE,EAAE,QACf,QAEjB,CAAE,MAAO,GACL,OAAO,QAAQ,OAAO,EAC1B,CACJ,EAGJ,OAAO,QAAU","file":"/npm/@petitchevalroux/base64-img-to-url@2.0.2/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@petitchevalroux/base64-img-to-url@2.0.2/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nconst cheerio = require(\"cheerio\"),\n    Promise = require(\"bluebird\");\nclass Base64Img {\n    constructor(options) {\n        if (options.uploader) {\n            this.uploader = options.uploader;\n            if (options.htmlParserOptions) {\n                this.htmlParserOptions = options.htmlParserOptions;\n            }\n        } else {\n            this.uploader = options;\n        }\n        this.htmlParserOptions = this.htmlParserOptions ? this.htmlParserOptions :\n            {\n                decodeEntities: false\n            };\n    }\n    replace(html) {\n        const self = this;\n        try {\n            const $ = cheerio.load(html, self.htmlParserOptions),\n                promises = [],\n                hasBody = html.indexOf(\"<body>\") > -1;\n            $(\"img[src^='data:']\")\n                .each((index, img) => {\n                    const $img = $(img);\n                    const match = $img.attr(\"src\")\n                        .match(/data:([^;]+);base64,(.*)/);\n                    if (match) {\n                        promises.push(\n                            self\n                                .uploader\n                                .upload(new Buffer(match[2], \"base64\"),\n                                    match[1])\n                                .then(url => {\n                                // Replace image source with url\n                                    $img.attr(\"src\", url);\n                                    return url;\n                                })\n                        );\n                    }\n                });\n            return Promise\n                .all(promises)\n                .then(() => {\n\n                    return !hasBody ? $(\"body\")\n                        .html() : $.html();\n                });\n        } catch (err) {\n            return Promise.reject(err);\n        }\n    }\n}\n\nmodule.exports = Base64Img;\n"]}