import{hh as ke,br as ve,u as Ye,bV as Ze,a as Je,m as Ke}from"./index.6c049565.js";import{I as _e,L as oe}from"./enums.54326430.js";import{f as Be,t as le,n as se,a as Ce,h as We,r as Se,P as Y,b as ge}from"./GeometryUtils.4f19e772.js";import{t as Ee}from"./Rect.95b0fd2e.js";import{o as Re}from"./config.82550349.js";import{l as ie,m as k,o as Oe,n as be,p as Qe,u as Pe,a as ee}from"./StyleDefinition.d56936e4.js";import{t as D,s as Xe}from"./Geometry.d049a63c.js";import{r as et,c as tt,n as st,_ as it,i as rt}from"./TileClipper.7297efa2.js";import{t as E,T as nt,m as at,l as ot}from"./StyleRepository.43c45b26.js";import{x as Fe}from"./earcut.afc1d357.js";import{C as lt}from"./BidiEngine.d8bba3fc.js";import"./enums.0295eb81.js";import"./GeometryUtils.51c4032a.js";import"./enums.2d9e6f64.js";import"./VertexElementDescriptor.1fdca6da.js";import"./colorUtils.bb6424b7.js";function ht(u){return u===746||u===747||!(u<4352)&&(u>=12704&&u<=12735||u>=12544&&u<=12591||u>=65072&&u<=65103&&!(u>=65097&&u<=65103)||u>=63744&&u<=64255||u>=13056&&u<=13311||u>=11904&&u<=12031||u>=12736&&u<=12783||u>=12288&&u<=12351&&!(u>=12296&&u<=12305||u>=12308&&u<=12319||u===12336)||u>=13312&&u<=19903||u>=19968&&u<=40959||u>=12800&&u<=13055||u>=12592&&u<=12687||u>=43360&&u<=43391||u>=55216&&u<=55295||u>=4352&&u<=4607||u>=44032&&u<=55215||u>=12352&&u<=12447||u>=12272&&u<=12287||u>=12688&&u<=12703||u>=12032&&u<=12255||u>=12784&&u<=12799||u>=12448&&u<=12543&&u!==12540||u>=65280&&u<=65519&&!(u===65288||u===65289||u===65293||u>=65306&&u<=65310||u===65339||u===65341||u===65343||u>=65371&&u<=65503||u===65507||u>=65512&&u<=65519)||u>=65104&&u<=65135&&!(u>=65112&&u<=65118||u>=65123&&u<=65126)||u>=5120&&u<=5759||u>=6320&&u<=6399||u>=65040&&u<=65055||u>=19904&&u<=19967||u>=40960&&u<=42127||u>=42128&&u<=42191)}function ct(u){return!(u<11904)&&(u>=12704&&u<=12735||u>=12544&&u<=12591||u>=65072&&u<=65103||u>=63744&&u<=64255||u>=13056&&u<=13311||u>=11904&&u<=12031||u>=12736&&u<=12783||u>=12288&&u<=12351||u>=13312&&u<=19903||u>=19968&&u<=40959||u>=12800&&u<=13055||u>=65280&&u<=65519||u>=12352&&u<=12447||u>=12272&&u<=12287||u>=12032&&u<=12255||u>=12784&&u<=12799||u>=12448&&u<=12543||u>=65040&&u<=65055||u>=42128&&u<=42191||u>=40960&&u<=42127)}function ut(u){switch(u){case 10:case 32:case 38:case 40:case 41:case 43:case 45:case 47:case 173:case 183:case 8203:case 8208:case 8211:case 8231:return!0}return!1}function ze(u){switch(u){case 9:case 10:case 11:case 12:case 13:case 32:return!0}return!1}const H=24,je=17;class qe{constructor(e,t,i,s,r,n,a){this._glyphItems=e,this._maxWidth=t,this._lineHeight=i,this._letterSpacing=s,this._hAnchor=r,this._vAnchor=n,this._justify=a}getShaping(e,t,i){const s=this._letterSpacing,r=this._lineHeight,n=this._justify,a=this._maxWidth,o=[];let c=0,h=0;const d=e.length;for(let g=0;g0&&(l=c/Math.max(1,Math.ceil(c/a)));const f=e.includes("\u200B"),y=[];for(let g=0;gb&&ze(o[_].codePoint);)o[_].glyphMosaicItem=null,--_;if(b<=_){const M=o[b].x;for(let P=b;P<=_;P++)o[P].x-=M,o[P].y=h;let B=o[_].x;o[_].glyphMosaicItem&&(B+=o[_].glyphMosaicItem.metrics.advance),w=Math.max(B,w),n&&this._applyJustification(o,b,_)}m=I,h+=x}if(o.length>0){const g=p.length-1,I=(n-this._hAnchor)*w;let b=(-this._vAnchor*(g+1)+.5)*r;t&&g&&(b+=g*r);for(const _ of o)_.x+=I,_.y+=b}return o.filter(g=>g.glyphMosaicItem)}static getTextBox(e,t){if(!e.length)return null;let i=1/0,s=1/0,r=0,n=0;for(const a of e){const o=a.glyphMosaicItem.metrics.advance,c=a.x,h=a.y-je,d=c+o,l=h+t;i=Math.min(i,c),r=Math.max(r,d),s=Math.min(s,h),n=Math.max(n,l)}return{x:i,y:s,width:r-i,height:n-s}}static getBox(e){if(!e.length)return null;let t=1/0,i=1/0,s=0,r=0;for(const n of e){const{height:a,left:o,top:c,width:h}=n.glyphMosaicItem.metrics,d=n.x,l=n.y-(a-Math.abs(c)),f=d+h+o,y=l+a;t=Math.min(t,d),s=Math.max(s,f),i=Math.min(i,l),r=Math.max(r,y)}return{x:t,y:i,width:s-t,height:r-i}}static addDecoration(e,t){const i=e.length;if(i===0)return;const s=3;let r=e[0].x+e[0].glyphMosaicItem.metrics.left,n=e[0].y;for(let o=1;o=0&&a,f=s.allowOverlap&&s.ignorePlacement?null:[],y=[],p=4,w=!l;let x=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,g=x,I=m;const b=(l||a)&&o,_=s.size/H;let M=!1;for(const T of t)if(T.vertical){M=!0;break}let B,P=0,L=0;if(!l&&M){const T=qe.getTextBox(t,s.lineHeight*H);switch(s.anchor){case k.LEFT:P=T.height/2,L=-T.width/2;break;case k.RIGHT:P=-T.height/2,L=T.width/2;break;case k.TOP:P=T.height/2,L=T.width/2;break;case k.BOTTOM:P=-T.height/2,L=-T.width/2;break;case k.TOP_LEFT:P=T.height;break;case k.BOTTOM_LEFT:L=-T.width;break;case k.TOP_RIGHT:L=T.width;break;case k.BOTTOM_RIGHT:P=-T.height}}P+=s.offset[0]*H,L+=s.offset[1]*H;for(const T of t){const C=T.glyphMosaicItem;if(!C||C.rect.isEmpty)continue;const A=C.rect,v=C.metrics,R=C.page;if(f&&w){if(B!==void 0&&B!==T.y){let S,F,$,G;M?(S=-I+P,F=x+L,$=I-g,G=m-x):(S=x+P,F=g+L,$=m-x,G=I-g);const j={xTile:e.x,yTile:e.y,dxPixels:S*_-c,dyPixels:F*_-c,hard:!s.optional,partIndex:1,width:$*_+2*c,height:G*_+2*c,angle:n,minLod:X,maxLod:se};f.push(j),x=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,g=x,I=m}B=T.y}const Z=[];if(l){const S=.5*C.metrics.width,F=(T.x+v.left-p+S)*_*he;if(h=this._placeGlyph(e,h,F,i,e.segment,1,T.vertical,R,Z),o&&(h=this._placeGlyph(e,h,F,i,e.segment,-1,T.vertical,R,Z)),h>=Te)break}else Z.push(new me(r,d,d,R,!1)),a&&o&&Z.push(new me(r,d+le,d+le,R,!1));const N=T.x+v.left,W=T.y-je-v.top,J=N+v.width,we=W+v.height;let O,U,ce,ue,Q,fe,Ve,Ae;if(!l&&M)if(T.vertical){const S=(N+J)/2-v.height/2,F=(W+we)/2+v.width/2;O=new D(-F-p+P,S-p+L),U=new D(O.x+A.width,O.y+A.height),ce=new D(O.x,U.y),ue=new D(U.x,O.y)}else O=new D(-W+p+P,N-p+L),U=new D(O.x-A.height,O.y+A.width),ce=new D(U.x,O.y),ue=new D(O.x,U.y);else O=new D(N-p+P,W-p+L),U=new D(O.x+A.width,O.y+A.height),ce=new D(O.x,U.y),ue=new D(U.x,O.y);for(const S of Z){let F,$,G,j;if(S.alternateVerticalGlyph){if(!Q){const q=(W+we)/2+L;Q=new D((N+J)/2+P-v.height/2-p,q+v.width/2+p),fe=new D(Q.x+A.height,Q.y-A.width),Ve=new D(fe.x,Q.y),Ae=new D(Q.x,fe.y)}F=Q,$=Ve,G=Ae,j=fe}else F=O,$=ce,G=ue,j=U;const de=W,Me=we,xe=S.glyphAngle+n;if(xe!==0){const q=Math.cos(xe),ye=Math.sin(xe);F=F.clone(),$=$.clone(),G=G.clone(),j=j.clone(),F.rotate(q,ye),j.rotate(q,ye),$.rotate(q,ye),G.rotate(q,ye)}let ne=0,ae=256;if(l&&M?T.vertical?S.alternateVerticalGlyph?(ne=32,ae=96):(ne=224,ae=32):(ne=224,ae=96):(ne=192,ae=64),y.push(new Ue(F,G,$,j,A,S.labelAngle,ne,ae,S.anchor,S.minzoom,S.maxzoom,S.page)),f&&(!b||this._legible(S.labelAngle))){if(w)Nm&&(m=J),Me>I&&(I=Me);else if(S.minzoom=Te)return null;if(f&&w){let T,C,A,v;M?(T=-I+P,C=x+L,A=I-g,v=m-x):(T=x+P,C=g+L,A=m-x,v=I-g);const R={xTile:e.x,yTile:e.y,dxPixels:T*_-c,dyPixels:C*_-c,hard:!s.optional,partIndex:1,width:A*_+2*c,height:v*_+2*c,angle:n,minLod:X,maxLod:se};f.push(R)}const V=new $e(y);return f&&f.length>0&&(V.textColliders=f),V}_legible(e){const t=We(e);return t<65||t>=193}_placeGlyph(e,t,i,s,r,n,a,o,c){let h=n;const d=h<0?Ce(e.angle+le,Se):e.angle;let l=0;i<0&&(h*=-1,i*=-1,l=le),h>0&&++r;let f=new D(e.x,e.y),y=s[r],p=se;if(s.length<=r)return p;for(;;){const w=y.x-f.x,x=y.y-f.y,m=Math.sqrt(w*w+x*x),g=Math.max(i/m,t),I=w/m,b=x/m,_=Ce(Math.atan2(b,I)+l,Se);if(c.push(new me(f,d,_,o,!1,g,p)),a&&c.push(new me(f,d,_,o,!0,g,p)),g<=t)return g;f=y.clone();do{if(r+=h,s.length<=r||r<0)return g;y=s[r]}while(f.isEqual(y));let M=y.x-f.x,B=y.y-f.y;const P=Math.sqrt(M*M+B*B);M*=m/P,B*=m/P,f.x-=M,f.y-=B,p=g}}}var re;(function(u){u[u.moveTo=1]="moveTo",u[u.lineTo=2]="lineTo",u[u.close=7]="close"})(re||(re={}));class dt{constructor(e,t){this.values={},this._geometry=void 0,this._pbfGeometry=null;const i=t.keys,s=t.values,r=e.asUnsafe();for(;r.next();)switch(r.tag()){case 1:this.id=r.getUInt64();break;case 2:{const n=r.getMessage().asUnsafe(),a=this.values;for(;!n.empty();){const o=n.getUInt32(),c=n.getUInt32();a[i[o]]=s[c]}n.release();break}case 3:this.type=r.getUInt32();break;case 4:this._pbfGeometry=r.getMessage();break;default:r.skip()}}getGeometry(e){if(this._geometry!==void 0)return this._geometry;if(!this._pbfGeometry)return null;const t=this._pbfGeometry.asUnsafe();let i,s;this._pbfGeometry=null,e?e.reset(this.type):i=[];let r,n=re.moveTo,a=0,o=0,c=0;for(;!t.empty();){if(a===0){const h=t.getUInt32();n=7&h,a=h>>3}switch(a--,n){case re.moveTo:o+=t.getSInt32(),c+=t.getSInt32(),e?e.moveTo(o,c):i&&(s&&i.push(s),s=[],s.push(new D(o,c)));break;case re.lineTo:o+=t.getSInt32(),c+=t.getSInt32(),e?e.lineTo(o,c):s&&s.push(new D(o,c));break;case re.close:e?e.close():s&&!s[0].equals(o,c)&&s.push(s[0].clone());break;default:throw t.release(),new Error("Invalid path operation")}}return e?r=e.result():i&&(s&&i.push(s),r=i),t.release(),this._geometry=r,r}}class te extends E{constructor(){super(12)}add(e,t,i){const s=this.array;s.push(e),s.push(t),s.push(i)}}class Le{constructor(e){this.extent=4096,this.keys=[],this.values=[],this._pbfLayer=e.clone();const t=e.asUnsafe();for(;t.next();)switch(t.tag()){case 1:this.name=t.getString();break;case 3:this.keys.push(t.getString());break;case 4:this.values.push(t.processMessage(Le._parseValue));break;case 5:this.extent=t.getUInt32();break;default:t.skip()}}getData(){return this._pbfLayer}static _parseValue(e){for(;e.next();)switch(e.tag()){case 1:return e.getString();case 2:return e.getFloat();case 3:return e.getDouble();case 4:return e.getInt64();case 5:return e.getUInt64();case 6:return e.getSInt64();case 7:return e.getBool();default:e.skip()}return null}}class xt extends E{constructor(e){super(e)}add(e,t,i,s,r,n,a,o,c,h,d,l){const f=this.array;let y=E.i1616to32(e,t);f.push(y);const p=31;y=E.i8888to32(Math.round(p*i),Math.round(p*s),Math.round(p*r),Math.round(p*n)),f.push(y),y=E.i8888to32(Math.round(p*a),Math.round(p*o),Math.round(p*c),Math.round(p*h)),f.push(y),y=E.i1616to32(d,0),f.push(y),l&&f.push(...l)}}class yt extends E{constructor(e){super(e)}add(e,t,i){const s=this.array;s.push(E.i1616to32(e,t)),i&&s.push(...i)}}class gt extends E{constructor(e){super(e)}add(e,t,i,s,r,n,a){const o=this.array,c=this.index;let h=E.i1616to32(e,t);o.push(h);const d=15;return h=E.i8888to32(Math.round(d*i),Math.round(d*s),r,n),o.push(h),a&&o.push(...a),c}}class Ge extends E{constructor(e){super(e)}add(e,t,i,s,r,n,a,o,c,h,d,l){const f=this.array;let y=E.i1616to32(e,t);f.push(y),y=E.i1616to32(Math.round(8*i),Math.round(8*s)),f.push(y),y=E.i8888to32(r/4,n/4,o,c),f.push(y),y=E.i8888to32(0,We(a),10*h,Math.min(10*d,255)),f.push(y),l&&f.push(...l)}}class pt extends E{constructor(e){super(e)}add(e,t,i,s,r){const n=this.array,a=E.i1616to32(2*e+i,2*t+s);n.push(a),r&&n.push(...r)}}class Ie{constructor(e,t,i){this.layerExtent=4096,this._features=[],this.layer=e,this.zoom=t,this._spriteInfo=i,this._filter=e.getFeatureFilter()}pushFeature(e){this._filter&&!this._filter.filter(e,this.zoom)||this._features.push(e)}hasFeatures(){return this._features.length>0}getResources(e,t,i){}}class mt extends Ie{constructor(e,t,i,s,r){super(e,t,i),this.type=_e.CIRCLE,this._circleVertexBuffer=s,this._circleIndexBuffer=r}get circleIndexStart(){return this._circleIndexStart}get circleIndexCount(){return this._circleIndexCount}processFeatures(e){const t=this._circleVertexBuffer,i=this._circleIndexBuffer;this._circleIndexStart=3*i.index,this._circleIndexCount=0;const s=this.layer,r=this.zoom;e&&e.setExtent(this.layerExtent);for(const n of this._features){const a=n.getGeometry(e);if(!a)continue;const o=s.circleMaterial.encodeAttributes(n,r,s);for(const c of a)if(c)for(const h of c){const d=t.index;t.add(h.x,h.y,0,0,o),t.add(h.x,h.y,0,1,o),t.add(h.x,h.y,1,0,o),t.add(h.x,h.y,1,1,o),i.add(d+0,d+1,d+2),i.add(d+1,d+2,d+3),this._circleIndexCount+=6}}}serialize(){let e=6;e+=this.layerUIDs.length,e+=this._circleVertexBuffer.array.length,e+=this._circleIndexBuffer.array.length;const t=new Uint32Array(e),i=new Int32Array(t.buffer);let s=0;t[s++]=this.type,t[s++]=this.layerUIDs.length;for(let r=0;rI.page-b.page);for(const{ddFillAttributes:I,ddOutlineAttributes:b,page:_,geometry:M}of f)this._processFeature(M,h,t.outlineUsesFillColor,I,b,l,_)}}else for(const f of d){const y=n?s.encodeAttributes(f,i,t):null,p=h&&a?r.encodeAttributes(f,i,t):null,w=f.getGeometry(e);this._processFeature(w,h,t.outlineUsesFillColor,y,p,l)}}serialize(){let e=10;e+=this.layerUIDs.length,e+=this._fillVertexBuffer.array.length,e+=this._fillIndexBuffer.array.length,e+=this._outlineVertexBuffer.array.length,e+=this._outlineIndexBuffer.array.length,e+=3*this._patternMap.size+1;const t=new Uint32Array(e),i=new Int32Array(t.buffer);let s=0;t[s++]=this.type,t[s++]=this.layerUIDs.length;for(let a=0;a0)for(const[a,[o,c]]of r)t[s++]=a,t[s++]=o,t[s++]=c;t[s++]=this._fillVertexBuffer.array.length;for(let a=0;ah?(d!==void 0&&this._processFill(e,d,s,n,a),d=[l]):f<-h&&d!==void 0&&d.push(l)}d!==void 0&&this._processFill(e,d,s,n,a)}_processOutline(e,t){const i=this._outlineVertexBuffer,s=this._outlineIndexBuffer,r=s.index;let n,a,o;const c=new D(0,0),h=new D(0,0),d=new D(0,0);let l=-1,f=-1,y=-1,p=-1,w=-1,x=!1;const m=0;let g=e.length;if(g<2)return;const I=e[m];let b=e[g-1];for(;g&&b.isEqual(I);)--g,b=e[g-1];if(!(g-m<2)){for(let _=m;_8&&(L=8),B>=0?(y=i.add(a.x,a.y,c.x,c.y,0,1,t),p===-1&&(p=y),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),f=i.add(a.x,a.y,L*-d.x,L*-d.y,0,-1,t),w===-1&&(w=f),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),l=f,f=y,y=i.add(a.x,a.y,d.x,d.y,0,1,t),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),f=i.add(a.x,a.y,h.x,h.y,0,1,t),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y)):(y=i.add(a.x,a.y,L*d.x,L*d.y,0,1,t),p===-1&&(p=y),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),f=i.add(a.x,a.y,-c.x,-c.y,0,-1,t),w===-1&&(w=f),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),l=f,f=y,y=i.add(a.x,a.y,-d.x,-d.y,0,-1,t),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y),l=i.add(a.x,a.y,-h.x,-h.y,0,-1,t),l>=0&&f>=0&&y>=0&&!M&&s.add(l,f,y))}l>=0&&f>=0&&p>=0&&!x&&s.add(l,f,p),l>=0&&p>=0&&w>=0&&!x&&s.add(l,w,p),this._outlineIndexCount+=3*(s.index-r)}}_processFill(e,t,i,s,r){s=!0;let n;t.length>1&&(n=[]);let a=0;for(const d of t)a!==0&&n.push(a),a+=e[d].length;const o=2*a,c=ke.acquire();for(const d of t){const l=e[d],f=l.length;for(let y=0;y0){const d=t.map(y=>e[y].length),{buffer:l,vertexCount:f}=et(c,d);if(f>0){const y=this._fillVertexBuffer.index;for(let p=0;p0){const l=this._fillVertexBuffer.index;let f=0;for(;f=4160:e.y===t.y&&(e.y<=-64||e.y>=4160)}static _area(e){let t=0;const i=e.length-1;for(let s=0;sT.page-C.page),r.textured=!0;for(const{ddAttributes:T,page:C,cap:A,join:v,miterLimit:R,roundLimit:Z,halfWidth:N,offset:W,geometry:J}of V)r.capType=A,r.joinType=v,r.miterLimit=R,r.roundLimit=Z,r.halfWidth=N,r.offset=W,this._processFeature(J,T,C)}else{if(o){const V=o.getValue(i),T=this._spriteInfo[V];if(!T||!T.rect)return}r.textured=!(!o&&!c),r.capType=y,r.joinType=m,r.miterLimit=I,r.roundLimit=_,r.halfWidth=.5*B,r.offset=L;for(const V of s){const T=n?a.encodeAttributes(V,i,t):null;f&&(r.capType=f.getValue(i,V)),x&&(r.joinType=x.getValue(i,V)),g&&(r.miterLimit=g.getValue(i,V)),b&&(r.roundLimit=b.getValue(i,V)),M&&(r.halfWidth=.5*M.getValue(i,V)),P&&(r.offset=P.getValue(i,V));const C=V.getGeometry(e);this._processFeature(C,T)}}}serialize(){let e=6;e+=this.layerUIDs.length,e+=this.tessellationProperties._lineVertexBuffer.array.length,e+=this.tessellationProperties._lineIndexBuffer.array.length,e+=3*this._patternMap.size+1;const t=new Uint32Array(e),i=new Int32Array(t.buffer);let s=0;t[s++]=this.type,t[s++]=this.layerUIDs.length;for(let a=0;a0)for(const[a,[o,c]]of r)t[s++]=a,t[s++]=o,t[s++]=c;t[s++]=this.tessellationProperties._lineVertexBuffer.array.length;for(let a=0;a(e,t,i,s,r,n,a,o,c,h,d)=>(u._lineVertexBuffer.add(e,t,a,o,i,s,r,n,c,h,d,u._ddValues),u._lineVertexBuffer.index-1),Mt=u=>(e,t,i)=>{u._lineIndexBuffer.add(e,t,i)},He=10;function bt(u,e){return u.iconMosaicItem&&e.iconMosaicItem?u.iconMosaicItem.page===e.iconMosaicItem.page?0:u.iconMosaicItem.page-e.iconMosaicItem.page:u.iconMosaicItem&&!e.iconMosaicItem?1:!u.iconMosaicItem&&e.iconMosaicItem?-1:0}class z extends Ie{constructor(e,t,i,s,r,n,a,o){super(e,t,o.getSpriteItems()),this.type=_e.SYMBOL,this._markerMap=new Map,this._glyphMap=new Map,this._glyphBufferDataStorage=new Map,this._isIconSDF=!1,this._iconVertexBuffer=i,this._iconIndexBuffer=s,this._textVertexBuffer=r,this._textIndexBuffer=n,this._placementEngine=a,this._workerTileHandler=o}get markerPageMap(){return this._markerMap}get glyphsPageMap(){return this._glyphMap}get symbolInstances(){return this._symbolInstances}getResources(e,t,i){const s=this.layer,r=this.zoom;e&&e.setExtent(this.layerExtent);const n=s.getLayoutProperty("icon-image"),a=s.getLayoutProperty("text-field");let o=s.getLayoutProperty("text-transform"),c=s.getLayoutProperty("text-font");const h=[];let d,l,f,y;n&&!n.isDataDriven&&(d=n.getValue(r)),a&&!a.isDataDriven&&(l=a.getValue(r)),o&&o.isDataDriven||(f=s.getLayoutValue("text-transform",r),o=null),c&&c.isDataDriven||(y=s.getLayoutValue("text-font",r),c=null);for(const p of this._features){const w=p.getGeometry(e);if(!w||w.length===0)continue;let x,m;n&&(x=n.isDataDriven?n.getValue(r,p):this._replaceKeys(d,p.values),x&&t(x));let g=!1;if(a&&(m=a.isDataDriven?a.getValue(r,p):this._replaceKeys(l,p.values),m)){switch(m=m.replace(/\\n/g,` `),o&&(f=o.getValue(r,p)),f){case Oe.LOWERCASE:m=m.toLowerCase();break;case Oe.UPPERCASE:m=m.toUpperCase()}if(z._bidiEngine.hasBidiChar(m)){let M;M=z._bidiEngine.checkContextual(m)==="rtl"?"IDNNN":"ICNNN",m=z._bidiEngine.bidiTransform(m,M,"VLYSN"),g=!0}const _=m.length;if(_>0){c&&(y=c.getValue(r,p));for(const M of y){let B=i[M];B||(B=i[M]=new Set);for(let P=0;P<_;P++){const L=m.charCodeAt(P);B.add(L)}}}}if(!x&&!m)continue;const I=s.getLayoutValue("symbol-sort-key",r,p),b={feature:p,sprite:x,label:m,rtl:g,geometry:w,hash:(m?ve(m):0)^(x?ve(x):0),priority:I,textFont:y};h.push(b)}this._symbolFeatures=h}processFeatures(e){e&&e.setExtent(this.layerExtent);const t=this.layer,i=this.zoom,s=t.getLayoutValue("symbol-placement",i),r=s!==be.POINT,n=t.getLayoutValue("symbol-spacing",i)*he,a=t.getLayoutProperty("icon-image"),o=t.getLayoutProperty("text-field"),c=a?new nt(t,i,r):null,h=o?new at(t,i,r):null,d=this._workerTileHandler;let l;a&&(l=d.getSpriteItems()),this._iconIndexStart=3*this._iconIndexBuffer.index,this._textIndexStart=3*this._textIndexBuffer.index,this._iconIndexCount=0,this._textIndexCount=0,this._markerMap.clear(),this._glyphMap.clear();const f=[];let y=1;h&&h.size&&(y=h.size/H);const p=h?h.maxAngle*Be:0,w=h?h.size*he:0;for(const x of this._symbolFeatures){let m;c&&l&&x.sprite&&(m=l[x.sprite],m&&m.sdf&&(this._isIconSDF=!0));let g;m&&c.update(i,x.feature);let I=0;const b=x.label;if(b){h.update(i,x.feature);const _=r&&h.rotationAlignment===ie.MAP?h.keepUpright:h.writingMode&&h.writingMode.includes(Qe.VERTICAL);let M=.5;switch(h.anchor){case k.TOP_LEFT:case k.LEFT:case k.BOTTOM_LEFT:M=0;break;case k.TOP_RIGHT:case k.RIGHT:case k.BOTTOM_RIGHT:M=1}let B=.5;switch(h.anchor){case k.TOP_LEFT:case k.TOP:case k.TOP_RIGHT:B=0;break;case k.BOTTOM_LEFT:case k.BOTTOM:case k.BOTTOM_RIGHT:B=1}let P=.5;switch(h.justify){case Pe.AUTO:P=M;break;case Pe.LEFT:P=0;break;case Pe.RIGHT:P=1}const L=h.letterSpacing*H,V=r?0:h.maxWidth*H,T=h.lineHeight*H,C=x.textFont.map(A=>d.getGlyphItems(A));if(g=new qe(C,V,T,L,M,B,P).getShaping(b,x.rtl,_),g&&g.length>0){let A=1e30,v=-1e30;for(const R of g)A=Math.min(A,R.x),v=Math.max(v,R.x);I=(v-A+2*H)*y*he}}for(let _ of x.geometry){const M=[];if(s===be.LINE){if(g&&g.length>0&&h&&h.size){const B=h.size*he*(2+Math.min(2,4*Math.abs(h.offset[1])));_=z._smoothVertices(_,B)}z._pushAnchors(M,_,n,I)}else s===be.LINE_CENTER?z._pushCenterAnchor(M,_):x.feature.type===Xe.Polygon?z._pushCentroid(M,_):M.push(new pe(_[0].x,_[0].y));for(const B of M){if(B.x<0||B.x>Ne||B.y<0||B.y>Ne||r&&I>0&&h.rotationAlignment===ie.MAP&&!z._honorsTextMaxAngle(_,B,I,p,w))continue;const P={shaping:g,line:_,iconMosaicItem:m,anchor:B,symbolFeature:x,textColliders:[],iconColliders:[],textVertexRanges:[],iconVertexRanges:[]};f.push(P),this._processFeature(P,c,h)}}}f.sort(bt),this._addPlacedGlyphs(),this._symbolInstances=f}serialize(){let e=11;e+=this.layerUIDs.length,e+=3*this.markerPageMap.size,e+=3*this.glyphsPageMap.size,e+=z._symbolsSerializationLength(this._symbolInstances),e+=this._iconVertexBuffer.array.length,e+=this._iconIndexBuffer.array.length,e+=this._textVertexBuffer.array.length,e+=this._textIndexBuffer.array.length;const t=new Uint32Array(e),i=new Int32Array(t.buffer),s=new Float32Array(t.buffer);let r=0;t[r++]=this.type,t[r++]=this.layerUIDs.length;for(let n=0;ns in t?t[s]:"")}_processFeature(e,t,i){const{line:s,iconMosaicItem:r,shaping:n,anchor:a}=e,o=this.zoom,c=this.layer,h=!!r;let d=!0;h&&(d=t.optional||!r);const l=n&&n.length>0;let f,y,p=!0;if(l&&(p=i.optional),h&&(f=this._placementEngine.getIconPlacement(a,r,t)),(f||d)&&(l&&(y=this._placementEngine.getTextPlacement(a,n,s,i)),y||p)){if(f&&y||(p||d?p||y?d||f||(y=null):f=null:(f=null,y=null)),y){const w=c.hasDataDrivenText?c.textMaterial.encodeAttributes(e.symbolFeature.feature,o,c):null;if(this._storePlacedGlyphs(e,y.shapes,o,i.rotationAlignment,w),y.textColliders){e.textColliders=y.textColliders;for(const x of y.textColliders){x.minLod=Math.max(o+Y(x.minLod),0),x.maxLod=Math.min(o+Y(x.maxLod),25);const m=x.angle;if(m){const g=Math.cos(m),I=Math.sin(m),b=x.dxPixels*g-x.dyPixels*I,_=x.dxPixels*I+x.dyPixels*g,M=(x.dxPixels+x.width)*g-x.dyPixels*I,B=(x.dxPixels+x.width)*I+x.dyPixels*g,P=x.dxPixels*g-(x.dyPixels+x.height)*I,L=x.dxPixels*I+(x.dyPixels+x.height)*g,V=(x.dxPixels+x.width)*g-(x.dyPixels+x.height)*I,T=(x.dxPixels+x.width)*I+(x.dyPixels+x.height)*g,C=Math.min(b,M,P,V),A=Math.max(b,M,P,V),v=Math.min(_,B,L,T),R=Math.max(_,B,L,T);x.dxPixels=C,x.dyPixels=v,x.width=A-C,x.height=R-v}}}}if(f){const w=c.hasDataDrivenIcon?c.iconMaterial.encodeAttributes(e.symbolFeature.feature,o,c):null;if(this._addPlacedIcons(e,f.shapes,o,r.page,t.rotationAlignment===ie.VIEWPORT,w),f.iconColliders){e.iconColliders=f.iconColliders;for(const x of f.iconColliders){x.minLod=Math.max(o+Y(x.minLod),0),x.maxLod=Math.min(o+Y(x.maxLod),25);const m=x.angle;if(m){const g=Math.cos(m),I=Math.sin(m),b=x.dxPixels*g-x.dyPixels*I,_=x.dxPixels*I+x.dyPixels*g,M=(x.dxPixels+x.width)*g-x.dyPixels*I,B=(x.dxPixels+x.width)*I+x.dyPixels*g,P=x.dxPixels*g-(x.dyPixels+x.height)*I,L=x.dxPixels*I+(x.dyPixels+x.height)*g,V=(x.dxPixels+x.width)*g-(x.dyPixels+x.height)*I,T=(x.dxPixels+x.width)*I+(x.dyPixels+x.height)*g,C=Math.min(b,M,P,V),A=Math.max(b,M,P,V),v=Math.min(_,B,L,T),R=Math.max(_,B,L,T);x.dxPixels=C,x.dyPixels=v,x.width=A-C,x.height=R-v}}}}}}_addPlacedIcons(e,t,i,s,r,n){const a=Math.max(i-1,0),o=this._iconVertexBuffer,c=this._iconIndexBuffer,h=this._markerMap;for(const d of t){const l=r?0:Math.max(i+Y(d.minzoom),a),f=r?25:Math.min(i+Y(d.maxzoom),25);if(f<=l)continue;const y=d.tl,p=d.tr,w=d.bl,x=d.br,m=d.mosaicRect,g=d.labelAngle,I=d.minAngle,b=d.maxAngle,_=d.anchor,M=o.index,B=m.x,P=m.y,L=B+m.width,V=P+m.height,T=o.index;o.add(_.x,_.y,y.x,y.y,B,P,g,I,b,l,f,n),o.add(_.x,_.y,p.x,p.y,L,P,g,I,b,l,f,n),o.add(_.x,_.y,w.x,w.y,B,V,g,I,b,l,f,n),o.add(_.x,_.y,x.x,x.y,L,V,g,I,b,l,f,n),e.iconVertexRanges.length>0&&e.iconVertexRanges[0][0]+e.iconVertexRanges[0][1]===T?e.iconVertexRanges[0][1]+=4:e.iconVertexRanges.push([T,4]),c.add(M+0,M+1,M+2),c.add(M+1,M+2,M+3),h.has(s)?h.get(s)[1]+=6:h.set(s,[this._iconIndexStart+this._iconIndexCount,6]),this._iconIndexCount+=6}}_addPlacedGlyphs(){const e=this._textVertexBuffer,t=this._textIndexBuffer,i=this._glyphMap;for(const[s,r]of this._glyphBufferDataStorage)for(const n of r){const a=e.index,o=n.symbolInstance,c=n.ddAttributes,h=e.index;e.add(n.glyphAnchor[0],n.glyphAnchor[1],n.tl[0],n.tl[1],n.xmin,n.ymin,n.labelAngle,n.minAngle,n.maxAngle,n.minLod,n.maxLod,c),e.add(n.glyphAnchor[0],n.glyphAnchor[1],n.tr[0],n.tr[1],n.xmax,n.ymin,n.labelAngle,n.minAngle,n.maxAngle,n.minLod,n.maxLod,c),e.add(n.glyphAnchor[0],n.glyphAnchor[1],n.bl[0],n.bl[1],n.xmin,n.ymax,n.labelAngle,n.minAngle,n.maxAngle,n.minLod,n.maxLod,c),e.add(n.glyphAnchor[0],n.glyphAnchor[1],n.br[0],n.br[1],n.xmax,n.ymax,n.labelAngle,n.minAngle,n.maxAngle,n.minLod,n.maxLod,c),o.textVertexRanges.length>0&&o.textVertexRanges[0][0]+o.textVertexRanges[0][1]===h?o.textVertexRanges[0][1]+=4:o.textVertexRanges.push([h,4]),t.add(a+0,a+1,a+2),t.add(a+1,a+2,a+3),i.has(s)?i.get(s)[1]+=6:i.set(s,[this._textIndexStart+this._textIndexCount,6]),this._textIndexCount+=6}this._glyphBufferDataStorage.clear()}_storePlacedGlyphs(e,t,i,s,r){const n=Math.max(i-1,0),a=s===ie.VIEWPORT;let o,c,h,d,l,f,y,p,w,x,m;for(const g of t)o=a?0:Math.max(i+Y(g.minzoom),n),c=a?25:Math.min(i+Y(g.maxzoom),25),!(c<=o)&&(h=g.tl,d=g.tr,l=g.bl,f=g.br,y=g.labelAngle,p=g.minAngle,w=g.maxAngle,x=g.anchor,m=g.mosaicRect,this._glyphBufferDataStorage.has(g.page)||this._glyphBufferDataStorage.set(g.page,[]),this._glyphBufferDataStorage.get(g.page).push({glyphAnchor:[x.x,x.y],tl:[h.x,h.y],tr:[d.x,d.y],bl:[l.x,l.y],br:[f.x,f.y],xmin:m.x,ymin:m.y,xmax:m.x+m.width,ymax:m.y+m.height,labelAngle:y,minAngle:p,maxAngle:w,minLod:o,maxLod:c,placementLod:n,symbolInstance:e,ddAttributes:r}))}static _pushAnchors(e,t,i,s){i+=s;let r=0;const n=t.length-1;for(let l=0;l-a;){if(--c,c<0)return!1;n-=D.distance(e[c],o),o=e[c]}n+=D.distance(e[c],e[c+1]);const h=[];let d=0;const l=e.length;for(;nr;)d-=h.shift().deviation;if(Math.abs(d)>s)return!1;n+=D.distance(y,w),c=p}return!0}static _smoothVertices(e,t){if(t<=0)return e;let i=e.length;if(i<3)return e;const s=[];let r=0,n=0;s.push(0);for(let p=1;p0&&(r+=w,s.push(r),n++,n!==p&&(e[n]=e[p]))}if(i=n+1,i<3)return e;t=Math.min(t,.2*r);const a=e[0].x,o=e[0].y,c=e[i-1].x,h=e[i-1].y,d=D.sub(e[0],e[1]);d.normalize(),e[0].x+=t*d.x,e[0].y+=t*d.y,d.assignSub(e[i-1],e[i-2]),d.normalize(),e[i-1].x+=t*d.x,e[i-1].y+=t*d.y,s[0]-=t,s[i-1]+=t;const l=[];l.push(new D(a,o));const f=1e-6,y=.5*t;for(let p=1;p=0;g--){const I=y+s[g+1]-s[p];if(I<0)break;const b=s[g+1]-s[g],_=s[p]-s[g]4096&&(d=4096),d<0&&(d=0),l>4096&&(l=4096),l<0&&(l=0);for(let f=1;f4096&&(y=4096),y<0&&(y=0),p>4096&&(p=4096),p<0&&(p=0),w>4096&&(w=4096),w<0&&(w=0),x>4096&&(x=4096),x<0&&(x=0);const m=(y-d)*(x-l)-(w-d)*(p-l);o+=m*(d+y+w),c+=m*(l+p+x),h+=m}o/=3*h,c/=3*h,isNaN(o)||isNaN(c)||e.push(new pe(o,c))}}z._bidiEngine=new lt;var K;(function(u){u[u.INITIALIZED=0]="INITIALIZED",u[u.NO_DATA=1]="NO_DATA",u[u.READY=2]="READY",u[u.MODIFIED=3]="MODIFIED",u[u.INVALID=4]="INVALID"})(K||(K={}));const Pt=8,Tt=14,Bt=5;class Lt{constructor(e,t,i,s,r){if(this._pbfTiles={},this._tileClippers={},this._client=i,this._tile=t,r){this._styleLayerUIDs=new Set;for(const h of r)this._styleLayerUIDs.add(h)}this._styleRepository=s,this._layers=this._styleRepository.layers;const[n,a,o]=t.tileKey.split("/").map(parseFloat);this._level=n;const c=Pt+Math.max((this._level-Tt)*Bt,0);for(const h of Object.keys(e)){const d=e[h];if(this._pbfTiles[h]=new Ye(new Uint8Array(d.protobuff),new DataView(d.protobuff)),d.refKey){const[l]=d.refKey.split("/").map(parseFloat),f=n-l;if(f>0){const y=(1<{n.has(h)||(r.push({name:h,repeat:d}),n.add(h))},o={};for(const h of s)h.getResources(h.tileClipper,a,o);if(this._tile.status===K.INVALID)return[];const c=this._fetchResources(r,o,e);return Promise.all([...c,t]).then(()=>this._processFeatures(i.returnedBuckets))}_initialize(e){return{signal:e&&e.signal,sourceNameToTileData:this._parseTileData(this._pbfTiles),layers:this._layers,zoom:this._level,sourceNameToTileClipper:this._tileClippers,sourceNameToUniqueSourceLayerBuckets:{},sourceNameToUniqueSourceLayers:{},returnedBuckets:[],layerIdToBucket:{},referencerUIDToReferencedId:new Map}}_processLayers(e){const{sourceNameToTileData:t,layers:i,zoom:s,sourceNameToTileClipper:r,sourceNameToUniqueSourceLayerBuckets:n,sourceNameToUniqueSourceLayers:a,returnedBuckets:o,layerIdToBucket:c,referencerUIDToReferencedId:h}=e;for(let d=i.length-1;d>=0;d--){const l=i[d];if(!this._canParseStyleLayer(l.uid)||l.minzoom&&s=l.maxzoom||l.type===ee.BACKGROUND||!t[l.source]||!r[l.source])continue;const f=t[l.source],y=r[l.source],p=l.sourceLayer,w=f[p];if(w){let x=a[l.source];if(x||(x=a[l.source]=new Set),x.add(l.sourceLayer),l.refLayerId)h.set(l.uid,l.refLayerId);else{const m=this._createBucket(l);if(m){m.layerUIDs=[l.uid],m.layerExtent=w.extent,m.tileClipper=y;let g=n[l.source];g||(g=n[l.source]={});let I=g[p];I||(I=g[p]=[]),I.push(m),o.push(m),c[l.id]=m}}}}}_linkReferences(e){const{layerIdToBucket:t,referencerUIDToReferencedId:i}=e;i.forEach((s,r)=>{t[s]&&t[s].layerUIDs.push(r)})}_filterFeatures(e){const{signal:t,sourceNameToTileData:i,sourceNameToUniqueSourceLayerBuckets:s,sourceNameToUniqueSourceLayers:r}=e,n=10*this._level,a=10*(this._level+1),o=[],c=[];for(const h of Object.keys(r))r[h].forEach(d=>{o.push(d),c.push(h)});for(let h=0;h=a)continue;const I=m._maxzoom;if(I&&I<=n)continue}for(const g of y)g.pushFeature(x)}}}_fetchResources(e,t,i){const s=[],r=this._tile.getWorkerTileHandler();let n,a;e.length>0&&(n=r.fetchSprites(e,this._client,i),s.push(n));for(const o in t){const c=t[o];c.size>0&&(a=r.fetchGlyphs(this._tile.tileKey,o,c,this._client,i),s.push(a))}return s}_processFeatures(e){const t=e.filter(i=>i.hasFeatures()||this._canParseStyleLayer(i.layer.uid));for(const i of t)i.processFeatures(i.tileClipper);return t}_parseTileData(e){const t={};for(const i of Object.keys(e)){const s=e[i],r={};for(;s.next();)switch(s.tag()){case 3:{const n=s.getMessage(),a=new Le(n);n.release(),r[a.name]=a;break}default:s.skip()}t[i]=r}return t}_createBucket(e){switch(e.type){case ee.BACKGROUND:return null;case ee.FILL:return this._createFillBucket(e);case ee.LINE:return this._createLineBucket(e);case ee.CIRCLE:return this._createCircleBucket(e);case ee.SYMBOL:return this._createSymbolBucket(e)}}_createFillBucket(e){return new De(e,this._level,this._tile.getWorkerTileHandler().getSpriteItems(),new yt(e.fillMaterial.getStride()),new te,new gt(e.outlineMaterial.getStride()),new te)}_createLineBucket(e){return new It(e,this._level,this._tile.getWorkerTileHandler().getSpriteItems(),new xt(e.lineMaterial.getStride()),new te)}_createCircleBucket(e){return new mt(e,this._level,this._tile.getWorkerTileHandler().getSpriteItems(),new pt(e.circleMaterial.getStride()),new te)}_createSymbolBucket(e){const t=this._tile;return new z(e,this._level,new Ge(e.iconMaterial.getStride()),new te,new Ge(e.textMaterial.getStride()),new te,t.placementEngine,t.getWorkerTileHandler())}}class Dt{constructor(e,t,i,s){this.status=K.INITIALIZED,this.placementEngine=new ft,this.tileKey=e,this.refKeys=t,this._workerTileHandler=i,this._styleRepository=s}release(){this.tileKey="",this.refKeys=null,this.status=K.INITIALIZED,this._workerTileHandler=null}async parse(e,t){const i=t&&t.signal;if(Je(i)){const h=()=>{i.removeEventListener("abort",h),this.status=K.INVALID};i.addEventListener("abort",h)}let s;const r={bucketsWithData:[],emptyBuckets:null};try{s=await this._parse(e,t)}catch(h){if(Ke(h))throw h;return{result:r,transferList:[]}}this.status=K.READY;const n=r.bucketsWithData,a=[];for(const h of s)if(h.hasFeatures()){const d=h.serialize();n.push(d)}else a.push(h.layer.uid);const o=[...n];let c=null;return a.length>0&&(c=Uint32Array.from(a),o.push(c.buffer)),r.emptyBuckets=c,{result:r,transferList:o}}setObsolete(){this.status=K.INVALID}getLayers(){return this._workerTileHandler.getLayers()}getWorkerTileHandler(){return this._workerTileHandler}async _parse(e,t){const i=e.sourceName2DataAndRefKey;return Object.keys(i).length===0?[]:(this.status=K.MODIFIED,new Lt(i,this,t.client,this._styleRepository,e.styleLayerUIDs).parse(t))}}class Kt{constructor(){this._spriteInfo={},this._glyphInfo={}}reset(){return this._spriteInfo={},this._glyphInfo={},Promise.resolve()}getLayers(){var e;return(e=this._styleRepository)==null?void 0:e.layers}async createTileAndParse(e,t){const{key:i}=e,s={};for(const n of Object.keys(e.sourceName2DataAndRefKey)){const a=e.sourceName2DataAndRefKey[n];s[n]=a.refKey}const r=new Dt(i,s,this,this._styleRepository);try{return await r.parse(e,t)}catch(n){if(r.setObsolete(),r.release(),!Ke(n))throw n;return null}}updateStyle(e){if(!e||e.length===0||!this._styleRepository)return;const t=this._styleRepository;for(const i of e){const s=i.type,r=i.data;switch(s){case oe.PAINTER_CHANGED:t.setPaintProperties(r.layer,r.paint);break;case oe.LAYOUT_CHANGED:t.setLayoutProperties(r.layer,r.layout);break;case oe.LAYER_REMOVED:t.deleteStyleLayer(r.layer);break;case oe.LAYER_CHANGED:t.setStyleLayer(r.layer,r.index);break;case oe.SPRITES_CHANGED:this._spriteInfo={}}}}setStyle(e){this._styleRepository=new ot(e),this._spriteInfo={},this._glyphInfo={}}fetchSprites(e,t,i){const s=[],r=this._spriteInfo;for(const n of e)r[n.name]===void 0&&s.push(n);return s.length===0?Promise.resolve():t.invoke("getSprites",s,{signal:i&&i.signal}).then(n=>{for(const a in n){const o=n[a];r[a]=o}})}getSpriteItems(){return this._spriteInfo}fetchGlyphs(e,t,i,s,r){const n=[];let a=this._glyphInfo[t];return a?i.forEach(o=>{a[o]||n.push(o)}):(a=this._glyphInfo[t]=[],i.forEach(o=>n.push(o))),n.length===0?Promise.resolve():s.invoke("getGlyphs",{tileID:e,font:t,codePoints:n},r).then(o=>{for(let c=0;c