2 lines
20 KiB
JavaScript
2 lines
20 KiB
JavaScript
(this.webpackJsonpreact=this.webpackJsonpreact||[]).push([[0],{12:function(e,t,n){e.exports=n(18)},17:function(e,t,n){},18:function(e,t,n){"use strict";n.r(t);var r=n(1),a=n(2),o=n(4),l=n(3),i=n(5),c=n(11),s=n(6),u=n(9),f=n(0),h=n.n(f),d=n(8),v=n.n(d),m=n(7);function p(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function g(e,t){t.sort((function(e,t){return e-t}));var n=!0;t.forEach((function(t,r){(n=n&&t===r)||p(e,t-1,t)}))}function y(e,t){var n=t.sort((function(e,t){return t-e})),r=!0;n.forEach((function(t,n){(r=r&&t===e.length-n-1)||p(e,t+1,t)}))}function w(e,t){t.sort((function(e,t){return e-t}));var n=t.map((function(t){return e[t]})),r=t.reverse().concat([0]);r.forEach((function(t,n){if(0!==n)for(var a=r[n-1]-1;a>=t;--a)e[a+n]=e[a]})),n.forEach((function(t,n){e[n]=t}))}function E(e,t){var n=t.sort((function(e,t){return t-e})),r=n.map((function(t){return e[t]}));(t=n.reverse().concat([e.length])).forEach((function(n,r){if(0!==r)for(var a=t[r-1]+1;a<n;++a)e[a-r]=e[a]})),r.forEach((function(t,n){e[e.length-n-1]=t}))}n(17);var x=Array.of(),k=!1,S=[];function C(){return JSON.stringify(x.map((function(e){return Object(u.a)({},e,{isSelected:!1})})))}function b(e){var t=JSON.parse(e);x.splice(0,x.length),t.forEach((function(e){I(e),x.push(e)})),k=!0}function M(){return Math.floor(Math.random()*Math.pow(2,31))}function B(e,t){var n=Math.random;Math.random=function(e){return function(){return(Math.pow(2,31)-1&(e=Math.imul(48271,e)))/Math.pow(2,31)}}(e);var r=t();return Math.random=n,r}function X(e,t,n,r,a,o){var l,i,c=a-n,s=o-r,u=c*c+s*s,f=-1;0!==u&&(f=((e-n)*c+(t-r)*s)/u),f<0?(l=n,i=r):f>1?(l=a,i=o):(l=n+f*c,i=r+f*s);var h=e-l,d=t-i;return Math.hypot(h,d)}function Y(e,t,n){if("ellipse"===e.type){var r=Math.abs(t-e.x-e.width/2),a=Math.abs(n-e.y-e.height/2),o=.707,l=.707,i=e.width/2,c=e.height/2;return[0,1,2,3].forEach((function(e){var t=i*o,n=c*l,s=(i*i-c*c)*Math.pow(o,3)/i,u=(c*c-i*i)*Math.pow(l,3)/c,f=t-s,h=n-u,d=r-s,v=a-u,m=Math.hypot(h,f),p=Math.hypot(v,d);o=Math.min(1,Math.max(0,(d*m/p+s)/i)),l=Math.min(1,Math.max(0,(v*m/p+u)/c));var g=Math.hypot(l,o);o/=g,l/=g})),Math.hypot(i*o-r,c*l-a)<10}if("rectangle"===e.type){var u=j(e),f=J(e),h=P(e),d=W(e);return X(t,n,u,h,f,h)<10||X(t,n,f,h,f,d)<10||X(t,n,f,d,u,d)<10||X(t,n,u,d,u,h)<10}if("arrow"===e.type){var v=z(e),m=Object(s.a)(v,8),p=m[0],g=m[1],y=m[2],w=m[3],E=m[4],x=m[5],k=m[6],S=m[7];return X(t-=e.x,n-=e.y,E,x,y,w)<10||X(t,n,p,g,y,w)<10||X(t,n,k,S,y,w)<10}if("text"===e.type){var C=j(e),b=J(e),M=P(e),B=W(e);return t>=C&&t<=b&&n>=M&&n<=B}if("selection"===e.type)return console.warn("This should not happen, we need to investigate why it does."),!1;throw new Error("Unimplemented type "+e.type)}function L(e,t,n,r){if("text"===e.type||"arrow"===e.type)return!1;var a=O(e,r),o=Object.keys(a).filter((function(e){var o=a[e];return t+r.scrollX>=o[0]&&t+r.scrollX<=o[0]+o[2]&&n+r.scrollY>=o[1]&&n+r.scrollY<=o[1]+o[3]}));return o.length>0&&o[0]}function D(e,t,n,r){var a=e*e/(e+Math.abs(n)),o={x:(n>0?0:e-a)+4,y:t-6-4,width:a-8,height:6},l=t*t/(t+Math.abs(r));return{horizontal:o,vertical:{x:e-6-4,y:(r>0?0:t-l)+4,width:6,height:l-12}}}function O(e,t){var n=e.x,r=e.x+e.width,a=e.y,o=e.y+e.height,l={},i=e.width<0?8:-8,c=e.height<0?8:-8;return Math.abs(r-n)>40&&(l.n=[n+(r-n)/2+t.scrollX-4,a-4+t.scrollY+c,8,8],l.s=[n+(r-n)/2+t.scrollX-4,o-4+t.scrollY-c,8,8]),Math.abs(o-a)>40&&(l.w=[n-4+t.scrollX+i,a+(o-a)/2+t.scrollY-4,8,8],l.e=[r-4+t.scrollX-i,a+(o-a)/2+t.scrollY-4,8,8]),l.nw=[n-4+t.scrollX+i,a-4+t.scrollY+c,8,8],l.ne=[r-4+t.scrollX-i,a-4+t.scrollY+c,8,8],l.sw=[n-4+t.scrollX+i,o-4+t.scrollY-c,8,8],l.se=[r-4+t.scrollX-i,o-4+t.scrollY-c,8,8],l}function U(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=r.offsetX,o=r.offsetY,l=r.renderScrollbars,i=void 0===l||l,c=r.renderSelection,s=void 0===c||c;if(t){var f=t.getContext("2d"),h=f.fillStyle;"string"===typeof n.viewBackgroundColor?(f.fillStyle=n.viewBackgroundColor,f.fillRect(0,0,t.width,t.height)):f.clearRect(0,0,t.width,t.height),f.fillStyle=h;var d=le();if(n=Object(u.a)({},n,{scrollX:"number"===typeof a?a:n.scrollX,scrollY:"number"===typeof o?o:n.scrollY}),x.forEach((function(t){if(t.draw(e,f,n),s&&t.isSelected){var r=j(t),a=J(t),o=P(t),l=W(t),i=f.getLineDash();if(f.setLineDash([8,4]),f.strokeRect(r-4+n.scrollX,o-4+n.scrollY,a-r+8,l-o+8),f.setLineDash(i),"text"!==t.type&&"arrow"!==t.type&&1===d.length){var c=O(t,n);Object.values(c).forEach((function(e){f.strokeRect(e[0],e[1],e[2],e[3])}))}}})),i){var v=D(f.canvas.width/window.devicePixelRatio,f.canvas.height/window.devicePixelRatio,n.scrollX,n.scrollY);f.fillStyle="rgba(0,0,0,0.3)",f.fillRect(v.horizontal.x,v.horizontal.y,v.horizontal.width,v.horizontal.height),f.fillRect(v.vertical.x,v.vertical.y,v.vertical.width,v.vertical.height),f.fillStyle=h}}}function R(e,t){var n=document.createElement("a");n.setAttribute("download",e),n.setAttribute("href",t),n.click(),n.remove()}function A(e,t,n,r,a){return[(e-n)*Math.cos(a)-(t-r)*Math.sin(a)+n,(e-n)*Math.sin(a)+(t-r)*Math.cos(a)+r]}var K=m.a.generator(null,null);function N(e){return"text"===e.type}function T(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}function z(e){var t=e.width,n=e.height,r=Math.hypot(t-0,n-0),a=Math.min(30,r/2),o=t-(t-0)/r*a,l=n-(n-0)/r*a,i=A(o,l,t,n,-20*Math.PI/180),c=Object(s.a)(i,2),u=c[0],f=c[1],h=A(o,l,t,n,20*Math.PI/180),d=Object(s.a)(h,2);return[0,0,t,n,u,f,d[0],d[1]]}function I(e){if("selection"===e.type)e.draw=function(t,n,r){var a=r.scrollX,o=r.scrollY,l=n.fillStyle;n.fillStyle="rgba(0, 0, 255, 0.10)",n.fillRect(e.x+a,e.y+o,e.width,e.height),n.fillStyle=l};else if("rectangle"===e.type){var t=B(e.seed,(function(){return K.rectangle(0,0,e.width,e.height,{stroke:e.strokeColor,fill:e.backgroundColor})}));e.draw=function(n,r,a){var o=a.scrollX,l=a.scrollY;r.translate(e.x+o,e.y+l),n.draw(t),r.translate(-e.x-o,-e.y-l)}}else if("ellipse"===e.type){var n=B(e.seed,(function(){return K.ellipse(e.width/2,e.height/2,e.width,e.height,{stroke:e.strokeColor,fill:e.backgroundColor})}));e.draw=function(t,r,a){var o=a.scrollX,l=a.scrollY;r.translate(e.x+o,e.y+l),t.draw(n),r.translate(-e.x-o,-e.y-l)}}else{if("arrow"===e.type){var r=z(e),a=Object(s.a)(r,8),o=a[0],l=a[1],i=a[2],c=a[3],u=a[4],f=a[5],h=a[6],d=a[7],v=B(e.seed,(function(){return[K.line(u,f,i,c,{stroke:e.strokeColor}),K.line(o,l,i,c,{stroke:e.strokeColor}),K.line(h,d,i,c,{stroke:e.strokeColor})]}));return void(e.draw=function(t,n,r){var a=r.scrollX,o=r.scrollY;n.translate(e.x+a,e.y+o),v.forEach((function(e){return t.draw(e)})),n.translate(-e.x-a,-e.y-o)})}if(!N(e))throw new Error("Unimplemented type "+e.type);e.draw=function(t,n,r){var a=r.scrollX,o=r.scrollY,l=n.font;n.font=e.font;var i=n.fillStyle;n.fillStyle=e.strokeColor,n.fillText(e.text,e.x+a,e.y+e.actualBoundingBoxAscent+o),n.fillStyle=i,n.font=l}}}function j(e){return e.width>=0?e.x:e.x+e.width}function J(e){return e.width>=0?e.x+e.width:e.x}function P(e){return e.height>=0?e.y:e.y+e.height}function W(e){return e.height>=0?e.y+e.height:e.y}function H(){x.forEach((function(e){e.isSelected=!1}))}function F(){document.documentElement.style.cursor=""}function V(){for(var e=x.length-1;e>=0;--e)x[e].isSelected&&x.splice(e,1)}function Z(e,t){try{return e&&(x.splice.apply(x,[0,x.length].concat(Object(c.a)("string"===typeof e?JSON.parse(e):e))),x.forEach((function(e){return I(e)}))),t?JSON.parse(t):null}catch(n){return x.splice(0,x.length),null}}var q="ArrowLeft",G="ArrowRight",Q="ArrowDown",$="ArrowUp",_="Escape",ee="Delete",te="Backspace",ne=[{icon:h.a.createElement("svg",{viewBox:"0 0 320 512"},h.a.createElement("path",{d:"M302.189 329.126H196.105l55.831 135.993c3.889 9.428-.555 19.999-9.444 23.999l-49.165 21.427c-9.165 4-19.443-.571-23.332-9.714l-53.053-129.136-86.664 89.138C18.729 472.71 0 463.554 0 447.977V18.299C0 1.899 19.921-6.096 30.277 5.443l284.412 292.542c11.472 11.179 3.007 31.141-12.5 31.141z"})),value:"selection"},{icon:h.a.createElement("svg",{viewBox:"0 0 448 512"},h.a.createElement("path",{d:"M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z"})),value:"rectangle"},{icon:h.a.createElement("svg",{viewBox:"0 0 512 512"},h.a.createElement("path",{d:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"})),value:"ellipse"},{icon:h.a.createElement("svg",{viewBox:"0 0 448 512"},h.a.createElement("path",{d:"M313.941 216H12c-6.627 0-12 5.373-12 12v56c0 6.627 5.373 12 12 12h301.941v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.569 0-33.941l-86.059-86.059c-15.119-15.119-40.971-4.411-40.971 16.971V216z"})),value:"arrow"},{icon:h.a.createElement("svg",{viewBox:"0 0 448 512"},h.a.createElement("path",{d:"M432 416h-23.41L277.88 53.69A32 32 0 0 0 247.58 32h-47.16a32 32 0 0 0-30.3 21.69L39.41 416H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16h-19.58l23.3-64h152.56l23.3 64H304a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM176.85 272L224 142.51 271.15 272z"})),value:"text"}],re=ne.map((function(e){return e.value[0]}));function ae(e){return ne.reduce((function(t,n){return n.value[0]!==e?t:n.value}),"selection")}function oe(e){return e===q||e===G||e===Q||e===$}function le(){var e=[];return x.forEach((function(t,n){t.isSelected&&e.push(n)})),e}var ie=function(){return x.some((function(e){return e.isSelected}))},ce=-1,se=-1,ue=null,fe=function(e){function t(){var e,n;Object(r.a)(this,t);for(var a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return(n=Object(o.a)(this,(e=Object(l.a)(t)).call.apply(e,[this].concat(i)))).state={draggingElement:null,resizingElement:null,elementType:"selection",exportBackground:!0,currentItemStrokeColor:"#000000",currentItemBackgroundColor:"#ffffff",viewBackgroundColor:"#ffffff",scrollX:0,scrollY:0},n.onResize=function(){n.forceUpdate()},n.onKeyDown=function(e){if(!T(e.target))if(e.key===_)H(),n.forceUpdate(),e.preventDefault();else if(e.key===te||e.key===ee)V(),n.forceUpdate(),e.preventDefault();else if(oe(e.key)){var t=e.shiftKey?5:1;x.forEach((function(n){n.isSelected&&(e.key===q?n.x-=t:e.key===G?n.x+=t:e.key===$?n.y-=t:e.key===Q&&(n.y+=t))})),n.forceUpdate(),e.preventDefault()}else if(e.metaKey&&e.shiftKey&&e.altKey&&"KeyB"===e.code)n.moveOneLeft(),e.preventDefault();else if(e.metaKey&&e.shiftKey&&"KeyB"===e.code)n.moveAllLeft(),e.preventDefault();else if(e.metaKey&&e.shiftKey&&e.altKey&&"KeyF"===e.code)n.moveOneRight(),e.preventDefault();else if(e.metaKey&&e.shiftKey&&"KeyF"===e.code)n.moveAllRight(),e.preventDefault();else if(e.metaKey&&"KeyA"===e.code)x.forEach((function(e){e.isSelected=!0})),n.forceUpdate(),e.preventDefault();else if(re.includes(e.key.toLowerCase()))n.setState({elementType:ae(e.key)});else if(e.metaKey&&"KeyZ"===e.code){var r=S.pop();C()===r&&(r=S.pop()),void 0!==r&&b(r),n.forceUpdate(),e.preventDefault()}},n.deleteSelectedElements=function(){V(),n.forceUpdate()},n.clearCanvas=function(){window.confirm("This will clear the whole canvas. Are you sure?")&&(x.splice(0,x.length),n.setState({viewBackgroundColor:"#ffffff",scrollX:0,scrollY:0}),n.forceUpdate())},n.moveAllLeft=function(){w(x,le()),n.forceUpdate()},n.moveOneLeft=function(){g(x,le()),n.forceUpdate()},n.moveAllRight=function(){E(x,le()),n.forceUpdate()},n.moveOneRight=function(){y(x,le()),n.forceUpdate()},n.removeWheelEventListener=void 0,n.handleWheel=function(e){e.preventDefault();var t=e.deltaX,r=e.deltaY;n.setState((function(e){return{scrollX:e.scrollX-t,scrollY:e.scrollY-r}}))},n}return Object(i.a)(t,e),Object(a.a)(t,[{key:"componentDidMount",value:function(){document.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("resize",this.onResize,!1);var e=Z(localStorage.getItem("excalidraw"),localStorage.getItem("excalidraw-state"));e&&this.setState(e)}},{key:"componentWillUnmount",value:function(){document.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("resize",this.onResize,!1)}},{key:"render",value:function(){var e=this,t=window.innerWidth-250,n=window.innerHeight-0;return h.a.createElement("div",{className:"container",onCut:function(t){t.clipboardData.setData("text/plain",JSON.stringify(x.filter((function(e){return e.isSelected})))),V(),e.forceUpdate(),t.preventDefault()},onCopy:function(e){e.clipboardData.setData("text/plain",JSON.stringify(x.filter((function(e){return e.isSelected})))),e.preventDefault()},onPaste:function(t){var n,r=t.clipboardData.getData("text");try{n=JSON.parse(r)}catch(t){}Array.isArray(n)&&n.length>0&&n[0].type&&(H(),n.forEach((function(e){e.x+=10,e.y+=10,e.seed=M(),I(e),x.push(e)})),e.forceUpdate()),t.preventDefault()}},h.a.createElement("div",{className:"sidePanel"},h.a.createElement("h4",null,"Shapes"),h.a.createElement("div",{className:"panelTools"},ne.map((function(t){var n=t.value,r=t.icon;return h.a.createElement("label",{key:n,className:"tool"},h.a.createElement("input",{type:"radio",checked:e.state.elementType===n,onChange:function(){e.setState({elementType:n}),H(),document.documentElement.style.cursor="text"===n?"text":"crosshair",e.forceUpdate()}}),h.a.createElement("div",{className:"toolIcon"},r))}))),h.a.createElement("h4",null,"Colors"),h.a.createElement("div",{className:"panelColumn"},h.a.createElement("label",null,h.a.createElement("input",{type:"color",value:this.state.viewBackgroundColor,onChange:function(t){e.setState({viewBackgroundColor:t.target.value})}}),"Background"),h.a.createElement("label",null,h.a.createElement("input",{type:"color",value:this.state.currentItemStrokeColor,onChange:function(t){e.setState({currentItemStrokeColor:t.target.value})}}),"Shape Stroke"),h.a.createElement("label",null,h.a.createElement("input",{type:"color",value:this.state.currentItemBackgroundColor,onChange:function(t){e.setState({currentItemBackgroundColor:t.target.value})}}),"Shape Background")),h.a.createElement("h4",null,"Canvas"),h.a.createElement("div",{className:"panelColumn"},h.a.createElement("button",{onClick:this.clearCanvas,title:"Clear the canvas & reset background color"},"Clear canvas")),h.a.createElement("h4",null,"Export"),h.a.createElement("div",{className:"panelColumn"},h.a.createElement("button",{onClick:function(){!function(e){var t=e.exportBackground,n=e.exportPadding,r=void 0===n?10:n,a=e.viewBackgroundColor;if(!x.length)return window.alert("Cannot export empty canvas.");var o=1/0,l=0,i=1/0,c=0;function s(e,t){return Math.abs(e>t?e-t:t-e)}x.forEach((function(e){o=Math.min(o,j(e)),l=Math.max(l,J(e)),i=Math.min(i,P(e)),c=Math.max(c,W(e))}));var u=document.createElement("canvas");u.style.display="none",document.body.appendChild(u),u.width=s(o,l)+2*r,u.height=s(i,c)+2*r,U(m.a.canvas(u),u,{viewBackgroundColor:t?a:null,scrollX:0,scrollY:0},{offsetX:-o+r,offsetY:-i+r,renderScrollbars:!1,renderSelection:!1}),R("excalidraw.png",u.toDataURL("image/png")),u!==de&&u.remove()}(e.state)}},"Export to png"),h.a.createElement("label",null,h.a.createElement("input",{type:"checkbox",checked:this.state.exportBackground,onChange:function(t){e.setState({exportBackground:t.target.checked})}}),"background")),h.a.createElement("h4",null,"Save/Load"),h.a.createElement("div",{className:"panelColumn"},h.a.createElement("button",{onClick:function(){!function(){var e=JSON.stringify({version:1,source:window.location.origin,elements:x});R("excalidraw.json","data:text/plain;charset=utf-8,"+encodeURIComponent(e))}()}},"Save as..."),h.a.createElement("button",{onClick:function(){(function(){var e=document.createElement("input"),t=new FileReader;return e.type="file",e.accept=".json",e.onchange=function(){e.files.length?t.readAsText(e.files[0],"utf8"):alert("A file was not selected.")},e.click(),new Promise((function(e){t.onloadend=function(){t.readyState===FileReader.DONE&&(Z(JSON.parse(t.result).elements,null),e())}}))})().then((function(){return e.forceUpdate()}))}},"Load file...")),ie()&&h.a.createElement(h.a.Fragment,null,h.a.createElement("h4",null,"Shape options"),h.a.createElement("div",{className:"panelColumn"},h.a.createElement("button",{onClick:this.deleteSelectedElements},"Delete"),h.a.createElement("button",{onClick:this.moveOneRight},"Bring forward"),h.a.createElement("button",{onClick:this.moveAllRight},"Bring to front"),h.a.createElement("button",{onClick:this.moveOneLeft},"Send backward"),h.a.createElement("button",{onClick:this.moveAllLeft},"Send to back")))),h.a.createElement("canvas",{id:"canvas",style:{width:t,height:n},width:t*window.devicePixelRatio,height:n*window.devicePixelRatio,ref:function(r){e.removeWheelEventListener&&(e.removeWheelEventListener(),e.removeWheelEventListener=void 0),r&&(r.addEventListener("wheel",e.handleWheel,{passive:!1}),e.removeWheelEventListener=function(){return r.removeEventListener("wheel",e.handleWheel)},t===ce&&n===se||(ce=t,se=n,r.getContext("2d").scale(window.devicePixelRatio,window.devicePixelRatio)))},onMouseDown:function(t){if(null!==ue&&ue(t),0===t.button){t.preventDefault(),T(document.activeElement)&&document.activeElement.blur();var n=t.clientX-250-e.state.scrollX,r=t.clientY-0-e.state.scrollY,a=function(e,t,n,r,a){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,i={type:e,x:t,y:n,width:o,height:l,isSelected:!1,strokeColor:r,backgroundColor:a,seed:M(),draw:function(e,t,n){}};return i}(e.state.elementType,n,r,e.state.currentItemStrokeColor,e.state.currentItemBackgroundColor),o=!1,l=!1,i=!1;if("selection"===e.state.elementType){var c=x.find((function(t){return L(t,n,r,{scrollX:e.state.scrollX,scrollY:e.state.scrollY,viewBackgroundColor:e.state.viewBackgroundColor})}));if(e.setState({resizingElement:c||null}),c)o=L(c,n,r,{scrollX:e.state.scrollX,scrollY:e.state.scrollY,viewBackgroundColor:e.state.viewBackgroundColor}),document.documentElement.style.cursor="".concat(o,"-resize"),i=!0;else{for(var s=null,u=x.length-1;u>=0;--u)if(Y(x[u],n,r)){s=x[u];break}s?s.isSelected||(t.shiftKey||H(),s.isSelected=!0):H(),(l=ie())&&(document.documentElement.style.cursor="move")}}if(N(a)){F();var f=prompt("What text do you want?");if(null===f)return;a.text=f,a.font="20px Virgil";var h=me.font;me.font=a.font;var d=me.measureText(a.text),v=d.actualBoundingBoxAscent,m=d.actualBoundingBoxDescent,p=d.width;a.actualBoundingBoxAscent=v,me.font=h;var g=v+m;a.x-=p/2,a.y-=v,a.width=p,a.height=g}I(a),x.push(a),"text"===e.state.elementType?(e.setState({draggingElement:null,elementType:"selection"}),a.isSelected=!0):e.setState({draggingElement:a});var y=n,w=r,E=function(t){if(t.target instanceof HTMLElement){if(i&&e.state.resizingElement){var n=e.state.resizingElement,r=x.filter((function(e){return e.isSelected}));if(1===r.length){var a=t.clientX-250-e.state.scrollX,c=t.clientY-0-e.state.scrollY;return r.forEach((function(e){switch(o){case"nw":e.width+=e.x-y,e.height+=e.y-w,e.x=y,e.y=w;break;case"ne":e.width=y-e.x,e.height+=e.y-w,e.y=w;break;case"sw":e.width+=e.x-y,e.x=y,e.height=w-e.y;break;case"se":e.width+=a-y,t.shiftKey?e.height=e.width:e.height+=c-w;break;case"n":e.height+=e.y-w,e.y=w;break;case"w":e.width+=e.x-y,e.x=y;break;case"s":e.height=w-e.y;break;case"e":e.width=y-e.x}n.x=e.x,n.y=e.y,I(n)})),y=a,w=c,k=!0,void e.forceUpdate()}}if(l){var s=x.filter((function(e){return e.isSelected}));if(s.length){var u=t.clientX-250-e.state.scrollX,f=t.clientY-0-e.state.scrollY;return s.forEach((function(e){e.x+=u-y,e.y+=f-w})),y=u,w=f,k=!0,void e.forceUpdate()}}var h=e.state.draggingElement;if(h){var d=t.clientX-250-h.x-e.state.scrollX,v=t.clientY-0-h.y-e.state.scrollY;h.width=d,h.height=t.shiftKey?d:v,I(h),"selection"===e.state.elementType&&function(e){var t=j(e),n=J(e),r=P(e),a=W(e);x.forEach((function(e){var o=j(e),l=J(e),i=P(e),c=W(e);e.isSelected="selection"!==e.type&&t<=o&&r<=i&&n>=l&&a>=c}))}(h),k=!0,e.forceUpdate()}}},S=function t(n){var r=e.state,a=r.draggingElement,o=r.elementType;if(ue=null,window.removeEventListener("mousemove",E),window.removeEventListener("mouseup",t),F(),null===a)return H(),void e.forceUpdate();"selection"===o?(l&&(l=!1),x.pop()):a.isSelected=!0,e.setState({draggingElement:null,elementType:"selection"}),e.forceUpdate()};ue=S,window.addEventListener("mousemove",E),window.addEventListener("mouseup",S),k=!0,e.forceUpdate()}}}))}},{key:"componentDidUpdate",value:function(){var e,t;U(ve,de,{scrollX:this.state.scrollX,scrollY:this.state.scrollY,viewBackgroundColor:this.state.viewBackgroundColor}),e=this.state,localStorage.setItem("excalidraw",JSON.stringify(x)),localStorage.setItem("excalidraw-state",JSON.stringify(e)),k||(t=C(),S.length>0&&S[S.length-1]===t||S.push(t)),k=!1}}]),t}(h.a.Component),he=document.getElementById("root");v.a.render(h.a.createElement(fe,null),he);var de=document.getElementById("canvas"),ve=m.a.canvas(de),me=de.getContext("2d");v.a.render(h.a.createElement(fe,null),he)}},[[12,1,2]]]);
|
|
//# sourceMappingURL=main.3def8d06.chunk.js.map
|