@annotorious/annotorious 3.0.0-rc.1

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.
Files changed (183) hide show
  1. package/README.md +6 -0
  2. package/dist/Annotorious.d.ts +15 -0
  3. package/dist/Annotorious.d.ts.map +1 -0
  4. package/dist/AnnotoriousOpts.d.ts +14 -0
  5. package/dist/AnnotoriousOpts.d.ts.map +1 -0
  6. package/dist/annotation/SVGAnnotationLayer.svelte.d.ts +1 -0
  7. package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts +11 -0
  8. package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -0
  9. package/dist/annotation/Transform.d.ts +6 -0
  10. package/dist/annotation/Transform.d.ts.map +1 -0
  11. package/dist/annotation/editors/Editor.svelte.d.ts +1 -0
  12. package/dist/annotation/editors/EditorMount.svelte.d.ts +1 -0
  13. package/dist/annotation/editors/Handle.d.ts +14 -0
  14. package/dist/annotation/editors/Handle.d.ts.map +1 -0
  15. package/dist/annotation/editors/editorsRegistry.d.ts +5 -0
  16. package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -0
  17. package/dist/annotation/editors/index.d.ts +7 -0
  18. package/dist/annotation/editors/index.d.ts.map +1 -0
  19. package/dist/annotation/editors/polygon/PolygonEditor.svelte.d.ts +1 -0
  20. package/dist/annotation/editors/polygon/index.d.ts +2 -0
  21. package/dist/annotation/editors/polygon/index.d.ts.map +1 -0
  22. package/dist/annotation/editors/rectangle/RectangleEditor.svelte.d.ts +1 -0
  23. package/dist/annotation/editors/rectangle/index.d.ts +2 -0
  24. package/dist/annotation/editors/rectangle/index.d.ts.map +1 -0
  25. package/dist/annotation/index.d.ts +7 -0
  26. package/dist/annotation/index.d.ts.map +1 -0
  27. package/dist/annotation/shapes/Ellipse.svelte.d.ts +1 -0
  28. package/dist/annotation/shapes/Polygon.svelte.d.ts +1 -0
  29. package/dist/annotation/shapes/Rectangle.svelte.d.ts +1 -0
  30. package/dist/annotation/shapes/index.d.ts +4 -0
  31. package/dist/annotation/shapes/index.d.ts.map +1 -0
  32. package/dist/annotation/tools/DrawingToolConfig.d.ts +8 -0
  33. package/dist/annotation/tools/DrawingToolConfig.d.ts.map +1 -0
  34. package/dist/annotation/tools/ToolMount.svelte.d.ts +1 -0
  35. package/dist/annotation/tools/drawingToolsRegistry.d.ts +17 -0
  36. package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -0
  37. package/dist/annotation/tools/index.d.ts +5 -0
  38. package/dist/annotation/tools/index.d.ts.map +1 -0
  39. package/dist/annotation/tools/polygon/RubberbandPolygon.svelte.d.ts +1 -0
  40. package/dist/annotation/tools/polygon/index.d.ts +2 -0
  41. package/dist/annotation/tools/polygon/index.d.ts.map +1 -0
  42. package/dist/annotation/tools/rectangle/RubberbandRectangle.svelte.d.ts +1 -0
  43. package/dist/annotation/tools/rectangle/index.d.ts +2 -0
  44. package/dist/annotation/tools/rectangle/index.d.ts.map +1 -0
  45. package/dist/annotation/utils/index.d.ts +4 -0
  46. package/dist/annotation/utils/index.d.ts.map +1 -0
  47. package/dist/annotation/utils/math.d.ts +2 -0
  48. package/dist/annotation/utils/math.d.ts.map +1 -0
  49. package/dist/annotation/utils/responsive.d.ts +5 -0
  50. package/dist/annotation/utils/responsive.d.ts.map +1 -0
  51. package/dist/annotation/utils/styling.d.ts +4 -0
  52. package/dist/annotation/utils/styling.d.ts.map +1 -0
  53. package/dist/annotation/utils/touch.d.ts +2 -0
  54. package/dist/annotation/utils/touch.d.ts.map +1 -0
  55. package/dist/annotorious.css +1 -0
  56. package/dist/annotorious.es.js +3890 -0
  57. package/dist/annotorious.es.js.map +1 -0
  58. package/dist/annotorious.js +2 -0
  59. package/dist/annotorious.js.map +1 -0
  60. package/dist/index.d.ts +12 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/model/core/ImageAnnotation.d.ts +9 -0
  63. package/dist/model/core/ImageAnnotation.d.ts.map +1 -0
  64. package/dist/model/core/Shape.d.ts +20 -0
  65. package/dist/model/core/Shape.d.ts.map +1 -0
  66. package/dist/model/core/ellipse/Ellipse.d.ts +12 -0
  67. package/dist/model/core/ellipse/Ellipse.d.ts.map +1 -0
  68. package/dist/model/core/ellipse/ellipseUtils.d.ts +2 -0
  69. package/dist/model/core/ellipse/ellipseUtils.d.ts.map +1 -0
  70. package/dist/model/core/ellipse/index.d.ts +3 -0
  71. package/dist/model/core/ellipse/index.d.ts.map +1 -0
  72. package/dist/model/core/index.d.ts +7 -0
  73. package/dist/model/core/index.d.ts.map +1 -0
  74. package/dist/model/core/polygon/Polygon.d.ts +9 -0
  75. package/dist/model/core/polygon/Polygon.d.ts.map +1 -0
  76. package/dist/model/core/polygon/index.d.ts +3 -0
  77. package/dist/model/core/polygon/index.d.ts.map +1 -0
  78. package/dist/model/core/polygon/polygonUtils.d.ts +2 -0
  79. package/dist/model/core/polygon/polygonUtils.d.ts.map +1 -0
  80. package/dist/model/core/rectangle/Rectangle.d.ts +12 -0
  81. package/dist/model/core/rectangle/Rectangle.d.ts.map +1 -0
  82. package/dist/model/core/rectangle/index.d.ts +3 -0
  83. package/dist/model/core/rectangle/index.d.ts.map +1 -0
  84. package/dist/model/core/rectangle/rectangleUtils.d.ts +4 -0
  85. package/dist/model/core/rectangle/rectangleUtils.d.ts.map +1 -0
  86. package/dist/model/core/shapeUtils.d.ts +35 -0
  87. package/dist/model/core/shapeUtils.d.ts.map +1 -0
  88. package/dist/model/index.d.ts +3 -0
  89. package/dist/model/index.d.ts.map +1 -0
  90. package/dist/model/w3c/W3CImageFormatAdapter.d.ts +7 -0
  91. package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -0
  92. package/dist/model/w3c/fragment/FragmentSelector.d.ts +10 -0
  93. package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -0
  94. package/dist/model/w3c/fragment/index.d.ts +2 -0
  95. package/dist/model/w3c/fragment/index.d.ts.map +1 -0
  96. package/dist/model/w3c/index.d.ts +4 -0
  97. package/dist/model/w3c/index.d.ts.map +1 -0
  98. package/dist/model/w3c/svg/SVG.d.ts +5 -0
  99. package/dist/model/w3c/svg/SVG.d.ts.map +1 -0
  100. package/dist/model/w3c/svg/SVGSelector.d.ts +9 -0
  101. package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -0
  102. package/dist/model/w3c/svg/index.d.ts +2 -0
  103. package/dist/model/w3c/svg/index.d.ts.map +1 -0
  104. package/dist/state/ImageAnnotationStore.d.ts +11 -0
  105. package/dist/state/ImageAnnotationStore.d.ts.map +1 -0
  106. package/dist/state/ImageAnnotatorState.d.ts +12 -0
  107. package/dist/state/ImageAnnotatorState.d.ts.map +1 -0
  108. package/dist/state/index.d.ts +3 -0
  109. package/dist/state/index.d.ts.map +1 -0
  110. package/dist/state/spatialTree.d.ts +21 -0
  111. package/dist/state/spatialTree.d.ts.map +1 -0
  112. package/dist/themes/index.d.ts +2 -0
  113. package/dist/themes/index.d.ts.map +1 -0
  114. package/dist/themes/smart/index.d.ts +2 -0
  115. package/dist/themes/smart/index.d.ts.map +1 -0
  116. package/dist/themes/smart/setTheme.d.ts +3 -0
  117. package/dist/themes/smart/setTheme.d.ts.map +1 -0
  118. package/package.json +55 -0
  119. package/src/Annotorious.css +74 -0
  120. package/src/Annotorious.ts +158 -0
  121. package/src/AnnotoriousOpts.ts +40 -0
  122. package/src/annotation/SVGAnnotationLayer.svelte +169 -0
  123. package/src/annotation/SVGAnnotationLayerPointerEvent.ts +55 -0
  124. package/src/annotation/Transform.ts +24 -0
  125. package/src/annotation/editors/Editor.svelte +61 -0
  126. package/src/annotation/editors/EditorMount.svelte +44 -0
  127. package/src/annotation/editors/Handle.ts +21 -0
  128. package/src/annotation/editors/editorsRegistry.ts +14 -0
  129. package/src/annotation/editors/index.ts +7 -0
  130. package/src/annotation/editors/polygon/PolygonEditor.svelte +64 -0
  131. package/src/annotation/editors/polygon/index.ts +1 -0
  132. package/src/annotation/editors/rectangle/RectangleEditor.svelte +143 -0
  133. package/src/annotation/editors/rectangle/index.ts +1 -0
  134. package/src/annotation/index.ts +7 -0
  135. package/src/annotation/shapes/Ellipse.svelte +32 -0
  136. package/src/annotation/shapes/Polygon.svelte +26 -0
  137. package/src/annotation/shapes/Rectangle.svelte +32 -0
  138. package/src/annotation/shapes/index.ts +3 -0
  139. package/src/annotation/tools/DrawingToolConfig.ts +9 -0
  140. package/src/annotation/tools/ToolMount.svelte +49 -0
  141. package/src/annotation/tools/drawingToolsRegistry.ts +26 -0
  142. package/src/annotation/tools/index.ts +4 -0
  143. package/src/annotation/tools/polygon/RubberbandPolygon.svelte +165 -0
  144. package/src/annotation/tools/polygon/index.ts +1 -0
  145. package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +131 -0
  146. package/src/annotation/tools/rectangle/index.ts +1 -0
  147. package/src/annotation/utils/index.ts +3 -0
  148. package/src/annotation/utils/math.ts +6 -0
  149. package/src/annotation/utils/responsive.ts +56 -0
  150. package/src/annotation/utils/styling.ts +19 -0
  151. package/src/annotation/utils/touch.ts +1 -0
  152. package/src/index.ts +20 -0
  153. package/src/model/core/ImageAnnotation.ts +14 -0
  154. package/src/model/core/Shape.ts +37 -0
  155. package/src/model/core/ellipse/Ellipse.ts +21 -0
  156. package/src/model/core/ellipse/ellipseUtils.ts +28 -0
  157. package/src/model/core/ellipse/index.ts +2 -0
  158. package/src/model/core/index.ts +6 -0
  159. package/src/model/core/polygon/Polygon.ts +15 -0
  160. package/src/model/core/polygon/index.ts +2 -0
  161. package/src/model/core/polygon/polygonUtils.ts +43 -0
  162. package/src/model/core/rectangle/Rectangle.ts +21 -0
  163. package/src/model/core/rectangle/index.ts +2 -0
  164. package/src/model/core/rectangle/rectangleUtils.ts +17 -0
  165. package/src/model/core/shapeUtils.ts +57 -0
  166. package/src/model/index.ts +2 -0
  167. package/src/model/w3c/W3CImageFormatAdapter.ts +83 -0
  168. package/src/model/w3c/fragment/FragmentSelector.ts +59 -0
  169. package/src/model/w3c/fragment/index.ts +1 -0
  170. package/src/model/w3c/index.ts +3 -0
  171. package/src/model/w3c/svg/SVG.ts +36 -0
  172. package/src/model/w3c/svg/SVGSelector.ts +99 -0
  173. package/src/model/w3c/svg/index.ts +1 -0
  174. package/src/state/ImageAnnotationStore.ts +18 -0
  175. package/src/state/ImageAnnotatorState.ts +88 -0
  176. package/src/state/index.ts +2 -0
  177. package/src/state/spatialTree.ts +108 -0
  178. package/src/themes/dark/index.css +24 -0
  179. package/src/themes/index.ts +1 -0
  180. package/src/themes/light/index.css +30 -0
  181. package/src/themes/smart/index.ts +1 -0
  182. package/src/themes/smart/setTheme.ts +46 -0
  183. package/src/vite-env.d.ts +2 -0
@@ -0,0 +1,2 @@
1
+ (function(S,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(S=typeof globalThis<"u"?globalThis:S||self,G(S.Annotorious={}))})(this,function(S){"use strict";function G(){}function On(e,t){for(const n in t)e[n]=t[n];return e}function dt(e){return e()}function ht(){return Object.create(null)}function re(e){e.forEach(dt)}function V(e){return typeof e=="function"}function Z(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Bn(e){return Object.keys(e).length===0}function mt(e,...t){if(e==null)return G;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function gt(e,t,n){e.$$.on_destroy.push(mt(t,n))}function In(e,t,n,o){if(e){const i=pt(e,t,n,o);return e[0](i)}}function pt(e,t,n,o){return e[1]&&o?On(n.ctx.slice(),e[1](o(t))):n.ctx}function Cn(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function Pn(e,t,n,o,i,s){if(i){const r=pt(t,n,o,s);e.p(r,i)}}function kn(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 fe(e,t){e.appendChild(t)}function B(e,t,n){e.insertBefore(t,n||null)}function O(e){e.parentNode&&e.parentNode.removeChild(e)}function We(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function D(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function _t(e){return document.createTextNode(e)}function te(){return _t(" ")}function le(){return _t("")}function W(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function u(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Rn(e){return Array.from(e.childNodes)}function yt(e,t,n){e.classList[n?"add":"remove"](t)}function Yn(e,t,{bubbles:n=!1,cancelable:o=!1}={}){const i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,o,t),i}let Le;function Oe(e){Le=e}function wt(){if(!Le)throw new Error("Function called outside component initialization");return Le}function Be(e){wt().$$.on_mount.push(e)}function ye(){const e=wt();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Yn(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function we(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const be=[],Ee=[];let Ae=[];const bt=[],Dn=Promise.resolve();let qe=!1;function Xn(){qe||(qe=!0,Dn.then(Et))}function Je(e){Ae.push(e)}const Qe=new Set;let Te=0;function Et(){if(Te!==0)return;const e=Le;do{try{for(;Te<be.length;){const t=be[Te];Te++,Oe(t),Un(t.$$)}}catch(t){throw be.length=0,Te=0,t}for(Oe(null),be.length=0,Te=0;Ee.length;)Ee.pop()();for(let t=0;t<Ae.length;t+=1){const n=Ae[t];Qe.has(n)||(Qe.add(n),n())}Ae.length=0}while(be.length);for(;bt.length;)bt.pop()();qe=!1,Qe.clear(),Oe(e)}function Un(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(Je)}}function Nn(e){const t=[],n=[];Ae.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ae=t}const Ye=new Set;let me;function ae(){me={r:0,c:[],p:me}}function ce(){me.r||re(me.c),me=me.p}function U(e,t){e&&e.i&&(Ye.delete(e),e.i(t))}function N(e,t,n,o){if(e&&e.o){if(Ye.has(e))return;Ye.add(e),me.c.push(()=>{Ye.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ge(e){e&&e.c()}function ue(e,t,n,o){const{fragment:i,after_update:s}=e.$$;i&&i.m(t,n),o||Je(()=>{const r=e.$$.on_mount.map(dt).filter(V);e.$$.on_destroy?e.$$.on_destroy.push(...r):re(r),e.$$.on_mount=[]}),s.forEach(Je)}function de(e,t){const n=e.$$;n.fragment!==null&&(Nn(n.after_update),re(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Gn(e,t){e.$$.dirty[0]===-1&&(be.push(e),Xn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ne(e,t,n,o,i,s,r,l=[-1]){const a=Le;Oe(e);const d=e.$$={fragment:null,ctx:[],props:s,update:G,not_equal:i,bound:ht(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:ht(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(d.root);let h=!1;if(d.ctx=n?n(e,t.props||{},(c,f,...m)=>{const g=m.length?m[0]:f;return d.ctx&&i(d.ctx[c],d.ctx[c]=g)&&(!d.skip_bound&&d.bound[c]&&d.bound[c](g),h&&Gn(e,c)),f}):[],d.update(),h=!0,re(d.before_update),d.fragment=o?o(d.ctx):!1,t.target){if(t.hydrate){const c=Rn(t.target);d.fragment&&d.fragment.l(c),c.forEach(O)}else d.fragment&&d.fragment.c();t.intro&&U(e.$$.fragment),ue(e,t.target,t.anchor,t.customElement),Et()}Oe(a)}class oe{$destroy(){de(this,1),this.$destroy=G}$on(t,n){if(!V(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&&!Bn(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}var H=(e=>(e.ELLIPSE="ELLIPSE",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(H||{});const Ze={},De=(e,t)=>Ze[e]=t,Ke=e=>Ze[e.type].area(e),At=(e,t,n)=>Ze[e.type].intersects(e,t,n),Ie=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Fn={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),d=Math.sin(l),h=t-o,c=n-i,f=a*h+d*c,m=d*h-a*c;return f*f/(s*s)+m*m/(r*r)<=1}};De(H.ELLIPSE,Fn);const Hn={area:e=>{const{points:t}=e.geometry;let n=0,o=t.length-1;for(let i=0;i<t.length;i++)n+=(t[o][0]+t[i][0])*(t[o][1]-t[i][1]),o=i;return Math.abs(.5*n)},intersects:(e,t,n)=>{const{points:o}=e.geometry;let i=!1;for(let s=0,r=o.length-1;s<o.length;r=s++){const l=o[s][0],a=o[s][1],d=o[r][0],h=o[r][1];a>n!=h>n&&t<(d-l)*(n-a)/(h-a)+l&&(i=!i)}return i}};De(H.POLYGON,Hn);const Tt={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};De(H.RECTANGLE,Tt);const St=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,l,a,d,h,c]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[f,m,g,p]=[a,d,h,c].map(parseFloat);return{type:H.RECTANGLE,geometry:{x:f,y:m,w:g,h:p,bounds:{minX:f,minY:t?m-p:m,maxX:f+g,maxY:t?m:m+p}}}},Mt=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},vt="http://www.w3.org/2000/svg",Lt=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},zn=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${vt}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},jn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(vt),i=n.lookupNamespaceURI(null);return o||i?Lt(n).firstChild:Lt(zn(n)).firstChild},Vn=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[];if(!o)return;const i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:H.POLYGON,geometry:{points:i,bounds:Ie(i)}}},Wn=e=>{const t=jn(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:H.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},Ot=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Vn(t);if(t.includes("<ellipse "))return Wn(t)},Bt=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 Xe;const qn=new Uint8Array(16);function Jn(){if(!Xe&&(Xe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Xe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Xe(qn)}const q=[];for(let e=0;e<256;++e)q.push((e+256).toString(16).slice(1));function Qn(e,t=0){return q[e[t+0]]+q[e[t+1]]+q[e[t+2]]+q[e[t+3]]+"-"+q[e[t+4]]+q[e[t+5]]+"-"+q[e[t+6]]+q[e[t+7]]+"-"+q[e[t+8]]+q[e[t+9]]+"-"+q[e[t+10]]+q[e[t+11]]+q[e[t+12]]+q[e[t+13]]+q[e[t+14]]+q[e[t+15]]}const It={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function xe(e,t,n){if(It.randomUUID&&!t&&!e)return It.randomUUID();e=e||{};const o=e.random||(e.rng||Jn)();if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=o[i];return t}return Qn(o)}var Ct=Object.prototype.hasOwnProperty;function pe(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&pe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(Ct.call(e,n)&&++o&&!Ct.call(t,n)||!(n in t)||!pe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Se=[];function Ue(e,t=G){let n;const o=new Set;function i(l){if(Z(e,l)&&(e=l,n)){const a=!Se.length;for(const d of o)d[1](),Se.push(d,e);if(a){for(let d=0;d<Se.length;d+=2)Se[d][0](Se[d+1]);Se.length=0}}}function s(l){i(l(e))}function r(l,a=G){const d=[l,a];return o.add(d),o.size===1&&(n=t(i)||G),l(e),()=>{o.delete(d),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Zn=e=>{const{subscribe:t,set:n}=Ue(null);let o=null;return t(i=>o=i),e.observe(({changes:i})=>{if(o){i.deleted.some(l=>l.id===o)&&n(null);const r=i.updated.find(({oldValue:l})=>l.id===o);r&&n(r.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Pt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Pt||{});const $e={selected:[]},Kn=(e,t="EDIT")=>{const{subscribe:n,set:o}=Ue($e);let i=$e;n(c=>i=c);const s=()=>o($e),r=()=>{var c;return((c=i.selected)==null?void 0:c.length)===0},l=c=>{if(i.selected.length===0)return!1;const f=typeof c=="string"?c:c.id;return i.selected.some(m=>m.id===f)},a=(c,f)=>{const m=e.getAnnotation(c);if(m){const g=xn(m,t);o(g==="EDIT"?{selected:[{id:c,editable:!0}],pointerEvent:f}:g==="SELECT"?{selected:[{id:c}],pointerEvent:f}:{selected:[],pointerEvent:f})}else console.warn("Invalid selection: "+c)},d=(c,f=!0)=>{const m=Array.isArray(c)?c:[c],g=m.map(p=>e.getAnnotation(p)).filter(p=>p);o({selected:g.map(({id:p})=>({id:p,editable:f}))}),g.length!==m.length&&console.warn("Invalid selection",c)},h=c=>{if(i.selected.length===0)return!1;const{selected:f}=i;f.filter(({id:g})=>c.includes(g)).length>0&&o({selected:f.filter(({id:g})=>!c.includes(g))})};return e.observe(({changes:c})=>h(c.deleted.map(f=>f.id))),{clear:s,clickSelect:a,get selected(){return i?[...i.selected]:null},get pointerEvent(){return i?i.pointerEvent:null},isEmpty:r,isSelected:l,setSelected:d,subscribe:n}},xn=(e,t)=>typeof t=="function"?t(e)||"EDIT":t||"EDIT",$n=e=>{const{creator:t,updatedBy:n}=e.target,o=e.bodies.reduce((i,s)=>[...i,s.creator,s.updatedBy],[]);return[t,n,...o].filter(i=>i)},eo=(e,t,n,o)=>({id:xe(),annotation:e.id,created:n||new Date,creator:o,...t}),to=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},no=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},oo=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!pe(o,n)?o:void 0}}).filter(({oldBody:n})=>n),io=(e,t)=>!pe(e.target,t.target),kt=(e,t)=>({oldValue:e,newValue:t,bodiesCreated:to(e,t),bodiesDeleted:no(e,t),bodiesUpdated:oo(e,t),targetUpdated:io(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0});var z=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e))(z||{});const so=(e,t)=>{var s,r;const{changes:n,origin:o}=t;if(!(!e.options.origin||e.options.origin===o))return!1;if(e.options.ignore){const{ignore:l}=e.options,a=h=>(h==null?void 0:h.length)>0;if(!(a(n.created)||a(n.deleted))){const h=(s=n.updated)==null?void 0:s.some(f=>a(f.bodiesCreated)||a(f.bodiesDeleted)||a(f.bodiesUpdated)),c=(r=n.updated)==null?void 0:r.some(f=>f.targetUpdated);if(l==="BODY_ONLY"&&h&&!c||l==="TARGET_ONLY"&&c&&!h)return!1}}if(e.options.annotations){const l=new Set([...n.created.map(d=>d.id),...n.deleted.map(d=>d.id),...n.updated.map(({oldValue:d})=>d.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(d=>l.has(d))}else return!0},ro=e=>e.id!==void 0,lo=()=>{const e=new Map,t=new Map,n=[],o=(_,w={})=>n.push({onChange:_,options:w}),i=_=>{const w=n.findIndex(A=>A.onChange==_);w>-1&&n.splice(w,1)},s=(_,w)=>{const A={origin:_,changes:{created:w.created||[],updated:w.updated||[],deleted:w.deleted||[]},state:[...e.values()]};n.forEach(M=>{so(M,A)&&M.onChange(A)})},r=(_,w=z.LOCAL)=>{if(e.get(_.id))throw Error(`Cannot add annotation ${_.id} - exists already`);e.set(_.id,_),_.bodies.forEach(M=>t.set(M.id,_.id)),s(w,{created:[_]})},l=(_,w=z.LOCAL,A=z.LOCAL)=>{const M=ro(w)?A:w,I=typeof _=="string"?w:_,R=typeof _=="string"?_:_.id,K=e.get(R);if(K){const he=kt(K,I);R===I.id?e.set(R,I):(e.delete(R),e.set(I.id,I)),K.bodies.forEach(ie=>t.delete(ie.id)),I.bodies.forEach(ie=>t.set(ie.id,I.id)),s(M,{updated:[he]})}else throw Error(`Cannot update annotation ${R} - does not exist`)},a=(_,w=z.LOCAL)=>{const A=e.get(_.annotation);if(A){const M={...A,bodies:[...A.bodies,_]};e.set(A.id,M),t.set(_.id,M.id),s(w,{updated:[{oldValue:A,newValue:M,bodiesCreated:[_]}]})}else console.warn(`Attempt to add body to missing annotation: ${_.annotation}`)},d=()=>[...e.values()],h=(_=z.LOCAL)=>{const w=[...e.values()];e.clear(),t.clear(),s(_,{deleted:w})},c=(_,w=!0,A=z.LOCAL)=>{if(w){const M=[...e.values()];e.clear(),t.clear(),_.forEach(I=>{e.set(I.id,I),I.bodies.forEach(R=>t.set(R.id,I.id))}),s(A,{created:_,deleted:M})}else{const M=_.reduce((I,R)=>{const K=e.get(R.id);return K?[...I,K]:I},[]);if(M.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${M.map(I=>I.id).join(", ")}`);_.forEach(I=>{e.set(I.id,I),I.bodies.forEach(R=>t.set(R.id,I.id))}),s(A,{created:_})}},f=_=>{const w=typeof _=="string"?_:_.id,A=e.get(w);if(A)return e.delete(w),A.bodies.forEach(M=>t.delete(M.id)),A;console.warn(`Attempt to delete missing annotation: ${w}`)},m=(_,w=z.LOCAL)=>{const A=f(_);A&&s(w,{deleted:[A]})},g=(_,w=z.LOCAL)=>{const A=_.reduce((M,I)=>{const R=f(I);return R?[...M,R]:M},[]);A.length>0&&s(w,{deleted:A})},p=(_,w=z.LOCAL)=>{const A=e.get(_.annotation);if(A){const M=A.bodies.find(I=>I.id===_.id);if(M){t.delete(M.id);const I={...A,bodies:A.bodies.filter(K=>K.id!==_.id)};e.set(A.id,I),s(w,{updated:[{oldValue:A,newValue:I,bodiesDeleted:[M]}]})}else console.warn(`Attempt to delete missing body ${_.id} from annotation ${_.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${_.annotation}`)},y=_=>{const w=e.get(_);return w?{...w}:void 0},L=_=>{const w=t.get(_);if(w){const M=y(w).bodies.find(I=>I.id===_);if(M)return M;console.error(`Store integrity error: body ${_} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${_}`)},E=(_,w)=>{if(_.annotation!==w.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const A=e.get(_.annotation);if(A){const M=A.bodies.find(R=>R.id===_.id),I={...A,bodies:A.bodies.map(R=>R.id===M.id?w:R)};return e.set(A.id,I),M.id!==w.id&&(t.delete(M.id),t.set(w.id,I.id)),{oldValue:A,newValue:I,bodiesUpdated:[{oldBody:M,newBody:w}]}}else console.warn(`Attempt to add body to missing annotation ${_.annotation}`)},C=(_,w,A=z.LOCAL)=>{const M=E(_,w);s(A,{updated:[M]})},b=(_,w=z.LOCAL)=>{const A=_.map(M=>E({id:M.id,annotation:M.annotation},M));s(w,{updated:A})},Y=_=>{const w=e.get(_.annotation);if(w){const A={...w,target:{...w.target,..._}};return e.set(w.id,A),{oldValue:w,newValue:A,targetUpdated:{oldTarget:w.target,newTarget:_}}}else console.warn(`Attempt to update target on missing annotation: ${_.annotation}`)};return{addAnnotation:r,addBody:a,all:d,bulkAddAnnotation:c,bulkDeleteAnnotation:g,bulkUpdateBodies:b,bulkUpdateTargets:(_,w=z.LOCAL)=>{const A=_.map(Y).filter(M=>M);A.length>0&&s(w,{updated:A})},clear:h,deleteAnnotation:m,deleteBody:p,getAnnotation:y,getBody:L,observe:o,unobserve:i,updateAnnotation:l,updateBody:C,updateTarget:(_,w=z.LOCAL)=>{const A=Y(_);A&&s(w,{updated:[A]})}}},ao=e=>({...e,subscribe:n=>{const o=i=>n(i.state);return e.observe(o),n(e.all()),()=>e.unobserve(o)}}),co=()=>{const{subscribe:e,set:t}=Ue([]);return{subscribe:e,set:t}},fo=(e,t,n,o,i,s)=>{const r=new Map;let l=[],a,d;const h=(g,p)=>{r.has(g)?r.get(g).push(p):r.set(g,[p])},c=(g,p)=>{const y=r.get(g);y&&y.indexOf(p)>0&&y.splice(y.indexOf(p),1)},f=(g,p,y)=>{r.has(g)&&setTimeout(()=>{r.get(g).forEach(L=>{if(i){const E=Array.isArray(p)?p.map(b=>i.serialize(b)):i.serialize(p),C=y?y instanceof PointerEvent?y:i.serialize(y):void 0;L(E,C)}else L(p,y)})},1)},m=()=>{const{selected:g}=t,p=g.map(({id:y})=>e.getAnnotation(y));p.forEach(y=>{const L=l.find(E=>E.id===y.id);(!L||!pe(L,y))&&f("updateAnnotation",y,L)}),l=l.map(y=>{const L=p.find(({id:E})=>E===y.id);return L||y})};return t.subscribe(({selected:g})=>{if(!(l.length===0&&g.length===0)){if(l.length===0&&g.length>0)l=g.map(({id:p})=>e.getAnnotation(p));else if(l.length>0&&g.length===0)l.forEach(p=>{const y=e.getAnnotation(p.id);y&&!pe(y,p)&&f("updateAnnotation",y,p)}),l=[];else{const p=new Set(l.map(E=>E.id)),y=new Set(g.map(({id:E})=>E));l.filter(E=>!y.has(E.id)).forEach(E=>{const C=e.getAnnotation(E.id);C&&!pe(C,E)&&f("updateAnnotation",C,E)}),l=[...l.filter(E=>y.has(E.id)),...g.filter(({id:E})=>!p.has(E)).map(({id:E})=>e.getAnnotation(E))]}f("selectionChanged",l)}}),n.subscribe(g=>{!a&&g?f("mouseEnterAnnotation",e.getAnnotation(g)):a&&!g?f("mouseLeaveAnnotation",e.getAnnotation(a)):a&&g&&(f("mouseLeaveAnnotation",e.getAnnotation(a)),f("mouseEnterAnnotation",e.getAnnotation(g))),a=g}),o==null||o.subscribe(g=>f("viewportIntersect",g.map(e.getAnnotation))),e.observe(g=>{s&&(d&&clearTimeout(d),d=setTimeout(m,1e3));const{created:p,deleted:y}=g.changes;p.forEach(E=>f("createAnnotation",E)),y.forEach(E=>f("deleteAnnotation",E)),g.changes.updated.filter(E=>[...E.bodiesCreated||[],...E.bodiesDeleted||[],...E.bodiesUpdated||[]].length>0).forEach(({oldValue:E,newValue:C})=>{const b=l.find(Y=>Y.id===E.id)||E;l=l.map(Y=>Y.id===E.id?C:Y),f("updateAnnotation",C,b)})},{origin:z.LOCAL}),e.observe(g=>{if(l){const p=new Set(l.map(L=>L.id)),y=g.changes.updated.filter(({newValue:L})=>p.has(L.id)).map(({newValue:L})=>L);y.length>0&&(l=l.map(L=>{const E=y.find(C=>C.id===L.id);return E||L}))}},{origin:z.REMOTE}),{on:h,off:c,emit:f}},uo=e=>t=>t.map(n=>e.serialize(n)),Rt=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:{parsed:[...n.parsed,i],failed:n.failed}},{parsed:[],failed:[]}),Yt=(e,t)=>{const n=h=>{if(t){const{parsed:c,error:f}=t.parse(h);c?e.addAnnotation(c,z.REMOTE):console.error(f)}else e.addAnnotation(h,z.REMOTE)},o=()=>e.clear(),i=h=>{const c=e.getAnnotation(h);return t&&c?t.serialize(c):c},s=()=>t?e.all().map(t.serialize):e.all(),r=h=>fetch(h).then(c=>c.json()).then(c=>(a(c),c)),l=h=>{if(typeof h=="string"){const c=e.getAnnotation(h);return e.deleteAnnotation(h),t?t.serialize(c):c}else{const c=t?t.parse(h).parsed:h;return e.deleteAnnotation(c),h}},a=h=>{if(t){const{parsed:c,failed:f}=Rt(t)(h);f.length>0&&console.warn(`Discarded ${f.length} invalid annotations`,f),e.bulkAddAnnotation(c,!0,z.REMOTE)}else e.bulkAddAnnotation(h,!0,z.REMOTE)};return{addAnnotation:n,clearAnnotations:o,getAnnotationById:i,getAnnotations:s,loadAnnotations:r,removeAnnotation:l,setAnnotations:a,updateAnnotation:h=>{if(t){const c=t.parse(h).parsed,f=t.serialize(e.getAnnotation(c.id));return e.updateAnnotation(c),f}else{const c=e.getAnnotation(h.id);return e.updateAnnotation(h),c}}}};let ho=e=>crypto.getRandomValues(new Uint8Array(e)),mo=(e,t,n)=>{let o=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i;for(;a--;)if(r+=e[l[a]&o]||"",r.length===s)return r}}},go=(e,t=21)=>mo(e,t,ho),po=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const Dt=()=>({isGuest:!0,id:go("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),_o=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Xt=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,creator:a,...d}=n;return{id:o||`temp-${_o(n)}`,annotation:t,type:i,purpose:s,value:r,created:l,creator:a?typeof a=="object"?{...a}:a:void 0,...d}}),Ut=e=>e.map(t=>{var o;const n={...t};return delete n.annotation,(o=n.id)!=null&&o.startsWith("temp-")&&delete n.id,n}),yo=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Nt=()=>{const e=[...yo];return{assignRandomColor:()=>{const o=Math.floor(Math.random()*e.length),i=e[o];return e.splice(o,1),i},releaseColor:o=>e.push(o)}},Gt=()=>{const e=Nt();return{addUser:(o,i)=>{const s=e.assignRandomColor();return{label:i.name||i.id,avatar:i.avatar,color:s}},removeUser:o=>e.releaseColor(o.appearance.color)}};let wo=()=>({emit(e,...t){let n=this.events[e]||[];for(let o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return(n=this.events[e])!=null&&n.push(t)||(this.events[e]=[t]),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const bo=(e,t)=>e.every(n=>e.includes(n))&&t.every(n=>e.includes(n)),Eo=po(),Ao=(e=Gt())=>{const t=wo(),n=new Map,o=new Map,i=(c,f)=>{if(n.has(c)){console.warn("Attempt to add user that is already present",c,f);return}const m=e.addUser(c,f);n.set(c,{...f,presenceKey:c,appearance:m})},s=c=>{const f=n.get(c);if(!f){console.warn("Attempt to remove user that is not present",c);return}e.removeUser(f),n.delete(c)},r=c=>{const f=new Set(c.map(p=>p.presenceKey)),m=c.filter(({presenceKey:p})=>!n.has(p)),g=Array.from(n.values()).filter(p=>!f.has(p.presenceKey));m.forEach(({presenceKey:p,user:y})=>i(p,y)),g.forEach(p=>{const{presenceKey:y}=p;o.has(y)&&t.emit("selectionChange",p,null),s(y)}),(m.length>0||g.length>0)&&t.emit("presence",d())},l=(c,f)=>{const m=n.get(c);if(!m){console.warn("Activity notification from user that is not present");return}const g=o.get(c);(!g||!bo(g,f))&&(o.set(c,f),t.emit("selectionChange",m,f))},a=(c,f)=>{const m=n.get(c);if(!m){console.warn("Selection change for user that is not present",c);return}f?o.set(c,f):o.delete(c),t.emit("selectionChange",m,f)},d=()=>[...Array.from(n.values())];return{getPresentUsers:d,notifyActivity:l,on:(c,f)=>t.on(c,f),syncUsers:r,updateSelection:a}},To=(e,t=!1)=>({parse:i=>Ft(i,t),serialize:i=>Ht(i,e)}),Ft=(e,t=!1)=>{const n=e.id||xe(),o=Xt(e.body,n),i=Array.isArray(e.target)?e.target[0]:e.target,s=Array.isArray(i.selector)?i.selector[0]:i.selector,r=s.type==="FragmentSelector"?St(s,t):s.type==="SvgSelector"?Ot(s):void 0;return r?{parsed:{...e,id:n,bodies:o,target:{annotation:n,selector:r}}}:{error:Error(`Unknown selector type: ${r.type}`)}},Ht=(e,t)=>{const n=e.target.selector,o=n.type==H.RECTANGLE?Mt(n.geometry):Bt(n);return{...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Ut(e.bodies),target:{source:t,selector:o}}};function zt(e,t,n){const o=e.slice();return o[11]=t[n],o[13]=n,o}function jt(e){let t,n,o,i,s;return{c(){t=D("rect"),u(t,"class","a9s-corner-handle"),u(t,"x",n=e[11][0]-e[3]/2),u(t,"y",o=e[11][1]-e[3]/2),u(t,"height",e[3]),u(t,"width",e[3])},m(r,l){B(r,t,l),i||(s=W(t,"pointerdown",function(){V(e[10](v(e[13])))&&e[10](v(e[13])).apply(this,arguments)}),i=!0)},p(r,l){e=r,l&24&&n!==(n=e[11][0]-e[3]/2)&&u(t,"x",n),l&24&&o!==(o=e[11][1]-e[3]/2)&&u(t,"y",o),l&8&&u(t,"height",e[3]),l&8&&u(t,"width",e[3])},d(r){r&&O(t),i=!1,s()}}}function So(e){let t,n,o,i,s,r,l,a,d,h,c=e[4].points,f=[];for(let m=0;m<c.length;m+=1)f[m]=jt(zt(e,c,m));return{c(){t=D("polygon"),i=te(),s=D("polygon"),l=te();for(let m=0;m<f.length;m+=1)f[m].c();a=le(),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"points",o=e[4].points.map(Vt).join(" ")),u(s,"class","a9s-inner a9s-shape-handle"),u(s,"style",e[1]),u(s,"points",r=e[4].points.map(Wt).join(" "))},m(m,g){B(m,t,g),B(m,i,g),B(m,s,g),B(m,l,g);for(let p=0;p<f.length;p+=1)f[p]&&f[p].m(m,g);B(m,a,g),d||(h=[W(t,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(s,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)})],d=!0)},p(m,g){if(e=m,g&2&&n!==(n=e[1]?"display:none;":void 0)&&u(t,"style",n),g&16&&o!==(o=e[4].points.map(Vt).join(" "))&&u(t,"points",o),g&2&&u(s,"style",e[1]),g&16&&r!==(r=e[4].points.map(Wt).join(" "))&&u(s,"points",r),g&1048){c=e[4].points;let p;for(p=0;p<c.length;p+=1){const y=zt(e,c,p);f[p]?f[p].p(y,g):(f[p]=jt(y),f[p].c(),f[p].m(a.parentNode,a))}for(;p<f.length;p+=1)f[p].d(1);f.length=c.length}},d(m){m&&O(t),m&&O(i),m&&O(s),m&&O(l),We(f,m),m&&O(a),d=!1,re(h)}}}function Mo(e){let t,n;return t=new tt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[So,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("change",e[7]),t.$on("grab",e[8]),t.$on("release",e[9]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&17434&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}const Vt=e=>e.join(","),Wt=e=>e.join(",");function vo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:l}=t,{viewportScale:a=1}=t;const d=(m,g,p)=>{let y;g===v.SHAPE?y=m.geometry.points.map(([E,C])=>[E+p[0],C+p[1]]):y=m.geometry.points.map(([E,C],b)=>g===v(b)?[E+p[0],C+p[1]]:[E,C]);const L=Ie(y);return{...m,geometry:{points:y,bounds:L}}};function h(m){we.call(this,e,m)}function c(m){we.call(this,e,m)}function f(m){we.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,l=m.transform),"viewportScale"in m&&n(6,a=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/a)},[s,r,l,i,o,d,a,h,c,f]}class qt extends oe{constructor(t){super(),ne(this,t,vo,Mo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}function Lo(e){let t,n,o,i,s,r,l,a,d,h,c,f,m,g,p,y,L,E,C,b,Y,F,X,_,w,A,M,I,R,K,he,ie,Re,x,P,Q,j,J,se,_e,ct,$,He,ze,ft,ee,je,Ve,ut,Ln;return{c(){t=D("rect"),l=te(),a=D("rect"),m=te(),g=D("rect"),E=te(),C=D("rect"),X=te(),_=D("rect"),I=te(),R=D("rect"),Re=te(),x=D("rect"),j=te(),J=D("rect"),ct=te(),$=D("rect"),ft=te(),ee=D("rect"),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"x",o=e[4].x),u(t,"y",i=e[4].y),u(t,"width",s=e[4].w),u(t,"height",r=e[4].h),u(a,"class","a9s-inner a9s-shape-handle"),u(a,"style",e[1]),u(a,"x",d=e[4].x),u(a,"y",h=e[4].y),u(a,"width",c=e[4].w),u(a,"height",f=e[4].h),u(g,"class","a9s-edge-handle a9s-edge-handle-top"),u(g,"x",p=e[4].x),u(g,"y",y=e[4].y),u(g,"height",1),u(g,"width",L=e[4].w),u(C,"class","a9s-edge-handle a9s-edge-handle-right"),u(C,"x",b=e[4].x+e[4].w),u(C,"y",Y=e[4].y),u(C,"height",F=e[4].h),u(C,"width",1),u(_,"class","a9s-edge-handle a9s-edge-handle-bottom"),u(_,"x",w=e[4].x),u(_,"y",A=e[4].y+e[4].h),u(_,"height",1),u(_,"width",M=e[4].w),u(R,"class","a9s-edge-handle a9s-edge-handle-left"),u(R,"x",K=e[4].x),u(R,"y",he=e[4].y),u(R,"height",ie=e[4].h),u(R,"width",1),u(x,"class","a9s-corner-handle a9s-corner-handle-topleft"),u(x,"x",P=e[4].x-e[3]/2),u(x,"y",Q=e[4].y-e[3]/2),u(x,"height",e[3]),u(x,"width",e[3]),u(J,"class","a9s-corner-handle a9s-corner-handle-topright"),u(J,"x",se=e[4].x+e[4].w-e[3]/2),u(J,"y",_e=e[4].y-e[3]/2),u(J,"height",e[3]),u(J,"width",e[3]),u($,"class","a9s-corner-handle a9s-corner-handle-bottomright"),u($,"x",He=e[4].x+e[4].w-e[3]/2),u($,"y",ze=e[4].y+e[4].h-e[3]/2),u($,"height",e[3]),u($,"width",e[3]),u(ee,"class","a9s-corner-handle a9s-corner-handle-bottomleft"),u(ee,"x",je=e[4].x-e[3]/2),u(ee,"y",Ve=e[4].y+e[4].h-e[3]/2),u(ee,"height",e[3]),u(ee,"width",e[3])},m(k,T){B(k,t,T),B(k,l,T),B(k,a,T),B(k,m,T),B(k,g,T),B(k,E,T),B(k,C,T),B(k,X,T),B(k,_,T),B(k,I,T),B(k,R,T),B(k,Re,T),B(k,x,T),B(k,j,T),B(k,J,T),B(k,ct,T),B(k,$,T),B(k,ft,T),B(k,ee,T),ut||(Ln=[W(t,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(a,"pointerdown",function(){V(e[10](v.SHAPE))&&e[10](v.SHAPE).apply(this,arguments)}),W(g,"pointerdown",function(){V(e[10](v.TOP))&&e[10](v.TOP).apply(this,arguments)}),W(C,"pointerdown",function(){V(e[10](v.RIGHT))&&e[10](v.RIGHT).apply(this,arguments)}),W(_,"pointerdown",function(){V(e[10](v.BOTTOM))&&e[10](v.BOTTOM).apply(this,arguments)}),W(R,"pointerdown",function(){V(e[10](v.LEFT))&&e[10](v.LEFT).apply(this,arguments)}),W(x,"pointerdown",function(){V(e[10](v.TOP_LEFT))&&e[10](v.TOP_LEFT).apply(this,arguments)}),W(J,"pointerdown",function(){V(e[10](v.TOP_RIGHT))&&e[10](v.TOP_RIGHT).apply(this,arguments)}),W($,"pointerdown",function(){V(e[10](v.BOTTOM_RIGHT))&&e[10](v.BOTTOM_RIGHT).apply(this,arguments)}),W(ee,"pointerdown",function(){V(e[10](v.BOTTOM_LEFT))&&e[10](v.BOTTOM_LEFT).apply(this,arguments)})],ut=!0)},p(k,T){e=k,T&2&&n!==(n=e[1]?"display:none;":void 0)&&u(t,"style",n),T&16&&o!==(o=e[4].x)&&u(t,"x",o),T&16&&i!==(i=e[4].y)&&u(t,"y",i),T&16&&s!==(s=e[4].w)&&u(t,"width",s),T&16&&r!==(r=e[4].h)&&u(t,"height",r),T&2&&u(a,"style",e[1]),T&16&&d!==(d=e[4].x)&&u(a,"x",d),T&16&&h!==(h=e[4].y)&&u(a,"y",h),T&16&&c!==(c=e[4].w)&&u(a,"width",c),T&16&&f!==(f=e[4].h)&&u(a,"height",f),T&16&&p!==(p=e[4].x)&&u(g,"x",p),T&16&&y!==(y=e[4].y)&&u(g,"y",y),T&16&&L!==(L=e[4].w)&&u(g,"width",L),T&16&&b!==(b=e[4].x+e[4].w)&&u(C,"x",b),T&16&&Y!==(Y=e[4].y)&&u(C,"y",Y),T&16&&F!==(F=e[4].h)&&u(C,"height",F),T&16&&w!==(w=e[4].x)&&u(_,"x",w),T&16&&A!==(A=e[4].y+e[4].h)&&u(_,"y",A),T&16&&M!==(M=e[4].w)&&u(_,"width",M),T&16&&K!==(K=e[4].x)&&u(R,"x",K),T&16&&he!==(he=e[4].y)&&u(R,"y",he),T&16&&ie!==(ie=e[4].h)&&u(R,"height",ie),T&24&&P!==(P=e[4].x-e[3]/2)&&u(x,"x",P),T&24&&Q!==(Q=e[4].y-e[3]/2)&&u(x,"y",Q),T&8&&u(x,"height",e[3]),T&8&&u(x,"width",e[3]),T&24&&se!==(se=e[4].x+e[4].w-e[3]/2)&&u(J,"x",se),T&24&&_e!==(_e=e[4].y-e[3]/2)&&u(J,"y",_e),T&8&&u(J,"height",e[3]),T&8&&u(J,"width",e[3]),T&24&&He!==(He=e[4].x+e[4].w-e[3]/2)&&u($,"x",He),T&24&&ze!==(ze=e[4].y+e[4].h-e[3]/2)&&u($,"y",ze),T&8&&u($,"height",e[3]),T&8&&u($,"width",e[3]),T&24&&je!==(je=e[4].x-e[3]/2)&&u(ee,"x",je),T&24&&Ve!==(Ve=e[4].y+e[4].h-e[3]/2)&&u(ee,"y",Ve),T&8&&u(ee,"height",e[3]),T&8&&u(ee,"width",e[3])},d(k){k&&O(t),k&&O(l),k&&O(a),k&&O(m),k&&O(g),k&&O(E),k&&O(C),k&&O(X),k&&O(_),k&&O(I),k&&O(R),k&&O(Re),k&&O(x),k&&O(j),k&&O(J),k&&O(ct),k&&O($),k&&O(ft),k&&O(ee),ut=!1,re(Ln)}}}function Oo(e){let t,n;return t=new tt({props:{shape:e[0],transform:e[2],editor:e[5],$$slots:{default:[Lo,({grab:o})=>({10:o}),({grab:o})=>o?1024:0]},$$scope:{ctx:e}}}),t.$on("grab",e[7]),t.$on("change",e[8]),t.$on("release",e[9]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&3098&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function Bo(e,t,n){let o,i,{shape:s}=t,{computedStyle:r=void 0}=t,{transform:l}=t,{viewportScale:a=1}=t;const d=(m,g,p)=>{const y=m.geometry.bounds;let[L,E]=[y.minX,y.minY],[C,b]=[y.maxX,y.maxY];const[Y,F]=p;if(g===v.SHAPE)L+=Y,C+=Y,E+=F,b+=F;else{switch(g){case v.TOP:case v.TOP_LEFT:case v.TOP_RIGHT:{E+=F;break}case v.BOTTOM:case v.BOTTOM_LEFT:case v.BOTTOM_RIGHT:{b+=F;break}}switch(g){case v.LEFT:case v.TOP_LEFT:case v.BOTTOM_LEFT:{L+=Y;break}case v.RIGHT:case v.TOP_RIGHT:case v.BOTTOM_RIGHT:{C+=Y;break}}}const X=Math.min(L,C),_=Math.min(E,b),w=Math.abs(C-L),A=Math.abs(b-E);return{...m,geometry:{x:X,y:_,w,h:A,bounds:{minX:X,minY:_,maxX:X+w,maxY:_+A}}}};function h(m){we.call(this,e,m)}function c(m){we.call(this,e,m)}function f(m){we.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,s=m.shape),"computedStyle"in m&&n(1,r=m.computedStyle),"transform"in m&&n(2,l=m.transform),"viewportScale"in m&&n(6,a=m.viewportScale)},e.$$.update=()=>{e.$$.dirty&1&&n(4,o=s.geometry),e.$$.dirty&64&&n(3,i=10/a)},[s,r,l,i,o,d,a,h,c,f]}class Jt extends oe{constructor(t){super(),ne(this,t,Bo,Oo,Z,{shape:0,computedStyle:1,transform:2,viewportScale:6})}}const Qt=new Map([[H.RECTANGLE,Jt],[H.POLYGON,qt]]),et=e=>Qt.get(e.type),Zt=(e,t)=>Qt.set(e,t),v=e=>`HANDLE-${e}`;v.SHAPE="SHAPE",v.TOP="TOP",v.RIGHT="RIGHT",v.BOTTOM="BOTTOM",v.LEFT="LEFT",v.TOP_LEFT="TOP_LEFT",v.TOP_RIGHT="TOP_RIGHT",v.BOTTOM_RIGHT="BOTTOM_RIGHT",v.BOTTOM_LEFT="BOTTOM_LEFT";const Io=e=>({}),Kt=e=>({grab:e[0]});function Co(e){let t,n,o,i;const s=e[7].default,r=In(s,e,e[6],Kt);return{c(){t=D("g"),r&&r.c(),u(t,"class","a9s-annotation selected")},m(l,a){B(l,t,a),r&&r.m(t,null),n=!0,o||(i=[W(t,"pointerup",e[2]),W(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&64)&&Pn(r,s,l,l[6],n?Cn(s,l[6],a,Io):kn(l[6]),Kt)},i(l){n||(U(r,l),n=!0)},o(l){N(r,l),n=!1},d(l){l&&O(t),r&&r.d(l),o=!1,re(i)}}}function Po(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=ye();let{shape:r}=t,{editor:l}=t,{transform:a}=t,d=null,h,c=null;const f=p=>y=>{d=p,h=a.elementToImage(y.offsetX,y.offsetY),c=r,y.target.setPointerCapture(y.pointerId),s("grab")},m=p=>{if(d){const[y,L]=a.elementToImage(p.offsetX,p.offsetY),E=[y-h[0],L-h[1]];n(3,r=l(c,d,E)),s("change",r)}},g=p=>{p.target.releasePointerCapture(p.pointerId),d=null,c=r,s("release")};return e.$$set=p=>{"shape"in p&&n(3,r=p.shape),"editor"in p&&n(4,l=p.editor),"transform"in p&&n(5,a=p.transform),"$$scope"in p&&n(6,i=p.$$scope)},[f,m,g,r,l,a,i,o]}class tt extends oe{constructor(t){super(),ne(this,t,Po,Co,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 s="";return o&&(s+=`fill:${o};stroke:${o};`),s+=`fill-opacity:${i||"0.25"};`,s}};function ko(e,t,n){let o;const i=ye();let{annotation:s}=t,{editor:r}=t,{style:l=void 0}=t,{target:a}=t,{transform:d}=t,{viewportScale:h}=t,c;return Be(()=>(n(6,c=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:d,viewportScale:h}})),c.$on("change",f=>{c.$$set({shape:f.detail}),i("change",f.detail)}),c.$on("grab",f=>i("grab",f.detail)),c.$on("release",f=>i("release",f.detail)),()=>{c.$destroy()})),e.$$set=f=>{"annotation"in f&&n(0,s=f.annotation),"editor"in f&&n(1,r=f.editor),"style"in f&&n(2,l=f.style),"target"in f&&n(3,a=f.target),"transform"in f&&n(4,d=f.transform),"viewportScale"in f&&n(5,h=f.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&(o=Ne(s,l)),e.$$.dirty&80&&c&&c.$set({transform:d}),e.$$.dirty&96&&c&&c.$set({viewportScale:h})},[s,r,l,a,d,h,c]}class xt extends oe{constructor(t){super(),ne(this,t,ko,null,Z,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Ro(e,t,n){const o=ye();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,d;return Be(()=>{const h=s.closest("svg"),c=[],f=(m,g,p)=>{h.addEventListener(m,g,p),c.push(()=>h.removeEventListener(m,g,p))};return n(5,d=new r({target:s,props:{addEventListener:f,drawingMode:i,transform:l,viewportScale:a}})),d.$on("create",m=>o("create",m.detail)),()=>{c.forEach(m=>m()),d.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,i=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,l=h.transform),"viewportScale"in h&&n(4,a=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&d&&d.$set({transform:l}),e.$$.dirty&48&&d&&d.$set({viewportScale:a})},[i,s,r,l,a,d]}class $t extends oe{constructor(t){super(),ne(this,t,Ro,null,Z,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function en(e){let t,n;return{c(){t=D("rect"),n=D("rect"),u(t,"class","a9s-outer"),u(t,"x",e[2]),u(t,"y",e[3]),u(t,"width",e[4]),u(t,"height",e[5]),u(n,"class","a9s-inner"),u(n,"x",e[2]),u(n,"y",e[3]),u(n,"width",e[4]),u(n,"height",e[5])},m(o,i){B(o,t,i),B(o,n,i)},p(o,i){i&4&&u(t,"x",o[2]),i&8&&u(t,"y",o[3]),i&16&&u(t,"width",o[4]),i&32&&u(t,"height",o[5]),i&4&&u(n,"x",o[2]),i&8&&u(n,"y",o[3]),i&16&&u(n,"width",o[4]),i&32&&u(n,"height",o[5])},d(o){o&&O(t),o&&O(n)}}}function Yo(e){let t,n=e[1]&&en(e);return{c(){t=D("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null),e[9](t)},p(o,[i]){o[1]?n?n.p(o,i):(n=en(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&O(t),n&&n.d(),e[9](null)}}}function Do(e,t,n){const o=ye();let{addEventListener:i}=t,{drawingMode:s}=t,{transform:r}=t,l,a,d,h,c,f,m,g;const p=b=>{a=performance.now(),s==="drag"&&(n(1,d=r.elementToImage(b.offsetX,b.offsetY)),h=d,n(2,c=d[0]),n(3,f=d[1]),n(4,m=1),n(5,g=1))},y=b=>{d&&(h=r.elementToImage(b.offsetX,b.offsetY),n(2,c=Math.min(h[0],d[0])),n(3,f=Math.min(h[1],d[1])),n(4,m=Math.abs(h[0]-d[0])),n(5,g=Math.abs(h[1]-d[1])))},L=b=>{const Y=performance.now()-a;if(s==="click"){if(Y>300)return;b.stopPropagation(),d?E():(n(1,d=r.elementToImage(b.offsetX,b.offsetY)),h=d,n(2,c=d[0]),n(3,f=d[1]),n(4,m=1),n(5,g=1))}else d&&(Y>300||m*g>100?(b.stopPropagation(),E()):(n(1,d=null),h=null))},E=()=>{if(m*g>15){const b={type:H.RECTANGLE,geometry:{bounds:{minX:c,minY:f,maxX:c+m,maxY:f+g},x:c,y:f,w:m,h:g}};o("create",b)}n(1,d=null),h=null};Be(()=>{i("pointerdown",p),i("pointermove",y),i("pointerup",L,!0)});function C(b){Ee[b?"unshift":"push"](()=>{l=b,n(0,l)})}return e.$$set=b=>{"addEventListener"in b&&n(6,i=b.addEventListener),"drawingMode"in b&&n(7,s=b.drawingMode),"transform"in b&&n(8,r=b.transform)},[l,d,c,f,m,g,i,s,r,C]}class tn extends oe{constructor(t){super(),ne(this,t,Do,Yo,Z,{addEventListener:6,drawingMode:7,transform:8})}}const nt=(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))},Xo=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${s}`),e.addEventListener("load",r=>{const l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${o}`)},nn=(e,t)=>{Xo(e,t);const{subscribe:n,set:o}=Ue(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,d=Math.max(r.width/l,r.height/a);o(d)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Uo="ontouchstart"in window||navigator.maxTouchPoints>0;function ot(e){const t=e.slice(),n=(t[3]?t[1]:[...t[1],t[2]]).map(o=>o.join(",")).join(" ");return t[17]=n,t}function on(e){let t,n,o,i,s,r=e[3]&&sn(e);return{c(){t=D("polygon"),o=D("polygon"),r&&r.c(),s=le(),u(t,"class","a9s-outer"),u(t,"points",n=e[17]),u(o,"class","a9s-inner"),u(o,"points",i=e[17])},m(l,a){B(l,t,a),B(l,o,a),r&&r.m(l,a),B(l,s,a)},p(l,a){a&14&&n!==(n=l[17])&&u(t,"points",n),a&14&&i!==(i=l[17])&&u(o,"points",i),l[3]?r?r.p(l,a):(r=sn(l),r.c(),r.m(s.parentNode,s)):r&&(r.d(1),r=null)},d(l){l&&O(t),l&&O(o),r&&r.d(l),l&&O(s)}}}function sn(e){let t,n,o;return{c(){t=D("rect"),u(t,"class","a9s-corner-handle"),u(t,"x",n=e[1][0][0]-e[4]/2),u(t,"y",o=e[1][0][1]-e[4]/2),u(t,"height",e[4]),u(t,"width",e[4])},m(i,s){B(i,t,s)},p(i,s){s&18&&n!==(n=i[1][0][0]-i[4]/2)&&u(t,"x",n),s&18&&o!==(o=i[1][0][1]-i[4]/2)&&u(t,"y",o),s&16&&u(t,"height",i[4]),s&16&&u(t,"width",i[4])},d(i){i&&O(t)}}}function No(e){let t,n=e[2]&&on(ot(e));return{c(){t=D("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(o,i){B(o,t,i),n&&n.m(t,null),e[9](t)},p(o,[i]){o[2]?n?n.p(ot(o),i):(n=on(ot(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:G,o:G,d(o){o&&O(t),n&&n.d(),e[9](null)}}}const Go=20;function Fo(e,t,n){let o;const i=ye();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,d,h,c=[],f=null,m=!1;const g=b=>{if(h=performance.now(),r==="drag"&&c.length===0){const Y=l.elementToImage(b.offsetX,b.offsetY);c.push(Y),n(2,f=Y)}},p=b=>{if(c.length>0&&(n(2,f=l.elementToImage(b.offsetX,b.offsetY)),c.length>2)){const Y=nt(f,c[0])*a;n(3,m=Y<Go)}},y=b=>{const Y=performance.now()-h;if(r==="click"){if(Y>300)return;if(b.stopPropagation(),m)E();else if(c.length===0){const F=l.elementToImage(b.offsetX,b.offsetY);c.push(F),n(2,f=F)}else c.push(f)}else{if(c.length===1&&nt(c[0],f)<=4){n(1,c=[]),n(2,f=null);return}b.stopImmediatePropagation(),m?E():c.push(f)}},L=()=>{console.log("dblclick");const b=[...c,f],Y={type:H.POLYGON,geometry:{bounds:Ie(b),points:b}};n(1,c=[]),n(2,f=null),i("create",Y)},E=()=>{const b={type:H.POLYGON,geometry:{bounds:Ie(c),points:[...c]}};n(1,c=[]),n(2,f=null),i("create",b)};Be(()=>{s("pointerdown",g,!0),s("pointermove",p),s("pointerup",y,!0),s("dblclick",L,!0)});function C(b){Ee[b?"unshift":"push"](()=>{d=b,n(0,d)})}return e.$$set=b=>{"addEventListener"in b&&n(5,s=b.addEventListener),"drawingMode"in b&&n(6,r=b.drawingMode),"transform"in b&&n(7,l=b.transform),"viewportScale"in b&&n(8,a=b.viewportScale)},e.$$.update=()=>{e.$$.dirty&256&&n(4,o=10/a)},[d,c,f,m,o,s,r,l,a,C]}class Ho extends oe{constructor(t){super(),ne(this,t,Fo,No,Z,{addEventListener:5,drawingMode:6,transform:7,viewportScale:8})}}const it=new Map([["rectangle",{tool:tn}],["polygon",{tool:Ho}]]),rn=()=>[...it.keys()],st=e=>it.get(e),ln=(e,t,n)=>it.set(e,{tool:t,opts:n});function zo(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("ellipse"),i=D("ellipse"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"cx",e[2]),u(n,"cy",e[3]),u(n,"rx",e[4]),u(n,"ry",e[5]),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"cx",e[2]),u(i,"cy",e[3]),u(i,"rx",e[4]),u(i,"ry",e[5]),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}function jo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{cx:l,cy:a,rx:d,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,i=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,l,a,d,h,s,r]}class Vo extends oe{constructor(t){super(),ne(this,t,jo,zo,Z,{annotation:0,geom:6,style:7})}}function Wo(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("polygon"),i=D("polygon"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"points",e[2].map(qo).join(" ")),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"points",e[2].map(Jo).join(" ")),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}const qo=e=>e.join(","),Jo=e=>e.join(",");function Qo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,o=Ne(i,r))},[i,o,l,s,r]}class Zo extends oe{constructor(t){super(),ne(this,t,Qo,Wo,Z,{annotation:0,geom:3,style:4})}}function Ko(e){let t,n,o,i,s;return{c(){t=D("g"),n=D("rect"),i=D("rect"),u(n,"class","a9s-outer"),u(n,"style",o=e[1]?"display:none;":void 0),u(n,"x",e[2]),u(n,"y",e[3]),u(n,"width",e[4]),u(n,"height",e[5]),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"x",e[2]),u(i,"y",e[3]),u(i,"width",e[4]),u(i,"height",e[5]),u(t,"data-id",s=e[0].id)},m(r,l){B(r,t,l),fe(t,n),fe(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&u(n,"style",o),l&2&&u(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:G,o:G,d(r){r&&O(t)}}}function xo(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r=void 0}=t;const{x:l,y:a,w:d,h}=s;return e.$$set=c=>{"annotation"in c&&n(0,i=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ne(i,r))},[i,o,l,a,d,h,s,r]}class $o extends oe{constructor(t){super(),ne(this,t,xo,Ko,Z,{annotation:0,geom:6,style:7})}}const ei={elementToImage:(e,t)=>[e,t]},an=e=>({elementToImage:(t,n)=>{const o=e.createSVGPoint();o.x=t,o.y=n;const{x:i,y:s}=o.matrixTransform(e.getCTM().inverse());return[i,s]}}),ti=250,cn=(e,t)=>{const n=ye();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<ti){const{x:a,y:d}=ni(r,e),h=t.getAt(a,d);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},ni=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function fn(e,t,n){const o=e.slice();return o[28]=t[n],o}function un(e,t,n){const o=e.slice();return o[31]=t[n],o}function rt(e){const t=e.slice(),n=t[31].target.selector;return t[34]=n,t}function dn(e){let t=e[31].id,n,o,i=hn(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4096&&Z(t,t=s[31].id)?(ae(),N(i,1,1,G),ce(),i=hn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function oi(e){let t,n;return t=new Zo({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function ii(e){let t,n;return t=new $o({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function si(e){let t,n;return t=new Vo({props:{annotation:e[31],geom:e[34].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&4096&&(s.annotation=o[31]),i[0]&4096&&(s.geom=o[34].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function hn(e){let t,n,o,i;const s=[si,ii,oi],r=[];function l(a,d){return a[34].type===H.ELLIPSE?0:a[34].type===H.RECTANGLE?1:a[34].type===H.POLYGON?2:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=le()},m(a,d){~t&&r[t].m(a,d),B(a,o,d),i=!0},p(a,d){let h=t;t=l(a),t===h?~t&&r[t].p(a,d):(n&&(ae(),N(r[h],1,1,()=>{r[h]=null}),ce()),~t?(n=r[t],n?n.p(a,d):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){N(n),i=!1},d(a){~t&&r[t].d(a),a&&O(o)}}}function mn(e){let t=!e[7](e[31]),n,o,i=t&&dn(rt(e));return{c(){i&&i.c(),n=le()},m(s,r){i&&i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4224&&(t=!s[7](s[31])),t?i?(i.p(rt(s),r),r[0]&4224&&U(i,1)):(i=dn(rt(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(ae(),N(i,1,1,()=>{i=null}),ce())},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){i&&i.d(s),s&&O(n)}}}function gn(e){let t,n,o,i;const s=[li,ri],r=[];function l(a,d){return a[6]?0:a[2]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=le()},m(a,d){~t&&r[t].m(a,d),B(a,o,d),i=!0},p(a,d){let h=t;t=l(a),t===h?~t&&r[t].p(a,d):(n&&(ae(),N(r[h],1,1,()=>{r[h]=null}),ce()),~t?(n=r[t],n?n.p(a,d):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){N(n),i=!1},d(a){~t&&r[t].d(a),a&&O(o)}}}function ri(e){let t=e[2],n,o,i=pn(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&4&&Z(t,t=s[2])?(ae(),N(i,1,1,G),ce(),i=pn(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function li(e){let t,n,o=e[6],i=[];for(let r=0;r<o.length;r+=1)i[r]=yn(fn(e,o,r));const s=r=>N(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=le()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);B(r,t,l),n=!0},p(r,l){if(l[0]&140370){o=r[6];let a;for(a=0;a<o.length;a+=1){const d=fn(r,o,a);i[a]?(i[a].p(d,l),U(i[a],1)):(i[a]=yn(d),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(ae(),a=o.length;a<i.length;a+=1)s(a);ce()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)N(i[l]);n=!1},d(r){We(i,r),r&&O(t)}}}function pn(e){let t,n;return t=new $t({props:{target:e[4],tool:e[2],drawingMode:e[11],transform:e[10],viewportScale:e[13]}}),t.$on("create",e[16]),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){const s={};i[0]&16&&(s.target=o[4]),i[0]&4&&(s.tool=o[2]),i[0]&2048&&(s.drawingMode=o[11]),i[0]&1024&&(s.transform=o[10]),i[0]&8192&&(s.viewportScale=o[13]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function _n(e){let t,n;return t=new xt({props:{target:e[4],editor:et(e[28].target.selector),annotation:e[28],style:e[1],transform:e[10],viewportScale:e[13]}}),t.$on("change",function(){V(e[17](e[28]))&&e[17](e[28]).apply(this,arguments)}),{c(){ge(t.$$.fragment)},m(o,i){ue(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&16&&(s.target=e[4]),i[0]&64&&(s.editor=et(e[28].target.selector)),i[0]&64&&(s.annotation=e[28]),i[0]&2&&(s.style=e[1]),i[0]&1024&&(s.transform=e[10]),i[0]&8192&&(s.viewportScale=e[13]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){N(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function yn(e){let t=e[28].id,n,o,i=_n(e);return{c(){i.c(),n=le()},m(s,r){i.m(s,r),B(s,n,r),o=!0},p(s,r){r[0]&64&&Z(t,t=s[28].id)?(ae(),N(i,1,1,G),ce(),i=_n(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){N(i),o=!1},d(s){s&&O(n),i.d(s)}}}function ai(e){let t,n,o,i,s,r,l=e[12],a=[];for(let c=0;c<l.length;c+=1)a[c]=mn(un(e,l,c));const d=c=>N(a[c],1,1,()=>{a[c]=null});let h=e[4]&&gn(e);return{c(){t=D("svg"),n=D("g");for(let c=0;c<a.length;c+=1)a[c].c();o=D("g"),h&&h.c(),u(o,"class","drawing"),u(t,"class","a9s-annotationlayer"),yt(t,"drawing",e[2])},m(c,f){B(c,t,f),fe(t,n);for(let m=0;m<a.length;m+=1)a[m]&&a[m].m(n,null);fe(t,o),h&&h.m(o,null),e[24](o),e[25](t),i=!0,s||(r=[W(t,"pointerup",function(){V(e[8])&&e[8].apply(this,arguments)}),W(t,"pointerdown",function(){V(e[9])&&e[9].apply(this,arguments)})],s=!0)},p(c,f){if(e=c,f[0]&4226){l=e[12];let m;for(m=0;m<l.length;m+=1){const g=un(e,l,m);a[m]?(a[m].p(g,f),U(a[m],1)):(a[m]=mn(g),a[m].c(),U(a[m],1),a[m].m(n,null))}for(ae(),m=l.length;m<a.length;m+=1)d(m);ce()}e[4]?h?(h.p(e,f),f[0]&16&&U(h,1)):(h=gn(e),h.c(),U(h,1),h.m(o,null)):h&&(ae(),N(h,1,1,()=>{h=null}),ce()),(!i||f[0]&4)&&yt(t,"drawing",e[2])},i(c){if(!i){for(let f=0;f<l.length;f+=1)U(a[f]);U(h),i=!0}},o(c){a=a.filter(Boolean);for(let f=0;f<a.length;f+=1)N(a[f]);N(h),i=!1},d(c){c&&O(t),We(a,c),h&&h.d(),e[24](null),e[25](null),s=!1,re(r)}}}function ci(e,t,n){let o,i,s,r,l,a,d,h,c=G,f=()=>(c(),c=mt(w,P=>n(13,h=P)),w);e.$$.on_destroy.push(()=>c());let{drawingEnabled:m}=t,{image:g}=t,{preferredDrawingMode:p}=t,{state:y}=t,{style:L=void 0}=t,{tool:E,opts:C}=st("rectangle"),{tool:b=E,opts:Y=C}=t,{user:F}=t,X,_,w;Be(()=>f(n(5,w=nn(g,_))));const{selection:A,store:M}=y;gt(e,A,P=>n(23,a=P)),gt(e,M,P=>n(12,d=P));let I=null,R=null;const K=P=>{M.unobserve(I);const Q=P.filter(({editable:j})=>j).map(({id:j})=>j);Q.length>0?(n(6,R=Q.map(j=>M.getAnnotation(j))),I=j=>{const{updated:J}=j.changes;n(6,R=J.map(se=>se.newValue))},M.observe(I,{annotations:Q})):n(6,R=null)},he=P=>{const Q=xe(),j={id:Q,bodies:[],target:{annotation:Q,selector:P.detail,creator:F,created:new Date}};M.addAnnotation(j),A.setSelected(j.id)},ie=P=>Q=>{var _e;const{target:j}=P,J=10*60*1e3,se=((_e=j.creator)==null?void 0:_e.id)!==F.id||!j.created||new Date().getTime()-j.created.getTime()>J;M.updateTarget({...j,selector:Q.detail,created:se?j.created:new Date,updated:se?new Date:null,updatedBy:se?F:null})};function Re(P){Ee[P?"unshift":"push"](()=>{X=P,n(4,X)})}function x(P){Ee[P?"unshift":"push"](()=>{_=P,n(3,_)})}return e.$$set=P=>{"drawingEnabled"in P&&n(0,m=P.drawingEnabled),"image"in P&&n(18,g=P.image),"preferredDrawingMode"in P&&n(19,p=P.preferredDrawingMode),"state"in P&&n(20,y=P.state),"style"in P&&n(1,L=P.style),"tool"in P&&n(2,b=P.tool),"opts"in P&&n(21,Y=P.opts),"user"in P&&n(22,F=P.user)},e.$$.update=()=>{e.$$.dirty[0]&2621440&&n(11,o=(Y==null?void 0:Y.drawingMode)||p),e.$$.dirty[0]&8&&n(10,i=an(_)),e.$$.dirty[0]&8&&n(9,{onPointerDown:s,onPointerUp:r}=cn(_,M),s,(n(8,r),n(3,_))),e.$$.dirty[0]&8388608&&n(7,l=P=>a.selected.find(Q=>Q.id===P.id&&Q.editable)),e.$$.dirty[0]&8388608&&K(a.selected)},[m,L,b,_,X,w,R,l,r,s,i,o,d,h,A,M,he,ie,g,p,y,Y,F,a,Re,x]}class wn extends oe{constructor(t){super(),ne(this,t,ci,ai,Z,{drawingEnabled:0,image:18,preferredDrawingMode:19,state:20,style:1,tool:2,opts:21,user:22},null,[-1,-1])}}function fi(e,t,n,o,i){bn(e,t,n||0,o||e.length-1,i||ui)}function bn(e,t,n,o,i){for(;o>n;){if(o-n>600){var s=o-n+1,r=t-n+1,l=Math.log(s),a=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*a*(s-a)/s)*(r-s/2<0?-1:1),h=Math.max(n,Math.floor(t-r*a/s+d)),c=Math.min(o,Math.floor(t+(s-r)*a/s+d));bn(e,t,h,c,i)}var f=e[t],m=n,g=o;for(Ce(e,n,t),i(e[o],f)>0&&Ce(e,n,o);m<g;){for(Ce(e,m,g),m++,g--;i(e[m],f)<0;)m++;for(;i(e[g],f)>0;)g--}i(e[n],f)===0?Ce(e,n,g):(g++,Ce(e,g,o)),g<=t&&(n=g+1),t<=g&&(o=g-1)}}function Ce(e,t,n){var o=e[t];e[t]=e[n],e[n]=o}function ui(e,t){return e<t?-1:e>t?1:0}class di{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(!Fe(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;Fe(t,a)&&(n.leaf?o.push(l):at(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!Fe(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(Fe(t,r)){if(n.leaf||at(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const o=this.data;this.data=n,n=o}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=ve([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,d;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),d=!0),o.leaf){const h=hi(t,o.children,n);if(h!==-1)return o.children.splice(h,1),s.push(o),this._condense(s),this}!d&&!o.leaf&&at(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],d=!1):o=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=ve(t.slice(n,o+1)),Me(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=ve([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),d=a*Math.ceil(Math.sqrt(r));En(t,n,o,d,this.compareMinX);for(let h=n;h<=o;h+=d){const c=Math.min(h+d-1,o);En(t,h,c,a,this.compareMinY);for(let f=h;f<=c;f+=a){const m=Math.min(f+a-1,c);l.children.push(this._build(t,f,m,i-1))}}return Me(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const d=n.children[a],h=lt(d),c=pi(t,d)-h;c<r?(r=c,s=h<s?h:s,l=d):c===r&&h<s&&(s=h,l=d)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),ke(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=ve(o.children.splice(r,o.children.length-r));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,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=Pe(t,0,l,this.toBBox),d=Pe(t,l,o,this.toBBox),h=_i(a,d),c=lt(a)+lt(d);h<s?(s=h,i=l,r=c<r?c:r):h===s&&c<r&&(r=c,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:mi,s=t.leaf?this.compareMinY:gi,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=Pe(t,0,n,s),l=Pe(t,o-n,o,s);let a=Ge(r)+Ge(l);for(let d=n;d<o-n;d++){const h=t.children[d];ke(r,t.leaf?s(h):h),a+=Ge(r)}for(let d=o-n-1;d>=n;d--){const h=t.children[d];ke(l,t.leaf?s(h):h),a+=Ge(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)ke(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 hi(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){Pe(e,0,e.children.length,t,e)}function Pe(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 s=t;s<n;s++){const r=e.children[s];ke(i,e.leaf?o(r):r)}return i}function ke(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 mi(e,t){return e.minX-t.minX}function gi(e,t){return e.minY-t.minY}function lt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ge(e){return e.maxX-e.minX+(e.maxY-e.minY)}function pi(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 _i(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function at(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Fe(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 En(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;fi(e,r,t,n,i),s.push(t,r,r,n)}}const yi=()=>{const e=new di,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=c=>{const{minX:f,minY:m,maxX:g,maxY:p}=c.selector.geometry.bounds,y={minX:f,minY:m,maxX:g,maxY:p,target:c};e.insert(y),t.set(c.annotation,y)},s=c=>{const f=t.get(c.annotation);e.remove(f),t.delete(c.annotation)};return{all:n,clear:o,getAt:(c,f)=>{const g=e.search({minX:c,minY:f,maxX:c,maxY:f}).map(p=>p.target).filter(p=>p.selector.type===H.RECTANGLE||At(p.selector,c,f));if(g.length>0)return g.sort((p,y)=>Ke(p.selector)-Ke(y.selector)),g[0]},getIntersecting:(c,f,m,g)=>e.search({minX:c,minY:f,maxX:c+m,maxY:f+g}).map(p=>p.target),insert:i,remove:s,set:(c,f=!0)=>{f&&o();const m=c.map(g=>{const{minX:p,minY:y,maxX:L,maxY:E}=g.selector.geometry.bounds;return{minX:p,minY:y,maxX:L,maxY:E,target:g}});m.forEach(g=>t.set(g.target.annotation,g)),e.load(m)},size:()=>e.all().length,update:(c,f)=>{s(c),i(f)}}},An=e=>{const t=lo(),n=yi(),o=Kn(t,e.pointerSelectAction),i=Zn(t),s=co();return t.observe(({changes:a})=>{n.set(a.created.map(d=>d.target),!1),a.deleted.forEach(d=>n.remove(d.target)),a.updated.forEach(({oldValue:d,newValue:h})=>n.update(d.target,h.target))}),{store:{...t,getAt:(a,d)=>{const h=n.getAt(a,d);return h?t.getAnnotation(h.annotation):void 0},getIntersecting:(a,d,h,c)=>n.getIntersecting(a,d,h,c).map(f=>t.getAnnotation(f.annotation))},selection:o,hover:i,viewport:s}},Tn=e=>{const t=An(e);return{...t,store:ao(t.store)}},Sn=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,d=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=d}return o/81},Mn=(e,t)=>{const n=Sn(e),o=n>.6?"dark":"light";console.log(`[Annotorious] Image brightness: ${n.toFixed(1)}. Setting ${o} theme.`),t.setAttribute("data-theme",o)},vn=e=>({...e,drawingEnabled:e.drawingEnabled===void 0?!0:e.drawingEnabled,drawingMode:e.drawingMode||"drag",pointerSelectAction:e.pointerSelectAction||Pt.EDIT}),Ei="",Ai="",Ti="",wi=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=vn(t),i=Tn(o),{hover:s,selection:r,store:l}=i,a=fo(l,r,s,void 0,o.adapter,o.autoSave);let d=Dt(),h=o.style;const 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),Mn(n,c);const f=new wn({target:c,props:{drawingEnabled:o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:h,user:d}});f.$on("click",X=>{const{originalEvent:_,annotation:w}=X.detail;w?r.clickSelect(w.id,_):r.isEmpty()||r.clear()});const m=Yt(l,o.adapter),g=X=>{h=X,f.$set({style:h})},p=()=>{f.$destroy(),c.parentNode.insertBefore(n,c),c.parentNode.removeChild(c)},y=()=>d,L=(X,_,w)=>ln(X,_,w),E=(X,_)=>Zt(X,_),C=X=>{const{tool:_,opts:w}=st(X);f.$set({tool:_,opts:w})},b=X=>f.$set({drawingEnabled:X}),Y=X=>{X?r.setSelected(X):r.clear()},F=X=>{d=X,f.$set({user:X})};return{...m,get style(){return h},set style(X){g(X)},destroy:p,getUser:y,listDrawingTools:rn,on:a.on,off:a.off,registerDrawingTool:L,registerShapeEditor:E,setDrawingEnabled:b,setDrawingTool:C,setSelected:Y,setUser:F,state:i}};S.Editor=tt,S.EditorMount=xt,S.Handle=v,S.IdentityTransform=ei,S.PRESENCE_KEY=Eo,S.PolygonEditor=qt,S.RectangleEditor=Jt,S.RectangleUtil=Tt,S.RubberbandRectangle=tn,S.SVGAnnotationLayer=wn,S.ShapeType=H,S.ToolMount=$t,S.W3CImageFormat=To,S.addEventListeners=cn,S.boundsFromPoints=Ie,S.computeArea=Ke,S.createAnonymousGuest=Dt,S.createBaseAnnotator=Yt,S.createBody=eo,S.createDefaultAppearenceProvider=Gt,S.createImageAnnotator=wi,S.createImageAnnotatorState=An,S.createPresenceState=Ao,S.createSVGTransform=an,S.createSvelteImageAnnotatorState=Tn,S.defaultColorProvider=Nt,S.diffAnnotations=kt,S.distance=nt,S.enableResponsive=nn,S.fillDefaults=vn,S.getContributors=$n,S.getEditor=et,S.getTool=st,S.intersects=At,S.isTouch=Uo,S.listDrawingTools=rn,S.parseAll=Rt,S.parseFragmentSelector=St,S.parseSVGSelector=Ot,S.parseW3CBodies=Xt,S.parseW3CImageAnnotation=Ft,S.registerEditor=Zt,S.registerShapeUtil=De,S.registerTool=ln,S.sampleBrightness=Sn,S.serializeAll=uo,S.serializeFragmentSelector=Mt,S.serializeSVGSelector=Bt,S.serializeW3CBodies=Ut,S.serializeW3CImageAnnotation=Ht,S.setTheme=Mn,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
2
+ //# sourceMappingURL=annotorious.js.map