UNPKG

@recogito/annotorious

Version:

A JavaScript image annotation library

1 lines 62.1 kB
(function(v,U){typeof exports=="object"&&typeof module<"u"?U(exports):typeof define=="function"&&define.amd?define(["exports"],U):(v=typeof globalThis<"u"?globalThis:v||self,U(v.Annotorious={}))})(this,function(v){"use strict";function U(){}function On(e,t){for(const n in t)e[n]=t[n];return e}function dt(e){return e()}function ht(){return Object.create(null)}function oe(e){e.forEach(dt)}function z(e){return typeof e=="function"}function q(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 mt(e,...t){if(e==null)return U;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function gt(e,t,n){e.$$.on_destroy.push(mt(t,n))}function Bn(e,t,n,o){if(e){const i=pt(e,t,n,o);return e[0](i)}}function pt(e,t,n,o){return e[1]&&o?On(n.ctx.slice(),e[1](o(t))):n.ctx}function Cn(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|i[a];return s}return t.dirty|i}return t.dirty}function kn(e,t,n,o,i,s){if(i){const r=pt(t,n,o,s);e.p(r,i)}}function Pn(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function le(e,t){e.appendChild(t)}function I(e,t,n){e.insertBefore(t,n||null)}function O(e){e.parentNode&&e.parentNode.removeChild(e)}function je(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function P(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function _t(e){return document.createTextNode(e)}function $(){return _t(" ")}function ie(){return _t("")}function V(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 Rn(e){return Array.from(e.childNodes)}function yt(e,t,n){e.classList[n?"add":"remove"](t)}function Yn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,o,t),i}let Ae;function Te(e){Ae=e}function wt(){if(!Ae)throw new Error("Function called outside component initialization");return Ae}function Se(e){wt().$$.on_mount.push(e)}function he(){const e=wt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Yn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function me(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const ge=[],pe=[];let _e=[];const bt=[],Xn=Promise.resolve();let Ve=!1;function Gn(){Ve||(Ve=!0,Xn.then(Et))}function We(e){_e.push(e)}const qe=new Set;let ye=0;function Et(){if(ye!==0)return;const e=Ae;do{try{for(;ye<ge.length;){const t=ge[ye];ye++,Te(t),Dn(t.$$)}}catch(t){throw ge.length=0,ye=0,t}for(Te(null),ge.length=0,ye=0;pe.length;)pe.pop()();for(let t=0;t<_e.length;t+=1){const n=_e[t];qe.has(n)||(qe.add(n),n())}_e.length=0}while(ge.length);for(;bt.length;)bt.pop()();Ve=!1,qe.clear(),Te(e)}function Dn(e){if(e.fragment!==null){e.update(),oe(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(We)}}function Un(e){const t=[],n=[];_e.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),_e=t}const Ie=new Set;let fe;function se(){fe={r:0,c:[],p:fe}}function re(){fe.r||oe(fe.c),fe=fe.p}function Y(e,t){e&&e.i&&(Ie.delete(e),e.i(t))}function D(e,t,n,o){if(e&&e.o){if(Ie.has(e))return;Ie.add(e),fe.c.push(()=>{Ie.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ue(e){e&&e.c()}function ae(e,t,n,o){const{fragment:i,after_update:s}=e.$$;i&&i.m(t,n),o||We(()=>{const r=e.$$.on_mount.map(dt).filter(z);e.$$.on_destroy?e.$$.on_destroy.push(...r):oe(r),e.$$.on_mount=[]}),s.forEach(We)}function ce(e,t){const n=e.$$;n.fragment!==null&&(Un(n.after_update),oe(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Nn(e,t){e.$$.dirty[0]===-1&&(ge.push(e),Gn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ee(e,t,n,o,i,s,r,a=[-1]){const l=Ae;Te(e);const u=e.$$={fragment:null,ctx:[],props:s,update:U,not_equal:i,bound:ht(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:ht(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(u.root);let h=!1;if(u.ctx=n?n(e,t.props||{},(c,d,...m)=>{const g=m.length?m[0]:d;return u.ctx&&i(u.ctx[c],u.ctx[c]=g)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](g),h&&Nn(e,c)),d}):[],u.update(),h=!0,oe(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const c=Rn(t.target);u.fragment&&u.fragment.l(c),c.forEach(O)}else u.fragment&&u.fragment.c();t.intro&&Y(e.$$.fragment),ae(e,t.target,t.anchor,t.customElement),Et()}Te(l)}class te{$destroy(){ce(this,1),this.$destroy=U}$on(t,n){if(!z(n))return U;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 H=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(H||{});const Je={},Be=(e,t)=>Je[e]=t,Qe=e=>Je[e.type].area(e),At=(e,t,n)=>Je[e.type].intersects(e,t,n),ve=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}},Hn={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),u=Math.sin(a),h=t-o,c=n-i,d=l*h+u*c,m=u*h-l*c;return d*d/(s*s)+m*m/(r*r)<=1}};Be(H.ELLIPSE,Hn);const Fn={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],u=o[r][0],h=o[r][1];l>n!=h>n&&t<(u-a)*(n-l)/(h-l)+a&&(i=!i)}return i}};Be(H.POLYGON,Fn);const Tt={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};Be(H.RECTANGLE,Tt);const St=(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,u,h,c]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,m,g,_]=[l,u,h,c].map(parseFloat);return{type:H.RECTANGLE,geometry:{x:d,y:m,w:g,h:_,bounds:{minX:d,minY:t?m-_:m,maxX:d+g,maxY:t?m:m+_}}}},vt=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}`}},Mt="http://www.w3.org/2000/svg",Lt=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},zn=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Mt}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},jn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(Mt),i=n.lookupNamespaceURI(null);return o||i?Lt(n).firstChild:Lt(zn(n)).firstChild},Vn=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[];if(!o)return;const i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:H.POLYGON,geometry:{points:i,bounds:ve(i)}}},Wn=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:H.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Ot=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Vn(t);if(t.includes("<ellipse "))return Wn(t)},It=e=>{let t;if(e.type===H.POLYGON){const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`}else if(e.type===H.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`};let Ce;const qn=new Uint8Array(16);function Jn(){if(!Ce&&(Ce=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Ce))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ce(qn)}const W=[];for(let e=0;e<256;++e)W.push((e+256).toString(16).slice(1));function Qn(e,t=0){return W[e[t+0]]+W[e[t+1]]+W[e[t+2]]+W[e[t+3]]+"-"+W[e[t+4]]+W[e[t+5]]+"-"+W[e[t+6]]+W[e[t+7]]+"-"+W[e[t+8]]+W[e[t+9]]+"-"+W[e[t+10]]+W[e[t+11]]+W[e[t+12]]+W[e[t+13]]+W[e[t+14]]+W[e[t+15]]}const Bt={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ze(e,t,n){if(Bt.randomUUID&&!t&&!e)return Bt.randomUUID();e=e||{};const o=e.random||(e.rng||Jn)();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 Ct=Object.prototype.hasOwnProperty;function de(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&de(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ct.call(e,n)&&++o&&!Ct.call(t,n)||!(n in t)||!de(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const we=[];function ke(e,t=U){let n;const o=new Set;function i(a){if(q(e,a)&&(e=a,n)){const l=!we.length;for(const u of o)u[1](),we.push(u,e);if(l){for(let u=0;u<we.length;u+=2)we[u][0](we[u+1]);we.length=0}}}function s(a){i(a(e))}function r(a,l=U){const u=[a,l];return o.add(u),o.size===1&&(n=t(i)||U),a(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Zn=e=>{const{subscribe:t,set:n}=ke(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 kt=(e=>(e.EDIT="EDIT",e.HIGHLIGHT="HIGHLIGHT",e.NONE="NONE",e))(kt||{});const Ke={selected:[]},Kn=(e,t="EDIT")=>{const{subscribe:n,set:o}=ke(Ke);let i=Ke;n(c=>i=c);const s=()=>o(Ke),r=()=>{var c;return((c=i.selected)==null?void 0:c.length)===0},a=c=>{if(i.selected.length===0)return!1;const d=typeof c=="string"?c:c.id;return i.selected.some(m=>m.id===d)},l=(c,d)=>{const m=e.getAnnotation(c);if(m){const g=xn(m,t);o(g==="EDIT"?{selected:[{id:c,editable:!0}],pointerEvent:d}:g==="HIGHLIGHT"?{selected:[{id:c}],pointerEvent:d}:{selected:[],pointerEvent:d})}else console.warn("Invalid selection: "+c)},u=(c,d=!0)=>{const m=Array.isArray(c)?c:[c],g=m.map(_=>e.getAnnotation(_)).filter(_=>_);o({selected:g.map(({id:_})=>({id:_,editable:d}))}),g.length!==m.length&&console.warn("Invalid selection",c)},h=c=>{if(i.selected.length===0)return!1;const{selected:d}=i;d.filter(({id:g})=>c.includes(g)).length>0&&o({selected:d.filter(({id:g})=>!c.includes(g))})};return e.observe(({changes:c})=>h(c.deleted.map(d=>d.id))),{clear:s,clickSelect:l,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:a,setSelected:u,subscribe:n}},xn=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT",$n=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)},eo=(e,t,n,o)=>({id:Ze(),annotation:e.id,created:n||new Date,creator:o,...t}),to=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},no=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},oo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!de(o,n)?o:void 0}}).filter(({oldBody:n})=>n),io=(e,t)=>!de(e.target,t.target),Pt=(e,t)=>({oldValue:e,newValue:t,bodiesCreated:to(e,t),bodiesDeleted:no(e,t),bodiesUpdated:oo(e,t),targetUpdated:io(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0});var F=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(F||{});const so=(e,t)=>{var 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=h=>(h==null?void 0:h.length)>0;if(!(l(n.created)||l(n.deleted))){const h=(s=n.updated)==null?void 0:s.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),c=(r=n.updated)==null?void 0:r.some(d=>d.targetUpdated);if(a==="BODY_ONLY"&&h&&!c||a==="TARGET_ONLY"&&c&&!h)return!1}}if(e.options.annotations){const a=new Set([...n.created.map(u=>u.id),...n.deleted.map(u=>u.id),...n.updated.map(({oldValue:u})=>u.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(u=>a.has(u))}else return!0},ro=e=>e.id!==void 0,lo=()=>{const e=new Map,t=new Map,n=[],o=(y,b={})=>n.push({onChange:y,options:b}),i=y=>{const b=n.findIndex(A=>A.onChange==y);b>-1&&n.splice(b,1)},s=(y,b)=>{const A={origin:y,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(L=>{so(L,A)&&L.onChange(A)})},r=(y,b=F.LOCAL)=>{if(e.get(y.id))throw Error(`Cannot add annotation ${y.id} - exists already`);e.set(y.id,y),y.bodies.forEach(L=>t.set(L.id,y.id)),s(b,{created:[y]})},a=(y,b=F.LOCAL,A=F.LOCAL)=>{const L=ro(b)?A:b,w=typeof y=="string"?b:y,B=typeof y=="string"?y:y.id,X=e.get(B);if(X){const ne=Pt(X,w);B===w.id?e.set(B,w):(e.delete(B),e.set(w.id,w)),X.bodies.forEach(J=>t.delete(J.id)),w.bodies.forEach(J=>t.set(J.id,w.id)),s(L,{updated:[ne]})}else throw Error(`Cannot update annotation ${B} - does not exist`)},l=(y,b=F.LOCAL)=>{const A=e.get(y.annotation);if(A){const L={...A,bodies:[...A.bodies,y]};e.set(A.id,L),t.set(y.id,L.id),s(b,{updated:[{oldValue:A,newValue:L,bodiesCreated:[y]}]})}else console.warn(`Attempt to add body to missing annotation: ${y.annotation}`)},u=()=>[...e.values()],h=(y=F.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(y,{deleted:b})},c=(y,b=!0,A=F.LOCAL)=>{if(b){const L=[...e.values()];e.clear(),t.clear(),y.forEach(w=>{e.set(w.id,w),w.bodies.forEach(B=>t.set(B.id,w.id))}),s(A,{created:y,deleted:L})}else{const L=y.reduce((w,B)=>{const X=e.get(B.id);return X?[...w,X]:w},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(w=>w.id).join(", ")}`);y.forEach(w=>{e.set(w.id,w),w.bodies.forEach(B=>t.set(B.id,w.id))}),s(A,{created:y})}},d=y=>{const b=typeof y=="string"?y:y.id,A=e.get(b);if(A)return e.delete(b),A.bodies.forEach(L=>t.delete(L.id)),A;console.warn(`Attempt to delete missing annotation: ${b}`)},m=(y,b=F.LOCAL)=>{const A=d(y);A&&s(b,{deleted:[A]})},g=(y,b=F.LOCAL)=>{const A=y.reduce((L,w)=>{const B=d(w);return B?[...L,B]:L},[]);A.length>0&&s(b,{deleted:A})},_=(y,b=F.LOCAL)=>{const A=e.get(y.annotation);if(A){const L=A.bodies.find(w=>w.id===y.id);if(L){t.delete(L.id);const w={...A,bodies:A.bodies.filter(X=>X.id!==y.id)};e.set(A.id,w),s(b,{updated:[{oldValue:A,newValue:w,bodiesDeleted:[L]}]})}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 b=e.get(y);return b?{...b}:void 0},T=y=>{const b=t.get(y);if(b){const L=p(b).bodies.find(w=>w.id===y);if(L)return L;console.error(`Store integrity error: body ${y} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${y}`)},E=(y,b)=>{if(y.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const A=e.get(y.annotation);if(A){const L=A.bodies.find(B=>B.id===y.id),w={...A,bodies:A.bodies.map(B=>B.id===L.id?b:B)};return e.set(A.id,w),L.id!==b.id&&(t.delete(L.id),t.set(b.id,w.id)),{oldValue:A,newValue:w,bodiesUpdated:[{oldBody:L,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${y.annotation}`)},C=(y,b,A=F.LOCAL)=>{const L=E(y,b);s(A,{updated:[L]})},G=(y,b=F.LOCAL)=>{const A=y.map(L=>E({id:L.id,annotation:L.annotation},L));s(b,{updated:A})},N=y=>{const b=e.get(y.annotation);if(b){const A={...b,target:{...b.target,...y}};return e.set(b.id,A),{oldValue:b,newValue:A,targetUpdated:{oldTarget:b.target,newTarget:y}}}else console.warn(`Attempt to update target on missing annotation: ${y.annotation}`)};return{addAnnotation:r,addBody:l,all:u,bulkAddAnnotation:c,bulkDeleteAnnotation:g,bulkUpdateBodies:G,bulkUpdateTargets:(y,b=F.LOCAL)=>{const A=y.map(N).filter(L=>L);A.length>0&&s(b,{updated:A})},clear:h,deleteAnnotation:m,deleteBody:_,getAnnotation:p,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:C,updateTarget:(y,b=F.LOCAL)=>{const A=N(y);A&&s(b,{updated:[A]})}}},ao=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),co=()=>{const{subscribe:e,set:t}=ke([]);return{subscribe:e,set:t}},fo=(e,t,n,o,i,s)=>{const r=new Map;let a=[],l,u;const h=(g,_)=>{r.has(g)?r.get(g).push(_):r.set(g,[_])},c=(g,_)=>{const p=r.get(g);p&&p.indexOf(_)>0&&p.splice(p.indexOf(_),1)},d=(g,_,p)=>{r.has(g)&&setTimeout(()=>{r.get(g).forEach(T=>{if(i){const E=Array.isArray(_)?_.map(G=>i.serialize(G)):i.serialize(_),C=p?p instanceof PointerEvent?p:i.serialize(p):void 0;T(E,C)}else T(_,p)})},1)},m=()=>{const{selected:g}=t,_=g.map(({id:p})=>e.getAnnotation(p));_.forEach(p=>{const T=a.find(E=>E.id===p.id);(!T||!de(T,p))&&d("updateAnnotation",p,T)}),a=a.map(p=>{const T=_.find(({id:E})=>E===p.id);return T||p})};return t.subscribe(({selected:g})=>{if(!(a.length===0&&g.length===0)){if(a.length===0&&g.length>0)a=g.map(({id:_})=>e.getAnnotation(_));else if(a.length>0&&g.length===0)a.forEach(_=>{const p=e.getAnnotation(_.id);p&&!de(p,_)&&d("updateAnnotation",p,_)}),a=[];else{const _=new Set(a.map(E=>E.id)),p=new Set(g.map(({id:E})=>E));a.filter(E=>!p.has(E.id)).forEach(E=>{const C=e.getAnnotation(E.id);C&&!de(C,E)&&d("updateAnnotation",C,E)}),a=[...a.filter(E=>p.has(E.id)),...g.filter(({id:E})=>!_.has(E)).map(({id:E})=>e.getAnnotation(E))]}d("selectionChanged",a)}}),n.subscribe(g=>{!l&&g?d("mouseEnterAnnotation",e.getAnnotation(g)):l&&!g?d("mouseLeaveAnnotation",e.getAnnotation(l)):l&&g&&(d("mouseLeaveAnnotation",e.getAnnotation(l)),d("mouseEnterAnnotation",e.getAnnotation(g))),l=g}),o==null||o.subscribe(g=>d("viewportIntersect",g.map(e.getAnnotation))),e.observe(g=>{s&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:_,deleted:p}=g.changes;_.forEach(E=>d("createAnnotation",E)),p.forEach(E=>d("deleteAnnotation",E)),g.changes.updated.filter(E=>[...E.bodiesCreated||[],...E.bodiesDeleted||[],...E.bodiesUpdated||[]].length>0).forEach(({oldValue:E,newValue:C})=>{const G=a.find(N=>N.id===E.id)||E;a=a.map(N=>N.id===E.id?C:N),d("updateAnnotation",C,G)})},{origin:F.LOCAL}),e.observe(g=>{if(a){const _=new Set(a.map(T=>T.id)),p=g.changes.updated.filter(({newValue:T})=>_.has(T.id)).map(({newValue:T})=>T);p.length>0&&(a=a.map(T=>{const E=p.find(C=>C.id===T.id);return E||T}))}},{origin:F.REMOTE}),{on:h,off:c,emit:d}},uo=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)=>{const n=h=>{if(t){const{parsed:c,error:d}=t.parse(h);c?e.addAnnotation(c,F.REMOTE):console.error(d)}else e.addAnnotation(h,F.REMOTE)},o=()=>e.clear(),i=h=>{const c=e.getAnnotation(h);return t&&c?t.serialize(c):c},s=()=>t?e.all().map(t.serialize):e.all(),r=h=>fetch(h).then(c=>c.json()).then(c=>(l(c),c)),a=h=>{if(typeof h=="string"){const c=e.getAnnotation(h);return e.deleteAnnotation(h),t?t.serialize(c):c}else{const c=t?t.parse(h).parsed:h;return e.deleteAnnotation(c),h}},l=h=>{if(t){const{parsed:c,failed:d}=Rt(t)(h);d.length>0&&console.warn(`Discarded ${d.length} invalid annotations`,d),e.bulkAddAnnotation(c,!0,F.REMOTE)}else e.bulkAddAnnotation(h,!0,F.REMOTE)};return{addAnnotation:n,clearAnnotations:o,getAnnotationById:i,getAnnotations:s,loadAnnotations:r,removeAnnotation:a,setAnnotations:l,updateAnnotation:h=>{if(t){const c=t.parse(h).parsed,d=t.serialize(e.getAnnotation(c.id));return e.updateAnnotation(c),d}else{const c=e.getAnnotation(h.id);return e.updateAnnotation(h),c}}}};let ho=e=>crypto.getRandomValues(new Uint8Array(e)),mo=(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}}},go=(e,t=21)=>mo(e,t,ho),po=(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 Xt=()=>({isGuest:!0,id:go("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),_o=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}`},Gt=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:a,creator:l,...u}=n;return{id:o||_o(n),annotation:t,type:i,purpose:s,value:r,created:a,creator:l?typeof l=="object"?{...l}:l:void 0,...u}}),Dt=e=>e.map(t=>{const n={...t};return delete n.annotation,delete n.id,n}),yo=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ut=()=>{const e=[...yo];return{assignRandomColor:()=>{const o=Math.floor(Math.random()*e.length),i=e[o];return e.splice(o,1),i},releaseColor:o=>e.push(o)}},Nt=()=>{const e=Ut();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 wo=()=>({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 bo=(e,t)=>e.every(n=>e.includes(n))&&t.every(n=>e.includes(n)),Eo=po(),Ao=(e=Nt())=>{const t=wo(),n=new Map,o=new Map,i=(c,d)=>{if(n.has(c)){console.warn("Attempt to add user that is already present",c,d);return}const m=e.addUser(c,d);n.set(c,{...d,presenceKey:c,appearance:m})},s=c=>{const d=n.get(c);if(!d){console.warn("Attempt to remove user that is not present",c);return}e.removeUser(d),n.delete(c)},r=c=>{const d=new Set(c.map(_=>_.presenceKey)),m=c.filter(({presenceKey:_})=>!n.has(_)),g=Array.from(n.values()).filter(_=>!d.has(_.presenceKey));m.forEach(({presenceKey:_,user:p})=>i(_,p)),g.forEach(_=>{const{presenceKey:p}=_;o.has(p)&&t.emit("selectionChange",_,null),s(p)}),(m.length>0||g.length>0)&&t.emit("presence",u())},a=(c,d)=>{const m=n.get(c);if(!m){console.warn("Activity notification from user that is not present");return}const g=o.get(c);(!g||!bo(g,d))&&(o.set(c,d),t.emit("selectionChange",m,d))},l=(c,d)=>{const m=n.get(c);if(!m){console.warn("Selection change for user that is not present",c);return}d?o.set(c,d):o.delete(c),t.emit("selectionChange",m,d)},u=()=>[...Array.from(n.values())];return{getPresentUsers:u,notifyActivity:a,on:(c,d)=>t.on(c,d),syncUsers:r,updateSelection:l}},To=(e,t=!1)=>({parse:i=>Ht(i,t),serialize:i=>Ft(i,e)}),Ht=(e,t=!1)=>{const n=e.id||Ze(),o=Gt(e.body,n),i=Array.isArray(e.target)?e.target[0]:e.target,s=Array.isArray(i.selector)?i.selector[0]:i.selector,r=s.type==="FragmentSelector"?St(s,t):s.type==="SvgSelector"?Ot(s):void 0;return r?{parsed:{id:n,bodies:o,target:{annotation:n,selector:r}}}:{error:Error(`Unknown selector type: ${r.type}`)}},Ft=(e,t)=>{const n=e.target.selector,o=n.type==H.RECTANGLE?vt(n.geometry):It(n);return{"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Dt(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 jt(e){let t,n,o,i,s;return{c(){t=P("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){I(r,t,a),i||(s=V(t,"pointerdown",function(){z(e[10](M(e[13])))&&e[10](M(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&&O(t),i=!1,s()}}}function So(e){let t,n,o,i,s,r,a,l,u,h,c=e[4].points,d=[];for(let m=0;m<c.length;m+=1)d[m]=jt(zt(e,c,m));return{c(){t=P("polygon"),i=$(),s=P("polygon"),a=$();for(let m=0;m<d.length;m+=1)d[m].c();l=ie(),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"points",o=e[4].points.map(Vt).join(" ")),f(s,"class","a9s-inner a9s-shape-handle"),f(s,"style",e[1]),f(s,"points",r=e[4].points.map(Wt).join(" "))},m(m,g){I(m,t,g),I(m,i,g),I(m,s,g),I(m,a,g);for(let _=0;_<d.length;_+=1)d[_]&&d[_].m(m,g);I(m,l,g),u||(h=[V(t,"pointerdown",function(){z(e[10](M.SHAPE))&&e[10](M.SHAPE).apply(this,arguments)}),V(s,"pointerdown",function(){z(e[10](M.SHAPE))&&e[10](M.SHAPE).apply(this,arguments)})],u=!0)},p(m,g){if(e=m,g&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),g&16&&o!==(o=e[4].points.map(Vt).join(" "))&&f(t,"points",o),g&2&&f(s,"style",e[1]),g&16&&r!==(r=e[4].points.map(Wt).join(" "))&&f(s,"points",r),g&1048){c=e[4].points;let _;for(_=0;_<c.length;_+=1){const p=zt(e,c,_);d[_]?d[_].p(p,g):(d[_]=jt(p),d[_].c(),d[_].m(l.parentNode,l))}for(;_<d.length;_+=1)d[_].d(1);d.length=c.length}},d(m){m&&O(t),m&&O(i),m&&O(s),m&&O(a),je(d,m),m&&O(l),u=!1,oe(h)}}}function vo(e){let t,n;return t=new $e({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[So,({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(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&17434&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}const Vt=e=>e.join(","),Wt=e=>e.join(",");function Mo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const u=(m,g,_)=>{let p;g===M.SHAPE?p=m.geometry.points.map(([E,C])=>[E+_[0],C+_[1]]):p=m.geometry.points.map(([E,C],G)=>g===M(G)?[E+_[0],C+_[1]]:[E,C]);const T=ve(p);return{...m,geometry:{points:p,bounds:T}}};function h(m){me.call(this,e,m)}function c(m){me.call(this,e,m)}function d(m){me.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,a=m.transform),"viewportScale"in m&&n(6,l=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,u,l,h,c,d]}class qt extends te{constructor(t){super(),ee(this,t,Mo,vo,q,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Lo(e){let t,n,o,i,s,r,a,l,u,h,c,d,m,g,_,p,T,E,C,G,N,R,j,y,b,A,L,w,B,X,ne,J,lt,Q,Xe,Ge,at,Z,De,Ue,ct,K,Ne,He,ft,x,Fe,ze,ut,Ln;return{c(){t=P("rect"),a=$(),l=P("rect"),m=$(),g=P("rect"),E=$(),C=P("rect"),j=$(),y=P("rect"),w=$(),B=P("rect"),lt=$(),Q=P("rect"),at=$(),Z=P("rect"),ct=$(),K=P("rect"),ft=$(),x=P("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",u=e[4].x),f(l,"y",h=e[4].y),f(l,"width",c=e[4].w),f(l,"height",d=e[4].h),f(g,"class","a9s-edge-handle a9s-edge-handle-top"),f(g,"x",_=e[4].x),f(g,"y",p=e[4].y),f(g,"height",1),f(g,"width",T=e[4].w),f(C,"class","a9s-edge-handle a9s-edge-handle-right"),f(C,"x",G=e[4].x+e[4].w),f(C,"y",N=e[4].y),f(C,"height",R=e[4].h),f(C,"width",1),f(y,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(y,"x",b=e[4].x),f(y,"y",A=e[4].y+e[4].h),f(y,"height",1),f(y,"width",L=e[4].w),f(B,"class","a9s-edge-handle a9s-edge-handle-left"),f(B,"x",X=e[4].x),f(B,"y",ne=e[4].y),f(B,"height",J=e[4].h),f(B,"width",1),f(Q,"class","a9s-corner-handle a9s-corner-handle-topleft"),f(Q,"x",Xe=e[4].x-e[3]/2),f(Q,"y",Ge=e[4].y-e[3]/2),f(Q,"height",e[3]),f(Q,"width",e[3]),f(Z,"class","a9s-corner-handle a9s-corner-handle-topright"),f(Z,"x",De=e[4].x+e[4].w-e[3]/2),f(Z,"y",Ue=e[4].y-e[3]/2),f(Z,"height",e[3]),f(Z,"width",e[3]),f(K,"class","a9s-corner-handle a9s-corner-handle-bottomright"),f(K,"x",Ne=e[4].x+e[4].w-e[3]/2),f(K,"y",He=e[4].y+e[4].h-e[3]/2),f(K,"height",e[3]),f(K,"width",e[3]),f(x,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),f(x,"x",Fe=e[4].x-e[3]/2),f(x,"y",ze=e[4].y+e[4].h-e[3]/2),f(x,"height",e[3]),f(x,"width",e[3])},m(k,S){I(k,t,S),I(k,a,S),I(k,l,S),I(k,m,S),I(k,g,S),I(k,E,S),I(k,C,S),I(k,j,S),I(k,y,S),I(k,w,S),I(k,B,S),I(k,lt,S),I(k,Q,S),I(k,at,S),I(k,Z,S),I(k,ct,S),I(k,K,S),I(k,ft,S),I(k,x,S),ut||(Ln=[V(t,"pointerdown",function(){z(e[10](M.SHAPE))&&e[10](M.SHAPE).apply(this,arguments)}),V(l,"pointerdown",function(){z(e[10](M.SHAPE))&&e[10](M.SHAPE).apply(this,arguments)}),V(g,"pointerdown",function(){z(e[10](M.TOP))&&e[10](M.TOP).apply(this,arguments)}),V(C,"pointerdown",function(){z(e[10](M.RIGHT))&&e[10](M.RIGHT).apply(this,arguments)}),V(y,"pointerdown",function(){z(e[10](M.BOTTOM))&&e[10](M.BOTTOM).apply(this,arguments)}),V(B,"pointerdown",function(){z(e[10](M.LEFT))&&e[10](M.LEFT).apply(this,arguments)}),V(Q,"pointerdown",function(){z(e[10](M.TOP_LEFT))&&e[10](M.TOP_LEFT).apply(this,arguments)}),V(Z,"pointerdown",function(){z(e[10](M.TOP_RIGHT))&&e[10](M.TOP_RIGHT).apply(this,arguments)}),V(K,"pointerdown",function(){z(e[10](M.BOTTOM_RIGHT))&&e[10](M.BOTTOM_RIGHT).apply(this,arguments)}),V(x,"pointerdown",function(){z(e[10](M.BOTTOM_LEFT))&&e[10](M.BOTTOM_LEFT).apply(this,arguments)})],ut=!0)},p(k,S){e=k,S&2&&n!==(n=e[1]?"display:none;":void 0)&&f(t,"style",n),S&16&&o!==(o=e[4].x)&&f(t,"x",o),S&16&&i!==(i=e[4].y)&&f(t,"y",i),S&16&&s!==(s=e[4].w)&&f(t,"width",s),S&16&&r!==(r=e[4].h)&&f(t,"height",r),S&2&&f(l,"style",e[1]),S&16&&u!==(u=e[4].x)&&f(l,"x",u),S&16&&h!==(h=e[4].y)&&f(l,"y",h),S&16&&c!==(c=e[4].w)&&f(l,"width",c),S&16&&d!==(d=e[4].h)&&f(l,"height",d),S&16&&_!==(_=e[4].x)&&f(g,"x",_),S&16&&p!==(p=e[4].y)&&f(g,"y",p),S&16&&T!==(T=e[4].w)&&f(g,"width",T),S&16&&G!==(G=e[4].x+e[4].w)&&f(C,"x",G),S&16&&N!==(N=e[4].y)&&f(C,"y",N),S&16&&R!==(R=e[4].h)&&f(C,"height",R),S&16&&b!==(b=e[4].x)&&f(y,"x",b),S&16&&A!==(A=e[4].y+e[4].h)&&f(y,"y",A),S&16&&L!==(L=e[4].w)&&f(y,"width",L),S&16&&X!==(X=e[4].x)&&f(B,"x",X),S&16&&ne!==(ne=e[4].y)&&f(B,"y",ne),S&16&&J!==(J=e[4].h)&&f(B,"height",J),S&24&&Xe!==(Xe=e[4].x-e[3]/2)&&f(Q,"x",Xe),S&24&&Ge!==(Ge=e[4].y-e[3]/2)&&f(Q,"y",Ge),S&8&&f(Q,"height",e[3]),S&8&&f(Q,"width",e[3]),S&24&&De!==(De=e[4].x+e[4].w-e[3]/2)&&f(Z,"x",De),S&24&&Ue!==(Ue=e[4].y-e[3]/2)&&f(Z,"y",Ue),S&8&&f(Z,"height",e[3]),S&8&&f(Z,"width",e[3]),S&24&&Ne!==(Ne=e[4].x+e[4].w-e[3]/2)&&f(K,"x",Ne),S&24&&He!==(He=e[4].y+e[4].h-e[3]/2)&&f(K,"y",He),S&8&&f(K,"height",e[3]),S&8&&f(K,"width",e[3]),S&24&&Fe!==(Fe=e[4].x-e[3]/2)&&f(x,"x",Fe),S&24&&ze!==(ze=e[4].y+e[4].h-e[3]/2)&&f(x,"y",ze),S&8&&f(x,"height",e[3]),S&8&&f(x,"width",e[3])},d(k){k&&O(t),k&&O(a),k&&O(l),k&&O(m),k&&O(g),k&&O(E),k&&O(C),k&&O(j),k&&O(y),k&&O(w),k&&O(B),k&&O(lt),k&&O(Q),k&&O(at),k&&O(Z),k&&O(ct),k&&O(K),k&&O(ft),k&&O(x),ut=!1,oe(Ln)}}}function Oo(e){let t,n;return t=new $e({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Lo,({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(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&3098&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function Io(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:a}=t,{viewportScale:l=1}=t;const u=(m,g,_)=>{const p=m.geometry.bounds;let[T,E]=[p.minX,p.minY],[C,G]=[p.maxX,p.maxY];const[N,R]=_;if(g===M.SHAPE)T+=N,C+=N,E+=R,G+=R;else{switch(g){case M.TOP:case M.TOP_LEFT:case M.TOP_RIGHT:{E+=R;break}case M.BOTTOM:case M.BOTTOM_LEFT:case M.BOTTOM_RIGHT:{G+=R;break}}switch(g){case M.LEFT:case M.TOP_LEFT:case M.BOTTOM_LEFT:{T+=N;break}case M.RIGHT:case M.TOP_RIGHT:case M.BOTTOM_RIGHT:{C+=N;break}}}const j=Math.min(T,C),y=Math.min(E,G),b=Math.abs(C-T),A=Math.abs(G-E);return{...m,geometry:{x:j,y,w:b,h:A,bounds:{minX:j,minY:y,maxX:j+b,maxY:y+A}}}};function h(m){me.call(this,e,m)}function c(m){me.call(this,e,m)}function d(m){me.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,a=m.transform),"viewportScale"in m&&n(6,l=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/l)},[s,r,a,i,o,u,l,h,c,d]}class Jt extends te{constructor(t){super(),ee(this,t,Io,Oo,q,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const Qt=new Map([[H.RECTANGLE,Jt],[H.POLYGON,qt]]),xe=e=>Qt.get(e.type),Zt=(e,t)=>Qt.set(e,t),M=e=>`HANDLE-${e}`;M.SHAPE="SHAPE",M.TOP="TOP",M.RIGHT="RIGHT",M.BOTTOM="BOTTOM",M.LEFT="LEFT",M.TOP_LEFT="TOP_LEFT",M.TOP_RIGHT="TOP_RIGHT",M.BOTTOM_RIGHT="BOTTOM_RIGHT",M.BOTTOM_LEFT="BOTTOM_LEFT";const Bo=e=>({}),Kt=e=>({grab:e[0]});function Co(e){let t,n,o,i;const s=e[7].default,r=Bn(s,e,e[6],Kt);return{c(){t=P("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(a,l){I(a,t,l),r&&r.m(t,null),n=!0,o||(i=[V(t,"pointerup",e[2]),V(t,"pointermove",e[1])],o=!0)},p(a,[l]){r&&r.p&&(!n||l&64)&&kn(r,s,a,a[6],n?Cn(s,a[6],l,Bo):Pn(a[6]),Kt)},i(a){n||(Y(r,a),n=!0)},o(a){D(r,a),n=!1},d(a){a&&O(t),r&&r.d(a),o=!1,oe(i)}}}function ko(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=he();let{shape:r}=t,{editor:a}=t,{transform:l}=t,u=null,h,c=null;const d=_=>p=>{u=_,h=l.elementToImage(p.offsetX,p.offsetY),c=r,p.target.setPointerCapture(p.pointerId),s("grab")},m=_=>{if(u){const[p,T]=l.elementToImage(_.offsetX,_.offsetY),E=[p-h[0],T-h[1]];n(3,r=a(c,u,E)),s("change",r)}},g=_=>{_.target.releasePointerCapture(_.pointerId),u=null,c=r,s("release")};return e.$$set=_=>{"shape"in _&&n(3,r=_.shape),"editor"in _&&n(4,a=_.editor),"transform"in _&&n(5,l=_.transform),"$$scope"in _&&n(6,i=_.$$scope)},[d,m,g,r,a,l,i,o]}class $e extends te{constructor(t){super(),ee(this,t,ko,Co,q,{shape:3,editor:4,transform:5})}}const Pe=(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 Po(e,t,n){let o;const i=he();let{annotation:s}=t,{editor:r}=t,{style:a=void 0}=t,{target:l}=t,{transform:u}=t,{viewportScale:h}=t,c;return Se(()=>(n(6,c=new r({target:l,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:h}})),c.$on("change",d=>{c.$$set({shape:d.detail}),i("change",d.detail)}),()=>{c.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,u=d.transform),"viewportScale"in d&&n(5,h=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Pe(s,a)),e.$$.dirty&80&&c&&c.$set({transform:u}),e.$$.dirty&96&&c&&c.$set({viewportScale:h})},[s,r,a,l,u,h,c]}class xt extends te{constructor(t){super(),ee(this,t,Po,null,q,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Ro(e,t,n){const o=he();let{target:i}=t,{tool:s}=t,{transform:r}=t,{viewportScale:a}=t,l;return Se(()=>(n(4,l=new s({target:i,props:{transform:r,viewportScale:a}})),l.$on("create",u=>o("create",u.detail)),()=>{l.$destroy()})),e.$$set=u=>{"target"in u&&n(0,i=u.target),"tool"in u&&n(1,s=u.tool),"transform"in u&&n(2,r=u.transform),"viewportScale"in u&&n(3,a=u.viewportScale)},e.$$.update=()=>{e.$$.dirty&20&&l&&l.$set({transform:r}),e.$$.dirty&24&&l&&l.$set({viewportScale:a})},[i,s,r,a,l]}class $t extends te{constructor(t){super(),ee(this,t,Ro,null,q,{target:0,tool:1,transform:2,viewportScale:3})}}function en(e){let t,n;return{c(){t=P("rect"),n=P("rect"),f(t,"class","a9s-outer"),f(t,"x",e[2]),f(t,"y",e[3]),f(t,"width",e[4]),f(t,"height",e[5]),f(n,"class","a9s-inner"),f(n,"x",e[2]),f(n,"y",e[3]),f(n,"width",e[4]),f(n,"height",e[5])},m(o,i){I(o,t,i),I(o,n,i)},p(o,i){i&4&&f(t,"x",o[2]),i&8&&f(t,"y",o[3]),i&16&&f(t,"width",o[4]),i&32&&f(t,"height",o[5]),i&4&&f(n,"x",o[2]),i&8&&f(n,"y",o[3]),i&16&&f(n,"width",o[4]),i&32&&f(n,"height",o[5])},d(o){o&&O(t),o&&O(n)}}}function Yo(e){let t,n=e[1]&&en(e);return{c(){t=P("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){I(o,t,i),n&&n.m(t,null),e[7](t)},p(o,[i]){o[1]?n?n.p(o,i):(n=en(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:U,o:U,d(o){o&&O(t),n&&n.d(),e[7](null)}}}function Xo(e,t,n){const o=he();let{transform:i}=t,s,r,a,l,u,h,c;const d=p=>{n(1,r=i.elementToImage(p.offsetX,p.offsetY)),a=r,n(2,l=r[0]),n(3,u=r[1]),n(4,h=1),n(5,c=1)},m=p=>{r&&(a=i.elementToImage(p.offsetX,p.offsetY),n(2,l=Math.min(a[0],r[0])),n(3,u=Math.min(a[1],r[1])),n(4,h=Math.abs(a[0]-r[0])),n(5,c=Math.abs(a[1]-r[1])))},g=()=>{if(h*c>15){const p={type:H.RECTANGLE,geometry:{bounds:{minX:l,minY:u,maxX:l+h,maxY:u+c},x:l,y:u,w:h,h:c}};o("create",p)}n(1,r=null),a=null};Se(()=>{const p=s.closest("svg");return p.addEventListener("pointerdown",d),p.addEventListener("pointermove",m),p.addEventListener("pointerup",g),()=>{p.removeEventListener("pointerdown",d),p.removeEventListener("pointermove",m),p.removeEventListener("pointerup",g)}});function _(p){pe[p?"unshift":"push"](()=>{s=p,n(0,s)})}return e.$$set=p=>{"transform"in p&&n(6,i=p.transform)},[s,r,l,u,h,c,i,_]}class tn extends te{constructor(t){super(),ee(this,t,Xo,Yo,q,{transform:6})}}const et=(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))},Go=(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)=>{Go(e,t);const{subscribe:n,set:o}=ke(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,u=Math.max(r.width/a,r.height/l);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},on="ontouchstart"in window||navigator.maxTouchPoints>0;function tt(e){const t=e.slice(),n=(t[3]?t[1]:[...t[1],t[2]]).map(o=>o.join(",")).join(" ");return t[13]=n,t}function sn(e){let t,n,o,i,s,r=e[3]&&rn(e);return{c(){t=P("polygon"),o=P("polygon"),r&&r.c(),s=ie(),f(t,"class","a9s-outer"),f(t,"points",n=e[13]),f(o,"class","a9s-inner"),f(o,"points",i=e[13])},m(a,l){I(a,t,l),I(a,o,l),r&&r.m(a,l),I(a,s,l)},p(a,l){l&14&&n!==(n=a[13])&&f(t,"points",n),l&14&&i!==(i=a[13])&&f(o,"points",i),a[3]?r?r.p(a,l):(r=rn(a),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(a){a&&O(t),a&&O(o),r&&r.d(a),a&&O(s)}}}function rn(e){let t,n,o;return{c(){t=P("rect"),f(t,"class","a9s-corner-handle"),f(t,"x",n=e[1][0][0]-e[4]/2),f(t,"y",o=e[1][0][1]-e[4]/2),f(t,"height",e[4]),f(t,"width",e[4])},m(i,s){I(i,t,s)},p(i,s){s&18&&n!==(n=i[1][0][0]-i[4]/2)&&f(t,"x",n),s&18&&o!==(o=i[1][0][1]-i[4]/2)&&f(t,"y",o),s&16&&f(t,"height",i[4]),s&16&&f(t,"width",i[4])},d(i){i&&O(t)}}}function Do(e){let t,n=e[2]&&sn(tt(e));return{c(){t=P("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(o,i){I(o,t,i),n&&n.m(t,null),e[7](t)},p(o,[i]){o[2]?n?n.p(tt(o),i):(n=sn(tt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:U,o:U,d(o){o&&O(t),n&&n.d(),e[7](null)}}}const Uo=20;function No(e,t,n){let o;const i=he();let{transform:s}=t,{viewportScale:r=1}=t,a,l=[],u=null,h=!1;const c=p=>{const T=s.elementToImage(p.offsetX,p.offsetY);l.length===0&&l.push(T),n(2,u=T)},d=p=>{if(l.length>0&&(n(2,u=s.elementToImage(p.offsetX,p.offsetY)),l.length>2)){const T=et(u,l[0])*r;n(3,h=T<Uo)}},m=p=>{if(l.length===1&&et(l[0],u)<=4){n(1,l=[]),n(2,u=null);return}if(p.stopImmediatePropagation(),h){const T={type:H.POLYGON,geometry:{bounds:ve(l),points:[...l]}};n(1,l=[]),n(2,u=null),i("create",T)}else l.push(u)},g=()=>{const p=[...l,u],T={type:H.POLYGON,geometry:{bounds:ve(p),points:p}};n(1,l=[]),n(2,u=null),i("create",T)};Se(()=>{const p=a.closest("svg");return p.addEventListener("pointerdown",c,!0),p.addEventListener("pointermove",d),p.addEventListener("pointerup",m,!0),p.addEventListener("dblclick",g,!0),()=>{p.removeEventListener("pointerdown",c,!0),p.removeEventListener("pointermove",d,!0),p.removeEventListener("pointerup",m,!0),p.removeEventListener("dblclick",g,!0)}});function _(p){pe[p?"unshift":"push"](()=>{a=p,n(0,a)})}return e.$$set=p=>{"transform"in p&&n(5,s=p.transform),"viewportScale"in p&&n(6,r=p.viewportScale)},e.$$.update=()=>{e.$$.dirty&64&&n(4,o=10/r)},[a,l,u,h,o,s,r,_]}class Ho extends te{constructor(t){super(),ee(this,t,No,Do,q,{transform:5,viewportScale:6})}}const nt=new Map([["rectangle",tn],["polygon",Ho]]),Fo=()=>[...nt.keys()],ot=e=>nt.get(e),ln=(e,t)=>nt.set(e,t);function zo(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("ellipse"),i=P("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){I(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:U,o:U,d(r){r&&O(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:u,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=Pe(i,r))},[i,o,a,l,u,h,s,r]}class Vo extends te{constructor(t){super(),ee(this,t,jo,zo,q,{annotation:0,geom:6,style:7})}}function Wo(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("polygon"),i=P("polygon"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"points",e[2].map(qo).join(" ")),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"points",e[2].map(Jo).join(" ")),f(t,"data-id",s=e[0].id)},m(r,a){I(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:U,o:U,d(r){r&&O(t)}}}const qo=e=>e.join(","),Jo=e=>e.join(",");function Qo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,i=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Pe(i,r))},[i,o,a,s,r]}class Zo extends te{constructor(t){super(),ee(this,t,Qo,Wo,q,{annotation:0,geom:3,style:4})}}function Ko(e){let t,n,o,i,s;return{c(){t=P("g"),n=P("rect"),i=P("rect"),f(n,"class","a9s-outer"),f(n,"style",o=e[1]?"display:none;":void 0),f(n,"x",e[2]),f(n,"y",e[3]),f(n,"width",e[4]),f(n,"height",e[5]),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"x",e[2]),f(i,"y",e[3]),f(i,"width",e[4]),f(i,"height",e[5]),f(t,"data-id",s=e[0].id)},m(r,a){I(r,t,a),le(t,n),le(t,i)},p(r,[a]){a&2&&o!==(o=r[1]?"display:none;":void 0)&&f(n,"style",o),a&2&&f(i,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:U,o:U,d(r){r&&O(t)}}}function xo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{x:a,y:l,w:u,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=Pe(i,r))},[i,o,a,l,u,h,s,r]}class $o extends te{constructor(t){super(),ee(this,t,xo,Ko,q,{annotation:0,geom:6,style:7})}}const ei={elementToImage:(e,t)=>[e,t]},an=e=>({elementToImage:(t,n)=>{const o=e.createSVGPoint();o.x=t,o.y=n;const{x:i,y:s}=o.matrixTransform(e.getCTM().inverse());return[i,s]}}),ti=200,cn=(e,t)=>{const n=he();let o;return{onPointerDown:()=>o=new Date().getTime(),onPointerUp:r=>{if(new Date().getTime()-o<ti){const{x:l,y:u}=ni(r,e),h=t.getAt(l,u);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},ni=(e,t)=>{const n=t.createSVGPoint();if(on){const 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())}else return n.x=e.offsetX,n.y=e.offsetY,n.matrixTransform(t.getCTM().inverse())};function fn(e,t,n){const o=e.slice();return o[23]=t[n],o}function un(e,t,n){const o=e.slice();return o[26]=t[n],o}function it(e){const t=e.slice(),n=t[26].target.selector;return t[29]=n,t}function dn(e){let t=e[26].id,n,o,i=hn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),I(s,n,r),o=!0},p(s,r){r&1024&&q(t,t=s[26].id)?(se(),D(i,1,1,U),re(),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){D(i),o=!1},d(s){s&&O(n),i.d(s)}}}function oi(e){let t,n;return t=new Zo({props:{annotation:e[26],geom:e[29].geometry,style:e[0]}}),{c(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i&1024&&(s.annotation=o[26]),i&1024&&(s.geom=o[29].geometry),i&1&&(s.style=o[0]),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function ii(e){let t,n;return t=new $o({props:{annotation:e[26],geom:e[29].geometry,style:e[0]}}),{c(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i&1024&&(s.annotation=o[26]),i&1024&&(s.geom=o[29].geometry),i&1&&(s.style=o[0]),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function si(e){let t,n;return t=new Vo({props:{annotation:e[26],geom:e[29].geometry,style:e[0]}}),{c(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i&1024&&(s.annotation=o[26]),i&1024&&(s.geom=o[29].geometry),i&1&&(s.style=o[0]),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function hn(e){let t,n,o,i;const s=[si,ii,oi],r=[];function a(l,u){return l[29].type===H.ELLIPSE?0:l[29].type===H.RECTANGLE?1:l[29].type===H.POLYGON?2:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,u){~t&&r[t].m(l,u),I(l,o,u),i=!0},p(l,u){let h=t;t=a(l),t===h?~t&&r[t].p(l,u):(n&&(se(),D(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,u):(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){D(n),i=!1},d(l){~t&&r[t].d(l),l&&O(o)}}}function mn(e){let t=!e[6](e[26]),n,o,i=t&&dn(it(e));return{c(){i&&i.c(),n=ie()},m(s,r){i&&i.m(s,r),I(s,n,r),o=!0},p(s,r){r&1088&&(t=!s[6](s[26])),t?i?(i.p(it(s),r),r&1088&&Y(i,1)):(i=dn(it(s)),i.c(),Y(i,1),i.m(n.parentNode,n)):i&&(se(),D(i,1,1,()=>{i=null}),re())},i(s){o||(Y(i),o=!0)},o(s){D(i),o=!1},d(s){i&&i.d(s),s&&O(n)}}}function gn(e){let t,n,o,i;const s=[li,ri],r=[];function a(l,u){return l[5]?0:l[1]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ie()},m(l,u){~t&&r[t].m(l,u),I(l,o,u),i=!0},p(l,u){let h=t;t=a(l),t===h?~t&&r[t].p(l,u):(n&&(se(),D(r[h],1,1,()=>{r[h]=null}),re()),~t?(n=r[t],n?n.p(l,u):(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){D(n),i=!1},d(l){~t&&r[t].d(l),l&&O(o)}}}function ri(e){let t=e[1],n,o,i=pn(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),I(s,n,r),o=!0},p(s,r){r&2&&q(t,t=s[1])?(se(),D(i,1,1,U),re(),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){D(i),o=!1},d(s){s&&O(n),i.d(s)}}}function li(e){let t,n,o=e[5],i=[];for(let r=0;r<o.length;r+=1)i[r]=yn(fn(e,o,r));const s=r=>D(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ie()},m(r,a){for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(r,a);I(r,t,a),n=!0},p(r,a){if(a&35369){o=r[5];let l;for(l=0;l<o.length;l+=1){const u=fn(r,o,l);i[l]?(i[l].p(u,a),Y(i[l],1)):(i[l]=yn(u),i[l].c(),Y(i[l],1),i[l].m(t.parentNode,t))}for(se(),l=o.length;l<i.length;l+=1)s(l);re()}},i(r){if(!n){for(let a=0;a<o.length;a+=1)Y(i[a]);n=!0}},o(r){i=i.filter(Boolean);for(let a=0;a<i.length;a+=1)D(i[a]);n=!1},d(r){je(i,r),r&&O(t)}}}function pn(e){let t,n;return t=new $t({props:{target:e[3],tool:e[1],transform:e[9],viewportScale:e[11]}}),t.$on("create",e[14]),{c(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){const s={};i&8&&(s.target=o[3]),i&2&&(s.tool=o[1]),i&512&&(s.transform=o[9]),i&2048&&(s.viewportScale=o[11]),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function _n(e){let t,n;return t=new xt({props:{target:e[3],editor:xe(e[23].target.selector),annotation:e[23],style:e[0],transform:e[9],viewportScale:e[11]}}),t.$on("change",function(){z(e[15](e[23]))&&e[15](e[23]).apply(this,arguments)}),{c(){ue(t.$$.fragment)},m(o,i){ae(t,o,i),n=!0},p(o,i){e=o;const s={};i&8&&(s.target=e[3]),i&32&&(s.editor=xe(e[23].target.selector)),i&32&&(s.annotation=e[23]),i&1&&(s.style=e[0]),i&512&&(s.transform=e[9]),i&2048&&(s.viewportScale=e[11]),t.$set(s)},i(o){n||(Y(t.$$.fragment,o),n=!0)},o(o){D(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function yn(e){let t=e[23].id,n,o,i=_n(e);return{c(){i.c(),n=ie()},m(s,r){i.m(s,r),I(s,n,r),o=!0},p(s,r){r&32&&q(t,t=s[23].id)?(se(),D(i,1,1,U),re(),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){D(i),o=!1},d(s){s&&O(n),i.d(s)}}}function ai(e){let t,n,o,i,s,r,a=e[10],l=[];for(let c=0;c<a.length;c+=1)l[c]=mn(un(e,a,c));const u=c=>D(l[c],1,1,()=>{l[c]=null});let h=e[3]&&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"),h&&h.c(),f(o,"class","drawing"),f(t,"class","a9s-annotationlayer"),yt(t,"drawing",e[1])},m(c,d){I(c,t,d),le(t,n);for(let m=0;m<l.length;m+=1)l[m]&&l[m].m(n,null);le(t,o),h&&h.m(o,null),e[19](o),e[20](t),i=!0,s||(r=[V(t,"pointerup",function(){z(e[7])&&e[7].apply(this,arguments)}),V(t,"pointerdown",function(){z(e[8])&&e[8].apply(this,arguments)})],s=!0)},p(c,[d]){if(e=c,d&1089){a=e[10];let m;for(m=0;m<a.length;m+=1){const g=un(e,a,m);l[m]?(l[m].p(g,d),Y(l[m],1)):(l[m]=mn(g),l[m].c(),Y(l[m],1),l[m].m(n,null))}for(se(),m=a.length;m<l.length;m+=1)u(m);re()}e[3]?h?(h.