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EAFe,EAAO,SAAS,aAGnC,KAAO,CAEH,MAAM,EAAS,SAAS,cAAc,UACtC,EAAO,MAAQ,EACf,EAAO,OAAS,EAChB,MAAM,EAAM,EAAO,WAAW,MAsB9B,GAnBI,IACA,EAAI,YACJ,EAAI,IAAI,EAAQ,EAAG,EAAS,EAAG,KAAK,IAAI,EAAO,GAAU,EAAG,EAAa,EAAV,KAAK,IACpE,EAAI,QAIR,EAAI,UAAY,EAChB,EAAI,SAAS,EAAG,EAAG,EAAO,GAG1B,EAAI,KAAO,EAGX,EAAI,UAAY,EAChB,EAAI,UAAY,EAChB,EAAI,aAAe,EAGf,EAAU,CACV,MAAM,EAAgB,GAAsB,EAAI,EAAqB,EACrE,EAAI,YAAc,EAClB,EAAI,UAAY,EAAY,EAAgB,EACxC,GACA,EAAI,YACJ,EAAI,IAAI,EAAQ,EAAG,EAAS,EAAG,KAAK,IAAI,EAAO,GAAU,EAAI,EAAgB,EAAG,EAAa,EAAV,KAAK,IACxF,EAAI,UAEJ,EAAI,WAAW,EAAG,EAAG,EAAO,EAEpC,CAGA,MAAM,EAAc,EAAI,YAAY,GAC9B,EAAa,EAAY,wBAA0B,EAAY,yBAC/D,EAAU,EAAS,EAAI,EAAa,EAAI,EAAY,wBAG1D,EAAI,SAAS,EAAM,EAAQ,EAAG,EAAY,EAAU,EAAS,GAGzD,IACA,EAAI,YAAc,EAClB,EAAI,UAAY,EAChB,EAAI,WAAW,EAAM,EAAQ,EAAG,EAAY,EAAU,EAAS,IAKnE,EADgB,EAAO,UAAU,aAErC,CACJ,CAAE,MAAO,GACL,QAAQ,MAAM,wCAAsC,GACpD,EAAO,EACX,IACF,GASV,OAAO,QAAU","file":"/npm/letter-avatar-image@0.1.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/letter-avatar-image@0.1.6/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","const { createCanvas } = require('canvas');\nconst allColors = require('./colors.json');\n\nconst Avatar = {\n    extractHexColors: () => {\n        return Object.values(allColors).map((color) => color.hex);\n    },\n\n    allConditionCheck: async ({ width, height, letter, font, textColor, textAlign, textBaseline, colors }) => {\n        return new Promise(async (resolve, reject) => {\n            try {\n                if (!letter || letter === null || letter === undefined || letter == '') {\n                    throw new Error(`Please provide the 'letter' configuration for the specified text. The first letter will be converted into an avatar image.`);\n                }\n                if (!colors?.length || colors == [] || colors === null || colors === undefined || colors === '') {\n                    throw new Error(`Invalid input: The colors array cannot be empty. Please provide at least one color in the array.`);\n                }\n                if (!width || width === null || width === undefined || width === '') {\n                    throw new Error(`Invalid input: The width field cannot be empty. Please provide a valid width value.`);\n                }\n                if (!height || height === null || height === undefined || height === '') {\n                    throw new Error(`Invalid input: The height field cannot be empty. Please provide a valid height value.`);\n                }\n                if (!font || font === null || font === undefined || font === '') {\n                    throw new Error(`Invalid input: The font field cannot be empty. Please provide a valid font value.`);\n                }\n                if (!textColor || textColor === null || textColor === undefined || textColor === '') {\n                    throw new Error(`Invalid input: The textColor field cannot be empty. Please provide a valid textColor value.`);\n                }\n                if (!textAlign || textAlign === null || textAlign === undefined || textAlign === '') {\n                    throw new Error(`Invalid input: The textAlign field cannot be empty. Please provide a valid textAlign value.`);\n                }\n                if (!textBaseline || textBaseline === null || textBaseline === undefined || textBaseline === '') {\n                    throw new Error(`Invalid input: The textAlign field cannot be empty. Please provide a valid textAlign value.`);\n                }\n                resolve(true);\n            } catch (error) {\n                reject(error);\n            }\n        });\n    },\n\n    LetterAvatar: async ({ width = 100, height = 100, letter = 'A', font = 'bold 60pt Graphiks', textColor = '#ffffff', textAlign = 'center', textBaseline = 'middle', strokeColor = '#000000', isStroke = false, strokeWidth = 1, isTextStroke = false, textStrokeColor = '#000000', textStrokeWidth = 1, colors = Avatar.extractHexColors(), singleColor = '', isRounded = false, roundedStrokeWidth = 1, isUpperCase = true, textCharacter = 0 }) => {\n        const isNode = typeof window === 'undefined';\n        return new Promise(async (resolve, reject) => {\n            try {\n                await Avatar.allConditionCheck({ width, height, letter, font, textColor, textAlign, textBaseline, colors });\n                const character = textCharacter === 0 ? letter?.charAt(textCharacter) : letter?.slice(0, textCharacter);\n                let text = isUpperCase ? character?.toUpperCase() : character;\n                const adjustedFont = isRounded ? font.replace(/\\d+pt/, `${Math.floor(parseInt(font.match(/\\d+/)[0]) * 0.8)}pt`) : font;\n                const randomColor = singleColor || colors[Math.floor(Math.random() * colors.length)];\n                if (isNode) {\n                    const canvas = createCanvas(width, height);\n                    const ctx = canvas.getContext('2d');\n\n                    if (isRounded) {\n                        ctx.beginPath();\n                        ctx.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, Math.PI * 2);\n                        ctx.clip();\n                    }\n\n                    ctx.fillStyle = randomColor;\n                    ctx.fillRect(0, 0, width, height);\n\n                    ctx.font = adjustedFont;\n\n                    ctx.fillStyle = textColor;\n                    ctx.textAlign = textAlign;\n                    ctx.textBaseline = textBaseline;\n\n                    if (isStroke) {\n                        const roundedStroke = roundedStrokeWidth <= 3 ? roundedStrokeWidth : 1;\n                        ctx.strokeStyle = strokeColor;\n                        ctx.lineWidth = isRounded ? roundedStroke : strokeWidth;\n                        if (isRounded) {\n                            ctx.beginPath();\n                            ctx.arc(width / 2, height / 2, Math.min(width, height) / 2 - roundedStroke / 2, 0, Math.PI * 2);\n                            ctx.stroke();\n                        } else {\n                            ctx.strokeRect(0, 0, width, height);\n                        }\n                    }\n\n                    const textMetrics = ctx.measureText(text);\n                    const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;\n                    const centerY = height / 2 - textHeight / 2 + textMetrics.actualBoundingBoxAscent;\n\n                    ctx.fillText(text, width / 2, isRounded ? centerY : height / 2);\n\n                    if (isTextStroke) {\n                        ctx.strokeStyle = textStrokeColor;\n                        ctx.lineWidth = textStrokeWidth;\n                        ctx.strokeText(text, width / 2, isRounded ? centerY : height / 2);\n                    }\n\n                    const buffer = canvas.toBuffer('image/png');\n\n                    resolve(buffer);\n                } else {\n                    // Browser (Frontend)\n                    const canvas = document.createElement('canvas');\n                    canvas.width = width;\n                    canvas.height = height;\n                    const ctx = canvas.getContext('2d');\n\n                    // Check for rounded shape\n                    if (isRounded) {\n                        ctx.beginPath();\n                        ctx.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, Math.PI * 2);\n                        ctx.clip();\n                    }\n\n                    // Set background color\n                    ctx.fillStyle = randomColor;\n                    ctx.fillRect(0, 0, width, height);\n\n                    // Adjust font size for rounded shapes\n                    ctx.font = adjustedFont;\n\n                    // Set text properties\n                    ctx.fillStyle = textColor;\n                    ctx.textAlign = textAlign;\n                    ctx.textBaseline = textBaseline;\n\n                    // Add border/stroke around the shape if needed\n                    if (isStroke) {\n                        const roundedStroke = roundedStrokeWidth <= 3 ? roundedStrokeWidth : 1;\n                        ctx.strokeStyle = strokeColor;\n                        ctx.lineWidth = isRounded ? roundedStroke : strokeWidth;\n                        if (isRounded) {\n                            ctx.beginPath();\n                            ctx.arc(width / 2, height / 2, Math.min(width, height) / 2 - roundedStroke / 2, 0, Math.PI * 2);\n                            ctx.stroke();\n                        } else {\n                            ctx.strokeRect(0, 0, width, height);\n                        }\n                    }\n\n                    // Measure text for vertical alignment\n                    const textMetrics = ctx.measureText(text);\n                    const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;\n                    const centerY = height / 2 - textHeight / 2 + textMetrics.actualBoundingBoxAscent;\n\n                    // Draw text\n                    ctx.fillText(text, width / 2, isRounded ? centerY : height / 2);\n\n                    // Add stroke to text if required\n                    if (isTextStroke) {\n                        ctx.strokeStyle = textStrokeColor;\n                        ctx.lineWidth = textStrokeWidth;\n                        ctx.strokeText(text, width / 2, isRounded ? centerY : height / 2);\n                    }\n\n                    // Convert canvas to data URL and resolve\n                    const dataURL = canvas.toDataURL('image/png');\n                    resolve(dataURL);\n                }\n            } catch (e) {\n                console.error('error in LetterAvatar =----->>    ', e);\n                reject(e);\n            }\n        });\n    },\n};\n\n// (async () => {\n//     const avtar = await Avatar.LetterAvatar({ font: 'bold 60pt Graphiks', letter: \"tirth\", isRounded: false, isUpperCase: true, isStroke: true });\n//     console.log('avtar :', avtar.toString('base64'));\n// })();\n\nmodule.exports = Avatar;\n"]}