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AAQ,SAC3B,EAAM,OAAO,EAAU,GAErB,EAAQ,SACV,EAAM,QAAQ,KAAK,MAAM,EAAQ,UAI/B,EAAQ,WAAa,EAAQ,QAAS,CACxC,IAAI,EAAU,EAAQ,QAAQ,WAC1B,EAAQ,WAAa,EAAQ,UAC/B,GAAW,WAEb,GAAW,EAAQ,WAAY,IAAI,MAAO,cAAgB,GAC1D,EAAM,MAAM,UAAW,GAAI,GAAI,EAAS,EAAM,OAAO,MAAQ,IAC7D,EAAM,MAAM,KAAM,GAAI,GAAI,EAAS,EAAM,OAAO,MAAQ,GAC1D,CAYI,EAAQ,SACV,EAAM,UAAU,KAAK,MAAM,SAAS,EAAO,GAEzC,GAAI,EACF,OAAO,EAAS,GAGlB,EAAS,KAAM,EACjB,IAEA,EAAM,MAAM,GAAQ,SAAS,GAC3B,OAAI,EACK,EAAS,GAGX,EAAS,KAAM,EACxB,GAEJ,CACA,MAAO,GACL,EAAS,EACX,CACF,GACF,CA4CQ,CAAa,EAAQ,KAAM,EAAQ,OAAQ,GAAS,SAAS,EAAO,GAClE,OAAI,GACF,EAAO,GACA,MAGT,EAAQ,GACD,IACT,GACF,CACA,MAAO,GAEL,OADA,EAAO,GACA,GACT,CACF,GACF,GACF,IACG,MAAK,SAAS,GAKb,OAJI,EAAO,UACT,EAAO,SAAS,KAAM,GAGjB,CACT,IACC,OAAM,SAAS,GACd,GAAI,EAAO,SACT,OAAO,EAAO,SAAS,GAGzB,MAAM,CACR,GACJ,CAxOA,KAAK,SAAS,KAAK,oBAAoB,MAAK,SAAU,GACpD,KAAO,CACT,IACA,KAAK,SAAS,KAAK,oBAAoB,MAAK,SAAU,GACpD,UAAY,CACd,IAqOA,QAAU,OAAO,QAAU","file":"/npm/@senzil/desktop-screenshot@1.0.10-0/module.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@senzil/desktop-screenshot@1.0.10-0/module.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'\n\nvar path = require('path')\nvar jimp = require('jimp')\nvar fs = require('fs')\nvar capture = require('./capture')\nvar tmp = require('tmp')\nvar font, fontwhite\n\nvar validext = ['jpg', 'jpeg', 'png', 'bmp']\n\njimp.loadFont(jimp.FONT_SANS_16_BLACK).then(function (_font) {\n  font = _font\n})\njimp.loadFont(jimp.FONT_SANS_16_WHITE).then(function (_font) {\n  fontwhite = _font\n})\n\nfunction Screenshot() {\n\n  var config = parseArgs(Array.prototype.slice.call(arguments))\n\n  function parseArgs(args) {\n\n    var config = {\n      callback: null,\n      options: {\n        buffered: false,\n        caption: '',\n        extension: 'png',\n        multi: false,\n        noprocess: false,\n        output: '',\n        timestamp: true\n      }\n    }\n\n    for (var index in args) {\n      switch (typeof args[index]) {\n      case 'string':\n        config.options.output = path.normalize(args[index])\n        break\n      case 'function':\n        config.callback = args[index]\n        break\n      case 'object':\n        config.options = Object.assign(config.options, args[index])\n        break\n      }\n    }\n\n    return config\n  }\n\n  function checkConfig(){\n    if (!config.options.output) {\n      throw new Error('there is not configured output')\n    }\n\n    config.options.extension = path.extname(config.options.output).toLowerCase().substring(1) || 'png'\n    if (validext.indexOf(config.options.extension) === -1) {\n      throw new Error('The library only support png, jpeg and bpm output formats')\n    }\n\n    if (config.options.width != null && typeof config.options.width !== 'number'){\n      throw new Error('the width must be a number or nothing')\n    }\n\n    if (config.options.height != null && typeof config.options.height !== 'number'){\n      throw new Error('the height must be a number or nothing')\n    }\n\n    if (config.options.quality != null && (typeof config.options.quality !== 'number' || config.options.quality < 0 || config.options.quality >100)){\n      throw new Error('the quality must be a number beetween 0 to 100 or nothing')\n    }\n\n    if (!capture.hasOwnProperty(process.platform)){\n      throw new  Error('Unsupported platform ' + process.platform)\n    }\n\n    //there is no modification\n    if (!config.options.width\n      && !config.options.height\n      && !config.options.quality\n      && !config.options.timestamp\n      && !config.options.caption){\n      config.options.noprocess = true\n    }\n  }\n\n  function processImage(input, output, options, callback) {\n    if (!input){\n      return callback(new Error('No image to process.'))\n    }\n\n    new jimp(input, function (err, image) {\n\n      if (err){\n        return callback(err)\n      }\n      if (!image){\n        return callback(new Error('No image received from jimp.'))\n      }\n\n      var resWidth, resHeight\n\n      if (typeof options.width === 'number')\n        resWidth = Math.floor(options.width)\n      if (typeof options.height === 'number')\n        resHeight = Math.floor(options.height)\n\n      if (typeof resWidth === 'number' && typeof resHeight !== 'number') // resize to width, maintain aspect ratio\n        resHeight = Math.floor(image.bitmap.height * (resWidth / image.bitmap.width))\n      else if (typeof resHeight === 'number' && typeof resWidth !== 'number') // resize to height, maintain aspect ratio\n        resWidth = Math.floor(image.bitmap.width * (resHeight / image.bitmap.height))\n\n      try {\n        if (options.width || options.height) {\n          image.resize(resWidth, resHeight)\n        }\n        if (options.quality) {\n          image.quality(Math.floor(options.quality)) // only works with JPEGs\n        }\n\n\n        if (options.timestamp || options.caption) {\n          var caption = options.caption.toString()\n          if (options.timestamp && options.caption) {\n            caption += '\\r\\n - '\n          }\n          caption += options.timestamp ? new Date().toUTCString() : ''\n          image.print(fontwhite, 11, 11, caption, image.bitmap.width - 20) //shadow\n          image.print(font, 10, 10, caption, image.bitmap.width - 20)\n        }\n\n        /* USE THIS WITH NEXT JIMP VERSION >0.2.28\n        if (options.timestamp) {\n          image.print(font, 10, 10, {\n            alignmentX: jimp.HORIZONTAL_ALIGN_RIGHT,\n            alignmentY: jimp.VERTICAL_ALIGN_BOTTOM,\n            text: new Date().toUTCString()\n          })\n        }\n        */\n\n        if (options.buffered){\n          image.getBuffer(jimp.AUTO, function(error, buffer) {\n\n            if (error) {\n              return callback(error)\n            }\n\n            callback(null, buffer)\n          })\n        } else {\n          image.write(output, function(err){\n            if (err){\n              return callback(err)\n            }\n\n            return callback(null, output)\n          })\n        }\n      }\n      catch (error) {\n        callback(error)\n      }\n    })\n  }\n\n  return new Promise(function(resolve, reject) {\n\n    checkConfig()\n\n    tmp.file({ postfix: '.' + config.options.extension, discardDescriptor: true }, function _tempFileCreated(err, path, fd, cleanupCallback) {\n      if (err) {\n        return reject(err)\n      }\n\n      config.options.temp = path\n\n      capture[process.platform](config.options, function(error, options) {\n        // TODO add option for string, rather than file\n        if (error){\n          reject(error)\n          return cleanupCallback()\n        }\n\n        if (options.noprocess) {\n          return fs.readFile(config.options.temp, function (err, data) {\n            if (err) {\n              reject(err)\n              return cleanupCallback()\n            }\n            if (!options.buffered) {\n              return fs.writeFile(config.options.output, data, function (err) {\n                if (err) {\n                  reject(err)\n                  return cleanupCallback()\n                }\n\n                resolve(config.options.output)\n                return cleanupCallback()\n              })\n            }\n\n            resolve(data)\n            return cleanupCallback()\n          })\n        }\n\n        try {\n          processImage(options.temp, options.output, options, function(error, success) {\n            if (error){\n              reject(error)\n              return cleanupCallback()\n            }\n\n            resolve(success)\n            return cleanupCallback()\n          })\n        }\n        catch (e) {\n          reject(e)\n          return cleanupCallback()\n        }\n      })\n    })\n  })\n    .then(function(success){\n      if (config.callback) {\n        config.callback(null, success)\n      }\n\n      return success\n    })\n    .catch(function(e) {\n      if (config.callback) {\n        return config.callback(e)\n      }\n\n      throw e\n    })\n}\n\nexports = module.exports = Screenshot"]}