@linkurious/ogma-annotations 2.1.0 β†’ 2.1.2

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/index.js CHANGED
@@ -1,14 +1,9 @@
1
- (function(S,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("@linkurious/ogma")):typeof define=="function"&&define.amd?define(["exports","@linkurious/ogma"],U):(S=typeof globalThis<"u"?globalThis:S||self,U(S["@linkurious/ogma-annotations"]={},S.Ogma))})(this,(function(S,U){"use strict";var Zo=Object.defineProperty;var Jo=(S,U,St)=>U in S?Zo(S,U,{enumerable:!0,configurable:!0,writable:!0,value:St}):S[U]=St;var m=(S,U,St)=>Jo(S,typeof U!="symbol"?U+"":U,St);function St(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var re={exports:{}},Ve;function as(){return Ve||(Ve=1,(function(s){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function i(d,c,l){this.fn=d,this.context=c,this.once=l||!1}function r(d,c,l,u,h){if(typeof l!="function")throw new TypeError("The listener must be a function");var x=new i(l,u||d,h),g=t?t+c:c;return d._events[g]?d._events[g].fn?d._events[g]=[d._events[g],x]:d._events[g].push(x):(d._events[g]=x,d._eventsCount++),d}function o(d,c){--d._eventsCount===0?d._events=new n:delete d._events[c]}function a(){this._events=new n,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],l,u;if(this._eventsCount===0)return c;for(u in l=this._events)e.call(l,u)&&c.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(l)):c},a.prototype.listeners=function(c){var l=t?t+c:c,u=this._events[l];if(!u)return[];if(u.fn)return[u.fn];for(var h=0,x=u.length,g=new Array(x);h<x;h++)g[h]=u[h].fn;return g},a.prototype.listenerCount=function(c){var l=t?t+c:c,u=this._events[l];return u?u.fn?1:u.length:0},a.prototype.emit=function(c,l,u,h,x,g){var f=t?t+c:c;if(!this._events[f])return!1;var p=this._events[f],y=arguments.length,A,E;if(p.fn){switch(p.once&&this.removeListener(c,p.fn,void 0,!0),y){case 1:return p.fn.call(p.context),!0;case 2:return p.fn.call(p.context,l),!0;case 3:return p.fn.call(p.context,l,u),!0;case 4:return p.fn.call(p.context,l,u,h),!0;case 5:return p.fn.call(p.context,l,u,h,x),!0;case 6:return p.fn.call(p.context,l,u,h,x,g),!0}for(E=1,A=new Array(y-1);E<y;E++)A[E-1]=arguments[E];p.fn.apply(p.context,A)}else{var w=p.length,N;for(E=0;E<w;E++)switch(p[E].once&&this.removeListener(c,p[E].fn,void 0,!0),y){case 1:p[E].fn.call(p[E].context);break;case 2:p[E].fn.call(p[E].context,l);break;case 3:p[E].fn.call(p[E].context,l,u);break;case 4:p[E].fn.call(p[E].context,l,u,h);break;default:if(!A)for(N=1,A=new Array(y-1);N<y;N++)A[N-1]=arguments[N];p[E].fn.apply(p[E].context,A)}}return!0},a.prototype.on=function(c,l,u){return r(this,c,l,u,!1)},a.prototype.once=function(c,l,u){return r(this,c,l,u,!0)},a.prototype.removeListener=function(c,l,u,h){var x=t?t+c:c;if(!this._events[x])return this;if(!l)return o(this,x),this;var g=this._events[x];if(g.fn)g.fn===l&&(!h||g.once)&&(!u||g.context===u)&&o(this,x);else{for(var f=0,p=[],y=g.length;f<y;f++)(g[f].fn!==l||h&&!g[f].once||u&&g[f].context!==u)&&p.push(g[f]);p.length?this._events[x]=p.length===1?p[0]:p:o(this,x)}return this},a.prototype.removeAllListeners=function(c){var l;return c?(l=t?t+c:c,this._events[l]&&o(this,l)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,s.exports=a})(re)),re.exports}var cs=as();const ls=St(cs),ds=-1,Dt="dragging",Ft="dragstart",vt="dragend",Wt="click",Ke="select",Ze="unselect",us="hover",hs="unhover",Je="remove",$t="add",Qe="cancelDrawing",oe="completeDrawing",tn="update",en="link",nn="history",xs="data-annotation",ae=5,sn=3,Yt={SHAPES:1,EDITOR:2,HANDLES:3},$="start",it="end",z={default:"default",move:"move",pointer:"pointer",crosshair:"crosshair",grab:"grab",grabbing:"grabbing",ewResize:"ew-resize",nsResize:"ns-resize",neswResize:"nesw-resize",nwseResize:"nwse-resize",nwResize:"nw-resize",neResize:"ne-resize",swResize:"sw-resize",seResize:"se-resize",nResize:"n-resize",eResize:"e-resize",sResize:"s-resize",wResize:"w-resize"},rt="collapsed",Bt="expanded",Xt=1.2,ce=.2,P={TEXT:"text",NODE:"node",BOX:"box",COMMENT:"comment",POLYGON:"polygon",ANNOTATION:"annotation",EDGE:"edge"},le=`<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
3
- </svg>`,de=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
4
- <path d="M12 6.00015H7.33333C6.97971 6.00015 6.64057 6.14063 6.39052 6.39068C6.14048 6.64072 6 6.97986 6 7.33348V16.6668C6 17.0204 6.14048 17.3596 6.39052 17.6096C6.64057 17.8597 6.97971 18.0002 7.33333 18.0002H16.6667C17.0203 18.0002 17.3594 17.8597 17.6095 17.6096C17.8595 17.3596 18 17.0204 18 16.6668V12.0002M16.25 5.75015C16.5152 5.48493 16.8749 5.33594 17.25 5.33594C17.6251 5.33594 17.9848 5.48493 18.25 5.75015C18.5152 6.01537 18.6642 6.37508 18.6642 6.75015C18.6642 7.12522 18.5152 7.48493 18.25 7.75015L12.2413 13.7595C12.083 13.9176 11.8875 14.0334 11.6727 14.0962L9.75733 14.6562C9.69997 14.6729 9.63916 14.6739 9.58127 14.6591C9.52339 14.6442 9.47055 14.6141 9.4283 14.5719C9.38604 14.5296 9.35593 14.4768 9.3411 14.4189C9.32627 14.361 9.32727 14.3002 9.344 14.2428L9.904 12.3275C9.96702 12.1129 10.083 11.9175 10.2413 11.7595L16.25 5.75015Z" stroke="#1A70E5" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>
5
- </svg>
6
- `;let ht=(s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");function fs(s,e){const t=s[0]-e[0],n=s[1]-e[1];return t*t+n*n}function gs(s,e,t){let n=e[0],i=e[1],r=t[0]-n,o=t[1]-i;if(r!==0||o!==0){const a=((s[0]-n)*r+(s[1]-i)*o)/(r*r+o*o);a>1?(n=t[0],i=t[1]):a>0&&(n+=r*a,i+=o*a)}return r=s[0]-n,o=s[1]-i,r*r+o*o}function ps(s,e){let t=s[0];const n=[t];let i;for(let r=1,o=s.length;r<o;r++)i=s[r],fs(i,t)>e&&(n.push(i),t=i);return t!==i&&n.push(i),n}function ue(s,e,t,n,i){let r=n,o=0;for(let a=e+1;a<t;a++){const d=gs(s[a],s[e],s[t]);d>r&&(o=a,r=d)}r>n&&(o-e>1&&ue(s,e,o,n,i),i.push(s[o]),t-o>1&&ue(s,o,t,n,i))}function ms(s,e){const t=s.length-1,n=[s[0]];return ue(s,0,t,e,n),n.push(s[t]),n}function he(s,e,t){if(s.length<=2)return s;const n=e!==void 0?e*e:1;return s=t?s:ps(s,n),s=ms(s,n),s}function xe(s){if(s.geometry.bbox)return s.geometry.bbox;const e=s.geometry.coordinates[0];let t=1/0,n=1/0,i=-1/0,r=-1/0;for(const[o,a]of e)o<t&&(t=o),o>i&&(i=o),a<n&&(n=a),a>r&&(r=a);return[t,n,i,r]}function fe(s){const e=s.geometry.coordinates[0];let t=0,n=0;const i=e.length-1;for(let r=0;r<i;r++)t+=e[r][0],n+=e[r][1];return{x:t/i,y:n/i}}function ys(s,e,t){const n=s.geometry.coordinates.map(o=>o.map(([a,d])=>[a+e,d+t])),i=s.geometry.bbox,r=i?[i[0]+e,i[1]+t,i[2]+e,i[3]+t]:void 0;return{...s,geometry:{...s.geometry,coordinates:n,bbox:r}}}function ge(s){const e=s.geometry.coordinates[0];let t=1/0,n=1/0,i=-1/0,r=-1/0;for(const[o,a]of e)o<t&&(t=o),o>i&&(i=o),a<n&&(n=a),a>r&&(r=a);s.geometry.bbox=[t,n,i,r]}function Ss(s,e,t,n){const i=s.geometry.coordinates.map(o=>o.map(([a,d])=>{const c=a-t,l=d-n;return[t+c*e,n+l*e]})),r={...s,geometry:{...s.geometry,coordinates:i}};return ge(r),r}const Fs="http://www.w3.org/2000/svg";function T(s){return document.createElementNS(Fs,s)}function et(s){return s.geometry.bbox||ct(s),s.geometry.bbox}function X(s){if("width"in s.properties&&"height"in s.properties)return{width:s.properties.width,height:s.properties.height};const e=et(s);return{width:e[2]-e[0],height:e[3]-e[1]}}function xt(s,e=!1,t=1){if(s.geometry.type==="Point"&&"width"in s.properties&&"height"in s.properties){const[i,r]=s.geometry.coordinates;let o=s.properties.width,a=s.properties.height;return e&&(o/=t,a/=t),{x:i-o/2,y:r-a/2}}const n=et(s);return{x:n[0],y:n[1]}}function J(s){if(s.geometry.type==="Point")return{x:s.geometry.coordinates[0],y:s.geometry.coordinates[1]};const e=et(s);return{x:(e[0]+e[2])/2,y:(e[1]+e[3])/2}}function ct(s){if(tt(s)){const[e,t]=s.geometry.coordinates[0],[n,i]=s.geometry.coordinates[1];s.geometry.bbox=[Math.min(e,n),Math.min(t,i),Math.max(e,n),Math.max(t,i)]}else if(s.geometry.type==="Point"&&"width"in s.properties&&"height"in s.properties){const[e,t]=s.geometry.coordinates,n=s.properties.width/2,i=s.properties.height/2;s.geometry.bbox=[e-n,t-i,e+n,t+i]}else if(s.geometry.type==="Polygon"){const e=s.geometry.coordinates[0];let t=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(const o of e){const a=o[0],d=o[1];a<t&&(t=a),d<n&&(n=d),a>i&&(i=a),d>r&&(r=d)}s.geometry.bbox=[t,n,i,r]}}function rn(s,e,t,n,i){s.geometry.coordinates=[e+n/2,t+i/2],s.geometry.bbox=[e,t,e+n,t+i],s.properties.width=n,s.properties.height=i}function pe(s){const[e,t]=s.geometry.coordinates[0];return{x:e,y:t}}function kt(s,e){const[t,n]=s.geometry.coordinates[e===$?0:1];return{x:t,y:n}}function me(s){const[e,t]=s.geometry.coordinates[1];return{x:e,y:t}}function on(s,e,t){s.geometry.coordinates[0]=[e,t]}function an(s,e,t){s.geometry.coordinates[1]=[e,t]}function Ut(s){return{start:pe(s),end:me(s)}}function cn(s,e,t,n){e===$?on(s,t,n):an(s,t,n)}const As=s=>parseInt(s.getAttribute("data-handle-id")||"-1");function Es(s){return Lt(s).reduce((e,t)=>(e[0]=Math.min(t[0],e[0]),e[1]=Math.min(t[1],e[1]),e[2]=Math.max(t[0],e[2]),e[3]=Math.max(t[1],e[3]),e),[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY])}function Ns(s){return Array.isArray(s)&&s.length===2&&s.every(isFinite)}function Cs(s,e,t,n){for(let i=0;i<s.coordinates.length;i++){const r=s.coordinates[i];if(Ns(r))r[0]=t+(r[0]-t)*e,r[1]=n+(r[1]-n)*e;else for(let o=0;o<r.length;o++){const a=r[o];a[0]=t+(a[0]-t)*e,a[1]=n+(a[1]-n)*e}}return s}function Lt(s){let e=[];if(s.type=="Point")s.bbox?e=[[s.bbox[0],s.bbox[1]],[s.bbox[2],s.bbox[3]]]:e=[s.coordinates];else if(s.type=="LineString"||s.type=="MultiPoint")e=s.coordinates;else if(s.type=="Polygon"||s.type=="MultiLineString")e=s.coordinates.reduce(function(t,n){return t.concat(n)},[]);else if(s.type=="MultiPolygon")e=s.coordinates.reduce((t,n)=>t.concat(n.reduce((i,r)=>i.concat(r),[])),[]);else if(s.type=="Feature")if(_(s)||G(s)){const t=et(s);e=[[t[0],t[1]],[t[2],t[3]]]}else e=Lt(s.geometry);else s.type=="GeometryCollection"?e=s.geometries.reduce((t,n)=>t.concat(Lt(n)),[]):s.type=="FeatureCollection"&&(e=s.features.reduce((t,n)=>t.concat(Lt(n)),[]));return e}function ws(s,e,t){const n=Math.atan2(s.y-e.y,s.x-e.x);return{x:e.x+t*Math.cos(n),y:e.y+t*Math.sin(n)}}function Tt(s,e){if(!e)return{x:s.clientX,y:s.clientY};const t=e.getBoundingClientRect();return{x:s.clientX-t.left-e.clientLeft,y:s.clientY-t.top-e.clientTop}}function Ms(s,e){return s.startsWith("#")?ln(s,e):s.startsWith("rgb")?dn(s,e):s}function bs(s){if(s.startsWith("#")){const e=Gt(s),t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16);return{r:t,g:n,b:i,a:1}}else{const e=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/);if(!e)throw new Error(`Invalid RGB color: ${s}`);return{r:parseInt(e[1]),g:parseInt(e[2]),b:parseInt(e[3]),a:e[4]!==void 0?parseFloat(e[4]):1}}}function Gt(s){return s.length===4?s.split("").map(e=>e+e).join(""):s}function ln(s,e){const[t,n,i]=Gt(s).match(/\w\w/g).map(r=>parseInt(r,16));return`rgba(${t}, ${n}, ${i}, ${e})`}function dn(s,e){const[t,n,i]=s.match(/\d+/g).map(r=>parseInt(r,10));return`rgba(${t}, ${n}, ${i}, ${e})`}function ye(){return typeof window<"u"?window:void 0}const Se=(s,e=16,t=!1)=>{let n=!1,i=null;const r=Math.max(1,Math.round(e*60/1e3)),o=a=>{requestAnimationFrame(()=>{if(a>1)o(a-1);else if(n=!1,t&&i!==null){const d=i;i=null,s(...d),n=!0,o(r)}})};return(...a)=>{if(n){t&&(i=a);return}s(...a),n=!0,o(r)}},Ds=(s,e)=>{let t;return(...i)=>{clearTimeout(t),t=setTimeout(()=>s(...i),e)}};function vs(s,e){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>{s.apply(this,n)},e)}}function un(s){if((G(s)||_(s))&&s.geometry.type==="Polygon"){const e=s.geometry.coordinates[0],t=e[0][0],n=e[0][1],i=e[2][0],r=e[2][1],o=i-t,a=r-n,d=t+o/2,c=n+a/2;return{...s,geometry:{type:"Point",coordinates:[d,c],bbox:[t,n,i,r]},properties:{...s.properties,width:o,height:a}}}return s}function Fe(s,e){let t,n,i,r=1;const o=s.trim();if(o.startsWith("#")){const u=(o.length===4?Gt(o):o).match(/#?(\w{2})(\w{2})(\w{2})/);if(!u)return s;t=parseInt(u[1],16),n=parseInt(u[2],16),i=parseInt(u[3],16)}else{const l=o.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)/);if(!l)return s;t=parseInt(l[1]),n=parseInt(l[2]),i=parseInt(l[3]),r=l[4]!==void 0?parseFloat(l[4]):1}const a=e*100,c=.299*t+.587*n+.114*i>186?-a/2:a;return t=Math.max(0,Math.min(255,t+Math.round(2.55*c))),n=Math.max(0,Math.min(255,n+Math.round(2.55*c))),i=Math.max(0,Math.min(255,i+Math.round(2.55*c))),`rgba(${t},${n},${i},${r})`}const At=s=>Fe(s,ce),Bs=s=>Fe(s,-ce),Y=(s,e)=>({x:s.x-e.x,y:s.y-e.y}),Q=s=>Math.sqrt(s.x*s.x+s.y*s.y),ks=s=>({x:-s.x,y:-s.y}),jt=s=>{const e=Q(s);return e===0?{x:0,y:0}:{x:s.x/e,y:s.y/e}},ft=(s,e)=>({x:s.x+e.x,y:s.y+e.y}),ot=(s,e)=>({x:s.x*e,y:s.y*e}),hn=(s,e)=>{const t=Math.sin(e),n=Math.cos(e);return{x:s.x*n-s.y*t,y:s.x*t+s.y*n}},Et=(s,e)=>s.x*e.x+s.y*e.y,Ls=(s,e)=>s.x*e.y-s.y*e.x,tt=s=>s.properties.type==="arrow";function Ae(s,e,t){const{start:n,end:i}=Ut(s),r=Y(e,n),o=s.properties.style.strokeWidth,a=Y(i,n),d=Q(a),c=Et(r,jt(a));return c>0&&c<d&&Math.abs(Ls(r,jt(a)))<o/2+t}const gt={strokeType:"plain",strokeColor:"#202020",strokeWidth:1,head:"none",tail:"none"},Ts={id:void 0,type:"Feature",properties:{type:"arrow",style:{...gt}},geometry:{type:"LineString",coordinates:[[0,0],[100,100]]}},Ot=(s=0,e=0,t=0,n=0,i={...gt})=>({id:ht(),type:"Feature",properties:{type:"arrow",style:{...gt,...i}},geometry:{type:"LineString",coordinates:[[s,e],[t,n]]}}),G=s=>s.properties.type==="box";function xn(s,e,t=0,n=1,i=0){const r=xt(s),{width:o,height:a}=X(s),d=e.x-r.x,c=e.y-r.y,l=d*n-c*t,u=d*t+c*n;return l>-i&&l<o+i&&u>-i&&u<a+i}const Nt={background:"#f5f5f5",strokeWidth:0,borderRadius:8,boxShadow:"",padding:16,strokeType:"plain"},Os={id:void 0,type:"Feature",properties:{type:"box",width:100,height:50,style:{...Nt}},geometry:{type:"Point",coordinates:[50,25],bbox:[0,0,100,50]}},Ee=(s=0,e=0,t=100,n=50,i={...Nt})=>({id:ht(),type:"Feature",properties:{type:"box",width:t,height:n,style:{...Nt,...i}},geometry:{type:"Point",coordinates:[s+t/2,e+n/2]}}),_=s=>s.properties.type==="text",q={font:"sans-serif",fontSize:18,color:"#505050",background:"#f5f5f5",strokeWidth:0,borderRadius:8,padding:16,strokeType:"plain",fixedSize:!1},Ps={id:ht(),type:"Feature",properties:{type:"text",content:"",width:100,height:50,style:{...q}},geometry:{type:"Point",coordinates:[50,25],bbox:[0,0,100,50]}},Ne=(s=0,e=0,t=100,n=50,i="",r={...q})=>({id:ht(),type:"Feature",properties:{type:"text",content:i,width:t,height:n,style:{...q,...r}},geometry:{type:"Point",coordinates:[s+t/2,e+n/2],bbox:[s,e,s+t,e+n]}});function Ce(s,e,t=0,n=0,i=1,r=1){var p;const[o,a]=s.geometry.coordinates;let{width:d,height:c}=X(s);(p=s.properties.style)!=null&&p.fixedSize&&(d/=r,c/=r);const l=d/2,u=c/2,h=e.x-o,x=e.y-a,g=h*i-x*n,f=h*n+x*i;return g>-l-t&&g<l+t&&f>-u-t&&f<u+t}const I=s=>s.properties.type==="comment",Z={background:"#FFFACD",padding:8,borderRadius:4,strokeColor:"#DDD",strokeWidth:1,strokeType:"plain",iconColor:"#FFFACD",iconSymbol:"πŸ’¬",iconBorderColor:"#aaa",iconBorderWidth:1,minHeight:60,maxHeight:480,iconSize:32,color:"#333",font:"Arial, sans-serif",fontSize:12,showSendButton:!0,autoGrow:!0,shadow:!0,expandOnSelect:!1,fixedSize:!0},qt={mode:"expanded",width:200,height:60,style:Z};function we(s,e,t,n){const i={type:"comment",content:t,mode:(n==null?void 0:n.mode)??qt.mode,width:(n==null?void 0:n.width)??qt.width,height:(n==null?void 0:n.height)??qt.height,author:n==null?void 0:n.author,timestamp:n==null?void 0:n.timestamp,style:{...Z,...n==null?void 0:n.style}};return{id:ht(),type:"Feature",properties:i,geometry:{type:"Point",coordinates:[s,e]}}}function Rs(s){return{...s,properties:{...s.properties,mode:s.properties.mode===rt?Bt:rt}}}function fn(s,e,t=0,n,i,r=1){if(s.properties.mode!==rt)return Ce(s,e,t,n,i,r);const o=s.properties,a={...Z,...o.style};let d=a.iconSize,c=a.iconSize;a.fixedSize&&(d/=r,c/=r);const l=d/2,u=c/2,h=e.x-s.geometry.coordinates[0],x=e.y-s.geometry.coordinates[1];return h>=-l-t&&h<=l+t&&x>=-u-t&&x<=u+t}function Is(s){const[e,t]=s.geometry.coordinates;return{x:e,y:t}}function gn(s){const e=s.properties,t={...Z,...e.style};return e.mode===rt?{width:t.iconSize,height:t.iconSize}:{width:e.width,height:e.height}}function pn(s,e=80){const t=e/s.properties.width;return Math.max(.1,Math.min(1,t))}function Hs(s){const e={...Z,...s.properties.style};return e.collapseZoomThreshold!==void 0?e.collapseZoomThreshold:pn(s)}function _s(s,e,t,n,i="",r){const o=we(t,n,i,r==null?void 0:r.commentStyle),a={...gt,head:"arrow",...r==null?void 0:r.arrowStyle},d=Ot(t,n,s,e,a);return d.properties.link={[$]:{id:o.id,side:$,type:"comment",magnet:{x:0,y:0}}},{comment:o,arrow:d}}function zs(s,e,t,n,i,r,o,a,d){const c=s-o,l=e-a,u=o+c*r-l*i,h=a+c*i+l*r,x=o+(c+t)*r-l*i,g=a+(c+t)*i+l*r,f=o+(c+t)*r-(l+n)*i,p=a+(c+t)*i+(l+n)*r,y=o+c*r-(l+n)*i,A=a+c*i+(l+n)*r;return d[0]=Math.min(u,x,f,y),d[1]=Math.min(h,g,p,A),d[2]=Math.max(u,x,f,y),d[3]=Math.max(h,g,p,A),d}function Ws(s,e,t){const n=t.x-e.x,i=t.y-e.y,r=n*n+i*i;if(r===0){const u=s.x-e.x,h=s.y-e.y;return Math.sqrt(u*u+h*h)}let o=((s.x-e.x)*n+(s.y-e.y)*i)/r;o=Math.max(0,Math.min(1,o));const a=e.x+o*n,d=e.y+o*i,c=s.x-a,l=s.y-d;return Math.sqrt(c*c+l*l)}const nt=s=>s.properties.type==="polygon";function Me(s,e,t=0){const n=s.geometry.coordinates[0],i=s.geometry.bbox;if(i){const[o,a,d,c]=i;if(e.x<o-t||e.x>d+t||e.y<a-t||e.y>c+t)return!1}let r=!1;for(let o=0,a=n.length-1;o<n.length;a=o++){const d=n[o][0],c=n[o][1],l=n[a][0],u=n[a][1];c>e.y!=u>e.y&&e.x<(l-d)*(e.y-c)/(u-c)+d&&(r=!r)}if(r)return!0;if(t>0)for(let o=0;o<n.length-1;o++){const[a,d]=n[o],[c,l]=n[o+1];if(Ws(e,{x:a,y:d},{x:c,y:l})<=t)return!0}return!1}function mn(s,e){const t=s[0];t.length>0&&(t[0][0]!==t[t.length-1][0]||t[0][1]!==t[t.length-1][1])&&t.push([t[0][0],t[0][1]]);let n=1/0,i=1/0,r=-1/0,o=-1/0;for(const[u,h]of t)u<n&&(n=u),u>r&&(r=u),h<i&&(i=h),h>o&&(o=h);const a=[n,i,r,o],{id:d,style:c,...l}=e||{};return{type:"Feature",id:d||ht(),geometry:{type:"Polygon",coordinates:s,bbox:a},properties:{type:"polygon",style:{...lt,...c},...l}}}const lt={...Nt,strokeColor:"#000000",strokeWidth:2,background:"transparent"},$s={type:"polygon",style:{...lt}},be=s=>s.type==="FeatureCollection";function De(s){return/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(s.trim())}function ve(s){return/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(s.trim())}function Be(s){return/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[0-9.]+\s*\)$/.test(s.trim())}function yn(s){return De(s)||ve(s)||Be(s)}function Ys(s){if(yn(s))return s;throw new Error(`Invalid color format: ${s}`)}function Xs(s){if(De(s))return s;throw new Error(`Invalid hex color format: ${s}`)}function Us(s){if(ve(s))return s;throw new Error(`Invalid RGB color format: ${s}`)}function Gs(s){if(Be(s))return s;throw new Error(`Invalid RGBA color format: ${s}`)}class js{constructor(e){m(this,"previousZoom",-1);this.store=e}toggleComment(e){const t=this.store.getState().getFeature(e);if(!t||!I(t))return;const n=t;this.store.getState().applyLiveUpdate(e,{properties:{...n.properties,mode:n.properties.mode==="collapsed"?"expanded":"collapsed"}})}updateCommentModesForZoom(e){if(Math.abs(this.previousZoom-e)<5e-4)return;this.previousZoom=e;const t=this.store.getState(),n=t.features,i={};Object.values(n).forEach(r=>{if(I(r)){const o=r,a=this.getCommentZoomThreshold(o),d=e<a?rt:Bt;if(o.properties.mode===d)return;i[o.id]={properties:{...o.properties,mode:d}}}}),t.applyLiveUpdates(i)}getCommentZoomThreshold(e){const t={...e.properties.style};if(t.collapseZoomThreshold!==void 0)return t.collapseZoomThreshold;const i=80/e.properties.width;return Math.max(.1,Math.min(1,i))}}const ke="ogma-annotation-link";function Vt(s){let e=s;for(;e;){if(e.classList&&e.classList.contains(ke))return!0;e=e.parentElement}return!1}const qs="(https?://[^\\s<]+)";function Sn(){return new RegExp(qs,"g")}function Vs(s,e,t,n,i,r){const o=Math.min(n/2,i/2),a=Math.min(r,o);s.beginPath(),s.moveTo(e+a,t),s.lineTo(e+n-a,t),s.quadraticCurveTo(e+n,t,e+n,t+a),s.lineTo(e+n,t+i-a),s.quadraticCurveTo(e+n,t+i,e+n-a,t+i),s.lineTo(e+a,t+i),s.quadraticCurveTo(e,t+i,e,t+i-a),s.lineTo(e,t+a),s.quadraticCurveTo(e,t,e+a,t),s.closePath()}class Kt extends EventTarget{constructor(t,n){super();m(this,"annotation",null);m(this,"ogma");m(this,"dragging",!1);m(this,"dragStartPoint");m(this,"hoveredHandle");m(this,"ogmaPanningOption",!1);m(this,"store");m(this,"draggingWasEnabled",!0);m(this,"handleMouseMove",t=>{if(t.target instanceof HTMLTextAreaElement||!this.isActive())return;const n=this.store.getState();if(!this.dragging&&n.mousePressed&&n.mousePressPoint&&(this.detectHandle(t,this.ogma.view.getZoom()),this.hoveredHandle)){this.dragStartPoint=n.mousePressPoint,this.onDragStart(t),this.dispatchEvent(new CustomEvent(Ft,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})),this.disablePanning();return}this.dragging?this.dragStartPoint&&this.onDrag(t):this.detectHandle(t,this.ogma.view.getZoom())});m(this,"handleMouseDown",t=>{t.target instanceof HTMLTextAreaElement||Vt(t.target)||!this.isActive()||this.dragging||this.hoveredHandle||this.detectHandle(t,this.ogma.view.getZoom())});m(this,"disablePanning",()=>{var t,n;this.ogmaPanningOption=!!((n=(t=this.ogma.getOptions().interactions)==null?void 0:t.pan)!=null&&n.enabled),this.ogma.setOptions({interactions:{pan:{enabled:!1},drag:{enabled:!1}}})});m(this,"restorePanning",()=>{this.ogma.setOptions({interactions:{pan:{enabled:!0},drag:{enabled:!0}}})});m(this,"handleMouseUp",t=>{this.isActive()&&this.dragging&&(this.restorePanning(),this.onDragEnd(t),this.dispatchEvent(new CustomEvent(vt,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})))});m(this,"onClick",t=>{});this.store=n,this.ogma=t,this.store.subscribe(i=>i.features,i=>{this.isActive()&&!i[this.annotation]&&this.stopEditing()})}cancelEdit(){!this.isActive()||this.annotation===null||this.clearDragState()}clearDragState(){this.dragging=!1,this.dragStartPoint=void 0,this.hoveredHandle=void 0,this.restorePanning(),this.setCursor(z.default)}commitChange(){this.getAnnotation()&&this.store.getState().commitLiveUpdates()}onDrag(t){this.dispatchEvent(new Event(Dt))}onDragStart(t){return this.isActive()?(this.dragging=!0,this.dragStartPoint=this.clientToCanvas(t),this.disablePanning(),!0):!1}onDragEnd(t){return this.isActive()?(this.restorePanning(),this.dragging=!1,!0):!1}clientToCanvas(t){const n=this.ogma,i=Tt(t,n.getContainer());return n.view.screenToGraphCoordinates(i)}setAnnotation(t){if(this.annotation=t?t.id:null,this.annotation!==null){const n=this.ogma.getContainer();if(n){const i=ye()||n;i.addEventListener("mousemove",this.handleMouseMove),i.addEventListener("mouseup",this.handleMouseUp,!1),n.addEventListener("mousedown",this.handleMouseDown,!0),i.addEventListener("click",this.onClick,!0)}}else{const n=this.ogma.getContainer();if(n){const i=ye()||n;i.removeEventListener("mousemove",this.handleMouseMove),i.removeEventListener("mouseup",this.handleMouseUp),n.removeEventListener("mousedown",this.handleMouseDown),i.removeEventListener("click",this.onClick)}this.clearDragState(),this.setCursor(z.default)}}getAnnotation(t){const n=this.store.getState(),i=n.getFeature(this.annotation);if(!t)return i;const r=n.liveUpdates[this.annotation];return i&&r?{...i,...r}:i}setCursor(t){var i;const n=(i=this.ogma.getContainer())==null?void 0:i.firstChild;n&&(n.style.cursor=t)}stopEditing(){this.isActive()&&this.setAnnotation(null)}cancelDrawing(){if(!this.isActive())return;const t=this.store.getState();t.drawingFeature===this.annotation&&t.removeFeature(this.annotation),this.stopEditing()}isActive(){return this.annotation!==null}}class Ks extends Kt{constructor(t,n,i,r,o,a,d){super(t,n);m(this,"links");m(this,"snapping");m(this,"arrowHandler");m(this,"arrowStyle");m(this,"offsetX");m(this,"offsetY");m(this,"comment");m(this,"startX",0);m(this,"startY",0);m(this,"onArrowComplete",()=>{var E;this.arrowHandler.removeEventListener("dragend",this.onArrowComplete);const t=this.store.getState(),n=Array.from(t.selectedFeatures);if(n.length===0)return;const i=t.getFeature(n[0]);if(!i||!tt(i))return;const r=i.geometry.coordinates[0],o=i.geometry.coordinates[1],a=o[0]-this.startX,d=o[1]-this.startY,c=Math.sqrt(a*a+d*d);let l,u;c<5?(l=this.startX+this.offsetX,u=this.startY+this.offsetY):(l=o[0],u=o[1]);const h=this.comment;h.geometry.coordinates=[l,u],t.addFeature(h),this.store.setState({drawingFeature:h.id});const x=h.properties.height,g=t.zoom,f=x/g,p=l,y=u+f*.5;this.snapArrowStart(i,r[0],r[1]);const A=(E=i.properties.link)==null?void 0:E.start;t.updateFeature(i.id,{...i,geometry:{...i.geometry,coordinates:[[p,y],r]},properties:{...i.properties,link:{start:{side:$,id:h.id,type:P.COMMENT,magnet:{x:0,y:.5}},end:A?{side:it,id:A.id,type:A.type,magnet:A.magnet}:void 0}}}),this.links.add(i,$,h.id,P.COMMENT,{x:0,y:.5}),A&&A.magnet&&this.links.add(i,it,A.id,A.type,A.magnet),t.setSelectedFeatures([h.id]),this.store.setState({drawingFeature:null})});this.links=i,this.arrowHandler=o,this.snapping=r,this.offsetX=(d==null?void 0:d.offsetX)??100,this.offsetY=(d==null?void 0:d.offsetY)??-50,this.arrowStyle=d==null?void 0:d.arrowStyle,this.comment=a}detectHandle(t,n){}startDrawing(t,n,i){var o;this.startX=n,this.startY=i;const r=Ot(n,i,n,i,{...gt,head:"arrow",...(o=this.arrowStyle)==null?void 0:o.style});this.store.getState().addFeature(r),this.store.setState({drawingFeature:r.id}),this.arrowHandler.addEventListener("dragend",this.onArrowComplete),this.store.getState().setSelectedFeatures([r.id]),this.arrowHandler.startDrawing(r.id,n,i)}snapArrowStart(t,n,i){const r=this.snapping.snap({x:n,y:i});r&&(t.geometry.coordinates[0]=[r.point.x,r.point.y],t.properties.link={start:{side:$,id:r.id,type:r.type,magnet:r.magnet}},this.links.add(t,$,r.id,r.type,r.magnet))}}function Zs(s,e,t,n,i){const{width:r,height:o}=n.view.getSize(),a=8,d=16,c=a*d,l={width:150,height:50},u=l.width,h=l.height,x=Math.max(r,o),g=200,f={minX:0,minY:0,maxX:0,maxY:0},p=n.view.graphToScreenCoordinates({x:s,y:e});for(let y=0;y<c;y++){const A=y%a,E=Math.floor(y/a),w=2*Math.PI*(A/a),N=g+E/d*(x-g),F=Math.cos(w)*N,C=Math.sin(w)*N,M=p.x+F,B=p.y+C;if(f.minX=M,f.minY=B-h/2,f.maxX=M+u,f.maxY=B+h/2,F<0&&(f.minX-=u,f.maxX-=u),f.minX<0||f.maxX>r||f.minY<0||f.maxY>o)continue;const D=n.view.screenToGraphCoordinates({x:f.minX,y:f.minY}),v=n.view.screenToGraphCoordinates({x:f.maxX,y:f.maxY});if(f.minX=D.x,f.minY=D.y,f.maxX=v.x,f.maxY=v.y,!t.query(f).filter(R=>R.properties.type!=="arrow").length)return n.view.screenToGraphCoordinates({x:M,y:B})}return n.view.screenToGraphCoordinates({x:r/2,y:o/2})}class Js{constructor(e,t,n,i,r,o,a){m(this,"ogma");m(this,"store");m(this,"editor");m(this,"interactions");m(this,"links");m(this,"control");m(this,"index");m(this,"pendingDrawingListener",null);m(this,"placementCleanup",null);this.ogma=e,this.store=t,this.editor=n,this.interactions=i,this.links=r,this.control=o,this.index=a}cancelPendingDrawing(){this.pendingDrawingListener&&(this.ogma.events.off(this.pendingDrawingListener),this.pendingDrawingListener=null),this.placementCleanup&&(this.placementCleanup(),this.placementCleanup=null)}isDrawing(){return this.store.getState().drawingFeature!==null}enableDrawingMode(e){this.control.unselect().cancelDrawing();const t=n=>{this.ogma.events.off(t),this.pendingDrawingListener=null;const{x:i,y:r}=this.ogma.view.screenToGraphCoordinates(n);e(i,r)};return this.pendingDrawingListener=t,this.ogma.events.once("mousedown",t),this.control}enableArrowDrawing(e){return this.enableDrawingMode((t,n)=>{const i=Ot(t,n,t,n,e);this.startArrow(t,n,i)})}enableTextDrawing(e){return this.enableDrawingMode((t,n)=>{const i=Ne(t,n,0,0,void 0,e);this.startText(t,n,i)})}enableBoxDrawing(e){return this.enableDrawingMode((t,n)=>{const i=Ee(t,n,0,0,e);this.startBox(t,n,i)})}enablePolygonDrawing(e){return this.enableDrawingMode((t,n)=>{const i=mn([[[t,n]]],{style:e});this.startPolygon(t,n,i)})}enableCommentDrawing(e={}){return this.enableDrawingMode((t,n)=>{let i=e.offsetX,r=e.offsetY;if(i===void 0&&r===void 0){const a=Zs(t,n,this.index,this.ogma);i=a.x,r=a.y}const o=we(t,n,"",e==null?void 0:e.commentStyle);this.startComment(t,n,o,{...e,offsetX:i,offsetY:r})})}enablePlacement(e){this.control.unselect().cancelDrawing(),this.store.setState({drawingFeature:e.id}),this.control.add(e);const t=this.ogma.getContainer();if(!t)return this.control;const n=a=>{const{x:d,y:c}=this.ogma.view.screenToGraphCoordinates(a),l=e.properties.width,u=e.properties.height;this.store.getState().applyLiveUpdate(e.id,{geometry:{...e.geometry,coordinates:[d,c],bbox:[d-l/2,c-u/2,d+l/2,c+u/2]}})},i=a=>{o();const{x:d,y:c}=this.ogma.view.screenToGraphCoordinates(a),l=e.properties.width,u=e.properties.height;this.store.getState().updateFeature(e.id,{geometry:{...e.geometry,coordinates:[d,c],bbox:[d-l/2,c-u/2,d+l/2,c+u/2]}}),this.store.setState({drawingFeature:null}),this.interactions.suppressClicksTemporarily(200),this.control.select(e.id)},r=a=>{a.key==="Escape"&&(o(),this.control.remove(e),this.store.setState({drawingFeature:null}))},o=()=>{t.removeEventListener("mousemove",n),this.ogma.events.off(i),document.removeEventListener("keydown",r),this.placementCleanup=null};return t.addEventListener("mousemove",n,{passive:!0}),this.ogma.events.once("mousedown",i),document.addEventListener("keydown",r),this.placementCleanup=o,this.control}startComment(e,t,n,i){this.editor.getActiveHandler()&&this.editor.getActiveHandler().stopEditing(),this.control.cancelDrawing(),this.store.setState({drawingFeature:n.id}),this.interactions.suppressClicksTemporarily(200);const r=new Ks(this.ogma,this.store,this.links,this.editor.getSnapping(),this.editor.getArrowHandler(),n,i),o=a=>{var d;a.id===n.id&&(this.control.select(a.id),this.control.off($t,o),(d=this.editor.getActiveHandler())==null||d.startEditingText())};return this.control.on($t,o),r.startDrawing(n.id,e,t),this.control}startBox(e,t,n){return n||(n=Ee(e,t)),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startArrow(e,t,n){return n||(n=Ot(e,t)),this.editor.getActiveHandler()&&this.editor.getActiveHandler().stopEditing(),this.control.cancelDrawing(),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startText(e,t,n){return n||(n=Ne(e,t)),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startPolygon(e,t,n){return this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}}class Qs{constructor(e,t){this.store=e,this.links=t}undo(){return this.canUndo()?(this.store.temporal.getState().undo(),this.links.refresh(),!0):!1}redo(){return this.canRedo()?(this.store.temporal.getState().redo(),this.links.refresh(),!0):!1}canUndo(){return this.store.temporal.getState().pastStates.length>0}canRedo(){return this.store.temporal.getState().futureStates.length>0}clearHistory(){this.store.temporal.getState().clear()}}class ti{constructor(e){this.store=e}select(e){const t=Array.isArray(e)?e:[e];this.store.getState().setSelectedFeatures(t)}unselect(e){const t=Array.isArray(e)?e:[e];if(e===void 0)this.store.getState().setSelectedFeatures([]);else{const n=new Set(t),i=Array.from(this.store.getState().selectedFeatures).filter(r=>!n.has(r));this.store.getState().setSelectedFeatures(i)}}getSelectedAnnotations(){const e=this.store.getState();return{type:"FeatureCollection",features:Array.from(e.selectedFeatures).map(t=>e.features[t])}}getSelected(){const e=this.store.getState(),t=Array.from(e.selectedFeatures)[0];return t?e.features[t]:null}}class ei{constructor(e){this.store=e}add(e){if(be(e))for(const t of e.features)this.add(t);else{const t=un(e);this.store.getState().addFeature(t)}}remove(e){if(be(e))for(const t of e.features)this.remove(t);else this.store.getState().removeFeature(e.id)}getAnnotations(){const e=this.store.getState().features;return{type:"FeatureCollection",features:Object.values(e)}}getAnnotation(e){return this.store.getState().getFeature(e)}updateStyle(e,t){const n=this.store.getState().getFeature(e);n&&this.store.getState().updateFeature(e,{id:e,properties:{...n.properties,style:{...n.properties.style,...t}}})}update(e){var i;const t=this.store.getState(),n=t.getFeature(e.id);n&&t.updateFeature(e.id,{...n,...e,properties:{...n.properties,...e.properties,style:{...n.properties.style,...(i=e.properties)==null?void 0:i.style}},geometry:{...n.geometry,...e.geometry}})}setScale(e,t,n,i){const r=this.store.getState().getFeature(e);if(!r)return;const o=this.store.getState();if(tt(r)){const a=r.geometry.coordinates.map(([d,c])=>{const l=d-n,u=c-i;return[n+l*t,i+u*t]});o.updateFeature(e,{geometry:{...r.geometry,coordinates:a}})}else if(_(r)||G(r)){const[a,d]=r.geometry.coordinates,c=a-n,l=d-i,u=n+c*t,h=i+l*t,x=r.properties.width*t,g=r.properties.height*t;o.updateFeature(e,{properties:{...r.properties,width:x,height:g},geometry:{...r.geometry,coordinates:[u,h]}})}}}function Fn(s){var t,n;const e=s.properties.link;return e?((t=e.start)==null?void 0:t.type)===P.COMMENT||((n=e.end)==null?void 0:n.type)===P.COMMENT:!1}function An(s){var e,t;return((t=(e=s.properties.link)==null?void 0:e.start)==null?void 0:t.type)!==P.COMMENT}function ni(s){return!0}function Le(s,e,t,n,i=!1){const r=s.getState(),o=r.getFeature(t);if(!o)return;const a=new Set,d=new Set;let c="";if(tt(o)){const u=o;if(i){const h=u.properties.link||{};h.start&&Zt(h.start.type)&&a.add(h.start.id),h.end&&Zt(h.end.type)&&a.add(h.end.id)}c=u.id,d.add(u.id)}else a.add(o.id);const l={};for(const u of a){const h=r.getFeature(u);if(!h)continue;const x=si(h,n);x&&(l[u]=x,e.updateLinkedArrowsDuringDrag(u,n,l))}for(const u of d){const h=r.getFeature(u);if(!h)continue;const x=h.properties.link||{},g=h.geometry.coordinates,f=[...g];(x.start&&Zt(x.start.type)||c===u)&&(f[0]=[g[0][0]+n.x,g[0][1]+n.y]),(x.end&&Zt(x.end.type)||c===u)&&(f[1]=[g[1][0]+n.x,g[1][1]+n.y]),l[u]={geometry:{...h.geometry,coordinates:f}}}r.applyLiveUpdates(l)}function Zt(s){return s!==P.NODE&&s!==P.EDGE}function si(s,e){if(_(s)||G(s)||I(s)){const t=J(s);return{geometry:{type:s.geometry.type,coordinates:[t.x+e.x,t.y+e.y]}}}if(nt(s)){const t=s,n=t.geometry.coordinates.map(i=>i.map(r=>[r[0]+e.x,r[1]+e.y]));return{geometry:{type:t.geometry.type,coordinates:n}}}return null}class ii extends Kt{constructor(t,n,i,r){super(t,n);m(this,"snapping");m(this,"links");m(this,"snap",null);this.snapping=i,this.links=r}detectHandle(t){const n=this.getAnnotation(),i=this.clientToCanvas(t),r=ae,o=n.geometry.coordinates[0],a=n.geometry.coordinates[1],d=Math.sqrt(Math.pow(i.x-o[0],2)+Math.pow(i.y-o[1],2)),c=Math.sqrt(Math.pow(i.x-a[0],2)+Math.pow(i.y-a[1],2));d<r?this.grabHandle("start",o[0],o[1]):c<r?this.grabHandle("end",a[0],a[1]):Ae(n,i,r)?(this.setCursor(z.grab),this.hoveredHandle={type:"body",point:i},this.store.setState({hoveredHandle:2,hoveredFeature:this.annotation})):(this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.hoveredHandle=void 0)}grabHandle(t,n,i){this.hoveredHandle={type:t,point:{x:n,y:i}},this.store.setState({hoveredHandle:t==="start"?0:1,hoveredFeature:this.annotation}),this.setCursor(z.move)}onDrag(t){var l;if(!(this.dragStartPoint||!this.hoveredHandle)||!this.isActive())return;t.stopPropagation(),t.stopImmediatePropagation();const n=this.hoveredHandle,i=this.getAnnotation(),r=i.properties.link||{},o=this.clientToCanvas(t);this.snap=this.snapping.snap(o);const a=((l=this.snap)==null?void 0:l.point)||o,d=new CustomEvent(Dt,{detail:{point:a,annotation:this.annotation,handle:n}}),c=[...i.geometry.coordinates];if(n.type==="body"){const u=a.x-n.point.x,h=a.y-n.point.y;Le(this.store,this.links,i.id,{x:u,y:h},!0),this.dispatchEvent(d);return}else n.type==="start"?(c[0]=[a.x,a.y],this.snap&&(r.start={side:n.type,id:this.snap.id,type:this.snap.type,magnet:this.snap.magnet})):n.type==="end"&&(c[1]=[a.x,a.y],this.snap&&(r.end={side:n.type,id:this.snap.id,type:this.snap.type,magnet:this.snap.magnet}));this.store.getState().applyLiveUpdate(i.id,{id:i.id,properties:{...i.properties,link:r},geometry:{type:i.geometry.type,coordinates:c}}),this.dispatchEvent(d)}onDragStart(t){if(!super.onDragStart(t))return!1;const n=this.getAnnotation(),i=this.hoveredHandle;return i.type==="end"&&!1||i.type==="start"&&!An(n)?(this.clearDragState(),!1):(this.store.getState().startLiveUpdate([this.annotation]),!0)}onDragEnd(t){var r,o,a,d;if(!super.onDragEnd(t))return!1;const n=this.getAnnotation(!0);if(this.hoveredHandle){const c=n.geometry.coordinates;if(this.hoveredHandle.type==="body"){const l=this.snapping.snap({x:c[0][0],y:c[0][1]}),u=this.snapping.snap({x:c[1][0],y:c[1][1]});l?this.links.add(n,"start",l.id,l.type,l.magnet):((o=(r=n.properties.link)==null?void 0:r.start)==null?void 0:o.type)!=="comment"&&this.links.remove(n,$),u?this.links.add(n,"end",u.id,u.type,u.magnet):((d=(a=n.properties.link)==null?void 0:a.end)==null?void 0:d.type)!=="comment"&&this.links.remove(n,it)}else if(this.snap){const l=this.hoveredHandle;l.type!=="body"&&this.links.add(n,l.type,this.snap.id,this.snap.type,this.snap.magnet)}else if(this.snap===null){const l=this.hoveredHandle.type;if(n.properties.link&&n.properties.link[l]){this.links.remove(n,l);const u={...n.properties.link};delete u[l],this.store.getState().applyLiveUpdate(n.id,{properties:{...n.properties,link:u}})}}}return this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null}),this.commitChange(),this.clearDragState(),this.snap=null,!0}snapDrawingStart(t,n,i){const r=this.snapping.snap({x:n,y:i});if(r){const o={geometry:{...t.geometry,coordinates:[[r.point.x,r.point.y],t.geometry.coordinates[1]]},properties:{...t.properties,link:{start:{side:$,id:r.id,type:r.type,magnet:r.magnet}}}},a=this.store.getState();a.applyLiveUpdate(t.id,o),a.updateFeature(t.id,o),this.links.add(t,"start",r.id,r.type,r.magnet)}}startDrawing(t,n,i){this.annotation=t;const r=this.getAnnotation();this.snapDrawingStart(r,n,i),this.grabHandle("end",n,i),this.dragging=!0,this.dragStartPoint={x:n,y:i};const o=this.ogma.view.graphToScreenCoordinates({x:n,y:i});this.onDragStart({clientX:o.x,clientY:o.y})}link(t,n,i){let r=kt(t,i);const o=t.properties.link||{};let a=null;if(n instanceof U.Node)r=n.getPosition(),a=this.snapping.snapToNodes(r,n.toList());else{const d=this.store.getState().getFeature(n);if(!d)throw new Error(`Annotation with id ${n} not found`);if(_(d)||G(d))r=J(d),a=this.snapping.snapToText(r,[d]);else if(nt(d))r=fe(d),a=this.snapping.snapToPolygon(r,[d]);else throw new Error(`Cannot link arrow to annotation of type ${d.properties.type}`)}a&&(o[i]={side:i,id:a.id,type:a.type,magnet:a.magnet},this.links.add(t,i,a.id,a.type,a.magnet),cn(t,i,r.x,r.y),this.store.getState().updateFeature(t.id,{properties:{...t.properties,link:o},geometry:{type:t.geometry.type,coordinates:t.geometry.coordinates}}))}}class ri extends Kt{constructor(t,n,i){super(t,n);m(this,"links");m(this,"isDrawingMode",!1);m(this,"simplificationTolerance",5);m(this,"handleMouseDown",t=>{!this.isActive()||this.dragging||!this.hoveredHandle||(t.preventDefault(),t.stopPropagation(),this.dragStartPoint=this.clientToCanvas(t),this.onDragStart(t),this.dispatchEvent(new CustomEvent(Ft,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})),this.disablePanning())});this.links=i}startDrawing(t,n,i){this.annotation=t,this.isDrawingMode=!0;const r=this.store.getState();r.startLiveUpdate([t]),r.setDrawingPoints([]);const o=this.ogma.view.graphToScreenCoordinates({x:n,y:i});return this.dragStartPoint=o,this.disablePanning(),this.onDragStart({clientX:o.x,clientY:o.y}),this}cancelDrawing(){this.isDrawingMode&&(this.isDrawingMode=!1,this.annotation&&(this.store.getState().removeFeature(this.annotation),this.annotation=null)),this.restorePanning()}detectHandle(t,n=1){const i=this.getAnnotation();if(!i)return;const r=this.clientToCanvas(t),o=ae/n,a=i.geometry.coordinates[0];for(let d=0;d<a.length-1;d++){const[c,l]=a[d];if(Math.sqrt(Math.pow(r.x-c,2)+Math.pow(r.y-l,2))<o*2){this.grabHandle("vertex",c,l,d);return}}Me(i,r,o)?(this.setCursor(z.grab),this.hoveredHandle={type:"body",point:r},this.store.setState({hoveredHandle:-1,hoveredFeature:this.annotation})):(this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.hoveredHandle=void 0)}grabHandle(t,n,i,r){this.setCursor(t==="vertex"?z.pointer:z.grab),this.hoveredHandle={type:t,point:{x:n,y:i},vertexIndex:r},this.store.setState({hoveredHandle:r??0,hoveredFeature:this.annotation})}onDragStart(t){if(this.isDrawingMode){const n=this.clientToCanvas(t);this.dragging=!0;const i=this.getAnnotation();if(i){const r=[[n.x,n.y],[n.x,n.y]],o=this.store.getState();o.setDrawingPoints(r),o.applyLiveUpdate(i.id,{...i,geometry:{type:"Polygon",coordinates:[r],bbox:[n.x,n.y,n.x,n.y]}})}return this.dragStartPoint=n,!0}return this.hoveredHandle?(this.dragging=!0,this.setCursor(z.grabbing),this.store.getState().startLiveUpdate([this.annotation]),!0):!1}onDrag(t){if(this.isDrawingMode&&this.dragging){const a=this.clientToCanvas(t),d=this.store.getState(),c=this.getAnnotation();if(!c)return;const l=d.liveUpdates[this.annotation],u=l?{...c,...l}:c,x=d.drawingPoints.slice(0,-1),g=[...x,[a.x,a.y],x[0]];d.setDrawingPoints(g);const f=he(g,this.simplificationTolerance,!1),p=[...f,f[0]];d.applyLiveUpdate(this.annotation,{...u,geometry:{type:"Polygon",coordinates:[p]}});return}if(!this.dragging||!this.dragStartPoint||!this.hoveredHandle)return;const n=this.clientToCanvas(t),i=n.x-this.dragStartPoint.x,r=n.y-this.dragStartPoint.y,o=this.getAnnotation();if(o){if(this.hoveredHandle.type==="body")Le(this.store,this.links,o.id,{x:i,y:r});else if(this.hoveredHandle.type==="vertex"&&this.hoveredHandle.vertexIndex!==void 0){const a=o.geometry.coordinates[0].map((c,l)=>l===this.hoveredHandle.vertexIndex?[this.hoveredHandle.point.x+i,this.hoveredHandle.point.y+r]:l===o.geometry.coordinates[0].length-1&&this.hoveredHandle.vertexIndex===0?[this.hoveredHandle.point.x+i,this.hoveredHandle.point.y+r]:c),d={...o,geometry:{...o.geometry,coordinates:[a]}};ge(d),this.store.getState().applyLiveUpdate(o.id,d),this.links.snapLinkedArrowsDuringDrag(o.id)}this.dispatchEvent(new Event(Dt))}}onDragEnd(){if(this.isDrawingMode&&this.dragging){const n=this.store.getState(),i=this.getAnnotation();if(i){const r=n.drawingPoints;if(r.length<3)this.cancelDrawing();else{const o=he(r.slice(1,-1),this.simplificationTolerance,!0),a={...i,geometry:{type:"Polygon",coordinates:[o]}};ct(a),this.store.getState().applyLiveUpdate(i.id,a),this.store.setState({drawingFeature:null}),this.commitChange(),this.isDrawingMode=!1,this.dragging=!1,this.restorePanning(),this.dispatchEvent(new CustomEvent(oe,{detail:a}))}}return!0}return!this.dragging||(this.dragging=!1,this.dragStartPoint=void 0,!this.getAnnotation())?!1:(this.commitChange(),this.setCursor(z.grab),!0)}getAnnotation(){if(this.annotation)return this.store.getState().getFeature(this.annotation)}}class oi{constructor(e,t,n,i=()=>{}){m(this,"layer");m(this,"textarea");m(this,"sendButton",null);m(this,"isFocused");m(this,"unsubscribe");m(this,"fixedSize");m(this,"onFocus",()=>{this.isFocused=!0});m(this,"onBlur",()=>{this.getAnnotation()&&this.updateContent(),this.isFocused=!1});m(this,"onKeyup",e=>{e.key==="Escape"&&this.textarea.blur(),e.stopPropagation()});m(this,"onKeydown",e=>{e.stopPropagation()});m(this,"onMouseEvent",e=>{e.stopPropagation()});m(this,"onInput",()=>{this.updateContent(),this.updateStyle(),this.updatePosition(),this.layer.setSize(this.getSize()),this.updateSendButtonState()});m(this,"onSendClick",e=>{e.preventDefault(),e.stopPropagation(),!(!this.sendButton||this.sendButton.disabled)&&(this.updateContent(),this.textarea.blur(),this.onSendHandler())});m(this,"update",()=>{this.getAnnotation()&&(this.updateStyle(),this.updatePosition(),this.layer.setSize(this.getSize()))});var x,g,f,p;this.ogma=e,this.store=t,this.annotation=n,this.onSendHandler=i;const r=this.getAnnotation(),o=this.store.getState(),a=I(r)&&(((x=o.options)==null?void 0:x.showSendButton)??!0),d=((g=o.options)==null?void 0:g.sendButtonIcon)||"",c=((f=o.options)==null?void 0:f.textPlaceholder)||"Enter text",l=I(r)?Z:q;this.fixedSize=((p=r.properties.style)==null?void 0:p.fixedSize)??l.fixedSize??!1;const u=this.getPosition(),h=this.getSize();this.layer=this.ogma.layers.addOverlay({element:`<div class="ogma-annotation-text-editor">
7
- <textarea wrap="on" name="annotation-text--input" spellcheck="false" placeholder="${c}"></textarea>
1
+ "use strict";var ze=Object.defineProperty;var Ye=(i,e,t)=>e in i?ze(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var S=(i,e,t)=>Ye(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./Polygon-D4SNG2xn.cjs"),st=require("@linkurious/ogma");function We(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var pt={exports:{}},$t;function Ue(){return $t||($t=1,(function(i){var e=Object.prototype.hasOwnProperty,t="~";function n(){}Object.create&&(n.prototype=Object.create(null),new n().__proto__||(t=!1));function s(u,l,d){this.fn=u,this.context=l,this.once=d||!1}function r(u,l,d,h,x){if(typeof d!="function")throw new TypeError("The listener must be a function");var f=new s(d,h||u,x),g=t?t+l:l;return u._events[g]?u._events[g].fn?u._events[g]=[u._events[g],f]:u._events[g].push(f):(u._events[g]=f,u._eventsCount++),u}function o(u,l){--u._eventsCount===0?u._events=new n:delete u._events[l]}function a(){this._events=new n,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],d,h;if(this._eventsCount===0)return l;for(h in d=this._events)e.call(d,h)&&l.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},a.prototype.listeners=function(l){var d=t?t+l:l,h=this._events[d];if(!h)return[];if(h.fn)return[h.fn];for(var x=0,f=h.length,g=new Array(f);x<f;x++)g[x]=h[x].fn;return g},a.prototype.listenerCount=function(l){var d=t?t+l:l,h=this._events[d];return h?h.fn?1:h.length:0},a.prototype.emit=function(l,d,h,x,f,g){var p=t?t+l:l;if(!this._events[p])return!1;var m=this._events[p],F=arguments.length,y,A;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),F){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,d),!0;case 3:return m.fn.call(m.context,d,h),!0;case 4:return m.fn.call(m.context,d,h,x),!0;case 5:return m.fn.call(m.context,d,h,x,f),!0;case 6:return m.fn.call(m.context,d,h,x,f,g),!0}for(A=1,y=new Array(F-1);A<F;A++)y[A-1]=arguments[A];m.fn.apply(m.context,y)}else{var D=m.length,C;for(A=0;A<D;A++)switch(m[A].once&&this.removeListener(l,m[A].fn,void 0,!0),F){case 1:m[A].fn.call(m[A].context);break;case 2:m[A].fn.call(m[A].context,d);break;case 3:m[A].fn.call(m[A].context,d,h);break;case 4:m[A].fn.call(m[A].context,d,h,x);break;default:if(!y)for(C=1,y=new Array(F-1);C<F;C++)y[C-1]=arguments[C];m[A].fn.apply(m[A].context,y)}}return!0},a.prototype.on=function(l,d,h){return r(this,l,d,h,!1)},a.prototype.once=function(l,d,h){return r(this,l,d,h,!0)},a.prototype.removeListener=function(l,d,h,x){var f=t?t+l:l;if(!this._events[f])return this;if(!d)return o(this,f),this;var g=this._events[f];if(g.fn)g.fn===d&&(!x||g.once)&&(!h||g.context===h)&&o(this,f);else{for(var p=0,m=[],F=g.length;p<F;p++)(g[p].fn!==d||x&&!g[p].once||h&&g[p].context!==h)&&m.push(g[p]);m.length?this._events[f]=m.length===1?m[0]:m:o(this,f)}return this},a.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&o(this,d)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,i.exports=a})(pt)),pt.exports}var $e=Ue();const Xe=We($e);function Ve(i,e){const t=i[0]-e[0],n=i[1]-e[1];return t*t+n*n}function je(i,e,t){let n=e[0],s=e[1],r=t[0]-n,o=t[1]-s;if(r!==0||o!==0){const a=((i[0]-n)*r+(i[1]-s)*o)/(r*r+o*o);a>1?(n=t[0],s=t[1]):a>0&&(n+=r*a,s+=o*a)}return r=i[0]-n,o=i[1]-s,r*r+o*o}function qe(i,e){let t=i[0];const n=[t];let s;for(let r=1,o=i.length;r<o;r++)s=i[r],Ve(s,t)>e&&(n.push(s),t=s);return t!==s&&n.push(s),n}function Nt(i,e,t,n,s){let r=n,o=0;for(let a=e+1;a<t;a++){const u=je(i[a],i[e],i[t]);u>r&&(o=a,r=u)}r>n&&(o-e>1&&Nt(i,e,o,n,s),s.push(i[o]),t-o>1&&Nt(i,o,t,n,s))}function Ke(i,e){const t=i.length-1,n=[i[0]];return Nt(i,0,t,e,n),n.push(i[t]),n}function Dt(i,e,t){if(i.length<=2)return i;const n=e!==void 0?e*e:1;return i=t?i:qe(i,n),i=Ke(i,n),i}function Bt(i){if(i.geometry.bbox)return i.geometry.bbox;const e=i.geometry.coordinates[0];let t=1/0,n=1/0,s=-1/0,r=-1/0;for(const[o,a]of e)o<t&&(t=o),o>s&&(s=o),a<n&&(n=a),a>r&&(r=a);return[t,n,s,r]}function vt(i){const e=i.geometry.coordinates[0];let t=0,n=0;const s=e.length-1;for(let r=0;r<s;r++)t+=e[r][0],n+=e[r][1];return{x:t/s,y:n/s}}function Ze(i,e,t){const n=i.geometry.coordinates.map(o=>o.map(([a,u])=>[a+e,u+t])),s=i.geometry.bbox,r=s?[s[0]+e,s[1]+t,s[2]+e,s[3]+t]:void 0;return{...i,geometry:{...i.geometry,coordinates:n,bbox:r}}}function kt(i){const e=i.geometry.coordinates[0];let t=1/0,n=1/0,s=-1/0,r=-1/0;for(const[o,a]of e)o<t&&(t=o),o>s&&(s=o),a<n&&(n=a),a>r&&(r=a);i.geometry.bbox=[t,n,s,r]}function Je(i,e,t,n){const s=i.geometry.coordinates.map(o=>o.map(([a,u])=>{const l=a-t,d=u-n;return[t+l*e,n+d*e]})),r={...i,geometry:{...i.geometry,coordinates:s}};return kt(r),r}const Mt=i=>i.type==="FeatureCollection";function Lt(i){return/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(i.trim())}function Ot(i){return/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(i.trim())}function Pt(i){return/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[0-9.]+\s*\)$/.test(i.trim())}function ye(i){return Lt(i)||Ot(i)||Pt(i)}function Qe(i){if(ye(i))return i;throw new Error(`Invalid color format: ${i}`)}function tn(i){if(Lt(i))return i;throw new Error(`Invalid hex color format: ${i}`)}function en(i){if(Ot(i))return i;throw new Error(`Invalid RGB color format: ${i}`)}function nn(i){if(Pt(i))return i;throw new Error(`Invalid RGBA color format: ${i}`)}class sn{constructor(e){S(this,"previousZoom",-1);this.store=e}toggleComment(e){const t=this.store.getState().getFeature(e);if(!t||!c.isComment(t))return;const n=t;this.store.getState().applyLiveUpdate(e,{properties:{...n.properties,mode:n.properties.mode==="collapsed"?"expanded":"collapsed"}})}updateCommentModesForZoom(e){if(Math.abs(this.previousZoom-e)<5e-4)return;this.previousZoom=e;const t=this.store.getState(),n=t.features,s={};Object.values(n).forEach(r=>{if(c.isComment(r)){const o=r,a=this.getCommentZoomThreshold(o),u=e<a?c.COMMENT_MODE_COLLAPSED:c.COMMENT_MODE_EXPANDED;if(o.properties.mode===u)return;s[o.id]={properties:{...o.properties,mode:u}}}}),t.applyLiveUpdates(s)}getCommentZoomThreshold(e){const t={...e.properties.style};if(t.collapseZoomThreshold!==void 0)return t.collapseZoomThreshold;const s=80/e.properties.width;return Math.max(.1,Math.min(1,s))}}const Rt="ogma-annotation-link";function nt(i){let e=i;for(;e;){if(e.classList&&e.classList.contains(Rt))return!0;e=e.parentElement}return!1}const rn="(https?://[^\\s<]+)";function Ae(){return new RegExp(rn,"g")}function on(i,e,t,n,s,r){const o=Math.min(n/2,s/2),a=Math.min(r,o);i.beginPath(),i.moveTo(e+a,t),i.lineTo(e+n-a,t),i.quadraticCurveTo(e+n,t,e+n,t+a),i.lineTo(e+n,t+s-a),i.quadraticCurveTo(e+n,t+s,e+n-a,t+s),i.lineTo(e+a,t+s),i.quadraticCurveTo(e,t+s,e,t+s-a),i.lineTo(e,t+a),i.quadraticCurveTo(e,t,e+a,t),i.closePath()}class dt extends EventTarget{constructor(t,n){super();S(this,"annotation",null);S(this,"ogma");S(this,"dragging",!1);S(this,"dragStartPoint");S(this,"hoveredHandle");S(this,"ogmaPanningOption",!1);S(this,"store");S(this,"draggingWasEnabled",!0);S(this,"savedDetectOption");S(this,"handleMouseMove",t=>{if(t.target instanceof HTMLTextAreaElement||!this.isActive())return;const n=this.store.getState();if(!this.dragging&&n.mousePressed&&n.mousePressPoint&&(this.detectHandle(t,this.ogma.view.getZoom()),this.hoveredHandle)){this.dragStartPoint=n.mousePressPoint,this.onDragStart(t),this.dispatchEvent(new CustomEvent(c.EVT_DRAG_START,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})),this.disablePanning();return}this.dragging?this.dragStartPoint&&this.onDrag(t):this.detectHandle(t,this.ogma.view.getZoom())});S(this,"handleMouseDown",t=>{t.target instanceof HTMLTextAreaElement||nt(t.target)||!this.isActive()||this.dragging||this.hoveredHandle||this.detectHandle(t,this.ogma.view.getZoom())});S(this,"disablePanning",()=>{var t,n;this.ogmaPanningOption=!!((n=(t=this.ogma.getOptions().interactions)==null?void 0:t.pan)!=null&&n.enabled),this.savedDetectOption===void 0&&(this.savedDetectOption={...this.ogma.getOptions().detect}),this.ogma.setOptions({interactions:{pan:{enabled:!1},drag:{enabled:!1}},detect:{...this.savedDetectOption,nodes:!1,edges:!1}})});S(this,"restorePanning",()=>{this.ogma.setOptions({interactions:{pan:{enabled:!0},drag:{enabled:!0}},...this.savedDetectOption?{detect:this.savedDetectOption}:{}}),this.savedDetectOption=void 0});S(this,"handleMouseUp",t=>{this.isActive()&&this.dragging&&(this.restorePanning(),this.onDragEnd(t),this.dispatchEvent(new CustomEvent(c.EVT_DRAG_END,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})))});S(this,"onClick",t=>{});this.store=n,this.ogma=t,this.store.subscribe(s=>s.features,s=>{this.isActive()&&!s[this.annotation]&&this.stopEditing()})}cancelEdit(){!this.isActive()||this.annotation===null||this.clearDragState()}clearDragState(){this.dragging=!1,this.dragStartPoint=void 0,this.hoveredHandle=void 0,this.restorePanning(),this.setCursor(c.cursors.default)}commitChange(){this.getAnnotation()&&this.store.getState().commitLiveUpdates()}onDrag(t){this.dispatchEvent(new Event(c.EVT_DRAG))}onDragStart(t){return this.isActive()?(this.dragging=!0,this.dragStartPoint=this.clientToCanvas(t),this.disablePanning(),!0):!1}onDragEnd(t){return this.isActive()?(this.restorePanning(),this.dragging=!1,!0):!1}clientToCanvas(t){const n=this.ogma,s=c.clientToContainerPosition(t,n.getContainer());return n.view.screenToGraphCoordinates(s)}setAnnotation(t){if(this.annotation=t?t.id:null,this.annotation!==null){const n=this.ogma.getContainer();if(n){const s=c.getBrowserWindow()||n;s.addEventListener("mousemove",this.handleMouseMove),s.addEventListener("mouseup",this.handleMouseUp,!1),n.addEventListener("mousedown",this.handleMouseDown,!0),s.addEventListener("click",this.onClick,!0)}}else{const n=this.ogma.getContainer();if(n){const s=c.getBrowserWindow()||n;s.removeEventListener("mousemove",this.handleMouseMove),s.removeEventListener("mouseup",this.handleMouseUp),n.removeEventListener("mousedown",this.handleMouseDown),s.removeEventListener("click",this.onClick)}this.clearDragState(),this.setCursor(c.cursors.default)}}getAnnotation(t){const n=this.store.getState(),s=n.getFeature(this.annotation);if(!t)return s;const r=n.liveUpdates[this.annotation];return s&&r?{...s,...r}:s}setCursor(t){var s;const n=(s=this.ogma.getContainer())==null?void 0:s.firstChild;n&&(n.style.cursor=t)}stopEditing(){this.isActive()&&this.setAnnotation(null)}cancelDrawing(){if(!this.isActive())return;const t=this.store.getState();t.drawingFeature===this.annotation&&t.removeFeature(this.annotation),this.stopEditing()}isActive(){return this.annotation!==null}}const an=5;class cn extends dt{constructor(t,n,s,r,o,a,u){super(t,n);S(this,"links");S(this,"snapping");S(this,"arrowHandler");S(this,"arrowStyle");S(this,"offsetX");S(this,"offsetY");S(this,"comment");S(this,"startX",0);S(this,"startY",0);S(this,"onArrowComplete",()=>{var A;this.arrowHandler.removeEventListener("dragend",this.onArrowComplete);const t=this.store.getState(),n=Array.from(t.selectedFeatures);if(n.length===0)return;const s=t.getFeature(n[0]);if(!s||!c.isArrow(s))return;const r=s.geometry.coordinates[0],o=s.geometry.coordinates[1],a=o[0]-this.startX,u=o[1]-this.startY,l=Math.sqrt(a*a+u*u);let d,h;l<an?(d=this.startX+this.offsetX,h=this.startY+this.offsetY):(d=o[0],h=o[1]);const x=this.comment;x.geometry.coordinates=[d,h],t.addFeature(x),this.store.setState({drawingFeature:x.id});const f=x.properties.height,g=t.zoom,p=f/g,m=d,F=h+p*.5;this.snapArrowStart(s,r[0],r[1]);const y=(A=s.properties.link)==null?void 0:A.start;t.updateFeature(s.id,{...s,geometry:{...s.geometry,coordinates:[[m,F],r]},properties:{...s.properties,link:{start:{side:c.SIDE_START,id:x.id,type:c.TARGET_TYPES.COMMENT,magnet:{x:0,y:.5}},end:y?{side:c.SIDE_END,id:y.id,type:y.type,magnet:y.magnet}:void 0}}}),this.links.add(s,c.SIDE_START,x.id,c.TARGET_TYPES.COMMENT,{x:0,y:.5}),y&&y.magnet&&this.links.add(s,c.SIDE_END,y.id,y.type,y.magnet,"stored"),t.setSelectedFeatures([x.id]),this.store.setState({drawingFeature:null})});this.links=s,this.arrowHandler=o,this.snapping=r,this.offsetX=(u==null?void 0:u.offsetX)??100,this.offsetY=(u==null?void 0:u.offsetY)??-50,this.arrowStyle=u==null?void 0:u.arrowStyle,this.comment=a}detectHandle(t,n){}startDrawing(t,n,s){var o;this.startX=n,this.startY=s;const r=c.createArrow(n,s,n,s,{...c.defaultArrowStyle,head:"arrow",...(o=this.arrowStyle)==null?void 0:o.style});this.store.getState().addFeature(r),this.store.setState({drawingFeature:r.id}),this.arrowHandler.addEventListener("dragend",this.onArrowComplete),this.store.getState().setSelectedFeatures([r.id]),this.arrowHandler.startDrawing(r.id,n,s)}snapArrowStart(t,n,s){const r=this.snapping.snap({x:n,y:s});r&&(t.geometry.coordinates[0]=[r.point.x,r.point.y],t.properties.link={start:{side:c.SIDE_START,id:r.id,type:r.type,magnet:r.magnet}},this.links.add(t,c.SIDE_START,r.id,r.type,r.magnet))}}function ln(i,e,t,n,s){const{width:r,height:o}=n.view.getSize(),a=8,u=16,l=a*u,d={width:150,height:50},h=d.width,x=d.height,f=Math.max(r,o),g=200,p={minX:0,minY:0,maxX:0,maxY:0},m=n.view.graphToScreenCoordinates({x:i,y:e});for(let F=0;F<l;F++){const y=F%a,A=Math.floor(F/a),D=2*Math.PI*(y/a),C=g+A/u*(f-g),E=Math.cos(D)*C,N=Math.sin(D)*C,M=m.x+E,B=m.y+N;if(p.minX=M,p.minY=B-x/2,p.maxX=M+h,p.maxY=B+x/2,E<0&&(p.minX-=h,p.maxX-=h),p.minX<0||p.maxX>r||p.minY<0||p.maxY>o)continue;const b=n.view.screenToGraphCoordinates({x:p.minX,y:p.minY}),T=n.view.screenToGraphCoordinates({x:p.maxX,y:p.maxY});if(p.minX=b.x,p.minY=b.y,p.maxX=T.x,p.maxY=T.y,!t.query(p).filter(O=>O.properties.type!=="arrow").length)return n.view.screenToGraphCoordinates({x:M,y:B})}return n.view.screenToGraphCoordinates({x:r/2,y:o/2})}const Xt=160,dn={font:"IBM Plex Sans",fontSize:18,color:"#4A3B00",background:"#FFEB99",strokeWidth:0,strokeType:"plain",borderRadius:4,padding:16,fixedSize:!1,placeholder:"Quick note…"};class un{constructor(e,t,n,s,r,o,a){S(this,"ogma");S(this,"store");S(this,"editor");S(this,"interactions");S(this,"links");S(this,"control");S(this,"index");S(this,"pendingDrawingListener",null);S(this,"placementCleanup",null);S(this,"eraseModeActive",!1);S(this,"onEraseClick",e=>{if(e.id===void 0||e.id===null)return;const t=this.store.getState().features[e.id];t&&this.control.remove(t)});this.ogma=e,this.store=t,this.editor=n,this.interactions=s,this.links=r,this.control=o,this.index=a}cancelPendingDrawing(){this.pendingDrawingListener&&(this.ogma.events.off(this.pendingDrawingListener),this.pendingDrawingListener=null),this.placementCleanup&&(this.placementCleanup(),this.placementCleanup=null),this.disableEraseMode()}isDrawing(){return this.store.getState().drawingFeature!==null}isEraseModeActive(){return this.eraseModeActive}enableEraseMode(){return this.eraseModeActive?this.control:(this.control.unselect().cancelDrawing(),this.eraseModeActive=!0,this.control.on(c.EVT_CLICK,this.onEraseClick),this.interactions.setCursor(c.cursors.crosshair),this.control)}disableEraseMode(){return this.eraseModeActive?(this.eraseModeActive=!1,this.control.off(c.EVT_CLICK,this.onEraseClick),this.interactions.setCursor(c.cursors.default),this.control):this.control}enableDrawingMode(e){this.control.unselect().cancelDrawing();const t=n=>{this.ogma.events.off(t),this.pendingDrawingListener=null;const{x:s,y:r}=this.ogma.view.screenToGraphCoordinates(n);e(s,r)};return this.pendingDrawingListener=t,this.ogma.events.once("mousedown",t),this.control}enableArrowDrawing(e){return this.enableDrawingMode((t,n)=>{const s=c.createArrow(t,n,t,n,e);this.startArrow(t,n,s)})}enableTextDrawing(e){return this.enableDrawingMode((t,n)=>{const s=c.createText(t,n,0,0,void 0,e);this.startText(t,n,s)})}enableBoxDrawing(e){return this.enableDrawingMode((t,n)=>{const s=c.createBox(t,n,0,0,e);this.startBox(t,n,s)})}enablePolygonDrawing(e){return this.enableDrawingMode((t,n)=>{const s=c.createPolygon([[[t,n]]],{style:e});this.startPolygon(t,n,s)})}enableCommentDrawing(e={}){return this.enableDrawingMode((t,n)=>{let s=e.offsetX,r=e.offsetY;if(s===void 0&&r===void 0){const a=ln(t,n,this.index,this.ogma);s=a.x,r=a.y}const o=c.createComment(t,n,"",e==null?void 0:e.commentStyle);this.startComment(t,n,o,{...e,offsetX:s,offsetY:r})})}enableStickyNoteDrawing(e){return this.enableDrawingMode((t,n)=>{this.startStickyNote(t,n,e)})}startStickyNote(e,t,n){this.editor.getActiveHandler()&&this.editor.getActiveHandler().stopEditing(),this.control.cancelDrawing();const s=c.createText(e,t,0,0,"",{...dn,...n});return this.store.setState({drawingFeature:s.id}),this.control.add(s),this.interactions.suppressClicksTemporarily(200),this.control.select(s.id),this.editor.getActiveHandler().startDrawing(s.id,e,t,{defaultSize:{width:Xt,height:Xt},autoEditAfterDrag:!0}),this.control}enablePlacement(e){this.control.unselect().cancelDrawing(),this.store.setState({drawingFeature:e.id}),this.control.add(e);const t=this.ogma.getContainer();if(!t)return this.control;const n=a=>{const{x:u,y:l}=this.ogma.view.screenToGraphCoordinates(a),d=e.properties.width,h=e.properties.height;this.store.getState().applyLiveUpdate(e.id,{geometry:{...e.geometry,coordinates:[u,l],bbox:[u-d/2,l-h/2,u+d/2,l+h/2]}})},s=a=>{o();const{x:u,y:l}=this.ogma.view.screenToGraphCoordinates(a),d=e.properties.width,h=e.properties.height;this.store.getState().updateFeature(e.id,{geometry:{...e.geometry,coordinates:[u,l],bbox:[u-d/2,l-h/2,u+d/2,l+h/2]}}),this.store.setState({drawingFeature:null}),this.interactions.suppressClicksTemporarily(200),this.control.select(e.id)},r=a=>{a.key==="Escape"&&(o(),this.control.remove(e),this.store.setState({drawingFeature:null}))},o=()=>{t.removeEventListener("mousemove",n),this.ogma.events.off(s),document.removeEventListener("keydown",r),this.placementCleanup=null};return t.addEventListener("mousemove",n,{passive:!0}),this.ogma.events.once("mousedown",s),document.addEventListener("keydown",r),this.placementCleanup=o,this.control}startComment(e,t,n,s){this.editor.getActiveHandler()&&this.editor.getActiveHandler().stopEditing(),this.control.cancelDrawing(),this.store.setState({drawingFeature:n.id}),this.interactions.suppressClicksTemporarily(200);const r=new cn(this.ogma,this.store,this.links,this.editor.getSnapping(),this.editor.getArrowHandler(),n,s),o=a=>{var u;a.id===n.id&&(this.control.select(a.id),this.control.off(c.EVT_ADD,o),(u=this.editor.getActiveHandler())==null||u.startEditingText())};return this.control.on(c.EVT_ADD,o),r.startDrawing(n.id,e,t),this.control}startBox(e,t,n){return n||(n=c.createBox(e,t)),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startArrow(e,t,n){return n||(n=c.createArrow(e,t)),this.editor.getActiveHandler()&&this.editor.getActiveHandler().stopEditing(),this.control.cancelDrawing(),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startText(e,t,n){return n||(n=c.createText(e,t)),this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startPolygon(e,t,n){return this.store.setState({drawingFeature:n.id}),this.control.add(n),this.interactions.suppressClicksTemporarily(200),this.control.select(n.id),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}}class hn{constructor(e,t){this.store=e,this.links=t}undo(){return this.canUndo()?(this.store.temporal.getState().undo(),this.links.refresh(),!0):!1}redo(){return this.canRedo()?(this.store.temporal.getState().redo(),this.links.refresh(),!0):!1}canUndo(){return this.store.temporal.getState().pastStates.length>0}canRedo(){return this.store.temporal.getState().futureStates.length>0}clearHistory(){this.store.temporal.getState().clear()}}class xn{constructor(e){this.store=e}select(e){const t=Array.isArray(e)?e:[e];this.store.getState().setSelectedFeatures(t)}unselect(e){const t=Array.isArray(e)?e:[e];if(e===void 0)this.store.getState().setSelectedFeatures([]);else{const n=new Set(t),s=Array.from(this.store.getState().selectedFeatures).filter(r=>!n.has(r));this.store.getState().setSelectedFeatures(s)}}getSelectedAnnotations(){const e=this.store.getState();return{type:"FeatureCollection",features:Array.from(e.selectedFeatures).map(t=>e.features[t])}}getSelected(){const e=this.store.getState(),t=Array.from(e.selectedFeatures)[0];return t?e.features[t]:null}}class fn{constructor(e){this.store=e}add(e){if(Mt(e))for(const t of e.features)this.add(t);else{const t=c.migrateBoxOrTextIfNeeded(e);this.store.getState().addFeature(t)}}remove(e){if(Mt(e))for(const t of e.features)this.remove(t);else this.store.getState().removeFeature(e.id)}getAnnotations(){const e=this.store.getState().features;return{type:"FeatureCollection",features:Object.values(e)}}getAnnotation(e){return this.store.getState().getFeature(e)}updateStyle(e,t){const n=this.store.getState().getFeature(e);n&&this.store.getState().updateFeature(e,{id:e,properties:{...n.properties,style:{...n.properties.style,...t}}})}update(e){var s;const t=this.store.getState(),n=t.getFeature(e.id);n&&t.updateFeature(e.id,{...n,...e,properties:{...n.properties,...e.properties,style:{...n.properties.style,...(s=e.properties)==null?void 0:s.style}},geometry:{...n.geometry,...e.geometry}})}setScale(e,t,n,s){const r=this.store.getState().getFeature(e);if(!r)return;const o=this.store.getState();if(c.isArrow(r)){const a=r.geometry.coordinates.map(([u,l])=>{const d=u-n,h=l-s;return[n+d*t,s+h*t]});o.updateFeature(e,{geometry:{...r.geometry,coordinates:a}})}else if(c.isText(r)||c.isBox(r)){const[a,u]=r.geometry.coordinates,l=a-n,d=u-s,h=n+l*t,x=s+d*t,f=r.properties.width*t,g=r.properties.height*t;o.updateFeature(e,{properties:{...r.properties,width:f,height:g},geometry:{...r.geometry,coordinates:[h,x]}})}}}function Ce(i){var t,n;const e=i.properties.link;return e?((t=e.start)==null?void 0:t.type)===c.TARGET_TYPES.COMMENT||((n=e.end)==null?void 0:n.type)===c.TARGET_TYPES.COMMENT:!1}function Ne(i){var t,n;const e=i.properties.link;if(e){if(((t=e.start)==null?void 0:t.type)===c.TARGET_TYPES.COMMENT)return e.start.id;if(((n=e.end)==null?void 0:n.type)===c.TARGET_TYPES.COMMENT)return e.end.id}}function De(i){var e,t;return((t=(e=i.properties.link)==null?void 0:e.start)==null?void 0:t.type)!==c.TARGET_TYPES.COMMENT}function gn(i){return!0}function Me(i,e){const t=new Set([e]),n=i[e];return n&&(c.isComment(n)||c.isText(n))&&Object.values(i).forEach(s=>{var r,o,a,u;c.isArrow(s)&&(((o=(r=s.properties.link)==null?void 0:r.end)==null?void 0:o.id)===e||((u=(a=s.properties.link)==null?void 0:a.start)==null?void 0:u.id)===e)&&t.add(s.id)}),t}function we(i,e){var r,o,a,u;const t=i[e];if(!t||!c.isArrow(t))return null;const n=((o=(r=t.properties.link)==null?void 0:r.end)==null?void 0:o.type)===c.TARGET_TYPES.COMMENT?t.properties.link.end.id:((u=(a=t.properties.link)==null?void 0:a.start)==null?void 0:u.type)===c.TARGET_TYPES.COMMENT?t.properties.link.start.id:null;return n?Object.values(i).some(l=>{var d,h,x,f;return c.isArrow(l)&&l.id!==e&&(((h=(d=l.properties.link)==null?void 0:d.end)==null?void 0:h.id)===n||((f=(x=l.properties.link)==null?void 0:x.start)==null?void 0:f.id)===n)})?null:n:null}function _t(i,e,t,n,s=!1){const r=i.getState(),o=r.getFeature(t);if(!o)return;const a=new Set,u=new Set;let l="";if(c.isArrow(o)){const h=o;if(s){const x=h.properties.link||{};x.start&&rt(x.start.type)&&a.add(x.start.id),x.end&&rt(x.end.type)&&a.add(x.end.id)}l=h.id,u.add(h.id)}else a.add(o.id);const d={};for(const h of a){const x=r.getFeature(h);if(!x)continue;const f=pn(x,n);f&&(d[h]=f,e.updateLinkedArrowsDuringDrag(h,n,d))}for(const h of u){const x=r.getFeature(h);if(!x)continue;const f=x.properties.link||{},g=x.geometry.coordinates,p=[...g];(f.start&&rt(f.start.type)||l===h)&&(p[0]=[g[0][0]+n.x,g[0][1]+n.y]),(f.end&&rt(f.end.type)||l===h)&&(p[1]=[g[1][0]+n.x,g[1][1]+n.y]),d[h]={geometry:{...x.geometry,coordinates:p}}}r.applyLiveUpdates(d)}function rt(i){return i!==c.TARGET_TYPES.NODE&&i!==c.TARGET_TYPES.EDGE}function pn(i,e){if(c.isText(i)||c.isBox(i)||c.isComment(i)){const t=c.getBoxCenter(i);return{geometry:{type:i.geometry.type,coordinates:[t.x+e.x,t.y+e.y]}}}if(c.isPolygon(i)){const t=i,n=t.geometry.coordinates.map(s=>s.map(r=>[r[0]+e.x,r[1]+e.y]));return{geometry:{type:t.geometry.type,coordinates:n}}}return null}class mn extends dt{constructor(t,n,s,r){super(t,n);S(this,"snapping");S(this,"links");S(this,"snap",null);this.snapping=s,this.links=r}detectHandle(t){const n=this.getAnnotation(),s=this.clientToCanvas(t),r=c.handleDetectionThreshold,o=n.geometry.coordinates[0],a=n.geometry.coordinates[1],u=Math.sqrt(Math.pow(s.x-o[0],2)+Math.pow(s.y-o[1],2)),l=Math.sqrt(Math.pow(s.x-a[0],2)+Math.pow(s.y-a[1],2));u<r?this.grabHandle("start",o[0],o[1]):l<r?this.grabHandle("end",a[0],a[1]):c.detectArrow(n,s,r)?(this.setCursor(c.cursors.grab),this.hoveredHandle={type:"body",point:s},this.store.setState({hoveredHandle:2,hoveredFeature:this.annotation})):(this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.hoveredHandle=void 0)}grabHandle(t,n,s){this.hoveredHandle={type:t,point:{x:n,y:s}},this.store.setState({hoveredHandle:t==="start"?0:1,hoveredFeature:this.annotation}),this.setCursor(c.cursors.move)}onDrag(t){var d;if(!(this.dragStartPoint||!this.hoveredHandle)||!this.isActive())return;t.stopPropagation(),t.stopImmediatePropagation();const n=this.hoveredHandle,s=this.getAnnotation(),r=s.properties.link||{},o=this.clientToCanvas(t);this.snap=this.snapping.snap(o);const a=((d=this.snap)==null?void 0:d.point)||o,u=new CustomEvent(c.EVT_DRAG,{detail:{point:a,annotation:this.annotation,handle:n}}),l=[...s.geometry.coordinates];if(n.type==="body"){const h=a.x-n.point.x,x=a.y-n.point.y;_t(this.store,this.links,s.id,{x:h,y:x},!0),this.dispatchEvent(u);return}else n.type==="start"?(l[0]=[a.x,a.y],this.snap&&(r.start={side:n.type,id:this.snap.id,type:this.snap.type,magnet:this.snap.magnet})):n.type==="end"&&(l[1]=[a.x,a.y],this.snap&&(r.end={side:n.type,id:this.snap.id,type:this.snap.type,magnet:this.snap.magnet}));this.store.getState().applyLiveUpdate(s.id,{id:s.id,properties:{...s.properties,link:r},geometry:{type:s.geometry.type,coordinates:l}}),this.dispatchEvent(u)}onDragStart(t){if(!super.onDragStart(t))return!1;const n=this.getAnnotation(),s=this.hoveredHandle;return s.type==="end"&&!1||s.type==="start"&&!De(n)?(this.clearDragState(),!1):(this.store.getState().startLiveUpdate([this.annotation]),!0)}onDragEnd(t){var r,o,a,u;if(!super.onDragEnd(t))return!1;const n=this.getAnnotation(!0);if(this.hoveredHandle){const l=n.geometry.coordinates;if(this.hoveredHandle.type==="body"){const d=this.snapping.snap({x:l[0][0],y:l[0][1]}),h=this.snapping.snap({x:l[1][0],y:l[1][1]});d?this.links.add(n,"start",d.id,d.type,d.magnet):((o=(r=n.properties.link)==null?void 0:r.start)==null?void 0:o.type)!=="comment"&&this.links.remove(n,c.SIDE_START),h?this.links.add(n,"end",h.id,h.type,h.magnet):((u=(a=n.properties.link)==null?void 0:a.end)==null?void 0:u.type)!=="comment"&&this.links.remove(n,c.SIDE_END)}else if(this.snap){const d=this.hoveredHandle;d.type!=="body"&&this.links.add(n,d.type,this.snap.id,this.snap.type,this.snap.magnet)}else if(this.snap===null){const d=this.hoveredHandle.type;if(n.properties.link&&n.properties.link[d]){this.links.remove(n,d);const h={...n.properties.link};delete h[d],this.store.getState().applyLiveUpdate(n.id,{properties:{...n.properties,link:h}})}}}return this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null}),this.commitChange(),this.clearDragState(),this.snap=null,!0}snapDrawingStart(t,n,s){const r=this.snapping.snap({x:n,y:s});if(r){const o={geometry:{...t.geometry,coordinates:[[r.point.x,r.point.y],t.geometry.coordinates[1]]},properties:{...t.properties,link:{start:{side:c.SIDE_START,id:r.id,type:r.type,magnet:r.magnet}}}},a=this.store.getState();a.applyLiveUpdate(t.id,o),a.updateFeature(t.id,o),this.links.add(t,"start",r.id,r.type,r.magnet)}}startDrawing(t,n,s){this.annotation=t;const r=this.getAnnotation();this.snapDrawingStart(r,n,s),this.grabHandle("end",n,s),this.dragging=!0,this.dragStartPoint={x:n,y:s};const o=this.ogma.view.graphToScreenCoordinates({x:n,y:s});this.onDragStart({clientX:o.x,clientY:o.y})}link(t,n,s){let r=c.getArrowSide(t,s);const o=t.properties.link||{};let a=null;if(n instanceof st.Node)r=n.getPosition(),a=this.snapping.snapToNodes(r,n.toList());else{const u=this.store.getState().getFeature(n);if(!u)throw new Error(`Annotation with id ${n} not found`);if(c.isText(u)||c.isBox(u))r=c.getBoxCenter(u),a=this.snapping.snapToText(r,[u]);else if(c.isPolygon(u))r=vt(u),a=this.snapping.snapToPolygon(r,[u]);else throw new Error(`Cannot link arrow to annotation of type ${u.properties.type}`)}a&&(o[s]={side:s,id:a.id,type:a.type,magnet:a.magnet},this.links.add(t,s,a.id,a.type,a.magnet),c.setArrowEndPoint(t,s,r.x,r.y),this.store.getState().updateFeature(t.id,{properties:{...t.properties,link:o},geometry:{type:t.geometry.type,coordinates:t.geometry.coordinates}}))}}const Sn=-2;class En extends dt{constructor(t,n,s){super(t,n);S(this,"links");S(this,"isDrawingMode",!1);S(this,"simplificationTolerance",5);S(this,"handleMouseDown",t=>{!this.isActive()||this.dragging||!this.hoveredHandle||(t.preventDefault(),t.stopPropagation(),this.dragStartPoint=this.clientToCanvas(t),this.onDragStart(t),this.dispatchEvent(new CustomEvent(c.EVT_DRAG_START,{detail:{id:this.annotation,position:{x:t.clientX,y:t.clientY}}})),this.disablePanning())});this.links=s}startDrawing(t,n,s){this.annotation=t,this.isDrawingMode=!0;const r=this.store.getState();r.startLiveUpdate([t]),r.setDrawingPoints([]);const o=this.ogma.view.graphToScreenCoordinates({x:n,y:s});return this.dragStartPoint=o,this.disablePanning(),this.onDragStart({clientX:o.x,clientY:o.y}),this}cancelDrawing(){this.isDrawingMode&&(this.isDrawingMode=!1,this.annotation&&(this.store.getState().removeFeature(this.annotation),this.annotation=null)),this.restorePanning()}detectHandle(t,n=1){const s=this.getAnnotation();if(!s)return;const r=this.clientToCanvas(t),o=c.handleDetectionThreshold/n,a=s.geometry.coordinates[0];for(let u=0;u<a.length-1;u++){const[l,d]=a[u];if(Math.sqrt(Math.pow(r.x-l,2)+Math.pow(r.y-d,2))<o*2){this.grabHandle("vertex",l,d,u);return}}c.detectPolygon(s,r,o)?(this.setCursor(c.cursors.grab),this.hoveredHandle={type:"body",point:r},this.store.setState({hoveredHandle:Sn,hoveredFeature:this.annotation})):(this.store.setState({hoveredHandle:c.NONE,hoveredFeature:null}),this.hoveredHandle=void 0)}grabHandle(t,n,s,r){this.setCursor(t==="vertex"?c.cursors.pointer:c.cursors.grab),this.hoveredHandle={type:t,point:{x:n,y:s},vertexIndex:r},this.store.setState({hoveredHandle:r??0,hoveredFeature:this.annotation})}onDragStart(t){if(this.isDrawingMode){const n=this.clientToCanvas(t);this.dragging=!0;const s=this.getAnnotation();if(s){const r=[[n.x,n.y],[n.x,n.y]],o=this.store.getState();o.setDrawingPoints(r),o.applyLiveUpdate(s.id,{...s,geometry:{type:"Polygon",coordinates:[r],bbox:[n.x,n.y,n.x,n.y]}})}return this.dragStartPoint=n,!0}return this.hoveredHandle?(this.dragging=!0,this.setCursor(c.cursors.grabbing),this.store.getState().startLiveUpdate([this.annotation]),!0):!1}onDrag(t){if(this.isDrawingMode&&this.dragging){const a=this.clientToCanvas(t),u=this.store.getState(),l=this.getAnnotation();if(!l)return;const d=u.liveUpdates[this.annotation],h=d?{...l,...d}:l,f=u.drawingPoints.slice(0,-1),g=[...f,[a.x,a.y],f[0]];u.setDrawingPoints(g);const p=Dt(g,this.simplificationTolerance,!1),m=[...p,p[0]];u.applyLiveUpdate(this.annotation,{...h,geometry:{type:"Polygon",coordinates:[m]}});return}if(!this.dragging||!this.dragStartPoint||!this.hoveredHandle)return;const n=this.clientToCanvas(t),s=n.x-this.dragStartPoint.x,r=n.y-this.dragStartPoint.y,o=this.getAnnotation();if(o){if(this.hoveredHandle.type==="body")_t(this.store,this.links,o.id,{x:s,y:r});else if(this.hoveredHandle.type==="vertex"&&this.hoveredHandle.vertexIndex!==void 0){const a=o.geometry.coordinates[0].map((l,d)=>d===this.hoveredHandle.vertexIndex?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:d===o.geometry.coordinates[0].length-1&&this.hoveredHandle.vertexIndex===0?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:l),u={...o,geometry:{...o.geometry,coordinates:[a]}};kt(u),this.store.getState().applyLiveUpdate(o.id,u),this.links.snapLinkedArrowsDuringDrag(o.id)}this.dispatchEvent(new Event(c.EVT_DRAG))}}onDragEnd(){if(this.isDrawingMode&&this.dragging){const n=this.store.getState(),s=this.getAnnotation();if(s){const r=n.drawingPoints;if(r.length<3)this.cancelDrawing();else{const o=Dt(r.slice(1,-1),this.simplificationTolerance,!0),a={...s,geometry:{type:"Polygon",coordinates:[o]}};c.updateBbox(a),this.store.getState().applyLiveUpdate(s.id,a),this.store.setState({drawingFeature:null}),this.commitChange(),this.isDrawingMode=!1,this.dragging=!1,this.restorePanning(),this.dispatchEvent(new CustomEvent(c.EVT_COMPLETE_DRAWING,{detail:a}))}}return!0}return!this.dragging||(this.dragging=!1,this.dragStartPoint=void 0,!this.getAnnotation())?!1:(this.commitChange(),this.setCursor(c.cursors.grab),!0)}getAnnotation(){if(this.annotation)return this.store.getState().getFeature(this.annotation)}}const Fn=24,yn=4,An=16,Cn=50;class Nn{constructor(e,t,n,s=()=>{}){S(this,"layer");S(this,"textarea");S(this,"sendButton",null);S(this,"isFocused");S(this,"unsubscribe");S(this,"fixedSize");S(this,"onFocus",()=>{this.isFocused=!0});S(this,"onBlur",()=>{this.getAnnotation()&&this.updateContent(),this.isFocused=!1});S(this,"onKeyup",e=>{e.key==="Escape"&&this.textarea.blur(),e.stopPropagation()});S(this,"onKeydown",e=>{e.stopPropagation()});S(this,"onMouseEvent",e=>{e.stopPropagation()});S(this,"onInput",()=>{this.updateContent(),this.updateStyle(),this.updatePosition(),this.layer.setSize(this.getSize()),this.updateSendButtonState()});S(this,"onSendClick",e=>{e.preventDefault(),e.stopPropagation(),!(!this.sendButton||this.sendButton.disabled)&&(this.updateContent(),this.textarea.blur(),this.onSendHandler())});S(this,"update",()=>{this.getAnnotation()&&(this.updateStyle(),this.updatePosition(),this.layer.setSize(this.getSize()))});var f,g,p,m,F;this.ogma=e,this.store=t,this.annotation=n,this.onSendHandler=s;const r=this.getAnnotation(),o=this.store.getState(),a=c.isComment(r)&&(((f=o.options)==null?void 0:f.showSendButton)??!0),u=((g=o.options)==null?void 0:g.sendButtonIcon)||"",l=((p=r.properties.style)==null?void 0:p.placeholder)||((m=o.options)==null?void 0:m.textPlaceholder)||"Enter text",d=c.isComment(r)?c.defaultCommentStyle:c.defaultTextStyle;this.fixedSize=((F=r.properties.style)==null?void 0:F.fixedSize)??d.fixedSize??!1;const h=this.getPosition(),x=this.getSize();this.layer=this.ogma.layers.addOverlay({element:`<div class="ogma-annotation-text-editor">
2
+ <textarea wrap="on" name="annotation-text--input" spellcheck="false" placeholder="${l}"></textarea>
8
3
  ${a?`<button class="ogma-send-button" type="button" title="Send">
9
- <span class="ogma-send-button-icon">${d}</span>
4
+ <span class="ogma-send-button-icon">${u}</span>
10
5
  </button>`:""}
11
- </div>`,position:u,size:h,scaled:!this.fixedSize},Yt.EDITOR),this.textarea=this.layer.element.querySelector("textarea"),this.textarea.setAttribute("wrap","on"),this.textarea.setAttribute("spellcheck","false"),this.textarea.value=r.properties.content||"",a&&(this.sendButton=this.layer.element.querySelector(".ogma-send-button"),this.sendButton.addEventListener("click",this.onSendClick),this.updateSendButtonState()),this.isFocused=!1,this.textarea.addEventListener("focus",this.onFocus),this.textarea.addEventListener("blur",this.onBlur),this.textarea.addEventListener("input",this.onInput),this.textarea.addEventListener("keyup",this.onKeyup),this.textarea.addEventListener("keydown",this.onKeydown),this.textarea.addEventListener("wheel",this.onMouseEvent),this.textarea.addEventListener("mouseup",this.onMouseEvent),this.textarea.addEventListener("mousedown",this.onMouseEvent),this.textarea.addEventListener("click",this.onMouseEvent),this.textarea.addEventListener("drag",this.onMouseEvent),this.updateStyle(),this.updatePosition(),this.textarea.focus(),this.unsubscribe=this.store.subscribe(y=>({rotation:y.rotation,zoom:y.zoom,annotation:y.features[this.annotation]}),this.update,{equalityFn:(y,A)=>y.rotation===A.rotation&&y.zoom===A.zoom&&y.annotation===A.annotation})}getAnnotation(){const e=this.store.getState();e.liveUpdates[this.annotation]||e.startLiveUpdate([this.annotation]);const t=e.getFeature(this.annotation),n=e.liveUpdates[this.annotation];return t&&n?{...t,...n}:t}getPosition(){const e=this.getAnnotation();if(!e)return{x:0,y:0};const t=e.properties.style,n=t==null?void 0:t.maxHeight,i=this.store.getState().zoom,r=En(e),[o,a]=e.geometry.coordinates,d=e.properties.width;let c=e.properties.height;n&&(c=Math.min(c,n));const l=this.fixedSize?1/i:1;return{x:o-d*l/2+r*l,y:a-c*l/2+r*l}}getSize(){const e=this.getAnnotation();if(!e)return{width:0,height:0};const t=X(e),n=En(e),i=e.properties.style,r=i==null?void 0:i.maxHeight;let o=t.height-n*2;return r&&(o=Math.min(o,r-n*2)),{width:t.width-n*2,height:o}}updateStyle(){var y;const e=this.getAnnotation();if(!e)return;const t=I(e)?Z:q,{font:n,fontSize:i=t.fontSize,borderRadius:r,color:o,background:a=t.background,padding:d=0,fixedSize:c=t.fixedSize}=e.properties.style||t,l=this.textarea,u=this.layer.element,h=1,x=parseFloat(i.toString())*h,g=d*h,f=u.style;if(f.display="grid",f.gridTemplateRows="1fr auto",f.boxSizing="border-box",f.background=a||"transparent",f.borderRadius=`${(r||0)*h}px`,f.padding=`${g}px`,f.transformOrigin="center",f.transform=`rotate(${this.store.getState().rotation}rad)`,e.properties.type==="comment"){const A=e.properties.style,E=(A==null?void 0:A.shadow)!==!1;f.boxShadow=E?"0 2px 8px rgba(0, 0, 0, 0.15)":"none"}const p=l.style;if(p.fontFamily=n||"sans-serif",p.fontSize=`${x}px`,p.lineHeight=`${x*Xt}px`,p.padding="0",p.border="none",p.outline="none",p.boxSizing="border-box",p.color=o||"black",p.background="transparent",p.flex="1",p.minHeight="0",p.resize="none",this.sendButton){const A=24*h,E=4*h;this.sendButton.style.width=`${A}px`,this.sendButton.style.height=`${A}px`,this.sendButton.style.padding=`${E}px`,this.sendButton.style.transform="";const w=this.sendButton.querySelector(".ogma-send-button-icon");if(w){const N=16*h;w.style.width=`${N}px`,w.style.height=`${N}px`}}if(c){const A=(y=e.properties.style)==null?void 0:y.maxHeight,E=A&&e.properties.height>=A;p.overflowY=E?"auto":"hidden",p.overflowX="hidden"}}updatePosition(){this.layer.setPosition(this.getPosition())}updateContent(){var o,a,d,c;const e=this.getAnnotation();if(!e)return;let t=e.properties.height,n=e.geometry.coordinates;const i=(o=e.properties.style)==null?void 0:o.fixedSize;if(i){const l=this.textarea.style.height;this.textarea.style.height="0px";const u=this.textarea.scrollHeight;this.textarea.style.height=l;const h=((a=e.properties.style)==null?void 0:a.padding)||0,x=this.sendButton?parseFloat(this.sendButton.style.height||"0"):0,g=u+h*2+x,f=((d=e.properties.style)==null?void 0:d.minHeight)||50;t=Math.max(f,g);const p=(c=e.properties.style)==null?void 0:c.maxHeight,y=e.properties.height,A=t-y;if(!I(e)&&Math.abs(A)>1){const[w,N]=e.geometry.coordinates;if(p&&t>p){const F=p-y;t=p,Math.abs(F)>1&&(n=[w,N+F/2])}else n=[w,N+A/2]}else p&&t>p&&(t=p)}const r={...e,properties:{...e.properties,content:this.textarea.value,height:t},geometry:{...e.geometry,coordinates:n}};i&&Math.abs(e.properties.height-t)>1&&(this.layer.setSize(this.getSize()),this.layer.setPosition(this.getPosition())),this.store.getState().applyLiveUpdate(this.annotation,r)}updateSendButtonState(){if(!this.sendButton)return;const e=this.textarea.value.trim().length===0;this.sendButton.disabled=e}destroy(){this.store.getState().commitLiveUpdates(new Set([this.annotation])),this.unsubscribe(),this.sendButton&&this.sendButton.removeEventListener("click",this.onSendClick),this.layer.destroy()}}function En(s){var e;return((e=s.properties.style)==null?void 0:e.strokeWidth)||0}const Nn={x:1,y:0},Cn={x:0,y:1},ai=[["top",Cn,-.5,-.5,.5,-.5],["right",Nn,.5,-.5,.5,.5],["bottom",Cn,-.5,.5,.5,.5],["left",Nn,-.5,-.5,-.5,.5]],ci={top:[0,1],right:[1,2],bottom:[2,3],left:[3,0]},wn=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]],li=[z.nwResize,z.neResize,z.seResize,z.swResize];class Te extends Kt{constructor(t,n,i){super(t,n);m(this,"links");m(this,"textEditor",null);m(this,"justActivated",!1);m(this,"onClick",t=>{if(Vt(t.target??null))return;const n=this.getAnnotation();if(n){if(I(n)&&n.properties.mode===rt){this.store.getState().updateFeature(n.id,{properties:{...n.properties,mode:Bt}}),this.ogma.view.afterNextFrame(),this.justActivated=!1;return}if(this.store.getState().selectedFeatures.has(n.id)){if(I(n)&&this.justActivated){this.justActivated=!1;return}n&&(_(n)||I(n))&&this.startEditingText()}}});m(this,"stopEditingText",()=>{this.textEditor&&(this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null}),this.textEditor.destroy()),this.textEditor=null,this.store.setState({editingFeature:null})});this.links=i}detectHandle(t,n){var w;const i=this.getAnnotation(),{x:r,y:o}=this.clientToCanvas(t);let{width:a,height:d}=X(i);const c=5/n,l=J(i),u=this.store.getState();let{revSin:h,revCos:x}=u;(G(i)||I(i))&&(h=0,x=1),this.hoveredHandle=void 0;const g=sn*(1/n),f=r-l.x,p=o-l.y,y=f*x-p*h,A=f*h+p*x,E=((w=i.properties.style)==null?void 0:w.fixedSize)===!0||I(i);if(E&&(a/=n,d/=n),!E){for(let N=0;N<wn.length;N++){const[F,C]=wn[N],M=a*F,B=d*C;if(y>=M-g-c&&y<=M+g+c&&A>=B-g-c&&A<=B+g+c){this.hoveredHandle={type:"corner",corner:N},this.store.setState({hoveredHandle:N,hoveredFeature:this.annotation}),this.setCursor(this.getCornerCursor(N));return}}for(const[N,F,C,M,B,D]of ai){const v=a*C,O=d*M,R=a*B,W=d*D,b=Et(F,{x:y-v,y:A-O});if(Math.abs(b)<c&&y>=v-c&&y<=R+c&&A>=O-c&&A<=W+c){this.hoveredHandle={type:"edge",edge:N,corner:-1},this.store.setState({hoveredHandle:ci[N][0]+4,hoveredFeature:this.annotation}),this.setCursor(this.getEdgeCursor(N));return}}}if(y>=-a/2-c&&y<=a/2+c&&A>=-d/2-c&&A<=d/2+c){this.store.setState({hoveredHandle:8,hoveredFeature:this.annotation}),this.hoveredHandle={type:"body",corner:-1},this.setCursor(z.grab);return}this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.setCursor(z.default)}onDrag(t){if(!this.dragStartPoint||!this.hoveredHandle||!this.isActive())return;t.stopPropagation(),t.stopImmediatePropagation();const n=this.getAnnotation(),i=this.clientToCanvas(t),r={x:i.x-this.dragStartPoint.x,y:i.y-this.dragStartPoint.y},o=this.hoveredHandle,a=this.getAnnotation();let d=null;o.type==="corner"?d=this.dragCorner(a,r,o.corner):o.type==="edge"&&o.edge?d=this.dragEdge(a,r,o):o.type==="body"&&(Le(this.store,this.links,n.id,r),this.textEditor&&this.textEditor.update()),d&&(this.store.getState().applyLiveUpdate(n.id,d),this.links.updateLinkedArrowsDuringDrag(n.id,r),this.textEditor&&this.textEditor.update()),this.dispatchEvent(new CustomEvent(Dt,{detail:{point:i,annotation:this.annotation,handle:o}}))}dragCorner(t,n,i){const r=i===0||i===1,o=i===0||i===3,a=i===1||i===2,d=i===2||i===3,{width:c,height:l}=X(t),u=this.store.getState();let{revSin:h,revCos:x}=u;(G(t)||I(t))&&(h=0,x=1);const g=n.x*x-n.y*h,f=n.x*h+n.y*x;let p=0,y=0;o?p=-g:a&&(p=g),r?y=-f:d&&(y=f);const A=Math.max(0,c+p),E=Math.max(0,l+y),w=J(t),N=w.x+n.x/2,F=w.y+n.y/2;return{...t,properties:{...t.properties,width:A,height:E},geometry:{type:t.geometry.type,coordinates:[N,F]}}}dragEdge(t,n,i){const{width:r,height:o}=X(t),a=J(t),d=this.store.getState();let{revSin:c,revCos:l}=d;(G(t)||I(t))&&(c=0,l=1);const u=n.x*l-n.y*c,h=n.x*c+n.y*l;let x=r,g=o,f=0,p=0;switch(i.edge){case"top":g=Math.max(0,o-h),p=h/2;break;case"bottom":g=Math.max(0,o+h),p=h/2;break;case"left":x=Math.max(0,r-u),f=u/2;break;case"right":x=Math.max(0,r+u),f=u/2;break}const y=f*l+p*c,A=-f*c+p*l;return{...t,properties:{...t.properties,width:x,height:g},geometry:{type:t.geometry.type,coordinates:[a.x+y,a.y+A]}}}onDragStart(t){return super.onDragStart(t)?(this.stopEditingText(),this.store.getState().startLiveUpdate([this.annotation]),!0):!1}startEditingText(){this.textEditor===null&&(this.store.setState({editingFeature:this.annotation}),this.textEditor=new oi(this.ogma,this.store,this.annotation,this.stopEditingText))}onDragEnd(t){var a,d;if(!super.onDragEnd(t))return!1;this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null});const i=this.clientToCanvas(t),r=i.x-(((a=this.dragStartPoint)==null?void 0:a.x)||0),o=i.y-(((d=this.dragStartPoint)==null?void 0:d.y)||0);return Math.abs(r)<1&&Math.abs(o)<1?(this.clearDragState(),this.onClick({clientX:t.clientX,clientY:t.clientY})):this.commitChange(),this.hoveredHandle=void 0,this.dragStartPoint=void 0,this.dragging=!1,!0}getCornerCursor(t){return li[t]}getEdgeCursor(t){switch(t){case"top":case"bottom":return z.nsResize;case"left":case"right":return z.ewResize;default:return z.default}}stopEditing(){super.stopEditing(),this.commitChange(),this.stopEditingText()}startDrawing(t,n,i){this.annotation=t,this.hoveredHandle={type:"corner",corner:2},this.store.setState({hoveredHandle:2,hoveredFeature:this.annotation}),this.dragging=!0;const r=this.ogma.view.graphToScreenCoordinates({x:n,y:i});this.dragStartPoint=r,this.disablePanning(),this.onDragStart({clientX:r.x,clientY:r.y})}setAnnotation(t){t&&I(t)&&(this.justActivated=!0),super.setAnnotation(t),t&&I(t)&&t.properties.mode===rt&&this.store.getState().updateFeature(t.id,{properties:{...t.properties,mode:Bt}})}}class di extends EventTarget{constructor(t,n,i,r,o){super();m(this,"handlers",new Map);m(this,"activeHandler");m(this,"interaction");m(this,"ogma");m(this,"snapping");m(this,"store");this.ogma=t,this.store=n,this.snapping=i,this.interaction=o,this.handlers.set("box",new Te(this.ogma,this.store,r)),this.handlers.set("text",new Te(this.ogma,this.store,r)),this.handlers.set("comment",new Te(this.ogma,this.store,r)),this.handlers.set("arrow",new ii(this.ogma,this.store,this.snapping,r)),this.handlers.set("polygon",new ri(this.ogma,this.store,r)),this.handlers.forEach(a=>{a.addEventListener("dragstart",(d=>{this.dispatchEvent(new CustomEvent(Ft,{detail:{...d.detail}})),this.store.setState({isDragging:!0}),this.interaction.setMode("edit")})),a.addEventListener("dragend",(d=>{this.dispatchEvent(new CustomEvent(vt,{detail:{...d.detail}})),this.store.setState({isDragging:!1}),this.interaction.suppressClicksTemporarily()}))}),this.store.subscribe(a=>a.selectedFeatures,(a,d)=>{const c=Array.from(a.keys()).filter(u=>!d.has(u)),l=Array.from(d.keys()).filter(u=>!a.has(u));!c.length&&!l.length||(l.forEach(u=>this.stopEditingFeature(u)),c.forEach(u=>this.editFeature(u)))})}stopEditingFeature(t){const n=this.store.getState().features[t];if(!n)return;const i=n.properties.type,r=this.handlers.get(i);r&&r.stopEditing()}editFeature(t){var i;const n=this.store.getState().features[t];n&&(this.setActiveHandler(n.properties.type),(i=this.activeHandler)==null||i.setAnnotation(n))}getSnapping(){return this.snapping}getArrowHandler(){return this.handlers.get("arrow")}getActiveHandler(){return this.activeHandler}setActiveHandler(t){const n=this.handlers.get(t);if(!n)throw new Error(`Handler for type ${t} not found`);return this.activeHandler=n,this}destroy(){}}const ui=["x","y","radius"],hi=1;function xi(s,e){return e===P.NODE?{type:"node",center:s.x===0&&s.y===0}:e===P.EDGE?{type:"edge",t:s.x}:e===P.POLYGON?{type:"polygon",rx:s.x,ry:s.y}:{type:"box",nx:s.x,ny:s.y}}class fi{constructor(e,t,n,i){m(this,"links",new Map);m(this,"nodeToLink",new Map);m(this,"edgeToLink",new Map);m(this,"annotationToLink",new Map);m(this,"linksByArrowId",new Map);m(this,"store");m(this,"ogma");m(this,"snapping");m(this,"updatedItems",new Set);m(this,"onLinkCreated");m(this,"commitTimeout");m(this,"nodePositionTimeout");m(this,"onSetMultipleAttributes",({elements:e,updatedAttributes:t})=>{const n=new Set(t);!e.isNode||!n.has("x")&&!n.has("y")&&!n.has("radius")||this.requestUpdateFromNodePositions(e.toList())});m(this,"refresh",()=>{const e=this.store.getState(),t=new Map;this.annotationToLink.forEach((n,i)=>{var a;const r=e.getFeature(i);if(!r)return;(_(r)&&((a=r.properties.style)==null?void 0:a.fixedSize)||I(r))&&n.forEach(d=>{const c=this.links.get(d);if(!c)return;const l=c.arrow;t.set(l,this.linksByArrowId.get(l))})}),t.size>0&&this.update(t)});m(this,"throttledRefresh",Se(()=>this.refresh(),20));m(this,"onAddRemoveEdges",e=>{const t=e.edges;if(!t.size||!this.edgeToLink.size)return;const n=new Map,i=new Map;t.getParallelEdges().getId().forEach(r=>{const o=this.edgeToLink.get(r);o&&o.forEach(a=>{const d=this.links.get(a);if(!d)return;const c=d.arrow;n.set(c,this.linksByArrowId.get(c)),i.set(c,this.linksByArrowId.get(c))})}),i.size!==0&&this.update(i)});m(this,"commit",()=>{this.store.getState().batchUpdate(this.commitLiveUpdates),this.updatedItems.clear()});m(this,"commitLiveUpdates",()=>{this.store.getState().commitLiveUpdates(this.updatedItems)});m(this,"onAddArrow",(e,t)=>{const n=this.store.getState(),i=new Set(Object.keys(t)),r=Object.keys(e).filter(d=>!i.has(d)),o=Object.keys(t).filter(d=>!e[d]);r.forEach(d=>{var u,h;const c=n.getFeature(d);if(!c||!tt(c))return;const l=c;if((u=l.properties.link)!=null&&u.start){const x=l.properties.link.start;this.add(l,$,x.id,x.type,x.magnet)}if((h=l.properties.link)!=null&&h.end){const x=l.properties.link.end;this.add(l,it,x.id,x.type,x.magnet)}}),o.forEach(d=>{const c=t[d];if(tt(c)){const l=c;this.remove(l,$),this.remove(l,it)}else{const l=this.annotationToLink.get(d);if(!l)return;for(const u of l){const h=this.links.get(u);if(!h)continue;const x=n.getFeature(h.arrow);x?this.remove(x,h.side):this.remove(h.arrow,h.side)}}});const a=new Map;for(const d of i){const c=e[d];if(!c||!this.annotationToLink.has(d))continue;const l=t[d],u=l.geometry.coordinates!==c.geometry.coordinates,h=l.properties.width!==c.properties.width||l.properties.height!==c.properties.height;if(!u&&!h)continue;const x=this.annotationToLink.get(d);for(const g of x){const f=this.links.get(g);if(!f)continue;const p=f.arrow;this.linksByArrowId.has(p)&&a.set(p,this.linksByArrowId.get(p))}}a.size>0&&this._updateAndCommitSync(a)});this.ogma=e,this.store=n,this.snapping=t,this.onLinkCreated=i,this.store.subscribe(r=>r.features,this.onAddArrow),this.store.subscribe(r=>({zoom:r.zoom,rotation:r.rotation}),this.throttledRefresh,{equalityFn:(r,o)=>r.zoom===o.zoom&&r.rotation===o.rotation}),this.ogma.events.on("setMultipleAttributes",this.onSetMultipleAttributes).on(["addEdges","removeEdges"],this.onAddRemoveEdges).on("viewChanged",this.refresh)}updateLinkedArrowsDuringDrag(e,t,n){const i=this.store.getState();if(!i.getFeature(e))return;const o=this.annotationToLink.get(e);if(o)for(const a of o){const d=this.links.get(a);if(!d)continue;const c=i.getFeature(d.arrow),l=kt(c,d.side),u=ft(l,t),h={...c.geometry,coordinates:c.geometry.coordinates.map((x,g)=>d.side===$&&g===0||d.side===it&&g===1?[u.x,u.y]:[...x])};n?n[c.id]={geometry:h}:i.applyLiveUpdate(c.id,{geometry:h}),this.updatedItems.add(c.id)}}snapLinkedArrowsDuringDrag(e,t){const n=this.store.getState();let i=n.getFeature(e);if(!i)return;const r=n.liveUpdates[e];i=r?{...i,...r}:i;const o=this.annotationToLink.get(e);if(o)for(const a of o){const d=this.links.get(a);if(!d)continue;let c=n.getFeature(d.arrow);const l=n.liveUpdates[c.id];c=l?{...c,...l}:c;const u=c.geometry.coordinates[d.side===$?0:1],h={x:u[0],y:u[1]};let x;if(_(i)||I(i)||G(i)?x=this.snapping.snapToText(h,[i]):nt(i)&&(x=this.snapping.snapToPolygon(h,[i])),!x)continue;const g=x.point,f={...c.geometry,coordinates:c.geometry.coordinates.map((p,y)=>d.side===$&&y===0||d.side===it&&y===1?[g.x,g.y]:[...p])};t?t[c.id]={geometry:f}:n.applyLiveUpdate(c.id,{geometry:f})}}add(e,t,n,i,r){const o=ht(),a=e.id;let d=r;if(i===P.POLYGON){const h=this.store.getState().getFeature(n);if(h&&nt(h)){const x=xe(h),g=x[2]-x[0],f=x[3]-x[1],p=r.x-x[0],y=r.y-x[1],A=g>0?p/g:.5,E=f>0?y/f:.5;d={x:A,y:E}}}const c={id:o,arrow:a,target:n,targetType:i,magnet:xi(d,i),side:t};if(i===P.NODE&&!this.ogma.getNode(n)||i===P.EDGE&&!this.ogma.getEdge(n))return;this.remove(e,t),this.links.set(o,c);const l=i===P.NODE?this.nodeToLink:i===P.EDGE?this.edgeToLink:this.annotationToLink;return l.has(n)||l.set(n,new Set),l.get(n).add(o),this.linksByArrowId.has(a)||this.linksByArrowId.set(a,{}),this.linksByArrowId.get(a)[t]=o,e.properties.link=e.properties.link||{},e.properties.link[t]={id:n,side:t,type:i,magnet:d},this.onLinkCreated&&this.onLinkCreated(e,c),this}remove(e,t){var o,a,d,c,l;const n=typeof e=="object"?e.id:e,i=(o=this.linksByArrowId.get(n))==null?void 0:o[t];if(typeof e=="object"&&((a=e.properties.link)==null||delete a[t]),!i)return this;const r=this.links.get(i);return r?(this.links.delete(i),(d=this.nodeToLink.get(r.target))==null||d.delete(i),(c=this.edgeToLink.get(r.target))==null||c.delete(i),(l=this.annotationToLink.get(r.target))==null||l.delete(i),this.linksByArrowId.has(n)&&(this.linksByArrowId.get(n)[t]=void 0),this):this}requestUpdateFromNodePositions(e){clearTimeout(this.nodePositionTimeout),this.nodePositionTimeout=setTimeout(()=>this.updateFromNodePositions(e),1)}updateFromNodePositions(e){if(!e.size)return;const t=e.getId(),n=new Map;t.forEach(c=>{const l=this.nodeToLink.get(c);l&&l.forEach(u=>{const h=this.links.get(u);if(!h)return;const x=h.arrow;n.set(x,this.linksByArrowId.get(x))})});const i=new Map;e.getAdjacentEdges().getId().forEach(c=>{const l=this.edgeToLink.get(c);l&&l.forEach(u=>{const h=this.links.get(u);if(!h)return;const x=h.arrow;n.set(x,this.linksByArrowId.get(x)),i.set(x,this.linksByArrowId.get(x))})});const o=e.getAttributes(ui),a=this.store.getState(),d={};for(let c=0;c<t.length;c++){const l=t[c],u=this.nodeToLink.get(l);if(u)for(const h of u){const x=this.links.get(h);if(!x)continue;const g=x.arrow,f=this.store.getState().getFeature(g),p=f.geometry.coordinates.slice(),y=kt(f,it),A=kt(f,$),E=x.side===$?0:1,w=o[c],N=this._getNodeSnapPoint(w,ot(Y(y,A),-1),this._isLinkedToCenter(x)),F=this._getRigidFollowComment(g,x);if(F){const C=p[E],M=Y({x:N[0],y:N[1]},{x:C[0],y:C[1]});p[0]=[p[0][0]+M.x,p[0][1]+M.y],p[1]=[p[1][0]+M.x,p[1][1]+M.y];const[B,D]=F.geometry.coordinates,v={...F,geometry:{type:"Point",coordinates:[B+M.x,D+M.y]}};d[F.id]=v,ct(v),this.updatedItems.add(F.id)}else p[E]=N;d[g]={...f,geometry:{coordinates:p}},this.updatedItems.add(g),ct(d[g])}}if(a.applyLiveUpdates(d),i.size>0){this.update(i);return}this.requestCommit()}update(e=this.linksByArrowId){const t=this._computeArrowUpdates(e);this.store.getState().applyLiveUpdates(t),this.requestCommit()}_updateAndCommitSync(e){const t=this._computeArrowUpdates(e);if(Object.keys(t).length===0)return;const n=this.store.getState();n.batchUpdate(()=>{n.updateFeatures(t)})}_computeArrowUpdates(e){const t=this.store.getState(),n=Array.from(this.nodeToLink.keys()),i=new Map;n.forEach((d,c)=>i.set(d,c));const o=this.ogma.getNodes(n).getAttributes(["x","y","radius"]),a={};return e.forEach((d,c)=>{const l=this.links.get(d.start),u=this.links.get(d.end),h=t.getFeature(c);let x=h.geometry.coordinates[0],g=h.geometry.coordinates[1];const f=l?l.targetType===P.NODE?o[i.get(l.target)]:l.targetType===P.EDGE?this._getEdgeSnapPoint(l.target,l.magnet.t,!0):this._getAnnotationCenter(t.getFeature(l.target)):{x:x[0],y:x[1]},p=u?u.targetType===P.NODE?o[i.get(u.target)]:u.targetType===P.EDGE?this._getEdgeSnapPoint(u.target,u.magnet.t,!0):this._getAnnotationCenter(t.getFeature(u.target)):{x:g[0],y:g[1]},y=Y(p,f);if(l)if(l.targetType===P.NODE)x=this._getNodeSnapPoint(f,y,this._isLinkedToCenter(l));else if(l.targetType===P.EDGE)x=this._getEdgeSnapPoint(l.target,l.magnet.t);else{const A=t.getMergedFeature(l.target);x=this._getAnnotationSnapPoint(A,p,l,t.zoom)}if(u)if(u.targetType===P.NODE)g=this._getNodeSnapPoint(p,ot(y,-1),this._isLinkedToCenter(u));else if(u.targetType===P.EDGE)g=this._getEdgeSnapPoint(u.target,u.magnet.t);else{const A=t.getMergedFeature(u.target);g=this._getAnnotationSnapPoint(A,f,u,t.zoom)}a[h.id]={properties:h.properties,geometry:{coordinates:[x,g]}},ct(a[h.id]),this.updatedItems.add(h.id)}),a}requestCommit(){clearTimeout(this.commitTimeout),this.commitTimeout=setTimeout(this.commit,hi)}_isLinkedToCenter(e){return e.magnet.type==="node"&&e.magnet.center}_getRigidFollowComment(e,t){const n=this.linksByArrowId.get(e);if(!n)return;const i=t.side===$?n.end:n.start;if(!i)return;const r=this.links.get(i);if(!r||r.targetType!==P.COMMENT)return;const o=this.annotationToLink.get(r.target);if(!o||o.size!==1)return;const a=this.store.getState().getFeature(r.target);if(!(!a||!I(a)))return a}_getAnnotationCenter(e){return nt(e)?fe(e):J(e)}_getAnnotationSnapPoint(e,t,n,i){if(nt(e)){const r=xe(e),o=n.magnet,a=r[0]+o.rx*(r[2]-r[0]),d=r[1]+o.ry*(r[3]-r[1]);return[a,d]}return this._getBoxSnapPoint(e,t,n,i)}_getBoxSnapPoint(e,t,n,i){var h;const r=J(e);let{width:o,height:a}=I(e)?gn(e):X(e);(_(e)&&((h=e.properties.style)==null?void 0:h.fixedSize)||I(e))&&(o/=i,a/=i);const c=n.magnet;let l=c.nx*o,u=c.ny*a;if(_(e)&&!G(e)){const{sin:x,cos:g}=this.store.getState(),f=l*g-u*x,p=l*x+u*g;l=f,u=p}return[r.x+l,r.y+u]}_getNodeSnapPoint(e,t,n){if(n)return[e.x,e.y];const i=Math.sqrt(t.x*t.x+t.y*t.y),r=ot(t,1/i),o=i<Number(e.radius)/2?{x:e.x,y:e.y}:ft({x:e.x,y:e.y},ot(r,-Number(e.radius)));return[o.x,o.y]}_getEdgeSnapPoint(e,t,n=!1){const i=this.ogma.getEdge(e);if(!i)return[0,0];const r=i.getAttribute("curvature"),a=i.getExtremities().getPosition(),d=a[0],c=a[1];if(r===0||r===void 0){const h=[d.x+t*(c.x-d.x),d.y+t*(c.y-d.y)];return n?{x:h[0],y:h[1]}:h}const l=U.geometry.getQuadraticCurveControlPoint(d.x,d.y,c.x,c.y,r),u=U.geometry.getPointOnQuadraticCurve(t,d.x,d.y,c.x,c.y,l.x,l.y);return n?{x:u.x,y:u.y}:[u.x,u.y]}destroy(){clearTimeout(this.commitTimeout),clearTimeout(this.nodePositionTimeout),this.ogma.events.off(this.onSetMultipleAttributes)}}function gi(s,e,t,n,i=20){let r=0,o=1/0,a=null;for(let d=0;d<=i;d++){const c=d/i,l=U.geometry.getPointOnQuadraticCurve(c,e.x,e.y,t.x,t.y,n.x,n.y),u=Q(Y(l,s));u<o&&(o=u,a=l,r=c)}return a?{t:r,point:a,distance:o}:null}function pi(s,e,t){const n=t.x-e.x,i=t.y-e.y,r=n*n+i*i;if(r===0)return{t:0,point:{x:e.x,y:e.y},distance:Q(Y(e,s))};const o=Math.max(0,Math.min(1,((s.x-e.x)*n+(s.y-e.y)*i)/r)),a={x:e.x+o*n,y:e.y+o*i};return{t:o,point:a,distance:Q(Y(a,s))}}function mi(s,e,t){let n=null,i=t;const r=e.getAttribute("curvature"),a=e.getExtremities().getPosition();for(let d=0;d<e.size;d++){const c=e.get(d),l=r[d],u=a[2*d],h=a[2*d+1];let x;if(l===0||l===void 0)x=pi(s,u,h);else{const g=U.geometry.getQuadraticCurveControlPoint(u.x,u.y,h.x,h.y,l);x=gi(s,u,h,g)}x&&x.distance<i&&(i=x.distance,n={point:x.point,id:c.getId(),magnet:{x:x.t,y:0},type:P.EDGE})}return n}function yi(s,e,t){const n=e.getAttributes(["x","y","radius"]);for(let i=0;i<n.length;i++){const r=n[i],o=Y({x:r.x,y:r.y},s),a=Q(o);if(a>=Number(r.radius)+Number(t))continue;const d=ot(o,1/a),c=a<Number(r.radius)/2,l=c?{x:r.x,y:r.y}:ft({x:r.x,y:r.y},ot(d,-Number(r.radius))),u=c?{x:0,y:0}:d;return{point:l,id:e.get(i).getId(),magnet:u,type:P.NODE}}return null}function Si(s,e){let t=!1;for(let n=0,i=e.length-1;n<e.length;i=n++){const r=e[n][0],o=e[n][1],a=e[i][0],d=e[i][1];o>s.y!=d>s.y&&s.x<(a-r)*(s.y-o)/(d-o)+r&&(t=!t)}return t}function Fi(s,e,t,n,i){const r=s*s,o=r*s,a=1-s,d=a*a,c=d*a;return{x:c*e.x+3*d*s*t.x+3*a*r*n.x+o*i.x,y:c*e.y+3*d*s*t.y+3*a*r*n.y+o*i.y}}function Ai(s,e,t,n,i){let r=1/0,o=null;const a=20;for(let d=0;d<=a;d++){const c=d/a,l=Fi(c,e,t,n,i),u=Q(Y(l,s));u<r&&(r=u,o=l)}return o?{point:o,distance:r}:null}function Ei(s,e,t){const n=e.geometry.coordinates[0];for(let i=0;i<n.length-1;i++){const[r,o]=n[i];if(Q(Y({x:r,y:o},s))<t)return{point:{x:r,y:o},magnet:{x:r,y:o},type:P.POLYGON,id:e.id}}for(let i=0;i<n.length-1;i++){const[r,o]=n[i],[a,d]=n[i+1],c={x:r,y:o},u=Y({x:a,y:d},c),h=Q(u),x={x:u.x/h,y:u.y/h},g={x:-x.y,y:x.x},f=Y(s,c),p=Math.abs(Et(g,f)),y=Et(x,f);if(y>=0&&y<=h&&p<t){const A={x:c.x+x.x*y,y:c.y+x.y*y};return{point:A,magnet:A,type:P.POLYGON,id:e.id}}}return null}function Ni(s,e,t){for(const i of e){const o=i.geometry.coordinates[0].slice(0,-1);if(o.length<3)return Ei(s,i,t);for(let l=0;l<o.length;l++){const[u,h]=o[l];if(Q(Y({x:u,y:h},s))<t)return{point:{x:u,y:h},magnet:{x:u,y:h},type:P.POLYGON,id:i.id}}const a=Si(s,o);let d=null,c=a?1/0:t;for(let l=0;l<o.length;l++){const u=o[(l-1+o.length)%o.length],h=o[l],x=o[(l+1)%o.length],g=o[(l+2)%o.length],f=h[0]+(x[0]-u[0])/6*.5,p=h[1]+(x[1]-u[1])/6*.5,y=x[0]-(g[0]-h[0])/6*.5,A=x[1]-(g[1]-h[1])/6*.5,E=Ai(s,{x:h[0],y:h[1]},{x:f,y:p},{x:y,y:A},{x:x[0],y:x[1]});if(E){const w=E.distance;if(a)w<c&&(c=w,d=E.point);else if(w<t)return{point:E.point,magnet:E.point,type:P.POLYGON,id:i.id}}}if(a&&d)return{point:d,magnet:d,type:P.POLYGON,id:i.id}}return null}const Mn=[{x:-.5,y:-.5},{x:0,y:-.5},{x:.5,y:-.5},{x:-.5,y:0},{x:.5,y:0},{x:-.5,y:.5},{x:0,y:.5},{x:.5,y:.5},{x:0,y:0}],Ci=[[-.5,-.5,.5,-.5],[.5,-.5,.5,.5],[.5,.5,-.5,.5],[-.5,.5,-.5,-.5]];function bn(s,e,t,n,i,r,o,a,d){const c=s*i,l=e*r;return d?{x:t+(c*o-l*a),y:n+(c*a+l*o)}:{x:t+c,y:n+l}}function wi(s,e,t,n,i){var l;const r=J(e);let{width:o,height:a}=X(e);const{sin:d,cos:c}=i.getState();(l=e.properties.style)!=null&&l.fixedSize&&(o/=t,a/=t);for(const u of Mn){let h=u.x*o,x=u.y*a;if(!G(e)){const p=h*c-x*d,y=h*d+x*c;h=p,x=y}const g={x:r.x+h,y:r.y+x};if(!(Q(Y(g,s))>=n))return{point:{x:g.x,y:g.y},type:P.TEXT,magnet:u,id:e.id}}return null}function Mi(s,e,t,n,i){var g;const{x:r,y:o}=J(e);let{width:a,height:d}=X(e);(g=e.properties.style)!=null&&g.fixedSize&&(a/=t,d/=t);const{sin:c,cos:l}=i.getState(),u=!G(e);let h=null,x=1/0;for(let f=0;f<4;f++){const[p,y,A,E]=Ci[f],w=bn(p,y,r,o,a,d,l,c,u),N=bn(A,E,r,o,a,d,l,c,u),F=Y(N,w),C=Q(F),M={x:F.x/C,y:F.y/C},B={x:-M.y,y:M.x},D=Y(s,w),v=Et(B,D),O=Et(M,D);if(O>=0&&O<=C){const R=Math.abs(v);if(R<n||R<x){const W=O/C,b={point:{x:w.x+M.x*O,y:w.y+M.y*O},magnet:{x:p+(A-p)*W,y:y+(E-y)*W},type:P.TEXT,id:e.id};if(R<n)return b;R<x&&(x=R,h=b)}}}return h&&x<Math.max(a,d)?h:null}function bi(s,e,t,n,i){for(const r of e){const o=wi(s,r,t,n,i)||Mi(s,r,t,n,i);if(o)return o}return null}class Di extends EventTarget{constructor(t,n,i,r){super();m(this,"ogma");m(this,"options");m(this,"spatialIndex");m(this,"hoveredNode",null);m(this,"store");this.ogma=t,this.options=n,this.spatialIndex=i,this.store=r}snap(t){const n=this.findMagnet(t);return n||null}findMagnet(t){const n=this.options.detectMargin,i={minX:t.x-n,minY:t.y-n,maxX:t.x+n,maxY:t.y+n},r=this.spatialIndex.search(i),o=r.filter(g=>_(g)||G(g)),a=r.filter(g=>nt(g)),{nodes:d,edges:c}=this.ogma.view.getElementsInside(i.minX,i.minY,i.maxX,i.maxY),l=this.snapToNodes(t,d);if(l)return l;const u=this.snapToEdges(t,c);if(u)return u;const h=this.snapToText(t,o);if(h)return h;const x=this.snapToPolygon(t,a);return x||null}snapToText(t,n){const{zoom:i}=this.store.getState();return bi(t,n,i,this.options.magnetRadius,this.store)}snapToPolygon(t,n){return Ni(t,n,this.options.magnetRadius)}snapToNodes(t,n){return yi(t,n,this.options.detectMargin)}snapToEdges(t,n){return mi(t,n,this.options.magnetRadius)}getHoveredNode(){return this.hoveredNode}clearHoveredNode(){var t;(t=this.hoveredNode)==null||t.setSelected(!1),this.hoveredNode=null}getMagnets(){return Mn}}class vi extends EventTarget{constructor(t,n,i){super();m(this,"query",{minX:1/0,minY:1/0,maxX:1/0,maxY:1/0});m(this,"suppressClickUntil",0);m(this,"mouseDownState",null);m(this,"DRAG_THRESHOLD",3);m(this,"onMouseMove",t=>{const n=Tt(t,this.ogma.getContainer()),i=this.store.getState();if(this.mouseDownState&&!i.isDragging){const l=t.clientX-this.mouseDownState.screenX,u=t.clientY-this.mouseDownState.screenY;Math.sqrt(l*l+u*u)>this.DRAG_THRESHOLD&&(this.mouseDownState.hasMoved=!0)}if(i.isDragging)return;const{x:r,y:o}=this.ogma.view.screenToGraphCoordinates(n),a=this.detect(r,o),d=(a==null?void 0:a.id)??null,c=i.hoveredFeature;d!==c&&i.setHoveredFeature(d),this.setCursor(d===null?z.default:z.pointer)});m(this,"onMouseClick",()=>{Date.now()<this.suppressClickUntil});m(this,"onMouseDown",t=>{if(Date.now()<this.suppressClickUntil)return;if(Vt(t.target)){this.mouseDownState=null;return}const n=Tt(t,this.ogma.getContainer()),{x:i,y:r}=this.ogma.view.screenToGraphCoordinates(n),o=this.detect(i,r);this.mouseDownState={annotation:o,screenX:t.clientX,screenY:t.clientY,hasMoved:!1};const a=this.store.getState();this.store.setState({mousePressed:!0,mousePressPoint:{x:i,y:r}}),o&&!a.selectedFeatures.has(o.id)&&(t.ctrlKey||t.metaKey?a.toggleSelection(o.id):a.setSelectedFeatures([o.id]))});m(this,"onMouseUp",t=>{const n=this.store.getState();if(this.store.setState({mousePressed:!1,mousePressPoint:null}),Vt(t.target)){this.mouseDownState=null;return}if(this.mouseDownState&&!this.mouseDownState.hasMoved&&!n.isDragging){const i=this.mouseDownState.annotation;i?t.ctrlKey||t.metaKey?n.toggleSelection(i.id):n.selectedFeatures.has(i.id)||n.setSelectedFeatures([i.id]):!t.ctrlKey&&!t.metaKey&&n.clearSelection(),this.dispatchEvent(new CustomEvent(Wt,{detail:{id:(i==null?void 0:i.id)??null,position:{x:t.clientX,y:t.clientY}}}))}this.mouseDownState=null});m(this,"onWheel",t=>{var u;if(t.target instanceof HTMLTextAreaElement)return;const n=Tt(t,this.ogma.getContainer()),{x:i,y:r}=this.ogma.view.screenToGraphCoordinates(n),o=this.detect(i,r);if(!o||!I(o))return;const a=(u=o.properties.style)==null?void 0:u.maxHeight,d=o.properties.height;if(!a||d<=a)return;const c=this.ogma.getContainer(),l=c==null?void 0:c.querySelector(`[data-annotation="${o.id}"] .comment-box foreignObject div`);l&&(t.stopPropagation(),t.preventDefault(),l.scrollTop+=t.deltaY)});this.ogma=t,this.store=n,this.index=i;const r=this.ogma.getContainer();r&&(r.addEventListener("mousemove",this.onMouseMove,{passive:!0,capture:!0}),r.addEventListener("click",this.onMouseClick,{passive:!0,capture:!0}),r.addEventListener("mousedown",this.onMouseDown,{passive:!0,capture:!1}),r.addEventListener("mouseup",this.onMouseUp,{passive:!0,capture:!0}),r.addEventListener("wheel",this.onWheel,{passive:!1,capture:!0}))}detect(t,n,i){let r=null;const o=this.store.getState(),a=i??o.options.detectMargin;this.query.minX=t-a,this.query.minY=n-a,this.query.maxX=t+a,this.query.maxY=n+a;const d=this.index.query(this.query);if(d.length===0)return null;for(const c of d){const l=o.getFeature(c.id);if(tt(l)){if(Ae(l,{x:t,y:n},a)){r=l;break}}else if(G(l)){if(xn(l,{x:t,y:n},0,1,a)){r=l;break}}else if(nt(l)){if(Me(l,{x:t,y:n},a)){r=l;break}}else if(I(l)){if(fn(l,{x:t,y:n},a,o.sin,o.cos,o.zoom)){r=l;break}}else if(_(l)&&Ce(l,{x:t,y:n},a,o.revSin,o.revCos,o.zoom)){r=l;break}}return r}setCursor(t){var i;const n=(i=this.ogma.getContainer())==null?void 0:i.firstChild;n&&(n.style.cursor=t)}setMode(t){var n;t==="default"?this.setCursor(((n=this.ogma.getOptions().cursor)==null?void 0:n.default)||"default"):t==="add"||t==="link"?this.setCursor(z.crosshair):t==="rotate"&&this.setCursor(z.alias)}suppressClicksTemporarily(t=100){this.suppressClickUntil=Date.now()+t}destroy(){const t=this.ogma.getContainer();t&&(t.removeEventListener("mousemove",this.onMouseMove),t.removeEventListener("click",this.onMouseClick))}}function Dn(s,e,t=0,n=s.length-1,i=Bi){for(;n>t;){if(n-t>600){const d=n-t+1,c=e-t+1,l=Math.log(d),u=.5*Math.exp(2*l/3),h=.5*Math.sqrt(l*u*(d-u)/d)*(c-d/2<0?-1:1),x=Math.max(t,Math.floor(e-c*u/d+h)),g=Math.min(n,Math.floor(e+(d-c)*u/d+h));Dn(s,e,x,g,i)}const r=s[e];let o=t,a=n;for(Pt(s,t,e),i(s[n],r)>0&&Pt(s,t,n);o<a;){for(Pt(s,o,a),o++,a--;i(s[o],r)<0;)o++;for(;i(s[a],r)>0;)a--}i(s[t],r)===0?Pt(s,t,a):(a++,Pt(s,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Pt(s,e,t){const n=s[e];s[e]=s[t],s[t]=n}function Bi(s,e){return s<e?-1:s>e?1:0}class ki{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!Qt(e,t))return n;const i=this.toBBox,r=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],d=t.leaf?i(a):a;Qt(e,d)&&(t.leaf?n.push(a):Pe(e,d)?this._all(a,n):r.push(a))}t=r.pop()}return n}collides(e){let t=this.data;if(!Qt(e,t))return!1;const n=[];for(;t;){for(let i=0;i<t.children.length;i++){const r=t.children[i],o=t.leaf?this.toBBox(r):r;if(Qt(e,o)){if(t.leaf||Pe(e,o))return!0;n.push(r)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=wt([]),this}remove(e,t){if(!e)return this;let n=this.data;const i=this.toBBox(e),r=[],o=[];let a,d,c;for(;n||r.length;){if(n||(n=r.pop(),d=r[r.length-1],a=o.pop(),c=!0),n.leaf){const l=Li(e,n.children,t);if(l!==-1)return n.children.splice(l,1),r.push(n),this._condense(r),this}!c&&!n.leaf&&Pe(n,i)?(r.push(n),o.push(a),a=0,d=n,n=n.children[0]):d?(a++,n=d.children[a],c=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,i){const r=n-t+1;let o=this._maxEntries,a;if(r<=o)return a=wt(e.slice(t,n+1)),Ct(a,this.toBBox),a;i||(i=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,i-1))),a=wt([]),a.leaf=!1,a.height=i;const d=Math.ceil(r/o),c=d*Math.ceil(Math.sqrt(o));vn(e,t,n,c,this.compareMinX);for(let l=t;l<=n;l+=c){const u=Math.min(l+c-1,n);vn(e,l,u,d,this.compareMinY);for(let h=l;h<=u;h+=d){const x=Math.min(h+d-1,u);a.children.push(this._build(e,h,x,i-1))}}return Ct(a,this.toBBox),a}_chooseSubtree(e,t,n,i){for(;i.push(t),!(t.leaf||i.length-1===n);){let r=1/0,o=1/0,a;for(let d=0;d<t.children.length;d++){const c=t.children[d],l=Oe(c),u=Pi(e,c)-l;u<o?(o=u,r=l<r?l:r,a=c):u===o&&l<r&&(r=l,a=c)}t=a||t.children[0]}return t}_insert(e,t,n){const i=n?e:this.toBBox(e),r=[],o=this._chooseSubtree(i,this.data,t,r);for(o.children.push(e),It(o,i);t>=0&&r[t].children.length>this._maxEntries;)this._split(r,t),t--;this._adjustParentBBoxes(i,r,t)}_split(e,t){const n=e[t],i=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,i);const o=this._chooseSplitIndex(n,r,i),a=wt(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,Ct(n,this.toBBox),Ct(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=wt([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Ct(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let i,r=1/0,o=1/0;for(let a=t;a<=n-t;a++){const d=Rt(e,0,a,this.toBBox),c=Rt(e,a,n,this.toBBox),l=Ri(d,c),u=Oe(d)+Oe(c);l<r?(r=l,i=a,o=u<o?u:o):l===r&&u<o&&(o=u,i=a)}return i||n-t}_chooseSplitAxis(e,t,n){const i=e.leaf?this.compareMinX:Ti,r=e.leaf?this.compareMinY:Oi,o=this._allDistMargin(e,t,n,i),a=this._allDistMargin(e,t,n,r);o<a&&e.children.sort(i)}_allDistMargin(e,t,n,i){e.children.sort(i);const r=this.toBBox,o=Rt(e,0,t,r),a=Rt(e,n-t,n,r);let d=Jt(o)+Jt(a);for(let c=t;c<n-t;c++){const l=e.children[c];It(o,e.leaf?r(l):l),d+=Jt(o)}for(let c=n-t-1;c>=t;c--){const l=e.children[c];It(a,e.leaf?r(l):l),d+=Jt(a)}return d}_adjustParentBBoxes(e,t,n){for(let i=n;i>=0;i--)It(t[i],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():Ct(e[t],this.toBBox)}}function Li(s,e,t){if(!t)return e.indexOf(s);for(let n=0;n<e.length;n++)if(t(s,e[n]))return n;return-1}function Ct(s,e){Rt(s,0,s.children.length,e,s)}function Rt(s,e,t,n,i){i||(i=wt(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let r=e;r<t;r++){const o=s.children[r];It(i,s.leaf?n(o):o)}return i}function It(s,e){return s.minX=Math.min(s.minX,e.minX),s.minY=Math.min(s.minY,e.minY),s.maxX=Math.max(s.maxX,e.maxX),s.maxY=Math.max(s.maxY,e.maxY),s}function Ti(s,e){return s.minX-e.minX}function Oi(s,e){return s.minY-e.minY}function Oe(s){return(s.maxX-s.minX)*(s.maxY-s.minY)}function Jt(s){return s.maxX-s.minX+(s.maxY-s.minY)}function Pi(s,e){return(Math.max(e.maxX,s.maxX)-Math.min(e.minX,s.minX))*(Math.max(e.maxY,s.maxY)-Math.min(e.minY,s.minY))}function Ri(s,e){const t=Math.max(s.minX,e.minX),n=Math.max(s.minY,e.minY),i=Math.min(s.maxX,e.maxX),r=Math.min(s.maxY,e.maxY);return Math.max(0,i-t)*Math.max(0,r-n)}function Pe(s,e){return s.minX<=e.minX&&s.minY<=e.minY&&e.maxX<=s.maxX&&e.maxY<=s.maxY}function Qt(s,e){return e.minX<=s.maxX&&e.minY<=s.maxY&&e.maxX>=s.minX&&e.maxY>=s.minY}function wt(s){return{children:s,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function vn(s,e,t,n,i){const r=[e,t];for(;r.length;){if(t=r.pop(),e=r.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Dn(s,o,e,t,i),r.push(e,o,o,t)}}const Ht={minX:0,minY:0,maxX:0,maxY:0},Bn=(s,e)=>s.id===e.id;class Ii extends ki{constructor(t){super();m(this,"store");m(this,"onRotationChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>_(n)||I(n));for(const n of t)this.updateRotatedText(n)});m(this,"onZoomChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>{var i;return(_(n)||I(n))&&((i=n.properties.style)==null?void 0:i.fixedSize)});for(const n of t)this.updateRotatedText(n)});this.store=t,this.store.subscribe(n=>n.features,n=>{this.clear(),Object.values(n).forEach(i=>{_(i)||I(i)?this.updateRotatedText(i):this.insert(i)})}),this.store.subscribe(n=>({features:n.features,isDragging:n.isDragging,lastChangedFeatures:n.lastChangedFeatures,rotation:n.rotation}),(n,i)=>{i&&i.isDragging&&!n.isDragging&&n.lastChangedFeatures.length>0&&n.lastChangedFeatures.forEach(r=>{const o=n.features[r];o&&(ct(o),_(o)||I(o)?this.updateRotatedText(o):(this.remove(o,Bn),this.insert(o)))})},{equalityFn:(n,i)=>n.isDragging===i.isDragging}),this.store.subscribe(n=>n.rotation,this.onRotationChange),this.store.subscribe(n=>n.zoom,this.onZoomChange)}updateRotatedText(t){var u;const n=this.store.getState();this.remove(t,Bn);const i=J(t);let{width:r,height:o}=X(t);if(((u=t.properties.style)==null?void 0:u.fixedSize)===!0){const h=n.invZoom;r*=h,o*=h}const d=r/2,c=o/2,l=n.getRotatedBBox(i.x-d,i.y-c,i.x+d,i.y+c);this.insert({...t,geometry:{...t.geometry,bbox:l.slice()}})}compareMinX(t,n){return et(t)[0]-et(n)[0]}compareMinY(t,n){return et(t)[1]-et(n)[1]}toBBox(t){const n=et(t);return Ht.minX=n[0],Ht.minY=n[1],Ht.maxX=n[2],Ht.maxY=n[3],Ht}query(t){return super.search(t)}}class kn{constructor(e,t){m(this,"layer");this.ogma=e,this.store=t}destroy(){}}const Ln=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]];class Hi extends kn{constructor(t,n){super(t,n);m(this,"handleFill","#fff");m(this,"handleStroke","#1A70E5");m(this,"handleStrokeWidth",1.5);m(this,"handleRadius",3);m(this,"handleMagnifier",1.5);m(this,"refresh",()=>{this.layer.refresh()});m(this,"render",t=>{const n=this.store.getState(),i=1/n.zoom,{hoveredHandle:r,rotation:o,liveUpdates:a,features:d}=n,c=this.handleRadius*i;t.fillStyle=this.handleFill,t.lineWidth=this.handleStrokeWidth*i,t.strokeStyle=this.handleStroke,Object.values(d).forEach(l=>{if(!n.isSelected(l.id))return;const u=a[l.id]?{...l,...a[l.id]}:l;if(tt(u))this.renderArrowHandles(u,t,c,r);else if(G(u)||_(u)){const h=_(u)?o:0;this.renderOutline(u,t,h,r,n.zoom),this.renderBoxHandles(u,t,c,r,h)}else nt(u)&&this.renderPolygonHandles(u,t,c,r,n.drawingFeature===u.id)})});this.layer=t.layers.addCanvasLayer(this.render,void 0,Yt.HANDLES),this.store.subscribe(i=>({selectedFeatures:i.selectedFeatures,liveUpdates:i.liveUpdates}),this.refresh),t.events.on("zoom",this.refresh)}renderOutline(t,n,i,r,o){var p,y;const a=_(t)&&((p=t.properties.style)==null?void 0:p.fixedSize);let{width:d,height:c}=X(t);a&&(d/=o,c/=o);const l=xt(t,a,o),u=d/2,h=c/2,x=l.x+u,g=l.y+h;n.save(),n.translate(x,g),n.rotate(i);const f=(y=t.properties.style)==null?void 0:y.borderRadius;if(f&&f>0?(Vs(n,-u,-h,d,c,f),n.stroke()):n.strokeRect(-u,-h,d,c),r>=4&&r<8){let A,E,w,N;const F=f&&f>0?f:this.handleRadius/o;switch(r){case 4:A=-u+F,E=-h,w=u-F,N=-h;break;case 5:A=u,E=-h+F,w=u,N=h-F;break;case 6:A=u-F,E=h,w=-u+F,N=h;break;case 7:A=-u,E=h-F,w=-u,N=-h+F;break}n.lineWidth=this.handleStrokeWidth*this.handleMagnifier/o,n.beginPath(),n.moveTo(A,E),n.lineTo(w,N),n.stroke(),n.lineWidth=this.handleStrokeWidth}n.restore()}renderArrowHandles(t,n,i,r){var h,x,g,f;const o=pe(t),a=me(t),d=+(r===0),c=+(r===1),l=i*(1+(this.handleMagnifier-1)*d),u=i*(1+(this.handleMagnifier-1)*c);n.beginPath(),n.moveTo(o.x,o.y),n.lineTo(a.x,a.y),n.closePath(),n.stroke(),n.beginPath(),((x=(h=t.properties.link)==null?void 0:h.start)==null?void 0:x.type)!=="comment"&&(n.moveTo(o.x-l,o.y-l),n.rect(o.x-l,o.y-l,l*2,l*2)),((f=(g=t.properties.link)==null?void 0:g.end)==null?void 0:f.type)!=="comment"&&(n.moveTo(a.x-u,a.y-u),n.rect(a.x-u,a.y-u,u*2,u*2)),n.closePath(),n.fill(),n.stroke()}renderBoxHandles(t,n,i,r,o){var g;if(_(t)&&((g=t.properties.style)!=null&&g.fixedSize))return;const{width:a,height:d}=X(t),c=xt(t),l=a/2,u=d/2,h=c.x+l,x=c.y+u;n.save(),n.translate(h,x),n.rotate(o),n.beginPath();for(let f=0;f<Ln.length;f++){const[p,y]=Ln[f],A=a*p,E=d*y,w=r===f?i*this.handleMagnifier:i;n.rect(A-w,E-w,w*2,w*2)}n.closePath(),n.fill(),n.stroke(),n.restore()}renderPolygonHandles(t,n,i,r,o){const a=t.geometry.coordinates[0];if(!o){a.length>2&&(n.save(),n.strokeStyle=this.handleStroke,n.lineWidth=this.handleStrokeWidth/this.store.getState().zoom,this.drawSmoothPolygon(n,a,.5),n.stroke(),n.restore()),n.beginPath();for(let d=0;d<a.length-1;d++){const[c,l]=a[d],u=r===d?i*this.handleMagnifier:i;n.moveTo(c+u,l),n.arc(c,l,u,0,2*Math.PI)}n.closePath(),n.fill(),n.stroke()}}drawSmoothPolygon(t,n,i){const r=n.slice(0,-1);if(r.length<3)return;t.beginPath();const o=r.length;for(let a=0;a<o;a++){const d=r[(a-1+o)%o],c=r[a],l=r[(a+1)%o],u=r[(a+2)%o],h=c[0]+(l[0]-d[0])/6*i,x=c[1]+(l[1]-d[1])/6*i,g=l[0]-(u[0]-c[0])/6*i,f=l[1]-(u[1]-c[1])/6*i;a===0&&t.moveTo(c[0],c[1]),t.bezierCurveTo(h,x,g,f,l[0],l[1])}t.closePath()}renderCenterPoint(t,n){var r;const i=this.store.getState();if(_(t)){const o=xt(t,(r=t.properties.style)==null?void 0:r.fixedSize,i.zoom),a=X(t);n.moveTo(o.x+a.width/2+5,o.y+a.height/2),n.arc(o.x+a.width/2,o.y+a.height/2,5,0,Math.PI*2,!0)}}destroy(){this.layer.destroy(),super.destroy()}}const _i=.5;function zi(s,e,t,n){const{start:i,end:r}=Ut(s),o=Y(r,i);return Math.min(n,Math.max(2*e,Q(o)*.01,t))}function Tn(s,e){return!s||s==="none"?0:s==="dot"?e*2:s==="halo-dot"?e*4:s==="arrow"||s==="arrow-plain"?e:0}function Wi(s,e){if(!s){s=T("g");const t=T("path");s.classList.add("annotation-arrow"),s.setAttribute("data-annotation",`${e}`),s.setAttribute("data-annotation-type","arrow"),s.appendChild(t);const n=T("g");n.classList.add("annotation-arrow-endpoints"),s.appendChild(n)}return s}function $i(s,e,t,n,i,r){const{start:o,end:a}=Ut(e),d=e.properties.style||gt,{tail:c,strokeWidth:l=0,head:u,strokeColor:h,strokeType:x}=d,g=Y(a,o),f=Fn(e)?1/r.zoom:1,p=zi(e,l,t,n)*f,y=Wi(i,e.id),A=y.firstChild,E=h||"none";A.setAttribute("stroke",E),A.setAttribute("stroke-width",`${f*l}`),A.setAttribute("fill","none"),A.setAttribute("stroke-linecap","round"),A.setAttribute("stroke-linejoin","round");const w=Tn(c,l*f),N=Tn(u,l*f),F=jt(g),C=ft(o,ot(F,w)),M=ft(a,ot(F,-N)),B=`M ${C.x} ${C.y} L ${M.x} ${M.y}`;A.setAttribute("d",B);const D=y.children[1];return D.innerHTML="",x==="dashed"?A.setAttribute("stroke-dasharray","5,10"):A.removeAttribute("stroke-dasharray"),On(D,o,g,E,c,l,f,p),On(D,a,ks(g),E,u,l,f,p),y.setAttribute("transform",`rotate(${-r.rotation*(180/Math.PI)})`),s.appendChild(y),y}function On(s,e,t,n,i,r,o,a){i==="halo-dot"&&Pn(s,e,Yi(n),_i,r*o*4),(i==="dot"||i==="halo-dot")&&Pn(s,e,n,1,r*o*2),(i==="arrow"||i==="arrow-plain")&&Xi(s,e,t,n,i==="arrow-plain",r*o,a)}function Yi(s){return s==="none"?"none":s}function Pn(s,e,t,n,i){const r=T("circle");r.setAttribute("cx",`${e.x}`),r.setAttribute("cy",`${e.y}`),r.setAttribute("r",`${i}`),r.setAttribute("fill-opacity",`${n}`),r.setAttribute("fill",t),s.appendChild(r)}function Xi(s,e,t,n,i,r,o){const a=ot(jt(t),o),d=ft(e,hn(a,Math.PI/6)),c=ft(e,hn(a,-Math.PI/6)),l=T("path"),u=`${e.x} ${e.y}`,h=`M ${d.x} ${d.y} L ${u} L ${c.x} ${c.y}${i?" Z":""}`;l.setAttribute("d",h),l.setAttribute("stroke",n),l.setAttribute("stroke-width",`${r}`),l.setAttribute("fill",i?n:"none"),l.setAttribute("stroke-linecap","round"),l.setAttribute("stroke-linejoin","round"),s.appendChild(l)}function Ui(s,e,t="box"){if(!s){s=T("g"),s.setAttribute("data-annotation",`${e}`),s.setAttribute("data-annotation-type",t),s.classList.add(`annotation-${t}`);const n=T("rect");s.appendChild(n)}return s}function Rn(s,e,t,n){const i=e.id,r=`class${i}`,o=X(e),a=Ui(t,i,e.properties.type),{strokeColor:d,strokeWidth:c,strokeType:l,background:u,borderRadius:h,boxShadow:x}=e.properties.style||Nt;a.classList.add("annotation-box"),a.setAttribute("fill",`${u||"transparent"}`);const g=a.firstChild;h&&(g.setAttribute("rx",`${h}`),g.setAttribute("ry",`${h}`)),l&&l!=="none"&&(g.setAttribute("stroke",d||"black"),g.setAttribute("stroke-width",`${c}`),l==="dashed"&&g.setAttribute("stroke-dasharray","5,5")),u&&u.length&&(n.hoveredFeature===e.id?g.setAttribute("fill",At(u)):g.setAttribute("fill",u));const f=xt(e);return g.setAttribute("width",`${o.width}`),g.setAttribute("height",`${o.height}`),g.setAttribute("x",`${f.x}`),g.setAttribute("y",`${f.y}`),a.appendChild(g),x?a.style.filter=`drop-shadow(${x})`:a.style.filter="",a.setAttribute("transform",n.getRotationTransform(0,0)),a.classList.add(r),a.setAttribute("data-annotation",`${e.id}`),a.setAttribute("data-annotation-type",e.properties.type),s.appendChild(a),a}function Gi(){const s=T("style");return s.textContent=`
6
+ </div>`,position:h,size:x,scaled:!this.fixedSize},c.LAYERS.EDITOR),this.textarea=this.layer.element.querySelector("textarea"),this.textarea.setAttribute("wrap","on"),this.textarea.setAttribute("spellcheck","false"),this.textarea.value=r.properties.content||"",a&&(this.sendButton=this.layer.element.querySelector(".ogma-send-button"),this.sendButton.addEventListener("click",this.onSendClick),this.updateSendButtonState()),this.isFocused=!1,this.textarea.addEventListener("focus",this.onFocus),this.textarea.addEventListener("blur",this.onBlur),this.textarea.addEventListener("input",this.onInput),this.textarea.addEventListener("keyup",this.onKeyup),this.textarea.addEventListener("keydown",this.onKeydown),this.textarea.addEventListener("wheel",this.onMouseEvent),this.textarea.addEventListener("mouseup",this.onMouseEvent),this.textarea.addEventListener("mousedown",this.onMouseEvent),this.textarea.addEventListener("click",this.onMouseEvent),this.textarea.addEventListener("drag",this.onMouseEvent),this.updateStyle(),this.updatePosition(),this.textarea.focus(),this.unsubscribe=this.store.subscribe(y=>({rotation:y.rotation,zoom:y.zoom,annotation:y.features[this.annotation]}),this.update,{equalityFn:(y,A)=>y.rotation===A.rotation&&y.zoom===A.zoom&&y.annotation===A.annotation})}getAnnotation(){const e=this.store.getState();e.liveUpdates[this.annotation]||e.startLiveUpdate([this.annotation]);const t=e.getFeature(this.annotation),n=e.liveUpdates[this.annotation];return t&&n?{...t,...n}:t}getPosition(){const e=this.getAnnotation();if(!e)return{x:0,y:0};const t=e.properties.style,n=t==null?void 0:t.maxHeight,s=this.store.getState().zoom,r=Vt(e),[o,a]=e.geometry.coordinates,u=e.properties.width;let l=e.properties.height;n&&(l=Math.min(l,n));const d=this.fixedSize?1/s:1;return{x:o-u*d/2+r*d,y:a-l*d/2+r*d}}getSize(){const e=this.getAnnotation();if(!e)return{width:0,height:0};const t=c.getBoxSize(e),n=Vt(e),s=e.properties.style,r=s==null?void 0:s.maxHeight;let o=t.height-n*2;return r&&(o=Math.min(o,r-n*2)),{width:t.width-n*2,height:o}}updateStyle(){var F;const e=this.getAnnotation();if(!e)return;const t=c.isComment(e)?c.defaultCommentStyle:c.defaultTextStyle,{font:n,fontSize:s=t.fontSize,borderRadius:r,color:o,background:a=t.background,padding:u=0,fixedSize:l=t.fixedSize}=e.properties.style||t,d=this.textarea,h=this.layer.element,x=1,f=parseFloat(s.toString())*x,g=u*x,p=h.style;if(p.display="grid",p.gridTemplateRows="1fr auto",p.boxSizing="border-box",p.background=a||"transparent",p.borderRadius=`${(r||0)*x}px`,p.padding=`${g}px`,p.transformOrigin="center",p.transform=`rotate(${this.store.getState().rotation}rad)`,e.properties.type==="comment"){const y=e.properties.style,A=(y==null?void 0:y.shadow)!==!1;p.boxShadow=A?"0 2px 8px rgba(0, 0, 0, 0.15)":"none"}const m=d.style;if(m.fontFamily=n||"sans-serif",m.fontSize=`${f}px`,m.lineHeight=`${f*c.TEXT_LINE_HEIGHT}px`,m.padding="0",m.border="none",m.outline="none",m.boxSizing="border-box",m.color=o||"black",m.background="transparent",m.flex="1",m.minHeight="0",m.resize="none",this.sendButton){const y=Fn*x,A=yn*x;this.sendButton.style.width=`${y}px`,this.sendButton.style.height=`${y}px`,this.sendButton.style.padding=`${A}px`,this.sendButton.style.transform="";const D=this.sendButton.querySelector(".ogma-send-button-icon");if(D){const C=An*x;D.style.width=`${C}px`,D.style.height=`${C}px`}}if(l){const y=(F=e.properties.style)==null?void 0:F.maxHeight,A=y&&e.properties.height>=y;m.overflowY=A?"auto":"hidden",m.overflowX="hidden"}}updatePosition(){this.layer.setPosition(this.getPosition())}updateContent(){var o,a,u,l;const e=this.getAnnotation();if(!e)return;let t=e.properties.height,n=e.geometry.coordinates;const s=(o=e.properties.style)==null?void 0:o.fixedSize;if(s){const d=this.textarea.style.height;this.textarea.style.height="0px";const h=this.textarea.scrollHeight;this.textarea.style.height=d;const x=((a=e.properties.style)==null?void 0:a.padding)||0,f=this.sendButton?parseFloat(this.sendButton.style.height||"0"):0,g=h+x*2+f,p=((u=e.properties.style)==null?void 0:u.minHeight)||Cn;t=Math.max(p,g);const m=(l=e.properties.style)==null?void 0:l.maxHeight,F=e.properties.height,y=t-F;if(!c.isComment(e)&&Math.abs(y)>1){const[D,C]=e.geometry.coordinates;if(m&&t>m){const E=m-F;t=m,Math.abs(E)>1&&(n=[D,C+E/2])}else n=[D,C+y/2]}else m&&t>m&&(t=m)}const r={...e,properties:{...e.properties,content:this.textarea.value,height:t},geometry:{...e.geometry,coordinates:n}};s&&Math.abs(e.properties.height-t)>1&&(this.layer.setSize(this.getSize()),this.layer.setPosition(this.getPosition())),this.store.getState().applyLiveUpdate(this.annotation,r)}updateSendButtonState(){if(!this.sendButton)return;const e=this.textarea.value.trim().length===0;this.sendButton.disabled=e}destroy(){this.store.getState().commitLiveUpdates(new Set([this.annotation])),this.unsubscribe(),this.sendButton&&this.sendButton.removeEventListener("click",this.onSendClick),this.layer.destroy()}}function Vt(i){var e;return((e=i.properties.style)==null?void 0:e.strokeWidth)||0}const jt={x:1,y:0},qt={x:0,y:1},Dn=[["top",qt,-.5,-.5,.5,-.5],["right",jt,.5,-.5,.5,.5],["bottom",qt,-.5,.5,.5,.5],["left",jt,-.5,-.5,-.5,.5]],Mn={top:[0,1],right:[1,2],bottom:[2,3],left:[3,0]},Kt=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]],wn=[c.cursors.nwResize,c.cursors.neResize,c.cursors.seResize,c.cursors.swResize],bn=100,Tn=50;class mt extends dt{constructor(t,n,s){super(t,n);S(this,"links");S(this,"textEditor",null);S(this,"justActivated",!1);S(this,"pendingDefaultSize",null);S(this,"autoEditAfterDrag",!1);S(this,"onClick",t=>{if(nt(t.target??null))return;const n=this.getAnnotation();if(n){if(c.isComment(n)&&n.properties.mode===c.COMMENT_MODE_COLLAPSED){this.store.getState().updateFeature(n.id,{properties:{...n.properties,mode:c.COMMENT_MODE_EXPANDED}}),this.ogma.view.afterNextFrame(),this.justActivated=!1;return}if(this.store.getState().selectedFeatures.has(n.id)){if(c.isComment(n)&&this.justActivated){this.justActivated=!1;return}n&&(c.isText(n)||c.isComment(n))&&this.startEditingText()}}});S(this,"stopEditingText",()=>{this.textEditor&&(this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null}),this.textEditor.destroy()),this.textEditor=null,this.store.setState({editingFeature:null})});this.links=s}detectHandle(t,n){var D;const s=this.getAnnotation(),{x:r,y:o}=this.clientToCanvas(t);let{width:a,height:u}=c.getBoxSize(s);const l=c.handleDetectionThreshold/n,d=c.getBoxCenter(s),h=this.store.getState();let{revSin:x,revCos:f}=h;(c.isBox(s)||c.isComment(s))&&(x=0,f=1),this.hoveredHandle=void 0;const g=c.handleRadius*(1/n),p=r-d.x,m=o-d.y,F=p*f-m*x,y=p*x+m*f,A=((D=s.properties.style)==null?void 0:D.fixedSize)===!0||c.isComment(s);if(A&&(a/=n,u/=n),!A){for(let C=0;C<Kt.length;C++){const[E,N]=Kt[C],M=a*E,B=u*N;if(F>=M-g-l&&F<=M+g+l&&y>=B-g-l&&y<=B+g+l){this.hoveredHandle={type:"corner",corner:C},this.store.setState({hoveredHandle:C,hoveredFeature:this.annotation}),this.setCursor(this.getCornerCursor(C));return}}for(const[C,E,N,M,B,b]of Dn){const T=a*N,L=u*M,O=a*B,R=u*b,w=c.dot(E,{x:F-T,y:y-L});if(Math.abs(w)<l&&F>=T-l&&F<=O+l&&y>=L-l&&y<=R+l){this.hoveredHandle={type:"edge",edge:C,corner:-1},this.store.setState({hoveredHandle:Mn[C][0]+4,hoveredFeature:this.annotation}),this.setCursor(this.getEdgeCursor(C));return}}}if(F>=-a/2-l&&F<=a/2+l&&y>=-u/2-l&&y<=u/2+l){this.store.setState({hoveredHandle:8,hoveredFeature:this.annotation}),this.hoveredHandle={type:"body",corner:-1},this.setCursor(c.cursors.grab);return}this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.setCursor(c.cursors.default)}onDrag(t){if(!this.dragStartPoint||!this.hoveredHandle||!this.isActive())return;t.stopPropagation(),t.stopImmediatePropagation();const n=this.getAnnotation(),s=this.clientToCanvas(t),r={x:s.x-this.dragStartPoint.x,y:s.y-this.dragStartPoint.y},o=this.hoveredHandle,a=this.getAnnotation();let u=null;o.type==="corner"?u=this.dragCorner(a,r,o.corner):o.type==="edge"&&o.edge?u=this.dragEdge(a,r,o):o.type==="body"&&(_t(this.store,this.links,n.id,r),this.textEditor&&this.textEditor.update()),u&&(this.store.getState().applyLiveUpdate(n.id,u),this.links.updateLinkedArrowsDuringDrag(n.id,r),this.textEditor&&this.textEditor.update()),this.dispatchEvent(new CustomEvent(c.EVT_DRAG,{detail:{point:s,annotation:this.annotation,handle:o}}))}dragCorner(t,n,s){const r=s===0||s===1,o=s===0||s===3,a=s===1||s===2,u=s===2||s===3,{width:l,height:d}=c.getBoxSize(t),h=this.store.getState();let{revSin:x,revCos:f}=h;(c.isBox(t)||c.isComment(t))&&(x=0,f=1);const g=n.x*f-n.y*x,p=n.x*x+n.y*f;let m=0,F=0;o?m=-g:a&&(m=g),r?F=-p:u&&(F=p);const y=Math.max(0,l+m),A=Math.max(0,d+F),D=c.getBoxCenter(t),C=D.x+n.x/2,E=D.y+n.y/2;return{...t,properties:{...t.properties,width:y,height:A},geometry:{type:t.geometry.type,coordinates:[C,E]}}}dragEdge(t,n,s){const{width:r,height:o}=c.getBoxSize(t),a=c.getBoxCenter(t),u=this.store.getState();let{revSin:l,revCos:d}=u;(c.isBox(t)||c.isComment(t))&&(l=0,d=1);const h=n.x*d-n.y*l,x=n.x*l+n.y*d;let f=r,g=o,p=0,m=0;switch(s.edge){case"top":g=Math.max(0,o-x),m=x/2;break;case"bottom":g=Math.max(0,o+x),m=x/2;break;case"left":f=Math.max(0,r-h),p=h/2;break;case"right":f=Math.max(0,r+h),p=h/2;break}const F=p*d+m*l,y=-p*l+m*d;return{...t,properties:{...t.properties,width:f,height:g},geometry:{type:t.geometry.type,coordinates:[a.x+F,a.y+y]}}}onDragStart(t){return super.onDragStart(t)?(this.stopEditingText(),this.store.getState().startLiveUpdate([this.annotation]),!0):!1}applyDefaultSizeIfEmpty(){var u;const t=this.pendingDefaultSize;this.pendingDefaultSize=null;const n=this.getAnnotation();if(!n||!(c.isBox(n)||c.isText(n))||(u=n.properties.style)!=null&&u.fixedSize||n.properties.width>0&&n.properties.height>0)return;const s=(t==null?void 0:t.width)??bn,r=(t==null?void 0:t.height)??Tn,[o,a]=n.geometry.coordinates;this.store.getState().updateFeature(n.id,{properties:{...n.properties,width:s,height:r},geometry:{...n.geometry,bbox:[o-s/2,a-r/2,o+s/2,a+r/2]}})}startEditingText(){this.textEditor===null&&(this.store.setState({editingFeature:this.annotation}),this.textEditor=new Nn(this.ogma,this.store,this.annotation,this.stopEditingText))}onDragEnd(t){var u,l;if(!super.onDragEnd(t))return!1;this.store.getState().drawingFeature===this.annotation&&this.store.setState({drawingFeature:null});const s=this.clientToCanvas(t),r=s.x-(((u=this.dragStartPoint)==null?void 0:u.x)||0),o=s.y-(((l=this.dragStartPoint)==null?void 0:l.y)||0),a=this.autoEditAfterDrag;if(this.autoEditAfterDrag=!1,Math.abs(r)<1&&Math.abs(o)<1)this.clearDragState(),this.applyDefaultSizeIfEmpty(),this.onClick({clientX:t.clientX,clientY:t.clientY});else{this.commitChange();const d=this.getAnnotation();a&&d&&(c.isText(d)||c.isComment(d))&&this.startEditingText()}return this.hoveredHandle=void 0,this.dragStartPoint=void 0,this.dragging=!1,!0}getCornerCursor(t){return wn[t]}getEdgeCursor(t){switch(t){case"top":case"bottom":return c.cursors.nsResize;case"left":case"right":return c.cursors.ewResize;default:return c.cursors.default}}stopEditing(){super.stopEditing(),this.commitChange(),this.stopEditingText()}startDrawing(t,n,s,r){this.annotation=t,this.pendingDefaultSize=(r==null?void 0:r.defaultSize)??null,this.autoEditAfterDrag=(r==null?void 0:r.autoEditAfterDrag)??!1,this.hoveredHandle={type:"corner",corner:2},this.store.setState({hoveredHandle:2,hoveredFeature:this.annotation}),this.dragging=!0;const o=this.ogma.view.graphToScreenCoordinates({x:n,y:s});this.dragStartPoint=o,this.disablePanning(),this.onDragStart({clientX:o.x,clientY:o.y})}setAnnotation(t){t&&c.isComment(t)&&(this.justActivated=!0),super.setAnnotation(t),t&&c.isComment(t)&&t.properties.mode===c.COMMENT_MODE_COLLAPSED&&this.store.getState().updateFeature(t.id,{properties:{...t.properties,mode:c.COMMENT_MODE_EXPANDED}})}}class Bn extends EventTarget{constructor(t,n,s,r,o){super();S(this,"handlers",new Map);S(this,"activeHandler");S(this,"interaction");S(this,"ogma");S(this,"snapping");S(this,"store");this.ogma=t,this.store=n,this.snapping=s,this.interaction=o,this.handlers.set("box",new mt(this.ogma,this.store,r)),this.handlers.set("text",new mt(this.ogma,this.store,r)),this.handlers.set("comment",new mt(this.ogma,this.store,r)),this.handlers.set("arrow",new mn(this.ogma,this.store,this.snapping,r)),this.handlers.set("polygon",new En(this.ogma,this.store,r)),this.handlers.forEach(a=>{a.addEventListener("dragstart",(u=>{this.dispatchEvent(new CustomEvent(c.EVT_DRAG_START,{detail:{...u.detail}})),this.store.setState({isDragging:!0}),this.interaction.setMode("edit")})),a.addEventListener("dragend",(u=>{this.dispatchEvent(new CustomEvent(c.EVT_DRAG_END,{detail:{...u.detail}})),this.store.setState({isDragging:!1}),this.interaction.suppressClicksTemporarily()}))}),this.store.subscribe(a=>a.selectedFeatures,(a,u)=>{const l=Array.from(a.keys()).filter(h=>!u.has(h)),d=Array.from(u.keys()).filter(h=>!a.has(h));!l.length&&!d.length||(d.forEach(h=>this.stopEditingFeature(h)),l.forEach(h=>this.editFeature(h)))})}stopEditingFeature(t){const n=this.store.getState().features[t];if(!n)return;const s=n.properties.type,r=this.handlers.get(s);r&&r.stopEditing()}editFeature(t){var s;const n=this.store.getState().features[t];n&&(this.setActiveHandler(n.properties.type),(s=this.activeHandler)==null||s.setAnnotation(n))}getSnapping(){return this.snapping}getArrowHandler(){return this.handlers.get("arrow")}getActiveHandler(){return this.activeHandler}setActiveHandler(t){const n=this.handlers.get(t);if(!n)throw new Error(`Handler for type ${t} not found`);return this.activeHandler=n,this}destroy(){}}function be(i,e,t,n,s){const r=e.get(n);if(!r)return;const o=s.side===c.SIDE_START?r.end:r.start;if(!o)return;const a=i.get(o);if(!(!a||a.targetType!==c.TARGET_TYPES.COMMENT))return wt(t,a)}function wt(i,e){if(!e||e.targetType!==c.TARGET_TYPES.COMMENT)return;const t=i.getState().getFeature(e.target);if(!(!t||!c.isComment(t))&&c.isRigidConnector(t))return t}function ct(i,e,t,n){const[s,r]=i.geometry.coordinates,o={...i,geometry:{type:"Point",coordinates:[s+e.x,r+e.y]}};t[i.id]=o,c.updateBbox(o),n.add(i.id)}const vn=.5;class kn{constructor(e,t){S(this,"ogma");S(this,"store");this.ogma=e,this.store=t}isLinkedToCenter(e){return e.magnet.type==="node"&&e.magnet.center}resolveLinkCenter(e,t,n,s){return e.targetType===c.TARGET_TYPES.NODE?t[n.get(e.target)]:e.targetType===c.TARGET_TYPES.EDGE?this.getEdgeSnapPoint(e.target,e.magnet.t,!0):this.getAnnotationCenter(s.getFeature(e.target))}resolveLinkPoint(e,t,n,s,r){if(e.targetType===c.TARGET_TYPES.NODE)return this.getNodeSnapPoint(t,n,this.isLinkedToCenter(e));if(e.targetType===c.TARGET_TYPES.EDGE)return this.getEdgeSnapPoint(e.target,e.magnet.t);const o=r.getMergedFeature(e.target);return this.getAnnotationSnapPoint(o,s,e,r.zoom)}getAnnotationCenter(e){return c.isPolygon(e)?vt(e):c.getBoxCenter(e)}getAnnotationSnapPoint(e,t,n,s){if(c.isPolygon(e)){const r=Bt(e),o=n.magnet,a=r[0]+o.rx*(r[2]-r[0]),u=r[1]+o.ry*(r[3]-r[1]);return[a,u]}return this.getBoxSnapPoint(e,t,n,s)}getBoxSnapPoint(e,t,n,s){var x;const r=c.getBoxCenter(e);let{width:o,height:a}=c.isComment(e)?c.getCommentSize(e):c.getBoxSize(e);(c.isText(e)&&((x=e.properties.style)==null?void 0:x.fixedSize)||c.isComment(e))&&(o/=s,a/=s);const l=n.magnet;let d=l.nx*o,h=l.ny*a;if(c.isText(e)&&!c.isBox(e)){const{sin:f,cos:g}=this.store.getState(),p=d*g-h*f,m=d*f+h*g;d=p,h=m}return[r.x+d,r.y+h]}getNodeSnapPoint(e,t,n){if(n)return[e.x,e.y];const s=Math.sqrt(t.x*t.x+t.y*t.y),r=c.mul(t,1/s),o=s<Number(e.radius)*vn?{x:e.x,y:e.y}:c.add({x:e.x,y:e.y},c.mul(r,-Number(e.radius)));return[o.x,o.y]}getEdgeSnapPoint(e,t,n=!1){const s=this.ogma.getEdge(e);if(!s)return[0,0];const r=s.getAttribute("curvature"),a=s.getExtremities().getPosition(),u=a[0],l=a[1];if(r===0||r===void 0){const x=[u.x+t*(l.x-u.x),u.y+t*(l.y-u.y)];return n?{x:x[0],y:x[1]}:x}const d=st.geometry.getQuadraticCurveControlPoint(u.x,u.y,l.x,l.y,r),h=st.geometry.getPointOnQuadraticCurve(t,u.x,u.y,l.x,l.y,d.x,d.y);return n?{x:h.x,y:h.y}:[h.x,h.y]}}function Ln(i,e){return e===c.TARGET_TYPES.NODE?{type:"node",center:i.x===0&&i.y===0}:e===c.TARGET_TYPES.EDGE?{type:"edge",t:i.x}:e===c.TARGET_TYPES.POLYGON?{type:"polygon",rx:i.x,ry:i.y}:{type:"box",nx:i.x,ny:i.y}}class On{constructor(e,t,n){S(this,"links",new Map);S(this,"nodeToLink",new Map);S(this,"edgeToLink",new Map);S(this,"annotationToLink",new Map);S(this,"linksByArrowId",new Map);S(this,"ogma");S(this,"store");S(this,"onLinkCreated");this.ogma=e,this.store=t,this.onLinkCreated=n}add(e,t,n,s,r,o="absolute"){const a=c.nanoid(),u=e.id;let l=r;if(s===c.TARGET_TYPES.POLYGON&&o==="absolute"){const f=this.store.getState().getFeature(n);if(f&&c.isPolygon(f)){const g=Bt(f),p=g[2]-g[0],m=g[3]-g[1],F=r.x-g[0],y=r.y-g[1],A=p>0?F/p:.5,D=m>0?y/m:.5;l={x:A,y:D}}}const d={id:a,arrow:u,target:n,targetType:s,magnet:Ln(l,s),side:t};if(s===c.TARGET_TYPES.NODE&&!this.ogma.getNode(n)||s===c.TARGET_TYPES.EDGE&&!this.ogma.getEdge(n))return;this.remove(e,t),this.links.set(a,d);const h=s===c.TARGET_TYPES.NODE?this.nodeToLink:s===c.TARGET_TYPES.EDGE?this.edgeToLink:this.annotationToLink;return h.has(n)||h.set(n,new Set),h.get(n).add(a),this.linksByArrowId.has(u)||this.linksByArrowId.set(u,{}),this.linksByArrowId.get(u)[t]=a,e.properties.link=e.properties.link||{},e.properties.link[t]={id:n,side:t,type:s,magnet:l},this.onLinkCreated&&this.onLinkCreated(e,d),this}remove(e,t){var o,a,u,l,d;const n=typeof e=="object"?e.id:e,s=(o=this.linksByArrowId.get(n))==null?void 0:o[t];if(typeof e=="object"&&((a=e.properties.link)==null||delete a[t]),!s)return this;const r=this.links.get(s);return r?(this.links.delete(s),(u=this.nodeToLink.get(r.target))==null||u.delete(s),(l=this.edgeToLink.get(r.target))==null||l.delete(s),(d=this.annotationToLink.get(r.target))==null||d.delete(s),this.linksByArrowId.has(n)&&(this.linksByArrowId.get(n)[t]=void 0),this):this}syncFromFeatureChange(e,t){const n=this.store.getState(),s=new Set(Object.keys(t)),r=Object.keys(e).filter(u=>!s.has(u)),o=Object.keys(t).filter(u=>!e[u]);r.forEach(u=>{var h,x;const l=n.getFeature(u);if(!l||!c.isArrow(l))return;const d=l;if((h=d.properties.link)!=null&&h.start){const f=d.properties.link.start;this.add(d,c.SIDE_START,f.id,f.type,f.magnet,"stored")}if((x=d.properties.link)!=null&&x.end){const f=d.properties.link.end;this.add(d,c.SIDE_END,f.id,f.type,f.magnet,"stored")}}),o.forEach(u=>{const l=t[u];if(c.isArrow(l)){const d=l;this.remove(d,c.SIDE_START),this.remove(d,c.SIDE_END)}else{const d=this.annotationToLink.get(u);if(!d)return;for(const h of d){const x=this.links.get(h);if(!x)continue;const f=n.getFeature(x.arrow);f?this.remove(f,x.side):this.remove(x.arrow,x.side)}}});const a=new Map;for(const u of s){const l=e[u];if(!l||!this.annotationToLink.has(u))continue;const d=t[u],h=d.geometry.coordinates!==l.geometry.coordinates,x=d.properties.width!==l.properties.width||d.properties.height!==l.properties.height;if(!h&&!x)continue;const f=this.annotationToLink.get(u);for(const g of f){const p=this.links.get(g);if(!p)continue;const m=p.arrow;this.linksByArrowId.has(m)&&a.set(m,this.linksByArrowId.get(m))}}return a}}const Pn=["x","y","radius"],Rn=1,_n=1,In=20;class Hn{constructor(e,t,n,s,r){S(this,"ogma");S(this,"store");S(this,"index");S(this,"geometry");S(this,"updatedItems");S(this,"commitTimeout");S(this,"nodePositionTimeout");S(this,"onSetMultipleAttributes",({elements:e,updatedAttributes:t})=>{const n=new Set(t);!e.isNode||!n.has("x")&&!n.has("y")&&!n.has("radius")||this.requestUpdateFromNodePositions(e.toList())});S(this,"refresh",()=>{const e=this.store.getState(),t=new Map;this.index.annotationToLink.forEach((n,s)=>{var a;const r=e.getFeature(s);if(!r)return;(c.isText(r)&&((a=r.properties.style)==null?void 0:a.fixedSize)||c.isComment(r))&&n.forEach(u=>{const l=this.index.links.get(u);if(!l)return;const d=l.arrow;t.set(d,this.index.linksByArrowId.get(d))})}),t.size>0&&this.update(t)});S(this,"throttledRefresh",c.throttle(()=>this.refresh(),In));S(this,"onAddRemoveEdges",e=>{const t=e.edges;if(!t.size||!this.index.edgeToLink.size)return;const n=new Map,s=new Map;t.getParallelEdges().getId().forEach(r=>{const o=this.index.edgeToLink.get(r);o&&o.forEach(a=>{const u=this.index.links.get(a);if(!u)return;const l=u.arrow;n.set(l,this.index.linksByArrowId.get(l)),s.set(l,this.index.linksByArrowId.get(l))})}),s.size!==0&&this.update(s)});S(this,"commit",()=>{this.store.getState().batchUpdate(this.commitLiveUpdates),this.updatedItems.clear()});S(this,"commitLiveUpdates",()=>{this.store.getState().commitLiveUpdates(this.updatedItems)});this.ogma=e,this.store=t,this.index=n,this.geometry=s,this.updatedItems=r,this.store.subscribe(o=>({zoom:o.zoom,rotation:o.rotation}),this.throttledRefresh,{equalityFn:(o,a)=>o.zoom===a.zoom&&o.rotation===a.rotation}),this.ogma.events.on("setMultipleAttributes",this.onSetMultipleAttributes).on(["addEdges","removeEdges"],this.onAddRemoveEdges).on("viewChanged",this.refresh)}requestUpdateFromNodePositions(e){clearTimeout(this.nodePositionTimeout),this.nodePositionTimeout=setTimeout(()=>this.updateFromNodePositions(e),_n)}updateFromNodePositions(e){if(!e.size)return;const t=e.getId(),n=new Map;t.forEach(l=>{const d=this.index.nodeToLink.get(l);d&&d.forEach(h=>{const x=this.index.links.get(h);if(!x)return;const f=x.arrow;n.set(f,this.index.linksByArrowId.get(f))})});const s=new Map;e.getAdjacentEdges().getId().forEach(l=>{const d=this.index.edgeToLink.get(l);d&&d.forEach(h=>{const x=this.index.links.get(h);if(!x)return;const f=x.arrow;n.set(f,this.index.linksByArrowId.get(f)),s.set(f,this.index.linksByArrowId.get(f))})});const o=e.getAttributes(Pn),a=this.store.getState(),u={};for(let l=0;l<t.length;l++){const d=t[l],h=this.index.nodeToLink.get(d);if(h)for(const x of h){const f=this.index.links.get(x);if(!f)continue;const g=f.arrow,p=this.store.getState().getFeature(g),m=p.geometry.coordinates.slice(),F=c.getArrowSide(p,c.SIDE_END),y=c.getArrowSide(p,c.SIDE_START),A=f.side===c.SIDE_START?0:1,D=o[l],C=this.geometry.getNodeSnapPoint(D,c.mul(c.subtract(F,y),-1),this.geometry.isLinkedToCenter(f)),E=be(this.index.links,this.index.linksByArrowId,this.store,g,f);if(E){const N=m[A],M=c.subtract({x:C[0],y:C[1]},{x:N[0],y:N[1]});m[0]=[m[0][0]+M.x,m[0][1]+M.y],m[1]=[m[1][0]+M.x,m[1][1]+M.y],ct(E,M,u,this.updatedItems)}else m[A]=C;u[g]={...p,geometry:{coordinates:m}},this.updatedItems.add(g),c.updateBbox(u[g])}}if(a.applyLiveUpdates(u),s.size>0){this.update(s);return}this.requestCommit()}update(e=this.index.linksByArrowId){const t=this._computeArrowUpdates(e);this.store.getState().applyLiveUpdates(t),this.requestCommit()}updateAndCommitSync(e){const t=this._computeArrowUpdates(e);if(Object.keys(t).length===0)return;const n=this.store.getState();n.batchUpdate(()=>{n.updateFeatures(t)})}_computeArrowUpdates(e){const t=this.store.getState(),n=Array.from(this.index.nodeToLink.keys()),s=new Map;n.forEach((u,l)=>s.set(u,l));const o=this.ogma.getNodes(n).getAttributes(["x","y","radius"]),a={};return e.forEach((u,l)=>{const d=this.index.links.get(u.start),h=this.index.links.get(u.end),x=t.getFeature(l);let f=x.geometry.coordinates[0],g=x.geometry.coordinates[1];const p=d?this.geometry.resolveLinkCenter(d,o,s,t):{x:f[0],y:f[1]},m=h?this.geometry.resolveLinkCenter(h,o,s,t):{x:g[0],y:g[1]},F=c.subtract(m,p);d&&(f=this.geometry.resolveLinkPoint(d,p,F,m,t)),h&&(g=this.geometry.resolveLinkPoint(h,m,c.mul(F,-1),p,t));const y=wt(this.store,d),A=wt(this.store,h);if(y&&h){const D=x.geometry.coordinates[1],C={x:g[0]-D[0],y:g[1]-D[1]};if(C.x!==0||C.y!==0){const E=x.geometry.coordinates[0];f=[E[0]+C.x,E[1]+C.y],ct(y,C,a,this.updatedItems)}}else if(A&&d){const D=x.geometry.coordinates[0],C={x:f[0]-D[0],y:f[1]-D[1]};if(C.x!==0||C.y!==0){const E=x.geometry.coordinates[1];g=[E[0]+C.x,E[1]+C.y],ct(A,C,a,this.updatedItems)}}a[x.id]={properties:x.properties,geometry:{coordinates:[f,g]}},c.updateBbox(a[x.id]),this.updatedItems.add(x.id)}),a}requestCommit(){clearTimeout(this.commitTimeout),this.commitTimeout=setTimeout(this.commit,Rn)}destroy(){clearTimeout(this.commitTimeout),clearTimeout(this.nodePositionTimeout),this.ogma.events.off(this.onSetMultipleAttributes).off(this.onAddRemoveEdges).off(this.refresh)}}class Gn{constructor(e,t,n,s){S(this,"registry");S(this,"geometry");S(this,"sync");S(this,"store");S(this,"snapping");S(this,"updatedItems",new Set);S(this,"refresh",()=>this.sync.refresh());S(this,"onAddArrow",(e,t)=>{const n=this.registry.syncFromFeatureChange(e,t);n.size>0&&this.sync.updateAndCommitSync(n)});this.store=n,this.snapping=t,this.registry=new On(e,n,s),this.geometry=new kn(e,n),this.sync=new Hn(e,n,this.registry,this.geometry,this.updatedItems),this.store.subscribe(r=>r.features,this.onAddArrow)}updateLinkedArrowsDuringDrag(e,t,n){const s=n??{};this._collectLinkedArrowUpdates(e,t,s,new Set),n||this.store.getState().applyLiveUpdates(s)}_collectLinkedArrowUpdates(e,t,n,s){var l;if(s.has(e))return;s.add(e);const r=this.store.getState();if(!r.getFeature(e))return;const a=this.registry.annotationToLink.get(e);if(!a)return;const u=new Set;for(const d of a){const h=this.registry.links.get(d);if(!h)continue;const x=r.getFeature(h.arrow);if(!x)continue;const f=n[h.arrow],g=((l=f==null?void 0:f.geometry)==null?void 0:l.coordinates)??x.geometry.coordinates,p=h.side===c.SIDE_START?0:1,m={x:g[p][0],y:g[p][1]},F=c.add(m,t),y={...x.geometry,coordinates:g.map((D,C)=>C===p?[F.x,F.y]:[...D])};n[h.arrow]={geometry:y},this.updatedItems.add(h.arrow);const A=be(this.registry.links,this.registry.linksByArrowId,this.store,h.arrow,h);A&&!s.has(A.id)&&u.add(A.id)}for(const d of u){const h=r.getFeature(d);h&&(ct(h,t,n,this.updatedItems),this._collectLinkedArrowUpdates(d,t,n,s))}}snapLinkedArrowsDuringDrag(e,t){const n=this.store.getState();let s=n.getFeature(e);if(!s)return;const r=n.liveUpdates[e];s=r?{...s,...r}:s;const o=this.registry.annotationToLink.get(e);if(o)for(const a of o){const u=this.registry.links.get(a);if(!u)continue;let l=n.getFeature(u.arrow);const d=n.liveUpdates[l.id];l=d?{...l,...d}:l;const h=l.geometry.coordinates[u.side===c.SIDE_START?0:1],x={x:h[0],y:h[1]};let f;if(c.isText(s)||c.isComment(s)||c.isBox(s)?f=this.snapping.snapToText(x,[s]):c.isPolygon(s)&&(f=this.snapping.snapToPolygon(x,[s])),!f)continue;const g=f.point,p={...l.geometry,coordinates:l.geometry.coordinates.map((m,F)=>u.side===c.SIDE_START&&F===0||u.side===c.SIDE_END&&F===1?[g.x,g.y]:[...m])};t?t[l.id]={geometry:p}:n.applyLiveUpdate(l.id,{geometry:p})}}add(e,t,n,s,r,o="absolute"){return this.registry.add(e,t,n,s,r,o)?this:void 0}remove(e,t){return this.registry.remove(e,t),this}update(e){this.sync.update(e)}destroy(){this.sync.destroy()}}function zn(i,e,t,n,s=20){let r=0,o=1/0,a=null;for(let u=0;u<=s;u++){const l=u/s,d=st.geometry.getPointOnQuadraticCurve(l,e.x,e.y,t.x,t.y,n.x,n.y),h=c.length(c.subtract(d,i));h<o&&(o=h,a=d,r=l)}return a?{t:r,point:a,distance:o}:null}function Yn(i,e,t){const n=t.x-e.x,s=t.y-e.y,r=n*n+s*s;if(r===0)return{t:0,point:{x:e.x,y:e.y},distance:c.length(c.subtract(e,i))};const o=Math.max(0,Math.min(1,((i.x-e.x)*n+(i.y-e.y)*s)/r)),a={x:e.x+o*n,y:e.y+o*s};return{t:o,point:a,distance:c.length(c.subtract(a,i))}}function Wn(i,e,t){let n=null,s=t;const r=e.getAttribute("curvature"),a=e.getExtremities().getPosition();for(let u=0;u<e.size;u++){const l=e.get(u),d=r[u],h=a[2*u],x=a[2*u+1];let f;if(d===0||d===void 0)f=Yn(i,h,x);else{const g=st.geometry.getQuadraticCurveControlPoint(h.x,h.y,x.x,x.y,d);f=zn(i,h,x,g)}f&&f.distance<s&&(s=f.distance,n={point:f.point,id:l.getId(),magnet:{x:f.t,y:0},type:c.TARGET_TYPES.EDGE})}return n}function Un(i,e,t){const n=e.getAttributes(["x","y","radius"]);for(let s=0;s<n.length;s++){const r=n[s],o=c.subtract({x:r.x,y:r.y},i),a=c.length(o);if(a>=Number(r.radius)+Number(t))continue;const u=c.mul(o,1/a),l=a<Number(r.radius)/2,d=l?{x:r.x,y:r.y}:c.add({x:r.x,y:r.y},c.mul(u,-Number(r.radius))),h=l?{x:0,y:0}:u;return{point:d,id:e.get(s).getId(),magnet:h,type:c.TARGET_TYPES.NODE}}return null}function $n(i,e){let t=!1;for(let n=0,s=e.length-1;n<e.length;s=n++){const r=e[n][0],o=e[n][1],a=e[s][0],u=e[s][1];o>i.y!=u>i.y&&i.x<(a-r)*(i.y-o)/(u-o)+r&&(t=!t)}return t}function Xn(i,e,t,n,s){const r=i*i,o=r*i,a=1-i,u=a*a,l=u*a;return{x:l*e.x+3*u*i*t.x+3*a*r*n.x+o*s.x,y:l*e.y+3*u*i*t.y+3*a*r*n.y+o*s.y}}function Vn(i,e,t,n,s){let r=1/0,o=null;const a=20;for(let u=0;u<=a;u++){const l=u/a,d=Xn(l,e,t,n,s),h=c.length(c.subtract(d,i));h<r&&(r=h,o=d)}return o?{point:o,distance:r}:null}function jn(i,e,t){const n=e.geometry.coordinates[0];for(let s=0;s<n.length-1;s++){const[r,o]=n[s];if(c.length(c.subtract({x:r,y:o},i))<t)return{point:{x:r,y:o},magnet:{x:r,y:o},type:c.TARGET_TYPES.POLYGON,id:e.id}}for(let s=0;s<n.length-1;s++){const[r,o]=n[s],[a,u]=n[s+1],l={x:r,y:o},d={x:a,y:u},h=c.subtract(d,l),x=c.length(h),f={x:h.x/x,y:h.y/x},g={x:-f.y,y:f.x},p=c.subtract(i,l),m=Math.abs(c.dot(g,p)),F=c.dot(f,p);if(F>=0&&F<=x&&m<t){const y={x:l.x+f.x*F,y:l.y+f.y*F};return{point:y,magnet:y,type:c.TARGET_TYPES.POLYGON,id:e.id}}}return null}function qn(i,e,t){for(const s of e){const o=s.geometry.coordinates[0].slice(0,-1);if(o.length<3)return jn(i,s,t);for(let d=0;d<o.length;d++){const[h,x]=o[d];if(c.length(c.subtract({x:h,y:x},i))<t)return{point:{x:h,y:x},magnet:{x:h,y:x},type:c.TARGET_TYPES.POLYGON,id:s.id}}const a=$n(i,o);let u=null,l=a?1/0:t;for(let d=0;d<o.length;d++){const h=o[(d-1+o.length)%o.length],x=o[d],f=o[(d+1)%o.length],g=o[(d+2)%o.length],p=x[0]+(f[0]-h[0])/6*.5,m=x[1]+(f[1]-h[1])/6*.5,F=f[0]-(g[0]-x[0])/6*.5,y=f[1]-(g[1]-x[1])/6*.5,A=Vn(i,{x:x[0],y:x[1]},{x:p,y:m},{x:F,y},{x:f[0],y:f[1]});if(A){const D=A.distance;if(a)D<l&&(l=D,u=A.point);else if(D<t)return{point:A.point,magnet:A.point,type:c.TARGET_TYPES.POLYGON,id:s.id}}}if(a&&u)return{point:u,magnet:u,type:c.TARGET_TYPES.POLYGON,id:s.id}}return null}const Te=[{x:-.5,y:-.5},{x:0,y:-.5},{x:.5,y:-.5},{x:-.5,y:0},{x:.5,y:0},{x:-.5,y:.5},{x:0,y:.5},{x:.5,y:.5},{x:0,y:0}],Kn=[[-.5,-.5,.5,-.5],[.5,-.5,.5,.5],[.5,.5,-.5,.5],[-.5,.5,-.5,-.5]];function Zt(i,e,t,n,s,r,o,a,u){const l=i*s,d=e*r;return u?{x:t+(l*o-d*a),y:n+(l*a+d*o)}:{x:t+l,y:n+d}}function Zn(i,e,t,n,s){var d;const r=c.getBoxCenter(e);let{width:o,height:a}=c.getBoxSize(e);const{sin:u,cos:l}=s.getState();(d=e.properties.style)!=null&&d.fixedSize&&(o/=t,a/=t);for(const h of Te){let x=h.x*o,f=h.y*a;if(!c.isBox(e)){const m=x*l-f*u,F=x*u+f*l;x=m,f=F}const g={x:r.x+x,y:r.y+f};if(!(c.length(c.subtract(g,i))>=n))return{point:{x:g.x,y:g.y},type:c.TARGET_TYPES.TEXT,magnet:h,id:e.id}}return null}function Jn(i,e,t,n,s){var g;const{x:r,y:o}=c.getBoxCenter(e);let{width:a,height:u}=c.getBoxSize(e);(g=e.properties.style)!=null&&g.fixedSize&&(a/=t,u/=t);const{sin:l,cos:d}=s.getState(),h=!c.isBox(e);let x=null,f=1/0;for(let p=0;p<4;p++){const[m,F,y,A]=Kn[p],D=Zt(m,F,r,o,a,u,d,l,h),C=Zt(y,A,r,o,a,u,d,l,h),E=c.subtract(C,D),N=c.length(E),M={x:E.x/N,y:E.y/N},B={x:-M.y,y:M.x},b=c.subtract(i,D),T=c.dot(B,b),L=c.dot(M,b);if(L>=0&&L<=N){const O=Math.abs(T);if(O<n||O<f){const R=L/N,w={point:{x:D.x+M.x*L,y:D.y+M.y*L},magnet:{x:m+(y-m)*R,y:F+(A-F)*R},type:c.TARGET_TYPES.TEXT,id:e.id};if(O<n)return w;O<f&&(f=O,x=w)}}}return x&&f<Math.max(a,u)?x:null}function Qn(i,e,t,n,s){for(const r of e){const o=Zn(i,r,t,n,s)||Jn(i,r,t,n,s);if(o)return o}return null}class ts extends EventTarget{constructor(t,n,s,r){super();S(this,"ogma");S(this,"options");S(this,"spatialIndex");S(this,"hoveredNode",null);S(this,"store");this.ogma=t,this.options=n,this.spatialIndex=s,this.store=r}snap(t){const n=this.findMagnet(t);return n||null}findMagnet(t){const n=this.options.detectMargin,s={minX:t.x-n,minY:t.y-n,maxX:t.x+n,maxY:t.y+n},r=this.spatialIndex.search(s),o=r.filter(g=>c.isText(g)||c.isBox(g)),a=r.filter(g=>c.isPolygon(g)),{nodes:u,edges:l}=this.ogma.view.getElementsInside(s.minX,s.minY,s.maxX,s.maxY),d=this.snapToNodes(t,u);if(d)return d;const h=this.snapToEdges(t,l);if(h)return h;const x=this.snapToText(t,o);if(x)return x;const f=this.snapToPolygon(t,a);return f||null}snapToText(t,n){const{zoom:s}=this.store.getState();return Qn(t,n,s,this.options.magnetRadius,this.store)}snapToPolygon(t,n){return qn(t,n,this.options.magnetRadius)}snapToNodes(t,n){return Un(t,n,this.options.detectMargin)}snapToEdges(t,n){return Wn(t,n,this.options.magnetRadius)}getHoveredNode(){return this.hoveredNode}clearHoveredNode(){var t;(t=this.hoveredNode)==null||t.setSelected(!1),this.hoveredNode=null}getMagnets(){return Te}}class es extends EventTarget{constructor(t,n,s){super();S(this,"query",{minX:1/0,minY:1/0,maxX:1/0,maxY:1/0});S(this,"suppressClickUntil",0);S(this,"mouseDownState",null);S(this,"DRAG_THRESHOLD",3);S(this,"onNativeDragStart",()=>{this.store.getState().setHoveredFeature(null),this.store.setState({isDragging:!0})});S(this,"onNativeDragEnd",()=>{this.store.setState({isDragging:!1})});S(this,"onMouseMove",t=>{const n=c.clientToContainerPosition(t,this.ogma.getContainer()),s=this.store.getState();if(this.mouseDownState&&!s.isDragging){const d=t.clientX-this.mouseDownState.screenX,h=t.clientY-this.mouseDownState.screenY;Math.sqrt(d*d+h*h)>this.DRAG_THRESHOLD&&(this.mouseDownState.hasMoved=!0)}if(s.isDragging)return;const{x:r,y:o}=this.ogma.view.screenToGraphCoordinates(n),a=this.detect(r,o),u=(a==null?void 0:a.id)??null,l=s.hoveredFeature;u!==l&&s.setHoveredFeature(u),this.setCursor(u===null?c.cursors.default:c.cursors.pointer)});S(this,"onMouseClick",()=>{Date.now()<this.suppressClickUntil});S(this,"onMouseDownArm",t=>{if(Date.now()<this.suppressClickUntil||nt(t.target))return;const n=c.clientToContainerPosition(t,this.ogma.getContainer()),{x:s,y:r}=this.ogma.view.screenToGraphCoordinates(n);this.store.setState({mousePressed:!0,mousePressPoint:{x:s,y:r}})});S(this,"onMouseDown",t=>{if(Date.now()<this.suppressClickUntil)return;if(nt(t.target)){this.mouseDownState=null;return}const n=c.clientToContainerPosition(t,this.ogma.getContainer()),{x:s,y:r}=this.ogma.view.screenToGraphCoordinates(n),o=this.detect(s,r);this.mouseDownState={annotation:o,screenX:t.clientX,screenY:t.clientY,hasMoved:!1};const a=this.store.getState();o&&!a.selectedFeatures.has(o.id)&&(t.ctrlKey||t.metaKey?a.toggleSelection(o.id):a.setSelectedFeatures([o.id]))});S(this,"onMouseUp",t=>{const n=this.store.getState();if(this.store.setState({mousePressed:!1,mousePressPoint:null}),nt(t.target)){this.mouseDownState=null;return}if(this.mouseDownState&&!this.mouseDownState.hasMoved&&!n.isDragging){const s=this.mouseDownState.annotation;s?t.ctrlKey||t.metaKey?n.toggleSelection(s.id):n.selectedFeatures.has(s.id)||n.setSelectedFeatures([s.id]):!t.ctrlKey&&!t.metaKey&&n.clearSelection(),this.dispatchEvent(new CustomEvent(c.EVT_CLICK,{detail:{id:(s==null?void 0:s.id)??null,position:{x:t.clientX,y:t.clientY}}}))}this.mouseDownState=null});S(this,"onWheel",t=>{var h;if(t.target instanceof HTMLTextAreaElement)return;const n=c.clientToContainerPosition(t,this.ogma.getContainer()),{x:s,y:r}=this.ogma.view.screenToGraphCoordinates(n),o=this.detect(s,r);if(!o||!c.isComment(o))return;const a=(h=o.properties.style)==null?void 0:h.maxHeight,u=o.properties.height;if(!a||u<=a)return;const l=this.ogma.getContainer(),d=l==null?void 0:l.querySelector(`[data-annotation="${o.id}"] .comment-box foreignObject div`);d&&(t.stopPropagation(),t.preventDefault(),d.scrollTop+=t.deltaY)});this.ogma=t,this.store=n,this.index=s;const r=this.ogma.getContainer();r&&(r.addEventListener("mousemove",this.onMouseMove,{passive:!0,capture:!0}),r.addEventListener("click",this.onMouseClick,{passive:!0,capture:!0}),r.addEventListener("mousedown",this.onMouseDownArm,{passive:!0,capture:!0}),r.addEventListener("mousedown",this.onMouseDown,{passive:!0,capture:!1}),r.addEventListener("mouseup",this.onMouseUp,{passive:!0,capture:!0}),r.addEventListener("wheel",this.onWheel,{passive:!1,capture:!0})),this.ogma.events.on("nodesDragStart",this.onNativeDragStart),this.ogma.events.on("nodesDragEnd",this.onNativeDragEnd)}detect(t,n,s){let r=null;const o=this.store.getState(),a=s??o.options.detectMargin;this.query.minX=t-a,this.query.minY=n-a,this.query.maxX=t+a,this.query.maxY=n+a;const u=this.index.query(this.query);if(u.length===0)return null;const l={arrow:0,comment:1,text:1,box:2,polygon:2},d=[...u].sort((h,x)=>(l[h.properties.type]??9)-(l[x.properties.type]??9));for(const h of d){const x=o.getFeature(h.id);if(c.isArrow(x)){if(c.detectArrow(x,{x:t,y:n},a)){r=x;break}}else if(c.isBox(x)){if(c.detectBox(x,{x:t,y:n},0,1,a)){r=x;break}}else if(c.isPolygon(x)){if(c.detectPolygon(x,{x:t,y:n},a)){r=x;break}}else if(c.isComment(x)){if(c.detectComment(x,{x:t,y:n},a,o.sin,o.cos,o.zoom)){r=x;break}}else if(c.isText(x)&&c.detectText(x,{x:t,y:n},a,o.revSin,o.revCos,o.zoom)){r=x;break}}return r}setCursor(t){var s;const n=(s=this.ogma.getContainer())==null?void 0:s.firstChild;n&&(n.style.cursor=t)}setMode(t){var n;t==="default"?this.setCursor(((n=this.ogma.getOptions().cursor)==null?void 0:n.default)||"default"):t==="add"||t==="link"?this.setCursor(c.cursors.crosshair):t==="rotate"&&this.setCursor(c.cursors.alias)}suppressClicksTemporarily(t=100){this.suppressClickUntil=Date.now()+t}destroy(){const t=this.ogma.getContainer();t&&(t.removeEventListener("mousemove",this.onMouseMove,!0),t.removeEventListener("click",this.onMouseClick,!0),t.removeEventListener("mousedown",this.onMouseDownArm,!0),t.removeEventListener("mousedown",this.onMouseDown,!1),t.removeEventListener("mouseup",this.onMouseUp,!0),t.removeEventListener("wheel",this.onWheel,!0)),this.ogma.events.off(this.onNativeDragStart),this.ogma.events.off(this.onNativeDragEnd)}}function Be(i,e,t=0,n=i.length-1,s=ns){for(;n>t;){if(n-t>600){const u=n-t+1,l=e-t+1,d=Math.log(u),h=.5*Math.exp(2*d/3),x=.5*Math.sqrt(d*h*(u-h)/u)*(l-u/2<0?-1:1),f=Math.max(t,Math.floor(e-l*h/u+x)),g=Math.min(n,Math.floor(e+(u-l)*h/u+x));Be(i,e,f,g,s)}const r=i[e];let o=t,a=n;for(Z(i,t,e),s(i[n],r)>0&&Z(i,t,n);o<a;){for(Z(i,o,a),o++,a--;s(i[o],r)<0;)o++;for(;s(i[a],r)>0;)a--}s(i[t],r)===0?Z(i,t,a):(a++,Z(i,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function Z(i,e,t){const n=i[e];i[e]=i[t],i[t]=n}function ns(i,e){return i<e?-1:i>e?1:0}class ss{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const n=[];if(!at(e,t))return n;const s=this.toBBox,r=[];for(;t;){for(let o=0;o<t.children.length;o++){const a=t.children[o],u=t.leaf?s(a):a;at(e,u)&&(t.leaf?n.push(a):Et(e,u)?this._all(a,n):r.push(a))}t=r.pop()}return n}collides(e){let t=this.data;if(!at(e,t))return!1;const n=[];for(;t;){for(let s=0;s<t.children.length;s++){const r=t.children[s],o=t.leaf?this.toBBox(r):r;if(at(e,o)){if(t.leaf||Et(e,o))return!0;n.push(r)}}t=n.pop()}return!1}load(e){if(!(e&&e.length))return this;if(e.length<this._minEntries){for(let n=0;n<e.length;n++)this.insert(e[n]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(!this.data.children.length)this.data=t;else if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const n=this.data;this.data=t,t=n}this._insert(t,this.data.height-t.height-1,!0)}return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=K([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),r=[],o=[];let a,u,l;for(;n||r.length;){if(n||(n=r.pop(),u=r[r.length-1],a=o.pop(),l=!0),n.leaf){const d=is(e,n.children,t);if(d!==-1)return n.children.splice(d,1),r.push(n),this._condense(r),this}!l&&!n.leaf&&Et(n,s)?(r.push(n),o.push(a),a=0,u=n,n=n.children[0]):u?(a++,n=u.children[a],l=!1):n=null}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,s){const r=n-t+1;let o=this._maxEntries,a;if(r<=o)return a=K(e.slice(t,n+1)),V(a,this.toBBox),a;s||(s=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,s-1))),a=K([]),a.leaf=!1,a.height=s;const u=Math.ceil(r/o),l=u*Math.ceil(Math.sqrt(o));Jt(e,t,n,l,this.compareMinX);for(let d=t;d<=n;d+=l){const h=Math.min(d+l-1,n);Jt(e,d,h,u,this.compareMinY);for(let x=d;x<=h;x+=u){const f=Math.min(x+u-1,h);a.children.push(this._build(e,x,f,s-1))}}return V(a,this.toBBox),a}_chooseSubtree(e,t,n,s){for(;s.push(t),!(t.leaf||s.length-1===n);){let r=1/0,o=1/0,a;for(let u=0;u<t.children.length;u++){const l=t.children[u],d=St(l),h=as(e,l)-d;h<o?(o=h,r=d<r?d:r,a=l):h===o&&d<r&&(r=d,a=l)}t=a||t.children[0]}return t}_insert(e,t,n){const s=n?e:this.toBBox(e),r=[],o=this._chooseSubtree(s,this.data,t,r);for(o.children.push(e),et(o,s);t>=0&&r[t].children.length>this._maxEntries;)this._split(r,t),t--;this._adjustParentBBoxes(s,r,t)}_split(e,t){const n=e[t],s=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,s);const o=this._chooseSplitIndex(n,r,s),a=K(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,V(n,this.toBBox),V(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=K([e,t]),this.data.height=e.height+1,this.data.leaf=!1,V(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let s,r=1/0,o=1/0;for(let a=t;a<=n-t;a++){const u=tt(e,0,a,this.toBBox),l=tt(e,a,n,this.toBBox),d=cs(u,l),h=St(u)+St(l);d<r?(r=d,s=a,o=h<o?h:o):d===r&&h<o&&(o=h,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:rs,r=e.leaf?this.compareMinY:os,o=this._allDistMargin(e,t,n,s),a=this._allDistMargin(e,t,n,r);o<a&&e.children.sort(s)}_allDistMargin(e,t,n,s){e.children.sort(s);const r=this.toBBox,o=tt(e,0,t,r),a=tt(e,n-t,n,r);let u=ot(o)+ot(a);for(let l=t;l<n-t;l++){const d=e.children[l];et(o,e.leaf?r(d):d),u+=ot(o)}for(let l=n-t-1;l>=t;l--){const d=e.children[l];et(a,e.leaf?r(d):d),u+=ot(a)}return u}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)et(t[s],e)}_condense(e){for(let t=e.length-1,n;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children,n.splice(n.indexOf(e[t]),1)):this.clear():V(e[t],this.toBBox)}}function is(i,e,t){if(!t)return e.indexOf(i);for(let n=0;n<e.length;n++)if(t(i,e[n]))return n;return-1}function V(i,e){tt(i,0,i.children.length,e,i)}function tt(i,e,t,n,s){s||(s=K(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let r=e;r<t;r++){const o=i.children[r];et(s,i.leaf?n(o):o)}return s}function et(i,e){return i.minX=Math.min(i.minX,e.minX),i.minY=Math.min(i.minY,e.minY),i.maxX=Math.max(i.maxX,e.maxX),i.maxY=Math.max(i.maxY,e.maxY),i}function rs(i,e){return i.minX-e.minX}function os(i,e){return i.minY-e.minY}function St(i){return(i.maxX-i.minX)*(i.maxY-i.minY)}function ot(i){return i.maxX-i.minX+(i.maxY-i.minY)}function as(i,e){return(Math.max(e.maxX,i.maxX)-Math.min(e.minX,i.minX))*(Math.max(e.maxY,i.maxY)-Math.min(e.minY,i.minY))}function cs(i,e){const t=Math.max(i.minX,e.minX),n=Math.max(i.minY,e.minY),s=Math.min(i.maxX,e.maxX),r=Math.min(i.maxY,e.maxY);return Math.max(0,s-t)*Math.max(0,r-n)}function Et(i,e){return i.minX<=e.minX&&i.minY<=e.minY&&e.maxX<=i.maxX&&e.maxY<=i.maxY}function at(i,e){return e.minX<=i.maxX&&e.minY<=i.maxY&&e.maxX>=i.minX&&e.maxY>=i.minY}function K(i){return{children:i,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Jt(i,e,t,n,s){const r=[e,t];for(;r.length;){if(t=r.pop(),e=r.pop(),t-e<=n)continue;const o=e+Math.ceil((t-e)/n/2)*n;Be(i,o,e,t,s),r.push(e,o,o,t)}}const J={minX:0,minY:0,maxX:0,maxY:0},Qt=(i,e)=>i.id===e.id;class ls extends ss{constructor(t){super();S(this,"store");S(this,"onRotationChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>c.isText(n)||c.isComment(n));for(const n of t)this.updateRotatedText(n)});S(this,"onZoomChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>{var s;return(c.isText(n)||c.isComment(n))&&((s=n.properties.style)==null?void 0:s.fixedSize)});for(const n of t)this.updateRotatedText(n)});this.store=t,this.store.subscribe(n=>n.features,n=>{this.clear(),Object.values(n).forEach(s=>{c.isText(s)||c.isComment(s)?this.updateRotatedText(s):this.insert(s)})}),this.store.subscribe(n=>({features:n.features,isDragging:n.isDragging,lastChangedFeatures:n.lastChangedFeatures,rotation:n.rotation}),(n,s)=>{s&&s.isDragging&&!n.isDragging&&n.lastChangedFeatures.length>0&&n.lastChangedFeatures.forEach(r=>{const o=n.features[r];o&&(c.updateBbox(o),c.isText(o)||c.isComment(o)?this.updateRotatedText(o):(this.remove(o,Qt),this.insert(o)))})},{equalityFn:(n,s)=>n.isDragging===s.isDragging}),this.store.subscribe(n=>n.rotation,this.onRotationChange),this.store.subscribe(n=>n.zoom,this.onZoomChange)}updateRotatedText(t){var h;const n=this.store.getState();this.remove(t,Qt);const s=c.getBoxCenter(t);let{width:r,height:o}=c.getBoxSize(t);if(((h=t.properties.style)==null?void 0:h.fixedSize)===!0){const x=n.invZoom;r*=x,o*=x}const u=r/2,l=o/2,d=n.getRotatedBBox(s.x-u,s.y-l,s.x+u,s.y+l);this.insert({...t,geometry:{...t.geometry,bbox:d.slice()}})}compareMinX(t,n){return c.getBbox(t)[0]-c.getBbox(n)[0]}compareMinY(t,n){return c.getBbox(t)[1]-c.getBbox(n)[1]}toBBox(t){const n=c.getBbox(t);return J.minX=n[0],J.minY=n[1],J.maxX=n[2],J.maxY=n[3],J}query(t){return super.search(t)}}class ve{constructor(e,t){S(this,"layer");this.ogma=e,this.store=t}destroy(){}}const te=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]];class ds extends ve{constructor(t,n){super(t,n);S(this,"handleFill","#fff");S(this,"handleStroke","#1A70E5");S(this,"handleStrokeWidth",1.5);S(this,"handleRadius",3);S(this,"handleMagnifier",1.5);S(this,"refresh",()=>{this.layer.refresh()});S(this,"render",t=>{const n=this.store.getState(),s=1/n.zoom,{hoveredHandle:r,rotation:o,liveUpdates:a,features:u}=n,l=this.handleRadius*s;t.fillStyle=this.handleFill,t.lineWidth=this.handleStrokeWidth*s,t.strokeStyle=this.handleStroke,Object.values(u).forEach(d=>{if(!n.isSelected(d.id))return;const h=a[d.id]?{...d,...a[d.id]}:d;if(c.isArrow(h))this.renderArrowHandles(h,t,l,r);else if(c.isBox(h)||c.isText(h)){const x=c.isText(h)?o:0;this.renderOutline(h,t,x,r,n.zoom),this.renderBoxHandles(h,t,l,r,x)}else c.isPolygon(h)&&this.renderPolygonHandles(h,t,l,r,n.drawingFeature===h.id)})});this.layer=t.layers.addCanvasLayer(this.render,void 0,c.LAYERS.HANDLES),this.store.subscribe(s=>({selectedFeatures:s.selectedFeatures,liveUpdates:s.liveUpdates}),this.refresh),t.events.on("zoom",this.refresh)}renderOutline(t,n,s,r,o){var m,F;const a=c.isText(t)&&((m=t.properties.style)==null?void 0:m.fixedSize);let{width:u,height:l}=c.getBoxSize(t);a&&(u/=o,l/=o);const d=c.getBoxPosition(t,a,o),h=u/2,x=l/2,f=d.x+h,g=d.y+x;n.save(),n.translate(f,g),n.rotate(s);const p=(F=t.properties.style)==null?void 0:F.borderRadius;if(p&&p>0?(on(n,-h,-x,u,l,p),n.stroke()):n.strokeRect(-h,-x,u,l),r>=4&&r<8){let y,A,D,C;const E=p&&p>0?p:this.handleRadius/o;switch(r){case 4:y=-h+E,A=-x,D=h-E,C=-x;break;case 5:y=h,A=-x+E,D=h,C=x-E;break;case 6:y=h-E,A=x,D=-h+E,C=x;break;case 7:y=-h,A=x-E,D=-h,C=-x+E;break}n.lineWidth=this.handleStrokeWidth*this.handleMagnifier/o,n.beginPath(),n.moveTo(y,A),n.lineTo(D,C),n.stroke(),n.lineWidth=this.handleStrokeWidth}n.restore()}renderArrowHandles(t,n,s,r){var x,f,g,p;const o=c.getArrowStart(t),a=c.getArrowEnd(t),u=+(r===0),l=+(r===1),d=s*(1+(this.handleMagnifier-1)*u),h=s*(1+(this.handleMagnifier-1)*l);n.beginPath(),n.moveTo(o.x,o.y),n.lineTo(a.x,a.y),n.closePath(),n.stroke(),n.beginPath(),((f=(x=t.properties.link)==null?void 0:x.start)==null?void 0:f.type)!=="comment"&&(n.moveTo(o.x-d,o.y-d),n.rect(o.x-d,o.y-d,d*2,d*2)),((p=(g=t.properties.link)==null?void 0:g.end)==null?void 0:p.type)!=="comment"&&(n.moveTo(a.x-h,a.y-h),n.rect(a.x-h,a.y-h,h*2,h*2)),n.closePath(),n.fill(),n.stroke()}renderBoxHandles(t,n,s,r,o){var g;if(c.isText(t)&&((g=t.properties.style)!=null&&g.fixedSize))return;const{width:a,height:u}=c.getBoxSize(t),l=c.getBoxPosition(t),d=a/2,h=u/2,x=l.x+d,f=l.y+h;n.save(),n.translate(x,f),n.rotate(o),n.beginPath();for(let p=0;p<te.length;p++){const[m,F]=te[p],y=a*m,A=u*F,D=r===p?s*this.handleMagnifier:s;n.rect(y-D,A-D,D*2,D*2)}n.closePath(),n.fill(),n.stroke(),n.restore()}renderPolygonHandles(t,n,s,r,o){const a=t.geometry.coordinates[0];if(!o){a.length>2&&(n.save(),n.strokeStyle=this.handleStroke,n.lineWidth=this.handleStrokeWidth/this.store.getState().zoom,this.drawSmoothPolygon(n,a,.5),n.stroke(),n.restore()),n.beginPath();for(let u=0;u<a.length-1;u++){const[l,d]=a[u],h=r===u?s*this.handleMagnifier:s;n.moveTo(l+h,d),n.arc(l,d,h,0,2*Math.PI)}n.closePath(),n.fill(),n.stroke()}}drawSmoothPolygon(t,n,s){const r=n.slice(0,-1);if(r.length<3)return;t.beginPath();const o=r.length;for(let a=0;a<o;a++){const u=r[(a-1+o)%o],l=r[a],d=r[(a+1)%o],h=r[(a+2)%o],x=l[0]+(d[0]-u[0])/6*s,f=l[1]+(d[1]-u[1])/6*s,g=d[0]-(h[0]-l[0])/6*s,p=d[1]-(h[1]-l[1])/6*s;a===0&&t.moveTo(l[0],l[1]),t.bezierCurveTo(x,f,g,p,d[0],d[1])}t.closePath()}destroy(){this.layer.destroy(),super.destroy()}}const us=.5;function hs(i,e,t,n){const{start:s,end:r}=c.getArrowEndPoints(i),o=c.subtract(r,s);return Math.min(n,Math.max(2*e,c.length(o)*.01,t))}function ee(i,e){return!i||i==="none"?0:i==="dot"?e*2:i==="halo-dot"?e*4:i==="arrow"||i==="arrow-plain"?e:0}function xs(i,e){if(!i){i=c.createSVGElement("g");const t=c.createSVGElement("path");i.classList.add("annotation-arrow"),i.setAttribute("data-annotation",`${e}`),i.setAttribute("data-annotation-type","arrow"),i.appendChild(t);const n=c.createSVGElement("g");n.classList.add("annotation-arrow-endpoints"),i.appendChild(n)}return i}function fs(i,e,t,n,s,r){const{start:o,end:a}=c.getArrowEndPoints(e),u=e.properties.style||c.defaultArrowStyle,{tail:l,strokeWidth:d=0,head:h,strokeColor:x,strokeType:f}=u,g=c.subtract(a,o),p=Ce(e)?1/r.zoom:1,m=hs(e,d,t,n)*p,F=xs(s,e.id),y=F.firstChild,A=x||"none";y.setAttribute("stroke",A),y.setAttribute("stroke-width",`${p*d}`),y.setAttribute("fill","none"),y.setAttribute("stroke-linecap","round"),y.setAttribute("stroke-linejoin","round");const D=ee(l,d*p),C=ee(h,d*p),E=c.normalize(g),N=c.add(o,c.mul(E,D)),M=c.add(a,c.mul(E,-C)),B=`M ${N.x} ${N.y} L ${M.x} ${M.y}`;y.setAttribute("d",B);const b=F.children[1];b.innerHTML="",f==="dashed"?y.setAttribute("stroke-dasharray","5,10"):y.removeAttribute("stroke-dasharray"),ne(b,o,g,A,l,d,p,m),ne(b,a,c.invert(g),A,h,d,p,m),F.setAttribute("transform",`rotate(${-r.rotation*(180/Math.PI)})`);const T=Ne(e);return(!F.parentNode||F.parentNode!==i||r.selectedFeatures.has(e.id)||T!==void 0&&r.selectedFeatures.has(T))&&c.bringToTop(i,F),F}function ne(i,e,t,n,s,r,o,a){s==="halo-dot"&&se(i,e,gs(n),us,r*o*4),(s==="dot"||s==="halo-dot")&&se(i,e,n,1,r*o*2),(s==="arrow"||s==="arrow-plain")&&ps(i,e,t,n,s==="arrow-plain",r*o,a)}function gs(i){return i==="none"?"none":i}function se(i,e,t,n,s){const r=c.createSVGElement("circle");r.setAttribute("cx",`${e.x}`),r.setAttribute("cy",`${e.y}`),r.setAttribute("r",`${s}`),r.setAttribute("fill-opacity",`${n}`),r.setAttribute("fill",t),i.appendChild(r)}function ps(i,e,t,n,s,r,o){const a=c.mul(c.normalize(t),o),u=c.add(e,c.rotateRadians(a,Math.PI/6)),l=c.add(e,c.rotateRadians(a,-Math.PI/6)),d=c.createSVGElement("path"),h=`${e.x} ${e.y}`,x=`M ${u.x} ${u.y} L ${h} L ${l.x} ${l.y}${s?" Z":""}`;d.setAttribute("d",x),d.setAttribute("stroke",n),d.setAttribute("stroke-width",`${r}`),d.setAttribute("fill",s?n:"none"),d.setAttribute("stroke-linecap","round"),d.setAttribute("stroke-linejoin","round"),i.appendChild(d)}function ms(i,e,t="box"){if(!i){i=c.createSVGElement("g"),i.setAttribute("data-annotation",`${e}`),i.setAttribute("data-annotation-type",t),i.classList.add(`annotation-${t}`);const n=c.createSVGElement("rect");i.appendChild(n)}return i}function ke(i,e,t,n){const s=e.id,r=`class${s}`,o=c.getBoxSize(e),a=ms(t,s,e.properties.type),{strokeColor:u,strokeWidth:l,strokeType:d,background:h,borderRadius:x,boxShadow:f}=e.properties.style||c.defaultBoxStyle;a.classList.add("annotation-box"),a.setAttribute("fill",`${h||"transparent"}`);const g=a.firstChild;x&&(g.setAttribute("rx",`${x}`),g.setAttribute("ry",`${x}`)),d&&d!=="none"&&(g.setAttribute("stroke",u||"black"),g.setAttribute("stroke-width",`${l}`),d==="dashed"&&g.setAttribute("stroke-dasharray","5,5")),h&&h.length&&(n.hoveredFeature===e.id?g.setAttribute("fill",c.brighten(h)):g.setAttribute("fill",h));const p=c.getBoxPosition(e);return g.setAttribute("width",`${o.width}`),g.setAttribute("height",`${o.height}`),g.setAttribute("x",`${p.x}`),g.setAttribute("y",`${p.y}`),a.appendChild(g),f?a.style.filter=`drop-shadow(${f})`:a.style.filter="",a.setAttribute("transform",n.getRotationTransform(0,0)),a.classList.add(r),a.setAttribute("data-annotation",`${e.id}`),a.setAttribute("data-annotation-type",e.properties.type),i.appendChild(a),a}function Ss(){const i=c.createSVGElement("style");return i.textContent=`
12
7
  /* Comment Animation Styles */
13
8
  .comment-icon {
14
9
  transition:
@@ -85,7 +80,7 @@
85
80
  .comment-edit-button:hover {
86
81
  opacity: 1;
87
82
  }
88
- `,s}function ji(s,e,t){const n={...Z,...e.properties.style},i=n.iconSize,{iconColor:r=Z.iconColor,iconSymbol:o=Z.iconSymbol,iconBorderColor:a=Z.iconBorderColor,iconBorderWidth:d=Z.iconBorderWidth}=n;let c=s.querySelector("rect");c||(c=T("rect"),c.setAttribute("x",`${-i/2}`),c.setAttribute("y",`${-i/2}`),c.setAttribute("rx",`${n.borderRadius}`),c.setAttribute("ry",`${n.borderRadius}`),s.appendChild(c)),c.setAttribute("width",`${i}`),c.setAttribute("height",`${i}`),t.hoveredFeature===e.id?c.setAttribute("fill",At(r)):c.setAttribute("fill",r),d&&d>0?(c.setAttribute("stroke",a||"#CCC"),c.setAttribute("stroke-width",`${d}`)):(c.removeAttribute("stroke"),c.removeAttribute("stroke-width"));let l=s.querySelector("text");l||(l=T("text"),l.setAttribute("x","0"),l.setAttribute("y","0"),l.setAttribute("text-anchor","middle"),l.setAttribute("dominant-baseline","central"),l.setAttribute("pointer-events","none"),s.appendChild(l)),l.setAttribute("font-size",`${i*.5}`),l.textContent=o}function qi(s,e,t,n=!1){const i={...Z,...e.properties.style},{font:r="Arial, sans-serif",fontSize:o=12,padding:a=8,background:d="#FFFACD",color:c="#333",borderRadius:l=4,strokeColor:u="#DDD",strokeWidth:h=1,maxHeight:x}=i,g=e.properties.width,f=e.properties.height,p=x?Math.min(f,x):f,y=x?f>x:!1,A=e.properties.content||"";s.innerHTML="";const E=-g/2,w=-p/2,N=T("rect");N.setAttribute("x",`${E}`),N.setAttribute("y",`${w}`),N.setAttribute("width",`${g}`),N.setAttribute("height",`${p}`),N.setAttribute("rx",`${l}`),N.setAttribute("ry",`${l}`),N.setAttribute("fill",t.hoveredFeature===e.id?At(d):d),h&&h>0&&(N.setAttribute("stroke",u||"#DDD"),N.setAttribute("stroke-width",`${h}`)),s.appendChild(N);const F=T("foreignObject");F.setAttribute("x",`${E}`),F.setAttribute("y",`${w}`),F.setAttribute("width",`${g}`),F.setAttribute("height",`${p}`),F.style.pointerEvents="none";const C=document.createElement("div");if(C.style.width="100%",C.style.height="100%",C.style.padding=`${a}px`,C.style.boxSizing="border-box",C.style.fontFamily=r,C.style.fontSize=`${typeof o=="number"?o:parseFloat(o)}px`,C.style.lineHeight=`${(typeof o=="number"?o:parseFloat(o))*Xt}px`,C.style.color=c,C.style.overflowY=y?"auto":"hidden",C.style.overflowX="hidden",C.style.overflowWrap="break-word",C.style.whiteSpace="pre-wrap",C.style.pointerEvents="none",C.innerHTML=Vi(A),F.appendChild(C),s.appendChild(F),n){const D=T("foreignObject");D.setAttribute("x",`${E+g-24-4}`),D.setAttribute("y",`${w+p-24-4}`),D.setAttribute("width","24"),D.setAttribute("height","24");const v=document.createElement("div");v.classList.add("ogma-send-button"),v.style.width="100%",v.style.height="100%",v.style.display="flex",v.style.alignItems="center",v.style.justifyContent="center",v.style.boxSizing="border-box",v.style.background=d,v.style.border=`1px solid ${u||"#DDD"}`,v.style.borderRadius="4px",v.style.pointerEvents="auto";const O=document.createElement("span");O.classList.add("ogma-send-button-icon"),O.innerHTML=t.options.editButtonIcon,v.appendChild(O),D.appendChild(v),s.appendChild(D)}i.shadow!==!1?s.setAttribute("filter","url(#softShadow)"):s.removeAttribute("filter")}function Vi(s){if(!s)return"";let e=s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return e=e.replace(Sn(),`<a href="$1" class="${ke}" target="_blank" rel="noopener noreferrer">$1</a>`),e}function Ki(s,e,t,n,i){const r=e.properties.mode;let o=t;o||(o=T("g"),o.setAttribute("data-annotation",`${e.id}`),o.setAttribute("data-annotation-type","comment"));let a=o.querySelector(".comment-icon");a||(a=T("g"),a.classList.add("comment-icon"),o.appendChild(a));let d=o.querySelector(".comment-box");d||(d=T("g"),d.classList.add("comment-box"),o.appendChild(d));const c=r!==rt&&n.selectedFeatures.has(e.id)&&n.editingFeature!==e.id&&n.options.showEditButton;ji(a,e,n),qi(d,e,n,c),i?o.classList.remove("comment-no-transition"):o.classList.add("comment-no-transition"),r===rt?(o.classList.add("comment-collapsed"),o.classList.remove("comment-expanded")):(o.classList.add("comment-expanded"),o.classList.remove("comment-collapsed"));const l=J(e);return o.setAttribute("transform",n.getScreenAlignedTransform(l.x,l.y,!1)),o.style.visibility=n.editingFeature===e.id?"hidden":"",(!o.parentNode||o.parentNode!==s)&&s.appendChild(o),o}function Zi(s,e=.5,t=!1){if(s.length<2)return"";if(s.length<3)return s.map((o,a)=>`${a===0?"M":"L"}${o[0]},${o[1]}`).join(" ")+" Z";const n=s,i=n.length-1,r=[];for(let o=0;o<i;o++){const a=n[(o-1+i)%i],d=n[o],c=n[(o+1)%i],l=n[(o+2)%i],u=d[0]+(c[0]-a[0])/6*e,h=d[1]+(c[1]-a[1])/6*e,x=c[0]-(l[0]-d[0])/6*e,g=c[1]-(l[1]-d[1])/6*e;o===0&&r.push(`M${d[0]},${d[1]}`),t&&o===i-1?r.push(`L${c[0]},${c[1]}`):r.push(`C${u},${h} ${x},${g} ${c[0]},${c[1]}`)}return r.push("Z"),r.join(" ")}const Ji=(s,e,t="box")=>(s||(s=T("g"),s.setAttribute("data-annotation",`${e}`),s.classList.add(`annotation-${t}`)),s);function Qi(s,e,t,n){const i=Ji(t,e.id.toString(),e.properties.type);i.setAttribute("data-annotation",String(e.id));let r=i.querySelector("path");r||(r=T("path"),i.appendChild(r));const{strokeColor:o=lt.strokeColor,strokeWidth:a=lt.strokeWidth,background:d=lt.background,strokeType:c=lt.strokeType}=e.properties.style||lt;o&&r.setAttribute("stroke",o),a!==void 0&&r.setAttribute("stroke-width",String(a)),d&&(n.hoveredFeature===e.id?r.setAttribute("fill",At(d)):r.setAttribute("fill",d)),c==="dashed"?r.setAttribute("stroke-dasharray","5,5"):r.removeAttribute("stroke-dasharray");const l=e.geometry.coordinates[0],u=Zi(l,.5,n.drawingFeature===e.id);return r.setAttribute("d",u),i.setAttribute("transform",n.getRotationTransform(0,0)),s.appendChild(i),i}const tr=["BN","BN","BN","BN","BN","BN","BN","BN","BN","S","B","S","WS","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","B","B","B","S","WS","ON","ON","ET","ET","ET","ON","ON","ON","ON","ON","ES","CS","ES","CS","CS","EN","EN","EN","EN","EN","EN","EN","EN","EN","EN","CS","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","BN","BN","BN","BN","BN","BN","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","CS","ON","ET","ET","ET","ET","ON","ON","ON","ON","L","ON","ON","BN","ON","ON","ET","ET","EN","EN","ON","L","ON","ON","ON","EN","L","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L"],In=[[697,698,"ON"],[706,719,"ON"],[722,735,"ON"],[741,749,"ON"],[751,767,"ON"],[768,879,"NSM"],[884,885,"ON"],[894,894,"ON"],[900,901,"ON"],[903,903,"ON"],[1014,1014,"ON"],[1155,1161,"NSM"],[1418,1418,"ON"],[1421,1422,"ON"],[1423,1423,"ET"],[1424,1424,"R"],[1425,1469,"NSM"],[1470,1470,"R"],[1471,1471,"NSM"],[1472,1472,"R"],[1473,1474,"NSM"],[1475,1475,"R"],[1476,1477,"NSM"],[1478,1478,"R"],[1479,1479,"NSM"],[1480,1535,"R"],[1536,1541,"AN"],[1542,1543,"ON"],[1544,1544,"AL"],[1545,1546,"ET"],[1547,1547,"AL"],[1548,1548,"CS"],[1549,1549,"AL"],[1550,1551,"ON"],[1552,1562,"NSM"],[1563,1610,"AL"],[1611,1631,"NSM"],[1632,1641,"AN"],[1642,1642,"ET"],[1643,1644,"AN"],[1645,1647,"AL"],[1648,1648,"NSM"],[1649,1749,"AL"],[1750,1756,"NSM"],[1757,1757,"AN"],[1758,1758,"ON"],[1759,1764,"NSM"],[1765,1766,"AL"],[1767,1768,"NSM"],[1769,1769,"ON"],[1770,1773,"NSM"],[1774,1775,"AL"],[1776,1785,"EN"],[1786,1808,"AL"],[1809,1809,"NSM"],[1810,1839,"AL"],[1840,1866,"NSM"],[1867,1957,"AL"],[1958,1968,"NSM"],[1969,1983,"AL"],[1984,2026,"R"],[2027,2035,"NSM"],[2036,2037,"R"],[2038,2041,"ON"],[2042,2044,"R"],[2045,2045,"NSM"],[2046,2069,"R"],[2070,2073,"NSM"],[2074,2074,"R"],[2075,2083,"NSM"],[2084,2084,"R"],[2085,2087,"NSM"],[2088,2088,"R"],[2089,2093,"NSM"],[2094,2136,"R"],[2137,2139,"NSM"],[2140,2143,"R"],[2144,2191,"AL"],[2192,2193,"AN"],[2194,2198,"AL"],[2199,2207,"NSM"],[2208,2249,"AL"],[2250,2273,"NSM"],[2274,2274,"AN"],[2275,2306,"NSM"],[2362,2362,"NSM"],[2364,2364,"NSM"],[2369,2376,"NSM"],[2381,2381,"NSM"],[2385,2391,"NSM"],[2402,2403,"NSM"],[2433,2433,"NSM"],[2492,2492,"NSM"],[2497,2500,"NSM"],[2509,2509,"NSM"],[2530,2531,"NSM"],[2546,2547,"ET"],[2555,2555,"ET"],[2558,2558,"NSM"],[2561,2562,"NSM"],[2620,2620,"NSM"],[2625,2626,"NSM"],[2631,2632,"NSM"],[2635,2637,"NSM"],[2641,2641,"NSM"],[2672,2673,"NSM"],[2677,2677,"NSM"],[2689,2690,"NSM"],[2748,2748,"NSM"],[2753,2757,"NSM"],[2759,2760,"NSM"],[2765,2765,"NSM"],[2786,2787,"NSM"],[2801,2801,"ET"],[2810,2815,"NSM"],[2817,2817,"NSM"],[2876,2876,"NSM"],[2879,2879,"NSM"],[2881,2884,"NSM"],[2893,2893,"NSM"],[2901,2902,"NSM"],[2914,2915,"NSM"],[2946,2946,"NSM"],[3008,3008,"NSM"],[3021,3021,"NSM"],[3059,3064,"ON"],[3065,3065,"ET"],[3066,3066,"ON"],[3072,3072,"NSM"],[3076,3076,"NSM"],[3132,3132,"NSM"],[3134,3136,"NSM"],[3142,3144,"NSM"],[3146,3149,"NSM"],[3157,3158,"NSM"],[3170,3171,"NSM"],[3192,3198,"ON"],[3201,3201,"NSM"],[3260,3260,"NSM"],[3276,3277,"NSM"],[3298,3299,"NSM"],[3328,3329,"NSM"],[3387,3388,"NSM"],[3393,3396,"NSM"],[3405,3405,"NSM"],[3426,3427,"NSM"],[3457,3457,"NSM"],[3530,3530,"NSM"],[3538,3540,"NSM"],[3542,3542,"NSM"],[3633,3633,"NSM"],[3636,3642,"NSM"],[3647,3647,"ET"],[3655,3662,"NSM"],[3761,3761,"NSM"],[3764,3772,"NSM"],[3784,3790,"NSM"],[3864,3865,"NSM"],[3893,3893,"NSM"],[3895,3895,"NSM"],[3897,3897,"NSM"],[3898,3901,"ON"],[3953,3966,"NSM"],[3968,3972,"NSM"],[3974,3975,"NSM"],[3981,3991,"NSM"],[3993,4028,"NSM"],[4038,4038,"NSM"],[4141,4144,"NSM"],[4146,4151,"NSM"],[4153,4154,"NSM"],[4157,4158,"NSM"],[4184,4185,"NSM"],[4190,4192,"NSM"],[4209,4212,"NSM"],[4226,4226,"NSM"],[4229,4230,"NSM"],[4237,4237,"NSM"],[4253,4253,"NSM"],[4957,4959,"NSM"],[5008,5017,"ON"],[5120,5120,"ON"],[5760,5760,"WS"],[5787,5788,"ON"],[5906,5908,"NSM"],[5938,5939,"NSM"],[5970,5971,"NSM"],[6002,6003,"NSM"],[6068,6069,"NSM"],[6071,6077,"NSM"],[6086,6086,"NSM"],[6089,6099,"NSM"],[6107,6107,"ET"],[6109,6109,"NSM"],[6128,6137,"ON"],[6144,6154,"ON"],[6155,6157,"NSM"],[6158,6158,"BN"],[6159,6159,"NSM"],[6277,6278,"NSM"],[6313,6313,"NSM"],[6432,6434,"NSM"],[6439,6440,"NSM"],[6450,6450,"NSM"],[6457,6459,"NSM"],[6464,6464,"ON"],[6468,6469,"ON"],[6622,6655,"ON"],[6679,6680,"NSM"],[6683,6683,"NSM"],[6742,6742,"NSM"],[6744,6750,"NSM"],[6752,6752,"NSM"],[6754,6754,"NSM"],[6757,6764,"NSM"],[6771,6780,"NSM"],[6783,6783,"NSM"],[6832,6877,"NSM"],[6880,6891,"NSM"],[6912,6915,"NSM"],[6964,6964,"NSM"],[6966,6970,"NSM"],[6972,6972,"NSM"],[6978,6978,"NSM"],[7019,7027,"NSM"],[7040,7041,"NSM"],[7074,7077,"NSM"],[7080,7081,"NSM"],[7083,7085,"NSM"],[7142,7142,"NSM"],[7144,7145,"NSM"],[7149,7149,"NSM"],[7151,7153,"NSM"],[7212,7219,"NSM"],[7222,7223,"NSM"],[7376,7378,"NSM"],[7380,7392,"NSM"],[7394,7400,"NSM"],[7405,7405,"NSM"],[7412,7412,"NSM"],[7416,7417,"NSM"],[7616,7679,"NSM"],[8125,8125,"ON"],[8127,8129,"ON"],[8141,8143,"ON"],[8157,8159,"ON"],[8173,8175,"ON"],[8189,8190,"ON"],[8192,8202,"WS"],[8203,8205,"BN"],[8207,8207,"R"],[8208,8231,"ON"],[8232,8232,"WS"],[8233,8233,"B"],[8234,8238,"BN"],[8239,8239,"CS"],[8240,8244,"ET"],[8245,8259,"ON"],[8260,8260,"CS"],[8261,8286,"ON"],[8287,8287,"WS"],[8288,8303,"BN"],[8304,8304,"EN"],[8308,8313,"EN"],[8314,8315,"ES"],[8316,8318,"ON"],[8320,8329,"EN"],[8330,8331,"ES"],[8332,8334,"ON"],[8352,8399,"ET"],[8400,8432,"NSM"],[8448,8449,"ON"],[8451,8454,"ON"],[8456,8457,"ON"],[8468,8468,"ON"],[8470,8472,"ON"],[8478,8483,"ON"],[8485,8485,"ON"],[8487,8487,"ON"],[8489,8489,"ON"],[8494,8494,"ET"],[8506,8507,"ON"],[8512,8516,"ON"],[8522,8525,"ON"],[8528,8543,"ON"],[8585,8587,"ON"],[8592,8721,"ON"],[8722,8722,"ES"],[8723,8723,"ET"],[8724,9013,"ON"],[9083,9108,"ON"],[9110,9257,"ON"],[9280,9290,"ON"],[9312,9351,"ON"],[9352,9371,"EN"],[9450,9899,"ON"],[9901,10239,"ON"],[10496,11123,"ON"],[11126,11263,"ON"],[11493,11498,"ON"],[11503,11505,"NSM"],[11513,11519,"ON"],[11647,11647,"NSM"],[11744,11775,"NSM"],[11776,11869,"ON"],[11904,11929,"ON"],[11931,12019,"ON"],[12032,12245,"ON"],[12272,12287,"ON"],[12288,12288,"WS"],[12289,12292,"ON"],[12296,12320,"ON"],[12330,12333,"NSM"],[12336,12336,"ON"],[12342,12343,"ON"],[12349,12351,"ON"],[12441,12442,"NSM"],[12443,12444,"ON"],[12448,12448,"ON"],[12539,12539,"ON"],[12736,12773,"ON"],[12783,12783,"ON"],[12829,12830,"ON"],[12880,12895,"ON"],[12924,12926,"ON"],[12977,12991,"ON"],[13004,13007,"ON"],[13175,13178,"ON"],[13278,13279,"ON"],[13311,13311,"ON"],[19904,19967,"ON"],[42128,42182,"ON"],[42509,42511,"ON"],[42607,42610,"NSM"],[42611,42611,"ON"],[42612,42621,"NSM"],[42622,42623,"ON"],[42654,42655,"NSM"],[42736,42737,"NSM"],[42752,42785,"ON"],[42888,42888,"ON"],[43010,43010,"NSM"],[43014,43014,"NSM"],[43019,43019,"NSM"],[43045,43046,"NSM"],[43048,43051,"ON"],[43052,43052,"NSM"],[43064,43065,"ET"],[43124,43127,"ON"],[43204,43205,"NSM"],[43232,43249,"NSM"],[43263,43263,"NSM"],[43302,43309,"NSM"],[43335,43345,"NSM"],[43392,43394,"NSM"],[43443,43443,"NSM"],[43446,43449,"NSM"],[43452,43453,"NSM"],[43493,43493,"NSM"],[43561,43566,"NSM"],[43569,43570,"NSM"],[43573,43574,"NSM"],[43587,43587,"NSM"],[43596,43596,"NSM"],[43644,43644,"NSM"],[43696,43696,"NSM"],[43698,43700,"NSM"],[43703,43704,"NSM"],[43710,43711,"NSM"],[43713,43713,"NSM"],[43756,43757,"NSM"],[43766,43766,"NSM"],[43882,43883,"ON"],[44005,44005,"NSM"],[44008,44008,"NSM"],[44013,44013,"NSM"],[64285,64285,"R"],[64286,64286,"NSM"],[64287,64296,"R"],[64297,64297,"ES"],[64298,64335,"R"],[64336,64450,"AL"],[64451,64466,"ON"],[64467,64829,"AL"],[64830,64847,"ON"],[64848,64911,"AL"],[64912,64913,"ON"],[64914,64967,"AL"],[64968,64975,"ON"],[64976,65007,"BN"],[65008,65020,"AL"],[65021,65023,"ON"],[65024,65039,"NSM"],[65040,65049,"ON"],[65056,65071,"NSM"],[65072,65103,"ON"],[65104,65104,"CS"],[65105,65105,"ON"],[65106,65106,"CS"],[65108,65108,"ON"],[65109,65109,"CS"],[65110,65118,"ON"],[65119,65119,"ET"],[65120,65121,"ON"],[65122,65123,"ES"],[65124,65126,"ON"],[65128,65128,"ON"],[65129,65130,"ET"],[65131,65131,"ON"],[65136,65278,"AL"],[65279,65279,"BN"],[65281,65282,"ON"],[65283,65285,"ET"],[65286,65290,"ON"],[65291,65291,"ES"],[65292,65292,"CS"],[65293,65293,"ES"],[65294,65295,"CS"],[65296,65305,"EN"],[65306,65306,"CS"],[65307,65312,"ON"],[65339,65344,"ON"],[65371,65381,"ON"],[65504,65505,"ET"],[65506,65508,"ON"],[65509,65510,"ET"],[65512,65518,"ON"],[65520,65528,"BN"],[65529,65533,"ON"],[65534,65535,"BN"],[65793,65793,"ON"],[65856,65932,"ON"],[65936,65948,"ON"],[65952,65952,"ON"],[66045,66045,"NSM"],[66272,66272,"NSM"],[66273,66299,"EN"],[66422,66426,"NSM"],[67584,67870,"R"],[67871,67871,"ON"],[67872,68096,"R"],[68097,68099,"NSM"],[68100,68100,"R"],[68101,68102,"NSM"],[68103,68107,"R"],[68108,68111,"NSM"],[68112,68151,"R"],[68152,68154,"NSM"],[68155,68158,"R"],[68159,68159,"NSM"],[68160,68324,"R"],[68325,68326,"NSM"],[68327,68408,"R"],[68409,68415,"ON"],[68416,68863,"R"],[68864,68899,"AL"],[68900,68903,"NSM"],[68904,68911,"AL"],[68912,68921,"AN"],[68922,68927,"AL"],[68928,68937,"AN"],[68938,68968,"R"],[68969,68973,"NSM"],[68974,68974,"ON"],[68975,69215,"R"],[69216,69246,"AN"],[69247,69290,"R"],[69291,69292,"NSM"],[69293,69311,"R"],[69312,69327,"AL"],[69328,69336,"ON"],[69337,69369,"AL"],[69370,69375,"NSM"],[69376,69423,"R"],[69424,69445,"AL"],[69446,69456,"NSM"],[69457,69487,"AL"],[69488,69505,"R"],[69506,69509,"NSM"],[69510,69631,"R"],[69633,69633,"NSM"],[69688,69702,"NSM"],[69714,69733,"ON"],[69744,69744,"NSM"],[69747,69748,"NSM"],[69759,69761,"NSM"],[69811,69814,"NSM"],[69817,69818,"NSM"],[69826,69826,"NSM"],[69888,69890,"NSM"],[69927,69931,"NSM"],[69933,69940,"NSM"],[70003,70003,"NSM"],[70016,70017,"NSM"],[70070,70078,"NSM"],[70089,70092,"NSM"],[70095,70095,"NSM"],[70191,70193,"NSM"],[70196,70196,"NSM"],[70198,70199,"NSM"],[70206,70206,"NSM"],[70209,70209,"NSM"],[70367,70367,"NSM"],[70371,70378,"NSM"],[70400,70401,"NSM"],[70459,70460,"NSM"],[70464,70464,"NSM"],[70502,70508,"NSM"],[70512,70516,"NSM"],[70587,70592,"NSM"],[70606,70606,"NSM"],[70608,70608,"NSM"],[70610,70610,"NSM"],[70625,70626,"NSM"],[70712,70719,"NSM"],[70722,70724,"NSM"],[70726,70726,"NSM"],[70750,70750,"NSM"],[70835,70840,"NSM"],[70842,70842,"NSM"],[70847,70848,"NSM"],[70850,70851,"NSM"],[71090,71093,"NSM"],[71100,71101,"NSM"],[71103,71104,"NSM"],[71132,71133,"NSM"],[71219,71226,"NSM"],[71229,71229,"NSM"],[71231,71232,"NSM"],[71264,71276,"ON"],[71339,71339,"NSM"],[71341,71341,"NSM"],[71344,71349,"NSM"],[71351,71351,"NSM"],[71453,71453,"NSM"],[71455,71455,"NSM"],[71458,71461,"NSM"],[71463,71467,"NSM"],[71727,71735,"NSM"],[71737,71738,"NSM"],[71995,71996,"NSM"],[71998,71998,"NSM"],[72003,72003,"NSM"],[72148,72151,"NSM"],[72154,72155,"NSM"],[72160,72160,"NSM"],[72193,72198,"NSM"],[72201,72202,"NSM"],[72243,72248,"NSM"],[72251,72254,"NSM"],[72263,72263,"NSM"],[72273,72278,"NSM"],[72281,72283,"NSM"],[72330,72342,"NSM"],[72344,72345,"NSM"],[72544,72544,"NSM"],[72546,72548,"NSM"],[72550,72550,"NSM"],[72752,72758,"NSM"],[72760,72765,"NSM"],[72850,72871,"NSM"],[72874,72880,"NSM"],[72882,72883,"NSM"],[72885,72886,"NSM"],[73009,73014,"NSM"],[73018,73018,"NSM"],[73020,73021,"NSM"],[73023,73029,"NSM"],[73031,73031,"NSM"],[73104,73105,"NSM"],[73109,73109,"NSM"],[73111,73111,"NSM"],[73459,73460,"NSM"],[73472,73473,"NSM"],[73526,73530,"NSM"],[73536,73536,"NSM"],[73538,73538,"NSM"],[73562,73562,"NSM"],[73685,73692,"ON"],[73693,73696,"ET"],[73697,73713,"ON"],[78912,78912,"NSM"],[78919,78933,"NSM"],[90398,90409,"NSM"],[90413,90415,"NSM"],[92912,92916,"NSM"],[92976,92982,"NSM"],[94031,94031,"NSM"],[94095,94098,"NSM"],[94178,94178,"ON"],[94180,94180,"NSM"],[113821,113822,"NSM"],[113824,113827,"BN"],[117760,117973,"ON"],[118e3,118009,"EN"],[118010,118012,"ON"],[118016,118451,"ON"],[118458,118480,"ON"],[118496,118512,"ON"],[118528,118573,"NSM"],[118576,118598,"NSM"],[119143,119145,"NSM"],[119155,119162,"BN"],[119163,119170,"NSM"],[119173,119179,"NSM"],[119210,119213,"NSM"],[119273,119274,"ON"],[119296,119361,"ON"],[119362,119364,"NSM"],[119365,119365,"ON"],[119552,119638,"ON"],[120513,120513,"ON"],[120539,120539,"ON"],[120571,120571,"ON"],[120597,120597,"ON"],[120629,120629,"ON"],[120655,120655,"ON"],[120687,120687,"ON"],[120713,120713,"ON"],[120745,120745,"ON"],[120771,120771,"ON"],[120782,120831,"EN"],[121344,121398,"NSM"],[121403,121452,"NSM"],[121461,121461,"NSM"],[121476,121476,"NSM"],[121499,121503,"NSM"],[121505,121519,"NSM"],[122880,122886,"NSM"],[122888,122904,"NSM"],[122907,122913,"NSM"],[122915,122916,"NSM"],[122918,122922,"NSM"],[123023,123023,"NSM"],[123184,123190,"NSM"],[123566,123566,"NSM"],[123628,123631,"NSM"],[123647,123647,"ET"],[124140,124143,"NSM"],[124398,124399,"NSM"],[124643,124643,"NSM"],[124646,124646,"NSM"],[124654,124655,"NSM"],[124661,124661,"NSM"],[124928,125135,"R"],[125136,125142,"NSM"],[125143,125251,"R"],[125252,125258,"NSM"],[125259,126063,"R"],[126064,126143,"AL"],[126144,126207,"R"],[126208,126287,"AL"],[126288,126463,"R"],[126464,126703,"AL"],[126704,126705,"ON"],[126706,126719,"AL"],[126720,126975,"R"],[126976,127019,"ON"],[127024,127123,"ON"],[127136,127150,"ON"],[127153,127167,"ON"],[127169,127183,"ON"],[127185,127221,"ON"],[127232,127242,"EN"],[127243,127247,"ON"],[127279,127279,"ON"],[127338,127343,"ON"],[127405,127405,"ON"],[127584,127589,"ON"],[127744,128728,"ON"],[128732,128748,"ON"],[128752,128764,"ON"],[128768,128985,"ON"],[128992,129003,"ON"],[129008,129008,"ON"],[129024,129035,"ON"],[129040,129095,"ON"],[129104,129113,"ON"],[129120,129159,"ON"],[129168,129197,"ON"],[129200,129211,"ON"],[129216,129217,"ON"],[129232,129240,"ON"],[129280,129623,"ON"],[129632,129645,"ON"],[129648,129660,"ON"],[129664,129674,"ON"],[129678,129734,"ON"],[129736,129736,"ON"],[129741,129756,"ON"],[129759,129770,"ON"],[129775,129784,"ON"],[129792,129938,"ON"],[129940,130031,"ON"],[130032,130041,"EN"],[130042,130042,"ON"],[131070,131071,"BN"],[196606,196607,"BN"],[262142,262143,"BN"],[327678,327679,"BN"],[393214,393215,"BN"],[458750,458751,"BN"],[524286,524287,"BN"],[589822,589823,"BN"],[655358,655359,"BN"],[720894,720895,"BN"],[786430,786431,"BN"],[851966,851967,"BN"],[917502,917759,"BN"],[917760,917999,"NSM"],[918e3,921599,"BN"],[983038,983039,"BN"],[1048574,1048575,"BN"],[1114110,1114111,"BN"]];function er(s){if(s<=255)return tr[s];let e=0,t=In.length-1;for(;e<=t;){const n=e+t>>1,i=In[n];if(s<i[0]){t=n-1;continue}if(s>i[1]){e=n+1;continue}return i[2]}return"L"}function nr(s){const e=s.length;if(e===0)return null;const t=new Array(e);let n=!1;for(let c=0;c<e;){const l=s.charCodeAt(c);let u=l,h=1;if(l>=55296&&l<=56319&&c+1<e){const g=s.charCodeAt(c+1);g>=56320&&g<=57343&&(u=(l-55296<<10)+(g-56320)+65536,h=2)}const x=er(u);(x==="R"||x==="AL"||x==="AN")&&(n=!0);for(let g=0;g<h;g++)t[c+g]=x;c+=h}if(!n)return null;let i=0;for(let c=0;c<e;c++){const l=t[c];if(l==="L"){i=0;break}if(l==="R"||l==="AL"){i=1;break}}const r=new Int8Array(e);for(let c=0;c<e;c++)r[c]=i;const o=i&1?"R":"L",a=o;let d=a;for(let c=0;c<e;c++)t[c]==="NSM"?t[c]=d:d=t[c];d=a;for(let c=0;c<e;c++){const l=t[c];l==="EN"?t[c]=d==="AL"?"AN":"EN":(l==="R"||l==="L"||l==="AL")&&(d=l)}for(let c=0;c<e;c++)t[c]==="AL"&&(t[c]="R");for(let c=1;c<e-1;c++)t[c]==="ES"&&t[c-1]==="EN"&&t[c+1]==="EN"&&(t[c]="EN"),t[c]==="CS"&&(t[c-1]==="EN"||t[c-1]==="AN")&&t[c+1]===t[c-1]&&(t[c]=t[c-1]);for(let c=0;c<e;c++){if(t[c]!=="EN")continue;let l;for(l=c-1;l>=0&&t[l]==="ET";l--)t[l]="EN";for(l=c+1;l<e&&t[l]==="ET";l++)t[l]="EN"}for(let c=0;c<e;c++){const l=t[c];(l==="WS"||l==="ES"||l==="ET"||l==="CS")&&(t[c]="ON")}d=a;for(let c=0;c<e;c++){const l=t[c];l==="EN"?t[c]=d==="L"?"L":"EN":(l==="R"||l==="L")&&(d=l)}for(let c=0;c<e;c++){if(t[c]!=="ON")continue;let l=c+1;for(;l<e&&t[l]==="ON";)l++;const u=c>0?t[c-1]:a,h=l<e?t[l]:a,x=u!=="L"?"R":"L";if(x===(h!=="L"?"R":"L"))for(let f=c;f<l;f++)t[f]=x;c=l-1}for(let c=0;c<e;c++)t[c]==="ON"&&(t[c]=o);for(let c=0;c<e;c++){const l=t[c];(r[c]&1)===0?l==="R"?r[c]++:(l==="AN"||l==="EN")&&(r[c]+=2):(l==="L"||l==="AN"||l==="EN")&&r[c]++}return r}function sr(s,e){const t=nr(s);if(t===null)return null;const n=new Int8Array(e.length);for(let i=0;i<e.length;i++)n[i]=t[e[i]];return n}const ir=/[ \t\n\r\f]+/g,rr=/[\t\n\r\f]| {2,}|^ | $/;function or(s){const e=s??"normal";return e==="pre-wrap"?{mode:e,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:e,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function ar(s){if(!rr.test(s))return s;let e=s.replace(ir," ");return e.charCodeAt(0)===32&&(e=e.slice(1)),e.length>0&&e.charCodeAt(e.length-1)===32&&(e=e.slice(0,-1)),e}function cr(s){return/[\r\f]/.test(s)?s.replace(/\r\n/g,`
83
+ `,i}function Es(i,e,t){const n={...c.defaultCommentStyle,...e.properties.style},s=n.iconSize,{iconColor:r=c.defaultCommentStyle.iconColor,iconSymbol:o=c.defaultCommentStyle.iconSymbol,iconBorderColor:a=c.defaultCommentStyle.iconBorderColor,iconBorderWidth:u=c.defaultCommentStyle.iconBorderWidth}=n;let l=i.querySelector("rect");l||(l=c.createSVGElement("rect"),l.setAttribute("x",`${-s/2}`),l.setAttribute("y",`${-s/2}`),l.setAttribute("rx",`${n.borderRadius}`),l.setAttribute("ry",`${n.borderRadius}`),i.appendChild(l)),l.setAttribute("width",`${s}`),l.setAttribute("height",`${s}`),t.hoveredFeature===e.id?l.setAttribute("fill",c.brighten(r)):l.setAttribute("fill",r),u&&u>0?(l.setAttribute("stroke",a||"#CCC"),l.setAttribute("stroke-width",`${u}`)):(l.removeAttribute("stroke"),l.removeAttribute("stroke-width"));let d=i.querySelector("text");d||(d=c.createSVGElement("text"),d.setAttribute("x","0"),d.setAttribute("y","0"),d.setAttribute("text-anchor","middle"),d.setAttribute("dominant-baseline","central"),d.setAttribute("pointer-events","none"),i.appendChild(d)),d.setAttribute("font-size",`${s*.5}`),d.textContent=o}function Fs(i,e,t,n=!1){const s={...c.defaultCommentStyle,...e.properties.style},{font:r="Arial, sans-serif",fontSize:o=12,padding:a=8,background:u="#FFFACD",color:l="#333",borderRadius:d=4,strokeColor:h="#DDD",strokeWidth:x=1,maxHeight:f}=s,g=e.properties.width,p=e.properties.height,m=f?Math.min(p,f):p,F=f?p>f:!1,y=e.properties.content||"";i.innerHTML="";const A=-g/2,D=-m/2,C=c.createSVGElement("rect");C.setAttribute("x",`${A}`),C.setAttribute("y",`${D}`),C.setAttribute("width",`${g}`),C.setAttribute("height",`${m}`),C.setAttribute("rx",`${d}`),C.setAttribute("ry",`${d}`),C.setAttribute("fill",t.hoveredFeature===e.id?c.brighten(u):u),x&&x>0&&(C.setAttribute("stroke",h||"#DDD"),C.setAttribute("stroke-width",`${x}`)),i.appendChild(C);const E=c.createSVGElement("foreignObject");E.setAttribute("x",`${A}`),E.setAttribute("y",`${D}`),E.setAttribute("width",`${g}`),E.setAttribute("height",`${m}`),E.style.pointerEvents="none";const N=document.createElement("div");if(N.style.width="100%",N.style.height="100%",N.style.padding=`${a}px`,N.style.boxSizing="border-box",N.style.fontFamily=r,N.style.fontSize=`${typeof o=="number"?o:parseFloat(o)}px`,N.style.lineHeight=`${(typeof o=="number"?o:parseFloat(o))*c.TEXT_LINE_HEIGHT}px`,N.style.color=l,N.style.overflowY=F?"auto":"hidden",N.style.overflowX="hidden",N.style.overflowWrap="break-word",N.style.whiteSpace="pre-wrap",N.style.pointerEvents="none",N.innerHTML=ys(y),E.appendChild(N),i.appendChild(E),n){const b=c.createSVGElement("foreignObject");b.setAttribute("x",`${A+g-24-4}`),b.setAttribute("y",`${D+m-24-4}`),b.setAttribute("width","24"),b.setAttribute("height","24");const T=document.createElement("div");T.classList.add("ogma-send-button"),T.style.width="100%",T.style.height="100%",T.style.display="flex",T.style.alignItems="center",T.style.justifyContent="center",T.style.boxSizing="border-box",T.style.background=u,T.style.border=`1px solid ${h||"#DDD"}`,T.style.borderRadius="4px",T.style.pointerEvents="auto";const L=document.createElement("span");L.classList.add("ogma-send-button-icon"),L.innerHTML=t.options.editButtonIcon,T.appendChild(L),b.appendChild(T),i.appendChild(b)}s.shadow!==!1?i.setAttribute("filter","url(#softShadow)"):i.removeAttribute("filter")}function ys(i){if(!i)return"";let e=i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return e=e.replace(Ae(),`<a href="$1" class="${Rt}" target="_blank" rel="noopener noreferrer">$1</a>`),e}function As(i,e,t,n,s){const r=e.properties.mode;let o=t;o||(o=c.createSVGElement("g"),o.setAttribute("data-annotation",`${e.id}`),o.setAttribute("data-annotation-type","comment"));let a=o.querySelector(".comment-icon");a||(a=c.createSVGElement("g"),a.classList.add("comment-icon"),o.appendChild(a));let u=o.querySelector(".comment-box");u||(u=c.createSVGElement("g"),u.classList.add("comment-box"),o.appendChild(u));const l=r!==c.COMMENT_MODE_COLLAPSED&&n.selectedFeatures.has(e.id)&&n.editingFeature!==e.id&&n.options.showEditButton;Es(a,e,n),Fs(u,e,n,l),s?o.classList.remove("comment-no-transition"):o.classList.add("comment-no-transition"),r===c.COMMENT_MODE_COLLAPSED?(o.classList.add("comment-collapsed"),o.classList.remove("comment-expanded")):(o.classList.add("comment-expanded"),o.classList.remove("comment-collapsed"));const d=c.getBoxCenter(e);return o.setAttribute("transform",n.getScreenAlignedTransform(d.x,d.y,!1)),o.style.visibility=n.editingFeature===e.id?"hidden":"",(!o.parentNode||o.parentNode!==i||n.selectedFeatures.has(e.id))&&c.bringToTop(i,o),o}function Cs(i,e=.5,t=!1){if(i.length<2)return"";if(i.length<3)return i.map((o,a)=>`${a===0?"M":"L"}${o[0]},${o[1]}`).join(" ")+" Z";const n=i,s=n.length-1,r=[];for(let o=0;o<s;o++){const a=n[(o-1+s)%s],u=n[o],l=n[(o+1)%s],d=n[(o+2)%s],h=u[0]+(l[0]-a[0])/6*e,x=u[1]+(l[1]-a[1])/6*e,f=l[0]-(d[0]-u[0])/6*e,g=l[1]-(d[1]-u[1])/6*e;o===0&&r.push(`M${u[0]},${u[1]}`),t&&o===s-1?r.push(`L${l[0]},${l[1]}`):r.push(`C${h},${x} ${f},${g} ${l[0]},${l[1]}`)}return r.push("Z"),r.join(" ")}const Ns=(i,e,t="box")=>(i||(i=c.createSVGElement("g"),i.setAttribute("data-annotation",`${e}`),i.classList.add(`annotation-${t}`)),i);function Ds(i,e,t,n){const s=Ns(t,e.id.toString(),e.properties.type);s.setAttribute("data-annotation",String(e.id));let r=s.querySelector("path");r||(r=c.createSVGElement("path"),s.appendChild(r));const{strokeColor:o=c.defaultPolygonStyle.strokeColor,strokeWidth:a=c.defaultPolygonStyle.strokeWidth,background:u=c.defaultPolygonStyle.background,strokeType:l=c.defaultPolygonStyle.strokeType}=e.properties.style||c.defaultPolygonStyle;o&&r.setAttribute("stroke",o),a!==void 0&&r.setAttribute("stroke-width",String(a)),u&&(n.hoveredFeature===e.id?r.setAttribute("fill",c.brighten(u)):r.setAttribute("fill",u)),l==="dashed"?r.setAttribute("stroke-dasharray","5,5"):r.removeAttribute("stroke-dasharray");const d=e.geometry.coordinates[0],h=Cs(d,.5,n.drawingFeature===e.id);return r.setAttribute("d",h),s.setAttribute("transform",n.getRotationTransform(0,0)),i.appendChild(s),s}const Ms=["BN","BN","BN","BN","BN","BN","BN","BN","BN","S","B","S","WS","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","B","B","B","S","WS","ON","ON","ET","ET","ET","ON","ON","ON","ON","ON","ES","CS","ES","CS","CS","EN","EN","EN","EN","EN","EN","EN","EN","EN","EN","CS","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","BN","BN","BN","BN","BN","BN","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","CS","ON","ET","ET","ET","ET","ON","ON","ON","ON","L","ON","ON","BN","ON","ON","ET","ET","EN","EN","ON","L","ON","ON","ON","EN","L","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L"],ie=[[697,698,"ON"],[706,719,"ON"],[722,735,"ON"],[741,749,"ON"],[751,767,"ON"],[768,879,"NSM"],[884,885,"ON"],[894,894,"ON"],[900,901,"ON"],[903,903,"ON"],[1014,1014,"ON"],[1155,1161,"NSM"],[1418,1418,"ON"],[1421,1422,"ON"],[1423,1423,"ET"],[1424,1424,"R"],[1425,1469,"NSM"],[1470,1470,"R"],[1471,1471,"NSM"],[1472,1472,"R"],[1473,1474,"NSM"],[1475,1475,"R"],[1476,1477,"NSM"],[1478,1478,"R"],[1479,1479,"NSM"],[1480,1535,"R"],[1536,1541,"AN"],[1542,1543,"ON"],[1544,1544,"AL"],[1545,1546,"ET"],[1547,1547,"AL"],[1548,1548,"CS"],[1549,1549,"AL"],[1550,1551,"ON"],[1552,1562,"NSM"],[1563,1610,"AL"],[1611,1631,"NSM"],[1632,1641,"AN"],[1642,1642,"ET"],[1643,1644,"AN"],[1645,1647,"AL"],[1648,1648,"NSM"],[1649,1749,"AL"],[1750,1756,"NSM"],[1757,1757,"AN"],[1758,1758,"ON"],[1759,1764,"NSM"],[1765,1766,"AL"],[1767,1768,"NSM"],[1769,1769,"ON"],[1770,1773,"NSM"],[1774,1775,"AL"],[1776,1785,"EN"],[1786,1808,"AL"],[1809,1809,"NSM"],[1810,1839,"AL"],[1840,1866,"NSM"],[1867,1957,"AL"],[1958,1968,"NSM"],[1969,1983,"AL"],[1984,2026,"R"],[2027,2035,"NSM"],[2036,2037,"R"],[2038,2041,"ON"],[2042,2044,"R"],[2045,2045,"NSM"],[2046,2069,"R"],[2070,2073,"NSM"],[2074,2074,"R"],[2075,2083,"NSM"],[2084,2084,"R"],[2085,2087,"NSM"],[2088,2088,"R"],[2089,2093,"NSM"],[2094,2136,"R"],[2137,2139,"NSM"],[2140,2143,"R"],[2144,2191,"AL"],[2192,2193,"AN"],[2194,2198,"AL"],[2199,2207,"NSM"],[2208,2249,"AL"],[2250,2273,"NSM"],[2274,2274,"AN"],[2275,2306,"NSM"],[2362,2362,"NSM"],[2364,2364,"NSM"],[2369,2376,"NSM"],[2381,2381,"NSM"],[2385,2391,"NSM"],[2402,2403,"NSM"],[2433,2433,"NSM"],[2492,2492,"NSM"],[2497,2500,"NSM"],[2509,2509,"NSM"],[2530,2531,"NSM"],[2546,2547,"ET"],[2555,2555,"ET"],[2558,2558,"NSM"],[2561,2562,"NSM"],[2620,2620,"NSM"],[2625,2626,"NSM"],[2631,2632,"NSM"],[2635,2637,"NSM"],[2641,2641,"NSM"],[2672,2673,"NSM"],[2677,2677,"NSM"],[2689,2690,"NSM"],[2748,2748,"NSM"],[2753,2757,"NSM"],[2759,2760,"NSM"],[2765,2765,"NSM"],[2786,2787,"NSM"],[2801,2801,"ET"],[2810,2815,"NSM"],[2817,2817,"NSM"],[2876,2876,"NSM"],[2879,2879,"NSM"],[2881,2884,"NSM"],[2893,2893,"NSM"],[2901,2902,"NSM"],[2914,2915,"NSM"],[2946,2946,"NSM"],[3008,3008,"NSM"],[3021,3021,"NSM"],[3059,3064,"ON"],[3065,3065,"ET"],[3066,3066,"ON"],[3072,3072,"NSM"],[3076,3076,"NSM"],[3132,3132,"NSM"],[3134,3136,"NSM"],[3142,3144,"NSM"],[3146,3149,"NSM"],[3157,3158,"NSM"],[3170,3171,"NSM"],[3192,3198,"ON"],[3201,3201,"NSM"],[3260,3260,"NSM"],[3276,3277,"NSM"],[3298,3299,"NSM"],[3328,3329,"NSM"],[3387,3388,"NSM"],[3393,3396,"NSM"],[3405,3405,"NSM"],[3426,3427,"NSM"],[3457,3457,"NSM"],[3530,3530,"NSM"],[3538,3540,"NSM"],[3542,3542,"NSM"],[3633,3633,"NSM"],[3636,3642,"NSM"],[3647,3647,"ET"],[3655,3662,"NSM"],[3761,3761,"NSM"],[3764,3772,"NSM"],[3784,3790,"NSM"],[3864,3865,"NSM"],[3893,3893,"NSM"],[3895,3895,"NSM"],[3897,3897,"NSM"],[3898,3901,"ON"],[3953,3966,"NSM"],[3968,3972,"NSM"],[3974,3975,"NSM"],[3981,3991,"NSM"],[3993,4028,"NSM"],[4038,4038,"NSM"],[4141,4144,"NSM"],[4146,4151,"NSM"],[4153,4154,"NSM"],[4157,4158,"NSM"],[4184,4185,"NSM"],[4190,4192,"NSM"],[4209,4212,"NSM"],[4226,4226,"NSM"],[4229,4230,"NSM"],[4237,4237,"NSM"],[4253,4253,"NSM"],[4957,4959,"NSM"],[5008,5017,"ON"],[5120,5120,"ON"],[5760,5760,"WS"],[5787,5788,"ON"],[5906,5908,"NSM"],[5938,5939,"NSM"],[5970,5971,"NSM"],[6002,6003,"NSM"],[6068,6069,"NSM"],[6071,6077,"NSM"],[6086,6086,"NSM"],[6089,6099,"NSM"],[6107,6107,"ET"],[6109,6109,"NSM"],[6128,6137,"ON"],[6144,6154,"ON"],[6155,6157,"NSM"],[6158,6158,"BN"],[6159,6159,"NSM"],[6277,6278,"NSM"],[6313,6313,"NSM"],[6432,6434,"NSM"],[6439,6440,"NSM"],[6450,6450,"NSM"],[6457,6459,"NSM"],[6464,6464,"ON"],[6468,6469,"ON"],[6622,6655,"ON"],[6679,6680,"NSM"],[6683,6683,"NSM"],[6742,6742,"NSM"],[6744,6750,"NSM"],[6752,6752,"NSM"],[6754,6754,"NSM"],[6757,6764,"NSM"],[6771,6780,"NSM"],[6783,6783,"NSM"],[6832,6877,"NSM"],[6880,6891,"NSM"],[6912,6915,"NSM"],[6964,6964,"NSM"],[6966,6970,"NSM"],[6972,6972,"NSM"],[6978,6978,"NSM"],[7019,7027,"NSM"],[7040,7041,"NSM"],[7074,7077,"NSM"],[7080,7081,"NSM"],[7083,7085,"NSM"],[7142,7142,"NSM"],[7144,7145,"NSM"],[7149,7149,"NSM"],[7151,7153,"NSM"],[7212,7219,"NSM"],[7222,7223,"NSM"],[7376,7378,"NSM"],[7380,7392,"NSM"],[7394,7400,"NSM"],[7405,7405,"NSM"],[7412,7412,"NSM"],[7416,7417,"NSM"],[7616,7679,"NSM"],[8125,8125,"ON"],[8127,8129,"ON"],[8141,8143,"ON"],[8157,8159,"ON"],[8173,8175,"ON"],[8189,8190,"ON"],[8192,8202,"WS"],[8203,8205,"BN"],[8207,8207,"R"],[8208,8231,"ON"],[8232,8232,"WS"],[8233,8233,"B"],[8234,8238,"BN"],[8239,8239,"CS"],[8240,8244,"ET"],[8245,8259,"ON"],[8260,8260,"CS"],[8261,8286,"ON"],[8287,8287,"WS"],[8288,8303,"BN"],[8304,8304,"EN"],[8308,8313,"EN"],[8314,8315,"ES"],[8316,8318,"ON"],[8320,8329,"EN"],[8330,8331,"ES"],[8332,8334,"ON"],[8352,8399,"ET"],[8400,8432,"NSM"],[8448,8449,"ON"],[8451,8454,"ON"],[8456,8457,"ON"],[8468,8468,"ON"],[8470,8472,"ON"],[8478,8483,"ON"],[8485,8485,"ON"],[8487,8487,"ON"],[8489,8489,"ON"],[8494,8494,"ET"],[8506,8507,"ON"],[8512,8516,"ON"],[8522,8525,"ON"],[8528,8543,"ON"],[8585,8587,"ON"],[8592,8721,"ON"],[8722,8722,"ES"],[8723,8723,"ET"],[8724,9013,"ON"],[9083,9108,"ON"],[9110,9257,"ON"],[9280,9290,"ON"],[9312,9351,"ON"],[9352,9371,"EN"],[9450,9899,"ON"],[9901,10239,"ON"],[10496,11123,"ON"],[11126,11263,"ON"],[11493,11498,"ON"],[11503,11505,"NSM"],[11513,11519,"ON"],[11647,11647,"NSM"],[11744,11775,"NSM"],[11776,11869,"ON"],[11904,11929,"ON"],[11931,12019,"ON"],[12032,12245,"ON"],[12272,12287,"ON"],[12288,12288,"WS"],[12289,12292,"ON"],[12296,12320,"ON"],[12330,12333,"NSM"],[12336,12336,"ON"],[12342,12343,"ON"],[12349,12351,"ON"],[12441,12442,"NSM"],[12443,12444,"ON"],[12448,12448,"ON"],[12539,12539,"ON"],[12736,12773,"ON"],[12783,12783,"ON"],[12829,12830,"ON"],[12880,12895,"ON"],[12924,12926,"ON"],[12977,12991,"ON"],[13004,13007,"ON"],[13175,13178,"ON"],[13278,13279,"ON"],[13311,13311,"ON"],[19904,19967,"ON"],[42128,42182,"ON"],[42509,42511,"ON"],[42607,42610,"NSM"],[42611,42611,"ON"],[42612,42621,"NSM"],[42622,42623,"ON"],[42654,42655,"NSM"],[42736,42737,"NSM"],[42752,42785,"ON"],[42888,42888,"ON"],[43010,43010,"NSM"],[43014,43014,"NSM"],[43019,43019,"NSM"],[43045,43046,"NSM"],[43048,43051,"ON"],[43052,43052,"NSM"],[43064,43065,"ET"],[43124,43127,"ON"],[43204,43205,"NSM"],[43232,43249,"NSM"],[43263,43263,"NSM"],[43302,43309,"NSM"],[43335,43345,"NSM"],[43392,43394,"NSM"],[43443,43443,"NSM"],[43446,43449,"NSM"],[43452,43453,"NSM"],[43493,43493,"NSM"],[43561,43566,"NSM"],[43569,43570,"NSM"],[43573,43574,"NSM"],[43587,43587,"NSM"],[43596,43596,"NSM"],[43644,43644,"NSM"],[43696,43696,"NSM"],[43698,43700,"NSM"],[43703,43704,"NSM"],[43710,43711,"NSM"],[43713,43713,"NSM"],[43756,43757,"NSM"],[43766,43766,"NSM"],[43882,43883,"ON"],[44005,44005,"NSM"],[44008,44008,"NSM"],[44013,44013,"NSM"],[64285,64285,"R"],[64286,64286,"NSM"],[64287,64296,"R"],[64297,64297,"ES"],[64298,64335,"R"],[64336,64450,"AL"],[64451,64466,"ON"],[64467,64829,"AL"],[64830,64847,"ON"],[64848,64911,"AL"],[64912,64913,"ON"],[64914,64967,"AL"],[64968,64975,"ON"],[64976,65007,"BN"],[65008,65020,"AL"],[65021,65023,"ON"],[65024,65039,"NSM"],[65040,65049,"ON"],[65056,65071,"NSM"],[65072,65103,"ON"],[65104,65104,"CS"],[65105,65105,"ON"],[65106,65106,"CS"],[65108,65108,"ON"],[65109,65109,"CS"],[65110,65118,"ON"],[65119,65119,"ET"],[65120,65121,"ON"],[65122,65123,"ES"],[65124,65126,"ON"],[65128,65128,"ON"],[65129,65130,"ET"],[65131,65131,"ON"],[65136,65278,"AL"],[65279,65279,"BN"],[65281,65282,"ON"],[65283,65285,"ET"],[65286,65290,"ON"],[65291,65291,"ES"],[65292,65292,"CS"],[65293,65293,"ES"],[65294,65295,"CS"],[65296,65305,"EN"],[65306,65306,"CS"],[65307,65312,"ON"],[65339,65344,"ON"],[65371,65381,"ON"],[65504,65505,"ET"],[65506,65508,"ON"],[65509,65510,"ET"],[65512,65518,"ON"],[65520,65528,"BN"],[65529,65533,"ON"],[65534,65535,"BN"],[65793,65793,"ON"],[65856,65932,"ON"],[65936,65948,"ON"],[65952,65952,"ON"],[66045,66045,"NSM"],[66272,66272,"NSM"],[66273,66299,"EN"],[66422,66426,"NSM"],[67584,67870,"R"],[67871,67871,"ON"],[67872,68096,"R"],[68097,68099,"NSM"],[68100,68100,"R"],[68101,68102,"NSM"],[68103,68107,"R"],[68108,68111,"NSM"],[68112,68151,"R"],[68152,68154,"NSM"],[68155,68158,"R"],[68159,68159,"NSM"],[68160,68324,"R"],[68325,68326,"NSM"],[68327,68408,"R"],[68409,68415,"ON"],[68416,68863,"R"],[68864,68899,"AL"],[68900,68903,"NSM"],[68904,68911,"AL"],[68912,68921,"AN"],[68922,68927,"AL"],[68928,68937,"AN"],[68938,68968,"R"],[68969,68973,"NSM"],[68974,68974,"ON"],[68975,69215,"R"],[69216,69246,"AN"],[69247,69290,"R"],[69291,69292,"NSM"],[69293,69311,"R"],[69312,69327,"AL"],[69328,69336,"ON"],[69337,69369,"AL"],[69370,69375,"NSM"],[69376,69423,"R"],[69424,69445,"AL"],[69446,69456,"NSM"],[69457,69487,"AL"],[69488,69505,"R"],[69506,69509,"NSM"],[69510,69631,"R"],[69633,69633,"NSM"],[69688,69702,"NSM"],[69714,69733,"ON"],[69744,69744,"NSM"],[69747,69748,"NSM"],[69759,69761,"NSM"],[69811,69814,"NSM"],[69817,69818,"NSM"],[69826,69826,"NSM"],[69888,69890,"NSM"],[69927,69931,"NSM"],[69933,69940,"NSM"],[70003,70003,"NSM"],[70016,70017,"NSM"],[70070,70078,"NSM"],[70089,70092,"NSM"],[70095,70095,"NSM"],[70191,70193,"NSM"],[70196,70196,"NSM"],[70198,70199,"NSM"],[70206,70206,"NSM"],[70209,70209,"NSM"],[70367,70367,"NSM"],[70371,70378,"NSM"],[70400,70401,"NSM"],[70459,70460,"NSM"],[70464,70464,"NSM"],[70502,70508,"NSM"],[70512,70516,"NSM"],[70587,70592,"NSM"],[70606,70606,"NSM"],[70608,70608,"NSM"],[70610,70610,"NSM"],[70625,70626,"NSM"],[70712,70719,"NSM"],[70722,70724,"NSM"],[70726,70726,"NSM"],[70750,70750,"NSM"],[70835,70840,"NSM"],[70842,70842,"NSM"],[70847,70848,"NSM"],[70850,70851,"NSM"],[71090,71093,"NSM"],[71100,71101,"NSM"],[71103,71104,"NSM"],[71132,71133,"NSM"],[71219,71226,"NSM"],[71229,71229,"NSM"],[71231,71232,"NSM"],[71264,71276,"ON"],[71339,71339,"NSM"],[71341,71341,"NSM"],[71344,71349,"NSM"],[71351,71351,"NSM"],[71453,71453,"NSM"],[71455,71455,"NSM"],[71458,71461,"NSM"],[71463,71467,"NSM"],[71727,71735,"NSM"],[71737,71738,"NSM"],[71995,71996,"NSM"],[71998,71998,"NSM"],[72003,72003,"NSM"],[72148,72151,"NSM"],[72154,72155,"NSM"],[72160,72160,"NSM"],[72193,72198,"NSM"],[72201,72202,"NSM"],[72243,72248,"NSM"],[72251,72254,"NSM"],[72263,72263,"NSM"],[72273,72278,"NSM"],[72281,72283,"NSM"],[72330,72342,"NSM"],[72344,72345,"NSM"],[72544,72544,"NSM"],[72546,72548,"NSM"],[72550,72550,"NSM"],[72752,72758,"NSM"],[72760,72765,"NSM"],[72850,72871,"NSM"],[72874,72880,"NSM"],[72882,72883,"NSM"],[72885,72886,"NSM"],[73009,73014,"NSM"],[73018,73018,"NSM"],[73020,73021,"NSM"],[73023,73029,"NSM"],[73031,73031,"NSM"],[73104,73105,"NSM"],[73109,73109,"NSM"],[73111,73111,"NSM"],[73459,73460,"NSM"],[73472,73473,"NSM"],[73526,73530,"NSM"],[73536,73536,"NSM"],[73538,73538,"NSM"],[73562,73562,"NSM"],[73685,73692,"ON"],[73693,73696,"ET"],[73697,73713,"ON"],[78912,78912,"NSM"],[78919,78933,"NSM"],[90398,90409,"NSM"],[90413,90415,"NSM"],[92912,92916,"NSM"],[92976,92982,"NSM"],[94031,94031,"NSM"],[94095,94098,"NSM"],[94178,94178,"ON"],[94180,94180,"NSM"],[113821,113822,"NSM"],[113824,113827,"BN"],[117760,117973,"ON"],[118e3,118009,"EN"],[118010,118012,"ON"],[118016,118451,"ON"],[118458,118480,"ON"],[118496,118512,"ON"],[118528,118573,"NSM"],[118576,118598,"NSM"],[119143,119145,"NSM"],[119155,119162,"BN"],[119163,119170,"NSM"],[119173,119179,"NSM"],[119210,119213,"NSM"],[119273,119274,"ON"],[119296,119361,"ON"],[119362,119364,"NSM"],[119365,119365,"ON"],[119552,119638,"ON"],[120513,120513,"ON"],[120539,120539,"ON"],[120571,120571,"ON"],[120597,120597,"ON"],[120629,120629,"ON"],[120655,120655,"ON"],[120687,120687,"ON"],[120713,120713,"ON"],[120745,120745,"ON"],[120771,120771,"ON"],[120782,120831,"EN"],[121344,121398,"NSM"],[121403,121452,"NSM"],[121461,121461,"NSM"],[121476,121476,"NSM"],[121499,121503,"NSM"],[121505,121519,"NSM"],[122880,122886,"NSM"],[122888,122904,"NSM"],[122907,122913,"NSM"],[122915,122916,"NSM"],[122918,122922,"NSM"],[123023,123023,"NSM"],[123184,123190,"NSM"],[123566,123566,"NSM"],[123628,123631,"NSM"],[123647,123647,"ET"],[124140,124143,"NSM"],[124398,124399,"NSM"],[124643,124643,"NSM"],[124646,124646,"NSM"],[124654,124655,"NSM"],[124661,124661,"NSM"],[124928,125135,"R"],[125136,125142,"NSM"],[125143,125251,"R"],[125252,125258,"NSM"],[125259,126063,"R"],[126064,126143,"AL"],[126144,126207,"R"],[126208,126287,"AL"],[126288,126463,"R"],[126464,126703,"AL"],[126704,126705,"ON"],[126706,126719,"AL"],[126720,126975,"R"],[126976,127019,"ON"],[127024,127123,"ON"],[127136,127150,"ON"],[127153,127167,"ON"],[127169,127183,"ON"],[127185,127221,"ON"],[127232,127242,"EN"],[127243,127247,"ON"],[127279,127279,"ON"],[127338,127343,"ON"],[127405,127405,"ON"],[127584,127589,"ON"],[127744,128728,"ON"],[128732,128748,"ON"],[128752,128764,"ON"],[128768,128985,"ON"],[128992,129003,"ON"],[129008,129008,"ON"],[129024,129035,"ON"],[129040,129095,"ON"],[129104,129113,"ON"],[129120,129159,"ON"],[129168,129197,"ON"],[129200,129211,"ON"],[129216,129217,"ON"],[129232,129240,"ON"],[129280,129623,"ON"],[129632,129645,"ON"],[129648,129660,"ON"],[129664,129674,"ON"],[129678,129734,"ON"],[129736,129736,"ON"],[129741,129756,"ON"],[129759,129770,"ON"],[129775,129784,"ON"],[129792,129938,"ON"],[129940,130031,"ON"],[130032,130041,"EN"],[130042,130042,"ON"],[131070,131071,"BN"],[196606,196607,"BN"],[262142,262143,"BN"],[327678,327679,"BN"],[393214,393215,"BN"],[458750,458751,"BN"],[524286,524287,"BN"],[589822,589823,"BN"],[655358,655359,"BN"],[720894,720895,"BN"],[786430,786431,"BN"],[851966,851967,"BN"],[917502,917759,"BN"],[917760,917999,"NSM"],[918e3,921599,"BN"],[983038,983039,"BN"],[1048574,1048575,"BN"],[1114110,1114111,"BN"]];function ws(i){if(i<=255)return Ms[i];let e=0,t=ie.length-1;for(;e<=t;){const n=e+t>>1,s=ie[n];if(i<s[0]){t=n-1;continue}if(i>s[1]){e=n+1;continue}return s[2]}return"L"}function bs(i){const e=i.length;if(e===0)return null;const t=new Array(e);let n=!1;for(let l=0;l<e;){const d=i.charCodeAt(l);let h=d,x=1;if(d>=55296&&d<=56319&&l+1<e){const g=i.charCodeAt(l+1);g>=56320&&g<=57343&&(h=(d-55296<<10)+(g-56320)+65536,x=2)}const f=ws(h);(f==="R"||f==="AL"||f==="AN")&&(n=!0);for(let g=0;g<x;g++)t[l+g]=f;l+=x}if(!n)return null;let s=0;for(let l=0;l<e;l++){const d=t[l];if(d==="L"){s=0;break}if(d==="R"||d==="AL"){s=1;break}}const r=new Int8Array(e);for(let l=0;l<e;l++)r[l]=s;const o=s&1?"R":"L",a=o;let u=a;for(let l=0;l<e;l++)t[l]==="NSM"?t[l]=u:u=t[l];u=a;for(let l=0;l<e;l++){const d=t[l];d==="EN"?t[l]=u==="AL"?"AN":"EN":(d==="R"||d==="L"||d==="AL")&&(u=d)}for(let l=0;l<e;l++)t[l]==="AL"&&(t[l]="R");for(let l=1;l<e-1;l++)t[l]==="ES"&&t[l-1]==="EN"&&t[l+1]==="EN"&&(t[l]="EN"),t[l]==="CS"&&(t[l-1]==="EN"||t[l-1]==="AN")&&t[l+1]===t[l-1]&&(t[l]=t[l-1]);for(let l=0;l<e;l++){if(t[l]!=="EN")continue;let d;for(d=l-1;d>=0&&t[d]==="ET";d--)t[d]="EN";for(d=l+1;d<e&&t[d]==="ET";d++)t[d]="EN"}for(let l=0;l<e;l++){const d=t[l];(d==="WS"||d==="ES"||d==="ET"||d==="CS")&&(t[l]="ON")}u=a;for(let l=0;l<e;l++){const d=t[l];d==="EN"?t[l]=u==="L"?"L":"EN":(d==="R"||d==="L")&&(u=d)}for(let l=0;l<e;l++){if(t[l]!=="ON")continue;let d=l+1;for(;d<e&&t[d]==="ON";)d++;const h=l>0?t[l-1]:a,x=d<e?t[d]:a,f=h!=="L"?"R":"L";if(f===(x!=="L"?"R":"L"))for(let p=l;p<d;p++)t[p]=f;l=d-1}for(let l=0;l<e;l++)t[l]==="ON"&&(t[l]=o);for(let l=0;l<e;l++){const d=t[l];(r[l]&1)===0?d==="R"?r[l]++:(d==="AN"||d==="EN")&&(r[l]+=2):(d==="L"||d==="AN"||d==="EN")&&r[l]++}return r}function Ts(i,e){const t=bs(i);if(t===null)return null;const n=new Int8Array(e.length);for(let s=0;s<e.length;s++)n[s]=t[e[s]];return n}const Bs=/[ \t\n\r\f]+/g,vs=/[\t\n\r\f]| {2,}|^ | $/;function ks(i){const e=i??"normal";return e==="pre-wrap"?{mode:e,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:e,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function Ls(i){if(!vs.test(i))return i;let e=i.replace(Bs," ");return e.charCodeAt(0)===32&&(e=e.slice(1)),e.length>0&&e.charCodeAt(e.length-1)===32&&(e=e.slice(0,-1)),e}function Os(i){return/[\r\f]/.test(i)?i.replace(/\r\n/g,`
89
84
  `).replace(/[\r\f]/g,`
90
- `):s}let Re=null,lr;function dr(){return Re===null&&(Re=new Intl.Segmenter(lr,{granularity:"word"})),Re}const ur=new RegExp("\\p{Script=Arabic}","u"),pt=new RegExp("\\p{M}","u"),Ie=new RegExp("\\p{Nd}","u");function Hn(s){return ur.test(s)}function _n(s){return s>=19968&&s<=40959||s>=13312&&s<=19903||s>=131072&&s<=173791||s>=173824&&s<=177983||s>=177984&&s<=178207||s>=178208&&s<=183983||s>=183984&&s<=191471||s>=191472&&s<=192093||s>=194560&&s<=195103||s>=196608&&s<=201551||s>=201552&&s<=205743||s>=205744&&s<=210041||s>=63744&&s<=64255||s>=12288&&s<=12351||s>=12352&&s<=12447||s>=12448&&s<=12543||s>=12592&&s<=12687||s>=44032&&s<=55215||s>=65280&&s<=65519}function at(s){for(let e=0;e<s.length;e++){const t=s.charCodeAt(e);if(!(t<12288)){if(t>=55296&&t<=56319&&e+1<s.length){const n=s.charCodeAt(e+1);if(n>=56320&&n<=57343){const i=(t-55296<<10)+(n-56320)+65536;if(_n(i))return!0;e++;continue}}if(_n(t))return!0}}return!1}function hr(s){const e=_t(s);return e!==null&&(He.has(e)||mt.has(e))}const xr=new Set(["Β ","β€―","⁠","\uFEFF"]),fr=new Set(["-","‐","–","β€”"]);function gr(s){const e=_t(s);return e!==null&&xr.has(e)}function pr(s){const e=_t(s);return e!==null&&fr.has(e)}function mr(s,e){return gr(s)?!1:e?!(hr(s)||pr(s)):!0}const He=new Set([",",".","!",":","οΌ›","?","、","。","・","οΌ‰","〕","〉","》","」","』","】","γ€—","γ€™","γ€›","γƒΌ","γ€…","γ€»","ゝ","γ‚ž","ヽ","γƒΎ"]),te=new Set(['"',"(","[","{","Β‘","ΒΏ","β€œ","β€˜","β€š","β€ž","Β«","β€Ή","⸘","(","γ€”","γ€ˆ","γ€Š","γ€Œ","γ€Ž","【","γ€–","γ€˜","γ€š"]),_e=new Set(["'","’"]),mt=new Set([".",",","!","?",":",";","،","Ψ›","؟","ΰ₯€","ΰ₯₯","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","Β»","β€Ί","…"]),yr=new Set([":",".","،","Ψ›"]),Sr=new Set(["၏"]),Fr=new Set(["”","’","Β»","β€Ί","」","』","】","》","〉","〕","οΌ‰"]);function Ar(s){if(ze(s))return!0;let e=!1;for(const t of s){if(mt.has(t)||ne(t)){e=!0;continue}if(!(e&&pt.test(t)))return!1}return e}function Er(s){for(const e of s)if(!He.has(e)&&!mt.has(e))return!1;return s.length>0}function Nr(s){if(ze(s))return!0;for(const e of s)if(!te.has(e)&&!_e.has(e)&&!pt.test(e)&&!ne(e))return!1;return s.length>0}function ze(s){let e=!1;for(const t of s)if(!(t==="\\"||pt.test(t))){if(te.has(t)||mt.has(t)||_e.has(t)){e=!0;continue}return!1}return e}function ee(s,e){const t=e-1;if(t<=0)return Math.max(t,0);const n=s.charCodeAt(t);if(n<56320||n>57343)return t;const i=t-1;if(i<0)return t;const r=s.charCodeAt(i);return r>=55296&&r<=56319?i:t}function _t(s){if(s.length===0)return null;const e=ee(s,s.length);return s.slice(e)}function Cr(s){for(const e of s)if(!pt.test(e))return e;return null}function wr(s){for(let e=s.length;e>0;){const t=ee(s,e),n=s.slice(t,e);if(!pt.test(n))return n;e=t}return null}const Mr=[36,37,43,43,92,92,162,165,176,177,1423,1423,1545,1547,1642,1642,2046,2047,2546,2547,2553,2555,2801,2801,3065,3065,3449,3449,3647,3647,6107,6107,8240,8247,8279,8279,8352,8399,8451,8451,8457,8457,8470,8470,8722,8723,43064,43064,65020,65020,65129,65130,65284,65285,65504,65505,65509,65510,73693,73696,123647,123647,126124,126124,126128,126128];function br(s,e){for(let t=0;t<e.length;t+=2)if(s>=e[t]&&s<=e[t+1])return!0;return!1}function ne(s){const e=s.codePointAt(0);return e!==void 0&&br(e,Mr)}function Dr(s){const e=wr(s);return e!==null&&ne(e)}function vr(s){const e=Cr(s);return e!==null&&Ie.test(e)}function Br(s){const e=Array.from(s);let t=e.length;for(;t>0;){const n=e[t-1];if(pt.test(n)){t--;continue}if(te.has(n)||_e.has(n)){t--;continue}break}return t<=0||t===e.length?null:{head:e.slice(0,t).join(""),tail:e.slice(t).join("")}}function kr(s,e,t){return t==="text"&&!e&&s.length===1&&s!=="-"&&s!=="β€”"?s:null}function zn(s,e,t,n){const i=e[n],r=s[n];if(i==null)return r;const o=t[n];if(r.length===o)return r;const a=i.repeat(o);return s[n]=a,a}function Wn(s,e){return s&&e!==null&&yr.has(e)}function Lr(s){const e=_t(s);return e!==null&&Sr.has(e)}function Tr(s){if(s.length<2||s[0]!==" ")return null;const e=s.slice(1);return new RegExp("^\\p{M}+$","u").test(e)?{space:" ",marks:e}:null}function We(s){let e=s.length;for(;e>0;){const t=ee(s,e),n=s.slice(t,e);if(Fr.has(n))return!0;if(!mt.has(n))return!1;e=t}return!1}function Or(s,e){if(e.preserveOrdinarySpaces||e.preserveHardBreaks){if(s===" ")return"preserved-space";if(s===" ")return"tab";if(e.preserveHardBreaks&&s===`
91
- `)return"hard-break"}return s===" "?"space":s==="Β "||s==="β€―"||s==="⁠"||s==="\uFEFF"?"glue":s==="​"?"zero-width-break":s==="Β­"?"soft-hyphen":"text"}const Pr=/[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;function st(s){return s.length===1?s[0]:s.join("")}function Rr(s,e){const t=[];for(let n=s.length-1;n>=0;n--)t.push(s[n]);return t.push(e),st(t)}function Ir(s,e,t,n){if(!Pr.test(s))return[{text:s,isWordLike:e,kind:"text",start:t}];const i=[];let r=null,o=[],a=t,d=!1,c=0;for(const l of s){const u=Or(l,n),h=u==="text"&&e;if(r!==null&&u===r&&h===d){o.push(l),c+=l.length;continue}r!==null&&i.push({text:st(o),isWordLike:d,kind:r,start:a}),r=u,o=[l],a=t+c,d=h,c+=l.length}return r!==null&&i.push({text:st(o),isWordLike:d,kind:r,start:a}),i}function $e(s){return s==="space"||s==="preserved-space"||s==="zero-width-break"||s==="hard-break"}const Hr=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function _r(s,e){const t=s.texts[e];return t.startsWith("www.")?!0:Hr.test(t)&&e+1<s.len&&s.kinds[e+1]==="text"&&s.texts[e+1]==="//"}function zr(s){return s.includes("?")&&(s.includes("://")||s.startsWith("www."))}function Wr(s){const e=s.texts.slice(),t=s.isWordLike.slice(),n=s.kinds.slice(),i=s.starts.slice();for(let o=0;o<s.len;o++){if(n[o]!=="text"||!_r(s,o))continue;const a=[e[o]];let d=o+1;for(;d<s.len&&!$e(n[d]);){a.push(e[d]),t[o]=!0;const c=e[d].includes("?");if(n[d]="text",e[d]="",d++,c)break}e[o]=st(a)}let r=0;for(let o=0;o<e.length;o++){const a=e[o];a.length!==0&&(r!==o&&(e[r]=a,t[r]=t[o],n[r]=n[o],i[r]=i[o]),r++)}return e.length=r,t.length=r,n.length=r,i.length=r,{len:r,texts:e,isWordLike:t,kinds:n,starts:i}}function $r(s){const e=[],t=[],n=[],i=[];for(let r=0;r<s.len;r++){const o=s.texts[r];if(e.push(o),t.push(s.isWordLike[r]),n.push(s.kinds[r]),i.push(s.starts[r]),!zr(o))continue;const a=r+1;if(a>=s.len||$e(s.kinds[a]))continue;const d=[],c=s.starts[a];let l=a;for(;l<s.len&&!$e(s.kinds[l]);)d.push(s.texts[l]),l++;d.length>0&&(e.push(st(d)),t.push(!0),n.push("text"),i.push(c),r=l-1)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}const Yr=new Set([":","-","/","Γ—",",",".","+","–","β€”"]),Xr=new Set([".",",",":",";"]);function $n(s){for(let e=s.length;e>0;){const t=ee(s,e),n=s.slice(t,e);if(pt.test(n)){e=t;continue}return Xr.has(n)||ne(n)}return!1}function Ur(s,e){return e&&!at(s)}function Yn(s){for(const e of s)if(Ie.test(e))return!0;return!1}function se(s){if(s.length===0)return!1;for(const e of s)if(!(Ie.test(e)||Yr.has(e)))return!1;return!0}function Gr(s){const e=[],t=[],n=[],i=[];for(let r=0;r<s.len;r++){const o=s.texts[r],a=s.kinds[r];if(a==="text"&&se(o)&&Yn(o)){const d=[o];let c=r+1;for(;c<s.len&&s.kinds[c]==="text"&&se(s.texts[c]);)d.push(s.texts[c]),c++;e.push(st(d)),t.push(!0),n.push("text"),i.push(s.starts[r]),r=c-1;continue}e.push(o),t.push(s.isWordLike[r]),n.push(a),i.push(s.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}function jr(s){const e=[],t=[],n=[],i=[];for(let r=0;r<s.len;r++){const o=s.texts[r],a=s.kinds[r],d=s.isWordLike[r];if(a==="text"&&$n(o)&&(d||Dr(o))&&!at(o)){const c=[o];let l=!0,u=r+1;for(;l&&u<s.len&&s.kinds[u]==="text"&&Ur(s.texts[u],s.isWordLike[u]);){const h=s.texts[u];c.push(h),l=$n(h),u++}e.push(st(c)),t.push(!0),n.push("text"),i.push(s.starts[r]),r=u-1;continue}e.push(o),t.push(d),n.push(a),i.push(s.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}function qr(s){const e=[],t=[],n=[],i=[];for(let r=0;r<s.len;r++){const o=s.texts[r];if(s.kinds[r]==="text"&&o.includes("-")){const a=o.split("-");let d=a.length>1;for(let c=0;c<a.length;c++){const l=a[c];if(!d)break;(l.length===0||!Yn(l)||!se(l))&&(d=!1)}if(d){let c=0;for(let l=0;l<a.length;l++){const u=a[l],h=l<a.length-1?`${u}-`:u;e.push(h),t.push(!0),n.push("text"),i.push(s.starts[r]+c),c+=h.length}continue}}e.push(o),t.push(s.isWordLike[r]),n.push(s.kinds[r]),i.push(s.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}function Vr(s){const e=[],t=[],n=[],i=[];let r=0;for(;r<s.len;){const o=[s.texts[r]];let a=s.isWordLike[r],d=s.kinds[r],c=s.starts[r];if(d==="glue"){const l=[o[0]],u=c;for(r++;r<s.len&&s.kinds[r]==="glue";)l.push(s.texts[r]),r++;const h=st(l);if(r<s.len&&s.kinds[r]==="text")o[0]=h,o.push(s.texts[r]),a=s.isWordLike[r],d="text",c=u,r++;else{e.push(h),t.push(!1),n.push("glue"),i.push(u);continue}}else r++;if(d==="text")for(;r<s.len&&s.kinds[r]==="glue";){const l=[];for(;r<s.len&&s.kinds[r]==="glue";)l.push(s.texts[r]),r++;const u=st(l);if(r<s.len&&s.kinds[r]==="text"){o.push(u,s.texts[r]),a=a||s.isWordLike[r],r++;continue}o.push(u)}e.push(st(o)),t.push(a),n.push(d),i.push(c)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}function Kr(s){const e=s.texts.slice(),t=s.isWordLike.slice(),n=s.kinds.slice(),i=s.starts.slice();for(let r=0;r<e.length-1;r++){if(n[r]!=="text"||n[r+1]!=="text"||!at(e[r])||!at(e[r+1]))continue;const o=Br(e[r]);o!==null&&(e[r]=o.head,e[r+1]=o.tail+e[r+1],i[r+1]=i[r]+o.head.length)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:i}}function Zr(s,e,t){const n=dr();let i=0;const r=[],o=[],a=[],d=[],c=[],l=[],u=[],h=[],x=[],g=[],f=[],p=[];for(const F of n.segment(s))for(const C of Ir(F.segment,F.isWordLike??!1,F.index,t)){let L=function(){l[b]!==null&&(o[b]=[zn(r,l,u,b)],l[b]=null),o[b].push(C.text),a[b]=a[b]||C.isWordLike,h[b]=h[b]||D,x[b]=x[b]||v,g[b]=R,f[b]=W,p[b]=Wn(x[b],O)};const M=C.kind==="text",B=kr(C.text,C.isWordLike,C.kind),D=at(C.text),v=Hn(C.text),O=_t(C.text),R=We(C.text),W=Lr(C.text),b=i-1;e.carryCJKAfterClosingQuote&&M&&i>0&&d[b]==="text"&&D&&h[b]&&g[b]||M&&i>0&&d[b]==="text"&&Er(C.text)&&h[b]||M&&i>0&&d[b]==="text"&&f[b]?L():M&&i>0&&d[b]==="text"&&C.isWordLike&&v&&p[b]?(L(),a[b]=!0):B!==null&&i>0&&d[b]==="text"&&l[b]===B?u[b]=(u[b]??1)+1:M&&!C.isWordLike&&i>0&&d[b]==="text"&&!h[b]&&(Ar(C.text)||C.text==="-"&&a[b])?L():(r[i]=C.text,o[i]=[C.text],a[i]=C.isWordLike,d[i]=C.kind,c[i]=C.start,l[i]=B,u[i]=B===null?0:1,h[i]=D,x[i]=v,g[i]=R,f[i]=W,p[i]=Wn(v,O),i++)}for(let F=0;F<i;F++){if(l[F]!==null){r[F]=zn(r,l,u,F);continue}r[F]=st(o[F])}for(let F=1;F<i;F++)d[F]==="text"&&!a[F]&&ze(r[F])&&d[F-1]==="text"&&!h[F-1]&&(r[F-1]+=r[F],a[F-1]=a[F-1]||a[F],r[F]="");const y=Array.from({length:i},()=>null);let A=-1;for(let F=i-1;F>=0;F--){const C=r[F];if(C.length!==0){if(d[F]==="text"&&!a[F]&&A>=0&&d[A]==="text"&&(Nr(C)||C==="-"&&vr(r[A]))){const M=y[A]??[];M.push(C),y[A]=M,c[A]=c[F],r[F]="";continue}A=F}}for(let F=0;F<i;F++){const C=y[F];C!=null&&(r[F]=Rr(C,r[F]))}let E=0;for(let F=0;F<i;F++){const C=r[F];C.length!==0&&(E!==F&&(r[E]=C,a[E]=a[F],d[E]=d[F],c[E]=c[F]),E++)}r.length=E,a.length=E,d.length=E,c.length=E;const w=Vr({len:E,texts:r,isWordLike:a,kinds:d,starts:c}),N=Kr(jr(qr(Gr($r(Wr(w))))));for(let F=0;F<N.len-1;F++){const C=Tr(N.texts[F]);C!==null&&(N.kinds[F]!=="space"&&N.kinds[F]!=="preserved-space"||N.kinds[F+1]!=="text"||!Hn(N.texts[F+1])||(N.texts[F]=C.space,N.isWordLike[F]=!1,N.kinds[F]=N.kinds[F]==="preserved-space"?"preserved-space":"space",N.texts[F+1]=C.marks+N.texts[F+1],N.starts[F+1]=N.starts[F]+C.space.length))}return N}function Jr(s,e){if(s.len===0)return[];if(!e.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:s.len,consumedEndSegmentIndex:s.len}];const t=[];let n=0;for(let i=0;i<s.len;i++)s.kinds[i]==="hard-break"&&(t.push({startSegmentIndex:n,endSegmentIndex:i,consumedEndSegmentIndex:i+1}),n=i+1);return n<s.len&&t.push({startSegmentIndex:n,endSegmentIndex:s.len,consumedEndSegmentIndex:s.len}),t}function Qr(s,e,t){if(e.len<=1)return e;const n=[],i=[],r=[],o=[];let a=-1,d=!1;function c(h){n.push(e.texts[h]),i.push(e.isWordLike[h]),r.push("text"),o.push(e.starts[h])}function l(h,x){let g=!1;for(let y=h;y<x;y++)g=g||e.isWordLike[y];const f=e.starts[h],p=x<e.len?e.starts[x]:s.length;n.push(s.slice(f,p)),i.push(g),r.push("text"),o.push(f)}function u(h){if(!(a<0)){if(d)a+1===h?c(a):l(a,h);else for(let x=a;x<h;x++)c(x);a=-1,d=!1}}for(let h=0;h<e.len;h++){const x=e.texts[h],g=e.kinds[h];if(g==="text"){a>=0&&!mr(e.texts[h-1],t)&&u(h),a<0&&(a=h),d=d||at(x);continue}u(h),n.push(x),i.push(e.isWordLike[h]),r.push(g),o.push(e.starts[h])}return u(e.len),{len:n.length,texts:n,isWordLike:i,kinds:r,starts:o}}function to(s,e,t="normal",n="normal"){const i=or(t),r=i.mode==="pre-wrap"?cr(s):ar(s);if(r.length===0)return{normalized:r,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};const o=Zr(r,e,i),a=n==="keep-all"?Qr(r,o,e.breakKeepAllAfterPunctuation):o;return{normalized:r,chunks:Jr(a,i),...a}}let Mt=null;const Xn=new Map;let bt=null;const eo=96,no=new RegExp("\\p{Emoji_Presentation}","u"),so=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;let Ye=null;const Un=new Map;function Xe(){if(Mt!==null)return Mt;if(typeof OffscreenCanvas<"u")return Mt=new OffscreenCanvas(1,1).getContext("2d"),Mt;if(typeof document<"u")return Mt=document.createElement("canvas").getContext("2d"),Mt;throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function io(s){let e=Xn.get(s);return e||(e=new Map,Xn.set(s,e)),e}function dt(s,e){let t=e.get(s);return t===void 0&&(t={width:Xe().measureText(s).width,containsCJK:at(s)},e.set(s,t)),t}function ie(){if(bt!==null)return bt;if(typeof navigator>"u")return bt={lineFitEpsilon:.005,carryCJKAfterClosingQuote:!1,breakKeepAllAfterPunctuation:!0,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},bt;const s=navigator.userAgent,t=navigator.vendor==="Apple Computer, Inc."&&s.includes("Safari/")&&!s.includes("Chrome/")&&!s.includes("Chromium/")&&!s.includes("CriOS/")&&!s.includes("FxiOS/")&&!s.includes("EdgiOS/"),n=s.includes("Chrome/")||s.includes("Chromium/")||s.includes("CriOS/")||s.includes("Edg/");return bt={lineFitEpsilon:t?1/64:.005,carryCJKAfterClosingQuote:n,breakKeepAllAfterPunctuation:!t,preferPrefixWidthsForBreakableRuns:t,preferEarlySoftHyphenBreak:t},bt}function ro(s){const e=s.match(/(\d+(?:\.\d+)?)\s*px/);return e?parseFloat(e[1]):16}function Gn(){return Ye===null&&(Ye=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Ye}function oo(s){return no.test(s)||s.includes("️")}function ao(s){return so.test(s)}function co(s,e){let t=Un.get(s);if(t!==void 0)return t;const n=Xe();n.font=s;const i=n.measureText("πŸ˜€").width;if(t=0,i>e+.5&&typeof document<"u"&&document.body!==null){const r=document.createElement("span");r.style.font=s,r.style.display="inline-block",r.style.visibility="hidden",r.style.position="absolute",r.textContent="πŸ˜€",document.body.appendChild(r);const o=r.getBoundingClientRect().width;document.body.removeChild(r),i-o>.5&&(t=i-o)}return Un.set(s,t),t}function lo(s){let e=0;const t=Gn();for(const n of t.segment(s))oo(n.segment)&&e++;return e}function uo(s,e){return e.emojiCount===void 0&&(e.emojiCount=lo(s)),e.emojiCount}function yt(s,e,t){return t===0?e.width:e.width-uo(s,e)*t}function ho(s,e,t,n,i){if(e.breakableFitAdvances!==void 0&&e.breakableFitMode===i)return e.breakableFitAdvances;e.breakableFitMode=i;const r=Gn(),o=[];for(const l of r.segment(s))o.push(l.segment);if(o.length<=1)return e.breakableFitAdvances=null,e.breakableFitAdvances;if(i==="sum-graphemes"){const l=[];for(const u of o){const h=dt(u,t);l.push(yt(u,h,n))}return e.breakableFitAdvances=l,e.breakableFitAdvances}if(i==="pair-context"||o.length>eo){const l=[];let u=null,h=0;for(const x of o){const g=dt(x,t),f=yt(x,g,n);if(u===null)l.push(f);else{const p=u+x,y=dt(p,t);l.push(yt(p,y,n)-h)}u=x,h=f}return e.breakableFitAdvances=l,e.breakableFitAdvances}const a=[];let d="",c=0;for(const l of o){d+=l;const u=dt(d,t),h=yt(d,u,n);a.push(h-c),c=h}return e.breakableFitAdvances=a,e.breakableFitAdvances}function xo(s,e){const t=Xe();t.font=s;const n=io(s),i=ro(s),r=e?co(s,i):0;return{cache:n,fontSize:i,emojiCorrection:r}}function fo(s){return s==="space"||s==="zero-width-break"||s==="soft-hyphen"}function jn(s){return s==="space"||s==="preserved-space"||s==="tab"||s==="zero-width-break"||s==="soft-hyphen"}function qn(s,e,t=s.widths.length){for(;e<t;){const n=s.kinds[e];if(!fo(n))break;e++}return e}function go(s,e){if(e<=0)return 0;const t=s%e;return Math.abs(t)<=1e-6?e:e-t}function po(s,e,t){return s.letterSpacing!==0&&e&&s.spacingGraphemeCounts[t]>0?s.letterSpacing:0}function Ue(s,e){return e===0?0:s+e}function mo(s,e){return s.letterSpacing!==0&&s.spacingGraphemeCounts[e]>0?s.letterSpacing:0}function yo(s,e,t,n,i){const r=e==="tab"?i+mo(s,t):s.lineEndFitAdvances[t];return Ue(n,r)}function Vn(s,e,t,n){const i=e==="tab"?0:s.lineEndFitAdvances[t];return Ue(n,i)}function Kn(s,e,t,n,i){const r=e==="tab"?i:s.lineEndPaintAdvances[t];return Ue(n,r)}function So(s,e,t){return s.letterSpacing!==0&&e?t+s.letterSpacing:t}function Fo(s,e){return s.letterSpacing===0?e:e+s.letterSpacing}function Ao(s,e,t,n,i){if(s.letterSpacing===0)return 0;if(i>0)return s.spacingGraphemeCounts[n]>0?s.letterSpacing:0;for(let r=n-1;r>=e;r--){const o=s.kinds[r];if(!(o==="space"||o==="zero-width-break"||o==="hard-break")){if(o==="soft-hyphen"){if(r===n-1)return 0;continue}return r===e&&t>0||s.spacingGraphemeCounts[r]>0?s.letterSpacing:0}}return 0}function Eo(s,e,t,n,i,r){return e+Ao(s,t,n,i,r)}function No(s,e,t){const{widths:n,kinds:i,breakableFitAdvances:r}=s;if(n.length===0)return 0;const a=ie().lineFitEpsilon,d=e+a;let c=0,l=0,u=!1,h=0,x=0,g=0,f=0,p=-1,y=0;function A(){p=-1,y=0}function E(B=g,D=f,v=l){c++,t==null||t(v,h,x,B,D),l=0,u=!1,A()}function w(B,D){u=!0,h=B,x=0,g=B+1,f=0,l=D}function N(B,D,v){u=!0,h=B,x=D,g=B,f=D+1,l=v}function F(B,D){if(!u){w(B,D);return}l+=D,g=B+1,f=0}function C(B,D){const v=r[B];for(let O=D;O<v.length;O++){const R=v[O];u?l+R>d?(E(),N(B,O,R)):(l+=R,g=B,f=O+1):N(B,O,R)}u&&g===B&&f===v.length&&(g=B+1,f=0)}let M=0;for(;M<n.length&&!(!u&&(M=qn(s,M),M>=n.length));){const B=n[M],D=i[M],v=jn(D);if(!u){B>d&&r[M]!==null?C(M,0):w(M,B),v&&(p=M+1,y=l-B),M++;continue}if(l+B>d){if(v){F(M,B),E(M+1,0,l-B),M++;continue}if(p>=0){if(g>p||g===p&&f>0){E();continue}E(p,0,y);continue}if(B>d&&r[M]!==null){E(),C(M,0),M++;continue}E();continue}F(M,B),v&&(p=M+1,y=l-B),M++}return u&&E(),c}function Co(s,e,t){if(s.simpleLineWalkFastPath)return No(s,e,t);const{widths:n,kinds:i,breakableFitAdvances:r,discretionaryHyphenWidth:o,chunks:a}=s;if(n.length===0||a.length===0)return 0;const d=ie(),c=d.lineFitEpsilon,l=e+c;let u=0,h=0,x=!1,g=0,f=0,p=0,y=0,A=-1,E=0,w=0,N=null;function F(){A=-1,E=0,w=0,N=null}function C(){return N==="soft-hyphen"&&A===p&&y===0?w:h}function M(b=p,L=y,k){u++,t!==void 0&&t(Eo(s,k??C(),g,f,b,L),g,f,b,L),h=0,x=!1,F()}function B(b,L){x=!0,g=b,f=0,p=b+1,y=0,h=L}function D(b,L,k){x=!0,g=b,f=L,p=b,y=L+1,h=k}function v(b,L){if(!x){B(b,L);return}h+=L,p=b+1,y=0}function O(b,L,k,H,j,K){if(!L)return;const V=Vn(s,b,k,j),ut=Kn(s,b,k,j,H);A=k+1,E=h-K+V,w=h-K+ut,N=b}function R(b,L){const k=r[b];for(let H=L;H<k.length;H++){const j=k[H];if(!x)D(b,H,j);else{const K=So(s,!0,j),V=h+K;Fo(s,V)>l?(M(),D(b,H,j)):(h=V,p=b,y=H+1)}}x&&p===b&&y===k.length&&(p=b+1,y=0)}function W(b){u++,t==null||t(0,b.startSegmentIndex,0,b.consumedEndSegmentIndex,0),F()}for(let b=0;b<a.length;b++){const L=a[b];if(L.startSegmentIndex===L.endSegmentIndex){W(L);continue}x=!1,h=0,g=L.startSegmentIndex,f=0,p=L.startSegmentIndex,y=0,F();let k=L.startSegmentIndex;for(;k<L.endSegmentIndex&&!(!x&&(k=qn(s,k,L.endSegmentIndex),k>=L.endSegmentIndex));){const H=i[k],j=jn(H),K=po(s,x,k),V=H==="tab"?go(h+K,s.tabStopAdvance):n[k],ut=K+V,qe=yo(s,H,k,K,V);if(H==="soft-hyphen"){x&&(p=k+1,y=0,A=k+1,E=h+o,w=h+o,N=H),k++;continue}if(!x){qe>l&&r[k]!==null?R(k,0):B(k,V),O(H,j,k,V,K,ut),k++;continue}if(h+qe>l){const Vo=h+Vn(s,H,k,K),Ko=h+Kn(s,H,k,K,V);if(N==="soft-hyphen"&&d.preferEarlySoftHyphenBreak&&E<=l){M(A,0,w);continue}if(j&&Vo<=l){v(k,ut),M(k+1,0,Ko),k++;continue}if(A>=0&&E<=l){if(p>A||p===A&&y>0){M();continue}const os=A;M(os,0,w),k=os;continue}if(qe>l&&r[k]!==null){M(),R(k,0),k++;continue}M();continue}v(k,ut),O(H,j,k,V,K,ut),k++}if(x){const H=A===L.consumedEndSegmentIndex?w:h;M(L.consumedEndSegmentIndex,0,H)}}return u}let Ge=null,Zn=new WeakMap;function wo(){return Ge===null&&(Ge=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Ge}function Jn(s,e,t){let n=t.get(s);if(n!==void 0)return n;n=[];const i=wo();for(const r of i.segment(e[s]))n.push(r.segment);return t.set(s,n),n}function Mo(s,e,t){return t>e&&s[t-1]==="soft-hyphen"}function Qn(s,e,t,n){for(let i=t;i<n;i++)s+=e[i];return s}function bo(s){let e=Zn.get(s);return e!==void 0||(e=new Map,Zn.set(s,e)),e}function Do(s,e,t,n,i,r){let o="";const a=Mo(s.kinds,t,i);for(let d=t;d<i;d++)if(!(s.kinds[d]==="soft-hyphen"||s.kinds[d]==="hard-break"))if(d===t&&n>0){const c=Jn(d,s.segments,e);o=Qn(o,c,n,c.length)}else o+=s.segments[d];if(r>0){a&&(o+="-");const d=Jn(i,s.segments,e);o=Qn(o,d,t===i?n:0,r)}else a&&(o+="-");return o}let je=null;function ts(){return je===null&&(je=new Intl.Segmenter(void 0,{granularity:"grapheme"})),je}function vo(s){return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]}}function Bo(s,e){const t=[];let n=[],i=0,r=!1,o=!1,a=!1;function d(){n.length!==0&&(t.push({text:n.length===1?n[0]:n.join(""),start:i}),n=[],r=!1,o=!1,a=!1)}function c(u,h,x){n=[u],i=h,r=x,o=We(u),a=te.has(u)}function l(u,h){n.push(u),r=r||h;const x=We(u);u.length===1&&mt.has(u)?o=o||x:o=x,a=!1}for(const u of ts().segment(s)){const h=u.segment,x=at(h);if(n.length===0){c(h,u.index,x);continue}if(a||He.has(h)||mt.has(h)||e.carryCJKAfterClosingQuote&&x&&o){l(h,x);continue}if(!r&&!x){l(h,x);continue}d(),c(h,u.index,x)}return d(),t}function es(s,e){if(e==="zero-width-break"||e==="soft-hyphen"||e==="hard-break")return 0;if(e==="tab")return 1;let t=0;const n=ts();for(const i of n.segment(s))t++;return t}function ko(s,e,t){return e>1?s+(e-1)*t:s}function Lo(s,e,t,n,i){const r=ie(),{cache:o,emojiCorrection:a}=xo(e,ao(s.normalized)),d=yt("-",dt("-",o),a)+(i===0?0:i*2),l=yt(" ",dt(" ",o),a)*8,u=i!==0;if(s.len===0)return vo();const h=[],x=[],g=[],f=[];let p=s.chunks.length<=1&&!u;const y=t?[]:null,A=[],E=[],w=t?[]:null,N=Array.from({length:s.len});function F(D,v,O,R,W,b,L,k){W!=="text"&&W!=="space"&&W!=="zero-width-break"&&(p=!1),h.push(v),x.push(O),g.push(R),f.push(W),y==null||y.push(b),A.push(L),u&&E.push(k),w!==null&&w.push(D)}function C(D,v,O,R,W){const b=dt(D,o),L=u?es(D,v):0,k=ko(yt(D,b,a),L,i),H=v==="space"||v==="preserved-space"||v==="zero-width-break"?0:k,j=H===0?0:H+(L>0?i:0),K=v==="space"||v==="zero-width-break"?0:k;if(W&&R&&D.length>1){let V="sum-graphemes";i!==0?V="segment-prefixes":se(D)?V="pair-context":r.preferPrefixWidthsForBreakableRuns&&(V="segment-prefixes");const ut=ho(D,b,o,a,V);F(D,k,j,K,v,O,ut,L);return}F(D,k,j,K,v,O,null,L)}for(let D=0;D<s.len;D++){N[D]=h.length;const v=s.texts[D],O=s.isWordLike[D],R=s.kinds[D],W=s.starts[D];if(R==="soft-hyphen"){F(v,0,d,d,R,W,null,0);continue}if(R==="hard-break"){F(v,0,0,0,R,W,null,0);continue}if(R==="tab"){F(v,0,0,0,R,W,null,u?es(v,R):0);continue}const b=dt(v,o);if(R==="text"&&b.containsCJK){const k=Bo(v,r);for(let H=0;H<k.length;H++){const j=k[H];C(j.text,"text",W+j.start,O,!at(j.text))}continue}C(v,R,W,O,!0)}const M=To(s.chunks,N,h.length),B=y===null?null:sr(s.normalized,y);return w!==null?{widths:h,lineEndFitAdvances:x,lineEndPaintAdvances:g,kinds:f,simpleLineWalkFastPath:p,segLevels:B,breakableFitAdvances:A,letterSpacing:i,spacingGraphemeCounts:E,discretionaryHyphenWidth:d,tabStopAdvance:l,chunks:M,segments:w}:{widths:h,lineEndFitAdvances:x,lineEndPaintAdvances:g,kinds:f,simpleLineWalkFastPath:p,segLevels:B,breakableFitAdvances:A,letterSpacing:i,spacingGraphemeCounts:E,discretionaryHyphenWidth:d,tabStopAdvance:l,chunks:M}}function To(s,e,t){const n=[];for(let i=0;i<s.length;i++){const r=s[i],o=r.startSegmentIndex<e.length?e[r.startSegmentIndex]:t,a=r.endSegmentIndex<e.length?e[r.endSegmentIndex]:t,d=r.consumedEndSegmentIndex<e.length?e[r.consumedEndSegmentIndex]:t;n.push({startSegmentIndex:o,endSegmentIndex:a,consumedEndSegmentIndex:d})}return n}function Oo(s,e,t,n){const i=n==null?void 0:n.wordBreak,r=(n==null?void 0:n.letterSpacing)??0,o=to(s,ie(),n==null?void 0:n.whiteSpace,i);return Lo(o,e,t,i,r)}function Po(s,e,t){return Oo(s,e,!0,t)}function Qo(s){return s}function Ro(s,e,t,n,i,r,o){return{text:Do(s,e,n,i,r,o),width:t,start:{segmentIndex:n,graphemeIndex:i},end:{segmentIndex:r,graphemeIndex:o}}}function Io(s,e,t){const n=[];if(s.widths.length===0)return{lineCount:0,height:0,lines:n};const i=bo(s),r=Co(s,e,(o,a,d,c,l)=>{n.push(Ro(s,i,o,a,d,c,l))});return{lineCount:r,height:r*t,lines:n}}function Ho(s,e,t,n){const{width:i,height:r}=X(e),{color:o=q.color,strokeColor:a=q.strokeColor,strokeWidth:d=q.strokeWidth,strokeType:c=q.strokeType,background:l=q.background,borderRadius:u=q.borderRadius,fixedSize:h=q.fixedSize}=e.properties.style||q,x=Rn(s,e,t,n);x.setAttribute("data-annotation-type",e.properties.type),x.classList.add("annotation-text"),x.setAttribute("fill",`${o}`);let g=x.firstChild;for(;g;){const E=g.nextSibling;g.nodeType===1&&g.tagName!=="rect"&&x.removeChild(g),g=E}let f=x.firstChild;f||(f=T("rect"),x.appendChild(f));const p=-i/2,y=-r/2;u&&(f.setAttribute("rx",`${u}`),f.setAttribute("ry",`${u}`)),c&&c!=="none"&&(f.setAttribute("stroke",a||"black"),f.setAttribute("stroke-width",`${d}`),c==="dashed"&&f.setAttribute("stroke-dasharray","5,5")),l&&l.length&&(n.hoveredFeature===e.id?f.setAttribute("fill",At(l)):f.setAttribute("fill",l)),f.setAttribute("width",`${i}`),f.setAttribute("height",`${r}`);const A=J(e);return f.setAttribute("x",`${p}`),f.setAttribute("y",`${y}`),zo(e,x,p,y),x.setAttribute("transform",n.getScreenAlignedTransform(A.x,A.y,!h)),s.appendChild(x),x}let zt=null;const ns=new Map;function _o(s,e){const t=`${s}|${e}`,n=ns.get(t);if(n!=null)return n;try{const i=document.createElement("div"),r=document.createElement("span");i.style.cssText=`font:${s};line-height:${e}px;position:fixed;left:-9999px;top:0;margin:0;padding:0;visibility:hidden;`,r.style.cssText="display:inline-block;width:1px;height:1px;vertical-align:baseline;",i.appendChild(r),document.body.appendChild(i);const o=r.getBoundingClientRect().bottom-i.getBoundingClientRect().top;if(document.body.removeChild(i),o>0&&o<=e)return ns.set(t,o),o}catch{}try{if(zt||(zt=document.createElement("canvas").getContext("2d")),zt){zt.font=s;const i=zt.measureText("M"),r=i.fontBoundingBoxAscent,o=i.fontBoundingBoxDescent;if(r!=null&&o!=null)return Math.max(0,(e-r-o)/2)+r}}catch{}return e}function zo(s,e,t=0,n=0){const{width:i,height:r}=X(s),{fontSize:o=q.fontSize,font:a=q.font,padding:d=0}=s.properties.style||{};if(i===r&&i===0)return;const c=parseFloat(o.toString())*Xt,l=`${o}px ${a}`.replace(/(px)+/g,"px"),u=i-d*2,h=r-d,x=s.properties.content||"";if(x.length===0)return;const g=Po(x,l,{whiteSpace:"pre-wrap",wordBreak:"normal"}),{lines:f}=Io(g,u,c),p=Math.max(1,Math.floor(h/c)),y=f.slice(0,p);if(f.length>p&&y.length>0){const w=y[y.length-1];y[y.length-1]={...w,text:w.text.trimEnd()+"…"}}const A=T("text");A.setAttribute("font-size",`${parseFloat(o.toString())}`),A.setAttribute("font-family",`${a}`),A.setAttribute("transform",`translate(${t+d}, ${n+d})`);const E=_o(l,c);y.forEach((w,N)=>{const F=T("tspan");F.setAttribute("x","0"),F.setAttribute("dy",`${N===0?E:c}`);let C=0,M;const B=Sn();for(;(M=B.exec(w.text))!==null;){M.index>C&&F.appendChild(document.createTextNode(w.text.slice(C,M.index)));const D=document.createElementNS("http://www.w3.org/2000/svg","a");D.setAttribute("href",M[0]),D.setAttribute("target","_blank"),D.setAttribute("rel","noopener noreferrer"),D.setAttribute("class",ke),D.textContent=M[0],F.appendChild(D),C=M.index+M[0].length}C<w.text.length&&F.appendChild(document.createTextNode(w.text.slice(C))),A.appendChild(F)}),e.appendChild(A)}class Wo extends kn{constructor(t,n){super(t,n);m(this,"features",new Map);m(this,"arrowsRoot",null);m(this,"shapesRoot",null);m(this,"commentsRoot",null);m(this,"annotationsRoot",null);m(this,"visibleFeatures",new Set);m(this,"isExporting",!1);m(this,"render",t=>{if(!t)return;const{features:n,hoveredFeature:i,selectedFeatures:r,liveUpdates:o}=this.store.getState();(!this.annotationsRoot||!t.contains(this.annotationsRoot))&&(t.innerHTML="",t.appendChild(this.getDefs()),this.arrowsRoot=T("g"),this.commentsRoot=T("g"),this.annotationsRoot=T("g"),this.shapesRoot=T("g"),this.annotationsRoot.appendChild(this.arrowsRoot),this.annotationsRoot.appendChild(this.shapesRoot),this.annotationsRoot.appendChild(this.commentsRoot),t.appendChild(this.annotationsRoot)),t.removeChild(this.annotationsRoot);const a=this.arrowsRoot,d=this.annotationsRoot,c=this.commentsRoot,l=this.shapesRoot,u=this.store.getState(),h=this.getViewportBounds(),x=new Set(Object.keys(n));this.removeFeatures(x);const g=new Set;for(let f of Object.values(n)){if(o[f.id]&&(f={...f,...o[f.id]}),!this.isExporting&&!this.isFeatureVisible(f,h))continue;g.add(f.id);let p=this.features.get(f.id);G(f)?p=Rn(l,f,p,u):_(f)?p=Ho(l,f,p,u):I(f)?p=Ki(c,f,p,u,this.visibleFeatures.has(f.id)):nt(f)?p=Qi(l,f,p,u):tt(f)&&(p=$i(a,f,u.options.minArrowHeight,u.options.maxArrowHeight,p,u)),p&&this.features.set(f.id,p)}this.applyStateClasses(d,i,r),t.appendChild(d),this.visibleFeatures.clear(),this.visibleFeatures=g});m(this,"throttleRender",Se(()=>this.render(this.layer.element),16,!0));m(this,"refresh",()=>{this.layer.refresh()});m(this,"onExportStart",()=>{this.isExporting=!0});m(this,"onExportEnd",()=>{this.isExporting=!1});t.events.on("viewExportStart",this.onExportStart),t.events.on("afterImageExport",this.onExportEnd),this.layer=this.ogma.layers.addSVGLayer({draw:this.render},Yt.SHAPES),this.store.subscribe(i=>({features:i.features,liveUpdates:i.liveUpdates,hoveredFeature:i.hoveredFeature,selectedFeatures:i.selectedFeatures,editingFeature:i.editingFeature,rotation:i.rotation,zoom:i.zoom}),this.throttleRender,{equalityFn:(i,r)=>i.features===r.features&&i.liveUpdates===r.liveUpdates&&i.hoveredFeature===r.hoveredFeature&&i.selectedFeatures===r.selectedFeatures&&i.editingFeature===r.editingFeature&&i.rotation===r.rotation&&i.zoom===r.zoom})}getViewportBounds(){const t=this.ogma;let n=null;try{n=t.view.getSize()}catch{return[0,0,0,0]}if(!n)return[0,0,0,0];const{width:i,height:r}=n,o=1.5,a=t.view.screenToGraphCoordinates({x:0,y:0}),d=t.view.screenToGraphCoordinates({x:i*o,y:0}),c=t.view.screenToGraphCoordinates({x:0,y:r*o}),l=t.view.screenToGraphCoordinates({x:i*o,y:r*o});return[Math.min(a.x,d.x,c.x,l.x),Math.min(a.y,d.y,c.y,l.y),Math.max(a.x,d.x,c.x,l.x),Math.max(a.y,d.y,c.y,l.y)]}isFeatureVisible(t,n){const i=t.geometry.bbox;if(!i)return!0;const[r,o,a,d]=i;return!(a<n[0]||r>n[2]||d<n[1]||o>n[3])}getDefs(){const t=T("defs");t.appendChild(Gi());const n=T("filter");n.setAttribute("id","softShadow"),n.setAttribute("x","-50%"),n.setAttribute("y","-50%"),n.setAttribute("width","200%"),n.setAttribute("height","200%");const i=T("feGaussianBlur");i.setAttribute("in","SourceAlpha"),i.setAttribute("stdDeviation","2"),i.setAttribute("result","blur");const r=T("feOffset");r.setAttribute("in","blur"),r.setAttribute("dx","0"),r.setAttribute("dy","1"),r.setAttribute("result","offsetBlur");const o=T("feComponentTransfer");o.setAttribute("in","offsetBlur"),o.setAttribute("result","shadow");const a=T("feFuncA");a.setAttribute("type","linear"),a.setAttribute("slope","0.25"),o.appendChild(a);const d=T("feMerge"),c=T("feMergeNode");c.setAttribute("in","shadow");const l=T("feMergeNode");return l.setAttribute("in","SourceGraphic"),d.appendChild(c),d.appendChild(l),n.appendChild(i),n.appendChild(r),n.appendChild(o),n.appendChild(d),t.appendChild(n),t}removeFeatures(t){for(const n of this.features.keys())if(!t.has(n)){const i=this.features.get(n);i&&i.parentNode&&i.parentNode.removeChild(i),this.features.delete(n)}}applyStateClasses(t,n,i){if(n!==null){const r=t.querySelector(`[data-annotation="${n}"]`);r&&r.classList.add("annotation-hovered")}i.forEach(r=>{const o=t.querySelector(`[data-annotation="${r}"]`);o&&o.classList.add("annotation-selected")})}destroy(){this.features.clear(),this.layer.destroy(),this.ogma.events.off(this.onExportStart),this.ogma.events.off(this.onExportEnd),super.destroy()}}const ss=s=>{let e;const t=new Set,n=(c,l)=>{const u=typeof c=="function"?c(e):c;if(!Object.is(u,e)){const h=e;e=l??(typeof u!="object"||u===null)?u:Object.assign({},e,u),t.forEach(x=>x(e,h))}},i=()=>e,a={setState:n,getState:i,getInitialState:()=>d,subscribe:c=>(t.add(c),()=>t.delete(c))},d=e=s(n,i,a);return a},is=s=>s?ss(s):ss;var rs=(s,e,t)=>(i,r)=>({pastStates:(t==null?void 0:t.pastStates)||[],futureStates:(t==null?void 0:t.futureStates)||[],undo:(o=1)=>{var a,d;if(r().pastStates.length){const c=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),l=r().pastStates.splice(-o,o),u=l.shift();s(u),i({pastStates:r().pastStates,futureStates:r().futureStates.concat(((d=t==null?void 0:t.diff)==null?void 0:d.call(t,c,u))||c,l.reverse())})}},redo:(o=1)=>{var a,d;if(r().futureStates.length){const c=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),l=r().futureStates.splice(-o,o),u=l.shift();s(u),i({pastStates:r().pastStates.concat(((d=t==null?void 0:t.diff)==null?void 0:d.call(t,c,u))||c,l.reverse()),futureStates:r().futureStates})}},clear:()=>i({pastStates:[],futureStates:[]}),isTracking:!0,pause:()=>i({isTracking:!1}),resume:()=>i({isTracking:!0}),setOnSave:o=>i({_onSave:o}),_onSave:t==null?void 0:t.onSave,_handleSet:(o,a,d,c)=>{var l,u;t!=null&&t.limit&&r().pastStates.length>=(t==null?void 0:t.limit)&&r().pastStates.shift(),(u=(l=r())._onSave)==null||u.call(l,o,d),i({pastStates:r().pastStates.concat(c||o),futureStates:[]})}}),$o=(s,e)=>(n,i,r)=>{var c,l;r.temporal=is(((c=e==null?void 0:e.wrapTemporal)==null?void 0:c.call(e,rs(n,i,e)))||rs(n,i,e));const o=((l=e==null?void 0:e.handleSet)==null?void 0:l.call(e,r.temporal.getState()._handleSet))||r.temporal.getState()._handleSet,a=u=>{var g,f,p;if(!r.temporal.getState().isTracking)return;const h=((g=e==null?void 0:e.partialize)==null?void 0:g.call(e,i()))||i(),x=(f=e==null?void 0:e.diff)==null?void 0:f.call(e,u,h);x===null||(p=e==null?void 0:e.equality)!=null&&p.call(e,u,h)||o(u,void 0,h,x)},d=r.setState;return r.setState=(...u)=>{var x;const h=((x=e==null?void 0:e.partialize)==null?void 0:x.call(e,i()))||i();d(...u),a(h)},s((...u)=>{var x;const h=((x=e==null?void 0:e.partialize)==null?void 0:x.call(e,i()))||i();n(...u),a(h)},i,r)};const Yo=s=>(e,t,n)=>{const i=n.subscribe;return n.subscribe=(o,a,d)=>{let c=o;if(a){const l=(d==null?void 0:d.equalityFn)||Object.is;let u=o(n.getState());c=h=>{const x=o(h);if(!l(u,x)){const g=u;a(u=x,g)}},d!=null&&d.fireImmediately&&a(u,u)}return i(c)},s(e,t,n)},Xo=[0,0,0,0];function Uo(s,e){const t=Object.keys(s.features),n=Object.keys(e.features);if(t.length!==n.length)return!1;for(const i of t)if(!(i in e.features))return!1;for(const i of t){const r=s.features[i],o=e.features[i],a=r.geometry,d=o.geometry;if(a.coordinates!==d.coordinates||r.properties!==o.properties||r.properties.style!==o.properties.style||a!==d)return!1}return s.drawingFeature===e.drawingFeature}const Go=s=>{const e=is()(Yo($o((t,n)=>({features:{},liveUpdates:{},isDragging:!1,hoveringHandle:!1,hoveredHandle:-1,hoveredFeature:null,selectedFeatures:new Set,lastChangedFeatures:[],drawingFeature:null,drawingPoints:null,editingFeature:null,mousePressed:!1,mousePressPoint:null,rotation:0,sin:0,cos:1,revRotation:0,revSin:0,revCos:1,zoom:1,invZoom:1,options:{showSendButton:(s==null?void 0:s.showSendButton)??!0,sendButtonIcon:(s==null?void 0:s.sendButtonIcon)??le,showEditButton:(s==null?void 0:s.showEditButton)??!0,editButtonIcon:(s==null?void 0:s.editButtonIcon)??de,minArrowHeight:(s==null?void 0:s.minArrowHeight)??20,maxArrowHeight:(s==null?void 0:s.maxArrowHeight)??30,detectMargin:(s==null?void 0:s.detectMargin)??2,magnetRadius:(s==null?void 0:s.magnetRadius)??10,magnetHandleRadius:(s==null?void 0:s.magnetHandleRadius)??5,textPlaceholder:(s==null?void 0:s.textPlaceholder)??"Type here"},setOptions:i=>t(r=>({options:{...r.options,...i}})),removeFeature:i=>t(r=>{var h,x,g,f;const o=r.features[i];if(!o)return r;const{features:a,liveUpdates:d}=r,c=new Set([i]);if((I(o)||_(o))&&Object.values(a).forEach(p=>{var y,A,E,w;tt(p)&&(((A=(y=p.properties.link)==null?void 0:y.end)==null?void 0:A.id)===i||((w=(E=p.properties.link)==null?void 0:E.start)==null?void 0:w.id)===i)&&c.add(p.id)}),tt(o)){const p=((x=(h=o.properties.link)==null?void 0:h.end)==null?void 0:x.type)==="comment"?o.properties.link.end.id:((f=(g=o.properties.link)==null?void 0:g.start)==null?void 0:f.type)==="comment"?o.properties.link.start.id:null;if(p){let y=0;if(Object.values(r.features).forEach(A=>{var E,w,N,F;tt(A)&&A.id!==i&&(((w=(E=A.properties.link)==null?void 0:E.end)==null?void 0:w.id)===p||((F=(N=A.properties.link)==null?void 0:N.start)==null?void 0:F.id)===p)&&y++}),y===0)return console.error("Cannot delete last arrow attached to comment. Delete the comment instead."),r}}const l={...a},u={...d};return c.forEach(p=>{delete l[p],delete u[p]}),{features:l,liveUpdates:u}}),addFeature:i=>t(r=>({features:{...r.features,[i.id]:i}})),startLiveUpdate:i=>{t(r=>({liveUpdates:i.reduce((o,a)=>({...o,[a]:{...r.features[a]}}),{})}))},applyLiveUpdate:(i,r)=>{t(o=>({liveUpdates:{...o.liveUpdates,[i]:{...o.liveUpdates[i],...r}}}))},applyLiveUpdates:i=>{t(r=>{const o={...r.liveUpdates};for(const a in i)o[a]=i[a];return{liveUpdates:o}})},commitLiveUpdates:i=>{const{features:r,liveUpdates:o}=n(),a={...r},d=[],c=Object.keys(o);i||(i=new Set(c)),c.forEach(l=>{const u=o[l];a[l]&&Object.keys(u).length>0&&(a[l]={...a[l],...u},d.push(l))}),t({features:a,liveUpdates:{},isDragging:!1,lastChangedFeatures:d})},cancelLiveUpdates:()=>t({liveUpdates:{},isDragging:!1}),updateFeature:(i,r)=>t(o=>{const a={...o.features[i],...r},d={...o.liveUpdates};return delete d[i],{features:{...o.features,[i]:a},liveUpdates:d}}),updateFeatures:i=>t(r=>{const o={...r.features};return Object.entries(i).forEach(([a,d])=>{o[a]&&(o[a]={...o[a],...d})}),{features:o}}),batchUpdate:i=>{const r=e.temporal.getState();r.pause(),i(),r.resume()},getFeature:i=>n().features[i],getMergedFeature:i=>{const r=n().features[i],o=n().liveUpdates[i];if(r)return o?{...r,...o}:r},getAllFeatures:()=>{const{features:i,liveUpdates:r}=n();return Object.entries(i).map(([o,a])=>{const d=r[o];return d?{...a,...d}:a})},setHoveredFeature:i=>t({hoveredFeature:i}),setSelectedFeatures:i=>t({selectedFeatures:new Set(i)}),addToSelection:i=>{const{selectedFeatures:r}=n(),o=new Set(r);o.add(i),t({selectedFeatures:o})},removeFromSelection:i=>{const{selectedFeatures:r}=n(),o=new Set(r);o.delete(i),t({selectedFeatures:o})},toggleSelection:i=>{const{selectedFeatures:r}=n(),o=new Set(r);o.has(i)?o.delete(i):o.add(i),t({selectedFeatures:o})},clearSelection:()=>t({selectedFeatures:new Set}),isHovered:i=>n().hoveredFeature===i,isSelected:i=>n().selectedFeatures.has(i),setRotation:i=>{t({rotation:i,sin:Math.sin(i),cos:Math.cos(i),revRotation:-i,revSin:Math.sin(-i),revCos:Math.cos(-i)})},setZoom:i=>{t({zoom:i,invZoom:1/i})},getScreenAlignedTransform(i,r,o=!0){const a=this.revSin,d=this.revCos,c=i*d-r*a,l=i*a+r*d,u=o?1:this.invZoom;return`matrix(${u}, 0, 0, ${u}, ${c}, ${l})`},getRotationTransform(i,r){const o=this.revSin,a=this.revCos,d=i*a-r*o,c=i*o+r*a;return`matrix(${a}, ${o}, ${-o}, ${a}, ${-d}, ${-c})`},getRotatedBBox(i,r,o,a){return zs(i,r,o-i,a-r,this.sin,this.cos,i+(o-i)/2,r+(a-r)/2,Xo)},setDrawingPoints:i=>t({drawingPoints:i})}),{limit:250,partialize:t=>({drawingFeature:t.drawingFeature,isDragging:t.isDragging,features:t.features,lastChangedFeatures:t.lastChangedFeatures}),equality:Uo,handleSet:t=>n=>{n.drawingFeature===null&&t(n)}})));return e},jo={detectMargin:2,magnetHandleRadius:5,magnetRadius:10,textPlaceholder:"Type here",showSendButton:!0,sendButtonIcon:le,showEditButton:!0,editButtonIcon:de,minArrowHeight:20,maxArrowHeight:30};class qo extends ls{constructor(t,n={}){super();m(this,"ogma");m(this,"store");m(this,"renderers",{});m(this,"interactions");m(this,"editor");m(this,"links");m(this,"index");m(this,"drawing");m(this,"snapping");m(this,"selectionManager");m(this,"historyManager");m(this,"updateManager");m(this,"commentManager");m(this,"onRotate",()=>this.store.getState().setRotation(this.ogma.view.getAngle()));m(this,"onZoom",()=>{const t=this.ogma.view.getZoom();this.store.getState().setZoom(t),this.commentManager.updateCommentModesForZoom(t)});m(this,"onLayout",()=>{this.links.update()});this.ogma=t;const i={...jo,...n};this.store=Go(i),this.index=new Ii(this.store),this.snapping=new Di(this.ogma,{detectMargin:n.detectMargin===void 0?10:n.detectMargin,magnetRadius:n.magnetRadius===void 0?10:n.magnetRadius},this.index,this.store),this.links=new fi(this.ogma,this.snapping,this.store,(r,o)=>{this.emit(en,{arrow:r,link:o})}),this.interactions=new vi(this.ogma,this.store,this.index),this.editor=new di(this.ogma,this.store,this.snapping,this.links,this.interactions),this.drawing=new Js(this.ogma,this.store,this.editor,this.interactions,this.links,this,this.index),this.selectionManager=new ti(this.store),this.historyManager=new Qs(this.store,this.links),this.updateManager=new ei(this.store),this.commentManager=new js(this.store),this.initializeRenderers(),this.setupEvents()}initializeRenderers(){this.renderers.shapes=new Wo(this.ogma,this.store),this.renderers.handles=new Hi(this.ogma,this.store)}setupEvents(){this.ogma.events.on("rotate",this.onRotate).on("zoom",this.onZoom).on("layoutEnd",this.onLayout),this.editor.addEventListener(Ft,t=>this.emit(Ft,{id:t.detail.id,position:t.detail.position})),this.editor.addEventListener(vt,t=>this.emit(vt,{id:t.detail.id,position:t.detail.position})),this.interactions.addEventListener(Wt,(t=>this.emit(Wt,{id:t.detail.id,position:t.detail.position}))),this.store.temporal.subscribe(t=>{this.emit(nn,{canUndo:t.pastStates.length>0,canRedo:t.futureStates.length>0})}),this.store.subscribe(t=>t.selectedFeatures,(t,n)=>{const i=Array.from(t).filter(r=>!(n!=null&&n.has(r)));if(i.length>0&&this.emit(Ke,{ids:i}),n){const r=Array.from(n).filter(o=>!t.has(o));r.length>0&&this.emit(Ze,{ids:r})}}),this.store.subscribe(t=>t.drawingFeature,(t,n)=>{t===null&&n!==null&&this.emit(oe,{id:n})}),this.store.subscribe(t=>t.features,(t,n)=>{for(const i of Object.keys(t))n[i]?n[i]!==t[i]&&this.emit(tn,t[i]):this.emit($t,{id:i});for(const i of Object.keys(n))t[i]||this.emit(Je,{id:i})})}setOptions(t={}){return this.store.getState().setOptions(t),this.store.getState().options}add(t){return this.updateManager.add(t),this}remove(t){return this.updateManager.remove(t),this}undo(){return this.historyManager.undo()}redo(){return this.historyManager.redo()}canUndo(){return this.historyManager.canUndo()}canRedo(){return this.historyManager.canRedo()}clearHistory(){this.historyManager.clearHistory()}getAnnotations(){return this.updateManager.getAnnotations()}select(t){return this.selectionManager.select(t),this}unselect(t){return this.selectionManager.unselect(t),this}cancelDrawing(){var t;return this.drawing.cancelPendingDrawing(),(t=this.editor.getActiveHandler())==null||t.cancelDrawing(),this.emit(Qe),this}enableArrowDrawing(t){return this.drawing.enableArrowDrawing(t),this}enableTextDrawing(t){return this.drawing.enableTextDrawing(t),this}enableBoxDrawing(t){return this.drawing.enableBoxDrawing(t),this}enablePolygonDrawing(t){return this.drawing.enablePolygonDrawing(t),this}enableCommentDrawing(t={}){return this.drawing.enableCommentDrawing(t),this}enablePlacement(t){return this.drawing.enablePlacement(t),this}startComment(t,n,i,r){return this.drawing.startComment(t,n,i,r),this}startBox(t,n,i){return this.drawing.startBox(t,n,i),this}startArrow(t,n,i){return this.drawing.startArrow(t,n,i),this}startText(t,n,i){return this.drawing.startText(t,n,i),this}startPolygon(t,n,i){return this.drawing.startPolygon(t,n,i),this}getSelectedAnnotations(){return this.selectionManager.getSelectedAnnotations()}getSelected(){return this.selectionManager.getSelected()}getAnnotation(t){return this.updateManager.getAnnotation(t)}setScale(t,n,i,r){return this.updateManager.setScale(t,n,i,r),this}toggleComment(t){return this.commentManager.toggleComment(t),this}destroy(){this.ogma.events.off(this.onRotate).off(this.onZoom),this.links.destroy(),Object.values(this.renderers).forEach(t=>t.destroy()),this.interactions.destroy(),this.editor.destroy()}updateStyle(t,n){return this.updateManager.updateStyle(t,n),this}update(t){return this.updateManager.update(t),this}link(t,n,i=it){const r=this.getAnnotation(t);if(!r)throw new Error(`Arrow with id ${t} not found`);return this.editor.getArrowHandler().link(r,n,i),this}isDrawing(){return this.drawing.isDrawing()}}S.COMMENT_MODE_COLLAPSED=rt,S.COMMENT_MODE_EXPANDED=Bt,S.Control=qo,S.DATA_ATTR=xs,S.DEFAULT_EDIT_ICON=de,S.DEFAULT_SEND_ICON=le,S.EVT_ADD=$t,S.EVT_CANCEL_DRAWING=Qe,S.EVT_CLICK=Wt,S.EVT_COMPLETE_DRAWING=oe,S.EVT_DRAG=Dt,S.EVT_DRAG_END=vt,S.EVT_DRAG_START=Ft,S.EVT_HISTORY=nn,S.EVT_HOVER=us,S.EVT_LINK=en,S.EVT_REMOVE=Je,S.EVT_SELECT=Ke,S.EVT_UNHOVER=hs,S.EVT_UNSELECT=Ze,S.EVT_UPDATE=tn,S.HL_BRIGHTEN=ce,S.LAYERS=Yt,S.NONE=ds,S.SIDE_END=it,S.SIDE_START=$,S.TARGET_TYPES=P,S.TEXT_LINE_HEIGHT=Xt,S.adjustColorBrightness=Fe,S.asColor=Ys,S.asHexColor=Xs,S.asRgbColor=Us,S.asRgbaColor=Gs,S.brighten=At,S.calculateCommentZoomThreshold=pn,S.canDetachArrowEnd=ni,S.canDetachArrowStart=An,S.clientToContainerPosition=Tt,S.colorToRgba=Ms,S.createArrow=Ot,S.createBox=Ee,S.createComment=we,S.createCommentWithArrow=_s,S.createPolygon=mn,S.createSVGElement=T,S.createText=Ne,S.cursors=z,S.darken=Bs,S.debounce=Ds,S.debounceTail=vs,S.defaultArrowOptions=Ts,S.defaultArrowStyle=gt,S.defaultBoxOptions=Os,S.defaultBoxStyle=Nt,S.defaultCommentOptions=qt,S.defaultCommentStyle=Z,S.defaultPolygonProperties=$s,S.defaultPolygonStyle=lt,S.defaultTextOptions=Ps,S.defaultTextStyle=q,S.detectArrow=Ae,S.detectBox=xn,S.detectComment=fn,S.detectPolygon=Me,S.detectText=Ce,S.getAnnotationsBounds=Es,S.getArrowEnd=me,S.getArrowEndPoints=Ut,S.getArrowSide=kt,S.getArrowStart=pe,S.getAttachmentPointOnNode=ws,S.getBbox=et,S.getBoxCenter=J,S.getBoxPosition=xt,S.getBoxSize=X,S.getBrowserWindow=ye,S.getCommentPosition=Is,S.getCommentSize=gn,S.getCommentZoomThreshold=Hs,S.getCoordinates=Lt,S.getHandleId=As,S.getPolygonBounds=xe,S.getPolygonCenter=fe,S.getTextBbox=et,S.getTextPosition=xt,S.getTextSize=X,S.handleDetectionThreshold=ae,S.handleRadius=sn,S.hexShortToLong=Gt,S.hexToRgba=ln,S.isAnnotationCollection=be,S.isArrow=tt,S.isBox=G,S.isColor=yn,S.isComment=I,S.isCommentArrow=Fn,S.isHexColor=De,S.isPolygon=nt,S.isRgbColor=ve,S.isRgbaColor=Be,S.isText=_,S.migrateBoxOrTextIfNeeded=un,S.parseColor=bs,S.rgbToRgba=dn,S.scaleGeometry=Cs,S.scalePolygon=Ss,S.setArrowEnd=an,S.setArrowEndPoint=cn,S.setArrowStart=on,S.setBbox=rn,S.setTextBbox=rn,S.simplifyPolygon=he,S.throttle=Se,S.toggleCommentMode=Rs,S.translatePolygon=ys,S.updateBbox=ct,S.updatePolygonBbox=ge,S.updateTextBbox=ct,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
85
+ `):i}let Ft=null,Ps;function Rs(){return Ft===null&&(Ft=new Intl.Segmenter(Ps,{granularity:"word"})),Ft}const _s=new RegExp("\\p{Script=Arabic}","u"),X=new RegExp("\\p{M}","u"),It=new RegExp("\\p{Nd}","u");function re(i){return _s.test(i)}function oe(i){return i>=19968&&i<=40959||i>=13312&&i<=19903||i>=131072&&i<=173791||i>=173824&&i<=177983||i>=177984&&i<=178207||i>=178208&&i<=183983||i>=183984&&i<=191471||i>=191472&&i<=192093||i>=194560&&i<=195103||i>=196608&&i<=201551||i>=201552&&i<=205743||i>=205744&&i<=210041||i>=63744&&i<=64255||i>=12288&&i<=12351||i>=12352&&i<=12447||i>=12448&&i<=12543||i>=12592&&i<=12687||i>=44032&&i<=55215||i>=65280&&i<=65519}function z(i){for(let e=0;e<i.length;e++){const t=i.charCodeAt(e);if(!(t<12288)){if(t>=55296&&t<=56319&&e+1<i.length){const n=i.charCodeAt(e+1);if(n>=56320&&n<=57343){const s=(t-55296<<10)+(n-56320)+65536;if(oe(s))return!0;e++;continue}}if(oe(t))return!0}}return!1}function Is(i){const e=it(i);return e!==null&&(Ht.has(e)||$.has(e))}const Hs=new Set(["Β ","β€―","⁠","\uFEFF"]),Gs=new Set(["-","‐","–","β€”"]);function zs(i){const e=it(i);return e!==null&&Hs.has(e)}function Ys(i){const e=it(i);return e!==null&&Gs.has(e)}function Ws(i,e){return zs(i)?!1:e?!(Is(i)||Ys(i)):!0}const Ht=new Set([",",".","!",":","οΌ›","?","、","。","・","οΌ‰","〕","〉","》","」","』","】","γ€—","γ€™","γ€›","γƒΌ","γ€…","γ€»","ゝ","γ‚ž","ヽ","γƒΎ"]),ut=new Set(['"',"(","[","{","Β‘","ΒΏ","β€œ","β€˜","β€š","β€ž","Β«","β€Ή","⸘","(","γ€”","γ€ˆ","γ€Š","γ€Œ","γ€Ž","【","γ€–","γ€˜","γ€š"]),Gt=new Set(["'","’"]),$=new Set([".",",","!","?",":",";","،","Ψ›","؟","ΰ₯€","ΰ₯₯","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","Β»","β€Ί","…"]),Us=new Set([":",".","،","Ψ›"]),$s=new Set(["၏"]),Xs=new Set(["”","’","Β»","β€Ί","」","』","】","》","〉","〕","οΌ‰"]);function Vs(i){if(zt(i))return!0;let e=!1;for(const t of i){if($.has(t)||xt(t)){e=!0;continue}if(!(e&&X.test(t)))return!1}return e}function js(i){for(const e of i)if(!Ht.has(e)&&!$.has(e))return!1;return i.length>0}function qs(i){if(zt(i))return!0;for(const e of i)if(!ut.has(e)&&!Gt.has(e)&&!X.test(e)&&!xt(e))return!1;return i.length>0}function zt(i){let e=!1;for(const t of i)if(!(t==="\\"||X.test(t))){if(ut.has(t)||$.has(t)||Gt.has(t)){e=!0;continue}return!1}return e}function ht(i,e){const t=e-1;if(t<=0)return Math.max(t,0);const n=i.charCodeAt(t);if(n<56320||n>57343)return t;const s=t-1;if(s<0)return t;const r=i.charCodeAt(s);return r>=55296&&r<=56319?s:t}function it(i){if(i.length===0)return null;const e=ht(i,i.length);return i.slice(e)}function Ks(i){for(const e of i)if(!X.test(e))return e;return null}function Zs(i){for(let e=i.length;e>0;){const t=ht(i,e),n=i.slice(t,e);if(!X.test(n))return n;e=t}return null}const Js=[36,37,43,43,92,92,162,165,176,177,1423,1423,1545,1547,1642,1642,2046,2047,2546,2547,2553,2555,2801,2801,3065,3065,3449,3449,3647,3647,6107,6107,8240,8247,8279,8279,8352,8399,8451,8451,8457,8457,8470,8470,8722,8723,43064,43064,65020,65020,65129,65130,65284,65285,65504,65505,65509,65510,73693,73696,123647,123647,126124,126124,126128,126128];function Qs(i,e){for(let t=0;t<e.length;t+=2)if(i>=e[t]&&i<=e[t+1])return!0;return!1}function xt(i){const e=i.codePointAt(0);return e!==void 0&&Qs(e,Js)}function ti(i){const e=Zs(i);return e!==null&&xt(e)}function ei(i){const e=Ks(i);return e!==null&&It.test(e)}function ni(i){const e=Array.from(i);let t=e.length;for(;t>0;){const n=e[t-1];if(X.test(n)){t--;continue}if(ut.has(n)||Gt.has(n)){t--;continue}break}return t<=0||t===e.length?null:{head:e.slice(0,t).join(""),tail:e.slice(t).join("")}}function si(i,e,t){return t==="text"&&!e&&i.length===1&&i!=="-"&&i!=="β€”"?i:null}function ae(i,e,t,n){const s=e[n],r=i[n];if(s==null)return r;const o=t[n];if(r.length===o)return r;const a=s.repeat(o);return i[n]=a,a}function ce(i,e){return i&&e!==null&&Us.has(e)}function ii(i){const e=it(i);return e!==null&&$s.has(e)}function ri(i){if(i.length<2||i[0]!==" ")return null;const e=i.slice(1);return new RegExp("^\\p{M}+$","u").test(e)?{space:" ",marks:e}:null}function bt(i){let e=i.length;for(;e>0;){const t=ht(i,e),n=i.slice(t,e);if(Xs.has(n))return!0;if(!$.has(n))return!1;e=t}return!1}function oi(i,e){if(e.preserveOrdinarySpaces||e.preserveHardBreaks){if(i===" ")return"preserved-space";if(i===" ")return"tab";if(e.preserveHardBreaks&&i===`
86
+ `)return"hard-break"}return i===" "?"space":i==="Β "||i==="β€―"||i==="⁠"||i==="\uFEFF"?"glue":i==="​"?"zero-width-break":i==="Β­"?"soft-hyphen":"text"}const ai=/[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;function G(i){return i.length===1?i[0]:i.join("")}function ci(i,e){const t=[];for(let n=i.length-1;n>=0;n--)t.push(i[n]);return t.push(e),G(t)}function li(i,e,t,n){if(!ai.test(i))return[{text:i,isWordLike:e,kind:"text",start:t}];const s=[];let r=null,o=[],a=t,u=!1,l=0;for(const d of i){const h=oi(d,n),x=h==="text"&&e;if(r!==null&&h===r&&x===u){o.push(d),l+=d.length;continue}r!==null&&s.push({text:G(o),isWordLike:u,kind:r,start:a}),r=h,o=[d],a=t+l,u=x,l+=d.length}return r!==null&&s.push({text:G(o),isWordLike:u,kind:r,start:a}),s}function Tt(i){return i==="space"||i==="preserved-space"||i==="zero-width-break"||i==="hard-break"}const di=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function ui(i,e){const t=i.texts[e];return t.startsWith("www.")?!0:di.test(t)&&e+1<i.len&&i.kinds[e+1]==="text"&&i.texts[e+1]==="//"}function hi(i){return i.includes("?")&&(i.includes("://")||i.startsWith("www."))}function xi(i){const e=i.texts.slice(),t=i.isWordLike.slice(),n=i.kinds.slice(),s=i.starts.slice();for(let o=0;o<i.len;o++){if(n[o]!=="text"||!ui(i,o))continue;const a=[e[o]];let u=o+1;for(;u<i.len&&!Tt(n[u]);){a.push(e[u]),t[o]=!0;const l=e[u].includes("?");if(n[u]="text",e[u]="",u++,l)break}e[o]=G(a)}let r=0;for(let o=0;o<e.length;o++){const a=e[o];a.length!==0&&(r!==o&&(e[r]=a,t[r]=t[o],n[r]=n[o],s[r]=s[o]),r++)}return e.length=r,t.length=r,n.length=r,s.length=r,{len:r,texts:e,isWordLike:t,kinds:n,starts:s}}function fi(i){const e=[],t=[],n=[],s=[];for(let r=0;r<i.len;r++){const o=i.texts[r];if(e.push(o),t.push(i.isWordLike[r]),n.push(i.kinds[r]),s.push(i.starts[r]),!hi(o))continue;const a=r+1;if(a>=i.len||Tt(i.kinds[a]))continue;const u=[],l=i.starts[a];let d=a;for(;d<i.len&&!Tt(i.kinds[d]);)u.push(i.texts[d]),d++;u.length>0&&(e.push(G(u)),t.push(!0),n.push("text"),s.push(l),r=d-1)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}const gi=new Set([":","-","/","Γ—",",",".","+","–","β€”"]),pi=new Set([".",",",":",";"]);function le(i){for(let e=i.length;e>0;){const t=ht(i,e),n=i.slice(t,e);if(X.test(n)){e=t;continue}return pi.has(n)||xt(n)}return!1}function mi(i,e){return e&&!z(i)}function Le(i){for(const e of i)if(It.test(e))return!0;return!1}function lt(i){if(i.length===0)return!1;for(const e of i)if(!(It.test(e)||gi.has(e)))return!1;return!0}function Si(i){const e=[],t=[],n=[],s=[];for(let r=0;r<i.len;r++){const o=i.texts[r],a=i.kinds[r];if(a==="text"&&lt(o)&&Le(o)){const u=[o];let l=r+1;for(;l<i.len&&i.kinds[l]==="text"&&lt(i.texts[l]);)u.push(i.texts[l]),l++;e.push(G(u)),t.push(!0),n.push("text"),s.push(i.starts[r]),r=l-1;continue}e.push(o),t.push(i.isWordLike[r]),n.push(a),s.push(i.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Ei(i){const e=[],t=[],n=[],s=[];for(let r=0;r<i.len;r++){const o=i.texts[r],a=i.kinds[r],u=i.isWordLike[r];if(a==="text"&&le(o)&&(u||ti(o))&&!z(o)){const l=[o];let d=!0,h=r+1;for(;d&&h<i.len&&i.kinds[h]==="text"&&mi(i.texts[h],i.isWordLike[h]);){const x=i.texts[h];l.push(x),d=le(x),h++}e.push(G(l)),t.push(!0),n.push("text"),s.push(i.starts[r]),r=h-1;continue}e.push(o),t.push(u),n.push(a),s.push(i.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Fi(i){const e=[],t=[],n=[],s=[];for(let r=0;r<i.len;r++){const o=i.texts[r];if(i.kinds[r]==="text"&&o.includes("-")){const a=o.split("-");let u=a.length>1;for(let l=0;l<a.length;l++){const d=a[l];if(!u)break;(d.length===0||!Le(d)||!lt(d))&&(u=!1)}if(u){let l=0;for(let d=0;d<a.length;d++){const h=a[d],x=d<a.length-1?`${h}-`:h;e.push(x),t.push(!0),n.push("text"),s.push(i.starts[r]+l),l+=x.length}continue}}e.push(o),t.push(i.isWordLike[r]),n.push(i.kinds[r]),s.push(i.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function yi(i){const e=[],t=[],n=[],s=[];let r=0;for(;r<i.len;){const o=[i.texts[r]];let a=i.isWordLike[r],u=i.kinds[r],l=i.starts[r];if(u==="glue"){const d=[o[0]],h=l;for(r++;r<i.len&&i.kinds[r]==="glue";)d.push(i.texts[r]),r++;const x=G(d);if(r<i.len&&i.kinds[r]==="text")o[0]=x,o.push(i.texts[r]),a=i.isWordLike[r],u="text",l=h,r++;else{e.push(x),t.push(!1),n.push("glue"),s.push(h);continue}}else r++;if(u==="text")for(;r<i.len&&i.kinds[r]==="glue";){const d=[];for(;r<i.len&&i.kinds[r]==="glue";)d.push(i.texts[r]),r++;const h=G(d);if(r<i.len&&i.kinds[r]==="text"){o.push(h,i.texts[r]),a=a||i.isWordLike[r],r++;continue}o.push(h)}e.push(G(o)),t.push(a),n.push(u),s.push(l)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Ai(i){const e=i.texts.slice(),t=i.isWordLike.slice(),n=i.kinds.slice(),s=i.starts.slice();for(let r=0;r<e.length-1;r++){if(n[r]!=="text"||n[r+1]!=="text"||!z(e[r])||!z(e[r+1]))continue;const o=ni(e[r]);o!==null&&(e[r]=o.head,e[r+1]=o.tail+e[r+1],s[r+1]=s[r]+o.head.length)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Ci(i,e,t){const n=Rs();let s=0;const r=[],o=[],a=[],u=[],l=[],d=[],h=[],x=[],f=[],g=[],p=[],m=[];for(const E of n.segment(i))for(const N of li(E.segment,E.isWordLike??!1,E.index,t)){let k=function(){d[w]!==null&&(o[w]=[ae(r,d,h,w)],d[w]=null),o[w].push(N.text),a[w]=a[w]||N.isWordLike,x[w]=x[w]||b,f[w]=f[w]||T,g[w]=O,p[w]=R,m[w]=ce(f[w],L)};const M=N.kind==="text",B=si(N.text,N.isWordLike,N.kind),b=z(N.text),T=re(N.text),L=it(N.text),O=bt(N.text),R=ii(N.text),w=s-1;e.carryCJKAfterClosingQuote&&M&&s>0&&u[w]==="text"&&b&&x[w]&&g[w]||M&&s>0&&u[w]==="text"&&js(N.text)&&x[w]||M&&s>0&&u[w]==="text"&&p[w]?k():M&&s>0&&u[w]==="text"&&N.isWordLike&&T&&m[w]?(k(),a[w]=!0):B!==null&&s>0&&u[w]==="text"&&d[w]===B?h[w]=(h[w]??1)+1:M&&!N.isWordLike&&s>0&&u[w]==="text"&&!x[w]&&(Vs(N.text)||N.text==="-"&&a[w])?k():(r[s]=N.text,o[s]=[N.text],a[s]=N.isWordLike,u[s]=N.kind,l[s]=N.start,d[s]=B,h[s]=B===null?0:1,x[s]=b,f[s]=T,g[s]=O,p[s]=R,m[s]=ce(T,L),s++)}for(let E=0;E<s;E++){if(d[E]!==null){r[E]=ae(r,d,h,E);continue}r[E]=G(o[E])}for(let E=1;E<s;E++)u[E]==="text"&&!a[E]&&zt(r[E])&&u[E-1]==="text"&&!x[E-1]&&(r[E-1]+=r[E],a[E-1]=a[E-1]||a[E],r[E]="");const F=Array.from({length:s},()=>null);let y=-1;for(let E=s-1;E>=0;E--){const N=r[E];if(N.length!==0){if(u[E]==="text"&&!a[E]&&y>=0&&u[y]==="text"&&(qs(N)||N==="-"&&ei(r[y]))){const M=F[y]??[];M.push(N),F[y]=M,l[y]=l[E],r[E]="";continue}y=E}}for(let E=0;E<s;E++){const N=F[E];N!=null&&(r[E]=ci(N,r[E]))}let A=0;for(let E=0;E<s;E++){const N=r[E];N.length!==0&&(A!==E&&(r[A]=N,a[A]=a[E],u[A]=u[E],l[A]=l[E]),A++)}r.length=A,a.length=A,u.length=A,l.length=A;const D=yi({len:A,texts:r,isWordLike:a,kinds:u,starts:l}),C=Ai(Ei(Fi(Si(fi(xi(D))))));for(let E=0;E<C.len-1;E++){const N=ri(C.texts[E]);N!==null&&(C.kinds[E]!=="space"&&C.kinds[E]!=="preserved-space"||C.kinds[E+1]!=="text"||!re(C.texts[E+1])||(C.texts[E]=N.space,C.isWordLike[E]=!1,C.kinds[E]=C.kinds[E]==="preserved-space"?"preserved-space":"space",C.texts[E+1]=N.marks+C.texts[E+1],C.starts[E+1]=C.starts[E]+N.space.length))}return C}function Ni(i,e){if(i.len===0)return[];if(!e.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:i.len,consumedEndSegmentIndex:i.len}];const t=[];let n=0;for(let s=0;s<i.len;s++)i.kinds[s]==="hard-break"&&(t.push({startSegmentIndex:n,endSegmentIndex:s,consumedEndSegmentIndex:s+1}),n=s+1);return n<i.len&&t.push({startSegmentIndex:n,endSegmentIndex:i.len,consumedEndSegmentIndex:i.len}),t}function Di(i,e,t){if(e.len<=1)return e;const n=[],s=[],r=[],o=[];let a=-1,u=!1;function l(x){n.push(e.texts[x]),s.push(e.isWordLike[x]),r.push("text"),o.push(e.starts[x])}function d(x,f){let g=!1;for(let F=x;F<f;F++)g=g||e.isWordLike[F];const p=e.starts[x],m=f<e.len?e.starts[f]:i.length;n.push(i.slice(p,m)),s.push(g),r.push("text"),o.push(p)}function h(x){if(!(a<0)){if(u)a+1===x?l(a):d(a,x);else for(let f=a;f<x;f++)l(f);a=-1,u=!1}}for(let x=0;x<e.len;x++){const f=e.texts[x],g=e.kinds[x];if(g==="text"){a>=0&&!Ws(e.texts[x-1],t)&&h(x),a<0&&(a=x),u=u||z(f);continue}h(x),n.push(f),s.push(e.isWordLike[x]),r.push(g),o.push(e.starts[x])}return h(e.len),{len:n.length,texts:n,isWordLike:s,kinds:r,starts:o}}function Mi(i,e,t="normal",n="normal"){const s=ks(t),r=s.mode==="pre-wrap"?Os(i):Ls(i);if(r.length===0)return{normalized:r,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};const o=Ci(r,e,s),a=n==="keep-all"?Di(r,o,e.breakKeepAllAfterPunctuation):o;return{normalized:r,chunks:Ni(a,s),...a}}let j=null;const de=new Map;let q=null;const wi=96,bi=new RegExp("\\p{Emoji_Presentation}","u"),Ti=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;let yt=null;const ue=new Map;function Yt(){if(j!==null)return j;if(typeof OffscreenCanvas<"u")return j=new OffscreenCanvas(1,1).getContext("2d"),j;if(typeof document<"u")return j=document.createElement("canvas").getContext("2d"),j;throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function Bi(i){let e=de.get(i);return e||(e=new Map,de.set(i,e)),e}function W(i,e){let t=e.get(i);return t===void 0&&(t={width:Yt().measureText(i).width,containsCJK:z(i)},e.set(i,t)),t}function ft(){if(q!==null)return q;if(typeof navigator>"u")return q={lineFitEpsilon:.005,carryCJKAfterClosingQuote:!1,breakKeepAllAfterPunctuation:!0,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},q;const i=navigator.userAgent,t=navigator.vendor==="Apple Computer, Inc."&&i.includes("Safari/")&&!i.includes("Chrome/")&&!i.includes("Chromium/")&&!i.includes("CriOS/")&&!i.includes("FxiOS/")&&!i.includes("EdgiOS/"),n=i.includes("Chrome/")||i.includes("Chromium/")||i.includes("CriOS/")||i.includes("Edg/");return q={lineFitEpsilon:t?1/64:.005,carryCJKAfterClosingQuote:n,breakKeepAllAfterPunctuation:!t,preferPrefixWidthsForBreakableRuns:t,preferEarlySoftHyphenBreak:t},q}function vi(i){const e=i.match(/(\d+(?:\.\d+)?)\s*px/);return e?parseFloat(e[1]):16}function Oe(){return yt===null&&(yt=new Intl.Segmenter(void 0,{granularity:"grapheme"})),yt}function ki(i){return bi.test(i)||i.includes("️")}function Li(i){return Ti.test(i)}function Oi(i,e){let t=ue.get(i);if(t!==void 0)return t;const n=Yt();n.font=i;const s=n.measureText("πŸ˜€").width;if(t=0,s>e+.5&&typeof document<"u"&&document.body!==null){const r=document.createElement("span");r.style.font=i,r.style.display="inline-block",r.style.visibility="hidden",r.style.position="absolute",r.textContent="πŸ˜€",document.body.appendChild(r);const o=r.getBoundingClientRect().width;document.body.removeChild(r),s-o>.5&&(t=s-o)}return ue.set(i,t),t}function Pi(i){let e=0;const t=Oe();for(const n of t.segment(i))ki(n.segment)&&e++;return e}function Ri(i,e){return e.emojiCount===void 0&&(e.emojiCount=Pi(i)),e.emojiCount}function U(i,e,t){return t===0?e.width:e.width-Ri(i,e)*t}function _i(i,e,t,n,s){if(e.breakableFitAdvances!==void 0&&e.breakableFitMode===s)return e.breakableFitAdvances;e.breakableFitMode=s;const r=Oe(),o=[];for(const d of r.segment(i))o.push(d.segment);if(o.length<=1)return e.breakableFitAdvances=null,e.breakableFitAdvances;if(s==="sum-graphemes"){const d=[];for(const h of o){const x=W(h,t);d.push(U(h,x,n))}return e.breakableFitAdvances=d,e.breakableFitAdvances}if(s==="pair-context"||o.length>wi){const d=[];let h=null,x=0;for(const f of o){const g=W(f,t),p=U(f,g,n);if(h===null)d.push(p);else{const m=h+f,F=W(m,t);d.push(U(m,F,n)-x)}h=f,x=p}return e.breakableFitAdvances=d,e.breakableFitAdvances}const a=[];let u="",l=0;for(const d of o){u+=d;const h=W(u,t),x=U(u,h,n);a.push(x-l),l=x}return e.breakableFitAdvances=a,e.breakableFitAdvances}function Ii(i,e){const t=Yt();t.font=i;const n=Bi(i),s=vi(i),r=e?Oi(i,s):0;return{cache:n,fontSize:s,emojiCorrection:r}}function Hi(i){return i==="space"||i==="zero-width-break"||i==="soft-hyphen"}function Pe(i){return i==="space"||i==="preserved-space"||i==="tab"||i==="zero-width-break"||i==="soft-hyphen"}function Re(i,e,t=i.widths.length){for(;e<t;){const n=i.kinds[e];if(!Hi(n))break;e++}return e}function Gi(i,e){if(e<=0)return 0;const t=i%e;return Math.abs(t)<=1e-6?e:e-t}function zi(i,e,t){return i.letterSpacing!==0&&e&&i.spacingGraphemeCounts[t]>0?i.letterSpacing:0}function Wt(i,e){return e===0?0:i+e}function Yi(i,e){return i.letterSpacing!==0&&i.spacingGraphemeCounts[e]>0?i.letterSpacing:0}function Wi(i,e,t,n,s){const r=e==="tab"?s+Yi(i,t):i.lineEndFitAdvances[t];return Wt(n,r)}function he(i,e,t,n){const s=e==="tab"?0:i.lineEndFitAdvances[t];return Wt(n,s)}function xe(i,e,t,n,s){const r=e==="tab"?s:i.lineEndPaintAdvances[t];return Wt(n,r)}function Ui(i,e,t){return i.letterSpacing!==0&&e?t+i.letterSpacing:t}function $i(i,e){return i.letterSpacing===0?e:e+i.letterSpacing}function Xi(i,e,t,n,s){if(i.letterSpacing===0)return 0;if(s>0)return i.spacingGraphemeCounts[n]>0?i.letterSpacing:0;for(let r=n-1;r>=e;r--){const o=i.kinds[r];if(!(o==="space"||o==="zero-width-break"||o==="hard-break")){if(o==="soft-hyphen"){if(r===n-1)return 0;continue}return r===e&&t>0||i.spacingGraphemeCounts[r]>0?i.letterSpacing:0}}return 0}function Vi(i,e,t,n,s,r){return e+Xi(i,t,n,s,r)}function ji(i,e,t){const{widths:n,kinds:s,breakableFitAdvances:r}=i;if(n.length===0)return 0;const a=ft().lineFitEpsilon,u=e+a;let l=0,d=0,h=!1,x=0,f=0,g=0,p=0,m=-1,F=0;function y(){m=-1,F=0}function A(B=g,b=p,T=d){l++,t==null||t(T,x,f,B,b),d=0,h=!1,y()}function D(B,b){h=!0,x=B,f=0,g=B+1,p=0,d=b}function C(B,b,T){h=!0,x=B,f=b,g=B,p=b+1,d=T}function E(B,b){if(!h){D(B,b);return}d+=b,g=B+1,p=0}function N(B,b){const T=r[B];for(let L=b;L<T.length;L++){const O=T[L];h?d+O>u?(A(),C(B,L,O)):(d+=O,g=B,p=L+1):C(B,L,O)}h&&g===B&&p===T.length&&(g=B+1,p=0)}let M=0;for(;M<n.length&&!(!h&&(M=Re(i,M),M>=n.length));){const B=n[M],b=s[M],T=Pe(b);if(!h){B>u&&r[M]!==null?N(M,0):D(M,B),T&&(m=M+1,F=d-B),M++;continue}if(d+B>u){if(T){E(M,B),A(M+1,0,d-B),M++;continue}if(m>=0){if(g>m||g===m&&p>0){A();continue}A(m,0,F);continue}if(B>u&&r[M]!==null){A(),N(M,0),M++;continue}A();continue}E(M,B),T&&(m=M+1,F=d-B),M++}return h&&A(),l}function qi(i,e,t){if(i.simpleLineWalkFastPath)return ji(i,e,t);const{widths:n,kinds:s,breakableFitAdvances:r,discretionaryHyphenWidth:o,chunks:a}=i;if(n.length===0||a.length===0)return 0;const u=ft(),l=u.lineFitEpsilon,d=e+l;let h=0,x=0,f=!1,g=0,p=0,m=0,F=0,y=-1,A=0,D=0,C=null;function E(){y=-1,A=0,D=0,C=null}function N(){return C==="soft-hyphen"&&y===m&&F===0?D:x}function M(w=m,k=F,v){h++,t!==void 0&&t(Vi(i,v??N(),g,p,w,k),g,p,w,k),x=0,f=!1,E()}function B(w,k){f=!0,g=w,p=0,m=w+1,F=0,x=k}function b(w,k,v){f=!0,g=w,p=k,m=w,F=k+1,x=v}function T(w,k){if(!f){B(w,k);return}x+=k,m=w+1,F=0}function L(w,k,v,P,_,H){if(!k)return;const I=he(i,w,v,_),Y=xe(i,w,v,_,P);y=v+1,A=x-H+I,D=x-H+Y,C=w}function O(w,k){const v=r[w];for(let P=k;P<v.length;P++){const _=v[P];if(!f)b(w,P,_);else{const H=Ui(i,!0,_),I=x+H;$i(i,I)>d?(M(),b(w,P,_)):(x=I,m=w,F=P+1)}}f&&m===w&&F===v.length&&(m=w+1,F=0)}function R(w){h++,t==null||t(0,w.startSegmentIndex,0,w.consumedEndSegmentIndex,0),E()}for(let w=0;w<a.length;w++){const k=a[w];if(k.startSegmentIndex===k.endSegmentIndex){R(k);continue}f=!1,x=0,g=k.startSegmentIndex,p=0,m=k.startSegmentIndex,F=0,E();let v=k.startSegmentIndex;for(;v<k.endSegmentIndex&&!(!f&&(v=Re(i,v,k.endSegmentIndex),v>=k.endSegmentIndex));){const P=s[v],_=Pe(P),H=zi(i,f,v),I=P==="tab"?Gi(x+H,i.tabStopAdvance):n[v],Y=H+I,gt=Wi(i,P,v,H,I);if(P==="soft-hyphen"){f&&(m=v+1,F=0,y=v+1,A=x+o,D=x+o,C=P),v++;continue}if(!f){gt>d&&r[v]!==null?O(v,0):B(v,I),L(P,_,v,I,H,Y),v++;continue}if(x+gt>d){const He=x+he(i,P,v,H),Ge=x+xe(i,P,v,H,I);if(C==="soft-hyphen"&&u.preferEarlySoftHyphenBreak&&A<=d){M(y,0,D);continue}if(_&&He<=d){T(v,Y),M(v+1,0,Ge),v++;continue}if(y>=0&&A<=d){if(m>y||m===y&&F>0){M();continue}const Ut=y;M(Ut,0,D),v=Ut;continue}if(gt>d&&r[v]!==null){M(),O(v,0),v++;continue}M();continue}T(v,Y),L(P,_,v,I,H,Y),v++}if(f){const P=y===k.consumedEndSegmentIndex?D:x;M(k.consumedEndSegmentIndex,0,P)}}return h}let At=null,fe=new WeakMap;function Ki(){return At===null&&(At=new Intl.Segmenter(void 0,{granularity:"grapheme"})),At}function ge(i,e,t){let n=t.get(i);if(n!==void 0)return n;n=[];const s=Ki();for(const r of s.segment(e[i]))n.push(r.segment);return t.set(i,n),n}function Zi(i,e,t){return t>e&&i[t-1]==="soft-hyphen"}function pe(i,e,t,n){for(let s=t;s<n;s++)i+=e[s];return i}function Ji(i){let e=fe.get(i);return e!==void 0||(e=new Map,fe.set(i,e)),e}function Qi(i,e,t,n,s,r){let o="";const a=Zi(i.kinds,t,s);for(let u=t;u<s;u++)if(!(i.kinds[u]==="soft-hyphen"||i.kinds[u]==="hard-break"))if(u===t&&n>0){const l=ge(u,i.segments,e);o=pe(o,l,n,l.length)}else o+=i.segments[u];if(r>0){a&&(o+="-");const u=ge(s,i.segments,e);o=pe(o,u,t===s?n:0,r)}else a&&(o+="-");return o}let Ct=null;function _e(){return Ct===null&&(Ct=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Ct}function tr(i){return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]}}function er(i,e){const t=[];let n=[],s=0,r=!1,o=!1,a=!1;function u(){n.length!==0&&(t.push({text:n.length===1?n[0]:n.join(""),start:s}),n=[],r=!1,o=!1,a=!1)}function l(h,x,f){n=[h],s=x,r=f,o=bt(h),a=ut.has(h)}function d(h,x){n.push(h),r=r||x;const f=bt(h);h.length===1&&$.has(h)?o=o||f:o=f,a=!1}for(const h of _e().segment(i)){const x=h.segment,f=z(x);if(n.length===0){l(x,h.index,f);continue}if(a||Ht.has(x)||$.has(x)||e.carryCJKAfterClosingQuote&&f&&o){d(x,f);continue}if(!r&&!f){d(x,f);continue}u(),l(x,h.index,f)}return u(),t}function me(i,e){if(e==="zero-width-break"||e==="soft-hyphen"||e==="hard-break")return 0;if(e==="tab")return 1;let t=0;const n=_e();for(const s of n.segment(i))t++;return t}function nr(i,e,t){return e>1?i+(e-1)*t:i}function sr(i,e,t,n,s){const r=ft(),{cache:o,emojiCorrection:a}=Ii(e,Li(i.normalized)),u=U("-",W("-",o),a)+(s===0?0:s*2),d=U(" ",W(" ",o),a)*8,h=s!==0;if(i.len===0)return tr();const x=[],f=[],g=[],p=[];let m=i.chunks.length<=1&&!h;const F=t?[]:null,y=[],A=[],D=t?[]:null,C=Array.from({length:i.len});function E(b,T,L,O,R,w,k,v){R!=="text"&&R!=="space"&&R!=="zero-width-break"&&(m=!1),x.push(T),f.push(L),g.push(O),p.push(R),F==null||F.push(w),y.push(k),h&&A.push(v),D!==null&&D.push(b)}function N(b,T,L,O,R){const w=W(b,o),k=h?me(b,T):0,v=nr(U(b,w,a),k,s),P=T==="space"||T==="preserved-space"||T==="zero-width-break"?0:v,_=P===0?0:P+(k>0?s:0),H=T==="space"||T==="zero-width-break"?0:v;if(R&&O&&b.length>1){let I="sum-graphemes";s!==0?I="segment-prefixes":lt(b)?I="pair-context":r.preferPrefixWidthsForBreakableRuns&&(I="segment-prefixes");const Y=_i(b,w,o,a,I);E(b,v,_,H,T,L,Y,k);return}E(b,v,_,H,T,L,null,k)}for(let b=0;b<i.len;b++){C[b]=x.length;const T=i.texts[b],L=i.isWordLike[b],O=i.kinds[b],R=i.starts[b];if(O==="soft-hyphen"){E(T,0,u,u,O,R,null,0);continue}if(O==="hard-break"){E(T,0,0,0,O,R,null,0);continue}if(O==="tab"){E(T,0,0,0,O,R,null,h?me(T,O):0);continue}const w=W(T,o);if(O==="text"&&w.containsCJK){const v=er(T,r);for(let P=0;P<v.length;P++){const _=v[P];N(_.text,"text",R+_.start,L,!z(_.text))}continue}N(T,O,R,L,!0)}const M=ir(i.chunks,C,x.length),B=F===null?null:Ts(i.normalized,F);return D!==null?{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:p,simpleLineWalkFastPath:m,segLevels:B,breakableFitAdvances:y,letterSpacing:s,spacingGraphemeCounts:A,discretionaryHyphenWidth:u,tabStopAdvance:d,chunks:M,segments:D}:{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:p,simpleLineWalkFastPath:m,segLevels:B,breakableFitAdvances:y,letterSpacing:s,spacingGraphemeCounts:A,discretionaryHyphenWidth:u,tabStopAdvance:d,chunks:M}}function ir(i,e,t){const n=[];for(let s=0;s<i.length;s++){const r=i[s],o=r.startSegmentIndex<e.length?e[r.startSegmentIndex]:t,a=r.endSegmentIndex<e.length?e[r.endSegmentIndex]:t,u=r.consumedEndSegmentIndex<e.length?e[r.consumedEndSegmentIndex]:t;n.push({startSegmentIndex:o,endSegmentIndex:a,consumedEndSegmentIndex:u})}return n}function rr(i,e,t,n){const s=n==null?void 0:n.wordBreak,r=(n==null?void 0:n.letterSpacing)??0,o=Mi(i,ft(),n==null?void 0:n.whiteSpace,s);return sr(o,e,t,s,r)}function or(i,e,t){return rr(i,e,!0,t)}function ar(i,e,t,n,s,r,o){return{text:Qi(i,e,n,s,r,o),width:t,start:{segmentIndex:n,graphemeIndex:s},end:{segmentIndex:r,graphemeIndex:o}}}function cr(i,e,t){const n=[];if(i.widths.length===0)return{lineCount:0,height:0,lines:n};const s=Ji(i),r=qi(i,e,(o,a,u,l,d)=>{n.push(ar(i,s,o,a,u,l,d))});return{lineCount:r,height:r*t,lines:n}}function lr(i,e,t,n){const{width:s,height:r}=c.getBoxSize(e),{color:o=c.defaultTextStyle.color,strokeColor:a=c.defaultTextStyle.strokeColor,strokeWidth:u=c.defaultTextStyle.strokeWidth,strokeType:l=c.defaultTextStyle.strokeType,background:d=c.defaultTextStyle.background,borderRadius:h=c.defaultTextStyle.borderRadius,fixedSize:x=c.defaultTextStyle.fixedSize}=e.properties.style||c.defaultTextStyle,f=ke(i,e,t,n);f.setAttribute("data-annotation-type",e.properties.type),f.classList.add("annotation-text"),f.setAttribute("fill",`${o}`);let g=f.firstChild;for(;g;){const A=g.nextSibling;g.nodeType===1&&g.tagName!=="rect"&&f.removeChild(g),g=A}let p=f.firstChild;p||(p=c.createSVGElement("rect"),f.appendChild(p));const m=-s/2,F=-r/2;h&&(p.setAttribute("rx",`${h}`),p.setAttribute("ry",`${h}`)),l&&l!=="none"&&(p.setAttribute("stroke",a||"black"),p.setAttribute("stroke-width",`${u}`),l==="dashed"&&p.setAttribute("stroke-dasharray","5,5")),d&&d.length&&(n.hoveredFeature===e.id?p.setAttribute("fill",c.brighten(d)):p.setAttribute("fill",d)),p.setAttribute("width",`${s}`),p.setAttribute("height",`${r}`);const y=c.getBoxCenter(e);return p.setAttribute("x",`${m}`),p.setAttribute("y",`${F}`),ur(e,f,m,F),f.setAttribute("transform",n.getScreenAlignedTransform(y.x,y.y,!x)),i.appendChild(f),f}let Q=null;const Se=new Map;function dr(i,e){const t=`${i}|${e}`,n=Se.get(t);if(n!=null)return n;try{const s=document.createElement("div"),r=document.createElement("span");s.style.cssText=`font:${i};line-height:${e}px;position:fixed;left:-9999px;top:0;margin:0;padding:0;visibility:hidden;`,r.style.cssText="display:inline-block;width:1px;height:1px;vertical-align:baseline;",s.appendChild(r),document.body.appendChild(s);const o=r.getBoundingClientRect().bottom-s.getBoundingClientRect().top;if(document.body.removeChild(s),o>0&&o<=e)return Se.set(t,o),o}catch{}try{if(Q||(Q=document.createElement("canvas").getContext("2d")),Q){Q.font=i;const s=Q.measureText("M"),r=s.fontBoundingBoxAscent,o=s.fontBoundingBoxDescent;if(r!=null&&o!=null)return Math.max(0,(e-r-o)/2)+r}}catch{}return e}function ur(i,e,t=0,n=0){const{width:s,height:r}=c.getBoxSize(i),{fontSize:o=c.defaultTextStyle.fontSize,font:a=c.defaultTextStyle.font,padding:u=0}=i.properties.style||{};if(s===r&&s===0)return;const l=parseFloat(o.toString())*c.TEXT_LINE_HEIGHT,d=`${o}px ${a}`.replace(/(px)+/g,"px"),h=s-u*2,x=r-u,f=i.properties.content||"";if(f.length===0)return;const g=or(f,d,{whiteSpace:"pre-wrap",wordBreak:"normal"}),{lines:p}=cr(g,h,l),m=Math.max(1,Math.floor(x/l)),F=p.slice(0,m);if(p.length>m&&F.length>0){const D=F[F.length-1];F[F.length-1]={...D,text:D.text.trimEnd()+"…"}}const y=c.createSVGElement("text");y.setAttribute("font-size",`${parseFloat(o.toString())}`),y.setAttribute("font-family",`${a}`),y.setAttribute("transform",`translate(${t+u}, ${n+u})`);const A=dr(d,l);F.forEach((D,C)=>{const E=c.createSVGElement("tspan");E.setAttribute("x","0"),E.setAttribute("dy",`${C===0?A:l}`);let N=0,M;const B=Ae();for(;(M=B.exec(D.text))!==null;){M.index>N&&E.appendChild(document.createTextNode(D.text.slice(N,M.index)));const b=document.createElementNS("http://www.w3.org/2000/svg","a");b.setAttribute("href",M[0]),b.setAttribute("target","_blank"),b.setAttribute("rel","noopener noreferrer"),b.setAttribute("class",Rt),b.textContent=M[0],E.appendChild(b),N=M.index+M[0].length}N<D.text.length&&E.appendChild(document.createTextNode(D.text.slice(N))),y.appendChild(E)}),e.appendChild(y)}class hr extends ve{constructor(t,n){super(t,n);S(this,"features",new Map);S(this,"arrowsRoot",null);S(this,"shapesRoot",null);S(this,"commentsRoot",null);S(this,"annotationsRoot",null);S(this,"underLayer");S(this,"underGraphRoot",null);S(this,"visibleFeatures",new Set);S(this,"isExporting",!1);S(this,"render",t=>{if(!t)return;const{features:n,hoveredFeature:s,selectedFeatures:r,liveUpdates:o}=this.store.getState();(!this.annotationsRoot||!t.contains(this.annotationsRoot))&&(t.innerHTML="",t.appendChild(this.getDefs()),this.arrowsRoot=c.createSVGElement("g"),this.commentsRoot=c.createSVGElement("g"),this.annotationsRoot=c.createSVGElement("g"),this.shapesRoot=c.createSVGElement("g"),this.annotationsRoot.appendChild(this.arrowsRoot),this.annotationsRoot.appendChild(this.shapesRoot),this.annotationsRoot.appendChild(this.commentsRoot),t.appendChild(this.annotationsRoot)),t.removeChild(this.annotationsRoot);const a=this.arrowsRoot,u=this.annotationsRoot,l=this.commentsRoot,d=this.shapesRoot,h=this.store.getState(),x=this.getViewportBounds();this.removeFeatures(n);const f=new Set;for(let g of Object.values(n)){if(o[g.id]&&(g={...g,...o[g.id]}),!this.isExporting&&!this.isFeatureVisible(g,x)||(f.add(g.id),c.isBox(g)||c.isPolygon(g)))continue;let p=this.features.get(g.id);c.isText(g)?p=lr(d,g,p,h):c.isComment(g)?p=As(l,g,p,h,this.visibleFeatures.has(g.id)):c.isArrow(g)&&(p=fs(a,g,h.options.minArrowHeight,h.options.maxArrowHeight,p,h)),p&&this.features.set(g.id,p)}this.applyStateClasses(u,s,r),t.appendChild(u),this.visibleFeatures.clear(),this.visibleFeatures=f});S(this,"renderUnderGraph",t=>{if(!t)return;const{features:n,liveUpdates:s,hoveredFeature:r,selectedFeatures:o}=this.store.getState();(!this.underGraphRoot||!t.contains(this.underGraphRoot))&&(t.innerHTML="",this.underGraphRoot=c.createSVGElement("g"),t.appendChild(this.underGraphRoot)),t.removeChild(this.underGraphRoot);const a=this.underGraphRoot,u=this.store.getState(),l=this.getViewportBounds();for(let d of Object.values(n)){if(!(c.isBox(d)||c.isPolygon(d))||(s[d.id]&&(d={...d,...s[d.id]}),!this.isExporting&&!this.isFeatureVisible(d,l)))continue;let h=this.features.get(d.id);c.isBox(d)?h=ke(a,d,h,u):c.isPolygon(d)&&(h=Ds(a,d,h,u)),h&&this.features.set(d.id,h)}this.applyStateClasses(a,r,o),t.appendChild(a)});S(this,"throttleRender",c.throttle(()=>{this.render(this.layer.element),this.renderUnderGraph(this.underLayer.element)},16,!0));S(this,"refresh",()=>{this.layer.refresh(),this.underLayer.refresh()});S(this,"onExportStart",()=>{this.isExporting=!0});S(this,"onExportEnd",()=>{this.isExporting=!1});t.events.on("viewExportStart",this.onExportStart),t.events.on("afterImageExport",this.onExportEnd),this.layer=this.ogma.layers.addSVGLayer({draw:this.render},c.LAYERS.SHAPES),this.underLayer=this.ogma.layers.addSVGLayer({draw:this.renderUnderGraph}),this.underLayer.moveToBottom(),this.store.subscribe(s=>({features:s.features,liveUpdates:s.liveUpdates,hoveredFeature:s.hoveredFeature,selectedFeatures:s.selectedFeatures,editingFeature:s.editingFeature,rotation:s.rotation,zoom:s.zoom}),this.throttleRender,{equalityFn:(s,r)=>s.features===r.features&&s.liveUpdates===r.liveUpdates&&s.hoveredFeature===r.hoveredFeature&&s.selectedFeatures===r.selectedFeatures&&s.editingFeature===r.editingFeature&&s.rotation===r.rotation&&s.zoom===r.zoom})}getViewportBounds(){const t=this.ogma;let n=null;try{n=t.view.getSize()}catch{return[0,0,0,0]}if(!n)return[0,0,0,0];const{width:s,height:r}=n,o=1.5,a=t.view.screenToGraphCoordinates({x:0,y:0}),u=t.view.screenToGraphCoordinates({x:s*o,y:0}),l=t.view.screenToGraphCoordinates({x:0,y:r*o}),d=t.view.screenToGraphCoordinates({x:s*o,y:r*o});return[Math.min(a.x,u.x,l.x,d.x),Math.min(a.y,u.y,l.y,d.y),Math.max(a.x,u.x,l.x,d.x),Math.max(a.y,u.y,l.y,d.y)]}isFeatureVisible(t,n){const s=t.geometry.bbox;if(!s)return!0;const[r,o,a,u]=s;return!(a<n[0]||r>n[2]||u<n[1]||o>n[3])}getDefs(){const t=c.createSVGElement("defs");t.appendChild(Ss());const n=c.createSVGElement("filter");n.setAttribute("id","softShadow"),n.setAttribute("x","-50%"),n.setAttribute("y","-50%"),n.setAttribute("width","200%"),n.setAttribute("height","200%");const s=c.createSVGElement("feGaussianBlur");s.setAttribute("in","SourceAlpha"),s.setAttribute("stdDeviation","2"),s.setAttribute("result","blur");const r=c.createSVGElement("feOffset");r.setAttribute("in","blur"),r.setAttribute("dx","0"),r.setAttribute("dy","1"),r.setAttribute("result","offsetBlur");const o=c.createSVGElement("feComponentTransfer");o.setAttribute("in","offsetBlur"),o.setAttribute("result","shadow");const a=c.createSVGElement("feFuncA");a.setAttribute("type","linear"),a.setAttribute("slope","0.25"),o.appendChild(a);const u=c.createSVGElement("feMerge"),l=c.createSVGElement("feMergeNode");l.setAttribute("in","shadow");const d=c.createSVGElement("feMergeNode");return d.setAttribute("in","SourceGraphic"),u.appendChild(l),u.appendChild(d),n.appendChild(s),n.appendChild(r),n.appendChild(o),n.appendChild(u),t.appendChild(n),t}removeFeatures(t){for(const n of this.features.keys())if(!(n in t)){const s=this.features.get(n);s&&s.parentNode&&s.parentNode.removeChild(s),this.features.delete(n)}}applyStateClasses(t,n,s){if(n!==null){const r=t.querySelector(`[data-annotation="${n}"]`);r&&r.classList.add("annotation-hovered")}s.forEach(r=>{const o=t.querySelector(`[data-annotation="${r}"]`);o&&o.classList.add("annotation-selected")})}destroy(){this.features.clear(),this.layer.destroy(),this.underLayer.destroy(),this.ogma.events.off(this.onExportStart),this.ogma.events.off(this.onExportEnd),super.destroy()}}const Ee=i=>{let e;const t=new Set,n=(l,d)=>{const h=typeof l=="function"?l(e):l;if(!Object.is(h,e)){const x=e;e=d??(typeof h!="object"||h===null)?h:Object.assign({},e,h),t.forEach(f=>f(e,x))}},s=()=>e,a={setState:n,getState:s,getInitialState:()=>u,subscribe:l=>(t.add(l),()=>t.delete(l))},u=e=i(n,s,a);return a},Ie=i=>i?Ee(i):Ee;var Fe=(i,e,t)=>(s,r)=>({pastStates:(t==null?void 0:t.pastStates)||[],futureStates:(t==null?void 0:t.futureStates)||[],undo:(o=1)=>{var a,u;if(r().pastStates.length){const l=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),d=r().pastStates.splice(-o,o),h=d.shift();i(h),s({pastStates:r().pastStates,futureStates:r().futureStates.concat(((u=t==null?void 0:t.diff)==null?void 0:u.call(t,l,h))||l,d.reverse())})}},redo:(o=1)=>{var a,u;if(r().futureStates.length){const l=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),d=r().futureStates.splice(-o,o),h=d.shift();i(h),s({pastStates:r().pastStates.concat(((u=t==null?void 0:t.diff)==null?void 0:u.call(t,l,h))||l,d.reverse()),futureStates:r().futureStates})}},clear:()=>s({pastStates:[],futureStates:[]}),isTracking:!0,pause:()=>s({isTracking:!1}),resume:()=>s({isTracking:!0}),setOnSave:o=>s({_onSave:o}),_onSave:t==null?void 0:t.onSave,_handleSet:(o,a,u,l)=>{var d,h;t!=null&&t.limit&&r().pastStates.length>=(t==null?void 0:t.limit)&&r().pastStates.shift(),(h=(d=r())._onSave)==null||h.call(d,o,u),s({pastStates:r().pastStates.concat(l||o),futureStates:[]})}}),xr=(i,e)=>(n,s,r)=>{var l,d;r.temporal=Ie(((l=e==null?void 0:e.wrapTemporal)==null?void 0:l.call(e,Fe(n,s,e)))||Fe(n,s,e));const o=((d=e==null?void 0:e.handleSet)==null?void 0:d.call(e,r.temporal.getState()._handleSet))||r.temporal.getState()._handleSet,a=h=>{var g,p,m;if(!r.temporal.getState().isTracking)return;const x=((g=e==null?void 0:e.partialize)==null?void 0:g.call(e,s()))||s(),f=(p=e==null?void 0:e.diff)==null?void 0:p.call(e,h,x);f===null||(m=e==null?void 0:e.equality)!=null&&m.call(e,h,x)||o(h,void 0,x,f)},u=r.setState;return r.setState=(...h)=>{var f;const x=((f=e==null?void 0:e.partialize)==null?void 0:f.call(e,s()))||s();u(...h),a(x)},i((...h)=>{var f;const x=((f=e==null?void 0:e.partialize)==null?void 0:f.call(e,s()))||s();n(...h),a(x)},s,r)};const fr=i=>(e,t,n)=>{const s=n.subscribe;return n.subscribe=(o,a,u)=>{let l=o;if(a){const d=(u==null?void 0:u.equalityFn)||Object.is;let h=o(n.getState());l=x=>{const f=o(x);if(!d(h,f)){const g=h;a(h=f,g)}},u!=null&&u.fireImmediately&&a(h,h)}return s(l)},i(e,t,n)},gr=fr,pr=[0,0,0,0];function mr(i,e){const t=Object.keys(i.features),n=Object.keys(e.features);if(t.length!==n.length)return!1;for(const s of t)if(!(s in e.features))return!1;for(const s of t){const r=i.features[s],o=e.features[s],a=r.geometry,u=o.geometry;if(a.coordinates!==u.coordinates||r.properties!==o.properties||r.properties.style!==o.properties.style||a!==u)return!1}return i.drawingFeature===e.drawingFeature}const Sr=i=>{const e=Ie()(gr(xr((t,n)=>({features:{},liveUpdates:{},isDragging:!1,hoveringHandle:!1,hoveredHandle:-1,hoveredFeature:null,selectedFeatures:new Set,lastChangedFeatures:[],drawingFeature:null,drawingPoints:null,editingFeature:null,mousePressed:!1,mousePressPoint:null,rotation:0,sin:0,cos:1,revRotation:0,revSin:0,revCos:1,zoom:1,invZoom:1,options:{showSendButton:(i==null?void 0:i.showSendButton)??!0,sendButtonIcon:(i==null?void 0:i.sendButtonIcon)??c.DEFAULT_SEND_ICON,showEditButton:(i==null?void 0:i.showEditButton)??!0,editButtonIcon:(i==null?void 0:i.editButtonIcon)??c.DEFAULT_EDIT_ICON,minArrowHeight:(i==null?void 0:i.minArrowHeight)??20,maxArrowHeight:(i==null?void 0:i.maxArrowHeight)??30,detectMargin:(i==null?void 0:i.detectMargin)??2,magnetRadius:(i==null?void 0:i.magnetRadius)??10,magnetHandleRadius:(i==null?void 0:i.magnetHandleRadius)??5,textPlaceholder:(i==null?void 0:i.textPlaceholder)??"Type here"},setOptions:s=>t(r=>({options:{...r.options,...s}})),removeFeature:s=>t(r=>{const o=r.features[s];if(!o)return r;const{features:a,liveUpdates:u}=r;if(c.isArrow(o)&&we(a,s))return console.error("Cannot delete last arrow attached to comment. Delete the comment instead."),r;const l=Me(a,s),d={...a},h={...u};return l.forEach(x=>{delete d[x],delete h[x]}),{features:d,liveUpdates:h}}),addFeature:s=>t(r=>({features:{...r.features,[s.id]:s}})),startLiveUpdate:s=>{t(r=>({liveUpdates:s.reduce((o,a)=>({...o,[a]:{...r.features[a]}}),{})}))},applyLiveUpdate:(s,r)=>{t(o=>({liveUpdates:{...o.liveUpdates,[s]:{...o.liveUpdates[s],...r}}}))},applyLiveUpdates:s=>{t(r=>{const o={...r.liveUpdates};for(const a in s)o[a]=s[a];return{liveUpdates:o}})},commitLiveUpdates:s=>{const{features:r,liveUpdates:o}=n(),a={...r},u=[],l=Object.keys(o);s||(s=new Set(l)),l.forEach(d=>{const h=o[d];a[d]&&Object.keys(h).length>0&&(a[d]={...a[d],...h},u.push(d))}),t({features:a,liveUpdates:{},isDragging:!1,lastChangedFeatures:u})},cancelLiveUpdates:()=>t({liveUpdates:{},isDragging:!1}),updateFeature:(s,r)=>t(o=>{const a={...o.features[s],...r},u={...o.liveUpdates};return delete u[s],{features:{...o.features,[s]:a},liveUpdates:u}}),updateFeatures:s=>t(r=>{const o={...r.features};return Object.entries(s).forEach(([a,u])=>{o[a]&&(o[a]={...o[a],...u})}),{features:o}}),batchUpdate:s=>{const r=e.temporal.getState();r.pause(),s(),r.resume()},getFeature:s=>n().features[s],getMergedFeature:s=>{const r=n().features[s],o=n().liveUpdates[s];if(r)return o?{...r,...o}:r},getAllFeatures:()=>{const{features:s,liveUpdates:r}=n();return Object.entries(s).map(([o,a])=>{const u=r[o];return u?{...a,...u}:a})},setHoveredFeature:s=>t({hoveredFeature:s}),setSelectedFeatures:s=>t({selectedFeatures:new Set(s)}),addToSelection:s=>{const{selectedFeatures:r}=n(),o=new Set(r);o.add(s),t({selectedFeatures:o})},removeFromSelection:s=>{const{selectedFeatures:r}=n(),o=new Set(r);o.delete(s),t({selectedFeatures:o})},toggleSelection:s=>{const{selectedFeatures:r}=n(),o=new Set(r);o.has(s)?o.delete(s):o.add(s),t({selectedFeatures:o})},clearSelection:()=>t({selectedFeatures:new Set}),isHovered:s=>n().hoveredFeature===s,isSelected:s=>n().selectedFeatures.has(s),setRotation:s=>{t({rotation:s,sin:Math.sin(s),cos:Math.cos(s),revRotation:-s,revSin:Math.sin(-s),revCos:Math.cos(-s)})},setZoom:s=>{t({zoom:s,invZoom:1/s})},getScreenAlignedTransform(s,r,o=!0){const a=this.revSin,u=this.revCos,l=s*u-r*a,d=s*a+r*u,h=o?1:this.invZoom;return`matrix(${h}, 0, 0, ${h}, ${l}, ${d})`},getRotationTransform(s,r){const o=this.revSin,a=this.revCos,u=s*a-r*o,l=s*o+r*a;return`matrix(${a}, ${o}, ${-o}, ${a}, ${-u}, ${-l})`},getRotatedBBox(s,r,o,a){return c.getAABB(s,r,o-s,a-r,this.sin,this.cos,s+(o-s)/2,r+(a-r)/2,pr)},setDrawingPoints:s=>t({drawingPoints:s})}),{limit:250,partialize:t=>({drawingFeature:t.drawingFeature,isDragging:t.isDragging,features:t.features,lastChangedFeatures:t.lastChangedFeatures}),equality:mr,handleSet:t=>n=>{n.drawingFeature===null&&t(n)}})));return e},Er={detectMargin:2,magnetHandleRadius:5,magnetRadius:10,textPlaceholder:"Type here",showSendButton:!0,sendButtonIcon:c.DEFAULT_SEND_ICON,showEditButton:!0,editButtonIcon:c.DEFAULT_EDIT_ICON,minArrowHeight:20,maxArrowHeight:30};class Fr extends Xe{constructor(t,n={}){super();S(this,"ogma");S(this,"store");S(this,"renderers",{});S(this,"interactions");S(this,"editor");S(this,"links");S(this,"index");S(this,"drawing");S(this,"snapping");S(this,"selectionManager");S(this,"historyManager");S(this,"updateManager");S(this,"commentManager");S(this,"onRotate",()=>this.store.getState().setRotation(this.ogma.view.getAngle()));S(this,"onZoom",()=>{const t=this.ogma.view.getZoom();this.store.getState().setZoom(t),this.commentManager.updateCommentModesForZoom(t)});S(this,"onLayout",()=>{this.links.update()});this.ogma=t;const s={...Er,...n};this.store=Sr(s),this.index=new ls(this.store),this.snapping=new ts(this.ogma,{detectMargin:n.detectMargin===void 0?10:n.detectMargin,magnetRadius:n.magnetRadius===void 0?10:n.magnetRadius},this.index,this.store),this.links=new Gn(this.ogma,this.snapping,this.store,(r,o)=>{this.emit(c.EVT_LINK,{arrow:r,link:o})}),this.interactions=new es(this.ogma,this.store,this.index),this.editor=new Bn(this.ogma,this.store,this.snapping,this.links,this.interactions),this.drawing=new un(this.ogma,this.store,this.editor,this.interactions,this.links,this,this.index),this.selectionManager=new xn(this.store),this.historyManager=new hn(this.store,this.links),this.updateManager=new fn(this.store),this.commentManager=new sn(this.store),this.initializeRenderers(),this.setupEvents()}initializeRenderers(){this.renderers.shapes=new hr(this.ogma,this.store),this.renderers.handles=new ds(this.ogma,this.store)}setupEvents(){this.ogma.events.on("rotate",this.onRotate).on("zoom",this.onZoom).on("layoutEnd",this.onLayout),this.editor.addEventListener(c.EVT_DRAG_START,t=>this.emit(c.EVT_DRAG_START,{id:t.detail.id,position:t.detail.position})),this.editor.addEventListener(c.EVT_DRAG_END,t=>this.emit(c.EVT_DRAG_END,{id:t.detail.id,position:t.detail.position})),this.interactions.addEventListener(c.EVT_CLICK,(t=>this.emit(c.EVT_CLICK,{id:t.detail.id,position:t.detail.position}))),this.store.temporal.subscribe(t=>{this.emit(c.EVT_HISTORY,{canUndo:t.pastStates.length>0,canRedo:t.futureStates.length>0})}),this.store.subscribe(t=>t.selectedFeatures,(t,n)=>{const s=Array.from(t).filter(r=>!(n!=null&&n.has(r)));if(s.length>0&&this.emit(c.EVT_SELECT,{ids:s}),n){const r=Array.from(n).filter(o=>!t.has(o));r.length>0&&this.emit(c.EVT_UNSELECT,{ids:r})}}),this.store.subscribe(t=>t.drawingFeature,(t,n)=>{t===null&&n!==null&&this.emit(c.EVT_COMPLETE_DRAWING,{id:n})}),this.store.subscribe(t=>t.features,(t,n)=>{for(const s of Object.keys(t))n[s]?n[s]!==t[s]&&this.emit(c.EVT_UPDATE,t[s]):this.emit(c.EVT_ADD,{id:s});for(const s of Object.keys(n))t[s]||this.emit(c.EVT_REMOVE,{id:s})})}setOptions(t={}){return this.store.getState().setOptions(t),this.store.getState().options}add(t){return this.updateManager.add(t),this}remove(t){return this.updateManager.remove(t),this}undo(){return this.historyManager.undo()}redo(){return this.historyManager.redo()}canUndo(){return this.historyManager.canUndo()}canRedo(){return this.historyManager.canRedo()}clearHistory(){this.historyManager.clearHistory()}getAnnotations(){return this.updateManager.getAnnotations()}select(t){return this.selectionManager.select(t),this}unselect(t){return this.selectionManager.unselect(t),this}cancelDrawing(){var t;return this.drawing.cancelPendingDrawing(),(t=this.editor.getActiveHandler())==null||t.cancelDrawing(),this.emit(c.EVT_CANCEL_DRAWING),this}enableArrowDrawing(t){return this.drawing.enableArrowDrawing(t),this}enableTextDrawing(t){return this.drawing.enableTextDrawing(t),this}enableBoxDrawing(t){return this.drawing.enableBoxDrawing(t),this}enablePolygonDrawing(t){return this.drawing.enablePolygonDrawing(t),this}enableCommentDrawing(t={}){return this.drawing.enableCommentDrawing(t),this}enableStickyNoteDrawing(t){return this.drawing.enableStickyNoteDrawing(t),this}enableEraseMode(){return this.drawing.enableEraseMode(),this}disableEraseMode(){return this.drawing.disableEraseMode(),this}isEraseModeActive(){return this.drawing.isEraseModeActive()}enablePlacement(t){return this.drawing.enablePlacement(t),this}startComment(t,n,s,r){return this.drawing.startComment(t,n,s,r),this}startStickyNote(t,n,s){return this.drawing.startStickyNote(t,n,s),this}startBox(t,n,s){return this.drawing.startBox(t,n,s),this}startArrow(t,n,s){return this.drawing.startArrow(t,n,s),this}startText(t,n,s){return this.drawing.startText(t,n,s),this}startPolygon(t,n,s){return this.drawing.startPolygon(t,n,s),this}getSelectedAnnotations(){return this.selectionManager.getSelectedAnnotations()}getSelected(){return this.selectionManager.getSelected()}getAnnotation(t){return this.updateManager.getAnnotation(t)}setScale(t,n,s,r){return this.updateManager.setScale(t,n,s,r),this}toggleComment(t){return this.commentManager.toggleComment(t),this}destroy(){this.ogma.events.off(this.onRotate).off(this.onZoom).off(this.onLayout),this.links.destroy(),Object.values(this.renderers).forEach(t=>t.destroy()),this.interactions.destroy(),this.editor.destroy()}updateStyle(t,n){return this.updateManager.updateStyle(t,n),this}update(t){return this.updateManager.update(t),this}link(t,n,s=c.SIDE_END){const r=this.getAnnotation(t);if(!r)throw new Error(`Arrow with id ${t} not found`);return this.editor.getArrowHandler().link(r,n,s),this}isDrawing(){return this.drawing.isDrawing()}}exports.COMMENT_MODE_COLLAPSED=c.COMMENT_MODE_COLLAPSED;exports.COMMENT_MODE_EXPANDED=c.COMMENT_MODE_EXPANDED;exports.DATA_ATTR=c.DATA_ATTR;exports.DEFAULT_EDIT_ICON=c.DEFAULT_EDIT_ICON;exports.DEFAULT_SEND_ICON=c.DEFAULT_SEND_ICON;exports.EVT_ADD=c.EVT_ADD;exports.EVT_CANCEL_DRAWING=c.EVT_CANCEL_DRAWING;exports.EVT_CLICK=c.EVT_CLICK;exports.EVT_COMPLETE_DRAWING=c.EVT_COMPLETE_DRAWING;exports.EVT_DRAG=c.EVT_DRAG;exports.EVT_DRAG_END=c.EVT_DRAG_END;exports.EVT_DRAG_START=c.EVT_DRAG_START;exports.EVT_HISTORY=c.EVT_HISTORY;exports.EVT_HOVER=c.EVT_HOVER;exports.EVT_LINK=c.EVT_LINK;exports.EVT_REMOVE=c.EVT_REMOVE;exports.EVT_SELECT=c.EVT_SELECT;exports.EVT_UNHOVER=c.EVT_UNHOVER;exports.EVT_UNSELECT=c.EVT_UNSELECT;exports.EVT_UPDATE=c.EVT_UPDATE;exports.HL_BRIGHTEN=c.HL_BRIGHTEN;exports.LAYERS=c.LAYERS;exports.NONE=c.NONE;exports.SIDE_END=c.SIDE_END;exports.SIDE_START=c.SIDE_START;exports.TARGET_TYPES=c.TARGET_TYPES;exports.TEXT_LINE_HEIGHT=c.TEXT_LINE_HEIGHT;exports.adjustColorBrightness=c.adjustColorBrightness;exports.brighten=c.brighten;exports.bringToTop=c.bringToTop;exports.calculateCommentZoomThreshold=c.calculateCommentZoomThreshold;exports.clientToContainerPosition=c.clientToContainerPosition;exports.colorToRgba=c.colorToRgba;exports.createArrow=c.createArrow;exports.createBox=c.createBox;exports.createComment=c.createComment;exports.createCommentWithArrow=c.createCommentWithArrow;exports.createPolygon=c.createPolygon;exports.createSVGElement=c.createSVGElement;exports.createText=c.createText;exports.cursors=c.cursors;exports.darken=c.darken;exports.debounce=c.debounce;exports.debounceTail=c.debounceTail;exports.defaultArrowOptions=c.defaultArrowOptions;exports.defaultArrowStyle=c.defaultArrowStyle;exports.defaultBoxOptions=c.defaultBoxOptions;exports.defaultBoxStyle=c.defaultBoxStyle;exports.defaultCommentOptions=c.defaultCommentOptions;exports.defaultCommentStyle=c.defaultCommentStyle;exports.defaultPolygonProperties=c.defaultPolygonProperties;exports.defaultPolygonStyle=c.defaultPolygonStyle;exports.defaultTextOptions=c.defaultTextOptions;exports.defaultTextStyle=c.defaultTextStyle;exports.detectArrow=c.detectArrow;exports.detectBox=c.detectBox;exports.detectComment=c.detectComment;exports.detectPolygon=c.detectPolygon;exports.detectText=c.detectText;exports.getAnnotationsBounds=c.getAnnotationsBounds;exports.getArrowEnd=c.getArrowEnd;exports.getArrowEndPoints=c.getArrowEndPoints;exports.getArrowSide=c.getArrowSide;exports.getArrowStart=c.getArrowStart;exports.getAttachmentPointOnNode=c.getAttachmentPointOnNode;exports.getBbox=c.getBbox;exports.getBoxCenter=c.getBoxCenter;exports.getBoxPosition=c.getBoxPosition;exports.getBoxSize=c.getBoxSize;exports.getBrowserWindow=c.getBrowserWindow;exports.getCommentPosition=c.getCommentPosition;exports.getCommentSize=c.getCommentSize;exports.getCommentZoomThreshold=c.getCommentZoomThreshold;exports.getCoordinates=c.getCoordinates;exports.getHandleId=c.getHandleId;exports.getTextBbox=c.getBbox;exports.getTextPosition=c.getBoxPosition;exports.getTextSize=c.getBoxSize;exports.handleDetectionThreshold=c.handleDetectionThreshold;exports.handleRadius=c.handleRadius;exports.hexShortToLong=c.hexShortToLong;exports.hexToRgba=c.hexToRgba;exports.isArrow=c.isArrow;exports.isBox=c.isBox;exports.isComment=c.isComment;exports.isPolygon=c.isPolygon;exports.isRigidConnector=c.isRigidConnector;exports.isText=c.isText;exports.migrateBoxOrTextIfNeeded=c.migrateBoxOrTextIfNeeded;exports.parseColor=c.parseColor;exports.rgbToRgba=c.rgbToRgba;exports.scaleGeometry=c.scaleGeometry;exports.setArrowEnd=c.setArrowEnd;exports.setArrowEndPoint=c.setArrowEndPoint;exports.setArrowStart=c.setArrowStart;exports.setBbox=c.setBbox;exports.setTextBbox=c.setBbox;exports.throttle=c.throttle;exports.toggleCommentMode=c.toggleCommentMode;exports.updateBbox=c.updateBbox;exports.updateTextBbox=c.updateBbox;exports.Control=Fr;exports.asColor=Qe;exports.asHexColor=tn;exports.asRgbColor=en;exports.asRgbaColor=nn;exports.canDetachArrowEnd=gn;exports.canDetachArrowStart=De;exports.getCascadeDeleteIds=Me;exports.getCommentLeftOrphanedBy=we;exports.getCommentLinkId=Ne;exports.getPolygonBounds=Bt;exports.getPolygonCenter=vt;exports.isAnnotationCollection=Mt;exports.isColor=ye;exports.isCommentArrow=Ce;exports.isHexColor=Lt;exports.isRgbColor=Ot;exports.isRgbaColor=Pt;exports.scalePolygon=Je;exports.simplifyPolygon=Dt;exports.translatePolygon=Ze;exports.updatePolygonBbox=kt;