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