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 nt=Object.create;var ce=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var ot=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var dt=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of lt(e))!rt.call(t,l)&&l!==n&&ce(t,l,{get:()=>e[l],enumerable:!(i=it(e,l))||i.enumerable});return t};var ht=(t,e,n)=>(n=t!=null?nt(at(t)):{},dt(e||!t||!t.__esModule?ce(n,"default",{value:t,enumerable:!0}):n,t));var be=ot((Nt,ye)=>{"use strict";ye.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 ie=ht(be(),1),we=st,xe={red:0,orange:60,yellow:120,green:180,blue:240,purple:300};function st(t){var e,n=[],i=1,l;if(typeof t=="string")if(ie.default[t])n=ie.default[t].slice(),l="rgb";else if(t==="transparent")i=0,l="rgb",n=[0,0,0];else if(/^#[A-Fa-f0-9]+$/.test(t)){var a=t.slice(1),r=a.length,h=r<=4;i=1,h?(n=[parseInt(a[0]+a[0],16),parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16)],r===4&&(i=parseInt(a[3]+a[3],16)/255)):(n=[parseInt(a[0]+a[1],16),parseInt(a[2]+a[3],16),parseInt(a[4]+a[5],16)],r===8&&(i=parseInt(a[6]+a[7],16)/255)),n[0]||(n[0]=0),n[1]||(n[1]=0),n[2]||(n[2]=0),l="rgb"}else if(e=/^((?:rgb|hs[lvb]|hwb|cmyk?|xy[zy]|gray|lab|lchu?v?|[ly]uv|lms)a?)\s*\(([^\)]*)\)/.exec(t)){var s=e[1],f=s==="rgb",a=s.replace(/a$/,"");l=a;var r=a==="cmyk"?4:a==="gray"?1:3;n=e[2].trim().split(/\s*[,\/]\s*|\s+/).map(function(o,g){if(/%$/.test(o))return g===r?parseFloat(o)/100:a==="rgb"?parseFloat(o)*255/100:parseFloat(o);if(a[g]==="h"){if(/deg$/.test(o))return parseFloat(o);if(xe[o]!==void 0)return xe[o]}return parseFloat(o)}),s===a&&n.push(1),i=f||n[r]===void 0?1:n[r],n=n.slice(0,r)}else t.length>10&&/[0-9](?:\s|\/)/.test(t)&&(n=t.match(/([0-9]+)/g).map(function(m){return parseFloat(m)}),l=t.match(/([a-z])/ig).join("").toLowerCase());else isNaN(t)?Array.isArray(t)||t.length?(n=[t[0],t[1],t[2]],l="rgb",i=t.length===4?t[3]:1):t instanceof Object&&(t.r!=null||t.red!=null||t.R!=null?(l="rgb",n=[t.r||t.red||t.R||0,t.g||t.green||t.G||0,t.b||t.blue||t.B||0]):(l="hsl",n=[t.h||t.hue||t.H||0,t.s||t.saturation||t.S||0,t.l||t.lightness||t.L||t.b||t.brightness]),i=t.a||t.alpha||t.opacity||1,t.opacity!=null&&(i/=100)):(l="rgb",n=[t>>>16,(t&65280)>>>8,t&255]);return{space:l,values:n,alpha:i}}var q={name:"rgb",min:[0,0,0],max:[255,255,255],channel:["red","green","blue"],alias:["RGB"]};var Y={name:"hsl",min:[0,0,0],max:[360,100,100],channel:["hue","saturation","lightness"],alias:["HSL"],rgb:function(t){var e=t[0]/360,n=t[1]/100,i=t[2]/100,l,a,r,h,s,f=0;if(n===0)return s=i*255,[s,s,s];for(a=i<.5?i*(1+n):i+n-i*n,l=2*i-a,h=[0,0,0];f<3;)r=e+1/3*-(f-1),r<0?r++:r>1&&r--,s=6*r<1?l+(a-l)*6*r:2*r<1?a:3*r<2?l+(a-l)*(2/3-r)*6:l,h[f++]=s*255;return h}};q.hsl=function(t){var e=t[0]/255,n=t[1]/255,i=t[2]/255,l=Math.min(e,n,i),a=Math.max(e,n,i),r=a-l,h,s,f;return a===l?h=0:e===a?h=(n-i)/r:n===a?h=2+(i-e)/r:i===a&&(h=4+(e-n)/r),h=Math.min(h*60,360),h<0&&(h+=360),f=(l+a)/2,a===l?s=0:f<=.5?s=r/(a+l):s=r/(2-a-l),[h,s*100,f*100]};function X(t){Array.isArray(t)&&t.raw&&(t=String.raw(...arguments));var e,n,i,l=we(t);if(!l.space)return[];let a=l.space[0]==="h"?Y.min:q.min,r=l.space[0]==="h"?Y.max:q.max;return e=Array(3),e[0]=Math.min(Math.max(l.values[0],a[0]),r[0]),e[1]=Math.min(Math.max(l.values[1],a[1]),r[1]),e[2]=Math.min(Math.max(l.values[2],a[2]),r[2]),l.space[0]==="h"&&(e=Y.rgb(e)),e.push(Math.min(Math.max(l.alpha,0),1)),e}var ut='"sans-serif-condensed", "Arial Narrow", sans-serif',O=(t,e)=>`bold ${t}px ${e||ut}`,$=12;function le(t,e,n){return 255-t/255*(255-n)-(1-t/255)*(255-e)}function gt(t,e,n,i){e[i]=t[n],e[i+1]=t[n+1],e[i+2]=t[n+2],e[i+3]=t[n+3]}function pt(t,e,n,i,l,a){e[i]=le(t[n],l[0],a[0]),e[i+1]=le(t[n+1],l[1],a[1]),e[i+2]=le(t[n+2],l[2],a[2]),e[i+3]=t[n+3]}function ae(t,e,n,i,l,a){let r=t.createImageData(e.data.width,e.data.height),h=l||a?pt:gt,s=l?X(l):X("#000"),f=a?X(a):X("#fff");if(i)for(let m=0;m<e.data.height;m++)for(let u=0;u<e.data.width;u++){let g=((e.data.height-m-1)*e.data.width+u)*4,p=(m*e.data.width+u)*4;h(e.data.data,r.data,p,g,s,f)}else for(let m=0;m<e.data.data.length;m+=4)h(e.data.data,r.data,m,m,s,f);t.putImageData(r,0,n)}var L={Middle:"middle",Top:"top",Bottom:"bottom"},ft={top:0,bottom:0,left:0,right:0};function ke(t,e){var n=t.width,i=t.height,l=e.width,a=e.height;return n*i/Math.sqrt(n*n*a*a+i*i*l*l)}function mt(t,e){return{scale:ke(t,e),valign:L.Middle}}function St(t,e){return{scale:ke(t,{height:e.width/2,width:e.height}),valign:L.Top}}function ve(t,e){var n=t.height/e.height,i=t.width/e.width;return{scale:Math.min(i,n),valign:L.Middle}}function ct(t,e,n){let i=2;return n!==void 0&&n.radius!==void 0&&(i=n.radius),ve({width:t.width-i*(2-Math.sqrt(2)),height:t.height-i*(2-Math.sqrt(2))},e)}function Re(t,e){let n=t.width,i=t.height,l=e.width,a=e.height;return{scale:n*i/(i*l+n*a),valign:L.Middle}}function yt(t,e){return{scale:Re(t,e).scale,valign:L.Top}}function re(t,e,n,i,l,a=14){var r=t.px(n.top)||0,h=t.px(n.bottom)||0,s=t.px(n.left)||0,f=t.px(n.right)||0,m=t.px(a),u=t.gfxFactory.createGraphics(i);u.font=O($,t.options.shieldFont),u.textAlign="center",u.textBaseline="top";var o=u.measureText(e),g=o.width,p=o.actualBoundingBoxDescent,S=i.height-r-h,d=i.width-s-f,c=s+d/2;let y=Pe[l.constraintFunc],b=y({height:S,width:d},{height:p,width:g},l.options);var w=Math.min(m,$*b.scale);u.font=O(w,t.options.shieldFont),u.textAlign="center",u.textBaseline="top",o=u.measureText(e),p=o.actualBoundingBoxDescent;let x;switch(b.valign){case L.Top:x=r;break;case L.Bottom:x=r+S-p;break;case L.Middle:default:x=r+(S-p)/2;break}return{xBaseline:c,yBaseline:x,fontPx:w}}var bt={padding:{top:0,bottom:0,left:0,right:0},shapeBlank:{drawFunc:"rect",params:{fillColor:"white",strokeColor:"black"}}};function oe(t,e,n,i){n==null&&(n=bt);var l=n.padding||ft,a={constraintFunc:"rect"},r=14;return typeof n.textLayout!="undefined"&&(a=n.textLayout),typeof n.maxFontSize!="undefined"&&(r=Math.min(r,n.maxFontSize)),re(t,e,l,i,a,r)}function Ce(t,e,n,i){Be(t,e,i),e.fillText(n,i.xBaseline,i.yBaseline)}function de(t,e,n,i){Be(t,e,i),e.shadowColor=e.strokeStyle.toString(),e.shadowBlur=0,e.lineWidth=t.px(2),e.strokeText(n,i.xBaseline,i.yBaseline),e.shadowColor=null,e.shadowBlur=null}function Be(t,e,n){e.textAlign="center",e.textBaseline="top",e.font=O(n.fontPx,t.options.shieldFont)}function he(t,e,n){var i=t.emptySprite();return i.font=O(n,t.options.shieldFont),Math.ceil(i.measureText(e).width)}var Pe={};function N(t,e){Pe[t]=e}N("diamond",Re);N("ellipse",mt);N("rect",ve);N("roundedRect",ct);N("southHalfEllipse",St);N("triangleDown",yt);function xt(t,e,n){K(t,e,{fillColor:"white",strokeColor:"black",outlineWidth:1,radius:2,rectWidth:20});let i=n.fillColor,l=t.px(.5),a=t.shieldSize()/3-l;return e.beginPath(),e.arc(t.shieldSize()/2,t.shieldSize()/2,a,0,2*Math.PI,!1),e.fillStyle=i,e.strokeStyle=n.strokeColor,e.fill(),e.lineWidth=l,e.stroke(),20}function wt(t,e,n){K(t,e,{fillColor:"#006747",strokeColor:"white",outlineWidth:1,radius:2,rectWidth:20});let i=n.fillColor,l=t.px(.5),a=.15*t.shieldSize()+l,r=.7*t.shieldSize()-2*l,h=.4*t.shieldSize()+l,s=.45*t.shieldSize()-2*l;return e.beginPath(),e.rect(a,h,r,s),e.fillStyle=i,e.strokeStyle=n.strokeColor,e.fill(),e.lineWidth=l,e.stroke(),20}function Me(){W("branson",wt,20),W("paBelt",xt,20)}var We=20,Ie=34,ze=18;function I(t,e,n,i){if(se[i]!==void 0)return t.px(se[i]);let l=e.rectWidth==null?null:e.rectWidth,a=e.sideAngle==null?0:e.sideAngle,r=Math.tan(a);if(l==null){let h=he(t,n,t.px(ze))+t.px(2),s=t.px(We);switch(i){case"pentagon":let f=e.yOffset==null?0:e.yOffset;h+=(t.shieldSize()-t.px(f))*r/2;break;case"trapezoid":h+=t.shieldSize()*r/2;break;case"triangle":s+=t.px(2);break;case"diamond":case"hexagonHorizontal":s+=t.px(4);break}return Math.max(s,Math.min(t.px(Ie),h))}else return t.px(l)}function Tt(t,e,n,i){let l=n.fillColor==null?"white":n.fillColor,a=n.strokeColor==null?"black":n.strokeColor,r=I(t,n,i),h=t.px(1),s=r/2-h,f=t.shieldSize()/2-h;return e.beginPath(),e.ellipse(e.canvas.width/2,t.shieldSize()/2,s,f,0,0,2*Math.PI,!1),e.fillStyle=l,e.fill(),e.lineWidth=h,e.strokeStyle=a,e.stroke(),r}function Ae(t,e){var n=he(t,e,t.px(ze))+t.px(2),i=Math.max(t.px(We),Math.min(t.px(Ie),n));return t.gfxFactory.createGraphics({width:i,height:t.shieldSize()})}function K(t,e,n,i){let l=n.fillColor==null?"white":n.fillColor,a=n.strokeColor==null?"black":n.strokeColor,r=n.radius==null?0:n.radius,h=n.outlineWidth==null?1:n.outlineWidth,s=I(t,n,i),f=t.px(h),m=f/2,u=t.px(r),o=m,g=m+u,p=s-m-u,S=s-m,d=m,c=m+u,y=t.shieldSize()-m-u,b=t.shieldSize()-m;return e.beginPath(),e.moveTo(p,d),e.arcTo(S,d,S,c,u),e.arcTo(S,b,p,b,u),e.arcTo(o,b,o,y,u),e.arcTo(o,d,g,d,u),e.closePath(),e.lineWidth=f,e.fillStyle=l,e.fill(),a!=null&&(e.strokeStyle=a,e.stroke()),s}function kt(t,e,n,i){let l=n.yOffset==null?0:n.yOffset,a=n.fillColor==null?"white":n.fillColor,r=n.strokeColor==null?"black":n.strokeColor,h=n.radius==null?0:n.radius,s=n.outlineWidth==null?1:n.outlineWidth,f=I(t,n,i),m=t.px(s),u=m/2,o=t.px(h),g=t.px(l),p=u,S=f-u,d=u,c=t.shieldSize()-u,y=p+o,b=(p+S)/2,w=d+o,x=c-g,k=(2*p+b)/3,T=(b+2*S)/3,v=(x+c)/2,C=(v+2*c)/3;return e.beginPath(),e.moveTo(b,c),e.bezierCurveTo(k,C,p,v,p,x),e.arcTo(p,d,y,d,o),e.arcTo(S,d,S,w,o),e.lineTo(S,x),e.bezierCurveTo(S,v,T,C,b,c),e.closePath(),e.lineWidth=m,e.fillStyle=a,e.fill(),r!=null&&(e.strokeStyle=r,e.stroke()),f}function vt(t,e,n,i){let l=n.pointUp==null?!1:n.pointUp,a=n.fillColor==null?"white":n.fillColor,r=n.strokeColor==null?"black":n.strokeColor,h=n.outlineWidth==null?1:n.outlineWidth,s=l?-1:1,f=I(t,n,i),m=t.px(h),u=m/2,o=u,g=f-u,p=l?t.shieldSize()-u:u,S=l?u:t.shieldSize()-u,d=o+t.px(1),c=o+t.px(2.5),y=(o+g)/2,b=g-t.px(2.5),w=g-t.px(1),x=p+s*t.px(2),k=p+s*t.px(4.5),T=p+s*t.px(7),v=S-s*t.px(6),C=S-s*t.px(1),R=(o+y)/2,B=(y+g)/2;return e.beginPath(),e.moveTo(y,S),e.bezierCurveTo(R,C,o,v,o,T),e.bezierCurveTo(o,k,d,x,c,p),e.lineTo(b,p),e.bezierCurveTo(w,x,g,k,g,T),e.bezierCurveTo(g,v,B,C,y,S),e.closePath(),e.lineWidth=m,e.fillStyle=a,e.fill(),r!=null&&(e.strokeStyle=r,e.stroke()),f}function Rt(t,e,n,i){let l=n.pointUp==null?!1:n.pointUp,a=n.fillColor==null?"white":n.fillColor,r=n.strokeColor==null?"black":n.strokeColor,h=n.radius==null?0:n.radius,s=n.outlineWidth==null?1:n.outlineWidth,f=l?-1:1,m=I(t,n,i,"triangle"),u=t.px(s),o=u/2,g=t.px(h),p=o,S=m-o,d=l?t.shieldSize()-o:o,c=l?o:t.shieldSize()-o,y=p+g,b=(p+S)/2,w=S-g,x=d+f*g,k=Math.atan((b-y)/Math.abs(c-g-x)),T=Math.sin(k),v=Math.cos(k),C=Math.tan(k/2),R=Math.tan(Math.PI/4-k/2),B=y-g*v,P=b-g*R,D=b+g*R,z=w+g*v,F=x+f*g*C,M=x+f*g*T,A=c-f*g*(1-T);return e.beginPath(),e.moveTo(b,c),e.arcTo(P,c,B,M,g),e.arcTo(p,F,p,x,g),e.arcTo(p,d,y,d,g),e.arcTo(S,d,S,x,g),e.arcTo(S,F,z,M,g),e.arcTo(D,c,b,c,g),e.closePath(),e.lineWidth=u,e.fillStyle=a,e.fill(),r!=null&&(e.strokeStyle=r,e.stroke()),m}function Ct(t,e,n,i){let l=n.shortSideUp==null?!1:n.shortSideUp,a=n.sideAngle==null?0:n.sideAngle,r=n.fillColor==null?"white":n.fillColor,h=n.strokeColor==null?"black":n.strokeColor,s=n.radius==null?0:n.radius,f=n.outlineWidth==null?1:n.outlineWidth,m=l?-1:1,u=Math.sin(a),o=Math.cos(a),g=Math.tan(a),p=I(t,n,i,"trapezoid"),S=t.px(f),d=S/2,c=t.px(s),y=d,b=p-d,w=l?t.shieldSize()-d:d,x=l?d:t.shieldSize()-d,k=w+m*c*(1+u),T=x-m*c*(1-u),v=y+(k-w)*g,C=v+c*o,R=y+m*(T-w)*g,B=y+m*(x-w)*g,P=R+m*c*o,D=p-B,z=p-R,F=p-C;return e.beginPath(),e.moveTo(F,w),e.arcTo(b,w,z,T,c),e.arcTo(D,x,P,x,c),e.arcTo(B,x,v,k,c),e.arcTo(y,w,F,w,c),e.closePath(),e.lineWidth=S,e.fillStyle=r,e.fill(),h!=null&&(e.strokeStyle=h,e.stroke()),p}function Bt(t,e,n,i){let l=n.fillColor==null?"white":n.fillColor,a=n.strokeColor==null?"black":n.strokeColor,r=n.radius==null?0:n.radius,h=n.outlineWidth==null?1:n.outlineWidth,s=Z(t,"diamond"),f=I(t,n,i,"diamond"),m=t.px(h),u=m/2,o=t.px(r),g=u,p=f-u,S=u,d=s-u,c=(g+p)/2,y=(S+d)/2,b=Math.atan((c-o-g)/(d-o-y)),w=Math.sin(b),x=Math.cos(b),k=Math.tan(b/2),T=Math.tan(Math.PI/4-b/2),v=g+o*(1-x),C=c-o*x,R=c-o*T,B=c+o*T,P=c+o*x,D=p-o*(1-x),z=S+o*(1-w),F=y-o*w,M=y-o*k,A=y+o*k,_=y+o*w,H=d-o*(1-w);return e.beginPath(),e.moveTo(c,d),e.arcTo(R,d,v,_,o),e.arcTo(g,A,g,y,o),e.arcTo(g,M,C,z,o),e.arcTo(R,S,c,S,o),e.arcTo(B,S,D,F,o),e.arcTo(p,M,p,y,o),e.arcTo(p,A,P,H,o),e.arcTo(B,d,c,d,o),e.closePath(),e.lineWidth=m,e.fillStyle=l,e.fill(),a!=null&&(e.strokeStyle=a,e.stroke()),f}function Pt(t,e,n,i){let l=n.pointUp==null?!0:n.pointUp,a=n.yOffset==null?0:n.yOffset,r=n.sideAngle==null?0:n.sideAngle,h=n.fillColor==null?"white":n.fillColor,s=n.strokeColor==null?"black":n.strokeColor,f=n.radius1==null?0:n.radius1,m=n.radius2==null?0:n.radius2,u=n.outlineWidth==null?1:n.outlineWidth,o=l?-1:1,g=Math.sin(r),p=Math.cos(r),S=Math.tan(r),d=I(t,n,i,"pentagon"),c=t.px(u),y=c/2,b=t.px(f),w=t.px(m),x=t.px(a),k=y,T=d-y,v=l?t.shieldSize()-y:y,C=l?y:t.shieldSize()-y,R=C-o*x,B=k+o*(R-v)*S,P=(k+T)/2,D=T-o*(R-v)*S,z=Math.atan(x/(P-k)),F=(Math.PI/2-z+r)/2,M=Math.tan(F),A=(Math.PI/2-r)/2,_=Math.tan(A),H=k+b*M*g,J=B+w*_,E=D-w*_,V=T-b*M*g,Q=R-o*b*M*p;return e.beginPath(),e.moveTo(P,C),e.arcTo(k,R,H,Q,b),e.arcTo(B,v,J,v,w),e.lineTo(E,v),e.arcTo(D,v,V,Q,w),e.arcTo(T,R,P,C,b),e.closePath(),e.lineWidth=c,e.fillStyle=h,e.fill(),s!=null&&(e.strokeStyle=s,e.stroke()),d}function Dt(t,e,n,i){let l=n.yOffset==null?0:n.yOffset,a=n.fillColor==null?"white":n.fillColor,r=n.strokeColor==null?"black":n.strokeColor,h=n.radius==null?0:n.radius,s=n.outlineWidth==null?1:n.outlineWidth,f=I(t,n,i),m=t.px(s),u=m/2,o=t.px(h),g=t.px(l),p=u,S=f-u,d=u,c=t.shieldSize()-u,y=(p+S)/2,b=d+g,w=c-g,x=o*Math.tan(Math.PI/4-Math.asin(g/(y-p))/2),k=b+x,T=w-x;return e.beginPath(),e.moveTo(y,c),e.arcTo(p,w,p,T,o),e.arcTo(p,b,y,d,o),e.lineTo(y,d),e.arcTo(S,b,S,k,o),e.arcTo(S,w,y,c,o),e.lineTo(y,c),e.closePath(),e.lineWidth=m,e.fillStyle=a,e.fill(),r!=null&&(e.strokeStyle=r,e.stroke()),f}function Mt(t,e,n,i){let l=n.sideAngle==null?0:n.sideAngle,a=n.fillColor==null?"white":n.fillColor,r=n.strokeColor==null?"black":n.strokeColor,h=n.radius==null?0:n.radius,s=n.outlineWidth==null?1:n.outlineWidth,f=Math.sin(l),m=Math.cos(l),u=Math.tan(l),o=Math.tan(Math.PI/4-l/2),g=I(t,n,i,"hexagonHorizontal"),p=t.px(s),S=p/2,d=t.px(h),c=S,y=g-S,b=S,w=t.shieldSize()-S,x=(b+w)/2,k=b+d*o*m,T=x-d*f,v=x+d*f,C=w-d*o*m,R=c+(x-T)*u,B=c+(x-b)*u,P=y-(x-b)*u,D=y-(x-T)*u,z=B-d*o*f,F=B+d*o,M=P-d*o,A=P+d*o*f;return e.beginPath(),e.moveTo(F,b),e.arcTo(P,b,A,k,d),e.arcTo(y,x,D,v,d),e.arcTo(P,w,M,w,d),e.arcTo(B,w,z,C,d),e.arcTo(c,x,R,T,d),e.arcTo(B,b,F,b,d),e.closePath(),e.lineWidth=p,e.fillStyle=a,e.fill(),r!=null&&(e.strokeStyle=r,e.stroke()),g}function Ft(t,e,n,i){let l=n.yOffset==null?0:n.yOffset,a=n.sideAngle==null?0:n.sideAngle,r=n.fillColor==null?"white":n.fillColor,h=n.strokeColor==null?"black":n.strokeColor,s=n.radius==null?0:n.radius,f=n.outlineWidth==null?1:n.outlineWidth,m=Math.sin(a),u=Math.cos(a),o=Math.tan(a),g=I(t,n,i),p=t.px(f),S=p/2,d=t.px(s),c=t.px(l),y=S,b=g-S,w=S,x=t.shieldSize()-S,k=y+d*o*m,T=(y+b)/2,v=b-d*o*m,C=w+c,R=(w+x)/2,B=x-c,P=y+(R-C)*o,D=b-(R-C)*o,z=R-d*o*u,F=R+d*o*u,M=Math.atan(c/(T-P)),A=Math.sin(M),_=Math.cos(M),H=(Math.PI/2-a-M)/2,J=Math.cos(H),E=d*Math.cos(a+H)/J,V=d*Math.sin(a+H)/J,Q=P+E-d*u,Je=P+E-d*A,Qe=D-E+d*A,Ye=D-E+d*u,Ke=C+V-d*_,Ze=C+V-d*m,et=B-V+d*m,tt=B-V+d*_;return e.beginPath(),e.moveTo(T,x),e.arcTo(P,B,Q,et,d),e.arcTo(y,R,k,z,d),e.arcTo(P,C,Je,Ke,d),e.lineTo(T,w),e.arcTo(D,C,Ye,Ze,d),e.arcTo(b,R,v,F,d),e.arcTo(D,B,Qe,tt,d),e.lineTo(T,x),e.closePath(),e.lineWidth=p,e.fillStyle=r,e.fill(),h!=null&&(e.strokeStyle=h,e.stroke()),g}function Z(t,e){switch(e){case"diamond":return t.shieldSize()+t.px(4);default:return t.shieldSize()}}function Le(t,e,n,i,l){return _e[e](t,n,i,l)}var _e={},se={};function W(t,e,n){_e[t]=e,n!==void 0&&(se[t]=n)}W("diamond",Bt);W("ellipse",Tt);W("escutcheon",kt);W("fishhead",vt);W("hexagonVertical",Dt);W("hexagonHorizontal",Mt);W("octagonVertical",Ft);W("pentagon",Pt);W("roundedRectangle",K);W("trapezoid",Ct);W("triangle",Rt);Me();var Wt={constraintFunc:"rect"};function He(t,e,n){n.bannerTextColor?e.fillStyle=n.bannerTextColor:e.fillStyle=t.options.bannerTextColor,Ge(t,e,n,It)}function Oe(t,e,n){n.bannerTextHaloColor?e.strokeStyle=e.shadowColor=n.bannerTextHaloColor:e.strokeStyle=e.shadowColor=t.options.bannerTextHaloColor,Ge(t,e,n,zt)}function Ge(t,e,n,i){if(!(n==null||typeof n.banners=="undefined"))for(var l=0;l<n.banners.length;l++)i(t,e,n.banners[l],l)}function ee(t){return t==null||typeof t.banners=="undefined"?0:t.banners.length}function It(t,e,n,i){Ue(t,e,n,i,!0)}function zt(t,e,n,i){Ue(t,e,n,i,!1)}function Ue(t,e,n,i,l){let a={top:t.options.bannerPadding,bottom:0,left:0,right:0},r={width:e.canvas.width,height:t.px(t.options.bannerHeight-t.options.bannerPadding)},h=re(t,n,a,r,Wt);e.font=O(h.fontPx,t.options.shieldFont),e.textBaseline="top",e.textAlign="center",l?e.fillText(n,h.xBaseline,h.yBaseline+i*t.px(t.options.bannerHeight-t.options.bannerPadding)):(e.shadowBlur=0,e.lineWidth=t.px(2),e.strokeText(n,h.xBaseline,h.yBaseline+i*t.px(t.options.bannerHeight-t.options.bannerPadding)),e.shadowColor=null,e.shadowBlur=null)}function At(t,e,n){return{width:e.width,height:e.height+n*t.px(t.options.bannerHeight+t.options.bannerPadding)}}function ue(t){return t!==null&&t.length!==0&&t.length<=6}function Ee(t,e,n){var i=null,l,a=0,r;if(Array.isArray(e.spriteBlank))for(var h=0;h<e.spriteBlank.length&&(i=t.spriteRepo.getSprite(e.spriteBlank[h]),r=At(t,i.data,a),l=oe(t,n.ref,e,r),!(l.fontPx>t.px($)));h++);else i=t.spriteRepo.getSprite(e.spriteBlank);return i}function Lt(t){return t!=null&&typeof t.textColor!="undefined"?t.textColor:"black"}function Ve(t){return typeof t.shapeBlank!="undefined"?(e,n,i)=>Le(e,t.shapeBlank.drawFunc,n,t.shapeBlank.params,i):Ae}function _t(t,e,n,i){let a=ee(n)*t.px(t.options.bannerHeight);e.save(),e.translate(0,a),Ve(n)(t,e,i.ref),e.restore()}function Ht(t,e){return typeof e.shapeBlank!="undefined"?Z(t,e.shapeBlank.drawFunc):t.shieldSize()}function Ot(t,e,n,i){var l=ee(n),a=null,r=Ee(t,n,i);let h=l*t.px(t.options.bannerHeight);if(r==null?(e.translate(0,h),Ve(n)(t,e,i.ref),e.translate(0,-h),a={width:e.canvas.width,height:Ht(t,n)}):a={width:r.data.width,height:r.data.height},n.notext)return e;var s=oe(t,i.ref,n,a);return s.yBaseline+=l*t.px(t.options.bannerHeight),typeof t.options.SHIELD_TEXT_HALO_COLOR_OVERRIDE!="undefined"?(e.strokeStyle=options.SHIELD_TEXT_HALO_COLOR_OVERRIDE,de(t,e,i.ref,s)):n.textHaloColor&&(e.strokeStyle=n.textHaloColor,de(t,e,i.ref,s)),e.fillStyle=Lt(n),Ce(t,e,i.ref,s),t.options.SHIELD_TEXT_BBOX_COLOR&&(e.strokeStyle=t.options.SHIELD_TEXT_BBOX_COLOR,e.lineWidth=t.px(1),e.strokeRect(t.px(n.padding.left-.5),l*t.px(t.options.bannerHeight)+t.px(n.padding.top-.5),a.width-t.px(n.padding.left+n.padding.right-1),a.height-t.px(n.padding.top+n.padding.bottom-1))),e}function Xe(t,e,n){let i=ge(t,e);i==null&&(console.warn("Didn't produce a shield for",JSON.stringify(e)),i=t.gfxFactory.createGraphics({width:1,height:1})),Ne(t,n,i)}function Ne(t,e,n){let i=n.getImageData(0,0,n.canvas.width,n.canvas.height);t.spriteRepo.putSprite(e,{width:n.canvas.width,height:n.canvas.height,data:i.data},t.px(1))}function qe(t,e){Ne(t,e,t.emptySprite())}function $e(t,e){return e.refsByName&&t.name&&e.refsByName[t.name]?e.refsByName[t.name]:t.ref}function Gt(t,e){var n=t[e.network];if(e==null)return null;if(n==null)return console.debug("Generic shield for",JSON.stringify(e)),ue(e.ref)?t.default:null;var i=$e(e,n);return n.overrideByRef&&(n={...n,...n.overrideByRef[i]}),n.overrideByName&&(n={...n,...n.overrideByName[e.name||""]}),!ue(i)&&"noref"in n&&(n=n.noref,n.notext=!0),!ue(i)&&!n.notext&&!(n.refsByName&&e.name)?null:n}function Ut(t){let e=parseInt(t,10);if(isNaN(e))return t;let n="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 n=n.replace("DCCCC","CM").replace("CCCC","CD").replace("LXXXX","XC").replace("XXXX","XL").replace("VIIII","IX").replace("IIII","IV"),n+t.slice(e.toString().length)}function Et(t,e,n){let i=Math.max(t.shieldSize(),I(t,e.shapeBlank.params,n,e.shapeBlank.drawFunc)),l=Z(t,e.shapeBlank.drawFunc);return{width:i,height:l}}function ge(t,e){let n=Gt(t.shieldDef,e);if(n==null)return null;e.ref=$e(e,n);let i=ee(n),l=Ee(t,n,e),a=t.shieldSize(),r=t.shieldSize();if(l==null){if(typeof n.shapeBlank!="undefined"){let f=Et(t,n,e.ref);a=f.width,r=f.height}}else a=l.data.width,r=l.data.height;let h=i*t.px(t.options.bannerHeight);r+=h;let s=t.gfxFactory.createGraphics({width:a,height:r});return e.ref&&n.numberingSystem==="roman"&&(e.ref=Ut(e.ref)),Oe(t,s,n),l==null?_t(t,s,n,e):ae(s,l,h,n.verticalReflect,n.colorLighten,n.colorDarken),Ot(t,s,n,e),He(t,s,n),s}function je(){return(typeof window!="undefined"&&window.devicePixelRatio)>1?2:1}var te=class{createGraphics(e){var n=document.createElement("canvas").getContext("2d"),n=document.createElement("canvas").getContext("2d",{willReadFrequently:!0});return n.imageSmoothingQuality="high",n.textAlign="center",n.textBaseline="top",n.canvas.width=e.width,n.canvas.height=e.height,n}pixelRatio(){return je()}};var pe=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)}},fe=class{constructor(e){this.map=e}getSprite(e){return this.map.style.getImage(e)}putSprite(e,n,i){this.map.addImage(e,n,{pixelRatio:i})}},j=class{constructor(e){this._shieldPredicate=()=>!0;this._networkPredicate=()=>!0;this._shieldDefCallbacks=[];this._routeParser=e,this._renderContext=new pe,this._renderContext.gfxFactory=new te}setShields(e){this._renderContext.options=e.options,this._renderContext.shieldDef=e.networks,this._shieldDefCallbacks.forEach(n=>n(e.networks))}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.renderOnRepository(new fe(e)),e.on("styleimagemissing",this.getStyleImageMissingHandler()),this}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 n=this._routeParser.parse(e.id);if(!this._networkPredicate(n.network)){qe(this._renderContext,e.id);return}n&&Xe(this._renderContext,n,e.id)}catch(n){console.error(`Exception while loading image \u2018${e==null?void 0:e.id}\u2019:
`,n)}}}getGraphicForRoute(e,n,i){return ge(this._renderContext,{network:e,ref:n,name:i})}emptySprite(){return this._renderContext.emptySprite()}createGraphics(e){return this._renderContext.gfxFactory.createGraphics(e)}pixelRatio(){return this._renderContext.px(1)}},me=class extends j{constructor(e,n){super(n),this.setShields(e)}},Se=class extends j{constructor(e,n){super(n),this.setShieldURL(e)}async setShieldURL(e){await fetch(e).then(n=>n.json()).then(n=>super.setShields(n)).catch(n=>console.error(n))}},ne=class{constructor(){this.sprites={}}getSprite(e){return this.sprites[e]}hasSprite(e){return e in this.sprites}putSprite(e,n){this.sprites[e]=n}},pn=new ne;function G(t){return{constraintFunc:"roundedRect",options:{radius:t}}}function U(t){return{constraintFunc:t}}function Vt(t,e,n,i){return n=n!=null?n:e,{shapeBlank:{drawFunc:"ellipse",params:{fillColor:t,strokeColor:e,rectWidth:i}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:n}}function mn(t,e,n){return Vt(t,e,n,20)}function Sn(t,e,n,i,l){return n=n!=null?n:e,l=l!=null?l:2,{shapeBlank:{drawFunc:"roundedRectangle",params:{fillColor:t,strokeColor:e,rectWidth:i,radius:l}},textLayout:G(l),padding:{left:3,right:3,top:3,bottom:3},textColor:n}}function cn(t,e,n,i,l,a){return i=i!=null?i:n,l=l!=null?l:0,{shapeBlank:{drawFunc:"escutcheon",params:{yOffset:t,fillColor:e,strokeColor:n,rectWidth:a,radius:l,outlineWidth:1}},textLayout:G(l),padding:{left:2,right:2,top:2,bottom:0+t/2},textColor:i}}function yn(t,e,n,i){return n=n!=null?n:e,{shapeBlank:{drawFunc:"fishhead",params:{fillColor:t,strokeColor:e,rectWidth:i,outlineWidth:1}},textLayout:U("roundedRect"),padding:{left:3,right:3,top:2,bottom:6},textColor:n}}function bn(t,e,n,i,l){return n=n!=null?n:e,i=i!=null?i:2,{shapeBlank:{drawFunc:"triangle",params:{pointUp:!1,fillColor:t,strokeColor:e,rectWidth:l,radius:i}},textLayout:U("triangleDown"),padding:{left:1,right:1,top:2,bottom:1},textColor:n}}function xn(t,e,n,i,l,a){let r=t*Math.PI/180;return i=i!=null?i:n,l=l!=null?l:0,{shapeBlank:{drawFunc:"trapezoid",params:{sideAngle:r,fillColor:e,strokeColor:n,rectWidth:a,radius:l}},textLayout:G(l),padding:{left:2+10*Math.tan(r),right:2+10*Math.tan(r),top:2,bottom:4},textColor:i}}function wn(t,e,n,i,l,a){let r=t*Math.PI/180;return i=i!=null?i:n,l=l!=null?l:0,{shapeBlank:{drawFunc:"trapezoid",params:{shortSideUp:!0,sideAngle:r,fillColor:e,strokeColor:n,rectWidth:a,radius:l}},textLayout:G(l),padding:{left:2+10*Math.tan(r),right:2+10*Math.tan(r),top:4,bottom:2},textColor:i}}function Tn(t,e,n,i,l){return n=n!=null?n:e,i=i!=null?i:2,{shapeBlank:{drawFunc:"diamond",params:{fillColor:t,strokeColor:e,radius:i,rectWidth:l}},textLayout:U("diamond"),padding:{left:1,right:1,top:1,bottom:1},textColor:n}}function kn(t,e,n,i,l,a,r,h){let s=e*Math.PI/180;return l=l!=null?l:i,a=a!=null?a:2,r=r!=null?r:0,{shapeBlank:{drawFunc:"pentagon",params:{yOffset:t,sideAngle:s,fillColor:n,strokeColor:i,radius1:a,radius2:r,rectWidth:h}},textLayout:{constraintFunc:"rect"},padding:{left:2+(20-t)*Math.tan(s)/2,right:2+(20-t)*Math.tan(s)/2,top:1+t/2,bottom:3},textColor:l}}function vn(t,e,n,i,l,a,r){return i=i!=null?i:n,l=l!=null?l:2,a=a!=null?a:2,{shapeBlank:{drawFunc:"pentagon",params:{pointUp:!1,yOffset:t,sideAngle:0,fillColor:e,strokeColor:n,radius1:l,radius2:a,rectWidth:r}},textLayout:G(a),padding:{left:2,right:2,top:2,bottom:1+t},textColor:i}}function Rn(t,e,n,i,l,a,r){return i=i!=null?i:n,l=l!=null?l:2,a=a!=null?a:2,{shapeBlank:{drawFunc:"pentagon",params:{pointUp:!0,yOffset:t,sideAngle:0,fillColor:e,strokeColor:n,radius1:l,radius2:a,rectWidth:r}},textLayout:G(a),padding:{left:2,right:2,top:1+t,bottom:2},textColor:i}}function Cn(t,e,n,i,l,a){return i=i!=null?i:n,l=l!=null?l:2,{shapeBlank:{drawFunc:"hexagonVertical",params:{yOffset:t,fillColor:e,strokeColor:n,radius:l,rectWidth:a}},textLayout:G(l),padding:{left:2,right:2,top:1+t,bottom:1+t},textColor:i}}function Bn(t,e,n,i,l,a){let r=t*Math.PI/180;return i=i!=null?i:n,l=l!=null?l:2,{shapeBlank:{drawFunc:"hexagonHorizontal",params:{sideAngle:r,fillColor:e,strokeColor:n,radius:l,rectWidth:a}},textLayout:U("ellipse"),padding:{left:3,right:3,top:2,bottom:2},textColor:i}}function Pn(t,e,n,i,l,a,r){let h=e*Math.PI/180;return l=l!=null?l:i,a=a!=null?a:2,{shapeBlank:{drawFunc:"octagonVertical",params:{yOffset:t,sideAngle:h,fillColor:n,strokeColor:i,radius:a,rectWidth:r}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:l}}function Dn(t,e,n,i){return n=n!=null?n:e,{shapeBlank:{drawFunc:"roundedRectangle",params:{fillColor:t,strokeColor:e,rectWidth:i,radius:10}},textLayout:U("ellipse"),padding:{left:2,right:2,top:2,bottom:2},textColor:n}}function Mn(t,e,n){return{banners:e,bannerTextColor:n,...t}}function Fn(t,e){return{notext:!0,shapeBlank:{drawFunc:"paBelt",params:{fillColor:t,strokeColor:e}}}}function Wn(t,e){return{notext:!0,shapeBlank:{drawFunc:"branson",params:{fillColor:t,strokeColor:e}}}}export{j as AbstractShieldRenderer,ne as InMemorySpriteRepository,me as ShieldRenderer,Se as URLShieldRenderer,Mn as banneredShield,Wn as bransonRouteShield,mn as circleShield,Tn as diamondShield,cn as escutcheonDownShield,yn as fishheadDownShield,je as getDOMPixelRatio,Bn as hexagonHorizontalShield,Cn as hexagonVerticalShield,vn as homePlateDownShield,Rn as homePlateUpShield,Pn as octagonVerticalShield,Vt as ovalShield,Fn as paBeltShield,kn as pentagonUpShield,Dn as pillShield,Sn as roundedRectShield,G as roundedRectTextConstraint,U as textConstraint,ae as transposeImageData,xn as trapezoidDownShield,wn as trapezoidUpShield,bn as triangleDownShield};
//# sourceMappingURL=https://unpkg.com/@americana/maplibre-shield-generator@0.0.5/dist/index.js.map