mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
36 lines
No EOL
154 KiB
JavaScript
36 lines
No EOL
154 KiB
JavaScript
/*!
|
|
* Paper.js v0.9.6 - The Swiss Army Knife of Vector Graphics Scripting.
|
|
* 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.
|
|
*
|
|
* Date: Thu Jun 27 03:21:56 2013 -0700
|
|
*
|
|
***
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
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:{}}})};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&&n.equals)return n.equals(e);if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(var s=0,r=e.length;r>s;s++)if(!t.equals(e[s],n[s]))return!1;return!0}if(e&&"object"==typeof e&&n&&"object"==typeof n){if(!i(e,n)||!i(n,e))return!1;for(var s in e)if(e.hasOwnProperty(s)&&!t.equals(e[s],n[s]))return!1;return!0}return!1},read:function(e,n,i,s,r){if(this===t){var a=this.peek(e,n);return e._index++,e._read=1,a}var o=this.prototype,h=o._readIndex,u=n||h&&e._index||0;i||(i=e.length-u);var l=e[u];return l instanceof this||s&&null==l&&1>=i?(h&&(e._index=u+1),l&&r?l.clone():l):(l=t.create(this),h&&(l._read=!0),l=l.initialize.apply(l,u>0||i<e.length?Array.prototype.slice.call(e,u,u+i):e)||l,h&&(e._index=u+l._read,e._read=l._read,delete l._read),l)},peek:function(t,e){return t[t._index=e||t._index||0]},readAll:function(t,e,n,i){for(var s,r=[],a=e||0,o=t.length;o>a;a++)r.push(Array.isArray(s=t[a])?this.read(s,0,0,n,i):this.read(t,a,1,n,i));return r},readNamed:function(t,e,n,i,s,r){var a=this.getNamed(t,e);return this.read(null!=a?[a]:t,n,i,s,r)},getNamed:function(e,n){var i=e[0];return void 0===e._hasObject&&(e._hasObject=1===e.length&&t.isPlainObject(i)),e._hasObject?n?i[n]:i:void 0},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t){return this.isPlainObject(t)||Array.isArray(t)},serialize:function(e,n,i,s){n=n||{};var a,o=!s;if(o&&(n.formatter=new r(n.precision),s={length:0,definitions:{},references:{},add:function(t,e){var n="#"+t._id,i=this.references[n];if(!i){this.length++;var s=e.call(t),r=t._class;r&&s[0]!==r&&s.unshift(r),this.definitions[n]=s,i=this.references[n]=[n]}return i}}),e&&e._serialize){a=e._serialize(n,s);var h=e._class;!h||i||a._compact||a[0]===h||a.unshift(h)}else if(Array.isArray(e)){a=[];for(var u=0,l=e.length;l>u;u++)a[u]=t.serialize(e[u],n,i,s);i&&(a._compact=!0)}else if(t.isPlainObject(e)){a={};for(var u in e)e.hasOwnProperty(u)&&(a[u]=t.serialize(e[u],n,i,s))}else a="number"==typeof e?n.formatter.number(e,n.precision):e;return o&&s.length>0?[["dictionary",s.definitions],a]:a},deserialize:function(e,n){var i=e;if(n=n||{},Array.isArray(e)){var s=e[0],r="dictionary"===s;if(!r){if(n.dictionary&&1==e.length&&/^#/.test(s))return n.dictionary[s];s=t.exports[s]}i=[];for(var a=s?1:0,o=e.length;o>a;a++)i.push(t.deserialize(e[a],n));if(r)n.dictionary=i[0];else if(s){var h=i;i=t.create(s),s.apply(i,h)}}else if(t.isPlainObject(e)){i={};for(var u in e)i[u]=t.deserialize(e[u],n)}return i},exportJSON:function(e,n){return JSON.stringify(t.serialize(e,n))},importJSON:function(e){return t.deserialize("string"==typeof e?JSON.parse(e):e)},splice:function(t,e,n,i){var s=e&&e.length,r=void 0===n;n=r?t.length:n,n>t.length&&(n=t.length);for(var a=0;s>a;a++)e[a]._index=n+a;if(r)return t.push.apply(t,e),[];var o=[n,i];e&&o.push.apply(o,e);for(var h=t.splice.apply(t,o),a=0,u=h.length;u>a;a++)delete h[a]._index;for(var a=n+s,u=t.length;u>a;a++)t[a]._index=a;return h},merge:function(){return t.each(arguments,function(e){t.each(e,function(t,e){this[e]=t},this)},new t,!0)},capitalize:function(t){return t.replace(/\b[a-z]/g,function(t){return t.toUpperCase()})},camelize:function(t){return t.replace(/-(.)/g,function(t,e){return e.toUpperCase()})},hyphenate:function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}}});var e={attach:function(e,n){if("string"!=typeof e)return t.each(e,function(t,e){this.attach(e,t)},this),void 0;var i=this._eventTypes[e];if(i){var s=this._handlers=this._handlers||{};s=s[e]=s[e]||[],-1==s.indexOf(n)&&(s.push(n),i.install&&1==s.length&&i.install.call(this,e))}},detach:function(e,n){if("string"!=typeof e)return t.each(e,function(t,e){this.detach(e,t)},this),void 0;var i,s=this._eventTypes[e],r=this._handlers&&this._handlers[e];s&&r&&(!n||-1!=(i=r.indexOf(n))&&1==r.length?(s.uninstall&&s.uninstall.call(this,e),delete this._handlers[e]):-1!=i&&r.splice(i,1))},once:function(t,e){this.attach(t,function(){e.apply(this,arguments),this.detach(t,e)})},fire:function(e,n){var i=this._handlers&&this._handlers[e];if(!i)return!1;var s=[].slice.call(arguments,1);return t.each(i,function(t){t.apply(this,s)===!1&&n&&n.stop&&n.stop()},this),!0},responds:function(t){return!(!this._handlers||!this._handlers[t])},on:"#attach",off:"#detach",trigger:"#fire",statics:{inject:function ne(){for(var e=0,n=arguments.length;n>e;e++){var i=arguments[e],s=i._events;if(s){var r={};t.each(s,function(e,n){var s="string"==typeof e,a=s?e:n,o=t.capitalize(a),h=a.substring(2).toLowerCase();r[h]=s?{}:e,a="_"+a,i["get"+o]=function(){return this[a]},i["set"+o]=function(t){t?this.attach(h,t):this[a]&&this.detach(h,this[a]),this[a]=t}}),i._eventTypes=r}ne.base.call(this,i)}return this}}},n=t.extend({_class:"PaperScope",initialize:function ie(t){if(paper=this,this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=t&&(t.getAttribute("id")||t.src)||"paperscope-"+ie._id++,t&&t.setAttribute("id",this._id),ie._scopes[this._id]=this,!this.support){var e=$.getContext(1,1);ie.prototype.support={nativeDash:"setLineDash"in e||"mozDash"in e,nativeBlendModes:K.nativeModes},$.release(e)}},version:"0.9.6",getView:function(){return this.project&&this.project.view},getTool:function(){return this._tool||(this._tool=new U),this._tool},evaluate:function(t){var e=paper.PaperScript.evaluate(t,this);return V.updateFocus(),e},install:function(e){var n=this;t.each(["project","view","tool"],function(i){t.define(e,i,{configurable:!0,get:function(){return n[i]}})});for(var i in this)/^(version|_id)/.test(i)||i in e||(e[i]=this[i])},setup:function(t){return paper=this,this.project=new v(t),this},clear:function(){for(var t=this.projects.length-1;t>=0;t--)this.projects[t].remove();for(var t=this.tools.length-1;t>=0;t--)this.tools[t].remove();for(var t=this.palettes.length-1;t>=0;t--)this.palettes[t].remove()},remove:function(){this.clear(),delete n._scopes[this._id]},statics:new function(){function t(t){return t+="Attribute",function(e,n){return e[t](n)||e[t]("data-paper-"+n)}}return{_scopes:{},_id:0,get:function(t){return"object"==typeof t&&(t=t.getAttribute("id")),this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),s=t.extend(e,{initialize:function(t){this._scope=paper,this._index=this._scope[this._list].push(this)-1,(t||!this._scope[this._reference])&&this.activate()},activate:function(){if(!this._scope)return!1;var t=this._scope[this._reference];return t&&t!=this&&t.fire("deactivate"),this._scope[this._reference]=this,this.fire("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(t.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),r=t.extend({initialize:function(t){this.precision=t||5,this.multiplier=Math.pow(10,this.precision)},number:function(t){return Math.round(t*this.multiplier)/this.multiplier},point:function(t,e){return this.number(t.x)+(e||",")+this.number(t.y)},size:function(t,e){return this.number(t.width)+(e||",")+this.number(t.height)},rectangle:function(t,e){return this.point(t,e)+(e||",")+this.size(t,e)}});r.instance=new r(5);var a=new function(){var t=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],e=[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]],n=Math.abs,i=Math.sqrt,s=Math.pow,r=Math.cos,o=Math.PI;return{TOLERANCE:1e-5,EPSILON:1e-11,KAPPA:4*(i(2)-1)/3,isZero:function(t){return n(t)<=this.EPSILON},integrate:function(n,i,s,r){for(var a=t[r-2],o=e[r-2],h=.5*(s-i),u=h+i,l=0,c=r+1>>1,d=1&r?o[l++]*n(u):0;c>l;){var _=h*a[l];d+=o[l++]*(n(u+_)+n(u-_))}return h*d},findRoot:function(t,e,i,s,r,a,o){for(var h=0;a>h;h++){var u=t(i),l=u/e(i);if(n(l)<o)return i;var c=i-l;u>0?(r=i,i=s>=c?.5*(s+r):c):(s=i,i=c>=r?.5*(s+r):c)}},solveQuadratic:function(t,e,s,r){var a=this.EPSILON;if(n(t)<a)return n(e)>=a?(r[0]=-s/e,1):n(s)<a?-1:0;var o=e*e-4*t*s;if(0>o)return 0;o=i(o),t*=2;var h=0;return r[h++]=(-e-o)/t,o>0&&(r[h++]=(-e+o)/t),h},solveCubic:function(t,e,h,u,l){var c=this.EPSILON;if(n(t)<c)return a.solveQuadratic(e,h,u,l);e/=t,h/=t,u/=t;var d=e*e,_=(d-3*h)/9,f=(2*d*e-9*e*h+27*u)/54,g=_*_*_,v=f*f-g;if(e/=3,n(v)<c){if(n(f)<c)return l[0]=-e,1;var m=i(_),p=f>0?1:-1;return l[0]=2*-p*m-e,l[1]=p*m-e,2}if(0>v){var m=i(_),y=Math.acos(f/(m*m*m))/3,w=-2*m,x=2*o/3;return l[0]=w*r(y)-e,l[1]=w*r(y+x)-e,l[2]=w*r(y-x)-e,3}var b=(f>0?-1:1)*s(n(f)+i(v),1/3);return l[0]=b+_/b-e,1}}},o=t.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var n=typeof t;if("number"===n){var i="number"==typeof e;this.x=t,this.y=i?e:t,this._read&&(this._read=i?2:1)}else"undefined"===n||null===t?(this.x=this.y=0,this._read&&(this._read=null===t?1:0)):(Array.isArray(t)?(this.x=t[0],this.y=t.length>1?t[1]:t[0]):null!=t.x?(this.x=t.x,this.y=t.y):null!=t.width?(this.x=t.width,this.y=t.height):null!=t.angle?(this.x=t.length,this.y=0,this.setAngle(t.angle)):(this.x=this.y=0,this._read&&(this._read=0)),this._read&&(this._read=1))},set:function(t,e){return this.x=t,this.y=e,this},equals:function(t){return t===this||t&&(this.x===t.x&&this.y===t.y||Array.isArray(t)&&this.x===t[0]&&this.y===t[1])||!1},clone:function(){return new o(this.x,this.y)},toString:function(){var t=r.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y)]},add:function(t){return t=o.read(arguments),new o(this.x+t.x,this.y+t.y)},subtract:function(t){return t=o.read(arguments),new o(this.x-t.x,this.y-t.y)},multiply:function(t){return t=o.read(arguments),new o(this.x*t.x,this.y*t.y)},divide:function(t){return t=o.read(arguments),new o(this.x/t.x,this.y/t.y)},modulo:function(t){return t=o.read(arguments),new o(this.x%t.x,this.y%t.y)},negate:function(){return new o(-this.x,-this.y)},transform:function(t){return t?t._transformPoint(this):this},getDistance:function(t,e){t=o.read(arguments);var n=t.x-this.x,i=t.y-this.y,s=n*n+i*i;return e?s:Math.sqrt(s)},getLength:function(){var t=this.x*this.x+this.y*this.y;return arguments.length&&arguments[0]?t:Math.sqrt(t)},setLength:function(t){if(this.isZero()){var e=this._angle||0;this.set(Math.cos(e)*t,Math.sin(e)*t)}else{var n=t/this.getLength();a.isZero(n)&&this.getAngle(),this.set(this.x*n,this.y*n)}return this},normalize:function(t){void 0===t&&(t=1);var e=this.getLength(),n=0!==e?t/e:0,i=new o(this.x*n,this.y*n);return i._angle=this._angle,i},getAngle:function(){return 180*this.getAngleInRadians(arguments[0])/Math.PI},setAngle:function(t){if(t=this._angle=t*Math.PI/180,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}return this},getAngleInRadians:function(){if(void 0===arguments[0])return null==this._angle&&(this._angle=Math.atan2(this.y,this.x)),this._angle;var t=o.read(arguments),e=this.getLength()*t.getLength();return a.isZero(e)?0/0:Math.acos(this.dot(t)/e)},getAngleInDegrees:function(){return this.getAngle(arguments[0])},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3},getDirectedAngle:function(t){return t=o.read(arguments),180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},rotate:function(t,e){if(0===t)return this.clone();t=t*Math.PI/180;var n=e?this.subtract(e):this,i=Math.sin(t),s=Math.cos(t);return n=new o(n.x*s-n.y*i,n.y*s+n.x*i),e?n.add(e):n},isInside:function(t){return t.contains(this)},isClose:function(t,e){return this.getDistance(t)<e},isColinear:function(t){return this.cross(t)<1e-5},isOrthogonal:function(t){return this.dot(t)<1e-5},isZero:function(){return a.isZero(this.x)&&a.isZero(this.y)},isNaN:function(){return isNaN(this.x)||isNaN(this.y)},dot:function(t){return t=o.read(arguments),this.x*t.x+this.y*t.y},cross:function(t){return t=o.read(arguments),this.x*t.y-this.y*t.x},project:function(t){if(t=o.read(arguments),t.isZero())return new o(0,0);var e=this.dot(t)/t.dot(t);return new o(t.x*e,t.y*e)},statics:{min:function(){var t=o.read(arguments);return point2=o.read(arguments),new o(Math.min(t.x,point2.x),Math.min(t.y,point2.y))},max:function(){var t=o.read(arguments);return point2=o.read(arguments),new o(Math.max(t.x,point2.x),Math.max(t.y,point2.y))},random:function(){return new o(Math.random(),Math.random())}}},new function(){return t.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new o(e(this.x),e(this.y))}},{})}),h=o.extend({initialize:function(t,e,n,i){this._x=t,this._y=e,this._owner=n,this._setter=i},set:function(t,e,n){return this._x=t,this._y=e,n||this._owner[this._setter](this),this},getX:function(){return this._x},setX:function(t){this._x=t,this._owner[this._setter](this)},getY:function(){return this._y},setY:function(t){this._y=t,this._owner[this._setter](this)}}),u=t.extend({_class:"Size",_readIndex:!0,initialize:function(t,e){var n=typeof t;if("number"===n){var i="number"==typeof e;this.width=t,this.height=i?e:t,this._read&&(this._read=i?2:1)}else"undefined"===n||null===t?(this.width=this.height=0,this._read&&(this._read=null===t?1:0)):(Array.isArray(t)?(this.width=t[0],this.height=t.length>1?t[1]:t[0]):null!=t.width?(this.width=t.width,this.height=t.height):null!=t.x?(this.width=t.x,this.height=t.y):(this.width=this.height=0,this._read&&(this._read=0)),this._read&&(this._read=1))},set:function(t,e){return this.width=t,this.height=e,this},equals:function(t){return t===this||t&&(this.width===t.width&&this.height===t.height||Array.isArray(t)&&this.width===t[0]&&this.height===t[1])||!1},clone:function(){return new u(this.width,this.height)},toString:function(){var t=r.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.width),e.number(this.height)]},add:function(t){return t=u.read(arguments),new u(this.width+t.width,this.height+t.height)},subtract:function(t){return t=u.read(arguments),new u(this.width-t.width,this.height-t.height)},multiply:function(t){return t=u.read(arguments),new u(this.width*t.width,this.height*t.height)},divide:function(t){return t=u.read(arguments),new u(this.width/t.width,this.height/t.height)},modulo:function(t){return t=u.read(arguments),new u(this.width%t.width,this.height%t.height)},negate:function(){return new u(-this.width,-this.height)},isZero:function(){return a.isZero(this.width)&&a.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new u(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new u(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new u(Math.random(),Math.random())}}},new function(){return t.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new u(e(this.width),e(this.height))}},{})}),c=u.extend({initialize:function(t,e,n,i){this._width=t,this._height=e,this._owner=n,this._setter=i},set:function(t,e,n){return this._width=t,this._height=e,n||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(t){this._width=t,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(t){this._height=t,this._owner[this._setter](this)}}),d=t.extend({_class:"Rectangle",_readIndex:!0,initialize:function(e,n,i,s){var r=typeof e,a=0;if("number"===r?(this.x=e,this.y=n,this.width=i,this.height=s,a=4):"undefined"===r||null===e?(this.x=this.y=this.width=this.height=0,a=null===e?1:0):1===arguments.length&&(Array.isArray(e)?(this.x=e[0],this.y=e[1],this.width=e[2],this.height=e[3],a=1):void 0!==e.x||void 0!==e.width?(this.x=e.x||0,this.y=e.y||0,this.width=e.width||0,this.height=e.height||0,a=1):void 0===e.from&&void 0===e.to&&(this.x=this.y=this.width=this.height=0,this._set(e),a=1)),!a){var h=o.readNamed(arguments,"from"),l=t.peek(arguments);if(this.x=h.x,this.y=h.y,l&&void 0!==l.x||t.hasNamed(arguments,"to")){var c=o.readNamed(arguments,"to");this.width=c.x-h.x,this.height=c.y-h.y,this.width<0&&(this.x=c.x,this.width=-this.width),this.height<0&&(this.y=c.y,this.height=-this.height)}else{var d=u.read(arguments);this.width=d.width,this.height=d.height}a=arguments._index}this._read&&(this._read=a)},set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new d(this.x,this.y,this.width,this.height)},equals:function(e){return t.isPlainValue(e)&&(e=d.read(arguments)),e===this||e&&this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height||!1},toString:function(){var t=r.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+", width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){var e=t.formatter;return[e.number(this.x),e.number(this.y),e.number(this.width),e.number(this.height)]},getPoint:function(){return new(arguments[0]?o:h)(this.x,this.y,this,"setPoint")},setPoint:function(t){t=o.read(arguments),this.x=t.x,this.y=t.y},getSize:function(){return new(arguments[0]?u:c)(this.width,this.height,this,"setSize")},setSize:function(t){t=u.read(arguments),this._fixX&&(this.x+=(this.width-t.width)*this._fixX),this._fixY&&(this.y+=(this.height-t.height)*this._fixY),this.width=t.width,this.height=t.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(t){this._fixW||(this.width-=t-this.x),this.x=t,this._fixX=0},getTop:function(){return this.y},setTop:function(t){this._fixH||(this.height-=t-this.y),this.y=t,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(t){void 0!==this._fixX&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=t-this.width:this.width=t-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(t){void 0!==this._fixY&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=t-this.height:this.height=t-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(t){this.x=t-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(t){this.y=t-.5*this.height,this._fixY=.5},getCenter:function(){return new(arguments[0]?o:h)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(t){return t=o.read(arguments),this.setCenterX(t.x),this.setCenterY(t.y),this},isEmpty:function(){return 0==this.width||0==this.height},contains:function(t){return t&&void 0!==t.width||4==(Array.isArray(t)?t:arguments).length?this._containsRectangle(d.read(arguments)):this._containsPoint(o.read(arguments))},_containsPoint:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e<=this.x+this.width&&n<=this.y+this.height},_containsRectangle:function(t){var e=t.x,n=t.y;return e>=this.x&&n>=this.y&&e+t.width<=this.x+this.width&&n+t.height<=this.y+this.height},intersects:function(t){return t=d.read(arguments),t.x+t.width>this.x&&t.y+t.height>this.y&&t.x<this.x+this.width&&t.y<this.y+this.height},touches:function(t){return t=d.read(arguments),t.x+t.width>=this.x&&t.y+t.height>=this.y&&t.x<=this.x+this.width&&t.y<=this.y+this.height},intersect:function(t){t=d.read(arguments);var e=Math.max(this.x,t.x),n=Math.max(this.y,t.y),i=Math.min(this.x+this.width,t.x+t.width),s=Math.min(this.y+this.height,t.y+t.height);return new d(e,n,i-e,s-n)},unite:function(t){t=d.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x+t.width),s=Math.max(this.y+this.height,t.y+t.height);return new d(e,n,i-e,s-n)},include:function(t){t=o.read(arguments);var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x),s=Math.max(this.y+this.height,t.y);return new d(e,n,i-e,s-n)},expand:function(t,e){return void 0===e&&(e=t),new d(this.x-t/2,this.y-e/2,this.width+t,this.height+e)},scale:function(t,e){return this.expand(this.width*t-this.width,this.height*(void 0===e?t:e)-this.height)}},new function(){return t.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(t,e){var n=t.join(""),i=/^[RL]/.test(n);e>=4&&(t[1]+=i?"Y":"X");var s=t[i?0:1],r=t[i?1:0],a="get"+s,u="get"+r,l="set"+s,c="set"+r,d="get"+n,_="set"+n;this[d]=function(){return new(arguments[0]?o:h)(this[a](),this[u](),this,_)},this[_]=function(t){t=o.read(arguments),this[l](t.x),this[c](t.y)}},{})}),_=d.extend({initialize:function(t,e,n,i,s,r){this.set(t,e,n,i,!0),this._owner=s,this._setter=r},set:function(t,e,n,i,s){return this._x=t,this._y=e,this._width=n,this._height=i,s||this._owner[this._setter](this),this}},new function(){var e=d.prototype;return t.each(["x","y","width","height"],function(e){var n=t.capitalize(e),i="_"+e;this["get"+n]=function(){return this[i]},this["set"+n]=function(t){this[i]=t,this._dontNotify||this._owner[this._setter](this)}},t.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(t){var n="set"+t;this[n]=function(){this._dontNotify=!0,e[n].apply(this,arguments),delete this._dontNotify,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(t){var e=this._owner;e.setSelected&&(e._boundsSelected=t,e.setSelected(t||e._selectedSegmentState>0))}}))}),f=t.extend({_class:"Matrix",initialize:function se(t){var e=arguments.length,n=!0;if(6==e?this.set.apply(this,arguments):1==e?t instanceof se?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):n=!1:0==e?this.reset():n=!1,!n)throw Error("Unsupported matrix parameters")},set:function(t,e,n,i,s,r){return this._a=t,this._c=e,this._b=n,this._d=i,this._tx=s,this._ty=r,this},_serialize:function(e){return t.serialize(this.getValues(),e)},clone:function(){return new f(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(t){return t===this||t&&this._a==t._a&&this._b==t._b&&this._c==t._c&&this._d==t._d&&this._tx==t._tx&&this._ty==t._ty||!1},toString:function(){var t=r.instance;return"[["+[t.number(this._a),t.number(this._b),t.number(this._tx)].join(", ")+"], ["+[t.number(this._c),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,this},scale:function(){var t=o.read(arguments),e=o.read(arguments,0,0,!0);return e&&this.translate(e),this._a*=t.x,this._c*=t.x,this._b*=t.y,this._d*=t.y,e&&this.translate(e.negate()),this},translate:function(t){t=o.read(arguments);var e=t.x,n=t.y;return this._tx+=e*this._a+n*this._b,this._ty+=e*this._c+n*this._d,this},rotate:function(t,e){e=o.read(arguments,1),t=t*Math.PI/180;var n=e.x,i=e.y,s=Math.cos(t),r=Math.sin(t),a=n-n*s+i*r,h=i-n*r-i*s,u=this._a,l=this._b,c=this._c,d=this._d;return this._a=s*u+r*l,this._b=-r*u+s*l,this._c=s*c+r*d,this._d=-r*c+s*d,this._tx+=a*u+h*l,this._ty+=a*c+h*d,this},shear:function(){var t=o.read(arguments),e=o.read(arguments,0,0,!0);e&&this.translate(e);var n=this._a,i=this._c;return this._a+=t.y*this._b,this._c+=t.y*this._d,this._b+=t.x*n,this._d+=t.x*i,e&&this.translate(e.negate()),this},isIdentity:function(){return 1==this._a&&0==this._c&&0==this._b&&1==this._d&&0==this._tx&&0==this._ty},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},concatenate:function(t){var e=this._a,n=this._b,i=this._c,s=this._d;return this._a=t._a*e+t._c*n,this._b=t._b*e+t._d*n,this._c=t._a*i+t._c*s,this._d=t._b*i+t._d*s,this._tx+=t._tx*e+t._ty*n,this._ty+=t._tx*i+t._ty*s,this},preConcatenate:function(t){var e=this._a,n=this._b,i=this._c,s=this._d,r=this._tx,a=this._ty;return this._a=t._a*e+t._b*i,this._b=t._a*n+t._b*s,this._c=t._c*e+t._d*i,this._d=t._c*n+t._d*s,this._tx=t._a*r+t._b*a+t._tx,this._ty=t._c*r+t._d*a+t._ty,this},transform:function(t,e,n,i,s){return arguments.length<5?this._transformPoint(o.read(arguments)):this._transformCoordinates(t,e,n,i,s)},_transformPoint:function(t,e,n){var i=t.x,s=t.y;return e||(e=new o),e.set(i*this._a+s*this._b+this._tx,i*this._c+s*this._d+this._ty,n)},_transformCoordinates:function(t,e,n,i,s){for(var r=e,a=i,o=e+2*s;o>r;){var h=t[r++],u=t[r++];n[a++]=h*this._a+u*this._b+this._tx,n[a++]=h*this._c+u*this._d+this._ty}return n},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,s=n+t.height,r=[e,n,i,n,i,s,e,s];return this._transformCoordinates(r,0,r,0,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),s=i.slice(0,2),r=i.slice(),a=2;8>a;a++){var o=i[a],h=1&a;o<s[h]?s[h]=o:o>r[h]&&(r[h]=o)}return e||(e=new d),e.set(s[0],s[1],r[0]-s[0],r[1]-s[1],n)},inverseTransform:function(){return this._inverseTransform(o.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 s=t.x-this._tx,r=t.y-this._ty;return e||(e=new o),e.set((s*this._d-r*this._b)/i,(r*this._a-s*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 s=Math.sqrt(t*t+e*e);t/=s,e/=s;var r=t*n+e*i;n-=t*r,i-=e*r;var h=Math.sqrt(n*n+i*i);return n/=h,i/=h,r/=h,e*n>t*i&&(t=-t,e=-e,r=-r,s=-s),{translation:this.getTranslation(),scaling:new o(s,h),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:r}},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new o(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 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.beginPath(),e.rect(c[s]-2,c[++s]-2,4,4),e.fill()}}}e.restore()}}}),m=t.extend({_class:"Symbol",initialize:function ae(t,e){this._id=ae._id=(ae._id||0)+1,this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e),this._instances={}},_serialize:function(e,n){return n.add(this,function(){return t.serialize([this._class,this._definition],e,!1,n)})},_changed:function(e){t.each(this._instances,function(t){t._changed(e)})},getDefinition:function(){return this._definition},setDefinition:function(t){t._parentSymbol&&(t=t.clone()),this._definition&&delete this._definition._parentSymbol,this._definition=t,t.remove(),t.setSelected(!1),arguments[1]||t.setPosition(new o),t._parentSymbol=this,this._changed(5)},place:function(t){return new C(this,t)},clone:function(){return new m(this._definition.clone())}}),p=t.extend(e,{statics:{extend:function oe(e){e._serializeFields&&(e._serializeFields=t.merge(this.prototype._serializeFields,e._serializeFields));var n=oe.base.apply(this,arguments),i=n.prototype,s=i._class;return s&&(i._type=t.hyphenate(s)),n}},_class:"Item",_transformContent:!0,_boundsSelected:!1,_serializeFields:{name:null,matrix:new f,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,clipMask:!1,data:{}},initialize:function he(t){if(this._id=he._id=(he._id||0)+1,!this._project){var e=paper.project,n=e.activeLayer;n?n.addChild(this):this._setProject(e)}this._style=new E(this._project._currentStyle,this),this._matrix=new f,t&&this._matrix.translate(t)},_events:new function(){var e={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}},n={install:function(t){var n=this._project.view._eventCounters;if(n)for(var i in e)n[i]=(n[i]||0)+(e[i][t]||0)},uninstall:function(t){var n=this._project.view._eventCounters;if(n)for(var i in e)n[i]-=e[i][t]||0}};return t.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(t){this[t]=n},{onFrame:{install:function(){this._project.view._animateItem(this,!0)},uninstall:function(){this._project.view._animateItem(this,!1)}},onLoad:{}})},_serialize:function(e,n){function i(i){for(var a in i){var o=r[a];t.equals(o,i[a])||(s[a]=t.serialize(o,e,"data"!==a,n))}}var s={},r=this;return i(this._serializeFields),this instanceof y||i(this._style._defaults),[this._class,s]},_changed:function(t){if(4&t&&(delete this._bounds,delete this._position),this._parent&&12&t&&this._parent._clearBoundsCache(),2&t&&this._clearBoundsCache(),1&t&&(this._project._needsRedraw=!0),this._parentSymbol&&this._parentSymbol._changed(t),this._project._changes){var e=this._project._changesById[this._id];e?e.flags|=t:(e={item:this,flags:t},this._project._changesById[this._id]=e,this._project._changes.push(e))}},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getType:function(){return this._type},getName:function(){return this._name},setName:function(t,e){if(this._name&&this._removeFromNamed(),t&&this._parent){for(var n=this._parent._children,i=this._parent._namedChildren,s=t,r=1;e&&n[t];)t=s+" "+r++;(i[t]=i[t]||[]).push(this),n[t]=this}this._name=t||void 0,this._changed(32)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)},hasFill:function(){return!!this.getStyle().getFillColor()},hasStroke:function(){var t=this.getStyle();return!!t.getStrokeColor()&&t.getStrokeWidth()>0}},t.each(["locked","visible","blendMode","opacity","guide"],function(e){var n=t.capitalize(e),e="_"+e;this["get"+n]=function(){return this[e]},this["set"+n]=function(t){t!=this[e]&&(this[e]=t,this._changed("_locked"===e?32:33))}},{}),{_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._children)for(var t=0,e=this._children.length;e>t;t++)if(this._children[t].isSelected())return!0;return this._selected},setSelected:function(t){if(this._children&&!arguments[1])for(var e=0,n=this._children.length;n>e;e++)this._children[e].setSelected(t);(t=!!t)!=this._selected&&(this._selected=t,this._project._updateSelection(this),this._changed(33))},_selected:!1,isFullySelected:function(){if(this._children&&this._selected){for(var t=0,e=this._children.length;e>t;t++)if(!this._children[t].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){if(this._children)for(var e=0,n=this._children.length;n>e;e++)this._children[e].setFullySelected(t);this.setSelected(t,!0)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&(this._clipMask=t,t&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(33),this._parent&&this._parent._changed(256))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(){var t=this._position||(this._position=this.getBounds().getCenter(!0));return new(arguments[0]?o:h)(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(o.read(arguments).subtract(this.getPosition(!0)))},getMatrix:function(){return this._matrix},setMatrix:function(t){this._matrix.initialize(t),this._changed(5)},isEmpty:function(){return 0==this._children.length}},t.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){var e=this._boundsGetter,n=this._getCachedBounds("string"==typeof e?e:e&&e[t]||t,arguments[0]);return"getBounds"===t?new _(n.x,n.y,n.width,n.height,this,"setBounds"):n}},{_getCachedBounds:function(t,e,n){var i=(!e||e.equals(this._matrix))&&t;if(n&&this._parent){var s=n._id,r=this._parent._boundsCache=this._parent._boundsCache||{ids:{},list:[]};r.ids[s]||(r.list.push(n),r.ids[s]=n)}if(i&&this._bounds&&this._bounds[i])return this._bounds[i].clone();var a=this._matrix.isIdentity();e=!e||e.isIdentity()?a?null:this._matrix:a?e:e.clone().concatenate(this._matrix);var o=this._getBounds(t,e,i?this:n);return i&&(this._bounds||(this._bounds={}),this._bounds[i]=o.clone()),o},_clearBoundsCache:function(){if(this._boundsCache){for(var t=0,e=this._boundsCache.list,n=e.length;n>t;t++){var i=e[t];delete i._bounds,i!=this&&i._boundsCache&&i._clearBoundsCache()}delete this._boundsCache}},_getBounds:function(t,e,n){var i=this._children;if(!i||0==i.length)return new d;for(var s=1/0,r=-s,a=s,o=r,h=0,u=i.length;u>h;h++){var l=i[h];if(l._visible&&!l.isEmpty()){var c=l._getCachedBounds(t,e,n);s=Math.min(c.x,s),a=Math.min(c.y,a),r=Math.max(c.x+c.width,r),o=Math.max(c.y+c.height,o)}}return isFinite(s)?new d(s,a,r-s,o-a):new d},setBounds:function(t){t=d.read(arguments);var e=this.getBounds(),n=new f,i=t.getCenter();n.translate(i),(t.width!=e.width||t.height!=e.height)&&n.scale(0!=e.width?t.width/e.width:1,0!=e.height?t.height/e.height:1),i=e.getCenter(),n.translate(-i.x,-i.y),this.transform(n)}}),{getProject:function(){return this._project},_setProject:function(t){if(this._project!=t&&(this._project=t,this._children))for(var e=0,n=this._children.length;n>e;e++)this._children[e]._setProject(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof w)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},getChildren:function(){return this._children},setChildren:function(t){this.removeChildren(),this.addChildren(t)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){return this._parent&&this._parent._children[this._index+1]||null},getPreviousSibling:function(){return this._parent&&this._parent._children[this._index-1]||null},getIndex:function(){return this._index},isInserted:function(){return this._parent?this._parent.isInserted():!1},clone:function(){return this._clone(new this.constructor)},_clone:function(t){if(t.setStyle(this._style),this._children)for(var e=0,n=this._children.length;n>e;e++)t.addChild(this._children[e].clone(),!0);for(var i=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],e=0,n=i.length;n>e;e++){var s=i[e];this.hasOwnProperty(s)&&(t[s]=this[s])}return t._matrix.initialize(this._matrix),t.setSelected(this._selected),this._name&&t.setName(this._name,!0),t},copyTo:function(t){var e=this.clone();return t.layers?t.activeLayer.addChild(e):t.addChild(e),e},rasterize:function(e){var n=this.getStrokeBounds(),i=(e||72)/72,s=$.getCanvas(n.getSize().multiply(i)),r=s.getContext("2d"),a=(new f).scale(i).translate(-n.x,-n.y);r.save(),a.applyToContext(r),this.draw(r,t.merge({transforms:[a]}));var o=new b(s);return o.setBounds(n),r.restore(),o},contains:function(){return!!this._contains(this._matrix._inverseTransform(o.read(arguments)))},_contains:function(t){if(this._children){for(var e=this._children.length-1;e>=0;e--)if(this._children[e].contains(t))return!0;return!1}return t.isInside(this._getBounds("getBounds"))},hitTest:function(e,n){function i(i,s){var o=a["get"+s]();return e.getDistance(o)<n.tolerance?new S(i,r,{name:t.hyphenate(s),point:o}):void 0}if(e=o.read(arguments),n=S.getOptions(t.read(arguments)),this._locked||!this._visible||this._guide&&!n.guides)return null;if(!this._children&&!this.getRoughBounds().expand(n.tolerance)._containsPoint(e))return null;e=this._matrix._inverseTransform(e);var s,r=this;if(!(!n.center&&!n.bounds||this instanceof w&&!this._parent)){var a=this._getBounds("getBounds");if(n.center&&(s=i("center","Center")),!s&&n.bounds)for(var h=["TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],u=0;8>u&&!s;u++)s=i("bounds",h[u])}return(s||(s=this._children||!(n.guides&&!this._guide||n.selected&&!this._selected)?this._hitTest(e,n):null))&&s.point&&(s.point=r._matrix.transform(s.point)),s},_hitTest:function(t,e){if(this._children){for(var n,i=this._children.length-1;i>=0;i--)if(n=this._children[i].hitTest(t,e))return n}else if(this.hasFill()&&this._contains(t))return new S("fill",this)},addChild:function(t,e){return this.insertChild(void 0,t,e)},insertChild:function(t,e,n){var i=this.insertChildren(t,[e],n);return i&&i[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(e,n,i,s){var r=this._children;if(r&&n&&n.length>0){n=Array.prototype.slice.apply(n);for(var a=n.length-1;a>=0;a--){var o=n[a];s&&o._type!==s?n.splice(a,1):o._remove(!0)}t.splice(r,n,e,0);for(var a=0,h=n.length;h>a;a++){var o=n[a];o._parent=this,o._setProject(this._project),o._name&&o.setName(o._name)}this._changed(7)}else n=null;return n},insertAbove:function(t,e){var n=t._index;return t._parent==this._parent&&n<this._index&&n++,t._parent.insertChild(n,this,e)},insertBelow:function(t,e){var n=t._index;return t._parent==this._parent&&n>this._index&&n--,t._parent.insertChild(n,this,e)},sendToBack:function(){return this._parent.insertChild(0,this)},bringToFront:function(){return this._parent.addChild(this)},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",_removeFromNamed:function(){var t=this._parent._children,e=this._parent._namedChildren,n=this._name,i=e[n],s=i?i.indexOf(this):-1;-1!=s&&(t[n]==this&&delete t[n],i.splice(s,1),i.length?t[n]=i[i.length-1]:delete e[n])},_remove:function(e){return this._parent?(this._name&&this._removeFromNamed(),null!=this._index&&t.splice(this._parent._children,null,this._index,1),e&&this._parent._changed(7),this._parent=null,!0):!1},remove:function(){return this._remove(!0)},removeChildren:function(e,n){if(!this._children)return null;e=e||0,n=t.pick(n,this._children.length);for(var i=t.splice(this._children,null,e,n-e),s=i.length-1;s>=0;s--)i[s]._remove(!1);return i.length>0&&this._changed(7),i},reverseChildren:function(){if(this._children){this._children.reverse();for(var t=0,e=this._children.length;e>t;t++)this._children[t]._index=t;this._changed(7)}},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},_getOrder:function(t){function e(t){var e=[];do e.unshift(t);while(t=t._parent);return e}for(var n=e(this),i=e(t),s=0,r=Math.min(n.length,i.length);r>s;s++)if(n[s]!=i[s])return n[s]._index<i[s]._index?1:-1;return 0},hasChildren:function(){return this._children&&this._children.length>0},isAbove:function(t){return-1==this._getOrder(t)},isBelow:function(t){return 1==this._getOrder(t)},isParent:function(t){return this._parent==t},isChild:function(t){return t&&t._parent==this},isDescendant:function(t){for(var e=this;e=e._parent;)if(e==t)return!0;return!1},isAncestor:function(t){return t?t.isDescendant(this):!1},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(group|layer|compound-path)$/.test(e._type)&&t.isDescendant(e))return!0;e=e._parent}return!1},scale:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new f).scale(t,e,n||this.getPosition(!0)))},translate:function(){var t=new f;return this.transform(t.translate.apply(t,arguments))},rotate:function(t,e){return this.transform((new f).rotate(t,e||this.getPosition(!0)))},shear:function(t,e,n){return(arguments.length<2||"object"==typeof e)&&(n=e,e=t),this.transform((new f).shear(t,e,n||this.getPosition(!0)))},transform:function(t){var e=this._bounds,n=this._position;if(this._matrix.preConcatenate(t),(this._transformContent||arguments[1])&&this.applyMatrix(!0),this._changed(5),e&&0===t.getRotation()%90){for(var i in e){var s=e[i];t._transformBounds(s,s)}var r=this._boundsGetter,s=e[r&&r.getBounds||r||"getBounds"];s&&(this._position=s.getCenter(!0)),this._bounds=e}else n&&(this._position=t._transformPoint(n,n));return this},_applyMatrix:function(t,e){var n=this._children;if(n&&n.length>0){for(var i=0,s=n.length;s>i;i++)n[i].transform(t,e);return!0}},applyMatrix:function(t){var e=this._matrix;if(this._applyMatrix(e,!0)){var n=this._style,i=n.getFillColor(!0),s=n.getStrokeColor(!0);i&&i.transform(e),s&&s.transform(e),e.reset()}t||this._changed(5)},fitBounds:function(t,e){t=d.read(arguments);var n=this.getBounds(),i=n.height/n.width,s=t.height/t.width,r=(e?i>s:s>i)?t.width/n.width:t.height/n.height,a=new d(new o,new u(n.width*r,n.height*r));a.setCenter(t.getCenter()),this.setBounds(a)},importJSON:function(e){return this.addChild(t.importJSON(e))},_setStyles:function(t){var e=this._style,n=e.getStrokeWidth(),i=e.getStrokeJoin(),s=e.getStrokeCap(),r=e.getMiterLimit(),a=e.getFillColor(),o=e.getStrokeColor(),h=e.getDashArray(),u=e.getDashOffset();null!=n&&(t.lineWidth=n),i&&(t.lineJoin=i),s&&(t.lineCap=s),r&&(t.miterLimit=r),a&&(t.fillStyle=a.toCanvasStyle(t)),o&&(t.strokeStyle=o.toCanvasStyle(t),paper.support.nativeDash&&h&&h.length&&("setLineDash"in t?(t.setLineDash(h),t.lineDashOffset=u):(t.mozDash=h,t.mozDashOffset=u)))},draw:function(t,e){if(this._visible&&0!=this._opacity){this._drawCount=this._project._drawCount;var n=e.transforms,i=n[n.length-1],s=i.clone().concatenate(this._matrix);n.push(this._globalMatrix=s);var r,a,o,h=this._blendMode,l=this._opacity,c=K.nativeModes[h],d="normal"===h&&1===l||(c||1>l)&&this._canComposite();if(!d){var _=this.getStrokeBounds(i);if(!_.width||!_.height)return;o=e.offset,a=e.offset=_.getTopLeft().floor(),r=t,t=$.getContext(_.getSize().ceil().add(new u(1,1)))}t.save(),d?(t.globalAlpha=l,c&&(t.globalCompositeOperation=h)):t.translate(-a.x,-a.y),(d?this._matrix:s).applyToContext(t),!d&&e.clipItem&&e.clipItem.draw(t,e.extend({clip:!0})),this._draw(t,e),t.restore(),n.pop(),e.clip&&t.clip(),d||(K.process(h,t,r,l,a.subtract(o)),$.release(t),e.offset=o)}},_canComposite:function(){return!1}},t.each(["down","drag","up","move"],function(e){this["removeOn"+t.capitalize(e)]=function(){var t={};return t[e]=!0,this.removeOn(t)}},{removeOn:function(t){for(var e in t)if(t[e]){var n="mouse"+e,i=this._project,s=i._removeSets=i._removeSets||{};s[n]=s[n]||{},s[n][this._id]=this}return this}})),y=p.extend({_class:"Group",_serializeFields:{children:[]},initialize:function(t){p.call(this),this._children=[],this._namedChildren={},t&&!this._set(t)&&this.addChildren(Array.isArray(t)?t:arguments)},_changed:function ue(t){ue.base.call(this,t),2&t&&this._transformContent&&!this._matrix.isIdentity()&&this.applyMatrix(),258&t&&delete this._clipItem},_getClipItem:function(){if(void 0!==this._clipItem)return this._clipItem;for(var t=0,e=this._children.length;e>t;t++){var n=this._children[t];if(n._clipMask)return this._clipItem=n}return this._clipItem=null},getTransformContent:function(){return this._transformContent},setTransformContent:function(t){this._transformContent=t,t&&this.applyMatrix()},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var n=e.clipItem=this._getClipItem();n&&n.draw(t,e.extend({clip:!0}));for(var i=0,s=this._children.length;s>i;i++){var r=this._children[i];r!==n&&r.draw(t,e)}e.clipItem=null}}),w=y.extend({_class:"Layer",initialize:function(){this._project=paper.project,this._index=this._project.layers.push(this)-1,y.apply(this,arguments),this.activate()},_remove:function le(e){return this._parent?le.base.call(this,e):null!=this._index?(this._project.activeLayer===this&&(this._project.activeLayer=this.getNextSibling()||this.getPreviousSibling()),t.splice(this._project.layers,null,this._index,1),this._project._needsRedraw=!0,!0):!1},getNextSibling:function ce(){return this._parent?ce.base.call(this):this._project.layers[this._index+1]||null},getPreviousSibling:function de(){return this._parent?de.base.call(this):this._project.layers[this._index-1]||null},isInserted:function _e(){return this._parent?_e.base.call(this):null!=this._index},activate:function(){this._project.activeLayer=this}},new function(){function e(e){return function n(i){return i instanceof w&&!i._parent&&this._remove(!0)?(t.splice(i._project.layers,[this],i._index+(e?1:0),0),this._setProject(i._project),!0):n.base.call(this,i)}}return{insertAbove:e(!0),insertBelow:e(!1)}}),x=p.extend({_class:"Shape",_transformContent:!1,initialize:function(t,e,n){p.call(this,e),this._type=t,this._size=n},_draw:function(t,e){var n=this._style,i=this._size,s=i.width,r=i.height,o=n.getFillColor(),h=n.getStrokeColor();if(o||h||e.clip)switch(t.beginPath(),this._type){case"rect":t.rect(-s/2,-r/2,s,r);break;case"circle":t.arc(0,0,(s+r)/4,0,2*Math.PI,!0);break;case"ellipse":var u=s/2,l=r/2,c=a.KAPPA,d=u*c,_=l*c;t.moveTo(-u,0),t.bezierCurveTo(-u,-_,-d,-l,0,-l),t.bezierCurveTo(d,-l,u,-_,u,0),t.bezierCurveTo(u,_,d,l,0,l),t.bezierCurveTo(-d,l,-u,_,-u,0)}e.clip||!o&&!h||(this._setStyles(t),o&&t.fill(),h&&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},_contains:function fe(t){switch(this._type){case"rect":return fe.base.call(this,t);case"circle":case"ellipse":return t.divide(this._size).getLength()<=.5}},_hitTest:function ge(t){if(this.hasStroke()){var e=this._type,n=this.getStrokeWidth();switch(e){case"rect":var i=new d(this._size).setCenter(0,0),s=i.expand(n),r=i.expand(-n);if(s._containsPoint(t)&&!r._containsPoint(t))return new S("stroke",this);break;case"circle":case"ellipse":var a,o=this._size,h=o.width,u=o.height;if("ellipse"===e){var l=t.getAngleInRadians(),c=h*Math.sin(l),_=u*Math.cos(l);a=h*u/(2*Math.sqrt(c*c+_*_))}else a=(h+u)/4;if(2*Math.abs(t.getLength()-a)<=n)return new S("stroke",this)}}return ge.base.apply(this,arguments)},statics:new function(){function e(e,n,i,s){var r=new x(e,n,i),a=t.getNamed(s);return a&&r._set(a),r}return{Circle:function(){var n=o.readNamed(arguments,"center"),i=t.readNamed(arguments,"radius");return e("circle",n,new u(2*i),arguments)},Rectangle:function(){var t=d.readNamed(arguments,"rectangle");return e("rect",t.getCenter(!0),t.getSize(!0),arguments)},Ellipse:function(){var t=d.readNamed(arguments,"rectangle");return e("ellipse",t.getCenter(!0),t.getSize(!0),arguments)}}}}),b=p.extend({_class:"Raster",_transformContent:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{source:null},initialize:function(t,e){p.call(this,void 0!==e&&o.read(arguments,1)),t&&!this._set(t)&&(t.getContext?this.setCanvas(t):"string"==typeof t?this.setSource(t):this.setImage(t)),this._size||(this._size=new u)},clone:function(){var t=this._image;t||(t=$.getCanvas(this._size),t.getContext("2d").drawImage(this._canvas,0,0));var e=new b(t);return this._clone(e)},getSize:function(){return this._size},setSize:function(){var t=u.read(arguments);if(!this._size.equals(t)){var e=this.getElement();this.setCanvas($.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}},getWidth:function(){return this._size.width},getHeight:function(){return this._size.height},isEmpty:function(){return 0==this._size.width&&0==this._size.height},getPpi:function(){var t=this._matrix,e=new o(0,0).transform(t),n=new o(1,0).transform(t).subtract(e),i=new o(0,1).transform(t).subtract(e);return new u(72/n.getLength(),72/i.getLength())},getContext:function(){return this._context||(this._context=this.getCanvas().getContext("2d")),arguments[0]&&(this._image=null,this._changed(129)),this._context},setContext:function(t){this._context=t},getCanvas:function(){if(!this._canvas){var t=$.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){$.release(t)}}return this._canvas},setCanvas:function(t){this._canvas&&$.release(this._canvas),this._canvas=t,this._size=new u(t.width,t.height),this._image=null,this._context=null,this._changed(133)},getImage:function(){return this._image},setImage:function(t){this._canvas&&$.release(this._canvas),this._image=t,this._size=new u(t.naturalWidth,t.naturalHeight),this._canvas=null,this._context=null,this._changed(5)},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(t){function e(){n.fire("load"),n._project.view&&n._project.view.draw(!0)}var n=this,i=document.getElementById(t)||new Image;q.add(i,{load:function(){n.setImage(i),e()}}),i.width&&i.height?setTimeout(e,0):i.src||(i.src=t),this.setImage(i)},getElement:function(){return this._canvas||this._image},getSubImage:function(t){t=d.read(arguments);var e=$.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},toDataURL:function(){var t=this._image&&this._image.src;if(/^data:/.test(t))return t;var e=this.getCanvas();return e?e.toDataURL():null},drawImage:function(t,e){e=o.read(arguments,1),this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(e){var n,i;e?e instanceof k?(i=e,n=e.getBounds()):e.width?n=new d(e):e.x&&(n=new d(e.x-.5,e.y-.5,1,1)):n=this.getBounds();var s=32,r=Math.min(n.width,s),a=Math.min(n.height,s),o=b._sampleContext;o?o.clearRect(0,0,s+1,s+1):o=b._sampleContext=$.getContext(new u(s)),o.save();var h=(new f).scale(r/n.width,a/n.height).translate(-n.x,-n.y);h.applyToContext(o),i&&i.draw(o,t.merge({clip:!0,transforms:[h]})),this._matrix.applyToContext(o),o.drawImage(this.getElement(),-this._size.width/2,-this._size.height/2),o.restore();for(var l=o.getImageData(.5,.5,Math.ceil(r),Math.ceil(a)).data,c=[0,0,0],_=0,g=0,v=l.length;v>g;g+=4){var m=l[g+3];_+=m,m/=255,c[0]+=l[g]*m,c[1]+=l[g+1]*m,c[2]+=l[g+2]*m}for(var g=0;3>g;g++)c[g]/=_;return _?B.read(c):null},getPixel:function(t){t=o.read(arguments);var e=this.getContext().getImageData(t.x,t.y,1,1).data;return new B("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=o.read(arguments),e=B.read(arguments),n=e._convert("rgb"),i=e._alpha,s=this.getContext(!0),r=s.createImageData(1,1),a=r.data;a[0]=255*n[0],a[1]=255*n[1],a[2]=255*n[2],a[3]=null!=i?255*i:255,s.putImageData(r,t.x,t.y)},createImageData:function(t){return t=u.read(arguments),this.getContext().createImageData(t.width,t.height)},getImageData:function(t){return t=d.read(arguments),t.isEmpty()&&(t=new d(this.getSize())),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t,e){e=o.read(arguments,1),this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var n=new d(this._size).setCenter(0,0);return e?e._transformBounds(n):n},_hitTest:function(t){if(this._contains(t)){var e=this;return new S("pixel",e,{offset:t.add(e._size.divide(2)).round(),color:{get:function(){return e.getPixel(this.offset)}}})}},_draw:function(t){var e=this.getElement();e&&(t.globalAlpha=this._opacity,t.drawImage(e,-this._size.width/2,-this._size.height/2))},_canComposite:function(){return!0}}),C=p.extend({_class:"PlacedSymbol",_transformContent:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(t,e){p.call(this,void 0!==e&&o.read(arguments,1)),t&&!this._set(t)&&this.setSymbol(t instanceof m?t:new m(t))},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol&&delete this._symbol._instances[this._id],this._symbol=t,t._instances[this._id]=this},clone:function(){return this._clone(new C(this.symbol))},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e){return this.symbol._definition._getCachedBounds(t,e)},_hitTest:function(t,e,n){var i=this._symbol._definition._hitTest(t,e,n);return i&&(i.item=this),i},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),S=t.extend({_class:"HitResult",initialize:function(t,e,n){this.type=t,this.item=e,n&&(n.enumerable=!0,this.inject(n))},statics:{getOptions:function(e){return e&&e._merged?e:t.merge({type:null,tolerance:paper.project.options.hitTolerance||2,fill:!e,stroke:!e,segments:!e,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1,_merged:!0},e)}}}),P=t.extend({_class:"Segment",initialize:function(t,e,n,i,s,r){var a,o,h,u=arguments.length;0===u||(1===u?t.point?(a=t.point,o=t.handleIn,h=t.handleOut):a=t:6>u?2==u&&void 0===e.x?a=[t,e]:(a=t,o=e,h=n):6===u&&(a=[t,e],o=[n,i],h=[s,r])),this._point=new M(a,this),this._handleIn=new M(o,this),this._handleOut=new M(h,this)},_serialize:function(e){return t.serialize(this.isLinear()?this._point:[this._point,this._handleIn,this._handleOut],e,!0)},_changed:function(t){if(this._path){var e,n=this._path._curves&&this.getCurve();n&&(n._changed(),(e=n[t==this._point||t==this._handleIn&&n._segment1==this?"getPrevious":"getNext"]())&&e._changed()),this._path._changed(5)}},getPoint:function(){return this._point},setPoint:function(t){t=o.read(arguments),this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(t){t=o.read(arguments),this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(t){t=o.read(arguments),this._handleOut.set(t.x,t.y)},isLinear:function(){return this._handleIn.isZero()&&this._handleOut.isZero()},setLinear:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},_isSelected:function(t){var e=this._selectionState;return t==this._point?!!(4&e):t==this._handleIn?!!(1&e):t==this._handleOut?!!(2&e):!1},_setSelected:function(t,e){var n=this._path,e=!!e,i=this._selectionState||0,s=[!!(4&i),!!(1&i),!!(2&i)];if(t==this._point){if(e)s[1]=s[2]=!1;else{var r=this.getPrevious(),a=this.getNext();s[1]=r&&(r._point.isSelected()||r._handleOut.isSelected()),s[2]=a&&(a._point.isSelected()||a._handleIn.isSelected())}s[0]=e}else{var o=t==this._handleIn?1:2;s[o]!=e&&(e&&(s[0]=!1),s[o]=e)}this._selectionState=(s[0]?4:0)|(s[1]?1:0)|(s[2]?2:0),n&&i!=this._selectionState&&(n._updateSelection(this,i,this._selectionState),n._changed(33))},isSelected:function(){return this._isSelected(this._point)},setSelected:function(t){this._setSelected(this._point,t)},getIndex:function(){return void 0!==this._index?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(t._closed||e!=t._segments.length-1||e--,t.getCurves()[e]||null):null
|
|
},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,e);return n&&(this._length=i),i},getArea:function(){return z.getArea(this.getValues())},getPart:function(t,e){return new z(z.getPart(this.getValues(),t,e))},isLinear:function(){return this._segment1._handleOut.isZero()&&this._segment2._handleIn.isZero()},getIntersections:function(t){return z.getIntersections(this.getValues(),t.getValues(),this,t,[])},reverse:function(){return new z(this._segment2.reverse(),this._segment1.reverse())},divide:function(t){var e=null;if(t&&t.curve===this&&(t=t.parameter),t>0&&1>t){var n=z.subdivide(this.getValues(),t),i=this.isLinear(),s=n[0],r=n[1];i||(this._segment1._handleOut.set(s[2]-s[0],s[3]-s[1]),this._segment2._handleIn.set(r[4]-r[6],r[5]-r[7]));var a=s[6],h=s[7],u=new P(new o(a,h),!i&&new o(s[4]-a,s[5]-h),!i&&new o(r[2]-a,r[3]-h));if(this._path)this._segment1._index>0&&0===this._segment2._index?this._path.add(u):this._path.insert(this._segment2._index,u),e=this;else{var l=this._segment2;this._segment2=u,e=new z(u,l)}}return e},split:function(t){return this._path?this._path.split(this._segment1._index,t):null},clone:function(){return new z(this._segment1,this._segment2)},toString:function(){var t=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||t.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||t.push("handle2: "+this._segment2._handleIn),t.push("point2: "+this._segment2._point),"{ "+t.join(", ")+" }"},statics:{getValues:function(t,e){var n=t._point,i=t._handleOut,s=e._handleIn,r=e._point;return[n._x,n._y,n._x+i._x,n._y+i._y,r._x+s._x,r._y+s._y,r._x,r._y]},evaluate:function(t,e,n,i){var s,r,a=n?e:z.getParameterAt(t,e,0),h=t[0],u=t[1],l=t[2],c=t[3],d=t[4],_=t[5],f=t[6],g=t[7];if(0!==i||0!==a&&1!==a){var v=3*(l-h),m=3*(d-l)-v,p=f-h-v-m,y=3*(c-u),w=3*(_-c)-y,x=g-u-y-w;if(0===i)s=((p*a+m)*a+v)*a+h,r=((x*a+w)*a+y)*a+u;else{var b=1e-5;if(b>a&&l==h&&c==u||a>1-b&&d==f&&_==g?(s=d-l,r=_-c):(s=(3*p*a+2*m)*a+v,r=(3*x*a+2*w)*a+y),3===i){var C=6*p*a+2*m,S=6*x*a+2*w;return(s*S-r*C)/Math.pow(s*s+r*r,1.5)}}}else s=0===a?h:f,r=0===a?u:g;return 2==i?new o(r,-s):new o(s,r)},subdivide:function(t,e){var n=t[0],i=t[1],s=t[2],r=t[3],a=t[4],o=t[5],h=t[6],u=t[7];void 0===e&&(e=.5);var l=1-e,c=l*n+e*s,d=l*i+e*r,_=l*s+e*a,f=l*r+e*o,g=l*a+e*h,v=l*o+e*u,m=l*c+e*_,p=l*d+e*f,y=l*_+e*g,w=l*f+e*v,x=l*m+e*y,b=l*p+e*w;return[[n,i,c,d,m,p,x,b],[x,b,y,w,g,v,h,u]]},solveCubic:function(t,e,n,i){var s=t[e],r=t[e+2],o=t[e+4],h=t[e+6],u=3*(r-s),l=3*(o-r)-u,c=h-s-u-l;return a.solveCubic(c,l,u,s-n,i)},getParameterOf:function(t,e,n){if(Math.abs(t[0]-e)<1e-5&&Math.abs(t[1]-n)<1e-5)return 0;if(Math.abs(t[6]-e)<1e-5&&Math.abs(t[7]-n)<1e-5)return 1;for(var i,s,r=[],a=[],o=z.solveCubic(t,0,e,r),h=z.solveCubic(t,1,n,a),u=0;-1==o||o>u;)if(-1==o||(i=r[u++])>=0&&1>=i){for(var l=0;-1==h||h>l;)if((-1==h||(s=a[l++])>=0&&1>=s)&&(-1==o?i=s:-1==h&&(s=i),Math.abs(i-s)<1e-5))return.5*(i+s);if(-1==o)break}return null},getPart:function(t,e,n){return e>0&&(t=z.subdivide(t,e)[1]),1>n&&(t=z.subdivide(t,(n-e)/(1-e))[0]),t},isLinear:function(t){return t[0]===t[2]&&t[1]===t[3]&&t[4]===t[6]&&t[5]===t[7]},isFlatEnough:function(t,e){var n=t[0],i=t[1],s=t[2],r=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*s-2*n-h,c=3*r-2*i-u,d=3*a-2*h-n,_=3*o-2*u-i;return Math.max(l*l,d*d)+Math.max(c*c,_*_)<10*e*e},getArea:function(t){var e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],h=t[7];return(3*s*e-1.5*s*r-1.5*s*o-3*n*i-1.5*n*r-.5*n*o+1.5*a*e+1.5*a*i-3*a*o+.5*h*e+1.5*h*i+3*h*r)/10},getBounds:function(t){for(var e=t.slice(0,2),n=e.slice(),i=[0,0],s=0;2>s;s++)z._addBounds(t[s],t[s+2],t[s+4],t[s+6],s,0,e,n,i);return new d(e[0],e[1],n[0]-e[0],n[1]-e[1])},_getCrossings:function(t,e,n,i,s){function r(t){return z.evaluate(e,1,!0,1).y*t.y>0}var a=z.solveCubic(t,1,i,s),o=0,h=1e-5,u=Math.abs;-1===a&&(s[0]=z.getParameterOf(t,n,i),a=null!==s[0]?1:0);for(var l=0;a>l;l++){var c=s[l];if(c>-h&&1-h>c){var d=z.evaluate(t,c,!0,0);if(n<d.x+h){var _=z.evaluate(t,c,!0,1);if(u(d.x-n)<h){var f=_.getAngle();if(f>-180&&0>f&&(c>h||r(_)))continue}else if(u(_.y)<h||h>c&&!r(_))continue;o++}}}return o},_addBounds:function(t,e,n,i,s,r,o,h,u){function l(t,e){var n=t-e,i=t+e;n<o[s]&&(o[s]=n),i>h[s]&&(h[s]=i)}var c=3*(e-n)-t+i,d=2*(t+n)-4*e,_=e-t,f=a.solveQuadratic(c,d,_,u),g=1e-5,v=1-g;l(i,0);for(var m=0;f>m;m++){var p=u[m],y=1-p;p>g&&v>p&&l(y*y*y*t+3*y*y*p*e+3*y*p*p*n+p*p*p*i,r)}}}},t.each(["getBounds","getStrokeBounds","getHandleBounds","getRoughBounds"],function(t){this[t]=function(){this._bounds||(this._bounds={});var e=this._bounds[t];return e||(e=this._bounds[t]=A[t]([this._segment1,this._segment2],!1,this._path.getStyle())),e.clone()}},{}),t.each(["getPoint","getTangent","getNormal","getCurvatureAt"],function(t,e){this[t+"At"]=function(t,n){return z.evaluate(this.getValues(),t,n,e)},this[t]=function(t){return z.evaluate(this.getValues(),t,!0,e)}},{getParameterAt:function(t,e){return z.getParameterAt(this.getValues(),t,void 0!==e?e:0>t?1:0)},getParameterOf:function(t){return t=o.read(arguments),z.getParameterOf(this.getValues(),t.x,t.y)},getLocationAt:function(t,e){return e||(t=this.getParameterAt(t)),new I(this,t)},getLocationOf:function(t){t=o.read(arguments);var e=this.getParameterOf(t);return null!=e?new I(this,e):null},getNearestLocation:function(t){function e(e){if(e>=0&&1>=e){var i=t.getDistance(z.evaluate(n,e,!0,0),!0);if(r>i)return r=i,h=e,!0}}t=o.read(arguments);for(var n=this.getValues(),i=100,s=a.TOLERANCE,r=1/0,h=0,u=0;i>=u;u++)e(u/i);for(var l=1/(2*i);l>s;)e(h-l)||e(h+l)||(l/=2);var c=z.evaluate(n,h,!0,0);return new I(this,h,c,null,null,null,t.getDistance(c))},getNearestPoint:function(t){return t=o.read(arguments),this.getNearestLocation(t).getPoint()}}),new function(){function t(t){var e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],h=t[7],u=9*(i-r)+3*(o-e),l=6*(e+r)-12*i,c=3*(i-e),d=9*(s-a)+3*(h-n),_=6*(n+a)-12*s,f=3*(s-n);return function(t){var e=(u*t+l)*t+c,n=(d*t+_)*t+f;return Math.sqrt(e*e+n*n)}}function e(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}return{statics:!0,getLength:function(n,i,s){if(void 0===i&&(i=0),void 0===s&&(s=1),n[0]==n[2]&&n[1]==n[3]&&n[6]==n[4]&&n[7]==n[5]){var r=n[6]-n[0],o=n[7]-n[1];return(s-i)*Math.sqrt(r*r+o*o)}var h=t(n);return a.integrate(h,i,s,e(i,s))},getParameterAt:function(n,i,s){function r(t){var n=e(s,t);return _+=t>s?a.integrate(l,s,t,n):-a.integrate(l,t,s,n),s=t,_-i}if(0===i)return s;var o=i>0,h=o?s:0,u=o?1:s,i=Math.abs(i),l=t(n),c=a.integrate(l,h,u,e(h,u));if(i>=c)return o?u:h;var d=i/c,_=0;return a.findRoot(r,l,o?h+d:u-d,h,u,16,1e-5)}}},new function(){function t(t,e,n,i,s,r,a){var o=t[0],h=t[t.length-1];o&&i.equals(o._point)||h&&i.equals(h._point)||t.push(new I(e,n,i,s,r,a))}function e(i,s,r,a,o,h,u,l){if(l=(l||0)+1,!(l>20)){h=h||[0,1],u=u||[0,1];for(var c=z.getPart(i,h[0],h[1]),d=z.getPart(s,u[0],u[1]),_=0;_++<20;){var f,g=n(c,d,f=u.slice()),v=0;if(0===g)break;if(g>0){if(u=f,d=z.getPart(s,u[0],u[1]),v=n(d,c,f=h.slice()),0===v)break;g>0&&(h=f,c=z.getPart(i,h[0],h[1]))}if(0>g||0>v){if(h[1]-h[0]>u[1]-u[0]){var m=(h[0]+h[1])/2;e(i,s,r,a,o,[h[0],m],u,l),e(i,s,r,a,o,[m,h[1]],u,l);break}var m=(u[0]+u[1])/2;e(i,s,r,a,o,h,[u[0],m],l),e(i,s,r,a,o,h,[m,u[1]],l);break}if(Math.abs(h[1]-h[0])<=1e-5&&Math.abs(u[1]-u[0])<=1e-5){var p=(h[0]+h[1])/2,y=(u[0]+u[1])/2;t(o,r,p,z.evaluate(i,p,!0,0),a,y,z.evaluate(s,y,!0,0));break}}}}function n(t,e,n){var s=t[0],r=t[1],a=t[2],o=t[3],h=t[4],u=t[5],l=t[6],c=t[7],d=e[0],_=e[1],f=e[2],v=e[3],m=e[4],p=e[5],y=e[6],w=e[7],x=g.getSignedDistance,b=x(s,r,l,c,a,o)||0,C=x(s,r,l,c,h,u)||0,S=b*C>0?.75:4/9,P=S*Math.min(0,b,C),M=S*Math.max(0,b,C),I=x(s,r,l,c,d,_),k=x(s,r,l,c,f,v),A=x(s,r,l,c,m,p),O=x(s,r,l,c,y,w);if(P>Math.max(I,k,A,O)||M<Math.min(I,k,A,O))return 0;var L,D=i(I,k,A,O);I>O&&(L=P,P=M,M=L);for(var T=-1/0,j=1/0,B=-1/0,N=0,F=D.length;F>N;N++){var E=D[N],R=D[(N+1)%F];R[1]<E[1]&&(L=R,R=E,E=L);var q=E[0],V=E[1],H=R[0],Z=R[1],G=(Z-V)/(H-q);if(P>=V&&Z>=P){var J=q+(P-V)/G;j>J&&(j=J),J>T&&(T=J)}if(M>=V&&Z>=M){var J=q+(M-V)/G;J>B&&(B=J),j>J&&(j=0)}}if(1/0!==j&&B!==-1/0){var X=Math.min(P,M),W=Math.max(P,M);O>X&&W>O&&(B=1),I>X&&W>I&&(j=0),T>B&&(B=1);var Y=n[0],U=n[1]-Y;if(n[0]=Y+j*U,n[1]=Y+B*U,(U-(n[1]-n[0]))/U>=.2)return 1}return z.getBounds(t).touches(z.getBounds(e))?-1:0}function i(t,e,n,i){var s=[0,t],r=[1/3,e],a=[2/3,n],o=[1,i],h=g.getSignedDistance,u=h(0,t,1,i,1/3,e),l=h(0,t,1,i,2/3,n);if(0>u*l)return[s,r,o,a];var c,d;return Math.abs(u)>Math.abs(l)?(c=r,d=(i-n-(i-t)/3)*(2*(i-n)-i+e)/3):(c=a,d=(e-t+(t-i)/3)*(-2*(t-e)+t-n)/3),0>d?[s,c,o]:[s,r,a,o]}function s(e,n,i,s,r){for(var a=z.isLinear(e),o=a?n:e,h=a?e:n,u=h[0],l=h[1],c=h[6],d=h[7],_=c-u,f=d-l,g=Math.atan2(-f,_),v=Math.sin(g),m=Math.cos(g),p=_*m-f*v,y=[],w=0;8>w;w+=2){var x=o[w]-u,b=o[w+1]-l;y.push(x*m-b*v,b*m+x*v)}for(var C=[],S=z.solveCubic(y,1,0,C),w=0;S>w;w++){var P=C[w];if(P>=0&&1>=P){var M=z.evaluate(y,P,!0,0);M.x>=0&&M.x<=p&&t(r,a?s:i,P,z.evaluate(o,P,!0,0),a?i:s)}}}function r(e,n,i,s,r){var a=g.intersect(e[0],e[1],e[6],e[7],n[0],n[1],n[6],n[7]);a&&t(r,i,null,a,s)}return{statics:{getIntersections:function(t,n,i,a,o){var h=z.isLinear(t),u=z.isLinear(n);return(h&&u?r:h||u?s:e)(t,n,i,a,o),o}}}}),I=t.extend({_class:"CurveLocation",initialize:function ve(t,e,n,i,s,r,a){this._id=ve._id=(ve._id||0)+1,this._curve=t,this._segment1=t._segment1,this._segment2=t._segment2,this._parameter=e,this._point=n,this._curve2=i,this._parameter2=s,this._point2=r,this._distance=a},getSegment:function(){if(!this._segment){var t=this.getCurve(),e=this.getParameter();if(1===e)this._segment=t._segment2;else if(0===e||arguments[0])this._segment=t._segment1;else{if(null==e)return null;this._segment=t.getLength(0,e)<t.getLength(e,1)?t._segment1:t._segment2}}return this._segment},getCurve:function(){return(!this._curve||arguments[0])&&(this._curve=this._segment1.getCurve(),null==this._curve.getParameterOf(this._point)&&(this._curve=this._segment2.getPrevious().getCurve())),this._curve},getIntersection:function(){var t=this._intersection;if(!t&&this._curve2){var e=this._parameter2;this._intersection=t=new I(this._curve2,e,this._point2||this._point,this),t._intersection=this}return t},getPath:function(){var t=this.getCurve();return t&&t._path},getIndex:function(){var t=this.getCurve();return t&&t.getIndex()},getOffset:function(){var t=this.getPath();return t&&t._getOffset(this)},getCurveOffset:function(){var t=this.getCurve(),e=this.getParameter();return null!=e&&t&&t.getLength(0,e)},getParameter:function(){if((null==this._parameter||arguments[0])&&this._point){var t=this.getCurve(arguments[0]&&this._point);this._parameter=t&&t.getParameterOf(this._point)}return this._parameter},getPoint:function(){if((!this._point||arguments[0])&&null!=this._parameter){var t=this.getCurve();this._point=t&&t.getPointAt(this._parameter,!0)}return this._point},getTangent:function(){var t=this.getParameter(),e=this.getCurve();return null!=t&&e&&e.getTangentAt(t,!0)},getNormal:function(){var t=this.getParameter(),e=this.getCurve();return null!=t&&e&&e.getNormalAt(t,!0)},getDistance:function(){return this._distance},divide:function(){var t=this.getCurve(!0);return t&&t.divide(this.getParameter(!0))},split:function(){var t=this.getCurve(!0);return t&&t.split(this.getParameter(!0))},toString:function(){var t=[],e=this.getPoint(),n=r.instance;e&&t.push("point: "+e);var i=this.getIndex();null!=i&&t.push("index: "+i);var s=this.getParameter();return null!=s&&t.push("parameter: "+n.number(s)),null!=this._distance&&t.push("distance: "+n.number(this._distance)),"{ "+t.join(", ")+" }"}}),k=p.extend({_class:"PathItem",initialize:function(){p.apply(this,arguments)},getIntersections:function(t){if(!this.getBounds().touches(t.getBounds()))return[];for(var e=[],n=this.getCurves(),i=t.getCurves(),s=i.length,r=[],a=0;s>a;a++)r[a]=i[a].getValues();for(var a=0,o=n.length;o>a;a++)for(var h=n[a],u=h.getValues(),l=0;s>l;l++)z.getIntersections(u,r[l],h,i[l],e);return e},setPathData:function(t){function e(t,e,n){var s=parseFloat(i[t]);return a&&(s+=h[e]),n&&(h[e]=s),s}function n(t,n){return new o(e(t,"x",n),e(t+1,"y",n))}var i,s,r=t.match(/[a-z][^a-z]*/gi),a=!1,h=new o;"path"===this._type?this.removeSegments():this.removeChildren();for(var u=0,l=r.length;l>u;u++){var c=r[u],d=c[0],_=d.toLowerCase();i=c.slice(1).trim().split(/[\s,]+|(?=[+-])/),a=d===_;var f=i.length;switch(_){case"m":case"l":for(var g=0;f>g;g+=2)this[0===g&&"m"===_?"moveTo":"lineTo"](n(g,!0));break;case"h":case"v":for(var v="h"==_?"x":"y",g=0;f>g;g++)e(g,v,!0),this.lineTo(h);break;case"c":for(var g=0;f>g;g+=6)this.cubicCurveTo(n(g),s=n(g+2),n(g+4,!0));break;case"s":for(var g=0;f>g;g+=4)this.cubicCurveTo(h.multiply(2).subtract(s),s=n(g),n(g+2,!0));break;case"q":for(var g=0;f>g;g+=4)this.quadraticCurveTo(s=n(g),n(g+2,!0));break;case"t":for(var g=0;f>g;g+=2)this.quadraticCurveTo(s=h.multiply(2).subtract(s),n(g,!0));break;case"a":break;case"z":this.closePath()}}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())}}),A=k.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(t){this._closed=!1,this._segments=[],p.call(this);var e=Array.isArray(t)?"object"==typeof t[0]?t:arguments:!t||void 0===t.point&&void 0===t.x?null:arguments;this.setSegments(e||[]),t&&!e&&this._set(t)},clone:function(){var t=this._clone(new A(this._segments));return t._closed=this._closed,void 0!==this._clockwise&&(t._clockwise=this._clockwise),t},_changed:function(t){if(p.prototype._changed.call(this,t),4&t){if(delete this._length,delete this._clockwise,this._curves)for(var e=0,n=this._curves.length;n>e;e++)this._curves[e]._changed(5)}else 8&t&&delete this._bounds},getSegments:function(){return this._segments},setSegments:function(t){this._selectedSegmentState=0,this._segments.length=0,delete this._curves,this._add(P.readAll(t))},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var t=this._curves,e=this._segments;if(!t){var n=this._countCurves();t=this._curves=Array(n);for(var i=0;n>i;i++)t[i]=new z(this,e[i],e[i+1]||e[0])}return t},getFirstCurve:function(){return this.getCurves()[0]},getLastCurve:function(){var t=this.getCurves();return t[t.length-1]},getPathData:function(){function t(t,e,r){var a=t._point,o=e._point,h=t._handleOut,u=e._handleIn;if(h.isZero()&&u.isZero())r||s.push("L"+i.point(o,n));else{var l=o.subtract(a);s.push("c"+i.point(h,n)+" "+i.point(l.add(u),n)+" "+i.point(l,n))}}var e=this._segments,n=arguments[0],i=r.instance,s=[];if(0===e.length)return"";s.push("M"+i.point(e[0]._point));for(var a=0,o=e.length-1;o>a;a++)t(e[a],e[a+1],!1);return this._closed&&(t(e[e.length-1],e[0],!0),s.push("z")),s.join("")},isClosed:function(){return this._closed},setClosed:function(t){if(this._closed!=(t=!!t)){if(this._closed=t,this._curves){var e=this._curves.length=this._countCurves();t&&(this._curves[e-1]=new z(this,this._segments[e-1],this._segments[0]))}this._changed(5)}},isEmpty:function(){return 0===this._segments.length},isPolygon:function(){for(var t=0,e=this._segments.length;e>t;t++)if(!this._segments[t].isLinear())return!1;return!0},_applyMatrix:function(t){for(var e=Array(6),n=0,i=this._segments.length;i>n;n++)this._segments[n]._transformCoordinates(t,e,!0);return!0},_add:function(t,e){for(var n=this._segments,i=this._curves,s=t.length,r=null==e,e=r?n.length:e,a=this.isFullySelected(),o=0;s>o;o++){var h=t[o];h._path&&(h=t[o]=h.clone()),h._path=this,h._index=e+o,a&&(h._selectionState=4),h._selectionState&&this._updateSelection(h,0,h._selectionState)}if(r)n.push.apply(n,t);else{n.splice.apply(n,[e,0].concat(t));for(var o=e+s,u=n.length;u>o;o++)n[o]._index=o}if(i||t._curves){i||(i=this._curves=[]);var l=e>0?e-1:e,c=l,d=Math.min(l+s,this._countCurves());t._curves&&(i.splice.apply(i,[l,0].concat(t._curves)),c+=t._curves.length);for(var o=c;d>o;o++)i.splice(o,0,new z(this,null,null));this._adjustCurves(l,d)}return this._changed(5),t},_adjustCurves:function(t,e){for(var n,i=this._segments,s=this._curves,r=t;e>r;r++)n=s[r],n._path=this,n._segment1=i[r],n._segment2=i[r+1]||i[0];(n=s[this._closed&&0===t?i.length-1:t-1])&&(n._segment2=i[t]||i[0]),(n=s[e])&&(n._segment1=i[e])},_countCurves:function(){var t=this._segments.length;return!this._closed&&t>0?t-1:t},add:function(t){return arguments.length>1&&"number"!=typeof t?this._add(P.readAll(arguments)):this._add([P.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(P.readAll(arguments,1),t):this._add([P.read(arguments,1)],t)[0]},addSegment:function(){return this._add([P.read(arguments)])[0]},insertSegment:function(t){return this._add([P.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(P.readAll(t))},insertSegments:function(t,e){return this._add(P.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(e,n){e=e||0,n=t.pick(n,this._segments.length);var i=this._segments,s=this._curves,r=i.length,a=i.splice(e,n-e),o=a.length;if(!o)return a;for(var h=0;o>h;h++){var u=a[h];u._selectionState&&this._updateSelection(u,u._selectionState,0),delete u._index,delete u._path}for(var h=e,l=i.length;l>h;h++)i[h]._index=h;if(s){var c=e>0&&n===r+(this._closed?1:0)?e-1:e,s=s.splice(c,o);arguments[2]&&(a._curves=s.slice(1)),this._adjustCurves(c,c)}return this._changed(5),a},isFullySelected:function(){return this._selected&&this._selectedSegmentState==4*this._segments.length},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function me(t){t||this._selectSegments(!1),me.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?4*e:0;for(var n=0;e>n;n++)this._segments[n]._selectionState=t?4:0},_updateSelection:function(t,e,n){t._selectionState=n;var i=this._selectedSegmentState+=n-e;i>0&&this.setSelected(!0)},flatten:function(t){for(var e=new L(this),n=0,i=e.length/Math.ceil(e.length/t),s=e.length+(this._closed?-i:i)/2,r=[];s>=n;)r.push(new P(e.evaluate(n,0))),n+=i;this.setSegments(r)},simplify:function(t){if(this._segments.length>2){var e=new D(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null!==e){if(1==arguments.length){var n=t;"number"==typeof n&&(n=this.getLocationAt(n)),t=n.index,e=n.parameter}e>=1&&(t++,e--);var i=this.getCurves();if(t>=0&&t<i.length){e>0&&i[t++].divide(e);var s,r=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),s=this):t>0&&(s=this._clone((new A).insertAbove(this,!0))),s._add(r,0),this.addSegment(r[0]),s}return null}},isClockwise:function(){return void 0!==this._clockwise?this._clockwise:A.isClockwise(this._segments)},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},reverse:function(){this._segments.reverse();for(var t=0,e=this._segments.length;e>t;t++){var n=this._segments[t],i=n._handleIn;n._handleIn=n._handleOut,n._handleOut=i,n._index=t}delete this._curves,void 0!==this._clockwise&&(this._clockwise=!this._clockwise)},join:function(t){if(t){var e=t._segments,n=this.getLastSegment(),i=t.getLastSegment();n._point.equals(i._point)&&t.reverse();var s=t.getFirstSegment();if(n._point.equals(s._point))n.setHandleOut(s._handleOut),this._add(e.slice(1));else{var r=this.getFirstSegment();r._point.equals(s._point)&&t.reverse(),i=t.getLastSegment(),r._point.equals(i._point)?(r.setHandleIn(i._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())}t.remove();var r=this.getFirstSegment();return n=this.getLastSegment(),n._point.equals(r._point)&&(r.setHandleIn(n._handleIn),n.remove(),this.setClosed(!0)),this._changed(5),!0}return!1},reduce:function(){return this},getLength:function(){if(null==this._length){var t=this.getCurves();this._length=0;for(var e=0,n=t.length;n>e;e++)this._length+=t[e].getLength()}return this._length},getArea:function(){for(var t=this.getCurves(),e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},_getOffset:function(t){var e=t&&t.getIndex();if(null!=e){for(var n=this.getCurves(),i=0,s=0;e>s;s++)i+=n[s].getLength();var r=n[e];return i+r.getLength(0,t.getParameter())}return null},getLocationOf:function(t){t=o.read(arguments);for(var e=this.getCurves(),n=0,i=e.length;i>n;n++){var s=e[n].getLocationOf(t);if(s)return s}return null},getLocationAt:function(t,e){var n=this.getCurves(),i=0;if(e){var s=~~t;return n[s].getLocationAt(t-s,!0)}for(var r=0,a=n.length;a>r;r++){var o=i,h=n[r];if(i+=h.getLength(),i>=t)return h.getLocationAt(t-o)}return t<=this.getLength()?new I(n[n.length-1],1):null},getPointAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getPoint()},getTangentAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getTangent()},getNormalAt:function(t,e){var n=this.getLocationAt(t,e);return n&&n.getNormal()},getNearestLocation:function(t){t=o.read(arguments);for(var e=this.getCurves(),n=1/0,i=null,s=0,r=e.length;r>s;s++){var a=e[s].getNearestLocation(t);a._distance<n&&(n=a._distance,i=a)}return i},getNearestPoint:function(t){return t=o.read(arguments),this.getNearestLocation(t).getPoint()},getStyle:function(){var t=this._parent;return(t&&"compound-path"===t._type?t:this)._style},_contains:function(t){var e=this._closed;if(!e&&!this.hasFill()||!this._getBounds("getRoughBounds")._containsPoint(t))return!1;for(var n=this.getCurves(),i=this._segments,s=0,r=Array(3),a=(e?n[n.length-1]:new z(i[i.length-1]._point,i[0]._point)).getValues(),o=a,h=0,u=n.length;u>h;h++){var l=n[h].getValues(),c=l[0],d=l[1];(c!==l[2]||d!==l[3]||c!==l[4]||d!==l[5]||c!==l[6]||d!==l[7])&&(s+=z._getCrossings(l,o,t.x,t.y,r),o=l)}return e||(s+=z._getCrossings(a,o,t.x,t.y,r)),1===(1&s)},_hitTest:function(t,e){function n(e,n,i){return t.getDistance(n)<m?new S(i,y,{segment:e,point:n}):void 0}function i(t,i){var s=t._point;return(i||e.segments)&&n(t,s,"segment")||!i&&e.handles&&(n(t,s.add(t._handleIn),"handle-in")||n(t,s.add(t._handleOut),"handle-out"))}function s(t){c.push(t)}function r(t){var e=c[t],n=c[(t+1)%c.length];return[e.x,e.y,e.x,e.y,n.x,n.y,n.x,n.y]}function a(t){for(var e=c.length,n=r(e-1),i=Array(3),s=0,a=0;e>a;a++){var o=r(a);s+=z._getCrossings(o,n,t.x,t.y,i),n=o}return 1===(1&s)}function o(e){return("round"!==h||"round"!==u)&&(c=[],v||e._index>0&&e._index<g.length-1?"round"!==h&&(e._handleIn.isZero()||e._handleOut.isZero())&&A._addSquareJoin(e,h,p,l,s,!0):"round"!==u&&A._addSquareCap(e,u,p,s,!0),c.length>0)?a(t):t.getDistance(e._point)<=p}var h,u,l,c,d,_,f=this.getStyle(),g=this._segments,v=this._closed,m=e.tolerance||0,p=0,y=this;if(e.stroke&&f.getStrokeColor()&&(h=f.getStrokeJoin(),u=f.getStrokeCap(),p=f.getStrokeWidth()/2+m,l=p*f.getMiterLimit()),!e.ends||e.segments||v){if(e.segments||e.handles)for(var w=0,x=g.length;x>w;w++)if(_=i(g[w]))return _}else if(_=i(g[0],!0)||i(g[g.length-1],!0))return _;if(p>0){if(d=this.getNearestLocation(t)){var b=d.getParameter();0===b||1===b?o(d.getSegment())||(d=null):d._distance>p&&(d=null)}if(!d&&"miter"===h)for(var w=0,x=g.length;x>w;w++){var C=g[w];if(t.getDistance(C._point)<=l&&o(C)){d=C.getLocation();break}}}return!d&&e.fill&&this.hasFill()&&this.contains(t)?new S("fill",this):d?new S("stroke",this,{location:d}):null}},new function(){function t(t,e,n,i){function s(e){var n=a[e],i=a[e+1];(d!=n||_!=i)&&(t.beginPath(),t.moveTo(d,_),t.lineTo(n,i),t.stroke(),t.beginPath(),t.arc(n,i,r,0,2*Math.PI,!0),t.fill())}for(var r=i/2,a=Array(6),o=0,h=e.length;h>o;o++){var u=e[o];u._transformCoordinates(n,a,!1);var l=u._selectionState,c=4&l,d=a[0],_=a[1];(c||1&l)&&s(2),(c||2&l)&&s(4),t.save(),t.beginPath(),t.rect(d-r,_-r,i,i),t.fill(),c||(t.beginPath(),t.rect(d-r+1,_-r+1,i-2,i-2),t.fillStyle="#ffffff",t.fill()),t.restore()}}function e(t,e,n){function i(e){var i=d[e];if(n)i._transformCoordinates(n,f,!1),s=f[0],r=f[1];else{var _=i._point;s=_._x,r=_._y}if(g)t.moveTo(s,r),g=!1;else{if(n)h=f[2],u=f[3];else{var v=i._handleIn;h=s+v._x,u=r+v._y}h==s&&u==r&&l==a&&c==o?t.lineTo(s,r):t.bezierCurveTo(l,c,h,u,s,r)}if(a=s,o=r,n)l=f[4],c=f[5];else{var v=i._handleOut;l=a+v._x,c=o+v._y}}for(var s,r,a,o,h,u,l,c,d=e._segments,_=d.length,f=Array(6),g=!0,v=0;_>v;v++)i(v);e._closed&&_>1&&i(0)}return{_draw:function(t,n){var i=n.clip,s=n.compound;s||t.beginPath();var r=this.getStyle(),a=r.getFillColor(),o=r.getStrokeColor(),h=r.getDashArray(),u=!paper.support.nativeDash&&o&&h&&h.length;if((a||o&&!u||s||i)&&e(t,this),this._closed&&t.closePath(),!i&&!s&&(a||o)&&(this._setStyles(t),a&&t.fill(),o)){if(u){t.beginPath();for(var l,c=new L(this),d=r.getDashOffset(),_=0;d<c.length;)l=d+h[_++%h.length],c.drawPart(t,d,l),d=l+h[_++%h.length]}t.stroke()}},_drawSelected:function(n,i){n.beginPath(),e(n,this,i),n.stroke(),t(n,this._segments,i,this._project.options.handleSize||4)}}},new function(){function t(t){var e=t.length,n=[],i=[],s=2;n[0]=t[0]/s;for(var r=1;e>r;r++)i[r]=1/s,s=(e-1>r?4:2)-i[r],n[r]=(t[r]-n[r-1])/s;for(var r=1;e>r;r++)n[e-r-1]-=i[e-r]*n[e-r];return n}return{smooth:function(){var e,n=this._segments,i=n.length,s=i;if(!(2>=i)){this._closed?(e=Math.min(i,4),s+=2*Math.min(i,e)):e=0;for(var r=[],a=0;i>a;a++)r[a+e]=n[a]._point;if(this._closed)for(var a=0;e>a;a++)r[a]=n[a+i-e]._point,r[a+i+e]=n[a]._point;else s--;for(var h=[],a=1;s-1>a;a++)h[a]=4*r[a]._x+2*r[a+1]._x;h[0]=r[0]._x+2*r[1]._x,h[s-1]=3*r[s-1]._x;for(var u=t(h),a=1;s-1>a;a++)h[a]=4*r[a]._y+2*r[a+1]._y;h[0]=r[0]._y+2*r[1]._y,h[s-1]=3*r[s-1]._y;var l=t(h);if(this._closed){for(var a=0,c=i;e>a;a++,c++){var d=a/e,_=1-d,f=a+e,g=c+e;u[c]=u[a]*d+u[c]*_,l[c]=l[a]*d+l[c]*_,u[g]=u[f]*_+u[g]*d,l[g]=l[f]*_+l[g]*d}s--}for(var v=null,a=e;s-e>=a;a++){var m=n[a-e];v&&m.setHandleIn(v.subtract(m._point)),s>a&&(m.setHandleOut(new o(u[a],l[a]).subtract(m._point)),v=s-1>a?new o(2*r[a+1]._x-u[a+1],2*r[a+1]._y-l[a+1]):new o((r[s]._x+u[s-1])/2,(r[s]._y+l[s-1])/2))}if(this._closed&&v){var m=this._segments[0];m.setHandleIn(v.subtract(m._point))}}}}},new function(){function e(t){var e=t._segments;if(0==e.length)throw Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){1===this._segments.length&&this.removeSegment(0),this._segments.length||this._add([new P(o.read(arguments))])},moveBy:function(){throw Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new P(o.read(arguments))])},cubicCurveTo:function(){var t=o.read(arguments),n=o.read(arguments),i=o.read(arguments),s=e(this);s.setHandleOut(t.subtract(s._point)),this._add([new P(i,n.subtract(i))])},quadraticCurveTo:function(){var t=o.read(arguments),n=o.read(arguments),i=e(this)._point;this.cubicCurveTo(t.add(i.subtract(t).multiply(1/3)),t.add(n.subtract(t).multiply(1/3)),n)},curveTo:function(){var n=o.read(arguments),i=o.read(arguments),s=t.pick(t.read(arguments),.5),r=1-s,a=e(this)._point,h=n.subtract(a.multiply(r*r)).subtract(i.multiply(s*s)).divide(2*s*r);if(h.isNaN())throw Error("Cannot put a curve through points with parameter = "+s);this.quadraticCurveTo(h,i)},arcTo:function(n,i){var s,r=e(this),a=r._point,h=o.read(arguments),u=t.pick(t.peek(arguments),!0);if("boolean"==typeof u){n=h,i=u;var l=a.add(n).divide(2),s=l.add(l.subtract(a).rotate(i?-90:90))}else s=h,n=o.read(arguments);var c=new g(a.add(s).divide(2),s.subtract(a).rotate(90),!0),d=new g(s.add(n).divide(2),n.subtract(s).rotate(90),!0),_=c.intersect(d,!0),f=new g(a,n),v=f.getSide(s);if(!_){if(!v)return this.lineTo(n);throw Error("Cannot put an arc through the given points: "+[a,s,n])}var m=a.subtract(_),p=m.getDirectedAngle(n.subtract(_)),y=f.getSide(_);0==y?p=v*Math.abs(p):v==y&&(p-=360*(0>p?-1:1));for(var w=Math.abs(p),x=w>=360?4:Math.ceil(w/90),b=p/x,C=b*Math.PI/360,S=4/3*Math.sin(C)/(1+Math.cos(C)),M=[],z=0;x>=z;z++){var I=x>z?_.add(m):n,k=x>z?m.rotate(90).multiply(S):null;0==z?r.setHandleOut(k):M.push(new P(I,m.rotate(-90).multiply(S),k)),m=m.rotate(b)}this._add(M)},lineBy:function(t){t=o.read(arguments);var n=e(this);this.lineTo(n._point.add(t))},curveBy:function(t,n,i){t=o.read(t),n=o.read(n);var s=e(this)._point;this.curveTo(s.add(t),s.add(n),i)},arcBy:function(t,n){t=o.read(t),n=o.read(n);
|
|
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;4>o;o++){var h=r[o];a[o]=new P(h._point.multiply(s).add(i),h._handleIn.multiply(s),h._handleOut.multiply(s))}return n._add(a),n._closed=!0,n}var s=a.KAPPA/2,r=[new P([0,.5],[0,s],[0,-s]),new P([.5,0],[-s,0],[s,0]),new P([1,.5],[0,-s],[0,s]),new P([.5,1],[s,0],[-s,0])];return{Line:function(){return new A(o.readNamed(arguments,"from"),o.readNamed(arguments,"to")).set(t.getNamed(arguments))},Rectangle:n,RoundRectangle:n,Ellipse:i,Oval:i,Circle:function(){var e=o.readNamed(arguments,"center"),n=t.readNamed(arguments,"radius");return i(new d(e.subtract(n),new u(2*n,2*n))).set(t.getNamed(arguments))},Arc:function(){var t=o.readNamed(arguments,"from"),n=o.readNamed(arguments,"through"),i=o.readNamed(arguments,"to"),s=e(arguments);return s.moveTo(t),s.arcTo(n,i),s},RegularPolygon:function(){for(var n=o.readNamed(arguments,"center"),i=t.readNamed(arguments,"sides"),s=t.readNamed(arguments,"radius"),r=e(arguments),a=360/i,h=!(i%3),u=new o(0,h?-s:s),l=h?-1:.5,c=Array(i),d=0;i>d;d++)c[d]=new P(n.add(u.rotate((d+l)*a)));return r._add(c),r._closed=!0,r},Star:function(){for(var n=o.readNamed(arguments,"center"),i=2*t.readNamed(arguments,"points"),s=t.readNamed(arguments,"radius1"),r=t.readNamed(arguments,"radius2"),a=e(arguments),h=360/i,u=new o(0,-1),l=Array(i),c=0;i>c;c++)l[c]=new P(n.add(u.rotate(h*c).multiply(c%2?r:s)));return a._add(l),a._closed=!0,a}}}});var O=k.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){k.call(this),this._children=[],this._namedChildren={},t&&!this._set(t)&&this.addChildren(Array.isArray(t)?t:arguments)},insertChildren:function pe(t,e,n){e=pe.base.call(this,t,e,n,"path");for(var i=0,s=!n&&e&&e.length;s>i;i++){var r=e[i];void 0===r._clockwise&&r.setClockwise(0===r._index)}return e},reduce:function(){if(1==this._children.length){var t=this._children[0];return t.insertAbove(this),this.remove(),t}return this},reverse:function(){for(var t=this._children,e=0,n=t.length;n>e;e++)t[e].reverse()},smooth:function(){for(var t=0,e=this._children.length;e>t;t++)this._children[t].smooth()},isClockwise:function(){var t=this.getFirstChild();return t&&t.isClockwise()},setClockwise:function(t){this.isClockwise()!=!!t&&this.reverse()},getFirstSegment:function(){var t=this.getFirstChild();return t&&t.getFirstSegment()},getLastSegment:function(){var t=this.getLastChild();return t&&t.getLastSegment()},getCurves:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e=e.concat(t[n].getCurves());return e},getFirstCurve:function(){var t=this.getFirstChild();return t&&t.getFirstCurve()},getLastCurve:function(){var t=this.getLastChild();return t&&t.getFirstCurve()},getArea:function(){for(var t=this._children,e=0,n=0,i=t.length;i>n;n++)e+=t[n].getArea();return e},getPathData:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e.push(t[n].getPathData(arguments[0]));return e.join(" ")},_contains:function(t){for(var e=[],n=0,i=this._children.length;i>n;n++){var s=this._children[n];s.contains(t)&&e.push(s)}return 1==(1&e.length)&&e},_hitTest:function ye(e,n){var i=ye.base.call(this,e,t.merge(n,{fill:!1}));return!i&&n.fill&&this.hasFill()&&(i=this._contains(e),i=i?new S("fill",i[0]):null),i},_draw:function(t,e){var n=this._children,i=this._style;if(0!==n.length){t.beginPath(),e=e.extend({compound:!0});for(var s=0,r=n.length;r>s;s++)n[s].draw(t,e);e.clip||(this._setStyles(t),i.getFillColor()&&t.fill(),i.getStrokeColor()&&t.stroke())}}},new function(){function e(t){if(!t._children.length)throw Error("Use a moveTo() command first");return t._children[t._children.length-1]}var n={moveTo:function(){var t=new A;this.addChild(t),t.moveTo.apply(t,arguments)},moveBy:function(){this.moveTo(e(this).getLastSegment()._point.add(o.read(arguments)))},closePath:function(){e(this).closePath()}};return t.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","curveBy","arcBy"],function(t){n[t]=function(){var n=e(this);n[t].apply(n,arguments)}}),n}),L=t.extend({initialize:function(t){function e(t,e){var n=z.getValues(t,e);r.curves.push(n),r._computeParts(n,t._index,0,1)}this.curves=[],this.parts=[],this.length=0,this.index=0;for(var n,i=t._segments,s=i[0],r=this,a=1,o=i.length;o>a;a++)n=i[a],e(s,n),s=n;t._closed&&e(n,i[0])},_computeParts:function(t,e,n,i){if(i-n>1/32&&!z.isFlatEnough(t,.25)){var s=z.subdivide(t),r=(n+i)/2;this._computeParts(s[0],e,n,r),this._computeParts(s[1],e,r,i)}else{var a=t[6]-t[0],o=t[7]-t[1],h=Math.sqrt(a*a+o*o);h>1e-5&&(this.length+=h,this.parts.push({offset:this.length,value:i,index:e}))}},getParameterAt:function(t){for(var e,n=this.index;e=n,!(0==n||this.parts[--n].offset<t););for(var i=this.parts.length;i>e;e++){var s=this.parts[e];if(s.offset>=t){this.index=e;var r=this.parts[e-1],a=r&&r.index==s.index?r.value:0,o=r?r.offset:0;return{value:a+(s.value-a)*(t-o)/(s.offset-o),index:s.index}}}var s=this.parts[this.parts.length-1];return{value:1,index:s.index}},evaluate:function(t,e){var n=this.getParameterAt(t);return z.evaluate(this.curves[n.index],n.value,!0,e)},drawPart:function(t,e,n){e=this.getParameterAt(e),n=this.getParameterAt(n);for(var i=e.index;i<=n.index;i++){var s=z.getPart(this.curves[i],i==e.index?e.value:0,i==n.index?n.value:1);i==e.index&&t.moveTo(s[0],s[1]),t.bezierCurveTo.apply(t,s.slice(2))}}}),D=t.extend({initialize:function(t,e){this.points=[];for(var n,i=t._segments,s=0,r=i.length;r>s;s++){var a=i[s].point.clone();n&&n.equals(a)||(this.points.push(a),n=a)}this.error=e},fit:function(){var t=this.points,e=t.length;return this.segments=e>0?[new P(t[0])]:[],e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.segments},fitCubic:function(t,e,n,i){if(1==e-t){var s=this.points[t],r=this.points[e],a=s.getDistance(r)/3;return this.addCurve([s,s.add(n.normalize(a)),r.add(i.normalize(a)),r]),void 0}for(var o,h=this.chordLengthParameterize(t,e),u=Math.max(this.error,this.error*this.error),l=0;4>=l;l++){var c=this.generateBezier(t,e,h,n,i),d=this.findMaxError(t,e,c,h);if(d.error<this.error)return this.addCurve(c),void 0;if(o=d.index,d.error>=u)break;this.reparameterize(t,e,h,c),u=d.error}var _=this.points[o-1].subtract(this.points[o]),f=this.points[o].subtract(this.points[o+1]),g=_.add(f).divide(2).normalize();this.fitCubic(t,o,n,g),this.fitCubic(o,e,g.negate(),i)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new P(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,n,i,s){for(var r=1e-11,a=this.points[t],o=this.points[e],h=[[0,0],[0,0]],u=[0,0],l=0,c=e-t+1;c>l;l++){var d=n[l],_=1-d,f=3*d*_,g=_*_*_,v=f*_,m=f*d,p=d*d*d,y=i.normalize(v),w=s.normalize(m),x=this.points[t+l].subtract(a.multiply(g+v)).subtract(o.multiply(m+p));h[0][0]+=y.dot(y),h[0][1]+=y.dot(w),h[1][0]=h[0][1],h[1][1]+=w.dot(w),u[0]+=y.dot(x),u[1]+=w.dot(x)}var b,C,S=h[0][0]*h[1][1]-h[1][0]*h[0][1];if(Math.abs(S)>r){var P=h[0][0]*u[1]-h[1][0]*u[0],M=u[0]*h[1][1]-u[1]*h[0][1];b=M/S,C=P/S}else{var z=h[0][0]+h[0][1],I=h[1][0]+h[1][1];b=C=Math.abs(z)>r?u[0]/z:Math.abs(I)>r?u[1]/I:0}var k=o.getDistance(a);return r*=k,(r>b||r>C)&&(b=C=k/3),[a,a.add(i.normalize(b)),o.add(s.normalize(C)),o]},reparameterize:function(t,e,n,i){for(var s=t;e>=s;s++)n[s-t]=this.findRoot(i,this.points[s],n[s-t])},findRoot:function(t,e,n){for(var i=[],s=[],r=0;2>=r;r++)i[r]=t[r+1].subtract(t[r]).multiply(3);for(var r=0;1>=r;r++)s[r]=i[r+1].subtract(i[r]).multiply(2);var a=this.evaluate(3,t,n),o=this.evaluate(2,i,n),h=this.evaluate(1,s,n),u=a.subtract(e),l=o.dot(o)+u.dot(h);return Math.abs(l)<1e-5?n:n-u.dot(o)/l},evaluate:function(t,e,n){for(var i=e.slice(),s=1;t>=s;s++)for(var r=0;t-s>=r;r++)i[r]=i[r].multiply(1-n).add(i[r+1].multiply(n));return i[0]},chordLengthParameterize:function(t,e){for(var n=[0],i=t+1;e>=i;i++)n[i-t]=n[i-t-1]+this.points[i].getDistance(this.points[i-1]);for(var i=1,s=e-t;s>=i;i++)n[i]/=n[s];return n},findMaxError:function(t,e,n,i){for(var s=Math.floor((e-t+1)/2),r=0,a=t+1;e>a;a++){var o=this.evaluate(3,n,i[a-t]),h=o.subtract(this.points[a]),u=h.x*h.x+h.y*h.y;u>=r&&(r=u,s=a)}return{error:r,index:s}}});k.inject(new function(){function t(t,e){t.sort(function(t,e){var n=t.getPath(),i=e.getPath();return n===i?t.getIndex()+t.getParameter()-(e.getIndex()+e.getParameter()):n._id-i._id});for(var n=e&&[],i=t.length-1;i>=0;i--){var s=t[i],r=s.getIntersection(),a=s.divide(),o=a&&a.getSegment1()||s.getSegment();n&&n.push(r),o._intersection=r}return n}function e(t){if(t instanceof O){for(var e=t._children,n=e.length,i=Array(n),s=Array(n),r=e[0].isClockwise(),a=0;n>a;a++)i[a]=e[a].getBounds(),s[a]=0;for(var a=0;n>a;a++){for(var o=1;n>o;o++)a!==o&&i[a].contains(i[o])&&s[o]++;a>0&&0===s[a]%2&&e[a].setClockwise(r)}}return t}function n(n,s,r,a){n=e(n.clone()),s=e(s.clone());var h=n.isClockwise(),u=s.isClockwise(),l=n.getIntersections(s);t(t(l,!0)),a&&(s.reverse(),u=!u);for(var c=[].concat(n._children||[n]).concat(s._children||[s]),d=[],_=new O,f=0,g=c.length;g>f;f++){var v=c[f],m=v._parent,p=v.isClockwise(),y=v._segments;v=m instanceof O?m:v;for(var w=y.length-1;w>=0;w--){var x=y[w],b=x.getCurve().getPoint(.5),C=v!==n&&n.contains(b)&&(p===h||a||!i(n,b)),S=v!==s&&s.contains(b)&&(p===u||!i(s,b));r(v===n,C,S)?x._invalid=!0:d.push(x)}}for(var f=0,g=d.length;g>f;f++){var x=d[f];if(!x._visited){var v=new A,M=x._intersection,z=M&&M.getSegment(!0);x.getPrevious()._invalid&&x.setHandleIn(z?z._handleIn:new o(0,0));do{if(x._visited=!0,x._invalid&&x._intersection){var I=x._intersection.getSegment(!0);v.add(new P(x._point,x._handleIn,I._handleOut)),I._visited=!0,x=I}else v.add(x.clone());x=x.getNext()}while(x&&!x._visited&&x!==z);var k=v._segments.length;k>1&&(k>2||!v.isPolygon())?(v.setClosed(!0),_.addChild(v,!0)):v.remove()}}return n.remove(),s.remove(),_.reduce()}function i(t,e){var n=t.getCurves(),i=t.getBounds();if(i.contains(e))for(var s=0,r=n.length;r>s;s++){var a=n[s];if(a.getBounds().contains(e)&&a.getParameterOf(e))return!0}return!1}return{unite:function(t){return n(this,t,function(t,e,n){return e||n})},intersect:function(t){return n(this,t,function(t,e,n){return!(e||n)})},subtract:function(t){return n(this,t,function(t,e,n){return t&&n||!t&&!e},!0)},exclude:function(t){return new y([this.subtract(t),t.subtract(this)])},divide:function(t){return new y([this.subtract(t),this.intersect(t)])}}});var T=p.extend({_class:"TextItem",_boundsSelected:!0,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(e){var n=e&&t.isPlainObject(e)&&void 0===e.x&&void 0===e.y;p.call(this,n?null:o.read(arguments)),this._content="",this._lines=[],n&&this._set(e)},_clone:function we(t){return t.setContent(this._content),we.base.call(this,t)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(69)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),j=T.extend({_class:"PointText",initialize:function(){T.apply(this,arguments)},clone:function(){return this._clone(new j)},getPoint:function(){var t=this._matrix.getTranslation();return new h(t.x,t.y,this,"setPoint")},setPoint:function(t){t=o.read(arguments),this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._style,n=this._lines,i=e.getLeading();t.font=e.getFontStyle(),t.textAlign=e.getJustification();for(var s=0,r=n.length;r>s;s++){var a=n[s];e.getFillColor()&&t.fillText(a,0,0),e.getStrokeColor()&&t.strokeText(a,0,0),t.translate(0,i)}}}},new function(){var t=null;return{_getBounds:function(e,n){t||(t=$.getContext(1,1));var i=this._style,s=this._lines,r=s.length,a=i.getJustification(),o=i.getLeading(),h=0;t.font=i.getFontStyle();for(var u=0,l=0;r>l;l++)u=Math.max(u,t.measureText(s[l]).width);"left"!==a&&(h-=u/("center"===a?2:1));var c=new d(h,r?-.75*o:0,u,r*o);return n?n._transformBounds(c,c):c}}}),B=t.extend(new function(){function e(t){var e=h[t];if(!e){i||(i=$.getContext(1,1),i.globalCompositeOperation="copy"),i.fillStyle="rgba(0,0,0,0)",i.fillStyle=t,i.fillRect(0,0,1,1);var n=i.getImageData(0,0,1,1).data;e=h[t]=[n[0]/255,n[1]/255,n[2]/255]}return e.slice()}function n(t){var e=t.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(e.length>=4){for(var n=[0,0,0],i=0;3>i;i++){var s=e[i+1];n[i]=parseInt(1==s.length?s+s:s,16)/255}return n}}var i,s={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},a={},h={},u=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],l={"rgb-hsb":function(t,e,n){var i=Math.max(t,e,n),s=Math.min(t,e,n),r=i-s,a=0===r?0:60*(i==t?(e-n)/r+(n>e?6:0):i==e?(n-t)/r+2:(t-e)/r+4);return[a,0===i?0:r/i,i]},"hsb-rgb":function(t,e,n){var t=t/60%6,i=Math.floor(t),s=t-i,i=u[i],r=[n,n*(1-e),n*(1-e*s),n*(1-e*(1-s))];return[r[i[0]],r[i[1]],r[i[2]]]},"rgb-hsl":function(t,e,n){var i=Math.max(t,e,n),s=Math.min(t,e,n),r=i-s,a=0===r,o=a?0:60*(i==t?(e-n)/r+(n>e?6:0):i==e?(n-t)/r+2:(t-e)/r+4),h=(i+s)/2,u=a?0:.5>h?r/(i+s):r/(2-i-s);return[o,u,h]},"hsl-rgb":function(t,e,n){if(t/=360,0===e)return[n,n,n];for(var i=[t+1/3,t,t-1/3],s=.5>n?n*(1+e):n+e-n*e,r=2*n-s,a=[],o=0;3>o;o++){var h=i[o];0>h&&(h+=1),h>1&&(h-=1),a[o]=1>6*h?r+6*(s-r)*h:1>2*h?s:2>3*h?r+6*(s-r)*(2/3-h):r}return a},"rgb-gray":function(t,e,n){return[.2989*t+.587*e+.114*n]},"gray-rgb":function(t){return[t,t,t]},"gray-hsb":function(t){return[0,0,t]},"gray-hsl":function(t){return[0,0,t]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return t.each(s,function(e,n){a[n]=[],t.each(e,function(e,i){var s=t.capitalize(e),r=/^(hue|saturation)$/.test(e),h=a[n][i]="gradient"===e?function(t){var e=this._components[0];return t=N.read(Array.isArray(t)?t:arguments,0,0,!0),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"hue"===e?function(t){return isNaN(t)?0:(t%360+360)%360}:"gradient"===n?function(){return o.read(arguments,0,0,"highlight"===e,!0)}:function(t){return isNaN(t)?0:Math.min(Math.max(t,0),1)};this["get"+s]=function(){return this._type===n||r&&/^hs[bl]$/.test(this._type)?this._components[i]:this._convert(n)[i]},this["set"+s]=function(t){this._type===n||r&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(n),this._type=n),t=h.call(this,t),null!=t&&(this._components[i]=t,this._changed())}},this)},{_class:"Color",_readIndex:!0,initialize:function c(t){var i,r,o,h,u=Array.prototype.slice,l=arguments,d=0;Array.isArray(t)&&(l=t,t=l[0]);var _=null!=t&&typeof t;if("string"===_&&t in s&&(i=t,t=l[1],Array.isArray(t)?(r=t,o=l[2]):(this._read&&(d=1),l=u.call(l,1),_=typeof t)),!r){if(h="number"===_?l:"object"===_&&null!=t.length?t:null){i||(i=h.length>=3?"rgb":"gray");var f=s[i].length;o=h[f],this._read&&(d+=h===arguments?f+(null!=o?1:0):1),h.length>f&&(h=u.call(h,0,f))}else if("string"===_)r=t.match(/^#[0-9a-f]{3,6}$/i)?n(t):e(t),i="rgb";else if("object"===_)if(t.constructor===c){if(i=t._type,r=t._components.slice(),o=t._alpha,"gradient"===i)for(var g=1,v=r.length;v>g;g++){var m=r[g];m&&(r[g]=m.clone())}}else if(t.constructor===N)i="gradient",h=l;else{i="hue"in t?"lightness"in t?"hsl":"hsb":"gradient"in t||"stops"in t||"radial"in t?"gradient":"gray"in t?"gray":"rgb";var p=s[i];w=a[i],this._components=r=[];for(var g=0,v=p.length;v>g;g++){var y=t[p[g]];null==y&&0===g&&"gradient"===i&&"stops"in t&&(y={stops:t.stops,radial:t.radial}),y=w[g].call(this,y),null!=y&&(r[g]=y)}o=t.alpha}this._read&&i&&(d=1)}if(this._type=i||"rgb","gradient"===i&&(this._id=c._id=(c._id||0)+1),!r){this._components=r=[];for(var w=a[this._type],g=0,v=w.length;v>g;g++){var y=w[g].call(this,h&&h[g]);null!=y&&(r[g]=y)}}this._components=r,this._alpha=o,this._read&&(this._read=d)},_serialize:function(e,n){var i=this.getComponents();return t.serialize(/^(gray|rgb)$/.test(this._type)?i:[this._type].concat(i),e,!0,n)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(17)},clone:function(){return new B(this._type,this._components.slice(),this._alpha)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=l[this._type+"-"+t])?e.apply(this,this._components):l["rgb-"+t].apply(this,l[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new B(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._type=t},getComponents:function(){var t=this._components.slice();return null!=this._alpha&&t.push(this._alpha),t},getAlpha:function(){return null!=this._alpha?this._alpha:1},setAlpha:function(t){this._alpha=null==t?null:Math.min(Math.max(t,0),1),this._changed()},hasAlpha:function(){return null!=this._alpha},equals:function(e){return t.isPlainValue(e)&&(e=B.read(arguments)),e===this||e&&this._type===e._type&&this._alpha===e._alpha&&t.equals(this._components,e._components)||!1},toString:function(){for(var t=s[this._type],e=[],n="gradient"===this._type,i=r.instance,a=0,o=t.length;o>a;a++){var h=this._components[a];null!=h&&e.push(t[a]+": "+(n?h:i.number(h)))}return null!=this._alpha&&e.push("alpha: "+i.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){var e=this._convert("rgb"),n=t||null==this._alpha?1:this._alpha;return e=[Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])],1>n&&e.push(n),(4==e.length?"rgba(":"rgb(")+e.join(",")+")"},toCanvasStyle:function(t){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var e,n=this._components,i=n[0],s=i._stops,r=n[1],a=n[2];if(i._radial){var o=a.getDistance(r),h=n[3];if(h){var u=h.subtract(r);u.getLength()>o&&(h=r.add(u.normalize(o-.1)))}var l=h||r;e=t.createRadialGradient(l.x,l.y,0,r.x,r.y,o)}else e=t.createLinearGradient(r.x,r.y,a.x,a.y);for(var c=0,d=s.length;d>c;c++){var _=s[c];e.addColorStop(_._rampPoint,_._color.toCanvasStyle())}return this._canvasStyle=e},transform:function(t){if("gradient"===this._type){for(var e=this._components,n=1,i=e.length;i>n;n++){var s=e[n];t._transformPoint(s,s,!0)}this._changed()}},statics:{_types:s,random:function(){var t=Math.random;return new B(t(),t(),t())}}})});t.each(B._types,function(e,n){var i=this[t.capitalize(n)+"Color"]=function(t){var e=null!=t&&typeof t,i="object"===e&&null!=t.length?t:"string"===e?null:arguments;return i?new B(n,i):new B(t)};if(3==n.length){var s=n.toUpperCase();B[s]=this[s+"Color"]=i}},this);var N=t.extend({_class:"Gradient",initialize:function xe(t,e){this._id=xe._id=(xe._id||0)+1,t&&this._set(t)&&(t=e=null),this._stops||this.setStops(t||["white","black"]),null==this._radial&&this.setRadial("string"==typeof e&&"radial"===e||e||!1)},_serialize:function(e,n){return n.add(this,function(){return t.serialize([this._stops,this._radial],e,!0,n)})},_changed:function(){for(var t=0,e=this._owners&&this._owners.length;e>t;t++)this._owners[t]._changed()},_addOwner:function(t){this._owners||(this._owners=[]),this._owners.push(t)},_removeOwner:function(t){var e=this._owners?this._owners.indexOf(t):-1;-1!=e&&(this._owners.splice(e,1),0===this._owners.length&&delete this._owners)},clone:function(){for(var t=[],e=0,n=this._stops.length;n>e;e++)t[e]=this._stops[e].clone();return new this.constructor(t)},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var e=0,n=this._stops.length;n>e;e++)delete this._stops[e]._owner;if(t.length<2)throw Error("Gradient stop list needs to contain at least two stops.");this._stops=F.readAll(t,0,!1,!0);for(var e=0,n=this._stops.length;n>e;e++){var i=this._stops[e];i._owner=this,i._defaultRamp&&i.setRampPoint(e/(n-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t&&t.constructor==this.constructor&&this._stops.length==t._stops.length){for(var e=0,n=this._stops.length;n>e;e++)if(!this._stops[e].equals(t._stops[e]))return!1;return!0}return!1}}),F=t.extend({_class:"GradientStop",initialize:function(t,e){if(t){var n,i;void 0===e&&Array.isArray(t)?(n=t[0],i=t[1]):t.color?(n=t.color,i=t.rampPoint):(n=t,i=e),this.setColor(n),this.setRampPoint(i)}},clone:function(){return new F(this._color.clone(),this._rampPoint)},_serialize:function(e,n){return t.serialize([this._color,this._rampPoint],e,!0,n)},_changed:function(){this._owner&&this._owner._changed(17)},getRampPoint:function(){return this._rampPoint},setRampPoint:function(t){this._defaultRamp=null==t,this._rampPoint=t||0,this._changed()},getColor:function(){return this._color},setColor:function(t){this._color=B.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t instanceof F&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),E=t.extend(new function(){var e={fillColor:void 0,strokeColor:void 0,selectedColor:void 0,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",miterLimit:10,dashOffset:0,dashArray:[],font:"sans-serif",fontSize:12,leading:null,justification:"left"},n={strokeWidth:25,strokeCap:25,strokeJoin:25,miterLimit:25,font:5,fontSize:5,leading:5,justification:5},i={},s={_defaults:e,_textDefaults:t.merge(e,{fillColor:new B})};return t.each(e,function(e,r){var a=/Color$/.test(r),o=t.capitalize(r),h=n[r],u="set"+o,l="get"+o;s[u]=function(t){var e=this._item&&this._item._children;if(e&&e.length>0&&"compound-path"!==this._item._type)for(var n=0,i=e.length;i>n;n++)e[n]._style[u](t);else{var s=this._values[r];s!=t&&(a&&(s&&delete s._owner,t&&t.constructor===B&&(t._owner=this._item)),this._values[r]=t,this._item&&this._item._changed(h||17))}},s[l]=function(){var e,n=this._item&&this._item._children;if(!n||0===n.length||arguments[0]||"compound-path"===this._item._type){var e=this._values[r];return void 0===e?(e=this._defaults[r],e&&e.clone&&(e=e.clone()),this._values[r]=e):!a||e&&e.constructor===B||(this._values[r]=e=B.read([e],0,0,!0,!0),e&&(e._owner=this._item)),e}for(var i=0,s=n.length;s>i;i++){var o=n[i]._style[l]();if(0===i)e=o;else if(!t.equals(e,o))return void 0}return e},i[l]=function(){return this._style[l]()},i[u]=function(t){this._style[u](t)}}),p.inject(i),s},{_class:"Style",initialize:function(t,e){this._values={},this._item=e,e instanceof T&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof E,n=e?t._values:t;if(n)for(var i in n)if(i in this._defaults){var s=n[i];this[i]=s&&e&&s.clone?s.clone():s}},getLeading:function be(){var t=be.base.call(this);return null!=t?t:1.2*this.getFontSize()},getFontStyle:function(){var t=this.getFontSize();return(/[a-z]/i.test(t)?t+" ":t+"px ")+this.getFont()}}),R=new function(){function e(n,i){for(var s=[],r=0,a=n&&n.length;a>r;){var o=n[r++];if("string"==typeof o)o=document.createElement(o);else if(!o||!o.nodeType)continue;t.isPlainObject(n[r])&&R.set(o,n[r++]),Array.isArray(n[r])&&e(n[r++],o),i&&i.appendChild(o),s.push(o)}return s}var n=/^(checked|value|selected|disabled)$/i,i={text:"textContent",html:"innerHTML"},s={lineHeight:1,zoom:1,zIndex:1,opacity:1};return{create:function(t,n){var i=Array.isArray(t),s=e(i?t:arguments,i?n:null);return 1==s.length?s[0]:s},find:function(t,e){return(e||document).querySelector(t)},findAll:function(t,e){return(e||document).querySelectorAll(t)},get:function(t,e){return t?n.test(e)?"value"===e||"string"!=typeof t[e]?t[e]:!0:e in i?t[i[e]]:t.getAttribute(e):null},set:function(t,e,s){if("string"!=typeof e)for(var r in e)e.hasOwnProperty(r)&&this.set(t,r,e[r]);else{if(!t||void 0===s)return t;n.test(e)?t[e]=s:e in i?t[i[e]]=s:"style"===e?this.setStyle(t,s):"events"===e?q.add(t,s):t.setAttribute(e,s)}return t},getStyles:function(t){var e=t&&t.ownerDocument.defaultView;return e&&e.getComputedStyle(t,"")},getStyle:function(t,e){return t&&t.style[e]||this.getStyles(t)[e]||null},setStyle:function(t,e,n){if("string"!=typeof e)for(var i in e)e.hasOwnProperty(i)&&this.setStyle(t,i,e[i]);else!/^-?[\d\.]+$/.test(n)||e in s||(n+="px"),t.style[e]=n;return t},hasClass:function(t,e){return RegExp("\\s*"+e+"\\s*").test(t.className)},addClass:function(t,e){t.className=(t.className+" "+e).trim()},removeClass:function(t,e){t.className=t.className.replace(RegExp("\\s*"+e+"\\s*")," ").trim()},remove:function(t){t.parentNode&&t.parentNode.removeChild(t)},removeChildren:function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},getBounds:function(t,e){var n,i=t.ownerDocument,s=i.body,r=i.documentElement;try{n=t.getBoundingClientRect()}catch(a){n={left:0,top:0,width:0,height:0}}var o=n.left-(r.clientLeft||s.clientLeft||0),h=n.top-(r.clientTop||s.clientTop||0);if(!e){var u=i.defaultView;o+=u.pageXOffset||r.scrollLeft||s.scrollLeft,h+=u.pageYOffset||r.scrollTop||s.scrollTop}return new d(o,h,n.width,n.height)},getViewportBounds:function(t){var e=t.ownerDocument,n=e.defaultView,i=e.documentElement;return new d(0,0,n.innerWidth||i.clientWidth,n.innerHeight||i.clientHeight)},getOffset:function(t,e){return this.getBounds(t,e).getPoint()},getSize:function(t){return this.getBounds(t,!0).getSize()},isInvisible:function(t){return this.getSize(t).equals(new u(0,0))},isInView:function(t){return!this.isInvisible(t)&&this.getViewportBounds(t).intersects(this.getBounds(t,!0))}}},q={add:function(t,e){for(var n in e){var i=e[n];t.addEventListener?t.addEventListener(n,i,!1):t.attachEvent&&t.attachEvent("on"+n,i.bound=function(){i.call(t,window.event)})}},remove:function(t,e){for(var n in e){var i=e[n];t.removeEventListener?t.removeEventListener(n,i,!1):t.detachEvent&&t.detachEvent("on"+n,i.bound)}},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new o(e.pageX||e.clientX+document.documentElement.scrollLeft,e.pageY||e.clientY+document.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getOffset:function(t,e){return q.getPoint(t).subtract(R.getOffset(e||q.getTarget(t)))},preventDefault:function(t){t.preventDefault?t.preventDefault():t.returnValue=!1},stopPropagation:function(t){t.stopPropagation?t.stopPropagation():t.cancelBubble=!0},stop:function(t){q.stopPropagation(t),q.preventDefault(t)}};q.requestAnimationFrame=new function(){var t="equestAnimationFrame",e=window["r"+t]||window["webkitR"+t]||window["mozR"+t]||window["oR"+t]||window["msR"+t];e&&e(function(t){null==t&&(e=null)});var i,s=[],r=!0;return q.add(window,{focus:function(){r=!0},blur:function(){r=!1}}),function(t,a){return e?e(t,a):(s.push([t,a]),i||(i=setInterval(function(){for(var t=s.length-1;t>=0;t--){var e=s[t],i=e[0],a=e[1];(!a||("true"==n.getAttribute(a,"keepalive")||r)&&R.isInView(a))&&(s.splice(t,1),i(Date.now()))}},1e3/60)),void 0)}};var V=t.extend(e,{_class:"View",initialize:function Ce(t){this._scope=paper,this._project=paper.project,this._element=t;var e;if(this._id=t.getAttribute("id"),null==this._id&&t.setAttribute("id",this._id="view-"+Ce._id++),q.add(t,this._viewHandlers),n.hasAttribute(t,"resize")){var i=R.getOffset(t,!0),s=this;e=R.getViewportBounds(t).getSize().subtract(i),this._windowHandlers={resize:function(){R.isInvisible(t)||(i=R.getOffset(t,!0)),s.setViewSize(R.getViewportBounds(t).getSize().subtract(i))}},q.add(window,this._windowHandlers)}else e=new u(parseInt(t.getAttribute("width"),10),parseInt(t.getAttribute("height"),10)),e.isNaN()&&(e=R.getSize(t));if(t.width=e.width,t.height=e.height,n.hasAttribute(t,"stats")){this._stats=new Stats;var r=this._stats.domElement,a=r.style,i=R.getOffset(t);a.position="absolute",a.left=i.x+"px",a.top=i.y+"px",document.body.appendChild(r)}Ce._views.push(this),Ce._viewsById[this._id]=this,this._viewSize=new c(e.width,e.height,this,"setViewSize"),this._matrix=new f,this._zoom=1,Ce._focused||(Ce._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return this._project?(V._focused==this&&(V._focused=null),V._views.splice(V._views.indexOf(this),1),delete V._viewsById[this._id],this._project.view==this&&(this._project.view=null),q.remove(this._element,this._viewHandlers),q.remove(window,this._windowHandlers),this._element=this._project=null,this.detach("frame"),this._frameItems={},!0):!1
|
|
},_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=this._context,n=this._viewSize;return e.clearRect(0,0,n._width+1,n._height+1),this._project.draw(e,this._matrix),this._project._needsRedraw=!1,!0}},new function(){function t(t,e,n,i,s,r){for(var a,o=i;o;){if(o.responds(t)&&(a||(a=new X(t,e,n,i,s?n.subtract(s):null)),o.fire(t,a)&&(!r||a._stopped)))return!1;o=o.getParent()}return!0}function e(e,n,i,s,r){if(e._eventCounters[n]){var a=e._project,u=a.hitTest(s,{tolerance:a.options.hitTolerance||0,fill:!0,stroke:!0}),l=u&&u.item;if(l)return"mousemove"===n&&l!=o&&(r=s),"mousemove"===n&&h||t(n,i,s,l,r),l}}var n,i,s,r,a,o,h,u,l;return{_onMouseDown:function(t,o){var c=e(this,"mousedown",t,o);u=a==c&&Date.now()-l<300,r=a=c,n=i=s=o,h=r&&r.responds("mousedrag")},_onMouseUp:function(a,o){var c=e(this,"mouseup",a,o);h&&(i&&!i.equals(o)&&t("mousedrag",a,o,r,i),c!=r&&(s=o,t("mousemove",a,o,c,s))),c===r&&(l=Date.now(),(!u||t("doubleclick",a,n,c))&&t("click",a,n,c),u=!1),r=null,h=!1},_onMouseMove:function(n,a){r&&t("mousedrag",n,a,r,i);var h=e(this,"mousemove",n,a,s);i=s=a,h!==o&&(t("mouseleave",n,a,o),o=h,t("mouseenter",n,a,h))}}}),Z=t.extend({_class:"Event",initialize:function(t){this.event=t},preventDefault:function(){this._prevented=!0,q.preventDefault(this.event)},stopPropagation:function(){this._stopped=!0,q.stopPropagation(this.event)},stop:function(){this.stopPropagation(),this.preventDefault()},getModifiers:function(){return J.modifiers}}),G=Z.extend({_class:"KeyEvent",initialize:function(t,e,n,i){Z.call(this,i),this.type=t?"keydown":"keyup",this.key=e,this.character=n},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),J=new function(){function e(t,e,n,s){var r=String.fromCharCode(n),o=i[e]||r.toLowerCase(),h=t?"keydown":"keyup",u=V._focused,l=u&&u.isVisible()&&u._scope,c=l&&l._tool;a[o]=t,c&&c.responds(h)&&(c.fire(h,new G(t,o,r,s)),u&&u.draw(!0))}var n,i={8:"backspace",9:"tab",13:"enter",16:"shift",17:"control",18:"option",19:"pause",20:"caps-lock",27:"escape",32:"space",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",46:"delete",91:"command",93:"command",224:"command"},s=t.merge({shift:!1,control:!1,option:!1,command:!1,capsLock:!1,space:!1}),r={},a={};return q.add(document,{keydown:function(a){var o,h=a.which||a.keyCode,u=i[h];u?((o=t.camelize(u))in s&&(s[o]=!0),r[h]=0,e(!0,h,null,a)):n=h},keypress:function(t){if(null!=n){var i=t.which||t.keyCode;r[n]=i,e(!0,n,i,t),n=null}},keyup:function(n){var a,o=n.which||n.keyCode,h=i[o];h&&(a=t.camelize(h))in s&&(s[a]=!1),null!=r[o]&&(e(!1,o,r[o],n),delete r[o])}}),{modifiers:s,isDown:function(t){return!!a[t]}}},X=Z.extend({_class:"MouseEvent",initialize:function(t,e,n,i,s){Z.call(this,e),this.type=t,this.point=n,this.target=i,this.delta=s},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}});t.extend(e,{_class:"Palette",_events:["onChange"],initialize:function(e,n,i){var s=R.find(".palettejs-panel")||R.find("body").appendChild(R.create("div",{"class":"palettejs-panel"}));this._element=s.appendChild(R.create("table",{"class":"palettejs-pane"})),this._title=e,i||(i={});for(var r in this._components=n){var a=n[r];a instanceof W||(null==a.value&&(a.value=i[r]),a.name=r,a=n[r]=new W(a)),this._element.appendChild(a._element),a._palette=this,void 0===i[r]&&(i[r]=a.value)}this._values=t.each(i,function(e,s){var r=n[s];r&&t.define(i,s,{enumerable:!0,configurable:!0,get:function(){return r._value},set:function(t){r.setValue(t)}})}),window.paper&&paper.palettes.push(this)},reset:function(){for(var t in this._components)this._components[t].reset()},remove:function(){R.remove(this._element)}});var W=t.extend(e,{_class:"Component",_events:["onChange","onClick"],_types:{"boolean":{type:"checkbox",value:"checked"},string:{type:"text"},number:{type:"number",number:!0},button:{type:"button"},text:{tag:"div",value:"text"},slider:{type:"range",number:!0},list:{tag:"select",options:function(){R.removeChildren(this._inputItem),R.create(t.each(this._options,function(t){this.push("option",{value:t,text:t})},[]),this._inputItem)}}},initialize:function(e){this._type=e.type in this._types?e.type:"options"in e?"list":"onClick"in e?"button":typeof e.value,this._info=this._types[this._type]||{type:this._type};var n=this,i=!1;this._inputItem=R.create(this._info.tag||"input",{type:this._info.type,events:{change:function(){n.setValue(R.get(this,n._info.value||"value")),i&&(n._palette.fire("change",n,n.name,n._value),n.fire("change",n._value))},click:function(){n.fire("click")}}}),this._element=R.create("tr",[this._labelItem=R.create("td"),"td",[this._inputItem]]),t.each(e,function(t,e){this[e]=t},this),this._defaultValue=this._value,i=!0},getType:function(){return this._type},getLabel:function(){return this._label},setLabel:function(t){this._label=t,R.set(this._labelItem,"text",t+":")},getOptions:function(){return this._options},setOptions:function(t){this._options=t,this._info.options&&this._info.options.call(this)},getValue:function(){return this._value},setValue:function(t){var e=this._info.value||"value";R.set(this._inputItem,e,t),t=R.get(this._inputItem,e),this._value=this._info.number?parseFloat(t,10):t},getRange:function(){return[parseFloat(R.get(this._inputItem,"min")),parseFloat(R.get(this._inputItem,"max"))]},setRange:function(t,e){var n=Array.isArray(t)?t:[t,e];R.set(this._inputItem,{min:n[0],max:n[1]})},getMin:function(){return this.getRange()[0]},setMin:function(t){this.setRange(t,this.getMax())},getMax:function(){return this.getRange()[1]},setMax:function(t){this.setRange(this.getMin(),t)},getStep:function(){return parseFloat(R.get(this._inputItem,"step"))},setStep:function(t){R.set(this._inputItem,"step",t)},reset:function(){this.setValue(this._defaultValue)}}),Y=Z.extend({_class:"ToolEvent",_item:null,initialize:function(t,e,n){this.tool=t,this.type=e,this.event=n},_choosePoint:function(t,e){return t?t:e?e.clone():null},getPoint:function(){return this._choosePoint(this._point,this.tool._point)},setPoint:function(t){this._point=t},getLastPoint:function(){return this._choosePoint(this._lastPoint,this.tool._lastPoint)},setLastPoint:function(t){this._lastPoint=t},getDownPoint:function(){return this._choosePoint(this._downPoint,this.tool._downPoint)},setDownPoint:function(t){this._downPoint=t},getMiddlePoint:function(){return!this._middlePoint&&this.tool._lastPoint?this.tool._point.add(this.tool._lastPoint).divide(2):this.middlePoint},setMiddlePoint:function(t){this._middlePoint=t},getDelta:function(){return!this._delta&&this.tool._lastPoint?this.tool._point.subtract(this.tool._lastPoint):this._delta},setDelta:function(t){this._delta=t},getCount:function(){return/^mouse(down|up)$/.test(this.type)?this.tool._downCount:this.tool._count},setCount:function(t){this.tool[/^mouse(down|up)$/.test(this.type)?"downCount":"count"]=t},getItem:function(){if(!this._item){var t=this.tool._scope.project.hitTest(this.getPoint());if(t){for(var e=t.item,n=e._parent;/^(group|compound-path)$/.test(n._type);)e=n,n=n._parent;this._item=e}}return this._item},setItem:function(t){this._item=t},toString:function(){return"{ type: "+this.type+", point: "+this.getPoint()+", count: "+this.getCount()+", modifiers: "+this.getModifiers()+" }"}}),U=s.extend({_class:"Tool",_list:"tools",_reference:"_tool",_events:["onActivate","onDeactivate","onEditOptions","onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onKeyDown","onKeyUp"],initialize:function(t){s.call(this),this._firstMove=!0,this._count=0,this._downCount=0,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._minDistance>this._maxDistance&&(this._maxDistance=this._minDistance)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=this._maxDistance&&this._maxDistance<this._minDistance&&(this._minDistance=t)},getFixedDistance:function(){return this._minDistance==this._maxDistance?this._minDistance:null},setFixedDistance:function(t){this._minDistance=t,this._maxDistance=t},_updateEvent:function(t,e,n,i,s,r,a){if(!s){if(null!=n||null!=i){var o=null!=n?n:0,h=e.subtract(this._point),u=h.getLength();if(o>u)return!1;var l=null!=i?i:0;if(0!=l)if(u>l)e=this._point.add(h.normalize(l));else if(a)return!1}if(r&&e.equals(this._point))return!1}switch(this._lastPoint=s&&"mousemove"==t?e:this._point,this._point=e,t){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=s?0:this._count+1,!0},_fireEvent:function(t,e){var n=paper.project._removeSets;if(n){"mouseup"===t&&(n.mousedrag=null);var i=n[t];if(i){for(var s in i){var r=i[s];for(var a in n){var o=n[a];o&&o!=i&&delete o[r._id]}r.remove()}n[t]=null}}return this.responds(t)&&this.fire(t,new Y(this,t,e))},_onHandleEvent:function(t,e,n){paper=this._scope;var i=!1;switch(t){case"mousedown":this._updateEvent(t,e,null,null,!0,!1,!1),i=this._fireEvent(t,n);break;case"mousedrag":for(var s=!1,r=!1;this._updateEvent(t,e,this.minDistance,this.maxDistance,!1,s,r);)i=this._fireEvent(t,n)||i,s=!0,r=!0;break;case"mouseup":!e.equals(this._point)&&this._updateEvent("mousedrag",e,this.minDistance,this.maxDistance,!1,!1,!1)&&(i=this._fireEvent("mousedrag",n)),this._updateEvent(t,e,null,this.maxDistance,!1,!1,!1),i=this._fireEvent(t,n)||i,this._updateEvent(t,e,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(t,e,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)i=this._fireEvent(t,n)||i,this._firstMove=!1}return i}}),$={canvases:[],getCanvas:function(t,e){var n,i=void 0===e?t:new u(t,e),s=!0;n=this.canvases.length?this.canvases.pop():document.createElement("canvas");var r=n.getContext("2d");return r.save(),n.width===i.width&&n.height===i.height?s&&r.clearRect(0,0,i.width+1,i.height+1):(n.width=i.width,n.height=i.height),n},getContext:function(t,e){return this.getCanvas(t,e).getContext("2d")},release:function(t){var e=t.canvas?t.canvas:t;e.getContext("2d").restore(),this.canvases.push(e)}},K=new function(){function e(t,e,n){return.2989*t+.587*e+.114*n}function n(t,n,i,s){var r=s-e(t,n,i);f=t+r,g=n+r,v=i+r;var s=e(f,g,v),a=m(f,g,v),o=p(f,g,v);if(0>a){var h=s-a;f=s+(f-s)*s/h,g=s+(g-s)*s/h,v=s+(v-s)*s/h}if(o>255){var u=255-s,l=o-s;f=s+(f-s)*u/l,g=s+(g-s)*u/l,v=s+(v-s)*u/l}}function i(t,e,n){return p(t,e,n)-m(t,e,n)}function s(t,e,n,i){var s,r=[t,e,n],a=p(t,e,n),o=m(t,e,n);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,s=0===m(o,a)?1===p(o,a)?2:1:0,r[a]>r[o]?(r[s]=(r[s]-r[o])*i/(r[a]-r[o]),r[a]=i):r[s]=r[a]=0,r[o]=0,f=r[0],g=r[1],v=r[2]}function r(t){x.save();var e="darken"===t,n=!1;return x.fillStyle=e?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=t,x.globalCompositeOperation===t&&(x.fillStyle=e?"#a00":"#300",x.fillRect(0,0,1,1),n=x.getImageData(0,0,1,1).data[0]!==(e?170:51)),x.restore(),n}var a,o,h,u,l,c,d,_,f,g,v,m=Math.min,p=Math.max,y=Math.abs,w={multiply:function(){f=l*a/255,g=c*o/255,v=d*h/255},screen:function(){f=l+a-l*a/255,g=c+o-c*o/255,v=d+h-d*h/255},overlay:function(){f=128>l?2*l*a/255:255-2*(255-l)*(255-a)/255,g=128>c?2*c*o/255:255-2*(255-c)*(255-o)/255,v=128>d?2*d*h/255:255-2*(255-d)*(255-h)/255},"soft-light":function(){var t=a*l/255;f=t+l*(255-(255-l)*(255-a)/255-t)/255,t=o*c/255,g=t+c*(255-(255-c)*(255-o)/255-t)/255,t=h*d/255,v=t+d*(255-(255-d)*(255-h)/255-t)/255},"hard-light":function(){f=128>a?2*a*l/255:255-2*(255-a)*(255-l)/255,g=128>o?2*o*c/255:255-2*(255-o)*(255-c)/255,v=128>h?2*h*d/255:255-2*(255-h)*(255-d)/255},"color-dodge":function(){f=0===l?0:255===a?255:m(255,255*l/(255-a)),g=0===c?0:255===o?255:m(255,255*c/(255-o)),v=0===d?0:255===h?255:m(255,255*d/(255-h))},"color-burn":function(){f=255===l?255:0===a?0:p(0,255-255*(255-l)/a),g=255===c?255:0===o?0:p(0,255-255*(255-c)/o),v=255===d?255:0===h?0:p(0,255-255*(255-d)/h)},darken:function(){f=a>l?l:a,g=o>c?c:o,v=h>d?d:h},lighten:function(){f=l>a?l:a,g=c>o?c:o,v=d>h?d:h},difference:function(){f=l-a,0>f&&(f=-f),g=c-o,0>g&&(g=-g),v=d-h,0>v&&(v=-v)},exclusion:function(){f=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255,v=d+h*(255-d-d)/255},hue:function(){s(a,o,h,i(l,c,d)),n(f,g,v,e(l,c,d))},saturation:function(){s(l,c,d,i(a,o,h)),n(f,g,v,e(l,c,d))},luminosity:function(){n(l,c,d,e(a,o,h))},color:function(){n(a,o,h,e(l,c,d))},add:function(){f=m(l+a,255),g=m(c+o,255),v=m(d+h,255)},subtract:function(){f=p(l-a,0),g=p(c-o,0),v=p(d-h,0)},average:function(){f=(l+a)/2,g=(c+o)/2,v=(d+h)/2},negation:function(){f=255-y(255-a-l),g=255-y(255-o-c),v=255-y(255-h-d)}},x=$.getContext(1,1);this.nativeModes=r("multiply")&&t.each(w,function(t,e){this[e]=r(e)},{}),$.release(x),this.process=function(t,e,n,i,s){var r=e.canvas,m="normal"===t;if(m||this.nativeModes[t])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=i,m||(n.globalCompositeOperation=t),n.drawImage(r,s.x,s.y),n.restore();else{var p=w[t];if(!p)return;for(var y=n.getImageData(s.x,s.y,r.width,r.height),x=y.data,b=e.getImageData(0,0,r.width,r.height).data,C=0,S=x.length;S>C;C+=4){a=b[C],l=x[C],o=b[C+1],c=x[C+1],h=b[C+2],d=x[C+2],u=b[C+3],_=x[C+3],p();var P=u*i/255,M=1-P;x[C]=P*f+M*l,x[C+1]=P*g+M*c,x[C+2]=P*v+M*d,x[C+3]=u*i+M*_}n.putImageData(y,s.x,s.y)}}},Q=t.each({fillColor:["fill","color"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],font:["font-family","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","string"]},function(e,n){var i=t.capitalize(n),s=e[2];this[n]={type:e[1],property:n,attribute:e[0],toSVG:s,fromSVG:s&&t.each(s,function(t,e){this[t]=e},{}),get:"get"+i,set:"set"+i}},{}),te={href:"http://www.w3.org/1999/xlink",xlink:"http://www.w3.org/2000/xmlns"};return new function(){function e(t,e){for(var n in e){var i=e[n],s=te[n];"number"==typeof i&&(i=I.number(i)),s?t.setAttributeNS(s,n,i):t.setAttribute(n,i)}return t}function n(t,n){return e(document.createElementNS("http://www.w3.org/2000/svg",t),n)}function s(t,e,n){return t[e]._point.getDistance(t[n]._point)}function o(t,e){var n=t._matrix,i=n.getTranslation(),s={};if(e){n=n.shiftless();var r=n._inverseTransform(i);s.x=r.x,s.y=r.y,i=null}if(n.isIdentity())return s;var o=n.decompose();if(o&&!o.shearing){var h=[],u=o.rotation,l=o.scaling;i&&!i.isZero()&&h.push("translate("+I.point(i)+")"),a.isZero(l.x-1)&&a.isZero(l.y-1)||h.push("scale("+I.point(l)+")"),u&&h.push("rotate("+I.number(u)+")"),s.transform=h.join(" ")}else s.transform="matrix("+n.getValues().join(",")+")";return s}function h(t,e,n,i){var s="rect"===n?e[1]._point.add(e[2]._point).divide(2):"roundrect"===n?e[3]._point.add(e[4]._point).divide(2):"circle"===n||"ellipse"===n?e[1]._point:null,r=s&&s.subtract(i).getAngle()+90;return a.isZero(r||0)?0:r}function u(t,e){function n(t,n){var i=e[t],s=i.getNext(),r=e[n],a=r.getNext();return i._handleOut.isZero()&&s._handleIn.isZero()&&r._handleOut.isZero()&&a._handleIn.isZero()&&s._point.subtract(i._point).isColinear(a._point.subtract(r._point))}function i(t){var n=e[t],i=n.getNext(),s=n._handleOut,r=i._handleIn,o=a.KAPPA;if(s.isOrthogonal(r)){var h=n._point,u=i._point,l=new g(h,s,!0).intersect(new g(u,r,!0),!0);return l&&a.isZero(s.getLength()/l.subtract(h).getLength()-o)&&a.isZero(r.getLength()/l.subtract(u).getLength()-o)}}if(t.isPolygon())return 4===e.length&&t._closed&&n(0,2)&&n(1,3)?"rect":0===e.length?"empty":e.length>=3?t._closed?"polygon":"polyline":"line";if(t._closed){if(8===e.length&&i(0)&&i(2)&&i(4)&&i(6)&&n(1,5)&&n(3,7))return"roundrect";if(4===e.length&&i(0)&&i(1)&&i(2)&&i(3))return a.isZero(s(e,0,2)-s(e,1,3))?"circle":"ellipse"}return"path"}function c(t){for(var i=o(t),s=t._children,r=n("g",i),a=0,h=s.length;h>a;a++){var u=s[a],l=M(u);if(l)if(u.isClipMask()){var c=n("clipPath");c.appendChild(l),S(u,c,"clip"),e(r,{"clip-path":"url(#"+c.id+")"})}else r.appendChild(l)}return r}function d(t){var e=o(t,!0),i=t.getSize();return e.x-=i.width/2,e.y-=i.height/2,e.width=i.width,e.height=i.height,e.href=t.toDataURL(),n("image",e)}function _(t){var e,r=t._segments,a=t.getPosition(!0),o=u(t,r),c=h(t,r,o,a);switch(o){case"empty":return null;case"path":var d=t.getPathData();e=d&&{d:d};break;case"polyline":case"polygon":var _=[];for(i=0,l=r.length;l>i;i++)_.push(I.point(r[i]._point));e={points:_.join(" ")};break;case"rect":var g=s(r,0,3),v=s(r,0,1),m=r[1]._point.rotate(-c,a);e={x:m.x,y:m.y,width:g,height:v};break;case"roundrect":o="rect";var g=s(r,1,6),v=s(r,0,3),p=(g-s(r,0,7))/2,y=(v-s(r,1,2))/2,w=r[3]._point,x=r[4]._point,m=w.subtract(x.subtract(w).normalize(p)).rotate(-c,a);e={x:m.x,y:m.y,width:g,height:v,rx:p,ry:y};break;case"line":var b=r[0]._point,C=r[r.length-1]._point;e={x1:b.x,y1:b.y,x2:C.x,y2:C.y};break;case"circle":var S=s(r,0,2)/2;e={cx:a.x,cy:a.y,r:S};break;case"ellipse":var p=s(r,2,0)/2,y=s(r,3,1)/2;e={cx:a.x,cy:a.y,rx:p,ry:y}}return c&&(e.transform="rotate("+I.number(c)+","+I.point(a)+")",t._gradientMatrix=(new f).rotate(-c,a)),n(o,e)}function m(t){var e=o(t,!0),i=t.getPathData();return i&&(e.d=i),n("path",e)}function y(t){var e=o(t,!0),i=t.getSymbol(),s=C(i,"symbol");return definition=i.getDefinition(),bounds=definition.getBounds(),s||(s=n("symbol",{viewBox:I.rectangle(bounds)}),s.appendChild(M(definition)),S(i,s,"symbol")),e.href="#"+s.id,e.x+=bounds.x,e.y+=bounds.y,e.width=I.number(bounds.width),e.height=I.number(bounds.height),n("use",e)}function w(t,e){var i=C(t,"color");if(!i){var s,r=t.getGradient(),a=r._radial,o=e._gradientMatrix,h=t.getOrigin().transform(o),u=t.getDestination().transform(o);if(a){s={cx:h.x,cy:h.y,r:h.getDistance(u)};var l=t.getHighlight();l&&(l=l.transform(o),s.fx=l.x,s.fy=l.y)}else s={x1:h.x,y1:h.y,x2:u.x,y2:u.y};s.gradientUnits="userSpaceOnUse",i=n((a?"radial":"linear")+"Gradient",s);for(var c=r._stops,d=0,_=c.length;_>d;d++){var f=c[d],g=f._color,v=g.getAlpha();s={offset:f._rampPoint,"stop-color":g.toCSS(!0)},1>v&&(s["stop-opacity"]=v),i.appendChild(n("stop",s))}S(t,i,"color")}return"url(#"+i.id+")"}function x(t){var e=n("text",o(t,!0));return e.textContent=t._content,e}function b(n,i){var s={},r=n.getParent();return null!=n._name&&(s.id=n._name),t.each(Q,function(e){var i=e.get,a=e.type,o=n[i]();if(!r||!t.equals(r[i](),o)){if("color"===a&&null!=o){var h=o.getAlpha();1>h&&(s[e.attribute+"-opacity"]=h)}s[e.attribute]=null==o?"none":"number"===a?I.number(o):"color"===a?o.gradient?w(o,n):o.toCSS(!0):"array"===a?o.join(","):"lookup"===a?e.toSVG[o]:o}}),1===s.opacity&&delete s.opacity,null==n._visibility||n._visibility||(s.visibility="hidden"),delete n._gradientMatrix,e(i,s)}function C(t,e){return z||(z={ids:{},svgs:{}}),t&&z.svgs[e+"-"+t._id]}function S(t,e,n){z||C();var i=z.ids[n]=(z.ids[n]||0)+1;e.id=n+"-"+i,z.svgs[n+"-"+t._id]=e}function P(t){if(!z)return t;var e="svg"===t.nodeName.toLowerCase()&&t,i=null;for(var s in z.svgs)i||(e||(e=n("svg"),e.appendChild(t)),i=e.insertBefore(n("defs"),e.firstChild)),i.appendChild(z.svgs[s]);return z=null,e}function M(t){var e=k[t._type],n=e&&e(t,t._type);return n&&t._data&&n.setAttribute("data-paper-data",JSON.stringify(t._data)),n&&b(t,n)}var z,I=r.instance,k={group:c,layer:c,raster:d,path:_,"compound-path":m,"placed-symbol":y,"point-text":x};p.inject({exportSVG:function(){return P(M(this))}}),v.inject({exportSVG:function(){for(var t=this.layers,e=this.view.getSize(),i=n("svg",{x:0,y:0,width:e.width,height:e.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),s=0,r=t.length;r>s;s++)i.appendChild(M(t[s]));return P(i)}})},new function(){function e(t,e,n,i){var s=te[e],r=s?t.getAttributeNS(s,e):t.getAttribute(e);return"null"===r&&(r=null),null==r?i?null:n?"":0:n?r:parseFloat(r)}function n(t,n,i,s){return n=e(t,n,!1,s),i=e(t,i,!1,s),s&&null==n&&null==i?null:new o(n||0,i||0)}function i(t,n,i,s){return n=e(t,n,!1,s),i=e(t,i,!1,s),s&&null==n&&null==i?null:new u(n||0,i||0)}function s(t,e,n){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?x(t)||t:"lookup"===e?n[t]:t}function r(t,e){var n=t.childNodes,i="clippath"===e,s=i?new O:new y,r=s._project,a=r._currentStyle,o=[];i||(s._transformContent=!1,s=w(s,t),r._currentStyle=s._style.clone());for(var h=0,u=n.length;u>h;h++){var l,c=n[h];1==c.nodeType&&(l=C(c))&&(i&&l instanceof O?(o.push.apply(o,l.removeChildren()),l.remove()):l instanceof m||o.push(l))}return s.addChildren(o),i&&(s=w(s.reduce(),t)),r._currentStyle=a,(i||"defs"===e)&&(s.remove(),s=null),s}function a(t,e){var n=new A,i=t.points;n.moveTo(i.getItem(0));for(var s=1,r=i.numberOfItems;r>s;s++)n.lineTo(i.getItem(s));return"polygon"===e&&n.closePath(),n}function h(t){var e=t.getAttribute("d"),n=e.match(/m/gi).length>1?new O:new A;return n.setPathData(e),n}function l(t,i){for(var s=t.childNodes,r=[],a=0,o=s.length;o>a;a++){var h=s[a];1==h.nodeType&&r.push(w(new F,h))}var u,l,c,d="radialgradient"===i,_=new N(r,d);return d?(u=n(t,"cx","cy"),l=u.add(e(t,"r"),0),c=n(t,"fx","fy",!0)):(u=n(t,"x1","y1"),l=n(t,"x2","y2")),w(new B(_,u,l,c),t),null}function c(t,e,n,i){for(var s=(i.getAttribute(n)||"").split(/\)\s*/g),r=new f,a=0,o=s.length;o>a;a++){var h=s[a];if(!h)break;for(var u=h.split("("),l=u[0],c=u[1].split(/[\s,]+/g),d=0,_=c.length;_>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":r.concatenate(new f(c[0],c[2],c[1],c[3],c[4],c[5]));break;case"rotate":r.rotate(c[0],c[1],c[2]);break;case"translate":r.translate(c[0],c[1]);break;case"scale":r.scale(c);break;case"skewX":case"skewY":var e=Math.tan(c[0]*Math.PI/180),g="skewX"==l;r.shear(g?e:0,g?0:e)}}t.transform(r)}function _(t,e,n){var i=t["fill-opacity"===n?"getFillColor":"getStrokeColor"]();i&&i.setAlpha(parseFloat(e))}function g(e,n,i){var s=e.attributes[n],r=s&&s.value;if(!r){var a=t.camelize(n);r=e.style[a],r||i.node[a]===i.parent[a]||(r=i.node[a])}return r?"none"===r?null:r:void 0}function w(e,n){var i={node:R.getStyles(n)||{},parent:R.getStyles(n.parentNode)||{}};return t.each(P,function(s,r){var a=g(n,r,i);void 0!==a&&(e=t.pick(s(e,a,r,n,i),e))}),e}function x(t){var e=t&&t.match(/\((?:#|)([^)']+)/);return e&&M[e[1]]}function C(t,e){"string"==typeof t&&(t=(new DOMParser).parseFromString(t,"image/svg+xml"));var n=t.nodeName.toLowerCase(),i=S[n],s=i&&i(t,n),r=t.getAttribute("data-paper-data");return!s||s instanceof y||(s=w(s,t)),s&&r&&(s._data=JSON.parse(r)),e&&(M={}),s}var S={g:r,svg:r,clippath:r,polygon:a,polyline:a,path:h,lineargradient:l,radialgradient:l,image:function(t){var s=new b(e(t,"href",!0));return s.attach("load",function(){var e=i(t,"width","height");this.setSize(e),this.translate(n(t,"x","y").add(e.divide(2)))}),s},symbol:function(t,e){return new m(r(t,e),!0)},defs:r,use:function(t){var i=(e(t,"href",!0)||"").substring(1),s=M[i],r=n(t,"x","y");return s?s instanceof m?s.place(r):s.clone().translate(r):null},circle:function(t){return new A.Circle(n(t,"cx","cy"),e(t,"r"))},ellipse:function(t){var e=n(t,"cx","cy"),s=i(t,"rx","ry");return new A.Ellipse(new d(e.subtract(s),e.add(s)))},rect:function(t){var e=n(t,"x","y"),s=i(t,"width","height"),r=i(t,"rx","ry");return new A.Rectangle(new d(e,s),r)},line:function(t){return new A.Line(n(t,"x1","y1"),n(t,"x2","y2"))},text:function(t){var e=new j(n(t,"x","y",!1).add(n(t,"dx","dy",!1)));return e.setContent(t.textContent.trim()||""),e}},P=t.merge(t.each(Q,function(t){this[t.attribute]=function(e,n){e[t.set](s(n,t.type,t.fromSVG))}},{}),{id:function(t,e){M[e]=t,t.setName&&t.setName(e)},"clip-path":function(t,e){var n=x(e);if(n){if(n=n.clone(),n.setClipMask(!0),!(t instanceof y))return new y(n,t);t.insertChild(0,n)}},gradientTransform:c,transform:c,"fill-opacity":_,"stroke-opacity":_,visibility:function(t,e){t.setVisible("visible"===e)},"stop-color":function(t,e){t.setColor&&t.setColor(e)},"stop-opacity":function(t,e){t._color&&t._color.setAlpha(parseFloat(e))},offset:function(t,e){var n=e.match(/(.*)%$/);t.setRampPoint(n?n[1]/100:parseFloat(e))},viewBox:function(t,e,n,r,a){var o=new d(s(e,"array")),h=i(r,"width","height",!0);if(t instanceof y){var u=h?o.getSize().divide(h):1,l=(new f).translate(o.getPoint()).scale(u);t.transform(l.inverted())}else if(t instanceof m){h&&o.setSize(h);var c="visible"!=g(r,"overflow",a),_=t._definition;c&&!o.contains(_.getBounds())&&(c=new A.Rectangle(o).transform(_._matrix),c.setClipMask(!0),_.addChild(c))}}}),M={};p.inject({importSVG:function(t){return this.addChild(C(t,!0))}}),v.inject({importSVG:function(t){return this.activate(),C(t,!0)}})},paper=new(n.inject(t.merge(t.exports,{enumerable:!0,Base:t,Numerical:a,DomElement:R,DomEvent:q}))),"function"==typeof define&&define.amd&&define(paper),paper}; |