open-plant 1.4.20 → 1.4.21
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.
package/dist/index.cjs
CHANGED
|
@@ -243,6 +243,6 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
243
243
|
vec3 fillRgb = (uPointInnerFillColor / 255.0) * fillAlpha * pointOpacity;
|
|
244
244
|
outColor = vec4(color.rgb * ringAlpha * pointOpacity + fillRgb, alpha);
|
|
245
245
|
}
|
|
246
|
-
}`),i=Ie(t,r,"uCamera"),o=Ie(t,r,"uPointSize"),s=Ie(t,r,"uPointCssSize"),a=Ie(t,r,"uPointOpacity"),l=Ie(t,r,"uPointStrokeScale"),c=Ie(t,r,"uPointInnerFillAlpha"),f=Ie(t,r,"uPointInnerFillColor"),u=Ie(t,r,"uPalette"),h=Ie(t,r,"uPaletteSize"),d=Ie(t,r,"uPointLineDash"),m=t.createVertexArray(),p=t.createBuffer(),b=t.createBuffer(),y=t.createBuffer(),x=t.createBuffer(),M=t.createTexture();if(!m||!p||!b||!y||!x||!M)throw new Error("point buffer allocation failed");t.bindVertexArray(m),t.bindBuffer(t.ARRAY_BUFFER,p),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const S=t.getAttribLocation(r,"aPosition");if(S<0)throw new Error("point position attribute not found");t.enableVertexAttribArray(S),t.vertexAttribPointer(S,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const C=t.getAttribLocation(r,"aClass");if(C<0)throw new Error("point class attribute not found");t.enableVertexAttribArray(C),t.vertexAttribIPointer(C,1,t.UNSIGNED_SHORT,0,0),t.bindBuffer(t.ARRAY_BUFFER,y),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const A=t.getAttribLocation(r,"aFillMode");if(A<0)throw new Error("point fill mode attribute not found");return t.enableVertexAttribArray(A),t.vertexAttribIPointer(A,1,t.UNSIGNED_BYTE,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,x),t.bufferData(t.ELEMENT_ARRAY_BUFFER,0,t.DYNAMIC_DRAW),t.bindVertexArray(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindTexture(t.TEXTURE_2D,M),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array([160,160,160,255])),t.bindTexture(t.TEXTURE_2D,null),{program:r,vao:m,posBuffer:p,classBuffer:b,fillModeBuffer:y,indexBuffer:x,paletteTexture:M,uCamera:i,uPointSize:o,uPointCssSize:s,uPointOpacity:a,uPointLineDash:d,uPointStrokeScale:l,uPointInnerFillAlpha:c,uPointInnerFillColor:f,uPalette:u,uPaletteSize:h}}function oo(t){t.animation=null,t.frame!==null&&(cancelAnimationFrame(t.frame),t.frame=null)}function Oc(t){const{state:e,camera:n,target:r,durationMs:i,easing:o,onUpdate:s}=t,a=n.getViewState();oo(e),e.animation={startMs:Ee(),durationMs:Math.max(0,i),from:a,to:r,easing:o};const l=()=>{const c=e.animation;if(!c)return;const f=Math.max(0,Ee()-c.startMs),u=c.durationMs<=0?1:F(f/c.durationMs,0,1);let h=u;try{h=c.easing(u)}catch{h=u}if(Number.isFinite(h)||(h=u),h=F(h,0,1),n.setViewState({zoom:c.from.zoom+(c.to.zoom-c.from.zoom)*h,offsetX:c.from.offsetX+(c.to.offsetX-c.from.offsetX)*h,offsetY:c.from.offsetY+(c.to.offsetY-c.from.offsetY)*h,rotationDeg:c.from.rotationDeg+(c.to.rotationDeg-c.from.rotationDeg)*h}),s(),u>=1){e.animation=null,e.frame=null;return}e.frame=requestAnimationFrame(l)};e.frame=requestAnimationFrame(l)}function Wc(t){const e=Math.max(t*.5,1e-6),n=Math.max(1,t*8);return{minZoom:e,maxZoom:Math.max(e,n)}}function Yc(t,e,n){const r=Wc(t);let i=e??r.minZoom,o=n??r.maxZoom;return i=Math.max(1e-6,i),o=Math.max(1e-6,o),i>o&&(i=o),{minZoom:i,maxZoom:o}}function Xc(t,e,n,r,i){const o=t.getViewState(),s={zoom:typeof r.zoom=="number"&&Number.isFinite(r.zoom)?F(r.zoom,e,n):o.zoom,offsetX:typeof r.offsetX=="number"&&Number.isFinite(r.offsetX)?r.offsetX:o.offsetX,offsetY:typeof r.offsetY=="number"&&Number.isFinite(r.offsetY)?r.offsetY:o.offsetY,rotationDeg:typeof r.rotationDeg=="number"&&Number.isFinite(r.rotationDeg)?r.rotationDeg:o.rotationDeg};t.setViewState(s),i();const a=t.getViewState();return t.setViewState(o),a}function si(t,e,n,r,i,o=0){const s=Math.min(e/t.width,n/t.height),a=Number.isFinite(s)&&s>0?s:1,l=F(a,r,i),c=e/l,f=n/l;return{fitZoom:a,target:{zoom:l,offsetX:(t.width-c)*.5,offsetY:(t.height-f)*.5,rotationDeg:o}}}function Vc(t,e,n,r,i,o){const s=t.getViewState(),a=F(s.zoom*r,e,n);if(a===s.zoom)return null;const[l,c]=t.screenToWorld(i,o),f=t.getViewportSize(),u=i-f.width*.5,h=o-f.height*.5,d=on(s.rotationDeg),m=Math.cos(d),p=Math.sin(d),b=u/a*m-h/a*p,y=u/a*p+h/a*m,x=l-b,M=c-y;return{zoom:a,offsetX:x-f.width/(2*a),offsetY:M-f.height/(2*a)}}function Gc(t,e,n,r,i,o){const s=t.getViewState(),a=F(r,e,n);if(a===s.zoom)return null;const[l,c]=t.screenToWorld(i,o),f=t.getViewportSize(),u=i-f.width*.5,h=o-f.height*.5,d=on(s.rotationDeg),m=Math.cos(d),p=Math.sin(d),b=u/a*m-h/a*p,y=u/a*p+h/a*m,x=l-b,M=c-y;return{zoom:a,offsetX:x-f.width/(2*a),offsetY:M-f.height/(2*a)}}const Zc=250;function ai(t,e){if(!t||t.length===0)return[];if(!e||e<=0)return[];const n=10/e;return t.map(r=>r/n).filter(r=>Number.isFinite(r)&&r>0).sort((r,i)=>r-i)}function qc(t,e,n,r){if(t.length===0)return null;const i=Math.max(e*.005,1e-8);if(n==="in"){for(const o of t)if(o>e+i)return{type:"snap",zoom:o};return null}for(let o=t.length-1;o>=0;o--)if(t[o]<e-i)return{type:"snap",zoom:t[o]};return r&&e<=t[0]+i?{type:"fit"}:null}function Hc(t,e,n,r,i){const o=t.camera.getViewState(),[s,a]=t.camera.screenToWorld(n,r),l=t.camera.getViewportSize(),c=F(e,t.minZoom,t.maxZoom);if(c===o.zoom)return;const f=on(o.rotationDeg),u=Math.cos(f),h=Math.sin(f),d=n-l.width*.5,m=r-l.height*.5;t.cancelViewAnimation();const p=x=>{const M=d/x*u-m/x*h,S=d/x*h+m/x*u;return{offsetX:s-M-l.width/(2*x),offsetY:a-S-l.height/(2*x)}},b=p(c);t.viewAnimationState.animation={startMs:Ee(),durationMs:Math.max(0,i),from:o,to:{zoom:c,offsetX:b.offsetX,offsetY:b.offsetY,rotationDeg:o.rotationDeg},easing:Hn};const y=()=>{const x=t.viewAnimationState.animation;if(!x)return;const M=Math.max(0,Ee()-x.startMs),S=F(M/i,0,1),C=F(S*S*(3-2*S),0,1),A=o.zoom+(c-o.zoom)*C,{offsetX:B,offsetY:z}=p(A);t.camera.setViewState({zoom:A,offsetX:B,offsetY:z,rotationDeg:o.rotationDeg});const Y=S>=1;Y&&(t.clampViewState(),t.viewAnimationState.animation=null,t.viewAnimationState.frame=null),t.onViewStateChange(t.camera.getViewState()),t.requestRender(),Y||(t.viewAnimationState.frame=requestAnimationFrame(y))};t.viewAnimationState.frame=requestAnimationFrame(y)}const Fe="__default_point_layer__";class so{constructor(e,n,r={}){E(this,"canvas");E(this,"source");E(this,"gl");E(this,"camera",new ci);E(this,"onViewStateChange");E(this,"onStats");E(this,"onTileError");E(this,"onContextLost");E(this,"onContextRestored");E(this,"resizeObserver");E(this,"removeDprListener");E(this,"tileProgram");E(this,"tileScheduler");E(this,"authToken");E(this,"destroyed",!1);E(this,"contextLost",!1);E(this,"frame",null);E(this,"frameSerial",0);E(this,"interactionState",{dragging:!1,mode:"none",rotateLastAngleRad:null,pointerId:null,lastPointerX:0,lastPointerY:0});E(this,"interactionLocked",!1);E(this,"ctrlDragRotate",!0);E(this,"rotationDragSensitivityDegPerPixel",Fn);E(this,"maxCacheTiles");E(this,"fitZoom",1);E(this,"initialRotationDeg",0);E(this,"minZoom",1e-6);E(this,"maxZoom",1);E(this,"minZoomOverride",null);E(this,"maxZoomOverride",null);E(this,"viewTransitionDurationMs",0);E(this,"viewTransitionEasing",Hn);E(this,"viewAnimationState",{animation:null,frame:null});E(this,"pointLayers",new Map);E(this,"defaultPointSizeZoomStops",tn(Ln));E(this,"defaultPointSizeMagnificationStops",null);E(this,"defaultPointWeightMagnificationStops",null);E(this,"defaultPointOpacity",1);E(this,"defaultPointLineDash",[1,0]);E(this,"defaultPointStrokeScale",1);E(this,"defaultPointInnerFillOpacity",0);E(this,"defaultPointInnerFillColor",[...Ji]);E(this,"imageColorSettings",{brightness:0,contrast:0,saturation:0});E(this,"cache",new Map);E(this,"zoomSnaps",[]);E(this,"zoomSnapFitAsMin",!1);E(this,"zoomSnapState",{accumulatedDelta:0,lastSnapTimeMs:0,blockedDirection:null});E(this,"panExtentX",.2);E(this,"panExtentY",.2);E(this,"boundPointerDown");E(this,"boundPointerMove");E(this,"boundPointerUp");E(this,"boundWheel");E(this,"boundDoubleClick");E(this,"boundContextMenu");E(this,"boundContextLost");E(this,"boundContextRestored");this.canvas=e,this.source=n,this.onViewStateChange=r.onViewStateChange,this.onStats=r.onStats,this.onTileError=r.onTileError,this.onContextLost=r.onContextLost,this.onContextRestored=r.onContextRestored,this.authToken=r.authToken??"",this.maxCacheTiles=Math.max(32,Math.floor(r.maxCacheTiles??320)),this.initialRotationDeg=typeof r.initialRotationDeg=="number"&&Number.isFinite(r.initialRotationDeg)?r.initialRotationDeg:0,this.ctrlDragRotate=r.ctrlDragRotate??!0,this.rotationDragSensitivityDegPerPixel=typeof r.rotationDragSensitivityDegPerPixel=="number"&&Number.isFinite(r.rotationDragSensitivityDegPerPixel)?Math.max(0,r.rotationDragSensitivityDegPerPixel):Fn,this.defaultPointSizeZoomStops=$r(r.pointSizeByZoom),this.defaultPointSizeMagnificationStops=Kr(r.pointSizeByMagnification),this.defaultPointWeightMagnificationStops=jr(r.pointWeightByMagnification),this.defaultPointOpacity=Qr(r.pointOpacity),this.defaultPointStrokeScale=Gt(r.pointStrokeScale),this.defaultPointInnerFillOpacity=Jr(r.pointInnerFillOpacity),this.defaultPointInnerFillColor=ei(r.pointInnerFillColor),this.imageColorSettings=ti(r.imageColorSettings),this.minZoomOverride=Ot(r.minZoom),this.maxZoomOverride=Ot(r.maxZoom),this.viewTransitionDurationMs=mn(r.viewTransition?.duration),this.viewTransitionEasing=gn(r.viewTransition?.easing),this.zoomSnaps=ai(r.zoomSnaps,this.source.mpp),this.zoomSnapFitAsMin=!!r.zoomSnapFitAsMin,this.applyPanExtent(r.panExtent);const i=e.getContext("webgl2",{alpha:!1,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:r.preserveDrawingBuffer??!1});if(!i)throw new Error("WebGL2 not supported");this.gl=i,this.tileProgram=ii(this.gl),this.tileScheduler=new Qi({authToken:this.authToken,maxConcurrency:r.tileScheduler?.maxConcurrency??12,maxRetries:r.tileScheduler?.maxRetries??2,retryBaseDelayMs:r.tileScheduler?.retryBaseDelayMs??120,retryMaxDelayMs:r.tileScheduler?.retryMaxDelayMs??1200,onTileLoad:(s,a)=>Lc({gl:this.gl,cache:this.cache,tile:s,bitmap:a,frameSerial:this.frameSerial,maxCacheTiles:this.maxCacheTiles,destroyed:this.destroyed,contextLost:this.contextLost,requestRender:()=>this.requestRender()}),onTileError:(s,a,l)=>{this.onTileError?.({tile:s,error:a,attemptCount:l}),console.warn("tile load failed",s.url,a)}}),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),this.removeDprListener=rn(()=>this.resize());const o=Ic({canvas:this.canvas,state:this.interactionState,getInteractionLocked:()=>this.interactionLocked,getCtrlDragRotate:()=>this.ctrlDragRotate,getRotationDragSensitivityDegPerPixel:()=>this.rotationDragSensitivityDegPerPixel,cancelViewAnimation:()=>this.cancelViewAnimation(),camera:this.camera,source:this.source,emitViewState:()=>this.onViewStateChange?.(this.camera.getViewState()),requestRender:()=>this.requestRender(),getPanExtentX:()=>this.panExtentX,getPanExtentY:()=>this.panExtentY,zoomBy:(s,a,l)=>this.zoomBy(s,a,l),getUseZoomSnaps:()=>this.zoomSnaps.length>0,onSnapZoom:(s,a,l)=>this.handleSnapZoom(s,a,l),zoomSnapState:this.zoomSnapState});this.boundPointerDown=o.pointerDown,this.boundPointerMove=o.pointerMove,this.boundPointerUp=o.pointerUp,this.boundWheel=o.wheel,this.boundDoubleClick=o.doubleClick,this.boundContextMenu=o.contextMenu,this.boundContextLost=s=>this.onWebGlContextLost(s),this.boundContextRestored=s=>this.onWebGlContextRestored(s),Zl(e,this.getCanvasHandlers()),this.fitToImage({duration:0}),this.resize()}getCanvasHandlers(){return{pointerDown:this.boundPointerDown,pointerMove:this.boundPointerMove,pointerUp:this.boundPointerUp,wheel:this.boundWheel,doubleClick:this.boundDoubleClick,contextMenu:this.boundContextMenu,contextLost:this.boundContextLost,contextRestored:this.boundContextRestored}}applyZoomBounds(){const e=Yc(this.fitZoom,this.minZoomOverride,this.maxZoomOverride);this.minZoom=e.minZoom,this.maxZoom=e.maxZoom}resolveTargetViewState(e){return Xc(this.camera,this.minZoom,this.maxZoom,e,()=>Zt(this.camera,this.source,this.panExtentX,this.panExtentY))}cancelViewAnimation(){oo(this.viewAnimationState)}startViewAnimation(e,n,r){Oc({state:this.viewAnimationState,camera:this.camera,target:e,durationMs:n,easing:r,onUpdate:()=>{Zt(this.camera,this.source,this.panExtentX,this.panExtentY),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}})}createPointBufferRuntime(){return{pointCount:0,usePointIndices:!1,pointBuffersDirty:!0,lastPointData:null,zeroFillModes:new Uint8Array(0),lastPointPalette:null,pointPaletteSize:1}}createPointLayerState(e){return{id:e,program:oi(this.gl),runtime:this.createPointBufferRuntime(),pointSizeZoomStops:tn(this.defaultPointSizeZoomStops),pointSizeMagnificationStops:ic(this.defaultPointSizeMagnificationStops),pointWeightMagnificationStops:oc(this.defaultPointWeightMagnificationStops),pointOpacity:this.defaultPointOpacity,pointLineDash:[...this.defaultPointLineDash],pointStrokeScale:this.defaultPointStrokeScale,pointInnerFillOpacity:this.defaultPointInnerFillOpacity,pointInnerFillColor:[...this.defaultPointInnerFillColor]}}ensurePointLayer(e=Fe){const n=String(e||Fe),r=this.pointLayers.get(n);if(r)return r;const i=this.createPointLayerState(n);return this.pointLayers.set(n,i),i}deletePointProgram(e){this.contextLost||this.gl.isContextLost()||(this.gl.deleteBuffer(e.posBuffer),this.gl.deleteBuffer(e.classBuffer),this.gl.deleteBuffer(e.fillModeBuffer),this.gl.deleteBuffer(e.indexBuffer),this.gl.deleteTexture(e.paletteTexture),this.gl.deleteVertexArray(e.vao),this.gl.deleteProgram(e.program))}getPointRenderLayers(){const e=Math.max(1,window.devicePixelRatio||1),n=[];for(const r of this.pointLayers.values()){const i=this.getPointSize(r.id);n.push({pointProgram:r.program,pointCount:r.runtime.pointCount,usePointIndices:r.runtime.usePointIndices,pointPaletteSize:r.runtime.pointPaletteSize,pointLineDash:r.pointLineDash,pointOpacity:r.pointOpacity,pointStrokeScale:this.getPointStrokeScale(r.id),pointInnerFillOpacity:r.pointInnerFillOpacity,pointInnerFillColor:r.pointInnerFillColor,pointCssSizePx:i,pointSizePx:i*e})}return n}applyViewStateAndRender(e,n=!0){n&&this.cancelViewAnimation(),this.camera.setViewState(e),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}setAuthToken(e){this.authToken=String(e??""),this.tileScheduler.setAuthToken(this.authToken)}setZoomRange(e,n){const r=Ot(e),i=Ot(n);if(this.minZoomOverride===r&&this.maxZoomOverride===i)return;this.minZoomOverride=r,this.maxZoomOverride=i,this.applyZoomBounds();const o=this.resolveTargetViewState({}),s=this.camera.getViewState();Rn(s,o)||this.applyViewStateAndRender(o)}setViewTransition(e){this.viewTransitionDurationMs=mn(e?.duration),this.viewTransitionEasing=gn(e?.easing)}setViewState(e,n){const r=this.resolveTargetViewState(e),i=this.camera.getViewState();if(Rn(i,r))return;const o=mn(n?.duration??this.viewTransitionDurationMs),s=gn(n?.easing??this.viewTransitionEasing);if(o<=0){this.applyViewStateAndRender(r);return}this.startViewAnimation(r,o,s)}getViewState(){return this.camera.getViewState()}getZoomRange(){return{minZoom:this.minZoom,maxZoom:this.maxZoom}}getRegionLabelAutoLiftCapZoom(){const e=this.zoomSnaps.filter(n=>n>=this.minZoom&&n<=this.maxZoom);return e.length>0?e[e.length-1]:this.maxZoom}isViewAnimating(){return this.viewAnimationState.animation!==null}registerPointLayer(e){this.ensurePointLayer(e)}unregisterPointLayer(e){const n=String(e||Fe),r=this.pointLayers.get(n);r&&(this.pointLayers.delete(n),this.deletePointProgram(r.program),this.requestRender())}setPointPalette(e,n=Fe){const r=this.ensurePointLayer(n);r.runtime=ni(r.runtime,this.gl,r.program,this.contextLost,e),!(!e||e.length===0)&&this.requestRender()}setPointLineDash(e,n=Fe){const r=this.ensurePointLayer(n),i=hc(e);r.pointLineDash[0]===i[0]&&r.pointLineDash[1]===i[1]||(r.pointLineDash=i,this.requestRender())}setPointData(e,n=Fe){const r=this.ensurePointLayer(n);r.runtime=ri(r.runtime,this.gl,r.program,this.contextLost,e),this.requestRender()}setInteractionLock(e){const n=!!e;this.interactionLocked!==n&&(this.interactionLocked=n,n&&this.cancelDrag())}setPointSizeByZoom(e,n=Fe){const r=this.ensurePointLayer(n),i=$r(e);sc(r.pointSizeZoomStops,i)||(r.pointSizeZoomStops=i,this.requestRender())}setPointSizeByMagnification(e,n=Fe){const r=this.ensurePointLayer(n),i=Kr(e);ac(r.pointSizeMagnificationStops,i)||(r.pointSizeMagnificationStops=i,this.requestRender())}setPointWeightByMagnification(e,n=Fe){const r=this.ensurePointLayer(n),i=jr(e);lc(r.pointWeightMagnificationStops,i)||(r.pointWeightMagnificationStops=i,this.requestRender())}setPointOpacity(e,n=Fe){const r=this.ensurePointLayer(n),i=Qr(e);r.pointOpacity!==i&&(r.pointOpacity=i,this.requestRender())}setPointStrokeScale(e,n=Fe){const r=this.ensurePointLayer(n),i=Gt(e);r.pointStrokeScale!==i&&(r.pointStrokeScale=i,this.requestRender())}setPointInnerFillOpacity(e,n=Fe){const r=this.ensurePointLayer(n),i=Jr(e);r.pointInnerFillOpacity!==i&&(r.pointInnerFillOpacity=i,this.requestRender())}setPointInnerFillColor(e,n=Fe){const r=this.ensurePointLayer(n),i=ei(e);r.pointInnerFillColor[0]===i[0]&&r.pointInnerFillColor[1]===i[1]&&r.pointInnerFillColor[2]===i[2]||(r.pointInnerFillColor=i,this.requestRender())}setImageColorSettings(e){const n=ti(e),r=this.imageColorSettings;r.brightness===n.brightness&&r.contrast===n.contrast&&r.saturation===n.saturation||(this.imageColorSettings=n,this.requestRender())}cancelDrag(){Tc(this.canvas,this.interactionState)}screenToWorld(e,n){const r=this.canvas.getBoundingClientRect(),i=e-r.left,o=n-r.top;return this.camera.screenToWorld(i,o)}worldToScreen(e,n){return this.camera.worldToScreen(e,n)}setViewCenter(e,n,r){if(!Number.isFinite(e)||!Number.isFinite(n))return;const i=this.camera.getViewState(),o=Math.max(1e-6,i.zoom),s=this.camera.getViewportSize();this.setViewState({offsetX:e-s.width/(2*o),offsetY:n-s.height/(2*o)},r)}getViewCorners(){return this.camera.getViewCorners()}getInitialRotationDeg(){return this.initialRotationDeg}getViewBounds(){return nn(this.camera)}resetRotation(e){const n=this.camera.getViewState();Math.abs(n.rotationDeg-this.initialRotationDeg)<1e-6||this.setViewState({rotationDeg:this.initialRotationDeg},e)}getPointSize(e=Fe){const n=this.pointLayers.get(String(e||Fe)),r=n?.pointSizeMagnificationStops??this.defaultPointSizeMagnificationStops;if(r&&r.length>0){const l=Math.max(1e-6,this.camera.getViewState().zoom),c=En(this.source.mpp??0,l);if(c>0){const f=uc(c,r);return F(f,ht,Hr)}}const i=Math.max(1e-6,this.camera.getViewState().zoom),o=this.source.maxTierZoom+Math.log2(i),s=n?.pointSizeZoomStops??this.defaultPointSizeZoomStops,a=cc(o,s);return F(a,ht,Hr)}getPointSizeByZoom(e=Fe){return this.getPointSize(e)}getPointStrokeScale(e=Fe){const n=this.pointLayers.get(String(e||Fe)),r=n?.pointWeightMagnificationStops??this.defaultPointWeightMagnificationStops;if(r&&r.length>0){const i=Math.max(1e-6,this.camera.getViewState().zoom),o=En(this.source.mpp??0,i);if(o>0)return Gt(fc(o,r))}return n?.pointStrokeScale??this.defaultPointStrokeScale}fitToImage(e){const n=this.canvas.getBoundingClientRect(),r=Math.max(1,n.width||1),i=Math.max(1,n.height||1),o=si(this.source,r,i,this.minZoom,this.maxZoom,this.initialRotationDeg);this.fitZoom=o.fitZoom,this.applyZoomBounds(),this.setViewState(o.target,e)}zoomBy(e,n,r,i){const o=Vc(this.camera,this.minZoom,this.maxZoom,e,n,r);o&&this.setViewState(o,i)}handleWheelZoom(e,n,r){if(this.zoomSnaps.length>0){ro(e,n,r,this.zoomSnapState,(i,o,s)=>this.handleSnapZoom(i,o,s));return}no(e,n,r,(i,o,s)=>this.zoomBy(i,o,s))}zoomTo(e,n,r,i){const o=Gc(this.camera,this.minZoom,this.maxZoom,e,n,r);o&&this.setViewState(o,i)}setZoomSnaps(e,n){this.zoomSnaps=ai(e,this.source.mpp),this.zoomSnapFitAsMin=!!n}setPanExtent(e){this.applyPanExtent(e)}applyPanExtent(e){typeof e=="number"&&Number.isFinite(e)?(this.panExtentX=Math.max(0,e),this.panExtentY=Math.max(0,e)):e!=null&&typeof e=="object"?(this.panExtentX=typeof e.x=="number"&&Number.isFinite(e.x)?Math.max(0,e.x):.2,this.panExtentY=typeof e.y=="number"&&Number.isFinite(e.y)?Math.max(0,e.y):.2):(this.panExtentX=.2,this.panExtentY=.2)}getZoomPivotAnimationContext(){return{camera:this.camera,viewAnimationState:this.viewAnimationState,minZoom:this.minZoom,maxZoom:this.maxZoom,cancelViewAnimation:()=>this.cancelViewAnimation(),clampViewState:()=>Zt(this.camera,this.source,this.panExtentX,this.panExtentY),onViewStateChange:e=>this.onViewStateChange?.(e),requestRender:()=>this.requestRender()}}handleSnapZoom(e,n,r){const i=this.viewAnimationState.animation,o=i?i.to.zoom:this.camera.getViewState().zoom,s=this.zoomSnaps.filter(f=>f>=this.minZoom&&f<=this.maxZoom),a=qc(s,o,e,this.zoomSnapFitAsMin);if(!a)return!1;let l;if(a.type==="fit"){const f=this.canvas.getBoundingClientRect(),u=Math.max(1,f.width||1),h=Math.max(1,f.height||1),d=si(this.source,u,h,this.minZoom,this.maxZoom,this.initialRotationDeg);this.fitZoom=d.fitZoom,this.applyZoomBounds(),l=d.target.zoom}else l=a.zoom;const c=Math.max(Math.abs(l)*.005,1e-8);if(i){if((i.to.zoom>i.from.zoom+c?"in":i.to.zoom<i.from.zoom-c?"out":null)===e&&Math.abs(i.to.zoom-l)<=c)return!1}else if(Math.abs(o-l)<=c)return!1;return Hc(this.getZoomPivotAnimationContext(),l,n,r,Zc),!0}render(){if(this.destroyed||this.contextLost||this.gl.isContextLost())return;const e=this.onStats?Ee():0;this.frameSerial+=1;const n=Uc({gl:this.gl,camera:this.camera,source:this.source,cache:this.cache,frameSerial:this.frameSerial,tileProgram:this.tileProgram,imageColorSettings:this.imageColorSettings,pointLayers:this.getPointRenderLayers(),tileScheduler:this.tileScheduler,getVisibleTiles:()=>Rc(this.camera,this.source),getVisibleTilesForTier:r=>io(this.camera,this.source,r),getViewBounds:()=>nn(this.camera),intersectsBounds:Ec});if(this.onStats){const r=this.tileScheduler.getSnapshot();this.onStats({tier:n.tier,visible:n.visible,rendered:n.rendered,points:n.points,fallback:n.fallback,cache:this.cache.size,inflight:r.inflight,queued:r.queued,retries:r.retries,failed:r.failed,aborted:r.aborted,cacheHits:n.cacheHits,cacheMisses:n.cacheMisses,drawCalls:n.drawCalls,frameMs:Ee()-e})}}requestRender(){this.frame!==null||this.destroyed||this.contextLost||this.gl.isContextLost()||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}resize(){Hl(this.canvas,this.gl,this.camera),this.requestRender()}onWebGlContextLost(e){const n=Nc({event:e,destroyed:this.destroyed,contextLost:this.contextLost,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,cache:this.cache,onContextLost:this.onContextLost});if(n.handled){this.frame=n.frame,this.contextLost=!0;for(const r of this.pointLayers.values())r.runtime={...r.runtime,pointBuffersDirty:!0}}}onWebGlContextRestored(e){if(!this.destroyed){this.contextLost=!1,this.cache.clear(),this.tileProgram=ii(this.gl);for(const n of this.pointLayers.values())n.program=oi(this.gl),n.runtime={...n.runtime,pointBuffersDirty:!0},n.runtime.lastPointPalette&&n.runtime.lastPointPalette.length>0&&(n.runtime=ni(n.runtime,this.gl,n.program,this.contextLost,n.runtime.lastPointPalette)),n.runtime.lastPointData&&(n.runtime=ri(n.runtime,this.gl,n.program,this.contextLost,n.runtime.lastPointData));this.resize(),this.onContextRestored?.()}}destroy(){const e=zc({destroyed:this.destroyed,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),resizeObserver:this.resizeObserver,removeDprListener:this.removeDprListener,removeCanvasEventListeners:()=>ql(this.canvas,this.getCanvasHandlers()),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,contextLost:this.contextLost,gl:this.gl,cache:this.cache,tileProgram:this.tileProgram,pointPrograms:Array.from(this.pointLayers.values(),n=>n.program)});e.didDestroy&&(this.destroyed=!0,this.frame=e.frame)}}const $c=[];function Kc(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function jc({source:t,viewState:e,onViewStateChange:n,onStats:r,onTileError:i,onContextLost:o,onContextRestored:s,imageColorSettings:a=null,initialRotate:l=0,fitNonce:c=0,rotationResetNonce:f=0,authToken:u="",ctrlDragRotate:h=!0,minZoom:d,maxZoom:m,viewTransition:p,zoomSnaps:b,zoomSnapFitAsMin:y,panExtent:x,preserveDrawingBuffer:M,onPointerWorldMove:S,debugOverlay:C=!1,debugOverlayStyle:A,className:B,style:z,children:Y}){const P=g.useRef(null),I=g.useRef(null),O=g.useRef(null),v=g.useRef(null),W=g.useRef(null),j=g.useRef(null),L=g.useRef($c),ge=g.useRef(!1),le=g.useRef(new Set),Q=g.useRef(new Set),ve=g.useRef(n),Ae=g.useRef(r),D=g.useRef(i),T=g.useRef(o),k=g.useRef(s),[oe,ue]=g.useState(0),[$,ce]=g.useState(null),te=g.useRef(C);g.useEffect(()=>{ve.current=n},[n]),g.useEffect(()=>{Ae.current=r},[r]),g.useEffect(()=>{D.current=i},[i]),g.useEffect(()=>{T.current=o},[o]),g.useEffect(()=>{k.current=s},[s]),g.useEffect(()=>{te.current=C,C||ce(null)},[C]);const _e=g.useMemo(()=>({position:"relative",width:"100%",height:"100%",...z}),[z]),Se=g.useMemo(()=>({position:"absolute",top:8,left:8,zIndex:7,margin:0,padding:"8px 10px",maxWidth:"min(420px, 80%)",pointerEvents:"none",whiteSpace:"pre-wrap",lineHeight:1.35,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:11,color:"#cde6ff",background:"rgba(6, 12, 20, 0.82)",border:"1px solid rgba(173, 216, 255, 0.28)",borderRadius:8,boxShadow:"0 8px 22px rgba(0,0,0,0.35)",...A}),[A]),fe=Kc(l),xe=g.useCallback(U=>({...U,rotationDeg:U.rotationDeg-fe}),[fe]),ee=g.useCallback(U=>typeof U.rotationDeg!="number"||!Number.isFinite(U.rotationDeg)?U:{...U,rotationDeg:U.rotationDeg+fe},[fe]),se=g.useCallback(U=>{Ae.current?.(U),te.current&&ce(U)},[]),he=g.useMemo(()=>$?[`tier ${$.tier} | frame ${$.frameMs?.toFixed(2)??"-"} ms | drawCalls ${$.drawCalls??"-"}`,`tiles visible ${$.visible} | rendered ${$.rendered} | fallback ${$.fallback}`,`cache size ${$.cache} | hit ${$.cacheHits??"-"} | miss ${$.cacheMisses??"-"}`,`queue inflight ${$.inflight} | queued ${$.queued??"-"} | retries ${$.retries??"-"} | failed ${$.failed??"-"} | aborted ${$.aborted??"-"}`,`points ${$.points}`].join(`
|
|
246
|
+
}`),i=Ie(t,r,"uCamera"),o=Ie(t,r,"uPointSize"),s=Ie(t,r,"uPointCssSize"),a=Ie(t,r,"uPointOpacity"),l=Ie(t,r,"uPointStrokeScale"),c=Ie(t,r,"uPointInnerFillAlpha"),f=Ie(t,r,"uPointInnerFillColor"),u=Ie(t,r,"uPalette"),h=Ie(t,r,"uPaletteSize"),d=Ie(t,r,"uPointLineDash"),m=t.createVertexArray(),p=t.createBuffer(),b=t.createBuffer(),y=t.createBuffer(),x=t.createBuffer(),M=t.createTexture();if(!m||!p||!b||!y||!x||!M)throw new Error("point buffer allocation failed");t.bindVertexArray(m),t.bindBuffer(t.ARRAY_BUFFER,p),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const S=t.getAttribLocation(r,"aPosition");if(S<0)throw new Error("point position attribute not found");t.enableVertexAttribArray(S),t.vertexAttribPointer(S,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const C=t.getAttribLocation(r,"aClass");if(C<0)throw new Error("point class attribute not found");t.enableVertexAttribArray(C),t.vertexAttribIPointer(C,1,t.UNSIGNED_SHORT,0,0),t.bindBuffer(t.ARRAY_BUFFER,y),t.bufferData(t.ARRAY_BUFFER,0,t.DYNAMIC_DRAW);const A=t.getAttribLocation(r,"aFillMode");if(A<0)throw new Error("point fill mode attribute not found");return t.enableVertexAttribArray(A),t.vertexAttribIPointer(A,1,t.UNSIGNED_BYTE,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,x),t.bufferData(t.ELEMENT_ARRAY_BUFFER,0,t.DYNAMIC_DRAW),t.bindVertexArray(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindTexture(t.TEXTURE_2D,M),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array([160,160,160,255])),t.bindTexture(t.TEXTURE_2D,null),{program:r,vao:m,posBuffer:p,classBuffer:b,fillModeBuffer:y,indexBuffer:x,paletteTexture:M,uCamera:i,uPointSize:o,uPointCssSize:s,uPointOpacity:a,uPointLineDash:d,uPointStrokeScale:l,uPointInnerFillAlpha:c,uPointInnerFillColor:f,uPalette:u,uPaletteSize:h}}function oo(t){t.animation=null,t.frame!==null&&(cancelAnimationFrame(t.frame),t.frame=null)}function Oc(t){const{state:e,camera:n,target:r,durationMs:i,easing:o,onUpdate:s}=t,a=n.getViewState();oo(e),e.animation={startMs:Ee(),durationMs:Math.max(0,i),from:a,to:r,easing:o};const l=()=>{const c=e.animation;if(!c)return;const f=Math.max(0,Ee()-c.startMs),u=c.durationMs<=0?1:F(f/c.durationMs,0,1);let h=u;try{h=c.easing(u)}catch{h=u}if(Number.isFinite(h)||(h=u),h=F(h,0,1),n.setViewState({zoom:c.from.zoom+(c.to.zoom-c.from.zoom)*h,offsetX:c.from.offsetX+(c.to.offsetX-c.from.offsetX)*h,offsetY:c.from.offsetY+(c.to.offsetY-c.from.offsetY)*h,rotationDeg:c.from.rotationDeg+(c.to.rotationDeg-c.from.rotationDeg)*h}),s(),u>=1){e.animation=null,e.frame=null;return}e.frame=requestAnimationFrame(l)};e.frame=requestAnimationFrame(l)}function Wc(t){const e=Math.max(t*.5,1e-6),n=Math.max(1,t*8);return{minZoom:e,maxZoom:Math.max(e,n)}}function Yc(t,e,n){const r=Wc(t);let i=e??r.minZoom,o=n??r.maxZoom;return i=Math.max(1e-6,i),o=Math.max(1e-6,o),i>o&&(i=o),{minZoom:i,maxZoom:o}}function Xc(t,e,n,r,i){const o=t.getViewState(),s={zoom:typeof r.zoom=="number"&&Number.isFinite(r.zoom)?F(r.zoom,e,n):o.zoom,offsetX:typeof r.offsetX=="number"&&Number.isFinite(r.offsetX)?r.offsetX:o.offsetX,offsetY:typeof r.offsetY=="number"&&Number.isFinite(r.offsetY)?r.offsetY:o.offsetY,rotationDeg:typeof r.rotationDeg=="number"&&Number.isFinite(r.rotationDeg)?r.rotationDeg:o.rotationDeg};t.setViewState(s),i();const a=t.getViewState();return t.setViewState(o),a}function si(t,e,n,r,i,o=0){const s=Math.min(e/t.width,n/t.height),a=Number.isFinite(s)&&s>0?s:1,l=F(a,r,i),c=e/l,f=n/l;return{fitZoom:a,target:{zoom:l,offsetX:(t.width-c)*.5,offsetY:(t.height-f)*.5,rotationDeg:o}}}function Vc(t,e,n,r,i,o){const s=t.getViewState(),a=F(s.zoom*r,e,n);if(a===s.zoom)return null;const[l,c]=t.screenToWorld(i,o),f=t.getViewportSize(),u=i-f.width*.5,h=o-f.height*.5,d=on(s.rotationDeg),m=Math.cos(d),p=Math.sin(d),b=u/a*m-h/a*p,y=u/a*p+h/a*m,x=l-b,M=c-y;return{zoom:a,offsetX:x-f.width/(2*a),offsetY:M-f.height/(2*a)}}function Gc(t,e,n,r,i,o){const s=t.getViewState(),a=F(r,e,n);if(a===s.zoom)return null;const[l,c]=t.screenToWorld(i,o),f=t.getViewportSize(),u=i-f.width*.5,h=o-f.height*.5,d=on(s.rotationDeg),m=Math.cos(d),p=Math.sin(d),b=u/a*m-h/a*p,y=u/a*p+h/a*m,x=l-b,M=c-y;return{zoom:a,offsetX:x-f.width/(2*a),offsetY:M-f.height/(2*a)}}const Zc=250;function ai(t,e){if(!t||t.length===0)return[];if(!e||e<=0)return[];const n=10/e;return t.map(r=>r/n).filter(r=>Number.isFinite(r)&&r>0).sort((r,i)=>r-i)}function qc(t,e,n,r){if(t.length===0)return null;const i=Math.max(e*.005,1e-8);if(n==="in"){for(const o of t)if(o>e+i)return{type:"snap",zoom:o};return null}for(let o=t.length-1;o>=0;o--)if(t[o]<e-i)return{type:"snap",zoom:t[o]};return r&&e<=t[0]+i?{type:"fit"}:null}function Hc(t,e,n,r,i){const o=t.camera.getViewState(),[s,a]=t.camera.screenToWorld(n,r),l=t.camera.getViewportSize(),c=F(e,t.minZoom,t.maxZoom);if(c===o.zoom)return;const f=on(o.rotationDeg),u=Math.cos(f),h=Math.sin(f),d=n-l.width*.5,m=r-l.height*.5;t.cancelViewAnimation();const p=x=>{const M=d/x*u-m/x*h,S=d/x*h+m/x*u;return{offsetX:s-M-l.width/(2*x),offsetY:a-S-l.height/(2*x)}},b=p(c);t.viewAnimationState.animation={startMs:Ee(),durationMs:Math.max(0,i),from:o,to:{zoom:c,offsetX:b.offsetX,offsetY:b.offsetY,rotationDeg:o.rotationDeg},easing:Hn};const y=()=>{const x=t.viewAnimationState.animation;if(!x)return;const M=Math.max(0,Ee()-x.startMs),S=F(M/i,0,1),C=F(S*S*(3-2*S),0,1),A=o.zoom+(c-o.zoom)*C,{offsetX:B,offsetY:z}=p(A);t.camera.setViewState({zoom:A,offsetX:B,offsetY:z,rotationDeg:o.rotationDeg});const Y=S>=1;Y&&(t.clampViewState(),t.viewAnimationState.animation=null,t.viewAnimationState.frame=null),t.onViewStateChange(t.camera.getViewState()),t.requestRender(),Y||(t.viewAnimationState.frame=requestAnimationFrame(y))};t.viewAnimationState.frame=requestAnimationFrame(y)}const Fe="__default_point_layer__";class so{constructor(e,n,r={}){E(this,"canvas");E(this,"source");E(this,"gl");E(this,"camera",new ci);E(this,"onViewStateChange");E(this,"onStats");E(this,"onTileError");E(this,"onContextLost");E(this,"onContextRestored");E(this,"resizeObserver");E(this,"removeDprListener");E(this,"tileProgram");E(this,"tileScheduler");E(this,"authToken");E(this,"destroyed",!1);E(this,"contextLost",!1);E(this,"frame",null);E(this,"frameSerial",0);E(this,"interactionState",{dragging:!1,mode:"none",rotateLastAngleRad:null,pointerId:null,lastPointerX:0,lastPointerY:0});E(this,"interactionLocked",!1);E(this,"ctrlDragRotate",!0);E(this,"rotationDragSensitivityDegPerPixel",Fn);E(this,"maxCacheTiles");E(this,"fitZoom",1);E(this,"initialRotationDeg",0);E(this,"minZoom",1e-6);E(this,"maxZoom",1);E(this,"minZoomOverride",null);E(this,"maxZoomOverride",null);E(this,"viewTransitionDurationMs",0);E(this,"viewTransitionEasing",Hn);E(this,"viewAnimationState",{animation:null,frame:null});E(this,"pointLayers",new Map);E(this,"defaultPointSizeZoomStops",tn(Ln));E(this,"defaultPointSizeMagnificationStops",null);E(this,"defaultPointWeightMagnificationStops",null);E(this,"defaultPointOpacity",1);E(this,"defaultPointLineDash",[1,0]);E(this,"defaultPointStrokeScale",1);E(this,"defaultPointInnerFillOpacity",0);E(this,"defaultPointInnerFillColor",[...Ji]);E(this,"imageColorSettings",{brightness:0,contrast:0,saturation:0});E(this,"cache",new Map);E(this,"zoomSnaps",[]);E(this,"zoomSnapFitAsMin",!1);E(this,"zoomSnapState",{accumulatedDelta:0,lastSnapTimeMs:0,blockedDirection:null});E(this,"panExtentX",.2);E(this,"panExtentY",.2);E(this,"boundPointerDown");E(this,"boundPointerMove");E(this,"boundPointerUp");E(this,"boundWheel");E(this,"boundDoubleClick");E(this,"boundContextMenu");E(this,"boundContextLost");E(this,"boundContextRestored");this.canvas=e,this.source=n,this.onViewStateChange=r.onViewStateChange,this.onStats=r.onStats,this.onTileError=r.onTileError,this.onContextLost=r.onContextLost,this.onContextRestored=r.onContextRestored,this.authToken=r.authToken??"",this.maxCacheTiles=Math.max(32,Math.floor(r.maxCacheTiles??320)),this.initialRotationDeg=typeof r.initialRotationDeg=="number"&&Number.isFinite(r.initialRotationDeg)?r.initialRotationDeg:0,this.ctrlDragRotate=r.ctrlDragRotate??!0,this.rotationDragSensitivityDegPerPixel=typeof r.rotationDragSensitivityDegPerPixel=="number"&&Number.isFinite(r.rotationDragSensitivityDegPerPixel)?Math.max(0,r.rotationDragSensitivityDegPerPixel):Fn,this.defaultPointSizeZoomStops=$r(r.pointSizeByZoom),this.defaultPointSizeMagnificationStops=Kr(r.pointSizeByMagnification),this.defaultPointWeightMagnificationStops=jr(r.pointWeightByMagnification),this.defaultPointOpacity=Qr(r.pointOpacity),this.defaultPointStrokeScale=Gt(r.pointStrokeScale),this.defaultPointInnerFillOpacity=Jr(r.pointInnerFillOpacity),this.defaultPointInnerFillColor=ei(r.pointInnerFillColor),this.imageColorSettings=ti(r.imageColorSettings),this.minZoomOverride=Ot(r.minZoom),this.maxZoomOverride=Ot(r.maxZoom),this.viewTransitionDurationMs=mn(r.viewTransition?.duration),this.viewTransitionEasing=gn(r.viewTransition?.easing),this.zoomSnaps=ai(r.zoomSnaps,this.source.mpp),this.zoomSnapFitAsMin=!!r.zoomSnapFitAsMin,this.applyPanExtent(r.panExtent);const i=e.getContext("webgl2",{alpha:!1,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance",preserveDrawingBuffer:r.preserveDrawingBuffer??!1});if(!i)throw new Error("WebGL2 not supported");this.gl=i,this.tileProgram=ii(this.gl),this.tileScheduler=new Qi({authToken:this.authToken,maxConcurrency:r.tileScheduler?.maxConcurrency??12,maxRetries:r.tileScheduler?.maxRetries??2,retryBaseDelayMs:r.tileScheduler?.retryBaseDelayMs??120,retryMaxDelayMs:r.tileScheduler?.retryMaxDelayMs??1200,onTileLoad:(s,a)=>Lc({gl:this.gl,cache:this.cache,tile:s,bitmap:a,frameSerial:this.frameSerial,maxCacheTiles:this.maxCacheTiles,destroyed:this.destroyed,contextLost:this.contextLost,requestRender:()=>this.requestRender()}),onTileError:(s,a,l)=>{this.onTileError?.({tile:s,error:a,attemptCount:l}),console.warn("tile load failed",s.url,a)}}),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),this.removeDprListener=rn(()=>this.resize());const o=Ic({canvas:this.canvas,state:this.interactionState,getInteractionLocked:()=>this.interactionLocked,getCtrlDragRotate:()=>this.ctrlDragRotate,getRotationDragSensitivityDegPerPixel:()=>this.rotationDragSensitivityDegPerPixel,cancelViewAnimation:()=>this.cancelViewAnimation(),camera:this.camera,source:this.source,emitViewState:()=>this.onViewStateChange?.(this.camera.getViewState()),requestRender:()=>this.requestRender(),getPanExtentX:()=>this.panExtentX,getPanExtentY:()=>this.panExtentY,zoomBy:(s,a,l)=>this.zoomBy(s,a,l),getUseZoomSnaps:()=>this.zoomSnaps.length>0,onSnapZoom:(s,a,l)=>this.handleSnapZoom(s,a,l),zoomSnapState:this.zoomSnapState});this.boundPointerDown=o.pointerDown,this.boundPointerMove=o.pointerMove,this.boundPointerUp=o.pointerUp,this.boundWheel=o.wheel,this.boundDoubleClick=o.doubleClick,this.boundContextMenu=o.contextMenu,this.boundContextLost=s=>this.onWebGlContextLost(s),this.boundContextRestored=s=>this.onWebGlContextRestored(s),Zl(e,this.getCanvasHandlers()),this.fitToImage({duration:0}),this.resize()}getCanvasHandlers(){return{pointerDown:this.boundPointerDown,pointerMove:this.boundPointerMove,pointerUp:this.boundPointerUp,wheel:this.boundWheel,doubleClick:this.boundDoubleClick,contextMenu:this.boundContextMenu,contextLost:this.boundContextLost,contextRestored:this.boundContextRestored}}applyZoomBounds(){const e=Yc(this.fitZoom,this.minZoomOverride,this.maxZoomOverride);this.minZoom=e.minZoom,this.maxZoom=e.maxZoom}resolveTargetViewState(e){return Xc(this.camera,this.minZoom,this.maxZoom,e,()=>Zt(this.camera,this.source,this.panExtentX,this.panExtentY))}cancelViewAnimation(){oo(this.viewAnimationState)}startViewAnimation(e,n,r){this.resetZoomSnapStateForZoomChange(this.camera.getViewState().zoom,e.zoom),Oc({state:this.viewAnimationState,camera:this.camera,target:e,durationMs:n,easing:r,onUpdate:()=>{Zt(this.camera,this.source,this.panExtentX,this.panExtentY),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}})}createPointBufferRuntime(){return{pointCount:0,usePointIndices:!1,pointBuffersDirty:!0,lastPointData:null,zeroFillModes:new Uint8Array(0),lastPointPalette:null,pointPaletteSize:1}}createPointLayerState(e){return{id:e,program:oi(this.gl),runtime:this.createPointBufferRuntime(),pointSizeZoomStops:tn(this.defaultPointSizeZoomStops),pointSizeMagnificationStops:ic(this.defaultPointSizeMagnificationStops),pointWeightMagnificationStops:oc(this.defaultPointWeightMagnificationStops),pointOpacity:this.defaultPointOpacity,pointLineDash:[...this.defaultPointLineDash],pointStrokeScale:this.defaultPointStrokeScale,pointInnerFillOpacity:this.defaultPointInnerFillOpacity,pointInnerFillColor:[...this.defaultPointInnerFillColor]}}ensurePointLayer(e=Fe){const n=String(e||Fe),r=this.pointLayers.get(n);if(r)return r;const i=this.createPointLayerState(n);return this.pointLayers.set(n,i),i}deletePointProgram(e){this.contextLost||this.gl.isContextLost()||(this.gl.deleteBuffer(e.posBuffer),this.gl.deleteBuffer(e.classBuffer),this.gl.deleteBuffer(e.fillModeBuffer),this.gl.deleteBuffer(e.indexBuffer),this.gl.deleteTexture(e.paletteTexture),this.gl.deleteVertexArray(e.vao),this.gl.deleteProgram(e.program))}getPointRenderLayers(){const e=Math.max(1,window.devicePixelRatio||1),n=[];for(const r of this.pointLayers.values()){const i=this.getPointSize(r.id);n.push({pointProgram:r.program,pointCount:r.runtime.pointCount,usePointIndices:r.runtime.usePointIndices,pointPaletteSize:r.runtime.pointPaletteSize,pointLineDash:r.pointLineDash,pointOpacity:r.pointOpacity,pointStrokeScale:this.getPointStrokeScale(r.id),pointInnerFillOpacity:r.pointInnerFillOpacity,pointInnerFillColor:r.pointInnerFillColor,pointCssSizePx:i,pointSizePx:i*e})}return n}resetZoomSnapState(){this.zoomSnapState.accumulatedDelta=0,this.zoomSnapState.lastSnapTimeMs=0,this.zoomSnapState.blockedDirection=null}resetZoomSnapStateForZoomChange(e,n){Math.abs(e-n)<1e-6||this.resetZoomSnapState()}applyViewStateAndRender(e,n=!0){const r=this.camera.getViewState();n&&this.cancelViewAnimation(),this.resetZoomSnapStateForZoomChange(r.zoom,e.zoom),this.camera.setViewState(e),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}setAuthToken(e){this.authToken=String(e??""),this.tileScheduler.setAuthToken(this.authToken)}setZoomRange(e,n){const r=Ot(e),i=Ot(n);if(this.minZoomOverride===r&&this.maxZoomOverride===i)return;this.minZoomOverride=r,this.maxZoomOverride=i,this.applyZoomBounds(),this.resetZoomSnapState();const o=this.resolveTargetViewState({}),s=this.camera.getViewState();Rn(s,o)||this.applyViewStateAndRender(o)}setViewTransition(e){this.viewTransitionDurationMs=mn(e?.duration),this.viewTransitionEasing=gn(e?.easing)}setViewState(e,n){const r=this.resolveTargetViewState(e),i=this.camera.getViewState();if(Rn(i,r))return;const o=mn(n?.duration??this.viewTransitionDurationMs),s=gn(n?.easing??this.viewTransitionEasing);if(o<=0){this.applyViewStateAndRender(r);return}this.startViewAnimation(r,o,s)}getViewState(){return this.camera.getViewState()}getZoomRange(){return{minZoom:this.minZoom,maxZoom:this.maxZoom}}getRegionLabelAutoLiftCapZoom(){const e=this.zoomSnaps.filter(n=>n>=this.minZoom&&n<=this.maxZoom);return e.length>0?e[e.length-1]:this.maxZoom}isViewAnimating(){return this.viewAnimationState.animation!==null}registerPointLayer(e){this.ensurePointLayer(e)}unregisterPointLayer(e){const n=String(e||Fe),r=this.pointLayers.get(n);r&&(this.pointLayers.delete(n),this.deletePointProgram(r.program),this.requestRender())}setPointPalette(e,n=Fe){const r=this.ensurePointLayer(n);r.runtime=ni(r.runtime,this.gl,r.program,this.contextLost,e),!(!e||e.length===0)&&this.requestRender()}setPointLineDash(e,n=Fe){const r=this.ensurePointLayer(n),i=hc(e);r.pointLineDash[0]===i[0]&&r.pointLineDash[1]===i[1]||(r.pointLineDash=i,this.requestRender())}setPointData(e,n=Fe){const r=this.ensurePointLayer(n);r.runtime=ri(r.runtime,this.gl,r.program,this.contextLost,e),this.requestRender()}setInteractionLock(e){const n=!!e;this.interactionLocked!==n&&(this.interactionLocked=n,n&&this.cancelDrag())}setPointSizeByZoom(e,n=Fe){const r=this.ensurePointLayer(n),i=$r(e);sc(r.pointSizeZoomStops,i)||(r.pointSizeZoomStops=i,this.requestRender())}setPointSizeByMagnification(e,n=Fe){const r=this.ensurePointLayer(n),i=Kr(e);ac(r.pointSizeMagnificationStops,i)||(r.pointSizeMagnificationStops=i,this.requestRender())}setPointWeightByMagnification(e,n=Fe){const r=this.ensurePointLayer(n),i=jr(e);lc(r.pointWeightMagnificationStops,i)||(r.pointWeightMagnificationStops=i,this.requestRender())}setPointOpacity(e,n=Fe){const r=this.ensurePointLayer(n),i=Qr(e);r.pointOpacity!==i&&(r.pointOpacity=i,this.requestRender())}setPointStrokeScale(e,n=Fe){const r=this.ensurePointLayer(n),i=Gt(e);r.pointStrokeScale!==i&&(r.pointStrokeScale=i,this.requestRender())}setPointInnerFillOpacity(e,n=Fe){const r=this.ensurePointLayer(n),i=Jr(e);r.pointInnerFillOpacity!==i&&(r.pointInnerFillOpacity=i,this.requestRender())}setPointInnerFillColor(e,n=Fe){const r=this.ensurePointLayer(n),i=ei(e);r.pointInnerFillColor[0]===i[0]&&r.pointInnerFillColor[1]===i[1]&&r.pointInnerFillColor[2]===i[2]||(r.pointInnerFillColor=i,this.requestRender())}setImageColorSettings(e){const n=ti(e),r=this.imageColorSettings;r.brightness===n.brightness&&r.contrast===n.contrast&&r.saturation===n.saturation||(this.imageColorSettings=n,this.requestRender())}cancelDrag(){Tc(this.canvas,this.interactionState)}screenToWorld(e,n){const r=this.canvas.getBoundingClientRect(),i=e-r.left,o=n-r.top;return this.camera.screenToWorld(i,o)}worldToScreen(e,n){return this.camera.worldToScreen(e,n)}setViewCenter(e,n,r){if(!Number.isFinite(e)||!Number.isFinite(n))return;const i=this.camera.getViewState(),o=Math.max(1e-6,i.zoom),s=this.camera.getViewportSize();this.setViewState({offsetX:e-s.width/(2*o),offsetY:n-s.height/(2*o)},r)}getViewCorners(){return this.camera.getViewCorners()}getInitialRotationDeg(){return this.initialRotationDeg}getViewBounds(){return nn(this.camera)}resetRotation(e){const n=this.camera.getViewState();Math.abs(n.rotationDeg-this.initialRotationDeg)<1e-6||this.setViewState({rotationDeg:this.initialRotationDeg},e)}getPointSize(e=Fe){const n=this.pointLayers.get(String(e||Fe)),r=n?.pointSizeMagnificationStops??this.defaultPointSizeMagnificationStops;if(r&&r.length>0){const l=Math.max(1e-6,this.camera.getViewState().zoom),c=En(this.source.mpp??0,l);if(c>0){const f=uc(c,r);return F(f,ht,Hr)}}const i=Math.max(1e-6,this.camera.getViewState().zoom),o=this.source.maxTierZoom+Math.log2(i),s=n?.pointSizeZoomStops??this.defaultPointSizeZoomStops,a=cc(o,s);return F(a,ht,Hr)}getPointSizeByZoom(e=Fe){return this.getPointSize(e)}getPointStrokeScale(e=Fe){const n=this.pointLayers.get(String(e||Fe)),r=n?.pointWeightMagnificationStops??this.defaultPointWeightMagnificationStops;if(r&&r.length>0){const i=Math.max(1e-6,this.camera.getViewState().zoom),o=En(this.source.mpp??0,i);if(o>0)return Gt(fc(o,r))}return n?.pointStrokeScale??this.defaultPointStrokeScale}fitToImage(e){const n=this.canvas.getBoundingClientRect(),r=Math.max(1,n.width||1),i=Math.max(1,n.height||1),o=si(this.source,r,i,this.minZoom,this.maxZoom,this.initialRotationDeg);this.fitZoom=o.fitZoom,this.applyZoomBounds(),this.setViewState(o.target,e)}zoomBy(e,n,r,i){const o=Vc(this.camera,this.minZoom,this.maxZoom,e,n,r);o&&this.setViewState(o,i)}handleWheelZoom(e,n,r){if(this.zoomSnaps.length>0){ro(e,n,r,this.zoomSnapState,(i,o,s)=>this.handleSnapZoom(i,o,s));return}no(e,n,r,(i,o,s)=>this.zoomBy(i,o,s))}zoomTo(e,n,r,i){const o=Gc(this.camera,this.minZoom,this.maxZoom,e,n,r);o&&this.setViewState(o,i)}setZoomSnaps(e,n){this.zoomSnaps=ai(e,this.source.mpp),this.zoomSnapFitAsMin=!!n,this.resetZoomSnapState()}setPanExtent(e){this.applyPanExtent(e)}applyPanExtent(e){typeof e=="number"&&Number.isFinite(e)?(this.panExtentX=Math.max(0,e),this.panExtentY=Math.max(0,e)):e!=null&&typeof e=="object"?(this.panExtentX=typeof e.x=="number"&&Number.isFinite(e.x)?Math.max(0,e.x):.2,this.panExtentY=typeof e.y=="number"&&Number.isFinite(e.y)?Math.max(0,e.y):.2):(this.panExtentX=.2,this.panExtentY=.2)}getZoomPivotAnimationContext(){return{camera:this.camera,viewAnimationState:this.viewAnimationState,minZoom:this.minZoom,maxZoom:this.maxZoom,cancelViewAnimation:()=>this.cancelViewAnimation(),clampViewState:()=>Zt(this.camera,this.source,this.panExtentX,this.panExtentY),onViewStateChange:e=>this.onViewStateChange?.(e),requestRender:()=>this.requestRender()}}handleSnapZoom(e,n,r){const i=this.viewAnimationState.animation,o=i?i.to.zoom:this.camera.getViewState().zoom,s=this.zoomSnaps.filter(f=>f>=this.minZoom&&f<=this.maxZoom),a=qc(s,o,e,this.zoomSnapFitAsMin);if(!a)return!1;let l;if(a.type==="fit"){const f=this.canvas.getBoundingClientRect(),u=Math.max(1,f.width||1),h=Math.max(1,f.height||1),d=si(this.source,u,h,this.minZoom,this.maxZoom,this.initialRotationDeg);this.fitZoom=d.fitZoom,this.applyZoomBounds(),l=d.target.zoom}else l=a.zoom;const c=Math.max(Math.abs(l)*.005,1e-8);if(i){if((i.to.zoom>i.from.zoom+c?"in":i.to.zoom<i.from.zoom-c?"out":null)===e&&Math.abs(i.to.zoom-l)<=c)return!1}else if(Math.abs(o-l)<=c)return!1;return Hc(this.getZoomPivotAnimationContext(),l,n,r,Zc),!0}render(){if(this.destroyed||this.contextLost||this.gl.isContextLost())return;const e=this.onStats?Ee():0;this.frameSerial+=1;const n=Uc({gl:this.gl,camera:this.camera,source:this.source,cache:this.cache,frameSerial:this.frameSerial,tileProgram:this.tileProgram,imageColorSettings:this.imageColorSettings,pointLayers:this.getPointRenderLayers(),tileScheduler:this.tileScheduler,getVisibleTiles:()=>Rc(this.camera,this.source),getVisibleTilesForTier:r=>io(this.camera,this.source,r),getViewBounds:()=>nn(this.camera),intersectsBounds:Ec});if(this.onStats){const r=this.tileScheduler.getSnapshot();this.onStats({tier:n.tier,visible:n.visible,rendered:n.rendered,points:n.points,fallback:n.fallback,cache:this.cache.size,inflight:r.inflight,queued:r.queued,retries:r.retries,failed:r.failed,aborted:r.aborted,cacheHits:n.cacheHits,cacheMisses:n.cacheMisses,drawCalls:n.drawCalls,frameMs:Ee()-e})}}requestRender(){this.frame!==null||this.destroyed||this.contextLost||this.gl.isContextLost()||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}resize(){Hl(this.canvas,this.gl,this.camera),this.requestRender()}onWebGlContextLost(e){const n=Nc({event:e,destroyed:this.destroyed,contextLost:this.contextLost,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,cache:this.cache,onContextLost:this.onContextLost});if(n.handled){this.frame=n.frame,this.contextLost=!0;for(const r of this.pointLayers.values())r.runtime={...r.runtime,pointBuffersDirty:!0}}}onWebGlContextRestored(e){if(!this.destroyed){this.contextLost=!1,this.cache.clear(),this.tileProgram=ii(this.gl);for(const n of this.pointLayers.values())n.program=oi(this.gl),n.runtime={...n.runtime,pointBuffersDirty:!0},n.runtime.lastPointPalette&&n.runtime.lastPointPalette.length>0&&(n.runtime=ni(n.runtime,this.gl,n.program,this.contextLost,n.runtime.lastPointPalette)),n.runtime.lastPointData&&(n.runtime=ri(n.runtime,this.gl,n.program,this.contextLost,n.runtime.lastPointData));this.resize(),this.onContextRestored?.()}}destroy(){const e=zc({destroyed:this.destroyed,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),resizeObserver:this.resizeObserver,removeDprListener:this.removeDprListener,removeCanvasEventListeners:()=>ql(this.canvas,this.getCanvasHandlers()),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,contextLost:this.contextLost,gl:this.gl,cache:this.cache,tileProgram:this.tileProgram,pointPrograms:Array.from(this.pointLayers.values(),n=>n.program)});e.didDestroy&&(this.destroyed=!0,this.frame=e.frame)}}const $c=[];function Kc(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function jc({source:t,viewState:e,onViewStateChange:n,onStats:r,onTileError:i,onContextLost:o,onContextRestored:s,imageColorSettings:a=null,initialRotate:l=0,fitNonce:c=0,rotationResetNonce:f=0,authToken:u="",ctrlDragRotate:h=!0,minZoom:d,maxZoom:m,viewTransition:p,zoomSnaps:b,zoomSnapFitAsMin:y,panExtent:x,preserveDrawingBuffer:M,onPointerWorldMove:S,debugOverlay:C=!1,debugOverlayStyle:A,className:B,style:z,children:Y}){const P=g.useRef(null),I=g.useRef(null),O=g.useRef(null),v=g.useRef(null),W=g.useRef(null),j=g.useRef(null),L=g.useRef($c),ge=g.useRef(!1),le=g.useRef(new Set),Q=g.useRef(new Set),ve=g.useRef(n),Ae=g.useRef(r),D=g.useRef(i),T=g.useRef(o),k=g.useRef(s),[oe,ue]=g.useState(0),[$,ce]=g.useState(null),te=g.useRef(C);g.useEffect(()=>{ve.current=n},[n]),g.useEffect(()=>{Ae.current=r},[r]),g.useEffect(()=>{D.current=i},[i]),g.useEffect(()=>{T.current=o},[o]),g.useEffect(()=>{k.current=s},[s]),g.useEffect(()=>{te.current=C,C||ce(null)},[C]);const _e=g.useMemo(()=>({position:"relative",width:"100%",height:"100%",...z}),[z]),Se=g.useMemo(()=>({position:"absolute",top:8,left:8,zIndex:7,margin:0,padding:"8px 10px",maxWidth:"min(420px, 80%)",pointerEvents:"none",whiteSpace:"pre-wrap",lineHeight:1.35,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fontSize:11,color:"#cde6ff",background:"rgba(6, 12, 20, 0.82)",border:"1px solid rgba(173, 216, 255, 0.28)",borderRadius:8,boxShadow:"0 8px 22px rgba(0,0,0,0.35)",...A}),[A]),fe=Kc(l),xe=g.useCallback(U=>({...U,rotationDeg:U.rotationDeg-fe}),[fe]),ee=g.useCallback(U=>typeof U.rotationDeg!="number"||!Number.isFinite(U.rotationDeg)?U:{...U,rotationDeg:U.rotationDeg+fe},[fe]),se=g.useCallback(U=>{Ae.current?.(U),te.current&&ce(U)},[]),he=g.useMemo(()=>$?[`tier ${$.tier} | frame ${$.frameMs?.toFixed(2)??"-"} ms | drawCalls ${$.drawCalls??"-"}`,`tiles visible ${$.visible} | rendered ${$.rendered} | fallback ${$.fallback}`,`cache size ${$.cache} | hit ${$.cacheHits??"-"} | miss ${$.cacheMisses??"-"}`,`queue inflight ${$.inflight} | queued ${$.queued??"-"} | retries ${$.retries??"-"} | failed ${$.failed??"-"} | aborted ${$.aborted??"-"}`,`points ${$.points}`].join(`
|
|
247
247
|
`):"stats: waiting for first frame...",[$]),ae=g.useCallback(()=>{const U=O.current;if(!U)return;const Z=U.getContext("2d");if(!Z)return;const q=Math.max(1,window.devicePixelRatio||1),re=U.getBoundingClientRect(),pe=Math.max(1,Math.round(re.width*q)),de=Math.max(1,Math.round(re.height*q));(U.width!==pe||U.height!==de)&&(U.width=pe,U.height=de);const Ne=re.width,w=re.height;Z.setTransform(1,0,0,1,0,0),Z.clearRect(0,0,U.width,U.height),Z.setTransform(q,0,0,q,0,0);const R=L.current;for(let _=0;_<R.length;_+=1)Z.save(),R[_].draw(Z,Ne,w),Z.restore()},[]),ne=g.useCallback(()=>{ge.current||(ge.current=!0,requestAnimationFrame(()=>{ge.current=!1,ae()}))},[ae]),Me=g.useCallback((U,Z,q)=>{const re=L.current.filter(pe=>pe.id!==U);re.push({id:U,priority:Z,draw:q}),re.sort((pe,de)=>pe.priority-de.priority),L.current=re,ne()},[ne]),we=g.useCallback(U=>{L.current=L.current.filter(Z=>Z.id!==U),ne()},[ne]),V=g.useCallback((U,Z)=>{Z?le.current.add(U):le.current.delete(U),v.current?.setInteractionLock(le.current.size>0)},[]),H=g.useCallback(()=>le.current.size>0,[]),be=g.useCallback((U,Z)=>{const q=v.current;return q?Bn(q.worldToScreen(U,Z)):null},[]),J=g.useCallback((U,Z)=>{const q=v.current;if(!q)return null;const re=q.screenToWorld(U,Z);if(!Array.isArray(re)||re.length<2)return null;const pe=Number(re[0]),de=Number(re[1]);return!Number.isFinite(pe)||!Number.isFinite(de)?null:[pe,de]},[]),K=g.useCallback(U=>(Q.current.add(U),()=>{Q.current.delete(U)}),[]),Re=g.useCallback(U=>{ve.current?.(xe(U));const Z=Q.current;if(Z.size>0){const q=Array.from(Z);for(let re=0;re<q.length;re+=1)q[re](U)}W.current?.(),j.current?.(),ne()},[ne,xe]);g.useEffect(()=>{const U=I.current;if(!U||!t)return;const Z=new so(U,t,{onViewStateChange:Re,onStats:se,onTileError:q=>{D.current?.(q)},onContextLost:()=>{T.current?.()},onContextRestored:()=>{k.current?.()},authToken:u,imageColorSettings:a,initialRotationDeg:l,ctrlDragRotate:h,minZoom:d,maxZoom:m,viewTransition:p,zoomSnaps:b,zoomSnapFitAsMin:y,panExtent:x,preserveDrawingBuffer:M});return v.current=Z,ue(q=>q+1),e&&Z.setViewState(ee(e)),Z.setInteractionLock(le.current.size>0),()=>{Z.destroy(),v.current=null}},[t,se,h,Re,fe,ee]),g.useEffect(()=>{v.current?.setAuthToken(u)},[u]),g.useEffect(()=>{const U=v.current;!U||!e||U.isViewAnimating()||U.setViewState(ee(e))},[e,ee]),g.useEffect(()=>{v.current?.fitToImage()},[c]),g.useEffect(()=>{v.current?.resetRotation()},[f]),g.useEffect(()=>{v.current?.setZoomRange(d,m)},[d,m]),g.useEffect(()=>{v.current?.setViewTransition(p)},[p]),g.useEffect(()=>{v.current?.setZoomSnaps(b,y)},[b,y]),g.useEffect(()=>{v.current?.setPanExtent(x)},[x]),g.useEffect(()=>{v.current?.setImageColorSettings(a)},[a]),g.useEffect(()=>{const U=O.current;if(!U)return;W.current=ne,ne();const Z=new ResizeObserver(()=>ne());return Z.observe(U),()=>{Z.disconnect(),W.current===ne&&(W.current=null)}},[ne]),g.useEffect(()=>rn(()=>ne()),[ne]);const X=g.useMemo(()=>({source:t,rendererRef:v,rendererSerial:oe,canvasRef:I,containerRef:P,drawInvalidateRef:W,overviewInvalidateRef:j,worldToScreen:be,screenToWorld:J,registerDrawCallback:Me,unregisterDrawCallback:we,requestOverlayRedraw:ne,registerViewStateListener:K,setInteractionLock:V,isInteractionLocked:H}),[t,oe,be,J,Me,we,ne,K,V,H]),Ce=g.useRef(S);g.useEffect(()=>{Ce.current=S},[S]);const De=g.useCallback(U=>{const Z=Ce.current;if(!Z)return;const q=J(U.clientX,U.clientY),re=!!q&&q[0]>=0&&q[1]>=0&&!!t&&q[0]<=t.width&&q[1]<=t.height;Z({coordinate:q,clientX:U.clientX,clientY:U.clientY,insideImage:re})},[J,t]),Le=g.useCallback(()=>{Ce.current?.({coordinate:null,clientX:-1,clientY:-1,insideImage:!1})},[]);return Ge.jsx(ca,{value:X,children:Ge.jsxs("div",{ref:P,className:B,style:_e,onPointerMove:S?De:void 0,onPointerLeave:S?Le:void 0,children:[Ge.jsx("canvas",{ref:I,className:"wsi-render-canvas",style:{position:"absolute",inset:0,zIndex:1,width:"100%",height:"100%",display:"block",touchAction:"none"}}),Ge.jsx("canvas",{ref:O,className:"wsi-overlay-canvas",style:{position:"absolute",inset:0,zIndex:2,width:"100%",height:"100%",display:"block",pointerEvents:"none",touchAction:"none"}}),Y,C&&Ge.jsx("pre",{"data-open-plant-debug-overlay":!0,style:Se,children:he})]})})}function Qc(t){const e=[];for(let n=0;n<t.length;n+=1){const r=t[n],i=mt([dt(r?.coordinates)]);if(i.length===0)continue;let o=0,s=1/0,a=1/0,l=-1/0,c=-1/0;for(const f of i)o+=f.area,f.minX<s&&(s=f.minX),f.minY<a&&(a=f.minY),f.maxX>l&&(l=f.maxX),f.maxY>c&&(c=f.maxY);!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(l)||!Number.isFinite(c)||e.push({regionId:r.id??n,regionIndex:n,polygons:i,area:Math.max(1e-6,o),minX:s,minY:a,maxX:l,maxY:c})}return e}const Jc=128,pn=[];function ut(t,e,n,r,i){if(i<=1||n<=e)return 0;const o=(t-e)/r;return!Number.isFinite(o)||o<=0?0:o>=i-1?i-1:Math.floor(o)}function eu(t){if(t.length===0)return null;let e=1/0,n=1/0,r=-1/0,i=-1/0;for(const f of t)f.minX<e&&(e=f.minX),f.minY<n&&(n=f.minY),f.maxX>r&&(r=f.maxX),f.maxY>i&&(i=f.maxY);if(!Number.isFinite(e)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i))return null;const o=Math.ceil(Math.sqrt(t.length*2)),s=Math.max(1,Math.min(Jc,o)),a=r>e?(r-e)/s:1,l=i>n?(i-n)/s:1,c=Array.from({length:s*s},()=>[]);for(let f=0;f<t.length;f+=1){const u=t[f],h=ut(u.minX,e,r,a,s),d=ut(u.maxX,e,r,a,s),m=ut(u.minY,n,i,l,s),p=ut(u.maxY,n,i,l,s);for(let b=m;b<=p;b+=1)for(let y=h;y<=d;y+=1)c[b*s+y].push(f)}return{minX:e,minY:n,maxX:r,maxY:i,gridSize:s,cellWidth:a,cellHeight:l,buckets:c}}function tu(t,e,n){if(!t||e<t.minX||e>t.maxX||n<t.minY||n>t.maxY)return pn;const r=ut(e,t.minX,t.maxX,t.cellWidth,t.gridSize),i=ut(n,t.minY,t.maxY,t.cellHeight,t.gridSize);return t.buckets[i*t.gridSize+r]??pn}function nu(t,e){if(Array.isArray(e)){const n=e[t];if(typeof n=="string"&&n.length>0)return n}if(e instanceof Map){const n=e.get(t);if(typeof n=="string"&&n.length>0)return n}return String(t)}function ru(t,e,n={}){const r=Math.max(0,Math.min(Math.floor(t?.count??0),Math.floor((t?.positions?.length??0)/2),t?.paletteIndices?.length??0,t?.fillModes instanceof Uint8Array?t.fillModes.length:Number.MAX_SAFE_INTEGER));let i=null;if(t?.drawIndices instanceof Uint32Array){const d=t.drawIndices;let m=d.length;for(let p=0;p<d.length;p+=1)d[p]<r||(m-=1);if(m===d.length)i=d;else if(m>0){const p=new Uint32Array(m);let b=0;for(let y=0;y<d.length;y+=1){const x=d[y];x>=r||(p[b]=x,b+=1)}i=p}else i=new Uint32Array(0)}const o=i?i.length:r,s=Qc(e??[]);if(!t||o===0||s.length===0)return{groups:[],inputPointCount:o,pointsInsideAnyRegion:0,unmatchedPointCount:o};const a=new Map,l=new Map,c=eu(s);let f=0;for(let d=0;d<o;d+=1){const m=i?i[d]:d,p=t.positions[m*2],b=t.positions[m*2+1];if(!Number.isFinite(p)||!Number.isFinite(b))continue;let y=null;const x=tu(c,p,b);if(x.length===0)continue;for(const C of x){const A=s[C];let B=!1;for(const z of A.polygons)if(gi(p,b,z)){B=!0;break}B&&(!y||A.area<y.area)&&(y=A)}if(!y)continue;f+=1;const M=t.paletteIndices[m]??0,S=a.get(y.regionIndex)??new Map;S.set(M,(S.get(M)??0)+1),a.set(y.regionIndex,S),l.set(y.regionIndex,(l.get(y.regionIndex)??0)+1)}const u=n.includeEmptyRegions??!1,h=[];for(const d of s){const m=l.get(d.regionIndex)??0;if(!u&&m<=0)continue;const p=a.get(d.regionIndex)??new Map,b=Array.from(p.entries()).map(([y,x])=>({classId:nu(y,n.paletteIndexToClassId),paletteIndex:y,count:x})).sort((y,x)=>x.count-y.count||y.paletteIndex-x.paletteIndex);h.push({regionId:d.regionId,regionIndex:d.regionIndex,totalCount:m,classCounts:b})}return{groups:h,inputPointCount:o,pointsInsideAnyRegion:f,unmatchedPointCount:Math.max(0,o-f)}}function iu(t){return t.replace(/^\s*SRID\s*=\s*\d+\s*;\s*/i,"")}function ou(t){return t>="A"&&t<="Z"||t>="a"&&t<="z"}function su(t){return t>="0"&&t<="9"}function li(t){return t==="+"||t==="-"||t==="."||su(t)}class au{constructor(e){E(this,"text");E(this,"index",0);this.text=iu(e.trim())}parse(){if(!this.text)return null;const e=this.readWord();if(!e)return null;const n=e.toUpperCase();if(n!=="POLYGON"&&n!=="MULTIPOLYGON")return null;this.skipWhitespace();const r=this.peekWord();if(r){const s=r.toUpperCase();(s==="Z"||s==="M"||s==="ZM")&&(this.readWord(),this.skipWhitespace())}if(this.consumeWordIf("EMPTY"))return this.skipWhitespace(),this.isEof()?n==="POLYGON"?{type:"Polygon",coordinates:[]}:{type:"MultiPolygon",coordinates:[]}:null;let i;try{i=this.parseNestedList()}catch{return null}if(this.skipWhitespace(),!this.isEof())return null;if(n==="POLYGON"){const s=ao(i);return s?{type:"Polygon",coordinates:s}:null}const o=cu(i);return o?{type:"MultiPolygon",coordinates:o}:null}isEof(){return this.index>=this.text.length}currentChar(){return this.text[this.index]??""}skipWhitespace(){for(;!this.isEof()&&/\s/.test(this.currentChar());)this.index+=1}readWord(){if(this.skipWhitespace(),this.isEof())return null;const e=this.index;for(;!this.isEof()&&ou(this.currentChar());)this.index+=1;return this.index===e?null:this.text.slice(e,this.index)}peekWord(){const e=this.index,n=this.readWord();return this.index=e,n}consumeWordIf(e){const n=this.index,r=this.readWord();return!r||r.toUpperCase()!==e.toUpperCase()?(this.index=n,!1):!0}parseNestedList(){if(this.skipWhitespace(),this.currentChar()!=="(")throw new Error("Expected '('");this.index+=1;const e=[];for(;;){this.skipWhitespace(),this.currentChar()==="("?e.push(this.parseNestedList()):e.push(this.parseCoordinateTuple()),this.skipWhitespace();const n=this.currentChar();if(n===","){this.index+=1;continue}if(n===")"){this.index+=1;break}throw new Error("Expected ',' or ')'")}return e}parseCoordinateTuple(){this.skipWhitespace();const e=[];for(;;){this.skipWhitespace();const n=this.currentChar();if(!n||!li(n))break;const r=this.readNumber();if(r===null)break;e.push(r),this.skipWhitespace();const i=this.currentChar();if(!i||i===","||i===")")break;if(!li(i))throw new Error("Invalid coordinate")}if(e.length<2)throw new Error("Coordinate requires at least x y");return[e[0],e[1]]}readNumber(){if(this.skipWhitespace(),this.isEof())return null;const n=this.text.slice(this.index).match(/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/);if(!n)return null;const r=Number(n[0]);return Number.isFinite(r)?(this.index+=n[0].length,r):null}}function lu(t){return Array.isArray(t)&&t.length>=2&&typeof t[0]=="number"&&Number.isFinite(t[0])&&typeof t[1]=="number"&&Number.isFinite(t[1])}function ao(t){if(!Array.isArray(t))return null;const e=[];for(const n of t){if(!Array.isArray(n))return null;const r=[];for(const i of n){if(!lu(i))return null;r.push([i[0],i[1]])}e.push(r)}return e}function cu(t){if(!Array.isArray(t))return null;const e=[];for(const n of t){const r=ao(n);if(!r)return null;e.push(r)}return e}function uu(t){return typeof t!="string"?null:new au(t).parse()}exports.DEFAULT_POINT_COLOR=Nn;exports.DrawLayer=Pi;exports.DrawingLayer=ua;exports.HeatmapLayer=Va;exports.M1TileRenderer=ui;exports.OverlayLayer=Za;exports.OverviewMap=nl;exports.PatchLayer=il;exports.PointLayer=Il;exports.RegionLayer=Xl;exports.TileScheduler=Qi;exports.TileViewerCanvas=Vl;exports.WsiTileRenderer=so;exports.WsiViewer=jc;exports.__heatmapLayerInternals=Ga;exports.buildClassPalette=Ho;exports.buildPointSpatialIndexAsync=ji;exports.calcScaleLength=Vo;exports.calcScaleResolution=zn;exports.calcViewingMagnification=En;exports.clamp=F;exports.closeRing=Oe;exports.computeRoiPointGroups=ru;exports.createCircle=Mn;exports.createRectangle=Qt;exports.createSpatialIndex=Ti;exports.filterPointDataByPolygons=Mt;exports.filterPointDataByPolygonsHybrid=qi;exports.filterPointDataByPolygonsInWorker=$i;exports.filterPointIndicesByPolygons=Vi;exports.filterPointIndicesByPolygonsInWorker=ml;exports.getWebGpuCapabilities=fl;exports.hexToRgba=pi;exports.isSameViewState=Rn;exports.lookupCellIndex=Ki;exports.normalizeImageClasses=qa;exports.normalizeImageInfo=$a;exports.parseWkt=uu;exports.prefilterPointsByBoundsWebGpu=Zi;exports.terminatePointHitIndexWorker=Ml;exports.terminateRoiClipWorker=dl;exports.toBearerToken=Go;exports.toRoiGeometry=dt;exports.toTileUrl=qn;exports.useViewerContext=st;
|
|
248
248
|
//# sourceMappingURL=index.cjs.map
|