paper
Version:
The Swiss Army Knife of Vector Graphics Scripting
32 lines • 240 kB
JavaScript
/*!
* Paper.js v0.12.18 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
* http://juerglehni.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
* Date: Wed Jul 17 14:57:24 2024 +0200
*
***
*
* Straps.js - Class inheritance library with support for bean-style accessors
*
* Copyright (c) 2006 - 2020 Jürg Lehni
* http://juerglehni.com/
*
* Distributed under the MIT license.
*
***
*
* Acorn.js
* https://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(w,R){var A=(w=w||require("./node/self.js")).window,T=w.document,j=new function(){function n(t,e,n){var i;return t&&((i=f(t,"length"))&&"number"==typeof i.value?s:function(t,e){for(var n in this)this.hasOwnProperty(n)&&t.call(e,this[n],n,this)}).call(t,e,n=n||t),n}var r=/^(statics|enumerable|beans|preserve)$/,t=[],i=t.slice,a=Object.create,f=Object.getOwnPropertyDescriptor,d=Object.defineProperty,s=t.forEach||function(t,e){for(var n=0,i=this.length;n<i;n++)t.call(e,this[n],n,this)},o=Object.assign||function(t){for(var e=1,n=arguments.length;e<n;e++){var i,r=arguments[e];for(i in r)r.hasOwnProperty(i)&&(t[i]=r[i])}return t};function h(a,o,h,u,l){var c={};function t(t,e){var n,i="function"==typeof(e="string"==typeof(e=e||(e=f(o,t))&&(e.get?e:e.value))&&"#"===e[0]?a[e.substring(1)]||e:e),r=e,s=l||i&&!e.base?e&&e.get?t in a:a[t]:null;l&&s||(i&&s&&(e.base=s),i&&!1!==u&&(n=t.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(c[n[3].toLowerCase()+n[4]]=n[2]),r&&!i&&r.get&&"function"==typeof r.get&&_.isPlainObject(r)||(r={value:r,writable:!0}),(f(a,t)||{configurable:!0}).configurable&&(r.configurable=!0,r.enumerable=null!=h?h:!n),d(a,t,r))}if(o){for(var e in o)o.hasOwnProperty(e)&&!r.test(e)&&t(e);for(var e in c){var n=c[e],i=a["set"+n],n=a["get"+n]||i&&a["is"+n];!n||!0!==u&&0!==n.length||t(e,{get:n,set:i})}}return a}function _(){for(var t=0,e=arguments.length;t<e;t++){var n=arguments[t];n&&o(this,n)}return this}return h(_,{inject:function(t){var e,n,i;t&&(e=!0===t.statics?t:t.statics,n=t.beans,i=t.preserve,e!==t&&h(this.prototype,t,t.enumerable,n,i),h(this,e,null,n,i));for(var r=1,s=arguments.length;r<s;r++)this.inject(arguments[r]);return this},extend:function(){for(var t,e,n,i=this,r=0,s=arguments.length;r<s&&(!t||!e);r++)n=arguments[r],t=t||n.initialize,e=e||n.prototype;return e=(t=t||function(){i.apply(this,arguments)}).prototype=e||a(this.prototype),d(e,"constructor",{value:t,writable:!0,configurable:!0}),h(t,this),arguments.length&&this.inject.apply(t,arguments),t.base=i,t}}).inject({enumerable:!1,initialize:_,set:_,inject:function(){for(var t=0,e=arguments.length;t<e;t++){var n=arguments[t];n&&h(this,n,n.enumerable,n.beans,n.preserve)}return this},extend:function(){var t=a(this);return t.inject.apply(t,arguments)},each:function(t,e){return n(this,t,e)},clone:function(){return new this.constructor(this)},statics:{set:o,each:n,create:a,define:d,describe:f,clone:function(t){return o(new t.constructor,t)},isPlainObject:function(t){t=null!=t&&t.constructor;return t&&(t===Object||t===_||"Object"===t.name)},pick:function(t,e){return t!==R?t:e},slice:function(t,e,n){return i.call(t,e,n)}}})};"undefined"!=typeof module&&(module.exports=j),j.inject({enumerable:!1,toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+j.each(this,function(t,e){/^_/.test(e)||this.push(e+": "+("number"==(e=typeof t)?x.instance.number(t):"string"==e?"'"+t+"'":t))},[]).join(", ")+" }"},getClassName:function(){return this._class||""},importJSON:function(t){return j.importJSON(t,this)},exportJSON:function(t){return j.exportJSON(this,t)},toJSON:function(){return j.serialize(this)},set:function(t,e){return t&&j.filter(this,t,e,this._prioritize),this}},{beans:!1,statics:{exports:{},extend:function t(){var e=t.base.apply(this,arguments),n=e.prototype._class;return n&&!j.exports[n]&&(j.exports[n]=e),e},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)){if((n=t.length)!==e.length)return!1;for(;n--;)if(!j.equals(t[n],e[n]))return!1}else{var n,i=Object.keys(t);if((n=i.length)!==Object.keys(e).length)return!1;for(;n--;){var r=i[n];if(!e.hasOwnProperty(r)||!j.equals(t[r],e[r]))return!1}}return!0}return!1},read:function(t,e,n,i){if(this===j){var r=this.peek(t,e);return t.__index++,r}var s=this.prototype,a=s._readIndex,o=e||a&&t.__index||0,r=t.length,e=t[o];return i=i||r-o,e instanceof this||n&&n.readNull&&null==e&&i<=1?(a&&(t.__index=o+1),e&&n&&n.clone?e.clone():e):(e=j.create(s),a&&(e.__read=!0),e=e.initialize.apply(e,0<o||o+i<r?j.slice(t,o,o+i):t)||e,a&&(t.__index=o+e.__read,(o=e.__filtered)&&(t.__filtered=o,e.__filtered=R),e.__read=R),e)},peek:function(t,e){return t[t.__index=e||t.__index||0]},remain:function(t){return t.length-(t.__index||0)},readList:function(t,e,n,i){for(var r,s=[],e=e||0,a=i?e+i:t.length,o=e;o<a;o++)s.push(Array.isArray(r=t[o])?this.read(r,0,n):this.read(t,o,n,1));return s},readNamed:function(t,e,n,i,r){var s,a,o=this.getNamed(t,e),h=o!==R;return h&&((a=t.__filtered)||(s=this.getSource(t),(a=t.__filtered=j.create(s)).__unfiltered=s),a[e]=R),this.read(h?[o]:t,n,i,r)},readSupported:function(n,i){var t=this.getSource(n),r=this,s=!1;return t&&Object.keys(t).forEach(function(t){var e;t in i&&((e=r.readNamed(n,t))!==R&&(i[t]=e),s=!0)}),s},getSource:function(t){var e,n=t.__source;return n===R&&(e=1===t.length&&t[0],n=t.__source=e&&j.isPlainObject(e)?e:null),n},getNamed:function(t,e){var n=this.getSource(t);if(n)return e?n[e]:t.__filtered||n},hasNamed:function(t,e){return!!this.getNamed(t,e)},filter:function(n,i,r,t){var s;function e(t){var e;r&&t in r||s&&t in s||(e=i[t])!==R&&(n[t]=e)}if(t){for(var a,o={},h=0,u=t.length;h<u;h++)(a=t[h])in i&&(e(a),o[a]=!0);s=o}return Object.keys(i.__unfiltered||i).forEach(e),n},isPlainValue:function(t,e){return j.isPlainObject(t)||Array.isArray(t)||e&&"string"==typeof t},serialize:function(t,e,n,i){e=e||{};var r=!i;if(r&&(e.formatter=new x(e.precision),i={length:0,definitions:{},references:{},add:function(t,e){var n="#"+t._id,i=this.references[n];return i||(this.length++,e=e.call(t),(t=t._class)&&e[0]!==t&&e.unshift(t),this.definitions[n]=e,i=this.references[n]=[n]),i}}),t&&t._serialize){var s=t._serialize(e,i),a=t._class;!a||t._compactSerialize||!r&&n||s[0]===a||s.unshift(a)}else if(Array.isArray(t)){s=[];for(var o=0,h=t.length;o<h;o++)s[o]=j.serialize(t[o],e,n,i)}else if(j.isPlainObject(t)){s={};for(var u=Object.keys(t),o=0,h=u.length;o<h;o++){var l=u[o];s[l]=j.serialize(t[l],e,n,i)}}else s="number"==typeof t?e.formatter.number(t,e.precision):t;return r&&0<i.length?[["dictionary",i.definitions],s]:s},deserialize:function(t,e,n,i,r){var s=t,a=!n,o=a&&t&&t.length&&"dictionary"===t[0][0];if(n=n||{},Array.isArray(t)){var h=t[0],u="dictionary"===h;if(1==t.length&&/^#/.test(h))return n.dictionary[h];s=[];for(var l,c=(h=j.exports[h])?1:0,f=t.length;c<f;c++)s.push(j.deserialize(t[c],e,n,u,o));h&&(l=s,s=e?e(h,l,a||r):new h(l))}else if(j.isPlainObject(t))for(var d in s={},i&&(n.dictionary=s),t)s[d]=j.deserialize(t[d],e,n);return o?s[1]:s},exportJSON:function(t,e){t=j.serialize(t,e);return e&&0==e.asString?t:JSON.stringify(t)},importJSON:function(t,s){return j.deserialize("string"==typeof t?JSON.parse(t):t,function(t,e,n){var i=n&&s&&s.constructor===t,r=i?s:j.create(t.prototype);return!(1===e.length&&r instanceof V)||!i&&r instanceof a||(n=e[0],j.isPlainObject(n)&&(n.insert=!1,i&&(e=e.concat([V.INSERT])))),(i?r.set:t).apply(r,e),i&&(s=null),r})},push:function(t,e){var n=e.length;if(n<4096)t.push.apply(t,e);else{var i=t.length;t.length+=n;for(var r=0;r<n;r++)t[i+r]=e[r]}return t},splice:function(t,e,n,i){var r=e&&e.length,s=n===R;(n=s?t.length:n)>t.length&&(n=t.length);for(var a=0;a<r;a++)e[a]._index=n+a;if(s)return j.push(t,e),[];i=[n,i];e&&j.push(i,e);for(var o=t.splice.apply(t,i),a=0,h=o.length;a<h;a++)o[a]._index=R;for(a=n+r,h=t.length;a<h;a++)t[a]._index=a;return o},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 t={on:function(t,e){var n,i;return"string"!=typeof t?j.each(t,function(t,e){this.on(e,t)},this):(n=(i=this._eventTypes)&&i[t],-1===(i=(i=this._callbacks=this._callbacks||{})[t]=i[t]||[]).indexOf(e)&&(i.push(e),n&&n.install&&1===i.length&&n.install.call(this,t))),this},off:function(t,e){if("string"==typeof t){var n,i=this._eventTypes,r=i&&i[t],i=this._callbacks&&this._callbacks[t];return i&&(!e||-1!==(n=i.indexOf(e))&&1===i.length?(r&&r.uninstall&&r.uninstall.call(this,t),delete this._callbacks[t]):-1!==n&&i.splice(n,1)),this}j.each(t,function(t,e){this.off(e,t)},this)},once:function(e,n){return this.on(e,function t(){n.apply(this,arguments),this.off(e,t)})},emit:function(t,e){if(!(r=this._callbacks&&this._callbacks[t]))return!1;var n=j.slice(arguments,1),i=e&&e.target&&!e.currentTarget,r=r.slice();i&&(e.currentTarget=this);for(var s=0,a=r.length;s<a;s++)if(0==r[s].apply(this,n)){e&&e.stop&&e.stop();break}return i&&delete e.currentTarget,!0},responds:function(t){return!(!this._callbacks||!this._callbacks[t])},attach:"#on",detach:"#off",fire:"#emit",_installEvents:function(t){var e,n=this._eventTypes,i=this._callbacks,r=t?"install":"uninstall";if(n)for(var s in i)0<i[s].length&&((e=(e=n[s])&&e[r])&&e.call(this,s))},statics:{inject:function t(s){var a,e=s._events;return e&&(a={},j.each(e,function(t,e){var n="string"==typeof t,i=n?t:e,e=j.capitalize(i),r=i.substring(2).toLowerCase();a[r]=n?{}:t,i="_"+i,s["get"+e]=function(){return this[i]},s["set"+e]=function(t){var e=this[i];e&&this.off(r,e),t&&this.on(r,t),this[i]=t}}),s._eventTypes=a),t.base.apply(this,arguments)}}},l=j.extend({_class:"PaperScope",initialize:function t(){(Bt=this).settings=new j({applyMatrix:!0,insertItems:!0,handleSize:4,hitTolerance:0}),this.project=null,this.projects=[],this.tools=[],this._id=t._id++,t._scopes[this._id]=this;var e,n,s,i=t.prototype;this.support||(n=ut.getContext(1,1)||{},i.support={nativeDash:"setLineDash"in n||"mozDash"in n,nativeBlendModes:lt.nativeModes},ut.release(n)),this.agent||(e=w.navigator.userAgent.toLowerCase(),n=(/(darwin|win|mac|linux|freebsd|sunos)/.exec(e)||[])[0],s=i.agent=i.browser={platform:n="darwin"===n?"mac":n},n&&(s[n]=!0),e.replace(/(opera|chrome|safari|webkit|firefox|msie|trident|atom|node|jsdom)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:v?([.\d]+))?/g,function(t,e,n,i,r){s.chrome||(n="opera"===e?i:/^(node|trident)$/.test(e)?r:n,s.version=n,s.versionNumber=parseFloat(n),s.name=e={trident:"msie",jsdom:"node"}[e]||e,s[e]=!0)}),s.chrome&&delete s.webkit,s.atom&&delete s.chrome)},version:"0.12.18",getView:function(){var t=this.project;return t&&t._view},getPaper:function(){return this},execute:function(t,e){e=Bt.PaperScript.execute(t,this,e);return Y.updateFocus(),e},install:function(e){var t,n=this;for(t in j.each(["project","view","tool"],function(t){j.define(e,t,{configurable:!0,get:function(){return n[t]}})}),this)!/^_/.test(t)&&this[t]&&(e[t]=this[t])},setup:function(t){return(Bt=this).project=new i(t),this},createCanvas:function(t,e){return ut.getCanvas(t,e)},activate:function(){Bt=this},clear:function(){for(var t=this.projects,e=this.tools,n=t.length-1;0<=n;n--)t[n].remove();for(n=e.length-1;0<=n;n--)e[n].remove()},remove:function(){this.clear(),delete l._scopes[this._id]},statics:new function(){function t(n){return n+="Attribute",function(t,e){return t[n](e)||t[n]("data-paper-"+e)}}return{_scopes:{},_id:0,get:function(t){return this._scopes[t]||null},getAttribute:t("get"),hasAttribute:t("has")}}}),e=j.extend(t,{initialize:function(t){this._scope=Bt,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).emit("activate",t),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null!=this._index&&(j.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),!(this._scope=null))},getView:function(){return this._scope.getView()}}),D={findItemBoundsCollisions:function(t,e,n){function i(t){for(var e=new Array(t.length),n=0;n<t.length;n++){var i=t[n].getBounds();e[n]=[i.left,i.top,i.right,i.bottom]}return e}var r=i(t),e=e&&e!==t?i(e):r;return this.findBoundsCollisions(r,e,n||0)},findCurveBoundsCollisions:function(t,e,n,i){function r(t){for(var e=Math.min,n=Math.max,i=new Array(t.length),r=0;r<t.length;r++){var s=t[r];i[r]=[e(s[0],s[2],s[4],s[6]),e(s[1],s[3],s[5],s[7]),n(s[0],s[2],s[4],s[6]),n(s[1],s[3],s[5],s[7])]}return i}var s=r(t),e=e&&e!==t?r(e):s;if(i){for(var a=this.findBoundsCollisions(s,e,n||0,!1,!0),o=this.findBoundsCollisions(s,e,n||0,!0,!0),h=[],u=0,l=a.length;u<l;u++)h[u]={hor:a[u],ver:o[u]};return h}return this.findBoundsCollisions(s,e,n||0)},findBoundsCollisions:function(t,e,n,i,r){var s=!e||t===e,a=s?t:t.concat(e),o=t.length,h=a.length;function u(t,e,n){for(var i=0,r=t.length;i<r;){var s=r+i>>>1;a[t[s]][e]<n?i=1+s:r=s}return i-1}for(var l=i?1:0,c=2+l,f=i?0:1,d=2+f,_=new Array(h),g=0;g<h;g++)_[g]=g;_.sort(function(t,e){return a[t][l]-a[e][l]});for(var p=[],v=new Array(o),g=0;g<h;g++){var m=_[g],y=a[m],w=s?m:m-o,x=m<o,b=s||!x,C=x?[]:null;if(p.length){var S=u(p,c,y[l]-n)+1;if(p.splice(0,S),s&&r)for(var C=C.concat(p),k=0;k<p.length;k++)v[A=p[k]].push(w);else for(var I=y[d],P=y[f],k=0;k<p.length;k++){var A=p[k],T=a[A],M=A<o,O=s||o<=A;(r||(x&&O||b&&M)&&I>=T[f]-n&&P<=T[d]+n)&&(x&&O&&C.push(s?A:A-o),b&&M&&v[A].push(w))}}x&&(t===e&&C.push(m),v[m]=C),p.length?(y=u(p,c,y[c]),p.splice(y+1,0,m)):p.push(m)}for(g=0;g<v.length;g++){var z=v[g];z&&z.sort(function(t,e){return t-e})}return v}},x=j.extend({initialize:function(t){this.precision=j.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)}});x.instance=new x;var q=new function(){var f=[[.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]],d=[[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]],m=Math.abs,y=Math.sqrt,w=Math.pow,e=Math.log2||function(t){return Math.log(t)*Math.LOG2E},x=1e-12,b=112e-18;function C(t,e,n){return t<e?e:n<t?n:t}function _(t,e,n){function i(t){var e=134217729*t,e=t-e+e;return[e,t-e]}var r,s,a=e*e-t*n,o=e*e+t*n;return 3*m(a)<o&&(r=i(t),s=i(e),o=i(n),a=(e=e*e)-(n=t*n)+(s[0]*s[0]-e+2*s[0]*s[1]+s[1]*s[1]-(r[0]*o[0]-n+r[0]*o[1]+r[1]*o[0]+r[1]*o[1]))),a}function S(){var t=Math.max.apply(Math,arguments);return t&&(t<1e-8||1e8<t)?w(2,-Math.round(e(t))):0}return{EPSILON:x,MACHINE_EPSILON:b,CURVETIME_EPSILON:1e-8,GEOMETRIC_EPSILON:1e-7,TRIGONOMETRIC_EPSILON:1e-8,ANGULAR_EPSILON:1e-5,KAPPA:4*(y(2)-1)/3,isZero:function(t){return-x<=t&&t<=x},isMachineZero:function(t){return-b<=t&&t<=b},clamp:C,integrate:function(t,e,n,i){for(var r=f[i-2],s=d[i-2],a=.5*(n-e),o=a+e,h=0,u=i+1>>1,l=1&i?s[h++]*t(o):0;h<u;){var c=a*r[h];l+=s[h++]*(t(o+c)+t(o-c))}return a*l},findRoot:function(t,e,n,i,r,s,a){for(var o=0;o<s;o++){var h=t(n),u=h/e(n),l=n-u;if(m(u)<a){n=l;break}n=0<h?(r=n,l<=i?.5*(i+r):l):(i=n,r<=l?.5*(i+r):l)}return C(n,i,r)},solveQuadratic:function(t,e,n,i,r,s){var a,o=1/0;if(m(t)<x){if(m(e)<x)return m(n)<x?-1:0;a=-n/e}else{var h,u=_(t,e*=-.5,n);u&&m(u)<b&&((h=S(m(t),m(e),m(n)))&&(u=_(t*=h,e*=h,n*=h))),-b<=u&&(l=u<0?0:y(u),o=0===(c=e+(e<0?-l:l))?-(a=n/t):(a=c/t,n/c))}var l=0,t=null==r,n=r-x,c=s+x;return isFinite(a)&&(t||n<a&&a<c)&&(i[l++]=t?a:C(a,r,s)),o!==a&&isFinite(o)&&(t||n<o&&o<c)&&(i[l++]=t?o:C(o,r,s)),l},solveCubic:function(e,n,i,r,t,s,a){var o,h,u,l,c,f=S(m(e),m(n),m(i),m(r));function d(t){t=e*(o=t);l=(t+(h=t+n))*o+(u=h*o+i),c=u*o+r}if(f&&(e*=f,n*=f,i*=f,r*=f),m(e)<x)e=n,h=i,u=r,o=1/0;else if(m(r)<x)h=n,u=i,o=0;else{d(-n/e/3);var _=c/e,g=w(m(_),1/3),p=_<0?-1:1,_=-l/e,_=0<_?1.324717957244746*Math.max(g,y(_)):g,v=o-p*_;if(v!==o){for(;d(v),v=0===l?o:o-c/l/(1+b),p*o<p*v;);m(e)*o*o>m(r/o)&&(h=((u=-r/o)-i)/o)}}g=q.solveQuadratic(e,h,u,t,s,a),_=null==s;return isFinite(o)&&(0===g||0<g&&o!==t[0]&&o!==t[1])&&(_||s-x<o&&o<a+x)&&(t[g++]=_?o:C(o,s,a)),g}}},o={_id:1,_pools:{},get:function(t){if(t){var e=this._pools[t];return(e=e||(this._pools[t]={_id:1}))._id++}return this._id++}},E=j.extend({_class:"Point",_readIndex:!0,initialize:function(t,e){var n,i=typeof t,r=this.__read,s=0;return"number"==i?(this._set(t,(n="number"==typeof e)?e:t),r&&(s=n?2:1)):"undefined"==i||null===t?(this._set(0,0),r&&(s=null===t?1:0)):(t="string"==i?t.split(/[\s,]+/)||[]:t,s=1,Array.isArray(t)?this._set(+t[0],+(1<t.length?t[1]:t[0])):"x"in t?this._set(t.x||0,t.y||0):"width"in t?this._set(t.width||0,t.height||0):"angle"in t?(this._set(t.length||0,0),this.setAngle(t.angle||0)):(this._set(0,0),s=0)),r&&(this.__read=s),this},set:"#initialize",_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 E(this.x,this.y)},toString:function(){var t=x.instance;return"{ x: "+t.number(this.x)+", y: "+t.number(this.y)+" }"},_serialize:function(t){t=t.formatter;return[t.number(this.x),t.number(this.y)]},getLength:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},setLength:function(t){var e;this.isZero()?(e=this._angle||0,this._set(Math.cos(e)*t,Math.sin(e)*t)):(t=t/this.getLength(),q.isZero(t)&&this.getAngle(),this._set(this.x*t,this.y*t))},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=E.read(arguments),e=this.getLength()*t.getLength();if(q.isZero(e))return NaN;e=this.dot(t)/e;return Math.acos(e<-1?-1:1<e?1:e)}return this.isZero()?this._angle||0:this._angle=Math.atan2(this.y,this.x)},setAngleInRadians:function(t){var e;this._angle=t,this.isZero()||(e=this.getLength(),this._set(Math.cos(t)*e,Math.sin(t)*e))},getQuadrant:function(){return 0<=this.x?0<=this.y?1:4:0<=this.y?2:3}},{beans:!1,getDirectedAngle:function(){var t=E.read(arguments);return 180*Math.atan2(this.cross(t),this.dot(t))/Math.PI},getDistance:function(){var t=arguments,e=E.read(t),n=e.x-this.x,e=e.y-this.y,e=n*n+e*e;return j.read(t)?e:Math.sqrt(e)},normalize:function(t){t===R&&(t=1);var e=this.getLength(),t=0!==e?t/e:0,e=new E(this.x*t,this.y*t);return 0<=t&&(e._angle=this._angle),e},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),t=Math.cos(t),n=new E(n.x*t-n.y*i,n.x*i+n.y*t);return e?n.add(e):n},transform:function(t){return t?t._transformPoint(this):this},add:function(){var t=E.read(arguments);return new E(this.x+t.x,this.y+t.y)},subtract:function(){var t=E.read(arguments);return new E(this.x-t.x,this.y-t.y)},multiply:function(){var t=E.read(arguments);return new E(this.x*t.x,this.y*t.y)},divide:function(){var t=E.read(arguments);return new E(this.x/t.x,this.y/t.y)},modulo:function(){var t=E.read(arguments);return new E(this.x%t.x,this.y%t.y)},negate:function(){return new E(-this.x,-this.y)},isInside:function(){return b.read(arguments).contains(this)},isClose:function(){var t=arguments,e=E.read(t),t=j.read(t);return this.getDistance(e)<=t},isCollinear:function(){var t=E.read(arguments);return E.isCollinear(this.x,this.y,t.x,t.y)},isColinear:"#isCollinear",isOrthogonal:function(){var t=E.read(arguments);return E.isOrthogonal(this.x,this.y,t.x,t.y)},isZero:function(){var t=q.isZero;return t(this.x)&&t(this.y)},isNaN:function(){return isNaN(this.x)||isNaN(this.y)},isInQuadrant:function(t){return 0<=this.x*(1<t&&t<4?-1:1)&&0<=this.y*(2<t?-1:1)},dot:function(){var t=E.read(arguments);return this.x*t.x+this.y*t.y},cross:function(){var t=E.read(arguments);return this.x*t.y-this.y*t.x},project:function(){var t=E.read(arguments),e=t.isZero()?0:this.dot(t)/t.dot(t);return new E(t.x*e,t.y*e)},statics:{min:function(){var t=arguments,e=E.read(t),t=E.read(t);return new E(Math.min(e.x,t.x),Math.min(e.y,t.y))},max:function(){var t=arguments,e=E.read(t),t=E.read(t);return new E(Math.max(e.x,t.x),Math.max(e.y,t.y))},random:function(){return new E(Math.random(),Math.random())},isCollinear:function(t,e,n,i){return Math.abs(t*i-e*n)<=1e-8*Math.sqrt((t*t+e*e)*(n*n+i*i))},isOrthogonal:function(t,e,n,i){return Math.abs(t*n+e*i)<=1e-8*Math.sqrt((t*t+e*e)*(n*n+i*i))}}},j.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new E(e(this.x),e(this.y))}},{})),u=E.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)},isSelected:function(){return!!(this._owner._selection&this._getSelection())},setSelected:function(t){this._owner._changeSelection(this._getSelection(),t)},_getSelection:function(){return"setPosition"===this._setter?4:0}}),O=j.extend({_class:"Size",_readIndex:!0,initialize:function(t,e){var n,i=typeof t,r=this.__read,s=0;return"number"==i?(this._set(t,(n="number"==typeof e)?e:t),r&&(s=n?2:1)):"undefined"==i||null===t?(this._set(0,0),r&&(s=null===t?1:0)):(t="string"==i?t.split(/[\s,]+/)||[]:t,s=1,Array.isArray(t)?this._set(+t[0],+(1<t.length?t[1]:t[0])):"width"in t?this._set(t.width||0,t.height||0):"x"in t?this._set(t.x||0,t.y||0):(this._set(0,0),s=0)),r&&(this.__read=s),this},set:"#initialize",_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 O(this.width,this.height)},toString:function(){var t=x.instance;return"{ width: "+t.number(this.width)+", height: "+t.number(this.height)+" }"},_serialize:function(t){t=t.formatter;return[t.number(this.width),t.number(this.height)]},add:function(){var t=O.read(arguments);return new O(this.width+t.width,this.height+t.height)},subtract:function(){var t=O.read(arguments);return new O(this.width-t.width,this.height-t.height)},multiply:function(){var t=O.read(arguments);return new O(this.width*t.width,this.height*t.height)},divide:function(){var t=O.read(arguments);return new O(this.width/t.width,this.height/t.height)},modulo:function(){var t=O.read(arguments);return new O(this.width%t.width,this.height%t.height)},negate:function(){return new O(-this.width,-this.height)},isZero:function(){var t=q.isZero;return t(this.width)&&t(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(t,e){return new O(Math.min(t.width,e.width),Math.min(t.height,e.height))},max:function(t,e){return new O(Math.max(t.width,e.width),Math.max(t.height,e.height))},random:function(){return new O(Math.random(),Math.random())}}},j.each(["round","ceil","floor","abs"],function(t){var e=Math[t];this[t]=function(){return new O(e(this.width),e(this.height))}},{})),n=O.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)}}),b=j.extend({_class:"Rectangle",_readIndex:!0,beans:!0,initialize:function(t,e,n,i){var r,s,a,o,h,u,l=arguments,c=typeof t;"number"==c?(this._set(t,e,n,i),r=4):"undefined"==c||null===t?(this._set(0,0,0,0),r=null===t?1:0):1===l.length&&(Array.isArray(t)?(this._set.apply(this,t),r=1):t.x!==R||t.width!==R?(this._set(t.x||0,t.y||0,t.width||0,t.height||0),r=1):t.from===R&&t.to===R&&(this._set(0,0,0,0),j.readSupported(l,this)&&(r=1))),r===R&&(a=E.readNamed(l,"from"),s=j.peek(l),c=a.x,a=a.y,s&&s.x!==R||j.hasNamed(l,"to")?(o=(u=E.readNamed(l,"to")).x-c,h=u.y-a,o<0&&(c=u.x,o=-o),h<0&&(a=u.y,h=-h)):(o=(u=O.read(l)).width,h=u.height),this._set(c,a,o,h),r=l.__index);l=l.__filtered;return l&&(this.__filtered=l),this.__read&&(this.__read=r),this},set:"#initialize",_set:function(t,e,n,i){return this.x=t,this.y=e,this.width=n,this.height=i,this},clone:function(){return new b(this.x,this.y,this.width,this.height)},equals:function(t){var e=j.isPlainValue(t)?b.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=x.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){t=t.formatter;return[t.number(this.x),t.number(this.y),t.number(this.width),t.number(this.height)]},getPoint:function(t){return new(t?E:u)(this.x,this.y,this,"setPoint")},setPoint:function(){var t=E.read(arguments);this.x=t.x,this.y=t.y},getSize:function(t){return new(t?O:n)(this.width,this.height,this,"setSize")},_fw:1,_fh:1,setSize:function(){var t=O.read(arguments),e=this._sx,n=this._sy,i=t.width,t=t.height;e&&(this.x+=(this.width-i)*e),n&&(this.y+=(this.height-t)*n),this.width=i,this.height=t,this._fw=this._fh=1},getLeft:function(){return this.x},setLeft:function(t){var e;this._fw||(e=t-this.x,this.width-=.5===this._sx?2*e:e),this.x=t,this._sx=this._fw=0},getTop:function(){return this.y},setTop:function(t){var e;this._fh||(e=t-this.y,this.height-=.5===this._sy?2*e:e),this.y=t,this._sy=this._fh=0},getRight:function(){return this.x+this.width},setRight:function(t){var e;this._fw||(e=t-this.x,this.width=.5===this._sx?2*e:e),this.x=t-this.width,this._sx=1,this._fw=0},getBottom:function(){return this.y+this.height},setBottom:function(t){var e;this._fh||(e=t-this.y,this.height=.5===this._sy?2*e:e),this.y=t-this.height,this._sy=1,this._fh=0},getCenterX:function(){return this.x+this.width/2},setCenterX:function(t){this._fw||.5===this._sx?this.x=t-this.width/2:(this._sx&&(this.x+=2*(t-this.x)*this._sx),this.width=2*(t-this.x)),this._sx=.5,this._fw=0},getCenterY:function(){return this.y+this.height/2},setCenterY:function(t){this._fh||.5===this._sy?this.y=t-this.height/2:(this._sy&&(this.y+=2*(t-this.y)*this._sy),this.height=2*(t-this.y)),this._sy=.5,this._fh=0},getCenter:function(t){return new(t?E:u)(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(){var t=E.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!==R||4===(Array.isArray(t)?t:arguments).length?this._containsRectangle(b.read(arguments)):this._containsPoint(E.read(arguments))},_containsPoint:function(t){var e=t.x,t=t.y;return e>=this.x&&t>=this.y&&e<=this.x+this.width&&t<=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=b.read(arguments),e=j.read(arguments)||0;return t.x+t.width>this.x-e&&t.y+t.height>this.y-e&&t.x<this.x+this.width+e&&t.y<this.y+this.height+e},intersect:function(){var t=b.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),t=Math.min(this.y+this.height,t.y+t.height);return new b(e,n,i-e,t-n)},unite:function(){var t=b.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),t=Math.max(this.y+this.height,t.y+t.height);return new b(e,n,i-e,t-n)},include:function(){var t=E.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=Math.max(this.y+this.height,t.y);return new b(e,n,i-e,t-n)},expand:function(){var t=O.read(arguments),e=t.width,t=t.height;return new b(this.x-e/2,this.y-t/2,this.width+e,this.height+t)},scale:function(t,e){return this.expand(this.width*t-this.width,this.height*(e===R?t:e)-this.height)}},j.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);4<=e&&(t[1]+=i?"Y":"X");var e=t[i?0:1],i=t[i?1:0],r="get"+e,s="get"+i,a="set"+e,o="set"+i,h="set"+n;this["get"+n]=function(t){return new(t?E:u)(this[r](),this[s](),this,h)},this[h]=function(){var t=E.read(arguments);this[a](t.x),this[o](t.y)}},{beans:!0})),r=b.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 n=b.prototype;return j.each(["x","y","width","height"],function(t){var e=j.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)}},j.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(t){var e="set"+t;this[e]=function(){this._dontNotify=!0,n[e].apply(this,arguments),this._dontNotify=!1,this._owner[this._setter](this)}},{isSelected:function(){return!!(2&this._owner._selection)},setSelected:function(t){var e=this._owner;e._changeSelection&&e._changeSelection(2,t)}}))}),z=j.extend({_class:"Matrix",initialize:function t(e,n){var i=arguments,r=i.length,s=!0;if(6<=r?this._set.apply(this,i):1===r||2===r?e instanceof t?this._set(e._a,e._b,e._c,e._d,e._tx,e._ty,n):Array.isArray(e)?this._set.apply(this,n?e.concat([n]):e):s=!1:r?s=!1:this.reset(),!s)throw new Error("Unsupported matrix parameters");return this},set:"#initialize",_set:function(t,e,n,i,r,s,a){return this._a=t,this._b=e,this._c=n,this._d=i,this._tx=r,this._ty=s,a||this._changed(),this},_serialize:function(t,e){return j.serialize(this.getValues(),t,!0,e)},_changed:function(){var t=this._owner;t&&(t._applyMatrix?t.transform(null,!0):t._changed(25))},clone:function(){return new z(this._a,this._b,this._c,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},toString:function(){var t=x.instance;return"[["+[t.number(this._a),t.number(this._c),t.number(this._tx)].join(", ")+"], ["+[t.number(this._b),t.number(this._d),t.number(this._ty)].join(", ")+"]]"},reset:function(t){return this._a=this._d=1,this._b=this._c=this._tx=this._ty=0,t||this._changed(),this},apply:function(t,e){var n=this._owner;return!!n&&(n.transform(null,j.pick(t,!0),e),this.isIdentity())},translate:function(){var t=E.read(arguments),e=t.x,t=t.y;return this._tx+=e*this._a+t*this._c,this._ty+=e*this._b+t*this._d,this._changed(),this},scale:function(){var t=arguments,e=E.read(t),t=E.read(t,0,{readNull:!0});return t&&this.translate(t),this._a*=e.x,this._b*=e.x,this._c*=e.y,this._d*=e.y,t&&this.translate(t.negate()),this._changed(),this},rotate:function(t){t*=Math.PI/180;var e=E.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,e=this._b,n=this._c,i=this._d;return this._a=r*h+s*n,this._b=r*e+s*i,this._c=-s*h+r*n,this._d=-s*e+r*i,this._tx+=a*h+o*n,this._ty+=a*e+o*i,this._changed(),this},shear:function(){var t=arguments,e=E.read(t),n=E.read(t,0,{readNull:!0});n&&this.translate(n);var i=this._a,t=this._b;return this._a+=e.y*this._c,this._b+=e.y*this._d,this._c+=e.x*i,this._d+=e.x*t,n&&this.translate(n.negate()),this._changed(),this},skew:function(){var t=arguments,e=E.read(t),n=E.read(t,0,{readNull:!0}),t=Math.PI/180,t=new E(Math.tan(e.x*t),Math.tan(e.y*t));return this.shear(t,n)},append:function(t,e){var n,i,r,s,a,o,h,u,l;return t&&(n=this._a,i=this._b,r=this._c,s=this._d,a=t._a,o=t._c,h=t._b,u=t._d,l=t._tx,t=t._ty,this._a=a*n+h*r,this._c=o*n+u*r,this._b=a*i+h*s,this._d=o*i+u*s,this._tx+=l*n+t*r,this._ty+=l*i+t*s,e||this._changed()),this},prepend:function(t,e){var n,i,r,s,a,o,h,u,l,c,f;return t&&(n=this._a,i=this._b,r=this._c,s=this._d,a=this._tx,o=this._ty,h=t._a,u=t._c,l=t._b,c=t._d,f=t._tx,t=t._ty,this._a=h*n+u*i,this._c=h*r+u*s,this._b=l*n+c*i,this._d=l*r+c*s,this._tx=h*a+u*o+f,this._ty=l*a+c*o+t,e||this._changed()),this},appended:function(t){return this.clone().append(t)},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=(n*s-i*r)/a,this._ty=(e*r-t*s)/a,o=this),o},inverted:function(){return this.clone().invert()},concatenate:"#append",preConcatenate:"#prepend",chain:"#appended",_shiftless:function(){return new z(this._a,this._b,this._c,this._d,0,0)},_orNullIfIdentity:function(){return this.isIdentity()?null:this},isIdentity:function(){return 1===this._a&&0===this._b&&0===this._c&&1===this._d&&0===this._tx&&0===this._ty},isInvertible:function(){var t=this._a*this._d-this._c*this._b;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(E.read(arguments)):this._transformCoordinates(t,e,n)},_transformPoint:function(t,e,n){var i=t.x,t=t.y;return(e=e||new E)._set(i*this._a+t*this._c+this._tx,i*this._b+t*this._d+this._ty,n)},_transformCoordinates:function(t,e,n){for(var i=0,r=2*n;i<r;i+=2){var s=t[i],a=t[i+1];e[i]=s*this._a+a*this._c+this._tx,e[i+1]=s*this._b+a*this._d+this._ty}return e},_transformCorners:function(t){var e=t.x,n=t.y,i=e+t.width,t=n+t.height,t=[e,n,i,n,i,t,e,t];return this._transformCoordinates(t,t,4)},_transformBounds:function(t,e,n){for(var i=this._transformCorners(t),r=i.slice(0,2),s=r.slice(),a=2;a<8;a++){var o=i[a],h=1&a;o<r[h]?r[h]=o:o>s[h]&&(s[h]=o)}return(e=e||new b)._set(r[0],r[1],s[0]-r[0],s[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(E.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,l=null;return u&&!isNaN(u)&&isFinite(o)&&isFinite(h)&&(h=t.x-this._tx,t=t.y-this._ty,l=(e=e||new E)._set((h*a-t*s)/u,(t*i-h*r)/u,n)),l},decompose:function(){var t,e,n,i,r=this._a,s=this._b,a=this._c,o=this._d,h=r*o-s*a,u=Math.sqrt,l=Math.atan2,c=180/Math.PI;return i=0!==r||0!==s?(t=u(r*r+s*s),e=Math.acos(r/t)*(0<s?1:-1),n=[t,h/t],[l(r*a+s*o,t*t),0]):0!==a||0!==o?(i=u(a*a+o*o),e=Math.asin(a/i)*(0<o?1:-1),n=[h/i,i],[0,l(r*a+s*o,i*i)]):n=[e=0,0],{translation:this.getTranslation(),rotation:e*c,scaling:new E(n),skewing:new E(i[0]*c,i[1]*c)}},getValues:function(){return[this._a,this._b,this._c,this._d,this._tx,this._ty]},getTranslation:function(){return new E(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._b,this._c,this._d,this._tx,this._ty)}},j.each(["a","b","c","d","tx","ty"],function(t){var e=j.capitalize(t),n="_"+t;this["get"+e]=function(){return this[n]},this["set"+e]=function(t){this[n]=t,this._changed()}},{})),L=j.extend({_class:"Line",initialize:function(t,e,n,i,r){(4<=arguments.length?(this._px=t,this._py=e,this._vx=n,this._vy=i,r):(this._px=t.x,this._py=t.y,this._vx=e.x,this._vy=e.y,n))||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new E(this._px,this._py)},getVector:function(){return new E(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(t,e){return L.intersect(this._px,this._py,this._vx,this._vy,t._px,t._py,t._vx,t._vy,!0,e)},getSide:function(t,e){return L.getSide(this._px,this._py,this._vx,this._vy,t.x,t.y,!0,e)},getDistance:function(t){return Math.abs(this.getSignedDistance(t))},getSignedDistance:function(t){return L.getSignedDistance(this._px,this._py,this._vx,this._vy,t.x,t.y,!0)},isCollinear:function(t){return E.isCollinear(this._vx,this._vy,t._vx,t._vy)},isOrthogonal:function(t){return E.isOrthogonal(this._vx,this._vy,t._vx,t._vy)},statics:{intersect:function(t,e,n,i,r,s,a,o,h,u){h||(n-=t,i-=e,a-=r,o-=s);h=n*o-i*a;if(!q.isMachineZero(h)){r=t-r,s=e-s,o=(a*s-o*r)/h,h=(n*s-i*r)/h;if(u||-1e-12<o&&o<1+1e-12&&-1e-12<h&&h<1+1e-12)return new E(t+(o=!u?o<=0?0:1<=o?1:o:o)*n,e+o*i)}},getSide:function(t,e,n,i,r,s,a,o){a||(n-=t,i-=e);t=r-t,e=t*i-(s-e)*n;return(e=!o&&q.isMachineZero(e)&&0<=(e=(t*n+t*n)/(n*n+i*i))&&e<=1?0:e)<0?-1:0<e?1:0},getSignedDistance:function(t,e,n,i,r,s,a){return a||(n-=t,i-=e),0===n?0<i?r-t:t-r:0===i?n<0?s-e:e-s:((r-t)*i-(s-e)*n)/(n<i?i*Math.sqrt(1+n*n/(i*i)):n*Math.sqrt(1+i*i/(n*n)))},getDistance:function(t,e,n,i,r,s,a){return Math.abs(L.getSignedDistance(t,e,n,i,r,s,a))}}}),i=e.extend({_class:"Project",_list:"projects",_reference:"project",_compactSerialize:!0,initialize:function(t){e.call(this,!0),this._children=[],this._namedChildren={},this._activeLayer=null,this._currentStyle=new I(null,null,this),this._view=Y.create(this,t||ut.getCanvas(1,1)),this._selectionItems={},this._selectionCount=0,this._updateVersion=0},_serialize:function(t,e){return j.serialize(this._children,t,!0,e)},_changed:function(t,e){1&t&&((r=this._view)&&(r._needsUpdate=!0,!r._requested&&r._autoUpdate&&r.requestUpdate()));var n,i,r,s=this._changes;s&&e&&((r=(n=this._changesById)[i=e._id])?r.flags|=t:s.push(n[i]={item:e,flags:t}))},clear:function(){for(var t=this._children,e=t.length-1;0<=e;e--)t[e].remove()},isEmpty:function(){return!this._children.length},remove:function t(){return!!t.base.call(this)&&(this._view&&this._view.remove(),!0)},getView:function(){return this._view},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(t){this._currentStyle.set(t)},getIndex:function(){return this._index},getOptions:function(){return this._scope.settings},getLayers:function(){return this._children},getActiveLayer:function(){return this._activeLayer||new a({project:this,insert:!0})},getSymbolDefinitions:function(){var n=[],i={};return this.getItems({class:s,match:function(t){var e=t._definition,t=e._id;return i[t]||(i[t]=!0,n.push(e)),!1}}),n},getSymbols:"getSymbolDefinitions",getSelectedItems:function(){var t,e=this._selectionItems,n=[];for(t in e){var i=e[t],r=i._selection;1&r&&i.isInserted()?n.push(i):r||this._updateSelection(i)}return n},_updateSelection:function(t){var e=t._id,n=this._selectionItems;t._selection?n[e]!==t&&(this._selectionCount++,n[e]=t):n[e]===t&&(this._selectionCount--,delete n[e])},selectAll:function(){for(var t=this._children,e=0,n=t.length;e<n;e++)t[e].setFullySelected(!0)},deselectAll:function(){var t,e=this._selectionItems;for(t in e)e[t].setFullySelected(!1)},addLayer:function(t){return this.insertLayer(R,t)},insertLayer:function(t,e){return e instanceof a?(e._remove(!1,!0),j.splice(this._children,[e],t,0),e._setProject(this,!0),(t=e._name)&&e.setName(t),this._changes&&e._changed(5),this._activeLayer||(this._activeLayer=e)):e=null,e},_insertItem:function(t,e,n){return e=this.insertLayer(t,e)||(this._activeLayer||this._insertItem(R,new a(V.NO_INSERT),!0)).insertChild(t,e),n&&e.activate&&e.activate(),e},getItems:function(t){return V._getItems(this,t)},getItem:function(t){return V._getItems(this,t,null,null,!0)[0]||null},importJSON:function(t){this.activate();var e=this._activeLayer;return j.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,s=n[i];for(r in e){var a=e[r];a&&a!=n&&delete a[s._id]}s.remove()}e[t]=null}}},draw:function(t,e,n){this._updateVersion++,t.save(),e.applyToContext(t);for(var i=this._children,r=new j({offset:new E(0,0),pixelRatio:n,viewMatrix:e.isIdentity()?null:e,matrices:[new z],updateMatrix:!0}),s=0,a=i.length;s<a;s++)i[s].draw(t,r);if(t.restore(),0<this._selectionCount){t.save(),t.strokeWidth=1;var o,h=this._selectionItems,u=this._scope.settings.handleSize,l=this._updateVersion;for(o in h)h[o]._drawSelection(t,e,u,h,l);t.restore()}}}),V=j.extend(t,{statics:{extend:function t(e){return e._serializeFields&&(e._serializeFields=j.set({},this.prototype._serializeFields,e._serializeFields)),t.base.apply(this,arguments)},INSERT:{insert:!0},NO_INSERT:{insert:!1}},_class:"Item",_name:null,_applyMatrix:!0,_canApplyMatrix:!0,_canScaleStroke:!1,_pivot:null,_visible:!0,_blendMode:"normal",_opacity:1,_locked:!1,_guide:!1,_clipMask:!1,_selection:0,_selectBounds:!0,_selectChildren:!1,_serializeFields:{name:null,applyMatrix:null,matrix:new z,pivot:null,visible:!0,blendMode:"normal",opacity:1,locked:!1,guide:!1,clipMask:!1,selected:!1,data:{}},_prioritize:["applyMatrix"]},new function(){var t=["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"];return j.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,e){var n=t&&j.isPlainObject(t),i=n&&!0===t.internal,r=this._matrix=new z,s=n&&t.project||Bt.project,a=Bt.settings;return this._id=i?null:o.get(),this._parent=this._index=null,this._applyMatrix=this._canApplyMatrix&&a.applyMatrix,e&&r.translate(e),(r._owner=this)._style=new I(s._currentStyle,this,s),i||n&&0==t.insert||!a.insertItems&&(!n||1!=t.insert)?this._setProject(s):(n&&t.parent||s)._insertItem(R,this,!0),n&&t!==V.NO_INSERT&&t!==V.INSERT&&this.set(t,{internal:!0,insert:!0,project:!0,parent:!0}),n},_serialize:function(i,r){var s={},a=this;function t(t){for(var e in t){var n=a[e];j.equals(n,"leading"===e?1.2*t.fontSize:t[e])||(s[e]=j.serialize(n,i,"data"!==e,r))}}return t(this._serializeFields),this instanceof g||t(this._style._defaults),[this._class,s]},_changed:function(t){var e=this._symbol,n=this._parent||e,i=this._project;8&t&&(this._bounds=this._position=this._decomposed=R),16&t&&(this._globalMatrix=R),n&&72&t&&V._clearBoundsCache(n),2&t&&V._clearBoundsCache(this),i&&i._changed(t,this),e&&e._changed(t)},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 e,n=this._getOwner();t&&n&&(e=n._children,((n=n._namedChildren)[t]=n[t]||[]).push(this),t in e||(e[t]=this)),this._name=t||R,this._changed(256)},getStyle:function(){return this._style},setStyle:function(t){this.getStyle().set(t)}},j.each(["locked","visible","blendMode","opacity","guide"],function(e){var t=j.capitalize(e),n="_"+e,i={locked:256,visible:265};this["get"+t]=function(){return this[n]},this["set"+t]=function(t){t!=this[n]&&(this[n]=t,this._changed(i[e]||257))}},{}),{beans:!0,getSelection:function(){return this._selection},setSelection:function(t){t!==this._selection&&(this._selection=t,(t=this._project)&&(t._updateSelection(this),this._changed(257)))},_changeSelection:function(t,e){var n=this._selection;this.setSelection(e?n|t:n&~t)},isSelected:function(){if(this._selectChildren)for(var t=this._children,e=0,n=t.length;e<n;e++)if(t[e].isSelected())return!0;return!!(1&this._selection)},setSelected:function(t){if(this._selectChildren)for(var e=this._children,n=0,i=e.length;n<i;n++)e[n].setSelected(t);this._changeSelection(1,t)},isFullySelected:function(){var t=this._children,e=!!(1&this._selection);if(t&&e){for(var n=0,i=t.length;n<i;n++)if(!t[n].isFullySelected())return!1;return!0}return e},setFullySelected:function(t){var e=this._children;if(e)for(var n=0,i=e.length;n<i;n++)e[n].setFullySelected(t);this._changeSelection(1,t)},isClipMask:function(){return this._clipMask},setClipMask:function(t){this._clipMask!=(t=!!t)&&((this._clipMask=t)&&(this.setFillColor(null),this.setStrokeColor(null)),this._changed(257),this._parent&&this._parent._changed(2048))},getData:function(){return this._data||(this._data={}),this._data},setData:function(t){this._data=t},getPosition:function(t){var e=t?E:u,t=this._position||(this._position=this._getPositionFromBounds());return new e(t.x,t.y,this,"setPosition")},setPosition:function(){this.translate(E.read(arguments).subtract(this.getPosition(!0)))},_getPositionFromBounds:function(t){return this._pivot?this._matrix._transformPoint(this._pivot):(t||this.getBounds()).getCenter(!0)},getPivot:function(){var t=this._pivot;return t?new u(t.x,t.y,this,"setPivot"):null},setPivot:function(){this._pivot=E.read(arguments,0,{clone:!0,readNull:!0}),this._position=R}},j.each({getStrokeBounds:{stroke:!0},getHandleBounds:{handle:!0},getInternalBounds:{internal:!0}},function(e,t){this[t]=function(t){return this.getBounds(t,e)}},{beans:!0,getBounds:function(t,e){var n=e||t instanceof z,i=j.set({},n?e:t,this._boundsOptions);i.stroke&&!this.getStrokeScaling()||(i.cacheItem=this);i=this._getCachedBounds(n&&t,i).rect;return arguments.length?i:new r(i.x,i.y,i.width,i.height,this,"setBounds")},setBounds:function(){var t=b.read(arguments),e=this.getBounds(),n=this._matrix,i=new z,r=t.getCenter();i.translate(r),t.width==e.width&&t.height==e.height||(n.isInvertible()||(n.set(n._backup||(new z).translate(n.getTranslation())),e=this.getBounds()),i.scale(0!==e.width?t.width/e.width:0,0!==e.height?t.height/e.height:0)),r=e.getCenter(),i.translate(-r.x,-r.y),this.transform(i)},_getBounds:function(t,e){var n=this._children;return n&&n.length?(V._updateBoundsCache(this,e.cacheItem),V._getBounds(n,t,e)):new b},_getBoundsCacheKey:function(t,e){return[t.stroke?1:0,t.handle?1:0,e?1:0].join("")},_getCachedBounds:function(t,e,n){t=t&&t._orNullIfIdentity();var i=e.internal&&!n,r=e.cacheItem,s=i?null:this._matrix._orNullIfIdentity(),a=r&&(!t||t.equals(s))&&this._getBoundsCacheKey(e,i),n=this._bounds;if(V._updateBoundsCache(this._parent||this._symbol,r),a&&n&&a in n)return{rect:(o=n[a]).rect.clone(),nonscaling:o.nonscaling};var o,t=this._getBounds(t||s,e),s=t.rect||t,e=this._style,e=t.nonscaling||e.hasStroke()&&!e.getStrokeScaling();return a&&(n||(this._bounds=n={}),o=n[a]={rect:s.clone(),nonscaling:e,internal:i}),{rect:s,nonscaling:e}},_getStrokeMatrix:function(t,e){e=this.getStrokeScaling()?null:e&&e.internal?this:this._parent||this._symbol&&this._symbol._item,t=e?e.getViewMatrix().invert():t;return t&&t._shiftless()},statics:{_updateBoundsCache:function(t,e){var n;t&&e&&(n=e._id,(t=t._boundsCache=t._boundsCache||{ids:{},list:[]}).ids[n]||(t.list.push(e),t.ids[n]=e))},_clearBoundsCache:function(t){var e=t.