var PortrayCanvas=function(t){var e={};function i(s){if(e[s])return e[s].exports;var n=e[s]={i:s,l:!1,exports:{}};return t[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:s})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";var s=i(1),n=i(2);t.exports=class{constructor(t,e){if(t.hasOwnProperty("length")&&(t=t[0]),"canvas"!==t.tagName.toLowerCase())throw new Error("Element is not a canvas.");this.canvas=t,this.context=this.canvas.getContext("2d"),this.started=!1,this.context.lineJoin="round",this.context.lineCap="round",this.memCanvas=document.createElement("canvas"),this.memCanvas.width=this.canvas.width,this.memCanvas.height=this.canvas.height,this.memCtx=this.memCanvas.getContext("2d"),this.undoHistory=[],this.renderer=new n(this.canvas),this.init(),this.setOptions(e),this.canvas.addEventListener("mousedown",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("mousemove",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("mouseup",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("mouseout",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("touchstart",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("touchend",this.eventCanvas.bind(this),!1),this.canvas.addEventListener("touchmove",this.eventCanvas.bind(this),!1)}drawLine(t){var e;0==this.lines.length?(e=0,this.firstTimestamp=(new Date).getTime()):e=(new Date).getTime()-this.firstTimestamp,t.map(t=>t.timestamp=e++),this.tempLine=t,this.renderer.drawPoints(this.context,t),this.lineFinish()}setOptions(t){this.context.strokeStyle=s.rgb2hex(s.getStyleProp(this.canvas,"color")),this.context.lineWidth=5,this.period=5,this.onLineFinish=null,this.onClear=null,this.onUndo=null,"object"==typeof t&&null!=t&&("string"==typeof t.color&&(this.context.strokeStyle=t.color),"number"==typeof t.lineWidth&&(this.context.lineWidth=t.lineWidth),"number"==typeof t.period&&(this.period=t.period),"function"==typeof t.onLineFinish&&(this.onLineFinish=t.onLineFinish),"function"==typeof t.onClear&&(this.onClear=t.onClear),"function"==typeof t.onUndo&&(this.onUndo=t.onUndo),this.colorDefault=this.context.strokeStyle)}setColor(t){this.context.strokeStyle=t}revertDefaultColor(){this.context.strokeStyle=this.colorDefault}isEmpty(){return 0==this.lines.length}getLines(){return this.lines}undo(){if(this.undoHistory.pop(),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.memCtx.clearRect(0,0,this.canvas.width,this.canvas.height),this.undoHistory.length>0){var t=this.undoHistory[this.undoHistory.length-1];this.context.drawImage(t,0,0),this.memCtx.drawImage(t,0,0)}let e=this.lines.pop();null!=this.onUndo&&this.onUndo(e,this)}init(){this.points=[],this.count=0,this.tempLine=[],this.lines=[],this.firstTimestamp=-1}eventCanvas(t){let e={};if(this.totalWidth=this.canvas.offsetWidth-this.borderHorizontal(),this.totalHeight=this.canvas.offsetHeight-this.borderVertical(),"t"===t.type.charAt(0)){var i=t.touches[0];if(void 0===i)e=this.currPoint;else{var s=this.canvas.getBoundingClientRect();e.x=(i.clientX-s.left)/this.totalWidth,e.y=(i.clientY-s.top)/this.totalHeight}}else e.x=t.offsetX/this.totalWidth,e.y=t.offsetY/this.totalHeight;switch(this.currPoint=e,t.type){case"mousedown":this.eventStart(e);break;case"mousemove":this.eventMove(e);break;case"mouseup":this.eventEnd(e);break;case"touchstart":this.eventStart(e);break;case"touchmove":this.eventMove(e);break;case"touchend":this.eventEnd(e)}}borderHorizontal(){return this.borderWidth("left")+this.borderWidth("right")}borderVertical(){return this.borderWidth("top")+this.borderWidth("bottom")}borderWidth(t){return+(s.getStyleProp(this.canvas,"border-"+t+"-width")||"").replace("px","")}addDotToTempLine(t){let e=0;0==this.tempLine.length&&0==this.lines.length?(e=0,this.firstTimestamp=(new Date).getTime()):e=(new Date).getTime()-this.firstTimestamp,t.timestamp=e,this.tempLine.push(t)}lineFinish(){var t=document.createElement("canvas");t.width=this.canvas.width,t.height=this.canvas.height,t.getContext("2d").drawImage(this.canvas,0,0),this.undoHistory.push(t),this.lines.push(this.tempLine),this.tempLine=[],null!=this.onLineFinish&&this.onLineFinish(this)}eventStart(t){this.count=0,this.addDotToTempLine(t),this.renderer.drawDot(this.context,t.x,t.y),this.memCtx.clearRect(0,0,this.canvas.width,this.canvas.height),this.memCtx.drawImage(this.canvas,0,0),this.points.push(t),this.started=!0,this.renderer.drawPoints(this.context,this.points)}eventEnd(t){this.started&&(this.started=!1,this.memCtx.clearRect(0,0,this.canvas.width,this.canvas.height),this.memCtx.drawImage(this.canvas,0,0),this.points=[],this.addDotToTempLine(t),this.lineFinish())}eventMove(t){this.started&&(this.count++,this.count==this.period&&(this.addDotToTempLine(t),this.count=0),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.drawImage(this.memCanvas,0,0),this.points.push(t),this.renderer.drawPoints(this.context,this.points))}clear(){this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.memCtx.clearRect(0,0,this.canvas.width,this.canvas.height),this.undoHistory=[],this.init(),null!=this.onClear&&this.onClear(this)}}},function(t,e,i){"use strict";t.exports=class{static rgb2hex(t){var e=new RegExp(/^rgb\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)$/);if(null==(t=t.match(e)))return"#000000";function i(t){let e=Number(t);return e>255&&(e=255),1==(e=e.toString(16)).length&&(e="0"+e),e}return`#${i(t[1])}${i(t[2])}${i(t[3])}`}static getStyleProp(t,e){return window.getComputedStyle?window.getComputedStyle(t,null).getPropertyValue(e):t.currentStyle?t.currentStyle[e]:void 0}}},function(t,e,i){"use strict";t.exports=class{constructor(t){this.canvasWidth=t.width,this.canvasHeight=t.height}drawPoints(t,e){if(2==e.length)return t.beginPath(),t.moveTo(e[0].x*this.canvasWidth,e[0].y*this.canvasHeight),t.lineTo(e[1].x*this.canvasWidth,e[1].y*this.canvasHeight),void t.stroke();t.beginPath(),t.moveTo(e[0].x*this.canvasWidth,e[0].y*this.canvasHeight);for(var i=1;i