@linkurious/ogma-annotations 2.1.1 → 2.1.3

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,9 +1,12 @@
1
- "use strict";var Oe=Object.defineProperty;var Re=(i,e,t)=>e in i?Oe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var S=(i,e,t)=>Re(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./Polygon-D6lGfOCn.cjs"),nt=require("@linkurious/ogma");function _e(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var gt={exports:{}},Wt;function He(){return Wt||(Wt=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,d,c){this.fn=u,this.context=d,this.once=c||!1}function r(u,d,c,h,x){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new s(c,h||u,x),g=t?t+d:d;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,d){--u._eventsCount===0?u._events=new n:delete u._events[d]}function a(){this._events=new n,this._eventsCount=0}a.prototype.eventNames=function(){var d=[],c,h;if(this._eventsCount===0)return d;for(h in c=this._events)e.call(c,h)&&d.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?d.concat(Object.getOwnPropertySymbols(c)):d},a.prototype.listeners=function(d){var c=t?t+d:d,h=this._events[c];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(d){var c=t?t+d:d,h=this._events[c];return h?h.fn?1:h.length:0},a.prototype.emit=function(d,c,h,x,f,g){var p=t?t+d:d;if(!this._events[p])return!1;var m=this._events[p],A=arguments.length,E,y;if(m.fn){switch(m.once&&this.removeListener(d,m.fn,void 0,!0),A){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,c),!0;case 3:return m.fn.call(m.context,c,h),!0;case 4:return m.fn.call(m.context,c,h,x),!0;case 5:return m.fn.call(m.context,c,h,x,f),!0;case 6:return m.fn.call(m.context,c,h,x,f,g),!0}for(y=1,E=new Array(A-1);y<A;y++)E[y-1]=arguments[y];m.fn.apply(m.context,E)}else{var D=m.length,C;for(y=0;y<D;y++)switch(m[y].once&&this.removeListener(d,m[y].fn,void 0,!0),A){case 1:m[y].fn.call(m[y].context);break;case 2:m[y].fn.call(m[y].context,c);break;case 3:m[y].fn.call(m[y].context,c,h);break;case 4:m[y].fn.call(m[y].context,c,h,x);break;default:if(!E)for(C=1,E=new Array(A-1);C<A;C++)E[C-1]=arguments[C];m[y].fn.apply(m[y].context,E)}}return!0},a.prototype.on=function(d,c,h){return r(this,d,c,h,!1)},a.prototype.once=function(d,c,h){return r(this,d,c,h,!0)},a.prototype.removeListener=function(d,c,h,x){var f=t?t+d:d;if(!this._events[f])return this;if(!c)return o(this,f),this;var g=this._events[f];if(g.fn)g.fn===c&&(!x||g.once)&&(!h||g.context===h)&&o(this,f);else{for(var p=0,m=[],A=g.length;p<A;p++)(g[p].fn!==c||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(d){var c;return d?(c=t?t+d:d,this._events[c]&&o(this,c)):(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})(gt)),gt.exports}var Ie=He();const Ge=_e(Ie);function ze(i,e){const t=i[0]-e[0],n=i[1]-e[1];return t*t+n*n}function Ye(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 We(i,e){let t=i[0];const n=[t];let s;for(let r=1,o=i.length;r<o;r++)s=i[r],ze(s,t)>e&&(n.push(s),t=s);return t!==s&&n.push(s),n}function Ct(i,e,t,n,s){let r=n,o=0;for(let a=e+1;a<t;a++){const u=Ye(i[a],i[e],i[t]);u>r&&(o=a,r=u)}r>n&&(o-e>1&&Ct(i,e,o,n,s),s.push(i[o]),t-o>1&&Ct(i,o,t,n,s))}function $e(i,e){const t=i.length-1,n=[i[0]];return Ct(i,0,t,e,n),n.push(i[t]),n}function Nt(i,e,t){if(i.length<=2)return i;const n=e!==void 0?e*e:1;return i=t?i:We(i,n),i=$e(i,n),i}function Dt(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 Bt(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 Ue(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 Tt(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 Xe(i,e,t,n){const s=i.geometry.coordinates.map(o=>o.map(([a,u])=>{const d=a-t,c=u-n;return[t+d*e,n+c*e]})),r={...i,geometry:{...i.geometry,coordinates:s}};return Tt(r),r}const Mt=i=>i.type==="FeatureCollection";function vt(i){return/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(i.trim())}function kt(i){return/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(i.trim())}function Lt(i){return/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[0-9.]+\s*\)$/.test(i.trim())}function Ee(i){return vt(i)||kt(i)||Lt(i)}function Ve(i){if(Ee(i))return i;throw new Error(`Invalid color format: ${i}`)}function je(i){if(vt(i))return i;throw new Error(`Invalid hex color format: ${i}`)}function qe(i){if(kt(i))return i;throw new Error(`Invalid RGB color format: ${i}`)}function Ke(i){if(Lt(i))return i;throw new Error(`Invalid RGBA color format: ${i}`)}class Ze{constructor(e){S(this,"previousZoom",-1);this.store=e}toggleComment(e){const t=this.store.getState().getFeature(e);if(!t||!l.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(l.isComment(r)){const o=r,a=this.getCommentZoomThreshold(o),u=e<a?l.COMMENT_MODE_COLLAPSED:l.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 Pt="ogma-annotation-link";function at(i){let e=i;for(;e;){if(e.classList&&e.classList.contains(Pt))return!0;e=e.parentElement}return!1}const Je="(https?://[^\\s<]+)";function Fe(){return new RegExp(Je,"g")}function Qe(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 lt 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,"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(l.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||at(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.ogma.setOptions({interactions:{pan:{enabled:!1},drag:{enabled:!1}}})});S(this,"restorePanning",()=>{this.ogma.setOptions({interactions:{pan:{enabled:!0},drag:{enabled:!0}}})});S(this,"handleMouseUp",t=>{this.isActive()&&this.dragging&&(this.restorePanning(),this.onDragEnd(t),this.dispatchEvent(new CustomEvent(l.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(l.cursors.default)}commitChange(){this.getAnnotation()&&this.store.getState().commitLiveUpdates()}onDrag(t){this.dispatchEvent(new Event(l.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=l.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=l.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=l.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(l.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}}class tn extends lt{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 y;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||!l.isArrow(s))return;const r=s.geometry.coordinates[0],o=s.geometry.coordinates[1],a=o[0]-this.startX,u=o[1]-this.startY,d=Math.sqrt(a*a+u*u);let c,h;d<5?(c=this.startX+this.offsetX,h=this.startY+this.offsetY):(c=o[0],h=o[1]);const x=this.comment;x.geometry.coordinates=[c,h],t.addFeature(x),this.store.setState({drawingFeature:x.id});const f=x.properties.height,g=t.zoom,p=f/g,m=c,A=h+p*.5;this.snapArrowStart(s,r[0],r[1]);const E=(y=s.properties.link)==null?void 0:y.start;t.updateFeature(s.id,{...s,geometry:{...s.geometry,coordinates:[[m,A],r]},properties:{...s.properties,link:{start:{side:l.SIDE_START,id:x.id,type:l.TARGET_TYPES.COMMENT,magnet:{x:0,y:.5}},end:E?{side:l.SIDE_END,id:E.id,type:E.type,magnet:E.magnet}:void 0}}}),this.links.add(s,l.SIDE_START,x.id,l.TARGET_TYPES.COMMENT,{x:0,y:.5}),E&&E.magnet&&this.links.add(s,l.SIDE_END,E.id,E.type,E.magnet),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=l.createArrow(n,s,n,s,{...l.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:l.SIDE_START,id:r.id,type:r.type,magnet:r.magnet}},this.links.add(t,l.SIDE_START,r.id,r.type,r.magnet))}}function en(i,e,t,n,s){const{width:r,height:o}=n.view.getSize(),a=8,u=16,d=a*u,c={width:150,height:50},h=c.width,x=c.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 A=0;A<d;A++){const E=A%a,y=Math.floor(A/a),D=2*Math.PI*(E/a),C=g+y/u*(f-g),F=Math.cos(D)*C,N=Math.sin(D)*C,M=m.x+F,T=m.y+N;if(p.minX=M,p.minY=T-x/2,p.maxX=M+h,p.maxY=T+x/2,F<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}),B=n.view.screenToGraphCoordinates({x:p.maxX,y:p.maxY});if(p.minX=b.x,p.minY=b.y,p.maxX=B.x,p.maxY=B.y,!t.query(p).filter(P=>P.properties.type!=="arrow").length)return n.view.screenToGraphCoordinates({x:M,y:T})}return n.view.screenToGraphCoordinates({x:r/2,y:o/2})}const $t=160,nn={font:"IBM Plex Sans",fontSize:18,color:"#4A3B00",background:"#FFEB99",strokeWidth:0,strokeType:"plain",borderRadius:4,padding:16,fixedSize:!1,placeholder:"Quick note…"};class sn{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(l.EVT_CLICK,this.onEraseClick),this.interactions.setCursor(l.cursors.crosshair),this.control)}disableEraseMode(){return this.eraseModeActive?(this.eraseModeActive=!1,this.control.off(l.EVT_CLICK,this.onEraseClick),this.interactions.setCursor(l.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=l.createArrow(t,n,t,n,e);this.startArrow(t,n,s)})}enableTextDrawing(e){return this.enableDrawingMode((t,n)=>{const s=l.createText(t,n,0,0,void 0,e);this.startText(t,n,s)})}enableBoxDrawing(e){return this.enableDrawingMode((t,n)=>{const s=l.createBox(t,n,0,0,e);this.startBox(t,n,s)})}enablePolygonDrawing(e){return this.enableDrawingMode((t,n)=>{const s=l.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=en(t,n,this.index,this.ogma);s=a.x,r=a.y}const o=l.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=l.createText(e,t,0,0,"",{...nn,...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:$t,height:$t},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:d}=this.ogma.view.screenToGraphCoordinates(a),c=e.properties.width,h=e.properties.height;this.store.getState().applyLiveUpdate(e.id,{geometry:{...e.geometry,coordinates:[u,d],bbox:[u-c/2,d-h/2,u+c/2,d+h/2]}})},s=a=>{o();const{x:u,y:d}=this.ogma.view.screenToGraphCoordinates(a),c=e.properties.width,h=e.properties.height;this.store.getState().updateFeature(e.id,{geometry:{...e.geometry,coordinates:[u,d],bbox:[u-c/2,d-h/2,u+c/2,d+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 tn(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(l.EVT_ADD,o),(u=this.editor.getActiveHandler())==null||u.startEditingText())};return this.control.on(l.EVT_ADD,o),r.startDrawing(n.id,e,t),this.control}startBox(e,t,n){return n||(n=l.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=l.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=l.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 rn{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 on{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 an{constructor(e){this.store=e}add(e){if(Mt(e))for(const t of e.features)this.add(t);else{const t=l.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(l.isArrow(r)){const a=r.geometry.coordinates.map(([u,d])=>{const c=u-n,h=d-s;return[n+c*t,s+h*t]});o.updateFeature(e,{geometry:{...r.geometry,coordinates:a}})}else if(l.isText(r)||l.isBox(r)){const[a,u]=r.geometry.coordinates,d=a-n,c=u-s,h=n+d*t,x=s+c*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 Ae(i){var t,n;const e=i.properties.link;return e?((t=e.start)==null?void 0:t.type)===l.TARGET_TYPES.COMMENT||((n=e.end)==null?void 0:n.type)===l.TARGET_TYPES.COMMENT:!1}function ye(i){var e,t;return((t=(e=i.properties.link)==null?void 0:e.start)==null?void 0:t.type)!==l.TARGET_TYPES.COMMENT}function cn(i){return!0}function Ot(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 d="";if(l.isArrow(o)){const h=o;if(s){const x=h.properties.link||{};x.start&&it(x.start.type)&&a.add(x.start.id),x.end&&it(x.end.type)&&a.add(x.end.id)}d=h.id,u.add(h.id)}else a.add(o.id);const c={};for(const h of a){const x=r.getFeature(h);if(!x)continue;const f=ln(x,n);f&&(c[h]=f,e.updateLinkedArrowsDuringDrag(h,n,c))}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&&it(f.start.type)||d===h)&&(p[0]=[g[0][0]+n.x,g[0][1]+n.y]),(f.end&&it(f.end.type)||d===h)&&(p[1]=[g[1][0]+n.x,g[1][1]+n.y]),c[h]={geometry:{...x.geometry,coordinates:p}}}r.applyLiveUpdates(c)}function it(i){return i!==l.TARGET_TYPES.NODE&&i!==l.TARGET_TYPES.EDGE}function ln(i,e){if(l.isText(i)||l.isBox(i)||l.isComment(i)){const t=l.getBoxCenter(i);return{geometry:{type:i.geometry.type,coordinates:[t.x+e.x,t.y+e.y]}}}if(l.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 dn extends lt{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=l.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)),d=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]):d<r?this.grabHandle("end",a[0],a[1]):l.detectArrow(n,s,r)?(this.setCursor(l.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(l.cursors.move)}onDrag(t){var c;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=((c=this.snap)==null?void 0:c.point)||o,u=new CustomEvent(l.EVT_DRAG,{detail:{point:a,annotation:this.annotation,handle:n}}),d=[...s.geometry.coordinates];if(n.type==="body"){const h=a.x-n.point.x,x=a.y-n.point.y;Ot(this.store,this.links,s.id,{x:h,y:x},!0),this.dispatchEvent(u);return}else n.type==="start"?(d[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"&&(d[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:d}}),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"&&!ye(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 d=n.geometry.coordinates;if(this.hoveredHandle.type==="body"){const c=this.snapping.snap({x:d[0][0],y:d[0][1]}),h=this.snapping.snap({x:d[1][0],y:d[1][1]});c?this.links.add(n,"start",c.id,c.type,c.magnet):((o=(r=n.properties.link)==null?void 0:r.start)==null?void 0:o.type)!=="comment"&&this.links.remove(n,l.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,l.SIDE_END)}else if(this.snap){const c=this.hoveredHandle;c.type!=="body"&&this.links.add(n,c.type,this.snap.id,this.snap.type,this.snap.magnet)}else if(this.snap===null){const c=this.hoveredHandle.type;if(n.properties.link&&n.properties.link[c]){this.links.remove(n,c);const h={...n.properties.link};delete h[c],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:l.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=l.getArrowSide(t,s);const o=t.properties.link||{};let a=null;if(n instanceof nt.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(l.isText(u)||l.isBox(u))r=l.getBoxCenter(u),a=this.snapping.snapToText(r,[u]);else if(l.isPolygon(u))r=Bt(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),l.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}}))}}class un extends lt{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(l.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=l.handleDetectionThreshold/n,a=s.geometry.coordinates[0];for(let u=0;u<a.length-1;u++){const[d,c]=a[u];if(Math.sqrt(Math.pow(r.x-d,2)+Math.pow(r.y-c,2))<o*2){this.grabHandle("vertex",d,c,u);return}}l.detectPolygon(s,r,o)?(this.setCursor(l.cursors.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,s,r){this.setCursor(t==="vertex"?l.cursors.pointer:l.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(l.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(),d=this.getAnnotation();if(!d)return;const c=u.liveUpdates[this.annotation],h=c?{...d,...c}:d,f=u.drawingPoints.slice(0,-1),g=[...f,[a.x,a.y],f[0]];u.setDrawingPoints(g);const p=Nt(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")Ot(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((d,c)=>c===this.hoveredHandle.vertexIndex?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:c===o.geometry.coordinates[0].length-1&&this.hoveredHandle.vertexIndex===0?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:d),u={...o,geometry:{...o.geometry,coordinates:[a]}};Tt(u),this.store.getState().applyLiveUpdate(o.id,u),this.links.snapLinkedArrowsDuringDrag(o.id)}this.dispatchEvent(new Event(l.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=Nt(r.slice(1,-1),this.simplificationTolerance,!0),a={...s,geometry:{type:"Polygon",coordinates:[o]}};l.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(l.EVT_COMPLETE_DRAWING,{detail:a}))}}return!0}return!this.dragging||(this.dragging=!1,this.dragStartPoint=void 0,!this.getAnnotation())?!1:(this.commitChange(),this.setCursor(l.cursors.grab),!0)}getAnnotation(){if(this.annotation)return this.store.getState().getFeature(this.annotation)}}class hn{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,A;this.ogma=e,this.store=t,this.annotation=n,this.onSendHandler=s;const r=this.getAnnotation(),o=this.store.getState(),a=l.isComment(r)&&(((f=o.options)==null?void 0:f.showSendButton)??!0),u=((g=o.options)==null?void 0:g.sendButtonIcon)||"",d=((p=r.properties.style)==null?void 0:p.placeholder)||((m=o.options)==null?void 0:m.textPlaceholder)||"Enter text",c=l.isComment(r)?l.defaultCommentStyle:l.defaultTextStyle;this.fixedSize=((A=r.properties.style)==null?void 0:A.fixedSize)??c.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="${d}"></textarea>
3
- ${a?`<button class="ogma-send-button" type="button" title="Send">
4
- <span class="ogma-send-button-icon">${u}</span>
1
+ "use strict";var rn=Object.defineProperty;var on=(i,e,t)=>e in i?rn(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var S=(i,e,t)=>on(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./Polygon-DVGwsFvt.cjs"),lt=require("@linkurious/ogma");function an(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Nt={exports:{}},te;function cn(){return te||(te=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(d,l,h){this.fn=d,this.context=l,this.once=h||!1}function r(d,l,h,u,x){if(typeof h!="function")throw new TypeError("The listener must be a function");var f=new s(h,u||d,x),g=t?t+l:l;return d._events[g]?d._events[g].fn?d._events[g]=[d._events[g],f]:d._events[g].push(f):(d._events[g]=f,d._eventsCount++),d}function o(d,l){--d._eventsCount===0?d._events=new n:delete d._events[l]}function a(){this._events=new n,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],h,u;if(this._eventsCount===0)return l;for(u in h=this._events)e.call(h,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(h)):l},a.prototype.listeners=function(l){var h=t?t+l:l,u=this._events[h];if(!u)return[];if(u.fn)return[u.fn];for(var x=0,f=u.length,g=new Array(f);x<f;x++)g[x]=u[x].fn;return g},a.prototype.listenerCount=function(l){var h=t?t+l:l,u=this._events[h];return u?u.fn?1:u.length:0},a.prototype.emit=function(l,h,u,x,f,g){var m=t?t+l:l;if(!this._events[m])return!1;var p=this._events[m],A=arguments.length,y,F;if(p.fn){switch(p.once&&this.removeListener(l,p.fn,void 0,!0),A){case 1:return p.fn.call(p.context),!0;case 2:return p.fn.call(p.context,h),!0;case 3:return p.fn.call(p.context,h,u),!0;case 4:return p.fn.call(p.context,h,u,x),!0;case 5:return p.fn.call(p.context,h,u,x,f),!0;case 6:return p.fn.call(p.context,h,u,x,f,g),!0}for(F=1,y=new Array(A-1);F<A;F++)y[F-1]=arguments[F];p.fn.apply(p.context,y)}else{var b=p.length,C;for(F=0;F<b;F++)switch(p[F].once&&this.removeListener(l,p[F].fn,void 0,!0),A){case 1:p[F].fn.call(p[F].context);break;case 2:p[F].fn.call(p[F].context,h);break;case 3:p[F].fn.call(p[F].context,h,u);break;case 4:p[F].fn.call(p[F].context,h,u,x);break;default:if(!y)for(C=1,y=new Array(A-1);C<A;C++)y[C-1]=arguments[C];p[F].fn.apply(p[F].context,y)}}return!0},a.prototype.on=function(l,h,u){return r(this,l,h,u,!1)},a.prototype.once=function(l,h,u){return r(this,l,h,u,!0)},a.prototype.removeListener=function(l,h,u,x){var f=t?t+l:l;if(!this._events[f])return this;if(!h)return o(this,f),this;var g=this._events[f];if(g.fn)g.fn===h&&(!x||g.once)&&(!u||g.context===u)&&o(this,f);else{for(var m=0,p=[],A=g.length;m<A;m++)(g[m].fn!==h||x&&!g[m].once||u&&g[m].context!==u)&&p.push(g[m]);p.length?this._events[f]=p.length===1?p[0]:p:o(this,f)}return this},a.prototype.removeAllListeners=function(l){var h;return l?(h=t?t+l:l,this._events[h]&&o(this,h)):(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})(Nt)),Nt.exports}var ln=cn();const dn=an(ln);function hn(i,e){const t=i[0]-e[0],n=i[1]-e[1];return t*t+n*n}function un(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 xn(i,e){let t=i[0];const n=[t];let s;for(let r=1,o=i.length;r<o;r++)s=i[r],hn(s,t)>e&&(n.push(s),t=s);return t!==s&&n.push(s),n}function Lt(i,e,t,n,s){let r=n,o=0;for(let a=e+1;a<t;a++){const d=un(i[a],i[e],i[t]);d>r&&(o=a,r=d)}r>n&&(o-e>1&&Lt(i,e,o,n,s),s.push(i[o]),t-o>1&&Lt(i,o,t,n,s))}function fn(i,e){const t=i.length-1,n=[i[0]];return Lt(i,0,t,e,n),n.push(i[t]),n}function Ot(i,e,t){if(i.length<=2)return i;const n=e!==void 0?e*e:1;return i=t?i:xn(i,n),i=fn(i,n),i}function zt(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 Gt(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 gn(i,e,t){const n=i.geometry.coordinates.map(o=>o.map(([a,d])=>[a+e,d+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 Ut(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 pn(i,e,t,n){const s=i.geometry.coordinates.map(o=>o.map(([a,d])=>{const l=a-t,h=d-n;return[t+l*e,n+h*e]})),r={...i,geometry:{...i.geometry,coordinates:s}};return Ut(r),r}const Pt=i=>i.type==="FeatureCollection";function Wt(i){return/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(i.trim())}function Yt(i){return/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(i.trim())}function $t(i){return/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*[0-9.]+\s*\)$/.test(i.trim())}function Oe(i){const e=i.trim();return e==="transparent"||e==="none"||Wt(e)||Yt(e)||$t(e)}function mn(i){if(Oe(i))return i;throw new Error(`Invalid color format: ${i}`)}function Sn(i){if(Wt(i))return i;throw new Error(`Invalid hex color format: ${i}`)}function En(i){if(Yt(i))return i;throw new Error(`Invalid RGB color format: ${i}`)}function Fn(i){if($t(i))return i;throw new Error(`Invalid RGBA color format: ${i}`)}class yn{constructor(e){S(this,"previousZoom",-1);this.store=e}toggleComment(e){const t=this.store.getState(),n=t.getMergedFeature(e);if(!n||!c.isComment(n))return;const s=n;t.applyLiveUpdate(e,{properties:{...s.properties,mode:s.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={};Object.keys(t.features).forEach(s=>{const r=t.getMergedFeature(s);if(!r||!c.isComment(r))return;const o=r,a=this.getCommentZoomThreshold(o),d=e<a?c.COMMENT_MODE_COLLAPSED:c.COMMENT_MODE_EXPANDED;o.properties.mode!==d&&(n[s]={properties:{...o.properties,mode:d}})}),t.applyLiveUpdates(n)}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 Vt="ogma-annotation-link";function ct(i){let e=i;for(;e;){if(e.classList&&e.classList.contains(Vt))return!0;e=e.parentElement}return!1}const An="(https?://[^\\s)<]+)";function Pe(){return new RegExp(An,"g")}const Cn="\\[([^\\]\\n]+)\\]\\((https?://[^\\s)<]+)\\)";function Nn(){return new RegExp(Cn,"g")}function bn(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dn(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 Et 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||ct(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){const n=this.ogma.getContainer(),s=n?c.getBrowserWindow()||n:null;n&&s&&(s.removeEventListener("mousemove",this.handleMouseMove),s.removeEventListener("mouseup",this.handleMouseUp),n.removeEventListener("mousedown",this.handleMouseDown,!0),s.removeEventListener("click",this.onClick,!0)),this.annotation=t?t.id:null,this.annotation!==null?n&&s&&(s.addEventListener("mousemove",this.handleMouseMove),s.addEventListener("mouseup",this.handleMouseUp,!1),n.addEventListener("mousedown",this.handleMouseDown,!0),s.addEventListener("click",this.onClick,!0)):(this.clearDragState(),this.setCursor(c.cursors.default))}isAnnotation(t){return this.annotation===t}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.store.setState({drawingFeature:null})),this.stopEditing()}isActive(){return this.annotation!==null}}const Mn=5;class wn extends Et{constructor(t,n,s,r,o,a,d){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 b;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,d=o[1]-this.startY,l=Math.sqrt(a*a+d*d);let h,u;l<Mn?(h=this.startX+this.offsetX,u=this.startY+this.offsetY):(h=o[0],u=o[1]);const x=this.comment;x.geometry.coordinates=[h,u];const f=x.properties.height,g=t.zoom,m=f/g,p=h,A=u+m*.5;this.snapArrowStart(s,r[0],r[1]);const y=(b=s.properties.link)==null?void 0:b.start,F={...s,geometry:{...s.geometry,coordinates:[[p,A],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.store.setState(C=>{const E={...C.liveUpdates};return delete E[s.id],{features:{...C.features,[x.id]:x,[s.id]:F},liveUpdates:E,drawingFeature:x.id}}),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=(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,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().batchUpdate(()=>{this.store.getState().addFeature(r),this.store.setState({drawingFeature:r.id}),this.store.getState().setSelectedFeatures([r.id])}),this.arrowHandler.addEventListener("dragend",this.onArrowComplete),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 vn(i,e,t,n,s){const{width:r,height:o}=n.view.getSize(),a=8,d=16,l=a*d,h={width:150,height:50},u=h.width,x=h.height,f=Math.max(r,o),g=200,m={minX:0,minY:0,maxX:0,maxY:0},p=n.view.graphToScreenCoordinates({x:i,y:e});for(let A=0;A<l;A++){const y=A%a,F=Math.floor(A/a),b=2*Math.PI*(y/a),C=g+F/d*(f-g),E=Math.cos(b)*C,N=Math.sin(b)*C,D=p.x+E,v=p.y+N;if(m.minX=D,m.minY=v-x/2,m.maxX=D+u,m.maxY=v+x/2,E<0&&(m.minX-=u,m.maxX-=u),m.minX<0||m.maxX>r||m.minY<0||m.maxY>o)continue;const T=n.view.screenToGraphCoordinates({x:m.minX,y:m.minY}),w=n.view.screenToGraphCoordinates({x:m.maxX,y:m.maxY});if(m.minX=T.x,m.minY=T.y,m.maxX=w.x,m.maxY=w.y,!t.query(m).filter(O=>O.properties.type!=="arrow").length)return n.view.screenToGraphCoordinates({x:D,y:v})}return n.view.screenToGraphCoordinates({x:r/2,y:o/2})}const ee=160,Tn={font:"IBM Plex Sans",fontSize:18,color:"#4A3B00",background:"#FFEB99",strokeWidth:0,strokeType:"plain",borderRadius:4,padding:16,fixedSize:!1,placeholder:"Quick note…",scaleFontOnResize:!0};class Bn{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=vn(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,"",{...Tn,...n});return this.store.getState().batchUpdate(()=>{this.store.setState({drawingFeature:s.id}),this.control.add(s),this.control.select(s.id)}),this.interactions.suppressClicksTemporarily(200),this.editor.getActiveHandler().startDrawing(s.id,e,t,{defaultSize:{width:ee,height:ee},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:d,y:l}=this.ogma.view.screenToGraphCoordinates(a),h=e.properties.width,u=e.properties.height;this.store.getState().applyLiveUpdate(e.id,{geometry:{...e.geometry,coordinates:[d,l],bbox:[d-h/2,l-u/2,d+h/2,l+u/2]}})},s=a=>{o();const{x:d,y:l}=this.ogma.view.screenToGraphCoordinates(a),h=e.properties.width,u=e.properties.height;this.store.getState().updateFeature(e.id,{geometry:{...e.geometry,coordinates:[d,l],bbox:[d-h/2,l-u/2,d+h/2,l+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(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.getState().batchUpdate(()=>{this.store.setState({drawingFeature:n.id})}),this.interactions.suppressClicksTemporarily(200);const r=new wn(this.ogma,this.store,this.links,this.editor.getSnapping(),this.editor.getArrowHandler(),n,s),o=a=>{var d;a.id===n.id&&(this.control.select(a.id),this.control.off(c.EVT_ADD,o),(d=this.editor.getActiveHandler())==null||d.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.getState().batchUpdate(()=>{this.store.setState({drawingFeature:n.id}),this.control.add(n),this.control.select(n.id)}),this.interactions.suppressClicksTemporarily(200),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.getState().batchUpdate(()=>{this.store.setState({drawingFeature:n.id}),this.control.add(n),this.control.select(n.id)}),this.interactions.suppressClicksTemporarily(200),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startText(e,t,n){return n||(n=c.createText(e,t)),this.store.getState().batchUpdate(()=>{this.store.setState({drawingFeature:n.id}),this.control.add(n),this.control.select(n.id)}),this.interactions.suppressClicksTemporarily(200),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}startPolygon(e,t,n){return this.store.getState().batchUpdate(()=>{this.store.setState({drawingFeature:n.id}),this.control.add(n),this.control.select(n.id)}),this.interactions.suppressClicksTemporarily(200),this.editor.getActiveHandler().startDrawing(n.id,e,t),this.control}}class kn{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 Ln{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 On{constructor(e){this.store=e}add(e){if(Pt(e))for(const t of e.features)this.add(t);else{const t=c.migrateBoxOrTextIfNeeded(e);this.store.getState().addFeature(t)}}remove(e){if(Pt(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(([d,l])=>{const h=d-n,u=l-s;return[n+h*t,s+u*t]});o.updateFeature(e,{geometry:{...r.geometry,coordinates:a}})}else if(c.isText(r)||c.isBox(r)){const[a,d]=r.geometry.coordinates,l=a-n,h=d-s,u=n+l*t,x=s+h*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:[u,x]}})}}}function Re(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 _e(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 Ie(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 Pn(i){return!0}function He(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,d;c.isArrow(s)&&(((o=(r=s.properties.link)==null?void 0:r.end)==null?void 0:o.id)===e||((d=(a=s.properties.link)==null?void 0:a.start)==null?void 0:d.id)===e)&&t.add(s.id)}),t}function ze(i,e){var r,o,a,d;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:((d=(a=t.properties.link)==null?void 0:a.start)==null?void 0:d.type)===c.TARGET_TYPES.COMMENT?t.properties.link.start.id:null;return n?Object.values(i).some(l=>{var h,u,x,f;return c.isArrow(l)&&l.id!==e&&(((u=(h=l.properties.link)==null?void 0:h.end)==null?void 0:u.id)===n||((f=(x=l.properties.link)==null?void 0:x.start)==null?void 0:f.id)===n)})?null:n:null}function Xt(i,e,t,n,s=!1){const r=i.getState(),o={};Rt(r,e,t,n,s,o);for(const a of r.selectedFeatures)a!==t&&Rt(r,e,a,n,!1,o);r.applyLiveUpdates(o)}function Rn(i){return i!==c.TARGET_TYPES.NODE&&i!==c.TARGET_TYPES.EDGE}function Rt(i,e,t,n,s,r){const o=i.getFeature(t);if(!o)return;if(c.isArrow(o)){if(s){const l=o.properties.link||{};for(const h of[l.start,l.end])h&&Rn(h.type)&&Rt(i,e,h.id,n,!1,r)}const d=o.geometry.coordinates;r[t]={geometry:{...o.geometry,coordinates:[[d[0][0]+n.x,d[0][1]+n.y],[d[1][0]+n.x,d[1][1]+n.y]]}};return}const a=_n(o,n);a&&(r[t]=a,e.updateLinkedArrowsDuringDrag(t,n,r))}function _n(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 In extends Et{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],d=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));d<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 h;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=((h=this.snap)==null?void 0:h.point)||o,d=new CustomEvent(c.EVT_DRAG,{detail:{point:a,annotation:this.annotation,handle:n}}),l=[...s.geometry.coordinates];if(n.type==="body"){const u=a.x-n.point.x,x=a.y-n.point.y;Xt(this.store,this.links,s.id,{x:u,y:x},!0),this.dispatchEvent(d);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(d)}onDragStart(t){if(!super.onDragStart(t))return!1;const n=this.getAnnotation(),s=this.hoveredHandle;return s.type==="end"&&!1||s.type==="start"&&!Ie(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 l=n.geometry.coordinates;if(this.hoveredHandle.type==="body"){const h=this.snapping.snap({x:l[0][0],y:l[0][1]}),u=this.snapping.snap({x:l[1][0],y:l[1][1]});h?this.links.add(n,"start",h.id,h.type,h.magnet):((o=(r=n.properties.link)==null?void 0:r.start)==null?void 0:o.type)!=="comment"&&this.links.remove(n,c.SIDE_START),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,c.SIDE_END)}else if(this.snap){const h=this.hoveredHandle;h.type!=="body"&&this.links.add(n,h.type,this.snap.id,this.snap.type,this.snap.magnet)}else if(this.snap===null){const h=this.hoveredHandle.type;if(n.properties.link&&n.properties.link[h]){this.links.remove(n,h);const u={...n.properties.link};delete u[h],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,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){if(!this.store.getState().options.isEditable(t)){console.error(`Cannot link annotation ${t.id}: not editable`);return}let r=c.getArrowSide(t,s);const o=t.properties.link||{};let a=null;if(n instanceof lt.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(c.isText(d)||c.isBox(d))r=c.getBoxCenter(d),a=this.snapping.snapToText(r,[d]);else if(c.isPolygon(d))r=Gt(d),a=this.snapping.snapToPolygon(r,[d]);else throw new Error(`Cannot link arrow to annotation of type ${d.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 Hn=-2;class zn extends Et{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(){if(this.isDrawingMode&&(this.isDrawingMode=!1,this.annotation)){const t=this.annotation,n=this.store.getState().drawingFeature===t;this.store.getState().removeFeature(t),n&&this.store.setState({drawingFeature:null}),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 d=0;d<a.length-1;d++){const[l,h]=a[d];if(Math.sqrt(Math.pow(r.x-l,2)+Math.pow(r.y-h,2))<o*2){this.grabHandle("vertex",l,h,d);return}}c.detectPolygon(s,r,o)?(this.setCursor(c.cursors.grab),this.hoveredHandle={type:"body",point:r},this.store.setState({hoveredHandle:Hn,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),d=this.store.getState(),l=this.getAnnotation();if(!l)return;const h=d.liveUpdates[this.annotation],u=h?{...l,...h}:l,f=d.drawingPoints.slice(0,-1),g=[...f,[a.x,a.y],f[0]];d.setDrawingPoints(g);const m=Ot(g,this.simplificationTolerance,!1),p=[...m,m[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),s=n.x-this.dragStartPoint.x,r=n.y-this.dragStartPoint.y,o=this.getAnnotation();if(o){if(this.hoveredHandle.type==="body")Xt(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,h)=>h===this.hoveredHandle.vertexIndex?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:h===o.geometry.coordinates[0].length-1&&this.hoveredHandle.vertexIndex===0?[this.hoveredHandle.point.x+s,this.hoveredHandle.point.y+r]:l),d={...o,geometry:{...o.geometry,coordinates:[a]}};Ut(d),this.store.getState().applyLiveUpdate(o.id,d),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=Ot(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 Gn=["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"],ne=[[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 Un(i){if(i<=255)return Gn[i];let e=0,t=ne.length-1;for(;e<=t;){const n=e+t>>1,s=ne[n];if(i<s[0]){t=n-1;continue}if(i>s[1]){e=n+1;continue}return s[2]}return"L"}function Wn(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 h=i.charCodeAt(l);let u=h,x=1;if(h>=55296&&h<=56319&&l+1<e){const g=i.charCodeAt(l+1);g>=56320&&g<=57343&&(u=(h-55296<<10)+(g-56320)+65536,x=2)}const f=Un(u);(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 h=t[l];if(h==="L"){s=0;break}if(h==="R"||h==="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 d=a;for(let l=0;l<e;l++)t[l]==="NSM"?t[l]=d:d=t[l];d=a;for(let l=0;l<e;l++){const h=t[l];h==="EN"?t[l]=d==="AL"?"AN":"EN":(h==="R"||h==="L"||h==="AL")&&(d=h)}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 h;for(h=l-1;h>=0&&t[h]==="ET";h--)t[h]="EN";for(h=l+1;h<e&&t[h]==="ET";h++)t[h]="EN"}for(let l=0;l<e;l++){const h=t[l];(h==="WS"||h==="ES"||h==="ET"||h==="CS")&&(t[l]="ON")}d=a;for(let l=0;l<e;l++){const h=t[l];h==="EN"?t[l]=d==="L"?"L":"EN":(h==="R"||h==="L")&&(d=h)}for(let l=0;l<e;l++){if(t[l]!=="ON")continue;let h=l+1;for(;h<e&&t[h]==="ON";)h++;const u=l>0?t[l-1]:a,x=h<e?t[h]:a,f=u!=="L"?"R":"L";if(f===(x!=="L"?"R":"L"))for(let m=l;m<h;m++)t[m]=f;l=h-1}for(let l=0;l<e;l++)t[l]==="ON"&&(t[l]=o);for(let l=0;l<e;l++){const h=t[l];(r[l]&1)===0?h==="R"?r[l]++:(h==="AN"||h==="EN")&&(r[l]+=2):(h==="L"||h==="AN"||h==="EN")&&r[l]++}return r}function Yn(i,e){const t=Wn(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 $n=/[ \t\n\r\f]+/g,Vn=/[\t\n\r\f]| {2,}|^ | $/;function Xn(i){const e=i??"normal";return e==="pre-wrap"?{mode:e,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:e,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function jn(i){if(!Vn.test(i))return i;let e=i.replace($n," ");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 Kn(i){return/[\r\f]/.test(i)?i.replace(/\r\n/g,`
2
+ `).replace(/[\r\f]/g,`
3
+ `):i}let bt=null,qn;function Zn(){return bt===null&&(bt=new Intl.Segmenter(qn,{granularity:"word"})),bt}const Jn=new RegExp("\\p{Script=Arabic}","u"),K=new RegExp("\\p{M}","u"),jt=new RegExp("\\p{Nd}","u");function se(i){return Jn.test(i)}function ie(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 W(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(ie(s))return!0;e++;continue}}if(ie(t))return!0}}return!1}function Qn(i){const e=dt(i);return e!==null&&(Kt.has(e)||j.has(e))}const ts=new Set([" "," ","⁠","\uFEFF"]),es=new Set(["-","‐","–","—"]);function ns(i){const e=dt(i);return e!==null&&ts.has(e)}function ss(i){const e=dt(i);return e!==null&&es.has(e)}function Ge(i,e){return ns(i)?!1:e?!(Qn(i)||ss(i)):!0}const Kt=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),Ft=new Set(['"',"(","[","{","¡","¿","“","‘","‚","„","«","‹","⸘","(","〔","〈","《","「","『","【","〖","〘","〚"]),qt=new Set(["'","’"]),j=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),is=new Set([":",".","،","؛"]),rs=new Set(["၏"]),os=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function as(i){if(Zt(i))return!0;let e=!1;for(const t of i){if(j.has(t)||At(t)){e=!0;continue}if(!(e&&K.test(t)))return!1}return e}function cs(i){for(const e of i)if(!Kt.has(e)&&!j.has(e))return!1;return i.length>0}function ls(i){if(Zt(i))return!0;for(const e of i)if(!Ft.has(e)&&!qt.has(e)&&!K.test(e)&&!At(e))return!1;return i.length>0}function Zt(i){let e=!1;for(const t of i)if(!(t==="\\"||K.test(t))){if(Ft.has(t)||j.has(t)||qt.has(t)){e=!0;continue}return!1}return e}function yt(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 dt(i){if(i.length===0)return null;const e=yt(i,i.length);return i.slice(e)}function ds(i){for(const e of i)if(!K.test(e))return e;return null}function hs(i){for(let e=i.length;e>0;){const t=yt(i,e),n=i.slice(t,e);if(!K.test(n))return n;e=t}return null}const us=[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 xs(i,e){for(let t=0;t<e.length;t+=2)if(i>=e[t]&&i<=e[t+1])return!0;return!1}function At(i){const e=i.codePointAt(0);return e!==void 0&&xs(e,us)}function fs(i){const e=hs(i);return e!==null&&At(e)}function gs(i){const e=ds(i);return e!==null&&jt.test(e)}function ps(i){const e=Array.from(i);let t=e.length;for(;t>0;){const n=e[t-1];if(K.test(n)){t--;continue}if(Ft.has(n)||qt.has(n)){t--;continue}break}return t<=0||t===e.length?null:{head:e.slice(0,t).join(""),tail:e.slice(t).join("")}}function ms(i,e,t){return t==="text"&&!e&&i.length===1&&i!=="-"&&i!=="—"?i:null}function re(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 oe(i,e){return i&&e!==null&&is.has(e)}function Ss(i){const e=dt(i);return e!==null&&rs.has(e)}function Es(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 _t(i){let e=i.length;for(;e>0;){const t=yt(i,e),n=i.slice(t,e);if(os.has(n))return!0;if(!j.has(n))return!1;e=t}return!1}function Fs(i,e){if(e.preserveOrdinarySpaces||e.preserveHardBreaks){if(i===" ")return"preserved-space";if(i===" ")return"tab";if(e.preserveHardBreaks&&i===`
4
+ `)return"hard-break"}return i===" "?"space":i===" "||i===" "||i==="⁠"||i==="\uFEFF"?"glue":i==="​"?"zero-width-break":i==="­"?"soft-hyphen":"text"}const ys=/[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;function U(i){return i.length===1?i[0]:i.join("")}function As(i,e){const t=[];for(let n=i.length-1;n>=0;n--)t.push(i[n]);return t.push(e),U(t)}function Cs(i,e,t,n){if(!ys.test(i))return[{text:i,isWordLike:e,kind:"text",start:t}];const s=[];let r=null,o=[],a=t,d=!1,l=0;for(const h of i){const u=Fs(h,n),x=u==="text"&&e;if(r!==null&&u===r&&x===d){o.push(h),l+=h.length;continue}r!==null&&s.push({text:U(o),isWordLike:d,kind:r,start:a}),r=u,o=[h],a=t+l,d=x,l+=h.length}return r!==null&&s.push({text:U(o),isWordLike:d,kind:r,start:a}),s}function It(i){return i==="space"||i==="preserved-space"||i==="zero-width-break"||i==="hard-break"}const Ns=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function bs(i,e){const t=i.texts[e];return t.startsWith("www.")?!0:Ns.test(t)&&e+1<i.len&&i.kinds[e+1]==="text"&&i.texts[e+1]==="//"}function Ds(i){return i.includes("?")&&(i.includes("://")||i.startsWith("www."))}function Ms(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"||!bs(i,o))continue;const a=[e[o]];let d=o+1;for(;d<i.len&&!It(n[d]);){a.push(e[d]),t[o]=!0;const l=e[d].includes("?");if(n[d]="text",e[d]="",d++,l)break}e[o]=U(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 ws(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]),!Ds(o))continue;const a=r+1;if(a>=i.len||It(i.kinds[a]))continue;const d=[],l=i.starts[a];let h=a;for(;h<i.len&&!It(i.kinds[h]);)d.push(i.texts[h]),h++;d.length>0&&(e.push(U(d)),t.push(!0),n.push("text"),s.push(l),r=h-1)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}const vs=new Set([":","-","/","×",",",".","+","–","—"]),Ts=new Set([".",",",":",";"]);function ae(i){for(let e=i.length;e>0;){const t=yt(i,e),n=i.slice(t,e);if(K.test(n)){e=t;continue}return Ts.has(n)||At(n)}return!1}function Bs(i,e){return e&&!W(i)}function Ue(i){for(const e of i)if(jt.test(e))return!0;return!1}function St(i){if(i.length===0)return!1;for(const e of i)if(!(jt.test(e)||vs.has(e)))return!1;return!0}function ks(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"&&St(o)&&Ue(o)){const d=[o];let l=r+1;for(;l<i.len&&i.kinds[l]==="text"&&St(i.texts[l]);)d.push(i.texts[l]),l++;e.push(U(d)),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 Ls(i){const e=[],t=[],n=[],s=[];for(let r=0;r<i.len;r++){const o=i.texts[r],a=i.kinds[r],d=i.isWordLike[r];if(a==="text"&&ae(o)&&(d||fs(o))&&!W(o)){const l=[o];let h=!0,u=r+1;for(;h&&u<i.len&&i.kinds[u]==="text"&&Bs(i.texts[u],i.isWordLike[u]);){const x=i.texts[u];l.push(x),h=ae(x),u++}e.push(U(l)),t.push(!0),n.push("text"),s.push(i.starts[r]),r=u-1;continue}e.push(o),t.push(d),n.push(a),s.push(i.starts[r])}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Os(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 d=a.length>1;for(let l=0;l<a.length;l++){const h=a[l];if(!d)break;(h.length===0||!Ue(h)||!St(h))&&(d=!1)}if(d){let l=0;for(let h=0;h<a.length;h++){const u=a[h],x=h<a.length-1?`${u}-`:u;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 Ps(i){const e=[],t=[],n=[],s=[];let r=0;for(;r<i.len;){const o=[i.texts[r]];let a=i.isWordLike[r],d=i.kinds[r],l=i.starts[r];if(d==="glue"){const h=[o[0]],u=l;for(r++;r<i.len&&i.kinds[r]==="glue";)h.push(i.texts[r]),r++;const x=U(h);if(r<i.len&&i.kinds[r]==="text")o[0]=x,o.push(i.texts[r]),a=i.isWordLike[r],d="text",l=u,r++;else{e.push(x),t.push(!1),n.push("glue"),s.push(u);continue}}else r++;if(d==="text")for(;r<i.len&&i.kinds[r]==="glue";){const h=[];for(;r<i.len&&i.kinds[r]==="glue";)h.push(i.texts[r]),r++;const u=U(h);if(r<i.len&&i.kinds[r]==="text"){o.push(u,i.texts[r]),a=a||i.isWordLike[r],r++;continue}o.push(u)}e.push(U(o)),t.push(a),n.push(d),s.push(l)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function Rs(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"||!W(e[r])||!W(e[r+1]))continue;const o=ps(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 _s(i,e,t){const n=Zn();let s=0;const r=[],o=[],a=[],d=[],l=[],h=[],u=[],x=[],f=[],g=[],m=[],p=[];for(const E of n.segment(i))for(const N of Cs(E.segment,E.isWordLike??!1,E.index,t)){let k=function(){h[M]!==null&&(o[M]=[re(r,h,u,M)],h[M]=null),o[M].push(N.text),a[M]=a[M]||N.isWordLike,x[M]=x[M]||T,f[M]=f[M]||w,g[M]=O,m[M]=R,p[M]=oe(f[M],L)};const D=N.kind==="text",v=ms(N.text,N.isWordLike,N.kind),T=W(N.text),w=se(N.text),L=dt(N.text),O=_t(N.text),R=Ss(N.text),M=s-1;e.carryCJKAfterClosingQuote&&D&&s>0&&d[M]==="text"&&T&&x[M]&&g[M]||D&&s>0&&d[M]==="text"&&cs(N.text)&&x[M]||D&&s>0&&d[M]==="text"&&m[M]?k():D&&s>0&&d[M]==="text"&&N.isWordLike&&w&&p[M]?(k(),a[M]=!0):v!==null&&s>0&&d[M]==="text"&&h[M]===v?u[M]=(u[M]??1)+1:D&&!N.isWordLike&&s>0&&d[M]==="text"&&!x[M]&&(as(N.text)||N.text==="-"&&a[M])?k():(r[s]=N.text,o[s]=[N.text],a[s]=N.isWordLike,d[s]=N.kind,l[s]=N.start,h[s]=v,u[s]=v===null?0:1,x[s]=T,f[s]=w,g[s]=O,m[s]=R,p[s]=oe(w,L),s++)}for(let E=0;E<s;E++){if(h[E]!==null){r[E]=re(r,h,u,E);continue}r[E]=U(o[E])}for(let E=1;E<s;E++)d[E]==="text"&&!a[E]&&Zt(r[E])&&d[E-1]==="text"&&!x[E-1]&&(r[E-1]+=r[E],a[E-1]=a[E-1]||a[E],r[E]="");const A=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(d[E]==="text"&&!a[E]&&y>=0&&d[y]==="text"&&(ls(N)||N==="-"&&gs(r[y]))){const D=A[y]??[];D.push(N),A[y]=D,l[y]=l[E],r[E]="";continue}y=E}}for(let E=0;E<s;E++){const N=A[E];N!=null&&(r[E]=As(N,r[E]))}let F=0;for(let E=0;E<s;E++){const N=r[E];N.length!==0&&(F!==E&&(r[F]=N,a[F]=a[E],d[F]=d[E],l[F]=l[E]),F++)}r.length=F,a.length=F,d.length=F,l.length=F;const b=Ps({len:F,texts:r,isWordLike:a,kinds:d,starts:l}),C=Rs(Ls(Os(ks(ws(Ms(b))))));for(let E=0;E<C.len-1;E++){const N=Es(C.texts[E]);N!==null&&(C.kinds[E]!=="space"&&C.kinds[E]!=="preserved-space"||C.kinds[E+1]!=="text"||!se(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 Is(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 Hs(i,e,t){if(e.len<=1)return e;const n=[],s=[],r=[],o=[];let a=-1,d=!1;function l(x){n.push(e.texts[x]),s.push(e.isWordLike[x]),r.push("text"),o.push(e.starts[x])}function h(x,f){let g=!1;for(let A=x;A<f;A++)g=g||e.isWordLike[A];const m=e.starts[x],p=f<e.len?e.starts[f]:i.length;n.push(i.slice(m,p)),s.push(g),r.push("text"),o.push(m)}function u(x){if(!(a<0)){if(d)a+1===x?l(a):h(a,x);else for(let f=a;f<x;f++)l(f);a=-1,d=!1}}for(let x=0;x<e.len;x++){const f=e.texts[x],g=e.kinds[x];if(g==="text"){a>=0&&!Ge(e.texts[x-1],t)&&u(x),a<0&&(a=x),d=d||W(f);continue}u(x),n.push(f),s.push(e.isWordLike[x]),r.push(g),o.push(e.starts[x])}return u(e.len),{len:n.length,texts:n,isWordLike:s,kinds:r,starts:o}}function zs(i,e,t="normal",n="normal"){const s=Xn(t),r=s.mode==="pre-wrap"?Kn(i):jn(i);if(r.length===0)return{normalized:r,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};const o=_s(r,e,s),a=n==="keep-all"?Hs(r,o,e.breakKeepAllAfterPunctuation):o;return{normalized:r,chunks:Is(a,s),...a}}let Q=null;const ce=new Map;let tt=null;const Gs=96,Us=new RegExp("\\p{Emoji_Presentation}","u"),Ws=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;let Dt=null;const le=new Map;function Jt(){if(Q!==null)return Q;if(typeof OffscreenCanvas<"u")return Q=new OffscreenCanvas(1,1).getContext("2d"),Q;if(typeof document<"u")return Q=document.createElement("canvas").getContext("2d"),Q;throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function Ys(i){let e=ce.get(i);return e||(e=new Map,ce.set(i,e)),e}function $(i,e){let t=e.get(i);return t===void 0&&(t={width:Jt().measureText(i).width,containsCJK:W(i)},e.set(i,t)),t}function Ct(){if(tt!==null)return tt;if(typeof navigator>"u")return tt={lineFitEpsilon:.005,carryCJKAfterClosingQuote:!1,breakKeepAllAfterPunctuation:!0,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},tt;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 tt={lineFitEpsilon:t?1/64:.005,carryCJKAfterClosingQuote:n,breakKeepAllAfterPunctuation:!t,preferPrefixWidthsForBreakableRuns:t,preferEarlySoftHyphenBreak:t},tt}function $s(i){const e=i.match(/(\d+(?:\.\d+)?)\s*px/);return e?parseFloat(e[1]):16}function We(){return Dt===null&&(Dt=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Dt}function Vs(i){return Us.test(i)||i.includes("️")}function Xs(i){return Ws.test(i)}function js(i,e){let t=le.get(i);if(t!==void 0)return t;const n=Jt();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 le.set(i,t),t}function Ks(i){let e=0;const t=We();for(const n of t.segment(i))Vs(n.segment)&&e++;return e}function qs(i,e){return e.emojiCount===void 0&&(e.emojiCount=Ks(i)),e.emojiCount}function X(i,e,t){return t===0?e.width:e.width-qs(i,e)*t}function Zs(i,e,t,n,s){if(e.breakableFitAdvances!==void 0&&e.breakableFitMode===s)return e.breakableFitAdvances;e.breakableFitMode=s;const r=We(),o=[];for(const h of r.segment(i))o.push(h.segment);if(o.length<=1)return e.breakableFitAdvances=null,e.breakableFitAdvances;if(s==="sum-graphemes"){const h=[];for(const u of o){const x=$(u,t);h.push(X(u,x,n))}return e.breakableFitAdvances=h,e.breakableFitAdvances}if(s==="pair-context"||o.length>Gs){const h=[];let u=null,x=0;for(const f of o){const g=$(f,t),m=X(f,g,n);if(u===null)h.push(m);else{const p=u+f,A=$(p,t);h.push(X(p,A,n)-x)}u=f,x=m}return e.breakableFitAdvances=h,e.breakableFitAdvances}const a=[];let d="",l=0;for(const h of o){d+=h;const u=$(d,t),x=X(d,u,n);a.push(x-l),l=x}return e.breakableFitAdvances=a,e.breakableFitAdvances}function Js(i,e){const t=Jt();t.font=i;const n=Ys(i),s=$s(i),r=e?js(i,s):0;return{cache:n,fontSize:s,emojiCorrection:r}}function Qs(i){return i==="space"||i==="zero-width-break"||i==="soft-hyphen"}function Ye(i){return i==="space"||i==="preserved-space"||i==="tab"||i==="zero-width-break"||i==="soft-hyphen"}function $e(i,e,t=i.widths.length){for(;e<t;){const n=i.kinds[e];if(!Qs(n))break;e++}return e}function ti(i,e){if(e<=0)return 0;const t=i%e;return Math.abs(t)<=1e-6?e:e-t}function ei(i,e,t){return i.letterSpacing!==0&&e&&i.spacingGraphemeCounts[t]>0?i.letterSpacing:0}function Qt(i,e){return e===0?0:i+e}function ni(i,e){return i.letterSpacing!==0&&i.spacingGraphemeCounts[e]>0?i.letterSpacing:0}function si(i,e,t,n,s){const r=e==="tab"?s+ni(i,t):i.lineEndFitAdvances[t];return Qt(n,r)}function de(i,e,t,n){const s=e==="tab"?0:i.lineEndFitAdvances[t];return Qt(n,s)}function he(i,e,t,n,s){const r=e==="tab"?s:i.lineEndPaintAdvances[t];return Qt(n,r)}function ii(i,e,t){return i.letterSpacing!==0&&e?t+i.letterSpacing:t}function ri(i,e){return i.letterSpacing===0?e:e+i.letterSpacing}function oi(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 ai(i,e,t,n,s,r){return e+oi(i,t,n,s,r)}function ci(i,e,t){const{widths:n,kinds:s,breakableFitAdvances:r}=i;if(n.length===0)return 0;const a=Ct().lineFitEpsilon,d=e+a;let l=0,h=0,u=!1,x=0,f=0,g=0,m=0,p=-1,A=0;function y(){p=-1,A=0}function F(v=g,T=m,w=h){l++,t==null||t(w,x,f,v,T),h=0,u=!1,y()}function b(v,T){u=!0,x=v,f=0,g=v+1,m=0,h=T}function C(v,T,w){u=!0,x=v,f=T,g=v,m=T+1,h=w}function E(v,T){if(!u){b(v,T);return}h+=T,g=v+1,m=0}function N(v,T){const w=r[v];for(let L=T;L<w.length;L++){const O=w[L];u?h+O>d?(F(),C(v,L,O)):(h+=O,g=v,m=L+1):C(v,L,O)}u&&g===v&&m===w.length&&(g=v+1,m=0)}let D=0;for(;D<n.length&&!(!u&&(D=$e(i,D),D>=n.length));){const v=n[D],T=s[D],w=Ye(T);if(!u){v>d&&r[D]!==null?N(D,0):b(D,v),w&&(p=D+1,A=h-v),D++;continue}if(h+v>d){if(w){E(D,v),F(D+1,0,h-v),D++;continue}if(p>=0){if(g>p||g===p&&m>0){F();continue}F(p,0,A);continue}if(v>d&&r[D]!==null){F(),N(D,0),D++;continue}F();continue}E(D,v),w&&(p=D+1,A=h-v),D++}return u&&F(),l}function li(i,e,t){if(i.simpleLineWalkFastPath)return ci(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 d=Ct(),l=d.lineFitEpsilon,h=e+l;let u=0,x=0,f=!1,g=0,m=0,p=0,A=0,y=-1,F=0,b=0,C=null;function E(){y=-1,F=0,b=0,C=null}function N(){return C==="soft-hyphen"&&y===p&&A===0?b:x}function D(M=p,k=A,B){u++,t!==void 0&&t(ai(i,B??N(),g,m,M,k),g,m,M,k),x=0,f=!1,E()}function v(M,k){f=!0,g=M,m=0,p=M+1,A=0,x=k}function T(M,k,B){f=!0,g=M,m=k,p=M,A=k+1,x=B}function w(M,k){if(!f){v(M,k);return}x+=k,p=M+1,A=0}function L(M,k,B,P,I,H){if(!k)return;const _=de(i,M,B,I),G=he(i,M,B,I,P);y=B+1,F=x-H+_,b=x-H+G,C=M}function O(M,k){const B=r[M];for(let P=k;P<B.length;P++){const I=B[P];if(!f)T(M,P,I);else{const H=ii(i,!0,I),_=x+H;ri(i,_)>h?(D(),T(M,P,I)):(x=_,p=M,A=P+1)}}f&&p===M&&A===B.length&&(p=M+1,A=0)}function R(M){u++,t==null||t(0,M.startSegmentIndex,0,M.consumedEndSegmentIndex,0),E()}for(let M=0;M<a.length;M++){const k=a[M];if(k.startSegmentIndex===k.endSegmentIndex){R(k);continue}f=!1,x=0,g=k.startSegmentIndex,m=0,p=k.startSegmentIndex,A=0,E();let B=k.startSegmentIndex;for(;B<k.endSegmentIndex&&!(!f&&(B=$e(i,B,k.endSegmentIndex),B>=k.endSegmentIndex));){const P=s[B],I=Ye(P),H=ei(i,f,B),_=P==="tab"?ti(x+H,i.tabStopAdvance):n[B],G=H+_,V=si(i,P,B,H,_);if(P==="soft-hyphen"){f&&(p=B+1,A=0,y=B+1,F=x+o,b=x+o,C=P),B++;continue}if(!f){V>h&&r[B]!==null?O(B,0):v(B,_),L(P,I,B,_,H,G),B++;continue}if(x+V>h){const q=x+de(i,P,B,H),Z=x+he(i,P,B,H,_);if(C==="soft-hyphen"&&d.preferEarlySoftHyphenBreak&&F<=h){D(y,0,b);continue}if(I&&q<=h){w(B,G),D(B+1,0,Z),B++;continue}if(y>=0&&F<=h){if(p>y||p===y&&A>0){D();continue}const z=y;D(z,0,b),B=z;continue}if(V>h&&r[B]!==null){D(),O(B,0),B++;continue}D();continue}w(B,G),L(P,I,B,_,H,G),B++}if(f){const P=y===k.consumedEndSegmentIndex?b:x;D(k.consumedEndSegmentIndex,0,P)}}return u}let Mt=null,ue=new WeakMap;function di(){return Mt===null&&(Mt=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Mt}function xe(i,e,t){let n=t.get(i);if(n!==void 0)return n;n=[];const s=di();for(const r of s.segment(e[i]))n.push(r.segment);return t.set(i,n),n}function hi(i,e,t){return t>e&&i[t-1]==="soft-hyphen"}function fe(i,e,t,n){for(let s=t;s<n;s++)i+=e[s];return i}function ui(i){let e=ue.get(i);return e!==void 0||(e=new Map,ue.set(i,e)),e}function xi(i,e,t,n,s,r){let o="";const a=hi(i.kinds,t,s);for(let d=t;d<s;d++)if(!(i.kinds[d]==="soft-hyphen"||i.kinds[d]==="hard-break"))if(d===t&&n>0){const l=xe(d,i.segments,e);o=fe(o,l,n,l.length)}else o+=i.segments[d];if(r>0){a&&(o+="-");const d=xe(s,i.segments,e);o=fe(o,d,t===s?n:0,r)}else a&&(o+="-");return o}let wt=null;function Ve(){return wt===null&&(wt=new Intl.Segmenter(void 0,{granularity:"grapheme"})),wt}function fi(i){return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]}}function gi(i,e){const t=[];let n=[],s=0,r=!1,o=!1,a=!1;function d(){n.length!==0&&(t.push({text:n.length===1?n[0]:n.join(""),start:s}),n=[],r=!1,o=!1,a=!1)}function l(u,x,f){n=[u],s=x,r=f,o=_t(u),a=Ft.has(u)}function h(u,x){n.push(u),r=r||x;const f=_t(u);u.length===1&&j.has(u)?o=o||f:o=f,a=!1}for(const u of Ve().segment(i)){const x=u.segment,f=W(x);if(n.length===0){l(x,u.index,f);continue}if(a||Kt.has(x)||j.has(x)||e.carryCJKAfterClosingQuote&&f&&o){h(x,f);continue}if(!r&&!f){h(x,f);continue}d(),l(x,u.index,f)}return d(),t}function pi(i,e,t){if(e.length<=1)return e;const n=[];let s=-1,r=!1;function o(d,l){const h=e[d].start,u=l<e.length?e[l].start:i.length;n.push({text:i.slice(h,u),start:h})}function a(d){if(!(s<0)){if(r)s+1===d?n.push(e[s]):o(s,d);else for(let l=s;l<d;l++)n.push(e[l]);s=-1,r=!1}}for(let d=0;d<e.length;d++){const l=e[d];s>=0&&!Ge(e[d-1].text,t)&&a(d),s<0&&(s=d),r=r||W(l.text)}return a(e.length),n}function ge(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=Ve();for(const s of n.segment(i))t++;return t}function mi(i,e,t){return e>1?i+(e-1)*t:i}function Si(i,e,t,n,s){const r=Ct(),{cache:o,emojiCorrection:a}=Js(e,Xs(i.normalized)),d=X("-",$("-",o),a)+(s===0?0:s*2),h=X(" ",$(" ",o),a)*8,u=s!==0;if(i.len===0)return fi();const x=[],f=[],g=[],m=[];let p=i.chunks.length<=1&&!u;const A=t?[]:null,y=[],F=[],b=t?[]:null,C=Array.from({length:i.len});function E(T,w,L,O,R,M,k,B){R!=="text"&&R!=="space"&&R!=="zero-width-break"&&(p=!1),x.push(w),f.push(L),g.push(O),m.push(R),A==null||A.push(M),y.push(k),u&&F.push(B),b!==null&&b.push(T)}function N(T,w,L,O,R){const M=$(T,o),k=u?ge(T,w):0,B=mi(X(T,M,a),k,s),P=w==="space"||w==="preserved-space"||w==="zero-width-break"?0:B,I=P===0?0:P+(k>0?s:0),H=w==="space"||w==="zero-width-break"?0:B;if(R&&O&&T.length>1){let _="sum-graphemes";s!==0?_="segment-prefixes":St(T)?_="pair-context":r.preferPrefixWidthsForBreakableRuns&&(_="segment-prefixes");const G=Zs(T,M,o,a,_);E(T,B,I,H,w,L,G,k);return}E(T,B,I,H,w,L,null,k)}for(let T=0;T<i.len;T++){C[T]=x.length;const w=i.texts[T],L=i.isWordLike[T],O=i.kinds[T],R=i.starts[T];if(O==="soft-hyphen"){E(w,0,d,d,O,R,null,0);continue}if(O==="hard-break"){E(w,0,0,0,O,R,null,0);continue}if(O==="tab"){E(w,0,0,0,O,R,null,u?ge(w,O):0);continue}const M=$(w,o);if(O==="text"&&M.containsCJK){const k=gi(w,r),B=n==="keep-all"?pi(w,k,r.breakKeepAllAfterPunctuation):k;for(let P=0;P<B.length;P++){const I=B[P];N(I.text,"text",R+I.start,L,n==="keep-all"||!W(I.text))}continue}N(w,O,R,L,!0)}const D=Ei(i.chunks,C,x.length),v=A===null?null:Yn(i.normalized,A);return b!==null?{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:m,simpleLineWalkFastPath:p,segLevels:v,breakableFitAdvances:y,letterSpacing:s,spacingGraphemeCounts:F,discretionaryHyphenWidth:d,tabStopAdvance:h,chunks:D,segments:b}:{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:m,simpleLineWalkFastPath:p,segLevels:v,breakableFitAdvances:y,letterSpacing:s,spacingGraphemeCounts:F,discretionaryHyphenWidth:d,tabStopAdvance:h,chunks:D}}function Ei(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,d=r.consumedEndSegmentIndex<e.length?e[r.consumedEndSegmentIndex]:t;n.push({startSegmentIndex:o,endSegmentIndex:a,consumedEndSegmentIndex:d})}return n}function Fi(i,e,t,n){const s=(n==null?void 0:n.wordBreak)??"normal",r=(n==null?void 0:n.letterSpacing)??0,o=zs(i,Ct(),n==null?void 0:n.whiteSpace,s);return Si(o,e,t,s,r)}function Xe(i,e,t){return Fi(i,e,!0,t)}function yi(i,e,t,n,s,r,o){return{text:xi(i,e,n,s,r,o),width:t,start:{segmentIndex:n,graphemeIndex:s},end:{segmentIndex:r,graphemeIndex:o}}}function je(i,e,t){const n=[];if(i.widths.length===0)return{lineCount:0,height:0,lines:n};const s=ui(i),r=li(i,e,(o,a,d,l,h)=>{n.push(yi(i,s,o,a,d,l,h))});return{lineCount:r,height:r*t,lines:n}}function Ai(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=Ai(t,s,e.properties.type),{strokeColor:d,strokeWidth:l,strokeType:h,background:u,borderRadius:x,boxShadow:f}=e.properties.style||c.defaultBoxStyle;a.classList.add("annotation-box"),a.setAttribute("fill",`${u||"transparent"}`);const g=a.firstChild;x&&(g.setAttribute("rx",`${x}`),g.setAttribute("ry",`${x}`)),h&&h!=="none"&&(g.setAttribute("stroke",d||"black"),g.setAttribute("stroke-width",`${l}`),h==="dashed"&&g.setAttribute("stroke-dasharray","5,5")),u&&u.length&&(n.hoveredFeature===e.id?g.setAttribute("fill",c.brighten(u)):g.setAttribute("fill",u));const m=c.getBoxPosition(e);return g.setAttribute("width",`${o.width}`),g.setAttribute("height",`${o.height}`),g.setAttribute("x",`${m.x}`),g.setAttribute("y",`${m.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}const Ci=Nn(),pe=Pe();function Ni(i,e,t,n,s=!1){const{width:r,height:o}=c.getBoxSize(e),{color:a=c.defaultTextStyle.color,strokeColor:d=c.defaultTextStyle.strokeColor,strokeWidth:l=c.defaultTextStyle.strokeWidth,strokeType:h=c.defaultTextStyle.strokeType,background:u=c.defaultTextStyle.background,borderRadius:x=c.defaultTextStyle.borderRadius,fixedSize:f=c.defaultTextStyle.fixedSize}=e.properties.style||c.defaultTextStyle,g=Ke(i,e,t,n);g.setAttribute("data-annotation-type",e.properties.type),g.classList.add("annotation-text"),g.setAttribute("fill",`${a}`);let m=g.firstChild;for(;m;){const b=m.nextSibling;m.nodeType===1&&m.tagName!=="rect"&&g.removeChild(m),m=b}let p=g.firstChild;p||(p=c.createSVGElement("rect"),g.appendChild(p));const A=-r/2,y=-o/2;x&&(p.setAttribute("rx",`${x}`),p.setAttribute("ry",`${x}`)),h&&h!=="none"&&(p.setAttribute("stroke",d||"black"),p.setAttribute("stroke-width",`${l}`),h==="dashed"&&p.setAttribute("stroke-dasharray","5,5")),u&&u.length&&(n.hoveredFeature===e.id?p.setAttribute("fill",c.brighten(u)):p.setAttribute("fill",u)),p.setAttribute("width",`${r}`),p.setAttribute("height",`${o}`);const F=c.getBoxCenter(e);return p.setAttribute("x",`${A}`),p.setAttribute("y",`${y}`),wi(e,g,A,y,n,s),g.setAttribute("transform",n.getScreenAlignedTransform(F.x,F.y,!f)),i.appendChild(g),g}let st=null;const me=new Map;function Se(i,e){const t=`${i}|${e}`,n=me.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 me.set(t,o),o}catch{}try{if(st||(st=document.createElement("canvas").getContext("2d")),st){st.font=i;const s=st.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}const ft={font:"sans-serif",fontSize:12,color:"#8a8a8a",fontWeight:"normal"};function qe(i,e){return{font:(i==null?void 0:i.font)??(e==null?void 0:e.font)??ft.font,fontSize:(i==null?void 0:i.fontSize)??(e==null?void 0:e.fontSize)??ft.fontSize,color:(i==null?void 0:i.color)??(e==null?void 0:e.color)??ft.color,fontWeight:(i==null?void 0:i.fontWeight)??(e==null?void 0:e.fontWeight)??ft.fontWeight}}const bi=4;function Di(i,e,t=!1){var x,f,g,m,p;const n=(x=i.properties.author)==null?void 0:x.trim();if(((f=i.properties.style)==null?void 0:f.showAuthor)!==!0||!n)return 0;const{fixedSize:s=c.defaultTextStyle.fixedSize,padding:r=0}=i.properties.style||{},o=qe((g=i.properties.style)==null?void 0:g.authorStyle,(m=e==null?void 0:e.options)==null?void 0:m.authorStyle),a=c.getEffectiveFontSize(o.fontSize,void 0),d=s?1:(e==null?void 0:e.zoom)??1,l=((p=e==null?void 0:e.options)==null?void 0:p.minReadableFontSize)??0;return!t&&l>0&&a*d<l?0:r+a*c.TEXT_LINE_HEIGHT}function Ee(i){const e=[],t=Ci;t.lastIndex=0;let n=0,s="",r;for(;(r=t.exec(i))!==null;){s+=i.slice(n,r.index);const[,o,a]=r,d=o.replace(/\s+/g," ");e.push({token:d,href:a}),s+=d,n=r.index+r[0].length}return s+=i.slice(n),{measureText:s,links:e}}function Fe(i){if(i.length===0)return{pattern:pe,hrefByToken:null};const e=new Map(i.map(n=>[n.token,n.href])),t=i.map(n=>bn(n.token));return t.push(pe.source),{pattern:new RegExp(t.join("|"),"g"),hrefByToken:e}}function ye(i,e,t){const{pattern:n,hrefByToken:s}=t;n.lastIndex=0;let r=0,o;for(;(o=n.exec(e))!==null;){o.index>r&&i.appendChild(document.createTextNode(e.slice(r,o.index)));const a=s==null?void 0:s.get(o[0]),d=a??o[0],l=a!==void 0?o[0].replace(/ /g," "):o[0],h=document.createElementNS("http://www.w3.org/2000/svg","a");h.setAttribute("href",d),h.setAttribute("target","_blank"),h.setAttribute("rel","noopener noreferrer"),h.setAttribute("class",Vt),h.textContent=l,i.appendChild(h),r=o.index+o[0].length}r<e.length&&i.appendChild(document.createTextNode(e.slice(r)))}function Mi(i,e,t){const n=Xe(i,e,{whiteSpace:"pre-wrap",wordBreak:"normal"}),{lines:s}=je(n,t,1e6);return s.length===0?"":s.length===1?s[0].text:s[0].text.trimEnd()+"…"}function wi(i,e,t=0,n=0,s,r=!1){var k,B,P,I,H;const{width:o,height:a}=c.getBoxSize(i),{fontSize:d=c.defaultTextStyle.fontSize,font:l=c.defaultTextStyle.font,padding:h=0,fontScale:u,fontWeight:x,fixedSize:f=c.defaultTextStyle.fixedSize}=i.properties.style||{};if(o===a&&o===0)return;const g=c.getEffectiveFontSize(d,u),m=g*c.TEXT_LINE_HEIGHT,p=`${x==="bold"?"bold ":""}${g}px ${l}`.replace(/(px)+/g,"px"),A=o-h*2,y=f?1:(s==null?void 0:s.zoom)??1,F=((k=s==null?void 0:s.options)==null?void 0:k.minReadableFontSize)??0,b=!r&&F>0,C=b&&g*y<F,E=(B=i.properties.author)==null?void 0:B.trim(),N=((P=i.properties.style)==null?void 0:P.showAuthor)===!0&&!!E,D=N?qe((I=i.properties.style)==null?void 0:I.authorStyle,(H=s==null?void 0:s.options)==null?void 0:H.authorStyle):null,v=D?c.getEffectiveFontSize(D.fontSize,void 0):0,T=b&&v*y<F,w=N&&!T,L=w?v*c.TEXT_LINE_HEIGHT:0,O=w?L+bi:0,R=a-h-O,M=i.properties.content||"";if(M.length>0&&!C){const{measureText:_,links:G}=Ee(M),V=Fe(G),ht=Xe(_,p,{whiteSpace:"pre-wrap",wordBreak:"normal"}),{lines:q}=je(ht,A,m),Z=Math.max(1,Math.floor(R/m)),z=q.slice(0,Z);if(q.length>Z&&z.length>0){const ut=z[z.length-1];z[z.length-1]={...ut,text:ut.text.trimEnd()+"…"}}const Y=c.createSVGElement("text");Y.setAttribute("font-size",`${g}`),Y.setAttribute("font-family",`${l}`),x==="bold"&&Y.setAttribute("font-weight","bold"),Y.setAttribute("transform",`translate(${t+h}, ${n+h})`);const J=Se(p,m);z.forEach((ut,sn)=>{const xt=c.createSVGElement("tspan");xt.setAttribute("x","0"),xt.setAttribute("y",`${J+sn*m}`),ye(xt,ut.text,V),Y.appendChild(xt)}),e.appendChild(Y)}if(w&&D){const _=`${D.fontWeight==="bold"?"bold ":""}${v}px ${D.font}`.replace(/(px)+/g,"px"),G=o-h*2,{measureText:V,links:ht}=Ee(E),q=Fe(ht),Z=Mi(V,_,G),z=c.createSVGElement("text");z.setAttribute("font-size",`${v}`),z.setAttribute("font-family",D.font),z.setAttribute("fill",D.color),D.fontWeight==="bold"&&z.setAttribute("font-weight","bold"),z.classList.add("annotation-text-author");const Y=n+a-h-L;z.setAttribute("transform",`translate(${t+h}, ${Y})`);const J=c.createSVGElement("tspan");J.setAttribute("x","0"),J.setAttribute("dy",`${Se(_,L)}`),ye(J,Z,q),z.appendChild(J),e.appendChild(z)}}const vi=24,Ti=4,Bi=16,ki=50;class Li{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.metaKey||e.ctrlKey)&&e.key==="Enter"&&this.sendButton&&!this.sendButton.disabled&&(e.preventDefault(),this.send()),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.send()});S(this,"update",()=>{this.getAnnotation()&&(this.updateStyle(),this.updatePosition(),this.layer.setSize(this.getSize()))});var m,p,A,y,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)&&(((m=o.options)==null?void 0:m.showSendButton)??!0),d=((p=o.options)==null?void 0:p.sendButtonIcon)||"",h=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent)?"⌘Enter":"Ctrl+Enter",u=((A=r.properties.style)==null?void 0:A.placeholder)||((y=o.options)==null?void 0:y.textPlaceholder)||"Enter text",x=c.isComment(r)?c.defaultCommentStyle:c.defaultTextStyle;this.fixedSize=((F=r.properties.style)==null?void 0:F.fixedSize)??x.fixedSize??!1;const f=this.getPosition(),g=this.getSize();this.layer=this.ogma.layers.addOverlay({element:`<div class="ogma-annotation-text-editor">
5
+ <textarea wrap="on" name="annotation-text--input" spellcheck="false" placeholder="${u}"></textarea>
6
+ ${a?`<button class="ogma-send-button" type="button" title="Send (${h})">
7
+ <span class="ogma-send-button-icon">${d}</span>
5
8
  </button>`:""}
6
- </div>`,position:h,size:x,scaled:!this.fixedSize},l.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(E=>({rotation:E.rotation,zoom:E.zoom,annotation:E.features[this.annotation]}),this.update,{equalityFn:(E,y)=>E.rotation===y.rotation&&E.zoom===y.zoom&&E.annotation===y.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=Ut(e),[o,a]=e.geometry.coordinates,u=e.properties.width;let d=e.properties.height;n&&(d=Math.min(d,n));const c=this.fixedSize?1/s:1;return{x:o-u*c/2+r*c,y:a-d*c/2+r*c}}getSize(){const e=this.getAnnotation();if(!e)return{width:0,height:0};const t=l.getBoxSize(e),n=Ut(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 A;const e=this.getAnnotation();if(!e)return;const t=l.isComment(e)?l.defaultCommentStyle:l.defaultTextStyle,{font:n,fontSize:s=t.fontSize,borderRadius:r,color:o,background:a=t.background,padding:u=0,fixedSize:d=t.fixedSize}=e.properties.style||t,c=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 E=e.properties.style,y=(E==null?void 0:E.shadow)!==!1;p.boxShadow=y?"0 2px 8px rgba(0, 0, 0, 0.15)":"none"}const m=c.style;if(m.fontFamily=n||"sans-serif",m.fontSize=`${f}px`,m.lineHeight=`${f*l.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 E=24*x,y=4*x;this.sendButton.style.width=`${E}px`,this.sendButton.style.height=`${E}px`,this.sendButton.style.padding=`${y}px`,this.sendButton.style.transform="";const D=this.sendButton.querySelector(".ogma-send-button-icon");if(D){const C=16*x;D.style.width=`${C}px`,D.style.height=`${C}px`}}if(d){const E=(A=e.properties.style)==null?void 0:A.maxHeight,y=E&&e.properties.height>=E;m.overflowY=y?"auto":"hidden",m.overflowX="hidden"}}updatePosition(){this.layer.setPosition(this.getPosition())}updateContent(){var o,a,u,d;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 c=this.textarea.style.height;this.textarea.style.height="0px";const h=this.textarea.scrollHeight;this.textarea.style.height=c;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)||50;t=Math.max(p,g);const m=(d=e.properties.style)==null?void 0:d.maxHeight,A=e.properties.height,E=t-A;if(!l.isComment(e)&&Math.abs(E)>1){const[D,C]=e.geometry.coordinates;if(m&&t>m){const F=m-A;t=m,Math.abs(F)>1&&(n=[D,C+F/2])}else n=[D,C+E/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 Ut(i){var e;return((e=i.properties.style)==null?void 0:e.strokeWidth)||0}const Xt={x:1,y:0},Vt={x:0,y:1},xn=[["top",Vt,-.5,-.5,.5,-.5],["right",Xt,.5,-.5,.5,.5],["bottom",Vt,-.5,.5,.5,.5],["left",Xt,-.5,-.5,-.5,.5]],fn={top:[0,1],right:[1,2],bottom:[2,3],left:[3,0]},jt=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]],gn=[l.cursors.nwResize,l.cursors.neResize,l.cursors.seResize,l.cursors.swResize],pn=100,mn=50;class pt extends lt{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(at(t.target??null))return;const n=this.getAnnotation();if(n){if(l.isComment(n)&&n.properties.mode===l.COMMENT_MODE_COLLAPSED){this.store.getState().updateFeature(n.id,{properties:{...n.properties,mode:l.COMMENT_MODE_EXPANDED}}),this.ogma.view.afterNextFrame(),this.justActivated=!1;return}if(this.store.getState().selectedFeatures.has(n.id)){if(l.isComment(n)&&this.justActivated){this.justActivated=!1;return}n&&(l.isText(n)||l.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}=l.getBoxSize(s);const d=5/n,c=l.getBoxCenter(s),h=this.store.getState();let{revSin:x,revCos:f}=h;(l.isBox(s)||l.isComment(s))&&(x=0,f=1),this.hoveredHandle=void 0;const g=l.handleRadius*(1/n),p=r-c.x,m=o-c.y,A=p*f-m*x,E=p*x+m*f,y=((D=s.properties.style)==null?void 0:D.fixedSize)===!0||l.isComment(s);if(y&&(a/=n,u/=n),!y){for(let C=0;C<jt.length;C++){const[F,N]=jt[C],M=a*F,T=u*N;if(A>=M-g-d&&A<=M+g+d&&E>=T-g-d&&E<=T+g+d){this.hoveredHandle={type:"corner",corner:C},this.store.setState({hoveredHandle:C,hoveredFeature:this.annotation}),this.setCursor(this.getCornerCursor(C));return}}for(const[C,F,N,M,T,b]of xn){const B=a*N,L=u*M,P=a*T,R=u*b,w=l.dot(F,{x:A-B,y:E-L});if(Math.abs(w)<d&&A>=B-d&&A<=P+d&&E>=L-d&&E<=R+d){this.hoveredHandle={type:"edge",edge:C,corner:-1},this.store.setState({hoveredHandle:fn[C][0]+4,hoveredFeature:this.annotation}),this.setCursor(this.getEdgeCursor(C));return}}}if(A>=-a/2-d&&A<=a/2+d&&E>=-u/2-d&&E<=u/2+d){this.store.setState({hoveredHandle:8,hoveredFeature:this.annotation}),this.hoveredHandle={type:"body",corner:-1},this.setCursor(l.cursors.grab);return}this.store.setState({hoveredHandle:-1,hoveredFeature:null}),this.setCursor(l.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"&&(Ot(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(l.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:d,height:c}=l.getBoxSize(t),h=this.store.getState();let{revSin:x,revCos:f}=h;(l.isBox(t)||l.isComment(t))&&(x=0,f=1);const g=n.x*f-n.y*x,p=n.x*x+n.y*f;let m=0,A=0;o?m=-g:a&&(m=g),r?A=-p:u&&(A=p);const E=Math.max(0,d+m),y=Math.max(0,c+A),D=l.getBoxCenter(t),C=D.x+n.x/2,F=D.y+n.y/2;return{...t,properties:{...t.properties,width:E,height:y},geometry:{type:t.geometry.type,coordinates:[C,F]}}}dragEdge(t,n,s){const{width:r,height:o}=l.getBoxSize(t),a=l.getBoxCenter(t),u=this.store.getState();let{revSin:d,revCos:c}=u;(l.isBox(t)||l.isComment(t))&&(d=0,c=1);const h=n.x*c-n.y*d,x=n.x*d+n.y*c;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 A=p*c+m*d,E=-p*d+m*c;return{...t,properties:{...t.properties,width:f,height:g},geometry:{type:t.geometry.type,coordinates:[a.x+A,a.y+E]}}}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||!(l.isBox(n)||l.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)??pn,r=(t==null?void 0:t.height)??mn,[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 hn(this.ogma,this.store,this.annotation,this.stopEditingText))}onDragEnd(t){var u,d;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-(((d=this.dragStartPoint)==null?void 0:d.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 c=this.getAnnotation();a&&c&&(l.isText(c)||l.isComment(c))&&this.startEditingText()}return this.hoveredHandle=void 0,this.dragStartPoint=void 0,this.dragging=!1,!0}getCornerCursor(t){return gn[t]}getEdgeCursor(t){switch(t){case"top":case"bottom":return l.cursors.nsResize;case"left":case"right":return l.cursors.ewResize;default:return l.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&&l.isComment(t)&&(this.justActivated=!0),super.setAnnotation(t),t&&l.isComment(t)&&t.properties.mode===l.COMMENT_MODE_COLLAPSED&&this.store.getState().updateFeature(t.id,{properties:{...t.properties,mode:l.COMMENT_MODE_EXPANDED}})}}class Sn 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 pt(this.ogma,this.store,r)),this.handlers.set("text",new pt(this.ogma,this.store,r)),this.handlers.set("comment",new pt(this.ogma,this.store,r)),this.handlers.set("arrow",new dn(this.ogma,this.store,this.snapping,r)),this.handlers.set("polygon",new un(this.ogma,this.store,r)),this.handlers.forEach(a=>{a.addEventListener("dragstart",(u=>{this.dispatchEvent(new CustomEvent(l.EVT_DRAG_START,{detail:{...u.detail}})),this.store.setState({isDragging:!0}),this.interaction.setMode("edit")})),a.addEventListener("dragend",(u=>{this.dispatchEvent(new CustomEvent(l.EVT_DRAG_END,{detail:{...u.detail}})),this.store.setState({isDragging:!1}),this.interaction.suppressClicksTemporarily()}))}),this.store.subscribe(a=>a.selectedFeatures,(a,u)=>{const d=Array.from(a.keys()).filter(h=>!u.has(h)),c=Array.from(u.keys()).filter(h=>!a.has(h));!d.length&&!c.length||(c.forEach(h=>this.stopEditingFeature(h)),d.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(){}}const En=["x","y","radius"],Fn=1;function An(i,e){return e===l.TARGET_TYPES.NODE?{type:"node",center:i.x===0&&i.y===0}:e===l.TARGET_TYPES.EDGE?{type:"edge",t:i.x}:e===l.TARGET_TYPES.POLYGON?{type:"polygon",rx:i.x,ry:i.y}:{type:"box",nx:i.x,ny:i.y}}class yn{constructor(e,t,n,s){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,"store");S(this,"ogma");S(this,"snapping");S(this,"updatedItems",new Set);S(this,"onLinkCreated");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.annotationToLink.forEach((n,s)=>{var a;const r=e.getFeature(s);if(!r)return;(l.isText(r)&&((a=r.properties.style)==null?void 0:a.fixedSize)||l.isComment(r))&&n.forEach(u=>{const d=this.links.get(u);if(!d)return;const c=d.arrow;t.set(c,this.linksByArrowId.get(c))})}),t.size>0&&this.update(t)});S(this,"throttledRefresh",l.throttle(()=>this.refresh(),20));S(this,"onAddRemoveEdges",e=>{const t=e.edges;if(!t.size||!this.edgeToLink.size)return;const n=new Map,s=new Map;t.getParallelEdges().getId().forEach(r=>{const o=this.edgeToLink.get(r);o&&o.forEach(a=>{const u=this.links.get(a);if(!u)return;const d=u.arrow;n.set(d,this.linksByArrowId.get(d)),s.set(d,this.linksByArrowId.get(d))})}),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)});S(this,"onAddArrow",(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 d=n.getFeature(u);if(!d||!l.isArrow(d))return;const c=d;if((h=c.properties.link)!=null&&h.start){const f=c.properties.link.start;this.add(c,l.SIDE_START,f.id,f.type,f.magnet)}if((x=c.properties.link)!=null&&x.end){const f=c.properties.link.end;this.add(c,l.SIDE_END,f.id,f.type,f.magnet)}}),o.forEach(u=>{const d=t[u];if(l.isArrow(d)){const c=d;this.remove(c,l.SIDE_START),this.remove(c,l.SIDE_END)}else{const c=this.annotationToLink.get(u);if(!c)return;for(const h of c){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 d=e[u];if(!d||!this.annotationToLink.has(u))continue;const c=t[u],h=c.geometry.coordinates!==d.geometry.coordinates,x=c.properties.width!==d.properties.width||c.properties.height!==d.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))}}a.size>0&&this._updateAndCommitSync(a)});this.ogma=e,this.store=n,this.snapping=t,this.onLinkCreated=s,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 s=this.store.getState();if(!s.getFeature(e))return;const o=this.annotationToLink.get(e);if(o)for(const a of o){const u=this.links.get(a);if(!u)continue;const d=s.getFeature(u.arrow),c=l.getArrowSide(d,u.side),h=l.add(c,t),x={...d.geometry,coordinates:d.geometry.coordinates.map((f,g)=>u.side===l.SIDE_START&&g===0||u.side===l.SIDE_END&&g===1?[h.x,h.y]:[...f])};n?n[d.id]={geometry:x}:s.applyLiveUpdate(d.id,{geometry:x}),this.updatedItems.add(d.id)}}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.annotationToLink.get(e);if(o)for(const a of o){const u=this.links.get(a);if(!u)continue;let d=n.getFeature(u.arrow);const c=n.liveUpdates[d.id];d=c?{...d,...c}:d;const h=d.geometry.coordinates[u.side===l.SIDE_START?0:1],x={x:h[0],y:h[1]};let f;if(l.isText(s)||l.isComment(s)||l.isBox(s)?f=this.snapping.snapToText(x,[s]):l.isPolygon(s)&&(f=this.snapping.snapToPolygon(x,[s])),!f)continue;const g=f.point,p={...d.geometry,coordinates:d.geometry.coordinates.map((m,A)=>u.side===l.SIDE_START&&A===0||u.side===l.SIDE_END&&A===1?[g.x,g.y]:[...m])};t?t[d.id]={geometry:p}:n.applyLiveUpdate(d.id,{geometry:p})}}add(e,t,n,s,r){const o=l.nanoid(),a=e.id;let u=r;if(s===l.TARGET_TYPES.POLYGON){const x=this.store.getState().getFeature(n);if(x&&l.isPolygon(x)){const f=Dt(x),g=f[2]-f[0],p=f[3]-f[1],m=r.x-f[0],A=r.y-f[1],E=g>0?m/g:.5,y=p>0?A/p:.5;u={x:E,y}}}const d={id:o,arrow:a,target:n,targetType:s,magnet:An(u,s),side:t};if(s===l.TARGET_TYPES.NODE&&!this.ogma.getNode(n)||s===l.TARGET_TYPES.EDGE&&!this.ogma.getEdge(n))return;this.remove(e,t),this.links.set(o,d);const c=s===l.TARGET_TYPES.NODE?this.nodeToLink:s===l.TARGET_TYPES.EDGE?this.edgeToLink:this.annotationToLink;return c.has(n)||c.set(n,new Set),c.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:s,magnet:u},this.onLinkCreated&&this.onLinkCreated(e,d),this}remove(e,t){var o,a,u,d,c;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),(d=this.edgeToLink.get(r.target))==null||d.delete(s),(c=this.annotationToLink.get(r.target))==null||c.delete(s),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(d=>{const c=this.nodeToLink.get(d);c&&c.forEach(h=>{const x=this.links.get(h);if(!x)return;const f=x.arrow;n.set(f,this.linksByArrowId.get(f))})});const s=new Map;e.getAdjacentEdges().getId().forEach(d=>{const c=this.edgeToLink.get(d);c&&c.forEach(h=>{const x=this.links.get(h);if(!x)return;const f=x.arrow;n.set(f,this.linksByArrowId.get(f)),s.set(f,this.linksByArrowId.get(f))})});const o=e.getAttributes(En),a=this.store.getState(),u={};for(let d=0;d<t.length;d++){const c=t[d],h=this.nodeToLink.get(c);if(h)for(const x of h){const f=this.links.get(x);if(!f)continue;const g=f.arrow,p=this.store.getState().getFeature(g),m=p.geometry.coordinates.slice(),A=l.getArrowSide(p,l.SIDE_END),E=l.getArrowSide(p,l.SIDE_START),y=f.side===l.SIDE_START?0:1,D=o[d],C=this._getNodeSnapPoint(D,l.mul(l.subtract(A,E),-1),this._isLinkedToCenter(f)),F=this._getRigidFollowComment(g,f);if(F){const N=m[y],M=l.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];const[T,b]=F.geometry.coordinates,B={...F,geometry:{type:"Point",coordinates:[T+M.x,b+M.y]}};u[F.id]=B,l.updateBbox(B),this.updatedItems.add(F.id)}else m[y]=C;u[g]={...p,geometry:{coordinates:m}},this.updatedItems.add(g),l.updateBbox(u[g])}}if(a.applyLiveUpdates(u),s.size>0){this.update(s);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()),s=new Map;n.forEach((u,d)=>s.set(u,d));const o=this.ogma.getNodes(n).getAttributes(["x","y","radius"]),a={};return e.forEach((u,d)=>{const c=this.links.get(u.start),h=this.links.get(u.end),x=t.getFeature(d);let f=x.geometry.coordinates[0],g=x.geometry.coordinates[1];const p=c?c.targetType===l.TARGET_TYPES.NODE?o[s.get(c.target)]:c.targetType===l.TARGET_TYPES.EDGE?this._getEdgeSnapPoint(c.target,c.magnet.t,!0):this._getAnnotationCenter(t.getFeature(c.target)):{x:f[0],y:f[1]},m=h?h.targetType===l.TARGET_TYPES.NODE?o[s.get(h.target)]:h.targetType===l.TARGET_TYPES.EDGE?this._getEdgeSnapPoint(h.target,h.magnet.t,!0):this._getAnnotationCenter(t.getFeature(h.target)):{x:g[0],y:g[1]},A=l.subtract(m,p);if(c)if(c.targetType===l.TARGET_TYPES.NODE)f=this._getNodeSnapPoint(p,A,this._isLinkedToCenter(c));else if(c.targetType===l.TARGET_TYPES.EDGE)f=this._getEdgeSnapPoint(c.target,c.magnet.t);else{const E=t.getMergedFeature(c.target);f=this._getAnnotationSnapPoint(E,m,c,t.zoom)}if(h)if(h.targetType===l.TARGET_TYPES.NODE)g=this._getNodeSnapPoint(m,l.mul(A,-1),this._isLinkedToCenter(h));else if(h.targetType===l.TARGET_TYPES.EDGE)g=this._getEdgeSnapPoint(h.target,h.magnet.t);else{const E=t.getMergedFeature(h.target);g=this._getAnnotationSnapPoint(E,p,h,t.zoom)}a[x.id]={properties:x.properties,geometry:{coordinates:[f,g]}},l.updateBbox(a[x.id]),this.updatedItems.add(x.id)}),a}requestCommit(){clearTimeout(this.commitTimeout),this.commitTimeout=setTimeout(this.commit,Fn)}_isLinkedToCenter(e){return e.magnet.type==="node"&&e.magnet.center}_getRigidFollowComment(e,t){const n=this.linksByArrowId.get(e);if(!n)return;const s=t.side===l.SIDE_START?n.end:n.start;if(!s)return;const r=this.links.get(s);if(!r||r.targetType!==l.TARGET_TYPES.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||!l.isComment(a)))return a}_getAnnotationCenter(e){return l.isPolygon(e)?Bt(e):l.getBoxCenter(e)}_getAnnotationSnapPoint(e,t,n,s){if(l.isPolygon(e)){const r=Dt(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=l.getBoxCenter(e);let{width:o,height:a}=l.isComment(e)?l.getCommentSize(e):l.getBoxSize(e);(l.isText(e)&&((x=e.properties.style)==null?void 0:x.fixedSize)||l.isComment(e))&&(o/=s,a/=s);const d=n.magnet;let c=d.nx*o,h=d.ny*a;if(l.isText(e)&&!l.isBox(e)){const{sin:f,cos:g}=this.store.getState(),p=c*g-h*f,m=c*f+h*g;c=p,h=m}return[r.x+c,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=l.mul(t,1/s),o=s<Number(e.radius)/2?{x:e.x,y:e.y}:l.add({x:e.x,y:e.y},l.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],d=a[1];if(r===0||r===void 0){const x=[u.x+t*(d.x-u.x),u.y+t*(d.y-u.y)];return n?{x:x[0],y:x[1]}:x}const c=nt.geometry.getQuadraticCurveControlPoint(u.x,u.y,d.x,d.y,r),h=nt.geometry.getPointOnQuadraticCurve(t,u.x,u.y,d.x,d.y,c.x,c.y);return n?{x:h.x,y:h.y}:[h.x,h.y]}destroy(){clearTimeout(this.commitTimeout),clearTimeout(this.nodePositionTimeout),this.ogma.events.off(this.onSetMultipleAttributes)}}function Cn(i,e,t,n,s=20){let r=0,o=1/0,a=null;for(let u=0;u<=s;u++){const d=u/s,c=nt.geometry.getPointOnQuadraticCurve(d,e.x,e.y,t.x,t.y,n.x,n.y),h=l.length(l.subtract(c,i));h<o&&(o=h,a=c,r=d)}return a?{t:r,point:a,distance:o}:null}function Nn(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:l.length(l.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:l.length(l.subtract(a,i))}}function Dn(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 d=e.get(u),c=r[u],h=a[2*u],x=a[2*u+1];let f;if(c===0||c===void 0)f=Nn(i,h,x);else{const g=nt.geometry.getQuadraticCurveControlPoint(h.x,h.y,x.x,x.y,c);f=Cn(i,h,x,g)}f&&f.distance<s&&(s=f.distance,n={point:f.point,id:d.getId(),magnet:{x:f.t,y:0},type:l.TARGET_TYPES.EDGE})}return n}function Mn(i,e,t){const n=e.getAttributes(["x","y","radius"]);for(let s=0;s<n.length;s++){const r=n[s],o=l.subtract({x:r.x,y:r.y},i),a=l.length(o);if(a>=Number(r.radius)+Number(t))continue;const u=l.mul(o,1/a),d=a<Number(r.radius)/2,c=d?{x:r.x,y:r.y}:l.add({x:r.x,y:r.y},l.mul(u,-Number(r.radius))),h=d?{x:0,y:0}:u;return{point:c,id:e.get(s).getId(),magnet:h,type:l.TARGET_TYPES.NODE}}return null}function wn(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 bn(i,e,t,n,s){const r=i*i,o=r*i,a=1-i,u=a*a,d=u*a;return{x:d*e.x+3*u*i*t.x+3*a*r*n.x+o*s.x,y:d*e.y+3*u*i*t.y+3*a*r*n.y+o*s.y}}function Bn(i,e,t,n,s){let r=1/0,o=null;const a=20;for(let u=0;u<=a;u++){const d=u/a,c=bn(d,e,t,n,s),h=l.length(l.subtract(c,i));h<r&&(r=h,o=c)}return o?{point:o,distance:r}:null}function Tn(i,e,t){const n=e.geometry.coordinates[0];for(let s=0;s<n.length-1;s++){const[r,o]=n[s];if(l.length(l.subtract({x:r,y:o},i))<t)return{point:{x:r,y:o},magnet:{x:r,y:o},type:l.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],d={x:r,y:o},c={x:a,y:u},h=l.subtract(c,d),x=l.length(h),f={x:h.x/x,y:h.y/x},g={x:-f.y,y:f.x},p=l.subtract(i,d),m=Math.abs(l.dot(g,p)),A=l.dot(f,p);if(A>=0&&A<=x&&m<t){const E={x:d.x+f.x*A,y:d.y+f.y*A};return{point:E,magnet:E,type:l.TARGET_TYPES.POLYGON,id:e.id}}}return null}function vn(i,e,t){for(const s of e){const o=s.geometry.coordinates[0].slice(0,-1);if(o.length<3)return Tn(i,s,t);for(let c=0;c<o.length;c++){const[h,x]=o[c];if(l.length(l.subtract({x:h,y:x},i))<t)return{point:{x:h,y:x},magnet:{x:h,y:x},type:l.TARGET_TYPES.POLYGON,id:s.id}}const a=wn(i,o);let u=null,d=a?1/0:t;for(let c=0;c<o.length;c++){const h=o[(c-1+o.length)%o.length],x=o[c],f=o[(c+1)%o.length],g=o[(c+2)%o.length],p=x[0]+(f[0]-h[0])/6*.5,m=x[1]+(f[1]-h[1])/6*.5,A=f[0]-(g[0]-x[0])/6*.5,E=f[1]-(g[1]-x[1])/6*.5,y=Bn(i,{x:x[0],y:x[1]},{x:p,y:m},{x:A,y:E},{x:f[0],y:f[1]});if(y){const D=y.distance;if(a)D<d&&(d=D,u=y.point);else if(D<t)return{point:y.point,magnet:y.point,type:l.TARGET_TYPES.POLYGON,id:s.id}}}if(a&&u)return{point:u,magnet:u,type:l.TARGET_TYPES.POLYGON,id:s.id}}return null}const Ce=[{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 qt(i,e,t,n,s,r,o,a,u){const d=i*s,c=e*r;return u?{x:t+(d*o-c*a),y:n+(d*a+c*o)}:{x:t+d,y:n+c}}function Ln(i,e,t,n,s){var c;const r=l.getBoxCenter(e);let{width:o,height:a}=l.getBoxSize(e);const{sin:u,cos:d}=s.getState();(c=e.properties.style)!=null&&c.fixedSize&&(o/=t,a/=t);for(const h of Ce){let x=h.x*o,f=h.y*a;if(!l.isBox(e)){const m=x*d-f*u,A=x*u+f*d;x=m,f=A}const g={x:r.x+x,y:r.y+f};if(!(l.length(l.subtract(g,i))>=n))return{point:{x:g.x,y:g.y},type:l.TARGET_TYPES.TEXT,magnet:h,id:e.id}}return null}function Pn(i,e,t,n,s){var g;const{x:r,y:o}=l.getBoxCenter(e);let{width:a,height:u}=l.getBoxSize(e);(g=e.properties.style)!=null&&g.fixedSize&&(a/=t,u/=t);const{sin:d,cos:c}=s.getState(),h=!l.isBox(e);let x=null,f=1/0;for(let p=0;p<4;p++){const[m,A,E,y]=kn[p],D=qt(m,A,r,o,a,u,c,d,h),C=qt(E,y,r,o,a,u,c,d,h),F=l.subtract(C,D),N=l.length(F),M={x:F.x/N,y:F.y/N},T={x:-M.y,y:M.x},b=l.subtract(i,D),B=l.dot(T,b),L=l.dot(M,b);if(L>=0&&L<=N){const P=Math.abs(B);if(P<n||P<f){const R=L/N,w={point:{x:D.x+M.x*L,y:D.y+M.y*L},magnet:{x:m+(E-m)*R,y:A+(y-A)*R},type:l.TARGET_TYPES.TEXT,id:e.id};if(P<n)return w;P<f&&(f=P,x=w)}}}return x&&f<Math.max(a,u)?x:null}function On(i,e,t,n,s){for(const r of e){const o=Ln(i,r,t,n,s)||Pn(i,r,t,n,s);if(o)return o}return null}class Rn 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=>l.isText(g)||l.isBox(g)),a=r.filter(g=>l.isPolygon(g)),{nodes:u,edges:d}=this.ogma.view.getElementsInside(s.minX,s.minY,s.maxX,s.maxY),c=this.snapToNodes(t,u);if(c)return c;const h=this.snapToEdges(t,d);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 On(t,n,s,this.options.magnetRadius,this.store)}snapToPolygon(t,n){return vn(t,n,this.options.magnetRadius)}snapToNodes(t,n){return Mn(t,n,this.options.detectMargin)}snapToEdges(t,n){return Dn(t,n,this.options.magnetRadius)}getHoveredNode(){return this.hoveredNode}clearHoveredNode(){var t;(t=this.hoveredNode)==null||t.setSelected(!1),this.hoveredNode=null}getMagnets(){return Ce}}class _n 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,"onMouseMove",t=>{const n=l.clientToContainerPosition(t,this.ogma.getContainer()),s=this.store.getState();if(this.mouseDownState&&!s.isDragging){const c=t.clientX-this.mouseDownState.screenX,h=t.clientY-this.mouseDownState.screenY;Math.sqrt(c*c+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,d=s.hoveredFeature;u!==d&&s.setHoveredFeature(u),this.setCursor(u===null?l.cursors.default:l.cursors.pointer)});S(this,"onMouseClick",()=>{Date.now()<this.suppressClickUntil});S(this,"onMouseDown",t=>{if(Date.now()<this.suppressClickUntil)return;if(at(t.target)){this.mouseDownState=null;return}const n=l.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();this.store.setState({mousePressed:!0,mousePressPoint:{x:s,y:r}}),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}),at(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(l.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=l.clientToContainerPosition(t,this.ogma.getContainer()),{x:s,y:r}=this.ogma.view.screenToGraphCoordinates(n),o=this.detect(s,r);if(!o||!l.isComment(o))return;const a=(h=o.properties.style)==null?void 0:h.maxHeight,u=o.properties.height;if(!a||u<=a)return;const d=this.ogma.getContainer(),c=d==null?void 0:d.querySelector(`[data-annotation="${o.id}"] .comment-box foreignObject div`);c&&(t.stopPropagation(),t.preventDefault(),c.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.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,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;for(const d of u){const c=o.getFeature(d.id);if(l.isArrow(c)){if(l.detectArrow(c,{x:t,y:n},a)){r=c;break}}else if(l.isBox(c)){if(l.detectBox(c,{x:t,y:n},0,1,a)){r=c;break}}else if(l.isPolygon(c)){if(l.detectPolygon(c,{x:t,y:n},a)){r=c;break}}else if(l.isComment(c)){if(l.detectComment(c,{x:t,y:n},a,o.sin,o.cos,o.zoom)){r=c;break}}else if(l.isText(c)&&l.detectText(c,{x:t,y:n},a,o.revSin,o.revCos,o.zoom)){r=c;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(l.cursors.crosshair):t==="rotate"&&this.setCursor(l.cursors.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 Ne(i,e,t=0,n=i.length-1,s=Hn){for(;n>t;){if(n-t>600){const u=n-t+1,d=e-t+1,c=Math.log(u),h=.5*Math.exp(2*c/3),x=.5*Math.sqrt(c*h*(u-h)/u)*(d-u/2<0?-1:1),f=Math.max(t,Math.floor(e-d*h/u+x)),g=Math.min(n,Math.floor(e+(u-d)*h/u+x));Ne(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 Hn(i,e){return i<e?-1:i>e?1:0}class In{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(!ot(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;ot(e,u)&&(t.leaf?n.push(a):St(e,u)?this._all(a,n):r.push(a))}t=r.pop()}return n}collides(e){let t=this.data;if(!ot(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(ot(e,o)){if(t.leaf||St(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,d;for(;n||r.length;){if(n||(n=r.pop(),u=r[r.length-1],a=o.pop(),d=!0),n.leaf){const c=Gn(e,n.children,t);if(c!==-1)return n.children.splice(c,1),r.push(n),this._condense(r),this}!d&&!n.leaf&&St(n,s)?(r.push(n),o.push(a),a=0,u=n,n=n.children[0]):u?(a++,n=u.children[a],d=!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),d=u*Math.ceil(Math.sqrt(o));Kt(e,t,n,d,this.compareMinX);for(let c=t;c<=n;c+=d){const h=Math.min(c+d-1,n);Kt(e,c,h,u,this.compareMinY);for(let x=c;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 d=t.children[u],c=mt(d),h=Wn(e,d)-c;h<o?(o=h,r=c<r?c:r,a=d):h===o&&c<r&&(r=c,a=d)}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),d=tt(e,a,n,this.toBBox),c=$n(u,d),h=mt(u)+mt(d);c<r?(r=c,s=a,o=h<o?h:o):c===r&&h<o&&(o=h,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:zn,r=e.leaf?this.compareMinY:Yn,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=rt(o)+rt(a);for(let d=t;d<n-t;d++){const c=e.children[d];et(o,e.leaf?r(c):c),u+=rt(o)}for(let d=n-t-1;d>=t;d--){const c=e.children[d];et(a,e.leaf?r(c):c),u+=rt(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 Gn(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 zn(i,e){return i.minX-e.minX}function Yn(i,e){return i.minY-e.minY}function mt(i){return(i.maxX-i.minX)*(i.maxY-i.minY)}function rt(i){return i.maxX-i.minX+(i.maxY-i.minY)}function Wn(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 $n(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 St(i,e){return i.minX<=e.minX&&i.minY<=e.minY&&e.maxX<=i.maxX&&e.maxY<=i.maxY}function ot(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 Kt(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;Ne(i,o,e,t,s),r.push(e,o,o,t)}}const J={minX:0,minY:0,maxX:0,maxY:0},Zt=(i,e)=>i.id===e.id;class Un extends In{constructor(t){super();S(this,"store");S(this,"onRotationChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>l.isText(n)||l.isComment(n));for(const n of t)this.updateRotatedText(n)});S(this,"onZoomChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>{var s;return(l.isText(n)||l.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=>{l.isText(s)||l.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&&(l.updateBbox(o),l.isText(o)||l.isComment(o)?this.updateRotatedText(o):(this.remove(o,Zt),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,Zt);const s=l.getBoxCenter(t);let{width:r,height:o}=l.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,d=o/2,c=n.getRotatedBBox(s.x-u,s.y-d,s.x+u,s.y+d);this.insert({...t,geometry:{...t.geometry,bbox:c.slice()}})}compareMinX(t,n){return l.getBbox(t)[0]-l.getBbox(n)[0]}compareMinY(t,n){return l.getBbox(t)[1]-l.getBbox(n)[1]}toBBox(t){const n=l.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 De{constructor(e,t){S(this,"layer");this.ogma=e,this.store=t}destroy(){}}const Jt=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]];class Xn extends De{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,d=this.handleRadius*s;t.fillStyle=this.handleFill,t.lineWidth=this.handleStrokeWidth*s,t.strokeStyle=this.handleStroke,Object.values(u).forEach(c=>{if(!n.isSelected(c.id))return;const h=a[c.id]?{...c,...a[c.id]}:c;if(l.isArrow(h))this.renderArrowHandles(h,t,d,r);else if(l.isBox(h)||l.isText(h)){const x=l.isText(h)?o:0;this.renderOutline(h,t,x,r,n.zoom),this.renderBoxHandles(h,t,d,r,x)}else l.isPolygon(h)&&this.renderPolygonHandles(h,t,d,r,n.drawingFeature===h.id)})});this.layer=t.layers.addCanvasLayer(this.render,void 0,l.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,A;const a=l.isText(t)&&((m=t.properties.style)==null?void 0:m.fixedSize);let{width:u,height:d}=l.getBoxSize(t);a&&(u/=o,d/=o);const c=l.getBoxPosition(t,a,o),h=u/2,x=d/2,f=c.x+h,g=c.y+x;n.save(),n.translate(f,g),n.rotate(s);const p=(A=t.properties.style)==null?void 0:A.borderRadius;if(p&&p>0?(Qe(n,-h,-x,u,d,p),n.stroke()):n.strokeRect(-h,-x,u,d),r>=4&&r<8){let E,y,D,C;const F=p&&p>0?p:this.handleRadius/o;switch(r){case 4:E=-h+F,y=-x,D=h-F,C=-x;break;case 5:E=h,y=-x+F,D=h,C=x-F;break;case 6:E=h-F,y=x,D=-h+F,C=x;break;case 7:E=-h,y=x-F,D=-h,C=-x+F;break}n.lineWidth=this.handleStrokeWidth*this.handleMagnifier/o,n.beginPath(),n.moveTo(E,y),n.lineTo(D,C),n.stroke(),n.lineWidth=this.handleStrokeWidth}n.restore()}renderArrowHandles(t,n,s,r){var x,f,g,p;const o=l.getArrowStart(t),a=l.getArrowEnd(t),u=+(r===0),d=+(r===1),c=s*(1+(this.handleMagnifier-1)*u),h=s*(1+(this.handleMagnifier-1)*d);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-c,o.y-c),n.rect(o.x-c,o.y-c,c*2,c*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(l.isText(t)&&((g=t.properties.style)!=null&&g.fixedSize))return;const{width:a,height:u}=l.getBoxSize(t),d=l.getBoxPosition(t),c=a/2,h=u/2,x=d.x+c,f=d.y+h;n.save(),n.translate(x,f),n.rotate(o),n.beginPath();for(let p=0;p<Jt.length;p++){const[m,A]=Jt[p],E=a*m,y=u*A,D=r===p?s*this.handleMagnifier:s;n.rect(E-D,y-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[d,c]=a[u],h=r===u?s*this.handleMagnifier:s;n.moveTo(d+h,c),n.arc(d,c,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],d=r[a],c=r[(a+1)%o],h=r[(a+2)%o],x=d[0]+(c[0]-u[0])/6*s,f=d[1]+(c[1]-u[1])/6*s,g=c[0]-(h[0]-d[0])/6*s,p=c[1]-(h[1]-d[1])/6*s;a===0&&t.moveTo(d[0],d[1]),t.bezierCurveTo(x,f,g,p,c[0],c[1])}t.closePath()}renderCenterPoint(t,n){var r;const s=this.store.getState();if(l.isText(t)){const o=l.getBoxPosition(t,(r=t.properties.style)==null?void 0:r.fixedSize,s.zoom),a=l.getBoxSize(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 Vn=.5;function jn(i,e,t,n){const{start:s,end:r}=l.getArrowEndPoints(i),o=l.subtract(r,s);return Math.min(n,Math.max(2*e,l.length(o)*.01,t))}function Qt(i,e){return!i||i==="none"?0:i==="dot"?e*2:i==="halo-dot"?e*4:i==="arrow"||i==="arrow-plain"?e:0}function qn(i,e){if(!i){i=l.createSVGElement("g");const t=l.createSVGElement("path");i.classList.add("annotation-arrow"),i.setAttribute("data-annotation",`${e}`),i.setAttribute("data-annotation-type","arrow"),i.appendChild(t);const n=l.createSVGElement("g");n.classList.add("annotation-arrow-endpoints"),i.appendChild(n)}return i}function Kn(i,e,t,n,s,r){const{start:o,end:a}=l.getArrowEndPoints(e),u=e.properties.style||l.defaultArrowStyle,{tail:d,strokeWidth:c=0,head:h,strokeColor:x,strokeType:f}=u,g=l.subtract(a,o),p=Ae(e)?1/r.zoom:1,m=jn(e,c,t,n)*p,A=qn(s,e.id),E=A.firstChild,y=x||"none";E.setAttribute("stroke",y),E.setAttribute("stroke-width",`${p*c}`),E.setAttribute("fill","none"),E.setAttribute("stroke-linecap","round"),E.setAttribute("stroke-linejoin","round");const D=Qt(d,c*p),C=Qt(h,c*p),F=l.normalize(g),N=l.add(o,l.mul(F,D)),M=l.add(a,l.mul(F,-C)),T=`M ${N.x} ${N.y} L ${M.x} ${M.y}`;E.setAttribute("d",T);const b=A.children[1];return b.innerHTML="",f==="dashed"?E.setAttribute("stroke-dasharray","5,10"):E.removeAttribute("stroke-dasharray"),te(b,o,g,y,d,c,p,m),te(b,a,l.invert(g),y,h,c,p,m),A.setAttribute("transform",`rotate(${-r.rotation*(180/Math.PI)})`),i.appendChild(A),A}function te(i,e,t,n,s,r,o,a){s==="halo-dot"&&ee(i,e,Zn(n),Vn,r*o*4),(s==="dot"||s==="halo-dot")&&ee(i,e,n,1,r*o*2),(s==="arrow"||s==="arrow-plain")&&Jn(i,e,t,n,s==="arrow-plain",r*o,a)}function Zn(i){return i==="none"?"none":i}function ee(i,e,t,n,s){const r=l.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 Jn(i,e,t,n,s,r,o){const a=l.mul(l.normalize(t),o),u=l.add(e,l.rotateRadians(a,Math.PI/6)),d=l.add(e,l.rotateRadians(a,-Math.PI/6)),c=l.createSVGElement("path"),h=`${e.x} ${e.y}`,x=`M ${u.x} ${u.y} L ${h} L ${d.x} ${d.y}${s?" Z":""}`;c.setAttribute("d",x),c.setAttribute("stroke",n),c.setAttribute("stroke-width",`${r}`),c.setAttribute("fill",s?n:"none"),c.setAttribute("stroke-linecap","round"),c.setAttribute("stroke-linejoin","round"),i.appendChild(c)}function Qn(i,e,t="box"){if(!i){i=l.createSVGElement("g"),i.setAttribute("data-annotation",`${e}`),i.setAttribute("data-annotation-type",t),i.classList.add(`annotation-${t}`);const n=l.createSVGElement("rect");i.appendChild(n)}return i}function Me(i,e,t,n){const s=e.id,r=`class${s}`,o=l.getBoxSize(e),a=Qn(t,s,e.properties.type),{strokeColor:u,strokeWidth:d,strokeType:c,background:h,borderRadius:x,boxShadow:f}=e.properties.style||l.defaultBoxStyle;a.classList.add("annotation-box"),a.setAttribute("fill",`${h||"transparent"}`);const g=a.firstChild;x&&(g.setAttribute("rx",`${x}`),g.setAttribute("ry",`${x}`)),c&&c!=="none"&&(g.setAttribute("stroke",u||"black"),g.setAttribute("stroke-width",`${d}`),c==="dashed"&&g.setAttribute("stroke-dasharray","5,5")),h&&h.length&&(n.hoveredFeature===e.id?g.setAttribute("fill",l.brighten(h)):g.setAttribute("fill",h));const p=l.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 ts(){const i=l.createSVGElement("style");return i.textContent=`
9
+ </div>`,position:f,size:g,scaled:!this.fixedSize},c.LAYERS.EDITOR),this.layer.moveToTop(),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(b=>({rotation:b.rotation,zoom:b.zoom,annotation:b.features[this.annotation]}),this.update,{equalityFn:(b,C)=>b.rotation===C.rotation&&b.zoom===C.zoom&&b.annotation===C.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=Ae(e),[o,a]=e.geometry.coordinates,d=e.properties.width;let l=e.properties.height;n&&(l=Math.min(l,n));const h=this.fixedSize?1/s:1;return{x:o-d*h/2+r*h,y:a-l*h/2+r*h}}getSize(){const e=this.getAnnotation();if(!e)return{width:0,height:0};const t=c.getBoxSize(e),n=Ae(e),s=e.properties.style,r=s==null?void 0:s.maxHeight;let o=t.height-n*2;r&&(o=Math.min(o,r-n*2));const a=Di(e,this.store.getState());return o=Math.max(0,o-a),{width:t.width-n*2,height:o}}updateStyle(){var b;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:d=0,fixedSize:l=t.fixedSize,fontScale:h,fontWeight:u}=e.properties.style||t,x=this.textarea,f=this.layer.element,g=1,p=c.getEffectiveFontSize(s,h)*g,A=d*g,y=f.style;if(y.display="grid",y.gridTemplateRows="1fr auto",y.boxSizing="border-box",y.background=a||"transparent",y.borderRadius=`${(r||0)*g}px`,y.padding=`${A}px`,y.transformOrigin="center",y.transform=`rotate(${this.store.getState().rotation}rad)`,e.properties.type==="comment"){const C=e.properties.style,E=(C==null?void 0:C.shadow)!==!1;y.boxShadow=E?"0 2px 8px rgba(0, 0, 0, 0.15)":"none"}const F=x.style;if(F.fontFamily=n||"sans-serif",F.fontWeight=u||"normal",F.fontSize=`${p}px`,F.lineHeight=`${p*c.TEXT_LINE_HEIGHT}px`,F.padding="0",F.border="none",F.outline="none",F.boxSizing="border-box",F.color=o||"black",F.background="transparent",F.flex="1",F.minHeight="0",F.resize="none",this.sendButton){const C=vi*g,E=Ti*g;this.sendButton.style.width=`${C}px`,this.sendButton.style.height=`${C}px`,this.sendButton.style.padding=`${E}px`,this.sendButton.style.transform="";const N=this.sendButton.querySelector(".ogma-send-button-icon");if(N){const D=Bi*g;N.style.width=`${D}px`,N.style.height=`${D}px`}}if(l){const C=(b=e.properties.style)==null?void 0:b.maxHeight,E=C&&e.properties.height>=C;F.overflowY=E?"auto":"hidden",F.overflowX="hidden"}}updatePosition(){this.layer.setPosition(this.getPosition())}updateContent(){var o,a,d,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 h=this.textarea.style.height;this.textarea.style.height="0px";const u=this.textarea.scrollHeight;this.textarea.style.height=h;const x=((a=e.properties.style)==null?void 0:a.padding)||0,f=this.sendButton?parseFloat(this.sendButton.style.height||"0"):0,g=u+x*2+f,m=((d=e.properties.style)==null?void 0:d.minHeight)||ki;t=Math.max(m,g);const p=(l=e.properties.style)==null?void 0:l.maxHeight,A=e.properties.height,y=t-A;if(!c.isComment(e)&&Math.abs(y)>1){const[b,C]=e.geometry.coordinates;if(p&&t>p){const E=p-A;t=p,Math.abs(E)>1&&(n=[b,C+E/2])}else n=[b,C+y/2]}else p&&t>p&&(t=p)}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)}send(){this.updateContent(),this.textarea.blur(),this.onSendHandler()}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 Ae(i){var e;return((e=i.properties.style)==null?void 0:e.strokeWidth)||0}const Ce={x:1,y:0},Ne={x:0,y:1},Oi=[["top",Ne,-.5,-.5,.5,-.5],["right",Ce,.5,-.5,.5,.5],["bottom",Ne,-.5,.5,.5,.5],["left",Ce,-.5,-.5,-.5,.5]],Pi={top:[0,1],right:[1,2],bottom:[2,3],left:[3,0]},be=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]],Ri=[c.cursors.nwResize,c.cursors.neResize,c.cursors.seResize,c.cursors.swResize],_i=100,Ii=50;class vt extends Et{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(ct(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 b;const s=this.getAnnotation(),{x:r,y:o}=this.clientToCanvas(t);let{width:a,height:d}=c.getBoxSize(s);const l=c.handleDetectionThreshold/n,h=c.getBoxCenter(s),u=this.store.getState();let{revSin:x,revCos:f}=u;(c.isBox(s)||c.isComment(s))&&(x=0,f=1),this.hoveredHandle=void 0;const g=c.handleRadius*(1/n),m=r-h.x,p=o-h.y,A=m*f-p*x,y=m*x+p*f,F=((b=s.properties.style)==null?void 0:b.fixedSize)===!0||c.isComment(s);if(F&&(a/=n,d/=n),!F){for(let C=0;C<be.length;C++){const[E,N]=be[C],D=a*E,v=d*N;if(A>=D-g-l&&A<=D+g+l&&y>=v-g-l&&y<=v+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,D,v,T]of Oi){const w=a*N,L=d*D,O=a*v,R=d*T,M=c.dot(E,{x:A-w,y:y-L});if(Math.abs(M)<l&&A>=w-l&&A<=O+l&&y>=L-l&&y<=R+l){this.hoveredHandle={type:"edge",edge:C,corner:-1},this.store.setState({hoveredHandle:Pi[C][0]+4,hoveredFeature:this.annotation}),this.setCursor(this.getEdgeCursor(C));return}}}if(A>=-a/2-l&&A<=a/2+l&&y>=-d/2-l&&y<=d/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 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"&&(Xt(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(c.EVT_DRAG,{detail:{point:s,annotation:this.annotation,handle:o}}))}nextStyleWithFontScale(t,n,s,r,o){const a=t.properties.style;if(!(a!=null&&a.scaleFontOnResize)||n<=0||s<=0||r<=0||o<=0)return a;const d=Math.sqrt(r/n*(o/s)),l=Math.min(c.MAX_FONT_SCALE,Math.max(c.MIN_FONT_SCALE,(a.fontScale??1)*d));return{...a,fontScale:l}}dragCorner(t,n,s){const r=s===0||s===1,o=s===0||s===3,a=s===1||s===2,d=s===2||s===3,{width:l,height:h}=c.getBoxSize(t),u=this.store.getState();let{revSin:x,revCos:f}=u;(c.isBox(t)||c.isComment(t))&&(x=0,f=1);const g=n.x*f-n.y*x,m=n.x*x+n.y*f;let p=0,A=0;o?p=-g:a&&(p=g),r?A=-m:d&&(A=m);const y=Math.max(0,l+p),F=Math.max(0,h+A),b=c.getBoxCenter(t),C=b.x+n.x/2,E=b.y+n.y/2;return{...t,properties:{...t.properties,width:y,height:F,style:this.nextStyleWithFontScale(t,l,h,y,F)},geometry:{type:t.geometry.type,coordinates:[C,E]}}}dragEdge(t,n,s){const{width:r,height:o}=c.getBoxSize(t),a=c.getBoxCenter(t),d=this.store.getState();let{revSin:l,revCos:h}=d;(c.isBox(t)||c.isComment(t))&&(l=0,h=1);const u=n.x*h-n.y*l,x=n.x*l+n.y*h;let f=r,g=o,m=0,p=0;switch(s.edge){case"top":g=Math.max(0,o-x),p=x/2;break;case"bottom":g=Math.max(0,o+x),p=x/2;break;case"left":f=Math.max(0,r-u),m=u/2;break;case"right":f=Math.max(0,r+u),m=u/2;break}const A=m*h+p*l,y=-m*l+p*h;return{...t,properties:{...t.properties,width:f,height:g,style:this.nextStyleWithFontScale(t,r,o,f,g)},geometry:{type:t.geometry.type,coordinates:[a.x+A,a.y+y]}}}onDragStart(t){return super.onDragStart(t)?(this.stopEditingText(),this.store.getState().startLiveUpdate([this.annotation]),!0):!1}applyDefaultSizeIfEmpty(){var d;const t=this.pendingDefaultSize;this.pendingDefaultSize=null;const n=this.getAnnotation();if(!n||!(c.isBox(n)||c.isText(n))||(d=n.properties.style)!=null&&d.fixedSize||n.properties.width>0&&n.properties.height>0)return;const s=(t==null?void 0:t.width)??_i,r=(t==null?void 0:t.height)??Ii,[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 Li(this.ogma,this.store,this.annotation,this.stopEditingText))}onDragEnd(t){var d,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-(((d=this.dragStartPoint)==null?void 0:d.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 h=this.getAnnotation();a&&h&&(c.isText(h)||c.isComment(h))&&this.startEditingText()}return this.hoveredHandle=void 0,this.dragStartPoint=void 0,this.dragging=!1,!0}getCornerCursor(t){return Ri[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}})}}const Ze="mousedown-annotation";class Hi 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,"savedPan");S(this,"savedDrag");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 h=t.clientX-this.mouseDownState.screenX,u=t.clientY-this.mouseDownState.screenY;Math.sqrt(h*h+u*u)>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),d=(a==null?void 0:a.id)??null,l=s.hoveredFeature;d!==l&&s.setHoveredFeature(d),this.setCursor(d===null?c.cursors.default:c.cursors.pointer)});S(this,"onMouseClick",()=>{Date.now()<this.suppressClickUntil});S(this,"onMouseDownArm",t=>{if(Date.now()<this.suppressClickUntil||ct(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=>{var l,h;if(Date.now()<this.suppressClickUntil)return;if(ct(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),a=this.store.getState(),d=o?a.selectedFeatures.has(o.id):!1;if(this.mouseDownState={annotation:o,screenX:t.clientX,screenY:t.clientY,hasMoved:!1,wasSelected:d},o&&!a.options.isEditable(o)){const u=this.ogma.getOptions().interactions;this.savedPan=((l=u==null?void 0:u.pan)==null?void 0:l.enabled)??!0,this.savedDrag=((h=u==null?void 0:u.drag)==null?void 0:h.enabled)??!0,this.ogma.setOptions({interactions:{pan:{enabled:!1},drag:{enabled:!1}}})}o&&!d&&(t.ctrlKey||t.metaKey?a.toggleSelection(o.id):a.setSelectedFeatures([o.id])),o&&this.dispatchEvent(new CustomEvent(Ze,{detail:{id:o.id}}))});S(this,"onMouseUp",t=>{const n=this.store.getState();if(this.store.setState({mousePressed:!1,mousePressPoint:null}),this.savedPan!==void 0&&(this.ogma.setOptions({interactions:{pan:{enabled:this.savedPan},drag:{enabled:this.savedDrag}}}),this.savedPan=void 0,this.savedDrag=void 0),ct(t.target)){this.mouseDownState=null;return}if(this.mouseDownState&&!this.mouseDownState.hasMoved&&!n.isDragging){const s=this.mouseDownState.annotation;s?t.ctrlKey||t.metaKey?this.mouseDownState.wasSelected&&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 u;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=(u=o.properties.style)==null?void 0:u.maxHeight,d=o.properties.height;if(!a||d<=a)return;const l=this.ogma.getContainer(),h=l==null?void 0:l.querySelector(`[data-annotation="${o.id}"] .comment-box foreignObject div`);h&&(t.stopPropagation(),t.preventDefault(),h.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 d=this.index.query(this.query);if(d.length===0)return null;const l={comment:0,arrow:1,text:2,box:3,polygon:3},h=[...d].sort((u,x)=>(l[u.properties.type]??9)-(l[x.properties.type]??9));for(const u of h){const x=o.getFeature(u.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)}}class zi 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 vt(this.ogma,this.store,r)),this.handlers.set("text",new vt(this.ogma,this.store,r)),this.handlers.set("comment",new vt(this.ogma,this.store,r)),this.handlers.set("arrow",new In(this.ogma,this.store,this.snapping,r)),this.handlers.set("polygon",new zn(this.ogma,this.store,r)),this.handlers.forEach(a=>{a.addEventListener("dragstart",(d=>{this.dispatchEvent(new CustomEvent(c.EVT_DRAG_START,{detail:{...d.detail}})),this.store.setState({isDragging:!0}),this.interaction.setMode("edit")})),a.addEventListener("dragend",(d=>{this.dispatchEvent(new CustomEvent(c.EVT_DRAG_END,{detail:{...d.detail}})),this.store.setState({isDragging:!1}),this.interaction.suppressClicksTemporarily()}))}),this.interaction.addEventListener(Ze,(a=>{const d=a.detail.id,l=this.store.getState().features[d],h=l&&this.handlers.get(l.properties.type);h&&!h.isAnnotation(d)&&this.editFeature(d)})),this.store.subscribe(a=>a.selectedFeatures,(a,d)=>{const l=Array.from(a.keys()).filter(u=>!d.has(u)),h=Array.from(d.keys()).filter(u=>!a.has(u));!l.length&&!h.length||(h.forEach(u=>this.stopEditingFeature(u)),l.forEach(u=>this.editFeature(u)))})}stopEditingFeature(t){const n=this.store.getState().features[t];if(!n)return;const s=n.properties.type,r=this.handlers.get(s);r&&r.isAnnotation(t)&&r.stopEditing()}editFeature(t){var s;const n=this.store.getState().features[t];n&&(this.setActiveHandler(n.properties.type),this.store.getState().options.isEditable(n)&&((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 Je(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 Ht(t,a)}function Ht(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 mt(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 Gi=.5;class Ui{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)?Gt(e):c.getBoxCenter(e)}getAnnotationSnapPoint(e,t,n,s){if(c.isPolygon(e)){const r=zt(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,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 h=l.nx*o,u=l.ny*a;if(c.isText(e)&&!c.isBox(e)){const{sin:f,cos:g}=this.store.getState(),m=h*g-u*f,p=h*f+u*g;h=m,u=p}return[r.x+h,r.y+u]}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)*Gi?{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(),d=a[0],l=a[1];if(r===0||r===void 0){const x=[d.x+t*(l.x-d.x),d.y+t*(l.y-d.y)];return n?{x:x[0],y:x[1]}:x}const h=lt.geometry.getQuadraticCurveControlPoint(d.x,d.y,l.x,l.y,r),u=lt.geometry.getPointOnQuadraticCurve(t,d.x,d.y,l.x,l.y,h.x,h.y);return n?{x:u.x,y:u.y}:[u.x,u.y]}}function Wi(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 Yi{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(),d=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=zt(f),m=g[2]-g[0],p=g[3]-g[1],A=r.x-g[0],y=r.y-g[1],F=m>0?A/m:.5,b=p>0?y/p:.5;l={x:F,y:b}}}const h={id:a,arrow:d,target:n,targetType:s,magnet:Wi(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,h);const u=s===c.TARGET_TYPES.NODE?this.nodeToLink:s===c.TARGET_TYPES.EDGE?this.edgeToLink:this.annotationToLink;return u.has(n)||u.set(n,new Set),u.get(n).add(a),this.linksByArrowId.has(d)||this.linksByArrowId.set(d,{}),this.linksByArrowId.get(d)[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,h),this}remove(e,t){var o,a,d,l,h;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),(d=this.nodeToLink.get(r.target))==null||d.delete(s),(l=this.edgeToLink.get(r.target))==null||l.delete(s),(h=this.annotationToLink.get(r.target))==null||h.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(d=>!s.has(d)),o=Object.keys(t).filter(d=>!e[d]);r.forEach(d=>{var u,x;const l=n.getFeature(d);if(!l||!c.isArrow(l))return;const h=l;if((u=h.properties.link)!=null&&u.start){const f=h.properties.link.start;this.add(h,c.SIDE_START,f.id,f.type,f.magnet,"stored")}if((x=h.properties.link)!=null&&x.end){const f=h.properties.link.end;this.add(h,c.SIDE_END,f.id,f.type,f.magnet,"stored")}}),o.forEach(d=>{const l=t[d];if(c.isArrow(l)){const h=l;this.remove(h,c.SIDE_START),this.remove(h,c.SIDE_END)}else{const h=this.annotationToLink.get(d);if(!h)return;for(const u of h){const x=this.links.get(u);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 d of s){const l=e[d];if(!l||!this.annotationToLink.has(d))continue;const h=t[d],u=h.geometry.coordinates!==l.geometry.coordinates,x=h.properties.width!==l.properties.width||h.properties.height!==l.properties.height;if(!u&&!x)continue;const f=this.annotationToLink.get(d);for(const g of f){const m=this.links.get(g);if(!m)continue;const p=m.arrow;this.linksByArrowId.has(p)&&a.set(p,this.linksByArrowId.get(p))}}return a}}const $i=["x","y","radius"],Vi=1,Xi=20;class ji{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,"nodePositionFrameHandler");S(this,"geoOverlayActive",!1);S(this,"lastNodeLinkZoom",1);S(this,"lastGeoOverlayIds",[]);S(this,"onGeoModeChanged",()=>{if(this.geoOverlayActive=this.geoEnabled(),this.index.linksByArrowId.size!==0)if(this.geoOverlayActive){const e=this._computeArrowUpdates(this.index.linksByArrowId);this.lastGeoOverlayIds=Object.keys(e),this.store.getState().applyLiveUpdates(e)}else this.store.getState().clearLiveUpdates(this.lastGeoOverlayIds),this.lastGeoOverlayIds.forEach(e=>this.updatedItems.delete(e)),this.lastGeoOverlayIds=[]});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,"applyingEditingLiveUpdate",!1);S(this,"onEditingLiveUpdate",({editing:e})=>{if(!e||this.applyingEditingLiveUpdate)return;const t=this.index.annotationToLink.get(e);if(!t||t.size===0)return;const n=new Map;if(t.forEach(r=>{const o=this.index.links.get(r);if(!o)return;const a=o.arrow;n.set(a,this.index.linksByArrowId.get(a))}),n.size===0)return;const s=this._computeArrowUpdates(n);if(Object.keys(s).length!==0){this.applyingEditingLiveUpdate=!0;try{this.store.getState().applyLiveUpdates(s)}finally{this.applyingEditingLiveUpdate=!1}}});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(d=>{const l=this.index.links.get(d);if(!l)return;const h=l.arrow;t.set(h,this.index.linksByArrowId.get(h))})}),t.size>0&&this.update(t)});S(this,"throttledRefresh",c.throttle(()=>this.refresh(),Xi));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 d=this.index.links.get(a);if(!d)return;const l=d.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,"onRemoveNodes",({nodes:e})=>{const t=e.getId();if(!t.length)return;const n=this.store.getState(),s={};t.forEach(r=>{const o=this.index.nodeToLink.get(r);o&&Array.from(o).forEach(a=>{const d=this.index.links.get(a);if(!d)return;const l=d.arrow,h=s[l]??n.getFeature(l);if(!h)return;const u={...h,properties:{...h.properties,link:{...h.properties.link}}};this.index.remove(u,d.side),s[l]=u})}),Object.keys(s).length!==0&&n.batchUpdate(()=>{n.updateFeatures(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.geoOverlayActive=this.geoEnabled(),this.geoOverlayActive||(this.lastNodeLinkZoom=e.view.getZoom()),this.store.subscribe(o=>({zoom:o.zoom,rotation:o.rotation}),o=>{this.geoEnabled()||(this.lastNodeLinkZoom=o.zoom),this.throttledRefresh()},{equalityFn:(o,a)=>o.zoom===a.zoom&&o.rotation===a.rotation}),this.store.subscribe(o=>({editing:o.editingFeature,liveUpdates:o.liveUpdates}),this.onEditingLiveUpdate,{equalityFn:(o,a)=>o.editing===a.editing&&o.liveUpdates===a.liveUpdates}),this.ogma.events.on("setMultipleAttributes",this.onSetMultipleAttributes).on(["addEdges","removeEdges"],this.onAddRemoveEdges).on("removeNodes",this.onRemoveNodes).on("viewChanged",this.refresh).on(["geoEnabled","geoDisabled"],this.onGeoModeChanged)}requestUpdateFromNodePositions(e){this.nodePositionFrameHandler&&this.ogma.events.off(this.nodePositionFrameHandler),this.nodePositionFrameHandler=()=>{this.nodePositionFrameHandler=void 0,this.updateFromNodePositions(e)},this.ogma.events.once("frame",this.nodePositionFrameHandler)}updateFromNodePositions(e){if(!e.size)return;const t=e.getId(),n=new Map;t.forEach(l=>{const h=this.index.nodeToLink.get(l);h&&h.forEach(u=>{const x=this.index.links.get(u);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 h=this.index.edgeToLink.get(l);h&&h.forEach(u=>{const x=this.index.links.get(u);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($i),a=this.store.getState(),d={};for(let l=0;l<t.length;l++){const h=t[l],u=this.index.nodeToLink.get(h);if(u)for(const x of u){const f=this.index.links.get(x);if(!f)continue;const g=f.arrow,m=this.store.getState().getFeature(g),p=m.geometry.coordinates.slice(),A=c.getArrowSide(m,c.SIDE_END),y=c.getArrowSide(m,c.SIDE_START),F=f.side===c.SIDE_START?0:1,b=o[l],C=this.geometry.getNodeSnapPoint(b,c.mul(c.subtract(A,y),-1),this.geometry.isLinkedToCenter(f)),E=Je(this.index.links,this.index.linksByArrowId,this.store,g,f);if(E){const N=p[F],D=c.subtract({x:C[0],y:C[1]},{x:N[0],y:N[1]});p[0]=[p[0][0]+D.x,p[0][1]+D.y],p[1]=[p[1][0]+D.x,p[1][1]+D.y],mt(E,D,d,this.updatedItems)}else p[F]=C;d[g]={...m,geometry:{coordinates:p}},this.updatedItems.add(g),c.updateBbox(d[g])}}if(a.applyLiveUpdates(d),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();if(this.commitBlocked()){n.applyLiveUpdates(t);return}n.batchUpdate(()=>{n.updateFeatures(t)})}_geoRigidFollowDelta(e,t,n){if(!this.geoOverlayActive)return e;const s=this.lastNodeLinkZoom/this.ogma.view.getZoom(),r=c.subtract({x:n[0],y:n[1]},{x:t[0],y:t[1]});return c.subtract(e,c.mul(r,1-s))}_computeArrowUpdates(e){const t=this.store.getState(),n=Array.from(this.index.nodeToLink.keys()),s=new Map;n.forEach((d,l)=>s.set(d,l));const o=this.ogma.getNodes(n).getAttributes(["x","y","radius"]),a={};return e.forEach((d,l)=>{const h=this.index.links.get(d.start),u=this.index.links.get(d.end),x=t.getFeature(l);let f=x.geometry.coordinates[0],g=x.geometry.coordinates[1];const m=h?this.geometry.resolveLinkCenter(h,o,s,t):{x:f[0],y:f[1]},p=u?this.geometry.resolveLinkCenter(u,o,s,t):{x:g[0],y:g[1]},A=c.subtract(p,m);h&&(f=this.geometry.resolveLinkPoint(h,m,A,p,t)),u&&(g=this.geometry.resolveLinkPoint(u,p,c.mul(A,-1),m,t));const y=Ht(this.store,h),F=Ht(this.store,u);if(y&&u){const b=x.geometry.coordinates[1],C=x.geometry.coordinates[0],E={x:g[0]-b[0],y:g[1]-b[1]},N=this._geoRigidFollowDelta(E,b,C);(N.x!==0||N.y!==0)&&(f=[C[0]+N.x,C[1]+N.y],mt(y,N,a,this.updatedItems))}else if(F&&h){const b=x.geometry.coordinates[0],C=x.geometry.coordinates[1],E={x:f[0]-b[0],y:f[1]-b[1]},N=this._geoRigidFollowDelta(E,b,C);(N.x!==0||N.y!==0)&&(g=[C[0]+N.x,C[1]+N.y],mt(F,N,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(){this.commitBlocked()||(clearTimeout(this.commitTimeout),this.commitTimeout=setTimeout(this.commit,Vi))}commitBlocked(){return this.geoEnabled()||this.geoOverlayActive}geoEnabled(){try{return this.ogma.geo.enabled()}catch{return!1}}destroy(){clearTimeout(this.commitTimeout),this.nodePositionFrameHandler&&this.ogma.events.off(this.nodePositionFrameHandler),this.ogma.events.off(this.onSetMultipleAttributes).off(this.onAddRemoveEdges).off(this.onRemoveNodes).off(this.refresh).off(this.onGeoModeChanged)}}class Ki{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 Yi(e,n,s),this.geometry=new Ui(e,n),this.sync=new ji(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 d=new Set;for(const h of a){const u=this.registry.links.get(h);if(!u)continue;const x=r.getFeature(u.arrow);if(!x)continue;const f=n[u.arrow],g=((l=f==null?void 0:f.geometry)==null?void 0:l.coordinates)??x.geometry.coordinates,m=u.side===c.SIDE_START?0:1,p={x:g[m][0],y:g[m][1]},A=c.add(p,t),y={...x.geometry,coordinates:g.map((b,C)=>C===m?[A.x,A.y]:[...b])};n[u.arrow]={geometry:y},this.updatedItems.add(u.arrow);const F=Je(this.registry.links,this.registry.linksByArrowId,this.store,u.arrow,u);F&&!s.has(F.id)&&d.add(F.id)}for(const h of d){const u=r.getFeature(h);u&&(mt(u,t,n,this.updatedItems),this._collectLinkedArrowUpdates(h,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 d=this.registry.links.get(a);if(!d)continue;let l=n.getFeature(d.arrow);const h=n.liveUpdates[l.id];l=h?{...l,...h}:l;const u=l.geometry.coordinates[d.side===c.SIDE_START?0:1],x={x:u[0],y:u[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,m={...l.geometry,coordinates:l.geometry.coordinates.map((p,A)=>d.side===c.SIDE_START&&A===0||d.side===c.SIDE_END&&A===1?[g.x,g.y]:[...p])};t?t[l.id]={geometry:m}:n.applyLiveUpdate(l.id,{geometry:m})}}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 qi(i,e,t,n,s=20){let r=0,o=1/0,a=null;for(let d=0;d<=s;d++){const l=d/s,h=lt.geometry.getPointOnQuadraticCurve(l,e.x,e.y,t.x,t.y,n.x,n.y),u=c.length(c.subtract(h,i));u<o&&(o=u,a=h,r=l)}return a?{t:r,point:a,distance:o}:null}function Zi(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 Ji(i,e,t){let n=null,s=t;const r=e.getAttribute("curvature"),a=e.getExtremities().getPosition();for(let d=0;d<e.size;d++){const l=e.get(d),h=r[d],u=a[2*d],x=a[2*d+1];let f;if(h===0||h===void 0)f=Zi(i,u,x);else{const g=lt.geometry.getQuadraticCurveControlPoint(u.x,u.y,x.x,x.y,h);f=qi(i,u,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 Qi(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 d=c.mul(o,1/a),l=a<Number(r.radius)/2,h=l?{x:r.x,y:r.y}:c.add({x:r.x,y:r.y},c.mul(d,-Number(r.radius))),u=l?{x:0,y:0}:d;return{point:h,id:e.get(s).getId(),magnet:u,type:c.TARGET_TYPES.NODE}}return null}function tr(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],d=e[s][1];o>i.y!=d>i.y&&i.x<(a-r)*(i.y-o)/(d-o)+r&&(t=!t)}return t}function er(i,e,t,n,s){const r=i*i,o=r*i,a=1-i,d=a*a,l=d*a;return{x:l*e.x+3*d*i*t.x+3*a*r*n.x+o*s.x,y:l*e.y+3*d*i*t.y+3*a*r*n.y+o*s.y}}function nr(i,e,t,n,s){let r=1/0,o=null;const a=20;for(let d=0;d<=a;d++){const l=d/a,h=er(l,e,t,n,s),u=c.length(c.subtract(h,i));u<r&&(r=u,o=h)}return o?{point:o,distance:r}:null}function sr(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,d]=n[s+1],l={x:r,y:o},h={x:a,y:d},u=c.subtract(h,l),x=c.length(u),f={x:u.x/x,y:u.y/x},g={x:-f.y,y:f.x},m=c.subtract(i,l),p=Math.abs(c.dot(g,m)),A=c.dot(f,m);if(A>=0&&A<=x&&p<t){const y={x:l.x+f.x*A,y:l.y+f.y*A};return{point:y,magnet:y,type:c.TARGET_TYPES.POLYGON,id:e.id}}}return null}function ir(i,e,t){for(const s of e){const o=s.geometry.coordinates[0].slice(0,-1);if(o.length<3)return sr(i,s,t);for(let h=0;h<o.length;h++){const[u,x]=o[h];if(c.length(c.subtract({x:u,y:x},i))<t)return{point:{x:u,y:x},magnet:{x:u,y:x},type:c.TARGET_TYPES.POLYGON,id:s.id}}const a=tr(i,o);let d=null,l=a?1/0:t;for(let h=0;h<o.length;h++){const u=o[(h-1+o.length)%o.length],x=o[h],f=o[(h+1)%o.length],g=o[(h+2)%o.length],m=x[0]+(f[0]-u[0])/6*.5,p=x[1]+(f[1]-u[1])/6*.5,A=f[0]-(g[0]-x[0])/6*.5,y=f[1]-(g[1]-x[1])/6*.5,F=nr(i,{x:x[0],y:x[1]},{x:m,y:p},{x:A,y},{x:f[0],y:f[1]});if(F){const b=F.distance;if(a)b<l&&(l=b,d=F.point);else if(b<t)return{point:F.point,magnet:F.point,type:c.TARGET_TYPES.POLYGON,id:s.id}}}if(a&&d)return{point:d,magnet:d,type:c.TARGET_TYPES.POLYGON,id:s.id}}return null}const Qe=[{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}],rr=[[-.5,-.5,.5,-.5],[.5,-.5,.5,.5],[.5,.5,-.5,.5],[-.5,.5,-.5,-.5]];function De(i,e,t,n,s,r,o,a,d){const l=i*s,h=e*r;return d?{x:t+(l*o-h*a),y:n+(l*a+h*o)}:{x:t+l,y:n+h}}function or(i,e,t,n,s){var h;const r=c.getBoxCenter(e);let{width:o,height:a}=c.getBoxSize(e);const{sin:d,cos:l}=s.getState();(h=e.properties.style)!=null&&h.fixedSize&&(o/=t,a/=t);for(const u of Qe){let x=u.x*o,f=u.y*a;if(!c.isBox(e)){const p=x*l-f*d,A=x*d+f*l;x=p,f=A}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:u,id:e.id}}return null}function ar(i,e,t,n,s){var g;const{x:r,y:o}=c.getBoxCenter(e);let{width:a,height:d}=c.getBoxSize(e);(g=e.properties.style)!=null&&g.fixedSize&&(a/=t,d/=t);const{sin:l,cos:h}=s.getState(),u=!c.isBox(e);let x=null,f=1/0;for(let m=0;m<4;m++){const[p,A,y,F]=rr[m],b=De(p,A,r,o,a,d,h,l,u),C=De(y,F,r,o,a,d,h,l,u),E=c.subtract(C,b),N=c.length(E),D={x:E.x/N,y:E.y/N},v={x:-D.y,y:D.x},T=c.subtract(i,b),w=c.dot(v,T),L=c.dot(D,T);if(L>=0&&L<=N){const O=Math.abs(w);if(O<n||O<f){const R=L/N,M={point:{x:b.x+D.x*L,y:b.y+D.y*L},magnet:{x:p+(y-p)*R,y:A+(F-A)*R},type:c.TARGET_TYPES.TEXT,id:e.id};if(O<n)return M;O<f&&(f=O,x=M)}}}return x&&f<Math.max(a,d)?x:null}function cr(i,e,t,n,s){for(const r of e){const o=or(i,r,t,n,s)||ar(i,r,t,n,s);if(o)return o}return null}class lr 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:d,edges:l}=this.ogma.view.getElementsInside(s.minX,s.minY,s.maxX,s.maxY),h=this.snapToNodes(t,d);if(h)return h;const u=this.snapToEdges(t,l);if(u)return u;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 cr(t,n,s,this.options.magnetRadius,this.store)}snapToPolygon(t,n){return ir(t,n,this.options.magnetRadius)}snapToNodes(t,n){return Qi(t,n,this.options.detectMargin)}snapToEdges(t,n){return Ji(t,n,this.options.magnetRadius)}getHoveredNode(){return this.hoveredNode}clearHoveredNode(){var t;(t=this.hoveredNode)==null||t.setSelected(!1),this.hoveredNode=null}getMagnets(){return Qe}}function tn(i,e,t=0,n=i.length-1,s=dr){for(;n>t;){if(n-t>600){const d=n-t+1,l=e-t+1,h=Math.log(d),u=.5*Math.exp(2*h/3),x=.5*Math.sqrt(h*u*(d-u)/d)*(l-d/2<0?-1:1),f=Math.max(t,Math.floor(e-l*u/d+x)),g=Math.min(n,Math.floor(e+(d-l)*u/d+x));tn(i,e,f,g,s)}const r=i[e];let o=t,a=n;for(it(i,t,e),s(i[n],r)>0&&it(i,t,n);o<a;){for(it(i,o,a),o++,a--;s(i[o],r)<0;)o++;for(;s(i[a],r)>0;)a--}s(i[t],r)===0?it(i,t,a):(a++,it(i,a,n)),a<=e&&(t=a+1),e<=a&&(n=a-1)}}function it(i,e,t){const n=i[e];i[e]=i[t],i[t]=n}function dr(i,e){return i<e?-1:i>e?1:0}class hr{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(!pt(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],d=t.leaf?s(a):a;pt(e,d)&&(t.leaf?n.push(a):Bt(e,d)?this._all(a,n):r.push(a))}t=r.pop()}return n}collides(e){let t=this.data;if(!pt(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(pt(e,o)){if(t.leaf||Bt(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=nt([]),this}remove(e,t){if(!e)return this;let n=this.data;const s=this.toBBox(e),r=[],o=[];let a,d,l;for(;n||r.length;){if(n||(n=r.pop(),d=r[r.length-1],a=o.pop(),l=!0),n.leaf){const h=ur(e,n.children,t);if(h!==-1)return n.children.splice(h,1),r.push(n),this._condense(r),this}!l&&!n.leaf&&Bt(n,s)?(r.push(n),o.push(a),a=0,d=n,n=n.children[0]):d?(a++,n=d.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=nt(e.slice(t,n+1)),et(a,this.toBBox),a;s||(s=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,s-1))),a=nt([]),a.leaf=!1,a.height=s;const d=Math.ceil(r/o),l=d*Math.ceil(Math.sqrt(o));Me(e,t,n,l,this.compareMinX);for(let h=t;h<=n;h+=l){const u=Math.min(h+l-1,n);Me(e,h,u,d,this.compareMinY);for(let x=h;x<=u;x+=d){const f=Math.min(x+d-1,u);a.children.push(this._build(e,x,f,s-1))}}return et(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 d=0;d<t.children.length;d++){const l=t.children[d],h=Tt(l),u=gr(e,l)-h;u<o?(o=u,r=h<r?h:r,a=l):u===o&&h<r&&(r=h,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),at(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=nt(n.children.splice(o,n.children.length-o));a.height=n.height,a.leaf=n.leaf,et(n,this.toBBox),et(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(n,a)}_splitRoot(e,t){this.data=nt([e,t]),this.data.height=e.height+1,this.data.leaf=!1,et(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 d=ot(e,0,a,this.toBBox),l=ot(e,a,n,this.toBBox),h=pr(d,l),u=Tt(d)+Tt(l);h<r?(r=h,s=a,o=u<o?u:o):h===r&&u<o&&(o=u,s=a)}return s||n-t}_chooseSplitAxis(e,t,n){const s=e.leaf?this.compareMinX:xr,r=e.leaf?this.compareMinY:fr,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=ot(e,0,t,r),a=ot(e,n-t,n,r);let d=gt(o)+gt(a);for(let l=t;l<n-t;l++){const h=e.children[l];at(o,e.leaf?r(h):h),d+=gt(o)}for(let l=n-t-1;l>=t;l--){const h=e.children[l];at(a,e.leaf?r(h):h),d+=gt(a)}return d}_adjustParentBBoxes(e,t,n){for(let s=n;s>=0;s--)at(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():et(e[t],this.toBBox)}}function ur(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 et(i,e){ot(i,0,i.children.length,e,i)}function ot(i,e,t,n,s){s||(s=nt(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];at(s,i.leaf?n(o):o)}return s}function at(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 xr(i,e){return i.minX-e.minX}function fr(i,e){return i.minY-e.minY}function Tt(i){return(i.maxX-i.minX)*(i.maxY-i.minY)}function gt(i){return i.maxX-i.minX+(i.maxY-i.minY)}function gr(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 pr(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 Bt(i,e){return i.minX<=e.minX&&i.minY<=e.minY&&e.maxX<=i.maxX&&e.maxY<=i.maxY}function pt(i,e){return e.minX<=i.maxX&&e.minY<=i.maxY&&e.maxX>=i.minX&&e.maxY>=i.minY}function nt(i){return{children:i,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Me(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;tn(i,o,e,t,s),r.push(e,o,o,t)}}const rt={minX:0,minY:0,maxX:0,maxY:0},kt=(i,e)=>i.id===e.id;class mr extends hr{constructor(t){super();S(this,"store");S(this,"onRotationChange",()=>{const t=this.store.getState().getAllFeatures().filter(n=>(c.isText(n)||c.isComment(n))&&this.isVisible(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)&&this.isVisible(n)});for(const n of t)this.updateRotatedText(n)});S(this,"isVisible",t=>this.store.getState().options.isVisible(t));S(this,"rebuild",t=>{this.clear();for(const n of Object.values(t))this.isVisible(n)&&(c.isText(n)||c.isComment(n)?this.updateRotatedText(n):this.insert(n))});this.store=t,this.store.subscribe(n=>n.features,this.rebuild),this.store.subscribe(n=>n.options.isVisible,()=>this.rebuild(this.store.getState().features)),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];if(o){if(!this.isVisible(o)){this.remove(o,kt);return}c.updateBbox(o),c.isText(o)||c.isComment(o)?this.updateRotatedText(o):(this.remove(o,kt),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 u;const n=this.store.getState();this.remove(t,kt);const s=c.getBoxCenter(t);let{width:r,height:o}=c.getBoxSize(t);if(((u=t.properties.style)==null?void 0:u.fixedSize)===!0){const x=n.invZoom;r*=x,o*=x}const d=r/2,l=o/2,h=n.getRotatedBBox(s.x-d,s.y-l,s.x+d,s.y+l);this.insert({...t,geometry:{...t.geometry,bbox:h.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 rt.minX=n[0],rt.minY=n[1],rt.maxX=n[2],rt.maxY=n[3],rt}query(t){return super.search(t)}}class en{constructor(e,t){S(this,"layer");this.ogma=e,this.store=t}destroy(){}}const we=[[-.5,-.5],[.5,-.5],[.5,.5],[-.5,.5]];class Sr extends en{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:d}=n,l=this.handleRadius*s;t.fillStyle=this.handleFill,t.lineWidth=this.handleStrokeWidth*s,t.strokeStyle=this.handleStroke,Object.values(d).forEach(h=>{if(!n.isSelected(h.id))return;const u=a[h.id]?{...h,...a[h.id]}:h,x=n.options.isEditable(u);if(c.isArrow(u))this.renderArrowHandles(u,t,l,r,x);else if(c.isBox(u)||c.isText(u)){const f=c.isText(u)?o:0;this.renderOutline(u,t,f,r,n.zoom),x&&this.renderBoxHandles(u,t,l,r,f)}else c.isPolygon(u)&&this.renderPolygonHandles(u,t,l,r,n.drawingFeature===u.id,x)})});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),this.layer.element.style.zIndex="1000"}renderOutline(t,n,s,r,o){var p,A;const a=c.isText(t)&&((p=t.properties.style)==null?void 0:p.fixedSize);let{width:d,height:l}=c.getBoxSize(t);a&&(d/=o,l/=o);const h=c.getBoxPosition(t,a,o),u=d/2,x=l/2,f=h.x+u,g=h.y+x;n.save(),n.translate(f,g),n.rotate(s);const m=(A=t.properties.style)==null?void 0:A.borderRadius;if(m&&m>0?(Dn(n,-u,-x,d,l,m),n.stroke()):n.strokeRect(-u,-x,d,l),r>=4&&r<8){let y,F,b,C;const E=m&&m>0?m:this.handleRadius/o;switch(r){case 4:y=-u+E,F=-x,b=u-E,C=-x;break;case 5:y=u,F=-x+E,b=u,C=x-E;break;case 6:y=u-E,F=x,b=-u+E,C=x;break;case 7:y=-u,F=x-E,b=-u,C=-x+E;break}n.lineWidth=this.handleStrokeWidth*this.handleMagnifier/o,n.beginPath(),n.moveTo(y,F),n.lineTo(b,C),n.stroke(),n.lineWidth=this.handleStrokeWidth}n.restore()}renderArrowHandles(t,n,s,r,o){var f,g,m,p;const a=c.getArrowStart(t),d=c.getArrowEnd(t),l=+(r===0),h=+(r===1),u=s*(1+(this.handleMagnifier-1)*l),x=s*(1+(this.handleMagnifier-1)*h);n.beginPath(),n.moveTo(a.x,a.y),n.lineTo(d.x,d.y),n.closePath(),n.stroke(),o&&(n.beginPath(),((g=(f=t.properties.link)==null?void 0:f.start)==null?void 0:g.type)!=="comment"&&(n.moveTo(a.x-u,a.y-u),n.rect(a.x-u,a.y-u,u*2,u*2)),((p=(m=t.properties.link)==null?void 0:m.end)==null?void 0:p.type)!=="comment"&&(n.moveTo(d.x-x,d.y-x),n.rect(d.x-x,d.y-x,x*2,x*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:d}=c.getBoxSize(t),l=c.getBoxPosition(t),h=a/2,u=d/2,x=l.x+h,f=l.y+u;n.save(),n.translate(x,f),n.rotate(o),n.beginPath();for(let m=0;m<we.length;m++){const[p,A]=we[m],y=a*p,F=d*A,b=r===m?s*this.handleMagnifier:s;n.rect(y-b,F-b,b*2,b*2)}n.closePath(),n.fill(),n.stroke(),n.restore()}renderPolygonHandles(t,n,s,r,o,a){const d=t.geometry.coordinates[0];if(!o&&(d.length>2&&(n.save(),n.strokeStyle=this.handleStroke,n.lineWidth=this.handleStrokeWidth/this.store.getState().zoom,this.drawSmoothPolygon(n,d,.5),n.stroke(),n.restore()),!!a)){n.beginPath();for(let l=0;l<d.length-1;l++){const[h,u]=d[l],x=r===l?s*this.handleMagnifier:s;n.moveTo(h+x,u),n.arc(h,u,x,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 d=r[(a-1+o)%o],l=r[a],h=r[(a+1)%o],u=r[(a+2)%o],x=l[0]+(h[0]-d[0])/6*s,f=l[1]+(h[1]-d[1])/6*s,g=h[0]-(u[0]-l[0])/6*s,m=h[1]-(u[1]-l[1])/6*s;a===0&&t.moveTo(l[0],l[1]),t.bezierCurveTo(x,f,g,m,h[0],h[1])}t.closePath()}destroy(){this.layer.destroy(),super.destroy()}}const Er=.5;function Fr(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 ve(i,e){return!i||i==="none"?0:i==="dot"?e*2:i==="halo-dot"?e*4:i==="arrow"||i==="arrow-plain"?e:0}function yr(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 Ar(i,e,t,n,s,r,o=!1){const{start:a,end:d}=c.getArrowEndPoints(e),l=e.properties.style||c.defaultArrowStyle,{tail:h,strokeWidth:u=0,head:x,strokeColor:f,strokeType:g}=l,m=c.subtract(d,a),p=Re(e)||o?1/r.zoom:1,A=Fr(e,u,t,n)*p,y=yr(s,e.id),F=y.firstChild,b=f||"none";F.setAttribute("stroke",b),F.setAttribute("stroke-width",`${p*u}`),F.setAttribute("fill","none"),F.setAttribute("stroke-linecap","round"),F.setAttribute("stroke-linejoin","round");const C=ve(h,u*p),E=ve(x,u*p),N=c.normalize(m),D=c.add(a,c.mul(N,C)),v=c.add(d,c.mul(N,-E)),T=`M ${D.x} ${D.y} L ${v.x} ${v.y}`;F.setAttribute("d",T);const w=y.children[1];w.innerHTML="",g==="dashed"?F.setAttribute("stroke-dasharray","5,10"):F.removeAttribute("stroke-dasharray"),Te(w,a,m,b,h,u,p,A),Te(w,d,c.invert(m),b,x,u,p,A),y.setAttribute("transform",`rotate(${-r.rotation*(180/Math.PI)})`);const L=_e(e);return(!y.parentNode||y.parentNode!==i||r.selectedFeatures.has(e.id)||L!==void 0&&r.selectedFeatures.has(L))&&c.bringToTop(i,y),y}function Te(i,e,t,n,s,r,o,a){s==="halo-dot"&&Be(i,e,Cr(n),Er,r*o*4),(s==="dot"||s==="halo-dot")&&Be(i,e,n,1,r*o*2),(s==="arrow"||s==="arrow-plain")&&Nr(i,e,t,n,s==="arrow-plain",r*o,a)}function Cr(i){return i==="none"?"none":i}function Be(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 Nr(i,e,t,n,s,r,o){const a=c.mul(c.normalize(t),o),d=c.add(e,c.rotateRadians(a,Math.PI/6)),l=c.add(e,c.rotateRadians(a,-Math.PI/6)),h=c.createSVGElement("path"),u=`${e.x} ${e.y}`,x=`M ${d.x} ${d.y} L ${u} L ${l.x} ${l.y}${s?" Z":""}`;h.setAttribute("d",x),h.setAttribute("stroke",n),h.setAttribute("stroke-width",`${r}`),h.setAttribute("fill",s?n:"none"),h.setAttribute("stroke-linecap","round"),h.setAttribute("stroke-linejoin","round"),i.appendChild(h)}function br(){const i=c.createSVGElement("style");return i.textContent=`
7
10
  /* Comment Animation Styles */
8
11
  .comment-icon {
9
12
  transition:
@@ -80,7 +83,4 @@
80
83
  .comment-edit-button:hover {
81
84
  opacity: 1;
82
85
  }
83
- `,i}function es(i,e,t){const n={...l.defaultCommentStyle,...e.properties.style},s=n.iconSize,{iconColor:r=l.defaultCommentStyle.iconColor,iconSymbol:o=l.defaultCommentStyle.iconSymbol,iconBorderColor:a=l.defaultCommentStyle.iconBorderColor,iconBorderWidth:u=l.defaultCommentStyle.iconBorderWidth}=n;let d=i.querySelector("rect");d||(d=l.createSVGElement("rect"),d.setAttribute("x",`${-s/2}`),d.setAttribute("y",`${-s/2}`),d.setAttribute("rx",`${n.borderRadius}`),d.setAttribute("ry",`${n.borderRadius}`),i.appendChild(d)),d.setAttribute("width",`${s}`),d.setAttribute("height",`${s}`),t.hoveredFeature===e.id?d.setAttribute("fill",l.brighten(r)):d.setAttribute("fill",r),u&&u>0?(d.setAttribute("stroke",a||"#CCC"),d.setAttribute("stroke-width",`${u}`)):(d.removeAttribute("stroke"),d.removeAttribute("stroke-width"));let c=i.querySelector("text");c||(c=l.createSVGElement("text"),c.setAttribute("x","0"),c.setAttribute("y","0"),c.setAttribute("text-anchor","middle"),c.setAttribute("dominant-baseline","central"),c.setAttribute("pointer-events","none"),i.appendChild(c)),c.setAttribute("font-size",`${s*.5}`),c.textContent=o}function ns(i,e,t,n=!1){const s={...l.defaultCommentStyle,...e.properties.style},{font:r="Arial, sans-serif",fontSize:o=12,padding:a=8,background:u="#FFFACD",color:d="#333",borderRadius:c=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,A=f?p>f:!1,E=e.properties.content||"";i.innerHTML="";const y=-g/2,D=-m/2,C=l.createSVGElement("rect");C.setAttribute("x",`${y}`),C.setAttribute("y",`${D}`),C.setAttribute("width",`${g}`),C.setAttribute("height",`${m}`),C.setAttribute("rx",`${c}`),C.setAttribute("ry",`${c}`),C.setAttribute("fill",t.hoveredFeature===e.id?l.brighten(u):u),x&&x>0&&(C.setAttribute("stroke",h||"#DDD"),C.setAttribute("stroke-width",`${x}`)),i.appendChild(C);const F=l.createSVGElement("foreignObject");F.setAttribute("x",`${y}`),F.setAttribute("y",`${D}`),F.setAttribute("width",`${g}`),F.setAttribute("height",`${m}`),F.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))*l.TEXT_LINE_HEIGHT}px`,N.style.color=d,N.style.overflowY=A?"auto":"hidden",N.style.overflowX="hidden",N.style.overflowWrap="break-word",N.style.whiteSpace="pre-wrap",N.style.pointerEvents="none",N.innerHTML=ss(E),F.appendChild(N),i.appendChild(F),n){const b=l.createSVGElement("foreignObject");b.setAttribute("x",`${y+g-24-4}`),b.setAttribute("y",`${D+m-24-4}`),b.setAttribute("width","24"),b.setAttribute("height","24");const B=document.createElement("div");B.classList.add("ogma-send-button"),B.style.width="100%",B.style.height="100%",B.style.display="flex",B.style.alignItems="center",B.style.justifyContent="center",B.style.boxSizing="border-box",B.style.background=u,B.style.border=`1px solid ${h||"#DDD"}`,B.style.borderRadius="4px",B.style.pointerEvents="auto";const L=document.createElement("span");L.classList.add("ogma-send-button-icon"),L.innerHTML=t.options.editButtonIcon,B.appendChild(L),b.appendChild(B),i.appendChild(b)}s.shadow!==!1?i.setAttribute("filter","url(#softShadow)"):i.removeAttribute("filter")}function ss(i){if(!i)return"";let e=i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return e=e.replace(Fe(),`<a href="$1" class="${Pt}" target="_blank" rel="noopener noreferrer">$1</a>`),e}function is(i,e,t,n,s){const r=e.properties.mode;let o=t;o||(o=l.createSVGElement("g"),o.setAttribute("data-annotation",`${e.id}`),o.setAttribute("data-annotation-type","comment"));let a=o.querySelector(".comment-icon");a||(a=l.createSVGElement("g"),a.classList.add("comment-icon"),o.appendChild(a));let u=o.querySelector(".comment-box");u||(u=l.createSVGElement("g"),u.classList.add("comment-box"),o.appendChild(u));const d=r!==l.COMMENT_MODE_COLLAPSED&&n.selectedFeatures.has(e.id)&&n.editingFeature!==e.id&&n.options.showEditButton;es(a,e,n),ns(u,e,n,d),s?o.classList.remove("comment-no-transition"):o.classList.add("comment-no-transition"),r===l.COMMENT_MODE_COLLAPSED?(o.classList.add("comment-collapsed"),o.classList.remove("comment-expanded")):(o.classList.add("comment-expanded"),o.classList.remove("comment-collapsed"));const c=l.getBoxCenter(e);return o.setAttribute("transform",n.getScreenAlignedTransform(c.x,c.y,!1)),o.style.visibility=n.editingFeature===e.id?"hidden":"",(!o.parentNode||o.parentNode!==i)&&i.appendChild(o),o}function rs(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],d=n[(o+1)%s],c=n[(o+2)%s],h=u[0]+(d[0]-a[0])/6*e,x=u[1]+(d[1]-a[1])/6*e,f=d[0]-(c[0]-u[0])/6*e,g=d[1]-(c[1]-u[1])/6*e;o===0&&r.push(`M${u[0]},${u[1]}`),t&&o===s-1?r.push(`L${d[0]},${d[1]}`):r.push(`C${h},${x} ${f},${g} ${d[0]},${d[1]}`)}return r.push("Z"),r.join(" ")}const os=(i,e,t="box")=>(i||(i=l.createSVGElement("g"),i.setAttribute("data-annotation",`${e}`),i.classList.add(`annotation-${t}`)),i);function as(i,e,t,n){const s=os(t,e.id.toString(),e.properties.type);s.setAttribute("data-annotation",String(e.id));let r=s.querySelector("path");r||(r=l.createSVGElement("path"),s.appendChild(r));const{strokeColor:o=l.defaultPolygonStyle.strokeColor,strokeWidth:a=l.defaultPolygonStyle.strokeWidth,background:u=l.defaultPolygonStyle.background,strokeType:d=l.defaultPolygonStyle.strokeType}=e.properties.style||l.defaultPolygonStyle;o&&r.setAttribute("stroke",o),a!==void 0&&r.setAttribute("stroke-width",String(a)),u&&(n.hoveredFeature===e.id?r.setAttribute("fill",l.brighten(u)):r.setAttribute("fill",u)),d==="dashed"?r.setAttribute("stroke-dasharray","5,5"):r.removeAttribute("stroke-dasharray");const c=e.geometry.coordinates[0],h=rs(c,.5,n.drawingFeature===e.id);return r.setAttribute("d",h),s.setAttribute("transform",n.getRotationTransform(0,0)),i.appendChild(s),s}const cs=["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"],ne=[[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 ls(i){if(i<=255)return cs[i];let e=0,t=ne.length-1;for(;e<=t;){const n=e+t>>1,s=ne[n];if(i<s[0]){t=n-1;continue}if(i>s[1]){e=n+1;continue}return s[2]}return"L"}function ds(i){const e=i.length;if(e===0)return null;const t=new Array(e);let n=!1;for(let d=0;d<e;){const c=i.charCodeAt(d);let h=c,x=1;if(c>=55296&&c<=56319&&d+1<e){const g=i.charCodeAt(d+1);g>=56320&&g<=57343&&(h=(c-55296<<10)+(g-56320)+65536,x=2)}const f=ls(h);(f==="R"||f==="AL"||f==="AN")&&(n=!0);for(let g=0;g<x;g++)t[d+g]=f;d+=x}if(!n)return null;let s=0;for(let d=0;d<e;d++){const c=t[d];if(c==="L"){s=0;break}if(c==="R"||c==="AL"){s=1;break}}const r=new Int8Array(e);for(let d=0;d<e;d++)r[d]=s;const o=s&1?"R":"L",a=o;let u=a;for(let d=0;d<e;d++)t[d]==="NSM"?t[d]=u:u=t[d];u=a;for(let d=0;d<e;d++){const c=t[d];c==="EN"?t[d]=u==="AL"?"AN":"EN":(c==="R"||c==="L"||c==="AL")&&(u=c)}for(let d=0;d<e;d++)t[d]==="AL"&&(t[d]="R");for(let d=1;d<e-1;d++)t[d]==="ES"&&t[d-1]==="EN"&&t[d+1]==="EN"&&(t[d]="EN"),t[d]==="CS"&&(t[d-1]==="EN"||t[d-1]==="AN")&&t[d+1]===t[d-1]&&(t[d]=t[d-1]);for(let d=0;d<e;d++){if(t[d]!=="EN")continue;let c;for(c=d-1;c>=0&&t[c]==="ET";c--)t[c]="EN";for(c=d+1;c<e&&t[c]==="ET";c++)t[c]="EN"}for(let d=0;d<e;d++){const c=t[d];(c==="WS"||c==="ES"||c==="ET"||c==="CS")&&(t[d]="ON")}u=a;for(let d=0;d<e;d++){const c=t[d];c==="EN"?t[d]=u==="L"?"L":"EN":(c==="R"||c==="L")&&(u=c)}for(let d=0;d<e;d++){if(t[d]!=="ON")continue;let c=d+1;for(;c<e&&t[c]==="ON";)c++;const h=d>0?t[d-1]:a,x=c<e?t[c]:a,f=h!=="L"?"R":"L";if(f===(x!=="L"?"R":"L"))for(let p=d;p<c;p++)t[p]=f;d=c-1}for(let d=0;d<e;d++)t[d]==="ON"&&(t[d]=o);for(let d=0;d<e;d++){const c=t[d];(r[d]&1)===0?c==="R"?r[d]++:(c==="AN"||c==="EN")&&(r[d]+=2):(c==="L"||c==="AN"||c==="EN")&&r[d]++}return r}function us(i,e){const t=ds(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 hs=/[ \t\n\r\f]+/g,xs=/[\t\n\r\f]| {2,}|^ | $/;function fs(i){const e=i??"normal";return e==="pre-wrap"?{mode:e,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:e,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function gs(i){if(!xs.test(i))return i;let e=i.replace(hs," ");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 ps(i){return/[\r\f]/.test(i)?i.replace(/\r\n/g,`
84
- `).replace(/[\r\f]/g,`
85
- `):i}let Et=null,ms;function Ss(){return Et===null&&(Et=new Intl.Segmenter(ms,{granularity:"word"})),Et}const Es=new RegExp("\\p{Script=Arabic}","u"),X=new RegExp("\\p{M}","u"),Rt=new RegExp("\\p{Nd}","u");function se(i){return Es.test(i)}function ie(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(ie(s))return!0;e++;continue}}if(ie(t))return!0}}return!1}function Fs(i){const e=st(i);return e!==null&&(_t.has(e)||U.has(e))}const As=new Set([" "," ","⁠","\uFEFF"]),ys=new Set(["-","‐","–","—"]);function Cs(i){const e=st(i);return e!==null&&As.has(e)}function Ns(i){const e=st(i);return e!==null&&ys.has(e)}function Ds(i,e){return Cs(i)?!1:e?!(Fs(i)||Ns(i)):!0}const _t=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),dt=new Set(['"',"(","[","{","¡","¿","“","‘","‚","„","«","‹","⸘","(","〔","〈","《","「","『","【","〖","〘","〚"]),Ht=new Set(["'","’"]),U=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),Ms=new Set([":",".","،","؛"]),ws=new Set(["၏"]),bs=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function Bs(i){if(It(i))return!0;let e=!1;for(const t of i){if(U.has(t)||ht(t)){e=!0;continue}if(!(e&&X.test(t)))return!1}return e}function Ts(i){for(const e of i)if(!_t.has(e)&&!U.has(e))return!1;return i.length>0}function vs(i){if(It(i))return!0;for(const e of i)if(!dt.has(e)&&!Ht.has(e)&&!X.test(e)&&!ht(e))return!1;return i.length>0}function It(i){let e=!1;for(const t of i)if(!(t==="\\"||X.test(t))){if(dt.has(t)||U.has(t)||Ht.has(t)){e=!0;continue}return!1}return e}function ut(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 st(i){if(i.length===0)return null;const e=ut(i,i.length);return i.slice(e)}function ks(i){for(const e of i)if(!X.test(e))return e;return null}function Ls(i){for(let e=i.length;e>0;){const t=ut(i,e),n=i.slice(t,e);if(!X.test(n))return n;e=t}return null}const Ps=[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 Os(i,e){for(let t=0;t<e.length;t+=2)if(i>=e[t]&&i<=e[t+1])return!0;return!1}function ht(i){const e=i.codePointAt(0);return e!==void 0&&Os(e,Ps)}function Rs(i){const e=Ls(i);return e!==null&&ht(e)}function _s(i){const e=ks(i);return e!==null&&Rt.test(e)}function Hs(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(dt.has(n)||Ht.has(n)){t--;continue}break}return t<=0||t===e.length?null:{head:e.slice(0,t).join(""),tail:e.slice(t).join("")}}function Is(i,e,t){return t==="text"&&!e&&i.length===1&&i!=="-"&&i!=="—"?i:null}function re(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 oe(i,e){return i&&e!==null&&Ms.has(e)}function Gs(i){const e=st(i);return e!==null&&ws.has(e)}function zs(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 wt(i){let e=i.length;for(;e>0;){const t=ut(i,e),n=i.slice(t,e);if(bs.has(n))return!0;if(!U.has(n))return!1;e=t}return!1}function Ys(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 Ws=/[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;function G(i){return i.length===1?i[0]:i.join("")}function $s(i,e){const t=[];for(let n=i.length-1;n>=0;n--)t.push(i[n]);return t.push(e),G(t)}function Us(i,e,t,n){if(!Ws.test(i))return[{text:i,isWordLike:e,kind:"text",start:t}];const s=[];let r=null,o=[],a=t,u=!1,d=0;for(const c of i){const h=Ys(c,n),x=h==="text"&&e;if(r!==null&&h===r&&x===u){o.push(c),d+=c.length;continue}r!==null&&s.push({text:G(o),isWordLike:u,kind:r,start:a}),r=h,o=[c],a=t+d,u=x,d+=c.length}return r!==null&&s.push({text:G(o),isWordLike:u,kind:r,start:a}),s}function bt(i){return i==="space"||i==="preserved-space"||i==="zero-width-break"||i==="hard-break"}const Xs=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function Vs(i,e){const t=i.texts[e];return t.startsWith("www.")?!0:Xs.test(t)&&e+1<i.len&&i.kinds[e+1]==="text"&&i.texts[e+1]==="//"}function js(i){return i.includes("?")&&(i.includes("://")||i.startsWith("www."))}function qs(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"||!Vs(i,o))continue;const a=[e[o]];let u=o+1;for(;u<i.len&&!bt(n[u]);){a.push(e[u]),t[o]=!0;const d=e[u].includes("?");if(n[u]="text",e[u]="",u++,d)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 Ks(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]),!js(o))continue;const a=r+1;if(a>=i.len||bt(i.kinds[a]))continue;const u=[],d=i.starts[a];let c=a;for(;c<i.len&&!bt(i.kinds[c]);)u.push(i.texts[c]),c++;u.length>0&&(e.push(G(u)),t.push(!0),n.push("text"),s.push(d),r=c-1)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}const Zs=new Set([":","-","/","×",",",".","+","–","—"]),Js=new Set([".",",",":",";"]);function ae(i){for(let e=i.length;e>0;){const t=ut(i,e),n=i.slice(t,e);if(X.test(n)){e=t;continue}return Js.has(n)||ht(n)}return!1}function Qs(i,e){return e&&!z(i)}function we(i){for(const e of i)if(Rt.test(e))return!0;return!1}function ct(i){if(i.length===0)return!1;for(const e of i)if(!(Rt.test(e)||Zs.has(e)))return!1;return!0}function ti(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"&&ct(o)&&we(o)){const u=[o];let d=r+1;for(;d<i.len&&i.kinds[d]==="text"&&ct(i.texts[d]);)u.push(i.texts[d]),d++;e.push(G(u)),t.push(!0),n.push("text"),s.push(i.starts[r]),r=d-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"&&ae(o)&&(u||Rs(o))&&!z(o)){const d=[o];let c=!0,h=r+1;for(;c&&h<i.len&&i.kinds[h]==="text"&&Qs(i.texts[h],i.isWordLike[h]);){const x=i.texts[h];d.push(x),c=ae(x),h++}e.push(G(d)),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 ni(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 d=0;d<a.length;d++){const c=a[d];if(!u)break;(c.length===0||!we(c)||!ct(c))&&(u=!1)}if(u){let d=0;for(let c=0;c<a.length;c++){const h=a[c],x=c<a.length-1?`${h}-`:h;e.push(x),t.push(!0),n.push("text"),s.push(i.starts[r]+d),d+=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 si(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],d=i.starts[r];if(u==="glue"){const c=[o[0]],h=d;for(r++;r<i.len&&i.kinds[r]==="glue";)c.push(i.texts[r]),r++;const x=G(c);if(r<i.len&&i.kinds[r]==="text")o[0]=x,o.push(i.texts[r]),a=i.isWordLike[r],u="text",d=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 c=[];for(;r<i.len&&i.kinds[r]==="glue";)c.push(i.texts[r]),r++;const h=G(c);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(d)}return{len:e.length,texts:e,isWordLike:t,kinds:n,starts:s}}function ii(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=Hs(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 ri(i,e,t){const n=Ss();let s=0;const r=[],o=[],a=[],u=[],d=[],c=[],h=[],x=[],f=[],g=[],p=[],m=[];for(const F of n.segment(i))for(const N of Us(F.segment,F.isWordLike??!1,F.index,t)){let k=function(){c[w]!==null&&(o[w]=[re(r,c,h,w)],c[w]=null),o[w].push(N.text),a[w]=a[w]||N.isWordLike,x[w]=x[w]||b,f[w]=f[w]||B,g[w]=P,p[w]=R,m[w]=oe(f[w],L)};const M=N.kind==="text",T=Is(N.text,N.isWordLike,N.kind),b=z(N.text),B=se(N.text),L=st(N.text),P=wt(N.text),R=Gs(N.text),w=s-1;e.carryCJKAfterClosingQuote&&M&&s>0&&u[w]==="text"&&b&&x[w]&&g[w]||M&&s>0&&u[w]==="text"&&Ts(N.text)&&x[w]||M&&s>0&&u[w]==="text"&&p[w]?k():M&&s>0&&u[w]==="text"&&N.isWordLike&&B&&m[w]?(k(),a[w]=!0):T!==null&&s>0&&u[w]==="text"&&c[w]===T?h[w]=(h[w]??1)+1:M&&!N.isWordLike&&s>0&&u[w]==="text"&&!x[w]&&(Bs(N.text)||N.text==="-"&&a[w])?k():(r[s]=N.text,o[s]=[N.text],a[s]=N.isWordLike,u[s]=N.kind,d[s]=N.start,c[s]=T,h[s]=T===null?0:1,x[s]=b,f[s]=B,g[s]=P,p[s]=R,m[s]=oe(B,L),s++)}for(let F=0;F<s;F++){if(c[F]!==null){r[F]=re(r,c,h,F);continue}r[F]=G(o[F])}for(let F=1;F<s;F++)u[F]==="text"&&!a[F]&&It(r[F])&&u[F-1]==="text"&&!x[F-1]&&(r[F-1]+=r[F],a[F-1]=a[F-1]||a[F],r[F]="");const A=Array.from({length:s},()=>null);let E=-1;for(let F=s-1;F>=0;F--){const N=r[F];if(N.length!==0){if(u[F]==="text"&&!a[F]&&E>=0&&u[E]==="text"&&(vs(N)||N==="-"&&_s(r[E]))){const M=A[E]??[];M.push(N),A[E]=M,d[E]=d[F],r[F]="";continue}E=F}}for(let F=0;F<s;F++){const N=A[F];N!=null&&(r[F]=$s(N,r[F]))}let y=0;for(let F=0;F<s;F++){const N=r[F];N.length!==0&&(y!==F&&(r[y]=N,a[y]=a[F],u[y]=u[F],d[y]=d[F]),y++)}r.length=y,a.length=y,u.length=y,d.length=y;const D=si({len:y,texts:r,isWordLike:a,kinds:u,starts:d}),C=ii(ei(ni(ti(Ks(qs(D))))));for(let F=0;F<C.len-1;F++){const N=zs(C.texts[F]);N!==null&&(C.kinds[F]!=="space"&&C.kinds[F]!=="preserved-space"||C.kinds[F+1]!=="text"||!se(C.texts[F+1])||(C.texts[F]=N.space,C.isWordLike[F]=!1,C.kinds[F]=C.kinds[F]==="preserved-space"?"preserved-space":"space",C.texts[F+1]=N.marks+C.texts[F+1],C.starts[F+1]=C.starts[F]+N.space.length))}return C}function oi(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 ai(i,e,t){if(e.len<=1)return e;const n=[],s=[],r=[],o=[];let a=-1,u=!1;function d(x){n.push(e.texts[x]),s.push(e.isWordLike[x]),r.push("text"),o.push(e.starts[x])}function c(x,f){let g=!1;for(let A=x;A<f;A++)g=g||e.isWordLike[A];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?d(a):c(a,x);else for(let f=a;f<x;f++)d(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&&!Ds(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 ci(i,e,t="normal",n="normal"){const s=fs(t),r=s.mode==="pre-wrap"?ps(i):gs(i);if(r.length===0)return{normalized:r,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};const o=ri(r,e,s),a=n==="keep-all"?ai(r,o,e.breakKeepAllAfterPunctuation):o;return{normalized:r,chunks:oi(a,s),...a}}let j=null;const ce=new Map;let q=null;const li=96,di=new RegExp("\\p{Emoji_Presentation}","u"),ui=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;let Ft=null;const le=new Map;function Gt(){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 hi(i){let e=ce.get(i);return e||(e=new Map,ce.set(i,e)),e}function W(i,e){let t=e.get(i);return t===void 0&&(t={width:Gt().measureText(i).width,containsCJK:z(i)},e.set(i,t)),t}function xt(){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 xi(i){const e=i.match(/(\d+(?:\.\d+)?)\s*px/);return e?parseFloat(e[1]):16}function be(){return Ft===null&&(Ft=new Intl.Segmenter(void 0,{granularity:"grapheme"})),Ft}function fi(i){return di.test(i)||i.includes("️")}function gi(i){return ui.test(i)}function pi(i,e){let t=le.get(i);if(t!==void 0)return t;const n=Gt();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 le.set(i,t),t}function mi(i){let e=0;const t=be();for(const n of t.segment(i))fi(n.segment)&&e++;return e}function Si(i,e){return e.emojiCount===void 0&&(e.emojiCount=mi(i)),e.emojiCount}function $(i,e,t){return t===0?e.width:e.width-Si(i,e)*t}function Ei(i,e,t,n,s){if(e.breakableFitAdvances!==void 0&&e.breakableFitMode===s)return e.breakableFitAdvances;e.breakableFitMode=s;const r=be(),o=[];for(const c of r.segment(i))o.push(c.segment);if(o.length<=1)return e.breakableFitAdvances=null,e.breakableFitAdvances;if(s==="sum-graphemes"){const c=[];for(const h of o){const x=W(h,t);c.push($(h,x,n))}return e.breakableFitAdvances=c,e.breakableFitAdvances}if(s==="pair-context"||o.length>li){const c=[];let h=null,x=0;for(const f of o){const g=W(f,t),p=$(f,g,n);if(h===null)c.push(p);else{const m=h+f,A=W(m,t);c.push($(m,A,n)-x)}h=f,x=p}return e.breakableFitAdvances=c,e.breakableFitAdvances}const a=[];let u="",d=0;for(const c of o){u+=c;const h=W(u,t),x=$(u,h,n);a.push(x-d),d=x}return e.breakableFitAdvances=a,e.breakableFitAdvances}function Fi(i,e){const t=Gt();t.font=i;const n=hi(i),s=xi(i),r=e?pi(i,s):0;return{cache:n,fontSize:s,emojiCorrection:r}}function Ai(i){return i==="space"||i==="zero-width-break"||i==="soft-hyphen"}function Be(i){return i==="space"||i==="preserved-space"||i==="tab"||i==="zero-width-break"||i==="soft-hyphen"}function Te(i,e,t=i.widths.length){for(;e<t;){const n=i.kinds[e];if(!Ai(n))break;e++}return e}function yi(i,e){if(e<=0)return 0;const t=i%e;return Math.abs(t)<=1e-6?e:e-t}function Ci(i,e,t){return i.letterSpacing!==0&&e&&i.spacingGraphemeCounts[t]>0?i.letterSpacing:0}function zt(i,e){return e===0?0:i+e}function Ni(i,e){return i.letterSpacing!==0&&i.spacingGraphemeCounts[e]>0?i.letterSpacing:0}function Di(i,e,t,n,s){const r=e==="tab"?s+Ni(i,t):i.lineEndFitAdvances[t];return zt(n,r)}function de(i,e,t,n){const s=e==="tab"?0:i.lineEndFitAdvances[t];return zt(n,s)}function ue(i,e,t,n,s){const r=e==="tab"?s:i.lineEndPaintAdvances[t];return zt(n,r)}function Mi(i,e,t){return i.letterSpacing!==0&&e?t+i.letterSpacing:t}function wi(i,e){return i.letterSpacing===0?e:e+i.letterSpacing}function bi(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 Bi(i,e,t,n,s,r){return e+bi(i,t,n,s,r)}function Ti(i,e,t){const{widths:n,kinds:s,breakableFitAdvances:r}=i;if(n.length===0)return 0;const a=xt().lineFitEpsilon,u=e+a;let d=0,c=0,h=!1,x=0,f=0,g=0,p=0,m=-1,A=0;function E(){m=-1,A=0}function y(T=g,b=p,B=c){d++,t==null||t(B,x,f,T,b),c=0,h=!1,E()}function D(T,b){h=!0,x=T,f=0,g=T+1,p=0,c=b}function C(T,b,B){h=!0,x=T,f=b,g=T,p=b+1,c=B}function F(T,b){if(!h){D(T,b);return}c+=b,g=T+1,p=0}function N(T,b){const B=r[T];for(let L=b;L<B.length;L++){const P=B[L];h?c+P>u?(y(),C(T,L,P)):(c+=P,g=T,p=L+1):C(T,L,P)}h&&g===T&&p===B.length&&(g=T+1,p=0)}let M=0;for(;M<n.length&&!(!h&&(M=Te(i,M),M>=n.length));){const T=n[M],b=s[M],B=Be(b);if(!h){T>u&&r[M]!==null?N(M,0):D(M,T),B&&(m=M+1,A=c-T),M++;continue}if(c+T>u){if(B){F(M,T),y(M+1,0,c-T),M++;continue}if(m>=0){if(g>m||g===m&&p>0){y();continue}y(m,0,A);continue}if(T>u&&r[M]!==null){y(),N(M,0),M++;continue}y();continue}F(M,T),B&&(m=M+1,A=c-T),M++}return h&&y(),d}function vi(i,e,t){if(i.simpleLineWalkFastPath)return Ti(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=xt(),d=u.lineFitEpsilon,c=e+d;let h=0,x=0,f=!1,g=0,p=0,m=0,A=0,E=-1,y=0,D=0,C=null;function F(){E=-1,y=0,D=0,C=null}function N(){return C==="soft-hyphen"&&E===m&&A===0?D:x}function M(w=m,k=A,v){h++,t!==void 0&&t(Bi(i,v??N(),g,p,w,k),g,p,w,k),x=0,f=!1,F()}function T(w,k){f=!0,g=w,p=0,m=w+1,A=0,x=k}function b(w,k,v){f=!0,g=w,p=k,m=w,A=k+1,x=v}function B(w,k){if(!f){T(w,k);return}x+=k,m=w+1,A=0}function L(w,k,v,O,_,I){if(!k)return;const H=de(i,w,v,_),Y=ue(i,w,v,_,O);E=v+1,y=x-I+H,D=x-I+Y,C=w}function P(w,k){const v=r[w];for(let O=k;O<v.length;O++){const _=v[O];if(!f)b(w,O,_);else{const I=Mi(i,!0,_),H=x+I;wi(i,H)>c?(M(),b(w,O,_)):(x=H,m=w,A=O+1)}}f&&m===w&&A===v.length&&(m=w+1,A=0)}function R(w){h++,t==null||t(0,w.startSegmentIndex,0,w.consumedEndSegmentIndex,0),F()}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,A=0,F();let v=k.startSegmentIndex;for(;v<k.endSegmentIndex&&!(!f&&(v=Te(i,v,k.endSegmentIndex),v>=k.endSegmentIndex));){const O=s[v],_=Be(O),I=Ci(i,f,v),H=O==="tab"?yi(x+I,i.tabStopAdvance):n[v],Y=I+H,ft=Di(i,O,v,I,H);if(O==="soft-hyphen"){f&&(m=v+1,A=0,E=v+1,y=x+o,D=x+o,C=O),v++;continue}if(!f){ft>c&&r[v]!==null?P(v,0):T(v,H),L(O,_,v,H,I,Y),v++;continue}if(x+ft>c){const Le=x+de(i,O,v,I),Pe=x+ue(i,O,v,I,H);if(C==="soft-hyphen"&&u.preferEarlySoftHyphenBreak&&y<=c){M(E,0,D);continue}if(_&&Le<=c){B(v,Y),M(v+1,0,Pe),v++;continue}if(E>=0&&y<=c){if(m>E||m===E&&A>0){M();continue}const Yt=E;M(Yt,0,D),v=Yt;continue}if(ft>c&&r[v]!==null){M(),P(v,0),v++;continue}M();continue}B(v,Y),L(O,_,v,H,I,Y),v++}if(f){const O=E===k.consumedEndSegmentIndex?D:x;M(k.consumedEndSegmentIndex,0,O)}}return h}let At=null,he=new WeakMap;function ki(){return At===null&&(At=new Intl.Segmenter(void 0,{granularity:"grapheme"})),At}function xe(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 Li(i,e,t){return t>e&&i[t-1]==="soft-hyphen"}function fe(i,e,t,n){for(let s=t;s<n;s++)i+=e[s];return i}function Pi(i){let e=he.get(i);return e!==void 0||(e=new Map,he.set(i,e)),e}function Oi(i,e,t,n,s,r){let o="";const a=Li(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 d=xe(u,i.segments,e);o=fe(o,d,n,d.length)}else o+=i.segments[u];if(r>0){a&&(o+="-");const u=xe(s,i.segments,e);o=fe(o,u,t===s?n:0,r)}else a&&(o+="-");return o}let yt=null;function ve(){return yt===null&&(yt=new Intl.Segmenter(void 0,{granularity:"grapheme"})),yt}function Ri(i){return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]}}function _i(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 d(h,x,f){n=[h],s=x,r=f,o=wt(h),a=dt.has(h)}function c(h,x){n.push(h),r=r||x;const f=wt(h);h.length===1&&U.has(h)?o=o||f:o=f,a=!1}for(const h of ve().segment(i)){const x=h.segment,f=z(x);if(n.length===0){d(x,h.index,f);continue}if(a||_t.has(x)||U.has(x)||e.carryCJKAfterClosingQuote&&f&&o){c(x,f);continue}if(!r&&!f){c(x,f);continue}u(),d(x,h.index,f)}return u(),t}function ge(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=ve();for(const s of n.segment(i))t++;return t}function Hi(i,e,t){return e>1?i+(e-1)*t:i}function Ii(i,e,t,n,s){const r=xt(),{cache:o,emojiCorrection:a}=Fi(e,gi(i.normalized)),u=$("-",W("-",o),a)+(s===0?0:s*2),c=$(" ",W(" ",o),a)*8,h=s!==0;if(i.len===0)return Ri();const x=[],f=[],g=[],p=[];let m=i.chunks.length<=1&&!h;const A=t?[]:null,E=[],y=[],D=t?[]:null,C=Array.from({length:i.len});function F(b,B,L,P,R,w,k,v){R!=="text"&&R!=="space"&&R!=="zero-width-break"&&(m=!1),x.push(B),f.push(L),g.push(P),p.push(R),A==null||A.push(w),E.push(k),h&&y.push(v),D!==null&&D.push(b)}function N(b,B,L,P,R){const w=W(b,o),k=h?ge(b,B):0,v=Hi($(b,w,a),k,s),O=B==="space"||B==="preserved-space"||B==="zero-width-break"?0:v,_=O===0?0:O+(k>0?s:0),I=B==="space"||B==="zero-width-break"?0:v;if(R&&P&&b.length>1){let H="sum-graphemes";s!==0?H="segment-prefixes":ct(b)?H="pair-context":r.preferPrefixWidthsForBreakableRuns&&(H="segment-prefixes");const Y=Ei(b,w,o,a,H);F(b,v,_,I,B,L,Y,k);return}F(b,v,_,I,B,L,null,k)}for(let b=0;b<i.len;b++){C[b]=x.length;const B=i.texts[b],L=i.isWordLike[b],P=i.kinds[b],R=i.starts[b];if(P==="soft-hyphen"){F(B,0,u,u,P,R,null,0);continue}if(P==="hard-break"){F(B,0,0,0,P,R,null,0);continue}if(P==="tab"){F(B,0,0,0,P,R,null,h?ge(B,P):0);continue}const w=W(B,o);if(P==="text"&&w.containsCJK){const v=_i(B,r);for(let O=0;O<v.length;O++){const _=v[O];N(_.text,"text",R+_.start,L,!z(_.text))}continue}N(B,P,R,L,!0)}const M=Gi(i.chunks,C,x.length),T=A===null?null:us(i.normalized,A);return D!==null?{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:p,simpleLineWalkFastPath:m,segLevels:T,breakableFitAdvances:E,letterSpacing:s,spacingGraphemeCounts:y,discretionaryHyphenWidth:u,tabStopAdvance:c,chunks:M,segments:D}:{widths:x,lineEndFitAdvances:f,lineEndPaintAdvances:g,kinds:p,simpleLineWalkFastPath:m,segLevels:T,breakableFitAdvances:E,letterSpacing:s,spacingGraphemeCounts:y,discretionaryHyphenWidth:u,tabStopAdvance:c,chunks:M}}function Gi(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 zi(i,e,t,n){const s=n==null?void 0:n.wordBreak,r=(n==null?void 0:n.letterSpacing)??0,o=ci(i,xt(),n==null?void 0:n.whiteSpace,s);return Ii(o,e,t,s,r)}function Yi(i,e,t){return zi(i,e,!0,t)}function Wi(i,e,t,n,s,r,o){return{text:Oi(i,e,n,s,r,o),width:t,start:{segmentIndex:n,graphemeIndex:s},end:{segmentIndex:r,graphemeIndex:o}}}function $i(i,e,t){const n=[];if(i.widths.length===0)return{lineCount:0,height:0,lines:n};const s=Pi(i),r=vi(i,e,(o,a,u,d,c)=>{n.push(Wi(i,s,o,a,u,d,c))});return{lineCount:r,height:r*t,lines:n}}function Ui(i,e,t,n){const{width:s,height:r}=l.getBoxSize(e),{color:o=l.defaultTextStyle.color,strokeColor:a=l.defaultTextStyle.strokeColor,strokeWidth:u=l.defaultTextStyle.strokeWidth,strokeType:d=l.defaultTextStyle.strokeType,background:c=l.defaultTextStyle.background,borderRadius:h=l.defaultTextStyle.borderRadius,fixedSize:x=l.defaultTextStyle.fixedSize}=e.properties.style||l.defaultTextStyle,f=Me(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 y=g.nextSibling;g.nodeType===1&&g.tagName!=="rect"&&f.removeChild(g),g=y}let p=f.firstChild;p||(p=l.createSVGElement("rect"),f.appendChild(p));const m=-s/2,A=-r/2;h&&(p.setAttribute("rx",`${h}`),p.setAttribute("ry",`${h}`)),d&&d!=="none"&&(p.setAttribute("stroke",a||"black"),p.setAttribute("stroke-width",`${u}`),d==="dashed"&&p.setAttribute("stroke-dasharray","5,5")),c&&c.length&&(n.hoveredFeature===e.id?p.setAttribute("fill",l.brighten(c)):p.setAttribute("fill",c)),p.setAttribute("width",`${s}`),p.setAttribute("height",`${r}`);const E=l.getBoxCenter(e);return p.setAttribute("x",`${m}`),p.setAttribute("y",`${A}`),Vi(e,f,m,A),f.setAttribute("transform",n.getScreenAlignedTransform(E.x,E.y,!x)),i.appendChild(f),f}let Q=null;const pe=new Map;function Xi(i,e){const t=`${i}|${e}`,n=pe.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 pe.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 Vi(i,e,t=0,n=0){const{width:s,height:r}=l.getBoxSize(i),{fontSize:o=l.defaultTextStyle.fontSize,font:a=l.defaultTextStyle.font,padding:u=0}=i.properties.style||{};if(s===r&&s===0)return;const d=parseFloat(o.toString())*l.TEXT_LINE_HEIGHT,c=`${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=Yi(f,c,{whiteSpace:"pre-wrap",wordBreak:"normal"}),{lines:p}=$i(g,h,d),m=Math.max(1,Math.floor(x/d)),A=p.slice(0,m);if(p.length>m&&A.length>0){const D=A[A.length-1];A[A.length-1]={...D,text:D.text.trimEnd()+"…"}}const E=l.createSVGElement("text");E.setAttribute("font-size",`${parseFloat(o.toString())}`),E.setAttribute("font-family",`${a}`),E.setAttribute("transform",`translate(${t+u}, ${n+u})`);const y=Xi(c,d);A.forEach((D,C)=>{const F=l.createSVGElement("tspan");F.setAttribute("x","0"),F.setAttribute("dy",`${C===0?y:d}`);let N=0,M;const T=Fe();for(;(M=T.exec(D.text))!==null;){M.index>N&&F.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",Pt),b.textContent=M[0],F.appendChild(b),N=M.index+M[0].length}N<D.text.length&&F.appendChild(document.createTextNode(D.text.slice(N))),E.appendChild(F)}),e.appendChild(E)}class ji extends De{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=l.createSVGElement("g"),this.commentsRoot=l.createSVGElement("g"),this.annotationsRoot=l.createSVGElement("g"),this.shapesRoot=l.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,d=this.commentsRoot,c=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),l.isBox(g)||l.isPolygon(g)))continue;let p=this.features.get(g.id);l.isText(g)?p=Ui(c,g,p,h):l.isComment(g)?p=is(d,g,p,h,this.visibleFeatures.has(g.id)):l.isArrow(g)&&(p=Kn(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=l.createSVGElement("g"),t.appendChild(this.underGraphRoot)),t.removeChild(this.underGraphRoot);const a=this.underGraphRoot,u=this.store.getState(),d=this.getViewportBounds();for(let c of Object.values(n)){if(!(l.isBox(c)||l.isPolygon(c))||(s[c.id]&&(c={...c,...s[c.id]}),!this.isExporting&&!this.isFeatureVisible(c,d)))continue;let h=this.features.get(c.id);l.isBox(c)?h=Me(a,c,h,u):l.isPolygon(c)&&(h=as(a,c,h,u)),h&&this.features.set(c.id,h)}this.applyStateClasses(a,r,o),t.appendChild(a)});S(this,"throttleRender",l.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},l.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}),d=t.view.screenToGraphCoordinates({x:0,y:r*o}),c=t.view.screenToGraphCoordinates({x:s*o,y:r*o});return[Math.min(a.x,u.x,d.x,c.x),Math.min(a.y,u.y,d.y,c.y),Math.max(a.x,u.x,d.x,c.x),Math.max(a.y,u.y,d.y,c.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=l.createSVGElement("defs");t.appendChild(ts());const n=l.createSVGElement("filter");n.setAttribute("id","softShadow"),n.setAttribute("x","-50%"),n.setAttribute("y","-50%"),n.setAttribute("width","200%"),n.setAttribute("height","200%");const s=l.createSVGElement("feGaussianBlur");s.setAttribute("in","SourceAlpha"),s.setAttribute("stdDeviation","2"),s.setAttribute("result","blur");const r=l.createSVGElement("feOffset");r.setAttribute("in","blur"),r.setAttribute("dx","0"),r.setAttribute("dy","1"),r.setAttribute("result","offsetBlur");const o=l.createSVGElement("feComponentTransfer");o.setAttribute("in","offsetBlur"),o.setAttribute("result","shadow");const a=l.createSVGElement("feFuncA");a.setAttribute("type","linear"),a.setAttribute("slope","0.25"),o.appendChild(a);const u=l.createSVGElement("feMerge"),d=l.createSVGElement("feMergeNode");d.setAttribute("in","shadow");const c=l.createSVGElement("feMergeNode");return c.setAttribute("in","SourceGraphic"),u.appendChild(d),u.appendChild(c),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 me=i=>{let e;const t=new Set,n=(d,c)=>{const h=typeof d=="function"?d(e):d;if(!Object.is(h,e)){const x=e;e=c??(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:d=>(t.add(d),()=>t.delete(d))},u=e=i(n,s,a);return a},ke=i=>i?me(i):me;var Se=(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 d=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),c=r().pastStates.splice(-o,o),h=c.shift();i(h),s({pastStates:r().pastStates,futureStates:r().futureStates.concat(((u=t==null?void 0:t.diff)==null?void 0:u.call(t,d,h))||d,c.reverse())})}},redo:(o=1)=>{var a,u;if(r().futureStates.length){const d=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),c=r().futureStates.splice(-o,o),h=c.shift();i(h),s({pastStates:r().pastStates.concat(((u=t==null?void 0:t.diff)==null?void 0:u.call(t,d,h))||d,c.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,d)=>{var c,h;t!=null&&t.limit&&r().pastStates.length>=(t==null?void 0:t.limit)&&r().pastStates.shift(),(h=(c=r())._onSave)==null||h.call(c,o,u),s({pastStates:r().pastStates.concat(d||o),futureStates:[]})}}),qi=(i,e)=>(n,s,r)=>{var d,c;r.temporal=ke(((d=e==null?void 0:e.wrapTemporal)==null?void 0:d.call(e,Se(n,s,e)))||Se(n,s,e));const o=((c=e==null?void 0:e.handleSet)==null?void 0:c.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 Ki=i=>(e,t,n)=>{const s=n.subscribe;return n.subscribe=(o,a,u)=>{let d=o;if(a){const c=(u==null?void 0:u.equalityFn)||Object.is;let h=o(n.getState());d=x=>{const f=o(x);if(!c(h,f)){const g=h;a(h=f,g)}},u!=null&&u.fireImmediately&&a(h,h)}return s(d)},i(e,t,n)},Zi=Ki,Ji=[0,0,0,0];function Qi(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 tr=i=>{const e=ke()(Zi(qi((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)??l.DEFAULT_SEND_ICON,showEditButton:(i==null?void 0:i.showEditButton)??!0,editButtonIcon:(i==null?void 0:i.editButtonIcon)??l.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=>{var x,f,g,p;const o=r.features[s];if(!o)return r;const{features:a,liveUpdates:u}=r,d=new Set([s]);if((l.isComment(o)||l.isText(o))&&Object.values(a).forEach(m=>{var A,E,y,D;l.isArrow(m)&&(((E=(A=m.properties.link)==null?void 0:A.end)==null?void 0:E.id)===s||((D=(y=m.properties.link)==null?void 0:y.start)==null?void 0:D.id)===s)&&d.add(m.id)}),l.isArrow(o)){const m=((f=(x=o.properties.link)==null?void 0:x.end)==null?void 0:f.type)==="comment"?o.properties.link.end.id:((p=(g=o.properties.link)==null?void 0:g.start)==null?void 0:p.type)==="comment"?o.properties.link.start.id:null;if(m){let A=0;if(Object.values(r.features).forEach(E=>{var y,D,C,F;l.isArrow(E)&&E.id!==s&&(((D=(y=E.properties.link)==null?void 0:y.end)==null?void 0:D.id)===m||((F=(C=E.properties.link)==null?void 0:C.start)==null?void 0:F.id)===m)&&A++}),A===0)return console.error("Cannot delete last arrow attached to comment. Delete the comment instead."),r}}const c={...a},h={...u};return d.forEach(m=>{delete c[m],delete h[m]}),{features:c,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=[],d=Object.keys(o);s||(s=new Set(d)),d.forEach(c=>{const h=o[c];a[c]&&Object.keys(h).length>0&&(a[c]={...a[c],...h},u.push(c))}),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,d=s*u-r*a,c=s*a+r*u,h=o?1:this.invZoom;return`matrix(${h}, 0, 0, ${h}, ${d}, ${c})`},getRotationTransform(s,r){const o=this.revSin,a=this.revCos,u=s*a-r*o,d=s*o+r*a;return`matrix(${a}, ${o}, ${-o}, ${a}, ${-u}, ${-d})`},getRotatedBBox(s,r,o,a){return l.getAABB(s,r,o-s,a-r,this.sin,this.cos,s+(o-s)/2,r+(a-r)/2,Ji)},setDrawingPoints:s=>t({drawingPoints:s})}),{limit:250,partialize:t=>({drawingFeature:t.drawingFeature,isDragging:t.isDragging,features:t.features,lastChangedFeatures:t.lastChangedFeatures}),equality:Qi,handleSet:t=>n=>{n.drawingFeature===null&&t(n)}})));return e},er={detectMargin:2,magnetHandleRadius:5,magnetRadius:10,textPlaceholder:"Type here",showSendButton:!0,sendButtonIcon:l.DEFAULT_SEND_ICON,showEditButton:!0,editButtonIcon:l.DEFAULT_EDIT_ICON,minArrowHeight:20,maxArrowHeight:30};class nr extends Ge{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=tr(s),this.index=new Un(this.store),this.snapping=new Rn(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 yn(this.ogma,this.snapping,this.store,(r,o)=>{this.emit(l.EVT_LINK,{arrow:r,link:o})}),this.interactions=new _n(this.ogma,this.store,this.index),this.editor=new Sn(this.ogma,this.store,this.snapping,this.links,this.interactions),this.drawing=new sn(this.ogma,this.store,this.editor,this.interactions,this.links,this,this.index),this.selectionManager=new on(this.store),this.historyManager=new rn(this.store,this.links),this.updateManager=new an(this.store),this.commentManager=new Ze(this.store),this.initializeRenderers(),this.setupEvents()}initializeRenderers(){this.renderers.shapes=new ji(this.ogma,this.store),this.renderers.handles=new Xn(this.ogma,this.store)}setupEvents(){this.ogma.events.on("rotate",this.onRotate).on("zoom",this.onZoom).on("layoutEnd",this.onLayout),this.editor.addEventListener(l.EVT_DRAG_START,t=>this.emit(l.EVT_DRAG_START,{id:t.detail.id,position:t.detail.position})),this.editor.addEventListener(l.EVT_DRAG_END,t=>this.emit(l.EVT_DRAG_END,{id:t.detail.id,position:t.detail.position})),this.interactions.addEventListener(l.EVT_CLICK,(t=>this.emit(l.EVT_CLICK,{id:t.detail.id,position:t.detail.position}))),this.store.temporal.subscribe(t=>{this.emit(l.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(l.EVT_SELECT,{ids:s}),n){const r=Array.from(n).filter(o=>!t.has(o));r.length>0&&this.emit(l.EVT_UNSELECT,{ids:r})}}),this.store.subscribe(t=>t.drawingFeature,(t,n)=>{t===null&&n!==null&&this.emit(l.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(l.EVT_UPDATE,t[s]):this.emit(l.EVT_ADD,{id:s});for(const s of Object.keys(n))t[s]||this.emit(l.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(l.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),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=l.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=l.COMMENT_MODE_COLLAPSED;exports.COMMENT_MODE_EXPANDED=l.COMMENT_MODE_EXPANDED;exports.DATA_ATTR=l.DATA_ATTR;exports.DEFAULT_EDIT_ICON=l.DEFAULT_EDIT_ICON;exports.DEFAULT_SEND_ICON=l.DEFAULT_SEND_ICON;exports.EVT_ADD=l.EVT_ADD;exports.EVT_CANCEL_DRAWING=l.EVT_CANCEL_DRAWING;exports.EVT_CLICK=l.EVT_CLICK;exports.EVT_COMPLETE_DRAWING=l.EVT_COMPLETE_DRAWING;exports.EVT_DRAG=l.EVT_DRAG;exports.EVT_DRAG_END=l.EVT_DRAG_END;exports.EVT_DRAG_START=l.EVT_DRAG_START;exports.EVT_HISTORY=l.EVT_HISTORY;exports.EVT_HOVER=l.EVT_HOVER;exports.EVT_LINK=l.EVT_LINK;exports.EVT_REMOVE=l.EVT_REMOVE;exports.EVT_SELECT=l.EVT_SELECT;exports.EVT_UNHOVER=l.EVT_UNHOVER;exports.EVT_UNSELECT=l.EVT_UNSELECT;exports.EVT_UPDATE=l.EVT_UPDATE;exports.HL_BRIGHTEN=l.HL_BRIGHTEN;exports.LAYERS=l.LAYERS;exports.NONE=l.NONE;exports.SIDE_END=l.SIDE_END;exports.SIDE_START=l.SIDE_START;exports.TARGET_TYPES=l.TARGET_TYPES;exports.TEXT_LINE_HEIGHT=l.TEXT_LINE_HEIGHT;exports.adjustColorBrightness=l.adjustColorBrightness;exports.brighten=l.brighten;exports.calculateCommentZoomThreshold=l.calculateCommentZoomThreshold;exports.clientToContainerPosition=l.clientToContainerPosition;exports.colorToRgba=l.colorToRgba;exports.createArrow=l.createArrow;exports.createBox=l.createBox;exports.createComment=l.createComment;exports.createCommentWithArrow=l.createCommentWithArrow;exports.createPolygon=l.createPolygon;exports.createSVGElement=l.createSVGElement;exports.createText=l.createText;exports.cursors=l.cursors;exports.darken=l.darken;exports.debounce=l.debounce;exports.debounceTail=l.debounceTail;exports.defaultArrowOptions=l.defaultArrowOptions;exports.defaultArrowStyle=l.defaultArrowStyle;exports.defaultBoxOptions=l.defaultBoxOptions;exports.defaultBoxStyle=l.defaultBoxStyle;exports.defaultCommentOptions=l.defaultCommentOptions;exports.defaultCommentStyle=l.defaultCommentStyle;exports.defaultPolygonProperties=l.defaultPolygonProperties;exports.defaultPolygonStyle=l.defaultPolygonStyle;exports.defaultTextOptions=l.defaultTextOptions;exports.defaultTextStyle=l.defaultTextStyle;exports.detectArrow=l.detectArrow;exports.detectBox=l.detectBox;exports.detectComment=l.detectComment;exports.detectPolygon=l.detectPolygon;exports.detectText=l.detectText;exports.getAnnotationsBounds=l.getAnnotationsBounds;exports.getArrowEnd=l.getArrowEnd;exports.getArrowEndPoints=l.getArrowEndPoints;exports.getArrowSide=l.getArrowSide;exports.getArrowStart=l.getArrowStart;exports.getAttachmentPointOnNode=l.getAttachmentPointOnNode;exports.getBbox=l.getBbox;exports.getBoxCenter=l.getBoxCenter;exports.getBoxPosition=l.getBoxPosition;exports.getBoxSize=l.getBoxSize;exports.getBrowserWindow=l.getBrowserWindow;exports.getCommentPosition=l.getCommentPosition;exports.getCommentSize=l.getCommentSize;exports.getCommentZoomThreshold=l.getCommentZoomThreshold;exports.getCoordinates=l.getCoordinates;exports.getHandleId=l.getHandleId;exports.getTextBbox=l.getBbox;exports.getTextPosition=l.getBoxPosition;exports.getTextSize=l.getBoxSize;exports.handleDetectionThreshold=l.handleDetectionThreshold;exports.handleRadius=l.handleRadius;exports.hexShortToLong=l.hexShortToLong;exports.hexToRgba=l.hexToRgba;exports.isArrow=l.isArrow;exports.isBox=l.isBox;exports.isComment=l.isComment;exports.isPolygon=l.isPolygon;exports.isText=l.isText;exports.migrateBoxOrTextIfNeeded=l.migrateBoxOrTextIfNeeded;exports.parseColor=l.parseColor;exports.rgbToRgba=l.rgbToRgba;exports.scaleGeometry=l.scaleGeometry;exports.setArrowEnd=l.setArrowEnd;exports.setArrowEndPoint=l.setArrowEndPoint;exports.setArrowStart=l.setArrowStart;exports.setBbox=l.setBbox;exports.setTextBbox=l.setBbox;exports.throttle=l.throttle;exports.toggleCommentMode=l.toggleCommentMode;exports.updateBbox=l.updateBbox;exports.updateTextBbox=l.updateBbox;exports.Control=nr;exports.asColor=Ve;exports.asHexColor=je;exports.asRgbColor=qe;exports.asRgbaColor=Ke;exports.canDetachArrowEnd=cn;exports.canDetachArrowStart=ye;exports.getPolygonBounds=Dt;exports.getPolygonCenter=Bt;exports.isAnnotationCollection=Mt;exports.isColor=Ee;exports.isCommentArrow=Ae;exports.isHexColor=vt;exports.isRgbColor=kt;exports.isRgbaColor=Lt;exports.scalePolygon=Xe;exports.simplifyPolygon=Nt;exports.translatePolygon=Ue;exports.updatePolygonBbox=Tt;
86
+ `,i}function Dr(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:d=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),d&&d>0?(l.setAttribute("stroke",a||"#CCC"),l.setAttribute("stroke-width",`${d}`)):(l.removeAttribute("stroke"),l.removeAttribute("stroke-width"));let h=i.querySelector("text");h||(h=c.createSVGElement("text"),h.setAttribute("x","0"),h.setAttribute("y","0"),h.setAttribute("text-anchor","middle"),h.setAttribute("dominant-baseline","central"),h.setAttribute("pointer-events","none"),i.appendChild(h)),h.setAttribute("font-size",`${s*.5}`),h.textContent=o}function Mr(i,e,t,n=!1){const s={...c.defaultCommentStyle,...e.properties.style},{font:r="Arial, sans-serif",fontSize:o=12,padding:a=8,background:d="#FFFACD",color:l="#333",borderRadius:h=4,strokeColor:u="#DDD",strokeWidth:x=1,maxHeight:f}=s,g=e.properties.width,m=e.properties.height,p=f?Math.min(m,f):m,A=f?m>f:!1,y=e.properties.content||"";i.innerHTML="";const F=-g/2,b=-p/2,C=c.createSVGElement("rect");C.setAttribute("x",`${F}`),C.setAttribute("y",`${b}`),C.setAttribute("width",`${g}`),C.setAttribute("height",`${p}`),C.setAttribute("rx",`${h}`),C.setAttribute("ry",`${h}`),C.setAttribute("fill",t.hoveredFeature===e.id?c.brighten(d):d),x&&x>0&&(C.setAttribute("stroke",u||"#DDD"),C.setAttribute("stroke-width",`${x}`)),i.appendChild(C);const E=c.createSVGElement("foreignObject");E.setAttribute("x",`${F}`),E.setAttribute("y",`${b}`),E.setAttribute("width",`${g}`),E.setAttribute("height",`${p}`),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=A?"auto":"hidden",N.style.overflowX="hidden",N.style.overflowWrap="break-word",N.style.whiteSpace="pre-wrap",N.style.pointerEvents="none",N.innerHTML=wr(y),E.appendChild(N),i.appendChild(E),n){const T=c.createSVGElement("foreignObject");T.setAttribute("x",`${F+g-24-4}`),T.setAttribute("y",`${b+p-24-4}`),T.setAttribute("width","24"),T.setAttribute("height","24");const w=document.createElement("div");w.classList.add("ogma-send-button"),w.style.width="100%",w.style.height="100%",w.style.display="flex",w.style.alignItems="center",w.style.justifyContent="center",w.style.boxSizing="border-box",w.style.background=d,w.style.border=`1px solid ${u||"#DDD"}`,w.style.borderRadius="4px",w.style.pointerEvents="auto";const L=document.createElement("span");L.classList.add("ogma-send-button-icon"),L.innerHTML=t.options.editButtonIcon,w.appendChild(L),T.appendChild(w),i.appendChild(T)}s.shadow!==!1?i.setAttribute("filter","url(#softShadow)"):i.removeAttribute("filter")}function wr(i){if(!i)return"";let e=i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return e=e.replace(Pe(),`<a href="$1" class="${Vt}" target="_blank" rel="noopener noreferrer">$1</a>`),e}function vr(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 d=o.querySelector(".comment-box");d||(d=c.createSVGElement("g"),d.classList.add("comment-box"),o.appendChild(d));const l=r!==c.COMMENT_MODE_COLLAPSED&&n.selectedFeatures.has(e.id)&&n.editingFeature!==e.id&&n.options.showEditButton&&n.options.isEditable(e);Dr(a,e,n),Mr(d,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 h=c.getBoxCenter(e);return o.setAttribute("transform",n.getScreenAlignedTransform(h.x,h.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 Tr(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],d=n[o],l=n[(o+1)%s],h=n[(o+2)%s],u=d[0]+(l[0]-a[0])/6*e,x=d[1]+(l[1]-a[1])/6*e,f=l[0]-(h[0]-d[0])/6*e,g=l[1]-(h[1]-d[1])/6*e;o===0&&r.push(`M${d[0]},${d[1]}`),t&&o===s-1?r.push(`L${l[0]},${l[1]}`):r.push(`C${u},${x} ${f},${g} ${l[0]},${l[1]}`)}return r.push("Z"),r.join(" ")}const Br=(i,e,t="box")=>(i||(i=c.createSVGElement("g"),i.setAttribute("data-annotation",`${e}`),i.classList.add(`annotation-${t}`)),i);function kr(i,e,t,n){const s=Br(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:d=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)),d&&(n.hoveredFeature===e.id?r.setAttribute("fill",c.brighten(d)):r.setAttribute("fill",d)),l==="dashed"?r.setAttribute("stroke-dasharray","5,5"):r.removeAttribute("stroke-dasharray");const h=e.geometry.coordinates[0],u=Tr(h,.5,n.drawingFeature===e.id);return r.setAttribute("d",u),s.setAttribute("transform",n.getRotationTransform(0,0)),i.appendChild(s),s}class Lr extends en{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,d=this.annotationsRoot,l=this.commentsRoot,h=this.shapesRoot,u=this.store.getState(),x=this.isGeoActive(),f=this.getViewportBounds();this.removeFeatures(n);const g=new Set;for(let m of Object.values(n)){if(o[m.id]&&(m={...m,...o[m.id]}),this.hideIfNotVisible(m)||!this.isExporting&&!this.isFeatureVisible(m,f)||(g.add(m.id),c.isBox(m)||c.isPolygon(m)))continue;let p=this.features.get(m.id);c.isText(m)?p=Ni(h,m,p,u,this.isExporting):c.isComment(m)?p=vr(l,m,p,u,this.visibleFeatures.has(m.id)):c.isArrow(m)&&(p=Ar(a,m,u.options.minArrowHeight,u.options.maxArrowHeight,p,u,x)),p&&this.features.set(m.id,p)}this.applyStateClasses(d,s,r),t.appendChild(d),this.visibleFeatures.clear(),this.visibleFeatures=g});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,d=this.store.getState(),l=this.getViewportBounds();for(let h of Object.values(n)){if(!(c.isBox(h)||c.isPolygon(h))||(s[h.id]&&(h={...h,...s[h.id]}),this.hideIfNotVisible(h))||!this.isExporting&&!this.isFeatureVisible(h,l))continue;let u=this.features.get(h.id);c.isBox(h)?u=Ke(a,h,u,d):c.isPolygon(h)&&(u=kr(a,h,u,d)),u&&this.features.set(h.id,u)}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}),this.store.subscribe(s=>s.options.isVisible,this.throttleRender)}isGeoActive(){try{return this.ogma.geo.enabled()}catch{return!1}}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}),d=t.view.screenToGraphCoordinates({x:s*o,y:0}),l=t.view.screenToGraphCoordinates({x:0,y:r*o}),h=t.view.screenToGraphCoordinates({x:s*o,y:r*o});return[Math.min(a.x,d.x,l.x,h.x),Math.min(a.y,d.y,l.y,h.y),Math.max(a.x,d.x,l.x,h.x),Math.max(a.y,d.y,l.y,h.y)]}isFeatureVisible(t,n){const s=t.geometry.bbox;if(!s)return!0;const[r,o,a,d]=s;return!(a<n[0]||r>n[2]||d<n[1]||o>n[3])}hideIfNotVisible(t){var s;if(this.store.getState().options.isVisible(t))return!1;const n=this.features.get(t.id);return n&&((s=n.parentNode)==null||s.removeChild(n),this.features.delete(t.id)),!0}getDefs(){const t=c.createSVGElement("defs");t.appendChild(br());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 d=c.createSVGElement("feMerge"),l=c.createSVGElement("feMergeNode");l.setAttribute("in","shadow");const h=c.createSVGElement("feMergeNode");return h.setAttribute("in","SourceGraphic"),d.appendChild(l),d.appendChild(h),n.appendChild(s),n.appendChild(r),n.appendChild(o),n.appendChild(d),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 ke=i=>{let e;const t=new Set,n=(l,h)=>{const u=typeof l=="function"?l(e):l;if(!Object.is(u,e)){const x=e;e=h??(typeof u!="object"||u===null)?u:Object.assign({},e,u),t.forEach(f=>f(e,x))}},s=()=>e,a={setState:n,getState:s,getInitialState:()=>d,subscribe:l=>(t.add(l),()=>t.delete(l))},d=e=i(n,s,a);return a},nn=i=>i?ke(i):ke;var Le=(i,e,t)=>(s,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 l=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),h=r().pastStates.splice(-o,o),u=h.shift();i(u),s({pastStates:r().pastStates,futureStates:r().futureStates.concat(((d=t==null?void 0:t.diff)==null?void 0:d.call(t,l,u))||l,h.reverse())})}},redo:(o=1)=>{var a,d;if(r().futureStates.length){const l=((a=t==null?void 0:t.partialize)==null?void 0:a.call(t,e()))||e(),h=r().futureStates.splice(-o,o),u=h.shift();i(u),s({pastStates:r().pastStates.concat(((d=t==null?void 0:t.diff)==null?void 0:d.call(t,l,u))||l,h.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,d,l)=>{var h,u;t!=null&&t.limit&&r().pastStates.length>=(t==null?void 0:t.limit)&&r().pastStates.shift(),(u=(h=r())._onSave)==null||u.call(h,o,d),s({pastStates:r().pastStates.concat(l||o),futureStates:[]})}}),Or=(i,e)=>(n,s,r)=>{var l,h;r.temporal=nn(((l=e==null?void 0:e.wrapTemporal)==null?void 0:l.call(e,Le(n,s,e)))||Le(n,s,e));const o=((h=e==null?void 0:e.handleSet)==null?void 0:h.call(e,r.temporal.getState()._handleSet))||r.temporal.getState()._handleSet,a=u=>{var g,m,p;if(!r.temporal.getState().isTracking)return;const x=((g=e==null?void 0:e.partialize)==null?void 0:g.call(e,s()))||s(),f=(m=e==null?void 0:e.diff)==null?void 0:m.call(e,u,x);f===null||(p=e==null?void 0:e.equality)!=null&&p.call(e,u,x)||o(u,void 0,x,f)},d=r.setState;return r.setState=(...u)=>{var f;const x=((f=e==null?void 0:e.partialize)==null?void 0:f.call(e,s()))||s();d(...u),a(x)},i((...u)=>{var f;const x=((f=e==null?void 0:e.partialize)==null?void 0:f.call(e,s()))||s();n(...u),a(x)},s,r)};const Pr=i=>(e,t,n)=>{const s=n.subscribe;return n.subscribe=(o,a,d)=>{let l=o;if(a){const h=(d==null?void 0:d.equalityFn)||Object.is;let u=o(n.getState());l=x=>{const f=o(x);if(!h(u,f)){const g=u;a(u=f,g)}},d!=null&&d.fireImmediately&&a(u,u)}return s(l)},i(e,t,n)},Rr=Pr,_r=[0,0,0,0];function Ir(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,d=o.geometry;if(a.coordinates!==d.coordinates||r.properties!==o.properties||r.properties.style!==o.properties.style||a!==d)return!1}return i.drawingFeature===e.drawingFeature}const Hr=i=>{const e=nn()(Rr(Or((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",authorStyle:i==null?void 0:i.authorStyle,minReadableFontSize:(i==null?void 0:i.minReadableFontSize)??2,isEditable:(i==null?void 0:i.isEditable)??(()=>!0),isVisible:(i==null?void 0:i.isVisible)??(()=>!0)},setOptions:s=>t(r=>({options:{...r.options,...s}})),removeFeature:s=>t(r=>{const o=r.features[s];if(!o)return r;if(s!==r.drawingFeature&&!r.options.isEditable(o))return console.error(`Cannot delete annotation ${s}: not editable`),r;const{features:a,liveUpdates:d}=r;if(c.isArrow(o)&&ze(a,s))return console.error("Cannot delete last arrow attached to comment. Delete the comment instead."),r;const l=He(a,s);for(const g of l){const m=a[g];if(m&&g!==r.drawingFeature&&!r.options.isEditable(m))return console.error(`Cannot delete annotation ${s}: cascade includes non-editable annotation ${g}`),r}const h={...a},u={...d};l.forEach(g=>{delete h[g],delete u[g]});const x=new Set(Array.from(l,g=>String(g))),f=new Set(Array.from(r.selectedFeatures).filter(g=>!x.has(String(g))));return{features:h,liveUpdates:u,selectedFeatures:f}}),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},d=[],l=s?Array.from(s).filter(u=>u in o):Object.keys(o);l.forEach(u=>{const x=o[u];a[u]&&Object.keys(x).length>0&&(a[u]={...a[u],...x},d.push(u))});const h={...o};l.forEach(u=>delete h[u]),t({features:a,liveUpdates:h,isDragging:Object.keys(h).length===0?!1:n().isDragging,lastChangedFeatures:d})},cancelLiveUpdates:()=>t({liveUpdates:{},isDragging:!1}),clearLiveUpdates:s=>{t(r=>{const o={...r.liveUpdates};for(const a of s)delete o[a];return{liveUpdates:o}})},updateFeature:(s,r)=>t(o=>{const a=o.features[s];if(a&&s!==o.drawingFeature&&!o.options.isEditable(a))return console.error(`Cannot update annotation ${s}: not editable`),o;const d={...o.features[s],...r},l={...o.liveUpdates};return delete l[s],{features:{...o.features,[s]:d},liveUpdates:l}}),updateFeatures:s=>t(r=>{const o={...r.features};return Object.entries(s).forEach(([a,d])=>{const l=o[a];l&&(a!==r.drawingFeature&&!r.options.isEditable(l)||(o[a]={...l,...d}))}),{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 d=r[o];return d?{...a,...d}: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,d=this.revCos,l=s*d-r*a,h=s*a+r*d,u=o?1:this.invZoom;return`matrix(${u}, 0, 0, ${u}, ${l}, ${h})`},getRotationTransform(s,r){const o=this.revSin,a=this.revCos,d=s*a-r*o,l=s*o+r*a;return`matrix(${a}, ${o}, ${-o}, ${a}, ${-d}, ${-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,_r)},setDrawingPoints:s=>t({drawingPoints:s})}),{limit:250,partialize:t=>({drawingFeature:t.drawingFeature,isDragging:t.isDragging,features:t.features,lastChangedFeatures:t.lastChangedFeatures}),equality:Ir,handleSet:t=>n=>{n.drawingFeature===null&&t(n)}})));return e},zr={detectMargin:2,magnetHandleRadius:5,magnetRadius:10,textPlaceholder:"Type here",minReadableFontSize:2,showSendButton:!0,sendButtonIcon:c.DEFAULT_SEND_ICON,showEditButton:!0,editButtonIcon:c.DEFAULT_EDIT_ICON,minArrowHeight:20,maxArrowHeight:30,isEditable:()=>!0,isVisible:()=>!0};class Gr extends dn{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={...zr,...n};this.store=Hr(s),this.index=new mr(this.store),this.snapping=new lr(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 Ki(this.ogma,this.snapping,this.store,(r,o)=>{this.emit(c.EVT_LINK,{arrow:r,link:o})}),this.interactions=new Hi(this.ogma,this.store,this.index),this.editor=new zi(this.ogma,this.store,this.snapping,this.links,this.interactions),this.drawing=new Bn(this.ogma,this.store,this.editor,this.interactions,this.links,this,this.index),this.selectionManager=new Ln(this.store),this.historyManager=new kn(this.store,this.links),this.updateManager=new On(this.store),this.commentManager=new yn(this.store),this.initializeRenderers(),this.setupEvents()}initializeRenderers(){this.renderers.shapes=new Lr(this.ogma,this.store),this.renderers.handles=new Sr(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})})}getOgma(){return this.ogma}getRotation(){return this.store.getState().rotation}getZoom(){return this.store.getState().zoom}setOptions(t={}){return this.store.getState().setOptions(t),this.store.getState().options}isAnnotationEditable(t){const n=this.store.getState().getFeature(t);return!!n&&this.store.getState().options.isEditable(n)}isAnnotationVisible(t){const n=this.store.getState().getFeature(t);return!!n&&this.store.getState().options.isVisible(n)}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.MAX_FONT_SCALE=c.MAX_FONT_SCALE;exports.MIN_FONT_SCALE=c.MIN_FONT_SCALE;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.getEffectiveFontSize=c.getEffectiveFontSize;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.isStickyNote=c.isStickyNote;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=Gr;exports.asColor=mn;exports.asHexColor=Sn;exports.asRgbColor=En;exports.asRgbaColor=Fn;exports.canDetachArrowEnd=Pn;exports.canDetachArrowStart=Ie;exports.getCascadeDeleteIds=He;exports.getCommentLeftOrphanedBy=ze;exports.getCommentLinkId=_e;exports.getPolygonBounds=zt;exports.getPolygonCenter=Gt;exports.isAnnotationCollection=Pt;exports.isColor=Oe;exports.isCommentArrow=Re;exports.isHexColor=Wt;exports.isRgbColor=Yt;exports.isRgbaColor=$t;exports.scalePolygon=pn;exports.simplifyPolygon=Ot;exports.translatePolygon=gn;exports.updatePolygonBbox=Ut;