@atlas-viewer/atlas 2.0.1 → 2.0.2
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/bundle/cjs/index.js +1 -1
- package/dist/bundle/cjs/index.js.map +1 -1
- package/dist/bundle/esm/index.mjs +31 -4
- package/dist/bundle/esm/index.mjs.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/types/modules/react-reconciler/hooks/use-mode.d.ts +4 -0
- package/dist/types/modules/react-reconciler/reconciler.d.ts +1 -0
- package/package.json +2 -1
package/dist/bundle/cjs/index.js
CHANGED
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
* @return {boolean} True if the event is supported.
|
|
13
13
|
* @internal
|
|
14
14
|
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
15
|
-
*/;var Wr=Dr,Ur=function(t,e){if(!jr.canUseDOM||e&&!("addEventListener"in document))return!1;var i="on"+t,n=i in document;if(!n){var s=document.createElement("div");s.setAttribute(i,"return;"),n="function"==typeof s[i]}return!n&&Br&&"wheel"===t&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n};function Hr(t){var e=0,i=0,n=0,s=0;return"detail"in t&&(i=t.detail),"wheelDelta"in t&&(i=-t.wheelDelta/120),"wheelDeltaY"in t&&(i=-t.wheelDeltaY/120),"wheelDeltaX"in t&&(e=-t.wheelDeltaX/120),"axis"in t&&t.axis===t.HORIZONTAL_AXIS&&(e=i,i=0),n=10*e,s=10*i,"deltaY"in t&&(s=t.deltaY),"deltaX"in t&&(n=t.deltaX),(n||s)&&t.deltaMode&&(1==t.deltaMode?(n*=40,s*=40):(n*=800,s*=800)),n&&!e&&(e=n<1?-1:1),s&&!i&&(i=s<1?-1:1),{spinX:e,spinY:i,pixelX:n,pixelY:s}}Hr.getEventType=function(){return Wr.firefox()?"DOMMouseScroll":Ur("wheel")?"wheel":"mousewheel"};var Vr=Hr;const Gr={zoomOutFactor:.8,zoomInFactor:1.25,maxZoomFactor:1,minZoomFactor:.05,zoomDuration:300,zoomWheelConstant:20,zoomClamp:.6,panBounceStiffness:120,panBounceDamping:15,panTimeConstant:240,panPower:.1,nudgeDistance:100,panPadding:0,devicePixelRatio:1,enableWheel:!0,enableClickToZoom:!1,onPanInSketchMode:()=>{}},Xr=(t={})=>({start:function(e){const{zoomWheelConstant:i,enableWheel:n,enableClickToZoom:s}={...Gr,...t},r={pointerStart:{x:0,y:0},isPressing:!1,mousemoveBuffer:p(5),multiTouch:{distance:0}};function o(){e.world.constraintBounds(),h=0}function a(t){t.which>1?r.isPressing=!1:"explore"===e.mode&&(t.preventDefault(),r.pointerStart.x=t.atlas.x,r.pointerStart.y=t.atlas.y,e.transitionManager.stopTransition(),r.isPressing=!0)}function l(){r.isPressing&&("explore"===e.mode&&e.world.constraintBounds(),r.isPressing=!1)}e.world.activatedEvents.push("onMouseUp","onMouseDown","onMouseMove","onTouchStart","onTouchEnd","onTouchMove","onPointerUp","onPointerDown","onPointerMove");let h=0;function c(t){if("explore"===e.mode){if(1===t.atlasTouches.length&&(t.preventDefault(),r.pointerStart.x=t.atlasTouches[0].x,r.pointerStart.y=t.atlasTouches[0].y),2===t.atlasTouches.length){t.preventDefault();const e=t.atlasTouches[0].x,i=t.atlasTouches[1].x;r.pointerStart.x=(e+i)/2;const n=t.atlasTouches[0].y,s=t.atlasTouches[1].y;r.pointerStart.y=(n+s)/2,h=C({x:t.touches[0].clientX,y:t.touches[0].clientY},{x:t.touches[1].clientX,y:t.touches[1].clientY})}e.transitionManager.stopTransition(),r.isPressing=!0}}function d(t){if(r.isPressing){const i=e.getRendererScreenPosition();if(i){const{x:n,y:s}=e.viewerToWorld(t.clientX-i.x,t.clientY-i.y);e.transitionManager.customTransition((t=>{t.from=p(e.target),t.to=b(t.from,y(r.pointerStart.x-n,r.pointerStart.y-s),r.mousemoveBuffer),t.elapsed_time=0,t.total_time=0,t.timingFunction=Hs.easeInOutExpo,t.done=!1}))}}}function u(t){"explore"===e.mode&&e.world.zoomIn(t.atlas)}function g(t){const n=1+Vr(t).spinY/i;e.world.zoomTo(n,t.atlas,!0)}e.world.addEventListener("mouseup",o),e.world.addEventListener("touchend",o),e.world.addEventListener("touchstart",c),e.world.addEventListener("mousedown",a),window.addEventListener("touchend",l),window.addEventListener("mouseup",l),window.addEventListener("mousemove",d),window.addEventListener("touchmove",(function(t){let i=null,n=null,s=0;if(r.isPressing&&2===t.touches.length){i=(t.touches[0].clientX+t.touches[1].clientX)/2;n=(t.touches[0].clientY+t.touches[1].clientY)/2,s=C({x:t.touches[0].clientX,y:t.touches[0].clientY},{x:t.touches[1].clientX,y:t.touches[1].clientY})}if(r.isPressing&&1===t.touches.length){const e=t.touches[0];i=e.clientX,n=e.clientY}if(null!==i&&null!==n){const t=e.getRendererScreenPosition();if(t){const{x:o,y:a}=e.viewerToWorld(i-t.x,n-t.y),l=s&&h?s/h:1;e.transitionManager.customTransition((t=>{t.from=p(e.target),t.to=b(t.from,f(y(r.pointerStart.x-o,r.pointerStart.y-a),w(1/l,o,a)),r.mousemoveBuffer),t.elapsed_time=0,t.total_time=0,t.timingFunction=Hs.easeInOutExpo,t.done=!1}))}h=s}})),s&&(e.world.activatedEvents.push("onClick"),e.world.addEventListener("click",u)),n&&(e.world.activatedEvents.push("onWheel"),e.world.addEventListener("wheel",g));const m=e.world.addLayoutSubscriber(((t,i)=>{if("zone-changed"===t&&e.transitionManager.constrainBounds({transition:{duration:0}}),"zoom-to"===t&&i&&e.transitionManager.zoomTo(i.factor,{origin:i.point,stream:i.stream}),"go-home"===t){const t=i.immediate?{duration:0}:void 0;e.transitionManager.goToRegion({x:(n=e.homePosition)[1],y:n[2],width:n[3]-n[1],height:n[4]-n[2]},{transition:t})}var n;if("goto-region"===t&&i){const t=i.immediate?{duration:0}:{};e.transitionManager.goToRegion(i,{transition:t})}"constrain-bounds"===t&&e.transitionManager.constrainBounds({transition:(null==i?void 0:i.immediate)?{duration:0}:void 0})}));return()=>{e.world.removeEventListener("mouseup",o),e.world.removeEventListener("touchend",o),e.world.removeEventListener("touchstart",c),e.world.removeEventListener("mousedown",a),window.removeEventListener("touchend",l),window.removeEventListener("mouseup",l),e.world.removeEventListener("mousemove",d),e.world.removeEventListener("touchmove",d),s&&e.world.removeEventListener("click",u),n&&e.world.removeEventListener("wheel",g),m()}},updatePosition(){}}),Yr=a.default.createContext("explore"),Kr=()=>e.useContext(Yr);function Qr(t,e,i){var n,s,r,o,a;function l(){var h=Date.now()-o;h<e&&h>=0?n=setTimeout(l,e-h):(n=null,i||(a=t.apply(r,s),r=s=null))}null==e&&(e=100);var h=function(){r=this,s=arguments,o=Date.now();var h=i&&!n;return n||(n=setTimeout(l,e)),h&&(a=t.apply(r,s),r=s=null),a};return h.clear=function(){n&&(clearTimeout(n),n=null)},h.flush=function(){n&&(a=t.apply(r,s),r=s=null,clearTimeout(n),n=null)},h}Qr.debounce=Qr;var qr=Qr;function Zr(t){let{debounce:i,scroll:n,polyfill:s,offsetSize:r}=void 0===t?{debounce:0,scroll:!1,offsetSize:!1}:t;const o=s||("undefined"==typeof window?class{}:window.ResizeObserver);if(!o)throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");const[a,l]=e.useState({left:0,top:0,width:0,height:0,bottom:0,right:0,x:0,y:0}),h=e.useRef({element:null,scrollContainers:null,resizeObserver:null,lastBounds:a}),c=i?"number"==typeof i?i:i.scroll:null,d=i?"number"==typeof i?i:i.resize:null,u=e.useRef(!1);e.useEffect((()=>(u.current=!0,()=>{u.current=!1})));const[p,f,g]=e.useMemo((()=>{const t=()=>{if(!h.current.element)return;const{left:t,top:e,width:i,height:n,bottom:s,right:o,x:a,y:c}=h.current.element.getBoundingClientRect(),d={left:t,top:e,width:i,height:n,bottom:s,right:o,x:a,y:c};h.current.element instanceof HTMLElement&&r&&(d.height=h.current.element.offsetHeight,d.width=h.current.element.offsetWidth),Object.freeze(d),u.current&&!eo(h.current.lastBounds,d)&&l(h.current.lastBounds=d)};return[t,d?qr(t,d):t,c?qr(t,c):t]}),[l,r,c,d]);function m(){h.current.scrollContainers&&(h.current.scrollContainers.forEach((t=>t.removeEventListener("scroll",g,!0))),h.current.scrollContainers=null),h.current.resizeObserver&&(h.current.resizeObserver.disconnect(),h.current.resizeObserver=null)}function v(){h.current.element&&(h.current.resizeObserver=new o(g),h.current.resizeObserver.observe(h.current.element),n&&h.current.scrollContainers&&h.current.scrollContainers.forEach((t=>t.addEventListener("scroll",g,{capture:!0,passive:!0}))))}var y,w,b;return y=g,w=Boolean(n),e.useEffect((()=>{if(w){const t=y;return window.addEventListener("scroll",t,{capture:!0,passive:!0}),()=>{window.removeEventListener("scroll",t,!0)}}}),[y,w]),b=f,e.useEffect((()=>{const t=b;return window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}}),[b]),e.useEffect((()=>{m(),v()}),[n,g,f]),e.useEffect((()=>m),[]),[t=>{t&&t!==h.current.element&&(m(),h.current.element=t,h.current.scrollContainers=Jr(t),v())},a,p]}function Jr(t){const e=[];if(!t||t===document.body)return e;const{overflow:i,overflowX:n,overflowY:s}=window.getComputedStyle(t);return[i,n,s].some((t=>"auto"===t||"scroll"===t))&&e.push(t),[...e,...Jr(t.parentElement)]}const to=["x","y","top","bottom","left","right","width","height"],eo=(t,e)=>to.every((i=>t[i]===e[i])),io=a.default.createContext(null),no=a.default.createContext(null);let so;if("object"==typeof performance&&"function"==typeof performance.now){const t=performance;so=()=>t.now()}else{const t=Date,e=t.now();so=()=>t.now()-e}function ro(t,e){t&&t.appendChild&&e&&t.appendChild(e)}function oo(t,e){t&&t.removeChild&&e&&t.removeChild(e)}function ao(t,e,i){t&&t instanceof Gs&&(t=t.world),t&&t.insertBefore&&t.insertBefore(e,i)}function lo(t,e,i){if(i&&(t.applyProps&&t.applyProps(i),t instanceof E))for(const n of h){const s=n.slice(2).toLowerCase();i[n]!==e[n]&&(e[n]&&t.removeEventListener(s,e[n]),t.addEventListener(s,i[n]))}}function ho(t,e){const i=Object.keys(e);let n=!1;for(const s of i)if(-1!==h.indexOf(s)){const e=d[s];if(e){if(-1!==t.activatedEvents.indexOf(e))continue;n=!0,t.activatedEvents.push(e)}}n&&t.triggerEventActivation()}const co=new Map,uo={};const po=l.default({unstable_now:so,now:so,createInstance:function(t,{args:e=[],...i},n,s,r){if(!(n instanceof Gs)&&r){const t=e=>e.return?t(e.return):e.stateNode&&e.stateNode.containerInfo;n=t(r)}let o,a=n.world;switch(t){case"world":o=ks.withProps({width:i.width,height:i.height,viewingDirection:"left-to-right"}),o.activatedEvents=a.activatedEvents,o.eventHandlers=a.eventHandlers,o.subscriptions=a.subscriptions,o.triggerEventActivation(),a=o;break;case"box":o=new Is;break;case"shape":o=new pr;break;case"worldObject":case"world-object":o=new Cs;break;case"worldImage":case"world-image":o=new S;break;case"texture":o=new _;break;case"compositeImage":case"composite-image":o=new _s({id:i.id,width:i.width,height:i.height,images:[]});break;case"tiledImage":case"tiled-image":o=Es.fromTile(i.uri,i.display,i.tile,i.scaleFactor,void 0,i.format);break;case"paragraph":o=new Ls,o.text=i.children;break;default:return}return ho(a,i),lo(o,{},i),o},removeChild:oo,appendChild:ro,appendInitialChild:ro,insertBefore:ao,warnsIfNotActing:!0,supportsMutation:!0,isPrimaryRenderer:!1,scheduleTimeout:"undefined"!=typeof setTimeout?setTimeout:void 0,cancelTimeout:"undefined"!=typeof clearTimeout?clearTimeout:void 0,setTimeout:"undefined"!=typeof setTimeout?setTimeout:void 0,clearTimeout:"undefined"!=typeof clearTimeout?clearTimeout:void 0,noTimeout:-1,appendChildToContainer:function(t,e){if(e instanceof ks)t.world=e;else if(e instanceof Cs)t.world.appendChild(e);else if(e)throw new Error("Invalid root")},removeChildFromContainer:function(t,e){return oo(t.world,e)},createTextInstance(){},insertInContainerBefore:function(t,e,i){return ao(t.world,e,i)},prepareUpdate:(t,e,i,n,s)=>(ho(s.world,n),n),commitUpdate(t,e,i,n,s,r){t.applyProps&&e&&lo(t,n,e)},finalizeInitialChildren:t=>null==t?void 0:t.__handlers,getChildHostContext:()=>uo,getRootHostContext:()=>uo,prepareForCommit:t=>(t.isCommitting=!0,null),preparePortalMount(){},hideInstance(t){t&&t.points&&(t.points[0]=0)},unhideInstance(t,e){t&&t.points&&(t.points[0]=1)},getPublicInstance:t=>t,hideTextInstance(){throw new Error("Text is not allowed in the react-three-fibre tree. You may have extraneous whitespace between components.")},resetAfterCommit(t){t.isCommitting=!1,t.pendingUpdate=!0,t.world&&t.world.needsRecalculate&&(t.world.recalculateWorldSize(),t.world.triggerRepaint())},shouldSetTextContent:()=>!1,clearContainer:()=>!1});function fo(t,e){const i=co.get(t);i&&po.updateContainer(null,i,null,(()=>{co.delete(t),e&&e(t)}))}po.injectIntoDevTools({bundleType:0,version:e.version,rendererPackageName:"@atlas-viewer/atlas"});const go={render(t,e){const i=co.get(e);if(i)po.updateContainer(t,i,null,(()=>{}));else{const i=po.createContainer(e,0,null,!1,null,"",(()=>{}),null);po.updateContainer(t,i,null,null),co.set(e,i)}}},mo=a.default.memo((({children:t,setIsReady:i,onCreated:n,bounds:s,preset:r,mode:o="explore"})=>{const l=e.useCallback((function(t){const s=()=>{i(!0)};return e.useEffect((()=>{if(!r)return()=>{};{r.runtime.goHome();const t=n&&n(r);t&&t.then?t.then(s):s()}}),[]),t.children}),[r]);return e.useLayoutEffect((()=>{if(r){const e=r.runtime;o!==e.mode&&(e.mode=o),go.render(a.default.createElement(a.default.StrictMode,null,a.default.createElement(l,null,a.default.createElement(no.Provider,{value:s},a.default.createElement(Yr.Provider,{value:o},a.default.createElement(io.Provider,{value:r},t))))),e)}}),[r,o,t]),null}));class vo{constructor(t,e){this.fragmentShaderSource="\n precision mediump float;\n\n uniform sampler2D u_image;\n varying vec2 v_texCoord;\n\n void main() {\n gl_FragColor = texture2D(u_image, v_texCoord);\n }\n ",this.vertexShaderSource="\n attribute vec2 a_position;\n uniform vec2 u_resolution;\n varying vec4 v_color;\n uniform sampler2D u_texture;\n\n attribute vec2 a_texCoord;\n varying vec2 v_texCoord;\n\n void main() {\n\n // convert the position from pixels to 0.0 to 1.0\n vec2 zeroToOne = a_position / u_resolution;\n\n // convert from 0->1 to 0->2\n vec2 zeroToTwo = zeroToOne * 2.0;\n\n // convert from 0->2 to -1->+1 (clip space)\n vec2 clipSpace = zeroToTwo - 1.0;\n\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n \n v_texCoord = a_texCoord;\n }\n ",this.lastResize=0,this.lastKnownScale=1,this.canvas=t,this.rendererPosition=t.getBoundingClientRect(),this.gl=t.getContext("webgl2"),this.fragmentShader=this.createShader(this.gl.FRAGMENT_SHADER,this.fragmentShaderSource),this.vertexShader=this.createShader(this.gl.VERTEX_SHADER,this.vertexShaderSource),this.program=this.createProgram(this.vertexShader,this.fragmentShader),this.dpi=(null==e?void 0:e.dpi)||1,this.attributes={position:this.gl.getAttribLocation(this.program,"a_position"),texCoord:this.gl.getAttribLocation(this.program,"a_texCoord")},this.uniforms={resolution:this.gl.getUniformLocation(this.program,"u_resolution"),texture:this.gl.getUniformLocation(this.program,"u_texture")},this.buffers={position:this.createArrayBuffer(),texCoord:this.createArrayBuffer(new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]))},this.rectBuffer=new Float32Array(12),this.resize(),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.enableVertexAttribArray(this.attributes.position)}resize(){this.resizeCanvasToDisplaySize(),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.rendererPosition=this.canvas.getBoundingClientRect()}isReady(){return!0}beforeFrame(t,e,i){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.vertexAttribPointer(this.attributes.position,2,this.gl.FLOAT,!1,0,0),this.gl.uniform2f(this.uniforms.resolution,this.gl.canvas.width,this.gl.canvas.height),this.lastResize>1e3&&(this.lastResize=0,this.resizeCanvasToDisplaySize()),this.lastResize+=e}prepareLayer(t){t.__host&&t.__host.webgl||((t instanceof S||t instanceof Es)&&this.createImageHost(t),t instanceof _&&this.createTextureHost(t))}createTextureHost(t){t.__host=t.__host?t.__host:{};const e=this.gl,i=this.gl.createTexture();let n;if(e.bindTexture(e.TEXTURE_2D,i),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),t instanceof _){const i=t.getTexture();i.source&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i.source),n=i}e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),t.__host.webgl={height:t.height,width:t.width,texture:i,lastImage:n}}createImageHost(t){const e=[...new Array(t.points.length/5)];t.__host=t.__host?t.__host:{},t.__host.webgl={height:t.height,width:t.width,textures:e,loading:[],loaded:[],lastLevelRendered:-1,onLoad:(e,i)=>{const n=this.gl,s=this.gl.createTexture();n.bindTexture(n.TEXTURE_2D,s),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),t.__host.webgl.textures[e]=s,t.__host.webgl.loaded.push(e)}}}paint(t,e,i,n,s,r){if("spacial-content"===t.type&&t.__host&&t.__host.webgl){if(t.getTexture){const e=null==t?void 0:t.getTexture();if(e&&t.__host.webgl.lastImage!==e.hash&&e.source&&!t.__host.webgl.error)try{const i=0,n=this.gl.RGBA,s=this.gl.RGBA,r=this.gl.UNSIGNED_BYTE;this.gl.bindTexture(this.gl.TEXTURE_2D,t.__host.webgl.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,i,n,s,r,e.source),t.__host.webgl.lastImage=e.hash}catch(o){t.__host.webgl.error=o}}if(t.__host.webgl.loading&&-1===t.__host.webgl.loading.indexOf(e)&&t.getImageUrl){t.__host.webgl.loading.push(e);const i=document.createElement("img");i.decoding="async",i.crossOrigin="anonymous",i.src=t.getImageUrl(e),i.onload=()=>(i.onload=null,t.__host.webgl.onLoad(e,i))}const a=t.__host.webgl.texture?t.__host.webgl.texture:t.__host.webgl.textures[e];a&&(this.gl.enableVertexAttribArray(this.attributes.texCoord),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.texCoord),this.gl.enableVertexAttribArray(this.attributes.texCoord),this.gl.vertexAttribPointer(this.attributes.texCoord,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.position),this.gl.enableVertexAttribArray(this.attributes.position),this.gl.vertexAttribPointer(this.attributes.position,2,this.gl.FLOAT,!1,0,0),this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.uniforms.texture,0),this.setRectangle(i,n,s,r),this.gl.drawArrays(this.gl.TRIANGLES,0,6))}}afterPaintLayer(t,e){}pendingUpdate(){return!0}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}afterFrame(){}getScale(t,e,i){if(Number.isNaN(t)||Number.isNaN(e))return this.lastKnownScale;const n=this.getCanvasDims(),s=n.width/t,r=n.height/e,o=(s<r?r:s)*(i&&this.dpi||1);return Number.isNaN(o)||(this.lastKnownScale=o),this.lastKnownScale}getCanvasDims(){return{width:this.canvas.width/this.dpi,height:this.canvas.height/this.dpi}}getViewportBounds(t,e,i){return null}createShader(t,e){const i=this.gl.createShader(t);if(i){this.gl.shaderSource(i,e),this.gl.compileShader(i);if(this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS))return i;const t=this.gl.getShaderInfoLog(i);if(this.gl.deleteShader(i),t)throw new Error(t)}throw new Error("Invalid shader")}createProgram(t,e){const i=this.gl.createProgram();if(i){this.gl.attachShader(i,t),this.gl.attachShader(i,e),this.gl.linkProgram(i);if(this.gl.getProgramParameter(i,this.gl.LINK_STATUS))return i;const n=this.gl.getProgramInfoLog(i);if(this.gl.deleteProgram(i),n)throw new Error(n)}throw new Error("Invalid program")}resizeCanvasToDisplaySize(){const t=this.gl.canvas,e=t.clientWidth,i=t.clientHeight,n=t.width!==e||t.height!==i;return n&&(t.width=e,t.height=i),n}createArrayBuffer(t){const e=this.gl.createBuffer();if(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e),t&&this.gl.bufferData(this.gl.ARRAY_BUFFER,t,this.gl.STATIC_DRAW),!e)throw new Error("Cannot create buffer");return e}setRectangle(t,e,i,n){this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getRectangle(t,e,i,n),this.gl.STATIC_DRAW)}getRectangle(t,e,i,n){const s=t,r=t+i,o=e,a=e+n;return this.rectBuffer.set([s,o,r,o,s,a,s,a,r,o,r,a]),this.rectBuffer}getRendererScreenPosition(){return this.rendererPosition}finishLayer(){}reset(){}}function yo(t,e){const i=e?t:JSON.stringify(t);let n=5381,s=i.length;for(;s;)n=33*n^i.charCodeAt(--s);const r=(n>>>0).toString(16);return r.length%2?"0"+r:r}class wo{constructor(t){this.sheetPrefix=(null==t?void 0:t.sheetPrefix)||"a-",this.$element=document.createElement("style"),this.stylesheetClasses=[],this.activeStylesheetClasses=[],this.sheetsDidUpdate=!1,this.stylesheetEntries={}}getElement(){return this.$element}addStylesheet(t){const e=t.replace(/\s\s+/g," ").replace(/: /g,":").replace(/; /g,";").trim(),i=this.sheetPrefix+yo(e,!0);return-1!==this.stylesheetClasses.indexOf(i)||(this.stylesheetClasses.push(i),this.activeStylesheetClasses.push(i),this.stylesheetEntries[i]=e,this.sheetsDidUpdate=!0),i}removeStylesheet(t){const e=this.sheetPrefix+yo(t,!0);this.stylesheetClasses.indexOf(e)&&(this.stylesheetClasses=this.stylesheetClasses.filter((t=>t!==e))),this.sheetsDidUpdate=!0}clearClasses(){this.activeStylesheetClasses=[]}didUpdateActive(){if(this.activeStylesheetClasses.length){for(const t of this.activeStylesheetClasses)if(-1===this.stylesheetClasses.indexOf(t))return!0;for(const t of this.stylesheetClasses)if(-1===this.activeStylesheetClasses.indexOf(t))return!0}return!1}updateSheet(){(this.sheetsDidUpdate||this.didUpdateActive())&&(this.$element.innerText=this.activeStylesheetClasses.map((t=>`.${t}{${this.stylesheetEntries[t]}}`)).join(""),this.sheetsDidUpdate=!1,this.stylesheetClasses=[...this.activeStylesheetClasses])}}class bo{constructor(t,e){this.visible=[],this.previousVisible=[],this.htmlIds=[],this.firstMeaningfulPaint=!1,this.paintTx=1,this.zIndex=0,this.htmlContainer=t,this.htmlContainer.innerHTML="",this.rendererPosition=this.htmlContainer.getBoundingClientRect(),this.options={triggerResize:()=>{},box:!1,text:!1,sheetPrefix:"",inlineStyles:!1,background:"",...e||{}},this.stylesheet=new wo({sheetPrefix:this.options.sheetPrefix}),this.options.inlineStyles||this.htmlContainer.appendChild(this.stylesheet.getElement()),this.options.background&&this.htmlContainer.classList.add(this.stylesheet.addStylesheet(`\n background: ${this.options.background};\n `)),this.classes={hostClassName:this.stylesheet.addStylesheet("\n position: absolute;\n transform-origin: 0px 0px;\n "),interactive:this.stylesheet.addStylesheet("pointer-events: all"),nonInteractive:this.stylesheet.addStylesheet("pointer-events: none")},this.stylesheet.updateSheet()}createHtmlHost(t){if(this.htmlContainer&&(this.options.box||t.props.className||t.props.html||t.props.href)){const e=document.createElement(t.props.href?"a":"div");if(t.props.href){e.style.display="block",e.href=t.props.href;const i=t.props.hrefTarget||"_blank";e.target=i,"_self"!==i&&(e.rel="noopener noreferrer")}e.title=t.props.title||"",this.options.inlineStyles?(e.style.display="block",e.style.position="absolute",e.style.overflow="hidden",e.style.transformOrigin="0px 0px"):e.classList.add(this.classes.hostClassName),t.__host={element:e,revision:null,relative:!1},this.updateHtmlHost(t,t.width,t.height),t.__onCreate&&t.__onCreate()}}triggerResize(){this.options.triggerResize()}updateHtmlHost(t,e,i){if(t.__revision!==t.__host.revision){const n=t.__host.element,s=[this.classes.hostClassName];if(t.props.interactive?this.options.inlineStyles?n.style.pointerEvents="all":s.push(this.classes.interactive):this.options.inlineStyles?n.style.pointerEvents="none":s.push(this.classes.nonInteractive),t.props.href){n.style.display="block",n.href=t.props.href;const e=t.props.hrefTarget||"_blank";n.target=e,n.rel="_self"!==e?"noopener noreferrer":""}else n.href&&n.removeAttribute("href");t.props.title&&(n.title=t.props.title||""),t.props.className&&(s.push(t.props.className),t.hovering&&s.push(`${t.props.className}--hover`),t.pressing&&s.push(`${t.props.className}--active`)),t.props.relativeStyle?(n.style.width=`${e||t.width}px`,n.style.height=`${i||t.height}px`):(n.style.width=`${t.width}px`,n.style.height=`${t.height}px`);if(t.props.style)return void Object.assign(n.style,t.props.style||{},t.hovering&&t.props.hoverStyles||{},t.pressing&&t.props.pressStyles||{});if(this.options.text&&t instanceof Ls){t.text&&(n.innerText=t.text),t.backgroundColor&&(n.style.backgroundColor=t.backgroundColor),t.color&&(n.style.color=t.color),t.props.font&&(n.style.font=t.props.font),t.props.textAlign&&(n.style.textAlign=t.props.textAlign),t.__host.revision=t.__revision;const e=s.join(" ");n.className=e,n.part=e}t instanceof Is&&(this.options.box||t.props.className||t.props.html)&&(t.props.backgroundColor&&(n.style.backgroundColor=t.props.backgroundColor),t.props.border!==n.style.border&&(n.style.border=t.props.border));const r=s.join(" ");n.className=r,n.part=r}}afterFrame(t,e,i){this.stylesheet.updateSheet();for(const n of this.previousVisible)-1===this.visible.indexOf(n)&&this.htmlContainer&&n.__id&&-1!==this.htmlIds.indexOf(n.__id)&&this.htmlContainer.removeChild(n.__host.element);this.previousVisible=this.visible}afterPaintLayer(t,e){}beforeFrame(t,e,i){this.stylesheet.clearClasses(),this.paintTx++,this.zIndex=0,this.visible=[]}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}getScale(t,e){const i=this.rendererPosition.width/t,n=this.rendererPosition.height/e;return i<n?n:i}getViewportBounds(t,e,i){return null}isReady(){return!1}paint(t,e,i,n,s,r){if(this.zIndex++,(this.options.text&&t instanceof Ls||t instanceof Is&&(this.options.box||t.props.className||t.props.html))&&t.__host.tx!==this.paintTx&&(this.visible.push(t),t.__host.tx=this.paintTx,this.htmlContainer)){this.updateHtmlHost(t,s,r);const e=s/t.width,o=t.__host.element;o.style.zIndex=`${this.zIndex}`,t.props.relativeStyle?o.style.transform=`translate(${Math.round(i)}px, ${Math.round(n)}px)`:o.style.transform=`translate(${Math.round(i)}px, ${Math.round(n)}px) scale(${e})`,-1===this.previousVisible.indexOf(t)&&this.htmlContainer.appendChild(o),-1===this.htmlIds.indexOf(t.__id)&&this.htmlIds.push(t.__id)}}pendingUpdate(){return!1}prepareLayer(t){t.__host||(t instanceof Ls||t instanceof Is)&&this.createHtmlHost(t)}resize(t,e){void 0!==t&&void 0!==e&&(this.htmlContainer.style.width=`${t}px`,this.htmlContainer.style.height=`${e}px`),this.rendererPosition=this.htmlContainer.getBoundingClientRect()}getRendererScreenPosition(){return this.rendererPosition}finishLayer(){}reset(){}}const xo=class{constructor(t,e,i){this.activatedEvents=[],this.eventHandlers=[],this.pointerMoveEvent=void 0,this.pointerEventState={isClicking:!1,isDragging:!1,isPressed:!1,mousedOver:[],itemsBeingDragged:[],mouseDownStart:{x:0,y:0},lastTouches:[]},this._realPointerMove=t=>{this.pointerMoveEvent=t},this.onWheelEvent=t=>{t.preventDefault(),this.onPointerEvent(t)},this.onTouchEvent=t=>{const e=d[t.type],i=[],n=t.touches.length;for(let s=0;s<n;s++){const e=t.touches.item(s);if(!e)continue;const{x:n,y:r}=this.runtime.viewerToWorld(e.clientX-this.bounds.left,e.clientY-this.bounds.top),o={id:e.identifier,x:n,y:r};i.push(o)}i.length&&this.assignToEvent(t,i[0].x,i[0].y),"onTouchEnd"!==e?(this.pointerEventState.lastTouches=i,t.atlasTouches=i,this.runtime.world.propagateTouchEvent(e,t,i)):(t.atlasTouches=[],this.runtime.world.propagateTouchEvent(e,t,this.pointerEventState.lastTouches),this.pointerEventState.lastTouches=[])},this.onPointerEvent=t=>{const e=d[t.type];if(e&&-1!==this.runtime.world.activatedEvents.indexOf(e)){const{x:i,y:n}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);this.assignToEvent(t,i,n),this.runtime.world.propagatePointerEvent(e,t,i,n)}},this.onPointerDown=t=>{this.pointerEventState.isPressed=!0,this.pointerEventState.isClicking=!0,this.pointerEventState.mouseDownStart.x=t.clientX,this.pointerEventState.mouseDownStart.y=t.clientY,setTimeout((()=>{this.runtime&&(this.pointerEventState.isClicking=!1)}),250),setTimeout((()=>{if(this.runtime&&this.pointerEventState.isPressed&&!this.pointerEventState.isDragging){const e=this.runtime.viewerToWorld(this.pointerEventState.mouseDownStart.x-this.bounds.left,this.pointerEventState.mouseDownStart.y-this.bounds.top);this.pointerEventState.isDragging=!0,this.pointerEventState.itemsBeingDragged=this.runtime.world.propagatePointerEvent("onDragStart",t,e.x,e.y)}}),800),this.onPointerEvent(t)},this.onPointerUp=t=>{if(this.pointerEventState.isClicking){const{x:e,y:i}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);this.assignToEvent(t,e,i),this.runtime.world.propagatePointerEvent("onClick",t,e,i)}if(this.pointerEventState.isDragging){for(const e of this.pointerEventState.itemsBeingDragged)e.dispatchEvent("onDragEnd",t);this.pointerEventState.isDragging=!1}this.pointerEventState.isClicking=!1,this.pointerEventState.isPressed=!1,this.pointerEventState.itemsBeingDragged=[],this.onPointerEvent(t)},this.onPointerMove=t=>{this.pointerMoveEvent=void 0;const{x:e,y:i}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);if(Number.isNaN(e)||Number.isNaN(i))return;this.assignToEvent(t,e,i),this.runtime.world.propagatePointerEvent("onPointerMove",t,e,i);const n=this.runtime.world.propagatePointerEvent("onMouseMove",t,e,i),s=[],r=[];for(const o of n)s.push(o.id),r.push(o),-1===this.pointerEventState.mousedOver.indexOf(o)&&(o.dispatchEvent("onMouseEnter",t),o.dispatchEvent("onPointerEnter",t),o.dispatchEvent("onMouseOver",t),o.dispatchEvent("onPointerOver",t));for(const o of this.pointerEventState.mousedOver)-1===s.indexOf(o.id)&&(o.dispatchEvent("onMouseLeave",t),o.dispatchEvent("onPointerLeave",t),o.dispatchEvent("onMouseOut",t),o.dispatchEvent("onPointerOut",t));if(this.pointerEventState.isDragging)for(const o of this.pointerEventState.itemsBeingDragged)o.dispatchEvent("onDrag",t);if(this.pointerEventState.isPressed&&!this.pointerEventState.isDragging&&C(this.pointerEventState.mouseDownStart,{x:t.clientX,y:t.clientY})>50){const e=this.runtime.viewerToWorld(this.pointerEventState.mouseDownStart.x-this.bounds.left,this.pointerEventState.mouseDownStart.y-this.bounds.top);this.pointerEventState.isDragging=!0,this.pointerEventState.itemsBeingDragged=this.runtime.world.propagatePointerEvent("onDragStart",{...t,atlas:{x:e.x,y:e.y}},e.x,e.y)}this.pointerEventState.mousedOver=r},this.element=t,this.runtime=e,this.unsubscribe=e.world.addLayoutSubscriber(this.layoutSubscriber.bind(this)),this.bounds=t.getBoundingClientRect(),this.options={simulationRate:0,...i||{}};let n=0;e.registerHook("useFrame",(t=>{n+=t,n>this.options.simulationRate&&this.pointerMoveEvent&&(n=0,e.updateNextFrame())})),e.registerHook("useBeforeFrame",(()=>{this.pointerMoveEvent&&this.onPointerMove(this.pointerMoveEvent)})),this.activateEvents()}updateBounds(){this.bounds=this.element.getBoundingClientRect(),this.runtime.updateRendererScreenPosition()}layoutSubscriber(t){"event-activation"===t&&this.activateEvents()}assignToEvent(t,e,i){xo.eventPool.atlas.x=e,xo.eventPool.atlas.y=i,t.atlas=xo.eventPool.atlas}activateEvents(){this.element.addEventListener("pointermove",this._realPointerMove),this.element.addEventListener("pointerup",this.onPointerUp),this.element.addEventListener("pointerdown",this.onPointerDown),this.element.addEventListener("mousedown",this.onPointerEvent),this.element.addEventListener("mouseup",this.onPointerEvent),this.element.addEventListener("pointercancel",this.onPointerEvent),this.element.addEventListener("wheel",this.onWheelEvent),this.element.addEventListener("touchstart",this.onTouchEvent),this.element.addEventListener("touchcancel",this.onTouchEvent),this.element.addEventListener("touchend",this.onTouchEvent),this.element.addEventListener("touchmove",this.onTouchEvent)}normalizeEventName(t){return t.startsWith("on")?t.slice(2).toLowerCase():t.toLowerCase()}stop(){this.unsubscribe();for(const[t,e]of this.eventHandlers)this.element.removeEventListener(this.normalizeEventName(t),e)}};let Eo=xo;function So({interactive:t=!0,viewport:e,forceRefresh:i,canvasElement:n,overlayElement:s,controllerConfig:r,unstable_webglRenderer:o,dpi:a,debug:l,canvasBox:h=!0,polygon:c=!0,navigatorElement:d,background:u,runtimeOptions:p}){if(!n)throw new Error("Invalid container");n.style.userSelect="none";const f=t?Xr({minZoomFactor:.5,maxZoomFactor:3,enableClickToZoom:!1,...r||{}}):void 0,g=new yr([o?new vo(n,{dpi:a}):new vr(n,{dpi:a,debug:l,box:h,polygon:c,background:u}),s?new bo(s,{box:o||!h,text:!0,triggerResize:i}):void 0,d?new wr(d):void 0]),m=new Gs(g,new ks(1024,1024),e,f?[f]:[],p),v=new Eo(n,m);return{name:"default-preset",em:v,runtime:m,renderer:g,controller:f,canvas:n,navigator:d,unmount(){fo(m),m.stopControllers(),m.stop(),m.reset(),v&&v.stop()}}}Eo.eventPool={atlas:{x:0,y:0}};class _o{constructor(t,e){this.pending=!0,this.zIndex=0,this.lastKnownScale=1,this.currentlyVisible=[],this.previouslyVisible=[],this.container=t,this.rendererPosition=t.getBoundingClientRect();const{width:i,height:n}=this.rendererPosition;this.width=i,this.height=n,this.options={addPart:!1,setDraggableFalse:!1,imageClass:"",widthStylesheet:!1,sheetPrefix:"position-",background:"#000",...e||{}},this.stylesheet=new wo({sheetPrefix:this.options.sheetPrefix}),this.container.classList.add(this.stylesheet.addStylesheet(`\n background: ${this.options.background};\n `)),this.options.widthStylesheet&&this.container.appendChild(this.stylesheet.getElement())}isReady(){return!0}resize(){this.rendererPosition=this.container.getBoundingClientRect(),this.width=this.rendererPosition.width,this.height=this.rendererPosition.height}getRendererScreenPosition(){return this.rendererPosition}afterFrame(t,e,i){this.stylesheet.updateSheet();for(const n of this.previouslyVisible)-1===this.currentlyVisible.indexOf(n)&&this.container.removeChild(n);for(const n of this.currentlyVisible)-1===this.previouslyVisible.indexOf(n)&&this.container.appendChild(n);this.previouslyVisible=this.currentlyVisible,this.currentlyVisible=[]}afterPaintLayer(t,e){}beforeFrame(t,e,i){this.stylesheet.clearClasses(),this.zIndex=0}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}getScale(t,e){if(Number.isNaN(t)||Number.isNaN(e))return this.lastKnownScale;const i=this.width/t,n=this.height/e,s=i<n?n:i;return Number.isNaN(s)||(this.lastKnownScale=s),this.lastKnownScale}getViewportBounds(t,e,i){return null}createImage(){const t=document.createElement("img");return this.options.imageClass?(t.className=this.options.imageClass,this.options.addPart&&t.setAttribute("part",this.options.imageClass)):(t.style.position="absolute",t.style.pointerEvents="none",t.style.userSelect="none"),this.options.setDraggableFalse&&t.setAttribute("draggable","false"),t}paint(t,e,i,n,s,r){if(this.pending=!1,this.zIndex++,t instanceof S){if(!t.__host){const e=this.createImage();e.src=t.uri,t.__host=e,this.container.appendChild(t.__host)}const e=t.__host;this.currentlyVisible.push(e),e.style.zIndex=`${this.zIndex}`,e.style.opacity=`${t.style.opacity}`,this.options.widthStylesheet?e.className=this.options.imageClass+" "+this.stylesheet.addStylesheet(`width:${(s+Number.MIN_VALUE).toFixed(2)}px;height:${(r+Number.MIN_VALUE).toFixed(2)}px;`):(e.style.width=`${s+Number.MIN_VALUE}px`,e.style.height=`${r+Number.MIN_VALUE}px`),e.style.transform=`translate(${i}px, ${n}px)`}if(t instanceof Es){if(t.__host||(t.__host={images:[]}),!t.__host.images[e]){const i=t.getImageUrl(e),n=this.createImage();n.src=i,t.__host.images[e]=n,this.container.appendChild(n)}const o=t.__host.images[e];o.style.zIndex=`${this.zIndex}`,o.style.opacity=`${t.style.opacity}`,this.currentlyVisible.push(o),this.options.widthStylesheet?o.className=this.options.imageClass+" "+this.stylesheet.addStylesheet(`width:${(s+Number.MIN_VALUE).toFixed(2)}px;height:${(r+Number.MIN_VALUE).toFixed(2)}px;`):(o.style.width=`${s+Number.MIN_VALUE}px`,o.style.height=`${r+Number.MIN_VALUE}px`),o.style.transform=`translate(${i}px, ${n}px)`}}pendingUpdate(){return this.pending}prepareLayer(t){}finishLayer(t){}reset(){}}function To({interactive:t,viewport:e,forceRefresh:i,containerElement:n,overlayElement:s,controllerConfig:r,background:o}){if(!n)throw new Error("Invalid container");n.style.userSelect="none";const a=t?Xr({minZoomFactor:.5,maxZoomFactor:3,enableClickToZoom:!1,...r||{}}):void 0,l=new _o(n,{addPart:!1,setDraggableFalse:!1,imageClass:"atlas-static-image",background:o}),h=s?new yr([l,new bo(s,{box:!0,text:!0,triggerResize:i})]):l,c=new Gs(h,new ks(1024,1024),e,a?[a]:[]),d=new Eo(n,c);return{name:"static-preset",em:d,runtime:c,renderer:h,controller:a,container:n,overlay:s,unmount(){fo(c),c.stopControllers(),c.stop(),d&&d.stop()}}}const Co={"default-preset":So,"static-preset":To},ko={};function Po(t,i){const n=e.useRef(),s=e.useRef(),r=e.useRef(),o=e.useRef(),a=e.useRef({width:i.width,height:i.height,didUpdate:!0}),[l="default-preset",h=ko]=Array.isArray(t)?t||[]:[t],[c,d]=e.useState(null);e.useLayoutEffect((()=>{const t=s.current,e=o.current,c=n.current,u=r.current,p=(Co[l]||So)({containerElement:e,canvasElement:t,overlayElement:c,navigatorElement:u,viewport:a.current,dpi:window.devicePixelRatio||1,forceRefresh:i.forceRefresh,unstable_webglRenderer:i.unstable_webglRenderer,...h||{}});return d(p),()=>{p&&(p.unmount(),t&&(t.height=0,t.width=0),c&&(c.innerHTML=""),u&&(u.height=0,u.width=0))}}),[l,h]);const u=e.useMemo((()=>({canvas:s,overlay:n,container:o,navigator:r})),[]);return[l,c,a,u]}const Oo=a.default.forwardRef(((t,e)=>a.default.createElement("div",{...t,ref:e,part:t.className}))),Ro=({htmlChildren:t,renderPreset:i,onCreated:n,mode:s="explore",resetWorldOnChange:r=!0,unstable_webglRenderer:o=!1,unstable_noReconciler:l=!1,hideInlineStyle:h=!1,controllerConfig:c,children:d,overlayStyle:u,containerStyle:p,enableNavigator:f,className:g,containerProps:m={},homePosition:v,background:y,runtimeOptions:w,debug:b,...x})=>{const[E,S]=e.useState(y),[_,T]=e.useState(s),[C,k]=e.useState(!1),P=e.useMemo((()=>("string"==typeof i&&(i=[i,{}]),E||b?i?[i[0],{debug:b,background:E,...i[1]||{}}]:["default-preset",{background:E,debug:b}]:i||"default-preset")),[i,E,b]),[O,R,A]=Zr({scroll:!0}),I=e.useRef(),[L,$,z,M]=Po(P,{width:x.width,height:x.height,forceRefresh:A,unstable_webglRenderer:o}),[B,F]=e.useState("");e.useEffect((()=>{T(s)}),[s]),e.useEffect((()=>{$&&$.em&&$.em.updateBounds()}),[$,R]),e.useEffect((()=>{null==$||$.runtime.setOptions(w||{})}),[w]),e.useEffect((()=>{$&&$.runtime&&($.runtime.mode=_),C&&$&&($.ready=!0)}),[$,C,_]),e.useEffect((()=>{$&&($.runtime.manualHomePosition=!!v,$.runtime.setHomePosition(v))}),[$,v]),e.useEffect((()=>{if($){const t=$.runtime;t.resize(z.current.width,x.width,z.current.height,x.height),z.current.width=x.width,z.current.height=x.height,t.updateNextFrame(),z.current.didUpdate=!0}}),[$,x.width,x.height]),e.useLayoutEffect((()=>{$&&($.overlay&&($.overlay.style.width=`${R.width}px`,$.overlay.style.height=`${R.height}px`),$.container&&($.container.style.width=`${R.width}px`,$.container.style.height=`${R.height}px`))}),[$,R.height,R.width]),e.useLayoutEffect((()=>{const t=()=>{if($){const t=$.runtime;z.current.width!==x.width&&z.current.height!==x.height&&(t.resize(z.current.width,x.width,z.current.height,x.height),z.current.width=x.width,z.current.height=x.height,t.updateNextFrame(),z.current.didUpdate=!0)}};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)}),[$,x.height,x.width]);const D=120,N=()=>{if($&&$.navigator){const t=$.runtime.world.height,e=$.runtime.world.width,i=window.devicePixelRatio||1,n=D,s=D/e*t;$.navigator.width=n*i,$.navigator.height=s*i,$.navigator.style.width=n+"px",$.navigator.style.height=s+"px"}};e.useLayoutEffect((()=>{if($){N();const t=$.runtime;return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&(N(),t.resize(z.current.width,x.width,z.current.height,x.height))}))}return()=>{}}),[$]);const j=e.useCallback((function(t){const i=()=>{k(!0)};return e.useEffect((()=>{if(!$)throw new Error("Invalid configuration - no runtime found");{$.runtime.goHome();const t=n&&n($);t&&t.then?t.then(i):i()}}),[]),t.children}),[$]);e.useEffect((()=>{if($){const t=$.runtime;if(r)return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&t.goHome()}))}return()=>{}}),[$,r]),e.useEffect((()=>{if($){return $.runtime.registerHook("useBeforeFrame",(()=>{var t;if(z.current.didUpdate&&$.canvas){const e=window.devicePixelRatio||1,i=z.current.width,n=z.current.height;$.canvas.width=i*e,$.canvas.height=n*e,$.canvas.style.width=i+"px",$.canvas.style.height=n+"px",null==(t=$.canvas.getContext("2d"))||t.scale(e,e),$&&$.em&&$.em.updateBounds(),z.current.didUpdate=!1}}))}return()=>{}}),[$,r]),e.useEffect((()=>{const t=()=>{$&&(T("sketch"),F("mode-sketch")),window.removeEventListener("keyup",t)},e=e=>{if("Space"===e.code&&$&&"sketch"===$.runtime.mode){if(e.target&&e.target.tagName&&"input"===e.target.tagName.toLowerCase())return;e.preventDefault(),T("explore"),F("mode-explore"),window.addEventListener("keyup",t)}};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)}}),[$]),e.useLayoutEffect((()=>{if(I.current&&!E){const t=getComputedStyle(I.current).getPropertyValue("--atlas-background");t&&S(t)}}),[E]);const{height:W,width:U,...H}=x,V=(G=[x.width,x.height],e.useMemo((()=>yo(G)),G));var G;return a.default.createElement(Oo,{ref:t=>{I.current=t,O(t)},className:["atlas",h?"":`atlas-width-${V}`,B,g].filter(Boolean).join(" ").trim(),style:{...p,...h?{}:{width:x.width,height:x.height}}},"static-preset"===L?a.default.createElement(Oo,{className:"atlas-static-container",style:$&&$.controller?void 0:{pointerEvents:"none"},ref:M.container,tabIndex:0,...m}):a.default.createElement("canvas",{className:"atlas-canvas",part:"atlas-canvas",tabIndex:0,...H,...m,ref:M.canvas}),a.default.createElement(Oo,{className:"atlas-overlay",style:{...u||{}},ref:M.overlay},l?a.default.createElement(j,null,a.default.createElement(no.Provider,{value:R},a.default.createElement(Yr.Provider,{value:_},a.default.createElement(io.Provider,{value:$},d)))):a.default.createElement(mo,{bounds:R,preset:$,mode:_,setIsReady:k,onCreated:n},d)),f?a.default.createElement(Oo,{className:"atlas-navigator"},a.default.createElement("canvas",{className:"atlas-navigator-canvas",part:"atlas-navigator-canvas",ref:M.navigator})):null,h?a.default.createElement("style",null,`.atlas-width-${V} { width: ${x.width}px; height: ${x.height}px; }`):a.default.createElement("style",null,`\n .atlas { position: relative; user-select: none; display: flex; background: var(--atlas-background, #000); z-index: var(--atlas-z-index, 10); touch-action: none; }\n .atlas-width-${V} { width: ${x.width}px; height: ${x.height}px; }\n .atlas-canvas { flex: 1 1 0px; }\n .atlas-canvas:focus, .atlas-static-container:focus { outline: none }\n .atlas-canvas:focus-visible, .atlas-canvas-container:focus-visible { outline: var(--atlas-focus, 2px solid darkorange) }\n .atlas-static-container { position: relative; overflow: hidden; flex: 1 1 0px; }\n .atlas-overlay { position: absolute; top: 0; left: 0; pointer-events: none; overflow: hidden; }\n .atlas-static-image { position: absolute; pointer-events: none; user-select: none; transform-origin: 0px 0px; }\n .atlas-navigator { position: absolute; top: var(--atlas-navigator-top, 10px); right: var(--atlas-navigator-bottom, 10px); left: var(--atlas-navigator-left); bottom: var(--atlas-navigator-bottom); opacity: .8 }\n .atlas-navigator-canvas { width: 100%; }\n `),t)};const Ao=()=>e.useContext(io),Io=()=>{const t=Ao();return t?t.runtime:void 0},Lo=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useAfterFrame",t):()=>{}),i)},$o=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useFrame",t):()=>{}),i)},zo=()=>{const t=Ao();return t&&t.canvas?t.canvas:void 0};function Mo(){return e.useContext(no)}const Bo=a.default.forwardRef((({children:t,...i},n)=>{const r=e.useRef(),o=Io(),l=e.useRef(0),h=e.useRef(),c=e.useRef();return $o((()=>{var t,e,n,s;if(i.relative){const i=r.current;if(i&&o){const a=o.getScaleFactor();l.current!==a&&(l.current=a,i.style.transformOrigin="0 0",i.style.transform=`scale(${1/l.current})`,i.style.width=100*l.current+"%",i.style.height=100*l.current+"%",r.current&&(null==(e=null==(t=h.current)?void 0:t.__owner.value)?void 0:e.rotation)&&(i.style.transform=`scale(${1/l.current}) translate(50%, 50%) rotate(${(null==(s=null==(n=h.current)?void 0:n.__owner.value)?void 0:s.rotation)||0}deg) translate(-50%, -50%)`))}}}),[i.relative]),e.useLayoutEffect((()=>{const o=h.current;async function l(){if(o&&o.__host){const n=i.relative?a.default.createElement("div",{ref:r},t):t;await async function(t,i,n){if(e.version.startsWith("18.")){const e=await Promise.resolve().then((function(){return s(require("react-dom/client"))})),r=e.default?e.default.createRoot:e.createRoot;n.current||(n.current=r(t)),n.current.render(i)}else if("undefined"!=typeof ReactDOM){const{render:e,unmountComponentAtNode:s}=ReactDOM;e(i,t),n.current={unmount(){s(t)}}}else{const e=await Promise.resolve().then((function(){return s(require("react-dom"))})),r=e.default?e.default.render:e.render,o=e.default?e.default.unmountComponentAtNode:e.unmountComponentAtNode;r(i,t),n.current={unmount(){o(t)}}}}(o.__host.element,n,c)}}n&&o&&("function"==typeof n?n(o):n.current=o),o&&o.__host?l():o&&(o.__onCreate=l)}),[n,t,h,i.relative]),e.useLayoutEffect((()=>()=>{c.current&&setTimeout((()=>{c.current.unmount()}),0)}),[]),a.default.createElement("box",{html:!0,...i,ref:h})}));Bo.displayName="HTMLPortal";const Fo=(t,i,n=[])=>{const s=Io(),r=s?s.world:void 0;e.useEffect((()=>{if(s){const e=i,n=d[t];s.world.activatedEvents.push(n);const r=n.slice(2).toLowerCase();return s.world.addEventListener(r,e),()=>{s.world.removeEventListener(r,e)}}return()=>{}}),[r,t,...n])};function Do(t,e){if(0===t)return[0,1];if(0===e)return[1,0];const i=Math.abs(t)/Math.abs(e);return[i,1-i]}const No=(t,i)=>{const n=Kr(),s=Io(),r=Mo(),o=e.useRef(),a=e.useRef(null),l=e.useRef(),[h,c]=e.useState(!1),d=e.useRef(!1),u=e.useRef({north:0,south:0,east:0,west:0}),p=function(){const t=e.useRef({ctrl:!1,shift:!1,alt:!1});return e.useLayoutEffect((()=>{function e(e){"Shift"===e.key&&(t.current.shift=!0),"Control"===e.key&&(t.current.ctrl=!0),"Alt"===e.key&&(t.current.alt=!0)}function i(e){"Shift"===e.key&&(t.current.shift=!1),"Control"===e.key&&(t.current.ctrl=!1),"Alt"===e.key&&(t.current.alt=!1)}return window.addEventListener("keydown",e),window.addEventListener("keyup",i),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",i)}}),[]),t}(),f=e.useCallback((t=>e=>{if(d.current=!0,c(!0),r&&s){const{top:i,left:n}=r,a=s.viewerToWorld(e.pageX-n,e.pageY-i);l.current={x:a.x,y:a.y},o.current=t}}),[r,s]),g=e.useMemo((()=>t.width/t.height),[t.width,t.height]),m=e.useCallback((e=>{if(!Math.abs(e.north-e.south+(e.east-e.west)))return;const i=-e.west+e.east,n=-e.north+e.south,s=t.width+i,r=t.height+n;if(s/r>=g){const t=s-r*g,[i,n]=Do(e.east,e.west);e.west=e.west+t*n,e.east=e.east-t*i}else{const t=r-s/g,[i,n]=Do(e.north,e.south);e.north=e.north+t*i,e.south=e.south-t*n}}),[t.width,t.height,g]);$o((()=>{l&&s&&s.updateNextFrame()})),e.useEffect((()=>{s&&s.updateNextFrame()}),[s,h]);const v=e.useCallback((e=>{var i;if(!s||!r||"sketch"!==s.mode)return;const{top:n,left:h}=r,c=s.viewerToWorld(e.pageX-h,e.pageY-n),d=a.current,f=!t.maintainAspectRatio&&p.current.alt,g=!f&&p.current.shift&&-1!==(null==(i=o.current)?void 0:i.indexOf("-"));if("translate"!==o.current&&"east"!==o.current&&"north-east"!==o.current&&"south-east"!==o.current||(u.current.east=c.x-(l.current?l.current.x:0),f&&(u.current.west=-u.current.east)),"translate"!==o.current&&"west"!==o.current&&"north-west"!==o.current&&"south-west"!==o.current||(u.current.west=c.x-(l.current?l.current.x:0),f&&(u.current.east=-u.current.west)),"translate"!==o.current&&"north"!==o.current&&"north-east"!==o.current&&"north-west"!==o.current||(u.current.north=c.y-(l.current?l.current.y:0),f&&(u.current.south=-u.current.north)),"translate"!==o.current&&"south"!==o.current&&"south-west"!==o.current&&"south-east"!==o.current||(u.current.south=c.y-(l.current?l.current.y:0),f&&(u.current.north=-u.current.south)),(t.maintainAspectRatio||g)&&m(u.current),d){const e=u.current.west,i=u.current.north,n=t.width+u.current.east,r=t.height+u.current.south;d.points[1]=Math.min(e,n),d.points[2]=Math.min(i,r),d.points[3]=Math.max(e,n),d.points[4]=Math.max(i,r),s.updateNextFrame()}}),[s,t.width,t.height,t.maintainAspectRatio,r]);Fo("mousemove",v,[t.width,t.height,r]),Fo("pointermove",v,[t.width,t.height,r]);const y=e.useRef();return e.useEffect((()=>{y.current=()=>{if(d.current){const e=u.current.west,n=u.current.north,s=t.width+u.current.east,r=t.height+u.current.south,a=Math.min(e,s),h=Math.min(n,r),p=Math.max(e,s),f=Math.max(n,r),g={x:(t.x||0)+a,y:(t.y||0)+h,width:p-a||1,height:f-h||1};t.maintainAspectRatio,i(g),o.current=void 0,l.current=void 0,u.current.east=0,u.current.west=0,u.current.north=0,u.current.south=0,d.current=!1,c(!1)}}}),[i,t.height,t.width,t.x,t.y]),e.useEffect((()=>{const t=()=>{y.current&&y.current()};return window.addEventListener("pointerup",t),window.addEventListener("touchend",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("touchend",t)}}),[]),{portalRef:a,mode:n,mouseEvent:f,onPointerMoveCallback:v,isEditing:h}};function jo({handleSize:t,resizable:i,onSave:n,children:s,maintainAspectRatio:r,disableCardinalControls:o,...l}){const h=void 0===t?r?10:8:t,{portalRef:c,mode:d,mouseEvent:u,isEditing:p}=No({x:l.x||0,y:l.y||0,width:l.width,height:l.height,maintainAspectRatio:r},n),f=e.useMemo((()=>u("translate")),[u]),g=e.useMemo((()=>u("east")),[u]),m=e.useMemo((()=>u("west")),[u]),v=e.useMemo((()=>u("south")),[u]),y=e.useMemo((()=>u("north")),[u]),w=e.useMemo((()=>u("south-east")),[u]),b=e.useMemo((()=>u("south-west")),[u]),x=e.useMemo((()=>u("north-east")),[u]),E=e.useMemo((()=>u("north-west")),[u]),S="sketch"===d,_={zIndex:999,boxShadow:"0px 2px 3px 0 rgba(0,0,0,0.2)",border:"1px solid rgba(155,155,155,.7)",borderRadius:r||o?"50%":2,position:"absolute",background:"#fff",pointerEvents:p?"none":S?"initial":"none"};return a.default.createElement(a.default.Fragment,null,a.default.createElement("world-object",{...l},s,S&&i?a.default.createElement(Bo,{ref:c,target:{x:0,y:0,height:l.height,width:l.width},relative:!0,interactive:!1},S&&i?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onMouseDown:f,onTouchStart:f,style:{display:"block",width:"100%",height:"100%",position:"relative",border:"1px solid rgba(155,155,155, .7)",boxSizing:"border-box",pointerEvents:p?"none":S?"initial":"none"}}),r?null:a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{title:"east",onTouchStart:g,onMouseDown:g,style:{..._,cursor:"e-resize",height:2*h,width:h,right:0,top:"50%",opacity:o?0:1,transform:`translate(${h/2}px, -${h}px)`}}),a.default.createElement("div",{title:"west",onMouseDown:m,style:{..._,cursor:"w-resize",position:"absolute",height:2*h,width:h,left:0,top:"50%",opacity:o?0:1,transform:`translate(-${h/2}px, -${h}px)`}}),a.default.createElement("div",{title:"north",onMouseDown:y,style:{..._,cursor:"n-resize",position:"absolute",height:h,width:2*h,left:"50%",top:0,opacity:o?0:1,transform:`translate(-${h}px, -${h/2}px)`}}),a.default.createElement("div",{title:"south",onMouseDown:v,style:{..._,cursor:"s-resize",position:"absolute",height:h,width:2*h,left:"50%",bottom:0,opacity:o?0:1,transform:`translate(-${h}px, ${h/2}px)`}})),a.default.createElement("div",{title:"north-east",onMouseDown:x,style:{..._,cursor:"ne-resize",position:"absolute",height:h,width:h,right:0,top:0,transform:`translate(${h/2}px, -${h/2}px)`}}),a.default.createElement("div",{title:"south-east",onMouseDown:w,style:{..._,cursor:"se-resize",position:"absolute",height:h,width:h,bottom:0,right:0,transform:`translate(${h/2}px, ${h/2}px)`}}),a.default.createElement("div",{title:"south-west",onMouseDown:b,style:{..._,cursor:"sw-resize",position:"absolute",height:h,width:h,bottom:0,left:0,transform:`translate(-${h/2}px, ${h/2}px)`}}),a.default.createElement("div",{title:"north-west",onMouseDown:E,style:{..._,cursor:"nw-resize",position:"absolute",height:h,width:h,top:0,left:0,transform:`translate(-${h/2}px, -${h/2}px)`}})):null):null))}const Wo=t=>{var i,n,s,r,o;const l=t.width/((null==(i=t.crop)?void 0:i.width)||t.tiles.width),h=t.tiles.imageService.tiles||[],c=t.tiles.imageService.sizes||[],d=t.enableThumbnail,u=t.enableSizes,p=e.useMemo((()=>{const e=t.tiles.imageService.id||t.tiles.imageService["@id"];return e&&e.endsWith("/info.json")?e.slice(0,-1*"/info.json".length):e}),[t.tiles.imageService.id]);return a.default.createElement("world-object",{rotation:t.rotation,key:t.tiles.imageService.id,scale:l,height:(null==(n=t.crop)?void 0:n.height)||t.tiles.height,width:(null==(s=t.crop)?void 0:s.width)||t.tiles.width,x:t.x,y:t.y,onClick:t.onClick},a.default.createElement("composite-image",{key:t.tiles.imageService.id,id:t.tiles.imageService.id,width:(null==(r=t.crop)?void 0:r.width)||t.tiles.width,height:(null==(o=t.crop)?void 0:o.height)||t.tiles.height,crop:t.crop},d&&t.tiles.thumbnail?a.default.createElement("world-image",{priority:!0,uri:t.tiles.thumbnail.id,target:{width:t.tiles.width,height:t.tiles.height},display:{width:t.tiles.thumbnail.width,height:t.tiles.thumbnail.height},crop:t.crop}):null,u&&c.map(((e,i)=>a.default.createElement("world-image",{key:i,uri:`${p}/full/${e.width},${e.height}/0/default.jpg`,target:{width:t.tiles.width,height:t.tiles.height},display:{width:e.width,height:e.height},crop:t.crop}))),h.map((e=>(e.scaleFactors||[]).map((i=>a.default.createElement("tiled-image",{key:`${t.tiles.imageService.id}-tile-${i}`,uri:t.tiles.imageService.id,display:{width:t.tiles.width,height:t.tiles.height},tile:e,scaleFactor:i,crop:t.crop})))))))};function Uo(t){return t.id||t["@id"]}function Ho(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Vo="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Go="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xo="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Yo="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ko="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Qo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",qo="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Zo="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Jo="http://iiif.io/api/image/1/level1.json",ta="http://iiif.io/api/image/1/profiles/level1.json",ea="http://iiif.io/api/image/1/level2.json",ia="http://iiif.io/api/image/1/profiles/level2.json",na="http://iiif.io/api/image/2/level1.json",sa="http://iiif.io/api/image/2/profiles/level1.json",ra="http://iiif.io/api/image/2/level2.json",oa="http://iiif.io/api/image/2/profiles/level2.json",aa="level1",la="level2",ha="http://iiif.io/api/image/2/level1",ca="http://iiif.io/api/image/2/level2",da=[ca,Go,Yo,Qo,Zo,ea,ia,ra,oa,la],ua=[...da,ha,Vo,Xo,Ko,qo,Jo,ta,na,sa,aa],pa=["http://iiif.io/api/image/2/level0",ha,ca,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",Vo,Go,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",Xo,Yo,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ko,Qo,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",qo,Zo,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",Jo,ta,ea,ia,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",na,sa,ra,oa,"level0",aa,la],fa={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ga={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},ma={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function va(t){return-1!==da.indexOf(t)?ma:-1!==ua.indexOf(t)?ga:fa}function ya(t){try{if("full"===t)return{full:!0};if("square"===t)return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map((t=>parseFloat(t)));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function wa(t){const e={upscaled:!1,max:!1,confined:!1};if("^"===t[0]&&(e.upscaled=!0,t=t.slice(1)),"max"===t||"full"===t)return e.max=!0,e.serialiseAsFull="full"===t,e;if("!"===t[0]&&(e.confined=!0,t=t.slice(1)),"p"===t[0])return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map((t=>t.trim()));return i.length&&(""!==i[0]&&(e.width=parseInt(i[0],10)),""!==i[1]&&(e.height=parseInt(i[1],10))),e}function ba(t){const e={angle:0};if("!"===t[0]&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function xa(t,e=""){const{path:i,scheme:n,server:s,prefix:r}=function(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const n=i[2],s=i[3];let r=i[4];if("/"===r[0]&&(r=r.substr(1)),e.length>0){if("/"===e[0]&&(e=e.substr(1)),e!==r.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${r}, prefix: ${e})`);r=r.substr(e.length)}return{scheme:n,server:s,path:r,prefix:e}}(t,e),o=i.split("/").reverse(),[a,l,h,c,...d]=o,u=d.reverse().filter(Boolean).join("/");if(1===o.length||""===a)return{type:"base",scheme:n,server:s,prefix:r,identifier:u};if("info.json"===a){const[,...t]=o;return{type:"info",scheme:n,server:s,prefix:r,identifier:t.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:n,server:s,prefix:r,identifier:u,originalPath:i,region:ya(c),size:wa(h),rotation:ba(l),quality:p[0],format:p[1]}}function Ea(t){const e=xa(Ho(t.id));if("info"!==e.type)throw new Error("Invalid service URL");const i=function(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if("string"==typeof n&&(n=va(n)),n){if(n.formats)for(const t of n.formats)-1===i.extraFormats.indexOf(t)&&i.extraFormats.push(t);if(n.qualities)for(const t of n.qualities)-1===i.extraQualities.indexOf(t)&&i.extraQualities.push(t);if(n.supports)for(const t of n.supports)-1===i.extraFeatures.indexOf(t)&&i.extraFeatures.push(t);if(n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea),n.extraFormats)for(const t of n.extraFormats)-1===i.extraFormats.indexOf(t)&&i.extraFormats.push(t);if(n.extraQualities)for(const t of n.extraQualities)-1===i.extraQualities.indexOf(t)&&i.extraQualities.push(t);if(n.extraFeatures)for(const t of n.extraFeatures)-1===i.extraFeatures.indexOf(t)&&i.extraFeatures.push(t);n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)-1===i.extraFormats.indexOf(n)&&i.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)-1===i.extraFeatures.indexOf(n)&&i.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)-1===i.extraQualities.indexOf(n)&&i.extraQualities.push(n);return i}(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:-1===i.extraQualities.indexOf("default")?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Sa(t,e,i){const n=i.length,s=[];for(let r=0;r<n;r++){const e=i[r].width;s.push(t/e)}return s}function _a(t,e,i){const n=i.length,s=[];for(let r=0;r<n;r++){const n=i[r];s.push({width:Math.floor(t/n),height:Math.floor(e/n)})}return s}function Ta(t){return t["@id"]?t["@id"]:t.id?t.id:void 0}function Ca(t){if(!t||!t.profile||!Ta(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if("string"==typeof i&&-1!==pa.indexOf(i))return!0;return!1}function ka(t){if(!function(t){if(!Ca(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if("string"==typeof i){if(-1!==ua.indexOf(i))return!0}else{const t=[...i.supports||[],...i.extraFeatures||[]];if(-1!==t.indexOf("regionByPx")&&(-1!==t.indexOf("sizeByW")||-1!==t.indexOf("sizeByWh")))return!0}return!1}(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],n=i.length;for(let s=0;s<n;s++){const e=i[s];if("string"!=typeof e&&(e.maxHeight||e.maxWidth))return[{id:Ta(t),type:"variable",minWidth:0,minHeight:0,maxHeight:e.maxHeight||e.maxWidth,maxWidth:e.maxWidth||e.maxHeight}]}if(t.tiles){const i=t.tiles.length;for(let n=0;n<i;n++){const i=t.tiles[n];(i.height||i.width)&&e.push({id:Ta(t),type:"variable",minHeight:0,minWidth:0,maxHeight:i.height||i.width,maxWidth:i.width})}}return e}function Pa(t){const e=t.match(/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/);if(e){const i=e[1],n=parseInt(e[4],10),s=parseInt(e[5],10),r=e[7];if(("max"===i||"full"===i)&&n&&s&&r)return{type:"fixed",id:t,height:s,width:n}}return{type:"unknown",id:t}}function Oa(t){if("string"==typeof t)return Pa(t);const e=function(t){return t["@type"]?t["@type"]:t.type?t.type:void 0}(t);if("Image"!==e&&"sc:Image"!==e)return null;const i=t,n=Ta(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Pa(n):null}function Ra(t){return Ca(t)?(t&&t.sizes?t.sizes:[]).map((e=>({id:Ta(t),type:"fixed-service",height:e.height,width:e.width}))):[]}function Aa(t){const e=[],i=t.length;for(let n=0;n<i;n++){const i=Ra(t[n]);i.length&&e.push(...i);const s=ka(t[n]);s.length&&e.push(...s)}return e}function Ia(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,n=[];for(let s=0;s<i;s++)Ca(e[s])&&n.push(e[s]);return n}function La({x:t=0,y:e=0,w:i,h:n,full:s,square:r,percent:o}){if(s)return"full";if(r)return"square";if(typeof i>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${n}`;return o?`pct:${a}`:a}function $a({max:t,percentScale:e,upscaled:i,confined:n,width:s,height:r,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(n&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),r&&a.push(`${r}`),a.join(""))}function za(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ma=Object.defineProperty,Ba=Object.defineProperties,Fa=Object.getOwnPropertyDescriptors,Da=Object.getOwnPropertySymbols,Na=Object.prototype.hasOwnProperty,ja=Object.prototype.propertyIsEnumerable,Wa=(t,e,i)=>e in t?Ma(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ua=(t,e)=>{for(var i in e||(e={}))Na.call(e,i)&&Wa(t,i,e[i]);if(Da)for(var i of Da(e))ja.call(e,i)&&Wa(t,i,e[i]);return t},Ha=(t,e)=>Ba(t,Fa(e));function Va(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if("base"===t.type)return n;if("info"===t.type)return`${n}/info.json`;let{region:s,size:r,rotation:o,format:a,quality:l}=t;if(e){const t=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],i=-1!==t.indexOf("http://iiif.io/api/image/2/context.json"),n=-1!==t.indexOf("http://iiif.io/api/image/3/context.json");if((r.width===e.width&&!r.height||r.height===e.height&&!r.width||r.width===e.width&&r.height===e.height)&&(r=Ha(Ua({},r),{max:!0})),i&&(r.max&&!r.serialiseAsFull&&(r=Ha(Ua({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=Ha(Ua({},r),{height:void 0}))),n&&(r.max&&r.serialiseAsFull&&(r=Ha(Ua({},r),{serialiseAsFull:!1})),r.width&&!r.height&&e.width&&e.height)){const t=e.height/e.width;r=Ha(Ua({},r),{height:Math.ceil(r.width*t)})}}return[n,La(s),$a(r),za(o),`${l}.${a}`].filter(Boolean).join("/")}function Ga(t,e,i){const n=Ea({id:Ho(Ta(t)),profile:"level2",type:"ImageService2"});if("image"!==n.type)throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=i,{id:Va(n),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function Xa(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return-1!==e.indexOf("/")?e.split("/")[0]:e}function Ya(t,e){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],r=[];let o=null;const a=(t,e)=>{if(function(t,e,i){const n=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-n)<Math.abs(e.width-n))}(n,e,t)){if(n.preferFixedSize&&t.unsafe)return void r.push(t);n.returnAllOptions&&e&&r.push(e),o=t}else n.returnAllOptions&&r.push(t)},l=e.length;for(let h=0;h<l;h++){const t=e[h](),i=t.length;for(let e=0;e<i;e++){const i=t[e];if("unknown"===i.type&&n.atAnyCost&&s.push(i),"fixed"===i.type&&(i.unsafe?s.push(i):a(i,o)),"fixed-service"===i.type)if(n.unsafeImageService){a(Ga(i,n.width,n.height),o)}else{a(Ga(i,i.width,i.height),o)}if("variable"===i.type&&i.maxWidth){a(Ga({id:i.id,type:"fixed-service",width:i.maxWidth,height:i.maxWidth},i.maxWidth),o)}}if(o&&!n.returnAllOptions){if(o.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&0===r.length?{best:o||s[0],fallback:s.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?o||r[0]||s[0]:o||r[0],fallback:[...r,...s],log:i}:{best:o||r[0]||null,fallback:o?r:r.slice(1),log:i}}var Ka=Object.defineProperty,Qa=Object.defineProperties,qa=Object.getOwnPropertyDescriptors,Za=Object.getOwnPropertySymbols,Ja=Object.prototype.hasOwnProperty,tl=Object.prototype.propertyIsEnumerable,el=(t,e,i)=>e in t?Ka(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,il=(t,e)=>{for(var i in e||(e={}))Ja.call(e,i)&&el(t,i,e[i]);if(Za)for(var i of Za(e))tl.call(e,i)&&el(t,i,e[i]);return t},nl=(t,e)=>Qa(t,qa(e));function sl(t,e,i){const n=t>e?t:e,s=i.length,r=[];for(let o=0;o<s;o++){const t=i[o];let e=t.scaleFactors[0],s=n/e;const a=[e];for(;s>=t.width;)e*=2,a.push(e),s/=2;r.push(nl(il({},t),{scaleFactors:a}))}return r}var rl=(t,e,i)=>new Promise(((n,s)=>{var r=t=>{try{a(i.next(t))}catch(e){s(e)}},o=t=>{try{a(i.throw(t))}catch(e){s(e)}},a=t=>t.done?n(t.value):Promise.resolve(t.value).then(r,o);a((i=i.apply(t,e)).next())}));class ol{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,e,i=!0){const n=Xa(Ta(t)),s=Ho(Ta(t)),r=this.knownImageServers[n];return this.imageServices[s]=Object.assign(t,{real:!0}),!r&&t.tiles?(this.knownImageServers[n]={verifications:0,malformed:!1,root:n,preLoaded:i,sampledId:Ta(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:e&&t.height?e.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Sa(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,e=!0){this.knownImageServers[t.root]=t,e&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,e=!1,i=!1){const n=null==t?void 0:t.source,s=Xa(Ta(t)),r=this.knownImageServers[s];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const o=Ho(Ta(t));return this.imageServices[o]||(this.imageServices[o]={"@context":r.result.context,"@id":Ta(t),id:Ta(t),protocol:"http://iiif.io/api/image",tiles:(null==n?void 0:n.tiles)||sl(t.width,t.height,r.result.sampledTiles),sizes:(null==n?void 0:n.sizes)||_a(Math.round(t.width/r.result.resourceServiceRatio),Math.round(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:(null==n?void 0:n.profile)||r.result.sampledProfile,height:(null==n?void 0:n.height)||t.height,width:(null==n?void 0:n.width)||t.width,real:!1}),this.imageServices[o]}getThumbnailFromResource(t,e){return rl(this,arguments,(function*(t,e,i=!0,n=[]){const s=yield this.getImageCandidates(t,i);return Ya(e,[()=>n,()=>s])}))}getImageCandidates(t,e=!0){return rl(this,null,(function*(){const i=t;if(e&&i.height&&i.width){const t=Ia(i);for(const e of t){const t={id:Ta(e),width:e.width?e.width:i.width,height:e.height?e.height:i.height,source:e};yield this.loadService(t)}}return function(t,e=!0,i){const n=[],s=Oa(t);if(null===s)return n;const r=t;if(n.push(s),e&&r.width&&r.height){const t=[],e=Ia(r);for(const n of e){const e={id:Ta(n),width:r.width,height:r.height};if(i.canLoadSync(e)){const n=i.loadServiceSync(e);n&&(n.height||(n.height=r.height),n.width||(n.width=r.width),t.push(...Aa([n])))}}if(t.length)return n.push(...t),n}return r.service&&n.push(...Aa(r.service)),n}(t,e,this)}))}verify(t){return rl(this,null,(function*(){const e=this.predict(t,!1,!0),i=yield this.fetchService(Ta(t));if(!e)return!1;const n=e.height===i.height&&e.width===i.width&&e["@context"]===i["@context"]&&function(t,e){if(t.length!==e.length)return!1;if(0===t.length&&0===e.length)return!0;const i=t.length;let n=!0;for(let r=0;r<i;r++){const i=t[r],s=e[r];if(i.width!==s.width||i.height!==s.height){n=!1;break}}if(n)return!0;let s=0;for(let r=0;r<i;r++)for(let n=0;n<i;n++)if(t[r].width===e[n].width&&t[r].height===e[n].height){s++;break}return s===i}(e.sizes||[],i.sizes||[]);if(n){const e=Xa(Ta(t));this.knownImageServers[e].verifications+=1,this.knownImageServers[e].verifications>=this.config.verificationsRequired&&(this.knownImageServers[e].verified=!0)}return n}))}canLoadSync(t){const e="string"==typeof t?t:Ta(t),i=Ho(e);if(this.imageServices[i])return!0;const n=this.knownImageServers[Xa(e)];return n&&!n.malformed&&n.verifications>=this.config.verificationsRequired}markAsMalformed(t){return rl(this,null,(function*(){return this.knownImageServers[Xa(Ta(t))].malformed=!0,this.loadService(t,!0)}))}fetchService(t,e=!1){return rl(this,null,(function*(){const i=Ho(t);if(this.imageServices[i]&&(!e||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const n=yield this.fetch(i).then((t=>t.json()));return!n.id&&n["@id"]&&(n.id=n["@id"]),n.id!==t&&(n.id=t,n["@id"]&&(n["@id"]=t)),this.imageServices[i]=Object.assign(n,{real:!0}),this.imageServices[i]}))}fetch(t,e){return rl(this,null,(function*(){return fetch(t,e)}))}loadService(t,e=!1){return rl(this,null,(function*(){if(!this.config.disableThrottling){let t=!0;for(;t;){if(!(this.fetchingCount>=this.config.verificationsRequired)){t=!1;break}yield new Promise((t=>setTimeout(t,500)))}}const i=this.knownImageServers[Xa(Ta(t))];if(i&&!i.malformed&&!e){yield i.result;const e=this.loadServiceSync(t);if(e)return e}this.fetchingCount++;const n=yield this.fetchService(Ta(t),e);return this.fetchingCount--,n.real&&this.sample(n,t),n}))}loadServiceSync(t){const e=Ho(Ta(t));return this.imageServices[e]?this.imageServices[e]:this.predict(t)}}new ol;const al={},ll={get:t=>t,setMetaValue([t,e,i],n){const s=ll.getResourceMeta(t,e),r=s?s[i]:void 0,o="function"==typeof n?n(r):n;al[t]={...al[t]||{},[e]:{...(al[t]||{})[e]||{},[i]:o}}},getResourceMeta:(t,e)=>{const i=al[t];if(i)return e?i[e]:i}},hl=new ol;function cl(){const t="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};if(void 0!==t.IIIF_VAULT)return t.IIIF_VAULT;if(void 0===t.IIIFVault)throw new Error("Vault not found");return t.IIIF_VAULT=new t.IIIFVault.Vault,t.IIIF_VAULT}const dl={};function ul(){return dl.helper||(dl.vault=cl(),dl.loader=new ol,dl.helper=function(t=ll,e={}){const i=e.imageServiceLoader||hl;return{getBestThumbnailAtSize:async function e(n,s,r=!1,o=[],a){const l=()=>i.getThumbnailFromResource(void 0,s,r,o);if(!n)return await i.getThumbnailFromResource(void 0,s,r,o);if("string"==typeof n){const t=Oa(n);return t&&o.push(t),await i.getThumbnailFromResource(void 0,s,r,o)}const h=t.get(n,{skipSelfReturn:!1});if("string"==typeof h)return{best:Oa(h),fallback:[],log:[]};if(!h)return await l();switch(await(async e=>{if(e&&e.thumbnail&&e.thumbnail.length){const n=t.get(e.thumbnail[0]),s=await i.getImageCandidates(n,r);s&&s.length&&o.push(...s)}})(h),h.type){case"Annotation":{const e=Array.isArray(h.body)?h.body:[h.body],n=t.get(e[0]);return a&&!n.width&&(n.width=a.width,n.height=a.height),await i.getThumbnailFromResource(n,s,r,o)}case"Canvas":{const t=h;return e(t.items[0],s,r,o,{width:t.width,height:t.height})}case"AnnotationPage":return e(h.items[0],s,r,o,a);case"Choice":{const t=h;return!t.items||t.items[0]?await l():e(t.items[0],s,r,o,a)}case"Collection":{const t=h.items[0];return t?e(t,s,r,o,a):await l()}case"Manifest":{const t=h.items[0];return t?e(t,s,r,o,a):await l()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return a&&!h.width&&(h.width=a.width,h.height=a.height),i.getThumbnailFromResource(h,s,r,o)}return await l()}}}(dl.vault,{imageServiceLoader:dl.loader})),dl}async function pl(t,e,i){const{loader:n}=ul(),s=await n.loadService({id:t,width:e,height:i});return{id:Uo(s),width:e,height:i,imageService:s,thumbnail:void 0}}async function fl(t,e=512){const{vault:i,loader:n,helper:s}=ul(),r=[];for(const o of t.items)for(const a of i.get(o).items){const o=i.get(i.get(a).body[0]).service[0],l=await pl(o.id,t.width,t.height),{best:h}=await s.getBestThumbnailAtSize(i,n,t,{maxHeight:e,maxWidth:e},!0);h&&(l.thumbnail=h),r.push(l)}return r}async function gl(t){const{vault:e}=ul(),i=[];for(const n of t.items){const t=e.get(n);i.push(...await fl(t))}return i}exports.Atlas=Ro,exports.AtlasAuto=({resizeHash:t,aspectRatio:i,containerProps:n={},...s})=>{const[r,o,l]=Zr(),{height:h,width:c,...d}=s;e.useEffect((()=>{l()}),[c,h,t,l]);const u=e.useMemo((()=>i?{width:o.width,height:o.width*(1/i)}:o),[o,i]);return a.default.createElement(Oo,{ref:r,className:"atlas-container",...n},u.width?a.default.createElement(Ro,{width:u.width||100,height:u.height||100,...d},s.children):null,s.hideInlineStyle?null:a.default.createElement("style",null,`\n .atlas-container { \n display: var(--atlas-container-display, block);\n flex: var(--atlas-container-flex, none);\n width: var(--atlas-container-width, ${c?`${c}px`:"100%"});\n height: var(--atlas-container-height, ${p=h||(i?u.height:512),Number(p)==p?`${p}px`:p}) \n }\n `),s.htmlChildren);var p},exports.AtlasContext=io,exports.BoundsContext=no,exports.Box=Is,exports.BrowserEventManager=Eo,exports.CanvasRenderer=vr,exports.CompositeRenderer=yr,exports.CompositeResource=_s,exports.DebugRenderer=wr,exports.DrawBox=({onCreate:t})=>{const i=e.useRef({x:0,y:0}),n=zo(),s=Mo(),r=Io(),[o,a]=e.useState(),[l,h]=e.useState(),c=Kr();return $o((()=>{r&&o&&!l&&(r.pendingUpdate=!0)}),[o,l]),Lo((()=>{if(o&&n&&r){const t=n.getContext("2d");if(t){const{x:e,y:n,width:s,height:a}=r.worldToViewer(o.x,o.y,(l?l.x:i.current.x)-o.x,(l?l.y:i.current.y)-o.y);t.lineWidth=l?3:1,t.strokeStyle="#fff",t.strokeRect(e,n,s,a),t.lineWidth=l?3:1,t.strokeStyle="#000",t.strokeRect(e+1,n+1,s-2,a-2)}}}),[o,l]),e.useEffect((()=>{const t=t=>{if(s&&r){const{x:e,y:n}=r.viewerToWorld(t.clientX-s.left,t.clientY-s.top);i.current.x=~~e,i.current.y=~~n}};return n?(n.addEventListener("mousemove",t),()=>n.removeEventListener("mousemove",t)):()=>{}}),[s,n,r]),e.useEffect((()=>{const t=t=>{"sketch"===c&&(a({x:Math.round(i.current.x),y:Math.round(i.current.y)}),h(void 0))};return n?(n.addEventListener("mousedown",t),()=>n.removeEventListener("mousedown",t)):()=>{}}),[n,c]),e.useEffect((()=>{const t=t=>{o&&!l&&h({x:Math.round(i.current.x),y:Math.round(i.current.y)})};return n?(n.addEventListener("mouseup",t),()=>n.removeEventListener("mouseup",t)):()=>{}}),[n,o,l]),e.useEffect((()=>{o&&l&&t({x:Math.min(o.x,l.x),y:Math.min(o.y,l.y),width:Math.abs(l.x-o.x),height:Math.abs(l.y-o.y)})}),[o,t,l]),null},exports.GridBuilder=class{constructor(){this.autoWidth=!1,this.autoHeight=!0,this.content=[],this.viewingDirection="left-to-right",this.columns=4,this.spacing=20,this.reversed=!1,this.padding=20,this.world=ks.withProps({width:0,height:0,viewingDirection:"left-to-right"}),this.width=0,this.height=0}setViewingDirection(t){this.viewingDirection=t}addContent(t){this.content.push(...t.map((t=>this.world.addObjectAt(t,{width:0,height:0,x:0,y:0}))))}setWidth(t){this.width=t}setHeight(t){this.height=t}setSpacing(t){this.spacing=t}setPadding(t){this.padding=t}setRows(t){this.autoWidth=!0,this.rows=t}setColumns(t){this.autoHeight=!0,this.columns=t}recalculate(){if(0===this.height&&0===this.width)return;if(0===this.rows||0===this.columns)return;if(this.autoHeight&&!this.width)throw new Error("Cannot set auto height without setting a width");if(this.autoWidth&&!this.height)throw new Error("Cannot set auto width without setting a height");"left-to-right"!==this.viewingDirection&&"top-to-bottom"!==this.viewingDirection||!this.reversed||(this.reversed=!1,this.content.reverse()),"right-to-left"!==this.viewingDirection&&"bottom-to-top"!==this.viewingDirection||this.reversed||(this.reversed=!0,this.content.reverse());const t=this.content.length,{columns:e,rows:i}=(()=>{if(this.autoWidth&&this.rows){const e=t>this.rows?this.rows:t;return{columns:Math.ceil(t/e),rows:e}}if(this.autoHeight&&this.columns){const e=t>this.columns?this.columns:t;return{columns:e,rows:Math.ceil(t/e)}}throw new Error("Something went wrong.")})(),n=this.autoWidth?-1:this.width-2*this.padding,s=this.autoWidth?-1:(n-this.spacing*(e-1))/e;if(this.autoHeight&&!this.autoWidth){let n=0,r=this.padding;for(let o=0;o<i&&n!==t;o++){let i=0;const o=[];for(let r=0;r<e;r++){const e=this.reversed?t-n:n;if(n===t)break;const r=this.content[e],a=r.width,l=s/(r.width/r.height);o.push([n,s,l,s/a]),l>i&&(i=l),n++}for(let n=0;n<e&&o[n];n++){const e=this.world.getPoints(),s=o[n][0],a=o[n][1],l=o[n][2],h=o[n][3],c=this.padding+n*(this.spacing+a),d=r+(i-l)/2,u=this.reversed?t-s:s,p=e[5*u+1],f=e[5*u+2];this.world.scaleWorldObject(s,h),p===c&&f===d||this.world.translateWorldObject(u,c-p,d-f)}r+=i+this.spacing}return this.height=r+this.padding,void this.world.resize(this.width,this.height)}this.autoWidth&&this.autoHeight,!this.autoWidth&&this.autoHeight}getWorld(){return this.world}},exports.HTMLPortal=Bo,exports.ImageService=t=>{var i,n;const[s,r]=e.useState();return e.useEffect((()=>{pl(t.id,t.width,t.height).then((t=>{r(t)}))}),[t.height,t.id,t.width]),a.default.createElement("world-object",{x:t.x||0,y:t.y||0,width:t.width,height:t.height,scale:t.scale},s?a.default.createElement(Wo,{tiles:s,x:t.x,y:t.y,width:(null==(i=t.crop)?void 0:i.width)||t.width,height:(null==(n=t.crop)?void 0:n.height)||t.height,rotation:t.rotation,crop:t.crop},t.children):null)},exports.ImageTexture=_,exports.ModeContext=Yr,exports.OverlayRenderer=bo,exports.ReactAtlas=go,exports.RegionHighlight=function({interactive:t,region:i,onClick:n,onSave:s,maintainAspectRatio:r,disableCardinalControls:o,isEditing:l,rotation:h,style:c={backgroundColor:"rgba(0,0,0,.5)"}}){const d=e.useCallback((t=>{s({id:i.id,x:i.x,y:i.y,height:i.height,width:i.width,...t})}),[s,i.id,i.x,i.y,i.height,i.width]);return a.default.createElement(jo,{x:i.x,y:i.y,rotation:h,width:i.width,height:i.height,resizable:l,onSave:d,maintainAspectRatio:r,disableCardinalControls:o},a.default.createElement("box",{interactive:t,onClick:t=>{t.preventDefault(),t.stopPropagation(),n(i)},target:{x:0,y:0,width:i.width,height:i.height},style:c}))},exports.ResizeWorldItem=jo,exports.Runtime=Gs,exports.SingleImage=S,exports.StaticRenderer=_o,exports.Text=Ls,exports.TileSet=Wo,exports.TiledImage=Es,exports.WebGLRenderer=vo,exports.World=ks,exports.WorldObject=Cs,exports.Zone=class{constructor(t,e={}){this.id=t.map((t=>t.id)).join("$$"),this.config={...Ps,...e},this.points=p(5),this.objects=t,this.recalculateBounds()}recalculateBounds(){this.points.set([1,Math.min(...this.objects.map((t=>t.points[1])))-this.config.margin,Math.min(...this.objects.map((t=>t.points[2])))-this.config.margin,Math.max(...this.objects.map((t=>t.points[3])))+this.config.margin,Math.max(...this.objects.map((t=>t.points[4])))+this.config.margin])}getPointsAt(t,e,i){return[]}},exports.activateEvents=ho,exports.applyProps=lo,exports.bounceOut=Us,exports.canDrag=function(t){return"sketch"===t.current},exports.createDefaultEventMap=c,exports.defaultConfig=Gr,exports.defaultPreset=So,exports.easingFunctions=Hs,exports.fromImage=function(t){const{src:e,target:i}=t,n=i?i.width:t.width,s=i?i.height:t.height;return new Cs({id:e,height:s,width:n,layers:[S.fromImage(e,{height:s,width:n},{width:t.width,height:t.height})]})},exports.getId=Uo,exports.getTileFromCanvas=fl,exports.getTileFromImageService=pl,exports.getTiles=async function(t){try{const{vault:e}=ul(),i=await e.loadManifest(t);return i?gl(i):[]}catch(e){return console.log("ERR",e),[]}},exports.getTilesFromManifest=gl,exports.mergeStyles=function(t,e){return t?e?{...t,...e||{},":hover":t[":hover"]?Object.assign(t[":hover"]||{},e[":hover"]||{}):e[":hover"],":active":t[":active"]?Object.assign(t[":active"]||{},e[":active"]||{}):e[":hover"]}:t:e},exports.popmotionController=Xr,exports.presets=Co,exports.staticPreset=To,exports.supportedEventAttributes=h,exports.supportedEventMap=d,exports.unmountComponentAtNode=fo,exports.useAfterFrame=Lo,exports.useAfterPaint=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useAfterPaint",t):()=>{}),i)},exports.useAtlas=Ao,exports.useAtlasImage=(t,{onCreated:i,resetWorldOnChange:n=!0,mode:s="explore",cover:r,containerRef:o,...l})=>{const[h,c]=e.useState(!1),[d,u]=e.useState(void 0),[p,f]=e.useState(void 0),g=e.useRef(),m=e.useRef(),v=e.useMemo((()=>({width:l.width,height:l.height})),[l.width,l.height]),[y,w,b,x]=Po(void 0,{width:l.width,height:l.height});e.useLayoutEffect((()=>{const t=document.createElement("canvas");t.height=v.height,t.width=v.width,g.current=t}),[]),e.useLayoutEffect((()=>{const t=g.current;t&&(t.height=v.height,t.width=v.width)}),[v.width,v.height]),e.useEffect((()=>{if(w){return w.runtime.registerHook("useAfterFrame",(()=>{if(g.current)try{u(g.current.toDataURL())}catch(t){t instanceof Error&&f(t.message)}}))}return()=>{}}),[]),e.useEffect((()=>{if(w){return w.runtime.world.addLayoutSubscriber((t=>{"ready"===t&&c(!0)}))}return()=>{}}),[]),e.useEffect((()=>{w&&w.em&&w.em.updateBounds()}),[v]),e.useEffect((()=>{w&&(w.runtime.mode=s)}),[s]),e.useEffect((()=>{if(w){const t=w.runtime;t.resize(b.current.width,l.width,b.current.height,l.height),r?t.cover():t.goHome(),b.current.width=l.width,b.current.height=l.height,t.updateNextFrame()}}),[l.width,l.height]),e.useLayoutEffect((()=>{const t=m.current;t&&(t.style.width=`${v.width}px`,t.style.height=`${v.height}px`,t.style.pointerEvents="none",t.style.overflow="hidden")}),[v.height,v.width]),e.useLayoutEffect((()=>{const t=()=>{if(w&&w.runtime){const t=w.runtime;t.resize(b.current.width,l.width,b.current.height,l.height),b.current.width=l.width,b.current.height=l.height,t.updateNextFrame()}};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)}),[w,l.height,l.width]);const E=e.useCallback((function(t){const n=()=>{w&&(w.ready=!0)};return e.useEffect((()=>{if(!w)return()=>{};{const t=i&&i(w);t&&t.then?t.then(n):n()}}),[]),t.children}),[w]);return e.useEffect((()=>{if(w&&w.runtime){const t=w.runtime;if(n)return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&t.goHome({cover:r})}))}return()=>{}}),[w,r,n]),e.useLayoutEffect((()=>{w&&go.render(a.default.createElement(E,null,a.default.createElement(Yr.Provider,{value:s},a.default.createElement(io.Provider,{value:w},t))),w.runtime)}),[w,s,t]),{loading:!d&&h,uri:d,imageError:p}},exports.useBeforeFrame=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useBeforeFrame",t):()=>{}),i)},exports.useCanvas=zo,exports.useControlledAnnotationList=(t=[])=>{const[i,n]=e.useState(t),[s,r]=e.useState(!1),[o,a]=e.useState(),l=e.useCallback((()=>{r(!0),a(void 0)}),[]),h=e.useCallback((t=>{r(!0),a(t)}),[]),c=e.useCallback((t=>{const e=x();n((i=>[...i,{id:e,...t}])),r(!1),a(void 0)}),[]);return{isEditing:s,onDeselect:e.useCallback((()=>{r(!1),a(void 0)}),[]),selectedAnnotation:o,onCreateNewAnnotation:c,annotations:i,onUpdateAnnotation:t=>{n((e=>e.map((e=>e.id===t.id?t:e))))},setIsEditing:r,setSelectedAnnotation:a,editAnnotation:h,addNewAnnotation:l}},exports.useFrame=$o,exports.useMode=Kr,exports.useResizeWorldItem=No,exports.useRuntime=Io,exports.useWorldEvent=Fo;
|
|
15
|
+
*/;var Wr=Dr,Ur=function(t,e){if(!jr.canUseDOM||e&&!("addEventListener"in document))return!1;var i="on"+t,n=i in document;if(!n){var s=document.createElement("div");s.setAttribute(i,"return;"),n="function"==typeof s[i]}return!n&&Br&&"wheel"===t&&(n=document.implementation.hasFeature("Events.wheel","3.0")),n};function Hr(t){var e=0,i=0,n=0,s=0;return"detail"in t&&(i=t.detail),"wheelDelta"in t&&(i=-t.wheelDelta/120),"wheelDeltaY"in t&&(i=-t.wheelDeltaY/120),"wheelDeltaX"in t&&(e=-t.wheelDeltaX/120),"axis"in t&&t.axis===t.HORIZONTAL_AXIS&&(e=i,i=0),n=10*e,s=10*i,"deltaY"in t&&(s=t.deltaY),"deltaX"in t&&(n=t.deltaX),(n||s)&&t.deltaMode&&(1==t.deltaMode?(n*=40,s*=40):(n*=800,s*=800)),n&&!e&&(e=n<1?-1:1),s&&!i&&(i=s<1?-1:1),{spinX:e,spinY:i,pixelX:n,pixelY:s}}Hr.getEventType=function(){return Wr.firefox()?"DOMMouseScroll":Ur("wheel")?"wheel":"mousewheel"};var Vr=Hr;const Gr={zoomOutFactor:.8,zoomInFactor:1.25,maxZoomFactor:1,minZoomFactor:.05,zoomDuration:300,zoomWheelConstant:20,zoomClamp:.6,panBounceStiffness:120,panBounceDamping:15,panTimeConstant:240,panPower:.1,nudgeDistance:100,panPadding:0,devicePixelRatio:1,enableWheel:!0,enableClickToZoom:!1,onPanInSketchMode:()=>{}},Xr=(t={})=>({start:function(e){const{zoomWheelConstant:i,enableWheel:n,enableClickToZoom:s}={...Gr,...t},r={pointerStart:{x:0,y:0},isPressing:!1,mousemoveBuffer:p(5),multiTouch:{distance:0}};function o(){e.world.constraintBounds(),h=0}function a(t){t.which>1?r.isPressing=!1:"explore"===e.mode&&(t.preventDefault(),r.pointerStart.x=t.atlas.x,r.pointerStart.y=t.atlas.y,e.transitionManager.stopTransition(),r.isPressing=!0)}function l(){r.isPressing&&("explore"===e.mode&&e.world.constraintBounds(),r.isPressing=!1)}e.world.activatedEvents.push("onMouseUp","onMouseDown","onMouseMove","onTouchStart","onTouchEnd","onTouchMove","onPointerUp","onPointerDown","onPointerMove");let h=0;function c(t){if("explore"===e.mode){if(1===t.atlasTouches.length&&(t.preventDefault(),r.pointerStart.x=t.atlasTouches[0].x,r.pointerStart.y=t.atlasTouches[0].y),2===t.atlasTouches.length){t.preventDefault();const e=t.atlasTouches[0].x,i=t.atlasTouches[1].x;r.pointerStart.x=(e+i)/2;const n=t.atlasTouches[0].y,s=t.atlasTouches[1].y;r.pointerStart.y=(n+s)/2,h=C({x:t.touches[0].clientX,y:t.touches[0].clientY},{x:t.touches[1].clientX,y:t.touches[1].clientY})}e.transitionManager.stopTransition(),r.isPressing=!0}}function d(t){if(r.isPressing){const i=e.getRendererScreenPosition();if(i){const{x:n,y:s}=e.viewerToWorld(t.clientX-i.x,t.clientY-i.y);e.transitionManager.customTransition((t=>{t.from=p(e.target),t.to=b(t.from,y(r.pointerStart.x-n,r.pointerStart.y-s),r.mousemoveBuffer),t.elapsed_time=0,t.total_time=0,t.timingFunction=Hs.easeInOutExpo,t.done=!1}))}}}function u(t){"explore"===e.mode&&e.world.zoomIn(t.atlas)}function g(t){const n=1+Vr(t).spinY/i;e.world.zoomTo(n,t.atlas,!0)}e.world.addEventListener("mouseup",o),e.world.addEventListener("touchend",o),e.world.addEventListener("touchstart",c),e.world.addEventListener("mousedown",a),window.addEventListener("touchend",l),window.addEventListener("mouseup",l),window.addEventListener("mousemove",d),window.addEventListener("touchmove",(function(t){let i=null,n=null,s=0;if(r.isPressing&&2===t.touches.length){i=(t.touches[0].clientX+t.touches[1].clientX)/2;n=(t.touches[0].clientY+t.touches[1].clientY)/2,s=C({x:t.touches[0].clientX,y:t.touches[0].clientY},{x:t.touches[1].clientX,y:t.touches[1].clientY})}if(r.isPressing&&1===t.touches.length){const e=t.touches[0];i=e.clientX,n=e.clientY}if(null!==i&&null!==n){const t=e.getRendererScreenPosition();if(t){const{x:o,y:a}=e.viewerToWorld(i-t.x,n-t.y),l=s&&h?s/h:1;e.transitionManager.customTransition((t=>{t.from=p(e.target),t.to=b(t.from,f(y(r.pointerStart.x-o,r.pointerStart.y-a),w(1/l,o,a)),r.mousemoveBuffer),t.elapsed_time=0,t.total_time=0,t.timingFunction=Hs.easeInOutExpo,t.done=!1}))}h=s}})),s&&(e.world.activatedEvents.push("onClick"),e.world.addEventListener("click",u)),n&&(e.world.activatedEvents.push("onWheel"),e.world.addEventListener("wheel",g));const m=e.world.addLayoutSubscriber(((t,i)=>{if("zone-changed"===t&&e.transitionManager.constrainBounds({transition:{duration:0}}),"zoom-to"===t&&i&&e.transitionManager.zoomTo(i.factor,{origin:i.point,stream:i.stream}),"go-home"===t){const t=i.immediate?{duration:0}:void 0;e.transitionManager.goToRegion({x:(n=e.homePosition)[1],y:n[2],width:n[3]-n[1],height:n[4]-n[2]},{transition:t})}var n;if("goto-region"===t&&i){const t=i.immediate?{duration:0}:{};e.transitionManager.goToRegion(i,{transition:t})}"constrain-bounds"===t&&e.transitionManager.constrainBounds({transition:(null==i?void 0:i.immediate)?{duration:0}:void 0})}));return()=>{e.world.removeEventListener("mouseup",o),e.world.removeEventListener("touchend",o),e.world.removeEventListener("touchstart",c),e.world.removeEventListener("mousedown",a),window.removeEventListener("touchend",l),window.removeEventListener("mouseup",l),e.world.removeEventListener("mousemove",d),e.world.removeEventListener("touchmove",d),s&&e.world.removeEventListener("click",u),n&&e.world.removeEventListener("wheel",g),m()}},updatePosition(){}}),Yr=a.default.createContext("explore");Yr.displayName="Mode";const Kr=()=>e.useContext(Yr);function Qr(t,e,i){var n,s,r,o,a;function l(){var h=Date.now()-o;h<e&&h>=0?n=setTimeout(l,e-h):(n=null,i||(a=t.apply(r,s),r=s=null))}null==e&&(e=100);var h=function(){r=this,s=arguments,o=Date.now();var h=i&&!n;return n||(n=setTimeout(l,e)),h&&(a=t.apply(r,s),r=s=null),a};return h.clear=function(){n&&(clearTimeout(n),n=null)},h.flush=function(){n&&(a=t.apply(r,s),r=s=null,clearTimeout(n),n=null)},h}Qr.debounce=Qr;var qr=Qr;function Zr(t){let{debounce:i,scroll:n,polyfill:s,offsetSize:r}=void 0===t?{debounce:0,scroll:!1,offsetSize:!1}:t;const o=s||("undefined"==typeof window?class{}:window.ResizeObserver);if(!o)throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");const[a,l]=e.useState({left:0,top:0,width:0,height:0,bottom:0,right:0,x:0,y:0}),h=e.useRef({element:null,scrollContainers:null,resizeObserver:null,lastBounds:a}),c=i?"number"==typeof i?i:i.scroll:null,d=i?"number"==typeof i?i:i.resize:null,u=e.useRef(!1);e.useEffect((()=>(u.current=!0,()=>{u.current=!1})));const[p,f,g]=e.useMemo((()=>{const t=()=>{if(!h.current.element)return;const{left:t,top:e,width:i,height:n,bottom:s,right:o,x:a,y:c}=h.current.element.getBoundingClientRect(),d={left:t,top:e,width:i,height:n,bottom:s,right:o,x:a,y:c};h.current.element instanceof HTMLElement&&r&&(d.height=h.current.element.offsetHeight,d.width=h.current.element.offsetWidth),Object.freeze(d),u.current&&!eo(h.current.lastBounds,d)&&l(h.current.lastBounds=d)};return[t,d?qr(t,d):t,c?qr(t,c):t]}),[l,r,c,d]);function m(){h.current.scrollContainers&&(h.current.scrollContainers.forEach((t=>t.removeEventListener("scroll",g,!0))),h.current.scrollContainers=null),h.current.resizeObserver&&(h.current.resizeObserver.disconnect(),h.current.resizeObserver=null)}function v(){h.current.element&&(h.current.resizeObserver=new o(g),h.current.resizeObserver.observe(h.current.element),n&&h.current.scrollContainers&&h.current.scrollContainers.forEach((t=>t.addEventListener("scroll",g,{capture:!0,passive:!0}))))}var y,w,b;return y=g,w=Boolean(n),e.useEffect((()=>{if(w){const t=y;return window.addEventListener("scroll",t,{capture:!0,passive:!0}),()=>{window.removeEventListener("scroll",t,!0)}}}),[y,w]),b=f,e.useEffect((()=>{const t=b;return window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}}),[b]),e.useEffect((()=>{m(),v()}),[n,g,f]),e.useEffect((()=>m),[]),[t=>{t&&t!==h.current.element&&(m(),h.current.element=t,h.current.scrollContainers=Jr(t),v())},a,p]}function Jr(t){const e=[];if(!t||t===document.body)return e;const{overflow:i,overflowX:n,overflowY:s}=window.getComputedStyle(t);return[i,n,s].some((t=>"auto"===t||"scroll"===t))&&e.push(t),[...e,...Jr(t.parentElement)]}const to=["x","y","top","bottom","left","right","width","height"],eo=(t,e)=>to.every((i=>t[i]===e[i])),io=a.default.createContext(null);io.displayName="Atlas";const no=a.default.createContext(null);let so;no.displayName="Bounds";if("object"==typeof performance&&"function"==typeof performance.now){const t=performance;so=()=>t.now()}else{const t=Date,e=t.now();so=()=>t.now()-e}function ro(t,e){t&&t.appendChild&&e&&t.appendChild(e)}function oo(t,e){t&&t.removeChild&&e&&t.removeChild(e)}function ao(t,e,i){t&&t instanceof Gs&&(t=t.world),t&&t.insertBefore&&t.insertBefore(e,i)}function lo(t,e,i){if(i&&(t.applyProps&&t.applyProps(i),t instanceof E))for(const n of h){const s=n.slice(2).toLowerCase();i[n]!==e[n]&&(e[n]&&t.removeEventListener(s,e[n]),t.addEventListener(s,i[n]))}}function ho(t,e){const i=Object.keys(e);let n=!1;for(const s of i)if(-1!==h.indexOf(s)){const e=d[s];if(e){if(-1!==t.activatedEvents.indexOf(e))continue;n=!0,t.activatedEvents.push(e)}}n&&t.triggerEventActivation()}const co=new Map,uo={};const po=l.default({unstable_now:so,now:so,createInstance:function(t,{args:e=[],...i},n,s,r){if(!(n instanceof Gs)&&r){const t=e=>e.return?t(e.return):e.stateNode&&e.stateNode.containerInfo;n=t(r)}let o,a=n.world;switch(t){case"world":o=ks.withProps({width:i.width,height:i.height,viewingDirection:"left-to-right"}),o.activatedEvents=a.activatedEvents,o.eventHandlers=a.eventHandlers,o.subscriptions=a.subscriptions,o.triggerEventActivation(),a=o;break;case"box":o=new Is;break;case"shape":o=new pr;break;case"worldObject":case"world-object":o=new Cs;break;case"worldImage":case"world-image":o=new S;break;case"texture":o=new _;break;case"compositeImage":case"composite-image":o=new _s({id:i.id,width:i.width,height:i.height,images:[]});break;case"tiledImage":case"tiled-image":o=Es.fromTile(i.uri,i.display,i.tile,i.scaleFactor,void 0,i.format);break;case"paragraph":o=new Ls,o.text=i.children;break;default:return}return ho(a,i),lo(o,{},i),o},removeChild:oo,appendChild:ro,appendInitialChild:ro,insertBefore:ao,warnsIfNotActing:!0,supportsMutation:!0,isPrimaryRenderer:!1,scheduleTimeout:"undefined"!=typeof setTimeout?setTimeout:void 0,cancelTimeout:"undefined"!=typeof clearTimeout?clearTimeout:void 0,setTimeout:"undefined"!=typeof setTimeout?setTimeout:void 0,clearTimeout:"undefined"!=typeof clearTimeout?clearTimeout:void 0,noTimeout:-1,appendChildToContainer:function(t,e){if(e instanceof ks)t.world=e;else if(e instanceof Cs)t.world.appendChild(e);else if(e)throw new Error("Invalid root")},removeChildFromContainer:function(t,e){return oo(t.world,e)},createTextInstance(){},insertInContainerBefore:function(t,e,i){return ao(t.world,e,i)},prepareUpdate:(t,e,i,n,s)=>(ho(s.world,n),n),commitUpdate(t,e,i,n,s,r){t.applyProps&&e&&lo(t,n,e)},finalizeInitialChildren:t=>null==t?void 0:t.__handlers,getChildHostContext:()=>uo,getRootHostContext:()=>uo,prepareForCommit:t=>(t.isCommitting=!0,null),preparePortalMount(){},hideInstance(t){t&&t.points&&(t.points[0]=0)},unhideInstance(t,e){t&&t.points&&(t.points[0]=1)},getPublicInstance:t=>t,hideTextInstance(){throw new Error("Text is not allowed in the react-three-fibre tree. You may have extraneous whitespace between components.")},resetAfterCommit(t){t.isCommitting=!1,t.pendingUpdate=!0,t.world&&t.world.needsRecalculate&&(t.world.recalculateWorldSize(),t.world.triggerRepaint())},shouldSetTextContent:()=>!1,clearContainer:()=>!1});function fo(t,e){const i=co.get(t);i&&po.updateContainer(null,i,null,(()=>{co.delete(t),e&&e(t)}))}po.injectIntoDevTools({bundleType:0,version:e.version,rendererPackageName:"@atlas-viewer/atlas"});const go={render(t,e){const i=co.get(e);if(i)po.updateContainer(t,i,null,(()=>{}));else{const i=po.createContainer(e,0,null,!1,null,"",(()=>{}),null);po.updateContainer(t,i,null,null),co.set(e,i)}},unmountComponentAtNode(t,e){fo(t,e)}},mo=a.default.memo((({children:t,setIsReady:i,onCreated:n,bounds:s,preset:r,mode:o="explore"})=>{const l=e.useCallback((function(t){const s=e.useRef(!1),o=()=>{i(!0)};return e.useEffect((()=>{if(!r||s.current)return()=>{};{r.runtime.goHome();const t=n&&n(r);t&&t.then?t.then(o):o()}}),[]),e.useEffect((()=>{s.current=!0}),[]),t.children}),[r]);return e.useLayoutEffect((()=>{if(r){const e=r.runtime;o!==e.mode&&(e.mode=o),go.render(a.default.createElement(a.default.StrictMode,null,a.default.createElement(l,null,a.default.createElement(no.Provider,{value:s},a.default.createElement(Yr.Provider,{value:o},a.default.createElement(io.Provider,{value:r},t))))),e)}}),[r,o,t]),e.useLayoutEffect((()=>{if(r){const t=r.runtime;return()=>{go.unmountComponentAtNode(t)}}return()=>{}}),[r]),null}));class vo{constructor(t,e){this.fragmentShaderSource="\n precision mediump float;\n\n uniform sampler2D u_image;\n varying vec2 v_texCoord;\n\n void main() {\n gl_FragColor = texture2D(u_image, v_texCoord);\n }\n ",this.vertexShaderSource="\n attribute vec2 a_position;\n uniform vec2 u_resolution;\n varying vec4 v_color;\n uniform sampler2D u_texture;\n\n attribute vec2 a_texCoord;\n varying vec2 v_texCoord;\n\n void main() {\n\n // convert the position from pixels to 0.0 to 1.0\n vec2 zeroToOne = a_position / u_resolution;\n\n // convert from 0->1 to 0->2\n vec2 zeroToTwo = zeroToOne * 2.0;\n\n // convert from 0->2 to -1->+1 (clip space)\n vec2 clipSpace = zeroToTwo - 1.0;\n\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n \n v_texCoord = a_texCoord;\n }\n ",this.lastResize=0,this.lastKnownScale=1,this.canvas=t,this.rendererPosition=t.getBoundingClientRect(),this.gl=t.getContext("webgl2"),this.fragmentShader=this.createShader(this.gl.FRAGMENT_SHADER,this.fragmentShaderSource),this.vertexShader=this.createShader(this.gl.VERTEX_SHADER,this.vertexShaderSource),this.program=this.createProgram(this.vertexShader,this.fragmentShader),this.dpi=(null==e?void 0:e.dpi)||1,this.attributes={position:this.gl.getAttribLocation(this.program,"a_position"),texCoord:this.gl.getAttribLocation(this.program,"a_texCoord")},this.uniforms={resolution:this.gl.getUniformLocation(this.program,"u_resolution"),texture:this.gl.getUniformLocation(this.program,"u_texture")},this.buffers={position:this.createArrayBuffer(),texCoord:this.createArrayBuffer(new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]))},this.rectBuffer=new Float32Array(12),this.resize(),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.enableVertexAttribArray(this.attributes.position)}resize(){this.resizeCanvasToDisplaySize(),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.rendererPosition=this.canvas.getBoundingClientRect()}isReady(){return!0}beforeFrame(t,e,i){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.vertexAttribPointer(this.attributes.position,2,this.gl.FLOAT,!1,0,0),this.gl.uniform2f(this.uniforms.resolution,this.gl.canvas.width,this.gl.canvas.height),this.lastResize>1e3&&(this.lastResize=0,this.resizeCanvasToDisplaySize()),this.lastResize+=e}prepareLayer(t){t.__host&&t.__host.webgl||((t instanceof S||t instanceof Es)&&this.createImageHost(t),t instanceof _&&this.createTextureHost(t))}createTextureHost(t){t.__host=t.__host?t.__host:{};const e=this.gl,i=this.gl.createTexture();let n;if(e.bindTexture(e.TEXTURE_2D,i),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),t instanceof _){const i=t.getTexture();i.source&&e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i.source),n=i}e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),t.__host.webgl={height:t.height,width:t.width,texture:i,lastImage:n}}createImageHost(t){const e=[...new Array(t.points.length/5)];t.__host=t.__host?t.__host:{},t.__host.webgl={height:t.height,width:t.width,textures:e,loading:[],loaded:[],lastLevelRendered:-1,onLoad:(e,i)=>{const n=this.gl,s=this.gl.createTexture();n.bindTexture(n.TEXTURE_2D,s),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),t.__host.webgl.textures[e]=s,t.__host.webgl.loaded.push(e)}}}paint(t,e,i,n,s,r){if("spacial-content"===t.type&&t.__host&&t.__host.webgl){if(t.getTexture){const e=null==t?void 0:t.getTexture();if(e&&t.__host.webgl.lastImage!==e.hash&&e.source&&!t.__host.webgl.error)try{const i=0,n=this.gl.RGBA,s=this.gl.RGBA,r=this.gl.UNSIGNED_BYTE;this.gl.bindTexture(this.gl.TEXTURE_2D,t.__host.webgl.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,i,n,s,r,e.source),t.__host.webgl.lastImage=e.hash}catch(o){t.__host.webgl.error=o}}if(t.__host.webgl.loading&&-1===t.__host.webgl.loading.indexOf(e)&&t.getImageUrl){t.__host.webgl.loading.push(e);const i=document.createElement("img");i.decoding="async",i.crossOrigin="anonymous",i.src=t.getImageUrl(e),i.onload=()=>(i.onload=null,t.__host.webgl.onLoad(e,i))}const a=t.__host.webgl.texture?t.__host.webgl.texture:t.__host.webgl.textures[e];a&&(this.gl.enableVertexAttribArray(this.attributes.texCoord),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.texCoord),this.gl.enableVertexAttribArray(this.attributes.texCoord),this.gl.vertexAttribPointer(this.attributes.texCoord,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.buffers.position),this.gl.enableVertexAttribArray(this.attributes.position),this.gl.vertexAttribPointer(this.attributes.position,2,this.gl.FLOAT,!1,0,0),this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.uniforms.texture,0),this.setRectangle(i,n,s,r),this.gl.drawArrays(this.gl.TRIANGLES,0,6))}}afterPaintLayer(t,e){}pendingUpdate(){return!0}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}afterFrame(){}getScale(t,e,i){if(Number.isNaN(t)||Number.isNaN(e))return this.lastKnownScale;const n=this.getCanvasDims(),s=n.width/t,r=n.height/e,o=(s<r?r:s)*(i&&this.dpi||1);return Number.isNaN(o)||(this.lastKnownScale=o),this.lastKnownScale}getCanvasDims(){return{width:this.canvas.width/this.dpi,height:this.canvas.height/this.dpi}}getViewportBounds(t,e,i){return null}createShader(t,e){const i=this.gl.createShader(t);if(i){this.gl.shaderSource(i,e),this.gl.compileShader(i);if(this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS))return i;const t=this.gl.getShaderInfoLog(i);if(this.gl.deleteShader(i),t)throw new Error(t)}throw new Error("Invalid shader")}createProgram(t,e){const i=this.gl.createProgram();if(i){this.gl.attachShader(i,t),this.gl.attachShader(i,e),this.gl.linkProgram(i);if(this.gl.getProgramParameter(i,this.gl.LINK_STATUS))return i;const n=this.gl.getProgramInfoLog(i);if(this.gl.deleteProgram(i),n)throw new Error(n)}throw new Error("Invalid program")}resizeCanvasToDisplaySize(){const t=this.gl.canvas,e=t.clientWidth,i=t.clientHeight,n=t.width!==e||t.height!==i;return n&&(t.width=e,t.height=i),n}createArrayBuffer(t){const e=this.gl.createBuffer();if(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e),t&&this.gl.bufferData(this.gl.ARRAY_BUFFER,t,this.gl.STATIC_DRAW),!e)throw new Error("Cannot create buffer");return e}setRectangle(t,e,i,n){this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getRectangle(t,e,i,n),this.gl.STATIC_DRAW)}getRectangle(t,e,i,n){const s=t,r=t+i,o=e,a=e+n;return this.rectBuffer.set([s,o,r,o,s,a,s,a,r,o,r,a]),this.rectBuffer}getRendererScreenPosition(){return this.rendererPosition}finishLayer(){}reset(){}}function yo(t,e){const i=e?t:JSON.stringify(t);let n=5381,s=i.length;for(;s;)n=33*n^i.charCodeAt(--s);const r=(n>>>0).toString(16);return r.length%2?"0"+r:r}class wo{constructor(t){this.sheetPrefix=(null==t?void 0:t.sheetPrefix)||"a-",this.$element=document.createElement("style"),this.stylesheetClasses=[],this.activeStylesheetClasses=[],this.sheetsDidUpdate=!1,this.stylesheetEntries={}}getElement(){return this.$element}addStylesheet(t){const e=t.replace(/\s\s+/g," ").replace(/: /g,":").replace(/; /g,";").trim(),i=this.sheetPrefix+yo(e,!0);return-1!==this.stylesheetClasses.indexOf(i)||(this.stylesheetClasses.push(i),this.activeStylesheetClasses.push(i),this.stylesheetEntries[i]=e,this.sheetsDidUpdate=!0),i}removeStylesheet(t){const e=this.sheetPrefix+yo(t,!0);this.stylesheetClasses.indexOf(e)&&(this.stylesheetClasses=this.stylesheetClasses.filter((t=>t!==e))),this.sheetsDidUpdate=!0}clearClasses(){this.activeStylesheetClasses=[]}didUpdateActive(){if(this.activeStylesheetClasses.length){for(const t of this.activeStylesheetClasses)if(-1===this.stylesheetClasses.indexOf(t))return!0;for(const t of this.stylesheetClasses)if(-1===this.activeStylesheetClasses.indexOf(t))return!0}return!1}updateSheet(){(this.sheetsDidUpdate||this.didUpdateActive())&&(this.$element.innerText=this.activeStylesheetClasses.map((t=>`.${t}{${this.stylesheetEntries[t]}}`)).join(""),this.sheetsDidUpdate=!1,this.stylesheetClasses=[...this.activeStylesheetClasses])}}class bo{constructor(t,e){this.visible=[],this.previousVisible=[],this.htmlIds=[],this.firstMeaningfulPaint=!1,this.paintTx=1,this.zIndex=0,this.htmlContainer=t,this.htmlContainer.innerHTML="",this.rendererPosition=this.htmlContainer.getBoundingClientRect(),this.options={triggerResize:()=>{},box:!1,text:!1,sheetPrefix:"",inlineStyles:!1,background:"",...e||{}},this.stylesheet=new wo({sheetPrefix:this.options.sheetPrefix}),this.options.inlineStyles||this.htmlContainer.appendChild(this.stylesheet.getElement()),this.options.background&&this.htmlContainer.classList.add(this.stylesheet.addStylesheet(`\n background: ${this.options.background};\n `)),this.classes={hostClassName:this.stylesheet.addStylesheet("\n position: absolute;\n transform-origin: 0px 0px;\n "),interactive:this.stylesheet.addStylesheet("pointer-events: all"),nonInteractive:this.stylesheet.addStylesheet("pointer-events: none")},this.stylesheet.updateSheet()}createHtmlHost(t){if(this.htmlContainer&&(this.options.box||t.props.className||t.props.html||t.props.href)){const e=document.createElement(t.props.href?"a":"div");if(t.props.href){e.style.display="block",e.href=t.props.href;const i=t.props.hrefTarget||"_blank";e.target=i,"_self"!==i&&(e.rel="noopener noreferrer")}e.title=t.props.title||"",this.options.inlineStyles?(e.style.display="block",e.style.position="absolute",e.style.overflow="hidden",e.style.transformOrigin="0px 0px"):e.classList.add(this.classes.hostClassName),t.__host={element:e,revision:null,relative:!1},this.updateHtmlHost(t,t.width,t.height),t.__onCreate&&t.__onCreate()}}triggerResize(){this.options.triggerResize()}updateHtmlHost(t,e,i){if(t.__revision!==t.__host.revision){const n=t.__host.element,s=[this.classes.hostClassName];if(t.props.interactive?this.options.inlineStyles?n.style.pointerEvents="all":s.push(this.classes.interactive):this.options.inlineStyles?n.style.pointerEvents="none":s.push(this.classes.nonInteractive),t.props.href){n.style.display="block",n.href=t.props.href;const e=t.props.hrefTarget||"_blank";n.target=e,n.rel="_self"!==e?"noopener noreferrer":""}else n.href&&n.removeAttribute("href");t.props.title&&(n.title=t.props.title||""),t.props.className&&(s.push(t.props.className),t.hovering&&s.push(`${t.props.className}--hover`),t.pressing&&s.push(`${t.props.className}--active`)),t.props.relativeStyle?(n.style.width=`${e||t.width}px`,n.style.height=`${i||t.height}px`):(n.style.width=`${t.width}px`,n.style.height=`${t.height}px`);if(t.props.style)return void Object.assign(n.style,t.props.style||{},t.hovering&&t.props.hoverStyles||{},t.pressing&&t.props.pressStyles||{});if(this.options.text&&t instanceof Ls){t.text&&(n.innerText=t.text),t.backgroundColor&&(n.style.backgroundColor=t.backgroundColor),t.color&&(n.style.color=t.color),t.props.font&&(n.style.font=t.props.font),t.props.textAlign&&(n.style.textAlign=t.props.textAlign),t.__host.revision=t.__revision;const e=s.join(" ");n.className=e,n.part=e}t instanceof Is&&(this.options.box||t.props.className||t.props.html)&&(t.props.backgroundColor&&(n.style.backgroundColor=t.props.backgroundColor),t.props.border!==n.style.border&&(n.style.border=t.props.border));const r=s.join(" ");n.className=r,n.part=r}}afterFrame(t,e,i){this.stylesheet.updateSheet();for(const n of this.previousVisible)-1===this.visible.indexOf(n)&&this.htmlContainer&&n.__id&&-1!==this.htmlIds.indexOf(n.__id)&&this.htmlContainer.removeChild(n.__host.element);this.previousVisible=this.visible}afterPaintLayer(t,e){}beforeFrame(t,e,i){this.stylesheet.clearClasses(),this.paintTx++,this.zIndex=0,this.visible=[]}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}getScale(t,e){const i=this.rendererPosition.width/t,n=this.rendererPosition.height/e;return i<n?n:i}getViewportBounds(t,e,i){return null}isReady(){return!1}paint(t,e,i,n,s,r){if(this.zIndex++,(this.options.text&&t instanceof Ls||t instanceof Is&&(this.options.box||t.props.className||t.props.html))&&t.__host.tx!==this.paintTx&&(this.visible.push(t),t.__host.tx=this.paintTx,this.htmlContainer)){this.updateHtmlHost(t,s,r);const e=s/t.width,o=t.__host.element;o.style.zIndex=`${this.zIndex}`,t.props.relativeStyle?o.style.transform=`translate(${Math.round(i)}px, ${Math.round(n)}px)`:o.style.transform=`translate(${Math.round(i)}px, ${Math.round(n)}px) scale(${e})`,-1===this.previousVisible.indexOf(t)&&this.htmlContainer.appendChild(o),-1===this.htmlIds.indexOf(t.__id)&&this.htmlIds.push(t.__id)}}pendingUpdate(){return!1}prepareLayer(t){t.__host||(t instanceof Ls||t instanceof Is)&&this.createHtmlHost(t)}resize(t,e){void 0!==t&&void 0!==e&&(this.htmlContainer.style.width=`${t}px`,this.htmlContainer.style.height=`${e}px`),this.rendererPosition=this.htmlContainer.getBoundingClientRect()}getRendererScreenPosition(){return this.rendererPosition}finishLayer(){}reset(){}}const xo=class{constructor(t,e,i){this.activatedEvents=[],this.eventHandlers=[],this.pointerMoveEvent=void 0,this.pointerEventState={isClicking:!1,isDragging:!1,isPressed:!1,mousedOver:[],itemsBeingDragged:[],mouseDownStart:{x:0,y:0},lastTouches:[]},this._realPointerMove=t=>{this.pointerMoveEvent=t},this.onWheelEvent=t=>{t.preventDefault(),this.onPointerEvent(t)},this.onTouchEvent=t=>{const e=d[t.type],i=[],n=t.touches.length;for(let s=0;s<n;s++){const e=t.touches.item(s);if(!e)continue;const{x:n,y:r}=this.runtime.viewerToWorld(e.clientX-this.bounds.left,e.clientY-this.bounds.top),o={id:e.identifier,x:n,y:r};i.push(o)}i.length&&this.assignToEvent(t,i[0].x,i[0].y),"onTouchEnd"!==e?(this.pointerEventState.lastTouches=i,t.atlasTouches=i,this.runtime.world.propagateTouchEvent(e,t,i)):(t.atlasTouches=[],this.runtime.world.propagateTouchEvent(e,t,this.pointerEventState.lastTouches),this.pointerEventState.lastTouches=[])},this.onPointerEvent=t=>{const e=d[t.type];if(e&&-1!==this.runtime.world.activatedEvents.indexOf(e)){const{x:i,y:n}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);this.assignToEvent(t,i,n),this.runtime.world.propagatePointerEvent(e,t,i,n)}},this.onPointerDown=t=>{this.pointerEventState.isPressed=!0,this.pointerEventState.isClicking=!0,this.pointerEventState.mouseDownStart.x=t.clientX,this.pointerEventState.mouseDownStart.y=t.clientY,setTimeout((()=>{this.runtime&&(this.pointerEventState.isClicking=!1)}),250),setTimeout((()=>{if(this.runtime&&this.pointerEventState.isPressed&&!this.pointerEventState.isDragging){const e=this.runtime.viewerToWorld(this.pointerEventState.mouseDownStart.x-this.bounds.left,this.pointerEventState.mouseDownStart.y-this.bounds.top);this.pointerEventState.isDragging=!0,this.pointerEventState.itemsBeingDragged=this.runtime.world.propagatePointerEvent("onDragStart",t,e.x,e.y)}}),800),this.onPointerEvent(t)},this.onPointerUp=t=>{if(this.pointerEventState.isClicking){const{x:e,y:i}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);this.assignToEvent(t,e,i),this.runtime.world.propagatePointerEvent("onClick",t,e,i)}if(this.pointerEventState.isDragging){for(const e of this.pointerEventState.itemsBeingDragged)e.dispatchEvent("onDragEnd",t);this.pointerEventState.isDragging=!1}this.pointerEventState.isClicking=!1,this.pointerEventState.isPressed=!1,this.pointerEventState.itemsBeingDragged=[],this.onPointerEvent(t)},this.onPointerMove=t=>{this.pointerMoveEvent=void 0;const{x:e,y:i}=this.runtime.viewerToWorld(t.clientX-this.bounds.left,t.clientY-this.bounds.top);if(Number.isNaN(e)||Number.isNaN(i))return;this.assignToEvent(t,e,i),this.runtime.world.propagatePointerEvent("onPointerMove",t,e,i);const n=this.runtime.world.propagatePointerEvent("onMouseMove",t,e,i),s=[],r=[];for(const o of n)s.push(o.id),r.push(o),-1===this.pointerEventState.mousedOver.indexOf(o)&&(o.dispatchEvent("onMouseEnter",t),o.dispatchEvent("onPointerEnter",t),o.dispatchEvent("onMouseOver",t),o.dispatchEvent("onPointerOver",t));for(const o of this.pointerEventState.mousedOver)-1===s.indexOf(o.id)&&(o.dispatchEvent("onMouseLeave",t),o.dispatchEvent("onPointerLeave",t),o.dispatchEvent("onMouseOut",t),o.dispatchEvent("onPointerOut",t));if(this.pointerEventState.isDragging)for(const o of this.pointerEventState.itemsBeingDragged)o.dispatchEvent("onDrag",t);if(this.pointerEventState.isPressed&&!this.pointerEventState.isDragging&&C(this.pointerEventState.mouseDownStart,{x:t.clientX,y:t.clientY})>50){const e=this.runtime.viewerToWorld(this.pointerEventState.mouseDownStart.x-this.bounds.left,this.pointerEventState.mouseDownStart.y-this.bounds.top);this.pointerEventState.isDragging=!0,this.pointerEventState.itemsBeingDragged=this.runtime.world.propagatePointerEvent("onDragStart",{...t,atlas:{x:e.x,y:e.y}},e.x,e.y)}this.pointerEventState.mousedOver=r},this.element=t,this.runtime=e,this.unsubscribe=e.world.addLayoutSubscriber(this.layoutSubscriber.bind(this)),this.bounds=t.getBoundingClientRect(),this.options={simulationRate:0,...i||{}};let n=0;e.registerHook("useFrame",(t=>{n+=t,n>this.options.simulationRate&&this.pointerMoveEvent&&(n=0,e.updateNextFrame())})),e.registerHook("useBeforeFrame",(()=>{this.pointerMoveEvent&&this.onPointerMove(this.pointerMoveEvent)})),this.activateEvents()}updateBounds(){this.bounds=this.element.getBoundingClientRect(),this.runtime.updateRendererScreenPosition()}layoutSubscriber(t){"event-activation"===t&&this.activateEvents()}assignToEvent(t,e,i){xo.eventPool.atlas.x=e,xo.eventPool.atlas.y=i,t.atlas=xo.eventPool.atlas}activateEvents(){this.element.addEventListener("pointermove",this._realPointerMove),this.element.addEventListener("pointerup",this.onPointerUp),this.element.addEventListener("pointerdown",this.onPointerDown),this.element.addEventListener("mousedown",this.onPointerEvent),this.element.addEventListener("mouseup",this.onPointerEvent),this.element.addEventListener("pointercancel",this.onPointerEvent),this.element.addEventListener("wheel",this.onWheelEvent),this.element.addEventListener("touchstart",this.onTouchEvent),this.element.addEventListener("touchcancel",this.onTouchEvent),this.element.addEventListener("touchend",this.onTouchEvent),this.element.addEventListener("touchmove",this.onTouchEvent)}normalizeEventName(t){return t.startsWith("on")?t.slice(2).toLowerCase():t.toLowerCase()}stop(){this.unsubscribe();for(const[t,e]of this.eventHandlers)this.element.removeEventListener(this.normalizeEventName(t),e)}};let Eo=xo;function So({interactive:t=!0,viewport:e,forceRefresh:i,canvasElement:n,overlayElement:s,controllerConfig:r,unstable_webglRenderer:o,dpi:a,debug:l,canvasBox:h=!0,polygon:c=!0,navigatorElement:d,background:u,runtimeOptions:p}){if(!n)throw new Error("Invalid container");n.style.userSelect="none";const f=t?Xr({minZoomFactor:.5,maxZoomFactor:3,enableClickToZoom:!1,...r||{}}):void 0,g=new yr([o?new vo(n,{dpi:a}):new vr(n,{dpi:a,debug:l,box:h,polygon:c,background:u}),s?new bo(s,{box:o||!h,text:!0,triggerResize:i}):void 0,d?new wr(d):void 0]),m=new Gs(g,new ks(1024,1024),e,f?[f]:[],p),v=new Eo(n,m);return{name:"default-preset",em:v,runtime:m,renderer:g,controller:f,canvas:n,navigator:d,unmount(){fo(m),m.stopControllers(),m.stop(),m.reset(),v&&v.stop()}}}Eo.eventPool={atlas:{x:0,y:0}};class _o{constructor(t,e){this.pending=!0,this.zIndex=0,this.lastKnownScale=1,this.currentlyVisible=[],this.previouslyVisible=[],this.container=t,this.rendererPosition=t.getBoundingClientRect();const{width:i,height:n}=this.rendererPosition;this.width=i,this.height=n,this.options={addPart:!1,setDraggableFalse:!1,imageClass:"",widthStylesheet:!1,sheetPrefix:"position-",background:"#000",...e||{}},this.stylesheet=new wo({sheetPrefix:this.options.sheetPrefix}),this.container.classList.add(this.stylesheet.addStylesheet(`\n background: ${this.options.background};\n `)),this.options.widthStylesheet&&this.container.appendChild(this.stylesheet.getElement())}isReady(){return!0}resize(){this.rendererPosition=this.container.getBoundingClientRect(),this.width=this.rendererPosition.width,this.height=this.rendererPosition.height}getRendererScreenPosition(){return this.rendererPosition}afterFrame(t,e,i){this.stylesheet.updateSheet();for(const n of this.previouslyVisible)-1===this.currentlyVisible.indexOf(n)&&this.container.removeChild(n);for(const n of this.currentlyVisible)-1===this.previouslyVisible.indexOf(n)&&this.container.appendChild(n);this.previouslyVisible=this.currentlyVisible,this.currentlyVisible=[]}afterPaintLayer(t,e){}beforeFrame(t,e,i){this.stylesheet.clearClasses(),this.zIndex=0}getPointsAt(t,e,i,n){return t.getPointsAt(e,i,n)}getScale(t,e){if(Number.isNaN(t)||Number.isNaN(e))return this.lastKnownScale;const i=this.width/t,n=this.height/e,s=i<n?n:i;return Number.isNaN(s)||(this.lastKnownScale=s),this.lastKnownScale}getViewportBounds(t,e,i){return null}createImage(){const t=document.createElement("img");return this.options.imageClass?(t.className=this.options.imageClass,this.options.addPart&&t.setAttribute("part",this.options.imageClass)):(t.style.position="absolute",t.style.pointerEvents="none",t.style.userSelect="none"),this.options.setDraggableFalse&&t.setAttribute("draggable","false"),t}paint(t,e,i,n,s,r){if(this.pending=!1,this.zIndex++,t instanceof S){if(!t.__host){const e=this.createImage();e.src=t.uri,t.__host=e,this.container.appendChild(t.__host)}const e=t.__host;this.currentlyVisible.push(e),e.style.zIndex=`${this.zIndex}`,e.style.opacity=`${t.style.opacity}`,this.options.widthStylesheet?e.className=this.options.imageClass+" "+this.stylesheet.addStylesheet(`width:${(s+Number.MIN_VALUE).toFixed(2)}px;height:${(r+Number.MIN_VALUE).toFixed(2)}px;`):(e.style.width=`${s+Number.MIN_VALUE}px`,e.style.height=`${r+Number.MIN_VALUE}px`),e.style.transform=`translate(${i}px, ${n}px)`}if(t instanceof Es){if(t.__host||(t.__host={images:[]}),!t.__host.images[e]){const i=t.getImageUrl(e),n=this.createImage();n.src=i,t.__host.images[e]=n,this.container.appendChild(n)}const o=t.__host.images[e];o.style.zIndex=`${this.zIndex}`,o.style.opacity=`${t.style.opacity}`,this.currentlyVisible.push(o),this.options.widthStylesheet?o.className=this.options.imageClass+" "+this.stylesheet.addStylesheet(`width:${(s+Number.MIN_VALUE).toFixed(2)}px;height:${(r+Number.MIN_VALUE).toFixed(2)}px;`):(o.style.width=`${s+Number.MIN_VALUE}px`,o.style.height=`${r+Number.MIN_VALUE}px`),o.style.transform=`translate(${i}px, ${n}px)`}}pendingUpdate(){return this.pending}prepareLayer(t){}finishLayer(t){}reset(){}}function To({interactive:t,viewport:e,forceRefresh:i,containerElement:n,overlayElement:s,controllerConfig:r,background:o}){if(!n)throw new Error("Invalid container");n.style.userSelect="none";const a=t?Xr({minZoomFactor:.5,maxZoomFactor:3,enableClickToZoom:!1,...r||{}}):void 0,l=new _o(n,{addPart:!1,setDraggableFalse:!1,imageClass:"atlas-static-image",background:o}),h=s?new yr([l,new bo(s,{box:!0,text:!0,triggerResize:i})]):l,c=new Gs(h,new ks(1024,1024),e,a?[a]:[]),d=new Eo(n,c);return{name:"static-preset",em:d,runtime:c,renderer:h,controller:a,container:n,overlay:s,unmount(){fo(c),c.stopControllers(),c.stop(),d&&d.stop()}}}const Co={"default-preset":So,"static-preset":To},ko={};function Po(t,i){const n=e.useRef(),s=e.useRef(),r=e.useRef(),o=e.useRef(),a=e.useRef({width:i.width,height:i.height,didUpdate:!0}),[l="default-preset",h=ko]=Array.isArray(t)?t||[]:[t],[c,d]=e.useState(null);e.useLayoutEffect((()=>{const t=s.current,e=o.current,c=n.current,u=r.current,p=(Co[l]||So)({containerElement:e,canvasElement:t,overlayElement:c,navigatorElement:u,viewport:a.current,dpi:window.devicePixelRatio||1,forceRefresh:i.forceRefresh,unstable_webglRenderer:i.unstable_webglRenderer,...h||{}});return d(p),()=>{p&&(p.unmount(),t&&(t.height=0,t.width=0),c&&(c.innerHTML=""),u&&(u.height=0,u.width=0))}}),[l,h]);const u=e.useMemo((()=>({canvas:s,overlay:n,container:o,navigator:r})),[]);return[l,c,a,u]}const Oo=a.default.forwardRef(((t,e)=>a.default.createElement("div",{...t,ref:e,part:t.className}))),Ro=({htmlChildren:t,renderPreset:i,onCreated:n,mode:s="explore",resetWorldOnChange:r=!0,unstable_webglRenderer:o=!1,unstable_noReconciler:l=!1,hideInlineStyle:h=!1,controllerConfig:c,children:d,overlayStyle:u,containerStyle:p,enableNavigator:f,className:g,containerProps:m={},homePosition:v,background:y,runtimeOptions:w,debug:b,...x})=>{const[E,S]=e.useState(y),[_,T]=e.useState(s),[C,k]=e.useState(!1),P=e.useRef(!1),O=e.useMemo((()=>("string"==typeof i&&(i=[i,{}]),E||b?i?[i[0],{debug:b,background:E,...i[1]||{}}]:["default-preset",{background:E,debug:b}]:i||"default-preset")),[i,E,b]),[R,A,I]=Zr({scroll:!0}),L=e.useRef(),[$,z,M,B]=Po(O,{width:x.width,height:x.height,forceRefresh:I,unstable_webglRenderer:o}),[F,D]=e.useState("");e.useEffect((()=>{T(s)}),[s]),e.useEffect((()=>{z&&z.em&&z.em.updateBounds()}),[z,A]),e.useEffect((()=>{null==z||z.runtime.setOptions(w||{})}),[w]),e.useEffect((()=>{z&&z.runtime&&(z.runtime.mode=_),C&&z&&(z.ready=!0)}),[z,C,_]),e.useEffect((()=>{z&&(z.runtime.manualHomePosition=!!v,z.runtime.setHomePosition(v))}),[z,v]),e.useEffect((()=>{if(z){const t=z.runtime;t.resize(M.current.width,x.width,M.current.height,x.height),M.current.width=x.width,M.current.height=x.height,t.updateNextFrame(),M.current.didUpdate=!0}}),[z,x.width,x.height]),e.useLayoutEffect((()=>{z&&(z.overlay&&(z.overlay.style.width=`${A.width}px`,z.overlay.style.height=`${A.height}px`),z.container&&(z.container.style.width=`${A.width}px`,z.container.style.height=`${A.height}px`))}),[z,A.height,A.width]),e.useLayoutEffect((()=>{const t=()=>{if(z){const t=z.runtime;M.current.width!==x.width&&M.current.height!==x.height&&(t.resize(M.current.width,x.width,M.current.height,x.height),M.current.width=x.width,M.current.height=x.height,t.updateNextFrame(),M.current.didUpdate=!0)}};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)}),[z,x.height,x.width]);const N=120,j=()=>{if(z&&z.navigator){const t=z.runtime.world.height,e=z.runtime.world.width,i=window.devicePixelRatio||1,n=N,s=N/e*t;z.navigator.width=n*i,z.navigator.height=s*i,z.navigator.style.width=n+"px",z.navigator.style.height=s+"px"}};e.useLayoutEffect((()=>{if(z){j();const t=z.runtime;return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&(j(),t.resize(M.current.width,x.width,M.current.height,x.height))}))}return()=>{}}),[z]);const W=e.useCallback((function(t){const i=()=>{k(!0)};return e.useEffect((()=>{if(!z)throw new Error("Invalid configuration - no runtime found");{z.runtime.goHome();const t=n&&n(z);t&&t.then?t.then(i):i()}}),[]),t.children}),[z]);e.useEffect((()=>{if(z){const t=z.runtime;if(r)return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&t.goHome()}))}return()=>{}}),[z,r]),e.useEffect((()=>{if(z){return z.runtime.registerHook("useBeforeFrame",(()=>{var t;if(M.current.didUpdate&&z.canvas){const e=window.devicePixelRatio||1,i=M.current.width,n=M.current.height;z.canvas.width=i*e,z.canvas.height=n*e,z.canvas.style.width=i+"px",z.canvas.style.height=n+"px",null==(t=z.canvas.getContext("2d"))||t.scale(e,e),z&&z.em&&z.em.updateBounds(),M.current.didUpdate=!1}}))}return()=>{}}),[z,r]),e.useEffect((()=>{const t=()=>{z&&(T("sketch"),D("mode-sketch")),window.removeEventListener("keyup",t)},e=e=>{if("Space"===e.code&&z&&"sketch"===z.runtime.mode){if(e.target&&e.target.tagName&&"input"===e.target.tagName.toLowerCase())return;e.preventDefault(),T("explore"),D("mode-explore"),window.addEventListener("keyup",t)}};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)}}),[z]),e.useLayoutEffect((()=>{if(L.current&&!E){const t=getComputedStyle(L.current).getPropertyValue("--atlas-background");t&&S(t)}}),[E]),P.current=!0;const{height:U,width:H,...V}=x,G=(X=[x.width,x.height],e.useMemo((()=>yo(X)),X));var X;return a.default.createElement(Oo,{ref:t=>{L.current=t,R(t)},className:["atlas",h?"":`atlas-width-${G}`,F,g].filter(Boolean).join(" ").trim(),style:{...p,...h?{}:{width:x.width,height:x.height}}},"static-preset"===$?a.default.createElement(Oo,{className:"atlas-static-container",style:z&&z.controller?void 0:{pointerEvents:"none"},ref:B.container,tabIndex:0,...m}):a.default.createElement("canvas",{className:"atlas-canvas",part:"atlas-canvas",tabIndex:0,...V,...m,ref:B.canvas}),a.default.createElement(Oo,{className:"atlas-overlay",style:{...u||{}},ref:B.overlay},l?a.default.createElement(W,null,a.default.createElement(no.Provider,{value:A},a.default.createElement(Yr.Provider,{value:_},a.default.createElement(io.Provider,{value:z},d)))):a.default.createElement(mo,{bounds:A,preset:z,mode:_,setIsReady:k,onCreated:n},d)),f?a.default.createElement(Oo,{className:"atlas-navigator"},a.default.createElement("canvas",{className:"atlas-navigator-canvas",part:"atlas-navigator-canvas",ref:B.navigator})):null,h?a.default.createElement("style",null,`.atlas-width-${G} { width: ${x.width}px; height: ${x.height}px; }`):a.default.createElement("style",null,`\n .atlas { position: relative; user-select: none; display: flex; background: var(--atlas-background, #000); z-index: var(--atlas-z-index, 10); touch-action: none; }\n .atlas-width-${G} { width: ${x.width}px; height: ${x.height}px; }\n .atlas-canvas { flex: 1 1 0px; }\n .atlas-canvas:focus, .atlas-static-container:focus { outline: none }\n .atlas-canvas:focus-visible, .atlas-canvas-container:focus-visible { outline: var(--atlas-focus, 2px solid darkorange) }\n .atlas-static-container { position: relative; overflow: hidden; flex: 1 1 0px; }\n .atlas-overlay { position: absolute; top: 0; left: 0; pointer-events: none; overflow: hidden; }\n .atlas-static-image { position: absolute; pointer-events: none; user-select: none; transform-origin: 0px 0px; }\n .atlas-navigator { position: absolute; top: var(--atlas-navigator-top, 10px); right: var(--atlas-navigator-bottom, 10px); left: var(--atlas-navigator-left); bottom: var(--atlas-navigator-bottom); opacity: .8 }\n .atlas-navigator-canvas { width: 100%; }\n `),t)};const Ao=()=>e.useContext(io),Io=()=>{const t=Ao();return t?t.runtime:void 0},Lo=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useAfterFrame",t):()=>{}),i)},$o=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useFrame",t):()=>{}),i)},zo=()=>{const t=Ao();return t&&t.canvas?t.canvas:void 0};function Mo(){return e.useContext(no)}const Bo=a.default.forwardRef((({children:t,...i},n)=>{const r=e.useRef(),o=Io(),l=e.useRef(0),h=e.useRef(),c=e.useRef();return $o((()=>{var t,e,n,s;if(i.relative){const i=r.current;if(i&&o){const a=o.getScaleFactor();l.current!==a&&(l.current=a,i.style.transformOrigin="0 0",i.style.transform=`scale(${1/l.current})`,i.style.width=100*l.current+"%",i.style.height=100*l.current+"%",r.current&&(null==(e=null==(t=h.current)?void 0:t.__owner.value)?void 0:e.rotation)&&(i.style.transform=`scale(${1/l.current}) translate(50%, 50%) rotate(${(null==(s=null==(n=h.current)?void 0:n.__owner.value)?void 0:s.rotation)||0}deg) translate(-50%, -50%)`))}}}),[i.relative]),e.useLayoutEffect((()=>{const o=h.current;async function l(){if(o&&o.__host){const n=i.relative?a.default.createElement("div",{ref:r},t):t;await async function(t,i,n){if(e.version.startsWith("18.")){const e=await Promise.resolve().then((function(){return s(require("react-dom/client"))})),r=e.default?e.default.createRoot:e.createRoot;n.current||(n.current=r(t)),n.current.render(i)}else if("undefined"!=typeof ReactDOM){const{render:e,unmountComponentAtNode:s}=ReactDOM;e(i,t),n.current={unmount(){s(t)}}}else{const e=await Promise.resolve().then((function(){return s(require("react-dom"))})),r=e.default?e.default.render:e.render,o=e.default?e.default.unmountComponentAtNode:e.unmountComponentAtNode;r(i,t),n.current={unmount(){o(t)}}}}(o.__host.element,n,c)}}n&&o&&("function"==typeof n?n(o):n.current=o),o&&o.__host?l():o&&(o.__onCreate=l)}),[n,t,h,i.relative]),e.useLayoutEffect((()=>()=>{c.current&&setTimeout((()=>{c.current.unmount()}),0)}),[]),a.default.createElement("box",{html:!0,...i,ref:h})}));Bo.displayName="HTMLPortal";const Fo=(t,i,n=[])=>{const s=Io(),r=s?s.world:void 0;e.useEffect((()=>{if(s){const e=i,n=d[t];s.world.activatedEvents.push(n);const r=n.slice(2).toLowerCase();return s.world.addEventListener(r,e),()=>{s.world.removeEventListener(r,e)}}return()=>{}}),[r,t,...n])};function Do(t,e){if(0===t)return[0,1];if(0===e)return[1,0];const i=Math.abs(t)/Math.abs(e);return[i,1-i]}const No=(t,i)=>{const n=Kr(),s=Io(),r=Mo(),o=e.useRef(),a=e.useRef(null),l=e.useRef(),[h,c]=e.useState(!1),d=e.useRef(!1),u=e.useRef({north:0,south:0,east:0,west:0}),p=function(){const t=e.useRef({ctrl:!1,shift:!1,alt:!1});return e.useLayoutEffect((()=>{function e(e){"Shift"===e.key&&(t.current.shift=!0),"Control"===e.key&&(t.current.ctrl=!0),"Alt"===e.key&&(t.current.alt=!0)}function i(e){"Shift"===e.key&&(t.current.shift=!1),"Control"===e.key&&(t.current.ctrl=!1),"Alt"===e.key&&(t.current.alt=!1)}return window.addEventListener("keydown",e),window.addEventListener("keyup",i),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",i)}}),[]),t}(),f=e.useCallback((t=>e=>{if(d.current=!0,c(!0),r&&s){const{top:i,left:n}=r,a=s.viewerToWorld(e.pageX-n,e.pageY-i);l.current={x:a.x,y:a.y},o.current=t}}),[r,s]),g=e.useMemo((()=>t.width/t.height),[t.width,t.height]),m=e.useCallback((e=>{if(!Math.abs(e.north-e.south+(e.east-e.west)))return;const i=-e.west+e.east,n=-e.north+e.south,s=t.width+i,r=t.height+n;if(s/r>=g){const t=s-r*g,[i,n]=Do(e.east,e.west);e.west=e.west+t*n,e.east=e.east-t*i}else{const t=r-s/g,[i,n]=Do(e.north,e.south);e.north=e.north+t*i,e.south=e.south-t*n}}),[t.width,t.height,g]);$o((()=>{l&&s&&s.updateNextFrame()})),e.useEffect((()=>{s&&s.updateNextFrame()}),[s,h]);const v=e.useCallback((e=>{var i;if(!s||!r||"sketch"!==s.mode)return;const{top:n,left:h}=r,c=s.viewerToWorld(e.pageX-h,e.pageY-n),d=a.current,f=!t.maintainAspectRatio&&p.current.alt,g=!f&&p.current.shift&&-1!==(null==(i=o.current)?void 0:i.indexOf("-"));if("translate"!==o.current&&"east"!==o.current&&"north-east"!==o.current&&"south-east"!==o.current||(u.current.east=c.x-(l.current?l.current.x:0),f&&(u.current.west=-u.current.east)),"translate"!==o.current&&"west"!==o.current&&"north-west"!==o.current&&"south-west"!==o.current||(u.current.west=c.x-(l.current?l.current.x:0),f&&(u.current.east=-u.current.west)),"translate"!==o.current&&"north"!==o.current&&"north-east"!==o.current&&"north-west"!==o.current||(u.current.north=c.y-(l.current?l.current.y:0),f&&(u.current.south=-u.current.north)),"translate"!==o.current&&"south"!==o.current&&"south-west"!==o.current&&"south-east"!==o.current||(u.current.south=c.y-(l.current?l.current.y:0),f&&(u.current.north=-u.current.south)),(t.maintainAspectRatio||g)&&m(u.current),d){const e=u.current.west,i=u.current.north,n=t.width+u.current.east,r=t.height+u.current.south;d.points[1]=Math.min(e,n),d.points[2]=Math.min(i,r),d.points[3]=Math.max(e,n),d.points[4]=Math.max(i,r),s.updateNextFrame()}}),[s,t.width,t.height,t.maintainAspectRatio,r]);Fo("mousemove",v,[t.width,t.height,r]),Fo("pointermove",v,[t.width,t.height,r]);const y=e.useRef();return e.useEffect((()=>{y.current=()=>{if(d.current){const e=u.current.west,n=u.current.north,s=t.width+u.current.east,r=t.height+u.current.south,a=Math.min(e,s),h=Math.min(n,r),p=Math.max(e,s),f=Math.max(n,r),g={x:(t.x||0)+a,y:(t.y||0)+h,width:p-a||1,height:f-h||1};t.maintainAspectRatio,i(g),o.current=void 0,l.current=void 0,u.current.east=0,u.current.west=0,u.current.north=0,u.current.south=0,d.current=!1,c(!1)}}}),[i,t.height,t.width,t.x,t.y]),e.useEffect((()=>{const t=()=>{y.current&&y.current()};return window.addEventListener("pointerup",t),window.addEventListener("touchend",t),()=>{window.removeEventListener("pointerup",t),window.removeEventListener("touchend",t)}}),[]),{portalRef:a,mode:n,mouseEvent:f,onPointerMoveCallback:v,isEditing:h}};function jo({handleSize:t,resizable:i,onSave:n,children:s,maintainAspectRatio:r,disableCardinalControls:o,...l}){const h=void 0===t?r?10:8:t,{portalRef:c,mode:d,mouseEvent:u,isEditing:p}=No({x:l.x||0,y:l.y||0,width:l.width,height:l.height,maintainAspectRatio:r},n),f=e.useMemo((()=>u("translate")),[u]),g=e.useMemo((()=>u("east")),[u]),m=e.useMemo((()=>u("west")),[u]),v=e.useMemo((()=>u("south")),[u]),y=e.useMemo((()=>u("north")),[u]),w=e.useMemo((()=>u("south-east")),[u]),b=e.useMemo((()=>u("south-west")),[u]),x=e.useMemo((()=>u("north-east")),[u]),E=e.useMemo((()=>u("north-west")),[u]),S="sketch"===d,_={zIndex:999,boxShadow:"0px 2px 3px 0 rgba(0,0,0,0.2)",border:"1px solid rgba(155,155,155,.7)",borderRadius:r||o?"50%":2,position:"absolute",background:"#fff",pointerEvents:p?"none":S?"initial":"none"};return a.default.createElement(a.default.Fragment,null,a.default.createElement("world-object",{...l},s,S&&i?a.default.createElement(Bo,{ref:c,target:{x:0,y:0,height:l.height,width:l.width},relative:!0,interactive:!1},S&&i?a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{onMouseDown:f,onTouchStart:f,style:{display:"block",width:"100%",height:"100%",position:"relative",border:"1px solid rgba(155,155,155, .7)",boxSizing:"border-box",pointerEvents:p?"none":S?"initial":"none"}}),r?null:a.default.createElement(a.default.Fragment,null,a.default.createElement("div",{title:"east",onTouchStart:g,onMouseDown:g,style:{..._,cursor:"e-resize",height:2*h,width:h,right:0,top:"50%",opacity:o?0:1,transform:`translate(${h/2}px, -${h}px)`}}),a.default.createElement("div",{title:"west",onMouseDown:m,style:{..._,cursor:"w-resize",position:"absolute",height:2*h,width:h,left:0,top:"50%",opacity:o?0:1,transform:`translate(-${h/2}px, -${h}px)`}}),a.default.createElement("div",{title:"north",onMouseDown:y,style:{..._,cursor:"n-resize",position:"absolute",height:h,width:2*h,left:"50%",top:0,opacity:o?0:1,transform:`translate(-${h}px, -${h/2}px)`}}),a.default.createElement("div",{title:"south",onMouseDown:v,style:{..._,cursor:"s-resize",position:"absolute",height:h,width:2*h,left:"50%",bottom:0,opacity:o?0:1,transform:`translate(-${h}px, ${h/2}px)`}})),a.default.createElement("div",{title:"north-east",onMouseDown:x,style:{..._,cursor:"ne-resize",position:"absolute",height:h,width:h,right:0,top:0,transform:`translate(${h/2}px, -${h/2}px)`}}),a.default.createElement("div",{title:"south-east",onMouseDown:w,style:{..._,cursor:"se-resize",position:"absolute",height:h,width:h,bottom:0,right:0,transform:`translate(${h/2}px, ${h/2}px)`}}),a.default.createElement("div",{title:"south-west",onMouseDown:b,style:{..._,cursor:"sw-resize",position:"absolute",height:h,width:h,bottom:0,left:0,transform:`translate(-${h/2}px, ${h/2}px)`}}),a.default.createElement("div",{title:"north-west",onMouseDown:E,style:{..._,cursor:"nw-resize",position:"absolute",height:h,width:h,top:0,left:0,transform:`translate(-${h/2}px, -${h/2}px)`}})):null):null))}const Wo=t=>{var i,n,s,r,o;const l=t.width/((null==(i=t.crop)?void 0:i.width)||t.tiles.width),h=t.tiles.imageService.tiles||[],c=t.tiles.imageService.sizes||[],d=t.enableThumbnail,u=t.enableSizes,p=e.useMemo((()=>{const e=t.tiles.imageService.id||t.tiles.imageService["@id"];return e&&e.endsWith("/info.json")?e.slice(0,-1*"/info.json".length):e}),[t.tiles.imageService.id]);return a.default.createElement("world-object",{rotation:t.rotation,key:t.tiles.imageService.id,scale:l,height:(null==(n=t.crop)?void 0:n.height)||t.tiles.height,width:(null==(s=t.crop)?void 0:s.width)||t.tiles.width,x:t.x,y:t.y,onClick:t.onClick},a.default.createElement("composite-image",{key:t.tiles.imageService.id,id:t.tiles.imageService.id,width:(null==(r=t.crop)?void 0:r.width)||t.tiles.width,height:(null==(o=t.crop)?void 0:o.height)||t.tiles.height,crop:t.crop},d&&t.tiles.thumbnail?a.default.createElement("world-image",{priority:!0,uri:t.tiles.thumbnail.id,target:{width:t.tiles.width,height:t.tiles.height},display:{width:t.tiles.thumbnail.width,height:t.tiles.thumbnail.height},crop:t.crop}):null,u&&c.map(((e,i)=>a.default.createElement("world-image",{key:i,uri:`${p}/full/${e.width},${e.height}/0/default.jpg`,target:{width:t.tiles.width,height:t.tiles.height},display:{width:e.width,height:e.height},crop:t.crop}))),h.map((e=>(e.scaleFactors||[]).map((i=>a.default.createElement("tiled-image",{key:`${t.tiles.imageService.id}-tile-${i}`,uri:t.tiles.imageService.id,display:{width:t.tiles.width,height:t.tiles.height},tile:e,scaleFactor:i,crop:t.crop})))))))};function Uo(t){return t.id||t["@id"]}function Ho(t){return t.endsWith("info.json")?t:t.endsWith("/")?`${t}info.json`:`${t}/info.json`}const Vo="http://library.stanford.edu/iiif/image-api/compliance.html#level1",Go="http://library.stanford.edu/iiif/image-api/compliance.html#level2",Xo="http://library.stanford.edu/iiif/image-api/conformance.html#level1",Yo="http://library.stanford.edu/iiif/image-api/conformance.html#level2",Ko="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1",Qo="http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2",qo="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level1",Zo="http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level2",Jo="http://iiif.io/api/image/1/level1.json",ta="http://iiif.io/api/image/1/profiles/level1.json",ea="http://iiif.io/api/image/1/level2.json",ia="http://iiif.io/api/image/1/profiles/level2.json",na="http://iiif.io/api/image/2/level1.json",sa="http://iiif.io/api/image/2/profiles/level1.json",ra="http://iiif.io/api/image/2/level2.json",oa="http://iiif.io/api/image/2/profiles/level2.json",aa="level1",la="level2",ha="http://iiif.io/api/image/2/level1",ca="http://iiif.io/api/image/2/level2",da=[ca,Go,Yo,Qo,Zo,ea,ia,ra,oa,la],ua=[...da,ha,Vo,Xo,Ko,qo,Jo,ta,na,sa,aa],pa=["http://iiif.io/api/image/2/level0",ha,ca,"http://library.stanford.edu/iiif/image-api/compliance.html#level0",Vo,Go,"http://library.stanford.edu/iiif/image-api/conformance.html#level0",Xo,Yo,"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",Ko,Qo,"http://library.stanford.edu/iiif/image-api/1.1/conformance.html#level0",qo,Zo,"http://iiif.io/api/image/1/level0.json","http://iiif.io/api/image/1/profiles/level0.json",Jo,ta,ea,ia,"http://iiif.io/api/image/2/level0.json","http://iiif.io/api/image/2/profiles/level0.json",na,sa,ra,oa,"level0",aa,la],fa={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["sizeByWhListed"]},ga={extraFormats:["jpg"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPx","regionSquare","sizeByWhListed","sizeByH","sizeByW","sizeByWh"]},ma={extraFormats:["jpg","png"],extraQualities:["default"],extraFeatures:["baseUriRedirect","cors","jsonldMediaType","regionByPct","regionByPx","regionSquare","rotationBy90s","sizeByWhListed","sizeByConfinedWh","sizeByH","sizeByPct","sizeByW","sizeByWh"]};function va(t){return-1!==da.indexOf(t)?ma:-1!==ua.indexOf(t)?ga:fa}function ya(t){try{if("full"===t)return{full:!0};if("square"===t)return{square:!0};const e=t.startsWith("pct:"),i=t.substr(e?4:0).split(",").map((t=>parseFloat(t)));return{x:i[0],y:i[1],w:i[2],h:i[3],percent:e}}catch{throw new Error("Expected 'full', 'square' or 'x,y,w,h'. Found "+t)}}function wa(t){const e={upscaled:!1,max:!1,confined:!1};if("^"===t[0]&&(e.upscaled=!0,t=t.slice(1)),"max"===t||"full"===t)return e.max=!0,e.serialiseAsFull="full"===t,e;if("!"===t[0]&&(e.confined=!0,t=t.slice(1)),"p"===t[0])return e.percentScale=parseFloat(t.slice(4)),e;const i=t.split(",").map((t=>t.trim()));return i.length&&(""!==i[0]&&(e.width=parseInt(i[0],10)),""!==i[1]&&(e.height=parseInt(i[1],10))),e}function ba(t){const e={angle:0};if("!"===t[0]&&(e.mirror=!0,t=t.substr(1)),e.angle=parseFloat(t)%360,Number.isNaN(e.angle))throw new Error(`Invalid rotation ${t}`);return e}function xa(t,e=""){const{path:i,scheme:n,server:s,prefix:r}=function(t,e=""){const i=t.match(/^(([a-zA-Z]+):\/\/([^/]+))?((.*)+)/);if(!i)throw new Error(`Invalid or unknown input ${t}`);const n=i[2],s=i[3];let r=i[4];if("/"===r[0]&&(r=r.substr(1)),e.length>0){if("/"===e[0]&&(e=e.substr(1)),e!==r.substr(0,e.length))throw new Error(`Path does not start with prefix (path: ${r}, prefix: ${e})`);r=r.substr(e.length)}return{scheme:n,server:s,path:r,prefix:e}}(t,e),o=i.split("/").reverse(),[a,l,h,c,...d]=o,u=d.reverse().filter(Boolean).join("/");if(1===o.length||""===a)return{type:"base",scheme:n,server:s,prefix:r,identifier:u};if("info.json"===a){const[,...t]=o;return{type:"info",scheme:n,server:s,prefix:r,identifier:t.reverse().filter(Boolean).join("/")}}const p=a.split(".");return{type:"image",scheme:n,server:s,prefix:r,identifier:u,originalPath:i,region:ya(c),size:wa(h),rotation:ba(l),quality:p[0],format:p[1]}}function Ea(t){const e=xa(Ho(t.id));if("info"!==e.type)throw new Error("Invalid service URL");const i=function(t){const e=t?Array.isArray(t.profile)?t.profile:[t.profile]:[],i={extraQualities:[],extraFormats:[],extraFeatures:[]};for(let n of e)if("string"==typeof n&&(n=va(n)),n){if(n.formats)for(const t of n.formats)-1===i.extraFormats.indexOf(t)&&i.extraFormats.push(t);if(n.qualities)for(const t of n.qualities)-1===i.extraQualities.indexOf(t)&&i.extraQualities.push(t);if(n.supports)for(const t of n.supports)-1===i.extraFeatures.indexOf(t)&&i.extraFeatures.push(t);if(n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea),n.extraFormats)for(const t of n.extraFormats)-1===i.extraFormats.indexOf(t)&&i.extraFormats.push(t);if(n.extraQualities)for(const t of n.extraQualities)-1===i.extraQualities.indexOf(t)&&i.extraQualities.push(t);if(n.extraFeatures)for(const t of n.extraFeatures)-1===i.extraFeatures.indexOf(t)&&i.extraFeatures.push(t);n.maxHeight&&(i.maxHeight=n.maxHeight),n.maxWidth&&(i.maxWidth=n.maxWidth),n.maxArea&&(i.maxArea=n.maxArea)}if(t.extraFormats)for(const n of t.extraFormats)-1===i.extraFormats.indexOf(n)&&i.extraFormats.push(n);if(t.extraFeatures)for(const n of t.extraFeatures)-1===i.extraFeatures.indexOf(n)&&i.extraFeatures.push(n);if(t.extraQualities)for(const n of t.extraQualities)-1===i.extraQualities.indexOf(n)&&i.extraQualities.push(n);return i}(t);return{identifier:e.identifier,originalPath:"",server:e.server,prefix:e.prefix,scheme:e.scheme,type:"image",quality:-1===i.extraQualities.indexOf("default")?i.extraQualities[0]:"default",region:{full:!0},size:{max:!0,upscaled:!1,confined:!1},format:"jpg",rotation:{angle:0}}}function Sa(t,e,i){const n=i.length,s=[];for(let r=0;r<n;r++){const e=i[r].width;s.push(t/e)}return s}function _a(t,e,i){const n=i.length,s=[];for(let r=0;r<n;r++){const n=i[r];s.push({width:Math.floor(t/n),height:Math.floor(e/n)})}return s}function Ta(t){return t["@id"]?t["@id"]:t.id?t.id:void 0}function Ca(t){if(!t||!t.profile||!Ta(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if("string"==typeof i&&-1!==pa.indexOf(i))return!0;return!1}function ka(t){if(!function(t){if(!Ca(t))return!1;const e=Array.isArray(t.profile)?t.profile:[t.profile];for(const i of e)if("string"==typeof i){if(-1!==ua.indexOf(i))return!0}else{const t=[...i.supports||[],...i.extraFeatures||[]];if(-1!==t.indexOf("regionByPx")&&(-1!==t.indexOf("sizeByW")||-1!==t.indexOf("sizeByWh")))return!0}return!1}(t))return[];const e=[],i=Array.isArray(t.profile)?t.profile:[t.profile],n=i.length;for(let s=0;s<n;s++){const e=i[s];if("string"!=typeof e&&(e.maxHeight||e.maxWidth))return[{id:Ta(t),type:"variable",minWidth:0,minHeight:0,maxHeight:e.maxHeight||e.maxWidth,maxWidth:e.maxWidth||e.maxHeight}]}if(t.tiles){const i=t.tiles.length;for(let n=0;n<i;n++){const i=t.tiles[n];(i.height||i.width)&&e.push({id:Ta(t),type:"variable",minHeight:0,minWidth:0,maxHeight:i.height||i.width,maxWidth:i.width})}}return e}function Pa(t){const e=t.match(/^.*\/(full)\/(((\d+),(\d+)?)|max)\/(\d+)\/default\.(jpg|png|jpeg)$/);if(e){const i=e[1],n=parseInt(e[4],10),s=parseInt(e[5],10),r=e[7];if(("max"===i||"full"===i)&&n&&s&&r)return{type:"fixed",id:t,height:s,width:n}}return{type:"unknown",id:t}}function Oa(t){if("string"==typeof t)return Pa(t);const e=function(t){return t["@type"]?t["@type"]:t.type?t.type:void 0}(t);if("Image"!==e&&"sc:Image"!==e)return null;const i=t,n=Ta(i);return n?n&&i.width&&i.height?{id:n,type:"fixed",width:i.width,height:i.height,unsafe:!0}:Pa(n):null}function Ra(t){return Ca(t)?(t&&t.sizes?t.sizes:[]).map((e=>({id:Ta(t),type:"fixed-service",height:e.height,width:e.width}))):[]}function Aa(t){const e=[],i=t.length;for(let n=0;n<i;n++){const i=Ra(t[n]);i.length&&e.push(...i);const s=ka(t[n]);s.length&&e.push(...s)}return e}function Ia(t){const e=t.service?Array.isArray(t.service)?t.service:[t.service]:[],i=e.length,n=[];for(let s=0;s<i;s++)Ca(e[s])&&n.push(e[s]);return n}function La({x:t=0,y:e=0,w:i,h:n,full:s,square:r,percent:o}){if(s)return"full";if(r)return"square";if(typeof i>"u"||typeof n>"u")throw new Error("RegionParameter: invalid region");const a=`${t},${e},${i},${n}`;return o?`pct:${a}`:a}function $a({max:t,percentScale:e,upscaled:i,confined:n,width:s,height:r,serialiseAsFull:o}){const a=[];return i&&a.push("^"),t?(a.push(o?"full":"max"),a.join("")):(n&&a.push("!"),e&&a.push(`pct:${e}`),s&&a.push(`${s}`),a.push(","),r&&a.push(`${r}`),a.join(""))}function za(t){return`${t.mirror?"!":""}${(t.angle||0)%360}`}var Ma=Object.defineProperty,Ba=Object.defineProperties,Fa=Object.getOwnPropertyDescriptors,Da=Object.getOwnPropertySymbols,Na=Object.prototype.hasOwnProperty,ja=Object.prototype.propertyIsEnumerable,Wa=(t,e,i)=>e in t?Ma(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Ua=(t,e)=>{for(var i in e||(e={}))Na.call(e,i)&&Wa(t,i,e[i]);if(Da)for(var i of Da(e))ja.call(e,i)&&Wa(t,i,e[i]);return t},Ha=(t,e)=>Ba(t,Fa(e));function Va(t,e){const i=t.prefix.startsWith("/")?t.prefix.substr(1):t.prefix,n=`${t.scheme}://${t.server}/${i?`${i}/`:""}${t.identifier}`;if("base"===t.type)return n;if("info"===t.type)return`${n}/info.json`;let{region:s,size:r,rotation:o,format:a,quality:l}=t;if(e){const t=e["@context"]?Array.isArray(e["@context"])?e["@context"]:[e["@context"]]:[],i=-1!==t.indexOf("http://iiif.io/api/image/2/context.json"),n=-1!==t.indexOf("http://iiif.io/api/image/3/context.json");if((r.width===e.width&&!r.height||r.height===e.height&&!r.width||r.width===e.width&&r.height===e.height)&&(r=Ha(Ua({},r),{max:!0})),i&&(r.max&&!r.serialiseAsFull&&(r=Ha(Ua({},r),{serialiseAsFull:!0})),!r.max&&r.width&&r.height&&(r=Ha(Ua({},r),{height:void 0}))),n&&(r.max&&r.serialiseAsFull&&(r=Ha(Ua({},r),{serialiseAsFull:!1})),r.width&&!r.height&&e.width&&e.height)){const t=e.height/e.width;r=Ha(Ua({},r),{height:Math.ceil(r.width*t)})}}return[n,La(s),$a(r),za(o),`${l}.${a}`].filter(Boolean).join("/")}function Ga(t,e,i){const n=Ea({id:Ho(Ta(t)),profile:"level2",type:"ImageService2"});if("image"!==n.type)throw new Error("Invalid service");return n.size.max=!1,n.size.width=e,n.size.height=i,{id:Va(n),type:"fixed",width:e,height:i||t.height/(t.width||1)*e,unsafe:t.width>e}}function Xa(t){const e=t.replace(/(https?:\/\/)?(www.)?/i,"");return-1!==e.indexOf("/")?e.split("/")[0]:e}function Ya(t,e){const i=[],n=Object.assign({unsafeImageService:!1,atAnyCost:!0,fallback:!0,minHeight:64,minWidth:64,maxHeight:1/0,maxWidth:1/0,returnAllOptions:!1,preferFixedSize:!1,allowUnsafe:!1,explain:!1,height:0,width:0},t),s=[],r=[];let o=null;const a=(t,e)=>{if(function(t,e,i){const n=t.width?t.width:t.maxWidth;return i.height<=t.maxHeight&&i.width<=t.maxWidth&&i.height>=t.minHeight&&i.width>=t.minWidth&&(!e||Math.abs(i.width-n)<Math.abs(e.width-n))}(n,e,t)){if(n.preferFixedSize&&t.unsafe)return void r.push(t);n.returnAllOptions&&e&&r.push(e),o=t}else n.returnAllOptions&&r.push(t)},l=e.length;for(let h=0;h<l;h++){const t=e[h](),i=t.length;for(let e=0;e<i;e++){const i=t[e];if("unknown"===i.type&&n.atAnyCost&&s.push(i),"fixed"===i.type&&(i.unsafe?s.push(i):a(i,o)),"fixed-service"===i.type)if(n.unsafeImageService){a(Ga(i,n.width,n.height),o)}else{a(Ga(i,i.width,i.height),o)}if("variable"===i.type&&i.maxWidth){a(Ga({id:i.id,type:"fixed-service",width:i.maxWidth,height:i.maxWidth},i.maxWidth),o)}}if(o&&!n.returnAllOptions){if(o.unsafe||n.allowUnsafe)continue;break}}return n.atAnyCost&&0===r.length?{best:o||s[0],fallback:s.slice(1),log:i}:n.returnAllOptions?{best:n.atAnyCost?o||r[0]||s[0]:o||r[0],fallback:[...r,...s],log:i}:{best:o||r[0]||null,fallback:o?r:r.slice(1),log:i}}var Ka=Object.defineProperty,Qa=Object.defineProperties,qa=Object.getOwnPropertyDescriptors,Za=Object.getOwnPropertySymbols,Ja=Object.prototype.hasOwnProperty,tl=Object.prototype.propertyIsEnumerable,el=(t,e,i)=>e in t?Ka(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,il=(t,e)=>{for(var i in e||(e={}))Ja.call(e,i)&&el(t,i,e[i]);if(Za)for(var i of Za(e))tl.call(e,i)&&el(t,i,e[i]);return t},nl=(t,e)=>Qa(t,qa(e));function sl(t,e,i){const n=t>e?t:e,s=i.length,r=[];for(let o=0;o<s;o++){const t=i[o];let e=t.scaleFactors[0],s=n/e;const a=[e];for(;s>=t.width;)e*=2,a.push(e),s/=2;r.push(nl(il({},t),{scaleFactors:a}))}return r}var rl=(t,e,i)=>new Promise(((n,s)=>{var r=t=>{try{a(i.next(t))}catch(e){s(e)}},o=t=>{try{a(i.throw(t))}catch(e){s(e)}},a=t=>t.done?n(t.value):Promise.resolve(t.value).then(r,o);a((i=i.apply(t,e)).next())}));class ol{constructor(){this.config={verificationsRequired:1,approximateServices:!0,enableFetching:!0,disableThrottling:!1},this.fetchingCount=0,this.imageServices={},this.knownImageServers={}}setConfig(t){Object.assign(this.config,t)}sample(t,e,i=!0){const n=Xa(Ta(t)),s=Ho(Ta(t)),r=this.knownImageServers[n];return this.imageServices[s]=Object.assign(t,{real:!0}),!r&&t.tiles?(this.knownImageServers[n]={verifications:0,malformed:!1,root:n,preLoaded:i,sampledId:Ta(t),verified:!1,server:null,result:{context:t["@context"]||[],sampledProfile:t.profile,resourceServiceRatio:e&&t.height?e.height/t.height:1,sampledSizes:t.sizes||[],sizeRatios:Sa(t.width,t.height,t.sizes||[]),sampledTiles:t.tiles||[]}},!0):this.verify(t)}preLoad(t,e=!0){this.knownImageServers[t.root]=t,e&&(this.knownImageServers[t.root].malformed=!1,this.knownImageServers[t.root].verifications=this.config.verificationsRequired)}predict(t,e=!1,i=!1){const n=null==t?void 0:t.source,s=Xa(Ta(t)),r=this.knownImageServers[s];if(!r||!r.result||!i&&(r.malformed||r.verifications<this.config.verificationsRequired))return null;const o=Ho(Ta(t));return this.imageServices[o]||(this.imageServices[o]={"@context":r.result.context,"@id":Ta(t),id:Ta(t),protocol:"http://iiif.io/api/image",tiles:(null==n?void 0:n.tiles)||sl(t.width,t.height,r.result.sampledTiles),sizes:(null==n?void 0:n.sizes)||_a(Math.round(t.width/r.result.resourceServiceRatio),Math.round(t.height/r.result.resourceServiceRatio),r.result.sizeRatios),profile:(null==n?void 0:n.profile)||r.result.sampledProfile,height:(null==n?void 0:n.height)||t.height,width:(null==n?void 0:n.width)||t.width,real:!1}),this.imageServices[o]}getThumbnailFromResource(t,e){return rl(this,arguments,(function*(t,e,i=!0,n=[]){const s=yield this.getImageCandidates(t,i);return Ya(e,[()=>n,()=>s])}))}getImageCandidates(t,e=!0){return rl(this,null,(function*(){const i=t;if(e&&i.height&&i.width){const t=Ia(i);for(const e of t){const t={id:Ta(e),width:e.width?e.width:i.width,height:e.height?e.height:i.height,source:e};yield this.loadService(t)}}return function(t,e=!0,i){const n=[],s=Oa(t);if(null===s)return n;const r=t;if(n.push(s),e&&r.width&&r.height){const t=[],e=Ia(r);for(const n of e){const e={id:Ta(n),width:r.width,height:r.height};if(i.canLoadSync(e)){const n=i.loadServiceSync(e);n&&(n.height||(n.height=r.height),n.width||(n.width=r.width),t.push(...Aa([n])))}}if(t.length)return n.push(...t),n}return r.service&&n.push(...Aa(r.service)),n}(t,e,this)}))}verify(t){return rl(this,null,(function*(){const e=this.predict(t,!1,!0),i=yield this.fetchService(Ta(t));if(!e)return!1;const n=e.height===i.height&&e.width===i.width&&e["@context"]===i["@context"]&&function(t,e){if(t.length!==e.length)return!1;if(0===t.length&&0===e.length)return!0;const i=t.length;let n=!0;for(let r=0;r<i;r++){const i=t[r],s=e[r];if(i.width!==s.width||i.height!==s.height){n=!1;break}}if(n)return!0;let s=0;for(let r=0;r<i;r++)for(let n=0;n<i;n++)if(t[r].width===e[n].width&&t[r].height===e[n].height){s++;break}return s===i}(e.sizes||[],i.sizes||[]);if(n){const e=Xa(Ta(t));this.knownImageServers[e].verifications+=1,this.knownImageServers[e].verifications>=this.config.verificationsRequired&&(this.knownImageServers[e].verified=!0)}return n}))}canLoadSync(t){const e="string"==typeof t?t:Ta(t),i=Ho(e);if(this.imageServices[i])return!0;const n=this.knownImageServers[Xa(e)];return n&&!n.malformed&&n.verifications>=this.config.verificationsRequired}markAsMalformed(t){return rl(this,null,(function*(){return this.knownImageServers[Xa(Ta(t))].malformed=!0,this.loadService(t,!0)}))}fetchService(t,e=!1){return rl(this,null,(function*(){const i=Ho(t);if(this.imageServices[i]&&(!e||this.imageServices[i].real))return this.imageServices[i];if(!this.config.enableFetching)throw new Error("Fetching is not enabled");const n=yield this.fetch(i).then((t=>t.json()));return!n.id&&n["@id"]&&(n.id=n["@id"]),n.id!==t&&(n.id=t,n["@id"]&&(n["@id"]=t)),this.imageServices[i]=Object.assign(n,{real:!0}),this.imageServices[i]}))}fetch(t,e){return rl(this,null,(function*(){return fetch(t,e)}))}loadService(t,e=!1){return rl(this,null,(function*(){if(!this.config.disableThrottling){let t=!0;for(;t;){if(!(this.fetchingCount>=this.config.verificationsRequired)){t=!1;break}yield new Promise((t=>setTimeout(t,500)))}}const i=this.knownImageServers[Xa(Ta(t))];if(i&&!i.malformed&&!e){yield i.result;const e=this.loadServiceSync(t);if(e)return e}this.fetchingCount++;const n=yield this.fetchService(Ta(t),e);return this.fetchingCount--,n.real&&this.sample(n,t),n}))}loadServiceSync(t){const e=Ho(Ta(t));return this.imageServices[e]?this.imageServices[e]:this.predict(t)}}new ol;const al={},ll={get:t=>t,setMetaValue([t,e,i],n){const s=ll.getResourceMeta(t,e),r=s?s[i]:void 0,o="function"==typeof n?n(r):n;al[t]={...al[t]||{},[e]:{...(al[t]||{})[e]||{},[i]:o}}},getResourceMeta:(t,e)=>{const i=al[t];if(i)return e?i[e]:i}},hl=new ol;function cl(){const t="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};if(void 0!==t.IIIF_VAULT)return t.IIIF_VAULT;if(void 0===t.IIIFVault)throw new Error("Vault not found");return t.IIIF_VAULT=new t.IIIFVault.Vault,t.IIIF_VAULT}const dl={};function ul(){return dl.helper||(dl.vault=cl(),dl.loader=new ol,dl.helper=function(t=ll,e={}){const i=e.imageServiceLoader||hl;return{getBestThumbnailAtSize:async function e(n,s,r=!1,o=[],a){const l=()=>i.getThumbnailFromResource(void 0,s,r,o);if(!n)return await i.getThumbnailFromResource(void 0,s,r,o);if("string"==typeof n){const t=Oa(n);return t&&o.push(t),await i.getThumbnailFromResource(void 0,s,r,o)}const h=t.get(n,{skipSelfReturn:!1});if("string"==typeof h)return{best:Oa(h),fallback:[],log:[]};if(!h)return await l();switch(await(async e=>{if(e&&e.thumbnail&&e.thumbnail.length){const n=t.get(e.thumbnail[0]),s=await i.getImageCandidates(n,r);s&&s.length&&o.push(...s)}})(h),h.type){case"Annotation":{const e=Array.isArray(h.body)?h.body:[h.body],n=t.get(e[0]);return a&&!n.width&&(n.width=a.width,n.height=a.height),await i.getThumbnailFromResource(n,s,r,o)}case"Canvas":{const t=h;return e(t.items[0],s,r,o,{width:t.width,height:t.height})}case"AnnotationPage":return e(h.items[0],s,r,o,a);case"Choice":{const t=h;return!t.items||t.items[0]?await l():e(t.items[0],s,r,o,a)}case"Collection":{const t=h.items[0];return t?e(t,s,r,o,a):await l()}case"Manifest":{const t=h.items[0];return t?e(t,s,r,o,a):await l()}case"SpecificResource":case"Image":case"Dataset":case"Sound":case"Text":case"TextualBody":case"Video":return a&&!h.width&&(h.width=a.width,h.height=a.height),i.getThumbnailFromResource(h,s,r,o)}return await l()}}}(dl.vault,{imageServiceLoader:dl.loader})),dl}async function pl(t,e,i){const{loader:n}=ul(),s=await n.loadService({id:t,width:e,height:i});return{id:Uo(s),width:e,height:i,imageService:s,thumbnail:void 0}}async function fl(t,e=512){const{vault:i,loader:n,helper:s}=ul(),r=[];for(const o of t.items)for(const a of i.get(o).items){const o=i.get(i.get(a).body[0]).service[0],l=await pl(o.id,t.width,t.height),{best:h}=await s.getBestThumbnailAtSize(i,n,t,{maxHeight:e,maxWidth:e},!0);h&&(l.thumbnail=h),r.push(l)}return r}async function gl(t){const{vault:e}=ul(),i=[];for(const n of t.items){const t=e.get(n);i.push(...await fl(t))}return i}exports.Atlas=Ro,exports.AtlasAuto=({resizeHash:t,aspectRatio:i,containerProps:n={},...s})=>{const[r,o,l]=Zr(),{height:h,width:c,...d}=s;e.useEffect((()=>{l()}),[c,h,t,l]);const u=e.useMemo((()=>i?{width:o.width,height:o.width*(1/i)}:o),[o,i]);return a.default.createElement(Oo,{ref:r,className:"atlas-container",...n},u.width?a.default.createElement(Ro,{width:u.width||100,height:u.height||100,...d},s.children):null,s.hideInlineStyle?null:a.default.createElement("style",null,`\n .atlas-container { \n display: var(--atlas-container-display, block);\n flex: var(--atlas-container-flex, none);\n width: var(--atlas-container-width, ${c?`${c}px`:"100%"});\n height: var(--atlas-container-height, ${p=h||(i?u.height:512),Number(p)==p?`${p}px`:p}) \n }\n `),s.htmlChildren);var p},exports.AtlasContext=io,exports.BoundsContext=no,exports.Box=Is,exports.BrowserEventManager=Eo,exports.CanvasRenderer=vr,exports.CompositeRenderer=yr,exports.CompositeResource=_s,exports.DebugRenderer=wr,exports.DrawBox=({onCreate:t})=>{const i=e.useRef({x:0,y:0}),n=zo(),s=Mo(),r=Io(),[o,a]=e.useState(),[l,h]=e.useState(),c=Kr();return $o((()=>{r&&o&&!l&&(r.pendingUpdate=!0)}),[o,l]),Lo((()=>{if(o&&n&&r){const t=n.getContext("2d");if(t){const{x:e,y:n,width:s,height:a}=r.worldToViewer(o.x,o.y,(l?l.x:i.current.x)-o.x,(l?l.y:i.current.y)-o.y);t.lineWidth=l?3:1,t.strokeStyle="#fff",t.strokeRect(e,n,s,a),t.lineWidth=l?3:1,t.strokeStyle="#000",t.strokeRect(e+1,n+1,s-2,a-2)}}}),[o,l]),e.useEffect((()=>{const t=t=>{if(s&&r){const{x:e,y:n}=r.viewerToWorld(t.clientX-s.left,t.clientY-s.top);i.current.x=~~e,i.current.y=~~n}};return n?(n.addEventListener("mousemove",t),()=>n.removeEventListener("mousemove",t)):()=>{}}),[s,n,r]),e.useEffect((()=>{const t=t=>{"sketch"===c&&(a({x:Math.round(i.current.x),y:Math.round(i.current.y)}),h(void 0))};return n?(n.addEventListener("mousedown",t),()=>n.removeEventListener("mousedown",t)):()=>{}}),[n,c]),e.useEffect((()=>{const t=t=>{o&&!l&&h({x:Math.round(i.current.x),y:Math.round(i.current.y)})};return n?(n.addEventListener("mouseup",t),()=>n.removeEventListener("mouseup",t)):()=>{}}),[n,o,l]),e.useEffect((()=>{o&&l&&t({x:Math.min(o.x,l.x),y:Math.min(o.y,l.y),width:Math.abs(l.x-o.x),height:Math.abs(l.y-o.y)})}),[o,t,l]),null},exports.GridBuilder=class{constructor(){this.autoWidth=!1,this.autoHeight=!0,this.content=[],this.viewingDirection="left-to-right",this.columns=4,this.spacing=20,this.reversed=!1,this.padding=20,this.world=ks.withProps({width:0,height:0,viewingDirection:"left-to-right"}),this.width=0,this.height=0}setViewingDirection(t){this.viewingDirection=t}addContent(t){this.content.push(...t.map((t=>this.world.addObjectAt(t,{width:0,height:0,x:0,y:0}))))}setWidth(t){this.width=t}setHeight(t){this.height=t}setSpacing(t){this.spacing=t}setPadding(t){this.padding=t}setRows(t){this.autoWidth=!0,this.rows=t}setColumns(t){this.autoHeight=!0,this.columns=t}recalculate(){if(0===this.height&&0===this.width)return;if(0===this.rows||0===this.columns)return;if(this.autoHeight&&!this.width)throw new Error("Cannot set auto height without setting a width");if(this.autoWidth&&!this.height)throw new Error("Cannot set auto width without setting a height");"left-to-right"!==this.viewingDirection&&"top-to-bottom"!==this.viewingDirection||!this.reversed||(this.reversed=!1,this.content.reverse()),"right-to-left"!==this.viewingDirection&&"bottom-to-top"!==this.viewingDirection||this.reversed||(this.reversed=!0,this.content.reverse());const t=this.content.length,{columns:e,rows:i}=(()=>{if(this.autoWidth&&this.rows){const e=t>this.rows?this.rows:t;return{columns:Math.ceil(t/e),rows:e}}if(this.autoHeight&&this.columns){const e=t>this.columns?this.columns:t;return{columns:e,rows:Math.ceil(t/e)}}throw new Error("Something went wrong.")})(),n=this.autoWidth?-1:this.width-2*this.padding,s=this.autoWidth?-1:(n-this.spacing*(e-1))/e;if(this.autoHeight&&!this.autoWidth){let n=0,r=this.padding;for(let o=0;o<i&&n!==t;o++){let i=0;const o=[];for(let r=0;r<e;r++){const e=this.reversed?t-n:n;if(n===t)break;const r=this.content[e],a=r.width,l=s/(r.width/r.height);o.push([n,s,l,s/a]),l>i&&(i=l),n++}for(let n=0;n<e&&o[n];n++){const e=this.world.getPoints(),s=o[n][0],a=o[n][1],l=o[n][2],h=o[n][3],c=this.padding+n*(this.spacing+a),d=r+(i-l)/2,u=this.reversed?t-s:s,p=e[5*u+1],f=e[5*u+2];this.world.scaleWorldObject(s,h),p===c&&f===d||this.world.translateWorldObject(u,c-p,d-f)}r+=i+this.spacing}return this.height=r+this.padding,void this.world.resize(this.width,this.height)}this.autoWidth&&this.autoHeight,!this.autoWidth&&this.autoHeight}getWorld(){return this.world}},exports.HTMLPortal=Bo,exports.ImageService=t=>{var i,n;const[s,r]=e.useState();return e.useEffect((()=>{pl(t.id,t.width,t.height).then((t=>{r(t)}))}),[t.height,t.id,t.width]),a.default.createElement("world-object",{x:t.x||0,y:t.y||0,width:t.width,height:t.height,scale:t.scale},s?a.default.createElement(Wo,{tiles:s,x:t.x,y:t.y,width:(null==(i=t.crop)?void 0:i.width)||t.width,height:(null==(n=t.crop)?void 0:n.height)||t.height,rotation:t.rotation,crop:t.crop},t.children):null)},exports.ImageTexture=_,exports.ModeContext=Yr,exports.ModeProvider=function(t){return a.default.createElement(Yr.Provider,{value:t.mode},t.children)},exports.OverlayRenderer=bo,exports.ReactAtlas=go,exports.RegionHighlight=function({interactive:t,region:i,onClick:n,onSave:s,maintainAspectRatio:r,disableCardinalControls:o,isEditing:l,rotation:h,style:c={backgroundColor:"rgba(0,0,0,.5)"}}){const d=e.useCallback((t=>{s({id:i.id,x:i.x,y:i.y,height:i.height,width:i.width,...t})}),[s,i.id,i.x,i.y,i.height,i.width]);return a.default.createElement(jo,{x:i.x,y:i.y,rotation:h,width:i.width,height:i.height,resizable:l,onSave:d,maintainAspectRatio:r,disableCardinalControls:o},a.default.createElement("box",{interactive:t,onClick:t=>{t.preventDefault(),t.stopPropagation(),n(i)},target:{x:0,y:0,width:i.width,height:i.height},style:c}))},exports.ResizeWorldItem=jo,exports.Runtime=Gs,exports.SingleImage=S,exports.StaticRenderer=_o,exports.Text=Ls,exports.TileSet=Wo,exports.TiledImage=Es,exports.WebGLRenderer=vo,exports.World=ks,exports.WorldObject=Cs,exports.Zone=class{constructor(t,e={}){this.id=t.map((t=>t.id)).join("$$"),this.config={...Ps,...e},this.points=p(5),this.objects=t,this.recalculateBounds()}recalculateBounds(){this.points.set([1,Math.min(...this.objects.map((t=>t.points[1])))-this.config.margin,Math.min(...this.objects.map((t=>t.points[2])))-this.config.margin,Math.max(...this.objects.map((t=>t.points[3])))+this.config.margin,Math.max(...this.objects.map((t=>t.points[4])))+this.config.margin])}getPointsAt(t,e,i){return[]}},exports.activateEvents=ho,exports.applyProps=lo,exports.bounceOut=Us,exports.canDrag=function(t){return"sketch"===t.current},exports.createDefaultEventMap=c,exports.defaultConfig=Gr,exports.defaultPreset=So,exports.easingFunctions=Hs,exports.fromImage=function(t){const{src:e,target:i}=t,n=i?i.width:t.width,s=i?i.height:t.height;return new Cs({id:e,height:s,width:n,layers:[S.fromImage(e,{height:s,width:n},{width:t.width,height:t.height})]})},exports.getId=Uo,exports.getTileFromCanvas=fl,exports.getTileFromImageService=pl,exports.getTiles=async function(t){try{const{vault:e}=ul(),i=await e.loadManifest(t);return i?gl(i):[]}catch(e){return console.log("ERR",e),[]}},exports.getTilesFromManifest=gl,exports.mergeStyles=function(t,e){return t?e?{...t,...e||{},":hover":t[":hover"]?Object.assign(t[":hover"]||{},e[":hover"]||{}):e[":hover"],":active":t[":active"]?Object.assign(t[":active"]||{},e[":active"]||{}):e[":hover"]}:t:e},exports.popmotionController=Xr,exports.presets=Co,exports.staticPreset=To,exports.supportedEventAttributes=h,exports.supportedEventMap=d,exports.unmountComponentAtNode=fo,exports.useAfterFrame=Lo,exports.useAfterPaint=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useAfterPaint",t):()=>{}),i)},exports.useAtlas=Ao,exports.useAtlasImage=(t,{onCreated:i,resetWorldOnChange:n=!0,mode:s="explore",cover:r,containerRef:o,...l})=>{const[h,c]=e.useState(!1),[d,u]=e.useState(void 0),[p,f]=e.useState(void 0),g=e.useRef(),m=e.useRef(),v=e.useMemo((()=>({width:l.width,height:l.height})),[l.width,l.height]),[y,w,b,x]=Po(void 0,{width:l.width,height:l.height});e.useLayoutEffect((()=>{const t=document.createElement("canvas");t.height=v.height,t.width=v.width,g.current=t}),[]),e.useLayoutEffect((()=>{const t=g.current;t&&(t.height=v.height,t.width=v.width)}),[v.width,v.height]),e.useEffect((()=>{if(w){return w.runtime.registerHook("useAfterFrame",(()=>{if(g.current)try{u(g.current.toDataURL())}catch(t){t instanceof Error&&f(t.message)}}))}return()=>{}}),[]),e.useEffect((()=>{if(w){return w.runtime.world.addLayoutSubscriber((t=>{"ready"===t&&c(!0)}))}return()=>{}}),[]),e.useEffect((()=>{w&&w.em&&w.em.updateBounds()}),[v]),e.useEffect((()=>{w&&(w.runtime.mode=s)}),[s]),e.useEffect((()=>{if(w){const t=w.runtime;t.resize(b.current.width,l.width,b.current.height,l.height),r?t.cover():t.goHome(),b.current.width=l.width,b.current.height=l.height,t.updateNextFrame()}}),[l.width,l.height]),e.useLayoutEffect((()=>{const t=m.current;t&&(t.style.width=`${v.width}px`,t.style.height=`${v.height}px`,t.style.pointerEvents="none",t.style.overflow="hidden")}),[v.height,v.width]),e.useLayoutEffect((()=>{const t=()=>{if(w&&w.runtime){const t=w.runtime;t.resize(b.current.width,l.width,b.current.height,l.height),b.current.width=l.width,b.current.height=l.height,t.updateNextFrame()}};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)}),[w,l.height,l.width]);const E=e.useCallback((function(t){const n=()=>{w&&(w.ready=!0)};return e.useEffect((()=>{if(!w)return()=>{};{const t=i&&i(w);t&&t.then?t.then(n):n()}}),[]),t.children}),[w]);return e.useEffect((()=>{if(w&&w.runtime){const t=w.runtime;if(n)return t.world.addLayoutSubscriber((e=>{"recalculate-world-size"===e&&t.goHome({cover:r})}))}return()=>{}}),[w,r,n]),e.useLayoutEffect((()=>{w&&go.render(a.default.createElement(E,null,a.default.createElement(Yr.Provider,{value:s},a.default.createElement(io.Provider,{value:w},t))),w.runtime)}),[w,s,t]),{loading:!d&&h,uri:d,imageError:p}},exports.useBeforeFrame=(t,i=[])=>{const n=Io();e.useEffect((()=>n?n.registerHook("useBeforeFrame",t):()=>{}),i)},exports.useCanvas=zo,exports.useControlledAnnotationList=(t=[])=>{const[i,n]=e.useState(t),[s,r]=e.useState(!1),[o,a]=e.useState(),l=e.useCallback((()=>{r(!0),a(void 0)}),[]),h=e.useCallback((t=>{r(!0),a(t)}),[]),c=e.useCallback((t=>{const e=x();n((i=>[...i,{id:e,...t}])),r(!1),a(void 0)}),[]);return{isEditing:s,onDeselect:e.useCallback((()=>{r(!1),a(void 0)}),[]),selectedAnnotation:o,onCreateNewAnnotation:c,annotations:i,onUpdateAnnotation:t=>{n((e=>e.map((e=>e.id===t.id?t:e))))},setIsEditing:r,setSelectedAnnotation:a,editAnnotation:h,addNewAnnotation:l}},exports.useFrame=$o,exports.useMode=Kr,exports.useResizeWorldItem=No,exports.useRuntime=Io,exports.useWorldEvent=Fo;
|
|
16
16
|
//# sourceMappingURL=index.js.map
|