drawui-core 0.3.4 → 0.3.5

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.cjs CHANGED
@@ -1,20 +1,20 @@
1
- 'use strict';var q={identity(){return {a:1,b:0,c:0,d:1,e:0,f:0}},translation(a,e){return {a:1,b:0,c:0,d:1,e:a,f:e}},rotation(a){let e=Math.cos(a),t=Math.sin(a);return {a:e,b:t,c:-t,d:e,e:0,f:0}},scale(a,e){return {a,b:0,c:0,d:e,e:0,f:0}},multiply(a,e){return {a:a.a*e.a+a.b*e.c,b:a.a*e.b+a.b*e.d,c:a.c*e.a+a.d*e.c,d:a.c*e.b+a.d*e.d,e:a.e*e.a+a.f*e.c+e.e,f:a.e*e.b+a.f*e.d+e.f}},apply(a,e){return {x:a.a*e.x+a.c*e.y+a.e,y:a.b*e.x+a.d*e.y+a.f}},invert(a){let e=a.a*a.d-a.b*a.c;if(Math.abs(e)<1e-10)return null;let t=1/e;return {a:a.d*t,b:-a.b*t,c:-a.c*t,d:a.a*t,e:(a.c*a.f-a.d*a.e)*t,f:(a.b*a.e-a.a*a.f)*t}},createCameraMatrix(a){let e=q.scale(a.zoom,a.zoom),t=q.translation(a.x,a.y);return q.multiply(t,e)}};var re=class{x=0;y=0;zoom=1;minZoom=.1;maxZoom=10;getMatrix(){return q.createCameraMatrix({x:this.x,y:this.y,zoom:this.zoom})}getInverseMatrix(){return q.invert(this.getMatrix())}screenToPage(e){let t=this.getInverseMatrix();return t?q.apply(t,e):e}pageToScreen(e){return q.apply(this.getMatrix(),e)}translate(e,t){this.x+=e,this.y+=t;}zoomAt(e,t){let i=this.screenToPage(e);this.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.zoom*t));let n=this.pageToScreen(i);this.x+=e.x-n.x,this.y+=e.y-n.y;}reset(){this.x=0,this.y=0,this.zoom=1;}getZoom(){return this.zoom}fitBounds(e,t=50){let i=window.innerWidth,n=window.innerHeight,s=(i-t*2)/e.width,r=(n-t*2)/e.height,o=Math.min(s,r,this.maxZoom);this.zoom=Math.max(this.minZoom,o),this.x=(i-e.width*this.zoom)/2-e.x*this.zoom,this.y=(n-e.height*this.zoom)/2-e.y*this.zoom;}};var gt={primary:"#3b82f6",selection:{outline:"#3b82f6",handleStroke:"#3b82f6",handleFill:"#ffffff",outlineFill:"rgba(59, 130, 246, 0.1)",shadow:"#3b82f6"},grid:"#e5e7eb",text:"#1f2937",editBorder:"#3b82f6",brushFill:"rgba(59, 130, 246, 0.08)",brushStroke:"rgba(59, 130, 246, 0.8)",guide:"rgba(59, 130, 246, 0.6)",lineHighlight:"rgba(59, 130, 246, 0.4)",genDot:"#3b82f6",genLine:"rgba(59, 130, 246, 0.55)"},D={...gt,selection:{...gt.selection}},Ke=new Set;function At(a){return Ke.add(a),()=>Ke.delete(a)}function Le(a){a.selection&&Object.assign(D.selection,a.selection);for(let e of Object.keys(a)){if(e==="selection")continue;let t=a[e];t!==void 0&&(D[e]=t);}Ke.forEach(e=>e());}function $t(){return D}function F(a,e){let t=pt(a);if(!t)return a;let i=parseInt(t,16),n=i>>16&255,s=i>>8&255,r=i&255;return `rgba(${n}, ${s}, ${r}, ${e})`}function Rt(a,e){let t=pt(a);if(!t)return a;let i=parseInt(t,16),n=e<0?0:255,s=Math.abs(e),r=o=>Math.round((n-o)*s+o).toString(16).padStart(2,"0");return `#${r(i>>16&255)}${r(i>>8&255)}${r(i&255)}`}function pt(a){let e=a.replace("#","").trim();return /^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/.test(e)?e.length===3?e.split("").map(t=>t+t).join(""):e:null}var N=class{context;constructor(e){this.context=e;}getCursor(e){return null}hasTransientState(){return false}cancelTransient(){return false}dispose(){}};var yt={"zh-CN":{"save.success":"\u5DF2\u4FDD\u5B58","save.fail":"\u4FDD\u5B58\u5931\u8D25","tool.select":"\u9009\u62E9\u5DE5\u5177","tool.hand":"\u62D6\u62FD\u89C6\u53E3","tool.rectangle":"\u77E9\u5F62","tool.rounded-rectangle":"\u5706\u89D2\u77E9\u5F62","tool.circle":"\u5706\u5F62","tool.ellipse":"\u692D\u5706","tool.diamond":"\u83F1\u5F62","tool.triangle":"\u4E09\u89D2\u5F62","tool.hexagon":"\u516D\u8FB9\u5F62","tool.parallelogram":"\u5E73\u884C\u56DB\u8FB9\u5F62","tool.trapezoid":"\u68AF\u5F62","tool.pentagon":"\u4E94\u8FB9\u5F62","tool.octagon":"\u516B\u8FB9\u5F62","tool.star":"\u661F\u5F62","tool.cylinder":"\u5706\u67F1\u4F53","tool.cloud":"\u4E91\u5F62","tool.heart":"\u5FC3\u5F62","tool.block-arrow-right":"\u53F3\u7BAD\u5934","tool.block-arrow-left":"\u5DE6\u7BAD\u5934","tool.block-arrow-up":"\u4E0A\u7BAD\u5934","tool.block-arrow-down":"\u4E0B\u7BAD\u5934","tool.block-arrow-double":"\u53CC\u5411\u7BAD\u5934","tool.right-triangle":"\u76F4\u89D2\u4E09\u89D2\u5F62","tool.cross":"\u5341\u5B57","tool.speech-rect":"\u65B9\u5F62\u5BF9\u8BDD\u6846","tool.speech-round":"\u5706\u5F62\u5BF9\u8BDD\u6846","tool.cube":"\u7ACB\u65B9\u4F53","tool.sector":"\u6247\u5F62","tool.delay":"D \u5F62","tool.predefined-process":"\u9884\u5B9A\u4E49\u6D41\u7A0B","tool.document":"\u6587\u6863","tool.stadium":"\u5168\u5706\u89D2\u77E9\u5F62","tool.class-catalog":"\u7C7B\u76EE","class.plain":"\u7C7B","flow.process":"\u5904\u7406","flow.step":"\u6D41\u7A0B","flow.startEnd":"\u5F00\u59CB/\u7ED3\u675F","flow.decision":"\u5224\u5B9A","flow.data":"\u6570\u636E","flow.manual":"\u624B\u52A8\u64CD\u4F5C","flow.preparation":"\u51C6\u5907","flow.database":"\u6570\u636E\u5E93","flow.delay":"\u5EF6\u65F6","shapeGroup.basic":"\u57FA\u7840","shapeGroup.flowchart":"\u6D41\u7A0B\u56FE","shapeGroup.other":"\u5176\u4ED6","shapeGroup.uml":"\u7C7B\u56FE","shapeMenu.hint":"\u60AC\u505C\u67E5\u770B\u540D\u79F0","tool.chevron":"\u5C16\u89D2","tool.brace-left":"\u5DE6\u62EC\u53F7","tool.brace-right":"\u53F3\u62EC\u53F7","tool.uml-class":"UML \u7C7B\u56FE","tool.uml-interface":"UML \u63A5\u53E3","tool.line":"\u76F4\u7EBF","tool.arrow":"\u7EBF\u6761","tool.text":"\u6587\u672C","tool.draw":"\u753B\u7B14","tool.pen":"\u753B\u7B14","tool.highlighter":"\u8367\u5149\u7B14","tool.eraser":"\u6A61\u76AE\u64E6","status.none":"\u672A\u9009\u62E9","status.selected":"\u5DF2\u9009\u62E9 {n} \u4E2A\u56FE\u5F62","toolbar.select":"\u9009\u62E9 (V)","toolbar.hand":"\u62D6\u62FD\u89C6\u53E3 (H)","toolbar.shapes":"\u5F62\u72B6","toolbar.grid":"\u7F51\u683C","toolbar.undo":"\u64A4\u9500 (Ctrl+Z)","toolbar.redo":"\u91CD\u505A (Ctrl+Shift+Z)","toolbar.arrow":"\u7BAD\u5934","toolbar.text":"\u6587\u672C","toolbar.pen":"\u753B\u7B14","toolbar.highlighter":"\u8367\u5149\u7B14","toolbar.eraser":"\u6A61\u76AE\u64E6","toolbar.uml-class":"UML \u7C7B\u56FE","toolbar.uml-interface":"UML \u63A5\u53E3","zoom.in":"\u653E\u5927","zoom.out":"\u7F29\u5C0F","zoom.reset":"\u91CD\u7F6E","style.stroke":"\u8FB9\u6846","style.line":"\u7EBF\u6761","style.fill":"\u586B\u5145","style.text":"\u6587\u5B57","style.highlight":"\u9AD8\u4EAE","style.prefix":"\u524D\u7F00\u7B26\u53F7","style.prefix.soon":"\u524D\u7F00\u7B26\u53F7\u5F00\u53D1\u4E2D\uFF0C\u656C\u8BF7\u671F\u5F85","style.none":"\u65E0","style.addColor":"\u6DFB\u52A0\u989C\u8272","style.connection":"\u8FDE\u7EBF","style.arrow":"\u7BAD\u5934","style.dashed":"\u865A\u7EBF","style.solid":"\u5B9E\u7EBF","style.opacity":"\u4E0D\u900F\u660E\u5EA6","style.connection.straight":"\u76F4\u7EBF","style.connection.polyline":"\u6298\u7EBF","style.connection.orthogonal":"\u76F4\u89D2\u6298\u7EBF","style.connection.curve":"\u66F2\u7EBF","style.arrowhead.none":"\u65E0\u7BAD\u5934","style.arrowhead.end":"\u7EC8\u70B9\u7BAD\u5934","style.arrowhead.start":"\u8D77\u70B9\u7BAD\u5934","style.arrowhead.both":"\u53CC\u7BAD\u5934","style.arrowhead.none-dashed":"\u65E0\u7BAD\u5934\u865A\u7EBF","style.arrowhead.both-dashed":"\u53CC\u7BAD\u5934\u865A\u7EBF","style.uml":"UML","style.arrowhead.inheritance":"\u7EE7\u627F","style.arrowhead.composition":"\u7EC4\u5408","style.arrowhead.aggregation":"\u805A\u5408","style.arrowhead.dependency":"\u4F9D\u8D56","style.arrowhead.realization":"\u5B9E\u73B0","menu.title":"\u9009\u62E9\u65B0\u56FE\u5F62","menu.cancel":"\u70B9\u51FB\u7A7A\u767D\u5904\u53D6\u6D88","shape.rectangle":"\u77E9\u5F62","shape.rounded-rectangle":"\u5706\u89D2","shape.circle":"\u5706\u5F62","shape.ellipse":"\u692D\u5706","shape.diamond":"\u83F1\u5F62","shape.triangle":"\u4E09\u89D2","shape.hexagon":"\u516D\u8FB9\u5F62","shape.parallelogram":"\u5E73\u884C","shape.trapezoid":"\u68AF\u5F62","shape.pentagon":"\u4E94\u8FB9\u5F62","shape.octagon":"\u516B\u8FB9\u5F62","shape.star":"\u661F\u5F62","shape.uml-class":"\u7C7B\u56FE","shape.uml-interface":"\u63A5\u53E3","uml.drag":"\u62D6\u62FD\u6392\u5E8F","uml.delete":"\u5220\u9664\u8BE5\u884C","uml.textColor":"\u6587\u5B57\u989C\u8272","uml.defaultColor":"\u9ED8\u8BA4\u989C\u8272","uml.fontSize":"\u5B57\u53F7","uml.strikethrough":"\u5220\u9664\u7EBF","uml.attribute":"\u5C5E\u6027","uml.method":"\u65B9\u6CD5","minimap.title":"\u5C0F\u5730\u56FE","minimap.expand":"\u5C55\u5F00\u5C0F\u5730\u56FE","minimap.collapse":"\u6536\u8D77\u5C0F\u5730\u56FE","tool.mind-map":"\u601D\u7EF4\u5BFC\u56FE","toolbar.mind-map":"\u601D\u7EF4\u5BFC\u56FE","toolbar.export":"\u5BFC\u51FA","toolbar.export.png":"PNG \u56FE\u7247","toolbar.export.svg":"SVG \u77E2\u91CF\u56FE","toolbar.export.pdf":"PDF \u6587\u6863","shape.mind-map":"\u601D\u7EF4\u5BFC\u56FE","mindmap.defaultRoot":"\u4E2D\u5FC3\u4E3B\u9898","mindmap.defaultBranch":"\u5206\u652F\u4E3B\u9898","mindmap.nodeText":"\u8282\u70B9\u6587\u672C","mindmap.addChild":"\u5B50\u8282\u70B9","mindmap.addSibling":"\u5144\u5F1F\u8282\u70B9","mindmap.deleteNode":"\u5220\u9664\u8282\u70B9","mindmap.color":"\u989C\u8272","mindmap.levelColor":"\u9ED8\u8BA4\u5C42\u7EA7\u8272","mindmap.icon":"\u56FE\u6807","mindmap.noIcon":"\u65E0\u56FE\u6807","mindmap.note":"\u5C5E\u6027\u8BF4\u660E","mindmap.notePlaceholder":"\u8BF4\u660E\u5185\u5BB9\uFF08\u53EF\u9009\uFF09","mindmap.noteColor":"\u8BF4\u660E\u989C\u8272","mindmap.noteColorDefault":"\u540C\u8282\u70B9\u8272","mindmap.collapse":"\u6298\u53E0","mindmap.expand":"\u5C55\u5F00","mindmap.close":"\u5173\u95ED\u7F16\u8F91","mindmap.more":"\u66F4\u591A\u8BBE\u7F6E"},"en-US":{"save.success":"Saved","save.fail":"Save failed","tool.select":"Select tool","tool.hand":"Pan view","tool.rectangle":"Rectangle","tool.rounded-rectangle":"Rounded rectangle","tool.circle":"Circle","tool.ellipse":"Ellipse","tool.diamond":"Diamond","tool.triangle":"Triangle","tool.hexagon":"Hexagon","tool.parallelogram":"Parallelogram","tool.trapezoid":"Trapezoid","tool.pentagon":"Pentagon","tool.octagon":"Octagon","tool.star":"Star","tool.cylinder":"Cylinder","tool.cloud":"Cloud","tool.heart":"Heart","tool.block-arrow-right":"Arrow right","tool.block-arrow-left":"Arrow left","tool.block-arrow-up":"Arrow up","tool.block-arrow-down":"Arrow down","tool.block-arrow-double":"Double arrow","tool.right-triangle":"Right triangle","tool.cross":"Cross","tool.speech-rect":"Speech bubble","tool.speech-round":"Round bubble","tool.cube":"Cube","tool.sector":"Sector","tool.delay":"Delay","tool.predefined-process":"Predefined process","tool.document":"Document","tool.stadium":"Stadium","tool.class-catalog":"Category","class.plain":"Class","flow.process":"Process","flow.step":"Step","flow.startEnd":"Start / End","flow.decision":"Decision","flow.data":"Data","flow.manual":"Manual operation","flow.preparation":"Preparation","flow.database":"Database","flow.delay":"Delay","shapeGroup.basic":"Basic","shapeGroup.flowchart":"Flowchart","shapeGroup.other":"Other","shapeGroup.uml":"Class diagram","shapeMenu.hint":"Hover to see name","tool.chevron":"Chevron","tool.brace-left":"Left brace","tool.brace-right":"Right brace","tool.uml-class":"UML class","tool.uml-interface":"UML interface","tool.line":"Line","tool.arrow":"Line","tool.text":"Text","tool.draw":"Pen","tool.pen":"Pen","tool.highlighter":"Highlighter","tool.eraser":"Eraser","status.none":"Nothing selected","status.selected":"{n} shapes selected","toolbar.select":"Select (V)","toolbar.hand":"Pan view (H)","toolbar.shapes":"Shapes","toolbar.grid":"Grid","toolbar.undo":"Undo (Ctrl+Z)","toolbar.redo":"Redo (Ctrl+Shift+Z)","toolbar.arrow":"Arrow","toolbar.text":"Text","toolbar.pen":"Pen","toolbar.highlighter":"Highlighter","toolbar.eraser":"Eraser","toolbar.uml-class":"UML class","toolbar.uml-interface":"UML interface","zoom.in":"Zoom in","zoom.out":"Zoom out","zoom.reset":"Reset","style.stroke":"Border","style.line":"Line","style.fill":"Fill","style.text":"Text","style.highlight":"Highlight","style.prefix":"Prefix","style.prefix.soon":"Prefix symbols are coming soon","style.none":"None","style.addColor":"Add color","style.connection":"Connection","style.arrow":"Arrow head","style.dashed":"Dashed","style.solid":"Solid","style.opacity":"Opacity","style.connection.straight":"Straight","style.connection.polyline":"Polyline","style.connection.orthogonal":"Orthogonal","style.connection.curve":"Curve","style.arrowhead.none":"None","style.arrowhead.end":"End","style.arrowhead.start":"Start","style.arrowhead.both":"Both","style.arrowhead.none-dashed":"Dashed","style.arrowhead.both-dashed":"Dashed both","style.uml":"UML","style.arrowhead.inheritance":"Inheritance","style.arrowhead.composition":"Composition","style.arrowhead.aggregation":"Aggregation","style.arrowhead.dependency":"Dependency","style.arrowhead.realization":"Realization","menu.title":"Create shape","menu.cancel":"Click empty space to cancel","shape.rectangle":"Rectangle","shape.rounded-rectangle":"Rounded","shape.circle":"Circle","shape.ellipse":"Ellipse","shape.diamond":"Diamond","shape.triangle":"Triangle","shape.hexagon":"Hexagon","shape.parallelogram":"Parallelogram","shape.trapezoid":"Trapezoid","shape.pentagon":"Pentagon","shape.octagon":"Octagon","shape.star":"Star","shape.uml-class":"Class","shape.uml-interface":"Interface","uml.drag":"Drag to reorder","uml.delete":"Delete row","uml.textColor":"Text color","uml.defaultColor":"Default color","uml.fontSize":"Font size","uml.strikethrough":"Strikethrough","uml.attribute":"Attributes","uml.method":"Methods","minimap.title":"Minimap","minimap.expand":"Expand minimap","minimap.collapse":"Collapse minimap","tool.mind-map":"Mind map","toolbar.mind-map":"Mind map","toolbar.export":"Export","toolbar.export.png":"PNG image","toolbar.export.svg":"SVG vector","toolbar.export.pdf":"PDF document","shape.mind-map":"Mind map","mindmap.defaultRoot":"Central topic","mindmap.defaultBranch":"Branch topic","mindmap.nodeText":"Node text","mindmap.addChild":"Child","mindmap.addSibling":"Sibling","mindmap.deleteNode":"Delete node","mindmap.color":"Color","mindmap.levelColor":"Default level color","mindmap.icon":"Icon","mindmap.noIcon":"No icon","mindmap.note":"Note","mindmap.notePlaceholder":"Note content (optional)","mindmap.noteColor":"Note color","mindmap.noteColorDefault":"Same as node","mindmap.collapse":"Collapse","mindmap.expand":"Expand","mindmap.close":"Close editor","mindmap.more":"More settings"}},ke="zh-CN",Fe=new Set;function Ae(a){ke!==a&&(ke=a,Fe.forEach(e=>e()));}function Ht(){return ke}function Vt(a){return Fe.add(a),()=>Fe.delete(a)}function Z(a,e){let i=yt[ke][a]??yt["zh-CN"][a];if(e)for(let[n,s]of Object.entries(e))i=i.replace(new RegExp(`\\{${n}\\}`,"g"),String(s));return i}var Ze=["#ef4444","#f59e0b","#10b981","#3b82f6","#8b5cf6","#ec4899"],J=14,Nt=40,Bt=80,_t=240;function oe(a,e){return a.color??Ze[e%Ze.length]}function ft(a){let e=a.text||"",t=0;for(let n of e)t+=/[\u2e80-\u9fff\uf900-\ufaff\uff00-\uffef\u3000-\u303f]/.test(n)?1:.6;let i=Math.max(80,Math.min(240,Math.ceil(t*14)+24));return a.icon&&(i+=26),{width:i,height:40}}function $e(a){let e={...a};return a.children&&(e.children=a.children.map(t=>$e(t))),e}function Re(a,e,t){if(a.id===e)return {...a,...t};let i=a.children??[],n=i.map(s=>Re(s,e,t));return n.some((s,r)=>s!==i[r])?{...a,children:n}:a}function je(a,e,t){if(a.id===e)return {...a,children:[...a.children??[],t],collapsed:false};let i=a.children??[],n=i.map(s=>je(s,e,t));return n.some((s,r)=>s!==i[r])?{...a,children:n}:a}function qe(a,e,t){let i=a.children??[];for(let n=0;n<i.length;n++){if(i[n].id===e){let r=[...i];return r.splice(n+1,0,t),{...a,children:r}}let s=qe(i[n],e,t);if(s!==i[n])return {...a,children:i.map(r=>r===i[n]?s:r)}}return a}function Je(a,e){if(a.id===e)return null;let t=a.children??[],i=t.map(n=>Je(n,e)).filter(n=>n!==null);return i.length!==t.length||i.some((n,s)=>n!==t[s])?{...a,children:i}:a}function Q(a,e){if(a.id===e)return a;for(let t of a.children??[]){let i=Q(t,e);if(i)return i}return null}function mt(a,e){if(a.id===e)return 0;for(let t of a.children??[]){let i=mt(t,e);if(i!==-1)return i+1}return -1}function fe(a,e){for(let t of a.children??[]){if(t.id===e)return a;let i=fe(t,e);if(i)return i}return null}function xt(a){let e=1;for(let t of a.children??[])e+=xt(t);return e}function wt(a,e){e.set(a.id,ft(a));for(let t of a.children??[])wt(t,e);}function B(a){let e=new Map;wt(a,e);let t=new Map,i=g=>{let u=g.collapsed?[]:g.children??[];if(u.length===0)t.set(g.id,e.get(g.id).height);else {let p=0;for(let y of u)p+=i(y);p+=16*(u.length-1),t.set(g.id,Math.max(e.get(g.id).height,p));}return t.get(g.id)};i(a);let n=new Map,s=(g,u,p,y)=>{let f=t.get(g.id),w=e.get(g.id);if(n.set(g.id,{x:p,y:y+f/2,depth:u,width:w.width,height:w.height}),g.collapsed)return;let x=y;for(let v of g.children??[]){let b=e.get(v.id);s(v,u+1,p+w.width/2+48+b.width/2,x),x+=t.get(v.id)+16;}};s(a,0,0,-t.get(a.id)/2);let r=1/0,o=-1/0,h=1/0,l=-1/0;n.forEach(g=>{r=Math.min(r,g.x-g.width/2),o=Math.max(o,g.x+g.width/2),h=Math.min(h,g.y-g.height/2),l=Math.max(l,g.y+g.height/2);});let c=(r+o)/2,d=(h+l)/2;return n.forEach(g=>{g.x-=c,g.y-=d;}),{positions:n,width:o-r,height:l-h}}var Ot={strokeColor:"#1f2937",fillColor:"#f8fafc",fillOpacity:.9,strokeWidth:2,strokeDash:null},Gt={rectangle:{width:120,height:60},"rounded-rectangle":{width:120,height:60,borderRadius:8},circle:{width:80,height:80},ellipse:{width:100,height:70},diamond:{width:100,height:80},triangle:{width:100,height:90},hexagon:{width:100,height:90},parallelogram:{width:120,height:60},trapezoid:{width:120,height:70},pentagon:{width:100,height:90},octagon:{width:100,height:90},star:{width:100,height:100},cylinder:{width:100,height:110},cloud:{width:140,height:90},heart:{width:100,height:95},"block-arrow-right":{width:140,height:80},"block-arrow-left":{width:140,height:80},"block-arrow-up":{width:80,height:140},"block-arrow-down":{width:80,height:140},"block-arrow-double":{width:150,height:80},"right-triangle":{width:100,height:90},cross:{width:90,height:90},"speech-rect":{width:130,height:92},"speech-round":{width:130,height:92},cube:{width:110,height:110},sector:{width:100,height:100},delay:{width:120,height:80},"predefined-process":{width:130,height:80},document:{width:120,height:90},stadium:{width:130,height:60},"class-catalog":{width:160,height:90},chevron:{width:110,height:80},"brace-left":{width:220,height:120},"brace-right":{width:220,height:120}},U=14,$=22,j=36,O=14,k=8,me=160,Ut=["rectangle","rounded-rectangle","circle","ellipse","diamond","triangle","hexagon","parallelogram","trapezoid","pentagon","octagon","star","cylinder","cloud","heart","block-arrow-right","block-arrow-left","block-arrow-up","block-arrow-down","block-arrow-double","right-triangle","cross","speech-rect","speech-round","cube","sector","delay","predefined-process","document","stadium","class-catalog","chevron","brace-left","brace-right","uml-class","uml-interface","mind-map"];function He(a){return Ut.includes(a)}function ee(a,e,t){let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=Gt[a]||{width:120,height:60},s=n.width,r=n.height,o=n.radius??s/2,h=n.borderRadius??8,l=t??{...Ot};switch(a){case "rounded-rectangle":return {id:i,type:"rounded-rectangle",x:e.x,y:e.y,width:s,height:r,borderRadius:h,rotation:0,style:l};case "circle":return {id:i,type:"circle",x:e.x,y:e.y,radius:o,rotation:0,style:l};case "ellipse":return {id:i,type:"ellipse",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "diamond":return {id:i,type:"diamond",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "triangle":return {id:i,type:"triangle",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "hexagon":return {id:i,type:"hexagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "parallelogram":return {id:i,type:"parallelogram",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "trapezoid":return {id:i,type:"trapezoid",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "pentagon":return {id:i,type:"pentagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "octagon":return {id:i,type:"octagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "star":return {id:i,type:"star",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":return {id:i,type:a,x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "uml-class":{let c="ClassName",d=[{id:`attr_${Date.now()}_1`,visibility:"+",name:"field",type:"string"}],g=[{id:`meth_${Date.now()}_1`,visibility:"+",name:"method",params:"param",returnType:"void"}],{width:u,height:p}=Ve(c,d,g);return {id:i,type:"uml-class",x:e.x,y:e.y,width:u,height:p,className:c,attributes:d,methods:g,rotation:0,style:{...l,fillColor:"#ffffff"}}}case "uml-interface":{let c="Interface",d=[{id:`meth_${Date.now()}_1`,visibility:"+",name:"method",params:"type",returnType:"type"}],g=U*.6,u=d.map(x=>`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`),p=Math.max(c.length,...u.map(x=>x.length),0),y=Math.max(me,p*g+O*2),f=d.length>0?d.length*$+k*2:k*2,w=j+f;return {id:i,type:"uml-interface",x:e.x,y:e.y,width:y,height:w,className:c,methods:d,rotation:0,style:{...l,fillColor:"#ffffff"}}}case "mind-map":{let c=p=>`mm_${p}_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,d={id:c("root"),text:Z("mindmap.defaultRoot"),children:[{id:c("b1"),text:Z("mindmap.defaultBranch")},{id:c("b2"),text:Z("mindmap.defaultBranch")},{id:c("b3"),text:Z("mindmap.defaultBranch")}]},{width:g,height:u}=B(d);return {id:i,type:"mind-map",x:e.x,y:e.y,width:g,height:u,root:d,rotation:0,style:{...l,fillColor:"#ffffff"}}}default:return {id:i,type:"rectangle",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l}}}function Ve(a,e,t){let i=U*.6,n=[a];for(let d of e)n.push(`${d.visibility} ${d.name}: ${d.type}`);for(let d of t)n.push(`${d.visibility} ${d.name}(${d.params}): ${d.returnType}`);let r=Math.max(...n.map(d=>d.length),0)*i+O*2,o=Math.max(me,r),h=e.length>0?e.length*$+k*2:k*2,l=t.length>0?t.length*$+k*2:k*2,c=j+h+l;return {width:o,height:c}}var T=class extends N{type;constructor(e,t){super(e),this.type=t;}onPointerDown(e,t){let i=ee(this.type,e);this.context.commitHistory(),this.context.addShape(i),this.context.selectShape(i.id,false);}onPointerMove(e,t){}onPointerUp(e,t){this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(e){return this.context.getMindMapCursorHitAtPoint(e)?"pointer":"crosshair"}};var Qe={n:"top",e:"right",s:"bottom",w:"left"},xe={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function Ne(a,e,t){return we(a,e,t?xe[Qe[t]]:void 0)}function we(a,e,t){let i=e.x-a.x,n=e.y-a.y;return t&&t.x!==0?i>=0?"left":"right":t&&t.y!==0?n>=0?"top":"bottom":Math.abs(i)>=Math.abs(n)?i>=0?"left":"right":n>=0?"top":"bottom"}function bt(a,e,t){switch(t){case "top":return {x:a.x,y:a.y-e.height/2};case "bottom":return {x:a.x,y:a.y+e.height/2};case "left":return {x:a.x-e.width/2,y:a.y};case "right":return {x:a.x+e.width/2,y:a.y}}}var et=14,Be=class extends N{type="eraser";erasing=false;lastPoint=null;erasedIds=new Set;onPointerDown(e){this.erasing=true,this.lastPoint=e,this.erasedIds.clear(),this.context.commitHistory(),this.context.setEraserPoint(e),this.eraseAt(e);}onPointerMove(e){if(!this.erasing||!this.lastPoint)return;let t=this.lastPoint,i=Math.hypot(e.x-t.x,e.y-t.y),n=Math.max(1,Math.ceil(i/Math.max(this.brushRadius()*.5,1)));for(let s=1;s<=n;s++){let r=s/n;this.eraseAt({x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r});}this.lastPoint=e,this.context.setEraserPoint(e);}onPointerUp(){this.erasing=false,this.lastPoint=null,this.erasedIds.clear(),this.context.setEraserPoint(null);}onKeyDown(){}onKeyUp(){}getCursor(){return this.erasing?"grabbing":"crosshair"}dispose(){this.erasing=false,this.lastPoint=null,this.erasedIds.clear(),this.context.setEraserPoint(null);}brushRadius(){return et/this.context.getCamera().getZoom()}eraseAt(e){let t=this.context.getShapesInBrushRadius(e,this.brushRadius());for(let i of t)this.erasedIds.has(i.id)||(this.erasedIds.add(i.id),this.context.deleteShape(i.id));}};function ge(a,e,t){let i=s=>(s-.5)*e,n=s=>(s-.5)*t;return a.map(s=>s[0]==="Z"?s:s[0]==="M"||s[0]==="L"?[s[0],i(s[1]),n(s[2])]:["C",i(s[1]),n(s[2]),i(s[3]),n(s[4]),i(s[5]),n(s[6])])}function ue(a,e,t,i,n,s,r){let o=[],h=s-n,l=Math.max(1,Math.ceil(Math.abs(h)/90)),c=h/l,d=4/3*Math.tan(c*Math.PI/180/4),g=y=>{let f=y*Math.PI/180;return [a+t*Math.cos(f),e+i*Math.sin(f)]},[u,p]=g(n);o.push(r?["M",u,p]:["L",u,p]);for(let y=0;y<l;y++){let f=n+c*y,w=f+c,x=f*Math.PI/180,v=w*Math.PI/180,[b,S]=g(f),[I,C]=g(w);o.push(["C",b-d*t*Math.sin(x),S+d*i*Math.cos(x),I+d*t*Math.sin(v),C-d*i*Math.cos(v),I,C]);}return o}function zt(a){let e=1/0,t=1/0,i=-1/0,n=-1/0,s=(u,p)=>{u<e&&(e=u),p<t&&(t=p),u>i&&(i=u),p>n&&(n=p);},r=0,o=0,h=0,l=0;for(let u of a){if(u[0]==="Z"){s(h,l);continue}if(u[0]==="M"||u[0]==="L"){r=u[1],o=u[2],u[0]==="M"&&(h=r,l=o),s(r,o);continue}let p=u[1],y=u[2],f=u[3],w=u[4],x=u[5],v=u[6];for(let b=0;b<=12;b++){let S=b/12,I=1-S,C=I*I*I,H=3*I*I*S,G=3*I*S*S,W=S*S*S;s(C*r+H*p+G*f+W*x,C*o+H*y+G*w+W*v);}r=x,o=v;}let c=i-e||1,d=n-t||1,g=(u,p)=>[(u-e)/c,(p-t)/d];return a.map(u=>{if(u[0]==="Z")return u;if(u[0]==="M"||u[0]==="L"){let[b,S]=g(u[1],u[2]);return [u[0],b,S]}let[p,y]=g(u[1],u[2]),[f,w]=g(u[3],u[4]),[x,v]=g(u[5],u[6]);return ["C",p,y,f,w,x,v]})}function Yt(){let a={x:.24,y:.7,r:.24},e={x:.5,y:.48,r:.36},t={x:.76,y:.7,r:.24},i=[...ue(a.x,a.y,a.r,a.r,90,246,true),...ue(e.x,e.y,e.r,e.r,180,360,false),...ue(t.x,t.y,t.r,t.r,294,450,false),["Z"]];return zt(i)}var X=.14,St=.5523,ce=X*St,_e=1-X,de=.5-.5*St,Xt={outline:[["M",0,X],["L",0,_e],["C",0,_e+ce,de,1,.5,1],["C",1-de,1,1,_e+ce,1,_e],["L",1,X],["C",1,X-ce,1-de,0,.5,0],["C",de,0,0,X-ce,0,X],["Z"]],seams:[[["M",0,X],["C",0,X+ce,de,X*2,.5,X*2],["C",1-de,X*2,1,X+ce,1,X]]]},Wt={outline:Yt()},Kt={outline:[["M",.5,.97],["C",.5,.97,.03,.66,.03,.35],["C",.03,.17,.16,.04,.31,.04],["C",.41,.04,.47,.1,.5,.17],["C",.53,.1,.59,.04,.69,.04],["C",.84,.04,.97,.17,.97,.35],["C",.97,.66,.5,.97,.5,.97],["Z"]]},Oe=[["M",0,.25],["L",.58,.25],["L",.58,0],["L",1,.5],["L",.58,1],["L",.58,.75],["L",0,.75],["Z"]];function tt(a,e){let t=(i,n)=>{switch(e){case "down":return [1-n,i];case "left":return [1-i,1-n];case "up":return [n,1-i];default:return [i,n]}};return a.map(i=>{if(i[0]==="Z")return i;if(i[0]==="M"||i[0]==="L"){let[c,d]=t(i[1],i[2]);return [i[0],c,d]}let[n,s]=t(i[1],i[2]),[r,o]=t(i[3],i[4]),[h,l]=t(i[5],i[6]);return ["C",n,s,r,o,h,l]})}var Ge={right:Oe,left:tt(Oe,"left"),up:tt(Oe,"up"),down:tt(Oe,"down")},Ft={outline:[["M",0,0],["L",0,1],["L",1,1],["Z"]]},Zt={outline:[["M",.34,0],["L",.66,0],["L",.66,.34],["L",1,.34],["L",1,.66],["L",.66,.66],["L",.66,1],["L",.34,1],["L",.34,.66],["L",0,.66],["L",0,.34],["L",.34,.34],["Z"]]},jt={outline:[["M",0,.5],["L",.22,.13],["L",.22,.34],["L",.78,.34],["L",.78,.13],["L",1,.5],["L",.78,.87],["L",.78,.66],["L",.22,.66],["L",.22,.87],["Z"]]},qt={outline:[["M",0,0],["L",1,0],["L",1,.8],["L",.32,.8],["L",.2,1],["L",.15,.8],["L",0,.8],["Z"]]},Jt={outline:[...ue(.5,.4,.5,.4,100,-228,true),["L",.19,1],["Z"]]},Qt={outline:[["M",.5,0],["L",1,.25],["L",1,.75],["L",.5,1],["L",0,.75],["L",0,.25],["Z"]],seams:[[["M",.5,.5],["L",.5,1]],[["M",.5,.5],["L",0,.25]],[["M",.5,.5],["L",1,.25]]]},en={outline:[...ue(.5,.5,.5,.5,0,-270,true),["L",.5,.5],["Z"]]},tn={outline:[["M",0,0],...ue(.6,.5,.4,.5,270,450,false),["L",0,1],["Z"]]},nn={outline:[["M",0,0],["L",1,0],["L",1,1],["L",0,1],["Z"]],seams:[[["M",.12,0],["L",.12,1]],[["M",.88,0],["L",.88,1]]]},sn={outline:[["M",0,0],["L",1,0],["L",1,.84],["C",.72,1.06,.28,.62,0,.84],["Z"]]},rn={outline:[["M",0,0],["L",.45,0],["L",1,.5],["L",.45,1],["L",0,1],["L",.42,.5],["Z"]]};function on(a){let e=t=>1-t;return a.map(t=>t[0]==="Z"?t:t[0]==="M"||t[0]==="L"?[t[0],e(t[1]),t[2]]:["C",e(t[1]),t[2],e(t[3]),t[4],e(t[5]),t[6]])}var be=.16,Mt={outline:[["M",.015,.02],["C",.075,.02,.1,.08,.1,.2],["C",.1,.36,.125,.5,.16,.5],["C",.125,.5,.1,.64,.1,.8],["C",.1,.92,.075,.98,.015,.98]],strokeOnly:true},an={outline:on(Mt.outline),strokeOnly:true};function Ue(a){if(a.type!=="brace-left"&&a.type!=="brace-right")return 0;let e=(a.width??0)*be/2;return a.type==="brace-left"?e:-e}var hn={outline:[["M",0,0],["L",1,0],["L",1,1],["L",0,1],["Z"]],seams:[[["M",.1,0],["L",.1,1]],[["M",.9,0],["L",.9,1]]]};function ze(a){switch(a){case "cylinder":return Xt;case "cloud":return Wt;case "heart":return Kt;case "class-catalog":return hn;case "block-arrow-right":return {outline:Ge.right};case "block-arrow-left":return {outline:Ge.left};case "block-arrow-up":return {outline:Ge.up};case "block-arrow-down":return {outline:Ge.down};case "block-arrow-double":return jt;case "right-triangle":return Ft;case "cross":return Zt;case "speech-rect":return qt;case "speech-round":return Jt;case "cube":return Qt;case "sector":return en;case "delay":return tn;case "predefined-process":return nn;case "document":return sn;case "chevron":return rn;case "brace-left":return Mt;case "brace-right":return an;default:return}}var ae=class a{ctx;width=0;height=0;dpr=window.devicePixelRatio||1;showGrid=false;textLayoutCache=new Map;static TEXT_CACHE_LIMIT=500;constructor(e,t){let i=e.getContext("2d");if(!i)throw new Error("Failed to get Canvas 2D context");this.ctx=i,typeof t=="number"&&t>0&&(this.dpr=t);}resize(e,t){this.width=e,this.height=t;let i=Math.ceil(e*this.dpr),n=Math.ceil(t*this.dpr);(this.ctx.canvas.width!==i||this.ctx.canvas.height!==n)&&(this.ctx.canvas.width=i,this.ctx.canvas.height=n,this.ctx.canvas.style.width=`${e}px`,this.ctx.canvas.style.height=`${t}px`);}setShowGrid(e){this.showGrid=e;}render(e,t,i,n,s,r,o,h,l,c,d,g){let u=this.ctx,p=t.getZoom(),y=t.x,f=t.y;u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),d&&(u.fillStyle=d,u.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height));let w=this.dpr*p;u.setTransform(w,0,0,w,w*y,w*f),this.showGrid&&this.drawGrid(u,p,y,f);let x=null;for(let b of e)if(b.type==="arrow"&&(b.startBinding||b.endBinding)){x=new Map,e.forEach(S=>x.set(S.id,S));break}let v=x??new Map;if(e.forEach(b=>{u.save(),u.translate(b.x,b.y),u.rotate(b.rotation);let S=i.has(b.id);this.drawShape(u,b,S,p,v,l,c),u.restore();}),o&&this.drawGenerationPreview(u,o,p,e,v),g&&!i.has(g)){let b=e.find(S=>S.id===g);b&&this.drawConnectionDots(u,this.getShapeWorldBounds(b),p,.6);}n&&this.drawBrushRect(u,n,p),s&&s.length>0&&this.drawSnapGuides(u,s,p),r&&this.drawConnectingTargetHighlight(u,r,e,p),h&&this.drawEraserBrush(u,h,p),u.setTransform(1,0,0,1,0,0);}drawEraserBrush(e,t,i){let n=et/i;e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.fillStyle=F(D.primary,.12),e.fill(),e.strokeStyle=F(D.primary,.55),e.lineWidth=1.5/i,e.stroke();}drawConnectingTargetHighlight(e,t,i,n){let s=i.find(l=>l.id===t);if(!s||s.type==="line"||s.type==="arrow"||s.type==="draw")return;let r=this.getShapeWorldBounds(s),o=[{x:r.x+r.width/2,y:r.y},{x:r.x+r.width,y:r.y+r.height/2},{x:r.x+r.width/2,y:r.y+r.height},{x:r.x,y:r.y+r.height/2}],h=6/n;e.save(),o.forEach(l=>{e.beginPath(),e.arc(l.x,l.y,h,0,Math.PI*2),e.fillStyle=D.selection.handleFill,e.fill(),e.strokeStyle=D.primary,e.lineWidth=2/n,e.stroke();}),e.restore();}getShapeWorldBounds(e){let t=this.getShapeBounds(e);return {x:e.x+t.x,y:e.y+t.y,width:t.width,height:t.height}}drawBrushRect(e,t,i){e.save(),e.fillStyle=D.brushFill,e.strokeStyle=D.brushStroke,e.lineWidth=1.5/i,e.setLineDash([4/i,4/i]),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.fill(),e.stroke(),e.restore();}drawGrid(e,t,i,n){let s=-i,r=-n,o=s+this.width/t,h=r+this.height/t,l=20;for(;l*t<10;)l*=2;e.strokeStyle=D.grid,e.lineWidth=1/t,e.beginPath();for(let c=Math.floor(s/l)*l;c<=o;c+=l)e.moveTo(c,r),e.lineTo(c,h);for(let c=Math.floor(r/l)*l;c<=h;c+=l)e.moveTo(s,c),e.lineTo(o,c);e.stroke();}drawShape(e,t,i,n,s,r,o){switch(this.applyStyle(e,t.style,n),t.type){case "rectangle":this.drawRectangle(e,t,i);break;case "rounded-rectangle":this.drawRoundedRectangle(e,t,i);break;case "circle":this.drawCircle(e,t,i);break;case "ellipse":this.drawEllipse(e,t,i);break;case "diamond":this.drawDiamond(e,t,i);break;case "triangle":this.drawTriangle(e,t,i);break;case "hexagon":this.drawHexagon(e,t,i);break;case "parallelogram":this.drawParallelogram(e,t,i);break;case "trapezoid":this.drawTrapezoid(e,t,i);break;case "pentagon":this.drawPentagon(e,t,i);break;case "octagon":this.drawOctagon(e,t,i);break;case "star":this.drawStar(e,t,i);break;case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "class-catalog":case "chevron":case "brace-left":case "brace-right":this.drawPathShape(e,t,i);break;case "stadium":this.drawStadium(e,t,i);break;case "uml-class":this.drawUmlClass(e,t,i);break;case "uml-interface":this.drawUmlInterface(e,t,i);break;case "mind-map":this.drawMindMap(e,t,i,r,o);break;case "line":this.drawLine(e,t,s,i,n);break;case "arrow":this.drawArrow(e,t,s,i,n);break;case "text":this.drawText(e,t);break;case "draw":this.drawFreehand(e,t);break}if(t.text&&t.type!=="text"&&t.type!=="line"&&t.type!=="arrow"&&t.type!=="draw"&&this.drawShapeText(e,t),i){let h=t.type==="line"||t.type==="arrow";t.type==="mind-map"||(h?this.drawSelectionHandles(e,t,n):(this.drawSelectionOutline(e,t,n),this.drawSelectionHandles(e,t,n)));}}applyStyle(e,t,i){let n=t.strokeOpacity??1;e.strokeStyle=n<1&&t.strokeColor!=="transparent"?F(t.strokeColor,n):t.strokeColor,e.lineWidth=t.strokeWidth/i,e.lineCap="round",e.lineJoin="round";let s=t.fillOpacity??1;s<1&&t.fillColor!=="transparent"?e.fillStyle=F(t.fillColor,s):e.fillStyle=t.fillColor,t.strokeDash?e.setLineDash(t.strokeDash):e.setLineDash([]);}drawRectangle(e,t,i){e.beginPath(),e.rect(-t.width/2,-t.height/2,t.width,t.height),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawRoundedRectangle(e,t,i){let{width:n,height:s,borderRadius:r}=t;e.beginPath(),e.roundRect(-n/2,-s/2,n,s,r),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStadium(e,t,i){let{width:n,height:s}=t;e.beginPath(),e.roundRect(-n/2,-s/2,n,s,Math.min(n,s)/2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawCircle(e,t,i){e.beginPath(),e.arc(0,0,t.radius,0,Math.PI*2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawEllipse(e,t,i){e.beginPath(),e.ellipse(0,0,t.width/2,t.height/2,0,0,Math.PI*2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawDiamond(e,t,i){e.beginPath(),e.moveTo(0,-t.height/2),e.lineTo(t.width/2,0),e.lineTo(0,t.height/2),e.lineTo(-t.width/2,0),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawTriangle(e,t,i){e.beginPath(),e.moveTo(0,-t.height/2),e.lineTo(t.width/2,t.height/2),e.lineTo(-t.width/2,t.height/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawHexagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<6;r++){let o=r*Math.PI/3-Math.PI/2,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawParallelogram(e,t,i){let{width:n,height:s}=t,r=n*.2;e.beginPath(),e.moveTo(-n/2+r,-s/2),e.lineTo(n/2,-s/2),e.lineTo(n/2-r,s/2),e.lineTo(-n/2,s/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawTrapezoid(e,t,i){let{width:n,height:s}=t,r=n*.15;e.beginPath(),e.moveTo(-n/2+r,-s/2),e.lineTo(n/2-r,-s/2),e.lineTo(n/2,s/2),e.lineTo(-n/2,s/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPentagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<5;r++){let o=r*2*Math.PI/5-Math.PI/2,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawOctagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<8;r++){let o=r*Math.PI/4-Math.PI/8,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStar(e,t,i){let n=t.width/2,s=t.height/2,r=5,o=.4;e.beginPath();for(let h=0;h<r*2;h++){let l=h*Math.PI/r-Math.PI/2,c=h%2===0?1:o,d=n*c*Math.cos(l),g=s*c*Math.sin(l);h===0?e.moveTo(d,g):e.lineTo(d,g);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPathShape(e,t,i){let n=ze(t.type);if(n&&(this.tracePath(e,ge(n.outline,t.width,t.height)),!n.strokeOnly&&t.style.fillColor!=="transparent"&&e.fill(),e.stroke(),n.seams))for(let s of n.seams)this.tracePath(e,ge(s,t.width,t.height)),e.stroke();}tracePath(e,t){e.beginPath();for(let i of t)switch(i[0]){case "M":e.moveTo(i[1],i[2]);break;case "L":e.lineTo(i[1],i[2]);break;case "C":e.bezierCurveTo(i[1],i[2],i[3],i[4],i[5],i[6]);break;case "Z":e.closePath();break}}drawUmlClass(e,t,i){let{width:n,height:s,className:r,attributes:o,methods:h}=t,l=n/2,c=s/2,d=j,g=o.length>0?o.length*$+k*2:k*2;e.beginPath(),e.rect(-l,-c,n,s),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-l,-c+d),e.lineTo(l,-c+d),e.moveTo(-l,-c+d+g),e.lineTo(l,-c+d+g),e.stroke(),e.save(),e.textBaseline="middle";let u=n-O*2,p=x=>{if(e.measureText(x).width<=u)return x;let v="\u2026",b=0,S=x.length;for(;b<S;){let I=b+S+1>>1;e.measureText(x.slice(0,I)+v).width<=u?b=I:S=I-1;}return x.slice(0,b)+v},y=(x,v,b,S,I,C,H)=>{let G=S||U,W=I||"#1f2937";e.font=`${G}px sans-serif`,e.fillStyle=W,e.textAlign=H;let R=p(x);if(e.fillText(R,v,b),C){let V=e.measureText(R).width,De=v;e.strokeStyle=W,e.beginPath(),e.moveTo(De,b),e.lineTo(De+V,b),e.stroke();}};e.font=`bold ${t.fontSize||U}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937",e.fillText(p(r),0,-c+d/2);let f=-c+d+k+$/2;o.forEach((x,v)=>{let b=`${x.visibility} ${x.name}: ${x.type}`;y(b,-l+O,f+v*$,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");});let w=-c+d+g+k+$/2;h.forEach((x,v)=>{let b=`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`;y(b,-l+O,w+v*$,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");}),e.restore();}drawUmlInterface(e,t,i){let{width:n,height:s,className:r,methods:o}=t,h=n/2,l=s/2,c=j;e.beginPath(),e.rect(-h,-l,n,s),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-h,-l+c),e.lineTo(h,-l+c),e.stroke(),e.save(),e.textBaseline="middle";let d=n-O*2,g=f=>{if(e.measureText(f).width<=d)return f;let w="\u2026",x=0,v=f.length;for(;x<v;){let b=x+v+1>>1;e.measureText(f.slice(0,b)+w).width<=d?x=b:v=b-1;}return f.slice(0,x)+w},u=(f,w,x,v,b,S,I)=>{let C=v||U,H=b||"#1f2937";e.font=`${C}px sans-serif`,e.fillStyle=H,e.textAlign=I;let G=g(f);if(e.fillText(G,w,x),S){let W=e.measureText(G).width,R=w;e.strokeStyle=H,e.beginPath(),e.moveTo(R,x),e.lineTo(R+W,x),e.stroke();}};e.font=`bold ${t.fontSize||U}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937";let p=`<<${r||"Interface"}>>`;e.fillText(g(p),0,-l+c/2);let y=-l+c+k+$/2;o.forEach((f,w)=>{let x=`${f.visibility} ${f.name}(${f.params}): ${f.returnType}`;u(x,-h+O,y+w*$,f.fontSize||t.fontSize||0,f.textColor||t.textColor||"",!!f.strikethrough,"left");}),e.restore();}static DEFAULT_CORNER_RADIUS=10;static ROUTE_CLEARANCE=30;static CONNECTION_LEAD=24;static CONNECTED_PAD=8;drawMindMap(e,t,i,n,s){let o=B(t.root).positions;this.drawMindMapConnections(e,t.root,o),this.drawMindMapNodes(e,t,o,n,s);}drawMindMapConnections(e,t,i){let n=s=>{if(s.collapsed)return;let r=i.get(s.id);if(r)for(let o of s.children??[]){let h=i.get(o.id);if(!h)continue;let l=oe(o,h.depth);e.strokeStyle=l,e.lineWidth=2,e.lineCap="round",e.beginPath(),e.moveTo(r.x+r.width/2,r.y);let c=(r.x+r.width/2+(h.x-h.width/2))/2;e.bezierCurveTo(c,r.y,c,h.y,h.x-h.width/2,h.y),e.stroke(),n(o);}};n(t);}drawMindMapNodes(e,t,i,n,s){let r=t.root,o=h=>{let l=i.get(h.id);if(!l)return;let c=oe(h,l.depth),d=l.width/2,g=l.height/2;if(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.roundRect(l.x-d,l.y-g,l.width,l.height,6),e.fill(),e.stroke(),s&&s.shapeId===t.id&&s.nodeId===h.id&&(e.fillStyle=F(D.primary,.06),e.strokeStyle=F(D.primary,.55),e.lineWidth=2,e.beginPath(),e.roundRect(l.x-d,l.y-g,l.width,l.height,6),e.fill(),e.stroke()),n&&n.shapeId===t.id&&n.nodeId===h.id&&(e.fillStyle=F(D.primary,.12),e.strokeStyle=D.primary,e.lineWidth=2.5,e.beginPath(),e.roundRect(l.x-d,l.y-g,l.width,l.height,6),e.fill(),e.stroke()),h.children&&h.children.length>0&&(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.arc(l.x+d+10,l.y,8,0,Math.PI*2),e.fill(),e.stroke(),e.fillStyle=c,e.font="bold 13px sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillText(h.collapsed?"+":"\u2212",l.x+d+10,l.y+.5)),h.note){let I=h.noteColor??c;e.font="11px sans-serif";let C=Math.min(e.measureText(h.note).width+12,130),H=16;e.fillStyle=I,e.beginPath(),e.roundRect(l.x-d,l.y-g-H+2,C,H,4),e.fill(),e.fillStyle="#ffffff",e.font="11px sans-serif",e.textAlign="left",e.textBaseline="middle",e.fillText(e.measureText(h.note).width+12>130?h.note.slice(0,12)+"\u2026":h.note,l.x-d+6,l.y-g-H/2+2);}e.font=`${14}px sans-serif`;let f=h.icon?18:0,w=l.width-f-(h.icon?8:0)-16,x=this.ellipsizeText(e,h.text||"",w),v=e.measureText(x).width,b=f+(f?8:0)+v,S=l.x-b/2;if(e.textBaseline="middle",h.icon&&(e.font="16px sans-serif",e.textAlign="left",e.fillStyle="#1f2937",e.fillText(h.icon,S,l.y+1),S+=f+8),e.font=`${14}px sans-serif`,e.textAlign="left",e.fillStyle="#1f2937",e.fillText(x,S,l.y),!h.collapsed)for(let I of h.children??[])o(I);};o(r);}ellipsizeText(e,t,i){if(i<=0)return "";if(e.measureText(t).width<=i)return t;let n="\u2026",s=0,r=t.length;for(;s<r;){let o=s+r+1>>1;e.measureText(t.slice(0,o)+n).width<=i?s=o:r=o-1;}return t.slice(0,s)+n}drawLine(e,t,i,n,s){if(t.points.length<2)return;let r=t.points.map(c=>({x:c.x,y:c.y}));r.length>=2&&(r[0]=this.clampToShapeOutline(r[0],i,t.id,r[r.length-1]),r[r.length-1]=this.clampToShapeOutline(r[r.length-1],i,t.id,r[0]));let o=r.map(c=>({x:c.x-t.x,y:c.y-t.y})),h=t.connectionType||"straight",l=h==="straight"?this.getAlignedPoints(o):this.buildPathPoints(o,h,this.collectRoutingObstacles(t.id,o[0],o[o.length-1],i,{x:t.x,y:t.y}),{fromN:this.getDockNormal(r[0],i,t.id),toN:this.getDockNormal(r[r.length-1],i,t.id)});if(h==="straight"){e.beginPath(),e.moveTo(o[0].x,o[0].y);for(let c=1;c<o.length;c++)e.lineTo(o[c].x,o[c].y);e.stroke(),e.setLineDash([]);}else h==="orthogonal"?this.drawSharpPolyline(e,l):this.drawRoundedPolyline(e,l,a.DEFAULT_CORNER_RADIUS),e.stroke(),e.setLineDash([]);n&&this.drawLinearHighlight(e,l,s);}drawArrow(e,t,i,n,s){if(t.points.length<2)return;let r=t.points.map(u=>({x:u.x,y:u.y})),o=t.endBinding;if(t.startBinding){let u=i.get(t.startBinding.toShapeId);u&&(r[0]=this.getBindingPoint(u,t.startBinding));}if(t.endBinding){let u=i.get(t.endBinding.toShapeId);u&&(o=this.resolveAutoEndBinding(t.endBinding,t,r[0],u),r[r.length-1]=this.getBindingPoint(u,o));}t.startBinding||(r[0]=this.clampToShapeOutline(r[0],i,t.id,r[r.length-1])),t.endBinding||(r[r.length-1]=this.clampToShapeOutline(r[r.length-1],i,t.id,r[0]));let h=r.map(u=>({x:u.x-t.x,y:u.y-t.y})),l=t.connectionType||"straight",c=t.arrowHead??"end";!!t.dashed||c==="dependency"||c==="realization"?e.setLineDash([8,5]):e.setLineDash([]);let g;if(l==="straight"){let u=this.getAlignedPoints(h);g=u,e.beginPath(),e.moveTo(u[0].x,u[0].y);for(let p=1;p<u.length;p++)e.lineTo(u[p].x,u[p].y);e.stroke(),this.drawArrowHeads(e,u,c);}else g=this.buildPathPoints(h,l,this.collectRoutingObstacles(t.id,h[0],h[h.length-1],i,{x:t.x,y:t.y}),{fromN:this.resolveDockNormal(t.startBinding,r[0],i,t.id),toN:this.resolveDockNormal(o,r[r.length-1],i,t.id)}),l==="orthogonal"?this.drawSharpPolyline(e,g):this.drawRoundedPolyline(e,g,a.DEFAULT_CORNER_RADIUS),e.stroke(),this.drawArrowHeads(e,g,c);e.setLineDash([]),n&&this.drawLinearHighlight(e,g,s);}drawLinearHighlight(e,t,i){if(!(!t||t.length<2)){e.save(),e.strokeStyle=D.lineHighlight,e.lineWidth=7/i,e.lineCap="round",e.lineJoin="round",e.setLineDash([]),e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);e.stroke(),e.restore();}}drawGenerationPreview(e,t,i,n,s){let{from:r,to:o}=t,h=t.arrowStyle??{connectionType:"polyline",arrowHead:"end",dashed:false},l=new Map(s);n.forEach(y=>l.set(y.id,y));let c=t.targetShapeId;if(!c&&t.type){let y=ee(t.type,o);y.id=a.GEN_GHOST_ID,l.set(a.GEN_GHOST_ID,y),c=a.GEN_GHOST_ID;}let d=t.sourceEdge?Qe[t.sourceEdge]:void 0,g=t.sourceShapeId&&d?{toShapeId:t.sourceShapeId,handle:d}:void 0,u=c?{...t.targetBinding??{auto:true,handle:"left"},toShapeId:c}:void 0,p={id:a.GEN_PREVIEW_ID,type:"arrow",x:r.x,y:r.y,points:[r,o],rotation:0,style:t.lineStyle??a.PREVIEW_LINE_STYLE,startBinding:g,endBinding:u,connectionType:h.connectionType,arrowHead:h.arrowHead,dashed:h.dashed};if(e.save(),t.dragging||(e.globalAlpha=.65),e.translate(r.x,r.y),this.applyStyle(e,p.style,i),this.drawArrow(e,p,l,false,i),e.restore(),t.type){let y=l.get(a.GEN_GHOST_ID),f=y?this.getShapeBounds(y):{x:-60,y:-30,width:120,height:60};this.drawPreviewShapeOutline(e,o,t.type,f,i);}e.save(),e.beginPath(),e.arc(r.x,r.y,5/i,0,Math.PI*2),e.fillStyle=D.genDot,e.fill(),e.restore();}drawPreviewShapeOutline(e,t,i,n,s){let r=n.width,o=n.height,h=r/2,l=o/2,c=t.x,d=t.y;switch(e.strokeStyle=D.genLine,e.lineWidth=1.5/s,e.setLineDash([6/s,4/s]),e.beginPath(),i){case "circle":case "ellipse":e.ellipse(c,d,r/2,o/2,0,0,Math.PI*2);break;case "diamond":e.moveTo(c,d-l),e.lineTo(c+h,d),e.lineTo(c,d+l),e.lineTo(c-h,d),e.closePath();break;case "triangle":e.moveTo(c,d-l),e.lineTo(c+h,d+l),e.lineTo(c-h,d+l),e.closePath();break;case "hexagon":for(let g=0;g<6;g++){let u=g*Math.PI/3-Math.PI/2,p=c+h*Math.cos(u),y=d+l*Math.sin(u);g===0?e.moveTo(p,y):e.lineTo(p,y);}e.closePath();break;case "parallelogram":{let g=r*.15;e.moveTo(c-h+g,d-l),e.lineTo(c+h,d-l),e.lineTo(c+h-g,d+l),e.lineTo(c-h,d+l),e.closePath();break}default:e.roundRect(c-h,d-l,r,o,i==="rounded-rectangle"?8:4);break}e.stroke();}static ALIGN_TOLERANCE=8;static GEN_PREVIEW_ID="__gen_preview_line__";static GEN_GHOST_ID="__gen_preview_ghost__";static PREVIEW_LINE_STYLE={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null};getAlignedPoints(e){if(e.length<2)return e;let t=e[0],i=e[e.length-1],n=i.x-t.x,s=i.y-t.y,r=a.ALIGN_TOLERANCE;if(Math.abs(s)<=r){let o=(t.y+i.y)/2;return e.map(h=>({x:h.x,y:o}))}if(Math.abs(n)<=r){let o=(t.x+i.x)/2;return e.map(h=>({x:o,y:h.y}))}return e}buildPathPoints(e,t,i=[],n={}){if(e.length<2||t==="straight")return e;switch(t){case "polyline":return this.generatePolylinePoints(e,i,n);case "orthogonal":return this.generateOrthogonalPoints(e,i,n);case "curve":return this.generateCurvePoints(e,n);default:return e}}drawRoundedPolyline(e,t,i){if(e.beginPath(),!(t.length<2)){if(t.length===2||i<=0){e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);return}e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length-1;n++){let s=t[n-1],r=t[n],o=t[n+1],h=r.x-s.x,l=r.y-s.y,c=o.x-r.x,d=o.y-r.y,g=Math.hypot(h,l),u=Math.hypot(c,d);if(g<1e-6||u<1e-6){e.lineTo(r.x,r.y);continue}let p=Math.min(i,g*.5,u*.5),y=r.x-h/g*p,f=r.y-l/g*p,w=r.x+c/u*p,x=r.y+d/u*p;e.lineTo(y,f),e.arcTo(r.x,r.y,w,x,p);}e.lineTo(t[t.length-1].x,t[t.length-1].y);}}drawSharpPolyline(e,t){if(e.beginPath(),!(t.length<2)){e.moveTo(t[0].x,t[0].y);for(let i=1;i<t.length;i++)e.lineTo(t[i].x,t[i].y);}}drawSnapGuides(e,t,i){e.save(),e.strokeStyle=D.guide,e.lineWidth=1/i,e.setLineDash([6/i,4/i]),e.beginPath();for(let n of t)n.type==="horizontal"?(e.moveTo(n.start,n.position),e.lineTo(n.end,n.position)):(e.moveTo(n.position,n.start),e.lineTo(n.position,n.end));e.stroke(),e.restore();}generatePolylinePoints(e,t=[],i={}){if(e.length<2)return e;let n=[];n.push(e[0]);let s=e.length-1,r=a.CONNECTION_LEAD,o=e[0],h=e[s];i.fromN&&i.toN&&(i.fromN.x!==0&&i.toN.x!==0?r=Math.min(r,Math.abs(h.x-o.x)/2):i.fromN.y!==0&&i.toN.y!==0&&(r=Math.min(r,Math.abs(h.y-o.y)/2)));for(let l=1;l<e.length;l++){let c=e[l-1],d=e[l],g=l===1,u=l===s,p=g&&i.fromN?{x:c.x+i.fromN.x*r,y:c.y+i.fromN.y*r}:c,y=u&&i.toN?{x:d.x+i.toN.x*r,y:d.y+i.toN.y*r}:d;g&&i.fromN&&n.push(p);let f=g?i.fromN:void 0,w=u?i.toN:void 0,x=w?w.x!==0?"H":"V":f?f.x!==0?"H":"V":void 0,v=this.computeOrthogonalRoute(p,y,t,x);x&&(v=this.ensureFinalAxis(v,x));for(let b of v)n.push(b);u&&i.toN&&n.push(d);}return this.collapseLinePoints(n)}generateOrthogonalPoints(e,t=[],i={}){return this.generatePolylinePoints(e,t,i)}ensureFinalAxis(e,t){if(e.length<2)return e;let i=e[e.length-1],n=e[e.length-2],s=Math.abs(i.y-n.y)<1e-6;if(t==="H"?s:!s)return e;let r=t==="H"?{x:n.x,y:i.y}:{x:i.x,y:n.y},o=e.slice(0,-1);return o.push(r,i),o}collapseLinePoints(e){let t=[];for(let i of e){let n=t.length;if(!(n>0&&Math.abs(t[n-1].x-i.x)<1e-6&&Math.abs(t[n-1].y-i.y)<1e-6)){if(n>=2){let s=t[n-2],r=t[n-1];if(Math.abs(s.y-r.y)<1e-6&&Math.abs(r.y-i.y)<1e-6||Math.abs(s.x-r.x)<1e-6&&Math.abs(r.x-i.x)<1e-6){t[n-1]=i;continue}}t.push(i);}}return t}computeOrthogonalRoute(e,t,i=[],n){let s=t.x-e.x,r=t.y-e.y;if(Math.abs(s)<1||Math.abs(r)<1)return [t];let o=e.x+s/2,h=e.y+r/2,l=this.dropObstaclesAtEndpoints(e,t,i),c=l.length>0,d=Math.max(e.x,Math.min(o,t.x)),g=Math.max(e.y,Math.min(h,t.y)),u=n==="H"?[[{x:d,y:e.y},{x:d,y:t.y},t],[{x:e.x,y:g},{x:t.x,y:g},t],[{x:t.x,y:e.y},t],[{x:e.x,y:t.y},t]]:n==="V"?[[{x:e.x,y:g},{x:t.x,y:g},t],[{x:d,y:e.y},{x:d,y:t.y},t],[{x:t.x,y:e.y},t],[{x:e.x,y:t.y},t]]:[[{x:o,y:e.y},{x:o,y:t.y},t],[{x:e.x,y:h},{x:t.x,y:h},t],[{x:t.x,y:e.y},t],[{x:e.x,y:t.y},t]];if(c){if(n){let y=this.findClearBus(e,t,l,n);if(y!==null)return y}for(let y of u)if(!this.routeHitsObstacles(e,y,l))return y;let p=this.routeOrthogonalAvoidance(e,t,l);return p&&p.length>0?p:u[0]}return n==="H"?[{x:d,y:e.y},{x:d,y:t.y},t]:n==="V"?[{x:e.x,y:g},{x:t.x,y:g},t]:Math.abs(s)>=Math.abs(r)?[{x:o,y:e.y},{x:o,y:t.y},t]:[{x:e.x,y:h},{x:t.x,y:h},t]}dropObstaclesAtEndpoints(e,t,i){if(i.length===0)return i;let n=(s,r)=>{let o=s.pad??a.ROUTE_CLEARANCE;return r.x>s.x-o&&r.x<s.x+s.width+o&&r.y>s.y-o&&r.y<s.y+s.height+o};return i.filter(s=>!n(s,e)&&!n(s,t))}findClearBus(e,t,i,n){let s=n==="H"?e.x:e.y,r=n==="H"?t.x:t.y;if(r-s<1)return null;let o=Math.max(6,(r-s)/24);for(let h=s;h<=r;h+=o){let l=n==="H"?[{x:h,y:e.y},{x:h,y:t.y},t]:[{x:e.x,y:h},{x:t.x,y:h},t];if(!this.routeHitsObstacles(e,l,i))return l}return null}collectRoutingObstacles(e,t,i,n,s){if(!n||n.size===0)return [];let r=[];return n.forEach((o,h)=>{if(h===e||o.type==="line"||o.type==="arrow")return;let l=this.getShapeBounds(o),c={x:o.x+l.x-s.x,y:o.y+l.y-s.y,width:l.width,height:l.height};c.pad=this.pointInRect(t,c)||this.pointInRect(i,c)?a.CONNECTED_PAD:a.ROUTE_CLEARANCE,r.push(c);}),r}pointInRect(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}routeHitsObstacles(e,t,i){let n=[e,...t];for(let s=1;s<n.length;s++)if(this.segmentHitsObstacle(n[s-1],n[s],i))return true;return false}segmentHitsObstacle(e,t,i){for(let n of i){let s=n.pad??a.ROUTE_CLEARANCE,r=n.y-s,o=n.y+n.height+s,h=n.x-s,l=n.x+n.width+s;if(Math.abs(e.y-t.y)<.5){if(e.y>=r&&e.y<=o){let c=Math.min(e.x,t.x);if(Math.max(e.x,t.x)>=h&&c<=l)return true}}else if(e.x>=h&&e.x<=l){let c=Math.min(e.y,t.y);if(Math.max(e.y,t.y)>=r&&c<=o)return true}}return false}routeOrthogonalAvoidance(e,t,i){let n=new Set([e.x,t.x]),s=new Set([e.y,t.y]);for(let M of i){let P=M.pad??a.ROUTE_CLEARANCE;n.add(M.x-P),n.add(M.x+M.width+P),s.add(M.y-P),s.add(M.y+M.height+P);}let r=[...n].sort((M,P)=>M-P),o=[...s].sort((M,P)=>M-P),h=r.length,l=o.length,c=M=>{for(let P=0;P<h;P++)if(Math.abs(r[P]-M)<1e-6)return P;return 0},d=M=>{for(let P=0;P<l;P++)if(Math.abs(o[P]-M)<1e-6)return P;return 0},g=c(e.x),u=d(e.y),p=c(t.x),y=d(t.y),f=[],w=[];for(let M=0;M<h;M++)f.push(new Array(l).fill(true)),w.push(new Array(l).fill(true));for(let M of i){let P=M.pad??a.ROUTE_CLEARANCE,E=M.x-P,L=M.x+M.width+P,z=M.y-P,Y=M.y+M.height+P;for(let A=0;A<h-1;A++)if(!(r[A+1]<=E||r[A]>=L))for(let K=0;K<l;K++)o[K]>z&&o[K]<Y&&(f[A][K]=false);for(let A=0;A<l-1;A++)if(!(o[A+1]<=z||o[A]>=Y))for(let K=0;K<h;K++)r[K]>E&&r[K]<L&&(w[K][A]=false);}let x=h*l,v=1/0,b=new Float64Array(x).fill(v),S=new Int32Array(x).fill(-1),I=new Uint8Array(x),C=M=>{let P=M%h,E=M/h|0;return Math.abs(r[P]-t.x)+Math.abs(o[E]-t.y)},H=(M,P)=>M%h===P%h,G=u*h+g,W=y*h+p;b[G]=0;let R=[G],V=[C(G)],De=M=>{let P=b[M]+C(M);R.push(M),V.push(P);let E=R.length-1;for(;E>0;){let L=E-1>>1;if(V[L]<=V[E])break;[R[L],R[E]]=[R[E],R[L]],[V[L],V[E]]=[V[E],V[L]],E=L;}},kt=()=>{let M=R[0],P=R.pop(),E=V.pop();if(R.length){R[0]=P,V[0]=E;let L=0;for(;;){let z=L*2+1,Y=z+1,A=L;if(z<R.length&&V[z]<V[A]&&(A=z),Y<R.length&&V[Y]<V[A]&&(A=Y),A===L)break;[R[A],R[L]]=[R[L],R[A]],[V[A],V[L]]=[V[L],V[A]],L=A;}}return M},Ee=(M,P,E)=>{let L=M%h,z=P%h,Y=b[M]+(Math.abs(z-L)===0?Math.abs(o[P/h|0]-o[M/h|0]):Math.abs(r[z]-r[L]))+E;Y<b[P]&&(b[P]=Y,S[P]=M,I[P]||De(P));};for(;R.length;){let M=kt();if(M===W||I[M]){if(M===W)break;continue}I[M]=1;let P=M%h,E=M/h|0,L=S[M],z=L>=0?H(L,M)?"v":"h":"",Y=A=>{let K=H(M,A)?"v":"h";return z!==""&&z!==K?24:0};P+1<h&&f[P][E]&&Ee(M,E*h+P+1,Y(E*h+P+1)),P-1>=0&&f[P-1][E]&&Ee(M,E*h+P-1,Y(E*h+P-1)),E+1<l&&w[P][E]&&Ee(M,(E+1)*h+P,Y((E+1)*h+P)),E-1>=0&&w[P][E-1]&&Ee(M,(E-1)*h+P,Y((E-1)*h+P));}if(b[W]===v)return null;let We=[];for(let M=W;M!==-1;M=S[M])We.push({x:r[M%h],y:o[M/h|0]});We.reverse();let le=[];for(let M of We){let P=le.length;if(P>=2){let E=le[P-2],L=le[P-1];if(Math.abs(E.y-L.y)<1e-6&&Math.abs(L.y-M.y)<1e-6||Math.abs(E.x-L.x)<1e-6&&Math.abs(L.x-M.x)<1e-6){le[P-1]=M;continue}}le.push(M);}return le.slice(1)}generateCurvePoints(e,t={}){if(e.length<2)return e;let i=e.length,n=[e[0]],s=h=>{let l=e[h],c=e[h+1];return Math.hypot(c.x-l.x,c.y-l.y)},r=h=>Math.max(16,Math.min(h*.32,150)),o=h=>{let l=e[Math.max(0,h-1)],c=e[Math.min(i-1,h+1)],d=c.x-l.x,g=c.y-l.y,u=Math.hypot(d,g);return u<1e-6?{x:1,y:0}:{x:d/u,y:g/u}};for(let h=0;h<i-1;h++){let l=e[h],c=e[h+1],d=s(h),g;if(h===0&&t.fromN)g={x:l.x+t.fromN.x*r(d),y:l.y+t.fromN.y*r(d)};else {let y=o(h);g={x:l.x+y.x*r(d),y:l.y+y.y*r(d)};}let u;if(h===i-2&&t.toN)u={x:c.x+t.toN.x*r(d),y:c.y+t.toN.y*r(d)};else {let y=o(h+1);u={x:c.x-y.x*r(d),y:c.y-y.y*r(d)};}let p=20;for(let y=1;y<=p;y++){let f=y/p,w=1-f,x=w*w*w*l.x+3*w*w*f*g.x+3*w*f*f*u.x+f*f*f*c.x,v=w*w*w*l.y+3*w*w*f*g.y+3*w*f*f*u.y+f*f*f*c.y;n.push({x,y:v});}}return n}getDisplayLines(e,t,i,n,s,r){let o=n*1.3,h=Math.max(1,Math.floor(r/o)),l=`${t.id}\0${i}\0${n}\0${s}x${r}\0${h}`,c=this.textLayoutCache.get(l);if(c)return c;let d=i.split(`
2
- `),g=[];for(let p of d){let y=this.wrapLine(e,p,s);for(let f of y)g.push(f);}let u=g.slice(0,h);return g.length>h&&u.length>0&&(u[u.length-1]=this.truncateLine(e,u[u.length-1],s)),this.textLayoutCache.size>=a.TEXT_CACHE_LIMIT&&this.textLayoutCache.clear(),this.textLayoutCache.set(l,u),u}drawShapeText(e,t){let i=t.text||"";if(!i)return;let n=t.fontSize||16;e.font=`${n}px sans-serif`,e.fillStyle=t.textColor||"#1f2937";let s=this.getTextBounds(t),r=n*1.3,o=this.getDisplayLines(e,t,i,n,s.width,s.height),l=-(o.length*r)/2+r/2,c=Ue(t);e.textAlign="center",e.textBaseline="middle",o.forEach((d,g)=>{let u=l+g*r;e.fillText(d,c,u);});}getTextBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "uml-class":case "uml-interface":return {width:e.width*.85,height:e.height*.85};case "brace-left":case "brace-right":return {width:e.width*(1-be)*.85,height:e.height*.85};case "circle":return {width:e.radius*2*.85,height:e.radius*2*.85};default:return {width:100,height:40}}}wrapLine(e,t,i){if(!t)return [""];let n=[],s="";for(let r of t){let o=s+r;e.measureText(o).width>i&&s?(n.push(s),s=r):s=o;}return s&&n.push(s),n}truncateLine(e,t,i){if(!t)return "...";let n="...",s=t;for(;s.length>0&&e.measureText(s+n).width>i;)s=s.slice(0,-1);return s+n}static HANDLE_NORMALS=xe;pickAutoHandle(e,t,i){return we(e,t,i)}resolveAutoEndBinding(e,t,i,n){if(!e.auto||e.isPrecise)return e;let s=t.startBinding?.handle?a.HANDLE_NORMALS[t.startBinding.handle]:void 0;return {...e,handle:this.pickAutoHandle(i,{x:n.x,y:n.y},s)}}getBindingPoint(e,t){if(t.isPrecise&&t.normalizedAnchor){let i=this.getShapePageBounds(e),n={x:i.x+i.width*t.normalizedAnchor.x,y:i.y+i.height*t.normalizedAnchor.y},s={x:e.x,y:e.y};return this.nearestPointOnShapeOutline(e,s,n)}if(t.handle){let i=this.getShapeBounds(e);switch(t.handle){case "top":return {x:e.x,y:e.y+i.y};case "bottom":return {x:e.x,y:e.y+i.y+i.height};case "left":return {x:e.x+i.x,y:e.y};case "right":return {x:e.x+i.x+i.width,y:e.y}}}return {x:e.x,y:e.y}}resolveDockNormal(e,t,i,n){return e&&!e.isPrecise&&e.handle?a.HANDLE_NORMALS[e.handle]:this.getDockNormal(t,i,n,e?.toShapeId)}getDockNormal(e,t,i,n){if(!t||t.size===0)return;let s=null,r=1/0,o=.5;if(t.forEach((d,g)=>{if(g===i||d.type==="line"||d.type==="arrow")return;let u=this.getShapePageBounds(d);if(e.x>=u.x-o&&e.x<=u.x+u.width+o&&e.y>=u.y-o&&e.y<=u.y+u.height+o){let p=d.id===n?-1:(e.x-d.x)**2+(e.y-d.y)**2;p<r&&(r=p,s=d);}}),!s)return;let h=s,l=e.x-h.x,c=e.y-h.y;return Math.abs(c)>Math.abs(l)?{x:0,y:c<0?-1:1}:{x:l<0?-1:1,y:0}}getShapePageBounds(e){let t=this.getShapeBounds(e);return {x:e.x+t.x,y:e.y+t.y,width:t.width,height:t.height}}clampToShapeOutline(e,t,i,n){if(!t||t.size===0)return e;let s=null,r=1/0;if(t.forEach((h,l)=>{if(l===i)return;let c=this.getShapePageBounds(h);if(e.x>c.x&&e.x<c.x+c.width&&e.y>c.y&&e.y<c.y+c.height){let d=(h.x-n.x)**2+(h.y-n.y)**2;d<r&&(r=d,s=h);}}),!s)return e;let o=s;return this.nearestPointOnShapeOutline(o,{x:o.x,y:o.y},e)}nearestPointOnShapeOutline(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=Math.hypot(n,s);if(r<1e-6)return {x:t.x,y:t.y};let o=n/r,h=s/r,l=Math.max(1e4,r*2),c={x:t.x+o*l,y:t.y+h*l},d=this.intersectShapeOutlineWithSegment(e,t,c);if(d.length===0)return i;let g=d[0],u=(g.x-t.x)**2+(g.y-t.y)**2;for(let p=1;p<d.length;p++){let y=(d[p].x-t.x)**2+(d[p].y-t.y)**2;y<u&&(u=y,g=d[p]);}return g}intersectShapeOutlineWithSegment(e,t,i){let n={x:t.x-e.x,y:t.y-e.y},s={x:i.x-e.x,y:i.y-e.y};return this.intersectLocalShapeOutlineWithSegment(e,n,s).map(o=>({x:o.x+e.x,y:o.y+e.y}))}intersectLocalShapeOutlineWithSegment(e,t,i){switch(e.type){case "rectangle":case "rounded-rectangle":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "ellipse":case "diamond":case "triangle":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "circle":{let n=e.radius;return this.intersectSegmentCircle(t,i,{x:0,y:0},n)}default:return []}}intersectSegmentRect(e,t,i){let n=i.x,s=i.y,r=i.width,o=i.height,h=[[{x:n,y:s},{x:n+r,y:s}],[{x:n+r,y:s},{x:n+r,y:s+o}],[{x:n+r,y:s+o},{x:n,y:s+o}],[{x:n,y:s+o},{x:n,y:s}]],l=[];for(let[c,d]of h){let g=this.segmentIntersection(e,t,c,d);g&&l.push(g);}return l}segmentIntersection(e,t,i,n){let s=e.x,r=e.y,o=t.x,h=t.y,l=i.x,c=i.y,d=n.x,g=n.y,u=(s-o)*(c-g)-(r-h)*(l-d);if(Math.abs(u)<1e-9)return null;let p=((s-l)*(c-g)-(r-c)*(l-d))/u,y=-((s-o)*(r-c)-(r-h)*(s-l))/u;return p<0||p>1||y<0||y>1?null:{x:s+p*(o-s),y:r+p*(h-r)}}intersectSegmentCircle(e,t,i,n){let s=t.x-e.x,r=t.y-e.y,o=e.x-i.x,h=e.y-i.y,l=s*s+r*r,c=2*(o*s+h*r),d=o*o+h*h-n*n,g=c*c-4*l*d;if(g<0)return [];g=Math.sqrt(g);let u=(-c-g)/(2*l),p=(-c+g)/(2*l),y=[];return u>=0&&u<=1&&y.push({x:e.x+u*s,y:e.y+u*r}),p>=0&&p<=1&&Math.abs(p-u)>1e-6&&y.push({x:e.x+p*s,y:e.y+p*r}),y}drawArrowHead(e,t,i){let n=Math.atan2(i.y-t.y,i.x-t.x),s=12;e.save(),e.setLineDash([]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x-s*Math.cos(n-Math.PI/6),i.y-s*Math.sin(n-Math.PI/6)),e.moveTo(i.x,i.y),e.lineTo(i.x-s*Math.cos(n+Math.PI/6),i.y-s*Math.sin(n+Math.PI/6)),e.stroke(),e.restore();}drawInheritanceHead(e,t,i){let n=Math.atan2(i.y-t.y,i.x-t.x),s=14,r=i.x,o=i.y,h=i.x-s*Math.cos(n),l=i.y-s*Math.sin(n),c=h+s*.5*Math.cos(n-Math.PI/2),d=l+s*.5*Math.sin(n-Math.PI/2),g=h+s*.5*Math.cos(n+Math.PI/2),u=l+s*.5*Math.sin(n+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle="#ffffff",e.beginPath(),e.moveTo(r,o),e.lineTo(c,d),e.lineTo(g,u),e.closePath(),e.fill(),e.stroke(),e.restore();}drawDiamondHead(e,t,i,n){let s=Math.atan2(i.y-t.y,i.x-t.x),r=14,o=i.x,h=i.y,l=i.x-r*.5*Math.cos(s),c=i.y-r*.5*Math.sin(s),d=i.x-r*Math.cos(s),g=i.y-r*Math.sin(s),u=l+r*.4*Math.cos(s-Math.PI/2),p=c+r*.4*Math.sin(s-Math.PI/2),y=l+r*.4*Math.cos(s+Math.PI/2),f=c+r*.4*Math.sin(s+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle=n?"#1f2937":"#ffffff",e.beginPath(),e.moveTo(o,h),e.lineTo(u,p),e.lineTo(d,g),e.lineTo(y,f),e.closePath(),e.fill(),e.stroke(),e.restore();}drawArrowHeads(e,t,i){if(i!=="none"){if(i==="start"||i==="both"){let n=t[0],s=t[1];this.drawArrowHead(e,s,n);}if(i==="end"||i==="both"){let n=t.length,s=t[n-2],r=t[n-1];this.drawArrowHead(e,s,r);}if(i==="inheritance"){let n=t.length,s=t[n-2],r=t[n-1];this.drawInheritanceHead(e,s,r);}if(i==="aggregation"){let n=t[0],s=t[1];this.drawDiamondHead(e,s,n,false);}if(i==="composition"){let n=t[0],s=t[1];this.drawDiamondHead(e,s,n,true);}if(i==="dependency"){let n=t.length;this.drawArrowHead(e,t[n-2],t[n-1]);}if(i==="realization"){let n=t.length;this.drawInheritanceHead(e,t[n-2],t[n-1]);}}}drawText(e,t){if(!t.text)return;let i=t.fontSize;e.font=`${i}px sans-serif`,e.textAlign="center",e.textBaseline="middle";let n=t.width,s=t.height,r=i*1.3,o=this.getDisplayLines(e,t,t.text,i,n,s),h=o.length*r,l=-h/2+r/2;if(t.highlightColor&&t.highlightColor!=="transparent"){let c=t.highlightOpacity??1;e.fillStyle=c<1?F(t.highlightColor,c):t.highlightColor;let d=i*.15;e.beginPath(),e.roundRect(-n/2-d,-h/2-d,n+d*2,h+d*2,4),e.fill();}e.fillStyle=t.textColor||"#1f2937",o.forEach((c,d)=>{let g=l+d*r;e.fillText(c,0,g);});}drawFreehand(e,t){if(t.points.length<2)return;let i=t.points;e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let n=1;n<i.length-1;n++){let s=(i[n].x+i[n+1].x)/2,r=(i[n].y+i[n+1].y)/2;e.quadraticCurveTo(i[n].x,i[n].y,s,r);}e.lineTo(i[i.length-1].x,i[i.length-1].y),e.stroke();}drawSelectionOutline(e,t,i){let n=this.getShapeBounds(t);e.strokeStyle=D.selection.outline,e.lineWidth=1/i,e.setLineDash([]),e.save(),e.shadowColor=D.selection.shadow,e.shadowBlur=8,e.shadowOffsetX=0,e.shadowOffsetY=0,e.beginPath(),e.roundRect(n.x-2,n.y-2,n.width+4,n.height+4,4),e.stroke(),e.restore(),e.fillStyle=D.selection.outlineFill,e.beginPath(),e.roundRect(n.x-2,n.y-2,n.width+4,n.height+4,4),e.fill();}drawSelectionHandles(e,t,i){let n=8/i;if((t.type==="line"||t.type==="arrow")&&t.points&&t.points.length>=2){let r=t.points.map(l=>({x:l.x-t.x,y:l.y-t.y})),o=r[0],h=r[r.length-1];e.fillStyle=D.selection.handleFill,e.strokeStyle=D.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),[o,h].forEach(l=>{e.beginPath(),e.arc(l.x,l.y,n/2,0,Math.PI*2),e.fill(),e.stroke();});}else {let r=this.getShapeBounds(t),o=n,h=[{x:r.x,y:r.y},{x:r.x+r.width,y:r.y},{x:r.x+r.width,y:r.y+r.height},{x:r.x,y:r.y+r.height}];e.fillStyle=D.selection.handleFill,e.strokeStyle=D.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),h.forEach(g=>{e.beginPath(),e.roundRect(g.x-o/2,g.y-o/2,o,o,2),e.fill(),e.stroke();}),this.drawConnectionDots(e,r,i,1);let l=26/i,c=r.x+r.width/2,d=r.y-l;e.strokeStyle="#94a3b8",e.lineWidth=1.5/i,e.setLineDash([]),e.beginPath(),e.moveTo(c,r.y),e.lineTo(c,d),e.stroke(),e.beginPath(),e.arc(c,d,8/i,0,Math.PI*2),e.fillStyle=D.selection.handleFill,e.fill(),e.strokeStyle=D.primary,e.lineWidth=1.6/i,e.stroke(),this.drawRotateIcon(e,c,d,i);}}drawConnectionDots(e,t,i,n=1){let s=9/i,r=[{x:t.x+t.width/2,y:t.y},{x:t.x+t.width,y:t.y+t.height/2},{x:t.x+t.width/2,y:t.y+t.height},{x:t.x,y:t.y+t.height/2}];e.save(),e.globalAlpha=n,r.forEach(o=>{e.beginPath(),e.arc(o.x,o.y,s,0,Math.PI*2),e.fillStyle=D.selection.handleFill,e.fill(),e.strokeStyle=D.primary,e.lineWidth=1.5/i,e.stroke(),e.beginPath(),e.arc(o.x,o.y,s*.45,0,Math.PI*2),e.fillStyle=D.primary,e.fill();}),e.restore();}drawRotateIcon(e,t,i,n){let s=8/n;e.save(),e.translate(t,i),e.strokeStyle=D.primary,e.lineWidth=1.8/n,e.lineCap="round",e.beginPath(),e.arc(0,0,s*.5,Math.PI*.18,Math.PI*1.6,false),e.stroke();let r=Math.PI*.18,o=Math.cos(r)*s*.5,h=Math.sin(r)*s*.5,l=1;e.beginPath(),e.moveTo(o,h),e.lineTo(o-Math.cos(r)*s*.26+l*Math.sin(r)*s*.16,h-Math.sin(r)*s*.26-l*Math.cos(r)*s*.16),e.moveTo(o,h),e.lineTo(o-Math.cos(r)*s*.26-l*Math.sin(r)*s*.16,h-Math.sin(r)*s*.26+l*Math.cos(r)*s*.16),e.stroke(),e.restore();}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:-e.width/2,y:-e.height/2,width:e.width,height:e.height};case "circle":return {x:-e.radius,y:-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(e.points.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x-e.x),i=Math.min(i,r.y-e.y),n=Math.max(n,r.x-e.x),s=Math.max(s,r.y-e.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e;if(typeof t.width=="number"&&typeof t.height=="number")return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height};if(t.points.length===0)return {x:0,y:0,width:0,height:0};let i=1/0,n=1/0,s=-1/0,r=-1/0;return t.points.forEach(o=>{let h=o.x-t.x,l=o.y-t.y;i=Math.min(i,h),n=Math.min(n,l),s=Math.max(s,h),r=Math.max(r,l);}),{x:i,y:n,width:s-i,height:r-n}}case "text":{let t=e;return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}}default:return {x:0,y:0,width:0,height:0}}}};var he={create(a=0,e=0){return {x:a,y:e}},add(a,e){return {x:a.x+e.x,y:a.y+e.y}},subtract(a,e){return {x:a.x-e.x,y:a.y-e.y}},multiply(a,e){return {x:a.x*e,y:a.y*e}},divide(a,e){return {x:a.x/e,y:a.y/e}},dot(a,e){return a.x*e.x+a.y*e.y},length(a){return Math.sqrt(a.x*a.x+a.y*a.y)},normalize(a){let e=he.length(a);return e===0?{x:0,y:0}:{x:a.x/e,y:a.y/e}},distance(a,e){return he.length(he.subtract(a,e))},rotate(a,e){let t=Math.cos(e),i=Math.sin(e);return {x:a.x*t-a.y*i,y:a.x*i+a.y*t}},clone(a){return {x:a.x,y:a.y}},equals(a,e){return a.x===e.x&&a.y===e.y}};function te(a,e,t,i=8){let n=[];if(t==="horizontal"){let s=Math.min(a.x,e.x),r=Math.max(a.x+a.width,e.x+e.width),o=Math.abs(a.y-e.y)<=i,h=Math.abs(a.y+a.height-(e.y+e.height))<=i,l=Math.abs(a.y+a.height/2-(e.y+e.height/2))<=i;o&&n.push({type:"horizontal",position:(a.y+e.y)/2,start:s,end:r}),h&&n.push({type:"horizontal",position:(a.y+a.height+e.y+e.height)/2,start:s,end:r}),l&&!(o&&h)&&n.push({type:"horizontal",position:(a.y+a.height/2+e.y+e.height/2)/2,start:s,end:r});}else {let s=Math.min(a.y,e.y),r=Math.max(a.y+a.height,e.y+e.height),o=Math.abs(a.x-e.x)<=i,h=Math.abs(a.x+a.width-(e.x+e.width))<=i,l=Math.abs(a.x+a.width/2-(e.x+e.width/2))<=i;o&&n.push({type:"vertical",position:(a.x+e.x)/2,start:s,end:r}),h&&n.push({type:"vertical",position:(a.x+a.width+e.x+e.width)/2,start:s,end:r}),l&&!(o&&h)&&n.push({type:"vertical",position:(a.x+a.width/2+e.x+e.width/2)/2,start:s,end:r});}return n}var Se=class a extends N{type="select";state="idle";translatingState=null;resizingState=null;generatingState=null;hoverGenPoint=null;hoverShapeId=null;rotatingState=null;draggingArrowId=null;draggingTerminal=null;pendingHistoryCommit=false;brushStart={x:0,y:0};brushShiftKey=false;defaultGenType(e){if(e){let t=this.context.getShapes().find(i=>i.id===e);if(t&&He(t.type))return t.type}return "rectangle"}genPreviewOf(e,t,i={}){let n=this.context.getArrowStyle();return {from:e.point,to:t,type:i.type,sourceShapeId:e.sourceShapeId,sourceEdge:e.edge,targetShapeId:i.targetShapeId,targetBinding:i.targetBinding,dragging:i.dragging,arrowStyle:{connectionType:"polyline",arrowHead:n.arrowHead,dashed:n.dashed},lineStyle:this.context.getLineStyle()}}genContext(e,t){return {from:e.point,to:t,sourceShapeId:e.sourceShapeId,edge:e.edge}}onPointerDown(e,t){let i=this.context.getShapes(),n=this.context.getSelectedIds(),s=this.hitTestArrowTerminal(e,i);if(s&&n.includes(s.shapeId)){this.state="dragging-terminal",this.draggingArrowId=s.shapeId,this.draggingTerminal=s.terminal,this.pendingHistoryCommit=true,this.context.updateArrowBinding(s.shapeId,s.terminal,null);return}let r=this.hoverShapeId??this.findHoverAnchorShape(e,i,n),o=this.hitGenPoint(e,i,n,r);if(o){this.state="generating",this.hoverShapeId=r,this.generatingState={source:o,startPoint:e,hasMoved:false,sourceWasSelected:!!o.sourceShapeId&&n.includes(o.sourceShapeId)},this.pendingHistoryCommit=true,this.context.setGenerationPreview(this.genPreviewOf(o,this.genPreviewTarget(o,e,false),{type:this.defaultGenType(o.sourceShapeId)}));return}let h=this.hitTest(e,i,n);if(h.handle==="rotation"){this.state="rotating",this.pendingHistoryCommit=true;let l=h.shape;this.rotatingState={shapeId:l.id,center:{x:l.x,y:l.y},startAngle:Math.atan2(e.y-l.y,e.x-l.x),startRotation:l.rotation};return}if(h.handle&&h.shape&&h.shape.type!=="mind-map"){this.state="resizing",this.resizingState={startPoint:e,startShape:h.shape,handle:h.handle},this.pendingHistoryCommit=true;return}if(h.shape){let l=h.shape,c=l.type==="line"||l.type==="arrow",d=n.includes(l.id);if(c&&!d){this.context.selectShape(l.id,t.shiftKey);return}this.state="translating",this.pendingHistoryCommit=true,d||this.context.selectShape(l.id,t.shiftKey);let g=this.context.getSelectedIds(),u=new Map,p=new Map,y=new Map;g.forEach(f=>{let w=i.find(x=>x.id===f);w&&(u.set(f,{x:w.x,y:w.y}),p.set(f,w.rotation),y.set(f,this.getShapeWorldBounds(w)));}),this.translatingState={startPoint:e,startPositions:u,startRotation:p,startBounds:y};}else this.state="brushing",this.brushStart=e,this.brushShiftKey=t.shiftKey,t.shiftKey||this.context.selectShape("",false);}onPointerMove(e,t){let i=this.context.getShapes();if(this.state==="translating"&&this.translatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleTranslating(e,t);else if(this.state==="generating"&&this.generatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleGenerating(e,i);else if(this.state==="rotating"&&this.rotatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleRotating(e,t);else if(this.state==="resizing"&&this.resizingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleResizing(e);else if(this.state==="dragging-terminal"&&this.draggingArrowId&&this.draggingTerminal){this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false);let n=i.find(s=>s.id===this.draggingArrowId);if(n){let s=this.draggingTerminal==="start"?e:n.points[n.points.length-1],r=this.draggingTerminal==="start"?n.points[0]:e,o=this.computeSnapGuidesForArrow(s,r,e,n,i);this.context.setSnapGuides(o);let h=e;if(o.length>0){let d=o.filter(u=>u.type==="horizontal"),g=o.filter(u=>u.type==="vertical");if(d.length>0){let u=d[0].position,p=Math.abs(e.y-u);for(let y of d){let f=Math.abs(e.y-y.position);f<p&&(p=f,u=y.position);}h={...h,y:u};}else if(g.length>0){let u=g[0].position,p=Math.abs(e.x-u);for(let y of g){let f=Math.abs(e.x-y.position);f<p&&(p=f,u=y.position);}h={...h,x:u};}}let l=this.draggingTerminal==="start"?0:n.points.length-1,c=[...n.points];c[l]=h,this.context.updateShape(this.draggingArrowId,{points:c});}}else if(this.state==="brushing")this.handleBrushing(e);else {let n=this.context.getSelectedIds(),s=this.hitGenPoint(e,i,n,this.hoverShapeId);s?(this.hoverGenPoint=s,this.context.setGenerationPreview(this.genPreviewOf(s,this.genPreviewTarget(s,e,false),{type:this.defaultGenType(s.sourceShapeId)}))):(this.hoverGenPoint=null,this.context.setGenerationPreview(null));let r=this.findHoverAnchorShape(e,i,n);r!==this.hoverShapeId&&(this.hoverShapeId=r,this.context.setHoverAnchorShape(r));}}onPointerUp(e,t){if(this.state==="dragging-terminal"&&this.draggingArrowId&&this.draggingTerminal){let i=this.context.getShapes(),n=this.findBindingNearPoint(e,i,this.draggingArrowId);n&&this.context.updateArrowBinding(this.draggingArrowId,this.draggingTerminal,n.toShapeId,n.binding);}if(this.state==="generating"&&this.generatingState){let i=this.generatingState,n=this.context.getShapes(),s=i.source,r=this.findBindingNearPoint(e,n,s.sourceShapeId);if(r)this.context.connectToExisting(this.genContext(s,e),r.toShapeId,r.binding);else if(!i.hasMoved)i.sourceWasSelected?this.context.createGeneratedConnection(this.genContext(s,this.genPreviewTarget(s,s.point,false)),{type:this.defaultGenType(s.sourceShapeId)}):s.sourceShapeId&&this.context.selectShape(s.sourceShapeId,false);else {let o=this.defaultGenType(s.sourceShapeId),h=this.avoidSourceOverlap(s,e,o),l=this.context.createFloatingLine(this.genContext(s,this.futureDockPoint(s,h,o)));this.context.openGenerationMenu({context:this.genContext(s,h),existingArrowId:l,defaultShapeType:o});}this.generatingState=null;}this.state==="brushing"&&this.context.setBrushRect(null),this.context.setGenerationPreview(null),this.context.setConnectingTarget(null),this.hoverGenPoint=null,this.pendingHistoryCommit=false,this.state="idle",this.draggingArrowId=null,this.draggingTerminal=null,this.translatingState=null,this.resizingState=null,this.rotatingState=null,this.context.setSnapGuides([]);}hasTransientState(){return this.state!=="idle"||!!this.generatingState}cancelTransient(){let e=this.state!=="idle"||!!this.generatingState||!!this.hoverGenPoint||!!this.hoverShapeId||this.pendingHistoryCommit;return this.state="idle",this.generatingState=null,this.translatingState=null,this.resizingState=null,this.rotatingState=null,this.draggingArrowId=null,this.draggingTerminal=null,this.pendingHistoryCommit=false,this.hoverGenPoint=null,this.hoverShapeId&&(this.hoverShapeId=null,this.context.setHoverAnchorShape(null)),this.context.setGenerationPreview(null),this.context.setConnectingTarget(null),this.context.setSnapGuides([]),e}onKeyDown(e){let t=e.target;if(!(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable))){if(e.key==="Delete"||e.key==="Backspace"){let i=this.context.getSelectedIds();i.length>0&&(this.context.commitHistory(),i.forEach(n=>{this.context.deleteShape(n);}));}e.key==="Escape"&&(this.context.selectShape("",false),this.cancelTransient()),(e.key==="+"||e.key==="=")&&e.shiftKey&&(this.context.commitHistory(),this.handleRotation(15)),e.key==="-"&&e.shiftKey&&(this.context.commitHistory(),this.handleRotation(-15)),e.key==="ArrowUp"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(0,-5)),e.key==="ArrowDown"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(0,5)),e.key==="ArrowLeft"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(-5,0)),e.key==="ArrowRight"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(5,0));}}onKeyUp(e){}getCursor(e){switch(this.state){case "translating":return "grabbing";case "generating":return "crosshair";case "rotating":return "grabbing";case "resizing":return this.resizingState?this.getHandleCursor(this.resizingState.handle,this.resizingState.startShape):"default";case "dragging-terminal":return "crosshair";case "brushing":return "crosshair"}let t=this.context.getShapes(),i=this.context.getSelectedIds();if(this.context.getMindMapCursorHitAtPoint(e))return "pointer";if(this.hitGenPoint(e,t,i,this.hoverShapeId))return "crosshair";if(this.hitTestArrowTerminal(e,t)&&i.includes(this.hitTestArrowTerminal(e,t).shapeId))return "move";let n=this.hitTest(e,t,i);return n.handle==="rotation"?"grab":n.handle?this.getHandleCursor(n.handle,n.shape):n.shape?"move":null}getHandleCursor(e,t){let n={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315}[e];if(n===void 0)return "grab";let s=((n+t.rotation*180/Math.PI)%360+360)%360,r=Math.round(s/45)%4;return ["ew-resize","nwse-resize","ns-resize","nesw-resize"][r]}static ALIGN_SNAP_THRESHOLD=8;handleTranslating(e,t){if(!this.translatingState)return;let i=he.subtract(e,this.translatingState.startPoint),n={...i};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?n.y=0:n.x=0);let s=this.context.getShapes(),r=this.context.getSelectedIds(),o=new Set(r),h=[],l=[];if(this.translatingState.startBounds.forEach(c=>{l.push({x:c.x+n.x,y:c.y+n.y,width:c.width,height:c.height});}),!t.shiftKey&&l.length>0){let c=[];for(let u of s)o.has(u.id)||u.type==="line"||u.type==="arrow"||u.type==="draw"||c.push(this.getShapeWorldBounds(u));let d=[],g=[];for(let u of l){let p=[u.y,u.y+u.height/2,u.y+u.height],y=[u.x,u.x+u.width/2,u.x+u.width];for(let f of c){let w=[f.y,f.y+f.height/2,f.y+f.height];for(let v of p)for(let b of w){let S=b-v;Math.abs(S)<=a.ALIGN_SNAP_THRESHOLD&&d.push(S);}let x=[f.x,f.x+f.width/2,f.x+f.width];for(let v of y)for(let b of x){let S=b-v;Math.abs(S)<=a.ALIGN_SNAP_THRESHOLD&&g.push(S);}}}if(d.length>0){let u=d[0];for(let p of d)Math.abs(p)<Math.abs(u)&&(u=p);n.y+=u;}if(g.length>0){let u=g[0];for(let p of g)Math.abs(p)<Math.abs(u)&&(u=p);n.x+=u;}this.translatingState.startBounds.forEach(u=>{let p={x:u.x+n.x,y:u.y+n.y,width:u.width,height:u.height};for(let y of c)h.push(...te(p,y,"horizontal",1)),h.push(...te(p,y,"vertical",1));});}this.translatingState.startPositions.forEach((c,d)=>{this.context.updateShape(d,{x:c.x+n.x,y:c.y+n.y});}),this.context.setSnapGuides(this.mergeGuides(h));}handleResizing(e){if(!this.resizingState)return;let t=this.resizingState.startShape,i=this.resizingState.handle,n=this.resizingState.startPoint;if(!i||i==="rotation")return;let r={nw:[-1,-1],n:[0,-1],ne:[1,-1],w:[-1,0],e:[1,0],sw:[-1,1],s:[0,1],se:[1,1]}[i];if(!r)return;let[o,h]=r,l=he.subtract(e,n),c=[];for(let S of this.context.getShapes())S.id!==t.id&&(S.type==="line"||S.type==="arrow"||S.type==="draw"||c.push(this.getShapeWorldBounds(S)));let d=20,g=this.getShapeWorldBounds(t),u=g.x,p=g.y,y=g.x+g.width,f=g.y+g.height;o===1?y=Math.max(u+d,y+l.x):o===-1&&(u=Math.min(y-d,u+l.x)),h===1?f=Math.max(p+d,f+l.y):h===-1&&(p=Math.min(f-d,p+l.y));let w=(S,I)=>{let C=null;for(let H of I){let G=H-S;Math.abs(G)<=a.ALIGN_SNAP_THRESHOLD&&(C===null||Math.abs(G)<Math.abs(C))&&(C=G);}return C};if(o!==0&&c.length>0){let S=[];for(let C of c)S.push(C.x,C.x+C.width/2,C.x+C.width);let I=w(o===1?y:u,S);I!==null&&(o===1?y+=I:u+=I);}if(h!==0&&c.length>0){let S=[];for(let C of c)S.push(C.y,C.y+C.height/2,C.y+C.height);let I=w(h===1?f:p,S);I!==null&&(h===1?f+=I:p+=I);}let x={x:u,y:p,width:y-u,height:f-p},v=[];for(let S of c)o!==0&&v.push(...te(x,S,"vertical",1)),h!==0&&v.push(...te(x,S,"horizontal",1));this.context.setSnapGuides(this.mergeGuides(v));let b={};if(t.type==="circle"){let S=Math.max(10,Math.max(o!==0?x.width/2:0,h!==0?x.height/2:0));if(b.radius=S,o!==0){let I=o===1?g.x:g.x+g.width;b.x=o===1?I+S:I-S;}if(h!==0){let I=h===1?g.y:g.y+g.height;b.y=h===1?I+S:I-S;}}else if("width"in t&&o!==0&&(b.width=x.width,b.x=x.x+x.width/2),"height"in t&&h!==0&&(b.height=x.height,b.y=x.y+x.height/2),t.type==="draw"){let S=this.getShapeWorldBounds(t),I=o!==0?x.width/Math.max(1,S.width):1,C=h!==0?x.height/Math.max(1,S.height):1;b.points=t.points.map(H=>({x:H.x*I,y:H.y*C}));}Object.keys(b).length>0&&this.context.updateShape(t.id,b);}mergeGuides(e){let t=new Map;for(let i of e){let n=`${i.type}\0${Math.round(i.position*2)/2}`,s=t.get(n);s?(s.start=Math.min(s.start,i.start),s.end=Math.max(s.end,i.end)):t.set(n,{...i});}return [...t.values()]}handleRotation(e){let t=this.context.getSelectedIds(),i=this.context.getShapes();t.forEach(n=>{let s=i.find(r=>r.id===n);s&&this.context.updateShape(n,{rotation:s.rotation+e*Math.PI/180});});}handleNudge(e,t){let i=this.context.getSelectedIds(),n=this.context.getShapes();i.forEach(s=>{let r=n.find(o=>o.id===s);r&&this.context.updateShape(s,{x:r.x+e,y:r.y+t});});}handleBrushing(e){let t=Math.min(this.brushStart.x,e.x),i=Math.min(this.brushStart.y,e.y),n=Math.abs(e.x-this.brushStart.x),s=Math.abs(e.y-this.brushStart.y);this.context.setBrushRect({x:t,y:i,width:n,height:s});let r=this.context.getShapes(),o=[];for(let h of r){let l=this.getShapeWorldBounds(h);this.rectsIntersect({x:t,y:i,width:n,height:s},l)&&o.push(h.id);}if(this.brushShiftKey){let h=this.context.getSelectedIds(),l=new Set([...h,...o]);this.context.selectShapes([...l]);}else this.context.selectShapes(o);}getShapeWorldBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(!e.points||e.points.length===0)return {x:e.x,y:e.y,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x),i=Math.min(i,r.y),n=Math.max(n,r.x),s=Math.max(s,r.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e,i=t.width,n=t.height;if(typeof i=="number"&&typeof n=="number"&&i>0&&n>0)return {x:t.x-i/2,y:t.y-n/2,width:i,height:n};if(!t.points||t.points.length===0)return {x:t.x,y:t.y,width:0,height:0};let s=1/0,r=1/0,o=-1/0,h=-1/0;return t.points.forEach(l=>{let c=l.x+t.x,d=l.y+t.y;s=Math.min(s,c),r=Math.min(r,d),o=Math.max(o,c),h=Math.max(h,d);}),{x:s,y:r,width:o-s,height:h-r}}case "text":{let t=e;return {x:e.x-t.width/2,y:e.y-t.height/2,width:t.width,height:t.height}}default:{let t=e;return {x:t.x,y:t.y,width:0,height:0}}}}rectsIntersect(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}hitTest(e,t,i){for(let n=t.length-1;n>=0;n--){let s=t[n];if(i.includes(s.id)){let r=this.getHitHandle(e,s);if(r)return {shape:s,handle:r}}if(this.isPointInShape(e,s))return {shape:s,handle:null}}return {shape:null,handle:null}}getHitHandle(e,t){if(t.type==="mind-map")return null;let i=14,n=this.getShapeBounds(t),s=Math.cos(-t.rotation),r=Math.sin(-t.rotation),o=e.x-t.x,h=e.y-t.y,l=o*s-h*r,c=o*r+h*s,d=[{type:"nw",x:n.x,y:n.y},{type:"ne",x:n.x+n.width,y:n.y},{type:"se",x:n.x+n.width,y:n.y+n.height},{type:"sw",x:n.x,y:n.y+n.height},{type:"rotation",x:n.x+n.width/2,y:n.y-26}];for(let g of d)if(Math.abs(l-g.x)<i&&Math.abs(c-g.y)<i)return g.type;return null}static GEN_HIT_THRESHOLD=14;static CLICK_MOVE_THRESHOLD=6;static GEN_SUPPORTED_TYPES=new Set(["rectangle","rounded-rectangle","ellipse","diamond","triangle","hexagon","parallelogram","trapezoid","pentagon","octagon","star","uml-class","uml-interface","circle","draw","cylinder","cloud","heart","block-arrow-right","block-arrow-left","block-arrow-up","block-arrow-down","block-arrow-double","right-triangle","cross","speech-rect","speech-round","cube","sector","delay","predefined-process","document","stadium","class-catalog","chevron","brace-left","brace-right"]);computeGenPoints(e,t,i){let n=[],s=new Set(t);i&&s.add(i);for(let r of s){let o=e.find(h=>h.id===r);if(o&&a.GEN_SUPPORTED_TYPES.has(o.type)){let h=this.getShapeBounds(o),l={x:o.x,y:o.y};n.push({point:{x:l.x+h.x+h.width/2,y:l.y+h.y},edge:"n",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x+h.width,y:l.y+h.y+h.height/2},edge:"e",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x+h.width/2,y:l.y+h.y+h.height},edge:"s",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x,y:l.y+h.y+h.height/2},edge:"w",sourceShapeId:o.id});}}return n}hitGenPoint(e,t,i,n){let s=a.GEN_HIT_THRESHOLD,r=null,o=s;for(let h of this.computeGenPoints(t,i,n)){let l=Math.hypot(h.point.x-e.x,h.point.y-e.y);l<=o&&(o=l,r=h);}return r}findHoverAnchorShape(e,t,i){for(let s=t.length-1;s>=0;s--){let r=t[s];if(i.includes(r.id)||!a.GEN_SUPPORTED_TYPES.has(r.type))continue;let o=this.getShapeWorldBounds(r);if(!(e.x<o.x-12||e.x>o.x+o.width+12||e.y<o.y-12||e.y>o.y+o.height+12))return r.id}return null}genPreviewTarget(e,t,i){if(i)return t;let n=96;if(e.edge)switch(e.edge){case "n":return {x:e.point.x,y:e.point.y-n};case "s":return {x:e.point.x,y:e.point.y+n};case "e":return {x:e.point.x+n,y:e.point.y};case "w":return {x:e.point.x-n,y:e.point.y}}return {x:e.point.x,y:e.point.y-n}}handleGenerating(e,t){if(!this.generatingState)return;let i=this.generatingState,n=i.source;Math.hypot(e.x-i.startPoint.x,e.y-i.startPoint.y)>a.CLICK_MOVE_THRESHOLD&&(i.hasMoved=true);let r=this.findBindingNearPoint(e,t,n.sourceShapeId),o=this.defaultGenType(n.sourceShapeId),h=this.avoidSourceOverlap(n,e,o),l=r?this.bindingPosition(r.toShapeId,r.binding,t):i.hasMoved?h:this.genPreviewTarget(n,e,false);this.context.setConnectingTarget(r?r.toShapeId:null),this.context.setGenerationPreview(this.genPreviewOf(n,l,{dragging:i.hasMoved,targetShapeId:r?.toShapeId,targetBinding:r?.binding,type:r?void 0:o}));}handleRotating(e,t){if(!this.rotatingState)return;let i=this.rotatingState,n=Math.atan2(e.y-i.center.y,e.x-i.center.x),s=i.startRotation+(n-i.startAngle);t.shiftKey&&(s=Math.round(s/(Math.PI/12))*(Math.PI/12)),this.context.updateShape(i.shapeId,{rotation:s});}bindingPosition(e,t,i){let n=i.find(r=>r.id===e);if(!n)return {x:0,y:0};let s=this.getShapeWorldBounds(n);if(t.handle)switch(t.handle){case "top":return {x:n.x,y:s.y};case "bottom":return {x:n.x,y:s.y+s.height};case "left":return {x:s.x,y:n.y};case "right":return {x:s.x+s.width,y:n.y}}return t.normalizedAnchor?{x:s.x+s.width*t.normalizedAnchor.x,y:s.y+s.height*t.normalizedAnchor.y}:{x:n.x,y:n.y}}isPointInShape(e,t){let i=e.x-t.x,n=e.y-t.y;switch(t.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "circle":return i*i+n*n<=t.radius*t.radius;case "hexagon":return this.isPointInHexagon(i,n,t.width,t.height);case "line":case "arrow":for(let s=0;s<t.points.length-1;s++){let r=t.points[s],o=t.points[s+1];if(this.pointToLineDistance(e,r,o)<10)return true}return false;case "draw":{let s=this.getShapeBounds(t);return Math.abs(i)<=s.width/2&&Math.abs(n)<=s.height/2}case "text":return Math.abs(i)<=50&&Math.abs(n)<=t.fontSize/2;default:return false}}isPointInHexagon(e,t,i,n){let s=Math.abs(e),r=Math.abs(t),o=i/2,h=n/2;return s<=o&&r<=h&&s/o+r/h<=1.5}pointToLineDistance(e,t,i){let n=e.x-t.x,s=e.y-t.y,r=i.x-t.x,o=i.y-t.y,h=n*r+s*o,l=r*r+o*o,c=-1;l!==0&&(c=h/l);let d,g;c<0?(d=t.x,g=t.y):c>1?(d=i.x,g=i.y):(d=t.x+c*r,g=t.y+c*o);let u=e.x-d,p=e.y-g;return Math.sqrt(u*u+p*p)}avoidSourceOverlap(e,t,i){if(!e.sourceShapeId)return t;let n=this.context.getShapes().find(p=>p.id===e.sourceShapeId);if(!n)return t;let s=ee(i,t),r=this.getShapeWorldBounds(s),o=this.getShapeWorldBounds(n),h=Math.min(r.x+r.width,o.x+o.width)-Math.max(r.x,o.x),l=Math.min(r.y+r.height,o.y+o.height)-Math.max(r.y,o.y);if(h<=0||l<=0)return t;let c=24,d={...t},g=t.x-n.x,u=t.y-n.y;return Math.abs(g)>=Math.abs(u)?d.x=g>=0?o.x+o.width+c+r.width/2:o.x-c-r.width/2:d.y=u>=0?o.y+o.height+c+r.height/2:o.y-c-r.height/2,d}futureDockPoint(e,t,i){let n=ee(i,t),s=this.getShapeBounds(n),r=Ne(e.point,t,e.edge);return bt(t,{width:s.width,height:s.height},r)}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:-e.width/2,y:-e.height/2,width:e.width,height:e.height};case "circle":return {x:-e.radius,y:-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(e.points.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x-e.x),i=Math.min(i,r.y-e.y),n=Math.max(n,r.x-e.x),s=Math.max(s,r.y-e.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e;if(typeof t.width=="number"&&typeof t.height=="number")return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height};if(t.points.length===0)return {x:0,y:0,width:0,height:0};let i=1/0,n=1/0,s=-1/0,r=-1/0;return t.points.forEach(o=>{let h=o.x-t.x,l=o.y-t.y;i=Math.min(i,h),n=Math.min(n,l),s=Math.max(s,h),r=Math.max(r,l);}),{x:i,y:n,width:s-i,height:r-n}}case "text":return {x:-50,y:-e.fontSize/2,width:100,height:e.fontSize};default:return {x:0,y:0,width:0,height:0}}}hitTestArrowTerminal(e,t){for(let n of t){if(n.type!=="arrow")continue;let s=n;if(s.points.length<2)continue;let r=s.points[0],o=s.points[s.points.length-1],h=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2)),l=Math.sqrt(Math.pow(e.x-o.x,2)+Math.pow(e.y-o.y,2));if(h<20)return {shapeId:s.id,terminal:"start"};if(l<20)return {shapeId:s.id,terminal:"end"}}return null}findShapeNearPoint(e,t,i){for(let s=t.length-1;s>=0;s--){let r=t[s];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let o;switch(r.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":o=this.pointToRectDistance(e,{x:r.x-r.width/2,y:r.y-r.height/2,width:r.width,height:r.height});break;case "circle":o=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2))-r.radius;break;case "hexagon":{let h=r.width/2,l=r.height/2,c=Math.abs(e.x-r.x),d=Math.abs(e.y-r.y);o=c/h+d/l-1;break}default:continue}if(o<=30)return r}return null}pointToRectDistance(e,t){let i=Math.max(t.x,Math.min(e.x,t.x+t.width)),n=Math.max(t.y,Math.min(e.y,t.y+t.height));return Math.sqrt(Math.pow(e.x-i,2)+Math.pow(e.y-n,2))}static SNAP_THRESHOLD=32;static HANDLE_SNAP_DISTANCE=18;static ANCHOR_EPS=.001;computeSnapGuidesForArrow(e,t,i,n,s){let r=this.draggingTerminal==="start"?n.endBinding:n.startBinding,o=r?s.find(p=>p.id===r.toShapeId):null;if(!o)return [];let h=this.findShapeNearPoint(i,s,n.id);if(!h)return [];let l=this.getShapeWorldBounds(o),c=this.getShapeWorldBounds(h),d=t.x-e.x,g=t.y-e.y,u=Math.abs(d)>=Math.abs(g)?"horizontal":"vertical";return te(l,c,u)}findBindingNearPoint(e,t,i){let n;for(let s=t.length-1;s>=0;s--){let r=t[s];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let o=this.getPageBounds(r),h=a.SNAP_THRESHOLD;if(e.x<o.x-h||e.x>o.x+o.width+h||e.y<o.y-h||e.y>o.y+o.height+h)continue;let l={x:r.x,y:r.y},c=[{handle:"top",pos:{x:l.x,y:o.y}},{handle:"bottom",pos:{x:l.x,y:o.y+o.height}},{handle:"left",pos:{x:o.x,y:l.y}},{handle:"right",pos:{x:o.x+o.width,y:l.y}}];for(let u of c){let p=Math.hypot(u.pos.x-e.x,u.pos.y-e.y);p<=a.HANDLE_SNAP_DISTANCE&&(!n||p<n.distance)&&(n={toShapeId:r.id,binding:{toShapeId:r.id,handle:u.handle,isPrecise:false},distance:p});}let d=this.nearestPointOnShapeOutline(r,e);if(d&&d.distance<=a.SNAP_THRESHOLD&&(!n||d.distance<n.distance)){let u=this.computeNormalizedAnchor(o,d.point);n={toShapeId:r.id,binding:{toShapeId:r.id,isPrecise:true,normalizedAnchor:u},distance:d.distance};}e.x>o.x&&e.x<o.x+o.width&&e.y>o.y&&e.y<o.y+o.height&&(!n||n.distance>0)&&(n={toShapeId:r.id,binding:{toShapeId:r.id,auto:true},distance:0});}if(n)return {toShapeId:n.toShapeId,binding:n.binding}}getPageBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};default:return {x:e.x-50,y:e.y-50,width:100,height:100}}}computeNormalizedAnchor(e,t){let i=a.ANCHOR_EPS,n=e.width>0?(t.x-e.x)/e.width:.5,s=e.height>0?(t.y-e.y)/e.height:.5;return n=Math.max(i,Math.min(1-i,n)),s=Math.max(i,Math.min(1-i,s)),{x:n,y:s}}nearestPointOnShapeOutline(e,t){let i={x:t.x-e.x,y:t.y-e.y},n=this.nearestLocalPointOnShapeOutline(e,i);if(!n)return null;let s={x:n.point.x+e.x,y:n.point.y+e.y};return {point:s,distance:Math.hypot(s.x-t.x,s.y-t.y)}}nearestLocalPointOnShapeOutline(e,t){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":{let i=e.width,n=e.height;return this.nearestPointOnRectOutlineLocal(t,{x:-i/2,y:-n/2,width:i,height:n})}case "circle":{let i=e.radius;return this.nearestPointOnCircleOutlineLocal(t,{x:0,y:0},i)}default:return null}}nearestPointOnRectOutlineLocal(e,t){let i=[[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y}],[{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height}],[{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],[{x:t.x,y:t.y+t.height},{x:t.x,y:t.y}]],n=null;for(let[s,r]of i){let o=this.nearestPointOnSegment(e,s,r);(!n||o.distance<n.distance)&&(n=o);}return n}nearestPointOnCircleOutlineLocal(e,t,i){let n=e.x-t.x,s=e.y-t.y,r=Math.hypot(n,s);if(r<1e-9)return {point:{x:t.x+i,y:t.y},distance:i};let o=t.x+n/r*i,h=t.y+s/r*i,l={x:o,y:h};return {point:l,distance:Math.hypot(l.x-e.x,l.y-e.y)}}nearestPointOnSegment(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=n*n+s*s,o=r>0?((e.x-t.x)*n+(e.y-t.y)*s)/r:0;o=Math.max(0,Math.min(1,o));let h=t.x+o*n,l=t.y+o*s,c={x:h,y:l};return {point:c,distance:Math.hypot(c.x-e.x,c.y-e.y)}}};var Me=class a extends N{type="hand";state="idle";startScreenPoint={x:0,y:0};initialCameraPos={x:0,y:0};static DRAG_THRESHOLD=4;onPointerDown(e,t){this.startScreenPoint={x:t.clientX,y:t.clientY};let i=this.context.getCamera();this.initialCameraPos={x:i.x,y:i.y},this.state="pointing";}onPointerMove(e,t){if(this.state!=="idle"){if(this.state==="pointing"){let i=t.clientX-this.startScreenPoint.x,n=t.clientY-this.startScreenPoint.y;if(Math.hypot(i,n)<a.DRAG_THRESHOLD)return;this.state="dragging",this.applyCameraDelta(i,n);return}if(this.state==="dragging"){let i=t.clientX-this.startScreenPoint.x,n=t.clientY-this.startScreenPoint.y;this.applyCameraDelta(i,n);}}}onPointerUp(e,t){if(this.state!=="idle"){if(this.state==="dragging"){let i=this.context.getCamera();this.initialCameraPos={x:i.x,y:i.y},this.startScreenPoint={x:t.clientX,y:t.clientY};}this.state="idle";}}onKeyDown(e){e.key==="Escape"&&this.state!=="idle"&&(this.context.setCameraPosition(this.initialCameraPos.x,this.initialCameraPos.y),this.state="idle");}onKeyUp(e){}getCursor(e){return this.state==="dragging"||this.state==="pointing"?"grabbing":"grab"}applyCameraDelta(e,t){this.context.setCameraPosition(this.initialCameraPos.x+e,this.initialCameraPos.y+t);}};var ln={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},ve=class extends N{type="line";isDrawing=false;startPoint={x:0,y:0};currentShape=null;onPointerDown(e,t){this.isDrawing=true,this.startPoint=e,this.currentShape={id:`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,type:"line",x:e.x,y:e.y,points:[e],rotation:0,style:{...ln}},this.context.commitHistory(),this.context.addShape(this.currentShape);}onPointerMove(e,t){!this.isDrawing||!this.currentShape||this.context.updateShape(this.currentShape.id,{points:[this.startPoint,e]});}onPointerUp(e,t){this.isDrawing=false,this.currentShape=null,this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}};var cn={strokeColor:"#1f2937",fillColor:"transparent",fillOpacity:1,strokeWidth:4,strokeDash:null},dn=.5,un=16,Ye="#ffeb3b",gn=4200,ne=class extends N{type;mode;isDrawing=false;points=[];currentShapeId=null;committed=false;fadeTimer=null;highlighterColor=Ye;constructor(e,t){super(e),this.mode=t,this.type=t==="pen"?"pen":"highlighter";}setHighlighterColor(e){this.highlighterColor=e;}getHighlighterColor(){return this.highlighterColor}buildStyle(){return this.mode==="pen"?{...cn}:{strokeColor:F(this.highlighterColor,dn),fillColor:"transparent",fillOpacity:1,strokeWidth:un,strokeDash:null}}onPointerDown(e,t){this.isDrawing=true,this.committed=false,this.currentShapeId=null,this.points=[{...e}];}buildGeometry(e){let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let g of e)g.x<t&&(t=g.x),g.y<i&&(i=g.y),g.x>n&&(n=g.x),g.y>s&&(s=g.y);let r=(t+n)/2,o=(i+s)/2,h=6,l=Math.max(1,n-t)+h*2,c=Math.max(1,s-i)+h*2,d=e.map(g=>({x:g.x-r,y:g.y-o}));return {x:r,y:o,width:l,height:c,points:d}}onPointerMove(e,t){if(this.isDrawing){if(this.points.push({...e}),!this.committed&&this.points.length>=2){this.context.commitHistory();let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;this.currentShapeId=i;let n=this.buildGeometry(this.points),s=this.buildStyle(),r={id:i,type:"draw",x:n.x,y:n.y,width:n.width,height:n.height,points:n.points,rotation:0,style:s};this.context.addShape(r),this.committed=true;}else if(this.committed&&this.currentShapeId){let i=this.buildGeometry(this.points);this.context.updateShape(this.currentShapeId,{x:i.x,y:i.y,width:i.width,height:i.height,points:i.points});}}}onPointerUp(e,t){if(!this.isDrawing||(this.isDrawing=false,!this.committed||!this.currentShapeId))return;let i=this.currentShapeId;this.currentShapeId=null,this.mode==="highlighter"&&(this.fadeTimer=setTimeout(()=>{this.context.deleteShape(i);},gn));}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}dispose(){this.fadeTimer&&(clearTimeout(this.fadeTimer),this.fadeTimer=null);}};var pn={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},yn=4,Pe=class extends N{type="arrow";isDrawing=false;startPoint={x:0,y:0};currentShapeId=null;startBindingInfo=null;startBinding;onPointerDown(e,t){this.isDrawing=true,this.startPoint=e,this.startBindingInfo=null,this.currentShapeId=null;let i=this.context.getShapes(),n=this.findShapeBinding(e,i),s=e;n&&(s=this.getBindingPosition(n.toShapeId,n.handle,i),this.startBindingInfo={...n,position:s}),this.startPoint=s,this.startBinding=n?{toShapeId:n.toShapeId,handle:n.handle}:void 0;}onPointerMove(e,t){if(!this.isDrawing)return;let i=this.context.getShapes(),n=this.findShapeBinding(e,i),s=e;n&&(s=this.getBindingPosition(n.toShapeId,n.handle,i));let r=this.startPoint;if(!this.currentShapeId){if(Math.hypot(s.x-r.x,s.y-r.y)<yn)return;let l=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,c=this.context.getArrowStyle(),d={id:l,type:"arrow",x:r.x,y:r.y,points:[r,s],rotation:0,style:{...pn},startBinding:this.startBinding,connectionType:c.connectionType,arrowHead:c.arrowHead,dashed:c.dashed};this.context.commitHistory(),this.context.addShape(d),this.currentShapeId=l;}let o=this.computeSnapGuides(r,s,n,i);this.context.setSnapGuides(o),this.context.updateShape(this.currentShapeId,{points:[r,s],endBinding:n?{toShapeId:n.toShapeId,handle:n.handle,auto:true}:void 0});}onPointerUp(e,t){let i=!!this.currentShapeId;this.isDrawing=false,this.currentShapeId=null,this.startBindingInfo=null,this.startBinding=void 0,this.context.setSnapGuides([]),i&&this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}computeSnapGuides(e,t,i,n){let s=this.startBindingInfo?n.find(g=>g.id===this.startBindingInfo.toShapeId):null,r=i?n.find(g=>g.id===i.toShapeId):null;if(!s||!r)return [];let o=this.getShapeBounds(s),h=this.getShapeBounds(r),l=t.x-e.x,c=t.y-e.y,d=Math.abs(l)>=Math.abs(c)?"horizontal":"vertical";return te(o,h,d)}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};case "text":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};default:return {x:e.x-50,y:e.y-20,width:100,height:40}}}findShapeBinding(e,t){for(let n=t.length-1;n>=0;n--){let s=t[n];if(s.type==="arrow"||s.type==="line"||s.type==="draw")continue;let r;switch(s.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "uml-class":case "uml-interface":r=this.pointToRectDistance(e,{x:s.x-s.width/2,y:s.y-s.height/2,width:s.width,height:s.height});break;case "circle":{let o=Math.sqrt(Math.pow(e.x-s.x,2)+Math.pow(e.y-s.y,2));r=Math.abs(o-s.radius);break}case "hexagon":{let o=s.width/2,h=s.height/2,l=Math.abs(e.x-s.x),c=Math.abs(e.y-s.y);r=l/o+c/h-1;break}default:continue}if(r<=40){let o=this.getClosestHandle(e,s);return {toShapeId:s.id,handle:o}}}}pointToRectDistance(e,t){let i=Math.max(t.x,Math.min(e.x,t.x+t.width)),n=Math.max(t.y,Math.min(e.y,t.y+t.height));return Math.sqrt(Math.pow(e.x-i,2)+Math.pow(e.y-n,2))}getClosestHandle(e,t){let i=e.x-t.x,n=e.y-t.y;if(t.type==="circle"||t.type==="hexagon"){let l=Math.atan2(n,i);return l>=-Math.PI/4&&l<Math.PI/4?"right":l>=Math.PI/4&&l<3*Math.PI/4?"bottom":l>=3*Math.PI/4||l<-(3*Math.PI)/4?"left":"top"}let s="width"in t?t.width:100,r="height"in t?t.height:100,o=Math.abs(i)/(s/2),h=Math.abs(n)/(r/2);return o>h?i>0?"right":"left":n>0?"bottom":"top"}getBindingPosition(e,t,i){let n=i.find(s=>s.id===e);if(!n)return {x:0,y:0};switch(n.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":return this.getRectBindingPosition(n,t);case "circle":return this.getCircleBindingPosition(n,t);case "hexagon":return this.getRectBindingPosition(n,t);default:return {x:n.x,y:n.y}}}getRectBindingPosition(e,t){switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}}getCircleBindingPosition(e,t){switch(t){case "top":return {x:e.x,y:e.y-e.radius};case "bottom":return {x:e.x,y:e.y+e.radius};case "left":return {x:e.x-e.radius,y:e.y};case "right":return {x:e.x+e.radius,y:e.y}}}};var fn={strokeColor:"transparent",fillColor:"transparent",strokeWidth:0,strokeDash:null},Xe=class extends N{type="text";onPointerDown(e,t){let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n={id:i,type:"text",x:e.x,y:e.y,rotation:0,style:{...fn},text:"",fontSize:16,textColor:"#1f2937",width:200,height:24};this.context.commitHistory(),this.context.addShape(n),this.context.enterEditing(i);}onPointerMove(e,t){}onPointerUp(e,t){}onKeyDown(e){}onKeyUp(e){}getCursor(){return "text"}};var pe="#1f2937";function st(a){switch(a.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":case "text":return {x:-(a.width/2),y:-(a.height/2),width:a.width,height:a.height};case "circle":return {x:-a.radius,y:-a.radius,width:a.radius*2,height:a.radius*2};case "line":case "arrow":{let e=a.points;if(!e||e.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let r of e){let o=r.x-a.x,h=r.y-a.y;t=Math.min(t,o),i=Math.min(i,h),n=Math.max(n,o),s=Math.max(s,h);}return {x:t,y:i,width:n-t,height:s-i}}case "draw":{let e=a,t=e.width,i=e.height;if(typeof t=="number"&&typeof i=="number")return {x:-t/2,y:-i/2,width:t,height:i};let n=e.points;if(!n||n.length===0)return {x:0,y:0,width:0,height:0};let s=1/0,r=1/0,o=-1/0,h=-1/0;for(let l of n)s=Math.min(s,l.x),r=Math.min(r,l.y),o=Math.max(o,l.x),h=Math.max(h,l.y);return {x:s,y:r,width:o-s,height:h-r}}default:return {x:0,y:0,width:0,height:0}}}function mn(a){let e=st(a),t=Math.cos(a.rotation),i=Math.sin(a.rotation),n=1/0,s=1/0,r=-1/0,o=-1/0,h=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]];for(let[l,c]of h){let d=l*t-c*i+a.x,g=l*i+c*t+a.y;n=Math.min(n,d),s=Math.min(s,g),r=Math.max(r,d),o=Math.max(o,g);}return {x:n,y:s,width:r-n,height:o-s}}function Ce(a,e=24){if(!a||a.length===0)return {x:0,y:0,width:400,height:300};let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let r of a){let o=mn(r);t=Math.min(t,o.x),i=Math.min(i,o.y),n=Math.max(n,o.x+o.width),s=Math.max(s,o.y+o.height);}return {x:t-e,y:i-e,width:n-t+e*2,height:s-i+e*2}}function Dt(a,e={}){let t=e.padding??24,i=e.scale??2,n=e.background===void 0?"#ffffff":e.background??null,s=Ce(a,t),r=Math.max(1,Math.ceil(s.width)),o=Math.max(1,Math.ceil(s.height)),h=document.createElement("canvas");h.width=Math.ceil(r*i),h.height=Math.ceil(o*i);let l=new ae(h,i);l.resize(r*i,o*i);let c=new re;return c.zoom=1,c.x=-s.x,c.y=-s.y,l.render(a,c,new Set,void 0,void 0,void 0,void 0,void 0,void 0,void 0,n),h}function xn(a,e,t){return new Promise((i,n)=>{a.toBlob(s=>{s?i(s):n(new Error("canvas.toBlob failed"));},e,t);})}function wn(a,e,t){return a.toDataURL(e,t)}var Ie=null;function se(a,e){return Ie||(Ie=document.createElement("canvas").getContext("2d")),Ie?(Ie.font=e,Ie.measureText(a).width):a.length*8}function ye(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function rt(a,e,t,i){let n=e*1.3,s=Math.max(1,Math.floor(i/n)),r=`${e}px sans-serif`,o=a.split(`
3
- `),h=[];for(let c of o){let d="";for(let g of c){let u=d+g;se(u,r)>t&&d?(h.push(d),d=g):d=u;}d&&h.push(d);}let l=h.slice(0,s);if(h.length>s&&l.length>0){let c=l[l.length-1],d="...";for(;c.length>0&&se(c+d,r)>t;)c=c.slice(0,-1);l[l.length-1]=c+d;}return l}function ot(a,e,t){if(se(a,t)<=e)return a;let i="\u2026",n=0,s=a.length;for(;n<s;){let r=n+s+1>>1;se(a.slice(0,r)+i,t)<=e?n=r:s=r-1;}return a.slice(0,n)+i}function ie(a){return a.map(([e,t])=>`${m(e)},${m(t)}`).join(" ")}function vt(a){return a.map(e=>e[0]==="Z"?"Z":e[0]==="M"||e[0]==="L"?`${e[0]} ${m(e[1])} ${m(e[2])}`:`C ${m(e[1])} ${m(e[2])} ${m(e[3])} ${m(e[4])} ${m(e[5])} ${m(e[6])}`).join(" ")}function bn(a){let e=a;if(!e.text||a.type==="text"||a.type==="line"||a.type==="arrow"||a.type==="draw")return "";let t=e.fontSize||16,i=a.type==="brace-left"||a.type==="brace-right",n=e.width??(e.radius?e.radius*2:100),s=e.height??(e.radius?e.radius*2:40),r=n*(i?1-be:1)*.85,o=s*.85,h=rt(String(e.text),t,r,o);return ht(h,t,e.textColor||pe,m(Ue(a)))}function m(a){return Math.round(a*100)/100}function Et(a){return a.strokeDash&&a.strokeDash.length?a.strokeDash.join(","):void 0}function Sn(a,e){let t=e.x-a.x,i=e.y-a.y,n=Math.cos(a.rotation),s=Math.sin(a.rotation);return {x:t*n-i*s+a.x,y:t*s+i*n+a.y}}var at=xe;function Mn(a,e,t){return we(a,e,t)}function vn(a,e,t){let i=a.endBinding;if(!i||!i.auto||i.isPrecise)return i;let n=a.startBinding?.handle?at[a.startBinding.handle]:void 0;return {...i,handle:Mn(e,{x:t.x,y:t.y},n)}}function Pt(a,e){if(e.isPrecise&&e.normalizedAnchor){let t=st(a),i=a.x+t.x+t.width*e.normalizedAnchor.x,n=a.y+t.y+t.height*e.normalizedAnchor.y;return {x:i,y:n}}if(e.handle){let t=st(a);switch(e.handle){case "top":return {x:a.x,y:a.y+t.y};case "bottom":return {x:a.x,y:a.y+t.y+t.height};case "left":return {x:a.x+t.x,y:a.y};case "right":return {x:a.x+t.x+t.width,y:a.y}}}return {x:a.x,y:a.y}}function Pn(a,e){let t=a.points.map(s=>({...s})),i,n;if(t.length===0)return {pts:t,fromN:i,toN:n};if(a.startBinding){let s=e.get(a.startBinding.toShapeId);s&&(t[0]=Pt(s,a.startBinding),!a.startBinding.isPrecise&&a.startBinding.handle&&(i=at[a.startBinding.handle]));}if(a.endBinding){let s=e.get(a.endBinding.toShapeId);if(s){let r=vn(a,t[0],s)??a.endBinding;t[t.length-1]=Pt(s,r),!r.isPrecise&&r.handle&&(n=at[r.handle]);}}return {pts:t.map(s=>Sn(a,s)),fromN:i,toN:n}}function In(a){if(a.length<2)return a;let e=a[0],t=a[a.length-1],i=t.x-e.x,n=t.y-e.y,s=8;if(Math.abs(n)<=s){let r=(e.y+t.y)/2;return a.map(o=>({x:o.x,y:r}))}if(Math.abs(i)<=s){let r=(e.x+t.x)/2;return a.map(o=>({x:r,y:o.y}))}return a}function Tn(a){if(a.length<2)return a;let e=[a[0]];for(let t=1;t<a.length;t++){let i=a[t-1],n=a[t],s=(i.x+n.x)/2,r=(i.y+n.y)/2;Math.abs(n.x-i.x)>=Math.abs(n.y-i.y)?(e.push({x:s,y:i.y}),e.push({x:s,y:n.y})):(e.push({x:i.x,y:r}),e.push({x:n.x,y:r})),e.push(n);}return e}function Cn(a){if(a.length<2)return "";let e=`M ${m(a[0].x)} ${m(a[0].y)}`,t=a[0];for(let i=1;i<a.length;i++){let n=a[i],s=n.x-t.x,r=n.y-t.y,o=Math.hypot(s,r),h={x:(t.x+n.x)/2,y:(t.y+n.y)/2};if(o>=1){let l=-r/o,c=s/o,d=Math.min(o*.2,30);h={x:h.x+l*d,y:h.y+c*d};}e+=` Q ${m(h.x)} ${m(h.y)} ${m(n.x)} ${m(n.y)}`,t=n;}return e}var Dn=24;function En(a,e,t,i){let n=Dn;t&&i&&(t.x!==0&&i.x!==0?n=Math.min(n,Math.abs(e.x-a.x)/2):t.y!==0&&i.y!==0&&(n=Math.min(n,Math.abs(e.y-a.y)/2)));let s=t?{x:a.x+t.x*n,y:a.y+t.y*n}:a,r=i?{x:e.x+i.x*n,y:e.y+i.y*n}:e,o=[a];t&&o.push(s);let h=r.x-s.x,l=r.y-s.y;if(Math.abs(h)<1||Math.abs(l)<1)o.push(r);else {let c=s.x+h/2,d=s.y+l/2,g=Math.max(s.x,Math.min(c,r.x)),u=Math.max(s.y,Math.min(d,r.y)),p=i?i.x!==0?"H":"V":t?t.x!==0?"H":"V":void 0;p==="H"?o.push({x:g,y:s.y},{x:g,y:r.y},r):p==="V"?o.push({x:s.x,y:u},{x:r.x,y:u},r):Math.abs(h)>=Math.abs(l)?o.push({x:c,y:s.y},{x:c,y:r.y},r):o.push({x:s.x,y:d},{x:r.x,y:d},r);}return i&&o.push(e),o}function Ln(a){let e=[];for(let t of a){let i=e.length;if(!(i>0&&Math.abs(e[i-1].x-t.x)<1e-6&&Math.abs(e[i-1].y-t.y)<1e-6)){if(i>=2){let n=e[i-2],s=e[i-1];if(Math.abs(n.y-s.y)<1e-6&&Math.abs(s.y-t.y)<1e-6||Math.abs(n.x-s.x)<1e-6&&Math.abs(s.x-t.x)<1e-6){e[i-1]=t;continue}}e.push(t);}}return e}function kn(a,e,t,i){if(e==="curve")return Cn(a);let n;if(e==="straight"?n=In(a):a.length===2?n=Ln(En(a[0],a[1],t,i)):n=Tn(a),n.length<2)return "";let s=`M ${m(n[0].x)} ${m(n[0].y)}`;for(let r=1;r<n.length;r++)s+=` L ${m(n[r].x)} ${m(n[r].y)}`;return s}function nt(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),s=12,r={x:e.x-s*Math.cos(n-Math.PI/6),y:e.y-s*Math.sin(n-Math.PI/6)},o={x:e.x-s*Math.cos(n+Math.PI/6),y:e.y-s*Math.sin(n+Math.PI/6)};return `<path d="M ${m(e.x)} ${m(e.y)} L ${m(r.x)} ${m(r.y)} M ${m(e.x)} ${m(e.y)} L ${m(o.x)} ${m(o.y)}" stroke="${t}" stroke-width="${i}" stroke-linecap="round" fill="none" />`}function It(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),s=14,r=e.x,o=e.y,h=e.x-s*Math.cos(n),l=e.y-s*Math.sin(n),c=h+s*.5*Math.cos(n-Math.PI/2),d=l+s*.5*Math.sin(n-Math.PI/2),g=h+s*.5*Math.cos(n+Math.PI/2),u=l+s*.5*Math.sin(n+Math.PI/2);return `<polygon points="${m(r)},${m(o)} ${m(c)},${m(d)} ${m(g)},${m(u)}" fill="#ffffff" stroke="${t}" stroke-width="${i}" />`}function Tt(a,e,t,i,n){let s=Math.atan2(e.y-a.y,e.x-a.x),r=14,o=e.x,h=e.y,l=e.x-r*.5*Math.cos(s),c=e.y-r*.5*Math.sin(s),d=e.x-r*Math.cos(s),g=e.y-r*Math.sin(s),u=l+r*.4*Math.cos(s-Math.PI/2),p=c+r*.4*Math.sin(s-Math.PI/2),y=l+r*.4*Math.cos(s+Math.PI/2),f=c+r*.4*Math.sin(s+Math.PI/2);return `<polygon points="${m(o)},${m(h)} ${m(u)},${m(p)} ${m(d)},${m(g)} ${m(y)},${m(f)}" fill="${n?t:"#ffffff"}" stroke="${t}" stroke-width="${i}" />`}function An(a,e,t,i){if(e==="none"||a.length<2)return "";let n="";return (e==="start"||e==="both")&&(n+=nt(a[1],a[0],t,i)),(e==="end"||e==="both")&&(n+=nt(a[a.length-2],a[a.length-1],t,i)),e==="inheritance"&&(n+=It(a[a.length-2],a[a.length-1],t,i)),e==="aggregation"&&(n+=Tt(a[1],a[0],t,i,false)),e==="composition"&&(n+=Tt(a[1],a[0],t,i,true)),e==="dependency"&&(n+=nt(a[a.length-2],a[a.length-1],t,i)),e==="realization"&&(n+=It(a[a.length-2],a[a.length-1],t,i)),n}function ht(a,e,t,i=0,n=0){if(a.length===0)return "";let s=e*1.3,o=-(a.length*s)/2+s/2,h=a.map((l,c)=>`<tspan x="${m(i)}" y="${m(n+o+c*s)}">${ye(l)}</tspan>`).join("");return `<text text-anchor="middle" dominant-baseline="central" font-family="sans-serif" font-size="${e}" fill="${t}">${h}</text>`}function _(a,e){let t=Et(a),i=e&&a.fillColor!=="transparent",n=a.fillOpacity??1,s=a.strokeOpacity??1;return [i?`fill="${a.fillColor}"`:'fill="none"',i&&n<1?`fill-opacity="${m(n)}"`:"",`stroke="${a.strokeColor}"`,s<1&&a.strokeColor!=="transparent"?`stroke-opacity="${m(s)}"`:"",`stroke-width="${a.strokeWidth}"`,'stroke-linecap="round"','stroke-linejoin="round"',t?`stroke-dasharray="${t}"`:""].filter(Boolean).join(" ")}function Ct(a,e){let{width:t,height:i}=a,n=t/2,s=i/2,r=`${U}px sans-serif`,o=j,h=e?0:a.attributes.length>0?a.attributes.length*$+k*2:k*2,l=t-O*2,c=[];c.push(`<rect x="${m(-n)}" y="${m(-s)}" width="${t}" height="${i}" ${_(a.style,true)} />`),c.push(`<line x1="${m(-n)}" y1="${m(-s+o)}" x2="${m(n)}" y2="${m(-s+o)}" stroke="${a.style.strokeColor}" stroke-width="${a.style.strokeWidth}" />`),e||c.push(`<line x1="${m(-n)}" y1="${m(-s+o+h)}" x2="${m(n)}" y2="${m(-s+o+h)}" stroke="${a.style.strokeColor}" stroke-width="${a.style.strokeWidth}" />`);let d=e?`<<${a.className||"Interface"}>>`:a.className;c.push(`<text text-anchor="middle" dominant-baseline="central" font-family="sans-serif" font-weight="bold" font-size="${U}" fill="${a.textColor||pe}" x="0" y="${m(-s+o/2)}">${ye(ot(d,l,r))}</text>`);let g=(p,y,f,w,x)=>{let v=`${f||U}px sans-serif`,b=ot(p,l,v),S=`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${f||U}" fill="${w||pe}" x="${m(-n+O)}" y="${m(y)}">${ye(b)}</text>`;if(x){let I=se(b,v);S+=`<line x1="${m(-n+O)}" y1="${m(y)}" x2="${m(-n+O+I)}" y2="${m(y)}" stroke="${w||pe}" stroke-width="1" />`;}return S};if(!e){let p=-s+o+k+$/2;a.attributes.forEach((y,f)=>{c.push(g(`${y.visibility} ${y.name}: ${y.type}`,p+f*$,y.fontSize||a.fontSize||0,y.textColor||a.textColor||"",!!y.strikethrough));});}let u=-s+o+h+k+$/2;return a.methods.forEach((p,y)=>{c.push(g(`${p.visibility} ${p.name}(${p.params}): ${p.returnType}`,u+y*$,p.fontSize||a.fontSize||0,p.textColor||a.textColor||"",!!p.strikethrough));}),c.join("")}function $n(a){let t=B(a.root).positions,i=[],n=r=>{if(r.collapsed)return;let o=t.get(r.id);if(o)for(let h of r.children??[]){let l=t.get(h.id);if(!l)continue;let c=oe(h,l.depth),d=a.x+o.x+o.width/2,g=a.y+o.y,u=a.x+l.x-l.width/2,p=a.y+l.y,y=(d+u)/2;i.push(`<path d="M ${m(d)} ${m(g)} C ${m(y)} ${m(g)} ${m(y)} ${m(p)} ${m(u)} ${m(p)}" stroke="${c}" stroke-width="2" fill="none" stroke-linecap="round" />`),n(h);}};n(a.root);let s=r=>{let o=t.get(r.id);if(!o)return;let h=oe(r,o.depth),l=o.width/2,c=o.height/2,d=a.x+o.x,g=a.y+o.y;if(i.push(`<rect x="${m(d-l)}" y="${m(g-c)}" width="${o.width}" height="${o.height}" rx="6" ry="6" fill="#ffffff" stroke="${h}" stroke-width="2" />`),r.note){let v="11px sans-serif",b=r.noteColor??h,S=Math.min(se(r.note,v)+12,130),I=16,C=se(r.note,v)+12>130?r.note.slice(0,12)+"\u2026":r.note;i.push(`<rect x="${m(d-l)}" y="${m(g-c-I+2)}" width="${S}" height="${I}" rx="4" ry="4" fill="${b}" />`),i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="11" fill="#ffffff" x="${m(d-l+6)}" y="${m(g-c-I/2+2)}">${ye(C)}</text>`);}let u=r.icon?18:0,p=o.width-u-(r.icon?8:0)-16,y=ot(r.text||"",p,`${14}px sans-serif`),f=se(y,`${14}px sans-serif`),w=u+(u?8:0)+f,x=d-w/2;if(r.icon&&(i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="16" fill="#1f2937" x="${m(x)}" y="${m(g)}">${ye(r.icon)}</text>`),x+=u+8),i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${14}" fill="#1f2937" x="${m(x)}" y="${m(g)}">${ye(y)}</text>`),r.children&&r.children.length>0&&!r.collapsed)for(let v of r.children)s(v);};return s(a.root),i.join("")}function Rn(a,e){let t=a.rotation*180/Math.PI,i=`<g transform="translate(${m(a.x)} ${m(a.y)}) rotate(${m(t)})">`,n=`${bn(a)}</g>`,s=a.style;switch(a.type){case "rectangle":{let r=a.width,o=a.height;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" ${_(s,true)} />${n}`}case "rounded-rectangle":{let r=a.width,o=a.height,h=a.borderRadius||8;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" rx="${h}" ry="${h}" ${_(s,true)} />${n}`}case "stadium":{let r=a.width,o=a.height,h=Math.min(r,o)/2;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" rx="${h}" ry="${h}" ${_(s,true)} />${n}`}case "circle":{let r=a.radius;return `${i}<circle cx="0" cy="0" r="${r}" ${_(s,true)} />${n}`}case "ellipse":{let r=a.width,o=a.height;return `${i}<ellipse cx="0" cy="0" rx="${r/2}" ry="${o/2}" ${_(s,true)} />${n}`}case "diamond":{let r=a.width,o=a.height;return `${i}<polygon points="${ie([[0,-o/2],[r/2,0],[0,o/2],[-r/2,0]])}" ${_(s,true)} />${n}`}case "triangle":{let r=a.width,o=a.height;return `${i}<polygon points="${ie([[0,-o/2],[r/2,o/2],[-r/2,o/2]])}" ${_(s,true)} />${n}`}case "hexagon":{let r=a.width,o=a.height;return `${i}<polygon points="${ie(it(r,o,6,-Math.PI/2))}" ${_(s,true)} />${n}`}case "pentagon":{let r=a.width,o=a.height;return `${i}<polygon points="${ie(it(r,o,5,-Math.PI/2))}" ${_(s,true)} />${n}`}case "octagon":{let r=a.width,o=a.height;return `${i}<polygon points="${ie(it(r,o,8,-Math.PI/8))}" ${_(s,true)} />${n}`}case "star":{let r=a.width,o=a.height;return `${i}<polygon points="${ie(Hn(r,o))}" ${_(s,true)} />${n}`}case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "class-catalog":case "chevron":case "brace-left":case "brace-right":{let r=a.width,o=a.height,h=ze(a.type);if(!h)return "";let l=`<path d="${vt(ge(h.outline,r,o))}" ${_(s,!h.strokeOnly)} />`,c=(h.seams??[]).map(d=>`<path d="${vt(ge(d,r,o))}" ${_({...s,fillColor:"transparent"},true)} />`).join("");return `${i}${l}${c}${n}`}case "parallelogram":{let r=a.width,o=a.height,h=r*.2;return `${i}<polygon points="${ie([[-r/2+h,-o/2],[r/2,-o/2],[r/2-h,o/2],[-r/2,o/2]])}" ${_(s,true)} />${n}`}case "trapezoid":{let r=a.width,o=a.height,h=r*.15;return `${i}<polygon points="${ie([[-r/2+h,-o/2],[r/2-h,-o/2],[r/2,o/2],[-r/2,o/2]])}" ${_(s,true)} />${n}`}case "uml-class":return `${i}${Ct(a,false)}${n}`;case "uml-interface":return `${i}${Ct(a,true)}${n}`;case "mind-map":return $n(a);case "line":case "arrow":{let r=a,o=r.connectionType||"straight",{pts:h,fromN:l,toN:c}=Pn(r,e);if(h.length<2)return "";let d=r.style.strokeColor,g=r.style.strokeWidth,p=r.type==="arrow"&&(!!r.dashed||r.arrowHead==="dependency"||r.arrowHead==="realization")?"8,5":Et(r.style),y=`<path d="${kn(h,o,l,c)}" fill="none" stroke="${d}" stroke-width="${g}" stroke-linecap="round" stroke-linejoin="round"${p?` stroke-dasharray="${p}"`:""} />`,f=An(h,r.arrowHead||"end",d,g);return `${y}${f}`}case "draw":{let r=a,o=r.points;if(!o||o.length<2)return "";let h=Math.cos(r.rotation||0),l=Math.sin(r.rotation||0),c=o.map(g=>({x:g.x*h-g.y*l+r.x,y:g.x*l+g.y*h+r.y}));if(c.length<2)return "";let d=`M ${m(c[0].x)} ${m(c[0].y)}`;for(let g=1;g<c.length-1;g++){let u=(c[g].x+c[g+1].x)/2,p=(c[g].y+c[g+1].y)/2;d+=` Q ${m(c[g].x)} ${m(c[g].y)} ${m(u)} ${m(p)}`;}return d+=` L ${m(c[c.length-1].x)} ${m(c[c.length-1].y)}`,`<path d="${d}" fill="none" stroke="${s.strokeColor}" stroke-width="${s.strokeWidth}" stroke-linecap="round" stroke-linejoin="round" />`}case "text":{let r=a,o=r.fontSize||16,h=r.textColor||pe,l=rt(r.text||"",o,r.width,r.height),c="";if(r.highlightColor&&r.highlightColor!=="transparent"){let d=o*.15,g=typeof r.highlightOpacity=="number"?r.highlightOpacity:1,u=g<1?` fill-opacity="${m(g)}"`:"";c+=`<rect x="${m(-r.width/2-d)}" y="${m(-(l.length*o*1.3)/2-d)}" width="${r.width+d*2}" height="${l.length*o*1.3+d*2}" rx="4" fill="${r.highlightColor}"${u} />`;}return c+=ht(l,o,h),`${i}${c}${n}`}default:{let r=a,o=r.width||100,h=r.height||40,l="";if(r.text){let c=r.fontSize||16,d=rt(r.text,c,o*.85,h*.85);l+=ht(d,c,r.textColor||pe);}return `${i}<rect x="${m(-o/2)}" y="${m(-h/2)}" width="${o}" height="${h}" ${_(s,true)} />${l}${n}`}}}function it(a,e,t,i){let n=a/2,s=e/2,r=[];for(let o=0;o<t;o++){let h=o*2*Math.PI/t+i;r.push([n*Math.cos(h),s*Math.sin(h)]);}return r}function Hn(a,e){let t=a/2,i=e/2,n=5,s=.4,r=[];for(let o=0;o<n*2;o++){let h=o*Math.PI/n-Math.PI/2,l=o%2===0?1:s;r.push([t*l*Math.cos(h),i*l*Math.sin(h)]);}return r}function Lt(a,e={}){let t=e.padding??24,i=e.background===void 0?"#ffffff":e.background??null,n=Ce(a,t),s=Math.max(1,Math.ceil(n.width)),r=Math.max(1,Math.ceil(n.height)),o=new Map(a.map(c=>[c.id,c])),h=a.map(c=>Rn(c,o)).filter(Boolean).join(`
1
+ 'use strict';var G={identity(){return {a:1,b:0,c:0,d:1,e:0,f:0}},translation(a,e){return {a:1,b:0,c:0,d:1,e:a,f:e}},rotation(a){let e=Math.cos(a),t=Math.sin(a);return {a:e,b:t,c:-t,d:e,e:0,f:0}},scale(a,e){return {a,b:0,c:0,d:e,e:0,f:0}},multiply(a,e){return {a:a.a*e.a+a.b*e.c,b:a.a*e.b+a.b*e.d,c:a.c*e.a+a.d*e.c,d:a.c*e.b+a.d*e.d,e:a.e*e.a+a.f*e.c+e.e,f:a.e*e.b+a.f*e.d+e.f}},apply(a,e){return {x:a.a*e.x+a.c*e.y+a.e,y:a.b*e.x+a.d*e.y+a.f}},invert(a){let e=a.a*a.d-a.b*a.c;if(Math.abs(e)<1e-10)return null;let t=1/e;return {a:a.d*t,b:-a.b*t,c:-a.c*t,d:a.a*t,e:(a.c*a.f-a.d*a.e)*t,f:(a.b*a.e-a.a*a.f)*t}},createCameraMatrix(a){let e=G.scale(a.zoom,a.zoom),t=G.translation(a.x,a.y);return G.multiply(t,e)}};var Z=class{x=0;y=0;zoom=1;minZoom=.1;maxZoom=10;getMatrix(){return G.createCameraMatrix({x:this.x,y:this.y,zoom:this.zoom})}getInverseMatrix(){return G.invert(this.getMatrix())}screenToPage(e){let t=this.getInverseMatrix();return t?G.apply(t,e):e}pageToScreen(e){return G.apply(this.getMatrix(),e)}translate(e,t){this.x+=e,this.y+=t;}zoomAt(e,t){let i=this.screenToPage(e);this.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.zoom*t));let n=this.pageToScreen(i);this.x+=e.x-n.x,this.y+=e.y-n.y;}reset(){this.x=0,this.y=0,this.zoom=1;}getZoom(){return this.zoom}fitBounds(e,t=50){let i=window.innerWidth,n=window.innerHeight,s=(i-t*2)/e.width,r=(n-t*2)/e.height,o=Math.min(s,r,this.maxZoom);this.zoom=Math.max(this.minZoom,o),this.x=(i-e.width*this.zoom)/2-e.x*this.zoom,this.y=(n-e.height*this.zoom)/2-e.y*this.zoom;}};var Dt=40;var Lt=20;function we(a,e,t){let i=t.x-e.x,n=t.y-e.y,s=i*i+n*n;if(s<1e-9)return Math.hypot(a.x-e.x,a.y-e.y);let r=((a.x-e.x)*i+(a.y-e.y)*n)/s;return r=Math.max(0,Math.min(1,r)),Math.hypot(a.x-(e.x+i*r),a.y-(e.y+n*r))}function Se(a,e=40){let t=[];for(let i=0;i+1<a.length;i++){let n=a[i],s=a[i+1],r=s.x-n.x,o=s.y-n.y,h=Math.hypot(r,o);h<e||t.push({index:i,center:{x:(n.x+s.x)/2,y:(n.y+s.y)/2},axis:Math.abs(r)>=Math.abs(o)?"H":"V",length:h});}return t}function Ne(a,e,t=10,i=14){let n=Se(a);if(n.length===0)return null;let s=null,r=1/0;for(let o of n){if(Math.hypot(e.x-o.center.x,e.y-o.center.y)<=t)return o;let l=we(e,a[o.index],a[o.index+1]);l<=i&&l<r&&(r=l,s=o);}return s}function Be(a,e,t){if(e<0||e+1>=a.length)return a;let i=a[e],n=a[e+1],s=Math.abs(n.x-i.x)>=Math.abs(n.y-i.y),r=e===0,o=e+1===a.length-1,h=s?Math.sign(n.x-i.x)||1:Math.sign(n.y-i.y)||1,l=Math.abs(s?n.x-i.x:n.y-i.y),c=Math.min(24,l/2),d=s?(i.y+n.y)/2:(i.x+n.x)/2,u=f=>s?f.y:f.x,g=[];r?g.push(u(a[0])):g.push(u(a[e-1])),o?g.push(u(a[a.length-1])):g.push(u(a[e+2]));let p=d+t;for(let f of g)Math.abs(p-f)<20&&(p=f);let y=[];if(r){let f=s?{x:i.x+h*c,y:i.y}:{x:i.x,y:i.y+h*c};y.push({x:i.x,y:i.y},f,s?{x:f.x,y:p}:{x:p,y:f.y});}else y.push(s?{x:i.x,y:p}:{x:p,y:i.y});if(o){let f=s?{x:n.x-h*c,y:n.y}:{x:n.x,y:n.y-h*c};y.push(s?{x:f.x,y:p}:{x:p,y:f.y},f,{x:n.x,y:n.y});}else y.push(s?{x:n.x,y:p}:{x:p,y:n.y});return [...a.slice(0,e),...y,...a.slice(e+2)]}function oe(a){let e=[];for(let t of a){let i=e.length;if(!(i>0&&Math.abs(e[i-1].x-t.x)<1e-6&&Math.abs(e[i-1].y-t.y)<1e-6)){if(i>=2){let n=e[i-2],s=e[i-1];if(Math.abs(n.y-s.y)<1e-6&&Math.abs(s.y-t.y)<1e-6||Math.abs(n.x-s.x)<1e-6&&Math.abs(s.x-t.x)<1e-6){e[i-1]=t;continue}}e.push(t);}}return e}function _e(a){return a.length<=2?[]:a.slice(1,-1).map(e=>({x:e.x,y:e.y}))}var lt={primary:"#3b82f6",selection:{outline:"#3b82f6",handleStroke:"#3b82f6",handleFill:"#ffffff",outlineFill:"rgba(59, 130, 246, 0.1)",shadow:"#3b82f6"},grid:"#e5e7eb",text:"#1f2937",editBorder:"#3b82f6",brushFill:"rgba(59, 130, 246, 0.08)",brushStroke:"rgba(59, 130, 246, 0.8)",guide:"rgba(59, 130, 246, 0.6)",lineHighlight:"rgba(59, 130, 246, 0.4)",genDot:"#3b82f6",genLine:"rgba(59, 130, 246, 0.55)"},I={...lt,selection:{...lt.selection}},Ge=new Set;function Et(a){return Ge.add(a),()=>Ge.delete(a)}function be(a){a.selection&&Object.assign(I.selection,a.selection);for(let e of Object.keys(a)){if(e==="selection")continue;let t=a[e];t!==void 0&&(I[e]=t);}Ge.forEach(e=>e());}function kt(){return I}function R(a,e){let t=ct(a);if(!t)return a;let i=parseInt(t,16),n=i>>16&255,s=i>>8&255,r=i&255;return `rgba(${n}, ${s}, ${r}, ${e})`}function At(a,e){let t=ct(a);if(!t)return a;let i=parseInt(t,16),n=e<0?0:255,s=Math.abs(e),r=o=>Math.round((n-o)*s+o).toString(16).padStart(2,"0");return `#${r(i>>16&255)}${r(i>>8&255)}${r(i&255)}`}function ct(a){let e=a.replace("#","").trim();return /^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/.test(e)?e.length===3?e.split("").map(t=>t+t).join(""):e:null}var L=class{context;constructor(e){this.context=e;}getCursor(e){return null}hasTransientState(){return false}cancelTransient(){return false}dispose(){}};var dt={"zh-CN":{"save.success":"\u5DF2\u4FDD\u5B58","save.fail":"\u4FDD\u5B58\u5931\u8D25","tool.select":"\u9009\u62E9\u5DE5\u5177","tool.hand":"\u62D6\u62FD\u89C6\u53E3","tool.rectangle":"\u77E9\u5F62","tool.rounded-rectangle":"\u5706\u89D2\u77E9\u5F62","tool.circle":"\u5706\u5F62","tool.ellipse":"\u692D\u5706","tool.diamond":"\u83F1\u5F62","tool.triangle":"\u4E09\u89D2\u5F62","tool.hexagon":"\u516D\u8FB9\u5F62","tool.parallelogram":"\u5E73\u884C\u56DB\u8FB9\u5F62","tool.trapezoid":"\u68AF\u5F62","tool.pentagon":"\u4E94\u8FB9\u5F62","tool.octagon":"\u516B\u8FB9\u5F62","tool.star":"\u661F\u5F62","tool.cylinder":"\u5706\u67F1\u4F53","tool.cloud":"\u4E91\u5F62","tool.heart":"\u5FC3\u5F62","tool.block-arrow-right":"\u53F3\u7BAD\u5934","tool.block-arrow-left":"\u5DE6\u7BAD\u5934","tool.block-arrow-up":"\u4E0A\u7BAD\u5934","tool.block-arrow-down":"\u4E0B\u7BAD\u5934","tool.block-arrow-double":"\u53CC\u5411\u7BAD\u5934","tool.right-triangle":"\u76F4\u89D2\u4E09\u89D2\u5F62","tool.cross":"\u5341\u5B57","tool.speech-rect":"\u65B9\u5F62\u5BF9\u8BDD\u6846","tool.speech-round":"\u5706\u5F62\u5BF9\u8BDD\u6846","tool.cube":"\u7ACB\u65B9\u4F53","tool.sector":"\u6247\u5F62","tool.delay":"D \u5F62","tool.predefined-process":"\u9884\u5B9A\u4E49\u6D41\u7A0B","tool.document":"\u6587\u6863","tool.stadium":"\u5168\u5706\u89D2\u77E9\u5F62","tool.class-catalog":"\u7C7B\u76EE","class.plain":"\u7C7B","flow.process":"\u5904\u7406","flow.step":"\u6D41\u7A0B","flow.startEnd":"\u5F00\u59CB/\u7ED3\u675F","flow.decision":"\u5224\u5B9A","flow.data":"\u6570\u636E","flow.manual":"\u624B\u52A8\u64CD\u4F5C","flow.preparation":"\u51C6\u5907","flow.database":"\u6570\u636E\u5E93","flow.delay":"\u5EF6\u65F6","shapeGroup.basic":"\u57FA\u7840","shapeGroup.flowchart":"\u6D41\u7A0B\u56FE","shapeGroup.other":"\u5176\u4ED6","shapeGroup.uml":"\u7C7B\u56FE","shapeMenu.hint":"\u60AC\u505C\u67E5\u770B\u540D\u79F0","tool.chevron":"\u5C16\u89D2","tool.brace-left":"\u5DE6\u62EC\u53F7","tool.brace-right":"\u53F3\u62EC\u53F7","tool.uml-class":"UML \u7C7B\u56FE","tool.uml-interface":"UML \u63A5\u53E3","tool.line":"\u76F4\u7EBF","tool.arrow":"\u7EBF\u6761","tool.text":"\u6587\u672C","tool.draw":"\u753B\u7B14","tool.pen":"\u753B\u7B14","tool.highlighter":"\u8367\u5149\u7B14","tool.eraser":"\u6A61\u76AE\u64E6","status.none":"\u672A\u9009\u62E9","status.selected":"\u5DF2\u9009\u62E9 {n} \u4E2A\u56FE\u5F62","toolbar.select":"\u9009\u62E9 (V)","toolbar.hand":"\u62D6\u62FD\u89C6\u53E3 (H)","toolbar.shapes":"\u5F62\u72B6","toolbar.grid":"\u7F51\u683C","toolbar.undo":"\u64A4\u9500 (Ctrl+Z)","toolbar.redo":"\u91CD\u505A (Ctrl+Shift+Z)","toolbar.arrow":"\u7BAD\u5934","toolbar.text":"\u6587\u672C","toolbar.pen":"\u753B\u7B14","toolbar.highlighter":"\u8367\u5149\u7B14","toolbar.eraser":"\u6A61\u76AE\u64E6","toolbar.uml-class":"UML \u7C7B\u56FE","toolbar.uml-interface":"UML \u63A5\u53E3","zoom.in":"\u653E\u5927","zoom.out":"\u7F29\u5C0F","zoom.reset":"\u91CD\u7F6E","style.stroke":"\u8FB9\u6846","style.line":"\u7EBF\u6761","style.fill":"\u586B\u5145","style.text":"\u6587\u5B57","style.highlight":"\u9AD8\u4EAE","style.prefix":"\u524D\u7F00\u7B26\u53F7","style.prefix.soon":"\u524D\u7F00\u7B26\u53F7\u5F00\u53D1\u4E2D\uFF0C\u656C\u8BF7\u671F\u5F85","style.none":"\u65E0","style.addColor":"\u6DFB\u52A0\u989C\u8272","style.connection":"\u8FDE\u7EBF","style.arrow":"\u7BAD\u5934","style.dashed":"\u865A\u7EBF","style.solid":"\u5B9E\u7EBF","style.opacity":"\u4E0D\u900F\u660E\u5EA6","style.connection.straight":"\u76F4\u7EBF","style.connection.polyline":"\u6298\u7EBF","style.connection.orthogonal":"\u76F4\u89D2\u6298\u7EBF","style.connection.curve":"\u66F2\u7EBF","style.arrowhead.none":"\u65E0\u7BAD\u5934","style.arrowhead.end":"\u7EC8\u70B9\u7BAD\u5934","style.arrowhead.start":"\u8D77\u70B9\u7BAD\u5934","style.arrowhead.both":"\u53CC\u7BAD\u5934","style.arrowhead.none-dashed":"\u65E0\u7BAD\u5934\u865A\u7EBF","style.arrowhead.both-dashed":"\u53CC\u7BAD\u5934\u865A\u7EBF","style.uml":"UML","style.arrowhead.inheritance":"\u7EE7\u627F","style.arrowhead.composition":"\u7EC4\u5408","style.arrowhead.aggregation":"\u805A\u5408","style.arrowhead.dependency":"\u4F9D\u8D56","style.arrowhead.realization":"\u5B9E\u73B0","menu.title":"\u9009\u62E9\u65B0\u56FE\u5F62","menu.cancel":"\u70B9\u51FB\u7A7A\u767D\u5904\u53D6\u6D88","shape.rectangle":"\u77E9\u5F62","shape.rounded-rectangle":"\u5706\u89D2","shape.circle":"\u5706\u5F62","shape.ellipse":"\u692D\u5706","shape.diamond":"\u83F1\u5F62","shape.triangle":"\u4E09\u89D2","shape.hexagon":"\u516D\u8FB9\u5F62","shape.parallelogram":"\u5E73\u884C","shape.trapezoid":"\u68AF\u5F62","shape.pentagon":"\u4E94\u8FB9\u5F62","shape.octagon":"\u516B\u8FB9\u5F62","shape.star":"\u661F\u5F62","shape.uml-class":"\u7C7B\u56FE","shape.uml-interface":"\u63A5\u53E3","uml.drag":"\u62D6\u62FD\u6392\u5E8F","uml.delete":"\u5220\u9664\u8BE5\u884C","uml.textColor":"\u6587\u5B57\u989C\u8272","uml.defaultColor":"\u9ED8\u8BA4\u989C\u8272","uml.fontSize":"\u5B57\u53F7","uml.strikethrough":"\u5220\u9664\u7EBF","uml.attribute":"\u5C5E\u6027","uml.method":"\u65B9\u6CD5","minimap.title":"\u5C0F\u5730\u56FE","minimap.expand":"\u5C55\u5F00\u5C0F\u5730\u56FE","minimap.collapse":"\u6536\u8D77\u5C0F\u5730\u56FE","tool.mind-map":"\u601D\u7EF4\u5BFC\u56FE","toolbar.mind-map":"\u601D\u7EF4\u5BFC\u56FE","toolbar.export":"\u5BFC\u51FA","toolbar.export.png":"PNG \u56FE\u7247","toolbar.export.svg":"SVG \u77E2\u91CF\u56FE","toolbar.export.pdf":"PDF \u6587\u6863","shape.mind-map":"\u601D\u7EF4\u5BFC\u56FE","mindmap.defaultRoot":"\u4E2D\u5FC3\u4E3B\u9898","mindmap.defaultBranch":"\u5206\u652F\u4E3B\u9898","mindmap.nodeText":"\u8282\u70B9\u6587\u672C","mindmap.addChild":"\u5B50\u8282\u70B9","mindmap.addSibling":"\u5144\u5F1F\u8282\u70B9","mindmap.deleteNode":"\u5220\u9664\u8282\u70B9","mindmap.color":"\u989C\u8272","mindmap.levelColor":"\u9ED8\u8BA4\u5C42\u7EA7\u8272","mindmap.icon":"\u56FE\u6807","mindmap.noIcon":"\u65E0\u56FE\u6807","mindmap.note":"\u5C5E\u6027\u8BF4\u660E","mindmap.notePlaceholder":"\u8BF4\u660E\u5185\u5BB9\uFF08\u53EF\u9009\uFF09","mindmap.noteColor":"\u8BF4\u660E\u989C\u8272","mindmap.noteColorDefault":"\u540C\u8282\u70B9\u8272","mindmap.collapse":"\u6298\u53E0","mindmap.expand":"\u5C55\u5F00","mindmap.close":"\u5173\u95ED\u7F16\u8F91","mindmap.more":"\u66F4\u591A\u8BBE\u7F6E"},"en-US":{"save.success":"Saved","save.fail":"Save failed","tool.select":"Select tool","tool.hand":"Pan view","tool.rectangle":"Rectangle","tool.rounded-rectangle":"Rounded rectangle","tool.circle":"Circle","tool.ellipse":"Ellipse","tool.diamond":"Diamond","tool.triangle":"Triangle","tool.hexagon":"Hexagon","tool.parallelogram":"Parallelogram","tool.trapezoid":"Trapezoid","tool.pentagon":"Pentagon","tool.octagon":"Octagon","tool.star":"Star","tool.cylinder":"Cylinder","tool.cloud":"Cloud","tool.heart":"Heart","tool.block-arrow-right":"Arrow right","tool.block-arrow-left":"Arrow left","tool.block-arrow-up":"Arrow up","tool.block-arrow-down":"Arrow down","tool.block-arrow-double":"Double arrow","tool.right-triangle":"Right triangle","tool.cross":"Cross","tool.speech-rect":"Speech bubble","tool.speech-round":"Round bubble","tool.cube":"Cube","tool.sector":"Sector","tool.delay":"Delay","tool.predefined-process":"Predefined process","tool.document":"Document","tool.stadium":"Stadium","tool.class-catalog":"Category","class.plain":"Class","flow.process":"Process","flow.step":"Step","flow.startEnd":"Start / End","flow.decision":"Decision","flow.data":"Data","flow.manual":"Manual operation","flow.preparation":"Preparation","flow.database":"Database","flow.delay":"Delay","shapeGroup.basic":"Basic","shapeGroup.flowchart":"Flowchart","shapeGroup.other":"Other","shapeGroup.uml":"Class diagram","shapeMenu.hint":"Hover to see name","tool.chevron":"Chevron","tool.brace-left":"Left brace","tool.brace-right":"Right brace","tool.uml-class":"UML class","tool.uml-interface":"UML interface","tool.line":"Line","tool.arrow":"Line","tool.text":"Text","tool.draw":"Pen","tool.pen":"Pen","tool.highlighter":"Highlighter","tool.eraser":"Eraser","status.none":"Nothing selected","status.selected":"{n} shapes selected","toolbar.select":"Select (V)","toolbar.hand":"Pan view (H)","toolbar.shapes":"Shapes","toolbar.grid":"Grid","toolbar.undo":"Undo (Ctrl+Z)","toolbar.redo":"Redo (Ctrl+Shift+Z)","toolbar.arrow":"Arrow","toolbar.text":"Text","toolbar.pen":"Pen","toolbar.highlighter":"Highlighter","toolbar.eraser":"Eraser","toolbar.uml-class":"UML class","toolbar.uml-interface":"UML interface","zoom.in":"Zoom in","zoom.out":"Zoom out","zoom.reset":"Reset","style.stroke":"Border","style.line":"Line","style.fill":"Fill","style.text":"Text","style.highlight":"Highlight","style.prefix":"Prefix","style.prefix.soon":"Prefix symbols are coming soon","style.none":"None","style.addColor":"Add color","style.connection":"Connection","style.arrow":"Arrow head","style.dashed":"Dashed","style.solid":"Solid","style.opacity":"Opacity","style.connection.straight":"Straight","style.connection.polyline":"Polyline","style.connection.orthogonal":"Orthogonal","style.connection.curve":"Curve","style.arrowhead.none":"None","style.arrowhead.end":"End","style.arrowhead.start":"Start","style.arrowhead.both":"Both","style.arrowhead.none-dashed":"Dashed","style.arrowhead.both-dashed":"Dashed both","style.uml":"UML","style.arrowhead.inheritance":"Inheritance","style.arrowhead.composition":"Composition","style.arrowhead.aggregation":"Aggregation","style.arrowhead.dependency":"Dependency","style.arrowhead.realization":"Realization","menu.title":"Create shape","menu.cancel":"Click empty space to cancel","shape.rectangle":"Rectangle","shape.rounded-rectangle":"Rounded","shape.circle":"Circle","shape.ellipse":"Ellipse","shape.diamond":"Diamond","shape.triangle":"Triangle","shape.hexagon":"Hexagon","shape.parallelogram":"Parallelogram","shape.trapezoid":"Trapezoid","shape.pentagon":"Pentagon","shape.octagon":"Octagon","shape.star":"Star","shape.uml-class":"Class","shape.uml-interface":"Interface","uml.drag":"Drag to reorder","uml.delete":"Delete row","uml.textColor":"Text color","uml.defaultColor":"Default color","uml.fontSize":"Font size","uml.strikethrough":"Strikethrough","uml.attribute":"Attributes","uml.method":"Methods","minimap.title":"Minimap","minimap.expand":"Expand minimap","minimap.collapse":"Collapse minimap","tool.mind-map":"Mind map","toolbar.mind-map":"Mind map","toolbar.export":"Export","toolbar.export.png":"PNG image","toolbar.export.svg":"SVG vector","toolbar.export.pdf":"PDF document","shape.mind-map":"Mind map","mindmap.defaultRoot":"Central topic","mindmap.defaultBranch":"Branch topic","mindmap.nodeText":"Node text","mindmap.addChild":"Child","mindmap.addSibling":"Sibling","mindmap.deleteNode":"Delete node","mindmap.color":"Color","mindmap.levelColor":"Default level color","mindmap.icon":"Icon","mindmap.noIcon":"No icon","mindmap.note":"Note","mindmap.notePlaceholder":"Note content (optional)","mindmap.noteColor":"Note color","mindmap.noteColorDefault":"Same as node","mindmap.collapse":"Collapse","mindmap.expand":"Expand","mindmap.close":"Close editor","mindmap.more":"More settings"}},Me="zh-CN",Oe=new Set;function ve(a){Me!==a&&(Me=a,Oe.forEach(e=>e()));}function Ht(){return Me}function $t(a){return Oe.add(a),()=>Oe.delete(a)}function B(a,e){let i=dt[Me][a]??dt["zh-CN"][a];if(e)for(let[n,s]of Object.entries(e))i=i.replace(new RegExp(`\\{${n}\\}`,"g"),String(s));return i}var Ue=["#ef4444","#f59e0b","#10b981","#3b82f6","#8b5cf6","#ec4899"],U=14,Vt=40,Rt=80,Nt=240;function j(a,e){return a.color??Ue[e%Ue.length]}function ut(a){let e=a.text||"",t=0;for(let n of e)t+=/[\u2e80-\u9fff\uf900-\ufaff\uff00-\uffef\u3000-\u303f]/.test(n)?1:.6;let i=Math.max(80,Math.min(240,Math.ceil(t*14)+24));return a.icon&&(i+=26),{width:i,height:40}}function Pe(a){let e={...a};return a.children&&(e.children=a.children.map(t=>Pe(t))),e}function Ce(a,e,t){if(a.id===e)return {...a,...t};let i=a.children??[],n=i.map(s=>Ce(s,e,t));return n.some((s,r)=>s!==i[r])?{...a,children:n}:a}function ze(a,e,t){if(a.id===e)return {...a,children:[...a.children??[],t],collapsed:false};let i=a.children??[],n=i.map(s=>ze(s,e,t));return n.some((s,r)=>s!==i[r])?{...a,children:n}:a}function Ye(a,e,t){let i=a.children??[];for(let n=0;n<i.length;n++){if(i[n].id===e){let r=[...i];return r.splice(n+1,0,t),{...a,children:r}}let s=Ye(i[n],e,t);if(s!==i[n])return {...a,children:i.map(r=>r===i[n]?s:r)}}return a}function We(a,e){if(a.id===e)return null;let t=a.children??[],i=t.map(n=>We(n,e)).filter(n=>n!==null);return i.length!==t.length||i.some((n,s)=>n!==t[s])?{...a,children:i}:a}function z(a,e){if(a.id===e)return a;for(let t of a.children??[]){let i=z(t,e);if(i)return i}return null}function gt(a,e){if(a.id===e)return 0;for(let t of a.children??[]){let i=gt(t,e);if(i!==-1)return i+1}return -1}function ae(a,e){for(let t of a.children??[]){if(t.id===e)return a;let i=ae(t,e);if(i)return i}return null}function pt(a){let e=1;for(let t of a.children??[])e+=pt(t);return e}function yt(a,e){e.set(a.id,ut(a));for(let t of a.children??[])yt(t,e);}function k(a){let e=new Map;yt(a,e);let t=new Map,i=u=>{let g=u.collapsed?[]:u.children??[];if(g.length===0)t.set(u.id,e.get(u.id).height);else {let p=0;for(let y of g)p+=i(y);p+=16*(g.length-1),t.set(u.id,Math.max(e.get(u.id).height,p));}return t.get(u.id)};i(a);let n=new Map,s=(u,g,p,y)=>{let f=t.get(u.id),S=e.get(u.id);if(n.set(u.id,{x:p,y:y+f/2,depth:g,width:S.width,height:S.height}),u.collapsed)return;let x=y;for(let M of u.children??[]){let v=e.get(M.id);s(M,g+1,p+S.width/2+48+v.width/2,x),x+=t.get(M.id)+16;}};s(a,0,0,-t.get(a.id)/2);let r=1/0,o=-1/0,h=1/0,l=-1/0;n.forEach(u=>{r=Math.min(r,u.x-u.width/2),o=Math.max(o,u.x+u.width/2),h=Math.min(h,u.y-u.height/2),l=Math.max(l,u.y+u.height/2);});let c=(r+o)/2,d=(h+l)/2;return n.forEach(u=>{u.x-=c,u.y-=d;}),{positions:n,width:o-r,height:l-h}}var Bt={strokeColor:"#1f2937",fillColor:"#f8fafc",fillOpacity:.9,strokeWidth:2,strokeDash:null},_t={rectangle:{width:120,height:60},"rounded-rectangle":{width:120,height:60,borderRadius:8},circle:{width:80,height:80},ellipse:{width:100,height:70},diamond:{width:100,height:80},triangle:{width:100,height:90},hexagon:{width:100,height:90},parallelogram:{width:120,height:60},trapezoid:{width:120,height:70},pentagon:{width:100,height:90},octagon:{width:100,height:90},star:{width:100,height:100},cylinder:{width:100,height:110},cloud:{width:140,height:90},heart:{width:100,height:95},"block-arrow-right":{width:140,height:80},"block-arrow-left":{width:140,height:80},"block-arrow-up":{width:80,height:140},"block-arrow-down":{width:80,height:140},"block-arrow-double":{width:150,height:80},"right-triangle":{width:100,height:90},cross:{width:90,height:90},"speech-rect":{width:130,height:92},"speech-round":{width:130,height:92},cube:{width:110,height:110},sector:{width:100,height:100},delay:{width:120,height:80},"predefined-process":{width:130,height:80},document:{width:120,height:90},stadium:{width:130,height:60},"class-catalog":{width:160,height:90},chevron:{width:110,height:80},"brace-left":{width:220,height:120},"brace-right":{width:220,height:120}},$=14,D=22,_=36,H=14,T=8,he=160,Gt=["rectangle","rounded-rectangle","circle","ellipse","diamond","triangle","hexagon","parallelogram","trapezoid","pentagon","octagon","star","cylinder","cloud","heart","block-arrow-right","block-arrow-left","block-arrow-up","block-arrow-down","block-arrow-double","right-triangle","cross","speech-rect","speech-round","cube","sector","delay","predefined-process","document","stadium","class-catalog","chevron","brace-left","brace-right","uml-class","uml-interface","mind-map"];function Ie(a){return Gt.includes(a)}function Y(a,e,t){let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=_t[a]||{width:120,height:60},s=n.width,r=n.height,o=n.radius??s/2,h=n.borderRadius??8,l=t??{...Bt};switch(a){case "rounded-rectangle":return {id:i,type:"rounded-rectangle",x:e.x,y:e.y,width:s,height:r,borderRadius:h,rotation:0,style:l};case "circle":return {id:i,type:"circle",x:e.x,y:e.y,radius:o,rotation:0,style:l};case "ellipse":return {id:i,type:"ellipse",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "diamond":return {id:i,type:"diamond",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "triangle":return {id:i,type:"triangle",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "hexagon":return {id:i,type:"hexagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "parallelogram":return {id:i,type:"parallelogram",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "trapezoid":return {id:i,type:"trapezoid",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "pentagon":return {id:i,type:"pentagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "octagon":return {id:i,type:"octagon",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "star":return {id:i,type:"star",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":return {id:i,type:a,x:e.x,y:e.y,width:s,height:r,rotation:0,style:l};case "uml-class":{let c="ClassName",d=[{id:`attr_${Date.now()}_1`,visibility:"+",name:"field",type:"string"}],u=[{id:`meth_${Date.now()}_1`,visibility:"+",name:"method",params:"param",returnType:"void"}],{width:g,height:p}=Te(c,d,u);return {id:i,type:"uml-class",x:e.x,y:e.y,width:g,height:p,className:c,attributes:d,methods:u,rotation:0,style:{...l,fillColor:"#ffffff"}}}case "uml-interface":{let c="Interface",d=[{id:`meth_${Date.now()}_1`,visibility:"+",name:"method",params:"type",returnType:"type"}],u=$*.6,g=d.map(x=>`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`),p=Math.max(c.length,...g.map(x=>x.length),0),y=Math.max(he,p*u+H*2),f=d.length>0?d.length*D+T*2:T*2,S=_+f;return {id:i,type:"uml-interface",x:e.x,y:e.y,width:y,height:S,className:c,methods:d,rotation:0,style:{...l,fillColor:"#ffffff"}}}case "mind-map":{let c=p=>`mm_${p}_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,d={id:c("root"),text:B("mindmap.defaultRoot"),children:[{id:c("b1"),text:B("mindmap.defaultBranch")},{id:c("b2"),text:B("mindmap.defaultBranch")},{id:c("b3"),text:B("mindmap.defaultBranch")}]},{width:u,height:g}=k(d);return {id:i,type:"mind-map",x:e.x,y:e.y,width:u,height:g,root:d,rotation:0,style:{...l,fillColor:"#ffffff"}}}default:return {id:i,type:"rectangle",x:e.x,y:e.y,width:s,height:r,rotation:0,style:l}}}function Te(a,e,t){let i=$*.6,n=[a];for(let d of e)n.push(`${d.visibility} ${d.name}: ${d.type}`);for(let d of t)n.push(`${d.visibility} ${d.name}(${d.params}): ${d.returnType}`);let r=Math.max(...n.map(d=>d.length),0)*i+H*2,o=Math.max(he,r),h=e.length>0?e.length*D+T*2:T*2,l=t.length>0?t.length*D+T*2:T*2,c=_+h+l;return {width:o,height:c}}var P=class extends L{type;constructor(e,t){super(e),this.type=t;}onPointerDown(e,t){let i=Y(this.type,e);this.context.commitHistory(),this.context.addShape(i),this.context.selectShape(i.id,false);}onPointerMove(e,t){}onPointerUp(e,t){this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(e){return this.context.getMindMapCursorHitAtPoint(e)?"pointer":"crosshair"}};var Xe={n:"top",e:"right",s:"bottom",w:"left"},le={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function De(a,e,t){return ce(a,e,t?le[Xe[t]]:void 0)}function ce(a,e,t){let i=e.x-a.x,n=e.y-a.y;return t&&t.x!==0?i>=0?"left":"right":t&&t.y!==0?n>=0?"top":"bottom":Math.abs(i)>=Math.abs(n)?i>=0?"left":"right":n>=0?"top":"bottom"}function ft(a,e,t){switch(t){case "top":return {x:a.x,y:a.y-e.height/2};case "bottom":return {x:a.x,y:a.y+e.height/2};case "left":return {x:a.x-e.width/2,y:a.y};case "right":return {x:a.x+e.width/2,y:a.y}}}var Ke=14,Le=class extends L{type="eraser";erasing=false;lastPoint=null;erasedIds=new Set;onPointerDown(e){this.erasing=true,this.lastPoint=e,this.erasedIds.clear(),this.context.commitHistory(),this.context.setEraserPoint(e),this.eraseAt(e);}onPointerMove(e){if(!this.erasing||!this.lastPoint)return;let t=this.lastPoint,i=Math.hypot(e.x-t.x,e.y-t.y),n=Math.max(1,Math.ceil(i/Math.max(this.brushRadius()*.5,1)));for(let s=1;s<=n;s++){let r=s/n;this.eraseAt({x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r});}this.lastPoint=e,this.context.setEraserPoint(e);}onPointerUp(){this.erasing=false,this.lastPoint=null,this.erasedIds.clear(),this.context.setEraserPoint(null);}onKeyDown(){}onKeyUp(){}getCursor(){return this.erasing?"grabbing":"crosshair"}dispose(){this.erasing=false,this.lastPoint=null,this.erasedIds.clear(),this.context.setEraserPoint(null);}brushRadius(){return Ke/this.context.getCamera().getZoom()}eraseAt(e){let t=this.context.getShapesInBrushRadius(e,this.brushRadius());for(let i of t)this.erasedIds.has(i.id)||(this.erasedIds.add(i.id),this.context.deleteShape(i.id));}};function ne(a,e,t){let i=s=>(s-.5)*e,n=s=>(s-.5)*t;return a.map(s=>s[0]==="Z"?s:s[0]==="M"||s[0]==="L"?[s[0],i(s[1]),n(s[2])]:["C",i(s[1]),n(s[2]),i(s[3]),n(s[4]),i(s[5]),n(s[6])])}function te(a,e,t,i,n,s,r){let o=[],h=s-n,l=Math.max(1,Math.ceil(Math.abs(h)/90)),c=h/l,d=4/3*Math.tan(c*Math.PI/180/4),u=y=>{let f=y*Math.PI/180;return [a+t*Math.cos(f),e+i*Math.sin(f)]},[g,p]=u(n);o.push(r?["M",g,p]:["L",g,p]);for(let y=0;y<l;y++){let f=n+c*y,S=f+c,x=f*Math.PI/180,M=S*Math.PI/180,[v,w]=u(f),[b,C]=u(S);o.push(["C",v-d*t*Math.sin(x),w+d*i*Math.cos(x),b+d*t*Math.sin(M),C-d*i*Math.cos(M),b,C]);}return o}function Ot(a){let e=1/0,t=1/0,i=-1/0,n=-1/0,s=(g,p)=>{g<e&&(e=g),p<t&&(t=p),g>i&&(i=g),p>n&&(n=p);},r=0,o=0,h=0,l=0;for(let g of a){if(g[0]==="Z"){s(h,l);continue}if(g[0]==="M"||g[0]==="L"){r=g[1],o=g[2],g[0]==="M"&&(h=r,l=o),s(r,o);continue}let p=g[1],y=g[2],f=g[3],S=g[4],x=g[5],M=g[6];for(let v=0;v<=12;v++){let w=v/12,b=1-w,C=b*b*b,E=3*b*b*w,N=3*b*w*w,O=w*w*w;s(C*r+E*p+N*f+O*x,C*o+E*y+N*S+O*M);}r=x,o=M;}let c=i-e||1,d=n-t||1,u=(g,p)=>[(g-e)/c,(p-t)/d];return a.map(g=>{if(g[0]==="Z")return g;if(g[0]==="M"||g[0]==="L"){let[v,w]=u(g[1],g[2]);return [g[0],v,w]}let[p,y]=u(g[1],g[2]),[f,S]=u(g[3],g[4]),[x,M]=u(g[5],g[6]);return ["C",p,y,f,S,x,M]})}function Ut(){let a={x:.24,y:.7,r:.24},e={x:.5,y:.48,r:.36},t={x:.76,y:.7,r:.24},i=[...te(a.x,a.y,a.r,a.r,90,246,true),...te(e.x,e.y,e.r,e.r,180,360,false),...te(t.x,t.y,t.r,t.r,294,450,false),["Z"]];return Ot(i)}var V=.14,mt=.5523,Q=V*mt,Ee=1-V,ee=.5-.5*mt,zt={outline:[["M",0,V],["L",0,Ee],["C",0,Ee+Q,ee,1,.5,1],["C",1-ee,1,1,Ee+Q,1,Ee],["L",1,V],["C",1,V-Q,1-ee,0,.5,0],["C",ee,0,0,V-Q,0,V],["Z"]],seams:[[["M",0,V],["C",0,V+Q,ee,V*2,.5,V*2],["C",1-ee,V*2,1,V+Q,1,V]]]},Yt={outline:Ut()},Wt={outline:[["M",.5,.97],["C",.5,.97,.03,.66,.03,.35],["C",.03,.17,.16,.04,.31,.04],["C",.41,.04,.47,.1,.5,.17],["C",.53,.1,.59,.04,.69,.04],["C",.84,.04,.97,.17,.97,.35],["C",.97,.66,.5,.97,.5,.97],["Z"]]},ke=[["M",0,.25],["L",.58,.25],["L",.58,0],["L",1,.5],["L",.58,1],["L",.58,.75],["L",0,.75],["Z"]];function Fe(a,e){let t=(i,n)=>{switch(e){case "down":return [1-n,i];case "left":return [1-i,1-n];case "up":return [n,1-i];default:return [i,n]}};return a.map(i=>{if(i[0]==="Z")return i;if(i[0]==="M"||i[0]==="L"){let[c,d]=t(i[1],i[2]);return [i[0],c,d]}let[n,s]=t(i[1],i[2]),[r,o]=t(i[3],i[4]),[h,l]=t(i[5],i[6]);return ["C",n,s,r,o,h,l]})}var Ae={right:ke,left:Fe(ke,"left"),up:Fe(ke,"up"),down:Fe(ke,"down")},Xt={outline:[["M",0,0],["L",0,1],["L",1,1],["Z"]]},Kt={outline:[["M",.34,0],["L",.66,0],["L",.66,.34],["L",1,.34],["L",1,.66],["L",.66,.66],["L",.66,1],["L",.34,1],["L",.34,.66],["L",0,.66],["L",0,.34],["L",.34,.34],["Z"]]},Ft={outline:[["M",0,.5],["L",.22,.13],["L",.22,.34],["L",.78,.34],["L",.78,.13],["L",1,.5],["L",.78,.87],["L",.78,.66],["L",.22,.66],["L",.22,.87],["Z"]]},Zt={outline:[["M",0,0],["L",1,0],["L",1,.8],["L",.32,.8],["L",.2,1],["L",.15,.8],["L",0,.8],["Z"]]},jt={outline:[...te(.5,.4,.5,.4,100,-228,true),["L",.19,1],["Z"]]},qt={outline:[["M",.5,0],["L",1,.25],["L",1,.75],["L",.5,1],["L",0,.75],["L",0,.25],["Z"]],seams:[[["M",.5,.5],["L",.5,1]],[["M",.5,.5],["L",0,.25]],[["M",.5,.5],["L",1,.25]]]},Jt={outline:[...te(.5,.5,.5,.5,0,-270,true),["L",.5,.5],["Z"]]},Qt={outline:[["M",0,0],...te(.6,.5,.4,.5,270,450,false),["L",0,1],["Z"]]},en={outline:[["M",0,0],["L",1,0],["L",1,1],["L",0,1],["Z"]],seams:[[["M",.12,0],["L",.12,1]],[["M",.88,0],["L",.88,1]]]},tn={outline:[["M",0,0],["L",1,0],["L",1,.84],["C",.72,1.06,.28,.62,0,.84],["Z"]]},nn={outline:[["M",0,0],["L",.45,0],["L",1,.5],["L",.45,1],["L",0,1],["L",.42,.5],["Z"]]};function sn(a){let e=t=>1-t;return a.map(t=>t[0]==="Z"?t:t[0]==="M"||t[0]==="L"?[t[0],e(t[1]),t[2]]:["C",e(t[1]),t[2],e(t[3]),t[4],e(t[5]),t[6]])}var de=.16,xt={outline:[["M",.015,.02],["C",.075,.02,.1,.08,.1,.2],["C",.1,.36,.125,.5,.16,.5],["C",.125,.5,.1,.64,.1,.8],["C",.1,.92,.075,.98,.015,.98]],strokeOnly:true},rn={outline:sn(xt.outline),strokeOnly:true};function He(a){if(a.type!=="brace-left"&&a.type!=="brace-right")return 0;let e=(a.width??0)*de/2;return a.type==="brace-left"?e:-e}var on={outline:[["M",0,0],["L",1,0],["L",1,1],["L",0,1],["Z"]],seams:[[["M",.1,0],["L",.1,1]],[["M",.9,0],["L",.9,1]]]};function $e(a){switch(a){case "cylinder":return zt;case "cloud":return Yt;case "heart":return Wt;case "class-catalog":return on;case "block-arrow-right":return {outline:Ae.right};case "block-arrow-left":return {outline:Ae.left};case "block-arrow-up":return {outline:Ae.up};case "block-arrow-down":return {outline:Ae.down};case "block-arrow-double":return Ft;case "right-triangle":return Xt;case "cross":return Kt;case "speech-rect":return Zt;case "speech-round":return jt;case "cube":return qt;case "sector":return Jt;case "delay":return Qt;case "predefined-process":return en;case "document":return tn;case "chevron":return nn;case "brace-left":return xt;case "brace-right":return rn;default:return}}var q=class a{ctx;width=0;height=0;dpr=window.devicePixelRatio||1;showGrid=false;textLayoutCache=new Map;static TEXT_CACHE_LIMIT=500;constructor(e,t){let i=e.getContext("2d");if(!i)throw new Error("Failed to get Canvas 2D context");this.ctx=i,typeof t=="number"&&t>0&&(this.dpr=t);}resize(e,t){this.width=e,this.height=t;let i=Math.ceil(e*this.dpr),n=Math.ceil(t*this.dpr);(this.ctx.canvas.width!==i||this.ctx.canvas.height!==n)&&(this.ctx.canvas.width=i,this.ctx.canvas.height=n,this.ctx.canvas.style.width=`${e}px`,this.ctx.canvas.style.height=`${t}px`);}setShowGrid(e){this.showGrid=e;}render(e,t,i,n,s,r,o,h,l,c,d,u,g){let p=this.ctx,y=t.getZoom(),f=t.x,S=t.y;p.setTransform(1,0,0,1,0,0),p.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),d&&(p.fillStyle=d,p.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height));let x=this.dpr*y;p.setTransform(x,0,0,x,x*f,x*S),this.showGrid&&this.drawGrid(p,y,f,S);let M=null;for(let w of e)if(w.type==="arrow"&&(w.startBinding||w.endBinding)){M=new Map,e.forEach(b=>M.set(b.id,b));break}let v=M??new Map;if(e.forEach(w=>{p.save(),p.translate(w.x,w.y),p.rotate(w.rotation);let b=i.has(w.id);this.drawShape(p,w,b,y,v,l,c),p.restore();}),o&&this.drawGenerationPreview(p,o,y,e,v),u&&!i.has(u)){let w=e.find(b=>b.id===u);w&&this.drawConnectionDots(p,this.getShapeWorldBounds(w),y,.6);}if(g&&!i.has(g)){let w=e.find(b=>b.id===g);if(w){let b=this.getConnectorRoute(w,v);b.length>=2&&this.drawLinearHighlight(p,b,y,.22,9);}}n&&this.drawBrushRect(p,n,y),s&&s.length>0&&this.drawSnapGuides(p,s,y),r&&this.drawConnectingTargetHighlight(p,r,e,y),h&&this.drawEraserBrush(p,h,y),p.setTransform(1,0,0,1,0,0);}drawEraserBrush(e,t,i){let n=Ke/i;e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.fillStyle=R(I.primary,.12),e.fill(),e.strokeStyle=R(I.primary,.55),e.lineWidth=1.5/i,e.stroke();}drawConnectingTargetHighlight(e,t,i,n){let s=i.find(l=>l.id===t);if(!s||s.type==="line"||s.type==="arrow"||s.type==="draw")return;let r=this.getShapeWorldBounds(s),o=[{x:r.x+r.width/2,y:r.y},{x:r.x+r.width,y:r.y+r.height/2},{x:r.x+r.width/2,y:r.y+r.height},{x:r.x,y:r.y+r.height/2}],h=6/n;e.save(),o.forEach(l=>{e.beginPath(),e.arc(l.x,l.y,h,0,Math.PI*2),e.fillStyle=I.selection.handleFill,e.fill(),e.strokeStyle=I.primary,e.lineWidth=2/n,e.stroke();}),e.restore();}getShapeWorldBounds(e){let t=this.getShapeBounds(e);return {x:e.x+t.x,y:e.y+t.y,width:t.width,height:t.height}}drawBrushRect(e,t,i){e.save(),e.fillStyle=I.brushFill,e.strokeStyle=I.brushStroke,e.lineWidth=1.5/i,e.setLineDash([4/i,4/i]),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.fill(),e.stroke(),e.restore();}drawGrid(e,t,i,n){let s=-i,r=-n,o=s+this.width/t,h=r+this.height/t,l=20;for(;l*t<10;)l*=2;e.strokeStyle=I.grid,e.lineWidth=1/t,e.beginPath();for(let c=Math.floor(s/l)*l;c<=o;c+=l)e.moveTo(c,r),e.lineTo(c,h);for(let c=Math.floor(r/l)*l;c<=h;c+=l)e.moveTo(s,c),e.lineTo(o,c);e.stroke();}drawShape(e,t,i,n,s,r,o){switch(this.applyStyle(e,t.style,n),t.type){case "rectangle":this.drawRectangle(e,t,i);break;case "rounded-rectangle":this.drawRoundedRectangle(e,t,i);break;case "circle":this.drawCircle(e,t,i);break;case "ellipse":this.drawEllipse(e,t,i);break;case "diamond":this.drawDiamond(e,t,i);break;case "triangle":this.drawTriangle(e,t,i);break;case "hexagon":this.drawHexagon(e,t,i);break;case "parallelogram":this.drawParallelogram(e,t,i);break;case "trapezoid":this.drawTrapezoid(e,t,i);break;case "pentagon":this.drawPentagon(e,t,i);break;case "octagon":this.drawOctagon(e,t,i);break;case "star":this.drawStar(e,t,i);break;case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "class-catalog":case "chevron":case "brace-left":case "brace-right":this.drawPathShape(e,t,i);break;case "stadium":this.drawStadium(e,t,i);break;case "uml-class":this.drawUmlClass(e,t,i);break;case "uml-interface":this.drawUmlInterface(e,t,i);break;case "mind-map":this.drawMindMap(e,t,i,r,o);break;case "line":this.drawLine(e,t,s,i,n);break;case "arrow":this.drawArrow(e,t,s,i,n);break;case "text":this.drawText(e,t);break;case "draw":this.drawFreehand(e,t);break}if(t.text&&t.type!=="text"&&t.type!=="line"&&t.type!=="arrow"&&t.type!=="draw"&&this.drawShapeText(e,t),i){let h=t.type==="line"||t.type==="arrow";t.type==="mind-map"||(h?this.drawSelectionHandles(e,t,n,s):(this.drawSelectionOutline(e,t,n),this.drawSelectionHandles(e,t,n)));}}applyStyle(e,t,i){let n=t.strokeOpacity??1;e.strokeStyle=n<1&&t.strokeColor!=="transparent"?R(t.strokeColor,n):t.strokeColor,e.lineWidth=t.strokeWidth/i,e.lineCap="round",e.lineJoin="round";let s=t.fillOpacity??1;s<1&&t.fillColor!=="transparent"?e.fillStyle=R(t.fillColor,s):e.fillStyle=t.fillColor,t.strokeDash?e.setLineDash(t.strokeDash):e.setLineDash([]);}drawRectangle(e,t,i){e.beginPath(),e.rect(-t.width/2,-t.height/2,t.width,t.height),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawRoundedRectangle(e,t,i){let{width:n,height:s,borderRadius:r}=t;e.beginPath(),e.roundRect(-n/2,-s/2,n,s,r),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStadium(e,t,i){let{width:n,height:s}=t;e.beginPath(),e.roundRect(-n/2,-s/2,n,s,Math.min(n,s)/2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawCircle(e,t,i){e.beginPath(),e.arc(0,0,t.radius,0,Math.PI*2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawEllipse(e,t,i){e.beginPath(),e.ellipse(0,0,t.width/2,t.height/2,0,0,Math.PI*2),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawDiamond(e,t,i){e.beginPath(),e.moveTo(0,-t.height/2),e.lineTo(t.width/2,0),e.lineTo(0,t.height/2),e.lineTo(-t.width/2,0),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawTriangle(e,t,i){e.beginPath(),e.moveTo(0,-t.height/2),e.lineTo(t.width/2,t.height/2),e.lineTo(-t.width/2,t.height/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawHexagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<6;r++){let o=r*Math.PI/3-Math.PI/2,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawParallelogram(e,t,i){let{width:n,height:s}=t,r=n*.2;e.beginPath(),e.moveTo(-n/2+r,-s/2),e.lineTo(n/2,-s/2),e.lineTo(n/2-r,s/2),e.lineTo(-n/2,s/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawTrapezoid(e,t,i){let{width:n,height:s}=t,r=n*.15;e.beginPath(),e.moveTo(-n/2+r,-s/2),e.lineTo(n/2-r,-s/2),e.lineTo(n/2,s/2),e.lineTo(-n/2,s/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPentagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<5;r++){let o=r*2*Math.PI/5-Math.PI/2,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawOctagon(e,t,i){let n=t.width/2,s=t.height/2;e.beginPath();for(let r=0;r<8;r++){let o=r*Math.PI/4-Math.PI/8,h=n*Math.cos(o),l=s*Math.sin(o);r===0?e.moveTo(h,l):e.lineTo(h,l);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStar(e,t,i){let n=t.width/2,s=t.height/2,r=5,o=.4;e.beginPath();for(let h=0;h<r*2;h++){let l=h*Math.PI/r-Math.PI/2,c=h%2===0?1:o,d=n*c*Math.cos(l),u=s*c*Math.sin(l);h===0?e.moveTo(d,u):e.lineTo(d,u);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPathShape(e,t,i){let n=$e(t.type);if(n&&(this.tracePath(e,ne(n.outline,t.width,t.height)),!n.strokeOnly&&t.style.fillColor!=="transparent"&&e.fill(),e.stroke(),n.seams))for(let s of n.seams)this.tracePath(e,ne(s,t.width,t.height)),e.stroke();}tracePath(e,t){e.beginPath();for(let i of t)switch(i[0]){case "M":e.moveTo(i[1],i[2]);break;case "L":e.lineTo(i[1],i[2]);break;case "C":e.bezierCurveTo(i[1],i[2],i[3],i[4],i[5],i[6]);break;case "Z":e.closePath();break}}drawUmlClass(e,t,i){let{width:n,height:s,className:r,attributes:o,methods:h}=t,l=n/2,c=s/2,d=_,u=o.length>0?o.length*D+T*2:T*2;e.beginPath(),e.rect(-l,-c,n,s),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-l,-c+d),e.lineTo(l,-c+d),e.moveTo(-l,-c+d+u),e.lineTo(l,-c+d+u),e.stroke(),e.save(),e.textBaseline="middle";let g=n-H*2,p=x=>{if(e.measureText(x).width<=g)return x;let M="\u2026",v=0,w=x.length;for(;v<w;){let b=v+w+1>>1;e.measureText(x.slice(0,b)+M).width<=g?v=b:w=b-1;}return x.slice(0,v)+M},y=(x,M,v,w,b,C,E)=>{let N=w||$,O=b||"#1f2937";e.font=`${N}px sans-serif`,e.fillStyle=O,e.textAlign=E;let re=p(x);if(e.fillText(re,M,v),C){let at=e.measureText(re).width,ht=M;e.strokeStyle=O,e.beginPath(),e.moveTo(ht,v),e.lineTo(ht+at,v),e.stroke();}};e.font=`bold ${t.fontSize||$}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937",e.fillText(p(r),0,-c+d/2);let f=-c+d+T+D/2;o.forEach((x,M)=>{let v=`${x.visibility} ${x.name}: ${x.type}`;y(v,-l+H,f+M*D,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");});let S=-c+d+u+T+D/2;h.forEach((x,M)=>{let v=`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`;y(v,-l+H,S+M*D,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");}),e.restore();}drawUmlInterface(e,t,i){let{width:n,height:s,className:r,methods:o}=t,h=n/2,l=s/2,c=_;e.beginPath(),e.rect(-h,-l,n,s),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-h,-l+c),e.lineTo(h,-l+c),e.stroke(),e.save(),e.textBaseline="middle";let d=n-H*2,u=f=>{if(e.measureText(f).width<=d)return f;let S="\u2026",x=0,M=f.length;for(;x<M;){let v=x+M+1>>1;e.measureText(f.slice(0,v)+S).width<=d?x=v:M=v-1;}return f.slice(0,x)+S},g=(f,S,x,M,v,w,b)=>{let C=M||$,E=v||"#1f2937";e.font=`${C}px sans-serif`,e.fillStyle=E,e.textAlign=b;let N=u(f);if(e.fillText(N,S,x),w){let O=e.measureText(N).width,re=S;e.strokeStyle=E,e.beginPath(),e.moveTo(re,x),e.lineTo(re+O,x),e.stroke();}};e.font=`bold ${t.fontSize||$}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937";let p=`<<${r||"Interface"}>>`;e.fillText(u(p),0,-l+c/2);let y=-l+c+T+D/2;o.forEach((f,S)=>{let x=`${f.visibility} ${f.name}(${f.params}): ${f.returnType}`;g(x,-h+H,y+S*D,f.fontSize||t.fontSize||0,f.textColor||t.textColor||"",!!f.strikethrough,"left");}),e.restore();}static DEFAULT_CORNER_RADIUS=10;static CONNECTION_LEAD=24;drawMindMap(e,t,i,n,s){let o=k(t.root).positions;this.drawMindMapConnections(e,t.root,o),this.drawMindMapNodes(e,t,o,n,s);}drawMindMapConnections(e,t,i){let n=s=>{if(s.collapsed)return;let r=i.get(s.id);if(r)for(let o of s.children??[]){let h=i.get(o.id);if(!h)continue;let l=j(o,h.depth);e.strokeStyle=l,e.lineWidth=2,e.lineCap="round",e.beginPath(),e.moveTo(r.x+r.width/2,r.y);let c=(r.x+r.width/2+(h.x-h.width/2))/2;e.bezierCurveTo(c,r.y,c,h.y,h.x-h.width/2,h.y),e.stroke(),n(o);}};n(t);}drawMindMapNodes(e,t,i,n,s){let r=t.root,o=h=>{let l=i.get(h.id);if(!l)return;let c=j(h,l.depth),d=l.width/2,u=l.height/2;if(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.roundRect(l.x-d,l.y-u,l.width,l.height,6),e.fill(),e.stroke(),s&&s.shapeId===t.id&&s.nodeId===h.id&&(e.fillStyle=R(I.primary,.06),e.strokeStyle=R(I.primary,.55),e.lineWidth=2,e.beginPath(),e.roundRect(l.x-d,l.y-u,l.width,l.height,6),e.fill(),e.stroke()),n&&n.shapeId===t.id&&n.nodeId===h.id&&(e.fillStyle=R(I.primary,.12),e.strokeStyle=I.primary,e.lineWidth=2.5,e.beginPath(),e.roundRect(l.x-d,l.y-u,l.width,l.height,6),e.fill(),e.stroke()),h.children&&h.children.length>0&&(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.arc(l.x+d+10,l.y,8,0,Math.PI*2),e.fill(),e.stroke(),e.fillStyle=c,e.font="bold 13px sans-serif",e.textAlign="center",e.textBaseline="middle",e.fillText(h.collapsed?"+":"\u2212",l.x+d+10,l.y+.5)),h.note){let b=h.noteColor??c;e.font="11px sans-serif";let C=Math.min(e.measureText(h.note).width+12,130),E=16;e.fillStyle=b,e.beginPath(),e.roundRect(l.x-d,l.y-u-E+2,C,E,4),e.fill(),e.fillStyle="#ffffff",e.font="11px sans-serif",e.textAlign="left",e.textBaseline="middle",e.fillText(e.measureText(h.note).width+12>130?h.note.slice(0,12)+"\u2026":h.note,l.x-d+6,l.y-u-E/2+2);}e.font=`${14}px sans-serif`;let f=h.icon?18:0,S=l.width-f-(h.icon?8:0)-16,x=this.ellipsizeText(e,h.text||"",S),M=e.measureText(x).width,v=f+(f?8:0)+M,w=l.x-v/2;if(e.textBaseline="middle",h.icon&&(e.font="16px sans-serif",e.textAlign="left",e.fillStyle="#1f2937",e.fillText(h.icon,w,l.y+1),w+=f+8),e.font=`${14}px sans-serif`,e.textAlign="left",e.fillStyle="#1f2937",e.fillText(x,w,l.y),!h.collapsed)for(let b of h.children??[])o(b);};o(r);}ellipsizeText(e,t,i){if(i<=0)return "";if(e.measureText(t).width<=i)return t;let n="\u2026",s=0,r=t.length;for(;s<r;){let o=s+r+1>>1;e.measureText(t.slice(0,o)+n).width<=i?s=o:r=o-1;}return t.slice(0,s)+n}resolveConnectorEnds(e,t){let i=e.points.map(r=>({x:r.x,y:r.y}));if(i.length<2)return {world:i};let n=i.length-1;if(e.type==="line")return i[0]=this.clampToShapeOutline(i[0],t,e.id,i[n]),i[n]=this.clampToShapeOutline(i[n],t,e.id,i[0]),{world:i,fromN:this.getDockNormal(i[0],t,e.id),toN:this.getDockNormal(i[n],t,e.id)};let s=e.endBinding;if(e.startBinding){let r=t.get(e.startBinding.toShapeId);r&&(i[0]=this.getBindingPoint(r,e.startBinding));}if(e.endBinding){let r=t.get(e.endBinding.toShapeId);r&&(s=this.resolveAutoEndBinding(e.endBinding,e,i[0],r),i[n]=this.getBindingPoint(r,s));}return e.startBinding||(i[0]=this.clampToShapeOutline(i[0],t,e.id,i[n])),e.endBinding||(i[n]=this.clampToShapeOutline(i[n],t,e.id,i[0])),{world:i,fromN:this.resolveDockNormal(e.startBinding,i[0],t,e.id),toN:this.resolveDockNormal(s,i[n],t,e.id)}}withUserPoints(e,t){let i=e.userPoints;if(!i||i.length===0||t.length<2)return t;let n=this.effectiveConnType(e),s=[t[0],t[t.length-1]],[r,o]=n==="curve"?s:this.getAlignedPoints(s);return [r,...i.map(h=>({x:h.x,y:h.y})),o]}getConnectorRoute(e,t){if(e.type!=="arrow"&&e.type!=="line")return [];if(!e.points||e.points.length<2)return [];let i=e,{world:n,fromN:s,toN:r}=this.resolveConnectorEnds(i,t),h=this.withUserPoints(i,n).map(d=>({x:d.x-e.x,y:d.y-e.y})),l=this.effectiveConnType(i);return (l==="straight"?this.straightAligned(h):this.buildPathPoints(h,l,{fromN:s,toN:r})).map(d=>({x:d.x+e.x,y:d.y+e.y}))}drawSegmentHandles(e,t,i){let n=Se(t);if(n.length===0)return;let s=20/i,r=6/i;e.save(),e.setLineDash([]),e.lineWidth=1.5/i,e.strokeStyle="#ffffff",e.fillStyle=I.primary;for(let o of n){let h=o.axis==="H"?s:r,l=o.axis==="H"?r:s;e.beginPath(),e.roundRect(o.center.x-h/2,o.center.y-l/2,h,l,r/2),e.fill(),e.stroke();}e.restore();}drawLine(e,t,i,n,s){if(t.points.length<2)return;let r=t,{world:o,fromN:h,toN:l}=this.resolveConnectorEnds(r,i),c=this.withUserPoints(r,o).map(g=>({x:g.x-t.x,y:g.y-t.y})),d=this.effectiveConnType(t),u=d==="straight"?this.straightAligned(c):this.buildPathPoints(c,d,{fromN:h,toN:l});if(d==="straight"){e.beginPath(),e.moveTo(u[0].x,u[0].y);for(let g=1;g<u.length;g++)e.lineTo(u[g].x,u[g].y);e.stroke(),e.setLineDash([]);}else d==="orthogonal"?this.drawSharpPolyline(e,u):this.drawRoundedPolyline(e,u,a.DEFAULT_CORNER_RADIUS),e.stroke(),e.setLineDash([]);n&&(this.drawLinearHighlight(e,u,s),this.drawSegmentHandles(e,u,s));}drawArrow(e,t,i,n,s){if(t.points.length<2)return;let{world:r,fromN:o,toN:h}=this.resolveConnectorEnds(t,i),l=this.withUserPoints(t,r).map(p=>({x:p.x-t.x,y:p.y-t.y})),c=this.effectiveConnType(t),d=t.arrowHead??"end";!!t.dashed||d==="dependency"||d==="realization"?e.setLineDash([8,5]):e.setLineDash([]);let g;if(c==="straight"){let p=this.straightAligned(l);g=p,e.beginPath(),e.moveTo(p[0].x,p[0].y);for(let y=1;y<p.length;y++)e.lineTo(p[y].x,p[y].y);e.stroke(),this.drawArrowHeads(e,p,d);}else g=this.buildPathPoints(l,c,{fromN:o,toN:h}),c==="orthogonal"?this.drawSharpPolyline(e,g):this.drawRoundedPolyline(e,g,a.DEFAULT_CORNER_RADIUS),e.stroke(),this.drawArrowHeads(e,g,d);e.setLineDash([]),n&&(this.drawLinearHighlight(e,g,s),this.drawSegmentHandles(e,g,s));}drawLinearHighlight(e,t,i,n=1,s=7){if(!(!t||t.length<2)){e.save(),e.globalAlpha=n,e.strokeStyle=I.lineHighlight,e.lineWidth=s/i,e.lineCap="round",e.lineJoin="round",e.setLineDash([]),e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let r=1;r<t.length;r++)e.lineTo(t[r].x,t[r].y);e.stroke(),e.restore();}}drawGenerationPreview(e,t,i,n,s){let{from:r,to:o}=t,h=t.arrowStyle??{connectionType:"polyline",arrowHead:"end",dashed:false},l=new Map(s);n.forEach(y=>l.set(y.id,y));let c=t.targetShapeId;if(!c&&t.type){let y=Y(t.type,o);y.id=a.GEN_GHOST_ID,l.set(a.GEN_GHOST_ID,y),c=a.GEN_GHOST_ID;}let d=t.sourceEdge?Xe[t.sourceEdge]:void 0,u=t.sourceShapeId&&d?{toShapeId:t.sourceShapeId,handle:d}:void 0,g=c?{...t.targetBinding??{auto:true,handle:"left"},toShapeId:c}:void 0,p={id:a.GEN_PREVIEW_ID,type:"arrow",x:r.x,y:r.y,points:[r,o],rotation:0,style:t.lineStyle??a.PREVIEW_LINE_STYLE,startBinding:u,endBinding:g,connectionType:h.connectionType,arrowHead:h.arrowHead,dashed:h.dashed};if(e.save(),t.dragging||(e.globalAlpha=.65),e.translate(r.x,r.y),this.applyStyle(e,p.style,i),this.drawArrow(e,p,l,false,i),e.restore(),t.type){let y=l.get(a.GEN_GHOST_ID),f=y?this.getShapeBounds(y):{x:-60,y:-30,width:120,height:60};this.drawPreviewShapeOutline(e,o,t.type,f,i);}e.save(),e.beginPath(),e.arc(r.x,r.y,5/i,0,Math.PI*2),e.fillStyle=I.genDot,e.fill(),e.restore();}drawPreviewShapeOutline(e,t,i,n,s){let r=n.width,o=n.height,h=r/2,l=o/2,c=t.x,d=t.y;switch(e.strokeStyle=I.genLine,e.lineWidth=1.5/s,e.setLineDash([6/s,4/s]),e.beginPath(),i){case "circle":case "ellipse":e.ellipse(c,d,r/2,o/2,0,0,Math.PI*2);break;case "diamond":e.moveTo(c,d-l),e.lineTo(c+h,d),e.lineTo(c,d+l),e.lineTo(c-h,d),e.closePath();break;case "triangle":e.moveTo(c,d-l),e.lineTo(c+h,d+l),e.lineTo(c-h,d+l),e.closePath();break;case "hexagon":for(let u=0;u<6;u++){let g=u*Math.PI/3-Math.PI/2,p=c+h*Math.cos(g),y=d+l*Math.sin(g);u===0?e.moveTo(p,y):e.lineTo(p,y);}e.closePath();break;case "parallelogram":{let u=r*.15;e.moveTo(c-h+u,d-l),e.lineTo(c+h,d-l),e.lineTo(c+h-u,d+l),e.lineTo(c-h,d+l),e.closePath();break}default:e.roundRect(c-h,d-l,r,o,i==="rounded-rectangle"?8:4);break}e.stroke();}static ALIGN_TOLERANCE=8;static GEN_PREVIEW_ID="__gen_preview_line__";static GEN_GHOST_ID="__gen_preview_ghost__";static PREVIEW_LINE_STYLE={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null};straightAligned(e){return e.length===2?this.getAlignedPoints(e):e}effectiveConnType(e){let t=e.connectionType||"straight";return t==="straight"&&e.userPoints&&e.userPoints.length>0?"polyline":t}getAlignedPoints(e){if(e.length<2)return e;let t=e[0],i=e[e.length-1],n=i.x-t.x,s=i.y-t.y,r=a.ALIGN_TOLERANCE;if(Math.abs(s)<=r){let o=(t.y+i.y)/2;return e.map(h=>({x:h.x,y:o}))}if(Math.abs(n)<=r){let o=(t.x+i.x)/2;return e.map(h=>({x:o,y:h.y}))}return e}buildPathPoints(e,t,i={}){if(e.length<2)return e;if(t==="straight")return this.straightAligned(e);if(t==="polyline"||t==="orthogonal"){let n=e.length===2?this.getAlignedPoints(e):e;return this.generatePolylinePoints(n,i)}return t==="curve"?this.generateCurvePoints(e,i):e}drawRoundedPolyline(e,t,i){if(e.beginPath(),!(t.length<2)){if(t.length===2||i<=0){e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);return}e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length-1;n++){let s=t[n-1],r=t[n],o=t[n+1],h=r.x-s.x,l=r.y-s.y,c=o.x-r.x,d=o.y-r.y,u=Math.hypot(h,l),g=Math.hypot(c,d);if(u<1e-6||g<1e-6){e.lineTo(r.x,r.y);continue}let p=Math.min(i,u*.5,g*.5),y=r.x-h/u*p,f=r.y-l/u*p,S=r.x+c/g*p,x=r.y+d/g*p;e.lineTo(y,f),e.arcTo(r.x,r.y,S,x,p);}e.lineTo(t[t.length-1].x,t[t.length-1].y);}}drawSharpPolyline(e,t){if(e.beginPath(),!(t.length<2)){e.moveTo(t[0].x,t[0].y);for(let i=1;i<t.length;i++)e.lineTo(t[i].x,t[i].y);}}drawSnapGuides(e,t,i){e.save(),e.strokeStyle=I.guide,e.lineWidth=1/i,e.setLineDash([6/i,4/i]),e.beginPath();for(let n of t)n.type==="horizontal"?(e.moveTo(n.start,n.position),e.lineTo(n.end,n.position)):(e.moveTo(n.position,n.start),e.lineTo(n.position,n.end));e.stroke(),e.restore();}generatePolylinePoints(e,t={}){if(e.length<2)return e;let i=[];i.push(e[0]);let n=e.length-1,s=a.CONNECTION_LEAD,r=e[0],o=e[n];t.fromN&&t.toN&&(t.fromN.x!==0&&t.toN.x!==0?s=Math.min(s,Math.abs(o.x-r.x)/2):t.fromN.y!==0&&t.toN.y!==0&&(s=Math.min(s,Math.abs(o.y-r.y)/2)));for(let h=1;h<e.length;h++){let l=e[h-1],c=e[h],d=h===1,u=h===n,g=d&&t.fromN?{x:l.x+t.fromN.x*s,y:l.y+t.fromN.y*s}:l,p=u&&t.toN?{x:c.x+t.toN.x*s,y:c.y+t.toN.y*s}:c;d&&t.fromN&&i.push(g);let y=d?t.fromN:void 0,f=u?t.toN:void 0,S=f?f.x!==0?"H":"V":y?y.x!==0?"H":"V":void 0,x=this.computeOrthogonalRoute(g,p,S);S&&(x=this.ensureFinalAxis(x,S));for(let M of x)i.push(M);u&&t.toN&&i.push(c);}return this.collapseLinePoints(i)}ensureFinalAxis(e,t){if(e.length<2)return e;let i=e[e.length-1],n=e[e.length-2],s=Math.abs(i.y-n.y)<1e-6;if(t==="H"?s:!s)return e;let r=t==="H"?{x:n.x,y:i.y}:{x:i.x,y:n.y},o=e.slice(0,-1);return o.push(r,i),o}collapseLinePoints(e){return oe(e)}computeOrthogonalRoute(e,t,i){let n=t.x-e.x,s=t.y-e.y;if(Math.abs(n)<1||Math.abs(s)<1)return [t];let r=e.x+n/2,o=e.y+s/2,h=Math.max(e.x,Math.min(r,t.x)),l=Math.max(e.y,Math.min(o,t.y));return i==="H"?[{x:h,y:e.y},{x:h,y:t.y},t]:i==="V"?[{x:e.x,y:l},{x:t.x,y:l},t]:Math.abs(n)>=Math.abs(s)?[{x:r,y:e.y},{x:r,y:t.y},t]:[{x:e.x,y:o},{x:t.x,y:o},t]}generateCurvePoints(e,t={}){if(e.length<2)return e;let i=e.length,n=[e[0]],s=h=>{let l=e[h],c=e[h+1];return Math.hypot(c.x-l.x,c.y-l.y)},r=h=>Math.max(16,Math.min(h*.32,150)),o=h=>{let l=e[Math.max(0,h-1)],c=e[Math.min(i-1,h+1)],d=c.x-l.x,u=c.y-l.y,g=Math.hypot(d,u);return g<1e-6?{x:1,y:0}:{x:d/g,y:u/g}};for(let h=0;h<i-1;h++){let l=e[h],c=e[h+1],d=s(h),u;if(h===0&&t.fromN)u={x:l.x+t.fromN.x*r(d),y:l.y+t.fromN.y*r(d)};else {let y=o(h);u={x:l.x+y.x*r(d),y:l.y+y.y*r(d)};}let g;if(h===i-2&&t.toN)g={x:c.x+t.toN.x*r(d),y:c.y+t.toN.y*r(d)};else {let y=o(h+1);g={x:c.x-y.x*r(d),y:c.y-y.y*r(d)};}let p=20;for(let y=1;y<=p;y++){let f=y/p,S=1-f,x=S*S*S*l.x+3*S*S*f*u.x+3*S*f*f*g.x+f*f*f*c.x,M=S*S*S*l.y+3*S*S*f*u.y+3*S*f*f*g.y+f*f*f*c.y;n.push({x,y:M});}}return n}getDisplayLines(e,t,i,n,s,r){let o=n*1.3,h=Math.max(1,Math.floor(r/o)),l=`${t.id}\0${i}\0${n}\0${s}x${r}\0${h}`,c=this.textLayoutCache.get(l);if(c)return c;let d=i.split(`
2
+ `),u=[];for(let p of d){let y=this.wrapLine(e,p,s);for(let f of y)u.push(f);}let g=u.slice(0,h);return u.length>h&&g.length>0&&(g[g.length-1]=this.truncateLine(e,g[g.length-1],s)),this.textLayoutCache.size>=a.TEXT_CACHE_LIMIT&&this.textLayoutCache.clear(),this.textLayoutCache.set(l,g),g}drawShapeText(e,t){let i=t.text||"";if(!i)return;let n=t.fontSize||16;e.font=`${n}px sans-serif`,e.fillStyle=t.textColor||"#1f2937";let s=this.getTextBounds(t),r=n*1.3,o=this.getDisplayLines(e,t,i,n,s.width,s.height),l=-(o.length*r)/2+r/2,c=He(t);e.textAlign="center",e.textBaseline="middle",o.forEach((d,u)=>{let g=l+u*r;e.fillText(d,c,g);});}getTextBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "uml-class":case "uml-interface":return {width:e.width*.85,height:e.height*.85};case "brace-left":case "brace-right":return {width:e.width*(1-de)*.85,height:e.height*.85};case "circle":return {width:e.radius*2*.85,height:e.radius*2*.85};default:return {width:100,height:40}}}wrapLine(e,t,i){if(!t)return [""];let n=[],s="";for(let r of t){let o=s+r;e.measureText(o).width>i&&s?(n.push(s),s=r):s=o;}return s&&n.push(s),n}truncateLine(e,t,i){if(!t)return "...";let n="...",s=t;for(;s.length>0&&e.measureText(s+n).width>i;)s=s.slice(0,-1);return s+n}static HANDLE_NORMALS=le;pickAutoHandle(e,t,i){return ce(e,t,i)}resolveAutoEndBinding(e,t,i,n){if(!e.auto||e.isPrecise)return e;let s=t.startBinding?.handle?a.HANDLE_NORMALS[t.startBinding.handle]:void 0;return {...e,handle:this.pickAutoHandle(i,{x:n.x,y:n.y},s)}}getBindingPoint(e,t){if(t.isPrecise&&t.normalizedAnchor){let i=this.getShapePageBounds(e),n={x:i.x+i.width*t.normalizedAnchor.x,y:i.y+i.height*t.normalizedAnchor.y},s={x:e.x,y:e.y};return this.nearestPointOnShapeOutline(e,s,n)}if(t.handle){let i=this.getShapeBounds(e);switch(t.handle){case "top":return {x:e.x,y:e.y+i.y};case "bottom":return {x:e.x,y:e.y+i.y+i.height};case "left":return {x:e.x+i.x,y:e.y};case "right":return {x:e.x+i.x+i.width,y:e.y}}}return {x:e.x,y:e.y}}resolveDockNormal(e,t,i,n){return e&&!e.isPrecise&&e.handle?a.HANDLE_NORMALS[e.handle]:this.getDockNormal(t,i,n,e?.toShapeId)}getDockNormal(e,t,i,n){if(!t||t.size===0)return;let s=null,r=1/0,o=.5;if(t.forEach((d,u)=>{if(u===i||d.type==="line"||d.type==="arrow")return;let g=this.getShapePageBounds(d);if(e.x>=g.x-o&&e.x<=g.x+g.width+o&&e.y>=g.y-o&&e.y<=g.y+g.height+o){let p=d.id===n?-1:(e.x-d.x)**2+(e.y-d.y)**2;p<r&&(r=p,s=d);}}),!s)return;let h=s,l=e.x-h.x,c=e.y-h.y;return Math.abs(c)>Math.abs(l)?{x:0,y:c<0?-1:1}:{x:l<0?-1:1,y:0}}getShapePageBounds(e){let t=this.getShapeBounds(e);return {x:e.x+t.x,y:e.y+t.y,width:t.width,height:t.height}}clampToShapeOutline(e,t,i,n){if(!t||t.size===0)return e;let s=null,r=1/0;if(t.forEach((h,l)=>{if(l===i)return;let c=this.getShapePageBounds(h);if(e.x>c.x&&e.x<c.x+c.width&&e.y>c.y&&e.y<c.y+c.height){let d=(h.x-n.x)**2+(h.y-n.y)**2;d<r&&(r=d,s=h);}}),!s)return e;let o=s;return this.nearestPointOnShapeOutline(o,{x:o.x,y:o.y},e)}nearestPointOnShapeOutline(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=Math.hypot(n,s);if(r<1e-6)return {x:t.x,y:t.y};let o=n/r,h=s/r,l=Math.max(1e4,r*2),c={x:t.x+o*l,y:t.y+h*l},d=this.intersectShapeOutlineWithSegment(e,t,c);if(d.length===0)return i;let u=d[0],g=(u.x-t.x)**2+(u.y-t.y)**2;for(let p=1;p<d.length;p++){let y=(d[p].x-t.x)**2+(d[p].y-t.y)**2;y<g&&(g=y,u=d[p]);}return u}intersectShapeOutlineWithSegment(e,t,i){let n={x:t.x-e.x,y:t.y-e.y},s={x:i.x-e.x,y:i.y-e.y};return this.intersectLocalShapeOutlineWithSegment(e,n,s).map(o=>({x:o.x+e.x,y:o.y+e.y}))}intersectLocalShapeOutlineWithSegment(e,t,i){switch(e.type){case "rectangle":case "rounded-rectangle":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "ellipse":case "diamond":case "triangle":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":{let n=e.width,s=e.height,r={x:-n/2,y:-s/2,width:n,height:s};return this.intersectSegmentRect(t,i,r)}case "circle":{let n=e.radius;return this.intersectSegmentCircle(t,i,{x:0,y:0},n)}default:return []}}intersectSegmentRect(e,t,i){let n=i.x,s=i.y,r=i.width,o=i.height,h=[[{x:n,y:s},{x:n+r,y:s}],[{x:n+r,y:s},{x:n+r,y:s+o}],[{x:n+r,y:s+o},{x:n,y:s+o}],[{x:n,y:s+o},{x:n,y:s}]],l=[];for(let[c,d]of h){let u=this.segmentIntersection(e,t,c,d);u&&l.push(u);}return l}segmentIntersection(e,t,i,n){let s=e.x,r=e.y,o=t.x,h=t.y,l=i.x,c=i.y,d=n.x,u=n.y,g=(s-o)*(c-u)-(r-h)*(l-d);if(Math.abs(g)<1e-9)return null;let p=((s-l)*(c-u)-(r-c)*(l-d))/g,y=-((s-o)*(r-c)-(r-h)*(s-l))/g;return p<0||p>1||y<0||y>1?null:{x:s+p*(o-s),y:r+p*(h-r)}}intersectSegmentCircle(e,t,i,n){let s=t.x-e.x,r=t.y-e.y,o=e.x-i.x,h=e.y-i.y,l=s*s+r*r,c=2*(o*s+h*r),d=o*o+h*h-n*n,u=c*c-4*l*d;if(u<0)return [];u=Math.sqrt(u);let g=(-c-u)/(2*l),p=(-c+u)/(2*l),y=[];return g>=0&&g<=1&&y.push({x:e.x+g*s,y:e.y+g*r}),p>=0&&p<=1&&Math.abs(p-g)>1e-6&&y.push({x:e.x+p*s,y:e.y+p*r}),y}drawArrowHead(e,t,i){let n=Math.atan2(i.y-t.y,i.x-t.x),s=12;e.save(),e.setLineDash([]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x-s*Math.cos(n-Math.PI/6),i.y-s*Math.sin(n-Math.PI/6)),e.moveTo(i.x,i.y),e.lineTo(i.x-s*Math.cos(n+Math.PI/6),i.y-s*Math.sin(n+Math.PI/6)),e.stroke(),e.restore();}drawInheritanceHead(e,t,i){let n=Math.atan2(i.y-t.y,i.x-t.x),s=14,r=i.x,o=i.y,h=i.x-s*Math.cos(n),l=i.y-s*Math.sin(n),c=h+s*.5*Math.cos(n-Math.PI/2),d=l+s*.5*Math.sin(n-Math.PI/2),u=h+s*.5*Math.cos(n+Math.PI/2),g=l+s*.5*Math.sin(n+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle="#ffffff",e.beginPath(),e.moveTo(r,o),e.lineTo(c,d),e.lineTo(u,g),e.closePath(),e.fill(),e.stroke(),e.restore();}drawDiamondHead(e,t,i,n){let s=Math.atan2(i.y-t.y,i.x-t.x),r=14,o=i.x,h=i.y,l=i.x-r*.5*Math.cos(s),c=i.y-r*.5*Math.sin(s),d=i.x-r*Math.cos(s),u=i.y-r*Math.sin(s),g=l+r*.4*Math.cos(s-Math.PI/2),p=c+r*.4*Math.sin(s-Math.PI/2),y=l+r*.4*Math.cos(s+Math.PI/2),f=c+r*.4*Math.sin(s+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle=n?"#1f2937":"#ffffff",e.beginPath(),e.moveTo(o,h),e.lineTo(g,p),e.lineTo(d,u),e.lineTo(y,f),e.closePath(),e.fill(),e.stroke(),e.restore();}drawArrowHeads(e,t,i){if(i!=="none"){if(i==="start"||i==="both"){let n=t[0],s=t[1];this.drawArrowHead(e,s,n);}if(i==="end"||i==="both"){let n=t.length,s=t[n-2],r=t[n-1];this.drawArrowHead(e,s,r);}if(i==="inheritance"){let n=t.length,s=t[n-2],r=t[n-1];this.drawInheritanceHead(e,s,r);}if(i==="aggregation"){let n=t[0],s=t[1];this.drawDiamondHead(e,s,n,false);}if(i==="composition"){let n=t[0],s=t[1];this.drawDiamondHead(e,s,n,true);}if(i==="dependency"){let n=t.length;this.drawArrowHead(e,t[n-2],t[n-1]);}if(i==="realization"){let n=t.length;this.drawInheritanceHead(e,t[n-2],t[n-1]);}}}drawText(e,t){if(!t.text)return;let i=t.fontSize;e.font=`${i}px sans-serif`,e.textAlign="center",e.textBaseline="middle";let n=t.width,s=t.height,r=i*1.3,o=this.getDisplayLines(e,t,t.text,i,n,s),h=o.length*r,l=-h/2+r/2;if(t.highlightColor&&t.highlightColor!=="transparent"){let c=t.highlightOpacity??1;e.fillStyle=c<1?R(t.highlightColor,c):t.highlightColor;let d=i*.15;e.beginPath(),e.roundRect(-n/2-d,-h/2-d,n+d*2,h+d*2,4),e.fill();}e.fillStyle=t.textColor||"#1f2937",o.forEach((c,d)=>{let u=l+d*r;e.fillText(c,0,u);});}drawFreehand(e,t){if(t.points.length<2)return;let i=t.points;e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let n=1;n<i.length-1;n++){let s=(i[n].x+i[n+1].x)/2,r=(i[n].y+i[n+1].y)/2;e.quadraticCurveTo(i[n].x,i[n].y,s,r);}e.lineTo(i[i.length-1].x,i[i.length-1].y),e.stroke();}drawSelectionOutline(e,t,i){let n=this.getShapeBounds(t);e.strokeStyle=I.selection.outline,e.lineWidth=1/i,e.setLineDash([]),e.save(),e.shadowColor=I.selection.shadow,e.shadowBlur=8,e.shadowOffsetX=0,e.shadowOffsetY=0,e.beginPath(),e.roundRect(n.x-2,n.y-2,n.width+4,n.height+4,4),e.stroke(),e.restore(),e.fillStyle=I.selection.outlineFill,e.beginPath(),e.roundRect(n.x-2,n.y-2,n.width+4,n.height+4,4),e.fill();}drawSelectionHandles(e,t,i,n){let s=8/i;if((t.type==="line"||t.type==="arrow")&&t.points&&t.points.length>=2){let o=n?this.getConnectorRoute(t,n):[],h=o.length>=2?o:t.points,l={x:h[0].x-t.x,y:h[0].y-t.y},c={x:h[h.length-1].x-t.x,y:h[h.length-1].y-t.y};e.fillStyle=I.selection.handleFill,e.strokeStyle=I.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),[l,c].forEach(d=>{e.beginPath(),e.arc(d.x,d.y,s/2,0,Math.PI*2),e.fill(),e.stroke();});}else {let o=this.getShapeBounds(t),h=s,l=[{x:o.x,y:o.y},{x:o.x+o.width,y:o.y},{x:o.x+o.width,y:o.y+o.height},{x:o.x,y:o.y+o.height}];e.fillStyle=I.selection.handleFill,e.strokeStyle=I.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),l.forEach(g=>{e.beginPath(),e.roundRect(g.x-h/2,g.y-h/2,h,h,2),e.fill(),e.stroke();}),this.drawConnectionDots(e,o,i,1);let c=26/i,d=o.x+o.width/2,u=o.y-c;e.strokeStyle="#94a3b8",e.lineWidth=1.5/i,e.setLineDash([]),e.beginPath(),e.moveTo(d,o.y),e.lineTo(d,u),e.stroke(),e.beginPath(),e.arc(d,u,8/i,0,Math.PI*2),e.fillStyle=I.selection.handleFill,e.fill(),e.strokeStyle=I.primary,e.lineWidth=1.6/i,e.stroke(),this.drawRotateIcon(e,d,u,i);}}drawConnectionDots(e,t,i,n=1){let s=9/i,r=[{x:t.x+t.width/2,y:t.y},{x:t.x+t.width,y:t.y+t.height/2},{x:t.x+t.width/2,y:t.y+t.height},{x:t.x,y:t.y+t.height/2}];e.save(),e.globalAlpha=n,r.forEach(o=>{e.beginPath(),e.arc(o.x,o.y,s,0,Math.PI*2),e.fillStyle=I.selection.handleFill,e.fill(),e.strokeStyle=I.primary,e.lineWidth=1.5/i,e.stroke(),e.beginPath(),e.arc(o.x,o.y,s*.45,0,Math.PI*2),e.fillStyle=I.primary,e.fill();}),e.restore();}drawRotateIcon(e,t,i,n){let s=8/n;e.save(),e.translate(t,i),e.strokeStyle=I.primary,e.lineWidth=1.8/n,e.lineCap="round",e.beginPath(),e.arc(0,0,s*.5,Math.PI*.18,Math.PI*1.6,false),e.stroke();let r=Math.PI*.18,o=Math.cos(r)*s*.5,h=Math.sin(r)*s*.5,l=1;e.beginPath(),e.moveTo(o,h),e.lineTo(o-Math.cos(r)*s*.26+l*Math.sin(r)*s*.16,h-Math.sin(r)*s*.26-l*Math.cos(r)*s*.16),e.moveTo(o,h),e.lineTo(o-Math.cos(r)*s*.26-l*Math.sin(r)*s*.16,h-Math.sin(r)*s*.26+l*Math.cos(r)*s*.16),e.stroke(),e.restore();}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:-e.width/2,y:-e.height/2,width:e.width,height:e.height};case "circle":return {x:-e.radius,y:-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(e.points.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x-e.x),i=Math.min(i,r.y-e.y),n=Math.max(n,r.x-e.x),s=Math.max(s,r.y-e.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e;if(typeof t.width=="number"&&typeof t.height=="number")return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height};if(t.points.length===0)return {x:0,y:0,width:0,height:0};let i=1/0,n=1/0,s=-1/0,r=-1/0;return t.points.forEach(o=>{let h=o.x-t.x,l=o.y-t.y;i=Math.min(i,h),n=Math.min(n,l),s=Math.max(s,h),r=Math.max(r,l);}),{x:i,y:n,width:s-i,height:r-n}}case "text":{let t=e;return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}}default:return {x:0,y:0,width:0,height:0}}}};var J={create(a=0,e=0){return {x:a,y:e}},add(a,e){return {x:a.x+e.x,y:a.y+e.y}},subtract(a,e){return {x:a.x-e.x,y:a.y-e.y}},multiply(a,e){return {x:a.x*e,y:a.y*e}},divide(a,e){return {x:a.x/e,y:a.y/e}},dot(a,e){return a.x*e.x+a.y*e.y},length(a){return Math.sqrt(a.x*a.x+a.y*a.y)},normalize(a){let e=J.length(a);return e===0?{x:0,y:0}:{x:a.x/e,y:a.y/e}},distance(a,e){return J.length(J.subtract(a,e))},rotate(a,e){let t=Math.cos(e),i=Math.sin(e);return {x:a.x*t-a.y*i,y:a.x*i+a.y*t}},clone(a){return {x:a.x,y:a.y}},equals(a,e){return a.x===e.x&&a.y===e.y}};function W(a,e,t,i=8){let n=[];if(t==="horizontal"){let s=Math.min(a.x,e.x),r=Math.max(a.x+a.width,e.x+e.width),o=Math.abs(a.y-e.y)<=i,h=Math.abs(a.y+a.height-(e.y+e.height))<=i,l=Math.abs(a.y+a.height/2-(e.y+e.height/2))<=i;o&&n.push({type:"horizontal",position:(a.y+e.y)/2,start:s,end:r}),h&&n.push({type:"horizontal",position:(a.y+a.height+e.y+e.height)/2,start:s,end:r}),l&&!(o&&h)&&n.push({type:"horizontal",position:(a.y+a.height/2+e.y+e.height/2)/2,start:s,end:r});}else {let s=Math.min(a.y,e.y),r=Math.max(a.y+a.height,e.y+e.height),o=Math.abs(a.x-e.x)<=i,h=Math.abs(a.x+a.width-(e.x+e.width))<=i,l=Math.abs(a.x+a.width/2-(e.x+e.width/2))<=i;o&&n.push({type:"vertical",position:(a.x+e.x)/2,start:s,end:r}),h&&n.push({type:"vertical",position:(a.x+a.width+e.x+e.width)/2,start:s,end:r}),l&&!(o&&h)&&n.push({type:"vertical",position:(a.x+a.width/2+e.x+e.width/2)/2,start:s,end:r});}return n}var ue=class a extends L{type="select";state="idle";translatingState=null;resizingState=null;generatingState=null;hoverGenPoint=null;hoverShapeId=null;hoverConnectorId=null;draggingSegment=null;rotatingState=null;draggingArrowId=null;draggingTerminal=null;pendingHistoryCommit=false;brushStart={x:0,y:0};brushShiftKey=false;defaultGenType(e){if(e){let t=this.context.getShapes().find(i=>i.id===e);if(t&&Ie(t.type))return t.type}return "rectangle"}genPreviewOf(e,t,i={}){let n=this.context.getArrowStyle();return {from:e.point,to:t,type:i.type,sourceShapeId:e.sourceShapeId,sourceEdge:e.edge,targetShapeId:i.targetShapeId,targetBinding:i.targetBinding,dragging:i.dragging,arrowStyle:{connectionType:"polyline",arrowHead:n.arrowHead,dashed:n.dashed},lineStyle:this.context.getLineStyle()}}genContext(e,t){return {from:e.point,to:t,sourceShapeId:e.sourceShapeId,edge:e.edge}}onPointerDown(e,t){let i=this.context.getShapes(),n=this.context.getSelectedIds(),s=this.hitTestArrowTerminal(e,i);if(s&&n.includes(s.shapeId)){this.state="dragging-terminal",this.draggingArrowId=s.shapeId,this.draggingTerminal=s.terminal,this.pendingHistoryCommit=true,this.context.updateArrowBinding(s.shapeId,s.terminal,null);return}let r=this.hitConnectorSegmentHandle(e,i,n);if(r){this.state="dragging-segment",this.draggingSegment={...r,startPoint:e},this.pendingHistoryCommit=true;return}let o=this.hoverShapeId??this.findHoverAnchorShape(e,i,n),h=this.hitGenPoint(e,i,n,o);if(h){this.state="generating",this.hoverShapeId=o,this.generatingState={source:h,startPoint:e,hasMoved:false,sourceWasSelected:!!h.sourceShapeId&&n.includes(h.sourceShapeId)},this.pendingHistoryCommit=true,this.context.setGenerationPreview(this.genPreviewOf(h,this.genPreviewTarget(h,e,false),{type:this.defaultGenType(h.sourceShapeId)}));return}let l=this.hitTest(e,i,n);if(l.handle==="rotation"){this.state="rotating",this.pendingHistoryCommit=true;let c=l.shape;this.rotatingState={shapeId:c.id,center:{x:c.x,y:c.y},startAngle:Math.atan2(e.y-c.y,e.x-c.x),startRotation:c.rotation};return}if(l.handle&&l.shape&&l.shape.type!=="mind-map"){this.state="resizing",this.resizingState={startPoint:e,startShape:l.shape,handle:l.handle},this.pendingHistoryCommit=true;return}if(l.shape){let c=l.shape,d=c.type==="line"||c.type==="arrow",u=n.includes(c.id);if(d&&!u){this.context.selectShape(c.id,t.shiftKey);return}this.state="translating",this.pendingHistoryCommit=true,u||this.context.selectShape(c.id,t.shiftKey);let g=this.context.getSelectedIds(),p=new Map,y=new Map,f=new Map;g.forEach(S=>{let x=i.find(M=>M.id===S);x&&(p.set(S,{x:x.x,y:x.y}),y.set(S,x.rotation),f.set(S,this.getShapeWorldBounds(x)));}),this.translatingState={startPoint:e,startPositions:p,startRotation:y,startBounds:f};}else this.state="brushing",this.brushStart=e,this.brushShiftKey=t.shiftKey,t.shiftKey||this.context.selectShape("",false);}onPointerMove(e,t){let i=this.context.getShapes();if(this.state==="translating"&&this.translatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleTranslating(e,t);else if(this.state==="generating"&&this.generatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleGenerating(e,i);else if(this.state==="rotating"&&this.rotatingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleRotating(e,t);else if(this.state==="resizing"&&this.resizingState)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleResizing(e);else if(this.state==="dragging-terminal"&&this.draggingArrowId&&this.draggingTerminal){this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false);let n=i.find(s=>s.id===this.draggingArrowId);if(n){let s=this.draggingTerminal==="start"?e:n.points[n.points.length-1],r=this.draggingTerminal==="start"?n.points[0]:e,o=this.computeSnapGuidesForArrow(s,r,e,n,i);this.context.setSnapGuides(o);let h=e;if(o.length>0){let d=o.filter(g=>g.type==="horizontal"),u=o.filter(g=>g.type==="vertical");if(d.length>0){let g=d[0].position,p=Math.abs(e.y-g);for(let y of d){let f=Math.abs(e.y-y.position);f<p&&(p=f,g=y.position);}h={...h,y:g};}else if(u.length>0){let g=u[0].position,p=Math.abs(e.x-g);for(let y of u){let f=Math.abs(e.x-y.position);f<p&&(p=f,g=y.position);}h={...h,x:g};}}let l=this.draggingTerminal==="start"?0:n.points.length-1,c=[...n.points];c[l]=h,this.context.updateShape(this.draggingArrowId,{points:c});}}else if(this.state==="dragging-segment"&&this.draggingSegment)this.pendingHistoryCommit&&(this.context.commitHistory(),this.pendingHistoryCommit=false),this.handleDraggingSegment(e);else if(this.state==="brushing")this.handleBrushing(e);else {let n=this.context.getSelectedIds(),s=this.hitGenPoint(e,i,n,this.hoverShapeId);s?(this.hoverGenPoint=s,this.context.setGenerationPreview(this.genPreviewOf(s,this.genPreviewTarget(s,e,false),{type:this.defaultGenType(s.sourceShapeId)}))):(this.hoverGenPoint=null,this.context.setGenerationPreview(null));let r=this.findHoverAnchorShape(e,i,n);r!==this.hoverShapeId&&(this.hoverShapeId=r,this.context.setHoverAnchorShape(r));let o=this.findHoverConnector(e,i,n);o!==this.hoverConnectorId&&(this.hoverConnectorId=o,this.context.setHoverConnector(o));}}onPointerUp(e,t){if(this.state==="dragging-terminal"&&this.draggingArrowId&&this.draggingTerminal){let i=this.context.getShapes(),n=this.findBindingNearPoint(e,i,this.draggingArrowId);n&&this.context.updateArrowBinding(this.draggingArrowId,this.draggingTerminal,n.toShapeId,n.binding);}if(this.state==="generating"&&this.generatingState){let i=this.generatingState,n=this.context.getShapes(),s=i.source,r=this.findBindingNearPoint(e,n,s.sourceShapeId);if(r)this.context.connectToExisting(this.genContext(s,e),r.toShapeId,r.binding);else if(!i.hasMoved)i.sourceWasSelected?this.context.createGeneratedConnection(this.genContext(s,this.genPreviewTarget(s,s.point,false)),{type:this.defaultGenType(s.sourceShapeId)}):s.sourceShapeId&&this.context.selectShape(s.sourceShapeId,false);else {let o=this.defaultGenType(s.sourceShapeId),h=this.avoidSourceOverlap(s,e,o),l=this.context.createFloatingLine(this.genContext(s,this.futureDockPoint(s,h,o)));this.context.openGenerationMenu({context:this.genContext(s,h),existingArrowId:l,defaultShapeType:o});}this.generatingState=null;}this.state==="brushing"&&this.context.setBrushRect(null),this.context.setGenerationPreview(null),this.context.setConnectingTarget(null),this.hoverGenPoint=null,this.pendingHistoryCommit=false,this.state="idle",this.draggingArrowId=null,this.draggingTerminal=null,this.draggingSegment=null,this.translatingState=null,this.resizingState=null,this.rotatingState=null,this.context.setSnapGuides([]);}isPointOnConnector(e,t,i,n=10){let s=this.context.getConnectorRoute(t),r=s.length>=2?s:i.points;for(let o=1;o<r.length;o++)if(this.pointToLineDistance(e,r[o-1],r[o])<=n)return true;return false}findHoverConnector(e,t,i){for(let n=t.length-1;n>=0;n--){let s=t[n];if(!(s.type!=="arrow"&&s.type!=="line")&&!i.includes(s.id)&&this.isPointOnConnector(e,s.id,s))return s.id}return null}hitConnectorSegmentHandle(e,t,i){for(let n of i){let s=t.find(h=>h.id===n);if(!s||s.type!=="arrow"&&s.type!=="line")continue;let r=this.context.getConnectorRoute(n);if(r.length<2)continue;let o=Ne(r,e);if(o)return {shapeId:n,index:o.index,route:r,axis:o.axis}}return null}segmentCursor(e){return e==="H"?"ns-resize":"ew-resize"}handleDraggingSegment(e){let t=this.draggingSegment;if(!t||Math.hypot(e.x-t.startPoint.x,e.y-t.startPoint.y)<3)return;let i=t.route[t.index],n=t.route[t.index+1],r=Math.abs(n.x-i.x)>=Math.abs(n.y-i.y)?e.y-(i.y+n.y)/2:e.x-(i.x+n.x)/2;this.writeConnectorRoute(t.shapeId,Be(t.route,t.index,r));}writeConnectorRoute(e,t){let i=this.context.getShapes().find(r=>r.id===e);if(!i)return;let n=oe(t);if(i.type==="arrow"&&(!!i.startBinding||!!i.endBinding)){let r=_e(n);this.context.updateShape(e,{userPoints:r.length?r:void 0});}else this.context.updateShape(e,{points:n});}hasTransientState(){return this.state!=="idle"||!!this.generatingState}cancelTransient(){let e=this.state!=="idle"||!!this.generatingState||!!this.hoverGenPoint||!!this.hoverShapeId||!!this.hoverConnectorId||this.pendingHistoryCommit;return this.state="idle",this.generatingState=null,this.translatingState=null,this.resizingState=null,this.rotatingState=null,this.draggingArrowId=null,this.draggingTerminal=null,this.draggingSegment=null,this.pendingHistoryCommit=false,this.hoverGenPoint=null,this.hoverShapeId&&(this.hoverShapeId=null,this.context.setHoverAnchorShape(null)),this.hoverConnectorId&&(this.hoverConnectorId=null,this.context.setHoverConnector(null)),this.context.setGenerationPreview(null),this.context.setConnectingTarget(null),this.context.setSnapGuides([]),e}onKeyDown(e){let t=e.target;if(!(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable))){if(e.key==="Delete"||e.key==="Backspace"){let i=this.context.getSelectedIds();i.length>0&&(this.context.commitHistory(),i.forEach(n=>{this.context.deleteShape(n);}));}e.key==="Escape"&&(this.context.selectShape("",false),this.cancelTransient()),(e.key==="+"||e.key==="=")&&e.shiftKey&&(this.context.commitHistory(),this.handleRotation(15)),e.key==="-"&&e.shiftKey&&(this.context.commitHistory(),this.handleRotation(-15)),e.key==="ArrowUp"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(0,-5)),e.key==="ArrowDown"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(0,5)),e.key==="ArrowLeft"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(-5,0)),e.key==="ArrowRight"&&(e.preventDefault(),this.context.commitHistory(),this.handleNudge(5,0));}}onKeyUp(e){}getCursor(e){switch(this.state){case "translating":return "grabbing";case "generating":return "crosshair";case "rotating":return "grabbing";case "resizing":return this.resizingState?this.getHandleCursor(this.resizingState.handle,this.resizingState.startShape):"default";case "dragging-terminal":return "crosshair";case "dragging-segment":return this.segmentCursor(this.draggingSegment?.axis??"H");case "brushing":return "crosshair"}let t=this.context.getShapes(),i=this.context.getSelectedIds(),n=this.hitConnectorSegmentHandle(e,t,i);if(n)return this.segmentCursor(n.axis);if(this.hoverConnectorId||this.context.getMindMapCursorHitAtPoint(e))return "pointer";if(this.hitGenPoint(e,t,i,this.hoverShapeId))return "crosshair";if(this.hitTestArrowTerminal(e,t)&&i.includes(this.hitTestArrowTerminal(e,t).shapeId))return "move";let s=this.hitTest(e,t,i);return s.handle==="rotation"?"grab":s.handle?this.getHandleCursor(s.handle,s.shape):s.shape?"move":null}getHandleCursor(e,t){let n={e:0,se:45,s:90,sw:135,w:180,nw:225,n:270,ne:315}[e];if(n===void 0)return "grab";let s=((n+t.rotation*180/Math.PI)%360+360)%360,r=Math.round(s/45)%4;return ["ew-resize","nwse-resize","ns-resize","nesw-resize"][r]}static ALIGN_SNAP_THRESHOLD=8;handleTranslating(e,t){if(!this.translatingState)return;let i=J.subtract(e,this.translatingState.startPoint),n={...i};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?n.y=0:n.x=0);let s=this.context.getShapes(),r=this.context.getSelectedIds(),o=new Set(r),h=[],l=[];if(this.translatingState.startBounds.forEach(c=>{l.push({x:c.x+n.x,y:c.y+n.y,width:c.width,height:c.height});}),!t.shiftKey&&l.length>0){let c=[];for(let g of s)o.has(g.id)||g.type==="line"||g.type==="arrow"||g.type==="draw"||c.push(this.getShapeWorldBounds(g));let d=[],u=[];for(let g of l){let p=[g.y,g.y+g.height/2,g.y+g.height],y=[g.x,g.x+g.width/2,g.x+g.width];for(let f of c){let S=[f.y,f.y+f.height/2,f.y+f.height];for(let M of p)for(let v of S){let w=v-M;Math.abs(w)<=a.ALIGN_SNAP_THRESHOLD&&d.push(w);}let x=[f.x,f.x+f.width/2,f.x+f.width];for(let M of y)for(let v of x){let w=v-M;Math.abs(w)<=a.ALIGN_SNAP_THRESHOLD&&u.push(w);}}}if(d.length>0){let g=d[0];for(let p of d)Math.abs(p)<Math.abs(g)&&(g=p);n.y+=g;}if(u.length>0){let g=u[0];for(let p of u)Math.abs(p)<Math.abs(g)&&(g=p);n.x+=g;}this.translatingState.startBounds.forEach(g=>{let p={x:g.x+n.x,y:g.y+n.y,width:g.width,height:g.height};for(let y of c)h.push(...W(p,y,"horizontal",1)),h.push(...W(p,y,"vertical",1));});}this.translatingState.startPositions.forEach((c,d)=>{this.context.updateShape(d,{x:c.x+n.x,y:c.y+n.y});}),this.context.setSnapGuides(this.mergeGuides(h));}handleResizing(e){if(!this.resizingState)return;let t=this.resizingState.startShape,i=this.resizingState.handle,n=this.resizingState.startPoint;if(!i||i==="rotation")return;let r={nw:[-1,-1],n:[0,-1],ne:[1,-1],w:[-1,0],e:[1,0],sw:[-1,1],s:[0,1],se:[1,1]}[i];if(!r)return;let[o,h]=r,l=J.subtract(e,n),c=[];for(let w of this.context.getShapes())w.id!==t.id&&(w.type==="line"||w.type==="arrow"||w.type==="draw"||c.push(this.getShapeWorldBounds(w)));let d=20,u=this.getShapeWorldBounds(t),g=u.x,p=u.y,y=u.x+u.width,f=u.y+u.height;o===1?y=Math.max(g+d,y+l.x):o===-1&&(g=Math.min(y-d,g+l.x)),h===1?f=Math.max(p+d,f+l.y):h===-1&&(p=Math.min(f-d,p+l.y));let S=(w,b)=>{let C=null;for(let E of b){let N=E-w;Math.abs(N)<=a.ALIGN_SNAP_THRESHOLD&&(C===null||Math.abs(N)<Math.abs(C))&&(C=N);}return C};if(o!==0&&c.length>0){let w=[];for(let C of c)w.push(C.x,C.x+C.width/2,C.x+C.width);let b=S(o===1?y:g,w);b!==null&&(o===1?y+=b:g+=b);}if(h!==0&&c.length>0){let w=[];for(let C of c)w.push(C.y,C.y+C.height/2,C.y+C.height);let b=S(h===1?f:p,w);b!==null&&(h===1?f+=b:p+=b);}let x={x:g,y:p,width:y-g,height:f-p},M=[];for(let w of c)o!==0&&M.push(...W(x,w,"vertical",1)),h!==0&&M.push(...W(x,w,"horizontal",1));this.context.setSnapGuides(this.mergeGuides(M));let v={};if(t.type==="circle"){let w=Math.max(10,Math.max(o!==0?x.width/2:0,h!==0?x.height/2:0));if(v.radius=w,o!==0){let b=o===1?u.x:u.x+u.width;v.x=o===1?b+w:b-w;}if(h!==0){let b=h===1?u.y:u.y+u.height;v.y=h===1?b+w:b-w;}}else if("width"in t&&o!==0&&(v.width=x.width,v.x=x.x+x.width/2),"height"in t&&h!==0&&(v.height=x.height,v.y=x.y+x.height/2),t.type==="draw"){let w=this.getShapeWorldBounds(t),b=o!==0?x.width/Math.max(1,w.width):1,C=h!==0?x.height/Math.max(1,w.height):1;v.points=t.points.map(E=>({x:E.x*b,y:E.y*C}));}Object.keys(v).length>0&&this.context.updateShape(t.id,v);}mergeGuides(e){let t=new Map;for(let i of e){let n=`${i.type}\0${Math.round(i.position*2)/2}`,s=t.get(n);s?(s.start=Math.min(s.start,i.start),s.end=Math.max(s.end,i.end)):t.set(n,{...i});}return [...t.values()]}handleRotation(e){let t=this.context.getSelectedIds(),i=this.context.getShapes();t.forEach(n=>{let s=i.find(r=>r.id===n);s&&this.context.updateShape(n,{rotation:s.rotation+e*Math.PI/180});});}handleNudge(e,t){let i=this.context.getSelectedIds(),n=this.context.getShapes();i.forEach(s=>{let r=n.find(o=>o.id===s);r&&this.context.updateShape(s,{x:r.x+e,y:r.y+t});});}handleBrushing(e){let t=Math.min(this.brushStart.x,e.x),i=Math.min(this.brushStart.y,e.y),n=Math.abs(e.x-this.brushStart.x),s=Math.abs(e.y-this.brushStart.y);this.context.setBrushRect({x:t,y:i,width:n,height:s});let r=this.context.getShapes(),o=[];for(let h of r){let l=this.getShapeWorldBounds(h);this.rectsIntersect({x:t,y:i,width:n,height:s},l)&&o.push(h.id);}if(this.brushShiftKey){let h=this.context.getSelectedIds(),l=new Set([...h,...o]);this.context.selectShapes([...l]);}else this.context.selectShapes(o);}getShapeWorldBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(!e.points||e.points.length===0)return {x:e.x,y:e.y,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x),i=Math.min(i,r.y),n=Math.max(n,r.x),s=Math.max(s,r.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e,i=t.width,n=t.height;if(typeof i=="number"&&typeof n=="number"&&i>0&&n>0)return {x:t.x-i/2,y:t.y-n/2,width:i,height:n};if(!t.points||t.points.length===0)return {x:t.x,y:t.y,width:0,height:0};let s=1/0,r=1/0,o=-1/0,h=-1/0;return t.points.forEach(l=>{let c=l.x+t.x,d=l.y+t.y;s=Math.min(s,c),r=Math.min(r,d),o=Math.max(o,c),h=Math.max(h,d);}),{x:s,y:r,width:o-s,height:h-r}}case "text":{let t=e;return {x:e.x-t.width/2,y:e.y-t.height/2,width:t.width,height:t.height}}default:{let t=e;return {x:t.x,y:t.y,width:0,height:0}}}}rectsIntersect(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}hitTest(e,t,i){for(let n=t.length-1;n>=0;n--){let s=t[n];if(i.includes(s.id)){let r=this.getHitHandle(e,s);if(r)return {shape:s,handle:r}}if(this.isPointInShape(e,s))return {shape:s,handle:null}}return {shape:null,handle:null}}getHitHandle(e,t){if(t.type==="mind-map")return null;let i=14,n=this.getShapeBounds(t),s=Math.cos(-t.rotation),r=Math.sin(-t.rotation),o=e.x-t.x,h=e.y-t.y,l=o*s-h*r,c=o*r+h*s,d=[{type:"nw",x:n.x,y:n.y},{type:"ne",x:n.x+n.width,y:n.y},{type:"se",x:n.x+n.width,y:n.y+n.height},{type:"sw",x:n.x,y:n.y+n.height},{type:"rotation",x:n.x+n.width/2,y:n.y-26}];for(let u of d)if(Math.abs(l-u.x)<i&&Math.abs(c-u.y)<i)return u.type;return null}static GEN_HIT_THRESHOLD=14;static CLICK_MOVE_THRESHOLD=6;static GEN_SUPPORTED_TYPES=new Set(["rectangle","rounded-rectangle","ellipse","diamond","triangle","hexagon","parallelogram","trapezoid","pentagon","octagon","star","uml-class","uml-interface","circle","draw","cylinder","cloud","heart","block-arrow-right","block-arrow-left","block-arrow-up","block-arrow-down","block-arrow-double","right-triangle","cross","speech-rect","speech-round","cube","sector","delay","predefined-process","document","stadium","class-catalog","chevron","brace-left","brace-right"]);computeGenPoints(e,t,i){let n=[],s=new Set(t);i&&s.add(i);for(let r of s){let o=e.find(h=>h.id===r);if(o&&a.GEN_SUPPORTED_TYPES.has(o.type)){let h=this.getShapeBounds(o),l={x:o.x,y:o.y};n.push({point:{x:l.x+h.x+h.width/2,y:l.y+h.y},edge:"n",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x+h.width,y:l.y+h.y+h.height/2},edge:"e",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x+h.width/2,y:l.y+h.y+h.height},edge:"s",sourceShapeId:o.id}),n.push({point:{x:l.x+h.x,y:l.y+h.y+h.height/2},edge:"w",sourceShapeId:o.id});}}return n}hitGenPoint(e,t,i,n){let s=a.GEN_HIT_THRESHOLD,r=null,o=s;for(let h of this.computeGenPoints(t,i,n)){let l=Math.hypot(h.point.x-e.x,h.point.y-e.y);l<=o&&(o=l,r=h);}return r}findHoverAnchorShape(e,t,i){for(let s=t.length-1;s>=0;s--){let r=t[s];if(i.includes(r.id)||!a.GEN_SUPPORTED_TYPES.has(r.type))continue;let o=this.getShapeWorldBounds(r);if(!(e.x<o.x-12||e.x>o.x+o.width+12||e.y<o.y-12||e.y>o.y+o.height+12))return r.id}return null}genPreviewTarget(e,t,i){if(i)return t;let n=96;if(e.edge)switch(e.edge){case "n":return {x:e.point.x,y:e.point.y-n};case "s":return {x:e.point.x,y:e.point.y+n};case "e":return {x:e.point.x+n,y:e.point.y};case "w":return {x:e.point.x-n,y:e.point.y}}return {x:e.point.x,y:e.point.y-n}}handleGenerating(e,t){if(!this.generatingState)return;let i=this.generatingState,n=i.source;Math.hypot(e.x-i.startPoint.x,e.y-i.startPoint.y)>a.CLICK_MOVE_THRESHOLD&&(i.hasMoved=true);let r=this.findBindingNearPoint(e,t,n.sourceShapeId),o=this.defaultGenType(n.sourceShapeId),h=this.avoidSourceOverlap(n,e,o),l=r?this.bindingPosition(r.toShapeId,r.binding,t):i.hasMoved?h:this.genPreviewTarget(n,e,false);this.context.setConnectingTarget(r?r.toShapeId:null),this.context.setGenerationPreview(this.genPreviewOf(n,l,{dragging:i.hasMoved,targetShapeId:r?.toShapeId,targetBinding:r?.binding,type:r?void 0:o}));}handleRotating(e,t){if(!this.rotatingState)return;let i=this.rotatingState,n=Math.atan2(e.y-i.center.y,e.x-i.center.x),s=i.startRotation+(n-i.startAngle);t.shiftKey&&(s=Math.round(s/(Math.PI/12))*(Math.PI/12)),this.context.updateShape(i.shapeId,{rotation:s});}bindingPosition(e,t,i){let n=i.find(r=>r.id===e);if(!n)return {x:0,y:0};let s=this.getShapeWorldBounds(n);if(t.handle)switch(t.handle){case "top":return {x:n.x,y:s.y};case "bottom":return {x:n.x,y:s.y+s.height};case "left":return {x:s.x,y:n.y};case "right":return {x:s.x+s.width,y:n.y}}return t.normalizedAnchor?{x:s.x+s.width*t.normalizedAnchor.x,y:s.y+s.height*t.normalizedAnchor.y}:{x:n.x,y:n.y}}isPointInShape(e,t){let i=e.x-t.x,n=e.y-t.y;switch(t.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "circle":return i*i+n*n<=t.radius*t.radius;case "hexagon":return this.isPointInHexagon(i,n,t.width,t.height);case "line":case "arrow":return this.isPointOnConnector(e,t.id,t);case "draw":{let s=this.getShapeBounds(t);return Math.abs(i)<=s.width/2&&Math.abs(n)<=s.height/2}case "text":return Math.abs(i)<=50&&Math.abs(n)<=t.fontSize/2;default:return false}}isPointInHexagon(e,t,i,n){let s=Math.abs(e),r=Math.abs(t),o=i/2,h=n/2;return s<=o&&r<=h&&s/o+r/h<=1.5}pointToLineDistance(e,t,i){return we(e,t,i)}avoidSourceOverlap(e,t,i){if(!e.sourceShapeId)return t;let n=this.context.getShapes().find(p=>p.id===e.sourceShapeId);if(!n)return t;let s=Y(i,t),r=this.getShapeWorldBounds(s),o=this.getShapeWorldBounds(n),h=Math.min(r.x+r.width,o.x+o.width)-Math.max(r.x,o.x),l=Math.min(r.y+r.height,o.y+o.height)-Math.max(r.y,o.y);if(h<=0||l<=0)return t;let c=24,d={...t},u=t.x-n.x,g=t.y-n.y;return Math.abs(u)>=Math.abs(g)?d.x=u>=0?o.x+o.width+c+r.width/2:o.x-c-r.width/2:d.y=g>=0?o.y+o.height+c+r.height/2:o.y-c-r.height/2,d}futureDockPoint(e,t,i){let n=Y(i,t),s=this.getShapeBounds(n),r=De(e.point,t,e.edge);return ft(t,{width:s.width,height:s.height},r)}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":return {x:-e.width/2,y:-e.height/2,width:e.width,height:e.height};case "circle":return {x:-e.radius,y:-e.radius,width:e.radius*2,height:e.radius*2};case "line":case "arrow":{if(e.points.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;return e.points.forEach(r=>{t=Math.min(t,r.x-e.x),i=Math.min(i,r.y-e.y),n=Math.max(n,r.x-e.x),s=Math.max(s,r.y-e.y);}),{x:t,y:i,width:n-t,height:s-i}}case "draw":{let t=e;if(typeof t.width=="number"&&typeof t.height=="number")return {x:-t.width/2,y:-t.height/2,width:t.width,height:t.height};if(t.points.length===0)return {x:0,y:0,width:0,height:0};let i=1/0,n=1/0,s=-1/0,r=-1/0;return t.points.forEach(o=>{let h=o.x-t.x,l=o.y-t.y;i=Math.min(i,h),n=Math.min(n,l),s=Math.max(s,h),r=Math.max(r,l);}),{x:i,y:n,width:s-i,height:r-n}}case "text":return {x:-50,y:-e.fontSize/2,width:100,height:e.fontSize};default:return {x:0,y:0,width:0,height:0}}}hitTestArrowTerminal(e,t){for(let n of t){if(n.type!=="arrow")continue;let s=n;if(s.points.length<2)continue;let r=this.context.getConnectorRoute(s.id),o=r.length>=2?r[0]:s.points[0],h=r.length>=2?r[r.length-1]:s.points[s.points.length-1],l=Math.sqrt(Math.pow(e.x-o.x,2)+Math.pow(e.y-o.y,2)),c=Math.sqrt(Math.pow(e.x-h.x,2)+Math.pow(e.y-h.y,2));if(l<20)return {shapeId:s.id,terminal:"start"};if(c<20)return {shapeId:s.id,terminal:"end"}}return null}findShapeNearPoint(e,t,i){for(let s=t.length-1;s>=0;s--){let r=t[s];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let o;switch(r.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":o=this.pointToRectDistance(e,{x:r.x-r.width/2,y:r.y-r.height/2,width:r.width,height:r.height});break;case "circle":o=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2))-r.radius;break;case "hexagon":{let h=r.width/2,l=r.height/2,c=Math.abs(e.x-r.x),d=Math.abs(e.y-r.y);o=c/h+d/l-1;break}default:continue}if(o<=30)return r}return null}pointToRectDistance(e,t){let i=Math.max(t.x,Math.min(e.x,t.x+t.width)),n=Math.max(t.y,Math.min(e.y,t.y+t.height));return Math.sqrt(Math.pow(e.x-i,2)+Math.pow(e.y-n,2))}static SNAP_THRESHOLD=32;static HANDLE_SNAP_DISTANCE=18;static ANCHOR_EPS=.001;computeSnapGuidesForArrow(e,t,i,n,s){let r=this.draggingTerminal==="start"?n.endBinding:n.startBinding,o=r?s.find(p=>p.id===r.toShapeId):null;if(!o)return [];let h=this.findShapeNearPoint(i,s,n.id);if(!h)return [];let l=this.getShapeWorldBounds(o),c=this.getShapeWorldBounds(h),d=t.x-e.x,u=t.y-e.y,g=Math.abs(d)>=Math.abs(u)?"horizontal":"vertical";return W(l,c,g)}findBindingNearPoint(e,t,i){let n;for(let s=t.length-1;s>=0;s--){let r=t[s];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let o=this.getPageBounds(r),h=a.SNAP_THRESHOLD;if(e.x<o.x-h||e.x>o.x+o.width+h||e.y<o.y-h||e.y>o.y+o.height+h)continue;let l={x:r.x,y:r.y},c=[{handle:"top",pos:{x:l.x,y:o.y}},{handle:"bottom",pos:{x:l.x,y:o.y+o.height}},{handle:"left",pos:{x:o.x,y:l.y}},{handle:"right",pos:{x:o.x+o.width,y:l.y}}];for(let g of c){let p=Math.hypot(g.pos.x-e.x,g.pos.y-e.y);p<=a.HANDLE_SNAP_DISTANCE&&(!n||p<n.distance)&&(n={toShapeId:r.id,binding:{toShapeId:r.id,handle:g.handle,isPrecise:false},distance:p});}let d=this.nearestPointOnShapeOutline(r,e);if(d&&d.distance<=a.SNAP_THRESHOLD&&(!n||d.distance<n.distance)){let g=this.computeNormalizedAnchor(o,d.point);n={toShapeId:r.id,binding:{toShapeId:r.id,isPrecise:true,normalizedAnchor:g},distance:d.distance};}e.x>o.x&&e.x<o.x+o.width&&e.y>o.y&&e.y<o.y+o.height&&(!n||n.distance>0)&&(n={toShapeId:r.id,binding:{toShapeId:r.id,auto:true},distance:0});}if(n)return {toShapeId:n.toShapeId,binding:n.binding}}getPageBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};default:return {x:e.x-50,y:e.y-50,width:100,height:100}}}computeNormalizedAnchor(e,t){let i=a.ANCHOR_EPS,n=e.width>0?(t.x-e.x)/e.width:.5,s=e.height>0?(t.y-e.y)/e.height:.5;return n=Math.max(i,Math.min(1-i,n)),s=Math.max(i,Math.min(1-i,s)),{x:n,y:s}}nearestPointOnShapeOutline(e,t){let i={x:t.x-e.x,y:t.y-e.y},n=this.nearestLocalPointOnShapeOutline(e,i);if(!n)return null;let s={x:n.point.x+e.x,y:n.point.y+e.y};return {point:s,distance:Math.hypot(s.x-t.x,s.y-t.y)}}nearestLocalPointOnShapeOutline(e,t){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":{let i=e.width,n=e.height;return this.nearestPointOnRectOutlineLocal(t,{x:-i/2,y:-n/2,width:i,height:n})}case "circle":{let i=e.radius;return this.nearestPointOnCircleOutlineLocal(t,{x:0,y:0},i)}default:return null}}nearestPointOnRectOutlineLocal(e,t){let i=[[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y}],[{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height}],[{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],[{x:t.x,y:t.y+t.height},{x:t.x,y:t.y}]],n=null;for(let[s,r]of i){let o=this.nearestPointOnSegment(e,s,r);(!n||o.distance<n.distance)&&(n=o);}return n}nearestPointOnCircleOutlineLocal(e,t,i){let n=e.x-t.x,s=e.y-t.y,r=Math.hypot(n,s);if(r<1e-9)return {point:{x:t.x+i,y:t.y},distance:i};let o=t.x+n/r*i,h=t.y+s/r*i,l={x:o,y:h};return {point:l,distance:Math.hypot(l.x-e.x,l.y-e.y)}}nearestPointOnSegment(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=n*n+s*s,o=r>0?((e.x-t.x)*n+(e.y-t.y)*s)/r:0;o=Math.max(0,Math.min(1,o));let h=t.x+o*n,l=t.y+o*s,c={x:h,y:l};return {point:c,distance:Math.hypot(c.x-e.x,c.y-e.y)}}};var ge=class a extends L{type="hand";state="idle";startScreenPoint={x:0,y:0};initialCameraPos={x:0,y:0};static DRAG_THRESHOLD=4;onPointerDown(e,t){this.startScreenPoint={x:t.clientX,y:t.clientY};let i=this.context.getCamera();this.initialCameraPos={x:i.x,y:i.y},this.state="pointing";}onPointerMove(e,t){if(this.state!=="idle"){if(this.state==="pointing"){let i=t.clientX-this.startScreenPoint.x,n=t.clientY-this.startScreenPoint.y;if(Math.hypot(i,n)<a.DRAG_THRESHOLD)return;this.state="dragging",this.applyCameraDelta(i,n);return}if(this.state==="dragging"){let i=t.clientX-this.startScreenPoint.x,n=t.clientY-this.startScreenPoint.y;this.applyCameraDelta(i,n);}}}onPointerUp(e,t){if(this.state!=="idle"){if(this.state==="dragging"){let i=this.context.getCamera();this.initialCameraPos={x:i.x,y:i.y},this.startScreenPoint={x:t.clientX,y:t.clientY};}this.state="idle";}}onKeyDown(e){e.key==="Escape"&&this.state!=="idle"&&(this.context.setCameraPosition(this.initialCameraPos.x,this.initialCameraPos.y),this.state="idle");}onKeyUp(e){}getCursor(e){return this.state==="dragging"||this.state==="pointing"?"grabbing":"grab"}applyCameraDelta(e,t){this.context.setCameraPosition(this.initialCameraPos.x+e,this.initialCameraPos.y+t);}};var an={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},pe=class extends L{type="line";isDrawing=false;startPoint={x:0,y:0};currentShape=null;onPointerDown(e,t){this.isDrawing=true,this.startPoint=e,this.currentShape={id:`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,type:"line",x:e.x,y:e.y,points:[e],rotation:0,style:{...an}},this.context.commitHistory(),this.context.addShape(this.currentShape);}onPointerMove(e,t){!this.isDrawing||!this.currentShape||this.context.updateShape(this.currentShape.id,{points:[this.startPoint,e]});}onPointerUp(e,t){this.isDrawing=false,this.currentShape=null,this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}};var hn={strokeColor:"#1f2937",fillColor:"transparent",fillOpacity:1,strokeWidth:4,strokeDash:null},ln=.5,cn=16,Ve="#ffeb3b",dn=4200,X=class extends L{type;mode;isDrawing=false;points=[];currentShapeId=null;committed=false;fadeTimer=null;highlighterColor=Ve;constructor(e,t){super(e),this.mode=t,this.type=t==="pen"?"pen":"highlighter";}setHighlighterColor(e){this.highlighterColor=e;}getHighlighterColor(){return this.highlighterColor}buildStyle(){return this.mode==="pen"?{...hn}:{strokeColor:R(this.highlighterColor,ln),fillColor:"transparent",fillOpacity:1,strokeWidth:cn,strokeDash:null}}onPointerDown(e,t){this.isDrawing=true,this.committed=false,this.currentShapeId=null,this.points=[{...e}];}buildGeometry(e){let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let u of e)u.x<t&&(t=u.x),u.y<i&&(i=u.y),u.x>n&&(n=u.x),u.y>s&&(s=u.y);let r=(t+n)/2,o=(i+s)/2,h=6,l=Math.max(1,n-t)+h*2,c=Math.max(1,s-i)+h*2,d=e.map(u=>({x:u.x-r,y:u.y-o}));return {x:r,y:o,width:l,height:c,points:d}}onPointerMove(e,t){if(this.isDrawing){if(this.points.push({...e}),!this.committed&&this.points.length>=2){this.context.commitHistory();let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;this.currentShapeId=i;let n=this.buildGeometry(this.points),s=this.buildStyle(),r={id:i,type:"draw",x:n.x,y:n.y,width:n.width,height:n.height,points:n.points,rotation:0,style:s};this.context.addShape(r),this.committed=true;}else if(this.committed&&this.currentShapeId){let i=this.buildGeometry(this.points);this.context.updateShape(this.currentShapeId,{x:i.x,y:i.y,width:i.width,height:i.height,points:i.points});}}}onPointerUp(e,t){if(!this.isDrawing||(this.isDrawing=false,!this.committed||!this.currentShapeId))return;let i=this.currentShapeId;this.currentShapeId=null,this.mode==="highlighter"&&(this.fadeTimer=setTimeout(()=>{this.context.deleteShape(i);},dn));}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}dispose(){this.fadeTimer&&(clearTimeout(this.fadeTimer),this.fadeTimer=null);}};var un={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},gn=4,ye=class extends L{type="arrow";isDrawing=false;startPoint={x:0,y:0};currentShapeId=null;startBindingInfo=null;startBinding;onPointerDown(e,t){this.isDrawing=true,this.startPoint=e,this.startBindingInfo=null,this.currentShapeId=null;let i=this.context.getShapes(),n=this.findShapeBinding(e,i),s=e;n&&(s=this.getBindingPosition(n.toShapeId,n.handle,i),this.startBindingInfo={...n,position:s}),this.startPoint=s,this.startBinding=n?{toShapeId:n.toShapeId,handle:n.handle}:void 0;}onPointerMove(e,t){if(!this.isDrawing)return;let i=this.context.getShapes(),n=this.findShapeBinding(e,i),s=e;n&&(s=this.getBindingPosition(n.toShapeId,n.handle,i));let r=this.startPoint;if(!this.currentShapeId){if(Math.hypot(s.x-r.x,s.y-r.y)<gn)return;let l=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,c=this.context.getArrowStyle(),d={id:l,type:"arrow",x:r.x,y:r.y,points:[r,s],rotation:0,style:{...un},startBinding:this.startBinding,connectionType:c.connectionType,arrowHead:c.arrowHead,dashed:c.dashed};this.context.commitHistory(),this.context.addShape(d),this.currentShapeId=l;}let o=this.computeSnapGuides(r,s,n,i);this.context.setSnapGuides(o),this.context.updateShape(this.currentShapeId,{points:[r,s],endBinding:n?{toShapeId:n.toShapeId,handle:n.handle,auto:true}:void 0});}onPointerUp(e,t){let i=!!this.currentShapeId;this.isDrawing=false,this.currentShapeId=null,this.startBindingInfo=null,this.startBinding=void 0,this.context.setSnapGuides([]),i&&this.context.setActiveTool("select");}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}computeSnapGuides(e,t,i,n){let s=this.startBindingInfo?n.find(u=>u.id===this.startBindingInfo.toShapeId):null,r=i?n.find(u=>u.id===i.toShapeId):null;if(!s||!r)return [];let o=this.getShapeBounds(s),h=this.getShapeBounds(r),l=t.x-e.x,c=t.y-e.y,d=Math.abs(l)>=Math.abs(c)?"horizontal":"vertical";return W(o,h,d)}getShapeBounds(e){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};case "circle":return {x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2};case "text":return {x:e.x-e.width/2,y:e.y-e.height/2,width:e.width,height:e.height};default:return {x:e.x-50,y:e.y-20,width:100,height:40}}}findShapeBinding(e,t){for(let n=t.length-1;n>=0;n--){let s=t[n];if(s.type==="arrow"||s.type==="line"||s.type==="draw")continue;let r;switch(s.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "uml-class":case "uml-interface":r=this.pointToRectDistance(e,{x:s.x-s.width/2,y:s.y-s.height/2,width:s.width,height:s.height});break;case "circle":{let o=Math.sqrt(Math.pow(e.x-s.x,2)+Math.pow(e.y-s.y,2));r=Math.abs(o-s.radius);break}case "hexagon":{let o=s.width/2,h=s.height/2,l=Math.abs(e.x-s.x),c=Math.abs(e.y-s.y);r=l/o+c/h-1;break}default:continue}if(r<=40){let o=this.getClosestHandle(e,s);return {toShapeId:s.id,handle:o}}}}pointToRectDistance(e,t){let i=Math.max(t.x,Math.min(e.x,t.x+t.width)),n=Math.max(t.y,Math.min(e.y,t.y+t.height));return Math.sqrt(Math.pow(e.x-i,2)+Math.pow(e.y-n,2))}getClosestHandle(e,t){let i=e.x-t.x,n=e.y-t.y;if(t.type==="circle"||t.type==="hexagon"){let l=Math.atan2(n,i);return l>=-Math.PI/4&&l<Math.PI/4?"right":l>=Math.PI/4&&l<3*Math.PI/4?"bottom":l>=3*Math.PI/4||l<-(3*Math.PI)/4?"left":"top"}let s="width"in t?t.width:100,r="height"in t?t.height:100,o=Math.abs(i)/(s/2),h=Math.abs(n)/(r/2);return o>h?i>0?"right":"left":n>0?"bottom":"top"}getBindingPosition(e,t,i){let n=i.find(s=>s.id===e);if(!n)return {x:0,y:0};switch(n.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":return this.getRectBindingPosition(n,t);case "circle":return this.getCircleBindingPosition(n,t);case "hexagon":return this.getRectBindingPosition(n,t);default:return {x:n.x,y:n.y}}}getRectBindingPosition(e,t){switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}}getCircleBindingPosition(e,t){switch(t){case "top":return {x:e.x,y:e.y-e.radius};case "bottom":return {x:e.x,y:e.y+e.radius};case "left":return {x:e.x-e.radius,y:e.y};case "right":return {x:e.x+e.radius,y:e.y}}}};var pn={strokeColor:"transparent",fillColor:"transparent",strokeWidth:0,strokeDash:null},Re=class extends L{type="text";onPointerDown(e,t){let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n={id:i,type:"text",x:e.x,y:e.y,rotation:0,style:{...pn},text:"",fontSize:16,textColor:"#1f2937",width:200,height:24};this.context.commitHistory(),this.context.addShape(n),this.context.enterEditing(i);}onPointerMove(e,t){}onPointerUp(e,t){}onKeyDown(e){}onKeyUp(e){}getCursor(){return "text"}};var ie="#1f2937";function qe(a){switch(a.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":case "mind-map":case "text":return {x:-(a.width/2),y:-(a.height/2),width:a.width,height:a.height};case "circle":return {x:-a.radius,y:-a.radius,width:a.radius*2,height:a.radius*2};case "line":case "arrow":{let e=a.points;if(!e||e.length===0)return {x:0,y:0,width:0,height:0};let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let r of e){let o=r.x-a.x,h=r.y-a.y;t=Math.min(t,o),i=Math.min(i,h),n=Math.max(n,o),s=Math.max(s,h);}return {x:t,y:i,width:n-t,height:s-i}}case "draw":{let e=a,t=e.width,i=e.height;if(typeof t=="number"&&typeof i=="number")return {x:-t/2,y:-i/2,width:t,height:i};let n=e.points;if(!n||n.length===0)return {x:0,y:0,width:0,height:0};let s=1/0,r=1/0,o=-1/0,h=-1/0;for(let l of n)s=Math.min(s,l.x),r=Math.min(r,l.y),o=Math.max(o,l.x),h=Math.max(h,l.y);return {x:s,y:r,width:o-s,height:h-r}}default:return {x:0,y:0,width:0,height:0}}}function yn(a){let e=qe(a),t=Math.cos(a.rotation),i=Math.sin(a.rotation),n=1/0,s=1/0,r=-1/0,o=-1/0,h=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]];for(let[l,c]of h){let d=l*t-c*i+a.x,u=l*i+c*t+a.y;n=Math.min(n,d),s=Math.min(s,u),r=Math.max(r,d),o=Math.max(o,u);}return {x:n,y:s,width:r-n,height:o-s}}function xe(a,e=24){if(!a||a.length===0)return {x:0,y:0,width:400,height:300};let t=1/0,i=1/0,n=-1/0,s=-1/0;for(let r of a){let o=yn(r);t=Math.min(t,o.x),i=Math.min(i,o.y),n=Math.max(n,o.x+o.width),s=Math.max(s,o.y+o.height);}return {x:t-e,y:i-e,width:n-t+e*2,height:s-i+e*2}}function Ct(a,e={}){let t=e.padding??24,i=e.scale??2,n=e.background===void 0?"#ffffff":e.background??null,s=xe(a,t),r=Math.max(1,Math.ceil(s.width)),o=Math.max(1,Math.ceil(s.height)),h=document.createElement("canvas");h.width=Math.ceil(r*i),h.height=Math.ceil(o*i);let l=new q(h,i);l.resize(r*i,o*i);let c=new Z;return c.zoom=1,c.x=-s.x,c.y=-s.y,l.render(a,c,new Set,void 0,void 0,void 0,void 0,void 0,void 0,void 0,n),h}function fn(a,e,t){return new Promise((i,n)=>{a.toBlob(s=>{s?i(s):n(new Error("canvas.toBlob failed"));},e,t);})}function mn(a,e,t){return a.toDataURL(e,t)}var fe=null;function F(a,e){return fe||(fe=document.createElement("canvas").getContext("2d")),fe?(fe.font=e,fe.measureText(a).width):a.length*8}function se(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Je(a,e,t,i){let n=e*1.3,s=Math.max(1,Math.floor(i/n)),r=`${e}px sans-serif`,o=a.split(`
3
+ `),h=[];for(let c of o){let d="";for(let u of c){let g=d+u;F(g,r)>t&&d?(h.push(d),d=u):d=g;}d&&h.push(d);}let l=h.slice(0,s);if(h.length>s&&l.length>0){let c=l[l.length-1],d="...";for(;c.length>0&&F(c+d,r)>t;)c=c.slice(0,-1);l[l.length-1]=c+d;}return l}function Qe(a,e,t){if(F(a,t)<=e)return a;let i="\u2026",n=0,s=a.length;for(;n<s;){let r=n+s+1>>1;F(a.slice(0,r)+i,t)<=e?n=r:s=r-1;}return a.slice(0,n)+i}function K(a){return a.map(([e,t])=>`${m(e)},${m(t)}`).join(" ")}function wt(a){return a.map(e=>e[0]==="Z"?"Z":e[0]==="M"||e[0]==="L"?`${e[0]} ${m(e[1])} ${m(e[2])}`:`C ${m(e[1])} ${m(e[2])} ${m(e[3])} ${m(e[4])} ${m(e[5])} ${m(e[6])}`).join(" ")}function xn(a){let e=a;if(!e.text||a.type==="text"||a.type==="line"||a.type==="arrow"||a.type==="draw")return "";let t=e.fontSize||16,i=a.type==="brace-left"||a.type==="brace-right",n=e.width??(e.radius?e.radius*2:100),s=e.height??(e.radius?e.radius*2:40),r=n*(i?1-de:1)*.85,o=s*.85,h=Je(String(e.text),t,r,o);return nt(h,t,e.textColor||ie,m(He(a)))}function m(a){return Math.round(a*100)/100}function It(a){return a.strokeDash&&a.strokeDash.length?a.strokeDash.join(","):void 0}function wn(a,e){let t=e.x-a.x,i=e.y-a.y,n=Math.cos(a.rotation),s=Math.sin(a.rotation);return {x:t*n-i*s+a.x,y:t*s+i*n+a.y}}var et=le;function Sn(a,e,t){return ce(a,e,t)}function bn(a,e,t){let i=a.endBinding;if(!i||!i.auto||i.isPrecise)return i;let n=a.startBinding?.handle?et[a.startBinding.handle]:void 0;return {...i,handle:Sn(e,{x:t.x,y:t.y},n)}}function St(a,e){if(e.isPrecise&&e.normalizedAnchor){let t=qe(a),i=a.x+t.x+t.width*e.normalizedAnchor.x,n=a.y+t.y+t.height*e.normalizedAnchor.y;return {x:i,y:n}}if(e.handle){let t=qe(a);switch(e.handle){case "top":return {x:a.x,y:a.y+t.y};case "bottom":return {x:a.x,y:a.y+t.y+t.height};case "left":return {x:a.x+t.x,y:a.y};case "right":return {x:a.x+t.x+t.width,y:a.y}}}return {x:a.x,y:a.y}}function Mn(a,e){let t=a.points.map(r=>({...r})),i,n;if(t.length===0)return {pts:t,fromN:i,toN:n};if(a.startBinding){let r=e.get(a.startBinding.toShapeId);r&&(t[0]=St(r,a.startBinding),!a.startBinding.isPrecise&&a.startBinding.handle&&(i=et[a.startBinding.handle]));}if(a.endBinding){let r=e.get(a.endBinding.toShapeId);if(r){let o=bn(a,t[0],r)??a.endBinding;t[t.length-1]=St(r,o),!o.isPrecise&&o.handle&&(n=et[o.handle]);}}let s=t;if(a.userPoints&&a.userPoints.length>0&&t.length>=2){let r=tt([t[0],t[t.length-1]]),o=a.connectionType||"straight",[h,l]=o==="curve"?[t[0],t[t.length-1]]:r;s=[h,...a.userPoints.map(c=>({...c})),l];}return {pts:s.map(r=>wn(a,r)),fromN:i,toN:n}}function tt(a){if(a.length<2)return a;let e=a[0],t=a[a.length-1],i=t.x-e.x,n=t.y-e.y,s=8;if(Math.abs(n)<=s){let r=(e.y+t.y)/2;return a.map(o=>({x:o.x,y:r}))}if(Math.abs(i)<=s){let r=(e.x+t.x)/2;return a.map(o=>({x:r,y:o.y}))}return a}function vn(a){if(a.length<2)return a;let e=[a[0]];for(let t=1;t<a.length;t++){let i=a[t-1],n=a[t],s=(i.x+n.x)/2,r=(i.y+n.y)/2;Math.abs(n.x-i.x)>=Math.abs(n.y-i.y)?(e.push({x:s,y:i.y}),e.push({x:s,y:n.y})):(e.push({x:i.x,y:r}),e.push({x:n.x,y:r})),e.push(n);}return e}function Pn(a){if(a.length<2)return "";let e=`M ${m(a[0].x)} ${m(a[0].y)}`,t=a[0];for(let i=1;i<a.length;i++){let n=a[i],s=n.x-t.x,r=n.y-t.y,o=Math.hypot(s,r),h={x:(t.x+n.x)/2,y:(t.y+n.y)/2};if(o>=1){let l=-r/o,c=s/o,d=Math.min(o*.2,30);h={x:h.x+l*d,y:h.y+c*d};}e+=` Q ${m(h.x)} ${m(h.y)} ${m(n.x)} ${m(n.y)}`,t=n;}return e}var Cn=24;function In(a,e,t,i){let n=Cn;t&&i&&(t.x!==0&&i.x!==0?n=Math.min(n,Math.abs(e.x-a.x)/2):t.y!==0&&i.y!==0&&(n=Math.min(n,Math.abs(e.y-a.y)/2)));let s=t?{x:a.x+t.x*n,y:a.y+t.y*n}:a,r=i?{x:e.x+i.x*n,y:e.y+i.y*n}:e,o=[a];t&&o.push(s);let h=r.x-s.x,l=r.y-s.y;if(Math.abs(h)<1||Math.abs(l)<1)o.push(r);else {let c=s.x+h/2,d=s.y+l/2,u=Math.max(s.x,Math.min(c,r.x)),g=Math.max(s.y,Math.min(d,r.y)),p=i?i.x!==0?"H":"V":t?t.x!==0?"H":"V":void 0;p==="H"?o.push({x:u,y:s.y},{x:u,y:r.y},r):p==="V"?o.push({x:s.x,y:g},{x:r.x,y:g},r):Math.abs(h)>=Math.abs(l)?o.push({x:c,y:s.y},{x:c,y:r.y},r):o.push({x:s.x,y:d},{x:r.x,y:d},r);}return i&&o.push(e),o}function bt(a){let e=[];for(let t of a){let i=e.length;if(!(i>0&&Math.abs(e[i-1].x-t.x)<1e-6&&Math.abs(e[i-1].y-t.y)<1e-6)){if(i>=2){let n=e[i-2],s=e[i-1];if(Math.abs(n.y-s.y)<1e-6&&Math.abs(s.y-t.y)<1e-6||Math.abs(n.x-s.x)<1e-6&&Math.abs(s.x-t.x)<1e-6){e[i-1]=t;continue}}e.push(t);}}return e}function Tn(a,e,t,i,n=false){if(e==="curve")return Pn(a);let s=n&&e==="straight"?"polyline":e,r;if(s==="straight")r=a.length===2?tt(a):a;else if(a.length===2){let h=tt(a);r=bt(In(h[0],h[1],t,i));}else r=bt(vn(a));if(r.length<2)return "";let o=`M ${m(r[0].x)} ${m(r[0].y)}`;for(let h=1;h<r.length;h++)o+=` L ${m(r[h].x)} ${m(r[h].y)}`;return o}function Ze(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),s=12,r={x:e.x-s*Math.cos(n-Math.PI/6),y:e.y-s*Math.sin(n-Math.PI/6)},o={x:e.x-s*Math.cos(n+Math.PI/6),y:e.y-s*Math.sin(n+Math.PI/6)};return `<path d="M ${m(e.x)} ${m(e.y)} L ${m(r.x)} ${m(r.y)} M ${m(e.x)} ${m(e.y)} L ${m(o.x)} ${m(o.y)}" stroke="${t}" stroke-width="${i}" stroke-linecap="round" fill="none" />`}function Mt(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),s=14,r=e.x,o=e.y,h=e.x-s*Math.cos(n),l=e.y-s*Math.sin(n),c=h+s*.5*Math.cos(n-Math.PI/2),d=l+s*.5*Math.sin(n-Math.PI/2),u=h+s*.5*Math.cos(n+Math.PI/2),g=l+s*.5*Math.sin(n+Math.PI/2);return `<polygon points="${m(r)},${m(o)} ${m(c)},${m(d)} ${m(u)},${m(g)}" fill="#ffffff" stroke="${t}" stroke-width="${i}" />`}function vt(a,e,t,i,n){let s=Math.atan2(e.y-a.y,e.x-a.x),r=14,o=e.x,h=e.y,l=e.x-r*.5*Math.cos(s),c=e.y-r*.5*Math.sin(s),d=e.x-r*Math.cos(s),u=e.y-r*Math.sin(s),g=l+r*.4*Math.cos(s-Math.PI/2),p=c+r*.4*Math.sin(s-Math.PI/2),y=l+r*.4*Math.cos(s+Math.PI/2),f=c+r*.4*Math.sin(s+Math.PI/2);return `<polygon points="${m(o)},${m(h)} ${m(g)},${m(p)} ${m(d)},${m(u)} ${m(y)},${m(f)}" fill="${n?t:"#ffffff"}" stroke="${t}" stroke-width="${i}" />`}function Dn(a,e,t,i){if(e==="none"||a.length<2)return "";let n="";return (e==="start"||e==="both")&&(n+=Ze(a[1],a[0],t,i)),(e==="end"||e==="both")&&(n+=Ze(a[a.length-2],a[a.length-1],t,i)),e==="inheritance"&&(n+=Mt(a[a.length-2],a[a.length-1],t,i)),e==="aggregation"&&(n+=vt(a[1],a[0],t,i,false)),e==="composition"&&(n+=vt(a[1],a[0],t,i,true)),e==="dependency"&&(n+=Ze(a[a.length-2],a[a.length-1],t,i)),e==="realization"&&(n+=Mt(a[a.length-2],a[a.length-1],t,i)),n}function nt(a,e,t,i=0,n=0){if(a.length===0)return "";let s=e*1.3,o=-(a.length*s)/2+s/2,h=a.map((l,c)=>`<tspan x="${m(i)}" y="${m(n+o+c*s)}">${se(l)}</tspan>`).join("");return `<text text-anchor="middle" dominant-baseline="central" font-family="sans-serif" font-size="${e}" fill="${t}">${h}</text>`}function A(a,e){let t=It(a),i=e&&a.fillColor!=="transparent",n=a.fillOpacity??1,s=a.strokeOpacity??1;return [i?`fill="${a.fillColor}"`:'fill="none"',i&&n<1?`fill-opacity="${m(n)}"`:"",`stroke="${a.strokeColor}"`,s<1&&a.strokeColor!=="transparent"?`stroke-opacity="${m(s)}"`:"",`stroke-width="${a.strokeWidth}"`,'stroke-linecap="round"','stroke-linejoin="round"',t?`stroke-dasharray="${t}"`:""].filter(Boolean).join(" ")}function Pt(a,e){let{width:t,height:i}=a,n=t/2,s=i/2,r=`${$}px sans-serif`,o=_,h=e?0:a.attributes.length>0?a.attributes.length*D+T*2:T*2,l=t-H*2,c=[];c.push(`<rect x="${m(-n)}" y="${m(-s)}" width="${t}" height="${i}" ${A(a.style,true)} />`),c.push(`<line x1="${m(-n)}" y1="${m(-s+o)}" x2="${m(n)}" y2="${m(-s+o)}" stroke="${a.style.strokeColor}" stroke-width="${a.style.strokeWidth}" />`),e||c.push(`<line x1="${m(-n)}" y1="${m(-s+o+h)}" x2="${m(n)}" y2="${m(-s+o+h)}" stroke="${a.style.strokeColor}" stroke-width="${a.style.strokeWidth}" />`);let d=e?`<<${a.className||"Interface"}>>`:a.className;c.push(`<text text-anchor="middle" dominant-baseline="central" font-family="sans-serif" font-weight="bold" font-size="${$}" fill="${a.textColor||ie}" x="0" y="${m(-s+o/2)}">${se(Qe(d,l,r))}</text>`);let u=(p,y,f,S,x)=>{let M=`${f||$}px sans-serif`,v=Qe(p,l,M),w=`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${f||$}" fill="${S||ie}" x="${m(-n+H)}" y="${m(y)}">${se(v)}</text>`;if(x){let b=F(v,M);w+=`<line x1="${m(-n+H)}" y1="${m(y)}" x2="${m(-n+H+b)}" y2="${m(y)}" stroke="${S||ie}" stroke-width="1" />`;}return w};if(!e){let p=-s+o+T+D/2;a.attributes.forEach((y,f)=>{c.push(u(`${y.visibility} ${y.name}: ${y.type}`,p+f*D,y.fontSize||a.fontSize||0,y.textColor||a.textColor||"",!!y.strikethrough));});}let g=-s+o+h+T+D/2;return a.methods.forEach((p,y)=>{c.push(u(`${p.visibility} ${p.name}(${p.params}): ${p.returnType}`,g+y*D,p.fontSize||a.fontSize||0,p.textColor||a.textColor||"",!!p.strikethrough));}),c.join("")}function Ln(a){let t=k(a.root).positions,i=[],n=r=>{if(r.collapsed)return;let o=t.get(r.id);if(o)for(let h of r.children??[]){let l=t.get(h.id);if(!l)continue;let c=j(h,l.depth),d=a.x+o.x+o.width/2,u=a.y+o.y,g=a.x+l.x-l.width/2,p=a.y+l.y,y=(d+g)/2;i.push(`<path d="M ${m(d)} ${m(u)} C ${m(y)} ${m(u)} ${m(y)} ${m(p)} ${m(g)} ${m(p)}" stroke="${c}" stroke-width="2" fill="none" stroke-linecap="round" />`),n(h);}};n(a.root);let s=r=>{let o=t.get(r.id);if(!o)return;let h=j(r,o.depth),l=o.width/2,c=o.height/2,d=a.x+o.x,u=a.y+o.y;if(i.push(`<rect x="${m(d-l)}" y="${m(u-c)}" width="${o.width}" height="${o.height}" rx="6" ry="6" fill="#ffffff" stroke="${h}" stroke-width="2" />`),r.note){let M="11px sans-serif",v=r.noteColor??h,w=Math.min(F(r.note,M)+12,130),b=16,C=F(r.note,M)+12>130?r.note.slice(0,12)+"\u2026":r.note;i.push(`<rect x="${m(d-l)}" y="${m(u-c-b+2)}" width="${w}" height="${b}" rx="4" ry="4" fill="${v}" />`),i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="11" fill="#ffffff" x="${m(d-l+6)}" y="${m(u-c-b/2+2)}">${se(C)}</text>`);}let g=r.icon?18:0,p=o.width-g-(r.icon?8:0)-16,y=Qe(r.text||"",p,`${14}px sans-serif`),f=F(y,`${14}px sans-serif`),S=g+(g?8:0)+f,x=d-S/2;if(r.icon&&(i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="16" fill="#1f2937" x="${m(x)}" y="${m(u)}">${se(r.icon)}</text>`),x+=g+8),i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${14}" fill="#1f2937" x="${m(x)}" y="${m(u)}">${se(y)}</text>`),r.children&&r.children.length>0&&!r.collapsed)for(let M of r.children)s(M);};return s(a.root),i.join("")}function En(a,e){let t=a.rotation*180/Math.PI,i=`<g transform="translate(${m(a.x)} ${m(a.y)}) rotate(${m(t)})">`,n=`${xn(a)}</g>`,s=a.style;switch(a.type){case "rectangle":{let r=a.width,o=a.height;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" ${A(s,true)} />${n}`}case "rounded-rectangle":{let r=a.width,o=a.height,h=a.borderRadius||8;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" rx="${h}" ry="${h}" ${A(s,true)} />${n}`}case "stadium":{let r=a.width,o=a.height,h=Math.min(r,o)/2;return `${i}<rect x="${m(-r/2)}" y="${m(-o/2)}" width="${r}" height="${o}" rx="${h}" ry="${h}" ${A(s,true)} />${n}`}case "circle":{let r=a.radius;return `${i}<circle cx="0" cy="0" r="${r}" ${A(s,true)} />${n}`}case "ellipse":{let r=a.width,o=a.height;return `${i}<ellipse cx="0" cy="0" rx="${r/2}" ry="${o/2}" ${A(s,true)} />${n}`}case "diamond":{let r=a.width,o=a.height;return `${i}<polygon points="${K([[0,-o/2],[r/2,0],[0,o/2],[-r/2,0]])}" ${A(s,true)} />${n}`}case "triangle":{let r=a.width,o=a.height;return `${i}<polygon points="${K([[0,-o/2],[r/2,o/2],[-r/2,o/2]])}" ${A(s,true)} />${n}`}case "hexagon":{let r=a.width,o=a.height;return `${i}<polygon points="${K(je(r,o,6,-Math.PI/2))}" ${A(s,true)} />${n}`}case "pentagon":{let r=a.width,o=a.height;return `${i}<polygon points="${K(je(r,o,5,-Math.PI/2))}" ${A(s,true)} />${n}`}case "octagon":{let r=a.width,o=a.height;return `${i}<polygon points="${K(je(r,o,8,-Math.PI/8))}" ${A(s,true)} />${n}`}case "star":{let r=a.width,o=a.height;return `${i}<polygon points="${K(kn(r,o))}" ${A(s,true)} />${n}`}case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "class-catalog":case "chevron":case "brace-left":case "brace-right":{let r=a.width,o=a.height,h=$e(a.type);if(!h)return "";let l=`<path d="${wt(ne(h.outline,r,o))}" ${A(s,!h.strokeOnly)} />`,c=(h.seams??[]).map(d=>`<path d="${wt(ne(d,r,o))}" ${A({...s,fillColor:"transparent"},true)} />`).join("");return `${i}${l}${c}${n}`}case "parallelogram":{let r=a.width,o=a.height,h=r*.2;return `${i}<polygon points="${K([[-r/2+h,-o/2],[r/2,-o/2],[r/2-h,o/2],[-r/2,o/2]])}" ${A(s,true)} />${n}`}case "trapezoid":{let r=a.width,o=a.height,h=r*.15;return `${i}<polygon points="${K([[-r/2+h,-o/2],[r/2-h,-o/2],[r/2,o/2],[-r/2,o/2]])}" ${A(s,true)} />${n}`}case "uml-class":return `${i}${Pt(a,false)}${n}`;case "uml-interface":return `${i}${Pt(a,true)}${n}`;case "mind-map":return Ln(a);case "line":case "arrow":{let r=a,o=r.connectionType||"straight",{pts:h,fromN:l,toN:c}=Mn(r,e);if(h.length<2)return "";let d=r.style.strokeColor,u=r.style.strokeWidth,p=r.type==="arrow"&&(!!r.dashed||r.arrowHead==="dependency"||r.arrowHead==="realization")?"8,5":It(r.style),y=`<path d="${Tn(h,o,l,c,!!(r.userPoints&&r.userPoints.length))}" fill="none" stroke="${d}" stroke-width="${u}" stroke-linecap="round" stroke-linejoin="round"${p?` stroke-dasharray="${p}"`:""} />`,f=Dn(h,r.arrowHead||"end",d,u);return `${y}${f}`}case "draw":{let r=a,o=r.points;if(!o||o.length<2)return "";let h=Math.cos(r.rotation||0),l=Math.sin(r.rotation||0),c=o.map(u=>({x:u.x*h-u.y*l+r.x,y:u.x*l+u.y*h+r.y}));if(c.length<2)return "";let d=`M ${m(c[0].x)} ${m(c[0].y)}`;for(let u=1;u<c.length-1;u++){let g=(c[u].x+c[u+1].x)/2,p=(c[u].y+c[u+1].y)/2;d+=` Q ${m(c[u].x)} ${m(c[u].y)} ${m(g)} ${m(p)}`;}return d+=` L ${m(c[c.length-1].x)} ${m(c[c.length-1].y)}`,`<path d="${d}" fill="none" stroke="${s.strokeColor}" stroke-width="${s.strokeWidth}" stroke-linecap="round" stroke-linejoin="round" />`}case "text":{let r=a,o=r.fontSize||16,h=r.textColor||ie,l=Je(r.text||"",o,r.width,r.height),c="";if(r.highlightColor&&r.highlightColor!=="transparent"){let d=o*.15,u=typeof r.highlightOpacity=="number"?r.highlightOpacity:1,g=u<1?` fill-opacity="${m(u)}"`:"";c+=`<rect x="${m(-r.width/2-d)}" y="${m(-(l.length*o*1.3)/2-d)}" width="${r.width+d*2}" height="${l.length*o*1.3+d*2}" rx="4" fill="${r.highlightColor}"${g} />`;}return c+=nt(l,o,h),`${i}${c}${n}`}default:{let r=a,o=r.width||100,h=r.height||40,l="";if(r.text){let c=r.fontSize||16,d=Je(r.text,c,o*.85,h*.85);l+=nt(d,c,r.textColor||ie);}return `${i}<rect x="${m(-o/2)}" y="${m(-h/2)}" width="${o}" height="${h}" ${A(s,true)} />${l}${n}`}}}function je(a,e,t,i){let n=a/2,s=e/2,r=[];for(let o=0;o<t;o++){let h=o*2*Math.PI/t+i;r.push([n*Math.cos(h),s*Math.sin(h)]);}return r}function kn(a,e){let t=a/2,i=e/2,n=5,s=.4,r=[];for(let o=0;o<n*2;o++){let h=o*Math.PI/n-Math.PI/2,l=o%2===0?1:s;r.push([t*l*Math.cos(h),i*l*Math.sin(h)]);}return r}function Tt(a,e={}){let t=e.padding??24,i=e.background===void 0?"#ffffff":e.background??null,n=xe(a,t),s=Math.max(1,Math.ceil(n.width)),r=Math.max(1,Math.ceil(n.height)),o=new Map(a.map(c=>[c.id,c])),h=a.map(c=>En(c,o)).filter(Boolean).join(`
4
4
  `),l=i?`<rect x="${m(n.x)}" y="${m(n.y)}" width="${s}" height="${r}" fill="${i}" />`:"";return `<?xml version="1.0" encoding="UTF-8"?>
5
5
  <svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${r}" viewBox="${m(n.x)} ${m(n.y)} ${s} ${r}" font-family="sans-serif">
6
6
  ${l}
7
7
  ${h}
8
- </svg>`}function Te(a){return a.toString().padStart(10,"0")}function Vn(a,e,t){let i=a.split(",")[1]||"",n=atob(i),s=new Uint8Array(n.length);for(let C=0;C<n.length;C++)s[C]=n.charCodeAt(C);let r=Math.round(e),o=Math.round(t),h=`<< /Type /XObject /Subtype /Image /Width ${r} /Height ${o} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${s.length} >>`,l=`q ${r} 0 0 ${o} 0 0 cm /Im0 Do Q`,c=`1 0 obj
8
+ </svg>`}function me(a){return a.toString().padStart(10,"0")}function An(a,e,t){let i=a.split(",")[1]||"",n=atob(i),s=new Uint8Array(n.length);for(let C=0;C<n.length;C++)s[C]=n.charCodeAt(C);let r=Math.round(e),o=Math.round(t),h=`<< /Type /XObject /Subtype /Image /Width ${r} /Height ${o} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${s.length} >>`,l=`q ${r} 0 0 ${o} 0 0 cm /Im0 Do Q`,c=`1 0 obj
9
9
  << /Type /Catalog /Pages 2 0 R >>
10
10
  endobj
11
11
  `,d=`2 0 obj
12
12
  << /Type /Pages /Kids [3 0 R] /Count 1 >>
13
13
  endobj
14
- `,g=`3 0 obj
14
+ `,u=`3 0 obj
15
15
  << /Type /Page /Parent 2 0 R /MediaBox [0 0 ${r} ${o}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>
16
16
  endobj
17
- `,u=`4 0 obj
17
+ `,g=`4 0 obj
18
18
  ${h}
19
19
  stream
20
20
  `,p=`endstream
@@ -26,18 +26,18 @@ ${l}
26
26
  endstream
27
27
  endobj
28
28
  `,f=`%PDF-1.4
29
- `,w=f.length,x=w+c.length,v=x+d.length,b=v+g.length,S=b+u.length+s.length+p.length,I=`xref
29
+ `,S=f.length,x=S+c.length,M=x+d.length,v=M+u.length,w=v+g.length+s.length+p.length,b=`xref
30
30
  0 6
31
31
  0000000000 65535 f
32
- `+Te(w)+` 00000 n
33
- `+Te(x)+` 00000 n
34
- `+Te(v)+` 00000 n
35
- `+Te(b)+` 00000 n
36
- `+Te(S)+` 00000 n
32
+ `+me(S)+` 00000 n
33
+ `+me(x)+` 00000 n
34
+ `+me(M)+` 00000 n
35
+ `+me(v)+` 00000 n
36
+ `+me(w)+` 00000 n
37
37
  trailer
38
38
  << /Size 6 /Root 1 0 R >>
39
39
  startxref
40
- ${S+y.length}
41
- %%EOF`;return new Blob([f+c+d+g+u,s,p+y+I],{type:"application/pdf"})}async function lt(a,e,t={}){if(e==="svg"){let s=Lt(a,t);return new Blob([s],{type:"image/svg+xml;charset=utf-8"})}let i=Dt(a,t);if(e==="png")return xn(i,"image/png");let n=wn(i,"image/jpeg",.92);return Vn(n,i.width,i.height)}function ct(a,e){let t=URL.createObjectURL(a),i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(t),1e3);}var dt="drawui-canvas-data",Nn=50,ut=class{canvas;renderer;camera;tools=new Map;activeTool="select";shapes=[];selectedIds=[];listeners=new Set;notificationListeners=new Set;uiListeners=new Set;isPanning=false;panStart={x:0,y:0};dragStartPositions=new Map;lastClickTime=0;lastClickShapeId=null;editingShapeId=null;textInput=null;textOverlay=null;isNewTextShape=false;originalTextValue="";undoStack=[];redoStack=[];isUndoing=false;brushRect=null;snapGuides=[];connectingTargetId=null;genPreview=null;hoverAnchorShapeId=null;eraserPoint=null;mindMapEditingShapeId=null;mindMapSelectedNode=null;mindMapHoverNode=null;renderScheduled=false;pointerIsDown=false;notifyScheduled=false;persist=true;arrowStyle={connectionType:"straight",arrowHead:"end",dashed:false};constructor(e,t={}){this.canvas=e,this.persist=t.persist??!t.shapes,t.theme&&Le(t.theme),t.language&&Ae(t.language);let i=e.getBoundingClientRect();this.renderer=new ae(e),this.renderer.resize(i.width,i.height),this.camera=new re;let n={addShape:s=>this.addShape(s),updateShape:(s,r)=>this.updateShape(s,r),deleteShape:s=>this.deleteShape(s),selectShape:(s,r)=>this.selectShape(s,r),selectShapes:s=>this.selectShapes(s),getShapes:()=>[...this.shapes],getSelectedIds:()=>[...this.selectedIds],setActiveTool:s=>this.setActiveTool(s),screenToPage:s=>this.screenToPage(s),getCamera:()=>this.camera,panBy:(s,r)=>this.panBy(s,r),setCameraPosition:(s,r)=>this.setCameraPosition(s,r),getShapeAtPoint:(s,r)=>this.getShapeAtPoint(s,r),getShapesInBrushRadius:(s,r)=>this.getShapesInBrushRadius(s,r),setEraserPoint:s=>this.setEraserPoint(s),updateArrowBinding:(s,r,o,h)=>this.updateArrowBinding(s,r,o,h),enterEditing:s=>this.enterEditing(s),exitEditing:()=>this.exitEditing(),commitHistory:()=>this.commitHistory(),setBrushRect:s=>this.setBrushRect(s),setSnapGuides:s=>this.setSnapGuides(s),setConnectingTarget:s=>this.setConnectingTarget(s),setGenerationPreview:s=>this.setGenerationPreview(s),setHoverAnchorShape:s=>this.setHoverAnchorShape(s),getLineStyle:()=>this.lineStyle(),openGenerationMenu:s=>this.openGenerationMenu(s),createGeneratedConnection:(s,r)=>this.createGeneratedConnection(s,r),createFloatingLine:s=>this.createFloatingLine(s),connectToExisting:(s,r,o)=>this.connectToExisting(s,r,o),updateSelectedShapesStyle:s=>this.updateSelectedShapesStyle(s),updateSelectedShapesText:s=>this.updateSelectedShapesText(s),updateConnectionType:s=>this.updateConnectionType(s),getArrowStyle:()=>this.getArrowStyle(),getMindMapCursorHitAtPoint:s=>this.getMindMapCursorHitAtPoint(s),selectMindMapNode:(s,r)=>this.selectMindMapNode(s,r)};this.tools.set("select",new Se(n)),this.tools.set("hand",new Me(n)),this.tools.set("rectangle",new T(n,"rectangle")),this.tools.set("rounded-rectangle",new T(n,"rounded-rectangle")),this.tools.set("circle",new T(n,"circle")),this.tools.set("ellipse",new T(n,"ellipse")),this.tools.set("diamond",new T(n,"diamond")),this.tools.set("triangle",new T(n,"triangle")),this.tools.set("hexagon",new T(n,"hexagon")),this.tools.set("parallelogram",new T(n,"parallelogram")),this.tools.set("trapezoid",new T(n,"trapezoid")),this.tools.set("pentagon",new T(n,"pentagon")),this.tools.set("octagon",new T(n,"octagon")),this.tools.set("star",new T(n,"star")),this.tools.set("cylinder",new T(n,"cylinder")),this.tools.set("cloud",new T(n,"cloud")),this.tools.set("heart",new T(n,"heart")),this.tools.set("block-arrow-right",new T(n,"block-arrow-right")),this.tools.set("block-arrow-left",new T(n,"block-arrow-left")),this.tools.set("block-arrow-up",new T(n,"block-arrow-up")),this.tools.set("block-arrow-down",new T(n,"block-arrow-down")),this.tools.set("block-arrow-double",new T(n,"block-arrow-double")),this.tools.set("right-triangle",new T(n,"right-triangle")),this.tools.set("cross",new T(n,"cross")),this.tools.set("speech-rect",new T(n,"speech-rect")),this.tools.set("speech-round",new T(n,"speech-round")),this.tools.set("cube",new T(n,"cube")),this.tools.set("sector",new T(n,"sector")),this.tools.set("delay",new T(n,"delay")),this.tools.set("predefined-process",new T(n,"predefined-process")),this.tools.set("document",new T(n,"document")),this.tools.set("stadium",new T(n,"stadium")),this.tools.set("class-catalog",new T(n,"class-catalog")),this.tools.set("chevron",new T(n,"chevron")),this.tools.set("brace-left",new T(n,"brace-left")),this.tools.set("brace-right",new T(n,"brace-right")),this.tools.set("uml-class",new T(n,"uml-class")),this.tools.set("uml-interface",new T(n,"uml-interface")),this.tools.set("line",new ve(n)),this.tools.set("arrow",new Pe(n)),this.tools.set("text",new Xe(n)),this.tools.set("pen",new ne(n,"pen")),this.tools.set("highlighter",new ne(n,"highlighter")),this.tools.set("eraser",new Be(n)),this.tools.set("mind-map",new T(n,"mind-map")),this.setupEventListeners(),t.shapes?this.shapes=t.shapes.map(s=>({...s,style:{...s.style}})):this.persist&&this.loadFromStorage(),this.render();}setupEventListeners(){this.canvas.addEventListener("pointerdown",this.handlePointerDown),this.canvas.addEventListener("pointerleave",this.handlePointerUp),window.addEventListener("pointermove",this.handlePointerMove),window.addEventListener("pointerup",this.handlePointerUp),window.addEventListener("pointercancel",this.handlePointerUp),window.addEventListener("blur",this.handleWindowBlur),window.addEventListener("pointerdown",this.handleGlobalPointerDown,true),this.canvas.addEventListener("wheel",this.handleWheel,{passive:false}),window.addEventListener("keydown",this.handleKeyDown),window.addEventListener("keyup",this.handleKeyUp),window.addEventListener("resize",this.handleResize);}handleWindowBlur=()=>{this.pointerIsDown=false,this.isPanning=false,this.cancelTransientInteraction(),this.scheduleRender();};handleGlobalPointerDown=e=>{e.target!==this.canvas&&(!e.isPrimary||e.button!==0||(this.pointerIsDown=false,this.isPanning=false,this.cancelTransientInteraction()&&this.scheduleRender()));};shouldRecoverTransient(){let e=this.tools.get(this.activeTool);return !!this.connectingTargetId||this.snapGuides.length>0||!!this.brushRect||!!e&&e.hasTransientState()}cancelTransientInteraction(){let e=!!this.tools.get(this.activeTool)?.cancelTransient(),t=this.clearTransientPreview();return e||t}handlePointerDown=e=>{if(this.editingShapeId)return this.textInput&&e.target===this.textInput,void 0;this.clearTransientPreview(),this.pointerIsDown=true;try{this.canvas.hasPointerCapture(e.pointerId)||this.canvas.setPointerCapture(e.pointerId);}catch{}if(e.button===1||e.button===0&&e.altKey){this.isPanning=true,this.panStart={x:e.clientX,y:e.clientY},this.canvas.setPointerCapture(e.pointerId),this.canvas.style.cursor="grabbing";return}let t=this.screenToPage({x:e.clientX,y:e.clientY}),i=this.activeTool==="select"?this.getMindMapCollapseHitAtPoint(t):null;if(i){this.toggleMindMapCollapse(i.shapeId,i.nodeId);return}if(this.activeTool==="select"){let s=Date.now(),r=this.getShapeAtPoint(t);if(s-this.lastClickTime<400&&this.lastClickShapeId&&r&&r.id===this.lastClickShapeId&&this.canEditShape(r)){this.enterEditing(r.id),this.lastClickTime=0,this.lastClickShapeId=null;return}if(this.lastClickTime=s,this.lastClickShapeId=r?.id||null,r&&r.type==="mind-map"&&this.mindMapEditingShapeId===r.id){let o=this.getMindMapNodeAtPoint(t);o&&(this.mindMapSelectedNode=o,this.notifyListeners(),this.render());return}r&&(this.dragStartPositions.clear(),this.selectedIds.forEach(o=>{let h=this.shapes.find(l=>l.id===o);h&&this.dragStartPositions.set(o,{x:h.x,y:h.y});}));}this.tools.get(this.activeTool)?.onPointerDown(t,e),this.updateCursor(t),this.render();};handlePointerMove=e=>{if(this.editingShapeId||(e.buttons===0&&this.pointerIsDown&&(this.pointerIsDown=false,this.shouldRecoverTransient()&&(this.cancelTransientInteraction(),this.scheduleRender())),!this.pointerIsDown&&this.shouldRecoverTransient()&&this.cancelTransientInteraction(),!this.pointerIsDown&&e.target!==this.canvas))return;if(this.isPanning){let n=e.clientX-this.panStart.x,s=e.clientY-this.panStart.y;this.camera.translate(n,s),this.panStart={x:e.clientX,y:e.clientY},this.scheduleRender(),this.notifyListeners();return}let t=this.screenToPage({x:e.clientX,y:e.clientY});this.tools.get(this.activeTool)?.onPointerMove(t,e),this.updateCursor(t),this.scheduleRender();};handlePointerUp=e=>{if(e.type==="pointerleave"){if(this.mindMapHoverNode=null,this.pointerIsDown){this.scheduleRender();return}}else {if(!this.pointerIsDown&&e.target!==this.canvas)return;this.canvas.hasPointerCapture(e.pointerId)&&this.canvas.releasePointerCapture(e.pointerId);}if(this.pointerIsDown=false,this.editingShapeId)return;if(this.isPanning){this.isPanning=false,this.updateCursor(this.screenToPage({x:e.clientX,y:e.clientY}));return}let t=this.screenToPage({x:e.clientX,y:e.clientY});this.tools.get(this.activeTool)?.onPointerUp(t,e),this.updateCursor(t),this.scheduleRender();};updateCursor(e){let i=this.tools.get(this.activeTool)?.getCursor(e)??"default";if(this.canvas.style.cursor!==i&&(this.canvas.style.cursor=i),!this.pointerIsDown){let n=this.getMindMapCursorHitAtPoint(e);(n?.shapeId!==this.mindMapHoverNode?.shapeId||n?.nodeId!==this.mindMapHoverNode?.nodeId)&&(this.mindMapHoverNode=n,this.scheduleRender());}}handleWheel=e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let n=e.deltaY>0?.9:1.1;this.camera.zoomAt({x:e.clientX,y:e.clientY},n),this.scheduleRender(),this.notifyListeners();return}let t=e.deltaX||0,i=e.deltaY||0;e.deltaMode===1?(t*=40,i*=40):e.deltaMode===2&&(t*=120,i*=120),e.shiftKey&&(t=t||i,i=0),this.camera.translate(-t,-i),this.scheduleRender(),this.notifyListeners();};handleKeyDown=e=>{if(this.editingShapeId)return;if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="z"){e.preventDefault(),e.shiftKey?this.redo():this.undo();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="y"){e.preventDefault(),this.redo();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="s"){e.preventDefault(),this.saveToStorage();return}if(!e.ctrlKey&&!e.metaKey&&!e.altKey){if(e.key==="v"||e.key==="V"){this.setActiveTool("select"),e.preventDefault();return}if(e.key==="h"||e.key==="H"){this.setActiveTool("hand"),e.preventDefault();return}}this.tools.get(this.activeTool)?.onKeyDown(e),this.scheduleRender();};handleKeyUp=e=>{if(this.editingShapeId)return;this.tools.get(this.activeTool)?.onKeyUp(e),this.scheduleRender();};handleResize=()=>{this.renderer.resize(window.innerWidth,window.innerHeight),this.scheduleRender();};screenToPage(e){let t=this.canvas.getBoundingClientRect();return this.camera.screenToPage({x:e.x-t.left,y:e.y-t.top})}addShape(e){this.shapes.push(e),this.notifyListeners();}updateShape(e,t){let i=this.shapes.findIndex(n=>n.id===e);i!==-1&&(this.shapes[i]={...this.shapes[i],...t},(t.x!==void 0||t.y!==void 0)&&this.updateBoundArrows(e),this.notifyListeners());}updateBoundArrows(e){let t=this.shapes.find(i=>i.id===e);t&&this.shapes.forEach(i=>{if(i.type==="arrow"){let n=i,s={};if(n.startBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.startBinding.handle||"top");s.points=n.points.map((o,h)=>h===0?r:o);}if(n.endBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.endBinding.handle||"top"),o=s.points||[...n.points];s.points=o.map((h,l)=>l===o.length-1?r:h);}s.points&&(this.shapes[this.shapes.indexOf(i)]={...n,...s});}});}getBindingPosition(e,t){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}case "circle":switch(t){case "top":return {x:e.x,y:e.y-e.radius};case "bottom":return {x:e.x,y:e.y+e.radius};case "left":return {x:e.x-e.radius,y:e.y};case "right":return {x:e.x+e.radius,y:e.y}}case "hexagon":switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}default:return {x:e.x,y:e.y}}}deleteShape(e){this.shapes=this.shapes.filter(t=>t.id!==e),this.selectedIds=this.selectedIds.filter(t=>t!==e),this.shapes=this.shapes.map(t=>{if(t.type==="arrow"){let i=t;if(i.startBinding?.toShapeId===e)return {...i,startBinding:void 0};if(i.endBinding?.toShapeId===e)return {...i,endBinding:void 0}}return t}),this.notifyListeners(),this.scheduleRender();}selectShape(e,t){if(!e)this.selectedIds=[];else if(t){let i=this.selectedIds.indexOf(e);i===-1?this.selectedIds.push(e):this.selectedIds.splice(i,1);}else this.selectedIds=[e];this.notifyListeners(),this.scheduleRender();}selectShapes(e){this.selectedIds=[...e],this.notifyListeners(),this.scheduleRender();}setBrushRect(e){this.brushRect=e,this.scheduleRender();}setSnapGuides(e){this.snapGuides=e;}setConnectingTarget(e){this.connectingTargetId!==e&&(this.connectingTargetId=e,this.scheduleRender());}setGenerationPreview(e){let t=this.genPreview;t?.from.x===e?.from.x&&t?.from.y===e?.from.y&&t?.to.x===e?.to.x&&t?.to.y===e?.to.y&&t?.type===e?.type&&t?.targetShapeId===e?.targetShapeId&&t?.dragging===e?.dragging&&t?.sourceEdge===e?.sourceEdge||(this.genPreview=e,this.scheduleRender());}setHoverAnchorShape(e){this.hoverAnchorShapeId!==e&&(this.hoverAnchorShapeId=e,this.scheduleRender());}clearTransientPreview(){return !!this.genPreview||!!this.connectingTargetId||this.snapGuides.length>0||!!this.brushRect||!!this.hoverAnchorShapeId?(this.genPreview=null,this.connectingTargetId=null,this.snapGuides=[],this.brushRect=null,this.hoverAnchorShapeId=null,true):false}openGenerationMenu(e){let t=this.camera.getZoom(),i=(e.context.to.x+this.camera.x)*t,n=(e.context.to.y+this.camera.y)*t;this.emitUi({kind:"shapeTypeMenu",screenX:i,screenY:n,context:e.context,existingArrowId:e.existingArrowId,defaultShapeType:e.defaultShapeType});}lineStyle(){return {strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null}}computeSourceBinding(e){if(!e.sourceShapeId||!e.edge)return;let t=this.shapes.find(n=>n.id===e.sourceShapeId);if(!t)return;let i={n:"top",e:"right",s:"bottom",w:"left"};return {toShapeId:t.id,handle:i[e.edge]}}connectHandle(e,t,i){return Ne(e,t,i)}createFloatingLine(e){this.commitHistory();let t=e.from,i=e.to,n=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,s={id:n,type:"arrow",x:t.x,y:t.y,points:[{x:t.x,y:t.y},{x:i.x,y:i.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};return this.addShape(s),this.selectedIds=[n],this.notifyListeners(),this.render(),n}createGeneratedConnection(e,t){this.commitHistory();let i=t.type,n;if(e.sourceShapeId){let h=this.shapes.find(l=>l.id===e.sourceShapeId);h&&He(h.type)&&(n={...h.style});}let s=ee(i,e.to,n);this.addShape(s);let r=e.from,o={toShapeId:s.id,handle:this.connectHandle(r,e.to,e.edge),auto:true};if(t.existingArrowId)this.updateArrowBinding(t.existingArrowId,"end",s.id,{toShapeId:s.id,handle:this.connectHandle(r,e.to,e.edge),auto:true});else {let l={id:`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,type:"arrow",x:r.x,y:r.y,points:[{x:r.x,y:r.y},{x:e.to.x,y:e.to.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),endBinding:o,connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};this.addShape(l);}this.selectedIds=[s.id],this.notifyListeners(),this.render();}connectToExisting(e,t,i){this.commitHistory();let n=this.shapes.find(c=>c.id===t);if(!n)return;let s=e.from,r=i?.handle??this.connectHandle(s,{x:n.x,y:n.y},e.edge),o=this.getBindingPosition(n,r),h=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,l={id:h,type:"arrow",x:s.x,y:s.y,points:[{x:s.x,y:s.y},{x:o.x,y:o.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),endBinding:{toShapeId:t,handle:r,auto:!i||!i.handle&&!i.isPrecise},connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};this.addShape(l),this.selectedIds=[h],this.notifyListeners(),this.render();}subscribeUi(e){return this.uiListeners.add(e),()=>this.uiListeners.delete(e)}emitUi(e){this.uiListeners.forEach(t=>t(e));}updateSelectedShapesStyle(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);i!==-1&&(this.shapes[i]={...this.shapes[i],style:{...this.shapes[i].style,...e}});}),this.notifyListeners(),this.render());}updateSelectedShapesText(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);i!==-1&&(this.shapes[i]={...this.shapes[i],...e});}),this.notifyListeners(),this.render());}updateConnectionType(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);if(i!==-1){let n=this.shapes[i];(n.type==="line"||n.type==="arrow")&&(this.shapes[i]={...n,connectionType:e});}}),this.notifyListeners(),this.render());}updateArrowHeadType(e){if(this.selectedIds.length===0)return;this.commitHistory();let t=e==="dependency"||e==="realization";this.selectedIds.forEach(i=>{let n=this.shapes.findIndex(s=>s.id===i);if(n!==-1){let s=this.shapes[n];s.type==="arrow"&&(this.shapes[n]=t?{...s,arrowHead:e,dashed:true}:{...s,arrowHead:e});}}),this.notifyListeners(),this.render();}updateArrowStyle(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(o=>o.id===t);if(i===-1)return;let n=this.shapes[i];if(n.type!=="arrow")return;let s=e.arrowHead??n.arrowHead??"end",r=s==="dependency"||s==="realization";this.shapes[i]={...n,...e,arrowHead:s,dashed:r?true:e.dashed??n.dashed??false};}),this.notifyListeners(),this.render());}getArrowStyle(){return {...this.arrowStyle}}setArrowStyle(e){let t={...this.arrowStyle,...e};(t.arrowHead==="dependency"||t.arrowHead==="realization")&&(t.dashed=true),this.arrowStyle=t,this.notifyListeners();}updateArrowDashed(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);if(i!==-1){let n=this.shapes[i];n.type==="arrow"&&(this.shapes[i]={...n,dashed:e});}}),this.notifyListeners(),this.render());}updateUmlClass(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="uml-class")return;this.commitHistory();let s=t.className??n.className,r=t.attributes??n.attributes,o=t.methods??n.methods,{width:h,height:l}=Ve(s,r,o);this.shapes[i]={...n,className:s,attributes:r,methods:o,width:h,height:l},this.notifyListeners(),this.render();}updateUmlInterface(e,t){let i=this.shapes.findIndex(p=>p.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="uml-interface")return;this.commitHistory();let s=n,r=t.className??s.className,o=t.methods??s.methods,h=U*.6,l=o.map(p=>`${p.visibility} ${p.name}(${p.params}): ${p.returnType}`),c=Math.max(r.length,...l.map(p=>p.length),0),d=Math.max(me,c*h+O*2),g=o.length>0?o.length*$+k*2:k*2,u=j+g;this.shapes[i]={...n,className:r,methods:o,width:d,height:u},this.notifyListeners(),this.render();}getSelectedUml(){if(this.selectedIds.length!==1)return null;let e=this.shapes.find(t=>t.id===this.selectedIds[0]);return e&&(e.type==="uml-class"||e.type==="uml-interface")?e:null}getUmlById(e){let t=this.shapes.find(i=>i.id===e);return t&&(t.type==="uml-class"||t.type==="uml-interface")?t:null}getSelectedMindMap(){if(this.selectedIds.length!==1)return null;let e=this.shapes.find(t=>t.id===this.selectedIds[0]);return e&&e.type==="mind-map"?e:null}getMindMapNodeAtPoint(e){for(let t=this.shapes.length-1;t>=0;t--){let i=this.shapes[t];if(i.type!=="mind-map")continue;let n=i,s=e.x-n.x,r=e.y-n.y,o=Math.cos(n.rotation),h=Math.sin(n.rotation),l=s*o+r*h,c=-s*h+r*o;if(Math.abs(l)>n.width/2||Math.abs(c)>n.height/2)continue;let d=B(n.root);for(let[g,u]of d.positions)if(Math.abs(l-u.x)<=u.width/2&&Math.abs(c-u.y)<=u.height/2)return {shapeId:n.id,nodeId:g};return {shapeId:n.id,nodeId:n.root.id}}return null}getMindMapNodeAtScreenPoint(e){return this.getMindMapNodeAtPoint(this.screenToPage(e))}getMindMapCursorHitAtPoint(e){let t=this.getMindMapCollapseHitAtPoint(e);if(t)return t;for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(n.type!=="mind-map")continue;let s=n,r=e.x-s.x,o=e.y-s.y,h=Math.cos(s.rotation),l=Math.sin(s.rotation),c=r*h+o*l,d=-r*l+o*h,g=B(s.root);for(let[u,p]of g.positions)if(Math.abs(c-p.x)<=p.width/2&&Math.abs(d-p.y)<=p.height/2)return {shapeId:s.id,nodeId:u}}return null}selectMindMapNode(e,t){let i=this.shapes.find(n=>n.id===e);!i||i.type!=="mind-map"||(this.selectedIds=[e],this.mindMapSelectedNode={shapeId:e,nodeId:t},this.notifyListeners(),this.render());}getMindMapEditingShapeId(){return this.mindMapEditingShapeId}getMindMapSelectedNode(){return this.mindMapSelectedNode}getMindMapNode(e,t){let i=this.shapes.find(n=>n.id===e);return !i||i.type!=="mind-map"?null:Q(i.root,t)}getMindMapNodeScreenRect(e,t){let i=this.shapes.find(w=>w.id===e);if(!i||i.type!=="mind-map")return null;let n=i,r=B(n.root).positions.get(t);if(!r)return null;let o=this.camera.getZoom(),h=r.x,l=r.y,c=Math.cos(n.rotation),d=Math.sin(n.rotation),g=h*c-l*d,u=h*d+l*c,p=this.camera.pageToScreen({x:n.x,y:n.y}),y=p.x+g*o,f=p.y+u*o;return {x:y-r.width*o/2,y:f-r.height*o/2,width:r.width*o,height:r.height*o}}getMindMapCollapseHitAtPoint(e){for(let t of this.shapes){if(t.type!=="mind-map")continue;let i=t,n=B(i.root),s=e.x-i.x,r=e.y-i.y,o=Math.cos(i.rotation),h=Math.sin(i.rotation),l=s*o+r*h,c=-s*h+r*o;for(let[d,g]of n.positions){let u=Q(i.root,d);if(!u||!u.children||u.children.length===0)continue;let p=g.x+g.width/2+10,y=g.y,f=l-p,w=c-y;if(f*f+w*w<=121)return {shapeId:t.id,nodeId:d}}}return null}beginMindMapEdit(e,t){let i=this.shapes.find(s=>s.id===e);if(!i||i.type!=="mind-map")return;let n=i;this.mindMapEditingShapeId=e,this.mindMapSelectedNode={shapeId:e,nodeId:t&&Q(n.root,t)?t:n.root.id},this.selectedIds=[e],this.notifyListeners(),this.render();}exitMindMapEdit(){this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null,this.notifyListeners(),this.render();}updateMindMapNode(e,t,i,n=true){let s=this.shapes.findIndex(u=>u.id===e);if(s===-1)return;let r=this.shapes[s];if(r.type!=="mind-map")return;let o=r,h=Q(o.root,t);if(!h||!Object.keys(i).some(u=>h[u]!==i[u]))return;n&&this.commitHistory();let c=Re(o.root,t,i),{width:d,height:g}=B(c);this.shapes[s]={...o,root:c,width:d,height:g},this.notifyListeners(),this.render();}addMindMapChild(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n,r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:Z("mindmap.defaultBranch")},o=je(s.root,t,r);this.commitHistory();let{width:h,height:l}=B(o);this.shapes[i]={...s,root:o,width:h,height:l},this.mindMapSelectedNode={shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}addMindMapSibling(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n;if(!fe(s.root,t))return;let r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:Z("mindmap.defaultBranch")},o=qe(s.root,t,r);this.commitHistory();let{width:h,height:l}=B(o);this.shapes[i]={...s,root:o,width:h,height:l},this.mindMapSelectedNode={shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}deleteMindMapNode(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n;if(s.root.id===t){this.commitHistory(),this.shapes=this.shapes.filter(c=>c.id!==e),this.selectedIds=this.selectedIds.filter(c=>c!==e),this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null,this.notifyListeners(),this.render();return}let r=Je(s.root,t);if(!r)return;this.commitHistory();let{width:o,height:h}=B(r);this.shapes[i]={...s,root:r,width:o,height:h};let l=fe(s.root,t);this.mindMapSelectedNode=l?{shapeId:e,nodeId:l.id}:{shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}toggleMindMapCollapse(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n,r=Q(s.root,t);if(!r||!r.children||r.children.length===0)return;this.commitHistory();let o=Re(s.root,t,{collapsed:!r.collapsed}),{width:h,height:l}=B(o);this.shapes[i]={...s,root:o,width:h,height:l},this.notifyListeners(),this.render();}addUmlAttribute(e){let t=this.shapes.find(n=>n.id===e);if(!t||t.type!=="uml-class")return;let i={id:`attr_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,visibility:"+",name:"newField",type:"string"};this.updateUmlClass(e,{attributes:[...t.attributes,i]});}addUmlMethod(e){let t=this.getUmlById(e);if(!t)return;let i={id:`meth_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,visibility:"+",name:"newMethod",params:"",returnType:"void"};t.type==="uml-class"?this.updateUmlClass(e,{methods:[...t.methods,i]}):this.updateUmlInterface(e,{methods:[...t.methods,i]});}removeUmlAttribute(e,t){let i=this.shapes.find(n=>n.id===e);!i||i.type!=="uml-class"||this.updateUmlClass(e,{attributes:i.attributes.filter(n=>n.id!==t)});}removeUmlMethod(e,t){let i=this.getUmlById(e);if(!i)return;let n=i.methods.filter(s=>s.id!==t);i.type==="uml-class"?this.updateUmlClass(e,{methods:n}):this.updateUmlInterface(e,{methods:n});}reorderUmlAttribute(e,t,i){let n=this.shapes.find(o=>o.id===e);if(!n||n.type!=="uml-class"||t===i)return;let s=[...n.attributes];if(t<0||t>=s.length||i<0||i>=s.length)return;let[r]=s.splice(t,1);s.splice(i,0,r),this.updateUmlClass(e,{attributes:s});}reorderUmlMethod(e,t,i){let n=this.getUmlById(e);if(!n||t===i)return;let s=[...n.methods];if(t<0||t>=s.length||i<0||i>=s.length)return;let[r]=s.splice(t,1);s.splice(i,0,r),n.type==="uml-class"?this.updateUmlClass(e,{methods:s}):this.updateUmlInterface(e,{methods:s});}updateUmlRowStyle(e,t,i,n){let s=this.getUmlById(e);if(s)if(t==="attribute"){if(s.type!=="uml-class")return;let r=s.attributes.map(o=>o.id===i?{...o,textColor:n.textColor===null?void 0:n.textColor??o.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??o.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??o.strikethrough}:o);this.updateUmlClass(e,{attributes:r});}else {let r=s.methods.map(o=>o.id===i?{...o,textColor:n.textColor===null?void 0:n.textColor??o.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??o.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??o.strikethrough}:o);s.type==="uml-class"?this.updateUmlClass(e,{methods:r}):this.updateUmlInterface(e,{methods:r});}}getUmlRowAtScreenPoint(e){let t=this.camera.screenToPage(e);for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(n.type!=="uml-class"&&n.type!=="uml-interface")continue;let s=n.width/2,r=n.height/2;if(t.x<n.x-s||t.x>n.x+s||t.y<n.y-r||t.y>n.y+r)continue;let o=j,h=t.y-n.y;if(h>=-r&&h<=-r+o)return {shape:n,section:"className",rowIndex:-1,text:n.className};if(n.type==="uml-interface"){let p=-r+o,y=r;if(n.methods.length>0&&h>=p&&h<=y){let f=Math.floor((h-p-k)/$);if(f>=0&&f<n.methods.length){let w=n.methods[f];return {shape:n,section:"method",rowIndex:f,text:`${w.visibility} ${w.name}(${w.params}): ${w.returnType}`}}return {shape:n,section:"method",rowIndex:-1,text:""}}return {shape:n,section:"className",rowIndex:-1,text:n.className}}let l=n.attributes.length>0?n.attributes.length*$+k*2:k*2,c=-r+o,d=c+l;if(n.attributes.length>0&&h>=c&&h<=d){let p=Math.floor((h-c-k)/$);if(p>=0&&p<n.attributes.length){let y=n.attributes[p];return {shape:n,section:"attribute",rowIndex:p,text:`${y.visibility} ${y.name}: ${y.type}`}}return {shape:n,section:"attribute",rowIndex:-1,text:""}}let g=d,u=r;if(n.methods.length>0&&h>=g&&h<=u){let p=Math.floor((h-g-k)/$);if(p>=0&&p<n.methods.length){let y=n.methods[p];return {shape:n,section:"method",rowIndex:p,text:`${y.visibility} ${y.name}(${y.params}): ${y.returnType}`}}return {shape:n,section:"method",rowIndex:-1,text:""}}return {shape:n,section:"className",rowIndex:-1,text:n.className}}return null}setActiveTool(e){this.tools.has(e)&&(this.tools.get(this.activeTool)?.cancelTransient(),this.clearTransientPreview(),this.activeTool=e,this.eraserPoint=null,this.notifyListeners(),this.scheduleRender());}getActiveTool(){return this.activeTool}setHighlighterColor(e){let t=this.tools.get("highlighter");t instanceof ne&&t.setHighlighterColor(e);}getHighlighterColor(){let e=this.tools.get("highlighter");return e instanceof ne?e.getHighlighterColor():Ye}getShapes(){return [...this.shapes]}getData(){return {shapes:this.getShapes(),camera:{x:this.camera.x,y:this.camera.y,zoom:this.camera.zoom}}}setShapes(e){return Array.isArray(e)?(this.shapes=e.map(t=>({...t,style:{...t.style}})),this.selectedIds=[],this.undoStack=[],this.redoStack=[],this.notifyListeners(),this.render(),true):false}setTheme(e){Le(e),this.scheduleRender();}setLanguage(e){Ae(e);}getSelectedIds(){return [...this.selectedIds]}getCamera(){return this.camera}isPointerDown(){return this.pointerIsDown}getContentBounds(e=24){return Ce(this.shapes,e)}async exportImage(e,t={}){return lt(this.getShapes(),e,t)}async downloadImage(e="drawui",t="png",i={}){let n=await this.exportImage(t,i);ct(n,`${e}.${t}`);}zoomIn(){this.camera.zoomAt({x:window.innerWidth/2,y:window.innerHeight/2},1.2),this.scheduleRender(),this.notifyListeners();}zoomOut(){this.camera.zoomAt({x:window.innerWidth/2,y:window.innerHeight/2},.8),this.scheduleRender(),this.notifyListeners();}resetZoom(){this.camera.reset(),this.scheduleRender(),this.notifyListeners();}panBy(e,t){this.camera.translate(e,t),this.scheduleRender(),this.notifyListeners();}setCameraPosition(e,t){this.camera.x=e,this.camera.y=t,this.scheduleRender(),this.notifyListeners();}requestRender(){this.scheduleRender(),this.notifyListeners();}setShowGrid(e){this.renderer.setShowGrid(e),this.scheduleRender();}render(){this.renderer.render(this.shapes,this.camera,new Set(this.selectedIds),this.brushRect,this.snapGuides,this.connectingTargetId,this.genPreview,this.eraserPoint,this.mindMapSelectedNode,this.mindMapHoverNode,void 0,this.hoverAnchorShapeId);}scheduleRender(){this.renderScheduled||(this.renderScheduled=true,requestAnimationFrame(()=>{this.renderScheduled=false,this.render();}));}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeNotifications(e){return this.notificationListeners.add(e),()=>this.notificationListeners.delete(e)}notify(e){this.notificationListeners.forEach(t=>t(e));}notifyListeners(){this.notifyScheduled||(this.notifyScheduled=true,queueMicrotask(()=>{this.notifyScheduled=false,this.mindMapEditingShapeId&&!this.selectedIds.includes(this.mindMapEditingShapeId)&&(this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null),this.listeners.forEach(e=>e());}));}cloneShapes(e){return e.map(t=>{let i={...t,style:{...t.style}};return Array.isArray(t.points)&&(i.points=t.points.map(n=>({...n}))),t.startBinding&&(i.startBinding={...t.startBinding}),t.endBinding&&(i.endBinding={...t.endBinding}),t.root&&(i.root=$e(t.root)),i})}commitHistory(){if(this.isUndoing)return;let e={shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]};this.undoStack.push(e),this.undoStack.length>Nn&&this.undoStack.shift(),this.redoStack=[];}mark(){this.commitHistory();}undo(){if(this.undoStack.length!==0){this.isUndoing=true;try{this.redoStack.push({shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]});let e=this.undoStack.pop();this.shapes=this.cloneShapes(e.shapes),this.selectedIds=[...e.selectedIds];}finally{this.isUndoing=false;}this.notifyListeners(),this.render();}}redo(){if(this.redoStack.length!==0){this.isUndoing=true;try{this.undoStack.push({shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]});let e=this.redoStack.pop();this.shapes=this.cloneShapes(e.shapes),this.selectedIds=[...e.selectedIds];}finally{this.isUndoing=false;}this.notifyListeners(),this.render();}}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}saveToStorage(){if(!this.persist)return false;try{let e=JSON.stringify({version:1,shapes:this.shapes,savedAt:Date.now()});return localStorage.setItem(dt,e),this.notifyListeners(),this.notify(Z("save.success")),!0}catch(e){return console.error("\u4FDD\u5B58\u5931\u8D25:",e),this.notify(Z("save.fail")),false}}loadFromStorage(){if(!this.persist)return false;try{let e=localStorage.getItem(dt);if(!e)return !1;let t=JSON.parse(e);return t.shapes&&Array.isArray(t.shapes)?(this.shapes=t.shapes,this.selectedIds=[],this.undoStack=[],this.redoStack=[],this.notifyListeners(),this.scheduleRender(),!0):!1}catch(e){return console.error("\u52A0\u8F7D\u5931\u8D25:",e),false}}clearStorage(){localStorage.removeItem(dt);}exportJSON(){return JSON.stringify({version:1,shapes:this.shapes,savedAt:Date.now()},null,2)}importJSON(e){try{let t=JSON.parse(e);return t.shapes&&Array.isArray(t.shapes)?(this.commitHistory(),this.shapes=t.shapes,this.selectedIds=[],this.notifyListeners(),this.render(),!0):!1}catch(t){return console.error("\u5BFC\u5165\u5931\u8D25:",t),false}}getEditingShapeId(){return this.editingShapeId}canEditShape(e){return !(e.type==="line"||e.type==="arrow"||e.type==="draw"||e.type==="uml-class"||e.type==="uml-interface"||e.type==="mind-map")}enterEditing(e){let t=this.shapes.find(i=>i.id===e);!t||!this.canEditShape(t)||(this.editingShapeId=e,this.selectedIds=[e],this.isNewTextShape=t.type==="text"&&!t.text,this.originalTextValue=t.text||"",this.notifyListeners(),this.scheduleRender(),requestAnimationFrame(()=>{this.createTextInput(t);}));}exitEditing(){if(!this.editingShapeId)return;let e=this.editingShapeId,t=this.shapes.find(n=>n.id===e),i=this.textInput?this.textInput.value:"";if(this.removeTextInput(),t)if(t.type==="text")if(this.commitHistory(),!i.trim()&&this.isNewTextShape)this.shapes=this.shapes.filter(n=>n.id!==e),this.selectedIds=this.selectedIds.filter(n=>n!==e);else {let n=t,s=n.fontSize||16,r=s*1.3,o=n.width||200,h=i.split(`
42
- `),l=0;for(let g of h){let u="";for(let p of g){let y=u+p;y.length*s*.6>o&&u?(l++,u=p):u=y;}u&&l++;}let c={...n,text:i,height:Math.max(l*r,r)},d=this.shapes.indexOf(t);d!==-1&&(this.shapes[d]=c),i.trim()||(this.shapes=this.shapes.filter(g=>g.id!==e),this.selectedIds=this.selectedIds.filter(g=>g!==e));}else this.commitHistory(),this.updateShape(e,{text:i,textColor:t.textColor||D.text,fontSize:t.fontSize||16});this.editingShapeId=null,this.isNewTextShape=false,this.originalTextValue="",this.setActiveTool("select"),this.notifyListeners(),this.render();}removeTextInput(){this.textOverlay&&(this.textOverlay.remove(),this.textOverlay=null),this.textInput&&(this.textInput.remove(),this.textInput=null);}createTextInput(e){this.removeTextInput();let t=this.canvas.parentElement;if(!t)return;let i=this.canvas.getBoundingClientRect(),n=t.getBoundingClientRect(),s=i.left-n.left,r=i.top-n.top;this.textOverlay=document.createElement("div"),this.textOverlay.style.position="absolute",this.textOverlay.style.left=`${s}px`,this.textOverlay.style.top=`${r}px`,this.textOverlay.style.width=`${i.width}px`,this.textOverlay.style.height=`${i.height}px`,this.textOverlay.style.background="transparent",this.textOverlay.style.zIndex="1000",this.textOverlay.style.cursor="text",this.textOverlay.addEventListener("pointerdown",d=>{this.textInput&&d.target!==this.textInput&&(d.preventDefault(),this.exitEditing());}),t.appendChild(this.textOverlay);let o=this.getShapeScreenBounds(e),h=this.camera.getZoom(),l=(e.fontSize||16)*h,c=document.createElement("textarea");c.style.position="absolute",c.style.left=`${s+o.x}px`,c.style.top=`${r+o.y}px`,c.style.width=`${Math.max(o.width,60)}px`,c.style.height=`${Math.max(o.height,24)}px`,c.style.fontSize=`${l}px`,c.style.color=e.textColor||"#1f2937",c.style.textAlign="center",c.style.border=`2px solid ${D.editBorder}`,c.style.borderRadius="4px",c.style.background="rgba(255, 255, 255, 0.95)",c.style.resize="none",c.style.padding="4px 8px",c.style.boxSizing="border-box",c.style.lineHeight="1.4",c.style.fontFamily="sans-serif",c.style.outline="none",c.style.whiteSpace="pre-wrap",c.style.wordBreak="break-word",c.style.overflow="hidden",c.style.zIndex="1001",c.value=e.text||"",c.dataset.shapeId=e.id,c.addEventListener("pointerdown",d=>{d.stopPropagation();}),c.addEventListener("mousedown",d=>{d.stopPropagation();}),c.addEventListener("keydown",d=>{if(d.stopPropagation(),d.key==="Escape"&&(d.preventDefault(),this.textInput&&(this.textInput.value=this.originalTextValue),this.exitEditing()),d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),this.exitEditing()),d.key==="Enter"&&d.shiftKey){d.preventDefault();let g=c.selectionStart,u=c.selectionEnd;c.value=c.value.substring(0,g)+`
43
- `+c.value.substring(u),c.selectionStart=c.selectionEnd=g+1;}}),t.appendChild(c),c.focus(),e.type==="text"&&!e.text&&(c.placeholder="\u8F93\u5165\u6587\u672C..."),this.textInput=c;}getShapeScreenBounds(e){let t=this.camera.getZoom(),i=this.camera.pageToScreen({x:e.x,y:e.y});switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":return {x:i.x-e.width*t/2,y:i.y-e.height*t/2,width:e.width*t,height:e.height*t};case "circle":return {x:i.x-e.radius*t,y:i.y-e.radius*t,width:e.radius*2*t,height:e.radius*2*t};case "text":{let n=e,s=n.width*t,r=n.height*t;return {x:i.x-s/2,y:i.y-r/2,width:s,height:r}}default:return {x:i.x-50*t,y:i.y-20*t,width:100*t,height:40*t}}}getShapeAtScreenPoint(e){let t=this.screenToPage(e);return this.getShapeAtPoint(t)}getShapeAtPoint(e,t){for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(!(t&&n.id===t)&&this.isPointInShape(e,n))return n}return null}getShapesInBrushRadius(e,t){let i=[];for(let n of this.shapes)this.shapeIntersectsBrush(n,e,t)&&i.push(n);return i}shapeIntersectsBrush(e,t,i){switch(e.type){case "line":case "arrow":{let n=e.points,s=i+4;for(let r=1;r<n.length;r++)if(this.pointToSegmentDist(t,n[r-1],n[r])<=s)return true;return n.length>0&&Math.hypot(t.x-n[0].x,t.y-n[0].y)<=s}case "draw":{let n=e.points,s=i+4;for(let r=1;r<n.length;r++){let o={x:e.x+n[r-1].x,y:e.y+n[r-1].y},h={x:e.x+n[r].x,y:e.y+n[r].y};if(this.pointToSegmentDist(t,o,h)<=s)return true}return n.length>0&&Math.hypot(t.x-(e.x+n[0].x),t.y-(e.y+n[0].y))<=s}case "circle":return Math.hypot(t.x-e.x,t.y-e.y)<=e.radius+i;case "text":{let n=e;return Math.abs(t.x-e.x)<=n.width/2+i&&Math.abs(t.y-e.y)<=n.height/2+i}default:return Math.abs(t.x-e.x)<=e.width/2+i&&Math.abs(t.y-e.y)<=e.height/2+i}}pointToSegmentDist(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=n*n+s*s,o=r===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*s)/r));return Math.hypot(e.x-(t.x+o*n),e.y-(t.y+o*s))}setEraserPoint(e){this.eraserPoint=e,this.scheduleRender();}isPointInShape(e,t){let i=e.x-t.x,n=e.y-t.y;switch(t.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "circle":return i*i+n*n<=t.radius*t.radius;case "hexagon":{let s=t.width/2,r=t.height/2;return Math.abs(i)<=s&&Math.abs(n)<=r&&Math.abs(i)/s+Math.abs(n)/r<=1.5}case "mind-map":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "text":{let s=t;return Math.abs(i)<=s.width/2&&Math.abs(n)<=s.height/2}default:return false}}updateArrowBinding(e,t,i,n){let s=this.shapes.find(h=>h.id===e);if(!s||s.type!=="arrow")return;let r=s,o={};if(i){let h=this.shapes.find(g=>g.id===i);if(!h)return;let l=n?.handle||this.getClosestHandle(r,h),c=this.getBindingPosition(h,l),d=n?{...n,toShapeId:i}:{toShapeId:i,handle:l,auto:true};t==="start"?(o.startBinding=d,o.points=r.points.map((g,u)=>u===0?c:g)):(o.endBinding=d,o.points=r.points.map((g,u)=>u===r.points.length-1?c:g));}else t==="start"?o.startBinding=void 0:o.endBinding=void 0;this.updateShape(e,o);}getClosestHandle(e,t){let i=e.points[0],n=e.points[e.points.length-1],s=e.endBinding?n:i,r=s.x-t.x,o=s.y-t.y;return Math.abs(r)>Math.abs(o)?r>0?"right":"left":o>0?"bottom":"top"}dispose(){this.canvas.removeEventListener("pointerdown",this.handlePointerDown),this.canvas.removeEventListener("pointerleave",this.handlePointerUp),window.removeEventListener("pointermove",this.handlePointerMove),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),window.removeEventListener("blur",this.handleWindowBlur),window.removeEventListener("pointerdown",this.handleGlobalPointerDown,true),this.canvas.removeEventListener("wheel",this.handleWheel),window.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("keyup",this.handleKeyUp),window.removeEventListener("resize",this.handleResize),this.removeTextInput(),this.tools.forEach(e=>e.dispose()),this.listeners.clear();}};exports.ArrowTool=Pe;exports.Camera=re;exports.DEFAULT_HIGHLIGHTER_COLOR=Ye;exports.Editor=ut;exports.FreehandTool=ne;exports.HandTool=Me;exports.LineTool=ve;exports.MINDMAP_COLORS=Ze;exports.MINDMAP_FONT_SIZE=J;exports.MINDMAP_MAX_WIDTH=_t;exports.MINDMAP_MIN_WIDTH=Bt;exports.MINDMAP_NODE_HEIGHT=Nt;exports.Mat2d=q;exports.Renderer=ae;exports.SelectTool=Se;exports.ShapeTool=T;exports.THEME=D;exports.UML_FONT_SIZE=U;exports.UML_HEADER_HEIGHT=j;exports.UML_LINE_HEIGHT=$;exports.UML_MIN_WIDTH=me;exports.UML_PADDING_X=O;exports.UML_PADDING_Y=k;exports.Vec=he;exports.calcUmlClassSize=Ve;exports.cloneMindMapNode=$e;exports.countMindMapNodes=xt;exports.downloadBlob=ct;exports.exportToBlob=lt;exports.findMindMapNode=Q;exports.getContentBounds=Ce;exports.getLanguage=Ht;exports.getMindMapNodeDepth=mt;exports.getMindMapParent=fe;exports.getTheme=$t;exports.hexToRgba=F;exports.layoutMindMap=B;exports.mindMapNodeColor=oe;exports.mindMapNodeSize=ft;exports.renderSVGString=Lt;exports.renderToCanvas=Dt;exports.setLanguage=Ae;exports.setTheme=Le;exports.shadeColor=Rt;exports.subscribeLanguage=Vt;exports.subscribeTheme=At;exports.t=Z;
40
+ ${w+y.length}
41
+ %%EOF`;return new Blob([f+c+d+u+g,s,p+y+b],{type:"application/pdf"})}async function it(a,e,t={}){if(e==="svg"){let s=Tt(a,t);return new Blob([s],{type:"image/svg+xml;charset=utf-8"})}let i=Ct(a,t);if(e==="png")return fn(i,"image/png");let n=mn(i,"image/jpeg",.92);return An(n,i.width,i.height)}function st(a,e){let t=URL.createObjectURL(a),i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(t),1e3);}var rt="drawui-canvas-data",Hn=50,ot=class{canvas;renderer;camera;tools=new Map;activeTool="select";shapes=[];selectedIds=[];listeners=new Set;notificationListeners=new Set;uiListeners=new Set;isPanning=false;panStart={x:0,y:0};dragStartPositions=new Map;lastClickTime=0;lastClickShapeId=null;editingShapeId=null;textInput=null;textOverlay=null;isNewTextShape=false;originalTextValue="";undoStack=[];redoStack=[];isUndoing=false;brushRect=null;snapGuides=[];connectingTargetId=null;genPreview=null;hoverAnchorShapeId=null;hoverConnectorId=null;eraserPoint=null;mindMapEditingShapeId=null;mindMapSelectedNode=null;mindMapHoverNode=null;renderScheduled=false;pointerIsDown=false;notifyScheduled=false;persist=true;arrowStyle={connectionType:"straight",arrowHead:"end",dashed:false};constructor(e,t={}){this.canvas=e,this.persist=t.persist??!t.shapes,t.theme&&be(t.theme),t.language&&ve(t.language);let i=e.getBoundingClientRect();this.renderer=new q(e),this.renderer.resize(i.width,i.height),this.camera=new Z;let n={addShape:s=>this.addShape(s),updateShape:(s,r)=>this.updateShape(s,r),deleteShape:s=>this.deleteShape(s),selectShape:(s,r)=>this.selectShape(s,r),selectShapes:s=>this.selectShapes(s),getShapes:()=>[...this.shapes],getSelectedIds:()=>[...this.selectedIds],setActiveTool:s=>this.setActiveTool(s),screenToPage:s=>this.screenToPage(s),getCamera:()=>this.camera,panBy:(s,r)=>this.panBy(s,r),setCameraPosition:(s,r)=>this.setCameraPosition(s,r),getShapeAtPoint:(s,r)=>this.getShapeAtPoint(s,r),getShapesInBrushRadius:(s,r)=>this.getShapesInBrushRadius(s,r),setEraserPoint:s=>this.setEraserPoint(s),updateArrowBinding:(s,r,o,h)=>this.updateArrowBinding(s,r,o,h),enterEditing:s=>this.enterEditing(s),exitEditing:()=>this.exitEditing(),commitHistory:()=>this.commitHistory(),setBrushRect:s=>this.setBrushRect(s),setSnapGuides:s=>this.setSnapGuides(s),setConnectingTarget:s=>this.setConnectingTarget(s),setGenerationPreview:s=>this.setGenerationPreview(s),setHoverAnchorShape:s=>this.setHoverAnchorShape(s),setHoverConnector:s=>this.setHoverConnector(s),getConnectorRoute:s=>this.getConnectorRoute(s),getLineStyle:()=>this.lineStyle(),openGenerationMenu:s=>this.openGenerationMenu(s),createGeneratedConnection:(s,r)=>this.createGeneratedConnection(s,r),createFloatingLine:s=>this.createFloatingLine(s),connectToExisting:(s,r,o)=>this.connectToExisting(s,r,o),updateSelectedShapesStyle:s=>this.updateSelectedShapesStyle(s),updateSelectedShapesText:s=>this.updateSelectedShapesText(s),updateConnectionType:s=>this.updateConnectionType(s),getArrowStyle:()=>this.getArrowStyle(),getMindMapCursorHitAtPoint:s=>this.getMindMapCursorHitAtPoint(s),selectMindMapNode:(s,r)=>this.selectMindMapNode(s,r)};this.tools.set("select",new ue(n)),this.tools.set("hand",new ge(n)),this.tools.set("rectangle",new P(n,"rectangle")),this.tools.set("rounded-rectangle",new P(n,"rounded-rectangle")),this.tools.set("circle",new P(n,"circle")),this.tools.set("ellipse",new P(n,"ellipse")),this.tools.set("diamond",new P(n,"diamond")),this.tools.set("triangle",new P(n,"triangle")),this.tools.set("hexagon",new P(n,"hexagon")),this.tools.set("parallelogram",new P(n,"parallelogram")),this.tools.set("trapezoid",new P(n,"trapezoid")),this.tools.set("pentagon",new P(n,"pentagon")),this.tools.set("octagon",new P(n,"octagon")),this.tools.set("star",new P(n,"star")),this.tools.set("cylinder",new P(n,"cylinder")),this.tools.set("cloud",new P(n,"cloud")),this.tools.set("heart",new P(n,"heart")),this.tools.set("block-arrow-right",new P(n,"block-arrow-right")),this.tools.set("block-arrow-left",new P(n,"block-arrow-left")),this.tools.set("block-arrow-up",new P(n,"block-arrow-up")),this.tools.set("block-arrow-down",new P(n,"block-arrow-down")),this.tools.set("block-arrow-double",new P(n,"block-arrow-double")),this.tools.set("right-triangle",new P(n,"right-triangle")),this.tools.set("cross",new P(n,"cross")),this.tools.set("speech-rect",new P(n,"speech-rect")),this.tools.set("speech-round",new P(n,"speech-round")),this.tools.set("cube",new P(n,"cube")),this.tools.set("sector",new P(n,"sector")),this.tools.set("delay",new P(n,"delay")),this.tools.set("predefined-process",new P(n,"predefined-process")),this.tools.set("document",new P(n,"document")),this.tools.set("stadium",new P(n,"stadium")),this.tools.set("class-catalog",new P(n,"class-catalog")),this.tools.set("chevron",new P(n,"chevron")),this.tools.set("brace-left",new P(n,"brace-left")),this.tools.set("brace-right",new P(n,"brace-right")),this.tools.set("uml-class",new P(n,"uml-class")),this.tools.set("uml-interface",new P(n,"uml-interface")),this.tools.set("line",new pe(n)),this.tools.set("arrow",new ye(n)),this.tools.set("text",new Re(n)),this.tools.set("pen",new X(n,"pen")),this.tools.set("highlighter",new X(n,"highlighter")),this.tools.set("eraser",new Le(n)),this.tools.set("mind-map",new P(n,"mind-map")),this.setupEventListeners(),t.shapes?this.shapes=t.shapes.map(s=>({...s,style:{...s.style}})):this.persist&&this.loadFromStorage(),this.render();}setupEventListeners(){this.canvas.addEventListener("pointerdown",this.handlePointerDown),this.canvas.addEventListener("pointerleave",this.handlePointerUp),window.addEventListener("pointermove",this.handlePointerMove),window.addEventListener("pointerup",this.handlePointerUp),window.addEventListener("pointercancel",this.handlePointerUp),window.addEventListener("blur",this.handleWindowBlur),window.addEventListener("pointerdown",this.handleGlobalPointerDown,true),this.canvas.addEventListener("wheel",this.handleWheel,{passive:false}),window.addEventListener("keydown",this.handleKeyDown),window.addEventListener("keyup",this.handleKeyUp),window.addEventListener("resize",this.handleResize);}handleWindowBlur=()=>{this.pointerIsDown=false,this.isPanning=false,this.cancelTransientInteraction(),this.scheduleRender();};handleGlobalPointerDown=e=>{e.target!==this.canvas&&(!e.isPrimary||e.button!==0||(this.pointerIsDown=false,this.isPanning=false,this.cancelTransientInteraction()&&this.scheduleRender()));};shouldRecoverTransient(){let e=this.tools.get(this.activeTool);return !!this.connectingTargetId||this.snapGuides.length>0||!!this.brushRect||!!e&&e.hasTransientState()}cancelTransientInteraction(){let e=!!this.tools.get(this.activeTool)?.cancelTransient(),t=this.clearTransientPreview();return e||t}handlePointerDown=e=>{if(this.editingShapeId)return this.textInput&&e.target===this.textInput,void 0;this.clearTransientPreview(),this.pointerIsDown=true;try{this.canvas.hasPointerCapture(e.pointerId)||this.canvas.setPointerCapture(e.pointerId);}catch{}if(e.button===1||e.button===0&&e.altKey){this.isPanning=true,this.panStart={x:e.clientX,y:e.clientY},this.canvas.setPointerCapture(e.pointerId),this.canvas.style.cursor="grabbing";return}let t=this.screenToPage({x:e.clientX,y:e.clientY}),i=this.activeTool==="select"?this.getMindMapCollapseHitAtPoint(t):null;if(i){this.toggleMindMapCollapse(i.shapeId,i.nodeId);return}if(this.activeTool==="select"){let s=Date.now(),r=this.getShapeAtPoint(t);if(s-this.lastClickTime<400&&this.lastClickShapeId&&r&&r.id===this.lastClickShapeId&&this.canEditShape(r)){this.enterEditing(r.id),this.lastClickTime=0,this.lastClickShapeId=null;return}if(this.lastClickTime=s,this.lastClickShapeId=r?.id||null,r&&r.type==="mind-map"&&this.mindMapEditingShapeId===r.id){let o=this.getMindMapNodeAtPoint(t);o&&(this.mindMapSelectedNode=o,this.notifyListeners(),this.render());return}r&&(this.dragStartPositions.clear(),this.selectedIds.forEach(o=>{let h=this.shapes.find(l=>l.id===o);h&&this.dragStartPositions.set(o,{x:h.x,y:h.y});}));}this.tools.get(this.activeTool)?.onPointerDown(t,e),this.updateCursor(t),this.render();};handlePointerMove=e=>{if(this.editingShapeId||(e.buttons===0&&this.pointerIsDown&&(this.pointerIsDown=false,this.shouldRecoverTransient()&&(this.cancelTransientInteraction(),this.scheduleRender())),!this.pointerIsDown&&this.shouldRecoverTransient()&&this.cancelTransientInteraction(),!this.pointerIsDown&&e.target!==this.canvas))return;if(this.isPanning){let n=e.clientX-this.panStart.x,s=e.clientY-this.panStart.y;this.camera.translate(n,s),this.panStart={x:e.clientX,y:e.clientY},this.scheduleRender(),this.notifyListeners();return}let t=this.screenToPage({x:e.clientX,y:e.clientY});this.tools.get(this.activeTool)?.onPointerMove(t,e),this.updateCursor(t),this.scheduleRender();};handlePointerUp=e=>{if(e.type==="pointerleave"){if(this.mindMapHoverNode=null,this.pointerIsDown){this.scheduleRender();return}}else {if(!this.pointerIsDown&&e.target!==this.canvas)return;this.canvas.hasPointerCapture(e.pointerId)&&this.canvas.releasePointerCapture(e.pointerId);}if(this.pointerIsDown=false,this.editingShapeId)return;if(this.isPanning){this.isPanning=false,this.updateCursor(this.screenToPage({x:e.clientX,y:e.clientY}));return}let t=this.screenToPage({x:e.clientX,y:e.clientY});this.tools.get(this.activeTool)?.onPointerUp(t,e),this.updateCursor(t),this.scheduleRender();};updateCursor(e){let i=this.tools.get(this.activeTool)?.getCursor(e)??"default";if(this.canvas.style.cursor!==i&&(this.canvas.style.cursor=i),!this.pointerIsDown){let n=this.getMindMapCursorHitAtPoint(e);(n?.shapeId!==this.mindMapHoverNode?.shapeId||n?.nodeId!==this.mindMapHoverNode?.nodeId)&&(this.mindMapHoverNode=n,this.scheduleRender());}}handleWheel=e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let n=e.deltaY>0?.9:1.1;this.camera.zoomAt({x:e.clientX,y:e.clientY},n),this.scheduleRender(),this.notifyListeners();return}let t=e.deltaX||0,i=e.deltaY||0;e.deltaMode===1?(t*=40,i*=40):e.deltaMode===2&&(t*=120,i*=120),e.shiftKey&&(t=t||i,i=0),this.camera.translate(-t,-i),this.scheduleRender(),this.notifyListeners();};handleKeyDown=e=>{if(this.editingShapeId)return;if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="z"){e.preventDefault(),e.shiftKey?this.redo():this.undo();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="y"){e.preventDefault(),this.redo();return}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==="s"){e.preventDefault(),this.saveToStorage();return}if(!e.ctrlKey&&!e.metaKey&&!e.altKey){if(e.key==="v"||e.key==="V"){this.setActiveTool("select"),e.preventDefault();return}if(e.key==="h"||e.key==="H"){this.setActiveTool("hand"),e.preventDefault();return}}this.tools.get(this.activeTool)?.onKeyDown(e),this.scheduleRender();};handleKeyUp=e=>{if(this.editingShapeId)return;this.tools.get(this.activeTool)?.onKeyUp(e),this.scheduleRender();};handleResize=()=>{this.renderer.resize(window.innerWidth,window.innerHeight),this.scheduleRender();};screenToPage(e){let t=this.canvas.getBoundingClientRect();return this.camera.screenToPage({x:e.x-t.left,y:e.y-t.top})}addShape(e){this.shapes.push(e),this.notifyListeners();}updateShape(e,t){let i=this.shapes.findIndex(n=>n.id===e);i!==-1&&(this.shapes[i]={...this.shapes[i],...t},(t.x!==void 0||t.y!==void 0)&&this.updateBoundArrows(e),this.notifyListeners());}updateBoundArrows(e){let t=this.shapes.find(i=>i.id===e);t&&this.shapes.forEach(i=>{if(i.type==="arrow"){let n=i,s={};if(n.startBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.startBinding.handle||"top");s.points=n.points.map((o,h)=>h===0?r:o);}if(n.endBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.endBinding.handle||"top"),o=s.points||[...n.points];s.points=o.map((h,l)=>l===o.length-1?r:h);}s.points&&(this.shapes[this.shapes.indexOf(i)]={...n,...s});}});}getBindingPosition(e,t){switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}case "circle":switch(t){case "top":return {x:e.x,y:e.y-e.radius};case "bottom":return {x:e.x,y:e.y+e.radius};case "left":return {x:e.x-e.radius,y:e.y};case "right":return {x:e.x+e.radius,y:e.y}}case "hexagon":switch(t){case "top":return {x:e.x,y:e.y-e.height/2};case "bottom":return {x:e.x,y:e.y+e.height/2};case "left":return {x:e.x-e.width/2,y:e.y};case "right":return {x:e.x+e.width/2,y:e.y}}default:return {x:e.x,y:e.y}}}deleteShape(e){this.shapes=this.shapes.filter(t=>t.id!==e),this.selectedIds=this.selectedIds.filter(t=>t!==e),this.shapes=this.shapes.map(t=>{if(t.type==="arrow"){let i=t;if(i.startBinding?.toShapeId===e)return {...i,startBinding:void 0};if(i.endBinding?.toShapeId===e)return {...i,endBinding:void 0}}return t}),this.notifyListeners(),this.scheduleRender();}selectShape(e,t){if(!e)this.selectedIds=[];else if(t){let i=this.selectedIds.indexOf(e);i===-1?this.selectedIds.push(e):this.selectedIds.splice(i,1);}else this.selectedIds=[e];this.notifyListeners(),this.scheduleRender();}selectShapes(e){this.selectedIds=[...e],this.notifyListeners(),this.scheduleRender();}setBrushRect(e){this.brushRect=e,this.scheduleRender();}setSnapGuides(e){this.snapGuides=e;}setConnectingTarget(e){this.connectingTargetId!==e&&(this.connectingTargetId=e,this.scheduleRender());}setGenerationPreview(e){let t=this.genPreview;t?.from.x===e?.from.x&&t?.from.y===e?.from.y&&t?.to.x===e?.to.x&&t?.to.y===e?.to.y&&t?.type===e?.type&&t?.targetShapeId===e?.targetShapeId&&t?.dragging===e?.dragging&&t?.sourceEdge===e?.sourceEdge||(this.genPreview=e,this.scheduleRender());}setHoverAnchorShape(e){this.hoverAnchorShapeId!==e&&(this.hoverAnchorShapeId=e,this.scheduleRender());}setHoverConnector(e){this.hoverConnectorId!==e&&(this.hoverConnectorId=e,this.scheduleRender());}getConnectorRoute(e){let t=this.shapes.find(n=>n.id===e);if(!t)return [];let i=new Map(this.shapes.map(n=>[n.id,n]));return this.renderer.getConnectorRoute(t,i)}clearTransientPreview(){return !!this.genPreview||!!this.connectingTargetId||this.snapGuides.length>0||!!this.brushRect||!!this.hoverAnchorShapeId||!!this.hoverConnectorId?(this.genPreview=null,this.connectingTargetId=null,this.snapGuides=[],this.brushRect=null,this.hoverAnchorShapeId=null,this.hoverConnectorId=null,true):false}openGenerationMenu(e){let t=this.camera.getZoom(),i=(e.context.to.x+this.camera.x)*t,n=(e.context.to.y+this.camera.y)*t;this.emitUi({kind:"shapeTypeMenu",screenX:i,screenY:n,context:e.context,existingArrowId:e.existingArrowId,defaultShapeType:e.defaultShapeType});}lineStyle(){return {strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null}}computeSourceBinding(e){if(!e.sourceShapeId||!e.edge)return;let t=this.shapes.find(n=>n.id===e.sourceShapeId);if(!t)return;let i={n:"top",e:"right",s:"bottom",w:"left"};return {toShapeId:t.id,handle:i[e.edge]}}connectHandle(e,t,i){return De(e,t,i)}createFloatingLine(e){this.commitHistory();let t=e.from,i=e.to,n=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,s={id:n,type:"arrow",x:t.x,y:t.y,points:[{x:t.x,y:t.y},{x:i.x,y:i.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};return this.addShape(s),this.selectedIds=[n],this.notifyListeners(),this.render(),n}createGeneratedConnection(e,t){this.commitHistory();let i=t.type,n;if(e.sourceShapeId){let h=this.shapes.find(l=>l.id===e.sourceShapeId);h&&Ie(h.type)&&(n={...h.style});}let s=Y(i,e.to,n);this.addShape(s);let r=e.from,o={toShapeId:s.id,handle:this.connectHandle(r,e.to,e.edge),auto:true};if(t.existingArrowId)this.updateArrowBinding(t.existingArrowId,"end",s.id,{toShapeId:s.id,handle:this.connectHandle(r,e.to,e.edge),auto:true});else {let l={id:`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,type:"arrow",x:r.x,y:r.y,points:[{x:r.x,y:r.y},{x:e.to.x,y:e.to.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),endBinding:o,connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};this.addShape(l);}this.selectedIds=[s.id],this.notifyListeners(),this.render();}connectToExisting(e,t,i){this.commitHistory();let n=this.shapes.find(c=>c.id===t);if(!n)return;let s=e.from,r=i?.handle??this.connectHandle(s,{x:n.x,y:n.y},e.edge),o=this.getBindingPosition(n,r),h=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,l={id:h,type:"arrow",x:s.x,y:s.y,points:[{x:s.x,y:s.y},{x:o.x,y:o.y}],rotation:0,style:this.lineStyle(),startBinding:this.computeSourceBinding(e),endBinding:{toShapeId:t,handle:r,auto:!i||!i.handle&&!i.isPrecise},connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};this.addShape(l),this.selectedIds=[h],this.notifyListeners(),this.render();}subscribeUi(e){return this.uiListeners.add(e),()=>this.uiListeners.delete(e)}emitUi(e){this.uiListeners.forEach(t=>t(e));}updateSelectedShapesStyle(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);i!==-1&&(this.shapes[i]={...this.shapes[i],style:{...this.shapes[i].style,...e}});}),this.notifyListeners(),this.render());}updateSelectedShapesText(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);i!==-1&&(this.shapes[i]={...this.shapes[i],...e});}),this.notifyListeners(),this.render());}updateConnectionType(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);if(i!==-1){let n=this.shapes[i];(n.type==="line"||n.type==="arrow")&&(this.shapes[i]={...n,connectionType:e});}}),this.notifyListeners(),this.render());}updateArrowHeadType(e){if(this.selectedIds.length===0)return;this.commitHistory();let t=e==="dependency"||e==="realization";this.selectedIds.forEach(i=>{let n=this.shapes.findIndex(s=>s.id===i);if(n!==-1){let s=this.shapes[n];s.type==="arrow"&&(this.shapes[n]=t?{...s,arrowHead:e,dashed:true}:{...s,arrowHead:e});}}),this.notifyListeners(),this.render();}updateArrowStyle(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(o=>o.id===t);if(i===-1)return;let n=this.shapes[i];if(n.type!=="arrow")return;let s=e.arrowHead??n.arrowHead??"end",r=s==="dependency"||s==="realization";this.shapes[i]={...n,...e,arrowHead:s,dashed:r?true:e.dashed??n.dashed??false};}),this.notifyListeners(),this.render());}getArrowStyle(){return {...this.arrowStyle}}setArrowStyle(e){let t={...this.arrowStyle,...e};(t.arrowHead==="dependency"||t.arrowHead==="realization")&&(t.dashed=true),this.arrowStyle=t,this.notifyListeners();}updateArrowDashed(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(n=>n.id===t);if(i!==-1){let n=this.shapes[i];n.type==="arrow"&&(this.shapes[i]={...n,dashed:e});}}),this.notifyListeners(),this.render());}updateUmlClass(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="uml-class")return;this.commitHistory();let s=t.className??n.className,r=t.attributes??n.attributes,o=t.methods??n.methods,{width:h,height:l}=Te(s,r,o);this.shapes[i]={...n,className:s,attributes:r,methods:o,width:h,height:l},this.notifyListeners(),this.render();}updateUmlInterface(e,t){let i=this.shapes.findIndex(p=>p.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="uml-interface")return;this.commitHistory();let s=n,r=t.className??s.className,o=t.methods??s.methods,h=$*.6,l=o.map(p=>`${p.visibility} ${p.name}(${p.params}): ${p.returnType}`),c=Math.max(r.length,...l.map(p=>p.length),0),d=Math.max(he,c*h+H*2),u=o.length>0?o.length*D+T*2:T*2,g=_+u;this.shapes[i]={...n,className:r,methods:o,width:d,height:g},this.notifyListeners(),this.render();}getSelectedUml(){if(this.selectedIds.length!==1)return null;let e=this.shapes.find(t=>t.id===this.selectedIds[0]);return e&&(e.type==="uml-class"||e.type==="uml-interface")?e:null}getUmlById(e){let t=this.shapes.find(i=>i.id===e);return t&&(t.type==="uml-class"||t.type==="uml-interface")?t:null}getSelectedMindMap(){if(this.selectedIds.length!==1)return null;let e=this.shapes.find(t=>t.id===this.selectedIds[0]);return e&&e.type==="mind-map"?e:null}getMindMapNodeAtPoint(e){for(let t=this.shapes.length-1;t>=0;t--){let i=this.shapes[t];if(i.type!=="mind-map")continue;let n=i,s=e.x-n.x,r=e.y-n.y,o=Math.cos(n.rotation),h=Math.sin(n.rotation),l=s*o+r*h,c=-s*h+r*o;if(Math.abs(l)>n.width/2||Math.abs(c)>n.height/2)continue;let d=k(n.root);for(let[u,g]of d.positions)if(Math.abs(l-g.x)<=g.width/2&&Math.abs(c-g.y)<=g.height/2)return {shapeId:n.id,nodeId:u};return {shapeId:n.id,nodeId:n.root.id}}return null}getMindMapNodeAtScreenPoint(e){return this.getMindMapNodeAtPoint(this.screenToPage(e))}getMindMapCursorHitAtPoint(e){let t=this.getMindMapCollapseHitAtPoint(e);if(t)return t;for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(n.type!=="mind-map")continue;let s=n,r=e.x-s.x,o=e.y-s.y,h=Math.cos(s.rotation),l=Math.sin(s.rotation),c=r*h+o*l,d=-r*l+o*h,u=k(s.root);for(let[g,p]of u.positions)if(Math.abs(c-p.x)<=p.width/2&&Math.abs(d-p.y)<=p.height/2)return {shapeId:s.id,nodeId:g}}return null}selectMindMapNode(e,t){let i=this.shapes.find(n=>n.id===e);!i||i.type!=="mind-map"||(this.selectedIds=[e],this.mindMapSelectedNode={shapeId:e,nodeId:t},this.notifyListeners(),this.render());}getMindMapEditingShapeId(){return this.mindMapEditingShapeId}getMindMapSelectedNode(){return this.mindMapSelectedNode}getMindMapNode(e,t){let i=this.shapes.find(n=>n.id===e);return !i||i.type!=="mind-map"?null:z(i.root,t)}getMindMapNodeScreenRect(e,t){let i=this.shapes.find(S=>S.id===e);if(!i||i.type!=="mind-map")return null;let n=i,r=k(n.root).positions.get(t);if(!r)return null;let o=this.camera.getZoom(),h=r.x,l=r.y,c=Math.cos(n.rotation),d=Math.sin(n.rotation),u=h*c-l*d,g=h*d+l*c,p=this.camera.pageToScreen({x:n.x,y:n.y}),y=p.x+u*o,f=p.y+g*o;return {x:y-r.width*o/2,y:f-r.height*o/2,width:r.width*o,height:r.height*o}}getMindMapCollapseHitAtPoint(e){for(let t of this.shapes){if(t.type!=="mind-map")continue;let i=t,n=k(i.root),s=e.x-i.x,r=e.y-i.y,o=Math.cos(i.rotation),h=Math.sin(i.rotation),l=s*o+r*h,c=-s*h+r*o;for(let[d,u]of n.positions){let g=z(i.root,d);if(!g||!g.children||g.children.length===0)continue;let p=u.x+u.width/2+10,y=u.y,f=l-p,S=c-y;if(f*f+S*S<=121)return {shapeId:t.id,nodeId:d}}}return null}beginMindMapEdit(e,t){let i=this.shapes.find(s=>s.id===e);if(!i||i.type!=="mind-map")return;let n=i;this.mindMapEditingShapeId=e,this.mindMapSelectedNode={shapeId:e,nodeId:t&&z(n.root,t)?t:n.root.id},this.selectedIds=[e],this.notifyListeners(),this.render();}exitMindMapEdit(){this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null,this.notifyListeners(),this.render();}updateMindMapNode(e,t,i,n=true){let s=this.shapes.findIndex(g=>g.id===e);if(s===-1)return;let r=this.shapes[s];if(r.type!=="mind-map")return;let o=r,h=z(o.root,t);if(!h||!Object.keys(i).some(g=>h[g]!==i[g]))return;n&&this.commitHistory();let c=Ce(o.root,t,i),{width:d,height:u}=k(c);this.shapes[s]={...o,root:c,width:d,height:u},this.notifyListeners(),this.render();}addMindMapChild(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n,r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:B("mindmap.defaultBranch")},o=ze(s.root,t,r);this.commitHistory();let{width:h,height:l}=k(o);this.shapes[i]={...s,root:o,width:h,height:l},this.mindMapSelectedNode={shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}addMindMapSibling(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n;if(!ae(s.root,t))return;let r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:B("mindmap.defaultBranch")},o=Ye(s.root,t,r);this.commitHistory();let{width:h,height:l}=k(o);this.shapes[i]={...s,root:o,width:h,height:l},this.mindMapSelectedNode={shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}deleteMindMapNode(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n;if(s.root.id===t){this.commitHistory(),this.shapes=this.shapes.filter(c=>c.id!==e),this.selectedIds=this.selectedIds.filter(c=>c!==e),this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null,this.notifyListeners(),this.render();return}let r=We(s.root,t);if(!r)return;this.commitHistory();let{width:o,height:h}=k(r);this.shapes[i]={...s,root:r,width:o,height:h};let l=ae(s.root,t);this.mindMapSelectedNode=l?{shapeId:e,nodeId:l.id}:{shapeId:e,nodeId:r.id},this.notifyListeners(),this.render();}toggleMindMapCollapse(e,t){let i=this.shapes.findIndex(c=>c.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="mind-map")return;let s=n,r=z(s.root,t);if(!r||!r.children||r.children.length===0)return;this.commitHistory();let o=Ce(s.root,t,{collapsed:!r.collapsed}),{width:h,height:l}=k(o);this.shapes[i]={...s,root:o,width:h,height:l},this.notifyListeners(),this.render();}addUmlAttribute(e){let t=this.shapes.find(n=>n.id===e);if(!t||t.type!=="uml-class")return;let i={id:`attr_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,visibility:"+",name:"newField",type:"string"};this.updateUmlClass(e,{attributes:[...t.attributes,i]});}addUmlMethod(e){let t=this.getUmlById(e);if(!t)return;let i={id:`meth_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,visibility:"+",name:"newMethod",params:"",returnType:"void"};t.type==="uml-class"?this.updateUmlClass(e,{methods:[...t.methods,i]}):this.updateUmlInterface(e,{methods:[...t.methods,i]});}removeUmlAttribute(e,t){let i=this.shapes.find(n=>n.id===e);!i||i.type!=="uml-class"||this.updateUmlClass(e,{attributes:i.attributes.filter(n=>n.id!==t)});}removeUmlMethod(e,t){let i=this.getUmlById(e);if(!i)return;let n=i.methods.filter(s=>s.id!==t);i.type==="uml-class"?this.updateUmlClass(e,{methods:n}):this.updateUmlInterface(e,{methods:n});}reorderUmlAttribute(e,t,i){let n=this.shapes.find(o=>o.id===e);if(!n||n.type!=="uml-class"||t===i)return;let s=[...n.attributes];if(t<0||t>=s.length||i<0||i>=s.length)return;let[r]=s.splice(t,1);s.splice(i,0,r),this.updateUmlClass(e,{attributes:s});}reorderUmlMethod(e,t,i){let n=this.getUmlById(e);if(!n||t===i)return;let s=[...n.methods];if(t<0||t>=s.length||i<0||i>=s.length)return;let[r]=s.splice(t,1);s.splice(i,0,r),n.type==="uml-class"?this.updateUmlClass(e,{methods:s}):this.updateUmlInterface(e,{methods:s});}updateUmlRowStyle(e,t,i,n){let s=this.getUmlById(e);if(s)if(t==="attribute"){if(s.type!=="uml-class")return;let r=s.attributes.map(o=>o.id===i?{...o,textColor:n.textColor===null?void 0:n.textColor??o.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??o.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??o.strikethrough}:o);this.updateUmlClass(e,{attributes:r});}else {let r=s.methods.map(o=>o.id===i?{...o,textColor:n.textColor===null?void 0:n.textColor??o.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??o.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??o.strikethrough}:o);s.type==="uml-class"?this.updateUmlClass(e,{methods:r}):this.updateUmlInterface(e,{methods:r});}}getUmlRowAtScreenPoint(e){let t=this.camera.screenToPage(e);for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(n.type!=="uml-class"&&n.type!=="uml-interface")continue;let s=n.width/2,r=n.height/2;if(t.x<n.x-s||t.x>n.x+s||t.y<n.y-r||t.y>n.y+r)continue;let o=_,h=t.y-n.y;if(h>=-r&&h<=-r+o)return {shape:n,section:"className",rowIndex:-1,text:n.className};if(n.type==="uml-interface"){let p=-r+o,y=r;if(n.methods.length>0&&h>=p&&h<=y){let f=Math.floor((h-p-T)/D);if(f>=0&&f<n.methods.length){let S=n.methods[f];return {shape:n,section:"method",rowIndex:f,text:`${S.visibility} ${S.name}(${S.params}): ${S.returnType}`}}return {shape:n,section:"method",rowIndex:-1,text:""}}return {shape:n,section:"className",rowIndex:-1,text:n.className}}let l=n.attributes.length>0?n.attributes.length*D+T*2:T*2,c=-r+o,d=c+l;if(n.attributes.length>0&&h>=c&&h<=d){let p=Math.floor((h-c-T)/D);if(p>=0&&p<n.attributes.length){let y=n.attributes[p];return {shape:n,section:"attribute",rowIndex:p,text:`${y.visibility} ${y.name}: ${y.type}`}}return {shape:n,section:"attribute",rowIndex:-1,text:""}}let u=d,g=r;if(n.methods.length>0&&h>=u&&h<=g){let p=Math.floor((h-u-T)/D);if(p>=0&&p<n.methods.length){let y=n.methods[p];return {shape:n,section:"method",rowIndex:p,text:`${y.visibility} ${y.name}(${y.params}): ${y.returnType}`}}return {shape:n,section:"method",rowIndex:-1,text:""}}return {shape:n,section:"className",rowIndex:-1,text:n.className}}return null}setActiveTool(e){this.tools.has(e)&&(this.tools.get(this.activeTool)?.cancelTransient(),this.clearTransientPreview(),this.activeTool=e,this.eraserPoint=null,this.notifyListeners(),this.scheduleRender());}getActiveTool(){return this.activeTool}setHighlighterColor(e){let t=this.tools.get("highlighter");t instanceof X&&t.setHighlighterColor(e);}getHighlighterColor(){let e=this.tools.get("highlighter");return e instanceof X?e.getHighlighterColor():Ve}getShapes(){return [...this.shapes]}getData(){return {shapes:this.getShapes(),camera:{x:this.camera.x,y:this.camera.y,zoom:this.camera.zoom}}}setShapes(e){return Array.isArray(e)?(this.shapes=e.map(t=>({...t,style:{...t.style}})),this.selectedIds=[],this.undoStack=[],this.redoStack=[],this.notifyListeners(),this.render(),true):false}setTheme(e){be(e),this.scheduleRender();}setLanguage(e){ve(e);}getSelectedIds(){return [...this.selectedIds]}getCamera(){return this.camera}isPointerDown(){return this.pointerIsDown}getContentBounds(e=24){return xe(this.shapes,e)}async exportImage(e,t={}){return it(this.getShapes(),e,t)}async downloadImage(e="drawui",t="png",i={}){let n=await this.exportImage(t,i);st(n,`${e}.${t}`);}zoomIn(){this.camera.zoomAt({x:window.innerWidth/2,y:window.innerHeight/2},1.2),this.scheduleRender(),this.notifyListeners();}zoomOut(){this.camera.zoomAt({x:window.innerWidth/2,y:window.innerHeight/2},.8),this.scheduleRender(),this.notifyListeners();}resetZoom(){this.camera.reset(),this.scheduleRender(),this.notifyListeners();}panBy(e,t){this.camera.translate(e,t),this.scheduleRender(),this.notifyListeners();}setCameraPosition(e,t){this.camera.x=e,this.camera.y=t,this.scheduleRender(),this.notifyListeners();}requestRender(){this.scheduleRender(),this.notifyListeners();}setShowGrid(e){this.renderer.setShowGrid(e),this.scheduleRender();}render(){this.renderer.render(this.shapes,this.camera,new Set(this.selectedIds),this.brushRect,this.snapGuides,this.connectingTargetId,this.genPreview,this.eraserPoint,this.mindMapSelectedNode,this.mindMapHoverNode,void 0,this.hoverAnchorShapeId,this.hoverConnectorId);}scheduleRender(){this.renderScheduled||(this.renderScheduled=true,requestAnimationFrame(()=>{this.renderScheduled=false,this.render();}));}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeNotifications(e){return this.notificationListeners.add(e),()=>this.notificationListeners.delete(e)}notify(e){this.notificationListeners.forEach(t=>t(e));}notifyListeners(){this.notifyScheduled||(this.notifyScheduled=true,queueMicrotask(()=>{this.notifyScheduled=false,this.mindMapEditingShapeId&&!this.selectedIds.includes(this.mindMapEditingShapeId)&&(this.mindMapEditingShapeId=null,this.mindMapSelectedNode=null),this.listeners.forEach(e=>e());}));}cloneShapes(e){return e.map(t=>{let i={...t,style:{...t.style}};return Array.isArray(t.points)&&(i.points=t.points.map(n=>({...n}))),Array.isArray(t.userPoints)&&(i.userPoints=t.userPoints.map(n=>({...n}))),t.startBinding&&(i.startBinding={...t.startBinding}),t.endBinding&&(i.endBinding={...t.endBinding}),t.root&&(i.root=Pe(t.root)),i})}commitHistory(){if(this.isUndoing)return;let e={shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]};this.undoStack.push(e),this.undoStack.length>Hn&&this.undoStack.shift(),this.redoStack=[];}mark(){this.commitHistory();}undo(){if(this.undoStack.length!==0){this.isUndoing=true;try{this.redoStack.push({shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]});let e=this.undoStack.pop();this.shapes=this.cloneShapes(e.shapes),this.selectedIds=[...e.selectedIds];}finally{this.isUndoing=false;}this.notifyListeners(),this.render();}}redo(){if(this.redoStack.length!==0){this.isUndoing=true;try{this.undoStack.push({shapes:this.cloneShapes(this.shapes),selectedIds:[...this.selectedIds]});let e=this.redoStack.pop();this.shapes=this.cloneShapes(e.shapes),this.selectedIds=[...e.selectedIds];}finally{this.isUndoing=false;}this.notifyListeners(),this.render();}}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}saveToStorage(){if(!this.persist)return false;try{let e=JSON.stringify({version:1,shapes:this.shapes,savedAt:Date.now()});return localStorage.setItem(rt,e),this.notifyListeners(),this.notify(B("save.success")),!0}catch(e){return console.error("\u4FDD\u5B58\u5931\u8D25:",e),this.notify(B("save.fail")),false}}loadFromStorage(){if(!this.persist)return false;try{let e=localStorage.getItem(rt);if(!e)return !1;let t=JSON.parse(e);return t.shapes&&Array.isArray(t.shapes)?(this.shapes=t.shapes,this.selectedIds=[],this.undoStack=[],this.redoStack=[],this.notifyListeners(),this.scheduleRender(),!0):!1}catch(e){return console.error("\u52A0\u8F7D\u5931\u8D25:",e),false}}clearStorage(){localStorage.removeItem(rt);}exportJSON(){return JSON.stringify({version:1,shapes:this.shapes,savedAt:Date.now()},null,2)}importJSON(e){try{let t=JSON.parse(e);return t.shapes&&Array.isArray(t.shapes)?(this.commitHistory(),this.shapes=t.shapes,this.selectedIds=[],this.notifyListeners(),this.render(),!0):!1}catch(t){return console.error("\u5BFC\u5165\u5931\u8D25:",t),false}}getEditingShapeId(){return this.editingShapeId}canEditShape(e){return !(e.type==="line"||e.type==="arrow"||e.type==="draw"||e.type==="uml-class"||e.type==="uml-interface"||e.type==="mind-map")}enterEditing(e){let t=this.shapes.find(i=>i.id===e);!t||!this.canEditShape(t)||(this.editingShapeId=e,this.selectedIds=[e],this.isNewTextShape=t.type==="text"&&!t.text,this.originalTextValue=t.text||"",this.notifyListeners(),this.scheduleRender(),requestAnimationFrame(()=>{this.createTextInput(t);}));}exitEditing(){if(!this.editingShapeId)return;let e=this.editingShapeId,t=this.shapes.find(n=>n.id===e),i=this.textInput?this.textInput.value:"";if(this.removeTextInput(),t)if(t.type==="text")if(this.commitHistory(),!i.trim()&&this.isNewTextShape)this.shapes=this.shapes.filter(n=>n.id!==e),this.selectedIds=this.selectedIds.filter(n=>n!==e);else {let n=t,s=n.fontSize||16,r=s*1.3,o=n.width||200,h=i.split(`
42
+ `),l=0;for(let u of h){let g="";for(let p of u){let y=g+p;y.length*s*.6>o&&g?(l++,g=p):g=y;}g&&l++;}let c={...n,text:i,height:Math.max(l*r,r)},d=this.shapes.indexOf(t);d!==-1&&(this.shapes[d]=c),i.trim()||(this.shapes=this.shapes.filter(u=>u.id!==e),this.selectedIds=this.selectedIds.filter(u=>u!==e));}else this.commitHistory(),this.updateShape(e,{text:i,textColor:t.textColor||I.text,fontSize:t.fontSize||16});this.editingShapeId=null,this.isNewTextShape=false,this.originalTextValue="",this.setActiveTool("select"),this.notifyListeners(),this.render();}removeTextInput(){this.textOverlay&&(this.textOverlay.remove(),this.textOverlay=null),this.textInput&&(this.textInput.remove(),this.textInput=null);}createTextInput(e){this.removeTextInput();let t=this.canvas.parentElement;if(!t)return;let i=this.canvas.getBoundingClientRect(),n=t.getBoundingClientRect(),s=i.left-n.left,r=i.top-n.top;this.textOverlay=document.createElement("div"),this.textOverlay.style.position="absolute",this.textOverlay.style.left=`${s}px`,this.textOverlay.style.top=`${r}px`,this.textOverlay.style.width=`${i.width}px`,this.textOverlay.style.height=`${i.height}px`,this.textOverlay.style.background="transparent",this.textOverlay.style.zIndex="1000",this.textOverlay.style.cursor="text",this.textOverlay.addEventListener("pointerdown",d=>{this.textInput&&d.target!==this.textInput&&(d.preventDefault(),this.exitEditing());}),t.appendChild(this.textOverlay);let o=this.getShapeScreenBounds(e),h=this.camera.getZoom(),l=(e.fontSize||16)*h,c=document.createElement("textarea");c.style.position="absolute",c.style.left=`${s+o.x}px`,c.style.top=`${r+o.y}px`,c.style.width=`${Math.max(o.width,60)}px`,c.style.height=`${Math.max(o.height,24)}px`,c.style.fontSize=`${l}px`,c.style.color=e.textColor||"#1f2937",c.style.textAlign="center",c.style.border=`2px solid ${I.editBorder}`,c.style.borderRadius="4px",c.style.background="rgba(255, 255, 255, 0.95)",c.style.resize="none",c.style.padding="4px 8px",c.style.boxSizing="border-box",c.style.lineHeight="1.4",c.style.fontFamily="sans-serif",c.style.outline="none",c.style.whiteSpace="pre-wrap",c.style.wordBreak="break-word",c.style.overflow="hidden",c.style.zIndex="1001",c.value=e.text||"",c.dataset.shapeId=e.id,c.addEventListener("pointerdown",d=>{d.stopPropagation();}),c.addEventListener("mousedown",d=>{d.stopPropagation();}),c.addEventListener("keydown",d=>{if(d.stopPropagation(),d.key==="Escape"&&(d.preventDefault(),this.textInput&&(this.textInput.value=this.originalTextValue),this.exitEditing()),d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),this.exitEditing()),d.key==="Enter"&&d.shiftKey){d.preventDefault();let u=c.selectionStart,g=c.selectionEnd;c.value=c.value.substring(0,u)+`
43
+ `+c.value.substring(g),c.selectionStart=c.selectionEnd=u+1;}}),t.appendChild(c),c.focus(),e.type==="text"&&!e.text&&(c.placeholder="\u8F93\u5165\u6587\u672C..."),this.textInput=c;}getShapeScreenBounds(e){let t=this.camera.getZoom(),i=this.camera.pageToScreen({x:e.x,y:e.y});switch(e.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "hexagon":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":return {x:i.x-e.width*t/2,y:i.y-e.height*t/2,width:e.width*t,height:e.height*t};case "circle":return {x:i.x-e.radius*t,y:i.y-e.radius*t,width:e.radius*2*t,height:e.radius*2*t};case "text":{let n=e,s=n.width*t,r=n.height*t;return {x:i.x-s/2,y:i.y-r/2,width:s,height:r}}default:return {x:i.x-50*t,y:i.y-20*t,width:100*t,height:40*t}}}getShapeAtScreenPoint(e){let t=this.screenToPage(e);return this.getShapeAtPoint(t)}getShapeAtPoint(e,t){for(let i=this.shapes.length-1;i>=0;i--){let n=this.shapes[i];if(!(t&&n.id===t)&&this.isPointInShape(e,n))return n}return null}getShapesInBrushRadius(e,t){let i=[];for(let n of this.shapes)this.shapeIntersectsBrush(n,e,t)&&i.push(n);return i}shapeIntersectsBrush(e,t,i){switch(e.type){case "line":case "arrow":{let n=e.points,s=i+4;for(let r=1;r<n.length;r++)if(this.pointToSegmentDist(t,n[r-1],n[r])<=s)return true;return n.length>0&&Math.hypot(t.x-n[0].x,t.y-n[0].y)<=s}case "draw":{let n=e.points,s=i+4;for(let r=1;r<n.length;r++){let o={x:e.x+n[r-1].x,y:e.y+n[r-1].y},h={x:e.x+n[r].x,y:e.y+n[r].y};if(this.pointToSegmentDist(t,o,h)<=s)return true}return n.length>0&&Math.hypot(t.x-(e.x+n[0].x),t.y-(e.y+n[0].y))<=s}case "circle":return Math.hypot(t.x-e.x,t.y-e.y)<=e.radius+i;case "text":{let n=e;return Math.abs(t.x-e.x)<=n.width/2+i&&Math.abs(t.y-e.y)<=n.height/2+i}default:return Math.abs(t.x-e.x)<=e.width/2+i&&Math.abs(t.y-e.y)<=e.height/2+i}}pointToSegmentDist(e,t,i){let n=i.x-t.x,s=i.y-t.y,r=n*n+s*s,o=r===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*s)/r));return Math.hypot(e.x-(t.x+o*n),e.y-(t.y+o*s))}setEraserPoint(e){this.eraserPoint=e,this.scheduleRender();}isPointInShape(e,t){let i=e.x-t.x,n=e.y-t.y;switch(t.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "parallelogram":case "trapezoid":case "pentagon":case "octagon":case "star":case "cylinder":case "cloud":case "heart":case "block-arrow-right":case "block-arrow-left":case "block-arrow-up":case "block-arrow-down":case "block-arrow-double":case "right-triangle":case "cross":case "speech-rect":case "speech-round":case "cube":case "sector":case "delay":case "predefined-process":case "document":case "stadium":case "class-catalog":case "chevron":case "brace-left":case "brace-right":case "uml-class":case "uml-interface":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "circle":return i*i+n*n<=t.radius*t.radius;case "hexagon":{let s=t.width/2,r=t.height/2;return Math.abs(i)<=s&&Math.abs(n)<=r&&Math.abs(i)/s+Math.abs(n)/r<=1.5}case "mind-map":return Math.abs(i)<=t.width/2&&Math.abs(n)<=t.height/2;case "text":{let s=t;return Math.abs(i)<=s.width/2&&Math.abs(n)<=s.height/2}default:return false}}updateArrowBinding(e,t,i,n){let s=this.shapes.find(h=>h.id===e);if(!s||s.type!=="arrow")return;let r=s,o={};if(i){let h=this.shapes.find(u=>u.id===i);if(!h)return;let l=n?.handle||this.getClosestHandle(r,h),c=this.getBindingPosition(h,l),d=n?{...n,toShapeId:i}:{toShapeId:i,handle:l,auto:true};t==="start"?(o.startBinding=d,o.points=r.points.map((u,g)=>g===0?c:u)):(o.endBinding=d,o.points=r.points.map((u,g)=>g===r.points.length-1?c:u));}else t==="start"?o.startBinding=void 0:o.endBinding=void 0;this.updateShape(e,o);}getClosestHandle(e,t){let i=e.points[0],n=e.points[e.points.length-1],s=e.endBinding?n:i,r=s.x-t.x,o=s.y-t.y;return Math.abs(r)>Math.abs(o)?r>0?"right":"left":o>0?"bottom":"top"}dispose(){this.canvas.removeEventListener("pointerdown",this.handlePointerDown),this.canvas.removeEventListener("pointerleave",this.handlePointerUp),window.removeEventListener("pointermove",this.handlePointerMove),window.removeEventListener("pointerup",this.handlePointerUp),window.removeEventListener("pointercancel",this.handlePointerUp),window.removeEventListener("blur",this.handleWindowBlur),window.removeEventListener("pointerdown",this.handleGlobalPointerDown,true),this.canvas.removeEventListener("wheel",this.handleWheel),window.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("keyup",this.handleKeyUp),window.removeEventListener("resize",this.handleResize),this.removeTextInput(),this.tools.forEach(e=>e.dispose()),this.listeners.clear();}};exports.ArrowTool=ye;exports.Camera=Z;exports.DEFAULT_HIGHLIGHTER_COLOR=Ve;exports.Editor=ot;exports.FreehandTool=X;exports.HandTool=ge;exports.LineTool=pe;exports.MINDMAP_COLORS=Ue;exports.MINDMAP_FONT_SIZE=U;exports.MINDMAP_MAX_WIDTH=Nt;exports.MINDMAP_MIN_WIDTH=Rt;exports.MINDMAP_NODE_HEIGHT=Vt;exports.MIN_HANDLE_SEGMENT=Dt;exports.MIN_JOG=Lt;exports.Mat2d=G;exports.Renderer=q;exports.SelectTool=ue;exports.ShapeTool=P;exports.THEME=I;exports.UML_FONT_SIZE=$;exports.UML_HEADER_HEIGHT=_;exports.UML_LINE_HEIGHT=D;exports.UML_MIN_WIDTH=he;exports.UML_PADDING_X=H;exports.UML_PADDING_Y=T;exports.Vec=J;exports.calcUmlClassSize=Te;exports.cloneMindMapNode=Pe;exports.collapseRoute=oe;exports.connectorSegmentHandles=Se;exports.countMindMapNodes=pt;exports.downloadBlob=st;exports.exportToBlob=it;exports.findMindMapNode=z;exports.getContentBounds=xe;exports.getLanguage=Ht;exports.getMindMapNodeDepth=gt;exports.getMindMapParent=ae;exports.getTheme=kt;exports.hexToRgba=R;exports.layoutMindMap=k;exports.mindMapNodeColor=j;exports.mindMapNodeSize=ut;exports.offsetConnectorSegment=Be;exports.pickSegmentHandle=Ne;exports.pointToSegmentDistance=we;exports.renderSVGString=Tt;exports.renderToCanvas=Ct;exports.routeToUserPoints=_e;exports.setLanguage=ve;exports.setTheme=be;exports.shadeColor=At;exports.subscribeLanguage=$t;exports.subscribeTheme=Et;exports.t=B;