Module 325335

2,487 characters · in no known chunk
Dependencies
Required by (3)
Lazily required by (0)none
Requires (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";function r(e,t,n){if(/%$/.test(t))return 3===n?parseFloat(t)/100:255*parseFloat(t)/100;if("h"===e[n]){if(/turn$/.test(t))return 360*parseFloat(t);if(/rad$/.test(t))return 57.3*parseFloat(t)}return parseFloat(t)}function i(e){let t,{hue:n,saturation:r,lightness:i,alpha:s}=e,a=(1-Math.abs(2*(i/=255)-1))*(r/=255),o=a*(1-Math.abs(n/60%2-1)),l=i-a/2,u=(t=n<60?[a,o,0]:n<120?[o,a,0]:n<180?[0,a,o]:n<240?[0,o,a]:n<300?[o,0,a]:[a,0,o]).map(e=>Math.round((e+l)*255));return{red:u[0],green:u[1],blue:u[2],alpha:s}}function s(e){let{red:t,green:n,blue:r,alpha:i}=e,s=t/255,a=n/255,o=r/255,l=Math.max(s,a,o),u=Math.min(s,a,o),c=l-u,d=(l+u)/2,_=c>0?c/(1-Math.abs(2*d-1)):0;if(0===c)return{hue:0,saturation:_,lightness:d,alpha:i};let f=0;switch(l){case s:f=(a-o)/c%6;break;case a:f=(o-s)/c+2;break;case o:f=(a-o)/c+4}return{hue:60*f,saturation:_,lightness:d,alpha:i}}n.d(t,{A:()=>l});let a=/^#[0-9a-f]{3,8}$/i,o=/^((?:rgb|hsl)a?)\s*\(([^)]*)\)/i;class l{red;green;blue;alpha;constructor(e,t,n,r){this.red=e,this.green=t,this.blue=n,this.alpha=r}toHexString(){var e=Math.round(this.red).toString(16),t=Math.round(this.green).toString(16),n=Math.round(this.blue).toString(16);return"#"+(this.red>15.5?e:"0"+e)+(this.green>15.5?t:"0"+t)+(this.blue>15.5?n:"0"+n)}static parseString(e){return null!=e.match(o)?this.parseColorFnString(e):null!=e.match(a)?this.parseHexString(e):void 0}static parseRgbString(e){return"transparent"===e?new l(0,0,0,0):this.parseColorFnString(e)}static parseHexString(e){if(!(null==e.match(a)||[6,8].includes(e.length))){if((e=e.replace("#","")).length<6){let[t,n,r,i]=e;e=t+t+n+n+r+r,null!=i&&(e+=i+i)}var t=e.match(/.{1,2}/g);if(null!=t)return new l(parseInt(t[0],16),parseInt(t[1],16),parseInt(t[2],16),null!=t[3]?parseInt(t[3],16)/255:1)}}static parseColorFnString(e){let[,t,n]=e.match(o)??[];if(null==t||null==n)return;let s=n.split(/\s*[,/\s]\s*/).map(e=>e.replace(",","").trim()).filter(e=>""!==e).map((e,n)=>r(t,e,n));if("hsl"===t.substr(0,3)){let e=i({hue:s[0],saturation:s[1],lightness:s[2],alpha:s[3]});return new l(e.red,e.green,e.blue,e.alpha)}return new l(s[0],s[1],s[2],"number"==typeof s[3]?s[3]:1)}toHSL(){return s({red:this.red,green:this.green,blue:this.blue,alpha:this.alpha})}getRelativeLuminance(){var e=this.red/255,t=this.green/255,n=this.blue/255;return .2126*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.7152*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))}}}