snap.js/dist/savage-min.js

34 lines
70 KiB
JavaScript
Raw Normal View History

// .--.--.
// / / '.
// | : /`. /
// ; | |--` .---. ,----._,.
// | : ;_ ,--.--. /. ./| ,--.--. / / ' / ,---.
// \ \ `. / \ .-' . ' | / \ | : | / \
// `----. \.--. .-. /___/ \: | .--. .-. || | .\ . / / |
// __ \ \ | \__\/: . . \ ' . \__\/: . .. ; '; |. ' / |
// / /`--' / ," .--.; |\ \ ' ," .--.; |' . . |' ; /|
// '--'. / / / ,. | \ \ / / ,. | `---`-'| |' | / |
// `--'---' ; : .' \ \ \ |; : .' \.'__/\_: || : |
// | , .-./ '---" | , .-./| : : \ \ /
// `--`---' `--`---' \ \ / `----'
// `--`-'
// 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.
//
2013-09-17 06:33:21 +00:00
// build: 2013-09-17
!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);var mina=function(a){var b={},c=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,16)},d=Array.isArray||function(a){return a instanceof Array||"[object Array]"==Object.prototype.toString.call(a)},e=0,f="M"+(+new Date).toString(36),g=function(){return f+(e++).toString(36)},h=function(){return+new Date},i=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},j=function(a){var b=this;return null==a?b.spd:(b.spd=a,void 0)},k=function(a){var b=this;return null==a?b.dur:(b.s=b.s*a/b.dur,b.dur=a,void 0)},l=function(){var c=this;delete b[c.id],a("mina.stop."+c.id,c)},m=function(){var e=0;for(var f in b)if(b.hasOwnProperty(f)){var g,h=b[f],i=h.get();if(e++,h.s=(i-h.b)/(h.dur/h.spd),h.s>=1&&(delete b[f],h.s=1,e--),d(h.start)){g=[];for(var j=0,k=h.start.length;k>j;j++)g[j]=h.start[j]+(h.end[j]-h.start[j])*h.easing(h.s)}else g=h.start+(h.end-h.start)*h.easing(h.s);h.set(g),1==h.s&&a("mina.finish."+h.id,h)}e&&c(m)},n=function(a,d,e,f,h,o,p){var q={id:g(),start:a,end:d,b:e,s:0,dur:f-e,spd:1,get:h,set:o,easing:p||n.linear,status:i,speed:j,duration:k,stop:l};b[q.id]=q;var r,s=0;for(r in b)if(b.hasOwnProperty(r)&&(s++,2==s))break;return 1==s&&c(m),q};return n.time=h,n.getById=function(){return b[anim.id]||null},n.linear=function(a){return a},n.easeout=function(a){return Math.pow(a,1.7)},n.easein=function(a){return Math.pow(a,.48)},n.easeinout=function(a){if(1==a)return 1;if(0==a)return 0;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.p
2013-09-17 06:33:21 +00:00
}),eve.once("mina.stop."+s.id,function(){delete o.anims[s.id]}),o};var n={};d.data=function(b,c){var d=n[this.id]=n[this.id]||{};if(1==arguments.length){if(a.is(b,"object")){for(var e in b)b[x](e)&&this.data(e,b[e]);return this}return eve("savage.data.get."+this.id,this,d[b],b),d[b]}return d[b]=c,eve("savage.data.set."+this.id,this,c,b),this},d.removeData=function(a){return null==a?n[this.id]={}:n[this.id]&&delete n[this.id][a],this},d.toString=g(1),d.innerSVG=g()}(o.prototype),a.parse=function(a){var c=w.doc.createDocumentFragment(),d=c;return eve.on("elemental.tag",function(a,c){var e=b(a);c&&b(e,c),d.appendChild(e),d=e}),eve.on("elemental.text",function(a){d.appendChild(w.doc.createTextNode(a))}),eve.on("elemental./tag",function(){d=d.parentNode}),eve.on("elemental.eof",function(){eve.off("elemental.*"),eve("savage.parsed",c)}),elemental().parse(a).end(),new q(c)},q.prototype.select=o.prototype.select,q.prototype.selectAll=o.prototype.selectAll,a.fragment=function(){for(var b=Array.prototype.slice.call(arguments,0),c=w.doc.createDocumentFragment(),d=0,e=b.length;e>d;d++){var f=b[d];f.node&&f.node.nodeType&&c.appendChild(f.node),f.nodeType&&c.appendChild(f),"string"==typeof f&&c.appendChild(a.parse(f).node)}return new q(c)},function(d){d.el=function(a,b){return r(a,this.node).attr(b)},d.rect=function(a,b,d,e,f,g){var h=r("rect",this.node);return null==g&&(g=f),c(a,"object")&&"x"in a?h.attr(a):null!=a&&(h.attr({x:a,y:b,width:d,height:e}),null!=f&&h.attr({rx:f,ry:g})),h},d.circle=function(a,b,d){var e=r("circle",this.node);return c(a,"object")&&"cx"in a?e.attr(a):null!=a&&e.attr({cx:a,cy:b,r:d}),e},d.image=function(a,d,e,f,g){var h=r("image",this.node);if(c(a,"object")&&"src"in a)h.attr(a);else if(null!=a){var i={"xlink:href":a,preserveAspectRatio:"none"};null!=d&&null!=e&&(i.x=d,i.y=e),null!=f&&null!=g?(i.width=f,i.height=g):Y(a,function(){b(h.node,{width:this.offsetWidth,height:this.offsetHeight})}),b(h.node,i)}return h},d.ellipse=function(a,b,d,e){var f=r("ellipse",this.node);return c(a,"object")&&"cx"in a?f.attr(a):null!=a&&f.attr({cx:a,cy:b,rx:d,ry:e}),f},d.path=function(a){var b=r("path",this.node);return c(a,"object")&&!c(a,"array")?b.attr(a):a&&b.attr({d:a}),b},d.group=d.g=function(a){var b=r("g",this.node);b.add=n;for(var c in d)d[x](c)&&(b[c]=d[c]);return 1==arguments.length&&a&&!a.type?b.attr(a):arguments.length&&b.add(Array.prototype.slice.call(arguments,0)),b},d.text=function(a,b,d){var e=r("text",this.node);return c(a,"object")?e.attr(a):null!=a&&e.attr({x:a,y:b,text:d||""}),e},d.line=function(a,b,d,e){var f=r("line",this.node);return c(a,"object")?f.attr(a):null!=a&&f.attr({x1:a,x2:d,y1:b,y2:e}),f},d.polyline=function(a){arguments.length>1&&(a=Array.prototype.slice.call(arguments,0));var b=r("polyline",this.node);return c(a,"object")&&!c(a,"array")?b.attr(a):null!=a&&b.attr({points:a}),b},d.polygon=function(a){arguments.length>1&&(a=Array.prototype.slice.call(arguments,0));var b=r("polygon",this.node);return c(a,"object")&&!c(a,"array")?b.attr(a):null!=a&&b.attr({points:a}),b},function(){function c(){return this.selectAll("stop")}function e(a,c){var d=b("stop");return b(d,{"stop-color":a,offset:+c+"%"}),this.node.appendChild(d),this}function f(){if("linearGradient"==this.type){var c=b(this.node,"x1")||0,d=b(this.node,"x2")||1,e=b(this.node,"y1")||0,f=b(this.node,"y2")||0;return a._.box(c,e,B.abs(d-c),B.abs(f-e))}var g=this.node.cx||.5,h=this.node.cy||.5,i=this.node.r||0;return a._.box(g-i,h-i,2*i,2*i)}d.gradient=function(a){function c(a,b){for(var c=(b-h)/(a-i),d=i;a>d;d++)f[d].offset=+(+h+c*(d-i)).toFixed(2);i=a,h=b}var d,e=p(eve("savage.util.grad.parse",null,a));if(!e)return null;d="l"==e.type.toLowerCase()?this.gradientLinear.apply(this,e.params):this.gradientRadial.apply(this,e.params),e.type!=e.type.toLowerCase()&&b(d.node,{gradientUnits:"userSpaceOnUse"});var f=e.stops,g=f.length,h=0,i=0;g--;for(var j=0;g>j;j++)"offset"in f[j]&&c(j,f[j].offset);for(f[g].offset=f[g].offset||100,c(g,f[g].offset),j=0;g>=j;j++){var k=f[j];d.addStop(k.color,k.offset)}return d},d.gradientLinear=function(a,d,g,h){var i=r("
return a.preventDefault=a.preventDefault||k,a.stopPropagation=a.stopPropagation||m,c.call(e,a,g,h)};a.attachEvent("on"+b,f);var g=function(){return a.detachEvent("on"+b,f),!0};return g}:void 0}(),p=[],q=function(b){for(var c,d=b.clientX,e=b.clientY,f=j("y"),h=j("x"),i=p.length;i--;){if(c=p[i],g){for(var k,l=b.touches.length;l--;)if(k=b.touches[l],k.identifier==c.el._drag.id){d=k.clientX,e=k.clientY,(b.originalEvent?b.originalEvent:b).preventDefault();break}}else b.preventDefault();var m=c.el.node;a._.glob,m.nextSibling,m.parentNode,m.style.display,d+=h,e+=f,eve("savage.drag.move."+c.el.id,c.move_scope||c.el,d-c.el._drag.x,e-c.el._drag.y,d,e,b)}},r=function(b){a.unmousemove(q).unmouseup(r);for(var c,d=p.length;d--;)c=p[d],c.el._drag={},eve("savage.drag.end."+c.el.id,c.end_scope||c.start_scope||c.move_scope||c.el,b);p=[]},s=h.length;s--;)!function(b){a[b]=e[b]=function(c,e){return a.is(c,"function")&&(this.events=this.events||[],this.events.push({name:b,f:c,unbind:o(this.shape||this.node||d.doc,b,c,e||this)})),this},a["un"+b]=e["un"+b]=function(a){for(var c=this.events||[],d=c.length;d--;)if(c[d].name==b&&(c[d].f==a||!a))return c[d].unbind(),c.splice(d,1),!c.length&&delete this.events,this;return this}}(h[s]);e.hover=function(a,b,c,d){return this.mouseover(a,c).mouseout(b,d||c)},e.unhover=function(a,b){return this.unmouseover(a).unmouseout(b)};var t=[];e.drag=function(b,c,d,e,f,g){function h(h){(h.originalEvent||h).preventDefault();var i=j("y"),k=j("x");this._drag.x=h.clientX+k,this._drag.y=h.clientY+i,this._drag.id=h.identifier,!p.length&&a.mousemove(q).mouseup(r),p.push({el:this,move_scope:e,start_scope:f,end_scope:g}),c&&eve.on("savage.drag.start."+this.id,c),b&&eve.on("savage.drag.move."+this.id,b),d&&eve.on("savage.drag.end."+this.id,d),eve("savage.drag.start."+this.id,f||e||this,h.clientX+k,h.clientY+i,h)}if(!arguments.length){var i;return this.drag(function(a,b){this.attr({transform:i+(i?"T":"t")+[a,b]})},function(){i=this.transform().local})}return this._drag={},t.push({el:this,start:h}),this.mousedown(h),this},e.undrag=function(){for(var b=t.length;b--;)t[b].el==this&&(this.unmousedown(t[b].start),t.splice(b,1),eve.unbind("savage.drag.*."+this.id));return!t.length&&a.unmousemove(q).unmouseup(r),this}}),Savage.plugin(function(a,b,c){var d=(b.prototype,c.prototype),e=/^\s*url\((.+)\)/,f=String,g=a._.$;a.filter={},d.filter=function(c){var d=a.parse(f(c)),e=a._.id(),h=this.node.offsetWidth,i=this.node.offsetHeight,j=g("filter");return g(j,{id:e,filterUnits:"userSpaceOnUse",x:0,y:0,width:h,height:i}),j.appendChild(d.node),this.defs.appendChild(j),new b(j)},eve.on("savage.util.getattr.filter",function(){eve.stop();var b=g(this.node,"filter");if(b){var c=f(b).match(e);return c&&a.select(c[1])}}),eve.on("savage.util.attr.filter",function(a){if(a instanceof b&&"filter"==a.type){eve.stop();var c=a.node.id;c||(g(a.node,{id:a.id}),c=a.id),g(this.node,{filter:"url(#"+c+")"})}a&&"none"!=a||(eve.stop(),this.node.removeAttribute("filter"))}),a.filter.blur=function(b,c){null==b&&(b=2);var d=null==c?b:[b,c];return a.format('<feGaussianBlur stdDeviation="{def}"/>',{def:d})},a.filter.blur.toString=function(){return this()},a.filter.shadow=function(b,c,d,e){return e=e||"#000",null==d&&(d=4),null==b&&(b=0,c=2),null==c&&(c=b),a.format('<feGaussianBlur in="SourceAlpha" stdDeviation="{blur}"/><feOffset dx="{dx}" dy="{dy}" result="offsetblur"/><feFlood flood-color="{color}"/><feComposite in2="offsetblur" operator="in"/><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>',{color:e,dx:b,dy:c,blur:d})},a.filter.shadow.toString=function(){return this()},a.filter.grayscale=function(b){return null==b&&(b=1),a.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {b} {h} 0 0 0 0 0 1 0"/>',{a:.2126+.7874*(1-b),b:.7152-.7152*(1-b),c:.0722-.0722*(1-b),d:.2126-.2126*(1-b),e:.7152+.2848*(1-b),f:.0722-.0722*(1-b),g:.2126-.2126*(1-b),h:.0722+.9278*(1-b)})},a.filter.grayscale.toString=function(){return this()},a.filter.sepia=function(b){return null==b&&(b=1),a.format('<feColorMatrix type="matrix" values="{a} {b}