@plannco-ppe/ppe-core 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,4 +8,4 @@ var C_=Object.defineProperty;var w_=(Tt,$t,et)=>$t in Tt?C_(Tt,$t,{enumerable:!0
8
8
  <div style="height: 1rem; width: 1rem; background-color: ${n.color}"></div>
9
9
  <div>${n.name}</div>
10
10
  </div>
11
- `}const Wg={a0:[1189,841],a1:[841,594],a2:[594,420],a3:[420,297],a4:[297,210],a5:[210,148]},hh={name:"ppe-pdf-export",getInitialState:n=>({...n}),createPlanEditor:n=>{n.exportToPdf=t=>jg(n,t),n.exportPeriodicPdf=t=>Vg(n,t)}};async function ch(n,t,e){return new Promise(i=>{n.once("rendercomplete",function(){setTimeout(()=>{const s=document.createElement("canvas");s.width=t,s.height=e;const r=s.getContext("2d");if(!r){console.error("Unable to get canvas context"),i("");return}r.fillStyle="#FFFFFF",r.fillRect(0,0,t,e);const o=n.getViewport().querySelectorAll(".ol-layer canvas, canvas.ol-layer");Array.from(o).forEach(a=>{var l,h;if(a instanceof HTMLCanvasElement&&a.width>0){const c=((l=a.parentNode)==null?void 0:l.style.opacity)||"1";r.globalAlpha=parseFloat(c);const d=(h=a.style.transform.match(/^matrix\(([^(]*)\)$/))==null?void 0:h[1].split(",").map(Number);d&&r.setTransform(...d),r.drawImage(a,0,0),r.setTransform(1,0,0,1,0,0),r.globalAlpha=1}}),i(s.toDataURL("image/jpeg",1))},100)}),n.renderSync()})}function uh(n){const t=n.getTarget(),e=n.getSize();return{size:e?[e[0],e[1]]:[0,0],view:{center:n.getView().getCenter()||[0,0],zoom:n.getView().getZoom()||1,rotation:n.getView().getRotation()||0},containerStyles:{width:t.style.width,height:t.style.height,maxWidth:t.style.maxWidth,maxHeight:t.style.maxHeight}}}function dh(n,t){const e=n.getTarget();e.style.width=t.containerStyles.width,e.style.height=t.containerStyles.height,e.style.maxWidth=t.containerStyles.maxWidth,e.style.maxHeight=t.containerStyles.maxHeight,n.setSize(t.size),n.getView().setCenter(t.view.center),n.getView().setZoom(t.view.zoom),n.getView().setRotation(t.view.rotation)}function fh(n,t,e,i){const s=Wg[t],[r,o]=e==="landscape"?[s[0],s[1]]:[s[1],s[0]],a=i/25.4,l=Math.round(r*a),h=Math.round(o*a),c=n.getTarget();return c.style.width=`${l}px`,c.style.height=`${h}px`,c.style.maxWidth="none",c.style.maxHeight="none",n.setSize([l,h]),{width:r,height:o,canvasWidth:l,canvasHeight:h}}async function jg(n,t){const e=(t==null?void 0:t.format)||"a4",i=(t==null?void 0:t.orientation)||"landscape",s=(t==null?void 0:t.resolution)||350,r=(t==null?void 0:t.filename)||"map.pdf",o=(t==null?void 0:t.fitContent)!==!1,a=new $t.jsPDF(i,"mm",e),l=uh(n);try{const{width:h,height:c,canvasWidth:u,canvasHeight:d}=fh(n,e,i,s);o&&(n.fitToContent(),await new Promise(g=>setTimeout(g,500)));const f=await ch(n,u,d);f&&a.addImage(f,"JPEG",0,0,h,c,void 0,"FAST"),a.save(r)}finally{dh(n,l)}}async function Vg(n,t){var h,c,u;const e=t.format||"a4",i=t.orientation||"landscape",s=t.resolution||350,r=t.filename||"periodic-export.pdf",o=t.periods;if(!o||o.length===0)throw new Error("No periods provided for periodic export");const a=new $t.jsPDF(i,"mm",e),l=uh(n);try{const{width:d,height:f,canvasWidth:g,canvasHeight:m}=fh(n,e,i,s);n.fitToContent(),await new Promise(_=>setTimeout(_,500));for(let _=0;_<o.length&&!((h=t.onCancel)!=null&&h.call(t));_++){const y=o[_];await t.updateTasksForPeriod(y);const p=await ch(n,g,m);(c=t.onProgress)==null||c.call(t,_+1,o.length,y.label,p),_>0&&a.addPage(),p&&(a.addImage(p,"JPEG",0,0,d,f,void 0,"FAST"),a.setFontSize(10),a.setTextColor(0,0,0),a.text(`Période: ${y.label}`,10,f-10))}(u=t.onCancel)!=null&&u.call(t)||a.save(r)}finally{dh(n,l)}}let To;const Sn=[];function gh(n,t,e,i,s){n.beginPath(),n.moveTo(0,0),n.lineTo(t,e),n.lineTo(i,s),n.closePath(),n.save(),n.clip(),n.fillRect(0,0,Math.max(t,i)+1,Math.max(e,s)),n.restore()}function Po(n,t){return Math.abs(n[t*4]-210)>2||Math.abs(n[t*4+3]-191.25)>2}function Xg(){if(To===void 0){const n=dt(6,6,Sn);n.globalCompositeOperation="lighter",n.fillStyle="rgba(210, 0, 0, 0.75)",gh(n,4,5,4,0),gh(n,4,5,0,5);const t=n.getImageData(0,0,3,3).data;To=Po(t,0)||Po(t,4)||Po(t,8),Zs(n),Sn.push(n.canvas)}return To}function Bg(n,t,e,i){const s=fa(e,t,n);let r=ua(t,i,e);const o=t.getMetersPerUnit();o!==void 0&&(r*=o);const a=n.getMetersPerUnit();a!==void 0&&(r/=a);const l=n.getExtent();if(!l||ki(l,s)){const h=ua(n,r,s)/r;isFinite(h)&&h>0&&(r/=h)}return r}function Yg(n,t,e,i,s,r,o,a,l,h,c,u,d,f){const g=dt(Math.round(e*n),Math.round(e*t),Sn);if(u||(g.imageSmoothingEnabled=!1),l.length===0)return g.canvas;g.scale(e,e);function m(C){return Math.round(C*e)/e}g.globalCompositeOperation="lighter";const _=Ot();l.forEach(function(C,S,T){zo(_,C.extent)});let y;const p=e/i,E=(u?1:1+Math.pow(2,-24))/p;(l.length!==1||h!==0)&&(y=dt(Math.round(K(_)*p),Math.round(ut(_)*p),Sn),u||(y.imageSmoothingEnabled=!1),l.forEach(function(C,S,T){if(C.image.width>0&&C.image.height>0){if(C.clipExtent){y.save();const N=(C.clipExtent[0]-_[0])*p,j=-(C.clipExtent[3]-_[3])*p,F=K(C.clipExtent)*p,q=ut(C.clipExtent)*p;y.rect(u?N:Math.round(N),u?j:Math.round(j),u?F:Math.round(N+F)-Math.round(N),u?q:Math.round(j+q)-Math.round(j)),y.clip()}const I=(C.extent[0]-_[0])*p,v=-(C.extent[3]-_[3])*p,M=K(C.extent)*p,k=ut(C.extent)*p;y.drawImage(C.image,h,h,C.image.width-2*h,C.image.height-2*h,u?I:Math.round(I),u?v:Math.round(v),u?M:Math.round(I+M)-Math.round(I),u?k:Math.round(v+k)-Math.round(v)),C.clipExtent&&y.restore()}}));const x=An(o);return a.getTriangles().forEach(function(C,S,T){const I=C.source,v=C.target;let M=I[0][0],k=I[0][1],N=I[1][0],j=I[1][1],F=I[2][0],q=I[2][1];const b=m((v[0][0]-x[0])/r),W=m(-(v[0][1]-x[1])/r),V=m((v[1][0]-x[0])/r),Q=m(-(v[1][1]-x[1])/r),J=m((v[2][0]-x[0])/r),tt=m(-(v[2][1]-x[1])/r),R=M,Ce=k;M=0,k=0,N-=R,j-=Ce,F-=R,q-=Ce;const ii=[[N,j,0,0,V-b],[F,q,0,0,J-b],[0,0,N,j,Q-W],[0,0,F,q,tt-W]],wt=Nh(ii);if(!wt)return;if(g.save(),g.beginPath(),Xg()||!u){g.moveTo(V,Q);const qt=4,Ne=b-V,In=W-Q;for(let se=0;se<qt;se++)g.lineTo(V+m((se+1)*Ne/qt),Q+m(se*In/(qt-1))),se!=qt-1&&g.lineTo(V+m((se+1)*Ne/qt),Q+m((se+1)*In/(qt-1)));g.lineTo(J,tt)}else g.moveTo(V,Q),g.lineTo(b,W),g.lineTo(J,tt);g.clip(),g.transform(wt[0],wt[2],wt[1],wt[3],b,W),g.translate(_[0]-R,_[3]-Ce);let ne;if(y)ne=y.canvas,g.scale(E,-E);else{const qt=l[0],Ne=qt.extent;ne=qt.image,g.scale(K(Ne)/ne.width,-ut(Ne)/ne.height)}g.drawImage(ne,0,0),g.restore()}),y&&(Zs(y),Sn.push(y.canvas)),g.canvas}function Mo(n){return Array.isArray(n)?Math.min(...n):n}const Zg=10,_h=.25;class Kg{constructor(t,e,i,s,r,o,a){this.sourceProj_=t,this.targetProj_=e;let l={};const h=a?wc(E=>_t(a,fa(E,this.targetProj_,this.sourceProj_))):Xi(this.targetProj_,this.sourceProj_);this.transformInv_=function(E){const x=E[0]+"/"+E[1];return l[x]||(l[x]=h(E)),l[x]},this.maxSourceExtent_=s,this.errorThresholdSquared_=r*r,this.triangles_=[],this.wrapsXInSource_=!1,this.canWrapXInSource_=this.sourceProj_.canWrapX()&&!!s&&!!this.sourceProj_.getExtent()&&K(s)>=K(this.sourceProj_.getExtent()),this.sourceWorldWidth_=this.sourceProj_.getExtent()?K(this.sourceProj_.getExtent()):null,this.targetWorldWidth_=this.targetProj_.getExtent()?K(this.targetProj_.getExtent()):null;const c=An(i),u=zs(i),d=Ns(i),f=ks(i),g=this.transformInv_(c),m=this.transformInv_(u),_=this.transformInv_(d),y=this.transformInv_(f),p=Zg+(o?Math.max(0,Math.ceil(Math.log2(Ah(i)/(o*o*256*256)))):0);if(this.addQuad_(c,u,d,f,g,m,_,y,p),this.wrapsXInSource_){let E=1/0;this.triangles_.forEach(function(x,C,S){E=Math.min(E,x.source[0][0],x.source[1][0],x.source[2][0])}),this.triangles_.forEach(x=>{if(Math.max(x.source[0][0],x.source[1][0],x.source[2][0])-E>this.sourceWorldWidth_/2){const C=[[x.source[0][0],x.source[0][1]],[x.source[1][0],x.source[1][1]],[x.source[2][0],x.source[2][1]]];C[0][0]-E>this.sourceWorldWidth_/2&&(C[0][0]-=this.sourceWorldWidth_),C[1][0]-E>this.sourceWorldWidth_/2&&(C[1][0]-=this.sourceWorldWidth_),C[2][0]-E>this.sourceWorldWidth_/2&&(C[2][0]-=this.sourceWorldWidth_);const S=Math.min(C[0][0],C[1][0],C[2][0]);Math.max(C[0][0],C[1][0],C[2][0])-S<this.sourceWorldWidth_/2&&(x.source=C)}})}l={}}addTriangle_(t,e,i,s,r,o){this.triangles_.push({source:[s,r,o],target:[t,e,i]})}addQuad_(t,e,i,s,r,o,a,l,h){const c=ct([r,o,a,l]),u=this.sourceWorldWidth_?K(c)/this.sourceWorldWidth_:null,d=this.sourceWorldWidth_,f=this.sourceProj_.canWrapX()&&u>.5&&u<1;let g=!1;if(h>0){if(this.targetProj_.isGlobal()&&this.targetWorldWidth_){const _=ct([t,e,i,s]);g=K(_)/this.targetWorldWidth_>_h||g}!f&&this.sourceProj_.isGlobal()&&u&&(g=u>_h||g)}if(!g&&this.maxSourceExtent_&&isFinite(c[0])&&isFinite(c[1])&&isFinite(c[2])&&isFinite(c[3])&&!gt(c,this.maxSourceExtent_))return;let m=0;if(!g&&(!isFinite(r[0])||!isFinite(r[1])||!isFinite(o[0])||!isFinite(o[1])||!isFinite(a[0])||!isFinite(a[1])||!isFinite(l[0])||!isFinite(l[1]))){if(h>0)g=!0;else if(m=(!isFinite(r[0])||!isFinite(r[1])?8:0)+(!isFinite(o[0])||!isFinite(o[1])?4:0)+(!isFinite(a[0])||!isFinite(a[1])?2:0)+(!isFinite(l[0])||!isFinite(l[1])?1:0),m!=1&&m!=2&&m!=4&&m!=8)return}if(h>0){if(!g){const _=[(t[0]+i[0])/2,(t[1]+i[1])/2],y=this.transformInv_(_);let p;f?p=(ri(r[0],d)+ri(a[0],d))/2-ri(y[0],d):p=(r[0]+a[0])/2-y[0];const E=(r[1]+a[1])/2-y[1];g=p*p+E*E>this.errorThresholdSquared_}if(g){if(Math.abs(t[0]-i[0])<=Math.abs(t[1]-i[1])){const _=[(e[0]+i[0])/2,(e[1]+i[1])/2],y=this.transformInv_(_),p=[(s[0]+t[0])/2,(s[1]+t[1])/2],E=this.transformInv_(p);this.addQuad_(t,e,_,p,r,o,y,E,h-1),this.addQuad_(p,_,i,s,E,y,a,l,h-1)}else{const _=[(t[0]+e[0])/2,(t[1]+e[1])/2],y=this.transformInv_(_),p=[(i[0]+s[0])/2,(i[1]+s[1])/2],E=this.transformInv_(p);this.addQuad_(t,_,p,s,r,y,E,l,h-1),this.addQuad_(_,e,i,p,y,o,a,E,h-1)}return}}if(f){if(!this.canWrapXInSource_)return;this.wrapsXInSource_=!0}(m&11)==0&&this.addTriangle_(t,i,s,r,a,l),(m&14)==0&&this.addTriangle_(t,i,e,r,a,o),m&&((m&13)==0&&this.addTriangle_(e,s,t,o,l,r),(m&7)==0&&this.addTriangle_(e,s,i,o,l,a))}calculateSourceExtent(){const t=Ot();return this.triangles_.forEach(function(e,i,s){const r=e.source;Wi(t,r[0]),Wi(t,r[1]),Wi(t,r[2])}),t}getTriangles(){return this.triangles_}}const Ug=.5;class Hg extends gr{constructor(t,e,i,s,r,o,a){let l=t.getExtent();l&&t.canWrapX()&&(l=l.slice(),l[0]=-1/0,l[2]=1/0);let h=e.getExtent();h&&e.canWrapX()&&(h=h.slice(),h[0]=-1/0,h[2]=1/0);const c=h?Gs(i,h):i,u=Vt(c),d=Bg(t,e,u,s),f=Ug,g=new Kg(t,e,c,l,d*f,s),m=g.calculateSourceExtent(),_=si(m)?null:o(m,d,r),y=_?P.IDLE:P.EMPTY,p=_?_.getPixelRatio():1;super(i,s,p,y),this.targetProj_=e,this.maxSourceExtent_=l,this.triangulation_=g,this.targetResolution_=s,this.targetExtent_=i,this.sourceImage_=_,this.sourcePixelRatio_=p,this.interpolate_=a,this.canvas_=null,this.sourceListenerKey_=null}disposeInternal(){this.state==P.LOADING&&this.unlistenSource_(),super.disposeInternal()}getImage(){return this.canvas_}getProjection(){return this.targetProj_}reproject_(){const t=this.sourceImage_.getState();if(t==P.LOADED){const e=K(this.targetExtent_)/this.targetResolution_,i=ut(this.targetExtent_)/this.targetResolution_;this.canvas_=Yg(e,i,this.sourcePixelRatio_,Mo(this.sourceImage_.getResolution()),this.maxSourceExtent_,this.targetResolution_,this.targetExtent_,this.triangulation_,[{extent:this.sourceImage_.getExtent(),image:this.sourceImage_.getImage()}],0,void 0,this.interpolate_)}this.state=t,this.changed()}load(){if(this.state==P.IDLE){this.state=P.LOADING,this.changed();const t=this.sourceImage_.getState();t==P.LOADED||t==P.ERROR?this.reproject_():(this.sourceListenerKey_=z(this.sourceImage_,D.CHANGE,e=>{const i=this.sourceImage_.getState();(i==P.LOADED||i==P.ERROR)&&(this.unlistenSource_(),this.reproject_())}),this.sourceImage_.load())}}unlistenSource_(){$(this.sourceListenerKey_),this.sourceListenerKey_=null}}const Ps=4,Lo={IMAGELOADSTART:"imageloadstart",IMAGELOADEND:"imageloadend",IMAGELOADERROR:"imageloaderror"};class qg extends Pt{constructor(t,e){super(t),this.image=e}}class $g extends Gl{constructor(t){super({attributions:t.attributions,projection:t.projection,state:t.state,interpolate:t.interpolate!==void 0?t.interpolate:!0}),this.on,this.once,this.un,this.loader=t.loader||null,this.resolutions_=t.resolutions!==void 0?t.resolutions:null,this.reprojectedImage_=null,this.reprojectedRevision_=0,this.image=null,this.wantedExtent_,this.wantedResolution_,this.static_=t.loader?t.loader.length===0:!1,this.wantedProjection_=null}getResolutions(){return this.resolutions_}setResolutions(t){this.resolutions_=t}findNearestResolution(t){const e=this.getResolutions();if(e){const i=Fs(e,t,0);t=e[i]}return t}getImage(t,e,i,s){const r=this.getProjection();if(!r||!s||er(r,s))return r&&(s=r),this.getImageInternal(t,e,i,s);if(this.reprojectedImage_){if(this.reprojectedRevision_==this.getRevision()&&er(this.reprojectedImage_.getProjection(),s)&&this.reprojectedImage_.getResolution()==e&&zi(this.reprojectedImage_.getExtent(),t))return this.reprojectedImage_;this.reprojectedImage_.dispose(),this.reprojectedImage_=null}return this.reprojectedImage_=new Hg(r,s,t,e,i,(o,a,l)=>this.getImageInternal(o,a,l,r),this.getInterpolate()),this.reprojectedRevision_=this.getRevision(),this.reprojectedImage_}getImageInternal(t,e,i,s){if(this.loader){const r=Qg(t,e,i,1),o=this.findNearestResolution(e);if(this.image&&(this.static_||this.wantedProjection_===s&&(this.wantedExtent_&&ae(this.wantedExtent_,r)||ae(this.image.getExtent(),r))&&(this.wantedResolution_&&Mo(this.wantedResolution_)===o||Mo(this.image.getResolution())===o)))return this.image;this.wantedProjection_=s,this.wantedExtent_=r,this.wantedResolution_=o,this.image=new gr(r,o,i,this.loader),this.image.addEventListener(D.CHANGE,this.handleImageChange.bind(this))}return this.image}handleImageChange(t){const e=t.target;let i;switch(e.getState()){case P.LOADING:this.loading=!0,i=Lo.IMAGELOADSTART;break;case P.LOADED:this.loading=!1,i=Lo.IMAGELOADEND;break;case P.ERROR:this.loading=!1,i=Lo.IMAGELOADERROR;break;default:return}this.hasListener(i)&&this.dispatchEvent(new qg(i,e))}}function Jg(n,t){n.getImage().src=t}function Qg(n,t,e,i){const s=t/e,r=Vt(n),o=bn(K(n)/s,Ps),a=bn(ut(n)/s,Ps),l=bn((i-1)*o/2,Ps),h=o+2*l,c=bn((i-1)*a/2,Ps),u=a+2*c;return Ln(r,s,0,[h,u])}function t_(n){const t=n.load||Ea,e=n.imageExtent,i=n.crossOrigin??null;return()=>{const s=new Image;return s.crossOrigin=i,t(s,n.url).then(r=>{const o=K(e)/r.width,a=ut(e)/r.height;return{image:r,extent:e,resolution:o!==a?[o,a]:a,pixelRatio:1}})}}class e_ extends $g{constructor(t){const e=t.crossOrigin!==void 0?t.crossOrigin:null,i=t.imageLoadFunction!==void 0?t.imageLoadFunction:Jg;super({attributions:t.attributions,interpolate:t.interpolate,projection:ot(t.projection)}),this.url_=t.url,this.imageExtent_=t.imageExtent,this.image=null,this.image=new gr(this.imageExtent_,void 0,1,t_({url:t.url,imageExtent:t.imageExtent,crossOrigin:e,load:(s,r)=>(this.image.setImage(s),i(this.image,r),Ea(s))})),this.image.addEventListener(D.CHANGE,this.handleImageChange.bind(this))}getImageExtent(){return this.imageExtent_}getImageInternal(t,e,i,s){return gt(t,this.image.getExtent())?this.image:null}getUrl(){return this.url_}}class i_ extends Qa{constructor(t){super(t),this.image=null}getImage(){return this.image?this.image.getImage():null}prepareFrame(t){const e=t.layerStatesArray[t.layerIndex],i=t.pixelRatio,s=t.viewState,r=s.resolution,o=this.getLayer().getSource(),a=t.viewHints;let l=t.extent;if(e.extent!==void 0&&(l=Gs(l,Te(e.extent,s.projection))),!a[et.ANIMATING]&&!a[et.INTERACTING]&&!si(l))if(o){const h=s.projection,c=o.getImage(l,r,i,h);c&&(this.loadImage(c)?this.image=c:c.getState()===P.EMPTY&&(this.image=null))}else this.image=null;return!!this.image}getData(t){const e=this.frameState;if(!e)return null;const i=this.getLayer(),s=_t(e.pixelToCoordinateTransform,t.slice()),r=i.getExtent();if(r&&!ki(r,s))return null;const o=this.image.getExtent(),a=this.image.getImage(),l=K(o),h=Math.floor(a.width*((s[0]-o[0])/l));if(h<0||h>=a.width)return null;const c=ut(o),u=Math.floor(a.height*((o[3]-s[1])/c));return u<0||u>=a.height?null:this.getImageData(a,h,u)}renderFrame(t,e){const i=this.image,s=i.getExtent(),r=i.getResolution(),[o,a]=Array.isArray(r)?r:[r,r],l=i.getPixelRatio(),h=t.layerStatesArray[t.layerIndex],c=t.pixelRatio,u=t.viewState,d=u.center,f=u.resolution,g=c*o/(f*l),m=c*a/(f*l);this.prepareContainer(t,e);const _=this.context.canvas.width,y=this.context.canvas.height,p=this.getRenderContext(t);let E=!1,x=!0;if(h.extent){const v=Te(h.extent,u.projection);x=gt(v,t.extent),E=x&&!ae(v,t.extent),E&&this.clipUnrotated(p,t,v)}const C=i.getImage(),S=de(this.tempTransform,_/2,y/2,g,m,0,l*(s[0]-d[0])/o,l*(d[1]-s[3])/a);this.renderedResolution=a*c/l;const T=C.width*S[0],I=C.height*S[3];if(this.getLayer().getSource().getInterpolate()||(p.imageSmoothingEnabled=!1),this.preRender(p,t),x&&T>=.5&&I>=.5){const v=S[4],M=S[5],k=h.opacity;k!==1&&(p.save(),p.globalAlpha=k),p.drawImage(C,0,0,+C.width,+C.height,v,M,T,I),k!==1&&p.restore()}return this.postRender(this.context,t),E&&p.restore(),p.imageSmoothingEnabled=!0,this.container}}class n_ extends ds{constructor(t){t=t||{},super(t)}}class s_ extends n_{constructor(t){super(t)}createRenderer(){return new i_(this)}getData(t){return super.getData(t)}}function r_(n,t){return typeof n=="function"?n(t):n}const o_={name:"ppe-popup",getInitialState:n=>({...n}),createPlanEditor:n=>{const{overlay:t,closerElement:e,popupElement:i}=l_();n.addOverlay(t),e.addEventListener("click",()=>(t.setPosition(void 0),e.blur(),!1)),n._showPopup=(s,r)=>{t.setPosition(s.event.coordinate),i.innerHTML=s.content,r!=null&&r.offset&&t.setOffset(r.offset),t.setPositioning(a_(n,s.event,r==null?void 0:r.positioning))},n._hidePopup=()=>{t.setPosition(void 0)}}};function a_(n,t,e){if(e&&e!="auto")return e;const i=n.getSize();if(!i)return"top-right";const[s,r]=n.getPixelFromCoordinate(t.coordinate),[o,a]=i,l=s<o/2?"left":"right";return`${r<a/2?"top":"bottom"}-${l}`}function l_(){const n=document.createElement("div");n.id="ppe-popup",n.className="ppe-popup";const t=document.createElement("button");t.className="ppe-popup-closer";const e=document.createElement("div");return e.className="ppe-popup-content",n.insertAdjacentElement("beforeend",t),n.insertAdjacentElement("beforeend",e),{overlay:new tg({element:n,stopEvent:!1}),popupElement:n,closerElement:t}}const mh=[nh,{name:"ppe-layer",getInitialState:n=>({...n}),createPlanEditor:n=>{n.addVectorLayer=()=>{const t=new pn({wrapX:!1}),e=new Ii({source:t});return n.initialState._extent&&e.setExtent(n.initialState._extent),e}}},o_,hh];function h_(n){var m;const t=[...mh,...n._plugins??[]],{plan:e}=n,i=[0,0,e.file.width,e.file.height],s=new kn({code:"",units:"pixels",extent:i}),r=new e_({imageExtent:i,projection:s,url:e.file.original_url,crossOrigin:"anonymous"}),o=new s_({source:r}),a=new ee({projection:s,center:Vt(i),zoom:2,minZoom:0,maxZoom:10}),l=new Jf({target:n.target??"map",layers:[o],view:a}),h={_extent:i,_projection:s},c=l;c._plugins=t;const u=c._plugins.reduce((_,y)=>{var p;return Object.assign(_,(p=y.getDefaultOptions)==null?void 0:p.call(y,c))},{});let d={...h,...n.initialState??{}};c._plugins.forEach(_=>{var y;d=((y=_.getInitialState)==null?void 0:y.call(_,d))??d});const f=_=>c.options.mergeOptions?c.options.mergeOptions(u,_):{...u,..._},g={_plugins:t,options:{...u,...n},initialState:d,reset:()=>{c.setState(c.initialState)},getState:()=>c.options.state,setState:_=>{var y,p;(p=(y=c.options).onStateChange)==null||p.call(y,_)},setOptions:_=>{const y=r_(_,c.options),p=c.getTarget(),E=f(y);c.options=E,E.target&&E.target!==p&&c.setTarget(E.target)},fitToContent:()=>{const _=c.getView(),y=c.getSize();y&&i&&_.fit(i,{size:y,padding:[0,0,0,0],duration:500})}};Object.assign(c,g);for(const _ of c._plugins)(m=_==null?void 0:_.createPlanEditor)==null||m.call(_,c);return c}return Tt.PdfExportPlugin=hh,Tt.ZoningPlugin=nh,Tt.convertToZoneGeometry=Rs,Tt.convertZoneToGeometryFeatures=ih,Tt.createPlanEditor=h_,Tt.defaultPlugins=mh,Object.defineProperty(Tt,Symbol.toStringTag,{value:"Module"}),Tt})({},jspdf);
11
+ `}const Wg={a0:[1189,841],a1:[841,594],a2:[594,420],a3:[420,297],a4:[297,210],a5:[210,148]},hh={name:"ppe-pdf-export",getInitialState:n=>({...n}),createPlanEditor:n=>{n.exportToPdf=t=>jg(n,t),n.exportPeriodicPdf=t=>Vg(n,t)}};async function ch(n,t,e){return new Promise(i=>{n.once("rendercomplete",function(){setTimeout(()=>{const s=document.createElement("canvas");s.width=t,s.height=e;const r=s.getContext("2d");if(!r){console.error("Unable to get canvas context"),i("");return}r.fillStyle="#FFFFFF",r.fillRect(0,0,t,e);const o=n.getViewport().querySelectorAll(".ol-layer canvas, canvas.ol-layer");Array.from(o).forEach(a=>{var l,h;if(a instanceof HTMLCanvasElement&&a.width>0){const c=((l=a.parentNode)==null?void 0:l.style.opacity)||"1";r.globalAlpha=parseFloat(c);const d=(h=a.style.transform.match(/^matrix\(([^(]*)\)$/))==null?void 0:h[1].split(",").map(Number);d&&r.setTransform(...d),r.drawImage(a,0,0),r.setTransform(1,0,0,1,0,0),r.globalAlpha=1}}),i(s.toDataURL("image/jpeg",1))},100)}),n.renderSync()})}function uh(n){const t=n.getTarget(),e=n.getSize();return{size:e?[e[0],e[1]]:[0,0],view:{center:n.getView().getCenter()||[0,0],zoom:n.getView().getZoom()||1,rotation:n.getView().getRotation()||0},containerStyles:{width:t.style.width,height:t.style.height,maxWidth:t.style.maxWidth,maxHeight:t.style.maxHeight}}}function dh(n,t){const e=n.getTarget();e.style.width=t.containerStyles.width,e.style.height=t.containerStyles.height,e.style.maxWidth=t.containerStyles.maxWidth,e.style.maxHeight=t.containerStyles.maxHeight,n.setSize(t.size),n.getView().setCenter(t.view.center),n.getView().setZoom(t.view.zoom),n.getView().setRotation(t.view.rotation)}function fh(n,t,e,i){const s=Wg[t];if(!s)throw new Error(`Invalid PDF format: ${t}`);const[r,o]=e==="landscape"?[s[0],s[1]]:[s[1],s[0]],a=i/25.4,l=Math.round(r*a),h=Math.round(o*a),c=n.getTarget();if(!c)throw new Error("Unable to get editor container");return c.style.width=`${l}px`,c.style.height=`${h}px`,c.style.maxWidth="none",c.style.maxHeight="none",n.setSize([l,h]),{width:r,height:o,canvasWidth:l,canvasHeight:h}}async function jg(n,t){const e=(t==null?void 0:t.format)||"a4",i=(t==null?void 0:t.orientation)||"landscape",s=(t==null?void 0:t.resolution)||350,r=(t==null?void 0:t.filename)||"map.pdf",o=(t==null?void 0:t.fitContent)!==!1,a=new $t.jsPDF(i,"mm",e),l=uh(n);try{const{width:h,height:c,canvasWidth:u,canvasHeight:d}=fh(n,e,i,s);o&&(n.fitToContent(),await new Promise(g=>setTimeout(g,500)));const f=await ch(n,u,d);f&&a.addImage(f,"JPEG",0,0,h,c,void 0,"FAST"),a.save(r)}finally{dh(n,l)}}async function Vg(n,t){var h,c,u;const e=t.format||"a4",i=t.orientation||"landscape",s=t.resolution||350,r=t.filename||"periodic-export.pdf",o=t.periods;if(!o||o.length===0)throw new Error("No periods provided for periodic export");const a=new $t.jsPDF(i,"mm",e),l=uh(n);try{const{width:d,height:f,canvasWidth:g,canvasHeight:m}=fh(n,e,i,s);n.fitToContent(),await new Promise(_=>setTimeout(_,500));for(let _=0;_<o.length&&!((h=t.onCancel)!=null&&h.call(t));_++){const y=o[_];await t.updateTasksForPeriod(y);const p=await ch(n,g,m);(c=t.onProgress)==null||c.call(t,_+1,o.length,y.label,p),_>0&&a.addPage(),p&&(a.addImage(p,"JPEG",0,0,d,f,void 0,"FAST"),a.setFontSize(10),a.setTextColor(0,0,0),a.text(`Période: ${y.label}`,10,f-10))}(u=t.onCancel)!=null&&u.call(t)||a.save(r)}finally{dh(n,l)}}let To;const Sn=[];function gh(n,t,e,i,s){n.beginPath(),n.moveTo(0,0),n.lineTo(t,e),n.lineTo(i,s),n.closePath(),n.save(),n.clip(),n.fillRect(0,0,Math.max(t,i)+1,Math.max(e,s)),n.restore()}function Po(n,t){return Math.abs(n[t*4]-210)>2||Math.abs(n[t*4+3]-191.25)>2}function Xg(){if(To===void 0){const n=dt(6,6,Sn);n.globalCompositeOperation="lighter",n.fillStyle="rgba(210, 0, 0, 0.75)",gh(n,4,5,4,0),gh(n,4,5,0,5);const t=n.getImageData(0,0,3,3).data;To=Po(t,0)||Po(t,4)||Po(t,8),Zs(n),Sn.push(n.canvas)}return To}function Bg(n,t,e,i){const s=fa(e,t,n);let r=ua(t,i,e);const o=t.getMetersPerUnit();o!==void 0&&(r*=o);const a=n.getMetersPerUnit();a!==void 0&&(r/=a);const l=n.getExtent();if(!l||ki(l,s)){const h=ua(n,r,s)/r;isFinite(h)&&h>0&&(r/=h)}return r}function Yg(n,t,e,i,s,r,o,a,l,h,c,u,d,f){const g=dt(Math.round(e*n),Math.round(e*t),Sn);if(u||(g.imageSmoothingEnabled=!1),l.length===0)return g.canvas;g.scale(e,e);function m(C){return Math.round(C*e)/e}g.globalCompositeOperation="lighter";const _=Ot();l.forEach(function(C,S,T){zo(_,C.extent)});let y;const p=e/i,E=(u?1:1+Math.pow(2,-24))/p;(l.length!==1||h!==0)&&(y=dt(Math.round(K(_)*p),Math.round(ut(_)*p),Sn),u||(y.imageSmoothingEnabled=!1),l.forEach(function(C,S,T){if(C.image.width>0&&C.image.height>0){if(C.clipExtent){y.save();const N=(C.clipExtent[0]-_[0])*p,j=-(C.clipExtent[3]-_[3])*p,F=K(C.clipExtent)*p,q=ut(C.clipExtent)*p;y.rect(u?N:Math.round(N),u?j:Math.round(j),u?F:Math.round(N+F)-Math.round(N),u?q:Math.round(j+q)-Math.round(j)),y.clip()}const I=(C.extent[0]-_[0])*p,v=-(C.extent[3]-_[3])*p,M=K(C.extent)*p,k=ut(C.extent)*p;y.drawImage(C.image,h,h,C.image.width-2*h,C.image.height-2*h,u?I:Math.round(I),u?v:Math.round(v),u?M:Math.round(I+M)-Math.round(I),u?k:Math.round(v+k)-Math.round(v)),C.clipExtent&&y.restore()}}));const x=An(o);return a.getTriangles().forEach(function(C,S,T){const I=C.source,v=C.target;let M=I[0][0],k=I[0][1],N=I[1][0],j=I[1][1],F=I[2][0],q=I[2][1];const b=m((v[0][0]-x[0])/r),W=m(-(v[0][1]-x[1])/r),V=m((v[1][0]-x[0])/r),Q=m(-(v[1][1]-x[1])/r),J=m((v[2][0]-x[0])/r),tt=m(-(v[2][1]-x[1])/r),R=M,Ce=k;M=0,k=0,N-=R,j-=Ce,F-=R,q-=Ce;const ii=[[N,j,0,0,V-b],[F,q,0,0,J-b],[0,0,N,j,Q-W],[0,0,F,q,tt-W]],wt=Nh(ii);if(!wt)return;if(g.save(),g.beginPath(),Xg()||!u){g.moveTo(V,Q);const qt=4,Ne=b-V,In=W-Q;for(let se=0;se<qt;se++)g.lineTo(V+m((se+1)*Ne/qt),Q+m(se*In/(qt-1))),se!=qt-1&&g.lineTo(V+m((se+1)*Ne/qt),Q+m((se+1)*In/(qt-1)));g.lineTo(J,tt)}else g.moveTo(V,Q),g.lineTo(b,W),g.lineTo(J,tt);g.clip(),g.transform(wt[0],wt[2],wt[1],wt[3],b,W),g.translate(_[0]-R,_[3]-Ce);let ne;if(y)ne=y.canvas,g.scale(E,-E);else{const qt=l[0],Ne=qt.extent;ne=qt.image,g.scale(K(Ne)/ne.width,-ut(Ne)/ne.height)}g.drawImage(ne,0,0),g.restore()}),y&&(Zs(y),Sn.push(y.canvas)),g.canvas}function Mo(n){return Array.isArray(n)?Math.min(...n):n}const Zg=10,_h=.25;class Kg{constructor(t,e,i,s,r,o,a){this.sourceProj_=t,this.targetProj_=e;let l={};const h=a?wc(E=>_t(a,fa(E,this.targetProj_,this.sourceProj_))):Xi(this.targetProj_,this.sourceProj_);this.transformInv_=function(E){const x=E[0]+"/"+E[1];return l[x]||(l[x]=h(E)),l[x]},this.maxSourceExtent_=s,this.errorThresholdSquared_=r*r,this.triangles_=[],this.wrapsXInSource_=!1,this.canWrapXInSource_=this.sourceProj_.canWrapX()&&!!s&&!!this.sourceProj_.getExtent()&&K(s)>=K(this.sourceProj_.getExtent()),this.sourceWorldWidth_=this.sourceProj_.getExtent()?K(this.sourceProj_.getExtent()):null,this.targetWorldWidth_=this.targetProj_.getExtent()?K(this.targetProj_.getExtent()):null;const c=An(i),u=zs(i),d=Ns(i),f=ks(i),g=this.transformInv_(c),m=this.transformInv_(u),_=this.transformInv_(d),y=this.transformInv_(f),p=Zg+(o?Math.max(0,Math.ceil(Math.log2(Ah(i)/(o*o*256*256)))):0);if(this.addQuad_(c,u,d,f,g,m,_,y,p),this.wrapsXInSource_){let E=1/0;this.triangles_.forEach(function(x,C,S){E=Math.min(E,x.source[0][0],x.source[1][0],x.source[2][0])}),this.triangles_.forEach(x=>{if(Math.max(x.source[0][0],x.source[1][0],x.source[2][0])-E>this.sourceWorldWidth_/2){const C=[[x.source[0][0],x.source[0][1]],[x.source[1][0],x.source[1][1]],[x.source[2][0],x.source[2][1]]];C[0][0]-E>this.sourceWorldWidth_/2&&(C[0][0]-=this.sourceWorldWidth_),C[1][0]-E>this.sourceWorldWidth_/2&&(C[1][0]-=this.sourceWorldWidth_),C[2][0]-E>this.sourceWorldWidth_/2&&(C[2][0]-=this.sourceWorldWidth_);const S=Math.min(C[0][0],C[1][0],C[2][0]);Math.max(C[0][0],C[1][0],C[2][0])-S<this.sourceWorldWidth_/2&&(x.source=C)}})}l={}}addTriangle_(t,e,i,s,r,o){this.triangles_.push({source:[s,r,o],target:[t,e,i]})}addQuad_(t,e,i,s,r,o,a,l,h){const c=ct([r,o,a,l]),u=this.sourceWorldWidth_?K(c)/this.sourceWorldWidth_:null,d=this.sourceWorldWidth_,f=this.sourceProj_.canWrapX()&&u>.5&&u<1;let g=!1;if(h>0){if(this.targetProj_.isGlobal()&&this.targetWorldWidth_){const _=ct([t,e,i,s]);g=K(_)/this.targetWorldWidth_>_h||g}!f&&this.sourceProj_.isGlobal()&&u&&(g=u>_h||g)}if(!g&&this.maxSourceExtent_&&isFinite(c[0])&&isFinite(c[1])&&isFinite(c[2])&&isFinite(c[3])&&!gt(c,this.maxSourceExtent_))return;let m=0;if(!g&&(!isFinite(r[0])||!isFinite(r[1])||!isFinite(o[0])||!isFinite(o[1])||!isFinite(a[0])||!isFinite(a[1])||!isFinite(l[0])||!isFinite(l[1]))){if(h>0)g=!0;else if(m=(!isFinite(r[0])||!isFinite(r[1])?8:0)+(!isFinite(o[0])||!isFinite(o[1])?4:0)+(!isFinite(a[0])||!isFinite(a[1])?2:0)+(!isFinite(l[0])||!isFinite(l[1])?1:0),m!=1&&m!=2&&m!=4&&m!=8)return}if(h>0){if(!g){const _=[(t[0]+i[0])/2,(t[1]+i[1])/2],y=this.transformInv_(_);let p;f?p=(ri(r[0],d)+ri(a[0],d))/2-ri(y[0],d):p=(r[0]+a[0])/2-y[0];const E=(r[1]+a[1])/2-y[1];g=p*p+E*E>this.errorThresholdSquared_}if(g){if(Math.abs(t[0]-i[0])<=Math.abs(t[1]-i[1])){const _=[(e[0]+i[0])/2,(e[1]+i[1])/2],y=this.transformInv_(_),p=[(s[0]+t[0])/2,(s[1]+t[1])/2],E=this.transformInv_(p);this.addQuad_(t,e,_,p,r,o,y,E,h-1),this.addQuad_(p,_,i,s,E,y,a,l,h-1)}else{const _=[(t[0]+e[0])/2,(t[1]+e[1])/2],y=this.transformInv_(_),p=[(i[0]+s[0])/2,(i[1]+s[1])/2],E=this.transformInv_(p);this.addQuad_(t,_,p,s,r,y,E,l,h-1),this.addQuad_(_,e,i,p,y,o,a,E,h-1)}return}}if(f){if(!this.canWrapXInSource_)return;this.wrapsXInSource_=!0}(m&11)==0&&this.addTriangle_(t,i,s,r,a,l),(m&14)==0&&this.addTriangle_(t,i,e,r,a,o),m&&((m&13)==0&&this.addTriangle_(e,s,t,o,l,r),(m&7)==0&&this.addTriangle_(e,s,i,o,l,a))}calculateSourceExtent(){const t=Ot();return this.triangles_.forEach(function(e,i,s){const r=e.source;Wi(t,r[0]),Wi(t,r[1]),Wi(t,r[2])}),t}getTriangles(){return this.triangles_}}const Ug=.5;class Hg extends gr{constructor(t,e,i,s,r,o,a){let l=t.getExtent();l&&t.canWrapX()&&(l=l.slice(),l[0]=-1/0,l[2]=1/0);let h=e.getExtent();h&&e.canWrapX()&&(h=h.slice(),h[0]=-1/0,h[2]=1/0);const c=h?Gs(i,h):i,u=Vt(c),d=Bg(t,e,u,s),f=Ug,g=new Kg(t,e,c,l,d*f,s),m=g.calculateSourceExtent(),_=si(m)?null:o(m,d,r),y=_?P.IDLE:P.EMPTY,p=_?_.getPixelRatio():1;super(i,s,p,y),this.targetProj_=e,this.maxSourceExtent_=l,this.triangulation_=g,this.targetResolution_=s,this.targetExtent_=i,this.sourceImage_=_,this.sourcePixelRatio_=p,this.interpolate_=a,this.canvas_=null,this.sourceListenerKey_=null}disposeInternal(){this.state==P.LOADING&&this.unlistenSource_(),super.disposeInternal()}getImage(){return this.canvas_}getProjection(){return this.targetProj_}reproject_(){const t=this.sourceImage_.getState();if(t==P.LOADED){const e=K(this.targetExtent_)/this.targetResolution_,i=ut(this.targetExtent_)/this.targetResolution_;this.canvas_=Yg(e,i,this.sourcePixelRatio_,Mo(this.sourceImage_.getResolution()),this.maxSourceExtent_,this.targetResolution_,this.targetExtent_,this.triangulation_,[{extent:this.sourceImage_.getExtent(),image:this.sourceImage_.getImage()}],0,void 0,this.interpolate_)}this.state=t,this.changed()}load(){if(this.state==P.IDLE){this.state=P.LOADING,this.changed();const t=this.sourceImage_.getState();t==P.LOADED||t==P.ERROR?this.reproject_():(this.sourceListenerKey_=z(this.sourceImage_,D.CHANGE,e=>{const i=this.sourceImage_.getState();(i==P.LOADED||i==P.ERROR)&&(this.unlistenSource_(),this.reproject_())}),this.sourceImage_.load())}}unlistenSource_(){$(this.sourceListenerKey_),this.sourceListenerKey_=null}}const Ps=4,Lo={IMAGELOADSTART:"imageloadstart",IMAGELOADEND:"imageloadend",IMAGELOADERROR:"imageloaderror"};class qg extends Pt{constructor(t,e){super(t),this.image=e}}class $g extends Gl{constructor(t){super({attributions:t.attributions,projection:t.projection,state:t.state,interpolate:t.interpolate!==void 0?t.interpolate:!0}),this.on,this.once,this.un,this.loader=t.loader||null,this.resolutions_=t.resolutions!==void 0?t.resolutions:null,this.reprojectedImage_=null,this.reprojectedRevision_=0,this.image=null,this.wantedExtent_,this.wantedResolution_,this.static_=t.loader?t.loader.length===0:!1,this.wantedProjection_=null}getResolutions(){return this.resolutions_}setResolutions(t){this.resolutions_=t}findNearestResolution(t){const e=this.getResolutions();if(e){const i=Fs(e,t,0);t=e[i]}return t}getImage(t,e,i,s){const r=this.getProjection();if(!r||!s||er(r,s))return r&&(s=r),this.getImageInternal(t,e,i,s);if(this.reprojectedImage_){if(this.reprojectedRevision_==this.getRevision()&&er(this.reprojectedImage_.getProjection(),s)&&this.reprojectedImage_.getResolution()==e&&zi(this.reprojectedImage_.getExtent(),t))return this.reprojectedImage_;this.reprojectedImage_.dispose(),this.reprojectedImage_=null}return this.reprojectedImage_=new Hg(r,s,t,e,i,(o,a,l)=>this.getImageInternal(o,a,l,r),this.getInterpolate()),this.reprojectedRevision_=this.getRevision(),this.reprojectedImage_}getImageInternal(t,e,i,s){if(this.loader){const r=Qg(t,e,i,1),o=this.findNearestResolution(e);if(this.image&&(this.static_||this.wantedProjection_===s&&(this.wantedExtent_&&ae(this.wantedExtent_,r)||ae(this.image.getExtent(),r))&&(this.wantedResolution_&&Mo(this.wantedResolution_)===o||Mo(this.image.getResolution())===o)))return this.image;this.wantedProjection_=s,this.wantedExtent_=r,this.wantedResolution_=o,this.image=new gr(r,o,i,this.loader),this.image.addEventListener(D.CHANGE,this.handleImageChange.bind(this))}return this.image}handleImageChange(t){const e=t.target;let i;switch(e.getState()){case P.LOADING:this.loading=!0,i=Lo.IMAGELOADSTART;break;case P.LOADED:this.loading=!1,i=Lo.IMAGELOADEND;break;case P.ERROR:this.loading=!1,i=Lo.IMAGELOADERROR;break;default:return}this.hasListener(i)&&this.dispatchEvent(new qg(i,e))}}function Jg(n,t){n.getImage().src=t}function Qg(n,t,e,i){const s=t/e,r=Vt(n),o=bn(K(n)/s,Ps),a=bn(ut(n)/s,Ps),l=bn((i-1)*o/2,Ps),h=o+2*l,c=bn((i-1)*a/2,Ps),u=a+2*c;return Ln(r,s,0,[h,u])}function t_(n){const t=n.load||Ea,e=n.imageExtent,i=n.crossOrigin??null;return()=>{const s=new Image;return s.crossOrigin=i,t(s,n.url).then(r=>{const o=K(e)/r.width,a=ut(e)/r.height;return{image:r,extent:e,resolution:o!==a?[o,a]:a,pixelRatio:1}})}}class e_ extends $g{constructor(t){const e=t.crossOrigin!==void 0?t.crossOrigin:null,i=t.imageLoadFunction!==void 0?t.imageLoadFunction:Jg;super({attributions:t.attributions,interpolate:t.interpolate,projection:ot(t.projection)}),this.url_=t.url,this.imageExtent_=t.imageExtent,this.image=null,this.image=new gr(this.imageExtent_,void 0,1,t_({url:t.url,imageExtent:t.imageExtent,crossOrigin:e,load:(s,r)=>(this.image.setImage(s),i(this.image,r),Ea(s))})),this.image.addEventListener(D.CHANGE,this.handleImageChange.bind(this))}getImageExtent(){return this.imageExtent_}getImageInternal(t,e,i,s){return gt(t,this.image.getExtent())?this.image:null}getUrl(){return this.url_}}class i_ extends Qa{constructor(t){super(t),this.image=null}getImage(){return this.image?this.image.getImage():null}prepareFrame(t){const e=t.layerStatesArray[t.layerIndex],i=t.pixelRatio,s=t.viewState,r=s.resolution,o=this.getLayer().getSource(),a=t.viewHints;let l=t.extent;if(e.extent!==void 0&&(l=Gs(l,Te(e.extent,s.projection))),!a[et.ANIMATING]&&!a[et.INTERACTING]&&!si(l))if(o){const h=s.projection,c=o.getImage(l,r,i,h);c&&(this.loadImage(c)?this.image=c:c.getState()===P.EMPTY&&(this.image=null))}else this.image=null;return!!this.image}getData(t){const e=this.frameState;if(!e)return null;const i=this.getLayer(),s=_t(e.pixelToCoordinateTransform,t.slice()),r=i.getExtent();if(r&&!ki(r,s))return null;const o=this.image.getExtent(),a=this.image.getImage(),l=K(o),h=Math.floor(a.width*((s[0]-o[0])/l));if(h<0||h>=a.width)return null;const c=ut(o),u=Math.floor(a.height*((o[3]-s[1])/c));return u<0||u>=a.height?null:this.getImageData(a,h,u)}renderFrame(t,e){const i=this.image,s=i.getExtent(),r=i.getResolution(),[o,a]=Array.isArray(r)?r:[r,r],l=i.getPixelRatio(),h=t.layerStatesArray[t.layerIndex],c=t.pixelRatio,u=t.viewState,d=u.center,f=u.resolution,g=c*o/(f*l),m=c*a/(f*l);this.prepareContainer(t,e);const _=this.context.canvas.width,y=this.context.canvas.height,p=this.getRenderContext(t);let E=!1,x=!0;if(h.extent){const v=Te(h.extent,u.projection);x=gt(v,t.extent),E=x&&!ae(v,t.extent),E&&this.clipUnrotated(p,t,v)}const C=i.getImage(),S=de(this.tempTransform,_/2,y/2,g,m,0,l*(s[0]-d[0])/o,l*(d[1]-s[3])/a);this.renderedResolution=a*c/l;const T=C.width*S[0],I=C.height*S[3];if(this.getLayer().getSource().getInterpolate()||(p.imageSmoothingEnabled=!1),this.preRender(p,t),x&&T>=.5&&I>=.5){const v=S[4],M=S[5],k=h.opacity;k!==1&&(p.save(),p.globalAlpha=k),p.drawImage(C,0,0,+C.width,+C.height,v,M,T,I),k!==1&&p.restore()}return this.postRender(this.context,t),E&&p.restore(),p.imageSmoothingEnabled=!0,this.container}}class n_ extends ds{constructor(t){t=t||{},super(t)}}class s_ extends n_{constructor(t){super(t)}createRenderer(){return new i_(this)}getData(t){return super.getData(t)}}function r_(n,t){return typeof n=="function"?n(t):n}const o_={name:"ppe-popup",getInitialState:n=>({...n}),createPlanEditor:n=>{const{overlay:t,closerElement:e,popupElement:i}=l_();n.addOverlay(t),e.addEventListener("click",()=>(t.setPosition(void 0),e.blur(),!1)),n._showPopup=(s,r)=>{t.setPosition(s.event.coordinate),i.innerHTML=s.content,r!=null&&r.offset&&t.setOffset(r.offset),t.setPositioning(a_(n,s.event,r==null?void 0:r.positioning))},n._hidePopup=()=>{t.setPosition(void 0)}}};function a_(n,t,e){if(e&&e!="auto")return e;const i=n.getSize();if(!i)return"top-right";const[s,r]=n.getPixelFromCoordinate(t.coordinate),[o,a]=i,l=s<o/2?"left":"right";return`${r<a/2?"top":"bottom"}-${l}`}function l_(){const n=document.createElement("div");n.id="ppe-popup",n.className="ppe-popup";const t=document.createElement("button");t.className="ppe-popup-closer";const e=document.createElement("div");return e.className="ppe-popup-content",n.insertAdjacentElement("beforeend",t),n.insertAdjacentElement("beforeend",e),{overlay:new tg({element:n,stopEvent:!1}),popupElement:n,closerElement:t}}const mh=[nh,{name:"ppe-layer",getInitialState:n=>({...n}),createPlanEditor:n=>{n.addVectorLayer=()=>{const t=new pn({wrapX:!1}),e=new Ii({source:t});return n.initialState._extent&&e.setExtent(n.initialState._extent),e}}},o_,hh];function h_(n){var m;const t=[...mh,...n._plugins??[]],{plan:e}=n,i=[0,0,e.file.width,e.file.height],s=new kn({code:"",units:"pixels",extent:i}),r=new e_({imageExtent:i,projection:s,url:e.file.original_url,crossOrigin:"anonymous"}),o=new s_({source:r}),a=new ee({projection:s,center:Vt(i),zoom:2,minZoom:0,maxZoom:10}),l=new Jf({target:n.target??"map",layers:[o],view:a}),h={_extent:i,_projection:s},c=l;c._plugins=t;const u=c._plugins.reduce((_,y)=>{var p;return Object.assign(_,(p=y.getDefaultOptions)==null?void 0:p.call(y,c))},{});let d={...h,...n.initialState??{}};c._plugins.forEach(_=>{var y;d=((y=_.getInitialState)==null?void 0:y.call(_,d))??d});const f=_=>c.options.mergeOptions?c.options.mergeOptions(u,_):{...u,..._},g={_plugins:t,options:{...u,...n},initialState:d,reset:()=>{c.setState(c.initialState)},getState:()=>c.options.state,setState:_=>{var y,p;(p=(y=c.options).onStateChange)==null||p.call(y,_)},setOptions:_=>{const y=r_(_,c.options),p=c.getTarget(),E=f(y);c.options=E,E.target&&E.target!==p&&c.setTarget(E.target)},fitToContent:()=>{const _=c.getView(),y=c.getSize();y&&i&&_.fit(i,{size:y,padding:[0,0,0,0],duration:500})}};Object.assign(c,g);for(const _ of c._plugins)(m=_==null?void 0:_.createPlanEditor)==null||m.call(_,c);return c}return Tt.PdfExportPlugin=hh,Tt.ZoningPlugin=nh,Tt.convertToZoneGeometry=Rs,Tt.convertZoneToGeometryFeatures=ih,Tt.createPlanEditor=h_,Tt.defaultPlugins=mh,Object.defineProperty(Tt,Symbol.toStringTag,{value:"Module"}),Tt})({},jspdf);
package/dist/index.js CHANGED
@@ -24005,7 +24005,12 @@ function Eh(n, t) {
24005
24005
  e.style.width = t.containerStyles.width, e.style.height = t.containerStyles.height, e.style.maxWidth = t.containerStyles.maxWidth, e.style.maxHeight = t.containerStyles.maxHeight, n.setSize(t.size), n.getView().setCenter(t.view.center), n.getView().setZoom(t.view.zoom), n.getView().setRotation(t.view.rotation);
24006
24006
  }
24007
24007
  function Ch(n, t, e, i) {
24008
- const s = $g[t], [r, o] = e === "landscape" ? [s[0], s[1]] : [s[1], s[0]], a = i / 25.4, l = Math.round(r * a), h = Math.round(o * a), c = n.getTarget();
24008
+ const s = $g[t];
24009
+ if (!s)
24010
+ throw new Error(`Invalid PDF format: ${t}`);
24011
+ const [r, o] = e === "landscape" ? [s[0], s[1]] : [s[1], s[0]], a = i / 25.4, l = Math.round(r * a), h = Math.round(o * a), c = n.getTarget();
24012
+ if (!c)
24013
+ throw new Error("Unable to get editor container");
24009
24014
  return c.style.width = `${l}px`, c.style.height = `${h}px`, c.style.maxWidth = "none", c.style.maxHeight = "none", n.setSize([l, h]), { width: r, height: o, canvasWidth: l, canvasHeight: h };
24010
24015
  }
24011
24016
  async function Qg(n, t) {