open-plant 1.3.5 → 1.3.6
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -158,6 +158,6 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
|
158
158
|
// Premultiplied alpha output: inner fill is black, so it only contributes alpha.
|
|
159
159
|
outColor = vec4(color.rgb * ringAlpha, alpha);
|
|
160
160
|
}
|
|
161
|
-
}`),i=Pe(e,r,"uCamera"),o=Pe(e,r,"uPointSize"),s=Pe(e,r,"uPointStrokeScale"),a=Pe(e,r,"uPointInnerFillAlpha"),c=Pe(e,r,"uPalette"),l=Pe(e,r,"uPaletteSize"),u=e.createVertexArray(),f=e.createBuffer(),d=e.createBuffer(),g=e.createBuffer(),p=e.createBuffer(),S=e.createTexture();if(!u||!f||!d||!g||!p||!S)throw new Error("point buffer allocation failed");e.bindVertexArray(u),e.bindBuffer(e.ARRAY_BUFFER,f),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const x=e.getAttribLocation(r,"aPosition");if(x<0)throw new Error("point position attribute not found");e.enableVertexAttribArray(x),e.vertexAttribPointer(x,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,d),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const M=e.getAttribLocation(r,"aTerm");if(M<0)throw new Error("point term attribute not found");e.enableVertexAttribArray(M),e.vertexAttribIPointer(M,1,e.UNSIGNED_SHORT,0,0),e.bindBuffer(e.ARRAY_BUFFER,g),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const R=e.getAttribLocation(r,"aFillMode");if(R<0)throw new Error("point fill mode attribute not found");return e.enableVertexAttribArray(R),e.vertexAttribIPointer(R,1,e.UNSIGNED_BYTE,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,p),e.bufferData(e.ELEMENT_ARRAY_BUFFER,0,e.DYNAMIC_DRAW),e.bindVertexArray(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindTexture(e.TEXTURE_2D,S),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([160,160,160,255])),e.bindTexture(e.TEXTURE_2D,null),{program:r,vao:u,posBuffer:f,termBuffer:d,fillModeBuffer:g,indexBuffer:p,paletteTexture:S,uCamera:i,uPointSize:o,uPointStrokeScale:s,uPointInnerFillAlpha:a,uPalette:c,uPaletteSize:l}}function wi(e){e.animation=null,e.frame!==null&&(cancelAnimationFrame(e.frame),e.frame=null)}function Ba(e){const{state:t,camera:n,target:r,durationMs:i,easing:o,onUpdate:s}=e,a=n.getViewState();wi(t),t.animation={startMs:fe(),durationMs:Math.max(0,i),from:a,to:r,easing:o};const c=()=>{const l=t.animation;if(!l)return;const u=Math.max(0,fe()-l.startMs),f=l.durationMs<=0?1:L(u/l.durationMs,0,1);let d=f;try{d=l.easing(f)}catch{d=f}if(Number.isFinite(d)||(d=f),d=L(d,0,1),n.setViewState({zoom:l.from.zoom+(l.to.zoom-l.from.zoom)*d,offsetX:l.from.offsetX+(l.to.offsetX-l.from.offsetX)*d,offsetY:l.from.offsetY+(l.to.offsetY-l.from.offsetY)*d,rotationDeg:l.from.rotationDeg+(l.to.rotationDeg-l.from.rotationDeg)*d}),s(),f>=1){t.animation=null,t.frame=null;return}t.frame=requestAnimationFrame(c)};t.frame=requestAnimationFrame(c)}function Ua(e){const t=Math.max(e*.5,1e-6),n=Math.max(1,e*8);return{minZoom:t,maxZoom:Math.max(t,n)}}function Na(e,t,n){const r=Ua(e);let i=t??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 ka(e,t,n,r,i){const o=e.getViewState(),s={zoom:typeof r.zoom=="number"&&Number.isFinite(r.zoom)?L(r.zoom,t,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};e.setViewState(s),i();const a=e.getViewState();return e.setViewState(o),a}function La(e,t,n,r,i){const o=Math.min(t/e.width,n/e.height),s=Number.isFinite(o)&&o>0?o:1,a=L(s,r,i),c=t/a,l=n/a;return{fitZoom:s,target:{zoom:a,offsetX:(e.width-c)*.5,offsetY:(e.height-l)*.5,rotationDeg:0}}}function za(e,t,n,r,i,o){const s=e.getViewState(),a=L(s.zoom*r,t,n);if(a===s.zoom)return null;const[c,l]=e.screenToWorld(i,o),u=e.getViewportSize(),f=i-u.width*.5,d=o-u.height*.5,g=mi(s.rotationDeg),p=Math.cos(g),S=Math.sin(g),x=f/a*p-d/a*S,M=f/a*S+d/a*p,R=c-x,V=l-M;return{zoom:a,offsetX:R-u.width/(2*a),offsetY:V-u.height/(2*a)}}class xi{constructor(t,n,r={}){w(this,"canvas");w(this,"source");w(this,"gl");w(this,"camera",new zr);w(this,"onViewStateChange");w(this,"onStats");w(this,"onTileError");w(this,"onContextLost");w(this,"onContextRestored");w(this,"resizeObserver");w(this,"tileProgram");w(this,"pointProgram");w(this,"tileScheduler");w(this,"authToken");w(this,"destroyed",!1);w(this,"contextLost",!1);w(this,"frame",null);w(this,"frameSerial",0);w(this,"interactionState",{dragging:!1,mode:"none",rotateLastAngleRad:null,pointerId:null,lastPointerX:0,lastPointerY:0});w(this,"interactionLocked",!1);w(this,"ctrlDragRotate",!0);w(this,"rotationDragSensitivityDegPerPixel",In);w(this,"maxCacheTiles");w(this,"fitZoom",1);w(this,"minZoom",1e-6);w(this,"maxZoom",1);w(this,"minZoomOverride",null);w(this,"maxZoomOverride",null);w(this,"viewTransitionDurationMs",0);w(this,"viewTransitionEasing",gi);w(this,"viewAnimationState",{animation:null,frame:null});w(this,"pointCount",0);w(this,"usePointIndices",!1);w(this,"pointBuffersDirty",!0);w(this,"pointPaletteSize",1);w(this,"pointSizeStops",vn(En));w(this,"pointStrokeScale",1);w(this,"pointInnerFillOpacity",0);w(this,"imageColorSettings",{brightness:0,contrast:0,saturation:0});w(this,"lastPointData",null);w(this,"lastPointPalette",null);w(this,"zeroFillModes",new Uint8Array(0));w(this,"cache",new Map);w(this,"boundPointerDown");w(this,"boundPointerMove");w(this,"boundPointerUp");w(this,"boundWheel");w(this,"boundDoubleClick");w(this,"boundContextMenu");w(this,"boundContextLost");w(this,"boundContextRestored");this.canvas=t,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.ctrlDragRotate=r.ctrlDragRotate??!0,this.rotationDragSensitivityDegPerPixel=typeof r.rotationDragSensitivityDegPerPixel=="number"&&Number.isFinite(r.rotationDragSensitivityDegPerPixel)?Math.max(0,r.rotationDragSensitivityDegPerPixel):In,this.pointSizeStops=Ir(r.pointSizeByZoom),this.pointStrokeScale=Pr(r.pointStrokeScale),this.pointInnerFillOpacity=Er(r.pointInnerFillOpacity),this.imageColorSettings=vr(r.imageColorSettings),this.minZoomOverride=jt(r.minZoom),this.maxZoomOverride=jt(r.maxZoom),this.viewTransitionDurationMs=xn(r.viewTransition?.duration),this.viewTransitionEasing=Sn(r.viewTransition?.easing);const i=t.getContext("webgl2",{alpha:!1,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!i)throw new Error("WebGL2 not supported");this.gl=i,this.tileProgram=_r(this.gl),this.pointProgram=Fr(this.gl),this.tileScheduler=new hi({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)=>Aa({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,c)=>{this.onTileError?.({tile:s,error:a,attemptCount:c}),console.warn("tile load failed",s.url,a)}}),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(t);const o=Sa({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(),zoomBy:(s,a,c)=>this.zoomBy(s,a,c)});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),qs(t,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 t=Na(this.fitZoom,this.minZoomOverride,this.maxZoomOverride);this.minZoom=t.minZoom,this.maxZoom=t.maxZoom}resolveTargetViewState(t){return ka(this.camera,this.minZoom,this.maxZoom,t,()=>_n(this.camera,this.source))}cancelViewAnimation(){wi(this.viewAnimationState)}startViewAnimation(t,n,r){Ba({state:this.viewAnimationState,camera:this.camera,target:t,durationMs:n,easing:r,onUpdate:()=>{_n(this.camera,this.source),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}})}getPointBufferRuntime(){return{pointCount:this.pointCount,usePointIndices:this.usePointIndices,pointBuffersDirty:this.pointBuffersDirty,lastPointData:this.lastPointData,zeroFillModes:this.zeroFillModes,lastPointPalette:this.lastPointPalette,pointPaletteSize:this.pointPaletteSize}}applyPointBufferRuntime(t){this.pointCount=t.pointCount,this.usePointIndices=t.usePointIndices,this.pointBuffersDirty=t.pointBuffersDirty,this.lastPointData=t.lastPointData,this.zeroFillModes=t.zeroFillModes,this.lastPointPalette=t.lastPointPalette,this.pointPaletteSize=t.pointPaletteSize}applyViewStateAndRender(t,n=!0){n&&this.cancelViewAnimation(),this.camera.setViewState(t),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}setAuthToken(t){this.authToken=String(t??""),this.tileScheduler.setAuthToken(this.authToken)}setZoomRange(t,n){const r=jt(t),i=jt(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();Cn(s,o)||this.applyViewStateAndRender(o)}setViewTransition(t){this.viewTransitionDurationMs=xn(t?.duration),this.viewTransitionEasing=Sn(t?.easing)}setViewState(t,n){const r=this.resolveTargetViewState(t),i=this.camera.getViewState();if(Cn(i,r))return;const o=xn(n?.duration??this.viewTransitionDurationMs),s=Sn(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}}setPointPalette(t){const n=va(this.getPointBufferRuntime(),this.gl,this.pointProgram,this.contextLost,t);this.applyPointBufferRuntime(n),!(!t||t.length===0)&&this.requestRender()}setPointData(t){const n=_a(this.getPointBufferRuntime(),this.gl,this.pointProgram,this.contextLost,t);this.applyPointBufferRuntime(n),this.requestRender()}setInteractionLock(t){const n=!!t;this.interactionLocked!==n&&(this.interactionLocked=n,n&&this.cancelDrag())}setPointSizeByZoom(t){const n=Ir(t);ra(this.pointSizeStops,n)||(this.pointSizeStops=n,this.requestRender())}setPointStrokeScale(t){const n=Pr(t);this.pointStrokeScale!==n&&(this.pointStrokeScale=n,this.requestRender())}setPointInnerFillOpacity(t){const n=Er(t);this.pointInnerFillOpacity!==n&&(this.pointInnerFillOpacity=n,this.requestRender())}setImageColorSettings(t){const n=vr(t),r=this.imageColorSettings;r.brightness===n.brightness&&r.contrast===n.contrast&&r.saturation===n.saturation||(this.imageColorSettings=n,this.requestRender())}cancelDrag(){xa(this.canvas,this.interactionState)}screenToWorld(t,n){const r=this.canvas.getBoundingClientRect(),i=t-r.left,o=n-r.top;return this.camera.screenToWorld(i,o)}worldToScreen(t,n){return this.camera.worldToScreen(t,n)}setViewCenter(t,n,r){if(!Number.isFinite(t)||!Number.isFinite(n))return;const i=this.camera.getViewState(),o=Math.max(1e-6,i.zoom),s=this.camera.getViewportSize();this.setViewState({offsetX:t-s.width/(2*o),offsetY:n-s.height/(2*o)},r)}getViewCorners(){return this.camera.getViewCorners()}resetRotation(t){const n=this.camera.getViewState();Math.abs(n.rotationDeg)<1e-6||this.setViewState({rotationDeg:0},t)}getPointSizeByZoom(){const t=Math.max(1e-6,this.camera.getViewState().zoom),n=this.source.maxTierZoom+Math.log2(t),r=ia(n,this.pointSizeStops);return L(r,Pn,$s)}fitToImage(t){const n=this.canvas.getBoundingClientRect(),r=Math.max(1,n.width||1),i=Math.max(1,n.height||1),o=La(this.source,r,i,this.minZoom,this.maxZoom);this.fitZoom=o.fitZoom,this.applyZoomBounds(),this.setViewState(o.target,t)}zoomBy(t,n,r,i){const o=za(this.camera,this.minZoom,this.maxZoom,t,n,r);o&&this.setViewState(o,i)}render(){if(this.destroyed||this.contextLost||this.gl.isContextLost())return;const t=this.onStats?fe():0;this.frameSerial+=1;const n=Fa({gl:this.gl,camera:this.camera,source:this.source,cache:this.cache,frameSerial:this.frameSerial,tileProgram:this.tileProgram,pointProgram:this.pointProgram,imageColorSettings:this.imageColorSettings,pointCount:this.pointCount,usePointIndices:this.usePointIndices,pointPaletteSize:this.pointPaletteSize,pointStrokeScale:this.pointStrokeScale,pointInnerFillOpacity:this.pointInnerFillOpacity,pointSizePx:this.getPointSizeByZoom(),tileScheduler:this.tileScheduler,getVisibleTiles:()=>ha(this.camera,this.source),getVisibleTilesForTier:r=>yi(this.camera,this.source,r),getViewBounds:()=>Dn(this.camera),intersectsBounds:da});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:fe()-t})}}requestRender(){this.frame!==null||this.destroyed||this.contextLost||this.gl.isContextLost()||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}resize(){Zs(this.canvas,this.gl,this.camera),this.requestRender()}onWebGlContextLost(t){const n=Ta({event:t,destroyed:this.destroyed,contextLost:this.contextLost,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,cache:this.cache,onContextLost:this.onContextLost});n.handled&&(this.frame=n.frame,this.contextLost=!0,this.pointBuffersDirty=!0)}onWebGlContextRestored(t){this.destroyed||(this.contextLost=!1,this.cache.clear(),this.tileProgram=_r(this.gl),this.pointProgram=Fr(this.gl),this.pointBuffersDirty=!0,this.lastPointPalette&&this.lastPointPalette.length>0&&this.setPointPalette(this.lastPointPalette),this.lastPointData?this.setPointData(this.lastPointData):this.pointCount=0,this.resize(),this.requestRender(),this.onContextRestored?.())}destroy(){const t=Ia({destroyed:this.destroyed,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),resizeObserver:this.resizeObserver,removeCanvasEventListeners:()=>Hs(this.canvas,this.getCanvasHandlers()),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,contextLost:this.contextLost,gl:this.gl,cache:this.cache,tileProgram:this.tileProgram,pointProgram:this.pointProgram});t.didDestroy&&(this.destroyed=!0,this.frame=t.frame)}}const Da=6;function Fn(e,t){return e.id??t}function Oa(e,t,n,r,i,o){const s=i-n,a=o-r,c=s*s+a*a;if(c<=1e-12){const p=e-n,S=t-r;return p*p+S*S}const l=L(((e-n)*s+(t-r)*a)/c,0,1),u=n+s*l,f=r+a*l,d=e-u,g=t-f;return d*d+g*g}function Br(e,t,n,r){for(let i=1;i<n.length;i+=1){const o=n[i-1],s=n[i];if(Oa(e,t,o[0],o[1],s[0],s[1])<=r)return!0}return!1}function Ya(e,t,n,r){if(e<n.minX-r||e>n.maxX+r||t<n.minY-r||t>n.maxY+r)return!1;const i=r*r;if(Br(e,t,n.outer,i))return!0;for(const o of n.holes)if(Br(e,t,o,i))return!0;return!1}function Xa(e,t,n,r,i,o,s){if(!e.label||!e.labelAnchor)return!1;const a=rn(n.worldToScreen(e.labelAnchor[0],e.labelAnchor[1]));if(!a)return!1;const l=kn(e.label,r)+r.paddingX*2,u=r.fontSize+r.paddingY*2,f=a[0],d=a[1]-r.offsetY,g=s?L(f,l*.5+1,i-l*.5-1):f,p=s?L(d,u*.5+1,o-u*.5-1):d,S=g-l*.5,x=g+l*.5,M=p-u*.5,R=p+u*.5;return t[0]>=S&&t[0]<=x&&t[1]>=M&&t[1]<=R}function Wa(e,t="top-center"){const n=[];for(let r=0;r<e.length;r+=1){const i=e[r],o=vt([Et(i?.coordinates)]);if(o.length===0)continue;const s=typeof i?.label=="string"?i.label.trim():"";n.push({region:i,regionIndex:r,regionId:Fn(i,r),polygons:o,label:s,labelAnchor:s?Jr(o,t):null})}return n}function Va(e,t,n,r,i,o,s,a,c,l=!0){const u=e[0],f=e[1],d=Math.max(1e-6,r.getViewState().zoom),g=Math.max(0,s),p=Da/d;for(let S=n.length-1;S>=0;S-=1){const x=n[S];for(const R of x.polygons)if(Ya(u,f,R,p))return{region:x.region,regionIndex:x.regionIndex,regionId:x.regionId};let M=Qr(i,o?.({region:x.region,regionId:x.regionId,regionIndex:x.regionIndex,zoom:d}));if(g>0&&(M={...M,offsetY:M.offsetY+g}),!!Xa(x,t,r,M,a,c,l))return{region:x.region,regionIndex:x.regionIndex,regionId:x.regionId}}return null}const Mn=[],Ga=[],qa={count:0,positions:new Float32Array(0),paletteIndices:new Uint16Array(0)},Ha=.65,Za=4,$a=180,Ur=20;function Ka(e){const t=L(e,0,1);return t*t*(3-2*t)}function ja({source:e,viewState:t,imageColorSettings:n=null,onViewStateChange:r,onStats:i,onTileError:o,onContextLost:s,onContextRestored:a,debugOverlay:c=!1,debugOverlayStyle:l,fitNonce:u=0,rotationResetNonce:f=0,authToken:d="",ctrlDragRotate:g=!0,pointData:p=null,pointPalette:S=null,pointSizeByZoom:x,pointStrokeScale:M,pointInnerFillOpacity:R,minZoom:V,maxZoom:T,viewTransition:F,roiRegions:G,roiPolygons:J,clipPointsToRois:j=!1,clipMode:Q="worker",onClipStats:se,onRoiPointGroups:pe,roiPaletteIndexToTermId:Re,interactionLock:B=!1,drawTool:k="cursor",stampOptions:O,brushOptions:U,drawFillColor:ee,regionStrokeStyle:Ne,regionStrokeHoverStyle:ue,regionStrokeActiveStyle:Oe,patchStrokeStyle:Be,resolveRegionStrokeStyle:Ye,resolveRegionLabelStyle:P,overlayShapes:C,customLayers:D,patchRegions:ae,regionLabelStyle:Z,regionLabelAnchor:le="top-center",drawAreaTooltip:de,autoLiftRegionLabelAtMaxZoom:we=!1,clampRegionLabelToViewport:te=!0,onPointerWorldMove:he,onPointHover:re,onPointClick:ne,onRegionHover:K,onRegionClick:Me,activeRegionId:H,onActiveRegionChange:xe,getCellByCoordinatesRef:be,onDrawComplete:Se,onPatchComplete:ke,overviewMapConfig:Ce,className:Ee,style:Te}){const ct=Ce?.show??!1,ut=Ce?.options,Y=h.useRef(null),X=h.useRef(null),ie=h.useRef(null),ye=h.useRef(null),bt=h.useRef(r),yt=h.useRef(i),Qe=h.useRef(o),_t=h.useRef(s),Ft=h.useRef(a),wt=h.useRef(c),[Bt,m]=h.useState(null),[y,A]=h.useState(()=>H??null),I=H!==void 0,v=I?H??null:y,[me,q]=h.useState(null),[W,oe]=h.useState(null),[ce,Ae]=h.useState(0),ge=h.useRef(null),Ie=h.useRef(null),Ve=h.useRef(null),qe=h.useRef(0),et=h.useRef({rafId:null,startMs:0,from:0,to:0}),Ut=h.useRef(0),tt=G??Mn,Mi=ae??Mn,sn=J??Ga,Nt=(D?.length??0)>0,Ci=h.useMemo(()=>({position:"relative",width:"100%",height:"100%",...Te}),[Te]),Ai=h.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)",...l}),[l]),Xe=h.useMemo(()=>tt.length>0?tt:sn.length===0?Mn:sn.map((b,E)=>({id:E,coordinates:b})),[tt,sn]),He=h.useMemo(()=>Wa(Xe,le),[Xe,le]),On=h.useMemo(()=>Ln(Z),[Z]),lt=h.useCallback(b=>{const E=L(b,0,Ur);Math.abs(qe.current-E)<1e-4||(qe.current=E,Ae(E))},[]),nt=h.useCallback(()=>{const b=et.current;b.rafId!==null&&(cancelAnimationFrame(b.rafId),b.rafId=null)},[]),an=h.useCallback(b=>{const E=L(b,0,Ur),_=et.current,N=qe.current;if(Math.abs(N-E)<1e-4){nt(),_.to=E,lt(E);return}nt(),_.startMs=performance.now(),_.from=N,_.to=E;const z=$=>{const ve=et.current,Le=Math.max(0,$-ve.startMs),ht=L(Le/$a,0,1),cn=Ka(ht),un=ve.from+(ve.to-ve.from)*cn;if(lt(un),ie.current?.(),ht>=1){ve.rafId=null,lt(ve.to);return}ve.rafId=requestAnimationFrame(z)};_.rafId=requestAnimationFrame(z)},[lt,nt]),Ze=h.useCallback(b=>{const E=X.current;if(!E||typeof b!="number"||!Number.isFinite(b)){an(0);return}const _=ei(we,b,E.getZoomRange());an(_)},[we,an]),rt=h.useMemo(()=>Xe.map(b=>Et(b.coordinates)).filter(b=>b!=null),[Xe]),[it,kt]=h.useState(p);h.useEffect(()=>{const b=++Ut.current;let E=!1;if(!j)return kt(p),()=>{E=!0};if(!p||!p.count||!p.positions||!p.paletteIndices)return kt(null),()=>{E=!0};if(rt.length===0)return kt(qa),se?.({mode:Q,durationMs:0,inputCount:p.count,outputCount:0,polygonCount:0}),()=>{E=!0};const _=(z,$)=>{if(E||b!==Ut.current)return;const ve=p.count,Le=z?.drawIndices?z.drawIndices.length:z?.count??0;kt(z),se?.({mode:$.mode,durationMs:$.durationMs,inputCount:ve,outputCount:Le,polygonCount:rt.length,usedWebGpu:$.usedWebGpu,candidateCount:$.candidateCount,bridgedToDraw:$.bridgedToDraw})};return(async()=>{if(Q==="sync"){const z=performance.now(),$=It(p,rt);_($,{mode:"sync",durationMs:performance.now()-z});return}if(Q==="hybrid-webgpu"){const z=await ai(p,rt,{bridgeToDraw:!0});_(z.data,{mode:z.meta.mode,durationMs:z.meta.durationMs,usedWebGpu:z.meta.usedWebGpu,candidateCount:z.meta.candidateCount,bridgedToDraw:z.meta.bridgedToDraw});return}try{const z=await ui(p,rt);_(z.data,{mode:z.meta.mode,durationMs:z.meta.durationMs})}catch{const z=performance.now(),$=It(p,rt);_($,{mode:"sync",durationMs:performance.now()-z})}})(),()=>{E=!0}},[j,Q,p,rt,se]);const Yn=!!(re||ne||be),[Ge,Xn]=h.useState(null);h.useEffect(()=>{if(!Yn||!it){Xn(null);return}let b=!1;return fi(it,e).then(E=>{b||Xn(E)}),()=>{b=!0}},[Yn,it,e]);const ot=h.useCallback(b=>{const E=X.current;if(!E||!Ge)return null;const _=Number(b[0]),N=Number(b[1]);if(!Number.isFinite(_)||!Number.isFinite(N))return null;const z=Math.max(1e-6,E.getViewState().zoom),$=E.getPointSizeByZoom(),Le=Math.max(Za,$*Ha)/z;if(!Number.isFinite(Le)||Le<=0)return null;const{cellSize:ht,cellOffsets:cn,cellLengths:un,pointIndices:_i,positions:$n,safeCount:Fi}=Ge,Kn=Math.floor(_/ht),jn=Math.floor(N/ht),Dt=Math.max(1,Math.ceil(Le/ht)),Bi=Le*Le;let Ot=-1,Jn=Bi,Qn=0,er=0;for(let ln=Kn-Dt;ln<=Kn+Dt;ln+=1)for(let fn=jn-Dt;fn<=jn+Dt;fn+=1){const dn=li(Ge,ln,fn);if(dn<0)continue;const tr=cn[dn],Ni=tr+un[dn];for(let hn=tr;hn<Ni;hn+=1){const Yt=_i[hn];if(Yt>=Fi)continue;const nr=$n[Yt*2],rr=$n[Yt*2+1],ir=nr-_,or=rr-N,sr=ir*ir+or*or;sr>Jn||(Jn=sr,Ot=Yt,Qn=nr,er=rr)}}if(Ot<0)return null;const Ui=Ge.ids?Number(Ge.ids[Ot]):null;return{index:Ot,id:Ui,coordinate:[_,N],pointCoordinate:[Qn,er]}},[Ge]),ft=h.useCallback((b,E)=>{if(!re)return;const _=b?.index??null,N=b?.id??null;Ie.current===_&&Ve.current===N||(Ie.current=_,Ve.current=N,re({index:_,id:N,coordinate:E,pointCoordinate:b?.pointCoordinate??null}))},[re]),Lt=h.useCallback((b,E)=>{if(!ne)return;const _=ot(b);_&&ne({..._,button:E})},[ne,ot]);h.useEffect(()=>{if(be)return be.current=ot,()=>{be.current===ot&&(be.current=null)}},[be,ot]),h.useEffect(()=>{I&&A(H??null)},[I,H]);const $e=h.useCallback(b=>{String(v)!==String(b)&&(I||A(b),xe?.(b))},[v,I,xe]);h.useEffect(()=>{bt.current=r},[r]),h.useEffect(()=>{yt.current=i},[i]),h.useEffect(()=>{Qe.current=o},[o]),h.useEffect(()=>{_t.current=s},[s]),h.useEffect(()=>{Ft.current=a},[a]),h.useEffect(()=>{wt.current=c,c||oe(null)},[c]),h.useEffect(()=>()=>{nt()},[nt]);const Wn=h.useCallback(b=>{yt.current?.(b),wt.current&&oe(b)},[]),Ri=h.useMemo(()=>W?[`tier ${W.tier} | frame ${W.frameMs?.toFixed(2)??"-"} ms | drawCalls ${W.drawCalls??"-"}`,`tiles visible ${W.visible} | rendered ${W.rendered} | fallback ${W.fallback}`,`cache size ${W.cache} | hit ${W.cacheHits??"-"} | miss ${W.cacheMisses??"-"}`,`queue inflight ${W.inflight} | queued ${W.queued??"-"} | retries ${W.retries??"-"} | failed ${W.failed??"-"} | aborted ${W.aborted??"-"}`,`points ${W.points}`].join(`
|
|
161
|
+
}`),i=Pe(e,r,"uCamera"),o=Pe(e,r,"uPointSize"),s=Pe(e,r,"uPointStrokeScale"),a=Pe(e,r,"uPointInnerFillAlpha"),c=Pe(e,r,"uPalette"),l=Pe(e,r,"uPaletteSize"),u=e.createVertexArray(),f=e.createBuffer(),d=e.createBuffer(),g=e.createBuffer(),p=e.createBuffer(),S=e.createTexture();if(!u||!f||!d||!g||!p||!S)throw new Error("point buffer allocation failed");e.bindVertexArray(u),e.bindBuffer(e.ARRAY_BUFFER,f),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const x=e.getAttribLocation(r,"aPosition");if(x<0)throw new Error("point position attribute not found");e.enableVertexAttribArray(x),e.vertexAttribPointer(x,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,d),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const M=e.getAttribLocation(r,"aTerm");if(M<0)throw new Error("point term attribute not found");e.enableVertexAttribArray(M),e.vertexAttribIPointer(M,1,e.UNSIGNED_SHORT,0,0),e.bindBuffer(e.ARRAY_BUFFER,g),e.bufferData(e.ARRAY_BUFFER,0,e.DYNAMIC_DRAW);const R=e.getAttribLocation(r,"aFillMode");if(R<0)throw new Error("point fill mode attribute not found");return e.enableVertexAttribArray(R),e.vertexAttribIPointer(R,1,e.UNSIGNED_BYTE,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,p),e.bufferData(e.ELEMENT_ARRAY_BUFFER,0,e.DYNAMIC_DRAW),e.bindVertexArray(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindTexture(e.TEXTURE_2D,S),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array([160,160,160,255])),e.bindTexture(e.TEXTURE_2D,null),{program:r,vao:u,posBuffer:f,termBuffer:d,fillModeBuffer:g,indexBuffer:p,paletteTexture:S,uCamera:i,uPointSize:o,uPointStrokeScale:s,uPointInnerFillAlpha:a,uPalette:c,uPaletteSize:l}}function wi(e){e.animation=null,e.frame!==null&&(cancelAnimationFrame(e.frame),e.frame=null)}function Ba(e){const{state:t,camera:n,target:r,durationMs:i,easing:o,onUpdate:s}=e,a=n.getViewState();wi(t),t.animation={startMs:fe(),durationMs:Math.max(0,i),from:a,to:r,easing:o};const c=()=>{const l=t.animation;if(!l)return;const u=Math.max(0,fe()-l.startMs),f=l.durationMs<=0?1:L(u/l.durationMs,0,1);let d=f;try{d=l.easing(f)}catch{d=f}if(Number.isFinite(d)||(d=f),d=L(d,0,1),n.setViewState({zoom:l.from.zoom+(l.to.zoom-l.from.zoom)*d,offsetX:l.from.offsetX+(l.to.offsetX-l.from.offsetX)*d,offsetY:l.from.offsetY+(l.to.offsetY-l.from.offsetY)*d,rotationDeg:l.from.rotationDeg+(l.to.rotationDeg-l.from.rotationDeg)*d}),s(),f>=1){t.animation=null,t.frame=null;return}t.frame=requestAnimationFrame(c)};t.frame=requestAnimationFrame(c)}function Ua(e){const t=Math.max(e*.5,1e-6),n=Math.max(1,e*8);return{minZoom:t,maxZoom:Math.max(t,n)}}function Na(e,t,n){const r=Ua(e);let i=t??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 ka(e,t,n,r,i){const o=e.getViewState(),s={zoom:typeof r.zoom=="number"&&Number.isFinite(r.zoom)?L(r.zoom,t,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};e.setViewState(s),i();const a=e.getViewState();return e.setViewState(o),a}function La(e,t,n,r,i){const o=Math.min(t/e.width,n/e.height),s=Number.isFinite(o)&&o>0?o:1,a=L(s,r,i),c=t/a,l=n/a;return{fitZoom:s,target:{zoom:a,offsetX:(e.width-c)*.5,offsetY:(e.height-l)*.5,rotationDeg:0}}}function za(e,t,n,r,i,o){const s=e.getViewState(),a=L(s.zoom*r,t,n);if(a===s.zoom)return null;const[c,l]=e.screenToWorld(i,o),u=e.getViewportSize(),f=i-u.width*.5,d=o-u.height*.5,g=mi(s.rotationDeg),p=Math.cos(g),S=Math.sin(g),x=f/a*p-d/a*S,M=f/a*S+d/a*p,R=c-x,V=l-M;return{zoom:a,offsetX:R-u.width/(2*a),offsetY:V-u.height/(2*a)}}class xi{constructor(t,n,r={}){w(this,"canvas");w(this,"source");w(this,"gl");w(this,"camera",new zr);w(this,"onViewStateChange");w(this,"onStats");w(this,"onTileError");w(this,"onContextLost");w(this,"onContextRestored");w(this,"resizeObserver");w(this,"tileProgram");w(this,"pointProgram");w(this,"tileScheduler");w(this,"authToken");w(this,"destroyed",!1);w(this,"contextLost",!1);w(this,"frame",null);w(this,"frameSerial",0);w(this,"interactionState",{dragging:!1,mode:"none",rotateLastAngleRad:null,pointerId:null,lastPointerX:0,lastPointerY:0});w(this,"interactionLocked",!1);w(this,"ctrlDragRotate",!0);w(this,"rotationDragSensitivityDegPerPixel",In);w(this,"maxCacheTiles");w(this,"fitZoom",1);w(this,"minZoom",1e-6);w(this,"maxZoom",1);w(this,"minZoomOverride",null);w(this,"maxZoomOverride",null);w(this,"viewTransitionDurationMs",0);w(this,"viewTransitionEasing",gi);w(this,"viewAnimationState",{animation:null,frame:null});w(this,"pointCount",0);w(this,"usePointIndices",!1);w(this,"pointBuffersDirty",!0);w(this,"pointPaletteSize",1);w(this,"pointSizeStops",vn(En));w(this,"pointStrokeScale",1);w(this,"pointInnerFillOpacity",0);w(this,"imageColorSettings",{brightness:0,contrast:0,saturation:0});w(this,"lastPointData",null);w(this,"lastPointPalette",null);w(this,"zeroFillModes",new Uint8Array(0));w(this,"cache",new Map);w(this,"boundPointerDown");w(this,"boundPointerMove");w(this,"boundPointerUp");w(this,"boundWheel");w(this,"boundDoubleClick");w(this,"boundContextMenu");w(this,"boundContextLost");w(this,"boundContextRestored");this.canvas=t,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.ctrlDragRotate=r.ctrlDragRotate??!0,this.rotationDragSensitivityDegPerPixel=typeof r.rotationDragSensitivityDegPerPixel=="number"&&Number.isFinite(r.rotationDragSensitivityDegPerPixel)?Math.max(0,r.rotationDragSensitivityDegPerPixel):In,this.pointSizeStops=Ir(r.pointSizeByZoom),this.pointStrokeScale=Pr(r.pointStrokeScale),this.pointInnerFillOpacity=Er(r.pointInnerFillOpacity),this.imageColorSettings=vr(r.imageColorSettings),this.minZoomOverride=jt(r.minZoom),this.maxZoomOverride=jt(r.maxZoom),this.viewTransitionDurationMs=xn(r.viewTransition?.duration),this.viewTransitionEasing=Sn(r.viewTransition?.easing);const i=t.getContext("webgl2",{alpha:!1,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!i)throw new Error("WebGL2 not supported");this.gl=i,this.tileProgram=_r(this.gl),this.pointProgram=Fr(this.gl),this.tileScheduler=new hi({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)=>Aa({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,c)=>{this.onTileError?.({tile:s,error:a,attemptCount:c}),console.warn("tile load failed",s.url,a)}}),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(t);const o=Sa({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(),zoomBy:(s,a,c)=>this.zoomBy(s,a,c)});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),qs(t,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 t=Na(this.fitZoom,this.minZoomOverride,this.maxZoomOverride);this.minZoom=t.minZoom,this.maxZoom=t.maxZoom}resolveTargetViewState(t){return ka(this.camera,this.minZoom,this.maxZoom,t,()=>_n(this.camera,this.source))}cancelViewAnimation(){wi(this.viewAnimationState)}startViewAnimation(t,n,r){Ba({state:this.viewAnimationState,camera:this.camera,target:t,durationMs:n,easing:r,onUpdate:()=>{_n(this.camera,this.source),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}})}getPointBufferRuntime(){return{pointCount:this.pointCount,usePointIndices:this.usePointIndices,pointBuffersDirty:this.pointBuffersDirty,lastPointData:this.lastPointData,zeroFillModes:this.zeroFillModes,lastPointPalette:this.lastPointPalette,pointPaletteSize:this.pointPaletteSize}}applyPointBufferRuntime(t){this.pointCount=t.pointCount,this.usePointIndices=t.usePointIndices,this.pointBuffersDirty=t.pointBuffersDirty,this.lastPointData=t.lastPointData,this.zeroFillModes=t.zeroFillModes,this.lastPointPalette=t.lastPointPalette,this.pointPaletteSize=t.pointPaletteSize}applyViewStateAndRender(t,n=!0){n&&this.cancelViewAnimation(),this.camera.setViewState(t),this.onViewStateChange?.(this.camera.getViewState()),this.requestRender()}setAuthToken(t){this.authToken=String(t??""),this.tileScheduler.setAuthToken(this.authToken)}setZoomRange(t,n){const r=jt(t),i=jt(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();Cn(s,o)||this.applyViewStateAndRender(o)}setViewTransition(t){this.viewTransitionDurationMs=xn(t?.duration),this.viewTransitionEasing=Sn(t?.easing)}setViewState(t,n){const r=this.resolveTargetViewState(t),i=this.camera.getViewState();if(Cn(i,r))return;const o=xn(n?.duration??this.viewTransitionDurationMs),s=Sn(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}}setPointPalette(t){const n=va(this.getPointBufferRuntime(),this.gl,this.pointProgram,this.contextLost,t);this.applyPointBufferRuntime(n),!(!t||t.length===0)&&this.requestRender()}setPointData(t){const n=_a(this.getPointBufferRuntime(),this.gl,this.pointProgram,this.contextLost,t);this.applyPointBufferRuntime(n),this.requestRender()}setInteractionLock(t){const n=!!t;this.interactionLocked!==n&&(this.interactionLocked=n,n&&this.cancelDrag())}setPointSizeByZoom(t){const n=Ir(t);ra(this.pointSizeStops,n)||(this.pointSizeStops=n,this.requestRender())}setPointStrokeScale(t){const n=Pr(t);this.pointStrokeScale!==n&&(this.pointStrokeScale=n,this.requestRender())}setPointInnerFillOpacity(t){const n=Er(t);this.pointInnerFillOpacity!==n&&(this.pointInnerFillOpacity=n,this.requestRender())}setImageColorSettings(t){const n=vr(t),r=this.imageColorSettings;r.brightness===n.brightness&&r.contrast===n.contrast&&r.saturation===n.saturation||(this.imageColorSettings=n,this.requestRender())}cancelDrag(){xa(this.canvas,this.interactionState)}screenToWorld(t,n){const r=this.canvas.getBoundingClientRect(),i=t-r.left,o=n-r.top;return this.camera.screenToWorld(i,o)}worldToScreen(t,n){return this.camera.worldToScreen(t,n)}setViewCenter(t,n,r){if(!Number.isFinite(t)||!Number.isFinite(n))return;const i=this.camera.getViewState(),o=Math.max(1e-6,i.zoom),s=this.camera.getViewportSize();this.setViewState({offsetX:t-s.width/(2*o),offsetY:n-s.height/(2*o)},r)}getViewCorners(){return this.camera.getViewCorners()}resetRotation(t){const n=this.camera.getViewState();Math.abs(n.rotationDeg)<1e-6||this.setViewState({rotationDeg:0},t)}getPointSizeByZoom(){const t=Math.max(1e-6,this.camera.getViewState().zoom),n=this.source.maxTierZoom+Math.log2(t),r=ia(n,this.pointSizeStops);return L(r,Pn,$s)}fitToImage(t){const n=this.canvas.getBoundingClientRect(),r=Math.max(1,n.width||1),i=Math.max(1,n.height||1),o=La(this.source,r,i,this.minZoom,this.maxZoom);this.fitZoom=o.fitZoom,this.applyZoomBounds(),this.setViewState(o.target,t)}zoomBy(t,n,r,i){const o=za(this.camera,this.minZoom,this.maxZoom,t,n,r);o&&this.setViewState(o,i)}render(){if(this.destroyed||this.contextLost||this.gl.isContextLost())return;const t=this.onStats?fe():0;this.frameSerial+=1;const n=Fa({gl:this.gl,camera:this.camera,source:this.source,cache:this.cache,frameSerial:this.frameSerial,tileProgram:this.tileProgram,pointProgram:this.pointProgram,imageColorSettings:this.imageColorSettings,pointCount:this.pointCount,usePointIndices:this.usePointIndices,pointPaletteSize:this.pointPaletteSize,pointStrokeScale:this.pointStrokeScale,pointInnerFillOpacity:this.pointInnerFillOpacity,pointSizePx:this.getPointSizeByZoom()*Math.max(1,window.devicePixelRatio||1),tileScheduler:this.tileScheduler,getVisibleTiles:()=>ha(this.camera,this.source),getVisibleTilesForTier:r=>yi(this.camera,this.source,r),getViewBounds:()=>Dn(this.camera),intersectsBounds:da});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:fe()-t})}}requestRender(){this.frame!==null||this.destroyed||this.contextLost||this.gl.isContextLost()||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}resize(){Zs(this.canvas,this.gl,this.camera),this.requestRender()}onWebGlContextLost(t){const n=Ta({event:t,destroyed:this.destroyed,contextLost:this.contextLost,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,cache:this.cache,onContextLost:this.onContextLost});n.handled&&(this.frame=n.frame,this.contextLost=!0,this.pointBuffersDirty=!0)}onWebGlContextRestored(t){this.destroyed||(this.contextLost=!1,this.cache.clear(),this.tileProgram=_r(this.gl),this.pointProgram=Fr(this.gl),this.pointBuffersDirty=!0,this.lastPointPalette&&this.lastPointPalette.length>0&&this.setPointPalette(this.lastPointPalette),this.lastPointData?this.setPointData(this.lastPointData):this.pointCount=0,this.resize(),this.requestRender(),this.onContextRestored?.())}destroy(){const t=Ia({destroyed:this.destroyed,frame:this.frame,cancelViewAnimation:()=>this.cancelViewAnimation(),resizeObserver:this.resizeObserver,removeCanvasEventListeners:()=>Hs(this.canvas,this.getCanvasHandlers()),cancelDrag:()=>this.cancelDrag(),tileScheduler:this.tileScheduler,contextLost:this.contextLost,gl:this.gl,cache:this.cache,tileProgram:this.tileProgram,pointProgram:this.pointProgram});t.didDestroy&&(this.destroyed=!0,this.frame=t.frame)}}const Da=6;function Fn(e,t){return e.id??t}function Oa(e,t,n,r,i,o){const s=i-n,a=o-r,c=s*s+a*a;if(c<=1e-12){const p=e-n,S=t-r;return p*p+S*S}const l=L(((e-n)*s+(t-r)*a)/c,0,1),u=n+s*l,f=r+a*l,d=e-u,g=t-f;return d*d+g*g}function Br(e,t,n,r){for(let i=1;i<n.length;i+=1){const o=n[i-1],s=n[i];if(Oa(e,t,o[0],o[1],s[0],s[1])<=r)return!0}return!1}function Ya(e,t,n,r){if(e<n.minX-r||e>n.maxX+r||t<n.minY-r||t>n.maxY+r)return!1;const i=r*r;if(Br(e,t,n.outer,i))return!0;for(const o of n.holes)if(Br(e,t,o,i))return!0;return!1}function Xa(e,t,n,r,i,o,s){if(!e.label||!e.labelAnchor)return!1;const a=rn(n.worldToScreen(e.labelAnchor[0],e.labelAnchor[1]));if(!a)return!1;const l=kn(e.label,r)+r.paddingX*2,u=r.fontSize+r.paddingY*2,f=a[0],d=a[1]-r.offsetY,g=s?L(f,l*.5+1,i-l*.5-1):f,p=s?L(d,u*.5+1,o-u*.5-1):d,S=g-l*.5,x=g+l*.5,M=p-u*.5,R=p+u*.5;return t[0]>=S&&t[0]<=x&&t[1]>=M&&t[1]<=R}function Wa(e,t="top-center"){const n=[];for(let r=0;r<e.length;r+=1){const i=e[r],o=vt([Et(i?.coordinates)]);if(o.length===0)continue;const s=typeof i?.label=="string"?i.label.trim():"";n.push({region:i,regionIndex:r,regionId:Fn(i,r),polygons:o,label:s,labelAnchor:s?Jr(o,t):null})}return n}function Va(e,t,n,r,i,o,s,a,c,l=!0){const u=e[0],f=e[1],d=Math.max(1e-6,r.getViewState().zoom),g=Math.max(0,s),p=Da/d;for(let S=n.length-1;S>=0;S-=1){const x=n[S];for(const R of x.polygons)if(Ya(u,f,R,p))return{region:x.region,regionIndex:x.regionIndex,regionId:x.regionId};let M=Qr(i,o?.({region:x.region,regionId:x.regionId,regionIndex:x.regionIndex,zoom:d}));if(g>0&&(M={...M,offsetY:M.offsetY+g}),!!Xa(x,t,r,M,a,c,l))return{region:x.region,regionIndex:x.regionIndex,regionId:x.regionId}}return null}const Mn=[],Ga=[],qa={count:0,positions:new Float32Array(0),paletteIndices:new Uint16Array(0)},Ha=.65,Za=4,$a=180,Ur=20;function Ka(e){const t=L(e,0,1);return t*t*(3-2*t)}function ja({source:e,viewState:t,imageColorSettings:n=null,onViewStateChange:r,onStats:i,onTileError:o,onContextLost:s,onContextRestored:a,debugOverlay:c=!1,debugOverlayStyle:l,fitNonce:u=0,rotationResetNonce:f=0,authToken:d="",ctrlDragRotate:g=!0,pointData:p=null,pointPalette:S=null,pointSizeByZoom:x,pointStrokeScale:M,pointInnerFillOpacity:R,minZoom:V,maxZoom:T,viewTransition:F,roiRegions:G,roiPolygons:J,clipPointsToRois:j=!1,clipMode:Q="worker",onClipStats:se,onRoiPointGroups:pe,roiPaletteIndexToTermId:Re,interactionLock:B=!1,drawTool:k="cursor",stampOptions:O,brushOptions:U,drawFillColor:ee,regionStrokeStyle:Ne,regionStrokeHoverStyle:ue,regionStrokeActiveStyle:Oe,patchStrokeStyle:Be,resolveRegionStrokeStyle:Ye,resolveRegionLabelStyle:P,overlayShapes:C,customLayers:D,patchRegions:ae,regionLabelStyle:Z,regionLabelAnchor:le="top-center",drawAreaTooltip:de,autoLiftRegionLabelAtMaxZoom:we=!1,clampRegionLabelToViewport:te=!0,onPointerWorldMove:he,onPointHover:re,onPointClick:ne,onRegionHover:K,onRegionClick:Me,activeRegionId:H,onActiveRegionChange:xe,getCellByCoordinatesRef:be,onDrawComplete:Se,onPatchComplete:ke,overviewMapConfig:Ce,className:Ee,style:Te}){const ct=Ce?.show??!1,ut=Ce?.options,Y=h.useRef(null),X=h.useRef(null),ie=h.useRef(null),ye=h.useRef(null),bt=h.useRef(r),yt=h.useRef(i),Qe=h.useRef(o),_t=h.useRef(s),Ft=h.useRef(a),wt=h.useRef(c),[Bt,m]=h.useState(null),[y,A]=h.useState(()=>H??null),I=H!==void 0,v=I?H??null:y,[me,q]=h.useState(null),[W,oe]=h.useState(null),[ce,Ae]=h.useState(0),ge=h.useRef(null),Ie=h.useRef(null),Ve=h.useRef(null),qe=h.useRef(0),et=h.useRef({rafId:null,startMs:0,from:0,to:0}),Ut=h.useRef(0),tt=G??Mn,Mi=ae??Mn,sn=J??Ga,Nt=(D?.length??0)>0,Ci=h.useMemo(()=>({position:"relative",width:"100%",height:"100%",...Te}),[Te]),Ai=h.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)",...l}),[l]),Xe=h.useMemo(()=>tt.length>0?tt:sn.length===0?Mn:sn.map((b,E)=>({id:E,coordinates:b})),[tt,sn]),He=h.useMemo(()=>Wa(Xe,le),[Xe,le]),On=h.useMemo(()=>Ln(Z),[Z]),lt=h.useCallback(b=>{const E=L(b,0,Ur);Math.abs(qe.current-E)<1e-4||(qe.current=E,Ae(E))},[]),nt=h.useCallback(()=>{const b=et.current;b.rafId!==null&&(cancelAnimationFrame(b.rafId),b.rafId=null)},[]),an=h.useCallback(b=>{const E=L(b,0,Ur),_=et.current,N=qe.current;if(Math.abs(N-E)<1e-4){nt(),_.to=E,lt(E);return}nt(),_.startMs=performance.now(),_.from=N,_.to=E;const z=$=>{const ve=et.current,Le=Math.max(0,$-ve.startMs),ht=L(Le/$a,0,1),cn=Ka(ht),un=ve.from+(ve.to-ve.from)*cn;if(lt(un),ie.current?.(),ht>=1){ve.rafId=null,lt(ve.to);return}ve.rafId=requestAnimationFrame(z)};_.rafId=requestAnimationFrame(z)},[lt,nt]),Ze=h.useCallback(b=>{const E=X.current;if(!E||typeof b!="number"||!Number.isFinite(b)){an(0);return}const _=ei(we,b,E.getZoomRange());an(_)},[we,an]),rt=h.useMemo(()=>Xe.map(b=>Et(b.coordinates)).filter(b=>b!=null),[Xe]),[it,kt]=h.useState(p);h.useEffect(()=>{const b=++Ut.current;let E=!1;if(!j)return kt(p),()=>{E=!0};if(!p||!p.count||!p.positions||!p.paletteIndices)return kt(null),()=>{E=!0};if(rt.length===0)return kt(qa),se?.({mode:Q,durationMs:0,inputCount:p.count,outputCount:0,polygonCount:0}),()=>{E=!0};const _=(z,$)=>{if(E||b!==Ut.current)return;const ve=p.count,Le=z?.drawIndices?z.drawIndices.length:z?.count??0;kt(z),se?.({mode:$.mode,durationMs:$.durationMs,inputCount:ve,outputCount:Le,polygonCount:rt.length,usedWebGpu:$.usedWebGpu,candidateCount:$.candidateCount,bridgedToDraw:$.bridgedToDraw})};return(async()=>{if(Q==="sync"){const z=performance.now(),$=It(p,rt);_($,{mode:"sync",durationMs:performance.now()-z});return}if(Q==="hybrid-webgpu"){const z=await ai(p,rt,{bridgeToDraw:!0});_(z.data,{mode:z.meta.mode,durationMs:z.meta.durationMs,usedWebGpu:z.meta.usedWebGpu,candidateCount:z.meta.candidateCount,bridgedToDraw:z.meta.bridgedToDraw});return}try{const z=await ui(p,rt);_(z.data,{mode:z.meta.mode,durationMs:z.meta.durationMs})}catch{const z=performance.now(),$=It(p,rt);_($,{mode:"sync",durationMs:performance.now()-z})}})(),()=>{E=!0}},[j,Q,p,rt,se]);const Yn=!!(re||ne||be),[Ge,Xn]=h.useState(null);h.useEffect(()=>{if(!Yn||!it){Xn(null);return}let b=!1;return fi(it,e).then(E=>{b||Xn(E)}),()=>{b=!0}},[Yn,it,e]);const ot=h.useCallback(b=>{const E=X.current;if(!E||!Ge)return null;const _=Number(b[0]),N=Number(b[1]);if(!Number.isFinite(_)||!Number.isFinite(N))return null;const z=Math.max(1e-6,E.getViewState().zoom),$=E.getPointSizeByZoom(),Le=Math.max(Za,$*Ha)/z;if(!Number.isFinite(Le)||Le<=0)return null;const{cellSize:ht,cellOffsets:cn,cellLengths:un,pointIndices:_i,positions:$n,safeCount:Fi}=Ge,Kn=Math.floor(_/ht),jn=Math.floor(N/ht),Dt=Math.max(1,Math.ceil(Le/ht)),Bi=Le*Le;let Ot=-1,Jn=Bi,Qn=0,er=0;for(let ln=Kn-Dt;ln<=Kn+Dt;ln+=1)for(let fn=jn-Dt;fn<=jn+Dt;fn+=1){const dn=li(Ge,ln,fn);if(dn<0)continue;const tr=cn[dn],Ni=tr+un[dn];for(let hn=tr;hn<Ni;hn+=1){const Yt=_i[hn];if(Yt>=Fi)continue;const nr=$n[Yt*2],rr=$n[Yt*2+1],ir=nr-_,or=rr-N,sr=ir*ir+or*or;sr>Jn||(Jn=sr,Ot=Yt,Qn=nr,er=rr)}}if(Ot<0)return null;const Ui=Ge.ids?Number(Ge.ids[Ot]):null;return{index:Ot,id:Ui,coordinate:[_,N],pointCoordinate:[Qn,er]}},[Ge]),ft=h.useCallback((b,E)=>{if(!re)return;const _=b?.index??null,N=b?.id??null;Ie.current===_&&Ve.current===N||(Ie.current=_,Ve.current=N,re({index:_,id:N,coordinate:E,pointCoordinate:b?.pointCoordinate??null}))},[re]),Lt=h.useCallback((b,E)=>{if(!ne)return;const _=ot(b);_&&ne({..._,button:E})},[ne,ot]);h.useEffect(()=>{if(be)return be.current=ot,()=>{be.current===ot&&(be.current=null)}},[be,ot]),h.useEffect(()=>{I&&A(H??null)},[I,H]);const $e=h.useCallback(b=>{String(v)!==String(b)&&(I||A(b),xe?.(b))},[v,I,xe]);h.useEffect(()=>{bt.current=r},[r]),h.useEffect(()=>{yt.current=i},[i]),h.useEffect(()=>{Qe.current=o},[o]),h.useEffect(()=>{_t.current=s},[s]),h.useEffect(()=>{Ft.current=a},[a]),h.useEffect(()=>{wt.current=c,c||oe(null)},[c]),h.useEffect(()=>()=>{nt()},[nt]);const Wn=h.useCallback(b=>{yt.current?.(b),wt.current&&oe(b)},[]),Ri=h.useMemo(()=>W?[`tier ${W.tier} | frame ${W.frameMs?.toFixed(2)??"-"} ms | drawCalls ${W.drawCalls??"-"}`,`tiles visible ${W.visible} | rendered ${W.rendered} | fallback ${W.fallback}`,`cache size ${W.cache} | hit ${W.cacheHits??"-"} | miss ${W.cacheMisses??"-"}`,`queue inflight ${W.inflight} | queued ${W.queued??"-"} | retries ${W.retries??"-"} | failed ${W.failed??"-"} | aborted ${W.aborted??"-"}`,`points ${W.points}`].join(`
|
|
162
162
|
`):"stats: waiting for first frame...",[W]);h.useEffect(()=>{!(v===null?!0:Xe.some((N,z)=>String(Fn(N,z))===String(v)))&&v!==null&&$e(null);const E=ge.current;!(E===null?!0:Xe.some((N,z)=>String(Fn(N,z))===String(E)))&&E!==null&&(ge.current=null,m(null),K?.({region:null,regionId:null,regionIndex:-1,coordinate:null}))},[Xe,v,K,$e]),h.useEffect(()=>{const b=Ie.current;b!==null&&(Ge&&b<Ge.safeCount||(Ie.current=null,Ve.current=null,re?.({index:null,id:null,coordinate:null,pointCoordinate:null})))},[Ge,re]);const Vn=h.useCallback(b=>{Ze(b.zoom),Nt&&q(b);const E=bt.current;E&&E(b),ie.current?.(),ye.current?.()},[Nt,Ze]);h.useEffect(()=>{const b=X.current;b&&Ze(b.getViewState().zoom)},[Ze,V,T]),h.useEffect(()=>{k!=="cursor"&&ge.current!==null&&(ge.current=null,m(null),K?.({region:null,regionId:null,regionIndex:-1,coordinate:null}))},[k,K]),h.useEffect(()=>{k!=="cursor"&&Ie.current!==null&&(Ie.current=null,Ve.current=null,re?.({index:null,id:null,coordinate:null,pointCoordinate:null}))},[k,re]);const Ke=h.useCallback((b,E)=>{const _=X.current;if(!_)return null;const N=_.screenToWorld(b,E);if(!Array.isArray(N)||N.length<2)return null;const z=Number(N[0]),$=Number(N[1]);return!Number.isFinite(z)||!Number.isFinite($)?null:[z,$]},[]),Gn=h.useCallback((b,E)=>{const _=X.current;if(!_)return null;const N=_.worldToScreen(b,E);return rn(N)},[]),zt=h.useCallback((b,E)=>{const _=Y.current;if(!_)return null;const N=_.getBoundingClientRect();if(!Number.isFinite(N.width)||!Number.isFinite(N.height)||N.width<=0||N.height<=0)return null;const z=b-N.left,$=E-N.top;return!Number.isFinite(z)||!Number.isFinite($)?null:{screenCoord:[z,$],canvasWidth:Math.max(1,N.width),canvasHeight:Math.max(1,N.height)}},[]),dt=h.useCallback((b,E,_,N)=>{const z=X.current;return z?Va(b,E,He,z,On,P,ce,_,N,te):null},[He,On,P,ce,te]),qn=h.useCallback(()=>{X.current?.requestRender(),ie.current?.(),ye.current?.()},[]),Hn=h.useMemo(()=>me??X.current?.getViewState()??null,[me]),Zn=h.useMemo(()=>{if(!e)return null;const b=Hn;return b?{source:e,viewState:b,drawTool:k,interactionLock:B,worldToScreen:Gn,screenToWorld:Ke,requestRedraw:qn}:null},[e,Hn,k,B,Gn,Ke,qn]),Ti=h.useCallback(b=>{const E=b.target===Y.current,_=Ke(b.clientX,b.clientY);if(he){const Le=!!_&&_[0]>=0&&_[1]>=0&&!!e&&_[0]<=e.width&&_[1]<=e.height;he({coordinate:_,clientX:b.clientX,clientY:b.clientY,insideImage:Le})}if(k!=="cursor")return;if(!E){ft(null,null),ge.current!==null&&(ge.current=null,m(null),K?.({region:null,regionId:null,regionIndex:-1,coordinate:null}));return}if(!_){ft(null,null);return}if(re&&ft(ot(_),_),!He.length)return;const N=zt(b.clientX,b.clientY);if(!N)return;const z=dt(_,N.screenCoord,N.canvasWidth,N.canvasHeight),$=z?.regionId??null,ve=ge.current;String(ve)!==String($)&&(ge.current=$,m($),K?.({region:z?.region??null,regionId:$,regionIndex:z?.regionIndex??-1,coordinate:_}))},[k,He,Ke,K,he,e,ft,ot,re,zt,dt]),Ii=h.useCallback(()=>{he?.({coordinate:null,clientX:-1,clientY:-1,insideImage:!1}),ft(null,null),ge.current!==null&&(ge.current=null,m(null),K?.({region:null,regionId:null,regionIndex:-1,coordinate:null}))},[K,he,ft]),Pi=h.useCallback(b=>{if(k!=="cursor"||b.target!==Y.current)return;const E=Ke(b.clientX,b.clientY);if(!E)return;if(Lt(E,b.button),!He.length){$e(null);return}const _=zt(b.clientX,b.clientY);if(!_)return;const N=dt(E,_.screenCoord,_.canvasWidth,_.canvasHeight);if(!N){$e(null);return}const z=v!==null&&String(v)===String(N.regionId)?null:N.regionId;$e(z),Me?.({region:N.region,regionId:N.regionId,regionIndex:N.regionIndex,coordinate:E})},[k,He,Ke,Me,v,$e,Lt,zt,dt]),Ei=h.useCallback(b=>{if(k!=="brush"||U?.clickSelectRoi!==!0||!He.length)return!1;const E=X.current,_=Y.current;if(!E||!_)return!1;const N=_.getBoundingClientRect();if(N.width<=0||N.height<=0)return!1;const z=rn(E.worldToScreen(b[0],b[1]));if(!z)return!1;const $=dt(b,z,N.width,N.height);if(!$)return!1;const ve=v!==null&&String(v)===String($.regionId)?null:$.regionId;return $e(ve),Me?.({region:$.region,regionId:$.regionId,regionIndex:$.regionIndex,coordinate:b}),!0},[k,U?.clickSelectRoi,He,v,$e,Me,dt]),vi=h.useCallback(b=>{if(!ne||k!=="cursor"||b.target!==Y.current)return;b.preventDefault();const E=Ke(b.clientX,b.clientY);E&&Lt(E,b.button)},[k,Ke,Lt,ne]);return h.useEffect(()=>{const b=Y.current;if(!b||!e)return;const E=new xi(b,e,{onViewStateChange:Vn,onStats:Wn,onTileError:_=>{Qe.current?.(_)},onContextLost:()=>{_t.current?.()},onContextRestored:()=>{Ft.current?.()},authToken:d,imageColorSettings:n,ctrlDragRotate:g,pointSizeByZoom:x,pointStrokeScale:M,pointInnerFillOpacity:R,minZoom:V,maxZoom:T,viewTransition:F});return X.current=E,t&&E.setViewState(t),Ze(E.getViewState().zoom),E.setInteractionLock(B),Nt&&q(E.getViewState()),()=>{nt(),lt(0),E.destroy(),X.current=null}},[e,Wn,d,g,Vn,Nt,Ze,nt,lt]),h.useEffect(()=>{const b=X.current;!b||!t||b.setViewState(t)},[t]),h.useEffect(()=>{const b=X.current;b&&b.fitToImage()},[u]),h.useEffect(()=>{const b=X.current;b&&b.resetRotation()},[f]),h.useEffect(()=>{const b=X.current;!b||!S||b.setPointPalette(S)},[S]),h.useEffect(()=>{const b=X.current;b&&b.setPointSizeByZoom(x)},[x]),h.useEffect(()=>{const b=X.current;b&&b.setPointStrokeScale(M)},[M]),h.useEffect(()=>{const b=X.current;b&&b.setPointInnerFillOpacity(R)},[R]),h.useEffect(()=>{const b=X.current;b&&(b.setZoomRange(V,T),Ze(b.getViewState().zoom))},[V,T,Ze]),h.useEffect(()=>{const b=X.current;b&&b.setViewTransition(F)},[F]),h.useEffect(()=>{const b=X.current;b&&b.setImageColorSettings(n)},[n]),h.useEffect(()=>{const b=X.current;b&&b.setPointData(it)},[it]),h.useEffect(()=>{if(!pe)return;const E=di(j?it:p,Xe,{paletteIndexToTermId:Re,includeEmptyRegions:!0});pe(E)},[pe,j,p,it,Xe,Re]),h.useEffect(()=>{const b=X.current;b&&b.setInteractionLock(B)},[B]),De.jsxs("div",{className:Ee,style:Ci,onPointerMove:Ti,onPointerLeave:Ii,onClick:Pi,onContextMenu:vi,children:[De.jsx("canvas",{ref:Y,className:"wsi-render-canvas",style:{position:"absolute",inset:0,zIndex:1,width:"100%",height:"100%",display:"block",touchAction:"none",cursor:k==="cursor"&&Bt!==null?"pointer":B?"crosshair":"grab"}}),e&&Zn&&Array.isArray(D)&&D.length>0?D.map((b,E)=>De.jsx("div",{className:b.className,style:{position:"absolute",inset:0,zIndex:b.zIndex??3,pointerEvents:b.pointerEvents??"none",...b.style},children:b.render(Zn)},b.id??E)):null,e?De.jsx(ti,{tool:k,enabled:k!=="cursor",imageWidth:e.width,imageHeight:e.height,imageMpp:e.mpp,imageZoom:e.maxTierZoom,stampOptions:O,brushOptions:U,drawFillColor:ee,projectorRef:X,onBrushTap:Ei,viewStateSignal:t,persistedRegions:Xe,patchRegions:Mi,regionStrokeStyle:Ne,regionStrokeHoverStyle:ue,regionStrokeActiveStyle:Oe,patchStrokeStyle:Be,resolveRegionStrokeStyle:Ye,resolveRegionLabelStyle:P,overlayShapes:C,hoveredRegionId:Bt,activeRegionId:v,regionLabelStyle:Z,regionLabelAnchor:le,drawAreaTooltip:de,autoLiftRegionLabelAtMaxZoom:we,clampRegionLabelToViewport:te,regionLabelAutoLiftOffsetPx:ce,invalidateRef:ie,onDrawComplete:Se,onPatchComplete:ke}):null,c?De.jsx("pre",{"data-open-plant-debug-overlay":!0,style:Ai,children:Ri}):null,e&&ct&&De.jsx(ri,{source:e,projectorRef:X,authToken:d,options:ut,invalidateRef:ye,className:Ce?.className,style:Ce?.style})]})}function Nr(e,t,n,r){return[Math.min(e,n),Math.min(t,r),Math.max(e,n),Math.max(t,r)]}function kr(e,t){return!(e[2]<t[0]||e[0]>t[2]||e[3]<t[1]||e[1]>t[3])}class Ja{constructor(t=16){w(this,"targetNodeSize");w(this,"items",[]);w(this,"globalBounds",[0,0,0,0]);w(this,"gridSize",1);w(this,"cellWidth",1);w(this,"cellHeight",1);w(this,"buckets",[]);w(this,"visited",new Uint32Array(0));w(this,"querySerial",1);const n=Number.isFinite(t)?Math.floor(t):16;this.targetNodeSize=Math.max(1,n)}load(t){if(!Array.isArray(t)||t.length===0){this.items=[],this.globalBounds=[0,0,0,0],this.gridSize=1,this.cellWidth=1,this.cellHeight=1,this.buckets=[],this.visited=new Uint32Array(0),this.querySerial=1;return}const n=[];let r=1/0,i=1/0,o=-1/0,s=-1/0;for(const u of t){if(!u||!Number.isFinite(u.minX)||!Number.isFinite(u.minY)||!Number.isFinite(u.maxX)||!Number.isFinite(u.maxY))continue;const f=Nr(u.minX,u.minY,u.maxX,u.maxY);r=Math.min(r,f[0]),i=Math.min(i,f[1]),o=Math.max(o,f[2]),s=Math.max(s,f[3]),n.push({minX:f[0],minY:f[1],maxX:f[2],maxY:f[3],value:u.value})}if(this.items=n,this.visited=new Uint32Array(n.length),this.querySerial=1,n.length===0||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(s)){this.globalBounds=[0,0,0,0],this.gridSize=1,this.cellWidth=1,this.cellHeight=1,this.buckets=[];return}this.globalBounds=[r,i,o,s],this.gridSize=Math.max(1,Math.ceil(Math.sqrt(n.length/this.targetNodeSize)));const a=Math.max(0,o-r),c=Math.max(0,s-i);this.cellWidth=a>0?a/this.gridSize:1,this.cellHeight=c>0?c/this.gridSize:1;const l=this.gridSize*this.gridSize;this.buckets=Array.from({length:l},()=>[]);for(let u=0;u<n.length;u+=1){const f=n[u],d=this.toCellX(f.minX),g=this.toCellX(f.maxX),p=this.toCellY(f.minY),S=this.toCellY(f.maxY);for(let x=p;x<=S;x+=1)for(let M=d;M<=g;M+=1)this.buckets[x*this.gridSize+M].push(u)}}search(t){if(this.items.length===0)return[];if(!Array.isArray(t)||t.length<4)return[];const n=Nr(t[0],t[1],t[2],t[3]);if(!kr(n,this.globalBounds))return[];const r=this.toCellX(n[0]),i=this.toCellX(n[2]),o=this.toCellY(n[1]),s=this.toCellY(n[3]),a=this.nextSerial(),c=[];for(let l=o;l<=s;l+=1)for(let u=r;u<=i;u+=1){const f=this.buckets[l*this.gridSize+u];if(!(!f||f.length===0))for(const d of f){if(this.visited[d]===a)continue;this.visited[d]=a;const g=this.items[d];kr(n,[g.minX,g.minY,g.maxX,g.maxY])&&c.push(g)}}return c}nextSerial(){return this.querySerial+=1,this.querySerial===4294967295&&(this.visited.fill(0),this.querySerial=1),this.querySerial}toCellX(t){const n=this.globalBounds[0],r=this.globalBounds[2];if(this.gridSize<=1||r<=n)return 0;const i=(t-n)/this.cellWidth;return!Number.isFinite(i)||i<=0?0:i>=this.gridSize-1?this.gridSize-1:Math.max(0,Math.min(this.gridSize-1,Math.floor(i)))}toCellY(t){const n=this.globalBounds[1],r=this.globalBounds[3];if(this.gridSize<=1||r<=n)return 0;const i=(t-n)/this.cellHeight;return!Number.isFinite(i)||i<=0?0:i>=this.gridSize-1?this.gridSize-1:Math.max(0,Math.min(this.gridSize-1,Math.floor(i)))}}function Qa(e){return new Ja(e)}function ec(e){return e.replace(/^\s*SRID\s*=\s*\d+\s*;\s*/i,"")}function tc(e){return e>="A"&&e<="Z"||e>="a"&&e<="z"}function nc(e){return e>="0"&&e<="9"}function Lr(e){return e==="+"||e==="-"||e==="."||nc(e)}class rc{constructor(t){w(this,"text");w(this,"index",0);this.text=ec(t.trim())}parse(){if(!this.text)return null;const t=this.readWord();if(!t)return null;const n=t.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=Si(i);return s?{type:"Polygon",coordinates:s}:null}const o=oc(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 t=this.index;for(;!this.isEof()&&tc(this.currentChar());)this.index+=1;return this.index===t?null:this.text.slice(t,this.index)}peekWord(){const t=this.index,n=this.readWord();return this.index=t,n}consumeWordIf(t){const n=this.index,r=this.readWord();return!r||r.toUpperCase()!==t.toUpperCase()?(this.index=n,!1):!0}parseNestedList(){if(this.skipWhitespace(),this.currentChar()!=="(")throw new Error("Expected '('");this.index+=1;const t=[];for(;;){this.skipWhitespace(),this.currentChar()==="("?t.push(this.parseNestedList()):t.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 t}parseCoordinateTuple(){this.skipWhitespace();const t=[];for(;;){this.skipWhitespace();const n=this.currentChar();if(!n||!Lr(n))break;const r=this.readNumber();if(r===null)break;t.push(r),this.skipWhitespace();const i=this.currentChar();if(!i||i===","||i===")")break;if(!Lr(i))throw new Error("Invalid coordinate")}if(t.length<2)throw new Error("Coordinate requires at least x y");return[t[0],t[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 ic(e){return Array.isArray(e)&&e.length>=2&&typeof e[0]=="number"&&Number.isFinite(e[0])&&typeof e[1]=="number"&&Number.isFinite(e[1])}function Si(e){if(!Array.isArray(e))return null;const t=[];for(const n of e){if(!Array.isArray(n))return null;const r=[];for(const i of n){if(!ic(i))return null;r.push([i[0],i[1]])}t.push(r)}return t}function oc(e){if(!Array.isArray(e))return null;const t=[];for(const n of e){const r=Si(n);if(!r)return null;t.push(r)}return t}function sc(e){return typeof e!="string"?null:new rc(e).parse()}exports.DEFAULT_POINT_COLOR=Un;exports.DrawLayer=ti;exports.M1TileRenderer=Dr;exports.OverviewMap=ri;exports.TileScheduler=hi;exports.TileViewerCanvas=xs;exports.WsiTileRenderer=xi;exports.WsiViewerCanvas=ja;exports.buildPointSpatialIndexAsync=fi;exports.buildTermPalette=Vi;exports.calcScaleLength=Xi;exports.calcScaleResolution=Nn;exports.clamp=L;exports.closeRing=Fe;exports.computeRoiPointGroups=di;exports.createCircle=Rn;exports.createRectangle=on;exports.createSpatialIndex=Qa;exports.filterPointDataByPolygons=It;exports.filterPointDataByPolygonsHybrid=ai;exports.filterPointDataByPolygonsInWorker=ui;exports.filterPointIndicesByPolygons=ii;exports.filterPointIndicesByPolygonsInWorker=vs;exports.getWebGpuCapabilities=Is;exports.hexToRgba=Vr;exports.isSameViewState=Cn;exports.lookupCellIndex=li;exports.normalizeImageInfo=ys;exports.parseWkt=sc;exports.prefilterPointsByBoundsWebGpu=si;exports.terminatePointHitIndexWorker=zs;exports.terminateRoiClipWorker=Es;exports.toBearerToken=Wi;exports.toRoiGeometry=Et;exports.toTileUrl=zn;
|
|
163
163
|
//# sourceMappingURL=index.cjs.map
|