diff --git a/article.js b/article.js index f7e624c0..596c725e 100644 --- a/article.js +++ b/article.js @@ -1,20 +1,21 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.BezierArticle=t():e.BezierArticle=t()}(this,function(){return function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=116)}([function(e,t,n){"use strict";var i=n(1),r=n(3),a=new r;e.exports=function(e,t){var n={getDefaultProps:function(){return{title:a.getTitle(e)}},render:function(){return a.getContent(e,this)}};return t&&Object.keys(t).forEach(function(e){n[e]=t[e]}),i.createClass(n)}},function(e,t,n){"use strict";(function(e){function i(){return null}function r(e){var t=e.nodeName,n=e.attributes;e.attributes={},t.defaultProps&&x(e.attributes,t.defaultProps),n&&x(e.attributes,n)}function a(e,t){var n,i,r;if(t){for(r in t)if(n=X.test(r))break;if(n){i=e.attributes={};for(r in t)t.hasOwnProperty(r)&&(i[X.test(r)?r.replace(/([A-Z0-9])/,"-$1").toLowerCase():r]=t[r])}}}function s(e,t,i){var r=t&&t._preactCompatRendered&&t._preactCompatRendered.base;r&&r.parentNode!==t&&(r=null),r||(r=t.children[0]);for(var a=t.childNodes.length;a--;)t.childNodes[a]!==r&&t.removeChild(t.childNodes[a]);var s=n.i(q.render)(e,t,r);return t&&(t._preactCompatRendered=s&&(s._component||{base:s})),"function"==typeof i&&i(),s&&s._component||s}function o(e,t,i,r){var a=n.i(q.h)(Z,{context:e.context},t),o=s(a,i);return r&&r(o),o._component||o.base}function l(e){var t=e._preactCompatRendered&&e._preactCompatRendered.base;return!(!t||t.parentNode!==e)&&(n.i(q.render)(n.i(q.h)(i),e,t),!0)}function c(e){return m.bind(null,e)}function h(e,t){for(var n=t||0;n0;)i[r]=arguments[r+2];if(!v(e))return e;var a=e.attributes||e.props,s=n.i(q.h)(e.nodeName||e.type,a,e.children||a&&a.children),o=[s,t];return i&&i.length?o.push(i):t&&t.children&&o.push(t.children),p(q.cloneElement.apply(void 0,o))}function v(e){return e&&(e instanceof Q||e.$$typeof===V)}function w(e,t){return t._refProxies[e]||(t._refProxies[e]=function(n){t&&t.refs&&(t.refs[e]=n,null===n&&(delete t._refProxies[e],t=null))})}function y(e){var t=e.nodeName,n=e.attributes;if(n&&"string"==typeof t){var i={};for(var r in n)i[r.toLowerCase()]=r;if(i.ondoubleclick&&(n.ondblclick=n[i.ondoubleclick],delete n[i.ondoubleclick]),i.onchange&&("textarea"===t||"input"===t.toLowerCase()&&!/^fil|che|rad/i.test(n.type))){var a=i.oninput||"oninput";n[a]||(n[a]=B([n[a],n[i.onchange]]),delete n[i.onchange])}}}function b(e){var t=e.attributes;if(t){var n=t.className||t.class;n&&(t.className=n)}}function x(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}function _(e,t){for(var n in e)if(!(n in t))return!0;for(var i in t)if(e[i]!==t[i])return!0;return!1}function E(e){return e&&e.base||e}function C(){}function k(e){function t(e,t){T(this),A.call(this,e,t,H),N.call(this,e,t)}return e=x({constructor:t},e),e.mixins&&z(e,S(e.mixins)),e.statics&&x(t,e.statics),e.propTypes&&(t.propTypes=e.propTypes),e.defaultProps&&(t.defaultProps=e.defaultProps),e.getDefaultProps&&(t.defaultProps=e.getDefaultProps()),C.prototype=A.prototype,t.prototype=x(new C,e),t.displayName=e.displayName||"Component",t}function S(e){for(var t={},n=0;n4){if(1!==arguments.length)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");a=!0}}else if(6!==s&&8!==s&&9!==s&&12!==s&&1!==arguments.length)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");var o=!a&&(9===s||12===s)||e&&e[0]&&"undefined"!=typeof e[0].z;this._3d=o;for(var l=[],c=0,u=o?3:2;c1e-4)return void(e._linear=!1);e._linear=!0}(this),this._t1=0,this._t2=1,this.update()};d.fromSVG=function(e){var t=e.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g).map(parseFloat),n=/[cq]/.test(e);return n?(t=t.map(function(e,n){return n<2?e:e+t[n%2]}),new d(t)):new d(t)},d.quadraticFromPoints=function(e,n,i,r){if("undefined"==typeof r&&(r=.5),0===r)return new d(n,n,i);if(1===r)return new d(e,n,n);var a=t(2,e,n,i,r);return new d(e,a.A,i)},d.cubicFromPoints=function(e,n,i,r,a){"undefined"==typeof r&&(r=.5);var s=t(3,e,n,i,r);"undefined"==typeof a&&(a=h.dist(n,s.C));var o=a*(1-r)/r,l=h.dist(e,i),c=(i.x-e.x)/l,u=(i.y-e.y)/l,f=a*c,m=a*u,p=o*c,g=o*u,v={x:n.x-f,y:n.y-m},w={x:n.x+p,y:n.y+g},y=s.A,b={x:y.x+(v.x-y.x)/(1-r),y:y.y+(v.y-y.y)/(1-r)},x={x:y.x+(w.x-y.x)/r,y:y.y+(w.y-y.y)/r},_={x:e.x+(b.x-e.x)/r,y:e.y+(b.y-e.y)/r},E={x:i.x+(x.x-i.x)/(1-r),y:i.y+(x.y-i.y)/(1-r)};return new d(e,_,E,i)};var f=function(){return h};d.getUtils=f,d.prototype={getUtils:f,valueOf:function(){return this.toString()},toString:function(){return h.pointsToString(this.points)},toSVG:function(e){if(this._3d)return!1;for(var t=this.points,n=t[0].x,i=t[0].y,r=["M",n,i,2===this.order?"Q":"C"],a=1,s=t.length;a1;t--,n--){for(var i,r=[],a=0;a0},length:function(){return h.length(this.derivative.bind(this))},_lut:[],getLUT:function(e){if(e=e||100,this._lut.length===e)return this._lut;this._lut=[];for(var t=0;t<=e;t++)this._lut.push(this.compute(t/e));return this._lut},on:function(e,t){t=t||5;for(var n,i=this.getLUT(),r=[],a=0,s=0;s1;){for(var d=0;d1;){for(i=[],s=0,o=n.length-1;s=0&&e<=1}),r=r.concat(i[n].sort())}.bind(this)),r=r.sort().filter(function(e,t){return r.indexOf(e)===t}),i.values=r,i},bbox:function(){var e=this.extrema(),t={};return this.dims.forEach(function(n){t[n]=h.getminmax(this,n,e[n])}.bind(this)),t},overlaps:function(e){var t=this.bbox(),n=e.bbox();return h.bboxoverlap(t,n)},offset:function(e,t){if("undefined"!=typeof t){var n=this.get(e),i=this.normal(e),r={c:n,n:i,x:n.x+i.x*t,y:n.y+i.y*t};return this._3d&&(r.z=n.z+i.z*t),r}if(this._linear){var a=this.normal(0),s=this.points.map(function(t){var n={x:t.x+e*a.x,y:t.y+e*a.y};return t.z&&i.z&&(n.z=t.z+e*a.z),n});return[new d(s)]}var o=this.reduce();return o.map(function(t){return t.scale(e)})},simple:function(){if(3===this.order){var e=h.angle(this.points[0],this.points[3],this.points[1]),t=h.angle(this.points[0],this.points[3],this.points[2]);if(e>0&&t<0||e<0&&t>0)return!1}var n=this.normal(0),r=this.normal(1),a=n.x*r.x+n.y*r.y;this._3d&&(a+=n.z*r.z);var o=i(s(a));return o1,o.endcap.virtual=a0&&(r=r.concat(t))}),r},arcs:function(e){e=e||.5;var t=[];return this._iterate(e,t)},_error:function(e,t,n,r){var a=(r-n)/4,s=this.get(n+a),o=this.get(r-a),l=h.dist(e,t),c=h.dist(e,s),u=h.dist(e,o);return i(c-l)+i(u-l)},_iterate:function(e,t){var n,i=0,r=1;do{n=0,r=1;var a,s,o,l,c,u=this.get(i),d=!1,f=!1,m=r,p=1,g=0;do{f=d,l=o,m=(i+r)/2,g++,a=this.get(m),s=this.get(r),o=h.getccenter(u,a,s),o.interval={start:i,end:r};var v=this._error(o,u,i,r);if(d=v<=e,c=f&&!d,c||(p=r),d){if(r>=1){p=1,l=o;break}r+=(r-i)/2}else r=m}while(!c&&n++<100);if(n>=100){console.error("arc abstraction somehow failed...");break}l=l?l:o,t.push(l),i=p}while(r<1);return t}},e.exports=d}()},function(e,t,n){!function(){"use strict";var t=Math.abs,i=Math.cos,r=Math.sin,a=Math.acos,s=Math.atan2,o=Math.sqrt,l=Math.pow,c=function(e){return e<0?-l(-e,1/3):l(e,1/3)},h=Math.PI,u=2*h,d=h/2,f=1e-6,m={Tvalues:[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213],Cvalues:[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872],arcfn:function(e,t){var n=t(e),i=n.x*n.x+n.y*n.y;return"undefined"!=typeof n.z&&(i+=n.z*n.z),o(i)},between:function(e,t,n){return t<=e&&e<=n||m.approximately(e,t)||m.approximately(e,n)},approximately:function(e,n,i){return t(e-n)<=(i||f)},length:function(e){var t,n,i=.5,r=0,a=m.Tvalues.length;for(t=0;ta.x.min&&(t=a.x.min),n>a.y.min&&(n=a.y.min),i0&&(s.c1=t,s.c2=i,s.s1=e,s.s2=n,a.push(s))}})}),a},makeshape:function(e,t,n){var i=t.points.length,r=e.points.length,a=m.makeline(t.points[i-1],e.points[0]),s=m.makeline(e.points[r-1],t.points[0]),o={startcap:a,forward:e,back:t,endcap:s,bbox:m.findbbox([a,e,t,s])},l=m;return o.intersections=function(e){return l.shapeintersections(o,o.bbox,e,e.bbox,n)},o},getminmax:function(e,t,n){if(!n)return{min:0,max:0};var i,r,a=0x10000000000000000,s=-a;n.indexOf(0)===-1&&(n=[0].concat(n)),n.indexOf(1)===-1&&n.push(1);for(var o=0,l=n.length;os&&(s=r[t]);return{min:a,mid:(a+s)/2,max:s,size:s-a}},align:function(e,t){var n=t.p1.x,a=t.p1.y,o=-s(t.p2.y-a,t.p2.x-n),l=function(e){return{x:(e.x-n)*i(o)-(e.y-a)*r(o),y:(e.x-n)*r(o)+(e.y-a)*i(o)}};return e.map(l)},roots:function(e,t){t=t||{p1:{x:0,y:0},p2:{x:1,y:0}};var n=e.length-1,r=m.align(e,t),s=function(e){return 0<=e&&e<=1};if(2===n){var l=r[0].y,h=r[1].y,d=r[2].y,f=l-2*h+d;if(0!==f){var p=-o(h*h-l*d),g=-l+h,v=-(p+g)/f,w=-(-p+g)/f;return[v,w].filter(s)}return h!==d&&0===f?[(2*h-d)/2*(h-d)].filter(s):[]}var y,v,b,x,_,E=r[0].y,C=r[1].y,k=r[2].y,S=r[3].y,f=-E+3*C-3*k+S,l=(3*E-6*C+3*k)/f,h=(-3*E+3*C)/f,d=E/f,r=(3*h-l*l)/3,z=r/3,T=(2*l*l*l-9*l*h+27*d)/27,P=T/2,B=P*P+z*z*z;if(B<0){var N=-r/3,L=N*N*N,M=o(L),I=-T/(2*M),A=I<-1?-1:I>1?1:I,O=a(A),D=c(M),j=2*D;return b=j*i(O/3)-l/3,x=j*i((O+u)/3)-l/3,_=j*i((O+2*u)/3)-l/3,[b,x,_].filter(s)}if(0===B)return y=P<0?c(-P):-c(P),b=2*y-l/3,x=-y-l/3,[b,x].filter(s);var q=o(B);return y=c(-P+q),v=c(P+q),[y-v-l/3].filter(s)},droots:function(e){if(3===e.length){var t=e[0],n=e[1],i=e[2],r=t-2*n+i;if(0!==r){var a=-o(n*n-t*i),s=-t+n,l=-(a+s)/r,c=-(-a+s)/r;return[l,c]}return n!==i&&0===r?[(2*n-i)/(2*(n-i))]:[]}if(2===e.length){var t=e[0],n=e[1];return t!==n?[t/(t-n)]:[]}},inflections:function(e){if(e.length<4)return[];var t=m.align(e,{p1:e[0],p2:e.slice(-1)[0]}),n=t[2].x*t[1].y,i=t[3].x*t[1].y,r=t[1].x*t[2].y,a=t[3].x*t[2].y,s=18*(-3*n+2*i+3*r-a),o=18*(3*n-i-3*r),l=18*(r-n);if(m.approximately(s,0))return[];var c=o*o-4*s*l,h=Math.sqrt(c),a=2*s;return m.approximately(a,0)?[]:[(h-o)/a,-(o+h)/a].filter(function(e){return 0<=e&&e<=1})},bboxoverlap:function(e,n){var i,r,a,s,o,l=["x","y"],c=l.length;for(i=0;i=o)return!1;return!0},expandbox:function(e,t){t.x.mine.x.max&&(e.x.max=t.x.max),t.y.max>e.y.max&&(e.y.max=t.y.max),t.z&&t.z.max>e.z.max&&(e.z.max=t.z.max),e.x.mid=(e.x.min+e.x.max)/2,e.y.mid=(e.y.min+e.y.max)/2,e.z&&(e.z.mid=(e.z.min+e.z.max)/2),e.x.size=e.x.max-e.x.min,e.y.size=e.y.max-e.y.min,e.z&&(e.z.size=e.z.max-e.z.min)},pairiteration:function(e,t,n){var i=e.bbox(),r=t.bbox(),a=1e5,s=n||.5;if(i.x.size+i.y.sizeP||P>B)&&(T+=u),T>B&&(a=B,B=T,T=a)):Bu-1)throw new Error("degree must be less than or equal to point count - 1");if(!r)for(r=[],o=0;op)throw new Error("out of bounds");for(c=f[0];c=i[c]&&e<=i[c+1]);c++);var g=[];for(o=0;oc-t-1+h;o--)for(v=(e-i[o])/(i[o+t+1-h]-i[o]),l=0;l0||i0?[["dictionary",i.definitions],r]:r},deserialize:function(e,t,n,i){var r=e,a=!n;if(n=n||{},Array.isArray(e)){var s=e[0],l="dictionary"===s;if(1==e.length&&/^#/.test(s))return n.dictionary[s];s=o.exports[s],r=[],i&&(n.dictionary=r);for(var c=s?1:0,h=e.length;ce.length&&(n=e.length);for(var o=0;o0){var r=this._eventTypes,a=r&&r[i],s=a&&a[n];s&&s.call(this,i)}},statics:{inject:function e(t){var n=t._events;if(n){var i={};o.each(n,function(e,n){var r="string"==typeof e,a=r?e:n,s=o.capitalize(a),l=a.substring(2).toLowerCase();i[l]=r?{}:e,a="_"+a,t["get"+s]=function(){return this[a]},t["set"+s]=function(e){var t=this[a];t&&this.off(l,t),e&&this.on(l,e),this[a]=e}}),t._eventTypes=i}return e.base.apply(this,arguments)}}},c=o.extend({_class:"PaperScope",initialize:function e(){a=this,this.settings=new o({applyMatrix:!0,handleSize:4,hitTolerance:0}),this.project=null,this.projects=[],this.tools=[],this.palettes=[],this._id=e._id++,e._scopes[this._id]=this;var t=e.prototype;if(!this.support){var n=ne.getContext(1,1);t.support={nativeDash:"setLineDash"in n||"mozDash"in n,nativeBlendModes:ie.nativeModes},ne.release(n)}if(!this.browser){var i=navigator.userAgent.toLowerCase(),r=(/(win)/.exec(i)||/(mac)/.exec(i)||/(linux)/.exec(i)||[])[0],s=t.browser={platform:r};r&&(s[r]=!0),i.replace(/(opera|chrome|safari|webkit|firefox|msie|trident|atom)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:([.\d]+))?/g,function(e,t,n,i,r){if(!s.chrome){var a="opera"===t?i:n;"trident"===t&&(a=r,t="msie"),s.version=a,s.versionNumber=parseFloat(a),s.name=t,s[t]=!0}}),s.chrome&&delete s.webkit,s.atom&&delete s.chrome}},version:"0.9.25",getView:function(){return this.project&&this.project.getView()},getPaper:function(){return this},execute:function(e,t,n){a.PaperScript.execute(e,this,t,n),Q.updateFocus()},install:function(e){var t=this;o.each(["project","view","tool"],function(n){o.define(e,n,{configurable:!0,get:function(){return t[n]}})});for(var n in this)!/^_/.test(n)&&this[n]&&(e[n]=this[n])},setup:function(e){return a=this,this.project=new _(e),this},activate:function(){a=this},clear:function(){for(var e=this.projects.length-1;e>=0;e--)this.projects[e].remove();for(var e=this.tools.length-1;e>=0;e--)this.tools[e].remove();for(var e=this.palettes.length-1;e>=0;e--)this.palettes[e].remove()},remove:function(){this.clear(),delete c._scopes[this._id]},statics:new function(){function e(e){return e+="Attribute",function(t,n){return t[e](n)||t[e]("data-paper-"+n)}}return{_scopes:{},_id:0,get:function(e){return this._scopes[e]||null},getAttribute:e("get"),hasAttribute:e("has")}}}),h=o.extend(l,{initialize:function(e){this._scope=a,this._index=this._scope[this._list].push(this)-1,!e&&this._scope[this._reference]||this.activate()},activate:function(){if(!this._scope)return!1;var e=this._scope[this._reference];return e&&e!==this&&e.emit("deactivate"),this._scope[this._reference]=this,this.emit("activate",e),!0},isActive:function(){return this._scope[this._reference]===this},remove:function(){return null!=this._index&&(o.splice(this._scope[this._list],null,this._index,1),this._scope[this._reference]==this&&(this._scope[this._reference]=null),this._scope=null,!0)}}),u=o.extend({initialize:function(e){this.precision=e||5,this.multiplier=Math.pow(10,this.precision)},number:function(e){return Math.round(e*this.multiplier)/this.multiplier},pair:function(e,t,n){return this.number(e)+(n||",")+this.number(t)},point:function(e,t){return this.number(e.x)+(t||",")+this.number(e.y)},size:function(e,t){return this.number(e.width)+(t||",")+this.number(e.height)},rectangle:function(e,t){return this.point(e,t)+(t||",")+this.size(e,t)}});u.instance=new u;var d=new function(){function e(e,t,n){return en?n:e}var t=[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],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,a=Math.pow,s=1e-12,o=1.12e-16;return{TOLERANCE:1e-6,EPSILON:s,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(e){return e>=-s&&e<=s},integrate:function(e,i,r,a){for(var s=t[a-2],o=n[a-2],l=.5*(r-i),c=l+i,h=0,u=a+1>>1,d=1&a?o[h++]*e(c):0;h0?(a=n,n=u<=r?.5*(r+a):u):(r=n,n=u>=a?.5*(r+a):u)}return n},solveQuadratic:function(t,n,l,c,h,u){var d,f,m=0,p=h-s,g=u+s,v=1/0,w=n;if(n/=-2,f=n*n-t*l,0!==f&&i(f)=-o){var x=f<0?0:r(f),_=n+(n<0?-x:x);0===_?(d=l/t,v=-d):(d=_/t,v=l/_)}return isFinite(d)&&(null==h||d>p&&dp&&v0?1.3247179572*Math.max(_,r(x)):_,w=m-E*_,w!==m){do if(m=w,C=t*m,p=C+n,g=p*m+l,b=(C+p)*m+g,y=g*m+c,w=0===b?m:m-y/b/k,w===m){m=w;break}while(E*w>E*m);i(t)*m*m>i(c/m)&&(g=-c/m,p=(g-l)/m)}}var v=d.solveQuadratic(t,p,g,h,u,f);return isFinite(m)&&(0===v||m!==h[v-1])&&(null==u||m>u-s&&m1?e[1]:e[0]):null!=e.x?(this.x=e.x,this.y=e.y):null!=e.width?(this.x=e.width,this.y=e.height):null!=e.angle?(this.x=e.length,this.y=0,this.setAngle(e.angle)):(this.x=this.y=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(e,t){return this.x=e,this.y=t,this},equals:function(e){return this===e||e&&(this.x===e.x&&this.y===e.y||Array.isArray(e)&&this.x===e[0]&&this.y===e[1])||!1},clone:function(){return new m(this.x,this.y)},toString:function(){var e=u.instance;return"{ x: "+e.number(this.x)+", y: "+e.number(this.y)+" }"},_serialize:function(e){var t=e.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(e){if(this.isZero()){var t=this._angle||0;this.set(Math.cos(t)*e,Math.sin(t)*e)}else{var n=e/this.getLength();d.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(e){this.setAngleInRadians.call(this,e*Math.PI/180)},getAngleInDegrees:"#getAngle",setAngleInDegrees:"#setAngle",getAngleInRadians:function(){if(arguments.length){var e=m.read(arguments),t=this.getLength()*e.getLength();if(d.isZero(t))return NaN;var n=this.dot(e)/t;return Math.acos(n<-1?-1:n>1?1:n)}return this.isZero()?this._angle||0:this._angle=Math.atan2(this.y,this.x)},setAngleInRadians:function(e){if(this._angle=e,!this.isZero()){var t=this.getLength();this.set(Math.cos(e)*t,Math.sin(e)*t)}},getQuadrant:function(){return this.x>=0?this.y>=0?1:4:this.y>=0?2:3}},{beans:!1,getDirectedAngle:function(){var e=m.read(arguments);return 180*Math.atan2(this.cross(e),this.dot(e))/Math.PI},getDistance:function(){var e=m.read(arguments),t=e.x-this.x,n=e.y-this.y,i=t*t+n*n,r=o.read(arguments);return r?i:Math.sqrt(i)},normalize:function(e){e===s&&(e=1);var t=this.getLength(),n=0!==t?e/t:0,i=new m(this.x*n,this.y*n);return n>=0&&(i._angle=this._angle),i},rotate:function(e,t){if(0===e)return this.clone();e=e*Math.PI/180;var n=t?this.subtract(t):this,i=Math.sin(e),r=Math.cos(e);return n=new m(n.x*r-n.y*i,n.x*i+n.y*r),t?n.add(t):n},transform:function(e){return e?e._transformPoint(this):this},add:function(){var e=m.read(arguments);return new m(this.x+e.x,this.y+e.y)},subtract:function(){var e=m.read(arguments);return new m(this.x-e.x,this.y-e.y)},multiply:function(){var e=m.read(arguments);return new m(this.x*e.x,this.y*e.y)},divide:function(){var e=m.read(arguments);return new m(this.x/e.x,this.y/e.y)},modulo:function(){var e=m.read(arguments);return new m(this.x%e.x,this.y%e.y)},negate:function(){return new m(-this.x,-this.y)},isInside:function(){return w.read(arguments).contains(this)},isClose:function(){var e=m.read(arguments),t=o.read(arguments);return this.getDistance(e)1?e[1]:e[0]):null!=e.width?(this.width=e.width,this.height=e.height):null!=e.x?(this.width=e.x,this.height=e.y):(this.width=this.height=0,this.__read&&(this.__read=0)),this.__read&&(this.__read=1))},set:function(e,t){return this.width=e,this.height=t,this},equals:function(e){return e===this||e&&(this.width===e.width&&this.height===e.height||Array.isArray(e)&&this.width===e[0]&&this.height===e[1])||!1},clone:function(){return new g(this.width,this.height)},toString:function(){var e=u.instance;return"{ width: "+e.number(this.width)+", height: "+e.number(this.height)+" }"},_serialize:function(e){var t=e.formatter;return[t.number(this.width),t.number(this.height)]},add:function(){var e=g.read(arguments);return new g(this.width+e.width,this.height+e.height)},subtract:function(){var e=g.read(arguments);return new g(this.width-e.width,this.height-e.height)},multiply:function(){var e=g.read(arguments);return new g(this.width*e.width,this.height*e.height)},divide:function(){var e=g.read(arguments);return new g(this.width/e.width,this.height/e.height)},modulo:function(){var e=g.read(arguments);return new g(this.width%e.width,this.height%e.height)},negate:function(){return new g(-this.width,-this.height)},isZero:function(){return d.isZero(this.width)&&d.isZero(this.height)},isNaN:function(){return isNaN(this.width)||isNaN(this.height)},statics:{min:function(e,t){return new g(Math.min(e.width,t.width),Math.min(e.height,t.height))},max:function(e,t){return new g(Math.max(e.width,t.width),Math.max(e.height,t.height))},random:function(){return new g(Math.random(),Math.random())}}},o.each(["round","ceil","floor","abs"],function(e){var t=Math[e];this[e]=function(){return new g(t(this.width),t(this.height))}},{})),v=g.extend({initialize:function(e,t,n,i){this._width=e,this._height=t,this._owner=n,this._setter=i},set:function(e,t,n){return this._width=e,this._height=t,n||this._owner[this._setter](this),this},getWidth:function(){return this._width},setWidth:function(e){this._width=e,this._owner[this._setter](this)},getHeight:function(){return this._height},setHeight:function(e){this._height=e,this._owner[this._setter](this)}}),w=o.extend({_class:"Rectangle",_readIndex:!0,beans:!0,initialize:function(e,t,n,i){var r=typeof e,a=0;if("number"===r?(this.x=e,this.y=t,this.width=n,this.height=i,a=4):"undefined"===r||null===e?(this.x=this.y=this.width=this.height=0,a=null===e?1:0):1===arguments.length&&(Array.isArray(e)?(this.x=e[0],this.y=e[1],this.width=e[2],this.height=e[3],a=1):e.x!==s||e.width!==s?(this.x=e.x||0,this.y=e.y||0,this.width=e.width||0,this.height=e.height||0,a=1):e.from===s&&e.to===s&&(this.x=this.y=this.width=this.height=0,this._set(e),a=1)),!a){var l=m.readNamed(arguments,"from"),c=o.peek(arguments);if(this.x=l.x,this.y=l.y,c&&c.x!==s||o.hasNamed(arguments,"to")){var h=m.readNamed(arguments,"to");this.width=h.x-l.x,this.height=h.y-l.y,this.width<0&&(this.x=h.x,this.width=-this.width),this.height<0&&(this.y=h.y,this.height=-this.height)}else{var u=g.read(arguments);this.width=u.width,this.height=u.height}a=arguments.__index}this.__read&&(this.__read=a)},set:function(e,t,n,i){return this.x=e,this.y=t,this.width=n,this.height=i,this},clone:function(){return new w(this.x,this.y,this.width,this.height)},equals:function(e){var t=o.isPlainValue(e)?w.read(arguments):e;return t===this||t&&this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height||!1},toString:function(){var e=u.instance;return"{ x: "+e.number(this.x)+", y: "+e.number(this.y)+", width: "+e.number(this.width)+", height: "+e.number(this.height)+" }"},_serialize:function(e){var t=e.formatter;return[t.number(this.x),t.number(this.y),t.number(this.width),t.number(this.height)]},getPoint:function(e){var t=e?m:p;return new t(this.x,this.y,this,"setPoint")},setPoint:function(){var e=m.read(arguments);this.x=e.x,this.y=e.y},getSize:function(e){var t=e?g:v;return new t(this.width,this.height,this,"setSize")},setSize:function(){var e=g.read(arguments);this._fixX&&(this.x+=(this.width-e.width)*this._fixX),this._fixY&&(this.y+=(this.height-e.height)*this._fixY),this.width=e.width,this.height=e.height,this._fixW=1,this._fixH=1},getLeft:function(){return this.x},setLeft:function(e){this._fixW||(this.width-=e-this.x),this.x=e,this._fixX=0},getTop:function(){return this.y},setTop:function(e){this._fixH||(this.height-=e-this.y),this.y=e,this._fixY=0},getRight:function(){return this.x+this.width},setRight:function(e){this._fixX!==s&&1!==this._fixX&&(this._fixW=0),this._fixW?this.x=e-this.width:this.width=e-this.x,this._fixX=1},getBottom:function(){return this.y+this.height},setBottom:function(e){this._fixY!==s&&1!==this._fixY&&(this._fixH=0),this._fixH?this.y=e-this.height:this.height=e-this.y,this._fixY=1},getCenterX:function(){return this.x+.5*this.width},setCenterX:function(e){this.x=e-.5*this.width,this._fixX=.5},getCenterY:function(){return this.y+.5*this.height},setCenterY:function(e){this.y=e-.5*this.height,this._fixY=.5},getCenter:function(e){var t=e?m:p;return new t(this.getCenterX(),this.getCenterY(),this,"setCenter")},setCenter:function(){var e=m.read(arguments);return this.setCenterX(e.x),this.setCenterY(e.y),this},getArea:function(){return this.width*this.height},isEmpty:function(){return 0===this.width||0===this.height},contains:function(e){return e&&e.width!==s||4==(Array.isArray(e)?e:arguments).length?this._containsRectangle(w.read(arguments)):this._containsPoint(m.read(arguments))},_containsPoint:function(e){var t=e.x,n=e.y;return t>=this.x&&n>=this.y&&t<=this.x+this.width&&n<=this.y+this.height},_containsRectangle:function(e){var t=e.x,n=e.y;return t>=this.x&&n>=this.y&&t+e.width<=this.x+this.width&&n+e.height<=this.y+this.height},intersects:function(){var e=w.read(arguments);return e.x+e.width>this.x&&e.y+e.height>this.y&&e.x=this.x&&e.y+e.height>=this.y&&e.x<=this.x+this.width&&e.y<=this.y+this.height},intersect:function(){var e=w.read(arguments),t=Math.max(this.x,e.x),n=Math.max(this.y,e.y),i=Math.min(this.x+this.width,e.x+e.width),r=Math.min(this.y+this.height,e.y+e.height);return new w(t,n,i-t,r-n)},unite:function(){var e=w.read(arguments),t=Math.min(this.x,e.x),n=Math.min(this.y,e.y),i=Math.max(this.x+this.width,e.x+e.width),r=Math.max(this.y+this.height,e.y+e.height);return new w(t,n,i-t,r-n)},include:function(){var e=m.read(arguments),t=Math.min(this.x,e.x),n=Math.min(this.y,e.y),i=Math.max(this.x+this.width,e.x),r=Math.max(this.y+this.height,e.y);return new w(t,n,i-t,r-n)},expand:function(){var e=g.read(arguments),t=e.width,n=e.height;return new w(this.x-t/2,this.y-n/2,this.width+t,this.height+n)},scale:function(e,t){return this.expand(this.width*e-this.width,this.height*(t===s?e:t)-this.height)}},o.each([["Top","Left"],["Top","Right"],["Bottom","Left"],["Bottom","Right"],["Left","Center"],["Top","Center"],["Right","Center"],["Bottom","Center"]],function(e,t){var n=e.join(""),i=/^[RL]/.test(n);t>=4&&(e[1]+=i?"Y":"X");var r=e[i?0:1],a=e[i?1:0],s="get"+r,o="get"+a,l="set"+r,c="set"+a,h="get"+n,u="set"+n;this[h]=function(e){var t=e?m:p;return new t(this[s](),this[o](),this,u)},this[u]=function(){var e=m.read(arguments);this[l](e.x),this[c](e.y)}},{beans:!0})),y=w.extend({initialize:function(e,t,n,i,r,a){this.set(e,t,n,i,!0),this._owner=r,this._setter=a},set:function(e,t,n,i,r){return this._x=e,this._y=t,this._width=n,this._height=i,r||this._owner[this._setter](this),this}},new function(){var e=w.prototype;return o.each(["x","y","width","height"],function(e){var t=o.capitalize(e),n="_"+e;this["get"+t]=function(){return this[n]},this["set"+t]=function(e){this[n]=e,this._dontNotify||this._owner[this._setter](this)}},o.each(["Point","Size","Center","Left","Top","Right","Bottom","CenterX","CenterY","TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],function(t){var n="set"+t;this[n]=function(){this._dontNotify=!0,e[n].apply(this,arguments),this._dontNotify=!1,this._owner[this._setter](this)}},{isSelected:function(){return this._owner._boundsSelected},setSelected:function(e){var t=this._owner;t.setSelected&&(t._boundsSelected=e,t.setSelected(e||t._selectedSegmentState>0))}}))}),b=o.extend({_class:"Matrix",initialize:function e(t){var n=arguments.length,i=!0;if(6===n?this.set.apply(this,arguments):1===n?t instanceof e?this.set(t._a,t._c,t._b,t._d,t._tx,t._ty):Array.isArray(t)?this.set.apply(this,t):i=!1:0===n?this.reset():i=!1,!i)throw new Error("Unsupported matrix parameters")},set:function(e,t,n,i,r,a,s){return this._a=e,this._c=t,this._b=n,this._d=i,this._tx=r,this._ty=a,s||this._changed(),this},_serialize:function(e){return o.serialize(this.getValues(),e)},_changed:function(){var e=this._owner;e&&(e._applyMatrix?e.transform(null,!0):e._changed(9))},clone:function(){return new b(this._a,this._c,this._b,this._d,this._tx,this._ty)},equals:function(e){return e===this||e&&this._a===e._a&&this._b===e._b&&this._c===e._c&&this._d===e._d&&this._tx===e._tx&&this._ty===e._ty||!1},toString:function(){var e=u.instance;return"[["+[e.number(this._a),e.number(this._b),e.number(this._tx)].join(", ")+"], ["+[e.number(this._c),e.number(this._d),e.number(this._ty)].join(", ")+"]]"},reset:function(e){return this._a=this._d=1,this._c=this._b=this._tx=this._ty=0,e||this._changed(),this},apply:function(e,t){var n=this._owner;return!!n&&(n.transform(null,!0,o.pick(e,!0),t),this.isIdentity())},translate:function(){var e=m.read(arguments),t=e.x,n=e.y;return this._tx+=t*this._a+n*this._b,this._ty+=t*this._c+n*this._d,this._changed(),this},scale:function(){var e=m.read(arguments),t=m.read(arguments,0,{readNull:!0});return t&&this.translate(t),this._a*=e.x,this._c*=e.x,this._b*=e.y,this._d*=e.y,t&&this.translate(t.negate()),this._changed(),this},rotate:function(e){e*=Math.PI/180;var t=m.read(arguments,1),n=t.x,i=t.y,r=Math.cos(e),a=Math.sin(e),s=n-n*r+i*a,o=i-n*a-i*r,l=this._a,c=this._b,h=this._c,u=this._d;return this._a=r*l+a*c,this._b=-a*l+r*c,this._c=r*h+a*u,this._d=-a*h+r*u,this._tx+=s*l+o*c,this._ty+=s*h+o*u,this._changed(),this},shear:function(){var e=m.read(arguments),t=m.read(arguments,0,{readNull:!0});t&&this.translate(t);var n=this._a,i=this._c; -return this._a+=e.y*this._b,this._c+=e.y*this._d,this._b+=e.x*n,this._d+=e.x*i,t&&this.translate(t.negate()),this._changed(),this},skew:function(){var e=m.read(arguments),t=m.read(arguments,0,{readNull:!0}),n=Math.PI/180,i=new m(Math.tan(e.x*n),Math.tan(e.y*n));return this.shear(i,t)},concatenate:function(e){var t=this._a,n=this._b,i=this._c,r=this._d,a=e._a,s=e._b,o=e._c,l=e._d,c=e._tx,h=e._ty;return this._a=a*t+o*n,this._b=s*t+l*n,this._c=a*i+o*r,this._d=s*i+l*r,this._tx+=c*t+h*n,this._ty+=c*i+h*r,this._changed(),this},preConcatenate:function(e){var t=this._a,n=this._b,i=this._c,r=this._d,a=this._tx,s=this._ty,o=e._a,l=e._b,c=e._c,h=e._d,u=e._tx,d=e._ty;return this._a=o*t+l*i,this._b=o*n+l*r,this._c=c*t+h*i,this._d=c*n+h*r,this._tx=o*a+l*s+u,this._ty=c*a+h*s+d,this._changed(),this},chain:function(e){var t=this._a,n=this._b,i=this._c,r=this._d,a=this._tx,s=this._ty,o=e._a,l=e._b,c=e._c,h=e._d,u=e._tx,d=e._ty;return new b(o*t+c*n,o*i+c*r,l*t+h*n,l*i+h*r,a+u*t+d*n,s+u*i+d*r)},isIdentity:function(){return 1===this._a&&0===this._c&&0===this._b&&1===this._d&&0===this._tx&&0===this._ty},orNullIfIdentity:function(){return this.isIdentity()?null:this},isInvertible:function(){return!!this._getDeterminant()},isSingular:function(){return!this._getDeterminant()},transform:function(e,t,n){return arguments.length<3?this._transformPoint(m.read(arguments)):this._transformCoordinates(e,t,n)},_transformPoint:function(e,t,n){var i=e.x,r=e.y;return t||(t=new m),t.set(i*this._a+r*this._b+this._tx,i*this._c+r*this._d+this._ty,n)},_transformCoordinates:function(e,t,n){for(var i=0,r=0,a=2*n;ia[l]&&(a[l]=o)}return t||(t=new w),t.set(r[0],r[1],a[0]-r[0],a[1]-r[1],n)},inverseTransform:function(){return this._inverseTransform(m.read(arguments))},_getDeterminant:function(){var e=this._a*this._d-this._b*this._c;return isFinite(e)&&!d.isZero(e)&&isFinite(this._tx)&&isFinite(this._ty)?e:null},_inverseTransform:function(e,t,n){var i=this._getDeterminant();if(!i)return null;var r=e.x-this._tx,a=e.y-this._ty;return t||(t=new m),t.set((r*this._d-a*this._b)/i,(a*this._a-r*this._c)/i,n)},decompose:function(){var e=this._a,t=this._b,n=this._c,i=this._d;if(d.isZero(e*i-t*n))return null;var r=Math.sqrt(e*e+t*t);e/=r,t/=r;var a=e*n+t*i;n-=e*a,i-=t*a;var s=Math.sqrt(n*n+i*i);return n/=s,i/=s,a/=s,e*i=4?(this._px=e,this._py=t,this._vx=n,this._vy=i,a=r):(this._px=e.x,this._py=e.y,this._vx=t.x,this._vy=t.y,a=n),a||(this._vx-=this._px,this._vy-=this._py)},getPoint:function(){return new m(this._px,this._py)},getVector:function(){return new m(this._vx,this._vy)},getLength:function(){return this.getVector().getLength()},intersect:function(e,t){return x.intersect(this._px,this._py,this._vx,this._vy,e._px,e._py,e._vx,e._vy,!0,t)},getSide:function(e,t){return x.getSide(this._px,this._py,this._vx,this._vy,e.x,e.y,!0,t)},getDistance:function(e){return Math.abs(x.getSignedDistance(this._px,this._py,this._vx,this._vy,e.x,e.y,!0))},isCollinear:function(e){return m.isCollinear(this._vx,this._vy,e._vx,e._vy)},isOrthogonal:function(e){return m.isOrthogonal(this._vx,this._vy,e._vx,e._vy)},statics:{intersect:function(e,t,n,i,r,a,s,o,l,c){l||(n-=e,i-=t,s-=r,o-=a);var h=n*o-i*s;if(!d.isZero(h)){var u=e-r,f=t-a,p=(s*f-o*u)/h,g=(n*f-i*u)/h,v=1e-12,w=-v,y=1+v;if(c||w=1?1:p),new m(e+p*n,t+p*i)}},getSide:function(e,t,n,i,r,a,s,o){s||(n-=e,i-=t);var l=r-e,c=a-t,h=l*i-c*n;return 0!==h||o||(h=(l*n+l*n)/(n*n+i*i),h>=0&&h<=1&&(h=0)),h<0?-1:h>0?1:0},getSignedDistance:function(e,t,n,i,r,a,s){return s||(n-=e,i-=t),0===n?i>0?r-e:e-r:0===i?n<0?a-t:t-a:((r-e)*i-(a-t)*n)/Math.sqrt(n*n+i*i)}}}),_=h.extend({_class:"Project",_list:"projects",_reference:"project",initialize:function(e){h.call(this,!0),this.layers=[],this._activeLayer=null,this.symbols=[],this._currentStyle=new X(null,null,this),this._view=Q.create(this,e||ne.getCanvas(1,1)),this._selectedItems={},this._selectedItemCount=0,this._updateVersion=0},_serialize:function(e,t){return o.serialize(this.layers,e,!0,t)},clear:function(){for(var e=this.layers.length-1;e>=0;e--)this.layers[e].remove();this.symbols=[]},isEmpty:function(){return 0===this.layers.length},remove:function e(){return!!e.base.call(this)&&(this._view&&this._view.remove(),!0)},getView:function(){return this._view},getCurrentStyle:function(){return this._currentStyle},setCurrentStyle:function(e){this._currentStyle.initialize(e)},getIndex:function(){return this._index},getOptions:function(){return this._scope.settings},getActiveLayer:function(){return this._activeLayer||new S({project:this})},getSelectedItems:function(){var e=[];for(var t in this._selectedItems){var n=this._selectedItems[t];n.isInserted()&&e.push(n)}return e},insertChild:function(e,t,n){return t instanceof S?(t._remove(!1,!0),o.splice(this.layers,[t],e,0),t._setProject(this,!0),this._changes&&t._changed(5),this._activeLayer||(this._activeLayer=t)):t instanceof C?(this._activeLayer||this.insertChild(e,new S(C.NO_INSERT))).insertChild(e,t,n):t=null,t},addChild:function(e,t){return this.insertChild(s,e,t)},_updateSelection:function(e){var t=e._id,n=this._selectedItems;e._selected?n[t]!==e&&(this._selectedItemCount++,n[t]=e):n[t]===e&&(this._selectedItemCount--,delete n[t])},selectAll:function(){for(var e=this.layers,t=0,n=e.length;t=0;n--){var i=this.layers[n]._hitTest(e,t);if(i)return i}return null},getItems:function(e){return C._getItems(this.layers,e)},getItem:function(e){return C._getItems(this.layers,e,null,null,!0)[0]||null},importJSON:function(e){this.activate();var t=this._activeLayer;return o.importJSON(e,t&&t.isEmpty()&&t)},draw:function(e,t,n){this._updateVersion++,e.save(),t.applyToContext(e);for(var i=new o({offset:new m(0,0),pixelRatio:n,viewMatrix:t.isIdentity()?null:t,matrices:[new b],updateMatrix:!0}),r=0,a=this.layers,s=a.length;r0){e.save(),e.strokeWidth=1;var l=this._selectedItems,c=this._scope.settings.handleSize,h=this._updateVersion;for(var u in l)l[u]._drawSelection(e,t,c,l,h);e.restore()}}}),E=o.extend({_class:"Symbol",initialize:function(e,t){this._id=f.get(),this.project=a.project,this.project.symbols.push(this),e&&this.setDefinition(e,t)},_serialize:function(e,t){return t.add(this,function(){return o.serialize([this._class,this._definition],e,!1,t)})},_changed:function(e){8&e&&C._clearBoundsCache(this),1&e&&(this.project._needsUpdate=!0)},getDefinition:function(){return this._definition},setDefinition:function(e,t){e._parentSymbol&&(e=e.clone()),this._definition&&(this._definition._parentSymbol=null),this._definition=e,e.remove(),e.setSelected(!1),t||e.setPosition(new m),e._parentSymbol=this,this._changed(9)},place:function(e){return new P(this,e)},clone:function(){return new E(this._definition.clone(!1))},equals:function(e){return e===this||e&&this.definition.equals(e.definition)||!1}}),C=o.extend(l,{statics:{extend:function e(t){return t._serializeFields&&(t._serializeFields=new o(this.prototype._serializeFields,t._serializeFields)),e.base.apply(this,arguments)},NO_INSERT:{insert:!1}},_class:"Item",_applyMatrix:!0,_canApplyMatrix:!0,_boundsSelected:!1,_selectChildren:!1,_serializeFields:{name:null,applyMatrix:null,matrix:new b,pivot:null,locked:!1,visible:!0,blendMode:"normal",opacity:1,guide:!1,selected:!1,clipMask:!1,data:{}},initialize:function(){},_initialize:function(e,t){var n=e&&o.isPlainObject(e),i=n&&e.internal===!0,r=this._matrix=new b,s=n&&e.project||a.project;return i||(this._id=f.get()),this._applyMatrix=this._canApplyMatrix&&a.settings.applyMatrix,t&&r.translate(t),r._owner=this,this._style=new X(s._currentStyle,this,s),this._project||(i||n&&e.insert===!1?this._setProject(s):n&&e.parent?this.setParent(e.parent):(s._activeLayer||new S).addChild(this)),n&&e!==C.NO_INSERT&&this._set(e,{insert:!0,project:!0,parent:!0},!0),n},_events:o.each(["onMouseDown","onMouseUp","onMouseDrag","onClick","onDoubleClick","onMouseMove","onMouseEnter","onMouseLeave"],function(e){this[e]={install:function(e){this.getView()._installEvent(e)},uninstall:function(e){this.getView()._uninstallEvent(e)}}},{onFrame:{install:function(){this.getView()._animateItem(this,!0)},uninstall:function(){this.getView()._animateItem(this,!1)}},onLoad:{}}),_serialize:function(e,t){function n(n){for(var a in n){var s=r[a];o.equals(s,"leading"===a?1.2*n.fontSize:n[a])||(i[a]=o.serialize(s,e,"data"!==a,t))}}var i={},r=this;return n(this._serializeFields),this instanceof k||n(this._style._defaults),[this._class,i]},_changed:function(e){var t=this._parentSymbol,n=this._parent||t,i=this._project;if(8&e&&(this._bounds=this._position=this._decomposed=this._globalMatrix=this._currentPath=s),n&&40&e&&C._clearBoundsCache(n),2&e&&C._clearBoundsCache(this),i&&(1&e&&(i._needsUpdate=!0),i._changes)){var r=i._changesById[this._id];r?r.flags|=e:(r={item:this,flags:e},i._changesById[this._id]=r,i._changes.push(r))}t&&t._changed(e)},set:function(e){return e&&this._set(e),this},getId:function(){return this._id},getName:function(){return this._name},setName:function(e,t){if(this._name&&this._removeNamed(),e===+e+"")throw new Error("Names consisting only of numbers are not supported.");var n=this._parent;if(e&&n){for(var i=n._children,r=n._namedChildren,a=e,o=1;t&&i[e];)e=a+" "+o++;(r[e]=r[e]||[]).push(this),i[e]=this}this._name=e||s,this._changed(128)},getStyle:function(){return this._style},setStyle:function(e){this.getStyle().set(e)}},o.each(["locked","visible","blendMode","opacity","guide"],function(e){var t=o.capitalize(e),e="_"+e;this["get"+t]=function(){return this[e]},this["set"+t]=function(t){t!=this[e]&&(this[e]=t,this._changed("_locked"===e?128:129))}},{}),{beans:!0,_locked:!1,_visible:!0,_blendMode:"normal",_opacity:1,_guide:!1,isSelected:function(){if(this._selectChildren)for(var e=this._children,t=0,n=e.length;t=0;t--)if(this._children[t].contains(e))return!0;return!1}return e.isInside(this.getInternalBounds())},isInside:function(){return w.read(arguments).contains(this.getBounds())},_asPathItem:function(){return new O.Rectangle({rectangle:this.getInternalBounds(),matrix:this._matrix,insert:!1})},intersects:function(e,t){return e instanceof C&&this._asPathItem().getIntersections(e._asPathItem(),null,t||e._matrix,!0).length>0},hitTest:function(){return this._hitTest(m.read(arguments),B.getOptions(o.read(arguments)))},_hitTest:function(e,t){function n(t,n){var i=d["get"+n]();if(e.subtract(i).divide(l).length<=1)return new B(t,u,{name:o.hyphenate(n),point:i})}if(this._locked||!this._visible||this._guide&&!t.guides||this.isEmpty())return null;var i=this._matrix,r=t._totalMatrix,a=this.getView(),s=t._totalMatrix=r?r.chain(i):this.getGlobalMatrix().preConcatenate(a._matrix),l=t._tolerancePadding=new g(O._getPenPadding(1,s.inverted())).multiply(Math.max(t.tolerance,1e-6));if(e=i._inverseTransform(e),!this._children&&!this.getInternalRoughBounds().expand(l.multiply(2))._containsPoint(e))return null;var c,h=!(t.guides&&!this._guide||t.selected&&!this._selected||t.type&&t.type!==o.hyphenate(this._class)||t.class&&!(this instanceof t.class)),u=this;if(h&&(t.center||t.bounds)&&this._parent){var d=this.getInternalBounds();if(t.center&&(c=n("center","Center")),!c&&t.bounds)for(var f=["TopLeft","TopRight","BottomLeft","BottomRight","LeftCenter","TopCenter","RightCenter","BottomCenter"],m=0;m<8&&!c;m++)c=n("bounds",f[m])}var p=!c&&this._children;if(p)for(var v=this._getChildHitTestOptions(t),m=p.length-1;m>=0&&!c;m--)c=p[m]._hitTest(e,v);return!c&&h&&(c=this._hitTestSelf(e,t)),c&&c.point&&(c.point=i.transform(c.point)),t._totalMatrix=r,c},_getChildHitTestOptions:function(e){return e},_hitTestSelf:function(e,t){if(t.fill&&this.hasFill()&&this._contains(e))return new B("fill",this)},matches:function(e,t){function n(e,t){for(var i in e)if(e.hasOwnProperty(i)){var r=e[i],a=t[i];if(o.isPlainObject(r)&&o.isPlainObject(a)){if(!n(r,a))return!1}else if(!o.equals(r,a))return!1}return!0}var i=typeof e;if("object"===i){for(var r in e)if(e.hasOwnProperty(r)&&!this.matches(r,e[r]))return!1}else{if("function"===i)return e(this);var a=/^(empty|editable)$/.test(e)?this["is"+o.capitalize(e)]():"type"===e?o.hyphenate(this._class):this[e];if(/^(constructor|class)$/.test(e)){if(!(this instanceof t))return!1}else if(t instanceof RegExp){if(!t.test(a))return!1}else if("function"==typeof t){if(!t(a))return!1}else if(o.isPlainObject(t)){if(!n(t,a))return!1}else if(!o.equals(a,t))return!1}return!0},getItems:function(e){return C._getItems(this._children,e,this._matrix)},getItem:function(e){return C._getItems(this._children,e,this._matrix,null,!0)[0]||null},statics:{_getItems:function e(t,n,i,r,a){if(!r&&"object"==typeof n){var s=n.overlapping,l=n.inside,c=s||l,h=c&&w.read([c]);r={items:[],inside:!!l,overlapping:!!s,rect:h,path:s&&new O.Rectangle({rectangle:h,insert:!1})},c&&(n=o.set({},n,{inside:!0,overlapping:!0}))}var u=r&&r.items,h=r&&r.rect;i=h&&(i||new b);for(var d=0,f=t&&t.length;d0)break}return u}}},{importJSON:function(e){var t=o.importJSON(e,this);return t!==this?this.addChild(t):t},addChild:function(e,t){return this.insertChild(s,e,t)},insertChild:function(e,t,n){var i=t?this.insertChildren(e,[t],n):null;return i&&i[0]},addChildren:function(e,t){return this.insertChildren(this._children.length,e,t)},insertChildren:function(e,t,n,i){var r=this._children;if(r&&t&&t.length>0){t=Array.prototype.slice.apply(t);for(var a=t.length-1;a>=0;a--){var s=t[a];if(!i||s instanceof i){var l=s._parent===this&&s._index=0;i--)n[i]._remove(!0,!1);return n.length>0&&this._changed(11),n},clear:"#removeChildren",reverseChildren:function(){if(this._children){this._children.reverse();for(var e=0,t=this._children.length;e0},isInserted:function(){return!!this._parent&&this._parent.isInserted()},isAbove:function(e){return this._getOrder(e)===-1},isBelow:function(e){return 1===this._getOrder(e)},isParent:function(e){return this._parent===e},isChild:function(e){return e&&e._parent===this},isDescendant:function(e){for(var t=this;t=t._parent;)if(t==e)return!0;return!1},isAncestor:function(e){return!!e&&e.isDescendant(this)},isSibling:function(e){return this._parent===e._parent},isGroupedWith:function(e){for(var t=this._parent;t;){if(t._parent&&/^(Group|Layer|CompoundPath)$/.test(t._class)&&e.isDescendant(t))return!0;t=t._parent}return!1},translate:function(){var e=new b;return this.transform(e.translate.apply(e,arguments))},rotate:function(e){return this.transform((new b).rotate(e,m.read(arguments,1,{readNull:!0})||this.getPosition(!0)))}},o.each(["scale","shear","skew"],function(e){this[e]=function(){var t=m.read(arguments),n=m.read(arguments,0,{readNull:!0});return this.transform((new b)[e](t,n||this.getPosition(!0)))}},{}),{transform:function(e,t,n,i){e&&e.isIdentity()&&(e=null);var r=this._matrix,a=(t||this._applyMatrix)&&(!r.isIdentity()||e||t&&n&&this._children);if(!e&&!a)return this;if(e&&r.preConcatenate(e),a=a&&this._transformContent(r,n,i)){var s=this._pivot,o=this._style,l=o.getFillColor(!0),c=o.getStrokeColor(!0);s&&r._transformPoint(s,s,!0),l&&l.transform(r),c&&c.transform(r),r.reset(!0),i&&this._canApplyMatrix&&(this._applyMatrix=!0)}var h=this._bounds,u=this._position;this._changed(9);var d=h&&e&&e.decompose();if(d&&!d.shearing&&d.rotation%90===0){for(var f in h){var m=h[f];!a&&m._internal||e._transformBounds(m,m)}var p=this._boundsGetter,m=h[p&&p.getBounds||p||"getBounds"];m&&(this._position=m.getCenter(!0)),this._bounds=h}else e&&u&&(this._position=e._transformPoint(u,u));return this},_transformContent:function(e,t,n){var i=this._children;if(i){for(var r=0,a=i.length;rr:i0){e.strokeStyle=i.toCanvasStyle(e),e.lineWidth=s;var o=t.getStrokeJoin(),l=t.getStrokeCap(),c=t.getMiterLimit();if(o&&(e.lineJoin=o),l&&(e.lineCap=l),c&&(e.miterLimit=c),a.support.nativeDash){var h=t.getDashArray(),u=t.getDashOffset();h&&h.length&&("setLineDash"in e?(e.setLineDash(h),e.lineDashOffset=u):(e.mozDash=h,e.mozDashOffset=u))}}}if(r){var d=t.getShadowBlur();if(d>0){e.shadowColor=r.toCanvasStyle(e),e.shadowBlur=d;var f=this.getShadowOffset();e.shadowOffsetX=f.x,e.shadowOffsetY=f.y}}},draw:function(e,t,n){function i(e){return s?s.chain(e):e}var r=this._updateVersion=this._project._updateVersion;if(this._visible&&0!==this._opacity){var a=t.matrices,s=t.viewMatrix,o=this._matrix,l=a[a.length-1].chain(o);if(l.isInvertible()){a.push(l),t.updateMatrix&&(l._updateVersion=r,this._globalMatrix=l);var c,h,u,d=this._blendMode,f=this._opacity,m="normal"===d,p=ie.nativeModes[d],g=m&&1===f||t.dontStart||t.clip||(p||m&&f<1)&&this._canComposite(),v=t.pixelRatio||1;if(!g){var w=this.getStrokeBounds(i(l));if(!w.width||!w.height)return;u=t.offset,h=t.offset=w.getTopLeft().floor(),c=e,e=ne.getContext(w.getSize().ceil().add(1).multiply(v)),1!==v&&e.scale(v,v)}e.save();var y=n?n.chain(o):!this.getStrokeScaling(!0)&&i(l),b=!g&&t.clipItem,x=!y||b;if(g?(e.globalAlpha=f,p&&(e.globalCompositeOperation=d)):x&&e.translate(-h.x,-h.y),x&&(g?o:i(l)).applyToContext(e),b&&t.clipItem.draw(e,t.extend({clip:!0})),y){e.setTransform(v,0,0,v,0,0);var _=t.offset;_&&e.translate(-_.x,-_.y)}this._draw(e,t,y),e.restore(),a.pop(),t.clip&&!t.dontFinish&&e.clip(),g||(ie.process(d,e,c,f,h.subtract(u).multiply(v)),ne.release(e),t.offset=u)}}},_isUpdated:function(e){var t=this._parent;if(t instanceof D)return t._isUpdated(e);var n=this._updateVersion===e;return!n&&t&&t._visible&&t._isUpdated(e)&&(this._updateVersion=e,n=!0),n},_drawSelection:function(e,t,n,i,r){if((this._drawSelected||this._boundsSelected)&&this._isUpdated(r)){var a=this.getSelectedColor(!0)||this.getLayer().getSelectedColor(!0),s=t.chain(this.getGlobalMatrix(!0));if(e.strokeStyle=e.fillStyle=a?a.toCanvasStyle(e):"#009dec",this._drawSelected&&this._drawSelected(e,s,i),this._boundsSelected){var o=n/2,l=s._transformCorners(this.getInternalBounds());e.beginPath();for(var c=0;c<8;c++)e[0===c?"moveTo":"lineTo"](l[c],l[++c]);e.closePath(),e.stroke();for(var c=0;c<8;c++)e.fillRect(l[c]-o,l[++c]-o,n,n)}}},_canComposite:function(){return!1}},o.each(["down","drag","up","move"],function(e){this["removeOn"+o.capitalize(e)]=function(){var t={};return t[e]=!0,this.removeOn(t)}},{removeOn:function(e){for(var t in e)if(e[t]){var n="mouse"+t,i=this._project,r=i._removeSets=i._removeSets||{};r[n]=r[n]||{},r[n][this._id]=this}return this}})),k=C.extend({_class:"Group",_selectChildren:!0,_serializeFields:{children:[]},initialize:function(e){this._children=[],this._namedChildren={},this._initialize(e)||this.addChildren(Array.isArray(e)?e:arguments)},_changed:function e(t){e.base.call(this,t),1026&t&&(this._clipItem=s)},_getClipItem:function(){var e=this._clipItem;if(e===s){e=null;for(var t=0,n=this._children.length;t1?1:-1),o=s.multiply(r),l=o.subtract(s.multiply(i)),c=new w(o,l);if((n?c.expand(n):c).contains(t))return l}}function t(e,t){var n=e.getAngleInRadians(),i=2*t.width,r=2*t.height,a=i*Math.sin(n),s=r*Math.cos(n);return i*r/(2*Math.sqrt(a*a+s*s))}return{_contains:function t(n){if("rectangle"===this._type){var i=e(this,n);return i?n.subtract(i).divide(this._radius).getLength()<=1:t.base.call(this,n)}return n.divide(this.size).getLength()<=.5},_hitTestSelf:function n(i,r){var a=!1;if(this.hasStroke()){var s=this._type,o=this._radius,l=this.getStrokeWidth()+2*r.tolerance;if("rectangle"===s){var c=e(this,i,l);if(c){var h=i.subtract(c);a=2*Math.abs(h.getLength()-t(h,o))<=l}else{var u=new w(this._size).setCenter(0,0),d=u.expand(l),f=u.expand(-l);a=d._containsPoint(i)&&!f._containsPoint(i)}}else"ellipse"===s&&(o=t(i,o)),a=2*Math.abs(i.getLength()-o)<=l}return a?new B("stroke",this):n.base.apply(this,arguments)}}},{statics:new function(){function e(e,t,n,i,r){var a=new z(o.getNamed(r));return a._type=e,a._size=n,a._radius=i,a.translate(t)}return{Circle:function(){var t=m.readNamed(arguments,"center"),n=o.readNamed(arguments,"radius");return e("circle",t,new g(2*n),n,arguments)},Rectangle:function(){var t=w.readNamed(arguments,"rectangle"),n=g.min(g.readNamed(arguments,"radius"),t.getSize(!0).divide(2));return e("rectangle",t.getCenter(!0),t.getSize(!0),n,arguments)},Ellipse:function(){var t=z._readEllipse(arguments),n=t.radius;return e("ellipse",t.center,n.multiply(2),n,arguments)},_readEllipse:function(e){var t,n;if(o.hasNamed(e,"radius"))t=m.readNamed(e,"center"),n=g.readNamed(e,"radius");else{var i=w.readNamed(e,"rectangle");t=i.getCenter(!0),n=i.getSize(!0).divide(2)}return{center:t,radius:n}}}}}),T=C.extend({_class:"Raster",_applyMatrix:!1,_canApplyMatrix:!1,_boundsGetter:"getBounds",_boundsSelected:!0,_serializeFields:{crossOrigin:null,source:null},initialize:function(e,t){this._initialize(e,t!==s&&m.read(arguments,1))||("string"==typeof e?this.setSource(e):this.setImage(e)),this._size||(this._size=new g,this._loaded=!1)},_equals:function(e){return this.getSource()===e.getSource()},clone:function(e){var t=new T(C.NO_INSERT),n=this._image,i=this._canvas;if(n)t.setImage(n);else if(i){var r=ne.getCanvas(this._size);r.getContext("2d").drawImage(i,0,0),t.setImage(r)}return t._crossOrigin=this._crossOrigin,this._clone(t,e)},getSize:function(){var e=this._size;return new v(e?e.width:0,e?e.height:0,this,"setSize")},setSize:function(){var e=g.read(arguments);if(!e.equals(this._size))if(e.width>0&&e.height>0){var t=this.getElement();this.setImage(ne.getCanvas(e)),t&&this.getContext(!0).drawImage(t,0,0,e.width,e.height)}else this._canvas&&ne.release(this._canvas),this._size=e.clone()},getWidth:function(){return this._size?this._size.width:0},setWidth:function(e){this.setSize(e,this.getHeight())},getHeight:function(){return this._size?this._size.height:0},setHeight:function(e){this.setSize(this.getWidth(),e)},isEmpty:function(){var e=this._size;return!e||0===e.width&&0===e.height},getResolution:function(){var e=this._matrix,t=new m(0,0).transform(e),n=new m(1,0).transform(e).subtract(t),i=new m(0,1).transform(e).subtract(t);return new g(72/n.getLength(),72/i.getLength())},getPpi:"#getResolution",getImage:function(){return this._image},setImage:function(e){this._canvas&&ne.release(this._canvas),e&&e.getContext?(this._image=null,this._canvas=e,this._loaded=!0):(this._image=e,this._canvas=null,this._loaded=e&&e.complete),this._size=new g(e?e.naturalWidth||e.width:0,e?e.naturalHeight||e.height:0),this._context=null,this._changed(521)},getCanvas:function(){if(!this._canvas){var e=ne.getContext(this._size);try{this._image&&e.drawImage(this._image,0,0),this._canvas=e.canvas}catch(t){ne.release(e)}}return this._canvas},setCanvas:"#setImage",getContext:function(e){return this._context||(this._context=this.getCanvas().getContext("2d")),e&&(this._image=null,this._changed(513)),this._context},setContext:function(e){this._context=e},getSource:function(){return this._image&&this._image.src||this.toDataURL()},setSource:function(e){function t(){var e=i.getView();e&&(a=e._scope,i.setImage(n),i.emit("load"),e.update())}var n,i=this,r=this._crossOrigin;n=document.getElementById(e)||new Image,r&&(n.crossOrigin=r),n.naturalWidth&&n.naturalHeight?setTimeout(t,0):(U.add(n,{load:t}),n.src||(n.src=e)),this.setImage(n)},getCrossOrigin:function(){return this._image&&this._image.crossOrigin||this._crossOrigin||""},setCrossOrigin:function(e){this._crossOrigin=e,this._image&&(this._image.crossOrigin=e)},getElement:function(){return this._canvas||this._loaded&&this._image}},{beans:!1,getSubCanvas:function(){var e=w.read(arguments),t=ne.getContext(e.getSize());return t.drawImage(this.getCanvas(),e.x,e.y,e.width,e.height,0,0,e.width,e.height),t.canvas},getSubRaster:function(){var e=w.read(arguments),t=new T(C.NO_INSERT);return t.setImage(this.getSubCanvas(e)),t.translate(e.getCenter().subtract(this.getSize().divide(2))),t._matrix.preConcatenate(this._matrix),t.insertAbove(this),t},toDataURL:function(){var e=this._image&&this._image.src;if(/^data:/.test(e))return e;var t=this.getCanvas();return t?t.toDataURL.apply(t,arguments):null},drawImage:function(e){var t=m.read(arguments,1);this.getContext(!0).drawImage(e,t.x,t.y)},getAverageColor:function(e){var t,n;e?e instanceof A?(n=e,t=e.getBounds()):e.width?t=new w(e):e.x&&(t=new w(e.x-.5,e.y-.5,1,1)):t=this.getBounds();var i=32,r=Math.min(t.width,i),a=Math.min(t.height,i),s=T._sampleContext;s?s.clearRect(0,0,i+1,i+1):s=T._sampleContext=ne.getContext(new g(i)),s.save();var l=(new b).scale(r/t.width,a/t.height).translate(-t.x,-t.y);l.applyToContext(s),n&&n.draw(s,new o({clip:!0,matrices:[l]})),this._matrix.applyToContext(s);var c=this.getElement(),h=this._size;c&&s.drawImage(c,-h.width/2,-h.height/2),s.restore();for(var u=s.getImageData(.5,.5,Math.ceil(r),Math.ceil(a)).data,d=[0,0,0],f=0,m=0,p=u.length;m0?i[r-1]:t._closed?i[i.length-1]:null)||n._changed(),e&&e!==this._point&&e!==this._handleOut||!(n=i[r])||n._changed()),t._changed(25)}},getPoint:function(){return this._point},setPoint:function(){var e=m.read(arguments);this._point.set(e.x,e.y)},getHandleIn:function(){return this._handleIn},setHandleIn:function(){var e=m.read(arguments);this._handleIn.set(e.x,e.y)},getHandleOut:function(){return this._handleOut},setHandleOut:function(){var e=m.read(arguments);this._handleOut.set(e.x,e.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(e){var t=this._selectionState;return e?e===this._point?!!(4&t):e===this._handleIn?!!(1&t):e===this._handleOut&&!!(2&t):!!(7&t)},setSelected:function(e,t){var n=this._path,e=!!e,i=this._selectionState,r=i,a=t?t===this._point?4:t===this._handleIn?1:t===this._handleOut?2:0:7;e?i|=a:i&=~a,this._selectionState=i,n&&i!==r&&(n._updateSelection(this,r,i),n._changed(129))},getIndex:function(){return this._index!==s?this._index:null},getPath:function(){return this._path||null},getCurve:function(){var e=this._path,t=this._index;return e?(t>0&&!e._closed&&t===e._segments.length-1&&t--,e.getCurves()[t]||null):null},getLocation:function(){var e=this.getCurve();return e?new I(e,this===e._segment1?0:1):null},getNext:function(){var e=this._path&&this._path._segments;return e&&(e[this._index+1]||this._path._closed&&e[0])||null},getPrevious:function(){var e=this._path&&this._path._segments;return e&&(e[this._index-1]||this._path._closed&&e[e.length-1])||null},isFirst:function(){return 0===this._index},isLast:function(){var e=this._path;return e&&this._index===e._segments.length-1||!1},reverse:function(){var e=this._handleIn,t=this._handleOut,n=e._x,i=e._y;e.set(t._x,t._y),t.set(n,i)},reversed:function(){return new N(this._point,this._handleOut,this._handleIn)},remove:function(){return!!this._path&&!!this._path.removeSegment(this._index)},clone:function(){return new N(this._point,this._handleIn,this._handleOut)},equals:function(e){return e===this||e&&this._class===e._class&&this._point.equals(e._point)&&this._handleIn.equals(e._handleIn)&&this._handleOut.equals(e._handleOut)||!1},toString:function(){var e=["point: "+this._point];return this._handleIn.isZero()||e.push("handleIn: "+this._handleIn),this._handleOut.isZero()||e.push("handleOut: "+this._handleOut),"{ "+e.join(", ")+" }"},transform:function(e){this._transformCoordinates(e,new Array(6),!0),this._changed()},_transformCoordinates:function(e,t,n){var i=this._point,r=n&&this._handleIn.isZero()?null:this._handleIn,a=n&&this._handleOut.isZero()?null:this._handleOut,s=i._x,o=i._y,l=2;return t[0]=s,t[1]=o,r&&(t[l++]=r._x+s,t[l++]=r._y+o),a&&(t[l++]=a._x+s,t[l++]=a._y+o),e&&(e._transformCoordinates(t,t,l/2),s=t[0],o=t[1],n?(i._x=s,i._y=o,l=2,r&&(r._x=t[l++]-s,r._y=t[l++]-o),a&&(a._x=t[l++]-s,a._y=t[l++]-o)):(r||(t[l++]=s,t[l++]=o),a||(t[l++]=s,t[l++]=o))),t}}),L=m.extend({initialize:function(e,t,n){var i,r,a;if(e)if((i=e[0])!==s)r=e[1];else{var o=e;(i=o.x)===s&&(o=m.read(arguments),i=o.x),r=o.y,a=o.selected}else i=r=0;this._x=i,this._y=r,this._owner=t,t[n]=this,a&&this.setSelected(!0)},set:function(e,t){return this._x=e,this._y=t,this._owner._changed(this),this},_serialize:function(e){var t=e.formatter,n=t.number(this._x),i=t.number(this._y);return this.isSelected()?{x:n,y:i,selected:!0}:[n,i]},getX:function(){return this._x},setX:function(e){this._x=e,this._owner._changed(this)},getY:function(){return this._y},setY:function(e){this._y=e,this._owner._changed(this)},isZero:function(){return d.isZero(this._x)&&d.isZero(this._y)},setSelected:function(e){this._owner.setSelected(e,this)},isSelected:function(){return this._owner.isSelected(this)}}),M=o.extend({_class:"Curve",initialize:function(e,t,n,i,r,a,s,o){var l,c,h,u,d,f,m=arguments.length;3===m?(this._path=e,l=t,c=n):0===m?(l=new N,c=new N):1===m?"segment1"in e?(l=new N(e.segment1),c=new N(e.segment2)):"point1"in e?(h=e.point1,d=e.handle1,f=e.handle2,u=e.point2):Array.isArray(e)&&(h=[e[0],e[1]],u=[e[6],e[7]],d=[e[2]-e[0],e[3]-e[1]],f=[e[4]-e[6],e[5]-e[7]]):2===m?(l=new N(e),c=new N(t)):4===m?(h=e,d=t,f=n,u=i):8===m&&(h=[e,t],u=[s,o],d=[n-e,i-t],f=[r-s,a-o]),this._segment1=l||new N(h,null,d),this._segment2=c||new N(u,f,null)},_serialize:function(e){return o.serialize(this.hasHandles()?[this.getPoint1(),this.getHandle1(),this.getHandle2(),this.getPoint2()]:[this.getPoint1(),this.getPoint2()],e,!0)},_changed:function(){this._length=this._bounds=s},clone:function(){return new M(this._segment1,this._segment2)},toString:function(){var e=["point1: "+this._segment1._point];return this._segment1._handleOut.isZero()||e.push("handle1: "+this._segment1._handleOut),this._segment2._handleIn.isZero()||e.push("handle2: "+this._segment2._handleIn),e.push("point2: "+this._segment2._point),"{ "+e.join(", ")+" }"},remove:function(){var e=!1;if(this._path){var t=this._segment2,n=t._handleOut;e=t.remove(),e&&this._segment1._handleOut.set(n.x,n.y)}return e},getPoint1:function(){return this._segment1._point},setPoint1:function(){var e=m.read(arguments);this._segment1._point.set(e.x,e.y)},getPoint2:function(){return this._segment2._point},setPoint2:function(){var e=m.read(arguments);this._segment2._point.set(e.x,e.y)},getHandle1:function(){return this._segment1._handleOut},setHandle1:function(){var e=m.read(arguments);this._segment1._handleOut.set(e.x,e.y)},getHandle2:function(){return this._segment2._handleIn},setHandle2:function(){var e=m.read(arguments);this._segment2._handleIn.set(e.x,e.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 e=this._path&&this._path._curves;return e&&(e[this._segment1._index+1]||this._path._closed&&e[0])||null},getPrevious:function(){var e=this._path&&this._path._curves;return e&&(e[this._segment1._index-1]||this._path._closed&&e[e.length-1])||null},isFirst:function(){return 0===this._segment1._index},isLast:function(){var e=this._path;return e&&this._segment1._index===e._curves.length-1||!1},isSelected:function(){return this.getPoint1().isSelected()&&this.getHandle2().isSelected()&&this.getHandle2().isSelected()&&this.getPoint2().isSelected()},setSelected:function(e){this.getPoint1().setSelected(e),this.getHandle1().setSelected(e),this.getHandle2().setSelected(e),this.getPoint2().setSelected(e)},getValues:function(e){return M.getValues(this._segment1,this._segment2,e)},getPoints:function(){for(var e=this.getValues(),t=[],n=0;n<8;n+=2)t.push(new m(e[n],e[n+1]));return t},getLength:function(){return null==this._length&&(this._length=M.getLength(this.getValues(),0,1)),this._length},getArea:function(){return M.getArea(this.getValues())},getLine:function(){return new x(this._segment1._point,this._segment2._point)},getPart:function(e,t){return new M(M.getPart(this.getValues(),e,t))},getPartLength:function(e,t){return M.getLength(this.getValues(),e,t)},getIntersections:function(e){return M._getIntersections(this.getValues(),e&&e!==this?e.getValues():null,this,e,[],{})},_getParameter:function(e,t){return t?e:e&&e.curve===this?e.parameter:e===s&&t===s?.5:this.getParameterAt(e,0)},divide:function(e,t,n){var i=this._getParameter(e,t),r=4e-7,a=1-r,s=null;if(i>=r&&i<=a){var o=M.subdivide(this.getValues(),i),l=o[0],c=o[1],h=n||this.hasHandles(),u=this._segment1,d=this._segment2,f=this._path;h&&(u._handleOut.set(l[2]-l[0],l[3]-l[1]),d._handleIn.set(c[4]-c[6],c[5]-c[7]));var p=l[6],g=l[7],v=new N(new m(p,g),h&&new m(l[4]-p,l[5]-g),h&&new m(c[2]-p,c[3]-g));f?(f.insert(u._index+1,v),s=this.getNext()):(this._segment2=v,s=new M(v,d))}return s},split:function(e,t){return this._path?this._path.split(this._segment1._index,this._getParameter(e,t)):null},reversed:function(){return new M(this._segment2.reversed(),this._segment1.reversed())},clearHandles:function(){this._segment1._handleOut.set(0,0),this._segment2._handleIn.set(0,0)},statics:{getValues:function(e,t,n){var i=e._point,r=e._handleOut,a=t._handleIn,s=t._point,o=[i._x,i._y,i._x+r._x,i._y+r._y,s._x+a._x,s._y+a._y,s._x,s._y];return n&&n._transformCoordinates(o,o,4),o},subdivide:function(e,t){var n=e[0],i=e[1],r=e[2],a=e[3],o=e[4],l=e[5],c=e[6],h=e[7];t===s&&(t=.5);var u=1-t,d=u*n+t*r,f=u*i+t*a,m=u*r+t*o,p=u*a+t*l,g=u*o+t*c,v=u*l+t*h,w=u*d+t*m,y=u*f+t*p,b=u*m+t*g,x=u*p+t*v,_=u*w+t*b,E=u*y+t*x;return[[n,i,d,f,w,y,_,E],[_,E,b,x,g,v,c,h]]},solveCubic:function(e,t,n,i,r,a){var s=e[t],o=e[t+2],l=e[t+4],c=e[t+6],h=3*(o-s),u=3*(l-o)-h,f=c-s-h-u;return d.solveCubic(f,u,h,s-n,i,r,a)},getParameterOf:function(e,t){var n=new m(e[0],e[1]),i=new m(e[6],e[7]),r=1e-12,a=t.isClose(n,r)?0:t.isClose(i,r)?1:null;if(null!==a)return a;for(var s=[t.x,t.y],o=[],l=2e-7,c=0;c<2;c++)for(var h=M.solveCubic(e,c,s[c],o,0,1),u=0;u=0&&n<=1){var i=t.getDistance(M.getPoint(e,n),!0);if(i.999999999999?1:M.getParameterOf(e,new m(i+h*o,r+h*l))}for(var u=100,d=1/0,f=0,p=0;p<=u;p++)n(p/u);for(var g=1/(2*u);g>4e-7;)n(f-g)||n(f+g)||(g/=2);return f},getPart:function(e,t,n){var i=t>n;if(i){var r=t;t=n,n=r}return t>0&&(e=M.subdivide(e,t)[1]),n<1&&(e=M.subdivide(e,(n-t)/(1-t))[0]),i?[e[6],e[7],e[4],e[5],e[2],e[3],e[0],e[1]]:e},hasHandles:function(e){var t=d.isZero;return!(t(e[0]-e[2])&&t(e[1]-e[3])&&t(e[4]-e[6])&&t(e[5]-e[7]))},isFlatEnough:function(e,t){var n=e[0],i=e[1],r=e[2],a=e[3],s=e[4],o=e[5],l=e[6],c=e[7],h=3*r-2*n-l,u=3*a-2*i-c,d=3*s-2*l-n,f=3*o-2*c-i;return Math.max(h*h,d*d)+Math.max(u*u,f*f)<10*t*t},getArea:function(e){var t=e[0],n=e[1],i=e[6],r=e[7],a=(e[2]+t)/2,s=(e[3]+n)/2,o=(e[4]+e[6])/2,l=(e[5]+e[7])/2;return 6*((t-a)*(s+n)+(a-o)*(l+s)+(o-i)*(r+l))/10},getBounds:function(e){for(var t=e.slice(0,2),n=t.slice(),i=[0,0],r=0;r<2;r++)M._addBounds(e[r],e[r+2],e[r+4],e[r+6],r,0,t,n,i);return new w(t[0],t[1],n[0]-t[0],n[1]-t[1])},_addBounds:function(e,t,n,i,r,a,s,o,l){function c(e,t){var n=e-t,i=e+t;no[r]&&(o[r]=i)}var h=3*(t-n)-e+i,u=2*(e+n)-4*t,f=t-e,m=d.solveQuadratic(h,u,f,l),p=4e-7,g=1-p;c(i,0);for(var v=0;v=0&&r<=1&&a<=0&&a>=-1}return!1},isLinear:function(e,t,n){var i=e.divide(3);return t.equals(i)&&n.negate().equals(i)}},function(e,t){this[t]=function(){var t=this._segment1,n=this._segment2;return e(n._point.subtract(t._point),t._handleOut,n._handleIn)},this.statics[t]=function(t){var n=t[0],i=t[1],r=t[6],a=t[7];return e(new m(r-n,a-i),new m(t[2]-n,t[3]-i),new m(t[4]-r,t[5]-a))}},{statics:{},hasHandles:function(){return!this._segment1._handleOut.isZero()||!this._segment2._handleIn.isZero()},isCollinear:function(e){return e&&this.isStraight()&&e.isStraight()&&this.getLine().isCollinear(e.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(e,t){return M.getParameterAt(this.getValues(),e,t)},getParameterOf:function(){return M.getParameterOf(this.getValues(),m.read(arguments))},getLocationAt:function(e,t){var n=t?e:this.getParameterAt(e);return null!=n&&n>=0&&n<=1?new I(this,n):null},getLocationOf:function(){return this.getLocationAt(this.getParameterOf(m.read(arguments)),!0)},getOffsetOf:function(){var e=this.getLocationOf.apply(this,arguments);return e?e.getOffset():null},getNearestLocation:function(){var e=m.read(arguments),t=this.getValues(),n=M.getNearestParameter(t,e),i=M.getPoint(t,n);return new I(this,n,i,null,e.getDistance(i))},getNearestPoint:function(){return this.getNearestLocation.apply(this,arguments).getPoint()}},new function(){var e=["getPoint","getTangent","getNormal","getWeightedTangent","getWeightedNormal","getCurvature"];return o.each(e,function(e){this[e+"At"]=function(t,n){var i=this.getValues();return M[e](i,n?t:M.getParameterAt(i,t,0))}},{statics:{evaluateMethods:e}})},new function(){function e(e){var t=e[0],n=e[1],i=e[2],r=e[3],a=e[4],s=e[5],o=e[6],l=e[7],c=9*(i-a)+3*(o-t),h=6*(t+a)-12*i,u=3*(i-t),d=9*(r-s)+3*(l-n),f=6*(n+s)-12*r,m=3*(r-n);return function(e){var t=(c*e+h)*e+u,n=(d*e+f)*e+m;return Math.sqrt(t*t+n*n)}}function t(e,t){return Math.max(2,Math.min(16,Math.ceil(32*Math.abs(t-e))))}function n(e,t,n,i){if(null==t||t<0||t>1)return null;var r,a,s=e[0],o=e[1],l=e[2],c=e[3],h=e[4],u=e[5],d=e[6],f=e[7],p=4e-7,g=1-p;if(0===n&&(tg)){var v=tg?(r=3*(d-h),a=3*(f-u)):(r=(3*b*t+2*y)*t+w,a=(3*E*t+2*_)*t+x),i){0===r&&0===a&&(tg)&&(r=h-l,a=u-c);var C=Math.sqrt(r*r+a*a);C&&(r/=C,a/=C)}if(3===n){var k=6*b*t+2*y,S=6*E*t+2*_,z=Math.pow(r*r+a*a,1.5);r=0!==z?(r*S-a*k)/z:0,a=0}}}return 2===n?new m(a,-r):new m(r,a)}return{statics:{getLength:function(n,i,r){if(i===s&&(i=0),r===s&&(r=1),0===i&&1===r&&M.isStraight(n)){var a=n[6]-n[0],o=n[7]-n[1];return Math.sqrt(a*a+o*o)}var l=e(n);return d.integrate(l,i,r,t(i,r))},getParameterAt:function(n,i,r){function a(e){return p+=d.integrate(u,r,e,t(r,e)),r=e,p-i}if(r===s&&(r=i<0?1:0),0===i)return r;var o=Math.abs,l=i>0,c=l?r:0,h=l?1:r,u=e(n),f=d.integrate(u,c,h,t(c,h));if(o(i-f)<1e-12)return l?h:c;if(o(i)>f)return null;var m=i/f,p=0;return d.findRoot(a,u,r+m,c,h,32,1e-12)},getPoint:function(e,t){return n(e,t,0,!1)},getTangent:function(e,t){return n(e,t,1,!0)},getWeightedTangent:function(e,t){return n(e,t,1,!1)},getNormal:function(e,t){return n(e,t,2,!0)},getWeightedNormal:function(e,t){return n(e,t,2,!1)},getCurvature:function(e,t){return n(e,t,3,!1).x}}}},new function(){function e(e,t,n,i,r,a,s,o,l,c,h){var u=t.startConnected,d=t.endConnected,f=4e-7,m=1-f;if(null==r&&(r=M.getParameterOf(n,a)),null!==r&&r>=(u?f:0)&&r<=(d?m:1)&&(null==l&&(l=M.getParameterOf(s,c)),null!==l&&l>=(d?f:0)&&l<=(u?m:1))){var p=t.renormalize;if(p){var g=p(r,l);r=g[0],l=g[1]}var v=new I(i,r,a||M.getPoint(n,r),h),w=new I(o,l,c||M.getPoint(s,l),h),y=v.getPath()===w.getPath()&&v.getIndex()>w.getIndex(),b=y?w:v,x=t.include;v._intersection=w,w._intersection=v,x&&!x(b)||I.insert(e,b,!0)}}function t(r,a,s,o,l,c,h,u,d,f,m,p,g){if(!(++g>=24)){var v,w,y=a[0],b=a[1],_=a[6],E=a[7],C=x.getSignedDistance,k=C(y,b,_,E,a[2],a[3]),S=C(y,b,_,E,a[4],a[5]),z=k*S>0?.75:4/9,T=z*Math.min(0,k,S),P=z*Math.max(0,k,S),B=C(y,b,_,E,r[0],r[1]),N=C(y,b,_,E,r[2],r[3]),L=C(y,b,_,E,r[4],r[5]),I=C(y,b,_,E,r[6],r[7]),A=n(B,N,L,I),O=A[0],D=A[1];if(null!=(v=i(O,D,T,P))&&null!=(w=i(O.reverse(),D.reverse(),T,P))){r=M.getPart(r,v,w);var j=w-v,q=h+(u-h)*v,F=h+(u-h)*w;if(m>.5&&j>.5)if(F-q>f-d){var G=M.subdivide(r,.5),V=q+(F-q)/2;t(a,G[0],o,s,l,c,d,f,q,V,j,!p,g),t(a,G[1],o,s,l,c,d,f,V,F,j,!p,g)}else{var G=M.subdivide(a,.5),V=d+(f-d)/2;t(G[0],r,o,s,l,c,d,V,q,F,j,!p,g),t(G[1],r,o,s,l,c,V,f,q,F,j,!p,g)}else if(Math.max(f-d,F-q)<1e-7){var R=q+(F-q)/2,W=d+(f-d)/2;r=s.getValues(),a=o.getValues(),e(l,c,p?a:r,p?o:s,p?W:R,null,p?r:a,p?s:o,p?R:W,null)}else j>1e-12&&t(a,r,o,s,l,c,d,f,q,F,j,!p,g)}}}function n(e,t,n,i){var r,a=[0,e],s=[1/3,t],o=[2/3,n],l=[1,i],c=t-(2*e+i)/3,h=n-(e+2*i)/3;if(c*h<0)r=[[a,s,l],[a,o,l]];else{var u=c/h;r=[u>=2?[a,s,l]:u<=.5?[a,o,l]:[a,s,o,l],[a,l]]}return(c||h)<0?r.reverse():r}function i(e,t,n,i){return e[0][1]i?r(t,!1,i):e[0][0]}function r(e,t,n){for(var i=e[0][0],r=e[0][1],a=1,s=e.length;a=n:l<=n)return l===n?o:i+(n-r)*(o-i)/(l-r);i=o,r=l}return null}function a(t,n,i,r,a,s){for(var o=M.isStraight(t),l=o?n:t,c=o?t:n,h=c[0],u=c[1],f=c[6],m=c[7],p=f-h,g=m-u,v=Math.atan2(-g,p),w=Math.sin(v),y=Math.cos(v),b=[],x=0;x<8;x+=2){var _=l[x]-h,E=l[x+1]-u;b.push(_*y-E*w,_*w+E*y)}for(var C=[],k=M.solveCubic(b,1,0,C,0,1),x=0;xd.CURVETIME_EPSILON)&&e(a,s,t,i,B,o?P:z,n,r,N,o?z:P)}}}function s(t,n,i,r,a,s){var o=x.intersect(t[0],t[1],t[6],t[7],n[0],n[1],n[6],n[7]);o&&e(a,s,t,i,null,o,n,r,null,o)}return{statics:{_getIntersections:function(n,i,r,o,l,c){if(!i)return M._getSelfIntersection(n,r,l,c);var h=n[0],u=n[1],d=n[6],f=n[7],p=i[0],g=i[1],v=i[6],w=i[7],y=(3*n[2]+h)/4,b=(3*n[3]+u)/4,x=(3*n[4]+d)/4,_=(3*n[5]+f)/4,E=(3*i[2]+p)/4,C=(3*i[3]+g)/4,k=(3*i[4]+v)/4,S=(3*i[5]+w)/4,z=Math.min,T=Math.max;if(!(T(h,y,x,d)>=z(p,E,k,v)&&z(h,y,x,d)<=T(p,E,k,v)&&T(u,b,_,f)>=z(g,C,S,w)&&z(u,b,_,f)<=T(g,C,S,w)))return l;if(!c.startConnected&&!c.endConnected){var P=M.getOverlaps(n,i);if(P){for(var B=0;B<2;B++){var N=P[B];e(l,c,n,r,N[0],null,i,o,N[1],null,!0)}return l}}var L=M.isStraight(n),I=M.isStraight(i),A=L&&I,O=1e-12,D=l.length;if((A?s:L||I?a:t)(n,i,r,o,l,c,0,1,0,1,0,!1,0),A&&l.length>D)return l;var j=new m(h,u),q=new m(d,f),F=new m(p,g),G=new m(v,w);return j.isClose(F,O)&&e(l,c,n,r,0,j,i,o,0,F),!c.startConnected&&j.isClose(G,O)&&e(l,c,n,r,0,j,i,o,1,G),!c.endConnected&&q.isClose(F,O)&&e(l,c,n,r,1,q,i,o,0,F),q.isClose(G,O)&&e(l,c,n,r,1,q,i,o,1,G),l},_getSelfIntersection:function(e,t,n,i){var r=e[0],a=e[1],s=e[2],o=e[3],l=e[4],c=e[5],h=e[6],u=e[7],f=new x(r,a,h,u,!1),p=f.getSide(new m(s,o),!0),g=f.getSide(new m(l,c),!0);if(p===g){var v=(r-l)*(o-u)+(s-h)*(c-a);if(v*p>0)return n}var w=h-3*l+3*s-r,y=l-2*s+r,b=s-r,_=u-3*c+3*o-a,E=c-2*o+a,C=o-a,k=_*b-w*C,S=_*y-w*E,z=E*b-y*C;if(k*k-4*S*z<0){var T,P=[],B=d.solveCubic(w*w+_*_,3*(w*y+_*E),2*(y*y+E*E)+w*b+_*C,y*b+E*C,P,0,1);if(B>0){for(var N=0,L=0;NL&&(L=I,T=P[N])}var A=M.subdivide(e,T);i.endConnected=!0,i.renormalize=function(e,t){return[e*T,t*(1-T)+T]},M._getIntersections(A[0],A[1],t,t,n,i)}}return n},getOverlaps:function(e,t){function n(e){var t=e[6]-e[0],n=e[7]-e[1];return t*t+n*n}var i=Math.abs,r=4e-7,a=2e-7,s=M.isStraight(e),o=M.isStraight(t),l=s&&o;if(l){var c=n(e)a||d.getDistance(new m(u[6],u[7]))>a)return null}else if(s^o)return null;for(var f=[e,t],p=[],g=0,v=0;g<2&&p.length<2;g+=0===v?0:1,v^=1){var w=M.getParameterOf(f[1^g],new m(f[g][0===v?0:6],f[g][0===v?1:7]));if(null!=w){var y=0===g?[v,w]:[w,v];(0===p.length||i(y[0]-p[0][0])>r&&i(y[1]-p[0][1])>r)&&p.push(y)}if(1===g&&0===p.length)break}if(2!==p.length)p=null;else if(!l){var b=M.getPart(e,p[0][0],p[1][0]),_=M.getPart(t,p[0][1],p[1][1]);(i(_[2]-b[2])>a||i(_[3]-b[3])>a||i(_[4]-b[4])>a||i(_[5]-b[5])>a)&&(p=null)}return p; -}}}}),I=o.extend({_class:"CurveLocation",beans:!0,initialize:function e(t,n,i,r,a){if(n>.9999996){var s=t.getNext();s&&(n=0,t=s)}this._id=f.get(e),this._setCurve(t),this._parameter=n,this._point=i||t.getPointAt(n,!0),this._overlap=r,this._distance=a,this._intersection=this._next=this._prev=null},_setCurve:function(e){var t=e._path;this._version=t?t._version:0,this._curve=e,this._segment=null,this._segment1=e._segment1,this._segment2=e._segment2},_setSegment:function(e){this._setCurve(e.getCurve()),this._segment=e,this._parameter=e===this._segment1?0:1,this._point=e._point.clone()},getSegment:function(){var e=this.getCurve(),t=this._segment;if(!t){var n=this.getParameter();0===n?t=e._segment1:1===n?t=e._segment2:null!=n&&(t=e.getPartLength(0,n)t&&et&&e<=h||e>=-h&&e=r&&n<=a||i>=r&&i<=a)return!this.isTouching();var s=this.getCurve(),o=s.getPrevious(),l=t.getCurve(),c=l.getPrevious(),h=Math.PI;if(!o||!c)return!1;var u=o.getTangentAt(a,!0).negate().getAngleInRadians(),d=s.getTangentAt(r,!0).getAngleInRadians(),f=c.getTangentAt(a,!0).negate().getAngleInRadians(),m=l.getTangentAt(r,!0).getAngleInRadians();return e(f,u,d)^e(m,u,d)&&e(f,d,u)^e(m,d,u)},isOverlap:function(){return!!this._overlap}},o.each(M.evaluateMethods,function(e){var t=e+"At";this[e]=function(){var e=this.getParameter(),n=this.getCurve();return null!=e&&n&&n[t](e,!0)}},{preserve:!0}),new function(){function e(e,t,n){function i(n,i){for(var a=n+i;a>=-1&&a<=r;a+=i){var s=e[(a%r+r)%r];if(!t.getPoint().isClose(s.getPoint(),2e-7))break;if(t.equals(s))return s}return null}for(var r=e.length,a=0,s=r-1;a<=s;){var o,l=a+s>>>1,c=e[l];if(n&&(o=t.equals(c)?c:i(l,-1)||i(l,1)))return t._overlap&&(o._overlap=o._intersection._overlap=!0),o;var h=t.getPath(),u=c.getPath(),d=h===u?t.getIndex()+t.getParameter()-(c.getIndex()+c.getParameter()):h._id-u._id;d<0?s=l-1:a=l+1}return e.splice(a,0,t),t}return{statics:{insert:e,expand:function(t){for(var n=t.slice(),i=0,r=t.length;i0?this.setSegments(t):(this._curves=s,this._selectedSegmentState=0,t||"string"!=typeof e||(this.setPathData(e),e=null)),this._initialize(!t&&e)},_equals:function(e){return this._closed===e._closed&&o.equals(this._segments,e._segments)},clone:function(e){var t=new O(C.NO_INSERT);return t.setSegments(this._segments),t._closed=this._closed,this._clockwise!==s&&(t._clockwise=this._clockwise),this._clone(t,e)},_changed:function e(t){if(e.base.call(this,t),8&t){var n=this._parent;if(n&&(n._currentPath=s),this._length=this._area=this._clockwise=this._monoCurves=s,16&t)this._version++;else if(this._curves)for(var i=0,r=this._curves.length;i0&&this._add(N.readAll(e)),t&&this.setFullySelected(!0)},getFirstSegment:function(){return this._segments[0]},getLastSegment:function(){return this._segments[this._segments.length-1]},getCurves:function(){var e=this._curves,t=this._segments;if(!e){var n=this._countCurves();e=this._curves=new Array(n);for(var i=0;i0&&(n(d[0],!0),v.push("z")),v.join("")}},{isEmpty:function(){return 0===this._segments.length},_transformContent:function(e){for(var t=new Array(6),n=0,i=this._segments.length;n0?e-1:e},add:function(e){return arguments.length>1&&"number"!=typeof e?this._add(N.readAll(arguments)):this._add([N.read(arguments)])[0]},insert:function(e,t){return arguments.length>2&&"number"!=typeof t?this._add(N.readAll(arguments,1),e):this._add([N.read(arguments,1)],e)[0]},addSegment:function(){return this._add([N.read(arguments)])[0]},insertSegment:function(e){return this._add([N.read(arguments,1)],e)[0]},addSegments:function(e){return this._add(N.readAll(e))},insertSegments:function(e,t){return this._add(N.readAll(t),e)},removeSegment:function(e){return this.removeSegments(e,e+1)[0]||null},removeSegments:function(e,t,n){e=e||0,t=o.pick(t,this._segments.length);var i=this._segments,r=this._curves,a=i.length,s=i.splice(e,t-e),l=s.length;if(!l)return s;for(var c=0;c0&&t===a+(this._closed?1:0)?e-1:e,r=r.splice(d,l);n&&(s._curves=r.slice(1)),this._adjustCurves(d,d)}return this._changed(25),s},clear:"#removeSegments",hasHandles:function(){for(var e=this._segments,t=0,n=e.length;t=0},setClockwise:function(e){this.isClockwise()!=(e=!!e)&&this.reverse(),this._clockwise=e},isFullySelected:function(){var e=this._segments.length;return this._selected&&e>0&&this._selectedSegmentState===7*e},setFullySelected:function(e){e&&this._selectSegments(!0),this.setSelected(e)},setSelected:function e(t){t||this._selectSegments(!1),e.base.call(this,t)},_selectSegments:function(e){var t=this._segments.length;this._selectedSegmentState=e?7*t:0;for(var n=0;n0&&this.setSelected(!0)},flatten:function(e){for(var t=new j(this,64,.1),n=0,i=t.length/Math.ceil(t.length/e),r=t.length+(this._closed?-i:i)/2,a=[];n<=r;)a.push(new N(t.getPointAt(n))),n+=i;this.setSegments(a)},reduce:function(){for(var e=this.getCurves(),t=e.length-1;t>=0;t--){var n=e[t];n.hasHandles()||0!==n.getLength()&&!n.isCollinear(n.getNext())||n.remove()}return this},simplify:function(e){if(this._segments.length>2){var t=new q(this,e||2.5);this.setSegments(t.fit())}},split:function(e,t){if(null===t)return null;if(1===arguments.length){var n=e;if("number"==typeof n&&(n=this.getLocationAt(n)),!n)return null;e=n.index,t=n.parameter}var i=4e-7,r=1-i;t>=r&&(e++,t--);var a=this.getCurves();if(e>=0&&e=i&&a[e++].divide(t,!0);var s,o=this.removeSegments(e,this._segments.length,!0);return this._closed?(this.setClosed(!1),s=this):(s=new O(C.NO_INSERT),s.insertAbove(this,!0),this._clone(s)),s._add(o,0),this.addSegment(o[0]),s}return null},reverse:function(){this._segments.reverse();for(var e=0,t=this._segments.length;e0&&t._index0||E?0:null;if(null!==C&&(C>0?(o=p.getStrokeJoin(),l=p.getStrokeCap(),c=C*p.getMiterLimit(),b=y.add(new m(C,C))):o=l="round"),!t.ends||t.segments||w){if(t.segments||t.handles)for(var k=0;k1?s(u.getSegment())||(u=null):n(u.getPoint(),b)||(u=null)}if(!u&&"miter"===o&&v>1)for(var k=0;ke)return a.getLocationAt(e-l)}return n.length>0&&e<=this.getLength()?new I(n[n.length-1],1):null},getNearestLocation:function(){for(var e=m.read(arguments),t=this.getCurves(),n=1/0,i=null,r=0,a=t.length;r0&&i(d[0])}return{_draw:function(e,n,i){function r(e){return u[(e%d+d)%d]}var s=n.dontStart,o=n.dontFinish||n.clip,l=this.getStyle(),c=l.hasFill(),h=l.hasStroke(),u=l.getDashArray(),d=!a.support.nativeDash&&h&&u&&u.length;if(s||e.beginPath(),!s&&this._currentPath?e.currentPath=this._currentPath:(c||h&&!d||o)&&(t(e,this,i),this._closed&&e.closePath(),s||(this._currentPath=e.currentPath)),!o&&(c||h)&&(this._setStyles(e),c&&(e.fill(l.getWindingRule()),e.shadowColor="rgba(0,0,0,0)"),h)){if(d){s||e.beginPath();var f,m=new j(this,32,.25,i),p=m.length,g=-l.getDashOffset(),v=0;for(g%=p;g>0;)g-=r(v--)+r(v--);for(;g0||f>0)&&m.drawPart(e,Math.max(g,0),Math.max(f,0)),g=f+r(v++)}e.stroke()}},_drawSelected:function(n,i){n.beginPath(),t(n,this,i),n.stroke(),e(n,this._segments,i,a.settings.handleSize)}}},new function(){function e(e){var t=e.length,n=[],i=[],r=2;n[0]=e[0]/r;for(var a=1;a1&&(C*=B,k*=B,S=C*C,z=k*k),B=(S*z-S*P-z*T)/(S*P+z*T),E(B)<1e-12&&(B=0),B<0)throw new Error("Cannot create an arc with the given arguments");n=new m(C*_/k,-k*y/C).multiply((v===u?-1:1)*Math.sqrt(B)).rotate(p).add(d),a=(new b).translate(n).rotate(p).scale(C,k),r=a._inverseTransform(l),i=r.getDirectedAngle(a._inverseTransform(c)),!u&&i>0?i-=360:u&&i<0&&(i+=360)}if(t){var L=new x(l.add(t).divide(2),t.subtract(l).rotate(90),!0),M=new x(t.add(c).divide(2),c.subtract(t).rotate(90),!0),I=new x(l,c),A=I.getSide(t);if(n=L.intersect(M,!0),!n){if(!A)return this.lineTo(c);throw new Error("Cannot create an arc with the given arguments")}r=l.subtract(n),i=r.getDirectedAngle(c.subtract(n));var O=I.getSide(n);0===O?i=A*Math.abs(i):A===O&&(i+=i<0?360:-360)}for(var D=Math.abs(i),j=D>=360?4:Math.ceil(D/90),q=i/j,F=q*Math.PI/360,G=4/3*Math.sin(F)/(1+Math.cos(F)),V=[],R=0;R<=j;R++){var w=c,W=null;if(R0&&(o(e[0],f),o(e[e.length-1],f)),u},_getPenPadding:function(e,t){if(!t)return[e,e];var n=t.shiftless(),i=n.transform(new m(e,0)),r=n.transform(new m(0,e)),a=i.getAngleInRadians(),s=i.getLength(),o=r.getLength(),l=Math.sin(a),c=Math.cos(a),h=Math.tan(a),u=-Math.atan(o*h/s),d=Math.atan(o/(h*s));return[Math.abs(s*Math.cos(u)*c-o*Math.sin(u)*l),Math.abs(o*Math.sin(d)*c+s*Math.cos(d)*l)]},_addBevelJoin:function(e,t,n,i,r,a){var s=e.getCurve(),o=s.getPrevious(),l=s.getPointAt(0,!0),c=o.getNormalAt(1,!0),h=s.getNormalAt(0,!0),u=c.getDirectedAngle(h)<0?-n:n;if(c.setLength(u),h.setLength(u),a&&(r(l),r(l.add(c))),"miter"===t){var d=new x(l.add(c),new m(-c.y,c.x),!0).intersect(new x(l.add(h),new m(-h.y,h.x),!0),!0);if(d&&l.getDistance(d)<=i&&(r(d),!a))return}a||r(l.add(c)),r(l.add(h))},_addSquareCap:function(e,t,n,i,r){var a=e._point,s=e.getLocation(),o=s.getNormal().multiply(n);r&&(i(a.subtract(o)),i(a.add(o))),"square"===t&&(a=a.add(o.rotate(0===s.getParameter()?-90:90))),i(a.add(o)),i(a.subtract(o))},getHandleBounds:function(e,t,n,i,r,a){for(var s=new Array(6),o=1/0,l=-o,c=o,h=l,u=0,d=e.length;ul&&(l=_),Eh&&(h=C)}}return new w(o,c,l-o,h-c)},getRoughBounds:function(e,t,n,i){var r=n.hasStroke()?n.getStrokeWidth()/2:0,a=r;return r>0&&("miter"===n.getStrokeJoin()&&(a=r*n.getMiterLimit()),"square"===n.getStrokeCap()&&(a=Math.max(a,r*Math.sqrt(2)))),O.getHandleBounds(e,t,n,i,O._getPenPadding(r,i),O._getPenPadding(a,i))}}});O.inject({statics:new function(){function e(e,t,n){var i=o.getNamed(n),r=new O(i&&i.insert===!1&&C.NO_INSERT);return r._add(e),r._closed=t,r.set(i)}function t(t,n,r){for(var a=new Array(4),s=0;s<4;s++){var o=i[s];a[s]=new N(o._point.multiply(n).add(t),o._handleIn.multiply(n),o._handleOut.multiply(n))}return e(a,!0,r)}var n=.5522847498307936,i=[new N([-1,0],[0,n],[0,-n]),new N([0,-1],[-n,0],[n,0]),new N([1,0],[0,-n],[0,n]),new N([0,1],[n,0],[-n,0])];return{Line:function(){return e([new N(m.readNamed(arguments,"from")),new N(m.readNamed(arguments,"to"))],!1,arguments)},Circle:function(){var e=m.readNamed(arguments,"center"),n=o.readNamed(arguments,"radius");return t(e,new g(n),arguments)},Rectangle:function(){var t,i=w.readNamed(arguments,"rectangle"),r=g.readNamed(arguments,"radius",0,{readNull:!0}),a=i.getBottomLeft(!0),s=i.getTopLeft(!0),o=i.getTopRight(!0),l=i.getBottomRight(!0);if(!r||r.isZero())t=[new N(a),new N(s),new N(o),new N(l)];else{r=g.min(r,i.getSize(!0).divide(2));var c=r.width,h=r.height,u=c*n,d=h*n;t=[new N(a.add(c,0),null,[-u,0]),new N(a.subtract(0,h),[0,d]),new N(s.add(0,h),null,[0,-d]),new N(s.add(c,0),[-u,0],null),new N(o.subtract(c,0),null,[u,0]),new N(o.add(0,h),[0,-d],null),new N(l.subtract(0,h),null,[0,d]),new N(l.subtract(c,0),[u,0])]}return e(t,!0,arguments)},RoundRectangle:"#Rectangle",Ellipse:function(){var e=z._readEllipse(arguments);return t(e.center,e.radius,arguments)},Oval:"#Ellipse",Arc:function(){var e=m.readNamed(arguments,"from"),t=m.readNamed(arguments,"through"),n=m.readNamed(arguments,"to"),i=o.getNamed(arguments),r=new O(i&&i.insert===!1&&C.NO_INSERT);return r.moveTo(e),r.arcTo(t,n),r.set(i)},RegularPolygon:function(){for(var t=m.readNamed(arguments,"center"),n=o.readNamed(arguments,"sides"),i=o.readNamed(arguments,"radius"),r=360/n,a=!(n%3),s=new m(0,a?-i:i),l=a?-1:.5,c=new Array(n),h=0;h=0;r--){var a=n[r];a instanceof D&&(n.splice.apply(n,[r,1].concat(a.removeChildren())),a.remove())}n=e.base.call(this,t,n,i,O);for(var r=0,o=!i&&n&&n.length;r=0;n--){var i=t[n].reduce();i.isEmpty()&&t.splice(n,1)}if(0===t.length){var i=new O(C.NO_INSERT);return i.insertAbove(this),i.setStyle(this._style),this.remove(),i}return e.base.call(this)},isClockwise:function(){var e=this.getFirstChild();return e&&e.isClockwise()},setClockwise:function(e){this.isClockwise()!==!!e&&this.reverse()},getFirstSegment:function(){var e=this.getFirstChild();return e&&e.getFirstSegment()},getLastSegment:function(){var e=this.getLastChild();return e&&e.getLastSegment()},getCurves:function(){for(var e=this._children,t=[],n=0,i=e.length;n=0;u--){var d=l[u].split();d&&(a(d)&&d.getFirstSegment().setHandleIn(0,0),s.getLastSegment().setHandleOut(0,0))}return a(s),t(k,h,n,i)}function r(e,t){for(var n=e;n;){if(n===t)return;n=n._prev}for(;e._next&&e._next!==t;)e=e._next;if(!e._next){for(;t._prev;)t=t._prev;e._next=t,t._prev=e}}function a(e){for(var t,n,i=4e-7,a=1-i,s=!1,o=[],l=e.length-1;l>=0;l--){var c=e[l],h=c._curve,u=c._parameter,d=u;h!==t?s=!h.hasHandles():n>0&&(u/=n);var f;ua?f=h._segment2:(f=h.divide(u,!0,!0)._segment1,s&&o.push(f)),c._setSegment(f);var m=f._intersection,p=c._intersection;if(m){r(m,p);for(var g=m;g;)r(g._intersection,m),g=g._next}else f._intersection=p;t=h,n=d}for(var l=0,v=o.length;l0)for(var E=f.length-1;E>=0;E--){var C=M.getPoint(_,f[E]).y;Cg?g=C:C>y&&C-(1/0)&&(h=s(new m(l,g),t,!1,i)),v<1/0&&(u=s(new m(l,v),t,!1,i))}else for(var k,S,z=l-r,T=l+r,P=!1,b=0,x=t.length;b=_[1]&&c<=_[7]||c>=_[7]&&c<=_[1])&&1===M.solveCubic(_,1,c,f,0,1)){var L=f[0];if(!(L>o&&P&&B.next!==t[b+1]||Lo&&B.previous===k)){var I=M.getPoint(_,L).x,A=M.getTangent(_,L).y,O=!1;d.isZero(A)&&!M.isStraight(_)||Lo&&A*M.getTangent(B.next.values,0).y<0?i&&I>=z&&I<=T&&(++h,++u,O=!0):I<=z?(h+=N,O=!0):I>=T&&(u+=N,O=!0),B.previous!==t[b-1]&&(P=L=0;E--)o[E].segment._winding=_}function l(e,t){function n(e,t){if(e._visited)return!1;if(!h)return!0;var n=e._winding,i=e._intersection;return i&&t&&u&&i.isOverlap()&&(n=u[n]||n),h(n)}function i(e){return e===s||e===o}function r(e,t){if(!e._next)return e;for(;e;){var r=e._segment,a=r.getNext(),s=a._intersection;if(i(a)||!r._visited&&!a._visited&&(!h||(!t||n(r))&&(!(t&&s&&s.isOverlap())&&n(a)||!t&&s&&n(s._segment))))return e;e=e._next}return null}function a(e,t){for(;e;){var n=e._segment;if(i(n))return n;e=e[t?"_next":"_prev"]}}for(var s,o,l=[],h=c[t],u={unite:{1:2},intersect:{2:1}}[t],f=0,m=e.length;fr?-1:1,previous:n,next:null};n&&(n.next=a),i.push(a),n=a}function t(t){if(0!==M.getLength(t)){var n=t[1],i=t[3],r=t[5],a=t[7];if(M.isStraight(t))e(t);else{var s=3*(i-r)-n+a,o=2*(n+r)-4*i,l=i-n,c=4e-7,h=1-c,u=[],f=d.solveQuadratic(s,o,l,u,c,h);if(0===f)e(t);else{u.sort();var m=u[0],p=M.subdivide(t,m);e(p[0]),f>1&&(m=(u[1]-m)/(1-m),p=M.subdivide(p[1],m),e(p[0])),e(p[1])}}}}var n,i=this._monoCurves;if(!i){i=this._monoCurves=[];for(var r=this.getCurves(),a=this._segments,s=0,o=r.length;s1){var l=a[a.length-1]._point,c=a[0]._point,h=l._x,u=l._y,f=c._x,m=c._y;t([h,u,h,u,f,m,f,m])}if(i.length>0){var p=i[0],g=i[i.length-1];p.previous=g,g.next=p}}return i},getInteriorPoint:function(){var e=this.getBounds(),t=e.getCenter(!0);if(!this.contains(t)){for(var n=this._getMonoCurves(),i=[],r=t.y,a=[],s=0,o=n.length;s=l[1]&&r<=l[7]||r>=l[7]&&r<=l[1])&&M.solveCubic(l,1,r,i,0,1)>0)for(var c=i.length-1;c>=0;c--)a.push(M.getPoint(l,i[c]).x);if(a.length>1)break}t.x=(a[0]+a[1])/2}return t},reorient:function(){return this.setClockwise(!0),this}}),D.inject({_getMonoCurves:function(){for(var e=this._children,t=[],n=0,i=e.length;n0){this.addChildren(e);for(var t=e[0].isClockwise(),n=1,i=e.length;n=0;s--)e[s].contains(r)&&a++;e[n].setClockwise(a%2===0&&t)}}return this}});var j=o.extend({_class:"PathIterator",initialize:function(e,t,n,i){function r(e,t){var n=M.getValues(e,t,i);o.push(n),a(n,e._index,0,1)}function a(e,t,i,r){if(r-i>h&&!M.isFlatEnough(e,n||.25)){var s=M.subdivide(e,.5),o=(i+r)/2;a(s[0],t,i,o),a(s[1],t,o,r)}else{var u=e[6]-e[0],d=e[7]-e[1],f=Math.sqrt(u*u+d*d);f>1e-6&&(c+=f,l.push({offset:c,value:r,index:t}))}}for(var s,o=[],l=[],c=0,h=1/(t||32),u=e._segments,d=u[0],f=1,m=u.length;f=e){this.index=t;var a=this.parts[t-1],s=a&&a.index==r.index?a.value:0,o=a?a.offset:0;return{value:s+(r.value-s)*(e-o)/(r.offset-o),index:r.index}}}var r=this.parts[this.parts.length-1];return{value:1,index:r.index}},drawPart:function(e,t,n){t=this.getParameterAt(t),n=this.getParameterAt(n);for(var i=t.index;i<=n.index;i++){var r=M.getPart(this.curves[i],i==t.index?t.value:0,i==n.index?n.value:1);i==t.index&&e.moveTo(r[0],r[1]),e.bezierCurveTo.apply(e,r.slice(2))}}},o.each(M.evaluateMethods,function(e){this[e+"At"]=function(t,n){var i=this.getParameterAt(t);return M[e](this.curves[i.index],i.value,n)}},{})),q=o.extend({initialize:function(e,t){for(var n,i=this.points=[],r=e._segments,a=0,s=r.length;a0?[new N(e[0])]:[];return t>1&&this.fitCubic(0,t-1,e[1].subtract(e[0]).normalize(),e[t-2].subtract(e[t-1]).normalize()),this.closed&&(n.shift(),n.pop()),n},fitCubic:function(e,t,n,i){if(t-e==1){var r=this.points[e],a=this.points[t],s=r.getDistance(a)/3;return void this.addCurve([r,r.add(n.normalize(s)),a.add(i.normalize(s)),a])}for(var o,l=this.chordLengthParameterize(e,t),c=Math.max(this.error,this.error*this.error),h=!0,u=0;u<=4;u++){var d=this.generateBezier(e,t,l,n,i),f=this.findMaxError(e,t,d,l);if(f.error=c)break;h=this.reparameterize(e,t,l,d),c=f.error}var m=this.points[o-1].subtract(this.points[o]),p=this.points[o].subtract(this.points[o+1]),g=m.add(p).divide(2).normalize();this.fitCubic(e,o,n,g),this.fitCubic(o,t,g.negate(),i)},addCurve:function(e){var t=this.segments[this.segments.length-1];t.setHandleOut(e[1].subtract(e[0])),this.segments.push(new N(e[3],e[2].subtract(e[3])))},generateBezier:function(e,t,n,i,r){for(var a=1e-12,s=this.points[e],o=this.points[t],l=[[0,0],[0,0]],c=[0,0],h=0,u=t-e+1;ha){var k=l[0][0]*c[1]-l[1][0]*c[0],S=c[0]*l[1][1]-c[1]*l[0][1];_=S/C,E=k/C}else{var z=l[0][0]+l[0][1],T=l[1][0]+l[1][1];_=E=Math.abs(z)>a?c[0]/z:Math.abs(T)>a?c[1]/T:0}var P,B,N=o.getDistance(s),L=a*N;if(_N*N&&(_=E=N/3,P=B=null)}return[s,s.add(P||i.normalize(_)),o.add(B||r.normalize(E)),o]},reparameterize:function(e,t,n,i){for(var r=e;r<=t;r++)n[r-e]=this.findRoot(i,this.points[r],n[r-e]);for(var r=1,a=n.length;r=a&&(a=c,r=s)}return{error:a,index:r}}}),F=C.extend({_class:"TextItem",_boundsSelected:!0,_applyMatrix:!1,_canApplyMatrix:!1,_serializeFields:{content:null},_boundsGetter:"getBounds",initialize:function(e){this._content="",this._lines=[];var t=e&&o.isPlainObject(e)&&e.x===s&&e.y===s;this._initialize(t&&e,!t&&m.read(arguments))},_equals:function(e){return this._content===e._content},_clone:function e(t,n,i){return t.setContent(this._content),e.base.call(this,t,n,i)},getContent:function(){return this._content},setContent:function(e){this._content=""+e,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"}),G=F.extend({_class:"PointText",initialize:function(){F.apply(this,arguments)},clone:function(e){return this._clone(new G(C.NO_INSERT),e)},getPoint:function(){var e=this._matrix.getTranslation();return new p(e.x,e.y,this,"setPoint")},setPoint:function(){var e=m.read(arguments);this.translate(e.subtract(this._matrix.getTranslation()))},_draw:function(e){if(this._content){this._setStyles(e);var t=this._style,n=this._lines,i=t.getLeading(),r=e.shadowColor;e.font=t.getFontStyle(),e.textAlign=t.getJustification();for(var a=0,s=n.length;a1&&(l-=1),s[o]=6*l<1?a+6*(r-a)*l:2*l<1?r:3*l<2?a+(r-a)*(2/3-l)*6:a}return s},"rgb-gray":function(e,t,n){return[.2989*e+.587*t+.114*n]},"gray-rgb":function(e){return[e,e,e]},"gray-hsb":function(e){return[0,0,e]},"gray-hsl":function(e){return[0,0,e]},"gradient-rgb":function(){return[]},"rgb-gradient":function(){return[]}};return o.each(n,function(e,t){i[t]=[],o.each(e,function(e,r){var a=o.capitalize(e),s=/^(hue|saturation)$/.test(e),l=i[t][r]="gradient"===e?function(e){var t=this._components[0];return e=R.read(Array.isArray(e)?e:arguments,0,{readNull:!0}),t!==e&&(t&&t._removeOwner(this),e&&e._addOwner(this)),e}:"gradient"===t?function(){return m.read(arguments,0,{readNull:"highlight"===e,clone:!0})}:function(e){return null==e||isNaN(e)?0:e};this["get"+a]=function(){return this._type===t||s&&/^hs[bl]$/.test(this._type)?this._components[r]:this._convert(t)[r]},this["set"+a]=function(e){this._type===t||s&&/^hs[bl]$/.test(this._type)||(this._components=this._convert(t),this._properties=n[t],this._type=t),this._components[r]=l.call(this,e),this._changed()}},this)},{_class:"Color",_readIndex:!0,initialize:function t(r){var a,s,o,l,c=Array.prototype.slice,h=arguments,u=0;Array.isArray(r)&&(h=r,r=h[0]);var d=null!=r&&typeof r;if("string"===d&&r in n&&(a=r,r=h[1],Array.isArray(r)?(s=r,o=h[2]):(this.__read&&(u=1),h=c.call(h,1),d=typeof r)),!s){if(l="number"===d?h:"object"===d&&null!=r.length?r:null){a||(a=l.length>=3?"rgb":"gray");var m=n[a].length;o=l[m],this.__read&&(u+=l===arguments?m+(null!=o?1:0):1),l.length>m&&(l=c.call(l,0,m))}else if("string"===d)a="rgb",s=e(r),4===s.length&&(o=s[3],s.length--);else if("object"===d)if(r.constructor===t){if(a=r._type,s=r._components.slice(),o=r._alpha,"gradient"===a)for(var p=1,g=s.length;p1?1:e))}var n=this._convert("rgb"),i=e||null==this._alpha?1:this._alpha;return n=[t(n[0]),t(n[1]),t(n[2])],i<1&&n.push(i<0?0:i),e?"#"+((1<<24)+(n[0]<<16)+(n[1]<<8)+n[2]).toString(16).slice(1):(4==n.length?"rgba(":"rgb(")+n.join(",")+")"},toCanvasStyle:function(e){if(this._canvasStyle)return this._canvasStyle;if("gradient"!==this._type)return this._canvasStyle=this.toCSS();var t,n=this._components,i=n[0],r=i._stops,a=n[1],s=n[2];if(i._radial){var o=s.getDistance(a),l=n[3];if(l){var c=l.subtract(a);c.getLength()>o&&(l=a.add(c.normalize(o-.1)))}var h=l||a;t=e.createRadialGradient(h.x,h.y,0,a.x,a.y,o)}else t=e.createLinearGradient(a.x,a.y,s.x,s.y);for(var u=0,d=r.length;u0&&!(t instanceof D))for(var i=0,o=n.length;i0},hasShadow:function(){return!!this.getShadowColor()&&this.getShadowBlur()>0},getView:function(){return this._project.getView()},getFontStyle:function(){var e=this.getFontSize();return this.getFontWeight()+" "+e+(/[a-z]/i.test(e+"")?" ":"px ")+this.getFontFamily()},getFont:"#getFontFamily",setFont:"#setFontFamily",getLeading:function e(){var t=e.base.call(this),n=this.getFontSize();return/pt|em|%|px/.test(n)&&(n=this.getView().getPixelSize(n)),null!=t?t:1.2*n}}),H=new function(){function e(e,t,n,i){for(var r=["","webkit","moz","Moz","ms","o"],a=t[0].toUpperCase()+t.substring(1),s=0;s<6;s++){var o=r[s],l=o?o+a:t;if(l in e){if(!n)return e[l];e[l]=i;break}}}return{getStyles:function(e){var t=e&&9!==e.nodeType?e.ownerDocument:e,n=t&&t.defaultView;return n&&n.getComputedStyle(e,"")},getBounds:function(e,t){var n,i=e.ownerDocument,r=i.body,a=i.documentElement;try{n=e.getBoundingClientRect()}catch(e){n={left:0,top:0,width:0,height:0}}var s=n.left-(a.clientLeft||r.clientLeft||0),o=n.top-(a.clientTop||r.clientTop||0);if(!t){var l=i.defaultView;s+=l.pageXOffset||a.scrollLeft||r.scrollLeft,o+=l.pageYOffset||a.scrollTop||r.scrollTop}return new w(s,o,n.width,n.height)},getViewportBounds:function(e){var t=e.ownerDocument,n=t.defaultView,i=t.documentElement;return new w(0,0,n.innerWidth||i.clientWidth,n.innerHeight||i.clientHeight)},getOffset:function(e,t){return H.getBounds(e,t).getPoint()},getSize:function(e){return H.getBounds(e,!0).getSize()},isInvisible:function(e){return H.getSize(e).equals(new g(0,0))},isInView:function(e){return!H.isInvisible(e)&&H.getViewportBounds(e).intersects(H.getBounds(e,!0))},getPrefixed:function(t,n){return e(t,n)},setPrefixed:function(t,n,i){if("object"==typeof n)for(var r in n)e(t,r,!0,n[r]);else e(t,n,!0,i)}}},U={add:function(e,t){for(var n in t)for(var i=t[n],r=n.split(/[\s,]+/g),a=0,s=r.length;a=0;t--){var s=r[t],o=s[0],l=s[1];(!l||("true"==c.getAttribute(l,"keepalive")||a)&&H.isInView(l))&&(r.splice(t,1),o())}n&&(r.length?n(e):i=!1)}var t,n=H.getPrefixed(window,"requestAnimationFrame"),i=!1,r=[],a=!0;return U.add(window,{focus:function(){a=!0},blur:function(){a=!1}}),function(a,s){r.push([a,s]),n?i||(n(e),i=!0):t||(t=setInterval(e,1e3/60))}};var Q=o.extend(l,{_class:"View",initialize:function e(t,n){function i(e){return n[e]||parseInt(n.getAttribute(e),10)}function r(){var e=H.getSize(n);return e.isNaN()||e.isZero()?new g(i("width"),i("height")):e}this._project=t,this._scope=t._scope,this._element=n;var a;this._pixelRatio||(this._pixelRatio=window.devicePixelRatio||1),this._id=n.getAttribute("id"),null==this._id&&n.setAttribute("id",this._id="view-"+e._id++),U.add(n,this._viewEvents);var s="none";if(H.setPrefixed(n.style,{userSelect:s,touchAction:s,touchCallout:s,contentZooming:s,userDrag:s,tapHighlightColor:"rgba(0,0,0,0)"}),c.hasAttribute(n,"resize")){var o=this;U.add(window,this._windowEvents={resize:function(){o.setViewSize(r())}})}if(this._setViewSize(a=r()),c.hasAttribute(n,"stats")&&"undefined"!=typeof Stats){this._stats=new Stats;var l=this._stats.domElement,h=l.style,u=H.getOffset(n);h.position="absolute",h.left=u.x+"px",h.top=u.y+"px",document.body.appendChild(l)}e._views.push(this),e._viewsById[this._id]=this,this._viewSize=a,(this._matrix=new b)._owner=this,this._zoom=1,e._focused||(e._focused=this),this._frameItems={},this._frameItemCount=0},remove:function(){return!!this._project&&(Q._focused===this&&(Q._focused=null),Q._views.splice(Q._views.indexOf(this),1),delete Q._viewsById[this._id],this._project._view===this&&(this._project._view=null),U.remove(this._element,this._viewEvents),U.remove(window,this._windowEvents),this._element=this._project=null,this.off("frame"),this._animate=!1,this._frameItems={},!0)},_events:o.each(["onResize","onMouseDown","onMouseUp","onMouseMove"],function(e){this[e]={install:function(e){this._installEvent(e)},uninstall:function(e){this._uninstallEvent(e)}}},{onFrame:{install:function(){this.play()},uninstall:function(){this.pause()}}}),_animate:!1,_time:0,_count:0,_requestFrame:function(){var e=this;U.requestAnimationFrame(function(){e._requested=!1,e._animate&&(e._requestFrame(),e._handleFrame())},this._element),this._requested=!0},_handleFrame:function(){a=this._scope;var e=Date.now()/1e3,t=this._before?e-this._before:0;this._before=e,this._handlingFrame=!0,this.emit("frame",new o({delta:t,time:this._time+=t,count:this._count++})),this._stats&&this._stats.update(),this._handlingFrame=!1,this.update()},_animateItem:function(e,t){var n=this._frameItems;t?(n[e._id]={item:e,time:0,count:0},1===++this._frameItemCount&&this.on("frame",this._handleFrameItems)):(delete n[e._id],0===--this._frameItemCount&&this.off("frame",this._handleFrameItems))},_handleFrameItems:function(e){for(var t in this._frameItems){var n=this._frameItems[t];n.item.emit("frame",new o(e,{time:n.time+=e.delta,count:n.count++}))}},_update:function(){this._project._needsUpdate=!0,this._handlingFrame||(this._animate?this._handleFrame():this.update())},_changed:function(e){1&e&&(this._project._needsUpdate=!0)},_transform:function(e){this._matrix.concatenate(e),this._bounds=null,this._update()},getElement:function(){return this._element},getPixelRatio:function(){return this._pixelRatio},getResolution:function(){return 72*this._pixelRatio},getViewSize:function(){var e=this._viewSize;return new v(e.width,e.height,this,"setViewSize")},setViewSize:function(){var e=g.read(arguments),t=e.subtract(this._viewSize);t.isZero()||(this._viewSize.set(e.width,e.height),this._setViewSize(e),this._bounds=null,this.emit("resize",{size:e,delta:t}),this._update())},_setViewSize:function(e){var t=this._element;t.width=e.width,t.height=e.height},getBounds:function(){return this._bounds||(this._bounds=this._matrix.inverted()._transformBounds(new w(new m,this._viewSize))),this._bounds},getSize:function(){return this.getBounds().getSize(); -},getCenter:function(){return this.getBounds().getCenter()},setCenter:function(){var e=m.read(arguments);this.scrollBy(e.subtract(this.getCenter()))},getZoom:function(){return this._zoom},setZoom:function(e){this._transform((new b).scale(e/this._zoom,this.getCenter())),this._zoom=e},isVisible:function(){return H.isInView(this._element)},scrollBy:function(){this._transform((new b).translate(m.read(arguments).negate()))},play:function(){this._animate=!0,this._requested||this._requestFrame()},pause:function(){this._animate=!1},draw:function(){this.update()},projectToView:function(){return this._matrix._transformPoint(m.read(arguments))},viewToProject:function(){return this._matrix._inverseTransform(m.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(e,t){return"string"==typeof t&&(t=document.getElementById(t)),new K(e,t)}}},new function(){function e(e){var t=U.getTarget(e);return t.getAttribute&&Q._viewsById[t.getAttribute("id")]}function t(e,t){return e.viewToProject(U.getOffset(t,e._element))}function n(){if(!Q._focused||!Q._focused.isVisible())for(var e=0,t=Q._views.length;ethis._maxDistance&&(this._maxDistance=e)},getMaxDistance:function(){return this._maxDistance},setMaxDistance:function(e){this._maxDistance=e,null!=this._minDistance&&null!=e&&ei)t=this._point.add(l.normalize(i));else if(s)return!1}if(a&&t.equals(this._point))return!1}switch(this._lastPoint=r&&"mousemove"==e?t:this._point,this._point=t,e){case"mousedown":this._lastPoint=this._downPoint,this._downPoint=this._point,this._downCount++;break;case"mouseup":this._lastPoint=this._downPoint}return this._count=r?0:this._count+1,!0},_fireEvent:function(e,t){var n=a.project._removeSets;if(n){"mouseup"===e&&(n.mousedrag=null);var i=n[e];if(i){for(var r in i){var s=i[r];for(var o in n){var l=n[o];l&&l!=i&&delete l[s._id]}s.remove()}n[e]=null}}return this.responds(e)&&this.emit(e,new ee(this,e,t))},_handleEvent:function(e,t,n){a=this._scope;var i=!1;switch(e){case"mousedown":this._updateEvent(e,t,null,null,!0,!1,!1),i=this._fireEvent(e,n);break;case"mousedrag":for(var r=!1,s=!1;this._updateEvent(e,t,this.minDistance,this.maxDistance,!1,r,s);)i=this._fireEvent(e,n)||i,r=!0,s=!0;break;case"mouseup":!t.equals(this._point)&&this._updateEvent("mousedrag",t,this.minDistance,this.maxDistance,!1,!1,!1)&&(i=this._fireEvent("mousedrag",n)),this._updateEvent(e,t,null,this.maxDistance,!1,!1,!1),i=this._fireEvent(e,n)||i,this._updateEvent(e,t,null,null,!0,!1,!1),this._firstMove=!0;break;case"mousemove":for(;this._updateEvent(e,t,this.minDistance,this.maxDistance,this._firstMove,!0,!1);)i=this._fireEvent(e,n)||i,this._firstMove=!1}return i&&n.preventDefault(),i}}),{request:function(e,t,n,i){i=i===s||i;var r=new(window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");return r.open(e.toUpperCase(),t,i),"overrideMimeType"in r&&r.overrideMimeType("text/plain"),r.onreadystatechange=function(){if(4===r.readyState){var e=r.status;if(0!==e&&200!==e)throw new Error("Could not load "+t+" (Error "+e+")");n.call(r,r.responseText)}},r.send(null)}}),ne={canvases:[],getCanvas:function(e,t){var n,i=!0;"object"==typeof e&&(t=e.height,e=e.width),n=this.canvases.length?this.canvases.pop():document.createElement("canvas");var r=n.getContext("2d");return n.width===e&&n.height===t?i&&r.clearRect(0,0,e+1,t+1):(n.width=e,n.height=t),r.save(),n},getContext:function(e,t){return this.getCanvas(e,t).getContext("2d")},release:function(e){var t=e.canvas?e.canvas:e;t.getContext("2d").restore(),this.canvases.push(t)}},ie=new function(){function e(e,t,n){return.2989*e+.587*t+.114*n}function t(t,n,i,r){var a=r-e(t,n,i);f=t+a,m=n+a,p=i+a;var r=e(f,m,p),s=g(f,m,p),o=v(f,m,p);if(s<0){var l=r-s;f=r+(f-r)*r/l,m=r+(m-r)*r/l,p=r+(p-r)*r/l}if(o>255){var c=255-r,h=o-r;f=r+(f-r)*c/h,m=r+(m-r)*c/h,p=r+(p-r)*c/h}}function n(e,t,n){return v(e,t,n)-g(e,t,n)}function i(e,t,n,i){var r,a=[e,t,n],s=v(e,t,n),o=g(e,t,n);o=o===e?0:o===t?1:2,s=s===e?0:s===t?1:2,r=0===g(o,s)?1===v(o,s)?2:1:0,a[s]>a[o]?(a[r]=(a[r]-a[o])*i/(a[s]-a[o]),a[s]=i):a[r]=a[s]=0,a[o]=0,f=a[0],m=a[1],p=a[2]}var r,a,s,l,c,h,u,d,f,m,p,g=Math.min,v=Math.max,w=Math.abs,y={multiply:function(){f=c*r/255,m=h*a/255,p=u*s/255},screen:function(){f=c+r-c*r/255,m=h+a-h*a/255,p=u+s-u*s/255},overlay:function(){f=c<128?2*c*r/255:255-2*(255-c)*(255-r)/255,m=h<128?2*h*a/255:255-2*(255-h)*(255-a)/255,p=u<128?2*u*s/255:255-2*(255-u)*(255-s)/255},"soft-light":function(){var e=r*c/255;f=e+c*(255-(255-c)*(255-r)/255-e)/255,e=a*h/255,m=e+h*(255-(255-h)*(255-a)/255-e)/255,e=s*u/255,p=e+u*(255-(255-u)*(255-s)/255-e)/255},"hard-light":function(){f=r<128?2*r*c/255:255-2*(255-r)*(255-c)/255,m=a<128?2*a*h/255:255-2*(255-a)*(255-h)/255,p=s<128?2*s*u/255:255-2*(255-s)*(255-u)/255},"color-dodge":function(){f=0===c?0:255===r?255:g(255,255*c/(255-r)),m=0===h?0:255===a?255:g(255,255*h/(255-a)),p=0===u?0:255===s?255:g(255,255*u/(255-s))},"color-burn":function(){f=255===c?255:0===r?0:v(0,255-255*(255-c)/r),m=255===h?255:0===a?0:v(0,255-255*(255-h)/a),p=255===u?255:0===s?0:v(0,255-255*(255-u)/s)},darken:function(){f=cr?c:r,m=h>a?h:a,p=u>s?u:s},difference:function(){f=c-r,f<0&&(f=-f),m=h-a,m<0&&(m=-m),p=u-s,p<0&&(p=-p)},exclusion:function(){f=c+r*(255-c-c)/255,m=h+a*(255-h-h)/255,p=u+s*(255-u-u)/255},hue:function(){i(r,a,s,n(c,h,u)),t(f,m,p,e(c,h,u))},saturation:function(){i(c,h,u,n(r,a,s)),t(f,m,p,e(c,h,u))},luminosity:function(){t(c,h,u,e(r,a,s))},color:function(){t(r,a,s,e(c,h,u))},add:function(){f=g(c+r,255),m=g(h+a,255),p=g(u+s,255)},subtract:function(){f=v(c-r,0),m=v(h-a,0),p=v(u-s,0)},average:function(){f=(c+r)/2,m=(h+a)/2,p=(u+s)/2},negation:function(){f=255-w(255-r-c),m=255-w(255-a-h),p=255-w(255-s-u)}},b=this.nativeModes=o.each(["source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","darker","copy","xor"],function(e){this[e]=!0},{}),x=ne.getContext(1,1);o.each(y,function(e,t){var n="darken"===t,i=!1;x.save();try{x.fillStyle=n?"#300":"#a00",x.fillRect(0,0,1,1),x.globalCompositeOperation=t,x.globalCompositeOperation===t&&(x.fillStyle=n?"#a00":"#300",x.fillRect(0,0,1,1),i=x.getImageData(0,0,1,1).data[0]!==n?170:51)}catch(e){}x.restore(),b[t]=i}),ne.release(x),this.process=function(e,t,n,i,o){var g=t.canvas,v="normal"===e;if(v||b[e])n.save(),n.setTransform(1,0,0,1,0,0),n.globalAlpha=i,v||(n.globalCompositeOperation=e),n.drawImage(g,o.x,o.y),n.restore();else{var w=y[e];if(!w)return;for(var x=n.getImageData(o.x,o.y,g.width,g.height),_=x.data,E=t.getImageData(0,0,g.width,g.height).data,C=0,k=_.length;C=3){o=e._closed?"polygon":"polyline";for(var h=[],u=0,d=l.length;u1||/z\S+/i.test(t)?new D(n):new O(n)}function h(n,i){var r,a=(e(n,"href",!0)||"").substring(1),s="radialgradient"===i;if(a)r=P[a].getGradient();else{for(var o=n.childNodes,l=[],c=0,h=o.length;c0&&this.weights;t.beginPath();var i=r(0,this.degree,e,this.knots,n);t.moveTo(i[0],i[1]);for(var a=.01;a<1;a+=.01)i=r(a,this.degree,e,this.knots,n),t.lineTo(i[0],i[1]);i=r(1,this.degree,e,this.knots,n),t.lineTo(i[0],i[1]),t.stroke(),t.closePath()},drawKnots:function(e){var t=this,n=this.knots,i=this.weights.length>0&&this.weights;n.forEach(function(a,s){if(!(sn.length-1-t.degree)){var o=r(a,t.degree,e,n,i,!1,!0);t.circle(o[0],o[1],3)}})},drawNodes:function(e){var t,n=this;this.stroke(150),this.nodes.forEach(function(i,a){try{t=r(i,n.degree,e,n.knots,!1,!1,!0),n.line(t[0],t[1],e[a][0],e[a++][1])}catch(e){console.error(e)}})},formKnots:function(e,t){if(t=t===!0,!t)return this.formUniformKnots(e);var n,i=e.length,r=[],a=i-this.degree;for(n=1;n=0;n--)t.push(n);return t.reverse()},formNodes:function(e,t){var n,i,r,a=[this.degree,e.length-1-this.degree],s=[];for(i=0;ie[a[1]]||s.push(n)}return s},formWeights:function(e){var t=[];return e.forEach(function(e){return t.push(1)}),t},setDegree:function(e){this.degree+=e,this.knots=this.formKnots(this.points),this.nodes=this.formNodes(this.knots,this.points)},near:function(e,t,n){var i=e.x-t,r=e.y-n,a=Math.sqrt(i*i+r*r);return a1&&this.setDegree(-1),this.redraw()},keyUp:function(){},keyPressed:function(){},mouseDown:function(){this.isMouseDown=!0,this.cp=this.getCurrentPoint(this.mouseX,this.mouseY),this.cp||(this.points.push({x:this.mouseX,y:this.mouseY}),this.knots=this.formKnots(this.points),this.nodes=this.formNodes(this.knots,this.points)),this.redraw()},mouseUp:function(){this.isMouseDown=!1,this.cp=!1,this.redraw()},mouseDrag:function(){this.cp&&(this.cp.x=this.mouseX,this.cp.y=this.mouseY,this.redraw())},mouseMove:function(){},scrolled:function(e){if(this.cp=this.getCurrentPoint(this.mouseX,this.mouseY),this.cp){var t=this.points.indexOf(this.cp);this.weights.length>t&&(this.weights[t]+=.1*e,this.weights[t]<0&&(this.weights[t]=0)),t=this.points.indexOf(this.cp,t+1),t!==-1&&this.weights.length>t&&(this.weights[t]+=.1*e, -this.weights[t]<0&&(this.weights[t]=0)),this.redraw()}},setKeyboardValues:function(e){e.ctrlKey||e.metaKey||e.altKey||e.preventDefault(),this.key=e.key,this.keyCode=e.code},setMouseValues:function(e){var t=this.cvs.getBoundingClientRect();this.mouseX=e.clientX-t.left,this.mouseY=e.clientY-t.top},size:function(e,t){this.width=0|e,this.height=0|(t||e),this.cvs.width=this.width,this.cvs.height=this.height,this.ctx=this.cvs.getContext("2d")},redraw:function(){this.draw()},clear:function(){this.ctx.clearRect(0,0,this.width,this.height)},grid:function(e){e=(0|(e||10))+.5,this.stroke(200,200,220);for(var t=e;t=o)return null;var h={type:t,min:n,max:r,step:a,value:l,onChange:function(t){var n=e.state.weights;n[c]=t.target.value,s&&c-1){n.update();break}}else this.curve&&this.curve.update&&this.curve.update()}this.props.onMouseMove&&this.props.onMouseMove(e,this),this.dragging&&this.props.onMouseDrag&&this.props.onMouseDrag(e,this),this.props.static||this.playing||!this.props.draw||this.props.draw(this,this.curve)},mouseUp:function(e){return this.down=!1,this.movingPoint?(this.movingPoint=!1,this.mp=!1,void(this.props.onMouseUp&&this.props.onMouseUp(e,this))):void(this.props.onMouseUp&&this.props.onMouseUp(e,this))},onClick:function(e){this.mx=e.offsetX,this.my=e.offsetY,!this.dragging&&this.props.onClick&&this.props.onClick(e,this)},onKeyUp:function(e){this.props.onKeyUp&&(this.props.onKeyUp(e,this),!this.playing&&this.props.draw&&this.props.draw(this,this.curve))},onKeyDown:function(e){this.props.onKeyDown&&(this.props.onKeyDown(e,this),!this.playing&&this.props.draw&&this.props.draw(this,this.curve))},onKeyPress:function(e){this.props.onKeyPress&&(this.props.onKeyPress(e,this),!this.playing&&this.props.draw&&this.props.draw(this,this.curve))},reset:function(){this.refs.canvas.width=this.refs.canvas.width,this.ctx.strokeStyle="black",this.ctx.lineWidth=1,this.ctx.fillStyle="none";var e=this.getPixelRatio();this.ctx.scale(e,e),this.offset={x:0,y:0},this.colorSeed=0},setSize:function(e,t){this.defaultWidth=e,this.defaultHeight=t;var n=this.refs.canvas;n.style.width=this.panelCount*e+"px",n.style.height=t+"px";var i=this.getPixelRatio();n.width=this.panelCount*e*i,n.height=t*i,this.ctx.scale(i,i)},setCurves:function(e){this.setCurve(e)},setCurve:function(e){var t=[];e=e instanceof Array?e:Array.prototype.slice.call(arguments),e.forEach(function(e){t=t.concat(e.points)}),this.curve=1===e.length?e[0]:e,this.lpts=t},getPanelWidth:function(){return this.defaultWidth},getPanelHeight:function(){return this.defaultHeight},getDefaultQuadratic:function(){return new this.Bezier(70,250,20,110,250,60)},getDefaultCubic:function(){return new this.Bezier(120,160,35,200,220,260,220,40)},getPixelRatio:function(){return window.devicePixelRatio||1},toImage:function(){var e=this.refs.canvas.toDataURL(),t=new Image;return t.src=e,t.devicePixelRatio=this.getPixelRatio(),t},setPanelCount:function(e){this.panelCount=e;var t=this.refs.canvas;t.width=e*this.defaultWidth*this.getPixelRatio(),t.style.width=e*this.defaultWidth+"px"},setOffset:function(e){this.offset=e},setColor:function(e){this.ctx.strokeStyle=e},getColor:function(){return this.ctx.strokeStyle||"black"},setWeight:function(e){this.ctx.lineWidth=e},noColor:function(e){this.ctx.strokeStyle="transparent"},setRandomColor:function(e){e="undefined"==typeof e?1:e;var t=this.colorSeed%360,n=1,i=.34;this.colorSeed+=87,this.ctx.strokeStyle=r.hsl(t,n,i).alpha(e).css()},setRandomFill:function(e){e="undefined"==typeof e?1:e;var t=this.colorSeed%360,n=1,i=.34;this.colorSeed+=87,this.ctx.fillStyle=r.hsl(t,n,i).alpha(e).css()},setFill:function(e){this.ctx.fillStyle=e},getFill:function(){return this.ctx.fillStyle||"transparent"},noFill:function(){this.ctx.fillStyle="transparent"},drawSkeleton:function(e,t,n){t=t||{x:0,y:0};var i=e.points;if(i.length>2){this.ctx.strokeStyle="lightgrey",this.drawLine(i[0],i[1],t);for(var r=i.length-2,a=1;a.95)&&(t.t=!1),t.redraw()},setupQuadratic:function(e){var t=e.getDefaultQuadratic();t.points[0].y-=10,e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();t.points[2].y-=20,e.setCurve(t),e.lut=t.getLUT(100)},draw:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=e.getPanelHeight();if(e.setColor("black"),e.t){e.drawCircle(e.curve.get(e.t),3),e.setColor("lightgrey");var i,r,a,s=e.drawHull(t,e.t),o=e.utils;6===s.length?(i=t.points[1],r=s[5],a=o.lli4(i,r,t.points[0],t.points[2]),e.setColor("lightgrey"),e.drawLine(t.points[0],t.points[2])):10===s.length&&(i=s[5],r=s[9],a=o.lli4(i,r,t.points[0],t.points[3]),e.setColor("lightgrey"),e.drawLine(t.points[0],t.points[3])),e.setColor("#00FF00"),e.drawLine(i,r),e.setColor("red"),e.drawLine(r,a),e.setColor("black"),e.drawCircle(a,3),e.setFill("black"),e.text("A",{x:10+i.x,y:i.y}),e.text("B (t = "+e.utils.round(e.t,2)+")",{x:10+r.x,y:r.y}),e.text("C",{x:10+a.x,y:a.y});var l=o.dist(i,r),c=o.dist(r,a),h=l/c;e.text("d1 (A-B): "+o.round(l,2)+", d2 (B-C): "+o.round(c,2)+", ratio (d1/d2): "+o.round(h,4),{x:10,y:n-7})}},setCT:function(e,t){t.t=e.offsetX/t.getPanelWidth()},drawCTgraph:function(e){e.reset(),e.setColor("black");var t=e.getPanelWidth(),n=20,i=t-2*n;e.drawAxes(n,"t",0,1,"u",0,1),e.setColor("blue");var r=function(t){var r=e.u(t),a={x:n+t*i,y:n+r*i};return a};if(e.drawFunction(r),e.t){var a=e.u(e.t),s=e.utils.round(a,3),o=e.utils.round(1-a,3),l=r(e.t);e.drawLine({x:l.x,y:n},l),e.drawLine({x:n,y:l.y},l),e.drawCircle(l,3),e.setFill("blue"),e.text(" t = "+e.utils.round(e.t,3),{x:l.x+10,y:l.y-7}),e.text("u(t) = "+e.utils.round(a,3),{x:l.x+10,y:l.y+7}),e.setFill("black"),e.text("C = "+s+" * start + "+o+" * end",{x:t/2-n,y:n+i})}},drawQCT:function(e){e.u=e.u||function(e){var t=(e-1)*(e-1),n=2*e*e-2*e+1;return t/n},this.drawCTgraph(e)},drawCCT:function(e){e.u=e.u||function(e){var t=(1-e)*(1-e)*(1-e),n=e*e*e+t;return t/n},this.drawCTgraph(e)}}},function(e,t,n){"use strict";var i=n(25),r=n(0);e.exports=r("abc",i)},function(e,t,n){"use strict";e.exports={setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},align:function(e,t){var n=t.p1.x,i=t.p1.y,r=-Math.atan2(t.p2.y-i,t.p2.x-n),a=Math.cos,s=Math.sin,o=function(e){return{x:(e.x-n)*a(r)-(e.y-i)*s(r),y:(e.x-n)*s(r)+(e.y-i)*a(r)}};return e.map(o)},draw:function(e,t){e.setPanelCount(2),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.points,i={p1:n[0],p2:n[n.length-1]},r=this.align(n,i),a=new e.Bezier(r),s=e.getPanelWidth(),o=e.getPanelHeight(),l={x:s,y:0};e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:o},l),l.x+=s/4,l.y+=o/2,e.setColor("grey"),e.drawLine({x:0,y:-o/2},{x:0,y:o/2},l),e.drawLine({x:-s/4,y:0},{x:s,y:0},l),e.setFill("grey"),e.setColor("black"),e.drawSkeleton(a,l),e.drawCurve(a,l)}}},function(e,t,n){"use strict";var i=n(27),r=n(0);e.exports=r("aligning",i)},function(e,t,n){"use strict";var i=Math.atan2,r=Math.PI,a=2*r,s=Math.cos,o=Math.sin;e.exports={statics:{keyHandlingOptions:{propName:"error",values:{38:.1,40:-.1},controller:function(e){e.error<.1&&(e.error=.1)}}},setupCircle:function(e){var t=new e.Bezier(70,70,140,40,240,130);e.setCurve(t)},setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t),e.error=.5},getCCenter:function(e,t,n,l){var c,h=n.x-t.x,u=n.y-t.y,d=l.x-n.x,f=l.y-n.y,m=h*s(r/2)-u*o(r/2),p=h*o(r/2)+u*s(r/2),g=d*s(r/2)-f*o(r/2),v=d*o(r/2)+f*s(r/2),w=(t.x+n.x)/2,y=(t.y+n.y)/2,b=(n.x+l.x)/2,x=(n.y+l.y)/2,_=w+m,E=y+p,C=b+g,k=x+v,S=e.utils.lli8(w,y,_,E,b,x,C,k),z=e.utils.dist(S,t),T=i(t.y-S.y,t.x-S.x),P=i(n.y-S.y,n.x-S.x),B=i(l.y-S.y,l.x-S.x);return TP||P>B)&&(T+=a),T>B&&(c=B,B=T,T=c)):B-10&&(l.push({x:r*c,y:r*h}),e.drawLine({x:r*c,y:r*h},{x:r*s,y:r*o},a)),c=s,h=o;l.push({x:r*c,y:r*h}),e.text("Curve form has cusp →",{x:n/2-2*r,y:i/2+r/2.5}),e.setColor("#FF00FF"),e.setFill(e.getColor());var u=Math.sqrt;for(s=1;s>=0;s-=.005)l.push({x:r*c,y:r*h}),o=.5*(u(3)*u(4*s-s*s)-s),e.drawLine({x:r*c,y:r*h},{x:r*s,y:r*o},a),c=s,h=o;for(l.push({x:r*c,y:r*h}),e.text("← Curve forms a loop at t = 1",{x:n/2+r/4,y:i/2+r/1.5}),e.setColor("#3300FF"),e.setFill(e.getColor()),s=0;s>-n;s-=.01)l.push({x:r*c,y:r*h}),o=(-s*s+3*s)/3,e.drawLine({x:r*c,y:r*h},{x:r*s,y:r*o},a),c=s,h=o;l.push({x:r*c,y:r*h}),e.text("← Curve forms a loop at t = 0",{x:n/2-r+10,y:i/2-1.25*r}),e.setColor("transparent"),e.setFill("rgba(255,120,100,0.2)"),e.drawPath(l,a),l=[{x:-n/2,y:r},{x:n/2,y:r},{x:n/2,y:i},{x:-n/2,y:i}],e.setFill("rgba(0,200,0,0.2)"),e.drawPath(l,a),e.setColor("black"),e.setFill(e.getColor()),e.text("← Curve form has one inflection →",{x:n/2-r,y:i/2+1.75*r}),e.text("← Plain curve ↕",{x:n/2+r/2,y:i/6}),e.text("↕ Double inflection",{x:10,y:i/2-10}),e._map_image=e.toImage(),e._map_loaded=!0}}},function(e,t,n){"use strict";var i=n(45),r=n(0);e.exports=r("canonical",i)},function(e,t,n){"use strict";var i=n(0);e.exports=i("catmullconv")},function(e,t,n){"use strict";e.exports={statics:{keyHandlingOptions:{propName:"distance",values:{38:1,40:-1}}},setup:function(e){e.setPanelCount(3),e.lpts=[{x:56,y:153},{x:144,y:83},{x:188,y:185}],e.distance=0},convert:function(e,t,n,i){var r=.5;return[t,{x:t.x+(n.x-e.x)/(6*r),y:t.y+(n.y-e.y)/(6*r)},{x:n.x-(i.x-t.x)/(6*r),y:n.y-(i.y-t.y)/(6*r)},n]},draw:function(e){e.reset(),e.setColor("lightblue"),e.drawGrid(10,10);var t=e.lpts;e.setColor("black"),e.setFill("black"),t.forEach(function(t,n){e.drawCircle(t,3),e.text("point "+(n+1),t,{x:10,y:7})});var n=e.getPanelWidth(),i=e.getPanelHeight(),r={x:n,y:0};e.setColor("lightblue"),e.drawGrid(10,10,r),e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:i},r),t.forEach(function(t,n){e.drawCircle(t,3,r)});var a=t[0],s=t[1],o=t[2],l=o.x-a.x,c=o.y-a.y,h=Math.sqrt(l*l+c*c);l/=h,c/=h,e.drawLine(a,o,r);var u={x:a.x+(o.x-s.x)-e.distance*l,y:a.y+(o.y-s.y)-e.distance*c},d={x:a.x+(o.x-s.x)+e.distance*l,y:a.y+(o.y-s.y)+e.distance*c},f=e.utils.lli4(a,o,s,{x:(u.x+d.x)/2,y:(u.y+d.y)/2});e.setColor("blue"),e.drawCircle(f,3,r),e.drawLine(t[1],f,r),e.setColor("#666"),e.drawLine(f,u,r),e.drawLine(f,d,r),e.setFill("blue"),e.text("p0",u,{x:-20+r.x,y:r.y+2}),e.text("p4",d,{x:10+r.x,y:r.y+2}),e.setColor("red"),e.drawCircle(u,3,r),e.drawLine(s,u,r),e.drawLine(a,{x:a.x+(s.x-u.x)/5,y:a.y+(s.y-u.y)/5},r),e.setColor("#00FF00"),e.drawCircle(d,3,r),e.drawLine(s,d,r),e.drawLine(o,{x:o.x+(d.x-s.x)/5,y:o.y+(d.y-s.y)/5},r);var m=new e.Bezier(this.convert(u,a,s,o)),p=new e.Bezier(this.convert(a,s,o,d));e.setColor("lightgrey"),e.drawCurve(m,r),e.drawCurve(p,r),r.x+=n,e.setColor("lightblue"),e.drawGrid(10,10,r),e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:i},r),e.drawCurve(m,r),e.drawCurve(p,r),e.drawPoints(m.points,r),e.drawPoints(p.points,r),e.setColor("lightgrey"),e.drawLine(m.points[0],m.points[1],r),e.drawLine(m.points[2],p.points[1],r),e.drawLine(p.points[2],p.points[3],r)}}},function(e,t,n){"use strict";var i=n(48),r=n(0),a=n(2);e.exports=a(r("catmullmoulding",i))},function(e,t,n){"use strict";var i=Math.sin,r=Math.cos;e.exports={setup:function(e){e.w=e.getPanelWidth(),e.h=e.getPanelHeight(),e.pad=20,e.r=e.w/2-e.pad,e.mousePt=!1,e.angle=0;var t={x:e.w-e.pad,y:e.h/2};e.setCurve(new e.Bezier(t,t,t))},draw:function(e,t){e.reset(),e.setColor("lightgrey"),e.drawGrid(1,1),e.setColor("red"),e.drawCircle({x:e.w/2,y:e.h/2},e.r),e.setColor("transparent"),e.setFill("rgba(100,255,100,0.4)");var n={x:e.w/2,y:e.h/2,r:e.r,s:e.angle<0?e.angle:0,e:e.angle<0?0:e.angle};e.drawArc(n),e.setColor("black"),e.drawSkeleton(t),e.drawCurve(t)},onMouseMove:function(e,t){var n=e.offsetX-t.w/2,a=e.offsetY-t.h/2,s=Math.atan2(a,n),o=t.curve.points,l=t.r,c=(r(s)-1)/i(s);o[1]={x:t.w/2+l*(r(s)-c*i(s)),y:t.w/2+l*(i(s)+c*r(s))},o[2]={x:t.w/2+t.r*r(s),y:t.w/2+t.r*i(s)},t.setCurve(new t.Bezier(o)),t.angle=s}}},function(e,t,n){"use strict";var i=n(50),r=n(0);e.exports=r("circles",i)},function(e,t,n){"use strict";var i=Math.sin,r=Math.cos,a=Math.tan;e.exports={setup:function(e){e.setSize(400,400),e.w=e.getPanelWidth(),e.h=e.getPanelHeight(),e.pad=80,e.r=e.w/2-e.pad,e.mousePt=!1,e.angle=0;var t={x:e.w-e.pad,y:e.h/2};e.setCurve(new e.Bezier(t,t,t,t))},guessCurve:function(e,t,n){var i={x:(e.x+n.x)/2,y:(e.y+n.y)/2},r={x:t.x+(t.x-i.x)/3,y:t.y+(t.y-i.y)/3},a=(n.x-e.x)/4,s=(n.y-e.y)/4,o={x:t.x-a,y:t.y-s},l={x:t.x+a,y:t.y+s},c={x:r.x+2*(o.x-r.x),y:r.y+2*(o.y-r.y)},h={x:r.x+2*(l.x-r.x),y:r.y+2*(l.y-r.y)},u={x:e.x+2*(c.x-e.x),y:e.y+2*(c.y-e.y)},d={x:n.x+2*(h.x-n.x),y:n.y+2*(h.y-n.y)};return[u,d]},draw:function(e,t){e.reset(),e.setColor("lightgrey"),e.drawGrid(1,1),e.setColor("rgba(255,0,0,0.4)"),e.drawCircle({x:e.w/2,y:e.h/2},e.r),e.setColor("transparent"),e.setFill("rgba(100,255,100,0.4)");var n={x:e.w/2,y:e.h/2,r:e.r,s:e.angle<0?e.angle:0,e:e.angle<0?0:e.angle};e.drawArc(n);var a={x:e.w/2+e.r*r(e.angle/2),y:e.w/2+e.r*i(e.angle/2)},s=t.points[0],o=t.points[3],l=this.guessCurve(s,a,o),c=new e.Bezier([s,l[0],l[1],o]);e.setColor("rgb(140,140,255)"),e.drawLine(c.points[0],c.points[1]),e.drawLine(c.points[1],c.points[2]),e.drawLine(c.points[2],c.points[3]),e.setColor("blue"),e.drawCurve(c),e.drawCircle(c.points[1],3),e.drawCircle(c.points[2],3),e.drawSkeleton(t),e.setColor("black"),e.drawLine(t.points[1],t.points[2]),e.drawCurve(t)},onMouseMove:function(e,t){var n=e.offsetX-t.w/2,s=e.offsetY-t.h/2;if(!(n>t.w/2)){var o=Math.atan2(s,n);o<0&&(o=2*Math.PI+o);var l=t.curve.points,c=t.r,h=4*a(o/4)/3;l[1]={x:t.w/2+c,y:t.w/2+c*h},l[2]={x:t.w/2+t.r*(r(o)+h*i(o)),y:t.w/2+t.r*(i(o)-h*r(o))},l[3]={x:t.w/2+t.r*r(o),y:t.w/2+t.r*i(o)},t.setCurve(new t.Bezier(l)),t.angle=o}},drawCircle:function(e){e.setSize(325,325),e.reset();var t=e.getPanelWidth(),n=e.getPanelHeight(),i=60,r=t/2-i,a=.55228,s={x:-i/2,y:-i/4},o=new e.Bezier([{x:t/2+r,y:n/2},{x:t/2+r,y:n/2+a*r},{x:t/2+a*r,y:n/2+r},{x:t/2,y:n/2+r}]);e.setColor("lightgrey"),e.drawLine({x:0,y:n/2},{x:t+i,y:n/2},s),e.drawLine({x:t/2,y:0},{x:t/2,y:n+i},s);var l=o.points;e.setColor("red"),e.drawPoint(l[0],s),e.drawPoint(l[1],s),e.drawPoint(l[2],s),e.drawPoint(l[3],s),e.drawCurve(o,s),e.setColor("rgb(255,160,160)"),e.drawLine(l[0],l[1],s),e.drawLine(l[1],l[2],s),e.drawLine(l[2],l[3],s),e.setFill("red"),e.text(l[0].x-t/2+","+(l[0].y-n/2),{x:l[0].x+7,y:l[0].y+3},s),e.text(l[1].x-t/2+","+(l[1].y-n/2),{x:l[1].x+7,y:l[1].y+3},s),e.text(l[2].x-t/2+","+(l[2].y-n/2),{x:l[2].x+7,y:l[2].y+7},s),e.text(l[3].x-t/2+","+(l[3].y-n/2),{x:l[3].x,y:l[3].y+13},s),l.forEach(function(e){e.x=-(e.x-t)}),e.setColor("blue"),e.drawCurve(o,s),e.drawLine(l[2],l[3],s),e.drawPoint(l[2],s),e.setFill("blue"),e.text("reflected",{x:l[2].x-i/2,y:l[2].y+13},s),e.setColor("rgb(200,200,255)"),e.drawLine(l[1],l[0],s),e.drawPoint(l[1],s),l.forEach(function(e){e.y=-(e.y-n)}),e.setColor("green"),e.drawCurve(o,s),l.forEach(function(e){e.x=-(e.x-t)}),e.setColor("purple"),e.drawCurve(o,s),e.drawLine(l[1],l[0],s),e.drawPoint(l[1],s),e.setFill("purple"),e.text("reflected",{x:l[1].x+10,y:l[1].y+3},s),e.setColor("rgb(200,200,255)"),e.drawLine(l[2],l[3],s),e.drawPoint(l[2],s),e.setColor("black"),e.setFill("black"),e.drawLine({x:t/2,y:n/2},{x:t/2+r-2,y:n/2},s),e.drawLine({x:t/2,y:n/2},{x:t/2,y:n/2+r-2},s),e.text("r = "+r,{x:t/2+r/3,y:n/2+10},s)}}},function(e,t,n){"use strict";var i=n(52),r=n(0);e.exports=r("circles_cubic",i)},function(e,t,n){"use strict";e.exports={componentDidMount:function(){if("undefined"!=typeof document){var e=document.createElement("script");e.src="lib/site/disqus.js",e.async=!0,document.head.appendChild(e)}}}},function(e,t,n){"use strict";var i=n(54),r=n(0);e.exports=r("comments",i)},function(e,t,n){"use strict";e.exports={setupQuadratic:function(e){var t=e.getDefaultQuadratic();t.points[2].x=210,e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.setPanelCount(3),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.order,i=20,r=t.points,a=e.getPanelWidth(),s=a-2*i,o=e.getPanelHeight(),l={x:a,y:0},c=JSON.parse(JSON.stringify(r)).map(function(e,t){return{x:s*t/n,y:e.x}});e.drawLine({x:0,y:0},{x:0,y:o},l),e.drawAxes(i,"t",0,1,"x",0,a,l),l.x+=i,e.drawCurve(new e.Bezier(c),l),l.x+=a-i;var h=JSON.parse(JSON.stringify(r)).map(function(e,t){return{x:s*t/n,y:e.y}});e.drawLine({x:0,y:0},{x:0,y:o},l),e.drawAxes(i,"t",0,1,"y",0,a,l),l.x+=i,e.drawCurve(new e.Bezier(h),l)}}},function(e,t,n){"use strict";var i=n(56),r=n(0);e.exports=r("components",i)},function(e,t,n){"use strict";e.exports={drawCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},drawCurve:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t)},drawFunction:function(e,t,n,i){e.setRandomColor(),e.drawFunction(i),e.setFill(e.getColor()),t&&e.text(t,n)},drawLerpBox:function(e,t,n,i){e.noColor(),e.setFill("rgba(0,0,100,0.2)");var r={x:i.x-5,y:n},a={x:i.x+5,y:t};e.drawRect(r,a),e.setColor("black")},drawLerpPoint:function(e,t,n,i,r){r.y=n+t*i,e.drawCircle(r,3),e.setFill("black"),e.text((1e4*t|0)/100+"%",{x:r.x+10,y:r.y+4}),e.noFill()},drawQuadraticLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,i=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var r=e.hover;if(r&&r.x>=n&&r.x<=t-n){this.drawLerpBox(e,t,n,r);var a=(r.x-n)/i;this.drawLerpPoint(e,(1-a)*(1-a),n,i,r),this.drawLerpPoint(e,2*(1-a)*a,n,i,r),this.drawLerpPoint(e,a*a,n,i,r)}this.drawFunction(e,"first term",{x:2*n,y:i},function(e){return{x:n+e*i,y:n+i*(1-e)*(1-e)}}),this.drawFunction(e,"second term",{x:t/2-1.5*n,y:t/2+n},function(e){return{x:n+e*i,y:n+2*i*(1-e)*e}}),this.drawFunction(e,"third term",{x:i-2.5*n,y:i},function(e){return{x:n+e*i,y:n+i*e*e}})},drawCubicLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,i=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var r=e.hover;if(r&&r.x>=n&&r.x<=t-n){this.drawLerpBox(e,t,n,r);var a=(r.x-n)/i;this.drawLerpPoint(e,(1-a)*(1-a)*(1-a),n,i,r),this.drawLerpPoint(e,3*(1-a)*(1-a)*a,n,i,r),this.drawLerpPoint(e,3*(1-a)*a*a,n,i,r),this.drawLerpPoint(e,a*a*a,n,i,r)}this.drawFunction(e,"first term",{x:2*n,y:i},function(e){return{x:n+e*i,y:n+i*(1-e)*(1-e)*(1-e)}}),this.drawFunction(e,"second term",{x:t/2-4*n,y:t/2},function(e){return{x:n+e*i,y:n+3*i*(1-e)*(1-e)*e}}),this.drawFunction(e,"third term",{x:t/2+2*n,y:t/2},function(e){return{x:n+e*i,y:n+3*i*(1-e)*e*e}}),this.drawFunction(e,"fourth term",{x:i-2.5*n,y:i},function(e){return{x:n+e*i,y:n+i*e*e*e}})},draw15thLerp:function(e){e.reset();var t=e.getPanelWidth(),n=20,i=t-2*n;e.drawAxes(n,"t",0,1,"S","0%","100%");var r,a=[1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1],s=e.hover;if(s&&s.x>=n&&s.x<=t-n)for(this.drawLerpBox(e,t,n,s),r=0;r<=15;r++){var o=(s.x-n)/i,l=a[r]*Math.pow(1-o,15-r)*Math.pow(o,r);this.drawLerpPoint(e,l,n,i,s)}for(r=0;r<=15;r++){var c=!1,h=!1;0===r&&(c="first term",h={x:n+5,y:i}),15===r&&(c="last term",h={x:t-3.5*n,y:i}),this.drawFunction(e,c,h,function(e){return{x:n+e*i,y:n+i*a[r]*Math.pow(1-e,15-r)*Math.pow(e,r)}})}}}},function(e,t,n){"use strict";var i=n(58),r=n(0);e.exports=r("control",i)},function(e,t,n){"use strict";var i=Math.abs;e.exports={setup:function(e){this.api=e,e.setPanelCount(3);var t=new e.Bezier(10,100,90,30,40,140,220,220),n=new e.Bezier(5,150,180,20,80,250,210,190);e.setCurve(t,n),this.pairReset()},pairReset:function(){this.prevstep=0,this.step=0},draw:function(e,t){var n=this;e.reset();var r={x:0,y:0};t.forEach(function(t){e.drawSkeleton(t),e.drawCurve(t)});var a=e.getPanelWidth(),s=e.getPanelHeight();if(r.x+=a,e.drawLine({x:0,y:0},{x:0,y:s},r),0===this.step&&(this.pairs=[{c1:t[0],c2:t[1]}]),this.step!==this.prevstep){var o=this.pairs;this.pairs=[],this.finals=[],o.forEach(function(t){if(t.c1.length()<.6&&t.c2.length()<.6)return n.finals.push(t);var i=t.c1.split(.5);e.setColor("black"),e.drawCurve(t.c1,r),e.setColor("red"),e.drawbbox(i.left.bbox(),r),e.drawbbox(i.right.bbox(),r);var a=t.c2.split(.5);e.setColor("black"),e.drawCurve(t.c2,r),e.setColor("blue"),e.drawbbox(a.left.bbox(),r),e.drawbbox(a.right.bbox(),r),i.left.overlaps(a.left)&&n.pairs.push({c1:i.left,c2:a.left}),i.left.overlaps(a.right)&&n.pairs.push({c1:i.left,c2:a.right}),i.right.overlaps(a.left)&&n.pairs.push({c1:i.right,c2:a.left}),i.right.overlaps(a.right)&&n.pairs.push({c1:i.right,c2:a.right})}),this.prevstep=this.step}else this.pairs.forEach(function(t){e.setColor("black"),e.drawCurve(t.c1,r),e.drawCurve(t.c2,r),e.setColor("red"),e.drawbbox(t.c1.bbox(),r),e.setColor("blue"),e.drawbbox(t.c2.bbox(),r)});0===this.pairs.length&&(this.pairReset(),this.draw(e,t)),r.x+=a,e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:s},r);var l,c,h=t[0].intersects(t[1]).map(function(e){var t=e.split("/").map(function(e){return parseFloat(e)});return{t1:t[0],t2:t[1]}}),u=h[0],d=function(e,t){return i(e.t1-t.t1)<.01&&i(e.t2-t.t2)<.01};for(c=1;c.95)&&(e.text("t = "+Math.round(u),{x:h.x+1.25*o*Math.cos(u)-10,y:h.y+1.25*l*Math.sin(u)+5}),e.drawCircle(c,2,h))}}}},function(e,t,n){"use strict";var i=n(65),r=n(0),a=n(2);e.exports=a(r("explanation",i))},function(e,t,n){"use strict";e.exports={setupQuadratic:function(e){var t=new e.Bezier(70,155,20,110,100,75);e.setCurve(t)},setupCubic:function(e){var t=new e.Bezier(60,105,75,30,215,115,140,160);e.setCurve(t)},draw:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t),e.setColor("lightgrey");var n,i,r=.05,a=-10,s=t.get(a-r);for(n=a;n<=r;n+=r)i=t.get(n),e.drawLine(s,i),s=i;s=t.get(1);var o=10;for(n=1+r;n<=o;n+=r)i=t.get(n),e.drawLine(s,i),s=i}}},function(e,t,n){"use strict";var i=n(67),r=n(0);e.exports=r("extended",i)},function(e,t,n){"use strict";e.exports={setupQuadratic:function(e){var t=e.getDefaultQuadratic();t.points[2].x=210,e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.setPanelCount(3),e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=t.order+1,i=20,r=t.points,a=e.getPanelWidth(),s=e.getPanelHeight(),o={x:a,y:0},l=JSON.parse(JSON.stringify(r)).map(function(e,t){return{x:a*t/n,y:e.x}});e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:s},o),e.drawAxes(i,"t",0,1,"x",0,a,o),o.x+=i;var c=new e.Bezier(l);e.drawCurve(c,o),e.setColor("red"),c.extrema().y.forEach(function(t){var n=c.get(t);e.drawCircle(n,3,o)}),o.x+=a-i;var h=JSON.parse(JSON.stringify(r)).map(function(e,t){return{x:a*t/n,y:e.y}});e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:s},o),e.drawAxes(i,"t",0,1,"y",0,a,o),o.x+=i;var u=new e.Bezier(h);e.drawCurve(u,o),e.setColor("red"),u.extrema().y.forEach(function(t){var n=u.get(t);e.drawCircle(n,3,o)})}}},function(e,t,n){"use strict";var i=n(69),r=n(0);e.exports=r("extremities",i)},function(e,t,n){"use strict";e.exports={statics:{keyHandlingOptions:{propName:"steps",values:{38:1,40:-1},controller:function(e){e.steps<1&&(e.steps=1)}}},setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t),e.steps=3},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t),e.steps=5},drawFlattened:function(e,t){e.reset(),e.setColor("#DDD"),e.drawSkeleton(t),e.setColor("#DDD"),e.drawCurve(t);for(var n,i=1/e.steps,r=t.points[0],a=i;a<1+i;a+=i)n=t.get(Math.min(a,1)),e.setColor("red"),e.drawLine(r,n),r=n;e.setFill("black"),e.text("Curve approximation using "+e.steps+" segments",{x:10,y:15})},values:{38:1,40:-1},onKeyDown:function(e,t){var n=this.values[e.keyCode];n&&(e.preventDefault(),t.steps+=n,t.steps<1&&(t.steps=1))}}},function(e,t,n){"use strict";var i=n(71),r=n(0),a=n(2);e.exports=a(r("flattening",i))},function(e,t,n){"use strict";e.exports={statics:{keyHandlingOptions:{propName:"distance",values:{38:1,40:-1}}},setup:function(e,t){e.setCurve(t),e.distance=20},setupQuadratic:function(e){var t=e.getDefaultQuadratic();this.setup(e,t)},setupCubic:function(e){var t=e.getDefaultCubic();this.setup(e,t)},draw:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t),e.setColor("blue");var n=t.outline(0,0,e.distance,e.distance);n.curves.forEach(function(t){return e.drawCurve(t)})}}},function(e,t,n){"use strict";var i=n(73),r=n(0),a=n(2);e.exports=a(r("graduatedoffset",i))},function(e,t,n){"use strict";e.exports={setupCubic:function(e){var t=new e.Bezier(135,25,25,135,215,75,215,240);e.setCurve(t)},draw:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t),e.setColor("red"),t.inflections().forEach(function(n){e.drawCircle(t.get(n),5)})}}},function(e,t,n){"use strict";var i=n(75),r=n(0);e.exports=r("inflections",i)},function(e,t,n){"use strict";var i=Math.min,r=Math.max;e.exports={setupLines:function(e){var t=new e.Bezier([50,50,150,110]),n=new e.Bezier([50,250,170,170]);e.setCurve(t,n)},drawLineIntersection:function(e,t){e.reset();var n=e.utils.lli4,a=n(t[0].points[0],t[0].points[1],t[1].points[0],t[1].points[1]),s=0;t.forEach(function(t){if(e.drawSkeleton(t),e.setColor("black"),a){var n=t.points,o=i(n[0].x,n[1].x),l=i(n[0].y,n[1].y),c=r(n[0].x,n[1].x),h=r(n[0].y,n[1].y);o<=a.x&&l<=a.y&&c>=a.x&&h>=a.y&&(e.setColor("#00FF00"),s++)}e.drawCurve(t)}),a&&(e.setColor(s<2?"red":"#00FF00"),e.drawCircle(a,3))},setupQuadratic:function(e){var t=e.getDefaultQuadratic(),n=new e.Bezier([15,250,220,20]);e.setCurve(t,n)},setupCubic:function(e){var t=new e.Bezier([100,240,30,60,210,230,160,30]),n=new e.Bezier([25,260,230,20]);e.setCurve(t,n)},draw:function(e,t){e.reset(),t.forEach(function(t){e.drawSkeleton(t),e.drawCurve(t)});var n=e.utils,i={p1:t[1].points[0],p2:t[1].points[1]},r=n.align(t[0].points,i),a=new e.Bezier(r),s=n.roots(a.points);s.forEach(function(n){var i=t[0].get(n);e.drawCircle(i,3),e.text("t = "+n,{x:i.x+5,y:i.y+10})})}}},function(e,t,n){"use strict";var i=n(77),r=n(0);e.exports=r("intersections",i)},function(e,t,n){"use strict";e.exports={drawQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},drawCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},drawCurve:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t)}}},function(e,t,n){"use strict";var i=n(79),r=n(0);e.exports=r("introduction",i)},function(e,t,n){"use strict";var i=n(0);e.exports=i("matrix")},function(e,t,n){"use strict";var i=n(0);e.exports=i("matrixsplit")},function(e,t,n){"use strict";var i=Math.abs;e.exports={setupQuadratic:function(e){e.setPanelCount(3);var t=e.getDefaultQuadratic();t.points[2].x-=30,e.setCurve(t)},setupCubic:function(e){e.setPanelCount(3);var t=new e.Bezier([100,230,30,160,200,50,210,160]);t.points[2].y-=20,e.setCurve(t),e.lut=t.getLUT(100)},saveCurve:function(e,t){t.t&&(t.setCurve(t.newcurve),t.t=!1,t.redraw())},findTValue:function(e,t){var n=t.curve.on({x:e.offsetX,y:e.offsetY},7);return!(n<.05||n>.95)&&n},markQB:function(e,t){if(t.t=this.findTValue(e,t),t.t){var n=t.t,r=2*n,a=r*n-r,s=a+1,o=i(a/s),l=t.curve,c=t.A=l.points[1],h=t.B=l.get(n);t.C=t.utils.lli4(c,h,l.points[0],l.points[2]),t.ratio=o}},markCB:function(e,t){if(t.t=this.findTValue(e,t),t.t){var n=t.t,r=1-n,a=n*n*n,s=r*r*r,o=a+s,l=o-1,c=i(l/o),h=t.curve,u=h.hull(n),d=t.A=u[5],f=t.B=h.get(n);t.db=h.derivative(n),t.C=t.utils.lli4(d,f,h.points[0],h.points[3]),t.ratio=c}},drag:function(e,t){if(t.t){var n=t.newB={x:e.offsetX,y:e.offsetY};t.newA={x:n.x-(t.C.x-n.x)/t.ratio,y:n.y-(t.C.y-n.y)/t.ratio}}},dragQB:function(e,t){t.t&&(this.drag(e,t),t.update=[t.newA])},dragCB:function(e,t){if(t.t){this.drag(e,t);var n=t.curve,i=n.hull(t.t),r=t.B,a=i[7],s=i[8],o={x:a.x-r.x,y:a.y-r.y},l={x:s.x-r.x,y:s.y-r.y},c=n.points,h={x:t.newB.x+o.x,y:t.newB.y+o.y},u={x:t.newA.x-(t.newA.x-h.x)/(1-t.t),y:t.newA.y-(t.newA.y-h.y)/(1-t.t)},d={x:t.newB.x+l.x,y:t.newB.y+l.y},f={x:t.newA.x+(d.x-t.newA.x)/t.t,y:t.newA.y+(d.y-t.newA.y)/t.t},m={x:c[0].x+(u.x-c[0].x)/t.t,y:c[0].y+(u.y-c[0].y)/t.t},p={x:c[3].x-(c[3].x-f.x)/(1-t.t),y:c[3].y-(c[3].y-f.y)/(1-t.t)};t.p1=h,t.p2=d,t.sc1=u,t.sc2=f,t.nc1=m,t.nc2=p,t.update=[m,p]}},drawMould:function(e,t){e.reset(),e.drawSkeleton(t),e.drawCurve(t);var n=e.getPanelWidth(),i=e.getPanelHeight(),r={x:n,y:0},a=e.utils.round;if(e.setColor("black"),e.drawLine({x:0,y:0},{x:0,y:i},r),e.drawLine({x:n,y:0},{x:n,y:i},r),e.t){e.drawCircle(t.get(e.t),3),e.npts=[t.points[0]].concat(e.update).concat([t.points.slice(-1)[0]]),e.newcurve=new e.Bezier(e.npts),e.setColor("lightgrey"),e.drawCurve(e.newcurve);var s=e.drawHull(e.newcurve,e.t,r);if(e.drawLine(e.npts[0],e.npts.slice(-1)[0],r),e.drawLine(e.newA,e.newB,r),e.setColor("grey"),e.drawCircle(e.newA,3,r),e.setColor("blue"),e.drawCircle(e.B,3,r),e.drawCircle(e.C,3,r),e.drawCircle(e.newB,3,r),e.drawLine(e.B,e.C,r),e.drawLine(e.newB,e.C,r),e.setFill("black"),e.text("A'",e.newA,{x:r.x+7,y:r.y+1}),e.text("start",t.get(0),{x:r.x+7,y:r.y+1}),e.text("end",t.get(1),{x:r.x+7,y:r.y+1}),e.setFill("blue"),e.text("B'",e.newB,{x:r.x+7,y:r.y+1}),e.text("B, at t = "+a(e.t,2),e.B,{x:r.x+7,y:r.y+1}),e.text("C",e.C,{x:r.x+7,y:r.y+1}),3===t.order){var o=t.hull(e.t);e.drawLine(o[7],o[8],r),e.drawLine(s[7],s[8],r),e.drawCircle(s[7],3,r),e.drawCircle(s[8],3,r),e.text("e1",s[7],{x:r.x+7,y:r.y+1}),e.text("e2",s[8],{x:r.x+7,y:r.y+1})}r.x+=n,e.setColor("lightgrey"),e.drawSkeleton(e.newcurve,r),e.setColor("black"),e.drawCurve(e.newcurve,r)}else r.x+=n,e.drawCurve(t,r)}}},function(e,t,n){"use strict";var i=n(83),r=n(0);e.exports=r("moulding",i)},function(e,t,n){"use strict";e.exports={statics:{keyHandlingOptions:{propName:"distance",values:{38:1,40:-1}}},setup:function(e,t){e.setCurve(t),e.distance=20},setupQuadratic:function(e){var t=e.getDefaultQuadratic();this.setup(e,t)},setupCubic:function(e){var t=e.getDefaultCubic();this.setup(e,t)},draw:function(e,t){e.reset(),e.drawSkeleton(t);var n=t.reduce();n.forEach(function(t){e.setRandomColor(),e.drawCurve(t),e.drawCircle(t.points[0],1)});var i=n.slice(-1)[0];e.drawPoint(i.points[3]||i.points[2]),e.setColor("red");var r=t.offset(e.distance);r.forEach(function(t){e.drawPoint(t.points[0]),e.drawCurve(t)}),i=r.slice(-1)[0],e.drawPoint(i.points[3]||i.points[2]),e.setColor("blue"),r=t.offset(-e.distance),r.forEach(function(t){e.drawPoint(t.points[0]),e.drawCurve(t)}),i=r.slice(-1)[0],e.drawPoint(i.points[3]||i.points[2])}}},function(e,t,n){"use strict";var i=n(85),r=n(0),a=n(2);e.exports=a(r("offsetting",i))},function(e,t,n){"use strict";var i=Math.abs;e.exports={setup:function(e){e.lpts=[{x:56,y:153},{x:144,y:83},{x:188,y:185}]},onClick:function(e,t){3==t.lpts.length&&(t.lpts=[]),t.lpts.push({x:e.offsetX,y:e.offsetY}),t.redraw()},getQRatio:function(e){var t=2*e,n=t*e-t,r=n+1;return i(n/r)},getCRatio:function(e){var t=1-e,n=e*e*e,r=t*t*t,a=n+r,s=a-1;return i(s/a)},drawQuadratic:function(e,t){var n=["start","t=0.5","end"];if(e.reset(),e.setColor("lightblue"),e.drawGrid(10,10),e.setFill("black"),e.setColor("black"),e.lpts.forEach(function(t,i){e.drawCircle(t,3),e.text(n[i],t,{x:5,y:2})}),3===e.lpts.length){var i=e.lpts[0],r=e.lpts[2],a=e.lpts[1],s={x:(i.x+r.x)/2,y:(i.y+r.y)/2};e.setColor("blue"),e.drawLine(i,r),e.drawLine(a,s),e.drawCircle(s,3);var o=this.getQRatio(.5),l={x:a.x+(a.x-s.x)/o,y:a.y+(a.y-s.y)/o};t=new e.Bezier([i,l,r]),e.setColor("lightgrey"),e.drawLine(l,a),e.drawLine(l,i),e.drawLine(l,r),e.setColor("black"),e.drawCircle(l,1),e.drawCurve(t)}},drawCubic:function(e,t){var n=["start","t=0.5","end"];if(e.reset(),e.setFill("black"),e.setColor("black"),e.lpts.forEach(function(t,i){e.drawCircle(t,3),e.text(n[i],t,{x:5,y:2})}),e.setColor("lightblue"),e.drawGrid(10,10),3===e.lpts.length){var i=e.lpts[0],r=e.lpts[2],a=e.lpts[1],s={x:(i.x+r.x)/2,y:(i.y+r.y)/2};e.setColor("blue"),e.drawLine(i,r),e.drawLine(a,s),e.drawCircle(s,1);var o=this.getCRatio(.5),l={x:a.x+(a.x-s.x)/o,y:a.y+(a.y-s.y)/o},c=e.utils.dist(i,r),h=c/8,u=e.utils.dist(a,s),d=4,f=h+u/d,m=f*(r.x-i.x)/c,p=f*(r.y-i.y)/c,g={x:a.x-m,y:a.y-p},v={x:a.x+m,y:a.y+p},w={x:l.x+2*(g.x-l.x),y:l.y+2*(g.y-l.y)},y={x:l.x+2*(v.x-l.x),y:l.y+2*(v.y-l.y)},b={x:i.x+2*(w.x-i.x),y:i.y+2*(w.y-i.y)},x={x:r.x+2*(y.x-r.x),y:r.y+2*(y.y-r.y)};t=new e.Bezier([i,b,x,r]),e.drawLine(g,v),e.setColor("lightgrey"),e.drawLine(l,s),e.drawLine(l,w),e.drawLine(l,y),e.drawLine(i,b),e.drawLine(r,x),e.drawLine(b,x),e.setColor("black"),e.drawCircle(l,1),e.drawCircle(b,1),e.drawCircle(x,1),e.drawCurve(t)}}}},function(e,t,n){"use strict";var i=n(87),r=n(0);e.exports=r("pointcurves",i)},function(e,t,n){"use strict";e.exports={setupQuadratic:function(e){var t=e.getDefaultQuadratic();e.setCurve(t)},setupCubic:function(e){var t=e.getDefaultCubic();e.setCurve(t)},draw:function(e,t){e.reset(),e.drawSkeleton(t);var n,i,r,a,s,o,l=20;for(n=0;n<=10;n++)i=n/10,r=t.get(i),a=t.derivative(i),o=Math.sqrt(a.x*a.x+a.y*a.y),a={x:a.x/o,y:a.y/o},s=t.normal(i),e.setColor("blue"),e.drawLine(r,{x:r.x+a.x*l,y:r.y+a.y*l}),e.setColor("red"),e.drawLine(r,{x:r.x+s.x*l,y:r.y+s.y*l}),e.setColor("black"),e.drawCircle(r,3)}}},function(e,t,n){"use strict";var i=n(89),r=n(0);e.exports=r("pointvectors",i)},function(e,t,n){"use strict";var i=Math.atan2,r=Math.sqrt,a=Math.sin,s=Math.cos;e.exports={setupQuadratic:function(e){var t=e.getPanelWidth(),n=e.getPanelHeight(),i=t/2,r=n/2,a=40,s=[{x:i,y:a},{x:t-a,y:a},{x:t-a,y:r},{x:t-a,y:n-a},{x:i,y:n-a},{x:a,y:n-a},{x:a,y:r},{x:a,y:a}];e.lpts=s},setupCubic:function(e){var t=e.getPanelWidth(),n=e.getPanelHeight(),i=t/2,r=n/2,a=40,s=(t-2*a)/2,o=.55228,l=o*s,c=[{x:i,y:a},{x:i+l,y:a},{x:t-a,y:r-l},{x:t-a,y:r},{x:t-a,y:r+l},{x:i+l,y:n-a},{x:i,y:n-a},{x:i-l,y:n-a},{x:a,y:r+l},{x:a,y:r},{x:a,y:r-l},{x:i-l,y:a}];e.lpts=c},movePointsQuadraticLD:function(e,t){for(var n,i,r,a=1;a<4;a++)n=t+(2*a-2)+e.lpts.length,n=e.lpts[n%e.lpts.length],i=t+(2*a-1),i=e.lpts[i%e.lpts.length],r=t+2*a,r=e.lpts[r%e.lpts.length],r.x=i.x+(i.x-n.x),r.y=i.y+(i.y-n.y);r=t+6,r=e.lpts[r%e.lpts.length],e.problem=r},movePointsCubicLD:function(e,t){var n,i;t%3===1?(i=t-1,i+=i<0?e.lpts.length:0,n=t-2,n+=n<0?e.lpts.length:0):(i=(t+1)%e.lpts.length,n=(t+2)%e.lpts.length),i=e.lpts[i],n=e.lpts[n],n.x=i.x+(i.x-e.mp.x),n.y=i.y+(i.y-e.mp.y)},linkDerivatives:function(e,t){if(t.mp){var n=8===t.lpts.length,i=t.mp_idx;n?i%2!==0&&this.movePointsQuadraticLD(t,i):i%3!==0&&this.movePointsCubicLD(t,i)}},movePointsQuadraticDirOnly:function(e,t){var n,o,l;[-1,1].forEach(function(c){n=e.mp,o=t+c+e.lpts.length,o=e.lpts[o%e.lpts.length],l=t+2*c+e.lpts.length,l=e.lpts[l%e.lpts.length];var h=i(o.y-n.y,o.x-n.x),u=l.x-o.x,d=l.y-o.y,f=r(u*u+d*d);l.x=o.x+f*s(h),l.y=o.y+f*a(h)}),l=t+4,l=e.lpts[l%e.lpts.length],e.problem=l},movePointsCubicDirOnly:function(e,t){var n,o;t%3===1?(o=t-1,o+=o<0?e.lpts.length:0,n=t-2,n+=n<0?e.lpts.length:0):(o=(t+1)%e.lpts.length,n=(t+2)%e.lpts.length),o=e.lpts[o],n=e.lpts[n];var l=i(o.y-e.mp.y,o.x-e.mp.x),c=n.x-o.x,h=n.y-o.y,u=r(c*c+h*h);n.x=o.x+u*s(l),n.y=o.y+u*a(l)},linkDirection:function(e,t){if(t.mp){var n=8===t.lpts.length,i=t.mp_idx;n?i%2!==0&&this.movePointsQuadraticDirOnly(t,i):i%3!==0&&this.movePointsCubicDirOnly(t,i)}},bufferPoints:function(e,t){t.bpts=JSON.parse(JSON.stringify(t.lpts))},moveQuadraticPoint:function(e,t){this.moveCubicPoint(e,t),[-1,1].forEach(function(n){var o=t-n+e.lpts.length;o=e.lpts[o%e.lpts.length];var l=t-2*n+e.lpts.length;l=e.lpts[l%e.lpts.length];var c=t-3*n+e.lpts.length;c=e.lpts[c%e.lpts.length];var h=i(l.y-o.y,l.x-o.x),u=c.x-l.x,d=c.y-l.y,f=r(u*u+d*d);c.x=l.x+f*s(h),c.y=l.y+f*a(h)});var n=t+4;n=e.lpts[n%e.lpts.length],e.problem=n},moveCubicPoint:function(e,t){var n=e.bpts[t],i=e.lpts[t],r=i.x-n.x,a=i.y-n.y,s=e.lpts.length,o=t-1+s,l=t+1,c=e.bpts[o%s],h=e.bpts[l%s],u=e.lpts[o%s],d=e.lpts[l%s];return u.x=c.x+r,u.y=c.y+a,d.x=h.x+r,d.y=h.y+a,{x:r,y:a}},modelCurve:function(e,t){if(t.mp){var n=8===t.lpts.length,i=t.mp_idx;n?i%2!==0?this.movePointsQuadraticDirOnly(t,i):this.moveQuadraticPoint(t,i):i%3!==0?this.movePointsCubicDirOnly(t,i):this.moveCubicPoint(t,i)}},draw:function(e,t){e.reset();var n=e.lpts,i=8===n.length,r=i?new e.Bezier(n[0],n[1],n[2]):new e.Bezier(n[0],n[1],n[2],n[3]);e.drawSkeleton(r,!1,!0),e.drawCurve(r);var a=i?new e.Bezier(n[2],n[3],n[4]):new e.Bezier(n[3],n[4],n[5],n[6]);e.drawSkeleton(a,!1,!0),e.drawCurve(a);var s=i?new e.Bezier(n[4],n[5],n[6]):new e.Bezier(n[6],n[7],n[8],n[9]);e.drawSkeleton(s,!1,!0),e.drawCurve(s);var o=i?new e.Bezier(n[6],n[7],n[0]):new e.Bezier(n[9],n[10],n[11],n[0]);e.drawSkeleton(o,!1,!0),e.drawCurve(o),e.problem&&(e.setColor("red"),e.drawCircle(e.problem,5))}}},function(e,t,n){"use strict";var i=n(91),r=n(0);e.exports=r("polybezier",i)},function(e,t,n){"use strict";var i=n(0);e.exports=i("preface")},function(e,t,n){"use strict";e.exports={setup:function(e){e.setSize(320,320);var t=new e.Bezier([{x:248,y:188},{x:218,y:294},{x:45,y:290},{x:12,y:236},{x:14,y:82},{x:186,y:177},{x:221,y:90},{x:18,y:156},{x:34,y:57},{x:198,y:18}]);e.setCurve(t),e._lut=t.getLUT()},findClosest:function(e,t,n){var i,r,a=e.length,s=n(e[0],t),o=0;for(i=1;i1;){for(var s=0;sf){i--;break}i<0&&(i=0),i===h.length&&(i=h.length-1),d.push(h[i])}for(n=0;n0;s-=e.step)a=s/100,a>1||(e.setRandomColor(),n={x:d.x+a*(f.x-d.x),y:d.y+a*(f.y-d.y)},i={x:f.x+a*(m.x-f.x),y:f.y+a*(m.y-f.y)},r={x:n.x+a*(i.x-n.x),y:n.y+a*(i.y-n.y)},p={x:0,y:0},e.drawCircle(n,3,p),e.drawCircle(i,3,p),e.setWeight(.5),e.drawLine(n,i,p),e.setWeight(1.5),e.drawLine(d,n,p),e.drawLine(f,i,p),e.setWeight(1),p.x+=h,e.drawCircle(n,3,p),e.drawCircle(i,3,p),e.setWeight(.5),e.drawLine(n,i,p),e.setWeight(1.5),e.drawLine(n,r,p),e.setWeight(1),e.drawCircle(r,3,p),p.x+=h,e.drawCircle(r,3,p),e.text(s+"%, or t = "+e.utils.round(a,2),{x:r.x+10+p.x,y:r.y+10+p.y}))},values:{38:1,40:-1},onKeyDown:function(e,t){var n=this.values[e.keyCode];n&&(e.preventDefault(),t.step+=n,t.step<1&&(t.step=1))}}},function(e,t,n){"use strict";var i=n(106),r=n(0);e.exports=r("whatis",i)},function(e,t,n){"use strict";var i=n(1),r=n(15),a=n(4),s=n(12),o=n(17),l=n(21);a.locale="en-GB",e.exports={locale:"en-GB",preface:{locale:"en-GB",title:"Preface",getContent:function(e){return i.createElement("section",null,i.createElement(a,{name:"preface",title:"Preface"}),i.createElement("p",null,"In order to draw things in 2D, we usually rely on lines, which typically get classified into two categories: straight lines, and curves. The first of these are as easy to draw as they are easy to make a computer draw. Give a computer the first and last point in the line, and BAM! straight line. No questions asked."),i.createElement("p",null,"Curves, however, are a much bigger problem. While we can draw curves with ridiculous ease freehand, computers are a bit handicapped in that they can't draw curves unless there is a mathematical function that describes how it should be drawn. In fact, they even need this for straight lines, but the function is ridiculously easy, so we tend to ignore that as far as computers are concerned, all lines are \"functions\", regardless of whether they're straight or curves. However, that does mean that we need to come up with fast-to-compute functions that lead to nice looking curves on a computer. There's a number of these, and in this article we'll focus on a particular function that has received quite a bit of attention, and is used in pretty much anything that can draw curves: \"Bézier\" curves"),i.createElement("p",null,"They're named after ",i.createElement("a",{href:"https://en.wikipedia.org/wiki/Pierre_B%C3%A9zier"},"Pierre Bézier"),', who is principally responsible for getting them known to the world as a curve well-suited for design work (working for Renault and publishing his investigations in 1962), although he was not the first, or only one, to "invent" these type of curves. One might be tempted to say that the mathematician ',i.createElement("a",{href:"https://en.wikipedia.org/wiki/Paul_de_Casteljau"},"Paul de Casteljau"),' was first, investigating the nature of these curves in 1959 while working at Citroën, coming up with a really elegant way of figuring out how to draw them. However, de Casteljau did not publish his work, making the question "who was first" hard to answer in any absolute sense. Or is it? Bézier curves are, at their core, "Bernstein polynomials", a family of mathematical functions investigated by ',i.createElement("a",{href:"https://en.wikipedia.org/wiki/Sergei_Natanovich_Bernstein"},"Sergei Natanovich Bernstein"),", with publications on them at least as far back as 1912. Anyway, that's mostly trivia, what you are more likely to care about is that these curves are handy: you can link up multiple Bézier curves so that the combination looks like a single curve. If you've ever drawn Photoshop \"paths\" or worked with vector drawing programs like Flash, Illustrator or nkscape, those curves you've been drawing are Bézier curves."),i.createElement("p",null,"So, what if you need to program them yourself? What are the pitfalls? How do you draw them? What are the bounding boxes, how do you determine intersections, how can you extrude a curve, in short: how do you do everything that you might want when you do with these curves? That's what this page is for. Prepare to be mathed!"),i.createElement("p",null,"—Pomax (or in the tweetworld, ",i.createElement("a",{href:"https://twitter.com/TheRealPomax"},"@TheRealPomax"),")"),i.createElement("div",{className:"note"},i.createElement("h2",{id:"note-virtually-all-b-zier-graphics-are-interactive-"},"Note: virtually all Bézier graphics are interactive."),i.createElement("p",null,"This page uses interactive examples, relying heavily on ",i.createElement("a",{href:"http://pomax.github.io/bezierjs"},"Bezier.js"),', as well as "real" maths (in LaTeX form) which is typeset using the most excellent ',i.createElement("a",{href:"http://MathJax.org"},"MathJax")," library. The page is generated offline as a React application, using Webpack, which has made adding \"view source\" options considerably more challenging. I'm still trying to figure out how to add them back in, but it didn't feel like it should hold up deploying this update compared to the previous years' version."),i.createElement("h2",{id:"this-book-is-open-source-"},"This book is open source."),i.createElement("p",null,"This book is an open source software project, and lives on two github repositorites. The first is ",i.createElement("a",{href:"https://github.com/pomax/bezierinfo"},"https://github.com/pomax/bezierinfo")," and is the purely-for-presentation version you are viewing right now. The other repository is ",i.createElement("a",{href:"https://github.com/pomax/BezierInfo-2"},"https://github.com/pomax/BezierInfo-2"),", which is the development version, housing all the html, javascript, and css. You can fork either of these, and pretty much do with them as you please, except for passing it off as your own work wholesale, of course =)"),i.createElement("h2",{id:"how-complicated-is-the-maths-going-to-be-"},"How complicated is the maths going to be?"),i.createElement("p",null,"Most of the mathematics in this Primer are early high school maths. If you understand basic arithmetic, and you know how to read English, you should be able to get by just fine. There will at times be ",i.createElement("em",null,"far"),' more complicated maths, but if you don\'t feel like digesting them, you can safely skip over them by either skipping over the "detail boxes" in section or by just jumping to the end of a section with maths that looks too involving. The end of sections typically simply list the conclusions so you can just work with those values directly.'),i.createElement("h2",{id:"questions-comments-"},"Questions, comments:"),i.createElement("p",null,"If you have suggestions for new sections, hit up the ",i.createElement("a",{href:"https://github.com/pomax/BezierInfo-2/issues"},"Github issue tracker")," (also reachable from the repo linked to in the upper right). If you have questions about the material, there's currently no comment section while I'm doing the rewrite, but you can use the issue tracker for that as well. Once the rewrite is done, I'll add a general comment section back in, and maybe a more topical \"select this section of text and hit the 'question' button to ask a question about it\" system. We'll see."),i.createElement("h2",{id:"buy-me-a-coffee-"},"Buy me a coffee?"),i.createElement("p",null,"If you enjoyed this book, or you simply found it useful for something you were trying to get done, and you were wondering how to let me know you appreciated this book, you can always ",i.createElement("a",{href:"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QPRDLNGDANJSW"},"buy me a coffee"),", however-much a coffee is where you live. This work has grown over the years, from a small primer to a 70ish print-page-equivalent reader on the subject of Bézier curves, and a lot of coffee went into the making of it. I don't regret a minute I spent on writing it, but I can always do with some more coffee to keep on writing!")))}},introduction:{locale:"en-GB",title:"A lightning introduction",getContent:function(e){return i.createElement("section",null,i.createElement(a,{name:"introduction",title:"A lightning introduction",number:"1"}),i.createElement("p",null,"Let's start with the good stuff: when we're talking about Bézier curves, we're talking about the things that you can see in the following graphics. They run from some start point to some end point, with their curvature influenced by one or more \"intermediate\" control points. Now, because all the graphics on this page are interactive, go manipulate those curves a bit: click-drag the points, and see how their shape changes based on what you do."),i.createElement("div",{className:"figure"},i.createElement(r,{inline:!0,title:"Quadratic Bézier curves",setup:e.drawQuadratic,draw:e.drawCurve}),i.createElement(r,{inline:!0,title:"Cubic Bézier curves",setup:e.drawCubic,draw:e.drawCurve})),i.createElement("p",null,"These curves are used a lot in computer aided design and computer aided manufacturing (CAD/CAM) applications, as well as in graphic design programs like Adobe Illustrator and Photoshop, Inkscape, the Gimp, etc. and in graphic technologies like scalable vector graphics (SVG) and OpenType fonts (ttf/otf). A lot of things use Bézier curves, so if you want to learn more about them... prepare to get your learn on!"))}},whatis:{locale:"en-GB",title:"So what makes a Bézier Curve?",getContent:function(e){return i.createElement("section",null,i.createElement(a,{name:"whatis",title:"So what makes a Bézier Curve?",number:"2"}),i.createElement("p",null,"Playing with the points for curves may have given you a feel for how Bézier curves behave, but what ",i.createElement("em",null,"are")," Bézier curves, really? There are two ways to explain what a Bézier curve is, and they turn out to be the entirely equivalent, but one of them uses complicated maths, and the other uses really simple maths. So... let's start with the simple explanation:"),i.createElement("p",null,"Bezier curves are the result of ",i.createElement("a",{href:"https://en.wikipedia.org/wiki/Linear_interpolation"},"linear interpolations"),". That sounds complicated but you've been doing linear interpolation since you were very young: any time you had to point at something between two other things, you've been applying linear interpolation. It's simply \"picking a point between two points\"."),i.createElement("p",null,"If we know the distance between those two points, and we want a new point that is, say, 20% the distance away from the first point (and thus 80% the distance away from the second point) then we can compute that really easily:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/8090904d6448ed0c8e6151aecf62f361d51ead96.svg",width:"526.4",height:"107.8"}),i.createElement("p",null,"So let's look at that in action: the following graphic is interactive in that you can use your up and down arrow keys to increase or decrease the interpolation ratio, to see what happens. We start with three points, which gives us two lines. Linear interpolation over those lines gives use two points, between which we can again perform linear interpolation, yielding a single point. And that point —and all points we can form in this way for all ratios taken together— form our Bézier curve:"),i.createElement(r,{title:"Linear Interpolation leading to Bézier curves",setup:e.setup,draw:e.draw,onKeyDown:e.onKeyDown}),i.createElement("p",null,"And that brings us to the complicated maths: calculus."),i.createElement("p",null,'While it doesn\'t look like that\'s what we\'ve just done, we actually just drew a quadratic curve, in steps, rather than in a single go. One of the fascinating parts about Bézier curves is that they can both be described in terms of polynomial functions, as well as in terms of very simple interpolations of interpolations of [...]. That, in turn, means we can look at what these curves can do based on both "real maths" (by examining the functions, their derivatives, and all that stuff), as well as by looking at the "mechanical" composition (which tells us that a curve will never extend beyond the points we used to construct it, for instance)'),i.createElement("p",null,"So let's start looking at Bézier curves a bit more in depth. Their mathematical expressions, the properties we can derive from those, and the various things we can do to, and with, Bézier curves."))}},explanation:{locale:"en-GB",title:"The mathematics of Bézier curves",getContent:function(e){return i.createElement("section",null,i.createElement(a,{name:"explanation",title:"The mathematics of Bézier curves",number:"3"}),i.createElement("p",null,'Bézier curves are a form of "parametric" function. Mathematically speaking, parametric functions are cheats: a "function" is actually a well defined term representing a mapping from any number of inputs to a ',i.createElement("strong",null,"single")," output. Numbers go in, a single number comes out. Change the numbers that go in, and the number that comes out is still a single number. Parametric functions cheat. They basically say \"alright, well, we want multiple values coming out, so we'll just use more than one function\". An illustration: Let's say we have a function that maps some value, let's call it ",i.createElement("i",null,"x"),", to some other value, using some kind of number manipulation:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/785e792c343b71d4e674ac94d8800940b30917ac.svg",width:"100.8",height:"18.2"}),i.createElement("p",null,"The notation ",i.createElement("i",null,"f(x)")," is the standard way to show that it's a function (by convention called ",i.createElement("i",null,"f")," if we're only listing one) and its output changes based on one variable (in this case, ",i.createElement("i",null,"x"),"). Change ",i.createElement("i",null,"x"),", and the output for ",i.createElement("i",null,"f(x)")," changes."),i.createElement("p",null,"So far so good. Now, let's look at parametric functions, and how they cheat. Let's take the following two functions:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/0dfe7562b43441e72201ff4cdd2e8b6e2e3ecb2d.svg",width:"98",height:"37.8"}),i.createElement("p",null,"There's nothing really remarkable about them, they're just a sine and cosine function, but you'll notice the inputs have different names. If we change the value for ",i.createElement("i",null,"a"),", we're not going to change the output value for ",i.createElement("i",null,"f(b)"),", since ",i.createElement("i",null,"a")," isn't used in that function. Parametric functions cheat by changing that. In a parametric function all the different functions share a variable, like this:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/ed6f533530199d1e99b3319ba137c1327b0459c0.svg",width:"105",height:"42"}),i.createElement("p",null,"Multiple functions, but only one variable. If we change the value for ",i.createElement("i",null,"t"),", we change the outcome of both ",i.createElement("i",null,"f",i.createElement("sub",null,"a"),"(t)")," and ",i.createElement("i",null,"f",i.createElement("sub",null,"b"),"(t)"),". You might wonder how that's useful, and the answer is actually pretty simple: if we change the labels ",i.createElement("i",null,"f",i.createElement("sub",null,"a"),"(t)")," and ",i.createElement("i",null,"f",i.createElement("sub",null,"b"),"(t)")," with what we usually mean with them for parametric curves, things might be a lot more obvious:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/ea632ea75d6a2aeb6fe69c07feb6e76f81884746.svg",width:"81.19999999999999",height:"42"}),i.createElement("p",null,"There we go. ",i.createElement("i",null,"x"),"/",i.createElement("i",null,"y")," coordinates, linked through some mystery value ",i.createElement("i",null,"t"),"."),i.createElement("p",null,"So, parametric curves don't define a ",i.createElement("i",null,"y")," coordinate in terms of an ",i.createElement("i",null,"x"),' coordinate, like normal functions do, but they instead link the values to a "control" variable. If we vary the value of ',i.createElement("i",null,"t"),", then with every change we get ",i.createElement("strong",null,"two")," values, which we can use as (",i.createElement("i",null,"x"),",",i.createElement("i",null,"y"),") coordinates in a graph. The above set of functions, for instance, generates points on a circle: We can range ",i.createElement("i",null,"t")," from negative to positive infinity, and the resulting (",i.createElement("i",null,"x"),",",i.createElement("i",null,"y"),") coordinates will always lie on a circle with radius 1 around the origin (0,0). If we plot it for ",i.createElement("i",null,"t")," from 0 to 5, we get this (use your up and down arrow keys to change the plot end value):"),i.createElement(r,{preset:"empty",title:"A (partial) circle: x=sin(t), y=cos(t)",static:!0,setup:e.setup,draw:e.draw,onKeyDown:e.props.onKeyDown}),i.createElement("p",null,"Bézier curves are (one in many classes of) parametric functions, and are characterised by using the same base function for all its dimensions. Unlike the above example, where the ",i.createElement("i",null,"x")," and ",i.createElement("i",null,"y"),' values use different functions (one uses a sine, the other a cosine), Bézier curves use the "binomial polynomial" for both ',i.createElement("i",null,"x")," and ",i.createElement("i",null,"y"),". So what are binomial polynomials?"),i.createElement("p",null,"You may remember polynomials from high school, where they're those sums that look like:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/3e8b26cf8833db7089d65e9c6b3953a3140bb19f.svg",width:"224",height:"21"}),i.createElement("p",null,"If they have a highest order term ",i.createElement("i",null,"x³")," they're called \"cubic\" polynomials, if it's ",i.createElement("i",null,"x²")," it's a \"square\" polynomial, if it's just ",i.createElement("i",null,"x")," it's a line (and if there aren't even any terms with ",i.createElement("i",null,"x")," it's not a polynomial!)"),i.createElement("p",null,"Bézier curves are polynomials of ",i.createElement("i",null,"t"),", rather than ",i.createElement("i",null,"x"),", with the value for ",i.createElement("i",null,"t")," fixed being between 0 and 1, with coefficients ",i.createElement("i",null,"a"),", ",i.createElement("i",null,"b"),' etc. taking the "binomial" form, which sounds fancy but is actually a pretty simple description for mixing values:'),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/565d935cab46bc995f53190102dadfdd1afc08f6.svg",width:"385",height:"68.6"}),i.createElement("p",null,"I know what you're thinking: that doesn't look too simple, but if we remove ",i.createElement("i",null,"t"),' and add in "times one", things suddenly look pretty easy. Check out these binomial terms:'),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/8c618738924e53a313a31fa407b3d91155525ee1.svg",width:"219.79999999999998",height:"91"}),i.createElement("p",null,'Notice that 2 is the same as 1+1, and 3 is 2+1 and 1+2, and 6 is 3+3... As you can see, each time we go up a dimension, we simply start and end with 1, and everything in between is just "the two numbers above it, added together". Now ',i.createElement("i",null,"that's")," easy to remember."),i.createElement("p",null,"There's an equally simple way to figure out how the polynomial terms work: if we rename ",i.createElement("i",null,"(1-t)")," to ",i.createElement("i",null,"a")," and ",i.createElement("i",null,"t")," to ",i.createElement("i",null,"b"),", and remove the weights for a moment, we get this:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/c8740a3a9a63b592e1480883a54024ebdaffaf05.svg",width:"316.4",height:"62.99999999999999"}),i.createElement("p",null,"It's basically just a sum of \"every combination of ",i.createElement("i",null,"a")," and ",i.createElement("i",null,"b"),'", progressively replacing ',i.createElement("i",null,"a"),"'s with ",i.createElement("i",null,"b"),"'s after every + sign. So that's actually pretty simple too. So now you know binomial polynomials, and just for completeness I'm going to show you the generic function for this:"),i.createElement("img",{className:"LaTeX SVG",src:"images/latex/444a01611e5709f702c36f6ca17aa2761c0877a9.svg",width:"315",height:"57.4"}),i.createElement("p",null,"And that's the full description for Bézier curves. Σ in this function indicates that this is a series of additions (using the variable listed below the Σ, starting at ...= and ending at the value listed on top of the Σ)."),i.createElement("div",{className:"howtocode"},i.createElement("h3",{id:"how-to-implement-the-basis-function"},"How to implement the basis function"),i.createElement("p",null,"We could naively implement the basis function as a mathematical construct, using the function as our guide, like this:"),i.createElement("pre",null,"function Bezier(n,t):\n sum = 0\n for(k=0; k= lut.length):\n s = lut.length\n nextRow = new array(size=s+1)\n nextRow[0] = 1\n for(i=1, prev=s-1; i