snap.js/savage-min.js

33 lines
59 KiB
JavaScript
Raw Normal View History

2013-08-05 08:04:30 +00:00
// .--.--.
// / / '.
// | : /`. /
// ; | |--` .---. ,----._,.
// | : ;_ ,--.--. /. ./| ,--.--. / / ' / ,---.
// \ \ `. / \ .-' . ' | / \ | : | / \
// `----. \.--. .-. /___/ \: | .--. .-. || | .\ . / / |
// __ \ \ | \__\/: . . \ ' . \__\/: . .. ; '; |. ' / |
// / /`--' / ," .--.; |\ \ ' ," .--.; |' . . |' ; /|
// '--'. / / / ,. | \ \ / / ,. | `---`-'| |' | / |
// `--'---' ; : .' \ \ \ |; : .' \.'__/\_: || : |
// | , .-./ '---" | , .-./| : : \ \ /
// `--`---' `--`---' \ \ / `----'
// `--`-'
// Savage 0.0.1
//
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// build: 2013-08-09
!function(a){var b,c,d="0.4.2",e="hasOwnProperty",f=/[\.\/]/,g="*",h=function(){},i=function(a,b){return a-b},j={n:{}},k=function(a,d){a=String(a);var e,f=c,g=Array.prototype.slice.call(arguments,2),h=k.listeners(a),j=0,l=[],m={},n=[],o=b;b=a,c=0;for(var p=0,q=h.length;q>p;p++)"zIndex"in h[p]&&(l.push(h[p].zIndex),h[p].zIndex<0&&(m[h[p].zIndex]=h[p]));for(l.sort(i);l[j]<0;)if(e=m[l[j++]],n.push(e.apply(d,g)),c)return c=f,n;for(p=0;q>p;p++)if(e=h[p],"zIndex"in e)if(e.zIndex==l[j]){if(n.push(e.apply(d,g)),c)break;do if(j++,e=m[l[j]],e&&n.push(e.apply(d,g)),c)break;while(e)}else m[e.zIndex]=e;else if(n.push(e.apply(d,g)),c)break;return c=f,b=o,n.length?n:null};k._events=j,k.listeners=function(a){var b,c,d,e,h,i,k,l,m=a.split(f),n=j,o=[n],p=[];for(e=0,h=m.length;h>e;e++){for(l=[],i=0,k=o.length;k>i;i++)for(n=o[i].n,c=[n[m[e]],n[g]],d=2;d--;)b=c[d],b&&(l.push(b),p=p.concat(b.f||[]));o=l}return p},k.on=function(a,b){if(a=String(a),"function"!=typeof b)return function(){};for(var c=a.split(f),d=j,e=0,g=c.length;g>e;e++)d=d.n,d=d.hasOwnProperty(c[e])&&d[c[e]]||(d[c[e]]={n:{}});for(d.f=d.f||[],e=0,g=d.f.length;g>e;e++)if(d.f[e]==b)return h;return d.f.push(b),function(a){+a==+a&&(b.zIndex=+a)}},k.f=function(a){var b=[].slice.call(arguments,1);return function(){k.apply(null,[a,null].concat(b).concat([].slice.call(arguments,0)))}},k.stop=function(){c=1},k.nt=function(a){return a?new RegExp("(?:\\.|\\/|^)"+a+"(?:\\.|\\/|$)").test(b):b},k.nts=function(){return b.split(f)},k.off=k.unbind=function(a,b){if(!a)return k._events=j={n:{}},void 0;var c,d,h,i,l,m,n,o=a.split(f),p=[j];for(i=0,l=o.length;l>i;i++)for(m=0;m<p.length;m+=h.length-2){if(h=[m,1],c=p[m].n,o[i]!=g)c[o[i]]&&h.push(c[o[i]]);else for(d in c)c[e](d)&&h.push(c[d]);p.splice.apply(p,h)}for(i=0,l=p.length;l>i;i++)for(c=p[i];c.n;){if(b){if(c.f){for(m=0,n=c.f.length;n>m;m++)if(c.f[m]==b){c.f.splice(m,1);break}!c.f.length&&delete c.f}for(d in c.n)if(c.n[e](d)&&c.n[d].f){var q=c.n[d].f;for(m=0,n=q.length;n>m;m++)if(q[m]==b){q.splice(m,1);break}!q.length&&delete c.n[d].f}}else{delete c.f;for(d in c.n)c.n[e](d)&&c.n[d].f&&delete c.n[d].f}c=c.n}},k.once=function(a,b){var c=function(){return k.unbind(a,c),b.apply(this,arguments)};return k.on(a,c)},k.version=d,k.toString=function(){return"You are running Eve "+d},"undefined"!=typeof module&&module.exports?module.exports=k:"undefined"!=typeof define?define("eve",[],function(){return k}):a.eve=k}(this),window.mina=function(){var a=[],b=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,16)},c=Array.isArray||function(a){return a instanceof Array||"[object Array]"==Object.prototype.toString.call(a)},d=function(a,b,e,f){if(c(a)){res=[];for(var g=0,h=a.length;h>g;g++)res[g]=d(a[g],b,e[g],f);return res}var i=(e-a)/(f-b);return function(c){return a+i*(c-b)}},e=function(){return+new Date},f=function(){for(var d,e,g=0;g<a.length;g++){var h=a[g],i=h.b+(h.gen()-h.b)*h["*"]+h["+"];if(c(h.a)){d=[];for(var j=0,k=h.a.length;k>j;j++)d[j]=h.dif[j](i),e=h.A[j]-h.a[j],d[j]=e?h.a[j]+h.easing((d[j]-h.a[j])/e)*e:h.a[j]}else d=h.dif(i),e=h.A-h.a,d=h.a+h.easing((d-h.a)/e)*e;try{h.stopper(i)?--h.iterations?h["+"]+=h.b-h.B:(a.splice(g--,1),h.framer(h.A),h.callback&&h.callback()):h.framer(d)}catch(l){console.error(l)}}a.length&&b(f)},g=function(a){if(this["*"]=Math.abs(a),this.speed=a,0>a){var b=this.a;this.a=this.A,this.A=b,this.dif=d(this.a,this.b,this.A,this.B),this.stopper=j(this.b,this.B)}},h=function(){for(var b=0,c=a.length;c>b;b++)if(a[b]==this)return a.splice(b,1),void 0},i=function(c,e,i,j,l,m,n,o){var p={framer:l,callback:m,dif:d(c,i,e,j),easing:k.linear,"+":0,"*":1,gen:n,speed:1,iterations:1,stopper:o,a:c,b:i,A:e,B:j,setSpeed:g,stop:h};return a.push(p),1==a.length&&b(f),p},j=function(a,b){return function(c){return b>a?c>=b:b>=c}},k=function(a,b,c,d,f){var g=e(),h=g+c;return d(a),i(a,b,g,h,d,f,e,j(g,h))};return k.linear=function(a){return a},k.easeout=function(a){return Math.pow(a,1.7)},k.easein=function(a){return Math
2013-08-05 08:04:30 +00:00
var d="url(#"+c.node.id+")"}else if(d=a.color(c),d.error){var e=this.paper.gradient(c);e.node.id||b(e.node,{id:e.id}),d="url(#"+e.node.id+")"}else d=v(d);b(this.node,{fill:d}),this.node.style.fill=D});var cb=/^([lr])(?:\(([^)]*)\))?(.*)$/i;eve.on("savage.util.grad.parse",function(a){a=v(a);var b=a.match(cb),c=b[1],d=b[2],e=b[3];return d=d.split(/\s*,\s*/).map(function(a){return+a==a?+a:a}),1==d.length&&0==d[0]&&(d=[]),e=e.split("-"),e=e.map(function(a){a=a.split(":");var b={color:a[0]};return a[1]&&(b.offset=a[1]),b}),{type:c,params:d,stops:e}}),eve.on("savage.util.attr.d",function(d){eve.stop(),c(d,"array")&&c(d[0],"array")&&(d=a.path.toString.call(d)),d=v(d),d.match(/[ruo]/i)&&(d=a.path.toAbsolute(d)),b(this.node,{d:d})})(-1),eve.on("savage.util.attr.path",function(a){eve.stop(),this.attr({d:a})})(-1),eve.on("savage.util.attr.viewBox",function(a){var d;d=c(a,"object")&&"x"in a?[a.x,a.y,a.width,a.height].join(" "):c(a,"array")?a.join(" "):a,b(this.node,{viewBox:d}),eve.stop()})(-1),eve.on("savage.util.attr.transform",function(a){this.transform(a),eve.stop()})(-1),eve.on("savage.util.attr.r",function(a){"rect"==this.type&&(eve.stop(),b(this.node,{rx:a,ry:a}))})(-1),eve.on("savage.util.attr.text",function(a){if("text"==this.type){for(var d=this.node,e=function(a){var d=b("tspan");if(c(a,"array"))for(var f=0;f<a.length;f++)d.appendChild(e(a[f]));else d.appendChild(t.doc.createTextNode(a));return d.normalize&&d.normalize(),d};d.firstChild;)d.removeChild(d.firstChild);d.appendChild(e(a))}eve.stop()})(-1);var db={rect:{x:0,y:0,width:0,height:0,rx:0,ry:0,"class":0},circle:{cx:0,cy:0,r:0,"class":0},ellipse:{cx:0,cy:0,rx:0,ry:0,"class":0},line:{x1:0,y1:0,x2:0,y2:0,"class":0},polyline:{points:"","class":0},polygon:{points:"","class":0},text:{x:0,y:0,dx:0,dy:0,rotate:0,textLength:0,lengthAdjust:0,"class":0},tspan:{x:0,y:0,dx:0,dy:0,rotate:0,textLength:0,lengthAdjust:0,"class":0},textPath:{"xlink:href":0,startOffset:0,method:0,spacing:0,"class":0},marker:{viewBox:0,preserveAspectRatio:0,refX:0,refY:0,markerUnits:0,markerWidth:0,markerHeight:0,orient:0,"class":0},linearGradient:{x1:0,y1:0,x2:0,y2:0,gradientUnits:0,gradientTransform:0,spreadMethod:0,"xlink:href":0,"class":0},radialGradient:{cx:0,cy:0,r:0,fx:0,fy:0,gradientUnits:0,gradientTransform:0,spreadMethod:0,"xlink:href":0,"class":0},stop:{offset:0,"class":0},pattern:{viewBox:0,preserveAspectRatio:0,x:0,y:0,width:0,height:0,patternUnits:0,patternContentUnits:0,patternTransform:0,"xlink:href":0,"class":0},clipPath:{transform:0,clipPathUnits:0,"class":0},mask:{x:0,y:0,width:0,height:0,maskUnits:0,maskContentUnits:0,"class":0},image:{preserveAspectRatio:0,transform:0,x:0,y:0,width:0,height:0,"xlink:href":0,"class":0},path:{d:"","class":0}};return eve.on("savage.util.attr",function(a){var b=eve.nt();b=b.substring(b.lastIndexOf(".")+1);var c=b.replace(/-(\w)/gi,function(a,b){return b.toUpperCase()});db[u](this.type)&&db[this.type][u](b)?null==a?this.node.removeAttribute(b):this.node.setAttribute(b,a):this.node.style[c]=null==a?D:a}),eve.on("savage.util.getattr.transform",function(){return eve.stop(),this.transform()})(-1),function(){function c(b){return function(){eve.stop();var c=t.doc.defaultView.getComputedStyle(this.node,null).getPropertyValue("marker-"+b);return"none"==c?c:a(t.doc.getElementById(c.match(I)[1]))}}function d(a){return function(c){eve.stop();var d="marker"+a.charAt(0).toUpperCase()+a.substring(1);if(""==c||!c)return this.node.style[d]="none",void 0;if("marker"==c.type){var e=c.node.id;return e||b(c.node,{id:c.id}),this.node.style[d]="url(#"+e+")",void 0}}}eve.on("savage.util.getattr.marker-end",c("end"))(-1),eve.on("savage.util.getattr.markerEnd",c("end"))(-1),eve.on("savage.util.getattr.marker-start",c("start"))(-1),eve.on("savage.util.getattr.markerStart",c("start"))(-1),eve.on("savage.util.getattr.marker-mid",c("mid"))(-1),eve.on("savage.util.getattr.markerMid",c("mid"))(-1),eve.on("savage.util.attr.marker-end",d("end"))(-1),eve.on("savage.util.attr.markerEnd",d("end"))(-1),eve.on("savage.util.attr.marker-start",d("start"))(-1),eve.on("savage.util.attr.markerS