!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis: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 h(t){void 0!==t?this.m=t:this.identity()}function O(){}function l(){this.uuid=O.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 h,this.globalMatrix=new h,this.inverseGlobalMatrix=new h,this.masks=[],this.matrixAutoUpdate=!0,this.matrixNeedsUpdate=!0,this.draggable=!1,this.pointerEvents=!0,this.ignoreViewport=!1,this.saveContextState=!0,this.restoreContextState=!0,this.pointerInside=!1,this.beingDragged=!1,this.serializable=!0}function a(){this.pressed=!1,this.justPressed=!1,this.justReleased=!1}function d(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 a,this.keys[e]=new a;var o,s=this;void 0!==window.onmousewheel?this.events.add(this.domElement,"mousewheel",function(t){s._wheel=t.deltaY,s._wheelUpdated=!0}):void 0!==window.addEventListener?this.events.add(this.domElement,"DOMMouseScroll",function(t){s._wheel=30*t.detail,s._wheelUpdated=!0}):this.events.add(this.domElement,"wheel",function(t){s._wheel=t.deltaY,s._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()}}(),(l.prototype.constructor=l).prototype.type="Object2D",l.types=new Map([[l.prototype.type,l]]),l.register=function(t,i){l.types.set(i,t)},l.prototype.getWorldPointIntersections=function(t,i){void 0===i&&(i=[]);var e=this.inverseGlobalMatrix.transformPoint(t);this.isInside(e)&&i.push(this);for(var o=0;othis.max.x||t.ythis.max.y)},i.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},i.prototype.intersectsBox=function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)},i.prototype.distanceToPoint=function(t){return(new r).copy(t).clamp(this.min,this.max).sub(t).length()},i.prototype.intersect=function(t){this.min.max(t.min),this.max.min(t.max)},i.prototype.union=function(t){this.min.min(t.min),this.max.max(t.max)},i.prototype.translate=function(t){this.min.add(t),this.max.add(t)},i.prototype.equals=function(t){return t.min.equals(this.min)&&t.max.equals(this.max)},i.prototype.toArray=function(){return[this.min.x,this.min.y,this.max.x,this.max.y]},i.prototype.fromArray=function(t){this.min.set(t[0],t[1]),this.max.set(t[2],t[3])},((e.prototype=Object.create(l.prototype)).constructor=e).prototype.type="Mask",l.register(e,"Mask"),e.prototype.isMask=!0,e.prototype.clip=function(t,i,e){},((o.prototype=Object.create(e.prototype)).constructor=o).prototype.type="BoxMask",l.register(o,"BoxMask"),o.prototype.isInside=function(t){return this.box.containsPoint(t)},o.prototype.clip=function(t,i,e){t.beginPath();var o,s=this.box.max.x-this.box.min.x;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,s,1e4),t.rect(this.box.min.x,this.box.max.y,s,1e4)):(o=this.box.max.y-this.box.min.y,t.fillRect(this.box.min.x,this.box.min.y,s,o)),t.clip()},s.prototype.get=function(t){},s.prototype.serialize=function(){},s.prototype.parse=function(t){},s.types=new Map([]),s.register=function(t,i){s.types.set(i,t)},s.parse=function(t){var i=new(s.types.get(t.type));return i.parse(t),i},c.prototype=Object.create(s.prototype),s.register(c,"Color"),c.prototype.get=function(t){return this.color},c.prototype.serialize=function(){return{type:"Color",color:this.color}},c.prototype.parse=function(t){this.color=t.color},((u.prototype=Object.create(l.prototype)).constructor=u).prototype.type="Box",l.register(u,"Box"),u.prototype.isInside=function(t){return this.box.containsPoint(t)},u.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.get(t),t.fillRect(this.box.min.x,this.box.min.y,o,s)),null!==this.strokeStyle&&(t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle.get(t),t.strokeRect(this.box.min.x,this.box.min.y,o,s))},u.prototype.serialize=function(t){t=l.prototype.serialize.call(this,t);return t.box=this.box.toArray(),t.strokeStyle=null!==this.strokeStyle?this.strokeStyle.serialize():null,t.lineWidth=this.lineWidth,t.fillStyle=null!==this.fillStyle?this.fillStyle.serialize():null,t},u.prototype.parse=function(t,i){l.prototype.parse.call(this,t,i),this.box.fromArray(t.box),this.strokeStyle=null!==t.strokeStyle?s.parse(t.strokeStyle):null,this.lineWidth=t.lineWidth,this.fillStyle=null!==t.fillStyle?s.parse(t.fillStyle):null},((y.prototype=Object.create(l.prototype)).constructor=y).prototype.type="Circle",l.register(y,"Circle"),y.prototype.isInside=function(t){return t.length()<=this.radius},y.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.get(t),t.fill()),null!==this.strokeStyle&&(t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle.get(t),t.stroke())},y.prototype.serialize=function(t){t=l.prototype.serialize.call(this,t);return t.radius=this.radius,t.strokeStyle=null!==this.strokeStyle?this.strokeStyle.serialize():null,t.lineWidth=this.lineWidth,t.fillStyle=null!==this.fillStyle?this.fillStyle.serialize():null,t},y.prototype.parse=function(t,i){l.prototype.parse.call(this,t,i),this.radius=t.radius,this.strokeStyle=null!==t.strokeStyle?s.parse(t.strokeStyle):null,this.lineWidth=t.lineWidth,this.fillStyle=null!==t.fillStyle?s.parse(t.fillStyle):null},((m.prototype=Object.create(l.prototype)).constructor=m).prototype.type="Line",l.register(m,"Line"),m.prototype.style=function(t,i,e){t.lineWidth=this.lineWidth,t.strokeStyle=this.strokeStyle.get(t),t.setLineDash(this.dashPattern)},m.prototype.draw=function(t,i,e){t.beginPath(),t.moveTo(this.from.x,this.from.y),t.lineTo(this.to.x,this.to.y),t.stroke()},m.prototype.serialize=function(t){t=l.prototype.serialize.call(this,t);return t.from=this.from.toArray(),t.to=this.to.toArray(),t.dashPattern=this.dashPattern,t.strokeStyle=null!==this.strokeStyle?this.strokeStyle.serialize():null,t.lineWidth=this.lineWidth,t},m.prototype.parse=function(t,i){l.prototype.parse.call(this,t,i),this.to.fromArray(t.to),this.from.fromArray(t.from),this.dashPattern=t.dashPattern,this.strokeStyle=null!==t.strokeStyle?s.parse(t.strokeStyle):null,this.lineWidth=t.lineWidth},((f.prototype=Object.create(l.prototype)).constructor=f).prototype.type="Text",l.register(f,"Text"),f.prototype.draw=function(t,i,e){t.font=this.font,t.textAlign=this.textAlign,t.textBaseline=this.textBaseline,null!==this.fillStyle&&(t.fillStyle=this.fillStyle.get(t),t.fillText(this.text,0,0)),null!==this.strokeStyle&&(t.strokeStyle=this.strokeStyle.get(t),t.strokeText(this.text,0,0))},f.prototype.serialize=function(t){t=l.prototype.serialize.call(this,t);return t.text=this.text,t.font=this.font,t.strokeStyle=null!==this.strokeStyle?this.strokeStyle.serialize():null,t.lineWidth=this.lineWidth,t.fillStyle=null!==this.fillStyle?this.fillStyle.serialize():null,t.textAlign=this.textAlign,t.textBaseline=this.textBaseline,t},f.prototype.parse=function(t,i){l.prototype.parse.call(this,t,i),this.text=t.text,this.font=t.font,this.strokeStyle=null!==t.strokeStyle?Style.parse(t.strokeStyle):null,this.lineWidth=t.lineWidth,this.fillStyle=null!==t.fillStyle?Style.parse(t.fillStyle):null,this.textAlign=t.textAlign,this.textBaseline=t.textBaseline},((x.prototype=Object.create(l.prototype)).constructor=x).prototype.type="Image",l.register(x,"Image"),x.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},x.prototype.isInside=function(t){return this.box.containsPoint(t)},x.prototype.draw=function(t,i,e){0this.maxWidth)for(;0e&&(e=this.data[o].value);t.lineWidth=this.lineWidth;for(var s=this.endAngle-this.startAngle,n=this.startAngle,o=0;oi&&(i=this.children[o].position.x),this.children[o].position.y>e&&(e=this.children[o].position.y);return t.position.set(i+200,e/2),this.add(t),null!==t.registerSockets&&t.registerSockets(),t},((R.prototype=Object.create(S.prototype)).constructor=R).prototype.type="NodeConnector",l.register(R,"NodeConnector"),R.prototype.destroy=function(){S.prototype.destroy.call(this),null!==this.outputSocket&&(this.outputSocket.removeConnector(this),this.outputSocket=null),null!==this.inputSocket&&(this.inputSocket.removeConnector(this),this.inputSocket=null)},R.prototype.onUpdate=function(){null!==this.outputSocket&&this.from.copy(this.outputSocket.position),null!==this.inputSocket&&this.to.copy(this.inputSocket.position),this.fromCp.copy(this.from),this.fromCp.add(this.to),this.fromCp.multiplyScalar(.5),this.toCp.copy(this.fromCp);var t=this.to.y-this.from.y,i=this.to.x-this.from.x;Math.abs(i)>Math.abs(t)?(this.toCp.x+=.5*i,this.fromCp.x-=.5*i):(this.toCp.y+=.5*t,this.fromCp.y-=.5*t)},R.prototype.serialize=function(t){t=S.prototype.serialize.call(this,t);return t.outputSocket=null!==this.outputSocket?this.outputSocket.uuid:null,t.inputSocket=null!==this.inputSocket?this.inputSocket.uuid:null,t},R.prototype.parse=function(t,i){S.prototype.parse.call(this,t,i),null!==t.outputSocket&&(this.outputSocket=i.getChildByUUID(t.outputSocket)),null!==t.inputSocket&&(this.inputSocket=i.getChildByUUID(t.inputSocket))},((I.prototype=Object.create(y.prototype)).constructor=I).prototype.type="NodeSocket",l.register(I,"NodeSocket"),I.INPUT=1,I.OUTPUT=2,I.prototype.getValue=function(){return this.direction===I.INPUT&&0