paper.js/dist/paper-full.min.js

38 lines
213 KiB
JavaScript
Raw Normal View History

2013-06-26 22:42:24 -04:00
/*!
2015-10-25 06:24:42 -04:00
* Paper.js v0.9.25 - The Swiss Army Knife of Vector Graphics Scripting.
2013-06-26 22:42:24 -04:00
* http://paperjs.org/
*
2014-03-13 12:49:37 -04:00
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
2013-06-26 22:42:24 -04:00
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
2015-10-25 06:24:42 -04:00
* Date: Sun Oct 25 11:23:38 2015 +0100
2013-06-26 22:42:24 -04:00
*
***
*
2014-03-13 12:49:37 -04:00
* Straps.js - Class inheritance library with support for bean-style accessors
2013-06-26 22:42:24 -04:00
*
* Copyright (c) 2006 - 2013 Juerg Lehni
2014-03-13 12:49:37 -04:00
* http://scratchdisk.com/
2013-06-26 22:42:24 -04:00
*
* Distributed under the MIT license.
*
***
*
2014-03-13 12:49:37 -04:00
* Acorn.js
2013-06-26 22:42:24 -04:00
* http://marijnhaverbeke.nl/acorn/
*
* Acorn is a tiny, fast JavaScript parser written in JavaScript,
* created by Marijn Haverbeke and released under an MIT license.
*
*/
2015-10-25 06:24:42 -04:00
var paper=new function(t){var e=new function(){function n(t,n,i,r,a){function o(s,o){o=o||(o=u(n,s))&&(o.get?o:o.value),"string"==typeof o&&"#"===o[0]&&(o=t[o.substring(1)]||o);var l,d="function"==typeof o,f=o,g=a||d&&!o.base?o&&o.get?s in t:t[s]:null;a&&g||(d&&g&&(o.base=g),d&&r!==!1&&(l=s.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(h[l[3].toLowerCase()+l[4]]=l[2]),f&&!d&&f.get&&"function"==typeof f.get&&e.isPlainObject(f)||(f={value:f,writable:!0}),(u(t,s)||{configurable:!0}).configurable&&(f.configurable=!0,f.enumerable=i),c(t,s,f))}var h={};if(n){for(var l in n)n.hasOwnProperty(l)&&!s.test(l)&&o(l);for(var l in h){var d=h[l],f=t["set"+d],g=t["get"+d]||f&&t["is"+d];!g||r!==!0&&0!==g.length||o(l,{get:g,set:f})}}return t}function i(t,e,n){return t&&("length"in t&&!t.getLength&&"number"==typeof t.length?a:o).call(t,e,n=n||t),n}function r(t,e,n){for(var i in e)!e.hasOwnProperty(i)||n&&n[i]||(t[i]=e[i]);return t}var s=/^(statics|enumerable|beans|preserve)$/,a=[].forEach||function(t,e){for(var n=0,i=this.length;i>n;n++)t.call(e,this[n],n,this)},o=function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)},h=Object.create||function(t){return{__proto__:t}},u=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},l=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},c=function(t,e,n){return delete t[e],l(t,e,n)};return n(function(){for(var t=0,e=arguments.length;e>t;t++)r(this,arguments[t])},{inject:function(t){if(t){var e=t.statics===!0?t:t.statics,i=t.beans,r=t.preserve;e!==t&&n(this.prototype,t,t.enumerable,i,r),n(this,e,!0,i,r)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var t,e,i=this,r=0,s=arguments.length;s>r&&!(t=arguments[r].initialize);r++);return t=t||function(){i.apply(this,arguments)},e=t.prototype=h(this.prototype),c(e,"constructor",{value:t,writable:!0,configurable:!0}),n(t,this,!0),arguments.length&&this.inject.apply(t,arguments),t.base=i,t}},!0).inject({inject:function(){for(var t=0,e=arguments.length;e>t;t++){var i=arguments[t];i&&n(this,i,i.enumerable,i.beans,i.preserve)}return this},extend:function(){var t=h(this);return t.inject.apply(t,arguments)},each:function(t,e){return i(this,t,e)},set:function(t){return r(this,t)},clone:function(){return new this.constructor(this)},statics:{each:i,create:h,define:c,describe:u,set:r,clone:function(t){return r(new t.constructor,t)},isPlainObject:function(t){var n=null!=t&&t.constructor;return n&&(n===Object||n===e||"Object"===n.name)},pick:function(e,n){return e!==t?e:n}}})};"undefined"!=typeof module&&(module.exports=e),e.inject({toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+e.each(this,function(t,e){if(!/^_/.test(e)){var n=typeof t;this.push(e+": "+("number"===n?s.instance.number(t):"string"===n?"'"+t+"'":t))}},[]).join(", ")+" }"},getClassName:function(){return this._class||""},exportJSON:function(t){return e.exportJSON(this,t)},toJSON:function(){return e.serialize(this)},_set:function(n,i,r){if(n&&(r||e.isPlainObject(n))){for(var s=Object.keys(n._filtering||n),a=0,o=s.length;o>a;a++){var h=s[a];if(!i||!i[h]){var u=n[h];u!==t&&(this[h]=u)}}return!0}},statics:{exports:{enumerable:!0},extend:function et(){var t=et.base.apply(this,arguments),n=t.prototype._class;return n&&!e.exports[n]&&(e.exports[n]=t),t},equals:function(t,n){if(t===n)return!0;if(t&&t.equals)return t.equals(n);if(n&&n.equals)return n.equals(t);if(t&&n&&"object"==typeof t&&"object"==typeof n){if(Array.isArray(t)&&Array.isArray(n)){var i=t.length;if(i!==n.length)return!1;for(;i--;)if(!e.equals(t[i],n[i]))return!1}else{var r=Object.keys(t),i=r.length;if(i!==Object.keys(n).length)return!1;for(;i--;){var s=r[i];if(!n.hasOwnProperty(s)||!e.equals(t[s],n[s]))re
this._b=a*e+h*n,this._c=s*i+o*r,this._d=a*i+h*r,this._tx+=u*e+l*n,this._ty+=u*i+l*r,this._changed(),this},preConcatenate:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=this._tx,a=this._ty,o=t._a,h=t._b,u=t._c,l=t._d,c=t._tx,d=t._ty;return this._a=o*e+h*i,this._b=o*n+h*r,this._c=u*e+l*i,this._d=u*n+l*r,this._tx=o*s+h*a+c,this._ty=u*s+l*a+d,this._changed(),this},chain:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=this._tx,a=this._ty,o=t._a,h=t._b,u=t._c,l=t._d,c=t._tx,d=t._ty;return new g(o*e+u*n,o*i+u*r,h*e+l*n,h*i+l*r,s+c*e+d*n,a+c*i+d*r)},isIdentity:function(){return 1===this._a&&0===this._c&&0===this._b&&1===this._d&&0===this._tx&&0===this._ty},orNullIfIdentity:function(){return this.isIdentity()?null:this},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(t,e,n){return arguments.length<3?this._transformPoint(h.read(arguments)):this._transformCoordinates(t,e,n)},_transformPoint:function(t,e,n){var i=t.x,r=t.y;return e||(e=new h),e.set(i*this._a+r*this._b+this._tx,i*this._c+r*this._d+this._ty,n)},_transformCoordinates:function(t,e,n){for(var i=0,r=0,s=2*n;s>i;){var a=t[i++],o=t[i++];e[r++]=a*this._a+o*this._b+this._tx,e[r++]=a*this._c+o*this._d+this._ty}return e},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,r=n+t.height,s=[e,n,i,n,i,r,e,r];return this._transformCoordinates(s,s,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),r=i.slice(0,2),s=r.slice(),a=2;8>a;a++){var o=i[a],h=1&a;o<r[h]?r[h]=o:o>s[h]&&(s[h]=o)}return e||(e=new d),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(h.read(arguments))},_getDeterminant:function(){var t=this._a*this._d-this._b*this._c;return isFinite(t)&&!a.isZero(t)&&isFinite(this._tx)&&isFinite(this._ty)?t:null},_inverseTransform:function(t,e,n){var i=this._getDeterminant();if(!i)return null;var r=t.x-this._tx,s=t.y-this._ty;return e||(e=new h),e.set((r*this._d-s*this._b)/i,(s*this._a-r*this._c)/i,n)},decompose:function(){var t=this._a,e=this._b,n=this._c,i=this._d;if(a.isZero(t*i-e*n))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*n+e*i;n-=t*s,i-=e*s;var o=Math.sqrt(n*n+i*i);return n/=o,i/=o,s/=o,e*n>t*i&&(t=-t,e=-e,s=-s,r=-r),{scaling:new h(r,o),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s}},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new h(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},inverted:function(){var t=this._getDeterminant();return t&&new g(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 g(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)}},e.each(["a","c","b","d","tx","ty"],function(t){var n=e.capitalize(t),i="_"+t;this["get"+n]=function(){return this[i]},this["set"+n]=function(t){this[i]=t,this._changed()}},{})),_=e.extend({_class:"Line",initialize:function(t,e,n,i,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=n),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new h(this._px,this._py)},getVector:function(){return new h(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return _.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t,e){return _.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0,e)},getDistance:function(t){return Math.abs(_.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},isCollinear:function(t){return h.isCollinear(this._vx,this._vy,t._vx,t._vy)},isOrthogonal:function(t){return h.isOrthogonal(this._vx,this._vy,t._vx,t._vy)},statics:{intersect:function(t,e,n,i,r,s,o,u,l,c){l||(n-=t,i-=e,o-=r,u-=s);var
},isInserted:function ft(){return this._parent?ft.base.call(this):null!=this._index},activate:function(){this._project._activeLayer=this},_insertSibling:function gt(t,e,n){return this._parent?gt.base.call(this,t,e,n):this._project.insertChild(t,e,n)}}),x=m.extend({_class:"Shape",_applyMatrix:!1,_canApplyMatrix:!1,_boundsSelected:!0,_serializeFields:{type:null,size:null,radius:null},initialize:function(t){this._initialize(t)},_equals:function(t){return this._type===t._type&&this._size.equals(t._size)&&e.equals(this._radius,t._radius)},clone:function(t){var e=new x(m.NO_INSERT);return e.setType(this._type),e.setSize(this._size),e.setRadius(this._radius),this._clone(e,t)},getType:function(){return this._type},setType:function(t){this._type=t},getShape:"#getType",setShape:"#setType",getSize:function(){var t=this._size;return new c(t.width,t.height,this,"setSize")},setSize:function(){var t=l.read(arguments);if(this._size){if(!this._size.equals(t)){var e=this._type,n=t.width,i=t.height;if("rectangle"===e){var r=l.min(this._radius,t.divide(2));this._radius.set(r.width,r.height)}else"circle"===e?(n=i=(n+i)/2,this._radius=n/2):"ellipse"===e&&this._radius.set(n/2,i/2);this._size.set(n,i),this._changed(9)}}else this._size=t.clone()},getRadius:function(){var t=this._radius;return"circle"===this._type?t:new c(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._type;if("circle"===e){if(t===this._radius)return;var n=2*t;this._radius=t,this._size.set(n,n)}else if(t=l.read(arguments),this._radius){if(this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var n=l.max(this._size,t.multiply(2));this._size.set(n.width,n.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}else this._radius=t.clone();this._changed(9)},isEmpty:function(){return!1},toPath:function(t){var n=this._clone(new(A[e.capitalize(this._type)])({center:new h,size:this._size,radius:this._radius,insert:!1}),t);return paper.settings.applyMatrix&&n.setApplyMatrix(!0),n},_draw:function(t,e,n){var i=this._style,r=i.hasFill(),s=i.hasStroke(),a=e.dontFinish||e.clip,o=!n;if(r||s||a){var h=this._type,u=this._radius,l="circle"===h;if(e.dontStart||t.beginPath(),o&&l)t.arc(0,0,u,0,2*Math.PI,!0);else{var c=l?u:u.width,d=l?u:u.height,f=this._size,g=f.width,_=f.height;if(o&&"rectangle"===h&&0===c&&0===d)t.rect(-g/2,-_/2,g,_);else{var v=g/2,p=_/2,m=.44771525016920644,y=c*m,w=d*m,x=[-v,-p+d,-v,-p+w,-v+y,-p,-v+c,-p,v-c,-p,v-y,-p,v,-p+w,v,-p+d,v,p-d,v,p-w,v-y,p,v-c,p,-v+c,p,-v+y,p,-v,p-w,-v,p-d];n&&n.transform(x,x,32),t.moveTo(x[0],x[1]),t.bezierCurveTo(x[2],x[3],x[4],x[5],x[6],x[7]),v!==c&&t.lineTo(x[8],x[9]),t.bezierCurveTo(x[10],x[11],x[12],x[13],x[14],x[15]),p!==d&&t.lineTo(x[16],x[17]),t.bezierCurveTo(x[18],x[19],x[20],x[21],x[22],x[23]),v!==c&&t.lineTo(x[24],x[25]),t.bezierCurveTo(x[26],x[27],x[28],x[29],x[30],x[31])}}t.closePath()}a||!r&&!s||(this._setStyles(t),r&&(t.fill(i.getWindingRule()),t.shadowColor="rgba(0,0,0,0)"),s&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e){var n=new d(this._size).setCenter(0,0);return"getBounds"!==t&&this.hasStroke()&&(n=n.expand(this.getStrokeWidth())),e?e._transformBounds(n):n}},new function(){function t(t,e,n){var i=t._radius;if(!i.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new h(1&s?1:-1,s>1?1:-1),o=a.multiply(r),u=o.subtract(a.multiply(i)),l=new d(o,u);if((n?l.expand(n):l).contains(e))return u}}function e(t,e){var n=t.getAngleInRadians(),i=2*e.width,r=2*e.height,s=i*Math.sin(n),a=r*Math.cos(n);return i*r/(2*Math.sqrt(s*s+a*a))}return{_contains:function n(e){if("rectangle"===this._type){var i=t(this,e);return i?e.subtract(i).divide(this._radius).getLength()<=1:n.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTestSelf:function i(n,r){var s=!1;if(this.hasStroke()){var a=this._type,o=this._radius,h=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===a){var u=t(this,n,h);if(u){var l=n.subtract(u);s=2*Math.abs(l.getLength()-e(l,o))<=h}else{var c=new d(this._size).setCenter(0,0),f=c.expand(h),g=c.expand(-h
this._version=e?e._version:0,this._curve=t,this._segment=null,this._segment1=t._segment1,this._segment2=t._segment2},_setSegment:function(t){this._setCurve(t.getCurve()),this._segment=t,this._parameter=t===this._segment1?0:1,this._point=t._point.clone()},getSegment:function(){var t=this.getCurve(),e=this._segment;if(!e){var n=this.getParameter();0===n?e=t._segment1:1===n?e=t._segment2:null!=n&&(e=t.getPartLength(0,n)<t.getPartLength(n,1)?t._segment1:t._segment2),this._segment=e}return e},getCurve:function(){function e(e){var n=e&&e.getCurve();return n&&null!=(r._parameter=n.getParameterOf(r._point))?(r._setCurve(n),r._segment=e,n):t}var n=this._curve,i=n&&n._path,r=this;return i&&i._version!==this._version&&(n=this._parameter=this._curve=this._offset=null),n||e(this._segment)||e(this._segment1)||e(this._segment2.getPrevious())},getPath:function(){var t=this.getCurve();return t&&t._path},getIndex:function(){var t=this.getCurve();return t&&t.getIndex()},getParameter:function(){var t=this.getCurve(),e=this._parameter;return t&&null==e?this._parameter=t.getParameterOf(this._point):e},getPoint:function(){return this._point},getOffset:function(){var t=this._offset;if(null==t){t=0;var e=this.getPath(),n=this.getIndex();if(e&&null!=n)for(var i=e.getCurves(),r=0;n>r;r++)t+=i[r].getLength();this._offset=t+=this.getCurveOffset()}return t},getCurveOffset:function(){var t=this.getCurve(),e=this.getParameter();return null!=e&&t&&t.getPartLength(0,e)},getIntersection:function(){return this._intersection},getDistance:function(){return this._distance},divide:function(){var t=this.getCurve(),e=null;return t&&(e=t.divide(this.getParameter(),!0),e&&this._setSegment(e._segment1)),e},split:function(){var t=this.getCurve();return t?t.split(this.getParameter(),!0):null},equals:function(t,e){var n=this===t,i=2e-7;if(!n&&t instanceof M&&this.getPath()===t.getPath()&&this.getPoint().isClose(t.getPoint(),i)){var r=this.getCurve(),s=t.getCurve(),a=Math.abs,o=a((r.isLast()&&s.isFirst()?-1:r.getIndex())+this.getParameter()-((s.isLast()&&r.isFirst()?-1:s.getIndex())+t.getParameter()));n=(4e-7>o||(o=a(this.getOffset()-t.getOffset()))<i||a(this.getPath().getLength()-o)<i)&&(e||!this._intersection&&!t._intersection||this._intersection&&this._intersection.equals(t._intersection,!0))}return n},toString:function(){var t=[],e=this.getPoint(),n=s.instance;e&&t.push("point: "+e);var i=this.getIndex();null!=i&&t.push("index: "+i);var r=this.getParameter();return null!=r&&t.push("parameter: "+n.number(r)),null!=this._distance&&t.push("distance: "+n.number(this._distance)),"{ "+t.join(", ")+" }"},isTouching:function(){var t=this._intersection;if(t&&this.getTangent().isCollinear(t.getTangent())){var e=this.getCurve(),n=t.getCurve();return!(e.isStraight()&&n.isStraight()&&e.getLine().intersect(n.getLine()))}return!1},isCrossing:function(){function t(t,e,n){return n>e?t>e&&n>t:t>e&&l>=t||t>=-l&&n>t}var e=this._intersection;if(!e)return!1;var n=this.getParameter(),i=e.getParameter(),r=4e-7,s=1-r;if(n>=r&&s>=n||i>=r&&s>=i)return!this.isTouching();var a=this.getCurve(),o=a.getPrevious(),h=e.getCurve(),u=h.getPrevious(),l=Math.PI;if(!o||!u)return!1;var c=o.getTangentAt(s,!0).negate().getAngleInRadians(),d=a.getTangentAt(r,!0).getAngleInRadians(),f=u.getTangentAt(s,!0).negate().getAngleInRadians(),g=h.getTangentAt(r,!0).getAngleInRadians();return t(f,c,d)^t(g,c,d)&&t(f,d,c)^t(g,d,c)},isOverlap:function(){return!!this._overlap}},e.each(I.evaluateMethods,function(t){var e=t+"At";this[t]=function(){var t=this.getParameter(),n=this.getCurve();return null!=t&&n&&n[e](t,!0)}},{preserve:!0}),new function(){function t(t,e,n){function i(n,i){for(var s=n+i;s>=-1&&r>=s;s+=i){var a=t[(s%r+r)%r];if(!e.getPoint().isClose(a.getPoint(),2e-7))break;if(e.equals(a))return a}return null}for(var r=t.length,s=0,a=r-1;a>=s;){var o,h=s+a>>>1,u=t[h];if(n&&(o=e.equals(u)?u:i(h,-1)||i(h,1)))return e._overlap&&(o._overlap=o._intersection._overlap=!0),o;var l=e.getPath(),c=u.getPath(),d=l===c?e.getIndex()+e.getParameter()-(u.getIndex()+u.getParameter()):l._id-c._id;0>d?a=h-1:s=h+1}return t.splice(s,
var a=i[r],o=a._matrix;n[a._id]||a._drawSelected(t,o.isIdentity()?e:e.chain(o))}}},new function(){function t(t,e){var n=t._children;if(e&&0===n.length)throw Error("Use a moveTo() command first");return n[n.length-1]}var n={moveTo:function(){var e=t(this),n=e&&e.isEmpty()?e:new A(m.NO_INSERT);n!==e&&this.addChild(n),n.moveTo.apply(n,arguments)},moveBy:function(){var e=t(this,!0),n=e&&e.getLastSegment(),i=h.read(arguments);this.moveTo(n?i.add(n._point):i)},closePath:function(e){t(this,!0).closePath(e)}};return e.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(e){n[e]=function(){var n=t(this,!0);n[e].apply(n,arguments)}}),n});z.inject(new function(){function e(t,e){var n=t.clone(!1).reduce().transform(null,!0,!0);return e?n.resolveCrossings().reorient():n}function n(t,e,n,i,r){var s=new t(m.NO_INSERT);return s.addChildren(e,!0),r&&(s=s.reduce()),s.insertAbove(i&&n.isSibling(i)&&n.getIndex()<i.getIndex()?i:n),s.setStyle(n._style),s}function i(t,i,s){function a(t){for(var e=0,n=t.length;n>e;e++){var i=t[e];f.push.apply(f,i._segments),g.push.apply(g,i._getMonoCurves())}}if(!t._children&&!t._closed)return r(t,i,s);var h=e(t,!0),u=i&&t!==i&&e(i,!0);u&&/^(subtract|exclude)$/.test(s)^u.isClockwise()!==h.isClockwise()&&u.reverse();var d=M.expand(h.getIntersections(u,function(t){return u&&t.isOverlap()||t.isCrossing()}));o(d);var f=[],g=[];a(h._children||[h]),u&&a(u._children||[u]);for(var _=0,v=d.length;v>_;_++)l(d[_]._segment,h,u,g,s);for(var _=0,v=f.length;v>_;_++){var p=f[_];null==p._winding&&l(p,h,u,g,s)}return n(O,c(f,s),t,i,!0)}function r(i,r,s){function a(e){return h.contains(e.getPointAt(e.getLength()/2))^l?(c.unshift(e),!0):t}if(!r||!r._children&&!r._closed||!/^(subtract|intersect)$/.test(s))return null;for(var o=e(i,!1),h=e(r,!1),u=o.getIntersections(h,function(t){return t.isOverlap()||t.isCrossing()}),l="subtract"===s,c=[],d=u.length-1;d>=0;d--){var f=u[d].split();f&&(a(f)&&f.getFirstSegment().setHandleIn(0,0),o.getLastSegment().setHandleOut(0,0))}return a(o),n(y,c,i,r)}function s(t,e){for(var n=t;n;){if(n===e)return;n=n._prev}for(;t._next&&t._next!==e;)t=t._next;if(!t._next){for(;e._prev;)e=e._prev;t._next=e,e._prev=t}}function o(t){for(var e,n,i=4e-7,r=1-i,a=!1,o=[],h=t.length-1;h>=0;h--){var u=t[h],l=u._curve,c=u._parameter,d=c;l!==e?a=!l.hasHandles():n>0&&(c/=n);var f;i>c?f=l._segment1:c>r?f=l._segment2:(f=l.divide(c,!0,!0)._segment1,a&&o.push(f)),u._setSegment(f);var g=f._intersection,_=u._intersection;if(g){s(g,_);for(var v=g;v;)s(v._intersection,g),v=v._next}else f._intersection=_;e=l,n=d}for(var h=0,p=o.length;p>h;h++)o[h].clearHandles()}function u(t,e,n,i){var r=2e-7,s=4e-7,o=1-s,l=t.x,c=t.y,d=0,f=0,g=[],_=Math.abs;if(n){for(var v=-(1/0),p=1/0,m=c-r,y=c+r,w=0,x=e.length;x>w;w++){var b=e[w].values;if(I.solveCubic(b,0,l,g,0,1)>0)for(var C=g.length-1;C>=0;C--){var S=I.getPoint(b,g[C]).y;m>S&&S>v?v=S:S>y&&p>S&&(p=S)}}v=(v+c)/2,p=(p+c)/2,v>-(1/0)&&(d=u(new h(l,v),e,!1,i)),1/0>p&&(f=u(new h(l,p),e,!1,i))}else for(var P,k,M=l-r,z=l+r,A=!1,w=0,x=e.length;x>w;w++){var O=e[w],b=O.values,T=O.winding;if(T&&(1===T&&c>=b[1]&&c<=b[7]||c>=b[7]&&c<=b[1])&&1===I.solveCubic(b,1,c,g,0,1)){var E=g[0];if(!(E>o&&A&&O.next!==e[w+1]||s>E&&k>o&&O.previous===P)){var L=I.getPoint(b,E).x,N=I.getTangent(b,E).y,j=!1;a.isZero(N)&&!I.isStraight(b)||s>E&&N*I.getTangent(O.previous.values,1).y<0||E>o&&N*I.getTangent(O.next.values,0).y<0?i&&L>=M&&z>=L&&(++d,++f,j=!0):M>=L?(d+=T,j=!0):L>=z&&(f+=T,j=!0),O.previous!==e[w-1]&&(A=s>E&&j)}P=O,k=E}}return Math.max(_(d),_(f))}function l(t,e,n,i,r){var s=2e-7,a=[],o=t,h=0,l=0;do{var c=t.getCurve(),d=c.getLength();a.push({segment:t,curve:c,length:d}),h+=d,t=t.getNext()}while(t&&!t._intersection&&t!==o);for(var f=0;3>f;f++)for(var d=h*(f+1)/4,g=0,_=a.length;_>g;g++){var v=a[g],p=v.length;if(p>=d){(s>d||s>p-d)&&(d=p/2);var c=v.curve,m=c._path,y=m._parent,w=c.getPointAt(d),x=c.isHorizontal();y instanceof O&&(m=y),l+="subtract"===r&&n&&(m===e&&n._getWinding(w,x)||m===n&&!e._getWinding(w,x))?0:u(w,i,x);break}d-=p}for(var b=
this._transform((new g).translate(h.read(arguments).negate()))},play:function(){this._animate=!0,this._requested||this._requestFrame()},pause:function(){this._animate=!1},draw:function(){this.update()},projectToView:function(){return this._matrix._transformPoint(h.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(h.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t,e){return"string"==typeof e&&(e=document.getElementById(e)),new H(t,e)}}},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=a=n;break}}}function i(t,e,n){t._handleEvent("mousemove",e,n);var i=t._scope.tool;return i&&i._handleEvent(l&&i.responds("mousedrag")?"mousedrag":"mousemove",e,n),t.update(),i}var r,s,a,o,h,u,l=!1,c=window.navigator;c.pointerEnabled||c.msPointerEnabled?(o="pointerdown MSPointerDown",h="pointermove MSPointerMove",u="pointerup pointercancel MSPointerUp MSPointerCancel"):(o="touchstart",h="touchmove",u="touchend touchcancel","ontouchstart"in window&&c.userAgent.match(/mobile|tablet|ip(ad|hone|od)|android|silk/i)||(o+=" mousedown",h+=" mousemove",u+=" mouseup"));var d={"selectstart dragstart":function(t){l&&t.preventDefault()}},f={mouseout:function(t){var n=V._focused,r=q.getRelatedTarget(t);!n||r&&"HTML"!==r.nodeName||i(n,e(n,t),t)},scroll:n};d[o]=function(n){var i=V._focused=t(n),s=e(i,n);l=!0,i._handleEvent("mousedown",s,n),(r=i._scope.tool)&&r._handleEvent("mousedown",s,n),i.update()},f[h]=function(o){var h=V._focused;if(!l){var u=t(o);u?(h!==u&&i(h,e(h,o),o),s=h,h=V._focused=a=u):a&&a===h&&(h=V._focused=s,n())}if(h){var c=e(h,o);(l||h.getBounds().contains(c))&&(r=i(h,c,o))}},f[u]=function(t){var n=V._focused;if(n&&l){var i=e(n,t);l=!1,n._handleEvent("mouseup",i,t),r&&r._handleEvent("mouseup",i,t),n.update()}},q.add(document,f),q.add(window,{load:n});var g={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}};return{_viewEvents:d,_handleEvent:function(){},_installEvent:function(t){var e=this._eventCounters;if(e)for(var n in g)e[n]=(e[n]||0)+(g[n][t]||0)},_uninstallEvent:function(t){var e=this._eventCounters;if(e)for(var n in g)e[n]-=g[n][t]||0},statics:{updateFocus:n}}}),H=V.extend({_class:"CanvasView",initialize:function(t,e){if(!(e instanceof HTMLCanvasElement)){var n=l.read(arguments,1);if(n.isZero())throw Error("Cannot create CanvasView with the provided argument: "+[].slice.call(arguments,1));e=Y.getCanvas(n)}if(this._context=e.getContext("2d"),this._eventCounters={},this._pixelRatio=1,!/^off|false$/.test(i.getAttribute(e,"hidpi"))){var r=window.devicePixelRatio||1,s=F.getPrefixed(this._context,"backingStorePixelRatio")||1;this._pixelRatio=r/s}V.call(this,t,e)},_setViewSize:function(t){var e=this._element,n=this._pixelRatio,r=t.width,s=t.height;if(e.width=r*n,e.height=s*n,1!==n){if(!i.hasAttribute(e,"resize")){var a=e.style;a.width=r+"px",a.height=s+"px"}this._context.scale(n,n)}},getPixelSize:function(t){var e,n=paper.browser;if(n&&n.firefox){var i=this._element.parentNode,r=document.createElement("div");r.style.fontSize=t,i.appendChild(r),e=parseFloat(F.getStyles(r).fontSize),i.removeChild(r)}else{var s=this._context,a=s.font;s.font=t+" serif",e=parseFloat(s.font),s.font=a}return e},getTextWidth:function(t,e){var n=this._context,i=n.font,r=0;n.font=t;for(var s=0,a=e.length;a>s;s++)r=Math.max(r,n.measureText(e[s]).width);return n.font=i,r},update:function(t){var e=this._project;if(!e||!t&&!e._needsUpdate)return!1;var n=this._context,i=this._viewSize;return n.clearRect(0,0,i.width+1,i.height+1),e.draw(n,this._matrix,this._pixelRatio),e._needsUpdate=!1,!0}},new function(){function e(e,n,i,r,s,a){function o(e){return e.responds(n)&&(h||(h=new G(n,i,r,s,a?r.subtract(a):null)),e.emit(n,h)&&h.isStoppe
e(a)}n+="}"}else e(t);return Function("str",n)}function r(){this.line=Pt,this.column=pt-kt}function s(){Pt=1,pt=kt=0,St=!0,u()}function a(t,e){yt=pt,ct.locations&&(xt=new r),bt=t,u(),Ct=e,St=t.beforeExpr}function o(){var t=ct.onComment&&ct.locations&&new r,e=pt,i=dt.indexOf("*/",pt+=2);if(-1===i&&n(pt-2,"Unterminated comment"),pt=i+2,ct.locations){Je.lastIndex=e;for(var s;(s=Je.exec(dt))&&s.index<pt;)++Pt,kt=s.index+s[0].length}ct.onComment&&ct.onComment(!0,dt.slice(e+2,i),e,pt,t,ct.locations&&new r)}function h(){for(var t=pt,e=ct.onComment&&ct.locations&&new r,n=dt.charCodeAt(pt+=2);ft>pt&&10!==n&&13!==n&&8232!==n&&8233!==n;)++pt,n=dt.charCodeAt(pt);ct.onComment&&ct.onComment(!1,dt.slice(t+2,pt),t,pt,e,ct.locations&&new r)}function u(){for(;ft>pt;){var t=dt.charCodeAt(pt);if(32===t)++pt;else if(13===t){++pt;var e=dt.charCodeAt(pt);10===e&&++pt,ct.locations&&(++Pt,kt=pt)}else if(10===t||8232===t||8233===t)++pt,ct.locations&&(++Pt,kt=pt);else if(t>8&&14>t)++pt;else if(47===t){var e=dt.charCodeAt(pt+1);if(42===e)o();else{if(47!==e)break;h()}}else if(160===t)++pt;else{if(!(t>=5760&&Ze.test(String.fromCharCode(t))))break;++pt}}}function l(){var t=dt.charCodeAt(pt+1);return t>=48&&57>=t?S(!0):(++pt,a(we))}function c(){var t=dt.charCodeAt(pt+1);return St?(++pt,x()):61===t?w(Se,2):w(be,1)}function d(){var t=dt.charCodeAt(pt+1);return 61===t?w(Se,2):w(je,1)}function f(t){var e=dt.charCodeAt(pt+1);return e===t?w(124===t?Me:ze,2):61===e?w(Se,2):w(124===t?Ae:Te,1)}function g(){var t=dt.charCodeAt(pt+1);return 61===t?w(Se,2):w(Oe,1)}function _(t){var e=dt.charCodeAt(pt+1);return e===t?45==e&&62==dt.charCodeAt(pt+2)&&Xe.test(dt.slice(Mt,pt))?(pt+=3,h(),u(),y()):w(ke,2):61===e?w(Se,2):w(Pe,1)}function v(t){var e=dt.charCodeAt(pt+1),n=1;return e===t?(n=62===t&&62===dt.charCodeAt(pt+2)?3:2,61===dt.charCodeAt(pt+n)?w(Se,n+1):w(Ne,n)):33==e&&60==t&&45==dt.charCodeAt(pt+2)&&45==dt.charCodeAt(pt+3)?(pt+=4,h(),u(),y()):(61===e&&(n=61===dt.charCodeAt(pt+2)?3:2),w(Le,n))}function p(t){var e=dt.charCodeAt(pt+1);return 61===e?w(Ee,61===dt.charCodeAt(pt+2)?3:2):w(61===t?Ce:Ie,1)}function m(t){switch(t){case 46:return l();case 40:return++pt,a(_e);case 41:return++pt,a(ve);case 59:return++pt,a(me);case 44:return++pt,a(pe);case 91:return++pt,a(ce);case 93:return++pt,a(de);case 123:return++pt,a(fe);case 125:return++pt,a(ge);case 58:return++pt,a(ye);case 63:return++pt,a(xe);case 48:var e=dt.charCodeAt(pt+1);if(120===e||88===e)return C();case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return S(!1);case 34:case 39:return P(t);case 47:return c(t);case 37:case 42:return d();case 124:case 38:return f(t);case 94:return g();case 43:case 45:return _(t);case 60:case 62:return v(t);case 61:case 33:return p(t);case 126:return w(Ie,1)}return!1}function y(t){if(t?pt=mt+1:mt=pt,ct.locations&&(wt=new r),t)return x();if(pt>=ft)return a(Rt);var e=dt.charCodeAt(pt);if(Ye(e)||92===e)return M();var i=m(e);if(i===!1){var s=String.fromCharCode(e);if("\\"===s||Ge.test(s))return M();n(pt,"Unexpected character '"+s+"'")}return i}function w(t,e){var n=dt.slice(pt,pt+e);pt+=e,a(t,n)}function x(){for(var t,e,i="",r=pt;;){pt>=ft&&n(r,"Unterminated regular expression");var s=dt.charAt(pt);if(Xe.test(s)&&n(r,"Unterminated regular expression"),t)t=!1;else{if("["===s)e=!0;else if("]"===s&&e)e=!1;else if("/"===s&&!e)break;t="\\"===s}++pt}var i=dt.slice(r,pt);++pt;var o=I();return o&&!/^[gmsiy]*$/.test(o)&&n(r,"Invalid regexp flag"),a(Nt,RegExp(i,o))}function b(t,e){for(var n=pt,i=0,r=0,s=null==e?1/0:e;s>r;++r){var a,o=dt.charCodeAt(pt);if(a=o>=97?o-97+10:o>=65?o-65+10:o>=48&&57>=o?o-48:1/0,a>=t)break;++pt,i=i*t+a}return pt===n||null!=e&&pt-n!==e?null:i}function C(){pt+=2;var t=b(16);return null==t&&n(mt+2,"Expected hexadecimal number"),Ye(dt.charCodeAt(pt))&&n(pt,"Identifier directly after number"),a(Lt,t)}function S(t){var e=pt,i=!1,r=48===dt.charCodeAt(pt);t||null!==b(10)||n(e,"Invalid number"),46===dt.charCodeAt(pt)&&(++pt,b(10),i=!0);var s=dt.charCodeAt(pt);(69===s||101===s)&&(s=dt.charCodeAt(++pt),(43===s||45===s)&&++pt,null===b(10)&&n(e,"Invalid number"),