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