css-color-parser-h 3.0.4 → 3.0.6
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.
Potentially problematic release.
This version of css-color-parser-h might be problematic. Click here for more details.
- package/@types/CssColorParser.d.ts +219 -0
- package/@types/CssColorParserPlus.d.ts +186 -0
- package/@types/index.d.ts +4 -382
- package/example.html +3 -1
- package/lib/css-color-parser-h.cjs.js +936 -0
- package/lib/css-color-parser-h.esm.js +933 -0
- package/lib/css-color-parser-h.umd.js +1 -0
- package/package.json +34 -25
- package/readme.md +8 -2
- package/LICENSE +0 -21
- package/dist/css-color-parser-h.cjs +0 -2550
- package/dist/css-color-parser-h.esm.js +0 -2532
- package/dist/css-color-parser-h.esm.min.js +0 -1
- package/dist/css-color-parser-h.min.cjs +0 -1
- package/dist/css-color-parser-h.umd.js +0 -2559
- package/dist/css-color-parser-h.umd.min.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).Parser={})}(this,(function(t){"use strict";var r=function(){function t(){}return t.type=function(t,r,e){var n=typeof r;if(n!==e)throw new Error("Expected ".concat(t," to be typeof ").concat(e,", actual typeof was ").concat(n))},t.types=function(t,r,e){var n=typeof r;if(!e.includes(n))throw new Error("Expected ".concat(t," to be typeof ").concat(e.join("|"),", actual typeof was ").concat(n))},t.numValue=function(r,e,n,o){t.numMinValue(r,e,n),t.numMaxValue(r,e,o)},t.numMinValue=function(t,r,e){if(r<e)throw new Error("Expected ".concat(t," to > ").concat(e,", actual value was ").concat(r))},t.numMaxValue=function(t,r,e){if(r>e)throw new Error("Expected ".concat(t," to < ").concat(e,", actual value was ").concat(r))},t.numIsInt=function(t,r,e){var n=Math.floor(r)===r;if(n!==e)throw new Error("Expected ".concat(t," to ").concat(e?"Integer":"Float",", actual value was ").concat(n?"Integer":"Float"))},t}();function e(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function n(t,r,e){return e>r?e=r:e<t&&(e=t),e}function o(t,r){void 0===t&&(t=0);var e=Math.pow(10,r);return Math.round(t*e)/e}var a,s,i,c,u,l,h,p,f=function(){function t(){}return t.clearStrSpace=function(t){return t.replace(/\s/g,"")},t.trimStr=function(t){return(t=t.replace(/\s+/g," ")).trim()},t.parse3BitsHEX=function(r){var n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(r);if(n){var o=e(n[4],"f");return[t._parseResStrForRgb(parseInt(n[1]+n[1],16)),t._parseResStrForRgb(parseInt(n[2]+n[2],16)),t._parseResStrForRgb(parseInt(n[3]+n[3],16)),t._parsePercent(parseInt(o+o,16)/255)]}return null},t.parse6BitsHEX=function(r){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(r);if(n){var o=e(n[4],"ff");return[t._parseResStrForRgb(parseInt(n[1],16)),t._parseResStrForRgb(parseInt(n[2],16)),t._parseResStrForRgb(parseInt(n[3],16)),t._parsePercent(parseInt(o,16)/255)]}return null},t.parseRGBA=function(r){var e=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return e?[t._parseResStrForRgb(e[1]),t._parseResStrForRgb(e[2]),t._parseResStrForRgb(e[3]),t._parsePercent(e[4])]:null},t.parseHSLA=function(r){var e=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t.parseHWB=function(r){var e=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t.parseRGBA2=function(r){var e=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForRgb(e[1]),t._parseResStrForRgb(e[2]),t._parseResStrForRgb(e[3]),t._parsePercent(e[4])]:null},t.parseHSLA2=function(r){var e=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t._parseResStrForRgb=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100/255:1)),isNaN(t)&&(t=1),n(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),n(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),n(0,1,t)},t}(),b=function(){function t(t,r,e,n){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(t,r,e,n)}return t.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},t.prototype.setColor=function(t,r,o,a,s){return void 0===s&&(s=!0),s?(this.r=n(0,255,e(Number(t),0)),this.g=n(0,255,e(Number(r),0)),this.b=n(0,255,e(Number(o),0)),this.a=n(0,1,e(Number(a),1))):(this.r=e(Number(t),0),this.g=e(Number(r),0),this.b=e(Number(o),0),this.a=e(Number(a),1)),this},t.prototype.limitColor=function(){return this.setColor(this.r,this.g,this.b,this.a,!0)},t.prototype.setAlpha=function(t){return this.a=n(0,1,e(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=n(0,255,e(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=n(0,255,e(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=n(0,255,e(Number(t),0)),this},t.prototype.toRGBA=function(){var t=this.toJson();return 1===t.a?"rgb(".concat(t.r,",").concat(t.g,",").concat(t.b,")"):"rgba(".concat(t.r,",").concat(t.g,",").concat(t.b,",").concat(t.a,")")},t.prototype.toString=function(){return this.toRGBA()},t.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)]},t.prototype.toHEX=function(){var t=this.toJson(),r=t.r.toString(16);r.length<2&&(r="0".concat(r));var e=t.g.toString(16);e.length<2&&(e="0".concat(e));var n=t.b.toString(16);if(n.length<2&&(n="0".concat(n)),this.a<1){var o=parseInt((255*this.a).toFixed()).toString(16);return o.length<2&&(o="0".concat(o)),"#".concat(r).concat(e).concat(n).concat(o)}return"#".concat(r).concat(e).concat(n)},t.prototype.toArray=function(){var t=this.toJson();return[t.r,t.g,t.b,t.a]},t.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)}},t.prototype.toInvert=function(){return new t(255-this.r,255-this.g,255-this.b,1-this.a)},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.equals=function(t){if(this===t)return!0;var r=this.toJson(),e=t.toJson();return r.r===e.r&&r.g===e.g&&r.b===e.g&&r.a===e.a},t.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},t.prototype.multiplyByScalar=function(t,r){void 0===r&&(r=!0);var e=this.r*t,n=this.g*t,o=this.b*t,a=r?this.a*t:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var e=this.r/t,n=this.g/t,o=this.b/t,a=r?this.a/t:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.add=function(t,r){void 0===r&&(r=!0);var e=this.r+t.r,n=this.g+t.g,o=this.b+t.b,a=r?this.a+t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.subtract=function(t,r){void 0===r&&(r=!0);var e=this.r-t.r,n=this.g-t.g,o=this.b-t.b,a=r?this.a-t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.multiply=function(t,r){void 0===r&&(r=!0);var e=this.r*t.r,n=this.g*t.g,o=this.b*t.b,a=r?this.a*t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.divide=function(t,r){void 0===r&&(r=!0);var e=this.r/t.r,n=this.g/t.g,o=this.b/t.b,a=r?this.a/t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.addNumberForRGB=function(t){return this.r=this.r+t,this.g=this.g+t,this.b=this.b+t,this},t.prototype.addNumberForAlpha=function(t){return this.a=this.a+t,this},t.parseHEX=function(r){var e=f.clearStrSpace(r),n=f.parse3BitsHEX(e);return n||(n=f.parse6BitsHEX(e)),n&&t.fromArray(n)},t.parseRGBA=function(r){var e=f.clearStrSpace(r),n=f.parseRGBA(e);if(!n){var o=f.trimStr(r);n=f.parseRGBA2(o)}return n&&t.fromArray(n)},t.fromJson=function(r){return new t(r.r,r.g,r.b,r.a)},t.fromArray=function(r){return new t(r[0],r[1],r[2],r[3])},t.fromRandom=function(r,e){return new t(Math.random()*Math.abs(e.r-r.r)+Math.min(r.r,e.r),Math.random()*Math.abs(e.g-r.g)+Math.min(r.g,e.g),Math.random()*Math.abs(e.b-r.b)+Math.min(r.b,e.b),Math.random()*Math.abs(e.a-r.a)+Math.min(r.a,e.a))},t.fromNormalize=function(r){var e=255*r[0],n=255*r[1],o=255*r[2],a=r[3];return t.fromArray([e,n,o,a])},t}(),g=function(t,r){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},g(t,r)};function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function y(){if(c)return i;c=1;const t=s?a:(s=1,a={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]}),r={};for(const e of Object.keys(t))r[t[e]]=e;const e={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"]}};i=e;for(const t of Object.keys(e)){if(!("channels"in e[t]))throw new Error("missing channels property: "+t);if(!("labels"in e[t]))throw new Error("missing channel labels property: "+t);if(e[t].labels.length!==e[t].channels)throw new Error("channel and label counts mismatch: "+t);const{channels:r,labels:n}=e[t];delete e[t].channels,delete e[t].labels,Object.defineProperty(e[t],"channels",{value:r}),Object.defineProperty(e[t],"labels",{value:n})}return e.rgb.hsl=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.min(r,e,n),a=Math.max(r,e,n),s=a-o;let i,c;a===o?i=0:r===a?i=(e-n)/s:e===a?i=2+(n-r)/s:n===a&&(i=4+(r-e)/s),i=Math.min(60*i,360),i<0&&(i+=360);const u=(o+a)/2;return c=a===o?0:u<=.5?s/(a+o):s/(2-a-o),[i,100*c,100*u]},e.rgb.hsv=function(t){let r,e,n,o,a;const s=t[0]/255,i=t[1]/255,c=t[2]/255,u=Math.max(s,i,c),l=u-Math.min(s,i,c),h=function(t){return(u-t)/6/l+.5};return 0===l?(o=0,a=0):(a=l/u,r=h(s),e=h(i),n=h(c),s===u?o=n-e:i===u?o=1/3+r-n:c===u&&(o=2/3+e-r),o<0?o+=1:o>1&&(o-=1)),[360*o,100*a,100*u]},e.rgb.hwb=function(t){const r=t[0],n=t[1];let o=t[2];const a=e.rgb.hsl(t)[0],s=1/255*Math.min(r,Math.min(n,o));return o=1-1/255*Math.max(r,Math.max(n,o)),[a,100*s,100*o]},e.rgb.cmyk=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.min(1-r,1-e,1-n);return[100*((1-r-o)/(1-o)||0),100*((1-e-o)/(1-o)||0),100*((1-n-o)/(1-o)||0),100*o]},e.rgb.keyword=function(e){const n=r[e];if(n)return n;let o,a=1/0;for(const r of Object.keys(t)){const n=t[r],c=(i=n,((s=e)[0]-i[0])**2+(s[1]-i[1])**2+(s[2]-i[2])**2);c<a&&(a=c,o=r)}var s,i;return o},e.keyword.rgb=function(r){return t[r]},e.rgb.xyz=function(t){let r=t[0]/255,e=t[1]/255,n=t[2]/255;r=r>.04045?((r+.055)/1.055)**2.4:r/12.92,e=e>.04045?((e+.055)/1.055)**2.4:e/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92;return[100*(.4124*r+.3576*e+.1805*n),100*(.2126*r+.7152*e+.0722*n),100*(.0193*r+.1192*e+.9505*n)]},e.rgb.lab=function(t){const r=e.rgb.xyz(t);let n=r[0],o=r[1],a=r[2];n/=95.047,o/=100,a/=108.883,n=n>.008856?n**(1/3):7.787*n+16/116,o=o>.008856?o**(1/3):7.787*o+16/116,a=a>.008856?a**(1/3):7.787*a+16/116;return[116*o-16,500*(n-o),200*(o-a)]},e.hsl.rgb=function(t){const r=t[0]/360,e=t[1]/100,n=t[2]/100;let o,a,s;if(0===e)return s=255*n,[s,s,s];o=n<.5?n*(1+e):n+e-n*e;const i=2*n-o,c=[0,0,0];for(let t=0;t<3;t++)a=r+1/3*-(t-1),a<0&&a++,a>1&&a--,s=6*a<1?i+6*(o-i)*a:2*a<1?o:3*a<2?i+(o-i)*(2/3-a)*6:i,c[t]=255*s;return c},e.hsl.hsv=function(t){const r=t[0];let e=t[1]/100,n=t[2]/100,o=e;const a=Math.max(n,.01);n*=2,e*=n<=1?n:2-n,o*=a<=1?a:2-a;return[r,100*(0===n?2*o/(a+o):2*e/(n+e)),100*((n+e)/2)]},e.hsv.rgb=function(t){const r=t[0]/60,e=t[1]/100;let n=t[2]/100;const o=Math.floor(r)%6,a=r-Math.floor(r),s=255*n*(1-e),i=255*n*(1-e*a),c=255*n*(1-e*(1-a));switch(n*=255,o){case 0:return[n,c,s];case 1:return[i,n,s];case 2:return[s,n,c];case 3:return[s,i,n];case 4:return[c,s,n];case 5:return[n,s,i]}},e.hsv.hsl=function(t){const r=t[0],e=t[1]/100,n=t[2]/100,o=Math.max(n,.01);let a,s;s=(2-e)*n;const i=(2-e)*o;return a=e*o,a/=i<=1?i:2-i,a=a||0,s/=2,[r,100*a,100*s]},e.hwb.rgb=function(t){const r=t[0]/360;let e=t[1]/100,n=t[2]/100;const o=e+n;let a;o>1&&(e/=o,n/=o);const s=Math.floor(6*r),i=1-n;a=6*r-s,1&s&&(a=1-a);const c=e+a*(i-e);let u,l,h;switch(s){default:case 6:case 0:u=i,l=c,h=e;break;case 1:u=c,l=i,h=e;break;case 2:u=e,l=i,h=c;break;case 3:u=e,l=c,h=i;break;case 4:u=c,l=e,h=i;break;case 5:u=i,l=e,h=c}return[255*u,255*l,255*h]},e.cmyk.rgb=function(t){const r=t[0]/100,e=t[1]/100,n=t[2]/100,o=t[3]/100;return[255*(1-Math.min(1,r*(1-o)+o)),255*(1-Math.min(1,e*(1-o)+o)),255*(1-Math.min(1,n*(1-o)+o))]},e.xyz.rgb=function(t){const r=t[0]/100,e=t[1]/100,n=t[2]/100;let o,a,s;return o=3.2406*r+-1.5372*e+-.4986*n,a=-.9689*r+1.8758*e+.0415*n,s=.0557*r+-.204*e+1.057*n,o=o>.0031308?1.055*o**(1/2.4)-.055:12.92*o,a=a>.0031308?1.055*a**(1/2.4)-.055:12.92*a,s=s>.0031308?1.055*s**(1/2.4)-.055:12.92*s,o=Math.min(Math.max(0,o),1),a=Math.min(Math.max(0,a),1),s=Math.min(Math.max(0,s),1),[255*o,255*a,255*s]},e.xyz.lab=function(t){let r=t[0],e=t[1],n=t[2];r/=95.047,e/=100,n/=108.883,r=r>.008856?r**(1/3):7.787*r+16/116,e=e>.008856?e**(1/3):7.787*e+16/116,n=n>.008856?n**(1/3):7.787*n+16/116;return[116*e-16,500*(r-e),200*(e-n)]},e.lab.xyz=function(t){let r,e,n;e=(t[0]+16)/116,r=t[1]/500+e,n=e-t[2]/200;const o=e**3,a=r**3,s=n**3;return e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,n=s>.008856?s:(n-16/116)/7.787,r*=95.047,e*=100,n*=108.883,[r,e,n]},e.lab.lch=function(t){const r=t[0],e=t[1],n=t[2];let o;o=360*Math.atan2(n,e)/2/Math.PI,o<0&&(o+=360);return[r,Math.sqrt(e*e+n*n),o]},e.lch.lab=function(t){const r=t[0],e=t[1],n=t[2]/360*2*Math.PI;return[r,e*Math.cos(n),e*Math.sin(n)]},e.rgb.ansi16=function(t,r=null){const[n,o,a]=t;let s=null===r?e.rgb.hsv(t)[2]:r;if(s=Math.round(s/50),0===s)return 30;let i=30+(Math.round(a/255)<<2|Math.round(o/255)<<1|Math.round(n/255));return 2===s&&(i+=60),i},e.hsv.ansi16=function(t){return e.rgb.ansi16(e.hsv.rgb(t),t[2])},e.rgb.ansi256=function(t){const r=t[0],e=t[1],n=t[2];if(r===e&&e===n)return r<8?16:r>248?231:Math.round((r-8)/247*24)+232;return 16+36*Math.round(r/255*5)+6*Math.round(e/255*5)+Math.round(n/255*5)},e.ansi16.rgb=function(t){let r=t%10;if(0===r||7===r)return t>50&&(r+=3.5),r=r/10.5*255,[r,r,r];const e=.5*(1+~~(t>50));return[(1&r)*e*255,(r>>1&1)*e*255,(r>>2&1)*e*255]},e.ansi256.rgb=function(t){if(t>=232){const r=10*(t-232)+8;return[r,r,r]}let r;t-=16;return[Math.floor(t/36)/5*255,Math.floor((r=t%36)/6)/5*255,r%6/5*255]},e.rgb.hex=function(t){const r=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(r.length)+r},e.hex.rgb=function(t){const r=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!r)return[0,0,0];let e=r[0];3===r[0].length&&(e=e.split("").map((t=>t+t)).join(""));const n=parseInt(e,16);return[n>>16&255,n>>8&255,255&n]},e.rgb.hcg=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.max(Math.max(r,e),n),a=Math.min(Math.min(r,e),n),s=o-a;let i,c;return i=s<1?a/(1-s):0,c=s<=0?0:o===r?(e-n)/s%6:o===e?2+(n-r)/s:4+(r-e)/s,c/=6,c%=1,[360*c,100*s,100*i]},e.hsl.hcg=function(t){const r=t[1]/100,e=t[2]/100,n=e<.5?2*r*e:2*r*(1-e);let o=0;return n<1&&(o=(e-.5*n)/(1-n)),[t[0],100*n,100*o]},e.hsv.hcg=function(t){const r=t[1]/100,e=t[2]/100,n=r*e;let o=0;return n<1&&(o=(e-n)/(1-n)),[t[0],100*n,100*o]},e.hcg.rgb=function(t){const r=t[0]/360,e=t[1]/100,n=t[2]/100;if(0===e)return[255*n,255*n,255*n];const o=[0,0,0],a=r%1*6,s=a%1,i=1-s;let c=0;switch(Math.floor(a)){case 0:o[0]=1,o[1]=s,o[2]=0;break;case 1:o[0]=i,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]=i,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]=i}return c=(1-e)*n,[255*(e*o[0]+c),255*(e*o[1]+c),255*(e*o[2]+c)]},e.hcg.hsv=function(t){const r=t[1]/100,e=r+t[2]/100*(1-r);let n=0;return e>0&&(n=r/e),[t[0],100*n,100*e]},e.hcg.hsl=function(t){const r=t[1]/100,e=t[2]/100*(1-r)+.5*r;let n=0;return e>0&&e<.5?n=r/(2*e):e>=.5&&e<1&&(n=r/(2*(1-e))),[t[0],100*n,100*e]},e.hcg.hwb=function(t){const r=t[1]/100,e=r+t[2]/100*(1-r);return[t[0],100*(e-r),100*(1-e)]},e.hwb.hcg=function(t){const r=t[1]/100,e=1-t[2]/100,n=e-r;let o=0;return n<1&&(o=(e-n)/(1-n)),[t[0],100*n,100*o]},e.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},e.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},e.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},e.gray.hsl=function(t){return[0,0,t[0]]},e.gray.hsv=e.gray.hsl,e.gray.hwb=function(t){return[0,100,t[0]]},e.gray.cmyk=function(t){return[0,0,0,t[0]]},e.gray.lab=function(t){return[t[0],0,0]},e.gray.hex=function(t){const r=255&Math.round(t[0]/100*255),e=((r<<16)+(r<<8)+r).toString(16).toUpperCase();return"000000".substring(e.length)+e},e.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]},i}function m(){if(l)return u;l=1;const t=y();function r(r){const e=function(){const r={},e=Object.keys(t);for(let t=e.length,n=0;n<t;n++)r[e[n]]={distance:-1,parent:null};return r}(),n=[r];for(e[r].distance=0;n.length;){const r=n.pop(),o=Object.keys(t[r]);for(let t=o.length,a=0;a<t;a++){const t=o[a],s=e[t];-1===s.distance&&(s.distance=e[r].distance+1,s.parent=r,n.unshift(t))}}return e}function e(t,r){return function(e){return r(t(e))}}function n(r,n){const o=[n[r].parent,r];let a=t[n[r].parent][r],s=n[r].parent;for(;n[s].parent;)o.unshift(n[s].parent),a=e(t[n[s].parent][s],a),s=n[s].parent;return a.conversion=o,a}return u=function(t){const e=r(t),o={},a=Object.keys(e);for(let t=a.length,r=0;r<t;r++){const t=a[r];null!==e[t].parent&&(o[t]=n(t,e))}return o}}"function"==typeof SuppressedError&&SuppressedError;var v=function(){if(p)return h;p=1;const t=y(),r=m(),e={};return Object.keys(t).forEach((n=>{e[n]={},Object.defineProperty(e[n],"channels",{value:t[n].channels}),Object.defineProperty(e[n],"labels",{value:t[n].labels});const o=r(n);Object.keys(o).forEach((t=>{const r=o[t];e[n][t]=function(t){const r=function(...r){const e=r[0];if(null==e)return e;e.length>1&&(r=e);const n=t(r);if("object"==typeof n)for(let t=n.length,r=0;r<t;r++)n[r]=Math.round(n[r]);return n};return"conversion"in t&&(r.conversion=t.conversion),r}(r),e[n][t].raw=function(t){const r=function(...r){const e=r[0];return null==e?e:(e.length>1&&(r=e),t(r))};return"conversion"in t&&(r.conversion=t.conversion),r}(r)}))})),h=e}(),M=d(v),w=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}g(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}(o,t),o.prototype.toInvert=function(){return new o(255-this.r,255-this.g,255-this.b,1-this.a)},o.prototype.clone=function(){return new o(this.r,this.g,this.b,this.a)},o.prototype.equals=function(t){if(this===(t=o.parseColor(t)))return!0;var r=this.toJson(),e=t.toJson();return r.r===e.r&&r.g===e.g&&r.b===e.g&&r.a===e.a},o.prototype.add=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.add.call(this,n,e)},o.prototype.subtract=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.subtract.call(this,n,e)},o.prototype.multiply=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.multiply.call(this,n,e)},o.prototype.divide=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.divide.call(this,n,e)},o.parseColor=function(t){return t instanceof b?t:o.parseCssColorStr(t)},o.parseCssColorStr=function(t){return r.type("color",t,"string"),o.parseHEX(t)||o.parseRGBA(t)||o.parseKeyWord(t)||o.parseHSLA(t)||o.parseHWB(t)},o.parseKeyWord=function(t){var r=f.clearStrSpace(t),e=M.keyword.rgb(r);return e&&o.fromArray(e)},o.parseHSLA=function(t){var r=f.clearStrSpace(t),e=f.parseHSLA(r);if(!e){var n=f.trimStr(t);e=f.parseHSLA2(n)}return e&&o.fromHSL(e[0],e[1],e[2],e[3])},o.parseHWB=function(t){var r=f.trimStr(t),e=f.parseHWB(r);return e&&o.fromHWB(e[0],e[1],e[2],e[3])},o.fromHSL=function(t,r,a,s){var i=M.hsl.rgb(n(0,360,t),n(0,100,100*r),n(0,100,100*a));return new o(i[0],i[1],i[2],e(Number(s),1))},o.fromHWB=function(t,r,a,s){var i=M.hwb.rgb(n(0,360,t),n(0,100,100*r),n(0,100,100*a));return new o(i[0],i[1],i[2],e(Number(s),1))},o.parseHEX=function(t){var r=f.clearStrSpace(t),e=f.parse3BitsHEX(r);return e||(e=f.parse6BitsHEX(r)),e&&o.fromArray(e)},o.parseRGBA=function(t){var r=f.clearStrSpace(t),e=f.parseRGBA(r);if(!e){var n=f.trimStr(t);e=f.parseRGBA2(n)}return e&&o.fromArray(e)},o.fromJson=function(t){return new o(t.r,t.g,t.b,t.a)},o.fromArray=function(t){return new o(t[0],t[1],t[2],t[3])},o.fromRandom=function(t,r){return t=o.parseColor(t),r=o.parseColor(r),new o(Math.random()*Math.abs(r.r-t.r)+Math.min(t.r,r.r),Math.random()*Math.abs(r.g-t.g)+Math.min(t.g,r.g),Math.random()*Math.abs(r.b-t.b)+Math.min(t.b,r.b),Math.random()*Math.abs(r.a-t.a)+Math.min(t.a,r.a))},o.fromNormalize=function(t){var r=255*t[0],e=255*t[1],n=255*t[2],a=t[3];return o.fromArray([r,e,n,a])},o.lerp=function(t,r){var e=Object.keys(t).map((function(t){return Number(t)}));e.sort((function(t,r){return t-r}));for(var n=0;n<e.length;n++)if(r<=e[n]){var a=e[n-1],s=e[n];if(void 0===a)return o.parseColor(t[s]);var i=(r-a)/(s-a),c=o.parseColor(t[a]);return o.parseColor(t[s]).subtract(c).multiplyByScalar(i).add(c)}return o.parseColor(t[e[e.length-1]]).limitColor()},o}(b);t.CssColorParser=b,t.CssColorParserPlus=w}));
|
package/package.json
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-color-parser-h",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "A tool for parsing css color",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
5
|
+
"main": "lib/css-color-parser-h.cjs.js",
|
|
6
|
+
"module": "lib/css-color-parser-h.esm.js",
|
|
7
|
+
"jsnext:main": "lib/css-color-parser-h.esm.js",
|
|
8
|
+
"browser": "lib/css-color-parser-h.umd.js",
|
|
9
|
+
"types": "@types/css-color-parser-h.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./@types/index.d.ts",
|
|
13
|
+
"import": "./lib/css-color-parser-h.esm.js",
|
|
14
|
+
"require": "./lib/css-color-parser-h.cjs.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib",
|
|
20
|
+
"@types",
|
|
21
|
+
"example.html"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
7
24
|
"scripts": {
|
|
8
|
-
"build": "
|
|
25
|
+
"build": "rollup -c rollup.config.mjs",
|
|
9
26
|
"test": "npm run build && jest",
|
|
10
27
|
"test-c": "jest --coverage"
|
|
11
28
|
},
|
|
@@ -21,30 +38,22 @@
|
|
|
21
38
|
"conversion"
|
|
22
39
|
],
|
|
23
40
|
"author": "roman_123",
|
|
24
|
-
"license": "
|
|
25
|
-
"files": [
|
|
26
|
-
"dist",
|
|
27
|
-
"example.html",
|
|
28
|
-
"LICENSE",
|
|
29
|
-
"readme.md",
|
|
30
|
-
"package.json",
|
|
31
|
-
"@types"
|
|
32
|
-
],
|
|
41
|
+
"license": "ISC",
|
|
33
42
|
"dependencies": {
|
|
34
43
|
"color-convert": "^2.0.1"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
37
|
-
"@babel/
|
|
38
|
-
"@babel/preset-env": "^7.
|
|
39
|
-
"babel
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
46
|
+
"@babel/plugin-transform-runtime": "^7.26.10",
|
|
47
|
+
"@babel/preset-env": "^7.26.9",
|
|
48
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
49
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
50
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
51
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
52
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
53
|
+
"rollup": "^4.37.0",
|
|
54
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
55
|
+
"tslib": "^2.8.1",
|
|
56
|
+
"typescript": "^5.8.2",
|
|
57
|
+
"jest": "^29.7.0"
|
|
49
58
|
}
|
|
50
59
|
}
|
package/readme.md
CHANGED
|
@@ -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-h.umd.
|
|
17
|
+
<script src="./dist/css-color-parser-h.umd.js"></script>
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
@@ -79,6 +79,8 @@ colorParser.addNumberForRGB(num: number): CssColorParserPlus;
|
|
|
79
79
|
colorParser.addNumberForAlpha(num: number): CssColorParserPlus;
|
|
80
80
|
colorParser.clone():CssColorParserPlus
|
|
81
81
|
colorParser.equals(color: CssColorParserPlus):boolean
|
|
82
|
+
// 将颜色限制在0-255之间
|
|
83
|
+
colorParser.limitColor(): CssColorParserPlus
|
|
82
84
|
// 静态方法
|
|
83
85
|
CssColorParserPlus.parseKeyWord(v: string): CssColorParserPlus
|
|
84
86
|
CssColorParserPlus.parseHEX(v: string): CssColorParserPlus
|
|
@@ -93,6 +95,8 @@ CssColorParserPlus.fromRandom(color1: string | CssColorParser,color2: string | C
|
|
|
93
95
|
CssColorParserPlus.fromJson(json: ColorJson): CssColorParserPlus
|
|
94
96
|
CssColorParserPlus.fromArray(color: Array<number>): CssColorParserPlus
|
|
95
97
|
CssColorParserPlus.fromNormalize(colorArr: [number, number, number, number]): CssColorParserPlus;
|
|
98
|
+
// 计算颜色插值
|
|
99
|
+
CssColorParserPlus.lerp(opt: ColorLerpOpt, value: number): CssColorParserPlus
|
|
96
100
|
```
|
|
97
101
|
|
|
98
102
|
## Example
|
|
@@ -122,7 +126,7 @@ CssColorParserPlus.parseRGBA('rgba(76 144 240 / 80%)') // CssColorParser {r: 76,
|
|
|
122
126
|
CssColorParserPlus.fromRandom('blue', 'red').toRGBA() // rgb(4,0,34)
|
|
123
127
|
CssColorParserPlus.fromRandom('blue', '#ccffbbaa').toRGBA() // rgba(127,128,239,0.92)
|
|
124
128
|
CssColorParserPlus.fromRandom(new CssColorParser(205,205,100,0.5), '#ccffbbaa').toRGBA() // rgba(205,211,152,0.53)
|
|
125
|
-
CssColorParserPlus.fromRandom(
|
|
129
|
+
CssColorParserPlus.fromRandom(CssColorParserPlus.fromArray([205,205,100,0.5]), '#ccffbbaa').toRGBA() // rgba(205,235,131,0.62)
|
|
126
130
|
// 颜色相加
|
|
127
131
|
const colorParser = new CssColorParserPlus(0,20,0,1)
|
|
128
132
|
colorParser.toHEX()
|
|
@@ -132,4 +136,6 @@ const res = CssColorParserPlus.parseColor('#000').add('red').subtract('rgba(10,2
|
|
|
132
136
|
console.log(res)
|
|
133
137
|
// 归一化
|
|
134
138
|
CssColorParserPlus.fromArray([100, 200, 0, 0.552]).toNormalize() // { r: 0.39, g: 0.78, b: 0, a: 0.55 }
|
|
139
|
+
// 计算插值
|
|
140
|
+
CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)", 1: "rgba(255, 0, 0, 1)"}, 0.8) // CssColorParser { r: 153, g: 102, b: 0, a: 1 }
|
|
135
141
|
```
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 roman_123
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|