import{eL as W,x as E,A as h,B as c,C as N,bk as $,eM as R,aC as v,b3 as H,bv as q,aD as C,e2 as b,c3 as T,q as B}from"./index-b5c8f851.js";import{b as I}from"./Bitmap-e9c1dde3.js";const k=Math.PI/180;function A(e){return e*k}function U(e,i){const s=A(i.rotation),t=Math.abs(Math.cos(s)),r=Math.abs(Math.sin(s)),[o,n]=i.size;return e[0]=Math.round(n*r+o*t),e[1]=Math.round(n*t+o*r),e}function j(e,i,s,t){const[r,o]=i,[n,a]=t,l=.5*s;return e[0]=r-l*n,e[1]=o-l*a,e[2]=r+l*n,e[3]=o+l*a,e}const u=W(),m=[0,0],_=new E(0,0,0,0),y={container:null,fetchSource:null,requestUpdate:null,imageMaxWidth:2048,imageMaxHeight:2048,imageRotationSupported:!1,imageNormalizationSupported:!1,hidpi:!1};let p=class extends ${constructor(e){super(e),this._imagePromise=null,this.bitmaps=[],this.hidpi=y.hidpi,this.imageMaxWidth=y.imageMaxWidth,this.imageMaxHeight=y.imageMaxHeight,this.imageRotationSupported=y.imageRotationSupported,this.imageNormalizationSupported=y.imageNormalizationSupported,this.update=R(async(i,s)=>{if(v(s),!i.stationary||this.destroyed)return;const t=i.state,r=H(t.spatialReference),o=this.hidpi?i.pixelRatio:1,n=this.imageNormalizationSupported&&t.worldScreenWidth&&t.worldScreenWidtha||Math.floor(m[1]*o)>l,S=r&&(t.extent.xminr.valid[1]),x=!this.imageNormalizationSupported&&S,w=!M&&!x,f=this.imageRotationSupported?t.rotation:0,z=this.container.children.slice();if(w){const d=n?t.paddedViewState.center:t.center;this._imagePromise&&console.error("Image promise was not defined!"),this._imagePromise=this._singleExport(t,m,d,t.resolution,f,o,s)}else{let d=Math.min(a,l);x&&(d=Math.min(t.worldScreenWidth,d)),this._imagePromise=this._tiledExport(t,d,o,s)}try{const d=await this._imagePromise??[];v(s);const P=[];if(this._imagePromise=null,this.destroyed)return;this.bitmaps=d;for(const g of z)d.includes(g)||P.push(g.fadeOut().then(()=>{g.remove(),g.destroy()}));for(const g of d)P.push(g.fadeIn());await Promise.all(P)}catch(d){this._imagePromise=null,q(d)}},5e3),this.updateExports=R(async i=>{const s=[];for(const t of this.container.children){if(!t.visible||!t.stage)return;s.push(i(t).then(()=>{t.invalidateTexture(),t.requestRender()}))}this._imagePromise=C(s).then(()=>this._imagePromise=null),await this._imagePromise})}destroy(){this.bitmaps.forEach(e=>e.destroy()),this.bitmaps=[]}get updating(){return!this.destroyed&&this._imagePromise!==null}async _export(e,i,s,t,r,o){const n=await this.fetchSource(e,Math.floor(i*r),Math.floor(s*r),{rotation:t,pixelRatio:r,signal:o});v(o);const a=new I(null,!0);return a.x=e.xmin,a.y=e.ymax,a.resolution=e.width/i,a.rotation=t,a.pixelRatio=r,a.opacity=0,this.container.addChild(a),await a.setSourceAsync(n,o),v(o),a}async _singleExport(e,i,s,t,r,o,n){j(u,s,t,i);const a=b(u,e.spatialReference);return[await this._export(a,i[0],i[1],r,o,n)]}_tiledExport(e,i,s,t){const r=T.create({size:i,spatialReference:e.spatialReference,scales:[e.scale]}),o=new B(r),n=o.getTileCoverage(e);if(!n)return null;const a=[];return n.forEach((l,M,S,x)=>{_.set(l,M,S,0),o.getTileBounds(u,_);const w=b(u,e.spatialReference);a.push(this._export(w,i,i,0,s,t).then(f=>(x!==0&&(_.set(l,M,S,x),o.getTileBounds(u,_),f.x=u[0],f.y=u[3]),f)))}),Promise.all(a)}};h([c()],p.prototype,"_imagePromise",void 0),h([c()],p.prototype,"bitmaps",void 0),h([c()],p.prototype,"container",void 0),h([c()],p.prototype,"fetchSource",void 0),h([c()],p.prototype,"hidpi",void 0),h([c()],p.prototype,"imageMaxWidth",void 0),h([c()],p.prototype,"imageMaxHeight",void 0),h([c()],p.prototype,"imageRotationSupported",void 0),h([c()],p.prototype,"imageNormalizationSupported",void 0),h([c()],p.prototype,"requestUpdate",void 0),h([c()],p.prototype,"updating",null),p=h([N("esri.views.2d.layers.support.ExportStrategy")],p);const L=p;export{L as v};