Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createRipple = ({ length }, event, hex, color, node) => {
const body = document.body
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const piTwo = Math.PI * 2
let rgb = hex ? convert.hex.rgb(hex).join(',') : '0,0,255'
rgb = color ? convert.keyword.rgb(color) : rgb
canvas.style.zIndex = 10000
canvas.style.top = 0
canvas.style.position = 'fixed'
let vw = (canvas.width = window.innerWidth)
let vh = (canvas.height = window.innerHeight)
body.appendChild(canvas)
// Event coords
const x = event.clientX
const y = event.clientY
// Delta - difference between event and farthest corner
const dx = x < vw / 2 ? vw - x : x
update = {
red: parseInt(args[0], 10),
green: parseInt(args[1], 10),
blue: parseInt(args[2], 10)
};
// If rgba(...)
if (args.length > 3) {
if (isPercentString(args[3])) {
args[3] = parseInt(args[3], 10) / 100;
}
update = RGB.ToScaledRGB(100 * parseFloat(args[3]), update);
}
} else {
// color name
return RGB.ToRGB(converter.keyword.rgb(input.toLowerCase()));
}
}
}
} else {
// color(red, green, blue)
update = {
red: red,
green: green,
blue: blue
};
}
return update;
};
this.green = param.green;
this.blue = param.blue;
this.alpha = param.alpha;
}
else {
let hex = param;
if (typeof param === "string") {
if (param.startsWith("#")) {
const hexString = param.substr(1);
const str = hexString.length < 4 ?
hexString.split("").map(char => char.repeat(2)).join("") :
hexString;
hex = Number.parseInt(str, 16);
}
else {
const rgb = convert.keyword.rgb(param.toLocaleLowerCase()) || [0, 0, 0];
this.red = rgb[0] / 0xff;
this.green = rgb[1] / 0xff;
this.blue = rgb[2] / 0xff;
}
}
if (typeof hex === "number") {
this.red = hexToRatio(hex, 2);
this.green = hexToRatio(hex, 1);
this.blue = hexToRatio(hex, 0);
}
const alpha = colorDefinition[1];
if (alpha !== undefined) {
this.alpha = constrain(alpha, 0, 1);
}
}
}
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
}
case 'named':
return {
name: converter.keyword.hex(source.input),
rgb: converter.keyword.rgb(source.input)
}
default:
throw new Error(`Unrecognised color space: ${source.space}`)
}
})(this.source)
function fromString(str) {
str = str.trim().replace(/^#/, '');
var matches = str.trim().match(/^(([a-fA-F0-9]{3}){1,2})/);
if (matches) {
setColor.apply(null, convert.hex.rgb(matches[1]));
return true;
} else if (str.length > 0) {
try {
setColor.apply(null, convert.keyword.rgb(str.trim().toLowerCase()));
return true;
} catch (e) { }
}
return false;
}
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
}
case 'named':
return {
name: converter.keyword.hex(source.input),
rgb: converter.keyword.rgb(source.input)
}
default:
throw new Error(`Unrecognised color space: ${source.space}`)
}
})(this.source)
name: converter.hsv.hex(source.input),
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
}
case 'named':
return {
name: converter.keyword.hex(source.input),
rgb: converter.keyword.rgb(source.input)
}
default:
throw new Error(`Unrecognised color space: ${source.space}`)
}
})(this.source)
name: converter.hsv.hex(source.input),
rgb: converter.hsv.rgb(source.input)
}
case 'HWB':
return {
name: converter.hwb.hex(source.input),
rgb: converter.hwb.rgb(source.input)
}
case 'SGR':
return {
name: source.input,
rgb: source.input
}
case 'named':
return {
name: converter.keyword.hex(source.input),
rgb: converter.keyword.rgb(source.input)
}
default:
throw new Error(`Unrecognised color space: ${source.space}`)
}
})(this.source)