{"version":3,"file":"stylesheets/1270.css?h=4a538ede11189113b1f7","mappings":"AAwPA,wBACA,qBACA","sources":["webpack://@studip/core/./resources/vue/components/StudipIdentImage.vue"],"sourcesContent":["<template>\n    <canvas v-show=\"showCanvas\" ref=\"canvas\"></canvas>\n</template>\n\n<script>\nexport default {\n    name: 'studip-ident-image',\n    props: {\n        value: {\n            type: String,\n        },\n        showCanvas: {\n            type: Boolean,\n            default: false,\n        },\n        baseColor: {\n            type: String, // hex color\n        },\n        pattern: {\n            type: String,\n            required: true,\n        },\n        width: {\n            type: Number,\n            default: 1080,\n        },\n        height: {\n            type: Number,\n            default: 720,\n        },\n        shapesMin: {\n            type: Number,\n            default: 5,\n        },\n        shapesMax: {\n            type: Number,\n            default: 8,\n        },\n    },\n    data() {\n        return {\n            random: null,\n            ellipse: null,\n        };\n    },\n    methods: {\n        randint(min, max) {\n            return Math.floor(this.random() * (max - min) + min);\n        },\n        renderIdentimage() {\n            let canvas = this.$refs.canvas;\n            canvas.width = this.width;\n            canvas.height = this.height;\n\n            const minSize = Math.min(this.width, this.height) * 0.2;\n            const ctx = canvas.getContext('2d');\n            const backgroundHSL = this.hexToHSL(this.baseColor);\n            const numShape = this.randint(this.shapesMin, this.shapesMax);\n            const shapeSizes = [];\n\n            ctx.fillStyle = this.hexToRgbA(this.baseColor, 0.8);\n            ctx.fillRect(0, 0, canvas.width, canvas.height);\n\n            const curveStart = this.randint(10, 70)/100 * this.height;\n            const curveEnd = this.randint(10, 70)/100 * this.height;\n            ctx.strokeStyle = `rgba(255, 255, 255, ${this.randint(50, 70) / 100})`;\n            const curvedistance = this.randint(20, 40);\n            const xFactor = this.randint(10, 45) / 100;\n            const yFactor = this.randint(10, 45) / 100;\n            for (let c = 0; c < numShape * 2; c++) {\n                ctx.beginPath();\n                ctx.moveTo(0, curveStart + curvedistance * c);\n                ctx.bezierCurveTo(this.width * xFactor, this.height * yFactor, this.width * (xFactor + 0.5), this.height * (yFactor + 0.5), this.width, curveEnd + curvedistance * c);\n                ctx.stroke();\n            }\n\n            for (let i = 0; i < numShape; i++) {\n                shapeSizes.push(this.randint(minSize*0.2, minSize*2) + minSize);\n            }\n\n            shapeSizes.sort((a, b) => {\n                return a < b ? 1 : a > b ? -1 : 0;\n            });\n\n            shapeSizes.forEach((shapeSizes, index) => {\n                const radius = shapeSizes / 2;\n                const [x, y] = this.createPointInEllipse(ctx);\n                const x_center = x * (this.width + radius / 2) - radius / 4;\n                const y_center = y * (this.height + radius / 2) - radius / 4;\n\n                ctx.fillStyle = `rgba(255, 255, 255, ${this.randint(10, 80) / 100})`;\n\n                ctx.beginPath();\n\n                if (index % 2 === 0) {\n                    ctx.arc(x_center, y_center, radius, 0, 2 * Math.PI);\n                } else {\n                    const size = radius;\n                    ctx.moveTo(x_center + size * Math.cos(0), y_center + size * Math.sin(0));\n\n                    for (let side = 0; side < 7; side++) {\n                        ctx.lineTo(\n                            x_center + size * Math.cos((side * 2 * Math.PI) / 6),\n                            y_center + size * Math.sin((side * 2 * Math.PI) / 6)\n                        );\n                    }\n                }\n\n                ctx.fill();\n            });\n\n            this.$emit('input', canvas.toDataURL());\n        },\n        createPointInEllipse(ctx) {\n            const x = this.random();\n            const y = this.random();\n\n            if (ctx.isPointInPath(this.ellipse, x, y)) {\n                return [x, y];\n            }\n\n            return this.createPointInEllipse(...arguments);\n        },\n\n        cyrb128(value) {\n            let h1 = 1779033703,\n                h2 = 3144134277,\n                h3 = 1013904242,\n                h4 = 2773480762;\n\n            for (let i = 0, k; i < value.length; i++) {\n                k = value.charCodeAt(i);\n                h1 = h2 ^ Math.imul(h1 ^ k, 597399067);\n                h2 = h3 ^ Math.imul(h2 ^ k, 2869860233);\n                h3 = h4 ^ Math.imul(h3 ^ k, 951274213);\n                h4 = h1 ^ Math.imul(h4 ^ k, 2716044179);\n            }\n\n            h1 = Math.imul(h3 ^ (h1 >>> 18), 597399067);\n            h2 = Math.imul(h4 ^ (h2 >>> 22), 2869860233);\n            h3 = Math.imul(h1 ^ (h3 >>> 17), 951274213);\n            h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);\n\n            return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];\n        },\n        sfc32(a, b, c, d) {\n            return function () {\n                a >>>= 0;\n                b >>>= 0;\n                c >>>= 0;\n                d >>>= 0;\n                var t = (a + b) | 0;\n                a = b ^ (b >>> 9);\n                b = (c + (c << 3)) | 0;\n                c = (c << 21) | (c >>> 11);\n                d = (d + 1) | 0;\n                t = (t + d) | 0;\n                c = (c + t) | 0;\n\n                return (t >>> 0) / 4294967296;\n            };\n        },\n\n        hexToRGB(color) {\n            color = color.slice(1); // remove #\n            let val = parseInt(color, 16);\n            let r = val >> 16;\n            let g = (val >> 8) & 0x00ff;\n            let b = val & 0x0000ff;\n\n            if (g > 255) {\n                g = 255;\n            } else if (g < 0) {\n                g = 0;\n            }\n            if (b > 255) {\n                b = 255;\n            } else if (b < 0) {\n                b = 0;\n            }\n\n            return { r: r, g: g, b: b };\n        },\n        RGBToHSL(r, g, b) {\n            r /= 255;\n            g /= 255;\n            b /= 255;\n\n            let cmin = Math.min(r, g, b),\n                cmax = Math.max(r, g, b),\n                delta = cmax - cmin,\n                h = 0,\n                s = 0,\n                l = 0;\n            if (delta == 0) h = 0;\n            // Red is max\n            else if (cmax == r) h = ((g - b) / delta) % 6;\n            // Green is max\n            else if (cmax == g) h = (b - r) / delta + 2;\n            // Blue is max\n            else h = (r - g) / delta + 4;\n\n            h = Math.round(h * 60);\n\n            if (h < 0) h += 360;\n            l = (cmax + cmin) / 2;\n\n            s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));\n\n            s = +(s * 100).toFixed(1);\n            l = +(l * 100).toFixed(1);\n\n            return { h: h, s: s, l: l };\n            // return 'hsl(' + h + ',' + s + '%,' + l + '%)';\n        },\n        hexToHSL(color) {\n            const RGB = this.hexToRGB(color);\n            return this.RGBToHSL(RGB.r, RGB.g, RGB.b);\n        },\n        hexToRgbA(hex, a){\n            const RGB = this.hexToRGB(hex);\n\n            return 'rgba(' + RGB.r + ',' + RGB.g + ',' + RGB.b + ',' + a +')';\n        },\n        init() {\n            const seed = this.cyrb128(this.pattern);\n            this.random = this.sfc32(...seed);\n            this.ellipse = new Path2D();\n            this.ellipse.ellipse(0.5, 0.5, 0.5, 0.5, 0, 0, Math.PI * 2);\n            this.renderIdentimage();\n        }\n    },\n    mounted() {\n        this.init();\n    },\n    watch: {\n        baseColor() {\n            this.init();\n        },\n    },\n};\n</script>\n<style scoped>\n  canvas {\n    background-color: #fff;\n  }\n</style>\n"],"names":[],"sourceRoot":""}