mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
3 lines
38 KiB
JavaScript
3 lines
38 KiB
JavaScript
|
|
function e(e,t){let r=e.length;Array.isArray(e[0])||(e=[e]),Array.isArray(t[0])||(t=t.map((e=>[e])));let a=t[0].length,o=t[0].map(((e,r)=>t.map((e=>e[r])))),n=e.map((e=>o.map((t=>{let r=0;if(!Array.isArray(e)){for(let a of t)r+=e*a;return r}for(let a=0;a<e.length;a++)r+=e[a]*(t[a]||0);return r}))));return 1===r&&(n=n[0]),1===a?n.map((e=>e[0])):n}function t(e){return"string"===r(e)}function r(e){return(Object.prototype.toString.call(e).match(/^\[object\s+(.*?)\]$/)[1]||"").toLowerCase()}function a(e,t){e=+e,t=+t;let r=(Math.floor(e)+"").length;if(t>r)return+e.toFixed(t-r);{let a=10**(r-t);return Math.round(e/a)*a}}function o(e){if(!e)return;e=e.trim();const t=/^-?[\d.]+$/;let r=e.match(/^([a-z]+)\((.+?)\)$/i);if(r){let e=[];return r[2].replace(/\/?\s*([-\w.]+(?:%|deg)?)/g,((r,a)=>{/%$/.test(a)?(a=new Number(a.slice(0,-1)/100)).type="<percentage>":/deg$/.test(a)?((a=new Number(+a.slice(0,-3))).type="<angle>",a.unit="deg"):t.test(a)&&((a=new Number(a)).type="<number>"),r.startsWith("/")&&((a=a instanceof Number?a:new Number(a)).alpha=!0),e.push(a)})),{name:r[1].toLowerCase(),rawName:r[1],rawArgs:r[2],args:e}}}function n(e){return e[e.length-1]}function s(e,t,r){return isNaN(e)?t:isNaN(t)?e:e+(t-e)*r}function i(e,t,r){return(r-e)/(t-e)}function l(e,t,r){return s(t[0],t[1],i(e[0],e[1],r))}function c(e){return e.map((e=>e.split("|").map((e=>{let t=(e=e.trim()).match(/^(<[a-z]+>)\[(-?[.\d]+),\s*(-?[.\d]+)\]?$/);if(t){let e=new String(t[1]);return e.range=[+t[2],+t[3]],e}return e}))))}var u=Object.freeze({__proto__:null,isString:t,type:r,toPrecision:a,parseFunction:o,last:n,interpolate:s,interpolateInv:i,mapRange:l,parseCoordGrammar:c,multiplyMatrices:e});const h=new class{add(e,t,r){if("string"==typeof arguments[0])(Array.isArray(e)?e:[e]).forEach((function(e){this[e]=this[e]||[],t&&this[e][r?"unshift":"push"](t)}),this);else for(var e in arguments[0])this.add(e,arguments[0][e],arguments[1])}run(e,t){this[e]=this[e]||[],this[e].forEach((function(e){e.call(t&&t.context?t.context:t,t)}))}};var d={gamut_mapping:"lch.c",precision:5,deltaE:"76",css_space:"srgb"};const f={D50:[.3457/.3585,1,.2958/.3585],D65:[.3127/.329,1,.3583/.329]};function m(e){return Array.isArray(e)?e:f[e]}function p(t,r,a,o={}){if(t=m(t),r=m(r),!t||!r)throw new TypeError(`Missing white point to convert ${t?"":"from"}${t||r?"":"/"}${r?"":"to"}`);if(t===r)return a;let n={W1:t,W2:r,XYZ:a,options:o};if(h.run("chromatic-adaptation-start",n),n.M||(n.W1===f.D65&&n.W2===f.D50?n.M=[[1.0479298208405488,.022946793341019088,-.05019222954313557],[.029627815688159344,.990434484573249,-.01707382502938514],[-.009243058152591178,.015055144896577895,.7518742899580008]]:n.W1===f.D50&&n.W2===f.D65&&(n.M=[[.9554734527042182,-.023098536874261423,.0632593086610217],[-.028369706963208136,1.0099954580058226,.021041398966943008],[.012314001688319899,-.020507696433477912,1.3303659366080753]])),h.run("chromatic-adaptation-end",n),n.M)return e(n.M,n.XYZ);throw new TypeError("Only Bradford CAT with white points D50 and D65 supported for now.")}class g{constructor(e){this.id=e.id,this.name=e.name,this.base=e.base?g.get(e.base):null,this.base&&(this.fromBase=e.fromBase,this.toBase=e.toBase);let t=e.coords??this.base.coords;this.coords=t;let r=e.white??this.base.white??"D65";this.white=m(r),this.formats=e.formats??{};for(let e in this.formats){let t=this.formats[e];t.type||="function",t.name||=e}e.cssId&&!this.formats.functions?.color?(this.formats.color={id:e.cssId},Object.defineProperty(this,"cssId",{value:e.cssId})):this.formats?.color&&!this.formats?.color.id&&(this.formats.color.id=this.id),this.referred=e.referred,this.#e=this.#t().reverse(),h.run("colorspace-init-end",this)}inGamut(e,{epsilon:t=75e-6}={}){if(this.isPolar)return e=this.toBase(e),this.base.inGamut(e,{epsilon:t});let r=Object.values(this.coords);return e.every(((e,a)=>{let o=r[a];if("angle"!==o.type&&o.range){if(Number.isNaN(e))return!0;let[r,a]=o.range;return(void 0===r||e>=r-t)&&(void 0===a||e<=a+t)}return!0}))}get cssId(){return this.formats.functions?.color?.id||this.id}get isPolar(){for(let e in this.coords)if("angle
|
||
|
|
//# sourceMappingURL=color.min.js.map
|