UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 13.8 kB
function mxVsdxCanvas2D(){mxAbstractCanvas2D.call(this)}mxUtils.extend(mxVsdxCanvas2D,mxAbstractCanvas2D),mxVsdxCanvas2D.prototype.textEnabled=!0,mxVsdxCanvas2D.prototype.init=function(e){this.filesLoading=0,this.zip=e},mxVsdxCanvas2D.prototype.onFilesLoaded=function(){},mxVsdxCanvas2D.prototype.createElt=function(e){return null!=this.xmlDoc.createElementNS?this.xmlDoc.createElementNS(VsdxExport.prototype.XMLNS,e):this.xmlDoc.createElement(e)},mxVsdxCanvas2D.prototype.createGeoSec=function(){null!=this.geoSec&&this.shape.appendChild(this.geoSec);var e=this.createElt("Section");e.setAttribute("N","Geometry"),e.setAttribute("IX",this.geoIndex++),this.geoSec=e,this.geoStepIndex=1,this.lastX=0,this.lastY=0,this.lastMoveToX=0,this.lastMoveToY=0},mxVsdxCanvas2D.prototype.newShape=function(e,t,i){this.geoIndex=0,this.shape=e,this.cellState=t,this.xmGeo=t.cell.geometry,this.xmlDoc=i,this.geoSec=null,this.shapeImg=null,this.shapeType="Shape",this.createGeoSec()},mxVsdxCanvas2D.prototype.newEdge=function(e,t,i){this.shape=e,this.cellState=t,this.xmGeo=t.cellBounds,this.state,this.xmlDoc=i},mxVsdxCanvas2D.prototype.endShape=function(){null!=this.shapeImg&&this.addForeignData(this.shapeImg.type,this.shapeImg.id)},mxVsdxCanvas2D.prototype.newPage=function(){this.images=[]},mxVsdxCanvas2D.prototype.getShapeType=function(){return this.shapeType},mxVsdxCanvas2D.prototype.getShapeGeo=function(){return this.geoSec},mxVsdxCanvas2D.prototype.createCellElemScaled=function(e,t,i){return this.createCellElem(e,t/VsdxExport.prototype.CONVERSION_FACTOR,i)},mxVsdxCanvas2D.prototype.createCellElem=function(e,t,i){var a=this.createElt("Cell");return a.setAttribute("N",e),a.setAttribute("V",t),i&&a.setAttribute("F",i),a},mxVsdxCanvas2D.prototype.createRowScaled=function(e,t,i,a,l,s,o,n,h,d,r,p,c,x){return this.createRowRel(e,t,i/VsdxExport.prototype.CONVERSION_FACTOR,a/VsdxExport.prototype.CONVERSION_FACTOR,l/VsdxExport.prototype.CONVERSION_FACTOR,s/VsdxExport.prototype.CONVERSION_FACTOR,o/VsdxExport.prototype.CONVERSION_FACTOR,n/VsdxExport.prototype.CONVERSION_FACTOR,h,d,r,p,c,x)},mxVsdxCanvas2D.prototype.createRowRel=function(e,t,i,a,l,s,o,n,h,d,r,p,c,x){var m=this.createElt("Row");return m.setAttribute("T",e),m.setAttribute("IX",t),m.appendChild(this.createCellElem("X",i,h)),m.appendChild(this.createCellElem("Y",a,d)),null!=l&&isFinite(l)&&m.appendChild(this.createCellElem("A",l,r)),null!=s&&isFinite(s)&&m.appendChild(this.createCellElem("B",s,p)),null!=o&&isFinite(o)&&m.appendChild(this.createCellElem("C",o,c)),null!=n&&isFinite(n)&&m.appendChild(this.createCellElem("D",n,x)),m},mxVsdxCanvas2D.prototype.begin=function(){this.geoStepIndex>1&&this.createGeoSec()},mxVsdxCanvas2D.prototype.rect=function(e,t,i,a){this.geoStepIndex>1&&this.createGeoSec();var l=this.state;i*=l.scale,a*=l.scale;var s=this.xmGeo;e=(e-s.x+l.dx)*l.scale,t=(s.height-t+s.y-l.dy)*l.scale,this.geoSec.appendChild(this.createRowScaled("MoveTo",this.geoStepIndex++,e,t)),this.geoSec.appendChild(this.createRowScaled("LineTo",this.geoStepIndex++,e+i,t)),this.geoSec.appendChild(this.createRowScaled("LineTo",this.geoStepIndex++,e+i,t-a)),this.geoSec.appendChild(this.createRowScaled("LineTo",this.geoStepIndex++,e,t-a)),this.geoSec.appendChild(this.createRowScaled("LineTo",this.geoStepIndex++,e,t))},mxVsdxCanvas2D.prototype.roundrect=function(e,t,i,a,l,s){this.rect(e,t,i,a),this.shape.appendChild(this.createCellElemScaled("Rounding",l))},mxVsdxCanvas2D.prototype.ellipse=function(e,t,i,a){this.geoStepIndex>1&&this.createGeoSec();var l=this.state;i*=l.scale,a*=l.scale;var s=this.xmGeo,o=s.height*l.scale,n=s.width*l.scale,h=((e=(e-s.x+l.dx)*l.scale)+i/2)/n,d=((t=o+(-t+s.y-l.dy)*l.scale)-a/2)/o,r=e/n,p=(t-a/2)/o,c=(e+i/2)/n,x=t/o;this.geoSec.appendChild(this.createRowScaled("Ellipse",this.geoStepIndex++,e+i/2,t-a/2,e,t-a/2,e+i/2,t,"Width*"+h,"Height*"+d,"Width*"+r,"Height*"+p,"Width*"+c,"Height*"+x))},mxVsdxCanvas2D.prototype.moveTo=function(e,t){this.geoStepIndex>1&&this.createGeoSec(),this.lastMoveToX=e,this.lastMoveToY=t,this.lastX=e,this.lastY=t;var i=this.xmGeo,a=this.state;e=(e-i.x+a.dx)*a.scale,t=(i.height-t+i.y-a.dy)*a.scale;var l=i.height*a.scale,s=i.width*a.scale;this.geoSec.appendChild(this.createRowRel("RelMoveTo",this.geoStepIndex++,e/s,t/l))},mxVsdxCanvas2D.prototype.lineTo=function(e,t){this.lastX=e,this.lastY=t;var i=this.xmGeo,a=this.state;e=(e-i.x+a.dx)*a.scale,t=(i.height-t+i.y-a.dy)*a.scale;var l=i.height*a.scale,s=i.width*a.scale;this.geoSec.appendChild(this.createRowRel("RelLineTo",this.geoStepIndex++,e/s,t/l))},mxVsdxCanvas2D.prototype.quadTo=function(e,t,i,a){this.lastX=i,this.lastY=a;var l=this.state,s=this.xmGeo,o=s.height*l.scale,n=s.width*l.scale;e=(e-s.x+l.dx)*l.scale,t=(s.height-t+s.y-l.dy)*l.scale,i=(i-s.x+l.dx)*l.scale,a=(s.height-a+s.y-l.dy)*l.scale,e/=n,t/=o,i/=n,a/=o,this.geoSec.appendChild(this.createRowRel("RelQuadBezTo",this.geoStepIndex++,i,a,e,t))},mxVsdxCanvas2D.prototype.curveTo=function(e,t,i,a,l,s){this.lastX=l,this.lastY=s;var o=this.state,n=this.xmGeo,h=n.height*o.scale,d=n.width*o.scale;e=(e-n.x+o.dx)*o.scale,t=(n.height-t+n.y-o.dy)*o.scale,i=(i-n.x+o.dx)*o.scale,a=(n.height-a+n.y-o.dy)*o.scale,l=(l-n.x+o.dx)*o.scale,s=(n.height-s+n.y-o.dy)*o.scale,e/=d,t/=h,i/=d,a/=h,l/=d,s/=h,this.geoSec.appendChild(this.createRowRel("RelCubBezTo",this.geoStepIndex++,l,s,e,t,i,a))},mxVsdxCanvas2D.prototype.close=function(){this.lastMoveToX==this.lastX&&this.lastMoveToY==this.lastY||this.lineTo(this.lastMoveToX,this.lastMoveToY)},mxVsdxCanvas2D.prototype.addForeignData=function(e,t){var i=this.createElt("ForeignData");i.setAttribute("ForeignType","Bitmap"),"BMP"!=(e=e.toUpperCase())&&i.setAttribute("CompressionType",e);var a=this.createElt("Rel");a.setAttribute("r:id","rId"+t),i.appendChild(a),this.shape.appendChild(i),this.shapeType="Foreign"},mxVsdxCanvas2D.prototype.convertSvg2Png=function(e,t,i){var a=this;this.filesLoading++;try{var l=document.createElement("canvas"),s=l.getContext("2d");t||(e=String.fromCharCode.apply(null,new Uint8Array(e)),e=window.btoa?btoa(e):Base64.encode(e,!0));var o="data:image/svg+xml;base64,"+e;img=new Image,img.onload=function(){l.width=this.width,l.height=this.height,s.drawImage(this,0,0);try{i(l.toDataURL("image/png"))}catch(e){}a.filesLoading--,0==a.filesLoading&&a.onFilesLoaded()},img.onerror=function(){console.log("SVG2PNG conversion failed");try{i(e)}catch(e){}a.filesLoading--,0==a.filesLoading&&a.onFilesLoaded()},img.src=o}catch(t){console.log("SVG2PNG conversion failed"+t.message);try{i(e)}catch(e){}this.filesLoading--,0==a.filesLoading&&a.onFilesLoaded()}},mxVsdxCanvas2D.prototype.image=function(e,t,i,a,l,s,o,n){var h,d=this,r="image"+(this.images.length+1)+".";if(0==l.indexOf("data:")){var p=l.indexOf("base64,"),c=l.substring(p+7);0==(h=l.substring(11,p-1)).indexOf("svg")?(r+=h="png",this.convertSvg2Png(c,!0,(function(e){d.zip.file("visio/media/"+r,e.substring(22),{base64:!0})}))):(r+=h,this.zip.file("visio/media/"+r,c,{base64:!0}))}else if(window.XMLHttpRequest){l=this.converter.convert(l),this.filesLoading++,p=l.lastIndexOf("."),h=l.substring(p+1);var x=!1;0==h.indexOf("svg")&&(h="png",x=!0),r+=h;var m=new XMLHttpRequest;m.open("GET",l,!0),m.responseType="arraybuffer",m.onreadystatechange=function(e){4==this.readyState&&(200==this.status&&(x?d.convertSvg2Png(this.response,!1,(function(e){d.zip.file("visio/media/"+r,e.substring(22),{base64:!0})})):d.zip.file("visio/media/"+r,this.response)),d.filesLoading--,0==d.filesLoading&&d.onFilesLoaded())},m.send()}this.images.push(r),this.shapeImg={type:h,id:this.images.length+1},s=null==s||s,o=null!=o&&o,n=null!=n&&n;var C=this.state;i*=C.scale,a*=C.scale;var g=this.xmGeo;e=(e-g.x+C.dx)*C.scale,t=(g.height-t+g.y-C.dy)*C.scale,this.shape.appendChild(this.createCellElemScaled("ImgOffsetX",e)),this.shape.appendChild(this.createCellElemScaled("ImgOffsetY",t-a)),this.shape.appendChild(this.createCellElemScaled("ImgWidth",i)),this.shape.appendChild(this.createCellElemScaled("ImgHeight",a))},mxVsdxCanvas2D.prototype.text=function(e,t,i,a,l,s,o,n,h,d,r,p,c){var x=this;if(this.textEnabled&&null!=l){if(mxUtils.isNode(l)&&(l=mxUtils.getOuterHtml(l)),0==i&&0==a){var m=mxUtils.getSizeForString(l,x.cellState.style.fontSize,x.cellState.style.fontFamily);i=2*m.width,a=2*m.height}"html"==h&&("0"!=mxUtils.getValue(this.cellState.style,"nl2Br","1")&&(l=l.replace(/\n/g,"").replace(/<br\s*.?>/g,"\n")),null==this.html2txtDiv&&(this.html2txtDiv=document.createElement("div")),this.html2txtDiv.innerHTML=Graph.sanitizeHtml(l),l=mxUtils.extractTextWithWhitespace(this.html2txtDiv.childNodes));var C=this.state,g=this.xmGeo;i*=C.scale,a*=C.scale;var S=this.createElt("Section");S.setAttribute("N","Character");var u=this.createElt("Section");u.setAttribute("N","Paragraph");var y=this.createElt("Text"),v=0,f=0,E=0,V=0,I=0,b=0,T=0,D=function(e,t,a,l,s){var o=e.fontSize,h=e.fontFamily,d=mxUtils.getSizeForString(s,o,h);n&&d.width>i&&(d=mxUtils.getSizeForString(s,o,h,i)),e.blockElem?(I+=d.width,E=Math.min(Math.max(E,I),i),I=0,b=Math.max(b,d.height),V+=b+T,T=b,b=0):(I+=d.width,E=Math.min(Math.max(E,I),i),b=Math.max(b,d.height),V=Math.max(V,b));var r=x.createElt("Row");r.setAttribute("IX",v),e.fontColor&&r.appendChild(x.createCellElem("Color",mxUtils.rgba2hex(e.fontColor))),o&&r.appendChild(x.createCellElemScaled("Size",.97*o)),h&&r.appendChild(x.createCellElem("Font",h));var p=0;e.bold&&(p|=17),e.italic&&(p|=34),e.underline&&(p|=4),r.appendChild(x.createCellElem("Style",p)),r.appendChild(x.createCellElem("Case","0")),r.appendChild(x.createCellElem("Pos","0")),r.appendChild(x.createCellElem("FontScale","1")),r.appendChild(x.createCellElem("Letterspace","0")),t.appendChild(r);var c=x.createElt("Row");c.setAttribute("IX",f);var m=1;switch(e.align){case"left":case"start":case"justify":m=0;break;case"center":default:m=1;break;case"right":case"end":m=2}c.appendChild(x.createCellElem("HorzAlign",m)),a.appendChild(c);var C=x.createElt("cp");C.setAttribute("IX",v++),l.appendChild(C);var g=x.xmlDoc.createTextNode(s+(e.blockElem?"\n":""));l.appendChild(g)},R=function(e,t){t=t||{};for(var i=0;i<e.length;i++){var a=e[i];if(3==a.nodeType){var l=x.cellState.style.fontStyle,s={fontColor:t.fontColor||x.cellState.style.fontColor,fontSize:t.fontSize||x.cellState.style.fontSize,fontFamily:t.fontFamily||x.cellState.style.fontFamily,align:t.align||x.cellState.style.align,bold:t.bold||1&l,italic:t.italic||2&l,underline:t.underline||4&l},o=!1;i+1<e.length&&"BR"==e[i+1].nodeName.toUpperCase()&&(o=!0,i++),D(s,S,u,y,(t.OL?t.LiIndex+". ":"")+a.textContent+(o?"\n":""))}else if(1==a.nodeType){var n,h,d=a.nodeName.toUpperCase(),r=a.childNodes.length,p=window.getComputedStyle(a,null);if(s={bold:"bold"==p.getPropertyValue("font-weight")||t.bold,italic:"italic"==p.getPropertyValue("font-style")||t.italic,underline:p.getPropertyValue("text-decoration").indexOf("underline")>=0||t.underline,align:p.getPropertyValue("text-align"),fontColor:p.getPropertyValue("color"),fontSize:parseFloat(p.getPropertyValue("font-size")),fontFamily:p.getPropertyValue("font-family").replace(/"/g,""),blockElem:"block"==p.getPropertyValue("display")||"BR"==d||"LI"==d,OL:t.OL,LiIndex:t.LiIndex},"UL"==d?((n=x.createElt("Row")).setAttribute("IX",f),n.appendChild(x.createCellElem("HorzAlign","0")),n.appendChild(x.createCellElem("Bullet","1")),u.appendChild(n),(h=x.createElt("pp")).setAttribute("IX",f++),y.appendChild(h)):"OL"==d?s.OL=!0:"LI"==d&&(s.LiIndex=i+1),r>0)R(a.childNodes,s),"UL"==d&&((n=x.createElt("Row")).setAttribute("IX",f),n.appendChild(x.createCellElem("Bullet","0")),u.appendChild(n),(h=x.createElt("pp")).setAttribute("IX",f++),y.appendChild(h)),D(s,S,u,y,"");else D(s,S,u,y,(t.OL?t.LiIndex+". ":"")+a.textContent)}}};if("html"==h&&mxClient.IS_SVG){var L=this.cellState.text.node.getElementsByTagName("div")[mxClient.NO_FO?0:1];if(null!=L){var w=L.childNodes;R(w,{})}}else{var F={fontColor:x.cellState.style.fontColor,fontSize:x.cellState.style.fontSize,fontFamily:x.cellState.style.fontFamily};D(F,S,u,y,l)}var N=0,O=0;a=Math.max(a,V);var A=(i=Math.max(i,E))/2,M=a/2,X=parseInt(mxUtils.getValue(this.cellState.style,"rotation","0")),G=X*Math.PI/180;switch(s){case"right":0!=X?(e-=A*Math.cos(G),t-=A*Math.sin(G)):N=E/2;break;case"center":break;case"left":0!=X?(e+=A*Math.cos(G),t+=A*Math.sin(G)):N=-E/2}switch(o){case"top":0!=X?(e+=M*Math.sin(G),t+=M*Math.cos(G)):O=V/2;break;case"middle":break;case"bottom":0!=X?(e-=M*Math.sin(G),t-=M*Math.cos(G)):O=-V/2}e=(e-g.x+C.dx)*C.scale,t=(g.height-t+g.y-C.dy)*C.scale,this.shape.appendChild(this.createCellElemScaled("TxtPinX",e)),this.shape.appendChild(this.createCellElemScaled("TxtPinY",t)),this.shape.appendChild(this.createCellElemScaled("TxtWidth",i)),this.shape.appendChild(this.createCellElemScaled("TxtHeight",a)),this.shape.appendChild(this.createCellElemScaled("TxtLocPinX",A+N)),this.shape.appendChild(this.createCellElemScaled("TxtLocPinY",M+O)),0!=(p-=X)&&this.shape.appendChild(this.createCellElem("TxtAngle",(360-p)*Math.PI/180)),this.shape.appendChild(S),this.shape.appendChild(u),this.shape.appendChild(y)}},mxVsdxCanvas2D.prototype.rotate=function(e,t,i,a,l){if(0!=e){var s=this.state;a+=s.dx,l+=s.dy,a*=s.scale,l*=s.scale,this.shape.appendChild(this.createCellElem("Angle",(360-e)*Math.PI/180)),s.rotation=s.rotation+e,s.rotationCx=a,s.rotationCy=l}},mxVsdxCanvas2D.prototype.stroke=function(){this.geoSec.appendChild(this.createCellElem("NoFill","1")),this.geoSec.appendChild(this.createCellElem("NoLine","0"))},mxVsdxCanvas2D.prototype.fill=function(){this.geoSec.appendChild(this.createCellElem("NoFill","0")),this.geoSec.appendChild(this.createCellElem("NoLine","1"))},mxVsdxCanvas2D.prototype.fillAndStroke=function(){this.geoSec.appendChild(this.createCellElem("NoFill","0")),this.geoSec.appendChild(this.createCellElem("NoLine","0"))};