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A+MA,EAAc,SAAW,EACzB,EAAc,YA5Kd,SAAqB,EAAO,GAExB,IAAI,EAAW,EAAK,OAAO,IAkB3B,OAhBA,EAAS,MAAK,SAAS,EAAI,GAEvB,IAAI,EAAO,EAAW,GAClB,EAAO,EAAW,GAClB,EAAI,EAAW,GAQnB,OANA,EAAO,EAAQ,GACf,EAAO,EAAQ,GACf,EAAI,EAAQ,GAEa,KAAK,KAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,GAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,GAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,IAC/F,KAAK,KAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,GAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,GAAK,KAAK,IAAI,EAAE,GAAK,EAAK,GAAI,GAG5H,IAEO,EAAS,GAAG,QAAQ,IAAK,GAEpC,CAwJH,CAtRD","file":"/npm/ryb-color-mixer@0.6.1/ryb-color-mixer.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/ryb-color-mixer@0.6.1/ryb-color-mixer.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","(function() {\n\n    // Real Life Color Mixer by Camilo Tapia (github.com/Camme)\n    // Emulate color mixing as if you where mixing real life colors, ie substractive colors\n    //\n    // Usage:\n    //\n    // RLColorMixer.mixColorS(arrayOfColors);\n    // where arrayOFColos is an array of hex rgb colors ['#ff0000', '#00ff00'] or an array with the amoutn of each color\n    // [{color: '#ff0000', parts: 10}, {color: '#00ff00', parts: 2}].\n    // or a mizture of the two.\n    //\n    // You can also snap to the nearest color in an array of hex rgb colors:\n    // RLColorMixer.findNearest(orgColorinHex, listOfColors);\n    //\n    // Example:\n    // RLColorMixer.findNearest('#fff000', ['#ff0000', '#ff0f00']);\n    //\n\n    var rybColorMixer = {};\n\n    var defaults = { result: \"ryb\", hex: true };\n\n    function mix() {\n\n\n        var options = JSON.parse(JSON.stringify(defaults));\n\n        // check if the last arguments is an options object\n        var lastObject = arguments[arguments.length - 1];\n        if (typeof lastObject == \"object\" && lastObject.constructor != Array) {\n            var customOptions = lastObject;\n            options.result = customOptions.result || options.result;\n            options.hex = typeof customOptions.hex != \"undefined\" ? customOptions.hex : options.hex;\n            arguments.length--;\n        }\n\n        var colors = [];\n\n        // check if we got an array, but not if the array is just a representation of hex\n        if (arguments[0].constructor == Array && typeof arguments[0][0] != \"number\") {\n            colors = arguments[0]; \n        } else {\n            colors = arguments; \n        }\n\n        //normalize, ie make sure all colors are in the same format\n        var normalized = [];\n        for(var i = 0, ii = colors.length; i < ii; i++){\n            var color = colors[i];\n            if (typeof color == \"string\") {\n                color = hexToArray(color);\n            }\n            normalized.push(color);\n        }\n\n        var newColor = mixRYB(normalized);\n\n        if (options.result == \"rgb\") {\n            newColor = rybToRgb(newColor);\n        } \n\n        if (options.hex) {\n            newColor = arrayToHex(newColor); \n        }\n\n        return newColor;\n\n    }\n\n    function mixRYB(colors) {\n\n        var newR = 0;\n        var newY = 0;\n        var newB = 0;\n\n        var total = 0;\n\n        var maxR = 0;\n        var maxY = 0;\n        var maxB = 0;\n\n        for(var i = 0, ii = colors.length; i < ii; i++){\n\n            var color = colors[i];\n\n            newR += color[0];\n            newY += color[1];\n            newB += color[2];\n\n        }\n\n        // Calculate the max of all sums for each color \n        var max = Math.max(newR, newY, newB);\n\n        // Now calculate each channel as a percentage of the max\n        var totalR = Math.floor(newR / max * 255);\n        var totalY = Math.floor(newY / max * 255);\n        var totalB = Math.floor(newB / max * 255);\n\n        return [totalR, totalY, totalB];\n\n    }\n\n    function findNearest(color, list) {\n\n        var listCopy = list.concat([]);\n\n        listCopy.sort(function(c1, c2) {\n            \n            var rgb1 = hexToArray(c1);\n            var rgb2 = hexToArray(c2);\n            var c = hexToArray(color);\n\n            rgb1 = rgb2hsv(rgb1);\n            rgb2 = rgb2hsv(rgb2);\n            c = rgb2hsv(c);\n\n            var euclideanDistance1 = Math.sqrt(Math.pow(c[0] - rgb1[0], 2) + Math.pow(c[1] - rgb1[1], 2) + Math.pow(c[2] - rgb1[2], 2));\n            var euclideanDistance2 = Math.sqrt(Math.pow(c[0] - rgb2[0], 2) + Math.pow(c[1] - rgb2[1], 2) + Math.pow(c[2] - rgb2[2], 2));\n            return euclideanDistance1 - euclideanDistance2;\n\n        });\n\n        return listCopy[0].replace(\"#\", \"\");\n\n    }\n\n    function hexToArray(hex) {\n        var hex = hex.replace(\"#\", '');\n        var r = parseInt(hex.substr(0, 2), 16);\n        var g = parseInt(hex.substr(2, 2), 16);\n        var b = parseInt(hex.substr(4, 2), 16);\n        return [r, g, b];\n    }\n\n\n    // taken from the INTERNET\n    function rgb2hsv (color) {\n        var rr, gg, bb,\n        r = color[0] / 255,\n        g = color[1] / 255,\n        b = color[2] / 255,\n        h, s,\n        v = Math.max(r, g, b),\n        diff = v - Math.min(r, g, b),\n        diffc = function(c){\n            return (v - c) / 6 / diff + 1 / 2;\n        };\n\n        if (diff == 0) {\n            h = s = 0;\n        } \n        else {\n            s = diff / v;\n            rr = diffc(r);\n            gg = diffc(g);\n            bb = diffc(b);\n\n            if (r === v) {\n                h = bb - gg;\n            }\n            else if (g === v) {\n                h = (1 / 3) + rr - bb;\n            }\n            else if (b === v) {\n                h = (2 / 3) + gg - rr;\n            }\n            if (h < 0) {\n                h += 1;\n            }\n            else if (h > 1) {\n                h -= 1;\n            }\n        }\n        return [\n            Math.round(h * 360),\n            Math.round(s * 100),\n            Math.round(v * 100)\n        ];\n    }\n\n    function arrayToHex(rgbArray) {\n        var rHex = Math.round(rgbArray[0]).toString(16); rHex = rHex.length == 1 ? \"0\" + rHex : rHex;\n        var gHex = Math.round(rgbArray[1]).toString(16); gHex = gHex.length == 1 ? \"0\" + gHex : gHex;\n        var bHex = Math.round(rgbArray[2]).toString(16); bHex = bHex.length == 1 ? \"0\" + bHex : bHex;\n        return rHex + gHex + bHex;;\n    }\n\n    function cubicInt(t, A, B){\n        var weight = t*t*(3-2*t);\n        return A + weight*(B-A);\n    }\n\n    function getR(iR, iY, iB) {\n        // red\n        var x0 = cubicInt(iB, 1.0, 0.163);\n        var x1 = cubicInt(iB, 1.0, 0.0);\n        var x2 = cubicInt(iB, 1.0, 0.5);\n        var x3 = cubicInt(iB, 1.0, 0.2);\n        var y0 = cubicInt(iY, x0, x1);\n        var y1 = cubicInt(iY, x2, x3);\n        return Math.ceil (255 * cubicInt(iR, y0, y1));\n    }\n\n    function getG(iR, iY, iB) {\n        // green\n        var x0 = cubicInt(iB, 1.0, 0.373);\n        var x1 = cubicInt(iB, 1.0, 0.66);\n        var x2 = cubicInt(iB, 0.0, 0.0);\n        var x3 = cubicInt(iB, 0.5, 0.094);\n        var y0 = cubicInt(iY, x0, x1);\n        var y1 = cubicInt(iY, x2, x3);\n        return Math.ceil (255 * cubicInt(iR, y0, y1));\n    }\n\n    function getB(iR, iY, iB) {\n        // blue\n        var x0 = cubicInt(iB, 1.0, 0.6);\n        var x1 = cubicInt(iB, 0.0, 0.2);\n        var x2 = cubicInt(iB, 0.0, 0.5);\n        var x3 = cubicInt(iB, 0.0, 0.0);\n        var y0 = cubicInt(iY, x0, x1);\n        var y1 = cubicInt(iY, x2, x3);\n        return Math.ceil (255 * cubicInt(iR, y0, y1));\n    }\n\n    function rybToRgb(color, options){\n\n        if (typeof color == \"string\") {\n            color = hexToArray(color);\n        }\n\n        var R = color[0] / 255;\n        var Y = color[1] / 255;\n        var B = color[2] / 255;\n        var R1 = getR(R,Y,B) ;\n        var G1 = getG(R,Y,B) ;\n        var B1 = getB(R,Y,B) ;\n        var ret = [ R1, G1, B1 ];\n\n        if (options && options.hex == true) {\n            ret = arrayToHex(ret);\n        }\n\n        return ret;\n    }\n\n    function rybToRgbHex(color) {\n        var rgb = rybToRgb(color);\n        return arrayToHex(rgb);\n    }\n\n    /**\n     * Return the complementary color values for a given color.\n     * You must also give it the upper limit of the color values, typically 255 for\n     * GUIs, 1.0 for OpenGL.\n     */\n    function complimentary(color, limit) {\n        var r = color[0], g = color[1], b = color[2];\n        limit = limit || 255;\n        return [limit - r, limit - g, limit - b];\n    }\n\n    if ( typeof define === \"function\" && define.amd && typeof window != \"undefined\") {\n        define( function() {\n            return rybColorMixer;\n        });\n    } else if (typeof window != \"undefined\") {\n        window.rybColorMixer = rybColorMixer;\n    } else if (module && exports) {\n        module.exports = rybColorMixer;\n    } \n\n    rybColorMixer.mix = mix;\n    rybColorMixer.rybToRgb = rybToRgb;\n    rybColorMixer.findNearest = findNearest;\n\n})();\n"]}