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,IAAI,SAAQ,IACf,EAAO,cAAc,GACrB,EAAO,OAAS,KACZ,IAAI,EAAQ,IAAI,MAChB,EAAM,IAAM,EAAO,OACnB,EAAM,OAAS,WACX,IAAI,EAAiB,qBAAqB,CACtC,iBACA,QACA,YACA,WACA,YACA,WACA,UACA,aAEJ,MAAM,EAAc,SAAS,IAC7B,OAAQ,GACJ,IAAK,OACD,MAAM,EAAO,UAAU,EAAgB,GACvC,EAAQ,GACR,MACJ,IAAK,OAID,MAAM,EAAU,UAAU,EAHX,EAAK,KACiB,WAAW,QAAQ,wBAAyB,IACzC,OAAO,EAAe,YACP,GACvD,EAAQ,GACR,MAEJ,QACI,EAAQ,GAEpB,CAAC,EAEL,EAAO,QAAW,IACd,MAAM,MAAM,KAAK,UAAU,GAAO,CACrC,GAGb,CAEI,MAAM,MAAM,kBAEpB,CA7JA,OAAO,eAAe,QAAS,aAAc,CAAE,OAAO,IACtD,QAAQ,sBAAmB,EA6J3B,QAAQ,iBAAmB","file":"/npm/@peacechen/react-image-file-resizer@1.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@peacechen/react-image-file-resizer@1.0.0/dist/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\";\n/**\n *\n * @author Onur Zorluer\n *\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.imageFileResizer = void 0;\nfunction changeHeightWidth(args) {\n    const { height: argHeight, maxHeight, maxWidth, minHeight, minWidth, width: argWidth, } = args;\n    if (maxHeight === minHeight && maxWidth === minWidth) {\n        // Respect fixed dimensions\n        return { height: maxHeight, width: maxWidth };\n    }\n    let height = argHeight;\n    let width = argWidth;\n    // Resize while preserving aspect ratio\n    if (argWidth > maxWidth) {\n        height = Math.round((argHeight * maxWidth) / argWidth);\n        width = maxWidth;\n    }\n    else if (minWidth && argWidth < minWidth) {\n        height = Math.round((argHeight * minWidth) / argWidth);\n        width = minWidth;\n    }\n    if (argHeight > maxHeight) {\n        width = Math.round((argWidth * maxHeight) / argHeight);\n        height = maxHeight;\n    }\n    else if (minHeight && argHeight < minHeight) {\n        width = Math.round((argWidth * minHeight) / argHeight);\n        height = minHeight;\n    }\n    return { height, width };\n}\nfunction resizeAndRotateImage(args) {\n    const { compressFormat = \"jpeg\", image, maxHeight, maxWidth, minHeight, minWidth, quality = 100, rotation, } = args;\n    var qualityDecimal = quality / 100;\n    var canvas = document.createElement(\"canvas\");\n    var width = image.width;\n    var height = image.height;\n    var newHeightWidth = changeHeightWidth({\n        height,\n        maxHeight,\n        maxWidth,\n        minHeight,\n        minWidth,\n        width,\n    });\n    if (rotation && (rotation === 90 || rotation === 270)) {\n        canvas.width = newHeightWidth.height;\n        canvas.height = newHeightWidth.width;\n    }\n    else {\n        canvas.width = newHeightWidth.width;\n        canvas.height = newHeightWidth.height;\n    }\n    width = newHeightWidth.width;\n    height = newHeightWidth.height;\n    var ctx = canvas.getContext(\"2d\");\n    if (!ctx)\n        throw new Error(\"Unable to create canvas\");\n    ctx.fillStyle = \"rgba(0, 0, 0, 0)\";\n    ctx.fillRect(0, 0, width, height);\n    if (ctx.imageSmoothingEnabled && ctx.imageSmoothingQuality) {\n        ctx.imageSmoothingQuality = 'high';\n    }\n    if (rotation) {\n        ctx.rotate((rotation * Math.PI) / 180);\n        if (rotation === 90) {\n            ctx.translate(0, -canvas.width);\n        }\n        else if (rotation === 180) {\n            ctx.translate(-canvas.width, -canvas.height);\n        }\n        else if (rotation === 270) {\n            ctx.translate(-canvas.height, 0);\n        }\n        else if (rotation === 0 || rotation === 360) {\n            ctx.translate(0, 0);\n        }\n    }\n    ctx.drawImage(image, 0, 0, width, height);\n    return canvas.toDataURL(`image/${compressFormat}`, qualityDecimal);\n}\nfunction b64toByteArrays(b64Data, contentType) {\n    contentType = contentType || \"image/jpeg\";\n    var sliceSize = 512;\n    var byteCharacters = atob(b64Data.toString().replace(/^data:image\\/(png|jpeg|jpg|webp);base64,/, \"\"));\n    var byteArrays = [];\n    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n        var slice = byteCharacters.slice(offset, offset + sliceSize);\n        var byteNumbers = new Array(slice.length);\n        for (var i = 0; i < slice.length; i++) {\n            byteNumbers[i] = slice.charCodeAt(i);\n        }\n        var byteArray = new Uint8Array(byteNumbers);\n        byteArrays.push(byteArray);\n    }\n    return byteArrays;\n}\nfunction b64toBlob(b64Data, contentType) {\n    const byteArrays = b64toByteArrays(b64Data, contentType);\n    var blob = new Blob(byteArrays, { type: contentType });\n    return blob;\n}\nfunction b64toFile(b64Data, fileName, contentType) {\n    const byteArrays = b64toByteArrays(b64Data, contentType);\n    const file = new File(byteArrays, fileName, { type: contentType });\n    return file;\n}\nasync function imageFileResizer(args) {\n    const { compressFormat = \"jpeg\", file, maxHeight, maxWidth, minHeight, minWidth, outputType = \"base64\", quality = 100, rotation = 0, } = args;\n    const reader = new FileReader();\n    if (file) {\n        if (file.type && !file.type.includes(\"image\")) {\n            throw Error(\"File Is NOT Image!\");\n        }\n        else {\n            return new Promise(resolve => {\n                reader.readAsDataURL(file);\n                reader.onload = () => {\n                    var image = new Image();\n                    image.src = reader.result;\n                    image.onload = function () {\n                        var resizedDataUrl = resizeAndRotateImage({\n                            compressFormat,\n                            image,\n                            maxHeight,\n                            maxWidth,\n                            minHeight,\n                            minWidth,\n                            quality,\n                            rotation,\n                        });\n                        const contentType = `image/${compressFormat}`;\n                        switch (outputType) {\n                            case \"blob\":\n                                const blob = b64toBlob(resizedDataUrl, contentType);\n                                resolve(blob);\n                                break;\n                            case \"file\":\n                                let fileName = file.name;\n                                let fileNameWithoutFormat = fileName.toString().replace(/(png|jpeg|jpg|webp)$/i, \"\");\n                                let newFileName = fileNameWithoutFormat.concat(compressFormat.toString());\n                                const newFile = b64toFile(resizedDataUrl, newFileName, contentType);\n                                resolve(newFile);\n                                break;\n                            case \"base64\":\n                            default:\n                                resolve(resizedDataUrl);\n                        }\n                    };\n                };\n                reader.onerror = (error) => {\n                    throw Error(JSON.stringify(error));\n                };\n            });\n        }\n    }\n    else {\n        throw Error(\"File Not Found!\");\n    }\n}\nexports.imageFileResizer = imageFileResizer;\n"]}