MediaWiki:Gadget-maplibre-shield-generator.js

From OpenStreetMap Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* jslint esversion: 6 */
var Ke=Object.create;var me=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Ze=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var tt=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var nt=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Ye(e))!et.call(n,l)&&l!==t&&me(n,l,{get:()=>e[l],enumerable:!(i=Qe(e,l))||i.enumerable});return n};var it=(n,e,t)=>(t=n!=null?Ke(Ze(n)):{},nt(e||!n||!n.__esModule?me(t,"default",{value:n,enumerable:!0}):t,n));var ce=tt((Et,Se)=>{"use strict";Se.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}});var te=it(ce(),1),ye=lt,be={red:0,orange:60,yellow:120,green:180,blue:240,purple:300};function lt(n){var e,t=[],i=1,l;if(typeof n=="string")if(te.default[n])t=te.default[n].slice(),l="rgb";else if(n==="transparent")i=0,l="rgb",t=[0,0,0];else if(/^#[A-Fa-f0-9]+$/.test(n)){var a=n.slice(1),o=a.length,h=o<=4;i=1,h?(t=[parseInt(a[0]+a[0],16),parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16)],o===4&&(i=parseInt(a[3]+a[3],16)/255)):(t=[parseInt(a[0]+a[1],16),parseInt(a[2]+a[3],16),parseInt(a[4]+a[5],16)],o===8&&(i=parseInt(a[6]+a[7],16)/255)),t[0]||(t[0]=0),t[1]||(t[1]=0),t[2]||(t[2]=0),l="rgb"}else if(e=/^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\s*\(([^\)]*)\)/.exec(n)){var s=e[1],g=s==="rgb",a=s.replace(/a$/,"");l=a;var o=a==="cmyk"?4:a==="gray"?1:3;t=e[2].trim().split(/\s*[,\/]\s*|\s+/).map(function(r,f){if(/%$/.test(r))return f===o?parseFloat(r)/100:a==="rgb"?parseFloat(r)*255/100:parseFloat(r);if(a[f]==="h"){if(/deg$/.test(r))return parseFloat(r);if(be[r]!==void 0)return be[r]}return parseFloat(r)}),s===a&&t.push(1),i=g||t[o]===void 0?1:t[o],t=t.slice(0,o)}else n.length>10&&/[0-9](?:\s|\/)/.test(n)&&(t=n.match(/([0-9]+)/g).map(function(p){return parseFloat(p)}),l=n.match(/([a-z])/ig).join("").toLowerCase());else isNaN(n)?Array.isArray(n)||n.length?(t=[n[0],n[1],n[2]],l="rgb",i=n.length===4?n[3]:1):n instanceof Object&&(n.r!=null||n.red!=null||n.R!=null?(l="rgb",t=[n.r||n.red||n.R||0,n.g||n.green||n.G||0,n.b||n.blue||n.B||0]):(l="hsl",t=[n.h||n.hue||n.H||0,n.s||n.saturation||n.S||0,n.l||n.lightness||n.L||n.b||n.brightness]),i=n.a||n.alpha||n.opacity||1,n.opacity!=null&&(i/=100)):(l="rgb",t=[n>>>16,(n&65280)>>>8,n&255]);return{space:l,values:t,alpha:i}}var E={name:"rgb",min:[0,0,0],max:[255,255,255],channel:["red","green","blue"],alias:["RGB"]};var Q={name:"hsl",min:[0,0,0],max:[360,100,100],channel:["hue","saturation","lightness"],alias:["HSL"],rgb:function(n){var e=n[0]/360,t=n[1]/100,i=n[2]/100,l,a,o,h,s,g=0;if(t===0)return s=i*255,[s,s,s];for(a=i<.5?i*(1+t):i+t-i*t,l=2*i-a,h=[0,0,0];g<3;)o=e+1/3*-(g-1),o<0?o++:o>1&&o--,s=6*o<1?l+(a-l)*6*o:2*o<1?a:3*o<2?l+(a-l)*(2/3-o)*6:l,h[g++]=s*255;return h}};E.hsl=function(n){var e=n[0]/255,t=n[1]/255,i=n[2]/255,l=Math.min(e,t,i),a=Math.max(e,t,i),o=a-l,h,s,g;return a===l?h=0:e===a?h=(t-i)/o:t===a?h=2+(i-e)/o:i===a&&(h=4+(e-t)/o),h=Math.min(h*60,360),h<0&&(h+=360),g=(l+a)/2,a===l?s=0:g<=.5?s=o/(a+l):s=o/(2-a-l),[h,s*100,g*100]};function q(n){Array.isArray(n)&&n.raw&&(n=String.raw(...arguments));var e,t,i,l=ye(n);if(!l.space)return[];let a=l.space[0]==="h"?Q.min:E.min,o=l.space[0]==="h"?Q.max:E.max;return e=Array(3),e[0]=Math.min(Math.max(l.values[0],a[0]),o[0]),e[1]=Math.min(Math.max(l.values[1],a[1]),o[1]),e[2]=Math.min(Math.max(l.values[2],a[2]),o[2]),l.space[0]==="h"&&(e=Q.rgb(e)),e.push(Math.min(Math.max(l.alpha,0),1)),e}var at='"sans-serif-condensed", "Arial Narrow", sans-serif',G=(n,e)=>`condensed 500 ${n}px ${e||at}`,ie=11.8;function ne(n,e,t){return 255-n/255*(255-t)-(1-n/255)*(255-e)}function ot(n,e,t,i){e[i]=n[t],e[i+1]=n[t+1],e[i+2]=n[t+2],e[i+3]=n[t+3]}function rt(n,e,t,i,l,a){e[i]=ne(n[t],l[0],a[0]),e[i+1]=ne(n[t+1],l[1],a[1]),e[i+2]=ne(n[t+2],l[2],a[2]),e[i+3]=n[t+3]}function le(n,e,t,i,l,a){let o=n.createImageData(e.data.width,e.data.height),h=l||a?rt:ot,s=l?q(l):q("#000"),g=a?q(a):q("#fff");if(i)for(let p=0;p<e.data.height;p++)for(let u=0;u<e.data.width;u++){let f=((e.data.height-p-1)*e.data.width+u)*4,m=(p*e.data.width+u)*4;h(e.data.data,o.data,m,f,s,g)}else for(let p=0;p<e.data.data.length;p+=4)h(e.data.data,o.data,p,p,s,g);n.putImageData(o,0,t)}var L={Middle:"middle",Top:"top",Bottom:"bottom"},dt={top:0,bottom:0,left:0,right:0};function we(n,e){var t=n.width,i=n.height,l=e.width,a=e.height;return t*i/Math.sqrt(t*t*a*a+i*i*l*l)}function ht(n,e){return{scale:we(n,e),valign:L.Middle}}function st(n,e){return{scale:we(n,{height:e.width/2,width:e.height}),valign:L.Top}}function Ce(n,e){var t=n.height/e.height,i=n.width/e.width;return{scale:Math.min(i,t),valign:L.Middle}}function ut(n,e,t){let i=2;return t!==void 0&&t.radius!==void 0&&(i=t.radius),Ce({width:n.width-i*(2-Math.sqrt(2)),height:n.height-i*(2-Math.sqrt(2))},e)}function Te(n,e){let t=n.width,i=n.height,l=e.width,a=e.height;return{scale:t*i/(i*l+t*a),valign:L.Middle}}function gt(n,e){return{scale:Te(n,e).scale,valign:L.Top}}function ft(){if(typeof window=="undefined")return!1;let n=window.navigator.userAgent;return/WebKit/i.test(n)&&!/Chrome/i.test(n)}function ae(n,e,t,i,l,a=14){let o=n.px(t.top)||0,h=n.px(t.bottom)||0,s=n.px(t.left)||0,g=n.px(t.right)||0,p=n.px(a),u=n.gfxFactory.createGraphics(i);u.font=G(ie,n.options.shieldFont),u.textAlign="left",u.textBaseline="top";let r=u.measureText(e),f=Math.abs(r.actualBoundingBoxLeft)+Math.abs(r.actualBoundingBoxRight),m=Math.abs(r.actualBoundingBoxDescent)+Math.abs(r.actualBoundingBoxAscent);m*=.9,ft()&&(m*=.54);let S=i.height-o-h,d=i.width-s-g,c=s+d/2,b=Pe[l.constraintFunc],x=b({height:S,width:d},{height:m,width:f},l.options);var T=Math.min(p,ie*x.scale);u.font=G(T,n.options.shieldFont),u.textAlign="left",u.textBaseline="top",r=u.measureText(e),m=Math.abs(r.actualBoundingBoxDescent)+Math.abs(r.actualBoundingBoxAscent);let C;switch(x.valign){case L.Top:C=o+r.actualBoundingBoxAscent;break;case L.Bottom:C=o+S-m+r.actualBoundingBoxAscent;break;case L.Middle:default:C=o+(S-m)/2;break}return{xBaseline:c,yBaseline:C,fontPx:T}}var pt={padding:{top:0,bottom:0,left:0,right:0},shapeBlank:{drawFunc:"rect",params:{fillColor:"white",strokeColor:"black"}}};function Re(n,e,t,i){t==null&&(t=pt);var l=t.padding||dt,a={constraintFunc:"rect"},o=14;return typeof t.textLayout!="undefined"&&(a=t.textLayout),typeof t.maxFontSize!="undefined"&&(o=Math.min(o,t.maxFontSize)),ae(n,e,l,i,a,o)}function ke(n,e,t,i){ve(n,e,i),e.fillText(t,i.xBaseline,i.yBaseline)}function oe(n,e,t,i){ve(n,e,i),e.shadowColor=e.strokeStyle.toString(),e.shadowBlur=0,e.lineWidth=n.px(2),e.strokeText(t,i.xBaseline,i.yBaseline),e.shadowColor=null,e.shadowBlur=null}function ve(n,e,t){e.textAlign="center",e.textBaseline="top",e.font=G(t.fontPx,n.options.shieldFont)}function De(n,e,t){var i=n.emptySprite();return i.font=G(t,n.options.shieldFont),Math.ceil(i.measureText(e).width)}var Pe={};function X(n,e){Pe[n]=e}X("diamond",Te);X("ellipse",ht);X("rect",Ce);X("roundedRect",ut);X("southHalfEllipse",st);X("triangleDown",gt);function mt(n,e,t){$(n,e,{fillColor:"white",strokeColor:"black",outlineWidth:1,radius:2,rectWidth:20});let i=t.fillColor,l=n.px(.5),a=n.shieldSize()/3-l;return e.beginPath(),e.arc(n.shieldSize()/2,n.shieldSize()/2,a,0,2*Math.PI,!1),e.fillStyle=i,e.strokeStyle=t.strokeColor,e.fill(),e.lineWidth=l,e.stroke(),20}function St(n,e,t){$(n,e,{fillColor:"#006747",strokeColor:"white",outlineWidth:1,radius:2,rectWidth:20});let i=t.fillColor,l=n.px(.5),a=.15*n.shieldSize()+l,o=.7*n.shieldSize()-2*l,h=.4*n.shieldSize()+l,s=.45*n.shieldSize()-2*l;return e.beginPath(),e.rect(a,h,o,s),e.fillStyle=i,e.strokeStyle=t.strokeColor,e.fill(),e.lineWidth=l,e.stroke(),20}function Me(){F("branson",St,20),F("paBelt",mt,20)}var ct=20,bt=34,yt=18;function I(n,e,t,i){if(re[i]!==void 0)return n.px(re[i]);let l=e.rectWidth==null?null:e.rectWidth,a=e.sideAngle==null?0:e.sideAngle,o=Math.tan(a);if(l==null){let h=De(n,t,n.px(yt))+n.px(2),s=n.px(ct);switch(i){case"pentagon":let g=e.yOffset==null?0:e.yOffset;h+=(n.shieldSize()-n.px(g))*o/2;break;case"trapezoid":h+=n.shieldSize()*o/2;break;case"triangle":s+=n.px(2);break;case"diamond":case"hexagonHorizontal":s+=n.px(4);break}return Math.max(s,Math.min(n.px(bt),h))}else return n.px(l)}function xt(n,e,t,i){let l=t.fillColor==null?"white":t.fillColor,a=t.strokeColor==null?"black":t.strokeColor,o=I(n,t,i),h=n.px(1),s=o/2-h,g=n.shieldSize()/2-h;return e.beginPath(),e.ellipse(e.canvas.width/2,n.shieldSize()/2,s,g,0,0,2*Math.PI,!1),e.fillStyle=l,e.fill(),e.lineWidth=h,e.strokeStyle=a,e.stroke(),o}function wt(n,e,t,i){return t.radius=n.shieldSize()/n.px(2),$(n,e,t,i)}function $(n,e,t,i){let l=t.fillColor==null?"white":t.fillColor,a=t.strokeColor==null?"black":t.strokeColor,o=t.radius==null?0:t.radius,h=t.outlineWidth==null?1:t.outlineWidth,s=I(n,t,i),g=n.px(h),p=g/2,u=n.px(o),r=p,f=p+u,m=s-p-u,S=s-p,d=p,c=p+u,b=n.shieldSize()-p-u,y=n.shieldSize()-p;return e.beginPath(),e.moveTo(m,d),e.arcTo(S,d,S,c,u),e.arcTo(S,y,m,y,u),e.arcTo(r,y,r,b,u),e.arcTo(r,d,f,d,u),e.closePath(),e.lineWidth=g,e.fillStyle=l,e.fill(),a!=null&&(e.strokeStyle=a,e.stroke()),s}function Ct(n,e,t,i){let l=t.yOffset==null?0:t.yOffset,a=t.fillColor==null?"white":t.fillColor,o=t.strokeColor==null?"black":t.strokeColor,h=t.radius==null?0:t.radius,s=t.outlineWidth==null?1:t.outlineWidth,g=I(n,t,i),p=n.px(s),u=p/2,r=n.px(h),f=n.px(l),m=u,S=g-u,d=u,c=n.shieldSize()-u,b=m+r,y=(m+S)/2,w=d+r,x=c-f,T=(2*m+y)/3,C=(y+2*S)/3,R=(x+c)/2,v=(R+2*c)/3;return e.beginPath(),e.moveTo(y,c),e.bezierCurveTo(T,v,m,R,m,x),e.arcTo(m,d,b,d,r),e.arcTo(S,d,S,w,r),e.lineTo(S,x),e.bezierCurveTo(S,R,C,v,y,c),e.closePath(),e.lineWidth=p,e.fillStyle=a,e.fill(),o!=null&&(e.strokeStyle=o,e.stroke()),g}function Tt(n,e,t,i){let l=t.pointUp==null?!1:t.pointUp,a=t.fillColor==null?"white":t.fillColor,o=t.strokeColor==null?"black":t.strokeColor,h=t.outlineWidth==null?1:t.outlineWidth,s=l?-1:1,g=I(n,t,i),p=n.px(h),u=p/2,r=u,f=g-u,m=l?n.shieldSize()-u:u,S=l?u:n.shieldSize()-u,d=r+n.px(1),c=r+n.px(2.5),b=(r+f)/2,y=f-n.px(2.5),w=f-n.px(1),x=m+s*n.px(2),T=m+s*n.px(4.5),C=m+s*n.px(7),R=S-s*n.px(6),v=S-s*n.px(1),k=(r+b)/2,D=(b+f)/2;return e.beginPath(),e.moveTo(b,S),e.bezierCurveTo(k,v,r,R,r,C),e.bezierCurveTo(r,T,d,x,c,m),e.lineTo(y,m),e.bezierCurveTo(w,x,f,T,f,C),e.bezierCurveTo(f,R,D,v,b,S),e.closePath(),e.lineWidth=p,e.fillStyle=a,e.fill(),o!=null&&(e.strokeStyle=o,e.stroke()),g}function Rt(n,e,t,i){let l=t.pointUp==null?!1:t.pointUp,a=t.fillColor==null?"white":t.fillColor,o=t.strokeColor==null?"black":t.strokeColor,h=t.radius==null?0:t.radius,s=t.outlineWidth==null?1:t.outlineWidth,g=l?-1:1,p=I(n,t,i,"triangle"),u=n.px(s),r=u/2,f=n.px(h),m=r,S=p-r,d=l?n.shieldSize()-r:r,c=l?r:n.shieldSize()-r,b=m+f,y=(m+S)/2,w=S-f,x=d+g*f,T=Math.atan((y-b)/Math.abs(c-f-x)),C=Math.sin(T),R=Math.cos(T),v=Math.tan(T/2),k=Math.tan(Math.PI/4-T/2),D=b-f*R,P=y-f*k,B=y+f*k,z=w+f*R,W=x+g*f*v,M=x+g*f*C,A=c-g*f*(1-C);return e.beginPath(),e.moveTo(y,c),e.arcTo(P,c,D,M,f),e.arcTo(m,W,m,x,f),e.arcTo(m,d,b,d,f),e.arcTo(S,d,S,x,f),e.arcTo(S,W,z,M,f),e.arcTo(B,c,y,c,f),e.closePath(),e.lineWidth=u,e.fillStyle=a,e.fill(),o!=null&&(e.strokeStyle=o,e.stroke()),p}function kt(n,e,t,i){let l=t.shortSideUp==null?!1:t.shortSideUp,a=t.sideAngle==null?0:t.sideAngle,o=t.fillColor==null?"white":t.fillColor,h=t.strokeColor==null?"black":t.strokeColor,s=t.radius==null?0:t.radius,g=t.outlineWidth==null?1:t.outlineWidth,p=l?-1:1,u=Math.sin(a),r=Math.cos(a),f=Math.tan(a),m=I(n,t,i,"trapezoid"),S=n.px(g),d=S/2,c=n.px(s),b=d,y=m-d,w=l?n.shieldSize()-d:d,x=l?d:n.shieldSize()-d,T=w+p*c*(1+u),C=x-p*c*(1-u),R=b+(T-w)*f,v=R+c*r,k=b+p*(C-w)*f,D=b+p*(x-w)*f,P=k+p*c*r,B=m-D,z=m-k,W=m-v;return e.beginPath(),e.moveTo(W,w),e.arcTo(y,w,z,C,c),e.arcTo(B,x,P,x,c),e.arcTo(D,x,R,T,c),e.arcTo(b,w,W,w,c),e.closePath(),e.lineWidth=S,e.fillStyle=o,e.fill(),h!=null&&(e.strokeStyle=h,e.stroke()),m}function vt(n,e,t,i){let l=t.fillColor==null?"white":t.fillColor,a=t.strokeColor==null?"black":t.strokeColor,o=t.radius==null?0:t.radius,h=t.outlineWidth==null?1:t.outlineWidth,s=Y(n,"diamond"),g=I(n,t,i,"diamond"),p=n.px(h),u=p/2,r=n.px(o),f=u,m=g-u,S=u,d=s-u,c=(f+m)/2,b=(S+d)/2,y=Math.atan((c-r-f)/(d-r-b)),w=Math.sin(y),x=Math.cos(y),T=Math.tan(y/2),C=Math.tan(Math.PI/4-y/2),R=f+r*(1-x),v=c-r*x,k=c-r*C,D=c+r*C,P=c+r*x,B=m-r*(1-x),z=S+r*(1-w),W=b-r*w,M=b-r*T,A=b+r*T,_=b+r*w,H=d-r*(1-w);return e.beginPath(),e.moveTo(c,d),e.arcTo(k,d,R,_,r),e.arcTo(f,A,f,b,r),e.arcTo(f,M,v,z,r),e.arcTo(k,S,c,S,r),e.arcTo(D,S,B,W,r),e.arcTo(m,M,m,b,r),e.arcTo(m,A,P,H,r),e.arcTo(D,d,c,d,r),e.closePath(),e.lineWidth=p,e.fillStyle=l,e.fill(),a!=null&&(e.strokeStyle=a,e.stroke()),g}function Dt(n,e,t,i){let l=t.pointUp==null?!0:t.pointUp,a=t.yOffset==null?0:t.yOffset,o=t.sideAngle==null?0:t.sideAngle,h=t.fillColor==null?"white":t.fillColor,s=t.strokeColor==null?"black":t.strokeColor,g=t.radius1==null?0:t.radius1,p=t.radius2==null?0:t.radius2,u=t.outlineWidth==null?1:t.outlineWidth,r=l?-1:1,f=Math.sin(o),m=Math.cos(o),S=Math.tan(o),d=I(n,t,i,"pentagon"),c=n.px(u),b=c/2,y=n.px(g),w=n.px(p),x=n.px(a),T=b,C=d-b,R=l?n.shieldSize()-b:b,v=l?b:n.shieldSize()-b,k=v-r*x,D=T+r*(k-R)*S,P=(T+C)/2,B=C-r*(k-R)*S,z=Math.atan(x/(P-T)),W=(Math.PI/2-z+o)/2,M=Math.tan(W),A=(Math.PI/2-o)/2,_=Math.tan(A),H=T+y*M*f,J=D+w*_,N=B-w*_,V=C-y*M*f,K=k-r*y*M*m;return e.beginPath(),e.moveTo(P,v),e.arcTo(T,k,H,K,y),e.arcTo(D,R,J,R,w),e.lineTo(N,R),e.arcTo(B,R,V,K,w),e.arcTo(C,k,P,v,y),e.closePath(),e.lineWidth=c,e.fillStyle=h,e.fill(),s!=null&&(e.strokeStyle=s,e.stroke()),d}function Pt(n,e,t,i){let l=t.yOffset==null?0:t.yOffset,a=t.fillColor==null?"white":t.fillColor,o=t.strokeColor==null?"black":t.strokeColor,h=t.radius==null?0:t.radius,s=t.outlineWidth==null?1:t.outlineWidth,g=I(n,t,i),p=n.px(s),u=p/2,r=n.px(h),f=n.px(l),m=u,S=g-u,d=u,c=n.shieldSize()-u,b=(m+S)/2,y=d+f,w=c-f,x=r*Math.tan(Math.PI/4-Math.asin(f/(b-m))/2),T=y+x,C=w-x;return e.beginPath(),e.moveTo(b,c),e.arcTo(m,w,m,C,r),e.arcTo(m,y,b,d,r),e.lineTo(b,d),e.arcTo(S,y,S,T,r),e.arcTo(S,w,b,c,r),e.lineTo(b,c),e.closePath(),e.lineWidth=p,e.fillStyle=a,e.fill(),o!=null&&(e.strokeStyle=o,e.stroke()),g}function Bt(n,e,t,i){let l=t.sideAngle==null?0:t.sideAngle,a=t.fillColor==null?"white":t.fillColor,o=t.strokeColor==null?"black":t.strokeColor,h=t.radius==null?0:t.radius,s=t.outlineWidth==null?1:t.outlineWidth,g=Math.sin(l),p=Math.cos(l),u=Math.tan(l),r=Math.tan(Math.PI/4-l/2),f=I(n,t,i,"hexagonHorizontal"),m=n.px(s),S=m/2,d=n.px(h),c=S,b=f-S,y=S,w=n.shieldSize()-S,x=(y+w)/2,T=y+d*r*p,C=x-d*g,R=x+d*g,v=w-d*r*p,k=c+(x-C)*u,D=c+(x-y)*u,P=b-(x-y)*u,B=b-(x-C)*u,z=D-d*r*g,W=D+d*r,M=P-d*r,A=P+d*r*g;return e.beginPath(),e.moveTo(W,y),e.arcTo(P,y,A,T,d),e.arcTo(b,x,B,R,d),e.arcTo(P,w,M,w,d),e.arcTo(D,w,z,v,d),e.arcTo(c,x,k,C,d),e.arcTo(D,y,W,y,d),e.closePath(),e.lineWidth=m,e.fillStyle=a,e.fill(),o!=null&&(e.strokeStyle=o,e.stroke()),f}function Mt(n,e,t,i){let l=t.yOffset==null?0:t.yOffset,a=t.sideAngle==null?0:t.sideAngle,o=t.fillColor==null?"white":t.fillColor,h=t.strokeColor==null?"black":t.strokeColor,s=t.radius==null?0:t.radius,g=t.outlineWidth==null?1:t.outlineWidth,p=Math.sin(a),u=Math.cos(a),r=Math.tan(a),f=I(n,t,i),m=n.px(g),S=m/2,d=n.px(s),c=n.px(l),b=S,y=f-S,w=S,x=n.shieldSize()-S,T=b+d*r*p,C=(b+y)/2,R=y-d*r*p,v=w+c,k=(w+x)/2,D=x-c,P=b+(k-v)*r,B=y-(k-v)*r,z=k-d*r*u,W=k+d*r*u,M=Math.atan(c/(C-P)),A=Math.sin(M),_=Math.cos(M),H=(Math.PI/2-a-M)/2,J=Math.cos(H),N=d*Math.cos(a+H)/J,V=d*Math.sin(a+H)/J,K=P+N-d*u,Ve=P+N-d*A,qe=B-N+d*A,Xe=B-N+d*u,Ee=v+V-d*_,$e=v+V-d*p,je=D-V+d*p,Je=D-V+d*_;return e.beginPath(),e.moveTo(C,x),e.arcTo(P,D,K,je,d),e.arcTo(b,k,T,z,d),e.arcTo(P,v,Ve,Ee,d),e.lineTo(C,w),e.arcTo(B,v,Xe,$e,d),e.arcTo(y,k,R,W,d),e.arcTo(B,D,qe,Je,d),e.lineTo(C,x),e.closePath(),e.lineWidth=m,e.fillStyle=o,e.fill(),h!=null&&(e.strokeStyle=h,e.stroke()),f}function Y(n,e){switch(e){case"diamond":return n.shieldSize()+n.px(4);default:return n.shieldSize()}}function We(n,e,t,i,l){return Ie[e](n,t,i,l)}var Ie={},re={};function F(n,e,t){Ie[n]=e,t!==void 0&&(re[n]=t)}F("diamond",vt);F("ellipse",xt);F("escutcheon",Ct);F("fishhead",Tt);F("hexagonVertical",Pt);F("hexagonHorizontal",Bt);F("octagonVertical",Mt);F("pentagon",Dt);F("pill",wt);F("roundedRectangle",$);F("trapezoid",kt);F("triangle",Rt);Me();var Ft={constraintFunc:"rect"};function ze(n,e,t){t.bannerTextColor?e.fillStyle=t.bannerTextColor:e.fillStyle=n.options.bannerTextColor,Le(n,e,t,Wt)}function Ae(n,e,t){t.bannerTextHaloColor?e.strokeStyle=e.shadowColor=t.bannerTextHaloColor:e.strokeStyle=e.shadowColor=n.options.bannerTextHaloColor,Le(n,e,t,It)}function Le(n,e,t,i){if(!(t==null||typeof t.banners=="undefined"))for(var l=0;l<t.banners.length;l++)i(n,e,t.banners[l],l)}function _e(n){return n==null||typeof n.banners=="undefined"?0:n.banners.length}function Wt(n,e,t,i){He(n,e,t,i,!0)}function It(n,e,t,i){He(n,e,t,i,!1)}function He(n,e,t,i,l){let a={top:0,bottom:0,left:0,right:0},o={width:e.canvas.width,height:n.px(n.options.bannerHeight-n.options.bannerPadding)},h=ae(n,t,a,o,Ft);e.font=G(h.fontPx,n.options.shieldFont),e.textBaseline="top",e.textAlign="center",l?e.fillText(t,h.xBaseline,h.yBaseline+i*n.px(n.options.bannerHeight+n.options.bannerPadding)):(e.shadowBlur=0,e.lineWidth=n.px(2),e.strokeText(t,h.xBaseline,h.yBaseline+i*n.px(n.options.bannerHeight+n.options.bannerPadding)),e.shadowColor=null,e.shadowBlur=null)}var zt=/[1IJijl .-]/g;function de(n){return n!==null&&n.length!==0&&n.length<=6}function At(n,e,t){var h;let i=null,l,a=0,o;if(Array.isArray(e.spriteBlank)){let s=((h=t.ref.match(zt))!=null?h:[]).length,g=Math.ceil(t.ref.length-s/3),p=e.spriteBlank.length-1,u=e.spriteBlank.map(f=>parseInt(f.split("_").reverse()[0])),r=g>u[p]?p:Math.max(0,u.indexOf(g));i=n.spriteRepo.getSprite(e.spriteBlank[r])}else i=n.spriteRepo.getSprite(e.spriteBlank);return i}function Lt(n){return n!=null&&typeof n.textColor!="undefined"?n.textColor:"black"}function _t(n){return typeof n.shapeBlank!="undefined"?(e,t,i)=>We(e,n.shapeBlank.drawFunc,t,n.shapeBlank.params,i):(console.warn(`Draw function not defined in:
${n}`),(e,t,i)=>{})}function Ht(n,e){return typeof e.shapeBlank!="undefined"?Y(n,e.shapeBlank.drawFunc):n.shieldSize()}function Gt(n,e,t,i,l){var o,h;if(t.notext)return e;var a=Re(n,i.ref,t,l);return typeof((o=n.debugOptions)==null?void 0:o.shieldTextHaloColor)!="undefined"?(e.strokeStyle=n.debugOptions.shieldTextHaloColor,oe(n,e,i.ref,a)):t.textHaloColor&&(e.strokeStyle=t.textHaloColor,oe(n,e,i.ref,a)),e.fillStyle=Lt(t),ke(n,e,i.ref,a),(h=n.debugOptions)!=null&&h.shieldTextBboxColor&&(e.strokeStyle=n.debugOptions.shieldTextBboxColor,e.lineWidth=n.px(1),e.strokeRect(n.px(t.padding.left-.5),n.px(t.padding.top-.5),l.width-n.px(t.padding.left+t.padding.right-1),l.height-n.px(t.padding.top+t.padding.bottom-1))),e}function he(n,e,t,i){let l=se(n,e);l==null&&(console.warn("Didn't produce a shield for",JSON.stringify(e)),l=n.gfxFactory.createGraphics({width:1,height:1})),Ge(n,t,l,i)}function Ge(n,e,t,i){let l=t.getImageData(0,0,t.canvas.width,t.canvas.height);n.spriteRepo.putSprite(e,{width:t.canvas.width,height:t.canvas.height,data:l.data},{pixelRatio:n.px(1)},i)}function Oe(n,e){Ge(n,e,n.emptySprite(),!1)}function Ue(n,e){return e.ref?e.ref:e.refsByName&&n.name&&e.refsByName[n.name]?e.refsByName[n.name]:n.ref}function Ot(n,e){if(!n)return null;let t=n[e.network];if(e==null)return null;if(t==null)return console.debug("Generic shield for",JSON.stringify(e)),de(e.ref)?n.default:null;var i=Ue(e,t);return t.overrideByRef&&(t={...t,...t.overrideByRef[i]}),t.overrideByName&&(t={...t,...t.overrideByName[e.name||""]}),!de(i)&&"noref"in t&&(t=t.noref,t.notext=!0),!de(i)&&!t.notext&&!t.ref&&!(t.refsByName&&e.name)?null:t}function Ut(n){let e=parseInt(n,10);if(isNaN(e))return n;let t="M".repeat(e/1e3)+"D".repeat(e%1e3/500)+"C".repeat(e%500/100)+"L".repeat(e%100/50)+"X".repeat(e%50/10)+"V".repeat(e%10/5)+"I".repeat(e%5);return t=t.replace("DCCCC","CM").replace("CCCC","CD").replace("LXXXX","XC").replace("XXXX","XL").replace("VIIII","IX").replace("IIII","IV"),t+n.slice(e.toString().length)}function Nt(n,e,t){let i=Math.max(n.shieldSize(),I(n,e.shapeBlank.params,t,e.shapeBlank.drawFunc)),l=Y(n,e.shapeBlank.drawFunc);return{width:i,height:l}}function Vt(n,e){return e===0?0:e*n.px(n.options.bannerHeight)+(e-1)*n.px(n.options.bannerPadding)}function se(n,e){let t=Ot(n.shieldDef,e);if(t==null)return null;e.ref=Ue(e,t);let i=_e(t),l=At(n,t,e),a=n.shieldSize(),o=n.shieldSize(),h=null;if(l==null){if(typeof t.shapeBlank!="undefined"){let p=Nt(n,t,e.ref);a=p.width,o=p.height}h={width:a,height:Ht(n,t)}}else a=l.data.width,o=l.data.height,h={width:a,height:o};let s=Vt(n,i);o+=s;let g=n.gfxFactory.createGraphics({width:a,height:o});return e.ref&&t.numberingSystem==="roman"&&(e.ref=Ut(e.ref)),Ae(n,g,t),g.save(),g.translate(0,s),l==null?_t(t)(n,g,e.ref):le(g,l,s,t.verticalReflect,t.colorLighten,t.colorDarken),Gt(n,g,t,e,h),g.restore(),ze(n,g,t),g}function Ne(){return(typeof window!="undefined"&&window.devicePixelRatio)>1?2:1}var Z=class{createGraphics(e){var t=document.createElement("canvas").getContext("2d"),t=document.createElement("canvas").getContext("2d",{willReadFrequently:!0});return t.imageSmoothingQuality="high",t.textAlign="center",t.textBaseline="top",t.canvas.width=e.width,t.canvas.height=e.height,t}pixelRatio(){return Ne()}};var ue=class{emptySprite(){return this._emptySpriteCache||(this._emptySpriteCache=this.gfxFactory.createGraphics({width:1,height:1})),this._emptySpriteCache}px(e){return e*this.gfxFactory.pixelRatio()}shieldSize(){return this.px(this.options.shieldSize)}},ge=class{constructor(e){this.map=e}getSprite(e){return this.map.style.getImage(e)}putSprite(e,t,i,l){l&&this.map.listImages().includes(e)?(this.map.removeImage(e),this.map.addImage(e,t)):this.map.addImage(e,t,i)}},j=class{constructor(e){this._shieldPredicate=()=>!0;this._networkPredicate=()=>!0;this._fontsLoaded=!1;this._preFontImageCache=new Map;this._shieldDefCallbacks=[];this._routeParser=e,this._renderContext=new ue,this._renderContext.gfxFactory=new Z}setShields(e){this._renderContext.options=e.options,this._renderContext.shieldDef=e.networks,this._fontSpec="1em "+e.options.shieldFont,console.log("ShieldJSON loaded"),this._map&&this.reloadShieldsOnFontLoad(),this._shieldDefCallbacks.forEach(t=>t(e.networks))}onFontsLoaded(){if(this._fontsLoaded=!0,this._preFontImageCache.size!=0){console.log("Re-processing shields with loaded fonts");for(let[e,t]of this._preFontImageCache.entries())he(this._renderContext,t,e,!0);this._preFontImageCache.clear(),this._map.redraw()}}getShieldDefinitions(){return this._renderContext.shieldDef}debugOptions(e){return this._renderContext.debugOptions=e,this}filterImageID(e){return this._shieldPredicate=e,this}filterNetwork(e){return this._networkPredicate=e,this}graphicsFactory(e){return this._renderContext.gfxFactory=e,this}renderOnMaplibreGL(e){return this._map=e,this._fontSpec&&this.reloadShieldsOnFontLoad(),this.renderOnRepository(new ge(e)),e.on("styleimagemissing",this.getStyleImageMissingHandler()),this}reloadShieldsOnFontLoad(){!this._fontsLoaded&&!document.fonts.check(this._fontSpec)?document.fonts.load(this._fontSpec).then(()=>this.onFontsLoaded()):this._fontsLoaded=!0}onShieldDefLoad(e){return this._renderContext.shieldDef?e(this._renderContext.shieldDef):this._shieldDefCallbacks.push(e),this}renderOnRepository(e){return this._renderContext.spriteRepo||(this._renderContext.spriteRepo=e),this}getStyleImageMissingHandler(){return e=>{try{if(!this._shieldPredicate(e.id))return;let t=this._routeParser.parse(e.id);if(!this._networkPredicate(t.network)){Oe(this._renderContext,e.id);return}t&&(!this._fontsLoaded&&t.ref&&this._preFontImageCache.set(e.id,t),he(this._renderContext,t,e.id,!1))}catch(t){console.error(`Exception while loading image \u2018${e==null?void 0:e.id}\u2019:
`,t)}}}getGraphicForRoute(e,t,i){return se(this._renderContext,{network:e,ref:t,name:i})}emptySprite(){return this._renderContext.emptySprite()}createGraphics(e){return this._renderContext.gfxFactory.createGraphics(e)}pixelRatio(){return this._renderContext.px(1)}},fe=class extends j{constructor(e,t){super(t),this.setShields(e)}},pe=class extends j{constructor(e,t){super(t),this.setShieldURL(e)}async setShieldURL(e){await fetch(e).then(t=>t.json()).then(t=>super.setShields(t)).catch(t=>console.error(t))}},ee=class{constructor(){this.sprites={}}getSprite(e){return this.sprites[e]}hasSprite(e){return e in this.sprites}putSprite(e,t){this.sprites[e]=t}},pn=new ee;function O(n){return{constraintFunc:"roundedRect",options:{radius:n}}}function U(n){return{constraintFunc:n}}function qt(n,e,t,i){return t=t!=null?t:e,{shapeBlank:{drawFunc:"ellipse",params:{fillColor:n,strokeColor:e,rectWidth:i}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:t}}function Sn(n,e,t){return qt(n,e,t,20)}function cn(n,e,t,i,l){return t=t!=null?t:e,l=l!=null?l:2,{shapeBlank:{drawFunc:"roundedRectangle",params:{fillColor:n,strokeColor:e,rectWidth:i,radius:l}},textLayout:O(l),padding:{left:3,right:3,top:3,bottom:3},textColor:t}}function bn(n,e,t,i,l,a){return i=i!=null?i:t,l=l!=null?l:0,{shapeBlank:{drawFunc:"escutcheon",params:{yOffset:n,fillColor:e,strokeColor:t,rectWidth:a,radius:l,outlineWidth:1}},textLayout:O(l),padding:{left:2,right:2,top:2,bottom:0+n/2},textColor:i}}function yn(n,e,t,i){return t=t!=null?t:e,{shapeBlank:{drawFunc:"fishhead",params:{fillColor:n,strokeColor:e,rectWidth:i,outlineWidth:1}},textLayout:U("ellipse"),padding:{left:1,right:1,top:1,bottom:5},textColor:t}}function xn(n,e,t,i,l){return t=t!=null?t:e,i=i!=null?i:2,{shapeBlank:{drawFunc:"triangle",params:{pointUp:!1,fillColor:n,strokeColor:e,rectWidth:l,radius:i}},textLayout:U("triangleDown"),padding:{left:1,right:1,top:2,bottom:1},textColor:t}}function wn(n,e,t,i,l,a){let o=n*Math.PI/180;return i=i!=null?i:t,l=l!=null?l:0,{shapeBlank:{drawFunc:"trapezoid",params:{sideAngle:o,fillColor:e,strokeColor:t,rectWidth:a,radius:l}},textLayout:O(l),padding:{left:2+10*Math.tan(o),right:2+10*Math.tan(o),top:2,bottom:4},textColor:i}}function Cn(n,e,t,i,l,a){let o=n*Math.PI/180;return i=i!=null?i:t,l=l!=null?l:0,{shapeBlank:{drawFunc:"trapezoid",params:{shortSideUp:!0,sideAngle:o,fillColor:e,strokeColor:t,rectWidth:a,radius:l}},textLayout:O(l),padding:{left:2+10*Math.tan(o),right:2+10*Math.tan(o),top:4,bottom:2},textColor:i}}function Tn(n,e,t,i,l){return t=t!=null?t:e,i=i!=null?i:2,{shapeBlank:{drawFunc:"diamond",params:{fillColor:n,strokeColor:e,radius:i,rectWidth:l}},textLayout:U("diamond"),padding:{left:1,right:1,top:1,bottom:1},textColor:t}}function Rn(n,e,t,i,l,a,o,h){let s=e*Math.PI/180;return l=l!=null?l:i,a=a!=null?a:2,o=o!=null?o:0,{shapeBlank:{drawFunc:"pentagon",params:{yOffset:n,sideAngle:s,fillColor:t,strokeColor:i,radius1:a,radius2:o,rectWidth:h}},textLayout:{constraintFunc:"rect"},padding:{left:2+(20-n)*Math.tan(s)/2,right:2+(20-n)*Math.tan(s)/2,top:1+n/2,bottom:3},textColor:l}}function kn(n,e,t,i,l,a,o){return i=i!=null?i:t,l=l!=null?l:2,a=a!=null?a:2,{shapeBlank:{drawFunc:"pentagon",params:{pointUp:!1,yOffset:n,sideAngle:0,fillColor:e,strokeColor:t,radius1:l,radius2:a,rectWidth:o}},textLayout:O(a),padding:{left:2,right:2,top:2,bottom:1+n},textColor:i}}function vn(n,e,t,i,l,a,o){return i=i!=null?i:t,l=l!=null?l:2,a=a!=null?a:2,{shapeBlank:{drawFunc:"pentagon",params:{pointUp:!0,yOffset:n,sideAngle:0,fillColor:e,strokeColor:t,radius1:l,radius2:a,rectWidth:o}},textLayout:O(a),padding:{left:2,right:2,top:1+n,bottom:2},textColor:i}}function Dn(n,e,t,i,l,a){return i=i!=null?i:t,l=l!=null?l:2,{shapeBlank:{drawFunc:"hexagonVertical",params:{yOffset:n,fillColor:e,strokeColor:t,radius:l,rectWidth:a}},textLayout:O(l),padding:{left:2,right:2,top:1+n,bottom:1+n},textColor:i}}function Pn(n,e,t,i,l,a){let o=n*Math.PI/180;return i=i!=null?i:t,l=l!=null?l:2,{shapeBlank:{drawFunc:"hexagonHorizontal",params:{sideAngle:o,fillColor:e,strokeColor:t,radius:l,rectWidth:a}},textLayout:U("ellipse"),padding:{left:3,right:3,top:2,bottom:2},textColor:i}}function Bn(n,e,t,i,l,a,o){let h=e*Math.PI/180;return l=l!=null?l:i,a=a!=null?a:2,{shapeBlank:{drawFunc:"octagonVertical",params:{yOffset:n,sideAngle:h,fillColor:t,strokeColor:i,radius:a,rectWidth:o}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:l}}function Mn(n,e,t,i){return t=t!=null?t:e,{shapeBlank:{drawFunc:"pill",params:{fillColor:n,strokeColor:e,rectWidth:i}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:t}}function Fn(n,e,t){return{banners:e,bannerTextColor:t,...n}}function Wn(n,e){return{notext:!0,shapeBlank:{drawFunc:"paBelt",params:{fillColor:n,strokeColor:e}}}}function In(n,e){return{notext:!0,shapeBlank:{drawFunc:"branson",params:{fillColor:n,strokeColor:e}}}}export{j as AbstractShieldRenderer,ee as InMemorySpriteRepository,fe as ShieldRenderer,pe as URLShieldRenderer,Fn as banneredShield,In as bransonRouteShield,Sn as circleShield,Tn as diamondShield,bn as escutcheonDownShield,yn as fishheadDownShield,Ne as getDOMPixelRatio,Pn as hexagonHorizontalShield,Dn as hexagonVerticalShield,kn as homePlateDownShield,vn as homePlateUpShield,Bn as octagonVerticalShield,qt as ovalShield,Wn as paBeltShield,Rn as pentagonUpShield,Mn as pillShield,cn as roundedRectShield,O as roundedRectTextConstraint,U as textConstraint,le as transposeImageData,wn as trapezoidDownShield,Cn as trapezoidUpShield,xn as triangleDownShield};
//# sourceMappingURL=https://unpkg.com/@americana/maplibre-shield-generator@0.0.6/dist/index.js.map