All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.vectorizer.min.js Maven / Gradle / Ivy

There is a newer version: 5.2.2
Show newest version
/*! JointJS v0.9.2 - JavaScript diagramming library  2014-09-17 


This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
!function(a,b){"function"==typeof define&&define.amd?define([],b):a.Vectorizer=a.V=b()}(this,function(){function a(){var a=++m+"";return"v-"+a}function b(a){var b=''+(a||"")+"",c=new DOMParser;return c.async=!1,c.parseFromString(b,"text/xml").documentElement}function c(a,c,e){if(!a)return void 0;if("object"==typeof a)return new i(a);if(c=c||{},"svg"===a.toLowerCase())return new i(b());if("<"===a[0]){var f=b(a);if(f.childNodes.length>1){for(var g=[],h=0,j=f.childNodes.length;j>h;h++){var l=f.childNodes[h];g.push(new i(document.importNode(l,!0)))}return g}return new i(document.importNode(f.firstChild,!0))}a=document.createElementNS(k.xmlns,a);for(var m in c)d(a,m,c[m]);"[object Array]"!=Object.prototype.toString.call(e)&&(e=[e]);for(var n,h=0,j=e[0]&&e.length||0;j>h;h++)n=e[h],a.appendChild(n instanceof i?n.node:n);return new i(a)}function d(a,b,c){if(b.indexOf(":")>-1){var d=b.split(":");a.setAttributeNS(k[d[0]],d[1],c)}else"id"===b?a.id=c:a.setAttribute(b,c)}function e(a){var b,c,d;if(a){var e=/[ ,]+/,f=a.match(/translate\((.*)\)/);f&&(b=f[1].split(e));var g=a.match(/rotate\((.*)\)/);g&&(c=g[1].split(e));var h=a.match(/scale\((.*)\)/);h&&(d=h[1].split(e))}var i=d&&d[0]?parseFloat(d[0]):1;return{translate:{tx:b&&b[0]?parseInt(b[0],10):0,ty:b&&b[1]?parseInt(b[1],10):0},rotate:{angle:c&&c[0]?parseInt(c[0],10):0,cx:c&&c[1]?parseInt(c[1],10):void 0,cy:c&&c[2]?parseInt(c[2],10):void 0},scale:{sx:i,sy:d&&d[1]?parseFloat(d[1]):i}}}function f(a,b){var c=b.x*a.a+b.y*a.c+0,d=b.x*a.b+b.y*a.d+0;return{x:c,y:d}}function h(a){var b=f(a,{x:0,y:1}),c=f(a,{x:1,y:0}),d=180/Math.PI*Math.atan2(b.y,b.x)-90,e=180/Math.PI*Math.atan2(c.y,c.x);return{translateX:a.e,translateY:a.f,scaleX:Math.sqrt(a.a*a.a+a.b*a.b),scaleY:Math.sqrt(a.c*a.c+a.d*a.d),skewX:d,skewY:e,rotation:d}}function i(b){this.node=b,this.node.id||(this.node.id=a())}function j(a){var b=a.rx||a["top-rx"]||0,c=a.rx||a["bottom-rx"]||0,d=a.ry||a["top-ry"]||0,e=a.ry||a["bottom-ry"]||0;return["M",a.x,a.y+d,"v",a.height-d-e,"a",c,e,0,0,0,c,e,"h",a.width-2*c,"a",c,e,0,0,0,c,-e,"v",-(a.height-e-d),"a",b,d,0,0,0,-b,-d,"h",-(a.width-2*b),"a",b,d,0,0,0,-b,d].join(" ")}var k=(!(!window.SVGAngle&&!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")),{xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"}),l="1.1",m=0;i.prototype={translate:function(a,b,c){c=c||{},b=b||0;var d=this.attr("transform")||"",f=e(d);if("undefined"==typeof a)return f.translate;d=d.replace(/translate\([^\)]*\)/g,"").trim();var g=c.absolute?a:f.translate.tx+a,h=c.absolute?b:f.translate.ty+b,i="translate("+g+","+h+")";return this.attr("transform",(i+" "+d).trim()),this},rotate:function(a,b,c,d){d=d||{};var f=this.attr("transform")||"",g=e(f);if("undefined"==typeof a)return g.rotate;f=f.replace(/rotate\([^\)]*\)/g,"").trim(),a%=360;var h=d.absolute?a:g.rotate.angle+a,i=void 0!==b&&void 0!==c?","+b+","+c:"",j="rotate("+h+i+")";return this.attr("transform",(f+" "+j).trim()),this},scale:function(a,b){b="undefined"==typeof b?a:b;var c=this.attr("transform")||"",d=e(c);if("undefined"==typeof a)return d.scale;c=c.replace(/scale\([^\)]*\)/g,"").trim();var f="scale("+a+","+b+")";return this.attr("transform",(c+" "+f).trim()),this},bbox:function(a,b){if(!this.node.ownerSVGElement)return{x:0,y:0,width:0,height:0};var c;try{c=this.node.getBBox(),c={x:0|c.x,y:0|c.y,width:0|c.width,height:0|c.height}}catch(d){c={x:this.node.clientLeft,y:this.node.clientTop,width:this.node.clientWidth,height:this.node.clientHeight}}if(a)return c;var e=this.node.getTransformToElement(b||this.node.ownerSVGElement),f=[],g=this.node.ownerSVGElement.createSVGPoint();g.x=c.x,g.y=c.y,f.push(g.matrixTransform(e)),g.x=c.x+c.width,g.y=c.y,f.push(g.matrixTransform(e)),g.x=c.x+c.width,g.y=c.y+c.height,f.push(g.matrixTransform(e)),g.x=c.x,g.y=c.y+c.height,f.push(g.matrixTransform(e));for(var h=f[0].x,i=h,j=f[0].y,k=j,l=1,m=f.length;m>l;l++){var n=f[l].x,o=f[l].y;h>n?h=n:n>i&&(i=n),j>o?j=o:o>k&&(k=o)}return{x:h,y:j,width:i-h,height:k-j}},text:function(a,b){b=b||{};var c,d=a.split("\n"),e=0;if(this.attr("y","0.8em"),this.attr("display",a?null:"none"),this.node.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),1===d.length)return this.node.textContent=a,this;for(this.node.textContent="";ec;c++)a=b[c],this.node.appendChild(a instanceof i?a.node:a);return this},prepend:function(a){this.node.insertBefore(a instanceof i?a.node:a,this.node.firstChild)},svg:function(){return this.node instanceof window.SVGSVGElement?this:n(this.node.ownerSVGElement)},defs:function(){var a=this.svg().node.getElementsByTagName("defs");return a&&a.length?n(a[0]):void 0},clone:function(){var b=n(this.node.cloneNode(!0));return b.node.id=a(),b},findOne:function(a){var b=this.node.querySelector(a);return b?n(b):void 0},find:function(a){for(var b=this.node.querySelectorAll(a),c=0,d=b.length;d>c;c++)b[c]=n(b[c]);return b},toLocalPoint:function(a,b){var c=this.svg().node,d=c.createSVGPoint();d.x=a,d.y=b;try{var e=d.matrixTransform(c.getScreenCTM().inverse()),f=this.node.getTransformToElement(c).inverse()}catch(g){return d}return e.matrixTransform(f)},translateCenterToPoint:function(a){var b=this.bbox(),c=g.rect(b).center();this.translate(a.x-c.x,a.y-c.y)},translateAndAutoOrient:function(a,b,c){var d=this.scale();this.attr("transform",""),this.scale(d.sx,d.sy);var e=this.svg().node,f=this.bbox(!1,c),i=e.createSVGTransform();i.setTranslate(-f.x-f.width/2,-f.y-f.height/2);var j=e.createSVGTransform(),k=g.point(a).changeInAngle(a.x-b.x,a.y-b.y,b);j.setRotate(k,0,0);var l=e.createSVGTransform(),m=g.point(a).move(b,f.width/2);l.setTranslate(a.x+(a.x-m.x),a.y+(a.y-m.y));var n=this.node.getTransformToElement(c),o=e.createSVGTransform();o.setMatrix(l.matrix.multiply(j.matrix.multiply(i.matrix.multiply(n))));var p=h(o.matrix);return this.translate(p.translateX,p.translateY),this.rotate(p.rotation),this},animateAlongPath:function(a,b){var c=n("animateMotion",a),d=n("mpath",{"xlink:href":"#"+n(b).node.id});c.append(d),this.append(c);try{c.node.beginElement()}catch(e){if("fake"===document.documentElement.getAttribute("smiling")){var f=c.node;f.animators=[];var g=f.getAttribute("id");g&&(id2anim[g]=f);for(var h=getTargets(f),i=0,j=h.length;j>i;i++){var k=h[i],l=new Animator(f,k,i);animators.push(l),f.animators[i]=l,l.register()}}}},hasClass:function(a){return new RegExp("(\\s|^)"+a+"(\\s|$)").test(this.node.getAttribute("class"))},addClass:function(a){if(!this.hasClass(a)){var b=this.node.getAttribute("class")||"";this.node.setAttribute("class",(b+" "+a).trim())}return this},removeClass:function(a){if(this.hasClass(a)){var b=this.node.getAttribute("class").replace(new RegExp("(\\s|^)"+a+"(\\s|$)","g"),"$2");this.node.setAttribute("class",b)}return this},toggleClass:function(a,b){var c="undefined"==typeof b?this.hasClass(a):!b;return c?this.removeClass(a):this.addClass(a),this}};var n=c;n.decomposeMatrix=h,n.rectToPath=j;var o=n("svg").node;return n.createSVGMatrix=function(a){var b=o.createSVGMatrix();for(var c in a)b[c]=a[c];return b},n.createSVGTransform=function(){return o.createSVGTransform()},n.createSVGPoint=function(a,b){var c=o.createSVGPoint();return c.x=a,c.y=b,c},n});




© 2015 - 2025 Weber Informatics LLC | Privacy Policy