{"version":3,"sources":["../src/index.js"],"names":["PNG","throwError","isNodePattern","MIME_TYPE","PNG_FILTER_AUTO","PNG_FILTER_NONE","PNG_FILTER_SUB","PNG_FILTER_UP","PNG_FILTER_AVERAGE","PNG_FILTER_PATH","mime","constants","MIME_PNG","hasAlpha","decoders","sync","read","encoders","data","png","width","bitmap","height","write","deflateLevel","_deflateLevel","deflateStrategy","_deflateStrategy","filterType","_filterType","colorType","_colorType","_rgba","inputHasAlpha","class","l","cb","call","Math","round","s","f"],"mappings":";;AAAA,SAASA,GAAT,QAAoB,OAApB;AACA,SAASC,UAAT,EAAqBC,aAArB,QAA0C,aAA1C;AAEA,IAAMC,SAAS,GAAG,WAAlB,C,CAEA;;AACA,IAAMC,eAAe,GAAG,CAAC,CAAzB;AACA,IAAMC,eAAe,GAAG,CAAxB;AACA,IAAMC,cAAc,GAAG,CAAvB;AACA,IAAMC,aAAa,GAAG,CAAtB;AACA,IAAMC,kBAAkB,GAAG,CAA3B;AACA,IAAMC,eAAe,GAAG,CAAxB;AAEA,gBAAe;AAAA,SAAO;AACpBC,IAAAA,IAAI,sBAAKP,SAAL,EAAiB,CAAC,KAAD,CAAjB,CADgB;AAGpBQ,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAET,SADD;AAETC,MAAAA,eAAe,EAAfA,eAFS;AAGTC,MAAAA,eAAe,EAAfA,eAHS;AAITC,MAAAA,cAAc,EAAdA,cAJS;AAKTC,MAAAA,aAAa,EAAbA,aALS;AAMTC,MAAAA,kBAAkB,EAAlBA,kBANS;AAOTC,MAAAA,eAAe,EAAfA;AAPS,KAHS;AAapBI,IAAAA,QAAQ,sBAAKV,SAAL,EAAiB,IAAjB,CAbY;AAcpBW,IAAAA,QAAQ,sBAAKX,SAAL,EAAiBH,GAAG,CAACe,IAAJ,CAASC,IAA1B,CAdY;AAepBC,IAAAA,QAAQ,sBACLd,SADK,EACO,UAAAe,IAAI,EAAI;AACnB,UAAMC,GAAG,GAAG,IAAInB,GAA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aAAKP,WAAL,GAAmBS,IAAI,CAACC,KAAL,CAAWE,CAAX,CAAnB;;AAEA,YAAIvC,aAAa,CAACkC,EAAD,CAAjB,EAAuB;AACrBA,UAAAA,EAAE,CAACC,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,eAAO,IAAP;AACD,OAhFI;;AAiFL;;;;;;AAKIP,MAAAA,SAtFC,qBAsFSU,CAtFT,EAsFYJ,EAtFZ,EAsFgB;AACnB,YAAI,OAAOI,CAAP,KAAa,QAAjB,EAA2B;AACzB,iBAAOvC,UAAU,CAACoC,IAAX,CAAgB,IAAhB,EAAsB,oBAAtB,EAA4CD,EAA5C,CAAP;AACD;;AAED,YAAII,CAAC,KAAK,CAAN,IAAWA,CAAC,KAAK,CAAjB,IAAsBA,CAAC,KAAK,CAA5B,IAAiCA,CAAC,KAAK,CAA3C,EAA8C;AAC5C,iBAAOvC,UAAU,CAACoC,IAAX,CAAgB,IAAhB,EAAsB,gCAAtB,EAAwDD,EAAxD,CAAP;AACD;;AAED,aAAKL,UAAL,GAAkBO,IAAI,CAACC,KAAL,CAAWC,CAAX,CAAlB;;AAEA,YAAItC,aAAa,CAACkC,EAAD,CAAjB,EAAuB;AACrBA,UAAAA,EAAE,CAACC,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,eAAO,IAAP;AACD;AAtGI;AAzCa,GAAP;AAAA,CAAf","sourcesContent":["import { PNG } from 'pngjs';\nimport { throwError, isNodePattern } from '@jimp/utils';\n\nconst MIME_TYPE = 'image/png';\n\n// PNG filter types\nconst PNG_FILTER_AUTO = -1;\nconst PNG_FILTER_NONE = 0;\nconst PNG_FILTER_SUB = 1;\nconst PNG_FILTER_UP = 2;\nconst PNG_FILTER_AVERAGE = 3;\nconst PNG_FILTER_PATH = 4;\n\nexport default () => ({\n mime: { [MIME_TYPE]: ['png'] },\n\n constants: {\n MIME_PNG: MIME_TYPE,\n PNG_FILTER_AUTO,\n PNG_FILTER_NONE,\n PNG_FILTER_SUB,\n PNG_FILTER_UP,\n PNG_FILTER_AVERAGE,\n PNG_FILTER_PATH\n },\n\n hasAlpha: { [MIME_TYPE]: true },\n decoders: { [MIME_TYPE]: PNG.sync.read },\n encoders: {\n [MIME_TYPE]: data => {\n const png = new PNG({\n width: data.bitmap.width,\n height: data.bitmap.height\n });\n\n png.data = data.bitmap.data;\n\n return PNG.sync.write(png, {\n width: data.bitmap.width,\n height: data.bitmap.height,\n deflateLevel: data._deflateLevel,\n deflateStrategy: data._deflateStrategy,\n filterType: data._filterType,\n colorType:\n typeof data._colorType === 'number'\n ? data._colorType\n : data._rgba\n ? 6\n : 2,\n inputHasAlpha: data._rgba\n });\n }\n },\n\n class: {\n _deflateLevel: 9,\n _deflateStrategy: 3,\n _filterType: PNG_FILTER_AUTO,\n _colorType: null,\n\n /**\n * Sets the deflate level used when saving as PNG format (default is 9)\n * @param {number} l Deflate level to use 0-9. 0 is no compression. 9 (default) is maximum compression.\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n deflateLevel(l, cb) {\n if (typeof l !== 'number') {\n return throwError.call(this, 'l must be a number', cb);\n }\n\n if (l < 0 || l > 9) {\n return throwError.call(this, 'l must be a number 0 - 9', cb);\n }\n\n this._deflateLevel = Math.round(l);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n\n /**\n * Sets the deflate strategy used when saving as PNG format (default is 3)\n * @param {number} s Deflate strategy to use 0-3.\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n deflateStrategy(s, cb) {\n if (typeof s !== 'number') {\n return throwError.call(this, 's must be a number', cb);\n }\n\n if (s < 0 || s > 3) {\n return throwError.call(this, 's must be a number 0 - 3', cb);\n }\n\n this._deflateStrategy = Math.round(s);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n\n /**\n * Sets the filter type used when saving as PNG format (default is automatic filters)\n * @param {number} f The quality to use -1-4.\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n filterType(f, cb) {\n if (typeof f !== 'number') {\n return throwError.call(this, 'n must be a number', cb);\n }\n\n if (f < -1 || f > 4) {\n return throwError.call(\n this,\n 'n must be -1 (auto) or a number 0 - 4',\n cb\n );\n }\n\n this._filterType = Math.round(f);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n /**\n * Sets the color type used when saving as PNG format\n * @param {number} s color type to use 0, 2, 4, 6.\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */ colorType(s, cb) {\n if (typeof s !== 'number') {\n return throwError.call(this, 's must be a number', cb);\n }\n\n if (s !== 0 && s !== 2 && s !== 4 && s !== 6) {\n return throwError.call(this, 's must be a number 0, 2, 4, 6.', cb);\n }\n\n this._colorType = Math.round(s);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n }\n }\n});\n"],"file":"index.js"}