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,OAAE,EAAM,KAAE,EAAI,MAAE,EAAK,IAAE,EAAG,OAAE,EAAM,MAAE,GAAU,KAAK,QAC1D,EAAY,EAAQ,EAAO,MAAQ,IACnC,EAAa,EAAS,EAAO,OAAS,IAG5C,OAFA,EAAI,UAAY,EAET,IAAI,SAAS,SACF,IAAV,QAA+B,IAAR,EACvB,EAAI,SAAS,EAAO,MAAQ,EAAQ,EAAO,MAAQ,IAAM,EAAW,EAAM,EAAO,OAAS,IAAK,EAAW,QACzF,IAAV,QAAkC,IAAX,EAC9B,EAAI,SAAS,EAAO,MAAQ,EAAQ,EAAO,MAAQ,IAAM,EAAW,EAAO,OAAS,EAAS,EAAO,OAAS,IAAM,EAAY,EAAW,QAC1H,IAAT,QAAiC,IAAX,EAC7B,EAAI,SAAS,EAAO,EAAO,MAAQ,IAAK,EAAO,OAAS,EAAS,EAAO,OAAS,IAAM,EAAY,EAAW,GAE9G,EAAI,SAAS,EAAO,EAAO,MAAQ,IAAK,EAAM,EAAO,OAAS,IAAK,EAAW,GAElF,GAAS,GAEjB,EAIkB,oBAAX,aAAoD,IAAnB,OAAO,UAC/C,OAAO,QAAU,CAAE,8BAAgB,sBAAY,8BAAgB,gCAAiB","file":"/npm/@guymaster/badge-js@1.0.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/@guymaster/badge-js@1.0.4/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","/**\r\n * Class representing a badge generator.\r\n */\r\nclass BadgeGenerator {\r\n     /**\r\n     * Creates a badge generator.\r\n     * @param {string} canvasId - The ID of the canvas element.\r\n     * @param {{ downloadBtnId?: string, exportHeight?: number [2048], exportWidth?: number [2048], exportName?: string, isPhantom: boolean}} options - Configuration options.\r\n     */\r\n    constructor(canvasId, options) {\r\n        this.canvasId = canvasId;\r\n        this.canvas = document.getElementById(canvasId);\r\n        this.exportHeight = options.exportHeight?? 2048;\r\n        this.exportWidth = options.exportWidth?? 2048;\r\n        this.exportName = options.exportName?? \"Image\";\r\n        this.isPhantom = options.isPhantom?? false;\r\n        if (!this.canvas) {\r\n            throw new Error(\"Canvas element not found\");\r\n        }\r\n        if (options.downloadBtnId) {\r\n            this.downloadBtn = document.getElementById(options.downloadBtnId);\r\n            if (!this.downloadBtn) {\r\n                throw new Error(\"Download button element not found\");\r\n            }\r\n        }\r\n\r\n        window.addEventListener('resize', () => {\r\n            this.refresh();\r\n            this.draw();\r\n        });\r\n        this.layers = [];\r\n        this.refresh();\r\n        this.draw();\r\n        this.btnEventId = null;\r\n        if (this.downloadBtn) {\r\n            if (this.btnEventId) {\r\n                this.downloadBtn.removeEventListener('click', this.btnEventId);\r\n            }\r\n            this.btnEventId = async () => {\r\n                let url = await this.getDownloadURL();\r\n                let a = document.createElement('a');\r\n                a.href = 'data:image/png;base64,' + url.split(\",\")[1];\r\n                a.download = this.exportName + '.png';\r\n                document.body.appendChild(a);\r\n                a.click();\r\n                document.body.removeChild(a);\r\n            };\r\n        \r\n            this.downloadBtn.addEventListener('click', this.btnEventId);\r\n        }\r\n        if(!options.isPhantom){\r\n            this.phantomCanvas = document.createElement('canvas');\r\n            this.phantomCanvas.setAttribute('id', `${this.canvasId}-phantom`);\r\n            document.body.appendChild(this.phantomCanvas);\r\n            this.phantomCanvas.width = this.exportWidth;\r\n            this.phantomCanvas.height = this.exportHeight; \r\n            this.phantomCanvas.style.width = `${this.exportWidth}px`;\r\n            this.phantomCanvas.style.height = `${this.exportHeight}px`;\r\n            this.phantomCanvas.style.position = 'fixed';\r\n            this.phantomCanvas.style.top = `-${this.exportHeight}px`;\r\n            this.phantomCanvas.style.left = `-${this.exportWidth}px`;\r\n            this.phantomCanvas.style.zIndex = '-1';\r\n            this.phantomBadge = new BadgeGenerator(this.phantomCanvas.id, {isPhantom: true, exportHeight: this.exportHeight, exportWidth: this.exportWidth});\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Refreshes the size of the canvas.\r\n     */\r\n    async refresh(){\r\n        this.canvas.width = this.canvas.clientWidth;\r\n        this.canvas.height = this.canvas.clientHeight;\r\n        return this.draw();\r\n    }\r\n\r\n    /**\r\n     * Clears all layers from the badge.\r\n     */\r\n    async clear(){\r\n        this.layers = [];\r\n        if(!this.isPhantom){\r\n            await this.phantomBadge.clear();\r\n        }\r\n        await this.draw();\r\n        return Promise.resolve();\r\n    }\r\n\r\n    /**\r\n     * Adds a new layer to the badge.\r\n     * @param {BadgeLayer} layer - The layer to add.\r\n     */\r\n    async addLayer(layer) {\r\n        const copyLayer = Object.assign(Object.create(Object.getPrototypeOf(layer)), layer);\r\n        this.layers.push(layer);\r\n        if(this.phantomCanvas){\r\n            await this.phantomBadge.addLayer(copyLayer);\r\n        }\r\n        await this.draw();\r\n        setTimeout(() => {\r\n            const resizeEvent = new Event('resize');\r\n            window.dispatchEvent(resizeEvent);\r\n        }, 0);\r\n        if(this.isPhantom) return;\r\n    }\r\n\r\n    /**\r\n     * Generates a download URL for the badge.\r\n     * @returns {Promise<string>} The generated data URL.\r\n     */\r\n    async getDownloadURL() {\r\n        // const exportCanvas = document.createElement('canvas');\r\n        // exportCanvas.width = this.exportWidth;\r\n        // exportCanvas.height = this.exportHeight;\r\n        // const exportCtx = exportCanvas.getContext('2d');\r\n\r\n        // exportCtx.drawImage(this.canvas, 0, 0, this.exportWidth, this.exportHeight);\r\n        const exportCanvas = this.phantomCanvas;\r\n        return exportCanvas.toDataURL('image/png');\r\n    }\r\n\r\n    /**\r\n     * Draws the badge on the canvas.\r\n     * @returns {Promise<void>}\r\n     */\r\n    async draw() {\r\n        this.canvas.getContext(\"2d\").clearRect(0, 0, this.canvas.width, this.canvas.height);\r\n    \r\n        await Promise.all(this.layers.map(layer => layer.draw(this.canvas)));\r\n        return Promise.resolve();\r\n    }    \r\n}\r\n\r\n/**\r\n * Base class for badge layers.\r\n */\r\nclass BadgeLayer {\r\n    /**\r\n     * Creates a badge layer.\r\n     * @param {Object} options - Configuration options for the layer.\r\n     */\r\n    constructor(options = {}) {\r\n        this.options = options;\r\n        this.type = \"\";\r\n    }\r\n\r\n    /**\r\n     * Draws the layer on a given canvas.\r\n     * @param {HTMLCanvasElement} canvas - The canvas to draw on.\r\n     */\r\n    async draw() {}\r\n}\r\n\r\n/**\r\n * Class representing a text layer in the badge.\r\n */\r\nclass BadgeTextLayer extends BadgeLayer {\r\n    /**\r\n     * Creates a text layer.\r\n     * @param {string} text - The text content.\r\n     * @param {string} font - The font of the text.\r\n     * @param {{bottom?: function(renderedHeight: number, redenredWidth: number): number, left?: function(renderedHeight: number, redenredWidth: number): number, right?: function(renderedHeight: number, redenredWidth: number): number, top?: function(renderedHeight: number, redenredWidth: number): number, color?: string, size?: number}} options - Configuration options for the text layer.\r\n     */\r\n    constructor(text, font, options = {\r\n        bottom: undefined,\r\n        left: (renderedHeight, redenredWidth) => 0,\r\n        right: undefined,\r\n        top: (renderedHeight, redenredWidth) => 0,\r\n        color: \"black\",\r\n        size: 20\r\n    }) {\r\n        if(!((options.right!=undefined && options.top!=undefined) || (options.right!=undefined && options.bottom!=undefined) || (options.left!=undefined && options.bottom!=undefined) || (options.left!=undefined && options.top!=undefined))){\r\n            throw new Error(\"Only one of the following options should be set: right and top, right and bottom, left and bottom, left and top\");\r\n        }\r\n        super({\r\n            ...options,\r\n            left: 0,\r\n            top: 0,\r\n            bottom: 0,\r\n            right: 0\r\n        });\r\n        this.type = \"text\";\r\n        this.text = text;\r\n        this.font = font;\r\n        this.options.leftF = options.left;\r\n        this.options.topF = options.top;\r\n        this.options.bottomF = options.bottom;\r\n        this.options.rightF = options.right;\r\n    }\r\n\r\n    static getRenderedSize(text, font, size, canvas){\r\n        const c = document.createElement(\"canvas\");\r\n        const ctx = c.getContext('2d');\r\n        ctx.font = `${size}px ${font}`;\r\n        const textMetrics = ctx.measureText(text);\r\n        const renderedHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;\r\n        const redenredWidth = textMetrics.width;\r\n        return {height: renderedHeight, width: redenredWidth};\r\n    }\r\n\r\n    async draw(canvas) {\r\n        await document.fonts.ready;\r\n        const ctx = canvas.getContext(\"2d\");\r\n        ctx.font = `${this.options.size * canvas.height / 100}px ${this.font}`;\r\n        const { height, width } = BadgeTextLayer.getRenderedSize(this.text, this.font, this.options.size, canvas);\r\n        const renderedHeight = height;\r\n        const renderedWidth = width;\r\n        this.options.left = (this.options.leftF instanceof Function) ? this.options.leftF(renderedHeight, renderedWidth) : undefined;\r\n        this.options.top = (this.options.topF instanceof Function) ? this.options.topF(renderedHeight, renderedWidth) : undefined;\r\n        this.options.bottom = (this.options.bottomF instanceof Function) ? this.options.bottomF(renderedHeight, renderedWidth) : undefined;\r\n        this.options.right = (this.options.rightF instanceof Function) ? this.options.rightF(renderedHeight, renderedWidth) : undefined;\r\n        ctx.fillStyle = this.options.color;\r\n        const textMetrics = ctx.measureText(this.text);\r\n        const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;\r\n\r\n        return new Promise((resolve) => {\r\n            if (this.options.right !== undefined && this.options.top !== undefined) {\r\n                ctx.fillText(this.text, canvas.width - this.options.right * canvas.width / 100 - textMetrics.width, this.options.top * canvas.height / 100 + textHeight);\r\n            } else if (this.options.right !== undefined && this.options.bottom !== undefined) {\r\n                ctx.fillText(this.text, canvas.width - this.options.right * canvas.width / 100 - textMetrics.width, canvas.height - this.options.bottom * canvas.height / 100);\r\n            } else if (this.options.left !== undefined && this.options.bottom !== undefined) {\r\n                ctx.fillText(this.text, this.options.left * canvas.width / 100, canvas.height - this.options.bottom * canvas.height / 100);\r\n            } else {\r\n                ctx.fillText(this.text, this.options.left * canvas.width / 100, this.options.top * canvas.height / 100 + textHeight);\r\n            }\r\n            resolve();\r\n        });\r\n    }\r\n}\r\n\r\n/**\r\n * Class representing an image layer in the badge.\r\n */\r\nclass BadgeImageLayer extends BadgeLayer {\r\n    /**\r\n     * Creates an image layer.\r\n     * @param {string} imageSrc - The source URL of the image.\r\n     * @param {Object} options - Configuration options for the image layer.\r\n     */\r\n    constructor(imageSrc, options = {\r\n        bottom: undefined,\r\n        left: (renderedHeight, redenredWidth) => 0,\r\n        right: undefined,\r\n        top: (renderedHeight, redenredWidth) => 0,\r\n        width: 50,\r\n        height: 50\r\n    }) {\r\n        if(!((options.right!=undefined && options.top!=undefined) || (options.right!=undefined && options.bottom!=undefined) || (options.left!=undefined && options.bottom!=undefined) || (options.left!=undefined && options.top!=undefined))){\r\n            throw new Error(\"Only one of the following options should be set: right and top, right and bottom, left and bottom, left and top\");\r\n        }\r\n        super({\r\n            ...options,\r\n            left: 0,\r\n            top: 0,\r\n            bottom: 0,\r\n            right: 0\r\n        });\r\n        this.options = options;\r\n        this.type = \"image\";\r\n        this.image = new Image();\r\n        this.image.crossOrigin = \"anonymous\"; \r\n        this.image.src = imageSrc;\r\n        this.options.leftF = options.left;\r\n        this.options.topF = options.top;\r\n        this.options.bottomF = options.bottom;\r\n        this.options.rightF = options.right;\r\n    }\r\n\r\n    static getRenderedSize(image, width, height, canvas){\r\n        let imgWidth;\r\n        let imgHeight;\r\n        if(width == undefined && height != undefined){\r\n            imgHeight = (height * canvas.height) / 100;\r\n            imgWidth = (imgHeight * image.width) / image.height;\r\n        }\r\n        else if(width != undefined && height == undefined){\r\n            imgWidth = (width * canvas.width) / 100;\r\n            imgHeight = (imgWidth * image.height) / image.width;\r\n        }\r\n        else {\r\n            imgWidth = (width * canvas.width) / 100;\r\n            imgHeight = (height * canvas.height) / 100;\r\n        }\r\n        return {width: (imgWidth / canvas.width) * 100, height: (imgHeight / canvas.height) * 100};\r\n    }\r\n\r\n    async draw(canvas) {\r\n        const ctx = canvas.getContext(\"2d\");\r\n    \r\n        return new Promise((resolve, reject) => {\r\n            let imgWidth;\r\n            let imgHeight;\r\n            const drawImage = () => {\r\n                let width = this.options.width;\r\n                let height = this.options.height;\r\n                const rendered = BadgeImageLayer.getRenderedSize(this.image, width, height, canvas);\r\n                const rHeight = rendered.height;\r\n                const rWidth = rendered.width;\r\n                this.options.left = (this.options.leftF instanceof Function) ? this.options.leftF(rHeight, rWidth) : undefined;\r\n                this.options.top = (this.options.topF instanceof Function) ? this.options.topF(rHeight, rWidth) : undefined;\r\n                this.options.bottom = (this.options.bottomF instanceof Function) ? this.options.bottomF(rHeight, rWidth) : undefined;\r\n                this.options.right = (this.options.rightF instanceof Function) ? this.options.rightF(rHeight, rWidth) : undefined;\r\n                const top = this.options.top;\r\n                const right = this.options.right;\r\n                const bottom = this.options.bottom;\r\n                const left = this.options.left;\r\n                if(width == undefined && height != undefined){\r\n                    imgHeight = (height * canvas.height) / 100;\r\n                    imgWidth = (imgHeight * this.image.width) / this.image.height;\r\n                }\r\n                else if(width != undefined && height == undefined){\r\n                    imgWidth = (width * canvas.width) / 100;\r\n                    imgHeight = (imgWidth * this.image.height) / this.image.width;\r\n                }\r\n                else {\r\n                    imgWidth = (width * canvas.width) / 100;\r\n                    imgHeight = (height * canvas.height) / 100;\r\n                }\r\n                if (right !== undefined && top !== undefined) {\r\n                    ctx.drawImage(\r\n                        this.image,\r\n                        canvas.width - (right * canvas.width) / 100 - imgWidth,\r\n                        (top * canvas.height) / 100,\r\n                        imgWidth,\r\n                        imgHeight\r\n                    );\r\n                } else if (right !== undefined && bottom !== undefined) {\r\n                    ctx.drawImage(\r\n                        this.image,\r\n                        canvas.width - (right * canvas.width) / 100 - imgWidth,\r\n                        canvas.height - (bottom * canvas.height) / 100 - imgHeight,\r\n                        imgWidth,\r\n                        imgHeight\r\n                    );\r\n                } else if (left !== undefined && bottom !== undefined) {\r\n                    ctx.drawImage(\r\n                        this.image,\r\n                        (left * canvas.width) / 100,\r\n                        canvas.height - (bottom * canvas.height) / 100 - imgHeight,\r\n                        imgWidth,\r\n                        imgHeight\r\n                    );\r\n                } else {\r\n                    ctx.drawImage(\r\n                        this.image,\r\n                        (left * canvas.width) / 100,\r\n                        (top * canvas.height) / 100,\r\n                        imgWidth,\r\n                        imgHeight\r\n                    );\r\n                }\r\n                resolve();\r\n            };\r\n    \r\n            if (!this.image.src) {\r\n                return reject(new Error(\"No src provided for the image.\"));\r\n            }\r\n    \r\n            if (this.image.complete) {\r\n                drawImage();\r\n            } else {\r\n                this.image.onload = () => {\r\n                    drawImage();\r\n                };\r\n                this.image.onerror = () => {\r\n                    reject(new Error(\"Error loading image.\"));\r\n                };\r\n            }\r\n        });\r\n    }    \r\n}\r\n\r\n/**\r\n * Class representing a rectangle layer in the badge.\r\n */\r\nclass BadgeRectLayer extends BadgeLayer {\r\n    /**\r\n     * Creates a rectangle layer.\r\n     * @param {Object} options - Configuration options for the rectangle layer.\r\n     */\r\n    constructor(options = {\r\n        bottom: undefined,\r\n        left: 10,\r\n        right: undefined,\r\n        top: 80,\r\n        width: 50,\r\n        height: 50,\r\n        color: \"black\"\r\n    }) {\r\n        super(options);\r\n        this.options = options;\r\n        this.type = \"rect\";\r\n    }\r\n\r\n    async draw(canvas) {\r\n        const ctx = canvas.getContext(\"2d\");\r\n        const { width, height, left, right, top, bottom, color } = this.options;\r\n        const rectWidth = width * canvas.width / 100;\r\n        const rectHeight = height * canvas.height / 100;\r\n        ctx.fillStyle = color;\r\n\r\n        return new Promise((resolve) => {\r\n            if (right !== undefined && top !== undefined) {\r\n                ctx.fillRect(canvas.width - right * canvas.width / 100 - rectWidth, top * canvas.height / 100, rectWidth, rectHeight);\r\n            } else if (right !== undefined && bottom !== undefined) {\r\n                ctx.fillRect(canvas.width - right * canvas.width / 100 - rectWidth, canvas.height - bottom * canvas.height / 100 - rectHeight, rectWidth, rectHeight);\r\n            } else if (left !== undefined && bottom !== undefined) {\r\n                ctx.fillRect(left * canvas.width / 100, canvas.height - bottom * canvas.height / 100 - rectHeight, rectWidth, rectHeight);\r\n            } else {\r\n                ctx.fillRect(left * canvas.width / 100, top * canvas.height / 100, rectWidth, rectHeight);\r\n            }\r\n            resolve();\r\n        });\r\n    }\r\n}\r\n\r\n// ✅ CommonJS\r\nif (typeof module !== \"undefined\" && typeof module.exports !== \"undefined\") {\r\n    module.exports = { BadgeGenerator, BadgeLayer, BadgeTextLayer, BadgeImageLayer, BadgeRectLayer };\r\n}\r\n\r\n// // ✅ ES Modules\r\n// export { hello, BadgeGenerator, BadgeLayer, BadgeTextLayer, BadgeImageLayer, BadgeRectLayer };\r\n"]}