vara=i[r],o=a._matrix;n[a._id]||a._drawSelected(t,o.isIdentity()?e:e.chain(o))}}},newfunction(){functiont(t,e){varn=t._children;if(e&&0===n.length)throwError("Use a moveTo() command first");returnn[n.length-1]}varn={moveTo:function(){vare=t(this),n=e&&e.isEmpty()?e:newO(m.NO_INSERT);n!==e&&this.addChild(n),n.moveTo.apply(n,arguments)},moveBy:function(){vare=t(this,!0),n=e&&e.getLastSegment(),i=h.read(arguments);this.moveTo(n?i.add(n._point):i)},closePath:function(e){t(this,!0).closePath(e)}};returne.each(["lineTo","cubicCurveTo","quadraticCurveTo","curveTo","arcTo","lineBy","cubicCurveBy","quadraticCurveBy","curveBy","arcBy"],function(e){n[e]=function(){varn=t(this,!0);n[e].apply(n,arguments)}}),n});k.inject(newfunction(){functione(t,e){varn=t.clone(!1).reduce().transform(null,!0,!0);returne?n.resolveCrossings().reorient():n}functionn(t,e,n,i,r){vars=newt(m.NO_INSERT);returns.addChildren(e,!0),r&&(s=s.reduce()),s.insertAbove(i&&n.isSibling(i)&&n.getIndex()<i.getIndex()?i:n),s.setStyle(n._style),s}functioni(t,i,s){functiona(t){for(vare=0,n=t.length;n>e;e++){vari=t[e];_.push.apply(_,i._segments),f.push.apply(f,i._getMonoCurves())}}if(!t._children&&!t._closed)returnr(t,i,s);varh=e(t,!0),u=i&&t!==i&&e(i,!0);u&&/^(subtract|exclude)$/.test(s)^u.isClockwise()!==h.isClockwise()&&u.reverse();vard=z.expand(h.getIntersections(u,function(t){returnu&&t.isOverlap()||t.isCrossing()}));o(d);var_=[],f=[];a(h._children||[h]),u&&a(u._children||[u]);for(varg=0,v=d.length;v>g;g++)l(d[g]._segment,h,u,f,s);for(varg=0,v=_.length;v>g;g++){varp=_[g];null==p._winding&&l(p,h,u,f,s)}returnn(A,c(_,s),t,i,!0)}functionr(i,r,s){functiona(e){returnh.contains(e.getPointAt(e.getLength()/2))^l?(c.unshift(e),!0):t}if(!r||!r._children&&!r._closed||!/^(subtract|intersect)$/.test(s))returnnull;for(varo=e(i,!1),h=e(r,!1),u=o.getIntersections(h,function(t){returnt.isOverlap()||t.isCrossing()}),l="subtract"===s,c=[],d=u.length-1;d>=0;d--){var_=u[d].split();_&&(a(_)&&_.getFirstSegment().setHandleIn(0,0),o.getLastSegment().setHandleOut(0,0))}returna(o),n(y,c,i,r)}functions(t,e){for(varn=t;n;){if(n===e)return;n=n._prev}for(;t._next&&t._next!==e;)t=t._next;if(!t._next){for(;e._prev;)e=e._prev;t._next=e,e._prev=t}}functiono(t){for(vare,n,i=4e-7,r=1-i,a=!1,o=[],h=t.length-1;h>=0;h--){varu=t[h],l=u._curve,c=u._parameter,d=c;l!==e?a=!l.hasHandles():n>0&&(c/=n);var_;i>c?_=l._segment1:c>r?_=l._segment2:(_=l.divide(c,!0,!0)._segment1,a&&o.push(_)),u._setSegment(_);varf=_._intersection,g=u._intersection;if(f){s(f,g);for(varv=f;v;)s(v._intersection,f),v=v._next}else_._intersection=g;e=l,n=d}for(varh=0,p=o.length;p>h;h++)o[h].clearHandles()}functionu(t,e,n,i){varr=2e-7,s=4e-7,o=1-s,l=t.x,c=t.y,d=0,_=0,f=[],g=Math.abs;if(n){for(varv=-(1/0),p=1/0,m=c-r,y=c+r,w=0,x=e.length;x>w;w++){varb=e[w].values;if(I.solveCubic(b,0,l,f,0,1)>0)for(varC=f.length-1;C>=0;C--){varS=I.getPoint(b,f[C]).y;m>S&&S>v?v=S:S>y&&p>S&&(p=S)}}v=(v+c)/2,p=(p+c)/2,v>-(1/0)&&(d=u(newh(l,v),e,!1,i)),1/0>p&&(_=u(newh(l,p),e,!1,i))}elsefor(varP,M,z=l-r,k=l+r,O=!1,w=0,x=e.length;x>w;w++){varA=e[w],b=A.values,T=A.winding;if(T&&(1===T&&c>=b[1]&&c<=b[7]||c>=b[7]&&c<=b[1])&&1===I.solveCubic(b,1,c,f,0,1)){varN=f[0];if(!(N>o&&O&&A.next!==e[w+1]||s>N&&M>o&&A.previous===P)){varL=I.getPoint(b,N).x,E=I.getTangent(b,N).y,B=!1;a.isZero(E)&&!I.isStraight(b)||s>N&&E*I.getTangent(A.previous.values,1).y<0||N>o&&E*I.getTangent(A.next.values,0).y<0?i&&L>=z&&k>=L&&(++d,++_,B=!0):z>=L?(d+=T,B=!0):L>=k&&(_+=T,B=!0),A.previous!==e[w-1]&&(O=s>N&&B)}P=A,M=N}}returnMath.max(g(d),g(_))}functionl(t,e,n,i,r){vars=2e-7,a=[],o=t,h=0,l=0;do{varc=t.getCurve(),d=c.getLength();a.push({segment:t,curve:c,length:d}),h+=d,t=t.getNext()}while(t&&!t._intersection&&t!==o);for(var_=0;3>_;_++)for(vard=h*(_+1)/4,f=0,g=a.length;g>f;f++){varv=a[f],p=v.length;if(p>=d){(s>d||s>p-d)&&(d=p/2);varc=v.curve,m=c._path,y=m._parent,w=c.getPointAt(d),x=c.isHorizontal();yinstanceofA&&(m=y),l+="subtract"===r&&n&&(m===e&&n._getWinding(w,x)||m===n&&!e._getWinding(w,x))?0:u(w,i,x);break}d-=p}for(varb=
this._transform((newf).translate(h.read(arguments).negate()))},play:function(){this._animate=!0,this._requested||this._requestFrame()},pause:function(){this._animate=!1},draw:function(){this.update()},projectToView:function(){returnthis._matrix._transformPoint(h.read(arguments))},viewToProject:function(){returnthis._matrix._inverseTransform(h.read(arguments))}},{statics:{_views:[],_viewsById:{},_id:0,create:function(t,e){return"string"==typeofe&&(e=document.getElementById(e)),newH(t,e)}}},newfunction(){functiont(t){vare=q.getTarget(t);returne.getAttribute&&V._viewsById[e.getAttribute("id")]}functione(t,e){returnt.viewToProject(q.getOffset(e,t._element))}functionn(){if(!V._focused||!V._focused.isVisible())for(vart=0,e=V._views.length;e>t;t++){varn=V._views[t];if(n&&n.isVisible()){V._focused=a=n;break}}}functioni(t,e,n){t._handleEvent("mousemove",e,n);vari=t._scope.tool;returni&&i._handleEvent(l&&i.responds("mousedrag")?"mousedrag":"mousemove",e,n),t.update(),i}varr,s,a,o,h,u,l=!1,c=window.navigator;c.pointerEnabled||c.msPointerEnabled?(o="pointerdown MSPointerDown",h="pointermove MSPointerMove",u="pointerup pointercancel MSPointerUp MSPointerCancel"):(o="touchstart",h="touchmove",u="touchend touchcancel","ontouchstart"inwindow&&c.userAgent.match(/mobile|tablet|ip(ad|hone|od)|android|silk/i)||(o+=" mousedown",h+=" mousemove",u+=" mouseup"));vard={"selectstart dragstart":function(t){l&&t.preventDefault()}},_={mouseout:function(t){varn=V._focused,r=q.getRelatedTarget(t);!n||r&&"HTML"!==r.nodeName||i(n,e(n,t),t)},scroll:n};d[o]=function(n){vari=V._focused=t(n),s=e(i,n);l=!0,i._handleEvent("mousedown",s,n),(r=i._scope.tool)&&r._handleEvent("mousedown",s,n),i.update()},_[h]=function(o){varh=V._focused;if(!l){varu=t(o);u?(h!==u&&i(h,e(h,o),o),s=h,h=V._focused=a=u):a&&a===h&&(h=V._focused=s,n())}if(h){varc=e(h,o);(l||h.getBounds().contains(c))&&(r=i(h,c,o))}},_[u]=function(t){varn=V._focused;if(n&&l){vari=e(n,t);l=!1,n._handleEvent("mouseup",i,t),r&&r._handleEvent("mouseup",i,t),n.update()}},q.add(document,_),q.add(window,{load:n});varf={mousedown:{mousedown:1,mousedrag:1,click:1,doubleclick:1},mouseup:{mouseup:1,mousedrag:1,click:1,doubleclick:1},mousemove:{mousedrag:1,mousemove:1,mouseenter:1,mouseleave:1}};return{_viewEvents:d,_handleEvent:function(){},_installEvent:function(t){vare=this._eventCounters;if(e)for(varninf)e[n]=(e[n]||0)+(f[n][t]||0)},_uninstallEvent:function(t){vare=this._eventCounters;if(e)for(varninf)e[n]-=f[n][t]||0},statics:{updateFocus:n}}}),H=V.extend({_class:"CanvasView",initialize:function(t,e){if(!(einstanceofHTMLCanvasElement)){varn=l.read(arguments,1);if(n.isZero())throwError("Cannot create CanvasView with the provided argument: "+[].slice.call(arguments,1));e=Y.getCanvas(n)}if(this._context=e.getContext("2d"),this._eventCounters={},this._pixelRatio=1,!/^off|false$/.test(i.getAttribute(e,"hidpi"))){varr=window.devicePixelRatio||1,s=F.getPrefixed(this._context,"backingStorePixelRatio")||1;this._pixelRatio=r/s}V.call(this,t,e)},_setViewSize:function(t){vare=this._element,n=this._pixelRatio,r=t.width,s=t.height;if(e.width=r*n,e.height=s*n,1!==n){if(!i.hasAttribute(e,"resize")){vara=e.style;a.width=r+"px",a.height=s+"px"}this._context.scale(n,n)}},getPixelSize:function(t){vare,n=paper.browser;if(n&&n.firefox){vari=this._element.parentNode,r=document.createElement("div");r.style.fontSize=t,i.appendChild(r),e=parseFloat(F.getStyles(r).fontSize),i.removeChild(r)}else{vars=this._context,a=s.font;s.font=t+" serif",e=parseFloat(s.font),s.font=a}returne},getTextWidth:function(t,e){varn=this._context,i=n.font,r=0;n.font=t;for(vars=0,a=e.length;a>s;s++)r=Math.max(r,n.measureText(e[s]).width);returnn.font=i,r},update:function(t){vare=this._project;if(!e||!t&&!e._needsUpdate)return!1;varn=this._context,i=this._viewSize;returnn.clearRect(0,0,i.width+1,i.height+1),e.draw(n,this._matrix,this._pixelRatio),e._needsUpdate=!1,!0}},newfunction(){functione(e,n,i,r,s,a){functiono(e){returne.responds(n)&&(h||(h=newU(n,i,r,s,a?r.subtract(a):null)),e.emit(n,h)&&h.isStoppe