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