import{l as rt,n as V,U as xe,m as Je,g as Q,p as Ui,e as U,a as F,h as Ue,q as ki,u as Ni,v as Li,w as Gi,t as N,s as xt,x as Vi,y as Hi,z as ke,A as de,B as qi,D as Wi,r as ji,C as Yi,E as De,F as Tt,G as Ke,H as Xi,I as St,J as Zi,M as Ki,K as Qi,L as Ji,d as es,c as ts,N as is,o as ss,O as rs,P as ns,Q as as,R as Qe,S as fi,T as os,V as G,W as le,X as hs,Y as ls,Z as us,_ as R,$ as O,a0 as Te,a1 as Ee,a2 as Pt,a3 as ds,a4 as cs,a5 as gi,a6 as nt,a7 as at,a8 as vi,a9 as et,aa as ms,ab as _s,ac as ps,ad as fs,ae as gs,af as Ne,ag as vs,ah as bt,ai as ys,aj as bs,ak as Ot,al as Dt,am as ws,an as xs,ao as Ts}from"./index.6c049565.js";import{o as Es}from"./_commonjsHelpers.773c2c82.js";import{c as Ms}from"./imageutils.2ce8d042.js";import{i as At,r as Rs}from"./utils.eb2c3fd5.js";import{n as Fs}from"./BufferPool.8a9a4ff1.js";import{I as k,N as Bs,O as Ve,v as Cs,M as Ss,a as zt,T as Ps,B as Os,_ as He,E as $t,U as It,w as Ds,A as As,D as zs,b as Re,S as lt}from"./Utils.e8554a0e.js";import{n as j,t as $s,a as ge,b as Ge,c as re,m as Is}from"./WGLContainer.bbd0fcb8.js";import{T as I}from"./enums.54326430.js";import{e as Us,a as Le}from"./ProgramTemplate.83fdf5b6.js";import{n as ve}from"./programUtils.7e7bf03b.js";import{a as Et,E as Mt,x as H,s as ks}from"./VertexArrayObject.729879be.js";import{R as M,E as Ae,F as Rt,P as E,G as C,L as B,D,O as ut,I as yi,M as A,C as Ut,Y as J,V as ee,B as Ns}from"./enums.2d9e6f64.js";import{o as kt,T as Ls,y as Gs}from"./RenderingContext.f389fdc6.js";import{p as Vs,o as qe,r as Nt,t as Lt,a as Hs,b as qs,c as Ws,e as js,i as Ys,n as Xs}from"./ExpandedCIM.64535143.js";import{r as Zs,e as Ks}from"./rasterizingUtils.b3483176.js";import{e as ae,d as oe,z as Gt,y as Vt,b as Qs,x as Js,w as er,N as tr,B as ir,C as sr,J as bi,I as Fe,Y as wi,O as Ht,U as rr,V as nr}from"./enums.0295eb81.js";import{t as q}from"./Rect.95b0fd2e.js";import{E as W}from"./Texture.8e8dfb11.js";import{o as ar}from"./floatRGBA.c5518572.js";import{P as qt}from"./GeometryUtils.51c4032a.js";import{e as or}from"./Matcher.d9c9cebd.js";import{t as Wt}from"./VertexElementDescriptor.1fdca6da.js";import{s as hr}from"./CircularArray.415a06a8.js";import{e as lr}from"./imageUtils.753f41b1.js";import{t as ur}from"./ComputedAttributeStorage.dc79b701.js";import{o as jo}from"./BaseGraphicContainer.8f76c915.js";import{i as Xo}from"./GraphicContainer.ec6ac6c0.js";import{t as jt}from"./requestImageUtils.06d9d84a.js";import"./MaterialKey.bbaab8f1.js";import"./pixelUtils.f4eba4af.js";import"./StyleDefinition.d56936e4.js";import"./config.82550349.js";import"./earcut.afc1d357.js";import"./OrderIndependentTransparency.4d1575c0.js";import"./BidiEngine.d8bba3fc.js";import"./quantizationUtils.4f3ed95a.js";import"./GeometryUtils.4f19e772.js";import"./visualVariablesUtils.4b17aac7.js";import"./visualVariablesUtils.88ca310b.js";import"./tileUtils.a1e62810.js";import"./TileClipper.7297efa2.js";import"./Geometry.d049a63c.js";import"./devEnvironmentUtils.d8d0484c.js";import"./centroid.0c969b82.js";import"./normalizeUtilsSync.f896b328.js";import"./projectionSupport.2b4a8796.js";import"./json.879c9adc.js";import"./FeatureContainer.8e5dd053.js";import"./TileContainer.282da507.js";import"./schemaUtils.7eee5b9f.js";import"./createSymbolSchema.30665f63.js";import"./util.d5f4af7b.js";import"./vec3f32.1121a836.js";var Yt,xi={exports:{}};Yt=function(){return function(n){var e={};function t(i){if(e[i])return e[i].exports;var s=e[i]={exports:{},id:i,loaded:!1};return n[i].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}return t.m=n,t.c=e,t.p="",t(0)}([function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.isNotPNG=h,e.isNotAPNG=u,e.default=d;var i=a(t(1)),s=t(2);function a(p){return p&&p.__esModule?p:{default:p}}var r=new Error("Not a PNG"),o=new Error("Not an animated PNG");function h(p){return p===r}function u(p){return p===o}var l=new Uint8Array([137,80,78,71,13,10,26,10]);function d(p){var w=new Uint8Array(p);if(Array.prototype.some.call(l,function(X,$){return X!==w[$]}))return r;var y=!1;if(c(w,function(X){return!(y=X==="acTL")}),!y)return o;var b=[],x=[],z=null,T=null,Y=0,ne=new s.APNG;if(c(w,function(X,$,S,Me){var Z=new DataView($.buffer);switch(X){case"IHDR":z=$.subarray(S+8,S+8+Me),ne.width=Z.getUint32(S+8),ne.height=Z.getUint32(S+12);break;case"acTL":ne.numPlays=Z.getUint32(S+8+4);break;case"fcTL":T&&(ne.frames.push(T),Y++),(T=new s.Frame).width=Z.getUint32(S+8+4),T.height=Z.getUint32(S+8+8),T.left=Z.getUint32(S+8+12),T.top=Z.getUint32(S+8+16);var Ii=Z.getUint16(S+8+20),ht=Z.getUint16(S+8+22);ht===0&&(ht=100),T.delay=1e3*Ii/ht,T.delay<=10&&(T.delay=100),ne.playTime+=T.delay,T.disposeOp=Z.getUint8(S+8+24),T.blendOp=Z.getUint8(S+8+25),T.dataParts=[],Y===0&&T.disposeOp===2&&(T.disposeOp=1);break;case"fdAT":T&&T.dataParts.push($.subarray(S+8+4,S+8+Me));break;case"IDAT":T&&T.dataParts.push($.subarray(S+8,S+8+Me));break;case"IEND":x.push(f($,S,12+Me));break;default:b.push(f($,S,12+Me))}}),T&&ne.frames.push(T),ne.frames.length==0)return o;var zi=new Blob(b),$i=new Blob(x);return ne.frames.forEach(function(X){var $=[];$.push(l),z.set(v(X.width),0),z.set(v(X.height),4),$.push(g("IHDR",z)),$.push(zi),X.dataParts.forEach(function(S){return $.push(g("IDAT",S))}),$.push($i),X.imageData=new Blob($,{type:"image/png"}),delete X.dataParts,$=null}),ne}function c(p,w){var y=new DataView(p.buffer),b=8,x=void 0,z=void 0,T=void 0;do z=y.getUint32(b),T=w(x=m(p,b+4,4),p,b,z),b+=12+z;while(T!==!1&&x!="IEND"&&b>>24&255,p>>>16&255,p>>>8&255,255&p])}},function(n,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(r){for(var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,h=-1,u=o,l=o+(arguments.length>2&&arguments[2]!==void 0?arguments[2]:r.length-o);u>>8^t[255&(h^r[u])];return-1^h};for(var t=new Uint32Array(256),i=0;i<256;i++){for(var s=i,a=0;a<8;a++)s=(1&s)!=0?3988292384^s>>>1:s>>>1;t[i]=s}},function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0}),e.Frame=e.APNG=void 0;var i=function(){function o(h,u){for(var l=0;l1&&arguments[1]!==void 0&&arguments[1];return this.createImages().then(function(){return new s.default(u,h,l)})}}]),o}(),e.Frame=function(){function o(){r(this,o),this.left=0,this.top=0,this.width=0,this.height=0,this.delay=0,this.disposeOp=0,this.blendOp=0,this.imageData=null,this.imageElement=null}return i(o,[{key:"createImage",value:function(){var h=this;return this.imageElement?Promise.resolve():new Promise(function(u,l){var d=URL.createObjectURL(h.imageData);h.imageElement=document.createElement("img"),h.imageElement.onload=function(){URL.revokeObjectURL(d),u()},h.imageElement.onerror=function(){URL.revokeObjectURL(d),h.imageElement=null,l(new Error("Image creation error"))},h.imageElement.src=d})}}]),o}()},function(n,e,t){Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function u(l,d){for(var c=0;c=this._apng.numPlays&&(this._ended=!0,this._paused=!0)),this._prevFrame&&this._prevFrame.disposeOp==1?this.context.clearRect(this._prevFrame.left,this._prevFrame.top,this._prevFrame.width,this._prevFrame.height):this._prevFrame&&this._prevFrame.disposeOp==2&&this.context.putImageData(this._prevFrameData,this._prevFrame.left,this._prevFrame.top);var d=this.currentFrame;this._prevFrame=d,this._prevFrameData=null,d.disposeOp==2&&(this._prevFrameData=this.context.getImageData(d.left,d.top,d.width,d.height)),d.blendOp==0&&this.context.clearRect(d.left,d.top,d.width,d.height),this.context.drawImage(d.imageElement,d.left,d.top),this.emit("frame",this._currentFrameNumber),this._ended&&this.emit("end")}},{key:"play",value:function(){var d=this;this.emit("play"),this._ended&&this.stop(),this._paused=!1;var c=performance.now()+this.currentFrame.delay/this.playbackRate,m=function _(f){if(!d._ended&&!d._paused){if(f>=c){for(;f-c>=d._apng.playTime/d.playbackRate;)c+=d._apng.playTime/d.playbackRate,d._numPlays++;do d.renderNextFrame(),c+=d.currentFrame.delay/d.playbackRate;while(!d._ended&&f>c)}requestAnimationFrame(_)}};requestAnimationFrame(m)}},{key:"pause",value:function(){this._paused||(this.emit("pause"),this._paused=!0)}},{key:"stop",value:function(){this.emit("stop"),this._numPlays=0,this._ended=!1,this._paused=!0,this._currentFrameNumber=-1,this.context.clearRect(0,0,this._apng.width,this._apng.height),this.renderNextFrame()}},{key:"currentFrameNumber",get:function(){return this._currentFrameNumber}},{key:"currentFrame",get:function(){return this._apng.frames[this._currentFrameNumber]}},{key:"paused",get:function(){return this._paused}},{key:"ended",get:function(){return this._ended}}]),l}(s(t(4)).default);e.default=h},function(n,e){function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(o){return typeof o=="function"}function s(o){return typeof o=="number"}function a(o){return typeof o=="object"&&o!==null}function r(o){return o===void 0}n.exports=t,t.EventEmitter=t,t.prototype._events=void 0,t.prototype._maxListeners=void 0,t.defaultMaxListeners=10,t.prototype.setMaxListeners=function(o){if(!s(o)||o<0||isNaN(o))throw TypeError("n must be a positive number");return this._maxListeners=o,this},t.prototype.emit=function(o){var h,u,l,d,c,m;if(this._events||(this._events={}),o==="error"&&(!this._events.error||a(this._events.error)&&!this._events.error.length)){if((h=arguments[1])instanceof Error)throw h;var _=new Error('Uncaught, unspecified "error" event. ('+h+")");throw _.context=h,_}if(r(u=this._events[o]))return!1;if(i(u))switch(arguments.length){case 1:u.call(this);break;case 2:u.call(this,arguments[1]);break;case 3:u.call(this,arguments[1],arguments[2]);break;default:d=Array.prototype.slice.call(arguments,1),u.apply(this,d)}else if(a(u))for(d=Array.prototype.slice.call(arguments,1),l=(m=u.slice()).length,c=0;c0&&this._events[o].length>u&&(this._events[o].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[o].length),typeof console.trace=="function"&&console.trace()),this},t.prototype.on=t.prototype.addListener,t.prototype.once=function(o,h){if(!i(h))throw TypeError("listener must be a function");var u=!1;function l(){this.removeListener(o,l),u||(u=!0,h.apply(this,arguments))}return l.listener=h,this.on(o,l),this},t.prototype.removeListener=function(o,h){var u,l,d,c;if(!i(h))throw TypeError("listener must be a function");if(!this._events||!this._events[o])return this;if(d=(u=this._events[o]).length,l=-1,u===h||i(u.listener)&&u.listener===h)delete this._events[o],this._events.removeListener&&this.emit("removeListener",o,h);else if(a(u)){for(c=d;c-- >0;)if(u[c]===h||u[c].listener&&u[c].listener===h){l=c;break}if(l<0)return this;u.length===1?(u.length=0,delete this._events[o]):u.splice(l,1),this._events.removeListener&&this.emit("removeListener",o,h)}return this},t.prototype.removeAllListeners=function(o){var h,u;if(!this._events)return this;if(!this._events.removeListener)return arguments.length===0?this._events={}:this._events[o]&&delete this._events[o],this;if(arguments.length===0){for(h in this._events)h!=="removeListener"&&this.removeAllListeners(h);return this.removeAllListeners("removeListener"),this._events={},this}if(i(u=this._events[o]))this.removeListener(o,u);else if(u)for(;u.length;)this.removeListener(o,u[u.length-1]);return delete this._events[o],this},t.prototype.listeners=function(o){return this._events&&this._events[o]?i(this._events[o])?[this._events[o]]:this._events[o].slice():[]},t.prototype.listenerCount=function(o){if(this._events){var h=this._events[o];if(i(h))return 1;if(h)return h.length}return 0},t.listenerCount=function(o,h){return o.listenerCount(h)}}])},xi.exports=Yt();const dr=Es(xi.exports);async function cr(n,e){const t=dr(n);if(t instanceof Error)throw t;await t.createImages(),rt(e);const{frames:i,width:s,height:a}=t,r=document.createElement("canvas");r.width=s,r.height=a;const o=r.getContext("2d"),h=[],u=[];for(const l of i){u.push(V(l.delay||100));const d=l.imageElement;l.blendOp===0?o.globalCompositeOperation="copy":o.globalCompositeOperation="source-over";const c=l.disposeOp===2&&o.getImageData(l.left,l.top,l.width,l.height);o.drawImage(d,l.left,l.top);const m=o.getImageData(0,0,s,a);h.push(m),l.disposeOp===0||(l.disposeOp===1?o.clearRect(l.left,l.top,l.width,l.height):l.disposeOp===2&&o.putImageData(c,l.left,l.top))}return{frameDurations:u,getFrame:l=>h[l],width:s,height:a}}const mr=[137,80,78,71,13,10,26,10];function _r(n){const e=new Uint8Array(n);return!mr.some((t,i)=>t!==e[i])}function pr(n){if(!_r(n))return!1;const e=new DataView(n),t=new Uint8Array(n);let i,s=8;do{const a=e.getUint32(s);if(i=String.fromCharCode.apply(String,Array.prototype.slice.call(t.subarray(s+4,s+8))),i==="acTL")return!0;s+=12+a}while(i!=="IEND"&&s2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:i;if(Array.isArray(t))t.forEach(function(r){return n(e,r,i,s)});else if(typeof t=="function")t(e,i,s,n);else{var a=Object.keys(t)[0];Array.isArray(t[a])?(s[a]={},n(e,t[a],i,s[a])):s[a]=t[a](e,i,s,n)}return i};he.parse=fr;var gr=function(n,e){return function(t,i,s,a){e(t,i,s)&&a(t,n,i,s)}};he.conditional=gr;var vr=function(n,e){return function(t,i,s,a){for(var r=[],o=t.pos;e(t,i,s);){var h={};if(a(t,n,i,h),t.pos===o)break;o=t.pos,r.push(h)}return r}};he.loop=vr;var P={};Object.defineProperty(P,"__esModule",{value:!0}),P.readBits=P.readArray=P.readUnsigned=P.readString=P.peekBytes=P.readBytes=P.peekByte=P.readByte=P.buildStream=void 0;var yr=function(n){return{data:n,pos:0}};P.buildStream=yr;var Ei=function(){return function(n){return n.data[n.pos++]}};P.readByte=Ei;var br=function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+n]}};P.peekByte=br;var ot=function(n){return function(e){return e.data.subarray(e.pos,e.pos+=n)}};P.readBytes=ot;var wr=function(n){return function(e){return e.data.subarray(e.pos,e.pos+n)}};P.peekBytes=wr;var xr=function(n){return function(e){return Array.from(ot(n)(e)).map(function(t){return String.fromCharCode(t)}).join("")}};P.readString=xr;var Tr=function(n){return function(e){var t=ot(2)(e);return n?(t[1]<<8)+t[0]:(t[0]<<8)+t[1]}};P.readUnsigned=Tr;var Er=function(n,e){return function(t,i,s){for(var a=typeof e=="function"?e(t,i,s):e,r=ot(n),o=new Array(a),h=0;h=m){var g=m-l.pos;c.push((0,t.readBytes)(g)(l)),_+=g;break}c.push((0,t.readBytes)(f)(l)),_+=f}for(var v=new Uint8Array(_),p=0,w=0;w>=r,_-=r,l>i||l==o)break;if(l==s){a=(1<<(r=c+1))-1,i=s+2,u=y;continue}if(u==y){Y[g++]=T[l],u=l,f=l;continue}for(h=l,l==i&&(Y[g++]=f,l=u);l>s;)Y[g++]=T[l],l=z[l];f=255&T[l],Y[g++]=f,ih[l],width:s,height:a}}Mi=fe.decompressFrames=Ir;const kr=[71,73,70];function Nr(n){const e=new Uint8Array(n);return!kr.some((t,i)=>t!==e[i])}function Lr(n){if(!Nr(n))return!1;const e=new DataView(n),t=e.getUint8(10);let i=13+(128&t?3*2**(1+(7&t)):0),s=0,a=!1;for(;!a;){switch(e.getUint8(i++)){case 33:if(!r())return!1;break;case 44:o();break;case 59:a=!0;break;default:return!1}if(s>1)return!0}function r(){switch(e.getUint8(i++)){case 249:h();break;case 1:u();break;case 254:l();break;case 255:d();break;default:return!1}return!0}function o(){s++,i+=8;const m=e.getUint8(i++);i+=128&m?3*2**(1+(7&m)):0,i++,c()}function h(){i++,i+=4,c()}function u(){s++,i++,i+=12,c()}function l(){c()}function d(){i++,i+=8,i+=3,c()}function c(){let m;for(;m=e.getUint8(i++);)i+=m}return!1}class Gr{constructor(){this._resourceMap=new Map,this._inFlightResourceMap=new Map,this.geometryEngine=null}destroy(){this._inFlightResourceMap.clear(),this._resourceMap.clear()}getResource(e){var t;return(t=this._resourceMap.get(e))!=null?t:null}async fetchResource(e,t){const i=this._resourceMap.get(e);if(i)return{width:i.width,height:i.height};const s=this._inFlightResourceMap.get(e);if(s)return s.then(r=>({width:r.width,height:r.height}));const a=Hr(e,t);return this._inFlightResourceMap.set(e,s),a.then(r=>(this._inFlightResourceMap.delete(e),this._resourceMap.set(e,r),{width:r.width,height:r.height}),()=>({width:0,height:0}))}deleteResource(e){this._inFlightResourceMap.delete(e),this._resourceMap.delete(e)}}async function Vr(n,e){const t=window.URL.createObjectURL(n);try{const{data:i}=await xe(t,{...e,responseType:"image"});return i}catch(i){throw Je(i)?i:new Q("mapview-invalid-resource",`Could not fetch requested resource at ${t}`)}finally{window.URL.revokeObjectURL(t)}}async function Hr(n,e){const{arrayBuffer:t,mediaType:i}=await qr(n,e),s=i==="image/png";return i==="image/gif"&&Lr(t)?Ur(t):s&&pr(t)?cr(t,e):Vr(new Blob([t],{type:i}),e)}async function qr(n,e){let t;const i=";base64,";if(n.includes(i)){const s=n.indexOf(i),a=n.indexOf(i)+i.length,r=n.substring(a),o=atob(r),h=new Uint8Array(o.length);for(let u=0;u=c||d>=c){const m=l/d;m>1?(l=c,d=Math.round(c/m)):(d=c,l=Math.round(c*m)),u=new Uint8Array(4*l*d);const _=new Uint8ClampedArray(u.buffer);Hs(o,e,t,_,l,d,!1)}return{size:[l,d],image:new Uint32Array(u.buffer),sdf:!1,simplePattern:!1,anchorX:0,anchorY:0}}}const Yr={background:{"background.frag":`#ifdef PATTERN uniform lowp float u_opacity; uniform lowp sampler2D u_texture; varying mediump vec4 v_tlbr; varying mediump vec2 v_tileTextureCoord; #else uniform lowp vec4 u_color; #endif #ifdef ID varying mediump vec4 v_id; #endif void main() { #ifdef PATTERN mediump vec2 normalizedTextureCoord = mod(v_tileTextureCoord, 1.0); mediump vec2 samplePos = mix(v_tlbr.xy, v_tlbr.zw, normalizedTextureCoord); lowp vec4 color = texture2D(u_texture, samplePos); gl_FragColor = u_opacity * color; #else gl_FragColor = u_color; #endif #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"background.vert":`precision mediump float; attribute vec2 a_pos; #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif uniform highp mat3 u_dvsMat3; uniform mediump float u_coord_range; uniform mediump float u_depth; #ifdef PATTERN uniform mediump mat3 u_pattern_matrix; varying mediump vec2 v_tileTextureCoord; uniform mediump vec4 u_tlbr; uniform mediump vec2 u_mosaicSize; varying mediump vec4 v_tlbr; #endif void main() { gl_Position = vec4((u_dvsMat3 * vec3(u_coord_range * a_pos, 1.0)).xy, u_depth, 1.0); #ifdef PATTERN v_tileTextureCoord = (u_pattern_matrix * vec3(a_pos, 1.0)).xy; v_tlbr = u_tlbr / u_mosaicSize.xyxy; #endif #ifdef ID v_id = u_id / 255.0; #endif }`},circle:{"circle.frag":`precision lowp float; varying lowp vec4 v_color; varying lowp vec4 v_stroke_color; varying mediump float v_blur; varying mediump float v_stroke_width; varying mediump float v_radius; varying mediump vec2 v_offset; #ifdef ID varying mediump vec4 v_id; #endif void main() { mediump float dist = length(v_offset); mediump float alpha = smoothstep(0.0, -v_blur, dist - 1.0); lowp float color_mix_ratio = v_stroke_width < 0.01 ? 0.0 : smoothstep(-v_blur, 0.0, dist - v_radius / (v_radius + v_stroke_width)); gl_FragColor = alpha * mix(v_color, v_stroke_color, color_mix_ratio); #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"circle.vert":`precision mediump float; attribute vec2 a_pos; #pragma header varying lowp vec4 v_color; varying lowp vec4 v_stroke_color; varying mediump float v_blur; varying mediump float v_stroke_width; varying mediump float v_radius; varying mediump vec2 v_offset; #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform mediump vec2 u_circleTranslation; uniform mediump float u_depth; uniform mediump float u_antialiasingWidth; void main() { #pragma main v_color = color * opacity; v_stroke_color = stroke_color * stroke_opacity; v_stroke_width = stroke_width; v_radius = radius; v_blur = max(blur, u_antialiasingWidth / (radius + stroke_width)); mediump vec2 offset = vec2(mod(a_pos, 2.0) * 2.0 - 1.0); v_offset = offset; #ifdef ID v_id = u_id / 255.0; #endif mediump vec3 pos = u_dvsMat3 * vec3(a_pos * 0.5, 1.0) + u_displayMat3 * vec3((v_radius + v_stroke_width) * offset + u_circleTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth, 1.0); }`},fill:{"fill.frag":`precision lowp float; #ifdef PATTERN uniform lowp sampler2D u_texture; varying mediump vec2 v_tileTextureCoord; varying mediump vec4 v_tlbr; #endif #ifdef ID varying mediump vec4 v_id; #endif varying lowp vec4 v_color; vec4 mixColors(vec4 color1, vec4 color2) { float compositeAlpha = color2.a + color1.a * (1.0 - color2.a); vec3 compositeColor = color2.rgb + color1.rgb * (1.0 - color2.a); return vec4(compositeColor, compositeAlpha); } void main() { #ifdef PATTERN mediump vec2 normalizedTextureCoord = fract(v_tileTextureCoord); mediump vec2 samplePos = mix(v_tlbr.xy, v_tlbr.zw, normalizedTextureCoord); lowp vec4 color = texture2D(u_texture, samplePos); gl_FragColor = v_color[3] * color; #else gl_FragColor = v_color; #endif #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"fill.vert":`precision mediump float; attribute vec2 a_pos; #pragma header uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform mediump float u_depth; uniform mediump vec2 u_fillTranslation; #ifdef PATTERN #include uniform mediump vec2 u_mosaicSize; uniform mediump float u_patternFactor; varying mediump vec2 v_tileTextureCoord; varying mediump vec4 v_tlbr; #endif #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif varying lowp vec4 v_color; void main() { #pragma main v_color = color * opacity; #ifdef ID v_id = u_id / 255.0; #endif #ifdef PATTERN float patternWidth = nextPOT(tlbr.z - tlbr.x); float patternHeight = nextPOT(tlbr.w - tlbr.y); float scaleX = 1.0 / (patternWidth * u_patternFactor); float scaleY = 1.0 / (patternHeight * u_patternFactor); mat3 patterMat = mat3(scaleX, 0.0, 0.0, 0.0, -scaleY, 0.0, 0.0, 0.0, 1.0); v_tileTextureCoord = (patterMat * vec3(a_pos, 1.0)).xy; v_tlbr = tlbr / u_mosaicSize.xyxy; #endif vec3 pos = u_dvsMat3 * vec3(a_pos, 1.0) + u_displayMat3 * vec3(u_fillTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth, 1.0); }`},icon:{"icon.frag":`precision mediump float; uniform lowp sampler2D u_texture; #ifdef SDF uniform lowp vec4 u_color; uniform lowp vec4 u_outlineColor; #endif varying mediump vec2 v_tex; varying lowp float v_opacity; varying mediump vec2 v_size; varying lowp vec4 v_color; #ifdef SDF varying mediump flaot v_halo_width; #endif #ifdef ID varying mediump vec4 v_id; #endif #include vec4 mixColors(vec4 color1, vec4 color2) { float compositeAlpha = color2.a + color1.a * (1.0 - color2.a); vec3 compositeColor = color2.rgb + color1.rgb * (1.0 - color2.a); return vec4(compositeColor, compositeAlpha); } void main() { #ifdef SDF lowp vec4 fillPixelColor = v_color; float d = rgba2float(texture2D(u_texture, v_tex)) - 0.5; const float softEdgeRatio = 0.248062016; float size = max(v_size.x, v_size.y); float dist = d * softEdgeRatio * size; fillPixelColor *= clamp(0.5 - dist, 0.0, 1.0); if (v_halo_width > 0.25) { lowp vec4 outlinePixelColor = u_outlineColor; const float outlineLimitRatio = (16.0 / 86.0); float clampedOutlineSize = softEdgeRatio * min(v_halo_width, outlineLimitRatio * max(v_size.x, v_size.y)); outlinePixelColor *= clamp(0.5 - (abs(dist) - clampedOutlineSize), 0.0, 1.0); gl_FragColor = v_opacity * mixColors(fillPixelColor, outlinePixelColor); } else { gl_FragColor = v_opacity * fillPixelColor; } #else lowp vec4 texColor = texture2D(u_texture, v_tex); gl_FragColor = v_opacity * texColor; #endif #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"icon.vert":`attribute vec2 a_pos; attribute vec2 a_vertexOffset; attribute vec4 a_texAngleRange; attribute vec4 a_levelInfo; attribute float a_opacityInfo; #pragma header #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif varying lowp vec4 v_color; #ifdef SDF varying mediump float v_halo_width; #endif uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform highp mat3 u_displayViewMat3; uniform mediump vec2 u_iconTranslation; uniform vec2 u_mosaicSize; uniform mediump float u_depth; uniform mediump float u_mapRotation; uniform mediump float u_level; uniform lowp float u_keepUpright; uniform mediump float u_fadeDuration; varying mediump vec2 v_tex; varying lowp float v_opacity; varying mediump vec2 v_size; const float C_OFFSET_PRECISION = 1.0 / 8.0; const float C_256_TO_RAD = 3.14159265359 / 128.0; const float C_DEG_TO_RAD = 3.14159265359 / 180.0; const float tileCoordRatio = 1.0 / 8.0; uniform highp float u_time; void main() { #pragma main v_color = color; v_opacity = opacity; #ifdef SDF v_halo_width = halo_width; #endif float modded = mod(a_opacityInfo, 128.0); float targetOpacity = (a_opacityInfo - modded) / 128.0; float startOpacity = modded / 127.0; float interpolatedOpacity = clamp(startOpacity + 2.0 * (targetOpacity - 0.5) * u_time / u_fadeDuration, 0.0, 1.0); v_opacity *= interpolatedOpacity; mediump float a_angle = a_levelInfo[1]; mediump float a_minLevel = a_levelInfo[2]; mediump float a_maxLevel = a_levelInfo[3]; mediump vec2 a_tex = a_texAngleRange.xy; mediump float delta_z = 0.0; mediump float rotated = mod(a_angle + u_mapRotation, 256.0); delta_z += (1.0 - step(u_keepUpright, 0.0)) * step(64.0, rotated) * (1.0 - step(192.0, rotated)); delta_z += 1.0 - step(a_minLevel, u_level); delta_z += step(a_maxLevel, u_level); delta_z += step(v_opacity, 0.0); vec2 offset = C_OFFSET_PRECISION * a_vertexOffset; v_size = abs(offset); #ifdef SDF offset = (120.0 / 86.0) * offset; #endif mediump vec3 pos = u_dvsMat3 * vec3(a_pos, 1.0) + u_displayViewMat3 * vec3(size * offset, 0.0) + u_displayMat3 * vec3(u_iconTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth + delta_z, 1.0); #ifdef ID v_id = u_id / 255.0; #endif v_tex = a_tex.xy / u_mosaicSize; }`},line:{"line.frag":`precision lowp float; varying mediump vec2 v_normal; varying highp float v_accumulatedDistance; varying mediump float v_lineHalfWidth; varying lowp vec4 v_color; varying mediump float v_blur; #if defined (PATTERN) || defined(SDF) varying mediump vec4 v_tlbr; varying mediump vec2 v_patternSize; varying mediump float v_widthRatio; uniform sampler2D u_texture; uniform mediump float u_antialiasing; #endif #ifdef SDF #include #endif #ifdef ID varying mediump vec4 v_id; #endif void main() { mediump float fragDist = length(v_normal) * v_lineHalfWidth; lowp float alpha = clamp((v_lineHalfWidth - fragDist) / v_blur, 0.0, 1.0); #ifdef PATTERN mediump float relativeTexX = fract(v_accumulatedDistance / (v_patternSize.x * v_widthRatio)); mediump float relativeTexY = 0.5 + v_normal.y * v_lineHalfWidth / (v_patternSize.y * v_widthRatio); mediump vec2 texCoord = mix(v_tlbr.xy, v_tlbr.zw, vec2(relativeTexX, relativeTexY)); lowp vec4 color = texture2D(u_texture, texCoord); gl_FragColor = alpha * v_color[3] * color; #elif defined(SDF) mediump float relativeTexX = fract((v_accumulatedDistance * 0.5) / (v_patternSize.x * v_widthRatio)); mediump float relativeTexY = 0.5 + 0.25 * v_normal.y; mediump vec2 texCoord = mix(v_tlbr.xy, v_tlbr.zw, vec2(relativeTexX, relativeTexY)); mediump float d = rgba2float(texture2D(u_texture, texCoord)) - 0.5; float dist = d * (v_lineHalfWidth + u_antialiasing / 2.0); gl_FragColor = alpha * clamp(0.5 - dist, 0.0, 1.0) * v_color; #else gl_FragColor = alpha * v_color; #endif #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"line.vert":`precision mediump float; attribute vec2 a_pos; attribute vec4 a_extrude_offset; attribute vec4 a_dir_normal; attribute vec2 a_accumulatedDistance; #pragma header uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform highp mat3 u_displayViewMat3; uniform mediump float u_zoomFactor; uniform mediump vec2 u_lineTranslation; uniform mediump float u_antialiasing; uniform mediump float u_depth; varying mediump vec2 v_normal; varying highp float v_accumulatedDistance; const float scale = 1.0 / 31.0; const mediump float tileCoordRatio = 8.0; #if defined (SDF) const mediump float sdfPatternHalfWidth = 15.5; #endif #if defined (PATTERN) || defined(SDF) uniform mediump vec2 u_mosaicSize; varying mediump vec4 v_tlbr; varying mediump vec2 v_patternSize; varying mediump float v_widthRatio; #endif #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif varying lowp vec4 v_color; varying mediump float v_lineHalfWidth; varying mediump float v_blur; void main() { #pragma main v_color = color * opacity; v_blur = blur + u_antialiasing; v_normal = a_dir_normal.zw * scale; #if defined (PATTERN) || defined(SDF) v_tlbr = tlbr / u_mosaicSize.xyxy; v_patternSize = vec2(tlbr.z - tlbr.x, tlbr.y - tlbr.w); #if defined (PATTERN) v_widthRatio = width / v_patternSize.y; #else v_widthRatio = width / sdfPatternHalfWidth / 2.0; #endif #endif v_lineHalfWidth = (width + u_antialiasing) * 0.5; mediump vec2 dir = a_dir_normal.xy * scale; mediump vec2 offset_ = a_extrude_offset.zw * scale * offset; mediump vec2 dist = v_lineHalfWidth * scale * a_extrude_offset.xy; mediump vec3 pos = u_dvsMat3 * vec3(a_pos + offset_ * tileCoordRatio / u_zoomFactor, 1.0) + u_displayViewMat3 * vec3(dist, 0.0) + u_displayMat3 * vec3(u_lineTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth, 1.0); #if defined (PATTERN) || defined(SDF) v_accumulatedDistance = a_accumulatedDistance.x * u_zoomFactor / tileCoordRatio + dot(dir, dist + offset_); #endif #ifdef ID v_id = u_id / 255.0; #endif }`},outline:{"outline.frag":`varying lowp vec4 v_color; varying mediump vec2 v_normal; #ifdef ID varying mediump vec4 v_id; #endif void main() { lowp float dist = abs(v_normal.y); lowp float alpha = smoothstep(1.0, 0.0, dist); gl_FragColor = alpha * v_color; #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"outline.vert":`attribute vec2 a_pos; attribute vec2 a_offset; attribute vec2 a_xnormal; #pragma header varying lowp vec4 v_color; #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform mediump vec2 u_fillTranslation; uniform mediump float u_depth; uniform mediump float u_outline_width; varying lowp vec2 v_normal; const float scale = 1.0 / 15.0; void main() { #pragma main v_color = color * opacity; #ifdef ID v_id = u_id / 255.0; #endif v_normal = a_xnormal; mediump vec2 dist = u_outline_width * scale * a_offset; mediump vec3 pos = u_dvsMat3 * vec3(a_pos, 1.0) + u_displayMat3 * vec3(dist + u_fillTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth, 1.0); }`},text:{"text.frag":`uniform lowp sampler2D u_texture; varying lowp vec2 v_tex; varying lowp vec4 v_color; varying mediump float v_edgeWidth; varying mediump float v_edgeDistance; #ifdef ID varying mediump vec4 v_id; #endif void main() { lowp float dist = texture2D(u_texture, v_tex).a; mediump float alpha = smoothstep(v_edgeDistance - v_edgeWidth, v_edgeDistance + v_edgeWidth, dist); gl_FragColor = alpha * v_color; #ifdef ID if (gl_FragColor.a < 1.0 / 255.0) { discard; } gl_FragColor = v_id; #endif }`,"text.vert":`attribute vec2 a_pos; attribute vec2 a_vertexOffset; attribute vec4 a_texAngleRange; attribute vec4 a_levelInfo; attribute float a_opacityInfo; #pragma header varying lowp vec4 v_color; #ifdef ID uniform mediump vec4 u_id; varying mediump vec4 v_id; #endif uniform highp mat3 u_dvsMat3; uniform highp mat3 u_displayMat3; uniform highp mat3 u_displayViewMat3; uniform mediump vec2 u_textTranslation; uniform vec2 u_mosaicSize; uniform mediump float u_depth; uniform mediump float u_mapRotation; uniform mediump float u_level; uniform lowp float u_keepUpright; uniform mediump float u_fadeDuration; varying lowp vec2 v_tex; const float offsetPrecision = 1.0 / 8.0; const mediump float edgePos = 0.75; uniform mediump float u_antialiasingWidth; varying mediump float v_edgeDistance; varying mediump float v_edgeWidth; uniform lowp float u_halo; const float sdfFontScale = 1.0 / 24.0; const float sdfPixel = 3.0; uniform highp float u_time; void main() { #pragma main if (u_halo > 0.5) { v_color = halo_color * opacity; halo_width *= sdfPixel; halo_blur *= sdfPixel; } else { v_color = color * opacity; halo_width = 0.0; halo_blur = 0.0; } float modded = mod(a_opacityInfo, 128.0); float targetOpacity = (a_opacityInfo - modded) / 128.0; float startOpacity = modded / 127.0; float interpolatedOpacity = clamp(startOpacity + 2.0 * (targetOpacity - 0.5) * u_time / u_fadeDuration, 0.0, 1.0); v_color *= interpolatedOpacity; mediump float a_angle = a_levelInfo[1]; mediump float a_minLevel = a_levelInfo[2]; mediump float a_maxLevel = a_levelInfo[3]; mediump vec2 a_tex = a_texAngleRange.xy; mediump float a_visMinAngle = a_texAngleRange.z; mediump float a_visMaxAngle = a_texAngleRange.w; mediump float delta_z = 0.0; mediump float angle = mod(a_angle + u_mapRotation, 256.0); if (a_visMinAngle < a_visMaxAngle) { delta_z += (1.0 - step(u_keepUpright, 0.0)) * (step(a_visMaxAngle, angle) + (1.0 - step(a_visMinAngle, angle))); } else { delta_z += (1.0 - step(u_keepUpright, 0.0)) * (step(a_visMaxAngle, angle) * (1.0 - step(a_visMinAngle, angle))); } delta_z += 1.0 - step(a_minLevel, u_level); delta_z += step(a_maxLevel, u_level); delta_z += step(v_color[3], 0.0); v_tex = a_tex.xy / u_mosaicSize; #ifdef ID v_id = u_id / 255.0; #endif v_edgeDistance = edgePos - halo_width / size; v_edgeWidth = (u_antialiasingWidth + halo_blur) / size; mediump vec3 pos = u_dvsMat3 * vec3(a_pos, 1.0) + sdfFontScale * u_displayViewMat3 * vec3(offsetPrecision * size * a_vertexOffset, 0.0) + u_displayMat3 * vec3(u_textTranslation, 0.0); gl_Position = vec4(pos.xy, u_depth + delta_z, 1.0); }`},util:{"encoding.glsl":`const vec4 rgba2float_factors = vec4( 255.0 / (256.0), 255.0 / (256.0 * 256.0), 255.0 / (256.0 * 256.0 * 256.0), 255.0 / (256.0 * 256.0 * 256.0 * 256.0) ); float rgba2float(vec4 rgba) { return dot(rgba, rgba2float_factors); }`,"util.glsl":`float nextPOT(in float x) { return pow(2.0, ceil(log2(abs(x)))); }`}};function Xr(n){let e=Yr;return n.split("/").forEach(t=>{e&&(e=e[t])}),e}const Zr=new Us(Xr);function L(n){return Zr.resolveIncludes(n)}const Xt=n=>ve({ID:n.id,PATTERN:n.pattern}),Kr={shaders:n=>({vertexShader:Xt(n)+L("background/background.vert"),fragmentShader:Xt(n)+L("background/background.frag")})},Zt=n=>ve({ID:n.id}),Qr={shaders:n=>({vertexShader:Zt(n)+L("circle/circle.vert"),fragmentShader:Zt(n)+L("circle/circle.frag")})},Kt=n=>ve({ID:n.id,PATTERN:n.pattern}),Jr={shaders:n=>({vertexShader:Kt(n)+L("fill/fill.vert"),fragmentShader:Kt(n)+L("fill/fill.frag")})},Qt=n=>ve({ID:n.id}),en={shaders:n=>({vertexShader:Qt(n)+L("outline/outline.vert"),fragmentShader:Qt(n)+L("outline/outline.frag")})},Jt=n=>ve({ID:n.id,SDF:n.sdf}),tn={shaders:n=>({vertexShader:Jt(n)+L("icon/icon.vert"),fragmentShader:Jt(n)+L("icon/icon.frag")})},ei=n=>ve({ID:n.id,PATTERN:n.pattern,SDF:n.sdf}),sn={shaders:n=>({vertexShader:ei(n)+L("line/line.vert"),fragmentShader:ei(n)+L("line/line.frag")})},ti=n=>ve({ID:n.id}),rn={shaders:n=>({vertexShader:ti(n)+L("text/text.vert"),fragmentShader:ti(n)+L("text/text.frag")})};class nn{constructor(){this._programByKey=new Map}dispose(){this._programByKey.forEach(e=>e.dispose()),this._programByKey.clear()}getMaterialProgram(e,t,i){const s=t.key<<3|this._getMaterialOptionsValue(t.type,i);if(this._programByKey.has(s))return this._programByKey.get(s);const a=this._getProgramTemplate(t.type),{shaders:r}=a,{vertexShader:o,fragmentShader:h}=r(i),u=t.getShaderHeader(),l=t.getShaderMain(),d=o.replace("#pragma header",u).replace("#pragma main",l),c=e.programCache.acquire(d,h,t.getAttributeLocations());return this._programByKey.set(s,c),c}_getMaterialOptionsValue(e,t){switch(e){case I.BACKGROUND:{const i=t;return(i.pattern?1:0)<<1|(i.id?1:0)}case I.FILL:{const i=t;return(i.pattern?1:0)<<1|(i.id?1:0)}case I.OUTLINE:return t.id?1:0;case I.LINE:{const i=t;return(i.sdf?1:0)<<2|(i.pattern?1:0)<<1|(i.id?1:0)}case I.ICON:{const i=t;return(i.sdf?1:0)<<1|(i.id?1:0)}case I.CIRCLE:return t.id?1:0;case I.TEXT:return t.id?1:0;default:return 0}}_getProgramTemplate(e){switch(e){case I.BACKGROUND:return Kr;case I.CIRCLE:return Qr;case I.FILL:return Jr;case I.ICON:return tn;case I.LINE:return sn;case I.OUTLINE:return en;case I.TEXT:return rn;default:return null}}}const ii={shaders:{vertexShader:j("bitBlit/bitBlit.vert"),fragmentShader:j("bitBlit/bitBlit.frag")},attributes:new Map([["a_pos",0],["a_tex",1]])};class Bi{constructor(){this._initialized=!1}dispose(){this._program=U(this._program),this._vertexArrayObject=U(this._vertexArrayObject)}render(e,t,i,s){e&&(this._initialized||this._initialize(e),e.setBlendFunctionSeparate(M.ONE,M.ONE_MINUS_SRC_ALPHA,M.ONE,M.ONE_MINUS_SRC_ALPHA),e.bindVAO(this._vertexArrayObject),e.useProgram(this._program),t.setSamplingMode(i),e.bindTexture(t,0),this._program.setUniform1i("u_tex",0),this._program.setUniform1f("u_opacity",s),e.drawArrays(Ae.TRIANGLE_STRIP,0,4),e.bindTexture(null,0),e.bindVAO())}_initialize(e){if(this._initialized)return!0;const t=Le(e,ii);if(!t)return!1;const i=new Int8Array(16);i[0]=-1,i[1]=-1,i[2]=0,i[3]=0,i[4]=1,i[5]=-1,i[6]=1,i[7]=0,i[8]=-1,i[9]=1,i[10]=0,i[11]=1,i[12]=1,i[13]=1,i[14]=1,i[15]=1;const s=ii.attributes,a=new Et(e,s,$s,{geometry:Mt.createVertex(e,Rt.STATIC_DRAW,i)});return this._program=t,this._vertexArrayObject=a,this._initialized=!0,!0}}const Ci=n=>n===k.HITTEST||n===k.LABEL_ALPHA,an=n=>(Ci(n)?1:0)|(n===k.HIGHLIGHT?2:0),on=({rendererInfo:n,drawPhase:e},t,i,s)=>`${t.getVariationHash()}-${s.join(".")}-${an(e)}-${n.getVariationHash()}-${F(i)&&i.join(".")}`,hn=(n,e,t,i)=>{const s=i.reduce((r,o)=>({...r,[o]:n.context.driverTest[o]}),{}),a={...e.getVariation(),...n.rendererInfo.getVariation(),highlight:n.drawPhase===k.HIGHLIGHT,id:Ci(n.drawPhase),...s};if(F(t))for(const r of t)a[r]=!0;return a};class ln{constructor(e){this._rctx=e,this._programByKey=new Map}dispose(){this._programByKey.forEach(e=>e.dispose()),this._programByKey.clear()}getProgram(e,t=[],i=[]){const s=e.vsPath+"."+e.fsPath+JSON.stringify(t)+i.join(".");if(this._programByKey.has(s))return this._programByKey.get(s);const a=i.reduce((c,m)=>({...c,[m]:this._rctx.driverTest[m]}),{}),r={...t.map(c=>typeof c=="string"?{name:c,value:!0}:c).reduce((c,m)=>({...c,[m.name]:m.value}),{}),...a},{vsPath:o,fsPath:h,attributes:u}=e,l=kt(o,h,u,r),d=this._rctx.programCache.acquire(l.shaders.vertexShader,l.shaders.fragmentShader,l.attributes);if(!d)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(s,d),d}getMaterialProgram(e,t,i,s,a,r=["ignoresSamplerPrecision"]){const o=on(e,t,a,r);if(this._programByKey.has(o))return this._programByKey.get(o);const h=hn(e,t,a,r),u=kt(i,i,s,h),l=this._rctx.programCache.acquire(u.shaders.vertexShader,u.shaders.fragmentShader,u.attributes);if(!l)throw new Error("Unable to get program for key: ${key}");return this._programByKey.set(o,l),l}}class st{constructor(e,t){this._width=0,this._height=0,this._free=[],this._width=e,this._height=t,this._free.push(new q(0,0,e,t))}get width(){return this._width}get height(){return this._height}allocate(e,t){if(e>this._width||t>this._height)return new q;let i=null,s=-1;for(let a=0;ae&&this._free.push(new q(i.x+e,i.y,i.width-e,t)),i.height>t&&this._free.push(new q(i.x,i.y+t,i.width,i.height-t))):(i.width>e&&this._free.push(new q(i.x+e,i.y,i.width-e,i.height)),i.height>t&&this._free.push(new q(i.x,i.y+t,e,i.height-t))),new q(i.x,i.y,e,t))}release(e){for(let t=0;tMath.floor(n/256);function cn(n){const e=new Set;for(const t of n)e.add(dn(t));return e}function mn(n,e,t){return n.has(e)||n.set(e,t().then(()=>{n.delete(e)}).catch(i=>{n.delete(e),ki(i)})),n.get(e)}const _n=n=>({rect:new q(0,0,0,0),page:0,metrics:{left:0,width:0,height:0,advance:0,top:0},code:n,sdf:!0});class pn{constructor(e,t,i){this.width=0,this.height=0,this._dirties=[],this._glyphData=[],this._currentPage=0,this._glyphCache={},this._textures=[],this._rangePromises=new Map,this.width=e,this.height=t,this._glyphSource=i,this._binPack=new st(e-4,t-4),this._glyphData.push(new Uint8Array(e*t)),this._dirties.push(!0),this._textures.push(null),this._initDecorationGlyph()}dispose(){this._binPack=null;for(const e of this._textures)e&&e.dispose();this._textures.length=0,this._glyphData.length=0}_initDecorationGlyph(){const e=[117,149,181,207,207,181,149,117],t=[];for(let s=0;sthis._getMosaicItem(s,e,a))}bind(e,t,i,s){const a=this._getTexture(e,i);a.setSamplingMode(t),this._dirties[i]&&(a.setData(this._glyphData[i]),this._dirties[i]=!1),e.bindTexture(a,s)}_getGlyphCache(e){return this._glyphCache[e]||(this._glyphCache[e]={}),this._glyphCache[e]}_getTexture(e,t){return this._textures[t]||(this._textures[t]=new W(e,{pixelFormat:E.ALPHA,dataType:C.UNSIGNED_BYTE,width:this.width,height:this.height},new Uint8Array(this.width*this.height))),this._textures[t]}_invalidate(){this._dirties[this._currentPage]=!0}async _fetchRanges(e,t,i){const s=cn(t),a=[];s.forEach(r=>{a.push(this._fetchRange(e,r,i))}),await Promise.all(a)}async _fetchRange(e,t,i){if(t>un)return null;const s=e+t;return mn(this._rangePromises,s,()=>this._glyphSource.getRange(e,t,i))}_getMosaicItem(e,t,i){if(!e[i]){const s=this._glyphSource.getGlyph(t,i);if(!s||!s.metrics)return _n(i);const a=this._recordGlyph(s),r=this._currentPage,o=s.metrics;e[i]={rect:a,page:r,metrics:o,code:i,sdf:!0},this._invalidate()}return e[i]}_recordGlyph(e){const t=e.metrics;let i;if(t.width===0)i=new q(0,0,0,0);else{const a=t.width+6,r=t.height+2*3;i=this._binPack.allocate(a,r),i.isEmpty&&(this._dirties[this._currentPage]||(this._glyphData[this._currentPage]=null),this._currentPage=this._glyphData.length,this._glyphData.push(new Uint8Array(this.width*this.height)),this._dirties.push(!0),this._textures.push(null),this._initDecorationGlyph(),this._binPack=new st(this.width-4,this.height-4),i=this._binPack.allocate(a,r));const o=this._glyphData[this._currentPage],h=e.bitmap;let u,l;if(h)for(let d=0;d{s.addRange(t,new fn(new Ni(new Uint8Array(h.data),new DataView(h.data))))})}getGlyph(e,t){const i=this._getFontStack(e);if(!i)return;const s=Math.floor(t/256);if(s>256)return;const a=i.getRange(s);return a?{metrics:a.getMetrics(t),bitmap:a.getBitmap(t)}:void 0}_getFontStack(e){let t=this._glyphInfo[e];return t||(t=this._glyphInfo[e]=new gn),t}}const Be=1e20;class yn{constructor(e){this._svg=null,this.size=e;const t=document.createElement("canvas");t.width=t.height=e,this._context=t.getContext("2d"),this._gridOuter=new Float64Array(e*e),this._gridInner=new Float64Array(e*e),this._f=new Float64Array(e),this._d=new Float64Array(e),this._z=new Float64Array(e+1),this._v=new Int16Array(e)}dispose(){this._context=this._gridOuter=this._gridInner=this._f=this._d=this._z=this._v=null,this._svg&&(document.body.removeChild(this._svg),this._svg=null)}draw(e,t,i=31){this._initSVG();const s=this.createSVGString(e);return new Promise((a,r)=>{const o=new Image;o.src="data:image/svg+xml; charset=utf8, "+encodeURIComponent(s),o.onload=()=>{o.onload=null,this._context.clearRect(0,0,this.size,this.size),this._context.drawImage(o,0,0,this.size,this.size);const u=this._context.getImageData(0,0,this.size,this.size),l=new Uint8Array(this.size*this.size*4);for(let d=0;dr(Gi()))})}_initSVG(){if(!this._svg){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("style","position: absolute;"),e.setAttribute("width","0"),e.setAttribute("height","0"),e.setAttribute("aria-hidden","true"),e.setAttribute("role","presentation"),document.body.appendChild(e),this._svg=e}return this._svg}createSVGString(e){const t=this._initSVG(),i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",e),t.appendChild(i);const s=i.getBBox(),a=s.width/s.height,r=this.size/2;let o,h,u,l;if(a>1){h=o=r/s.width;const _=r*(1/a);u=this.size/4,l=r-_/2}else o=h=r/s.height,u=r-r*a/2,l=this.size/4;const d=-s.x*o+u,c=-s.y*h+l;i.setAttribute("style",`transform: matrix(${o}, 0, 0, ${h}, ${d}, ${c})`);const m=`${t.innerHTML}`;return t.removeChild(i),m}_edt(e,t,i){const s=this._f,a=this._d,r=this._v,o=this._z;for(let h=0;h0&&(this._maxItemSize=i),this.pixelRatio=window.devicePixelRatio||1,this._binPack=new st(this._pageWidth,this._pageHeight);const s=Math.floor(this._pageWidth),a=Math.floor(this._pageHeight);this._mosaicPages.push({mosaicsData:{type:"static",data:new Uint32Array(s*a)},size:[this._pageWidth,this._pageHeight],dirty:!0,texture:void 0})}getWidth(e){return e>=this._mosaicPages.length?-1:this._mosaicPages[e].size[0]}getHeight(e){return e>=this._mosaicPages.length?-1:this._mosaicPages[e].size[1]}getPageTexture(e){return e=this._mosaicPages.length)return;const t=this._mosaicPages[e.page],i=t.mosaicsData;if(!me(t.mosaicsData))throw new Q("mapview-invalid-resource","unsuitable data type!");const s=e.spriteData,a=i.data;a&&s||console.error("Source or target images are uninitialized!"),Ft._copyBits(s,e.spriteSize[0],0,0,a,e.pageSize[0],e.rect.x+ae,e.rect.y+ae,e.spriteSize[0],e.spriteSize[1],e.repeat),t.dirty=!0}_allocateImage(e,t){e+=2*ae,t+=2*ae;const i=Math.max(e,t);if(this._maxItemSize&&this._maxItemSizee+t,0))}function wn(n){const{width:e,height:t}=n;return{frameDurations:n.frameDurations.reverse(),getFrame:i=>{const s=n.frameDurations.length-1-i;return n.getFrame(s)},width:e,height:t}}function xn(n,e){const{width:t,height:i,getFrame:s}=n,a=e/Si(n);return{frameDurations:n.frameDurations.map(r=>V(r*a)),getFrame:s,width:t,height:i}}function Tn(n,e){const{width:t,height:i,getFrame:s}=n,a=n.frameDurations.slice(),r=a.shift();return a.unshift(V(r+e)),{frameDurations:a,getFrame:s,width:t,height:i}}function si(n,e){const{width:t,height:i,getFrame:s}=n,a=n.frameDurations.slice(),r=a.pop();return a.push(V(r+e)),{frameDurations:a,getFrame:s,width:t,height:i}}class En{constructor(e,t,i,s){this._animation=e,this._repeatType=i,this._onFrameData=s,this._direction=1,this._currentFrame=0,this.timeToFrame=this._animation.frameDurations[this._currentFrame];let a=0;for(;t>a;)a+=this.timeToFrame,this.nextFrame();const r=this._animation.getFrame(this._currentFrame);this._onFrameData(r)}nextFrame(){if(this._currentFrame+=this._direction,this._direction>0){if(this._currentFrame===this._animation.frameDurations.length)switch(this._repeatType){case oe.None:this._currentFrame-=this._direction;break;case oe.Loop:this._currentFrame=0;break;case oe.Oscillate:this._currentFrame-=this._direction,this._direction=-1}}else if(this._currentFrame===-1)switch(this._repeatType){case oe.None:this._currentFrame-=this._direction;break;case oe.Loop:this._currentFrame=this._animation.frameDurations.length-1;break;case oe.Oscillate:this._currentFrame-=this._direction,this._direction=1}this.timeToFrame=this._animation.frameDurations[this._currentFrame];const e=this._animation.getFrame(this._currentFrame);this._onFrameData(e)}}function Mn(n,e,t,i){let s,{repeatType:a}=e;if(a==null&&(a=oe.Loop),e.reverseAnimation===!0&&(n=wn(n)),e.duration!=null&&(n=xn(n,V(1e3*e.duration))),e.repeatDelay!=null){const r=1e3*e.repeatDelay;a===oe.Loop?n=si(n,V(r)):a===oe.Oscillate&&(n=Tn(si(n,V(r/2)),V(r/2)))}if(e.startTimeOffset!=null)s=V(1e3*e.startTimeOffset);else if(e.randomizeStartTime!=null){const r=Ws(t),o=82749913,h=e.randomizeStartSeed!=null?e.randomizeStartSeed:o,u=js(r,h);s=V(u*Si(n))}else s=V(0);return new En(n,s,a,i)}function Rn(n,e,t,i){const s=e.playAnimation==null||e.playAnimation,a=Mn(n,e,t,i);let r,o=a.timeToFrame;function h(){r=s&&setTimeout(()=>{a.nextFrame(),o=a.timeToFrame,h()},o)}return h(),{remove:()=>{s&&clearTimeout(r)}}}class Fn{constructor(e,t,i,s){this._animation=e,this._frameData=null;const a=r=>{this._frameData=r,t.requestRender()};this.frameCount=this._animation.frameDurations.length,this.width=this._animation.width,this.height=this._animation.height,this._playHandle=Rn(this._animation,i,s,a)}destroy(){this._playHandle.remove()}bindFrame(e,t,i){e.bindTexture(t,i),N(this._frameData)||(t.updateData(0,ae,ae,this._frameData.width,this._frameData.height,this._frameData),this._frameData=null)}}function Bn(n){switch(n.type){case"esriSMS":return`${n.style}.${n.path}`;case"esriSLS":return`${n.style}.${n.cap}`;case"esriSFS":return`${n.style}`;case"esriPFS":case"esriPMS":return n.imageData?`${n.imageData}${n.width}${n.height}`:`${n.url}${n.width}${n.height}`;default:return"mosaicHash"in n?n.mosaicHash:JSON.stringify(n)}}const ri=qi(),ni="arial-unicode-ms-regular",dt=126,Pi=xt.getLogger("esri.views.2d.engine.webgl.TextureManager");function ai(n,e){const t=Math.round(de(e)*window.devicePixelRatio),i=t>=128?2:4;return Math.min(n,t*i)}const ct=(n,e,t)=>Pi.error(new Q(n,e,t));class Bt{constructor(e,t,i){this.mosaicType=e,this.page=t,this.sdf=i}static fromMosaic(e,t){return new Bt(e,t.page,t.sdf)}}class Cn{constructor(e,t){this._requestRender=e,this.resourceManager=t,this._invalidFontsMap=new Map,this._sdfConverter=new yn(dt),this._bindingInfos=new Array,this._hashToBindingIndex=new Map,this._ongoingRasterizations=new Map,this._imageRequestQueue=new Vi({concurrency:10,process:async(i,s)=>{rt(s);try{return await xe(i,{responseType:"image",signal:s})}catch(a){throw Je(a)?a:new Q("mapview-invalid-resource",`Could not fetch requested resource at ${i}`,a)}}}),this._spriteMosaic=new Ft(2048,2048,500),this._glyphSource=new vn(`${Hi.fontsUrl}/{fontstack}/{range}.pbf`),this._glyphMosaic=new pn(1024,1024,this._glyphSource),this._rasterizer=new jr(t)}dispose(){this._spriteMosaic.dispose(),this._glyphMosaic.dispose(),this._rasterizer.dispose(),this._sdfConverter.dispose(),this._spriteMosaic=null,this._glyphMosaic=null,this._sdfConverter=null,this._hashToBindingIndex.clear(),this._hashToBindingIndex=null,this._bindingInfos=null,this._ongoingRasterizations.clear(),this._ongoingRasterizations=null,this._imageRequestQueue.clear(),this._imageRequestQueue=null}get sprites(){return this._spriteMosaic}get glyphs(){return this._glyphMosaic}async rasterizeItem(e,t,i,s){if(N(e))return ct("mapview-null-resource","Unable to rasterize null resource"),null;switch(e.type){case"text":case"esriTS":{const a=await this._rasterizeText(e,i,s);return a.forEach(r=>this._setTextureBinding(Ve.GLYPH,r)),{glyphMosaicItems:a}}default:{if(Bs(e))return ct("mapview-invalid-type",`MapView does not support symbol type: ${e.type}`,e),null;const a=await this._rasterizeSpriteSymbol(e,t,s);return or(a)&&a&&this._setTextureBinding(Ve.SPRITE,a),{spriteMosaicItem:a}}}}bindTextures(e,t,i,s=!1){if(i.textureBinding===0)return;const a=this._bindingInfos[i.textureBinding-1],r=a.page,o=s?B.LINEAR_MIPMAP_LINEAR:B.LINEAR;switch(a.mosaicType){case Ve.SPRITE:{const h=this.sprites.getWidth(r),u=this.sprites.getHeight(r),l=ke(ri,h,u);return this._spriteMosaic.bind(e,o,r,Vt),t.setUniform1i("u_texture",Vt),void t.setUniform2fv("u_mosaicSize",l)}case Ve.GLYPH:{const h=this.glyphs.width,u=this.glyphs.height,l=ke(ri,h,u);return this._glyphMosaic.bind(e,o,r,Gt),t.setUniform1i("u_texture",Gt),void t.setUniform2fv("u_mosaicSize",l)}default:Pi.error("mapview-texture-manager",`Cannot handle unknown type ${a.mosaicType}`)}}_hashMosaic(e,t){return 1|e<<1|(t.sdf?1:0)<<2|t.page<<3}_setTextureBinding(e,t){const i=this._hashMosaic(e,t);if(!this._hashToBindingIndex.has(i)){const s=Bt.fromMosaic(e,t),a=this._bindingInfos.length+1;this._hashToBindingIndex.set(i,a),this._bindingInfos.push(s)}t.textureBinding=this._hashToBindingIndex.get(i)}async _rasterizeText(e,t,i){let s,a;if("cim"in e){const h=e;s=h.fontName,a=h.text}else{const h=e;s=Ys(h.font),a=h.text}const r=this._invalidFontsMap.has(s),o=t||Cs(Xs(a)[0]);try{return await this._glyphMosaic.getGlyphItems(r?ni:s,o,i)}catch{return ct("mapview-invalid-resource",`Couldn't find font ${s}. Falling back to Arial Unicode MS Regular`),this._invalidFontsMap.set(s,!0),this._glyphMosaic.getGlyphItems(ni,o,i)}}async _rasterizeSpriteSymbol(e,t,i){if(Ss(e))return null;const s=Bn(e);if(this._spriteMosaic.has(s))return this._spriteMosaic.getSpriteItem(s);if(zt(e)||Ps(e)&&!Os(e))return this._handleAsyncResource(s,e,i);const a=Qs,r=this._rasterizer.rasterizeJSONResource(e,a);if(r){const{size:o,image:h,sdf:u,simplePattern:l,rasterizationScale:d}=r;return this._addItemToMosaic(s,o,{type:"static",data:h},He(e),u,l,d)}return new Q("TextureManager","unrecognized or null rasterized image")}async _handleAsyncResource(e,t,i){if(this._ongoingRasterizations.has(e))return this._ongoingRasterizations.get(e);let s;s=zt(t)?this._handleSVG(t,e,i):this._handleImage(t,e,i),this._ongoingRasterizations.set(e,s);try{await s,this._ongoingRasterizations.delete(e)}catch{this._ongoingRasterizations.delete(e)}return s}async _handleSVG(e,t,i){const s=[dt,dt],a=await this._sdfConverter.draw(e.path,i);return this._addItemToMosaic(t,s,{type:"static",data:new Uint32Array(a.buffer)},!1,!0,!0)}async _handleGIFOrPNG(e,t,i){const s=$t(e);await this.resourceManager.fetchResource(s,i);const a=this.resourceManager.getResource(s);if(N(a))return new Q("mapview-invalid-resource",`Could not fetch requested resource at ${s}.`);if(a instanceof HTMLImageElement){let u=a.width,l=a.height;e.type==="esriPMS"&&(u=Math.round(ai(a.width,It(e))),l=Math.round(a.height*(u/a.width)));const d="cim"in e?e.cim.colorSubstitutions:void 0,{size:c,sdf:m,image:_}=this._rasterizer.rasterizeImageResource(u,l,a,d);return this._addItemToMosaic(t,c,{type:"static",data:_},He(e),m,!1)}const r=e.animatedSymbolProperties||{},o=e.objectId,h=new Fn(a,this._requestRender,r,o);return this._addItemToMosaic(t,[h.width,h.height],{type:"animated",data:h},He(e),!1,!1)}async _handleImage(e,t,i){var a;if(Ds(e)||As(e))return this._handleGIFOrPNG(e,t,i);const s=$t(e);try{let r;const o=this.resourceManager.getResource(s);if(F(o)&&o instanceof HTMLImageElement)r=o;else{const{data:_}=await this._imageRequestQueue.push(s,{...i});r=_}if(zs(s)){if("width"in e&&"height"in e)r.width=de(e.width),r.height=de(e.height);else if("cim"in e){const _=e.cim;r.width=de((a=_.width)!=null?a:_.scaleX*_.size),r.height=de(_.size)}}if(!r.width||!r.height)return null;let h=r.width,u=r.height;e.type==="esriPMS"&&(h=Math.round(ai(r.width,It(e))),u=Math.round(r.height*(h/r.width)));const l="cim"in e?e.cim.colorSubstitutions:void 0,{size:d,sdf:c,image:m}=this._rasterizer.rasterizeImageResource(h,u,r,l);return this._addItemToMosaic(t,d,{type:"static",data:m},He(e),c,!1)}catch(r){if(!Je(r))return new Q("mapview-invalid-resource",`Could not fetch requested resource at ${s}. ${r.message}`)}}_addItemToMosaic(e,t,i,s,a,r,o){return this._spriteMosaic.addSpriteItem(e,t,i,s,a,r,o)}}class Sn{constructor(e,t){this._queue=[],this._context=e,this._refreshable=t}destroy(){this._queue=[]}enqueueTextureUpdate(e,t){const i=Wi(),s=e,a=er,r=Math.ceil(s.height/a);if(rt(t),this._context.type===ji.WEBGL1)this._queue.push({type:"no-chunk",request:e,resolver:i,options:t});else for(let o=0;oi.reject(o)),i.promise}upload(){let e=0;for(;this._queue.length;){const t=performance.now(),i=this._queue.shift();if(i){if(F(i.options.signal)&&i.options.signal.aborted)continue;switch(i.type){case"chunk":this._uploadChunk(i);break;case"no-chunk":this._uploadNoChunk(i)}const s=performance.now()-t;if(e+=s,e+s>=Js)break}}this._queue.length&&this._refreshable.requestRender()}_uploadChunk(e){const{request:t,resolver:i,chunkOffset:s,chunkIsLast:a,destHeight:r}=e,{data:o,texture:h,width:u}=t;F(o)&&(h.updateData(0,0,s,u,r,o,s),a&&i.resolve())}_uploadNoChunk(e){const{request:t,resolver:i}=e,{data:s,texture:a}=t;a.setData(s),i.resolve()}}const Pn={shaders:{vertexShader:j("stencil/stencil.vert"),fragmentShader:j("stencil/stencil.frag")},attributes:new Map([["a_pos",0]])},On=Qi(-.5,-.5);class Dn{constructor(){this._centerNdc=De(),this._pxToNdc=De(),this._worldDimensionsPx=De(),this._mat3=Tt(),this._initialized=!1}dispose(){this._program=U(this._program),this._quad=U(this._quad)}render(e,t){const{context:i}=e;return!!this._updateGeometry(e,t)&&(this._initialized||this._initialize(i),i.setDepthWriteEnabled(!1),i.setDepthTestEnabled(!1),i.setColorMask(!1,!1,!1,!1),i.setBlendingEnabled(!1),i.setStencilOp(ut.KEEP,ut.KEEP,ut.REPLACE),i.setStencilFunction(yi.ALWAYS,1,255),i.setStencilTestEnabled(!0),i.useProgram(this._program),this._program.setUniformMatrix3fv("u_worldExtent",this._mat3),this._quad.draw(),this._quad.unbind(),!0)}_initialize(e){if(this._initialized)return;const t=Le(e,Pn);t&&(this._program=t,this._quad=new ge(e,[0,0,1,0,0,1,1,1]),this._initialized=!0)}_updateGeometry(e,t){const{state:i,pixelRatio:s}=e,{size:a,rotation:r}=i,o=Math.round(a[0]*s),h=Math.round(a[1]*s);if(!i.spatialReference.isWrappable)return!1;const u=Ji(r),l=Math.abs(Math.cos(u)),d=Math.abs(Math.sin(u)),c=Math.round(o*l+h*d),m=Math.round(i.worldScreenWidth);if(c<=m)return!1;const _=o*d+h*l,f=m*s,g=(t.left-t.right)*s/o,v=(t.bottom-t.top)*s/h;Ke(this._worldDimensionsPx,f,_,1),Ke(this._pxToNdc,2/o,-2/h,1),Ke(this._centerNdc,g,v,1);const p=this._mat3;return Xi(p,this._centerNdc),St(p,p,this._pxToNdc),r!==0&&Zi(p,p,u),St(p,p,this._worldDimensionsPx),Ki(p,p,On),!0}}class An extends Ge{constructor(){super(...arguments),this.defines=[],this._desc={vsPath:"fx/integrate",fsPath:"fx/integrate",attributes:new Map([["a_position",0]])}}dispose(){this._quad&&this._quad.dispose()}bind(){}unbind(){}draw(e,t){if(!t.size)return;const{context:i,renderingOptions:s}=e;this._quad||(this._quad=new ge(i,[0,0,1,0,0,1,1,1]));const a=i.getBoundFramebufferObject(),{x:r,y:o,width:h,height:u}=i.getViewport();t.bindTextures(i);const l=t.getBlock(tr);if(N(l))return;const d=l.getFBO(i),c=l.getFBO(i,1);i.setViewport(0,0,t.size,t.size),this._computeDelta(e,c,s.labelsAnimationTime),this._updateAnimationState(e,c,d),i.bindFramebuffer(a),i.setViewport(r,o,h,u)}_computeDelta(e,t,i){const{context:s,painter:a,displayLevel:r}=e,o=a.materialManager.getProgram(this._desc,["delta"]);s.bindFramebuffer(t),s.setClearColor(0,0,0,0),s.clear(s.gl.COLOR_BUFFER_BIT),s.useProgram(o),o.setUniform1i("u_maskTexture",ir),o.setUniform1i("u_sourceTexture",sr),o.setUniform1f("u_timeDelta",e.deltaTime),o.setUniform1f("u_animationTime",i),o.setUniform1f("u_zoomLevel",Math.round(10*r)),this._quad.draw()}_updateAnimationState(e,t,i){const{context:s,painter:a}=e,r=a.materialManager.getProgram(this._desc,["update"]);s.bindTexture(t.colorTexture,1),s.useProgram(r),r.setUniform1i("u_sourceTexture",1),s.bindFramebuffer(i),s.setClearColor(0,0,0,0),s.clear(s.gl.COLOR_BUFFER_BIT),this._quad.draw()}}const zn=n=>n.replace("-","_").toUpperCase(),oi=n=>`#define ${zn(n)} `;function hi(n){return{attributes:new Map([["a_pos",0],["a_tex",1]]),shaders:{vertexShader:oi(n)+j("blend/blend.vert"),fragmentShader:oi(n)+j("blend/blend.frag")}}}const li=xt.getLogger("esri.views.2d.engine.webgl.effects.blendEffects.BlendEffect");class $n{constructor(){this._size=[0,0]}dispose(e){this._backBufferTexture=U(this._backBufferTexture),this._quad=U(this._quad)}draw(e,t,i,s,a){const{context:r,drawPhase:o}=e;if(this._setupShader(r),s&&s!=="normal"&&o!==k.LABEL)return void this._drawBlended(e,t,i,s,a);const h=hi("normal"),u=r.programCache.acquire(h.shaders.vertexShader,h.shaders.fragmentShader,h.attributes);if(!u)return void li.error(new Q("mapview-BlendEffect",'Error creating shader program for blend mode "normal"'));r.useProgram(u),t.setSamplingMode(i),r.bindTexture(t,0),u.setUniform1i("u_layerTexture",0),u.setUniform1f("u_opacity",a),r.setBlendingEnabled(!0),r.setBlendFunction(M.ONE,M.ONE_MINUS_SRC_ALPHA);const l=this._quad;l.draw(),l.unbind(),u.dispose()}_drawBlended(e,t,i,s,a){const{context:r,state:o,pixelRatio:h,inFadeTransition:u}=e,{size:l}=o,d=r.getBoundFramebufferObject();let c,m;if(F(d)){const p=d.descriptor;c=p.width,m=p.height}else c=Math.round(h*l[0]),m=Math.round(h*l[1]);this._createOrResizeTexture(e,c,m);const _=this._backBufferTexture;d.copyToTexture(0,0,c,m,0,0,_),r.setStencilTestEnabled(!1),r.setStencilWriteMask(0),r.setBlendingEnabled(!0),r.setDepthTestEnabled(!1),r.setDepthWriteEnabled(!1);const f=hi(s),g=r.programCache.acquire(f.shaders.vertexShader,f.shaders.fragmentShader,f.attributes);if(!g)return void li.error(new Q("mapview-BlendEffect",`Error creating shader program for blend mode ${s}`));r.useProgram(g),_.setSamplingMode(i),r.bindTexture(_,0),g.setUniform1i("u_backbufferTexture",0),t.setSamplingMode(i),r.bindTexture(t,1),g.setUniform1i("u_layerTexture",1),g.setUniform1f("u_opacity",a),g.setUniform1f("u_inFadeOpacity",u?1:0),r.setBlendFunction(M.ONE,M.ZERO);const v=this._quad;v.draw(),v.unbind(),g.dispose(),r.setBlendFunction(M.ONE,M.ONE_MINUS_SRC_ALPHA)}_setupShader(e){this._quad||(this._quad=new ge(e,[-1,-1,1,-1,-1,1,1,1]))}_createOrResizeTexture(e,t,i){const{context:s}=e;this._backBufferTexture!==null&&t===this._size[0]&&i===this._size[1]||(this._backBufferTexture?this._backBufferTexture.resize(t,i):this._backBufferTexture=new W(s,{target:A.TEXTURE_2D,pixelFormat:E.RGBA,internalFormat:E.RGBA,dataType:C.UNSIGNED_BYTE,wrapMode:D.CLAMP_TO_EDGE,samplingMode:B.LINEAR,flipped:!1,width:t,height:i}),this._size[0]=t,this._size[1]=i)}}class ui extends Ge{constructor(e){super(),this.name=this.constructor.name,this.defines=[e]}dispose(){}bind({context:e,painter:t}){this._prev=e.getBoundFramebufferObject();const{width:i,height:s}=e.getViewport(),a=t.getFbos(i,s).effect0;e.bindFramebuffer(a),e.setColorMask(!0,!0,!0,!0),e.setClearColor(0,0,0,0),e.clear(e.gl.COLOR_BUFFER_BIT)}unbind(){}draw(e,t){const{context:i,painter:s}=e,a=s.getPostProcessingEffects(t),r=i.getBoundFramebufferObject();for(const{postProcessingEffect:o,effect:h}of a)o.draw(e,r,h);i.bindFramebuffer(this._prev),i.setStencilTestEnabled(!1),s.blitTexture(i,r.colorTexture,B.NEAREST),i.setStencilTestEnabled(!0)}}const wt=1,In=[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],Un=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Ce=256,ce={outlineWidth:1.3,outerHaloWidth:.4,innerHaloWidth:.4,outlinePosition:0},mt=xt.getLogger("esri.views.2d.engine.webgl.painter.highlight.HighlightGradient");function kn(n,e){e.fillColor[0]=n.color.r/255,e.fillColor[1]=n.color.g/255,e.fillColor[2]=n.color.b/255,e.fillColor[3]=n.color.a,n.haloColor?(e.outlineColor[0]=n.haloColor.r/255,e.outlineColor[1]=n.haloColor.g/255,e.outlineColor[2]=n.haloColor.b/255,e.outlineColor[3]=n.haloColor.a):(e.outlineColor[0]=e.fillColor[0],e.outlineColor[1]=e.fillColor[1],e.outlineColor[2]=e.fillColor[2],e.outlineColor[3]=e.fillColor[3]),e.fillColor[3]*=n.fillOpacity,e.outlineColor[3]*=n.haloOpacity,e.fillColor[0]*=e.fillColor[3],e.fillColor[1]*=e.fillColor[3],e.fillColor[2]*=e.fillColor[3],e.outlineColor[0]*=e.outlineColor[3],e.outlineColor[1]*=e.outlineColor[3],e.outlineColor[2]*=e.outlineColor[3],e.outlineWidth=ce.outlineWidth,e.outerHaloWidth=ce.outerHaloWidth,e.innerHaloWidth=ce.innerHaloWidth,e.outlinePosition=ce.outlinePosition}const Nn=[0,0,0,0];class Ln{constructor(){this._convertedHighlightOptions={fillColor:[.2*.75,.6*.75,.675,.75],outlineColor:[.2*.9,.54,.81,.9],outlinePosition:ce.outlinePosition,outlineWidth:ce.outlineWidth,innerHaloWidth:ce.innerHaloWidth,outerHaloWidth:ce.outerHaloWidth},this._shadeTexChanged=!0,this._texelData=new Uint8Array(4*Ce),this._minMaxDistance=[0,0]}setHighlightOptions(e){const t=this._convertedHighlightOptions;kn(e,t);const i=t.outlinePosition-t.outlineWidth/2-t.outerHaloWidth,s=t.outlinePosition-t.outlineWidth/2,a=t.outlinePosition+t.outlineWidth/2,r=t.outlinePosition+t.outlineWidth/2+t.innerHaloWidth,o=Math.sqrt(Math.PI/2)*wt,h=Math.abs(i)>o?Math.round(10*(Math.abs(i)-o))/10:0,u=Math.abs(r)>o?Math.round(10*(Math.abs(r)-o))/10:0;let l;h&&!u?mt.error("The outer rim of the highlight is "+h+"px away from the edge of the feature; consider reducing some width values or shifting the outline position towards positive values (inwards)."):!h&&u?mt.error("The inner rim of the highlight is "+u+"px away from the edge of the feature; consider reducing some width values or shifting the outline position towards negative values (outwards)."):h&&u&&mt.error("The highlight is "+Math.max(h,u)+"px away from the edge of the feature; consider reducing some width values.");const d=[void 0,void 0,void 0,void 0];function c(_,f,g){d[0]=(1-g)*_[0]+g*f[0],d[1]=(1-g)*_[1]+g*f[1],d[2]=(1-g)*_[2]+g*f[2],d[3]=(1-g)*_[3]+g*f[3]}const{_texelData:m}=this;for(let _=0;_l.resolve([]));const r=a.getFBO(i),o=new Uint8Array(r.width*r.height*4);try{await r.readPixelsAsync(0,0,r.width,r.height,E.RGBA,C.UNSIGNED_BYTE,o)}catch{return void t.forEach(d=>d.resolve([]))}const h=[];for(let l=0;ld.directHits===l.directHits?d.id-l.id:d.directHits-l.directHits);const u=h.map(l=>l.id);t.forEach(l=>l.resolve(u))}}class Yn extends Ge{constructor(){super(...arguments),this.name=this.constructor.name,this.defines=["id"],this._lastSize=0}dispose(){F(this._fbo)&&this._fbo.dispose()}bind({context:e,painter:t}){const{width:i,height:s}=e.getViewport();this._boundFBO=e.getBoundFramebufferObject();const a=t.getFbos(i,s).effect0;e.bindFramebuffer(a),e.setColorMask(!0,!0,!0,!0),e.setClearColor(0,0,0,0),e.clear(e.gl.COLOR_BUFFER_BIT)}unbind({context:e}){e.bindFramebuffer(this._boundFBO),this._boundFBO=null}draw(e,t,i=2*wi){this._resolve(e,t,i)}async _resolve({context:e,state:t,pixelRatio:i},s,a){const r=e.getBoundFramebufferObject(),o=t.size[1]*i,h=Math.round(a*i),u=h/2,l=h/2;this._ensureBuffer(h),s.forEach(async(d,c)=>{const m=new Map,_=Math.floor(c.x*i-h/2),f=Math.floor(o-c.y*i-h/2);await r.readPixelsAsync(_,f,h,h,E.RGBA,C.UNSIGNED_BYTE,this._buf);for(let v=0;vv[1]-p[1]).map(v=>v[0]);d.resolve(g),s.delete(c)})}_ensureBuffer(e){this._lastSize!==e&&(this._lastSize=e,this._buf=new Uint8Array(4*e*e),this._buf32=new Uint32Array(this._buf.buffer))}}const _t=5,Xn=[1,0],Zn=[0,1],Kn=[1,.8,.6,.4,.2],Qn=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];class Jn{constructor(){this._intensityFBO=null,this._compositeFBO=null,this._mipsFBOs=new Array(_t),this._nMips=_t,this._kernelSizeArray=[3,5,7,9,11],this._size=[0,0],this._programDesc={luminosityHighPass:{vsPath:"post-processing/pp",fsPath:"post-processing/bloom/luminosityHighPass",attributes:new Map([["a_position",0]])},gaussianBlur:{vsPath:"post-processing/pp",fsPath:"post-processing/bloom/gaussianBlur",attributes:new Map([["a_position",0]])},composite:{vsPath:"post-processing/pp",fsPath:"post-processing/bloom/composite",attributes:new Map([["a_position",0]])},blit:{vsPath:"post-processing/pp",fsPath:"post-processing/blit",attributes:new Map([["a_position",0]])}}}dispose(){if(this._quad&&(this._quad.dispose(),this._quad=null),this._intensityFBO&&(this._intensityFBO.dispose(),this._intensityFBO=null),this._compositeFBO&&(this._compositeFBO.dispose(),this._compositeFBO=null),this._mipsFBOs){for(let e=0;enew sa,blur:()=>new ia,bloom:()=>new Jn,opacity:()=>new oa,"drop-shadow":()=>new aa};class ua{constructor(){this._effectMap=new Map}dispose(){this._effectMap.forEach(e=>e.dispose()),this._effectMap.clear()}getPostProcessingEffects(e){if(!e||e.length===0)return[];const t=[];for(const i of e){const s=ha(i.type);let a=this._effectMap.get(s);a||(a=la[s](),this._effectMap.set(s,a)),t.push({postProcessingEffect:a,effect:i})}return t}}class da{constructor(e,t){var i;this.brushes=e,this.name=t.name,this.drawPhase=t.drawPhase||k.MAP,this._targetFn=t.target,this.effects=t.effects||[],this.enableDefaultDraw=(i=t.enableDefaultDraw)!=null?i:()=>!0}render(e){const{context:t,profiler:i}=e,s=this._targetFn(),a=this.drawPhase&e.drawPhase;if(i.recordPassStart(this.name),a){this.enableDefaultDraw()&&this._doRender(e,s),i.recordPassEnd();for(const r of this.effects){if(!r.enable())continue;const o=r.apply,h=r.args&&r.args(),u=t.getViewport(),l=t.getBoundFramebufferObject(),d=e.passOptions;this._bindEffect(e,o,h),this._doRender(e,s,o.defines),this._drawAndUnbindEffect(e,o,u,l,d,h)}}}_doRender(e,t,i){if(N(t))return;const{profiler:s,context:a}=e;for(const r of this.brushes){if(s.recordBrushStart(r.name),F(r.brushEffect)){const o=a.getViewport(),h=a.getBoundFramebufferObject(),u=e.passOptions;this._bindEffect(e,r.brushEffect),this._drawWithBrush(r,e,t,i),this._drawAndUnbindEffect(e,r.brushEffect,o,h,u)}else this._drawWithBrush(r,e,t,i);s.recordBrushEnd()}}_drawWithBrush(e,t,i,s){ts(i)?(e.prepareState(t,s),e.drawMany(t,i,s)):i.visible&&(e.prepareState(t,s),e.draw(t,i,s))}_bindEffect(e,t,i){const{profiler:s}=e;s.recordPassStart(this.name+"."+t.name),t.bind(e,i);const a=t.createOptions(e,i);e.passOptions=a}_drawAndUnbindEffect(e,t,i,s,a,r){const{profiler:o,context:h}=e;e.passOptions=a,o.recordBrushStart(t.name),t.draw(e,r),t.unbind(e,r),h.bindFramebuffer(s);const{x:u,y:l,width:d,height:c}=i;h.setViewport(u,l,d,c),o.recordBrushEnd(),o.recordPassEnd()}}function ca(n,e){switch(n){case Re.LINE:return re.line;case Re.TEXT:return re.text;case Re.LABEL:return re.label;case Re.FILL:return e===lt.DOT_DENSITY?re.dotDensity:re.fill;case Re.MARKER:switch(e){case lt.HEATMAP:return re.heatmap;case lt.PIE_CHART:return re.pieChart;default:return re.marker}}}class ma{constructor(e,t,i){this.context=e,this._blitRenderer=new Bi,this._worldExtentClipRenderer=new Dn,this._isClippedToWorldExtent=!1,this._brushCache=new Map,this._vtlMaterialManager=new nn,this._blendEffect=new $n,this._fboPool=[],this.effects={highlight:new Wn,hittest:new jn,hittestVTL:new Yn,integrate:new An,insideEffect:new ui("inside"),outsideEffect:new ui("outside")},this.materialManager=new ln(e),this.textureManager=new Cn(t,i),this.textureUploadManager=new Sn(e,t),this._effectsManager=new ua}get vectorTilesMaterialManager(){return this._vtlMaterialManager}getRenderTarget(){return this._renderTarget}setRenderTarget(e){this._renderTarget=e}getFbos(e,t){if(e!==this._lastWidth||t!==this._lastHeight){if(this._lastWidth=e,this._lastHeight=t,this._fbos){for(const r in this._fbos)this._fbos[r].resize(e,t);return this._fbos}const i={target:A.TEXTURE_2D,pixelFormat:E.RGBA,dataType:C.UNSIGNED_BYTE,samplingMode:B.NEAREST,wrapMode:D.CLAMP_TO_EDGE,width:e,height:t},s={colorTarget:J.TEXTURE,depthStencilTarget:ee.DEPTH_STENCIL_RENDER_BUFFER},a=new ks(this.context,{width:e,height:t,internalFormat:Ns.DEPTH_STENCIL});this._stencilBuf=a,this._fbos={output:new H(this.context,s,i,a),blend:new H(this.context,s,i,a),effect0:new H(this.context,s,i,a)}}return this._fbos}acquireFbo(e,t){let i;i=this._fboPool.length>0?this._fboPool.pop():new H(this.context,{colorTarget:J.TEXTURE,depthStencilTarget:ee.DEPTH_STENCIL_RENDER_BUFFER},{target:A.TEXTURE_2D,pixelFormat:E.RGBA,dataType:C.UNSIGNED_BYTE,samplingMode:B.NEAREST,wrapMode:D.CLAMP_TO_EDGE,width:e,height:t},this._stencilBuf);const s=i.descriptor;return s.width===e&&s.height===t||i.resize(e,t),i}releaseFbo(e){this._fboPool.push(e)}getSharedStencilBuffer(){return this._stencilBuf}beforeRenderLayers(e,t=null){const{width:i,height:s}=e.getViewport();this._prevFBO=e.getBoundFramebufferObject();const a=this.getFbos(i,s);if(e.bindFramebuffer(a.output),e.setColorMask(!0,!0,!0,!0),F(t)){const{r,g:o,b:h,a:u}=t.color;e.setClearColor(u*r/255,u*o/255,u*h/255,u)}else e.setClearColor(0,0,0,0);e.setDepthWriteEnabled(!0),e.setClearDepth(1),e.clear(e.gl.COLOR_BUFFER_BIT|e.gl.DEPTH_BUFFER_BIT),e.setDepthWriteEnabled(!1)}beforeRenderLayer(e,t,i){const{context:s,blendMode:a,effects:r,requireFBO:o,drawPhase:h}=e;if(o||ci(h,a,r,i))s.bindFramebuffer(this._fbos.blend),s.setColorMask(!0,!0,!0,!0),s.setClearColor(0,0,0,0),s.setDepthWriteEnabled(!0),s.setClearDepth(1),s.clear(s.gl.COLOR_BUFFER_BIT|s.gl.DEPTH_BUFFER_BIT),s.setDepthWriteEnabled(!1);else{const u=this._getOutputFBO();s.bindFramebuffer(u)}s.setDepthWriteEnabled(!1),s.setDepthTestEnabled(!1),s.setStencilTestEnabled(!0),s.setClearStencil(t),s.setStencilWriteMask(255),s.clear(s.gl.STENCIL_BUFFER_BIT)}compositeLayer(e,t){const{context:i,blendMode:s,effects:a,requireFBO:r,drawPhase:o}=e;if(r||ci(o,s,a,t)){F(a)&&a.length>0&&o===k.MAP&&this._applyEffects(e,a);const h=this._getOutputFBO();i.bindFramebuffer(h),i.setStencilTestEnabled(!1),i.setStencilWriteMask(0),i.setBlendingEnabled(!0),i.setBlendFunctionSeparate(M.ONE,M.ONE_MINUS_SRC_ALPHA,M.ONE,M.ONE_MINUS_SRC_ALPHA),i.setColorMask(!0,!0,!0,!0);const u=N(s)||o===k.HIGHLIGHT?"normal":s;this._blendEffect.draw(e,this._fbos.blend.colorTexture,B.NEAREST,u,t)}}renderLayers(e){if(e.bindFramebuffer(this._prevFBO),!this._fbos)return;const t=this._getOutputFBO();e.setDepthTestEnabled(!1),e.setStencilWriteMask(0),this._isClippedToWorldExtent?(e.setStencilTestEnabled(!0),e.setStencilFunction(yi.EQUAL,1,255)):e.setStencilTestEnabled(!1),this.blitTexture(e,t.colorTexture,B.NEAREST)}prepareDisplay(e,t,i){const{context:s}=e;if(s.bindFramebuffer(this._prevFBO),s.setColorMask(!0,!0,!0,!0),F(t)){const{r:a,g:r,b:o,a:h}=t.color;s.setClearColor(h*a/255,h*r/255,h*o/255,h)}else s.setClearColor(0,0,0,0);s.setStencilWriteMask(255),s.setClearStencil(0),s.clear(s.gl.COLOR_BUFFER_BIT|s.gl.STENCIL_BUFFER_BIT),this._isClippedToWorldExtent=this._worldExtentClipRenderer.render(e,i)}dispose(){if(this.materialManager.dispose(),this.textureManager.dispose(),this.textureUploadManager.destroy(),this._blitRenderer=U(this._blitRenderer),this._worldExtentClipRenderer=U(this._worldExtentClipRenderer),this._brushCache&&(this._brushCache.forEach(e=>e.dispose()),this._brushCache.clear(),this._brushCache=null),this._fbos)for(const e in this._fbos)this._fbos[e]&&this._fbos[e].dispose();for(const e of this._fboPool)e.dispose();if(this._fboPool.length=0,this.effects)for(const e in this.effects)this.effects[e]&&this.effects[e].dispose();this._effectsManager.dispose(),this._vtlMaterialManager=U(this._vtlMaterialManager),this._prevFBO=null}getBrush(e,t){const i=ca(e,t);let s=this._brushCache.get(i);return s===void 0&&(s=new i,this._brushCache.set(i,s)),this._brushCache.get(i)}renderObject(e,t,i,s){const a=re[i];if(!a)return null;let r=this._brushCache.get(a);r===void 0&&(r=new a,this._brushCache.set(a,r)),r.prepareState(e,s),r.draw(e,t,s)}renderObjects(e,t,i,s){const a=re[i];if(!a)return null;let r=this._brushCache.get(a);r===void 0&&(r=new a,this._brushCache.set(a,r)),r.drawMany(e,t,s)}registerRenderPass(e){const t=e.brushes.map(i=>(this._brushCache.has(i)||this._brushCache.set(i,new i),this._brushCache.get(i)));return new da(t,e)}setHighlightOptions(e){this.effects.highlight.setHighlightOptions(e)}blitTexture(e,t,i,s=1){e.setBlendingEnabled(!0),e.setBlendFunctionSeparate(M.ONE,M.ONE_MINUS_SRC_ALPHA,M.ONE,M.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0),this._blitRenderer.render(e,t,i,s)}getPostProcessingEffects(e){return this._effectsManager.getPostProcessingEffects(e)}_getOutputFBO(){return this._renderTarget!=null?this._renderTarget:this._fbos.output}_applyEffects(e,t){const{context:i}=e,s=this._effectsManager.getPostProcessingEffects(t);for(const{postProcessingEffect:a,effect:r}of s)i.bindFramebuffer(this._fbos.blend),a.draw(e,this._fbos.blend,r)}}function ci(n,e,t,i){return n!==k.HIGHLIGHT&&(i!==1||F(e)&&e!=="normal"||F(t)&&t.length>0)}const K=Ue("esri-2d-profiler");class _a{constructor(e,t){if(this._events=new is,this._entries=new Map,this._timings=new hr(10),this._currentContainer=null,this._currentPass=null,this._currentBrush=null,this._currentSummary=null,!K)return;this._ext=Ls(e.gl,{}),this._debugOutput=t;const i=e.gl;if(this.enableCommandLogging){for(const s in i)if(typeof i[s]=="function"){const a=i[s],r=s.includes("draw");i[s]=(...o)=>(this._events.emit("command",{container:this._currentContainer,pass:this._currentPass,brush:this._currentBrush,method:s,args:o,isDrawCommand:r}),this._currentSummary&&(this._currentSummary.commands++,r&&this._currentSummary.drawCommands++),a.apply(i,o))}}}get enableCommandLogging(){return!(typeof K=="object"&&K.disableCommands)}recordContainerStart(e){K&&(this._currentContainer=e)}recordContainerEnd(){K&&(this._currentContainer=null)}recordPassStart(e){K&&(this._currentPass=e,this._initSummary())}recordPassEnd(){K&&(this._currentPass=null,this._emitSummary())}recordBrushStart(e){K&&(this._currentBrush=e)}recordBrushEnd(){K&&(this._currentBrush=null)}recordStart(e){if(K&&F(this._ext)){if(this._entries.has(e)){const i=this._entries.get(e),s=this._ext.resultAvailable(i.query),a=this._ext.disjoint();if(s&&!a){const r=this._ext.getResult(i.query)/1e6;let o=0;if(F(this._timings.enqueue(r))){const l=this._timings.entries,d=l.length;let c=0;for(const m of l)c+=m;o=c/d}const h=r.toFixed(2),u=o?o.toFixed(2):"--";this.enableCommandLogging?(console.groupCollapsed(`Frame report for ${e}, ${h} ms (${u} last 10 avg) ${i.commandsLen} Commands (${i.drawCommands} draw)`),console.log("RenderPass breakdown: "),console.table(i.summaries),console.log("Commands: ",i.commands),console.groupEnd()):console.log(`Frame report for ${e}, ${h} ms (${u} last 10 avg)`),this._debugOutput.innerHTML=`${h} (${u})`}for(const r of i.handles)r.remove();this._ext.deleteQuery(i.query),this._entries.delete(e)}const t={name:e,query:this._ext.createQuery(),commands:[],commandsLen:0,drawCommands:0,summaries:[],handles:[]};this.enableCommandLogging&&(t.handles.push(this._events.on("command",i=>{t.commandsLen++,t.commands.push(i),i.isDrawCommand&&t.drawCommands++})),t.handles.push(this._events.on("summary",i=>{t.summaries.push(i)}))),this._ext.beginTimeElapsed(t.query),this._entries.set(e,t)}}recordEnd(e){K&&F(this._ext)&&this._entries.has(e)&&this._ext.endTimeElapsed()}_initSummary(){this.enableCommandLogging&&(this._currentSummary={container:this._currentContainer,pass:this._currentPass,drawCommands:0,commands:0})}_emitSummary(){this.enableCommandLogging&&this._currentSummary&&this._events.emit("summary",this._currentSummary)}}const pa=2e3;class Lo extends At{constructor(e,t){super(),this._trash=new Set,this._renderRemainingTime=0,this._lastFrameRenderTime=0,this.renderRequested=!1,this.stage=this,this._stationary=!0;const{canvas:i=document.createElement("canvas"),alpha:s=!0,stencil:a=!0,contextOptions:r={}}=t;this._canvas=i;const o=ss("2d",i,{alpha:s,antialias:!1,depth:!0,stencil:a});this.context=new Gs(F(o)?o:null,r),this.resourceManager=new Gr,this.painter=new ma(this.context,this,this.resourceManager),Ue("esri-2d-profiler")&&(this._debugOutput=document.createElement("div"),this._debugOutput.setAttribute("style","margin: 24px 64px; position: absolute; color: red;"),e.appendChild(this._debugOutput)),this._renderParameters={drawPhase:0,state:this.state,pixelRatio:window.devicePixelRatio,stationary:!1,globalOpacity:1,blendMode:null,deltaTime:-1,time:0,inFadeTransition:!1,effects:null,context:this.context,painter:this.painter,timeline:t.timeline||new rs,renderingOptions:t.renderingOptions,requestRender:()=>this.requestRender(),allowDelayedRender:!1,requireFBO:!1,profiler:new _a(this.context,this._debugOutput),dataUploadCounter:0},this._taskHandle=ns({render:h=>this.renderFrame(h)}),this._taskHandle.pause(),this._lostWebGLContextHandle=as(i,"webglcontextlost",()=>{this.emit("webgl-error",{error:new Q("webgl-context-lost")})}),this._bufferPool=new Fs,i.setAttribute("style","width: 100%; height:100%; display:block;"),e.appendChild(i)}destroy(){this.removeAllChildren(),this._emptyTrash(),this._taskHandle.remove(),this._taskHandle=null,this._lostWebGLContextHandle&&(this._lostWebGLContextHandle.remove(),this._lostWebGLContextHandle=null),this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._debugOutput&&this._debugOutput.parentNode&&this._debugOutput.parentNode.removeChild(this._debugOutput),this._bufferPool.destroy(),this.highlightOptions=null,this.resourceManager.destroy(),this.painter.dispose(),this.context.dispose(),this._canvas=null}get background(){return this._background}set background(e){this._background=e,this.requestRender()}get bufferPool(){return this._bufferPool}get highlightOptions(){return this._highlightOptions}set highlightOptions(e){this._highlightOptionsHandle&&(this._highlightOptionsHandle.remove(),this._highlightOptionsHandle=null),this._highlightOptions=e,this._highlightOptions&&(this._highlightOptionsHandle=Qe(()=>{var t;return(t=this._highlightOptions)==null?void 0:t.version},()=>{this.painter.setHighlightOptions(e),this.requestRender()},fi))}get renderingOptions(){return this._renderingOptions}set renderingOptions(e){this._renderingOptions=e,this.requestRender()}get state(){return this._state}set state(e){this._state=e,this.requestRender()}get stationary(){return this._stationary}set stationary(e){this._stationary!==e&&(this._stationary=e,this.requestRender())}trashDisplayObject(e){this._trash.add(e),this.requestRender()}untrashDisplayObject(e){return this._trash.delete(e)}requestRender(){this._renderRemainingTime=pa,this.renderRequested||(this.renderRequested=!0,this.emit("will-render"),this._taskHandle.resume())}renderFrame(e){const t=this._lastFrameRenderTime?e.time-this._lastFrameRenderTime:0;this._renderRemainingTime-=t,this._renderRemainingTime<=0&&this._taskHandle.pause(),this._lastFrameRenderTime=e.time,this.renderRequested=!1,this._renderParameters.state=this._state,this._renderParameters.stationary=this.stationary,this._renderParameters.pixelRatio=window.devicePixelRatio,this._renderParameters.globalOpacity=1,this._renderParameters.time=e.time,this._renderParameters.deltaTime=e.deltaTime,this._renderParameters.effects=null,this.processRender(this._renderParameters),this._emptyTrash(),this.emit("post-render")}_createTransforms(){return{dvs:Tt()}}renderChildren(e){for(const t of this.children)t.beforeRender(e);this._renderChildren(this.children,e);for(const t of this.children)t.afterRender(e)}_renderChildren(e,t){const i=this.context;this.painter.textureUploadManager.upload(),i.resetInfo(),t.profiler.recordStart("drawLayers"),t.dataUploadCounter=0,t.drawPhase=k.MAP,this.painter.beforeRenderLayers(i,this.background);for(const s of e)s.processRender(t);this.painter.prepareDisplay(t,this.background,this.state.padding),this.painter.renderLayers(i),t.drawPhase=k.HIGHLIGHT,this.painter.beforeRenderLayers(i);for(const s of e)s.processRender(t);if(this.painter.renderLayers(i),this._isLabelDrawPhaseRequired(e)){t.drawPhase=k.LABEL,this.painter.beforeRenderLayers(i);for(const s of e)s.processRender(t);this.painter.renderLayers(i)}if(Ue("esri-tiles-debug")){t.drawPhase=k.DEBUG,this.painter.beforeRenderLayers(i);for(const s of e)s.processRender(t);this.painter.renderLayers(i)}t.profiler.recordEnd("drawLayers"),i.logInfo()}doRender(e){const t=this.context,{state:i,pixelRatio:s}=e;this._resizeCanvas(e),t.setViewport(0,0,s*i.size[0],s*i.size[1]),t.setDepthWriteEnabled(!0),t.setStencilWriteMask(255),super.doRender(e)}async takeScreenshot(e){const{framebufferWidth:t,framebufferHeight:i}={framebufferWidth:Math.round(this.state.size[0]*e.resolutionScale),framebufferHeight:Math.round(this.state.size[1]*e.resolutionScale)},s=1,a=this.context,r=this._state.clone();if(e.rotation!=null){const _=r.viewpoint;r.viewpoint.rotation=e.rotation,r.viewpoint=_}const o={...this._renderParameters,drawPhase:null,globalOpacity:1,stationary:!0,state:r,pixelRatio:s,time:performance.now(),deltaTime:0,blendMode:null,effects:null,inFadeTransition:!1},h=new H(a,{colorTarget:J.TEXTURE,depthStencilTarget:ee.DEPTH_STENCIL_RENDER_BUFFER,width:t,height:i}),u=a.getBoundFramebufferObject(),l=a.getViewport();a.bindFramebuffer(h),a.setViewport(0,0,t,i),this._renderChildren(e.children,o);const d=this._readbackScreenshot(h,{...e.cropArea,y:i-(e.cropArea.y+e.cropArea.height)});a.bindFramebuffer(u),a.setViewport(l.x,l.y,l.width,l.height),this.requestRender();const c=await d;let m;return e.outputScale===1?m=c:(m=new ImageData(Math.round(c.width*e.outputScale),Math.round(c.height*e.outputScale)),os(c,m,!0)),m}async _readbackScreenshot(e,t){const i=lr(t.width,t.height,document.createElement("canvas"));return await e.readPixelsAsync(t.x,t.y,t.width,t.height,E.RGBA,C.UNSIGNED_BYTE,new Uint8Array(i.data.buffer)),i}_resizeCanvas(e){const t=this._canvas,i=t.style,{state:{size:s},pixelRatio:a}=e,r=s[0],o=s[1],h=Math.round(r*a),u=Math.round(o*a);t.width===h&&t.height===u||(t.width=h,t.height=u),i.width=r+"px",i.height=o+"px"}_emptyTrash(){for(;this._trash.size>0;){const e=Array.from(this._trash);this._trash.clear();for(const t of e)t.processDetach()}}_isLabelDrawPhaseRequired(e){let t=!1;for(const i of e){if(!(i instanceof At)){t=t||!1;break}if(i.hasLabels)return!0;t=t||this._isLabelDrawPhaseRequired(i.children)}return t}}const je=2,ie=1,ze=0,$e=1,Ie=2;class fa{constructor(e,t,i){this._debugMap=new Map,this._width=e*i,this._height=t*i,this._pixelRatio=i;const s=Math.ceil(this._width/ie),a=Math.ceil(this._height/ie);this._cols=s,this._rows=a,this._cells=ur.create(s*a)}insertMetrics(e){const t=this._hasCollision(e);return t===ze&&this._markMetrics(e),t}getCellId(e,t){return e+t*this._cols}has(e){return this._cells.has(e)}hasRange(e,t){return this._cells.hasRange(e,t)}set(e){this._cells.set(e)}setRange(e,t){this._cells.setRange(e,t)}_collide(e,t,i,s){const a=e-i/2,r=t-s/2,o=a+i,h=r+s;if(o<0||h<0||a>this._width||r>this._height)return $e;const u=G(Math.floor(a/ie),0,this._cols),l=G(Math.floor(r/ie),0,this._rows),d=G(Math.ceil(o/ie),0,this._cols),c=G(Math.ceil(h/ie),0,this._rows);for(let m=l;m<=c;m++)for(let _=u;_<=d;_++){const f=this.getCellId(_,m);if(this.has(f))return Ie}return ze}_mark(e,t,i,s,a){const r=e-i/2,o=t-s/2,h=r+i,u=o+s,l=G(Math.floor(r/ie),0,this._cols),d=G(Math.floor(o/ie),0,this._rows),c=G(Math.ceil(h/ie),0,this._cols),m=G(Math.ceil(u/ie),0,this._rows);for(let _=d;_<=m;_++)for(let f=l;f<=c;f++){const g=this.getCellId(f,_);this._debugMap.set(g,a),this.set(g)}return!1}_hasCollision(e){const t=e.id;let i=0,s=0;e.save();do{const a=e.boundsCount;i+=a;for(let r=0;r=e.maxDataValue?s:i+t*(s-i)}function wa(n,e){const t=n/e.minDataValue,i=te(e.minSize,n),s=te(e.maxSize,n);let a=null;return a=t*i,G(a,i,s)}function xa(n,e){const[t,i,s]=Ea(n,e.cache.ipData);if(t===i)return te(e.stops[t].size,n);{const a=te(e.stops[t].size,n);return a+(te(e.stops[i].size,n)-a)*s}}function Ta(n,e){const t=hs[e.valueUnit],i=te(e.minSize,n),s=te(e.maxSize,n),{valueRepresentation:a}=e;let r=null;return r=a==="area"?2*Math.sqrt(n/ga)/t:a==="radius"||a==="distance"?2*n/t:n/t,G(r,i,s)}function Ea(n,e){if(!e)return;let t=0,i=e.length-1;return e.some((s,a)=>nt.push(i)),t.sort((i,s)=>i.instanceId-s.instanceId),t.forEach(i=>{F(i.labelMetrics)&&i.isReady&&e(i,i.labelMetrics.getCursor())})}function Ma(n){return n.layer&&(n.layer.type==="feature"||n.layer.type==="csv"||n.layer.type==="geojson"||n.layer.type==="ogc-feature"||n.layer.type==="stream"||n.layer.type==="subtype-group"||n.layer.type==="wfs")}function Ra(n){return e=>de(Oi(e,n))}function Fa(n){const e="visualVariables"in n&&n.visualVariables;if(!e)return null;for(const t of e)if(t.type==="size")return Ra(t);return null}function Ba(n){for(const e of n){const t="featureReduction"in e&&e.featureReduction&&"labelingInfo"in e.featureReduction&&e.featureReduction,i=[...e.labelingInfo||[],...(t==null?void 0:t.labelingInfo)||[]];if(!(!e.labelsVisible||!i.length)&&i.some(s=>s.deconflictionStrategy==="none"))return!0}return!1}function Ca(n,e){var h;if(!Ma(e))return;const t=e.layer.type==="subtype-group"?e.layer.sublayers.items:[e.layer],i=e.layer.geometryType,s=!Ba(t),a={};if(e.layer.type!=="subtype-group"){if(((h=e.tileRenderer)==null?void 0:h.type)==="heatmap")return;const u=Fa(e.layer.renderer);a[0]=u}const r=e.tileRenderer;if(N(r))return;const o=e.layer.visible&&!e.suspended;n.push({tileRenderer:r,vvEvaluators:a,deconflictionEnabled:s,geometryType:i,visible:o})}class Sa{run(e,t,i){const s=[];for(let a=e.length-1;a>=0;a--)Ca(s,e[a]);this._transformMetrics(s),this._runCollision(s,t,i)}_runCollision(e,t,i){const[s,a]=t.state.size,r=new fa(s,a,t.pixelRatio);for(const{tileRenderer:o,deconflictionEnabled:h,visible:u}of e){const l=o.featuresView.attributeView;h?u?(this._prepare(o),this._collideVisible(r,o,i),this._collideInvisible(r,o)):ye(o,(d,c)=>{for(;c.nextId();)l.setLabelMinZoom(c.id,Ye)}):ye(o,(d,c)=>{for(;c.nextId();)l.setLabelMinZoom(c.id,Se),u&&r.insertMetrics(c)})}}_isFiltered(e,t,i){const s=t.getFilterFlags(e),a=!i.hasFilter||!!(s&rr),r=N(i.featureEffect)||i.featureEffect.excludedLabelsVisible||!!(s&nr);return!(a&&r)}_prepare(e){const t=e.featuresView.attributeView,i=new Set;ye(e,(s,a)=>{for(;a.nextId();)if(!i.has(a.id)){if(i.add(a.id),this._isFiltered(a.id,t,e.layerView)){t.setLabelMinZoom(a.id,pt);continue}t.getLabelMinZoom(a.id)!==Se?t.setLabelMinZoom(a.id,Ye):t.setLabelMinZoom(a.id,Se)}})}_collideVisible(e,t,i){const s=t.featuresView.attributeView,a=new Set;ye(t,(r,o)=>{for(;o.nextId();)if(!a.has(o.id))if(r.key.level===i){if(s.getLabelMinZoom(o.id)===0)switch(e.insertMetrics(o)){case $e:break;case Ie:s.setLabelMinZoom(o.id,pt),a.add(o.id);break;case ze:s.setLabelMinZoom(o.id,Se),a.add(o.id)}}else s.setLabelMinZoom(o.id,pt)})}_collideInvisible(e,t){const i=t.featuresView.attributeView,s=new Set;ye(t,(a,r)=>{for(;r.nextId();)if(!s.has(r.id)&&i.getLabelMinZoom(r.id)===Ye)switch(e.insertMetrics(r)){case $e:break;case Ie:i.setLabelMinZoom(r.id,Ye),s.add(r.id);break;case ze:i.setLabelMinZoom(r.id,Se),s.add(r.id)}})}_transformMetrics(e){for(const{tileRenderer:t,geometryType:i,vvEvaluators:s}of e)ye(t,(a,r)=>{const o=t.featuresView.attributeView,h=a.transforms.labelMat2d;h[4]=Math.round(h[4]),h[5]=Math.round(h[5]);const u=i==="polyline";for(;r.next();){const l=r.boundsCount,d=r.anchorX,c=r.anchorY;let m=r.size;const _=s[0];if(F(_)){const v=_(o.getVVSize(r.id));m=isNaN(v)||v==null||v===1/0?m:v}const f=r.directionX*(m/2),g=r.directionY*(m/2);for(let v=0;v updateRequested: ${this.updateRequested}`),this.updateRequested}update(n){this._applyVisibilityPassThrottled(n)}viewChange(){this.requestUpdate()}requestUpdate(){this.updateRequested||(this.updateRequested=!0,this.view.requestUpdate())}processUpdate(n){this._set("updateParameters",n),this.updateRequested&&(this.updateRequested=!1,this.update(n))}_applyVisibilityPass(n){try{const e=this.view.featuresTilingScheme.getClosestInfoForScale(n.state.scale).level;this.collisionEngine.run(this.view.allLayerViews.items,n,e)}catch{}}};R([O()],pe.prototype,"updateRequested",void 0),R([O({readOnly:!0})],pe.prototype,"updateParameters",void 0),R([O()],pe.prototype,"updating",null),R([O()],pe.prototype,"view",void 0),pe=R([Te("esri.views.2d.layers.labels.LabelManager")],pe);const Go=pe,Xe={container:"esri-zoom-box__container",overlay:"esri-zoom-box__overlay",background:"esri-zoom-box__overlay-background",box:"esri-zoom-box__outline"},ft={zoom:"Shift",counter:"Ctrl"};let Pe=class extends Ee{constructor(n){super(n),this._container=null,this._overlay=null,this._backgroundShape=null,this._boxShape=null,this._box={x:0,y:0,width:0,height:0},this._redraw=this._redraw.bind(this)}destroy(){this.view=null}set view(n){this._handles&&this._handles.forEach(e=>{e.remove()}),this._handles=null,this._destroyOverlay(),this._set("view",n),n&&(n.on("drag",[ft.zoom],e=>this._handleDrag(e,1),Pt.INTERNAL),n.on("drag",[ft.zoom,ft.counter],e=>this._handleDrag(e,-1),Pt.INTERNAL))}_start(){this._createContainer(),this._createOverlay(),this.navigation.begin()}_update(n,e,t,i){this._box.x=n,this._box.y=e,this._box.width=t,this._box.height=i,this._rafId||(this._rafId=requestAnimationFrame(this._redraw))}_end(n,e,t,i,s){const a=this.view,r=a.toMap(ds(n+.5*t,e+.5*i));let o=Math.max(t/a.width,i/a.height);s===-1&&(o=1/o),this._destroyOverlay(),this.navigation.end(),a.goTo({center:r,scale:a.scale*o})}_updateBox(n,e,t,i){const s=this._boxShape;s.setAttributeNS(null,"x",""+n),s.setAttributeNS(null,"y",""+e),s.setAttributeNS(null,"width",""+t),s.setAttributeNS(null,"height",""+i),s.setAttributeNS(null,"class",Xe.box)}_updateBackground(n,e,t,i){this._backgroundShape.setAttributeNS(null,"d",this._toSVGPath(n,e,t,i,this.view.width,this.view.height))}_createContainer(){const n=document.createElement("div");n.className=Xe.container,this.view.root.appendChild(n),this._container=n}_createOverlay(){const n=this.view.width,e=this.view.height,t=document.createElementNS("http://www.w3.org/2000/svg","path");t.setAttributeNS(null,"d","M 0 0 L "+n+" 0 L "+n+" "+e+" L 0 "+e+" Z"),t.setAttributeNS(null,"class",Xe.background);const i=document.createElementNS("http://www.w3.org/2000/svg","rect"),s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),s.setAttributeNS(null,"class",Xe.overlay),s.appendChild(t),s.appendChild(i),this._container.appendChild(s),this._backgroundShape=t,this._boxShape=i,this._overlay=s}_destroyOverlay(){this._container&&this._container.parentNode&&this._container.parentNode.removeChild(this._container),this._container=this._backgroundShape=this._boxShape=this._overlay=null}_toSVGPath(n,e,t,i,s,a){const r=n+t,o=e+i;return"M 0 0 L "+s+" 0 L "+s+" "+a+" L 0 "+a+" ZM "+n+" "+e+" L "+n+" "+o+" L "+r+" "+o+" L "+r+" "+e+" Z"}_handleDrag(n,e){const t=n.x,i=n.y,s=n.origin.x,a=n.origin.y;let r,o,h,u;switch(t>s?(r=s,h=t-s):(r=t,h=s-t),i>a?(o=a,u=i-a):(o=i,u=a-i),n.action){case"start":this._start();break;case"update":this._update(r,o,h,u);break;case"end":this._end(r,o,h,u,e)}n.stopPropagation()}_redraw(){if(!this._rafId||(this._rafId=null,!this._overlay))return;const{x:n,y:e,width:t,height:i}=this._box;this._updateBox(n,e,t,i),this._updateBackground(n,e,t,i),this._rafId=requestAnimationFrame(this._redraw)}};R([O()],Pe.prototype,"navigation",void 0),R([O()],Pe.prototype,"view",null),Pe=R([Te("esri.views.2d.navigation.ZoomBox")],Pe);const Oa=Pe;class ue{constructor(e){this._gain=e,this.lastValue=void 0,this.filteredDelta=void 0}update(e){if(this.hasLastValue()){const t=this.computeDelta(e);this._updateDelta(t)}this.lastValue=e}reset(){this.lastValue=void 0,this.filteredDelta=void 0}hasLastValue(){return this.lastValue!==void 0}hasFilteredDelta(){return this.filteredDelta!==void 0}computeDelta(e){return this.lastValue===void 0?NaN:e-this.lastValue}_updateDelta(e){this.filteredDelta!==void 0?this.filteredDelta=(1-this._gain)*this.filteredDelta+this._gain*e:this.filteredDelta=e}}class Ct{constructor(e,t,i){this._initialVelocity=e,this._stopVelocity=t,this._friction=i,this._duration=Math.abs(Math.log(Math.abs(this._initialVelocity)/this._stopVelocity)/Math.log(1-this._friction))}get duration(){return this._duration}isFinished(e){return e>this.duration}get friction(){return this._friction}value(e){return this.valueFromInitialVelocity(this._initialVelocity,e)}valueDelta(e,t){const i=this.value(e);return this.value(e+t)-i}valueFromInitialVelocity(e,t){t=Math.min(t,this.duration);const i=1-this.friction;return e*(i**t-1)/Math.log(i)}}class Da extends Ct{constructor(e,t,i,s,a){super(e,t,i),this._sceneVelocity=s,this.direction=a}value(e){return super.valueFromInitialVelocity(this._sceneVelocity,e)}}class Aa{constructor(e=300,t=12,i=.84){this._minimumInitialVelocity=e,this._stopVelocity=t,this._friction=i,this.enabled=!0,this._time=new ue(.6),this._screen=[new ue(.4),new ue(.4)],this._scene=[new ue(.6),new ue(.6),new ue(.6)],this._tmpDirection=De()}add(e,t,i){if(this.enabled){if(this._time.hasLastValue()&&this._time.computeDelta(i)<.015)return;this._screen[0].update(e[0]),this._screen[1].update(e[1]),this._scene[0].update(t[0]),this._scene[1].update(t[1]),this._scene[2].update(t[2]),this._time.update(i)}}reset(){this._screen[0].reset(),this._screen[1].reset(),this._scene[0].reset(),this._scene[1].reset(),this._scene[2].reset(),this._time.reset()}evaluateMomentum(){if(!this.enabled||!this._screen[0].hasFilteredDelta()||!this._time.hasFilteredDelta())return null;const e=this._screen[0].filteredDelta,t=this._screen[1].filteredDelta,i=e==null||t==null?0:Math.sqrt(e*e+t*t),s=this._time.filteredDelta,a=s==null||i==null?0:i/s;return Math.abs(a)0&&gi(this._tmpDirection,this._tmpDirection,1/s);const a=this._time.filteredDelta;return new Da(e,t,i,a==null?0:s/a,this._tmpDirection)}}let be=class extends Ee{constructor(n){super(n),this.animationTime=0,this.momentumEstimator=new Aa(500,6,.92),this.momentum=null,this.tmpMomentum=De(),this.momentumFinished=!1,this.viewpoint=new nt({targetGeometry:new at,scale:0,rotation:0}),vi(()=>this.momentumFinished,()=>this.navigation.stop())}begin(n,e){this.navigation.begin(),this.momentumEstimator.reset(),this.addToEstimator(e),this._previousDrag=e}update(n,e){this.addToEstimator(e);let t=e.center.x,i=e.center.y;const s=this._previousDrag;t=s?s.center.x-t:-t,i=s?i-s.center.y:i,n.viewpoint=et(this.viewpoint,n.viewpoint,[t||0,i||0]),this._previousDrag=e}end(n,e){this.addToEstimator(e);const t=n.navigation.momentumEnabled;this.momentum=t?this.momentumEstimator.evaluateMomentum():null,this.animationTime=0,this.momentum&&this.onAnimationUpdate(n),this._previousDrag=null,this.navigation.end()}addToEstimator(n){const e=n.center.x,t=n.center.y,i=ms(-e,t),s=_s(-e,t,0);this.momentumEstimator.add(i,s,.001*n.timestamp)}onAnimationUpdate(n){this.navigation.animationManager.animateContinous(n.viewpoint,(e,t)=>{this.momentumFinished=!this.momentum||this.momentum.isFinished(this.animationTime);const i=.001*t;if(!this.momentumFinished){const s=this.momentum.valueDelta(this.animationTime,i);gi(this.tmpMomentum,this.momentum.direction,s),et(e,e,this.tmpMomentum),n.constraints.constrainByGeometry(e)}this.animationTime+=i})}stopMomentumNavigation(){this.momentum&&(this.momentumEstimator.reset(),this.momentum=null,this.navigation.stop())}};R([O()],be.prototype,"momentumFinished",void 0),R([O()],be.prototype,"viewpoint",void 0),R([O()],be.prototype,"navigation",void 0),be=R([Te("esri.views.2d.navigation.actions.Pan")],be);const za=be;class Di{constructor(e=2.5,t=.01,i=.95,s=12){this._minimumInitialVelocity=e,this._stopVelocity=t,this._friction=i,this._maxVelocity=s,this.enabled=!0,this.value=new ue(.8),this.time=new ue(.3)}add(e,t){if(this.enabled&&t!=null){if(this.time.hasLastValue()){if(this.time.computeDelta(t)<.01)return;if(this.value.hasFilteredDelta()){const i=this.value.computeDelta(e);this.value.filteredDelta*i<0&&this.value.reset()}}this.time.update(t),this.value.update(e)}}reset(){this.value.reset(),this.time.reset()}evaluateMomentum(){if(!this.enabled||!this.value.hasFilteredDelta()||!this.time.hasFilteredDelta())return null;let e=this.value.filteredDelta/this.time.filteredDelta;return e=G(e,-this._maxVelocity,this._maxVelocity),Math.abs(e)Math.PI;)s-=2*Math.PI;for(;s<-Math.PI;)s+=2*Math.PI;e=i+s}super.add(e,t)}}class Ia extends Ct{constructor(e,t,i){super(e,t,i)}value(e){const t=super.value(e);return Math.exp(t)}valueDelta(e,t){const i=super.value(e),s=super.value(e+t)-i;return Math.exp(s)}}class Ua extends Di{constructor(e=2.5,t=.01,i=.95,s=12){super(e,t,i,s)}add(e,t){super.add(Math.log(e),t)}createMomentum(e,t,i){return new Ia(e,t,i)}}let we=class extends Ee{constructor(n){super(n),this._animationTime=0,this._momentumFinished=!1,this._rotationMomentumEstimator=new $a(.6,.15,.95),this._rotationDirection=1,this._zoomDirection=1,this._zoomMomentumEstimator=new Ua,this._zoomOnly=null,this.zoomMomentum=null,this.rotateMomentum=null,this.viewpoint=new nt({targetGeometry:new at,scale:0,rotation:0}),this.addHandles(vi(()=>this._momentumFinished,()=>this.navigation.stop()))}begin(n,e){this.navigation.begin(),this._rotationMomentumEstimator.reset(),this._zoomMomentumEstimator.reset(),this._zoomOnly=null,this._previousAngle=this._startAngle=e.angle,this._previousRadius=this._startRadius=e.radius,this._previousCenter=e.center,this._updateTimestamp=null,n.constraints.rotationEnabled&&this.addToRotateEstimator(0,e.timestamp),this.addToZoomEstimator(e,1)}update(n,e){this._updateTimestamp===null&&(this._updateTimestamp=e.timestamp);const t=e.angle,i=e.radius,s=e.center,a=Math.abs(180*(t-this._startAngle)/Math.PI),r=Math.abs(i-this._startRadius),o=this._startRadius/i;if(this._previousRadius){const h=i/this._previousRadius;let u=180*(t-this._previousAngle)/Math.PI;this._rotationDirection=u>=0?1:-1,this._zoomDirection=h>=1?1:-1,n.constraints.rotationEnabled?(this._zoomOnly===null&&e.timestamp-this._updateTimestamp>200&&(this._zoomOnly=r-a>0),this._zoomOnly===null||this._zoomOnly?u=0:this.addToRotateEstimator(t-this._startAngle,e.timestamp)):u=0,this.addToZoomEstimator(e,o),this.navigation.setViewpoint([s.x,s.y],1/h,u,[this._previousCenter.x-s.x,s.y-this._previousCenter.y])}this._previousAngle=t,this._previousRadius=i,this._previousCenter=s}end(n){this.rotateMomentum=this._rotationMomentumEstimator.evaluateMomentum(),this.zoomMomentum=this._zoomMomentumEstimator.evaluateMomentum(),this._animationTime=0,(this.rotateMomentum||this.zoomMomentum)&&this.onAnimationUpdate(n),this.navigation.end()}addToRotateEstimator(n,e){this._rotationMomentumEstimator.add(n,.001*e)}addToZoomEstimator(n,e){this._zoomMomentumEstimator.add(e,.001*n.timestamp)}canZoomIn(n){const e=n.scale,t=n.constraints.effectiveMaxScale;return t===0||e>t}canZoomOut(n){const e=n.scale,t=n.constraints.effectiveMinScale;return t===0||e{const i=!this.canZoomIn(n)&&this._zoomDirection>1||!this.canZoomOut(n)&&this._zoomDirection<1,s=!this.rotateMomentum||this.rotateMomentum.isFinished(this._animationTime),a=i||!this.zoomMomentum||this.zoomMomentum.isFinished(this._animationTime),r=.001*t;if(this._momentumFinished=s&&a,!this._momentumFinished){const o=this.rotateMomentum?Math.abs(this.rotateMomentum.valueDelta(this._animationTime,r))*this._rotationDirection*180/Math.PI:0;let h=this.zoomMomentum?Math.abs(this.zoomMomentum.valueDelta(this._animationTime,r)):1;const u=Ne(),l=Ne();if(this._previousCenter){ke(u,this._previousCenter.x,this._previousCenter.y),ps(l,n.size,n.padding),fs(u,u,l);const{constraints:d,scale:c}=n,m=c*h;h<1&&!d.canZoomInTo(m)?(h=c/d.effectiveMaxScale,this.zoomMomentum=null,this.rotateMomentum=null):h>1&&!d.canZoomOutTo(m)&&(h=c/d.effectiveMinScale,this.zoomMomentum=null,this.rotateMomentum=null),gs(e,n.viewpoint,h,o,u,n.size),n.constraints.constrainByGeometry(e)}}this._animationTime+=r})}stopMomentumNavigation(){(this.rotateMomentum||this.zoomMomentum)&&(this.rotateMomentum&&(this._rotationMomentumEstimator.reset(),this.rotateMomentum=null),this.zoomMomentum&&(this._zoomMomentumEstimator.reset(),this.zoomMomentum=null),this.navigation.stop())}};R([O()],we.prototype,"_momentumFinished",void 0),R([O()],we.prototype,"viewpoint",void 0),R([O()],we.prototype,"navigation",void 0),we=R([Te("esri.views.2d.navigation.actions.Pinch")],we);const ka=we,gt=Ne(),mi=Ne();let Oe=class extends Ee{constructor(n){super(n),this._previousCenter=Ne(),this.viewpoint=new nt({targetGeometry:new at,scale:0,rotation:0})}begin(n,e){this.navigation.begin(),ke(this._previousCenter,e.center.x,e.center.y)}update(n,e){const{state:{size:t,padding:i}}=n;ke(gt,e.center.x,e.center.y),vs(mi,t,i),n.viewpoint=bt(this.viewpoint,n.state.paddedViewState.viewpoint,ys(mi,this._previousCenter,gt)),bs(this._previousCenter,gt)}end(){this.navigation.end()}};R([O()],Oe.prototype,"viewpoint",void 0),R([O()],Oe.prototype,"navigation",void 0),Oe=R([Te("esri.views.2d.actions.Rotate")],Oe);const Na=Oe,Ze=10,_i=1,vt=new nt({targetGeometry:new at}),yt=[0,0],pi=250;let se=class extends Ee{constructor(n){super(n),this._endTimer=null,this.animationManager=null}initialize(){this.pan=new za({navigation:this}),this.rotate=new Na({navigation:this}),this.pinch=new ka({navigation:this}),this.zoomBox=new Oa({view:this.view,navigation:this})}destroy(){this.pan.destroy(),this.rotate.destroy(),this.pinch.destroy(),this.zoomBox.destroy(),this.pan=this.rotate=this.pinch=this.zoomBox=this.animationManager=null}begin(){this._set("interacting",!0)}end(){this._lastEventTimestamp=performance.now(),this._startTimer(pi)}async zoom(n,e=this._getDefaultAnchor()){if(this.stop(),this.begin(),this.view.constraints.snapToZoom&&this.view.constraints.effectiveLODs)return n<1?this.zoomIn(e):this.zoomOut(e);this.setViewpoint(e,n,0,[0,0])}async zoomIn(n){const e=this.view,t=e.constraints.snapToNextScale(e.scale);return this._zoomToScale(t,n)}async zoomOut(n){const e=this.view,t=e.constraints.snapToPreviousScale(e.scale);return this._zoomToScale(t,n)}setViewpoint(n,e,t,i){this.begin(),this.view.state.viewpoint=this._scaleRotateTranslateViewpoint(this.view.viewpoint,n,e,t,i),this.end()}setViewpointImmediate(n,e=0,t=[0,0],i=this._getDefaultAnchor()){this.view.state.viewpoint=this._scaleRotateTranslateViewpoint(this.view.viewpoint,i,n,e,t)}continousRotateClockwise(){const n=this.get("view.viewpoint");this.animationManager.animateContinous(n,e=>{bt(e,e,-_i)})}continousRotateCounterclockwise(){const n=this.get("view.viewpoint");this.animationManager.animateContinous(n,e=>{bt(e,e,_i)})}resetRotation(){this.view.rotation=0}continousPanLeft(){this._continuousPan([-Ze,0])}continousPanRight(){this._continuousPan([Ze,0])}continousPanUp(){this._continuousPan([0,Ze])}continousPanDown(){this._continuousPan([0,-Ze])}stop(){this.pan.stopMomentumNavigation(),this.animationManager.stop(),this.end(),this._endTimer!==null&&(clearTimeout(this._endTimer),this._endTimer=null,this._set("interacting",!1))}_continuousPan(n){const e=this.view.viewpoint;this.animationManager.animateContinous(e,t=>{et(t,t,n),this.view.constraints.constrainByGeometry(t)})}_startTimer(n){return this._endTimer!==null||(this._endTimer=setTimeout(()=>{this._endTimer=null;const e=performance.now()-this._lastEventTimestamp;es&&!u))return Ot(vt,a,n/s,0,e,r,o),i.constrainByGeometry(vt),t.goTo(vt,{animate:!0})}_scaleRotateTranslateViewpoint(n,e,t,i,s){const{view:a}=this,{size:r,padding:o,constraints:h,scale:u,viewpoint:l}=a,d=u*t,c=h.canZoomInTo(d),m=h.canZoomOutTo(d);return(t<1&&!c||t>1&&!m)&&(t=1),et(l,l,s),Ot(n,l,t,i,e,r,o),h.constrainByGeometry(n)}};R([O()],se.prototype,"animationManager",void 0),R([O({type:Boolean,readOnly:!0})],se.prototype,"interacting",void 0),R([O()],se.prototype,"pan",void 0),R([O()],se.prototype,"pinch",void 0),R([O()],se.prototype,"rotate",void 0),R([O()],se.prototype,"view",void 0),R([O()],se.prototype,"zoomBox",void 0),se=R([Te("esri.views.2d.navigation.MapViewNavigation")],se);const Vo=se,Ai={shaders:{vertexShader:j("magnifier/magnifier.vert"),fragmentShader:j("magnifier/magnifier.frag")},attributes:new Map([["a_pos",0]])};function La(n){return Le(n,Ai)}async function Ga(n){const e=Dt(()=>import("./mask-svg.517894a6.js"),[]),t=Dt(()=>import("./overlay-svg.94683938.js"),[]),i=jt((await e).default,{signal:n}),s=jt((await t).default,{signal:n}),a={mask:await i,overlay:await s};return rt(n),a}class Ho extends Rs{constructor(){super(),this._handles=new ws,this._resourcePixelRatio=1,this.visible=!1}destroy(){this._handles.destroy(),this._handles=null,this._disposeRenderResources(),this._resourcesTask&&(this._resourcesTask.abort(),this._resourcesTask=null)}get background(){return this._background}set background(e){this._background=e,this.requestRender()}get magnifier(){return this._magnifier}set magnifier(e){this._magnifier=e,this._handles.removeAll(),this._handles.add([Qe(()=>e.version,()=>{this.visible=e.visible&&F(e.position)&&e.size>0,this.requestRender()},fi),Qe(()=>[e.maskUrl,e.overlayUrl],()=>this._reloadResources()),Qe(()=>e.size,()=>{this._disposeRenderResources(),this.requestRender()})])}_createTransforms(){return{dvs:Tt()}}doRender(e){var Y;const t=e.context;if(!this._resourcesTask)return void this._reloadResources();if(e.drawPhase!==k.MAP||!this._canRender())return;this._updateResources(e);const i=this._magnifier;if(N(i.position))return;const s=e.pixelRatio,a=i.size*s,r=1/i.factor,o=Math.ceil(r*a);this._readbackTexture.resize(o,o);const{size:h}=e.state,u=s*h[0],l=s*h[1],d=.5*o,c=.5*o,m=G(s*i.position.x,d,u-d-1),_=G(l-s*i.position.y,c,l-c-1);t.setBlendingEnabled(!0);const f=m-d,g=_-c,v=this._readbackTexture;t.bindTexture(v,0),t.gl.copyTexImage2D(v.descriptor.target,0,v.descriptor.pixelFormat,f,g,o,o,0);const p=(Y=this.background)==null?void 0:Y.color,w=p?[p.a*p.r/255,p.a*p.g/255,p.a*p.b/255,p.a]:[1,1,1,1],y=(m+i.offset.x*s)/u*2-1,b=(_-i.offset.y*s)/l*2-1,x=a/u*2,z=a/l*2,T=this._program;t.bindVAO(this._vertexArrayObject),t.bindTexture(this._overlayTexture,6),t.bindTexture(this._maskTexture,7),t.useProgram(T),T.setUniform4fv("u_background",w),T.setUniform1i("u_readbackTexture",0),T.setUniform1i("u_overlayTexture",6),T.setUniform1i("u_maskTexture",7),T.setUniform4f("u_drawPos",y,b,x,z),T.setUniform1i("u_maskEnabled",i.maskEnabled?1:0),T.setUniform1i("u_overlayEnabled",i.overlayEnabled?1:0),t.setStencilTestEnabled(!1),t.setColorMask(!0,!0,!0,!0),t.drawArrays(Ae.TRIANGLE_STRIP,0,4),t.bindVAO()}_canRender(){return this.mask&&this.overlay&&this._magnifier!=null}_reloadResources(){this._resourcesTask&&this._resourcesTask.abort();const e=F(this._magnifier)?this._magnifier.maskUrl:null,t=F(this._magnifier)?this._magnifier.overlayUrl:null;this._resourcesTask=xs(async i=>{const s=N(e)||N(t)?Ga(i):null,a=F(e)?xe(e,{responseType:"image",signal:i}).then(u=>u.data):s.then(u=>u.mask),r=F(t)?xe(t,{responseType:"image",signal:i}).then(u=>u.data):s.then(u=>u.overlay),[o,h]=await Promise.all([a,r]);this.mask=o,this.overlay=h,this._disposeRenderResources(),this.requestRender()})}_disposeRenderResources(){this._readbackTexture=U(this._readbackTexture),this._overlayTexture=U(this._overlayTexture),this._maskTexture=U(this._maskTexture),this._vertexArrayObject=U(this._vertexArrayObject),this._program=U(this._program)}_updateResources(e){if(e.pixelRatio!==this._resourcePixelRatio&&this._disposeRenderResources(),this._readbackTexture)return;const t=e.context;this._resourcePixelRatio=e.pixelRatio;const i=Math.ceil(this._magnifier.size*e.pixelRatio);this._program=La(t);const s=new Uint16Array([0,1,0,0,1,1,1,0]),a=Ai.attributes;this._vertexArrayObject=new Et(t,a,Is,{geometry:Mt.createVertex(t,Rt.STATIC_DRAW,s)}),this.overlay.width=i,this.overlay.height=i,this._overlayTexture=new W(t,{target:A.TEXTURE_2D,pixelFormat:E.RGBA,internalFormat:E.RGBA,dataType:C.UNSIGNED_BYTE,wrapMode:D.CLAMP_TO_EDGE,samplingMode:B.NEAREST,flipped:!0,preMultiplyAlpha:!Ts(this.overlay.src)||!e.context.driverTest.svgAlwaysPremultipliesAlpha},this.overlay),this.mask.width=i,this.mask.height=i,this._maskTexture=new W(t,{target:A.TEXTURE_2D,pixelFormat:E.ALPHA,internalFormat:E.ALPHA,dataType:C.UNSIGNED_BYTE,wrapMode:D.CLAMP_TO_EDGE,samplingMode:B.NEAREST,flipped:!0},this.mask);const r=1/this._magnifier.factor;this._readbackTexture=new W(t,{target:A.TEXTURE_2D,pixelFormat:E.RGBA,internalFormat:E.RGBA,dataType:C.UNSIGNED_BYTE,wrapMode:D.CLAMP_TO_EDGE,samplingMode:B.LINEAR,flipped:!1,width:Math.ceil(r*i),height:Math.ceil(r*i)})}}export{Xo as GraphicContainer,jo as GraphicsView2D,Go as LabelManager,Ho as MagnifierView2D,Vo as MapViewNavigation,Lo as Stage};