@annotorious/annotorious 3.0.0-rc.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Annotorious.d.ts +7 -8
- package/dist/AnnotoriousOpts.d.ts +5 -7
- package/dist/annotation/SVGAnnotationLayer.svelte.d.ts +1 -1
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts +3 -3
- package/dist/annotation/Transform.d.ts +0 -1
- package/dist/annotation/editors/Editor.svelte.d.ts +1 -1
- package/dist/annotation/editors/EditorMount.svelte.d.ts +1 -1
- package/dist/annotation/editors/Handle.svelte.d.ts +1 -0
- package/dist/annotation/editors/editorsRegistry.d.ts +3 -4
- package/dist/annotation/editors/index.d.ts +1 -2
- package/dist/annotation/editors/polygon/PolygonEditor.svelte.d.ts +1 -1
- package/dist/annotation/editors/polygon/index.d.ts +0 -1
- package/dist/annotation/editors/rectangle/RectangleEditor.svelte.d.ts +1 -1
- package/dist/annotation/editors/rectangle/index.d.ts +0 -1
- package/dist/annotation/index.d.ts +0 -1
- package/dist/annotation/shapes/Ellipse.svelte.d.ts +1 -1
- package/dist/annotation/shapes/Polygon.svelte.d.ts +1 -1
- package/dist/annotation/shapes/Rectangle.svelte.d.ts +1 -1
- package/dist/annotation/shapes/index.d.ts +0 -1
- package/dist/annotation/tools/DrawingToolConfig.d.ts +1 -2
- package/dist/annotation/tools/ToolMount.svelte.d.ts +1 -1
- package/dist/annotation/tools/drawingToolsRegistry.d.ts +4 -5
- package/dist/annotation/tools/index.d.ts +0 -1
- package/dist/annotation/tools/polygon/RubberbandPolygon.svelte.d.ts +1 -1
- package/dist/annotation/tools/polygon/index.d.ts +0 -1
- package/dist/annotation/tools/rectangle/RubberbandRectangle.svelte.d.ts +1 -1
- package/dist/annotation/tools/rectangle/index.d.ts +0 -1
- package/dist/annotation/utils/index.d.ts +0 -1
- package/dist/annotation/utils/math.d.ts +0 -1
- package/dist/annotation/utils/responsive.d.ts +1 -2
- package/dist/annotation/utils/styling.d.ts +3 -4
- package/dist/annotation/utils/touch.d.ts +0 -1
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +2489 -2025
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +1 -1
- package/dist/annotorious.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/keyboardCommands.d.ts +2 -2
- package/dist/model/core/ImageAnnotation.d.ts +2 -3
- package/dist/model/core/Shape.d.ts +1 -2
- package/dist/model/core/ellipse/Ellipse.d.ts +1 -2
- package/dist/model/core/ellipse/ellipseUtils.d.ts +0 -1
- package/dist/model/core/ellipse/index.d.ts +0 -1
- package/dist/model/core/index.d.ts +0 -1
- package/dist/model/core/polygon/Polygon.d.ts +1 -2
- package/dist/model/core/polygon/index.d.ts +0 -1
- package/dist/model/core/polygon/polygonUtils.d.ts +0 -1
- package/dist/model/core/rectangle/Rectangle.d.ts +1 -2
- package/dist/model/core/rectangle/index.d.ts +0 -1
- package/dist/model/core/rectangle/rectangleUtils.d.ts +2 -3
- package/dist/model/core/shapeUtils.d.ts +2 -6
- package/dist/model/index.d.ts +0 -1
- package/dist/model/w3c/W3CImageAnnotation.d.ts +10 -0
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts +11 -7
- package/dist/model/w3c/fragment/FragmentSelector.d.ts +2 -4
- package/dist/model/w3c/fragment/index.d.ts +0 -1
- package/dist/model/w3c/index.d.ts +1 -1
- package/dist/model/w3c/svg/SVG.d.ts +0 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts +2 -4
- package/dist/model/w3c/svg/index.d.ts +0 -1
- package/dist/state/ImageAnnotationStore.d.ts +2 -3
- package/dist/state/ImageAnnotatorState.d.ts +4 -5
- package/dist/state/index.d.ts +0 -1
- package/dist/state/spatialTree.d.ts +2 -3
- package/dist/themes/index.d.ts +0 -1
- package/dist/themes/smart/index.d.ts +0 -1
- package/dist/themes/smart/setTheme.d.ts +1 -2
- package/package.json +16 -19
- package/src/Annotorious.css +13 -5
- package/src/Annotorious.ts +33 -17
- package/src/AnnotoriousOpts.ts +12 -16
- package/src/annotation/SVGAnnotationLayer.svelte +68 -35
- package/src/annotation/SVGAnnotationLayerPointerEvent.ts +2 -3
- package/src/annotation/Transform.ts +1 -1
- package/src/annotation/editors/Editor.svelte +10 -11
- package/src/annotation/editors/EditorMount.svelte +3 -3
- package/src/annotation/editors/Handle.svelte +66 -0
- package/src/annotation/editors/editorsRegistry.ts +2 -2
- package/src/annotation/editors/index.ts +2 -2
- package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +46 -43
- package/src/annotation/shapes/Ellipse.svelte +4 -4
- package/src/annotation/shapes/Polygon.svelte +4 -4
- package/src/annotation/shapes/Rectangle.svelte +4 -4
- package/src/annotation/tools/ToolMount.svelte +3 -3
- package/src/annotation/tools/drawingToolsRegistry.ts +2 -1
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +36 -11
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +27 -11
- package/src/annotation/utils/responsive.ts +1 -1
- package/src/annotation/utils/styling.ts +18 -9
- package/src/annotation/utils/touch.ts +9 -1
- package/src/index.ts +1 -3
- package/src/keyboardCommands.ts +13 -5
- package/src/model/w3c/W3CImageAnnotation.ts +17 -0
- package/src/model/w3c/W3CImageFormatAdapter.ts +79 -32
- package/src/model/w3c/fragment/FragmentSelector.ts +5 -6
- package/src/model/w3c/index.ts +1 -0
- package/src/model/w3c/svg/SVG.ts +1 -2
- package/src/model/w3c/svg/SVGSelector.ts +11 -13
- package/src/state/ImageAnnotatorState.ts +5 -5
- package/src/state/spatialTree.ts +13 -6
- package/src/themes/dark/index.css +3 -3
- package/src/themes/light/index.css +2 -2
- package/src/themes/smart/setTheme.ts +2 -2
- package/dist/Annotorious.d.ts.map +0 -1
- package/dist/AnnotoriousOpts.d.ts.map +0 -1
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +0 -1
- package/dist/annotation/Transform.d.ts.map +0 -1
- package/dist/annotation/editors/Handle.d.ts +0 -14
- package/dist/annotation/editors/Handle.d.ts.map +0 -1
- package/dist/annotation/editors/editorsRegistry.d.ts.map +0 -1
- package/dist/annotation/editors/index.d.ts.map +0 -1
- package/dist/annotation/editors/polygon/index.d.ts.map +0 -1
- package/dist/annotation/editors/rectangle/index.d.ts.map +0 -1
- package/dist/annotation/index.d.ts.map +0 -1
- package/dist/annotation/shapes/index.d.ts.map +0 -1
- package/dist/annotation/tools/DrawingToolConfig.d.ts.map +0 -1
- package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +0 -1
- package/dist/annotation/tools/index.d.ts.map +0 -1
- package/dist/annotation/tools/polygon/index.d.ts.map +0 -1
- package/dist/annotation/tools/rectangle/index.d.ts.map +0 -1
- package/dist/annotation/utils/index.d.ts.map +0 -1
- package/dist/annotation/utils/math.d.ts.map +0 -1
- package/dist/annotation/utils/responsive.d.ts.map +0 -1
- package/dist/annotation/utils/styling.d.ts.map +0 -1
- package/dist/annotation/utils/touch.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/keyboardCommands.d.ts.map +0 -1
- package/dist/model/core/ImageAnnotation.d.ts.map +0 -1
- package/dist/model/core/Shape.d.ts.map +0 -1
- package/dist/model/core/ellipse/Ellipse.d.ts.map +0 -1
- package/dist/model/core/ellipse/ellipseUtils.d.ts.map +0 -1
- package/dist/model/core/ellipse/index.d.ts.map +0 -1
- package/dist/model/core/index.d.ts.map +0 -1
- package/dist/model/core/polygon/Polygon.d.ts.map +0 -1
- package/dist/model/core/polygon/index.d.ts.map +0 -1
- package/dist/model/core/polygon/polygonUtils.d.ts.map +0 -1
- package/dist/model/core/rectangle/Rectangle.d.ts.map +0 -1
- package/dist/model/core/rectangle/index.d.ts.map +0 -1
- package/dist/model/core/rectangle/rectangleUtils.d.ts.map +0 -1
- package/dist/model/core/shapeUtils.d.ts.map +0 -1
- package/dist/model/index.d.ts.map +0 -1
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +0 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +0 -1
- package/dist/model/w3c/fragment/index.d.ts.map +0 -1
- package/dist/model/w3c/index.d.ts.map +0 -1
- package/dist/model/w3c/svg/SVG.d.ts.map +0 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts.map +0 -1
- package/dist/model/w3c/svg/index.d.ts.map +0 -1
- package/dist/state/ImageAnnotationStore.d.ts.map +0 -1
- package/dist/state/ImageAnnotatorState.d.ts.map +0 -1
- package/dist/state/index.d.ts.map +0 -1
- package/dist/state/spatialTree.d.ts.map +0 -1
- package/dist/themes/index.d.ts.map +0 -1
- package/dist/themes/smart/index.d.ts.map +0 -1
- package/dist/themes/smart/setTheme.d.ts.map +0 -1
- package/src/annotation/editors/Handle.ts +0 -21
package/dist/annotorious.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(k,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(k=typeof globalThis<"u"?globalThis:k||self,G(k.Annotorious={}))})(this,function(k){"use strict";function G(){}function vn(e,t){for(const n in t)e[n]=t[n];return e}function gt(e){return e()}function pt(){return Object.create(null)}function oe(e){e.forEach(gt)}function W(e){return typeof e=="function"}function Z(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Ln(e){return Object.keys(e).length===0}function yt(e,...t){if(e==null)return G;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function _t(e,t,n){e.$$.on_destroy.push(yt(t,n))}function On(e,t,n,o){if(e){const i=wt(e,t,n,o);return e[0](i)}}function wt(e,t,n,o){return e[1]&&o?vn(n.ctx.slice(),e[1](o(t))):n.ctx}function In(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|i[a];return s}return t.dirty|i}return t.dirty}function kn(e,t,n,o,i,s){if(i){const r=wt(t,n,o,s);e.p(r,i)}}function Bn(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function le(e,t){e.appendChild(t)}function B(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function Je(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function X(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function bt(e){return document.createTextNode(e)}function ee(){return bt(" ")}function ie(){return bt("")}function q(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function f(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Pn(e){return Array.from(e.childNodes)}function Et(e,t,n){e.classList[n?"add":"remove"](t)}function Yn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,o,t),i}let ve;function Le(e){ve=e}function At(){if(!ve)throw new Error("Function called outside component initialization");return ve}function Oe(e){At().$$.on_mount.push(e)}function ge(){const e=At();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Yn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function pe(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const ye=[],Re=[];let _e=[];const Tt=[],Rn=Promise.resolve();let Ze=!1;function Dn(){Ze||(Ze=!0,Rn.then(St))}function Qe(e){_e.push(e)}const xe=new Set;let we=0;function St(){if(we!==0)return;const e=ve;do{try{for(;we<ye.length;){const t=ye[we];we++,Le(t),Cn(t.$$)}}catch(t){throw ye.length=0,we=0,t}for(Le(null),ye.length=0,we=0;Re.length;)Re.pop()();for(let t=0;t<_e.length;t+=1){const n=_e[t];xe.has(n)||(xe.add(n),n())}_e.length=0}while(ye.length);for(;Tt.length;)Tt.pop()();Ze=!1,xe.clear(),Le(e)}function Cn(e){if(e.fragment!==null){e.update(),oe(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Qe)}}function Xn(e){const t=[],n=[];_e.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),_e=t}const De=new Set;let ue;function se(){ue={r:0,c:[],p:ue}}function re(){ue.r||oe(ue.c),ue=ue.p}function U(e,t){e&&e.i&&(De.delete(e),e.i(t))}function V(e,t,n,o){if(e&&e.o){if(De.has(e))return;De.add(e),ue.c.push(()=>{De.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function fe(e){e&&e.c()}function ae(e,t,n,o){const{fragment:i,after_update:s}=e.$$;i&&i.m(t,n),o||Qe(()=>{const r=e.$$.on_mount.map(gt).filter(W);e.$$.on_destroy?e.$$.on_destroy.push(...r):oe(r),e.$$.on_mount=[]}),s.forEach(Qe)}function ce(e,t){const n=e.$$;n.fragment!==null&&(Xn(n.after_update),oe(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Un(e,t){e.$$.dirty[0]===-1&&(ye.push(e),Dn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function te(e,t,n,o,i,s,r,a=[-1]){const l=ve;Le(e);const c=e.$$={fragment:null,ctx:[],props:s,update:G,not_equal:i,bound:pt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:pt(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(c.root);let h=!1;if(c.ctx=n?n(e,t.props||{},(u,m,...d)=>{const g=d.length?d[0]:m;return c.ctx&&i(c.ctx[u],c.ctx[u]=g)&&(!c.skip_bound&&c.bound[u]&&c.bound[u](g),h&&Un(e,u)),m}):[],c.update(),h=!0,oe(c.before_update),c.fragment=o?o(c.ctx):!1,t.target){if(t.hydrate){const u=Pn(t.target);c.fragment&&c.fragment.l(u),u.forEach(I)}else c.fragment&&c.fragment.c();t.intro&&U(e.$$.fragment),ae(e,t.target,t.anchor,t.customElement),St()}Le(l)}class ne{$destroy(){ce(this,1),this.$destroy=G}$on(t,n){if(!W(n))return G;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!Ln(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}var z=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(z||{});const $e={},Ce=(e,t)=>$e[e]=t,Xe=e=>$e[e.type].area(e),Mt=(e,t,n)=>$e[e.type].intersects(e,t,n),Ie=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Nn={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),c=Math.sin(a),h=t-o,u=n-i,m=l*h+c*u,d=c*h-l*u;return m*m/(s*s)+d*d/(r*r)<=1}};Ce(z.ELLIPSE,Nn);const Vn={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let s=0,r=o.length-1;s<o.length;r=s++){const a=o[s][0],l=o[s][1],c=o[r][0],h=o[r][1];l>n!=h>n&&t<(c-a)*(n-l)/(h-l)+a&&(i=!i)}return i}};Ce(z.POLYGON,Vn);const vt={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};Ce(z.RECTANGLE,vt);const Lt=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,a,l,c,h,u]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[m,d,g,_]=[l,c,h,u].map(parseFloat);return{type:z.RECTANGLE,geometry:{x:m,y:d,w:g,h:_,bounds:{minX:m,minY:t?d-_:d,maxX:m+g,maxY:t?d:d+_}}}},Ot=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},It="http://www.w3.org/2000/svg",kt=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},Gn=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${It}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},Fn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(It),i=n.lookupNamespaceURI(null);return o||i?kt(n).firstChild:kt(Gn(n)).firstChild},Hn=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[];if(!o)return;const i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:z.POLYGON,geometry:{points:i,bounds:Ie(i)}}},zn=e=>{const t=Fn(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:z.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Bt=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Hn(t);if(t.includes("<ellipse "))return zn(t)},Pt=e=>{let t;if(e.type===z.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===z.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};let Ue;const jn=new Uint8Array(16);function Wn(){if(!Ue&&(Ue=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ue))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ue(jn)}const K=[];for(let e=0;e<256;++e)K.push((e+256).toString(16).slice(1));function qn(e,t=0){return K[e[t+0]]+K[e[t+1]]+K[e[t+2]]+K[e[t+3]]+"-"+K[e[t+4]]+K[e[t+5]]+"-"+K[e[t+6]]+K[e[t+7]]+"-"+K[e[t+8]]+K[e[t+9]]+"-"+K[e[t+10]]+K[e[t+11]]+K[e[t+12]]+K[e[t+13]]+K[e[t+14]]+K[e[t+15]]}const Yt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Rt(e,t,n){if(Yt.randomUUID&&!t&&!e)return Yt.randomUUID();e=e||{};const o=e.random||(e.rng||Wn)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=o[i];return t}return qn(o)}var Dt=Object.prototype.hasOwnProperty;function de(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&de(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Dt.call(e,n)&&++o&&!Dt.call(t,n)||!(n in t)||!de(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function et(){}function Kn(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const be=[];function tt(e,t=et){let n;const o=new Set;function i(a){if(Kn(e,a)&&(e=a,n)){const l=!be.length;for(const c of o)c[1](),be.push(c,e);if(l){for(let c=0;c<be.length;c+=2)be[c][0](be[c+1]);be.length=0}}}function s(a){i(a(e))}function r(a,l=et){const c=[a,l];return o.add(c),o.size===1&&(n=t(i)||et),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Jn=e=>{const{subscribe:t,set:n}=tt(null);let o=null;return t(i=>o=i),e.observe(({changes:i})=>{if(o){i.deleted.some(r=>r.id===o)&&n(null);const s=i.updated.find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Ct=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Ct||{});const nt={selected:[]},Zn=(e,t="EDIT")=>{const{subscribe:n,set:o}=tt(nt);let i=nt;n(u=>i=u);const s=()=>o(nt),r=()=>{var u;return((u=i.selected)==null?void 0:u.length)===0},a=u=>{if(i.selected.length===0)return!1;const m=typeof u=="string"?u:u.id;return i.selected.some(d=>d.id===m)},l=(u,m)=>{const d=e.getAnnotation(u);if(d){const g=Qn(d,t);o(g==="EDIT"?{selected:[{id:u,editable:!0}],pointerEvent:m}:g==="SELECT"?{selected:[{id:u}],pointerEvent:m}:{selected:[],pointerEvent:m})}else console.warn("Invalid selection: "+u)},c=(u,m=!0)=>{const d=Array.isArray(u)?u:[u],g=d.map(_=>e.getAnnotation(_)).filter(_=>_);o({selected:g.map(({id:_})=>({id:_,editable:m}))}),g.length!==d.length&&console.warn("Invalid selection",u)},h=u=>{if(i.selected.length===0)return!1;const{selected:m}=i;m.filter(({id:d})=>u.includes(d)).length>0&&o({selected:m.filter(({id:d})=>!u.includes(d))})};return e.observe(({changes:u})=>h(u.deleted.map(m=>m.id))),{clear:s,clickSelect:l,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:a,setSelected:c,subscribe:n}},Qn=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT",xn=[];for(let e=0;e<256;++e)xn.push((e+256).toString(16).slice(1));typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const $n=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},eo=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},to=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!de(o,n)?o:void 0}}).filter(({oldBody:n})=>n),no=(e,t)=>!de(e.target,t.target),Xt=(e,t)=>{const n=$n(e,t),o=eo(e,t),i=to(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:no(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var F=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(F||{});const oo=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(!e.options.origin||e.options.origin===s))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>(l==null?void 0:l.length)>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!l)return!1}}if(e.options.annotations){const r=new Set([...i.created.map(a=>a.id),...i.deleted.map(a=>a.id),...i.updated.map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},io=(e,t)=>{const n=new Set((e.created||[]).map(u=>u.id)),o=new Set((e.updated||[]).map(({newValue:u})=>u.id)),i=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),r=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(e.created||[]).filter(u=>!s.has(u.id)).map(u=>r.has(u.id)?t.updated.find(({oldValue:m})=>m.id===u.id).newValue:u),...t.created||[]],c=[...(e.deleted||[]).filter(u=>!i.has(u.id)),...(t.deleted||[]).filter(u=>!n.has(u.id))],h=[...(e.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:m,newValue:d}=u;if(r.has(d.id)){const g=t.updated.find(_=>_.oldValue.id===d.id).newValue;return Xt(m,g)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:c,updated:h}},so=e=>e.id!==void 0,ro=()=>{const e=new Map,t=new Map,n=[],o=(p,E={})=>n.push({onChange:p,options:E}),i=p=>{const E=n.findIndex(b=>b.onChange==p);E>-1&&n.splice(E,1)},s=(p,E)=>{const b={origin:p,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...e.values()]};n.forEach(v=>{oo(v,b)&&v.onChange(b)})},r=(p,E=F.LOCAL)=>{if(e.get(p.id))throw Error(`Cannot add annotation ${p.id} - exists already`);e.set(p.id,p),p.bodies.forEach(b=>t.set(b.id,p.id)),s(E,{created:[p]})},a=(p,E)=>{const b=typeof p=="string"?E:p,v=typeof p=="string"?p:p.id,P=e.get(v);if(P){const C=Xt(P,b);return v===b.id?e.set(v,b):(e.delete(v),e.set(b.id,b)),P.bodies.forEach(Q=>t.delete(Q.id)),b.bodies.forEach(Q=>t.set(Q.id,b.id)),C}else console.warn(`Cannot update annotation ${v} - does not exist`)},l=(p,E=F.LOCAL,b=F.LOCAL)=>{const v=so(E)?b:E,P=a(p,E);P&&s(v,{updated:[P]})},c=(p,E=F.LOCAL)=>{const b=p.reduce((v,P)=>{const C=a(P);return C?[...v,C]:v},[]);b.length>0&&s(E,{updated:b})},h=(p,E=F.LOCAL)=>{const b=e.get(p.annotation);if(b){const v={...b,bodies:[...b.bodies,p]};e.set(b.id,v),t.set(p.id,v.id),s(E,{updated:[{oldValue:b,newValue:v,bodiesCreated:[p]}]})}else console.warn(`Attempt to add body to missing annotation: ${p.annotation}`)},u=()=>[...e.values()],m=(p=F.LOCAL)=>{const E=[...e.values()];e.clear(),t.clear(),s(p,{deleted:E})},d=(p,E=!0,b=F.LOCAL)=>{if(E){const v=[...e.values()];e.clear(),t.clear(),p.forEach(P=>{e.set(P.id,P),P.bodies.forEach(C=>t.set(C.id,P.id))}),s(b,{created:p,deleted:v})}else{const v=p.reduce((P,C)=>{const Q=e.get(C.id);return Q?[...P,Q]:P},[]);if(v.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${v.map(P=>P.id).join(", ")}`);p.forEach(P=>{e.set(P.id,P),P.bodies.forEach(C=>t.set(C.id,P.id))}),s(b,{created:p})}},g=p=>{const E=typeof p=="string"?p:p.id,b=e.get(E);if(b)return e.delete(E),b.bodies.forEach(v=>t.delete(v.id)),b;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(p,E=F.LOCAL)=>{const b=g(p);b&&s(E,{deleted:[b]})},A=(p,E=F.LOCAL)=>{const b=p.reduce((v,P)=>{const C=g(P);return C?[...v,C]:v},[]);b.length>0&&s(E,{deleted:b})},w=(p,E=F.LOCAL)=>{const b=e.get(p.annotation);if(b){const v=b.bodies.find(P=>P.id===p.id);if(v){t.delete(v.id);const P={...b,bodies:b.bodies.filter(C=>C.id!==p.id)};e.set(b.id,P),s(E,{updated:[{oldValue:b,newValue:P,bodiesDeleted:[v]}]})}else console.warn(`Attempt to delete missing body ${p.id} from annotation ${p.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${p.annotation}`)},y=p=>{const E=e.get(p);return E?{...E}:void 0},T=p=>{const E=t.get(p);if(E){const b=y(E).bodies.find(v=>v.id===p);if(b)return b;console.error(`Store integrity error: body ${p} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${p}`)},S=(p,E)=>{if(p.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const b=e.get(p.annotation);if(b){const v=b.bodies.find(C=>C.id===p.id),P={...b,bodies:b.bodies.map(C=>C.id===v.id?E:C)};return e.set(b.id,P),v.id!==E.id&&(t.delete(v.id),t.set(E.id,P.id)),{oldValue:b,newValue:P,bodiesUpdated:[{oldBody:v,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${p.annotation}`)},Y=(p,E,b=F.LOCAL)=>{const v=S(p,E);s(b,{updated:[v]})},D=(p,E=F.LOCAL)=>{const b=p.map(v=>S({id:v.id,annotation:v.annotation},v));s(E,{updated:b})},N=p=>{const E=e.get(p.annotation);if(E){const b={...E,target:{...E.target,...p}};return e.set(E.id,b),{oldValue:E,newValue:b,targetUpdated:{oldTarget:E.target,newTarget:p}}}else console.warn(`Attempt to update target on missing annotation: ${p.annotation}`)};return{addAnnotation:r,addBody:h,all:u,bulkAddAnnotation:d,bulkDeleteAnnotation:A,bulkUpdateAnnotation:c,bulkUpdateBodies:D,bulkUpdateTargets:(p,E=F.LOCAL)=>{const b=p.map(N).filter(v=>v);b.length>0&&s(E,{updated:b})},clear:m,deleteAnnotation:_,deleteBody:w,getAnnotation:y,getBody:T,observe:o,unobserve:i,updateAnnotation:l,updateBody:Y,updateTarget:(p,E=F.LOCAL)=>{const b=N(p);b&&s(E,{updated:[b]})}}},lo=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ao=()=>({emit(e,...t){let n=this.events[e]||[];for(let o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return(n=this.events[e])!=null&&n.push(t)||(this.events[e]=[t]),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const co=250,uo=e=>{const t=ao(),n=[];let o=-1,i=!1,s=0;const r=d=>{if(!i){const{changes:g}=d,_=performance.now();if(_-s>co)n.splice(o+1),n.push(g),o=n.length-1;else{const A=n.length-1;n[A]=io(n[A],g)}s=_}i=!1};e.observe(r,{origin:F.LOCAL});const a=d=>(d==null?void 0:d.length)>0&&e.bulkDeleteAnnotation(d),l=d=>(d==null?void 0:d.length)>0&&e.bulkAddAnnotation(d,!1),c=d=>(d==null?void 0:d.length)>0&&e.bulkUpdateAnnotation(d.map(({oldValue:g})=>g)),h=d=>(d==null?void 0:d.length)>0&&e.bulkUpdateAnnotation(d.map(({newValue:g})=>g)),u=d=>(d==null?void 0:d.length)>0&&e.bulkAddAnnotation(d,!1),m=d=>(d==null?void 0:d.length)>0&&e.bulkDeleteAnnotation(d);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(r),on:(d,g)=>t.on(d,g),redo:()=>{if(n.length-1>o){i=!0;const{created:d,updated:g,deleted:_}=n[o+1];l(d),h(g),m(_),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:d,updated:g,deleted:_}=n[o];a(d),c(g),u(_),t.emit("undo",n[o]),o-=1}}}},fo=()=>{const{subscribe:e,set:t}=tt([]);return{subscribe:e,set:t}},ho=(e,t,n,o)=>{const{store:i,selection:s,hover:r,viewport:a}=e,l=new Map;let c=[],h,u;const m=(w,y)=>{l.has(w)?l.get(w).push(y):l.set(w,[y])},d=(w,y)=>{const T=l.get(w);T&&T.indexOf(y)>0&&T.splice(T.indexOf(y),1)},g=(w,y,T)=>{l.has(w)&&setTimeout(()=>{l.get(w).forEach(S=>{if(n){const Y=Array.isArray(y)?y.map(N=>n.serialize(N)):n.serialize(y),D=T?T instanceof PointerEvent?T:n.serialize(T):void 0;S(Y,D)}else S(y,T)})},1)},_=()=>{const{selected:w}=s,y=w.map(({id:T})=>i.getAnnotation(T));y.forEach(T=>{const S=c.find(Y=>Y.id===T.id);(!S||!de(S,T))&&g("updateAnnotation",T,S)}),c=c.map(T=>y.find(({id:Y})=>Y===T.id)||T)};s.subscribe(({selected:w})=>{if(!(c.length===0&&w.length===0)){if(c.length===0&&w.length>0)c=w.map(({id:y})=>i.getAnnotation(y));else if(c.length>0&&w.length===0)c.forEach(y=>{const T=i.getAnnotation(y.id);T&&!de(T,y)&&g("updateAnnotation",T,y)}),c=[];else{const y=new Set(c.map(S=>S.id)),T=new Set(w.map(({id:S})=>S));c.filter(S=>!T.has(S.id)).forEach(S=>{const Y=i.getAnnotation(S.id);Y&&!de(Y,S)&&g("updateAnnotation",Y,S)}),c=[...c.filter(S=>T.has(S.id)),...w.filter(({id:S})=>!y.has(S)).map(({id:S})=>i.getAnnotation(S))]}g("selectionChanged",c)}}),r.subscribe(w=>{!h&&w?g("mouseEnterAnnotation",i.getAnnotation(w)):h&&!w?g("mouseLeaveAnnotation",i.getAnnotation(h)):h&&w&&(g("mouseLeaveAnnotation",i.getAnnotation(h)),g("mouseEnterAnnotation",i.getAnnotation(w))),h=w}),a==null||a.subscribe(w=>g("viewportIntersect",w.map(i.getAnnotation))),i.observe(w=>{o&&(u&&clearTimeout(u),u=setTimeout(_,1e3));const{created:y,deleted:T}=w.changes;y.forEach(S=>g("createAnnotation",S)),T.forEach(S=>g("deleteAnnotation",S)),w.changes.updated.filter(S=>[...S.bodiesCreated||[],...S.bodiesDeleted||[],...S.bodiesUpdated||[]].length>0).forEach(({oldValue:S,newValue:Y})=>{const D=c.find(N=>N.id===S.id)||S;c=c.map(N=>N.id===S.id?Y:N),g("updateAnnotation",Y,D)})},{origin:F.LOCAL}),i.observe(w=>{if(c){const y=new Set(c.map(S=>S.id)),T=w.changes.updated.filter(({newValue:S})=>y.has(S.id)).map(({newValue:S})=>S);T.length>0&&(c=c.map(S=>T.find(D=>D.id===S.id)||S))}},{origin:F.REMOTE});const A=w=>y=>{const{created:T,deleted:S,updated:Y}=y;T.forEach(D=>g("createAnnotation",D)),S.forEach(D=>g("deleteAnnotation",D)),w?Y.forEach(D=>g("updateAnnotation",D.oldValue,D.newValue)):Y.forEach(D=>g("updateAnnotation",D.newValue,D.oldValue))};return t.on("undo",A(!0)),t.on("redo",A(!1)),{on:m,off:d,emit:g}},mo=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:{parsed:[...n.parsed,i],failed:n.failed}},{parsed:[],failed:[]}),go=(e,t,n)=>{const{store:o,selection:i}=e,s=A=>{if(n){const{parsed:w,error:y}=n.parse(A);w?o.addAnnotation(w,F.REMOTE):console.error(y)}else o.addAnnotation(A,F.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=A=>{const w=o.getAnnotation(A);return n&&w?n.serialize(w):w},c=()=>n?o.all().map(n.serialize):o.all(),h=()=>{var A;const w=(((A=i.selected)==null?void 0:A.map(y=>y.id))||[]).map(y=>o.getAnnotation(y));return n?w.map(n.serialize):w},u=A=>fetch(A).then(w=>w.json()).then(w=>(d(w),w)),m=A=>{if(typeof A=="string"){const w=o.getAnnotation(A);return o.deleteAnnotation(A),n?n.serialize(w):w}else{const w=n?n.parse(A).parsed:A;return o.deleteAnnotation(w),A}},d=A=>{if(n){const{parsed:w,failed:y}=mo(n)(A);y.length>0&&console.warn(`Discarded ${y.length} invalid annotations`,y),o.bulkAddAnnotation(w,!0,F.REMOTE)}else o.bulkAddAnnotation(A,!0,F.REMOTE)},g=A=>{A?i.setSelected(A):i.clear()},_=A=>{if(n){const w=n.parse(A).parsed,y=n.serialize(o.getAnnotation(w.id));return o.updateAnnotation(w),y}else{const w=o.getAnnotation(A.id);return o.updateAnnotation(A),w}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getSelected:h,loadAnnotations:u,redo:t.redo,removeAnnotation:m,setAnnotations:d,setSelected:g,undo:t.undo,updateAnnotation:_}};let po=e=>crypto.getRandomValues(new Uint8Array(e)),yo=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(i),l=i;for(;l--;)if(r+=e[a[l]&o]||"",r.length===s)return r}}},_o=(e,t=21)=>yo(e,t,po),wo=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const bo=()=>({isGuest:!0,id:_o("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Eo=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Ao=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,creator:l,...c}=n;return{id:o||`temp-${Eo(n)}`,annotation:t,type:i,purpose:s,value:r,created:a,creator:l?typeof l=="object"?{...l}:l:void 0,...c}}),To=e=>e.map(t=>{var n;const o={...t};return delete o.annotation,(n=o.id)!=null&&n.startsWith("temp-")&&delete o.id,o});wo();const So=(e,t=!1)=>({parse:i=>Ut(i,t),serialize:i=>Nt(i,e)}),Ut=(e,t=!1)=>{const n=e.id||Rt(),{body:o,...i}=e,s=Ao(o,n),r=Array.isArray(e.target)?e.target[0]:e.target,a=Array.isArray(r.selector)?r.selector[0]:r.selector,l=a.type==="FragmentSelector"?Lt(a,t):a.type==="SvgSelector"?Bt(a):void 0;return l?{parsed:{...i,id:n,bodies:s,target:{...i.target,annotation:n,selector:l}}}:{error:Error(`Unknown selector type: ${a.type}`)}},Nt=(e,t)=>{const n=e.target.selector,o=n.type==z.RECTANGLE?Ot(n.geometry):Pt(n);return{...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:To(e.bodies),target:{source:t,selector:o}}};function Vt(e,t,n){const o=e.slice();return o[11]=t[n],o[13]=n,o}function Gt(e){let t,n,o,i,s;return{c(){t=X("rect"),f(t,"class","a9s-corner-handle"),f(t,"x",n=e[11][0]-e[3]/2),f(t,"y",o=e[11][1]-e[3]/2),f(t,"height",e[3]),f(t,"width",e[3])},m(r,a){B(r,t,a),i||(s=q(t,"pointerdown",function(){W(e[10](L(e[13])))&&e[10](L(e[13])).apply(this,arguments)}),i=!0)},p(r,a){e=r,a&24&&n!==(n=e[11][0]-e[3]/2)&&f(t,"x",n),a&24&&o!==(o=e[11][1]-e[3]/2)&&f(t,"y",o),a&8&&f(t,"height",e[3]),a&8&&f(t,"width",e[3])},d(r){r&&I(t),i=!1,s()}}}function Mo(e){let t,n,o,i,s,r,a,l,c,h,u=e[4].points,m=[];for(let d=0;d<u.length;d+=1)m[d]=Gt(Vt(e,u,d));return{c(){t=X("polygon"),i=ee(),s=X("polygon"),a=ee();for(let d=0;d<m.length;d+=1)m[d].c();l=ie(),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"points",o=e[4].points.map(Ft).join(" ")),f(s,"class","a9s-inner a9s-shape-handle"),f(s,"style",e[1]),f(s,"points",r=e[4].points.map(Ht).join(" "))},m(d,g){B(d,t,g),B(d,i,g),B(d,s,g),B(d,a,g);for(let _=0;_<m.length;_+=1)m[_]&&m[_].m(d,g);B(d,l,g),c||(h=[q(t,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(s,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)})],c=!0)},p(d,g){if(e=d,g&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),g&16&&o!==(o=e[4].points.map(Ft).join(" "))&&f(t,"points",o),g&2&&f(s,"style",e[1]),g&16&&r!==(r=e[4].points.map(Ht).join(" "))&&f(s,"points",r),g&1048){u=e[4].points;let _;for(_=0;_<u.length;_+=1){const A=Vt(e,u,_);m[_]?m[_].p(A,g):(m[_]=Gt(A),m[_].c(),m[_].m(l.parentNode,l))}for(;_<m.length;_+=1)m[_].d(1);m.length=u.length}},d(d){d&&I(t),d&&I(i),d&&I(s),d&&I(a),Je(m,d),d&&I(l),c=!1,oe(h)}}}function vo(e){let t,n;return t=new it({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Mo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("change",e[7]),t.$on("grab",e[8]),t.$on("release",e[9]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&17434&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}const Ft=e=>e.join(","),Ht=e=>e.join(",");function Lo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const c=(d,g,_)=>{let A;g===L.SHAPE?A=d.geometry.points.map(([y,T])=>[y+_[0],T+_[1]]):A=d.geometry.points.map(([y,T],S)=>g===L(S)?[y+_[0],T+_[1]]:[y,T]);const w=Ie(A);return{...d,geometry:{points:A,bounds:w}}};function h(d){pe.call(this,e,d)}function u(d){pe.call(this,e,d)}function m(d){pe.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,s=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,a=d.transform),"viewportScale"in d&&n(6,l=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,c,l,h,u,m]}class zt extends ne{constructor(t){super(),te(this,t,Lo,vo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Oo(e){let t,n,o,i,s,r,a,l,c,h,u,m,d,g,_,A,w,y,T,S,Y,D,N,p,E,b,v,P,C,Q,Se,Me,Ye,O,J,H,he,j,me,ze,dt,x,je,We,ht,$,qe,Ke,mt,Mn;return{c(){t=X("rect"),a=ee(),l=X("rect"),d=ee(),g=X("rect"),y=ee(),T=X("rect"),N=ee(),p=X("rect"),P=ee(),C=X("rect"),Ye=ee(),O=X("rect"),he=ee(),j=X("rect"),dt=ee(),x=X("rect"),ht=ee(),$=X("rect"),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"x",o=e[4].x),f(t,"y",i=e[4].y),f(t,"width",s=e[4].w),f(t,"height",r=e[4].h),f(l,"class","a9s-inner a9s-shape-handle"),f(l,"style",e[1]),f(l,"x",c=e[4].x),f(l,"y",h=e[4].y),f(l,"width",u=e[4].w),f(l,"height",m=e[4].h),f(g,"class","a9s-edge-handle a9s-edge-handle-top"),f(g,"x",_=e[4].x),f(g,"y",A=e[4].y),f(g,"height",1),f(g,"width",w=e[4].w),f(T,"class","a9s-edge-handle a9s-edge-handle-right"),f(T,"x",S=e[4].x+e[4].w),f(T,"y",Y=e[4].y),f(T,"height",D=e[4].h),f(T,"width",1),f(p,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(p,"x",E=e[4].x),f(p,"y",b=e[4].y+e[4].h),f(p,"height",1),f(p,"width",v=e[4].w),f(C,"class","a9s-edge-handle a9s-edge-handle-left"),f(C,"x",Q=e[4].x),f(C,"y",Se=e[4].y),f(C,"height",Me=e[4].h),f(C,"width",1),f(O,"class","a9s-corner-handle a9s-corner-handle-topleft"),f(O,"x",J=e[4].x-e[3]/2),f(O,"y",H=e[4].y-e[3]/2),f(O,"height",e[3]),f(O,"width",e[3]),f(j,"class","a9s-corner-handle a9s-corner-handle-topright"),f(j,"x",me=e[4].x+e[4].w-e[3]/2),f(j,"y",ze=e[4].y-e[3]/2),f(j,"height",e[3]),f(j,"width",e[3]),f(x,"class","a9s-corner-handle a9s-corner-handle-bottomright"),f(x,"x",je=e[4].x+e[4].w-e[3]/2),f(x,"y",We=e[4].y+e[4].h-e[3]/2),f(x,"height",e[3]),f(x,"width",e[3]),f($,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),f($,"x",qe=e[4].x-e[3]/2),f($,"y",Ke=e[4].y+e[4].h-e[3]/2),f($,"height",e[3]),f($,"width",e[3])},m(R,M){B(R,t,M),B(R,a,M),B(R,l,M),B(R,d,M),B(R,g,M),B(R,y,M),B(R,T,M),B(R,N,M),B(R,p,M),B(R,P,M),B(R,C,M),B(R,Ye,M),B(R,O,M),B(R,he,M),B(R,j,M),B(R,dt,M),B(R,x,M),B(R,ht,M),B(R,$,M),mt||(Mn=[q(t,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(l,"pointerdown",function(){W(e[10](L.SHAPE))&&e[10](L.SHAPE).apply(this,arguments)}),q(g,"pointerdown",function(){W(e[10](L.TOP))&&e[10](L.TOP).apply(this,arguments)}),q(T,"pointerdown",function(){W(e[10](L.RIGHT))&&e[10](L.RIGHT).apply(this,arguments)}),q(p,"pointerdown",function(){W(e[10](L.BOTTOM))&&e[10](L.BOTTOM).apply(this,arguments)}),q(C,"pointerdown",function(){W(e[10](L.LEFT))&&e[10](L.LEFT).apply(this,arguments)}),q(O,"pointerdown",function(){W(e[10](L.TOP_LEFT))&&e[10](L.TOP_LEFT).apply(this,arguments)}),q(j,"pointerdown",function(){W(e[10](L.TOP_RIGHT))&&e[10](L.TOP_RIGHT).apply(this,arguments)}),q(x,"pointerdown",function(){W(e[10](L.BOTTOM_RIGHT))&&e[10](L.BOTTOM_RIGHT).apply(this,arguments)}),q($,"pointerdown",function(){W(e[10](L.BOTTOM_LEFT))&&e[10](L.BOTTOM_LEFT).apply(this,arguments)})],mt=!0)},p(R,M){e=R,M&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),M&16&&o!==(o=e[4].x)&&f(t,"x",o),M&16&&i!==(i=e[4].y)&&f(t,"y",i),M&16&&s!==(s=e[4].w)&&f(t,"width",s),M&16&&r!==(r=e[4].h)&&f(t,"height",r),M&2&&f(l,"style",e[1]),M&16&&c!==(c=e[4].x)&&f(l,"x",c),M&16&&h!==(h=e[4].y)&&f(l,"y",h),M&16&&u!==(u=e[4].w)&&f(l,"width",u),M&16&&m!==(m=e[4].h)&&f(l,"height",m),M&16&&_!==(_=e[4].x)&&f(g,"x",_),M&16&&A!==(A=e[4].y)&&f(g,"y",A),M&16&&w!==(w=e[4].w)&&f(g,"width",w),M&16&&S!==(S=e[4].x+e[4].w)&&f(T,"x",S),M&16&&Y!==(Y=e[4].y)&&f(T,"y",Y),M&16&&D!==(D=e[4].h)&&f(T,"height",D),M&16&&E!==(E=e[4].x)&&f(p,"x",E),M&16&&b!==(b=e[4].y+e[4].h)&&f(p,"y",b),M&16&&v!==(v=e[4].w)&&f(p,"width",v),M&16&&Q!==(Q=e[4].x)&&f(C,"x",Q),M&16&&Se!==(Se=e[4].y)&&f(C,"y",Se),M&16&&Me!==(Me=e[4].h)&&f(C,"height",Me),M&24&&J!==(J=e[4].x-e[3]/2)&&f(O,"x",J),M&24&&H!==(H=e[4].y-e[3]/2)&&f(O,"y",H),M&8&&f(O,"height",e[3]),M&8&&f(O,"width",e[3]),M&24&&me!==(me=e[4].x+e[4].w-e[3]/2)&&f(j,"x",me),M&24&&ze!==(ze=e[4].y-e[3]/2)&&f(j,"y",ze),M&8&&f(j,"height",e[3]),M&8&&f(j,"width",e[3]),M&24&&je!==(je=e[4].x+e[4].w-e[3]/2)&&f(x,"x",je),M&24&&We!==(We=e[4].y+e[4].h-e[3]/2)&&f(x,"y",We),M&8&&f(x,"height",e[3]),M&8&&f(x,"width",e[3]),M&24&&qe!==(qe=e[4].x-e[3]/2)&&f($,"x",qe),M&24&&Ke!==(Ke=e[4].y+e[4].h-e[3]/2)&&f($,"y",Ke),M&8&&f($,"height",e[3]),M&8&&f($,"width",e[3])},d(R){R&&I(t),R&&I(a),R&&I(l),R&&I(d),R&&I(g),R&&I(y),R&&I(T),R&&I(N),R&&I(p),R&&I(P),R&&I(C),R&&I(Ye),R&&I(O),R&&I(he),R&&I(j),R&&I(dt),R&&I(x),R&&I(ht),R&&I($),mt=!1,oe(Mn)}}}function Io(e){let t,n;return t=new it({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Oo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("grab",e[7]),t.$on("change",e[8]),t.$on("release",e[9]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&3098&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function ko(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const c=(d,g,_)=>{const A=d.geometry.bounds;let[w,y]=[A.minX,A.minY],[T,S]=[A.maxX,A.maxY];const[Y,D]=_;if(g===L.SHAPE)w+=Y,T+=Y,y+=D,S+=D;else{switch(g){case L.TOP:case L.TOP_LEFT:case L.TOP_RIGHT:{y+=D;break}case L.BOTTOM:case L.BOTTOM_LEFT:case L.BOTTOM_RIGHT:{S+=D;break}}switch(g){case L.LEFT:case L.TOP_LEFT:case L.BOTTOM_LEFT:{w+=Y;break}case L.RIGHT:case L.TOP_RIGHT:case L.BOTTOM_RIGHT:{T+=Y;break}}}const N=Math.min(w,T),p=Math.min(y,S),E=Math.abs(T-w),b=Math.abs(S-y);return{...d,geometry:{x:N,y:p,w:E,h:b,bounds:{minX:N,minY:p,maxX:N+E,maxY:p+b}}}};function h(d){pe.call(this,e,d)}function u(d){pe.call(this,e,d)}function m(d){pe.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,s=d.shape),"computedStyle"in d&&n(1,r=d.computedStyle),"transform"in d&&n(2,a=d.transform),"viewportScale"in d&&n(6,l=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,c,l,h,u,m]}class jt extends ne{constructor(t){super(),te(this,t,ko,Io,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const Wt=new Map([[z.RECTANGLE,jt],[z.POLYGON,zt]]),ot=e=>Wt.get(e.type),qt=(e,t)=>Wt.set(e,t),L=e=>`HANDLE-${e}`;L.SHAPE="SHAPE",L.TOP="TOP",L.RIGHT="RIGHT",L.BOTTOM="BOTTOM",L.LEFT="LEFT",L.TOP_LEFT="TOP_LEFT",L.TOP_RIGHT="TOP_RIGHT",L.BOTTOM_RIGHT="BOTTOM_RIGHT",L.BOTTOM_LEFT="BOTTOM_LEFT";const Bo=e=>({}),Kt=e=>({grab:e[0]});function Po(e){let t,n,o,i;const s=e[7].default,r=On(s,e,e[6],Kt);return{c(){t=X("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(a,l){B(a,t,l),r&&r.m(t,null),n=!0,o||(i=[q(t,"pointerup",e[2]),q(t,"pointermove",e[1])],o=!0)},p(a,[l]){r&&r.p&&(!n||l&64)&&kn(r,s,a,a[6],n?In(s,a[6],l,Bo):Bn(a[6]),Kt)},i(a){n||(U(r,a),n=!0)},o(a){V(r,a),n=!1},d(a){a&&I(t),r&&r.d(a),o=!1,oe(i)}}}function Yo(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=ge();let{shape:r}=t,{editor:a}=t,{transform:l}=t,c=null,h,u=null;const m=_=>A=>{c=_,h=l.elementToImage(A.offsetX,A.offsetY),u=r,A.target.setPointerCapture(A.pointerId),s("grab")},d=_=>{if(c){const[A,w]=l.elementToImage(_.offsetX,_.offsetY),y=[A-h[0],w-h[1]];n(3,r=a(u,c,y)),s("change",r)}},g=_=>{_.target.releasePointerCapture(_.pointerId),c=null,u=r,s("release")};return e.$$set=_=>{"shape"in _&&n(3,r=_.shape),"editor"in _&&n(4,a=_.editor),"transform"in _&&n(5,l=_.transform),"$$scope"in _&&n(6,i=_.$$scope)},[m,d,g,r,a,l,i,o]}class it extends ne{constructor(t){super(),te(this,t,Yo,Po,Z,{shape:3,editor:4,transform:5})}}const Ne=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i}=n;let s="";return o&&(s+=`fill:${o};stroke:${o};`),s+=`fill-opacity:${i||"0.25"};`,s}};function Ro(e,t,n){let o;const i=ge();let{annotation:s}=t,{editor:r}=t,{style:a=void 0}=t,{target:l}=t,{transform:c}=t,{viewportScale:h}=t,u;return Oe(()=>(n(6,u=new r({target:l,props:{shape:s.target.selector,computedStyle:o,transform:c,viewportScale:h}})),u.$on("change",m=>{u.$$set({shape:m.detail}),i("change",m.detail)}),u.$on("grab",m=>i("grab",m.detail)),u.$on("release",m=>i("release",m.detail)),()=>{u.$destroy()})),e.$$set=m=>{"annotation"in m&&n(0,s=m.annotation),"editor"in m&&n(1,r=m.editor),"style"in m&&n(2,a=m.style),"target"in m&&n(3,l=m.target),"transform"in m&&n(4,c=m.transform),"viewportScale"in m&&n(5,h=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ne(s,a)),e.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),e.$$.dirty&80&&u&&u.$set({transform:c}),e.$$.dirty&96&&u&&u.$set({viewportScale:h})},[s,r,a,l,c,h,u]}class Jt extends ne{constructor(t){super(),te(this,t,Ro,null,Z,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Do(e,t,n){const o=ge();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,c;return Oe(()=>{const h=s.closest("svg"),u=[],m=(d,g,_)=>{h.addEventListener(d,g,_),u.push(()=>h.removeEventListener(d,g,_))};return n(5,c=new r({target:s,props:{addEventListener:m,drawingMode:i,transform:a,viewportScale:l}})),c.$on("create",d=>o("create",d.detail)),()=>{u.forEach(d=>d()),c.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,i=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&c&&c.$set({transform:a}),e.$$.dirty&48&&c&&c.$set({viewportScale:l})},[i,s,r,a,l,c]}class Zt extends ne{constructor(t){super(),te(this,t,Do,null,Z,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Qt(e){let t,n;return{c(){t=X("rect"),n=X("rect"),f(t,"class","a9s-outer"),f(t,"x",e[1]),f(t,"y",e[2]),f(t,"width",e[3]),f(t,"height",e[4]),f(n,"class","a9s-inner"),f(n,"x",e[1]),f(n,"y",e[2]),f(n,"width",e[3]),f(n,"height",e[4])},m(o,i){B(o,t,i),B(o,n,i)},p(o,i){i&2&&f(t,"x",o[1]),i&4&&f(t,"y",o[2]),i&8&&f(t,"width",o[3]),i&16&&f(t,"height",o[4]),i&2&&f(n,"x",o[1]),i&4&&f(n,"y",o[2]),i&8&&f(n,"width",o[3]),i&16&&f(n,"height",o[4])},d(o){o&&I(t),o&&I(n)}}}function Co(e){let t,n=e[0]&&Qt(e);return{c(){t=X("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=Qt(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&I(t),n&&n.d()}}}function Xo(e,t,n){const o=ge();let{addEventListener:i}=t,{drawingMode:s}=t,{transform:r}=t,a,l,c,h,u,m,d;const g=y=>{a=performance.now(),s==="drag"&&(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,h=l[0]),n(2,u=l[1]),n(3,m=1),n(4,d=1))},_=y=>{l&&(c=r.elementToImage(y.offsetX,y.offsetY),n(1,h=Math.min(c[0],l[0])),n(2,u=Math.min(c[1],l[1])),n(3,m=Math.abs(c[0]-l[0])),n(4,d=Math.abs(c[1]-l[1])))},A=y=>{const T=performance.now()-a;if(s==="click"){if(T>300)return;y.stopPropagation(),l?w():(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,h=l[0]),n(2,u=l[1]),n(3,m=1),n(4,d=1))}else l&&(T>300||m*d>100?(y.stopPropagation(),w()):(n(0,l=null),c=null))},w=()=>{if(m*d>15){const y={type:z.RECTANGLE,geometry:{bounds:{minX:h,minY:u,maxX:h+m,maxY:u+d},x:h,y:u,w:m,h:d}};o("create",y)}n(0,l=null),c=null};return Oe(()=>{i("pointerdown",g),i("pointermove",_),i("pointerup",A,!0)}),e.$$set=y=>{"addEventListener"in y&&n(5,i=y.addEventListener),"drawingMode"in y&&n(6,s=y.drawingMode),"transform"in y&&n(7,r=y.transform)},[l,h,u,m,d,i,s,r]}class xt extends ne{constructor(t){super(),te(this,t,Xo,Co,Z,{addEventListener:5,drawingMode:6,transform:7})}}const Ve=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},Ee=[];function Uo(e,t=G){let n;const o=new Set;function i(a){if(Z(e,a)&&(e=a,n)){const l=!Ee.length;for(const c of o)c[1](),Ee.push(c,e);if(l){for(let c=0;c<Ee.length;c+=2)Ee[c][0](Ee[c+1]);Ee.length=0}}}function s(a){i(a(e))}function r(a,l=G){const c=[a,l];return o.add(c),o.size===1&&(n=t(i)||G),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const No=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},$t=(e,t)=>{No(e,t);const{subscribe:n,set:o}=Uo(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,c=Math.max(r.width/a,r.height/l);o(c)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Vo="ontouchstart"in window||navigator.maxTouchPoints>0;function st(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(o=>o.join(",")).join(" ");return t[15]=n,t}function en(e){let t,n,o,i,s,r=e[2]&&tn(e);return{c(){t=X("polygon"),o=X("polygon"),r&&r.c(),s=ie(),f(t,"class","a9s-outer"),f(t,"points",n=e[15]),f(o,"class","a9s-inner"),f(o,"points",i=e[15])},m(a,l){B(a,t,l),B(a,o,l),r&&r.m(a,l),B(a,s,l)},p(a,l){l&7&&n!==(n=a[15])&&f(t,"points",n),l&7&&i!==(i=a[15])&&f(o,"points",i),a[2]?r?r.p(a,l):(r=tn(a),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(a){a&&I(t),a&&I(o),r&&r.d(a),a&&I(s)}}}function tn(e){let t,n,o;return{c(){t=X("rect"),f(t,"class","a9s-corner-handle"),f(t,"x",n=e[0][0][0]-e[3]/2),f(t,"y",o=e[0][0][1]-e[3]/2),f(t,"height",e[3]),f(t,"width",e[3])},m(i,s){B(i,t,s)},p(i,s){s&9&&n!==(n=i[0][0][0]-i[3]/2)&&f(t,"x",n),s&9&&o!==(o=i[0][0][1]-i[3]/2)&&f(t,"y",o),s&8&&f(t,"height",i[3]),s&8&&f(t,"width",i[3])},d(i){i&&I(t)}}}function Go(e){let t,n=e[1]&&en(st(e));return{c(){t=X("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[1]?n?n.p(st(o),i):(n=en(st(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&I(t),n&&n.d()}}}const Fo=20;function Ho(e,t,n){let o;const i=ge();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,c,h=[],u=null,m=!1;const d=y=>{const{timeStamp:T,offsetX:S,offsetY:Y}=y;if(c={timeStamp:T,offsetX:S,offsetY:Y},r==="drag"&&h.length===0){const D=a.elementToImage(y.offsetX,y.offsetY);h.push(D),n(1,u=D)}},g=y=>{if(h.length>0&&(n(1,u=a.elementToImage(y.offsetX,y.offsetY)),h.length>2)){const T=Ve(u,h[0])*l;n(2,m=T<Fo)}},_=y=>{if(r==="click"){const T=y.timeStamp-c.timeStamp,S=Ve([c.offsetX,c.offsetY],[y.offsetX,y.offsetY]);if(T>300||S>15)return;if(m)w();else if(h.length===0){const Y=a.elementToImage(y.offsetX,y.offsetY);h.push(Y),n(1,u=Y)}else h.push(u)}else{if(h.length===1&&Ve(h[0],u)<=4){n(0,h=[]),n(1,u=null);return}y.stopImmediatePropagation(),m?w():h.push(u)}},A=()=>{const y=[...h,u],T={type:z.POLYGON,geometry:{bounds:Ie(y),points:y}};Xe(T)>4&&(n(0,h=[]),n(1,u=null),i("create",T))},w=()=>{const y={type:z.POLYGON,geometry:{bounds:Ie(h),points:[...h]}};n(0,h=[]),n(1,u=null),i("create",y)};return Oe(()=>{s("pointerdown",d,!0),s("pointermove",g),s("pointerup",_,!0),s("dblclick",A,!0)}),e.$$set=y=>{"addEventListener"in y&&n(4,s=y.addEventListener),"drawingMode"in y&&n(5,r=y.drawingMode),"transform"in y&&n(6,a=y.transform),"viewportScale"in y&&n(7,l=y.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,o=10/l)},[h,u,m,o,s,r,a,l]}class zo extends ne{constructor(t){super(),te(this,t,Ho,Go,Z,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const rt=new Map([["rectangle",{tool:xt}],["polygon",{tool:zo}]]),Ge=()=>[...rt.keys()],lt=e=>rt.get(e),nn=(e,t,n)=>rt.set(e,{tool:t,opts:n});function jo(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("ellipse"),i=X("ellipse"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"cx",e[2]),f(n,"cy",e[3]),f(n,"rx",e[4]),f(n,"ry",e[5]),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"cx",e[2]),f(i,"cy",e[3]),f(i,"rx",e[4]),f(i,"ry",e[5]),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}function Wo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{cx:a,cy:l,rx:c,ry:h}=s;return e.$$set=u=>{"annotation"in u&&n(0,i=u.annotation),"geom"in u&&n(6,s=u.geom),"style"in u&&n(7,r=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,a,l,c,h,s,r]}class qo extends ne{constructor(t){super(),te(this,t,Wo,jo,Z,{annotation:0,geom:6,style:7})}}function Ko(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("polygon"),i=X("polygon"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"points",e[2].map(Jo).join(" ")),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"points",e[2].map(Zo).join(" ")),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}const Jo=e=>e.join(","),Zo=e=>e.join(",");function Qo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,i=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ne(i,r))},[i,o,a,s,r]}class xo extends ne{constructor(t){super(),te(this,t,Qo,Ko,Z,{annotation:0,geom:3,style:4})}}function $o(e){let t,n,o,i,s;return{c(){t=X("g"),n=X("rect"),i=X("rect"),f(n,"class","a9s-outer"),f(n,"style",o=e[5]?"display:none;":void 0),f(n,"x",e[4]),f(n,"y",e[3]),f(n,"width",e[2]),f(n,"height",e[1]),f(i,"class","a9s-inner"),f(i,"style",e[5]),f(i,"x",e[4]),f(i,"y",e[3]),f(i,"width",e[2]),f(i,"height",e[1]),f(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&32&&o!==(o=r[5]?"display:none;":void 0)&&f(n,"style",o),a&16&&f(n,"x",r[4]),a&8&&f(n,"y",r[3]),a&4&&f(n,"width",r[2]),a&2&&f(n,"height",r[1]),a&32&&f(i,"style",r[5]),a&16&&f(i,"x",r[4]),a&8&&f(i,"y",r[3]),a&4&&f(i,"width",r[2]),a&2&&f(i,"height",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:G,o:G,d(r){r&&I(t)}}}function ei(e,t,n){let o,i,s,r,a,{annotation:l}=t,{geom:c}=t,{style:h=void 0}=t;return e.$$set=u=>{"annotation"in u&&n(0,l=u.annotation),"geom"in u&&n(6,c=u.geom),"style"in u&&n(7,h=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ne(l,h)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:a}=c,i,(n(3,s),n(6,c)),(n(2,r),n(6,c)),(n(1,a),n(6,c)))},[l,a,r,s,i,o,c,h]}class ti extends ne{constructor(t){super(),te(this,t,ei,$o,Z,{annotation:0,geom:6,style:7})}}const ni={elementToImage:(e,t)=>[e,t]},on=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),oi=250,sn=(e,t)=>{const n=ge();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<oi){const{x:l,y:c}=ii(r,e),h=t.getAt(l,c);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},ii=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=i+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function rn(e,t,n){const o=e.slice();return o[29]=t[n],o}function ln(e,t,n){const o=e.slice();return o[32]=t[n],o}function at(e){const t=e.slice(),n=t[32].target.selector;return t[35]=n,t}function an(e){let t=e[32].id,n,o,i=cn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&8192&&Z(t,t=s[32].id)?(se(),V(i,1,1,G),re(),i=cn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function si(e){let t,n;return t=new xo({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function ri(e){let t,n;return t=new ti({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function li(e){let t,n;return t=new qo({props:{annotation:e[32],geom:e[35].geometry,style:e[1]}}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&8192&&(s.annotation=o[32]),i[0]&8192&&(s.geom=o[35].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function cn(e){let t,n,o,i;const s=[li,ri,si],r=[];function a(l,c){return l[35].type===z.ELLIPSE?0:l[35].type===z.RECTANGLE?1:l[35].type===z.POLYGON?2:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let h=t;t=a(l),t===h?~t&&r[t].p(l,c):(n&&(se(),V(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(U(n),i=!0)},o(l){V(n),i=!1},d(l){~t&&r[t].d(l),l&&I(o)}}}function un(e){let t=!e[7](e[32]),n,o,i=t&&an(at(e));return{c(){i&&i.c(),n=ie()},m(s,r){i&&i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&8320&&(t=!s[7](s[32])),t?i?(i.p(at(s),r),r[0]&8320&&U(i,1)):(i=an(at(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(se(),V(i,1,1,()=>{i=null}),re())},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){i&&i.d(s),s&&I(n)}}}function fn(e){let t,n,o,i;const s=[ci,ai],r=[];function a(l,c){return l[6]?0:l[12]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let h=t;t=a(l),t===h?~t&&r[t].p(l,c):(n&&(se(),V(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(U(n),i=!0)},o(l){V(n),i=!1},d(l){~t&&r[t].d(l),l&&I(o)}}}function ai(e){let t=e[2],n,o,i=dn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4&&Z(t,t=s[2])?(se(),V(i,1,1,G),re(),i=dn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function ci(e){let t,n,o=e[6],i=[];for(let r=0;r<o.length;r+=1)i[r]=mn(rn(e,o,r));const s=r=>V(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ie()},m(r,a){for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(r,a);B(r,t,a),n=!0},p(r,a){if(a[0]&279634){o=r[6];let l;for(l=0;l<o.length;l+=1){const c=rn(r,o,l);i[l]?(i[l].p(c,a),U(i[l],1)):(i[l]=mn(c),i[l].c(),U(i[l],1),i[l].m(t.parentNode,t))}for(se(),l=o.length;l<i.length;l+=1)s(l);re()}},i(r){if(!n){for(let a=0;a<o.length;a+=1)U(i[a]);n=!0}},o(r){i=i.filter(Boolean);for(let a=0;a<i.length;a+=1)V(i[a]);n=!1},d(r){Je(i,r),r&&I(t)}}}function dn(e){let t,n;return t=new Zt({props:{target:e[4],tool:e[12],drawingMode:e[11],transform:e[10],viewportScale:e[14]}}),t.$on("create",e[17]),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i[0]&16&&(s.target=o[4]),i[0]&4096&&(s.tool=o[12]),i[0]&2048&&(s.drawingMode=o[11]),i[0]&1024&&(s.transform=o[10]),i[0]&16384&&(s.viewportScale=o[14]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function hn(e){let t,n;return t=new Jt({props:{target:e[4],editor:ot(e[29].target.selector),annotation:e[29],style:e[1],transform:e[10],viewportScale:e[14]}}),t.$on("change",function(){W(e[18](e[29]))&&e[18](e[29]).apply(this,arguments)}),{c(){fe(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&16&&(s.target=e[4]),i[0]&64&&(s.editor=ot(e[29].target.selector)),i[0]&64&&(s.annotation=e[29]),i[0]&2&&(s.style=e[1]),i[0]&1024&&(s.transform=e[10]),i[0]&16384&&(s.viewportScale=e[14]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){V(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function mn(e){let t=e[29].id,n,o,i=hn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&64&&Z(t,t=s[29].id)?(se(),V(i,1,1,G),re(),i=hn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){V(i),o=!1},d(s){s&&I(n),i.d(s)}}}function ui(e){let t,n,o,i,s,r,a=e[13],l=[];for(let u=0;u<a.length;u+=1)l[u]=un(ln(e,a,u));const c=u=>V(l[u],1,1,()=>{l[u]=null});let h=e[4]&&fn(e);return{c(){t=X("svg"),n=X("g");for(let u=0;u<l.length;u+=1)l[u].c();o=X("g"),h&&h.c(),f(o,"class","drawing"),f(t,"class","a9s-annotationlayer"),Et(t,"drawing",e[12])},m(u,m){B(u,t,m),le(t,n);for(let d=0;d<l.length;d+=1)l[d]&&l[d].m(n,null);le(t,o),h&&h.m(o,null),e[25](o),e[26](t),i=!0,s||(r=[q(t,"pointerup",function(){W(e[8])&&e[8].apply(this,arguments)}),q(t,"pointerdown",function(){W(e[9])&&e[9].apply(this,arguments)})],s=!0)},p(u,m){if(e=u,m[0]&8322){a=e[13];let d;for(d=0;d<a.length;d+=1){const g=ln(e,a,d);l[d]?(l[d].p(g,m),U(l[d],1)):(l[d]=un(g),l[d].c(),U(l[d],1),l[d].m(n,null))}for(se(),d=a.length;d<l.length;d+=1)c(d);re()}e[4]?h?(h.p(e,m),m[0]&16&&U(h,1)):(h=fn(e),h.c(),U(h,1),h.m(o,null)):h&&(se(),V(h,1,1,()=>{h=null}),re()),(!i||m[0]&4096)&&Et(t,"drawing",e[12])},i(u){if(!i){for(let m=0;m<a.length;m+=1)U(l[m]);U(h),i=!0}},o(u){l=l.filter(Boolean);for(let m=0;m<l.length;m+=1)V(l[m]);V(h),i=!1},d(u){u&&I(t),Je(l,u),h&&h.d(),e[25](null),e[26](null),s=!1,oe(r)}}}function fi(e,t,n){let o,i,s,r,a,l,c,h,u,m,d=G,g=()=>(d(),d=yt(p,O=>n(14,m=O)),p);e.$$.on_destroy.push(()=>d());let{drawingEnabled:_}=t,{image:A}=t,{preferredDrawingMode:w}=t,{state:y}=t,{style:T=void 0}=t,{toolName:S=Ge().length>0?Ge()[0]:void 0}=t,{user:Y}=t,D,N,p;Oe(()=>g(n(5,p=$t(A,N))));const{selection:E,store:b}=y;_t(e,E,O=>n(24,h=O)),_t(e,b,O=>n(13,u=O));let v=null,P=null;const C=O=>{b.unobserve(v);const J=O.filter(({editable:H})=>H).map(({id:H})=>H);J.length>0?(n(6,P=J.map(H=>b.getAnnotation(H))),v=H=>{const{updated:he}=H.changes;n(6,P=he.map(j=>j.newValue))},b.observe(v,{annotations:J})):n(6,P=null)},Q=O=>{const J=Rt(),H={id:J,bodies:[],target:{annotation:J,selector:O.detail,creator:Y,created:new Date}};b.addAnnotation(H),E.setSelected(H.id)},Se=O=>J=>{var me;const{target:H}=O,he=10*60*1e3,j=((me=H.creator)==null?void 0:me.id)!==Y.id||!H.created||new Date().getTime()-H.created.getTime()>he;b.updateTarget({...H,selector:J.detail,created:j?H.created:new Date,updated:j?new Date:null,updatedBy:j?Y:null})};function Me(O){Re[O?"unshift":"push"](()=>{D=O,n(4,D)})}function Ye(O){Re[O?"unshift":"push"](()=>{N=O,n(3,N)})}return e.$$set=O=>{"drawingEnabled"in O&&n(0,_=O.drawingEnabled),"image"in O&&n(19,A=O.image),"preferredDrawingMode"in O&&n(20,w=O.preferredDrawingMode),"state"in O&&n(21,y=O.state),"style"in O&&n(1,T=O.style),"toolName"in O&&n(2,S=O.toolName),"user"in O&&n(22,Y=O.user)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(12,{tool:o,opts:i}=lt(S),o,(n(23,i),n(2,S))),e.$$.dirty[0]&9437184&&n(11,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&8&&n(10,r=on(N)),e.$$.dirty[0]&8&&n(9,{onPointerDown:a,onPointerUp:l}=sn(N,b),a,(n(8,l),n(3,N))),e.$$.dirty[0]&16777216&&n(7,c=O=>h.selected.find(J=>J.id===O.id&&J.editable)),e.$$.dirty[0]&16777216&&C(h.selected)},[_,T,S,N,D,p,P,c,l,a,r,s,o,u,m,E,b,Q,Se,A,w,y,Y,i,h,Me,Ye]}class gn extends ne{constructor(t){super(),te(this,t,fi,ui,Z,{drawingEnabled:0,image:19,preferredDrawingMode:20,state:21,style:1,toolName:2,user:22},null,[-1,-1])}}function di(e,t,n,o,i){pn(e,t,n||0,o||e.length-1,i||hi)}function pn(e,t,n,o,i){for(;o>n;){if(o-n>600){var s=o-n+1,r=t-n+1,a=Math.log(s),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(s-l)/s)*(r-s/2<0?-1:1),h=Math.max(n,Math.floor(t-r*l/s+c)),u=Math.min(o,Math.floor(t+(s-r)*l/s+c));pn(e,t,h,u,i)}var m=e[t],d=n,g=o;for(ke(e,n,t),i(e[o],m)>0&&ke(e,n,o);d<g;){for(ke(e,d,g),d++,g--;i(e[d],m)<0;)d++;for(;i(e[g],m)>0;)g--}i(e[n],m)===0?ke(e,n,g):(g++,ke(e,g,o)),g<=t&&(n=g+1),t<=g&&(o=g-1)}}function ke(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function hi(e,t){return e<t?-1:e>t?1:0}class mi{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!He(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?i(a):a;He(t,l)&&(n.leaf?o.push(a):ut(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!He(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(He(t,r)){if(n.leaf||ut(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Te([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let a,l,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const h=gi(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&ut(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,a;if(s<=r)return a=Te(t.slice(n,o+1)),Ae(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=Te([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),c=l*Math.ceil(Math.sqrt(r));yn(t,n,o,c,this.compareMinX);for(let h=n;h<=o;h+=c){const u=Math.min(h+c-1,o);yn(t,h,u,l,this.compareMinY);for(let m=h;m<=u;m+=l){const d=Math.min(m+l-1,u);a.children.push(this._build(t,m,d,i-1))}}return Ae(a,this.toBBox),a}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const c=n.children[l],h=ct(c),u=_i(t,c)-h;u<r?(r=u,s=h<s?h:s,a=c):u===r&&h<s&&(s=h,a=c)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),Pe(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),a=Te(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,Ae(o,this.toBBox),Ae(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=Te([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Ae(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let a=n;a<=o-n;a++){const l=Be(t,0,a,this.toBBox),c=Be(t,a,o,this.toBBox),h=wi(l,c),u=ct(l)+ct(c);h<s?(s=h,i=a,r=u<r?u:r):h===s&&u<r&&(r=u,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:pi,s=t.leaf?this.compareMinY:yi,r=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,s);r<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Be(t,0,n,s),a=Be(t,o-n,o,s);let l=Fe(r)+Fe(a);for(let c=n;c<o-n;c++){const h=t.children[c];Pe(r,t.leaf?s(h):h),l+=Fe(r)}for(let c=o-n-1;c>=n;c--){const h=t.children[c];Pe(a,t.leaf?s(h):h),l+=Fe(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Pe(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():Ae(t[n],this.toBBox)}}function gi(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function Ae(e,t){Be(e,0,e.children.length,t,e)}function Be(e,t,n,o,i){i||(i=Te(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];Pe(i,e.leaf?o(r):r)}return i}function Pe(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function pi(e,t){return e.minX-t.minX}function yi(e,t){return e.minY-t.minY}function ct(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Fe(e){return e.maxX-e.minX+(e.maxY-e.minY)}function _i(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function wi(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function ut(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function He(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Te(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function yn(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;di(e,r,t,n,i),s.push(t,r,r,n)}}const bi=()=>{const e=new mi,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=u=>{const{minX:m,minY:d,maxX:g,maxY:_}=u.selector.geometry.bounds,A={minX:m,minY:d,maxX:g,maxY:_,target:u};e.insert(A),t.set(u.annotation,A)},s=u=>{const m=t.get(u.annotation);e.remove(m),t.delete(u.annotation)};return{all:n,clear:o,getAt:(u,m)=>{const g=e.search({minX:u,minY:m,maxX:u,maxY:m}).map(_=>_.target).filter(_=>_.selector.type===z.RECTANGLE||Mt(_.selector,u,m));if(g.length>0)return g.sort((_,A)=>Xe(_.selector)-Xe(A.selector)),g[0]},getIntersecting:(u,m,d,g)=>e.search({minX:u,minY:m,maxX:u+d,maxY:m+g}).map(_=>_.target),insert:i,remove:s,set:(u,m=!0)=>{m&&o();const d=u.map(g=>{const{minX:_,minY:A,maxX:w,maxY:y}=g.selector.geometry.bounds;return{minX:_,minY:A,maxX:w,maxY:y,target:g}});d.forEach(g=>t.set(g.target.annotation,g)),e.load(d)},size:()=>e.all().length,update:(u,m)=>{s(u),i(m)}}},_n=e=>{const t=ro(),n=bi(),o=Zn(t,e.pointerSelectAction),i=Jn(t),s=fo();return t.observe(({changes:l})=>{n.set(l.created.map(c=>c.target),!1),l.deleted.forEach(c=>n.remove(c.target)),l.updated.forEach(({oldValue:c,newValue:h})=>n.update(c.target,h.target))}),{store:{...t,getAt:(l,c)=>{const h=n.getAt(l,c);return h?t.getAnnotation(h.annotation):void 0},getIntersecting:(l,c,h,u)=>n.getIntersecting(l,c,h,u).map(m=>t.getAnnotation(m.annotation))},selection:o,hover:i,viewport:s}},wn=e=>{const t=_n(e);return{...t,store:lo(t.store)}},bn=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(i*t.height/10),l=n.getImageData(r,a,1,1).data,c=(.299*l[0]+.587*l[1]+.114*l[2])/255;o+=c}return o/81},En=e=>{const t=bn(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},ft=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?En(e):n),An=e=>({...e,drawingEnabled:e.drawingEnabled===void 0?!0:e.drawingEnabled,drawingMode:e.drawingMode||"drag",pointerSelectAction:e.pointerSelectAction||Ct.EDIT,theme:e.theme||"light"}),Tn=navigator.userAgent.indexOf("Mac OS X")!==-1,Sn=(e,t)=>{const n=t||document,o=r=>{r.key==="Z"&&r.ctrlKey?e.undo():r.key==="Y"&&r.ctrlKey&&e.redo()},i=r=>{r.key==="z"&&r.metaKey&&(r.shiftKey?e.redo():e.undo())},s=()=>{Tn?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return Tn?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Ti="",Si="",Mi="",Ei=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=An(t),i=wn(o),{selection:s,store:r}=i,a=uo(r),l=ho(i,a,o.adapter,o.autoSave),c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n);const h=Sn(a);let u=bo();ft(n,c,o.theme);const m=new gn({target:c,props:{drawingEnabled:o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:u}});m.$on("click",p=>{const{originalEvent:E,annotation:b}=p.detail;b?s.clickSelect(b.id,E):s.isEmpty()||s.clear()});const d=go(i,a,o.adapter),g=()=>{m.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c),h.destroy(),a.destroy()},_=()=>u,A=(p,E,b)=>nn(p,E,b),w=(p,E)=>qt(p,E),y=p=>{if(!lt(p))throw`No drawing tool named ${p}`;m.$set({toolName:p})},T=p=>m.$set({drawingEnabled:p}),S=p=>{console.warn("Filter not implemented yet")},Y=p=>m.$set({style:p}),D=p=>ft(n,c,p),N=p=>{u=p,m.$set({user:p})};return{...d,destroy:g,getUser:_,listDrawingTools:Ge,on:l.on,off:l.off,registerDrawingTool:A,registerShapeEditor:w,setDrawingEnabled:T,setDrawingTool:y,setFilter:S,setStyle:Y,setTheme:D,setUser:N,state:i}};k.Editor=it,k.EditorMount=Jt,k.Handle=L,k.IdentityTransform=ni,k.PolygonEditor=zt,k.RectangleEditor=jt,k.RectangleUtil=vt,k.RubberbandRectangle=xt,k.SVGAnnotationLayer=gn,k.ShapeType=z,k.ToolMount=Zt,k.W3CImageFormat=So,k.addEventListeners=sn,k.boundsFromPoints=Ie,k.computeArea=Xe,k.createImageAnnotator=Ei,k.createImageAnnotatorState=_n,k.createSVGTransform=on,k.createSvelteImageAnnotatorState=wn,k.detectTheme=En,k.distance=Ve,k.enableResponsive=$t,k.fillDefaults=An,k.getEditor=ot,k.getTool=lt,k.initKeyboardCommands=Sn,k.intersects=Mt,k.isTouch=Vo,k.listDrawingTools=Ge,k.parseFragmentSelector=Lt,k.parseSVGSelector=Bt,k.parseW3CImageAnnotation=Ut,k.registerEditor=qt,k.registerShapeUtil=Ce,k.registerTool=nn,k.sampleBrightness=bn,k.serializeFragmentSelector=Ot,k.serializeSVGSelector=Pt,k.serializeW3CImageAnnotation=Nt,k.setTheme=ft,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(L,X){typeof exports=="object"&&typeof module<"u"?X(exports):typeof define=="function"&&define.amd?define(["exports"],X):(L=typeof globalThis<"u"?globalThis:L||self,X(L.Annotorious={}))})(this,function(L){"use strict";var Fi=Object.defineProperty;var Hi=(L,X,me)=>X in L?Fi(L,X,{enumerable:!0,configurable:!0,writable:!0,value:me}):L[X]=me;var Tt=(L,X,me)=>Hi(L,typeof X!="symbol"?X+"":X,me);function X(){}function me(e,t){for(const n in t)e[n]=t[n];return e}function vt(e){return e()}function Mt(){return Object.create(null)}function ce(e){e.forEach(vt)}function q(e){return typeof e=="function"}function x(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Vn(e){return Object.keys(e).length===0}function Lt(e,...t){if(e==null){for(const o of t)o(void 0);return X}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function nt(e,t,n){e.$$.on_destroy.push(Lt(t,n))}function Gn(e,t,n,o){if(e){const i=kt(e,t,n,o);return e[0](i)}}function kt(e,t,n,o){return e[1]&&o?me(n.ctx.slice(),e[1](o(t))):n.ctx}function jn(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|i[a];return s}return t.dirty|i}return t.dirty}function zn(e,t,n,o,i,s){if(i){const r=kt(t,n,o,s);e.p(r,i)}}function Fn(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function It(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function Ve(e){return e??""}const Hn=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function fe(e,t){e.appendChild(t)}function B(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode&&e.parentNode.removeChild(e)}function ot(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function N(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function Ot(e){return document.createTextNode(e)}function se(){return Ot(" ")}function re(){return Ot("")}function W(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function h(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wn(e){return Array.from(e.childNodes)}function pe(e,t,n){e.classList.toggle(t,!!n)}function Kn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Be;function Pe(e){Be=e}function Bt(){if(!Be)throw new Error("Function called outside component initialization");return Be}function De(e){Bt().$$.on_mount.push(e)}function Ee(){const e=Bt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Kn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function ge(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const Ae=[],Ge=[];let Se=[];const Pt=[],qn=Promise.resolve();let it=!1;function Jn(){it||(it=!0,qn.then(Dt))}function st(e){Se.push(e)}const rt=new Set;let Te=0;function Dt(){if(Te!==0)return;const e=Be;do{try{for(;Te<Ae.length;){const t=Ae[Te];Te++,Pe(t),Qn(t.$$)}}catch(t){throw Ae.length=0,Te=0,t}for(Pe(null),Ae.length=0,Te=0;Ge.length;)Ge.pop()();for(let t=0;t<Se.length;t+=1){const n=Se[t];rt.has(n)||(rt.add(n),n())}Se.length=0}while(Ae.length);for(;Pt.length;)Pt.pop()();it=!1,rt.clear(),Pe(e)}function Qn(e){if(e.fragment!==null){e.update(),ce(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(st)}}function Zn(e){const t=[],n=[];Se.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Se=t}const je=new Set;let be;function ae(){be={r:0,c:[],p:be}}function le(){be.r||ce(be.c),be=be.p}function P(e,t){e&&e.i&&(je.delete(e),e.i(t))}function U(e,t,n,o){if(e&&e.o){if(je.has(e))return;je.add(e),be.c.push(()=>{je.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ne(e){e&&e.c()}function $(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),st(()=>{const s=e.$$.on_mount.map(vt).filter(q);e.$$.on_destroy?e.$$.on_destroy.push(...s):ce(s),e.$$.on_mount=[]}),i.forEach(st)}function ee(e,t){const n=e.$$;n.fragment!==null&&(Zn(n.after_update),ce(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xn(e,t){e.$$.dirty[0]===-1&&(Ae.push(e),Jn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function oe(e,t,n,o,i,s,r=null,a=[-1]){const l=Be;Pe(e);const c=e.$$={fragment:null,ctx:[],props:s,update:X,not_equal:i,bound:Mt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Mt(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(c.root);let f=!1;if(c.ctx=n?n(e,t.props||{},(u,d,...g)=>{const m=g.length?g[0]:d;return c.ctx&&i(c.ctx[u],c.ctx[u]=m)&&(!c.skip_bound&&c.bound[u]&&c.bound[u](m),f&&xn(e,u)),d}):[],c.update(),f=!0,ce(c.before_update),c.fragment=o?o(c.ctx):!1,t.target){if(t.hydrate){const u=Wn(t.target);c.fragment&&c.fragment.l(u),u.forEach(I)}else c.fragment&&c.fragment.c();t.intro&&P(e.$$.fragment),$(e,t.target,t.anchor),Dt()}Pe(l)}class ie{constructor(){Tt(this,"$$");Tt(this,"$$set")}$destroy(){ee(this,1),this.$destroy=X}$on(t,n){if(!q(n))return X;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!Vn(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $n="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($n);var K=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(K||{});const at={},ze=(e,t)=>at[e]=t,Fe=e=>at[e.type].area(e),Yt=(e,t,n)=>at[e.type].intersects(e,t,n),Ye=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},eo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),c=Math.sin(a),f=t-o,u=n-i,d=l*f+c*u,g=c*f-l*u;return d*d/(s*s)+g*g/(r*r)<=1}};ze(K.ELLIPSE,eo);const to={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let s=0,r=o.length-1;s<o.length;r=s++){const a=o[s][0],l=o[s][1],c=o[r][0],f=o[r][1];l>n!=f>n&&t<(c-a)*(n-l)/(f-l)+a&&(i=!i)}return i}};ze(K.POLYGON,to);const Rt={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};ze(K.RECTANGLE,Rt);const Ct=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,a,l,c,f,u]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,g,m,_]=[l,c,f,u].map(parseFloat);return{type:K.RECTANGLE,geometry:{x:d,y:g,w:m,h:_,bounds:{minX:d,minY:t?g-_:g,maxX:d+m,maxY:t?g:g+_}}}},Xt=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},Ut="http://www.w3.org/2000/svg",Nt=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},no=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Ut}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},oo=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Ut),i=n.lookupNamespaceURI(null);return o||i?Nt(n).firstChild:Nt(no(n)).firstChild},io=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:K.POLYGON,geometry:{points:i,bounds:Ye(i)}}},so=e=>{const t=oo(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:K.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Vt=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return io(t);if(t.includes("<ellipse "))return so(t);throw"Unsupported SVG shape: "+t},Gt=e=>{let t;if(e.type===K.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===K.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};for(var J=[],lt=0;lt<256;++lt)J.push((lt+256).toString(16).slice(1));function ro(e,t=0){return(J[e[t+0]]+J[e[t+1]]+J[e[t+2]]+J[e[t+3]]+"-"+J[e[t+4]]+J[e[t+5]]+"-"+J[e[t+6]]+J[e[t+7]]+"-"+J[e[t+8]]+J[e[t+9]]+"-"+J[e[t+10]]+J[e[t+11]]+J[e[t+12]]+J[e[t+13]]+J[e[t+14]]+J[e[t+15]]).toLowerCase()}var He,ao=new Uint8Array(16);function lo(){if(!He&&(He=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!He))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return He(ao)}var co=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const jt={randomUUID:co};function zt(e,t,n){if(jt.randomUUID&&!t&&!e)return jt.randomUUID();e=e||{};var o=e.random||(e.rng||lo)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,ro(o)}var Ft=Object.prototype.hasOwnProperty;function ye(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&ye(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ft.call(e,n)&&++o&&!Ft.call(t,n)||!(n in t)||!ye(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function ct(){}function fo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const Me=[];function ft(e,t=ct){let n;const o=new Set;function i(a){if(fo(e,a)&&(e=a,n)){const l=!Me.length;for(const c of o)c[1](),Me.push(c,e);if(l){for(let c=0;c<Me.length;c+=2)Me[c][0](Me[c+1]);Me.length=0}}}function s(a){i(a(e))}function r(a,l=ct){const c=[a,l];return o.add(c),o.size===1&&(n=t(i,s)||ct),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const uo=e=>{const{subscribe:t,set:n}=ft();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(r=>r.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Ht=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Ht||{});const We={selected:[]},ho=e=>{const{subscribe:t,set:n}=ft(We);let o,i=We;t(d=>i=d);const s=()=>{ye(i,We)||n(We)},r=()=>{var d;return((d=i.selected)==null?void 0:d.length)===0},a=d=>{if(r())return!1;const g=typeof d=="string"?d:d.id;return i.selected.some(m=>m.id===g)},l=(d,g)=>{const m=e.getAnnotation(d);if(!m){console.warn("Invalid selection: "+d);return}switch(Wt(m,o)){case"EDIT":n({selected:[{id:d,editable:!0}],event:g});break;case"SELECT":n({selected:[{id:d}],event:g});break;default:n({selected:[],event:g})}},c=(d,g)=>{const m=Array.isArray(d)?d:[d],_=m.map(T=>e.getAnnotation(T)).filter(T=>!!T);n({selected:_.map(T=>{const p=g===void 0?Wt(T,o)==="EDIT":g;return{id:T.id,editable:p}})}),_.length!==m.length&&console.warn("Invalid selection",d)},f=d=>{if(r())return!1;const{selected:g}=i;g.some(({id:m})=>d.includes(m))&&n({selected:g.filter(({id:m})=>!d.includes(m))})},u=d=>o=d;return e.observe(({changes:d})=>f((d.deleted||[]).map(g=>g.id))),{get event(){return i?i.event:null},get selected(){return i?[...i.selected]:null},get userSelectAction(){return o},clear:s,isEmpty:r,isSelected:a,setSelected:c,setUserSelectAction:u,subscribe:t,userSelect:l}},Wt=(e,t)=>typeof t=="function"?t(e):t||"EDIT";for(var Q=[],ut=0;ut<256;++ut)Q.push((ut+256).toString(16).slice(1));function go(e,t=0){return(Q[e[t+0]]+Q[e[t+1]]+Q[e[t+2]]+Q[e[t+3]]+"-"+Q[e[t+4]]+Q[e[t+5]]+"-"+Q[e[t+6]]+Q[e[t+7]]+"-"+Q[e[t+8]]+Q[e[t+9]]+"-"+Q[e[t+10]]+Q[e[t+11]]+Q[e[t+12]]+Q[e[t+13]]+Q[e[t+14]]+Q[e[t+15]]).toLowerCase()}var Ke,mo=new Uint8Array(16);function po(){if(!Ke&&(Ke=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ke))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ke(mo)}var yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Kt={randomUUID:yo};function _o(e,t,n){if(Kt.randomUUID&&!t&&!e)return Kt.randomUUID();e=e||{};var o=e.random||(e.rng||po)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,go(o)}const wo=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},bo=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Eo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!ye(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Ao=(e,t)=>!ye(e.target,t.target),qt=(e,t)=>{const n=wo(e,t),o=bo(e,t),i=Eo(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Ao(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var F=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(F||{});const So=(e,t)=>{var n,o;const{changes:i,origin:s}=t;if(!(!e.options.origin||e.options.origin===s))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(i.created)||a(i.deleted))){const l=(n=i.updated)==null?void 0:n.some(f=>a(f.bodiesCreated)||a(f.bodiesDeleted)||a(f.bodiesUpdated)),c=(o=i.updated)==null?void 0:o.some(f=>f.targetUpdated);if(r==="BODY_ONLY"&&l&&!c||r==="TARGET_ONLY"&&c&&!l)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(a=>a.id),...(i.deleted||[]).map(a=>a.id),...(i.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},To=(e,t)=>{const n=new Set((e.created||[]).map(u=>u.id)),o=new Set((e.updated||[]).map(({newValue:u})=>u.id)),i=new Set((t.created||[]).map(u=>u.id)),s=new Set((t.deleted||[]).map(u=>u.id)),r=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>n.has(u.id)||o.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(e.created||[]).filter(u=>!s.has(u.id)).map(u=>r.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],c=[...(e.deleted||[]).filter(u=>!i.has(u.id)),...(t.deleted||[]).filter(u=>!n.has(u.id))],f=[...(e.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:g}=u;if(r.has(g.id)){const m=t.updated.find(_=>_.oldValue.id===g.id).newValue;return qt(d,m)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:c,updated:f}},dt=e=>{const t=e.id===void 0?_o():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},vo=e=>e.id!==void 0,Mo=()=>{const e=new Map,t=new Map,n=[],o=(E,A={})=>n.push({onChange:E,options:A}),i=E=>{const A=n.findIndex(S=>S.onChange==E);A>-1&&n.splice(A,1)},s=(E,A)=>{const S={origin:E,changes:{created:A.created||[],updated:A.updated||[],deleted:A.deleted||[]},state:[...e.values()]};n.forEach(v=>{So(v,S)&&v.onChange(S)})},r=(E,A=F.LOCAL)=>{if(E.id&&e.get(E.id))throw Error(`Cannot add annotation ${E.id} - exists already`);{const S=dt(E);e.set(S.id,S),S.bodies.forEach(v=>t.set(v.id,S.id)),s(A,{created:[S]})}},a=(E,A)=>{const S=dt(typeof E=="string"?A:E),v=typeof E=="string"?E:E.id,V=v&&e.get(v);if(V){const C=qt(V,S);return v===S.id?e.set(v,S):(e.delete(v),e.set(S.id,S)),V.bodies.forEach(Z=>t.delete(Z.id)),S.bodies.forEach(Z=>t.set(Z.id,S.id)),C}else console.warn(`Cannot update annotation ${v} - does not exist`)},l=(E,A=F.LOCAL,S=F.LOCAL)=>{const v=vo(A)?S:A,V=a(E,A);V&&s(v,{updated:[V]})},c=(E,A=F.LOCAL)=>{const S=E.reduce((v,V)=>{const C=a(V);return C?[...v,C]:v},[]);S.length>0&&s(A,{updated:S})},f=(E,A=F.LOCAL)=>{const S=e.get(E.annotation);if(S){const v={...S,bodies:[...S.bodies,E]};e.set(S.id,v),t.set(E.id,v.id),s(A,{updated:[{oldValue:S,newValue:v,bodiesCreated:[E]}]})}else console.warn(`Attempt to add body to missing annotation: ${E.annotation}`)},u=()=>[...e.values()],d=(E=F.LOCAL)=>{const A=[...e.values()];e.clear(),t.clear(),s(E,{deleted:A})},g=(E,A=!0,S=F.LOCAL)=>{const v=E.map(dt);if(A){const V=[...e.values()];e.clear(),t.clear(),v.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),s(S,{created:v,deleted:V})}else{const V=E.reduce((C,Z)=>{const _e=Z.id&&e.get(Z.id);return _e?[...C,_e]:C},[]);if(V.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${V.map(C=>C.id).join(", ")}`);v.forEach(C=>{e.set(C.id,C),C.bodies.forEach(Z=>t.set(Z.id,C.id))}),s(S,{created:v})}},m=E=>{const A=typeof E=="string"?E:E.id,S=e.get(A);if(S)return e.delete(A),S.bodies.forEach(v=>t.delete(v.id)),S;console.warn(`Attempt to delete missing annotation: ${A}`)},_=(E,A=F.LOCAL)=>{const S=m(E);S&&s(A,{deleted:[S]})},T=(E,A=F.LOCAL)=>{const S=E.reduce((v,V)=>{const C=m(V);return C?[...v,C]:v},[]);S.length>0&&s(A,{deleted:S})},p=E=>{const A=e.get(E.annotation);if(A){const S=A.bodies.find(v=>v.id===E.id);if(S){t.delete(S.id);const v={...A,bodies:A.bodies.filter(V=>V.id!==E.id)};return e.set(A.id,v),{oldValue:A,newValue:v,bodiesDeleted:[S]}}else console.warn(`Attempt to delete missing body ${E.id} from annotation ${E.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${E.annotation}`)},w=(E,A=F.LOCAL)=>{const S=p(E);S&&s(A,{updated:[S]})},y=(E,A=F.LOCAL)=>{const S=E.map(v=>p(v)).filter(Boolean);S.length>0&&s(A,{updated:S})},b=E=>{const A=e.get(E);return A?{...A}:void 0},D=E=>{const A=t.get(E);if(A){const S=b(A).bodies.find(v=>v.id===E);if(S)return S;console.error(`Store integrity error: body ${E} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${E}`)},G=(E,A)=>{if(E.annotation!==A.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const S=e.get(E.annotation);if(S){const v=S.bodies.find(C=>C.id===E.id),V={...S,bodies:S.bodies.map(C=>C.id===v.id?A:C)};return e.set(S.id,V),v.id!==A.id&&(t.delete(v.id),t.set(A.id,V.id)),{oldValue:S,newValue:V,bodiesUpdated:[{oldBody:v,newBody:A}]}}else console.warn(`Attempt to add body to missing annotation ${E.annotation}`)},j=(E,A,S=F.LOCAL)=>{const v=G(E,A);v&&s(S,{updated:[v]})},z=(E,A=F.LOCAL)=>{const S=E.map(v=>G({id:v.id,annotation:v.annotation},v)).filter(Boolean);s(A,{updated:S})},Y=E=>{const A=e.get(E.annotation);if(A){const S={...A,target:{...A.target,...E}};return e.set(A.id,S),{oldValue:A,newValue:S,targetUpdated:{oldTarget:A.target,newTarget:E}}}else console.warn(`Attempt to update target on missing annotation: ${E.annotation}`)};return{addAnnotation:r,addBody:f,all:u,bulkAddAnnotation:g,bulkDeleteAnnotation:T,bulkDeleteBodies:y,bulkUpdateAnnotation:c,bulkUpdateBodies:z,bulkUpdateTargets:(E,A=F.LOCAL)=>{const S=E.map(v=>Y(v)).filter(Boolean);S.length>0&&s(A,{updated:S})},clear:d,deleteAnnotation:_,deleteBody:w,getAnnotation:b,getBody:D,observe:o,unobserve:i,updateAnnotation:l,updateBody:j,updateTarget:(E,A=F.LOCAL)=>{const S=Y(E);S&&s(A,{updated:[S]})}}},Lo=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let ko=()=>({emit(e,...t){for(let n=0,o=this.events[e]||[],i=o.length;n<i;n++)o[n](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Io=250,Oo=e=>{const t=ko(),n=[];let o=-1,i=!1,s=0;const r=g=>{if(!i){const{changes:m}=g,_=performance.now();if(_-s>Io)n.splice(o+1),n.push(m),o=n.length-1;else{const T=n.length-1;n[T]=To(n[T],m)}s=_}i=!1};e.observe(r,{origin:F.LOCAL});const a=g=>g&&g.length>0&&e.bulkDeleteAnnotation(g),l=g=>g&&g.length>0&&e.bulkAddAnnotation(g,!1),c=g=>g&&g.length>0&&e.bulkUpdateAnnotation(g.map(({oldValue:m})=>m)),f=g=>g&&g.length>0&&e.bulkUpdateAnnotation(g.map(({newValue:m})=>m)),u=g=>g&&g.length>0&&e.bulkAddAnnotation(g,!1),d=g=>g&&g.length>0&&e.bulkDeleteAnnotation(g);return{canRedo:()=>n.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(r),on:(g,m)=>t.on(g,m),redo:()=>{if(n.length-1>o){i=!0;const{created:g,updated:m,deleted:_}=n[o+1];l(g),f(m),d(_),t.emit("redo",n[o+1]),o+=1}},undo:()=>{if(o>-1){i=!0;const{created:g,updated:m,deleted:_}=n[o];a(g),c(m),u(_),t.emit("undo",n[o]),o-=1}}}},Bo=()=>{const{subscribe:e,set:t}=ft([]);return{subscribe:e,set:t}},Po=(e,t,n,o)=>{const{store:i,selection:s,hover:r,viewport:a}=e,l=new Map;let c=[],f,u;const d=(p,w)=>{l.has(p)?l.get(p).push(w):l.set(p,[w])},g=(p,w)=>{const y=l.get(p);if(y){const b=y.indexOf(w);b!==-1&&y.splice(b,1)}},m=(p,w,y)=>{l.has(p)&&setTimeout(()=>{l.get(p).forEach(b=>{if(n){const D=Array.isArray(w)?w.map(j=>n.serialize(j)):n.serialize(w),G=y?y instanceof PointerEvent?y:n.serialize(y):void 0;b(D,G)}else b(w,y)})},1)},_=()=>{const{selected:p}=s,w=(p||[]).map(({id:y})=>i.getAnnotation(y));w.forEach(y=>{const b=c.find(D=>D.id===y.id);(!b||!ye(b,y))&&m("updateAnnotation",y,b)}),c=c.map(y=>w.find(({id:D})=>D===y.id)||y)};s.subscribe(({selected:p})=>{if(!(c.length===0&&p.length===0)){if(c.length===0&&p.length>0)c=p.map(({id:w})=>i.getAnnotation(w));else if(c.length>0&&p.length===0)c.forEach(w=>{const y=i.getAnnotation(w.id);y&&!ye(y,w)&&m("updateAnnotation",y,w)}),c=[];else{const w=new Set(c.map(b=>b.id)),y=new Set(p.map(({id:b})=>b));c.filter(b=>!y.has(b.id)).forEach(b=>{const D=i.getAnnotation(b.id);D&&!ye(D,b)&&m("updateAnnotation",D,b)}),c=[...c.filter(b=>y.has(b.id)),...p.filter(({id:b})=>!w.has(b)).map(({id:b})=>i.getAnnotation(b))]}m("selectionChanged",c)}}),r.subscribe(p=>{!f&&p?m("mouseEnterAnnotation",i.getAnnotation(p)):f&&!p?m("mouseLeaveAnnotation",i.getAnnotation(f)):f&&p&&(m("mouseLeaveAnnotation",i.getAnnotation(f)),m("mouseEnterAnnotation",i.getAnnotation(p))),f=p}),a==null||a.subscribe(p=>m("viewportIntersect",p.map(w=>i.getAnnotation(w)))),i.observe(p=>{o&&(u&&clearTimeout(u),u=setTimeout(_,1e3));const{created:w,deleted:y}=p.changes;(w||[]).forEach(b=>m("createAnnotation",b)),(y||[]).forEach(b=>m("deleteAnnotation",b)),(p.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:D})=>{const G=c.find(j=>j.id===b.id)||b;c=c.map(j=>j.id===b.id?D:j),m("updateAnnotation",D,G)})},{origin:F.LOCAL}),i.observe(p=>{if(c){const w=new Set(c.map(b=>b.id)),y=(p.changes.updated||[]).filter(({newValue:b})=>w.has(b.id)).map(({newValue:b})=>b);y.length>0&&(c=c.map(b=>y.find(G=>G.id===b.id)||b))}},{origin:F.REMOTE});const T=p=>w=>{const{updated:y}=w;p?(y||[]).forEach(b=>m("updateAnnotation",b.oldValue,b.newValue)):(y||[]).forEach(b=>m("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",T(!0)),t.on("redo",T(!1)),{on:d,off:g,emit:m}},Do=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Yo=(e,t,n)=>{const{store:o,selection:i}=e,s=p=>{if(n){const{parsed:w,error:y}=n.parse(p);w?o.addAnnotation(w,F.REMOTE):console.error(y)}else o.addAnnotation(p,F.REMOTE)},r=()=>i.clear(),a=()=>o.clear(),l=p=>{const w=o.getAnnotation(p);return n&&w?n.serialize(w):w},c=()=>n?o.all().map(n.serialize):o.all(),f=()=>{var p;const w=(((p=i.selected)==null?void 0:p.map(y=>y.id))||[]).map(y=>o.getAnnotation(y)).filter(Boolean);return n?w.map(n.serialize):w},u=(p,w=!0)=>fetch(p).then(y=>y.json()).then(y=>(g(y,w),y)),d=p=>{if(typeof p=="string"){const w=o.getAnnotation(p);if(o.deleteAnnotation(p),w)return n?n.serialize(w):w}else{const w=n?n.parse(p).parsed:p;if(w)return o.deleteAnnotation(w),p}},g=(p,w=!0)=>{if(n){const{parsed:y,failed:b}=Do(n)(p);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),o.bulkAddAnnotation(y,w,F.REMOTE)}else o.bulkAddAnnotation(p,w,F.REMOTE)},m=(p,w)=>{p?i.setSelected(p,w):i.clear()},_=p=>{i.clear(),i.setUserSelectAction(p)},T=p=>{if(n){const w=n.parse(p).parsed,y=n.serialize(o.getAnnotation(w.id));return o.updateAnnotation(w),y}else{const w=o.getAnnotation(p.id);return o.updateAnnotation(p),w}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:c,getSelected:f,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:g,setSelected:m,setUserSelectAction:_,undo:t.undo,updateAnnotation:T}},Ro="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Co=e=>crypto.getRandomValues(new Uint8Array(e)),Xo=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(i),l=i;for(;l--;)if(r+=e[a[l]&o]||"",r.length===s)return r}}},Uo=(e,t=21)=>Xo(e,t,Co),No=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=Ro[n[e]&63];return t};const Vo=()=>({isGuest:!0,id:Uo("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Go=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Jt=e=>e?typeof e=="object"?{...e}:e:void 0,jo=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,modified:l,creator:c,...f}=n;return{id:o||`temp-${Go(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Jt(c),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...f}}),zo=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,a={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a});No();const Fo=(e,t={strict:!0,invertY:!1})=>({parse:i=>Qt(i,t),serialize:i=>Zt(i,e,t)}),Qt=(e,t={strict:!0,invertY:!1})=>{const n=e.id||zt(),{creator:o,created:i,modified:s,body:r,...a}=e,l=jo(r||[],n),c=Array.isArray(e.target)?e.target[0]:e.target,f=Array.isArray(c.selector)?c.selector[0]:c.selector,u=(f==null?void 0:f.type)==="FragmentSelector"?Ct(f,t.invertY):(f==null?void 0:f.type)==="SvgSelector"?Vt(f):void 0;return u||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:i?new Date(i):void 0,creator:Jt(o),updated:s?new Date(s):void 0,...Array.isArray(a.target)?a.target[0]:a.target,annotation:n,selector:u||f}}}:{error:Error(`Invalid selector: ${JSON.stringify(f)}`)}},Zt=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:a,...l}=e.target;let c;try{c=o.type==K.RECTANGLE?Xt(o.geometry):Gt(o)}catch(u){if(n.strict)throw u;c=o}const f={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:zo(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...l,source:t,selector:c}};return delete f.bodies,"annotation"in f.target&&delete f.target.annotation,f};function xt(e,t,n){const o=e.slice();return o[10]=t[n],o[12]=n,o}function $t(e){let t,n;return t=new ke({props:{x:e[10][0],y:e[10][1],scale:e[3]}}),t.$on("pointerdown",function(){q(e[9](`HANDLE-${e[12]}`))&&e[9](`HANDLE-${e[12]}`).apply(this,arguments)}),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const s={};i&16&&(s.x=e[10][0]),i&16&&(s.y=e[10][1]),i&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ho(e){let t,n,o,i,s,r,a,l,c,f,u,d=ve(e[4].points),g=[];for(let _=0;_<d.length;_+=1)g[_]=$t(xt(e,d,_));const m=_=>U(g[_],1,1,()=>{g[_]=null});return{c(){t=N("polygon"),i=se(),s=N("polygon"),a=se();for(let _=0;_<g.length;_+=1)g[_].c();l=re(),h(t,"class","a9s-outer"),h(t,"style",n=e[1]?"display:none;":void 0),h(t,"points",o=e[4].points.map(en).join(" ")),h(s,"class","a9s-inner a9s-shape-handle"),h(s,"style",e[1]),h(s,"points",r=e[4].points.map(tn).join(" "))},m(_,T){B(_,t,T),B(_,i,T),B(_,s,T),B(_,a,T);for(let p=0;p<g.length;p+=1)g[p]&&g[p].m(_,T);B(_,l,T),c=!0,f||(u=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(s,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)})],f=!0)},p(_,T){if(e=_,(!c||T&2&&n!==(n=e[1]?"display:none;":void 0))&&h(t,"style",n),(!c||T&16&&o!==(o=e[4].points.map(en).join(" ")))&&h(t,"points",o),(!c||T&2)&&h(s,"style",e[1]),(!c||T&16&&r!==(r=e[4].points.map(tn).join(" ")))&&h(s,"points",r),T&536){d=ve(e[4].points);let p;for(p=0;p<d.length;p+=1){const w=xt(e,d,p);g[p]?(g[p].p(w,T),P(g[p],1)):(g[p]=$t(w),g[p].c(),P(g[p],1),g[p].m(l.parentNode,l))}for(ae(),p=d.length;p<g.length;p+=1)m(p);le()}},i(_){if(!c){for(let T=0;T<d.length;T+=1)P(g[T]);c=!0}},o(_){g=g.filter(Boolean);for(let T=0;T<g.length;T+=1)U(g[T]);c=!1},d(_){_&&(I(t),I(i),I(s),I(a),I(l)),ot(g,_),f=!1,ce(u)}}}function Wo(e){let t,n;return t=new ht({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Ho,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("change",e[6]),t.$on("grab",e[7]),t.$on("release",e[8]),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&8730&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}const en=e=>e.join(","),tn=e=>e.join(",");function Ko(e,t,n){let o,{shape:i}=t,{computedStyle:s}=t,{transform:r}=t,{viewportScale:a=1}=t;const l=(d,g,m)=>{let _;const T=d.geometry;g==="SHAPE"?_=T.points.map(([w,y])=>[w+m[0],y+m[1]]):_=T.points.map(([w,y],b)=>g===`HANDLE-${b}`?[w+m[0],y+m[1]]:[w,y]);const p=Ye(_);return{...d,geometry:{points:_,bounds:p}}};function c(d){ge.call(this,e,d)}function f(d){ge.call(this,e,d)}function u(d){ge.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,i=d.shape),"computedStyle"in d&&n(1,s=d.computedStyle),"transform"in d&&n(2,r=d.transform),"viewportScale"in d&&n(3,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,s,r,a,o,l,c,f,u]}class nn extends ie{constructor(t){super(),oe(this,t,Ko,Wo,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const qe=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},Le=[];function qo(e,t=X){let n;const o=new Set;function i(a){if(x(e,a)&&(e=a,n)){const l=!Le.length;for(const c of o)c[1](),Le.push(c,e);if(l){for(let c=0;c<Le.length;c+=2)Le[c][0](Le[c+1]);Le.length=0}}}function s(a){i(a(e))}function r(a,l=X){const c=[a,l];return o.add(c),o.size===1&&(n=t(i,s)||X),a(e),()=>{o.delete(c),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Jo=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},on=(e,t)=>{Jo(e,t);const{subscribe:n,set:o}=qo(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,c=Math.max(r.width/a,r.height/l);o(c)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},sn=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Qo(e){let t,n,o,i,s,r;return{c(){t=N("rect"),h(t,"class",n=Ve(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),h(t,"x",o=e[0]-e[5]/2),h(t,"y",i=e[1]-e[5]/2),h(t,"width",e[5]),h(t,"height",e[5])},m(a,l){B(a,t,l),s||(r=W(t,"pointerdown",e[11]),s=!0)},p(a,l){l&256&&n!==(n=Ve(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&h(t,"class",n),l&33&&o!==(o=a[0]-a[5]/2)&&h(t,"x",o),l&34&&i!==(i=a[1]-a[5]/2)&&h(t,"y",i),l&32&&h(t,"width",a[5]),l&32&&h(t,"height",a[5])},d(a){a&&I(t),s=!1,r()}}}function Zo(e){let t,n,o,i,s,r,a,l,c;return{c(){t=N("g"),n=N("circle"),i=N("rect"),h(n,"cx",e[0]),h(n,"cy",e[1]),h(n,"r",o=e[3]/e[2]),h(n,"class","a9s-touch-halo svelte-1sgkh33"),pe(n,"touched",e[4]),h(i,"class",s=Ve(`a9s-handle ${e[8].class||""}`.trim())+" svelte-1sgkh33"),h(i,"x",r=e[0]-e[5]/2),h(i,"y",a=e[1]-e[5]/2),h(i,"width",e[5]),h(i,"height",e[5]),h(t,"class","a9s-touch-handle")},m(f,u){B(f,t,u),fe(t,n),fe(t,i),l||(c=[W(n,"pointerdown",e[10]),W(n,"pointerdown",e[6]),W(n,"pointerup",e[7]),W(i,"pointerdown",e[9]),W(i,"pointerdown",e[6]),W(i,"pointerup",e[7])],l=!0)},p(f,u){u&1&&h(n,"cx",f[0]),u&2&&h(n,"cy",f[1]),u&12&&o!==(o=f[3]/f[2])&&h(n,"r",o),u&16&&pe(n,"touched",f[4]),u&256&&s!==(s=Ve(`a9s-handle ${f[8].class||""}`.trim())+" svelte-1sgkh33")&&h(i,"class",s),u&33&&r!==(r=f[0]-f[5]/2)&&h(i,"x",r),u&34&&a!==(a=f[1]-f[5]/2)&&h(i,"y",a),u&32&&h(i,"width",f[5]),u&32&&h(i,"height",f[5])},d(f){f&&I(t),l=!1,ce(c)}}}function xo(e){let t;function n(s,r){return sn?Zo:Qo}let i=n()(e);return{c(){i.c(),t=re()},m(s,r){i.m(s,r),B(s,t,r)},p(s,[r]){i.p(s,r)},i:X,o:X,d(s){s&&I(t),i.d(s)}}}function $o(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{radius:a=30}=t,l=!1;const c=m=>{m.pointerType==="touch"&&n(4,l=!0)},f=()=>n(4,l=!1);function u(m){ge.call(this,e,m)}function d(m){ge.call(this,e,m)}function g(m){ge.call(this,e,m)}return e.$$set=m=>{n(8,t=me(me({},t),It(m))),"x"in m&&n(0,i=m.x),"y"in m&&n(1,s=m.y),"scale"in m&&n(2,r=m.scale),"radius"in m&&n(3,a=m.radius)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=10/r)},t=It(t),[i,s,r,a,l,o,c,f,t,u,d,g]}class ke extends ie{constructor(t){super(),oe(this,t,$o,xo,x,{x:0,y:1,scale:2,radius:3})}}function ei(e){let t,n,o,i,s,r,a,l,c,f,u,d,g,m,_,T,p,w,y,b,D,G,j,z,Y,E,A,S,v,V,C,Z,_e,ue,Ue,de,Ne,he,k,H,O,te,we;return ue=new ke({props:{class:"a9s-corner-handle-topleft",x:e[4].x,y:e[4].y,scale:e[3]}}),ue.$on("pointerdown",function(){q(e[9]("TOP_LEFT"))&&e[9]("TOP_LEFT").apply(this,arguments)}),de=new ke({props:{class:"a9s-corner-handle-topright",x:e[4].x+e[4].w,y:e[4].y,scale:e[3]}}),de.$on("pointerdown",function(){q(e[9]("TOP_RIGHT"))&&e[9]("TOP_RIGHT").apply(this,arguments)}),he=new ke({props:{class:"a9s-corner-handle-bottomright",x:e[4].x+e[4].w,y:e[4].y+e[4].h,scale:e[3]}}),he.$on("pointerdown",function(){q(e[9]("BOTTOM_RIGHT"))&&e[9]("BOTTOM_RIGHT").apply(this,arguments)}),H=new ke({props:{class:"a9s-corner-handle-bottomleft",x:e[4].x,y:e[4].y+e[4].h,scale:e[3]}}),H.$on("pointerdown",function(){q(e[9]("BOTTOM_LEFT"))&&e[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=N("rect"),a=se(),l=N("rect"),g=se(),m=N("rect"),w=se(),y=N("rect"),j=se(),z=N("rect"),S=se(),v=N("rect"),_e=se(),ne(ue.$$.fragment),Ue=se(),ne(de.$$.fragment),Ne=se(),ne(he.$$.fragment),k=se(),ne(H.$$.fragment),h(t,"class","a9s-outer"),h(t,"style",n=e[1]?"display:none;":void 0),h(t,"x",o=e[4].x),h(t,"y",i=e[4].y),h(t,"width",s=e[4].w),h(t,"height",r=e[4].h),h(l,"class","a9s-inner a9s-shape-handle"),h(l,"style",e[1]),h(l,"x",c=e[4].x),h(l,"y",f=e[4].y),h(l,"width",u=e[4].w),h(l,"height",d=e[4].h),h(m,"class","a9s-edge-handle a9s-edge-handle-top"),h(m,"x",_=e[4].x),h(m,"y",T=e[4].y),h(m,"height",1),h(m,"width",p=e[4].w),h(y,"class","a9s-edge-handle a9s-edge-handle-right"),h(y,"x",b=e[4].x+e[4].w),h(y,"y",D=e[4].y),h(y,"height",G=e[4].h),h(y,"width",1),h(z,"class","a9s-edge-handle a9s-edge-handle-bottom"),h(z,"x",Y=e[4].x),h(z,"y",E=e[4].y+e[4].h),h(z,"height",1),h(z,"width",A=e[4].w),h(v,"class","a9s-edge-handle a9s-edge-handle-left"),h(v,"x",V=e[4].x),h(v,"y",C=e[4].y),h(v,"height",Z=e[4].h),h(v,"width",1)},m(R,M){B(R,t,M),B(R,a,M),B(R,l,M),B(R,g,M),B(R,m,M),B(R,w,M),B(R,y,M),B(R,j,M),B(R,z,M),B(R,S,M),B(R,v,M),B(R,_e,M),$(ue,R,M),B(R,Ue,M),$(de,R,M),B(R,Ne,M),$(he,R,M),B(R,k,M),$(H,R,M),O=!0,te||(we=[W(t,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(l,"pointerdown",function(){q(e[9]("SHAPE"))&&e[9]("SHAPE").apply(this,arguments)}),W(m,"pointerdown",function(){q(e[9]("TOP"))&&e[9]("TOP").apply(this,arguments)}),W(y,"pointerdown",function(){q(e[9]("RIGHT"))&&e[9]("RIGHT").apply(this,arguments)}),W(z,"pointerdown",function(){q(e[9]("BOTTOM"))&&e[9]("BOTTOM").apply(this,arguments)}),W(v,"pointerdown",function(){q(e[9]("LEFT"))&&e[9]("LEFT").apply(this,arguments)})],te=!0)},p(R,M){e=R,(!O||M&2&&n!==(n=e[1]?"display:none;":void 0))&&h(t,"style",n),(!O||M&16&&o!==(o=e[4].x))&&h(t,"x",o),(!O||M&16&&i!==(i=e[4].y))&&h(t,"y",i),(!O||M&16&&s!==(s=e[4].w))&&h(t,"width",s),(!O||M&16&&r!==(r=e[4].h))&&h(t,"height",r),(!O||M&2)&&h(l,"style",e[1]),(!O||M&16&&c!==(c=e[4].x))&&h(l,"x",c),(!O||M&16&&f!==(f=e[4].y))&&h(l,"y",f),(!O||M&16&&u!==(u=e[4].w))&&h(l,"width",u),(!O||M&16&&d!==(d=e[4].h))&&h(l,"height",d),(!O||M&16&&_!==(_=e[4].x))&&h(m,"x",_),(!O||M&16&&T!==(T=e[4].y))&&h(m,"y",T),(!O||M&16&&p!==(p=e[4].w))&&h(m,"width",p),(!O||M&16&&b!==(b=e[4].x+e[4].w))&&h(y,"x",b),(!O||M&16&&D!==(D=e[4].y))&&h(y,"y",D),(!O||M&16&&G!==(G=e[4].h))&&h(y,"height",G),(!O||M&16&&Y!==(Y=e[4].x))&&h(z,"x",Y),(!O||M&16&&E!==(E=e[4].y+e[4].h))&&h(z,"y",E),(!O||M&16&&A!==(A=e[4].w))&&h(z,"width",A),(!O||M&16&&V!==(V=e[4].x))&&h(v,"x",V),(!O||M&16&&C!==(C=e[4].y))&&h(v,"y",C),(!O||M&16&&Z!==(Z=e[4].h))&&h(v,"height",Z);const xe={};M&16&&(xe.x=e[4].x),M&16&&(xe.y=e[4].y),M&8&&(xe.scale=e[3]),ue.$set(xe);const $e={};M&16&&($e.x=e[4].x+e[4].w),M&16&&($e.y=e[4].y),M&8&&($e.scale=e[3]),de.$set($e);const et={};M&16&&(et.x=e[4].x+e[4].w),M&16&&(et.y=e[4].y+e[4].h),M&8&&(et.scale=e[3]),he.$set(et);const tt={};M&16&&(tt.x=e[4].x),M&16&&(tt.y=e[4].y+e[4].h),M&8&&(tt.scale=e[3]),H.$set(tt)},i(R){O||(P(ue.$$.fragment,R),P(de.$$.fragment,R),P(he.$$.fragment,R),P(H.$$.fragment,R),O=!0)},o(R){U(ue.$$.fragment,R),U(de.$$.fragment,R),U(he.$$.fragment,R),U(H.$$.fragment,R),O=!1},d(R){R&&(I(t),I(a),I(l),I(g),I(m),I(w),I(y),I(j),I(z),I(S),I(v),I(_e),I(Ue),I(Ne),I(k)),ee(ue,R),ee(de,R),ee(he,R),ee(H,R),te=!1,ce(we)}}}function ti(e){let t,n;return t=new ht({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[ei,({grab:o})=>({9:o}),({grab:o})=>o?512:0]},$$scope:{ctx:e}}}),t.$on("grab",e[6]),t.$on("change",e[7]),t.$on("release",e[8]),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&1562&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function ni(e,t,n){let o,{shape:i}=t,{computedStyle:s}=t,{transform:r}=t,{viewportScale:a=1}=t;const l=(d,g,m)=>{const _=d.geometry.bounds;let[T,p]=[_.minX,_.minY],[w,y]=[_.maxX,_.maxY];const[b,D]=m;if(g==="SHAPE")T+=b,w+=b,p+=D,y+=D;else{switch(g){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{p+=D;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{y+=D;break}}switch(g){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{T+=b;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{w+=b;break}}}const G=Math.min(T,w),j=Math.min(p,y),z=Math.abs(w-T),Y=Math.abs(y-p);return{...d,geometry:{x:G,y:j,w:z,h:Y,bounds:{minX:G,minY:j,maxX:G+z,maxY:j+Y}}}};function c(d){ge.call(this,e,d)}function f(d){ge.call(this,e,d)}function u(d){ge.call(this,e,d)}return e.$$set=d=>{"shape"in d&&n(0,i=d.shape),"computedStyle"in d&&n(1,s=d.computedStyle),"transform"in d&&n(2,r=d.transform),"viewportScale"in d&&n(3,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=i.geometry)},[i,s,r,a,o,l,c,f,u]}class rn extends ie{constructor(t){super(),oe(this,t,ni,ti,x,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const an=new Map([[K.RECTANGLE,rn],[K.POLYGON,nn]]),ln=e=>an.get(e.type),cn=(e,t)=>an.set(e,t),oi=e=>({}),fn=e=>({grab:e[0]});function ii(e){let t,n,o,i;const s=e[7].default,r=Gn(s,e,e[6],fn);return{c(){t=N("g"),r&&r.c(),h(t,"class","a9s-annotation selected")},m(a,l){B(a,t,l),r&&r.m(t,null),n=!0,o||(i=[W(t,"pointerup",e[2]),W(t,"pointermove",e[1])],o=!0)},p(a,[l]){r&&r.p&&(!n||l&64)&&zn(r,s,a,a[6],n?jn(s,a[6],l,oi):Fn(a[6]),fn)},i(a){n||(P(r,a),n=!0)},o(a){U(r,a),n=!1},d(a){a&&I(t),r&&r.d(a),o=!1,ce(i)}}}function si(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Ee();let{shape:r}=t,{editor:a}=t,{transform:l}=t,c,f,u;const d=_=>T=>{c=_,f=l.elementToImage(T.offsetX,T.offsetY),u=r,T.target.setPointerCapture(T.pointerId),s("grab",T)},g=_=>{if(c){const[T,p]=l.elementToImage(_.offsetX,_.offsetY),w=[T-f[0],p-f[1]];n(3,r=a(u,c,w)),s("change",r)}},m=_=>{_.target.releasePointerCapture(_.pointerId),c=void 0,u=r,s("release",_)};return e.$$set=_=>{"shape"in _&&n(3,r=_.shape),"editor"in _&&n(4,a=_.editor),"transform"in _&&n(5,l=_.transform),"$$scope"in _&&n(6,i=_.$$scope)},[d,g,m,r,a,l,i,o]}class ht extends ie{constructor(t){super(),oe(this,t,si,ii,x,{shape:3,editor:4,transform:5})}}const Je=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:a}=n;let l="";return o&&(l+=`fill:${o};`,l+=`fill-opacity:${i||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${r||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}};function ri(e,t,n){let o;const i=Ee();let{annotation:s}=t,{editor:r}=t,{style:a}=t,{target:l}=t,{transform:c}=t,{viewportScale:f}=t,u;return De(()=>(n(6,u=new r({target:l,props:{shape:s.target.selector,computedStyle:o,transform:c,viewportScale:f}})),u.$on("change",d=>{u.$$set({shape:d.detail}),i("change",d.detail)}),u.$on("grab",d=>i("grab",d.detail)),u.$on("release",d=>i("release",d.detail)),()=>{u.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,c=d.transform),"viewportScale"in d&&n(5,f=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Je(s,a)),e.$$.dirty&65&&s&&(u==null||u.$set({shape:s.target.selector})),e.$$.dirty&80&&u&&u.$set({transform:c}),e.$$.dirty&96&&u&&u.$set({viewportScale:f})},[s,r,a,l,c,f,u]}class un extends ie{constructor(t){super(),oe(this,t,ri,null,x,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function ai(e,t,n){const o=Ee();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,c;return De(()=>{const f=s.closest("svg"),u=[],d=(g,m,_)=>{f==null||f.addEventListener(g,m,_),u.push(()=>f==null?void 0:f.removeEventListener(g,m,_))};return n(5,c=new r({target:s,props:{addEventListener:d,drawingMode:i,transform:a,viewportScale:l}})),c.$on("create",g=>o("create",g.detail)),()=>{u.forEach(g=>g()),c.$destroy()}}),e.$$set=f=>{"drawingMode"in f&&n(0,i=f.drawingMode),"target"in f&&n(1,s=f.target),"tool"in f&&n(2,r=f.tool),"transform"in f&&n(3,a=f.transform),"viewportScale"in f&&n(4,l=f.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&c&&c.$set({transform:a}),e.$$.dirty&48&&c&&c.$set({viewportScale:l})},[i,s,r,a,l,c]}class dn extends ie{constructor(t){super(),oe(this,t,ai,null,x,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function hn(e){let t,n;return{c(){t=N("rect"),n=N("rect"),h(t,"class","a9s-outer"),h(t,"x",e[1]),h(t,"y",e[2]),h(t,"width",e[3]),h(t,"height",e[4]),h(n,"class","a9s-inner"),h(n,"x",e[1]),h(n,"y",e[2]),h(n,"width",e[3]),h(n,"height",e[4])},m(o,i){B(o,t,i),B(o,n,i)},p(o,i){i&2&&h(t,"x",o[1]),i&4&&h(t,"y",o[2]),i&8&&h(t,"width",o[3]),i&16&&h(t,"height",o[4]),i&2&&h(n,"x",o[1]),i&4&&h(n,"y",o[2]),i&8&&h(n,"width",o[3]),i&16&&h(n,"height",o[4])},d(o){o&&(I(t),I(n))}}}function li(e){let t,n=e[0]&&hn(e);return{c(){t=N("g"),n&&n.c(),h(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=hn(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}function ci(e,t,n){const o=Ee();let{addEventListener:i}=t,{drawingMode:s}=t,{transform:r}=t,a,l,c,f,u,d,g;const m=w=>{const y=w;a=performance.now(),s==="drag"&&(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,f=l[0]),n(2,u=l[1]),n(3,d=1),n(4,g=1))},_=w=>{const y=w;l&&(c=r.elementToImage(y.offsetX,y.offsetY),n(1,f=Math.min(c[0],l[0])),n(2,u=Math.min(c[1],l[1])),n(3,d=Math.abs(c[0]-l[0])),n(4,g=Math.abs(c[1]-l[1])))},T=w=>{const y=w,b=performance.now()-a;if(s==="click"){if(b>300)return;l?p():(n(0,l=r.elementToImage(y.offsetX,y.offsetY)),c=l,n(1,f=l[0]),n(2,u=l[1]),n(3,d=1),n(4,g=1))}else l&&(b>300||d*g>100?(y.stopPropagation(),p()):(n(0,l=void 0),c=void 0))},p=()=>{if(d*g>15){const w={type:K.RECTANGLE,geometry:{bounds:{minX:f,minY:u,maxX:f+d,maxY:u+g},x:f,y:u,w:d,h:g}};o("create",w)}n(0,l=void 0),c=void 0};return De(()=>{i("pointerdown",m),i("pointermove",_),i("pointerup",T,!0)}),e.$$set=w=>{"addEventListener"in w&&n(5,i=w.addEventListener),"drawingMode"in w&&n(6,s=w.drawingMode),"transform"in w&&n(7,r=w.transform)},[l,f,u,d,g,i,s,r]}class gn extends ie{constructor(t){super(),oe(this,t,ci,li,x,{addEventListener:5,drawingMode:6,transform:7})}}function gt(e){const t=e.slice(),n=(t[2]?t[0]:[...t[0],t[1]]).map(o=>o.join(",")).join(" ");return t[16]=n,t}function mn(e){let t,n,o,i,s,r=e[2]&&pn(e);return{c(){t=N("polygon"),o=N("polygon"),r&&r.c(),s=re(),h(t,"class","a9s-outer"),h(t,"points",n=e[16]),h(o,"class","a9s-inner"),h(o,"points",i=e[16])},m(a,l){B(a,t,l),B(a,o,l),r&&r.m(a,l),B(a,s,l)},p(a,l){l&7&&n!==(n=a[16])&&h(t,"points",n),l&7&&i!==(i=a[16])&&h(o,"points",i),a[2]?r?r.p(a,l):(r=pn(a),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(a){a&&(I(t),I(o),I(s)),r&&r.d(a)}}}function pn(e){let t,n,o;return{c(){t=N("rect"),h(t,"class","a9s-corner-handle"),h(t,"x",n=e[0][0][0]-e[3]/2),h(t,"y",o=e[0][0][1]-e[3]/2),h(t,"height",e[3]),h(t,"width",e[3])},m(i,s){B(i,t,s)},p(i,s){s&9&&n!==(n=i[0][0][0]-i[3]/2)&&h(t,"x",n),s&9&&o!==(o=i[0][0][1]-i[3]/2)&&h(t,"y",o),s&8&&h(t,"height",i[3]),s&8&&h(t,"width",i[3])},d(i){i&&I(t)}}}function fi(e){let t,n=e[1]&&mn(gt(e));return{c(){t=N("g"),n&&n.c(),h(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null)},p(o,[i]){o[1]?n?n.p(gt(o),i):(n=mn(gt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:X,o:X,d(o){o&&I(t),n&&n.d()}}}const ui=20,di=1500;function hi(e,t,n){let o;const i=Ee();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,c,f=[],u,d,g=!1;const m=y=>{const b=y,{timeStamp:D,offsetX:G,offsetY:j}=b;if(c={timeStamp:D,offsetX:G,offsetY:j},r==="drag"&&f.length===0){const z=a.elementToImage(b.offsetX,b.offsetY);f.push(z),n(1,u=z)}},_=y=>{const b=y;if(d&&clearTimeout(d),f.length>0){if(n(1,u=a.elementToImage(b.offsetX,b.offsetY)),f.length>2){const D=qe(u,f[0])*l;n(2,g=D<ui)}b.pointerType==="touch"&&(d=setTimeout(()=>{p()},di))}},T=y=>{const b=y;if(d&&clearTimeout(d),r==="click"){const D=b.timeStamp-c.timeStamp,G=qe([c.offsetX,c.offsetY],[b.offsetX,b.offsetY]);if(D>300||G>15)return;if(g)w();else if(f.length===0){const j=a.elementToImage(b.offsetX,b.offsetY);f.push(j),n(1,u=j)}else f.push(u)}else{if(f.length===1&&qe(f[0],u)<=4){n(0,f=[]),n(1,u=void 0);return}b.stopImmediatePropagation(),g?w():f.push(u)}},p=()=>{if(!u)return;const y=[...f,u],b={type:K.POLYGON,geometry:{bounds:Ye(y),points:y}};Fe(b)>4&&(n(0,f=[]),n(1,u=void 0),i("create",b))},w=()=>{const y={type:K.POLYGON,geometry:{bounds:Ye(f),points:[...f]}};n(0,f=[]),n(1,u=void 0),i("create",y)};return De(()=>{s("pointerdown",m,!0),s("pointermove",_),s("pointerup",T,!0),s("dblclick",p,!0)}),e.$$set=y=>{"addEventListener"in y&&n(4,s=y.addEventListener),"drawingMode"in y&&n(5,r=y.drawingMode),"transform"in y&&n(6,a=y.transform),"viewportScale"in y&&n(7,l=y.viewportScale)},e.$$.update=()=>{e.$$.dirty&128&&n(3,o=10/l)},[f,u,g,o,s,r,a,l]}class gi extends ie{constructor(t){super(),oe(this,t,hi,fi,x,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const mt=new Map([["rectangle",{tool:gn}],["polygon",{tool:gi}]]),pt=()=>[...mt.keys()],yt=e=>mt.get(e),yn=(e,t,n)=>mt.set(e,{tool:t,opts:n});function mi(e){let t,n,o,i,s;return{c(){t=N("g"),n=N("ellipse"),i=N("ellipse"),h(n,"class","a9s-outer"),h(n,"style",o=e[1]?"display:none;":void 0),h(n,"cx",e[2]),h(n,"cy",e[3]),h(n,"rx",e[4]),h(n,"ry",e[5]),h(i,"class","a9s-inner"),h(i,"style",e[1]),h(i,"cx",e[2]),h(i,"cy",e[3]),h(i,"rx",e[4]),h(i,"ry",e[5]),h(t,"class","a9s-annotation"),h(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),fe(t,n),fe(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&h(n,"style",o),a&2&&h(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&h(t,"data-id",s)},i:X,o:X,d(r){r&&I(t)}}}function pi(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:a,cy:l,rx:c,ry:f}=s;return e.$$set=u=>{"annotation"in u&&n(0,i=u.annotation),"geom"in u&&n(6,s=u.geom),"style"in u&&n(7,r=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Je(i,r))},[i,o,a,l,c,f,s,r]}class yi extends ie{constructor(t){super(),oe(this,t,pi,mi,x,{annotation:0,geom:6,style:7})}}function _i(e){let t,n,o,i,s;return{c(){t=N("g"),n=N("polygon"),i=N("polygon"),h(n,"class","a9s-outer"),h(n,"style",o=e[1]?"display:none;":void 0),h(n,"points",e[2].map(wi).join(" ")),h(i,"class","a9s-inner"),h(i,"style",e[1]),h(i,"points",e[2].map(bi).join(" ")),h(t,"class","a9s-annotation"),h(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),fe(t,n),fe(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&h(n,"style",o),a&2&&h(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&h(t,"data-id",s)},i:X,o:X,d(r){r&&I(t)}}}const wi=e=>e.join(","),bi=e=>e.join(",");function Ei(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,i=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Je(i,r))},[i,o,a,s,r]}class Ai extends ie{constructor(t){super(),oe(this,t,Ei,_i,x,{annotation:0,geom:3,style:4})}}function Si(e){let t,n,o,i,s;return{c(){t=N("g"),n=N("rect"),i=N("rect"),h(n,"class","a9s-outer"),h(n,"style",o=e[5]?"display:none;":void 0),h(n,"x",e[4]),h(n,"y",e[3]),h(n,"width",e[2]),h(n,"height",e[1]),h(i,"class","a9s-inner"),h(i,"style",e[5]),h(i,"x",e[4]),h(i,"y",e[3]),h(i,"width",e[2]),h(i,"height",e[1]),h(t,"class","a9s-annotation"),h(t,"data-id",s=e[0].id)},m(r,a){B(r,t,a),fe(t,n),fe(t,i)},p(r,[a]){a&32&&o!==(o=r[5]?"display:none;":void 0)&&h(n,"style",o),a&16&&h(n,"x",r[4]),a&8&&h(n,"y",r[3]),a&4&&h(n,"width",r[2]),a&2&&h(n,"height",r[1]),a&32&&h(i,"style",r[5]),a&16&&h(i,"x",r[4]),a&8&&h(i,"y",r[3]),a&4&&h(i,"width",r[2]),a&2&&h(i,"height",r[1]),a&1&&s!==(s=r[0].id)&&h(t,"data-id",s)},i:X,o:X,d(r){r&&I(t)}}}function Ti(e,t,n){let o,i,s,r,a,{annotation:l}=t,{geom:c}=t,{style:f}=t;return e.$$set=u=>{"annotation"in u&&n(0,l=u.annotation),"geom"in u&&n(6,c=u.geom),"style"in u&&n(7,f=u.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Je(l,f)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:a}=c,i,(n(3,s),n(6,c)),(n(2,r),n(6,c)),(n(1,a),n(6,c)))},[l,a,r,s,i,o,c,f]}class vi extends ie{constructor(t){super(),oe(this,t,Ti,Si,x,{annotation:0,geom:6,style:7})}}const Mi={elementToImage:(e,t)=>[e,t]},_n=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),Li=250,wn=(e,t)=>{const n=Ee();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<Li){const{x:l,y:c}=_t(r,e),f=t.getAt(l,c);f?n("click",{originalEvent:r,annotation:f}):n("click",{originalEvent:r})}}}},_t=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=i+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())},{Boolean:bn}=Hn;function En(e,t,n){const o=e.slice();o[34]=t[n];const i=o[23](o[34].target.selector);return o[35]=i,o}function An(e,t,n){const o=e.slice();return o[38]=t[n],o}function wt(e){const t=e.slice(),n=t[38].target.selector;return t[41]=n,t}function Sn(e){let t=e[38].id,n,o,i=Tn(e);return{c(){i.c(),n=re()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&32768&&x(t,t=s[38].id)?(ae(),U(i,1,1,X),le(),i=Tn(s),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(P(i),o=!0)},o(s){U(i),o=!1},d(s){s&&I(n),i.d(s)}}}function ki(e){let t,n;return t=new Ai({props:{annotation:e[38],geom:e[41].geometry,style:e[1]}}),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const s={};i[0]&32768&&(s.annotation=o[38]),i[0]&32768&&(s.geom=o[41].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Ii(e){let t,n;return t=new vi({props:{annotation:e[38],geom:e[41].geometry,style:e[1]}}),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const s={};i[0]&32768&&(s.annotation=o[38]),i[0]&32768&&(s.geom=o[41].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function Oi(e){var o;let t,n;return t=new yi({props:{annotation:e[38],geom:(o=e[41])==null?void 0:o.geometry,style:e[1]}}),{c(){ne(t.$$.fragment)},m(i,s){$(t,i,s),n=!0},p(i,s){var a;const r={};s[0]&32768&&(r.annotation=i[38]),s[0]&32768&&(r.geom=(a=i[41])==null?void 0:a.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(P(t.$$.fragment,i),n=!0)},o(i){U(t.$$.fragment,i),n=!1},d(i){ee(t,i)}}}function Tn(e){let t,n,o,i;const s=[Oi,Ii,ki],r=[];function a(l,c){var f,u,d;return((f=l[41])==null?void 0:f.type)===K.ELLIPSE?0:((u=l[41])==null?void 0:u.type)===K.RECTANGLE?1:((d=l[41])==null?void 0:d.type)===K.POLYGON?2:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=re()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let f=t;t=a(l),t===f?~t&&r[t].p(l,c):(n&&(ae(),U(r[f],1,1,()=>{r[f]=null}),le()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(P(n),i=!0)},o(l){U(n),i=!1},d(l){l&&I(o),~t&&r[t].d(l)}}}function vn(e){let t=!e[8](e[38]),n,o,i=t&&Sn(wt(e));return{c(){i&&i.c(),n=re()},m(s,r){i&&i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&33024&&(t=!s[8](s[38])),t?i?(i.p(wt(s),r),r[0]&33024&&P(i,1)):(i=Sn(wt(s)),i.c(),P(i,1),i.m(n.parentNode,n)):i&&(ae(),U(i,1,1,()=>{i=null}),le())},i(s){o||(P(i),o=!0)},o(s){U(i),o=!1},d(s){s&&I(n),i&&i.d(s)}}}function Mn(e){let t,n,o,i;const s=[Pi,Bi],r=[];function a(l,c){return l[7]?0:l[13]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=re()},m(l,c){~t&&r[t].m(l,c),B(l,o,c),i=!0},p(l,c){let f=t;t=a(l),t===f?~t&&r[t].p(l,c):(n&&(ae(),U(r[f],1,1,()=>{r[f]=null}),le()),~t?(n=r[t],n?n.p(l,c):(n=r[t]=s[t](l),n.c()),P(n,1),n.m(o.parentNode,o)):n=null)},i(l){i||(P(n),i=!0)},o(l){U(n),i=!1},d(l){l&&I(o),~t&&r[t].d(l)}}}function Bi(e){let t=e[2],n,o,i=Ln(e);return{c(){i.c(),n=re()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4&&x(t,t=s[2])?(ae(),U(i,1,1,X),le(),i=Ln(s),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(P(i),o=!0)},o(s){U(i),o=!1},d(s){s&&I(n),i.d(s)}}}function Pi(e){let t,n,o=ve(e[7]),i=[];for(let r=0;r<o.length;r+=1)i[r]=On(En(e,o,r));const s=r=>U(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=re()},m(r,a){for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(r,a);B(r,t,a),n=!0},p(r,a){if(a[0]&10553506){o=ve(r[7]);let l;for(l=0;l<o.length;l+=1){const c=En(r,o,l);i[l]?(i[l].p(c,a),P(i[l],1)):(i[l]=On(c),i[l].c(),P(i[l],1),i[l].m(t.parentNode,t))}for(ae(),l=o.length;l<i.length;l+=1)s(l);le()}},i(r){if(!n){for(let a=0;a<o.length;a+=1)P(i[a]);n=!0}},o(r){i=i.filter(bn);for(let a=0;a<i.length;a+=1)U(i[a]);n=!1},d(r){r&&I(t),ot(i,r)}}}function Ln(e){let t,n;return t=new dn({props:{target:e[5],tool:e[13],drawingMode:e[12],transform:e[11],viewportScale:e[16]}}),t.$on("create",e[20]),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){const s={};i[0]&32&&(s.target=o[5]),i[0]&8192&&(s.tool=o[13]),i[0]&4096&&(s.drawingMode=o[12]),i[0]&2048&&(s.transform=o[11]),i[0]&65536&&(s.viewportScale=o[16]),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function kn(e){let t=e[34].id,n,o,i=In(e);return{c(){i.c(),n=re()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&128&&x(t,t=s[34].id)?(ae(),U(i,1,1,X),le(),i=In(s),i.c(),P(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(P(i),o=!0)},o(s){U(i),o=!1},d(s){s&&I(n),i.d(s)}}}function In(e){let t,n;return t=new un({props:{target:e[5],editor:e[23](e[34].target.selector),annotation:e[34],style:e[1],transform:e[11],viewportScale:e[16]}}),t.$on("change",function(){q(e[21](e[34]))&&e[21](e[34]).apply(this,arguments)}),{c(){ne(t.$$.fragment)},m(o,i){$(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.target=e[5]),i[0]&128&&(s.editor=e[23](e[34].target.selector)),i[0]&128&&(s.annotation=e[34]),i[0]&2&&(s.style=e[1]),i[0]&2048&&(s.transform=e[11]),i[0]&65536&&(s.viewportScale=e[16]),t.$set(s)},i(o){n||(P(t.$$.fragment,o),n=!0)},o(o){U(t.$$.fragment,o),n=!1},d(o){ee(t,o)}}}function On(e){let t,n,o=e[35]&&kn(e);return{c(){o&&o.c(),t=re()},m(i,s){o&&o.m(i,s),B(i,t,s),n=!0},p(i,s){i[35]?o?(o.p(i,s),s[0]&128&&P(o,1)):(o=kn(i),o.c(),P(o,1),o.m(t.parentNode,t)):o&&(ae(),U(o,1,1,()=>{o=null}),le())},i(i){n||(P(o),n=!0)},o(i){U(o),n=!1},d(i){i&&I(t),o&&o.d(i)}}}function Di(e){let t,n,o,i,s,r,a=ve(e[15]),l=[];for(let u=0;u<a.length;u+=1)l[u]=vn(An(e,a,u));const c=u=>U(l[u],1,1,()=>{l[u]=null});let f=e[5]&&Mn(e);return{c(){t=N("svg"),n=N("g");for(let u=0;u<l.length;u+=1)l[u].c();o=N("g"),f&&f.c(),h(o,"class","drawing"),h(t,"class","a9s-annotationlayer"),pe(t,"drawing",e[13]),pe(t,"hidden",!e[3]),pe(t,"hover",e[14])},m(u,d){B(u,t,d),fe(t,n);for(let g=0;g<l.length;g+=1)l[g]&&l[g].m(n,null);fe(t,o),f&&f.m(o,null),e[30](o),e[31](t),i=!0,s||(r=[W(t,"pointerup",function(){q(e[9])&&e[9].apply(this,arguments)}),W(t,"pointerdown",function(){q(e[10])&&e[10].apply(this,arguments)}),W(t,"pointermove",e[22])],s=!0)},p(u,d){if(e=u,d[0]&33026){a=ve(e[15]);let g;for(g=0;g<a.length;g+=1){const m=An(e,a,g);l[g]?(l[g].p(m,d),P(l[g],1)):(l[g]=vn(m),l[g].c(),P(l[g],1),l[g].m(n,null))}for(ae(),g=a.length;g<l.length;g+=1)c(g);le()}e[5]?f?(f.p(e,d),d[0]&32&&P(f,1)):(f=Mn(e),f.c(),P(f,1),f.m(o,null)):f&&(ae(),U(f,1,1,()=>{f=null}),le()),(!i||d[0]&8192)&&pe(t,"drawing",e[13]),(!i||d[0]&8)&&pe(t,"hidden",!e[3]),(!i||d[0]&16384)&&pe(t,"hover",e[14])},i(u){if(!i){for(let d=0;d<a.length;d+=1)P(l[d]);P(f),i=!0}},o(u){l=l.filter(bn);for(let d=0;d<l.length;d+=1)U(l[d]);U(f),i=!1},d(u){u&&I(t),ot(l,u),f&&f.d(),e[30](null),e[31](null),s=!1,ce(r)}}}function Yi(e,t,n){let o,i,s,r,a,l,c,f,u,d,g,m=X,_=()=>(m(),m=Lt(E,k=>n(16,g=k)),E);e.$$.on_destroy.push(()=>m());let{drawingEnabled:T}=t,{image:p}=t,{preferredDrawingMode:w}=t,{state:y}=t,{style:b=void 0}=t,{toolName:D=pt()[0]}=t,{user:G}=t,{visible:j=!0}=t,z,Y,E;De(()=>_(n(6,E=on(p,Y))));const{hover:A,selection:S,store:v}=y;nt(e,A,k=>n(14,f=k)),nt(e,S,k=>n(29,u=k)),nt(e,v,k=>n(15,d=k));let V,C;const Z=k=>{V&&v.unobserve(V);const H=k.filter(({editable:O})=>O).map(({id:O})=>O);H.length>0?(n(7,C=H.map(O=>v.getAnnotation(O)).filter(Boolean)),V=O=>{const{updated:te}=O.changes;n(7,C=te==null?void 0:te.map(we=>we.newValue))},v.observe(V,{annotations:H})):n(7,C=void 0)},_e=k=>{const H=zt(),O={id:H,bodies:[],target:{annotation:H,selector:k.detail,creator:G,created:new Date}};v.addAnnotation(O),S.setSelected(O.id)},ue=k=>H=>{var R;const{target:O}=k,te=10*60*1e3,we=((R=O.creator)==null?void 0:R.id)!==G.id||!O.created||new Date().getTime()-O.created.getTime()>te;v.updateTarget({...O,selector:H.detail,created:we?O.created:new Date,updated:we?new Date:void 0,updatedBy:we?G:void 0})},Ue=k=>{const{x:H,y:O}=_t(k,Y),te=v.getAt(H,O);te?f!==te.id&&A.set(te.id):A.set(void 0)},de=k=>ln(k);function Ne(k){Ge[k?"unshift":"push"](()=>{z=k,n(5,z)})}function he(k){Ge[k?"unshift":"push"](()=>{Y=k,n(4,Y)})}return e.$$set=k=>{"drawingEnabled"in k&&n(0,T=k.drawingEnabled),"image"in k&&n(24,p=k.image),"preferredDrawingMode"in k&&n(25,w=k.preferredDrawingMode),"state"in k&&n(26,y=k.state),"style"in k&&n(1,b=k.style),"toolName"in k&&n(2,D=k.toolName),"user"in k&&n(27,G=k.user),"visible"in k&&n(3,j=k.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(13,{tool:o,opts:i}=yt(D)||{tool:void 0,opts:void 0},o,(n(28,i),n(2,D))),e.$$.dirty[0]&301989888&&n(12,s=(i==null?void 0:i.drawingMode)||w),e.$$.dirty[0]&16&&n(11,r=_n(Y)),e.$$.dirty[0]&16&&n(10,{onPointerDown:a,onPointerUp:l}=wn(Y,v),a,(n(9,l),n(4,Y))),e.$$.dirty[0]&536870912&&n(8,c=k=>u.selected.find(H=>H.id===k.id&&H.editable)),e.$$.dirty[0]&536870912&&Z(u.selected)},[T,b,D,j,Y,z,E,C,c,l,a,r,s,o,f,d,g,A,S,v,_e,ue,Ue,de,p,w,y,G,i,u,Ne,he]}class Bn extends ie{constructor(t){super(),oe(this,t,Yi,Di,x,{drawingEnabled:0,image:24,preferredDrawingMode:25,state:26,style:1,toolName:2,user:27,visible:3},null,[-1,-1])}}function Pn(e,t,n=0,o=e.length-1,i=Ri){for(;o>n;){if(o-n>600){const l=o-n+1,c=t-n+1,f=Math.log(l),u=.5*Math.exp(2*f/3),d=.5*Math.sqrt(f*u*(l-u)/l)*(c-l/2<0?-1:1),g=Math.max(n,Math.floor(t-c*u/l+d)),m=Math.min(o,Math.floor(t+(l-c)*u/l+d));Pn(e,t,g,m,i)}const s=e[t];let r=n,a=o;for(Re(e,n,t),i(e[o],s)>0&&Re(e,n,o);r<a;){for(Re(e,r,a),r++,a--;i(e[r],s)<0;)r++;for(;i(e[a],s)>0;)a--}i(e[n],s)===0?Re(e,n,a):(a++,Re(e,a,o)),a<=t&&(n=a+1),t<=a&&(o=a-1)}}function Re(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function Ri(e,t){return e<t?-1:e>t?1:0}class Ci{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const o=[];if(!Ze(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?i(a):a;Ze(t,l)&&(n.leaf?o.push(a):Et(t,l)?this._all(a,o):s.push(a))}n=s.pop()}return o}collides(t){let n=this.data;if(!Ze(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(Ze(t,r)){if(n.leaf||Et(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Oe([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let a,l,c;for(;o||s.length;){if(o||(o=s.pop(),l=s[s.length-1],a=r.pop(),c=!0),o.leaf){const f=Xi(t,o.children,n);if(f!==-1)return o.children.splice(f,1),s.push(o),this._condense(s),this}!c&&!o.leaf&&Et(o,i)?(s.push(o),r.push(a),a=0,l=o,o=o.children[0]):l?(a++,o=l.children[a],c=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,a;if(s<=r)return a=Oe(t.slice(n,o+1)),Ie(a,this.toBBox),a;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),a=Oe([]),a.leaf=!1,a.height=i;const l=Math.ceil(s/r),c=l*Math.ceil(Math.sqrt(r));Dn(t,n,o,c,this.compareMinX);for(let f=n;f<=o;f+=c){const u=Math.min(f+c-1,o);Dn(t,f,u,l,this.compareMinY);for(let d=f;d<=u;d+=l){const g=Math.min(d+l-1,u);a.children.push(this._build(t,d,g,i-1))}}return Ie(a,this.toBBox),a}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const c=n.children[l],f=bt(c),u=Vi(t,c)-f;u<r?(r=u,s=f<s?f:s,a=c):u===r&&f<s&&(s=f,a=c)}n=a||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),Xe(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),a=Oe(o.children.splice(r,o.children.length-r));a.height=o.height,a.leaf=o.leaf,Ie(o,this.toBBox),Ie(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(o,a)}_splitRoot(t,n){this.data=Oe([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Ie(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let a=n;a<=o-n;a++){const l=Ce(t,0,a,this.toBBox),c=Ce(t,a,o,this.toBBox),f=Gi(l,c),u=bt(l)+bt(c);f<s?(s=f,i=a,r=u<r?u:r):f===s&&u<r&&(r=u,i=a)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Ui,s=t.leaf?this.compareMinY:Ni,r=this._allDistMargin(t,n,o,i),a=this._allDistMargin(t,n,o,s);r<a&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Ce(t,0,n,s),a=Ce(t,o-n,o,s);let l=Qe(r)+Qe(a);for(let c=n;c<o-n;c++){const f=t.children[c];Xe(r,t.leaf?s(f):f),l+=Qe(r)}for(let c=o-n-1;c>=n;c--){const f=t.children[c];Xe(a,t.leaf?s(f):f),l+=Qe(a)}return l}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)Xe(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():Ie(t[n],this.toBBox)}}function Xi(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function Ie(e,t){Ce(e,0,e.children.length,t,e)}function Ce(e,t,n,o,i){i||(i=Oe(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];Xe(i,e.leaf?o(r):r)}return i}function Xe(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Ui(e,t){return e.minX-t.minX}function Ni(e,t){return e.minY-t.minY}function bt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Qe(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Vi(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Gi(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Et(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ze(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Oe(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Dn(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;Pn(e,r,t,n,i),s.push(t,r,r,n)}}const ji=()=>{const e=new Ci,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=u=>{const{minX:d,minY:g,maxX:m,maxY:_}=u.selector.geometry.bounds,T={minX:d,minY:g,maxX:m,maxY:_,target:u};e.insert(T),t.set(u.annotation,T)},s=u=>{const d=t.get(u.annotation);d&&e.remove(d),t.delete(u.annotation)};return{all:n,clear:o,getAt:(u,d)=>{const m=e.search({minX:u,minY:d,maxX:u,maxY:d}).map(_=>_.target).filter(_=>_.selector.type===K.RECTANGLE||Yt(_.selector,u,d));if(m.length>0)return m.sort((_,T)=>Fe(_.selector)-Fe(T.selector)),m[0]},getIntersecting:(u,d,g,m)=>e.search({minX:u,minY:d,maxX:u+g,maxY:d+m}).map(_=>_.target),insert:i,remove:s,set:(u,d=!0)=>{d&&o();const g=u.reduce((m,_)=>{var T,p;if((p=(T=_.selector)==null?void 0:T.geometry)!=null&&p.bounds){const{minX:w,minY:y,maxX:b,maxY:D}=_.selector.geometry.bounds;return[...m,{minX:w,minY:y,maxX:b,maxY:D,target:_}]}else return m},[]);g.forEach(m=>t.set(m.target.annotation,m)),e.load(g)},size:()=>e.all().length,update:(u,d)=>{s(u),i(d)}}},Yn=e=>{const t=Mo(),n=ji(),o=ho(t);o.setUserSelectAction(e.userSelectAction);const i=uo(t),s=Bo();return t.observe(({changes:l})=>{n.set((l.created||[]).map(c=>c.target),!1),(l.deleted||[]).forEach(c=>n.remove(c.target)),(l.updated||[]).forEach(({oldValue:c,newValue:f})=>n.update(c.target,f.target))}),{store:{...t,getAt:(l,c)=>{const f=n.getAt(l,c);return f?t.getAnnotation(f.annotation):void 0},getIntersecting:(l,c,f,u)=>n.getIntersecting(l,c,f,u).map(d=>t.getAnnotation(d.annotation))},selection:o,hover:i,viewport:s}},Rn=e=>{const t=Yn(e);return{...t,store:Lo(t.store)}},Cn=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(i*t.height/10),l=n.getImageData(r,a,1,1).data,c=(.299*l[0]+.587*l[1]+.114*l[2])/255;o+=c}return o/81},Xn=e=>{const t=Cn(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},At=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Xn(e):n),Un=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),St=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Nn=(e,t)=>{const n=t||document,o=r=>{const a=r;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},i=r=>{const a=r;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},s=()=>{St?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return St?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},zi=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Un(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Ht.EDIT,theme:"light"}),i=Rn(o),{selection:s,store:r}=i,a=Oo(r),l=Po(i,a,o.adapter,o.autoSave),c=document.createElement("DIV");c.style.position="relative",c.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(c,n),c.appendChild(n);const f=Nn(a);let u=Vo();At(n,c,o.theme);const d=new Bn({target:c,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:u}});d.$on("click",Y=>{const{originalEvent:E,annotation:A}=Y.detail;A?s.userSelect(A.id,E):s.isEmpty()||s.clear()});const g=Yo(i,a,o.adapter),m=()=>{d.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c),f.destroy(),a.destroy()},_=()=>u,T=(Y,E,A)=>yn(Y,E,A),p=(Y,E)=>cn(Y,E),w=Y=>{if(!yt(Y))throw`No drawing tool named ${Y}`;d.$set({toolName:Y})},y=Y=>d.$set({drawingEnabled:Y}),b=Y=>{console.warn("Filter not implemented yet")},D=Y=>d.$set({style:Y}),G=Y=>At(n,c,Y),j=Y=>{u=Y,d.$set({user:Y})},z=Y=>d.$set({visible:Y});return{...g,destroy:m,getUser:_,listDrawingTools:pt,on:l.on,off:l.off,registerDrawingTool:T,registerShapeEditor:p,setDrawingEnabled:y,setDrawingTool:w,setFilter:b,setStyle:D,setTheme:G,setUser:j,setVisible:z,element:c,state:i}};L.Editor=ht,L.EditorMount=un,L.Handle=ke,L.IdentityTransform=Mi,L.PolygonEditor=nn,L.RectangleEditor=rn,L.RectangleUtil=Rt,L.RubberbandRectangle=gn,L.SVGAnnotationLayer=Bn,L.ShapeType=K,L.ToolMount=dn,L.W3CImageFormat=Fo,L.addEventListeners=wn,L.boundsFromPoints=Ye,L.computeArea=Fe,L.createImageAnnotator=zi,L.createImageAnnotatorState=Yn,L.createSVGTransform=_n,L.createSvelteImageAnnotatorState=Rn,L.detectTheme=Xn,L.distance=qe,L.enableResponsive=on,L.fillDefaults=Un,L.getEditor=ln,L.getSVGPoint=_t,L.getTool=yt,L.initKeyboardCommands=Nn,L.intersects=Yt,L.isMac=St,L.isTouch=sn,L.listDrawingTools=pt,L.parseFragmentSelector=Ct,L.parseSVGSelector=Vt,L.parseW3CImageAnnotation=Qt,L.registerEditor=cn,L.registerShapeUtil=ze,L.registerTool=yn,L.sampleBrightness=Cn,L.serializeFragmentSelector=Xt,L.serializeSVGSelector=Gt,L.serializeW3CImageAnnotation=Zt,L.setTheme=At,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=annotorious.js.map
|