snap.js/savage-min.js

33 lines
60 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-15
!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(){return+new Date},e=function(a){var b=this;if(null==a)return b.s;var c=b.s-a;b.b+=b.dur*c,b.B+=b.dur*c,b.s=a},f=function(a){var b=this;return null==a?b.spd:(b.spd=a,void 0)},g=function(a){var b=this;return null==a?b.dur:(b.s=b.s*a/b.dur,b.dur=a,void 0)},h=function(){for(var d=0,e=a.length;e>d;d++){var f,g=a[d],i=g.get();if(g.s=(i-g.b)/(g.dur/g.spd),g.s>=1&&(a.splice(d,1),g.s=1),c(g.start)){f=[];for(var j=0,k=g.start.length;k>j;j++)f[j]=g.start[j]+(g.end[j]-g.start[j])*g.easing(g.s)}else f=g.start+(g.end-g.start)*g.easing(g.s);g.set(f)}a.length&&b(h)},i=function(c,d,j,k,l,m,n){var o={start:c,end:d,b:j,s:0,dur:k-j,spd:1,get:l,set:m,easing:n||i.linear,status:e,speed:f,duration:g};return a.push(o),1==a.length&&b(h),o};return i.time=d,i.linear=function(a){return a},i.easeout=function(a){return Math.pow(a,1.7)},i.easein=function(a){return Math.pow(a,.48)},i.easeinout=function(a){var b=.48-a/1.04,c=Math.sqrt(.1734+b*b),d=c-b,e=Math.pow(Math.abs(d),1/3)*(0>d?-1:1),f=-c-b,g=Math.pow(Math.abs(f),1/3)*(0>f?-1:1),h=e+g+.5;return 3*(1-h)*h*h+h*h*h},i.backin=function(a){var b=1.70158;return a*a*((b+1)*a-b)},i.backout=function(a){a-=1;var b=1.70158;return a*a*((b+1)*a+b)+1},i.elastic=function(a){return a==!!a?a:Math.pow(2,-10*a)*Math.sin((a-.075)*2*Math.PI/.3)+1},i.bounce=function(a){var b,c=7.5625,d=2.75;return 1
}(function(a){if(a instanceof n||a instanceof p){if(eve.stop(),"clipPath"==a.type)var c=a;else c=q("clipPath",this.paper.defs),c.node.appendChild(a.node),!c.node.id&&b(c.node,{id:c.id});b(this.node,{"clip-path":"url(#"+c.id+")"})}}),eve.on("savage.util.attr.fill",function(c){if(eve.stop(),c instanceof p&&1==c.node.childNodes.length&&("radialGradient"==c.node.firstChild.tagName||"linearGradient"==c.node.firstChild.tagName||"pattern"==c.node.firstChild.tagName)&&(c=c.node.firstChild,this.paper.defs.appendChild(c),c=s(c)),c instanceof n&&("radialGradient"==c.type||"linearGradient"==c.type||"pattern"==c.type)){c.node.id||b(c.node,{id:c.id});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.styl