You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
2.1 KiB
2 lines
2.1 KiB
const t=new Map,n="#05c9ac";function e(t){if(!t||"string"!=typeof t)return n;let e=t.trim();if(e.startsWith("#")||(e=`#${e}`),/^#[0-9A-Fa-f]{6}$/.test(e))return e;if(/^#[0-9A-Fa-f]{3}$/.test(e)){const t=e[1],n=e[2],r=e[3];return`#${t}${t}${n}${n}${r}${r}`}return n}function r(n){const r=e(n||"");if(t.has(r))return t.get(r);if("undefined"==typeof document)return t.set(r,""),"";const i=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 56" width="48" height="56">\n<path fill="${r}" stroke="#ffffff" stroke-width="2" stroke-linejoin="round" d="M24 4C14.6 4 7 11.4 7 20.5C7 32 24 50 24 50S41 32 41 20.5C41 11.4 33.4 4 24 4Z"/>\n<circle cx="24" cy="21" r="7" fill="#ffffff"/>\n<circle cx="24" cy="21" r="3.5" fill="${r}"/>\n</svg>`)}`;return t.set(r,i),i}const i=80;function a(t,n){return new Promise(e=>{const r=new Image;n&&(r.crossOrigin="anonymous"),r.onload=()=>e(r),r.onerror=()=>e(null),r.src=t})}async function o(t,n,r){const i=t.trim();if(!i||"undefined"==typeof document)return"";let o=await a(i,!0);if(o||(o=await a(i,!1)),!o)return"";const s=e(n||""),c=Math.max(24,Math.min(Math.round(r??40),512)),f=document.createElement("canvas");f.width=c,f.height=c;const u=f.getContext("2d");if(!u)return"";u.clearRect(0,0,c,c);const h=c/2,l=c/2,g=Math.max(2,Math.min(6,Math.round(.038*c))),m=c/2-g-.25,{naturalWidth:d,naturalHeight:$}=o,w=d||o.width||1,p=$||o.height||1,y=2*m,M=Math.max(y/w,y/p),x=w*M,v=p*M,C=h-x/2,k=l-v/2;return u.save(),u.beginPath(),u.arc(h,l,m,0,2*Math.PI),u.clip(),u.drawImage(o,C,k,x,v),u.restore(),u.beginPath(),u.arc(h,l,m+g/2,0,2*Math.PI),u.strokeStyle=s,u.lineWidth=g,u.lineCap="round",u.stroke(),f.toDataURL("image/png")}function s(t,n){const e=t.venue_type_color;return e&&"string"==typeof e&&function(t){if(!t||"string"!=typeof t)return null;let n=t.trim();n.startsWith("#")||(n=`#${n}`);const e=n.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(!e)return null;let r=e[1];return 3===r.length&&(r=`${r[0]}${r[0]}${r[1]}${r[1]}${r[2]}${r[2]}`),r.toLowerCase()}(e.trim())?e.trim():n()}export{i as S,o as c,r as g,s as t};
|