css-color-parser-h 1.0.0 → 1.0.1
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/example.html +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/release.js +3 -3
- package/dist/css-color-parser.min.js +0 -1
- package/dist/css-color-parser.min.ts +0 -123
package/example.html
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-color-parser-h",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A tool for parsing css color",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "./dist/css-color-parser.min.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "webpack && node release.js"
|
|
8
8
|
},
|
package/readme.md
CHANGED
|
@@ -83,7 +83,7 @@ fromArray(color: Array<number>): CssColorParser
|
|
|
83
83
|
// 实例方法
|
|
84
84
|
setColor(red?: number | string,green?: number | string,blue?: number | string,alpha?: number | string)
|
|
85
85
|
toCssColorString(): string
|
|
86
|
-
|
|
86
|
+
toCssHEXString(): string
|
|
87
87
|
toString(): string
|
|
88
88
|
toNormalize(): ColorJson
|
|
89
89
|
toArray(): number[]
|
package/release.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @Author: roman_123
|
|
3
3
|
* @Description: webpack打包后处理
|
|
4
4
|
* @Date: 2022-12-05 09:03:05
|
|
5
|
-
* @LastEditTime: 2022-12-06
|
|
5
|
+
* @LastEditTime: 2022-12-06 18:29:57
|
|
6
6
|
*/
|
|
7
|
-
const fs=require('fs-extra')
|
|
7
|
+
const fs = require('fs-extra')
|
|
8
8
|
const path = require('path')
|
|
9
9
|
const basePath = path.resolve(__dirname, './dist')
|
|
10
10
|
const delFileList = ['./utils']
|
|
@@ -14,6 +14,6 @@ delFileList.forEach(file => {
|
|
|
14
14
|
fs.removeSync(filePath)
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
fs.renameSync(path.join(basePath, './main.d.ts'), path.join(basePath, './css-color-parser.min.ts'))
|
|
17
|
+
fs.renameSync(path.join(basePath, './main.d.ts'), path.join(basePath, './css-color-parser.min.d.ts'))
|
|
18
18
|
|
|
19
19
|
console.log(new Date().toLocaleString(), '打包完成!')
|
|
@@ -1 +0,0 @@
|
|
|
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={168:function(r,e,t){const n=t(874),a={};for(const r of Object.keys(n))a[n[r]]=r;const o={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=o;for(const r of Object.keys(o)){if(!("channels"in o[r]))throw new Error("missing channels property: "+r);if(!("labels"in o[r]))throw new Error("missing channel labels property: "+r);if(o[r].labels.length!==o[r].channels)throw new Error("channel and label counts mismatch: "+r);const{channels:e,labels:t}=o[r];delete o[r].channels,delete o[r].labels,Object.defineProperty(o[r],"channels",{value:e}),Object.defineProperty(o[r],"labels",{value:t})}o.rgb.hsl=function(r){const e=r[0]/255,t=r[1]/255,n=r[2]/255,a=Math.min(e,t,n),o=Math.max(e,t,n),s=o-a;let c,i;o===a?c=0:e===o?c=(t-n)/s:t===o?c=2+(n-e)/s:n===o&&(c=4+(e-t)/s),c=Math.min(60*c,360),c<0&&(c+=360);const l=(a+o)/2;return i=o===a?0:l<=.5?s/(o+a):s/(2-o-a),[c,100*i,100*l]},o.rgb.hsv=function(r){let e,t,n,a,o;const s=r[0]/255,c=r[1]/255,i=r[2]/255,l=Math.max(s,c,i),u=l-Math.min(s,c,i),h=function(r){return(l-r)/6/u+.5};return 0===u?(a=0,o=0):(o=u/l,e=h(s),t=h(c),n=h(i),s===l?a=n-t:c===l?a=1/3+e-n:i===l&&(a=2/3+t-e),a<0?a+=1:a>1&&(a-=1)),[360*a,100*o,100*l]},o.rgb.hwb=function(r){const e=r[0],t=r[1];let n=r[2];const a=o.rgb.hsl(r)[0],s=1/255*Math.min(e,Math.min(t,n));return n=1-1/255*Math.max(e,Math.max(t,n)),[a,100*s,100*n]},o.rgb.cmyk=function(r){const e=r[0]/255,t=r[1]/255,n=r[2]/255,a=Math.min(1-e,1-t,1-n);return[100*((1-e-a)/(1-a)||0),100*((1-t-a)/(1-a)||0),100*((1-n-a)/(1-a)||0),100*a]},o.rgb.keyword=function(r){const e=a[r];if(e)return e;let t,o=1/0;for(const e of Object.keys(n)){const a=(c=n[e],((s=r)[0]-c[0])**2+(s[1]-c[1])**2+(s[2]-c[2])**2);a<o&&(o=a,t=e)}var s,c;return t},o.keyword.rgb=function(r){return n[r]},o.rgb.xyz=function(r){let e=r[0]/255,t=r[1]/255,n=r[2]/255;return e=e>.04045?((e+.055)/1.055)**2.4:e/12.92,t=t>.04045?((t+.055)/1.055)**2.4:t/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92,[100*(.4124*e+.3576*t+.1805*n),100*(.2126*e+.7152*t+.0722*n),100*(.0193*e+.1192*t+.9505*n)]},o.rgb.lab=function(r){const e=o.rgb.xyz(r);let t=e[0],n=e[1],a=e[2];return t/=95.047,n/=100,a/=108.883,t=t>.008856?t**(1/3):7.787*t+16/116,n=n>.008856?n**(1/3):7.787*n+16/116,a=a>.008856?a**(1/3):7.787*a+16/116,[116*n-16,500*(t-n),200*(n-a)]},o.hsl.rgb=function(r){const e=r[0]/360,t=r[1]/100,n=r[2]/100;let a,o,s;if(0===t)return s=255*n,[s,s,s];a=n<.5?n*(1+t):n+t-n*t;const c=2*n-a,i=[0,0,0];for(let r=0;r<3;r++)o=e+1/3*-(r-1),o<0&&o++,o>1&&o--,s=6*o<1?c+6*(a-c)*o:2*o<1?a:3*o<2?c+(a-c)*(2/3-o)*6:c,i[r]=255*s;return i},o.hsl.hsv=function(r){const e=r[0];let t=r[1]/100,n=r[2]/100,a=t;const o=Math.max(n,.01);return n*=2,t*=n<=1?n:2-n,a*=o<=1?o:2-o,[e,100*(0===n?2*a/(o+a):2*t/(n+t)),(n+t)/2*100]},o.hsv.rgb=function(r){const e=r[0]/60,t=r[1]/100;let n=r[2]/100;const a=Math.floor(e)%6,o=e-Math.floor(e),s=255*n*(1-t),c=255*n*(1-t*o),i=255*n*(1-t*(1-o));switch(n*=255,a){case 0:return[n,i,s];case 1:return[c,n,s];case 2:return[s,n,i];case 3:return[s,c,n];case 4:return[i,s,n];case 5:return[n,s,c]}},o.hsv.hsl=function(r){const e=r[0],t=r[1]/100,n=r[2]/100,a=Math.max(n,.01);let o,s;s=(2-t)*n;const c=(2-t)*a;return o=t*a,o/=c<=1?c:2-c,o=o||0,s/=2,[e,100*o,100*s]},o.hwb.rgb=function(r){const e=r[0]/360;let t=r[1]/100,n=r[2]/100;const a=t+n;let o;a>1&&(t/=a,n/=a);const s=Math.floor(6*e),c=1-n;o=6*e-s,0!=(1&s)&&(o=1-o);const i=t+o*(c-t);let l,u,h;switch(s){default:case 6:case 0:l=c,u=i,h=t;break;case 1:l=i,u=c,h=t;break;case 2:l=t,u=c,h=i;break;case 3:l=t,u=i,h=c;break;case 4:l=i,u=t,h=c;break;case 5:l=c,u=t,h=i}return[255*l,255*u,255*h]},o.cmyk.rgb=function(r){const e=r[0]/100,t=r[1]/100,n=r[2]/100,a=r[3]/100;return[255*(1-Math.min(1,e*(1-a)+a)),255*(1-Math.min(1,t*(1-a)+a)),255*(1-Math.min(1,n*(1-a)+a))]},o.xyz.rgb=function(r){const e=r[0]/100,t=r[1]/100,n=r[2]/100;let a,o,s;return a=3.2406*e+-1.5372*t+-.4986*n,o=-.9689*e+1.8758*t+.0415*n,s=.0557*e+-.204*t+1.057*n,a=a>.0031308?1.055*a**(1/2.4)-.055:12.92*a,o=o>.0031308?1.055*o**(1/2.4)-.055:12.92*o,s=s>.0031308?1.055*s**(1/2.4)-.055:12.92*s,a=Math.min(Math.max(0,a),1),o=Math.min(Math.max(0,o),1),s=Math.min(Math.max(0,s),1),[255*a,255*o,255*s]},o.xyz.lab=function(r){let e=r[0],t=r[1],n=r[2];return e/=95.047,t/=100,n/=108.883,e=e>.008856?e**(1/3):7.787*e+16/116,t=t>.008856?t**(1/3):7.787*t+16/116,n=n>.008856?n**(1/3):7.787*n+16/116,[116*t-16,500*(e-t),200*(t-n)]},o.lab.xyz=function(r){let e,t,n;t=(r[0]+16)/116,e=r[1]/500+t,n=t-r[2]/200;const a=t**3,o=e**3,s=n**3;return t=a>.008856?a:(t-16/116)/7.787,e=o>.008856?o:(e-16/116)/7.787,n=s>.008856?s:(n-16/116)/7.787,e*=95.047,t*=100,n*=108.883,[e,t,n]},o.lab.lch=function(r){const e=r[0],t=r[1],n=r[2];let a;return a=360*Math.atan2(n,t)/2/Math.PI,a<0&&(a+=360),[e,Math.sqrt(t*t+n*n),a]},o.lch.lab=function(r){const e=r[0],t=r[1],n=r[2]/360*2*Math.PI;return[e,t*Math.cos(n),t*Math.sin(n)]},o.rgb.ansi16=function(r,e=null){const[t,n,a]=r;let s=null===e?o.rgb.hsv(r)[2]:e;if(s=Math.round(s/50),0===s)return 30;let c=30+(Math.round(a/255)<<2|Math.round(n/255)<<1|Math.round(t/255));return 2===s&&(c+=60),c},o.hsv.ansi16=function(r){return o.rgb.ansi16(o.hsv.rgb(r),r[2])},o.rgb.ansi256=function(r){const e=r[0],t=r[1],n=r[2];return e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},o.ansi16.rgb=function(r){let e=r%10;if(0===e||7===e)return r>50&&(e+=3.5),e=e/10.5*255,[e,e,e];const t=.5*(1+~~(r>50));return[(1&e)*t*255,(e>>1&1)*t*255,(e>>2&1)*t*255]},o.ansi256.rgb=function(r){if(r>=232){const e=10*(r-232)+8;return[e,e,e]}let e;return r-=16,[Math.floor(r/36)/5*255,Math.floor((e=r%36)/6)/5*255,e%6/5*255]},o.rgb.hex=function(r){const 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},o.hex.rgb=function(r){const e=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];let t=e[0];3===e[0].length&&(t=t.split("").map((r=>r+r)).join(""));const n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n]},o.rgb.hcg=function(r){const e=r[0]/255,t=r[1]/255,n=r[2]/255,a=Math.max(Math.max(e,t),n),o=Math.min(Math.min(e,t),n),s=a-o;let c,i;return c=s<1?o/(1-s):0,i=s<=0?0:a===e?(t-n)/s%6:a===t?2+(n-e)/s:4+(e-t)/s,i/=6,i%=1,[360*i,100*s,100*c]},o.hsl.hcg=function(r){const e=r[1]/100,t=r[2]/100,n=t<.5?2*e*t:2*e*(1-t);let a=0;return n<1&&(a=(t-.5*n)/(1-n)),[r[0],100*n,100*a]},o.hsv.hcg=function(r){const e=r[1]/100,t=r[2]/100,n=e*t;let a=0;return n<1&&(a=(t-n)/(1-n)),[r[0],100*n,100*a]},o.hcg.rgb=function(r){const e=r[0]/360,t=r[1]/100,n=r[2]/100;if(0===t)return[255*n,255*n,255*n];const a=[0,0,0],o=e%1*6,s=o%1,c=1-s;let i=0;switch(Math.floor(o)){case 0:a[0]=1,a[1]=s,a[2]=0;break;case 1:a[0]=c,a[1]=1,a[2]=0;break;case 2:a[0]=0,a[1]=1,a[2]=s;break;case 3:a[0]=0,a[1]=c,a[2]=1;break;case 4:a[0]=s,a[1]=0,a[2]=1;break;default:a[0]=1,a[1]=0,a[2]=c}return i=(1-t)*n,[255*(t*a[0]+i),255*(t*a[1]+i),255*(t*a[2]+i)]},o.hcg.hsv=function(r){const e=r[1]/100,t=e+r[2]/100*(1-e);let n=0;return t>0&&(n=e/t),[r[0],100*n,100*t]},o.hcg.hsl=function(r){const e=r[1]/100,t=r[2]/100*(1-e)+.5*e;let n=0;return t>0&&t<.5?n=e/(2*t):t>=.5&&t<1&&(n=e/(2*(1-t))),[r[0],100*n,100*t]},o.hcg.hwb=function(r){const e=r[1]/100,t=e+r[2]/100*(1-e);return[r[0],100*(t-e),100*(1-t)]},o.hwb.hcg=function(r){const e=r[1]/100,t=1-r[2]/100,n=t-e;let a=0;return n<1&&(a=(t-n)/(1-n)),[r[0],100*n,100*a]},o.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},o.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},o.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},o.gray.hsl=function(r){return[0,0,r[0]]},o.gray.hsv=o.gray.hsl,o.gray.hwb=function(r){return[0,100,r[0]]},o.gray.cmyk=function(r){return[0,0,0,r[0]]},o.gray.lab=function(r){return[r[0],0,0]},o.gray.hex=function(r){const e=255&Math.round(r[0]/100*255),t=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(t.length)+t},o.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}},85:function(r,e,t){const n=t(168),a=t(111),o={};Object.keys(n).forEach((r=>{o[r]={},Object.defineProperty(o[r],"channels",{value:n[r].channels}),Object.defineProperty(o[r],"labels",{value:n[r].labels});const e=a(r);Object.keys(e).forEach((t=>{const n=e[t];o[r][t]=function(r){const e=function(...e){const t=e[0];if(null==t)return t;t.length>1&&(e=t);const n=r(e);if("object"==typeof n)for(let r=n.length,e=0;e<r;e++)n[e]=Math.round(n[e]);return n};return"conversion"in r&&(e.conversion=r.conversion),e}(n),o[r][t].raw=function(r){const e=function(...e){const t=e[0];return null==t?t:(t.length>1&&(e=t),r(e))};return"conversion"in r&&(e.conversion=r.conversion),e}(n)}))})),r.exports=o},111:function(r,e,t){const n=t(168);function a(r,e){return function(t){return e(r(t))}}function o(r,e){const t=[e[r].parent,r];let o=n[e[r].parent][r],s=e[r].parent;for(;e[s].parent;)t.unshift(e[s].parent),o=a(n[e[s].parent][s],o),s=e[s].parent;return o.conversion=t,o}r.exports=function(r){const e=function(r){const e=function(){const r={},e=Object.keys(n);for(let t=e.length,n=0;n<t;n++)r[e[n]]={distance:-1,parent:null};return r}(),t=[r];for(e[r].distance=0;t.length;){const r=t.pop(),a=Object.keys(n[r]);for(let n=a.length,o=0;o<n;o++){const n=a[o],s=e[n];-1===s.distance&&(s.distance=e[r].distance+1,s.parent=r,t.unshift(n))}}return e}(r),t={},a=Object.keys(e);for(let r=a.length,n=0;n<r;n++){const r=a[n];null!==e[r].parent&&(t[r]=o(r,e))}return t}},874: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 t(n){var a=e[n];if(void 0!==a)return a.exports;var o=e[n]={exports:{}};return r[n](o,o.exports,t),o.exports}t.d=function(r,e){for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.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";t.r(n),t.d(n,{ColorJson:function(){return i},CssColorParser:function(){return c}});var r=function(){function r(){}return r.type=function(r,e,t){var n=typeof t;if(n!==r)throw new Error("Expected ".concat(e," to be typeof ").concat(r,", actual typeof was ").concat(n))},r.types=function(r,e,t){var n=typeof t;if(!r.includes(n))throw new Error("Expected ".concat(e," to be typeof ").concat(r.join("|"),", actual typeof was ").concat(n))},r}();function e(r,e){return null==r||isNaN(r)&&"number"==typeof e?e:r}function a(r,e,t){return t>e?t=e:t<r&&(t=r),t}var o=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(t){var n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(t);if(n){var a=e(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(t){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(t);if(n){var a=e(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(e){var t=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(e);return t?[r._parseResStrForRgb(t[1]),r._parseResStrForRgb(t[2]),r._parseResStrForRgb(t[3]),r._parsePercent(t[4])]:null},r.parseHSLA=function(e){var t=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(e);return t?[r._parseResStrForHue(t[1]),r._parsePercent(t[2]),r._parsePercent(t[3]),r._parsePercent(t[4])]:null},r.parseHWB=function(e){var t=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return t?[r._parseResStrForHue(t[1]),r._parsePercent(t[2]),r._parsePercent(t[3]),r._parsePercent(t[4])]:null},r.parseRGBA2=function(e){var t=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return t?[r._parseResStrForRgb(t[1]),r._parseResStrForRgb(t[2]),r._parseResStrForRgb(t[3]),r._parsePercent(t[4])]:null},r.parseHSLA2=function(e){var t=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(e);return t?[r._parseResStrForHue(t[1]),r._parsePercent(t[2]),r._parsePercent(t[3]),r._parsePercent(t[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=t(85),c=function(){function t(r,e,t,n){this.r=255,this.g=255,this.b=255,this.a=1,this.setColor(r,e,t,n)}return t.prototype.setColor=function(r,t,n,o){this.r=a(0,255,e(Number(r),0)),this.g=a(0,255,e(Number(t),0)),this.b=a(0,255,e(Number(n),0)),this.a=a(0,1,e(Number(o),1))},t.parseKeyWord=function(r){var e=o.clearStrSpace(r),n=s.keyword.rgb(e);return n&&t.fromArray(n)},t.parseHEX=function(r){var e=o.clearStrSpace(r),n=o.parse3BitsHEX(e);return n||(n=o.parse6BitsHEX(e)),n&&t.fromArray(n)},t.parseRGBA=function(r){var e=o.clearStrSpace(r),n=o.parseRGBA(e);if(!n){var a=o.trimStr(r);n=o.parseRGBA2(a)}return n&&t.fromArray(n)},t.parseHSLA=function(r){var e=o.clearStrSpace(r),n=o.parseHSLA(e);if(!n){var a=o.trimStr(r);n=o.parseHSLA2(a)}return n&&t.fromHSL(n[0],n[1],n[2],n[3])},t.parseHWB=function(r){var e=o.trimStr(r),n=o.parseHWB(e);return n&&t.fromHWB(n[0],n[1],n[2],n[3])},t.parseCssColorString=function(e){return r.type("string","color",e),t.parseHEX(e)||t.parseRGBA(e)||t.parseKeyWord(e)||t.parseHSLA(e)||t.parseHWB(e)},t.fromHSL=function(r,n,o,c){var i=s.hsl.rgb(a(0,360,r),a(0,100,100*n),a(0,100,100*o));return new t(i[0],i[1],i[2],e(Number(c),1))},t.fromHWB=function(r,n,o,c){var i=s.hwb.rgb(a(0,360,r),a(0,100,100*n),a(0,100,100*o));return new t(i[0],i[1],i[2],e(Number(c),1))},t.fromRandom=function(r,e){if("string"==typeof r&&(r=t.parseCssColorString(r)),"string"==typeof e&&(e=t.parseCssColorString(e)),!r||!e)throw new Error("fail to create object from random");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.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.prototype.toCssColorString=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,")")},t.prototype.toString=function(){return this.toCssColorString()},t.prototype.toNormalize=function(){return{r:parseFloat((this.r/255).toFixed(2)),g:parseFloat((this.g/255).toFixed(2)),b:parseFloat((this.b/255).toFixed(2)),a:parseFloat(this.a.toFixed(2))}},t.prototype.toCssHEXString=function(){var r=this.toJson(),e=r.r.toString(16);e.length<2&&(e="0".concat(e));var t=r.g.toString(16);t.length<2&&(t="0".concat(t));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(e).concat(t).concat(n).concat(a)}return"#".concat(e).concat(t).concat(n)},t.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},t.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))}},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.equals=function(r){return this===r||this.r===r.r&&this.g===r.g&&this.b===r.g&&this.a===r.a},t}(),i=function(){}}(),n}()}));
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
export declare class CssColorParser {
|
|
2
|
-
r: number;
|
|
3
|
-
g: number;
|
|
4
|
-
b: number;
|
|
5
|
-
a: number;
|
|
6
|
-
constructor(red?: number | string, green?: number | string, blue?: number | string, alpha?: number | string);
|
|
7
|
-
/**
|
|
8
|
-
* 设置颜色
|
|
9
|
-
* @param red
|
|
10
|
-
* @param green
|
|
11
|
-
* @param blue
|
|
12
|
-
* @param alpha
|
|
13
|
-
* @example: this.setColor(255,255,255,1)
|
|
14
|
-
*/
|
|
15
|
-
setColor(red?: number | string, green?: number | string, blue?: number | string, alpha?: number | string): void;
|
|
16
|
-
static parseKeyWord(v: string): CssColorParser;
|
|
17
|
-
static parseHEX(v: string): CssColorParser;
|
|
18
|
-
static parseRGBA(v: string): CssColorParser;
|
|
19
|
-
static parseHSLA(v: string): CssColorParser;
|
|
20
|
-
static parseHWB(v: string): CssColorParser;
|
|
21
|
-
/**
|
|
22
|
-
* @description: 将css字符串转换为解析对象
|
|
23
|
-
* @param {string} v
|
|
24
|
-
* @return {CssColorParser}
|
|
25
|
-
* @example: CssColorParser.parseCssColorString('rgba(255,255,255,1)')
|
|
26
|
-
*/
|
|
27
|
-
static parseCssColorString(v: string): CssColorParser;
|
|
28
|
-
/**
|
|
29
|
-
* @description: 将HSL色彩模式转换为解析对象
|
|
30
|
-
* @param {number} hue 色相
|
|
31
|
-
* @param {number} saturation 饱和度
|
|
32
|
-
* @param {number} lightness 亮度
|
|
33
|
-
* @param {number} alpha 不透明度
|
|
34
|
-
* @return {CssColorParser}
|
|
35
|
-
* @example: CssColorParser.fromHSL(0,1,1,1)
|
|
36
|
-
*/
|
|
37
|
-
static fromHSL(h: number, s: number, l: number, a?: number): CssColorParser;
|
|
38
|
-
/**
|
|
39
|
-
* @description: 将HWB色彩模式转换为解析对象
|
|
40
|
-
* @param {number} h 色调
|
|
41
|
-
* @param {number} w 白度
|
|
42
|
-
* @param {number} b 黑度
|
|
43
|
-
* @param {number} a 不透明度
|
|
44
|
-
* @return {CssColorParser}
|
|
45
|
-
* @example: CssColorParser.fromHSL(0,1,1,1)
|
|
46
|
-
*/
|
|
47
|
-
static fromHWB(h: number, w: number, b: number, a?: number): CssColorParser;
|
|
48
|
-
/**
|
|
49
|
-
* @description: 从解析器中产生随机颜色
|
|
50
|
-
* @return {CssColorParser}
|
|
51
|
-
* @author: roman_123
|
|
52
|
-
*/
|
|
53
|
-
static fromRandom(color1: string | CssColorParser, color2: string | CssColorParser): CssColorParser;
|
|
54
|
-
/**
|
|
55
|
-
* @description: 将ColorJson格式的json数据转换为解析对象
|
|
56
|
-
* @param {ColorJson} json
|
|
57
|
-
* @return {CssColorParser}
|
|
58
|
-
* @author: roman_123
|
|
59
|
-
*/
|
|
60
|
-
static fromJson(json: ColorJson): CssColorParser;
|
|
61
|
-
/**
|
|
62
|
-
* @description: 将rgba数组转换为解析对象
|
|
63
|
-
* @param {Array} color
|
|
64
|
-
* @return {CssColorParser}
|
|
65
|
-
* @author: roman_123
|
|
66
|
-
*/
|
|
67
|
-
static fromArray(color: Array<number>): CssColorParser;
|
|
68
|
-
/**
|
|
69
|
-
* @description: 返回rgba格式的css字符串
|
|
70
|
-
* @return {*}
|
|
71
|
-
* @author: roman_123
|
|
72
|
-
*/
|
|
73
|
-
toCssColorString(): string;
|
|
74
|
-
/**
|
|
75
|
-
* @description: 返回字符串
|
|
76
|
-
* @return {*}
|
|
77
|
-
* @author: roman_123
|
|
78
|
-
*/
|
|
79
|
-
toString(): string;
|
|
80
|
-
/**
|
|
81
|
-
* @description: 归一化
|
|
82
|
-
* @return {*}
|
|
83
|
-
* @author: roman_123
|
|
84
|
-
*/
|
|
85
|
-
toNormalize(): ColorJson;
|
|
86
|
-
/**
|
|
87
|
-
* @description: 返回16进制格式的css字符串
|
|
88
|
-
* @return {*}
|
|
89
|
-
* @author: roman_123
|
|
90
|
-
*/
|
|
91
|
-
toCssHEXString(): string;
|
|
92
|
-
/**
|
|
93
|
-
* @description: 返回rgba数组
|
|
94
|
-
* @return {*}
|
|
95
|
-
* @author: roman_123
|
|
96
|
-
*/
|
|
97
|
-
toArray(): number[];
|
|
98
|
-
/**
|
|
99
|
-
* @description: 返回ColorJson
|
|
100
|
-
* @return {*}
|
|
101
|
-
* @author: roman_123
|
|
102
|
-
*/
|
|
103
|
-
toJson(): ColorJson;
|
|
104
|
-
/**
|
|
105
|
-
* @description: 拷贝
|
|
106
|
-
* @return {*}
|
|
107
|
-
* @author: roman_123
|
|
108
|
-
*/
|
|
109
|
-
clone(): CssColorParser;
|
|
110
|
-
/**
|
|
111
|
-
* @description: 比较两个解析对象的数据是否相等
|
|
112
|
-
* @param {*} color
|
|
113
|
-
* @return {*}
|
|
114
|
-
* @author: roman_123
|
|
115
|
-
*/
|
|
116
|
-
equals(color: any): boolean;
|
|
117
|
-
}
|
|
118
|
-
export declare class ColorJson {
|
|
119
|
-
r: number;
|
|
120
|
-
g: number;
|
|
121
|
-
b: number;
|
|
122
|
-
a: number;
|
|
123
|
-
}
|