css-color-parser-h 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +384 -6
- package/dist/css-color-parser-h.common.js +517 -210
- package/dist/css-color-parser-h.common.min.js +1 -1
- package/dist/css-color-parser-h.umd.js +986 -210
- package/dist/css-color-parser-h.umd.min.js +1 -1
- package/example.html +10 -48
- package/package.json +6 -4
- package/readme.md +94 -56
- package/@types/css-color-parser-h.d.ts +0 -230
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Parser=e():r.Parser=e()}(this,(function(){return function(){var r={208:function(r,e,n){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var n=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=n){var t,a,o,i,u=[],s=!0,c=!1;try{if(o=(n=n.call(r)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(t=o.call(n)).done)&&(u.push(t.value),u.length!==e);s=!0);}catch(r){c=!0,a=r}finally{try{if(!s&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw a}}return u}}(r,e)||function(r,e){if(r){if("string"==typeof r)return a(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(r,e):void 0}}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}for(var o=n(101),i={},u=0,s=Object.keys(o);u<s.length;u++){var c=s[u];i[o[c]]=c}var l={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};r.exports=l;for(var h=0,f=Object.keys(l);h<f.length;h++){var p=f[h];if(!("channels"in l[p]))throw new Error("missing channels property: "+p);if(!("labels"in l[p]))throw new Error("missing channel labels property: "+p);if(l[p].labels.length!==l[p].channels)throw new Error("channel and label counts mismatch: "+p);var b=l[p],g=b.channels,v=b.labels;delete l[p].channels,delete l[p].labels,Object.defineProperty(l[p],"channels",{value:g}),Object.defineProperty(l[p],"labels",{value:v})}l.rgb.hsl=function(r){var e,n=r[0]/255,t=r[1]/255,a=r[2]/255,o=Math.min(n,t,a),i=Math.max(n,t,a),u=i-o;i===o?e=0:n===i?e=(t-a)/u:t===i?e=2+(a-n)/u:a===i&&(e=4+(n-t)/u),(e=Math.min(60*e,360))<0&&(e+=360);var s=(o+i)/2;return[e,100*(i===o?0:s<=.5?u/(i+o):u/(2-i-o)),100*s]},l.rgb.hsv=function(r){var e,n,t,a,o,i=r[0]/255,u=r[1]/255,s=r[2]/255,c=Math.max(i,u,s),l=c-Math.min(i,u,s),h=function(r){return(c-r)/6/l+.5};return 0===l?(a=0,o=0):(o=l/c,e=h(i),n=h(u),t=h(s),i===c?a=t-n:u===c?a=1/3+e-t:s===c&&(a=2/3+n-e),a<0?a+=1:a>1&&(a-=1)),[360*a,100*o,100*c]},l.rgb.hwb=function(r){var e=r[0],n=r[1],t=r[2];return[l.rgb.hsl(r)[0],1/255*Math.min(e,Math.min(n,t))*100,100*(t=1-1/255*Math.max(e,Math.max(n,t)))]},l.rgb.cmyk=function(r){var e=r[0]/255,n=r[1]/255,t=r[2]/255,a=Math.min(1-e,1-n,1-t);return[100*((1-e-a)/(1-a)||0),100*((1-n-a)/(1-a)||0),100*((1-t-a)/(1-a)||0),100*a]},l.rgb.keyword=function(r){var e=i[r];if(e)return e;for(var n,t,a,u=1/0,s=0,c=Object.keys(o);s<c.length;s++){var l=c[s],h=(t=r,a=o[l],Math.pow(t[0]-a[0],2)+Math.pow(t[1]-a[1],2)+Math.pow(t[2]-a[2],2));h<u&&(u=h,n=l)}return n},l.keyword.rgb=function(r){return o[r]},l.rgb.xyz=function(r){var e=r[0]/255,n=r[1]/255,t=r[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*e+.7152*n+.0722*t),100*(.0193*e+.1192*n+.9505*t)]},l.rgb.lab=function(r){var e=l.rgb.xyz(r),n=e[0],t=e[1],a=e[2];return t/=100,a/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116)-16,500*(n-t),200*(t-(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116))]},l.hsl.rgb=function(r){var e,n,t,a=r[0]/360,o=r[1]/100,i=r[2]/100;if(0===o)return[t=255*i,t,t];for(var u=2*i-(e=i<.5?i*(1+o):i+o-i*o),s=[0,0,0],c=0;c<3;c++)(n=a+1/3*-(c-1))<0&&n++,n>1&&n--,t=6*n<1?u+6*(e-u)*n:2*n<1?e:3*n<2?u+(e-u)*(2/3-n)*6:u,s[c]=255*t;return s},l.hsl.hsv=function(r){var e=r[0],n=r[1]/100,t=r[2]/100,a=n,o=Math.max(t,.01);return n*=(t*=2)<=1?t:2-t,a*=o<=1?o:2-o,[e,100*(0===t?2*a/(o+a):2*n/(t+n)),(t+n)/2*100]},l.hsv.rgb=function(r){var e=r[0]/60,n=r[1]/100,t=r[2]/100,a=Math.floor(e)%6,o=e-Math.floor(e),i=255*t*(1-n),u=255*t*(1-n*o),s=255*t*(1-n*(1-o));switch(t*=255,a){case 0:return[t,s,i];case 1:return[u,t,i];case 2:return[i,t,s];case 3:return[i,u,t];case 4:return[s,i,t];case 5:return[t,i,u]}},l.hsv.hsl=function(r){var e,n,t=r[0],a=r[1]/100,o=r[2]/100,i=Math.max(o,.01);n=(2-a)*o;var u=(2-a)*i;return e=a*i,[t,100*(e=(e/=u<=1?u:2-u)||0),100*(n/=2)]},l.hwb.rgb=function(r){var e,n=r[0]/360,t=r[1]/100,a=r[2]/100,o=t+a;o>1&&(t/=o,a/=o);var i=Math.floor(6*n),u=1-a;e=6*n-i,0!=(1&i)&&(e=1-e);var s,c,l,h=t+e*(u-t);switch(i){default:case 6:case 0:s=u,c=h,l=t;break;case 1:s=h,c=u,l=t;break;case 2:s=t,c=u,l=h;break;case 3:s=t,c=h,l=u;break;case 4:s=h,c=t,l=u;break;case 5:s=u,c=t,l=h}return[255*s,255*c,255*l]},l.cmyk.rgb=function(r){var e=r[0]/100,n=r[1]/100,t=r[2]/100,a=r[3]/100;return[255*(1-Math.min(1,e*(1-a)+a)),255*(1-Math.min(1,n*(1-a)+a)),255*(1-Math.min(1,t*(1-a)+a))]},l.xyz.rgb=function(r){var e,n,t,a=r[0]/100,o=r[1]/100,i=r[2]/100;return n=-.9689*a+1.8758*o+.0415*i,t=.0557*a+-.204*o+1.057*i,e=(e=3.2406*a+-1.5372*o+-.4986*i)>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1)),255*(t=Math.min(Math.max(0,t),1))]},l.xyz.lab=function(r){var e=r[0],n=r[1],t=r[2];return n/=100,t/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},l.lab.xyz=function(r){var e,n,t,a=r[0];e=r[1]/500+(n=(a+16)/116),t=n-r[2]/200;var o=Math.pow(n,3),i=Math.pow(e,3),u=Math.pow(t,3);return n=o>.008856?o:(n-16/116)/7.787,e=i>.008856?i:(e-16/116)/7.787,t=u>.008856?u:(t-16/116)/7.787,[e*=95.047,n*=100,t*=108.883]},l.lab.lch=function(r){var e,n=r[0],t=r[1],a=r[2];return(e=360*Math.atan2(a,t)/2/Math.PI)<0&&(e+=360),[n,Math.sqrt(t*t+a*a),e]},l.lch.lab=function(r){var e=r[0],n=r[1],t=r[2]/360*2*Math.PI;return[e,n*Math.cos(t),n*Math.sin(t)]},l.rgb.ansi16=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=t(r,3),a=n[0],o=n[1],i=n[2],u=null===e?l.rgb.hsv(r)[2]:e;if(0===(u=Math.round(u/50)))return 30;var s=30+(Math.round(i/255)<<2|Math.round(o/255)<<1|Math.round(a/255));return 2===u&&(s+=60),s},l.hsv.ansi16=function(r){return l.rgb.ansi16(l.hsv.rgb(r),r[2])},l.rgb.ansi256=function(r){var e=r[0],n=r[1],t=r[2];return e===n&&n===t?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(n/255*5)+Math.round(t/255*5)},l.ansi16.rgb=function(r){var e=r%10;if(0===e||7===e)return r>50&&(e+=3.5),[e=e/10.5*255,e,e];var n=.5*(1+~~(r>50));return[(1&e)*n*255,(e>>1&1)*n*255,(e>>2&1)*n*255]},l.ansi256.rgb=function(r){if(r>=232){var e=10*(r-232)+8;return[e,e,e]}var n;return r-=16,[Math.floor(r/36)/5*255,Math.floor((n=r%36)/6)/5*255,n%6/5*255]},l.rgb.hex=function(r){var e=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(e.length)+e},l.hex.rgb=function(r){var e=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var n=e[0];3===e[0].length&&(n=n.split("").map((function(r){return r+r})).join(""));var t=parseInt(n,16);return[t>>16&255,t>>8&255,255&t]},l.rgb.hcg=function(r){var e,n=r[0]/255,t=r[1]/255,a=r[2]/255,o=Math.max(Math.max(n,t),a),i=Math.min(Math.min(n,t),a),u=o-i;return e=u<=0?0:o===n?(t-a)/u%6:o===t?2+(a-n)/u:4+(n-t)/u,e/=6,[360*(e%=1),100*u,100*(u<1?i/(1-u):0)]},l.hsl.hcg=function(r){var e=r[1]/100,n=r[2]/100,t=n<.5?2*e*n:2*e*(1-n),a=0;return t<1&&(a=(n-.5*t)/(1-t)),[r[0],100*t,100*a]},l.hsv.hcg=function(r){var e=r[1]/100,n=r[2]/100,t=e*n,a=0;return t<1&&(a=(n-t)/(1-t)),[r[0],100*t,100*a]},l.hcg.rgb=function(r){var e=r[0]/360,n=r[1]/100,t=r[2]/100;if(0===n)return[255*t,255*t,255*t];var a,o=[0,0,0],i=e%1*6,u=i%1,s=1-u;switch(Math.floor(i)){case 0:o[0]=1,o[1]=u,o[2]=0;break;case 1:o[0]=s,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=u;break;case 3:o[0]=0,o[1]=s,o[2]=1;break;case 4:o[0]=u,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=s}return a=(1-n)*t,[255*(n*o[0]+a),255*(n*o[1]+a),255*(n*o[2]+a)]},l.hcg.hsv=function(r){var e=r[1]/100,n=e+r[2]/100*(1-e),t=0;return n>0&&(t=e/n),[r[0],100*t,100*n]},l.hcg.hsl=function(r){var e=r[1]/100,n=r[2]/100*(1-e)+.5*e,t=0;return n>0&&n<.5?t=e/(2*n):n>=.5&&n<1&&(t=e/(2*(1-n))),[r[0],100*t,100*n]},l.hcg.hwb=function(r){var e=r[1]/100,n=e+r[2]/100*(1-e);return[r[0],100*(n-e),100*(1-n)]},l.hwb.hcg=function(r){var e=r[1]/100,n=1-r[2]/100,t=n-e,a=0;return t<1&&(a=(n-t)/(1-t)),[r[0],100*t,100*a]},l.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},l.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},l.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},l.gray.hsl=function(r){return[0,0,r[0]]},l.gray.hsv=l.gray.hsl,l.gray.hwb=function(r){return[0,100,r[0]]},l.gray.cmyk=function(r){return[0,0,0,r[0]]},l.gray.lab=function(r){return[r[0],0,0]},l.gray.hex=function(r){var e=255&Math.round(r[0]/100*255),n=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(n.length)+n},l.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}},907:function(r,e,n){function t(r){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},t(r)}var a=n(208),o=n(171),i={};Object.keys(a).forEach((function(r){i[r]={},Object.defineProperty(i[r],"channels",{value:a[r].channels}),Object.defineProperty(i[r],"labels",{value:a[r].labels});var e=o(r);Object.keys(e).forEach((function(n){var a=e[n];i[r][n]=function(r){var e=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];var o=n[0];if(null==o)return o;o.length>1&&(n=o);var i=r(n);if("object"===t(i))for(var u=i.length,s=0;s<u;s++)i[s]=Math.round(i[s]);return i};return"conversion"in r&&(e.conversion=r.conversion),e}(a),i[r][n].raw=function(r){var e=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var a=n[0];return null==a?a:(a.length>1&&(n=a),r(n))};return"conversion"in r&&(e.conversion=r.conversion),e}(a)}))})),r.exports=i},171:function(r,e,n){var t=n(208);function a(r,e){return function(n){return e(r(n))}}function o(r,e){for(var n=[e[r].parent,r],o=t[e[r].parent][r],i=e[r].parent;e[i].parent;)n.unshift(e[i].parent),o=a(t[e[i].parent][i],o),i=e[i].parent;return o.conversion=n,o}r.exports=function(r){for(var e=function(r){var e=function(){for(var r={},e=Object.keys(t),n=e.length,a=0;a<n;a++)r[e[a]]={distance:-1,parent:null};return r}(),n=[r];for(e[r].distance=0;n.length;)for(var a=n.pop(),o=Object.keys(t[a]),i=o.length,u=0;u<i;u++){var s=o[u],c=e[s];-1===c.distance&&(c.distance=e[a].distance+1,c.parent=a,n.unshift(s))}return e}(r),n={},a=Object.keys(e),i=a.length,u=0;u<i;u++){var s=a[u];null!==e[s].parent&&(n[s]=o(s,e))}return n}},101:function(r){"use strict";r.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}}},e={};function n(t){var a=e[t];if(void 0!==a)return a.exports;var o=e[t]={exports:{}};return r[t](o,o.exports,n),o.exports}n.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(e,{a:e}),e},n.d=function(r,e){for(var t in e)n.o(e,t)&&!n.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},n.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},n.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var t={};return function(){"use strict";n.r(t),n.d(t,{CssColorParser:function(){return u},fromArray:function(){return w},fromColorStr:function(){return v},fromHSL:function(){return d},fromHWB:function(){return y},fromJson:function(){return M},fromRandom:function(){return m},parseCssColorStr:function(){return g},parseHEX:function(){return h},parseHSLA:function(){return p},parseHWB:function(){return b},parseKeyWord:function(){return l},parseRGBA:function(){return f}});var r=function(){function r(){}return r.type=function(r,e,n){var t=typeof n;if(t!==r)throw new Error("Expected ".concat(e," to be typeof ").concat(r,", actual typeof was ").concat(t))},r.types=function(r,e,n){var t=typeof n;if(!r.includes(t))throw new Error("Expected ".concat(e," to be typeof ").concat(r.join("|"),", actual typeof was ").concat(t))},r}();function e(r,e){return null==r||isNaN(r)&&"number"==typeof e?e:r}function a(r,e,n){return n>e?n=e:n<r&&(n=r),n}function o(r,e){return Number(r.toFixed(e))}var i=function(){function r(){}return r.clearStrSpace=function(r){return r.replace(/\s/g,"")},r.trimStr=function(r){return(r=r.replace(/\s+/g," ")).trim()},r.parse3BitsHEX=function(n){var t=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(n);if(t){var a=e(t[4],"f");return[r._parseResStrForRgb(parseInt(t[1]+t[1],16)),r._parseResStrForRgb(parseInt(t[2]+t[2],16)),r._parseResStrForRgb(parseInt(t[3]+t[3],16)),r._parsePercent(parseInt(a+a,16)/255)]}return null},r.parse6BitsHEX=function(n){var t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(n);if(t){var a=e(t[4],"ff");return[r._parseResStrForRgb(parseInt(t[1],16)),r._parseResStrForRgb(parseInt(t[2],16)),r._parseResStrForRgb(parseInt(t[3],16)),r._parsePercent(parseInt(a,16)/255)]}return null},r.parseRGBA=function(e){var n=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(e);return n?[r._parseResStrForRgb(n[1]),r._parseResStrForRgb(n[2]),r._parseResStrForRgb(n[3]),r._parsePercent(n[4])]:null},r.parseHSLA=function(e){var n=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(e);return n?[r._parseResStrForHue(n[1]),r._parsePercent(n[2]),r._parsePercent(n[3]),r._parsePercent(n[4])]:null},r.parseHWB=function(e){var n=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return n?[r._parseResStrForHue(n[1]),r._parsePercent(n[2]),r._parsePercent(n[3]),r._parsePercent(n[4])]:null},r.parseRGBA2=function(e){var n=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return n?[r._parseResStrForRgb(n[1]),r._parseResStrForRgb(n[2]),r._parseResStrForRgb(n[3]),r._parsePercent(n[4])]:null},r.parseHSLA2=function(e){var n=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return n?[r._parseResStrForHue(n[1]),r._parsePercent(n[2]),r._parsePercent(n[3]),r._parsePercent(n[4])]:null},r._parseResStrForRgb=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100/255:1)),isNaN(r)&&(r=1),a(0,255,r)},r._parseResStrForHue=function(r){return"string"==typeof r&&(r=parseFloat(r)),isNaN(r)&&(r=0),a(0,360,r)},r._parsePercent=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100:1)),isNaN(r)&&(r=1),a(0,1,r)},r}(),u=function(){function r(r,e,n,t){this.r=255,this.g=255,this.b=255,this.a=1,this.setColor(r,e,n,t)}return r.prototype.setColor=function(r,n,t,o){this.r=a(0,255,e(Number(r),0)),this.g=a(0,255,e(Number(n),0)),this.b=a(0,255,e(Number(t),0)),this.a=a(0,1,e(Number(o),1))},r.prototype.toRGBA=function(){var r=this.toJson();return 1===r.a?"rgb(".concat(r.r,",").concat(r.g,",").concat(r.b,")"):"rgba(".concat(r.r,",").concat(r.g,",").concat(r.b,",").concat(r.a,")")},r.prototype.toString=function(){return this.toRGBA()},r.prototype.toNormalize=function(){return{r:o(this.r/255,2),g:o(this.g/255,2),b:o(this.b/255,2),a:o(this.a,2)}},r.prototype.toHEX=function(){var r=this.toJson(),e=r.r.toString(16);e.length<2&&(e="0".concat(e));var n=r.g.toString(16);n.length<2&&(n="0".concat(n));var t=r.b.toString(16);if(t.length<2&&(t="0".concat(t)),this.a<1){var a=parseInt((255*this.a).toFixed()).toString(16);return a.length<2&&(a="0".concat(a)),"#".concat(e).concat(n).concat(t).concat(a)}return"#".concat(e).concat(n).concat(t)},r.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},r.prototype.toJson=function(){return{r:parseInt(this.r.toFixed()),g:parseInt(this.g.toFixed()),b:parseInt(this.b.toFixed()),a:parseFloat(this.a.toFixed(2))}},r.prototype.clone=function(){return new r(this.r,this.g,this.b,this.a)},r.prototype.equals=function(r){return this===r||this.r===r.r&&this.g===r.g&&this.b===r.g&&this.a===r.a},r.parseHEX=function(e){var n=i.clearStrSpace(e),t=i.parse3BitsHEX(n);return t||(t=i.parse6BitsHEX(n)),t&&r.fromArray(t)},r.parseRGBA=function(e){var n=i.clearStrSpace(e),t=i.parseRGBA(n);if(!t){var a=i.trimStr(e);t=i.parseRGBA2(a)}return t&&r.fromArray(t)},r.fromJson=function(e){return new r(e.r,e.g,e.b,e.a)},r.fromArray=function(e){return new r(e[0],e[1],e[2],e[3])},r.fromRandom=function(e,n){return new r(Math.random()*Math.abs(n.r-e.r)+Math.min(e.r,n.r),Math.random()*Math.abs(n.g-e.g)+Math.min(e.g,n.g),Math.random()*Math.abs(n.b-e.b)+Math.min(e.b,n.b),Math.random()*Math.abs(n.a-e.a)+Math.min(e.a,n.a))},r}(),s=n(907),c=n.n(s);function l(r){var e=i.clearStrSpace(r),n=c().keyword.rgb(e);return n&&w(n)}function h(r){var e=i.clearStrSpace(r),n=i.parse3BitsHEX(e);return n||(n=i.parse6BitsHEX(e)),n&&w(n)}function f(r){var e=i.clearStrSpace(r),n=i.parseRGBA(e);if(!n){var t=i.trimStr(r);n=i.parseRGBA2(t)}return n&&w(n)}function p(r){var e=i.clearStrSpace(r),n=i.parseHSLA(e);if(!n){var t=i.trimStr(r);n=i.parseHSLA2(t)}return n&&d(n[0],n[1],n[2],n[3])}function b(r){var e=i.trimStr(r),n=i.parseHWB(e);return n&&y(n[0],n[1],n[2],n[3])}function g(e){return r.type("string","color",e),h(e)||f(e)||l(e)||p(e)||b(e)}function v(e){return r.type("string","color",e),h(e)||f(e)||l(e)||p(e)||b(e)}function d(r,n,t,o){var i=c().hsl.rgb(a(0,360,r),a(0,100,100*n),a(0,100,100*t));return new u(i[0],i[1],i[2],e(Number(o),1))}function y(r,n,t,o){var i=c().hwb.rgb(a(0,360,r),a(0,100,100*n),a(0,100,100*t));return new u(i[0],i[1],i[2],e(Number(o),1))}function m(r,e){if("string"==typeof r&&(r=g(r)),"string"==typeof e&&(e=g(e)),!r||!e)throw new Error("fail to create object from random");var n=Math.random()*Math.abs(e.r-r.r)+Math.min(r.r,e.r),t=Math.random()*Math.abs(e.g-r.g)+Math.min(r.g,e.g),a=Math.random()*Math.abs(e.b-r.b)+Math.min(r.b,e.b),o=Math.random()*Math.abs(e.a-r.a)+Math.min(r.a,e.a);return new u(n,t,a,o)}function M(r){return new u(r.r,r.g,r.b,r.a)}function w(r){return new u(r[0],r[1],r[2],r[3])}}(),t}()}));
|
|
1
|
+
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Parser=t():r.Parser=t()}(this,(function(){return function(){var r={208:function(r,t,e){function n(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}for(var a=e(101),o={},i=0,s=Object.keys(a);i<s.length;i++){var u=s[i];o[a[u]]=u}var c={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};r.exports=c;for(var l=0,h=Object.keys(c);l<h.length;l++){var p=h[l];if(!("channels"in c[p]))throw new Error("missing channels property: "+p);if(!("labels"in c[p]))throw new Error("missing channel labels property: "+p);if(c[p].labels.length!==c[p].channels)throw new Error("channel and label counts mismatch: "+p);var f=c[p],b=f.channels,g=f.labels;delete c[p].channels,delete c[p].labels,Object.defineProperty(c[p],"channels",{value:b}),Object.defineProperty(c[p],"labels",{value:g})}c.rgb.hsl=function(r){var t,e=r[0]/255,n=r[1]/255,a=r[2]/255,o=Math.min(e,n,a),i=Math.max(e,n,a),s=i-o;i===o?t=0:e===i?t=(n-a)/s:n===i?t=2+(a-e)/s:a===i&&(t=4+(e-n)/s),(t=Math.min(60*t,360))<0&&(t+=360);var u=(o+i)/2;return[t,100*(i===o?0:u<=.5?s/(i+o):s/(2-i-o)),100*u]},c.rgb.hsv=function(r){var t,e,n,a,o,i=r[0]/255,s=r[1]/255,u=r[2]/255,c=Math.max(i,s,u),l=c-Math.min(i,s,u),h=function(r){return(c-r)/6/l+.5};return 0===l?(a=0,o=0):(o=l/c,t=h(i),e=h(s),n=h(u),i===c?a=n-e:s===c?a=1/3+t-n:u===c&&(a=2/3+e-t),a<0?a+=1:a>1&&(a-=1)),[360*a,100*o,100*c]},c.rgb.hwb=function(r){var t=r[0],e=r[1],n=r[2];return[c.rgb.hsl(r)[0],1/255*Math.min(t,Math.min(e,n))*100,100*(n=1-1/255*Math.max(t,Math.max(e,n)))]},c.rgb.cmyk=function(r){var t=r[0]/255,e=r[1]/255,n=r[2]/255,a=Math.min(1-t,1-e,1-n);return[100*((1-t-a)/(1-a)||0),100*((1-e-a)/(1-a)||0),100*((1-n-a)/(1-a)||0),100*a]},c.rgb.keyword=function(r){var t=o[r];if(t)return t;for(var e,n,i,s=1/0,u=0,c=Object.keys(a);u<c.length;u++){var l=c[u],h=(n=r,i=a[l],Math.pow(n[0]-i[0],2)+Math.pow(n[1]-i[1],2)+Math.pow(n[2]-i[2],2));h<s&&(s=h,e=l)}return e},c.keyword.rgb=function(r){return a[r]},c.rgb.xyz=function(r){var t=r[0]/255,e=r[1]/255,n=r[2]/255;return[100*(.4124*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)+.3576*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.1805*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)),100*(.2126*t+.7152*e+.0722*n),100*(.0193*t+.1192*e+.9505*n)]},c.rgb.lab=function(r){var t=c.rgb.xyz(r),e=t[0],n=t[1],a=t[2];return n/=100,a/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116))]},c.hsl.rgb=function(r){var t,e,n,a=r[0]/360,o=r[1]/100,i=r[2]/100;if(0===o)return[n=255*i,n,n];for(var s=2*i-(t=i<.5?i*(1+o):i+o-i*o),u=[0,0,0],c=0;c<3;c++)(e=a+1/3*-(c-1))<0&&e++,e>1&&e--,n=6*e<1?s+6*(t-s)*e:2*e<1?t:3*e<2?s+(t-s)*(2/3-e)*6:s,u[c]=255*n;return u},c.hsl.hsv=function(r){var t=r[0],e=r[1]/100,n=r[2]/100,a=e,o=Math.max(n,.01);return e*=(n*=2)<=1?n:2-n,a*=o<=1?o:2-o,[t,100*(0===n?2*a/(o+a):2*e/(n+e)),(n+e)/2*100]},c.hsv.rgb=function(r){var t=r[0]/60,e=r[1]/100,n=r[2]/100,a=Math.floor(t)%6,o=t-Math.floor(t),i=255*n*(1-e),s=255*n*(1-e*o),u=255*n*(1-e*(1-o));switch(n*=255,a){case 0:return[n,u,i];case 1:return[s,n,i];case 2:return[i,n,u];case 3:return[i,s,n];case 4:return[u,i,n];case 5:return[n,i,s]}},c.hsv.hsl=function(r){var t,e,n=r[0],a=r[1]/100,o=r[2]/100,i=Math.max(o,.01);e=(2-a)*o;var s=(2-a)*i;return t=a*i,[n,100*(t=(t/=s<=1?s:2-s)||0),100*(e/=2)]},c.hwb.rgb=function(r){var t,e=r[0]/360,n=r[1]/100,a=r[2]/100,o=n+a;o>1&&(n/=o,a/=o);var i=Math.floor(6*e),s=1-a;t=6*e-i,0!=(1&i)&&(t=1-t);var u,c,l,h=n+t*(s-n);switch(i){default:case 6:case 0:u=s,c=h,l=n;break;case 1:u=h,c=s,l=n;break;case 2:u=n,c=s,l=h;break;case 3:u=n,c=h,l=s;break;case 4:u=h,c=n,l=s;break;case 5:u=s,c=n,l=h}return[255*u,255*c,255*l]},c.cmyk.rgb=function(r){var t=r[0]/100,e=r[1]/100,n=r[2]/100,a=r[3]/100;return[255*(1-Math.min(1,t*(1-a)+a)),255*(1-Math.min(1,e*(1-a)+a)),255*(1-Math.min(1,n*(1-a)+a))]},c.xyz.rgb=function(r){var t,e,n,a=r[0]/100,o=r[1]/100,i=r[2]/100;return e=-.9689*a+1.8758*o+.0415*i,n=.0557*a+-.204*o+1.057*i,t=(t=3.2406*a+-1.5372*o+-.4986*i)>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,e=e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,[255*(t=Math.min(Math.max(0,t),1)),255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1))]},c.xyz.lab=function(r){var t=r[0],e=r[1],n=r[2];return e/=100,n/=108.883,t=(t/=95.047)>.008856?Math.pow(t,1/3):7.787*t+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(t-e),200*(e-(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116))]},c.lab.xyz=function(r){var t,e,n,a=r[0];t=r[1]/500+(e=(a+16)/116),n=e-r[2]/200;var o=Math.pow(e,3),i=Math.pow(t,3),s=Math.pow(n,3);return e=o>.008856?o:(e-16/116)/7.787,t=i>.008856?i:(t-16/116)/7.787,n=s>.008856?s:(n-16/116)/7.787,[t*=95.047,e*=100,n*=108.883]},c.lab.lch=function(r){var t,e=r[0],n=r[1],a=r[2];return(t=360*Math.atan2(a,n)/2/Math.PI)<0&&(t+=360),[e,Math.sqrt(n*n+a*a),t]},c.lch.lab=function(r){var t=r[0],e=r[1],n=r[2]/360*2*Math.PI;return[t,e*Math.cos(n),e*Math.sin(n)]},c.rgb.ansi16=function(r){var t,e,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=(e=3,function(r){if(Array.isArray(r))return r}(t=r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,a,o,i,s=[],u=!0,c=!1;try{if(o=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;u=!1}else for(;!(u=(n=o.call(e)).done)&&(s.push(n.value),s.length!==t);u=!0);}catch(r){c=!0,a=r}finally{try{if(!u&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(c)throw a}}return s}}(t,e)||function(r,t){if(r){if("string"==typeof r)return n(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(r,t):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=o[0],s=o[1],u=o[2],l=null===a?c.rgb.hsv(r)[2]:a;if(0===(l=Math.round(l/50)))return 30;var h=30+(Math.round(u/255)<<2|Math.round(s/255)<<1|Math.round(i/255));return 2===l&&(h+=60),h},c.hsv.ansi16=function(r){return c.rgb.ansi16(c.hsv.rgb(r),r[2])},c.rgb.ansi256=function(r){var t=r[0],e=r[1],n=r[2];return t===e&&e===n?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(e/255*5)+Math.round(n/255*5)},c.ansi16.rgb=function(r){var t=r%10;if(0===t||7===t)return r>50&&(t+=3.5),[t=t/10.5*255,t,t];var e=.5*(1+~~(r>50));return[(1&t)*e*255,(t>>1&1)*e*255,(t>>2&1)*e*255]},c.ansi256.rgb=function(r){if(r>=232){var t=10*(r-232)+8;return[t,t,t]}var e;return r-=16,[Math.floor(r/36)/5*255,Math.floor((e=r%36)/6)/5*255,e%6/5*255]},c.rgb.hex=function(r){var t=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(t.length)+t},c.hex.rgb=function(r){var t=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!t)return[0,0,0];var e=t[0];3===t[0].length&&(e=e.split("").map((function(r){return r+r})).join(""));var n=parseInt(e,16);return[n>>16&255,n>>8&255,255&n]},c.rgb.hcg=function(r){var t,e=r[0]/255,n=r[1]/255,a=r[2]/255,o=Math.max(Math.max(e,n),a),i=Math.min(Math.min(e,n),a),s=o-i;return t=s<=0?0:o===e?(n-a)/s%6:o===n?2+(a-e)/s:4+(e-n)/s,t/=6,[360*(t%=1),100*s,100*(s<1?i/(1-s):0)]},c.hsl.hcg=function(r){var t=r[1]/100,e=r[2]/100,n=e<.5?2*t*e:2*t*(1-e),a=0;return n<1&&(a=(e-.5*n)/(1-n)),[r[0],100*n,100*a]},c.hsv.hcg=function(r){var t=r[1]/100,e=r[2]/100,n=t*e,a=0;return n<1&&(a=(e-n)/(1-n)),[r[0],100*n,100*a]},c.hcg.rgb=function(r){var t=r[0]/360,e=r[1]/100,n=r[2]/100;if(0===e)return[255*n,255*n,255*n];var a,o=[0,0,0],i=t%1*6,s=i%1,u=1-s;switch(Math.floor(i)){case 0:o[0]=1,o[1]=s,o[2]=0;break;case 1:o[0]=u,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=s;break;case 3:o[0]=0,o[1]=u,o[2]=1;break;case 4:o[0]=s,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=u}return a=(1-e)*n,[255*(e*o[0]+a),255*(e*o[1]+a),255*(e*o[2]+a)]},c.hcg.hsv=function(r){var t=r[1]/100,e=t+r[2]/100*(1-t),n=0;return e>0&&(n=t/e),[r[0],100*n,100*e]},c.hcg.hsl=function(r){var t=r[1]/100,e=r[2]/100*(1-t)+.5*t,n=0;return e>0&&e<.5?n=t/(2*e):e>=.5&&e<1&&(n=t/(2*(1-e))),[r[0],100*n,100*e]},c.hcg.hwb=function(r){var t=r[1]/100,e=t+r[2]/100*(1-t);return[r[0],100*(e-t),100*(1-e)]},c.hwb.hcg=function(r){var t=r[1]/100,e=1-r[2]/100,n=e-t,a=0;return n<1&&(a=(e-n)/(1-n)),[r[0],100*n,100*a]},c.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},c.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},c.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},c.gray.hsl=function(r){return[0,0,r[0]]},c.gray.hsv=c.gray.hsl,c.gray.hwb=function(r){return[0,100,r[0]]},c.gray.cmyk=function(r){return[0,0,0,r[0]]},c.gray.lab=function(r){return[r[0],0,0]},c.gray.hex=function(r){var t=255&Math.round(r[0]/100*255),e=((t<<16)+(t<<8)+t).toString(16).toUpperCase();return"000000".substring(e.length)+e},c.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}},907:function(r,t,e){function n(r){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},n(r)}var a=e(208),o=e(171),i={};Object.keys(a).forEach((function(r){i[r]={},Object.defineProperty(i[r],"channels",{value:a[r].channels}),Object.defineProperty(i[r],"labels",{value:a[r].labels});var t=o(r);Object.keys(t).forEach((function(e){var a=t[e];i[r][e]=function(r){var t=function(){for(var t=arguments.length,e=new Array(t),a=0;a<t;a++)e[a]=arguments[a];var o=e[0];if(null==o)return o;o.length>1&&(e=o);var i=r(e);if("object"===n(i))for(var s=i.length,u=0;u<s;u++)i[u]=Math.round(i[u]);return i};return"conversion"in r&&(t.conversion=r.conversion),t}(a),i[r][e].raw=function(r){var t=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var a=e[0];return null==a?a:(a.length>1&&(e=a),r(e))};return"conversion"in r&&(t.conversion=r.conversion),t}(a)}))})),r.exports=i},171:function(r,t,e){var n=e(208);function a(r,t){return function(e){return t(r(e))}}function o(r,t){for(var e=[t[r].parent,r],o=n[t[r].parent][r],i=t[r].parent;t[i].parent;)e.unshift(t[i].parent),o=a(n[t[i].parent][i],o),i=t[i].parent;return o.conversion=e,o}r.exports=function(r){for(var t=function(r){var t=function(){for(var r={},t=Object.keys(n),e=t.length,a=0;a<e;a++)r[t[a]]={distance:-1,parent:null};return r}(),e=[r];for(t[r].distance=0;e.length;)for(var a=e.pop(),o=Object.keys(n[a]),i=o.length,s=0;s<i;s++){var u=o[s],c=t[u];-1===c.distance&&(c.distance=t[a].distance+1,c.parent=a,e.unshift(u))}return t}(r),e={},a=Object.keys(t),i=a.length,s=0;s<i;s++){var u=a[s];null!==t[u].parent&&(e[u]=o(u,t))}return e}},101:function(r){"use strict";r.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}}},t={};function e(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return r[n](o,o.exports,e),o.exports}e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,{a:t}),t},e.d=function(r,t){for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var n={};return function(){"use strict";e.r(n),e.d(n,{CssColorParser:function(){return s},CssColorParserPlus:function(){return p}});var r=function(){function r(){}return r.type=function(r,t,e){var n=typeof t;if(n!==e)throw new Error("Expected ".concat(r," to be typeof ").concat(e,", actual typeof was ").concat(n))},r.types=function(r,t,e){var n=typeof t;if(!e.includes(n))throw new Error("Expected ".concat(r," to be typeof ").concat(e.join("|"),", actual typeof was ").concat(n))},r.numValue=function(t,e,n,a){r.numMinValue(t,e,n),r.numMaxValue(t,e,a)},r.numMinValue=function(r,t,e){if(t<e)throw new Error("Expected ".concat(r," to > ").concat(e,", actual value was ").concat(t))},r.numMaxValue=function(r,t,e){if(t>e)throw new Error("Expected ".concat(r," to < ").concat(e,", actual value was ").concat(t))},r.numIsInt=function(r,t,e){var n=Math.floor(t)===t;if(n!==e)throw new Error("Expected ".concat(r," to ").concat(e?"Integer":"Float",", actual value was ").concat(n?"Integer":"Float"))},r}();function t(r,t){return null==r||isNaN(r)&&"number"==typeof t?t:r}function a(r,t,e){return e>t?e=t:e<r&&(e=r),e}function o(r,t){void 0===r&&(r=0);var e=Math.pow(10,t);return Math.round(r*e)/e}var i=function(){function r(){}return r.clearStrSpace=function(r){return r.replace(/\s/g,"")},r.trimStr=function(r){return(r=r.replace(/\s+/g," ")).trim()},r.parse3BitsHEX=function(e){var n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(e);if(n){var a=t(n[4],"f");return[r._parseResStrForRgb(parseInt(n[1]+n[1],16)),r._parseResStrForRgb(parseInt(n[2]+n[2],16)),r._parseResStrForRgb(parseInt(n[3]+n[3],16)),r._parsePercent(parseInt(a+a,16)/255)]}return null},r.parse6BitsHEX=function(e){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(e);if(n){var a=t(n[4],"ff");return[r._parseResStrForRgb(parseInt(n[1],16)),r._parseResStrForRgb(parseInt(n[2],16)),r._parseResStrForRgb(parseInt(n[3],16)),r._parsePercent(parseInt(a,16)/255)]}return null},r.parseRGBA=function(t){var e=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA=function(t){var e=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseHWB=function(t){var e=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseRGBA2=function(t){var e=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA2=function(t){var e=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r._parseResStrForRgb=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100/255:1)),isNaN(r)&&(r=1),a(0,255,r)},r._parseResStrForHue=function(r){return"string"==typeof r&&(r=parseFloat(r)),isNaN(r)&&(r=0),a(0,360,r)},r._parsePercent=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100:1)),isNaN(r)&&(r=1),a(0,1,r)},r}(),s=function(){function e(r,t,e,n){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(r,t,e,n)}return e.prototype.setOutPrecision=function(t,e){return r.type("colorPrecision",t,"number"),r.type("outAlphaPrecision",e,"number"),r.numMinValue("colorPrecision",t,0),r.numMinValue("outAlphaPrecision",e,0),r.numIsInt("colorPrecision",t,!0),r.numIsInt("outAlphaPrecision",e,!0),this._outColorPrecision=t,this._outAlphaPrecision=e,this},e.prototype.setColor=function(r,e,n,o){return this.r=a(0,255,t(Number(r),0)),this.g=a(0,255,t(Number(e),0)),this.b=a(0,255,t(Number(n),0)),this.a=a(0,1,t(Number(o),1)),this},e.prototype.setAlpha=function(r){return this.a=a(0,1,t(Number(r),1)),this},e.prototype.setRed=function(r){return this.r=a(0,255,t(Number(r),0)),this},e.prototype.setGreen=function(r){return this.g=a(0,255,t(Number(r),0)),this},e.prototype.setBlue=function(r){return this.b=a(0,255,t(Number(r),0)),this},e.prototype.toRGBA=function(){var r=this.toJson();return 1===r.a?"rgb(".concat(r.r,",").concat(r.g,",").concat(r.b,")"):"rgba(".concat(r.r,",").concat(r.g,",").concat(r.b,",").concat(r.a,")")},e.prototype.toString=function(){return this.toRGBA()},e.prototype.toNormalize=function(){return[o(this.r/255,this._outColorPrecision),o(this.g/255,this._outColorPrecision),o(this.b/255,this._outColorPrecision),o(this.a,this._outAlphaPrecision)]},e.prototype.toHEX=function(){var r=this.toJson(),t=r.r.toString(16);t.length<2&&(t="0".concat(t));var e=r.g.toString(16);e.length<2&&(e="0".concat(e));var n=r.b.toString(16);if(n.length<2&&(n="0".concat(n)),this.a<1){var a=parseInt((255*this.a).toFixed()).toString(16);return a.length<2&&(a="0".concat(a)),"#".concat(t).concat(e).concat(n).concat(a)}return"#".concat(t).concat(e).concat(n)},e.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},e.prototype.toJson=function(){return{r:o(this.r,this._outColorPrecision),g:o(this.g,this._outColorPrecision),b:o(this.b,this._outColorPrecision),a:o(this.a,this._outAlphaPrecision)}},e.prototype.toInvert=function(){return new e(255-this.r,255-this.g,255-this.b,1-this.a)},e.prototype.clone=function(){return new e(this.r,this.g,this.b,this.a)},e.prototype.equals=function(r){if(this===r)return!0;var t=this.toJson(),e=r.toJson();return t.r===e.r&&t.g===e.g&&t.b===e.g&&t.a===e.a},e.prototype.setInvert=function(){return this.r=255-this.r,this.g=255-this.g,this.b=255-this.b,this.a=1-this.a,this},e.prototype.multiplyByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r*r,n=this.g*r,a=this.b*r,o=t?this.a*r:this.a;return this.setColor(e,n,a,o)},e.prototype.divideByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r/r,n=this.g/r,a=this.b/r,o=t?this.a/r:this.a;return this.setColor(e,n,a,o)},e.prototype.add=function(r,t){void 0===t&&(t=!0);var e=this.r+r.r,n=this.g+r.g,a=this.b+r.b,o=t?this.a+r.a:this.a;return this.setColor(e,n,a,o)},e.prototype.subtract=function(r,t){void 0===t&&(t=!0);var e=this.r-r.r,n=this.g-r.g,a=this.b-r.b,o=t?this.a-r.a:this.a;return this.setColor(e,n,a,o)},e.prototype.multiply=function(r,t){void 0===t&&(t=!0);var e=this.r*r.r,n=this.g*r.g,a=this.b*r.b,o=t?this.a*r.a:this.a;return this.setColor(e,n,a,o)},e.prototype.divide=function(r,t){void 0===t&&(t=!0);var e=this.r/r.r,n=this.g/r.g,a=this.b/r.b,o=t?this.a/r.a:this.a;return this.setColor(e,n,a,o)},e.prototype.addNumberForRGB=function(r){return this.r=this.r+r,this.g=this.g+r,this.b=this.b+r,this},e.prototype.addNumberForAlpha=function(r){return this.a=this.a+r,this},e.parseHEX=function(r){var t=i.clearStrSpace(r),n=i.parse3BitsHEX(t);return n||(n=i.parse6BitsHEX(t)),n&&e.fromArray(n)},e.parseRGBA=function(r){var t=i.clearStrSpace(r),n=i.parseRGBA(t);if(!n){var a=i.trimStr(r);n=i.parseRGBA2(a)}return n&&e.fromArray(n)},e.fromJson=function(r){return new e(r.r,r.g,r.b,r.a)},e.fromArray=function(r){return new e(r[0],r[1],r[2],r[3])},e.fromRandom=function(r,t){return new e(Math.random()*Math.abs(t.r-r.r)+Math.min(r.r,t.r),Math.random()*Math.abs(t.g-r.g)+Math.min(r.g,t.g),Math.random()*Math.abs(t.b-r.b)+Math.min(r.b,t.b),Math.random()*Math.abs(t.a-r.a)+Math.min(r.a,t.a))},e.fromNormalize=function(r){var t=255*r[0],n=255*r[1],a=255*r[2],o=r[3];return e.fromArray([t,n,a,o])},e}(),u=function(r,t){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e])},u(r,t)};Object.create,Object.create;var c=e(907),l=e.n(c),h=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function e(){this.constructor=r}u(r,t),r.prototype=null===t?Object.create(t):(e.prototype=t.prototype,new e)}(n,e),n.prototype.toInvert=function(){return new n(255-this.r,255-this.g,255-this.b,1-this.a)},n.prototype.clone=function(){return new n(this.r,this.g,this.b,this.a)},n.prototype.equals=function(r){if(this===(r=n.parseColor(r)))return!0;var t=this.toJson(),e=r.toJson();return t.r===e.r&&t.g===e.g&&t.b===e.g&&t.a===e.a},n.prototype.add=function(r,t){void 0===t&&(t=!0);var a=n.parseColor(r);return e.prototype.add.call(this,a,t)},n.prototype.subtract=function(r,t){void 0===t&&(t=!0);var a=n.parseColor(r);return e.prototype.subtract.call(this,a,t)},n.prototype.multiply=function(r,t){void 0===t&&(t=!0);var a=n.parseColor(r);return e.prototype.multiply.call(this,a,t)},n.prototype.divide=function(r,t){void 0===t&&(t=!0);var a=n.parseColor(r);return e.prototype.divide.call(this,a,t)},n.parseColor=function(r){return r instanceof s?r:n.parseCssColorStr(r)},n.parseCssColorStr=function(t){return r.type("color",t,"string"),n.parseHEX(t)||n.parseRGBA(t)||n.parseKeyWord(t)||n.parseHSLA(t)||n.parseHWB(t)},n.parseKeyWord=function(r){var t=i.clearStrSpace(r),e=l().keyword.rgb(t);return e&&n.fromArray(e)},n.parseHSLA=function(r){var t=i.clearStrSpace(r),e=i.parseHSLA(t);if(!e){var a=i.trimStr(r);e=i.parseHSLA2(a)}return e&&n.fromHSL(e[0],e[1],e[2],e[3])},n.parseHWB=function(r){var t=i.trimStr(r),e=i.parseHWB(t);return e&&n.fromHWB(e[0],e[1],e[2],e[3])},n.fromHSL=function(r,e,o,i){var s=l().hsl.rgb(a(0,360,r),a(0,100,100*e),a(0,100,100*o));return new n(s[0],s[1],s[2],t(Number(i),1))},n.fromHWB=function(r,e,o,i){var s=l().hwb.rgb(a(0,360,r),a(0,100,100*e),a(0,100,100*o));return new n(s[0],s[1],s[2],t(Number(i),1))},n.parseHEX=function(r){var t=i.clearStrSpace(r),e=i.parse3BitsHEX(t);return e||(e=i.parse6BitsHEX(t)),e&&n.fromArray(e)},n.parseRGBA=function(r){var t=i.clearStrSpace(r),e=i.parseRGBA(t);if(!e){var a=i.trimStr(r);e=i.parseRGBA2(a)}return e&&n.fromArray(e)},n.fromJson=function(r){return new n(r.r,r.g,r.b,r.a)},n.fromArray=function(r){return new n(r[0],r[1],r[2],r[3])},n.fromRandom=function(r,t){return r=n.parseColor(r),t=n.parseColor(t),new n(Math.random()*Math.abs(t.r-r.r)+Math.min(r.r,t.r),Math.random()*Math.abs(t.g-r.g)+Math.min(r.g,t.g),Math.random()*Math.abs(t.b-r.b)+Math.min(r.b,t.b),Math.random()*Math.abs(t.a-r.a)+Math.min(r.a,t.a))},n.fromNormalize=function(r){var t=255*r[0],e=255*r[1],a=255*r[2],o=r[3];return n.fromArray([t,e,a,o])},n}(s),p=h}(),n}()}));
|
package/example.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: roman_123
|
|
3
3
|
* @Description:
|
|
4
4
|
* @Date: 2022-12-06 11:15:17
|
|
5
|
-
* @LastEditTime: 2023-
|
|
5
|
+
* @LastEditTime: 2023-06-27 19:24:53
|
|
6
6
|
-->
|
|
7
7
|
<!DOCTYPE html>
|
|
8
8
|
<html lang="en">
|
|
@@ -17,58 +17,20 @@
|
|
|
17
17
|
<meta http-equiv="Pragma" content="no-cache" />
|
|
18
18
|
<meta http-equiv="Expires" content="0" />
|
|
19
19
|
<title>css-color-parser示例</title>
|
|
20
|
-
<script src="./dist/css-color-parser-h.umd.js"></script>
|
|
20
|
+
<script src="./dist/css-color-parser-h.umd.min.js"></script>
|
|
21
21
|
</head>
|
|
22
22
|
|
|
23
23
|
<body>
|
|
24
24
|
<h2>f12 to view console log</h2>
|
|
25
25
|
<script>
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(
|
|
30
|
-
|
|
31
|
-
console.log(
|
|
32
|
-
|
|
33
|
-
console.log(
|
|
34
|
-
const parser3 = Parser.fromColorStr('rgba(76 144 240 / 80%)')
|
|
35
|
-
console.log(parser3)
|
|
36
|
-
const parser4 = Parser.fromColorStr('rgb(76 144 240)')
|
|
37
|
-
console.log(parser4)
|
|
38
|
-
const parser5 = Parser.fromColorStr('rgb(76,144,240)')
|
|
39
|
-
console.log(parser5)
|
|
40
|
-
const parser6 = Parser.fromColorStr('#4c90f0')
|
|
41
|
-
console.log(parser6)
|
|
42
|
-
const parser7 = Parser.fromColorStr('#4c90f0cc')
|
|
43
|
-
console.log(parser7)
|
|
44
|
-
const parser8 = Parser.fromColorStr('#ccc')
|
|
45
|
-
console.log(parser8)
|
|
46
|
-
const parser9 = Parser.fromColorStr('hsl(215 85% 62% / 0.8)')
|
|
47
|
-
console.log(parser9)
|
|
48
|
-
const parser10 = Parser.fromColorStr('hsla(215,85%,62%,0.8)')
|
|
49
|
-
console.log(parser10)
|
|
50
|
-
const parser11 = Parser.fromColorStr('hwb(215deg 30% 6% / 80%)')
|
|
51
|
-
console.log(parser11)
|
|
52
|
-
// 随机生成颜色
|
|
53
|
-
const parser12 = Parser.fromRandom('blue', 'red').toRGBA()
|
|
54
|
-
console.log(parser12)
|
|
55
|
-
const parser13 = Parser.fromRandom('blue', '#ccffbbaa').toRGBA()
|
|
56
|
-
console.log(parser13)
|
|
57
|
-
const parser14 = Parser.fromRandom(
|
|
58
|
-
new Parser.CssColorParser(205, 205, 100, 0.5),
|
|
59
|
-
'#ccffbbaa'
|
|
60
|
-
).toRGBA()
|
|
61
|
-
console.log(parser14)
|
|
62
|
-
const parser15 = Parser.fromRandom(
|
|
63
|
-
Parser.fromArray([205, 205, 100, 0.5]),
|
|
64
|
-
'#ccffbbaa'
|
|
65
|
-
).toRGBA()
|
|
66
|
-
console.log(parser15)
|
|
67
|
-
// 归一化
|
|
68
|
-
const parser16 = Parser.fromArray([100, 200, 0, 0.552]).toNormalize()
|
|
69
|
-
console.log(parser16)
|
|
70
|
-
const parser17 = Parser.parseRGBA('rgba(76 144 240 / 80%)')
|
|
71
|
-
console.log(parser17)
|
|
26
|
+
const cssColorParser = new Parser.CssColorParser()
|
|
27
|
+
const cssColorParserPlus = new Parser.CssColorParserPlus()
|
|
28
|
+
console.log(cssColorParser.toHEX())
|
|
29
|
+
console.log(cssColorParserPlus.toRGBA())
|
|
30
|
+
cssColorParserPlus.add('#333').add('red')
|
|
31
|
+
console.log(cssColorParserPlus.toRGBA())
|
|
32
|
+
cssColorParserPlus.subtract('blue', false)
|
|
33
|
+
console.log(cssColorParserPlus.toRGBA())
|
|
72
34
|
</script>
|
|
73
35
|
</body>
|
|
74
36
|
</html>
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-color-parser-h",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A tool for parsing css color",
|
|
5
5
|
"main": "dist/css-color-parser-h.common.js",
|
|
6
|
-
"types": "@types/
|
|
6
|
+
"types": "@types/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "webpack && node release.js"
|
|
8
|
+
"build": "webpack && node release.js",
|
|
9
|
+
"test": "npm run build && jest",
|
|
10
|
+
"test-c": "jest --coverage"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -35,8 +37,8 @@
|
|
|
35
37
|
"@babel/core": "^7.20.12",
|
|
36
38
|
"@babel/preset-env": "^7.20.2",
|
|
37
39
|
"babel-loader": "^9.1.2",
|
|
38
|
-
"clean-webpack-plugin": "^4.0.0",
|
|
39
40
|
"fs-extra": "^11.1.0",
|
|
41
|
+
"jest": "^29.5.0",
|
|
40
42
|
"ts-loader": "^9.4.1",
|
|
41
43
|
"tslib": "^2.5.2",
|
|
42
44
|
"typescript": "^4.9.3",
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# css-color-parser
|
|
1
|
+
# css-color-parser-h
|
|
2
2
|
 [](https://gitee.com/roman_123/css-color-parser/tree/master) [](https://www.npmjs.com/package/css-color-parser-h) 
|
|
3
3
|
|
|
4
4
|
> A tool for parsing css color
|
|
@@ -14,7 +14,7 @@ npm install --save css-color-parser-h
|
|
|
14
14
|
### Browser
|
|
15
15
|
|
|
16
16
|
```html
|
|
17
|
-
<script src="./dist/css-color-parser.min.js"></script>
|
|
17
|
+
<script src="./dist/css-color-parser-h.umd.min.js"></script>
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
@@ -23,90 +23,128 @@ You can then use it as a window global or as an CommonJs module
|
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
25
|
// plain javascript in browser
|
|
26
|
-
new Parser.CssColorParser(255,255,255,1)
|
|
26
|
+
new Parser.CssColorParser(255,255,255,1) // 轻量版本
|
|
27
|
+
new Parser.CssColorParserPlus(255,255,255,1) // 增强版本
|
|
27
28
|
|
|
28
29
|
// commonJs
|
|
29
|
-
const
|
|
30
|
+
const {CssColorParser, CssColorParserPlus} = require('css-color-parser-h')
|
|
30
31
|
|
|
31
32
|
// es6 module 使用ES6模块,需要在项目中集成webpack等打包工具
|
|
32
33
|
/**
|
|
33
34
|
* If you want to use this library by esm, you must ensure that your project
|
|
34
35
|
* has used webpack, vite, rollup or other packaging tools.
|
|
35
36
|
*/
|
|
36
|
-
import
|
|
37
|
+
import {CssColorParser, CssColorParserPlus} from 'css-color-parser-h'
|
|
37
38
|
|
|
38
39
|
//parse from '#4c90f0cc' to: CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
39
|
-
|
|
40
|
+
CssColorParserPlus.parseColor('#4c90f0cc')
|
|
40
41
|
/**
|
|
41
42
|
* 方法总览
|
|
42
43
|
* */
|
|
43
|
-
//
|
|
44
|
-
import Parser from 'css-color-parser-h'
|
|
45
|
-
Parser.parseKeyWord(v: string): CssColorParser
|
|
46
|
-
Parser.parseHEX(v: string): CssColorParser
|
|
47
|
-
Parser.parseRGBA(v: string): CssColorParser
|
|
48
|
-
Parser.parseHSLA(v: string): CssColorParser
|
|
49
|
-
Parser.parseHWB(v: string)
|
|
50
|
-
Parser.fromColorStr(v: string): CssColorParser
|
|
51
|
-
Parser.fromHSL(h: number, s: number, l: number, a?: number): CssColorParser
|
|
52
|
-
Parser.fromHWB(h: number, w: number, b: number, a?: number)
|
|
53
|
-
Parser.fromRandom(color1: string | CssColorParser,color2: string | CssColorParser): CssColorParser
|
|
54
|
-
Parser.fromJson(json: ColorJson): CssColorParser
|
|
55
|
-
Parser.fromArray(color: Array<number>): CssColorParser
|
|
44
|
+
// CssColorParser类
|
|
56
45
|
// 实例方法
|
|
57
|
-
import {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
import {CssColorParser} from 'css-color-parser-h'
|
|
47
|
+
const colorParser = new CssColorParser()
|
|
48
|
+
// 设置输出值的精度
|
|
49
|
+
colorParser.setOutPrecision(colorPrecision: number, outAlphaPrecision: number): CssColorParser;
|
|
50
|
+
colorParser.setColor(red?: number | string,green?: number | string,blue?: number | string,alpha?: number | string): CssColorParser
|
|
51
|
+
colorParser.setAlpha(alpha?: number | string): CssColorParser
|
|
52
|
+
colorParser.setRed(red?: number | string): CssColorParser;
|
|
53
|
+
colorParser.setGreen(green?: number | string): CssColorParser;
|
|
54
|
+
colorParser.setBlue(blue?: number | string): CssColorParser;
|
|
55
|
+
// 设置反色
|
|
56
|
+
colorParser.setInvert(): CssColorParser;
|
|
57
|
+
colorParser.toRGBA(): string
|
|
58
|
+
colorParser.toHEX(): string
|
|
59
|
+
// 获取反色的值(输出一个新的实例)
|
|
60
|
+
colorParser.toInvert(): CssColorParser;
|
|
61
|
+
colorParser.toString(): string
|
|
62
|
+
colorParser.toNormalize(): ColorJson
|
|
63
|
+
colorParser.toArray(): number[]
|
|
64
|
+
colorParser.toJson(): ColorJson
|
|
65
|
+
// 颜色相加
|
|
66
|
+
colorParser.add(colorParser: CssColorParser, isSetAlpha?: boolean): CssColorParser;
|
|
67
|
+
// 颜色相减
|
|
68
|
+
colorParser.subtract(colorParser: CssColorParser, isSetAlpha?: boolean): CssColorParser;
|
|
69
|
+
// 颜色相乘
|
|
70
|
+
colorParser.multiply(colorParser: CssColorParser, isSetAlpha?: boolean): CssColorParser;
|
|
71
|
+
// 颜色相除
|
|
72
|
+
colorParser.divide(colorParser: CssColorParser, isSetAlpha?: boolean): CssColorParser;
|
|
73
|
+
// 颜色乘以一个数值
|
|
74
|
+
colorParser.multiplyByScalar(scalar: number, isSetAlpha?: boolean): CssColorParser;
|
|
75
|
+
// 颜色除以一个数值
|
|
76
|
+
colorParser.divideByScalar(scalar: number, isSetAlpha?: boolean): CssColorParser;
|
|
77
|
+
// 颜色RGB属性加上一个数值
|
|
78
|
+
colorParser.addNumberForRGB(num: number): CssColorParser;
|
|
79
|
+
// 颜色透明度属性加上一个数值
|
|
80
|
+
colorParser.addNumberForAlpha(num: number): CssColorParser;
|
|
81
|
+
colorParser.clone():CssColorParser
|
|
82
|
+
colorParser.equals(color: CssColorParser):boolean
|
|
83
|
+
// 静态方法
|
|
69
84
|
CssColorParser.parseHEX(v: string): CssColorParser
|
|
70
85
|
CssColorParser.parseRGBA(v: string): CssColorParser
|
|
71
86
|
CssColorParser.fromJson(json: ColorJson): CssColorParser
|
|
72
87
|
CssColorParser.fromArray(color: Array<number>): CssColorParser
|
|
73
88
|
CssColorParser.fromRandomfromRandom(color1: CssColorParser, color2: CssColorParser): CssColorParser
|
|
89
|
+
CssColorParser.fromNormalize(colorArr: [number, number, number, number]): CssColorParser;
|
|
90
|
+
/**
|
|
91
|
+
* CssColorParserPlus类
|
|
92
|
+
* 继承CssColorParser所有方法,增加了一些静态方法,对于加减乘除、随机颜色等方法可以传入颜色字符串进行计算
|
|
93
|
+
* 使用parseColor方法可以解析css颜色格式的字符串
|
|
94
|
+
*/
|
|
95
|
+
import { CssColorParserPlus } from 'css-color-parser-h'
|
|
96
|
+
CssColorParserPlus.parseKeyWord(v: string): CssColorParserPlus
|
|
97
|
+
CssColorParserPlus.parseHEX(v: string): CssColorParserPlus
|
|
98
|
+
CssColorParserPlus.parseRGBA(v: string): CssColorParserPlus
|
|
99
|
+
CssColorParserPlus.parseHSLA(v: string): CssColorParserPlus
|
|
100
|
+
CssColorParserPlus.parseHWB(v: string)
|
|
101
|
+
CssColorParserPlus.parseColor(v: string|CssColorParser): CssColorParserPlus
|
|
102
|
+
CssColorParserPlus.parseCssColorStr(v: string): CssColorParserPlus
|
|
103
|
+
CssColorParserPlus.fromHSL(h: number, s: number, l: number, a?: number): CssColorParserPlus
|
|
104
|
+
CssColorParserPlus.fromHWB(h: number, w: number, b: number, a?: number)
|
|
105
|
+
CssColorParserPlus.fromRandom(color1: string | CssColorParser,color2: string | CssColorParser): CssColorParserPlus
|
|
106
|
+
CssColorParserPlus.fromJson(json: ColorJson): CssColorParserPlus
|
|
107
|
+
CssColorParserPlus.fromArray(color: Array<number>): CssColorParserPlus
|
|
74
108
|
```
|
|
75
109
|
|
|
76
110
|
## Example
|
|
77
111
|
|
|
78
112
|
```js
|
|
79
|
-
import Parser from 'css-color-parser-h'
|
|
80
|
-
|
|
81
|
-
Parser.fromColorStr('blue') // CssColorParser { r: 0, g: 0, b: 255, a: 1 }
|
|
82
|
-
Parser.fromColorStr('blue').toHEX() // #0000ff
|
|
83
|
-
Parser.fromColorStr('blue').toRGBA() // rgb(0,0,255)
|
|
84
|
-
Parser.fromColorStr('rgba(76,144,240,0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
85
|
-
Parser.fromColorStr('rgba(76 144 240 / 80%)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
86
|
-
Parser.fromColorStr('rgb(76 144 240)') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
87
|
-
Parser.fromColorStr('rgb(76,144,240)') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
88
|
-
Parser.fromColorStr('#4c90f0') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
89
|
-
Parser.fromColorStr('#4c90f0cc') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
90
|
-
Parser.fromColorStr('#ccc') // CssColorParser { r: 204, g: 204, b: 204, a: 1 }
|
|
91
|
-
Parser.fromColorStr('hsl(215 85% 62% / 0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
92
|
-
Parser.fromColorStr('hsla(215,85%,62%,0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
93
|
-
Parser.fromColorStr('hwb(215deg 30% 6% / 80%)') // CssColorParser { r: 77, g: 145, b: 240, a: 0.8 }
|
|
94
|
-
Parser.parseRGBA('rgba(76 144 240 / 80%)') // CssColorParser {r: 76, g: 144, b: 240, a: 0.8}
|
|
95
|
-
// 随机生成颜色
|
|
96
|
-
Parser.fromRandom('blue', 'red').toRGBA() // rgb(4,0,34)
|
|
97
|
-
Parser.fromRandom('blue', '#ccffbbaa').toRGBA() // rgba(127,128,239,0.92)
|
|
98
|
-
Parser.fromRandom(new CssColorParser(205,205,100,0.5), '#ccffbbaa').toRGBA() // rgba(205,211,152,0.53)
|
|
99
|
-
Parser.fromRandom(Parser.fromArray([205,205,100,0.5]), '#ccffbbaa').toRGBA() // rgba(205,235,131,0.62)
|
|
100
|
-
|
|
101
|
-
// 归一化
|
|
102
|
-
Parser.fromArray([100, 200, 0, 0.552]).toNormalize() // { r: 0.39, g: 0.78, b: 0, a: 0.55 }
|
|
103
|
-
|
|
104
113
|
import { CssColorParser } from 'css-color-parser-h'
|
|
105
114
|
|
|
115
|
+
const colorParser = new CssColorParser(255,255,255,1)
|
|
116
|
+
colorParser.toHEX()
|
|
106
117
|
CssColorParser.parseHEX('#FFF')
|
|
107
118
|
CssColorParser.parseRGBA('rgba(255,255,255,1)')
|
|
108
119
|
CssColorParser.fromJson({r: 255, g: 255, b: 255, a: 1})
|
|
109
120
|
CssColorParser.fromArray([255,255,255,1])
|
|
110
121
|
CssColorParser.fromRandom(new CssColorParser(0,0,0,0), new CssColorParser(255,255,255,1))
|
|
111
122
|
|
|
123
|
+
import { CssColorParserPlus } from 'css-color-parser-h'
|
|
124
|
+
|
|
125
|
+
CssColorParserPlus.parseColor('blue') // CssColorParser { r: 0, g: 0, b: 255, a: 1 }
|
|
126
|
+
CssColorParserPlus.parseColor('blue').toHEX() // #0000ff
|
|
127
|
+
CssColorParserPlus.parseColor('blue').toRGBA() // rgb(0,0,255)
|
|
128
|
+
CssColorParserPlus.parseColor('rgba(76,144,240,0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
129
|
+
CssColorParserPlus.parseColor('rgba(76 144 240 / 80%)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
130
|
+
CssColorParserPlus.parseColor('rgb(76 144 240)') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
131
|
+
CssColorParserPlus.parseColor('rgb(76,144,240)') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
132
|
+
CssColorParserPlus.parseColor('#4c90f0') // CssColorParser { r: 76, g: 144, b: 240, a: 1 }
|
|
133
|
+
CssColorParserPlus.parseColor('#4c90f0cc') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
134
|
+
CssColorParserPlus.parseColor('#ccc') // CssColorParser { r: 204, g: 204, b: 204, a: 1 }
|
|
135
|
+
CssColorParserPlus.parseColor('hsl(215 85% 62% / 0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
136
|
+
CssColorParserPlus.parseColor('hsla(215,85%,62%,0.8)') // CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
|
|
137
|
+
CssColorParserPlus.parseColor('hwb(215deg 30% 6% / 80%)') // CssColorParser { r: 77, g: 145, b: 240, a: 0.8 }
|
|
138
|
+
CssColorParserPlus.parseRGBA('rgba(76 144 240 / 80%)') // CssColorParser {r: 76, g: 144, b: 240, a: 0.8}
|
|
139
|
+
// 随机生成颜色
|
|
140
|
+
CssColorParserPlus.fromRandom('blue', 'red').toRGBA() // rgb(4,0,34)
|
|
141
|
+
CssColorParserPlus.fromRandom('blue', '#ccffbbaa').toRGBA() // rgba(127,128,239,0.92)
|
|
142
|
+
CssColorParserPlus.fromRandom(new CssColorParser(205,205,100,0.5), '#ccffbbaa').toRGBA() // rgba(205,211,152,0.53)
|
|
143
|
+
CssColorParserPlus.fromRandom(Parser.fromArray([205,205,100,0.5]), '#ccffbbaa').toRGBA() // rgba(205,235,131,0.62)
|
|
144
|
+
// 颜色相加
|
|
145
|
+
const colorParserPlus = new CssColorParserPlus(0,20,0,1)
|
|
146
|
+
colorParserPlus.add('red').toRGBA() // rgb(255,20,0)
|
|
147
|
+
|
|
148
|
+
// 归一化
|
|
149
|
+
CssColorParserPlus.fromArray([100, 200, 0, 0.552]).toNormalize() // { r: 0.39, g: 0.78, b: 0, a: 0.55 }
|
|
112
150
|
```
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: roman_123
|
|
3
|
-
* @Description:
|
|
4
|
-
* @Date: 2023-05-26 13:29:45
|
|
5
|
-
* @LastEditTime: 2023-05-26 16:10:51
|
|
6
|
-
*/
|
|
7
|
-
export class ColorJson {
|
|
8
|
-
r: number
|
|
9
|
-
g: number
|
|
10
|
-
b: number
|
|
11
|
-
a: number
|
|
12
|
-
}
|
|
13
|
-
declare module 'css-color-parser-h' {
|
|
14
|
-
/**
|
|
15
|
-
* @description: 解析颜色关键字
|
|
16
|
-
* @param {string} v
|
|
17
|
-
* @return {CssColorParser}
|
|
18
|
-
* @example: parseKeyWord('red')
|
|
19
|
-
*/
|
|
20
|
-
export function parseKeyWord(v: string): CssColorParser
|
|
21
|
-
/**
|
|
22
|
-
* @description: 解析16进制字符串
|
|
23
|
-
* @param {string} v
|
|
24
|
-
* @return {CssColorParser}
|
|
25
|
-
* @example: parseHEX('#FFF')
|
|
26
|
-
*/
|
|
27
|
-
export function parseHEX(v: string): CssColorParser
|
|
28
|
-
/**
|
|
29
|
-
* @description: 解析RGBA
|
|
30
|
-
* @param {string} v
|
|
31
|
-
* @return {CssColorParser}
|
|
32
|
-
* @example: parseRGBA('rgba(255,255,255,1)')
|
|
33
|
-
*/
|
|
34
|
-
export function parseRGBA(v: string): CssColorParser
|
|
35
|
-
/**
|
|
36
|
-
* @description: 解析HSLA
|
|
37
|
-
* @param {string} v
|
|
38
|
-
* @return {CssColorParser}
|
|
39
|
-
* @example: parseHSLA('hsla(215,85%,62%,0.8)')
|
|
40
|
-
*/
|
|
41
|
-
export function parseHSLA(v: string): CssColorParser
|
|
42
|
-
/**
|
|
43
|
-
* @description: 解析HWB
|
|
44
|
-
* @param {string} v
|
|
45
|
-
* @return {CssColorParser}
|
|
46
|
-
* @example: parseHWB('hwb(215deg 30% 6% / 80%)')
|
|
47
|
-
*/
|
|
48
|
-
export function parseHWB(v: string): CssColorParser
|
|
49
|
-
/**
|
|
50
|
-
* @description: 将css字符串转换为解析对象
|
|
51
|
-
* @param {string} v
|
|
52
|
-
* @return {CssColorParser}
|
|
53
|
-
* @example: parseCssColorStr('rgba(255,255,255,1)')
|
|
54
|
-
*/
|
|
55
|
-
export function parseCssColorStr(v: string): CssColorParser
|
|
56
|
-
/**
|
|
57
|
-
* **Deprecated method.** Use `parseCssColorStr()` instead.
|
|
58
|
-
* @description: since 2.0.1
|
|
59
|
-
* @deprecated
|
|
60
|
-
* @param {string} v
|
|
61
|
-
* @return {CssColorParser}
|
|
62
|
-
* @example: fromColorStr('rgba(255,255,255,1)')
|
|
63
|
-
*/
|
|
64
|
-
export function fromColorStr(v: string): CssColorParser
|
|
65
|
-
/**
|
|
66
|
-
* @description: 将HSL色彩模式转换为解析对象
|
|
67
|
-
* @param {number} hue 色相
|
|
68
|
-
* @param {number} saturation 饱和度
|
|
69
|
-
* @param {number} lightness 亮度
|
|
70
|
-
* @param {number} alpha 不透明度
|
|
71
|
-
* @return {CssColorParser}
|
|
72
|
-
* @example: fromHSL(0,1,1,1)
|
|
73
|
-
*/
|
|
74
|
-
export function fromHSL(
|
|
75
|
-
h: number,
|
|
76
|
-
s: number,
|
|
77
|
-
l: number,
|
|
78
|
-
a?: number
|
|
79
|
-
): CssColorParser
|
|
80
|
-
/**
|
|
81
|
-
* @description: 将HWB色彩模式转换为解析对象
|
|
82
|
-
* @param {number} h 色调
|
|
83
|
-
* @param {number} w 白度
|
|
84
|
-
* @param {number} b 黑度
|
|
85
|
-
* @param {number} a 不透明度
|
|
86
|
-
* @return {CssColorParser}
|
|
87
|
-
* @example: fromHSL(0,1,1,1)
|
|
88
|
-
*/
|
|
89
|
-
export function fromHWB(
|
|
90
|
-
h: number,
|
|
91
|
-
w: number,
|
|
92
|
-
b: number,
|
|
93
|
-
a?: number
|
|
94
|
-
): CssColorParser
|
|
95
|
-
/**
|
|
96
|
-
* @description: 产生随机颜色
|
|
97
|
-
* @return {CssColorParser}
|
|
98
|
-
* @example: fromRandom('#000', ''#fff)
|
|
99
|
-
*/
|
|
100
|
-
export function fromRandom(
|
|
101
|
-
color1: string | CssColorParser,
|
|
102
|
-
color2: string | CssColorParser
|
|
103
|
-
): CssColorParser
|
|
104
|
-
/**
|
|
105
|
-
* @description: 将ColorJson格式的json数据转换为解析对象
|
|
106
|
-
* @param {ColorJson} json
|
|
107
|
-
* @return {CssColorParser}
|
|
108
|
-
* @author: roman_123
|
|
109
|
-
*/
|
|
110
|
-
export function fromJson(json: ColorJson): CssColorParser
|
|
111
|
-
/**
|
|
112
|
-
* @description: 将rgba数组转换为解析对象
|
|
113
|
-
* @param {Array} color
|
|
114
|
-
* @return {CssColorParser}
|
|
115
|
-
* @author: roman_123
|
|
116
|
-
*/
|
|
117
|
-
export function fromArray(color: Array<number>): CssColorParser
|
|
118
|
-
export class CssColorParser {
|
|
119
|
-
r: number
|
|
120
|
-
g: number
|
|
121
|
-
b: number
|
|
122
|
-
a: number
|
|
123
|
-
constructor(
|
|
124
|
-
red?: number | string,
|
|
125
|
-
green?: number | string,
|
|
126
|
-
blue?: number | string,
|
|
127
|
-
alpha?: number | string
|
|
128
|
-
)
|
|
129
|
-
/**
|
|
130
|
-
* 设置颜色
|
|
131
|
-
* @param red
|
|
132
|
-
* @param green
|
|
133
|
-
* @param blue
|
|
134
|
-
* @param alpha
|
|
135
|
-
* @example: this.setColor(255,255,255,1)
|
|
136
|
-
*/
|
|
137
|
-
setColor(
|
|
138
|
-
red?: number | string,
|
|
139
|
-
green?: number | string,
|
|
140
|
-
blue?: number | string,
|
|
141
|
-
alpha?: number | string
|
|
142
|
-
): void
|
|
143
|
-
/**
|
|
144
|
-
* @description: 返回rgba格式的css字符串
|
|
145
|
-
* @return {*}
|
|
146
|
-
* @author: roman_123
|
|
147
|
-
*/
|
|
148
|
-
toRGBA(): string
|
|
149
|
-
/**
|
|
150
|
-
* @description: 返回字符串
|
|
151
|
-
* @return {*}
|
|
152
|
-
* @author: roman_123
|
|
153
|
-
*/
|
|
154
|
-
toString(): string
|
|
155
|
-
/**
|
|
156
|
-
* @description: 归一化
|
|
157
|
-
* @return {*}
|
|
158
|
-
* @author: roman_123
|
|
159
|
-
*/
|
|
160
|
-
toNormalize(): ColorJson
|
|
161
|
-
/**
|
|
162
|
-
* @description: 返回16进制格式的css字符串
|
|
163
|
-
* @return {*}
|
|
164
|
-
* @author: roman_123
|
|
165
|
-
*/
|
|
166
|
-
toHEX(): string
|
|
167
|
-
/**
|
|
168
|
-
* @description: 返回rgba数组
|
|
169
|
-
* @return {*}
|
|
170
|
-
* @author: roman_123
|
|
171
|
-
*/
|
|
172
|
-
toArray(): number[]
|
|
173
|
-
/**
|
|
174
|
-
* @description: 返回ColorJson
|
|
175
|
-
* @return {*}
|
|
176
|
-
* @author: roman_123
|
|
177
|
-
*/
|
|
178
|
-
toJson(): ColorJson
|
|
179
|
-
/**
|
|
180
|
-
* @description: 拷贝
|
|
181
|
-
* @return {*}
|
|
182
|
-
* @author: roman_123
|
|
183
|
-
*/
|
|
184
|
-
clone(): CssColorParser
|
|
185
|
-
/**
|
|
186
|
-
* @description: 比较两个解析对象的数据是否相等
|
|
187
|
-
* @param {*} color
|
|
188
|
-
* @return {*}
|
|
189
|
-
* @author: roman_123
|
|
190
|
-
*/
|
|
191
|
-
equals(color: any): boolean
|
|
192
|
-
/**
|
|
193
|
-
* @description: 解析16进制颜色
|
|
194
|
-
* @param {string} v
|
|
195
|
-
* @return {CssColorParser}
|
|
196
|
-
* @example: parseHEX('#FFF')
|
|
197
|
-
*/
|
|
198
|
-
static parseHEX(v: string): CssColorParser
|
|
199
|
-
/**
|
|
200
|
-
* @description: 解析rgba、rgb颜色
|
|
201
|
-
* @param {string} v
|
|
202
|
-
* @return {CssColorParser}
|
|
203
|
-
* @example: parseRGBA('rgba(255,255,255,1)')
|
|
204
|
-
*/
|
|
205
|
-
static parseRGBA(v: string): CssColorParser
|
|
206
|
-
/**
|
|
207
|
-
* @description: 将ColorJson格式的json数据转换为解析对象
|
|
208
|
-
* @param {ColorJson} json
|
|
209
|
-
* @return {CssColorParser}
|
|
210
|
-
* @example: fromJson({r: 255, g: 255, b: 255, a: 1})
|
|
211
|
-
*/
|
|
212
|
-
static fromJson(json: ColorJson): CssColorParser
|
|
213
|
-
/**
|
|
214
|
-
* @description: 将RGBA数组转换为解析对象
|
|
215
|
-
* @param {Array} color
|
|
216
|
-
* @return {CssColorParser}
|
|
217
|
-
* @example: fromJson([255,255,255,1])
|
|
218
|
-
*/
|
|
219
|
-
static fromArray(color: Array<number>): CssColorParser
|
|
220
|
-
/**
|
|
221
|
-
* @description: 产生随机颜色
|
|
222
|
-
* @return {CssColorParser}
|
|
223
|
-
* @example: fromRandom(new CssColorParser(0,0,0,0), new CssColorParser(255,255,255,1))
|
|
224
|
-
*/
|
|
225
|
-
static fromRandom(
|
|
226
|
-
color1: CssColorParser,
|
|
227
|
-
color2: CssColorParser
|
|
228
|
-
): CssColorParser
|
|
229
|
-
}
|
|
230
|
-
}
|