"use strict";var De=Object.defineProperty;var Be=(s,e,t)=>e in s?De(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var p=(s,e,t)=>(Be(s,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function fe(s){return typeof s=="number"}class Fe extends Error{constructor(e){super(e),this.name="AssertionError"}}function g(s,e){if(!s)throw new Fe(e)}function ee(s,e){g(s!=null,e)}function b(s,e){g(fe(s)&&Number.isFinite(s),e)}function S(s,e){g(fe(s)&&Number.isSafeInteger(s),e)}function H(s,e){S(s,e),g(s>0,e)}function $(s,e,t,n){b(s,n),g(e<=s&&s<=t,n)}class qe{constructor(...e){p(this,"elements");this.elements=[...e]}get isEmpty(){return this.elements.length===0}get size(){return this.elements.length}push(e){this.elements.push(e)}pop(){return this.elements.shift()}peek(){return this.elements[0]}toArray(){return[...this.elements]}}class Oe{constructor(){p(this,"first");p(this,"last");p(this,"size");this.first=void 0,this.last=void 0,this.size=0}get length(){return this.size}getFirst(){return this.first}getLast(){return this.last}addFirst(e){this.last?this.first&&(this.first.prev=e,e.next=this.first):this.last=e,this.first=e,this.size++}remove(e){if(e.next)if(e.prev)e.prev.next=e.next,e.next.prev=e.prev,e.prev=void 0,e.next=void 0;else{const t=e.next;t.prev=void 0,e.next=void 0,this.first=t}else if(e.prev){const t=e.prev;t.next=void 0,e.prev=void 0,this.last=t}else{if(this.first!==e||this.last!==e)return;this.first=void 0,this.last=void 0}this.size--}removeLast(){const e=this.last;return e&&this.remove(e),e}}class Pe{constructor(e){p(this,"elements");this.comparator=e,this.elements=[]}get isEmpty(){return this.elements.length===0}get size(){return this.elements.length}push(e){this.elements.push(e);let t=this.elements.length-1;for(;t>0;){const n=Math.floor((t-1)/2),r=this.elements[n];if(this.comparator(e,r)>=0)break;this.swap(t,n),t=n}}pop(){const e=this.elements[0],t=this.elements.pop();if(!t||this.elements.length===0)return e;this.elements[0]=t;let n=0;const r=this.elements.length;for(;n=this.capacity){const l=this.retrieveFrequencyList(this.minFrequency).removeLast();ee(l,`The last node for frequency(${this.minFrequency}) must be defined`),this.cache.delete(l.value.key)}const r={key:e,value:t,frequency:1};this.minFrequency=r.frequency;const i={value:r,prev:void 0,next:void 0};this.retrieveFrequencyList(r.frequency).addFirst(i),this.cache.set(e,i)}remove(e){const t=this.cache.get(e);return t?(this.retrieveFrequencyList(t.value.frequency).remove(t),this.cache.delete(e),!0):!1}clear(){this.cache.clear(),this.frequencyMap.clear(),this.minFrequency=0}updateFrequency(e){const t=e.value,n=this.retrieveFrequencyList(t.frequency);n.remove(e),t.frequency===this.minFrequency&&n.length===0&&this.minFrequency++,t.frequency++;const r=this.retrieveFrequencyList(t.frequency),i={value:t,prev:void 0,next:void 0};r.addFirst(i)}retrieveFrequencyList(e){let t=this.frequencyMap.get(e);return t||(t=new Oe,this.frequencyMap.set(e,t)),t}}const D=(s,e)=>{const t=B(s,e);return Math.sqrt(t)},B=(s,e)=>{const t=s.reduce((n,r,i)=>{const o=e[i]-r;return n+o*o},0);return b(t,"Either point1 or point2 contains infinite number"),t},ze=-1;class R{constructor(e){p(this,"components");const t=e.findIndex(n=>!Number.isFinite(n));g(t===ze,`The source point contain infinite number at ${t}`),this.components=[...e]}get dimension(){return this.components.length}toString(){return`Vector(${this.components.join(", ")})`}toArray(){return[...this.components]}clone(){return new R(this.components)}setZero(){for(let e=0;e=0,`The index(${e}) is less than 0`),!this.memberships.has(e)&&(this.centroid.scale(this.memberships.size),this.centroid.add(t),this.centroid.scale(1/(this.memberships.size+1)),this.memberships.add(e))}clear(){this.centroid.setZero(),this.memberships.clear()}}class Xe{constructor(e,t,n,r){this.index=e,this.axis=t,this.left=n,this.right=r,g(e>=0,`The index must be non-negative: ${e}`),g(t>=0,`The axis must be non-negative: ${t}`)}get isLeaf(){return!this.left&&!this.right}}class L{constructor(e,t,n){p(this,"points");this.root=e,this.distanceMeasure=n,this.points=Array.from(t)}search(e,t){g(t>=1,`The number of neighbors to be searched(${t}) must be greater than or equal to 1`);const n=new Pe((r,i)=>r.distancei.distance?1:0);return this.searchRecursively(this.root,e,t,n),this.extractNeighbors(n,t).sort((r,i)=>r.distance-i.distance)}searchNearest(e){const t=this.points[0],r={index:0,distance:this.distanceMeasure(e,t)};return this.nearestRecursively(this.root,e,r),r}searchRadius(e,t){g(t>0,`The radius(${t}) must be greater than 0.0`);const n=new Array;return this.rangeRecursively(this.root,e,t,n),n}nearestRecursively(e,t,n){if(!e)return;const r=e.index;if(r===n.index)return;const i=this.points[r],o=this.distanceMeasure(t,i);o=Math.abs(a)&&this.nearestRecursively(e.right,t,n)):(this.nearestRecursively(e.right,t,n),n.distance>=Math.abs(a)&&this.nearestRecursively(e.left,t,n))}searchRecursively(e,t,n,r){if(!e)return;const i=e.index,o=this.points[i],a=this.distanceMeasure(t,o);if(r.push({index:i,distance:a}),e.isLeaf)return;const l=t[e.axis]-o[e.axis],c=r.peek();r.sizeo),r=L.buildNode(e,n,0);return ee(r,"The given points array is empty"),new L(r,e,t)}static buildNode(e,t,n){if(t.length<=0)return;const r=e[0].length,i=n%r,o=Math.floor(t.length/2);t.sort((c,h)=>e[c][i]-e[h][i]);const a=L.buildNode(e,t.slice(0,o),n+1),l=L.buildNode(e,t.slice(o+1),n+1);return new Xe(t[o],i,a,l)}}const Z=-1,ce=-2,K=-3;class V{constructor(e,t,n){this.minPoints=e,this.epsilon=t,this.distanceMeasure=n,g(this.minPoints>=1,`The minimum size of cluster(${this.minPoints}) is not greater than or equal to 1`),g(this.epsilon>=0,`The epsilon(${this.epsilon}) is not greater than 0.0`)}fit(e){g(e.length>0,"The points array is empty");let t=0;const n=new Array(e.length).fill(K),r=new Array,i=L.build(e,this.distanceMeasure);for(let o=0;o=this.minPoints&&r.push(c),t++}return r}expandCluster(e,t,n,r,i){const o=new R(n[0]).setZero(),a=new J(o),l=new qe(...r);for(;!l.isEmpty;){const c=l.pop();if(!c)continue;const h=c.index,u=n[h];if(t[h]>0)continue;if(t[h]===Z){t[h]=e,a.addMember(h,u);continue}t[h]=e,a.addMember(h,u);const f=i.searchRadius(u,this.epsilon);if(!(f.length{if(t.has(c))return!1;const h=r[c];return h?h>o:!1});if(a===le){U.selectRandomly(e,t);return}t.set(a,e[a])}computeNearestDistance(e,t){let n=Number.MAX_VALUE;for(const r of t.values()){const i=this.distanceMeasure(e,r);i0,`The maximum number of iterations must be a positive integer: ${t}`),g(n>=0,`The tolerance must be a positive number: ${n}`)}fit(e){if(g(e.length>0,"The points array is empty"),e.length<=this.k)return e.map((n,r)=>{const i=new J(n);return i.addMember(r,n),i});const t=this.initializationStrategy.initialize(e,this.k).map(n=>new J(n));for(let n=0;n=this.tolerance&&(r=!0)}return r}assignPoints(e,t,n){const r=L.build(t,this.distanceMeasure);for(let i=0;i0,`The number of data points to downsample(${t}) must be greater than 0`),t>=e.length)return[...e];const n=new Map,r=new Array(e.length),i=0,o=e[i];n.set(i,o);for(let a=0;a=0,"No data point can be selected.");const l=e[a];n.set(a,l),r[a]=0;for(let c=0;cr&&(r=o,n=i)}return n}}function I(s,e,t){return b(s,`The value(${s}) must be finite number`),b(e,`The minimum value(${e}) must be finite number`),b(t,`The maximum value(${t}) must be finite number`),Math.max(Math.min(s,t),e)}function N(s,e,t){if(b(s,`The value(${s}) must be finite number`),b(e,`The minimum value(${e}) must be finite number`),b(t,`The maximum value(${t}) must be finite number`),e>=t)throw new RangeError(`The minimum value(${e}) is greater than the maximum value(${t})`);return Math.max(Math.min((s-e)/(t-e),1),0)}function C(s,e,t){if(b(s,`The value(${s}) must be finite number`),b(e,`The minimum value(${e}) must be finite number`),b(t,`The maximum value(${t}) must be finite number`),e>=t)throw new RangeError(`The minimum value(${e}) is greater than the maximum value(${t})`);return s*(t-e)+e}function E(s){return b(s,`The degree(${s}) must be finite number`),s*(Math.PI/180)}function de(s){return b(s,`The radian(${s}) must be finite number`),s*(180/Math.PI)}const Ye=(s,e)=>{const t=s.l-e.l,n=s.a-e.a,r=s.b-e.b;return Math.sqrt(t**2+n**2+r**2)},Ve=1,Ze=.045,Ke=.015,je=1,Qe=1,Je=(s,e)=>{const t=s.l-e.l,n=s.a-e.a,r=s.b-e.b,i=Math.sqrt(s.a**2+s.b**2),o=Math.sqrt(e.a**2+e.b**2),a=i-o,l=Math.sqrt(n**2+r**2-a**2),c=1,h=1+Ze*i,u=1+Ke*i,f=(t/(Ve*c))**2+(a/(je*h))**2+(l/(Qe*u))**2;return Math.sqrt(f)},et=1,tt=1,nt=1,he=25**7;function ue(s,e){if(s===0&&e===0)return 0;const t=de(Math.atan2(s,e));return t>=0?t:t+360}function st(s,e){return Math.abs(s-e)>180?(s+e+360)/2:(s+e)/2}function rt(s,e,t,n){if(s===0||e===0)return 0;const r=n-t;return Math.abs(r)<=180?r:n<=t?r+360:r-360}const ge=(s,e)=>{const t=e.l-s.l,n=(s.l+e.l)/2,r=Math.sqrt(s.a**2+s.b**2),i=Math.sqrt(e.a**2+e.b**2),o=(r+i)/2,a=Math.sqrt(o**7/(o**7+he)),l=s.a+s.a/2*(1-a),c=e.a+e.a/2*(1-a),h=Math.sqrt(l*l+s.b*s.b),u=Math.sqrt(c*c+e.b*e.b),f=(h+u)/2,d=u-h,y=ue(s.b,l),v=ue(e.b,c);let A=rt(r,i,y,v);A=2*Math.sqrt(h*u)*Math.sin(E(A)/2);const _=st(y,v),Re=1-.17*Math.cos(E(_-30))+.24*Math.cos(E(2*_))+.32*Math.cos(E(3*_+6))-.2*Math.cos(E(4*_-63)),$e=1+.015*(n-50)**2/Math.sqrt(20+(n-50)**2),Ce=1+.045*f,Ee=1+.015*f*Re,ie=f**7,Ge=-2*Math.sqrt(ie/(ie+he))*Math.sin(E(60*Math.exp(-1*((_-275)/25)**2))),He=t/(et*$e),oe=d/(tt*Ce),ae=A/(nt*Ee),_e=He**2+oe**2+ae**2+Ge*oe*ae;return Math.sqrt(_e)},it=0,M=255;function w(s){return I(s,it,M)}function ot(s){g(s.startsWith("#"),`The value(${s}) is not a valid hexadecimal color string`);let e=NaN,t=NaN,n=NaN;return s.length===4?(e=Number.parseInt(s[1],16)*17,t=Number.parseInt(s[2],16)*17,n=Number.parseInt(s[3],16)*17):s.length===7&&(e=Number.parseInt(s.slice(1,3),16),t=Number.parseInt(s.slice(3,5),16),n=Number.parseInt(s.slice(5,7),16)),S(e,`The value(${s}) is not a valid hexadecimal color string`),S(t,`The value(${s}) is not a valid hexadecimal color string`),S(n,`The value(${s}) is not a valid hexadecimal color string`),{r:e,g:t,b:n}}function at({r:s,g:e,b:t}){return[s,e,t].reduce((n,r)=>{g(Number.isFinite(r),`The r, g, and b components must be finite numbers: ${s}, ${e}, ${t}`);const i=w(r).toString(16).padStart(2,"0").toUpperCase();return n+i},"#")}const j=360,ct=0,lt=1,ht=0,ut=1;function pe(s){return(s%j+j)%j}function Me(s){return I(s,ct,lt)}function ye(s){return I(s,ht,ut)}function mt(s){S(s.r,`The r(${s.r}) must be an integer`),S(s.g,`The g(${s.g}) must be an integer`),S(s.b,`The b(${s.b}) must be an integer`);const e=w(s.r)/M,t=w(s.g)/M,n=w(s.b)/M,r=Math.max(e,t,n),i=Math.min(e,t,n),o=r-i;let a;o===0?a=0:r===e?a=60*((t-n)/o%6):r===t?a=60*((n-e)/o+2):a=60*((e-t)/o+4);const l=(r+i)/2;let c=0;return o!==0&&(c=o/(1-Math.abs(2*l-1))),{h:pe(a),s:Me(c),l:ye(l)}}function bt({h:s,s:e,l:t}){b(s,`The h(${s}) must be a finite number`),b(e,`The s(${e}) must be a finite number`),b(t,`The l(${t}) must be a finite number`);const n=pe(s),r=Me(e),i=ye(t),o=(1-Math.abs(2*i-1))*r,a=(1-Math.abs(n/60%2-1))*o,l=i-o/2;let[c,h,u]=[0,0,0];return 0<=n&&n<60?(c=o,h=a):60<=n&&n<120?(c=a,h=o):120<=n&&n<180?(h=o,u=a):180<=n&&n<240?(h=a,u=o):240<=n&&n<300?(c=a,u=o):300<=n&&n<360&&(c=o,u=a),{r:w((c+l)*M),g:w((h+l)*M),b:w((u+l)*M)}}const ft=0,dt=.950456,gt=0,pt=1,Mt=0,yt=1.088644;function Te(s){return I(s,ft,dt)}function Se(s){return I(s,gt,pt)}function Ne(s){return I(s,Mt,yt)}const G={x:.95047,y:1,z:1.08883};function F({r:s,g:e,b:t}){S(s,`The r(${s}) must be an integer`),S(e,`The g(${e}) must be an integer`),S(t,`The b(${t}) must be an integer`);const n=h=>h<=.04045?h/12.92:((h+.055)/1.055)**2.4,r=n(s/M),i=n(e/M),o=n(t/M),a=Te(.412391*r+.357584*i+.180481*o),l=Se(.212639*r+.715169*i+.072192*o),c=Ne(.019331*r+.119195*i+.950532*o);return{x:a,y:l,z:c}}function we({x:s,y:e,z:t}){b(s,`The x(${s}) must be a finite number`),b(e,`The y(${e}) must be a finite number`),b(t,`The z(${t}) must be a finite number`);const n=h=>h<=.0031308?12.92*h:1.055*h**(1/2.4)-.055,r=n(3.24097*s-1.537383*e-.498611*t),i=n(-.969244*s+1.875968*e+.041555*t),o=n(.05563*s-.203977*e+1.056972*t),a=w(Math.round(r*M)),l=w(Math.round(i*M)),c=w(Math.round(o*M));return{r:a,g:l,b:c}}const q=0,O=100,P=-128,k=128,z=-128,X=128;function te(s){return I(s,q,O)}function ne(s){return I(s,P,k)}function se(s){return I(s,z,X)}function W({x:s,y:e,z:t}){b(s,`The x(${s}) must be a finite number`),b(e,`The y(${e}) must be a finite number`),b(t,`The z(${t}) must be a finite number`);const n=(6/29)**3,r=841/108,i=4/29,o=d=>d>n?Math.cbrt(d):r*d+i,a=o(s/G.x),l=o(e/G.y),c=o(t/G.z),h=te(116*l-16),u=ne(500*(a-l)),f=se(200*(l-c));return{l:h,a:u,b:f}}function ve({l:s,a:e,b:t}){b(s,`The l(${s}) must be a finite number`),b(e,`The a(${e}) must be a finite number`),b(t,`The b(${t}) must be a finite number`);const n=6/29,r=108/841,i=4/29,o=d=>d>n?d**3:r*(d-i),a=(te(s)+16)/116,l=ne(e)/500,c=se(t)/200,h=Te(G.x*o(a+l)),u=Se(G.y*o(a)),f=Ne(G.z*o(a-c));return{x:h,y:u,z:f}}const Tt=[{name:"AliceBlue",color:{l:97.179,a:-1.35,b:-4.277}},{name:"AntiqueWhite",color:{l:93.731,a:1.835,b:11.514}},{name:"Aqua",color:{l:91.115,a:-48.081,b:-14.143}},{name:"Aquamarine",color:{l:92.035,a:-45.523,b:9.708}},{name:"Azure",color:{l:98.933,a:-4.882,b:-1.702}},{name:"Beige",color:{l:95.949,a:-4.196,b:12.037}},{name:"Bisque",color:{l:92.013,a:4.426,b:19}},{name:"Black",color:{l:0,a:0,b:0}},{name:"BlanchedAlmond",color:{l:93.92,a:2.126,b:17.014}},{name:"Blue",color:{l:32.301,a:79.194,b:-107.869}},{name:"BlueViolet",color:{l:42.189,a:69.849,b:-74.776}},{name:"Brown",color:{l:37.524,a:49.687,b:30.537}},{name:"BurlyWood",color:{l:77.018,a:7.044,b:30.01}},{name:"CadetBlue",color:{l:61.154,a:-19.678,b:-7.43}},{name:"Chartreuse",color:{l:89.873,a:-68.07,b:85.78}},{name:"Chocolate",color:{l:55.988,a:37.046,b:56.737}},{name:"Coral",color:{l:67.293,a:45.348,b:47.485}},{name:"CornflowerBlue",color:{l:61.927,a:9.339,b:-49.31}},{name:"Cornsilk",color:{l:97.455,a:-2.222,b:14.281}},{name:"Crimson",color:{l:47.033,a:70.918,b:33.591}},{name:"Cyan",color:{l:91.115,a:-48.081,b:-14.143}},{name:"DarkBlue",color:{l:14.756,a:50.428,b:-68.687}},{name:"DarkCyan",color:{l:52.206,a:-30.616,b:-9.006}},{name:"DarkGoldenRod",color:{l:59.22,a:9.858,b:62.728}},{name:"DarkGray",color:{l:69.238,a:-.002,b:-.01}},{name:"DarkGreen",color:{l:36.203,a:-43.37,b:41.859}},{name:"DarkGrey",color:{l:69.238,a:-.002,b:-.01}},{name:"DarkKhaki",color:{l:73.382,a:-8.793,b:39.285}},{name:"DarkMagenta",color:{l:32.599,a:62.552,b:-38.742}},{name:"DarkOliveGreen",color:{l:42.234,a:-18.831,b:30.595}},{name:"DarkOrange",color:{l:69.483,a:36.818,b:75.484}},{name:"DarkOrchid",color:{l:43.38,a:65.156,b:-60.11}},{name:"DarkRed",color:{l:28.087,a:50.997,b:41.288}},{name:"DarkSalmon",color:{l:69.855,a:28.168,b:27.702}},{name:"DarkSeaGreen",color:{l:72.087,a:-23.821,b:18.03}},{name:"DarkSlateBlue",color:{l:30.829,a:26.054,b:-42.091}},{name:"DarkSlateGray",color:{l:31.256,a:-11.719,b:-3.729}},{name:"DarkSlateGrey",color:{l:31.256,a:-11.719,b:-3.729}},{name:"DarkTurquoise",color:{l:75.292,a:-40.038,b:-13.523}},{name:"DarkViolet",color:{l:39.58,a:76.325,b:-70.379}},{name:"DeepPink",color:{l:55.958,a:84.536,b:-5.714}},{name:"DeepSkyBlue",color:{l:72.548,a:-17.65,b:-42.553}},{name:"DimGray",color:{l:54.365,a:-.002,b:-.01}},{name:"DimGrey",color:{l:54.365,a:-.002,b:-.01}},{name:"DodgerBlue",color:{l:59.38,a:9.967,b:-63.399}},{name:"FireBrick",color:{l:39.115,a:55.913,b:37.643}},{name:"FloralWhite",color:{l:98.402,a:-.04,b:5.363}},{name:"ForestGreen",color:{l:50.594,a:-49.586,b:45.015}},{name:"Fuchsia",color:{l:60.323,a:98.236,b:-60.842}},{name:"Gainsboro",color:{l:87.761,a:-.002,b:-.012}},{name:"GhostWhite",color:{l:97.757,a:1.245,b:-3.359}},{name:"Gold",color:{l:86.929,a:-1.932,b:87.13}},{name:"GoldenRod",color:{l:70.817,a:8.517,b:68.759}},{name:"Gray",color:{l:53.585,a:-.001,b:-.008}},{name:"Green",color:{l:46.228,a:-51.699,b:49.897}},{name:"GreenYellow",color:{l:91.957,a:-52.486,b:81.863}},{name:"Grey",color:{l:53.585,a:-.001,b:-.008}},{name:"HoneyDew",color:{l:98.566,a:-7.567,b:5.462}},{name:"HotPink",color:{l:65.484,a:64.235,b:-10.66}},{name:"IndianRed",color:{l:53.393,a:44.823,b:22.108}},{name:"Indigo",color:{l:20.47,a:51.688,b:-53.321}},{name:"Ivory",color:{l:99.64,a:-2.555,b:7.149}},{name:"Khaki",color:{l:90.328,a:-9.016,b:44.971}},{name:"Lavender",color:{l:91.828,a:3.707,b:-9.675}},{name:"LavenderBlush",color:{l:96.069,a:5.885,b:-.608}},{name:"LawnGreen",color:{l:88.877,a:-67.86,b:84.953}},{name:"LemonChiffon",color:{l:97.648,a:-5.431,b:22.222}},{name:"LightBlue",color:{l:83.814,a:-10.891,b:-11.489}},{name:"LightCoral",color:{l:66.155,a:42.805,b:19.546}},{name:"LightCyan",color:{l:97.868,a:-9.945,b:-3.389}},{name:"LightGoldenRodYellow",color:{l:97.369,a:-6.485,b:19.225}},{name:"LightGray",color:{l:84.556,a:-.002,b:-.012}},{name:"LightGreen",color:{l:86.549,a:-46.33,b:36.942}},{name:"LightGrey",color:{l:84.556,a:-.002,b:-.012}},{name:"LightPink",color:{l:81.054,a:27.958,b:5.023}},{name:"LightSalmon",color:{l:74.705,a:31.471,b:34.539}},{name:"LightSeaGreen",color:{l:65.786,a:-37.51,b:-6.34}},{name:"LightSkyBlue",color:{l:79.724,a:-10.827,b:-28.514}},{name:"LightSlateGray",color:{l:55.917,a:-2.247,b:-11.117}},{name:"LightSlateGrey",color:{l:55.917,a:-2.247,b:-11.117}},{name:"LightSteelBlue",color:{l:78.452,a:-1.281,b:-15.223}},{name:"LightYellow",color:{l:99.285,a:-5.111,b:14.825}},{name:"Lime",color:{l:87.736,a:-86.184,b:83.18}},{name:"LimeGreen",color:{l:72.607,a:-67.126,b:61.436}},{name:"Linen",color:{l:95.311,a:1.674,b:6.009}},{name:"Magenta",color:{l:60.323,a:98.236,b:-60.842}},{name:"Maroon",color:{l:25.533,a:48.043,b:38.054}},{name:"MediumAquaMarine",color:{l:75.692,a:-38.334,b:8.299}},{name:"MediumBlue",color:{l:24.975,a:67.182,b:-91.508}},{name:"MediumOrchid",color:{l:53.643,a:59.061,b:-47.416}},{name:"MediumPurple",color:{l:54.975,a:36.8,b:-50.102}},{name:"MediumSeaGreen",color:{l:65.272,a:-48.217,b:24.284}},{name:"MediumSlateBlue",color:{l:52.157,a:41.073,b:-65.408}},{name:"MediumSpringGreen",color:{l:87.34,a:-70.684,b:32.456}},{name:"MediumTurquoise",color:{l:76.882,a:-37.356,b:-8.365}},{name:"MediumVioletRed",color:{l:44.764,a:70.991,b:-15.182}},{name:"MidnightBlue",color:{l:15.859,a:31.718,b:-49.581}},{name:"MintCream",color:{l:99.156,a:-4.165,b:1.233}},{name:"MistyRose",color:{l:92.656,a:8.744,b:4.823}},{name:"Moccasin",color:{l:91.723,a:2.434,b:26.349}},{name:"NavajoWhite",color:{l:90.101,a:4.505,b:28.261}},{name:"Navy",color:{l:12.974,a:47.506,b:-64.707}},{name:"OldLace",color:{l:96.78,a:.168,b:8.153}},{name:"Olive",color:{l:51.869,a:-12.935,b:56.674}},{name:"OliveDrab",color:{l:54.65,a:-28.226,b:49.689}},{name:"Orange",color:{l:74.934,a:23.925,b:78.947}},{name:"OrangeRed",color:{l:57.579,a:67.777,b:68.955}},{name:"Orchid",color:{l:62.802,a:55.282,b:-34.419}},{name:"PaleGoldenRod",color:{l:91.141,a:-7.354,b:30.961}},{name:"PaleGreen",color:{l:90.75,a:-48.299,b:38.52}},{name:"PaleTurquoise",color:{l:90.061,a:-19.638,b:-6.412}},{name:"PaleVioletRed",color:{l:60.567,a:45.515,b:.391}},{name:"PapayaWhip",color:{l:95.076,a:1.267,b:14.513}},{name:"PeachPuff",color:{l:89.349,a:8.08,b:21.011}},{name:"Peru",color:{l:61.753,a:21.389,b:47.913}},{name:"Pink",color:{l:83.586,a:24.139,b:3.313}},{name:"Plum",color:{l:73.373,a:32.529,b:-21.999}},{name:"PowderBlue",color:{l:86.133,a:-14.092,b:-8.02}},{name:"Purple",color:{l:29.784,a:58.929,b:-36.498}},{name:"RebeccaPurple",color:{l:32.903,a:42.885,b:-47.158}},{name:"Red",color:{l:53.237,a:80.088,b:67.199}},{name:"RosyBrown",color:{l:63.607,a:17.009,b:6.6}},{name:"RoyalBlue",color:{l:47.832,a:26.27,b:-65.274}},{name:"SaddleBrown",color:{l:37.468,a:26.438,b:40.981}},{name:"Salmon",color:{l:67.262,a:45.22,b:29.084}},{name:"SandyBrown",color:{l:73.953,a:23.02,b:46.784}},{name:"SeaGreen",color:{l:51.534,a:-39.715,b:20.047}},{name:"SeaShell",color:{l:97.121,a:2.159,b:4.541}},{name:"Sienna",color:{l:43.798,a:29.317,b:35.633}},{name:"Silver",color:{l:77.704,a:-.002,b:-.011}},{name:"SkyBlue",color:{l:79.208,a:-14.836,b:-21.288}},{name:"SlateBlue",color:{l:45.337,a:36.044,b:-57.783}},{name:"SlateGray",color:{l:52.836,a:-2.143,b:-10.58}},{name:"SlateGrey",color:{l:52.836,a:-2.143,b:-10.58}},{name:"Snow",color:{l:98.644,a:1.654,b:.574}},{name:"SpringGreen",color:{l:88.471,a:-76.901,b:47.022}},{name:"SteelBlue",color:{l:52.467,a:-4.073,b:-32.201}},{name:"Tan",color:{l:74.975,a:5.016,b:24.419}},{name:"Teal",color:{l:48.255,a:-28.842,b:-8.484}},{name:"Thistle",color:{l:80.078,a:13.216,b:-9.242}},{name:"Tomato",color:{l:62.204,a:57.845,b:46.412}},{name:"Turquoise",color:{l:81.266,a:-44.078,b:-4.038}},{name:"Violet",color:{l:69.695,a:56.356,b:-36.825}},{name:"Wheat",color:{l:89.351,a:1.506,b:23.997}},{name:"White",color:{l:100,a:-.002,b:.011}},{name:"WhiteSmoke",color:{l:96.537,a:-.002,b:-.014}},{name:"Yellow",color:{l:97.139,a:-21.562,b:94.477}},{name:"YellowGreen",color:{l:76.535,a:-37.993,b:66.583}}];class re{constructor(e,t){p(this,"neighborSearch");this.colors=e,this.cache=t;const n=e.map(r=>{const i=r.color;return[i.l,i.a,i.b]});this.neighborSearch=L.build(n)}find(e){const t=re.createCacheKey(e),n=this.cache.get(t);if(n)return n.name;const r=[e.l,e.a,e.b],i=this.neighborSearch.searchNearest(r),o=this.colors[i.index];return this.cache.put(t,o),o.name}static createCacheKey(e){const t=ve(e),n=we(t);return n.r<<16|n.g<<8|n.b}}const St=64;let Q=null;function Nt(){return Q||(Q=new re(Tt,new ke(St))),Q}const T=class T{constructor(e,t,n){this.l=e,this.a=t,this.b=n,b(e,`The l(${e}) must be a finite number`),b(t,`The a(${t}) must be a finite number`),b(n,`The b(${n}) must be a finite number`),this.l=te(e),this.a=ne(t),this.b=se(n)}clone(){return new T(this.l,this.a,this.b)}isLight(){return this.l>50}isDark(){return!this.isLight()}lightness(){return this.l}chroma(){return Math.sqrt(this.a**2+this.b**2)}hue(){return de(Math.atan2(this.b,this.a))}differenceTo(e,t=ge){return t({l:this.l,a:this.a,b:this.b},{l:e.l,a:e.a,b:e.b})}toString(){const e=this.toRGB();return at(e)}toRGB(){const e=ve({l:this.l,a:this.a,b:this.b});return we(e)}toHSL(){const e=this.toRGB();return mt(e)}toLAB(){return{l:this.l,a:this.a,b:this.b}}static fromRGB(e){const t=F(e),n=W(t);return new T(n.l,n.a,n.b)}static fromHSL(e){const t=bt(e),n=F(t),r=W(n);return new T(r.l,r.a,r.b)}static fromLAB(e){return new T(e.l,e.a,e.b)}static fromString(e){g(e.startsWith("#"),`The value(${e}) is not a valid hexadecimal color string`);const t=ot(e),n=F(t),r=W(n);return new T(r.l,r.a,r.b)}};p(T,"MIN_LIGHTNESS",0),p(T,"MAX_LIGHTNESS",100),p(T,"MIN_CHROMA",0),p(T,"MAX_CHROMA",180);let m=T;function Le(s=1){return $(s,0,1,`The threshold(${s}) must be in [0.0, 1.0]`),e=>e.a/255>=s}const wt=.25,vt=.85;function Lt(s=wt,e=vt){if($(s,0,1,`The minThreshold(${s}) must be in [0.0, 1.0]`),$(e,0,1,`The maxThreshold(${e}) must be in [0.0, 1.0]`),s>e)throw new RangeError(`The minThreshold(${s}) must be less than or equal to maxThreshold(${e})`);return t=>{const n=[t.r/M,t.g/M,t.b/M],r=n[0]<=.03928?n[0]/12.92:((n[0]+.055)/1.055)**2.4,i=n[1]<=.03928?n[1]/12.92:((n[1]+.055)/1.055)**2.4,o=n[2]<=.03928?n[2]/12.92:((n[2]+.055)/1.055)**2.4,a=.2126*r+.7152*i+.0722*o;return a>=s&&a<=e}}function It(...s){return e=>s.every(t=>t(e))}const At=2.5;class Y{constructor(e,t){p(this,"filter");this.algorithm=e,this.filter=It(...t)}extract(e,t){const{data:n,width:r,height:i}=e;if(n.length===0||r===0||i===0)return[];const o=this.convertToPixels(e,t);if(o.length===0)return[];const a=this.algorithm.fit(o);if(a.length===0)return[];const l=this.convertToColors(a);return new V(1,At,D).fit(l).reduce((u,f)=>{const d=Y.createSwatch(f,a,r,i);return d.population!==0&&u.push(d),u},[])}convertToPixels(e,t){const{data:n,width:r,height:i}=e,o=Math.max(1,Math.floor(1/t)),a=[],l=Math.floor(n.length/(r*i));for(let c=0;c{if(n.size===0)return t;const r=n.getCentroid(),i=[C(r[0],q,O),C(r[1],P,k),C(r[2],z,X)];return t.push(i),t},[])}static createSwatch(e,t,n,r){const i={l:0,a:0,b:0,x:0,y:0,size:0,population:0};for(const c of e.getMemberships().values()){const h=t[c];if(h.size===0)continue;const u=h.size/(h.size+i.size),[f,d,y,v,A]=h.getCentroid();i.l+=(f-i.l)*u,i.a+=(d-i.a)*u,i.b+=(y-i.b)*u,u>=.5&&(i.x=v,i.y=A,i.size=h.size),i.population+=h.size}const o=m.fromLAB({l:C(i.l,q,O),a:C(i.a,P,k),b:C(i.b,z,X)}),a={x:Math.floor(i.x*n),y:Math.floor(i.y*r)},l=i.population;return{color:o,position:a,population:l}}}function Ie(){return typeof window<"u"}function Ae(){return typeof self<"u"&&typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function xt(s){return Ie()&&!Ae()&&s instanceof HTMLCanvasElement}function Rt(s){return Ie()&&!Ae()&&s instanceof HTMLImageElement}function $t(s){return"data"in s&&"width"in s&&"height"in s}function Ct(s){if(xt(s))return Et(s);if(Rt(s))return Gt(s);if($t(s))return s;throw new TypeError("The source of the image is not supported")}function xe(s){const e=s.getContext("2d");return ee(e,"The 2D context might not supported in this environment"),e}function Et(s){return xe(s).getImageData(0,0,s.width,s.height)}function Gt(s){if(!s.complete)throw new Error(`The image element is not loaded: ${s.src}`);const e=document.createElement("canvas");e.width=s.width,e.height=s.height;const t=xe(e);return t.drawImage(s,0,0),t.getImageData(0,0,e.width,e.height)}const Ht=25,_t=85,Dt=.25,Bt=.25,Ft=.5;class qt{constructor(e){this.maxPopulation=e,H(e,`The maximum population must be a positive integer: ${e}`)}filter(e){const t=e.color.lightness();return t>=Ht&&t<=_t}score(e){const t=N(e.color.chroma(),m.MIN_CHROMA,m.MAX_CHROMA),n=N(e.color.lightness(),m.MIN_LIGHTNESS,m.MAX_LIGHTNESS),r=N(e.population,0,this.maxPopulation);return Dt*t+Bt*n+Ft*r}}const Ot=50;class Pt{constructor(e=Ot){this.maxLightness=e,$(e,m.MIN_LIGHTNESS,m.MAX_LIGHTNESS,`The maximum lightness must be in the range [${m.MIN_LIGHTNESS}, ${m.MAX_LIGHTNESS}]: ${e}`)}filter(e){return e.color.lightness()<=this.maxLightness}score(e){const t=e.color.lightness();return 1-N(t,m.MIN_LIGHTNESS,m.MAX_LIGHTNESS)}}const kt=50;class zt{constructor(e=kt){this.minLightness=e,$(e,m.MIN_LIGHTNESS,m.MAX_LIGHTNESS,`The minimum lightness must be in the range [${m.MIN_LIGHTNESS}, ${m.MAX_LIGHTNESS}]: ${e}`)}filter(e){return e.color.lightness()>=this.minLightness}score(e){const t=e.color.lightness();return N(t,m.MIN_LIGHTNESS,m.MAX_LIGHTNESS)}}const Xt=80;class Wt{constructor(e=Xt){this.maxChroma=e,$(e,m.MIN_CHROMA,m.MAX_CHROMA,`The maximum chroma must be in the range [${m.MIN_CHROMA}, ${m.MAX_CHROMA}]: ${e}`)}filter(e){return e.color.chroma()<=this.maxChroma}score(e){const t=e.color.chroma();return 1-N(t,m.MIN_CHROMA,m.MAX_CHROMA)}}const Ut=60;class Yt{constructor(e=Ut){this.minChroma=e,$(e,m.MIN_CHROMA,m.MAX_CHROMA,`The minimum chroma must be in the range [${m.MIN_CHROMA}, ${m.MAX_CHROMA}]: ${e}`)}filter(e){return e.color.chroma()>=this.minChroma}score(e){const t=e.color.chroma();return N(t,m.MIN_CHROMA,m.MAX_CHROMA)}}const Vt={basic:(s,e)=>s.visitBasic(e),vivid:(s,e)=>s.visitVivid(e),muted:(s,e)=>s.visitMuted(e),light:(s,e)=>s.visitLight(e),dark:(s,e)=>s.visitDark(e)};function Zt(s,e,t){return Vt[s](e,t)}const Kt=20,jt=0,Qt=1,Jt=.5,me=0,be=1,en={algorithm:"dbscan",samplingRate:1,maxSwatches:256,filters:[Le()]};class x{constructor(e){p(this,"swatches");p(this,"samplingStrategy");this.swatches=Array.from(e),this.samplingStrategy=new Ue(D)}size(){return this.swatches.length}isEmpty(){return this.swatches.length===0}findSwatches(e,t="basic"){if(H(e,`The number of swatches to find must be a positive integer: ${e}`),e>=this.swatches.length)return this.swatches.map(c=>({name:x.findColorName(c.color),...c}));const n=this.createThemeStrategy(t),r=this.swatches.filter(c=>n.filter(c));if(r.length===0)return[];const i=r.map(c=>{const{l:h,a:u,b:f}=c.color.toLAB();return[h,u,f]}),o=L.build(i,D),a=new Array(i.length).fill(Qt);return this.samplingStrategy.sample(i,e).map(c=>{const h=x.findOptimalSwatch(r,c,o,a,n);return{name:x.findColorName(h.color),...h}})}createThemeStrategy(e){return Zt(e,{visitBasic(t){return new qt(t.population)},visitVivid(t){return new Yt},visitMuted(t){return new Wt},visitLight(t){return new zt},visitDark(t){return new Pt}},this.swatches[0])}static findOptimalSwatch(e,t,n,r,i){const a=n.searchRadius(t,Kt).reduce((l,c)=>{const h=e[l.index],u=e[c.index],f=r[l.index],d=r[c.index];r[c.index]=d*Jt;const y=i.score(h)*f,v=i.score(u)*d;return y>v?l:c});return r[a.index]=jt,e[a.index]}static extract(e,t={}){const{algorithm:n,samplingRate:r,maxSwatches:i,filters:o}={...en,...t};g(Number.isFinite(r)&&r>me&&r<=be,`The sampling rate must be in the range of (${me}, ${be}]: ${r}`),H(i,`The maximum number of swatches must be a positive integer: ${i}`);const a=x.createExtractor(n,o),l=Ct(e),c=a.extract(l,r);return c.sort((h,u)=>u.population-h.population),new x(c.slice(0,i))}static createExtractor(e,t){if(e==="kmeans"){const r=new U(B),i=new We(32,10,1e-4,B,r);return new Y(i,[...t])}const n=new V(16,.0016,B);return new Y(n,[...t])}static findColorName(e){const t=e.toLAB();return Nt().find(t)}}exports.Color=m;exports.Palette=x;exports.cie76=Ye;exports.cie94=Je;exports.ciede2000=ge;exports.luminanceFilter=Lt;exports.opacityFilter=Le; //# sourceMappingURL=index.cjs.map