drawui-core 0.3.4 → 0.3.6

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,43 +1,43 @@
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(`
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
- <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
- ${l}
1
+ 'use strict';var W={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=W.scale(a.zoom,a.zoom),t=W.translation(a.x,a.y);return W.multiply(t,e)}};var ie=class{x=0;y=0;zoom=1;minZoom=.1;maxZoom=10;getMatrix(){return W.createCameraMatrix({x:this.x,y:this.y,zoom:this.zoom})}getInverseMatrix(){return W.invert(this.getMatrix())}screenToPage(e){let t=this.getInverseMatrix();return t?W.apply(t,e):e}pageToScreen(e){return W.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,o=(i-t*2)/e.width,r=(n-t*2)/e.height,s=Math.min(o,r,this.maxZoom);this.zoom=Math.max(this.minZoom,s),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 _t=40;var Gt=20;function Te(a,e,t){let i=t.x-e.x,n=t.y-e.y,o=i*i+n*n;if(o<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)/o;return r=Math.max(0,Math.min(1,r)),Math.hypot(a.x-(e.x+i*r),a.y-(e.y+n*r))}function ke(a,e=40){let t=[];for(let i=0;i+1<a.length;i++){let n=a[i],o=a[i+1],r=o.x-n.x,s=o.y-n.y,l=Math.hypot(r,s);l<e||t.push({index:i,center:{x:(n.x+o.x)/2,y:(n.y+o.y)/2},axis:Math.abs(r)>=Math.abs(s)?"H":"V",length:l});}return t}function Ye(a,e,t=10,i=14){let n=ke(a);if(n.length===0)return null;let o=null,r=1/0;for(let s of n){if(Math.hypot(e.x-s.center.x,e.y-s.center.y)<=t)return s;let h=Te(e,a[s.index],a[s.index+1]);h<=i&&h<r&&(r=h,o=s);}return o}function Ke(a,e,t){if(e<0||e+1>=a.length)return a;let i=a[e],n=a[e+1],o=Math.abs(n.x-i.x)>=Math.abs(n.y-i.y),r=e===0,s=e+1===a.length-1,l=o?Math.sign(n.x-i.x)||1:Math.sign(n.y-i.y)||1,h=Math.abs(o?n.x-i.x:n.y-i.y),c=Math.min(24,h/2),d=o?(i.y+n.y)/2:(i.x+n.x)/2,u=m=>o?m.y:m.x,p=[];r?p.push(u(a[0])):p.push(u(a[e-1])),s?p.push(u(a[a.length-1])):p.push(u(a[e+2]));let g=d+t;for(let m of p)Math.abs(g-m)<20&&(g=m);let y=[];if(r){let m=o?{x:i.x+l*c,y:i.y}:{x:i.x,y:i.y+l*c};y.push({x:i.x,y:i.y},m,o?{x:m.x,y:g}:{x:g,y:m.y});}else y.push(o?{x:i.x,y:g}:{x:g,y:i.y});if(s){let m=o?{x:n.x-l*c,y:n.y}:{x:n.x,y:n.y-l*c};y.push(o?{x:m.x,y:g}:{x:g,y:m.y},m,{x:n.x,y:n.y});}else y.push(o?{x:n.x,y:g}:{x:g,y:n.y});return [...a.slice(0,e),...y,...a.slice(e+2)]}function pe(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],o=e[i-1];if(Math.abs(n.y-o.y)<1e-6&&Math.abs(o.y-t.y)<1e-6||Math.abs(n.x-o.x)<1e-6&&Math.abs(o.x-t.x)<1e-6){e[i-1]=t;continue}}e.push(t);}}return e}function Xe(a){return a.length<=2?[]:a.slice(1,-1).map(e=>({x:e.x,y:e.y}))}var bt={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={...bt,selection:{...bt.selection}},Fe=new Set;function zt(a){return Fe.add(a),()=>Fe.delete(a)}function De(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);}Fe.forEach(e=>e());}function Ut(){return I}function _(a,e){let t=St(a);if(!t)return a;let i=parseInt(t,16),n=i>>16&255,o=i>>8&255,r=i&255;return `rgba(${n}, ${o}, ${r}, ${e})`}function Ot(a,e){let t=St(a);if(!t)return a;let i=parseInt(t,16),n=e<0?0:255,o=Math.abs(e),r=s=>Math.round((n-s)*o+s).toString(16).padStart(2,"0");return `#${r(i>>16&255)}${r(i>>8&255)}${r(i&255)}`}function St(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 Wt=[{code:"zh-CN",label:"\u7B80\u4F53\u4E2D\u6587"},{code:"zh-TW",label:"\u7E41\u9AD4\u4E2D\u6587"},{code:"en-US",label:"English"},{code:"ja-JP",label:"\u65E5\u672C\u8A9E"},{code:"ko-KR",label:"\uD55C\uAD6D\uC5B4"},{code:"de-DE",label:"Deutsch"},{code:"fr-FR",label:"Fran\xE7ais"}],Yt={"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","tool.envelope":"\u4FE1\u5C01","tool.checkbox":"\u590D\u9009\u6846","tool.triangular-pyramid":"\u4E09\u68F1\u9525","tool.quadrangular-pyramid":"\u56DB\u68F1\u9525","tool.cuboid":"\u957F\u65B9\u4F53","tool.sphere":"\u7403","tool.ellipsoid":"\u692D\u7403","tool.pie":"\u997C\u72B6","tool.hollow-pie":"\u7A7A\u5FC3\u997C\u72B6","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.solid":"\u7ACB\u4F53","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"},Mt={"zh-CN":Yt,"zh-TW":{"save.success":"\u5DF2\u5132\u5B58","save.fail":"\u5132\u5B58\u5931\u6557","tool.select":"\u9078\u53D6\u5DE5\u5177","tool.hand":"\u62D6\u66F3\u8996\u7A97","tool.rectangle":"\u77E9\u5F62","tool.rounded-rectangle":"\u5713\u89D2\u77E9\u5F62","tool.circle":"\u5713\u5F62","tool.ellipse":"\u6A62\u5713","tool.diamond":"\u83F1\u5F62","tool.triangle":"\u4E09\u89D2\u5F62","tool.hexagon":"\u516D\u908A\u5F62","tool.parallelogram":"\u5E73\u884C\u56DB\u908A\u5F62","tool.trapezoid":"\u68AF\u5F62","tool.pentagon":"\u4E94\u908A\u5F62","tool.octagon":"\u516B\u908A\u5F62","tool.star":"\u661F\u5F62","tool.cylinder":"\u5713\u67F1\u9AD4","tool.cloud":"\u96F2\u5F62","tool.heart":"\u5FC3\u5F62","tool.block-arrow-right":"\u53F3\u7BAD\u982D","tool.block-arrow-left":"\u5DE6\u7BAD\u982D","tool.block-arrow-up":"\u4E0A\u7BAD\u982D","tool.block-arrow-down":"\u4E0B\u7BAD\u982D","tool.block-arrow-double":"\u96D9\u5411\u7BAD\u982D","tool.right-triangle":"\u76F4\u89D2\u4E09\u89D2\u5F62","tool.cross":"\u5341\u5B57","tool.speech-rect":"\u65B9\u5F62\u5C0D\u8A71\u6846","tool.speech-round":"\u5713\u5F62\u5C0D\u8A71\u6846","tool.cube":"\u7ACB\u65B9\u9AD4","tool.sector":"\u6247\u5F62","tool.delay":"D \u5F62","tool.predefined-process":"\u9810\u5B9A\u7FA9\u6D41\u7A0B","tool.document":"\u6587\u4EF6","tool.stadium":"\u5168\u5713\u89D2\u77E9\u5F62","tool.class-catalog":"\u985E\u76EE","tool.envelope":"\u4FE1\u5C01","tool.checkbox":"\u6838\u53D6\u65B9\u584A","tool.triangular-pyramid":"\u4E09\u7A1C\u9310","tool.quadrangular-pyramid":"\u56DB\u7A1C\u9310","tool.cuboid":"\u9577\u65B9\u9AD4","tool.sphere":"\u7403","tool.ellipsoid":"\u6A62\u7403","tool.pie":"\u9905\u72C0","tool.hollow-pie":"\u7A7A\u5FC3\u9905\u72C0","class.plain":"\u985E\u5225","flow.process":"\u8655\u7406","flow.step":"\u6D41\u7A0B","flow.startEnd":"\u958B\u59CB/\u7D50\u675F","flow.decision":"\u5224\u65B7","flow.data":"\u8CC7\u6599","flow.manual":"\u624B\u52D5\u64CD\u4F5C","flow.preparation":"\u6E96\u5099","flow.database":"\u8CC7\u6599\u5EAB","flow.delay":"\u5EF6\u9072","shapeGroup.basic":"\u57FA\u790E","shapeGroup.flowchart":"\u6D41\u7A0B\u5716","shapeGroup.other":"\u5176\u4ED6","shapeGroup.solid":"\u7ACB\u9AD4","shapeGroup.uml":"\u985E\u5225\u5716","shapeMenu.hint":"\u61F8\u505C\u67E5\u770B\u540D\u7A31","tool.chevron":"\u5C16\u89D2","tool.brace-left":"\u5DE6\u62EC\u865F","tool.brace-right":"\u53F3\u62EC\u865F","tool.uml-class":"UML \u985E\u5225\u5716","tool.uml-interface":"UML \u4ECB\u9762","tool.line":"\u76F4\u7DDA","tool.arrow":"\u7DDA\u689D","tool.text":"\u6587\u5B57","tool.draw":"\u756B\u7B46","tool.pen":"\u756B\u7B46","tool.highlighter":"\u87A2\u5149\u7B46","tool.eraser":"\u6A61\u76AE\u64E6","status.none":"\u672A\u9078\u53D6","status.selected":"\u5DF2\u9078\u53D6 {n} \u500B\u5716\u5F62","toolbar.select":"\u9078\u53D6 (V)","toolbar.hand":"\u62D6\u66F3\u8996\u7A97 (H)","toolbar.shapes":"\u5F62\u72C0","toolbar.grid":"\u683C\u7DDA","toolbar.undo":"\u5FA9\u539F (Ctrl+Z)","toolbar.redo":"\u91CD\u505A (Ctrl+Shift+Z)","toolbar.arrow":"\u7BAD\u982D","toolbar.text":"\u6587\u5B57","toolbar.pen":"\u756B\u7B46","toolbar.highlighter":"\u87A2\u5149\u7B46","toolbar.eraser":"\u6A61\u76AE\u64E6","toolbar.uml-class":"UML \u985E\u5225\u5716","toolbar.uml-interface":"UML \u4ECB\u9762","zoom.in":"\u653E\u5927","zoom.out":"\u7E2E\u5C0F","zoom.reset":"\u91CD\u8A2D","style.stroke":"\u908A\u6846","style.line":"\u7DDA\u689D","style.fill":"\u586B\u8272","style.text":"\u6587\u5B57","style.highlight":"\u6A19\u793A","style.prefix":"\u524D\u7F6E\u7B26\u865F","style.prefix.soon":"\u524D\u7F6E\u7B26\u865F\u958B\u767C\u4E2D\uFF0C\u656C\u8ACB\u671F\u5F85","style.none":"\u7121","style.addColor":"\u65B0\u589E\u984F\u8272","style.connection":"\u9023\u7DDA","style.arrow":"\u7BAD\u982D","style.dashed":"\u865B\u7DDA","style.solid":"\u5BE6\u7DDA","style.opacity":"\u4E0D\u900F\u660E\u5EA6","style.connection.straight":"\u76F4\u7DDA","style.connection.polyline":"\u6298\u7DDA","style.connection.orthogonal":"\u76F4\u89D2\u6298\u7DDA","style.connection.curve":"\u66F2\u7DDA","style.arrowhead.none":"\u7121\u7BAD\u982D","style.arrowhead.end":"\u7D42\u9EDE\u7BAD\u982D","style.arrowhead.start":"\u8D77\u9EDE\u7BAD\u982D","style.arrowhead.both":"\u96D9\u7BAD\u982D","style.arrowhead.none-dashed":"\u7121\u7BAD\u982D\u865B\u7DDA","style.arrowhead.both-dashed":"\u96D9\u7BAD\u982D\u865B\u7DDA","style.uml":"UML","style.arrowhead.inheritance":"\u7E7C\u627F","style.arrowhead.composition":"\u7D44\u5408","style.arrowhead.aggregation":"\u805A\u5408","style.arrowhead.dependency":"\u4F9D\u8CF4","style.arrowhead.realization":"\u5BE6\u73FE","menu.title":"\u9078\u64C7\u65B0\u5716\u5F62","menu.cancel":"\u9EDE\u64CA\u7A7A\u767D\u8655\u53D6\u6D88","shape.rectangle":"\u77E9\u5F62","shape.rounded-rectangle":"\u5713\u89D2","shape.circle":"\u5713\u5F62","shape.ellipse":"\u6A62\u5713","shape.diamond":"\u83F1\u5F62","shape.triangle":"\u4E09\u89D2","shape.hexagon":"\u516D\u908A\u5F62","shape.parallelogram":"\u5E73\u884C","shape.trapezoid":"\u68AF\u5F62","shape.pentagon":"\u4E94\u908A\u5F62","shape.octagon":"\u516B\u908A\u5F62","shape.star":"\u661F\u5F62","shape.uml-class":"\u985E\u5225\u5716","shape.uml-interface":"\u4ECB\u9762","uml.drag":"\u62D6\u66F3\u6392\u5E8F","uml.delete":"\u522A\u9664\u8A72\u5217","uml.textColor":"\u6587\u5B57\u984F\u8272","uml.defaultColor":"\u9810\u8A2D\u984F\u8272","uml.fontSize":"\u5B57\u7D1A","uml.strikethrough":"\u522A\u9664\u7DDA","uml.attribute":"\u5C6C\u6027","uml.method":"\u65B9\u6CD5","minimap.title":"\u5C0F\u5730\u5716","minimap.expand":"\u5C55\u958B\u5C0F\u5730\u5716","minimap.collapse":"\u6536\u5408\u5C0F\u5730\u5716","tool.mind-map":"\u5FC3\u667A\u5716","toolbar.mind-map":"\u5FC3\u667A\u5716","toolbar.export":"\u532F\u51FA","toolbar.export.png":"PNG \u5716\u7247","toolbar.export.svg":"SVG \u5411\u91CF\u5716","toolbar.export.pdf":"PDF \u6587\u4EF6","shape.mind-map":"\u5FC3\u667A\u5716","mindmap.defaultRoot":"\u4E2D\u5FC3\u4E3B\u984C","mindmap.defaultBranch":"\u5206\u652F\u4E3B\u984C","mindmap.nodeText":"\u7BC0\u9EDE\u6587\u5B57","mindmap.addChild":"\u5B50\u7BC0\u9EDE","mindmap.addSibling":"\u5144\u5F1F\u7BC0\u9EDE","mindmap.deleteNode":"\u522A\u9664\u7BC0\u9EDE","mindmap.color":"\u984F\u8272","mindmap.levelColor":"\u9810\u8A2D\u5C64\u7D1A\u8272","mindmap.icon":"\u5716\u793A","mindmap.noIcon":"\u7121\u5716\u793A","mindmap.note":"\u5C6C\u6027\u8AAA\u660E","mindmap.notePlaceholder":"\u8AAA\u660E\u5167\u5BB9\uFF08\u9078\u586B\uFF09","mindmap.noteColor":"\u8AAA\u660E\u984F\u8272","mindmap.noteColorDefault":"\u540C\u7BC0\u9EDE\u8272","mindmap.collapse":"\u6536\u5408","mindmap.expand":"\u5C55\u958B","mindmap.close":"\u95DC\u9589\u7DE8\u8F2F","mindmap.more":"\u66F4\u591A\u8A2D\u5B9A"},"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","tool.envelope":"Envelope","tool.checkbox":"Checkbox","tool.triangular-pyramid":"Triangular pyramid","tool.quadrangular-pyramid":"Square pyramid","tool.cuboid":"Cuboid","tool.sphere":"Sphere","tool.ellipsoid":"Ellipsoid","tool.pie":"Pie","tool.hollow-pie":"Donut","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.solid":"3D","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"},"ja-JP":{"save.success":"\u4FDD\u5B58\u3057\u307E\u3057\u305F","save.fail":"\u4FDD\u5B58\u306B\u5931\u6557\u3057\u307E\u3057\u305F","tool.select":"\u9078\u629E\u30C4\u30FC\u30EB","tool.hand":"\u30AD\u30E3\u30F3\u30D0\u30B9\u3092\u79FB\u52D5","tool.rectangle":"\u56DB\u89D2\u5F62","tool.rounded-rectangle":"\u89D2\u4E38\u56DB\u89D2\u5F62","tool.circle":"\u5186","tool.ellipse":"\u6955\u5186","tool.diamond":"\u3072\u3057\u5F62","tool.triangle":"\u4E09\u89D2\u5F62","tool.hexagon":"\u516D\u89D2\u5F62","tool.parallelogram":"\u5E73\u884C\u56DB\u8FBA\u5F62","tool.trapezoid":"\u53F0\u5F62","tool.pentagon":"\u4E94\u89D2\u5F62","tool.octagon":"\u516B\u89D2\u5F62","tool.star":"\u661F\u5F62","tool.cylinder":"\u5186\u67F1","tool.cloud":"\u96F2","tool.heart":"\u30CF\u30FC\u30C8","tool.block-arrow-right":"\u53F3\u77E2\u5370","tool.block-arrow-left":"\u5DE6\u77E2\u5370","tool.block-arrow-up":"\u4E0A\u77E2\u5370","tool.block-arrow-down":"\u4E0B\u77E2\u5370","tool.block-arrow-double":"\u53CC\u65B9\u5411\u77E2\u5370","tool.right-triangle":"\u76F4\u89D2\u4E09\u89D2\u5F62","tool.cross":"\u5341\u5B57","tool.speech-rect":"\u56DB\u89D2\u3044\u5439\u304D\u51FA\u3057","tool.speech-round":"\u4E38\u3044\u5439\u304D\u51FA\u3057","tool.cube":"\u7ACB\u65B9\u4F53","tool.sector":"\u6247\u5F62","tool.delay":"D \u5B57","tool.predefined-process":"\u5B9A\u7FA9\u6E08\u307F\u51E6\u7406","tool.document":"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8","tool.stadium":"\u4E21\u7AEF\u304C\u4E38\u3044\u9577\u65B9\u5F62","tool.class-catalog":"\u30AB\u30C6\u30B4\u30EA","tool.envelope":"\u5C01\u7B52","tool.checkbox":"\u30C1\u30A7\u30C3\u30AF\u30DC\u30C3\u30AF\u30B9","tool.triangular-pyramid":"\u4E09\u89D2\u9310","tool.quadrangular-pyramid":"\u56DB\u89D2\u9310","tool.cuboid":"\u76F4\u65B9\u4F53","tool.sphere":"\u7403","tool.ellipsoid":"\u6955\u5186\u4F53","tool.pie":"\u5186\u30B0\u30E9\u30D5","tool.hollow-pie":"\u30C9\u30FC\u30CA\u30C4","class.plain":"\u30AF\u30E9\u30B9","flow.process":"\u51E6\u7406","flow.step":"\u30B9\u30C6\u30C3\u30D7","flow.startEnd":"\u958B\u59CB/\u7D42\u4E86","flow.decision":"\u5224\u65AD","flow.data":"\u30C7\u30FC\u30BF","flow.manual":"\u624B\u52D5\u64CD\u4F5C","flow.preparation":"\u6E96\u5099","flow.database":"\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9","flow.delay":"\u9045\u5EF6","shapeGroup.basic":"\u57FA\u672C","shapeGroup.flowchart":"\u30D5\u30ED\u30FC\u30C1\u30E3\u30FC\u30C8","shapeGroup.other":"\u305D\u306E\u4ED6","shapeGroup.solid":"\u7ACB\u4F53","shapeGroup.uml":"\u30AF\u30E9\u30B9\u56F3","shapeMenu.hint":"\u30DB\u30D0\u30FC\u3067\u540D\u524D\u3092\u8868\u793A","tool.chevron":"\u5C71\u5F62","tool.brace-left":"\u5DE6\u4E2D\u62EC\u5F27","tool.brace-right":"\u53F3\u4E2D\u62EC\u5F27","tool.uml-class":"UML \u30AF\u30E9\u30B9\u56F3","tool.uml-interface":"UML \u30A4\u30F3\u30BF\u30FC\u30D5\u30A7\u30FC\u30B9","tool.line":"\u76F4\u7DDA","tool.arrow":"\u7DDA","tool.text":"\u30C6\u30AD\u30B9\u30C8","tool.draw":"\u30DA\u30F3","tool.pen":"\u30DA\u30F3","tool.highlighter":"\u86CD\u5149\u30DA\u30F3","tool.eraser":"\u6D88\u3057\u30B4\u30E0","status.none":"\u672A\u9078\u629E","status.selected":"{n} \u500B\u306E\u56F3\u5F62\u3092\u9078\u629E\u4E2D","toolbar.select":"\u9078\u629E (V)","toolbar.hand":"\u30AD\u30E3\u30F3\u30D0\u30B9\u3092\u79FB\u52D5 (H)","toolbar.shapes":"\u56F3\u5F62","toolbar.grid":"\u30B0\u30EA\u30C3\u30C9","toolbar.undo":"\u5143\u306B\u623B\u3059 (Ctrl+Z)","toolbar.redo":"\u3084\u308A\u76F4\u3059 (Ctrl+Shift+Z)","toolbar.arrow":"\u77E2\u5370","toolbar.text":"\u30C6\u30AD\u30B9\u30C8","toolbar.pen":"\u30DA\u30F3","toolbar.highlighter":"\u86CD\u5149\u30DA\u30F3","toolbar.eraser":"\u6D88\u3057\u30B4\u30E0","toolbar.uml-class":"UML \u30AF\u30E9\u30B9\u56F3","toolbar.uml-interface":"UML \u30A4\u30F3\u30BF\u30FC\u30D5\u30A7\u30FC\u30B9","zoom.in":"\u62E1\u5927","zoom.out":"\u7E2E\u5C0F","zoom.reset":"\u30EA\u30BB\u30C3\u30C8","style.stroke":"\u67A0\u7DDA","style.line":"\u7DDA","style.fill":"\u5857\u308A","style.text":"\u30C6\u30AD\u30B9\u30C8","style.highlight":"\u30CF\u30A4\u30E9\u30A4\u30C8","style.prefix":"\u63A5\u982D\u8A18\u53F7","style.prefix.soon":"\u63A5\u982D\u8A18\u53F7\u306F\u958B\u767A\u4E2D\u3067\u3059\u3002\u3057\u3070\u3089\u304F\u304A\u5F85\u3061\u304F\u3060\u3055\u3044","style.none":"\u306A\u3057","style.addColor":"\u8272\u3092\u8FFD\u52A0","style.connection":"\u63A5\u7D9A","style.arrow":"\u77E2\u5370","style.dashed":"\u7834\u7DDA","style.solid":"\u5B9F\u7DDA","style.opacity":"\u4E0D\u900F\u660E\u5EA6","style.connection.straight":"\u76F4\u7DDA","style.connection.polyline":"\u6298\u308C\u7DDA","style.connection.orthogonal":"\u76F4\u89D2\u6298\u308C\u7DDA","style.connection.curve":"\u66F2\u7DDA","style.arrowhead.none":"\u77E2\u5370\u306A\u3057","style.arrowhead.end":"\u7D42\u70B9\u306E\u77E2\u5370","style.arrowhead.start":"\u59CB\u70B9\u306E\u77E2\u5370","style.arrowhead.both":"\u4E21\u7AEF\u306E\u77E2\u5370","style.arrowhead.none-dashed":"\u77E2\u5370\u306A\u3057\u306E\u7834\u7DDA","style.arrowhead.both-dashed":"\u4E21\u7AEF\u77E2\u5370\u306E\u7834\u7DDA","style.uml":"UML","style.arrowhead.inheritance":"\u7D99\u627F","style.arrowhead.composition":"\u30B3\u30F3\u30DD\u30B8\u30B7\u30E7\u30F3","style.arrowhead.aggregation":"\u96C6\u7D04","style.arrowhead.dependency":"\u4F9D\u5B58","style.arrowhead.realization":"\u5B9F\u73FE","menu.title":"\u65B0\u3057\u3044\u56F3\u5F62\u3092\u9078\u629E","menu.cancel":"\u7A7A\u767D\u3092\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30AD\u30E3\u30F3\u30BB\u30EB","shape.rectangle":"\u56DB\u89D2\u5F62","shape.rounded-rectangle":"\u89D2\u4E38","shape.circle":"\u5186","shape.ellipse":"\u6955\u5186","shape.diamond":"\u3072\u3057\u5F62","shape.triangle":"\u4E09\u89D2","shape.hexagon":"\u516D\u89D2\u5F62","shape.parallelogram":"\u5E73\u884C","shape.trapezoid":"\u53F0\u5F62","shape.pentagon":"\u4E94\u89D2\u5F62","shape.octagon":"\u516B\u89D2\u5F62","shape.star":"\u661F\u5F62","shape.uml-class":"\u30AF\u30E9\u30B9\u56F3","shape.uml-interface":"\u30A4\u30F3\u30BF\u30FC\u30D5\u30A7\u30FC\u30B9","uml.drag":"\u30C9\u30E9\u30C3\u30B0\u3067\u4E26\u3079\u66FF\u3048","uml.delete":"\u3053\u306E\u884C\u3092\u524A\u9664","uml.textColor":"\u6587\u5B57\u8272","uml.defaultColor":"\u65E2\u5B9A\u306E\u8272","uml.fontSize":"\u6587\u5B57\u30B5\u30A4\u30BA","uml.strikethrough":"\u53D6\u308A\u6D88\u3057\u7DDA","uml.attribute":"\u5C5E\u6027","uml.method":"\u30E1\u30BD\u30C3\u30C9","minimap.title":"\u30DF\u30CB\u30DE\u30C3\u30D7","minimap.expand":"\u30DF\u30CB\u30DE\u30C3\u30D7\u3092\u5C55\u958B","minimap.collapse":"\u30DF\u30CB\u30DE\u30C3\u30D7\u3092\u6298\u308A\u305F\u305F\u3080","tool.mind-map":"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7","toolbar.mind-map":"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7","toolbar.export":"\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8","toolbar.export.png":"PNG \u753B\u50CF","toolbar.export.svg":"SVG \u30D9\u30AF\u30BF\u30FC","toolbar.export.pdf":"PDF \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8","shape.mind-map":"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7","mindmap.defaultRoot":"\u4E2D\u5FC3\u30C8\u30D4\u30C3\u30AF","mindmap.defaultBranch":"\u30D6\u30E9\u30F3\u30C1\u30C8\u30D4\u30C3\u30AF","mindmap.nodeText":"\u30CE\u30FC\u30C9\u306E\u30C6\u30AD\u30B9\u30C8","mindmap.addChild":"\u5B50\u30CE\u30FC\u30C9","mindmap.addSibling":"\u5144\u5F1F\u30CE\u30FC\u30C9","mindmap.deleteNode":"\u30CE\u30FC\u30C9\u3092\u524A\u9664","mindmap.color":"\u8272","mindmap.levelColor":"\u65E2\u5B9A\u306E\u968E\u5C64\u8272","mindmap.icon":"\u30A2\u30A4\u30B3\u30F3","mindmap.noIcon":"\u30A2\u30A4\u30B3\u30F3\u306A\u3057","mindmap.note":"\u88DC\u8DB3\u8AAC\u660E","mindmap.notePlaceholder":"\u8AAC\u660E\uFF08\u4EFB\u610F\uFF09","mindmap.noteColor":"\u8AAC\u660E\u306E\u8272","mindmap.noteColorDefault":"\u30CE\u30FC\u30C9\u3068\u540C\u3058","mindmap.collapse":"\u6298\u308A\u305F\u305F\u3080","mindmap.expand":"\u5C55\u958B","mindmap.close":"\u7DE8\u96C6\u3092\u9589\u3058\u308B","mindmap.more":"\u8A73\u7D30\u8A2D\u5B9A"},"ko-KR":{"save.success":"\uC800\uC7A5\uB418\uC5C8\uC2B5\uB2C8\uB2E4","save.fail":"\uC800\uC7A5 \uC2E4\uD328","tool.select":"\uC120\uD0DD \uB3C4\uAD6C","tool.hand":"\uD654\uBA74 \uC774\uB3D9","tool.rectangle":"\uC0AC\uAC01\uD615","tool.rounded-rectangle":"\uB465\uADFC \uC0AC\uAC01\uD615","tool.circle":"\uC6D0","tool.ellipse":"\uD0C0\uC6D0","tool.diamond":"\uB2E4\uC774\uC544\uBAAC\uB4DC","tool.triangle":"\uC0BC\uAC01\uD615","tool.hexagon":"\uC721\uAC01\uD615","tool.parallelogram":"\uD3C9\uD589\uC0AC\uBCC0\uD615","tool.trapezoid":"\uC0AC\uB2E4\uB9AC\uAF34","tool.pentagon":"\uC624\uAC01\uD615","tool.octagon":"\uD314\uAC01\uD615","tool.star":"\uBCC4","tool.cylinder":"\uC6D0\uAE30\uB465","tool.cloud":"\uAD6C\uB984","tool.heart":"\uD558\uD2B8","tool.block-arrow-right":"\uC624\uB978\uCABD \uD654\uC0B4\uD45C","tool.block-arrow-left":"\uC67C\uCABD \uD654\uC0B4\uD45C","tool.block-arrow-up":"\uC704\uCABD \uD654\uC0B4\uD45C","tool.block-arrow-down":"\uC544\uB798\uCABD \uD654\uC0B4\uD45C","tool.block-arrow-double":"\uC591\uBC29\uD5A5 \uD654\uC0B4\uD45C","tool.right-triangle":"\uC9C1\uAC01\uC0BC\uAC01\uD615","tool.cross":"\uC2ED\uC790","tool.speech-rect":"\uC0AC\uAC01\uD615 \uB9D0\uD48D\uC120","tool.speech-round":"\uC6D0\uD615 \uB9D0\uD48D\uC120","tool.cube":"\uC815\uC721\uBA74\uCCB4","tool.sector":"\uBD80\uCC44\uAF34","tool.delay":"D \uC790","tool.predefined-process":"\uC0AC\uC804 \uC815\uC758 \uD504\uB85C\uC138\uC2A4","tool.document":"\uBB38\uC11C","tool.stadium":"\uC591\uB05D\uC774 \uB465\uADFC \uC0AC\uAC01\uD615","tool.class-catalog":"\uCE74\uD14C\uACE0\uB9AC","tool.envelope":"\uBD09\uD22C","tool.checkbox":"\uCCB4\uD06C\uBC15\uC2A4","tool.triangular-pyramid":"\uC0BC\uAC01\uBFD4","tool.quadrangular-pyramid":"\uC0AC\uAC01\uBFD4","tool.cuboid":"\uC9C1\uC721\uBA74\uCCB4","tool.sphere":"\uAD6C","tool.ellipsoid":"\uD0C0\uC6D0\uCCB4","tool.pie":"\uD30C\uC774","tool.hollow-pie":"\uB3C4\uB11B","class.plain":"\uD074\uB798\uC2A4","flow.process":"\uCC98\uB9AC","flow.step":"\uB2E8\uACC4","flow.startEnd":"\uC2DC\uC791/\uC885\uB8CC","flow.decision":"\uD310\uB2E8","flow.data":"\uB370\uC774\uD130","flow.manual":"\uC218\uB3D9 \uC791\uC5C5","flow.preparation":"\uC900\uBE44","flow.database":"\uB370\uC774\uD130\uBCA0\uC774\uC2A4","flow.delay":"\uC9C0\uC5F0","shapeGroup.basic":"\uAE30\uBCF8","shapeGroup.flowchart":"\uC21C\uC11C\uB3C4","shapeGroup.other":"\uAE30\uD0C0","shapeGroup.solid":"\uC785\uCCB4","shapeGroup.uml":"\uD074\uB798\uC2A4 \uB2E4\uC774\uC5B4\uADF8\uB7A8","shapeMenu.hint":"\uB9C8\uC6B0\uC2A4\uB97C \uC62C\uB824 \uC774\uB984 \uD655\uC778","tool.chevron":"\uAEBE\uC1E0","tool.brace-left":"\uC67C\uCABD \uC911\uAD04\uD638","tool.brace-right":"\uC624\uB978\uCABD \uC911\uAD04\uD638","tool.uml-class":"UML \uD074\uB798\uC2A4","tool.uml-interface":"UML \uC778\uD130\uD398\uC774\uC2A4","tool.line":"\uC9C1\uC120","tool.arrow":"\uC120","tool.text":"\uD14D\uC2A4\uD2B8","tool.draw":"\uD39C","tool.pen":"\uD39C","tool.highlighter":"\uD615\uAD11\uD39C","tool.eraser":"\uC9C0\uC6B0\uAC1C","status.none":"\uC120\uD0DD \uC5C6\uC74C","status.selected":"\uB3C4\uD615 {n}\uAC1C \uC120\uD0DD\uB428","toolbar.select":"\uC120\uD0DD (V)","toolbar.hand":"\uD654\uBA74 \uC774\uB3D9 (H)","toolbar.shapes":"\uB3C4\uD615","toolbar.grid":"\uADF8\uB9AC\uB4DC","toolbar.undo":"\uC2E4\uD589 \uCDE8\uC18C (Ctrl+Z)","toolbar.redo":"\uB2E4\uC2DC \uC2E4\uD589 (Ctrl+Shift+Z)","toolbar.arrow":"\uD654\uC0B4\uD45C","toolbar.text":"\uD14D\uC2A4\uD2B8","toolbar.pen":"\uD39C","toolbar.highlighter":"\uD615\uAD11\uD39C","toolbar.eraser":"\uC9C0\uC6B0\uAC1C","toolbar.uml-class":"UML \uD074\uB798\uC2A4","toolbar.uml-interface":"UML \uC778\uD130\uD398\uC774\uC2A4","zoom.in":"\uD655\uB300","zoom.out":"\uCD95\uC18C","zoom.reset":"\uCD08\uAE30\uD654","style.stroke":"\uD14C\uB450\uB9AC","style.line":"\uC120","style.fill":"\uCC44\uC6B0\uAE30","style.text":"\uD14D\uC2A4\uD2B8","style.highlight":"\uD615\uAD11","style.prefix":"\uC811\uB450 \uAE30\uD638","style.prefix.soon":"\uC811\uB450 \uAE30\uD638\uB294 \uC900\uBE44 \uC911\uC785\uB2C8\uB2E4","style.none":"\uC5C6\uC74C","style.addColor":"\uC0C9\uC0C1 \uCD94\uAC00","style.connection":"\uC5F0\uACB0","style.arrow":"\uD654\uC0B4\uD45C","style.dashed":"\uC810\uC120","style.solid":"\uC2E4\uC120","style.opacity":"\uBD88\uD22C\uBA85\uB3C4","style.connection.straight":"\uC9C1\uC120","style.connection.polyline":"\uAEBE\uC740\uC120","style.connection.orthogonal":"\uC9C1\uAC01 \uAEBE\uC740\uC120","style.connection.curve":"\uACE1\uC120","style.arrowhead.none":"\uD654\uC0B4\uD45C \uC5C6\uC74C","style.arrowhead.end":"\uB05D \uD654\uC0B4\uD45C","style.arrowhead.start":"\uC2DC\uC791 \uD654\uC0B4\uD45C","style.arrowhead.both":"\uC591\uBC29\uD5A5 \uD654\uC0B4\uD45C","style.arrowhead.none-dashed":"\uD654\uC0B4\uD45C \uC5C6\uB294 \uC810\uC120","style.arrowhead.both-dashed":"\uC591\uBC29\uD5A5 \uD654\uC0B4\uD45C \uC810\uC120","style.uml":"UML","style.arrowhead.inheritance":"\uC0C1\uC18D","style.arrowhead.composition":"\uD569\uC131","style.arrowhead.aggregation":"\uC9D1\uD569","style.arrowhead.dependency":"\uC758\uC874","style.arrowhead.realization":"\uC2E4\uD604","menu.title":"\uC0C8 \uB3C4\uD615 \uC120\uD0DD","menu.cancel":"\uBE48 \uACF3\uC744 \uD074\uB9AD\uD574 \uCDE8\uC18C","shape.rectangle":"\uC0AC\uAC01\uD615","shape.rounded-rectangle":"\uB465\uADFC","shape.circle":"\uC6D0","shape.ellipse":"\uD0C0\uC6D0","shape.diamond":"\uB2E4\uC774\uC544\uBAAC\uB4DC","shape.triangle":"\uC0BC\uAC01","shape.hexagon":"\uC721\uAC01\uD615","shape.parallelogram":"\uD3C9\uD589","shape.trapezoid":"\uC0AC\uB2E4\uB9AC\uAF34","shape.pentagon":"\uC624\uAC01\uD615","shape.octagon":"\uD314\uAC01\uD615","shape.star":"\uBCC4","shape.uml-class":"\uD074\uB798\uC2A4","shape.uml-interface":"\uC778\uD130\uD398\uC774\uC2A4","uml.drag":"\uB4DC\uB798\uADF8\uD558\uC5EC \uC815\uB82C","uml.delete":"\uC774 \uD589 \uC0AD\uC81C","uml.textColor":"\uAE00\uC790\uC0C9","uml.defaultColor":"\uAE30\uBCF8 \uC0C9\uC0C1","uml.fontSize":"\uAE00\uC790 \uD06C\uAE30","uml.strikethrough":"\uCDE8\uC18C\uC120","uml.attribute":"\uC18D\uC131","uml.method":"\uBA54\uC11C\uB4DC","minimap.title":"\uBBF8\uB2C8\uB9F5","minimap.expand":"\uBBF8\uB2C8\uB9F5 \uD3BC\uCE58\uAE30","minimap.collapse":"\uBBF8\uB2C8\uB9F5 \uC811\uAE30","tool.mind-map":"\uB9C8\uC778\uB4DC\uB9F5","toolbar.mind-map":"\uB9C8\uC778\uB4DC\uB9F5","toolbar.export":"\uB0B4\uBCF4\uB0B4\uAE30","toolbar.export.png":"PNG \uC774\uBBF8\uC9C0","toolbar.export.svg":"SVG \uBCA1\uD130","toolbar.export.pdf":"PDF \uBB38\uC11C","shape.mind-map":"\uB9C8\uC778\uB4DC\uB9F5","mindmap.defaultRoot":"\uC911\uC2EC \uC8FC\uC81C","mindmap.defaultBranch":"\uBD84\uAE30 \uC8FC\uC81C","mindmap.nodeText":"\uB178\uB4DC \uD14D\uC2A4\uD2B8","mindmap.addChild":"\uD558\uC704 \uB178\uB4DC","mindmap.addSibling":"\uD615\uC81C \uB178\uB4DC","mindmap.deleteNode":"\uB178\uB4DC \uC0AD\uC81C","mindmap.color":"\uC0C9\uC0C1","mindmap.levelColor":"\uAE30\uBCF8 \uB2E8\uACC4 \uC0C9\uC0C1","mindmap.icon":"\uC544\uC774\uCF58","mindmap.noIcon":"\uC544\uC774\uCF58 \uC5C6\uC74C","mindmap.note":"\uC18D\uC131 \uC124\uBA85","mindmap.notePlaceholder":"\uC124\uBA85 \uB0B4\uC6A9(\uC120\uD0DD)","mindmap.noteColor":"\uC124\uBA85 \uC0C9\uC0C1","mindmap.noteColorDefault":"\uB178\uB4DC\uC640 \uB3D9\uC77C","mindmap.collapse":"\uC811\uAE30","mindmap.expand":"\uD3BC\uCE58\uAE30","mindmap.close":"\uD3B8\uC9D1 \uB2EB\uAE30","mindmap.more":"\uCD94\uAC00 \uC124\uC815"},"de-DE":{"save.success":"Gespeichert","save.fail":"Speichern fehlgeschlagen","tool.select":"Auswahlwerkzeug","tool.hand":"Ansicht verschieben","tool.rectangle":"Rechteck","tool.rounded-rectangle":"Abgerundetes Rechteck","tool.circle":"Kreis","tool.ellipse":"Ellipse","tool.diamond":"Raute","tool.triangle":"Dreieck","tool.hexagon":"Sechseck","tool.parallelogram":"Parallelogramm","tool.trapezoid":"Trapez","tool.pentagon":"F\xFCnfeck","tool.octagon":"Achteck","tool.star":"Stern","tool.cylinder":"Zylinder","tool.cloud":"Wolke","tool.heart":"Herz","tool.block-arrow-right":"Pfeil rechts","tool.block-arrow-left":"Pfeil links","tool.block-arrow-up":"Pfeil oben","tool.block-arrow-down":"Pfeil unten","tool.block-arrow-double":"Doppelpfeil","tool.right-triangle":"Rechtwinkliges Dreieck","tool.cross":"Kreuz","tool.speech-rect":"Eckige Sprechblase","tool.speech-round":"Runde Sprechblase","tool.cube":"W\xFCrfel","tool.sector":"Kreissektor","tool.delay":"D-Form","tool.predefined-process":"Vordefinierter Prozess","tool.document":"Dokument","tool.stadium":"Stadionform","tool.class-catalog":"Kategorie","tool.envelope":"Umschlag","tool.checkbox":"Kontrollk\xE4stchen","tool.triangular-pyramid":"Dreieckspyramide","tool.quadrangular-pyramid":"Viereckspyramide","tool.cuboid":"Quader","tool.sphere":"Kugel","tool.ellipsoid":"Ellipsoid","tool.pie":"Tortenst\xFCck","tool.hollow-pie":"Donut","class.plain":"Klasse","flow.process":"Prozess","flow.step":"Schritt","flow.startEnd":"Start / Ende","flow.decision":"Entscheidung","flow.data":"Daten","flow.manual":"Manueller Vorgang","flow.preparation":"Vorbereitung","flow.database":"Datenbank","flow.delay":"Verz\xF6gerung","shapeGroup.basic":"Basis","shapeGroup.flowchart":"Flussdiagramm","shapeGroup.other":"Sonstige","shapeGroup.solid":"3D","shapeGroup.uml":"Klassendiagramm","shapeMenu.hint":"Zum Anzeigen des Namens \xFCberfahren","tool.chevron":"Winkelform","tool.brace-left":"Linke Klammer","tool.brace-right":"Rechte Klammer","tool.uml-class":"UML-Klasse","tool.uml-interface":"UML-Schnittstelle","tool.line":"Linie","tool.arrow":"Linie","tool.text":"Text","tool.draw":"Stift","tool.pen":"Stift","tool.highlighter":"Textmarker","tool.eraser":"Radiergummi","status.none":"Nichts ausgew\xE4hlt","status.selected":"{n} Objekte ausgew\xE4hlt","toolbar.select":"Auswahl (V)","toolbar.hand":"Ansicht verschieben (H)","toolbar.shapes":"Formen","toolbar.grid":"Raster","toolbar.undo":"R\xFCckg\xE4ngig (Strg+Z)","toolbar.redo":"Wiederholen (Strg+Umschalt+Z)","toolbar.arrow":"Pfeil","toolbar.text":"Text","toolbar.pen":"Stift","toolbar.highlighter":"Textmarker","toolbar.eraser":"Radiergummi","toolbar.uml-class":"UML-Klasse","toolbar.uml-interface":"UML-Schnittstelle","zoom.in":"Vergr\xF6\xDFern","zoom.out":"Verkleinern","zoom.reset":"Zur\xFCcksetzen","style.stroke":"Rahmen","style.line":"Linie","style.fill":"F\xFCllung","style.text":"Text","style.highlight":"Hervorhebung","style.prefix":"Pr\xE4fix","style.prefix.soon":"Pr\xE4fixsymbole folgen in K\xFCrze","style.none":"Keine","style.addColor":"Farbe hinzuf\xFCgen","style.connection":"Verbindung","style.arrow":"Pfeilspitze","style.dashed":"Gestrichelt","style.solid":"Durchgezogen","style.opacity":"Deckkraft","style.connection.straight":"Gerade","style.connection.polyline":"Polylinie","style.connection.orthogonal":"Rechtwinklig","style.connection.curve":"Kurve","style.arrowhead.none":"Keine","style.arrowhead.end":"Ende","style.arrowhead.start":"Start","style.arrowhead.both":"Beide","style.arrowhead.none-dashed":"Gestrichelt","style.arrowhead.both-dashed":"Gestrichelt beidseitig","style.uml":"UML","style.arrowhead.inheritance":"Vererbung","style.arrowhead.composition":"Komposition","style.arrowhead.aggregation":"Aggregation","style.arrowhead.dependency":"Abh\xE4ngigkeit","style.arrowhead.realization":"Realisierung","menu.title":"Neue Form w\xE4hlen","menu.cancel":"Zum Abbrechen ins Leere klicken","shape.rectangle":"Rechteck","shape.rounded-rectangle":"Abgerundet","shape.circle":"Kreis","shape.ellipse":"Ellipse","shape.diamond":"Raute","shape.triangle":"Dreieck","shape.hexagon":"Sechseck","shape.parallelogram":"Parallelogramm","shape.trapezoid":"Trapez","shape.pentagon":"F\xFCnfeck","shape.octagon":"Achteck","shape.star":"Stern","shape.uml-class":"Klasse","shape.uml-interface":"Schnittstelle","uml.drag":"Zum Sortieren ziehen","uml.delete":"Zeile l\xF6schen","uml.textColor":"Textfarbe","uml.defaultColor":"Standardfarbe","uml.fontSize":"Schriftgr\xF6\xDFe","uml.strikethrough":"Durchgestrichen","uml.attribute":"Attribute","uml.method":"Methoden","minimap.title":"Minikarte","minimap.expand":"Minikarte einblenden","minimap.collapse":"Minikarte ausblenden","tool.mind-map":"Mindmap","toolbar.mind-map":"Mindmap","toolbar.export":"Exportieren","toolbar.export.png":"PNG-Bild","toolbar.export.svg":"SVG-Vektor","toolbar.export.pdf":"PDF-Dokument","shape.mind-map":"Mindmap","mindmap.defaultRoot":"Zentrales Thema","mindmap.defaultBranch":"Unterthema","mindmap.nodeText":"Knotentext","mindmap.addChild":"Unterknoten","mindmap.addSibling":"Geschwisterknoten","mindmap.deleteNode":"Knoten l\xF6schen","mindmap.color":"Farbe","mindmap.levelColor":"Standard-Ebenenfarbe","mindmap.icon":"Symbol","mindmap.noIcon":"Kein Symbol","mindmap.note":"Notiz","mindmap.notePlaceholder":"Notizinhalt (optional)","mindmap.noteColor":"Notizfarbe","mindmap.noteColorDefault":"Wie Knoten","mindmap.collapse":"Einklappen","mindmap.expand":"Ausklappen","mindmap.close":"Editor schlie\xDFen","mindmap.more":"Weitere Einstellungen"},"fr-FR":{"save.success":"Enregistr\xE9","save.fail":"\xC9chec de l'enregistrement","tool.select":"Outil de s\xE9lection","tool.hand":"D\xE9placer la vue","tool.rectangle":"Rectangle","tool.rounded-rectangle":"Rectangle arrondi","tool.circle":"Cercle","tool.ellipse":"Ellipse","tool.diamond":"Losange","tool.triangle":"Triangle","tool.hexagon":"Hexagone","tool.parallelogram":"Parall\xE9logramme","tool.trapezoid":"Trap\xE8ze","tool.pentagon":"Pentagone","tool.octagon":"Octogone","tool.star":"\xC9toile","tool.cylinder":"Cylindre","tool.cloud":"Nuage","tool.heart":"C\u0153ur","tool.block-arrow-right":"Fl\xE8che droite","tool.block-arrow-left":"Fl\xE8che gauche","tool.block-arrow-up":"Fl\xE8che haut","tool.block-arrow-down":"Fl\xE8che bas","tool.block-arrow-double":"Double fl\xE8che","tool.right-triangle":"Triangle rectangle","tool.cross":"Croix","tool.speech-rect":"Bulle rectangulaire","tool.speech-round":"Bulle ronde","tool.cube":"Cube","tool.sector":"Secteur","tool.delay":"Forme D","tool.predefined-process":"Processus pr\xE9d\xE9fini","tool.document":"Document","tool.stadium":"Forme stade","tool.class-catalog":"Cat\xE9gorie","tool.envelope":"Enveloppe","tool.checkbox":"Case \xE0 cocher","tool.triangular-pyramid":"Pyramide triangulaire","tool.quadrangular-pyramid":"Pyramide \xE0 base carr\xE9e","tool.cuboid":"Pav\xE9 droit","tool.sphere":"Sph\xE8re","tool.ellipsoid":"Ellipso\xEFde","tool.pie":"Camembert","tool.hollow-pie":"Anneau","class.plain":"Classe","flow.process":"Traitement","flow.step":"\xC9tape","flow.startEnd":"D\xE9but / Fin","flow.decision":"D\xE9cision","flow.data":"Donn\xE9es","flow.manual":"Op\xE9ration manuelle","flow.preparation":"Pr\xE9paration","flow.database":"Base de donn\xE9es","flow.delay":"D\xE9lai","shapeGroup.basic":"De base","shapeGroup.flowchart":"Organigramme","shapeGroup.other":"Autres","shapeGroup.solid":"3D","shapeGroup.uml":"Diagramme de classes","shapeMenu.hint":"Survolez pour voir le nom","tool.chevron":"Chevron","tool.brace-left":"Accolade gauche","tool.brace-right":"Accolade droite","tool.uml-class":"Classe UML","tool.uml-interface":"Interface UML","tool.line":"Ligne","tool.arrow":"Ligne","tool.text":"Texte","tool.draw":"Stylo","tool.pen":"Stylo","tool.highlighter":"Surligneur","tool.eraser":"Gomme","status.none":"Aucune s\xE9lection","status.selected":"{n} formes s\xE9lectionn\xE9es","toolbar.select":"S\xE9lection (V)","toolbar.hand":"D\xE9placer la vue (H)","toolbar.shapes":"Formes","toolbar.grid":"Grille","toolbar.undo":"Annuler (Ctrl+Z)","toolbar.redo":"R\xE9tablir (Ctrl+Maj+Z)","toolbar.arrow":"Fl\xE8che","toolbar.text":"Texte","toolbar.pen":"Stylo","toolbar.highlighter":"Surligneur","toolbar.eraser":"Gomme","toolbar.uml-class":"Classe UML","toolbar.uml-interface":"Interface UML","zoom.in":"Zoom avant","zoom.out":"Zoom arri\xE8re","zoom.reset":"R\xE9initialiser","style.stroke":"Bordure","style.line":"Ligne","style.fill":"Remplissage","style.text":"Texte","style.highlight":"Surlignage","style.prefix":"Pr\xE9fixe","style.prefix.soon":"Les symboles de pr\xE9fixe arrivent bient\xF4t","style.none":"Aucun","style.addColor":"Ajouter une couleur","style.connection":"Connexion","style.arrow":"Pointe de fl\xE8che","style.dashed":"Pointill\xE9","style.solid":"Continu","style.opacity":"Opacit\xE9","style.connection.straight":"Droite","style.connection.polyline":"Polyligne","style.connection.orthogonal":"Orthogonale","style.connection.curve":"Courbe","style.arrowhead.none":"Aucune","style.arrowhead.end":"Fin","style.arrowhead.start":"D\xE9but","style.arrowhead.both":"Les deux","style.arrowhead.none-dashed":"Pointill\xE9","style.arrowhead.both-dashed":"Pointill\xE9 double","style.uml":"UML","style.arrowhead.inheritance":"H\xE9ritage","style.arrowhead.composition":"Composition","style.arrowhead.aggregation":"Agr\xE9gation","style.arrowhead.dependency":"D\xE9pendance","style.arrowhead.realization":"R\xE9alisation","menu.title":"Choisir une nouvelle forme","menu.cancel":"Cliquez dans le vide pour annuler","shape.rectangle":"Rectangle","shape.rounded-rectangle":"Arrondi","shape.circle":"Cercle","shape.ellipse":"Ellipse","shape.diamond":"Losange","shape.triangle":"Triangle","shape.hexagon":"Hexagone","shape.parallelogram":"Parall\xE9logramme","shape.trapezoid":"Trap\xE8ze","shape.pentagon":"Pentagone","shape.octagon":"Octogone","shape.star":"\xC9toile","shape.uml-class":"Classe","shape.uml-interface":"Interface","uml.drag":"Glisser pour r\xE9ordonner","uml.delete":"Supprimer la ligne","uml.textColor":"Couleur du texte","uml.defaultColor":"Couleur par d\xE9faut","uml.fontSize":"Taille de police","uml.strikethrough":"Barr\xE9","uml.attribute":"Attributs","uml.method":"M\xE9thodes","minimap.title":"Mini-carte","minimap.expand":"D\xE9velopper la mini-carte","minimap.collapse":"R\xE9duire la mini-carte","tool.mind-map":"Carte mentale","toolbar.mind-map":"Carte mentale","toolbar.export":"Exporter","toolbar.export.png":"Image PNG","toolbar.export.svg":"Vecteur SVG","toolbar.export.pdf":"Document PDF","shape.mind-map":"Carte mentale","mindmap.defaultRoot":"Sujet central","mindmap.defaultBranch":"Sous-sujet","mindmap.nodeText":"Texte du n\u0153ud","mindmap.addChild":"N\u0153ud enfant","mindmap.addSibling":"N\u0153ud fr\xE8re","mindmap.deleteNode":"Supprimer le n\u0153ud","mindmap.color":"Couleur","mindmap.levelColor":"Couleur de niveau par d\xE9faut","mindmap.icon":"Ic\xF4ne","mindmap.noIcon":"Aucune ic\xF4ne","mindmap.note":"Note","mindmap.notePlaceholder":"Contenu de la note (facultatif)","mindmap.noteColor":"Couleur de la note","mindmap.noteColorDefault":"Comme le n\u0153ud","mindmap.collapse":"R\xE9duire","mindmap.expand":"D\xE9velopper","mindmap.close":"Fermer l'\xE9diteur","mindmap.more":"Plus de r\xE9glages"}},Le="zh-CN",Ze=new Set;function Ee(a){Le!==a&&(Le=a,Ze.forEach(e=>e()));}function Kt(){return Le}function Xt(a){return Ze.add(a),()=>Ze.delete(a)}function z(a,e){let i=Mt[Le][a]??Mt["zh-CN"][a];if(e)for(let[n,o]of Object.entries(e))i=i.replace(new RegExp(`\\{${n}\\}`,"g"),String(o));return i}var je=["#ef4444","#f59e0b","#10b981","#3b82f6","#8b5cf6","#ec4899"],X=14,Ft=40,Zt=80,jt=240;function oe(a,e){return a.color??je[e%je.length]}function vt(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 Ae(a){let e={...a};return a.children&&(e.children=a.children.map(t=>Ae(t))),e}function He(a,e,t){if(a.id===e)return {...a,...t};let i=a.children??[],n=i.map(o=>He(o,e,t));return n.some((o,r)=>o!==i[r])?{...a,children:n}:a}function qe(a,e,t){if(a.id===e)return {...a,children:[...a.children??[],t],collapsed:false};let i=a.children??[],n=i.map(o=>qe(o,e,t));return n.some((o,r)=>o!==i[r])?{...a,children:n}:a}function Je(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 o=Je(i[n],e,t);if(o!==i[n])return {...a,children:i.map(r=>r===i[n]?o:r)}}return a}function Qe(a,e){if(a.id===e)return null;let t=a.children??[],i=t.map(n=>Qe(n,e)).filter(n=>n!==null);return i.length!==t.length||i.some((n,o)=>n!==t[o])?{...a,children:i}:a}function F(a,e){if(a.id===e)return a;for(let t of a.children??[]){let i=F(t,e);if(i)return i}return null}function Pt(a,e){if(a.id===e)return 0;for(let t of a.children??[]){let i=Pt(t,e);if(i!==-1)return i+1}return -1}function ge(a,e){for(let t of a.children??[]){if(t.id===e)return a;let i=ge(t,e);if(i)return i}return null}function Ct(a){let e=1;for(let t of a.children??[])e+=Ct(t);return e}function It(a,e){e.set(a.id,vt(a));for(let t of a.children??[])It(t,e);}function R(a){let e=new Map;It(a,e);let t=new Map,i=u=>{let p=u.collapsed?[]:u.children??[];if(p.length===0)t.set(u.id,e.get(u.id).height);else {let g=0;for(let y of p)g+=i(y);g+=16*(p.length-1),t.set(u.id,Math.max(e.get(u.id).height,g));}return t.get(u.id)};i(a);let n=new Map,o=(u,p,g,y)=>{let m=t.get(u.id),b=e.get(u.id);if(n.set(u.id,{x:g,y:y+m/2,depth:p,width:b.width,height:b.height}),u.collapsed)return;let x=y;for(let M of u.children??[]){let v=e.get(M.id);o(M,p+1,g+b.width/2+48+v.width/2,x),x+=t.get(M.id)+16;}};o(a,0,0,-t.get(a.id)/2);let r=1/0,s=-1/0,l=1/0,h=-1/0;n.forEach(u=>{r=Math.min(r,u.x-u.width/2),s=Math.max(s,u.x+u.width/2),l=Math.min(l,u.y-u.height/2),h=Math.max(h,u.y+u.height/2);});let c=(r+s)/2,d=(l+h)/2;return n.forEach(u=>{u.x-=c,u.y-=d;}),{positions:n,width:s-r,height:h-l}}var qt={strokeColor:"#1f2937",fillColor:"#f8fafc",fillOpacity:.9,strokeWidth:2,strokeDash:null},Jt={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},envelope:{width:120,height:84},checkbox:{width:90,height:90},"triangular-pyramid":{width:100,height:100},"quadrangular-pyramid":{width:110,height:110},cuboid:{width:150,height:90},sphere:{width:100,height:100},ellipsoid:{width:130,height:90},pie:{width:130,height:90},"hollow-pie":{width:130,height:90}},B=14,k=22,U=36,$=14,T=8,ye=160,Qt=["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","envelope","checkbox","triangular-pyramid","quadrangular-pyramid","cuboid","sphere","ellipsoid","pie","hollow-pie","uml-class","uml-interface","mind-map"];function Re(a){return Qt.includes(a)}function Z(a,e,t){let i=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,n=Jt[a]||{width:120,height:60},o=n.width,r=n.height,s=n.radius??o/2,l=n.borderRadius??8,h=t??{...qt};switch(a){case "rounded-rectangle":return {id:i,type:"rounded-rectangle",x:e.x,y:e.y,width:o,height:r,borderRadius:l,rotation:0,style:h};case "circle":return {id:i,type:"circle",x:e.x,y:e.y,radius:s,rotation:0,style:h};case "ellipse":return {id:i,type:"ellipse",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "diamond":return {id:i,type:"diamond",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "triangle":return {id:i,type:"triangle",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "hexagon":return {id:i,type:"hexagon",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "parallelogram":return {id:i,type:"parallelogram",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "trapezoid":return {id:i,type:"trapezoid",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "pentagon":return {id:i,type:"pentagon",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "octagon":return {id:i,type:"octagon",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};case "star":return {id:i,type:"star",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":return {id:i,type:a,x:e.x,y:e.y,width:o,height:r,rotation:0,style:h};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:p,height:g}=Ve(c,d,u);return {id:i,type:"uml-class",x:e.x,y:e.y,width:p,height:g,className:c,attributes:d,methods:u,rotation:0,style:{...h,fillColor:"#ffffff"}}}case "uml-interface":{let c="Interface",d=[{id:`meth_${Date.now()}_1`,visibility:"+",name:"method",params:"type",returnType:"type"}],u=B*.6,p=d.map(x=>`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`),g=Math.max(c.length,...p.map(x=>x.length),0),y=Math.max(ye,g*u+$*2),m=d.length>0?d.length*k+T*2:T*2,b=U+m;return {id:i,type:"uml-interface",x:e.x,y:e.y,width:y,height:b,className:c,methods:d,rotation:0,style:{...h,fillColor:"#ffffff"}}}case "mind-map":{let c=g=>`mm_${g}_${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:u,height:p}=R(d);return {id:i,type:"mind-map",x:e.x,y:e.y,width:u,height:p,root:d,rotation:0,style:{...h,fillColor:"#ffffff"}}}default:return {id:i,type:"rectangle",x:e.x,y:e.y,width:o,height:r,rotation:0,style:h}}}function Ve(a,e,t){let i=B*.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+$*2,s=Math.max(ye,r),l=e.length>0?e.length*k+T*2:T*2,h=t.length>0?t.length*k+T*2:T*2,c=U+l+h;return {width:s,height:c}}var P=class extends L{type;constructor(e,t){super(e),this.type=t;}onPointerDown(e,t){let i=Z(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 et={n:"top",e:"right",s:"bottom",w:"left"},me={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 fe(a,e,t?me[et[t]]:void 0)}function fe(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 Tt(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 tt=14,$e=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 o=1;o<=n;o++){let r=o/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 tt/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));}};var he=[3,2.2];function J(a,e,t){let i=o=>(o-.5)*e,n=o=>(o-.5)*t;return a.map(o=>o[0]==="Z"?o:o[0]==="M"||o[0]==="L"?[o[0],i(o[1]),n(o[2])]:["C",i(o[1]),n(o[2]),i(o[3]),n(o[4]),i(o[5]),n(o[6])])}function D(a,e,t,i,n,o,r){let s=[],l=o-n,h=Math.max(1,Math.ceil(Math.abs(l)/90)),c=l/h,d=4/3*Math.tan(c*Math.PI/180/4),u=y=>{let m=y*Math.PI/180;return [a+t*Math.cos(m),e+i*Math.sin(m)]},[p,g]=u(n);s.push(r?["M",p,g]:["L",p,g]);for(let y=0;y<h;y++){let m=n+c*y,b=m+c,x=m*Math.PI/180,M=b*Math.PI/180,[v,w]=u(m),[S,C]=u(b);s.push(["C",v-d*t*Math.sin(x),w+d*i*Math.cos(x),S+d*t*Math.sin(M),C-d*i*Math.cos(M),S,C]);}return s}function en(a){let e=1/0,t=1/0,i=-1/0,n=-1/0,o=(p,g)=>{p<e&&(e=p),g<t&&(t=g),p>i&&(i=p),g>n&&(n=g);},r=0,s=0,l=0,h=0;for(let p of a){if(p[0]==="Z"){o(l,h);continue}if(p[0]==="M"||p[0]==="L"){r=p[1],s=p[2],p[0]==="M"&&(l=r,h=s),o(r,s);continue}let g=p[1],y=p[2],m=p[3],b=p[4],x=p[5],M=p[6];for(let v=0;v<=12;v++){let w=v/12,S=1-w,C=S*S*S,H=3*S*S*w,G=3*S*w*w,K=w*w*w;o(C*r+H*g+G*m+K*x,C*s+H*y+G*b+K*M);}r=x,s=M;}let c=i-e||1,d=n-t||1,u=(p,g)=>[(p-e)/c,(g-t)/d];return a.map(p=>{if(p[0]==="Z")return p;if(p[0]==="M"||p[0]==="L"){let[v,w]=u(p[1],p[2]);return [p[0],v,w]}let[g,y]=u(p[1],p[2]),[m,b]=u(p[3],p[4]),[x,M]=u(p[5],p[6]);return ["C",g,y,m,b,x,M]})}function tn(){let a={x:.24,y:.7,r:.24},e={x:.5,y:.48,r:.36},t={x:.76,y:.7,r:.24},i=[...D(a.x,a.y,a.r,a.r,90,246,true),...D(e.x,e.y,e.r,e.r,180,360,false),...D(t.x,t.y,t.r,t.r,294,450,false),["Z"]];return en(i)}var N=.14,ot=.5523,ae=N*ot,xe=1-N,le=.5-.5*ot,nn={outline:[["M",0,N],["L",0,xe],["C",0,xe+ae,le,1,.5,1],["C",1-le,1,1,xe+ae,1,xe],["L",1,N],["C",1,N-ae,1-le,0,.5,0],["C",le,0,0,N-ae,0,N],["Z"]],seams:[[["M",0,N],["C",0,N+ae,le,N*2,.5,N*2],["C",1-le,N*2,1,N+ae,1,N]]],hiddenSeams:[D(.5,xe,.5,N,180,360,true)]},on={outline:tn()},rn={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"]]},Be=[["M",0,.25],["L",.58,.25],["L",.58,0],["L",1,.5],["L",.58,1],["L",.58,.75],["L",0,.75],["Z"]];function nt(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,o]=t(i[1],i[2]),[r,s]=t(i[3],i[4]),[l,h]=t(i[5],i[6]);return ["C",n,o,r,s,l,h]})}var _e={right:Be,left:nt(Be,"left"),up:nt(Be,"up"),down:nt(Be,"down")},sn={outline:[["M",0,0],["L",0,1],["L",1,1],["Z"]]},an={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"]]},ln={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"]]},hn={outline:[["M",0,0],["L",1,0],["L",1,.8],["L",.32,.8],["L",.2,1],["L",.15,.8],["L",0,.8],["Z"]]},cn={outline:[...D(.5,.4,.5,.4,100,-228,true),["L",.19,1],["Z"]]},kt={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]]],hiddenSeams:[[["M",.5,.5],["L",.5,0]],[["M",.5,.5],["L",0,.75]],[["M",.5,.5],["L",1,.75]]]},dn={outline:[...D(.5,.5,.5,.5,0,-270,true),["L",.5,.5],["Z"]]},un={outline:[["M",0,0],...D(.6,.5,.4,.5,270,450,false),["L",0,1],["Z"]]},pn={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]]]},gn={outline:[["M",0,0],["L",1,0],["L",1,.84],["C",.72,1.06,.28,.62,0,.84],["Z"]]},yn={outline:[["M",0,0],["L",.45,0],["L",1,.5],["L",.45,1],["L",0,1],["L",.42,.5],["Z"]]};function mn(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 we=.16,Lt={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},fn={outline:mn(Lt.outline),strokeOnly:true};function ze(a){if(a.type!=="brace-left"&&a.type!=="brace-right")return 0;let e=(a.width??0)*we/2;return a.type==="brace-left"?e:-e}var xn={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]]]},wn={outline:[["M",0,0],["L",1,0],["L",1,1],["L",0,1],["Z"]],seams:[[["M",0,0],["L",1,1]],[["M",1,0],["L",0,1]]]},V=.12,j=V*ot,bn={outline:[["M",V,0],["L",1-V,0],["C",1-V+j,0,1,j,1,V],["L",1,1-V],["C",1,1-V+j,1-V+j,1,1-V,1],["L",V,1],["C",V-j,1,0,1-V+j,0,1-V],["L",0,V],["C",0,V-j,V-j,0,V,0],["Z"]],seams:[[["M",.26,.53],["L",.43,.72],["L",.77,.29]]]},Sn={outline:[["M",.5,.03],["L",.94,.75],["L",.5,.97],["L",.06,.75],["Z"]],seams:[[["M",.5,.03],["L",.5,.97]]],hiddenSeams:[[["M",.06,.75],["L",.94,.75]]]},Mn={outline:[["M",.5,.03],["L",.96,.74],["L",.5,.97],["L",.04,.74],["Z"]],seams:[[["M",.5,.03],["L",.5,.97]]],hiddenSeams:[[["M",.5,.51],["L",.04,.74]],[["M",.5,.51],["L",.96,.74]]]},vn={outline:D(.5,.5,.5,.5,0,360,true),seams:[D(.5,.5,.5,N,0,180,true)],hiddenSeams:[D(.5,.5,.5,N,180,360,true)]},Y=.5,O=.35,q=.3,E=O;function Dt(a){let e=a*Math.PI/180;return [["M",.5,E],["L",.5+Y*Math.cos(e),E+O*Math.sin(e)]]}var Pn={outline:[...D(.5,E,Y,O,180,0,true),["L",1,E+q],...D(.5,E+q,Y,O,0,180,false),["L",0,E],["Z"]],seams:[D(.5,E,Y,O,180,360,true),Dt(300),Dt(120)],hiddenSeams:[D(.5,E+q,Y,O,180,360,true)]},Ge=.2,it=.14,Cn={outline:[...D(.5,E,Y,O,180,0,true),["L",1,E+q],...D(.5,E+q,Y,O,0,180,false),["L",0,E],["Z"],...D(.5,E,Ge,it,0,180,true),["L",.5-Ge,E+q],...D(.5,E+q,Ge,it,180,0,false),["Z"]],seams:[D(.5,E,Y,O,180,360,true),D(.5,E,Ge,it,180,360,true)],hiddenSeams:[D(.5,E+q,Y,O,180,360,true)]};function Ue(a){switch(a){case "cylinder":return nn;case "envelope":return wn;case "checkbox":return bn;case "cuboid":return kt;case "triangular-pyramid":return Sn;case "quadrangular-pyramid":return Mn;case "sphere":case "ellipsoid":return vn;case "pie":return Pn;case "hollow-pie":return Cn;case "cloud":return on;case "heart":return rn;case "class-catalog":return xn;case "block-arrow-right":return {outline:_e.right};case "block-arrow-left":return {outline:_e.left};case "block-arrow-up":return {outline:_e.up};case "block-arrow-down":return {outline:_e.down};case "block-arrow-double":return ln;case "right-triangle":return sn;case "cross":return an;case "speech-rect":return hn;case "speech-round":return cn;case "cube":return kt;case "sector":return dn;case "delay":return un;case "predefined-process":return pn;case "document":return gn;case "chevron":return yn;case "brace-left":return Lt;case "brace-right":return fn;default:return}}var re=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,o,r,s,l,h,c,d,u,p){let g=this.ctx,y=t.getZoom(),m=t.x,b=t.y;g.setTransform(1,0,0,1,0,0),g.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),d&&(g.fillStyle=d,g.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height));let x=this.dpr*y;g.setTransform(x,0,0,x,x*m,x*b),this.showGrid&&this.drawGrid(g,y,m,b);let M=null;for(let w of e)if(w.type==="arrow"&&(w.startBinding||w.endBinding)){M=new Map,e.forEach(S=>M.set(S.id,S));break}let v=M??new Map;if(e.forEach(w=>{g.save(),g.translate(w.x,w.y),g.rotate(w.rotation);let S=i.has(w.id);this.drawShape(g,w,S,y,v,h,c),g.restore();}),s&&this.drawGenerationPreview(g,s,y,e,v),u&&!i.has(u)){let w=e.find(S=>S.id===u);w&&this.drawConnectionDots(g,this.getShapeWorldBounds(w),y,.6);}if(p&&!i.has(p)){let w=e.find(S=>S.id===p);if(w){let S=this.getConnectorRoute(w,v);S.length>=2&&this.drawLinearHighlight(g,S,y,.22,9);}}n&&this.drawBrushRect(g,n,y),o&&o.length>0&&this.drawSnapGuides(g,o,y),r&&this.drawConnectingTargetHighlight(g,r,e,y),l&&this.drawEraserBrush(g,l,y),g.setTransform(1,0,0,1,0,0);}drawEraserBrush(e,t,i){let n=tt/i;e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.fillStyle=_(I.primary,.12),e.fill(),e.strokeStyle=_(I.primary,.55),e.lineWidth=1.5/i,e.stroke();}drawConnectingTargetHighlight(e,t,i,n){let o=i.find(h=>h.id===t);if(!o||o.type==="line"||o.type==="arrow"||o.type==="draw")return;let r=this.getShapeWorldBounds(o),s=[{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}],l=6/n;e.save(),s.forEach(h=>{e.beginPath(),e.arc(h.x,h.y,l,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 o=-i,r=-n,s=o+this.width/t,l=r+this.height/t,h=20;for(;h*t<10;)h*=2;e.strokeStyle=I.grid,e.lineWidth=1/t,e.beginPath();for(let c=Math.floor(o/h)*h;c<=s;c+=h)e.moveTo(c,r),e.lineTo(c,l);for(let c=Math.floor(r/h)*h;c<=l;c+=h)e.moveTo(o,c),e.lineTo(s,c);e.stroke();}drawShape(e,t,i,n,o,r,s){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":case "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":this.drawPathShape(e,t,i,n);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,s);break;case "line":this.drawLine(e,t,o,i,n);break;case "arrow":this.drawArrow(e,t,o,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 l=t.type==="line"||t.type==="arrow";t.type==="mind-map"||(l?this.drawSelectionHandles(e,t,n,o):(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"?_(t.strokeColor,n):t.strokeColor,e.lineWidth=t.strokeWidth/i,e.lineCap="round",e.lineJoin="round";let o=t.fillOpacity??1;o<1&&t.fillColor!=="transparent"?e.fillStyle=_(t.fillColor,o):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:o,borderRadius:r}=t;e.beginPath(),e.roundRect(-n/2,-o/2,n,o,r),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStadium(e,t,i){let{width:n,height:o}=t;e.beginPath(),e.roundRect(-n/2,-o/2,n,o,Math.min(n,o)/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,o=t.height/2;e.beginPath();for(let r=0;r<6;r++){let s=r*Math.PI/3-Math.PI/2,l=n*Math.cos(s),h=o*Math.sin(s);r===0?e.moveTo(l,h):e.lineTo(l,h);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawParallelogram(e,t,i){let{width:n,height:o}=t,r=n*.2;e.beginPath(),e.moveTo(-n/2+r,-o/2),e.lineTo(n/2,-o/2),e.lineTo(n/2-r,o/2),e.lineTo(-n/2,o/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawTrapezoid(e,t,i){let{width:n,height:o}=t,r=n*.15;e.beginPath(),e.moveTo(-n/2+r,-o/2),e.lineTo(n/2-r,-o/2),e.lineTo(n/2,o/2),e.lineTo(-n/2,o/2),e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPentagon(e,t,i){let n=t.width/2,o=t.height/2;e.beginPath();for(let r=0;r<5;r++){let s=r*2*Math.PI/5-Math.PI/2,l=n*Math.cos(s),h=o*Math.sin(s);r===0?e.moveTo(l,h):e.lineTo(l,h);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawOctagon(e,t,i){let n=t.width/2,o=t.height/2;e.beginPath();for(let r=0;r<8;r++){let s=r*Math.PI/4-Math.PI/8,l=n*Math.cos(s),h=o*Math.sin(s);r===0?e.moveTo(l,h):e.lineTo(l,h);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawStar(e,t,i){let n=t.width/2,o=t.height/2,r=5,s=.4;e.beginPath();for(let l=0;l<r*2;l++){let h=l*Math.PI/r-Math.PI/2,c=l%2===0?1:s,d=n*c*Math.cos(h),u=o*c*Math.sin(h);l===0?e.moveTo(d,u):e.lineTo(d,u);}e.closePath(),t.style.fillColor!=="transparent"&&e.fill(),e.stroke();}drawPathShape(e,t,i,n){let o=Ue(t.type);if(o){if(this.tracePath(e,J(o.outline,t.width,t.height)),!o.strokeOnly&&t.style.fillColor!=="transparent"&&e.fill(),e.stroke(),o.seams)for(let r of o.seams)this.tracePath(e,J(r,t.width,t.height)),e.stroke();if(o.hiddenSeams){let r=t.style.strokeWidth||1;e.setLineDash([r*he[0]/n,r*he[1]/n]);for(let s of o.hiddenSeams)this.tracePath(e,J(s,t.width,t.height)),e.stroke();e.setLineDash([]);}}}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:o,className:r,attributes:s,methods:l}=t,h=n/2,c=o/2,d=U,u=s.length>0?s.length*k+T*2:T*2;e.beginPath(),e.rect(-h,-c,n,o),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-h,-c+d),e.lineTo(h,-c+d),e.moveTo(-h,-c+d+u),e.lineTo(h,-c+d+u),e.stroke(),e.save(),e.textBaseline="middle";let p=n-$*2,g=x=>{if(e.measureText(x).width<=p)return x;let M="\u2026",v=0,w=x.length;for(;v<w;){let S=v+w+1>>1;e.measureText(x.slice(0,S)+M).width<=p?v=S:w=S-1;}return x.slice(0,v)+M},y=(x,M,v,w,S,C,H)=>{let G=w||B,K=S||"#1f2937";e.font=`${G}px sans-serif`,e.fillStyle=K,e.textAlign=H;let ue=g(x);if(e.fillText(ue,M,v),C){let xt=e.measureText(ue).width,wt=M;e.strokeStyle=K,e.beginPath(),e.moveTo(wt,v),e.lineTo(wt+xt,v),e.stroke();}};e.font=`bold ${t.fontSize||B}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937",e.fillText(g(r),0,-c+d/2);let m=-c+d+T+k/2;s.forEach((x,M)=>{let v=`${x.visibility} ${x.name}: ${x.type}`;y(v,-h+$,m+M*k,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");});let b=-c+d+u+T+k/2;l.forEach((x,M)=>{let v=`${x.visibility} ${x.name}(${x.params}): ${x.returnType}`;y(v,-h+$,b+M*k,x.fontSize||t.fontSize||0,x.textColor||t.textColor||"",!!x.strikethrough,"left");}),e.restore();}drawUmlInterface(e,t,i){let{width:n,height:o,className:r,methods:s}=t,l=n/2,h=o/2,c=U;e.beginPath(),e.rect(-l,-h,n,o),t.style.fillColor!=="transparent"&&(e.fillStyle=t.style.fillColor,e.fill()),e.stroke(),e.beginPath(),e.moveTo(-l,-h+c),e.lineTo(l,-h+c),e.stroke(),e.save(),e.textBaseline="middle";let d=n-$*2,u=m=>{if(e.measureText(m).width<=d)return m;let b="\u2026",x=0,M=m.length;for(;x<M;){let v=x+M+1>>1;e.measureText(m.slice(0,v)+b).width<=d?x=v:M=v-1;}return m.slice(0,x)+b},p=(m,b,x,M,v,w,S)=>{let C=M||B,H=v||"#1f2937";e.font=`${C}px sans-serif`,e.fillStyle=H,e.textAlign=S;let G=u(m);if(e.fillText(G,b,x),w){let K=e.measureText(G).width,ue=b;e.strokeStyle=H,e.beginPath(),e.moveTo(ue,x),e.lineTo(ue+K,x),e.stroke();}};e.font=`bold ${t.fontSize||B}px sans-serif`,e.textAlign="center",e.fillStyle=t.textColor||"#1f2937";let g=`<<${r||"Interface"}>>`;e.fillText(u(g),0,-h+c/2);let y=-h+c+T+k/2;s.forEach((m,b)=>{let x=`${m.visibility} ${m.name}(${m.params}): ${m.returnType}`;p(x,-l+$,y+b*k,m.fontSize||t.fontSize||0,m.textColor||t.textColor||"",!!m.strikethrough,"left");}),e.restore();}static DEFAULT_CORNER_RADIUS=10;static CONNECTION_LEAD=24;drawMindMap(e,t,i,n,o){let s=R(t.root).positions;this.drawMindMapConnections(e,t.root,s),this.drawMindMapNodes(e,t,s,n,o);}drawMindMapConnections(e,t,i){let n=o=>{if(o.collapsed)return;let r=i.get(o.id);if(r)for(let s of o.children??[]){let l=i.get(s.id);if(!l)continue;let h=oe(s,l.depth);e.strokeStyle=h,e.lineWidth=2,e.lineCap="round",e.beginPath(),e.moveTo(r.x+r.width/2,r.y);let c=(r.x+r.width/2+(l.x-l.width/2))/2;e.bezierCurveTo(c,r.y,c,l.y,l.x-l.width/2,l.y),e.stroke(),n(s);}};n(t);}drawMindMapNodes(e,t,i,n,o){let r=t.root,s=l=>{let h=i.get(l.id);if(!h)return;let c=oe(l,h.depth),d=h.width/2,u=h.height/2;if(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.roundRect(h.x-d,h.y-u,h.width,h.height,6),e.fill(),e.stroke(),o&&o.shapeId===t.id&&o.nodeId===l.id&&(e.fillStyle=_(I.primary,.06),e.strokeStyle=_(I.primary,.55),e.lineWidth=2,e.beginPath(),e.roundRect(h.x-d,h.y-u,h.width,h.height,6),e.fill(),e.stroke()),n&&n.shapeId===t.id&&n.nodeId===l.id&&(e.fillStyle=_(I.primary,.12),e.strokeStyle=I.primary,e.lineWidth=2.5,e.beginPath(),e.roundRect(h.x-d,h.y-u,h.width,h.height,6),e.fill(),e.stroke()),l.children&&l.children.length>0&&(e.fillStyle="#ffffff",e.strokeStyle=c,e.lineWidth=2,e.beginPath(),e.arc(h.x+d+10,h.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(l.collapsed?"+":"\u2212",h.x+d+10,h.y+.5)),l.note){let S=l.noteColor??c;e.font="11px sans-serif";let C=Math.min(e.measureText(l.note).width+12,130),H=16;e.fillStyle=S,e.beginPath(),e.roundRect(h.x-d,h.y-u-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(l.note).width+12>130?l.note.slice(0,12)+"\u2026":l.note,h.x-d+6,h.y-u-H/2+2);}e.font=`${14}px sans-serif`;let m=l.icon?18:0,b=h.width-m-(l.icon?8:0)-16,x=this.ellipsizeText(e,l.text||"",b),M=e.measureText(x).width,v=m+(m?8:0)+M,w=h.x-v/2;if(e.textBaseline="middle",l.icon&&(e.font="16px sans-serif",e.textAlign="left",e.fillStyle="#1f2937",e.fillText(l.icon,w,h.y+1),w+=m+8),e.font=`${14}px sans-serif`,e.textAlign="left",e.fillStyle="#1f2937",e.fillText(x,w,h.y),!l.collapsed)for(let S of l.children??[])s(S);};s(r);}ellipsizeText(e,t,i){if(i<=0)return "";if(e.measureText(t).width<=i)return t;let n="\u2026",o=0,r=t.length;for(;o<r;){let s=o+r+1>>1;e.measureText(t.slice(0,s)+n).width<=i?o=s:r=s-1;}return t.slice(0,o)+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 o=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&&(o=this.resolveAutoEndBinding(e.endBinding,e,i[0],r),i[n]=this.getBindingPoint(r,o));}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(o,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),o=[t[0],t[t.length-1]],[r,s]=n==="curve"?o:this.getAlignedPoints(o);return [r,...i.map(l=>({x:l.x,y:l.y})),s]}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:o,toN:r}=this.resolveConnectorEnds(i,t),l=this.withUserPoints(i,n).map(d=>({x:d.x-e.x,y:d.y-e.y})),h=this.effectiveConnType(i);return (h==="straight"?this.straightAligned(l):this.buildPathPoints(l,h,{fromN:o,toN:r})).map(d=>({x:d.x+e.x,y:d.y+e.y}))}drawSegmentHandles(e,t,i){let n=ke(t);if(n.length===0)return;let o=20/i,r=6/i;e.save(),e.setLineDash([]),e.lineWidth=1.5/i,e.strokeStyle="#ffffff",e.fillStyle=I.primary;for(let s of n){let l=s.axis==="H"?o:r,h=s.axis==="H"?r:o;e.beginPath(),e.roundRect(s.center.x-l/2,s.center.y-h/2,l,h,r/2),e.fill(),e.stroke();}e.restore();}drawLine(e,t,i,n,o){if(t.points.length<2)return;let r=t,{world:s,fromN:l,toN:h}=this.resolveConnectorEnds(r,i),c=this.withUserPoints(r,s).map(p=>({x:p.x-t.x,y:p.y-t.y})),d=this.effectiveConnType(t),u=d==="straight"?this.straightAligned(c):this.buildPathPoints(c,d,{fromN:l,toN:h});if(d==="straight"){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(),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,o),this.drawSegmentHandles(e,u,o));}drawArrow(e,t,i,n,o){if(t.points.length<2)return;let{world:r,fromN:s,toN:l}=this.resolveConnectorEnds(t,i),h=this.withUserPoints(t,r).map(g=>({x:g.x-t.x,y:g.y-t.y})),c=this.effectiveConnType(t),d=t.arrowHead??"end";!!t.dashed||d==="dependency"||d==="realization"?e.setLineDash([8,5]):e.setLineDash([]);let p;if(c==="straight"){let g=this.straightAligned(h);p=g,e.beginPath(),e.moveTo(g[0].x,g[0].y);for(let y=1;y<g.length;y++)e.lineTo(g[y].x,g[y].y);e.stroke(),this.drawArrowHeads(e,g,d);}else p=this.buildPathPoints(h,c,{fromN:s,toN:l}),c==="orthogonal"?this.drawSharpPolyline(e,p):this.drawRoundedPolyline(e,p,a.DEFAULT_CORNER_RADIUS),e.stroke(),this.drawArrowHeads(e,p,d);e.setLineDash([]),n&&(this.drawLinearHighlight(e,p,o),this.drawSegmentHandles(e,p,o));}drawLinearHighlight(e,t,i,n=1,o=7){if(!(!t||t.length<2)){e.save(),e.globalAlpha=n,e.strokeStyle=I.lineHighlight,e.lineWidth=o/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,o){let{from:r,to:s}=t,l=t.arrowStyle??{connectionType:"polyline",arrowHead:"end",dashed:false},h=new Map(o);n.forEach(y=>h.set(y.id,y));let c=t.targetShapeId;if(!c&&t.type){let y=Z(t.type,s);y.id=a.GEN_GHOST_ID,h.set(a.GEN_GHOST_ID,y),c=a.GEN_GHOST_ID;}let d=t.sourceEdge?et[t.sourceEdge]:void 0,u=t.sourceShapeId&&d?{toShapeId:t.sourceShapeId,handle:d}:void 0,p=c?{...t.targetBinding??{auto:true,handle:"left"},toShapeId:c}:void 0,g={id:a.GEN_PREVIEW_ID,type:"arrow",x:r.x,y:r.y,points:[r,s],rotation:0,style:t.lineStyle??a.PREVIEW_LINE_STYLE,startBinding:u,endBinding:p,connectionType:l.connectionType,arrowHead:l.arrowHead,dashed:l.dashed};if(e.save(),t.dragging||(e.globalAlpha=.65),e.translate(r.x,r.y),this.applyStyle(e,g.style,i),this.drawArrow(e,g,h,false,i),e.restore(),t.type){let y=h.get(a.GEN_GHOST_ID),m=y?this.getShapeBounds(y):{x:-60,y:-30,width:120,height:60};this.drawPreviewShapeOutline(e,s,t.type,m,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,o){let r=n.width,s=n.height,l=r/2,h=s/2,c=t.x,d=t.y;switch(e.strokeStyle=I.genLine,e.lineWidth=1.5/o,e.setLineDash([6/o,4/o]),e.beginPath(),i){case "circle":case "ellipse":e.ellipse(c,d,r/2,s/2,0,0,Math.PI*2);break;case "diamond":e.moveTo(c,d-h),e.lineTo(c+l,d),e.lineTo(c,d+h),e.lineTo(c-l,d),e.closePath();break;case "triangle":e.moveTo(c,d-h),e.lineTo(c+l,d+h),e.lineTo(c-l,d+h),e.closePath();break;case "hexagon":for(let u=0;u<6;u++){let p=u*Math.PI/3-Math.PI/2,g=c+l*Math.cos(p),y=d+h*Math.sin(p);u===0?e.moveTo(g,y):e.lineTo(g,y);}e.closePath();break;case "parallelogram":{let u=r*.15;e.moveTo(c-l+u,d-h),e.lineTo(c+l,d-h),e.lineTo(c+l-u,d+h),e.lineTo(c-l,d+h),e.closePath();break}default:e.roundRect(c-l,d-h,r,s,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,o=i.y-t.y,r=a.ALIGN_TOLERANCE;if(Math.abs(o)<=r){let s=(t.y+i.y)/2;return e.map(l=>({x:l.x,y:s}))}if(Math.abs(n)<=r){let s=(t.x+i.x)/2;return e.map(l=>({x:s,y:l.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 o=t[n-1],r=t[n],s=t[n+1],l=r.x-o.x,h=r.y-o.y,c=s.x-r.x,d=s.y-r.y,u=Math.hypot(l,h),p=Math.hypot(c,d);if(u<1e-6||p<1e-6){e.lineTo(r.x,r.y);continue}let g=Math.min(i,u*.5,p*.5),y=r.x-l/u*g,m=r.y-h/u*g,b=r.x+c/p*g,x=r.y+d/p*g;e.lineTo(y,m),e.arcTo(r.x,r.y,b,x,g);}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,o=a.CONNECTION_LEAD,r=e[0],s=e[n];t.fromN&&t.toN&&(t.fromN.x!==0&&t.toN.x!==0?o=Math.min(o,Math.abs(s.x-r.x)/2):t.fromN.y!==0&&t.toN.y!==0&&(o=Math.min(o,Math.abs(s.y-r.y)/2)));for(let l=1;l<e.length;l++){let h=e[l-1],c=e[l],d=l===1,u=l===n,p=d&&t.fromN?{x:h.x+t.fromN.x*o,y:h.y+t.fromN.y*o}:h,g=u&&t.toN?{x:c.x+t.toN.x*o,y:c.y+t.toN.y*o}:c;d&&t.fromN&&i.push(p);let y=d?t.fromN:void 0,m=u?t.toN:void 0,b=m?m.x!==0?"H":"V":y?y.x!==0?"H":"V":void 0,x=this.computeOrthogonalRoute(p,g,b);b&&(x=this.ensureFinalAxis(x,b));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],o=Math.abs(i.y-n.y)<1e-6;if(t==="H"?o:!o)return e;let r=t==="H"?{x:n.x,y:i.y}:{x:i.x,y:n.y},s=e.slice(0,-1);return s.push(r,i),s}collapseLinePoints(e){return pe(e)}computeOrthogonalRoute(e,t,i){let n=t.x-e.x,o=t.y-e.y;if(Math.abs(n)<1||Math.abs(o)<1)return [t];let r=e.x+n/2,s=e.y+o/2,l=Math.max(e.x,Math.min(r,t.x)),h=Math.max(e.y,Math.min(s,t.y));return i==="H"?[{x:l,y:e.y},{x:l,y:t.y},t]:i==="V"?[{x:e.x,y:h},{x:t.x,y:h},t]:Math.abs(n)>=Math.abs(o)?[{x:r,y:e.y},{x:r,y:t.y},t]:[{x:e.x,y:s},{x:t.x,y:s},t]}generateCurvePoints(e,t={}){if(e.length<2)return e;let i=e.length,n=[e[0]],o=l=>{let h=e[l],c=e[l+1];return Math.hypot(c.x-h.x,c.y-h.y)},r=l=>Math.max(16,Math.min(l*.32,150)),s=l=>{let h=e[Math.max(0,l-1)],c=e[Math.min(i-1,l+1)],d=c.x-h.x,u=c.y-h.y,p=Math.hypot(d,u);return p<1e-6?{x:1,y:0}:{x:d/p,y:u/p}};for(let l=0;l<i-1;l++){let h=e[l],c=e[l+1],d=o(l),u;if(l===0&&t.fromN)u={x:h.x+t.fromN.x*r(d),y:h.y+t.fromN.y*r(d)};else {let y=s(l);u={x:h.x+y.x*r(d),y:h.y+y.y*r(d)};}let p;if(l===i-2&&t.toN)p={x:c.x+t.toN.x*r(d),y:c.y+t.toN.y*r(d)};else {let y=s(l+1);p={x:c.x-y.x*r(d),y:c.y-y.y*r(d)};}let g=20;for(let y=1;y<=g;y++){let m=y/g,b=1-m,x=b*b*b*h.x+3*b*b*m*u.x+3*b*m*m*p.x+m*m*m*c.x,M=b*b*b*h.y+3*b*b*m*u.y+3*b*m*m*p.y+m*m*m*c.y;n.push({x,y:M});}}return n}getDisplayLines(e,t,i,n,o,r){let s=n*1.3,l=Math.max(1,Math.floor(r/s)),h=`${t.id}\0${i}\0${n}\0${o}x${r}\0${l}`,c=this.textLayoutCache.get(h);if(c)return c;let d=i.split(`
2
+ `),u=[];for(let g of d){let y=this.wrapLine(e,g,o);for(let m of y)u.push(m);}let p=u.slice(0,l);return u.length>l&&p.length>0&&(p[p.length-1]=this.truncateLine(e,p[p.length-1],o)),this.textLayoutCache.size>=a.TEXT_CACHE_LIMIT&&this.textLayoutCache.clear(),this.textLayoutCache.set(h,p),p}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 o=this.getTextBounds(t),r=n*1.3,s=this.getDisplayLines(e,t,i,n,o.width,o.height),h=-(s.length*r)/2+r/2,c=ze(t);e.textAlign="center",e.textBaseline="middle",s.forEach((d,u)=>{let p=h+u*r;e.fillText(d,c,p);});}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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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-we)*.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=[],o="";for(let r of t){let s=o+r;e.measureText(s).width>i&&o?(n.push(o),o=r):o=s;}return o&&n.push(o),n}truncateLine(e,t,i){if(!t)return "...";let n="...",o=t;for(;o.length>0&&e.measureText(o+n).width>i;)o=o.slice(0,-1);return o+n}static HANDLE_NORMALS=me;pickAutoHandle(e,t,i){return fe(e,t,i)}resolveAutoEndBinding(e,t,i,n){if(!e.auto||e.isPrecise)return e;let o=t.startBinding?.handle?a.HANDLE_NORMALS[t.startBinding.handle]:void 0;return {...e,handle:this.pickAutoHandle(i,{x:n.x,y:n.y},o)}}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},o={x:e.x,y:e.y};return this.nearestPointOnShapeOutline(e,o,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 o=null,r=1/0,s=.5;if(t.forEach((d,u)=>{if(u===i||d.type==="line"||d.type==="arrow")return;let p=this.getShapePageBounds(d);if(e.x>=p.x-s&&e.x<=p.x+p.width+s&&e.y>=p.y-s&&e.y<=p.y+p.height+s){let g=d.id===n?-1:(e.x-d.x)**2+(e.y-d.y)**2;g<r&&(r=g,o=d);}}),!o)return;let l=o,h=e.x-l.x,c=e.y-l.y;return Math.abs(c)>Math.abs(h)?{x:0,y:c<0?-1:1}:{x:h<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 o=null,r=1/0;if(t.forEach((l,h)=>{if(h===i)return;let c=this.getShapePageBounds(l);if(e.x>c.x&&e.x<c.x+c.width&&e.y>c.y&&e.y<c.y+c.height){let d=(l.x-n.x)**2+(l.y-n.y)**2;d<r&&(r=d,o=l);}}),!o)return e;let s=o;return this.nearestPointOnShapeOutline(s,{x:s.x,y:s.y},e)}nearestPointOnShapeOutline(e,t,i){let n=i.x-t.x,o=i.y-t.y,r=Math.hypot(n,o);if(r<1e-6)return {x:t.x,y:t.y};let s=n/r,l=o/r,h=Math.max(1e4,r*2),c={x:t.x+s*h,y:t.y+l*h},d=this.intersectShapeOutlineWithSegment(e,t,c);if(d.length===0)return i;let u=d[0],p=(u.x-t.x)**2+(u.y-t.y)**2;for(let g=1;g<d.length;g++){let y=(d[g].x-t.x)**2+(d[g].y-t.y)**2;y<p&&(p=y,u=d[g]);}return u}intersectShapeOutlineWithSegment(e,t,i){let n={x:t.x-e.x,y:t.y-e.y},o={x:i.x-e.x,y:i.y-e.y};return this.intersectLocalShapeOutlineWithSegment(e,n,o).map(s=>({x:s.x+e.x,y:s.y+e.y}))}intersectLocalShapeOutlineWithSegment(e,t,i){switch(e.type){case "rectangle":case "rounded-rectangle":{let n=e.width,o=e.height,r={x:-n/2,y:-o/2,width:n,height:o};return this.intersectSegmentRect(t,i,r)}case "ellipse":case "diamond":case "triangle":{let n=e.width,o=e.height,r={x:-n/2,y:-o/2,width:n,height:o};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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":case "uml-class":case "uml-interface":{let n=e.width,o=e.height,r={x:-n/2,y:-o/2,width:n,height:o};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,o=i.y,r=i.width,s=i.height,l=[[{x:n,y:o},{x:n+r,y:o}],[{x:n+r,y:o},{x:n+r,y:o+s}],[{x:n+r,y:o+s},{x:n,y:o+s}],[{x:n,y:o+s},{x:n,y:o}]],h=[];for(let[c,d]of l){let u=this.segmentIntersection(e,t,c,d);u&&h.push(u);}return h}segmentIntersection(e,t,i,n){let o=e.x,r=e.y,s=t.x,l=t.y,h=i.x,c=i.y,d=n.x,u=n.y,p=(o-s)*(c-u)-(r-l)*(h-d);if(Math.abs(p)<1e-9)return null;let g=((o-h)*(c-u)-(r-c)*(h-d))/p,y=-((o-s)*(r-c)-(r-l)*(o-h))/p;return g<0||g>1||y<0||y>1?null:{x:o+g*(s-o),y:r+g*(l-r)}}intersectSegmentCircle(e,t,i,n){let o=t.x-e.x,r=t.y-e.y,s=e.x-i.x,l=e.y-i.y,h=o*o+r*r,c=2*(s*o+l*r),d=s*s+l*l-n*n,u=c*c-4*h*d;if(u<0)return [];u=Math.sqrt(u);let p=(-c-u)/(2*h),g=(-c+u)/(2*h),y=[];return p>=0&&p<=1&&y.push({x:e.x+p*o,y:e.y+p*r}),g>=0&&g<=1&&Math.abs(g-p)>1e-6&&y.push({x:e.x+g*o,y:e.y+g*r}),y}drawArrowHead(e,t,i){let n=Math.atan2(i.y-t.y,i.x-t.x),o=12;e.save(),e.setLineDash([]),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x-o*Math.cos(n-Math.PI/6),i.y-o*Math.sin(n-Math.PI/6)),e.moveTo(i.x,i.y),e.lineTo(i.x-o*Math.cos(n+Math.PI/6),i.y-o*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),o=14,r=i.x,s=i.y,l=i.x-o*Math.cos(n),h=i.y-o*Math.sin(n),c=l+o*.5*Math.cos(n-Math.PI/2),d=h+o*.5*Math.sin(n-Math.PI/2),u=l+o*.5*Math.cos(n+Math.PI/2),p=h+o*.5*Math.sin(n+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle="#ffffff",e.beginPath(),e.moveTo(r,s),e.lineTo(c,d),e.lineTo(u,p),e.closePath(),e.fill(),e.stroke(),e.restore();}drawDiamondHead(e,t,i,n){let o=Math.atan2(i.y-t.y,i.x-t.x),r=14,s=i.x,l=i.y,h=i.x-r*.5*Math.cos(o),c=i.y-r*.5*Math.sin(o),d=i.x-r*Math.cos(o),u=i.y-r*Math.sin(o),p=h+r*.4*Math.cos(o-Math.PI/2),g=c+r*.4*Math.sin(o-Math.PI/2),y=h+r*.4*Math.cos(o+Math.PI/2),m=c+r*.4*Math.sin(o+Math.PI/2);e.save(),e.setLineDash([]),e.fillStyle=n?"#1f2937":"#ffffff",e.beginPath(),e.moveTo(s,l),e.lineTo(p,g),e.lineTo(d,u),e.lineTo(y,m),e.closePath(),e.fill(),e.stroke(),e.restore();}drawArrowHeads(e,t,i){if(i!=="none"){if(i==="start"||i==="both"){let n=t[0],o=t[1];this.drawArrowHead(e,o,n);}if(i==="end"||i==="both"){let n=t.length,o=t[n-2],r=t[n-1];this.drawArrowHead(e,o,r);}if(i==="inheritance"){let n=t.length,o=t[n-2],r=t[n-1];this.drawInheritanceHead(e,o,r);}if(i==="aggregation"){let n=t[0],o=t[1];this.drawDiamondHead(e,o,n,false);}if(i==="composition"){let n=t[0],o=t[1];this.drawDiamondHead(e,o,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,o=t.height,r=i*1.3,s=this.getDisplayLines(e,t,t.text,i,n,o),l=s.length*r,h=-l/2+r/2;if(t.highlightColor&&t.highlightColor!=="transparent"){let c=t.highlightOpacity??1;e.fillStyle=c<1?_(t.highlightColor,c):t.highlightColor;let d=i*.15;e.beginPath(),e.roundRect(-n/2-d,-l/2-d,n+d*2,l+d*2,4),e.fill();}e.fillStyle=t.textColor||"#1f2937",s.forEach((c,d)=>{let u=h+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 o=(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,o,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 o=8/i;if((t.type==="line"||t.type==="arrow")&&t.points&&t.points.length>=2){let s=n?this.getConnectorRoute(t,n):[],l=s.length>=2?s:t.points,h={x:l[0].x-t.x,y:l[0].y-t.y},c={x:l[l.length-1].x-t.x,y:l[l.length-1].y-t.y};e.fillStyle=I.selection.handleFill,e.strokeStyle=I.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),[h,c].forEach(d=>{e.beginPath(),e.arc(d.x,d.y,o/2,0,Math.PI*2),e.fill(),e.stroke();});}else {let s=this.getShapeBounds(t),l=o,h=[{x:s.x,y:s.y},{x:s.x+s.width,y:s.y},{x:s.x+s.width,y:s.y+s.height},{x:s.x,y:s.y+s.height}];e.fillStyle=I.selection.handleFill,e.strokeStyle=I.selection.handleStroke,e.lineWidth=2/i,e.setLineDash([]),h.forEach(p=>{e.beginPath(),e.roundRect(p.x-l/2,p.y-l/2,l,l,2),e.fill(),e.stroke();}),this.drawConnectionDots(e,s,i,1);let c=26/i,d=s.x+s.width/2,u=s.y-c;e.strokeStyle="#94a3b8",e.lineWidth=1.5/i,e.setLineDash([]),e.beginPath(),e.moveTo(d,s.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 o=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(s=>{e.beginPath(),e.arc(s.x,s.y,o,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(s.x,s.y,o*.45,0,Math.PI*2),e.fillStyle=I.primary,e.fill();}),e.restore();}drawRotateIcon(e,t,i,n){let o=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,o*.5,Math.PI*.18,Math.PI*1.6,false),e.stroke();let r=Math.PI*.18,s=Math.cos(r)*o*.5,l=Math.sin(r)*o*.5,h=1;e.beginPath(),e.moveTo(s,l),e.lineTo(s-Math.cos(r)*o*.26+h*Math.sin(r)*o*.16,l-Math.sin(r)*o*.26-h*Math.cos(r)*o*.16),e.moveTo(s,l),e.lineTo(s-Math.cos(r)*o*.26-h*Math.sin(r)*o*.16,l-Math.sin(r)*o*.26+h*Math.cos(r)*o*.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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=-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),o=Math.max(o,r.y-e.y);}),{x:t,y:i,width:n-t,height:o-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,o=-1/0,r=-1/0;return t.points.forEach(s=>{let l=s.x-t.x,h=s.y-t.y;i=Math.min(i,l),n=Math.min(n,h),o=Math.max(o,l),r=Math.max(r,h);}),{x:i,y:n,width:o-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 se={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=se.length(a);return e===0?{x:0,y:0}:{x:a.x/e,y:a.y/e}},distance(a,e){return se.length(se.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 Q(a,e,t,i=8){let n=[];if(t==="horizontal"){let o=Math.min(a.x,e.x),r=Math.max(a.x+a.width,e.x+e.width),s=Math.abs(a.y-e.y)<=i,l=Math.abs(a.y+a.height-(e.y+e.height))<=i,h=Math.abs(a.y+a.height/2-(e.y+e.height/2))<=i;s&&n.push({type:"horizontal",position:(a.y+e.y)/2,start:o,end:r}),l&&n.push({type:"horizontal",position:(a.y+a.height+e.y+e.height)/2,start:o,end:r}),h&&!(s&&l)&&n.push({type:"horizontal",position:(a.y+a.height/2+e.y+e.height/2)/2,start:o,end:r});}else {let o=Math.min(a.y,e.y),r=Math.max(a.y+a.height,e.y+e.height),s=Math.abs(a.x-e.x)<=i,l=Math.abs(a.x+a.width-(e.x+e.width))<=i,h=Math.abs(a.x+a.width/2-(e.x+e.width/2))<=i;s&&n.push({type:"vertical",position:(a.x+e.x)/2,start:o,end:r}),l&&n.push({type:"vertical",position:(a.x+a.width+e.x+e.width)/2,start:o,end:r}),h&&!(s&&l)&&n.push({type:"vertical",position:(a.x+a.width/2+e.x+e.width/2)/2,start:o,end:r});}return n}var be=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&&Re(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(),o=this.hitTestArrowTerminal(e,i);if(o&&n.includes(o.shapeId)){this.state="dragging-terminal",this.draggingArrowId=o.shapeId,this.draggingTerminal=o.terminal,this.pendingHistoryCommit=true,this.context.updateArrowBinding(o.shapeId,o.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 s=this.hoverShapeId??this.findHoverAnchorShape(e,i,n),l=this.hitGenPoint(e,i,n,s);if(l){this.state="generating",this.hoverShapeId=s,this.generatingState={source:l,startPoint:e,hasMoved:false,sourceWasSelected:!!l.sourceShapeId&&n.includes(l.sourceShapeId)},this.pendingHistoryCommit=true,this.context.setGenerationPreview(this.genPreviewOf(l,this.genPreviewTarget(l,e,false),{type:this.defaultGenType(l.sourceShapeId)}));return}let h=this.hitTest(e,i,n);if(h.handle==="rotation"){this.state="rotating",this.pendingHistoryCommit=true;let c=h.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(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 c=h.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 p=this.context.getSelectedIds(),g=new Map,y=new Map,m=new Map;p.forEach(b=>{let x=i.find(M=>M.id===b);x&&(g.set(b,{x:x.x,y:x.y}),y.set(b,x.rotation),m.set(b,this.getShapeWorldBounds(x)));}),this.translatingState={startPoint:e,startPositions:g,startRotation:y,startBounds:m};}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(o=>o.id===this.draggingArrowId);if(n){let o=this.draggingTerminal==="start"?e:n.points[n.points.length-1],r=this.draggingTerminal==="start"?n.points[0]:e,s=this.computeSnapGuidesForArrow(o,r,e,n,i);this.context.setSnapGuides(s);let l=e;if(s.length>0){let d=s.filter(p=>p.type==="horizontal"),u=s.filter(p=>p.type==="vertical");if(d.length>0){let p=d[0].position,g=Math.abs(e.y-p);for(let y of d){let m=Math.abs(e.y-y.position);m<g&&(g=m,p=y.position);}l={...l,y:p};}else if(u.length>0){let p=u[0].position,g=Math.abs(e.x-p);for(let y of u){let m=Math.abs(e.x-y.position);m<g&&(g=m,p=y.position);}l={...l,x:p};}}let h=this.draggingTerminal==="start"?0:n.points.length-1,c=[...n.points];c[h]=l,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(),o=this.hitGenPoint(e,i,n,this.hoverShapeId);o?(this.hoverGenPoint=o,this.context.setGenerationPreview(this.genPreviewOf(o,this.genPreviewTarget(o,e,false),{type:this.defaultGenType(o.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 s=this.findHoverConnector(e,i,n);s!==this.hoverConnectorId&&(this.hoverConnectorId=s,this.context.setHoverConnector(s));}}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(),o=i.source,r=this.findBindingNearPoint(e,n,o.sourceShapeId);if(r)this.context.connectToExisting(this.genContext(o,e),r.toShapeId,r.binding);else if(!i.hasMoved)i.sourceWasSelected?this.context.createGeneratedConnection(this.genContext(o,this.genPreviewTarget(o,o.point,false)),{type:this.defaultGenType(o.sourceShapeId)}):o.sourceShapeId&&this.context.selectShape(o.sourceShapeId,false);else {let s=this.defaultGenType(o.sourceShapeId),l=this.avoidSourceOverlap(o,e,s),h=this.context.createFloatingLine(this.genContext(o,this.futureDockPoint(o,l,s)));this.context.openGenerationMenu({context:this.genContext(o,l),existingArrowId:h,defaultShapeType:s});}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 o=this.context.getConnectorRoute(t),r=o.length>=2?o:i.points;for(let s=1;s<r.length;s++)if(this.pointToLineDistance(e,r[s-1],r[s])<=n)return true;return false}findHoverConnector(e,t,i){for(let n=t.length-1;n>=0;n--){let o=t[n];if(!(o.type!=="arrow"&&o.type!=="line")&&!i.includes(o.id)&&this.isPointOnConnector(e,o.id,o))return o.id}return null}hitConnectorSegmentHandle(e,t,i){for(let n of i){let o=t.find(l=>l.id===n);if(!o||o.type!=="arrow"&&o.type!=="line")continue;let r=this.context.getConnectorRoute(n);if(r.length<2)continue;let s=Ye(r,e);if(s)return {shapeId:n,index:s.index,route:r,axis:s.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,Ke(t.route,t.index,r));}writeConnectorRoute(e,t){let i=this.context.getShapes().find(r=>r.id===e);if(!i)return;let n=pe(t);if(i.type==="arrow"&&(!!i.startBinding||!!i.endBinding)){let r=Xe(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 o=this.hitTest(e,t,i);return o.handle==="rotation"?"grab":o.handle?this.getHandleCursor(o.handle,o.shape):o.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 o=((n+t.rotation*180/Math.PI)%360+360)%360,r=Math.round(o/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=se.subtract(e,this.translatingState.startPoint),n={...i};t.shiftKey&&(Math.abs(i.x)>Math.abs(i.y)?n.y=0:n.x=0);let o=this.context.getShapes(),r=this.context.getSelectedIds(),s=new Set(r),l=[],h=[];if(this.translatingState.startBounds.forEach(c=>{h.push({x:c.x+n.x,y:c.y+n.y,width:c.width,height:c.height});}),!t.shiftKey&&h.length>0){let c=[];for(let p of o)s.has(p.id)||p.type==="line"||p.type==="arrow"||p.type==="draw"||c.push(this.getShapeWorldBounds(p));let d=[],u=[];for(let p of h){let g=[p.y,p.y+p.height/2,p.y+p.height],y=[p.x,p.x+p.width/2,p.x+p.width];for(let m of c){let b=[m.y,m.y+m.height/2,m.y+m.height];for(let M of g)for(let v of b){let w=v-M;Math.abs(w)<=a.ALIGN_SNAP_THRESHOLD&&d.push(w);}let x=[m.x,m.x+m.width/2,m.x+m.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 p=d[0];for(let g of d)Math.abs(g)<Math.abs(p)&&(p=g);n.y+=p;}if(u.length>0){let p=u[0];for(let g of u)Math.abs(g)<Math.abs(p)&&(p=g);n.x+=p;}this.translatingState.startBounds.forEach(p=>{let g={x:p.x+n.x,y:p.y+n.y,width:p.width,height:p.height};for(let y of c)l.push(...Q(g,y,"horizontal",1)),l.push(...Q(g,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(l));}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[s,l]=r,h=se.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),p=u.x,g=u.y,y=u.x+u.width,m=u.y+u.height;s===1?y=Math.max(p+d,y+h.x):s===-1&&(p=Math.min(y-d,p+h.x)),l===1?m=Math.max(g+d,m+h.y):l===-1&&(g=Math.min(m-d,g+h.y));let b=(w,S)=>{let C=null;for(let H of S){let G=H-w;Math.abs(G)<=a.ALIGN_SNAP_THRESHOLD&&(C===null||Math.abs(G)<Math.abs(C))&&(C=G);}return C};if(s!==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 S=b(s===1?y:p,w);S!==null&&(s===1?y+=S:p+=S);}if(l!==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 S=b(l===1?m:g,w);S!==null&&(l===1?m+=S:g+=S);}let x={x:p,y:g,width:y-p,height:m-g},M=[];for(let w of c)s!==0&&M.push(...Q(x,w,"vertical",1)),l!==0&&M.push(...Q(x,w,"horizontal",1));this.context.setSnapGuides(this.mergeGuides(M));let v={};if(t.type==="circle"){let w=Math.max(10,Math.max(s!==0?x.width/2:0,l!==0?x.height/2:0));if(v.radius=w,s!==0){let S=s===1?u.x:u.x+u.width;v.x=s===1?S+w:S-w;}if(l!==0){let S=l===1?u.y:u.y+u.height;v.y=l===1?S+w:S-w;}}else if("width"in t&&s!==0&&(v.width=x.width,v.x=x.x+x.width/2),"height"in t&&l!==0&&(v.height=x.height,v.y=x.y+x.height/2),t.type==="draw"){let w=this.getShapeWorldBounds(t),S=s!==0?x.width/Math.max(1,w.width):1,C=l!==0?x.height/Math.max(1,w.height):1;v.points=t.points.map(H=>({x:H.x*S,y:H.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}`,o=t.get(n);o?(o.start=Math.min(o.start,i.start),o.end=Math.max(o.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 o=i.find(r=>r.id===n);o&&this.context.updateShape(n,{rotation:o.rotation+e*Math.PI/180});});}handleNudge(e,t){let i=this.context.getSelectedIds(),n=this.context.getShapes();i.forEach(o=>{let r=n.find(s=>s.id===o);r&&this.context.updateShape(o,{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),o=Math.abs(e.y-this.brushStart.y);this.context.setBrushRect({x:t,y:i,width:n,height:o});let r=this.context.getShapes(),s=[];for(let l of r){let h=this.getShapeWorldBounds(l);this.rectsIntersect({x:t,y:i,width:n,height:o},h)&&s.push(l.id);}if(this.brushShiftKey){let l=this.context.getSelectedIds(),h=new Set([...l,...s]);this.context.selectShapes([...h]);}else this.context.selectShapes(s);}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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=-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),o=Math.max(o,r.y);}),{x:t,y:i,width:n-t,height:o-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 o=1/0,r=1/0,s=-1/0,l=-1/0;return t.points.forEach(h=>{let c=h.x+t.x,d=h.y+t.y;o=Math.min(o,c),r=Math.min(r,d),s=Math.max(s,c),l=Math.max(l,d);}),{x:o,y:r,width:s-o,height:l-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 o=t[n];if(i.includes(o.id)){let r=this.getHitHandle(e,o);if(r)return {shape:o,handle:r}}if(this.isPointInShape(e,o))return {shape:o,handle:null}}return {shape:null,handle:null}}getHitHandle(e,t){if(t.type==="mind-map")return null;let i=14,n=this.getShapeBounds(t),o=Math.cos(-t.rotation),r=Math.sin(-t.rotation),s=e.x-t.x,l=e.y-t.y,h=s*o-l*r,c=s*r+l*o,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(h-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","envelope","checkbox","triangular-pyramid","quadrangular-pyramid","cuboid","sphere","ellipsoid","pie","hollow-pie"]);computeGenPoints(e,t,i){let n=[],o=new Set(t);i&&o.add(i);for(let r of o){let s=e.find(l=>l.id===r);if(s&&a.GEN_SUPPORTED_TYPES.has(s.type)){let l=this.getShapeBounds(s),h={x:s.x,y:s.y};n.push({point:{x:h.x+l.x+l.width/2,y:h.y+l.y},edge:"n",sourceShapeId:s.id}),n.push({point:{x:h.x+l.x+l.width,y:h.y+l.y+l.height/2},edge:"e",sourceShapeId:s.id}),n.push({point:{x:h.x+l.x+l.width/2,y:h.y+l.y+l.height},edge:"s",sourceShapeId:s.id}),n.push({point:{x:h.x+l.x,y:h.y+l.y+l.height/2},edge:"w",sourceShapeId:s.id});}}return n}hitGenPoint(e,t,i,n){let o=a.GEN_HIT_THRESHOLD,r=null,s=o;for(let l of this.computeGenPoints(t,i,n)){let h=Math.hypot(l.point.x-e.x,l.point.y-e.y);h<=s&&(s=h,r=l);}return r}findHoverAnchorShape(e,t,i){for(let o=t.length-1;o>=0;o--){let r=t[o];if(i.includes(r.id)||!a.GEN_SUPPORTED_TYPES.has(r.type))continue;let s=this.getShapeWorldBounds(r);if(!(e.x<s.x-12||e.x>s.x+s.width+12||e.y<s.y-12||e.y>s.y+s.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),s=this.defaultGenType(n.sourceShapeId),l=this.avoidSourceOverlap(n,e,s),h=r?this.bindingPosition(r.toShapeId,r.binding,t):i.hasMoved?l:this.genPreviewTarget(n,e,false);this.context.setConnectingTarget(r?r.toShapeId:null),this.context.setGenerationPreview(this.genPreviewOf(n,h,{dragging:i.hasMoved,targetShapeId:r?.toShapeId,targetBinding:r?.binding,type:r?void 0:s}));}handleRotating(e,t){if(!this.rotatingState)return;let i=this.rotatingState,n=Math.atan2(e.y-i.center.y,e.x-i.center.x),o=i.startRotation+(n-i.startAngle);t.shiftKey&&(o=Math.round(o/(Math.PI/12))*(Math.PI/12)),this.context.updateShape(i.shapeId,{rotation:o});}bindingPosition(e,t,i){let n=i.find(r=>r.id===e);if(!n)return {x:0,y:0};let o=this.getShapeWorldBounds(n);if(t.handle)switch(t.handle){case "top":return {x:n.x,y:o.y};case "bottom":return {x:n.x,y:o.y+o.height};case "left":return {x:o.x,y:n.y};case "right":return {x:o.x+o.width,y:n.y}}return t.normalizedAnchor?{x:o.x+o.width*t.normalizedAnchor.x,y:o.y+o.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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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 o=this.getShapeBounds(t);return Math.abs(i)<=o.width/2&&Math.abs(n)<=o.height/2}case "text":return Math.abs(i)<=50&&Math.abs(n)<=t.fontSize/2;default:return false}}isPointInHexagon(e,t,i,n){let o=Math.abs(e),r=Math.abs(t),s=i/2,l=n/2;return o<=s&&r<=l&&o/s+r/l<=1.5}pointToLineDistance(e,t,i){return Te(e,t,i)}avoidSourceOverlap(e,t,i){if(!e.sourceShapeId)return t;let n=this.context.getShapes().find(g=>g.id===e.sourceShapeId);if(!n)return t;let o=Z(i,t),r=this.getShapeWorldBounds(o),s=this.getShapeWorldBounds(n),l=Math.min(r.x+r.width,s.x+s.width)-Math.max(r.x,s.x),h=Math.min(r.y+r.height,s.y+s.height)-Math.max(r.y,s.y);if(l<=0||h<=0)return t;let c=24,d={...t},u=t.x-n.x,p=t.y-n.y;return Math.abs(u)>=Math.abs(p)?d.x=u>=0?s.x+s.width+c+r.width/2:s.x-c-r.width/2:d.y=p>=0?s.y+s.height+c+r.height/2:s.y-c-r.height/2,d}futureDockPoint(e,t,i){let n=Z(i,t),o=this.getShapeBounds(n),r=Ne(e.point,t,e.edge);return Tt(t,{width:o.width,height:o.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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=-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),o=Math.max(o,r.y-e.y);}),{x:t,y:i,width:n-t,height:o-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,o=-1/0,r=-1/0;return t.points.forEach(s=>{let l=s.x-t.x,h=s.y-t.y;i=Math.min(i,l),n=Math.min(n,h),o=Math.max(o,l),r=Math.max(r,h);}),{x:i,y:n,width:o-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 o=n;if(o.points.length<2)continue;let r=this.context.getConnectorRoute(o.id),s=r.length>=2?r[0]:o.points[0],l=r.length>=2?r[r.length-1]:o.points[o.points.length-1],h=Math.sqrt(Math.pow(e.x-s.x,2)+Math.pow(e.y-s.y,2)),c=Math.sqrt(Math.pow(e.x-l.x,2)+Math.pow(e.y-l.y,2));if(h<20)return {shapeId:o.id,terminal:"start"};if(c<20)return {shapeId:o.id,terminal:"end"}}return null}findShapeNearPoint(e,t,i){for(let o=t.length-1;o>=0;o--){let r=t[o];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let s;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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":case "uml-class":case "uml-interface":s=this.pointToRectDistance(e,{x:r.x-r.width/2,y:r.y-r.height/2,width:r.width,height:r.height});break;case "circle":s=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2))-r.radius;break;case "hexagon":{let l=r.width/2,h=r.height/2,c=Math.abs(e.x-r.x),d=Math.abs(e.y-r.y);s=c/l+d/h-1;break}default:continue}if(s<=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,o){let r=this.draggingTerminal==="start"?n.endBinding:n.startBinding,s=r?o.find(g=>g.id===r.toShapeId):null;if(!s)return [];let l=this.findShapeNearPoint(i,o,n.id);if(!l)return [];let h=this.getShapeWorldBounds(s),c=this.getShapeWorldBounds(l),d=t.x-e.x,u=t.y-e.y,p=Math.abs(d)>=Math.abs(u)?"horizontal":"vertical";return Q(h,c,p)}findBindingNearPoint(e,t,i){let n;for(let o=t.length-1;o>=0;o--){let r=t[o];if(i&&r.id===i||r.type==="arrow"||r.type==="line"||r.type==="draw")continue;let s=this.getPageBounds(r),l=a.SNAP_THRESHOLD;if(e.x<s.x-l||e.x>s.x+s.width+l||e.y<s.y-l||e.y>s.y+s.height+l)continue;let h={x:r.x,y:r.y},c=[{handle:"top",pos:{x:h.x,y:s.y}},{handle:"bottom",pos:{x:h.x,y:s.y+s.height}},{handle:"left",pos:{x:s.x,y:h.y}},{handle:"right",pos:{x:s.x+s.width,y:h.y}}];for(let p of c){let g=Math.hypot(p.pos.x-e.x,p.pos.y-e.y);g<=a.HANDLE_SNAP_DISTANCE&&(!n||g<n.distance)&&(n={toShapeId:r.id,binding:{toShapeId:r.id,handle:p.handle,isPrecise:false},distance:g});}let d=this.nearestPointOnShapeOutline(r,e);if(d&&d.distance<=a.SNAP_THRESHOLD&&(!n||d.distance<n.distance)){let p=this.computeNormalizedAnchor(s,d.point);n={toShapeId:r.id,binding:{toShapeId:r.id,isPrecise:true,normalizedAnchor:p},distance:d.distance};}if(e.x>s.x&&e.x<s.x+s.width&&e.y>s.y&&e.y<s.y+s.height&&(!n||n.distance>0)){let p=e.x-(s.x+s.width/2),g=e.y-(s.y+s.height/2),y=Math.abs(p)>=Math.abs(g)?p>=0?"right":"left":g>=0?"bottom":"top";n={toShapeId:r.id,binding:{toShapeId:r.id,handle:y,isPrecise:false},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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=e.height>0?(t.y-e.y)/e.height:.5;return n=Math.max(i,Math.min(1-i,n)),o=Math.max(i,Math.min(1-i,o)),{x:n,y:o}}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 o={x:n.point.x+e.x,y:n.point.y+e.y};return {point:o,distance:Math.hypot(o.x-t.x,o.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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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[o,r]of i){let s=this.nearestPointOnSegment(e,o,r);(!n||s.distance<n.distance)&&(n=s);}return n}nearestPointOnCircleOutlineLocal(e,t,i){let n=e.x-t.x,o=e.y-t.y,r=Math.hypot(n,o);if(r<1e-9)return {point:{x:t.x+i,y:t.y},distance:i};let s=t.x+n/r*i,l=t.y+o/r*i,h={x:s,y:l};return {point:h,distance:Math.hypot(h.x-e.x,h.y-e.y)}}nearestPointOnSegment(e,t,i){let n=i.x-t.x,o=i.y-t.y,r=n*n+o*o,s=r>0?((e.x-t.x)*n+(e.y-t.y)*o)/r:0;s=Math.max(0,Math.min(1,s));let l=t.x+s*n,h=t.y+s*o,c={x:l,y:h};return {point:c,distance:Math.hypot(c.x-e.x,c.y-e.y)}}};var Se=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 In={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},Me=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:{...In}},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 Tn={strokeColor:"#1f2937",fillColor:"transparent",fillOpacity:1,strokeWidth:4,strokeDash:null},kn=.5,Dn=16,Oe="#ffeb3b",Ln=4200,ee=class extends L{type;mode;isDrawing=false;points=[];currentShapeId=null;committed=false;fadeTimer=null;highlighterColor=Oe;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"?{...Tn}:{strokeColor:_(this.highlighterColor,kn),fillColor:"transparent",fillOpacity:1,strokeWidth:Dn,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,o=-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>o&&(o=u.y);let r=(t+n)/2,s=(i+o)/2,l=6,h=Math.max(1,n-t)+l*2,c=Math.max(1,o-i)+l*2,d=e.map(u=>({x:u.x-r,y:u.y-s}));return {x:r,y:s,width:h,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),o=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:o};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);},Ln));}onKeyDown(e){}onKeyUp(e){}getCursor(){return "crosshair"}dispose(){this.fadeTimer&&(clearTimeout(this.fadeTimer),this.fadeTimer=null);}};var En={strokeColor:"#1f2937",fillColor:"transparent",strokeWidth:2,strokeDash:null},An=4,ve=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),o=e;n&&(o=this.getBindingPosition(n.toShapeId,n.handle,i),this.startBindingInfo={...n,position:o}),this.startPoint=o,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),o=e;n&&(o=this.getBindingPosition(n.toShapeId,n.handle,i));let r=this.startPoint;if(!this.currentShapeId){if(Math.hypot(o.x-r.x,o.y-r.y)<An)return;let h=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,c=this.context.getArrowStyle(),d={id:h,type:"arrow",x:r.x,y:r.y,points:[r,o],rotation:0,style:{...En},startBinding:this.startBinding,connectionType:c.connectionType,arrowHead:c.arrowHead,dashed:c.dashed};this.context.commitHistory(),this.context.addShape(d),this.currentShapeId=h;}let s=this.computeSnapGuides(r,o,n,i);this.context.setSnapGuides(s),this.context.updateShape(this.currentShapeId,{points:[r,o],endBinding:n?{toShapeId:n.toShapeId,handle:n.handle}: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 o=this.startBindingInfo?n.find(u=>u.id===this.startBindingInfo.toShapeId):null,r=i?n.find(u=>u.id===i.toShapeId):null;if(!o||!r)return [];let s=this.getShapeBounds(o),l=this.getShapeBounds(r),h=t.x-e.x,c=t.y-e.y,d=Math.abs(h)>=Math.abs(c)?"horizontal":"vertical";return Q(s,l,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 o=t[n];if(o.type==="arrow"||o.type==="line"||o.type==="draw")continue;let r;switch(o.type){case "rectangle":case "rounded-rectangle":case "ellipse":case "diamond":case "triangle":case "uml-class":case "uml-interface":r=this.pointToRectDistance(e,{x:o.x-o.width/2,y:o.y-o.height/2,width:o.width,height:o.height});break;case "circle":{let s=Math.sqrt(Math.pow(e.x-o.x,2)+Math.pow(e.y-o.y,2));r=Math.abs(s-o.radius);break}case "hexagon":{let s=o.width/2,l=o.height/2,h=Math.abs(e.x-o.x),c=Math.abs(e.y-o.y);r=h/s+c/l-1;break}default:continue}if(r<=40){let s=this.getClosestHandle(e,o);return {toShapeId:o.id,handle:s}}}}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 h=Math.atan2(n,i);return h>=-Math.PI/4&&h<Math.PI/4?"right":h>=Math.PI/4&&h<3*Math.PI/4?"bottom":h>=3*Math.PI/4||h<-(3*Math.PI)/4?"left":"top"}let o="width"in t?t.width:100,r="height"in t?t.height:100,s=Math.abs(i)/(o/2),l=Math.abs(n)/(r/2);return s>l?i>0?"right":"left":n>0?"bottom":"top"}getBindingPosition(e,t,i){let n=i.find(o=>o.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 Hn={strokeColor:"transparent",fillColor:"transparent",strokeWidth:0,strokeDash:null},We=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:{...Hn},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 ce="#1f2937";function lt(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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=-1/0;for(let r of e){let s=r.x-a.x,l=r.y-a.y;t=Math.min(t,s),i=Math.min(i,l),n=Math.max(n,s),o=Math.max(o,l);}return {x:t,y:i,width:n-t,height:o-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 o=1/0,r=1/0,s=-1/0,l=-1/0;for(let h of n)o=Math.min(o,h.x),r=Math.min(r,h.y),s=Math.max(s,h.x),l=Math.max(l,h.y);return {x:o,y:r,width:s-o,height:l-r}}default:return {x:0,y:0,width:0,height:0}}}function Rn(a){let e=lt(a),t=Math.cos(a.rotation),i=Math.sin(a.rotation),n=1/0,o=1/0,r=-1/0,s=-1/0,l=[[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[h,c]of l){let d=h*t-c*i+a.x,u=h*i+c*t+a.y;n=Math.min(n,d),o=Math.min(o,u),r=Math.max(r,d),s=Math.max(s,u);}return {x:n,y:o,width:r-n,height:s-o}}function Ie(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,o=-1/0;for(let r of a){let s=Rn(r);t=Math.min(t,s.x),i=Math.min(i,s.y),n=Math.max(n,s.x+s.width),o=Math.max(o,s.y+s.height);}return {x:t-e,y:i-e,width:n-t+e*2,height:o-i+e*2}}function Nt(a,e={}){let t=e.padding??24,i=e.scale??2,n=e.background===void 0?"#ffffff":e.background??null,o=Ie(a,t),r=Math.max(1,Math.ceil(o.width)),s=Math.max(1,Math.ceil(o.height)),l=document.createElement("canvas");l.width=Math.ceil(r*i),l.height=Math.ceil(s*i);let h=new re(l,i);h.resize(r*i,s*i);let c=new ie;return c.zoom=1,c.x=-o.x,c.y=-o.y,h.render(a,c,new Set,void 0,void 0,void 0,void 0,void 0,void 0,void 0,n),l}function Vn(a,e,t){return new Promise((i,n)=>{a.toBlob(o=>{o?i(o):n(new Error("canvas.toBlob failed"));},e,t);})}function Nn(a,e,t){return a.toDataURL(e,t)}var Pe=null;function ne(a,e){return Pe||(Pe=document.createElement("canvas").getContext("2d")),Pe?(Pe.font=e,Pe.measureText(a).width):a.length*8}function de(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function ht(a,e,t,i){let n=e*1.3,o=Math.max(1,Math.floor(i/n)),r=`${e}px sans-serif`,s=a.split(`
3
+ `),l=[];for(let c of s){let d="";for(let u of c){let p=d+u;ne(p,r)>t&&d?(l.push(d),d=u):d=p;}d&&l.push(d);}let h=l.slice(0,o);if(l.length>o&&h.length>0){let c=h[h.length-1],d="...";for(;c.length>0&&ne(c+d,r)>t;)c=c.slice(0,-1);h[h.length-1]=c+d;}return h}function ct(a,e,t){if(ne(a,t)<=e)return a;let i="\u2026",n=0,o=a.length;for(;n<o;){let r=n+o+1>>1;ne(a.slice(0,r)+i,t)<=e?n=r:o=r-1;}return a.slice(0,n)+i}function te(a){return a.map(([e,t])=>`${f(e)},${f(t)}`).join(" ")}function rt(a){return a.map(e=>e[0]==="Z"?"Z":e[0]==="M"||e[0]==="L"?`${e[0]} ${f(e[1])} ${f(e[2])}`:`C ${f(e[1])} ${f(e[2])} ${f(e[3])} ${f(e[4])} ${f(e[5])} ${f(e[6])}`).join(" ")}function $n(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),o=e.height??(e.radius?e.radius*2:40),r=n*(i?1-we:1)*.85,s=o*.85,l=ht(String(e.text),t,r,s);return pt(l,t,e.textColor||ce,f(ze(a)))}function f(a){return Math.round(a*100)/100}function $t(a){return a.strokeDash&&a.strokeDash.length?a.strokeDash.join(","):void 0}function Bn(a,e){let t=e.x-a.x,i=e.y-a.y,n=Math.cos(a.rotation),o=Math.sin(a.rotation);return {x:t*n-i*o+a.x,y:t*o+i*n+a.y}}var dt=me;function _n(a,e,t){return fe(a,e,t)}function Gn(a,e,t){let i=a.endBinding;if(!i||!i.auto||i.isPrecise)return i;let n=a.startBinding?.handle?dt[a.startBinding.handle]:void 0;return {...i,handle:_n(e,{x:t.x,y:t.y},n)}}function Et(a,e){if(e.isPrecise&&e.normalizedAnchor){let t=lt(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=lt(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 zn(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]=Et(r,a.startBinding),!a.startBinding.isPrecise&&a.startBinding.handle&&(i=dt[a.startBinding.handle]));}if(a.endBinding){let r=e.get(a.endBinding.toShapeId);if(r){let s=Gn(a,t[0],r)??a.endBinding;t[t.length-1]=Et(r,s),!s.isPrecise&&s.handle&&(n=dt[s.handle]);}}let o=t;if(a.userPoints&&a.userPoints.length>0&&t.length>=2){let r=ut([t[0],t[t.length-1]]),s=a.connectionType||"straight",[l,h]=s==="curve"?[t[0],t[t.length-1]]:r;o=[l,...a.userPoints.map(c=>({...c})),h];}return {pts:o.map(r=>Bn(a,r)),fromN:i,toN:n}}function ut(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,o=8;if(Math.abs(n)<=o){let r=(e.y+t.y)/2;return a.map(s=>({x:s.x,y:r}))}if(Math.abs(i)<=o){let r=(e.x+t.x)/2;return a.map(s=>({x:r,y:s.y}))}return a}function Un(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],o=(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:o,y:i.y}),e.push({x:o,y:n.y})):(e.push({x:i.x,y:r}),e.push({x:n.x,y:r})),e.push(n);}return e}function On(a){if(a.length<2)return "";let e=`M ${f(a[0].x)} ${f(a[0].y)}`,t=a[0];for(let i=1;i<a.length;i++){let n=a[i],o=n.x-t.x,r=n.y-t.y,s=Math.hypot(o,r),l={x:(t.x+n.x)/2,y:(t.y+n.y)/2};if(s>=1){let h=-r/s,c=o/s,d=Math.min(s*.2,30);l={x:l.x+h*d,y:l.y+c*d};}e+=` Q ${f(l.x)} ${f(l.y)} ${f(n.x)} ${f(n.y)}`,t=n;}return e}var Wn=24;function Yn(a,e,t,i){let n=Wn;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 o=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,s=[a];t&&s.push(o);let l=r.x-o.x,h=r.y-o.y;if(Math.abs(l)<1||Math.abs(h)<1)s.push(r);else {let c=o.x+l/2,d=o.y+h/2,u=Math.max(o.x,Math.min(c,r.x)),p=Math.max(o.y,Math.min(d,r.y)),g=i?i.x!==0?"H":"V":t?t.x!==0?"H":"V":void 0;g==="H"?s.push({x:u,y:o.y},{x:u,y:r.y},r):g==="V"?s.push({x:o.x,y:p},{x:r.x,y:p},r):Math.abs(l)>=Math.abs(h)?s.push({x:c,y:o.y},{x:c,y:r.y},r):s.push({x:o.x,y:d},{x:r.x,y:d},r);}return i&&s.push(e),s}function At(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],o=e[i-1];if(Math.abs(n.y-o.y)<1e-6&&Math.abs(o.y-t.y)<1e-6||Math.abs(n.x-o.x)<1e-6&&Math.abs(o.x-t.x)<1e-6){e[i-1]=t;continue}}e.push(t);}}return e}function Kn(a,e,t,i,n=false){if(e==="curve")return On(a);let o=n&&e==="straight"?"polyline":e,r;if(o==="straight")r=a.length===2?ut(a):a;else if(a.length===2){let l=ut(a);r=At(Yn(l[0],l[1],t,i));}else r=At(Un(a));if(r.length<2)return "";let s=`M ${f(r[0].x)} ${f(r[0].y)}`;for(let l=1;l<r.length;l++)s+=` L ${f(r[l].x)} ${f(r[l].y)}`;return s}function st(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),o=12,r={x:e.x-o*Math.cos(n-Math.PI/6),y:e.y-o*Math.sin(n-Math.PI/6)},s={x:e.x-o*Math.cos(n+Math.PI/6),y:e.y-o*Math.sin(n+Math.PI/6)};return `<path d="M ${f(e.x)} ${f(e.y)} L ${f(r.x)} ${f(r.y)} M ${f(e.x)} ${f(e.y)} L ${f(s.x)} ${f(s.y)}" stroke="${t}" stroke-width="${i}" stroke-linecap="round" fill="none" />`}function Ht(a,e,t,i){let n=Math.atan2(e.y-a.y,e.x-a.x),o=14,r=e.x,s=e.y,l=e.x-o*Math.cos(n),h=e.y-o*Math.sin(n),c=l+o*.5*Math.cos(n-Math.PI/2),d=h+o*.5*Math.sin(n-Math.PI/2),u=l+o*.5*Math.cos(n+Math.PI/2),p=h+o*.5*Math.sin(n+Math.PI/2);return `<polygon points="${f(r)},${f(s)} ${f(c)},${f(d)} ${f(u)},${f(p)}" fill="#ffffff" stroke="${t}" stroke-width="${i}" />`}function Rt(a,e,t,i,n){let o=Math.atan2(e.y-a.y,e.x-a.x),r=14,s=e.x,l=e.y,h=e.x-r*.5*Math.cos(o),c=e.y-r*.5*Math.sin(o),d=e.x-r*Math.cos(o),u=e.y-r*Math.sin(o),p=h+r*.4*Math.cos(o-Math.PI/2),g=c+r*.4*Math.sin(o-Math.PI/2),y=h+r*.4*Math.cos(o+Math.PI/2),m=c+r*.4*Math.sin(o+Math.PI/2);return `<polygon points="${f(s)},${f(l)} ${f(p)},${f(g)} ${f(d)},${f(u)} ${f(y)},${f(m)}" fill="${n?t:"#ffffff"}" stroke="${t}" stroke-width="${i}" />`}function Xn(a,e,t,i){if(e==="none"||a.length<2)return "";let n="";return (e==="start"||e==="both")&&(n+=st(a[1],a[0],t,i)),(e==="end"||e==="both")&&(n+=st(a[a.length-2],a[a.length-1],t,i)),e==="inheritance"&&(n+=Ht(a[a.length-2],a[a.length-1],t,i)),e==="aggregation"&&(n+=Rt(a[1],a[0],t,i,false)),e==="composition"&&(n+=Rt(a[1],a[0],t,i,true)),e==="dependency"&&(n+=st(a[a.length-2],a[a.length-1],t,i)),e==="realization"&&(n+=Ht(a[a.length-2],a[a.length-1],t,i)),n}function pt(a,e,t,i=0,n=0){if(a.length===0)return "";let o=e*1.3,s=-(a.length*o)/2+o/2,l=a.map((h,c)=>`<tspan x="${f(i)}" y="${f(n+s+c*o)}">${de(h)}</tspan>`).join("");return `<text text-anchor="middle" dominant-baseline="central" font-family="sans-serif" font-size="${e}" fill="${t}">${l}</text>`}function A(a,e,t){let i=t??$t(a),n=e&&a.fillColor!=="transparent",o=a.fillOpacity??1,r=a.strokeOpacity??1;return [n?`fill="${a.fillColor}"`:'fill="none"',n&&o<1?`fill-opacity="${f(o)}"`:"",`stroke="${a.strokeColor}"`,r<1&&a.strokeColor!=="transparent"?`stroke-opacity="${f(r)}"`:"",`stroke-width="${a.strokeWidth}"`,'stroke-linecap="round"','stroke-linejoin="round"',i?`stroke-dasharray="${i}"`:""].filter(Boolean).join(" ")}function Vt(a,e){let{width:t,height:i}=a,n=t/2,o=i/2,r=`${B}px sans-serif`,s=U,l=e?0:a.attributes.length>0?a.attributes.length*k+T*2:T*2,h=t-$*2,c=[];c.push(`<rect x="${f(-n)}" y="${f(-o)}" width="${t}" height="${i}" ${A(a.style,true)} />`),c.push(`<line x1="${f(-n)}" y1="${f(-o+s)}" x2="${f(n)}" y2="${f(-o+s)}" stroke="${a.style.strokeColor}" stroke-width="${a.style.strokeWidth}" />`),e||c.push(`<line x1="${f(-n)}" y1="${f(-o+s+l)}" x2="${f(n)}" y2="${f(-o+s+l)}" 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="${B}" fill="${a.textColor||ce}" x="0" y="${f(-o+s/2)}">${de(ct(d,h,r))}</text>`);let u=(g,y,m,b,x)=>{let M=`${m||B}px sans-serif`,v=ct(g,h,M),w=`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${m||B}" fill="${b||ce}" x="${f(-n+$)}" y="${f(y)}">${de(v)}</text>`;if(x){let S=ne(v,M);w+=`<line x1="${f(-n+$)}" y1="${f(y)}" x2="${f(-n+$+S)}" y2="${f(y)}" stroke="${b||ce}" stroke-width="1" />`;}return w};if(!e){let g=-o+s+T+k/2;a.attributes.forEach((y,m)=>{c.push(u(`${y.visibility} ${y.name}: ${y.type}`,g+m*k,y.fontSize||a.fontSize||0,y.textColor||a.textColor||"",!!y.strikethrough));});}let p=-o+s+l+T+k/2;return a.methods.forEach((g,y)=>{c.push(u(`${g.visibility} ${g.name}(${g.params}): ${g.returnType}`,p+y*k,g.fontSize||a.fontSize||0,g.textColor||a.textColor||"",!!g.strikethrough));}),c.join("")}function Fn(a){let t=R(a.root).positions,i=[],n=r=>{if(r.collapsed)return;let s=t.get(r.id);if(s)for(let l of r.children??[]){let h=t.get(l.id);if(!h)continue;let c=oe(l,h.depth),d=a.x+s.x+s.width/2,u=a.y+s.y,p=a.x+h.x-h.width/2,g=a.y+h.y,y=(d+p)/2;i.push(`<path d="M ${f(d)} ${f(u)} C ${f(y)} ${f(u)} ${f(y)} ${f(g)} ${f(p)} ${f(g)}" stroke="${c}" stroke-width="2" fill="none" stroke-linecap="round" />`),n(l);}};n(a.root);let o=r=>{let s=t.get(r.id);if(!s)return;let l=oe(r,s.depth),h=s.width/2,c=s.height/2,d=a.x+s.x,u=a.y+s.y;if(i.push(`<rect x="${f(d-h)}" y="${f(u-c)}" width="${s.width}" height="${s.height}" rx="6" ry="6" fill="#ffffff" stroke="${l}" stroke-width="2" />`),r.note){let M="11px sans-serif",v=r.noteColor??l,w=Math.min(ne(r.note,M)+12,130),S=16,C=ne(r.note,M)+12>130?r.note.slice(0,12)+"\u2026":r.note;i.push(`<rect x="${f(d-h)}" y="${f(u-c-S+2)}" width="${w}" height="${S}" 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="${f(d-h+6)}" y="${f(u-c-S/2+2)}">${de(C)}</text>`);}let p=r.icon?18:0,g=s.width-p-(r.icon?8:0)-16,y=ct(r.text||"",g,`${14}px sans-serif`),m=ne(y,`${14}px sans-serif`),b=p+(p?8:0)+m,x=d-b/2;if(r.icon&&(i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="16" fill="#1f2937" x="${f(x)}" y="${f(u)}">${de(r.icon)}</text>`),x+=p+8),i.push(`<text text-anchor="start" dominant-baseline="central" font-family="sans-serif" font-size="${14}" fill="#1f2937" x="${f(x)}" y="${f(u)}">${de(y)}</text>`),r.children&&r.children.length>0&&!r.collapsed)for(let M of r.children)o(M);};return o(a.root),i.join("")}function Zn(a,e){let t=a.rotation*180/Math.PI,i=`<g transform="translate(${f(a.x)} ${f(a.y)}) rotate(${f(t)})">`,n=`${$n(a)}</g>`,o=a.style;switch(a.type){case "rectangle":{let r=a.width,s=a.height;return `${i}<rect x="${f(-r/2)}" y="${f(-s/2)}" width="${r}" height="${s}" ${A(o,true)} />${n}`}case "rounded-rectangle":{let r=a.width,s=a.height,l=a.borderRadius||8;return `${i}<rect x="${f(-r/2)}" y="${f(-s/2)}" width="${r}" height="${s}" rx="${l}" ry="${l}" ${A(o,true)} />${n}`}case "stadium":{let r=a.width,s=a.height,l=Math.min(r,s)/2;return `${i}<rect x="${f(-r/2)}" y="${f(-s/2)}" width="${r}" height="${s}" rx="${l}" ry="${l}" ${A(o,true)} />${n}`}case "circle":{let r=a.radius;return `${i}<circle cx="0" cy="0" r="${r}" ${A(o,true)} />${n}`}case "ellipse":{let r=a.width,s=a.height;return `${i}<ellipse cx="0" cy="0" rx="${r/2}" ry="${s/2}" ${A(o,true)} />${n}`}case "diamond":{let r=a.width,s=a.height;return `${i}<polygon points="${te([[0,-s/2],[r/2,0],[0,s/2],[-r/2,0]])}" ${A(o,true)} />${n}`}case "triangle":{let r=a.width,s=a.height;return `${i}<polygon points="${te([[0,-s/2],[r/2,s/2],[-r/2,s/2]])}" ${A(o,true)} />${n}`}case "hexagon":{let r=a.width,s=a.height;return `${i}<polygon points="${te(at(r,s,6,-Math.PI/2))}" ${A(o,true)} />${n}`}case "pentagon":{let r=a.width,s=a.height;return `${i}<polygon points="${te(at(r,s,5,-Math.PI/2))}" ${A(o,true)} />${n}`}case "octagon":{let r=a.width,s=a.height;return `${i}<polygon points="${te(at(r,s,8,-Math.PI/8))}" ${A(o,true)} />${n}`}case "star":{let r=a.width,s=a.height;return `${i}<polygon points="${te(jn(r,s))}" ${A(o,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":case "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":{let r=a.width,s=a.height,l=Ue(a.type);if(!l)return "";let h=`<path d="${rt(J(l.outline,r,s))}" ${A(o,!l.strokeOnly)} />`,c=(l.seams??[]).map(p=>`<path d="${rt(J(p,r,s))}" ${A({...o,fillColor:"transparent"},true)} />`).join(""),d=`${f(o.strokeWidth*he[0])},${f(o.strokeWidth*he[1])}`,u=(l.hiddenSeams??[]).map(p=>`<path d="${rt(J(p,r,s))}" ${A({...o,fillColor:"transparent"},true,d)} />`).join("");return `${i}${h}${c}${u}${n}`}case "parallelogram":{let r=a.width,s=a.height,l=r*.2;return `${i}<polygon points="${te([[-r/2+l,-s/2],[r/2,-s/2],[r/2-l,s/2],[-r/2,s/2]])}" ${A(o,true)} />${n}`}case "trapezoid":{let r=a.width,s=a.height,l=r*.15;return `${i}<polygon points="${te([[-r/2+l,-s/2],[r/2-l,-s/2],[r/2,s/2],[-r/2,s/2]])}" ${A(o,true)} />${n}`}case "uml-class":return `${i}${Vt(a,false)}${n}`;case "uml-interface":return `${i}${Vt(a,true)}${n}`;case "mind-map":return Fn(a);case "line":case "arrow":{let r=a,s=r.connectionType||"straight",{pts:l,fromN:h,toN:c}=zn(r,e);if(l.length<2)return "";let d=r.style.strokeColor,u=r.style.strokeWidth,g=r.type==="arrow"&&(!!r.dashed||r.arrowHead==="dependency"||r.arrowHead==="realization")?"8,5":$t(r.style),y=`<path d="${Kn(l,s,h,c,!!(r.userPoints&&r.userPoints.length))}" fill="none" stroke="${d}" stroke-width="${u}" stroke-linecap="round" stroke-linejoin="round"${g?` stroke-dasharray="${g}"`:""} />`,m=Xn(l,r.arrowHead||"end",d,u);return `${y}${m}`}case "draw":{let r=a,s=r.points;if(!s||s.length<2)return "";let l=Math.cos(r.rotation||0),h=Math.sin(r.rotation||0),c=s.map(u=>({x:u.x*l-u.y*h+r.x,y:u.x*h+u.y*l+r.y}));if(c.length<2)return "";let d=`M ${f(c[0].x)} ${f(c[0].y)}`;for(let u=1;u<c.length-1;u++){let p=(c[u].x+c[u+1].x)/2,g=(c[u].y+c[u+1].y)/2;d+=` Q ${f(c[u].x)} ${f(c[u].y)} ${f(p)} ${f(g)}`;}return d+=` L ${f(c[c.length-1].x)} ${f(c[c.length-1].y)}`,`<path d="${d}" fill="none" stroke="${o.strokeColor}" stroke-width="${o.strokeWidth}" stroke-linecap="round" stroke-linejoin="round" />`}case "text":{let r=a,s=r.fontSize||16,l=r.textColor||ce,h=ht(r.text||"",s,r.width,r.height),c="";if(r.highlightColor&&r.highlightColor!=="transparent"){let d=s*.15,u=typeof r.highlightOpacity=="number"?r.highlightOpacity:1,p=u<1?` fill-opacity="${f(u)}"`:"";c+=`<rect x="${f(-r.width/2-d)}" y="${f(-(h.length*s*1.3)/2-d)}" width="${r.width+d*2}" height="${h.length*s*1.3+d*2}" rx="4" fill="${r.highlightColor}"${p} />`;}return c+=pt(h,s,l),`${i}${c}${n}`}default:{let r=a,s=r.width||100,l=r.height||40,h="";if(r.text){let c=r.fontSize||16,d=ht(r.text,c,s*.85,l*.85);h+=pt(d,c,r.textColor||ce);}return `${i}<rect x="${f(-s/2)}" y="${f(-l/2)}" width="${s}" height="${l}" ${A(o,true)} />${h}${n}`}}}function at(a,e,t,i){let n=a/2,o=e/2,r=[];for(let s=0;s<t;s++){let l=s*2*Math.PI/t+i;r.push([n*Math.cos(l),o*Math.sin(l)]);}return r}function jn(a,e){let t=a/2,i=e/2,n=5,o=.4,r=[];for(let s=0;s<n*2;s++){let l=s*Math.PI/n-Math.PI/2,h=s%2===0?1:o;r.push([t*h*Math.cos(l),i*h*Math.sin(l)]);}return r}function Bt(a,e={}){let t=e.padding??24,i=e.background===void 0?"#ffffff":e.background??null,n=Ie(a,t),o=Math.max(1,Math.ceil(n.width)),r=Math.max(1,Math.ceil(n.height)),s=new Map(a.map(c=>[c.id,c])),l=a.map(c=>Zn(c,s)).filter(Boolean).join(`
4
+ `),h=i?`<rect x="${f(n.x)}" y="${f(n.y)}" width="${o}" height="${r}" fill="${i}" />`:"";return `<?xml version="1.0" encoding="UTF-8"?>
5
+ <svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${r}" viewBox="${f(n.x)} ${f(n.y)} ${o} ${r}" font-family="sans-serif">
7
6
  ${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
7
+ ${l}
8
+ </svg>`}function Ce(a){return a.toString().padStart(10,"0")}function qn(a,e,t){let i=a.split(",")[1]||"",n=atob(i),o=new Uint8Array(n.length);for(let C=0;C<n.length;C++)o[C]=n.charCodeAt(C);let r=Math.round(e),s=Math.round(t),l=`<< /Type /XObject /Subtype /Image /Width ${r} /Height ${s} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${o.length} >>`,h=`q ${r} 0 0 ${s} 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
15
- << /Type /Page /Parent 2 0 R /MediaBox [0 0 ${r} ${o}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>
14
+ `,u=`3 0 obj
15
+ << /Type /Page /Parent 2 0 R /MediaBox [0 0 ${r} ${s}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>
16
16
  endobj
17
- `,u=`4 0 obj
18
- ${h}
17
+ `,p=`4 0 obj
18
+ ${l}
19
19
  stream
20
- `,p=`endstream
20
+ `,g=`endstream
21
21
  endobj
22
22
  `,y=`5 0 obj
23
- << /Length ${l.length} >>
23
+ << /Length ${h.length} >>
24
24
  stream
25
- ${l}
25
+ ${h}
26
26
  endstream
27
27
  endobj
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
28
+ `,m=`%PDF-1.4
29
+ `,b=m.length,x=b+c.length,M=x+d.length,v=M+u.length,w=v+p.length+o.length+g.length,S=`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
+ `+Ce(b)+` 00000 n
33
+ `+Ce(x)+` 00000 n
34
+ `+Ce(M)+` 00000 n
35
+ `+Ce(v)+` 00000 n
36
+ `+Ce(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([m+c+d+u+p,o,g+y+S],{type:"application/pdf"})}async function gt(a,e,t={}){if(e==="svg"){let o=Bt(a,t);return new Blob([o],{type:"image/svg+xml;charset=utf-8"})}let i=Nt(a,t);if(e==="png")return Vn(i,"image/png");let n=Nn(i,"image/jpeg",.92);return qn(n,i.width,i.height)}function yt(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 mt="drawui-canvas-data",Jn=50,ft=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&&De(t.theme),t.language&&Ee(t.language);let i=e.getBoundingClientRect();this.renderer=new re(e),this.renderer.resize(i.width,i.height),this.camera=new ie;let n={addShape:o=>this.addShape(o),updateShape:(o,r)=>this.updateShape(o,r),deleteShape:o=>this.deleteShape(o),selectShape:(o,r)=>this.selectShape(o,r),selectShapes:o=>this.selectShapes(o),getShapes:()=>[...this.shapes],getSelectedIds:()=>[...this.selectedIds],setActiveTool:o=>this.setActiveTool(o),screenToPage:o=>this.screenToPage(o),getCamera:()=>this.camera,panBy:(o,r)=>this.panBy(o,r),setCameraPosition:(o,r)=>this.setCameraPosition(o,r),getShapeAtPoint:(o,r)=>this.getShapeAtPoint(o,r),getShapesInBrushRadius:(o,r)=>this.getShapesInBrushRadius(o,r),setEraserPoint:o=>this.setEraserPoint(o),updateArrowBinding:(o,r,s,l)=>this.updateArrowBinding(o,r,s,l),enterEditing:o=>this.enterEditing(o),exitEditing:()=>this.exitEditing(),commitHistory:()=>this.commitHistory(),setBrushRect:o=>this.setBrushRect(o),setSnapGuides:o=>this.setSnapGuides(o),setConnectingTarget:o=>this.setConnectingTarget(o),setGenerationPreview:o=>this.setGenerationPreview(o),setHoverAnchorShape:o=>this.setHoverAnchorShape(o),setHoverConnector:o=>this.setHoverConnector(o),getConnectorRoute:o=>this.getConnectorRoute(o),getLineStyle:()=>this.lineStyle(),openGenerationMenu:o=>this.openGenerationMenu(o),createGeneratedConnection:(o,r)=>this.createGeneratedConnection(o,r),createFloatingLine:o=>this.createFloatingLine(o),connectToExisting:(o,r,s)=>this.connectToExisting(o,r,s),updateSelectedShapesStyle:o=>this.updateSelectedShapesStyle(o),updateSelectedShapesText:o=>this.updateSelectedShapesText(o),updateConnectionType:o=>this.updateConnectionType(o),getArrowStyle:()=>this.getArrowStyle(),getMindMapCursorHitAtPoint:o=>this.getMindMapCursorHitAtPoint(o),selectMindMapNode:(o,r)=>this.selectMindMapNode(o,r)};this.tools.set("select",new be(n)),this.tools.set("hand",new Se(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("envelope",new P(n,"envelope")),this.tools.set("checkbox",new P(n,"checkbox")),this.tools.set("triangular-pyramid",new P(n,"triangular-pyramid")),this.tools.set("quadrangular-pyramid",new P(n,"quadrangular-pyramid")),this.tools.set("cuboid",new P(n,"cuboid")),this.tools.set("sphere",new P(n,"sphere")),this.tools.set("ellipsoid",new P(n,"ellipsoid")),this.tools.set("pie",new P(n,"pie")),this.tools.set("hollow-pie",new P(n,"hollow-pie")),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 Me(n)),this.tools.set("arrow",new ve(n)),this.tools.set("text",new We(n)),this.tools.set("pen",new ee(n,"pen")),this.tools.set("highlighter",new ee(n,"highlighter")),this.tools.set("eraser",new $e(n)),this.tools.set("mind-map",new P(n,"mind-map")),this.setupEventListeners(),t.shapes?this.shapes=t.shapes.map(o=>({...o,style:{...o.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 o=Date.now(),r=this.getShapeAtPoint(t);if(o-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=o,this.lastClickShapeId=r?.id||null,r&&r.type==="mind-map"&&this.mindMapEditingShapeId===r.id){let s=this.getMindMapNodeAtPoint(t);s&&(this.mindMapSelectedNode=s,this.notifyListeners(),this.render());return}r&&(this.dragStartPositions.clear(),this.selectedIds.forEach(s=>{let l=this.shapes.find(h=>h.id===s);l&&this.dragStartPositions.set(s,{x:l.x,y:l.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,o=e.clientY-this.panStart.y;this.camera.translate(n,o),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,o={};if(n.startBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.startBinding.handle||"top");o.points=n.points.map((s,l)=>l===0?r:s);}if(n.endBinding?.toShapeId===e){let r=this.getBindingPosition(t,n.endBinding.handle||"top"),s=o.points||[...n.points];o.points=s.map((l,h)=>h===s.length-1?r:l);}o.points&&(this.shapes[this.shapes.indexOf(i)]={...n,...o});}});}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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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 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)}`,o={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(o),this.selectedIds=[n],this.notifyListeners(),this.render(),n}createGeneratedConnection(e,t){this.commitHistory();let i=t.type,n;if(e.sourceShapeId){let l=this.shapes.find(h=>h.id===e.sourceShapeId);l&&Re(l.type)&&(n={...l.style});}let o=Z(i,e.to,n);this.addShape(o);let r=e.from,s={toShapeId:o.id,handle:this.connectHandle(r,e.to,e.edge),auto:true};if(t.existingArrowId)this.updateArrowBinding(t.existingArrowId,"end",o.id,{toShapeId:o.id,handle:this.connectHandle(r,e.to,e.edge),auto:true});else {let h={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:s,connectionType:"polyline",arrowHead:this.arrowStyle.arrowHead,dashed:this.arrowStyle.dashed};this.addShape(h);}this.selectedIds=[o.id],this.notifyListeners(),this.render();}connectToExisting(e,t,i){this.commitHistory();let n=this.shapes.find(c=>c.id===t);if(!n)return;let o=e.from,r=i?.handle??this.connectHandle(o,{x:n.x,y:n.y},e.edge),s=this.getBindingPosition(n,r),l=`shape_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,h={id:l,type:"arrow",x:o.x,y:o.y,points:[{x:o.x,y:o.y},{x:s.x,y:s.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(h),this.selectedIds=[l],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(o=>o.id===i);if(n!==-1){let o=this.shapes[n];o.type==="arrow"&&(this.shapes[n]=t?{...o,arrowHead:e,dashed:true}:{...o,arrowHead:e});}}),this.notifyListeners(),this.render();}updateArrowStyle(e){this.selectedIds.length!==0&&(this.commitHistory(),this.selectedIds.forEach(t=>{let i=this.shapes.findIndex(s=>s.id===t);if(i===-1)return;let n=this.shapes[i];if(n.type!=="arrow")return;let o=e.arrowHead??n.arrowHead??"end",r=o==="dependency"||o==="realization";this.shapes[i]={...n,...e,arrowHead:o,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 o=t.className??n.className,r=t.attributes??n.attributes,s=t.methods??n.methods,{width:l,height:h}=Ve(o,r,s);this.shapes[i]={...n,className:o,attributes:r,methods:s,width:l,height:h},this.notifyListeners(),this.render();}updateUmlInterface(e,t){let i=this.shapes.findIndex(g=>g.id===e);if(i===-1)return;let n=this.shapes[i];if(n.type!=="uml-interface")return;this.commitHistory();let o=n,r=t.className??o.className,s=t.methods??o.methods,l=B*.6,h=s.map(g=>`${g.visibility} ${g.name}(${g.params}): ${g.returnType}`),c=Math.max(r.length,...h.map(g=>g.length),0),d=Math.max(ye,c*l+$*2),u=s.length>0?s.length*k+T*2:T*2,p=U+u;this.shapes[i]={...n,className:r,methods:s,width:d,height:p},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,o=e.x-n.x,r=e.y-n.y,s=Math.cos(n.rotation),l=Math.sin(n.rotation),h=o*s+r*l,c=-o*l+r*s;if(Math.abs(h)>n.width/2||Math.abs(c)>n.height/2)continue;let d=R(n.root);for(let[u,p]of d.positions)if(Math.abs(h-p.x)<=p.width/2&&Math.abs(c-p.y)<=p.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 o=n,r=e.x-o.x,s=e.y-o.y,l=Math.cos(o.rotation),h=Math.sin(o.rotation),c=r*l+s*h,d=-r*h+s*l,u=R(o.root);for(let[p,g]of u.positions)if(Math.abs(c-g.x)<=g.width/2&&Math.abs(d-g.y)<=g.height/2)return {shapeId:o.id,nodeId:p}}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:F(i.root,t)}getMindMapNodeScreenRect(e,t){let i=this.shapes.find(b=>b.id===e);if(!i||i.type!=="mind-map")return null;let n=i,r=R(n.root).positions.get(t);if(!r)return null;let s=this.camera.getZoom(),l=r.x,h=r.y,c=Math.cos(n.rotation),d=Math.sin(n.rotation),u=l*c-h*d,p=l*d+h*c,g=this.camera.pageToScreen({x:n.x,y:n.y}),y=g.x+u*s,m=g.y+p*s;return {x:y-r.width*s/2,y:m-r.height*s/2,width:r.width*s,height:r.height*s}}getMindMapCollapseHitAtPoint(e){for(let t of this.shapes){if(t.type!=="mind-map")continue;let i=t,n=R(i.root),o=e.x-i.x,r=e.y-i.y,s=Math.cos(i.rotation),l=Math.sin(i.rotation),h=o*s+r*l,c=-o*l+r*s;for(let[d,u]of n.positions){let p=F(i.root,d);if(!p||!p.children||p.children.length===0)continue;let g=u.x+u.width/2+10,y=u.y,m=h-g,b=c-y;if(m*m+b*b<=121)return {shapeId:t.id,nodeId:d}}}return null}beginMindMapEdit(e,t){let i=this.shapes.find(o=>o.id===e);if(!i||i.type!=="mind-map")return;let n=i;this.mindMapEditingShapeId=e,this.mindMapSelectedNode={shapeId:e,nodeId:t&&F(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 o=this.shapes.findIndex(p=>p.id===e);if(o===-1)return;let r=this.shapes[o];if(r.type!=="mind-map")return;let s=r,l=F(s.root,t);if(!l||!Object.keys(i).some(p=>l[p]!==i[p]))return;n&&this.commitHistory();let c=He(s.root,t,i),{width:d,height:u}=R(c);this.shapes[o]={...s,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 o=n,r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:z("mindmap.defaultBranch")},s=qe(o.root,t,r);this.commitHistory();let{width:l,height:h}=R(s);this.shapes[i]={...o,root:s,width:l,height:h},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 o=n;if(!ge(o.root,t))return;let r={id:`mm_${Date.now()}_${Math.random().toString(36).substr(2,6)}`,text:z("mindmap.defaultBranch")},s=Je(o.root,t,r);this.commitHistory();let{width:l,height:h}=R(s);this.shapes[i]={...o,root:s,width:l,height:h},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 o=n;if(o.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=Qe(o.root,t);if(!r)return;this.commitHistory();let{width:s,height:l}=R(r);this.shapes[i]={...o,root:r,width:s,height:l};let h=ge(o.root,t);this.mindMapSelectedNode=h?{shapeId:e,nodeId:h.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 o=n,r=F(o.root,t);if(!r||!r.children||r.children.length===0)return;this.commitHistory();let s=He(o.root,t,{collapsed:!r.collapsed}),{width:l,height:h}=R(s);this.shapes[i]={...o,root:s,width:l,height:h},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(o=>o.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(s=>s.id===e);if(!n||n.type!=="uml-class"||t===i)return;let o=[...n.attributes];if(t<0||t>=o.length||i<0||i>=o.length)return;let[r]=o.splice(t,1);o.splice(i,0,r),this.updateUmlClass(e,{attributes:o});}reorderUmlMethod(e,t,i){let n=this.getUmlById(e);if(!n||t===i)return;let o=[...n.methods];if(t<0||t>=o.length||i<0||i>=o.length)return;let[r]=o.splice(t,1);o.splice(i,0,r),n.type==="uml-class"?this.updateUmlClass(e,{methods:o}):this.updateUmlInterface(e,{methods:o});}updateUmlRowStyle(e,t,i,n){let o=this.getUmlById(e);if(o)if(t==="attribute"){if(o.type!=="uml-class")return;let r=o.attributes.map(s=>s.id===i?{...s,textColor:n.textColor===null?void 0:n.textColor??s.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??s.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??s.strikethrough}:s);this.updateUmlClass(e,{attributes:r});}else {let r=o.methods.map(s=>s.id===i?{...s,textColor:n.textColor===null?void 0:n.textColor??s.textColor,fontSize:n.fontSize===null?void 0:n.fontSize??s.fontSize,strikethrough:n.strikethrough===null?void 0:n.strikethrough??s.strikethrough}:s);o.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 o=n.width/2,r=n.height/2;if(t.x<n.x-o||t.x>n.x+o||t.y<n.y-r||t.y>n.y+r)continue;let s=U,l=t.y-n.y;if(l>=-r&&l<=-r+s)return {shape:n,section:"className",rowIndex:-1,text:n.className};if(n.type==="uml-interface"){let g=-r+s,y=r;if(n.methods.length>0&&l>=g&&l<=y){let m=Math.floor((l-g-T)/k);if(m>=0&&m<n.methods.length){let b=n.methods[m];return {shape:n,section:"method",rowIndex:m,text:`${b.visibility} ${b.name}(${b.params}): ${b.returnType}`}}return {shape:n,section:"method",rowIndex:-1,text:""}}return {shape:n,section:"className",rowIndex:-1,text:n.className}}let h=n.attributes.length>0?n.attributes.length*k+T*2:T*2,c=-r+s,d=c+h;if(n.attributes.length>0&&l>=c&&l<=d){let g=Math.floor((l-c-T)/k);if(g>=0&&g<n.attributes.length){let y=n.attributes[g];return {shape:n,section:"attribute",rowIndex:g,text:`${y.visibility} ${y.name}: ${y.type}`}}return {shape:n,section:"attribute",rowIndex:-1,text:""}}let u=d,p=r;if(n.methods.length>0&&l>=u&&l<=p){let g=Math.floor((l-u-T)/k);if(g>=0&&g<n.methods.length){let y=n.methods[g];return {shape:n,section:"method",rowIndex:g,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 ee&&t.setHighlighterColor(e);}getHighlighterColor(){let e=this.tools.get("highlighter");return e instanceof ee?e.getHighlighterColor():Oe}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){De(e),this.scheduleRender();}setLanguage(e){Ee(e);}getSelectedIds(){return [...this.selectedIds]}getCamera(){return this.camera}isPointerDown(){return this.pointerIsDown}getContentBounds(e=24){return Ie(this.shapes,e)}async exportImage(e,t={}){return gt(this.getShapes(),e,t)}async downloadImage(e="drawui",t="png",i={}){let n=await this.exportImage(t,i);yt(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=Ae(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>Jn&&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(mt,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(mt);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(mt);}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,o=n.fontSize||16,r=o*1.3,s=n.width||200,l=i.split(`
42
+ `),h=0;for(let u of l){let p="";for(let g of u){let y=p+g;y.length*o*.6>s&&p?(h++,p=g):p=y;}p&&h++;}let c={...n,text:i,height:Math.max(h*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(),o=i.left-n.left,r=i.top-n.top;this.textOverlay=document.createElement("div"),this.textOverlay.style.position="absolute",this.textOverlay.style.left=`${o}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 s=this.getShapeScreenBounds(e),l=this.camera.getZoom(),h=(e.fontSize||16)*l,c=document.createElement("textarea");c.style.position="absolute",c.style.left=`${o+s.x}px`,c.style.top=`${r+s.y}px`,c.style.width=`${Math.max(s.width,60)}px`,c.style.height=`${Math.max(s.height,24)}px`,c.style.fontSize=`${h}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,p=c.selectionEnd;c.value=c.value.substring(0,u)+`
43
+ `+c.value.substring(p),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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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,o=n.width*t,r=n.height*t;return {x:i.x-o/2,y:i.y-r/2,width:o,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,o=i+4;for(let r=1;r<n.length;r++)if(this.pointToSegmentDist(t,n[r-1],n[r])<=o)return true;return n.length>0&&Math.hypot(t.x-n[0].x,t.y-n[0].y)<=o}case "draw":{let n=e.points,o=i+4;for(let r=1;r<n.length;r++){let s={x:e.x+n[r-1].x,y:e.y+n[r-1].y},l={x:e.x+n[r].x,y:e.y+n[r].y};if(this.pointToSegmentDist(t,s,l)<=o)return true}return n.length>0&&Math.hypot(t.x-(e.x+n[0].x),t.y-(e.y+n[0].y))<=o}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,o=i.y-t.y,r=n*n+o*o,s=r===0?0:Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*o)/r));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*o))}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 "envelope":case "checkbox":case "triangular-pyramid":case "quadrangular-pyramid":case "cuboid":case "sphere":case "ellipsoid":case "pie":case "hollow-pie":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 o=t.width/2,r=t.height/2;return Math.abs(i)<=o&&Math.abs(n)<=r&&Math.abs(i)/o+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 o=t;return Math.abs(i)<=o.width/2&&Math.abs(n)<=o.height/2}default:return false}}updateArrowBinding(e,t,i,n){let o=this.shapes.find(l=>l.id===e);if(!o||o.type!=="arrow")return;let r=o,s={};if(i){let l=this.shapes.find(u=>u.id===i);if(!l)return;let h=n?.handle||this.getClosestHandle(r,l),c=this.getBindingPosition(l,h),d=n?.handle?{...n,toShapeId:i,auto:false}:n?.auto?n:{toShapeId:i,handle:h,auto:false};t==="start"?(s.startBinding=d,s.points=r.points.map((u,p)=>p===0?c:u)):(s.endBinding=d,s.points=r.points.map((u,p)=>p===r.points.length-1?c:u));}else t==="start"?s.startBinding=void 0:s.endBinding=void 0;this.updateShape(e,s);}getClosestHandle(e,t){let i=e.points[0],n=e.points[e.points.length-1],o=e.endBinding?n:i,r=o.x-t.x,s=o.y-t.y;return Math.abs(r)>Math.abs(s)?r>0?"right":"left":s>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=ve;exports.Camera=ie;exports.DEFAULT_HIGHLIGHTER_COLOR=Oe;exports.Editor=ft;exports.FreehandTool=ee;exports.HandTool=Se;exports.LANGUAGES=Wt;exports.LineTool=Me;exports.MINDMAP_COLORS=je;exports.MINDMAP_FONT_SIZE=X;exports.MINDMAP_MAX_WIDTH=jt;exports.MINDMAP_MIN_WIDTH=Zt;exports.MINDMAP_NODE_HEIGHT=Ft;exports.MIN_HANDLE_SEGMENT=_t;exports.MIN_JOG=Gt;exports.Mat2d=W;exports.Renderer=re;exports.SelectTool=be;exports.ShapeTool=P;exports.THEME=I;exports.UML_FONT_SIZE=B;exports.UML_HEADER_HEIGHT=U;exports.UML_LINE_HEIGHT=k;exports.UML_MIN_WIDTH=ye;exports.UML_PADDING_X=$;exports.UML_PADDING_Y=T;exports.Vec=se;exports.calcUmlClassSize=Ve;exports.cloneMindMapNode=Ae;exports.collapseRoute=pe;exports.connectorSegmentHandles=ke;exports.countMindMapNodes=Ct;exports.downloadBlob=yt;exports.exportToBlob=gt;exports.findMindMapNode=F;exports.getContentBounds=Ie;exports.getLanguage=Kt;exports.getMindMapNodeDepth=Pt;exports.getMindMapParent=ge;exports.getTheme=Ut;exports.hexToRgba=_;exports.layoutMindMap=R;exports.mindMapNodeColor=oe;exports.mindMapNodeSize=vt;exports.offsetConnectorSegment=Ke;exports.pickSegmentHandle=Ye;exports.pointToSegmentDistance=Te;exports.renderSVGString=Bt;exports.renderToCanvas=Nt;exports.routeToUserPoints=Xe;exports.setLanguage=Ee;exports.setTheme=De;exports.shadeColor=Ot;exports.subscribeLanguage=Xt;exports.subscribeTheme=zt;exports.t=z;