UNPKG

@publidata/utils-colors

Version:
1 lines 7.51 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["Utils-index"]=e():(t.Publidata=t.Publidata||{},t.Publidata["Utils-index"]=e())}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"isCssVariable",(function(){return n})),r.d(e,"getSearchableCssVariable",(function(){return a})),r.d(e,"getCssVariableValue",(function(){return c})),r.d(e,"hexaToRgb",(function(){return o})),r.d(e,"hexaToRgba",(function(){return i})),r.d(e,"hexify",(function(){return u})),r.d(e,"getShade",(function(){return l})),r.d(e,"getCSSColor",(function(){return f})),r.d(e,"getTints",(function(){return h})),r.d(e,"getShades",(function(){return g})),r.d(e,"generateColors",(function(){return y})),r.d(e,"generateClusterProperties",(function(){return b})),r.d(e,"getClusterRadius",(function(){return m})),r.d(e,"getClusterFontSize",(function(){return x})),r.d(e,"getBorderTrunk",(function(){return S})),r.d(e,"generatePieChartIcons",(function(){return P}));var n=t=>!!t&&(!(!t.startsWith("var(")||!t.endsWith(")"))||!!t.startsWith("--")),a=t=>t?t.startsWith("var(")&&t.endsWith(")")?t.slice(4,-1):t:"",c=t=>{if("undefined"!=typeof window){if(!t)return null;if(!n(t))return t;var e=window.getComputedStyle(document.documentElement).getPropertyValue(a(t)).trim();return e.length?e:null}},o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"string";if(!t)return null;var r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t),n=r?r.slice(1,4).map(t=>parseInt(t,16)):null;return n&&"string"===e?n.join(", "):n},i=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!t)return null;var r=o(t);if(!r)return null;var n=e>1?1:e<0?0:e;return"".concat(r,", ").concat(n)},u=t=>{if(!t||"string"!=typeof t)return null;var e=t.replace(/rgba?/,"").replace(/[(|)]/,"").replace(/[\s+]/g,"").split(","),r=parseFloat(e[3]||1),n=e.slice(0,3).map(t=>Math.floor(r*parseInt(t)+255*(1-r)));return n.forEach((t,e)=>n[e]=("0"+t.toString(16)).slice(-2)),"#".concat(n.join(""))},l=(t,e)=>{if(!t||"string"!=typeof t)return null;var r=!1,n=t;"#"===t[0]&&(n=t.slice(1),r=!0);var a=parseInt(n,16),c=(a>>16)+e;c>255?c=255:c<0&&(c=0);var o=(255&a)+e;o>255?o=255:o<0&&(o=0);var i=(a>>8&255)+e;return i>255?i=255:i<0&&(i=0),"".concat(r?"#":""," ").concat((o|i<<8|c<<16).toString(16)).replaceAll(" ","")},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!t)return t;var r=Array.isArray(t)&&3===t.length,n="string"==typeof t;if(n||r){var a,c,i;if(n){var u=o(t,"array");if(!u)return t;[a,c,i]=u}else[a,c,i]=t;return 1===e?"rgba(".concat(a,", ").concat(c,", ").concat(i,")"):"rgba(".concat(a,", ").concat(c,", ").concat(i,", ").concat(e,")")}return t},s=t=>((t,e)=>{for(var r=""+t;r.length<e;)r="0"+r;return r})(Math.min(Math.max(Math.round(t),0),255).toString(16),2),d=(t,e)=>{var r,n={red:parseInt(t.substr(0,2),16),green:parseInt(t.substr(2,2),16),blue:parseInt(t.substr(4,2),16)},a=[];for(var c=0;c<10;c++)a[c]=(r=e(n,c),s(r.red)+s(r.green)+s(r.blue));return a},p=(t,e)=>({red:t.red+(255-t.red)*e*.1,green:t.green+(255-t.green)*e*.1,blue:t.blue+(255-t.blue)*e*.1}),h=t=>d(t,p).concat("ffffff"),v=(t,e)=>({red:t.red*(1-.1*e),green:t.green*(1-.1*e),blue:t.blue*(1-.1*e)}),g=t=>d(t,v).concat("000000"),y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"string",n=[];Object.keys(t).forEach(e=>{n.push("--".concat(e,": ").concat(t[e],";"))}),e.forEach(r=>{if(!t[r])throw e.splice(e.indexOf(r),1),new Error("Color '".concat(r,"' is not defined"))});var a=[{name:"50",opacityPer:"10"},{name:"100",opacityPer:"20"},{name:"200",opacityPer:"40"},{name:"300",opacityPer:"60"},{name:"400",opacityPer:"80"},{name:"500",opacityPer:"100"},{name:"600",opacityShade:"80"},{name:"700",opacityShade:"60"},{name:"800",opacityShade:"40"},{name:"900",opacityShade:"20"}],c={};if(e.forEach(e=>{var r=h(t[e].replace("#","")).reverse(),n=g(t[e].replace("#","")).reverse();r.forEach((t,r)=>{var n=a.find(t=>{var{opacityPer:e}=t;return e==="".concat(10*r)});n&&(c["".concat(e,"-").concat(n.name)]="#".concat(t))}),n.forEach((t,r)=>{var n=a.find(t=>{var{opacityShade:e}=t;return e==="".concat(10*r)});n&&(c["".concat(e,"-").concat(n.name)]="#".concat(t))})}),Object.keys(c).forEach(t=>{n.push("--".concat(t,": ").concat(c[t],";"))}),"array"===r)return n;if("object"===r){var o={};return n.forEach(t=>{var[e,r]=t.replace(/--/g,"").split(":");o[e.trim()]=r.trim()}),o}return n.join("\n")},b=t=>{var e={},r=new Set,a=t=>n(t)?c(t):t,o={},i=t=>{o[t]=["any",["in",t,["get","multiflowColors"]],["all",["==",["get","color"],t],["==",["get","multiflowData"],null]]]};return t.forEach(t=>{var e=a(t.color),{multiflowColors:n}=t;Array.isArray(n)&&n.forEach(t=>{var e=a(t);r.has(e)||(i(e),r.add(e))}),r.has(e)||(i(e),r.add(e))}),Object.entries(o).forEach(t=>{var[r,n]=t;e[r]=["+",["case",n,1,0]]}),e},m=t=>[[1e3,50],[100,32],[10,24],[0,18]].find(e=>{var[r]=e;return t>=r})[1],x=t=>[[1e3,20],[100,18],[10,16],[0,14]].find(e=>{var[r]=e;return t>=r})[1],S=(t,e,r,n,a)=>{var c=(t,e)=>({x:e*Math.cos(2*Math.PI*(t-.25)),y:e*Math.sin(2*Math.PI*(t-.25))}),o=1===e?e-1e-5:e,i=o-t>.5?1:0,u=c(t,r),l=c(o,r),f=c(t,n),s=c(o,n);return'\n <path d="\n M '.concat(r+f.x," ").concat(r+f.y,"\n L ").concat(r+u.x," ").concat(r+u.y,"\n A ").concat(r," ").concat(r," 0 ").concat(i," 1 ").concat(r+l.x," ").concat(r+l.y,"\n L ").concat(r+s.x," ").concat(r+s.y,"\n A ").concat(n," ").concat(n," 0 ").concat(i," 0 ").concat(r+f.x," ").concat(r+f.y,'\n Z\n " fill="').concat(a,'" />\n ').trim()},P=t=>{var{point_count:e}=t,r=Object.keys(t).filter(t=>t.startsWith("#")),n=r.map(e=>t[e]),a=n.reduce((t,e)=>t+e,0),c=m(e||a),o=Math.round(.65*c),i=x(e||a),u=2*c,l=r.map((t,e)=>{var r=n.slice(0,e).reduce((t,e)=>t+e,0)/a,i=n.slice(0,e+1).reduce((t,e)=>t+e,0)/a;return S(r,i,c,o,t)}),f='\n <div>\n <svg width="'.concat(u,'" height="').concat(u,'" viewBox="0 0 ').concat(u," ").concat(u,'" text-anchor="middle" style="font: ').concat(i,'px Lato, sans-serif; font-weight:600; display: block">');f+=l.join(""),f+='<circle cx="'.concat(c,'" cy="').concat(c,'" r="').concat(o,'" fill="white" />\n <text dominant-baseline="central" transform="translate(').concat(c,", ").concat(c,')">\n ').concat(String(t.point_count),"\n </text>\n </svg>\n </div>");var s=document.createElement("div");return s.innerHTML=f.trim(),s.firstChild}}])}));