paper.js/dist/paper-core.min.js

36 lines
154 KiB
JavaScript
Raw Normal View History

2013-06-26 22:42:24 -04:00
/*!
2013-06-27 17:31:42 -04:00
* Paper.js v0.9.7 - The Swiss Army Knife of Vector Graphics Scripting.
2013-06-26 22:42:24 -04:00
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
2013-06-27 17:31:42 -04:00
* Date: Thu Jun 27 14:31:03 2013 -0700
2013-06-26 22:42:24 -04:00
*
***
*
* straps.js - Class inheritance library with support for bean-style accessors
*
* Copyright (c) 2006 - 2013 Juerg Lehni
* http://lehni.org/
*
* Distributed under the MIT license.
*
***
*
* acorn.js
* http://marijnhaverbeke.nl/acorn/
*
* Acorn is a tiny, fast JavaScript parser written in JavaScript,
* created by Marijn Haverbeke and released under an MIT license.
*
*/
2013-06-27 17:31:42 -04:00
var paper=new function(){var t=new function(){function e(t,e,n,i,r,a){function h(i,s,a,h){var s=s||(s=d(e,i))&&(s.get?s:s.value);"string"==typeof s&&"#"===s[0]&&(s=e[s.substring(1)]||s);var l,c="function"==typeof s,_=s,g=r||c?s&&s.get?i in t:t[i]:null;!(a||void 0!==s&&e.hasOwnProperty(i))||r&&g||(c&&g&&(s.base=g),c&&u&&0===s.length&&(l=i.match(/^(get|is)(([A-Z])(.*))$/))&&u.push([l[3].toLowerCase()+l[4],l[2]]),_&&!c&&_.get||(_={value:_,writable:!0}),(d(t,i)||{configurable:!0}).configurable&&(_.configurable=!0,_.enumerable=n),f(t,i,_)),!h||!c||r&&h[i]||(h[i]=function(e){return e&&t[i].apply(e,o.call(arguments,1))})}var u;if(e){u=[];for(var l in e)e.hasOwnProperty(l)&&!s.test(l)&&h(l,null,!0,a);h("toString"),h("valueOf");for(var c=0,_=u&&u.length;_>c;c++)try{var g=u[c],v=g[1];h(g[0],{get:t["get"+v]||t["is"+v],set:t["set"+v]},!0)}catch(m){}}return t}function n(e,n,i,s){try{e&&(s||void 0===s&&l(e)?h:u).call(e,n,i=i||e)}catch(r){if(r!==t.stop)throw r}return i}function i(t){return n(t,function(t,e){this[e]=t},new t.constructor)}var s=/^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,r=Object.prototype.toString,a=Array.prototype,o=a.slice,h=a.forEach||function(t,e){for(var n=0,i=this.length;i>n;n++)t.call(e,this[n],n,this)},u=function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)},l=Array.isArray=Array.isArray||function(t){return"[object Array]"===r.call(t)},c=Object.create||function(t){return{__proto__:t}},d=Object.getOwnPropertyDescriptor||function(t,e){var n=t.__lookupGetter__&&t.__lookupGetter__(e);return n?{get:n,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},_=Object.defineProperty||function(t,e,n){return(n.get||n.set)&&t.__defineGetter__?(n.get&&t.__defineGetter__(e,n.get),n.set&&t.__defineSetter__(e,n.set)):t[e]=n.value,t},f=function(t,e,n){return delete t[e],_(t,e,n)};return e(function(){},{inject:function(t){if(t){var n=this.prototype,i=Object.getPrototypeOf(n).constructor,s=t.statics===!0?t:t.statics;s!=t&&e(n,t,t.enumerable,i&&i.prototype,t.preserve,t.generics&&this),e(this,s,!0,i,t.preserve)}for(var r=1,a=arguments.length;a>r;r++)this.inject(arguments[r]);return this},extend:function(){for(var t,n=this,i=0,s=arguments.length;s>i&&!(t=arguments[i].initialize);i++);return t=t||function(){n.apply(this,arguments)},t.prototype=c(this.prototype),f(t.prototype,"constructor",{value:t,writable:!0,configurable:!0}),e(t,this,!0),arguments.length?this.inject.apply(t,arguments):t}},!0).inject({inject:function(){for(var t=0,n=arguments.length;n>t;t++)e(this,arguments[t],arguments[t].enumerable);return this},extend:function(){var t=c(this);return t.inject.apply(t,arguments)},each:function(t,e){return n(this,t,e)},clone:function(){return i(this)},statics:{each:n,clone:i,define:f,describe:d,create:function(t){return c(t.prototype)},isPlainObject:function(e){var n=null!=e&&e.constructor;return n&&(n===Object||n===t||"Object"===n.name)},check:function(t){return!(!t&&0!==t)},pick:function(){for(var t=0,e=arguments.length;e>t;t++)if(void 0!==arguments[t])return arguments[t];return null},stop:{}}})};"undefined"!=typeof module&&(module.exports=t),t.inject({generics:!0,clone:function(){return new this.constructor(this)},toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+t.each(this,function(t,e){if(!/^_/.test(e)){var n=typeof t;this.push(e+": "+("number"===n?r.instance.number(t):"string"===n?"'"+t+"'":t))}},[]).join(", ")+" }"},exportJSON:function(e){return t.exportJSON(this,e)},toJSON:function(){return t.serialize(this)},_set:function(e){if(e&&t.isPlainObject(e)){for(var n in e)e.hasOwnProperty(n)&&n in this&&(this[n]=e[n]);return!0}},statics:{exports:{},extend:function ee(){var e=ee.base.apply(this,arguments),n=e.prototype._class;return n&&!t.exports[n]&&(t.exports[n]=e),e},equals:function(e,n){function i(t,e){for(var n in t)if(t.hasOwnProperty(n)&&void 0===e[n])return!1;return!0}if(e===n)return!0;if(e&&e.equals)return e.equals(n);if(n
},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new f(this._d/t,-this._c/t,-this._b/t,this._a/t,(this._b*this._ty-this._d*this._tx)/t,(this._c*this._tx-this._a*this._ty)/t)},shiftless:function(){return new f(this._a,this._c,this._b,this._d,0,0)},applyToContext:function(t){t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},new function(){return t.each({scaleX:"_a",scaleY:"_d",translateX:"_tx",translateY:"_ty",shearX:"_b",shearY:"_c"},function(e,n){n=t.capitalize(n),this["get"+n]=function(){return this[e]},this["set"+n]=function(t){this[e]=t}},{})}),g=t.extend({_class:"Line",initialize:function(t,e,n,i,s){var r=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,r=s):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,r=n),r||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new o(this._px,this._py)},getVector:function(){return new o(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return g.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t){return g.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},getDistance:function(t){return Math.abs(g.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},statics:{intersect:function(t,e,n,i,s,r,h,u,l,c){l||(n-=t,i-=e,h-=s,u-=r);var d=u*n-h*i;if(!a.isZero(d)){var _=t-s,f=e-r,g=(h*f-u*_)/d,v=(n*f-i*_)/d;if((c||g>=0&&1>=g)&&(c||v>=0&&1>=v))return new o(t+g*n,e+g*i)}},getSide:function(t,e,n,i,s,r,a){a||(n-=t,i-=e);var o=s-t,h=r-e,u=o*i-h*n;return 0===u&&(u=o*n+h*i,u>0&&(o-=n,h-=i,u=o*n+h*i,0>u&&(u=0))),0>u?-1:u>0?1:0},getSignedDistance:function(t,e,n,i,s,r,a){a||(n-=t,i-=e);var o=i/n,h=e-o*t;return(r-o*s-h)/Math.sqrt(o*o+1)}}}),v=s.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){s.call(this,!0),this.layers=[],this.symbols=[],this._currentStyle=new E,this.activeLayer=new w,t&&(this.view=t instanceof V?t:V.create(t)),this._selectedItems={},this._selectedItemCount=0,this._drawCount=0,this.options={}},_serialize:function(e,n){return t.serialize(this.layers,e,!0,n)},clear:function(){for(var t=this.layers.length-1;t>=0;t--)this.layers[t].remove();this.symbols=[]},remove:function re(){return re.base.call(this)?(this.view&&this.view.remove(),!0):!1},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getSelectedItems:function(){var t=[];for(var e in this._selectedItems){var n=this._selectedItems[e];n._drawCount===this._drawCount&&t.push(n)}return t},_updateSelection:function(t){t._selected?(this._selectedItemCount++,this._selectedItems[t._id]=t,t.isInserted()&&(t._drawCount=this._drawCount)):(this._selectedItemCount--,delete this._selectedItems[t._id])},selectAll:function(){for(var t=0,e=this.layers.length;e>t;t++)this.layers[t].setSelected(!0)},deselectAll:function(){for(var t in this._selectedItems)this._selectedItems[t].setSelected(!1)},hitTest:function(e,n){e=o.read(arguments),n=S.getOptions(t.read(arguments));for(var i=this.layers.length-1;i>=0;i--){var s=this.layers[i].hitTest(e,n);if(s)return s}return null},importJSON:function(e){return this.activate(),t.importJSON(e)},draw:function(e,n){this._drawCount++,e.save(),n.applyToContext(e);for(var i=t.merge({offset:new o(0,0),transforms:[n]}),s=0,r=this.layers.length;r>s;s++)this.layers[s].draw(e,i);if(e.restore(),this._selectedItemCount>0){e.save(),e.strokeWidth=1;for(var a in this._selectedItems){var h=this._selectedItems[a];if(h._drawCount===this._drawCount&&(h._drawSelected||h._boundsSelected)){var u=h.getSelectedColor()||h.getLayer().getSelectedColor();e.strokeStyle=e.fillStyle=u?u.toCanvasStyle(e):"#009dec";var l=h._globalMatrix;if(h._drawSelected&&h._drawSelected(e,l),h._boundsSelected){var c=l._transformCorners(h._getBounds("getBounds"));e.beginPath();for(var s=0;8>s;s++)e[0===s?"moveTo":"lineTo"](c[s],c[++s]);e.closePath(),e.stroke();for(var s=0;8>s;s++)e.be
2013-06-26 22:42:24 -04:00
},getLocation:function(){var t=this.getCurve();return t?new I(t,t.getNext()?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},reverse:function(){return new P(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new P(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._point.equals(t._point)&&this._handleIn.equals(t._handleIn)&&this._handleOut.equals(t._handleOut)||!1},toString:function(){var t=["point: "+this._point];return this._handleIn.isZero()||t.push("handleIn: "+this._handleIn),this._handleOut.isZero()||t.push("handleOut: "+this._handleOut),"{ "+t.join(", ")+" }"},_transformCoordinates:function(t,e,n){var i=this._point,s=n&&this._handleIn.isZero()?null:this._handleIn,r=n&&this._handleOut.isZero()?null:this._handleOut,a=i._x,o=i._y,h=2;return e[0]=a,e[1]=o,s&&(e[h++]=s._x+a,e[h++]=s._y+o),r&&(e[h++]=r._x+a,e[h++]=r._y+o),t&&(t._transformCoordinates(e,0,e,0,h/2),a=e[0],o=e[1],n?(i._x=a,i._y=o,h=2,s&&(s._x=e[h++]-a,s._y=e[h++]-o),r&&(r._x=e[h++]-a,r._y=e[h++]-o)):(s||(e[h++]=a,e[h++]=o),r||(e[h++]=a,e[h++]=o))),e}}),M=o.extend({initialize:function(t,e){var n,i,s;t?void 0!==(n=t[0])?i=t[1]:(void 0===(n=t.x)&&(t=o.read(arguments),n=t.x),i=t.y,s=t.selected):n=i=0,this._x=n,this._y=i,this._owner=e,s&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner._changed(this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner._changed(this)},isZero:function(){return a.isZero(this._x)&&a.isZero(this._y)},setSelected:function(t){this._owner._setSelected(this,t)},isSelected:function(){return this._owner._isSelected(this)}}),z=t.extend({_class:"Curve",initialize:function(t,e,n,i,s,r,a,o){var h=arguments.length;if(3===h)this._path=t,this._segment1=e,this._segment2=n;else if(0===h)this._segment1=new P,this._segment2=new P;else if(1===h)this._segment1=new P(t.segment1),this._segment2=new P(t.segment2);else if(2===h)this._segment1=new P(t),this._segment2=new P(e);else{var u,l,c,d;4===h?(u=t,l=e,c=n,d=i):8===h&&(u=[t,e],d=[a,o],l=[n-t,i-e],c=[s-a,r-o]),this._segment1=new P(u,null,l),this._segment2=new P(d,c,null)}},_changed:function(){delete this._length,delete this._bounds},getPoint1:function(){return this._segment1._point},setPoint1:function(t){t=o.read(arguments),this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(t){t=o.read(arguments),this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(t){t=o.read(arguments),this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(t){t=o.read(arguments),this._segment2._handleIn.set(t.x,t.y)},getSegment1:function(){return this._segment1},getSegment2:function(){return this._segment2},getPath:function(){return this._path},getIndex:function(){return this._segment1._index},getNext:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index+1]||this._path._closed&&t[0])||null},getPrevious:function(){var t=this._path&&this._path._curves;return t&&(t[this._segment1._index-1]||this._path._closed&&t[t.length-1])||null},isSelected:function(){return this.getHandle1().isSelected()&&this.getHandle2().isSelected()},setSelected:function(t){this.getHandle1().setSelected(t),this.getHandle2().setSelected(t)},getValues:function(){return z.getValues(this._segment1,this._segment2)},getPoints:function(){for(var t=this.getValues(),e=[],n=0;8>n;n+=2)e.push(new o(t[n],t[n+1]));return e},getLength:function(){var t=arguments[0],e=arguments[1],n=0===arguments.length||0===t&&1===e;if(n&&null!=this._length)return this._length;var i=z.getLength(this.getValues(),t
2013-06-27 17:31:42 -04:00
var i=e(this)._point;this.arcTo(i.add(t),i.add(n))},closePath:function(){var t=this.getFirstSegment(),e=this.getLastSegment();t._point.equals(e._point)&&(t.setHandleIn(e._handleIn),e.remove()),this.setClosed(!0)}}},{_getBounds:function(t,e){return A[t](this._segments,this._closed,this.getStyle(),e)},statics:{isClockwise:function(t){function e(t,e){r&&(s+=(n-t)*(e+i)),n=t,i=e,r=!0}for(var n,i,s=0,r=!1,a=0,o=t.length;o>a;a++){var h=t[a],u=t[o>a+1?a+1:0],l=h._point,c=h._handleOut,d=u._handleIn,_=u._point;e(l._x,l._y),e(l._x+c._x,l._y+c._y),e(_._x+d._x,_._y+d._y),e(_._x,_._y)}return s>0},getBounds:function(t,e,n,i,s){function r(t){t._transformCoordinates(i,o,!1);for(var e=0;2>e;e++)z._addBounds(h[e],h[e+4],o[e+2],o[e],e,s?s[e]:0,u,l,c);var n=h;h=o,o=n}var a=t[0];if(!a)return new d;for(var o=Array(6),h=a._transformCoordinates(i,Array(6),!1),u=h.slice(0,2),l=u.slice(),c=Array(2),_=1,f=t.length;f>_;_++)r(t[_]);return e&&r(a),new d(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,n,i){function s(t,e){if(!e)return[t,t];var n=e.shiftless(),i=n.transform(new o(t,0)),s=n.transform(new o(0,t)),r=i.getAngleInRadians(),a=i.getLength(),h=s.getLength(),u=Math.sin(r),l=Math.cos(r),c=Math.tan(r),d=-Math.atan(h*c/a),_=Math.atan(h/(c*a));return[Math.abs(a*Math.cos(d)*l-h*Math.sin(d)*u),Math.abs(h*Math.sin(_)*l+a*Math.cos(_)*u)]}function r(t){f=f.include(i?i._transformPoint(t,t):t)}function a(t,e){"round"===e||!t._handleIn.isZero()&&!t._handleOut.isZero()?f=f.unite(p.setCenter(i?i._transformPoint(t._point):t._point)):A._addSquareJoin(t,e,c,m,r)}function h(t,e){switch(e){case"round":a(t,e);break;case"butt":case"square":A._addSquareCap(t,e,c,r)}}if(!n.getStrokeColor()||!n.getStrokeWidth())return A.getBounds(t,e,n,i);for(var l=t.length-(e?0:1),c=n.getStrokeWidth()/2,_=s(c,i),f=A.getBounds(t,e,n,i,_),g=n.getStrokeJoin(),v=n.getStrokeCap(),m=c*n.getMiterLimit(),p=new d(new u(_).multiply(2)),y=1;l>y;y++)a(t[y],g);return e?a(t[0],g):(h(t[0],v),h(t[t.length-1],v)),f},_addSquareJoin:function(t,e,n,i,s,r){var a=t.getCurve(),h=a.getPrevious(),u=a.getPointAt(0,!0),l=h.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=l.getDirectedAngle(c)<0?-n:n;if(l.setLength(d),c.setLength(d),r&&(s(u),s(u.add(l))),"miter"===e){var _=new g(u.add(l),new o(-l.y,l.x),!0).intersect(new g(u.add(c),new o(-c.y,c.x),!0),!0);if(_&&u.getDistance(_)<=i&&(s(_),!r))return}r||s(u.add(l)),s(u.add(c))},_addSquareCap:function(t,e,n,i,s){var r=t._point,a=t.getLocation(),o=a.getNormal().normalize(n);s&&(i(r.subtract(o)),i(r.add(o))),"square"===e&&(r=r.add(o.rotate(0==a.getParameter()?-90:90))),i(r.add(o)),i(r.subtract(o))},getHandleBounds:function(t,e,n,i,s,r){var a=Array(6),o=1/0,h=-o,u=o,l=h;s=s/2||0,r=r/2||0;for(var c=0,_=t.length;_>c;c++){var f=t[c];f._transformCoordinates(i,a,!1);for(var g=0;6>g;g+=2){var v=0==g?r:s,m=a[g],p=a[g+1],y=m-v,w=m+v,x=p-v,b=p+v;o>y&&(o=y),w>h&&(h=w),u>x&&(u=x),b>l&&(l=b)}}return new d(o,u,h-o,l-u)},getRoughBounds:function(t,e,n,i){var s=n.getStrokeColor()?n.getStrokeWidth():0,r=s;return s>0&&("miter"===n.getStrokeJoin()&&(r=s*n.getMiterLimit()),"square"===n.getStrokeCap()&&(r=Math.max(r,s*Math.sqrt(2)))),A.getHandleBounds(t,e,n,i,s,r)}}});A.inject({statics:new function(){function e(e){var n=new A,i=t.getNamed(e);return i&&n._set(i),n}function n(){var t=d.readNamed(arguments,"rectangle"),n=u.readNamed(arguments,"radius",0,0,!0),i=t.getBottomLeft(!0),r=t.getTopLeft(!0),a=t.getTopRight(!0),o=t.getBottomRight(!0),h=e(arguments);if(!n||n.isZero())h._add([new P(i),new P(r),new P(a),new P(o)]);else{n=u.min(n,t.getSize(!0).divide(2));var l=n.multiply(2*s);h._add([new P(i.add(n.width,0),null,[-l.width,0]),new P(i.subtract(0,n.height),[0,l.height],null),new P(r.add(0,n.height),null,[0,-l.height]),new P(r.add(n.width,0),[-l.width,0],null),new P(a.subtract(n.width,0),null,[l.width,0]),new P(a.add(0,n.height),[0,-l.height],null),new P(o.subtract(0,n.height),null,[0,l.height]),new P(o.subtract(n.width,0),[l.width,0],null)])}return h._closed=!0,h}function i(){for(var t=d.readNamed(arguments,"rectangle"),n=e(arguments),i=t.getPoint(!0),s=t.getSize(!0),a=Array(4),o=0;
},_events:{onFrame:{install:function(){this._requested||(this._animate=!0,this._handleFrame(!0))},uninstall:function(){this._animate=!1}},onResize:{}},_animate:!1,_time:0,_count:0,_handleFrame:function(e){if(this._requested=!1,this._animate){if(paper=this._scope,e){this._requested=!0;var n=this;q.requestAnimationFrame(function(){n._handleFrame(!0)},this._element)}var i=Date.now()/1e3,s=this._before?i-this._before:0;this._before=i,this._handlingFrame=!0,this.fire("frame",t.merge({delta:s,time:this._time+=s,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.draw(!0)}},_animateItem:function(t,e){var n=this._frameItems;e?(n[t._id]={item:t,time:0,count:0},1==++this._frameItemCount&&this.attach("frame",this._handleFrameItems)):(delete n[t._id],0==--this._frameItemCount&&this.detach("frame",this._handleFrameItems))},_handleFrameItems:function(e){for(var n in this._frameItems){var i=this._frameItems[n];i.item.fire("frame",t.merge(e,{time:i.time+=e.delta,count:i.count++}))}},_redraw:function(){this._project._needsRedraw=!0,this._handlingFrame||(this._animate?this._handleFrame():this.draw())},_transform:function(t){this._matrix.concatenate(t),this._bounds=null,this._inverse=null,this._redraw()},getElement:function(){return this._element},getViewSize:function(){return this._viewSize},setViewSize:function(t){t=u.read(arguments);var e=t.subtract(this._viewSize);e.isZero()||(this._element.width=t.width,this._element.height=t.height,this._viewSize.set(t.width,t.height,!0),this._bounds=null,this.fire("resize",{size:t,delta:e}),this._redraw())},getBounds:function(){return this._bounds||(this._bounds=this._getInverse()._transformBounds(new d(new o,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(arguments[0])},getCenter:function(){return this.getBounds().getCenter(arguments[0])},setCenter:function(t){t=o.read(arguments),this.scrollBy(t.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(t){this._transform((new f).scale(t/this._zoom,this.getCenter())),this._zoom=t},isVisible:function(){return R.isInView(this._element)},scrollBy:function(){this._transform((new f).translate(o.read(arguments).negate()))},projectToView:function(){return this._matrix._transformPoint(o.read(arguments))},viewToProject:function(){return this._getInverse()._transformPoint(o.read(arguments))},_getInverse:function(){return this._inverse||(this._inverse=this._matrix.inverted()),this._inverse}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t){return"string"==typeof t&&(t=document.getElementById(t)),new H(t)}}},new function(){function t(t){var e=q.getTarget(t);return e.getAttribute&&V._viewsById[e.getAttribute("id")]}function e(t,e){return t.viewToProject(q.getOffset(e,t._element))}function n(){if(!V._focused||!V._focused.isVisible())for(var t=0,e=V._views.length;e>t;t++){var n=V._views[t];if(n&&n.isVisible()){V._focused=u=n;break}}}function i(n){var i=V._focused=t(n),s=e(i,n);l=!0,i._onMouseDown&&i._onMouseDown(n,s),(o=i._scope._tool)&&o._onHandleEvent("mousedown",s,n),i.draw(!0)}function s(i){var s;if(l||(s=t(i),s?(h=V._focused,V._focused=u=s):u&&u==V._focused&&(V._focused=h,n())),s=s||V._focused){var r=i&&e(s,i);s._onMouseMove&&s._onMouseMove(i,r),(o=s._scope._tool)&&o._onHandleEvent(l&&o.responds("mousedrag")?"mousedrag":"mousemove",r,i)&&q.stop(i),s.draw(!0)}}function r(t){var n=V._focused;if(n&&l){var i=e(n,t);curPoint=null,l=!1,n._onMouseUp&&n._onMouseUp(t,i),o&&o._onHandleEvent("mouseup",i,t)&&q.stop(t),n.draw(!0)}}function a(t){l&&q.stop(t)}var o,h,u,l=!1;return q.add(document,{mousemove:s,mouseup:r,touchmove:s,touchend:r,selectstart:a,scroll:n}),q.add(window,{load:n}),{_viewHandlers:{mousedown:i,touchstart:i,selectstart:a},statics:{updateFocus:n}}}),H=V.extend({_class:"CanvasView",initialize:function(t){if(!(t instanceof HTMLCanvasElement)){var e=u.read(arguments,1);e.isZero()&&(e=new u(1024,768)),t=$.getCanvas(e)}this._context=t.getContext("2d"),this._eventCounters={},V.call(this,t)},draw:function(t){if(t&&!this._project._needsRedraw)return!1;var e=t