@vielzeug/atlas 26.11.23 → 26.11.24
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/README.md +1 -0
- package/dist/atlas.cjs +1 -1
- package/dist/atlas.cjs.map +1 -1
- package/dist/atlas.iife.js +1 -1
- package/dist/atlas.iife.js.map +1 -1
- package/dist/atlas.js +87 -3
- package/dist/atlas.js.map +1 -1
- package/dist/frame.cjs +2 -0
- package/dist/frame.cjs.map +1 -0
- package/dist/frame.d.ts +51 -0
- package/dist/frame.d.ts.map +1 -0
- package/dist/frame.js +93 -0
- package/dist/frame.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ index.queryRect(camera.visibleRect); // viewport culling, returns ids
|
|
|
32
32
|
- Matrix helpers in Canvas2D element order, including `invert()` and `toCssMatrix()`
|
|
33
33
|
- Rect/AABB math: union, closed-interval intersection, containment, inflation, bounds-from-points
|
|
34
34
|
- Narrow-phase geometry: `pointInPolygon`, `distanceToPolyline`, `pointNearPolygon`
|
|
35
|
+
- Frames: `frameMatrix()` placement, `boundsOfFrame()` world AABBs, and `resizeRect()` edge/corner resizing with min and aspect locks
|
|
35
36
|
- Snapping: `snapRect()` with candidate, grid, and equal-gap (`spacing`) targets and kind-tagged guide descriptors, plus pure `alignRects()`/`distributeRects()`
|
|
36
37
|
- `@vielzeug/atlas/grid` subpath: square-tile coordinate math, viewport tile ranges, 8-octant shadowcasting `computeFov()`, and three-state `createFog()`
|
|
37
38
|
- Typed errors; the camera follows the Vielzeug disposal contract
|
package/dist/atlas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var AtlasError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},AtlasConfigError=class extends AtlasError{},e=Object.freeze([1,0,0,1,0,0]);function multiply(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function apply(e,t){return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}function translate(e,t){return[1,0,0,1,e,t]}function scale(e,t=e){return[e,0,0,t,0,0]}function rotate(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,-n,t,0,0]}function around(e,t){return multiply(multiply(translate(e.x,e.y),t),translate(-e.x,-e.y))}function scaleOf(e){return(Math.hypot(e[0],e[1])+Math.hypot(e[2],e[3]))/2}function toCssMatrix(e){return`matrix(${e.join(`,`)})`}function invert(e){let t=e[0]*e[3]-e[2]*e[1];if(!Number.isFinite(t)||t===0)return null;let n=1/t;return[e[3]*n,-e[1]*n,-e[2]*n,e[0]*n,(e[2]*e[5]-e[3]*e[4])*n,(e[1]*e[4]-e[0]*e[5])*n]}function rectFromPoints(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e)a=!0,o.x<t&&(t=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return a?{height:i-n,width:r-t,x:t,y:n}:null}function rectRight(e){return e.x+e.width}function rectBottom(e){return e.y+e.height}function rectCenter(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function unionRect(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(rectBottom(e),rectBottom(t))-r,width:Math.max(rectRight(e),rectRight(t))-n,x:n,y:r}}function intersectRect(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(rectRight(e),rectRight(t)),a=Math.min(rectBottom(e),rectBottom(t));return i<n||a<r?null:{height:a-r,width:i-n,x:n,y:r}}function containsRect(e,t){return e.x<=t.x&&e.y<=t.y&&rectRight(e)>=rectRight(t)&&rectBottom(e)>=rectBottom(t)}function containsPoint(e,t){return t.x>=e.x&&t.x<=rectRight(e)&&t.y>=e.y&&t.y<=rectBottom(e)}function inflateRect(e,t){return{height:e.height+t*2,width:e.width+t*2,x:e.x-t,y:e.y-t}}function rectsIntersect(e,t){return intersectRect(e,t)!==null}var t={cancelFrame:e=>cancelAnimationFrame(e),now:()=>performance.now(),requestFrame:e=>requestAnimationFrame(e)};function assertFinite(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function easeInOut(e){return e<.5?2*e*e:1-(-2*e+2)**2/2}function normalizeAngle(e){return((e+Math.PI)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)-Math.PI}function shortestAngle(e,t){return normalizeAngle(t-e)}function screenDeltaToWorld(e,t,n){return apply(multiply(rotate(-n),scale(1/t)),e)}function matrixOf(e,t){let n=multiply(multiply(scale(e.zoom),rotate(e.rotation)),translate(-e.x,-e.y));return multiply(translate(t.width/2,t.height/2),n)}function inverseOf(e,t){let n=multiply(rotate(-e.rotation),scale(1/e.zoom)),r=screenDeltaToWorld({x:t.width/2,y:t.height/2},e.zoom,e.rotation);return multiply(translate(e.x-r.x,e.y-r.y),n)}function createCamera(e={}){let n=e.minZoom??.01,r=e.maxZoom??1e3;if(!(n>0&&n<=r))throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${n} and ${r}`);let i=e.scheduler??t,a=e.initial??{},o=e.viewport??{height:0,width:0},s={rotation:normalizeAngle(a.rotation??0),x:a.x??0,y:a.y??0,zoom:Math.min(r,Math.max(n,a.zoom??1))};for(let[e,t]of[[`camera.x`,s.x],[`camera.y`,s.y],[`camera.rotation`,s.rotation]])assertFinite(e,t);let c=new AbortController,l=!1,u=null,d=new Set,f=null,p=null,matrix=()=>(f??=matrixOf(s,o),f),inverse=()=>(p??=inverseOf(s,o),p),invalidate=()=>{f=null,p=null},relativeToCentre=e=>({x:e.x-o.width/2,y:e.y-o.height/2}),emit=()=>{for(let e of[...d])e(s)},set=e=>{if(l)return;let t={rotation:normalizeAngle(e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(n,e.zoom??s.zoom))};(t.x!==s.x||t.y!==s.y||t.zoom!==s.zoom||t.rotation!==s.rotation)&&(s=t,invalidate(),emit())},stop=()=>{u&&=(i.cancelFrame(u.frame),u.cleanup(),null)},dispose=()=>{l||(l=!0,stop(),d.clear(),c.abort())},animateTo=(e,t={})=>{if(stop(),l)return;let a=t.duration??250,o=t.easing??easeInOut,c=t.signal;if(c?.aborted)return;if(a<=0){set(e);return}let d=s,f={rotation:d.rotation+shortestAngle(d.rotation,e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(n,e.zoom??s.zoom))},p=i.now(),m=Math.log(d.zoom),h=Math.log(f.zoom),g={cleanup:()=>{},frame:0};u=g;let abort=()=>{u===g&&stop()};c&&(c.addEventListener(`abort`,abort,{once:!0}),g.cleanup=()=>c.removeEventListener(`abort`,abort));let step=e=>{if(u!==g)return;let t=Math.min(1,(e-p)/a),n=o(t);set({rotation:d.rotation+(f.rotation-d.rotation)*n,x:d.x+(f.x-d.x)*n,y:d.y+(f.y-d.y)*n,zoom:Math.exp(m+(h-m)*n)}),t>=1?(u=null,g.cleanup()):g.frame=i.requestFrame(step)};g.frame=i.requestFrame(step)};return{animateTo,get disposalSignal(){return c.signal},dispose,get disposed(){return l},fitBounds(e,t={}){if(l)return;stop();let i=t.padding??0,a=Math.max(1,o.width-i*2),s=Math.max(1,o.height-i*2),c=Math.min(r,Math.max(n,Math.min(e.width===0?r:a/e.width,e.height===0?r:s/e.height)));set({x:e.x+e.width/2,y:e.y+e.height/2,zoom:c})},get inverse(){return inverse()},get matrix(){return matrix()},panBy(e,t){if(l)return;stop();let n=screenDeltaToWorld({x:e,y:t},s.zoom,s.rotation);set({x:s.x-n.x,y:s.y-n.y})},resize(e){l||(e.width!==o.width||e.height!==o.height)&&(o={height:e.height,width:e.width},invalidate(),emit())},rotateAt(e,t){if(l)return;stop();let n=apply(inverse(),e),r=s.rotation+t,i=screenDeltaToWorld(relativeToCentre(e),s.zoom,r);set({rotation:r,x:n.x-i.x,y:n.y-i.y})},set(e){stop(),set(e)},[Symbol.dispose]:dispose,get state(){return s},stop,subscribe(e,t){return l||t?.signal?.aborted?()=>{}:(d.add(e),t?.signal?.addEventListener(`abort`,()=>d.delete(e),{once:!0}),()=>d.delete(e))},toScreen(e){return apply(matrix(),e)},toWorld(e){return apply(inverse(),e)},get viewport(){return o},get visibleRect(){let e=inverse();return rectFromPoints([apply(e,{x:0,y:0}),apply(e,{x:o.width,y:0}),apply(e,{x:0,y:o.height}),apply(e,{x:o.width,y:o.height})])},zoomAt(e,t){if(!Number.isFinite(t)||t<=0)throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${t}`);if(l)return;stop();let i=apply(inverse(),e),a=Math.min(r,Math.max(n,s.zoom*t)),o=screenDeltaToWorld(relativeToCentre(e),a,s.rotation);set({x:i.x-o.x,y:i.y-o.y,zoom:a})}}}function pointInPolygon(e,t){let n=!1,r=e.length;for(let i=0,a=r-1;i<r;a=i++){let r=e[i],o=e[a];if(r.y>t.y==o.y>t.y)continue;let s=(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x;t.x<s&&(n=!n)}return n}function distanceToSegment(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function distanceToPolyline(e,t){if(e.length===0)return 1/0;if(e.length===1)return Math.hypot(t.x-e[0].x,t.y-e[0].y);let n=1/0;for(let r=0,i=1;i<e.length;r=i++){let a=distanceToSegment(t,e[r],e[i]);a<n&&(n=a)}return n}function pointNearPolygon(e,t,n){if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(n)}.`);return distanceToPolyline(e.length>0?[...e,e[0]]:e,t)<=n||pointInPolygon(e,t)}function xAnchors(e){return[e.x,e.x+e.width/2,rectRight(e)]}function yAnchors(e){return[e.y,e.y+e.height/2,rectBottom(e)]}function bestAxisSnap(e,t,n){let r=null;for(let i of e)for(let e of t){let t=e.value-i;Math.abs(t)>n||(r===null||Math.abs(t)<Math.abs(r.delta))&&(r={delta:t,kind:e.kind,position:e.value})}return r}function gridTargets(e,t,n,r){if(n===void 0||!Number.isFinite(n)||n<=0)return[];let i=[];for(let a=Math.floor((e-r)/n)*n;a<=t+r;a+=n)i.push({kind:`grid`,value:a});return i}function spanFor(e,t,n,r){let i=[];for(let t of n)(r===`x`?xAnchors(t):yAnchors(t)).some(t=>t===e)&&i.push(t);let a=rectFromPoints([t,...i].flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]))??{height:0,width:0,x:e,y:e};return r===`x`?{from:a.y,to:rectBottom(a)}:{from:a.x,to:rectRight(a)}}function overlapsPerpendicular(e,t,n){return n===`x`?e.y<rectBottom(t)&&t.y<rectBottom(e):e.x<rectRight(t)&&t.x<rectRight(e)}function axisSpacingSnap(e,t,n,r){let i=n===`x`?e=>e.x:e=>e.y,a=n===`x`?e=>rectRight(e):e=>rectBottom(e),o=-1/0,s=1/0;for(let r of t)overlapsPerpendicular(e,r,n)&&(a(r)<=i(e)&&a(r)>o&&(o=a(r)),i(r)>=a(e)&&i(r)<s&&(s=i(r)));if(o===-1/0||s===1/0)return null;let c=s-o-(n===`x`?e.width:e.height);if(c<0)return null;let l=o+c/2-i(e);if(Math.abs(l)>r)return null;let u=c/2;return{delta:l,marks:[o+u/2,s-u/2],position:n===`x`?rectCenter(e).y:rectCenter(e).x,span:[o,s]}}function snapRect(e,t){let{candidates:n,grid:r,spacing:i,threshold:a}=t;if(!(a>=0))throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(a)}.`);let o=e.x,s=e.y,c={x:0,y:0},l=n.flatMap(e=>xAnchors(e).map(e=>({kind:`object`,value:e})));l.push(...gridTargets(e.x,rectRight(e),r?.x,a));let u=bestAxisSnap(xAnchors(e),l,a);u!==null&&(c.x=u.delta,o+=u.delta);let d=n.flatMap(e=>yAnchors(e).map(e=>({kind:`object`,value:e})));d.push(...gridTargets(e.y,rectBottom(e),r?.y,a));let f=bestAxisSnap(yAnchors(e),d,a);f!==null&&(c.y=f.delta,s+=f.delta);let p={...e,x:o,y:s},m=[];if(u!==null){let e=spanFor(u.position,p,n,`x`);m.push({axis:`x`,from:e.from,kind:u.kind,position:u.position,to:e.to})}if(f!==null){let e=spanFor(f.position,p,n,`y`);m.push({axis:`y`,from:e.from,kind:f.kind,position:f.position,to:e.to})}if(i){if(u===null){let e=axisSpacingSnap(p,n,`x`,a);e!==null&&(c.x=e.delta,m.push({axis:`y`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}if(f===null){let e=axisSpacingSnap(p,n,`y`,a);e!==null&&(c.y=e.delta,m.push({axis:`x`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}}return{delta:c,guides:m}}function alignRects(e,t){if(e.length===0)return[];let n=rectFromPoints(e.flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]));return n===null?[]:e.map(e=>{switch(t){case`left`:return{...e,x:n.x};case`horizontal-center`:return{...e,x:rectCenter(n).x-e.width/2};case`right`:return{...e,x:rectRight(n)-e.width};case`top`:return{...e,y:n.y};case`vertical-center`:return{...e,y:rectCenter(n).y-e.height/2};case`bottom`:return{...e,y:rectBottom(n)-e.height};default:throw new AtlasConfigError(`unknown align edge: ${String(t)}.`)}})}function distributeRects(e,t){if(e.length<=2)return e.map(e=>({...e}));let n=t===`x`?e=>e.x:e=>e.y,r=t===`x`?e=>e.width:e=>e.height,i=e.map((e,t)=>({index:t,rect:e})).sort((e,t)=>n(e.rect)-n(t.rect)||e.index-t.index),a=i[0].rect,o=i[i.length-1].rect,s=(n(o)+r(o)-n(a)-i.reduce((e,t)=>e+r(t.rect),0))/(i.length-1),c=e.map(e=>({...e})),l=n(a);for(let e of i){let n={...e.rect};t===`x`?n.x=l:n.y=l,c[e.index]=n,l+=r(e.rect)+s}return c}function rectOf(e){return e.rect}function unionRects(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(e.y+e.height,t.y+t.height)-r,width:Math.max(e.x+e.width,t.x+t.width)-n,x:n,y:r}}function area(e){return e.width*e.height}function rectsEqual(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function recompute(e){let t=null;for(let n of e.children)t=t===null?{...rectOf(n)}:unionRects(t,rectOf(n));e.rect=t}function createSpatialIndex(e={}){let t=e.maxEntriesPerNode??8;if(!Number.isInteger(t)||t<4)throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${t}`);let n=Math.max(2,Math.ceil(t/3)),r=new Map,i={children:[],leaf:!0,rect:null},pickChild=(e,t)=>{let n=null,r=1/0,i=1/0;for(let a of e.children){let e=a.rect??t,o=area(unionRects(e,t))-area(e);(o<r||o===r&&area(e)<i)&&(n=a,r=o,i=area(e))}return n},split=e=>{let r=e.children,i=0,a=1,o=-1/0;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=area(unionRects(rectOf(r[e]),rectOf(r[t])))-area(rectOf(r[e]))-area(rectOf(r[t]));n>o&&(o=n,i=e,a=t)}let s=[r[i]],c=[r[a]],l=rectOf(r[i]),u=rectOf(r[a]),d=r.filter((e,t)=>t!==i&&t!==a);for(let[e,r]of d.entries()){let i=s.length+(d.length-e)>t||c.length+(d.length-e)-1<n,a=c.length+(d.length-e)>t||s.length+(d.length-e)-1<n,o;if(i)o=!0;else if(a)o=!1;else{let e=area(unionRects(l,rectOf(r)))-area(l),t=area(unionRects(u,rectOf(r)))-area(u);o=e<t||e===t&&area(l)<=area(u)}o?(s.push(r),l=unionRects(l,rectOf(r))):(c.push(r),u=unionRects(u,rectOf(r)))}let f=e.leaf?{children:s,leaf:!0,rect:null}:{children:s,leaf:!1,rect:null},p=e.leaf?{children:c,leaf:!0,rect:null}:{children:c,leaf:!1,rect:null};return recompute(f),recompute(p),[f,p]},insertInto=(e,n)=>{if(e.leaf)return e.children.push(n),e.rect=e.rect===null?{...rectOf(n)}:unionRects(e.rect,rectOf(n)),e.children.length>t?split(e):null;let r=e,i=pickChild(r,rectOf(n)),a=insertInto(i,n);if(recompute(e),a){let t=r.children.indexOf(i);r.children.splice(t,1,a[0],a[1]),recompute(e)}return e.children.length>t?split(e):null},insertEntry=e=>{!i.leaf&&i.children.length===0&&(i={children:[],leaf:!0,rect:null});let t=insertInto(i,e);t&&(i={children:t,leaf:!1,rect:null},recompute(i))},removeFrom=(e,t)=>{if(e.leaf){let n=e.children.indexOf(t);return n!==-1&&e.children.splice(n,1),recompute(e),e.children.length===0}let n=e;for(let e=n.children.length-1;e>=0;e--){let r=n.children[e];r.rect&&containsRect(r.rect,t.rect)&&removeFrom(r,t)&&n.children.splice(e,1)}return recompute(e),n.children.length===0},deleteEntry=e=>{let t=r.get(e);if(!t)return!1;for(r.delete(e),removeFrom(i,t);!i.leaf&&i.children.length===1;)i=i.children[0];return!0},queryInto=(e,t,n)=>{if(e.rect&&t(e.rect)){if(e.leaf)for(let r of e.children)t(r.rect)&&n.push(r.id);else for(let r of e.children)queryInto(r,t,n)}};return{get bounds(){return i.rect},clear(){r.clear(),i={children:[],leaf:!0,rect:null}},delete:deleteEntry,get(e){return r.get(e)?.rect},has(e){return r.has(e)},queryPoint(e,t){let n=t?.tolerance??0;if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${n}`);let r=inflateRect({...e,height:0,width:0},n),a=[];return queryInto(i,e=>rectsIntersect(e,r),a),a},queryRect(e){let t=[];return queryInto(i,t=>rectsIntersect(t,e),t),t},set(e,t){let n=r.get(e);if(n){if(rectsEqual(n.rect,t))return;deleteEntry(e)}let i={id:e,rect:{...t}};r.set(e,i),insertEntry(i)},get size(){return r.size}}}exports.AtlasConfigError=AtlasConfigError,exports.AtlasError=AtlasError,exports.IDENTITY=e,exports.alignRects=alignRects,exports.apply=apply,exports.around=around,exports.containsPoint=containsPoint,exports.containsRect=containsRect,exports.createCamera=createCamera,exports.createSpatialIndex=createSpatialIndex,exports.distanceToPolyline=distanceToPolyline,exports.distributeRects=distributeRects,exports.inflateRect=inflateRect,exports.intersectRect=intersectRect,exports.invert=invert,exports.multiply=multiply,exports.pointInPolygon=pointInPolygon,exports.pointNearPolygon=pointNearPolygon,exports.rectBottom=rectBottom,exports.rectCenter=rectCenter,exports.rectFromPoints=rectFromPoints,exports.rectRight=rectRight,exports.rectsIntersect=rectsIntersect,exports.rotate=rotate,exports.scale=scale,exports.scaleOf=scaleOf,exports.snapRect=snapRect,exports.toCssMatrix=toCssMatrix,exports.translate=translate,exports.unionRect=unionRect;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var AtlasError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},AtlasConfigError=class extends AtlasError{},e=Object.freeze([1,0,0,1,0,0]);function multiply(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function apply(e,t){return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}function translate(e,t){return[1,0,0,1,e,t]}function scale(e,t=e){return[e,0,0,t,0,0]}function rotate(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,-n,t,0,0]}function around(e,t){return multiply(multiply(translate(e.x,e.y),t),translate(-e.x,-e.y))}function scaleOf(e){return(Math.hypot(e[0],e[1])+Math.hypot(e[2],e[3]))/2}function toCssMatrix(e){return`matrix(${e.join(`,`)})`}function invert(e){let t=e[0]*e[3]-e[2]*e[1];if(!Number.isFinite(t)||t===0)return null;let n=1/t;return[e[3]*n,-e[1]*n,-e[2]*n,e[0]*n,(e[2]*e[5]-e[3]*e[4])*n,(e[1]*e[4]-e[0]*e[5])*n]}function rectFromPoints(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e)a=!0,o.x<t&&(t=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return a?{height:i-n,width:r-t,x:t,y:n}:null}function rectRight(e){return e.x+e.width}function rectBottom(e){return e.y+e.height}function rectCenter(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function unionRect(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(rectBottom(e),rectBottom(t))-r,width:Math.max(rectRight(e),rectRight(t))-n,x:n,y:r}}function intersectRect(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(rectRight(e),rectRight(t)),a=Math.min(rectBottom(e),rectBottom(t));return i<n||a<r?null:{height:a-r,width:i-n,x:n,y:r}}function containsRect(e,t){return e.x<=t.x&&e.y<=t.y&&rectRight(e)>=rectRight(t)&&rectBottom(e)>=rectBottom(t)}function containsPoint(e,t){return t.x>=e.x&&t.x<=rectRight(e)&&t.y>=e.y&&t.y<=rectBottom(e)}function inflateRect(e,t){return{height:e.height+t*2,width:e.width+t*2,x:e.x-t,y:e.y-t}}function rectsIntersect(e,t){return intersectRect(e,t)!==null}var t={cancelFrame:e=>cancelAnimationFrame(e),now:()=>performance.now(),requestFrame:e=>requestAnimationFrame(e)};function assertFinite$1(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function easeInOut(e){return e<.5?2*e*e:1-(-2*e+2)**2/2}function normalizeAngle(e){return((e+Math.PI)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)-Math.PI}function shortestAngle(e,t){return normalizeAngle(t-e)}function screenDeltaToWorld(e,t,n){return apply(multiply(rotate(-n),scale(1/t)),e)}function matrixOf(e,t){let n=multiply(multiply(scale(e.zoom),rotate(e.rotation)),translate(-e.x,-e.y));return multiply(translate(t.width/2,t.height/2),n)}function inverseOf(e,t){let n=multiply(rotate(-e.rotation),scale(1/e.zoom)),r=screenDeltaToWorld({x:t.width/2,y:t.height/2},e.zoom,e.rotation);return multiply(translate(e.x-r.x,e.y-r.y),n)}function createCamera(e={}){let n=e.minZoom??.01,r=e.maxZoom??1e3;if(!(n>0&&n<=r))throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${n} and ${r}`);let i=e.scheduler??t,a=e.initial??{},o=e.viewport??{height:0,width:0},s={rotation:normalizeAngle(a.rotation??0),x:a.x??0,y:a.y??0,zoom:Math.min(r,Math.max(n,a.zoom??1))};for(let[e,t]of[[`camera.x`,s.x],[`camera.y`,s.y],[`camera.rotation`,s.rotation]])assertFinite$1(e,t);let c=new AbortController,l=!1,u=null,d=new Set,f=null,p=null,matrix=()=>(f??=matrixOf(s,o),f),inverse=()=>(p??=inverseOf(s,o),p),invalidate=()=>{f=null,p=null},relativeToCentre=e=>({x:e.x-o.width/2,y:e.y-o.height/2}),emit=()=>{for(let e of[...d])e(s)},set=e=>{if(l)return;let t={rotation:normalizeAngle(e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(n,e.zoom??s.zoom))};(t.x!==s.x||t.y!==s.y||t.zoom!==s.zoom||t.rotation!==s.rotation)&&(s=t,invalidate(),emit())},stop=()=>{u&&=(i.cancelFrame(u.frame),u.cleanup(),null)},dispose=()=>{l||(l=!0,stop(),d.clear(),c.abort())},animateTo=(e,t={})=>{if(stop(),l)return;let a=t.duration??250,o=t.easing??easeInOut,c=t.signal;if(c?.aborted)return;if(a<=0){set(e);return}let d=s,f={rotation:d.rotation+shortestAngle(d.rotation,e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(n,e.zoom??s.zoom))},p=i.now(),m=Math.log(d.zoom),h=Math.log(f.zoom),g={cleanup:()=>{},frame:0};u=g;let abort=()=>{u===g&&stop()};c&&(c.addEventListener(`abort`,abort,{once:!0}),g.cleanup=()=>c.removeEventListener(`abort`,abort));let step=e=>{if(u!==g)return;let t=Math.min(1,(e-p)/a),n=o(t);set({rotation:d.rotation+(f.rotation-d.rotation)*n,x:d.x+(f.x-d.x)*n,y:d.y+(f.y-d.y)*n,zoom:Math.exp(m+(h-m)*n)}),t>=1?(u=null,g.cleanup()):g.frame=i.requestFrame(step)};g.frame=i.requestFrame(step)};return{animateTo,get disposalSignal(){return c.signal},dispose,get disposed(){return l},fitBounds(e,t={}){if(l)return;stop();let i=t.padding??0,a=Math.max(1,o.width-i*2),s=Math.max(1,o.height-i*2),c=Math.min(r,Math.max(n,Math.min(e.width===0?r:a/e.width,e.height===0?r:s/e.height)));set({x:e.x+e.width/2,y:e.y+e.height/2,zoom:c})},get inverse(){return inverse()},get matrix(){return matrix()},panBy(e,t){if(l)return;stop();let n=screenDeltaToWorld({x:e,y:t},s.zoom,s.rotation);set({x:s.x-n.x,y:s.y-n.y})},resize(e){l||(e.width!==o.width||e.height!==o.height)&&(o={height:e.height,width:e.width},invalidate(),emit())},rotateAt(e,t){if(l)return;stop();let n=apply(inverse(),e),r=s.rotation+t,i=screenDeltaToWorld(relativeToCentre(e),s.zoom,r);set({rotation:r,x:n.x-i.x,y:n.y-i.y})},set(e){stop(),set(e)},[Symbol.dispose]:dispose,get state(){return s},stop,subscribe(e,t){return l||t?.signal?.aborted?()=>{}:(d.add(e),t?.signal?.addEventListener(`abort`,()=>d.delete(e),{once:!0}),()=>d.delete(e))},toScreen(e){return apply(matrix(),e)},toWorld(e){return apply(inverse(),e)},get viewport(){return o},get visibleRect(){let e=inverse();return rectFromPoints([apply(e,{x:0,y:0}),apply(e,{x:o.width,y:0}),apply(e,{x:0,y:o.height}),apply(e,{x:o.width,y:o.height})])},zoomAt(e,t){if(!Number.isFinite(t)||t<=0)throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${t}`);if(l)return;stop();let i=apply(inverse(),e),a=Math.min(r,Math.max(n,s.zoom*t)),o=screenDeltaToWorld(relativeToCentre(e),a,s.rotation);set({x:i.x-o.x,y:i.y-o.y,zoom:a})}}}var n=new Set([`e`,`n`,`ne`,`nw`,`s`,`se`,`sw`,`w`]);function assertFinite(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function frameMatrix(e){assertFinite(`frame.x`,e.x),assertFinite(`frame.y`,e.y);let t=e.rotation??0;assertFinite(`frame.rotation`,t);let n=e.scale??1,r=typeof n==`number`?n:n.x??1,i=typeof n==`number`?n:n.y??r;assertFinite(`frame.scale`,r),assertFinite(`frame.scale`,i);let a=e.origin??{x:e.x,y:e.y};return assertFinite(`frame.origin.x`,a.x),assertFinite(`frame.origin.y`,a.y),multiply(around(a,multiply(rotate(t),scale(r,i))),translate(e.x,e.y))}function boundsOfFrame(e,t){assertFiniteRect(e);for(let e=0;e<6;e++)assertFinite(`matrix[${e}]`,t[e]);return rectFromPoints([apply(t,{x:e.x,y:e.y}),apply(t,{x:rectRight(e),y:e.y}),apply(t,{x:e.x,y:rectBottom(e)}),apply(t,{x:rectRight(e),y:rectBottom(e)})])}function assertFiniteRect(e){assertFinite(`rect.x`,e.x),assertFinite(`rect.y`,e.y),assertFinite(`rect.width`,e.width),assertFinite(`rect.height`,e.height)}function resizeRect(e,t,r,i={}){if(assertFiniteRect(e),assertFinite(`point.x`,r.x),assertFinite(`point.y`,r.y),!n.has(t))throw new AtlasConfigError(`unknown resize edges: ${String(t)}. Expected one of ${[...n].join(`, `)}.`);let a=i.min??0;if(assertFinite(`min`,a),a<0)throw new AtlasConfigError(`min must be non-negative, received ${a}`);let o=i.aspect;if(o!==void 0&&(assertFinite(`aspect`,o),o<=0))throw new AtlasConfigError(`aspect must be positive, received ${o}`);let s=t.includes(`w`),c=t.includes(`e`),l=t.includes(`n`),u=t.includes(`s`),d=e.x,f=rectRight(e),p=e.y,m=rectBottom(e);if(s&&(d=Math.min(r.x,f-a)),c&&(f=Math.max(r.x,d+a)),l&&(p=Math.min(r.y,m-a)),u&&(m=Math.max(r.y,p+a)),o!==void 0){let t=Math.max(a,a*o),n=f-d,r=m-p,i=s||c,h=l||u,applyWidth=e=>{s?d=f-e:f=d+e},applyHeight=e=>{l?p=m-e:m=p+e};if(i&&h)Math.max(Math.abs(f-rectRight(e)),Math.abs(d-e.x))>=Math.max(Math.abs(m-rectBottom(e)),Math.abs(p-e.y))?(applyWidth(Math.max(n,t)),applyHeight((f-d)/o)):(applyHeight(Math.max(r,t/o)),applyWidth((m-p)*o));else if(i){let r=Math.max(n,t);applyWidth(r);let i=r/o,a=e.y+e.height/2;p=a-i/2,m=a+i/2}else{let n=Math.max(r,t/o);applyHeight(n);let i=n*o,a=e.x+e.width/2;d=a-i/2,f=a+i/2}}return{height:m-p,width:f-d,x:d,y:p}}function pointInPolygon(e,t){let n=!1,r=e.length;for(let i=0,a=r-1;i<r;a=i++){let r=e[i],o=e[a];if(r.y>t.y==o.y>t.y)continue;let s=(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x;t.x<s&&(n=!n)}return n}function distanceToSegment(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function distanceToPolyline(e,t){if(e.length===0)return 1/0;if(e.length===1)return Math.hypot(t.x-e[0].x,t.y-e[0].y);let n=1/0;for(let r=0,i=1;i<e.length;r=i++){let a=distanceToSegment(t,e[r],e[i]);a<n&&(n=a)}return n}function pointNearPolygon(e,t,n){if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(n)}.`);return distanceToPolyline(e.length>0?[...e,e[0]]:e,t)<=n||pointInPolygon(e,t)}function xAnchors(e){return[e.x,e.x+e.width/2,rectRight(e)]}function yAnchors(e){return[e.y,e.y+e.height/2,rectBottom(e)]}function bestAxisSnap(e,t,n){let r=null;for(let i of e)for(let e of t){let t=e.value-i;Math.abs(t)>n||(r===null||Math.abs(t)<Math.abs(r.delta))&&(r={delta:t,kind:e.kind,position:e.value})}return r}function gridTargets(e,t,n,r){if(n===void 0||!Number.isFinite(n)||n<=0)return[];let i=[];for(let a=Math.floor((e-r)/n)*n;a<=t+r;a+=n)i.push({kind:`grid`,value:a});return i}function spanFor(e,t,n,r){let i=[];for(let t of n)(r===`x`?xAnchors(t):yAnchors(t)).some(t=>t===e)&&i.push(t);let a=rectFromPoints([t,...i].flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]))??{height:0,width:0,x:e,y:e};return r===`x`?{from:a.y,to:rectBottom(a)}:{from:a.x,to:rectRight(a)}}function overlapsPerpendicular(e,t,n){return n===`x`?e.y<rectBottom(t)&&t.y<rectBottom(e):e.x<rectRight(t)&&t.x<rectRight(e)}function axisSpacingSnap(e,t,n,r){let i=n===`x`?e=>e.x:e=>e.y,a=n===`x`?e=>rectRight(e):e=>rectBottom(e),o=-1/0,s=1/0;for(let r of t)overlapsPerpendicular(e,r,n)&&(a(r)<=i(e)&&a(r)>o&&(o=a(r)),i(r)>=a(e)&&i(r)<s&&(s=i(r)));if(o===-1/0||s===1/0)return null;let c=s-o-(n===`x`?e.width:e.height);if(c<0)return null;let l=o+c/2-i(e);if(Math.abs(l)>r)return null;let u=c/2;return{delta:l,marks:[o+u/2,s-u/2],position:n===`x`?rectCenter(e).y:rectCenter(e).x,span:[o,s]}}function snapRect(e,t){let{candidates:n,grid:r,spacing:i,threshold:a}=t;if(!(a>=0))throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(a)}.`);let o=e.x,s=e.y,c={x:0,y:0},l=n.flatMap(e=>xAnchors(e).map(e=>({kind:`object`,value:e})));l.push(...gridTargets(e.x,rectRight(e),r?.x,a));let u=bestAxisSnap(xAnchors(e),l,a);u!==null&&(c.x=u.delta,o+=u.delta);let d=n.flatMap(e=>yAnchors(e).map(e=>({kind:`object`,value:e})));d.push(...gridTargets(e.y,rectBottom(e),r?.y,a));let f=bestAxisSnap(yAnchors(e),d,a);f!==null&&(c.y=f.delta,s+=f.delta);let p={...e,x:o,y:s},m=[];if(u!==null){let e=spanFor(u.position,p,n,`x`);m.push({axis:`x`,from:e.from,kind:u.kind,position:u.position,to:e.to})}if(f!==null){let e=spanFor(f.position,p,n,`y`);m.push({axis:`y`,from:e.from,kind:f.kind,position:f.position,to:e.to})}if(i){if(u===null){let e=axisSpacingSnap(p,n,`x`,a);e!==null&&(c.x=e.delta,m.push({axis:`y`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}if(f===null){let e=axisSpacingSnap(p,n,`y`,a);e!==null&&(c.y=e.delta,m.push({axis:`x`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}}return{delta:c,guides:m}}function alignRects(e,t){if(e.length===0)return[];let n=rectFromPoints(e.flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]));return n===null?[]:e.map(e=>{switch(t){case`left`:return{...e,x:n.x};case`horizontal-center`:return{...e,x:rectCenter(n).x-e.width/2};case`right`:return{...e,x:rectRight(n)-e.width};case`top`:return{...e,y:n.y};case`vertical-center`:return{...e,y:rectCenter(n).y-e.height/2};case`bottom`:return{...e,y:rectBottom(n)-e.height};default:throw new AtlasConfigError(`unknown align edge: ${String(t)}.`)}})}function distributeRects(e,t){if(e.length<=2)return e.map(e=>({...e}));let n=t===`x`?e=>e.x:e=>e.y,r=t===`x`?e=>e.width:e=>e.height,i=e.map((e,t)=>({index:t,rect:e})).sort((e,t)=>n(e.rect)-n(t.rect)||e.index-t.index),a=i[0].rect,o=i[i.length-1].rect,s=(n(o)+r(o)-n(a)-i.reduce((e,t)=>e+r(t.rect),0))/(i.length-1),c=e.map(e=>({...e})),l=n(a);for(let e of i){let n={...e.rect};t===`x`?n.x=l:n.y=l,c[e.index]=n,l+=r(e.rect)+s}return c}function rectOf(e){return e.rect}function unionRects(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(e.y+e.height,t.y+t.height)-r,width:Math.max(e.x+e.width,t.x+t.width)-n,x:n,y:r}}function area(e){return e.width*e.height}function rectsEqual(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function recompute(e){let t=null;for(let n of e.children)t=t===null?{...rectOf(n)}:unionRects(t,rectOf(n));e.rect=t}function createSpatialIndex(e={}){let t=e.maxEntriesPerNode??8;if(!Number.isInteger(t)||t<4)throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${t}`);let n=Math.max(2,Math.ceil(t/3)),r=new Map,i={children:[],leaf:!0,rect:null},pickChild=(e,t)=>{let n=null,r=1/0,i=1/0;for(let a of e.children){let e=a.rect??t,o=area(unionRects(e,t))-area(e);(o<r||o===r&&area(e)<i)&&(n=a,r=o,i=area(e))}return n},split=e=>{let r=e.children,i=0,a=1,o=-1/0;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=area(unionRects(rectOf(r[e]),rectOf(r[t])))-area(rectOf(r[e]))-area(rectOf(r[t]));n>o&&(o=n,i=e,a=t)}let s=[r[i]],c=[r[a]],l=rectOf(r[i]),u=rectOf(r[a]),d=r.filter((e,t)=>t!==i&&t!==a);for(let[e,r]of d.entries()){let i=s.length+(d.length-e)>t||c.length+(d.length-e)-1<n,a=c.length+(d.length-e)>t||s.length+(d.length-e)-1<n,o;if(i)o=!0;else if(a)o=!1;else{let e=area(unionRects(l,rectOf(r)))-area(l),t=area(unionRects(u,rectOf(r)))-area(u);o=e<t||e===t&&area(l)<=area(u)}o?(s.push(r),l=unionRects(l,rectOf(r))):(c.push(r),u=unionRects(u,rectOf(r)))}let f=e.leaf?{children:s,leaf:!0,rect:null}:{children:s,leaf:!1,rect:null},p=e.leaf?{children:c,leaf:!0,rect:null}:{children:c,leaf:!1,rect:null};return recompute(f),recompute(p),[f,p]},insertInto=(e,n)=>{if(e.leaf)return e.children.push(n),e.rect=e.rect===null?{...rectOf(n)}:unionRects(e.rect,rectOf(n)),e.children.length>t?split(e):null;let r=e,i=pickChild(r,rectOf(n)),a=insertInto(i,n);if(recompute(e),a){let t=r.children.indexOf(i);r.children.splice(t,1,a[0],a[1]),recompute(e)}return e.children.length>t?split(e):null},insertEntry=e=>{!i.leaf&&i.children.length===0&&(i={children:[],leaf:!0,rect:null});let t=insertInto(i,e);t&&(i={children:t,leaf:!1,rect:null},recompute(i))},removeFrom=(e,t)=>{if(e.leaf){let n=e.children.indexOf(t);return n!==-1&&e.children.splice(n,1),recompute(e),e.children.length===0}let n=e;for(let e=n.children.length-1;e>=0;e--){let r=n.children[e];r.rect&&containsRect(r.rect,t.rect)&&removeFrom(r,t)&&n.children.splice(e,1)}return recompute(e),n.children.length===0},deleteEntry=e=>{let t=r.get(e);if(!t)return!1;for(r.delete(e),removeFrom(i,t);!i.leaf&&i.children.length===1;)i=i.children[0];return!0},queryInto=(e,t,n)=>{if(e.rect&&t(e.rect)){if(e.leaf)for(let r of e.children)t(r.rect)&&n.push(r.id);else for(let r of e.children)queryInto(r,t,n)}};return{get bounds(){return i.rect},clear(){r.clear(),i={children:[],leaf:!0,rect:null}},delete:deleteEntry,get(e){return r.get(e)?.rect},has(e){return r.has(e)},queryPoint(e,t){let n=t?.tolerance??0;if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${n}`);let r=inflateRect({...e,height:0,width:0},n),a=[];return queryInto(i,e=>rectsIntersect(e,r),a),a},queryRect(e){let t=[];return queryInto(i,t=>rectsIntersect(t,e),t),t},set(e,t){let n=r.get(e);if(n){if(rectsEqual(n.rect,t))return;deleteEntry(e)}let i={id:e,rect:{...t}};r.set(e,i),insertEntry(i)},get size(){return r.size}}}exports.AtlasConfigError=AtlasConfigError,exports.AtlasError=AtlasError,exports.IDENTITY=e,exports.alignRects=alignRects,exports.apply=apply,exports.around=around,exports.boundsOfFrame=boundsOfFrame,exports.containsPoint=containsPoint,exports.containsRect=containsRect,exports.createCamera=createCamera,exports.createSpatialIndex=createSpatialIndex,exports.distanceToPolyline=distanceToPolyline,exports.distributeRects=distributeRects,exports.frameMatrix=frameMatrix,exports.inflateRect=inflateRect,exports.intersectRect=intersectRect,exports.invert=invert,exports.multiply=multiply,exports.pointInPolygon=pointInPolygon,exports.pointNearPolygon=pointNearPolygon,exports.rectBottom=rectBottom,exports.rectCenter=rectCenter,exports.rectFromPoints=rectFromPoints,exports.rectRight=rectRight,exports.rectsIntersect=rectsIntersect,exports.resizeRect=resizeRect,exports.rotate=rotate,exports.scale=scale,exports.scaleOf=scaleOf,exports.snapRect=snapRect,exports.toCssMatrix=toCssMatrix,exports.translate=translate,exports.unionRect=unionRect;
|
|
2
2
|
//# sourceMappingURL=atlas.cjs.map
|
package/dist/atlas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atlas.cjs","names":["message","opts","IDENTITY","a","b","matrix","point","tx","ty","sx","sy","cos","radians","sin","anchor","det","inv","minX","minY","maxX","maxY","found","points","rect","x","y","right","bottom","outer","inner","amount","DEFAULT_SCHEDULER","handle","callback","value","name","t","angle","to","from","rotation","zoom","delta","m","s","viewport","minZoom","options","maxZoom","scheduler","initial","state","controller","disposed","animation","listeners","cachedMatrix","cachedInverse","screenPoint","listener","candidate","next","duration","animateOptions","easing","signal","target","start","logFrom","logTo","frame","time","e","padding","fitOptions","availableWidth","availableHeight","bounds","offset","dx","dy","size","world","subscribeOptions","factor","inside","n","polygon","j","xAtY","lengthSq","path","best","i","d","tolerance","anchors","targets","threshold","spacing","line","min","max","touching","candidates","axis","position","moved","r","end","leftEnd","rightStart","free","gap","movedX","movedY","xTargets","grid","xSnap","yTargets","ySnap","movedRect","guides","span","rects","edge","order","first","last","sum","entry","result","cursor","node","child","maxEntries","minEntries","entries","root","bestEnlargement","bestArea","current","enlargement","items","si","sj","worst","waste","groupA","groupB","rectA","rectB","remaining","index","item","mustA","mustB","toA","enlargeA","enlargeB","branch","overflow","id","hits","out","queryOptions","box","existing"],"sources":["../src/errors.ts","../src/matrix.ts","../src/rect.ts","../src/camera.ts","../src/geometry.ts","../src/snap.ts","../src/spatial-index.ts"],"sourcesContent":["export class AtlasError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class AtlasConfigError extends AtlasError {}\n","import type { Matrix, Point } from './shapes.js';\n\nexport const IDENTITY: Matrix = Object.freeze([1, 0, 0, 1, 0, 0]) as Matrix;\n\nexport function multiply(a: Matrix, b: Matrix): Matrix {\n return [\n a[0] * b[0] + a[2] * b[1],\n a[1] * b[0] + a[3] * b[1],\n a[0] * b[2] + a[2] * b[3],\n a[1] * b[2] + a[3] * b[3],\n a[0] * b[4] + a[2] * b[5] + a[4],\n a[1] * b[4] + a[3] * b[5] + a[5],\n ];\n}\n\nexport function apply(matrix: Matrix, point: Point): Point {\n return {\n x: matrix[0] * point.x + matrix[2] * point.y + matrix[4],\n y: matrix[1] * point.x + matrix[3] * point.y + matrix[5],\n };\n}\n\nexport function translate(tx: number, ty: number): Matrix {\n return [1, 0, 0, 1, tx, ty];\n}\n\nexport function scale(sx: number, sy: number = sx): Matrix {\n return [sx, 0, 0, sy, 0, 0];\n}\n\n/** Rotation in radians; positive is clockwise on screen (y grows downward). */\nexport function rotate(radians: number): Matrix {\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n return [cos, sin, -sin, cos, 0, 0];\n}\n\n/** Transform applied around an anchor point: translate(anchor) · matrix · translate(-anchor). */\nexport function around(anchor: Point, matrix: Matrix): Matrix {\n return multiply(multiply(translate(anchor.x, anchor.y), matrix), translate(-anchor.x, -anchor.y));\n}\n\n/** Average axis scale of a matrix; 0 for degenerate matrices. */\nexport function scaleOf(matrix: Matrix): number {\n const sx = Math.hypot(matrix[0], matrix[1]);\n const sy = Math.hypot(matrix[2], matrix[3]);\n return (sx + sy) / 2;\n}\n\n/** Serializes to a CSS `matrix()` value usable in a DOM element's `transform`. */\nexport function toCssMatrix(matrix: Matrix): string {\n return `matrix(${matrix.join(',')})`;\n}\n\n/** Returns null for non-invertible matrices (zero determinant). */\nexport function invert(matrix: Matrix): Matrix | null {\n const det = matrix[0] * matrix[3] - matrix[2] * matrix[1];\n if (!Number.isFinite(det) || det === 0) return null;\n const inv = 1 / det;\n return [\n matrix[3] * inv,\n -matrix[1] * inv,\n -matrix[2] * inv,\n matrix[0] * inv,\n (matrix[2] * matrix[5] - matrix[3] * matrix[4]) * inv,\n (matrix[1] * matrix[4] - matrix[0] * matrix[5]) * inv,\n ];\n}\n","import type { Point, Rect } from './shapes.js';\n\nexport function rectFromPoints(points: readonly [Point, ...Point[]]): Rect;\nexport function rectFromPoints(points: Iterable<Point>): Rect | null;\nexport function rectFromPoints(points: Iterable<Point>): Rect | null {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n let found = false;\n for (const point of points) {\n found = true;\n if (point.x < minX) minX = point.x;\n if (point.y < minY) minY = point.y;\n if (point.x > maxX) maxX = point.x;\n if (point.y > maxY) maxY = point.y;\n }\n if (!found) return null;\n return { height: maxY - minY, width: maxX - minX, x: minX, y: minY };\n}\n\nexport function rectRight(rect: Rect): number {\n return rect.x + rect.width;\n}\n\nexport function rectBottom(rect: Rect): number {\n return rect.y + rect.height;\n}\n\nexport function rectCenter(rect: Rect): Point {\n return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };\n}\n\nexport function unionRect(a: Rect, b: Rect): Rect {\n const x = Math.min(a.x, b.x);\n const y = Math.min(a.y, b.y);\n return {\n height: Math.max(rectBottom(a), rectBottom(b)) - y,\n width: Math.max(rectRight(a), rectRight(b)) - x,\n x,\n y,\n };\n}\n\n/**\n * Overlap of two rects using closed intervals: touching rects (or a zero-area\n * rect on another's edge) intersect and may yield a zero-area result.\n * Returns null only when the rects are disjoint.\n */\nexport function intersectRect(a: Rect, b: Rect): Rect | null {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n const right = Math.min(rectRight(a), rectRight(b));\n const bottom = Math.min(rectBottom(a), rectBottom(b));\n if (right < x || bottom < y) return null;\n return { height: bottom - y, width: right - x, x, y };\n}\n\nexport function containsRect(outer: Rect, inner: Rect): boolean {\n return (\n outer.x <= inner.x &&\n outer.y <= inner.y &&\n rectRight(outer) >= rectRight(inner) &&\n rectBottom(outer) >= rectBottom(inner)\n );\n}\n\nexport function containsPoint(rect: Rect, point: Point): boolean {\n return point.x >= rect.x && point.x <= rectRight(rect) && point.y >= rect.y && point.y <= rectBottom(rect);\n}\n\n/** Grows (positive) or shrinks (negative) every edge; a shrink past the center yields a negative-size rect. */\nexport function inflateRect(rect: Rect, amount: number): Rect {\n return { height: rect.height + amount * 2, width: rect.width + amount * 2, x: rect.x - amount, y: rect.y - amount };\n}\n\n/** Whether two rects overlap or merely touch (closed intervals). */\nexport function rectsIntersect(a: Rect, b: Rect): boolean {\n return intersectRect(a, b) !== null;\n}\n","import { AtlasConfigError } from './errors.js';\nimport { apply, multiply, rotate, scale, translate } from './matrix.js';\nimport { rectFromPoints } from './rect.js';\nimport type { Matrix, Point, Rect, Size } from './shapes.js';\n\nexport type CameraState = Readonly<{\n /** World point at the viewport centre. */\n x: number;\n y: number;\n /** Screen pixels per world unit. */\n zoom: number;\n /** Radians in (-π, π]; positive is clockwise on screen. */\n rotation: number;\n}>;\n\nexport type CameraOptions = Readonly<{\n initial?: Partial<CameraState>;\n minZoom?: number;\n maxZoom?: number;\n /** Viewport size in CSS px. Default 0×0, where the centre is the origin. */\n viewport?: Size;\n scheduler?: FrameScheduler;\n}>;\n\nexport type FrameScheduler = Readonly<{\n requestFrame: (callback: (time: number) => void) => number;\n cancelFrame: (handle: number) => void;\n now: () => number;\n}>;\n\nexport type AnimationOptions = Readonly<{\n duration?: number;\n easing?: (t: number) => number;\n signal?: AbortSignal;\n}>;\n\nexport type Camera = Readonly<{\n readonly state: CameraState;\n /** Viewport size in CSS px; the world point at its centre is `state.x/y`. */\n readonly viewport: Size;\n /** world → screen. */\n readonly matrix: Matrix;\n /** screen → world. Zoom is clamped above zero, so this always exists. */\n readonly inverse: Matrix;\n toScreen(point: Point): Point;\n toWorld(point: Point): Point;\n /** Jump to `target` immediately, cancelling any animation. */\n set(target: Partial<CameraState>): void;\n /** Change the viewport size, keeping the world point at its centre fixed. */\n resize(size: Size): void;\n panBy(dx: number, dy: number): void;\n /** Zoom keeping the world point under `screenPoint` fixed. `factor` multiplies current zoom. */\n zoomAt(screenPoint: Point, factor: number): void;\n /** Rotate keeping the world point under `screenPoint` fixed. `delta` radians. */\n rotateAt(screenPoint: Point, delta: number): void;\n /** Fit `bounds` into the current viewport with inner `padding`. */\n fitBounds(bounds: Rect, options?: Readonly<{ padding?: number }>): void;\n /** Axis-aligned world bounds of the visible viewport, honouring rotation. */\n readonly visibleRect: Rect;\n /** Animate to `target`; concurrent calls replace the running animation. */\n animateTo(target: Partial<CameraState>, options?: AnimationOptions): void;\n stop(): void;\n subscribe(listener: (state: CameraState) => void, options?: Readonly<{ signal?: AbortSignal }>): () => void;\n dispose(): void;\n readonly disposed: boolean;\n readonly disposalSignal: AbortSignal;\n [Symbol.dispose]: () => void;\n}>;\n\nconst DEFAULT_SCHEDULER: FrameScheduler = {\n cancelFrame: (handle) => cancelAnimationFrame(handle),\n now: () => performance.now(),\n requestFrame: (callback) => requestAnimationFrame(callback),\n};\n\nfunction assertFinite(name: string, value: number): void {\n if (!Number.isFinite(value)) throw new AtlasConfigError(`${name} must be a finite number, received ${value}`);\n}\n\nfunction easeInOut(t: number): number {\n return t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;\n}\n\n/** Normalize an angle to (-π, π]. */\nfunction normalizeAngle(angle: number): number {\n const wrapped = (angle + Math.PI) % (2 * Math.PI);\n return ((wrapped + 2 * Math.PI) % (2 * Math.PI)) - Math.PI;\n}\n\n/** Shortest signed path from `from` to `to`, in (-π, π]. */\nfunction shortestAngle(from: number, to: number): number {\n return normalizeAngle(to - from);\n}\n\n/** World-space offset that a screen-space offset corresponds to at `zoom`/`rotation`. */\nfunction screenDeltaToWorld(delta: Point, zoom: number, rotation: number): Point {\n return apply(multiply(rotate(-rotation), scale(1 / zoom)), delta);\n}\n\n/**\n * world → screen: translate(viewport centre) · scale(zoom) · rotate(rotation) · translate(-state).\n * With the state point at the viewport centre, saved states no longer depend\n * on the screen size.\n */\nfunction matrixOf(s: CameraState, viewport: Size): Matrix {\n const rotated = multiply(scale(s.zoom), rotate(s.rotation));\n const m = multiply(rotated, translate(-s.x, -s.y));\n return multiply(translate(viewport.width / 2, viewport.height / 2), m);\n}\n\n/**\n * screen → world in closed form: translate(state) · rotate(-r) · scale(1/z) · translate(-centre).\n * Zoom is clamped above zero, so the camera matrix is always invertible.\n */\nfunction inverseOf(s: CameraState, viewport: Size): Matrix {\n const m = multiply(rotate(-s.rotation), scale(1 / s.zoom));\n const t = screenDeltaToWorld({ x: viewport.width / 2, y: viewport.height / 2 }, s.zoom, s.rotation);\n return multiply(translate(s.x - t.x, s.y - t.y), m);\n}\n\nexport function createCamera(options: CameraOptions = {}): Camera {\n const minZoom = options.minZoom ?? 0.01;\n const maxZoom = options.maxZoom ?? 1000;\n if (!(minZoom > 0 && minZoom <= maxZoom)) {\n throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${minZoom} and ${maxZoom}`);\n }\n const scheduler = options.scheduler ?? DEFAULT_SCHEDULER;\n const initial = options.initial ?? {};\n let viewport: Size = options.viewport ?? { height: 0, width: 0 };\n let state: CameraState = {\n rotation: normalizeAngle(initial.rotation ?? 0),\n x: initial.x ?? 0,\n y: initial.y ?? 0,\n zoom: Math.min(maxZoom, Math.max(minZoom, initial.zoom ?? 1)),\n };\n for (const [name, value] of [\n ['camera.x', state.x],\n ['camera.y', state.y],\n ['camera.rotation', state.rotation],\n ] as const) {\n assertFinite(name, value);\n }\n\n const controller = new AbortController();\n let disposed = false;\n let animation: { cleanup: () => void; frame: number } | null = null;\n const listeners = new Set<(state: CameraState) => void>();\n\n // Derived transforms are recomputed at most once per state or viewport change.\n let cachedMatrix: Matrix | null = null;\n let cachedInverse: Matrix | null = null;\n\n const matrix = (): Matrix => {\n cachedMatrix ??= matrixOf(state, viewport);\n return cachedMatrix;\n };\n const inverse = (): Matrix => {\n cachedInverse ??= inverseOf(state, viewport);\n return cachedInverse;\n };\n\n const invalidate = (): void => {\n cachedMatrix = null;\n cachedInverse = null;\n };\n\n /** Screen point measured from the viewport centre, where the state point sits. */\n const relativeToCentre = (screenPoint: Point): Point => ({\n x: screenPoint.x - viewport.width / 2,\n y: screenPoint.y - viewport.height / 2,\n });\n\n const emit = (): void => {\n for (const listener of [...listeners]) listener(state);\n };\n\n const set = (next: Partial<CameraState>): void => {\n if (disposed) return;\n const candidate: CameraState = {\n rotation: normalizeAngle(next.rotation ?? state.rotation),\n x: next.x ?? state.x,\n y: next.y ?? state.y,\n zoom: Math.min(maxZoom, Math.max(minZoom, next.zoom ?? state.zoom)),\n };\n if (\n candidate.x === state.x &&\n candidate.y === state.y &&\n candidate.zoom === state.zoom &&\n candidate.rotation === state.rotation\n ) {\n return;\n }\n state = candidate;\n invalidate();\n emit();\n };\n\n /** Cancel any running animation; direct manipulation always wins. */\n const stop = (): void => {\n if (!animation) return;\n scheduler.cancelFrame(animation.frame);\n animation.cleanup();\n animation = null;\n };\n\n const dispose = (): void => {\n if (disposed) return;\n disposed = true;\n stop();\n listeners.clear();\n controller.abort();\n };\n\n const animateTo: Camera['animateTo'] = (target, animateOptions = {}) => {\n stop();\n if (disposed) return;\n const duration = animateOptions.duration ?? 250;\n const easing = animateOptions.easing ?? easeInOut;\n const signal = animateOptions.signal;\n if (signal?.aborted) return;\n if (duration <= 0) {\n set(target);\n return;\n }\n const from = state;\n const to: CameraState = {\n rotation: from.rotation + shortestAngle(from.rotation, target.rotation ?? state.rotation),\n x: target.x ?? state.x,\n y: target.y ?? state.y,\n zoom: Math.min(maxZoom, Math.max(minZoom, target.zoom ?? state.zoom)),\n };\n const start = scheduler.now();\n // Log-space zoom interpolation keeps multiplicative zoom visually linear.\n const logFrom = Math.log(from.zoom);\n const logTo = Math.log(to.zoom);\n const frame = { cleanup: () => {}, frame: 0 };\n animation = frame;\n const abort = (): void => {\n if (animation !== frame) return;\n stop();\n };\n if (signal) {\n signal.addEventListener('abort', abort, { once: true });\n frame.cleanup = () => signal.removeEventListener('abort', abort);\n }\n const step = (time: number): void => {\n if (animation !== frame) return;\n const t = Math.min(1, (time - start) / duration);\n const e = easing(t);\n set({\n rotation: from.rotation + (to.rotation - from.rotation) * e,\n x: from.x + (to.x - from.x) * e,\n y: from.y + (to.y - from.y) * e,\n zoom: Math.exp(logFrom + (logTo - logFrom) * e),\n });\n if (t >= 1) {\n animation = null;\n frame.cleanup();\n return;\n }\n frame.frame = scheduler.requestFrame(step);\n };\n frame.frame = scheduler.requestFrame(step);\n };\n\n return {\n animateTo,\n get disposalSignal() {\n return controller.signal;\n },\n dispose,\n get disposed() {\n return disposed;\n },\n fitBounds(bounds, fitOptions = {}) {\n if (disposed) return;\n stop();\n const padding = fitOptions.padding ?? 0;\n const availableWidth = Math.max(1, viewport.width - padding * 2);\n const availableHeight = Math.max(1, viewport.height - padding * 2);\n const zoom = Math.min(\n maxZoom,\n Math.max(\n minZoom,\n Math.min(\n bounds.width === 0 ? maxZoom : availableWidth / bounds.width,\n bounds.height === 0 ? maxZoom : availableHeight / bounds.height,\n ),\n ),\n );\n // The state point is the world point at the viewport centre, so fitting\n // the bounds centre on screen means moving the state to it directly.\n set({ x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2, zoom });\n },\n get inverse() {\n return inverse();\n },\n get matrix() {\n return matrix();\n },\n panBy(dx, dy) {\n if (disposed) return;\n stop();\n // Screen-space pan: move the world centre opposite to the drag.\n const offset = screenDeltaToWorld({ x: dx, y: dy }, state.zoom, state.rotation);\n set({ x: state.x - offset.x, y: state.y - offset.y });\n },\n resize(size) {\n if (disposed) return;\n if (size.width === viewport.width && size.height === viewport.height) return;\n viewport = { height: size.height, width: size.width };\n // The state point is the world centre, so it stays fixed by definition;\n // only the derived transforms change.\n invalidate();\n emit();\n },\n rotateAt(screenPoint, delta) {\n if (disposed) return;\n stop();\n const world = apply(inverse(), screenPoint);\n // Anchor math must use the new rotation, so compute before set() normalizes it.\n const rotation = state.rotation + delta;\n const offset = screenDeltaToWorld(relativeToCentre(screenPoint), state.zoom, rotation);\n set({ rotation, x: world.x - offset.x, y: world.y - offset.y });\n },\n set(target) {\n stop();\n set(target);\n },\n [Symbol.dispose]: dispose,\n get state() {\n return state;\n },\n stop,\n subscribe(listener, subscribeOptions) {\n if (disposed || subscribeOptions?.signal?.aborted) return () => {};\n listeners.add(listener);\n subscribeOptions?.signal?.addEventListener('abort', () => listeners.delete(listener), { once: true });\n return () => listeners.delete(listener);\n },\n toScreen(point) {\n return apply(matrix(), point);\n },\n toWorld(point) {\n return apply(inverse(), point);\n },\n get viewport() {\n return viewport;\n },\n get visibleRect() {\n const to = inverse();\n const corners = [\n apply(to, { x: 0, y: 0 }),\n apply(to, { x: viewport.width, y: 0 }),\n apply(to, { x: 0, y: viewport.height }),\n apply(to, { x: viewport.width, y: viewport.height }),\n ] as const;\n // A finite viewport always produces a rect.\n return rectFromPoints(corners);\n },\n zoomAt(screenPoint, factor) {\n if (!Number.isFinite(factor) || factor <= 0) {\n throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${factor}`);\n }\n if (disposed) return;\n stop();\n const world = apply(inverse(), screenPoint);\n const zoom = Math.min(maxZoom, Math.max(minZoom, state.zoom * factor));\n // Anchor math must use the new zoom, so compute before set().\n const offset = screenDeltaToWorld(relativeToCentre(screenPoint), zoom, state.rotation);\n set({ x: world.x - offset.x, y: world.y - offset.y, zoom });\n },\n };\n}\n","import { AtlasConfigError } from './errors.js';\nimport type { Point } from './shapes.js';\n\n/**\n * Ray-casting point-in-polygon test. `polygon` is an open ring; an implicit closing\n * edge connects the last point to the first. Boundary behavior follows the standard\n * ray-cast convention (edge hits depend on the ray's crossing parity).\n */\nexport function pointInPolygon(polygon: readonly Point[], point: Point): boolean {\n let inside = false;\n const n = polygon.length;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n const a = polygon[i];\n const b = polygon[j];\n const crosses = a.y > point.y !== b.y > point.y;\n if (!crosses) continue;\n const xAtY = ((b.x - a.x) * (point.y - a.y)) / (b.y - a.y) + a.x;\n if (point.x < xAtY) inside = !inside;\n }\n return inside;\n}\n\nfunction distanceToSegment(point: Point, a: Point, b: Point): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lengthSq = dx * dx + dy * dy;\n if (lengthSq === 0) return Math.hypot(point.x - a.x, point.y - a.y);\n let t = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSq;\n t = Math.max(0, Math.min(1, t));\n return Math.hypot(point.x - (a.x + t * dx), point.y - (a.y + t * dy));\n}\n\n/**\n * Shortest distance from a point to a polyline (an open path; no implicit closing\n * edge). Returns Infinity for an empty path and the point-to-point distance for\n * a single-point path.\n */\nexport function distanceToPolyline(path: readonly Point[], point: Point): number {\n if (path.length === 0) return Infinity;\n if (path.length === 1) return Math.hypot(point.x - path[0].x, point.y - path[0].y);\n let best = Infinity;\n for (let i = 0, j = 1; j < path.length; i = j++) {\n const d = distanceToSegment(point, path[i], path[j]);\n if (d < best) best = d;\n }\n return best;\n}\n\n/**\n * Whether a point lies within `tolerance` of a polygon's outline or inside it —\n * the hit test for stroked shapes (outlines, wires rendered as strokes).\n */\nexport function pointNearPolygon(polygon: readonly Point[], point: Point, tolerance: number): boolean {\n if (!(tolerance >= 0)) {\n throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(tolerance)}.`);\n }\n const closed = polygon.length > 0 ? [...polygon, polygon[0]] : polygon;\n if (distanceToPolyline(closed, point) <= tolerance) return true;\n return pointInPolygon(polygon, point);\n}\n","import { AtlasConfigError } from './errors.js';\nimport { rectBottom, rectCenter, rectFromPoints, rectRight } from './rect.js';\nimport type { Point, Rect } from './shapes.js';\n\n/** What a guide was snapped to: a grid line, another shape's anchor, or an equal-spacing gap. */\nexport type SnapGuideKind = 'grid' | 'object' | 'spacing';\n\n/**\n * A guide line to render. `axis` names the axis the line is perpendicular to:\n * an `'x'` guide is a vertical line at `position = x`, spanning `from..to` on\n * y. Spacing guides carry `marks`: the centers of the two equal gaps, measured\n * along the span axis, drawn as markers.\n */\nexport interface SnapGuide {\n axis: 'x' | 'y';\n /** Span endpoints along the line's own direction (world coordinates). */\n from: number;\n /** Render hint: draw grid and spacing guides dashed, object guides solid. */\n kind: SnapGuideKind;\n /** Spacing guides only: centers of the two equal gaps, on the span axis. */\n marks?: readonly [number, number];\n /** The coordinate the line sits on, on `axis`. */\n position: number;\n to: number;\n}\n\nexport interface SnapOptions {\n /** Other shapes to snap against. The moving rect itself must not be included. */\n candidates: readonly Rect[];\n /** Optional grid spacing per axis; lines run through multiples of the spacing. */\n grid?: { x?: number; y?: number };\n /**\n * Also snap for equal gaps between neighbors (img.ly-style spacing guides)\n * on each axis where no alignment snap engaged. Default false.\n */\n spacing?: boolean;\n /** Maximum world-unit distance for a snap to engage. */\n threshold: number;\n}\n\nexport interface SnapResult {\n /** Offset to apply to the moving rect; zero on an axis with no snap. */\n delta: Point;\n /** Guides for the snaps that engaged, at most one per axis. */\n guides: SnapGuide[];\n}\n\n/** The three x coordinates (left, center, right) a rect can snap with. */\nfunction xAnchors(rect: Rect): number[] {\n return [rect.x, rect.x + rect.width / 2, rectRight(rect)];\n}\n\nfunction yAnchors(rect: Rect): number[] {\n return [rect.y, rect.y + rect.height / 2, rectBottom(rect)];\n}\n\n/** A snap target with the kind of guide it produced. */\ninterface Target {\n kind: SnapGuideKind;\n value: number;\n}\n\ninterface AxisSnap {\n delta: number;\n kind: SnapGuideKind;\n /** Target coordinate that produced the snap. */\n position: number;\n}\n\nfunction bestAxisSnap(anchors: readonly number[], targets: readonly Target[], threshold: number): AxisSnap | null {\n let best: AxisSnap | null = null;\n for (const anchor of anchors) {\n for (const target of targets) {\n const delta = target.value - anchor;\n if (Math.abs(delta) > threshold) continue;\n if (best === null || Math.abs(delta) < Math.abs(best.delta)) {\n best = { delta, kind: target.kind, position: target.value };\n }\n }\n }\n return best;\n}\n\nfunction gridTargets(min: number, max: number, spacing: number | undefined, threshold: number): Target[] {\n if (spacing === undefined || !Number.isFinite(spacing) || spacing <= 0) return [];\n const targets: Target[] = [];\n for (let line = Math.floor((min - threshold) / spacing) * spacing; line <= max + threshold; line += spacing) {\n targets.push({ kind: 'grid', value: line });\n }\n return targets;\n}\n\nfunction spanFor(\n position: number,\n moved: Rect,\n candidates: readonly Rect[],\n axis: 'x' | 'y',\n): { from: number; to: number } {\n const touching: Rect[] = [];\n for (const candidate of candidates) {\n const anchors = axis === 'x' ? xAnchors(candidate) : yAnchors(candidate);\n if (anchors.some((anchor) => anchor === position)) touching.push(candidate);\n }\n const points: Point[] = [moved, ...touching].flatMap((rect) => [\n { x: rect.x, y: rect.y },\n { x: rectRight(rect), y: rectBottom(rect) },\n ]);\n const bounds = rectFromPoints(points) ?? { height: 0, width: 0, x: position, y: position };\n return axis === 'x' ? { from: bounds.y, to: rectBottom(bounds) } : { from: bounds.x, to: rectRight(bounds) };\n}\n\n/** Overlap test on the axis perpendicular to `axis`. */\nfunction overlapsPerpendicular(a: Rect, b: Rect, axis: 'x' | 'y'): boolean {\n return axis === 'x' ? a.y < rectBottom(b) && b.y < rectBottom(a) : a.x < rectRight(b) && b.x < rectRight(a);\n}\n\n/**\n * Equal-gap snap along `axis`: centers the rect between the nearest\n * perpendicular-overlapping neighbors when the gaps can be made equal within\n * `threshold`. `position` is the moving rect's center on the perpendicular\n * axis; `span` and `marks` are along `axis`.\n */\nfunction axisSpacingSnap(\n rect: Rect,\n candidates: readonly Rect[],\n axis: 'x' | 'y',\n threshold: number,\n): { delta: number; marks: readonly [number, number]; position: number; span: readonly [number, number] } | null {\n const start = axis === 'x' ? (r: Rect) => r.x : (r: Rect) => r.y;\n const end = axis === 'x' ? (r: Rect) => rectRight(r) : (r: Rect) => rectBottom(r);\n let leftEnd = -Infinity;\n let rightStart = Infinity;\n for (const candidate of candidates) {\n if (!overlapsPerpendicular(rect, candidate, axis)) continue;\n if (end(candidate) <= start(rect) && end(candidate) > leftEnd) leftEnd = end(candidate);\n if (start(candidate) >= end(rect) && start(candidate) < rightStart) rightStart = start(candidate);\n }\n if (leftEnd === -Infinity || rightStart === Infinity) return null;\n const free = rightStart - leftEnd - (axis === 'x' ? rect.width : rect.height);\n if (free < 0) return null;\n const ideal = leftEnd + free / 2;\n const delta = ideal - start(rect);\n if (Math.abs(delta) > threshold) return null;\n const gap = free / 2;\n return {\n delta,\n marks: [leftEnd + gap / 2, rightStart - gap / 2],\n // `rect` is the already-moved rect, so the guide sits at the position the\n // shape actually occupies after both axes snapped.\n position: axis === 'x' ? rectCenter(rect).y : rectCenter(rect).x,\n span: [leftEnd, rightStart],\n };\n}\n\n/**\n * Snap a moving rect against candidate shapes, an optional grid, and (with\n * `spacing`) equal gaps between neighbors. Each axis snaps independently to\n * the nearest alignment target within `threshold`; when an axis finds no\n * alignment snap and `spacing` is enabled, it falls back to centering the rect\n * between its nearest neighbors on that axis.\n */\nexport function snapRect(rect: Rect, options: SnapOptions): SnapResult {\n const { candidates, grid, spacing, threshold } = options;\n if (!(threshold >= 0)) {\n throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(threshold)}.`);\n }\n let movedX = rect.x;\n let movedY = rect.y;\n const delta = { x: 0, y: 0 };\n\n const xTargets: Target[] = candidates.flatMap((candidate) =>\n xAnchors(candidate).map((value): Target => ({ kind: 'object', value })),\n );\n xTargets.push(...gridTargets(rect.x, rectRight(rect), grid?.x, threshold));\n const xSnap = bestAxisSnap(xAnchors(rect), xTargets, threshold);\n if (xSnap !== null) {\n delta.x = xSnap.delta;\n movedX += xSnap.delta;\n }\n\n const yTargets: Target[] = candidates.flatMap((candidate) =>\n yAnchors(candidate).map((value): Target => ({ kind: 'object', value })),\n );\n yTargets.push(...gridTargets(rect.y, rectBottom(rect), grid?.y, threshold));\n const ySnap = bestAxisSnap(yAnchors(rect), yTargets, threshold);\n if (ySnap !== null) {\n delta.y = ySnap.delta;\n movedY += ySnap.delta;\n }\n\n // Guides span the union of the moved rect and every candidate sharing the snapped coordinate.\n const movedRect: Rect = { ...rect, x: movedX, y: movedY };\n const guides: SnapGuide[] = [];\n if (xSnap !== null) {\n const span = spanFor(xSnap.position, movedRect, candidates, 'x');\n guides.push({ axis: 'x', from: span.from, kind: xSnap.kind, position: xSnap.position, to: span.to });\n }\n if (ySnap !== null) {\n const span = spanFor(ySnap.position, movedRect, candidates, 'y');\n guides.push({ axis: 'y', from: span.from, kind: ySnap.kind, position: ySnap.position, to: span.to });\n }\n\n // Equal-spacing fallback fills the axes where no alignment snap engaged.\n // It runs on the moved rect so its perpendicular position honours the other\n // axis's snap.\n if (spacing) {\n if (xSnap === null) {\n const gap = axisSpacingSnap(movedRect, candidates, 'x', threshold);\n if (gap !== null) {\n delta.x = gap.delta;\n guides.push({\n axis: 'y',\n from: gap.span[0],\n kind: 'spacing',\n marks: gap.marks,\n position: gap.position,\n to: gap.span[1],\n });\n }\n }\n if (ySnap === null) {\n const gap = axisSpacingSnap(movedRect, candidates, 'y', threshold);\n if (gap !== null) {\n delta.y = gap.delta;\n guides.push({\n axis: 'x',\n from: gap.span[0],\n kind: 'spacing',\n marks: gap.marks,\n position: gap.position,\n to: gap.span[1],\n });\n }\n }\n }\n return { delta, guides };\n}\n\n/** Which edge/center line to align rects on. */\nexport type AlignEdge = 'left' | 'horizontal-center' | 'right' | 'top' | 'vertical-center' | 'bottom';\n\n/**\n * Align rects on a shared line derived from their combined bounds, preserving\n * sizes. Returns new rects in input order; the input is untouched.\n */\nexport function alignRects(rects: readonly Rect[], edge: AlignEdge): Rect[] {\n if (rects.length === 0) return [];\n const bounds = rectFromPoints(\n rects.flatMap((rect) => [\n { x: rect.x, y: rect.y },\n { x: rectRight(rect), y: rectBottom(rect) },\n ]),\n );\n if (bounds === null) return [];\n return rects.map((rect) => {\n switch (edge) {\n case 'left':\n return { ...rect, x: bounds.x };\n case 'horizontal-center':\n return { ...rect, x: rectCenter(bounds).x - rect.width / 2 };\n case 'right':\n return { ...rect, x: rectRight(bounds) - rect.width };\n case 'top':\n return { ...rect, y: bounds.y };\n case 'vertical-center':\n return { ...rect, y: rectCenter(bounds).y - rect.height / 2 };\n case 'bottom':\n return { ...rect, y: rectBottom(bounds) - rect.height };\n default:\n throw new AtlasConfigError(`unknown align edge: ${String(edge)}.`);\n }\n });\n}\n\n/**\n * Equalize the gaps between rects along an axis. The outermost rects stay\n * fixed; middle rects move in sorted order along the axis. Fewer than three\n * rects are returned as copies unchanged.\n */\nexport function distributeRects(rects: readonly Rect[], axis: 'x' | 'y'): Rect[] {\n if (rects.length <= 2) return rects.map((rect) => ({ ...rect }));\n const start = axis === 'x' ? (rect: Rect) => rect.x : (rect: Rect) => rect.y;\n const size = axis === 'x' ? (rect: Rect) => rect.width : (rect: Rect) => rect.height;\n const order = rects\n .map((rect, index) => ({ index, rect }))\n .sort((a, b) => start(a.rect) - start(b.rect) || a.index - b.index);\n const first = order[0].rect;\n const last = order[order.length - 1].rect;\n const totalSpan = start(last) + size(last) - start(first);\n const totalSize = order.reduce((sum, entry) => sum + size(entry.rect), 0);\n const gap = (totalSpan - totalSize) / (order.length - 1);\n const result = rects.map((rect) => ({ ...rect }));\n let cursor = start(first);\n for (const entry of order) {\n const moved = { ...entry.rect };\n if (axis === 'x') moved.x = cursor;\n else moved.y = cursor;\n result[entry.index] = moved;\n cursor += size(entry.rect) + gap;\n }\n return result;\n}\n","import { AtlasConfigError } from './errors.js';\nimport { containsRect, inflateRect, rectsIntersect } from './rect.js';\nimport type { Point, Rect } from './shapes.js';\n\nexport type SpatialIndexOptions = Readonly<{\n /** Maximum children per node before a split. Default 8. */\n maxEntriesPerNode?: number;\n}>;\n\nexport type SpatialQueryOptions = Readonly<{\n /** Expand the query point into a box of this half-size. Default 0. */\n tolerance?: number;\n}>;\n\n/**\n * A Map-like index over ids and their bounding rects. The index stores only\n * geometry — the caller owns the data and looks it up from returned ids —\n * so stored values can never go stale.\n */\nexport type SpatialIndex<K = string> = Readonly<{\n /** Insert `id`, or move it to `rect` when it already exists. */\n set(id: K, rect: Rect): void;\n delete(id: K): boolean;\n /** Current rect for `id`, or undefined. */\n get(id: K): Rect | undefined;\n has(id: K): boolean;\n clear(): void;\n readonly size: number;\n /** Bounding box of all entries; null when empty. */\n readonly bounds: Rect | null;\n /** Ids whose rect overlaps or touches `rect`. */\n queryRect(rect: Rect): K[];\n /** Ids whose rect contains `point`, or comes within `tolerance` of it. */\n queryPoint(point: Point, options?: SpatialQueryOptions): K[];\n}>;\n\ninterface LeafEntry<K> {\n id: K;\n rect: Rect;\n}\n\ntype Leaf<K> = { children: LeafEntry<K>[]; leaf: true; rect: Rect | null };\ntype Branch<K> = { children: Node<K>[]; leaf: false; rect: Rect | null };\ntype Node<K> = Leaf<K> | Branch<K>;\n\nfunction rectOf<K>(node: Node<K> | LeafEntry<K>): Rect {\n return node.rect as Rect;\n}\n\nfunction unionRects(a: Rect, b: Rect): Rect {\n const x = Math.min(a.x, b.x);\n const y = Math.min(a.y, b.y);\n return {\n height: Math.max(a.y + a.height, b.y + b.height) - y,\n width: Math.max(a.x + a.width, b.x + b.width) - x,\n x,\n y,\n };\n}\n\nfunction area(rect: Rect): number {\n return rect.width * rect.height;\n}\n\nfunction rectsEqual(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\nfunction recompute<K>(node: Node<K>): void {\n let rect: Rect | null = null;\n for (const child of node.children) {\n rect = rect === null ? { ...rectOf(child) } : unionRects(rect, rectOf(child));\n }\n node.rect = rect;\n}\n\n/**\n * Dynamic R-tree (Guttman, quadratic split) over axis-aligned rectangles:\n * O(log n) rect and point queries for hit-testing, marquee selection, and\n * viewport culling over thousands of items. Rect intersection uses closed\n * intervals, so zero-area entries (lines, points) are findable.\n */\nexport function createSpatialIndex<K = string>(options: SpatialIndexOptions = {}): SpatialIndex<K> {\n const maxEntries = options.maxEntriesPerNode ?? 8;\n if (!Number.isInteger(maxEntries) || maxEntries < 4) {\n throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${maxEntries}`);\n }\n const minEntries = Math.max(2, Math.ceil(maxEntries / 3));\n const entries = new Map<K, LeafEntry<K>>();\n let root: Node<K> = { children: [], leaf: true, rect: null };\n\n const pickChild = (node: Branch<K>, rect: Rect): Node<K> => {\n let best: Node<K> | null = null;\n let bestEnlargement = Infinity;\n let bestArea = Infinity;\n for (const child of node.children) {\n const current = child.rect ?? rect;\n const enlargement = area(unionRects(current, rect)) - area(current);\n if (enlargement < bestEnlargement || (enlargement === bestEnlargement && area(current) < bestArea)) {\n best = child;\n bestEnlargement = enlargement;\n bestArea = area(current);\n }\n }\n return best as Node<K>;\n };\n\n const split = (node: Node<K>): [Node<K>, Node<K>] => {\n const items = node.children;\n // Quadratic pick-seeds: the pair wasting the most area when combined.\n let si = 0;\n let sj = 1;\n let worst = -Infinity;\n for (let i = 0; i < items.length; i++) {\n for (let j = i + 1; j < items.length; j++) {\n const waste =\n area(unionRects(rectOf(items[i]), rectOf(items[j]))) - area(rectOf(items[i])) - area(rectOf(items[j]));\n if (waste > worst) {\n worst = waste;\n si = i;\n sj = j;\n }\n }\n }\n const groupA: Array<Node<K> | LeafEntry<K>> = [items[si]];\n const groupB: Array<Node<K> | LeafEntry<K>> = [items[sj]];\n let rectA = rectOf(items[si]);\n let rectB = rectOf(items[sj]);\n const remaining = items.filter((_, index) => index !== si && index !== sj);\n for (const [index, item] of remaining.entries()) {\n // Force distribution so neither group can exceed maxEntries or fall below minEntries.\n const mustA =\n groupA.length + (remaining.length - index) > maxEntries ||\n groupB.length + (remaining.length - index) - 1 < minEntries;\n const mustB =\n groupB.length + (remaining.length - index) > maxEntries ||\n groupA.length + (remaining.length - index) - 1 < minEntries;\n let toA: boolean;\n if (mustA) toA = true;\n else if (mustB) toA = false;\n else {\n const enlargeA = area(unionRects(rectA, rectOf(item))) - area(rectA);\n const enlargeB = area(unionRects(rectB, rectOf(item))) - area(rectB);\n toA = enlargeA < enlargeB || (enlargeA === enlargeB && area(rectA) <= area(rectB));\n }\n if (toA) {\n groupA.push(item);\n rectA = unionRects(rectA, rectOf(item));\n } else {\n groupB.push(item);\n rectB = unionRects(rectB, rectOf(item));\n }\n }\n const a = (\n node.leaf\n ? { children: groupA as LeafEntry<K>[], leaf: true, rect: null }\n : { children: groupA as Node<K>[], leaf: false, rect: null }\n ) as Node<K>;\n const b = (\n node.leaf\n ? { children: groupB as LeafEntry<K>[], leaf: true, rect: null }\n : { children: groupB as Node<K>[], leaf: false, rect: null }\n ) as Node<K>;\n recompute(a);\n recompute(b);\n return [a, b];\n };\n\n /** Insert `item` under `node`; returns the split pair when `node` overflows. */\n const insertInto = (node: Node<K>, item: Node<K> | LeafEntry<K>): [Node<K>, Node<K>] | null => {\n if (node.leaf) {\n node.children.push(item as LeafEntry<K>);\n node.rect = node.rect === null ? { ...rectOf(item) } : unionRects(node.rect, rectOf(item));\n if (node.children.length > maxEntries) return split(node);\n return null;\n }\n const branch = node as Branch<K>;\n const child = pickChild(branch, rectOf(item));\n const overflow = insertInto(child, item);\n recompute(node);\n if (overflow) {\n const index = branch.children.indexOf(child);\n branch.children.splice(index, 1, overflow[0], overflow[1]);\n recompute(node);\n }\n if (node.children.length > maxEntries) return split(node);\n return null;\n };\n\n const insertEntry = (entry: LeafEntry<K>): void => {\n // A fully emptied root stays as an empty branch after removals; revive it as a leaf.\n if (!root.leaf && root.children.length === 0) {\n root = { children: [], leaf: true, rect: null };\n }\n const overflow = insertInto(root, entry);\n if (overflow) {\n root = { children: overflow, leaf: false, rect: null };\n recompute(root);\n }\n };\n\n /** Depth-first remove; returns true when `node` became empty. */\n const removeFrom = (node: Node<K>, entry: LeafEntry<K>): boolean => {\n if (node.leaf) {\n const index = node.children.indexOf(entry);\n if (index !== -1) node.children.splice(index, 1);\n recompute(node);\n return node.children.length === 0;\n }\n const branch = node as Branch<K>;\n for (let i = branch.children.length - 1; i >= 0; i--) {\n const child = branch.children[i];\n // Prune by containment, not intersection: a branch rect is the union of\n // its children, so the entry's rect is always contained in the child\n // that holds it.\n if (child.rect && containsRect(child.rect, entry.rect)) {\n if (removeFrom(child, entry)) branch.children.splice(i, 1);\n }\n }\n recompute(node);\n return branch.children.length === 0;\n };\n\n const deleteEntry = (id: K): boolean => {\n const entry = entries.get(id);\n if (!entry) return false;\n entries.delete(id);\n removeFrom(root, entry);\n // Collapse a root branch that ended up with a single child.\n while (!root.leaf && root.children.length === 1) {\n root = root.children[0];\n }\n return true;\n };\n\n const queryInto = (node: Node<K>, hits: (rect: Rect) => boolean, out: K[]): void => {\n if (!node.rect || !hits(node.rect)) return;\n if (node.leaf) {\n for (const entry of node.children) {\n if (hits(entry.rect)) out.push(entry.id);\n }\n return;\n }\n for (const child of (node as Branch<K>).children) queryInto(child, hits, out);\n };\n\n return {\n get bounds() {\n return root.rect;\n },\n clear() {\n entries.clear();\n root = { children: [], leaf: true, rect: null };\n },\n delete: deleteEntry,\n get(id) {\n return entries.get(id)?.rect;\n },\n has(id) {\n return entries.has(id);\n },\n queryPoint(point, queryOptions) {\n const tolerance = queryOptions?.tolerance ?? 0;\n if (!(tolerance >= 0)) {\n throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${tolerance}`);\n }\n // A point is a zero-size box; closed-interval intersection makes it hit\n // rects that merely touch it, so one shared path covers both query kinds.\n const box: Rect = inflateRect({ ...point, height: 0, width: 0 }, tolerance);\n const out: K[] = [];\n queryInto(root, (rect) => rectsIntersect(rect, box), out);\n return out;\n },\n queryRect(rect) {\n const out: K[] = [];\n queryInto(root, (candidate) => rectsIntersect(candidate, rect), out);\n return out;\n },\n set(id, rect) {\n const existing = entries.get(id);\n if (existing) {\n if (rectsEqual(existing.rect, rect)) return;\n deleteEntry(id);\n }\n const entry: LeafEntry<K> = { id, rect: { ...rect } };\n entries.set(id, entry);\n insertEntry(entry);\n },\n get size() {\n return entries.size;\n },\n };\n}\n"],"mappings":"A,mEAAA,IAAa,WAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAMA,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,iBAAb,cAAsC,UAAW,CAAC,ECNrCC,EAAmB,OAAO,OAAO,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,CAAC,CAAC,EAEhE,SAAgB,SAAS,EAAW,EAAmB,CACrD,MAAO,CACLC,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GACvBD,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GACvBD,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GACvBD,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GACvBD,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAC9BA,EAAE,GAAKC,EAAE,GAAKD,EAAE,GAAKC,EAAE,GAAKD,EAAE,EAChC,CACF,CAEA,SAAgB,MAAM,EAAgB,EAAqB,CACzD,MAAO,CACL,EAAGE,EAAO,GAAKC,EAAM,EAAID,EAAO,GAAKC,EAAM,EAAID,EAAO,GACtD,EAAGA,EAAO,GAAKC,EAAM,EAAID,EAAO,GAAKC,EAAM,EAAID,EAAO,EACxD,CACF,CAEA,SAAgB,UAAU,EAAY,EAAoB,CACxD,MAAO,CAAC,EAAG,EAAG,EAAG,EA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atlas.cjs","names":["assertFinite","message","opts","IDENTITY","a","b","matrix","point","tx","ty","sx","sy","cos","radians","sin","anchor","det","inv","minX","minY","maxX","maxY","found","points","rect","x","y","right","bottom","outer","inner","amount","DEFAULT_SCHEDULER","handle","callback","value","name","t","angle","to","from","rotation","zoom","delta","m","s","viewport","minZoom","options","maxZoom","scheduler","initial","state","controller","disposed","animation","listeners","cachedMatrix","cachedInverse","screenPoint","listener","candidate","next","duration","animateOptions","easing","signal","target","start","logFrom","logTo","frame","time","e","padding","fitOptions","availableWidth","availableHeight","bounds","offset","dx","dy","size","world","subscribeOptions","factor","RESIZE_EDGES","rawScale","origin","i","edges","min","aspect","dragsWest","dragsEast","dragsNorth","dragsSouth","left","top","minSize","width","height","horizontalDragged","verticalDragged","w","h","centerY","centerX","inside","n","polygon","j","xAtY","lengthSq","path","best","d","tolerance","anchors","targets","threshold","spacing","line","max","touching","candidates","axis","position","moved","r","end","leftEnd","rightStart","free","gap","movedX","movedY","xTargets","grid","xSnap","yTargets","ySnap","movedRect","guides","span","rects","edge","order","first","last","sum","entry","result","cursor","node","child","maxEntries","minEntries","entries","root","bestEnlargement","bestArea","current","enlargement","items","si","sj","worst","waste","groupA","groupB","rectA","rectB","remaining","index","item","mustA","mustB","toA","enlargeA","enlargeB","branch","overflow","id","hits","out","queryOptions","box","existing"],"sources":["../src/errors.ts","../src/matrix.ts","../src/rect.ts","../src/camera.ts","../src/frame.ts","../src/geometry.ts","../src/snap.ts","../src/spatial-index.ts"],"sourcesContent":["export class AtlasError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class AtlasConfigError extends AtlasError {}\n","import type { Matrix, Point } from './shapes.js';\n\nexport const IDENTITY: Matrix = Object.freeze([1, 0, 0, 1, 0, 0]) as Matrix;\n\nexport function multiply(a: Matrix, b: Matrix): Matrix {\n return [\n a[0] * b[0] + a[2] * b[1],\n a[1] * b[0] + a[3] * b[1],\n a[0] * b[2] + a[2] * b[3],\n a[1] * b[2] + a[3] * b[3],\n a[0] * b[4] + a[2] * b[5] + a[4],\n a[1] * b[4] + a[3] * b[5] + a[5],\n ];\n}\n\nexport function apply(matrix: Matrix, point: Point): Point {\n return {\n x: matrix[0] * point.x + matrix[2] * point.y + matrix[4],\n y: matrix[1] * point.x + matrix[3] * point.y + matrix[5],\n };\n}\n\nexport function translate(tx: number, ty: number): Matrix {\n return [1, 0, 0, 1, tx, ty];\n}\n\nexport function scale(sx: number, sy: number = sx): Matrix {\n return [sx, 0, 0, sy, 0, 0];\n}\n\n/** Rotation in radians; positive is clockwise on screen (y grows downward). */\nexport function rotate(radians: number): Matrix {\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n return [cos, sin, -sin, cos, 0, 0];\n}\n\n/** Transform applied around an anchor point: translate(anchor) · matrix · translate(-anchor). */\nexport function around(anchor: Point, matrix: Matrix): Matrix {\n return multiply(multiply(translate(anchor.x, anchor.y), matrix), translate(-anchor.x, -anchor.y));\n}\n\n/** Average axis scale of a matrix; 0 for degenerate matrices. */\nexport function scaleOf(matrix: Matrix): number {\n const sx = Math.hypot(matrix[0], matrix[1]);\n const sy = Math.hypot(matrix[2], matrix[3]);\n return (sx + sy) / 2;\n}\n\n/** Serializes to a CSS `matrix()` value usable in a DOM element's `transform`. */\nexport function toCssMatrix(matrix: Matrix): string {\n return `matrix(${matrix.join(',')})`;\n}\n\n/** Returns null for non-invertible matrices (zero determinant). */\nexport function invert(matrix: Matrix): Matrix | null {\n const det = matrix[0] * matrix[3] - matrix[2] * matrix[1];\n if (!Number.isFinite(det) || det === 0) return null;\n const inv = 1 / det;\n return [\n matrix[3] * inv,\n -matrix[1] * inv,\n -matrix[2] * inv,\n matrix[0] * inv,\n (matrix[2] * matrix[5] - matrix[3] * matrix[4]) * inv,\n (matrix[1] * matrix[4] - matrix[0] * matrix[5]) * inv,\n ];\n}\n","import type { Point, Rect } from './shapes.js';\n\nexport function rectFromPoints(points: readonly [Point, ...Point[]]): Rect;\nexport function rectFromPoints(points: Iterable<Point>): Rect | null;\nexport function rectFromPoints(points: Iterable<Point>): Rect | null {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n let found = false;\n for (const point of points) {\n found = true;\n if (point.x < minX) minX = point.x;\n if (point.y < minY) minY = point.y;\n if (point.x > maxX) maxX = point.x;\n if (point.y > maxY) maxY = point.y;\n }\n if (!found) return null;\n return { height: maxY - minY, width: maxX - minX, x: minX, y: minY };\n}\n\nexport function rectRight(rect: Rect): number {\n return rect.x + rect.width;\n}\n\nexport function rectBottom(rect: Rect): number {\n return rect.y + rect.height;\n}\n\nexport function rectCenter(rect: Rect): Point {\n return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };\n}\n\nexport function unionRect(a: Rect, b: Rect): Rect {\n const x = Math.min(a.x, b.x);\n const y = Math.min(a.y, b.y);\n return {\n height: Math.max(rectBottom(a), rectBottom(b)) - y,\n width: Math.max(rectRight(a), rectRight(b)) - x,\n x,\n y,\n };\n}\n\n/**\n * Overlap of two rects using closed intervals: touching rects (or a zero-area\n * rect on another's edge) intersect and may yield a zero-area result.\n * Returns null only when the rects are disjoint.\n */\nexport function intersectRect(a: Rect, b: Rect): Rect | null {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n const right = Math.min(rectRight(a), rectRight(b));\n const bottom = Math.min(rectBottom(a), rectBottom(b));\n if (right < x || bottom < y) return null;\n return { height: bottom - y, width: right - x, x, y };\n}\n\nexport function containsRect(outer: Rect, inner: Rect): boolean {\n return (\n outer.x <= inner.x &&\n outer.y <= inner.y &&\n rectRight(outer) >= rectRight(inner) &&\n rectBottom(outer) >= rectBottom(inner)\n );\n}\n\nexport function containsPoint(rect: Rect, point: Point): boolean {\n return point.x >= rect.x && point.x <= rectRight(rect) && point.y >= rect.y && point.y <= rectBottom(rect);\n}\n\n/** Grows (positive) or shrinks (negative) every edge; a shrink past the center yields a negative-size rect. */\nexport function inflateRect(rect: Rect, amount: number): Rect {\n return { height: rect.height + amount * 2, width: rect.width + amount * 2, x: rect.x - amount, y: rect.y - amount };\n}\n\n/** Whether two rects overlap or merely touch (closed intervals). */\nexport function rectsIntersect(a: Rect, b: Rect): boolean {\n return intersectRect(a, b) !== null;\n}\n","import { AtlasConfigError } from './errors.js';\nimport { apply, multiply, rotate, scale, translate } from './matrix.js';\nimport { rectFromPoints } from './rect.js';\nimport type { Matrix, Point, Rect, Size } from './shapes.js';\n\nexport type CameraState = Readonly<{\n /** World point at the viewport centre. */\n x: number;\n y: number;\n /** Screen pixels per world unit. */\n zoom: number;\n /** Radians in (-π, π]; positive is clockwise on screen. */\n rotation: number;\n}>;\n\nexport type CameraOptions = Readonly<{\n initial?: Partial<CameraState>;\n minZoom?: number;\n maxZoom?: number;\n /** Viewport size in CSS px. Default 0×0, where the centre is the origin. */\n viewport?: Size;\n scheduler?: FrameScheduler;\n}>;\n\nexport type FrameScheduler = Readonly<{\n requestFrame: (callback: (time: number) => void) => number;\n cancelFrame: (handle: number) => void;\n now: () => number;\n}>;\n\nexport type AnimationOptions = Readonly<{\n duration?: number;\n easing?: (t: number) => number;\n signal?: AbortSignal;\n}>;\n\nexport type Camera = Readonly<{\n readonly state: CameraState;\n /** Viewport size in CSS px; the world point at its centre is `state.x/y`. */\n readonly viewport: Size;\n /** world → screen. */\n readonly matrix: Matrix;\n /** screen → world. Zoom is clamped above zero, so this always exists. */\n readonly inverse: Matrix;\n toScreen(point: Point): Point;\n toWorld(point: Point): Point;\n /** Jump to `target` immediately, cancelling any animation. */\n set(target: Partial<CameraState>): void;\n /** Change the viewport size, keeping the world point at its centre fixed. */\n resize(size: Size): void;\n panBy(dx: number, dy: number): void;\n /** Zoom keeping the world point under `screenPoint` fixed. `factor` multiplies current zoom. */\n zoomAt(screenPoint: Point, factor: number): void;\n /** Rotate keeping the world point under `screenPoint` fixed. `delta` radians. */\n rotateAt(screenPoint: Point, delta: number): void;\n /** Fit `bounds` into the current viewport with inner `padding`. */\n fitBounds(bounds: Rect, options?: Readonly<{ padding?: number }>): void;\n /** Axis-aligned world bounds of the visible viewport, honouring rotation. */\n readonly visibleRect: Rect;\n /** Animate to `target`; concurrent calls replace the running animation. */\n animateTo(target: Partial<CameraState>, options?: AnimationOptions): void;\n stop(): void;\n subscribe(listener: (state: CameraState) => void, options?: Readonly<{ signal?: AbortSignal }>): () => void;\n dispose(): void;\n readonly disposed: boolean;\n readonly disposalSignal: AbortSignal;\n [Symbol.dispose]: () => void;\n}>;\n\nconst DEFAULT_SCHEDULER: FrameScheduler = {\n cancelFrame: (handle) => cancelAnimationFrame(handle),\n now: () => performance.now(),\n requestFrame: (callback) => requestAnimationFrame(callback),\n};\n\nfunction assertFinite(name: string, value: number): void {\n if (!Number.isFinite(value)) throw new AtlasConfigError(`${name} must be a finite number, received ${value}`);\n}\n\nfunction easeInOut(t: number): number {\n return t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;\n}\n\n/** Normalize an angle to (-π, π]. */\nfunction normalizeAngle(angle: number): number {\n const wrapped = (angle + Math.PI) % (2 * Math.PI);\n return ((wrapped + 2 * Math.PI) % (2 * Math.PI)) - Math.PI;\n}\n\n/** Shortest signed path from `from` to `to`, in (-π, π]. */\nfunction shortestAngle(from: number, to: number): number {\n return normalizeAngle(to - from);\n}\n\n/** World-space offset that a screen-space offset corresponds to at `zoom`/`rotation`. */\nfunction screenDeltaToWorld(delta: Point, zoom: number, rotation: number): Point {\n return apply(multiply(rotate(-rotation), scale(1 / zoom)), delta);\n}\n\n/**\n * world → screen: translate(viewport centre) · scale(zoom) · rotate(rotation) · translate(-state).\n * With the state point at the viewport centre, saved states no longer depend\n * on the screen size.\n */\nfunction matrixOf(s: CameraState, viewport: Size): Matrix {\n const rotated = multiply(scale(s.zoom), rotate(s.rotation));\n const m = multiply(rotated, translate(-s.x, -s.y));\n return multiply(translate(viewport.width / 2, viewport.height / 2), m);\n}\n\n/**\n * screen → world in closed form: translate(state) · rotate(-r) · scale(1/z) · translate(-centre).\n * Zoom is clamped above zero, so the camera matrix is always invertible.\n */\nfunction inverseOf(s: CameraState, viewport: Size): Matrix {\n const m = multiply(rotate(-s.rotation), scale(1 / s.zoom));\n const t = screenDeltaToWorld({ x: viewport.width / 2, y: viewport.height / 2 }, s.zoom, s.rotation);\n return multiply(translate(s.x - t.x, s.y - t.y), m);\n}\n\nexport function createCamera(options: CameraOptions = {}): Camera {\n const minZoom = options.minZoom ?? 0.01;\n const maxZoom = options.maxZoom ?? 1000;\n if (!(minZoom > 0 && minZoom <= maxZoom)) {\n throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${minZoom} and ${maxZoom}`);\n }\n const scheduler = options.scheduler ?? DEFAULT_SCHEDULER;\n const initial = options.initial ?? {};\n let viewport: Size = options.viewport ?? { height: 0, width: 0 };\n let state: CameraState = {\n rotation: normalizeAngle(initial.rotation ?? 0),\n x: initial.x ?? 0,\n y: initial.y ?? 0,\n zoom: Math.min(maxZoom, Math.max(minZoom, initial.zoom ?? 1)),\n };\n for (const [name, value] of [\n ['camera.x', state.x],\n ['camera.y', state.y],\n ['camera.rotation', state.rotation],\n ] as const) {\n assertFinite(name, value);\n }\n\n const controller = new AbortController();\n let disposed = false;\n let animation: { cleanup: () => void; frame: number } | null = null;\n const listeners = new Set<(state: CameraState) => void>();\n\n // Derived transforms are recomputed at most once per state or viewport change.\n let cachedMatrix: Matrix | null = null;\n let cachedInverse: Matrix | null = null;\n\n const matrix = (): Matrix => {\n cachedMatrix ??= matrixOf(state, viewport);\n return cachedMatrix;\n };\n const inverse = (): Matrix => {\n cachedInverse ??= inverseOf(state, viewport);\n return cachedInverse;\n };\n\n const invalidate = (): void => {\n cachedMatrix = null;\n cachedInverse = null;\n };\n\n /** Screen point measured from the viewport centre, where the state point sits. */\n const relativeToCentre = (screenPoint: Point): Point => ({\n x: screenPoint.x - viewport.width / 2,\n y: screenPoint.y - viewport.height / 2,\n });\n\n const emit = (): void => {\n for (const listener of [...listeners]) listener(state);\n };\n\n const set = (next: Partial<CameraState>): void => {\n if (disposed) return;\n const candidate: CameraState = {\n rotation: normalizeAngle(next.rotation ?? state.rotation),\n x: next.x ?? state.x,\n y: next.y ?? state.y,\n zoom: Math.min(maxZoom, Math.max(minZoom, next.zoom ?? state.zoom)),\n };\n if (\n candidate.x === state.x &&\n candidate.y === state.y &&\n candidate.zoom === state.zoom &&\n candidate.rotation === state.rotation\n ) {\n return;\n }\n state = candidate;\n invalidate();\n emit();\n };\n\n /** Cancel any running animation; direct manipulation always wins. */\n const stop = (): void => {\n if (!animation) return;\n scheduler.cancelFrame(animation.frame);\n animation.cleanup();\n animation = null;\n };\n\n const dispose = (): void => {\n if (disposed) return;\n disposed = true;\n stop();\n listeners.clear();\n controller.abort();\n };\n\n const animateTo: Camera['animateTo'] = (target, animateOptions = {}) => {\n stop();\n if (disposed) return;\n const duration = animateOptions.duration ?? 250;\n const easing = animateOptions.easing ?? easeInOut;\n const signal = animateOptions.signal;\n if (signal?.aborted) return;\n if (duration <= 0) {\n set(target);\n return;\n }\n const from = state;\n const to: CameraState = {\n rotation: from.rotation + shortestAngle(from.rotation, target.rotation ?? state.rotation),\n x: target.x ?? state.x,\n y: target.y ?? state.y,\n zoom: Math.min(maxZoom, Math.max(minZoom, target.zoom ?? state.zoom)),\n };\n const start = scheduler.now();\n // Log-space zoom interpolation keeps multiplicative zoom visually linear.\n const logFrom = Math.log(from.zoom);\n const logTo = Math.log(to.zoom);\n const frame = { cleanup: () => {}, frame: 0 };\n animation = frame;\n const abort = (): void => {\n if (animation !== frame) return;\n stop();\n };\n if (signal) {\n signal.addEventListener('abort', abort, { once: true });\n frame.cleanup = () => signal.removeEventListener('abort', abort);\n }\n const step = (time: number): void => {\n if (animation !== frame) return;\n const t = Math.min(1, (time - start) / duration);\n const e = easing(t);\n set({\n rotation: from.rotation + (to.rotation - from.rotation) * e,\n x: from.x + (to.x - from.x) * e,\n y: from.y + (to.y - from.y) * e,\n zoom: Math.exp(logFrom + (logTo - logFrom) * e),\n });\n if (t >= 1) {\n animation = null;\n frame.cleanup();\n return;\n }\n frame.frame = scheduler.requestFrame(step);\n };\n frame.frame = scheduler.requestFrame(step);\n };\n\n return {\n animateTo,\n get disposalSignal() {\n return controller.signal;\n },\n dispose,\n get disposed() {\n return disposed;\n },\n fitBounds(bounds, fitOptions = {}) {\n if (disposed) return;\n stop();\n const padding = fitOptions.padding ?? 0;\n const availableWidth = Math.max(1, viewport.width - padding * 2);\n const availableHeight = Math.max(1, viewport.height - padding * 2);\n const zoom = Math.min(\n maxZoom,\n Math.max(\n minZoom,\n Math.min(\n bounds.width === 0 ? maxZoom : availableWidth / bounds.width,\n bounds.height === 0 ? maxZoom : availableHeight / bounds.height,\n ),\n ),\n );\n // The state point is the world point at the viewport centre, so fitting\n // the bounds centre on screen means moving the state to it directly.\n set({ x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2, zoom });\n },\n get inverse() {\n return inverse();\n },\n get matrix() {\n return matrix();\n },\n panBy(dx, dy) {\n if (disposed) return;\n stop();\n // Screen-space pan: move the world centre opposite to the drag.\n const offset = screenDeltaToWorld({ x: dx, y: dy }, state.zoom, state.rotation);\n set({ x: state.x - offset.x, y: state.y - offset.y });\n },\n resize(size) {\n if (disposed) return;\n if (size.width === viewport.width && size.height === viewport.height) return;\n viewport = { height: size.height, width: size.width };\n // The state point is the world centre, so it stays fixed by definition;\n // only the derived transforms change.\n invalidate();\n emit();\n },\n rotateAt(screenPoint, delta) {\n if (disposed) return;\n stop();\n const world = apply(inverse(), screenPoint);\n // Anchor math must use the new rotation, so compute before set() normalizes it.\n const rotation = state.rotation + delta;\n const offset = screenDeltaToWorld(relativeToCentre(screenPoint), state.zoom, rotation);\n set({ rotation, x: world.x - offset.x, y: world.y - offset.y });\n },\n set(target) {\n stop();\n set(target);\n },\n [Symbol.dispose]: dispose,\n get state() {\n return state;\n },\n stop,\n subscribe(listener, subscribeOptions) {\n if (disposed || subscribeOptions?.signal?.aborted) return () => {};\n listeners.add(listener);\n subscribeOptions?.signal?.addEventListener('abort', () => listeners.delete(listener), { once: true });\n return () => listeners.delete(listener);\n },\n toScreen(point) {\n return apply(matrix(), point);\n },\n toWorld(point) {\n return apply(inverse(), point);\n },\n get viewport() {\n return viewport;\n },\n get visibleRect() {\n const to = inverse();\n const corners = [\n apply(to, { x: 0, y: 0 }),\n apply(to, { x: viewport.width, y: 0 }),\n apply(to, { x: 0, y: viewport.height }),\n apply(to, { x: viewport.width, y: viewport.height }),\n ] as const;\n // A finite viewport always produces a rect.\n return rectFromPoints(corners);\n },\n zoomAt(screenPoint, factor) {\n if (!Number.isFinite(factor) || factor <= 0) {\n throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${factor}`);\n }\n if (disposed) return;\n stop();\n const world = apply(inverse(), screenPoint);\n const zoom = Math.min(maxZoom, Math.max(minZoom, state.zoom * factor));\n // Anchor math must use the new zoom, so compute before set().\n const offset = screenDeltaToWorld(relativeToCentre(screenPoint), zoom, state.rotation);\n set({ x: world.x - offset.x, y: world.y - offset.y, zoom });\n },\n };\n}\n","import { AtlasConfigError } from './errors.js';\nimport { apply, around, multiply, rotate, scale, translate } from './matrix.js';\nimport { rectBottom, rectFromPoints, rectRight } from './rect.js';\nimport type { Matrix, Point, Rect } from './shapes.js';\n\n/**\n * Transform for a positioned frame: `{ x, y }` places the frame's local\n * origin in world space; `rotation` (radians, clockwise on screen) and\n * `scale` pivot around `origin` (a world point, defaulting to `{ x, y }`\n * itself, which makes rotation and scale pure post-transforms of the\n * placement).\n */\nexport interface FrameOptions {\n /** World pivot for rotation and scale. Defaults to `{ x, y }`. */\n origin?: Point;\n /** Radians; positive is clockwise on screen. Default 0. */\n rotation?: number;\n /** Uniform number or per-axis scale. Default 1. */\n scale?: number | { x?: number; y?: number };\n /** Local→world placement. */\n x: number;\n y: number;\n}\n\n/**\n * Which edge(s) a resize handle drags, named like the eight bounding-box\n * handles: `'e'` drags the right edge, `'nw'` drags the top-left corner.\n */\nexport type ResizeEdges = 'e' | 'n' | 'ne' | 'nw' | 's' | 'se' | 'sw' | 'w';\n\nexport interface ResizeOptions {\n /** width/height ratio to lock. When set, the free dimension follows. */\n aspect?: number;\n /** Minimum width and height of the result. Default 0. */\n min?: number;\n}\n\nconst RESIZE_EDGES: ReadonlySet<string> = new Set(['e', 'n', 'ne', 'nw', 's', 'se', 'sw', 'w']);\n\nfunction assertFinite(name: string, value: number): void {\n if (!Number.isFinite(value)) throw new AtlasConfigError(`${name} must be a finite number, received ${value}`);\n}\n\n/**\n * Local→world matrix for a frame: `around(origin, rotate · scale) · translate(x, y)`\n * (placement first, then the pivot transform). With the default origin this\n * reduces to `translate(x, y) · rotate · scale`.\n */\nexport function frameMatrix(options: FrameOptions): Matrix {\n assertFinite('frame.x', options.x);\n assertFinite('frame.y', options.y);\n const rotation = options.rotation ?? 0;\n assertFinite('frame.rotation', rotation);\n const rawScale = options.scale ?? 1;\n const sx = typeof rawScale === 'number' ? rawScale : (rawScale.x ?? 1);\n const sy = typeof rawScale === 'number' ? rawScale : (rawScale.y ?? sx);\n assertFinite('frame.scale', sx);\n assertFinite('frame.scale', sy);\n const origin = options.origin ?? { x: options.x, y: options.y };\n assertFinite('frame.origin.x', origin.x);\n assertFinite('frame.origin.y', origin.y);\n const local = multiply(rotate(rotation), scale(sx, sy));\n // Placement applies first, then the pivot transform: multiply(a, b) is a ∘ b.\n return multiply(around(origin, local), translate(options.x, options.y));\n}\n\n/** Axis-aligned world bounds of `rect` under `matrix`: the AABB of the four transformed corners. */\nexport function boundsOfFrame(rect: Rect, matrix: Matrix): Rect {\n assertFiniteRect(rect);\n for (let i = 0; i < 6; i++) assertFinite(`matrix[${i}]`, matrix[i]);\n const corners = [\n apply(matrix, { x: rect.x, y: rect.y }),\n apply(matrix, { x: rectRight(rect), y: rect.y }),\n apply(matrix, { x: rect.x, y: rectBottom(rect) }),\n apply(matrix, { x: rectRight(rect), y: rectBottom(rect) }),\n ] as const;\n return rectFromPoints(corners);\n}\n\nfunction assertFiniteRect(rect: Rect): void {\n assertFinite('rect.x', rect.x);\n assertFinite('rect.y', rect.y);\n assertFinite('rect.width', rect.width);\n assertFinite('rect.height', rect.height);\n}\n\n/**\n * Resizes `rect` by dragging the edge(s) named by `edges` to `point` (same\n * space as `rect`). The opposite edge(s) stay fixed. With `min`, the result\n * never collapses below that size on either axis. With `aspect`\n * (width/height), the ratio is locked: a corner drag derives the other axis\n * from the axis that moved further, an edge drag grows the free dimension\n * about its centre.\n */\nexport function resizeRect(rect: Rect, edges: ResizeEdges, point: Point, options: ResizeOptions = {}): Rect {\n assertFiniteRect(rect);\n assertFinite('point.x', point.x);\n assertFinite('point.y', point.y);\n if (!RESIZE_EDGES.has(edges)) {\n throw new AtlasConfigError(\n `unknown resize edges: ${String(edges)}. Expected one of ${[...RESIZE_EDGES].join(', ')}.`,\n );\n }\n const min = options.min ?? 0;\n assertFinite('min', min);\n if (min < 0) throw new AtlasConfigError(`min must be non-negative, received ${min}`);\n const aspect = options.aspect;\n if (aspect !== undefined) {\n assertFinite('aspect', aspect);\n if (aspect <= 0) throw new AtlasConfigError(`aspect must be positive, received ${aspect}`);\n }\n\n const dragsWest = edges.includes('w');\n const dragsEast = edges.includes('e');\n const dragsNorth = edges.includes('n');\n const dragsSouth = edges.includes('s');\n\n let left = rect.x;\n let right = rectRight(rect);\n let top = rect.y;\n let bottom = rectBottom(rect);\n if (dragsWest) left = Math.min(point.x, right - min);\n if (dragsEast) right = Math.max(point.x, left + min);\n if (dragsNorth) top = Math.min(point.y, bottom - min);\n if (dragsSouth) bottom = Math.max(point.y, top + min);\n\n if (aspect !== undefined) {\n // Clamping the driving width to max(min, min·aspect) keeps both axes ≥ min.\n const minSize = Math.max(min, min * aspect);\n const width = right - left;\n const height = bottom - top;\n const horizontalDragged = dragsWest || dragsEast;\n const verticalDragged = dragsNorth || dragsSouth;\n // The opposite edge of a dragged axis stays fixed; the free dimension of an\n // edge-only drag grows about its centre.\n const applyWidth = (w: number): void => {\n if (dragsWest) left = right - w;\n else right = left + w;\n };\n const applyHeight = (h: number): void => {\n if (dragsNorth) top = bottom - h;\n else bottom = top + h;\n };\n if (horizontalDragged && verticalDragged) {\n // Corner drag: the axis that moved further drives the other.\n const movedX = Math.max(Math.abs(right - rectRight(rect)), Math.abs(left - rect.x));\n const movedY = Math.max(Math.abs(bottom - rectBottom(rect)), Math.abs(top - rect.y));\n if (movedX >= movedY) {\n applyWidth(Math.max(width, minSize));\n applyHeight((right - left) / aspect);\n } else {\n applyHeight(Math.max(height, minSize / aspect));\n applyWidth((bottom - top) * aspect);\n }\n } else if (horizontalDragged) {\n // Re-apply the clamped width so a collapse past `min` keeps the ratio.\n const w = Math.max(width, minSize);\n applyWidth(w);\n const h = w / aspect;\n const centerY = rect.y + rect.height / 2;\n top = centerY - h / 2;\n bottom = centerY + h / 2;\n } else {\n const h = Math.max(height, minSize / aspect);\n applyHeight(h);\n const w = h * aspect;\n const centerX = rect.x + rect.width / 2;\n left = centerX - w / 2;\n right = centerX + w / 2;\n }\n }\n\n return { height: bottom - top, width: right - left, x: left, y: top };\n}\n","import { AtlasConfigError } from './errors.js';\nimport type { Point } from './shapes.js';\n\n/**\n * Ray-casting point-in-polygon test. `polygon` is an open ring; an implicit closing\n * edge connects the last point to the first. Boundary behavior follows the standard\n * ray-cast convention (edge hits depend on the ray's crossing parity).\n */\nexport function pointInPolygon(polygon: readonly Point[], point: Point): boolean {\n let inside = false;\n const n = polygon.length;\n for (let i = 0, j = n - 1; i < n; j = i++) {\n const a = polygon[i];\n const b = polygon[j];\n const crosses = a.y > point.y !== b.y > point.y;\n if (!crosses) continue;\n const xAtY = ((b.x - a.x) * (point.y - a.y)) / (b.y - a.y) + a.x;\n if (point.x < xAtY) inside = !inside;\n }\n return inside;\n}\n\nfunction distanceToSegment(point: Point, a: Point, b: Point): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lengthSq = dx * dx + dy * dy;\n if (lengthSq === 0) return Math.hypot(point.x - a.x, point.y - a.y);\n let t = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSq;\n t = Math.max(0, Math.min(1, t));\n return Math.hypot(point.x - (a.x + t * dx), point.y - (a.y + t * dy));\n}\n\n/**\n * Shortest distance from a point to a polyline (an open path; no implicit closing\n * edge). Returns Infinity for an empty path and the point-to-point distance for\n * a single-point path.\n */\nexport function distanceToPolyline(path: readonly Point[], point: Point): number {\n if (path.length === 0) return Infinity;\n if (path.length === 1) return Math.hypot(point.x - path[0].x, point.y - path[0].y);\n let best = Infinity;\n for (let i = 0, j = 1; j < path.length; i = j++) {\n const d = distanceToSegment(point, path[i], path[j]);\n if (d < best) best = d;\n }\n return best;\n}\n\n/**\n * Whether a point lies within `tolerance` of a polygon's outline or inside it —\n * the hit test for stroked shapes (outlines, wires rendered as strokes).\n */\nexport function pointNearPolygon(polygon: readonly Point[], point: Point, tolerance: number): boolean {\n if (!(tolerance >= 0)) {\n throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(tolerance)}.`);\n }\n const closed = polygon.length > 0 ? [...polygon, polygon[0]] : polygon;\n if (distanceToPolyline(closed, point) <= tolerance) return true;\n return pointInPolygon(polygon, point);\n}\n","import { AtlasConfigError } from './errors.js';\nimport { rectBottom, rectCenter, rectFromPoints, rectRight } from './rect.js';\nimport type { Point, Rect } from './shapes.js';\n\n/** What a guide was snapped to: a grid line, another shape's anchor, or an equal-spacing gap. */\nexport type SnapGuideKind = 'grid' | 'object' | 'spacing';\n\n/**\n * A guide line to render. `axis` names the axis the line is perpendicular to:\n * an `'x'` guide is a vertical line at `position = x`, spanning `from..to` on\n * y. Spacing guides carry `marks`: the centers of the two equal gaps, measured\n * along the span axis, drawn as markers.\n */\nexport interface SnapGuide {\n axis: 'x' | 'y';\n /** Span endpoints along the line's own direction (world coordinates). */\n from: number;\n /** Render hint: draw grid and spacing guides dashed, object guides solid. */\n kind: SnapGuideKind;\n /** Spacing guides only: centers of the two equal gaps, on the span axis. */\n marks?: readonly [number, number];\n /** The coordinate the line sits on, on `axis`. */\n position: number;\n to: number;\n}\n\nexport interface SnapOptions {\n /** Other shapes to snap against. The moving rect itself must not be included. */\n candidates: readonly Rect[];\n /** Optional grid spacing per axis; lines run through multiples of the spacing. */\n grid?: { x?: number; y?: number };\n /**\n * Also snap for equal gaps between neighbors (img.ly-style spacing guides)\n * on each axis where no alignment snap engaged. Default false.\n */\n spacing?: boolean;\n /** Maximum world-unit distance for a snap to engage. */\n threshold: number;\n}\n\nexport interface SnapResult {\n /** Offset to apply to the moving rect; zero on an axis with no snap. */\n delta: Point;\n /** Guides for the snaps that engaged, at most one per axis. */\n guides: SnapGuide[];\n}\n\n/** The three x coordinates (left, center, right) a rect can snap with. */\nfunction xAnchors(rect: Rect): number[] {\n return [rect.x, rect.x + rect.width / 2, rectRight(rect)];\n}\n\nfunction yAnchors(rect: Rect): number[] {\n return [rect.y, rect.y + rect.height / 2, rectBottom(rect)];\n}\n\n/** A snap target with the kind of guide it produced. */\ninterface Target {\n kind: SnapGuideKind;\n value: number;\n}\n\ninterface AxisSnap {\n delta: number;\n kind: SnapGuideKind;\n /** Target coordinate that produced the snap. */\n position: number;\n}\n\nfunction bestAxisSnap(anchors: readonly number[], targets: readonly Target[], threshold: number): AxisSnap | null {\n let best: AxisSnap | null = null;\n for (const anchor of anchors) {\n for (const target of targets) {\n const delta = target.value - anchor;\n if (Math.abs(delta) > threshold) continue;\n if (best === null || Math.abs(delta) < Math.abs(best.delta)) {\n best = { delta, kind: target.kind, position: target.value };\n }\n }\n }\n return best;\n}\n\nfunction gridTargets(min: number, max: number, spacing: number | undefined, threshold: number): Target[] {\n if (spacing === undefined || !Number.isFinite(spacing) || spacing <= 0) return [];\n const targets: Target[] = [];\n for (let line = Math.floor((min - threshold) / spacing) * spacing; line <= max + threshold; line += spacing) {\n targets.push({ kind: 'grid', value: line });\n }\n return targets;\n}\n\nfunction spanFor(\n position: number,\n moved: Rect,\n candidates: readonly Rect[],\n axis: 'x' | 'y',\n): { from: number; to: number } {\n const touching: Rect[] = [];\n for (const candidate of candidates) {\n const anchors = axis === 'x' ? xAnchors(candidate) : yAnchors(candidate);\n if (anchors.some((anchor) => anchor === position)) touching.push(candidate);\n }\n const points: Point[] = [moved, ...touching].flatMap((rect) => [\n { x: rect.x, y: rect.y },\n { x: rectRight(rect), y: rectBottom(rect) },\n ]);\n const bounds = rectFromPoints(points) ?? { height: 0, width: 0, x: position, y: position };\n return axis === 'x' ? { from: bounds.y, to: rectBottom(bounds) } : { from: bounds.x, to: rectRight(bounds) };\n}\n\n/** Overlap test on the axis perpendicular to `axis`. */\nfunction overlapsPerpendicular(a: Rect, b: Rect, axis: 'x' | 'y'): boolean {\n return axis === 'x' ? a.y < rectBottom(b) && b.y < rectBottom(a) : a.x < rectRight(b) && b.x < rectRight(a);\n}\n\n/**\n * Equal-gap snap along `axis`: centers the rect between the nearest\n * perpendicular-overlapping neighbors when the gaps can be made equal within\n * `threshold`. `position` is the moving rect's center on the perpendicular\n * axis; `span` and `marks` are along `axis`.\n */\nfunction axisSpacingSnap(\n rect: Rect,\n candidates: readonly Rect[],\n axis: 'x' | 'y',\n threshold: number,\n): { delta: number; marks: readonly [number, number]; position: number; span: readonly [number, number] } | null {\n const start = axis === 'x' ? (r: Rect) => r.x : (r: Rect) => r.y;\n const end = axis === 'x' ? (r: Rect) => rectRight(r) : (r: Rect) => rectBottom(r);\n let leftEnd = -Infinity;\n let rightStart = Infinity;\n for (const candidate of candidates) {\n if (!overlapsPerpendicular(rect, candidate, axis)) continue;\n if (end(candidate) <= start(rect) && end(candidate) > leftEnd) leftEnd = end(candidate);\n if (start(candidate) >= end(rect) && start(candidate) < rightStart) rightStart = start(candidate);\n }\n if (leftEnd === -Infinity || rightStart === Infinity) return null;\n const free = rightStart - leftEnd - (axis === 'x' ? rect.width : rect.height);\n if (free < 0) return null;\n const ideal = leftEnd + free / 2;\n const delta = ideal - start(rect);\n if (Math.abs(delta) > threshold) return null;\n const gap = free / 2;\n return {\n delta,\n marks: [leftEnd + gap / 2, rightStart - gap / 2],\n // `rect` is the already-moved rect, so the guide sits at the position the\n // shape actually occupies after both axes snapped.\n position: axis === 'x' ? rectCenter(rect).y : rectCenter(rect).x,\n span: [leftEnd, rightStart],\n };\n}\n\n/**\n * Snap a moving rect against candidate shapes, an optional grid, and (with\n * `spacing`) equal gaps between neighbors. Each axis snaps independently to\n * the nearest alignment target within `threshold`; when an axis finds no\n * alignment snap and `spacing` is enabled, it falls back to centering the rect\n * between its nearest neighbors on that axis.\n */\nexport function snapRect(rect: Rect, options: SnapOptions): SnapResult {\n const { candidates, grid, spacing, threshold } = options;\n if (!(threshold >= 0)) {\n throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(threshold)}.`);\n }\n let movedX = rect.x;\n let movedY = rect.y;\n const delta = { x: 0, y: 0 };\n\n const xTargets: Target[] = candidates.flatMap((candidate) =>\n xAnchors(candidate).map((value): Target => ({ kind: 'object', value })),\n );\n xTargets.push(...gridTargets(rect.x, rectRight(rect), grid?.x, threshold));\n const xSnap = bestAxisSnap(xAnchors(rect), xTargets, threshold);\n if (xSnap !== null) {\n delta.x = xSnap.delta;\n movedX += xSnap.delta;\n }\n\n const yTargets: Target[] = candidates.flatMap((candidate) =>\n yAnchors(candidate).map((value): Target => ({ kind: 'object', value })),\n );\n yTargets.push(...gridTargets(rect.y, rectBottom(rect), grid?.y, threshold));\n const ySnap = bestAxisSnap(yAnchors(rect), yTargets, threshold);\n if (ySnap !== null) {\n delta.y = ySnap.delta;\n movedY += ySnap.delta;\n }\n\n // Guides span the union of the moved rect and every candidate sharing the snapped coordinate.\n const movedRect: Rect = { ...rect, x: movedX, y: movedY };\n const guides: SnapGuide[] = [];\n if (xSnap !== null) {\n const span = spanFor(xSnap.position, movedRect, candidates, 'x');\n guides.push({ axis: 'x', from: span.from, kind: xSnap.kind, position: xSnap.position, to: span.to });\n }\n if (ySnap !== null) {\n const span = spanFor(ySnap.position, movedRect, candidates, 'y');\n guides.push({ axis: 'y', from: span.from, kind: ySnap.kind, position: ySnap.position, to: span.to });\n }\n\n // Equal-spacing fallback fills the axes where no alignment snap engaged.\n // It runs on the moved rect so its perpendicular position honours the other\n // axis's snap.\n if (spacing) {\n if (xSnap === null) {\n const gap = axisSpacingSnap(movedRect, candidates, 'x', threshold);\n if (gap !== null) {\n delta.x = gap.delta;\n guides.push({\n axis: 'y',\n from: gap.span[0],\n kind: 'spacing',\n marks: gap.marks,\n position: gap.position,\n to: gap.span[1],\n });\n }\n }\n if (ySnap === null) {\n const gap = axisSpacingSnap(movedRect, candidates, 'y', threshold);\n if (gap !== null) {\n delta.y = gap.delta;\n guides.push({\n axis: 'x',\n from: gap.span[0],\n kind: 'spacing',\n marks: gap.marks,\n position: gap.position,\n to: gap.span[1],\n });\n }\n }\n }\n return { delta, guides };\n}\n\n/** Which edge/center line to align rects on. */\nexport type AlignEdge = 'left' | 'horizontal-center' | 'right' | 'top' | 'vertical-center' | 'bottom';\n\n/**\n * Align rects on a shared line derived from their combined bounds, preserving\n * sizes. Returns new rects in input order; the input is untouched.\n */\nexport function alignRects(rects: readonly Rect[], edge: AlignEdge): Rect[] {\n if (rects.length === 0) return [];\n const bounds = rectFromPoints(\n rects.flatMap((rect) => [\n { x: rect.x, y: rect.y },\n { x: rectRight(rect), y: rectBottom(rect) },\n ]),\n );\n if (bounds === null) return [];\n return rects.map((rect) => {\n switch (edge) {\n case 'left':\n return { ...rect, x: bounds.x };\n case 'horizontal-center':\n return { ...rect, x: rectCenter(bounds).x - rect.width / 2 };\n case 'right':\n return { ...rect, x: rectRight(bounds) - rect.width };\n case 'top':\n return { ...rect, y: bounds.y };\n case 'vertical-center':\n return { ...rect, y: rectCenter(bounds).y - rect.height / 2 };\n case 'bottom':\n return { ...rect, y: rectBottom(bounds) - rect.height };\n default:\n throw new AtlasConfigError(`unknown align edge: ${String(edge)}.`);\n }\n });\n}\n\n/**\n * Equalize the gaps between rects along an axis. The outermost rects stay\n * fixed; middle rects move in sorted order along the axis. Fewer than three\n * rects are returned as copies unchanged.\n */\nexport function distributeRects(rects: readonly Rect[], axis: 'x' | 'y'): Rect[] {\n if (rects.length <= 2) return rects.map((rect) => ({ ...rect }));\n const start = axis === 'x' ? (rect: Rect) => rect.x : (rect: Rect) => rect.y;\n const size = axis === 'x' ? (rect: Rect) => rect.width : (rect: Rect) => rect.height;\n const order = rects\n .map((rect, index) => ({ index, rect }))\n .sort((a, b) => start(a.rect) - start(b.rect) || a.index - b.index);\n const first = order[0].rect;\n const last = order[order.length - 1].rect;\n const totalSpan = start(last) + size(last) - start(first);\n const totalSize = order.reduce((sum, entry) => sum + size(entry.rect), 0);\n const gap = (totalSpan - totalSize) / (order.length - 1);\n const result = rects.map((rect) => ({ ...rect }));\n let cursor = start(first);\n for (const entry of order) {\n const moved = { ...entry.rect };\n if (axis === 'x') moved.x = cursor;\n else moved.y = cursor;\n result[entry.index] = moved;\n cursor += size(entry.rect) + gap;\n }\n return result;\n}\n","import { AtlasConfigError } from './errors.js';\nimport { containsRect, inflateRect, rectsIntersect } from './rect.js';\nimport type { Point, Rect } from './shapes.js';\n\nexport type SpatialIndexOptions = Readonly<{\n /** Maximum children per node before a split. Default 8. */\n maxEntriesPerNode?: number;\n}>;\n\nexport type SpatialQueryOptions = Readonly<{\n /** Expand the query point into a box of this half-size. Default 0. */\n tolerance?: number;\n}>;\n\n/**\n * A Map-like index over ids and their bounding rects. The index stores only\n * geometry — the caller owns the data and looks it up from returned ids —\n * so stored values can never go stale.\n */\nexport type SpatialIndex<K = string> = Readonly<{\n /** Insert `id`, or move it to `rect` when it already exists. */\n set(id: K, rect: Rect): void;\n delete(id: K): boolean;\n /** Current rect for `id`, or undefined. */\n get(id: K): Rect | undefined;\n has(id: K): boolean;\n clear(): void;\n readonly size: number;\n /** Bounding box of all entries; null when empty. */\n readonly bounds: Rect | null;\n /** Ids whose rect overlaps or touches `rect`. */\n queryRect(rect: Rect): K[];\n /** Ids whose rect contains `point`, or comes within `tolerance` of it. */\n queryPoint(point: Point, options?: SpatialQueryOptions): K[];\n}>;\n\ninterface LeafEntry<K> {\n id: K;\n rect: Rect;\n}\n\ntype Leaf<K> = { children: LeafEntry<K>[]; leaf: true; rect: Rect | null };\ntype Branch<K> = { children: Node<K>[]; leaf: false; rect: Rect | null };\ntype Node<K> = Leaf<K> | Branch<K>;\n\nfunction rectOf<K>(node: Node<K> | LeafEntry<K>): Rect {\n return node.rect as Rect;\n}\n\nfunction unionRects(a: Rect, b: Rect): Rect {\n const x = Math.min(a.x, b.x);\n const y = Math.min(a.y, b.y);\n return {\n height: Math.max(a.y + a.height, b.y + b.height) - y,\n width: Math.max(a.x + a.width, b.x + b.width) - x,\n x,\n y,\n };\n}\n\nfunction area(rect: Rect): number {\n return rect.width * rect.height;\n}\n\nfunction rectsEqual(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n}\n\nfunction recompute<K>(node: Node<K>): void {\n let rect: Rect | null = null;\n for (const child of node.children) {\n rect = rect === null ? { ...rectOf(child) } : unionRects(rect, rectOf(child));\n }\n node.rect = rect;\n}\n\n/**\n * Dynamic R-tree (Guttman, quadratic split) over axis-aligned rectangles:\n * O(log n) rect and point queries for hit-testing, marquee selection, and\n * viewport culling over thousands of items. Rect intersection uses closed\n * intervals, so zero-area entries (lines, points) are findable.\n */\nexport function createSpatialIndex<K = string>(options: SpatialIndexOptions = {}): SpatialIndex<K> {\n const maxEntries = options.maxEntriesPerNode ?? 8;\n if (!Number.isInteger(maxEntries) || maxEntries < 4) {\n throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${maxEntries}`);\n }\n const minEntries = Math.max(2, Math.ceil(maxEntries / 3));\n const entries = new Map<K, LeafEntry<K>>();\n let root: Node<K> = { children: [], leaf: true, rect: null };\n\n const pickChild = (node: Branch<K>, rect: Rect): Node<K> => {\n let best: Node<K> | null = null;\n let bestEnlargement = Infinity;\n let bestArea = Infinity;\n for (const child of node.children) {\n const current = child.rect ?? rect;\n const enlargement = area(unionRects(current, rect)) - area(current);\n if (enlargement < bestEnlargement || (enlargement === bestEnlargement && area(current) < bestArea)) {\n best = child;\n bestEnlargement = enlargement;\n bestArea = area(current);\n }\n }\n return best as Node<K>;\n };\n\n const split = (node: Node<K>): [Node<K>, Node<K>] => {\n const items = node.children;\n // Quadratic pick-seeds: the pair wasting the most area when combined.\n let si = 0;\n let sj = 1;\n let worst = -Infinity;\n for (let i = 0; i < items.length; i++) {\n for (let j = i + 1; j < items.length; j++) {\n const waste =\n area(unionRects(rectOf(items[i]), rectOf(items[j]))) - area(rectOf(items[i])) - area(rectOf(items[j]));\n if (waste > worst) {\n worst = waste;\n si = i;\n sj = j;\n }\n }\n }\n const groupA: Array<Node<K> | LeafEntry<K>> = [items[si]];\n const groupB: Array<Node<K> | LeafEntry<K>> = [items[sj]];\n let rectA = rectOf(items[si]);\n let rectB = rectOf(items[sj]);\n const remaining = items.filter((_, index) => index !== si && index !== sj);\n for (const [index, item] of remaining.entries()) {\n // Force distribution so neither group can exceed maxEntries or fall below minEntries.\n const mustA =\n groupA.length + (remaining.length - index) > maxEntries ||\n groupB.length + (remaining.length - index) - 1 < minEntries;\n const mustB =\n groupB.length + (remaining.length - index) > maxEntries ||\n groupA.length + (remaining.length - index) - 1 < minEntries;\n let toA: boolean;\n if (mustA) toA = true;\n else if (mustB) toA = false;\n else {\n const enlargeA = area(unionRects(rectA, rectOf(item))) - area(rectA);\n const enlargeB = area(unionRects(rectB, rectOf(item))) - area(rectB);\n toA = enlargeA < enlargeB || (enlargeA === enlargeB && area(rectA) <= area(rectB));\n }\n if (toA) {\n groupA.push(item);\n rectA = unionRects(rectA, rectOf(item));\n } else {\n groupB.push(item);\n rectB = unionRects(rectB, rectOf(item));\n }\n }\n const a = (\n node.leaf\n ? { children: groupA as LeafEntry<K>[], leaf: true, rect: null }\n : { children: groupA as Node<K>[], leaf: false, rect: null }\n ) as Node<K>;\n const b = (\n node.leaf\n ? { children: groupB as LeafEntry<K>[], leaf: true, rect: null }\n : { children: groupB as Node<K>[], leaf: false, rect: null }\n ) as Node<K>;\n recompute(a);\n recompute(b);\n return [a, b];\n };\n\n /** Insert `item` under `node`; returns the split pair when `node` overflows. */\n const insertInto = (node: Node<K>, item: Node<K> | LeafEntry<K>): [Node<K>, Node<K>] | null => {\n if (node.leaf) {\n node.children.push(item as LeafEntry<K>);\n node.rect = node.rect === null ? { ...rectOf(item) } : unionRects(node.rect, rectOf(item));\n if (node.children.length > maxEntries) return split(node);\n return null;\n }\n const branch = node as Branch<K>;\n const child = pickChild(branch, rectOf(item));\n const overflow = insertInto(child, item);\n recompute(node);\n if (overflow) {\n const index = branch.children.indexOf(child);\n branch.children.splice(index, 1, overflow[0], overflow[1]);\n recompute(node);\n }\n if (node.children.length > maxEntries) return split(node);\n return null;\n };\n\n const insertEntry = (entry: LeafEntry<K>): void => {\n // A fully emptied root stays as an empty branch after removals; revive it as a leaf.\n if (!root.leaf && root.children.length === 0) {\n root = { children: [], leaf: true, rect: null };\n }\n const overflow = insertInto(root, entry);\n if (overflow) {\n root = { children: overflow, leaf: false, rect: null };\n recompute(root);\n }\n };\n\n /** Depth-first remove; returns true when `node` became empty. */\n const removeFrom = (node: Node<K>, entry: LeafEntry<K>): boolean => {\n if (node.leaf) {\n const index = node.children.indexOf(entry);\n if (index !== -1) node.children.splice(index, 1);\n recompute(node);\n return node.children.length === 0;\n }\n const branch = node as Branch<K>;\n for (let i = branch.children.length - 1; i >= 0; i--) {\n const child = branch.children[i];\n // Prune by containment, not intersection: a branch rect is the union of\n // its children, so the entry's rect is always contained in the child\n // that holds it.\n if (child.rect && containsRect(child.rect, entry.rect)) {\n if (removeFrom(child, entry)) branch.children.splice(i, 1);\n }\n }\n recompute(node);\n return branch.children.length === 0;\n };\n\n const deleteEntry = (id: K): boolean => {\n const entry = entries.get(id);\n if (!entry) return false;\n entries.delete(id);\n removeFrom(root, entry);\n // Collapse a root branch that ended up with a single child.\n while (!root.leaf && root.children.length === 1) {\n root = root.children[0];\n }\n return true;\n };\n\n const queryInto = (node: Node<K>, hits: (rect: Rect) => boolean, out: K[]): void => {\n if (!node.rect || !hits(node.rect)) return;\n if (node.leaf) {\n for (const entry of node.children) {\n if (hits(entry.rect)) out.push(entry.id);\n }\n return;\n }\n for (const child of (node as Branch<K>).children) queryInto(child, hits, out);\n };\n\n return {\n get bounds() {\n return root.rect;\n },\n clear() {\n entries.clear();\n root = { children: [], leaf: true, rect: null };\n },\n delete: deleteEntry,\n get(id) {\n return entries.get(id)?.rect;\n },\n has(id) {\n return entries.has(id);\n },\n queryPoint(point, queryOptions) {\n const tolerance = queryOptions?.tolerance ?? 0;\n if (!(tolerance >= 0)) {\n throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${tolerance}`);\n }\n // A point is a zero-size box; closed-interval intersection makes it hit\n // rects that merely touch it, so one shared path covers both query kinds.\n const box: Rect = inflateRect({ ...point, height: 0, width: 0 }, tolerance);\n const out: K[] = [];\n queryInto(root, (rect) => rectsIntersect(rect, box), out);\n return out;\n },\n queryRect(rect) {\n const out: K[] = [];\n queryInto(root, (candidate) => rectsIntersect(candidate, rect), out);\n return out;\n },\n set(id, rect) {\n const existing = entries.get(id);\n if (existing) {\n if (rectsEqual(existing.rect, rect)) return;\n deleteEntry(id);\n }\n const entry: LeafEntry<K> = { id, rect: { ...rect } };\n entries.set(id, entry);\n insertEntry(entry);\n },\n get size() {\n return entries.size;\n },\n };\n}\n"],"mappings":"A,mEAAA,IAAa,WAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAMC,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,iBAAb,cAAsC,UAAW,CAAC,ECNrCC,EAAmB,OAAO,OAAO,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,CAAC,CAAC,EAEhE,SAAgB,SAAS,EAAW,EAAmB,C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CACvB,EACA,WAAW,EAAO,EAAc,CAC9B,IAAMlE,EAAYqE,GAAc,WAAa,EAC7C,GAAI,EAAErE,GAAa,GACjB,MAAM,IAAI,iBAAiB,4DAA4DA,GAAW,EAIpG,IAAMsE,EAAY,YAAY,CAAE,GAAGpL,EAAO,OAAQ,EAAG,MAAO,CAAE,EAAG8G,CAAS,EACpEoE,EAAW,CAAC,EAElB,OADA,UAAU1B,EAAO,GAAS,eAAevI,EAAMmK,CAAG,EAAGF,CAAG,EACjDA,CACT,EACA,UAAU,EAAM,CACd,IAAMA,EAAW,CAAC,EAElB,OADA,UAAU1B,EAAO,GAAc,eAAelG,EAAWrC,CAAI,EAAGiK,CAAG,EAC5DA,CACT,EACA,IAAI,EAAI,EAAM,CACZ,IAAMG,EAAW9B,EAAQ,IAAIyB,CAAE,EAC/B,GAAIK,EAAU,CACZ,GAAI,WAAWA,EAAS,KAAMpK,CAAI,EAAG,OACrC,YAAY+J,CAAE,CAChB,CACA,IAAMhC,EAAsB,CAAE,KAAI,KAAM,CAAE,GAAG/H,CAAK,CAAE,EACpDsI,EAAQ,IAAIyB,EAAIhC,CAAK,EACrB,YAAYA,CAAK,CACnB,EACA,IAAI,MAAO,CACT,OAAOO,EAAQ,IACjB,CACF,CACF,C"}
|
package/dist/atlas.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Atlas=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var AtlasError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},AtlasConfigError=class extends AtlasError{},t=Object.freeze([1,0,0,1,0,0]);function multiply(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function apply(e,t){return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}function translate(e,t){return[1,0,0,1,e,t]}function scale(e,t=e){return[e,0,0,t,0,0]}function rotate(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,-n,t,0,0]}function around(e,t){return multiply(multiply(translate(e.x,e.y),t),translate(-e.x,-e.y))}function scaleOf(e){return(Math.hypot(e[0],e[1])+Math.hypot(e[2],e[3]))/2}function toCssMatrix(e){return`matrix(${e.join(`,`)})`}function invert(e){let t=e[0]*e[3]-e[2]*e[1];if(!Number.isFinite(t)||t===0)return null;let n=1/t;return[e[3]*n,-e[1]*n,-e[2]*n,e[0]*n,(e[2]*e[5]-e[3]*e[4])*n,(e[1]*e[4]-e[0]*e[5])*n]}function rectFromPoints(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e)a=!0,o.x<t&&(t=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return a?{height:i-n,width:r-t,x:t,y:n}:null}function rectRight(e){return e.x+e.width}function rectBottom(e){return e.y+e.height}function rectCenter(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function unionRect(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(rectBottom(e),rectBottom(t))-r,width:Math.max(rectRight(e),rectRight(t))-n,x:n,y:r}}function intersectRect(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(rectRight(e),rectRight(t)),a=Math.min(rectBottom(e),rectBottom(t));return i<n||a<r?null:{height:a-r,width:i-n,x:n,y:r}}function containsRect(e,t){return e.x<=t.x&&e.y<=t.y&&rectRight(e)>=rectRight(t)&&rectBottom(e)>=rectBottom(t)}function containsPoint(e,t){return t.x>=e.x&&t.x<=rectRight(e)&&t.y>=e.y&&t.y<=rectBottom(e)}function inflateRect(e,t){return{height:e.height+t*2,width:e.width+t*2,x:e.x-t,y:e.y-t}}function rectsIntersect(e,t){return intersectRect(e,t)!==null}var n={cancelFrame:e=>cancelAnimationFrame(e),now:()=>performance.now(),requestFrame:e=>requestAnimationFrame(e)};function assertFinite(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function easeInOut(e){return e<.5?2*e*e:1-(-2*e+2)**2/2}function normalizeAngle(e){return((e+Math.PI)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)-Math.PI}function shortestAngle(e,t){return normalizeAngle(t-e)}function screenDeltaToWorld(e,t,n){return apply(multiply(rotate(-n),scale(1/t)),e)}function matrixOf(e,t){let n=multiply(multiply(scale(e.zoom),rotate(e.rotation)),translate(-e.x,-e.y));return multiply(translate(t.width/2,t.height/2),n)}function inverseOf(e,t){let n=multiply(rotate(-e.rotation),scale(1/e.zoom)),r=screenDeltaToWorld({x:t.width/2,y:t.height/2},e.zoom,e.rotation);return multiply(translate(e.x-r.x,e.y-r.y),n)}function createCamera(e={}){let t=e.minZoom??.01,r=e.maxZoom??1e3;if(!(t>0&&t<=r))throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${t} and ${r}`);let i=e.scheduler??n,a=e.initial??{},o=e.viewport??{height:0,width:0},s={rotation:normalizeAngle(a.rotation??0),x:a.x??0,y:a.y??0,zoom:Math.min(r,Math.max(t,a.zoom??1))};for(let[e,t]of[[`camera.x`,s.x],[`camera.y`,s.y],[`camera.rotation`,s.rotation]])assertFinite(e,t);let c=new AbortController,l=!1,u=null,d=new Set,f=null,p=null,matrix=()=>(f??=matrixOf(s,o),f),inverse=()=>(p??=inverseOf(s,o),p),invalidate=()=>{f=null,p=null},relativeToCentre=e=>({x:e.x-o.width/2,y:e.y-o.height/2}),emit=()=>{for(let e of[...d])e(s)},set=e=>{if(l)return;let n={rotation:normalizeAngle(e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(t,e.zoom??s.zoom))};(n.x!==s.x||n.y!==s.y||n.zoom!==s.zoom||n.rotation!==s.rotation)&&(s=n,invalidate(),emit())},stop=()=>{u&&=(i.cancelFrame(u.frame),u.cleanup(),null)},dispose=()=>{l||(l=!0,stop(),d.clear(),c.abort())},animateTo=(e,n={})=>{if(stop(),l)return;let a=n.duration??250,o=n.easing??easeInOut,c=n.signal;if(c?.aborted)return;if(a<=0){set(e);return}let d=s,f={rotation:d.rotation+shortestAngle(d.rotation,e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(t,e.zoom??s.zoom))},p=i.now(),m=Math.log(d.zoom),h=Math.log(f.zoom),g={cleanup:()=>{},frame:0};u=g;let abort=()=>{u===g&&stop()};c&&(c.addEventListener(`abort`,abort,{once:!0}),g.cleanup=()=>c.removeEventListener(`abort`,abort));let step=e=>{if(u!==g)return;let t=Math.min(1,(e-p)/a),n=o(t);set({rotation:d.rotation+(f.rotation-d.rotation)*n,x:d.x+(f.x-d.x)*n,y:d.y+(f.y-d.y)*n,zoom:Math.exp(m+(h-m)*n)}),t>=1?(u=null,g.cleanup()):g.frame=i.requestFrame(step)};g.frame=i.requestFrame(step)};return{animateTo,get disposalSignal(){return c.signal},dispose,get disposed(){return l},fitBounds(e,n={}){if(l)return;stop();let i=n.padding??0,a=Math.max(1,o.width-i*2),s=Math.max(1,o.height-i*2),c=Math.min(r,Math.max(t,Math.min(e.width===0?r:a/e.width,e.height===0?r:s/e.height)));set({x:e.x+e.width/2,y:e.y+e.height/2,zoom:c})},get inverse(){return inverse()},get matrix(){return matrix()},panBy(e,t){if(l)return;stop();let n=screenDeltaToWorld({x:e,y:t},s.zoom,s.rotation);set({x:s.x-n.x,y:s.y-n.y})},resize(e){l||(e.width!==o.width||e.height!==o.height)&&(o={height:e.height,width:e.width},invalidate(),emit())},rotateAt(e,t){if(l)return;stop();let n=apply(inverse(),e),r=s.rotation+t,i=screenDeltaToWorld(relativeToCentre(e),s.zoom,r);set({rotation:r,x:n.x-i.x,y:n.y-i.y})},set(e){stop(),set(e)},[Symbol.dispose]:dispose,get state(){return s},stop,subscribe(e,t){return l||t?.signal?.aborted?()=>{}:(d.add(e),t?.signal?.addEventListener(`abort`,()=>d.delete(e),{once:!0}),()=>d.delete(e))},toScreen(e){return apply(matrix(),e)},toWorld(e){return apply(inverse(),e)},get viewport(){return o},get visibleRect(){let e=inverse();return rectFromPoints([apply(e,{x:0,y:0}),apply(e,{x:o.width,y:0}),apply(e,{x:0,y:o.height}),apply(e,{x:o.width,y:o.height})])},zoomAt(e,n){if(!Number.isFinite(n)||n<=0)throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${n}`);if(l)return;stop();let i=apply(inverse(),e),a=Math.min(r,Math.max(t,s.zoom*n)),o=screenDeltaToWorld(relativeToCentre(e),a,s.rotation);set({x:i.x-o.x,y:i.y-o.y,zoom:a})}}}function pointInPolygon(e,t){let n=!1,r=e.length;for(let i=0,a=r-1;i<r;a=i++){let r=e[i],o=e[a];if(r.y>t.y==o.y>t.y)continue;let s=(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x;t.x<s&&(n=!n)}return n}function distanceToSegment(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function distanceToPolyline(e,t){if(e.length===0)return 1/0;if(e.length===1)return Math.hypot(t.x-e[0].x,t.y-e[0].y);let n=1/0;for(let r=0,i=1;i<e.length;r=i++){let a=distanceToSegment(t,e[r],e[i]);a<n&&(n=a)}return n}function pointNearPolygon(e,t,n){if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(n)}.`);return distanceToPolyline(e.length>0?[...e,e[0]]:e,t)<=n||pointInPolygon(e,t)}function xAnchors(e){return[e.x,e.x+e.width/2,rectRight(e)]}function yAnchors(e){return[e.y,e.y+e.height/2,rectBottom(e)]}function bestAxisSnap(e,t,n){let r=null;for(let i of e)for(let e of t){let t=e.value-i;Math.abs(t)>n||(r===null||Math.abs(t)<Math.abs(r.delta))&&(r={delta:t,kind:e.kind,position:e.value})}return r}function gridTargets(e,t,n,r){if(n===void 0||!Number.isFinite(n)||n<=0)return[];let i=[];for(let a=Math.floor((e-r)/n)*n;a<=t+r;a+=n)i.push({kind:`grid`,value:a});return i}function spanFor(e,t,n,r){let i=[];for(let t of n)(r===`x`?xAnchors(t):yAnchors(t)).some(t=>t===e)&&i.push(t);let a=rectFromPoints([t,...i].flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]))??{height:0,width:0,x:e,y:e};return r===`x`?{from:a.y,to:rectBottom(a)}:{from:a.x,to:rectRight(a)}}function overlapsPerpendicular(e,t,n){return n===`x`?e.y<rectBottom(t)&&t.y<rectBottom(e):e.x<rectRight(t)&&t.x<rectRight(e)}function axisSpacingSnap(e,t,n,r){let i=n===`x`?e=>e.x:e=>e.y,a=n===`x`?e=>rectRight(e):e=>rectBottom(e),o=-1/0,s=1/0;for(let r of t)overlapsPerpendicular(e,r,n)&&(a(r)<=i(e)&&a(r)>o&&(o=a(r)),i(r)>=a(e)&&i(r)<s&&(s=i(r)));if(o===-1/0||s===1/0)return null;let c=s-o-(n===`x`?e.width:e.height);if(c<0)return null;let l=o+c/2-i(e);if(Math.abs(l)>r)return null;let u=c/2;return{delta:l,marks:[o+u/2,s-u/2],position:n===`x`?rectCenter(e).y:rectCenter(e).x,span:[o,s]}}function snapRect(e,t){let{candidates:n,grid:r,spacing:i,threshold:a}=t;if(!(a>=0))throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(a)}.`);let o=e.x,s=e.y,c={x:0,y:0},l=n.flatMap(e=>xAnchors(e).map(e=>({kind:`object`,value:e})));l.push(...gridTargets(e.x,rectRight(e),r?.x,a));let u=bestAxisSnap(xAnchors(e),l,a);u!==null&&(c.x=u.delta,o+=u.delta);let d=n.flatMap(e=>yAnchors(e).map(e=>({kind:`object`,value:e})));d.push(...gridTargets(e.y,rectBottom(e),r?.y,a));let f=bestAxisSnap(yAnchors(e),d,a);f!==null&&(c.y=f.delta,s+=f.delta);let p={...e,x:o,y:s},m=[];if(u!==null){let e=spanFor(u.position,p,n,`x`);m.push({axis:`x`,from:e.from,kind:u.kind,position:u.position,to:e.to})}if(f!==null){let e=spanFor(f.position,p,n,`y`);m.push({axis:`y`,from:e.from,kind:f.kind,position:f.position,to:e.to})}if(i){if(u===null){let e=axisSpacingSnap(p,n,`x`,a);e!==null&&(c.x=e.delta,m.push({axis:`y`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}if(f===null){let e=axisSpacingSnap(p,n,`y`,a);e!==null&&(c.y=e.delta,m.push({axis:`x`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}}return{delta:c,guides:m}}function alignRects(e,t){if(e.length===0)return[];let n=rectFromPoints(e.flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]));return n===null?[]:e.map(e=>{switch(t){case`left`:return{...e,x:n.x};case`horizontal-center`:return{...e,x:rectCenter(n).x-e.width/2};case`right`:return{...e,x:rectRight(n)-e.width};case`top`:return{...e,y:n.y};case`vertical-center`:return{...e,y:rectCenter(n).y-e.height/2};case`bottom`:return{...e,y:rectBottom(n)-e.height};default:throw new AtlasConfigError(`unknown align edge: ${String(t)}.`)}})}function distributeRects(e,t){if(e.length<=2)return e.map(e=>({...e}));let n=t===`x`?e=>e.x:e=>e.y,r=t===`x`?e=>e.width:e=>e.height,i=e.map((e,t)=>({index:t,rect:e})).sort((e,t)=>n(e.rect)-n(t.rect)||e.index-t.index),a=i[0].rect,o=i[i.length-1].rect,s=(n(o)+r(o)-n(a)-i.reduce((e,t)=>e+r(t.rect),0))/(i.length-1),c=e.map(e=>({...e})),l=n(a);for(let e of i){let n={...e.rect};t===`x`?n.x=l:n.y=l,c[e.index]=n,l+=r(e.rect)+s}return c}function rectOf(e){return e.rect}function unionRects(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(e.y+e.height,t.y+t.height)-r,width:Math.max(e.x+e.width,t.x+t.width)-n,x:n,y:r}}function area(e){return e.width*e.height}function rectsEqual(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function recompute(e){let t=null;for(let n of e.children)t=t===null?{...rectOf(n)}:unionRects(t,rectOf(n));e.rect=t}function createSpatialIndex(e={}){let t=e.maxEntriesPerNode??8;if(!Number.isInteger(t)||t<4)throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${t}`);let n=Math.max(2,Math.ceil(t/3)),r=new Map,i={children:[],leaf:!0,rect:null},pickChild=(e,t)=>{let n=null,r=1/0,i=1/0;for(let a of e.children){let e=a.rect??t,o=area(unionRects(e,t))-area(e);(o<r||o===r&&area(e)<i)&&(n=a,r=o,i=area(e))}return n},split=e=>{let r=e.children,i=0,a=1,o=-1/0;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=area(unionRects(rectOf(r[e]),rectOf(r[t])))-area(rectOf(r[e]))-area(rectOf(r[t]));n>o&&(o=n,i=e,a=t)}let s=[r[i]],c=[r[a]],l=rectOf(r[i]),u=rectOf(r[a]),d=r.filter((e,t)=>t!==i&&t!==a);for(let[e,r]of d.entries()){let i=s.length+(d.length-e)>t||c.length+(d.length-e)-1<n,a=c.length+(d.length-e)>t||s.length+(d.length-e)-1<n,o;if(i)o=!0;else if(a)o=!1;else{let e=area(unionRects(l,rectOf(r)))-area(l),t=area(unionRects(u,rectOf(r)))-area(u);o=e<t||e===t&&area(l)<=area(u)}o?(s.push(r),l=unionRects(l,rectOf(r))):(c.push(r),u=unionRects(u,rectOf(r)))}let f=e.leaf?{children:s,leaf:!0,rect:null}:{children:s,leaf:!1,rect:null},p=e.leaf?{children:c,leaf:!0,rect:null}:{children:c,leaf:!1,rect:null};return recompute(f),recompute(p),[f,p]},insertInto=(e,n)=>{if(e.leaf)return e.children.push(n),e.rect=e.rect===null?{...rectOf(n)}:unionRects(e.rect,rectOf(n)),e.children.length>t?split(e):null;let r=e,i=pickChild(r,rectOf(n)),a=insertInto(i,n);if(recompute(e),a){let t=r.children.indexOf(i);r.children.splice(t,1,a[0],a[1]),recompute(e)}return e.children.length>t?split(e):null},insertEntry=e=>{!i.leaf&&i.children.length===0&&(i={children:[],leaf:!0,rect:null});let t=insertInto(i,e);t&&(i={children:t,leaf:!1,rect:null},recompute(i))},removeFrom=(e,t)=>{if(e.leaf){let n=e.children.indexOf(t);return n!==-1&&e.children.splice(n,1),recompute(e),e.children.length===0}let n=e;for(let e=n.children.length-1;e>=0;e--){let r=n.children[e];r.rect&&containsRect(r.rect,t.rect)&&removeFrom(r,t)&&n.children.splice(e,1)}return recompute(e),n.children.length===0},deleteEntry=e=>{let t=r.get(e);if(!t)return!1;for(r.delete(e),removeFrom(i,t);!i.leaf&&i.children.length===1;)i=i.children[0];return!0},queryInto=(e,t,n)=>{if(e.rect&&t(e.rect)){if(e.leaf)for(let r of e.children)t(r.rect)&&n.push(r.id);else for(let r of e.children)queryInto(r,t,n)}};return{get bounds(){return i.rect},clear(){r.clear(),i={children:[],leaf:!0,rect:null}},delete:deleteEntry,get(e){return r.get(e)?.rect},has(e){return r.has(e)},queryPoint(e,t){let n=t?.tolerance??0;if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${n}`);let r=inflateRect({...e,height:0,width:0},n),a=[];return queryInto(i,e=>rectsIntersect(e,r),a),a},queryRect(e){let t=[];return queryInto(i,t=>rectsIntersect(t,e),t),t},set(e,t){let n=r.get(e);if(n){if(rectsEqual(n.rect,t))return;deleteEntry(e)}let i={id:e,rect:{...t}};r.set(e,i),insertEntry(i)},get size(){return r.size}}}return e.AtlasConfigError=AtlasConfigError,e.AtlasError=AtlasError,e.IDENTITY=t,e.alignRects=alignRects,e.apply=apply,e.around=around,e.containsPoint=containsPoint,e.containsRect=containsRect,e.createCamera=createCamera,e.createSpatialIndex=createSpatialIndex,e.distanceToPolyline=distanceToPolyline,e.distributeRects=distributeRects,e.inflateRect=inflateRect,e.intersectRect=intersectRect,e.invert=invert,e.multiply=multiply,e.pointInPolygon=pointInPolygon,e.pointNearPolygon=pointNearPolygon,e.rectBottom=rectBottom,e.rectCenter=rectCenter,e.rectFromPoints=rectFromPoints,e.rectRight=rectRight,e.rectsIntersect=rectsIntersect,e.rotate=rotate,e.scale=scale,e.scaleOf=scaleOf,e.snapRect=snapRect,e.toCssMatrix=toCssMatrix,e.translate=translate,e.unionRect=unionRect,e})({});
|
|
1
|
+
var Atlas=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var AtlasError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},AtlasConfigError=class extends AtlasError{},t=Object.freeze([1,0,0,1,0,0]);function multiply(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}function apply(e,t){return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}function translate(e,t){return[1,0,0,1,e,t]}function scale(e,t=e){return[e,0,0,t,0,0]}function rotate(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,-n,t,0,0]}function around(e,t){return multiply(multiply(translate(e.x,e.y),t),translate(-e.x,-e.y))}function scaleOf(e){return(Math.hypot(e[0],e[1])+Math.hypot(e[2],e[3]))/2}function toCssMatrix(e){return`matrix(${e.join(`,`)})`}function invert(e){let t=e[0]*e[3]-e[2]*e[1];if(!Number.isFinite(t)||t===0)return null;let n=1/t;return[e[3]*n,-e[1]*n,-e[2]*n,e[0]*n,(e[2]*e[5]-e[3]*e[4])*n,(e[1]*e[4]-e[0]*e[5])*n]}function rectFromPoints(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e)a=!0,o.x<t&&(t=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return a?{height:i-n,width:r-t,x:t,y:n}:null}function rectRight(e){return e.x+e.width}function rectBottom(e){return e.y+e.height}function rectCenter(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function unionRect(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(rectBottom(e),rectBottom(t))-r,width:Math.max(rectRight(e),rectRight(t))-n,x:n,y:r}}function intersectRect(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(rectRight(e),rectRight(t)),a=Math.min(rectBottom(e),rectBottom(t));return i<n||a<r?null:{height:a-r,width:i-n,x:n,y:r}}function containsRect(e,t){return e.x<=t.x&&e.y<=t.y&&rectRight(e)>=rectRight(t)&&rectBottom(e)>=rectBottom(t)}function containsPoint(e,t){return t.x>=e.x&&t.x<=rectRight(e)&&t.y>=e.y&&t.y<=rectBottom(e)}function inflateRect(e,t){return{height:e.height+t*2,width:e.width+t*2,x:e.x-t,y:e.y-t}}function rectsIntersect(e,t){return intersectRect(e,t)!==null}var n={cancelFrame:e=>cancelAnimationFrame(e),now:()=>performance.now(),requestFrame:e=>requestAnimationFrame(e)};function assertFinite$1(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function easeInOut(e){return e<.5?2*e*e:1-(-2*e+2)**2/2}function normalizeAngle(e){return((e+Math.PI)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)-Math.PI}function shortestAngle(e,t){return normalizeAngle(t-e)}function screenDeltaToWorld(e,t,n){return apply(multiply(rotate(-n),scale(1/t)),e)}function matrixOf(e,t){let n=multiply(multiply(scale(e.zoom),rotate(e.rotation)),translate(-e.x,-e.y));return multiply(translate(t.width/2,t.height/2),n)}function inverseOf(e,t){let n=multiply(rotate(-e.rotation),scale(1/e.zoom)),r=screenDeltaToWorld({x:t.width/2,y:t.height/2},e.zoom,e.rotation);return multiply(translate(e.x-r.x,e.y-r.y),n)}function createCamera(e={}){let t=e.minZoom??.01,r=e.maxZoom??1e3;if(!(t>0&&t<=r))throw new AtlasConfigError(`Zoom clamps must satisfy 0 < minZoom <= maxZoom, received ${t} and ${r}`);let i=e.scheduler??n,a=e.initial??{},o=e.viewport??{height:0,width:0},s={rotation:normalizeAngle(a.rotation??0),x:a.x??0,y:a.y??0,zoom:Math.min(r,Math.max(t,a.zoom??1))};for(let[e,t]of[[`camera.x`,s.x],[`camera.y`,s.y],[`camera.rotation`,s.rotation]])assertFinite$1(e,t);let c=new AbortController,l=!1,u=null,d=new Set,f=null,p=null,matrix=()=>(f??=matrixOf(s,o),f),inverse=()=>(p??=inverseOf(s,o),p),invalidate=()=>{f=null,p=null},relativeToCentre=e=>({x:e.x-o.width/2,y:e.y-o.height/2}),emit=()=>{for(let e of[...d])e(s)},set=e=>{if(l)return;let n={rotation:normalizeAngle(e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(t,e.zoom??s.zoom))};(n.x!==s.x||n.y!==s.y||n.zoom!==s.zoom||n.rotation!==s.rotation)&&(s=n,invalidate(),emit())},stop=()=>{u&&=(i.cancelFrame(u.frame),u.cleanup(),null)},dispose=()=>{l||(l=!0,stop(),d.clear(),c.abort())},animateTo=(e,n={})=>{if(stop(),l)return;let a=n.duration??250,o=n.easing??easeInOut,c=n.signal;if(c?.aborted)return;if(a<=0){set(e);return}let d=s,f={rotation:d.rotation+shortestAngle(d.rotation,e.rotation??s.rotation),x:e.x??s.x,y:e.y??s.y,zoom:Math.min(r,Math.max(t,e.zoom??s.zoom))},p=i.now(),m=Math.log(d.zoom),h=Math.log(f.zoom),g={cleanup:()=>{},frame:0};u=g;let abort=()=>{u===g&&stop()};c&&(c.addEventListener(`abort`,abort,{once:!0}),g.cleanup=()=>c.removeEventListener(`abort`,abort));let step=e=>{if(u!==g)return;let t=Math.min(1,(e-p)/a),n=o(t);set({rotation:d.rotation+(f.rotation-d.rotation)*n,x:d.x+(f.x-d.x)*n,y:d.y+(f.y-d.y)*n,zoom:Math.exp(m+(h-m)*n)}),t>=1?(u=null,g.cleanup()):g.frame=i.requestFrame(step)};g.frame=i.requestFrame(step)};return{animateTo,get disposalSignal(){return c.signal},dispose,get disposed(){return l},fitBounds(e,n={}){if(l)return;stop();let i=n.padding??0,a=Math.max(1,o.width-i*2),s=Math.max(1,o.height-i*2),c=Math.min(r,Math.max(t,Math.min(e.width===0?r:a/e.width,e.height===0?r:s/e.height)));set({x:e.x+e.width/2,y:e.y+e.height/2,zoom:c})},get inverse(){return inverse()},get matrix(){return matrix()},panBy(e,t){if(l)return;stop();let n=screenDeltaToWorld({x:e,y:t},s.zoom,s.rotation);set({x:s.x-n.x,y:s.y-n.y})},resize(e){l||(e.width!==o.width||e.height!==o.height)&&(o={height:e.height,width:e.width},invalidate(),emit())},rotateAt(e,t){if(l)return;stop();let n=apply(inverse(),e),r=s.rotation+t,i=screenDeltaToWorld(relativeToCentre(e),s.zoom,r);set({rotation:r,x:n.x-i.x,y:n.y-i.y})},set(e){stop(),set(e)},[Symbol.dispose]:dispose,get state(){return s},stop,subscribe(e,t){return l||t?.signal?.aborted?()=>{}:(d.add(e),t?.signal?.addEventListener(`abort`,()=>d.delete(e),{once:!0}),()=>d.delete(e))},toScreen(e){return apply(matrix(),e)},toWorld(e){return apply(inverse(),e)},get viewport(){return o},get visibleRect(){let e=inverse();return rectFromPoints([apply(e,{x:0,y:0}),apply(e,{x:o.width,y:0}),apply(e,{x:0,y:o.height}),apply(e,{x:o.width,y:o.height})])},zoomAt(e,n){if(!Number.isFinite(n)||n<=0)throw new AtlasConfigError(`zoomAt factor must be a positive finite number, received ${n}`);if(l)return;stop();let i=apply(inverse(),e),a=Math.min(r,Math.max(t,s.zoom*n)),o=screenDeltaToWorld(relativeToCentre(e),a,s.rotation);set({x:i.x-o.x,y:i.y-o.y,zoom:a})}}}var r=new Set([`e`,`n`,`ne`,`nw`,`s`,`se`,`sw`,`w`]);function assertFinite(e,t){if(!Number.isFinite(t))throw new AtlasConfigError(`${e} must be a finite number, received ${t}`)}function frameMatrix(e){assertFinite(`frame.x`,e.x),assertFinite(`frame.y`,e.y);let t=e.rotation??0;assertFinite(`frame.rotation`,t);let n=e.scale??1,r=typeof n==`number`?n:n.x??1,i=typeof n==`number`?n:n.y??r;assertFinite(`frame.scale`,r),assertFinite(`frame.scale`,i);let a=e.origin??{x:e.x,y:e.y};return assertFinite(`frame.origin.x`,a.x),assertFinite(`frame.origin.y`,a.y),multiply(around(a,multiply(rotate(t),scale(r,i))),translate(e.x,e.y))}function boundsOfFrame(e,t){assertFiniteRect(e);for(let e=0;e<6;e++)assertFinite(`matrix[${e}]`,t[e]);return rectFromPoints([apply(t,{x:e.x,y:e.y}),apply(t,{x:rectRight(e),y:e.y}),apply(t,{x:e.x,y:rectBottom(e)}),apply(t,{x:rectRight(e),y:rectBottom(e)})])}function assertFiniteRect(e){assertFinite(`rect.x`,e.x),assertFinite(`rect.y`,e.y),assertFinite(`rect.width`,e.width),assertFinite(`rect.height`,e.height)}function resizeRect(e,t,n,i={}){if(assertFiniteRect(e),assertFinite(`point.x`,n.x),assertFinite(`point.y`,n.y),!r.has(t))throw new AtlasConfigError(`unknown resize edges: ${String(t)}. Expected one of ${[...r].join(`, `)}.`);let a=i.min??0;if(assertFinite(`min`,a),a<0)throw new AtlasConfigError(`min must be non-negative, received ${a}`);let o=i.aspect;if(o!==void 0&&(assertFinite(`aspect`,o),o<=0))throw new AtlasConfigError(`aspect must be positive, received ${o}`);let s=t.includes(`w`),c=t.includes(`e`),l=t.includes(`n`),u=t.includes(`s`),d=e.x,f=rectRight(e),p=e.y,m=rectBottom(e);if(s&&(d=Math.min(n.x,f-a)),c&&(f=Math.max(n.x,d+a)),l&&(p=Math.min(n.y,m-a)),u&&(m=Math.max(n.y,p+a)),o!==void 0){let t=Math.max(a,a*o),n=f-d,r=m-p,i=s||c,h=l||u,applyWidth=e=>{s?d=f-e:f=d+e},applyHeight=e=>{l?p=m-e:m=p+e};if(i&&h)Math.max(Math.abs(f-rectRight(e)),Math.abs(d-e.x))>=Math.max(Math.abs(m-rectBottom(e)),Math.abs(p-e.y))?(applyWidth(Math.max(n,t)),applyHeight((f-d)/o)):(applyHeight(Math.max(r,t/o)),applyWidth((m-p)*o));else if(i){let r=Math.max(n,t);applyWidth(r);let i=r/o,a=e.y+e.height/2;p=a-i/2,m=a+i/2}else{let n=Math.max(r,t/o);applyHeight(n);let i=n*o,a=e.x+e.width/2;d=a-i/2,f=a+i/2}}return{height:m-p,width:f-d,x:d,y:p}}function pointInPolygon(e,t){let n=!1,r=e.length;for(let i=0,a=r-1;i<r;a=i++){let r=e[i],o=e[a];if(r.y>t.y==o.y>t.y)continue;let s=(o.x-r.x)*(t.y-r.y)/(o.y-r.y)+r.x;t.x<s&&(n=!n)}return n}function distanceToSegment(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*r+(e.y-t.y)*i)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function distanceToPolyline(e,t){if(e.length===0)return 1/0;if(e.length===1)return Math.hypot(t.x-e[0].x,t.y-e[0].y);let n=1/0;for(let r=0,i=1;i<e.length;r=i++){let a=distanceToSegment(t,e[r],e[i]);a<n&&(n=a)}return n}function pointNearPolygon(e,t,n){if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number; received ${String(n)}.`);return distanceToPolyline(e.length>0?[...e,e[0]]:e,t)<=n||pointInPolygon(e,t)}function xAnchors(e){return[e.x,e.x+e.width/2,rectRight(e)]}function yAnchors(e){return[e.y,e.y+e.height/2,rectBottom(e)]}function bestAxisSnap(e,t,n){let r=null;for(let i of e)for(let e of t){let t=e.value-i;Math.abs(t)>n||(r===null||Math.abs(t)<Math.abs(r.delta))&&(r={delta:t,kind:e.kind,position:e.value})}return r}function gridTargets(e,t,n,r){if(n===void 0||!Number.isFinite(n)||n<=0)return[];let i=[];for(let a=Math.floor((e-r)/n)*n;a<=t+r;a+=n)i.push({kind:`grid`,value:a});return i}function spanFor(e,t,n,r){let i=[];for(let t of n)(r===`x`?xAnchors(t):yAnchors(t)).some(t=>t===e)&&i.push(t);let a=rectFromPoints([t,...i].flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]))??{height:0,width:0,x:e,y:e};return r===`x`?{from:a.y,to:rectBottom(a)}:{from:a.x,to:rectRight(a)}}function overlapsPerpendicular(e,t,n){return n===`x`?e.y<rectBottom(t)&&t.y<rectBottom(e):e.x<rectRight(t)&&t.x<rectRight(e)}function axisSpacingSnap(e,t,n,r){let i=n===`x`?e=>e.x:e=>e.y,a=n===`x`?e=>rectRight(e):e=>rectBottom(e),o=-1/0,s=1/0;for(let r of t)overlapsPerpendicular(e,r,n)&&(a(r)<=i(e)&&a(r)>o&&(o=a(r)),i(r)>=a(e)&&i(r)<s&&(s=i(r)));if(o===-1/0||s===1/0)return null;let c=s-o-(n===`x`?e.width:e.height);if(c<0)return null;let l=o+c/2-i(e);if(Math.abs(l)>r)return null;let u=c/2;return{delta:l,marks:[o+u/2,s-u/2],position:n===`x`?rectCenter(e).y:rectCenter(e).x,span:[o,s]}}function snapRect(e,t){let{candidates:n,grid:r,spacing:i,threshold:a}=t;if(!(a>=0))throw new AtlasConfigError(`threshold must be a non-negative finite number; received ${String(a)}.`);let o=e.x,s=e.y,c={x:0,y:0},l=n.flatMap(e=>xAnchors(e).map(e=>({kind:`object`,value:e})));l.push(...gridTargets(e.x,rectRight(e),r?.x,a));let u=bestAxisSnap(xAnchors(e),l,a);u!==null&&(c.x=u.delta,o+=u.delta);let d=n.flatMap(e=>yAnchors(e).map(e=>({kind:`object`,value:e})));d.push(...gridTargets(e.y,rectBottom(e),r?.y,a));let f=bestAxisSnap(yAnchors(e),d,a);f!==null&&(c.y=f.delta,s+=f.delta);let p={...e,x:o,y:s},m=[];if(u!==null){let e=spanFor(u.position,p,n,`x`);m.push({axis:`x`,from:e.from,kind:u.kind,position:u.position,to:e.to})}if(f!==null){let e=spanFor(f.position,p,n,`y`);m.push({axis:`y`,from:e.from,kind:f.kind,position:f.position,to:e.to})}if(i){if(u===null){let e=axisSpacingSnap(p,n,`x`,a);e!==null&&(c.x=e.delta,m.push({axis:`y`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}if(f===null){let e=axisSpacingSnap(p,n,`y`,a);e!==null&&(c.y=e.delta,m.push({axis:`x`,from:e.span[0],kind:`spacing`,marks:e.marks,position:e.position,to:e.span[1]}))}}return{delta:c,guides:m}}function alignRects(e,t){if(e.length===0)return[];let n=rectFromPoints(e.flatMap(e=>[{x:e.x,y:e.y},{x:rectRight(e),y:rectBottom(e)}]));return n===null?[]:e.map(e=>{switch(t){case`left`:return{...e,x:n.x};case`horizontal-center`:return{...e,x:rectCenter(n).x-e.width/2};case`right`:return{...e,x:rectRight(n)-e.width};case`top`:return{...e,y:n.y};case`vertical-center`:return{...e,y:rectCenter(n).y-e.height/2};case`bottom`:return{...e,y:rectBottom(n)-e.height};default:throw new AtlasConfigError(`unknown align edge: ${String(t)}.`)}})}function distributeRects(e,t){if(e.length<=2)return e.map(e=>({...e}));let n=t===`x`?e=>e.x:e=>e.y,r=t===`x`?e=>e.width:e=>e.height,i=e.map((e,t)=>({index:t,rect:e})).sort((e,t)=>n(e.rect)-n(t.rect)||e.index-t.index),a=i[0].rect,o=i[i.length-1].rect,s=(n(o)+r(o)-n(a)-i.reduce((e,t)=>e+r(t.rect),0))/(i.length-1),c=e.map(e=>({...e})),l=n(a);for(let e of i){let n={...e.rect};t===`x`?n.x=l:n.y=l,c[e.index]=n,l+=r(e.rect)+s}return c}function rectOf(e){return e.rect}function unionRects(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{height:Math.max(e.y+e.height,t.y+t.height)-r,width:Math.max(e.x+e.width,t.x+t.width)-n,x:n,y:r}}function area(e){return e.width*e.height}function rectsEqual(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function recompute(e){let t=null;for(let n of e.children)t=t===null?{...rectOf(n)}:unionRects(t,rectOf(n));e.rect=t}function createSpatialIndex(e={}){let t=e.maxEntriesPerNode??8;if(!Number.isInteger(t)||t<4)throw new AtlasConfigError(`maxEntriesPerNode must be an integer >= 4, received ${t}`);let n=Math.max(2,Math.ceil(t/3)),r=new Map,i={children:[],leaf:!0,rect:null},pickChild=(e,t)=>{let n=null,r=1/0,i=1/0;for(let a of e.children){let e=a.rect??t,o=area(unionRects(e,t))-area(e);(o<r||o===r&&area(e)<i)&&(n=a,r=o,i=area(e))}return n},split=e=>{let r=e.children,i=0,a=1,o=-1/0;for(let e=0;e<r.length;e++)for(let t=e+1;t<r.length;t++){let n=area(unionRects(rectOf(r[e]),rectOf(r[t])))-area(rectOf(r[e]))-area(rectOf(r[t]));n>o&&(o=n,i=e,a=t)}let s=[r[i]],c=[r[a]],l=rectOf(r[i]),u=rectOf(r[a]),d=r.filter((e,t)=>t!==i&&t!==a);for(let[e,r]of d.entries()){let i=s.length+(d.length-e)>t||c.length+(d.length-e)-1<n,a=c.length+(d.length-e)>t||s.length+(d.length-e)-1<n,o;if(i)o=!0;else if(a)o=!1;else{let e=area(unionRects(l,rectOf(r)))-area(l),t=area(unionRects(u,rectOf(r)))-area(u);o=e<t||e===t&&area(l)<=area(u)}o?(s.push(r),l=unionRects(l,rectOf(r))):(c.push(r),u=unionRects(u,rectOf(r)))}let f=e.leaf?{children:s,leaf:!0,rect:null}:{children:s,leaf:!1,rect:null},p=e.leaf?{children:c,leaf:!0,rect:null}:{children:c,leaf:!1,rect:null};return recompute(f),recompute(p),[f,p]},insertInto=(e,n)=>{if(e.leaf)return e.children.push(n),e.rect=e.rect===null?{...rectOf(n)}:unionRects(e.rect,rectOf(n)),e.children.length>t?split(e):null;let r=e,i=pickChild(r,rectOf(n)),a=insertInto(i,n);if(recompute(e),a){let t=r.children.indexOf(i);r.children.splice(t,1,a[0],a[1]),recompute(e)}return e.children.length>t?split(e):null},insertEntry=e=>{!i.leaf&&i.children.length===0&&(i={children:[],leaf:!0,rect:null});let t=insertInto(i,e);t&&(i={children:t,leaf:!1,rect:null},recompute(i))},removeFrom=(e,t)=>{if(e.leaf){let n=e.children.indexOf(t);return n!==-1&&e.children.splice(n,1),recompute(e),e.children.length===0}let n=e;for(let e=n.children.length-1;e>=0;e--){let r=n.children[e];r.rect&&containsRect(r.rect,t.rect)&&removeFrom(r,t)&&n.children.splice(e,1)}return recompute(e),n.children.length===0},deleteEntry=e=>{let t=r.get(e);if(!t)return!1;for(r.delete(e),removeFrom(i,t);!i.leaf&&i.children.length===1;)i=i.children[0];return!0},queryInto=(e,t,n)=>{if(e.rect&&t(e.rect)){if(e.leaf)for(let r of e.children)t(r.rect)&&n.push(r.id);else for(let r of e.children)queryInto(r,t,n)}};return{get bounds(){return i.rect},clear(){r.clear(),i={children:[],leaf:!0,rect:null}},delete:deleteEntry,get(e){return r.get(e)?.rect},has(e){return r.has(e)},queryPoint(e,t){let n=t?.tolerance??0;if(!(n>=0))throw new AtlasConfigError(`tolerance must be a non-negative finite number, received ${n}`);let r=inflateRect({...e,height:0,width:0},n),a=[];return queryInto(i,e=>rectsIntersect(e,r),a),a},queryRect(e){let t=[];return queryInto(i,t=>rectsIntersect(t,e),t),t},set(e,t){let n=r.get(e);if(n){if(rectsEqual(n.rect,t))return;deleteEntry(e)}let i={id:e,rect:{...t}};r.set(e,i),insertEntry(i)},get size(){return r.size}}}return e.AtlasConfigError=AtlasConfigError,e.AtlasError=AtlasError,e.IDENTITY=t,e.alignRects=alignRects,e.apply=apply,e.around=around,e.boundsOfFrame=boundsOfFrame,e.containsPoint=containsPoint,e.containsRect=containsRect,e.createCamera=createCamera,e.createSpatialIndex=createSpatialIndex,e.distanceToPolyline=distanceToPolyline,e.distributeRects=distributeRects,e.frameMatrix=frameMatrix,e.inflateRect=inflateRect,e.intersectRect=intersectRect,e.invert=invert,e.multiply=multiply,e.pointInPolygon=pointInPolygon,e.pointNearPolygon=pointNearPolygon,e.rectBottom=rectBottom,e.rectCenter=rectCenter,e.rectFromPoints=rectFromPoints,e.rectRight=rectRight,e.rectsIntersect=rectsIntersect,e.resizeRect=resizeRect,e.rotate=rotate,e.scale=scale,e.scaleOf=scaleOf,e.snapRect=snapRect,e.toCssMatrix=toCssMatrix,e.translate=translate,e.unionRect=unionRect,e})({});
|
|
2
2
|
//# sourceMappingURL=atlas.iife.js.map
|