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