!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).Escher={})}(this,function(t){"use strict";function n(){this.events=[]}function r(t,i){this.x=t||0,this.y=i||0}function l(t){void 0!==t?this.m=t:this.identity()}function i(){}function p(){this.uuid=i.generate(),this.children=[],this.parent=null,this.level=0,this.position=new r(0,0),this.origin=new r(0,0),this.scale=new r(1,1),this.rotation=0,this.visible=!0,this.layer=0,this.matrix=new l,this.globalMatrix=new l,this.inverseGlobalMatrix=new l,this.masks=[],this.matrixNeedsUpdate=!0,this.draggable=!1,this.pointerEvents=!0,this.ignoreViewport=!1,this.saveContextState=!0,this.restoreContextState=!0,this.pointerInside=!1,this.beingDragged=!1}function h(){this.pressed=!1,this.justPressed=!1,this.justReleased=!1}function y(t,i){this._keys=new Array(5),this._position=new r(0,0),this._positionUpdated=!1,this._delta=new r(0,0),this._wheel=0,this._wheelUpdated=!1,this._doubleClicked=new Array(5),this.keys=new Array(5),this.position=new r(0,0),this.delta=new r(0,0),this.wheel=0,this.doubleClicked=new Array(5),this.domElement=void 0!==t?t:window,this.canvas=null,void 0!==i&&this.setCanvas(i),this.events=new n;for(var e=0;e<5;e++)this._doubleClicked[e]=!1,this.doubleClicked[e]=!1,this._keys[e]=new h,this.keys[e]=new h;var o=this;if(void 0!==window.onmousewheel?this.events.add(this.domElement,"mousewheel",function(t){o._wheel=t.deltaY,o._wheelUpdated=!0}):void 0!==window.addEventListener?this.events.add(this.domElement,"DOMMouseScroll",function(t){o._wheel=30*t.detail,o._wheelUpdated=!0}):this.events.add(this.domElement,"wheel",function(t){o._wheel=t.deltaY,o._wheelUpdated=!0}),void 0!==window.ontouchstart||0>8&255]+s[t>>16&255]+s[t>>24&255]+"-"+s[255&i]+s[i>>8&255]+"-"+s[i>>16&15|64]+s[i>>24&255]+"-"+s[63&e|128]+s[e>>8&255]+"-"+s[e>>16&255]+s[e>>24&255]+s[255&o]+s[o>>8&255]+s[o>>16&255]+s[o>>24&255]).toUpperCase()}}(),p.prototype.traverse=function(t){t(this);for(var i=this.children,e=0;ethis.max.x||t.ythis.max.y)},s.prototype.containsBox=function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y},s.prototype.intersectsBox=function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)},s.prototype.distanceToPoint=function(t){return(new r).copy(t).clamp(this.min,this.max).sub(t).length()},s.prototype.intersect=function(t){this.min.max(t.min),this.max.min(t.max)},s.prototype.union=function(t){this.min.min(t.min),this.max.max(t.max)},s.prototype.translate=function(t){this.min.add(t),this.max.add(t)},s.prototype.equals=function(t){return t.min.equals(this.min)&&t.max.equals(this.max)},(m.prototype=Object.create(p.prototype)).isMask=!0,m.prototype.clip=function(t,i,e){},(u.prototype=Object.create(m.prototype)).isInside=function(t){return this.box.containsPoint(t)},u.prototype.clip=function(t,i,e){t.beginPath();var o=this.box.max.x-this.box.min.x;if(this.invert)t.rect(this.box.min.x-1e4,-5e3,1e4,1e4),t.rect(this.box.max.x,-5e3,1e4,1e4),t.rect(this.box.min.x,this.box.min.y-1e4,o,1e4),t.rect(this.box.min.x,this.box.max.y,o,1e4);else{var s=this.box.max.y-this.box.min.y;t.fillRect(this.box.min.x,this.box.min.y,o,s)}t.clip()},(c.prototype=Object.create(p.prototype)).isInside=function(t){return t.length()<=this.radius},c.prototype.onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},c.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},c.prototype.draw=function(t,i,e){t.beginPath(),t.arc(0,0,this.radius,0,2*Math.PI),null!==this.fillStyle&&(t.fillStyle=this.fillStyle,t.fill()),null!==this.strokeStyle&&(t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.stroke())},d.rotateTool=function(o){var t=new c;t.radius=4,t.layer=o.layer+1,t.onPointerDrag=function(t,i,e){o.rotation+=.001*e.x},o.add(t)},d.boxResizeTool=function(o){if(void 0!==o.box){var s=new c;s.radius=4,s.layer=o.layer+1,s.draggable=!0,s.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.copy(s.position),a()},o.add(s);var n=new c;n.radius=4,n.layer=o.layer+1,n.draggable=!0,n.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.x=n.position.x,o.box.min.y=n.position.y,a()},o.add(n);var r=new c;r.radius=4,r.layer=o.layer+1,r.draggable=!0,r.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.max.copy(r.position),a()},o.add(r);var h=new c;h.radius=4,h.layer=o.layer+1,h.draggable=!0,h.onPointerDrag=function(t,i,e){p.prototype.onPointerDrag.call(this,t,i,e),o.box.min.x=h.position.x,o.box.max.y=h.position.y,a()},o.add(h),a()}else console.warn("escher.js: Helpers.boxResizeTool(), object box property missing.");function a(){s.position.copy(o.box.min),r.position.copy(o.box.max),n.position.set(o.box.max.x,o.box.min.y),h.position.set(o.box.min.x,o.box.max.y)}},(x.prototype=Object.create(p.prototype)).onPointerEnter=function(t,i){this.fillStyle="#CCCCCC"},x.prototype.onPointerLeave=function(t,i){this.fillStyle="#FFFFFF"},x.prototype.isInside=function(t){return this.box.containsPoint(t)},x.prototype.draw=function(t,i,e){var o=this.box.max.x-this.box.min.x,s=this.box.max.y-this.box.min.y;null!==this.fillStyle&&(t.fillStyle=this.fillStyle,t.fillRect(this.box.min.x,this.box.min.y,o,s)),null!==this.strokeStyle&&(t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.strokeRect(this.box.min.x,this.box.min.y,o,s))},(f.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle,t.setLineDash(this.dashPattern),t.beginPath(),t.moveTo(this.from.x,this.from.y),t.lineTo(this.to.x,this.to.y),t.stroke()},(v.prototype=Object.create(p.prototype)).draw=function(t,i,e){t.font=this.font,t.textAlign=this.textAlign,t.textBaseline="middle",null!==this.fillStyle&&(t.fillStyle=this.fillStyle,t.fillText(this.text,0,0)),null!==this.strokeStyle&&(t.strokeStyle=this.strokeStyle,t.strokeText(this.text,0,0))},(b.prototype=Object.create(p.prototype)).setImage=function(t){var i=this;this.image.onload=function(){i.box.min.set(0,0),i.box.max.set(this.naturalWidth,this.naturalHeight)},this.image.src=t},b.prototype.isInside=function(t){return this.box.containsPoint(t)},b.prototype.draw=function(t,i,e){0