Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

canvas-color

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-color - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

.babelrc

296

canvas-color.js

@@ -1,167 +0,191 @@

;(function(root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
return define(['exports'], factory);
} else if (typeof exports !== 'undefined') {
return factory(exports);
} else {
factory(root['CanvasColor'] || (root['CanvasColor'] = {}));
}
})(this, function(exports, undefined) {
'use strict';
'use strict';
var guid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
};
var guid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
};
var getBase64 = function(img, width, height) {
var canvas = document.createElement('canvas');
canvas.height = height;
canvas.width = width;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
};
var getBase64 = function(img, width, height) {
var canvas = document.createElement('canvas');
canvas.height = height;
canvas.width = width;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
};
function CanvasColor(options) {
this.image = options.image;
this.size = options.size || 50;
this.radius = options.radius || 1;
this.filter = options.filter;
this.onSuccess = options.onSuccess || function() {};
this.init();
}
function CanvasColor(options) {
this.image = options.image;
this.size = options.size || 50;
this.radius = options.radius || 1;
this.filter = options.filter;
this.onSuccess = options.onSuccess || function() {};
this.init();
}
CanvasColor.prototype.init = function() {
var that = this;
var canvas = document.createElement('canvas');
canvas.id = guid();
canvas.width = this.size;
canvas.height = this.size;
var context = canvas.getContext('2d');
CanvasColor.prototype.init = function() {
var that = this;
var canvas = document.createElement('canvas');
canvas.id = guid();
canvas.width = this.size;
canvas.height = this.size;
var context = canvas.getContext('2d');
if (typeof this.image === 'string') {
var img = new Image();
img.crossOrigin = '*';
img.src = this.image;
img.onload = function() {
context.drawImage(this, 0, 0, that.size, that.size);
var data = context.getImageData(0, 0, that.size, that.size).data;
var res = that.getRGB(data, that.size, that.size);
res.imgData = getBase64(img, this.width, this.height);
that.onSuccess(res);
};
} else {
context.drawImage(this.image, 0, 0, that.size, that.size);
if (typeof this.image === 'string') {
var img = new Image();
img.crossOrigin = '*';
img.src = this.image;
img.onload = function() {
context.drawImage(this, 0, 0, that.size, that.size);
var data = context.getImageData(0, 0, that.size, that.size).data;
var res = that.getRGB(data, that.size, that.size);
res.imgData = getBase64(this.image, this.image.width, this.image.height);
res.imgData = getBase64(img, this.width, this.height);
that.onSuccess(res);
}
};
};
} else {
context.drawImage(this.image, 0, 0, that.size, that.size);
var data = context.getImageData(0, 0, that.size, that.size).data;
var res = that.getRGB(data, that.size, that.size);
res.imgData = getBase64(this.image, this.image.width, this.image.height);
that.onSuccess(res);
}
};
CanvasColor.prototype.RGBtoHSV = function (rgb) {
var r = rgb[0],
g = rgb[1],
b = rgb[2];
CanvasColor.prototype.RGBtoHSV = function(rgb) {
var r = rgb[0];
var g = rgb[1];
var b = rgb[2];
r = r/255, g = g/255, b = b/255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, v = max;
r = r / 255;
g = g / 255;
b = b / 255;
var d = max - min;
s = max == 0 ? 0 : d / max;
var max = Math.max(r, g, b);
var min = Math.min(r, g, b);
var h;
var s;
var v = max;
if(max == min){
h = 0; // achromatic
}else{
switch(max){
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
var d = max - min;
s = max === 0 ? 0 : d / max;
if (max === min) {
h = 0; // achromatic
} else {
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0);
break;
case g:
h = (b - r) / d + 2;
break;
case b:
h = (r - g) / d + 4;
break;
}
h /= 6;
}
return [h, s, v];
};
return [h, s, v];
};
CanvasColor.prototype.HSVtoRGB = function(hsv) {
// in JS 1.7 use: var [h, s, l] = hsl;
var h = hsv[0];
var s = hsv[1];
var v = hsv[2];
var r;
var g;
var b;
CanvasColor.prototype.HSVtoRGB = function (hsv) {
// in JS 1.7 use: var [h, s, l] = hsl;
var h = hsv[0],
s = hsv[1],
v = hsv[2],
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
r, g, b;
switch (i % 6) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
case 5:
r = v;
g = p;
b = q;
break;
}
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
};
switch(i % 6){
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
CanvasColor.prototype.getRGB = function(data, width, height) {
var count = width * height;
var red = 0;
var green = 0;
var blue = 0;
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
};
var keys = Object.keys(data);
var total = keys.length;
CanvasColor.prototype.getRGB = function(data, width, height) {
var count = width * height;
var red = 0;
var green = 0;
var blue = 0;
for (var i = 0; i < total / 4; i++) {
var r = data[i * 4];
var g = data[i * 4 + 1];
var b = data[i * 4 + 2];
var keys = Object.keys(data);
var total = keys.length;
if (this.filter && this.filter(r, g, b)) {
continue;
}
for (var i = 0; i < total / 4; i++) {
var r = data[i * 4];
var g = data[i * 4 + 1];
var b = data[i * 4 + 2];
red += r;
green += g;
blue += b;
}
if (this.filter && this.filter(r, g, b)) {
continue;
}
red = red / count;
green = green / count;
blue = blue / count;
red += r;
green += g;
blue += b;
}
red = red > 255 ? 255 : red;
green = green > 255 ? 255 : green;
blue = blue > 255 ? 255 : blue;
red = red / count;
green = green / count;
blue = blue / count;
var hsv = this.RGBtoHSV([red, green, blue]);
red = red > 255 ? 255 : red;
green = green > 255 ? 255 : green;
blue = blue > 255 ? 255 : blue;
hsv[1] = 0.5;
hsv[2] = 0.5;
var hsv = this.RGBtoHSV([red, green, blue])
var rgb = this.HSVtoRGB(hsv);
hsv[1] = 0.5;
hsv[2] = 0.5;
var rgb = this.HSVtoRGB(hsv);
return {
red: Math.round(rgb[0]),
green: Math.round(rgb[1]),
blue: Math.round(rgb[2])
};
return {
red: Math.round(rgb[0]),
green: Math.round(rgb[1]),
blue: Math.round(rgb[2])
};
};
exports.CanvasColor = CanvasColor;
});
exports.CanvasColor = CanvasColor;

@@ -1,180 +0,1 @@

'use strict';
;(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
return define(['exports'], factory);
} else if (typeof exports !== 'undefined') {
return factory(exports);
} else {
factory(root['CanvasColor'] || (root['CanvasColor'] = {}));
}
})(undefined, function (exports, undefined) {
'use strict';
var guid = function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
};
var getBase64 = function getBase64(img, width, height) {
var canvas = document.createElement('canvas');
canvas.height = height;
canvas.width = width;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
};
function CanvasColor(options) {
this.image = options.image;
this.size = options.size || 50;
this.radius = options.radius || 1;
this.filter = options.filter;
this.onSuccess = options.onSuccess || function () {};
this.init();
}
CanvasColor.prototype.init = function () {
var that = this;
var canvas = document.createElement('canvas');
canvas.id = guid();
canvas.width = this.size;
canvas.height = this.size;
var context = canvas.getContext('2d');
if (typeof this.image === 'string') {
var img = new Image();
img.crossOrigin = '*';
img.src = this.image;
img.onload = function () {
context.drawImage(this, 0, 0, that.size, that.size);
var data = context.getImageData(0, 0, that.size, that.size).data;
var res = that.getRGB(data, that.size, that.size);
res.imgData = getBase64(img, this.width, this.height);
that.onSuccess(res);
};
} else {
context.drawImage(this.image, 0, 0, that.size, that.size);
var data = context.getImageData(0, 0, that.size, that.size).data;
var res = that.getRGB(data, that.size, that.size);
res.imgData = getBase64(this.image, this.image.width, this.image.height);
that.onSuccess(res);
}
};
CanvasColor.prototype.RGBtoHSV = function (rgb) {
var r = rgb[0],
g = rgb[1],
b = rgb[2];
r = r / 255, g = g / 255, b = b / 255;
var max = Math.max(r, g, b),
min = Math.min(r, g, b);
var h,
s,
v = max;
var d = max - min;
s = max == 0 ? 0 : d / max;
if (max == min) {
h = 0; // achromatic
} else {
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0);break;
case g:
h = (b - r) / d + 2;break;
case b:
h = (r - g) / d + 4;break;
}
h /= 6;
}
return [h, s, v];
};
CanvasColor.prototype.HSVtoRGB = function (hsv) {
// in JS 1.7 use: var [h, s, l] = hsl;
var h = hsv[0],
s = hsv[1],
v = hsv[2],
r,
g,
b;
var i = Math.floor(h * 6);
var f = h * 6 - i;
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p;break;
case 1:
r = q, g = v, b = p;break;
case 2:
r = p, g = v, b = t;break;
case 3:
r = p, g = q, b = v;break;
case 4:
r = t, g = p, b = v;break;
case 5:
r = v, g = p, b = q;break;
}
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
};
CanvasColor.prototype.getRGB = function (data, width, height) {
var count = width * height;
var red = 0;
var green = 0;
var blue = 0;
var keys = Object.keys(data);
var total = keys.length;
for (var i = 0; i < total / 4; i++) {
var r = data[i * 4];
var g = data[i * 4 + 1];
var b = data[i * 4 + 2];
if (this.filter && this.filter(r, g, b)) {
continue;
}
red += r;
green += g;
blue += b;
}
red = red / count;
green = green / count;
blue = blue / count;
red = red > 255 ? 255 : red;
green = green > 255 ? 255 : green;
blue = blue > 255 ? 255 : blue;
var hsv = this.RGBtoHSV([red, green, blue]);
hsv[1] = 0.5;
hsv[2] = 0.5;
var rgb = this.HSVtoRGB(hsv);
return {
red: Math.round(rgb[0]),
green: Math.round(rgb[1]),
blue: Math.round(rgb[2])
};
};
exports.CanvasColor = CanvasColor;
});
!function(n){function l(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return n[t].call(o.exports,o,o.exports,l),o.l=!0,o.exports}var e={};l.m=n,l.c=e,l.d=function(n,e,t){l.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:t})},l.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return l.d(e,"a",e),e},l.o=function(n,l){return Object.prototype.hasOwnProperty.call(n,l)},l.p="/dist",l(l.s=0)}([function(n,l,e){"use strict";function t(n){o.f[3]++,o.s[12]++,this.image=n.image,o.s[13]++,this.size=(o.b[1][0]++,n.size||(o.b[1][1]++,50)),o.s[14]++,this.radius=(o.b[2][0]++,n.radius||(o.b[2][1]++,1)),o.s[15]++,this.filter=n.filter,o.s[16]++,this.onSuccess=(o.b[3][0]++,n.onSuccess||(o.b[3][1]++,function(){o.f[4]++})),o.s[17]++,this.init()}var o=function(){var n="/Users/ziv/github/canvas-color/canvas-color.js",l="affec9d7923ba62c13a386cb4a1c2d7afea564d9",e=new Function("return this")(),t="__macaca_coverage__",o={path:"/Users/ziv/github/canvas-color/canvas-color.js",statementMap:{0:{start:{line:3,column:11},end:{line:9,column:1}},1:{start:{line:4,column:2},end:{line:8,column:5}},2:{start:{line:5,column:12},end:{line:5,column:34}},3:{start:{line:6,column:12},end:{line:6,column:41}},4:{start:{line:7,column:4},end:{line:7,column:26}},5:{start:{line:11,column:16},end:{line:18,column:1}},6:{start:{line:12,column:15},end:{line:12,column:47}},7:{start:{line:13,column:2},end:{line:13,column:25}},8:{start:{line:14,column:2},end:{line:14,column:23}},9:{start:{line:15,column:12},end:{line:15,column:35}},10:{start:{line:16,column:2},end:{line:16,column:27}},11:{start:{line:17,column:2},end:{line:17,column:28}},12:{start:{line:21,column:2},end:{line:21,column:29}},13:{start:{line:22,column:2},end:{line:22,column:33}},14:{start:{line:23,column:2},end:{line:23,column:36}},15:{start:{line:24,column:2},end:{line:24,column:31}},16:{start:{line:25,column:2},end:{line:25,column:54}},17:{start:{line:26,column:2},end:{line:26,column:14}},18:{start:{line:29,column:0},end:{line:55,column:2}},19:{start:{line:30,column:13},end:{line:30,column:17}},20:{start:{line:31,column:15},end:{line:31,column:47}},21:{start:{line:32,column:2},end:{line:32,column:21}},22:{start:{line:33,column:2},end:{line:33,column:27}},23:{start:{line:34,column:2},end:{line:34,column:28}},24:{start:{line:35,column:16},end:{line:35,column:39}},25:{start:{line:37,column:2},end:{line:54,column:3}},26:{start:{line:38,column:14},end:{line:38,column:25}},27:{start:{line:39,column:4},end:{line:39,column:26}},28:{start:{line:40,column:4},end:{line:40,column:25}},29:{start:{line:41,column:4},end:{line:47,column:6}},30:{start:{line:42,column:6},end:{line:42,column:58}},31:{start:{line:43,column:17},end:{line:43,column:70}},32:{start:{line:44,column:16},end:{line:44,column:55}},33:{start:{line:45,column:6},end:{line:45,column:60}},34:{start:{line:46,column:6},end:{line:46,column:26}},35:{start:{line:49,column:4},end:{line:49,column:62}},36:{start:{line:50,column:15},end:{line:50,column:68}},37:{start:{line:51,column:14},end:{line:51,column:53}},38:{start:{line:52,column:4},end:{line:52,column:77}},39:{start:{line:53,column:4},end:{line:53,column:24}},40:{start:{line:57,column:0},end:{line:93,column:2}},41:{start:{line:58,column:10},end:{line:58,column:16}},42:{start:{line:59,column:10},end:{line:59,column:16}},43:{start:{line:60,column:10},end:{line:60,column:16}},44:{start:{line:62,column:2},end:{line:62,column:14}},45:{start:{line:63,column:2},end:{line:63,column:14}},46:{start:{line:64,column:2},end:{line:64,column:14}},47:{start:{line:66,column:12},end:{line:66,column:29}},48:{start:{line:67,column:12},end:{line:67,column:29}},49:{start:{line:70,column:10},end:{line:70,column:13}},50:{start:{line:72,column:10},end:{line:72,column:19}},51:{start:{line:73,column:2},end:{line:73,column:30}},52:{start:{line:75,column:2},end:{line:90,column:3}},53:{start:{line:76,column:4},end:{line:76,column:10}},54:{start:{line:78,column:4},end:{line:88,column:5}},55:{start:{line:80,column:6},end:{line:80,column:40}},56:{start:{line:81,column:6},end:{line:81,column:12}},57:{start:{line:83,column:6},end:{line:83,column:26}},58:{start:{line:84,column:6},end:{line:84,column:12}},59:{start:{line:86,column:6},end:{line:86,column:26}},60:{start:{line:87,column:6},end:{line:87,column:12}},61:{start:{line:89,column:4},end:{line:89,column:11}},62:{start:{line:92,column:2},end:{line:92,column:19}},63:{start:{line:95,column:0},end:{line:144,column:2}},64:{start:{line:97,column:10},end:{line:97,column:16}},65:{start:{line:98,column:10},end:{line:98,column:16}},66:{start:{line:99,column:10},end:{line:99,column:16}},67:{start:{line:104,column:10},end:{line:104,column:27}},68:{start:{line:105,column:10},end:{line:105,column:19}},69:{start:{line:106,column:10},end:{line:106,column:21}},70:{start:{line:107,column:10},end:{line:107,column:25}},71:{start:{line:108,column:10},end:{line:108,column:31}},72:{start:{line:110,column:2},end:{line:141,column:3}},73:{start:{line:112,column:4},end:{line:112,column:10}},74:{start:{line:113,column:4},end:{line:113,column:10}},75:{start:{line:114,column:4},end:{line:114,column:10}},76:{start:{line:115,column:4},end:{line:115,column:10}},77:{start:{line:117,column:4},end:{line:117,column:10}},78:{start:{line:118,column:4},end:{line:118,column:10}},79:{start:{line:119,column:4},end:{line:119,column:10}},80:{start:{line:120,column:4},end:{line:120,column:10}},81:{start:{line:122,column:4},end:{line:122,column:10}},82:{start:{line:123,column:4},end:{line:123,column:10}},83:{start:{line:124,column:4},end:{line:124,column:10}},84:{start:{line:125,column:4},end:{line:125,column:10}},85:{start:{line:127,column:4},end:{line:127,column:10}},86:{start:{line:128,column:4},end:{line:128,column:10}},87:{start:{line:129,column:4},end:{line:129,column:10}},88:{start:{line:130,column:4},end:{line:130,column:10}},89:{start:{line:132,column:4},end:{line:132,column:10}},90:{start:{line:133,column:4},end:{line:133,column:10}},91:{start:{line:134,column:4},end:{line:134,column:10}},92:{start:{line:135,column:4},end:{line:135,column:10}},93:{start:{line:137,column:4},end:{line:137,column:10}},94:{start:{line:138,column:4},end:{line:138,column:10}},95:{start:{line:139,column:4},end:{line:139,column:10}},96:{start:{line:140,column:4},end:{line:140,column:10}},97:{start:{line:143,column:2},end:{line:143,column:73}},98:{start:{line:146,column:0},end:{line:189,column:2}},99:{start:{line:147,column:14},end:{line:147,column:28}},100:{start:{line:148,column:12},end:{line:148,column:13}},101:{start:{line:149,column:14},end:{line:149,column:15}},102:{start:{line:150,column:13},end:{line:150,column:14}},103:{start:{line:152,column:13},end:{line:152,column:30}},104:{start:{line:153,column:14},end:{line:153,column:25}},105:{start:{line:155,column:2},end:{line:167,column:3}},106:{start:{line:156,column:12},end:{line:156,column:23}},107:{start:{line:157,column:12},end:{line:157,column:27}},108:{start:{line:158,column:12},end:{line:158,column:27}},109:{start:{line:160,column:4},end:{line:162,column:5}},110:{start:{line:161,column:6},end:{line:161,column:15}},111:{start:{line:164,column:4},end:{line:164,column:13}},112:{start:{line:165,column:4},end:{line:165,column:15}},113:{start:{line:166,column:4},end:{line:166,column:14}},114:{start:{line:169,column:2},end:{line:169,column:20}},115:{start:{line:170,column:2},end:{line:170,column:24}},116:{start:{line:171,column:2},end:{line:171,column:22}},117:{start:{line:173,column:2},end:{line:173,column:30}},118:{start:{line:174,column:2},end:{line:174,column:36}},119:{start:{line:175,column:2},end:{line:175,column:33}},120:{start:{line:177,column:12},end:{line:177,column:45}},121:{start:{line:179,column:2},end:{line:179,column:15}},122:{start:{line:180,column:2},end:{line:180,column:15}},123:{start:{line:182,column:12},end:{line:182,column:30}},124:{start:{line:184,column:2},end:{line:188,column:4}},125:{start:{line:191,column:0},end:{line:191,column:34}}},fnMap:{0:{name:"(anonymous_0)",decl:{start:{line:3,column:11},end:{line:3,column:12}},loc:{start:{line:3,column:22},end:{line:9,column:1}},line:3},1:{name:"(anonymous_1)",decl:{start:{line:4,column:65},end:{line:4,column:66}},loc:{start:{line:4,column:77},end:{line:8,column:3}},line:4},2:{name:"(anonymous_2)",decl:{start:{line:11,column:16},end:{line:11,column:17}},loc:{start:{line:11,column:45},end:{line:18,column:1}},line:11},3:{name:"CanvasColor",decl:{start:{line:20,column:9},end:{line:20,column:20}},loc:{start:{line:20,column:30},end:{line:27,column:1}},line:20},4:{name:"(anonymous_4)",decl:{start:{line:25,column:40},end:{line:25,column:41}},loc:{start:{line:25,column:51},end:{line:25,column:53}},line:25},5:{name:"(anonymous_5)",decl:{start:{line:29,column:29},end:{line:29,column:30}},loc:{start:{line:29,column:40},end:{line:55,column:1}},line:29},6:{name:"(anonymous_6)",decl:{start:{line:41,column:17},end:{line:41,column:18}},loc:{start:{line:41,column:28},end:{line:47,column:5}},line:41},7:{name:"(anonymous_7)",decl:{start:{line:57,column:33},end:{line:57,column:34}},loc:{start:{line:57,column:47},end:{line:93,column:1}},line:57},8:{name:"(anonymous_8)",decl:{start:{line:95,column:33},end:{line:95,column:34}},loc:{start:{line:95,column:47},end:{line:144,column:1}},line:95},9:{name:"(anonymous_9)",decl:{start:{line:146,column:31},end:{line:146,column:32}},loc:{start:{line:146,column:61},end:{line:189,column:1}},line:146}},branchMap:{0:{loc:{start:{line:6,column:12},end:{line:6,column:41}},type:"cond-expr",locations:[{start:{line:6,column:24},end:{line:6,column:25}},{start:{line:6,column:28},end:{line:6,column:41}}],line:6},1:{loc:{start:{line:22,column:14},end:{line:22,column:32}},type:"binary-expr",locations:[{start:{line:22,column:14},end:{line:22,column:26}},{start:{line:22,column:30},end:{line:22,column:32}}],line:22},2:{loc:{start:{line:23,column:16},end:{line:23,column:35}},type:"binary-expr",locations:[{start:{line:23,column:16},end:{line:23,column:30}},{start:{line:23,column:34},end:{line:23,column:35}}],line:23},3:{loc:{start:{line:25,column:19},end:{line:25,column:53}},type:"binary-expr",locations:[{start:{line:25,column:19},end:{line:25,column:36}},{start:{line:25,column:40},end:{line:25,column:53}}],line:25},4:{loc:{start:{line:37,column:2},end:{line:54,column:3}},type:"if",locations:[{start:{line:37,column:2},end:{line:54,column:3}},{start:{line:37,column:2},end:{line:54,column:3}}],line:37},5:{loc:{start:{line:73,column:6},end:{line:73,column:29}},type:"cond-expr",locations:[{start:{line:73,column:18},end:{line:73,column:19}},{start:{line:73,column:22},end:{line:73,column:29}}],line:73},6:{loc:{start:{line:75,column:2},end:{line:90,column:3}},type:"if",locations:[{start:{line:75,column:2},end:{line:90,column:3}},{start:{line:75,column:2},end:{line:90,column:3}}],line:75},7:{loc:{start:{line:78,column:4},end:{line:88,column:5}},type:"switch",locations:[{start:{line:79,column:4},end:{line:81,column:12}},{start:{line:82,column:4},end:{line:84,column:12}},{start:{line:85,column:4},end:{line:87,column:12}}],line:78},8:{loc:{start:{line:80,column:25},end:{line:80,column:38}},type:"cond-expr",locations:[{start:{line:80,column:33},end:{line:80,column:34}},{start:{line:80,column:37},end:{line:80,column:38}}],line:80},9:{loc:{start:{line:110,column:2},end:{line:141,column:3}},type:"switch",locations:[{start:{line:111,column:2},end:{line:115,column:10}},{start:{line:116,column:2},end:{line:120,column:10}},{start:{line:121,column:2},end:{line:125,column:10}},{start:{line:126,column:2},end:{line:130,column:10}},{start:{line:131,column:2},end:{line:135,column:10}},{start:{line:136,column:2},end:{line:140,column:10}}],line:110},10:{loc:{start:{line:160,column:4},end:{line:162,column:5}},type:"if",locations:[{start:{line:160,column:4},end:{line:162,column:5}},{start:{line:160,column:4},end:{line:162,column:5}}],line:160},11:{loc:{start:{line:160,column:8},end:{line:160,column:43}},type:"binary-expr",locations:[{start:{line:160,column:8},end:{line:160,column:19}},{start:{line:160,column:23},end:{line:160,column:43}}],line:160},12:{loc:{start:{line:173,column:8},end:{line:173,column:29}},type:"cond-expr",locations:[{start:{line:173,column:20},end:{line:173,column:23}},{start:{line:173,column:26},end:{line:173,column:29}}],line:173},13:{loc:{start:{line:174,column:10},end:{line:174,column:35}},type:"cond-expr",locations:[{start:{line:174,column:24},end:{line:174,column:27}},{start:{line:174,column:30},end:{line:174,column:35}}],line:174},14:{loc:{start:{line:175,column:9},end:{line:175,column:32}},type:"cond-expr",locations:[{start:{line:175,column:22},end:{line:175,column:25}},{start:{line:175,column:28},end:{line:175,column:32}}],line:175}},s:{0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:0,30:0,31:0,32:0,33:0,34:0,35:0,36:0,37:0,38:0,39:0,40:0,41:0,42:0,43:0,44:0,45:0,46:0,47:0,48:0,49:0,50:0,51:0,52:0,53:0,54:0,55:0,56:0,57:0,58:0,59:0,60:0,61:0,62:0,63:0,64:0,65:0,66:0,67:0,68:0,69:0,70:0,71:0,72:0,73:0,74:0,75:0,76:0,77:0,78:0,79:0,80:0,81:0,82:0,83:0,84:0,85:0,86:0,87:0,88:0,89:0,90:0,91:0,92:0,93:0,94:0,95:0,96:0,97:0,98:0,99:0,100:0,101:0,102:0,103:0,104:0,105:0,106:0,107:0,108:0,109:0,110:0,111:0,112:0,113:0,114:0,115:0,116:0,117:0,118:0,119:0,120:0,121:0,122:0,123:0,124:0,125:0},f:{0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0},b:{0:[0,0],1:[0,0],2:[0,0],3:[0,0],4:[0,0],5:[0,0],6:[0,0],7:[0,0,0],8:[0,0],9:[0,0,0,0,0,0],10:[0,0],11:[0,0],12:[0,0],13:[0,0],14:[0,0]},_coverageSchema:"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c"},i=e[t]||(e[t]={});return i[n]&&i[n].hash===l?i[n]:(o.hash=l,i[n]=o)}();o.s[0]++;var i=function(){return o.f[0]++,o.s[1]++,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){o.f[1]++;var l=(o.s[2]++,16*Math.random()|0),e=(o.s[3]++,"x"===n?(o.b[0][0]++,l):(o.b[0][1]++,3&l|8));return o.s[4]++,e.toString(16)})};o.s[5]++;var c=function(n,l,e){o.f[2]++;var t=(o.s[6]++,document.createElement("canvas"));o.s[7]++,t.height=e,o.s[8]++,t.width=l;var i=(o.s[9]++,t.getContext("2d"));return o.s[10]++,i.drawImage(n,0,0),o.s[11]++,t.toDataURL()};o.s[18]++,t.prototype.init=function(){o.f[5]++;var n=(o.s[19]++,this),l=(o.s[20]++,document.createElement("canvas"));o.s[21]++,l.id=i(),o.s[22]++,l.width=this.size,o.s[23]++,l.height=this.size;var e=(o.s[24]++,l.getContext("2d"));if(o.s[25]++,"string"==typeof this.image){o.b[4][0]++;var t=(o.s[26]++,new Image);o.s[27]++,t.crossOrigin="*",o.s[28]++,t.src=this.image,o.s[29]++,t.onload=function(){o.f[6]++,o.s[30]++,e.drawImage(this,0,0,n.size,n.size);var l=(o.s[31]++,e.getImageData(0,0,n.size,n.size).data),i=(o.s[32]++,n.getRGB(l,n.size,n.size));o.s[33]++,i.imgData=c(t,this.width,this.height),o.s[34]++,n.onSuccess(i)}}else{o.b[4][1]++,o.s[35]++,e.drawImage(this.image,0,0,n.size,n.size);var u=(o.s[36]++,e.getImageData(0,0,n.size,n.size).data),s=(o.s[37]++,n.getRGB(u,n.size,n.size));o.s[38]++,s.imgData=c(this.image,this.image.width,this.image.height),o.s[39]++,n.onSuccess(s)}},o.s[40]++,t.prototype.RGBtoHSV=function(n){o.f[7]++;var l=(o.s[41]++,n[0]),e=(o.s[42]++,n[1]),t=(o.s[43]++,n[2]);o.s[44]++,l/=255,o.s[45]++,e/=255,o.s[46]++,t/=255;var i,c,u=(o.s[47]++,Math.max(l,e,t)),s=(o.s[48]++,Math.min(l,e,t)),m=(o.s[49]++,u),a=(o.s[50]++,u-s);if(o.s[51]++,c=0===u?(o.b[5][0]++,0):(o.b[5][1]++,a/u),o.s[52]++,u===s)o.b[6][0]++,o.s[53]++,i=0;else{switch(o.b[6][1]++,o.s[54]++,u){case l:o.b[7][0]++,o.s[55]++,i=(e-t)/a+(e<t?(o.b[8][0]++,6):(o.b[8][1]++,0)),o.s[56]++;break;case e:o.b[7][1]++,o.s[57]++,i=(t-l)/a+2,o.s[58]++;break;case t:o.b[7][2]++,o.s[59]++,i=(l-e)/a+4,o.s[60]++}o.s[61]++,i/=6}return o.s[62]++,[i,c,m]},o.s[63]++,t.prototype.HSVtoRGB=function(n){o.f[8]++;var l,e,t,i=(o.s[64]++,n[0]),c=(o.s[65]++,n[1]),u=(o.s[66]++,n[2]),s=(o.s[67]++,Math.floor(6*i)),m=(o.s[68]++,6*i-s),a=(o.s[69]++,u*(1-c)),r=(o.s[70]++,u*(1-m*c)),d=(o.s[71]++,u*(1-(1-m)*c));switch(o.s[72]++,s%6){case 0:o.b[9][0]++,o.s[73]++,l=u,o.s[74]++,e=d,o.s[75]++,t=a,o.s[76]++;break;case 1:o.b[9][1]++,o.s[77]++,l=r,o.s[78]++,e=u,o.s[79]++,t=a,o.s[80]++;break;case 2:o.b[9][2]++,o.s[81]++,l=a,o.s[82]++,e=u,o.s[83]++,t=d,o.s[84]++;break;case 3:o.b[9][3]++,o.s[85]++,l=a,o.s[86]++,e=r,o.s[87]++,t=u,o.s[88]++;break;case 4:o.b[9][4]++,o.s[89]++,l=d,o.s[90]++,e=a,o.s[91]++,t=u,o.s[92]++;break;case 5:o.b[9][5]++,o.s[93]++,l=u,o.s[94]++,e=a,o.s[95]++,t=r,o.s[96]++}return o.s[97]++,[Math.round(255*l),Math.round(255*e),Math.round(255*t)]},o.s[98]++,t.prototype.getRGB=function(n,l,e){o.f[9]++;var t=(o.s[99]++,l*e),i=(o.s[100]++,0),c=(o.s[101]++,0),u=(o.s[102]++,0),s=(o.s[103]++,Object.keys(n)),m=(o.s[104]++,s.length);o.s[105]++;for(var a=0;a<m/4;a++){var r=(o.s[106]++,n[4*a]),d=(o.s[107]++,n[4*a+1]),b=(o.s[108]++,n[4*a+2]);o.s[109]++,(o.b[11][0]++,this.filter&&(o.b[11][1]++,this.filter(r,d,b)))?(o.b[10][0]++,o.s[110]++):(o.b[10][1]++,o.s[111]++,i+=r,o.s[112]++,c+=d,o.s[113]++,u+=b)}o.s[114]++,i/=t,o.s[115]++,c/=t,o.s[116]++,u/=t,o.s[117]++,i=i>255?(o.b[12][0]++,255):(o.b[12][1]++,i),o.s[118]++,c=c>255?(o.b[13][0]++,255):(o.b[13][1]++,c),o.s[119]++,u=u>255?(o.b[14][0]++,255):(o.b[14][1]++,u);var h=(o.s[120]++,this.RGBtoHSV([i,c,u]));o.s[121]++,h[1]=.5,o.s[122]++,h[2]=.5;var f=(o.s[123]++,this.HSVtoRGB(h));return o.s[124]++,{red:Math.round(f[0]),green:Math.round(f[1]),blue:Math.round(f[2])}},o.s[125]++,l.CanvasColor=t}]);

@@ -5,3 +5,2 @@ 'use strict';

var getUrlParams = function(name) {

@@ -54,3 +53,3 @@ var results = new RegExp(`[\\?&]${name}=([^&#]*)`).exec(location.href);

img.crossOrigin = '*';
img.src = image || `//avatars1.githubusercontent.com/u/9607546?v=4&s=400`;
img.src = image || '//avatars1.githubusercontent.com/u/9607546?v=4&s=400';
img.onload = function() {

@@ -57,0 +56,0 @@ new CanvasColor.CanvasColor({

{
"name": "canvas-color",
"version": "2.1.3",
"description": "color",
"version": "2.1.4",
"description": "canvas color picker",
"keywords": [

@@ -15,23 +15,33 @@ "color"

"devDependencies": {
"babel": "~5.8.23",
"babel-core": "^6.17.0",
"babel-loader": "^7.1.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-env": "^1.6.1",
"babel-preset-latest": "^6.24.1",
"co-mocha": "*",
"istanbul": "^0.4.5",
"jshint": "*",
"mocha": "*",
"babel-preset-stage-2": "^6.22.0",
"cross-env": "^5.1.2",
"eslint": "^4.12.1",
"eslint-plugin-mocha": "^4.11.0",
"istanbul-instrumenter-loader": "^3.0.0",
"macaca-cli": "^2.0.12",
"macaca-coverage": "^1.0.0",
"macaca-electron": "^1.1.17",
"macaca-reporter": "^1.0.36",
"macaca-wd": "^1.0.18",
"pre-commit": "*",
"should": "*",
"webpack": "^3.5.3",
"webpack-dev-server": "^2.7.1"
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},
"pre-commit": [
"lint"
],
"scripts": {
"dev": "webpack-dev-server",
"lint": "eslint --fix . test",
"serve": "npm run dev &",
"test": "macaca run -d ./test --reporter macaca-reporter",
"prepublish": "npm run build",
"build": "babel canvas-color.js --out-dir dist/ -D && webpack -p",
"server": "webpack-dev-server"
"build": "cross-env NODE_ENV=production webpack -p --progress --hide-modules",
"ci": "npm run lint && npm run serve && npm run test"
},
"homepage": "https://github.com/xudafeng/canvas-color",
"license": "MIT"
}

@@ -5,2 +5,5 @@ # canvas-color

[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

@@ -11,2 +14,8 @@ [npm-image]: https://img.shields.io/npm/v/canvas-color.svg?style=flat-square

[travis-url]: https://travis-ci.org/xudafeng/canvas-color
[coveralls-image]: https://img.shields.io/coveralls/xudafeng/canvas-color.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/xudafeng/canvas-color?branch=master
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/canvas-color.svg?style=flat-square
[download-url]: https://npmjs.org/package/canvas-color

@@ -17,3 +26,3 @@ > canvas color picker

``` javascript
```javascript
new CanvasColorPicker({

@@ -20,0 +29,0 @@ image: 'https://avatars2.githubusercontent.com/u/9263023?v=4&s=400',

@@ -0,40 +1,54 @@

const fs = require('fs');
const path = require('path');
class WebpackAfterAllPlugin {
apply (compiler) {
compiler.plugin('done', (compilation) => {
setTimeout(() => {
fs.writeFileSync(path.join(__dirname, '.ready'), '');
}, 1000);
});
}
}
const pkg = require('./package');
module.exports = {
entry: {
index: path.resolve(__dirname, './index')
index: path.resolve(__dirname, 'index'),
[pkg.name]: path.resolve(__dirname, pkg.name)
},
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/build',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist',
filename: '[name].js'
},
externals: [
{
}
],
module: {
loaders: [
{
test: /\.less$/,
loader: 'style!css!less'
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'istanbul-instrumenter-loader',
query: {
esModules: true,
coverageVariable: '__macaca_coverage__'
}
},
{
test: /\.json$/,
loader: 'json',
exclude: /node_modules/
},
{
test: /\.js[x]?$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'latest'],
plugins: []
}
}
}
]
}
},
plugins: [
new WebpackAfterAllPlugin()
]
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc