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

37 lines
No EOL
187 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*!
* Paper.js v0.9.25-HEAD - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
* Date: Sat Jan 30 16:37:43 2016 +0100
*
***
*
* Straps.js - Class inheritance library with support for bean-style accessors
*
* Copyright (c) 2006 - 2016 Juerg Lehni
* http://scratchdisk.com/
*
* 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=function(t,e){t=t||require("./node/window");var n=t.document,i=new function(){function t(t,e,n,r,a){function o(s,o){o=o||(o=u(e,s))&&(o.get?o:o.value),"string"==typeof o&&"#"===o[0]&&(o=t[o.substring(1)]||o);var l,d="function"==typeof o,_=o,f=a||d&&!o.base?o&&o.get?s in t:t[s]:null;a&&f||(d&&f&&(o.base=f),d&&r!==!1&&(l=s.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(h[l[3].toLowerCase()+l[4]]=l[2]),_&&!d&&_.get&&"function"==typeof _.get&&i.isPlainObject(_)||(_={value:_,writable:!0}),(u(t,s)||{configurable:!0}).configurable&&(_.configurable=!0,_.enumerable=n),c(t,s,_))}var h={};if(e){for(var l in e)e.hasOwnProperty(l)&&!s.test(l)&&o(l);for(var l in h){var d=h[l],_=t["set"+d],f=t["get"+d]||_&&t["is"+d];!f||r!==!0&&0!==f.length||o(l,{get:f,set:_})}}return t}function n(t,e,n){return t&&("length"in t&&!t.getLength&&"number"==typeof t.length?a:o).call(t,e,n=n||t),n}function r(t,e,n){for(var i in e)!e.hasOwnProperty(i)||n&&n[i]||(t[i]=e[i]);return t}var s=/^(statics|enumerable|beans|preserve)$/,a=[].forEach||function(t,e){for(var n=0,i=this.length;i>n;n++)t.call(e,this[n],n,this)},o=function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)},h=Object.create||function(t){return{__proto__:t}},u=Object.getOwnPropertyDescriptor||function(t,e){var n=t.__lookupGetter__&&t.__lookupGetter__(e);return n?{get:n,set:t.__lookupSetter__(e),enumerable:!0,configurable:!0}:t.hasOwnProperty(e)?{value:t[e],enumerable:!0,configurable:!0,writable:!0}:null},l=Object.defineProperty||function(t,e,n){return(n.get||n.set)&&t.__defineGetter__?(n.get&&t.__defineGetter__(e,n.get),n.set&&t.__defineSetter__(e,n.set)):t[e]=n.value,t},c=function(t,e,n){return delete t[e],l(t,e,n)};return t(function(){for(var t=0,e=arguments.length;e>t;t++)r(this,arguments[t])},{inject:function(e){if(e){var n=e.statics===!0?e:e.statics,i=e.beans,r=e.preserve;n!==e&&t(this.prototype,e,e.enumerable,i,r),t(this,n,!0,i,r)}for(var s=1,a=arguments.length;a>s;s++)this.inject(arguments[s]);return this},extend:function(){for(var e,n,i,r=this,s=0,a=arguments.length;a>s&&(!e||!n);s++)i=arguments[s],e=e||i.initialize,n=n||i.prototype;return e=e||function(){r.apply(this,arguments)},n=e.prototype=n||h(this.prototype),c(n,"constructor",{value:e,writable:!0,configurable:!0}),t(e,this,!0),arguments.length&&this.inject.apply(e,arguments),e.base=r,e}},!0).inject({inject:function(){for(var e=0,n=arguments.length;n>e;e++){var i=arguments[e];i&&t(this,i,i.enumerable,i.beans,i.preserve)}return this},extend:function(){var t=h(this);return t.inject.apply(t,arguments)},each:function(t,e){return n(this,t,e)},set:function(t){return r(this,t)},clone:function(){return new this.constructor(this)},statics:{each:n,create:h,define:c,describe:u,set:r,clone:function(t){return r(new t.constructor,t)},isPlainObject:function(t){var e=null!=t&&t.constructor;return e&&(e===Object||e===i||"Object"===e.name)},pick:function(t,n){return t!==e?t:n}}})};"undefined"!=typeof module&&(module.exports=i),i.inject({toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+i.each(this,function(t,e){if(!/^_/.test(e)){var n=typeof t;this.push(e+": "+("number"===n?o.instance.number(t):"string"===n?"'"+t+"'":t))}},[]).join(", ")+" }"},getClassName:function(){return this._class||""},exportJSON:function(t){return i.exportJSON(this,t)},toJSON:function(){return i.serialize(this)},_set:function(t,n,r){if(t&&(r||i.isPlainObject(t))){for(var s=Object.keys(t._filtering||t),a=0,o=s.length;o>a;a++){var h=s[a];if(!n||!n[h]){var u=t[h];u!==e&&(this[h]=u)}}return!0}},statics:{exports:{enumerable:!0},extend:function nt(){var t=nt.base.apply(this,arguments),e=t.prototype._class;return e&&!i.exports[e]&&(i.exports[e]=t),t},equals:function(t,e){if(t===e)return!0;if(t&&t.equals)return t.equals(e);if(e&&e.equals)return e.equals(t);if(t&&e&&"object"==typeof t&&"object"==typeof e){if(Array.isArray(t)&&Array.isArray(e)){var n=t.length;if(n!==e.length)return!1;for(;n--;)if(!i.equals(t[n],e[n]))return!1}else{var r=Object.keys(t),n=r.length;if(n!==Object.keys(e).length)return!1;for(;n--;){var s=r[n];if(!e.hasOwnProperty(s)||!i.equals(t[s],e[s]))return!1}}return!0}return!1},read:function(t,n,r,s){if(this===i){var a=this.peek(t,n);return t.__index++,a}var o=this.prototype,h=o._readIndex,u=n||h&&t.__index||0;s||(s=t.length-u);var l=t[u];return l instanceof this||r&&r.readNull&&null==l&&1>=s?(h&&(t.__index=u+1),l&&r&&r.clone?l.clone():l):(l=i.create(this.prototype),h&&(l.__read=!0),l=l.initialize.apply(l,u>0||s<t.length?Array.prototype.slice.call(t,u,u+s):t)||l,h&&(t.__index=u+l.__read,l.__read=e),l)},peek:function(t,e){return t[t.__index=e||t.__index||0]},remain:function(t){return t.length-(t.__index||0)},readAll:function(t,e,n){for(var i,r=[],s=e||0,a=t.length;a>s;s++)r.push(Array.isArray(i=t[s])?this.read(i,0,n):this.read(t,s,n,1));return r},readNamed:function(t,n,r,s,a){var o=this.getNamed(t,n),h=o!==e;if(h){var u=t._filtered;u||(u=t._filtered=i.create(t[0]),u._filtering=t[0]),u[n]=e}return this.read(h?[o]:t,r,s,a)},getNamed:function(t,n){var r=t[0];return t._hasObject===e&&(t._hasObject=1===t.length&&i.isPlainObject(r)),t._hasObject?n?r[n]:t._filtered||r:void 0},hasNamed:function(t,e){return!!this.getNamed(t,e)},isPlainValue:function(t,e){return this.isPlainObject(t)||Array.isArray(t)||e&&"string"==typeof t},serialize:function(t,e,n,r){e=e||{};var s,a=!r;if(a&&(e.formatter=new o(e.precision),r={length:0,definitions:{},references:{},add:function(t,e){var n="#"+t._id,i=this.references[n];if(!i){this.length++;var r=e.call(t),s=t._class;s&&r[0]!==s&&r.unshift(s),this.definitions[n]=r,i=this.references[n]=[n]}return i}}),t&&t._serialize){s=t._serialize(e,r);var h=t._class;!h||n||s._compact||s[0]===h||s.unshift(h)}else if(Array.isArray(t)){s=[];for(var u=0,l=t.length;l>u;u++)s[u]=i.serialize(t[u],e,n,r);n&&(s._compact=!0)}else if(i.isPlainObject(t)){s={};for(var c=Object.keys(t),u=0,l=c.length;l>u;u++){var d=c[u];s[d]=i.serialize(t[d],e,n,r)}}else s="number"==typeof t?e.formatter.number(t,e.precision):t;return a&&r.length>0?[["dictionary",r.definitions],s]:s},deserialize:function(t,e,n,r){var s=t,a=!n;if(n=n||{},Array.isArray(t)){var o=t[0],h="dictionary"===o;if(1==t.length&&/^#/.test(o))return n.dictionary[o];o=i.exports[o],s=[],r&&(n.dictionary=s);for(var u=o?1:0,l=t.length;l>u;u++)s.push(i.deserialize(t[u],e,n,h));if(o){var c=s;e?s=e(o,c):(s=i.create(o.prototype),o.apply(s,c))}}else if(i.isPlainObject(t)){s={},r&&(n.dictionary=s);for(var d in t)s[d]=i.deserialize(t[d],e,n)}return a&&t&&t.length&&"dictionary"===t[0][0]?s[1]:s},exportJSON:function(t,e){var n=i.serialize(t,e);return e&&e.asString===!1?n:JSON.stringify(n)},importJSON:function(t,e){return i.deserialize("string"==typeof t?JSON.parse(t):t,function(t,n){var r=e&&e.constructor===t,s=r?e:i.create(t.prototype),a=r?s._initialize||s._set:t;if(1===n.length&&s instanceof w&&(r||!(s instanceof b))){var o=n[0];i.isPlainObject(o)&&(o.insert=!1)}return a.apply(s,n),r&&(e=null),s})},splice:function(t,n,i,r){var s=n&&n.length,a=i===e;i=a?t.length:i,i>t.length&&(i=t.length);for(var o=0;s>o;o++)n[o]._index=i+o;if(a)return t.push.apply(t,n),[];var h=[i,r];n&&h.push.apply(h,n);for(var u=t.splice.apply(t,h),o=0,l=u.length;l>o;o++)u[o]._index=e;for(var o=i+s,l=t.length;l>o;o++)t[o]._index=o;return u},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 r={on:function(t,e){if("string"!=typeof t)i.each(t,function(t,e){this.on(e,t)},this);else{var n=this._eventTypes,r=n&&n[t],s=this._callbacks=this._callbacks||{};s=s[t]=s[t]||[],-1===s.indexOf(e)&&(s.push(e),r&&r.install&&1===s.length&&r.install.call(this,t))}return this},off:function(t,e){if("string"!=typeof t)return void i.each(t,function(t,e){this.off(e,t)},this);var n,r=this._eventTypes,s=r&&r[t],a=this._callbacks&&this._callbacks[t];return a&&(!e||-1!==(n=a.indexOf(e))&&1===a.length?(s&&s.uninstall&&s.uninstall.call(this,t),delete this._callbacks[t]):-1!==n&&a.splice(n,1)),this},once:function(t,e){return this.on(t,function(){e.apply(this,arguments),this.off(t,e)})},emit:function(t,e){var n=this._callbacks&&this._callbacks[t];if(!n)return!1;var i=[].slice.call(arguments,1);n=n.slice();for(var r=0,s=n.length;s>r;r++)if(n[r].apply(this,i)===!1){e&&e.stop&&e.stop();break}return!0},responds:function(t){return!(!this._callbacks||!this._callbacks[t])},attach:"#on",detach:"#off",fire:"#emit",_installEvents:function(t){var e=this._callbacks,n=t?"install":"uninstall";for(var i in e)if(e[i].length>0){var r=this._eventTypes,s=r&&r[i],a=s&&s[n];a&&a.call(this,i)}},statics:{inject:function it(t){var e=t._events;if(e){var n={};i.each(e,function(e,r){var s="string"==typeof e,a=s?e:r,o=i.capitalize(a),h=a.substring(2).toLowerCase();n[h]=s?{}:e,a="_"+a,t["get"+o]=function(){return this[a]},t["set"+o]=function(t){var e=this[a];e&&this.off(h,e),t&&this.on(h,t),this[a]=t}}),t._eventTypes=n}return it.base.apply(this,arguments)}}},s=i.extend({_class:"PaperScope",initialize:function rt(){paper=this,this.settings=new i({applyMatrix:!0,handleSize:4,hitTolerance:0}),this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=rt._id++,rt._scopes[this._id]=this;var e=rt.prototype;if(!this.support){var n=K.getContext(1,1);e.support={nativeDash:"setLineDash"in n||"mozDash"in n,nativeBlendModes:Q.nativeModes},K.release(n)}if(!this.agent){var r=t.navigator.userAgent.toLowerCase(),s=(/(darwin|win|mac|linux|freebsd|sunos)/.exec(r)||[])[0],a="darwin"===s?"mac":s,o=e.agent=e.browser={platform:a};a&&(o[a]=!0),r.replace(/(opera|chrome|safari|webkit|firefox|msie|trident|atom|node)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g,function(t,e,n,i,r){if(!o.chrome){var s="opera"===e?i:/^(node|trident)$/.test(e)?r:n;o.version=s,o.versionNumber=parseFloat(s),e="trident"===e?"msie":e,o.name=e,o[e]=!0}}),o.chrome&&delete o.webkit,o.atom&&delete o.chrome}},version:"0.9.25-HEAD",getView:function(){var t=this.project;return t&&t._view},getPaper:function(){return this},execute:function(t,e){paper.PaperScript.execute(t,this,e),Z.updateFocus()},install:function(t){var e=this;i.each(["project","view","tool"],function(n){i.define(t,n,{configurable:!0,get:function(){return e[n]}})});for(var n in this)!/^_/.test(n)&&this[n]&&(t[n]=this[n])},setup:function(t){return paper=this,this.project=new m(t),this},createCanvas:function(t,e){return K.getCanvas(t,e)},activate:function(){paper=this},clear:function(){for(var t=this.projects,e=this.tools,n=this.palettes,i=t.length-1;i>=0;i--)t[i].remove();for(var i=e.length-1;i>=0;i--)e[i].remove();for(var i=n.length-1;i>=0;i--)n[i].remove()},remove:function(){this.clear(),delete s._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 this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),a=i.extend(r,{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.emit("deactivate"),this._scope[this._reference]=this,this.emit("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null==this._index?!1:(i.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)},getView:function(){return this._scope.getView()}}),o=i.extend({initialize:function(t){this.precision=i.pick(t,5),this.multiplier=Math.pow(10,this.precision)},number:function(t){return this.precision<16?Math.round(t*this.multiplier)/this.multiplier:t},pair:function(t,e,n){return this.number(t)+(n||",")+this.number(e)},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)}});o.instance=new o;var h=new function(){function t(t,e,n){return e>t?e:t>n?n:t}var e=[[.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]],n=[[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]],i=Math.abs,r=Math.sqrt,s=Math.pow,a=1e-12,o=1.12e-16;return{TOLERANCE:1e-6,EPSILON:a,MACHINE_EPSILON:o,CURVETIME_EPSILON:4e-7,GEOMETRIC_EPSILON:2e-7,WINDING_EPSILON:2e-7,TRIGONOMETRIC_EPSILON:1e-7,CLIPPING_EPSILON:1e-7,KAPPA:4*(r(2)-1)/3,isZero:function(t){return t>=-a&&a>=t},clamp:t,integrate:function(t,i,r,s){for(var a=e[s-2],o=n[s-2],h=.5*(r-i),u=h+i,l=0,c=s+1>>1,d=1&s?o[l++]*t(u):0;c>l;){var _=h*a[l];d+=o[l++]*(t(u+_)+t(u-_))}return h*d},findRoot:function(t,e,n,r,s,a,o){for(var h=0;a>h;h++){var u=t(n),l=u/e(n),c=n-l;if(i(l)<o)return c;u>0?(s=n,n=r>=c?.5*(r+s):c):(r=n,n=c>=s?.5*(r+s):c)}return n},solveQuadratic:function(e,n,h,u,l,c){var d,_,f=0,g=l-a,v=c+a,p=1/0,m=n;if(n/=-2,_=n*n-e*h,0!==_&&i(_)<o){var y=s(i(e*n*h),1/3);if(1e-8>y){var w=s(10,i(Math.floor(Math.log(y)*Math.LOG10E)));isFinite(w)||(w=0),e*=w,n*=w,h*=w,_=n*n-e*h}}if(i(e)<a){if(i(m)<a)return i(h)<a?-1:0;d=-h/m}else if(_>=-o){var x=0>_?0:r(_),b=n+(0>n?-x:x);0===b?(d=h/e,p=-d):(d=b/e,p=h/b)}return isFinite(d)&&(null==l||d>g&&v>d)&&(u[f++]=null==l?d:t(d,l,c)),p!==d&&isFinite(p)&&(null==l||p>g&&v>p)&&(u[f++]=null==l?p:t(p,l,c)),f},solveCubic:function(e,n,u,l,c,d,_){var f,g,v,p=0;if(i(e)<a)e=n,g=u,v=l,f=1/0;else if(i(l)<a)g=n,v=u,f=0;else{var m,y,w,x,b,S,C,P=1+o;if(f=-(n/e)/3,C=e*f,g=C+n,v=g*f+u,w=(C+g)*f+v,y=v*f+l,x=y/e,b=s(i(x),1/3),S=0>x?-1:1,x=-w/e,b=x>0?1.3247179572*Math.max(b,r(x)):b,m=f-S*b,m!==f){do f=m,C=e*f,g=C+n,v=g*f+u,w=(C+g)*f+v,y=v*f+l,m=0===w?f:f-y/w/P;while(S*m>S*f);i(e)*f*f>i(l/f)&&(v=-l/f,g=(v-u)/f)}}var p=h.solveQuadratic(e,g,v,c,d,_);return isFinite(f)&&(0===p||f!==c[p-1])&&(null==d||f>d-a&&_+a>f)&&(c[p++]=null==d?f:t(f,d,_)),p}}},u={_id:1,_pools:{},get:function(t){if(t){var e=t._class,n=this._pools[e];return n||(n=this._pools[e]={_id:1}),n._id++}return this._id++}},l=i.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 this===t||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 l(this.x,this.y)},toString:function(){var t=o.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)]},getLength:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},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();h.isZero(n)&&this.getAngle(),this.set(this.x*n,this.y*n)}},getAngle:function(){return 180*this.getAngleInRadians.apply(this,arguments)/Math.PI},setAngle:function(t){this.setAngleInRadians.call(this,t*Math.PI/180)},getAngleInDegrees:"#getAngle",setAngleInDegrees:"#setAngle",getAngleInRadians:function(){if(arguments.length){var t=l.read(arguments),e=this.getLength()*t.getLength();if(h.isZero(e))return NaN;var n=this.dot(t)/e;return Math.acos(-1>n?-1:n>1?1:n)}return this.isZero()?this._angle||0:this._angle=Math.atan2(this.y,this.x)},setAngleInRadians:function(t){if(this._angle=t,!this.isZero()){var e=this.getLength();this.set(Math.cos(t)*e,Math.sin(t)*e)}},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3}},{beans:!1,getDirectedAngle:function(){var t=l.read(arguments);return 180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},getDistance:function(){var t=l.read(arguments),e=t.x-this.x,n=t.y-this.y,r=e*e+n*n,s=i.read(arguments);return s?r:Math.sqrt(r)},normalize:function(t){t===e&&(t=1);var n=this.getLength(),i=0!==n?t/n:0,r=new l(this.x*i,this.y*i);return i>=0&&(r._angle=this._angle),r},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),r=Math.cos(t);return n=new l(n.x*r-n.y*i,n.x*i+n.y*r),e?n.add(e):n},transform:function(t){return t?t._transformPoint(this):this},add:function(){var t=l.read(arguments);return new l(this.x+t.x,this.y+t.y)},subtract:function(){var t=l.read(arguments);return new l(this.x-t.x,this.y-t.y)},multiply:function(){var t=l.read(arguments);return new l(this.x*t.x,this.y*t.y)},divide:function(){var t=l.read(arguments);return new l(this.x/t.x,this.y/t.y)},modulo:function(){var t=l.read(arguments);return new l(this.x%t.x,this.y%t.y)},negate:function(){return new l(-this.x,-this.y)},isInside:function(){return f.read(arguments).contains(this)},isClose:function(){var t=l.read(arguments),e=i.read(arguments);return this.getDistance(t)<e},isCollinear:function(){var t=l.read(arguments);return l.isCollinear(this.x,this.y,t.x,t.y)},isColinear:"#isCollinear",isOrthogonal:function(){var t=l.read(arguments);return l.isOrthogonal(this.x,this.y,t.x,t.y)},isZero:function(){return h.isZero(this.x)&&h.isZero(this.y)},isNaN:function(){return isNaN(this.x)||isNaN(this.y)},dot:function(){var t=l.read(arguments);return this.x*t.x+this.y*t.y},cross:function(){var t=l.read(arguments);return this.x*t.y-this.y*t.x},project:function(){var t=l.read(arguments),e=t.isZero()?0:this.dot(t)/t.dot(t);return new l(t.x*e,t.y*e)},statics:{min:function(){var t=l.read(arguments),e=l.read(arguments);return new l(Math.min(t.x,e.x),Math.min(t.y,e.y))},max:function(){var t=l.read(arguments),e=l.read(arguments);return new l(Math.max(t.x,e.x),Math.max(t.y,e.y))},random:function(){return new l(Math.random(),Math.random())},isCollinear:function(t,e,n,i){return Math.abs(t*i-e*n)<=1e-7*Math.sqrt((t*t+e*e)*(n*n+i*i))},isOrthogonal:function(t,e,n,i){return Math.abs(t*n+e*i)<=1e-7*Math.sqrt((t*t+e*e)*(n*n+i*i))}}},i.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new l(e(this.x),e(this.y))}},{})),c=l.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)}}),d=i.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 d(this.width,this.height)},toString:function(){var t=o.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(){var t=d.read(arguments);return new d(this.width+t.width,this.height+t.height)},subtract:function(){var t=d.read(arguments);return new d(this.width-t.width,this.height-t.height)},multiply:function(){var t=d.read(arguments);return new d(this.width*t.width,this.height*t.height)},divide:function(){var t=d.read(arguments);return new d(this.width/t.width,this.height/t.height)},modulo:function(){var t=d.read(arguments);return new d(this.width%t.width,this.height%t.height)},negate:function(){return new d(-this.width,-this.height)},isZero:function(){return h.isZero(this.width)&&h.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new d(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new d(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new d(Math.random(),Math.random())}}},i.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new d(e(this.width),e(this.height))}},{})),_=d.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)}}),f=i.extend({_class:"Rectangle",_readIndex:!0,beans:!0,initialize:function(t,n,r,s){var a=typeof t,o=0;if("number"===a?(this.x=t,this.y=n,this.width=r,this.height=s,o=4):"undefined"===a||null===t?(this.x=this.y=this.width=this.height=0,o=null===t?1:0):1===arguments.length&&(Array.isArray(t)?(this.x=t[0],this.y=t[1],this.width=t[2],this.height=t[3],o=1):t.x!==e||t.width!==e?(this.x=t.x||0,this.y=t.y||0,this.width=t.width||0,this.height=t.height||0,o=1):t.from===e&&t.to===e&&(this.x=this.y=this.width=this.height=0,this._set(t),o=1)),!o){var h=l.readNamed(arguments,"from"),u=i.peek(arguments);if(this.x=h.x,this.y=h.y,u&&u.x!==e||i.hasNamed(arguments,"to")){var c=l.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.read(arguments);this.width=_.width,this.height=_.height}o=arguments.__index}this.__read&&(this.__read=o)},set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new f(this.x,this.y,this.width,this.height)},equals:function(t){var e=i.isPlainValue(t)?f.read(arguments):t;return e===this||e&&this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height||!1},toString:function(){var t=o.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(t){var e=t?l:c;return new e(this.x,this.y,this,"setPoint")},setPoint:function(){var t=l.read(arguments);this.x=t.x,this.y=t.y},getSize:function(t){var e=t?d:_;return new e(this.width,this.height,this,"setSize")},setSize:function(){var t=d.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){this._fixX!==e&&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){this._fixY!==e&&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(t){var e=t?l:c;return new e(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(){var t=l.read(arguments);return this.setCenterX(t.x),this.setCenterY(t.y),this},getArea:function(){return this.width*this.height},isEmpty:function(){return 0===this.width||0===this.height},contains:function(t){return t&&t.width!==e||4===(Array.isArray(t)?t:arguments).length?this._containsRectangle(f.read(arguments)):this._containsPoint(l.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(){var t=f.read(arguments);return 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(){var t=f.read(arguments);return 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(){var t=f.read(arguments),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),r=Math.min(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},unite:function(){var t=f.read(arguments),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),r=Math.max(this.y+this.height,t.y+t.height);return new f(e,n,i-e,r-n)},include:function(){var t=l.read(arguments),e=Math.min(this.x,t.x),n=Math.min(this.y,t.y),i=Math.max(this.x+this.width,t.x),r=Math.max(this.y+this.height,t.y);return new f(e,n,i-e,r-n)},expand:function(){var t=d.read(arguments),e=t.width,n=t.height;return new f(this.x-e/2,this.y-n/2,this.width+e,this.height+n)},scale:function(t,n){return this.expand(this.width*t-this.width,this.height*(n===e?t:n)-this.height)}},i.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 r=t[i?0:1],s=t[i?1:0],a="get"+r,o="get"+s,h="set"+r,u="set"+s,d="get"+n,_="set"+n;this[d]=function(t){var e=t?l:c;return new e(this[a](),this[o](),this,_)},this[_]=function(){var t=l.read(arguments);this[h](t.x),this[u](t.y)}},{beans:!0})),g=f.extend({initialize:function(t,e,n,i,r,s){this.set(t,e,n,i,!0),this._owner=r,this._setter=s},set:function(t,e,n,i,r){return this._x=t,this._y=e,this._width=n,this._height=i,r||this._owner[this._setter](this),this}},new function(){var t=f.prototype;return i.each(["x","y","width","height"],function(t){var e=i.capitalize(t),n="_"+t;this["get"+e]=function(){return this[n]},this["set"+e]=function(t){this[n]=t,this._dontNotify||this._owner[this._setter](this)}},i.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(e){var n="set"+e;this[n]=function(){this._dontNotify=!0,t[n].apply(this,arguments),this._dontNotify=!1,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))}}))}),v=i.extend({_class:"Matrix",initialize:function st(t){var e=arguments.length,n=!0;if(6===e?this.set.apply(this,arguments):1===e?t instanceof st?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 new Error("Unsupported matrix parameters")},set:function(t,e,n,i,r,s,a){return this._a=t,this._c=e,this._b=n,this._d=i,this._tx=r,this._ty=s,a||this._changed(),this},_serialize:function(t){return i.serialize(this.getValues(),t)},_changed:function(){var t=this._owner;t&&(t._applyMatrix?t.transform(null,!0):t._changed(9))},clone:function(){return new v(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=o.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(t){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,t||this._changed(),this},apply:function(t,e){var n=this._owner;return n?(n.transform(null,!0,i.pick(t,!0),e),this.isIdentity()):!1},translate:function(){var t=l.read(arguments),e=t.x,n=t.y;return this._tx+=e*this._a+n*this._b,this._ty+=e*this._c+n*this._d,this._changed(),this},scale:function(){var t=l.read(arguments),e=l.read(arguments,0,{readNull:!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._changed(),this},rotate:function(t){t*=Math.PI/180;var e=l.read(arguments,1),n=e.x,i=e.y,r=Math.cos(t),s=Math.sin(t),a=n-n*r+i*s,o=i-n*s-i*r,h=this._a,u=this._b,c=this._c,d=this._d;return this._a=r*h+s*u,this._b=-s*h+r*u,this._c=r*c+s*d,this._d=-s*c+r*d,this._tx+=a*h+o*u,this._ty+=a*c+o*d,this._changed(),this},shear:function(){var t=l.read(arguments),e=l.read(arguments,0,{readNull:!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._changed(),this},skew:function(){
var t=l.read(arguments),e=l.read(arguments,0,{readNull:!0}),n=Math.PI/180,i=new l(Math.tan(t.x*n),Math.tan(t.y*n));return this.shear(i,e)},append:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=t._a,a=t._b,o=t._c,h=t._d,u=t._tx,l=t._ty;return this._a=s*e+o*n,this._b=a*e+h*n,this._c=s*i+o*r,this._d=a*i+h*r,this._tx+=u*e+l*n,this._ty+=u*i+l*r,this._changed(),this},appended:function(t){return this.clone().append(t)},prepend:function(t){var e=this._a,n=this._b,i=this._c,r=this._d,s=this._tx,a=this._ty,o=t._a,h=t._b,u=t._c,l=t._d,c=t._tx,d=t._ty;return this._a=o*e+h*i,this._b=o*n+h*r,this._c=u*e+l*i,this._d=u*n+l*r,this._tx=o*s+h*a+c,this._ty=u*s+l*a+d,this._changed(),this},prepended:function(t){return this.clone().prepend(t)},invert:function(){var t=this._a,e=this._b,n=this._c,i=this._d,r=this._tx,s=this._ty,a=t*i-e*n,o=null;return a&&!isNaN(a)&&isFinite(r)&&isFinite(s)&&(this._a=i/a,this._b=-e/a,this._c=-n/a,this._d=t/a,this._tx=(e*s-i*r)/a,this._ty=(n*r-t*s)/a,o=this),o},inverted:function(){return this.clone().invert()},concatenate:"#append",preConcatenate:"#prepend",chain:"#appended",_shiftless:function(){return new v(this._a,this._c,this._b,this._d,0,0)},_orNullIfIdentity:function(){return this.isIdentity()?null:this},isIdentity:function(){return 1===this._a&&0===this._c&&0===this._b&&1===this._d&&0===this._tx&&0===this._ty},isInvertible:function(){var t=this._a*this._d-this._b*this._c;return t&&!isNaN(t)&&isFinite(this._tx)&&isFinite(this._ty)},isSingular:function(){return!this.isInvertible()},transform:function(t,e,n){return arguments.length<3?this._transformPoint(l.read(arguments)):this._transformCoordinates(t,e,n)},_transformPoint:function(t,e,n){var i=t.x,r=t.y;return e||(e=new l),e.set(i*this._a+r*this._b+this._tx,i*this._c+r*this._d+this._ty,n)},_transformCoordinates:function(t,e,n){for(var i=0,r=2*n;r>i;i+=2){var s=t[i],a=t[i+1];e[i]=s*this._a+a*this._b+this._tx,e[i+1]=s*this._c+a*this._d+this._ty}return e},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,r=n+t.height,s=[e,n,i,n,i,r,e,r];return this._transformCoordinates(s,s,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),r=i.slice(0,2),s=r.slice(),a=2;8>a;a++){var o=i[a],h=1&a;o<r[h]?r[h]=o:o>s[h]&&(s[h]=o)}return e||(e=new f),e.set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(l.read(arguments))},_inverseTransform:function(t,e,n){var i=this._a,r=this._b,s=this._c,a=this._d,o=this._tx,h=this._ty,u=i*a-r*s,c=null;if(u&&!isNaN(u)&&isFinite(o)&&isFinite(h)){var d=t.x-this._tx,_=t.y-this._ty;e||(e=new l),c=e.set((d*a-_*r)/u,(_*i-d*s)/u,n)}return c},decompose:function(){var t=this._a,e=this._b,n=this._c,i=this._d;if(h.isZero(t*i-e*n))return null;var r=Math.sqrt(t*t+e*e);t/=r,e/=r;var s=t*n+e*i;n-=t*s,i-=e*s;var a=Math.sqrt(n*n+i*i);return n/=a,i/=a,s/=a,e*n>t*i&&(t=-t,e=-e,s=-s,r=-r),{scaling:new l(r,a),rotation:180*-Math.atan2(e,t)/Math.PI,shearing:s}},getValues:function(){return[this._a,this._c,this._b,this._d,this._tx,this._ty]},getTranslation:function(){return new l(this._tx,this._ty)},getScaling:function(){return(this.decompose()||{}).scaling},getRotation:function(){return(this.decompose()||{}).rotation},applyToContext:function(t){this.isIdentity()||t.transform(this._a,this._c,this._b,this._d,this._tx,this._ty)}},i.each(["a","c","b","d","tx","ty"],function(t){var e=i.capitalize(t),n="_"+t;this["get"+e]=function(){return this[n]},this["set"+e]=function(t){this[n]=t,this._changed()}},{})),p=i.extend({_class:"Line",initialize:function(t,e,n,i,r){var s=!1;arguments.length>=4?(this._px=t,this._py=e,this._vx=n,this._vy=i,s=r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,s=n),s||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new l(this._px,this._py)},getVector:function(){return new l(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return p.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t,e){return p.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0,e)},getDistance:function(t){return Math.abs(p.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0))},isCollinear:function(t){return l.isCollinear(this._vx,this._vy,t._vx,t._vy)},isOrthogonal:function(t){return l.isOrthogonal(this._vx,this._vy,t._vx,t._vy)},statics:{intersect:function(t,e,n,i,r,s,a,o,u,c){u||(n-=t,i-=e,a-=r,o-=s);var d=n*o-i*a;if(!h.isZero(d)){var _=t-r,f=e-s,g=(a*f-o*_)/d,v=(n*f-i*_)/d,p=1e-12,m=-p,y=1+p;if(c||g>m&&y>g&&v>m&&y>v)return c||(g=0>=g?0:g>=1?1:g),new l(t+g*n,e+g*i)}},getSide:function(t,e,n,i,r,s,a,o){a||(n-=t,i-=e);var h=r-t,u=s-e,l=h*i-u*n;return 0!==l||o||(l=(h*n+h*n)/(n*n+i*i),l>=0&&1>=l&&(l=0)),0>l?-1:l>0?1:0},getSignedDistance:function(t,e,n,i,r,s,a){return a||(n-=t,i-=e),0===n?i>0?r-t:t-r:0===i?0>n?s-e:e-s:((r-t)*i-(s-e)*n)/Math.sqrt(n*n+i*i)}}}),m=a.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(t){a.call(this,!0),this._children=[],this._namedChildren={},this._activeLayer=null,this.symbols=[],this._currentStyle=new q(null,null,this),this._view=Z.create(this,t||K.getCanvas(1,1)),this._selectedItems={},this._selectedItemCount=0,this._updateVersion=0},_serialize:function(t,e){return i.serialize(this._children,t,!0,e)},_changed:function(t,e){if(1&t){this._needsUpdate=!0;var n=this._view;n&&!n._requested&&n._autoUpdate&&n.requestUpdate()}var i=this._changes;if(i&&e){var r=this._changesById,s=e._id,a=r[s];a?a.flags|=t:i.push(r[s]={item:e,flags:t})}},clear:function(){for(var t=this._children,e=t.length-1;e>=0;e--)t[e].remove();this.symbols=[]},isEmpty:function(){return 0===this._children.length},remove:function at(){return at.base.call(this)?(this._view&&this._view.remove(),!0):!1},getView:function(){return this._view},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.initialize(t)},getIndex:function(){return this._index},getOptions:function(){return this._scope.settings},getLayers:function(){return this._children},getActiveLayer:function(){return this._activeLayer||new b({project:this})},getSelectedItems:function(){var t=this._selectedItems,e=[];for(var n in t){var i=t[n];i.isInserted()?e.push(i):(this._selectedItemCount--,delete t[n])}return e},_updateSelection:function(t){var e=t._id,n=this._selectedItems;t._selected?n[e]!==t&&(this._selectedItemCount++,n[e]=t):n[e]===t&&(this._selectedItemCount--,delete n[e])},selectAll:function(){for(var t=this._children,e=0,n=t.length;n>e;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t=this._selectedItems;for(var e in t)t[e].setFullySelected(!1)},hitTest:function(){for(var t=l.read(arguments),e=M.getOptions(i.read(arguments)),n=this._children,r=n.length-1;r>=0;r--){var s=n[r]._hitTest(t,e);if(s)return s}return null},addLayer:function(t){return this.insertLayer(e,t)},insertLayer:function(t,e){return e instanceof b?(e._remove(!1,!0),i.splice(this._children,[e],t,0),e._setProject(this,!0),this._changes&&e._changed(5),this._activeLayer||(this._activeLayer=e)):e=null,e},_insertItem:function(t,n,i,r){return n=this.insertLayer(t,n)||(this._activeLayer||this._insertItem(e,new b(w.NO_INSERT),!0,!0)).insertChild(t,n,i),r&&n.activate&&n.activate(),n},getItems:function(t){return w._getItems(this,t)},getItem:function(t){return w._getItems(this,t,null,null,!0)[0]||null},importJSON:function(t){this.activate();var e=this._activeLayer;return i.importJSON(t,e&&e.isEmpty()&&e)},removeOn:function(t){var e=this._removeSets;if(e){"mouseup"===t&&(e.mousedrag=null);var n=e[t];if(n){for(var i in n){var r=n[i];for(var s in e){var a=e[s];a&&a!=n&&delete a[r._id]}r.remove()}e[t]=null}}},draw:function(t,e,n){this._updateVersion++,t.save(),e.applyToContext(t);for(var r=this._children,s=new i({offset:new l(0,0),pixelRatio:n,viewMatrix:e.isIdentity()?null:e,matrices:[new v],updateMatrix:!0}),a=0,o=r.length;o>a;a++)r[a].draw(t,s);if(t.restore(),this._selectedItemCount>0){t.save(),t.strokeWidth=1;var h=this._selectedItems,u=this._scope.settings.handleSize,c=this._updateVersion;for(var d in h)h[d]._drawSelection(t,e,u,h,c);t.restore()}}}),y=i.extend({_class:"Symbol",initialize:function(t,e){this._id=u.get(),this.project=paper.project,this.project.symbols.push(this),t&&this.setDefinition(t,e)},_serialize:function(t,e){return e.add(this,function(){return i.serialize([this._class,this._definition],t,!1,e)})},_changed:function(t){8&t&&w._clearBoundsCache(this),1&t&&this.project._changed(t)},getDefinition:function(){return this._definition},setDefinition:function(t,e){t._parentSymbol&&(t=t.clone()),this._definition&&(this._definition._parentSymbol=null),this._definition=t,t.remove(),t.setSelected(!1),e||t.setPosition(new l),t._parentSymbol=this,this._changed(9)},place:function(t){return new P(this,t)},clone:function(){return new y(this._definition.clone(!1))},equals:function(t){return t===this||t&&this.definition.equals(t.definition)||!1}}),w=i.extend(r,{statics:{extend:function ot(t){return t._serializeFields&&(t._serializeFields=new i(this.prototype._serializeFields,t._serializeFields)),ot.base.apply(this,arguments)},NO_INSERT:{insert:!1}},_class:"Item",_applyMatrix:!0,_canApplyMatrix:!0,_canScaleStroke:!1,_boundsSelected:!1,_selectChildren:!1,_serializeFields:{name:null,applyMatrix:null,matrix:new v,pivot:null,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}}},new function(){var t=["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"];return i.each(t,function(t){this._events[t]={install:function(t){this.getView()._countItemEvent(t,1)},uninstall:function(t){this.getView()._countItemEvent(t,-1)}}},{_events:{onFrame:{install:function(){this.getView()._animateItem(this,!0)},uninstall:function(){this.getView()._animateItem(this,!1)}},onLoad:{},onError:{}},statics:{_itemHandlers:t}})},{initialize:function(){},_initialize:function(t,n){var r=t&&i.isPlainObject(t),s=r&&t.internal===!0,a=this._matrix=new v,o=r&&t.project||paper.project;return this._id=s?null:u.get(),this._parent=this._index=null,this._applyMatrix=this._canApplyMatrix&&paper.settings.applyMatrix,n&&a.translate(n),a._owner=this,this._style=new q(o._currentStyle,this,o),s||r&&t.insert===!1?this._setProject(o):(r&&t.parent||o)._insertItem(e,this,!0,!0),r&&t!==w.NO_INSERT&&this._set(t,{internal:!0,insert:!0,project:!0,parent:!0},!0),r},_serialize:function(t,e){function n(n){for(var a in n){var o=s[a];i.equals(o,"leading"===a?1.2*n.fontSize:n[a])||(r[a]=i.serialize(o,t,"data"!==a,e))}}var r={},s=this;return n(this._serializeFields),this instanceof x||n(this._style._defaults),[this._class,r]},_changed:function(t){var n=this._parentSymbol,i=this._parent||n,r=this._project;8&t&&(this._bounds=this._position=this._decomposed=this._globalMatrix=e),i&&40&t&&w._clearBoundsCache(i),2&t&&w._clearBoundsCache(this),r&&r._changed(t,this),n&&n._changed(t)},set:function(t){return t&&this._set(t),this},getId:function(){return this._id},getName:function(){return this._name},setName:function(t){if(this._name&&this._removeNamed(),t===+t+"")throw new Error("Names consisting only of numbers are not supported.");var n=this._getOwner();if(t&&n){var i=n._children,r=n._namedChildren;(r[t]=r[t]||[]).push(this),t in i||(i[t]=this)}this._name=t||e,this._changed(128)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)}},i.each(["locked","visible","blendMode","opacity","guide"],function(t){var e=i.capitalize(t),t="_"+t;this["get"+e]=function(){return this[t]},this["set"+e]=function(e){e!=this[t]&&(this[t]=e,this._changed("_locked"===t?128:129))}},{}),{beans:!0,_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._selectChildren)for(var t=this._children,e=0,n=t.length;n>e;e++)if(t[e].isSelected())return!0;return this._selected},setSelected:function(t,e){if(!e&&this._selectChildren)for(var n=this._children,i=0,r=n.length;r>i;i++)n[i].setSelected(t);if((t=!!t)^this._selected){this._selected=t;var s=this._project;s&&(s._updateSelection(this),this._changed(129))}},_selected:!1,isFullySelected:function(){var t=this._children;if(t&&this._selected){for(var e=0,n=t.length;n>e;e++)if(!t[e].isFullySelected())return!1;return!0}return this._selected},setFullySelected:function(t){var e=this._children;if(e)for(var n=0,i=e.length;i>n;n++)e[n].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(129),this._parent&&this._parent._changed(1024))},_clipMask:!1,getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(t){var e=this._position,n=t?l:c;if(!e){var i=this._pivot;e=this._position=i?this._matrix._transformPoint(i):this.getBounds().getCenter(!0)}return new n(e.x,e.y,this,"setPosition")},setPosition:function(){this.translate(l.read(arguments).subtract(this.getPosition(!0)))},getPivot:function(t){var e=this._pivot;if(e){var n=t?l:c;e=new n(e.x,e.y,this,"setPivot")}return e},setPivot:function(){this._pivot=l.read(arguments,0,{clone:!0,readNull:!0}),this._position=e},_pivot:null},i.each(["bounds","strokeBounds","handleBounds","roughBounds","internalBounds","internalHandleBounds","internalRoughBounds"],function(t){var e="get"+i.capitalize(t),n=t.match(/^internal(.*)$/),r=n?"get"+n[1]:null;this[e]=function(n){var i=this._boundsGetter,s=!r&&("string"==typeof i?i:i&&i[e])||e,a=this._getCachedBounds(s,n,this,r);return"bounds"===t?new g(a.x,a.y,a.width,a.height,this,"setBounds"):a}},{beans:!0,_getBounds:function(t,e,n,i){var r=this._children;if(!r||0===r.length)return new f;w._updateBoundsCache(this,n);for(var s=1/0,a=-s,o=s,h=a,u=0,l=r.length;l>u;u++){var c=r[u];if(c._visible&&!c.isEmpty()){var d=c._getCachedBounds(t,e&&e.appended(c._matrix),n,i);s=Math.min(d.x,s),o=Math.min(d.y,o),a=Math.max(d.x+d.width,a),h=Math.max(d.y+d.height,h)}}return isFinite(s)?new f(s,o,a-s,h-o):new f},setBounds:function(){var t=f.read(arguments),e=this.getBounds(),n=new v,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)},_getCachedBounds:function(t,e,n,i){e=e&&e._orNullIfIdentity();var r=i?null:this._matrix._orNullIfIdentity(),s=(!e||e.equals(r))&&t;if(w._updateBoundsCache(this._parent||this._parentSymbol,n),s&&this._bounds&&this._bounds[s])return this._bounds[s].clone();var a=this._getBounds(i||t,e||r,n,i);if(s){this._bounds||(this._bounds={});var o=this._bounds[s]=a.clone();o._internal=!!i}return a},_getStrokeMatrix:function(t,e){return this.getStrokeScaling()?t:(e?this:this._parent).getViewMatrix().invert()._shiftless()},statics:{_updateBoundsCache:function(t,e){if(t){var n=e._id,i=t._boundsCache=t._boundsCache||{ids:{},list:[]};i.ids[n]||(i.list.push(e),i.ids[n]=e)}},_clearBoundsCache:function(t){var n=t._boundsCache;if(n){t._bounds=t._position=t._boundsCache=e;for(var i=0,r=n.list,s=r.length;s>i;i++){var a=r[i];a!==t&&(a._bounds=a._position=e,a._boundsCache&&w._clearBoundsCache(a))}}}}}),{beans:!0,_decompose:function(){return this._decomposed=this._matrix.decompose()},getRotation:function(){var t=this._decomposed||this._decompose();return t&&t.rotation},setRotation:function(t){var e=this.getRotation();if(null!=e&&null!=t){var n=this._decomposed;this.rotate(t-e),n.rotation=t,this._decomposed=n}},getScaling:function(t){var e=this._decomposed||this._decompose(),n=e&&e.scaling,i=t?l:c;return n&&new i(n.x,n.y,this,"setScaling")},setScaling:function(){var t=this.getScaling();if(t){var e=l.read(arguments,0,{clone:!0}),n=this._decomposed;this.scale(e.x/t.x,e.y/t.y),n.scaling=e,this._decomposed=n}},getMatrix:function(){return this._matrix},setMatrix:function(){var t=this._matrix;t.initialize.apply(t,arguments)},getGlobalMatrix:function(t){var e=this._globalMatrix,n=this._project._updateVersion;if(e&&e._updateVersion!==n&&(e=null),!e){e=this._globalMatrix=this._matrix.clone();var i=this._parent;i&&e.prepend(i.getGlobalMatrix(!0)),e._updateVersion=n}return t?e:e.clone()},getViewMatrix:function(){return this.getGlobalMatrix().prepend(this.getView()._matrix)},getApplyMatrix:function(){return this._applyMatrix},setApplyMatrix:function(t){(this._applyMatrix=this._canApplyMatrix&&!!t)&&this.transform(null,!0)},getTransformContent:"#getApplyMatrix",setTransformContent:"#setApplyMatrix"},{getProject:function(){return this._project},_setProject:function(t,e){if(this._project!==t){this._project&&this._installEvents(!1),this._project=t;for(var n=this._children,i=0,r=n&&n.length;r>i;i++)n[i]._setProject(t);e=!0}e&&this._installEvents(!0)},getView:function(){return this._project._view},_installEvents:function ht(t){ht.base.call(this,t);for(var e=this._children,n=0,i=e&&e.length;i>n;n++)e[n]._installEvents(t)},getLayer:function(){for(var t=this;t=t._parent;)if(t instanceof b)return t;return null},getParent:function(){return this._parent},setParent:function(t){return t.addChild(this)},_getOwner:"#getParent",getChildren:function(){return this._children},setChildren:function(t,e){this.removeChildren(),this.addChildren(t,e)},getFirstChild:function(){return this._children&&this._children[0]||null},getLastChild:function(){return this._children&&this._children[this._children.length-1]||null},getNextSibling:function(){var t=this._getOwner();return t&&t._children[this._index+1]||null},getPreviousSibling:function(){var t=this._getOwner();return t&&t._children[this._index-1]||null},getIndex:function(){return this._index},equals:function(t){return t===this||t&&this._class===t._class&&this._style.equals(t._style)&&this._matrix.equals(t._matrix)&&this._locked===t._locked&&this._visible===t._visible&&this._blendMode===t._blendMode&&this._opacity===t._opacity&&this._clipMask===t._clipMask&&this._guide===t._guide&&this._equals(t)||!1},_equals:function(t){return i.equals(this._children,t._children)},clone:function(t){var n=new this.constructor(w.NO_INSERT),i=this._children;i&&n.copyAttributes(this),n.copyContent(this),i||n.copyAttributes(this),(t===e||t)&&n.insertAbove(this);var r=this._name,s=this._parent;if(r&&s){for(var i=s._children,a=r,o=1;i[r];)r=a+" "+o++;r!==a&&n.setName(r)}return n},copyContent:function(t){for(var e=t._children,n=0,i=e&&e.length;i>n;n++)this.addChild(e[n].clone(!1),!0)},copyAttributes:function(t,e){this.setStyle(t._style);for(var n=["_locked","_visible","_blendMode","_opacity","_clipMask","_guide"],r=0,s=n.length;s>r;r++){var a=n[r];t.hasOwnProperty(a)&&(this[a]=t[a])}e||this._matrix.initialize(t._matrix),this.setApplyMatrix(t._applyMatrix),this.setPivot(t._pivot),this.setSelected(t._selected);var o=t._data,h=t._name;this._data=o?i.clone(o):null,h&&this.setName(h)},rasterize:function(t,n){var r=this.getStrokeBounds(),s=(t||this.getView().getResolution())/72,a=r.getTopLeft().floor(),o=r.getBottomRight().ceil(),h=new d(o.subtract(a)),u=new C(w.NO_INSERT);if(!h.isZero()){var l=K.getCanvas(h.multiply(s)),c=l.getContext("2d"),_=(new v).scale(s).translate(a.negate());c.save(),_.applyToContext(c),this.draw(c,new i({matrices:[_]})),c.restore(),u.setCanvas(l)}return u.transform((new v).translate(a.add(h.divide(2))).scale(1/s)),(n===e||n)&&u.insertAbove(this),u},contains:function(){return!!this._contains(this._matrix._inverseTransform(l.read(arguments)))},_contains:function(t){var e=this._children;if(e){for(var n=e.length-1;n>=0;n--)if(e[n].contains(t))return!0;return!1}return t.isInside(this.getInternalBounds())},isInside:function(){return f.read(arguments).contains(this.getBounds())},_asPathItem:function(){return new T.Rectangle({rectangle:this.getInternalBounds(),matrix:this._matrix,insert:!1})},intersects:function(t,e){return t instanceof w?this._asPathItem().getIntersections(t._asPathItem(),null,e,!0).length>0:!1},hitTest:function(){return this._hitTest(l.read(arguments),M.getOptions(i.read(arguments)))},_hitTest:function(t,e){function n(e,n){var r=f["get"+n]();return t.subtract(r).divide(u).length<=1?new M(e,_,{name:i.hyphenate(n),point:r}):void 0}if(this._locked||!this._visible||this._guide&&!e.guides||this.isEmpty())return null;var r=this._matrix,s=e._viewMatrix,a=s?s.appended(r):this.getGlobalMatrix().prepend(this.getView()._matrix),o=a.inverted(),h=Math.max(e.tolerance,1e-6),u=e._tolerancePadding=new d(T._getStrokePadding(h,o));if(t=r._inverseTransform(t),!t||!this._children&&!this.getInternalRoughBounds().expand(u.multiply(2))._containsPoint(t))return null;var l,c=!(e.guides&&!this._guide||e.selected&&!this._selected||e.type&&e.type!==i.hyphenate(this._class)||e["class"]&&!(this instanceof e["class"])),_=this;if(c&&(e.center||e.bounds)&&this._parent){var f=this.getInternalBounds();if(e.center&&(l=n("center","Center")),!l&&e.bounds)for(var g=["TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],v=0;8>v&&!l;v++)l=n("bounds",g[v])}e._viewMatrix=a,e._strokeMatrix=o;var p=!l&&this._children;if(p)for(var m=this._getChildHitTestOptions(e),v=p.length-1;v>=0&&!l;v--)l=p[v]._hitTest(t,m);return!l&&c&&(l=this._hitTestSelf(t,e)),l&&l.point&&(l.point=r.transform(l.point)),e._viewMatrix=s,l},_getChildHitTestOptions:function(t){return t},_hitTestSelf:function(t,e){return e.fill&&this.hasFill()&&this._contains(t)?new M("fill",this):void 0},matches:function(t,e){function n(t,e){for(var r in t)if(t.hasOwnProperty(r)){var s=t[r],a=e[r];if(i.isPlainObject(s)&&i.isPlainObject(a)){if(!n(s,a))return!1}else if(!i.equals(s,a))return!1}return!0}var r=typeof t;if("object"===r){for(var s in t)if(t.hasOwnProperty(s)&&!this.matches(s,t[s]))return!1;return!0}if("function"===r)return t(this);if("match"===t)return e(this);var a=/^(empty|editable)$/.test(t)?this["is"+i.capitalize(t)]():"type"===t?i.hyphenate(this._class):this[t];if("class"===t){if("function"==typeof e)return this instanceof e;a=this._class}if("function"==typeof e)return!!e(a);if(e){if(e.test)return e.test(a);if(i.isPlainObject(e))return n(e,a)}return i.equals(a,e)},getItems:function(t){return w._getItems(this,t,this._matrix)},getItem:function(t){return w._getItems(this,t,this._matrix,null,!0)[0]||null},statics:{_getItems:function ut(t,e,n,r,s){if(!r){var a="object"==typeof e&&e,o=a&&a.overlapping,h=a&&a.inside,u=o||h,l=u&&f.read([u]);r={items:[],recursive:a&&a.recursive!==!1,inside:!!h,overlapping:!!o,rect:l,path:o&&new T.Rectangle({rectangle:l,insert:!1})},a&&(e=i.set({},e,{recursive:!0,inside:!0,overlapping:!0}))}var c=t._children,d=r.items,l=r.rect;n=l&&(n||new v);for(var _=0,g=c&&c.length;g>_;_++){var p=c[_],m=n&&n.appended(p._matrix),y=!0;if(l){var u=p.getBounds(m);if(!l.intersects(u))continue;l.contains(u)||r.overlapping&&(u.contains(l)||r.path.intersects(p,m))||(y=!1)}if(y&&p.matches(e)&&(d.push(p),s))break;if(r.recursive!==!1&&ut(p,e,m,r,s),s&&d.length>0)break}return d}}},{importJSON:function(t){var e=i.importJSON(t,this);return e!==this?this.addChild(e):e},addChild:function(t,n){return this.insertChild(e,t,n)},insertChild:function(t,e,n){var i=e?this.insertChildren(t,[e],n):null;return i&&i[0]},addChildren:function(t,e){return this.insertChildren(this._children.length,t,e)},insertChildren:function(t,e,n,r){var s=this._children;if(s&&e&&e.length>0){e=Array.prototype.slice.apply(e);for(var a=e.length-1;a>=0;a--){var o=e[a];if(!r||o instanceof r){var h=o._parent===this&&o._index<t;o._remove(!1,!0)&&h&&t--}else e.splice(a,1)}i.splice(s,e,t,0);for(var u=this._project,l=u&&u._changes,a=0,c=e.length;c>a;a++){var o=e[a];o._parent=this,o._setProject(this._project,!0),o._name&&o.setName(o._name),l&&this._changed(5)}this._changed(11)}else e=null;return e},_insertItem:"#insertChild",insertAbove:function(t,e){var n=t&&t._getOwner();return n?n._insertItem(t._index+1,this,e):null},insertBelow:function(t,e){var n=t&&t._getOwner();return n?n._insertItem(t._index,this,e):null},sendToBack:function(){var t=this._getOwner();return t?t._insertItem(0,this):null},bringToFront:function(){var t=this._getOwner();return t?t._insertItem(e,this):null},appendTop:"#addChild",appendBottom:function(t){return this.insertChild(0,t)},moveAbove:"#insertAbove",moveBelow:"#insertBelow",copyTo:function(t){return t._insertItem(e,this.clone(!1))},reduce:function(t){var e=this._children;if(e&&1===e.length){var n=e[0].reduce(t);return this._parent?(n.insertAbove(this),this.remove()):n.remove(),n.copyAttributes(this),n}return this},_removeNamed:function(){var t=this._getOwner();if(t){var e=t._children,n=t._namedChildren,i=this._name,r=n[i],s=r?r.indexOf(this):-1;-1!==s&&(e[i]==this&&delete e[i],r.splice(s,1),r.length?e[i]=r[0]:delete n[i])}},_remove:function(t,e){var n=this._getOwner(),r=this._project,s=this._index;return n&&null!=s?(r._activeLayer===this&&(r._activeLayer=this.getNextSibling()||this.getPreviousSibling()),this._name&&this._removeNamed(),i.splice(n._children,null,s,1),this._installEvents(!1),t&&r._changes&&this._changed(5),e&&n._changed(11,this),this._parent=null,!0):!1},remove:function(){return this._remove(!0,!0)},replaceWith:function(t){var e=t&&t.insertBelow(this);return e&&this.remove(),e},removeChildren:function(t,e){if(!this._children)return null;t=t||0,e=i.pick(e,this._children.length);for(var n=i.splice(this._children,null,t,e-t),r=n.length-1;r>=0;r--)n[r]._remove(!0,!1);return n.length>0&&this._changed(11),n},clear:"#removeChildren",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(11)}},isEmpty:function(){return!this._children||0===this._children.length},isEditable:function(){for(var t=this;t;){if(!t._visible||t._locked)return!1;t=t._parent}return!0},hasFill:function(){return this.getStyle().hasFill()},hasStroke:function(){return this.getStyle().hasStroke()},hasShadow:function(){return this.getStyle().hasShadow()},_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),r=0,s=Math.min(n.length,i.length);s>r;r++)if(n[r]!=i[r])return n[r]._index<i[r]._index?1:-1;return 0},hasChildren:function(){return this._children&&this._children.length>0},isInserted:function(){return this._parent?this._parent.isInserted():!1},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},isSibling:function(t){return this._parent===t._parent},isGroupedWith:function(t){for(var e=this._parent;e;){if(e._parent&&/^(Group|Layer|CompoundPath)$/.test(e._class)&&t.isDescendant(e))return!0;e=e._parent}return!1}},i.each(["rotate","scale","shear","skew"],function(t){var e="rotate"===t;this[t]=function(){var n=(e?i:l).read(arguments),r=l.read(arguments,0,{readNull:!0});return this.transform((new v)[t](n,r||this.getPosition(!0)))}},{translate:function(){var t=new v;return this.transform(t.translate.apply(t,arguments))},transform:function(t,e,n,i){t&&t.isIdentity()&&(t=null);var r=this._matrix,s=(e||this._applyMatrix)&&(!r.isIdentity()||t||e&&n&&this._children);if(!t&&!s)return this;if(t&&r.prepend(t),s=s&&this._transformContent(r,n,i)){var a=this._pivot,o=this._style,h=o.getFillColor(!0),u=o.getStrokeColor(!0);a&&r._transformPoint(a,a,!0),h&&h.transform(r),u&&u.transform(r),r.reset(!0),i&&this._canApplyMatrix&&(this._applyMatrix=!0)}var l=this._bounds,c=this._position;this._changed(9);var d=l&&t&&t.decompose();if(d&&!d.shearing&&d.rotation%90===0){for(var _ in l){var f=l[_];(s||!f._internal)&&t._transformBounds(f,f)}var g=this._boundsGetter,f=l[g&&g.getBounds||g||"getBounds"];f&&(this._position=f.getCenter(!0)),this._bounds=l}else t&&c&&(this._position=t._transformPoint(c,c));return this},_transformContent:function(t,e,n){var i=this._children;if(i){for(var r=0,s=i.length;s>r;r++)i[r].transform(t,!0,e,n);return!0}},globalToLocal:function(){return this.getGlobalMatrix(!0)._inverseTransform(l.read(arguments))},localToGlobal:function(){return this.getGlobalMatrix(!0)._transformPoint(l.read(arguments))},parentToLocal:function(){return this._matrix._inverseTransform(l.read(arguments))},localToParent:function(){return this._matrix._transformPoint(l.read(arguments))},fitBounds:function(t,e){t=f.read(arguments);var n=this.getBounds(),i=n.height/n.width,r=t.height/t.width,s=(e?i>r:r>i)?t.width/n.width:t.height/n.height,a=new f(new l,new d(n.width*s,n.height*s));a.setCenter(t.getCenter()),this.setBounds(a)}}),{_setStyles:function(t){var e=this._style,n=e.getFillColor(),i=e.getStrokeColor(),r=e.getShadowColor();if(n&&(t.fillStyle=n.toCanvasStyle(t)),i){var s=e.getStrokeWidth();if(s>0){t.strokeStyle=i.toCanvasStyle(t),t.lineWidth=s;var a=e.getStrokeJoin(),o=e.getStrokeCap(),h=e.getMiterLimit();if(a&&(t.lineJoin=a),o&&(t.lineCap=o),h&&(t.miterLimit=h),paper.support.nativeDash){var u=e.getDashArray(),l=e.getDashOffset();u&&u.length&&("setLineDash"in t?(t.setLineDash(u),t.lineDashOffset=l):(t.mozDash=u,t.mozDashOffset=l))}}}if(r){var c=e.getShadowBlur();if(c>0){t.shadowColor=r.toCanvasStyle(t),t.shadowBlur=c;var d=this.getShadowOffset();t.shadowOffsetX=d.x,t.shadowOffsetY=d.y}}},draw:function(t,e,n){function i(t){return a?a.appended(t):t}var r=this._updateVersion=this._project._updateVersion;if(this._visible&&0!==this._opacity){var s=e.matrices,a=e.viewMatrix,o=this._matrix,h=s[s.length-1].appended(o);if(h.isInvertible()){s.push(h),e.updateMatrix&&(h._updateVersion=r,this._globalMatrix=h);var u,l,c,d=this._blendMode,_=this._opacity,f="normal"===d,g=Q.nativeModes[d],v=f&&1===_||e.dontStart||e.clip||(g||f&&1>_)&&this._canComposite(),p=e.pixelRatio||1;if(!v){var m=this.getStrokeBounds(i(h));if(!m.width||!m.height)return;c=e.offset,l=e.offset=m.getTopLeft().floor(),u=t,t=K.getContext(m.getSize().ceil().add(1).multiply(p)),1!==p&&t.scale(p,p)}t.save();var y=n?n.appended(o):this._canScaleStroke&&!this.getStrokeScaling(!0)&&i(h),w=!v&&e.clipItem,x=!y||w;if(v?(t.globalAlpha=_,g&&(t.globalCompositeOperation=d)):x&&t.translate(-l.x,-l.y),x&&(v?o:i(h)).applyToContext(t),w&&e.clipItem.draw(t,e.extend({clip:!0})),y){t.setTransform(p,0,0,p,0,0);var b=e.offset;b&&t.translate(-b.x,-b.y)}this._draw(t,e,y),t.restore(),s.pop(),e.clip&&!e.dontFinish&&t.clip(),v||(Q.process(d,t,u,_,l.subtract(c).multiply(p)),K.release(t),e.offset=c)}}},_isUpdated:function(t){var e=this._parent;if(e instanceof N)return e._isUpdated(t);var n=this._updateVersion===t;return!n&&e&&e._visible&&e._isUpdated(t)&&(this._updateVersion=t,n=!0),n},_drawSelection:function(t,e,n,i,r){if((this._drawSelected||this._boundsSelected)&&this._isUpdated(r)){var s,a=this.getSelectedColor(!0)||(s=this.getLayer())&&s.getSelectedColor(!0),o=e.appended(this.getGlobalMatrix(!0));if(t.strokeStyle=t.fillStyle=a?a.toCanvasStyle(t):"#009dec",this._drawSelected&&this._drawSelected(t,o,i),this._boundsSelected){var h=n/2,u=o._transformCorners(this.getInternalBounds());t.beginPath();for(var l=0;8>l;l++)t[0===l?"moveTo":"lineTo"](u[l],u[++l]);t.closePath(),t.stroke();for(var l=0;8>l;l++)t.fillRect(u[l]-h,u[++l]-h,n,n)}}},_canComposite:function(){return!1}},i.each(["down","drag","up","move"],function(t){this["removeOn"+i.capitalize(t)]=function(){var e={};return e[t]=!0,this.removeOn(e)}},{removeOn:function(t){for(var e in t)if(t[e]){var n="mouse"+e,i=this._project,r=i._removeSets=i._removeSets||{};r[n]=r[n]||{},r[n][this._id]=this}return this}})),x=w.extend({_class:"Group",_selectChildren:!0,_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||this.addChildren(Array.isArray(t)?t:arguments)},_changed:function lt(t){lt.base.call(this,t),1026&t&&(this._clipItem=e)},_getClipItem:function(){var t=this._clipItem;if(t===e){t=null;for(var n=this._children,i=0,r=n.length;r>i;i++)if(n[i]._clipMask){
t=n[i];break}this._clipItem=t}return t},isClipped:function(){return!!this._getClipItem()},setClipped:function(t){var e=this.getFirstChild();e&&e.setClipMask(t)},_draw:function(t,e){var n=e.clip,i=!n&&this._getClipItem();e=e.extend({clipItem:i,clip:!1}),n?(t.beginPath(),e.dontStart=e.dontFinish=!0):i&&i.draw(t,e.extend({clip:!0}));for(var r=this._children,s=0,a=r.length;a>s;s++){var o=r[s];o!==i&&o.draw(t,e)}}}),b=x.extend({_class:"Layer",initialize:function(){x.apply(this,arguments)},_getOwner:function(){return this._parent||null!=this._index&&this._project},isInserted:function ct(){return this._parent?ct.base.call(this):null!=this._index},activate:function(){this._project._activeLayer=this},_hitTestSelf:function(){return null}}),S=w.extend({_class:"Shape",_applyMatrix:!1,_canApplyMatrix:!1,_canScaleStroke:!0,_boundsSelected:!0,_serializeFields:{type:null,size:null,radius:null},initialize:function(t){this._initialize(t)},_equals:function(t){return this._type===t._type&&this._size.equals(t._size)&&i.equals(this._radius,t._radius)},copyContent:function(t){this.setType(t._type),this.setSize(t._size),this.setRadius(t._radius)},getType:function(){return this._type},setType:function(t){this._type=t},getShape:"#getType",setShape:"#setType",getSize:function(){var t=this._size;return new _(t.width,t.height,this,"setSize")},setSize:function(){var t=d.read(arguments);if(this._size){if(!this._size.equals(t)){var e=this._type,n=t.width,i=t.height;if("rectangle"===e){var r=d.min(this._radius,t.divide(2));this._radius.set(r.width,r.height)}else"circle"===e?(n=i=(n+i)/2,this._radius=n/2):"ellipse"===e&&this._radius.set(n/2,i/2);this._size.set(n,i),this._changed(9)}}else this._size=t.clone()},getRadius:function(){var t=this._radius;return"circle"===this._type?t:new _(t.width,t.height,this,"setRadius")},setRadius:function(t){var e=this._type;if("circle"===e){if(t===this._radius)return;var n=2*t;this._radius=t,this._size.set(n,n)}else if(t=d.read(arguments),this._radius){if(this._radius.equals(t))return;if(this._radius.set(t.width,t.height),"rectangle"===e){var n=d.max(this._size,t.multiply(2));this._size.set(n.width,n.height)}else"ellipse"===e&&this._size.set(2*t.width,2*t.height)}else this._radius=t.clone();this._changed(9)},isEmpty:function(){return!1},toPath:function(t){var n=new(T[i.capitalize(this._type)])({center:new l,size:this._size,radius:this._radius,insert:!1});return n.copyAttributes(this),paper.settings.applyMatrix&&n.setApplyMatrix(!0),(t===e||t)&&n.insertAbove(this),n},toShape:"#clone",_draw:function(t,e,n){var i=this._style,r=i.hasFill(),s=i.hasStroke(),a=e.dontFinish||e.clip,o=!n;if(r||s||a){var h=this._type,u=this._radius,l="circle"===h;if(e.dontStart||t.beginPath(),o&&l)t.arc(0,0,u,0,2*Math.PI,!0);else{var c=l?u:u.width,d=l?u:u.height,_=this._size,f=_.width,g=_.height;if(o&&"rectangle"===h&&0===c&&0===d)t.rect(-f/2,-g/2,f,g);else{var v=f/2,p=g/2,m=.44771525016920644,y=c*m,w=d*m,x=[-v,-p+d,-v,-p+w,-v+y,-p,-v+c,-p,v-c,-p,v-y,-p,v,-p+w,v,-p+d,v,p-d,v,p-w,v-y,p,v-c,p,-v+c,p,-v+y,p,-v,p-w,-v,p-d];n&&n.transform(x,x,32),t.moveTo(x[0],x[1]),t.bezierCurveTo(x[2],x[3],x[4],x[5],x[6],x[7]),v!==c&&t.lineTo(x[8],x[9]),t.bezierCurveTo(x[10],x[11],x[12],x[13],x[14],x[15]),p!==d&&t.lineTo(x[16],x[17]),t.bezierCurveTo(x[18],x[19],x[20],x[21],x[22],x[23]),v!==c&&t.lineTo(x[24],x[25]),t.bezierCurveTo(x[26],x[27],x[28],x[29],x[30],x[31])}}t.closePath()}a||!r&&!s||(this._setStyles(t),r&&(t.fill(i.getFillRule()),t.shadowBlur=0),s&&t.stroke())},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_getBounds:function(t,e,n,i){var r=new f(this._size).setCenter(0,0),s=this._style,a=s.hasStroke()&&/^get(?:Stroke|Rough)Bounds$/.test(t)&&s.getStrokeWidth();return e&&(r=e._transformBounds(r)),a?r.expand(T._getStrokePadding(a,this._getStrokeMatrix(e,i))):r}},new function(){function t(t,e,n){var i=t._radius;if(!i.isZero())for(var r=t._size.divide(2),s=0;4>s;s++){var a=new l(1&s?1:-1,s>1?1:-1),o=a.multiply(r),h=o.subtract(a.multiply(i)),u=new f(o,h);if((n?u.expand(n):u).contains(e))return h}}function e(t,e,n,i){var r=t.divide(e);return(!i||r.quadrant===i)&&r.subtract(r.normalize()).multiply(e).divide(n).length<=1}return{_contains:function n(e){if("rectangle"===this._type){var i=t(this,e);return i?e.subtract(i).divide(this._radius).getLength()<=1:n.base.call(this,e)}return e.divide(this.size).getLength()<=.5},_hitTestSelf:function i(n,r){var s=!1,a=this._style;if(r.stroke&&a.hasStroke()){var o=this._type,h=this._radius,u=a.getStrokeWidth(),l=r._tolerancePadding.add(T._getStrokePadding(u/2,!a.getStrokeScaling()&&r._strokeMatrix));if("rectangle"===o){var c=l.multiply(2),d=t(this,n,c);if(d)s=e(n.subtract(d),h,l,d.getQuadrant());else{var _=new f(this._size).setCenter(0,0),g=_.expand(c),v=_.expand(c.negate());s=g._containsPoint(n)&&!v._containsPoint(n)}}else s=e(n,h,l)}return s?new M("stroke",this):i.base.apply(this,arguments)}}},{statics:new function(){function t(t,e,n,r,s){var a=new S(i.getNamed(s));return a._type=t,a._size=n,a._radius=r,a.translate(e)}return{Circle:function(){var e=l.readNamed(arguments,"center"),n=i.readNamed(arguments,"radius");return t("circle",e,new d(2*n),n,arguments)},Rectangle:function(){var e=f.readNamed(arguments,"rectangle"),n=d.min(d.readNamed(arguments,"radius"),e.getSize(!0).divide(2));return t("rectangle",e.getCenter(!0),e.getSize(!0),n,arguments)},Ellipse:function(){var e=S._readEllipse(arguments),n=e.radius;return t("ellipse",e.center,n.multiply(2),n,arguments)},_readEllipse:function(t){var e,n;if(i.hasNamed(t,"radius"))e=l.readNamed(t,"center"),n=d.readNamed(t,"radius");else{var r=f.readNamed(t,"rectangle");e=r.getCenter(!0),n=r.getSize(!0).divide(2)}return{center:e,radius:n}}}}}),C=w.extend({_class:"Raster",_applyMatrix:!1,_canApplyMatrix:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{crossOrigin:null,source:null},initialize:function(t,n){this._initialize(t,n!==e&&l.read(arguments,1))||("string"==typeof t?this.setSource(t):this.setImage(t)),this._size||(this._size=new d,this._loaded=!1)},_equals:function(t){return this.getSource()===t.getSource()},copyContent:function(t){var e=t._image,n=t._canvas;if(e)this._setImage(e);else if(n){var i=K.getCanvas(t._size);i.getContext("2d").drawImage(n,0,0),this._setImage(i)}this._crossOrigin=t._crossOrigin},getSize:function(){var t=this._size;return new _(t?t.width:0,t?t.height:0,this,"setSize")},setSize:function(){var t=d.read(arguments);if(!t.equals(this._size))if(t.width>0&&t.height>0){var e=this.getElement();this._setImage(K.getCanvas(t)),e&&this.getContext(!0).drawImage(e,0,0,t.width,t.height)}else this._canvas&&K.release(this._canvas),this._size=t.clone()},getWidth:function(){return this._size?this._size.width:0},setWidth:function(t){this.setSize(t,this.getHeight())},getHeight:function(){return this._size?this._size.height:0},setHeight:function(t){this.setSize(this.getWidth(),t)},isEmpty:function(){var t=this._size;return!t||0===t.width&&0===t.height},getResolution:function(){var t=this._matrix,e=new l(0,0).transform(t),n=new l(1,0).transform(t).subtract(e),i=new l(0,1).transform(t).subtract(e);return new d(72/n.getLength(),72/i.getLength())},getPpi:"#getResolution",getImage:function(){return this._image},setImage:function(t){function e(t){var e=n.getView(),i=t&&t.type||"load";e&&n.responds(i)&&(paper=e._scope,n.emit(i,new U(t)))}var n=this;this._setImage(t),this._loaded?setTimeout(e,0):t&&H.add(t,{load:function(i){n._setImage(t),e(i)},error:e})},_setImage:function(t){this._canvas&&K.release(this._canvas),t&&t.getContext?(this._image=null,this._canvas=t,this._loaded=!0):(this._image=t,this._canvas=null,this._loaded=!!(t&&t.src&&t.complete)),this._size=new d(t?t.naturalWidth||t.width:0,t?t.naturalHeight||t.height:0),this._context=null,this._changed(521)},getCanvas:function(){if(!this._canvas){var t=K.getContext(this._size);try{this._image&&t.drawImage(this._image,0,0),this._canvas=t.canvas}catch(e){K.release(t)}}return this._canvas},setCanvas:"#setImage",getContext:function(t){return this._context||(this._context=this.getCanvas().getContext("2d")),t&&(this._image=null,this._changed(513)),this._context},setContext:function(t){this._context=t},getSource:function(){var t=this._image;return t&&t.src||this.toDataURL()},setSource:function(e){var i=this._crossOrigin,r=n.getElementById(e)||new t.Image;i&&(r.crossOrigin=i),this.setImage(r),r.src||(r.src=e)},getCrossOrigin:function(){return this._image&&this._image.crossOrigin||this._crossOrigin||""},setCrossOrigin:function(t){this._crossOrigin=t,this._image&&(this._image.crossOrigin=t)},getElement:function(){return this._canvas||this._loaded&&this._image}},{beans:!1,getSubCanvas:function(){var t=f.read(arguments),e=K.getContext(t.getSize());return e.drawImage(this.getCanvas(),t.x,t.y,t.width,t.height,0,0,t.width,t.height),e.canvas},getSubRaster:function(){var t=f.read(arguments),e=new C(w.NO_INSERT);return e._setImage(this.getSubCanvas(t)),e.translate(t.getCenter().subtract(this.getSize().divide(2))),e._matrix.prepend(this._matrix),e.insertAbove(this),e},toDataURL:function(){var t=this._image,e=t&&t.src;if(/^data:/.test(e))return e;var n=this.getCanvas();return n?n.toDataURL.apply(n,arguments):null},drawImage:function(t){var e=l.read(arguments,1);this.getContext(!0).drawImage(t,e.x,e.y)},getAverageColor:function(t){var e,n;t?t instanceof A?(n=t,e=t.getBounds()):t.width?e=new f(t):t.x&&(e=new f(t.x-.5,t.y-.5,1,1)):e=this.getBounds();var r=32,s=Math.min(e.width,r),a=Math.min(e.height,r),o=C._sampleContext;o?o.clearRect(0,0,r+1,r+1):o=C._sampleContext=K.getContext(new d(r)),o.save();var h=(new v).scale(s/e.width,a/e.height).translate(-e.x,-e.y);h.applyToContext(o),n&&n.draw(o,new i({clip:!0,matrices:[h]})),this._matrix.applyToContext(o);var u=this.getElement(),l=this._size;u&&o.drawImage(u,-l.width/2,-l.height/2),o.restore();for(var c=o.getImageData(.5,.5,Math.ceil(s),Math.ceil(a)).data,_=[0,0,0],g=0,p=0,m=c.length;m>p;p+=4){var y=c[p+3];g+=y,y/=255,_[0]+=c[p]*y,_[1]+=c[p+1]*y,_[2]+=c[p+2]*y}for(var p=0;3>p;p++)_[p]/=g;return g?j.read(_):null},getPixel:function(){var t=l.read(arguments),e=this.getContext().getImageData(t.x,t.y,1,1).data;return new j("rgb",[e[0]/255,e[1]/255,e[2]/255],e[3]/255)},setPixel:function(){var t=l.read(arguments),e=j.read(arguments),n=e._convert("rgb"),i=e._alpha,r=this.getContext(!0),s=r.createImageData(1,1),a=s.data;a[0]=255*n[0],a[1]=255*n[1],a[2]=255*n[2],a[3]=null!=i?255*i:255,r.putImageData(s,t.x,t.y)},createImageData:function(){var t=d.read(arguments);return this.getContext().createImageData(t.width,t.height)},getImageData:function(){var t=f.read(arguments);return t.isEmpty()&&(t=new f(this._size)),this.getContext().getImageData(t.x,t.y,t.width,t.height)},setImageData:function(t){var e=l.read(arguments,1);this.getContext(!0).putImageData(t,e.x,e.y)},_getBounds:function(t,e){var n=new f(this._size).setCenter(0,0);return e?e._transformBounds(n):n},_hitTestSelf:function(t){if(this._contains(t)){var e=this;return new M("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}}),P=w.extend({_class:"PlacedSymbol",_applyMatrix:!1,_canApplyMatrix:!1,_boundsGetter:{getBounds:"getStrokeBounds"},_boundsSelected:!0,_serializeFields:{symbol:null},initialize:function(t,n){this._initialize(t,n!==e&&l.read(arguments,1))||this.setSymbol(t instanceof y?t:new y(t))},_equals:function(t){return this._symbol===t._symbol},copyContent:function(t){this.setSymbol(t._symbol)},getSymbol:function(){return this._symbol},setSymbol:function(t){this._symbol=t,this._changed(9)},isEmpty:function(){return this._symbol._definition.isEmpty()},_getBounds:function(t,e,n,i){var r=this.symbol._definition;return r._getCachedBounds(t,e&&e.appended(r._matrix),n,i)},_hitTestSelf:function(t,e){var n=this._symbol._definition._hitTest(t,e);return n&&(n.item=this),n},_draw:function(t,e){this.symbol._definition.draw(t,e)}}),M=i.extend({_class:"HitResult",initialize:function(t,e,n){this.type=t,this.item=e,n&&(n.enumerable=!0,this.inject(n))},statics:{getOptions:function(t){return new i({type:null,tolerance:paper.settings.hitTolerance,fill:!t,stroke:!t,segments:!t,handles:!1,ends:!1,center:!1,bounds:!1,guides:!1,selected:!1},t)}}}),I=i.extend({_class:"Segment",beans:!0,initialize:function(t,n,i,r,s,a){var o,h,u,l=arguments.length;0===l||(1===l?t&&"point"in t?(o=t.point,h=t.handleIn,u=t.handleOut):o=t:2===l&&"number"==typeof t?o=arguments:3>=l?(o=t,h=n,u=i):(o=t!==e?[t,n]:null,h=i!==e?[i,r]:null,u=s!==e?[s,a]:null)),new z(o,this,"_point"),new z(h,this,"_handleIn"),new z(u,this,"_handleOut")},_serialize:function(t){return i.serialize(this.hasHandles()?[this._point,this._handleIn,this._handleOut]:this._point,t,!0)},_changed:function(t){var e=this._path;if(e){var n,i=e._curves,r=this._index;i&&(t&&t!==this._point&&t!==this._handleIn||!(n=r>0?i[r-1]:e._closed?i[i.length-1]:null)||n._changed(),t&&t!==this._point&&t!==this._handleOut||!(n=i[r])||n._changed()),e._changed(25)}},getPoint:function(){return this._point},setPoint:function(){var t=l.read(arguments);this._point.set(t.x,t.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(){var t=l.read(arguments);this._handleIn.set(t.x,t.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(){var t=l.read(arguments);this._handleOut.set(t.x,t.y)},hasHandles:function(){return!this._handleIn.isZero()||!this._handleOut.isZero()},clearHandles:function(){this._handleIn.set(0,0),this._handleOut.set(0,0)},_selectionState:0,isSelected:function(t){var e=this._selectionState;return t?t===this._point?!!(4&e):t===this._handleIn?!!(1&e):t===this._handleOut?!!(2&e):!1:!!(7&e)},setSelected:function(t,e){var n=this._path,t=!!t,i=this._selectionState,r=i,s=e?e===this._point?4:e===this._handleIn?1:e===this._handleOut?2:0:7;t?i|=s:i&=~s,this._selectionState=i,n&&i!==r&&(n._updateSelection(this,r,i),n._changed(129))},getIndex:function(){return this._index!==e?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var t=this._path,e=this._index;return t?(e>0&&!t._closed&&e===t._segments.length-1&&e--,t.getCurves()[e]||null):null},getLocation:function(){var t=this.getCurve();return t?new O(t,this===t._segment1?0:1):null},getNext:function(){var t=this._path&&this._path._segments;return t&&(t[this._index+1]||this._path._closed&&t[0])||null},smooth:function(t,n,i){var r=t||{},s=r.type,a=r.factor,o=this.getPrevious(),h=this.getNext(),u=(o||this)._point,c=this._point,d=(h||this)._point,_=u.getDistance(c),f=c.getDistance(d);if(s&&"catmull-rom"!==s){if("geometric"!==s)throw new Error("Smoothing method '"+s+"' not supported.");if(o&&h){var g=u.subtract(d),v=a===e?.4:a,p=v*_/(_+f);n||this.setHandleIn(g.multiply(p)),i||this.setHandleOut(g.multiply(p-v))}}else{var m=a===e?.5:a,y=Math.pow(_,m),w=y*y,x=Math.pow(f,m),b=x*x;if(!n&&o){var S=2*b+3*x*y+w,C=3*x*(x+y);this.setHandleIn(0!==C?new l((b*u._x+S*c._x-w*d._x)/C-c._x,(b*u._y+S*c._y-w*d._y)/C-c._y):new l)}if(!i&&h){var S=2*w+3*y*x+b,C=3*y*(y+x);this.setHandleOut(0!==C?new l((w*d._x+S*c._x-b*u._x)/C-c._x,(w*d._y+S*c._y-b*u._y)/C-c._y):new l)}}},getPrevious:function(){var t=this._path&&this._path._segments;return t&&(t[this._index-1]||this._path._closed&&t[t.length-1])||null},isFirst:function(){return 0===this._index},isLast:function(){var t=this._path;return t&&this._index===t._segments.length-1||!1},reverse:function(){var t=this._handleIn,e=this._handleOut,n=t._x,i=t._y;t.set(e._x,e._y),e.set(n,i)},reversed:function(){return new I(this._point,this._handleOut,this._handleIn)},remove:function(){return this._path?!!this._path.removeSegment(this._index):!1},clone:function(){return new I(this._point,this._handleIn,this._handleOut)},equals:function(t){return t===this||t&&this._class===t._class&&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(", ")+" }"},transform:function(t){this._transformCoordinates(t,new Array(6),!0),this._changed()},_transformCoordinates:function(t,e,n){var i=this._point,r=n&&this._handleIn.isZero()?null:this._handleIn,s=n&&this._handleOut.isZero()?null:this._handleOut,a=i._x,o=i._y,h=2;return e[0]=a,e[1]=o,r&&(e[h++]=r._x+a,e[h++]=r._y+o),s&&(e[h++]=s._x+a,e[h++]=s._y+o),t&&(t._transformCoordinates(e,e,h/2),a=e[0],o=e[1],n?(i._x=a,i._y=o,h=2,r&&(r._x=e[h++]-a,r._y=e[h++]-o),s&&(s._x=e[h++]-a,s._y=e[h++]-o)):(r||(e[h++]=a,e[h++]=o),s||(e[h++]=a,e[h++]=o))),e}}),z=l.extend({initialize:function(t,n,i){var r,s,a;if(t)if((r=t[0])!==e)s=t[1];else{var o=t;(r=o.x)===e&&(o=l.read(arguments),r=o.x),s=o.y,a=o.selected}else r=s=0;this._x=r,this._y=s,this._owner=n,n[i]=this,a&&this.setSelected(!0)},set:function(t,e){return this._x=t,this._y=e,this._owner._changed(this),this},_serialize:function(t){var e=t.formatter,n=e.number(this._x),i=e.number(this._y);return this.isSelected()?{x:n,y:i,selected:!0}:[n,i]},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 h.isZero(this._x)&&h.isZero(this._y)},setSelected:function(t){this._owner.setSelected(t,this)},isSelected:function(){return this._owner.isSelected(this)}}),k=i.extend({_class:"Curve",initialize:function(t,e,n,i,r,s,a,o){var h,u,l,c,d,_,f=arguments.length;3===f?(this._path=t,h=e,u=n):0===f?(h=new I,u=new I):1===f?"segment1"in t?(h=new I(t.segment1),u=new I(t.segment2)):"point1"in t?(l=t.point1,d=t.handle1,_=t.handle2,c=t.point2):Array.isArray(t)&&(l=[t[0],t[1]],c=[t[6],t[7]],d=[t[2]-t[0],t[3]-t[1]],_=[t[4]-t[6],t[5]-t[7]]):2===f?(h=new I(t),u=new I(e)):4===f?(l=t,d=e,_=n,c=i):8===f&&(l=[t,e],c=[a,o],d=[n-t,i-e],_=[r-a,s-o]),this._segment1=h||new I(l,null,d),this._segment2=u||new I(c,_,null)},_serialize:function(t){return i.serialize(this.hasHandles()?[this.getPoint1(),this.getHandle1(),this.getHandle2(),this.getPoint2()]:[this.getPoint1(),this.getPoint2()],t,!0)},_changed:function(){this._length=this._bounds=e},clone:function(){return new k(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(", ")+" }"},remove:function(){var t=!1;if(this._path){var e=this._segment2,n=e._handleOut;t=e.remove(),t&&this._segment1._handleOut.set(n.x,n.y)}return t},getPoint1:function(){return this._segment1._point},setPoint1:function(){var t=l.read(arguments);this._segment1._point.set(t.x,t.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(){var t=l.read(arguments);this._segment2._point.set(t.x,t.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(){var t=l.read(arguments);this._segment1._handleOut.set(t.x,t.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(){var t=l.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},isFirst:function(){return 0===this._segment1._index},isLast:function(){var t=this._path;return t&&this._segment1._index===t._curves.length-1||!1},isSelected:function(){return this.getPoint1().isSelected()&&this.getHandle2().isSelected()&&this.getHandle2().isSelected()&&this.getPoint2().isSelected()},setSelected:function(t){this.getPoint1().setSelected(t),this.getHandle1().setSelected(t),this.getHandle2().setSelected(t),this.getPoint2().setSelected(t)},getValues:function(t){return k.getValues(this._segment1,this._segment2,t)},getPoints:function(){for(var t=this.getValues(),e=[],n=0;8>n;n+=2)e.push(new l(t[n],t[n+1]));return e},getLength:function(){return null==this._length&&(this._length=k.getLength(this.getValues(),0,1)),this._length},getArea:function(){return k.getArea(this.getValues())},getLine:function(){return new p(this._segment1._point,this._segment2._point)},getPart:function(t,e){return new k(k.getPart(this.getValues(),t,e))},getPartLength:function(t,e){return k.getLength(this.getValues(),t,e)},getIntersections:function(t){return k._getIntersections(this.getValues(),t&&t!==this?t.getValues():null,this,t,[],{})},_getParameter:function(t,n){return n?t:t&&t.curve===this?t.parameter:t===e&&n===e?.5:this.getParameterAt(t,0)},divide:function(t,e,n){var i=this._getParameter(t,e),r=4e-7,s=1-r,a=null;if(i>=r&&s>=i){var o=k.subdivide(this.getValues(),i),h=o[0],u=o[1],c=n||this.hasHandles(),d=this._segment1,_=this._segment2,f=this._path;c&&(d._handleOut.set(h[2]-h[0],h[3]-h[1]),_._handleIn.set(u[4]-u[6],u[5]-u[7]));var g=h[6],v=h[7],p=new I(new l(g,v),c&&new l(h[4]-g,h[5]-v),c&&new l(u[2]-g,u[3]-v));f?(f.insert(d._index+1,p),a=this.getNext()):(this._segment2=p,a=new k(p,_))}return a},split:function(t,e){return this._path?this._path.split(this._segment1._index,this._getParameter(t,e)):null},reversed:function(){return new k(this._segment2.reversed(),this._segment1.reversed())},clearHandles:function(){this._segment1._handleOut.set(0,0),this._segment2._handleIn.set(0,0)},statics:{getValues:function(t,e,n){var i=t._point,r=t._handleOut,s=e._handleIn,a=e._point,o=[i._x,i._y,i._x+r._x,i._y+r._y,a._x+s._x,a._y+s._y,a._x,a._y];return n&&n._transformCoordinates(o,o,4),o},subdivide:function(t,n){var i=t[0],r=t[1],s=t[2],a=t[3],o=t[4],h=t[5],u=t[6],l=t[7];n===e&&(n=.5);var c=1-n,d=c*i+n*s,_=c*r+n*a,f=c*s+n*o,g=c*a+n*h,v=c*o+n*u,p=c*h+n*l,m=c*d+n*f,y=c*_+n*g,w=c*f+n*v,x=c*g+n*p,b=c*m+n*w,S=c*y+n*x;return[[i,r,d,_,m,y,b,S],[b,S,w,x,v,p,u,l]]},solveCubic:function(t,e,n,i,r,s){var a=t[e],o=t[e+2],u=t[e+4],l=t[e+6],c=3*(o-a),d=3*(u-o)-c,_=l-a-c-d;return h.solveCubic(_,d,c,a-n,i,r,s)},getParameterOf:function(t,e){var n=new l(t[0],t[1]),i=new l(t[6],t[7]),r=1e-12,s=e.isClose(n,r)?0:e.isClose(i,r)?1:null;if(null!==s)return s;for(var a=[e.x,e.y],o=[],h=2e-7,u=0;2>u;u++)for(var c=k.solveCubic(t,u,a[u],o,0,1),d=0;c>d;d++)if(s=o[d],e.isClose(k.getPoint(t,s),h))return s;return e.isClose(n,h)?0:e.isClose(i,h)?1:null},getNearestParameter:function(t,e){function n(n){if(n>=0&&1>=n){var i=e.getDistance(k.getPoint(t,n),!0);if(_>i)return _=i,f=n,!0}}if(k.isStraight(t)){var i=t[0],r=t[1],s=t[6],a=t[7],o=s-i,h=a-r,u=o*o+h*h;if(0===u)return 0;var c=((e.x-i)*o+(e.y-r)*h)/u;return 1e-12>c?0:c>.999999999999?1:k.getParameterOf(t,new l(i+c*o,r+c*h))}for(var d=100,_=1/0,f=0,g=0;d>=g;g++)n(g/d);for(var v=1/(2*d);v>4e-7;)n(f-v)||n(f+v)||(v/=2);return f},getPart:function(t,e,n){var i=e>n;if(i){var r=e;e=n,n=r}return e>0&&(t=k.subdivide(t,e)[1]),1>n&&(t=k.subdivide(t,(n-e)/(1-e))[0]),i?[t[6],t[7],t[4],t[5],t[2],t[3],t[0],t[1]]:t},isFlatEnough:function(t,e){var n=t[0],i=t[1],r=t[2],s=t[3],a=t[4],o=t[5],h=t[6],u=t[7],l=3*r-2*n-h,c=3*s-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[6],r=t[7],s=(t[2]+e)/2,a=(t[3]+n)/2,o=(t[4]+t[6])/2,h=(t[5]+t[7])/2;return 6*((e-s)*(a+n)+(s-o)*(h+a)+(o-i)*(r+h))/10},getBounds:function(t){for(var e=t.slice(0,2),n=e.slice(),i=[0,0],r=0;2>r;r++)k._addBounds(t[r],t[r+2],t[r+4],t[r+6],r,0,e,n,i);return new f(e[0],e[1],n[0]-e[0],n[1]-e[1])},_addBounds:function(t,e,n,i,r,s,a,o,u){function l(t,e){var n=t-e,i=t+e;n<a[r]&&(a[r]=n),i>o[r]&&(o[r]=i)}s/=2;var c=3*(e-n)-t+i,d=2*(t+n)-4*e,_=e-t,f=h.solveQuadratic(c,d,_,u),g=4e-7,v=1-g;l(i,0);for(var p=0;f>p;p++){var m=u[p],y=1-m;m>g&&v>m&&l(y*y*y*t+3*y*y*m*e+3*y*m*m*n+m*m*m*i,s)}}}},i.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]=T[t]([this._segment1,this._segment2],!1,this._path)),e.clone()}},{}),i.each({isStraight:function(t,e,n){if(e.isZero()&&n.isZero())return!0;if(t.isZero())return!1;if(e.isCollinear(t)&&n.isCollinear(t)){var i=t.dot(t),r=t.dot(e)/i,s=t.dot(n)/i;return r>=0&&1>=r&&0>=s&&s>=-1}return!1},isLinear:function(t,e,n){var i=t.divide(3);return e.equals(i)&&n.negate().equals(i)}},function(t,e){this[e]=function(){var e=this._segment1,n=this._segment2;return t(n._point.subtract(e._point),e._handleOut,n._handleIn)},this.statics[e]=function(e){var n=e[0],i=e[1],r=e[6],s=e[7];return t(new l(r-n,s-i),new l(e[2]-n,e[3]-i),new l(e[4]-r,e[5]-s))}},{statics:{},hasHandles:function(){return!this._segment1._handleOut.isZero()||!this._segment2._handleIn.isZero()},isCollinear:function(t){return t&&this.isStraight()&&t.isStraight()&&this.getLine().isCollinear(t.getLine())},isHorizontal:function(){return this.isStraight()&&Math.abs(this.getTangentAt(.5,!0).y)<1e-7},isVertical:function(){return this.isStraight()&&Math.abs(this.getTangentAt(.5,!0).x)<1e-7}}),{beans:!1,getParameterAt:function(t,e){return k.getParameterAt(this.getValues(),t,e)},getParameterOf:function(){return k.getParameterOf(this.getValues(),l.read(arguments))},getLocationAt:function(t,e){var n=e?t:this.getParameterAt(t);return null!=n&&n>=0&&1>=n?new O(this,n):null},getLocationOf:function(){return this.getLocationAt(this.getParameterOf(l.read(arguments)),!0)},getOffsetOf:function(){var t=this.getLocationOf.apply(this,arguments);return t?t.getOffset():null},getNearestLocation:function(){var t=l.read(arguments),e=this.getValues(),n=k.getNearestParameter(e,t),i=k.getPoint(e,n);return new O(this,n,i,null,t.getDistance(i))},getNearestPoint:function(){return this.getNearestLocation.apply(this,arguments).getPoint()}},new function(){var t=["getPoint","getTangent","getNormal","getWeightedTangent","getWeightedNormal","getCurvature"];return i.each(t,function(t){this[t+"At"]=function(e,n){var i=this.getValues();return k[t](i,n?e:k.getParameterAt(i,e,0))}},{statics:{_evaluateMethods:t}})},new function(){function t(t){var e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],h=t[7],u=9*(i-s)+3*(o-e),l=6*(e+s)-12*i,c=3*(i-e),d=9*(r-a)+3*(h-n),_=6*(n+a)-12*r,f=3*(r-n);return function(t){var e=(u*t+l)*t+c,n=(d*t+_)*t+f;return Math.sqrt(e*e+n*n)}}function n(t,e){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(e-t))))}function i(t,e,n,i){if(null==e||0>e||e>1)return null;var r,s,a=t[0],o=t[1],u=t[2],c=t[3],d=t[4],_=t[5],f=t[6],g=t[7],v=4e-7,p=1-v,m=h.isZero;if(m(u-a)&&m(c-o)&&(u=a,c=o),m(d-f)&&m(_-g)&&(d=f,_=g),0===n&&(v>e||e>p)){var y=v>e;r=y?a:f,s=y?o:g}else{var w=3*(u-a),x=3*(d-u)-w,b=f-a-w-x,S=3*(c-o),C=3*(_-c)-S,P=g-o-S-C;if(0===n)r=((b*e+x)*e+w)*e+a,s=((P*e+C)*e+S)*e+o;else{if(v>e?(r=w,s=S):e>p?(r=3*(f-d),s=3*(g-_)):(r=(3*b*e+2*x)*e+w,s=(3*P*e+2*C)*e+S),i){0===r&&0===s&&(v>e||e>p)&&(r=d-u,s=_-c);var M=Math.sqrt(r*r+s*s);M&&(r/=M,s/=M)}if(3===n){var I=6*b*e+2*x,z=6*P*e+2*C,k=Math.pow(r*r+s*s,1.5);r=0!==k?(r*z-s*I)/k:0,s=0}}}return 2===n?new l(s,-r):new l(r,s)}return{statics:{getLength:function(i,r,s){if(r===e&&(r=0),s===e&&(s=1),0===r&&1===s&&k.isStraight(i)){var a=i[6]-i[0],o=i[7]-i[1];return Math.sqrt(a*a+o*o)}var u=t(i);return h.integrate(u,r,s,n(r,s))},getParameterAt:function(i,r,s){function a(t){return g+=h.integrate(d,s,t,n(s,t)),s=t,g-r}if(s===e&&(s=0>r?1:0),0===r)return s;var o=Math.abs,u=r>0,l=u?s:0,c=u?1:s,d=t(i),_=h.integrate(d,l,c,n(l,c));if(o(r-_)<1e-12)return u?c:l;if(o(r)>_)return null;var f=r/_,g=0;return h.findRoot(a,d,s+f,l,c,32,1e-12)},getPoint:function(t,e){return i(t,e,0,!1)},getTangent:function(t,e){return i(t,e,1,!0)},getWeightedTangent:function(t,e){return i(t,e,1,!1)},getNormal:function(t,e){return i(t,e,2,!0)},getWeightedNormal:function(t,e){return i(t,e,2,!1)},getCurvature:function(t,e){return i(t,e,3,!1).x}}}},new function(){function t(t,e,n,i,r,s,a,o,h,u,l){var c=!l&&e.excludeStart,d=!l&&e.excludeEnd,_=4e-7,f=1-_;if(null==r&&(r=k.getParameterOf(n,s)),null!==r&&r>=(c?_:0)&&(d?f:1)>=r&&(null==h&&(h=k.getParameterOf(a,u)),null!==h&&h>=(d?_:0)&&(c?f:1)>=h)){var g=e.renormalize;if(g){var v=g(r,h);r=v[0],h=v[1]}var p=new O(i,r,s||k.getPoint(n,r),l),m=new O(o,h,u||k.getPoint(a,h),l),y=p.getPath()===m.getPath()&&p.getIndex()>m.getIndex(),w=y?m:p,x=e.include;p._intersection=m,m._intersection=p,(!x||x(w))&&O.insert(t,w,!0)}}function e(r,s,a,o,h,u,l,c,d,_,f,g){if(!(++g>=26)){var v,m,y=s[0],w=s[1],x=s[6],b=s[7],S=p.getSignedDistance,C=S(y,w,x,b,s[2],s[3]),P=S(y,w,x,b,s[4],s[5]),M=C*P>0?.75:4/9,I=M*Math.min(0,C,P),z=M*Math.max(0,C,P),O=S(y,w,x,b,r[0],r[1]),A=S(y,w,x,b,r[2],r[3]),T=S(y,w,x,b,r[4],r[5]),N=S(y,w,x,b,r[6],r[7]),L=n(O,A,T,N),B=L[0],E=L[1];if((0!==C||0!==P||0!==O||0!==A||0!==T||0!==N)&&null!=(v=i(B,E,I,z))&&null!=(m=i(B.reverse(),E.reverse(),I,z))){var D=l+(c-l)*v,j=l+(c-l)*m;if(Math.max(_-d,j-D)<1e-7){var F=(D+j)/2,R=(d+_)/2;r=a.getValues(),s=o.getValues(),t(h,u,f?s:r,f?o:a,f?R:F,null,f?r:s,f?a:o,f?F:R,null)}else if(r=k.getPart(r,v,m),m-v>.8)if(j-D>_-d){var q=k.subdivide(r,.5),F=(D+j)/2;e(s,q[0],o,a,h,u,d,_,D,F,!f,g),e(s,q[1],o,a,h,u,d,_,F,j,!f,g)}else{var q=k.subdivide(s,.5),R=(d+_)/2;e(q[0],r,o,a,h,u,d,R,D,j,!f,g),e(q[1],r,o,a,h,u,R,_,D,j,!f,g)}else e(s,r,o,a,h,u,d,_,D,j,!f,g)}}}function n(t,e,n,i){var r,s=[0,t],a=[1/3,e],o=[2/3,n],h=[1,i],u=e-(2*t+i)/3,l=n-(t+2*i)/3;if(0>u*l)r=[[s,a,h],[s,o,h]];else{var c=u/l;r=[c>=2?[s,a,h]:.5>=c?[s,o,h]:[s,a,o,h],[s,h]]}return 0>(u||l)?r.reverse():r}function i(t,e,n,i){return t[0][1]<n?r(t,!0,n):e[0][1]>i?r(e,!1,i):t[0][0]}function r(t,e,n){for(var i=t[0][0],r=t[0][1],s=1,a=t.length;a>s;s++){var o=t[s][0],h=t[s][1];if(e?h>=n:n>=h)return h===n?o:i+(n-r)*(o-i)/(h-r);i=o,r=h}return null}function s(e,n,i,r,s,a){for(var o=k.isStraight(e),u=o?n:e,l=o?e:n,c=l[0],d=l[1],_=l[6],f=l[7],g=_-c,v=f-d,p=Math.atan2(-v,g),m=Math.sin(p),y=Math.cos(p),w=[],x=0;8>x;x+=2){var b=u[x]-c,S=u[x+1]-d;w.push(b*y-S*m,b*m+S*y)}for(var C=[],P=k.solveCubic(w,1,0,C,0,1),x=0;P>x;x++){var M=C[x],I=k.getPoint(u,M),z=k.getParameterOf(l,I);if(null!==z){var O=k.getPoint(l,z),A=o?z:M,T=o?M:z;(!a.excludeEnd||T>h.CURVETIME_EPSILON)&&t(s,a,e,i,A,o?O:I,n,r,T,o?I:O)}}}function a(e,n,i,r,s,a){var o=p.intersect(e[0],e[1],e[6],e[7],n[0],n[1],n[6],n[7]);o&&t(s,a,e,i,null,o,n,r,null,o)}return{statics:{_getIntersections:function(n,i,r,o,h,u){if(!i)return k._getSelfIntersection(n,r,h,u);var c=2e-7,d=n[0],_=n[1],f=n[6],g=n[7],v=i[0],p=i[1],m=i[6],y=i[7],w=(3*n[2]+d)/4,x=(3*n[3]+_)/4,b=(3*n[4]+f)/4,S=(3*n[5]+g)/4,C=(3*i[2]+v)/4,P=(3*i[3]+p)/4,M=(3*i[4]+m)/4,I=(3*i[5]+y)/4,z=Math.min,O=Math.max;if(!(O(d,w,b,f)+c>z(v,C,M,m)&&z(d,w,b,f)-c<O(v,C,M,m)&&O(_,x,S,g)+c>z(p,P,I,y)&&z(_,x,S,g)-c<O(p,P,I,y)))return h;var A=k.getOverlaps(n,i);if(A){for(var T=0;2>T;T++){var N=A[T];t(h,u,n,r,N[0],null,i,o,N[1],null,!0)}return h}var L=k.isStraight(n),B=k.isStraight(i),E=L&&B,D=h.length;if((E?a:L||B?s:e)(n,i,r,o,h,u,0,1,0,1,0,0),E&&h.length>D)return h;var j=new l(d,_),F=new l(f,g),R=new l(v,p),q=new l(m,y);return j.isClose(R,c)&&t(h,u,n,r,0,j,i,o,0,R),!u.excludeStart&&j.isClose(q,c)&&t(h,u,n,r,0,j,i,o,1,q),!u.excludeEnd&&F.isClose(R,c)&&t(h,u,n,r,1,F,i,o,0,R),F.isClose(q,c)&&t(h,u,n,r,1,F,i,o,1,q),h},_getSelfIntersection:function(t,e,n,i){var r=t[0],s=t[1],a=t[2],o=t[3],u=t[4],c=t[5],d=t[6],_=t[7],f=new p(r,s,d,_,!1),g=f.getSide(new l(a,o),!0),v=f.getSide(new l(u,c),!0);if(g===v){var m=(r-u)*(o-_)+(a-d)*(c-s);if(m*g>0)return n}var y=d-3*u+3*a-r,w=u-2*a+r,x=a-r,b=_-3*c+3*o-s,S=c-2*o+s,C=o-s,P=b*x-y*C,M=b*w-y*S,I=S*x-w*C;if(0>P*P-4*M*I){var z,O=[],A=h.solveCubic(y*y+b*b,3*(y*w+b*S),2*(w*w+S*S)+y*x+b*C,w*x+S*C,O,0,1);if(A>0){for(var T=0,N=0;A>T;T++){var L=Math.abs(e.getCurvatureAt(O[T],!0));
L>N&&(N=L,z=O[T])}var B=k.subdivide(t,z);i.excludeEnd=!0,i.renormalize=function(t,e){return[t*z,e*(1-z)+z]},k._getIntersections(B[0],B[1],e,e,n,i)}}return n},getOverlaps:function(t,e){function n(t){var e=t[6]-t[0],n=t[7]-t[1];return e*e+n*n}var i=Math.abs,r=4e-7,s=2e-7,a=k.isStraight(t),o=k.isStraight(e),h=a&&o,u=n(t)<n(e),c=u?e:t,d=u?t:e,_=new p(c[0],c[1],c[6],c[7]);if(_.getDistance(new l(d[0],d[1]))<s&&_.getDistance(new l(d[6],d[7]))<s)!h&&_.getDistance(new l(c[2],c[3]))<s&&_.getDistance(new l(c[4],c[5]))<s&&_.getDistance(new l(d[2],d[3]))<s&&_.getDistance(new l(d[4],d[5]))<s&&(a=o=h=!0);else if(h)return null;if(a^o)return null;for(var f=[t,e],g=[],v=0,m=0;2>v&&g.length<2;v+=0===m?0:1,m=1^m){var y=k.getParameterOf(f[1^v],new l(f[v][0===m?0:6],f[v][0===m?1:7]));if(null!=y){var w=0===v?[m,y]:[y,m];(0===g.length||i(w[0]-g[0][0])>r&&i(w[1]-g[0][1])>r)&&g.push(w)}if(1===v&&0===g.length)break}if(2!==g.length)g=null;else if(!h){var x=k.getPart(t,g[0][0],g[1][0]),b=k.getPart(e,g[0][1],g[1][1]);(i(b[2]-x[2])>s||i(b[3]-x[3])>s||i(b[4]-x[4])>s||i(b[5]-x[5])>s)&&(g=null)}return g}}}}),O=i.extend({_class:"CurveLocation",beans:!0,initialize:function dt(t,e,n,i,r){if(e>.9999996){var s=t.getNext();s&&(e=0,t=s)}this._id=u.get(dt),this._setCurve(t),this._parameter=e,this._point=n||t.getPointAt(e,!0),this._overlap=i,this._distance=r,this._intersection=this._next=this._prev=null},_setCurve:function(t){var e=t._path;this._path=e,this._version=e?e._version:0,this._curve=t,this._segment=null,this._segment1=t._segment1,this._segment2=t._segment2},_setSegment:function(t){this._setCurve(t.getCurve()),this._segment=t,this._parameter=t===this._segment1?0:1,this._point=t._point.clone()},getSegment:function(){var t=this.getCurve(),e=this._segment;if(!e){var n=this.getParameter();0===n?e=t._segment1:1===n?e=t._segment2:null!=n&&(e=t.getPartLength(0,n)<t.getPartLength(n,1)?t._segment1:t._segment2),this._segment=e}return e},getCurve:function(){function t(t){var e=t&&t.getCurve();return e&&null!=(n._parameter=e.getParameterOf(n._point))?(n._setCurve(e),n._segment=t,e):void 0}var e=this._path,n=this;return e&&e._version!==this._version&&(this._parameter=this._curve=this._offset=null),this._curve||t(this._segment)||t(this._segment1)||t(this._segment2.getPrevious())},getPath:function(){var t=this.getCurve();return t&&t._path},getIndex:function(){var t=this.getCurve();return t&&t.getIndex()},getParameter:function(){var t=this.getCurve(),e=this._parameter;return t&&null==e?this._parameter=t.getParameterOf(this._point):e},getPoint:function(){return this._point},getOffset:function(){var t=this._offset;if(null==t){t=0;var e=this.getPath(),n=this.getIndex();if(e&&null!=n)for(var i=e.getCurves(),r=0;n>r;r++)t+=i[r].getLength();this._offset=t+=this.getCurveOffset()}return t},getCurveOffset:function(){var t=this.getCurve(),e=this.getParameter();return null!=e&&t&&t.getPartLength(0,e)},getIntersection:function(){return this._intersection},getDistance:function(){return this._distance},divide:function(){var t=this.getCurve(),e=null;return t&&(e=t.divide(this.getParameter(),!0),e&&this._setSegment(e._segment1)),e},split:function(){var t=this.getCurve();return t?t.split(this.getParameter(),!0):null},equals:function(t,e){var n=this===t,i=2e-7;if(!n&&t instanceof O&&this.getPath()===t.getPath()&&this.getPoint().isClose(t.getPoint(),i)){var r=this.getCurve(),s=t.getCurve(),a=Math.abs,o=a((r.isLast()&&s.isFirst()?-1:r.getIndex())+this.getParameter()-((s.isLast()&&r.isFirst()?-1:s.getIndex())+t.getParameter()));n=(4e-7>o||(o=a(this.getOffset()-t.getOffset()))<i||a(this.getPath().getLength()-o)<i)&&(e||!this._intersection&&!t._intersection||this._intersection&&this._intersection.equals(t._intersection,!0))}return n},toString:function(){var t=[],e=this.getPoint(),n=o.instance;e&&t.push("point: "+e);var i=this.getIndex();null!=i&&t.push("index: "+i);var r=this.getParameter();return null!=r&&t.push("parameter: "+n.number(r)),null!=this._distance&&t.push("distance: "+n.number(this._distance)),"{ "+t.join(", ")+" }"},isTouching:function(){var t=this._intersection;if(t&&this.getTangent().isCollinear(t.getTangent())){var e=this.getCurve(),n=t.getCurve();return!(e.isStraight()&&n.isStraight()&&e.getLine().intersect(n.getLine()))}return!1},isCrossing:function(){function t(t,e,n){return n>e?t>e&&n>t:t>e&&180>=t||t>=-180&&n>t}var e=this._intersection;if(!e)return!1;var n=this.getParameter(),i=e.getParameter(),r=4e-7,s=1-r,a=n>r&&s>n,o=i>r&&s>i;if(a&&o)return!this.isTouching();var h=this.getCurve(),u=r>=n?h.getPrevious():h,l=e.getCurve(),c=r>=i?l.getPrevious():l;if(n>=s&&(h=h.getNext()),i>=s&&(l=l.getNext()),!(u&&h&&c&&l))return!1;if(a||o){var d=a?h:l;if(d.isStraight()){var _=d.getLine(),f=a?c:u,g=a?l:h,v=f.isStraight(),p=g.isStraight();if(v||p)return v&&_.intersect(f.getLine())||p&&_.intersect(g.getLine())}}var m=h.getTangentAt(a?n:r,!0),y=(a?m:u.getTangentAt(s,!0)).negate(),w=l.getTangentAt(o?i:r,!0),x=(o?w:c.getTangentAt(s,!0)).negate(),b=y.getAngle(),S=m.getAngle(),C=x.getAngle(),P=w.getAngle();return!!(a?t(b,C,P)^t(S,C,P)&&t(b,P,C)^t(S,P,C):t(C,b,S)^t(P,b,S)&&t(C,S,b)^t(P,S,b))},hasOverlap:function(){return!!this._overlap}},i.each(k._evaluateMethods,function(t){var e=t+"At";this[t]=function(){var t=this.getParameter(),n=this.getCurve();return null!=t&&n&&n[e](t,!0)}},{preserve:!0}),new function(){function t(t,e,n){function i(n,i){for(var s=n+i;s>=-1&&r>=s;s+=i){var a=t[(s%r+r)%r];if(!e.getPoint().isClose(a.getPoint(),2e-7))break;if(e.equals(a))return a}return null}for(var r=t.length,s=0,a=r-1;a>=s;){var o,h=s+a>>>1,u=t[h];if(n&&(o=e.equals(u)?u:i(h,-1)||i(h,1)))return e._overlap&&(o._overlap=o._intersection._overlap=!0),o;var l=e.getPath(),c=u.getPath(),d=l===c?e.getIndex()+e.getParameter()-(u.getIndex()+u.getParameter()):l._id-c._id;0>d?a=h-1:s=h+1}return t.splice(s,0,e),e}return{statics:{insert:t,expand:function(e){for(var n=e.slice(),i=e.length-1;i>=0;i--)t(n,e[i]._intersection,!1);return n}}}}),A=w.extend({_class:"PathItem",_canScaleStroke:!0,initialize:function(){},getIntersections:function(t,e,n,i){var r=this===t||!t,s=this._matrix._orNullIfIdentity(),a=r?s:(n||t._matrix)._orNullIfIdentity();if(!r&&!this.getBounds(s).touches(t.getBounds(a)))return[];for(var o,t,h=this.getCurves(),u=r?h:t.getCurves(),l=h.length,c=r?l:u.length,d=[],_=[],f=0;c>f;f++)d[f]=u[f].getValues(a);for(var f=0;l>f;f++){var g=h[f],v=r?d[f]:g.getValues(s),p=g.getPath();p!==t&&(t=p,o=[],_.push(o)),r&&k._getSelfIntersection(v,g,o,{include:e,excludeStart:1===l&&g.getPoint1().equals(g.getPoint2())});for(var m=r?f+1:0;c>m;m++){if(i&&o.length)return o;var y=u[m];k._getIntersections(v,d[m],g,y,o,{include:e,excludeStart:r&&g.getPrevious()===y,excludeEnd:r&&g.getNext()===y})}}o=[];for(var f=0,w=_.length;w>f;f++)o.push.apply(o,_[f]);return o},getCrossings:function(t){return this.getIntersections(t,function(t){return t._overlap||t.isCrossing()})},_asPathItem:function(){return this},setPathData:function(t){function e(t,e){var n=+i[t];return o&&(n+=h[e]),n}function n(t){return new l(e(t,"x"),e(t+1,"y"))}var i,r,s,a=t.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/gi),o=!1,h=new l,u=new l;this.clear();for(var c=0,_=a&&a.length;_>c;c++){var f=a[c],g=f[0],v=g.toLowerCase();i=f.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);var p=i&&i.length;switch(o=g===v,"z"!==r||/[mz]/.test(v)||this.moveTo(h=u),v){case"m":case"l":for(var m="m"===v,y=0;p>y;y+=2)this[0===y&&m?"moveTo":"lineTo"](h=n(y));s=h,m&&(u=h);break;case"h":case"v":for(var w="h"===v?"x":"y",y=0;p>y;y++)h[w]=e(y,w),this.lineTo(h);s=h;break;case"c":for(var y=0;p>y;y+=6)this.cubicCurveTo(n(y),s=n(y+2),h=n(y+4));break;case"s":for(var y=0;p>y;y+=4)this.cubicCurveTo(/[cs]/.test(r)?h.multiply(2).subtract(s):h,s=n(y),h=n(y+2)),r=v;break;case"q":for(var y=0;p>y;y+=4)this.quadraticCurveTo(s=n(y),h=n(y+2));break;case"t":for(var y=0;p>y;y+=2)this.quadraticCurveTo(s=/[qt]/.test(r)?h.multiply(2).subtract(s):h,h=n(y)),r=v;break;case"a":for(var y=0;p>y;y+=7)this.arcTo(h=n(y+5),new d(+i[y],+i[y+1]),+i[y+2],+i[y+4],+i[y+3]);break;case"z":this.closePath(!0)}r=v}},_canComposite:function(){return!(this.hasFill()&&this.hasStroke())},_contains:function(t){var e=t.isInside(this.getInternalHandleBounds())&&this._getWinding(t);return!!("evenodd"===this.getFillRule()?1&e:e)}}),T=A.extend({_class:"Path",_serializeFields:{segments:[],closed:!1},initialize:function(t){this._closed=!1,this._segments=[],this._version=0;var n=Array.isArray(t)?"object"==typeof t[0]?t:arguments:!t||t.size!==e||t.x===e&&t.point===e?null:arguments;n&&n.length>0?this.setSegments(n):(this._curves=e,this._selectedSegmentState=0,n||"string"!=typeof t||(this.setPathData(t),t=null)),this._initialize(!n&&t)},_equals:function(t){return this._closed===t._closed&&i.equals(this._segments,t._segments)},copyContent:function(t){this.setSegments(t._segments),this._closed=t._closed;var n=t._clockwise;n!==e&&(this._clockwise=n)},_changed:function _t(t){if(_t.base.call(this,t),8&t){if(this._length=this._area=this._clockwise=this._monoCurves=e,16&t)this._version++;else if(this._curves)for(var n=0,i=this._curves.length;i>n;n++)this._curves[n]._changed()}else 32&t&&(this._bounds=e)},getStyle:function(){var t=this._parent;return(t instanceof N?t:this)._style},getSegments:function(){return this._segments},setSegments:function(t){var n=this.isFullySelected();this._segments.length=0,this._selectedSegmentState=0,this._curves=e,t&&t.length>0&&this._add(I.readAll(t)),n&&this.setFullySelected(!0)},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=new Array(n);for(var i=0;n>i;i++)t[i]=new k(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]},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 k(this,this._segments[e-1],this._segments[0]))}this._changed(25)}}},{beans:!0,getPathData:function(t,e){function n(e,n){e._transformCoordinates(t,g,!1),i=g[0],r=g[1],v?(p.push("M"+f.pair(i,r)),v=!1):(h=g[2],u=g[3],h===i&&u===r&&l===s&&c===a?n||p.push("l"+f.pair(i-s,r-a)):p.push("c"+f.pair(l-s,c-a)+" "+f.pair(h-s,u-a)+" "+f.pair(i-s,r-a))),s=i,a=r,l=g[4],c=g[5]}var i,r,s,a,h,u,l,c,d=this._segments,_=d.length,f=new o(e),g=new Array(6),v=!0,p=[];if(0===_)return"";for(var m=0;_>m;m++)n(d[m]);return this._closed&&_>0&&(n(d[0],!0),p.push("z")),p.join("")}},{isEmpty:function(){return 0===this._segments.length},_transformContent:function(t){for(var e=this._segments,n=new Array(6),i=0,r=e.length;r>i;i++)e[i]._transformCoordinates(t,n,!0);return!0},_add:function(t,e){for(var n=this._segments,i=this._curves,r=t.length,s=null==e,e=s?n.length:e,a=0;r>a;a++){var o=t[a];o._path&&(o=t[a]=o.clone()),o._path=this,o._index=e+a,o._selectionState&&this._updateSelection(o,0,o._selectionState)}if(s)n.push.apply(n,t);else{n.splice.apply(n,[e,0].concat(t));for(var a=e+r,h=n.length;h>a;a++)n[a]._index=a}if(i){var u=this._countCurves(),l=e>0&&e+r-1===u?e-1:e,c=l,d=Math.min(l+r,u);t._curves&&(i.splice.apply(i,[l,0].concat(t._curves)),c+=t._curves.length);for(var a=c;d>a;a++)i.splice(a,0,new k(this,null,null));this._adjustCurves(l,d)}return this._changed(25),t},_adjustCurves:function(t,e){for(var n,i=this._segments,r=this._curves,s=t;e>s;s++)n=r[s],n._path=this,n._segment1=i[s],n._segment2=i[s+1]||i[0],n._changed();(n=r[this._closed&&0===t?i.length-1:t-1])&&(n._segment2=i[t]||i[0],n._changed()),(n=r[e])&&(n._segment1=i[e],n._changed())},_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(I.readAll(arguments)):this._add([I.read(arguments)])[0]},insert:function(t,e){return arguments.length>2&&"number"!=typeof e?this._add(I.readAll(arguments,1),t):this._add([I.read(arguments,1)],t)[0]},addSegment:function(){return this._add([I.read(arguments)])[0]},insertSegment:function(t){return this._add([I.read(arguments,1)],t)[0]},addSegments:function(t){return this._add(I.readAll(t))},insertSegments:function(t,e){return this._add(I.readAll(e),t)},removeSegment:function(t){return this.removeSegments(t,t+1)[0]||null},removeSegments:function(t,e,n){t=t||0,e=i.pick(e,this._segments.length);var r=this._segments,s=this._curves,a=r.length,o=r.splice(t,e-t),h=o.length;if(!h)return o;for(var u=0;h>u;u++){var l=o[u];l._selectionState&&this._updateSelection(l,l._selectionState,0),l._index=l._path=null}for(var u=t,c=r.length;c>u;u++)r[u]._index=u;if(s){for(var d=t>0&&e===a+(this._closed?1:0)?t-1:t,s=s.splice(d,h),u=s.length-1;u>=0;u--)s[u]._path=null;n&&(o._curves=s.slice(1)),this._adjustCurves(d,d)}return this._changed(25),o},clear:"#removeSegments",hasHandles:function(){for(var t=this._segments,e=0,n=t.length;n>e;e++)if(t[e].hasHandles())return!0;return!1},clearHandles:function(){for(var t=this._segments,e=0,n=t.length;n>e;e++)t[e].clearHandles()},getLength:function(){if(null==this._length){for(var t=this.getCurves(),e=0,n=0,i=t.length;i>n;n++)e+=t[n].getLength();this._length=e}return this._length},getArea:function(){if(null==this._area){for(var t=this._segments,e=t.length,n=e-1,i=0,r=0,s=this._closed?e:n;s>r;r++)i+=k.getArea(k.getValues(t[r],t[n>r?r+1:0]));this._area=i}return this._area},isClockwise:function(){return this._clockwise!==e?this._clockwise:this.getArea()>=0},setClockwise:function(t){this.isClockwise()!=(t=!!t)&&this.reverse(),this._clockwise=t},isFullySelected:function(){var t=this._segments.length;return this._selected&&t>0&&this._selectedSegmentState===7*t},setFullySelected:function(t){t&&this._selectSegments(!0),this.setSelected(t)},setSelected:function ft(t){t||this._selectSegments(!1),ft.base.call(this,t)},_selectSegments:function(t){var e=this._segments.length;this._selectedSegmentState=t?7*e:0;for(var n=0;e>n;n++)this._segments[n]._selectionState=t?7: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,64,.1),n=0,i=e.length/Math.ceil(e.length/t),r=e.length+(this._closed?-i:i)/2,s=[];r>=n;)s.push(new I(e.getPointAt(n))),n+=i;this.setSegments(s)},reduce:function(t){for(var e=this.getCurves(),n=t&&t.simplify,i=n?2e-7:0,r=e.length-1;r>=0;r--){var s=e[r];!s.hasHandles()&&(s.getLength()<i||n&&s.isCollinear(s.getNext()))&&s.remove()}return this},simplify:function(t){if(this._segments.length>2){var e=new B(this,t||2.5);this.setSegments(e.fit())}},split:function(t,e){if(null===e)return null;if(1===arguments.length){var n=t;if("number"==typeof n&&(n=this.getLocationAt(n)),!n)return null;t=n.index,e=n.parameter}var i=4e-7,r=1-i;e>=r&&(t++,e--);var s=this.getCurves();if(t>=0&&t<s.length){e>=i&&s[t++].divide(e,!0);var a,o=this.removeSegments(t,this._segments.length,!0);return this._closed?(this.setClosed(!1),a=this):(a=new T(w.NO_INSERT),a.insertAbove(this,!0),a.copyAttributes(this)),a._add(o,0),this.addSegment(o[0]),a}return null},reverse:function(){this._segments.reverse();for(var t=0,n=this._segments.length;n>t;t++){var i=this._segments[t],r=i._handleIn;i._handleIn=i._handleOut,i._handleOut=r,i._index=t}this._curves=null,this._clockwise!==e&&(this._clockwise=!this._clockwise),this._changed(9)},join:function(t){if(t){var e=t._segments,n=this.getLastSegment(),i=t.getLastSegment();if(!i)return this;n&&n._point.equals(i._point)&&t.reverse();var r=t.getFirstSegment();if(n&&n._point.equals(r._point))n.setHandleOut(r._handleOut),this._add(e.slice(1));else{var s=this.getFirstSegment();s&&s._point.equals(r._point)&&t.reverse(),i=t.getLastSegment(),s&&s._point.equals(i._point)?(s.setHandleIn(i._handleIn),this._add(e.slice(0,e.length-1),0)):this._add(e.slice())}t._closed&&this._add([e[0]]),t.remove()}var a=this.getFirstSegment(),o=this.getLastSegment();return a!==o&&a._point.equals(o._point)&&(a.setHandleIn(o._handleIn),o.remove(),this.setClosed(!0)),this},toShape:function(t){function n(t,e){var n=c[t],i=n.getNext(),r=c[e],s=r.getNext();return n._handleOut.isZero()&&i._handleIn.isZero()&&r._handleOut.isZero()&&s._handleIn.isZero()&&i._point.subtract(n._point).isCollinear(s._point.subtract(r._point))}function i(t){var e=c[t],n=e.getPrevious(),i=e.getNext();return n._handleOut.isZero()&&e._handleIn.isZero()&&e._handleOut.isZero()&&i._handleIn.isZero()&&e._point.subtract(n._point).isOrthogonal(i._point.subtract(e._point))}function r(t){var e=c[t],n=e.getNext(),i=e._handleOut,r=n._handleIn,s=.5522847498307936;if(i.isOrthogonal(r)){var a=e._point,o=n._point,u=new p(a,i,!0).intersect(new p(o,r,!0),!0);return u&&h.isZero(i.getLength()/u.subtract(a).getLength()-s)&&h.isZero(r.getLength()/u.subtract(o).getLength()-s)}return!1}function s(t,e){return c[t]._point.getDistance(c[e]._point)}if(!this._closed)return null;var a,o,u,l,c=this._segments;if(!this.hasHandles()&&4===c.length&&n(0,2)&&n(1,3)&&i(1)?(a=S.Rectangle,o=new d(s(0,3),s(0,1)),l=c[1]._point.add(c[2]._point).divide(2)):8===c.length&&r(0)&&r(2)&&r(4)&&r(6)&&n(1,5)&&n(3,7)?(a=S.Rectangle,o=new d(s(1,6),s(0,3)),u=o.subtract(new d(s(0,7),s(1,2))).divide(2),l=c[3]._point.add(c[4]._point).divide(2)):4===c.length&&r(0)&&r(1)&&r(2)&&r(3)&&(h.isZero(s(0,2)-s(1,3))?(a=S.Circle,u=s(0,2)/2):(a=S.Ellipse,u=new d(s(2,0)/2,s(3,1)/2)),l=c[1]._point),a){var _=this.getPosition(!0),f=new a({center:_,size:o,radius:u,insert:!1});return f.copyAttributes(this,!0),f._matrix.prepend(this._matrix),f.rotate(l.subtract(_).getAngle()+90),(t===e||t)&&f.insertAbove(this),f}return null},toPath:"#clone",_hitTestSelf:function(t,e){function n(e,n){return t.subtract(e).divide(n).length<=1}function i(t,i,r){if(!e.selected||i.isSelected()){var s=t._point;if(i!==s&&(i=i.add(s)),n(i,y))return new M(r,_,{segment:t,point:i})}}function r(t,n){return(n||e.segments)&&i(t,t._point,"segment")||!n&&e.handles&&(i(t,t._handleIn,"handle-in")||i(t,t._handleOut,"handle-out"))}function s(t){l.add(t)}function a(e){if(("round"!==o||"round"!==h)&&(l=new T({internal:!0,closed:!0}),p||e._index>0&&e._index<v-1?"round"!==o&&(e._handleIn.isZero()||e._handleOut.isZero())&&T._addBevelJoin(e,o,S,u,s,!0):"round"!==h&&T._addSquareCap(e,h,S,s,!0),!l.isEmpty())){var i;return l.contains(t)||(i=l.getNearestLocation(t))&&n(i.getPoint(),m)}return n(e._point,y)}var o,h,u,l,c,d,_=this,f=this.getStyle(),g=this._segments,v=g.length,p=this._closed,m=e._tolerancePadding,y=m,w=e.stroke&&f.hasStroke(),x=e.fill&&f.hasFill(),b=e.curves,S=w?f.getStrokeWidth()/2:x&&e.tolerance>0||b?0:null;if(null!==S&&(S>0?(o=f.getStrokeJoin(),h=f.getStrokeCap(),u=S*f.getMiterLimit(),y=m.add(T._getStrokePadding(S,!f.getStrokeScaling()&&e._strokeMatrix))):o=h="round"),!e.ends||e.segments||p){if(e.segments||e.handles)for(var C=0;v>C;C++)if(d=r(g[C]))return d}else if(d=r(g[0],!0)||r(g[v-1],!0))return d;if(null!==S){if(c=this.getNearestLocation(t)){var P=c.getParameter();0===P||1===P&&v>1?a(c.getSegment())||(c=null):n(c.getPoint(),y)||(c=null)}if(!c&&"miter"===o&&v>1)for(var C=0;v>C;C++){var I=g[C];if(t.getDistance(I._point)<=u&&a(I)){c=I.getLocation();break}}}return!c&&x&&this._contains(t)||c&&!w&&!b?new M("fill",this):c?new M(w?"stroke":"curve",this,{location:c,point:c.getPoint()}):null}},i.each(k._evaluateMethods,function(t){this[t+"At"]=function(e,n){var i=this.getLocationAt(e,n);return i&&i[t]()}},{beans:!1,getLocationOf:function(){for(var t=l.read(arguments),e=this.getCurves(),n=0,i=e.length;i>n;n++){var r=e[n].getLocationOf(t);if(r)return r}return null},getOffsetOf:function(){var t=this.getLocationOf.apply(this,arguments);return t?t.getOffset():null},getLocationAt:function(t,e){var n=this.getCurves(),i=0;if(e){var r=~~t,s=n[r];return s?s.getLocationAt(t-r,!0):null}for(var a=0,o=n.length;o>a;a++){var h=i,s=n[a];if(i+=s.getLength(),i>t)return s.getLocationAt(t-h)}return n.length>0&&t<=this.getLength()?new O(n[n.length-1],1):null},getNearestLocation:function(){for(var t=l.read(arguments),e=this.getCurves(),n=1/0,i=null,r=0,s=e.length;s>r;r++){var a=e[r].getNearestLocation(t);a._distance<n&&(n=a._distance,i=a)}return i},getNearestPoint:function(){return this.getNearestLocation.apply(this,arguments).getPoint()},smooth:function(t){function n(t,e){var n=t&&t.index;if(null!=n){var r=t.path;if(r&&r!==i)throw new Error(t._class+" "+n+" of "+r+" is not part of "+i);e&&t instanceof k&&n++}else n="number"==typeof t?t:e;return Math.min(0>n&&h?n%o:0>n?n+o:n,o-1)}var i=this,r=t||{},s=r.type||"asymmetric",a=this._segments,o=a.length,h=this._closed,u=h&&r.from===e&&r.to===e,l=n(r.from,0),c=n(r.to,o-1);if(l>c)if(h)l-=o;else{var d=l;l=c,c=d}if(/^(?:asymmetric|continuous)$/.test(s)){var _="asymmetric"===s,f=Math.min,g=c-l+1,v=g-1,p=u?f(g,4):1,m=p,y=p,w=[];if(h||(m=f(1,l),y=f(1,o-c-1)),v+=m+y,1>=v)return;for(var x=0,b=l-m;v>=x;x++,b++)w[x]=a[(0>b?b+o:b)%o]._point;for(var S=w[0]._x+2*w[1]._x,C=w[0]._y+2*w[1]._y,P=2,M=v-1,I=[S],z=[C],O=[P],A=[],T=[],x=1;v>x;x++){var N=M>x,L=N?1:_?1:2,B=N?4:_?2:7,E=N?4:_?3:8,D=N?2:_?0:1,j=L/P;P=O[x]=B-j,S=I[x]=E*w[x]._x+D*w[x+1]._x-j*S,C=z[x]=E*w[x]._y+D*w[x+1]._y-j*C}A[M]=I[M]/O[M],T[M]=z[M]/O[M];for(var x=v-2;x>=0;x--)A[x]=(I[x]-A[x+1])/O[x],T[x]=(z[x]-T[x+1])/O[x];A[v]=(3*w[v]._x-A[M])/2,T[v]=(3*w[v]._y-T[M])/2;for(var x=m,F=v-y,b=l;F>=x;x++,b++){var R=a[0>b?b+o:b],q=R._point,V=A[x]-q._x,H=T[x]-q._y;(u||F>x)&&R.setHandleOut(V,H),(u||x>m)&&R.setHandleIn(-V,-H)}}else for(var x=l;c>=x;x++)a[0>x?x+o:x].smooth(r,!u&&x===l,!u&&x===c)}}),new function(){function t(t,e,n,i){function r(e){var n=a[e],i=a[e+1];(c!=n||d!=i)&&(t.beginPath(),t.moveTo(c,d),t.lineTo(n,i),t.stroke(),t.beginPath(),t.arc(n,i,s,0,2*Math.PI,!0),t.fill())}for(var s=i/2,a=new Array(6),o=0,h=e.length;h>o;o++){var u=e[o];u._transformCoordinates(n,a,!1);var l=u._selectionState,c=a[0],d=a[1];if(1&l&&r(2),2&l&&r(4),t.fillRect(c-s,d-s,i,i),!(4&l)){var _=t.fillStyle;t.fillStyle="#ffffff",t.fillRect(c-s+1,d-s+1,i-2,i-2),t.fillStyle=_}}}function e(t,e,n){function i(e){if(n)e._transformCoordinates(n,f,!1),r=f[0],s=f[1];else{var i=e._point;r=i._x,s=i._y}if(g)t.moveTo(r,s),g=!1;else{if(n)h=f[2],u=f[3];else{var d=e._handleIn;h=r+d._x,u=s+d._y}h===r&&u===s&&l===a&&c===o?t.lineTo(r,s):t.bezierCurveTo(l,c,h,u,r,s)}if(a=r,o=s,n)l=f[4],c=f[5];else{var d=e._handleOut;l=a+d._x,c=o+d._y}}for(var r,s,a,o,h,u,l,c,d=e._segments,_=d.length,f=new Array(6),g=!0,v=0;_>v;v++)i(d[v]);e._closed&&_>0&&i(d[0])}return{_draw:function(t,n,i){function r(t){return l[(t%c+c)%c]}var s=n.dontStart,a=n.dontFinish||n.clip,o=this.getStyle(),h=o.hasFill(),u=o.hasStroke(),l=o.getDashArray(),c=!paper.support.nativeDash&&u&&l&&l.length;if(s||t.beginPath(),(h||u&&!c||a)&&(e(t,this,i),this._closed&&t.closePath()),!a&&(h||u)&&(this._setStyles(t),h&&(t.fill(o.getFillRule()),t.shadowBlur=0),u)){if(c){s||t.beginPath();var d,_=new L(this,32,.25,i),f=_.length,g=-o.getDashOffset(),v=0;for(g%=f;g>0;)g-=r(v--)+r(v--);for(;f>g;)d=g+r(v++),(g>0||d>0)&&_.drawPart(t,Math.max(g,0),Math.max(d,0)),g=d+r(v++)}t.stroke()}},_drawSelected:function(n,i){n.beginPath(),e(n,this,i),n.stroke(),t(n,this._segments,i,paper.settings.handleSize)}}},new function(){function t(t){var e=t._segments;if(0===e.length)throw new Error("Use a moveTo() command first");return e[e.length-1]}return{moveTo:function(){var t=this._segments;1===t.length&&this.removeSegment(0),t.length||this._add([new I(l.read(arguments))])},moveBy:function(){throw new Error("moveBy() is unsupported on Path items.")},lineTo:function(){this._add([new I(l.read(arguments))])},cubicCurveTo:function(){var e=l.read(arguments),n=l.read(arguments),i=l.read(arguments),r=t(this);r.setHandleOut(e.subtract(r._point)),this._add([new I(i,n.subtract(i))])},quadraticCurveTo:function(){var e=l.read(arguments),n=l.read(arguments),i=t(this)._point;this.cubicCurveTo(e.add(i.subtract(e).multiply(1/3)),e.add(n.subtract(e).multiply(1/3)),n)},curveTo:function(){var e=l.read(arguments),n=l.read(arguments),r=i.pick(i.read(arguments),.5),s=1-r,a=t(this)._point,o=e.subtract(a.multiply(s*s)).subtract(n.multiply(r*r)).divide(2*r*s);if(o.isNaN())throw new Error("Cannot put a curve through points with parameter = "+r);this.quadraticCurveTo(o,n)},arcTo:function(){var e,n,r,s,a,o=t(this),h=o._point,u=l.read(arguments),c=i.peek(arguments),_=i.pick(c,!0);if("boolean"==typeof _)var f=h.add(u).divide(2),e=f.add(f.subtract(h).rotate(_?-90:90));else if(i.remain(arguments)<=2)e=u,u=l.read(arguments);else{var g=d.read(arguments);if(g.isZero())return this.lineTo(u);var m=i.read(arguments),_=!!i.read(arguments),y=!!i.read(arguments),f=h.add(u).divide(2),w=h.subtract(f).rotate(-m),x=w.x,b=w.y,S=Math.abs,C=S(g.width),P=S(g.height),M=C*C,z=P*P,k=x*x,O=b*b,A=Math.sqrt(k/M+O/z);if(A>1&&(C*=A,P*=A,M=C*C,z=P*P),A=(M*z-M*O-z*k)/(M*O+z*k),S(A)<1e-12&&(A=0),0>A)throw new Error("Cannot create an arc with the given arguments");n=new l(C*b/P,-P*x/C).multiply((y===_?-1:1)*Math.sqrt(A)).rotate(m).add(f),a=(new v).translate(n).rotate(m).scale(C,P),s=a._inverseTransform(h),r=s.getDirectedAngle(a._inverseTransform(u)),!_&&r>0?r-=360:_&&0>r&&(r+=360)}if(e){var T=new p(h.add(e).divide(2),e.subtract(h).rotate(90),!0),N=new p(e.add(u).divide(2),u.subtract(e).rotate(90),!0),L=new p(h,u),B=L.getSide(e);if(n=T.intersect(N,!0),!n){if(!B)return this.lineTo(u);throw new Error("Cannot create an arc with the given arguments")}s=h.subtract(n),r=s.getDirectedAngle(u.subtract(n));var E=L.getSide(n);0===E?r=B*Math.abs(r):B===E&&(r+=0>r?360:-360)}for(var D=Math.abs(r),j=D>=360?4:Math.ceil(D/90),F=r/j,R=F*Math.PI/360,q=4/3*Math.sin(R)/(1+Math.cos(R)),V=[],H=0;j>=H;H++){var w=u,Z=null;if(j>H&&(Z=s.rotate(90).multiply(q),a?(w=a._transformPoint(s),Z=a._transformPoint(s.add(Z)).subtract(w)):w=n.add(s)),0===H)o.setHandleOut(Z);else{var G=s.rotate(-90).multiply(q);a&&(G=a._transformPoint(s.add(G)).subtract(w)),V.push(new I(w,G,Z))}s=s.rotate(F)}this._add(V)},lineBy:function(){var e=l.read(arguments),n=t(this)._point;this.lineTo(n.add(e))},curveBy:function(){var e=l.read(arguments),n=l.read(arguments),r=i.read(arguments),s=t(this)._point;this.curveTo(s.add(e),s.add(n),r)},cubicCurveBy:function(){var e=l.read(arguments),n=l.read(arguments),i=l.read(arguments),r=t(this)._point;this.cubicCurveTo(r.add(e),r.add(n),r.add(i))},quadraticCurveBy:function(){var e=l.read(arguments),n=l.read(arguments),i=t(this)._point;this.quadraticCurveTo(i.add(e),i.add(n))},arcBy:function(){var e=t(this)._point,n=e.add(l.read(arguments)),r=i.pick(i.peek(arguments),!0);"boolean"==typeof r?this.arcTo(n,r):this.arcTo(n,e.add(l.read(arguments)))},closePath:function(t){this.setClosed(!0),t&&this.join()}}},{_getBounds:function(t,e,n,i){return T[t](this._segments,this._closed,this,e,i)},statics:{getBounds:function(t,e,n,i,r){function s(t){t._transformCoordinates(i,o,!1);for(var e=0;2>e;e++)k._addBounds(h[e],h[e+4],o[e+2],o[e],e,r?r[e]:0,u,l,c);var n=h;h=o,o=n}var a=t[0];if(!a)return new f;for(var o=new Array(6),h=a._transformCoordinates(i,new Array(6),!1),u=h.slice(0,2),l=u.slice(),c=new Array(2),d=1,_=t.length;_>d;d++)s(t[d]);return e&&s(a),new f(u[0],u[1],l[0]-u[0],l[1]-u[1])},getStrokeBounds:function(t,e,n,i,r){function s(t){p=p.include(g?g._transformPoint(t,t):t)}function a(t){var e=t._point;p=p.unite(x.setCenter(i?i._transformPoint(e):e))}function o(t,e){var n=t._handleIn,i=t._handleOut;"round"===e||!n.isZero()&&!i.isZero()&&n.isCollinear(i)?a(t):T._addBevelJoin(t,e,_,w,s)}function h(t,e){"round"===e?a(t):T._addSquareCap(t,e,_,s)}var u=n._style;if(!u.hasStroke())return T.getBounds(t,e,n,i);for(var l=t.length-(e?0:1),c=u.getStrokeWidth(),_=c/2,g=n._getStrokeMatrix(i,r),v=T._getStrokePadding(c,g),p=T.getBounds(t,e,n,i,v),m=u.getStrokeJoin(),y=u.getStrokeCap(),w=_*u.getMiterLimit(),x=new f(new d(v)),b=1;l>b;b++)o(t[b],m);return e?o(t[0],m):l>0&&(h(t[0],y),h(t[t.length-1],y)),p},_getStrokePadding:function(t,e){if(!e)return[t,t];var n=e._shiftless(),i=n.transform(new l(t,0)),r=n.transform(new l(0,t)),s=i.getAngleInRadians(),a=i.getLength(),o=r.getLength(),h=Math.sin(s),u=Math.cos(s),c=Math.tan(s),d=Math.atan2(o*c,a),_=Math.atan2(o,c*a);return[Math.abs(a*Math.cos(d)*u+o*Math.sin(d)*h),Math.abs(o*Math.sin(_)*u+a*Math.cos(_)*h)]},_addBevelJoin:function(t,e,n,i,r,s){var a=t.getCurve(),o=a.getPrevious(),h=a.getPointAt(0,!0),u=o.getNormalAt(1,!0),c=a.getNormalAt(0,!0),d=u.getDirectedAngle(c)<0?-n:n;if(u.setLength(d),c.setLength(d),s&&(r(h),r(h.add(u))),"miter"===e){var _=new p(h.add(u),new l(-u.y,u.x),!0).intersect(new p(h.add(c),new l(-c.y,c.x),!0),!0);if(_&&h.getDistance(_)<=i&&(r(_),!s))return}s||r(h.add(u)),r(h.add(c))},_addSquareCap:function(t,e,n,i,r){var s=t._point,a=t.getLocation(),o=a.getNormal().multiply(n);r&&(i(s.subtract(o)),i(s.add(o))),"square"===e&&(s=s.add(o.rotate(0===a.getParameter()?-90:90))),i(s.add(o)),i(s.subtract(o))},getHandleBounds:function(t,e,n,i,r,s){for(var a=new Array(6),o=1/0,h=-o,u=o,l=h,c=0,d=t.length;d>c;c++){var _=t[c];_._transformCoordinates(i,a,!1);for(var g=0;6>g;g+=2){var v=0===g?s:r,p=v?v[0]:0,m=v?v[1]:0,y=a[g],w=a[g+1],x=y-p,b=y+p,S=w-m,C=w+m;o>x&&(o=x),b>h&&(h=b),u>S&&(u=S),C>l&&(l=C)}}return new f(o,u,h-o,l-u)},getRoughBounds:function(t,e,n,i,r){var s=n._style,a=s.hasStroke()?s.getStrokeWidth()/2:0,o=a,h=a&&n._getStrokeMatrix(i,r);return a>0&&("miter"===s.getStrokeJoin()&&(o=a*s.getMiterLimit()),"square"===s.getStrokeCap()&&(o=Math.max(o,a*Math.sqrt(2)))),T.getHandleBounds(t,e,n,i,T._getStrokePadding(a,h),T._getStrokePadding(o,h))}}});T.inject({statics:new function(){function t(t,e,n){var r=i.getNamed(n),s=new T(r&&r.insert===!1&&w.NO_INSERT);return s._add(t),s._closed=e,s.set(r)}function e(e,n,i){for(var s=new Array(4),a=0;4>a;a++){var o=r[a];s[a]=new I(o._point.multiply(n).add(e),o._handleIn.multiply(n),o._handleOut.multiply(n))}return t(s,!0,i)}var n=.5522847498307936,r=[new I([-1,0],[0,n],[0,-n]),new I([0,-1],[-n,0],[n,0]),new I([1,0],[0,-n],[0,n]),new I([0,1],[n,0],[-n,0])];return{Line:function(){return t([new I(l.readNamed(arguments,"from")),new I(l.readNamed(arguments,"to"))],!1,arguments)},Circle:function(){var t=l.readNamed(arguments,"center"),n=i.readNamed(arguments,"radius");return e(t,new d(n),arguments)},Rectangle:function(){var e,i=f.readNamed(arguments,"rectangle"),r=d.readNamed(arguments,"radius",0,{readNull:!0}),s=i.getBottomLeft(!0),a=i.getTopLeft(!0),o=i.getTopRight(!0),h=i.getBottomRight(!0);if(!r||r.isZero())e=[new I(s),new I(a),new I(o),new I(h)];else{r=d.min(r,i.getSize(!0).divide(2));var u=r.width,l=r.height,c=u*n,_=l*n;e=[new I(s.add(u,0),null,[-c,0]),new I(s.subtract(0,l),[0,_]),new I(a.add(0,l),null,[0,-_]),new I(a.add(u,0),[-c,0],null),new I(o.subtract(u,0),null,[c,0]),new I(o.add(0,l),[0,-_],null),new I(h.subtract(0,l),null,[0,_]),new I(h.subtract(u,0),[c,0])]}return t(e,!0,arguments)},RoundRectangle:"#Rectangle",Ellipse:function(){var t=S._readEllipse(arguments);return e(t.center,t.radius,arguments)},Oval:"#Ellipse",Arc:function(){var t=l.readNamed(arguments,"from"),e=l.readNamed(arguments,"through"),n=l.readNamed(arguments,"to"),r=i.getNamed(arguments),s=new T(r&&r.insert===!1&&w.NO_INSERT);return s.moveTo(t),s.arcTo(e,n),s.set(r)},RegularPolygon:function(){for(var e=l.readNamed(arguments,"center"),n=i.readNamed(arguments,"sides"),r=i.readNamed(arguments,"radius"),s=360/n,a=n%3===0,o=new l(0,a?-r:r),h=a?-1:.5,u=new Array(n),c=0;n>c;c++)u[c]=new I(e.add(o.rotate((c+h)*s)));return t(u,!0,arguments)},Star:function(){for(var e=l.readNamed(arguments,"center"),n=2*i.readNamed(arguments,"points"),r=i.readNamed(arguments,"radius1"),s=i.readNamed(arguments,"radius2"),a=360/n,o=new l(0,-1),h=new Array(n),u=0;n>u;u++)h[u]=new I(e.add(o.rotate(a*u).multiply(u%2?s:r)));return t(h,!0,arguments)}}}});var N=A.extend({_class:"CompoundPath",_serializeFields:{children:[]},initialize:function(t){this._children=[],this._namedChildren={},this._initialize(t)||("string"==typeof t?this.setPathData(t):this.addChildren(Array.isArray(t)?t:arguments))},insertChildren:function gt(t,n,i){for(var r=n.length-1;r>=0;r--){var s=n[r];
s instanceof N&&(n=n.slice(),n.splice.apply(n,[r,1].concat(s.removeChildren())),s.remove())}n=gt.base.call(this,t,n,i,T);for(var r=0,a=!i&&n&&n.length;a>r;r++){var s=n[r];s._clockwise===e&&s.setClockwise(0===s._index)}return n},reverse:function(){for(var t=this._children,e=0,n=t.length;n>e;e++)t[e].reverse()},reduce:function vt(t){for(var e=this._children,n=e.length-1;n>=0;n--){var i=e[n].reduce(t);i.isEmpty()&&i.remove()}if(0===e.length){var i=new T(w.NO_INSERT);return i.copyAttributes(this),i.insertAbove(this),this.remove(),i}return vt.base.call(this)},smooth:function(t){for(var e=this._children,n=0,i=e.length;i>n;n++)e[n].smooth(t)},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.push.apply(e,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}},{beans:!0,getPathData:function(t,e){for(var n=this._children,i=[],r=0,s=n.length;s>r;r++){var a=n[r],o=a._matrix;i.push(a.getPathData(t&&!o.isIdentity()?t.appended(o):t,e))}return i.join(" ")}},{_getChildHitTestOptions:function(t){return t["class"]===T||"path"===t.type?t:new i(t,{fill:!1})},_draw:function(t,e,n){var i=this._children;if(0!==i.length){e=e.extend({dontStart:!0,dontFinish:!0}),t.beginPath();for(var r=0,s=i.length;s>r;r++)i[r].draw(t,e,n);if(!e.clip){this._setStyles(t);var a=this._style;a.hasFill()&&(t.fill(a.getFillRule()),t.shadowBlur=0),a.hasStroke()&&t.stroke()}}},_drawSelected:function(t,e,n){for(var i=this._children,r=0,s=i.length;s>r;r++){var a=i[r],o=a._matrix;n[a._id]||a._drawSelected(t,o.isIdentity()?e:e.appended(o))}}},new function(){function t(t,e){var n=t._children;if(e&&0===n.length)throw new Error("Use a moveTo() command first");return n[n.length-1]}var e={moveTo:function(){var e=t(this),n=e&&e.isEmpty()?e:new T(w.NO_INSERT);n!==e&&this.addChild(n),n.moveTo.apply(n,arguments)},moveBy:function(){var e=t(this,!0),n=e&&e.getLastSegment(),i=l.read(arguments);this.moveTo(n?i.add(n._point):i)},closePath:function(e){t(this,!0).closePath(e)}};return i.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(n){e[n]=function(){var e=t(this,!0);e[n].apply(e,arguments)}}),e});A.inject(new function(){function t(t,e){var n=t.clone(!1).reduce({simplify:!0}).transform(null,!0,!0);return e?n.resolveCrossings():n}function e(t,e,n){return t.insertAbove(n&&e.isSibling(n)&&e.getIndex()<n.getIndex()?n:e),t.copyAttributes(e,!0),t}function n(t,e,n){var i=new t(w.NO_INSERT);return i.addChildren(e,!0),n&&(i=i.reduce({simplify:!0})),i}function r(i,r,a){function h(t){for(var e=0,n=t.length;n>e;e++){var i=t[e];v.push.apply(v,i._segments),p.push.apply(p,i._getMonoCurves())}}var u=_[a];if(u[a]=!0,!i._children&&!i._closed)return s(i,r,u);var l=t(i,!0),f=r&&i!==r&&t(r,!0);f&&(u.subtract||u.exclude)^(f.isClockwise()^l.isClockwise())&&f.reverse();var g=o(O.expand(l.getCrossings(f))),v=[],p=[],m=!0,y=!0;h(l._children||[l]),f&&h(f._children||[f]);for(var x=0,b=g.length;b>x;x++)c(g[x]._segment,l,f,p,u);for(var x=0,b=v.length;b>x;x++){var S=v[x],C=S._intersection;null==S._winding&&c(S,l,f,p,u),C&&C._overlap||(m=!1,u[S._winding]&&(y=!1))}return e(m?(u.unite||u.intersect)&&i.getArea()?i.clone(!1):new T(w.NO_INSERT):n(N,d(v,u,y),!m),i,r)}function s(i,r,s){function a(t){return h.contains(t.getPointAt(t.getLength()/2))^l?(c.unshift(t),!0):void 0}if(!r||!r._children&&!r._closed||!s.subtract&&!s.intersect)return null;for(var o=t(i,!1),h=t(r,!1),u=o.getCrossings(h),l=s.subtract,c=[],d=u.length-1;d>=0;d--){var _=u[d].split();_&&(a(_)&&_.getFirstSegment().setHandleIn(0,0),o.getLastSegment().setHandleOut(0,0))}return a(o),e(n(x,c),i,r)}function a(t,e){for(var n=t;n;){if(n===e)return;n=n._prev}for(;t._next&&t._next!==e;)t=t._next;if(!t._next){for(;e._prev;)e=e._prev;t._next=e,e._prev=t}}function o(t,e){for(var n,i,r=e&&[],s=4e-7,o=1-s,h=!1,u=[],l=t.length-1;l>=0;l--){var c=t[l];if(e){if(!e(c))continue;r.unshift(c)}var d,_=c._curve,f=c._parameter,g=f;if(_!==n?h=!_.hasHandles():i>0&&(f/=i),s>f)d=_._segment1;else if(f>o)d=_._segment2;else{var v=_.divide(f,!0,!0);h&&u.push(_,v),d=v._segment1}c._setSegment(d);var p=d._intersection,m=c._intersection;if(p){a(p,m);for(var y=p;y;)a(y._intersection,p),y=y._next}else d._intersection=m;n=_,i=g}for(var l=0,w=u.length;w>l;l++)u[l].clearHandles();return r||t}function u(t,e,n){var i=2e-7,r=t.x,s=t.y,a=0,o=0,h=e.length,c=[],d=Math.abs;if(n){for(var _=-(1/0),f=1/0,g=s-i,v=s+i,p=0;h>p;p++)for(var m=e[p].values,y=k.solveCubic(m,0,r,c,0,1),w=y-1;w>=0;w--){var x=k.getPoint(m,c[w]).y;g>x&&x>_?_=x:x>v&&f>x&&(f=x)}_=(_+s)/2,f=(f+s)/2,_>-(1/0)&&(a=u(new l(r,_),e)),1/0>f&&(o=u(new l(r,f),e))}else for(var b,S=r-i,C=r+i,P=0;h>P;){b=P;var M=e[b],I=M.last,z=I.winding,O=I.values[6];P=b+M.length;for(var p=b;P>p;p++){var M=e[p],A=M.winding,m=M.values,T=m[1],N=m[7];if(A&&(s>=T&&N>=s||s>=N&&T>=s)){var L=s===T?m[0]:s===N?m[6]:1===k.solveCubic(m,1,s,c,0,1)?k.getPoint(m,c[0]).x:null;if(null!=L){var B=A===-z;(s!==T||B||0>(L-r)*(O-r))&&(S>L?a+=A:L>C?o+=A:s===T&&B&&(++a,++o))}z=A,O=m[6]}}}return Math.max(d(a),d(o))}function c(t,e,n,i,r){var s=[],a=t,o=0,h=0;do{var l=t.getCurve(),c=l.getLength();s.push({segment:t,curve:l,length:c}),o+=c,t=t.getNext()}while(t&&!t._intersection&&t!==a);for(var d=0;3>d;d++)for(var c=o*(d+1)/4,_=0,f=s.length;f>_;_++){var g=s[_],v=g.length;if(v>=c){var l=g.curve,p=l._path,m=p._parent,y=l.getParameterAt(c),w=l.getPointAt(y,!0),x=Math.abs(l.getTangentAt(y,!0).y)<1e-7;m instanceof N&&(p=m),r.subtract&&n&&(p===e&&n._getWinding(w,x)||p===n&&!e._getWinding(w,x))||(h+=u(w,i,x));break}c-=v}for(var b=Math.round(h/3),_=s.length-1;_>=0;_--)s[_].segment._winding=b}function d(t,e,n){function i(t){return!(t._visited||e&&!e[t._winding])}function r(t){return t===a||t===o}function s(t,n){if(!t._next)return t;for(;t;){var s=t._segment,a=s.getNext(),o=a._intersection;if(r(s)||r(a)||!s._visited&&!a._visited&&(!e||(!n||i(s))&&(!(n&&o&&o._overlap)&&i(a)||!n&&o&&i(o._segment))))return t;t=t._next}return null}for(var a,o,u=[],l=0,c=t.length;c>l;l++){var d,_=null,f=!1,g=t[l],v=g._intersection;if(!(!i(g)||!n&&v&&g._winding&&v._overlap)){for(a=o=null;;){v=v&&(s(v,!0)||s(v,!1))||v;var p=v&&v._segment;if(r(g)?f=!0:p&&(r(p)?(f=!0,g=p):i(p)&&(e&&e.intersect&&v._overlap&&(g._visited=!0),g=p)),f||g._visited){g._visited=!0;break}if(n&&!i(g))break;_||(_=new T(w.NO_INSERT),a=g,o=p);var m=g.getNext();_.add(new I(g._point,d,m&&g._handleOut)),g._visited=!0,g=m||g._path.getFirstSegment(),d=m&&m._handleIn,v=g._intersection}if(f)_.firstSegment.setHandleIn(d),_.setClosed(!0);else if(_){var y=_.getLength();y>=2e-7&&console.error("Boolean operation resulted in open path","segments =",_._segments.length,"length =",y),_=null}_&&(_._segments.length>8||!h.isZero(_.getArea()))&&(u.push(_),_=null)}}return u}var _={unite:{0:!0,1:!0},intersect:{2:!0},subtract:{1:!0},exclude:{1:!0}};return{_getWinding:function(t,e){return u(t,this._getMonoCurves(),e)},unite:function(t){return r(this,t,"unite")},intersect:function(t){return r(this,t,"intersect")},subtract:function(t){return r(this,t,"subtract")},exclude:function(t){return r(this,t,"exclude")},divide:function(t){return e(n(x,[this.subtract(t),this.intersect(t)],!0),this,t)},resolveCrossings:function(){function t(t){var e=t&&t._intersection;return e&&e._overlap}var e=this._children,n=e||[this],r=!1,s=!1,a=this.getIntersections(null,function(t){return t._overlap&&(r=!0)||t.isCrossing()&&(s=!0)});if(a=O.expand(a),r)for(var h=o(a,function(t){return t._overlap}),u=h.length-1;u>=0;u--){var l=h[u]._segment,c=l.getPrevious(),_=l.getNext();if(l._path&&t(c)&&t(_)){l.remove(),c._handleOut.set(0,0),_._handleIn.set(0,0);var f=c.getCurve();f.isStraight()&&0===f.getLength()&&c.remove()}}s&&(o(a,r&&function(t){var e=t.getCurve(),n=t._intersection._curve,i=t._segment;return e&&n&&e._path&&n._path?!0:void(i&&(i._intersection=null))}),n=d(i.each(n,function(t){this.push.apply(this,t._segments)},[])));var g,v=n.length;if(v>1){n=n.slice().sort(function(t,e){return e.getBounds().getArea()-t.getBounds().getArea()});for(var p=n[0],m=[p],y={},x="nonzero"===this.getFillRule(),b=x&&i.each(n,function(t){this.push(t.isClockwise()?1:-1)},[]),u=1;v>u;u++){for(var S=n[u],C=S.getInteriorPoint(),P=!1,M=null,I=!1,z=u-1;z>=0&&!M;z--)if(n[z].contains(C)){if(x&&!P&&(b[u]+=b[z],b[u]&&b[z])){I=y[u]=!0;break}P=!0,M=!y[z]&&n[z]}I||(S.setClockwise(M?!M.isClockwise():p.isClockwise()),m.push(S))}n=m,v=m.length}return v>1&&e?(n!==e&&this.setChildren(n,!0),g=this):1!==v||e||(n[0]!==this&&this.setSegments(n[0].removeSegments()),g=this),g||(g=new N(w.NO_INSERT),g.addChildren(n,!0),g=g.reduce(),g.copyAttributes(this),this.replaceWith(g)),g}}}),T.inject({_getMonoCurves:function(){function t(t){var e=t[1],r=t[7],s=Math.abs((e-r)/(t[0]-t[6]))<2e-7?0:e>r?-1:1,a={values:t,winding:s};i.push(a),s&&(n=a)}function e(e){if(0!==k.getLength(e)){var n=e[1],i=e[3],r=e[5],s=e[7];if(k.isStraight(e)||n>=i==i>=r&&i>=r==r>=s)t(e);else{var a=3*(i-r)-n+s,o=2*(n+r)-4*i,u=i-n,l=4e-7,c=1-l,d=[],_=h.solveQuadratic(a,o,u,d,l,c);if(0===_)t(e);else{d.sort();var f=d[0],g=k.subdivide(e,f);t(g[0]),_>1&&(f=(d[1]-f)/(1-f),g=k.subdivide(g[1],f),t(g[0])),t(g[1])}}}}var n,i=this._monoCurves;if(!i){i=this._monoCurves=[];for(var r=this.getCurves(),s=this._segments,a=0,o=r.length;o>a;a++)e(r[a].getValues());if(!this._closed&&s.length>1){var u=s[s.length-1]._point,l=s[0]._point,c=u._x,d=u._y,_=l._x,f=l._y;e([c,d,c,d,_,f,_,f])}if(i.length>0){var g=i[0];g.length=i.length,g.last=n}}return i},getInteriorPoint:function(){var t=this.getBounds(),e=t.getCenter(!0);if(!this.contains(e)){for(var n=this._getMonoCurves(),i=[],r=e.y,s=[],a=0,o=n.length;o>a;a++){var h=n[a].values;if(1===n[a].winding&&r>=h[1]&&r<=h[7]||r>=h[7]&&r<=h[1])for(var u=k.solveCubic(h,1,r,i,0,1),l=u-1;l>=0;l--)s.push(k.getPoint(h,i[l]).x);if(s.length>1)break}e.x=(s[0]+s[1])/2}return e}}),N.inject({_getMonoCurves:function(){for(var t=this._children,e=[],n=0,i=t.length;i>n;n++)e.push.apply(e,t[n]._getMonoCurves());return e}});var L=i.extend({_class:"PathIterator",initialize:function(t,e,n,i){function r(t,e){var n=k.getValues(t,e,i);o.push(n),s(n,t._index,0,1)}function s(t,e,i,r){if(r-i>l&&!k.isFlatEnough(t,n||.25)){var a=k.subdivide(t,.5),o=(i+r)/2;s(a[0],e,i,o),s(a[1],e,o,r)}else{var c=t[6]-t[0],d=t[7]-t[1],_=Math.sqrt(c*c+d*d);_>1e-6&&(u+=_,h.push({offset:u,value:r,index:e}))}}for(var a,o=[],h=[],u=0,l=1/(e||32),c=t._segments,d=c[0],_=1,f=c.length;f>_;_++)a=c[_],r(d,a),d=a;t._closed&&r(a,c[0]),this.curves=o,this.parts=h,this.length=u,this.index=0},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 r=this.parts[e];if(r.offset>=t){this.index=e;var s=this.parts[e-1],a=s&&s.index==r.index?s.value:0,o=s?s.offset:0;return{value:a+(r.value-a)*(t-o)/(r.offset-o),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},drawPart:function(t,e,n){e=this.getParameterAt(e),n=this.getParameterAt(n);for(var i=e.index;i<=n.index;i++){var r=k.getPart(this.curves[i],i==e.index?e.value:0,i==n.index?n.value:1);i==e.index&&t.moveTo(r[0],r[1]),t.bezierCurveTo.apply(t,r.slice(2))}}},i.each(k._evaluateMethods,function(t){this[t+"At"]=function(e,n){var i=this.getParameterAt(e);return k[t](this.curves[i.index],i.value,n)}},{})),B=i.extend({initialize:function(t,e){for(var n,i=this.points=[],r=t._segments,s=0,a=r.length;a>s;s++){var o=r[s].point.clone();n&&n.equals(o)||(i.push(o),n=o)}t._closed&&(this.closed=!0,i.unshift(i[i.length-1]),i.push(i[1])),this.error=e},fit:function(){var t=this.points,e=t.length,n=this.segments=e>0?[new I(t[0])]:[];return e>1&&this.fitCubic(0,e-1,t[1].subtract(t[0]).normalize(),t[e-2].subtract(t[e-1]).normalize()),this.closed&&(n.shift(),n.pop()),n},fitCubic:function(t,e,n,i){if(e-t==1){var r=this.points[t],s=this.points[e],a=r.getDistance(s)/3;return void this.addCurve([r,r.add(n.normalize(a)),s.add(i.normalize(a)),s])}for(var o,h=this.chordLengthParameterize(t,e),u=Math.max(this.error,this.error*this.error),l=!0,c=0;4>=c;c++){var d=this.generateBezier(t,e,h,n,i),_=this.findMaxError(t,e,d,h);if(_.error<this.error&&l)return void this.addCurve(d);if(o=_.index,_.error>=u)break;l=this.reparameterize(t,e,h,d),u=_.error}var f=this.points[o-1].subtract(this.points[o+1]).normalize();this.fitCubic(t,o,n,f),this.fitCubic(o,e,f.negate(),i)},addCurve:function(t){var e=this.segments[this.segments.length-1];e.setHandleOut(t[1].subtract(t[0])),this.segments.push(new I(t[3],t[2].subtract(t[3])))},generateBezier:function(t,e,n,i,r){for(var s=1e-12,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*_,p=f*d,m=d*d*d,y=i.normalize(v),w=r.normalize(p),x=this.points[t+l].subtract(a.multiply(g+v)).subtract(o.multiply(p+m));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,S,C=h[0][0]*h[1][1]-h[1][0]*h[0][1];if(Math.abs(C)>s){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/C,S=P/C}else{var I=h[0][0]+h[0][1],z=h[1][0]+h[1][1];b=S=Math.abs(I)>s?u[0]/I:Math.abs(z)>s?u[1]/z:0}var k,O,A=o.getDistance(a),T=s*A;if(T>b||T>S)b=S=A/3;else{var N=o.subtract(a);k=i.normalize(b),O=r.normalize(S),k.dot(N)-O.dot(N)>A*A&&(b=S=A/3,k=O=null)}return[a,a.add(k||i.normalize(b)),o.add(O||r.normalize(S)),o]},reparameterize:function(t,e,n,i){for(var r=t;e>=r;r++)n[r-t]=this.findRoot(i,this.points[r],n[r-t]);for(var r=1,s=n.length;s>r;r++)if(n[r]<=n[r-1])return!1;return!0},findRoot:function(t,e,n){for(var i=[],r=[],s=0;2>=s;s++)i[s]=t[s+1].subtract(t[s]).multiply(3);for(var s=0;1>=s;s++)r[s]=i[s+1].subtract(i[s]).multiply(2);var a=this.evaluate(3,t,n),o=this.evaluate(2,i,n),h=this.evaluate(1,r,n),u=a.subtract(e),l=o.dot(o)+u.dot(h);return Math.abs(l)<1e-6?n:n-u.dot(o)/l},evaluate:function(t,e,n){for(var i=e.slice(),r=1;t>=r;r++)for(var s=0;t-r>=s;s++)i[s]=i[s].multiply(1-n).add(i[s+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,r=e-t;r>=i;i++)n[i]/=n[r];return n},findMaxError:function(t,e,n,i){for(var r=Math.floor((e-t+1)/2),s=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>=s&&(s=u,r=a)}return{error:s,index:r}}}),E=w.extend({_class:"TextItem",_boundsSelected:!0,_applyMatrix:!1,_canApplyMatrix:!1,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(t){this._content="",this._lines=[];var n=t&&i.isPlainObject(t)&&t.x===e&&t.y===e;this._initialize(n&&t,!n&&l.read(arguments))},_equals:function(t){return this._content===t._content},copyContent:function(t){this.setContent(t._content)},getContent:function(){return this._content},setContent:function(t){this._content=""+t,this._lines=this._content.split(/\r\n|\n|\r/gm),this._changed(265)},isEmpty:function(){return!this._content},getCharacterStyle:"#getStyle",setCharacterStyle:"#setStyle",getParagraphStyle:"#getStyle",setParagraphStyle:"#setStyle"}),D=E.extend({_class:"PointText",initialize:function(){E.apply(this,arguments)},getPoint:function(){var t=this._matrix.getTranslation();return new c(t.x,t.y,this,"setPoint")},setPoint:function(){var t=l.read(arguments);this.translate(t.subtract(this._matrix.getTranslation()))},_draw:function(t){if(this._content){this._setStyles(t);var e=this._lines,n=this._style,i=n.hasFill(),r=n.hasStroke(),s=n.getLeading(),a=t.shadowBlur;t.font=n.getFontStyle(),t.textAlign=n.getJustification();for(var o=0,h=e.length;h>o;o++){t.shadowBlur=a;var u=e[o];i&&(t.fillText(u,0,0),t.shadowBlur=0),r&&t.strokeText(u,0,0),t.translate(0,s)}}},_getBounds:function(t,e){var n=this._style,i=this._lines,r=i.length,s=n.getJustification(),a=n.getLeading(),o=this.getView().getTextWidth(n.getFontStyle(),i),h=0;"left"!==s&&(h-=o/("center"===s?2:1));var u=new f(h,r?-.75*a:0,o,r*a);return e?e._transformBounds(u,u):u}}),j=i.extend(new function(){function t(t){var n,i=t.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/);if(i){n=[0,0,0];for(var r=0;3>r;r++){var a=i[r+1];n[r]=parseInt(1==a.length?a+a:a,16)/255}}else if(i=t.match(/^rgba?\((.*)\)$/)){n=i[1].split(",");for(var r=0,o=n.length;o>r;r++){var a=+n[r];n[r]=3>r?a/255:a}}else{var h=s[t];if(!h){e||(e=K.getContext(1,1),e.globalCompositeOperation="copy"),e.fillStyle="rgba(0,0,0,0)",e.fillStyle=t,e.fillRect(0,0,1,1);var u=e.getImageData(0,0,1,1).data;h=s[t]=[u[0]/255,u[1]/255,u[2]/255]}n=h.slice()}return n}var e,n={gray:["gray"],rgb:["red","green","blue"],hsb:["hue","saturation","brightness"],hsl:["hue","saturation","lightness"],gradient:["gradient","origin","destination","highlight"]},r={},s={},a=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]],h={"rgb-hsb":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4);return[a,0===i?0:s/i,i]},"hsb-rgb":function(t,e,n){t=(t/60%6+6)%6;var i=Math.floor(t),r=t-i,i=a[i],s=[n,n*(1-e),n*(1-e*r),n*(1-e*(1-r))];return[s[i[0]],s[i[1]],s[i[2]]]},"rgb-hsl":function(t,e,n){var i=Math.max(t,e,n),r=Math.min(t,e,n),s=i-r,a=0===s,o=a?0:60*(i==t?(e-n)/s+(n>e?6:0):i==e?(n-t)/s+2:(t-e)/s+4),h=(i+r)/2,u=a?0:.5>h?s/(i+r):s/(2-i-r);return[o,u,h]},"hsl-rgb":function(t,e,n){if(t=(t/360%1+1)%1,0===e)return[n,n,n];for(var i=[t+1/3,t,t-1/3],r=.5>n?n*(1+e):n+e-n*e,s=2*n-r,a=[],o=0;3>o;o++){var h=i[o];0>h&&(h+=1),h>1&&(h-=1),a[o]=1>6*h?s+6*(r-s)*h:1>2*h?r:2>3*h?s+(r-s)*(2/3-h)*6:s}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 i.each(n,function(t,e){r[e]=[],i.each(t,function(t,s){var a=i.capitalize(t),o=/^(hue|saturation)$/.test(t),h=r[e][s]="gradient"===t?function(t){var e=this._components[0];return t=F.read(Array.isArray(t)?t:arguments,0,{readNull:!0}),e!==t&&(e&&e._removeOwner(this),t&&t._addOwner(this)),t}:"gradient"===e?function(){return l.read(arguments,0,{readNull:"highlight"===t,clone:!0})}:function(t){return null==t||isNaN(t)?0:t};this["get"+a]=function(){return this._type===e||o&&/^hs[bl]$/.test(this._type)?this._components[s]:this._convert(e)[s]},this["set"+a]=function(t){this._type===e||o&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(e),this._properties=n[e],this._type=e),this._components[s]=h.call(this,t),this._changed()}},this)},{_class:"Color",_readIndex:!0,initialize:function c(e){var i,s,a,o,h=Array.prototype.slice,l=arguments,d=0;Array.isArray(e)&&(l=e,e=l[0]);var _=null!=e&&typeof e;if("string"===_&&e in n&&(i=e,e=l[1],Array.isArray(e)?(s=e,a=l[2]):(this.__read&&(d=1),l=h.call(l,1),_=typeof e)),!s){if(o="number"===_?l:"object"===_&&null!=e.length?e:null){i||(i=o.length>=3?"rgb":"gray");var f=n[i].length;a=o[f],this.__read&&(d+=o===arguments?f+(null!=a?1:0):1),o.length>f&&(o=h.call(o,0,f))}else if("string"===_)i="rgb",s=t(e),4===s.length&&(a=s[3],s.length--);else if("object"===_)if(e.constructor===c){if(i=e._type,s=e._components.slice(),a=e._alpha,"gradient"===i)for(var g=1,v=s.length;v>g;g++){var p=s[g];p&&(s[g]=p.clone())}}else if(e.constructor===F)i="gradient",o=l;else{i="hue"in e?"lightness"in e?"hsl":"hsb":"gradient"in e||"stops"in e||"radial"in e?"gradient":"gray"in e?"gray":"rgb";var m=n[i],y=r[i];this._components=s=[];for(var g=0,v=m.length;v>g;g++){var w=e[m[g]];null==w&&0===g&&"gradient"===i&&"stops"in e&&(w={stops:e.stops,radial:e.radial}),w=y[g].call(this,w),null!=w&&(s[g]=w)}a=e.alpha}this.__read&&i&&(d=1)}if(this._type=i||"rgb",this._id=u.get(c),!s){this._components=s=[];for(var y=r[this._type],g=0,v=y.length;v>g;g++){var w=y[g].call(this,o&&o[g]);null!=w&&(s[g]=w)}}this._components=s,this._properties=n[this._type],this._alpha=a,this.__read&&(this.__read=d)},_serialize:function(t,e){var n=this.getComponents();return i.serialize(/^(gray|rgb)$/.test(this._type)?n:[this._type].concat(n),t,!0,e)},_changed:function(){this._canvasStyle=null,this._owner&&this._owner._changed(65)},_convert:function(t){var e;return this._type===t?this._components.slice():(e=h[this._type+"-"+t])?e.apply(this,this._components):h["rgb-"+t].apply(this,h[this._type+"-rgb"].apply(this,this._components))},convert:function(t){return new j(t,this._convert(t),this._alpha)},getType:function(){return this._type},setType:function(t){this._components=this._convert(t),this._properties=n[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(t){var e=i.isPlainValue(t,!0)?j.read(arguments):t;return e===this||e&&this._class===e._class&&this._type===e._type&&this._alpha===e._alpha&&i.equals(this._components,e._components)||!1},toString:function(){for(var t=this._properties,e=[],n="gradient"===this._type,i=o.instance,r=0,s=t.length;s>r;r++){var a=this._components[r];null!=a&&e.push(t[r]+": "+(n?a:i.number(a)))}return null!=this._alpha&&e.push("alpha: "+i.number(this._alpha)),"{ "+e.join(", ")+" }"},toCSS:function(t){function e(t){return Math.round(255*(0>t?0:t>1?1:t))}var n=this._convert("rgb"),i=t||null==this._alpha?1:this._alpha;return n=[e(n[0]),e(n[1]),e(n[2])],1>i&&n.push(0>i?0:i),t?"#"+((1<<24)+(n[0]<<16)+(n[1]<<8)+n[2]).toString(16).slice(1):(4==n.length?"rgba(":"rgb(")+n.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],r=i._stops,s=n[1],a=n[2];if(i._radial){var o=a.getDistance(s),h=n[3];if(h){var u=h.subtract(s);u.getLength()>o&&(h=s.add(u.normalize(o-.1)))}var l=h||s;e=t.createRadialGradient(l.x,l.y,0,s.x,s.y,o)}else e=t.createLinearGradient(s.x,s.y,a.x,a.y);for(var c=0,d=r.length;d>c;c++){var _=r[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 r=e[n];t._transformPoint(r,r,!0)}this._changed()}},statics:{_types:n,random:function(){var t=Math.random;return new j(t(),t(),t())}}})},new function(){var t={add:function(t,e){return t+e},subtract:function(t,e){return t-e},multiply:function(t,e){return t*e},divide:function(t,e){return t/e}};return i.each(t,function(t,e){this[e]=function(e){e=j.read(arguments);for(var n=this._type,i=this._components,r=e._convert(n),s=0,a=i.length;a>s;s++)r[s]=t(i[s],r[s]);return new j(n,r,null!=this._alpha?t(this._alpha,e.getAlpha()):null)}},{})}),F=i.extend({_class:"Gradient",initialize:function(t,e){this._id=u.get(),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(t,e){return e.add(this,function(){return i.serialize([this._stops,this._radial],t,!0,e)})},_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 n=this._owners?this._owners.indexOf(t):-1;-1!=n&&(this._owners.splice(n,1),0===this._owners.length&&(this._owners=e))},clone:function(){for(var t=[],e=0,n=this._stops.length;n>e;e++)t[e]=this._stops[e].clone();return new F(t,this._radial)},getStops:function(){return this._stops},setStops:function(t){if(this.stops)for(var n=0,i=this._stops.length;i>n;n++)this._stops[n]._owner=e;if(t.length<2)throw new Error("Gradient stop list needs to contain at least two stops.");this._stops=R.readAll(t,0,{clone:!0});for(var n=0,i=this._stops.length;i>n;n++){var r=this._stops[n];r._owner=this,r._defaultRamp&&r.setRampPoint(n/(i-1))}this._changed()},getRadial:function(){return this._radial},setRadial:function(t){this._radial=t,this._changed()},equals:function(t){if(t===this)return!0;if(t&&this._class===t._class&&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}}),R=i.extend({_class:"GradientStop",initialize:function(t,n){if(t){var i,r;n===e&&Array.isArray(t)?(i=t[0],r=t[1]):t.color?(i=t.color,r=t.rampPoint):(i=t,r=n),this.setColor(i),this.setRampPoint(r)}},clone:function(){return new R(this._color.clone(),this._rampPoint)},_serialize:function(t,e){return i.serialize([this._color,this._rampPoint],t,!0,e)},_changed:function(){this._owner&&this._owner._changed(65)},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=j.read(arguments),this._color===t&&(this._color=t.clone()),this._color._owner=this,this._changed()},equals:function(t){return t===this||t&&this._class===t._class&&this._color.equals(t._color)&&this._rampPoint==t._rampPoint||!1}}),q=i.extend(new function(){var t={fillColor:e,fillRule:"nonzero",strokeColor:e,strokeWidth:1,strokeCap:"butt",strokeJoin:"miter",strokeScaling:!0,miterLimit:10,dashOffset:0,dashArray:[],shadowColor:e,shadowBlur:0,shadowOffset:new l,selectedColor:e,fontFamily:"sans-serif",fontWeight:"normal",fontSize:12,font:"sans-serif",leading:null,justification:"left"},n={strokeWidth:97,strokeCap:97,strokeJoin:97,strokeScaling:105,miterLimit:97,fontFamily:9,fontWeight:9,fontSize:9,font:9,leading:9,justification:9},r={beans:!0},s={_defaults:t,_textDefaults:new i(t,{fillColor:new j}),beans:!0};return i.each(t,function(t,a){var o=/Color$/.test(a),h="shadowOffset"===a,u=i.capitalize(a),c=n[a],d="set"+u,_="get"+u;s[d]=function(t){var n=this._owner,i=n&&n._children;if(i&&i.length>0&&!(n instanceof N))for(var r=0,s=i.length;s>r;r++)i[r]._style[d](t);else{var h=this._values[a];h!==t&&(o&&(h&&(h._owner=e),t&&t.constructor===j&&(t._owner&&(t=t.clone()),t._owner=n)),this._values[a]=t,n&&n._changed(c||65))}},s[_]=function(t){var n,r=this._owner,s=r&&r._children;if(!s||0===s.length||t||r instanceof N){var n=this._values[a];if(n===e)n=this._defaults[a],n&&n.clone&&(n=n.clone());else{var u=o?j:h?l:null;!u||n&&n.constructor===u||(this._values[a]=n=u.read([n],0,{readNull:!0,clone:!0}),n&&o&&(n._owner=r))}return n}for(var c=0,d=s.length;d>c;c++){var f=s[c]._style[_]();if(0===c)n=f;else if(!i.equals(n,f))return e}return n},r[_]=function(t){return this._style[_](t)},r[d]=function(t){this._style[d](t)}}),i.each({Font:"FontFamily",WindingRule:"FillRule"},function(t,e){var n="get"+e,i="set"+e;s[n]=r[n]="#get"+t,s[i]=r[i]="#set"+t}),w.inject(r),s},{_class:"Style",initialize:function(t,e,n){this._values={},this._owner=e,this._project=e&&e._project||n||paper.project,e instanceof E&&(this._defaults=this._textDefaults),t&&this.set(t)},set:function(t){var e=t instanceof q,n=e?t._values:t;if(n)for(var i in n)if(i in this._defaults){var r=n[i];this[i]=r&&e&&r.clone?r.clone():r}},equals:function(t){return t===this||t&&this._class===t._class&&i.equals(this._values,t._values)||!1},hasFill:function(){return!!this.getFillColor()},hasStroke:function(){return!!this.getStrokeColor()&&this.getStrokeWidth()>0},hasShadow:function(){return!!this.getShadowColor()&&this.getShadowBlur()>0},getView:function(){return this._project._view},getFontStyle:function(){var t=this.getFontSize();return this.getFontWeight()+" "+t+(/[a-z]/i.test(t+"")?" ":"px ")+this.getFontFamily()},getFont:"#getFontFamily",setFont:"#setFontFamily",getLeading:function pt(){var t=pt.base.call(this),e=this.getFontSize();return/pt|em|%|px/.test(e)&&(e=this.getView().getPixelSize(e)),null!=t?t:1.2*e}}),V=new function(){function t(t,e,n,i){for(var r=["","webkit","moz","Moz","ms","o"],s=e[0].toUpperCase()+e.substring(1),a=0;6>a;a++){var o=r[a],h=o?o+s:e;if(h in t){if(!n)return t[h];t[h]=i;break}}}return{getStyles:function(t){var e=t&&9!==t.nodeType?t.ownerDocument:t,n=e&&e.defaultView;return n&&n.getComputedStyle(t,"")},getBounds:function(t,e){var n,i=t.ownerDocument,r=i.body,s=i.documentElement;try{n=t.getBoundingClientRect()}catch(a){n={left:0,top:0,width:0,height:0}}var o=n.left-(s.clientLeft||r.clientLeft||0),h=n.top-(s.clientTop||r.clientTop||0);if(!e){var u=i.defaultView;o+=u.pageXOffset||s.scrollLeft||r.scrollLeft,h+=u.pageYOffset||s.scrollTop||r.scrollTop}return new f(o,h,n.width,n.height)},getViewportBounds:function(t){var e=t.ownerDocument,n=e.defaultView,i=e.documentElement;return new f(0,0,n.innerWidth||i.clientWidth,n.innerHeight||i.clientHeight)},getOffset:function(t,e){return V.getBounds(t,e).getPoint()},getSize:function(t){return V.getBounds(t,!0).getSize()},isInvisible:function(t){return V.getSize(t).equals(new d(0,0))},isInView:function(t){return!V.isInvisible(t)&&V.getViewportBounds(t).intersects(V.getBounds(t,!0))},isInserted:function(t){return n.body.contains(t)},getPrefixed:function(e,n){return t(e,n)},setPrefixed:function(e,n,i){if("object"==typeof n)for(var r in n)t(e,r,!0,n[r]);else t(e,n,!0,i)}}},H={add:function(t,e){for(var n in e)for(var i=e[n],r=n.split(/[\s,]+/g),s=0,a=r.length;a>s;s++)t.addEventListener(r[s],i,!1)},remove:function(t,e){for(var n in e)for(var i=e[n],r=n.split(/[\s,]+/g),s=0,a=r.length;a>s;s++)t.removeEventListener(r[s],i,!1)},getPoint:function(t){var e=t.targetTouches?t.targetTouches.length?t.targetTouches[0]:t.changedTouches[0]:t;return new l(e.pageX||e.clientX+n.documentElement.scrollLeft,e.pageY||e.clientY+n.documentElement.scrollTop)},getTarget:function(t){return t.target||t.srcElement},getRelatedTarget:function(t){return t.relatedTarget||t.toElement},getOffset:function(t,e){return H.getPoint(t).subtract(V.getOffset(e||H.getTarget(t)))}};H.requestAnimationFrame=new function(){function e(){for(var t=a.length-1;t>=0;t--){var n=a[t],h=n[0],u=n[1];(!u||("true"==s.getAttribute(u,"keepalive")||o)&&V.isInView(u))&&(a.splice(t,1),h())}i&&(a.length?i(e):r=!1)}var n,i=V.getPrefixed(t,"requestAnimationFrame"),r=!1,a=[],o=!0;return H.add(t,{focus:function(){o=!0},blur:function(){o=!1}}),function(t,s){a.push([t,s]),i?r||(i(e),r=!0):n||(n=setInterval(e,1e3/60))}};var Z=i.extend(r,{_class:"View",initialize:function mt(e,i){function r(t){return i[t]||parseInt(i.getAttribute(t),10)}function a(){var t=V.getSize(i);return t.isNaN()||t.isZero()?new d(r("width"),r("height")):t}this._project=e,this._scope=e._scope,this._element=i,this._pixelRatio||(this._pixelRatio=t.devicePixelRatio||1),this._id=i.getAttribute("id"),null==this._id&&i.setAttribute("id",this._id="view-"+mt._id++),H.add(i,this._viewEvents);var o="none";if(V.setPrefixed(i.style,{userDrag:o,userSelect:o,touchCallout:o,contentZooming:o,tapHighlightColor:"rgba(0,0,0,0)"}),s.hasAttribute(i,"resize")){var h=this;H.add(t,this._windowEvents={resize:function(){h.setViewSize(a())}})}var u=this._viewSize=a();if(this._setViewSize(u.width,u.height),s.hasAttribute(i,"stats")&&"undefined"!=typeof Stats){this._stats=new Stats;var l=this._stats.domElement,c=l.style,_=V.getOffset(i);c.position="absolute",c.left=_.x+"px",c.top=_.y+"px",n.body.appendChild(l)}mt._views.push(this),mt._viewsById[this._id]=this,(this._matrix=new v)._owner=this,this._zoom=1,mt._focused||(mt._focused=this),this._frameItems={},this._frameItemCount=0,this._itemEvents={"native":{},virtual:{}},this._autoUpdate=!paper.agent.node},remove:function(){if(!this._project)return!1;Z._focused===this&&(Z._focused=null),Z._views.splice(Z._views.indexOf(this),1),delete Z._viewsById[this._id];
var e=this._project;return e._view===this&&(e._view=null),H.remove(this._element,this._viewEvents),H.remove(t,this._windowEvents),this._element=this._project=null,this.off("frame"),this._animate=!1,this._frameItems={},!0},_events:i.each(w._itemHandlers.concat(["onResize","onKeyDown","onKeyUp"]),function(t){this[t]={}},{onFrame:{install:function(){this.play()},uninstall:function(){this.pause()}}}),_animate:!1,_time:0,_count:0,getAutoUpdate:function(){return this._autoUpdate},setAutoUpdate:function(t){this._autoUpdate=t,t&&this.requestUpdate()},draw:function(){this.update()},requestUpdate:function(){if(!this._requested){var t=this;H.requestAnimationFrame(function(){t._requested=!1,t._animate&&(t.requestUpdate(),t._handleFrame()),t._autoUpdate&&t.update()},this._element),this._requested=!0}},play:function(){this._animate=!0,this.requestUpdate()},pause:function(){this._animate=!1},_handleFrame:function(){paper=this._scope;var t=Date.now()/1e3,e=this._last?t-this._last:0;this._last=t,this.emit("frame",new i({delta:e,time:this._time+=e,count:this._count++})),this._stats&&this._stats.update()},_animateItem:function(t,e){var n=this._frameItems;e?(n[t._id]={item:t,time:0,count:0},1===++this._frameItemCount&&this.on("frame",this._handleFrameItems)):(delete n[t._id],0===--this._frameItemCount&&this.off("frame",this._handleFrameItems))},_handleFrameItems:function(t){for(var e in this._frameItems){var n=this._frameItems[e];n.item.emit("frame",new i(t,{time:n.time+=t.delta,count:n.count++}))}},_changed:function(){this._project._changed(2049),this._bounds=null},getElement:function(){return this._element},getPixelRatio:function(){return this._pixelRatio},getResolution:function(){return 72*this._pixelRatio},getViewSize:function(){var t=this._viewSize;return new _(t.width,t.height,this,"setViewSize")},setViewSize:function(){var t=d.read(arguments),e=t.width,n=t.height,i=t.subtract(this._viewSize);i.isZero()||(this._viewSize.set(e,n),this._setViewSize(e,n),this.emit("resize",{size:t,delta:i}),this._changed(),this._autoUpdate&&this.requestUpdate())},_setViewSize:function(t,e){var n=this._element;n.width!==t&&(n.width=t),n.height!==e&&(n.height=e)},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new f(new l,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize()},getCenter:function(){return this.getBounds().getCenter()},setCenter:function(){var t=l.read(arguments);this.translate(this.getCenter().subtract(t))},getZoom:function(){return this._zoom},setZoom:function(t){this.transform((new v).scale(t/this._zoom,this.getCenter())),this._zoom=t},getMatrix:function(){return this._matrix},setMatrix:function(){var t=this._matrix;t.initialize.apply(t,arguments)},isVisible:function(){return V.isInView(this._element)},isInserted:function(){return V.isInserted(this._element)}},i.each(["rotate","scale","shear","skew"],function(t){var e="rotate"===t;this[t]=function(){var n=(e?i:l).read(arguments),r=l.read(arguments,0,{readNull:!0});return this.transform((new v)[t](n,r||this.getCenter(!0)))}},{translate:function(){var t=new v;return this.transform(t.translate.apply(t,arguments))},transform:function(t){this._matrix.append(t)},scrollBy:function(){this.translate(l.read(arguments).negate())}}),{projectToView:function(){return this._matrix._transformPoint(l.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(l.read(arguments))},getEventPoint:function(t){return this.viewToProject(H.getOffset(t,this._element))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t,e){return"string"==typeof e&&(e=n.getElementById(e)),new G(t,e)}}},new function(){function i(t){var e=H.getTarget(t);return e.getAttribute&&Z._viewsById[e.getAttribute("id")]}function r(){var t=Z._focused;if(!t||!t.isVisible())for(var e=0,n=Z._views.length;n>e;e++)if((t=Z._views[e]).isVisible()){Z._focused=u=t;break}}function s(t,e,n){t._handleMouseEvent("mousemove",e,n)}function a(t,e,n,i,r,s){function a(t,e){if(t.responds(e)){if(o||(o=new X(e,n,i,h,r?i.subtract(r):null)),t.emit(e,o)&&(I=!0,o.stopped))return!0}else{var s=z[e];if(s)return a(t,s)}}for(var o,h=t;t&&t!==s;){if(a(t,e))return!0;t=t._parent}return!1}function o(t,e,n,i,r,s){return t._project.removeOn(n),I=!1,b&&a(b,n,i,r,s)||e&&e!==b&&!e.isDescendant(b)&&a(e,z[n]||n,i,r,s,b)||a(t,n,i,r,s)}var h,u,l,c,d,_=!1,f=!1,g=t.navigator;g.pointerEnabled||g.msPointerEnabled?(l="pointerdown MSPointerDown",c="pointermove MSPointerMove",d="pointerup pointercancel MSPointerUp MSPointerCancel"):(l="touchstart",c="touchmove",d="touchend touchcancel","ontouchstart"in t&&g.userAgent.match(/mobile|tablet|ip(ad|hone|od)|android|silk/i)||(l+=" mousedown",c+=" mousemove",d+=" mouseup"));var v={},p={mouseout:function(t){var e=Z._focused,n=H.getRelatedTarget(t);if(e&&(!n||"HTML"===n.nodeName)){var i=H.getOffset(t,e._element),r=i.x,a=Math.abs,o=a(r),h=1<<25,u=o-h;i.x=a(u)<o?u*(0>r?-1:1):r,s(e,t,e.viewToProject(i))}},scroll:r};v[l]=function(t){var e=Z._focused=i(t);_||(_=!0,e._handleMouseEvent("mousedown",t))},p[c]=function(t){var e=Z._focused;if(!f){var n=i(t);n?e!==n&&(e&&s(e,t),h||(h=e),e=Z._focused=u=n):u&&u===e&&(h&&!h.isInserted()&&(h=null),e=Z._focused=h,h=null,r())}e&&s(e,t)},p[l]=function(){f=!0},p[d]=function(t){var e=Z._focused;e&&_&&e._handleMouseEvent("mouseup",t),f=_=!1},H.add(n,p),H.add(t,{load:r});var m,y,w,x,b,S,C,P,M,I=!1,z={doubleclick:"click",mousedrag:"mousemove"},k={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}},O=!1;return{_viewEvents:v,_handleMouseEvent:function(t,n,i){function r(t){return s.virtual[t]||l.responds(t)||u&&u.responds(t)}var s=this._itemEvents,h=s["native"][t],u=this._scope.tool,l=this;"mousemove"===t&&_&&r("mousedrag")&&(t="mousedrag"),i||(i=this.getEventPoint(n));var c=this.getBounds().contains(i),d=c&&h&&this._project.hitTest(i,{tolerance:0,fill:!0,stroke:!0}),f=d&&d.item||e,g=!1,v={};v[t.substr(5)]=!0;var p=v.move||v.drag?t:"mousemove";if(f!==x&&(x&&a(x,"mouseleave",n,i),f&&a(f,"mouseenter",n,i)),x=f,O^c&&(a(this,c?"mouseenter":"mouseleave",n,i),M=c?this:null,g=!0),!c&&!v.drag||i.equals(y)||(o(this,f,p,n,i,y),g=!0),O=c,v.down&&c||v.up&&m){var z=o(this,f,t,n,i,m);v.down?(P=f===S&&Date.now()-C<300,w=S=f,b=!z&&f,m=y=i):v.up&&(z||f!==w||(C=Date.now(),o(this,f,P?"doubleclick":"click",n,i,m),P=!1),w=b=null),O=!1,g=!0}y=i,g&&u&&(I=u._handleMouseEvent(t,n,i,v)||I),(I&&!v.move||v.down&&r("mouseup"))&&n.preventDefault()},_handleKeyEvent:function(t,e,n,i){function r(r){r.responds(t)&&(paper=a,r.emit(t,s=s||new W(t,e,n,i)))}var s,a=this._scope,o=a.tool;this.isVisible()&&(r(this),o&&o.responds(t)&&r(o))},_countItemEvent:function(t,e){var n=this._itemEvents,i=n["native"],r=n.virtual;for(var s in k)i[s]=(i[s]||0)+(k[s][t]||0)*e;r[t]=(r[t]||0)+e},statics:{updateFocus:r}}}),G=Z.extend({_class:"CanvasView",initialize:function(e,n){if(!(n instanceof t.HTMLCanvasElement)){var i=d.read(arguments,1);if(i.isZero())throw new Error("Cannot create CanvasView with the provided argument: "+[].slice.call(arguments,1));n=K.getCanvas(i)}var r=this._context=n.getContext("2d");if(r.save(),this._pixelRatio=1,!/^off|false$/.test(s.getAttribute(n,"hidpi"))){var a=t.devicePixelRatio||1,o=V.getPrefixed(r,"backingStorePixelRatio")||1;this._pixelRatio=a/o}Z.call(this,e,n)},remove:function yt(){return this._context.restore(),yt.base.call(this)},_setViewSize:function wt(t,e){var n=this._pixelRatio;if(wt.base.call(this,t*n,e*n),1!==n){var i=this._element,r=this._context;if(!s.hasAttribute(i,"resize")){var a=i.style;a.width=t+"px",a.height=e+"px"}r.restore(),r.save(),r.scale(n,n)}},getPixelSize:function(t){var e,i=paper.agent;if(i&&i.firefox){var r=this._element.parentNode,s=n.createElement("div");s.style.fontSize=t,r.appendChild(s),e=parseFloat(V.getStyles(s).fontSize),r.removeChild(s)}else{var a=this._context,o=a.font;a.font=t+" serif",e=parseFloat(a.font),a.font=o}return e},getTextWidth:function(t,e){var n=this._context,i=n.font,r=0;n.font=t;for(var s=0,a=e.length;a>s;s++)r=Math.max(r,n.measureText(e[s]).width);return n.font=i,r},update:function(){var t=this._project;if(!t||!t._needsUpdate)return!1;var e=this._context,n=this._viewSize;return e.clearRect(0,0,n.width+1,n.height+1),t.draw(e,this._matrix,this._pixelRatio),t._needsUpdate=!1,!0}}),U=i.extend({_class:"Event",initialize:function(t){this.event=t,this.type=t&&t.type},prevented:!1,stopped:!1,preventDefault:function(){this.prevented=!0,this.event.preventDefault()},stopPropagation:function(){this.stopped=!0,this.event.stopPropagation()},stop:function(){this.stopPropagation(),this.preventDefault()},getTimeStamp:function(){return this.event.timeStamp},getModifiers:function(){return J.modifiers}}),W=U.extend({_class:"KeyEvent",initialize:function(t,e,n,i){this.type=t,this.event=e,this.key=n,this.character=i},toString:function(){return"{ type: '"+this.type+"', key: '"+this.key+"', character: '"+this.character+"', modifiers: "+this.getModifiers()+" }"}}),J=new function(){function e(t){var e=t.key||t.keyIdentifier;return e=/^U\+/.test(e)?String.fromCharCode(parseInt(e.substr(2),16)):/^Arrow[A-Z]/.test(e)?e.substr(5):"Unidentified"===e?String.fromCharCode(t.keyCode):e,o[e]||(e.length>1?i.hyphenate(e):e.toLowerCase())}function r(t,e,n,a){var o,h=Z._focused;if(u[e]=t,t?l[e]=n:delete l[e],e.length>1&&(o=i.camelize(e))in modifiers){modifiers[o]=t;var c=paper.agent;if("meta"===o&&c&&c.mac)if(t)s={};else{for(var d in s)d in l&&r(!1,d,s[d],a);s=null}}else t&&s&&(s[e]=n);h&&h._handleKeyEvent(t?"keydown":"keyup",a,e,n)}var s,a,o={" ":"tab"," ":"space","\b":"backspace","":"delete",Spacebar:"space",Del:"delete",Win:"meta",Esc:"escape"},h={tab:" ",space:" ",enter:"\r"},u={},l={};return modifiers=new i({shift:!1,control:!1,alt:!1,meta:!1,capsLock:!1,space:!1}).inject({option:{get:function(){return this.alt}},command:{get:function(){var t=paper.agent;return t&&t.mac?this.meta:this.control}}}),H.add(n,{keydown:function(t){var n=e(t),i=paper.agent;n.length>1||i&&i.chrome&&(t.altKey||i.mac&&t.metaKey||!i.mac&&t.ctrlKey)?r(!0,n,h[n]||(n.length>1?"":n),t):a=n},keypress:function(t){if(a){var n=e(t),i=t.charCode,s=i>=32?String.fromCharCode(i):n.length>1?"":n;n!==a&&(n=s.toLowerCase()),r(!0,n,s,t),a=null}},keyup:function(t){var n=e(t);n in l&&r(!1,n,l[n],t)}}),H.add(t,{blur:function(t){for(var e in l)r(!1,e,l[e],t)}}),{modifiers:modifiers,isDown:function(t){return!!u[t]}}},X=U.extend({_class:"MouseEvent",initialize:function(t,e,n,i,r){this.type=t,this.event=e,this.point=n,this.target=i,this.delta=r},toString:function(){return"{ type: '"+this.type+"', point: "+this.point+", target: "+this.target+(this.delta?", delta: "+this.delta:"")+", modifiers: "+this.getModifiers()+" }"}}),Y=U.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|CompoundPath)$/.test(n._class);)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()+" }"}}),$=(a.extend({_class:"Tool",_list:"tools",_reference:"tool",_events:["onMouseDown","onMouseUp","onMouseDrag","onMouseMove","onActivate","onDeactivate","onEditOptions","onKeyDown","onKeyUp"],initialize:function(t){a.call(this),this._firstMove=!0,this._count=0,this._downCount=-1,this._set(t)},getMinDistance:function(){return this._minDistance},setMinDistance:function(t){this._minDistance=t,null!=t&&null!=this._maxDistance&&t>this._maxDistance&&(this._maxDistance=t)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(t){this._maxDistance=t,null!=this._minDistance&&null!=t&&t<this._minDistance&&(this._minDistance=t)},getFixedDistance:function(){return this._minDistance==this._maxDistance?this._minDistance:null},setFixedDistance:function(t){this._minDistance=this._maxDistance=t},_handleMouseEvent:function(t,e,n,i){function r(t,e,r){var s=c._point,h=n;if(t)c._count=0;else{if(h.equals(s))return!1;if(null!=e||null!=r){var u=h.subtract(s),l=u.getLength();if((e||0)>l)return!1;r&&(h=s.add(u.normalize(Math.min(l,r))))}c._count++}return o&&(c._point=h,c._lastPoint=a||i.drag?t&&a?h:s:c._downPoint||h),i.down&&(c._downPoint=h,c._downCount++),!0}function s(n){o&&(l=c.emit(t,new Y(c,t,e))||l,c._firstMove=n)}paper=this._scope;var a=i.move||i.drag&&!this.responds(t);a&&(t="mousemove");var o=this.responds(t),h=this.minDistance,u=this.maxDistance,l=!1,c=this;if(i.down)r(o),s(!1);else if(i.up)r(!1,null,u),s(!0);else if(o)for(;r(this._firstMove,h,u);)s(!1);return l}}),{request:function(n,i,r,s){s=s===e?!0:s;var a=t.ActiveXObject||t.XMLHttpRequest,o=new a("Microsoft.XMLHTTP");return o.open(n.toUpperCase(),i,s),"overrideMimeType"in o&&o.overrideMimeType("text/plain"),o.onreadystatechange=function(){if(4===o.readyState){var t=o.status;if(0!==t&&200!==t)throw new Error("Could not load "+i+" (Error "+t+")");r.call(o,o.responseText)}},o.send(null)}}),K={canvases:[],getCanvas:function(t,e){var i,r=!0;"object"==typeof t&&(e=t.height,t=t.width),this.canvases.length?i=this.canvases.pop():(i=n.createElement("canvas"),r=!1);var s=i.getContext("2d");return i.width===t&&i.height===e?r&&s.clearRect(0,0,t+1,e+1):(i.width=t,i.height=e),s.save(),i},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)}},Q=new function(){function t(t,e,n){return.2989*t+.587*e+.114*n}function e(e,n,i,r){var s=r-t(e,n,i);_=e+s,f=n+s,g=i+s;var r=t(_,f,g),a=v(_,f,g),o=p(_,f,g);if(0>a){var h=r-a;_=r+(_-r)*r/h,f=r+(f-r)*r/h,g=r+(g-r)*r/h}if(o>255){var u=255-r,l=o-r;_=r+(_-r)*u/l,f=r+(f-r)*u/l,g=r+(g-r)*u/l}}function n(t,e,n){return p(t,e,n)-v(t,e,n)}function r(t,e,n,i){var r,s=[t,e,n],a=p(t,e,n),o=v(t,e,n);o=o===t?0:o===e?1:2,a=a===t?0:a===e?1:2,r=0===v(o,a)?1===p(o,a)?2:1:0,s[a]>s[o]?(s[r]=(s[r]-s[o])*i/(s[a]-s[o]),s[a]=i):s[r]=s[a]=0,s[o]=0,_=s[0],f=s[1],g=s[2]}var s,a,o,h,u,l,c,d,_,f,g,v=Math.min,p=Math.max,m=Math.abs,y={multiply:function(){_=u*s/255,f=l*a/255,g=c*o/255},screen:function(){_=u+s-u*s/255,f=l+a-l*a/255,g=c+o-c*o/255},overlay:function(){_=128>u?2*u*s/255:255-2*(255-u)*(255-s)/255,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},"soft-light":function(){var t=s*u/255;_=t+u*(255-(255-u)*(255-s)/255-t)/255,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},"hard-light":function(){_=128>s?2*s*u/255:255-2*(255-s)*(255-u)/255,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},"color-dodge":function(){_=0===u?0:255===s?255:v(255,255*u/(255-s)),f=0===l?0:255===a?255:v(255,255*l/(255-a)),g=0===c?0:255===o?255:v(255,255*c/(255-o))},"color-burn":function(){_=255===u?255:0===s?0:p(0,255-255*(255-u)/s),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)},darken:function(){_=s>u?u:s,f=a>l?l:a,g=o>c?c:o},lighten:function(){_=u>s?u:s,f=l>a?l:a,g=c>o?c:o},difference:function(){_=u-s,0>_&&(_=-_),f=l-a,0>f&&(f=-f),g=c-o,0>g&&(g=-g)},exclusion:function(){_=u+s*(255-u-u)/255,f=l+a*(255-l-l)/255,g=c+o*(255-c-c)/255},hue:function(){r(s,a,o,n(u,l,c)),e(_,f,g,t(u,l,c))},saturation:function(){r(u,l,c,n(s,a,o)),e(_,f,g,t(u,l,c))},luminosity:function(){e(u,l,c,t(s,a,o))},color:function(){e(s,a,o,t(u,l,c))},add:function(){_=v(u+s,255),f=v(l+a,255),g=v(c+o,255)},subtract:function(){_=p(u-s,0),f=p(l-a,0),g=p(c-o,0)},average:function(){_=(u+s)/2,f=(l+a)/2,g=(c+o)/2},negation:function(){_=255-m(255-s-u),f=255-m(255-a-l),g=255-m(255-o-c)}},w=this.nativeModes=i.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(t){this[t]=!0},{}),x=K.getContext(1,1);i.each(y,function(t,e){var n="darken"===e,i=!1;x.save();try{x.fillStyle=n?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=e,x.globalCompositeOperation===e&&(x.fillStyle=n?"#a00":"#300",x.fillRect(0,0,1,1),i=x.getImageData(0,0,1,1).data[0]!==n?170:51)}catch(r){}x.restore(),w[e]=i}),K.release(x),this.process=function(t,e,n,i,r){var v=e.canvas,p="normal"===t;if(p||w[t])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=i,p||(n.globalCompositeOperation=t),n.drawImage(v,r.x,r.y),n.restore();else{var m=y[t];if(!m)return;for(var x=n.getImageData(r.x,r.y,v.width,v.height),b=x.data,S=e.getImageData(0,0,v.width,v.height).data,C=0,P=b.length;P>C;C+=4){s=S[C],u=b[C],a=S[C+1],l=b[C+1],o=S[C+2],c=b[C+2],h=S[C+3],d=b[C+3],m();var M=h*i/255,I=1-M;b[C]=M*_+I*u,b[C+1]=M*f+I*l,b[C+2]=M*g+I*c,b[C+3]=h*i+I*d}n.putImageData(x,r.x,r.y)}}},tt=i.each({fillColor:["fill","color"],fillRule:["fill-rule","string"],strokeColor:["stroke","color"],strokeWidth:["stroke-width","number"],strokeCap:["stroke-linecap","string"],strokeJoin:["stroke-linejoin","string"],strokeScaling:["vector-effect","lookup",{"true":"none","false":"non-scaling-stroke"},function(t,e){return!e&&(t instanceof A||t instanceof S||t instanceof E)}],miterLimit:["stroke-miterlimit","number"],dashArray:["stroke-dasharray","array"],dashOffset:["stroke-dashoffset","number"],fontFamily:["font-family","string"],fontWeight:["font-weight","string"],fontSize:["font-size","number"],justification:["text-anchor","lookup",{left:"start",center:"middle",right:"end"}],opacity:["opacity","number"],blendMode:["mix-blend-mode","style"]},function(t,e){var n=i.capitalize(e),r=t[2];this[e]={type:t[1],property:e,attribute:t[0],toSVG:r,fromSVG:r&&i.each(r,function(t,e){this[t]=e},{}),exportFilter:t[3],get:"get"+n,set:"set"+n}},{}),et={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],r=et[n];"number"==typeof i&&(i=C.number(i)),r?t.setAttributeNS(r,n,i):t.setAttribute(n,i)}return t}function r(t,i){return e(n.createElementNS("http://www.w3.org/2000/svg",t),i)}function s(t,e,n){var r=new i,s=t.getTranslation();if(e){t=t._shiftless();var a=t._inverseTransform(s);r[n?"cx":"x"]=a.x,r[n?"cy":"y"]=a.y,s=null}if(!t.isIdentity()){var o=t.decompose();if(o&&!o.shearing){var u=[],l=o.rotation,c=o.scaling;s&&!s.isZero()&&u.push("translate("+C.point(s)+")"),h.isZero(c.x-1)&&h.isZero(c.y-1)||u.push("scale("+C.point(c)+")"),l&&u.push("rotate("+C.number(l)+")"),r.transform=u.join(" ")}else r.transform="matrix("+t.getValues().join(",")+")"}return r}function a(t,n){for(var i=s(t._matrix),a=t._children,o=r("g",i),h=0,u=a.length;u>h;h++){var l=a[h],c=b(l,n);if(c)if(l.isClipMask()){var d=r("clipPath");d.appendChild(c),y(l,d,"clip"),e(o,{"clip-path":"url(#"+d.id+")"})}else o.appendChild(c)}return o}function u(t,e){var n=s(t._matrix,!0),i=t.getSize(),a=t.getImage();return n.x-=i.width/2,n.y-=i.height/2,n.width=i.width,n.height=i.height,n.href=e.embedImages===!1&&a&&a.src||t.toDataURL(),r("image",n)}function l(t,e){var n=e.matchShapes;if(n){var i=t.toShape(!1);if(i)return c(i,e)}var a,o=t._segments,h=s(t._matrix);if(0===o.length)return null;if(n&&!t.hasHandles())if(o.length>=3){a=t._closed?"polygon":"polyline";for(var u=[],l=0,d=o.length;d>l;l++)u.push(C.point(o[l]._point));h.points=u.join(" ")}else{a="line";var _=o[0]._point,f=o[o.length-1]._point;h.set({x1:_.x,y1:_.y,x2:f.x,y2:f.y})}else a="path",h.d=t.getPathData(null,e.precision);return r(a,h)}function c(t){var e=t._type,n=t._radius,i=s(t._matrix,!0,"rectangle"!==e);if("rectangle"===e){e="rect";var a=t._size,o=a.width,h=a.height;i.x-=o/2,i.y-=h/2,i.width=o,i.height=h,n.isZero()&&(n=null)}return n&&("circle"===e?i.r=n:(i.rx=n.width,i.ry=n.height)),r(e,i)}function d(t,e){var n=s(t._matrix),i=t.getPathData(null,e.precision);return i&&(n.d=i),r("path",n)}function _(t,e){var n=s(t._matrix,!0),i=t.getSymbol(),a=p(i,"symbol"),o=i.getDefinition(),h=o.getBounds();return a||(a=r("symbol",{viewBox:C.rectangle(h)}),a.appendChild(b(o,e)),y(i,a,"symbol")),n.href="#"+a.id,n.x+=h.x,n.y+=h.y,n.width=C.number(h.width),n.height=C.number(h.height),n.overflow="visible",r("use",n)}function f(t){var e=p(t,"color");if(!e){var n,i=t.getGradient(),s=i._radial,a=t.getOrigin().transform(),o=t.getDestination().transform();if(s){n={cx:a.x,cy:a.y,r:a.getDistance(o)};var h=t.getHighlight();h&&(h=h.transform(),n.fx=h.x,n.fy=h.y)}else n={x1:a.x,y1:a.y,x2:o.x,y2:o.y};n.gradientUnits="userSpaceOnUse",e=r((s?"radial":"linear")+"Gradient",n);for(var u=i._stops,l=0,c=u.length;c>l;l++){var d=u[l],_=d._color,f=_.getAlpha();n={offset:d._rampPoint,"stop-color":_.toCSS(!0)},1>f&&(n["stop-opacity"]=f),e.appendChild(r("stop",n))}y(t,e,"color")}return"url(#"+e.id+")"}function g(t){var e=r("text",s(t._matrix,!0));return e.textContent=t._content,e}function v(t,n,r){var s={},a=!r&&t.getParent(),o=[];return null!=t._name&&(s.id=t._name),i.each(tt,function(e){var n=e.get,r=e.type,h=t[n]();if(e.exportFilter?e.exportFilter(t,h):!a||!i.equals(a[n](),h)){if("color"===r&&null!=h){var u=h.getAlpha();1>u&&(s[e.attribute+"-opacity"]=u)}"style"===r?o.push(e.attribute+": "+h):s[e.attribute]=null==h?"none":"number"===r?C.number(h):"color"===r?h.gradient?f(h,t):h.toCSS(!0):"array"===r?h.join(","):"lookup"===r?e.toSVG[h]:h}}),o.length&&(s.style=o.join(";")),1===s.opacity&&delete s.opacity,t._visible||(s.visibility="hidden"),e(n,s)}function p(t,e){return P||(P={ids:{},svgs:{}}),t&&P.svgs[e+"-"+t._id]}function y(t,e,n){P||p();var i=P.ids[n]=(P.ids[n]||0)+1;e.id=n+"-"+i,P.svgs[n+"-"+t._id]=e}function x(e,n){var i=e,s=null;if(P){i="svg"===e.nodeName.toLowerCase()&&e;for(var a in P.svgs)s||(i||(i=r("svg"),i.appendChild(e)),s=i.insertBefore(r("defs"),i.firstChild)),s.appendChild(P.svgs[a]);P=null}return n.asString?(new t.XMLSerializer).serializeToString(i):i}function b(t,e,n){var i=M[t._class],r=i&&i(t,e);if(r){var s=e.onExport;s&&(r=s(t,r,e)||r);var a=JSON.stringify(t._data);a&&"{}"!==a&&"null"!==a&&r.setAttribute("data-paper-data",a)}return r&&v(t,r,n)}function S(t){return t||(t={}),C=new o(t.precision),t}var C,P,M={Group:a,Layer:a,Raster:u,Path:l,Shape:c,CompoundPath:d,PlacedSymbol:_,PointText:g};w.inject({exportSVG:function(t){return t=S(t),x(b(this,t,!0),t)}}),m.inject({exportSVG:function(t){t=S(t);var e=this._children,n=this.getView(),i=n.getViewSize(),a=r("svg",{x:0,y:0,width:i.width,height:i.height,version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"}),o=a,h=n._matrix;h.isIdentity()||(o=a.appendChild(r("g",s(h))));for(var u=0,l=e.length;l>u;u++)o.appendChild(b(e[u],t,!0));return x(a,t)}})},new function(){function r(t,e,n,i){var r=et[e],s=r?t.getAttributeNS(r,e):t.getAttribute(e);return"null"===s&&(s=null),null==s?i?null:n?"":0:n?s:parseFloat(s)}function s(t,e,n,i){return e=r(t,e,!1,i),n=r(t,n,!1,i),!i||null!=e&&null!=n?new l(e,n):null}function a(t,e,n,i){return e=r(t,e,!1,i),n=r(t,n,!1,i),!i||null!=e&&null!=n?new d(e,n):null}function o(t,e,n){return"none"===t?null:"number"===e?parseFloat(t):"array"===e?t?t.split(/[\s,]+/g).map(parseFloat):[]:"color"===e?M(t)||t:"lookup"===e?n[t]:t}function h(t,e,n,i){var r=t.childNodes,s="clippath"===e,a=new x,o=a._project,h=o._currentStyle,u=[];if(s||(a=P(a,t,i),o._currentStyle=a._style.clone()),i)for(var l=t.querySelectorAll("defs"),c=0,d=l.length;d>c;c++)I(l[c],n,!1);for(var c=0,d=r.length;d>c;c++){var _,f=r[c];1!==f.nodeType||"defs"===f.nodeName.toLowerCase()||!(_=I(f,n,!1))||_ instanceof y||u.push(_)}return a.addChildren(u),s&&(a=P(a.reduce(),t,i)),o._currentStyle=h,(s||"defs"===e)&&(a.remove(),a=null),a}function u(t,e){for(var n=t.getAttribute("points").match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g),i=[],r=0,s=n.length;s>r;r+=2)i.push(new l(parseFloat(n[r]),parseFloat(n[r+1])));var a=new T(i);return"polygon"===e&&a.closePath(),a}function c(t){var e=t.getAttribute("d"),n={pathData:e};return(e.match(/m/gi)||[]).length>1||/z\S+/i.test(e)?new N(n):new T(n)}function _(t,e){var n,i=(r(t,"href",!0)||"").substring(1),a="radialgradient"===e;if(i)n=O[i].getGradient();else{for(var o=t.childNodes,h=[],u=0,l=o.length;l>u;u++){var c=o[u];1===c.nodeType&&h.push(P(new R,c))}n=new F(h,a)}var d,_,f;return a?(d=s(t,"cx","cy"),_=d.add(r(t,"r"),0),f=s(t,"fx","fy",!0)):(d=s(t,"x1","y1"),_=s(t,"x2","y2")),P(new j(n,d,_,f),t),null}function g(t,e,n,i){for(var r=(i.getAttribute(n)||"").split(/\)\s*/g),s=new v,a=0,o=r.length;o>a;a++){var h=r[a];if(!h)break;for(var u=h.split(/\(\s*/),l=u[0],c=u[1].split(/[\s,]+/g),d=0,_=c.length;_>d;d++)c[d]=parseFloat(c[d]);switch(l){case"matrix":s.append(new v(c[0],c[1],c[2],c[3],c[4],c[5]));break;case"rotate":s.rotate(c[0],c[1],c[2]);break;case"translate":s.translate(c[0],c[1]);break;case"scale":s.scale(c);break;case"skewX":s.skew(c[0],0);break;case"skewY":s.skew(0,c[0])}}t.transform(s)}function p(t,e,n){var i=t["fill-opacity"===n?"getFillColor":"getStrokeColor"]();i&&i.setAlpha(parseFloat(e))}function b(t,n,r){var s=t.attributes[n],a=s&&s.value;if(!a){var o=i.camelize(n);a=t.style[o],a||r.node[o]===r.parent[o]||(a=r.node[o])}return a?"none"===a?null:a:e}function P(t,n,r){var s={node:V.getStyles(n)||{},parent:!r&&V.getStyles(n.parentNode)||{}};return i.each(k,function(r,a){var o=b(n,a,s);o!==e&&(t=i.pick(r(t,o,a,n,s),t))}),t}function M(t){var e=t&&t.match(/\((?:["'#]*)([^"')]+)/);return e&&O[e[1]]}function I(e,r,s){function a(t){paper=h;var e=I(t,r,s),n=r.onLoad;h.project&&h.getView();n&&n.call(this,e)}if(!e)return null;r?"function"==typeof r&&(r={onLoad:r}):r={};var o=e,h=paper;if(s)if("string"!=typeof e||/^.*</.test(e)){if("undefined"!=typeof File&&e instanceof File){var u=new FileReader;return u.onload=function(){a(u.result)},u.readAsText(e)}}else{if(o=n.getElementById(e),!o)return $.request("get",e,a);e=null}if("string"==typeof e&&(o=(new t.DOMParser).parseFromString(e,"image/svg+xml")),!o.nodeName)throw new Error("Unsupported SVG source: "+e);var l,c=o.nodeName.toLowerCase(),d=z[c],_=o.getAttribute&&o.getAttribute("data-paper-data"),f=h.settings,g=f.applyMatrix;if(f.applyMatrix=!1,l=d&&d(o,c,r,s)||null,f.applyMatrix=g,l){"#document"===c||l instanceof x||(l=P(l,o,s));var v=r.onImport;v&&(l=v(o,l,r)||l),r.expandShapes&&l instanceof S&&(l.remove(),l=l.toPath()),_&&(l._data=JSON.parse(_))}return s&&(O={},l&&i.pick(r.applyMatrix,g)&&l.matrix.apply(!0,!0)),l}var z={"#document":function(t,e,i,r){for(var s=t.childNodes,a=!paper.agent.node,o=0,h=s.length;h>o;o++){var u,l=s[o];if(1===l.nodeType){a&&(u=l.nextSibling,n.body.appendChild(l));var c=I(l,i,r);return a&&(u?t.insertBefore(l,u):t.appendChild(l)),c}}},g:h,svg:h,clippath:h,polygon:u,polyline:u,path:c,lineargradient:_,radialgradient:_,image:function(t){var e=new C(r(t,"href",!0));return e.on("load",function(){var e=a(t,"width","height");this.setSize(e);var n=this._matrix._transformPoint(s(t,"x","y").add(e.divide(2)));this.translate(n)}),e},symbol:function(t,e,n,i){return new y(h(t,e,n,i),!0)},defs:h,use:function(t){var e=(r(t,"href",!0)||"").substring(1),n=O[e],i=s(t,"x","y");return n?n instanceof y?n.place(i):n.clone().translate(i):null},circle:function(t){return new S.Circle(s(t,"cx","cy"),r(t,"r"))},ellipse:function(t){return new S.Ellipse({center:s(t,"cx","cy"),radius:a(t,"rx","ry")})},rect:function(t){var e=s(t,"x","y"),n=a(t,"width","height"),i=a(t,"rx","ry");return new S.Rectangle(new f(e,n),i)},line:function(t){return new T.Line(s(t,"x1","y1"),s(t,"x2","y2"))},text:function(t){var e=new D(s(t,"x","y").add(s(t,"dx","dy")));return e.setContent(t.textContent.trim()||""),e}},k=i.set(i.each(tt,function(t){this[t.attribute]=function(e,n){if(e[t.set](o(n,t.type,t.fromSVG)),"color"===t.type&&e instanceof S){var i=e[t.get]();i&&i.transform((new v).translate(e.getPosition(!0).negate()))}}},{}),{id:function(t,e){O[e]=t,t.setName&&t.setName(e)},"clip-path":function(t,e){var n=M(e);if(n){if(n=n.clone(),n.setClipMask(!0),!(t instanceof x))return new x(n,t);t.insertChild(0,n)}},gradientTransform:g,transform:g,"fill-opacity":p,"stroke-opacity":p,visibility:function(t,e){t.setVisible("visible"===e)},display:function(t,e){t.setVisible(null!==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,i,r){var s=new f(o(e,"array")),h=a(i,"width","height",!0);if(t instanceof x){var u=h?s.getSize().divide(h):1,l=(new v).translate(s.getPoint()).scale(u);t.transform(l.invert())}else if(t instanceof y){h&&s.setSize(h);var c="visible"!=b(i,"overflow",r),d=t._definition;c&&!s.contains(d.getBounds())&&(c=new S.Rectangle(s).transform(d._matrix),c.setClipMask(!0),d.addChild(c))}}}),O={};w.inject({importSVG:function(t,e){return this.addChild(I(t,e,!0))}}),m.inject({importSVG:function(t,e){return this.activate(),I(t,e,!0)}})},paper=new(s.inject(i.exports,{enumerable:!0,Base:i,Numerical:h,Key:J,DomEvent:H,DomElement:V,document:n,window:t})),paper.agent.node&&require("./node/extend")(paper),"function"==typeof define&&define.amd?define("paper",paper):"object"==typeof module&&module&&(module.exports=paper),paper}(this.window);