fabric.min.js 298 KB

1
  1. var fabric=fabric||{version:"2.3.3"};"undefined"!=typeof exports?exports.fabric=fabric:"function"==typeof define&&define.amd&&define([],function(){return fabric}),"undefined"!=typeof document&&"undefined"!=typeof window?(fabric.document=document,fabric.window=window):(fabric.document=require("jsdom").jsdom(decodeURIComponent("%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E"),{features:{FetchExternalResources:["img"]}}),fabric.jsdomImplForWrapper=require("jsdom/lib/jsdom/living/generated/utils").implForWrapper,fabric.nodeCanvas=require("jsdom/lib/jsdom/utils").Canvas,fabric.window=fabric.document.defaultView,DOMParser=require("xmldom").DOMParser),fabric.isTouchSupported="ontouchstart"in fabric.window,fabric.isLikelyNode="undefined"!=typeof Buffer&&"undefined"==typeof window,fabric.DPI=96,fabric.reNum="(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:e[-+]?\\d+)?)",fabric.fontPaths={},fabric.iMatrix=[1,0,0,1,0,0],fabric.canvasModule="canvas",fabric.perfLimitSizeTotal=2097152,fabric.maxCacheSideLimit=4096,fabric.minCacheSideLimit=256,fabric.charWidthsCache={},fabric.textureSize=2048,fabric.enableGLFiltering=!0,fabric.devicePixelRatio=fabric.window.devicePixelRatio||fabric.window.webkitDevicePixelRatio||fabric.window.mozDevicePixelRatio||1,fabric.browserShadowBlurConstant=1,fabric.initFilterBackend=function(){return fabric.enableGLFiltering&&fabric.isWebglSupported&&fabric.isWebglSupported(fabric.textureSize)?(console.log("max texture size: "+fabric.maxTextureSize),new fabric.WebglFilterBackend({tileSize:fabric.textureSize})):fabric.Canvas2dFilterBackend?new fabric.Canvas2dFilterBackend:void 0};"undefined"!=typeof document&&"undefined"!=typeof window&&(window.fabric=fabric);if("undefined"==typeof eventjs)var eventjs={};if(function(e){e.modifyEventListener=!1,e.modifySelectors=!1,e.configure=function(t){isFinite(t.modifyEventListener)&&(e.modifyEventListener=t.modifyEventListener),isFinite(t.modifySelectors)&&(e.modifySelectors=t.modifySelectors),l===!1&&e.modifyEventListener&&p(),g===!1&&e.modifySelectors&&m()},e.add=function(e,t,r,o){return n(e,t,r,o,"add")},e.remove=function(e,t,r,o){return n(e,t,r,o,"remove")},e.returnFalse=function(){return!1},e.stop=function(e){e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.cancelBubbleCount=0)},e.prevent=function(e){e&&(e.preventDefault?e.preventDefault():e.preventManipulation?e.preventManipulation():e.returnValue=!1)},e.cancel=function(t){e.stop(t),e.prevent(t)},e.blur=function(){var e=document.activeElement;if(e){var t=document.activeElement.nodeName;("INPUT"===t||"TEXTAREA"===t||"true"===e.contentEditable)&&e.blur&&e.blur()}},e.getEventSupport=function(e,t){if("string"==typeof e&&(t=e,e=window),t="on"+t,t in e)return!0;if(e.setAttribute||(e=document.createElement("div")),e.setAttribute&&e.removeAttribute){e.setAttribute(t,"");var n="function"==typeof e[t];return"undefined"!=typeof e[t]&&(e[t]=null),e.removeAttribute(t),n}};var t=function(e){if(!e||"object"!=typeof e)return e;var n=new e.constructor;for(var r in e)n[r]=e[r]&&"object"==typeof e[r]?t(e[r]):e[r];return n},n=function(i,s,v,l,p,g){if(l=l||{},"[object Object]"===String(i)){var m=i;if(i=m.target,delete m.target,!m.type||!m.listener){for(var y in m){var h=m[y];"function"!=typeof h&&(l[y]=h)}var j={};for(var w in m){var y=w.split(","),b=m[w],x={};for(var P in l)x[P]=l[P];if("function"==typeof b)var v=b;else{if("function"!=typeof b.listener)continue;var v=b.listener;for(var P in b)"function"!=typeof b[P]&&(x[P]=b[P])}for(var E=0;E<y.length;E++)j[w]=eventjs.add(i,y[E],v,x,p)}return j}s=m.type,delete m.type,v=m.listener,delete m.listener;for(var w in m)l[w]=m[w]}if(i&&s&&v){if("string"==typeof i&&"ready"===s){if(!window.eventjs_stallOnReady){var M=(new Date).getTime(),L=l.timeout,T=l.interval||1e3/60,G=window.setInterval(function(){(new Date).getTime()-M>L&&window.clearInterval(G),document.querySelector(i)&&(window.clearInterval(G),setTimeout(v,1))},T);return}s="load",i=window}if("string"==typeof i){if(i=document.querySelectorAll(i),0===i.length)return o("Missing target on listener!",arguments);1===i.length&&(i=i[0])}var _,D={};if(i.length>0&&i!==window){for(var S=0,k=i.length;k>S;S++)_=n(i[S],s,v,t(l),p),_&&(D[S]=_);return r(D)}if("string"==typeof s&&(s=s.toLowerCase(),-1!==s.indexOf(" ")?s=s.split(" "):-1!==s.indexOf(",")&&(s=s.split(","))),"string"!=typeof s){if("number"==typeof s.length)for(var C=0,F=s.length;F>C;C++)_=n(i,s[C],v,t(l),p),_&&(D[s[C]]=_);else for(var w in s)_="function"==typeof s[w]?n(i,w,s[w],t(l),p):n(i,w,s[w].listener,t(s[w]),p),_&&(D[w]=_);return r(D)}if(0===s.indexOf("on")&&(s=s.substr(2)),"object"!=typeof i)return o("Target is not defined!",arguments);if("function"!=typeof v)return o("Listener is not a function!",arguments);var X=l.useCapture||!1,Y=f(i)+"."+f(v)+"."+(X?1:0);if(e.Gesture&&e.Gesture._gestureHandlers[s]){if(Y=s+Y,"remove"===p){if(!u[Y])return;u[Y].remove(),delete u[Y]}else if("add"===p){if(u[Y])return u[Y].add(),u[Y];if(l.useCall&&!e.modifyEventListener){var H=v;v=function(e,t){for(var n in t)e[n]=t[n];return H.call(i,e)}}l.gesture=s,l.target=i,l.listener=v,l.fromOverwrite=g,u[Y]=e.proxy[s](l)}return u[Y]}for(var O,U=a(s),E=0;E<U.length;E++)if(s=U[E],O=s+"."+Y,"remove"===p){if(!u[O])continue;i[c](s,v,X),delete u[O]}else if("add"===p){if(u[O])return u[O];i[d](s,v,X),u[O]={id:O,type:s,target:i,listener:v,remove:function(){for(var t=0;t<U.length;t++)e.remove(i,U[t],v,l)}}}return u[O]}},r=function(e){return{remove:function(){for(var t in e)e[t].remove()},add:function(){for(var t in e)e[t].add()}}},o=function(e,t){"undefined"!=typeof console&&"undefined"!=typeof console.error&&console.error(e,t)},i={msPointer:["MSPointerDown","MSPointerMove","MSPointerUp"],touch:["touchstart","touchmove","touchend"],mouse:["mousedown","mousemove","mouseup"]},s={MSPointerDown:0,MSPointerMove:1,MSPointerUp:2,touchstart:0,touchmove:1,touchend:2,mousedown:0,mousemove:1,mouseup:2},a=(function(){e.supports={},window.navigator.msPointerEnabled&&(e.supports.msPointer=!0),e.getEventSupport("touchstart")&&(e.supports.touch=!0),e.getEventSupport("mousedown")&&(e.supports.mouse=!0)}(),function(){return function(t){var n=document.addEventListener?"":"on",r=s[t];if(isFinite(r)){var o=[];for(var a in e.supports)o.push(n+i[a][r]);return o}return[n+t]}}()),u={},v=0,f=function(e){return e===window?"#window":e===document?"#document":(e.uniqueID||(e.uniqueID="e"+v++),e.uniqueID)},d=document.addEventListener?"addEventListener":"attachEvent",c=document.removeEventListener?"removeEventListener":"detachEvent";e.createPointerEvent=function(t,n,r){var o=n.gesture,i=n.target,s=t.changedTouches||e.proxy.getCoords(t);if(s.length){var a=s[0];n.pointers=r?[]:s,n.pageX=a.pageX,n.pageY=a.pageY,n.x=n.pageX,n.y=n.pageY}var u=document.createEvent("Event");u.initEvent(o,!0,!0),u.originalEvent=t;for(var v in n)"target"!==v&&(u[v]=n[v]);var f=u.type;e.Gesture&&e.Gesture._gestureHandlers[f]&&n.oldListener.call(i,u,n,!1)};var l=!1,p=function(){if(window.HTMLElement){var t=function(t){var r=function(r){var o=r+"EventListener",i=t[o];t[o]=function(t,o,s){if(e.Gesture&&e.Gesture._gestureHandlers[t]){var u=s;"object"==typeof s?u.useCall=!0:u={useCall:!0,useCapture:s},n(this,t,o,u,r,!0)}else for(var v=a(t),f=0;f<v.length;f++)i.call(this,v[f],o,s)}};r("add"),r("remove")};navigator.userAgent.match(/Firefox/)?(t(HTMLDivElement.prototype),t(HTMLCanvasElement.prototype)):t(HTMLElement.prototype),t(document),t(window)}},g=!1,m=function(){var e=NodeList.prototype;e.removeEventListener=function(e,t,n){for(var r=0,o=this.length;o>r;r++)this[r].removeEventListener(e,t,n)},e.addEventListener=function(e,t,n){for(var r=0,o=this.length;o>r;r++)this[r].addEventListener(e,t,n)}};return e}(eventjs),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";e.pointerSetup=function(e,t){e.target=e.target||window,e.doc=e.target.ownerDocument||e.target,e.minFingers=e.minFingers||e.fingers||1,e.maxFingers=e.maxFingers||e.fingers||1/0,e.position=e.position||"relative",delete e.fingers,t=t||{},t.enabled=!0,t.gesture=e.gesture,t.target=e.target,t.env=e.env,eventjs.modifyEventListener&&e.fromOverwrite&&(e.oldListener=e.listener,e.listener=eventjs.createPointerEvent);var n=0,r=0===t.gesture.indexOf("pointer")&&eventjs.modifyEventListener?"pointer":"mouse";return e.oldListener&&(t.oldListener=e.oldListener),t.listener=e.listener,t.proxy=function(n){t.defaultListener=e.listener,e.listener=n,n(e.event,t)},t.add=function(){t.enabled!==!0&&(e.onPointerDown&&eventjs.add(e.target,r+"down",e.onPointerDown),e.onPointerMove&&eventjs.add(e.doc,r+"move",e.onPointerMove),e.onPointerUp&&eventjs.add(e.doc,r+"up",e.onPointerUp),t.enabled=!0)},t.remove=function(){t.enabled!==!1&&(e.onPointerDown&&eventjs.remove(e.target,r+"down",e.onPointerDown),e.onPointerMove&&eventjs.remove(e.doc,r+"move",e.onPointerMove),e.onPointerUp&&eventjs.remove(e.doc,r+"up",e.onPointerUp),t.reset(),t.enabled=!1)},t.pause=function(t){!e.onPointerMove||t&&!t.move||eventjs.remove(e.doc,r+"move",e.onPointerMove),!e.onPointerUp||t&&!t.up||eventjs.remove(e.doc,r+"up",e.onPointerUp),n=e.fingers,e.fingers=0},t.resume=function(t){!e.onPointerMove||t&&!t.move||eventjs.add(e.doc,r+"move",e.onPointerMove),!e.onPointerUp||t&&!t.up||eventjs.add(e.doc,r+"up",e.onPointerUp),e.fingers=n},t.reset=function(){e.tracker={},e.fingers=0},t};var t=eventjs.supports;eventjs.isMouse=!!t.mouse,eventjs.isMSPointer=!!t.touch,eventjs.isTouch=!!t.msPointer,e.pointerStart=function(t,n,r){var o=(t.type||"mousedown").toUpperCase();0===o.indexOf("MOUSE")?(eventjs.isMouse=!0,eventjs.isTouch=!1,eventjs.isMSPointer=!1):0===o.indexOf("TOUCH")?(eventjs.isMouse=!1,eventjs.isTouch=!0,eventjs.isMSPointer=!1):0===o.indexOf("MSPOINTER")&&(eventjs.isMouse=!1,eventjs.isTouch=!1,eventjs.isMSPointer=!0);var i=function(e,t){var n=r.bbox,o=a[t]={};switch(r.position){case"absolute":o.offsetX=0,o.offsetY=0;break;case"differenceFromLast":o.offsetX=e.pageX,o.offsetY=e.pageY;break;case"difference":o.offsetX=e.pageX,o.offsetY=e.pageY;break;case"move":o.offsetX=e.pageX-n.x1,o.offsetY=e.pageY-n.y1;break;default:o.offsetX=n.x1-n.scrollLeft,o.offsetY=n.y1-n.scrollTop}var i=e.pageX-o.offsetX,s=e.pageY-o.offsetY;o.rotation=0,o.scale=1,o.startTime=o.moveTime=(new Date).getTime(),o.move={x:i,y:s},o.start={x:i,y:s},r.fingers++};r.event=t,n.defaultListener&&(r.listener=n.defaultListener,delete n.defaultListener);for(var s=!r.fingers,a=r.tracker,u=t.changedTouches||e.getCoords(t),v=u.length,f=0;v>f;f++){var d=u[f],c=d.identifier||1/0;if(r.fingers){if(r.fingers>=r.maxFingers){var l=[];for(var c in r.tracker)l.push(c);return n.identifier=l.join(","),s}var p=0;for(var g in a){if(a[g].up){delete a[g],i(d,c),r.cancel=!0;break}p++}if(a[c])continue;i(d,c)}else a=r.tracker={},n.bbox=r.bbox=e.getBoundingBox(r.target),r.fingers=0,r.cancel=!1,i(d,c)}var l=[];for(var c in r.tracker)l.push(c);return n.identifier=l.join(","),s},e.pointerEnd=function(e,t,n,r){for(var o=e.touches||[],i=o.length,s={},a=0;i>a;a++){var u=o[a],v=u.identifier;s[v||1/0]=!0}for(var v in n.tracker){var f=n.tracker[v];s[v]||f.up||(r&&r({pageX:f.pageX,pageY:f.pageY,changedTouches:[{pageX:f.pageX,pageY:f.pageY,identifier:"Infinity"===v?1/0:v}]},"up"),f.up=!0,n.fingers--)}if(0!==n.fingers)return!1;var d=[];n.gestureFingers=0;for(var v in n.tracker)n.gestureFingers++,d.push(v);return t.identifier=d.join(","),!0},e.getCoords=function(t){return e.getCoords="undefined"!=typeof t.pageX?function(e){return Array({type:"mouse",x:e.pageX,y:e.pageY,pageX:e.pageX,pageY:e.pageY,identifier:e.pointerId||1/0})}:function(e){var t=document.documentElement;return e=e||window.event,Array({type:"mouse",x:e.clientX+t.scrollLeft,y:e.clientY+t.scrollTop,pageX:e.clientX+t.scrollLeft,pageY:e.clientY+t.scrollTop,identifier:1/0})},e.getCoords(t)},e.getCoord=function(t){if("ontouchstart"in window){var n=0,r=0;e.getCoord=function(e){var t=e.changedTouches;return t&&t.length?{x:n=t[0].pageX,y:r=t[0].pageY}:{x:n,y:r}}}else e.getCoord="undefined"!=typeof t.pageX&&"undefined"!=typeof t.pageY?function(e){return{x:e.pageX,y:e.pageY}}:function(e){var t=document.documentElement;return e=e||window.event,{x:e.clientX+t.scrollLeft,y:e.clientY+t.scrollTop}};return e.getCoord(t)};var n=function(e,t){var n=parseFloat(e.getPropertyValue(t),10);return isFinite(n)?n:0};return e.getBoundingBox=function(e){(e===window||e===document)&&(e=document.body);var t={},r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.x1=r.left,t.y1=r.top,t.scaleX=r.width/e.offsetWidth||1,t.scaleY=r.height/e.offsetHeight||1,t.scrollLeft=0,t.scrollTop=0;var o=window.getComputedStyle(e),i="border-box"===o.getPropertyValue("box-sizing");if(i===!1){var s=n(o,"border-left-width"),a=n(o,"border-right-width"),u=n(o,"border-bottom-width"),v=n(o,"border-top-width");t.border=[s,a,v,u],t.x1+=s,t.y1+=v,t.width-=a+s,t.height-=u+v}t.x2=t.x1+t.width,t.y2=t.y1+t.height;for(var f=o.getPropertyValue("position"),d="fixed"===f?e:e.parentNode;null!==d&&d!==document.body&&void 0!==d.scrollTop;){var o=window.getComputedStyle(d),f=o.getPropertyValue("position");if("absolute"===f);else{if("fixed"===f){t.scrollTop-=d.parentNode.scrollTop,t.scrollLeft-=d.parentNode.scrollLeft;break}t.scrollLeft+=d.scrollLeft,t.scrollTop+=d.scrollTop}d=d.parentNode}return t.scrollBodyLeft=void 0!==window.pageXOffset?window.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft,t.scrollBodyTop=void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop,t.scrollLeft-=t.scrollBodyLeft,t.scrollTop-=t.scrollBodyTop,t},function(){var t,n=navigator.userAgent.toLowerCase(),r=-1!==n.indexOf("macintosh");t=r&&-1!==n.indexOf("khtml")?{91:!0,93:!0}:r&&-1!==n.indexOf("firefox")?{224:!0}:{17:!0},(e.metaTrackerReset=function(){eventjs.fnKey=e.fnKey=!1,eventjs.metaKey=e.metaKey=!1,eventjs.escKey=e.escKey=!1,eventjs.ctrlKey=e.ctrlKey=!1,eventjs.shiftKey=e.shiftKey=!1,eventjs.altKey=e.altKey=!1})(),e.metaTracker=function(n){var r="keydown"===n.type;27===n.keyCode&&(eventjs.escKey=e.escKey=r),t[n.keyCode]&&(eventjs.metaKey=e.metaKey=r),eventjs.ctrlKey=e.ctrlKey=n.ctrlKey,eventjs.shiftKey=e.shiftKey=n.shiftKey,eventjs.altKey=e.altKey=n.altKey}}(),e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if(eventjs.MutationObserver=function(){var e=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,t=!e&&function(){var e=document.createElement("p"),t=!1,n=function(){t=!0};if(e.addEventListener)e.addEventListener("DOMAttrModified",n,!1);else{if(!e.attachEvent)return!1;e.attachEvent("onDOMAttrModified",n)}return e.setAttribute("id","target"),t}();return function(n,r){if(e){var o={subtree:!1,attributes:!0},i=new e(function(e){e.forEach(function(e){r.call(e.target,e.attributeName)})});i.observe(n,o)}else t?eventjs.add(n,"DOMAttrModified",function(e){r.call(n,e.attrName)}):"onpropertychange"in document.body&&eventjs.add(n,"propertychange",function(){r.call(n,window.event.propertyName)})}}(),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.click=function(t){t.gesture=t.gesture||"click",t.maxFingers=t.maxFingers||t.fingers||1,t.onPointerDown=function(r){e.pointerStart(r,n,t)&&eventjs.add(t.target,"mouseup",t.onPointerUp)},t.onPointerUp=function(r){if(e.pointerEnd(r,n,t)){eventjs.remove(t.target,"mouseup",t.onPointerUp);var o=r.changedTouches||e.getCoords(r),i=o[0],s=t.bbox,a=e.getBoundingBox(t.target),u=i.pageY-a.scrollBodyTop,v=i.pageX-a.scrollBodyLeft;if(v>s.x1&&u>s.y1&&v<s.x2&&u<s.y2&&s.scrollTop===a.scrollTop){for(var f in t.tracker)break;var d=t.tracker[f];n.x=d.start.x,n.y=d.start.y,t.listener(r,n)}}};var n=e.pointerSetup(t);return n.state="click",eventjs.add(t.target,"mousedown",t.onPointerDown),n},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.click=e.click,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.dbltap=e.dblclick=function(t){t.gesture=t.gesture||"dbltap",t.maxFingers=t.maxFingers||t.fingers||1;var n,r,o,i,s,a=700;t.onPointerDown=function(v){var f=v.changedTouches||e.getCoords(v);n&&!r?(s=f[0],r=(new Date).getTime()-n):(i=f[0],n=(new Date).getTime(),r=0,clearTimeout(o),o=setTimeout(function(){n=0},a)),e.pointerStart(v,u,t)&&(eventjs.add(t.target,"mousemove",t.onPointerMove).listener(v),eventjs.add(t.target,"mouseup",t.onPointerUp))},t.onPointerMove=function(a){if(n&&!r){var u=a.changedTouches||e.getCoords(a);s=u[0]}var v=t.bbox,f=s.pageX-v.x1,d=s.pageY-v.y1;f>0&&f<v.width&&d>0&&d<v.height&&Math.abs(s.pageX-i.pageX)<=25&&Math.abs(s.pageY-i.pageY)<=25||(eventjs.remove(t.target,"mousemove",t.onPointerMove),clearTimeout(o),n=r=0)},t.onPointerUp=function(i){if(e.pointerEnd(i,u,t)&&(eventjs.remove(t.target,"mousemove",t.onPointerMove),eventjs.remove(t.target,"mouseup",t.onPointerUp)),n&&r){if(a>=r){u.state=t.gesture;for(var s in t.tracker)break;var v=t.tracker[s];u.x=v.start.x,u.y=v.start.y,t.listener(i,u)}clearTimeout(o),n=r=0}};var u=e.pointerSetup(t);return u.state="dblclick",eventjs.add(t.target,"mousedown",t.onPointerDown),u},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.dbltap=e.dbltap,eventjs.Gesture._gestureHandlers.dblclick=e.dblclick,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.dragElement=function(t,n){e.drag({event:n,target:t,position:"move",listener:function(e,n){t.style.left=n.x+"px",t.style.top=n.y+"px",eventjs.prevent(e)}})},e.drag=function(t){t.gesture="drag",t.onPointerDown=function(r){e.pointerStart(r,n,t)&&(t.monitor||(eventjs.add(t.doc,"mousemove",t.onPointerMove),eventjs.add(t.doc,"mouseup",t.onPointerUp))),t.onPointerMove(r,"down")},t.onPointerMove=function(r,o){if(!t.tracker)return t.onPointerDown(r);for(var i=(t.bbox,r.changedTouches||e.getCoords(r)),s=i.length,a=0;s>a;a++){var u=i[a],v=u.identifier||1/0,f=t.tracker[v];f&&(f.pageX=u.pageX,f.pageY=u.pageY,n.state=o||"move",n.identifier=v,n.start=f.start,n.fingers=t.fingers,"differenceFromLast"===t.position?(n.x=f.pageX-f.offsetX,n.y=f.pageY-f.offsetY,f.offsetX=f.pageX,f.offsetY=f.pageY):(n.x=f.pageX-f.offsetX,n.y=f.pageY-f.offsetY),t.listener(r,n))}},t.onPointerUp=function(r){e.pointerEnd(r,n,t,t.onPointerMove)&&(t.monitor||(eventjs.remove(t.doc,"mousemove",t.onPointerMove),eventjs.remove(t.doc,"mouseup",t.onPointerUp)))};var n=e.pointerSetup(t);return t.event?t.onPointerDown(t.event):(eventjs.add(t.target,"mousedown",t.onPointerDown),t.monitor&&(eventjs.add(t.doc,"mousemove",t.onPointerMove),eventjs.add(t.doc,"mouseup",t.onPointerUp))),n},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.drag=e.drag,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";var t=Math.PI/180,n=function(e,t){var n=0,r=0,o=0;for(var i in t){var s=t[i];s.up||(n+=s.move.x,r+=s.move.y,o++)}return e.x=n/=o,e.y=r/=o,e};return e.gesture=function(r){r.gesture=r.gesture||"gesture",r.minFingers=r.minFingers||r.fingers||2,r.onPointerDown=function(t){var i=r.fingers;if(e.pointerStart(t,o,r)&&(eventjs.add(r.doc,"mousemove",r.onPointerMove),eventjs.add(r.doc,"mouseup",r.onPointerUp)),r.fingers===r.minFingers&&i!==r.fingers){o.fingers=r.minFingers,o.scale=1,o.rotation=0,o.state="start";var s="";for(var a in r.tracker)s+=a;o.identifier=parseInt(s),n(o,r.tracker),r.listener(t,o)}},r.onPointerMove=function(i){for(var s=r.bbox,a=r.tracker,u=i.changedTouches||e.getCoords(i),v=u.length,f=0;v>f;f++){var d=u[f],c=d.identifier||1/0,l=a[c];l&&(l.move.x=d.pageX-s.x1,l.move.y=d.pageY-s.y1)}if(!(r.fingers<r.minFingers)){var u=[],p=0,g=0;n(o,a);for(var c in a){var d=a[c];if(!d.up){var m=d.start;if(!m.distance){var y=m.x-o.x,h=m.y-o.y;m.distance=Math.sqrt(y*y+h*h),m.angle=Math.atan2(y,h)/t}var y=d.move.x-o.x,h=d.move.y-o.y,j=Math.sqrt(y*y+h*h);p+=j/m.distance;var w=Math.atan2(y,h)/t,b=(m.angle-w+360)%360-180;d.DEG2=d.DEG1,d.DEG1=b>0?b:-b,"undefined"!=typeof d.DEG2&&(b>0?d.rotation+=d.DEG1-d.DEG2:d.rotation-=d.DEG1-d.DEG2,g+=d.rotation),u.push(d.move)}}o.touches=u,o.fingers=r.fingers,o.scale=p/r.fingers,o.rotation=g/r.fingers,o.state="change",r.listener(i,o)}},r.onPointerUp=function(t){var n=r.fingers;e.pointerEnd(t,o,r)&&(eventjs.remove(r.doc,"mousemove",r.onPointerMove),eventjs.remove(r.doc,"mouseup",r.onPointerUp)),n===r.minFingers&&r.fingers<r.minFingers&&(o.fingers=r.fingers,o.state="end",r.listener(t,o))};var o=e.pointerSetup(r);return eventjs.add(r.target,"mousedown",r.onPointerDown),o},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.gesture=e.gesture,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.pointerdown=e.pointermove=e.pointerup=function(t){if(t.gesture=t.gesture||"pointer",!t.target.isPointerEmitter){var n=!0;t.onPointerDown=function(e){n=!1,r.gesture="pointerdown",t.listener(e,r)},t.onPointerMove=function(e){r.gesture="pointermove",t.listener(e,r,n)},t.onPointerUp=function(e){n=!0,r.gesture="pointerup",t.listener(e,r,!0)};var r=e.pointerSetup(t);return eventjs.add(t.target,"mousedown",t.onPointerDown),eventjs.add(t.target,"mousemove",t.onPointerMove),eventjs.add(t.doc,"mouseup",t.onPointerUp),t.target.isPointerEmitter=!0,r}},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.pointerdown=e.pointerdown,eventjs.Gesture._gestureHandlers.pointermove=e.pointermove,eventjs.Gesture._gestureHandlers.pointerup=e.pointerup,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.shake=function(e){var t={gesture:"devicemotion",acceleration:{},accelerationIncludingGravity:{},target:e.target,listener:e.listener,remove:function(){window.removeEventListener("devicemotion",v,!1)}},n=4,r=1e3,o=200,i=3,s=(new Date).getTime(),a={x:0,y:0,z:0},u={x:{count:0,value:0},y:{count:0,value:0},z:{count:0,value:0}},v=function(v){var f=.8,d=v.accelerationIncludingGravity;if(a.x=f*a.x+(1-f)*d.x,a.y=f*a.y+(1-f)*d.y,a.z=f*a.z+(1-f)*d.z,t.accelerationIncludingGravity=a,t.acceleration.x=d.x-a.x,t.acceleration.y=d.y-a.y,t.acceleration.z=d.z-a.z,"devicemotion"===e.gesture)return void e.listener(v,t);for(var c="xyz",l=(new Date).getTime(),p=0,g=c.length;g>p;p++){var m=c[p],y=t.acceleration[m],h=u[m],j=Math.abs(y);if(!(r>l-s)&&j>n){var w=l*y/j,b=Math.abs(w+h.value);h.value&&o>b?(h.value=w,h.count++,h.count===i&&(e.listener(v,t),s=l,h.value=0,h.count=0)):(h.value=w,h.count=1)}}};return window.addEventListener?(window.addEventListener("devicemotion",v,!1),t):void 0},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.shake=e.shake,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";var t=Math.PI/180;return e.swipe=function(n){n.snap=n.snap||90,n.threshold=n.threshold||1,n.gesture=n.gesture||"swipe",n.onPointerDown=function(t){e.pointerStart(t,r,n)&&(eventjs.add(n.doc,"mousemove",n.onPointerMove).listener(t),eventjs.add(n.doc,"mouseup",n.onPointerUp))},n.onPointerMove=function(t){for(var r=t.changedTouches||e.getCoords(t),o=r.length,i=0;o>i;i++){var s=r[i],a=s.identifier||1/0,u=n.tracker[a];u&&(u.move.x=s.pageX,u.move.y=s.pageY,u.moveTime=(new Date).getTime())}},n.onPointerUp=function(o){if(e.pointerEnd(o,r,n)){eventjs.remove(n.doc,"mousemove",n.onPointerMove),eventjs.remove(n.doc,"mouseup",n.onPointerUp);var i,s,a,u,v={x:0,y:0},f=0,d=0,c=0;for(var l in n.tracker){var p=n.tracker[l],g=p.move.x-p.start.x,m=p.move.y-p.start.y;f+=p.move.x,d+=p.move.y,v.x+=p.start.x,v.y+=p.start.y,c++;var y=Math.sqrt(g*g+m*m),h=p.moveTime-p.startTime,u=Math.atan2(g,m)/t+180,s=h?y/h:0;if("undefined"==typeof a)a=u,i=s;else{if(!(Math.abs(u-a)<=20))return;a=(a+u)/2,i=(i+s)/2}}var j=n.gestureFingers;n.minFingers<=j&&n.maxFingers>=j&&i>n.threshold&&(v.x/=c,v.y/=c,r.start=v,r.x=f/c,r.y=d/c,r.angle=-(((a/n.snap+.5>>0)*n.snap||360)-360),r.velocity=i,r.fingers=j,r.state="swipe",n.listener(o,r))}};var r=e.pointerSetup(n);return eventjs.add(n.target,"mousedown",n.onPointerDown),r},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.swipe=e.swipe,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.longpress=function(t){return t.gesture="longpress",e.tap(t)},e.tap=function(t){t.delay=t.delay||500,t.timeout=t.timeout||250,t.driftDeviance=t.driftDeviance||10,t.gesture=t.gesture||"tap";var n,r;t.onPointerDown=function(i){if(e.pointerStart(i,o,t)){if(n=(new Date).getTime(),eventjs.add(t.doc,"mousemove",t.onPointerMove).listener(i),eventjs.add(t.doc,"mouseup",t.onPointerUp),"longpress"!==t.gesture)return;r=setTimeout(function(){if(!(i.cancelBubble&&++i.cancelBubbleCount>1)){var e=0;for(var n in t.tracker){var r=t.tracker[n];if(r.end===!0)return;if(t.cancel)return;e++}t.minFingers<=e&&t.maxFingers>=e&&(o.state="start",o.fingers=e,o.x=r.start.x,o.y=r.start.y,t.listener(i,o))}},t.delay)}},t.onPointerMove=function(n){for(var r=t.bbox,o=n.changedTouches||e.getCoords(n),i=o.length,s=0;i>s;s++){var a=o[s],u=a.identifier||1/0,v=t.tracker[u];if(v){var f=a.pageX-r.x1,d=a.pageY-r.y1,c=f-v.start.x,l=d-v.start.y,p=Math.sqrt(c*c+l*l);if(!(f>0&&f<r.width&&d>0&&d<r.height&&p<=t.driftDeviance))return eventjs.remove(t.doc,"mousemove",t.onPointerMove),void(t.cancel=!0)}}},t.onPointerUp=function(i){if(e.pointerEnd(i,o,t)){if(clearTimeout(r),eventjs.remove(t.doc,"mousemove",t.onPointerMove),eventjs.remove(t.doc,"mouseup",t.onPointerUp),i.cancelBubble&&++i.cancelBubbleCount>1)return;if("longpress"===t.gesture)return void("start"===o.state&&(o.state="end",t.listener(i,o)));if(t.cancel)return;if((new Date).getTime()-n>t.timeout)return;var s=t.gestureFingers;t.minFingers<=s&&t.maxFingers>=s&&(o.state="tap",o.fingers=t.gestureFingers,t.listener(i,o))}};var o=e.pointerSetup(t);return eventjs.add(t.target,"mousedown",t.onPointerDown),o},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.tap=e.tap,eventjs.Gesture._gestureHandlers.longpress=e.longpress,e}(eventjs.proxy),"undefined"==typeof eventjs)var eventjs={};if("undefined"==typeof eventjs.proxy&&(eventjs.proxy={}),eventjs.proxy=function(e){"use strict";return e.wheelPreventElasticBounce=function(e){e&&("string"==typeof e&&(e=document.querySelector(e)),eventjs.add(e,"wheel",function(e,t){t.preventElasticBounce(),eventjs.stop(e)}))},e.wheel=function(e){var t,n=e.timeout||150,r=0,o={gesture:"wheel",state:"start",wheelDelta:0,target:e.target,listener:e.listener,preventElasticBounce:function(e){var t=this.target,n=t.scrollTop,r=n+t.offsetHeight,o=t.scrollHeight;r===o&&this.wheelDelta<=0?eventjs.cancel(e):0===n&&this.wheelDelta>=0&&eventjs.cancel(e),eventjs.stop(e)},add:function(){e.target[s](u,i,!1)},remove:function(){e.target[a](u,i,!1)}},i=function(i){i=i||window.event,o.state=r++?"change":"start",o.wheelDelta=i.detail?-20*i.detail:i.wheelDelta,e.listener(i,o),clearTimeout(t),t=setTimeout(function(){r=0,o.state="end",o.wheelDelta=0,e.listener(i,o)},n)},s=document.addEventListener?"addEventListener":"attachEvent",a=document.removeEventListener?"removeEventListener":"detachEvent",u=eventjs.getEventSupport("mousewheel")?"mousewheel":"DOMMouseScroll";return e.target[s](u,i,!1),o},eventjs.Gesture=eventjs.Gesture||{},eventjs.Gesture._gestureHandlers=eventjs.Gesture._gestureHandlers||{},eventjs.Gesture._gestureHandlers.wheel=e.wheel,e}(eventjs.proxy),"undefined"==typeof Event)var Event={};"undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(e){"use strict";return e.orientation=function(e){var t={gesture:"orientationchange",previous:null,current:window.orientation,target:e.target,listener:e.listener,remove:function(){window.removeEventListener("orientationchange",n,!1)}},n=function(n){return t.previous=t.current,t.current=window.orientation,null!==t.previous&&t.previous!=t.current?void e.listener(n,t):void 0};return window.DeviceOrientationEvent&&window.addEventListener("orientationchange",n,!1),t},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.orientation=e.orientation,e}(Event.proxy);!function(){function e(e,i){if(this.__eventListeners[e]){var r=this.__eventListeners[e];i?r[r.indexOf(i)]=!1:fabric.util.array.fill(r,!1)}}function i(e,i){if(this.__eventListeners||(this.__eventListeners={}),1===arguments.length)for(var r in e)this.on(r,e[r]);else this.__eventListeners[e]||(this.__eventListeners[e]=[]),this.__eventListeners[e].push(i);return this}function r(i,r){if(this.__eventListeners){if(0===arguments.length)for(i in this.__eventListeners)e.call(this,i);else if(1===arguments.length&&"object"==typeof arguments[0])for(var t in i)e.call(this,t,i[t]);else e.call(this,i,r);return this}}function t(e,i){if(this.__eventListeners){var r=this.__eventListeners[e];if(r){for(var t=0,n=r.length;n>t;t++)r[t]&&r[t].call(this,i||{});return this.__eventListeners[e]=r.filter(function(e){return e!==!1}),this}}}fabric.Observable={observe:i,stopObserving:r,fire:t,on:i,off:r,trigger:t}}();fabric.Collection={_objects:[],add:function(){if(this._objects.push.apply(this._objects,arguments),this._onObjectAdded)for(var e=0,t=arguments.length;t>e;e++)this._onObjectAdded(arguments[e]);return this.renderOnAddRemove&&this.requestRenderAll(),this},insertAt:function(e,t,n){var r=this.getObjects();return n?r[t]=e:r.splice(t,0,e),this._onObjectAdded&&this._onObjectAdded(e),this.renderOnAddRemove&&this.requestRenderAll(),this},remove:function(){for(var e,t=this.getObjects(),n=!1,r=0,i=arguments.length;i>r;r++)e=t.indexOf(arguments[r]),-1!==e&&(n=!0,t.splice(e,1),this._onObjectRemoved&&this._onObjectRemoved(arguments[r]));return this.renderOnAddRemove&&n&&this.requestRenderAll(),this},forEachObject:function(e,t){for(var n=this.getObjects(),r=0,i=n.length;i>r;r++)e.call(t,n[r],r,n);return this},getObjects:function(e){return"undefined"==typeof e?this._objects:this._objects.filter(function(t){return t.type===e})},item:function(e){return this.getObjects()[e]},isEmpty:function(){return 0===this.getObjects().length},size:function(){return this.getObjects().length},contains:function(e){return this.getObjects().indexOf(e)>-1},complexity:function(){return this.getObjects().reduce(function(e,t){return e+=t.complexity?t.complexity():0},0)}};fabric.CommonMethods={_setOptions:function(e){for(var i in e)this.set(i,e[i])},_initGradient:function(e,i){!e||!e.colorStops||e instanceof fabric.Gradient||this.set(i,new fabric.Gradient(e))},_initPattern:function(e,i,t){!e||!e.source||e instanceof fabric.Pattern?t&&t():this.set(i,new fabric.Pattern(e,t))},_initClipping:function(e){if(e.clipTo&&"string"==typeof e.clipTo){var i=fabric.util.getFunctionBody(e.clipTo);"undefined"!=typeof i&&(this.clipTo=new Function("ctx",i))}},_setObject:function(e){for(var i in e)this._set(i,e[i])},set:function(e,i){return"object"==typeof e?this._setObject(e):"function"==typeof i&&"clipTo"!==e?this._set(e,i(this.get(e))):this._set(e,i),this},_set:function(e,i){this[e]=i},toggle:function(e){var i=this.get(e);return"boolean"==typeof i&&this.set(e,!i),this},get:function(e){return this[e]}};!function(e){var t=Math.sqrt,n=Math.atan2,r=Math.pow,o=Math.abs,i=Math.PI/180,s=Math.PI/2;fabric.util={cos:function(e){if(0===e)return 1;0>e&&(e=-e);var t=e/s;switch(t){case 1:case 3:return 0;case 2:return-1}return Math.cos(e)},sin:function(e){if(0===e)return 0;var t=e/s,n=1;switch(0>e&&(n=-1),t){case 1:return n;case 2:return 0;case 3:return-n}return Math.sin(e)},removeFromArray:function(e,t){var n=e.indexOf(t);return-1!==n&&e.splice(n,1),e},getRandomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e},degreesToRadians:function(e){return e*i},radiansToDegrees:function(e){return e/i},rotatePoint:function(e,t,n){e.subtractEquals(t);var r=fabric.util.rotateVector(e,n);return new fabric.Point(r.x,r.y).addEquals(t)},rotateVector:function(e,t){var n=fabric.util.sin(t),r=fabric.util.cos(t),o=e.x*r-e.y*n,i=e.x*n+e.y*r;return{x:o,y:i}},transformPoint:function(e,t,n){return n?new fabric.Point(t[0]*e.x+t[2]*e.y,t[1]*e.x+t[3]*e.y):new fabric.Point(t[0]*e.x+t[2]*e.y+t[4],t[1]*e.x+t[3]*e.y+t[5])},makeBoundingBoxFromPoints:function(e){var t=[e[0].x,e[1].x,e[2].x,e[3].x],n=fabric.util.array.min(t),r=fabric.util.array.max(t),o=r-n,i=[e[0].y,e[1].y,e[2].y,e[3].y],s=fabric.util.array.min(i),a=fabric.util.array.max(i),u=a-s;return{left:n,top:s,width:o,height:u}},invertTransform:function(e){var t=1/(e[0]*e[3]-e[1]*e[2]),n=[t*e[3],-t*e[1],-t*e[2],t*e[0]],r=fabric.util.transformPoint({x:e[4],y:e[5]},n,!0);return n[4]=-r.x,n[5]=-r.y,n},toFixed:function(e,t){return parseFloat(Number(e).toFixed(t))},parseUnit:function(e,t){var n=/\D{0,2}$/.exec(e),r=parseFloat(e);switch(t||(t=fabric.Text.DEFAULT_SVG_FONT_SIZE),n[0]){case"mm":return r*fabric.DPI/25.4;case"cm":return r*fabric.DPI/2.54;case"in":return r*fabric.DPI;case"pt":return r*fabric.DPI/72;case"pc":return r*fabric.DPI/72*12;case"em":return r*t;default:return r}},falseFunction:function(){return!1},getKlass:function(e,t){return e=fabric.util.string.camelize(e.charAt(0).toUpperCase()+e.slice(1)),fabric.util.resolveNamespace(t)[e]},getSvgAttributes:function(e){var t=["instantiated_by_use","style","id","class"];switch(e){case"linearGradient":t=t.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);break;case"radialGradient":t=t.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);break;case"stop":t=t.concat(["offset","stop-color","stop-opacity"])}return t},resolveNamespace:function(t){if(!t)return fabric;var n,r=t.split("."),o=r.length,i=e||fabric.window;for(n=0;o>n;++n)i=i[r[n]];return i},loadImage:function(e,t,n,r){if(!e)return void(t&&t.call(n,e));var o=fabric.util.createImage(),i=function(){t&&t.call(n,o),o=o.onload=o.onerror=null};o.onload=i,o.onerror=function(){fabric.log("Error loading "+o.src),t&&t.call(n,null,!0),o=o.onload=o.onerror=null},0!==e.indexOf("data")&&r&&(o.crossOrigin=r),"data:image/svg"===e.substring(0,14)&&(o.onload=null,fabric.util.loadImageInDom(o,i)),o.src=e},loadImageInDom:function(e,t){var n=fabric.document.createElement("div");n.style.width=n.style.height="1px",n.style.left=n.style.top="-100%",n.style.position="absolute",n.appendChild(e),fabric.document.querySelector("body").appendChild(n),e.onload=function(){t(),n.parentNode.removeChild(n),n=null}},enlivenObjects:function(e,t,n,r){function o(){++s===a&&t&&t(i)}e=e||[];var i=[],s=0,a=e.length;return a?void e.forEach(function(e,t){if(!e||!e.type)return void o();var s=fabric.util.getKlass(e.type,n);s.fromObject(e,function(n,s){s||(i[t]=n),r&&r(e,n,s),o()})}):void(t&&t(i))},enlivenPatterns:function(e,t){function n(){++o===i&&t&&t(r)}e=e||[];var r=[],o=0,i=e.length;return i?void e.forEach(function(e,t){e&&e.source?new fabric.Pattern(e,function(e){r[t]=e,n()}):(r[t]=e,n())}):void(t&&t(r))},groupSVGElements:function(e,t,n){var r;return 1===e.length?e[0]:(t&&(t.width&&t.height?t.centerPoint={x:t.width/2,y:t.height/2}:(delete t.width,delete t.height)),r=new fabric.Group(e,t),"undefined"!=typeof n&&(r.sourcePath=n),r)},populateWithProperties:function(e,t,n){if(n&&"[object Array]"===Object.prototype.toString.call(n))for(var r=0,o=n.length;o>r;r++)n[r]in e&&(t[n[r]]=e[n[r]])},drawDashedLine:function(e,r,o,i,s,a){var u=i-r,c=s-o,f=t(u*u+c*c),d=n(c,u),v=a.length,l=0,p=!0;for(e.save(),e.translate(r,o),e.moveTo(0,0),e.rotate(d),r=0;f>r;)r+=a[l++%v],r>f&&(r=f),e[p?"lineTo":"moveTo"](r,0),p=!p;e.restore()},createCanvasElement:function(){return fabric.document.createElement("canvas")},copyCanvasElement:function(e){var t=fabric.document.createElement("canvas");return t.width=e.width,t.height=e.height,t.getContext("2d").drawImage(e,0,0),t},createImage:function(){return fabric.document.createElement("img")},clipContext:function(e,t){t.save(),t.beginPath(),e.clipTo(t),t.clip()},multiplyTransformMatrices:function(e,t,n){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],n?0:e[0]*t[4]+e[2]*t[5]+e[4],n?0:e[1]*t[4]+e[3]*t[5]+e[5]]},qrDecompose:function(e){var o=n(e[1],e[0]),s=r(e[0],2)+r(e[1],2),a=t(s),u=(e[0]*e[3]-e[2]*e[1])/a,c=n(e[0]*e[2]+e[1]*e[3],s);return{angle:o/i,scaleX:a,scaleY:u,skewX:c/i,skewY:0,translateX:e[4],translateY:e[5]}},customTransformMatrix:function(e,t,n){var r=[1,0,o(Math.tan(n*i)),1],s=[o(e),0,0,o(t)];return fabric.util.multiplyTransformMatrices(s,r,!0)},resetObjectTransform:function(e){e.scaleX=1,e.scaleY=1,e.skewX=0,e.skewY=0,e.flipX=!1,e.flipY=!1,e.rotate(0)},getFunctionBody:function(e){return(String(e).match(/function[^{]*\{([\s\S]*)\}/)||{})[1]},isTransparent:function(e,t,n,r){r>0&&(t>r?t-=r:t=0,n>r?n-=r:n=0);var o,i,s=!0,a=e.getImageData(t,n,2*r||1,2*r||1),u=a.data.length;for(o=3;u>o&&(i=a.data[o],s=0>=i,s!==!1);o+=4);return a=null,s},parsePreserveAspectRatioAttribute:function(e){var t,n="meet",r="Mid",o="Mid",i=e.split(" ");return i&&i.length&&(n=i.pop(),"meet"!==n&&"slice"!==n?(t=n,n="meet"):i.length&&(t=i.pop())),r="none"!==t?t.slice(1,4):"none",o="none"!==t?t.slice(5,8):"none",{meetOrSlice:n,alignX:r,alignY:o}},clearFabricFontCache:function(e){e=(e||"").toLowerCase(),e?fabric.charWidthsCache[e]&&delete fabric.charWidthsCache[e]:fabric.charWidthsCache={}},limitDimsByArea:function(e,t){var n=Math.sqrt(t*e),r=Math.floor(t/n);return{x:Math.floor(n),y:r}},capValue:function(e,t,n){return Math.max(e,Math.min(t,n))},findScaleToFit:function(e,t){return Math.min(t.width/e.width,t.height/e.height)},findScaleToCover:function(e,t){return Math.max(t.width/e.width,t.height/e.height)}}}("undefined"!=typeof exports?exports:this);!function(){fabric.util.createAccessors=function(e){var t,n,r,o,i,s=e.prototype;for(t=s.stateProperties.length;t--;)n=s.stateProperties[t],r=n.charAt(0).toUpperCase()+n.slice(1),o="set"+r,i="get"+r,s[i]||(s[i]=function(e){return new Function('return this.get("'+e+'")')}(n)),s[o]||(s[o]=function(e){return new Function("value",'return this.set("'+e+'", value)')}(n))}}("undefined"!=typeof exports?exports:this);!function(){function e(e,r,i,s,u,c,f){var v=a.call(arguments);if(o[v])return o[v];var d=Math.PI,l=f*d/180,p=fabric.util.sin(l),g=fabric.util.cos(l),m=0,h=0;i=Math.abs(i),s=Math.abs(s);var y=-g*e*.5-p*r*.5,b=-g*r*.5+p*e*.5,w=i*i,j=s*s,x=b*b,P=y*y,M=w*j-w*x-j*P,E=0;if(0>M){var T=Math.sqrt(1-M/(w*j));i*=T,s*=T}else E=(u===c?-1:1)*Math.sqrt(M/(w*x+j*P));var L=E*i*b/s,G=-E*s*y/i,D=g*L-p*G+.5*e,_=p*L+g*G+.5*r,C=n(1,0,(y-L)/i,(b-G)/s),S=n((y-L)/i,(b-G)/s,(-y-L)/i,(-b-G)/s);0===c&&S>0?S-=2*d:1===c&&0>S&&(S+=2*d);for(var F=Math.ceil(Math.abs(S/d*2)),k=[],X=S/F,Y=8/3*Math.sin(X/4)*Math.sin(X/4)/Math.sin(X/2),O=C+X,H=0;F>H;H++)k[H]=t(C,O,g,p,i,s,D,_,Y,m,h),m=k[H][4],h=k[H][5],C=O,O+=X;return o[v]=k,k}function t(e,t,n,r,o,s,u,c,f,v,d){var l=a.call(arguments);if(i[l])return i[l];var p=fabric.util.cos(e),g=fabric.util.sin(e),m=fabric.util.cos(t),h=fabric.util.sin(t),y=n*o*m-r*s*h+u,b=r*o*m+n*s*h+c,w=v+f*(-n*o*g-r*s*p),j=d+f*(-r*o*g+n*s*p),x=y+f*(n*o*h+r*s*m),P=b+f*(r*o*h-n*s*m);return i[l]=[w,j,x,P,y,b],i[l]}function n(e,t,n,r){var o=Math.atan2(t,e),i=Math.atan2(r,n);return i>=o?i-o:2*Math.PI-(o-i)}function r(e,t,n,r,o,i,u,c){var f=a.call(arguments);if(s[f])return s[f];var v,d,l,p,g,m,h,y,b=Math.sqrt,w=Math.min,j=Math.max,x=Math.abs,P=[],M=[[],[]];d=6*e-12*n+6*o,v=-3*e+9*n-9*o+3*u,l=3*n-3*e;for(var E=0;2>E;++E)if(E>0&&(d=6*t-12*r+6*i,v=-3*t+9*r-9*i+3*c,l=3*r-3*t),x(v)<1e-12){if(x(d)<1e-12)continue;p=-l/d,p>0&&1>p&&P.push(p)}else h=d*d-4*l*v,0>h||(y=b(h),g=(-d+y)/(2*v),g>0&&1>g&&P.push(g),m=(-d-y)/(2*v),m>0&&1>m&&P.push(m));for(var T,L,G,D=P.length,_=D;D--;)p=P[D],G=1-p,T=G*G*G*e+3*G*G*p*n+3*G*p*p*o+p*p*p*u,M[0][D]=T,L=G*G*G*t+3*G*G*p*r+3*G*p*p*i+p*p*p*c,M[1][D]=L;M[0][_]=e,M[1][_]=t,M[0][_+1]=u,M[1][_+1]=c;var C=[{x:w.apply(null,M[0]),y:w.apply(null,M[1])},{x:j.apply(null,M[0]),y:j.apply(null,M[1])}];return s[f]=C,C}var o={},i={},s={},a=Array.prototype.join;fabric.util.drawArc=function(t,n,r,o){for(var i=o[0],s=o[1],a=o[2],u=o[3],c=o[4],f=o[5],v=o[6],d=[[],[],[],[]],l=e(f-n,v-r,i,s,u,c,a),p=0,g=l.length;g>p;p++)d[p][0]=l[p][0]+n,d[p][1]=l[p][1]+r,d[p][2]=l[p][2]+n,d[p][3]=l[p][3]+r,d[p][4]=l[p][4]+n,d[p][5]=l[p][5]+r,t.bezierCurveTo.apply(t,d[p])},fabric.util.getBoundsOfArc=function(t,n,o,i,s,a,u,c,f){for(var v,d=0,l=0,p=[],g=e(c-t,f-n,o,i,a,u,s),m=0,h=g.length;h>m;m++)v=r(d,l,g[m][0],g[m][1],g[m][2],g[m][3],g[m][4],g[m][5]),p.push({x:v[0].x+t,y:v[0].y+n}),p.push({x:v[1].x+t,y:v[1].y+n}),d=g[m][4],l=g[m][5];return p},fabric.util.getBoundsOfCurve=r}();!function(){function e(e,t){for(var n=i.call(arguments,2),r=[],o=0,s=e.length;s>o;o++)r[o]=n.length?e[o][t].apply(e[o],n):e[o][t].call(e[o]);return r}function t(e,t){return o(e,t,function(e,t){return e>=t})}function n(e,t){return o(e,t,function(e,t){return t>e})}function r(e,t){for(var n=e.length;n--;)e[n]=t;return e}function o(e,t,n){if(e&&0!==e.length){var r=e.length-1,o=t?e[r][t]:e[r];if(t)for(;r--;)n(e[r][t],o)&&(o=e[r][t]);else for(;r--;)n(e[r],o)&&(o=e[r]);return o}}var i=Array.prototype.slice;fabric.util.array={fill:r,invoke:e,min:n,max:t}}();!function(){function e(t,n,r){if(r)if(!fabric.isLikelyNode&&n instanceof Element)t=n;else if(n instanceof Array){t=[];for(var o=0,i=n.length;i>o;o++)t[o]=e({},n[o],r)}else if(n&&"object"==typeof n)for(var s in n)n.hasOwnProperty(s)&&(t[s]=e({},n[s],r));else t=n;else for(var s in n)t[s]=n[s];return t}function t(t,n){return e({},t,n)}fabric.util.object={extend:e,clone:t},fabric.util.object.extend(fabric.util,fabric.Observable)}();!function(){function e(e){return e.replace(/-+(.)?/g,function(e,t){return t?t.toUpperCase():""})}function t(e,t){return e.charAt(0).toUpperCase()+(t?e.slice(1):e.slice(1).toLowerCase())}function n(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function r(e){var t,n=0,r=[];for(n=0,t;n<e.length;n++)(t=o(e,n))!==!1&&r.push(t);return r}function o(e,t){var n=e.charCodeAt(t);if(isNaN(n))return"";if(55296>n||n>57343)return e.charAt(t);if(n>=55296&&56319>=n){if(e.length<=t+1)throw"High surrogate without following low surrogate";var r=e.charCodeAt(t+1);if(56320>r||r>57343)throw"High surrogate without following low surrogate";return e.charAt(t)+e.charAt(t+1)}if(0===t)throw"Low surrogate without preceding high surrogate";var o=e.charCodeAt(t-1);if(55296>o||o>56319)throw"Low surrogate without preceding high surrogate";return!1}fabric.util.string={camelize:e,capitalize:t,escapeXml:n,graphemeSplit:r}}();!function(){function e(){}function t(e){for(var t=null,n=this;n.constructor.superclass;){var o=n.constructor.superclass.prototype[e];if(n[e]!==o){t=o;break}n=n.constructor.superclass.prototype}return t?arguments.length>1?t.apply(this,r.call(arguments,1)):t.call(this):console.log("tried to callSuper "+e+", method not found in prototype chain",this)}function n(){function n(){this.initialize.apply(this,arguments)}var i=null,s=r.call(arguments,0);"function"==typeof s[0]&&(i=s.shift()),n.superclass=i,n.subclasses=[],i&&(e.prototype=i.prototype,n.prototype=new e,i.subclasses.push(n));for(var u=0,c=s.length;c>u;u++)a(n,s[u],i);return n.prototype.initialize||(n.prototype.initialize=o),n.prototype.constructor=n,n.prototype.callSuper=t,n}var r=Array.prototype.slice,o=function(){},i=function(){for(var e in{toString:1})if("toString"===e)return!1;return!0}(),a=function(e,t,n){for(var r in t)e.prototype[r]=r in e.prototype&&"function"==typeof e.prototype[r]&&(t[r]+"").indexOf("callSuper")>-1?function(e){return function(){var r=this.constructor.superclass;this.constructor.superclass=n;var o=t[e].apply(this,arguments);return this.constructor.superclass=r,"initialize"!==e?o:void 0}}(r):t[r],i&&(t.toString!==Object.prototype.toString&&(e.prototype.toString=t.toString),t.valueOf!==Object.prototype.valueOf&&(e.prototype.valueOf=t.valueOf))};fabric.util.createClass=n}();!function(){function e(e){var t,n,r=Array.prototype.slice.call(arguments,1),o=r.length;for(n=0;o>n;n++)if(t=typeof e[r[n]],!/^(?:function|object|unknown)$/.test(t))return!1;return!0}function t(e,t){return{handler:t,wrappedHandler:n(e,t)}}function n(e,t){return function(n){t.call(a(e),n||fabric.window.event)}}function r(e,t){return function(n){if(g[e]&&g[e][t])for(var r=g[e][t],o=0,i=r.length;i>o;o++)r[o].call(this,n||fabric.window.event)}}function o(e){e||(e=fabric.window.event);var t=e.target||(typeof e.srcElement!==u?e.srcElement:null),n=fabric.util.getScrollLeftTop(t);return{x:m(e)+n.left,y:h(e)+n.top}}function i(e,t,n){var r,o="touchend"===e.type?"changedTouches":"touches",i=e[o];return i&&i[0]&&(r=i[0][n]),"undefined"==typeof r&&(r=e[n]),r}var a,s,u="unknown",c=function(){var e=0;return function(t){return t.__uniqueID||(t.__uniqueID="uniqueID__"+e++)}}();!function(){var e={};a=function(t){return e[t]},s=function(t,n){e[t]=n}}();var f,l,v=e(fabric.document.documentElement,"addEventListener","removeEventListener")&&e(fabric.window,"addEventListener","removeEventListener"),d=e(fabric.document.documentElement,"attachEvent","detachEvent")&&e(fabric.window,"attachEvent","detachEvent"),p={},g={};v?(f=function(e,t,n,r){e&&e.addEventListener(t,n,d?!1:r)},l=function(e,t,n,r){e&&e.removeEventListener(t,n,d?!1:r)}):d?(f=function(e,n,r){if(e){var o=c(e);s(o,e),p[o]||(p[o]={}),p[o][n]||(p[o][n]=[]);var i=t(o,r);p[o][n].push(i),e.attachEvent("on"+n,i.wrappedHandler)}},l=function(e,t,n){if(e){var r,o=c(e);if(p[o]&&p[o][t])for(var i=0,a=p[o][t].length;a>i;i++)r=p[o][t][i],r&&r.handler===n&&(e.detachEvent("on"+t,r.wrappedHandler),p[o][t][i]=null)}}):(f=function(e,t,n){if(e){var o=c(e);if(g[o]||(g[o]={}),!g[o][t]){g[o][t]=[];var i=e["on"+t];i&&g[o][t].push(i),e["on"+t]=r(o,t)}g[o][t].push(n)}},l=function(e,t,n){if(e){var r=c(e);if(g[r]&&g[r][t])for(var o=g[r][t],i=0,a=o.length;a>i;i++)o[i]===n&&o.splice(i,1)}}),fabric.util.addListener=f,fabric.util.removeListener=l;var m=function(e){return e.clientX},h=function(e){return e.clientY};fabric.isTouchSupported&&(m=function(e){return i(e,"pageX","clientX")},h=function(e){return i(e,"pageY","clientY")}),fabric.util.getPointer=o}();!function(){function e(e,t){var n=e.style;if(!n)return e;if("string"==typeof t)return e.style.cssText+=";"+t,t.indexOf("opacity")>-1?i(e,t.match(/opacity:\s*(\d?\.?\d*)/)[1]):e;for(var r in t)if("opacity"===r)i(e,t[r]);else{var o="float"===r||"cssFloat"===r?"undefined"==typeof n.styleFloat?"cssFloat":"styleFloat":r;n[o]=t[r]}return e}var t=fabric.document.createElement("div"),n="string"==typeof t.style.opacity,r="string"==typeof t.style.filter,o=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,i=function(e){return e};n?i=function(e,t){return e.style.opacity=t,e}:r&&(i=function(e,t){var n=e.style;return e.currentStyle&&!e.currentStyle.hasLayout&&(n.zoom=1),o.test(n.filter)?(t=t>=.9999?"":"alpha(opacity="+100*t+")",n.filter=n.filter.replace(o,t)):n.filter+=" alpha(opacity="+100*t+")",e}),fabric.util.setStyle=e}();!function(){function e(e){return"string"==typeof e?fabric.document.getElementById(e):e}function t(e,t){var n=fabric.document.createElement(e);for(var r in t)"class"===r?n.className=t[r]:"for"===r?n.htmlFor=t[r]:n.setAttribute(r,t[r]);return n}function n(e,t){e&&-1===(" "+e.className+" ").indexOf(" "+t+" ")&&(e.className+=(e.className?" ":"")+t)}function r(e,n,r){return"string"==typeof n&&(n=t(n,r)),e.parentNode&&e.parentNode.replaceChild(n,e),n.appendChild(e),n}function o(e){for(var t=0,n=0,r=fabric.document.documentElement,o=fabric.document.body||{scrollLeft:0,scrollTop:0};e&&(e.parentNode||e.host)&&(e=e.parentNode||e.host,e===fabric.document?(t=o.scrollLeft||r.scrollLeft||0,n=o.scrollTop||r.scrollTop||0):(t+=e.scrollLeft||0,n+=e.scrollTop||0),1!==e.nodeType||"fixed"!==e.style.position););return{left:t,top:n}}function i(e){var t,n,r=e&&e.ownerDocument,i={left:0,top:0},a={left:0,top:0},s={borderLeftWidth:"left",borderTopWidth:"top",paddingLeft:"left",paddingTop:"top"};if(!r)return a;for(var u in s)a[s[u]]+=parseInt(l(e,u),10)||0;return t=r.documentElement,"undefined"!=typeof e.getBoundingClientRect&&(i=e.getBoundingClientRect()),n=o(e),{left:i.left+n.left-(t.clientLeft||0)+a.left,top:i.top+n.top-(t.clientTop||0)+a.top}}function a(e){var t=fabric.jsdomImplForWrapper(e);return t._canvas||t._image}var s,u=Array.prototype.slice,c=function(e){return u.call(e,0)};try{s=c(fabric.document.childNodes)instanceof Array}catch(f){}s||(c=function(e){for(var t=new Array(e.length),n=e.length;n--;)t[n]=e[n];return t});var l;l=fabric.document.defaultView&&fabric.document.defaultView.getComputedStyle?function(e,t){var n=fabric.document.defaultView.getComputedStyle(e,null);return n?n[t]:void 0}:function(e,t){var n=e.style[t];return!n&&e.currentStyle&&(n=e.currentStyle[t]),n},function(){function e(e){return"undefined"!=typeof e.onselectstart&&(e.onselectstart=fabric.util.falseFunction),r?e.style[r]="none":"string"==typeof e.unselectable&&(e.unselectable="on"),e}function t(e){return"undefined"!=typeof e.onselectstart&&(e.onselectstart=null),r?e.style[r]="":"string"==typeof e.unselectable&&(e.unselectable=""),e}var n=fabric.document.documentElement.style,r="userSelect"in n?"userSelect":"MozUserSelect"in n?"MozUserSelect":"WebkitUserSelect"in n?"WebkitUserSelect":"KhtmlUserSelect"in n?"KhtmlUserSelect":"";fabric.util.makeElementUnselectable=e,fabric.util.makeElementSelectable=t}(),function(){function e(e,t){var n=fabric.document.getElementsByTagName("head")[0],r=fabric.document.createElement("script"),o=!0;r.onload=r.onreadystatechange=function(e){if(o){if("string"==typeof this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)return;o=!1,t(e||fabric.window.event),r=r.onload=r.onreadystatechange=null}},r.src=e,n.appendChild(r)}fabric.util.getScript=e}(),fabric.util.getById=e,fabric.util.toArray=c,fabric.util.makeElement=t,fabric.util.addClass=n,fabric.util.wrapElement=r,fabric.util.getScrollLeftTop=o,fabric.util.getElementOffset=i,fabric.util.getElementStyle=l,fabric.util.getNodeCanvas=a}();!function(){function e(e,t){return e+(/\?/.test(e)?"&":"?")+t}function t(){}function n(n,o){o||(o={});var i=o.method?o.method.toUpperCase():"GET",a=o.onComplete||function(){},s=r(),u=o.body||o.parameters;return s.onreadystatechange=function(){4===s.readyState&&(a(s),s.onreadystatechange=t)},"GET"===i&&(u=null,"string"==typeof o.parameters&&(n=e(n,o.parameters))),s.open(i,n,!0),("POST"===i||"PUT"===i)&&s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.send(u),s}var r=function(){for(var e=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest}],t=e.length;t--;)try{var n=e[t]();if(n)return e[t]}catch(r){}}();fabric.util.request=n}();fabric.log=function(){},fabric.warn=function(){},"undefined"!=typeof console&&["log","warn"].forEach(function(e){"undefined"!=typeof console[e]&&"function"==typeof console[e].apply&&(fabric[e]=function(){return console[e].apply(console,arguments)})});!function(){function e(){return!1}function t(t){n(function(r){t||(t={});var o,i=r||+new Date,a=t.duration||500,s=i+a,u=t.onChange||e,c=t.abort||e,f=t.onComplete||e,l=t.easing||function(e,t,n,r){return-n*Math.cos(e/r*(Math.PI/2))+n+t},d="startValue"in t?t.startValue:0,v="endValue"in t?t.endValue:100,p=t.byValue||v-d;t.onStart&&t.onStart(),function g(e){if(c())return void f(v,1,1);o=e||+new Date;var r=o>s?a:o-i,m=r/a,h=l(r,d,p,a),y=Math.abs((h-d)/p);return u(h,y,m),o>s?void(t.onComplete&&t.onComplete()):void n(g)}(i)})}function n(){return o.apply(fabric.window,arguments)}function r(){return i.apply(fabric.window,arguments)}var o=fabric.window.requestAnimationFrame||fabric.window.webkitRequestAnimationFrame||fabric.window.mozRequestAnimationFrame||fabric.window.oRequestAnimationFrame||fabric.window.msRequestAnimationFrame||function(e){return fabric.window.setTimeout(e,1e3/60)},i=fabric.window.cancelAnimationFrame||fabric.window.clearTimeout;fabric.util.animate=t,fabric.util.requestAnimFrame=n,fabric.util.cancelAnimFrame=r}();!function(){function e(e,t,n){var r="rgba("+parseInt(e[0]+n*(t[0]-e[0]),10)+","+parseInt(e[1]+n*(t[1]-e[1]),10)+","+parseInt(e[2]+n*(t[2]-e[2]),10);return r+=","+(e&&t?parseFloat(e[3]+n*(t[3]-e[3])):1),r+=")"}function t(t,n,r,o){var i=new fabric.Color(t).getSource(),a=new fabric.Color(n).getSource();o=o||{},fabric.util.animate(fabric.util.object.extend(o,{duration:r||500,startValue:i,endValue:a,byValue:a,easing:function(t,n,r,i){var a=o.colorEasing?o.colorEasing(t,i):1-Math.cos(t/i*(Math.PI/2));return e(n,r,a)}}))}fabric.util.animateColor=t}();!function(){function e(e,t,n,r){return e<Math.abs(t)?(e=t,r=n/4):r=0===t&&0===e?n/(2*Math.PI)*Math.asin(1):n/(2*Math.PI)*Math.asin(t/e),{a:e,c:t,p:n,s:r}}function t(e,t,n){return e.a*Math.pow(2,10*(t-=1))*Math.sin(2*(t*n-e.s)*Math.PI/e.p)}function n(e,t,n,r){return n*((e=e/r-1)*e*e+1)+t}function r(e,t,n,r){return e/=r/2,1>e?n/2*e*e*e+t:n/2*((e-=2)*e*e+2)+t}function o(e,t,n,r){return n*(e/=r)*e*e*e+t}function i(e,t,n,r){return-n*((e=e/r-1)*e*e*e-1)+t}function a(e,t,n,r){return e/=r/2,1>e?n/2*e*e*e*e+t:-n/2*((e-=2)*e*e*e-2)+t}function s(e,t,n,r){return n*(e/=r)*e*e*e*e+t}function u(e,t,n,r){return n*((e=e/r-1)*e*e*e*e+1)+t}function c(e,t,n,r){return e/=r/2,1>e?n/2*e*e*e*e*e+t:n/2*((e-=2)*e*e*e*e+2)+t}function f(e,t,n,r){return-n*Math.cos(e/r*(Math.PI/2))+n+t}function l(e,t,n,r){return n*Math.sin(e/r*(Math.PI/2))+t}function d(e,t,n,r){return-n/2*(Math.cos(Math.PI*e/r)-1)+t}function v(e,t,n,r){return 0===e?t:n*Math.pow(2,10*(e/r-1))+t}function p(e,t,n,r){return e===r?t+n:n*(-Math.pow(2,-10*e/r)+1)+t}function g(e,t,n,r){return 0===e?t:e===r?t+n:(e/=r/2,1>e?n/2*Math.pow(2,10*(e-1))+t:n/2*(-Math.pow(2,-10*--e)+2)+t)}function m(e,t,n,r){return-n*(Math.sqrt(1-(e/=r)*e)-1)+t}function h(e,t,n,r){return n*Math.sqrt(1-(e=e/r-1)*e)+t}function y(e,t,n,r){return e/=r/2,1>e?-n/2*(Math.sqrt(1-e*e)-1)+t:n/2*(Math.sqrt(1-(e-=2)*e)+1)+t}function b(n,r,o,i){var a=1.70158,s=0,u=o;if(0===n)return r;if(n/=i,1===n)return r+o;s||(s=.3*i);var c=e(u,o,s,a);return-t(c,n,i)+r}function w(t,n,r,o){var i=1.70158,a=0,s=r;if(0===t)return n;if(t/=o,1===t)return n+r;a||(a=.3*o);var u=e(s,r,a,i);return u.a*Math.pow(2,-10*t)*Math.sin(2*(t*o-u.s)*Math.PI/u.p)+u.c+n}function j(n,r,o,i){var a=1.70158,s=0,u=o;if(0===n)return r;if(n/=i/2,2===n)return r+o;s||(s=.3*i*1.5);var c=e(u,o,s,a);return 1>n?-.5*t(c,n,i)+r:c.a*Math.pow(2,-10*(n-=1))*Math.sin(2*(n*i-c.s)*Math.PI/c.p)*.5+c.c+r}function x(e,t,n,r,o){return void 0===o&&(o=1.70158),n*(e/=r)*e*((o+1)*e-o)+t}function M(e,t,n,r,o){return void 0===o&&(o=1.70158),n*((e=e/r-1)*e*((o+1)*e+o)+1)+t}function E(e,t,n,r,o){return void 0===o&&(o=1.70158),e/=r/2,1>e?n/2*e*e*(((o*=1.525)+1)*e-o)+t:n/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+t}function P(e,t,n,r){return n-T(r-e,0,n,r)+t}function T(e,t,n,r){return(e/=r)<1/2.75?7.5625*n*e*e+t:2/2.75>e?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:2.5/2.75>e?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t}function S(e,t,n,r){return r/2>e?.5*P(2*e,0,n,r)+t:.5*T(2*e-r,0,n,r)+.5*n+t}fabric.util.ease={easeInQuad:function(e,t,n,r){return n*(e/=r)*e+t},easeOutQuad:function(e,t,n,r){return-n*(e/=r)*(e-2)+t},easeInOutQuad:function(e,t,n,r){return e/=r/2,1>e?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t},easeInCubic:function(e,t,n,r){return n*(e/=r)*e*e+t},easeOutCubic:n,easeInOutCubic:r,easeInQuart:o,easeOutQuart:i,easeInOutQuart:a,easeInQuint:s,easeOutQuint:u,easeInOutQuint:c,easeInSine:f,easeOutSine:l,easeInOutSine:d,easeInExpo:v,easeOutExpo:p,easeInOutExpo:g,easeInCirc:m,easeOutCirc:h,easeInOutCirc:y,easeInElastic:b,easeOutElastic:w,easeInOutElastic:j,easeInBack:x,easeOutBack:M,easeInOutBack:E,easeInBounce:P,easeOutBounce:T,easeInOutBounce:S}}();!function(e){"use strict";function t(e){return e in T?T[e]:e}function n(e,t,n,r){var i,o="[object Array]"===Object.prototype.toString.call(t);if("fill"!==e&&"stroke"!==e||"none"!==t)if("strokeDashArray"===e)t="none"===t?null:t.replace(/,/g," ").split(/\s+/).map(function(e){return parseFloat(e)});else if("transformMatrix"===e)t=n&&n.transformMatrix?x(n.transformMatrix,m.parseTransformAttribute(t)):m.parseTransformAttribute(t);else if("visible"===e)t="none"!==t&&"hidden"!==t,n&&n.visible===!1&&(t=!1);else if("opacity"===e)t=parseFloat(t),n&&"undefined"!=typeof n.opacity&&(t*=n.opacity);else if("textAnchor"===e)t="start"===t?"left":"end"===t?"right":"center";else if("charSpacing"===e)i=w(t,r)/r*1e3;else if("paintFirst"===e){var a=t.indexOf("fill"),s=t.indexOf("stroke"),t="fill";a>-1&&s>-1&&a>s?t="stroke":-1===a&&s>-1&&(t="stroke")}else i=o?t.map(w):w(t,r);else t="";return!o&&isNaN(i)?t:i}function r(e){return new RegExp("^("+e.join("|")+")\\b","i")}function i(e){for(var t in S)if("undefined"!=typeof e[S[t]]&&""!==e[t]){if("undefined"==typeof e[t]){if(!m.Object.prototype[t])continue;e[t]=m.Object.prototype[t]}if(0!==e[t].indexOf("url(")){var n=new m.Color(e[t]);e[t]=n.setAlpha(b(n.getAlpha()*e[S[t]],2)).toRgba()}}return e}function o(e,t){var n,r,i,o,a=[];for(i=0,o=t.length;o>i;i++)n=t[i],r=e.getElementsByTagName(n),a=a.concat(Array.prototype.slice.call(r));return a}function a(e,t){var n,r;e.replace(/;\s*$/,"").split(";").forEach(function(e){var i=e.split(":");n=i[0].trim().toLowerCase(),r=i[1].trim(),t[n]=r})}function s(e,t){var n,r;for(var i in e)"undefined"!=typeof e[i]&&(n=i.toLowerCase(),r=e[i],t[n]=r)}function u(e,t){var n={};for(var r in m.cssRules[t])if(c(e,r.split(" ")))for(var i in m.cssRules[t][r])n[i]=m.cssRules[t][r][i];return n}function c(e,t){var n,r=!0;return n=l(e,t.pop()),n&&t.length&&(r=f(e,t)),n&&r&&0===t.length}function f(e,t){for(var n,r=!0;e.parentNode&&1===e.parentNode.nodeType&&t.length;)r&&(n=t.pop()),e=e.parentNode,r=l(e,n);return 0===t.length}function l(e,t){var n,r,i=e.nodeName,o=e.getAttribute("class"),a=e.getAttribute("id");if(n=new RegExp("^"+i,"i"),t=t.replace(n,""),a&&t.length&&(n=new RegExp("#"+a+"(?![a-zA-Z\\-]+)","i"),t=t.replace(n,"")),o&&t.length)for(o=o.split(" "),r=o.length;r--;)n=new RegExp("\\."+o[r]+"(?![a-zA-Z\\-]+)","i"),t=t.replace(n,"");return 0===t.length}function d(e,t){var n;if(e.getElementById&&(n=e.getElementById(t)),n)return n;var r,i,o,a=e.getElementsByTagName("*");for(i=0,o=a.length;o>i;i++)if(r=a[i],t===r.getAttribute("id"))return r}function v(e){for(var t=o(e,["use","svg:use"]),n=0;t.length&&n<t.length;){var r,i,a,s,u,c=t[n],f=c.getAttribute("xlink:href").substr(1),l=c.getAttribute("x")||0,v=c.getAttribute("y")||0,g=d(e,f).cloneNode(!0),m=(g.getAttribute("transform")||"")+" translate("+l+", "+v+")",h=t.length;if(p(g),/^svg$/i.test(g.nodeName)){var y=g.ownerDocument.createElement("g");for(a=0,s=g.attributes,u=s.length;u>a;a++)i=s.item(a),y.setAttribute(i.nodeName,i.nodeValue);for(;g.firstChild;)y.appendChild(g.firstChild);g=y}for(a=0,s=c.attributes,u=s.length;u>a;a++)i=s.item(a),"x"!==i.nodeName&&"y"!==i.nodeName&&"xlink:href"!==i.nodeName&&("transform"===i.nodeName?m=i.nodeValue+" "+m:g.setAttribute(i.nodeName,i.nodeValue));g.setAttribute("transform",m),g.setAttribute("instantiated_by_use","1"),g.removeAttribute("id"),r=c.parentNode,r.replaceChild(g,c),t.length===h&&n++}}function p(e){var t,n,r,i,o=e.getAttribute("viewBox"),a=1,s=1,u=0,c=0,f=e.getAttribute("width"),l=e.getAttribute("height"),d=e.getAttribute("x")||0,v=e.getAttribute("y")||0,p=e.getAttribute("preserveAspectRatio")||"",g=!o||!m.svgViewBoxElementsRegEx.test(e.nodeName)||!(o=o.match(C)),h=!f||!l||"100%"===f||"100%"===l,y=g&&h,b={},x="",j=0,E=0;if(b.width=0,b.height=0,b.toBeParsed=y,y)return b;if(g)return b.width=w(f),b.height=w(l),b;if(u=-parseFloat(o[1]),c=-parseFloat(o[2]),t=parseFloat(o[3]),n=parseFloat(o[4]),h?(b.width=t,b.height=n):(b.width=w(f),b.height=w(l),a=b.width/t,s=b.height/n),p=m.util.parsePreserveAspectRatioAttribute(p),"none"!==p.alignX&&("meet"===p.meetOrSlice&&(s=a=a>s?s:a),"slice"===p.meetOrSlice&&(s=a=a>s?a:s),j=b.width-t*a,E=b.height-n*a,"Mid"===p.alignX&&(j/=2),"Mid"===p.alignY&&(E/=2),"Min"===p.alignX&&(j=0),"Min"===p.alignY&&(E=0)),1===a&&1===s&&0===u&&0===c&&0===d&&0===v)return b;if((d||v)&&(x=" translate("+w(d)+" "+w(v)+") "),r=x+" matrix("+a+" 0 0 "+s+" "+(u*a+j)+" "+(c*s+E)+") ",b.viewboxTransform=m.parseTransformAttribute(r),"svg"===e.nodeName){for(i=e.ownerDocument.createElement("g");e.firstChild;)i.appendChild(e.firstChild);e.appendChild(i)}else i=e,r=i.getAttribute("transform")+r;return i.setAttribute("transform",r),b}function g(e,t){for(;e&&(e=e.parentNode);)if(e.nodeName&&t.test(e.nodeName.replace("svg:",""))&&!e.getAttribute("instantiated_by_use"))return!0;return!1}var m=e.fabric||(e.fabric={}),h=m.util.object.extend,y=m.util.object.clone,b=m.util.toFixed,w=m.util.parseUnit,x=m.util.multiplyTransformMatrices,j=["path","circle","polygon","polyline","ellipse","rect","line","image","text"],E=["symbol","image","marker","pattern","view","svg"],M=["pattern","defs","symbol","metadata","clipPath","mask","desc"],P=["symbol","g","a","svg","clipPath","defs"],T={cx:"left",x:"left",r:"radius",cy:"top",y:"top",display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule"},S={stroke:"strokeOpacity",fill:"fillOpacity"};m.svgValidTagNamesRegEx=r(j),m.svgViewBoxElementsRegEx=r(E),m.svgInvalidAncestorsRegEx=r(M),m.svgValidParentsRegEx=r(P),m.cssRules={},m.gradientDefs={},m.clipPaths={},m.parseTransformAttribute=function(){function e(e,t){var n=m.util.cos(t[0]),r=m.util.sin(t[0]),i=0,o=0;3===t.length&&(i=t[1],o=t[2]),e[0]=n,e[1]=r,e[2]=-r,e[3]=n,e[4]=i-(n*i-r*o),e[5]=o-(r*i+n*o)}function t(e,t){var n=t[0],r=2===t.length?t[1]:t[0];e[0]=n,e[3]=r}function n(e,t,n){e[n]=Math.tan(m.util.degreesToRadians(t[0]))}function r(e,t){e[4]=t[0],2===t.length&&(e[5]=t[1])}var i=[1,0,0,1,0,0],o=m.reNum,a="(?:\\s+,?\\s*|,\\s*)",s="(?:(skewX)\\s*\\(\\s*("+o+")\\s*\\))",u="(?:(skewY)\\s*\\(\\s*("+o+")\\s*\\))",c="(?:(rotate)\\s*\\(\\s*("+o+")(?:"+a+"("+o+")"+a+"("+o+"))?\\s*\\))",f="(?:(scale)\\s*\\(\\s*("+o+")(?:"+a+"("+o+"))?\\s*\\))",l="(?:(translate)\\s*\\(\\s*("+o+")(?:"+a+"("+o+"))?\\s*\\))",d="(?:(matrix)\\s*\\(\\s*("+o+")"+a+"("+o+")"+a+"("+o+")"+a+"("+o+")"+a+"("+o+")"+a+"("+o+")\\s*\\))",v="(?:"+d+"|"+l+"|"+f+"|"+c+"|"+s+"|"+u+")",p="(?:"+v+"(?:"+a+"*"+v+")*)",g="^\\s*(?:"+p+"?)\\s*$",h=new RegExp(g),y=new RegExp(v,"g");return function(o){var a=i.concat(),s=[];if(!o||o&&!h.test(o))return a;o.replace(y,function(o){var u=new RegExp(v).exec(o).filter(function(e){return!!e}),c=u[1],f=u.slice(2).map(parseFloat);switch(c){case"translate":r(a,f);break;case"rotate":f[0]=m.util.degreesToRadians(f[0]),e(a,f);break;case"scale":t(a,f);break;case"skewX":n(a,f,2);break;case"skewY":n(a,f,1);break;case"matrix":a=f}s.push(a.concat()),a=i.concat()});for(var u=s[0];s.length>1;)s.shift(),u=m.util.multiplyTransformMatrices(u,s[0]);return u}}();var C=new RegExp("^\\s*("+m.reNum+"+)\\s*,?\\s*("+m.reNum+"+)\\s*,?\\s*("+m.reNum+"+)\\s*,?\\s*("+m.reNum+"+)\\s*$");m.parseSVGDocument=function(e,t,n,r){if(e){v(e);var i,o,a=m.Object.__uid++,s=p(e),u=m.util.toArray(e.getElementsByTagName("*"));if(s.crossOrigin=r&&r.crossOrigin,s.svgUid=a,0===u.length&&m.isLikelyNode){u=e.selectNodes('//*[name(.)!="svg"]');var c=[];for(i=0,o=u.length;o>i;i++)c[i]=u[i];u=c}var f=u.filter(function(e){return p(e),m.svgValidTagNamesRegEx.test(e.nodeName.replace("svg:",""))&&!g(e,m.svgInvalidAncestorsRegEx)});if(!f||f&&!f.length)return void(t&&t([],{}));var l={};u.filter(function(e){return"clipPath"===e.nodeName.replace("svg:","")}).forEach(function(e){l[e.id]=m.util.toArray(e.getElementsByTagName("*")).filter(function(e){return m.svgValidTagNamesRegEx.test(e.nodeName.replace("svg:",""))})}),m.gradientDefs[a]=m.getGradientDefs(e),m.cssRules[a]=m.getCSSRules(e),m.clipPaths[a]=l,m.parseElements(f,function(e,n){t&&(t(e,s,n,u),delete m.gradientDefs[a],delete m.cssRules[a],delete m.clipPaths[a])},y(s),n,r)}};var L=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+m.reNum+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+m.reNum+"))?\\s+(.*)");h(m,{parseFontDeclaration:function(e,t){var n=e.match(L);if(n){var r=n[1],i=n[3],o=n[4],a=n[5],s=n[6];r&&(t.fontStyle=r),i&&(t.fontWeight=isNaN(parseFloat(i))?i:parseFloat(i)),o&&(t.fontSize=w(o)),s&&(t.fontFamily=s),a&&(t.lineHeight="normal"===a?1:a)}},getGradientDefs:function(e){var t,n,r,i=["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"],a=o(e,i),s=0,u={},c={};for(s=a.length;s--;)t=a[s],r=t.getAttribute("xlink:href"),n=t.getAttribute("id"),r&&(c[n]=r.substr(1)),u[n]=t;for(n in c){var f=u[c[n]].cloneNode(!0);for(t=u[n];f.firstChild;)t.appendChild(f.firstChild)}return u},parseAttributes:function(e,r,o){if(e){var a,s,c={};"undefined"==typeof o&&(o=e.getAttribute("svgUid")),e.parentNode&&m.svgValidParentsRegEx.test(e.parentNode.nodeName)&&(c=m.parseAttributes(e.parentNode,r,o)),s=c&&c.fontSize||e.getAttribute("font-size")||m.Text.DEFAULT_SVG_FONT_SIZE;var f=r.reduce(function(t,n){return a=e.getAttribute(n),a&&(t[n]=a),t},{});f=h(f,h(u(e,o),m.parseStyleAttribute(e)));var l,d,v={};for(var p in f)l=t(p),d=n(l,f[p],c,s),v[l]=d;v&&v.font&&m.parseFontDeclaration(v.font,v);var g=h(c,v);return m.svgValidParentsRegEx.test(e.nodeName)?g:i(g)}},parseElements:function(e,t,n,r,i){new m.ElementsParser(e,t,n,r,i).parse()},parseStyleAttribute:function(e){var t={},n=e.getAttribute("style");return n?("string"==typeof n?a(n,t):s(n,t),t):t},parsePointsAttribute:function(e){if(!e)return null;e=e.replace(/,/g," ").trim(),e=e.split(/\s+/);var t,n,r=[];for(t=0,n=e.length;n>t;t+=2)r.push({x:parseFloat(e[t]),y:parseFloat(e[t+1])});return r},getCSSRules:function(e){var t,n,r,i=e.getElementsByTagName("style"),o={};for(t=0,n=i.length;n>t;t++){var a=i[t].textContent||i[t].text;a=a.replace(/\/\*[\s\S]*?\*\//g,""),""!==a.trim()&&(r=a.match(/[^{]*\{[\s\S]*?\}/g),r=r.map(function(e){return e.trim()}),r.forEach(function(e){var r=e.match(/([\s\S]*?)\s*\{([^}]*)\}/),i={},a=r[2].trim(),s=a.replace(/;$/,"").split(/\s*;\s*/);for(t=0,n=s.length;n>t;t++){var u=s[t].split(/\s*:\s*/),c=u[0],f=u[1];i[c]=f}e=r[1],e.split(",").forEach(function(e){e=e.replace(/^svg/i,"").trim(),""!==e&&(o[e]?m.util.object.extend(o[e],i):o[e]=m.util.object.clone(i))})}))}return o},loadSVGFromURL:function(e,t,n,r){function i(e){var i=e.responseXML;i&&!i.documentElement&&m.window.ActiveXObject&&e.responseText&&(i=new ActiveXObject("Microsoft.XMLDOM"),i.async="false",i.loadXML(e.responseText.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,""))),i&&i.documentElement||t&&t(null),m.parseSVGDocument(i.documentElement,function(e,n,r,i){t&&t(e,n,r,i)},n,r)}e=e.replace(/^\n\s*/,"").trim(),new m.util.request(e,{method:"get",onComplete:i})},loadSVGFromString:function(e,t,n,r){e=e.trim();var i;if("undefined"!=typeof DOMParser){var o=new DOMParser;o&&o.parseFromString&&(i=o.parseFromString(e,"text/xml"))}else m.window.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLDOM"),i.async="false",i.loadXML(e.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,"")));m.parseSVGDocument(i.documentElement,function(e,n,r,i){t(e,n,r,i)},n,r)}})}("undefined"!=typeof exports?exports:this);fabric.ElementsParser=function(e,t,n,r,i){this.elements=e,this.callback=t,this.options=n,this.reviver=r,this.svgUid=n&&n.svgUid||0,this.parsingOptions=i,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g},function(e){e.parse=function(){this.instances=new Array(this.elements.length),this.numElements=this.elements.length,this.createObjects()},e.createObjects=function(){var e=this;this.elements.forEach(function(t,n){t.setAttribute("svgUid",e.svgUid),e.createObject(t,n)})},e.findTag=function(e){return fabric[fabric.util.string.capitalize(e.tagName.replace("svg:",""))]},e.createObject=function(e,t){var n=this.findTag(e);if(n&&n.fromElement)try{n.fromElement(e,this.createCallback(t,e),this.options)}catch(r){fabric.log(r)}else this.checkIfDone()},e.createCallback=function(e,t){var n=this;return function(r){var i;n.resolveGradient(r,"fill"),n.resolveGradient(r,"stroke"),r instanceof fabric.Image&&(i=r.parsePreserveAspectRatioAttribute(t)),r._removeTransformMatrix(i),n.resolveClipPath(r),n.reviver&&n.reviver(t,r),n.instances[e]=r,n.checkIfDone()}},e.extractPropertyDefinition=function(e,t,n){var r=e[t];if(/^url\(/.test(r)){var i=this.regexUrl.exec(r)[1];return this.regexUrl.lastIndex=0,fabric[n][this.svgUid][i]}},e.resolveGradient=function(e,t){var n=this.extractPropertyDefinition(e,t,"gradientDefs");n&&e.set(t,fabric.Gradient.fromElement(n,e))},e.createClipPathCallback=function(e,t){return function(e){e._removeTransformMatrix(),e.fillRule=e.clipRule,t.push(e)}},e.resolveClipPath=function(e){var t,n,r,i,o,a,s=this.extractPropertyDefinition(e,"clipPath","clipPaths");if(s){i=[],r=fabric.util.invertTransform(e.calcTransformMatrix());for(var u=0;u<s.length;u++)t=s[u],n=this.findTag(t),n.fromElement(t,this.createClipPathCallback(e,i),this.options);s=new fabric.Group(i),o=fabric.util.multiplyTransformMatrices(r,s.calcTransformMatrix());var a=fabric.util.qrDecompose(o);s.flipX=!1,s.flipY=!1,s.set("scaleX",a.scaleX),s.set("scaleY",a.scaleY),s.angle=a.angle,s.skewX=a.skewX,s.skewY=0,s.setPositionByOrigin({x:a.translateX,y:a.translateY},"center","center"),e.clipPath=s}},e.checkIfDone=function(){0===--this.numElements&&(this.instances=this.instances.filter(function(e){return null!=e}),this.callback(this.instances,this.elements))}}(fabric.ElementsParser.prototype);!function(e){"use strict";function t(e,t){this.x=e,this.y=t}var n=e.fabric||(e.fabric={});return n.Point?void n.warn("fabric.Point is already defined"):(n.Point=t,void(t.prototype={type:"point",constructor:t,add:function(e){return new t(this.x+e.x,this.y+e.y)},addEquals:function(e){return this.x+=e.x,this.y+=e.y,this},scalarAdd:function(e){return new t(this.x+e,this.y+e)},scalarAddEquals:function(e){return this.x+=e,this.y+=e,this},subtract:function(e){return new t(this.x-e.x,this.y-e.y)},subtractEquals:function(e){return this.x-=e.x,this.y-=e.y,this},scalarSubtract:function(e){return new t(this.x-e,this.y-e)},scalarSubtractEquals:function(e){return this.x-=e,this.y-=e,this},multiply:function(e){return new t(this.x*e,this.y*e)},multiplyEquals:function(e){return this.x*=e,this.y*=e,this},divide:function(e){return new t(this.x/e,this.y/e)},divideEquals:function(e){return this.x/=e,this.y/=e,this},eq:function(e){return this.x===e.x&&this.y===e.y},lt:function(e){return this.x<e.x&&this.y<e.y},lte:function(e){return this.x<=e.x&&this.y<=e.y},gt:function(e){return this.x>e.x&&this.y>e.y},gte:function(e){return this.x>=e.x&&this.y>=e.y},lerp:function(e,n){return"undefined"==typeof n&&(n=.5),n=Math.max(Math.min(1,n),0),new t(this.x+(e.x-this.x)*n,this.y+(e.y-this.y)*n)},distanceFrom:function(e){var t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)},midPointFrom:function(e){return this.lerp(e)},min:function(e){return new t(Math.min(this.x,e.x),Math.min(this.y,e.y))},max:function(e){return new t(Math.max(this.x,e.x),Math.max(this.y,e.y))},toString:function(){return this.x+","+this.y},setXY:function(e,t){return this.x=e,this.y=t,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setFromPoint:function(e){return this.x=e.x,this.y=e.y,this},swap:function(e){var t=this.x,n=this.y;this.x=e.x,this.y=e.y,e.x=t,e.y=n},clone:function(){return new t(this.x,this.y)}}))}("undefined"!=typeof exports?exports:this);!function(e){"use strict";function t(e){this.status=e,this.points=[]}var n=e.fabric||(e.fabric={});return n.Intersection?void n.warn("fabric.Intersection is already defined"):(n.Intersection=t,n.Intersection.prototype={constructor:t,appendPoint:function(e){return this.points.push(e),this},appendPoints:function(e){return this.points=this.points.concat(e),this}},n.Intersection.intersectLineLine=function(e,r,i,o){var a,s=(o.x-i.x)*(e.y-i.y)-(o.y-i.y)*(e.x-i.x),u=(r.x-e.x)*(e.y-i.y)-(r.y-e.y)*(e.x-i.x),c=(o.y-i.y)*(r.x-e.x)-(o.x-i.x)*(r.y-e.y);if(0!==c){var f=s/c,l=u/c;f>=0&&1>=f&&l>=0&&1>=l?(a=new t("Intersection"),a.appendPoint(new n.Point(e.x+f*(r.x-e.x),e.y+f*(r.y-e.y)))):a=new t}else a=new t(0===s||0===u?"Coincident":"Parallel");return a},n.Intersection.intersectLinePolygon=function(e,n,r){var i,o,a,s,u=new t,c=r.length;for(s=0;c>s;s++)i=r[s],o=r[(s+1)%c],a=t.intersectLineLine(e,n,i,o),u.appendPoints(a.points);return u.points.length>0&&(u.status="Intersection"),u},n.Intersection.intersectPolygonPolygon=function(e,n){var r,i=new t,o=e.length;for(r=0;o>r;r++){var a=e[r],s=e[(r+1)%o],u=t.intersectLinePolygon(a,s,n);i.appendPoints(u.points)}return i.points.length>0&&(i.status="Intersection"),i},void(n.Intersection.intersectPolygonRectangle=function(e,r,i){var o=r.min(i),a=r.max(i),s=new n.Point(a.x,o.y),u=new n.Point(o.x,a.y),c=t.intersectLinePolygon(o,s,e),f=t.intersectLinePolygon(s,a,e),l=t.intersectLinePolygon(a,u,e),d=t.intersectLinePolygon(u,o,e),p=new t;return p.appendPoints(c.points),p.appendPoints(f.points),p.appendPoints(l.points),p.appendPoints(d.points),p.points.length>0&&(p.status="Intersection"),p}))}("undefined"!=typeof exports?exports:this);!function(e){"use strict";function t(e){e?this._tryParsingColor(e):this.setSource([0,0,0,1])}function n(e,t,n){return 0>n&&(n+=1),n>1&&(n-=1),1/6>n?e+6*(t-e)*n:.5>n?t:2/3>n?e+(t-e)*(2/3-n)*6:e}var r=e.fabric||(e.fabric={});return r.Color?void r.warn("fabric.Color is already defined."):(r.Color=t,r.Color.prototype={_tryParsingColor:function(e){var n;e in t.colorNameMap&&(e=t.colorNameMap[e]),"transparent"===e&&(n=[255,255,255,0]),n||(n=t.sourceFromHex(e)),n||(n=t.sourceFromRgb(e)),n||(n=t.sourceFromHsl(e)),n||(n=[0,0,0,1]),n&&this.setSource(n)},_rgbToHsl:function(e,t,n){e/=255,t/=255,n/=255;var i,o,a,s=r.util.array.max([e,t,n]),u=r.util.array.min([e,t,n]);if(a=(s+u)/2,s===u)i=o=0;else{var c=s-u;switch(o=a>.5?c/(2-s-u):c/(s+u),s){case e:i=(t-n)/c+(n>t?6:0);break;case t:i=(n-e)/c+2;break;case n:i=(e-t)/c+4}i/=6}return[Math.round(360*i),Math.round(100*o),Math.round(100*a)]},getSource:function(){return this._source},setSource:function(e){this._source=e},toRgb:function(){var e=this.getSource();return"rgb("+e[0]+","+e[1]+","+e[2]+")"},toRgba:function(){var e=this.getSource();return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"},toHsl:function(){var e=this.getSource(),t=this._rgbToHsl(e[0],e[1],e[2]);return"hsl("+t[0]+","+t[1]+"%,"+t[2]+"%)"},toHsla:function(){var e=this.getSource(),t=this._rgbToHsl(e[0],e[1],e[2]);return"hsla("+t[0]+","+t[1]+"%,"+t[2]+"%,"+e[3]+")"},toHex:function(){var e,t,n,r=this.getSource();return e=r[0].toString(16),e=1===e.length?"0"+e:e,t=r[1].toString(16),t=1===t.length?"0"+t:t,n=r[2].toString(16),n=1===n.length?"0"+n:n,e.toUpperCase()+t.toUpperCase()+n.toUpperCase()},toHexa:function(){var e,t=this.getSource();return e=Math.round(255*t[3]),e=e.toString(16),e=1===e.length?"0"+e:e,this.toHex()+e.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(e){var t=this.getSource();return t[3]=e,this.setSource(t),this},toGrayscale:function(){var e=this.getSource(),t=parseInt((.3*e[0]+.59*e[1]+.11*e[2]).toFixed(0),10),n=e[3];return this.setSource([t,t,t,n]),this},toBlackWhite:function(e){var t=this.getSource(),n=(.3*t[0]+.59*t[1]+.11*t[2]).toFixed(0),r=t[3];return e=e||127,n=Number(n)<Number(e)?0:255,this.setSource([n,n,n,r]),this},overlayWith:function(e){e instanceof t||(e=new t(e));var n,r=[],i=this.getAlpha(),o=.5,a=this.getSource(),s=e.getSource();for(n=0;3>n;n++)r.push(Math.round(a[n]*(1-o)+s[n]*o));return r[3]=i,this.setSource(r),this}},r.Color.reRGBa=/^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i,r.Color.reHSLa=/^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i,r.Color.reHex=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,r.Color.colorNameMap={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#00FFFF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000000",blanchedalmond:"#FFEBCD",blue:"#0000FF",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#00FFFF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#FF00FF",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#00FF00",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#FF00FF",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#663399",red:"#FF0000",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFFFFF",whitesmoke:"#F5F5F5",yellow:"#FFFF00",yellowgreen:"#9ACD32"},r.Color.fromRgb=function(e){return t.fromSource(t.sourceFromRgb(e))},r.Color.sourceFromRgb=function(e){var n=e.match(t.reRGBa);if(n){var r=parseInt(n[1],10)/(/%$/.test(n[1])?100:1)*(/%$/.test(n[1])?255:1),i=parseInt(n[2],10)/(/%$/.test(n[2])?100:1)*(/%$/.test(n[2])?255:1),o=parseInt(n[3],10)/(/%$/.test(n[3])?100:1)*(/%$/.test(n[3])?255:1);return[parseInt(r,10),parseInt(i,10),parseInt(o,10),n[4]?parseFloat(n[4]):1]}},r.Color.fromRgba=t.fromRgb,r.Color.fromHsl=function(e){return t.fromSource(t.sourceFromHsl(e))},r.Color.sourceFromHsl=function(e){var r=e.match(t.reHSLa);if(r){var i,o,a,s=(parseFloat(r[1])%360+360)%360/360,u=parseFloat(r[2])/(/%$/.test(r[2])?100:1),c=parseFloat(r[3])/(/%$/.test(r[3])?100:1);if(0===u)i=o=a=c;else{var l=.5>=c?c*(u+1):c+u-c*u,f=2*c-l;i=n(f,l,s+1/3),o=n(f,l,s),a=n(f,l,s-1/3)}return[Math.round(255*i),Math.round(255*o),Math.round(255*a),r[4]?parseFloat(r[4]):1]}},r.Color.fromHsla=t.fromHsl,r.Color.fromHex=function(e){return t.fromSource(t.sourceFromHex(e))},r.Color.sourceFromHex=function(e){if(e.match(t.reHex)){var n=e.slice(e.indexOf("#")+1),r=3===n.length||4===n.length,i=8===n.length||4===n.length,o=r?n.charAt(0)+n.charAt(0):n.substring(0,2),a=r?n.charAt(1)+n.charAt(1):n.substring(2,4),s=r?n.charAt(2)+n.charAt(2):n.substring(4,6),u=i?r?n.charAt(3)+n.charAt(3):n.substring(6,8):"FF";return[parseInt(o,16),parseInt(a,16),parseInt(s,16),parseFloat((parseInt(u,16)/255).toFixed(2))]}},void(r.Color.fromSource=function(e){var n=new t;return n.setSource(e),n}))}("undefined"!=typeof exports?exports:this);!function(){function e(e,t,n){var r,i=0,o=1,a="";for(var s in t)"Infinity"===t[s]?t[s]=1:"-Infinity"===t[s]&&(t[s]=0),r=parseFloat(t[s],10),o="string"==typeof t[s]&&/^(\d+\.\d+)%|(\d+)%$/.test(t[s])?.01:1,"x1"===s||"x2"===s||"r2"===s?(o*="objectBoundingBox"===n?e.width:1,i="objectBoundingBox"===n?e.left||0:0):("y1"===s||"y2"===s)&&(o*="objectBoundingBox"===n?e.height:1,i="objectBoundingBox"===n?e.top||0:0),t[s]=r*o+i;if("ellipse"===e.type&&null!==t.r2&&"objectBoundingBox"===n&&e.rx!==e.ry){var u=e.ry/e.rx;a=" scale(1, "+u+")",t.y1&&(t.y1/=u),t.y2&&(t.y2/=u)}return a}fabric.util.object.clone;fabric.Gradient=fabric.util.createClass({offsetX:0,offsetY:0,initialize:function(e){e||(e={});var t={};this.id=fabric.Object.__uid++,this.type=e.type||"linear",t={x1:e.coords.x1||0,y1:e.coords.y1||0,x2:e.coords.x2||0,y2:e.coords.y2||0},"radial"===this.type&&(t.r1=e.coords.r1||0,t.r2=e.coords.r2||0),this.coords=t,this.colorStops=e.colorStops.slice(),e.gradientTransform&&(this.gradientTransform=e.gradientTransform),this.offsetX=e.offsetX||this.offsetX,this.offsetY=e.offsetY||this.offsetY},addColorStop:function(e){for(var t in e){var n=new fabric.Color(e[t]);this.colorStops.push({offset:parseFloat(t),color:n.toRgb(),opacity:n.getAlpha()})}return this},toObject:function(e){var t={type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientTransform:this.gradientTransform?this.gradientTransform.concat():this.gradientTransform};return fabric.util.populateWithProperties(this,t,e),t},toLive:function(e){var t,n,r,i=fabric.util.object.clone(this.coords);if(this.type){for("linear"===this.type?t=e.createLinearGradient(i.x1,i.y1,i.x2,i.y2):"radial"===this.type&&(t=e.createRadialGradient(i.x1,i.y1,i.r1,i.x2,i.y2,i.r2)),n=0,r=this.colorStops.length;r>n;n++){var o=this.colorStops[n].color,a=this.colorStops[n].opacity,s=this.colorStops[n].offset;"undefined"!=typeof a&&(o=new fabric.Color(o).setAlpha(a).toRgba()),t.addColorStop(s,o)}return t}}}),fabric.util.object.extend(fabric.Gradient,{forObject:function(t,n){return n||(n={}),e(t,n.coords,"userSpaceOnUse"),new fabric.Gradient(n)}})}();!function(){"use strict";var e=fabric.util.toFixed;fabric.Pattern=fabric.util.createClass({repeat:"repeat",offsetX:0,offsetY:0,crossOrigin:"",patternTransform:null,initialize:function(e,t){if(e||(e={}),this.id=fabric.Object.__uid++,this.setOptions(e),!e.source||e.source&&"string"!=typeof e.source)return void(t&&t(this));if("undefined"!=typeof fabric.util.getFunctionBody(e.source))this.source=new Function(fabric.util.getFunctionBody(e.source)),t&&t(this);else{var n=this;this.source=fabric.util.createImage(),fabric.util.loadImage(e.source,function(e){n.source=e,t&&t(n)},null,this.crossOrigin)}},toObject:function(t){var n,r,i=fabric.Object.NUM_FRACTION_DIGITS;return"function"==typeof this.source?n=String(this.source):"string"==typeof this.source.src?n=this.source.src:"object"==typeof this.source&&this.source.toDataURL&&(n=this.source.toDataURL()),r={type:"pattern",source:n,repeat:this.repeat,crossOrigin:this.crossOrigin,offsetX:e(this.offsetX,i),offsetY:e(this.offsetY,i),patternTransform:this.patternTransform?this.patternTransform.concat():null},fabric.util.populateWithProperties(this,r,t),r},setOptions:function(e){for(var t in e)this[t]=e[t]},toLive:function(e){var t="function"==typeof this.source?this.source():this.source;if(!t)return"";if("undefined"!=typeof t.src){if(!t.complete)return"";if(0===t.naturalWidth||0===t.naturalHeight)return""}return e.createPattern(t,this.repeat)}})}();!function(e){"use strict";{var t=e.fabric||(e.fabric={});t.util.toFixed}return t.Shadow?void t.warn("fabric.Shadow is already defined."):(t.Shadow=t.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,initialize:function(e){"string"==typeof e&&(e=this._parseShadow(e));for(var n in e)this[n]=e[n];this.id=t.Object.__uid++},_parseShadow:function(e){var n=e.trim(),r=t.Shadow.reOffsetsAndBlur.exec(n)||[],i=n.replace(t.Shadow.reOffsetsAndBlur,"")||"rgb(0,0,0)";return{color:i.trim(),offsetX:parseInt(r[1],10)||0,offsetY:parseInt(r[2],10)||0,blur:parseInt(r[3],10)||0}},toString:function(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")},toObject:function(){if(this.includeDefaultValues)return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke};var e={},n=t.Shadow.prototype;return["color","blur","offsetX","offsetY","affectStroke"].forEach(function(t){this[t]!==n[t]&&(e[t]=this[t])},this),e}}),void(t.Shadow.reOffsetsAndBlur=/(?:\s|^)(-?\d+(?:px)?(?:\s?|$))?(-?\d+(?:px)?(?:\s?|$))?(\d+(?:px)?)?(?:\s?|$)(?:$|\s)/))}("undefined"!=typeof exports?exports:this);!function(){"use strict";if(fabric.StaticCanvas)return void fabric.warn("fabric.StaticCanvas is already defined.");var e=fabric.util.object.extend,t=fabric.util.getElementOffset,n=fabric.util.removeFromArray,r=(fabric.util.toFixed,fabric.util.transformPoint),i=fabric.util.invertTransform,o=new Error("Could not initialize `canvas` element");fabric.StaticCanvas=fabric.util.createClass(fabric.CommonMethods,{initialize:function(e,t){t||(t={}),this.renderAndResetBound=this.renderAndReset.bind(this),this.requestRenderAllBound=this.requestRenderAll.bind(this),this._initStatic(e,t)},backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:!0,stateful:!1,renderOnAddRemove:!0,clipTo:null,controlsAboveOverlay:!1,allowTouchScrolling:!1,imageSmoothingEnabled:!0,viewportTransform:fabric.iMatrix.concat(),backgroundVpt:!0,overlayVpt:!0,onBeforeScaleRotate:function(){},enableRetinaScaling:!0,vptCoords:{},skipOffscreen:!0,_initStatic:function(e,t){var n=this.requestRenderAllBound;this._objects=[],this._createLowerCanvas(e),this._initOptions(t),this._setImageSmoothing(),this.interactive||this._initRetinaScaling(),t.overlayImage&&this.setOverlayImage(t.overlayImage,n),t.backgroundImage&&this.setBackgroundImage(t.backgroundImage,n),t.backgroundColor&&this.setBackgroundColor(t.backgroundColor,n),t.overlayColor&&this.setOverlayColor(t.overlayColor,n),this.calcOffset()},_isRetinaScaling:function(){return 1!==fabric.devicePixelRatio&&this.enableRetinaScaling},getRetinaScaling:function(){return this._isRetinaScaling()?fabric.devicePixelRatio:1},_initRetinaScaling:function(){this._isRetinaScaling()&&(this.lowerCanvasEl.setAttribute("width",this.width*fabric.devicePixelRatio),this.lowerCanvasEl.setAttribute("height",this.height*fabric.devicePixelRatio),this.contextContainer.scale(fabric.devicePixelRatio,fabric.devicePixelRatio))},calcOffset:function(){return this._offset=t(this.lowerCanvasEl),this},setOverlayImage:function(e,t,n){return this.__setBgOverlayImage("overlayImage",e,t,n)},setBackgroundImage:function(e,t,n){return this.__setBgOverlayImage("backgroundImage",e,t,n)},setOverlayColor:function(e,t){return this.__setBgOverlayColor("overlayColor",e,t)},setBackgroundColor:function(e,t){return this.__setBgOverlayColor("backgroundColor",e,t)},_setImageSmoothing:function(){var e=this.getContext();e.imageSmoothingEnabled=e.imageSmoothingEnabled||e.webkitImageSmoothingEnabled||e.mozImageSmoothingEnabled||e.msImageSmoothingEnabled||e.oImageSmoothingEnabled,e.imageSmoothingEnabled=this.imageSmoothingEnabled},__setBgOverlayImage:function(e,t,n,r){return"string"==typeof t?fabric.util.loadImage(t,function(t){t&&(this[e]=new fabric.Image(t,r)),n&&n(t)},this,r&&r.crossOrigin):(r&&t.setOptions(r),this[e]=t,n&&n(t)),this},__setBgOverlayColor:function(e,t,n){return this[e]=t,this._initGradient(t,e),this._initPattern(t,e,n),this},_createCanvasElement:function(){var e=fabric.util.createCanvasElement();if(!e)throw o;if(e.style||(e.style={}),"undefined"==typeof e.getContext)throw o;return e},_initOptions:function(e){this._setOptions(e),this.width=this.width||parseInt(this.lowerCanvasEl.width,10)||0,this.height=this.height||parseInt(this.lowerCanvasEl.height,10)||0,this.lowerCanvasEl.style&&(this.lowerCanvasEl.width=this.width,this.lowerCanvasEl.height=this.height,this.lowerCanvasEl.style.width=this.width+"px",this.lowerCanvasEl.style.height=this.height+"px",this.viewportTransform=this.viewportTransform.slice())},_createLowerCanvas:function(e){this.lowerCanvasEl=e&&e.getContext?e:fabric.util.getById(e)||this._createCanvasElement(),fabric.util.addClass(this.lowerCanvasEl,"lower-canvas"),this.interactive&&this._applyCanvasStyle(this.lowerCanvasEl),this.contextContainer=this.lowerCanvasEl.getContext("2d")},getWidth:function(){return this.width},getHeight:function(){return this.height},setWidth:function(e,t){return this.setDimensions({width:e},t)},setHeight:function(e,t){return this.setDimensions({height:e},t)},setDimensions:function(e,t){var n;t=t||{};for(var r in e)n=e[r],t.cssOnly||(this._setBackstoreDimension(r,e[r]),n+="px",this.hasLostContext=!0),t.backstoreOnly||this._setCssDimension(r,n);return this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(),this._initRetinaScaling(),this._setImageSmoothing(),this.calcOffset(),t.cssOnly||this.requestRenderAll(),this},_setBackstoreDimension:function(e,t){return this.lowerCanvasEl[e]=t,this.upperCanvasEl&&(this.upperCanvasEl[e]=t),this.cacheCanvasEl&&(this.cacheCanvasEl[e]=t),this[e]=t,this},_setCssDimension:function(e,t){return this.lowerCanvasEl.style[e]=t,this.upperCanvasEl&&(this.upperCanvasEl.style[e]=t),this.wrapperEl&&(this.wrapperEl.style[e]=t),this},getZoom:function(){return this.viewportTransform[0]},setViewportTransform:function(e){var t,n,r,i=this._activeObject,o=!1,s=!0;for(this.viewportTransform=e,n=0,r=this._objects.length;r>n;n++)t=this._objects[n],t.group||t.setCoords(o,s);return i&&"activeSelection"===i.type&&i.setCoords(o,s),this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll(),this},zoomToPoint:function(e,t){var n=e,o=this.viewportTransform.slice(0);e=r(e,i(this.viewportTransform)),o[0]=t,o[3]=t;var s=r(e,o);return o[4]+=n.x-s.x,o[5]+=n.y-s.y,this.setViewportTransform(o)},setZoom:function(e){return this.zoomToPoint(new fabric.Point(0,0),e),this},absolutePan:function(e){var t=this.viewportTransform.slice(0);return t[4]=-e.x,t[5]=-e.y,this.setViewportTransform(t)},relativePan:function(e){return this.absolutePan(new fabric.Point(-e.x-this.viewportTransform[4],-e.y-this.viewportTransform[5]))},getElement:function(){return this.lowerCanvasEl},_onObjectAdded:function(e){this.stateful&&e.setupState(),e._set("canvas",this),e.setCoords(),this.fire("object:added",{target:e}),e.fire("added")},_onObjectRemoved:function(e){this.fire("object:removed",{target:e}),e.fire("removed"),delete e.canvas},clearContext:function(e){return e.clearRect(0,0,this.width,this.height),this},getContext:function(){return this.contextContainer},clear:function(){return this._objects.length=0,this.backgroundImage=null,this.overlayImage=null,this.backgroundColor="",this.overlayColor="",this._hasITextHandlers&&(this.off("mouse:up",this._mouseUpITextHandler),this._iTextInstances=null,this._hasITextHandlers=!1),this.clearContext(this.contextContainer),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll(),this},renderAll:function(){var e=this.contextContainer;return this.renderCanvas(e,this._objects),this},renderAndReset:function(){this.isRendering=0,this.renderAll()},requestRenderAll:function(){return this.isRendering||(this.isRendering=fabric.util.requestAnimFrame(this.renderAndResetBound)),this},calcViewportBoundaries:function(){var e={},t=this.width,n=this.height,o=i(this.viewportTransform);return e.tl=r({x:0,y:0},o),e.br=r({x:t,y:n},o),e.tr=new fabric.Point(e.br.x,e.tl.y),e.bl=new fabric.Point(e.tl.x,e.br.y),this.vptCoords=e,e},renderCanvas:function(e,t){var n=this.viewportTransform;this.isRendering&&(fabric.util.cancelAnimFrame(this.isRendering),this.isRendering=0),this.calcViewportBoundaries(),this.clearContext(e),this.fire("before:render"),this.clipTo&&fabric.util.clipContext(this,e),this._renderBackground(e),e.save(),e.transform(n[0],n[1],n[2],n[3],n[4],n[5]),this._renderObjects(e,t),e.restore(),!this.controlsAboveOverlay&&this.interactive&&this.drawControls(e),this.clipTo&&e.restore(),this._renderOverlay(e),this.controlsAboveOverlay&&this.interactive&&this.drawControls(e),this.fire("after:render")},_renderObjects:function(e,t){var n,r;for(n=0,r=t.length;r>n;++n)t[n]&&t[n].render(e)},_renderBackgroundOrOverlay:function(e,t){var n,r=this[t+"Color"];r&&(e.fillStyle=r.toLive?r.toLive(e,this):r,e.fillRect(r.offsetX||0,r.offsetY||0,this.width,this.height)),r=this[t+"Image"],r&&(this[t+"Vpt"]&&(n=this.viewportTransform,e.save(),e.transform(n[0],n[1],n[2],n[3],n[4],n[5])),r.render(e),this[t+"Vpt"]&&e.restore())},_renderBackground:function(e){this._renderBackgroundOrOverlay(e,"background")},_renderOverlay:function(e){this._renderBackgroundOrOverlay(e,"overlay")},getCenter:function(){return{top:this.height/2,left:this.width/2}},centerObjectH:function(e){return this._centerObject(e,new fabric.Point(this.getCenter().left,e.getCenterPoint().y))},centerObjectV:function(e){return this._centerObject(e,new fabric.Point(e.getCenterPoint().x,this.getCenter().top))},centerObject:function(e){var t=this.getCenter();return this._centerObject(e,new fabric.Point(t.left,t.top))},viewportCenterObject:function(e){var t=this.getVpCenter();return this._centerObject(e,t)},viewportCenterObjectH:function(e){var t=this.getVpCenter();return this._centerObject(e,new fabric.Point(t.x,e.getCenterPoint().y)),this},viewportCenterObjectV:function(e){var t=this.getVpCenter();return this._centerObject(e,new fabric.Point(e.getCenterPoint().x,t.y))},getVpCenter:function(){var e=this.getCenter(),t=i(this.viewportTransform);return r({x:e.left,y:e.top},t)},_centerObject:function(e,t){return e.setPositionByOrigin(t,"center","center"),e.setCoords(),this.renderOnAddRemove&&this.requestRenderAll(),this},toDatalessJSON:function(e){return this.toDatalessObject(e)},toObject:function(e){return this._toObjectMethod("toObject",e)},toDatalessObject:function(e){return this._toObjectMethod("toDatalessObject",e)},_toObjectMethod:function(t,n){var r={version:fabric.version,objects:this._toObjects(t,n)};return e(r,this.__serializeBgOverlay(t,n)),fabric.util.populateWithProperties(this,r,n),r},_toObjects:function(e,t){return this.getObjects().filter(function(e){return!e.excludeFromExport}).map(function(n){return this._toObject(n,e,t)},this)},_toObject:function(e,t,n){var r;this.includeDefaultValues||(r=e.includeDefaultValues,e.includeDefaultValues=!1);var i=e[t](n);return this.includeDefaultValues||(e.includeDefaultValues=r),i},__serializeBgOverlay:function(e,t){var n={},r=this.backgroundImage,i=this.overlayImage;return this.backgroundColor&&(n.background=this.backgroundColor.toObject?this.backgroundColor.toObject(t):this.backgroundColor),this.overlayColor&&(n.overlay=this.overlayColor.toObject?this.overlayColor.toObject(t):this.overlayColor),r&&!r.excludeFromExport&&(n.backgroundImage=this._toObject(r,e,t)),i&&!i.excludeFromExport&&(n.overlayImage=this._toObject(i,e,t)),n},sendToBack:function(e){if(!e)return this;var t,r,i,o=this._activeObject;if(e===o&&"activeSelection"===e.type)for(i=o._objects,t=i.length;t--;)r=i[t],n(this._objects,r),this._objects.unshift(r);else n(this._objects,e),this._objects.unshift(e);return this.renderOnAddRemove&&this.requestRenderAll(),this},bringToFront:function(e){if(!e)return this;var t,r,i,o=this._activeObject;if(e===o&&"activeSelection"===e.type)for(i=o._objects,t=0;t<i.length;t++)r=i[t],n(this._objects,r),this._objects.push(r);else n(this._objects,e),this._objects.push(e);return this.renderOnAddRemove&&this.requestRenderAll(),this},sendBackwards:function(e,t){if(!e)return this;var r,i,o,s,a,c=this._activeObject,u=0;if(e===c&&"activeSelection"===e.type)for(a=c._objects,r=0;r<a.length;r++)i=a[r],o=this._objects.indexOf(i),o>0+u&&(s=o-1,n(this._objects,i),this._objects.splice(s,0,i)),u++;else o=this._objects.indexOf(e),0!==o&&(s=this._findNewLowerIndex(e,o,t),n(this._objects,e),this._objects.splice(s,0,e));return this.renderOnAddRemove&&this.requestRenderAll(),this},_findNewLowerIndex:function(e,t,n){var r,i;if(n)for(r=t,i=t-1;i>=0;--i){var o=e.intersectsWithObject(this._objects[i])||e.isContainedWithinObject(this._objects[i])||this._objects[i].isContainedWithinObject(e);if(o){r=i;break}}else r=t-1;return r},bringForward:function(e,t){if(!e)return this;var r,i,o,s,a,c=this._activeObject,u=0;if(e===c&&"activeSelection"===e.type)for(a=c._objects,r=a.length;r--;)i=a[r],o=this._objects.indexOf(i),o<this._objects.length-1-u&&(s=o+1,n(this._objects,i),this._objects.splice(s,0,i)),u++;else o=this._objects.indexOf(e),o!==this._objects.length-1&&(s=this._findNewUpperIndex(e,o,t),n(this._objects,e),this._objects.splice(s,0,e));return this.renderOnAddRemove&&this.requestRenderAll(),this},_findNewUpperIndex:function(e,t,n){var r,i,o;if(n)for(r=t,i=t+1,o=this._objects.length;o>i;++i){var s=e.intersectsWithObject(this._objects[i])||e.isContainedWithinObject(this._objects[i])||this._objects[i].isContainedWithinObject(e);if(s){r=i;break}}else r=t+1;return r},moveTo:function(e,t){return n(this._objects,e),this._objects.splice(t,0,e),this.renderOnAddRemove&&this.requestRenderAll()},dispose:function(){return this.isRendering&&(fabric.util.cancelAnimFrame(this.isRendering),this.isRendering=0),this.forEachObject(function(e){e.dispose&&e.dispose()}),this._objects=[],this.backgroundImage=null,this.overlayImage=null,this._iTextInstances=null,this.lowerCanvasEl=null,this.contextContainer=null,this},toString:function(){return"#<fabric.Canvas ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"}}),e(fabric.StaticCanvas.prototype,fabric.Observable),e(fabric.StaticCanvas.prototype,fabric.Collection),e(fabric.StaticCanvas.prototype,fabric.DataURLExporter),e(fabric.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',supports:function(e){var t=fabric.util.createCanvasElement();if(!t||!t.getContext)return null;var n=t.getContext("2d");if(!n)return null;switch(e){case"getImageData":return"undefined"!=typeof n.getImageData;case"setLineDash":return"undefined"!=typeof n.setLineDash;case"toDataURL":return"undefined"!=typeof t.toDataURL;case"toDataURLWithQuality":try{return t.toDataURL("image/jpeg",0),!0}catch(r){}return!1;default:return null}}}),fabric.StaticCanvas.prototype.toJSON=fabric.StaticCanvas.prototype.toObject,fabric.isLikelyNode&&(fabric.StaticCanvas.prototype.createPNGStream=function(){var e=fabric.util.getNodeCanvas(this.lowerCanvasEl);return e&&e.createPNGStream()},fabric.StaticCanvas.prototype.createJPEGStream=function(e){var t=fabric.util.getNodeCanvas(this.lowerCanvasEl);return t&&t.createJPEGStream(e)})}();fabric.BaseBrush=fabric.util.createClass({color:"rgb(0, 0, 0)",width:1,shadow:null,strokeLineCap:"round",strokeLineJoin:"round",strokeMiterLimit:10,strokeDashArray:null,setShadow:function(e){return this.shadow=new fabric.Shadow(e),this},_setBrushStyles:function(){var e=this.canvas.contextTop;e.strokeStyle=this.color,e.lineWidth=this.width,e.lineCap=this.strokeLineCap,e.miterLimit=this.strokeMiterLimit,e.lineJoin=this.strokeLineJoin,fabric.StaticCanvas.supports("setLineDash")&&e.setLineDash(this.strokeDashArray||[])},_saveAndTransform:function(e){var t=this.canvas.viewportTransform;e.save(),e.transform(t[0],t[1],t[2],t[3],t[4],t[5])},_setShadow:function(){if(this.shadow){var e=this.canvas.contextTop,t=this.canvas.getZoom();e.shadowColor=this.shadow.color,e.shadowBlur=this.shadow.blur*t,e.shadowOffsetX=this.shadow.offsetX*t,e.shadowOffsetY=this.shadow.offsetY*t}},_resetShadow:function(){var e=this.canvas.contextTop;e.shadowColor="",e.shadowBlur=e.shadowOffsetX=e.shadowOffsetY=0}});!function(){fabric.PencilBrush=fabric.util.createClass(fabric.BaseBrush,{initialize:function(e){this.canvas=e,this._points=[]},_drawSegment:function(e,t,n){var r=t.midPointFrom(n);return e.quadraticCurveTo(t.x,t.y,r.x,r.y),r},onMouseDown:function(e){this._prepareForDrawing(e),this._captureDrawingPath(e),this._render()},onMouseMove:function(e){if(this._captureDrawingPath(e)&&this._points.length>1)if(this.needsFullRender)this.canvas.clearContext(this.canvas.contextTop),this._render();else{var t=this._points,n=t.length,r=this.canvas.contextTop;this._saveAndTransform(r),this.oldEnd&&(r.beginPath(),r.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=this._drawSegment(r,t[n-2],t[n-1],!0),r.stroke(),r.restore()}},onMouseUp:function(){this.oldEnd=void 0,this._finalizeAndAddPath()},_prepareForDrawing:function(e){var t=new fabric.Point(e.x,e.y);this._reset(),this._addPoint(t),this.canvas.contextTop.moveTo(t.x,t.y)},_addPoint:function(e){return this._points.length>1&&e.eq(this._points[this._points.length-1])?!1:(this._points.push(e),!0)},_reset:function(){this._points.length=0,this._setBrushStyles();var e=new fabric.Color(this.color);this.needsFullRender=e.getAlpha()<1,this._setShadow()},_captureDrawingPath:function(e){var t=new fabric.Point(e.x,e.y);return this._addPoint(t)},_render:function(){var e,t,n=this.canvas.contextTop,r=this._points[0],i=this._points[1];if(this._saveAndTransform(n),n.beginPath(),2===this._points.length&&r.x===i.x&&r.y===i.y){var o=this.width/1e3;r=new fabric.Point(r.x,r.y),i=new fabric.Point(i.x,i.y),r.x-=o,i.x+=o}for(n.moveTo(r.x,r.y),e=1,t=this._points.length;t>e;e++)this._drawSegment(n,r,i),r=this._points[e],i=this._points[e+1];n.lineTo(r.x,r.y),n.stroke(),n.restore()},convertPointsToSVGPath:function(e){var t,n=[],r=this.width/1e3,i=new fabric.Point(e[0].x,e[0].y),o=new fabric.Point(e[1].x,e[1].y),s=e.length,a=1,c=1,u=s>2;for(u&&(a=e[2].x<o.x?-1:e[2].x===o.x?0:1,c=e[2].y<o.y?-1:e[2].y===o.y?0:1),n.push("M ",i.x-a*r," ",i.y-c*r," "),t=1;s>t;t++){if(!i.eq(o)){var l=i.midPointFrom(o);n.push("Q ",i.x," ",i.y," ",l.x," ",l.y," ")}i=e[t],t+1<e.length&&(o=e[t+1])}return u&&(a=i.x>e[t-2].x?1:i.x===e[t-2].x?0:-1,c=i.y>e[t-2].y?1:i.y===e[t-2].y?0:-1),n.push("L ",i.x+a*r," ",i.y+c*r),n},createPath:function(e){var t=new fabric.Path(e,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray}),n=new fabric.Point(t.left+t.width/2,t.top+t.height/2);return n=t.translateToGivenOrigin(n,"center","center",t.originX,t.originY),t.top=n.y,t.left=n.x,this.shadow&&(this.shadow.affectStroke=!0,t.setShadow(this.shadow)),t},_finalizeAndAddPath:function(){var e=this.canvas.contextTop;e.closePath();var t=this.convertPointsToSVGPath(this._points).join("");if("M 0 0 Q 0 0 0 0 L 0 0"===t)return void this.canvas.requestRenderAll();var n=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.add(n),this.canvas.renderAll(),n.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:n})}})}();fabric.CircleBrush=fabric.util.createClass(fabric.BaseBrush,{width:10,initialize:function(e){this.canvas=e,this.points=[]},drawDot:function(e){var t=this.addPoint(e),n=this.canvas.contextTop;this._saveAndTransform(n),n.fillStyle=t.fill,n.beginPath(),n.arc(t.x,t.y,t.radius,0,2*Math.PI,!1),n.closePath(),n.fill(),n.restore()},onMouseDown:function(e){this.points.length=0,this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.drawDot(e)},_render:function(){var e,t,n,r=this.canvas.contextTop,i=this.points;for(this._saveAndTransform(r),e=0,t=i.length;t>e;e++)n=i[e],r.fillStyle=n.fill,r.beginPath(),r.arc(n.x,n.y,n.radius,0,2*Math.PI,!1),r.closePath(),r.fill();r.restore()},onMouseMove:function(e){this.drawDot(e)},onMouseUp:function(){var e,t,n=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;var r=[];for(e=0,t=this.points.length;t>e;e++){var i=this.points[e],o=new fabric.Circle({radius:i.radius,left:i.x,top:i.y,originX:"center",originY:"center",fill:i.fill});this.shadow&&o.setShadow(this.shadow),r.push(o)}var s=new fabric.Group(r,{originX:"center",originY:"center"});s.canvas=this.canvas,this.canvas.add(s),this.canvas.fire("path:created",{path:s}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=n,this.canvas.requestRenderAll()},addPoint:function(e){var t=new fabric.Point(e.x,e.y),n=fabric.util.getRandomInt(Math.max(0,this.width-20),this.width+20)/2,r=new fabric.Color(this.color).setAlpha(fabric.util.getRandomInt(0,100)/100).toRgba();return t.radius=n,t.fill=r,this.points.push(t),t}});fabric.SprayBrush=fabric.util.createClass(fabric.BaseBrush,{width:10,density:20,dotWidth:1,dotWidthVariance:1,randomOpacity:!1,optimizeOverlapping:!0,initialize:function(e){this.canvas=e,this.sprayChunks=[]},onMouseDown:function(e){this.sprayChunks.length=0,this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.addSprayChunk(e),this.render(this.sprayChunkPoints)},onMouseMove:function(e){this.addSprayChunk(e),this.render(this.sprayChunkPoints)},onMouseUp:function(){var e=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;for(var t=[],n=0,r=this.sprayChunks.length;r>n;n++)for(var i=this.sprayChunks[n],o=0,s=i.length;s>o;o++){var a=new fabric.Rect({width:i[o].width,height:i[o].width,left:i[o].x+1,top:i[o].y+1,originX:"center",originY:"center",fill:this.color});t.push(a)}this.optimizeOverlapping&&(t=this._getOptimizedRects(t));var c=new fabric.Group(t,{originX:"center",originY:"center"});this.shadow&&c.setShadow(this.shadow),this.canvas.add(c),this.canvas.fire("path:created",{path:c}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=e,this.canvas.requestRenderAll()},_getOptimizedRects:function(e){var t,n,r,i={};for(n=0,r=e.length;r>n;n++)t=e[n].left+""+e[n].top,i[t]||(i[t]=e[n]);var o=[];for(t in i)o.push(i[t]);return o},render:function(e){var t,n,r=this.canvas.contextTop;for(r.fillStyle=this.color,this._saveAndTransform(r),t=0,n=e.length;n>t;t++){var i=e[t];"undefined"!=typeof i.opacity&&(r.globalAlpha=i.opacity),r.fillRect(i.x,i.y,i.width,i.width)}r.restore()},_render:function(){var e,t,n=this.canvas.contextTop;for(n.fillStyle=this.color,this._saveAndTransform(n),e=0,t=this.sprayChunks.length;t>e;e++)this.render(this.sprayChunks[e]);n.restore()},addSprayChunk:function(e){this.sprayChunkPoints=[];var t,n,r,i,o=this.width/2;for(i=0;i<this.density;i++){t=fabric.util.getRandomInt(e.x-o,e.x+o),n=fabric.util.getRandomInt(e.y-o,e.y+o),r=this.dotWidthVariance?fabric.util.getRandomInt(Math.max(1,this.dotWidth-this.dotWidthVariance),this.dotWidth+this.dotWidthVariance):this.dotWidth;var s=new fabric.Point(t,n);s.width=r,this.randomOpacity&&(s.opacity=fabric.util.getRandomInt(0,100)/100),this.sprayChunkPoints.push(s)}this.sprayChunks.push(this.sprayChunkPoints)}});fabric.PatternBrush=fabric.util.createClass(fabric.PencilBrush,{getPatternSrc:function(){var e=20,t=5,n=fabric.document.createElement("canvas"),r=n.getContext("2d");return n.width=n.height=e+t,r.fillStyle=this.color,r.beginPath(),r.arc(e/2,e/2,e/2,0,2*Math.PI,!1),r.closePath(),r.fill(),n},getPatternSrcFunction:function(){return String(this.getPatternSrc).replace("this.color",'"'+this.color+'"')},getPattern:function(){return this.canvas.contextTop.createPattern(this.source||this.getPatternSrc(),"repeat")},_setBrushStyles:function(){this.callSuper("_setBrushStyles"),this.canvas.contextTop.strokeStyle=this.getPattern()},createPath:function(e){var t=this.callSuper("createPath",e),n=t._getLeftTopCoords().scalarAdd(t.strokeWidth/2);return t.stroke=new fabric.Pattern({source:this.source||this.getPatternSrcFunction(),offsetX:-n.x,offsetY:-n.y}),t}});!function(){var e=fabric.util.getPointer,t=fabric.util.degreesToRadians,n=fabric.util.radiansToDegrees,r=Math.atan2,i=Math.abs,o=fabric.StaticCanvas.supports("setLineDash"),s=.5;fabric.Canvas=fabric.util.createClass(fabric.StaticCanvas,{initialize:function(e,t){t||(t={}),this.renderAndResetBound=this.renderAndReset.bind(this),this._initStatic(e,t),this._initInteractive(),this._createCacheCanvas()},uniScaleTransform:!1,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",interactive:!0,selection:!0,selectionKey:"shiftKey",altSelectionKey:null,selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",rotationCursor:"crosshair",notAllowedCursor:"not-allowed",containerClass:"canvas-container",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,isDrawingMode:!1,preserveObjectStacking:!1,snapAngle:0,snapThreshold:null,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,_initInteractive:function(){this._currentTransform=null,this._groupSelector=null,this._initWrapperElement(),this._createUpperCanvas(),this._initEventListeners(),this._initRetinaScaling(),this.freeDrawingBrush=fabric.PencilBrush&&new fabric.PencilBrush(this),this.calcOffset()},_chooseObjectsToRender:function(){var e,t,n,r=this.getActiveObjects();if(r.length>0&&!this.preserveObjectStacking){t=[],n=[];for(var i=0,o=this._objects.length;o>i;i++)e=this._objects[i],-1===r.indexOf(e)?t.push(e):n.push(e);r.length>1&&(this._activeObject._objects=n),t.push.apply(t,n)}else t=this._objects;return t},renderAll:function(){!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&this.renderTopLayer(this.contextTop);var e=this.contextContainer;return this.renderCanvas(e,this._chooseObjectsToRender()),this},renderTopLayer:function(e){this.isDrawingMode&&this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.selection&&this._groupSelector&&this._drawSelection(e)},renderTop:function(){var e=this.contextTop;return this.clearContext(e),this.renderTopLayer(e),this.fire("after:render"),this.contextTopDirty=!0,this},_resetCurrentTransform:function(){var e=this._currentTransform;e.target.set({scaleX:e.original.scaleX,scaleY:e.original.scaleY,skewX:e.original.skewX,skewY:e.original.skewY,left:e.original.left,top:e.original.top}),this._shouldCenterTransform(e.target)?("center"!==e.originX&&(e.mouseXSign="right"===e.originX?-1:1),"center"!==e.originY&&(e.mouseYSign="bottom"===e.originY?-1:1),e.originX="center",e.originY="center"):(e.originX=e.original.originX,e.originY=e.original.originY)},containsPoint:function(e,t,n){var r,i=!0,o=n||this.getPointer(e,i);return r=t.group&&t.group===this._activeObject&&"activeSelection"===t.group.type?this._normalizePointer(t.group,o):{x:o.x,y:o.y},t.containsPoint(r)||t._findTargetCorner(o)},_normalizePointer:function(e,t){var n=e.calcTransformMatrix(),r=fabric.util.invertTransform(n),i=this.restorePointerVpt(t);return fabric.util.transformPoint(i,r)},isTargetTransparent:function(e,t,n){if(e.shouldCache()&&e._cacheCanvas){var r=this._normalizePointer(e,{x:t,y:n}),i=e.cacheTranslationX+r.x*e.zoomX,o=e.cacheTranslationY+r.y*e.zoomY,s=fabric.util.isTransparent(e._cacheContext,i,o,this.targetFindTolerance);return s}var a=this.contextCache,c=e.selectionBackgroundColor,u=this.viewportTransform;e.selectionBackgroundColor="",this.clearContext(a),a.save(),a.transform(u[0],u[1],u[2],u[3],u[4],u[5]),e.render(a),a.restore(),e===this._activeObject&&e._renderControls(a,{hasBorders:!1,transparentCorners:!1},{hasBorders:!1}),e.selectionBackgroundColor=c;var s=fabric.util.isTransparent(a,t,n,this.targetFindTolerance);return s},_isSelectionKeyPressed:function(e){var t=!1;return t="[object Array]"===Object.prototype.toString.call(this.selectionKey)?!!this.selectionKey.find(function(t){return e[t]===!0}):e[this.selectionKey]},_shouldClearSelection:function(e,t){var n=this.getActiveObjects(),r=this._activeObject;return!t||t&&r&&n.length>1&&-1===n.indexOf(t)&&r!==t&&!this._isSelectionKeyPressed(e)||t&&!t.evented||t&&!t.selectable&&r&&r!==t},_shouldCenterTransform:function(e){if(e){var t,n=this._currentTransform;return"scale"===n.action||"scaleX"===n.action||"scaleY"===n.action?t=this.centeredScaling||e.centeredScaling:"rotate"===n.action&&(t=this.centeredRotation||e.centeredRotation),t?!n.altKey:n.altKey}},_getOriginFromCorner:function(e,t){var n={x:e.originX,y:e.originY};return"ml"===t||"tl"===t||"bl"===t?n.x="right":("mr"===t||"tr"===t||"br"===t)&&(n.x="left"),"tl"===t||"mt"===t||"tr"===t?n.y="bottom":("bl"===t||"mb"===t||"br"===t)&&(n.y="top"),n},_getActionFromCorner:function(e,t,n){if(!t)return"drag";switch(t){case"mtr":return"rotate";case"ml":case"mr":return n[this.altActionKey]?"skewY":"scaleX";case"mt":case"mb":return n[this.altActionKey]?"skewX":"scaleY";default:return"scale"}},_setupCurrentTransform:function(e,n){if(n){var r=this.getPointer(e),i=n._findTargetCorner(this.getPointer(e,!0)),o=this._getActionFromCorner(n,i,e),s=this._getOriginFromCorner(n,i);this._currentTransform={target:n,action:o,corner:i,scaleX:n.scaleX,scaleY:n.scaleY,skewX:n.skewX,skewY:n.skewY,offsetX:r.x-n.left,offsetY:r.y-n.top,originX:s.x,originY:s.y,ex:r.x,ey:r.y,lastX:r.x,lastY:r.y,theta:t(n.angle),width:n.width*n.scaleX,mouseXSign:1,mouseYSign:1,shiftKey:e.shiftKey,altKey:e[this.centeredKey]},this._currentTransform.original={left:n.left,top:n.top,scaleX:n.scaleX,scaleY:n.scaleY,skewX:n.skewX,skewY:n.skewY,originX:s.x,originY:s.y},this._resetCurrentTransform(),this._beforeTransform(e)}},_translateObject:function(e,t){var n=this._currentTransform,r=n.target,i=e-n.offsetX,o=t-n.offsetY,s=!r.get("lockMovementX")&&r.left!==i,a=!r.get("lockMovementY")&&r.top!==o;return s&&r.set("left",i),a&&r.set("top",o),s||a},_changeSkewTransformOrigin:function(e,t,n){var r="originX",i={0:"center"},o=t.target.skewX,s="left",a="right",c="mt"===t.corner||"ml"===t.corner?1:-1,u=1;e=e>0?1:-1,"y"===n&&(o=t.target.skewY,s="top",a="bottom",r="originY"),i[-1]=s,i[1]=a,t.target.flipX&&(u*=-1),t.target.flipY&&(u*=-1),0===o?(t.skewSign=-c*e*u,t[r]=i[-e]):(o=o>0?1:-1,t.skewSign=o,t[r]=i[o*c*u])},_skewObject:function(e,t,n){var r=this._currentTransform,i=r.target,o=!1,s=i.get("lockSkewingX"),a=i.get("lockSkewingY");if(s&&"x"===n||a&&"y"===n)return!1;var c,u,l=i.getCenterPoint(),f=i.toLocalPoint(new fabric.Point(e,t),"center","center")[n],h=i.toLocalPoint(new fabric.Point(r.lastX,r.lastY),"center","center")[n],d=i._getTransformedDimensions();return this._changeSkewTransformOrigin(f-h,r,n),c=i.toLocalPoint(new fabric.Point(e,t),r.originX,r.originY)[n],u=i.translateToOriginPoint(l,r.originX,r.originY),o=this._setObjectSkew(c,r,n,d),r.lastX=e,r.lastY=t,i.setPositionByOrigin(u,r.originX,r.originY),o},_setObjectSkew:function(e,t,n,r){var i,o,s,a,c,u,l,f,h,d=t.target,p=!1,v=t.skewSign;return"x"===n?(a="y",c="Y",u="X",f=0,h=d.skewY):(a="x",c="X",u="Y",f=d.skewX,h=0),s=d._getTransformedDimensions(f,h),l=2*Math.abs(e)-s[n],2>=l?i=0:(i=v*Math.atan(l/d["scale"+u]/(s[a]/d["scale"+c])),i=fabric.util.radiansToDegrees(i)),p=d["skew"+u]!==i,d.set("skew"+u,i),0!==d["skew"+c]&&(o=d._getTransformedDimensions(),i=r[a]/o[a]*d["scale"+c],d.set("scale"+c,i)),p},_scaleObject:function(e,t,n){var r=this._currentTransform,i=r.target,o=i.lockScalingX,s=i.lockScalingY,a=i.lockScalingFlip;if(o&&s)return!1;var c=i.translateToOriginPoint(i.getCenterPoint(),r.originX,r.originY),u=i.toLocalPoint(new fabric.Point(e,t),r.originX,r.originY),l=i._getTransformedDimensions(),f=!1;return this._setLocalMouse(u,r),f=this._setObjectScale(u,r,o,s,n,a,l),i.setPositionByOrigin(c,r.originX,r.originY),f},_setObjectScale:function(e,t,n,r,i,o,s){var a,c,u,l,f=t.target,h=!1,d=!1,p=!1;return u=e.x*f.scaleX/s.x,l=e.y*f.scaleY/s.y,a=f.scaleX!==u,c=f.scaleY!==l,o&&0>=u&&u<f.scaleX&&(h=!0,e.x=0),o&&0>=l&&l<f.scaleY&&(d=!0,e.y=0),"equally"!==i||n||r?i?"x"!==i||f.get("lockUniScaling")?"y"!==i||f.get("lockUniScaling")||d||r||f.set("scaleY",l)&&(p=p||c):h||n||f.set("scaleX",u)&&(p=p||a):(h||n||f.set("scaleX",u)&&(p=p||a),d||r||f.set("scaleY",l)&&(p=p||c)):p=this._scaleObjectEqually(e,f,t,s),t.newScaleX=u,t.newScaleY=l,h||d||this._flipObject(t,i),p},_scaleObjectEqually:function(e,t,n,r){var i,o=e.y+e.x,s=r.y*n.original.scaleY/t.scaleY+r.x*n.original.scaleX/t.scaleX,a=e.x<0?-1:1,c=e.y<0?-1:1;return n.newScaleX=a*Math.abs(n.original.scaleX*o/s),n.newScaleY=c*Math.abs(n.original.scaleY*o/s),i=n.newScaleX!==t.scaleX||n.newScaleY!==t.scaleY,t.set("scaleX",n.newScaleX),t.set("scaleY",n.newScaleY),i},_flipObject:function(e,t){e.newScaleX<0&&"y"!==t&&("left"===e.originX?e.originX="right":"right"===e.originX&&(e.originX="left")),e.newScaleY<0&&"x"!==t&&("top"===e.originY?e.originY="bottom":"bottom"===e.originY&&(e.originY="top"))},_setLocalMouse:function(e,t){var n=t.target,r=this.getZoom(),o=n.padding/r;"right"===t.originX?e.x*=-1:"center"===t.originX&&(e.x*=2*t.mouseXSign,e.x<0&&(t.mouseXSign=-t.mouseXSign)),"bottom"===t.originY?e.y*=-1:"center"===t.originY&&(e.y*=2*t.mouseYSign,e.y<0&&(t.mouseYSign=-t.mouseYSign)),i(e.x)>o?e.x<0?e.x+=o:e.x-=o:e.x=0,i(e.y)>o?e.y<0?e.y+=o:e.y-=o:e.y=0},_rotateObject:function(e,t){var i,o=this._currentTransform,s=o.target,i=s.translateToOriginPoint(s.getCenterPoint(),o.originX,o.originY);if(s.lockRotation)return!1;var a=r(o.ey-i.y,o.ex-i.x),c=r(t-i.y,e-i.x),u=n(c-a+o.theta),l=!0;if(s.snapAngle>0){var f=s.snapAngle,h=s.snapThreshold||f,d=Math.ceil(u/f)*f,p=Math.floor(u/f)*f;Math.abs(u-p)<h?u=p:Math.abs(u-d)<h&&(u=d)}return 0>u&&(u=360+u),u%=360,s.angle===u?l=!1:(s.angle=u,s.setPositionByOrigin(i,o.originX,o.originY)),l},setCursor:function(e){this.upperCanvasEl.style.cursor=e},_resetObjectTransform:function(e){e.scaleX=1,e.scaleY=1,e.skewX=0,e.skewY=0,e.rotate(0)},_drawSelection:function(e){var t=this._groupSelector,n=t.left,r=t.top,a=i(n),c=i(r);if(this.selectionColor&&(e.fillStyle=this.selectionColor,e.fillRect(t.ex-(n>0?0:-n),t.ey-(r>0?0:-r),a,c)),this.selectionLineWidth&&this.selectionBorderColor)if(e.lineWidth=this.selectionLineWidth,e.strokeStyle=this.selectionBorderColor,this.selectionDashArray.length>1&&!o){var u=t.ex+s-(n>0?0:a),l=t.ey+s-(r>0?0:c);e.beginPath(),fabric.util.drawDashedLine(e,u,l,u+a,l,this.selectionDashArray),fabric.util.drawDashedLine(e,u,l+c-1,u+a,l+c-1,this.selectionDashArray),fabric.util.drawDashedLine(e,u,l,u,l+c,this.selectionDashArray),fabric.util.drawDashedLine(e,u+a-1,l,u+a-1,l+c,this.selectionDashArray),e.closePath(),e.stroke()}else fabric.Object.prototype._setLineDash.call(this,e,this.selectionDashArray),e.strokeRect(t.ex+s-(n>0?0:a),t.ey+s-(r>0?0:c),a,c)},findTarget:function(e,t){if(!this.skipTargetFind){var n,r,i=!0,o=this.getPointer(e,i),s=this._activeObject,a=this.getActiveObjects();if(this.targets=[],a.length>1&&!t&&s===this._searchPossibleTargets([s],o))return s;if(1===a.length&&s._findTargetCorner(o))return s;if(1===a.length&&s===this._searchPossibleTargets([s],o)){if(!this.preserveObjectStacking)return s;n=s,r=this.targets,this.targets=[]}var c=this._searchPossibleTargets(this._objects,o);return e[this.altSelectionKey]&&c&&n&&c!==n&&(c=n,this.targets=r),c}},_checkTarget:function(e,t){if(t&&t.visible&&t.evented&&this.containsPoint(null,t,e)){if(!this.perPixelTargetFind&&!t.perPixelTargetFind||t.isEditing)return!0;var n=this.isTargetTransparent(t,e.x,e.y);if(!n)return!0}},_searchPossibleTargets:function(e,t){for(var n,r,i,o=e.length;o--;)if(this._checkTarget(t,e[o])){n=e[o],n.subTargetCheck&&n instanceof fabric.Group&&(r=this._normalizePointer(n,t),i=this._searchPossibleTargets(n._objects,r),i&&this.targets.push(i));break}return n},restorePointerVpt:function(e){return fabric.util.transformPoint(e,fabric.util.invertTransform(this.viewportTransform))},getPointer:function(t,n){if(this._absolutePointer&&!n)return this._absolutePointer;if(this._pointer&&n)return this._pointer;var r,i=e(t),o=this.upperCanvasEl,s=o.getBoundingClientRect(),a=s.width||0,c=s.height||0;return a&&c||("top"in s&&"bottom"in s&&(c=Math.abs(s.top-s.bottom)),"right"in s&&"left"in s&&(a=Math.abs(s.right-s.left))),this.calcOffset(),i.x=i.x-this._offset.left,i.y=i.y-this._offset.top,n||(i=this.restorePointerVpt(i)),r=0===a||0===c?{width:1,height:1}:{width:o.width/a,height:o.height/c},{x:i.x*r.width,y:i.y*r.height}},_createUpperCanvas:function(){var e=this.lowerCanvasEl.className.replace(/\s*lower-canvas\s*/,"");this.upperCanvasEl?this.upperCanvasEl.className="":this.upperCanvasEl=this._createCanvasElement(),fabric.util.addClass(this.upperCanvasEl,"upper-canvas "+e),this.wrapperEl.appendChild(this.upperCanvasEl),this._copyCanvasStyle(this.lowerCanvasEl,this.upperCanvasEl),this._applyCanvasStyle(this.upperCanvasEl),this.contextTop=this.upperCanvasEl.getContext("2d")},_createCacheCanvas:function(){this.cacheCanvasEl=this._createCanvasElement(),this.cacheCanvasEl.setAttribute("width",this.width),this.cacheCanvasEl.setAttribute("height",this.height),this.contextCache=this.cacheCanvasEl.getContext("2d")},_initWrapperElement:function(){this.wrapperEl=fabric.util.wrapElement(this.lowerCanvasEl,"div",{"class":this.containerClass}),fabric.util.setStyle(this.wrapperEl,{width:this.width+"px",height:this.height+"px",position:"relative"}),fabric.util.makeElementUnselectable(this.wrapperEl)},_applyCanvasStyle:function(e){var t=this.width||e.width,n=this.height||e.height;fabric.util.setStyle(e,{position:"absolute",width:t+"px",height:n+"px",left:0,top:0,"touch-action":this.allowTouchScrolling?"manipulation":"none"}),e.width=t,e.height=n,fabric.util.makeElementUnselectable(e)},_copyCanvasStyle:function(e,t){t.style.cssText=e.style.cssText},getSelectionContext:function(){return this.contextTop},getSelectionElement:function(){return this.upperCanvasEl},getActiveObject:function(){return this._activeObject},getActiveObjects:function(){var e=this._activeObject;return e?"activeSelection"===e.type&&e._objects?e._objects.slice(0):[e]:[]},_onObjectRemoved:function(e){e===this._activeObject&&(this.fire("before:selection:cleared",{target:e}),this._discardActiveObject(),this.fire("selection:cleared",{target:e}),e.fire("deselected")),this._hoveredTarget===e&&(this._hoveredTarget=null),this.callSuper("_onObjectRemoved",e)},_fireSelectionEvents:function(e,t){var n=!1,r=this.getActiveObjects(),i=[],o=[],s={e:t};e.forEach(function(e){-1===r.indexOf(e)&&(n=!0,e.fire("deselected",s),o.push(e))}),r.forEach(function(t){-1===e.indexOf(t)&&(n=!0,t.fire("selected",s),i.push(t))}),e.length>0&&r.length>0?(s.selected=i,s.deselected=o,s.updated=i[0]||o[0],s.target=this._activeObject,n&&this.fire("selection:updated",s)):r.length>0?(1===r.length&&(s.target=i[0],this.fire("object:selected",s)),s.selected=i,s.target=this._activeObject,this.fire("selection:created",s)):e.length>0&&(s.deselected=o,this.fire("selection:cleared",s))},setActiveObject:function(e,t){var n=this.getActiveObjects();return this._setActiveObject(e,t),this._fireSelectionEvents(n,t),this},_setActiveObject:function(e,t){return this._activeObject===e?!1:this._discardActiveObject(t,e)?e.onSelect({e:t})?!1:(this._activeObject=e,!0):!1},_discardActiveObject:function(e,t){var n=this._activeObject;if(n){if(n.onDeselect({e:e,object:t}))return!1;this._activeObject=null}return!0},discardActiveObject:function(e){var t=this.getActiveObjects();return t.length&&this.fire("before:selection:cleared",{target:t[0],e:e}),this._discardActiveObject(e),this._fireSelectionEvents(t,e),this},dispose:function(){var e=this.wrapperEl;return this.removeListeners(),e.removeChild(this.upperCanvasEl),e.removeChild(this.lowerCanvasEl),this.upperCanvasEl=null,this.cacheCanvasEl=null,this.contextCache=null,this.contextTop=null,e.parentNode&&e.parentNode.replaceChild(this.lowerCanvasEl,this.wrapperEl),delete this.wrapperEl,fabric.StaticCanvas.prototype.dispose.call(this),this},clear:function(){return this.discardActiveObject(),this.clearContext(this.contextTop),this.callSuper("clear")},drawControls:function(e){var t=this._activeObject;t&&t._renderControls(e)},_toObject:function(e,t,n){var r=this._realizeGroupTransformOnObject(e),i=this.callSuper("_toObject",e,t,n);return this._unwindGroupTransformOnObject(e,r),i},_realizeGroupTransformOnObject:function(e){if(e.group&&"activeSelection"===e.group.type&&this._activeObject===e.group){var t=["angle","flipX","flipY","left","scaleX","scaleY","skewX","skewY","top"],n={};return t.forEach(function(t){n[t]=e[t]}),this._activeObject.realizeTransform(e),n}return null},_unwindGroupTransformOnObject:function(e,t){t&&e.set(t)},_setSVGObject:function(e,t,n){var r=this._realizeGroupTransformOnObject(t);this.callSuper("_setSVGObject",e,t,n),this._unwindGroupTransformOnObject(t,r)},setViewportTransform:function(e){this.renderOnAddRemove&&this._activeObject&&this._activeObject.isEditing&&this._activeObject.clearContextTop(),fabric.StaticCanvas.prototype.setViewportTransform.call(this,e)}});for(var a in fabric.StaticCanvas)"prototype"!==a&&(fabric.Canvas[a]=fabric.StaticCanvas[a]);fabric.isTouchSupported&&(fabric.Canvas.prototype._setCursorFromEvent=function(){})}();!function(){function e(e,t){return"which"in e?e.which===t:e.button===t-1}var t={mt:0,tr:1,mr:2,br:3,mb:4,bl:5,ml:6,tl:7},n=fabric.util.addListener,r=fabric.util.removeListener,i=3,o=2,s=1,a={passive:!1};fabric.util.object.extend(fabric.Canvas.prototype,{cursorMap:["n-resize","ne-resize","e-resize","se-resize","s-resize","sw-resize","w-resize","nw-resize"],_initEventListeners:function(){this.removeListeners(),this._bindEvents(),this.addOrRemove(n,"add")},addOrRemove:function(e,t){e(fabric.window,"resize",this._onResize),e(this.upperCanvasEl,"mousedown",this._onMouseDown),e(this.upperCanvasEl,"mousemove",this._onMouseMove,a),e(this.upperCanvasEl,"mouseout",this._onMouseOut),e(this.upperCanvasEl,"mouseenter",this._onMouseEnter),e(this.upperCanvasEl,"wheel",this._onMouseWheel),e(this.upperCanvasEl,"contextmenu",this._onContextMenu),e(this.upperCanvasEl,"dblclick",this._onDoubleClick),e(this.upperCanvasEl,"touchstart",this._onMouseDown,a),e(this.upperCanvasEl,"touchmove",this._onMouseMove,a),e(this.upperCanvasEl,"dragover",this._onDragOver),e(this.upperCanvasEl,"dragenter",this._onDragEnter),e(this.upperCanvasEl,"dragleave",this._onDragLeave),e(this.upperCanvasEl,"drop",this._onDrop),"undefined"!=typeof eventjs&&t in eventjs&&(eventjs[t](this.upperCanvasEl,"gesture",this._onGesture),eventjs[t](this.upperCanvasEl,"drag",this._onDrag),eventjs[t](this.upperCanvasEl,"orientation",this._onOrientationChange),eventjs[t](this.upperCanvasEl,"shake",this._onShake),eventjs[t](this.upperCanvasEl,"longpress",this._onLongPress))},removeListeners:function(){this.addOrRemove(r,"remove"),r(fabric.document,"mouseup",this._onMouseUp),r(fabric.document,"touchend",this._onMouseUp,a),r(fabric.document,"mousemove",this._onMouseMove,a),r(fabric.document,"touchmove",this._onMouseMove,a)},_bindEvents:function(){this.eventsBound||(this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onResize=this._onResize.bind(this),this._onGesture=this._onGesture.bind(this),this._onDrag=this._onDrag.bind(this),this._onShake=this._onShake.bind(this),this._onLongPress=this._onLongPress.bind(this),this._onOrientationChange=this._onOrientationChange.bind(this),this._onMouseWheel=this._onMouseWheel.bind(this),this._onMouseOut=this._onMouseOut.bind(this),this._onMouseEnter=this._onMouseEnter.bind(this),this._onContextMenu=this._onContextMenu.bind(this),this._onDoubleClick=this._onDoubleClick.bind(this),this._onDragOver=this._onDragOver.bind(this),this._onDragEnter=this._simpleEventHandler.bind(this,"dragenter"),this._onDragLeave=this._simpleEventHandler.bind(this,"dragleave"),this._onDrop=this._simpleEventHandler.bind(this,"drop"),this.eventsBound=!0)},_onGesture:function(e,t){this.__onTransformGesture&&this.__onTransformGesture(e,t)},_onDrag:function(e,t){this.__onDrag&&this.__onDrag(e,t)},_onMouseWheel:function(e){this.__onMouseWheel(e)},_onMouseOut:function(e){var t=this._hoveredTarget;this.fire("mouse:out",{target:t,e:e}),this._hoveredTarget=null,t&&t.fire("mouseout",{e:e}),this._iTextInstances&&this._iTextInstances.forEach(function(e){e.isEditing&&e.hiddenTextarea.focus()})},_onMouseEnter:function(e){this.findTarget(e)||(this.fire("mouse:over",{target:null,e:e}),this._hoveredTarget=null)},_onOrientationChange:function(e,t){this.__onOrientationChange&&this.__onOrientationChange(e,t)},_onShake:function(e,t){this.__onShake&&this.__onShake(e,t)},_onLongPress:function(e,t){this.__onLongPress&&this.__onLongPress(e,t)},_onDragOver:function(e){e.preventDefault();var t=this._simpleEventHandler("dragover",e);this._fireEnterLeaveEvents(t,e)},_onContextMenu:function(e){return this.stopContextMenu&&(e.stopPropagation(),e.preventDefault()),!1},_onDoubleClick:function(e){this._cacheTransformEventData(e),this._handleEvent(e,"dblclick"),this._resetTransformEventData(e)},_onMouseDown:function(e){this.__onMouseDown(e),this._resetTransformEventData(),n(fabric.document,"touchend",this._onMouseUp,a),n(fabric.document,"touchmove",this._onMouseMove,a),r(this.upperCanvasEl,"mousemove",this._onMouseMove,a),r(this.upperCanvasEl,"touchmove",this._onMouseMove,a),"touchstart"===e.type?r(this.upperCanvasEl,"mousedown",this._onMouseDown):(n(fabric.document,"mouseup",this._onMouseUp),n(fabric.document,"mousemove",this._onMouseMove,a))},_onMouseUp:function(e){if(this.__onMouseUp(e),this._resetTransformEventData(),r(fabric.document,"mouseup",this._onMouseUp),r(fabric.document,"touchend",this._onMouseUp,a),r(fabric.document,"mousemove",this._onMouseMove,a),r(fabric.document,"touchmove",this._onMouseMove,a),n(this.upperCanvasEl,"mousemove",this._onMouseMove,a),n(this.upperCanvasEl,"touchmove",this._onMouseMove,a),"touchend"===e.type){var t=this;setTimeout(function(){n(t.upperCanvasEl,"mousedown",t._onMouseDown)},400)}},_onMouseMove:function(e){!this.allowTouchScrolling&&e.preventDefault&&e.preventDefault(),this.__onMouseMove(e)},_onResize:function(){this.calcOffset()},_shouldRender:function(e,t){var n=this._activeObject;return n&&n.isEditing&&e===n?!1:!!(e&&(e.isMoving||e!==n)||!e&&n||!e&&!n&&!this._groupSelector||t&&this._previousPointer&&this.selection&&(t.x!==this._previousPointer.x||t.y!==this._previousPointer.y))},__onMouseUp:function(t){var n,r=this._currentTransform,a=this._groupSelector,c=!a||0===a.left&&0===a.top;if(this._cacheTransformEventData(t),n=this._target,this._handleEvent(t,"up:before"),e(t,i))return void(this.fireRightClick&&this._handleEvent(t,"up",i,c));if(e(t,o))return this.fireMiddleClick&&this._handleEvent(t,"up",o,c),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)return void this._onMouseUpInDrawingMode(t);r&&this._finalizeCurrentTransform(t);var u=this._shouldRender(n,this._absolutePointer);(n||!c)&&this._maybeGroupObjects(t),n&&(n.isMoving=!1),this._setCursorFromEvent(t,n),this._handleEvent(t,"up",s,c),this._groupSelector=null,this._currentTransform=null,n&&(n.__corner=0),u&&this.requestRenderAll()},_simpleEventHandler:function(e,t){var n=this.findTarget(t),r=this.targets,i={e:t,target:n,subTargets:r};if(this.fire(e,i),n&&n.fire(e,i),!r)return n;for(var o=0;o<r.length;o++)r[o].fire(e,i);return n},_handleEvent:function(e,t,n,r){var i=this._target,o=this.targets||[],a={e:e,target:i,subTargets:o,button:n||s,isClick:r||!1,pointer:this._pointer,absolutePointer:this._absolutePointer,transform:this._currentTransform};this.fire("mouse:"+t,a),i&&i.fire("mouse"+t,a);for(var c=0;c<o.length;c++)o[c].fire("mouse"+t,a)},_finalizeCurrentTransform:function(e){var t,n=this._currentTransform,r=n.target,i={e:e,target:r,transform:n};r._scaling&&(r._scaling=!1),r.setCoords(),(n.actionPerformed||this.stateful&&r.hasStateChanged())&&(n.actionPerformed&&(t=this._addEventOptions(i,n),this._fire(t,i)),this._fire("modified",i))},_addEventOptions:function(e,t){var n,r;switch(t.action){case"scaleX":n="scaled",r="x";break;case"scaleY":n="scaled",r="y";break;case"skewX":n="skewed",r="x";break;case"skewY":n="skewed",r="y";break;case"scale":n="scaled",r="equally";break;case"rotate":n="rotated";break;case"drag":n="moved"}return e.by=r,n},_onMouseDownInDrawingMode:function(e){this._isCurrentlyDrawing=!0,this.getActiveObject()&&this.discardActiveObject(e).requestRenderAll(),this.clipTo&&fabric.util.clipContext(this,this.contextTop);var t=this.getPointer(e);this.freeDrawingBrush.onMouseDown(t),this._handleEvent(e,"down")},_onMouseMoveInDrawingMode:function(e){if(this._isCurrentlyDrawing){var t=this.getPointer(e);this.freeDrawingBrush.onMouseMove(t)}this.setCursor(this.freeDrawingCursor),this._handleEvent(e,"move")},_onMouseUpInDrawingMode:function(e){this._isCurrentlyDrawing=!1,this.clipTo&&this.contextTop.restore(),this.freeDrawingBrush.onMouseUp(),this._handleEvent(e,"up")},__onMouseDown:function(t){this._cacheTransformEventData(t),this._handleEvent(t,"down:before");var n=this._target;if(e(t,i))return void(this.fireRightClick&&this._handleEvent(t,"down",i));if(e(t,o))return void(this.fireMiddleClick&&this._handleEvent(t,"down",o));if(this.isDrawingMode)return void this._onMouseDownInDrawingMode(t);if(!this._currentTransform){var r=this._pointer;this._previousPointer=r;var s=this._shouldRender(n,r),a=this._shouldGroup(t,n);this._shouldClearSelection(t,n)?this.discardActiveObject(t):a&&(this._handleGrouping(t,n),n=this._activeObject),!this.selection||n&&(n.selectable||n.isEditing||n===this._activeObject)||(this._groupSelector={ex:r.x,ey:r.y,top:0,left:0}),n&&(n.selectable&&this.setActiveObject(n,t),n!==this._activeObject||!n.__corner&&a||this._setupCurrentTransform(t,n)),this._handleEvent(t,"down"),s&&this.requestRenderAll()}},_resetTransformEventData:function(){this._target=null,this._pointer=null,this._absolutePointer=null},_cacheTransformEventData:function(e){this._resetTransformEventData(),this._pointer=this.getPointer(e,!0),this._absolutePointer=this.restorePointerVpt(this._pointer),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(e)||null},_beforeTransform:function(e){var t=this._currentTransform;this.stateful&&t.target.saveState(),this.fire("before:transform",{e:e,transform:t}),t.corner&&this.onBeforeScaleRotate(t.target)},__onMouseMove:function(e){this._handleEvent(e,"move:before"),this._cacheTransformEventData(e);var t,n;if(this.isDrawingMode)return void this._onMouseMoveInDrawingMode(e);if(!("undefined"!=typeof e.touches&&e.touches.length>1)){var r=this._groupSelector;r?(n=this._pointer,r.left=n.x-r.ex,r.top=n.y-r.ey,this.renderTop()):this._currentTransform?this._transformObject(e):(t=this.findTarget(e)||null,this._setCursorFromEvent(e,t),this._fireOverOutEvents(t,e)),this._handleEvent(e,"move"),this._resetTransformEventData()}},_fireOverOutEvents:function(e,t){this.fireSynteticInOutEvents(e,t,{targetName:"_hoveredTarget",canvasEvtOut:"mouse:out",evtOut:"mouseout",canvasEvtIn:"mouse:over",evtIn:"mouseover"})},_fireEnterLeaveEvents:function(e,t){this.fireSynteticInOutEvents(e,t,{targetName:"_draggedoverTarget",evtOut:"dragleave",evtIn:"dragenter"})},fireSynteticInOutEvents:function(e,t,n){var r,i,o,s,a=this[n.targetName],c=a!==e,u=n.canvasEvtIn,l=n.canvasEvtOut;c&&(r={e:t,target:e,previousTarget:a},i={e:t,target:a,nextTarget:e},this[n.targetName]=e),s=e&&c,o=a&&c,o&&(l&&this.fire(l,i),a.fire(n.evtOut,i)),s&&(u&&this.fire(u,r),e.fire(n.evtIn,r))},__onMouseWheel:function(e){this._cacheTransformEventData(e),this._handleEvent(e,"wheel"),this._resetTransformEventData()},_transformObject:function(e){var t=this.getPointer(e),n=this._currentTransform;n.reset=!1,n.target.isMoving=!0,n.shiftKey=e.shiftKey,n.altKey=e[this.centeredKey],this._beforeScaleTransform(e,n),this._performTransformAction(e,n,t),n.actionPerformed&&this.requestRenderAll()},_performTransformAction:function(e,t,n){var r=n.x,i=n.y,o=t.action,s=!1,a={target:t.target,e:e,transform:t,pointer:n};"rotate"===o?(s=this._rotateObject(r,i))&&this._fire("rotating",a):"scale"===o?(s=this._onScale(e,t,r,i))&&this._fire("scaling",a):"scaleX"===o?(s=this._scaleObject(r,i,"x"))&&this._fire("scaling",a):"scaleY"===o?(s=this._scaleObject(r,i,"y"))&&this._fire("scaling",a):"skewX"===o?(s=this._skewObject(r,i,"x"))&&this._fire("skewing",a):"skewY"===o?(s=this._skewObject(r,i,"y"))&&this._fire("skewing",a):(s=this._translateObject(r,i),s&&(this._fire("moving",a),this.setCursor(a.target.moveCursor||this.moveCursor))),t.actionPerformed=t.actionPerformed||s},_fire:function(e,t){this.fire("object:"+e,t),t.target.fire(e,t)},_beforeScaleTransform:function(e,t){if("scale"===t.action||"scaleX"===t.action||"scaleY"===t.action){var n=this._shouldCenterTransform(t.target);(n&&("center"!==t.originX||"center"!==t.originY)||!n&&"center"===t.originX&&"center"===t.originY)&&(this._resetCurrentTransform(),t.reset=!0)}},_onScale:function(e,t,n,r){return this._isUniscalePossible(e,t.target)?(t.currentAction="scale",this._scaleObject(n,r)):(t.reset||"scale"!==t.currentAction||this._resetCurrentTransform(),t.currentAction="scaleEqually",this._scaleObject(n,r,"equally"))},_isUniscalePossible:function(e,t){return(e[this.uniScaleKey]||this.uniScaleTransform)&&!t.get("lockUniScaling")},_setCursorFromEvent:function(e,t){if(!t)return this.setCursor(this.defaultCursor),!1;var n=t.hoverCursor||this.hoverCursor,r=this._activeObject&&"activeSelection"===this._activeObject.type?this._activeObject:null,i=(!r||!r.contains(t))&&t._findTargetCorner(this.getPointer(e,!0));this.setCursor(i?this.getCornerCursor(i,t,e):n)},getCornerCursor:function(e,n,r){return this.actionIsDisabled(e,n,r)?this.notAllowedCursor:e in t?this._getRotatedCornerCursor(e,n,r):"mtr"===e&&n.hasRotatingPoint?this.rotationCursor:this.defaultCursor},actionIsDisabled:function(e,t,n){return"mt"===e||"mb"===e?n[this.altActionKey]?t.lockSkewingX:t.lockScalingY:"ml"===e||"mr"===e?n[this.altActionKey]?t.lockSkewingY:t.lockScalingX:"mtr"===e?t.lockRotation:this._isUniscalePossible(n,t)?t.lockScalingX&&t.lockScalingY:t.lockScalingX||t.lockScalingY},_getRotatedCornerCursor:function(e,n,r){var i=Math.round(n.angle%360/45);return 0>i&&(i+=8),i+=t[e],r[this.altActionKey]&&t[e]%2===0&&(i+=2),i%=8,this.cursorMap[i]}})}();!function(){var e=Math.min,t=Math.max;fabric.util.object.extend(fabric.Canvas.prototype,{_shouldGroup:function(e,t){var n=this._activeObject;return n&&this._isSelectionKeyPressed(e)&&t&&t.selectable&&this.selection&&(n!==t||"activeSelection"===n.type)},_handleGrouping:function(e,t){var n=this._activeObject;n.__corner||(t!==n||(t=this.findTarget(e,!0)))&&(n&&"activeSelection"===n.type?this._updateActiveSelection(t,e):this._createActiveSelection(t,e))},_updateActiveSelection:function(e,t){var n=this._activeObject,r=n._objects.slice(0);n.contains(e)?(n.removeWithUpdate(e),this._hoveredTarget=e,1===n.size()&&this._setActiveObject(n.item(0),t)):(n.addWithUpdate(e),this._hoveredTarget=n),this._fireSelectionEvents(r,t)},_createActiveSelection:function(e,t){var n=this.getActiveObjects(),r=this._createGroup(e);this._hoveredTarget=r,this._setActiveObject(r,t),this._fireSelectionEvents(n,t)},_createGroup:function(e){var t=this.getObjects(),n=t.indexOf(this._activeObject)<t.indexOf(e),r=n?[this._activeObject,e]:[e,this._activeObject];return this._activeObject.isEditing&&this._activeObject.exitEditing(),new fabric.ActiveSelection(r,{canvas:this})},_groupSelectedObjects:function(e){var t,n=this._collectObjects();1===n.length?this.setActiveObject(n[0],e):n.length>1&&(t=new fabric.ActiveSelection(n.reverse(),{canvas:this}),this.setActiveObject(t,e))},_collectObjects:function(){for(var n,r=[],i=this._groupSelector.ex,o=this._groupSelector.ey,s=i+this._groupSelector.left,a=o+this._groupSelector.top,c=new fabric.Point(e(i,s),e(o,a)),u=new fabric.Point(t(i,s),t(o,a)),l=!this.selectionFullyContained,f=i===s&&o===a,h=this._objects.length;h--&&(n=this._objects[h],!(n&&n.selectable&&n.visible&&(l&&n.intersectsWithRect(c,u)||n.isContainedWithinRect(c,u)||l&&n.containsPoint(c)||l&&n.containsPoint(u))&&(r.push(n),f))););return r},_maybeGroupObjects:function(e){this.selection&&this._groupSelector&&this._groupSelectedObjects(e),this.setCursor(this.defaultCursor),this._groupSelector=null}})}();!function(){var e=fabric.StaticCanvas.supports("toDataURLWithQuality");fabric.util.object.extend(fabric.StaticCanvas.prototype,{toDataURL:function(e){e||(e={});var t=e.format||"png",n=e.quality||1,r=(e.multiplier||1)*(e.enableRetinaScaling?1:1/this.getRetinaScaling()),i={left:e.left||0,top:e.top||0,width:e.width||0,height:e.height||0};return this.__toDataURLWithMultiplier(t,n,i,r)},__toDataURLWithMultiplier:function(e,t,n,r){var i=this.width,o=this.height,s=(n.width||this.width)*r,a=(n.height||this.height)*r,c=this.getZoom(),u=c*r,l=this.viewportTransform,f=(l[4]-n.left)*r,h=(l[5]-n.top)*r,d=[u,0,0,u,f,h],v=this.interactive,p=this.skipOffscreen,g=i!==s||o!==a;this.viewportTransform=d,this.skipOffscreen=!1,this.interactive=!1,g&&this.setDimensions({width:s,height:a},{backstoreOnly:!0}),this.renderAll();var m=this.__toDataURL(e,t,n);return this.interactive=v,this.skipOffscreen=p,this.viewportTransform=l,g&&this.setDimensions({width:i,height:o},{backstoreOnly:!0}),this.renderAll(),m},__toDataURL:function(t,n){var r=this.contextContainer.canvas;"jpg"===t&&(t="jpeg");var i=e?r.toDataURL("image/"+t,n):r.toDataURL("image/"+t);return i}})}();fabric.util.object.extend(fabric.StaticCanvas.prototype,{loadFromDatalessJSON:function(e,t,n){return this.loadFromJSON(e,t,n)},loadFromJSON:function(e,t,n){if(e){var r="string"==typeof e?JSON.parse(e):fabric.util.object.clone(e),i=this,o=this.renderOnAddRemove;return this.renderOnAddRemove=!1,this._enlivenObjects(r.objects,function(e){i.clear(),i._setBgOverlay(r,function(){e.forEach(function(e,t){i.insertAt(e,t)}),i.renderOnAddRemove=o,delete r.objects,delete r.backgroundImage,delete r.overlayImage,delete r.background,delete r.overlay,i._setOptions(r),i.renderAll(),t&&t()})},n),this}},_setBgOverlay:function(e,t){var n={backgroundColor:!1,overlayColor:!1,backgroundImage:!1,overlayImage:!1};if(!(e.backgroundImage||e.overlayImage||e.background||e.overlay))return void(t&&t());var r=function(){n.backgroundImage&&n.overlayImage&&n.backgroundColor&&n.overlayColor&&t&&t()};this.__setBgOverlay("backgroundImage",e.backgroundImage,n,r),this.__setBgOverlay("overlayImage",e.overlayImage,n,r),this.__setBgOverlay("backgroundColor",e.background,n,r),this.__setBgOverlay("overlayColor",e.overlay,n,r)},__setBgOverlay:function(e,t,n,r){var i=this;return t?void("backgroundImage"===e||"overlayImage"===e?fabric.util.enlivenObjects([t],function(t){i[e]=t[0],n[e]=!0,r&&r()}):this["set"+fabric.util.string.capitalize(e,!0)](t,function(){n[e]=!0,r&&r()})):(n[e]=!0,void(r&&r()))},_enlivenObjects:function(e,t,n){return e&&0!==e.length?void fabric.util.enlivenObjects(e,function(e){t&&t(e)},null,n):void(t&&t([]))},_toDataURL:function(e,t){this.clone(function(n){t(n.toDataURL(e))})},_toDataURLWithMultiplier:function(e,t,n){this.clone(function(r){n(r.toDataURLWithMultiplier(e,t))})},clone:function(e,t){var n=JSON.stringify(this.toJSON(t));this.cloneWithoutData(function(t){t.loadFromJSON(n,function(){e&&e(t)})})},cloneWithoutData:function(e){var t=fabric.document.createElement("canvas");t.width=this.width,t.height=this.height;var n=new fabric.Canvas(t);n.clipTo=this.clipTo,this.backgroundImage?(n.setBackgroundImage(this.backgroundImage.src,function(){n.renderAll(),e&&e(n)}),n.backgroundImageOpacity=this.backgroundImageOpacity,n.backgroundImageStretch=this.backgroundImageStretch):e&&e(n)}});!function(){var e=fabric.util.degreesToRadians,t=fabric.util.radiansToDegrees;fabric.util.object.extend(fabric.Canvas.prototype,{__onTransformGesture:function(e,t){if(!this.isDrawingMode&&e.touches&&2===e.touches.length&&"gesture"===t.gesture){var n=this.findTarget(e);"undefined"!=typeof n&&(this.__gesturesParams={e:e,self:t,target:n},this.__gesturesRenderer()),this.fire("touch:gesture",{target:n,e:e,self:t})}},__gesturesParams:null,__gesturesRenderer:function(){if(null!==this.__gesturesParams&&null!==this._currentTransform){var e=this.__gesturesParams.self,t=this._currentTransform,n=this.__gesturesParams.e;t.action="scale",t.originX=t.originY="center",this._scaleObjectBy(e.scale,n),0!==e.rotation&&(t.action="rotate",this._rotateObjectByAngle(e.rotation,n)),this.requestRenderAll(),t.action="drag"}},__onDrag:function(e,t){this.fire("touch:drag",{e:e,self:t})},__onOrientationChange:function(e,t){this.fire("touch:orientation",{e:e,self:t})},__onShake:function(e,t){this.fire("touch:shake",{e:e,self:t})},__onLongPress:function(e,t){this.fire("touch:longpress",{e:e,self:t})},_scaleObjectBy:function(e,t){var n=this._currentTransform,r=n.target,i=r.get("lockScalingX"),o=r.get("lockScalingY");if(!i||!o){r._scaling=!0;var s=r.translateToOriginPoint(r.getCenterPoint(),n.originX,n.originY),a=r._getTransformedDimensions();this._setObjectScale(new fabric.Point(n.scaleX*a.x*e/r.scaleX,n.scaleY*a.y*e/r.scaleY),n,i,o,null,r.get("lockScalingFlip"),a),r.setPositionByOrigin(s,n.originX,n.originY),this._fire("scaling",r,t)}},_rotateObjectByAngle:function(n,r){var i=this._currentTransform;i.target.get("lockRotation")||(i.target.rotate(t(e(n)+i.theta)),this._fire("rotating",i.target,r))}})}();!function(e){"use strict";var t=e.fabric||(e.fabric={}),n=t.util.object.extend,r=t.util.object.clone,i=t.util.toFixed,o=t.util.string.capitalize,s=t.util.degreesToRadians,a=t.StaticCanvas.supports("setLineDash"),c=!t.isLikelyNode,l=2;t.Object||(t.Object=t.util.createClass(t.CommonMethods,{type:"object",originX:"left",originY:"top",top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,skewX:0,skewY:0,cornerSize:13,transparentCorners:!0,hoverCursor:null,moveCursor:null,padding:0,borderColor:"rgba(102,153,255,0.75)",borderDashArray:null,cornerColor:"rgba(102,153,255,0.5)",cornerStrokeColor:null,cornerStyle:"rect",cornerDashArray:null,centeredScaling:!1,centeredRotation:!0,fill:"rgb(0,0,0)",fillRule:"nonzero",globalCompositeOperation:"source-over",backgroundColor:"",selectionBackgroundColor:"",stroke:null,strokeWidth:1,strokeDashArray:null,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,transformMatrix:null,minScaleLimit:0,selectable:!0,evented:!0,visible:!0,hasControls:!0,hasBorders:!0,hasRotatingPoint:!0,rotatingPointOffset:40,perPixelTargetFind:!1,includeDefaultValues:!0,clipTo:null,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockUniScaling:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,excludeFromExport:!1,objectCaching:c,statefullCache:!1,noScaleCache:!0,dirty:!0,__corner:0,paintFirst:"fill",stateProperties:"top left width height scaleX scaleY flipX flipY originX originY transformMatrix stroke strokeWidth strokeDashArray strokeLineCap strokeLineJoin strokeMiterLimit angle opacity fill globalCompositeOperation shadow clipTo visible backgroundColor skewX skewY fillRule paintFirst".split(" "),cacheProperties:"fill stroke strokeWidth strokeDashArray width height paintFirst strokeLineCap strokeLineJoin strokeMiterLimit backgroundColor".split(" "),clipPath:void 0,initialize:function(e){e&&this.setOptions(e)},_createCacheCanvas:function(e){this._cacheProperties={},this._cacheCanvas=t.document.createElement("canvas"),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(e),this.dirty=!0},_limitCacheSize:function(e){var n=t.perfLimitSizeTotal,r=e.width,i=e.height,o=t.maxCacheSideLimit,s=t.minCacheSideLimit;if(o>=r&&o>=i&&n>=r*i)return s>r&&(e.width=s),s>i&&(e.height=s),e;var a=r/i,c=t.util.limitDimsByArea(a,n),l=t.util.capValue,u=l(s,c.x,o),h=l(s,c.y,o);return r>u&&(e.zoomX/=r/u,e.width=u,e.capped=!0),i>h&&(e.zoomY/=i/h,e.height=h,e.capped=!0),e},_getCacheCanvasDimensions:function(e){var n,r,i=this.canvas||e&&e.canvas,o=i&&i.getZoom()||1,s=this.getObjectScaling(),a=i&&i._isRetinaScaling()?t.devicePixelRatio:1,c=this._getNonTransformedDimensions(),u=s.scaleX*o*a,h=s.scaleY*o*a;return n=c.x*u,r=c.y*h,{width:n+l,height:r+l,zoomX:u,zoomY:h,x:c.x,y:c.y}},_updateCacheCanvas:function(e){var n=this.canvas||e&&e.canvas;if(this.noScaleCache&&n&&n._currentTransform){var r=n._currentTransform.target,i=n._currentTransform.action;if(this===r&&i.slice&&"scale"===i.slice(0,5))return!1}var o,s,a=this._cacheCanvas,c=this._limitCacheSize(this._getCacheCanvasDimensions(e)),l=t.minCacheSideLimit,u=c.width,h=c.height,f=c.zoomX,d=c.zoomY,p=u!==this.cacheWidth||h!==this.cacheHeight,v=this.zoomX!==f||this.zoomY!==d,g=p||v,m=0,b=0,y=!1;if(p){var _=this._cacheCanvas.width,w=this._cacheCanvas.height,C=u>_||h>w,x=(.9*_>u||.9*w>h)&&_>l&&w>l;y=C||x,C&&!c.capped&&(u>l||h>l)&&(m=.1*u,b=.1*h)}return g?(y?(a.width=Math.ceil(u+m),a.height=Math.ceil(h+b)):(this._cacheContext.setTransform(1,0,0,1,0,0),this._cacheContext.clearRect(0,0,a.width,a.height)),o=c.x*f/2,s=c.y*d/2,this.cacheTranslationX=Math.round(a.width/2-o)+o,this.cacheTranslationY=Math.round(a.height/2-s)+s,this.cacheWidth=u,this.cacheHeight=h,this._cacheContext.translate(this.cacheTranslationX,this.cacheTranslationY),this._cacheContext.scale(f,d),this.zoomX=f,this.zoomY=d,!0):!1},setOptions:function(e){this._setOptions(e),this._initGradient(e.fill,"fill"),this._initGradient(e.stroke,"stroke"),this._initClipping(e),this._initPattern(e.fill,"fill"),this._initPattern(e.stroke,"stroke")},transform:function(e){var t;t=this.group&&!this.group._transformDone?this.calcTransformMatrix():this.calcOwnMatrix(),e.transform(t[0],t[1],t[2],t[3],t[4],t[5])},toObject:function(e){var n=t.Object.NUM_FRACTION_DIGITS,r={type:this.type,version:t.version,originX:this.originX,originY:this.originY,left:i(this.left,n),top:i(this.top,n),width:i(this.width,n),height:i(this.height,n),fill:this.fill&&this.fill.toObject?this.fill.toObject():this.fill,stroke:this.stroke&&this.stroke.toObject?this.stroke.toObject():this.stroke,strokeWidth:i(this.strokeWidth,n),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeLineJoin:this.strokeLineJoin,strokeMiterLimit:i(this.strokeMiterLimit,n),scaleX:i(this.scaleX,n),scaleY:i(this.scaleY,n),angle:i(this.angle,n),flipX:this.flipX,flipY:this.flipY,opacity:i(this.opacity,n),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,clipTo:this.clipTo&&String(this.clipTo),backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,transformMatrix:this.transformMatrix?this.transformMatrix.concat():null,skewX:i(this.skewX,n),skewY:i(this.skewY,n)};return this.clipPath&&(r.clipPath=this.clipPath.toObject()),t.util.populateWithProperties(this,r,e),this.includeDefaultValues||(r=this._removeDefaultValues(r)),r},toDatalessObject:function(e){return this.toObject(e)},_removeDefaultValues:function(e){var n=t.util.getKlass(e.type).prototype,r=n.stateProperties;return r.forEach(function(t){e[t]===n[t]&&delete e[t];var r="[object Array]"===Object.prototype.toString.call(e[t])&&"[object Array]"===Object.prototype.toString.call(n[t]);r&&0===e[t].length&&0===n[t].length&&delete e[t]}),e},toString:function(){return"#<fabric."+o(this.type)+">"},getObjectScaling:function(){var e=this.scaleX,t=this.scaleY;if(this.group){var n=this.group.getObjectScaling();e*=n.scaleX,t*=n.scaleY}return{scaleX:e,scaleY:t}},getObjectOpacity:function(){var e=this.opacity;return this.group&&(e*=this.group.getObjectOpacity()),e},_set:function(e,n){var r="scaleX"===e||"scaleY"===e,i=this[e]!==n,o=!1;return r&&(n=this._constrainScale(n)),"scaleX"===e&&0>n?(this.flipX=!this.flipX,n*=-1):"scaleY"===e&&0>n?(this.flipY=!this.flipY,n*=-1):"shadow"!==e||!n||n instanceof t.Shadow?"dirty"===e&&this.group&&this.group.set("dirty",n):n=new t.Shadow(n),this[e]=n,i&&(o=this.group&&this.group.isOnACache(),this.cacheProperties.indexOf(e)>-1?(this.dirty=!0,o&&this.group.set("dirty",!0)):o&&this.stateProperties.indexOf(e)>-1&&this.group.set("dirty",!0)),this},setOnGroup:function(){},getViewportTransform:function(){return this.canvas&&this.canvas.viewportTransform?this.canvas.viewportTransform:t.iMatrix.concat()},isNotVisible:function(){return 0===this.opacity||0===this.width&&0===this.height||!this.visible},render:function(e){this.isNotVisible()||(!this.canvas||!this.canvas.skipOffscreen||this.group||this.isOnScreen())&&(e.save(),this._setupCompositeOperation(e),this.drawSelectionBackground(e),this.transform(e),this._setOpacity(e),this._setShadow(e,this),this.transformMatrix&&e.transform.apply(e,this.transformMatrix),this.clipTo&&t.util.clipContext(this,e),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(e)):(this._removeCacheCanvas(),this.dirty=!1,this.drawObject(e),this.objectCaching&&this.statefullCache&&this.saveState({propertySet:"cacheProperties"})),this.clipTo&&e.restore(),e.restore())},renderCache:function(e,t){this._cacheCanvas||this._createCacheCanvas(e),this.isCacheDirty(!1,e)&&(this.statefullCache&&this.saveState({propertySet:"cacheProperties"}),this.drawObject(this._cacheContext,t),this.dirty=!1)},_removeCacheCanvas:function(){this._cacheCanvas=null,this.cacheWidth=0,this.cacheHeight=0},needsItsOwnCache:function(){return"stroke"===this.paintFirst&&"object"==typeof this.shadow?!0:this.clipPath?!0:!1},shouldCache:function(){return this.ownCaching=this.objectCaching&&(!this.group||this.needsItsOwnCache()||!this.group.isOnACache()),this.ownCaching},willDrawShadow:function(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)},drawClipPathOnCache:function(e){var t=this.clipPath;e.save(),e.globalCompositeOperation="destination-in",t.transform(e),e.scale(1/t.zoomX,1/t.zoomY),e.drawImage(t._cacheCanvas,-t.cacheTranslationX,-t.cacheTranslationY),e.restore()},drawObject:function(e,t){var n=this.clipPath;t?this._setClippingProperties(e):(this._renderBackground(e),this._setStrokeStyles(e,this),this._setFillStyles(e,this)),this._render(e),n&&(n.shouldCache(),n._transformDone=!0,n.renderCache(this,!0),this.drawClipPathOnCache(e))},drawCacheOnCanvas:function(e){e.scale(1/this.zoomX,1/this.zoomY),e.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)},isCacheDirty:function(e,t){if(this.isNotVisible())return!1;if(this._cacheCanvas&&!e&&this._updateCacheCanvas(t))return!0;if(this.dirty||this.statefullCache&&this.hasStateChanged("cacheProperties")){if(this._cacheCanvas&&!e){var n=this.cacheWidth/this.zoomX,r=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-n/2,-r/2,n,r)}return!0}return!1},_renderBackground:function(e){if(this.backgroundColor){var t=this._getNonTransformedDimensions();e.fillStyle=this.backgroundColor,e.fillRect(-t.x/2,-t.y/2,t.x,t.y),this._removeShadow(e)}},_setOpacity:function(e){this.group&&!this.group._transformDone?e.globalAlpha=this.getObjectOpacity():e.globalAlpha*=this.opacity},_setStrokeStyles:function(e,t){t.stroke&&(e.lineWidth=t.strokeWidth,e.lineCap=t.strokeLineCap,e.lineJoin=t.strokeLineJoin,e.miterLimit=t.strokeMiterLimit,e.strokeStyle=t.stroke.toLive?t.stroke.toLive(e,this):t.stroke)},_setFillStyles:function(e,t){t.fill&&(e.fillStyle=t.fill.toLive?t.fill.toLive(e,this):t.fill)},_setClippingProperties:function(e){e.globalAlpha=1,e.lineWidth=0,e.fillStyle="black"},_setLineDash:function(e,t,n){t&&(1&t.length&&t.push.apply(t,t),a?e.setLineDash(t):n&&n(e))},_renderControls:function(e,n){var r,i,o,a=this.getViewportTransform(),c=this.calcTransformMatrix();n=n||{},i="undefined"!=typeof n.hasBorders?n.hasBorders:this.hasBorders,o="undefined"!=typeof n.hasControls?n.hasControls:this.hasControls,c=t.util.multiplyTransformMatrices(a,c),r=t.util.qrDecompose(c),e.save(),e.translate(r.translateX,r.translateY),e.lineWidth=1*this.borderScaleFactor,this.group||(e.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),n.forActiveSelection?(e.rotate(s(r.angle)),i&&this.drawBordersInGroup(e,r,n)):(e.rotate(s(this.angle)),i&&this.drawBorders(e,n)),o&&this.drawControls(e,n),e.restore()},_setShadow:function(e){if(this.shadow){var n=this.canvas&&this.canvas.viewportTransform[0]||1,r=this.canvas&&this.canvas.viewportTransform[3]||1,i=this.getObjectScaling();this.canvas&&this.canvas._isRetinaScaling()&&(n*=t.devicePixelRatio,r*=t.devicePixelRatio),e.shadowColor=this.shadow.color,e.shadowBlur=this.shadow.blur*t.browserShadowBlurConstant*(n+r)*(i.scaleX+i.scaleY)/4,e.shadowOffsetX=this.shadow.offsetX*n*i.scaleX,e.shadowOffsetY=this.shadow.offsetY*r*i.scaleY}},_removeShadow:function(e){this.shadow&&(e.shadowColor="",e.shadowBlur=e.shadowOffsetX=e.shadowOffsetY=0)},_applyPatternGradientTransform:function(e,t){if(!t||!t.toLive)return{offsetX:0,offsetY:0};var n=t.gradientTransform||t.patternTransform,r=-this.width/2+t.offsetX||0,i=-this.height/2+t.offsetY||0;return e.translate(r,i),n&&e.transform(n[0],n[1],n[2],n[3],n[4],n[5]),{offsetX:r,offsetY:i}},_renderPaintInOrder:function(e){"stroke"===this.paintFirst?(this._renderStroke(e),this._renderFill(e)):(this._renderFill(e),this._renderStroke(e))},_renderFill:function(e){this.fill&&(e.save(),this._applyPatternGradientTransform(e,this.fill),"evenodd"===this.fillRule?e.fill("evenodd"):e.fill(),e.restore())},_renderStroke:function(e){this.stroke&&0!==this.strokeWidth&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(e),e.save(),this._setLineDash(e,this.strokeDashArray,this._renderDashedStroke),this._applyPatternGradientTransform(e,this.stroke),e.stroke(),e.restore())},_findCenterFromElement:function(){return{x:this.left+this.width/2,y:this.top+this.height/2}},_assignTransformMatrixProps:function(){if(this.transformMatrix){var e=t.util.qrDecompose(this.transformMatrix);this.flipX=!1,this.flipY=!1,this.set("scaleX",e.scaleX),this.set("scaleY",e.scaleY),this.angle=e.angle,this.skewX=e.skewX,this.skewY=0}},_removeTransformMatrix:function(e){var n=this._findCenterFromElement();this.transformMatrix&&(this._assignTransformMatrixProps(),n=t.util.transformPoint(n,this.transformMatrix)),this.transformMatrix=null,e&&(this.scaleX*=e.scaleX,this.scaleY*=e.scaleY,this.cropX=e.cropX,this.cropY=e.cropY,n.x+=e.offsetLeft,n.y+=e.offsetTop,this.width=e.width,this.height=e.height),this.setPositionByOrigin(n,"center","center")},clone:function(e,n){var r=this.toObject(n);this.constructor.fromObject?this.constructor.fromObject(r,e):t.Object._fromObject("Object",r,e)},cloneAsImage:function(e,n){var r=this.toDataURL(n);return t.util.loadImage(r,function(n){e&&e(new t.Image(n))}),this},toDataURL:function(e){e||(e={});var n=t.util.createCanvasElement(),r=this.getBoundingRect();n.width=r.width,n.height=r.height,t.util.wrapElement(n,"div");var i=new t.StaticCanvas(n,{enableRetinaScaling:e.enableRetinaScaling,renderOnAddRemove:!1,skipOffscreen:!1});"jpg"===e.format&&(e.format="jpeg"),"jpeg"===e.format&&(i.backgroundColor="#fff");var o={left:this.left,top:this.top};this.setPositionByOrigin(new t.Point(i.width/2,i.height/2),"center","center");var s=this.canvas;i.add(this);var a=i.toDataURL(e);return this.set(o).setCoords(),this.canvas=s,i._objects=[],i.dispose(),i=null,a},isType:function(e){return this.type===e},complexity:function(){return 1},toJSON:function(e){return this.toObject(e)},setGradient:function(e,n){n||(n={});var r={colorStops:[]};return r.type=n.type||(n.r1||n.r2?"radial":"linear"),r.coords={x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2},(n.r1||n.r2)&&(r.coords.r1=n.r1,r.coords.r2=n.r2),r.gradientTransform=n.gradientTransform,t.Gradient.prototype.addColorStop.call(r,n.colorStops),this.set(e,t.Gradient.forObject(this,r))},setPatternFill:function(e){return this.set("fill",new t.Pattern(e))},setShadow:function(e){return this.set("shadow",e?new t.Shadow(e):null)},setColor:function(e){return this.set("fill",e),this},rotate:function(e){var t=("center"!==this.originX||"center"!==this.originY)&&this.centeredRotation;return t&&this._setOriginToCenter(),this.set("angle",e),t&&this._resetOrigin(),this},centerH:function(){return this.canvas&&this.canvas.centerObjectH(this),this},viewportCenterH:function(){return this.canvas&&this.canvas.viewportCenterObjectH(this),this},centerV:function(){return this.canvas&&this.canvas.centerObjectV(this),this},viewportCenterV:function(){return this.canvas&&this.canvas.viewportCenterObjectV(this),this},center:function(){return this.canvas&&this.canvas.centerObject(this),this},viewportCenter:function(){return this.canvas&&this.canvas.viewportCenterObject(this),this},getLocalPointer:function(e,n){n=n||this.canvas.getPointer(e);var r=new t.Point(n.x,n.y),i=this._getLeftTopCoords();return this.angle&&(r=t.util.rotatePoint(r,i,s(-this.angle))),{x:r.x-i.x,y:r.y-i.y}},_setupCompositeOperation:function(e){this.globalCompositeOperation&&(e.globalCompositeOperation=this.globalCompositeOperation)}}),t.util.createAccessors&&t.util.createAccessors(t.Object),n(t.Object.prototype,t.Observable),t.Object.NUM_FRACTION_DIGITS=2,t.Object._fromObject=function(e,n,i,o){var s=t[e];n=r(n,!0),t.util.enlivenPatterns([n.fill,n.stroke],function(e){"undefined"!=typeof e[0]&&(n.fill=e[0]),"undefined"!=typeof e[1]&&(n.stroke=e[1]),t.util.enlivenObjects([n.clipPath],function(e){n.clipPath=e[0];var t=o?new s(n[o],n):new s(n);i&&i(t)})})},t.Object.__uid=0)}("undefined"!=typeof exports?exports:this);!function(){var t=fabric.util.degreesToRadians,e={left:-.5,center:0,right:.5},i={top:-.5,center:0,bottom:.5};fabric.util.object.extend(fabric.Object.prototype,{translateToGivenOrigin:function(t,n,r,o,s){var a,c,l,u=t.x,h=t.y;return"string"==typeof n?n=e[n]:n-=.5,"string"==typeof o?o=e[o]:o-=.5,a=o-n,"string"==typeof r?r=i[r]:r-=.5,"string"==typeof s?s=i[s]:s-=.5,c=s-r,(a||c)&&(l=this._getTransformedDimensions(),u=t.x+a*l.x,h=t.y+c*l.y),new fabric.Point(u,h)},translateToCenterPoint:function(e,i,n){var r=this.translateToGivenOrigin(e,i,n,"center","center");return this.angle?fabric.util.rotatePoint(r,e,t(this.angle)):r},translateToOriginPoint:function(e,i,n){var r=this.translateToGivenOrigin(e,"center","center",i,n);return this.angle?fabric.util.rotatePoint(r,e,t(this.angle)):r},getCenterPoint:function(){var t=new fabric.Point(this.left,this.top);return this.translateToCenterPoint(t,this.originX,this.originY)},getPointByOrigin:function(t,e){var i=this.getCenterPoint();return this.translateToOriginPoint(i,t,e)},toLocalPoint:function(e,i,n){var r,o,s=this.getCenterPoint();return r="undefined"!=typeof i&&"undefined"!=typeof n?this.translateToGivenOrigin(s,"center","center",i,n):new fabric.Point(this.left,this.top),o=new fabric.Point(e.x,e.y),this.angle&&(o=fabric.util.rotatePoint(o,s,-t(this.angle))),o.subtractEquals(r)},setPositionByOrigin:function(t,e,i){var n=this.translateToCenterPoint(t,e,i),r=this.translateToOriginPoint(n,this.originX,this.originY);this.set("left",r.x),this.set("top",r.y)},adjustPosition:function(i){var n,r,o=t(this.angle),s=this.getScaledWidth(),a=fabric.util.cos(o)*s,c=fabric.util.sin(o)*s;n="string"==typeof this.originX?e[this.originX]:this.originX-.5,r="string"==typeof i?e[i]:i-.5,this.left+=a*(r-n),this.top+=c*(r-n),this.setCoords(),this.originX=i},_setOriginToCenter:function(){this._originalOriginX=this.originX,this._originalOriginY=this.originY;var t=this.getCenterPoint();this.originX="center",this.originY="center",this.left=t.x,this.top=t.y},_resetOrigin:function(){var t=this.translateToOriginPoint(this.getCenterPoint(),this._originalOriginX,this._originalOriginY);this.originX=this._originalOriginX,this.originY=this._originalOriginY,this.left=t.x,this.top=t.y,this._originalOriginX=null,this._originalOriginY=null},_getLeftTopCoords:function(){return this.translateToOriginPoint(this.getCenterPoint(),"left","top")}})}();!function(){function t(t){return[new fabric.Point(t.tl.x,t.tl.y),new fabric.Point(t.tr.x,t.tr.y),new fabric.Point(t.br.x,t.br.y),new fabric.Point(t.bl.x,t.bl.y)]}var e=fabric.util.degreesToRadians,i=fabric.util.multiplyTransformMatrices,n=fabric.util.transformPoint;fabric.util.object.extend(fabric.Object.prototype,{oCoords:null,aCoords:null,ownMatrixCache:null,matrixCache:null,getCoords:function(e,i){this.oCoords||this.setCoords();var n=e?this.aCoords:this.oCoords;return t(i?this.calcCoords(e):n)},intersectsWithRect:function(t,e,i,n){var r=this.getCoords(i,n),o=fabric.Intersection.intersectPolygonRectangle(r,t,e);return"Intersection"===o.status},intersectsWithObject:function(t,e,i){var n=fabric.Intersection.intersectPolygonPolygon(this.getCoords(e,i),t.getCoords(e,i));return"Intersection"===n.status||t.isContainedWithinObject(this,e,i)||this.isContainedWithinObject(t,e,i)},isContainedWithinObject:function(t,e,i){for(var n=this.getCoords(e,i),r=0,o=t._getImageLines(i?t.calcCoords(e):e?t.aCoords:t.oCoords);4>r;r++)if(!t.containsPoint(n[r],o))return!1;return!0},isContainedWithinRect:function(t,e,i,n){var r=this.getBoundingRect(i,n);return r.left>=t.x&&r.left+r.width<=e.x&&r.top>=t.y&&r.top+r.height<=e.y},containsPoint:function(t,e,i,n){var e=e||this._getImageLines(n?this.calcCoords(i):i?this.aCoords:this.oCoords),r=this._findCrossPoints(t,e);return 0!==r&&r%2===1},isOnScreen:function(t){if(!this.canvas)return!1;for(var e,i=this.canvas.vptCoords.tl,n=this.canvas.vptCoords.br,r=this.getCoords(!0,t),o=0;4>o;o++)if(e=r[o],e.x<=n.x&&e.x>=i.x&&e.y<=n.y&&e.y>=i.y)return!0;return this.intersectsWithRect(i,n,!0,t)?!0:this._containsCenterOfCanvas(i,n,t)},_containsCenterOfCanvas:function(t,e,i){var n={x:(t.x+e.x)/2,y:(t.y+e.y)/2};return this.containsPoint(n,null,!0,i)?!0:!1},isPartiallyOnScreen:function(t){if(!this.canvas)return!1;var e=this.canvas.vptCoords.tl,i=this.canvas.vptCoords.br;return this.intersectsWithRect(e,i,!0,t)?!0:this._containsCenterOfCanvas(e,i,t)},_getImageLines:function(t){return{topline:{o:t.tl,d:t.tr},rightline:{o:t.tr,d:t.br},bottomline:{o:t.br,d:t.bl},leftline:{o:t.bl,d:t.tl}}},_findCrossPoints:function(t,e){var i,n,r,o,s,a,c=0;for(var l in e)if(a=e[l],!(a.o.y<t.y&&a.d.y<t.y||a.o.y>=t.y&&a.d.y>=t.y||(a.o.x===a.d.x&&a.o.x>=t.x?s=a.o.x:(i=0,n=(a.d.y-a.o.y)/(a.d.x-a.o.x),r=t.y-i*t.x,o=a.o.y-n*a.o.x,s=-(r-o)/(i-n)),s>=t.x&&(c+=1),2!==c)))break;return c},getBoundingRect:function(t,e){var i=this.getCoords(t,e);return fabric.util.makeBoundingBoxFromPoints(i)},getScaledWidth:function(){return this._getTransformedDimensions().x},getScaledHeight:function(){return this._getTransformedDimensions().y},_constrainScale:function(t){return Math.abs(t)<this.minScaleLimit?0>t?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t},scale:function(t){return this._set("scaleX",t),this._set("scaleY",t),this.setCoords()},scaleToWidth:function(t,e){var i=this.getBoundingRect(e).width/this.getScaledWidth();return this.scale(t/this.width/i)},scaleToHeight:function(t,e){var i=this.getBoundingRect(e).height/this.getScaledHeight();return this.scale(t/this.height/i)},calcCoords:function(t){var r=this._calcRotateMatrix(),o=this._calcTranslateMatrix(),s=i(o,r),a=this.getViewportTransform(),c=t?s:i(a,s),l=this._getTransformedDimensions(),u=l.x/2,h=l.y/2,f=n({x:-u,y:-h},c),d=n({x:u,y:-h},c),v=n({x:-u,y:h},c),g=n({x:u,y:h},c);if(!t){var p=this.padding,m=e(this.angle),b=fabric.util.cos(m),y=fabric.util.sin(m),_=b*p,w=y*p,x=_+w,C=_-w;p&&(f.x-=C,f.y-=x,d.x+=x,d.y-=C,v.x-=x,v.y+=C,g.x+=C,g.y+=x);var O=new fabric.Point((f.x+v.x)/2,(f.y+v.y)/2),j=new fabric.Point((d.x+f.x)/2,(d.y+f.y)/2),S=new fabric.Point((g.x+d.x)/2,(g.y+d.y)/2),P=new fabric.Point((g.x+v.x)/2,(g.y+v.y)/2),T=new fabric.Point(j.x+y*this.rotatingPointOffset,j.y-b*this.rotatingPointOffset)}var k={tl:f,tr:d,br:g,bl:v};return t||(k.ml=O,k.mt=j,k.mr=S,k.mb=P,k.mtr=T),k},setCoords:function(t,e){return this.oCoords=this.calcCoords(t),e||(this.aCoords=this.calcCoords(!0)),t||this._setCornerCoords&&this._setCornerCoords(),this},_calcRotateMatrix:function(){if(this.angle){var t=e(this.angle),i=fabric.util.cos(t),n=fabric.util.sin(t);return[i,n,-n,i,0,0]}return fabric.iMatrix.concat()},_calcTranslateMatrix:function(){var t=this.getCenterPoint();return[1,0,0,1,t.x,t.y]},transformMatrixKey:function(t){var e="_",i="";return!t&&this.group&&(i=this.group.transformMatrixKey(t)+e),i+this.top+e+this.left+e+this.scaleX+e+this.scaleY+e+this.skewX+e+this.skewY+e+this.angle+e+this.originX+e+this.originY+e+this.width+e+this.height+e+this.strokeWidth+this.flipX+this.flipY},calcTransformMatrix:function(t){if(t)return this.calcOwnMatrix();var e=this.transformMatrixKey(),n=this.matrixCache||(this.matrixCache={});if(n.key===e)return n.value;var r=this.calcOwnMatrix();return this.group&&(r=i(this.group.calcTransformMatrix(),r)),n.key=e,n.value=r,r},calcOwnMatrix:function(){var t=this.transformMatrixKey(!0),e=this.ownMatrixCache||(this.ownMatrixCache={});if(e.key===t)return e.value;var n,r=this._calcTranslateMatrix(),o=this._calcDimensionsTransformMatrix(this.skewX,this.skewY,!0);return this.angle&&(n=this._calcRotateMatrix(),r=i(r,n)),r=i(r,o),e.key=t,e.value=r,r},_calcDimensionsTransformMatrix:function(t,n,r){var o,s=this.scaleX*(r&&this.flipX?-1:1),a=this.scaleY*(r&&this.flipY?-1:1),c=[s,0,0,a,0,0];return t&&(o=[1,0,Math.tan(e(t)),1],c=i(c,o,!0)),n&&(o=[1,Math.tan(e(n)),0,1],c=i(c,o,!0)),c},_getNonTransformedDimensions:function(){var t=this.strokeWidth,e=this.width+t,i=this.height+t;return{x:e,y:i}},_getTransformedDimensions:function(t,e){"undefined"==typeof t&&(t=this.skewX),"undefined"==typeof e&&(e=this.skewY);var i=this._getNonTransformedDimensions();if(0===t&&0===e)return{x:i.x*this.scaleX,y:i.y*this.scaleY};var n,r,o=i.x/2,s=i.y/2,a=[{x:-o,y:-s},{x:o,y:-s},{x:-o,y:s},{x:o,y:s}],c=this._calcDimensionsTransformMatrix(t,e,!1);for(n=0;n<a.length;n++)a[n]=fabric.util.transformPoint(a[n],c);return r=fabric.util.makeBoundingBoxFromPoints(a),{x:r.width,y:r.height}},_calculateCurrentDimensions:function(){var t=this.getViewportTransform(),e=this._getTransformedDimensions(),i=fabric.util.transformPoint(e,t,!0);return i.scalarAdd(2*this.padding)}})}();fabric.util.object.extend(fabric.Object.prototype,{sendToBack:function(){return this.group?fabric.StaticCanvas.prototype.sendToBack.call(this.group,this):this.canvas.sendToBack(this),this},bringToFront:function(){return this.group?fabric.StaticCanvas.prototype.bringToFront.call(this.group,this):this.canvas.bringToFront(this),this},sendBackwards:function(t){return this.group?fabric.StaticCanvas.prototype.sendBackwards.call(this.group,this,t):this.canvas.sendBackwards(this,t),this},bringForward:function(t){return this.group?fabric.StaticCanvas.prototype.bringForward.call(this.group,this,t):this.canvas.bringForward(this,t),this},moveTo:function(t){return this.group&&"activeSelection"!==this.group.type?fabric.StaticCanvas.prototype.moveTo.call(this.group,this,t):this.canvas.moveTo(this,t),this}});!function(){function t(t,e,n){var r={},o=!0;n.forEach(function(e){r[e]=t[e]}),i(t[e],r,o)}function e(t,i,n){if(t===i)return!0;if(Array.isArray(t)){if(!Array.isArray(i)||t.length!==i.length)return!1;for(var r=0,o=t.length;o>r;r++)if(!e(t[r],i[r]))return!1;return!0}if(t&&"object"==typeof t){var s,a=Object.keys(t);if(!i||"object"!=typeof i||!n&&a.length!==Object.keys(i).length)return!1;for(var r=0,o=a.length;o>r;r++)if(s=a[r],!e(t[s],i[s]))return!1;return!0}}var i=fabric.util.object.extend,n="stateProperties";fabric.util.object.extend(fabric.Object.prototype,{hasStateChanged:function(t){t=t||n;var i="_"+t;return Object.keys(this[i]).length<this[t].length?!0:!e(this[i],this,!0)},saveState:function(e){var i=e&&e.propertySet||n,r="_"+i;return this[r]?(t(this,r,this[i]),e&&e.stateProperties&&t(this,r,e.stateProperties),this):this.setupState(e)},setupState:function(t){t=t||{};var e=t.propertySet||n;return t.propertySet=e,this["_"+e]={},this.saveState(t),this}})}();!function(){var t=fabric.util.degreesToRadians;fabric.util.object.extend(fabric.Object.prototype,{_controlsVisibility:null,_findTargetCorner:function(t){if(!this.hasControls||this.group||!this.canvas||this.canvas._activeObject!==this)return!1;var e,i,r=t.x,n=t.y;this.__corner=0;for(var o in this.oCoords)if(this.isControlVisible(o)&&("mtr"!==o||this.hasRotatingPoint)&&(!this.get("lockUniScaling")||"mt"!==o&&"mr"!==o&&"mb"!==o&&"ml"!==o)&&(i=this._getImageLines(this.oCoords[o].corner),e=this._findCrossPoints({x:r,y:n},i),0!==e&&e%2===1))return this.__corner=o,o;return!1},_setCornerCoords:function(){var e,i,r=this.oCoords,n=t(45-this.angle),o=.707106*this.cornerSize,s=o*fabric.util.cos(n),a=o*fabric.util.sin(n);for(var c in r)e=r[c].x,i=r[c].y,r[c].corner={tl:{x:e-a,y:i-s},tr:{x:e+s,y:i-a},bl:{x:e-s,y:i+a},br:{x:e+a,y:i+s}}},drawSelectionBackground:function(e){if(!this.selectionBackgroundColor||this.canvas&&!this.canvas.interactive||this.canvas&&this.canvas._activeObject!==this)return this;e.save();var i=this.getCenterPoint(),r=this._calculateCurrentDimensions(),n=this.canvas.viewportTransform;return e.translate(i.x,i.y),e.scale(1/n[0],1/n[3]),e.rotate(t(this.angle)),e.fillStyle=this.selectionBackgroundColor,e.fillRect(-r.x/2,-r.y/2,r.x,r.y),e.restore(),this},drawBorders:function(t,e){e=e||{};var i=this._calculateCurrentDimensions(),r=1/this.borderScaleFactor,n=i.x+r,o=i.y+r,s="undefined"!=typeof e.hasRotatingPoint?e.hasRotatingPoint:this.hasRotatingPoint,a="undefined"!=typeof e.hasControls?e.hasControls:this.hasControls,c="undefined"!=typeof e.rotatingPointOffset?e.rotatingPointOffset:this.rotatingPointOffset;if(t.save(),t.strokeStyle=e.borderColor||this.borderColor,this._setLineDash(t,e.borderDashArray||this.borderDashArray,null),t.strokeRect(-n/2,-o/2,n,o),s&&this.isControlVisible("mtr")&&a){var l=-o/2;t.beginPath(),t.moveTo(0,l),t.lineTo(0,l-c),t.stroke()}return t.restore(),this},drawBordersInGroup:function(t,e,i){i=i||{};var r=this._getNonTransformedDimensions(),n=fabric.util.customTransformMatrix(e.scaleX,e.scaleY,e.skewX),o=fabric.util.transformPoint(r,n),s=1/this.borderScaleFactor,a=o.x+s,c=o.y+s;return t.save(),this._setLineDash(t,i.borderDashArray||this.borderDashArray,null),t.strokeStyle=i.borderColor||this.borderColor,t.strokeRect(-a/2,-c/2,a,c),t.restore(),this},drawControls:function(t,e){e=e||{};var i=this._calculateCurrentDimensions(),r=i.x,n=i.y,o=e.cornerSize||this.cornerSize,s=-(r+o)/2,a=-(n+o)/2,c="undefined"!=typeof e.transparentCorners?e.transparentCorners:this.transparentCorners,l="undefined"!=typeof e.hasRotatingPoint?e.hasRotatingPoint:this.hasRotatingPoint,u=c?"stroke":"fill";return t.save(),t.strokeStyle=t.fillStyle=e.cornerColor||this.cornerColor,this.transparentCorners||(t.strokeStyle=e.cornerStrokeColor||this.cornerStrokeColor),this._setLineDash(t,e.cornerDashArray||this.cornerDashArray,null),this._drawControl("tl",t,u,s,a,e),this._drawControl("tr",t,u,s+r,a,e),this._drawControl("bl",t,u,s,a+n,e),this._drawControl("br",t,u,s+r,a+n,e),this.get("lockUniScaling")||(this._drawControl("mt",t,u,s+r/2,a,e),this._drawControl("mb",t,u,s+r/2,a+n,e),this._drawControl("mr",t,u,s+r,a+n/2,e),this._drawControl("ml",t,u,s,a+n/2,e)),l&&this._drawControl("mtr",t,u,s+r/2,a-this.rotatingPointOffset,e),t.restore(),this},_drawControl:function(t,e,i,r,n,o){if(o=o||{},this.isControlVisible(t)){var s=this.cornerSize,a=!this.transparentCorners&&this.cornerStrokeColor;switch(o.cornerStyle||this.cornerStyle){case"circle":e.beginPath(),e.arc(r+s/2,n+s/2,s/2,0,2*Math.PI,!1),e[i](),a&&e.stroke();break;default:this.transparentCorners||e.clearRect(r,n,s,s),e[i+"Rect"](r,n,s,s),a&&e.strokeRect(r,n,s,s)}}},isControlVisible:function(t){return this._getControlsVisibility()[t]},setControlVisible:function(t,e){return this._getControlsVisibility()[t]=e,this},setControlsVisibility:function(t){t||(t={});for(var e in t)this.setControlVisible(e,t[e]);return this},_getControlsVisibility:function(){return this._controlsVisibility||(this._controlsVisibility={tl:!0,tr:!0,br:!0,bl:!0,ml:!0,mt:!0,mr:!0,mb:!0,mtr:!0}),this._controlsVisibility},onDeselect:function(){},onSelect:function(){}})}();fabric.util.object.extend(fabric.StaticCanvas.prototype,{FX_DURATION:500,fxCenterObjectH:function(t,e){e=e||{};var i=function(){},r=e.onComplete||i,n=e.onChange||i,o=this;return fabric.util.animate({startValue:t.left,endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(e){t.set("left",e),o.requestRenderAll(),n()},onComplete:function(){t.setCoords(),r()}}),this},fxCenterObjectV:function(t,e){e=e||{};var i=function(){},r=e.onComplete||i,n=e.onChange||i,o=this;return fabric.util.animate({startValue:t.top,endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(e){t.set("top",e),o.requestRenderAll(),n()},onComplete:function(){t.setCoords(),r()}}),this},fxRemove:function(t,e){e=e||{};var i=function(){},r=e.onComplete||i,n=e.onChange||i,o=this;return fabric.util.animate({startValue:t.opacity,endValue:0,duration:this.FX_DURATION,onChange:function(e){t.set("opacity",e),o.requestRenderAll(),n()},onComplete:function(){o.remove(t),r()}}),this}}),fabric.util.object.extend(fabric.Object.prototype,{animate:function(){if(arguments[0]&&"object"==typeof arguments[0]){var t,e,i=[];for(t in arguments[0])i.push(t);for(var r=0,n=i.length;n>r;r++)t=i[r],e=r!==n-1,this._animate(t,arguments[0][t],arguments[1],e)}else this._animate.apply(this,arguments);return this},_animate:function(t,e,i,r){var n,o=this;e=e.toString(),i=i?fabric.util.object.clone(i):{},~t.indexOf(".")&&(n=t.split("."));var s=n?this.get(n[0])[n[1]]:this.get(t);"from"in i||(i.from=s),e=~e.indexOf("=")?s+parseFloat(e.replace("=","")):parseFloat(e),fabric.util.animate({startValue:i.from,endValue:e,byValue:i.by,easing:i.easing,duration:i.duration,abort:i.abort&&function(){return i.abort.call(o)},onChange:function(e,s,a){n?o[n[0]][n[1]]=e:o.set(t,e),r||i.onChange&&i.onChange(e,s,a)},onComplete:function(t,e,n){r||(o.setCoords(),i.onComplete&&i.onComplete(t,e,n))}})}});!function(t){"use strict";function e(t,e){var i=t.origin,n=t.axis1,r=t.axis2,o=t.dimension,s=e.nearest,a=e.center,c=e.farthest;return function(){switch(this.get(i)){case s:return Math.min(this.get(n),this.get(r));case a:return Math.min(this.get(n),this.get(r))+.5*this.get(o);case c:return Math.max(this.get(n),this.get(r))}}}var i=t.fabric||(t.fabric={}),n=i.util.object.extend,r=i.util.object.clone,o={x1:1,x2:1,y1:1,y2:1},s=i.StaticCanvas.supports("setLineDash");return i.Line?void i.warn("fabric.Line is already defined"):(i.Line=i.util.createClass(i.Object,{type:"line",x1:0,y1:0,x2:0,y2:0,cacheProperties:i.Object.prototype.cacheProperties.concat("x1","x2","y1","y2"),initialize:function(t,e){t||(t=[0,0,0,0]),this.callSuper("initialize",e),this.set("x1",t[0]),this.set("y1",t[1]),this.set("x2",t[2]),this.set("y2",t[3]),this._setWidthHeight(e)},_setWidthHeight:function(t){t||(t={}),this.width=Math.abs(this.x2-this.x1),this.height=Math.abs(this.y2-this.y1),this.left="left"in t?t.left:this._getLeftToOriginX(),this.top="top"in t?t.top:this._getTopToOriginY()},_set:function(t,e){return this.callSuper("_set",t,e),"undefined"!=typeof o[t]&&this._setWidthHeight(),this},_getLeftToOriginX:e({origin:"originX",axis1:"x1",axis2:"x2",dimension:"width"},{nearest:"left",center:"center",farthest:"right"}),_getTopToOriginY:e({origin:"originY",axis1:"y1",axis2:"y2",dimension:"height"},{nearest:"top",center:"center",farthest:"bottom"}),_render:function(t){if(t.beginPath(),!this.strokeDashArray||this.strokeDashArray&&s){var e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)}t.lineWidth=this.strokeWidth;var i=t.strokeStyle;t.strokeStyle=this.stroke||t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=i},_renderDashedStroke:function(t){var e=this.calcLinePoints();t.beginPath(),i.util.drawDashedLine(t,e.x1,e.y1,e.x2,e.y2,this.strokeDashArray),t.closePath()},_findCenterFromElement:function(){return{x:(this.x1+this.x2)/2,y:(this.y1+this.y2)/2}},toObject:function(t){return n(this.callSuper("toObject",t),this.calcLinePoints())},_getNonTransformedDimensions:function(){var t=this.callSuper("_getNonTransformedDimensions");return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t},calcLinePoints:function(){var t=this.x1<=this.x2?-1:1,e=this.y1<=this.y2?-1:1,i=t*this.width*.5,n=e*this.height*.5,r=t*this.width*-.5,o=e*this.height*-.5;return{x1:i,x2:r,y1:n,y2:o}}}),void(i.Line.fromObject=function(t,e){function n(t){delete t.points,e&&e(t)}var o=r(t,!0);o.points=[t.x1,t.y1,t.x2,t.y2],i.Object._fromObject("Line",o,n,"points")}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=Math.PI;return e.Circle?void e.warn("fabric.Circle is already defined."):(e.Circle=e.util.createClass(e.Object,{type:"circle",radius:0,startAngle:0,endAngle:2*i,cacheProperties:e.Object.prototype.cacheProperties.concat("radius","startAngle","endAngle"),_set:function(t,e){return this.callSuper("_set",t,e),"radius"===t&&this.setRadius(e),this},toObject:function(t){return this.callSuper("toObject",["radius","startAngle","endAngle"].concat(t))},_render:function(t){t.beginPath(),t.arc(0,0,this.radius,this.startAngle,this.endAngle,!1),this._renderPaintInOrder(t)},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(t){return this.radius=t,this.set("width",2*t).set("height",2*t)}}),void(e.Circle.fromObject=function(t,i){return e.Object._fromObject("Circle",t,i)}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={});return e.Triangle?void e.warn("fabric.Triangle is already defined"):(e.Triangle=e.util.createClass(e.Object,{type:"triangle",width:100,height:100,_render:function(t){var e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,i),t.lineTo(0,-i),t.lineTo(e,i),t.closePath(),this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var i=this.width/2,r=this.height/2;t.beginPath(),e.util.drawDashedLine(t,-i,r,0,-r,this.strokeDashArray),e.util.drawDashedLine(t,0,-r,i,r,this.strokeDashArray),e.util.drawDashedLine(t,i,r,-i,r,this.strokeDashArray),t.closePath()}}),void(e.Triangle.fromObject=function(t,i){return e.Object._fromObject("Triangle",t,i)}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=2*Math.PI;return e.Ellipse?void e.warn("fabric.Ellipse is already defined."):(e.Ellipse=e.util.createClass(e.Object,{type:"ellipse",rx:0,ry:0,cacheProperties:e.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this.set("rx",t&&t.rx||0),this.set("ry",t&&t.ry||0)},_set:function(t,e){switch(this.callSuper("_set",t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this},getRx:function(){return this.get("rx")*this.get("scaleX")},getRy:function(){return this.get("ry")*this.get("scaleY")},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))},_render:function(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,i,!1),t.restore(),this._renderPaintInOrder(t)}}),void(e.Ellipse.fromObject=function(t,i){return e.Object._fromObject("Ellipse",t,i)}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";{var e=t.fabric||(t.fabric={});e.util.object.extend}return e.Rect?void e.warn("fabric.Rect is already defined"):(e.Rect=e.util.createClass(e.Object,{stateProperties:e.Object.prototype.stateProperties.concat("rx","ry"),type:"rect",rx:0,ry:0,cacheProperties:e.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this._initRxRy()},_initRxRy:function(){this.rx&&!this.ry?this.ry=this.rx:this.ry&&!this.rx&&(this.rx=this.ry)},_render:function(t){if(1===this.width&&1===this.height)return void t.fillRect(-.5,-.5,1,1);var e=this.rx?Math.min(this.rx,this.width/2):0,i=this.ry?Math.min(this.ry,this.height/2):0,r=this.width,n=this.height,s=-this.width/2,o=-this.height/2,a=0!==e||0!==i,c=.4477152502;t.beginPath(),t.moveTo(s+e,o),t.lineTo(s+r-e,o),a&&t.bezierCurveTo(s+r-c*e,o,s+r,o+c*i,s+r,o+i),t.lineTo(s+r,o+n-i),a&&t.bezierCurveTo(s+r,o+n-c*i,s+r-c*e,o+n,s+r-e,o+n),t.lineTo(s+e,o+n),a&&t.bezierCurveTo(s+c*e,o+n,s,o+n-c*i,s,o+n-i),t.lineTo(s,o+i),a&&t.bezierCurveTo(s,o+c*i,s+c*e,o,s+e,o),t.closePath(),this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var i=-this.width/2,r=-this.height/2,n=this.width,s=this.height;t.beginPath(),e.util.drawDashedLine(t,i,r,i+n,r,this.strokeDashArray),e.util.drawDashedLine(t,i+n,r,i+n,r+s,this.strokeDashArray),e.util.drawDashedLine(t,i+n,r+s,i,r+s,this.strokeDashArray),e.util.drawDashedLine(t,i,r+s,i,r,this.strokeDashArray),t.closePath()},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))}}),void(e.Rect.fromObject=function(t,i){return e.Object._fromObject("Rect",t,i)}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";{var e=t.fabric||(t.fabric={}),i=e.util.object.extend,r=e.util.array.min,n=e.util.array.max;e.util.toFixed}return e.Polyline?void e.warn("fabric.Polyline is already defined"):(e.Polyline=e.util.createClass(e.Object,{type:"polyline",points:null,cacheProperties:e.Object.prototype.cacheProperties.concat("points"),initialize:function(t,e){e=e||{},this.points=t||[],this.callSuper("initialize",e);var i=this._calcDimensions();"undefined"==typeof e.left&&(this.left=i.left),"undefined"==typeof e.top&&(this.top=i.top),this.width=i.width,this.height=i.height,this.pathOffset={x:i.left+this.width/2,y:i.top+this.height/2}},_calcDimensions:function(){var t=this.points,e=r(t,"x")||0,i=r(t,"y")||0,s=n(t,"x")||0,o=n(t,"y")||0,a=s-e,c=o-i;return{left:e,top:i,width:a,height:c}},toObject:function(t){return i(this.callSuper("toObject",t),{points:this.points.concat()})},commonRender:function(t){var e,i=this.points.length,r=this.pathOffset.x,n=this.pathOffset.y;if(!i||isNaN(this.points[i-1].y))return!1;t.beginPath(),t.moveTo(this.points[0].x-r,this.points[0].y-n);for(var s=0;i>s;s++)e=this.points[s],t.lineTo(e.x-r,e.y-n);return!0},_render:function(t){this.commonRender(t)&&this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var i,r;t.beginPath();for(var n=0,s=this.points.length;s>n;n++)i=this.points[n],r=this.points[n+1]||i,e.util.drawDashedLine(t,i.x,i.y,r.x,r.y,this.strokeDashArray)},complexity:function(){return this.get("points").length}}),void(e.Polyline.fromObject=function(t,i){return e.Object._fromObject("Polyline",t,i,"points")}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";{var e=t.fabric||(t.fabric={});e.util.object.extend}return e.Polygon?void e.warn("fabric.Polygon is already defined"):(e.Polygon=e.util.createClass(e.Polyline,{type:"polygon",_render:function(t){this.commonRender(t)&&(t.closePath(),this._renderPaintInOrder(t))},_renderDashedStroke:function(t){this.callSuper("_renderDashedStroke",t),t.closePath()}}),void(e.Polygon.fromObject=function(t,i){return e.Object._fromObject("Polygon",t,i,"points")}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.array.min,r=e.util.array.max,n=e.util.object.extend,s=Object.prototype.toString,o=e.util.drawArc,a={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},c={m:"l",M:"L"};return e.Path?void e.warn("fabric.Path is already defined"):(e.Path=e.util.createClass(e.Object,{type:"path",path:null,cacheProperties:e.Object.prototype.cacheProperties.concat("path","fillRule"),stateProperties:e.Object.prototype.stateProperties.concat("path"),initialize:function(t,e){e=e||{},this.callSuper("initialize",e),t||(t=[]);var i="[object Array]"===s.call(t);this.path=i?t:t.match&&t.match(/[mzlhvcsqta][^mzlhvcsqta]*/gi),this.path&&(i||(this.path=this._parsePath()),this._setPositionDimensions(e))},_setPositionDimensions:function(t){var e=this._parseDimensions();this.width=e.width,this.height=e.height,"undefined"==typeof t.left&&(this.left=e.left),"undefined"==typeof t.top&&(this.top=e.top),this.pathOffset=this.pathOffset||{x:e.left+this.width/2,y:e.top+this.height/2}},_renderPathCommands:function(t){var e,i,r,n=null,s=0,a=0,c=0,l=0,h=0,u=0,f=-this.pathOffset.x,d=-this.pathOffset.y;t.beginPath();for(var p=0,g=this.path.length;g>p;++p){switch(e=this.path[p],e[0]){case"l":c+=e[1],l+=e[2],t.lineTo(c+f,l+d);break;case"L":c=e[1],l=e[2],t.lineTo(c+f,l+d);break;case"h":c+=e[1],t.lineTo(c+f,l+d);break;case"H":c=e[1],t.lineTo(c+f,l+d);break;case"v":l+=e[1],t.lineTo(c+f,l+d);break;case"V":l=e[1],t.lineTo(c+f,l+d);break;case"m":c+=e[1],l+=e[2],s=c,a=l,t.moveTo(c+f,l+d);break;case"M":c=e[1],l=e[2],s=c,a=l,t.moveTo(c+f,l+d);break;case"c":i=c+e[5],r=l+e[6],h=c+e[3],u=l+e[4],t.bezierCurveTo(c+e[1]+f,l+e[2]+d,h+f,u+d,i+f,r+d),c=i,l=r;break;case"C":c=e[5],l=e[6],h=e[3],u=e[4],t.bezierCurveTo(e[1]+f,e[2]+d,h+f,u+d,c+f,l+d);break;case"s":i=c+e[3],r=l+e[4],null===n[0].match(/[CcSs]/)?(h=c,u=l):(h=2*c-h,u=2*l-u),t.bezierCurveTo(h+f,u+d,c+e[1]+f,l+e[2]+d,i+f,r+d),h=c+e[1],u=l+e[2],c=i,l=r;break;case"S":i=e[3],r=e[4],null===n[0].match(/[CcSs]/)?(h=c,u=l):(h=2*c-h,u=2*l-u),t.bezierCurveTo(h+f,u+d,e[1]+f,e[2]+d,i+f,r+d),c=i,l=r,h=e[1],u=e[2];break;case"q":i=c+e[3],r=l+e[4],h=c+e[1],u=l+e[2],t.quadraticCurveTo(h+f,u+d,i+f,r+d),c=i,l=r;break;case"Q":i=e[3],r=e[4],t.quadraticCurveTo(e[1]+f,e[2]+d,i+f,r+d),c=i,l=r,h=e[1],u=e[2];break;case"t":i=c+e[1],r=l+e[2],null===n[0].match(/[QqTt]/)?(h=c,u=l):(h=2*c-h,u=2*l-u),t.quadraticCurveTo(h+f,u+d,i+f,r+d),c=i,l=r;break;case"T":i=e[1],r=e[2],null===n[0].match(/[QqTt]/)?(h=c,u=l):(h=2*c-h,u=2*l-u),t.quadraticCurveTo(h+f,u+d,i+f,r+d),c=i,l=r;break;case"a":o(t,c+f,l+d,[e[1],e[2],e[3],e[4],e[5],e[6]+c+f,e[7]+l+d]),c+=e[6],l+=e[7];break;case"A":o(t,c+f,l+d,[e[1],e[2],e[3],e[4],e[5],e[6]+f,e[7]+d]),c=e[6],l=e[7];break;case"z":case"Z":c=s,l=a,t.closePath()}n=e}},_render:function(t){this._renderPathCommands(t),this._renderPaintInOrder(t)},toString:function(){return"#<fabric.Path ("+this.complexity()+'): { "top": '+this.top+', "left": '+this.left+" }>"},toObject:function(t){var e=n(this.callSuper("toObject",t),{path:this.path.map(function(t){return t.slice()}),top:this.top,left:this.left});return e},toDatalessObject:function(t){var e=this.toObject(["sourcePath"].concat(t));return e.sourcePath&&delete e.path,e},complexity:function(){return this.path.length},_parsePath:function(){for(var t,e,i,r,n,s=[],o=[],l=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi,h=0,u=this.path.length;u>h;h++){for(t=this.path[h],r=t.slice(1).trim(),o.length=0;i=l.exec(r);)o.push(i[0]);n=[t.charAt(0)];for(var f=0,d=o.length;d>f;f++)e=parseFloat(o[f]),isNaN(e)||n.push(e);var p=n[0],g=a[p.toLowerCase()],v=c[p]||p;if(n.length-1>g)for(var m=1,b=n.length;b>m;m+=g)s.push([p].concat(n.slice(m,m+g))),p=v;else s.push(n)}return s},_parseDimensions:function(){for(var t,n,s,o,a=[],c=[],l=null,h=0,u=0,f=0,d=0,p=0,g=0,v=0,m=this.path.length;m>v;++v){switch(t=this.path[v],t[0]){case"l":f+=t[1],d+=t[2],o=[];break;case"L":f=t[1],d=t[2],o=[];break;case"h":f+=t[1],o=[];break;case"H":f=t[1],o=[];break;case"v":d+=t[1],o=[];break;case"V":d=t[1],o=[];break;case"m":f+=t[1],d+=t[2],h=f,u=d,o=[];break;case"M":f=t[1],d=t[2],h=f,u=d,o=[];break;case"c":n=f+t[5],s=d+t[6],p=f+t[3],g=d+t[4],o=e.util.getBoundsOfCurve(f,d,f+t[1],d+t[2],p,g,n,s),f=n,d=s;break;case"C":p=t[3],g=t[4],o=e.util.getBoundsOfCurve(f,d,t[1],t[2],p,g,t[5],t[6]),f=t[5],d=t[6];break;case"s":n=f+t[3],s=d+t[4],null===l[0].match(/[CcSs]/)?(p=f,g=d):(p=2*f-p,g=2*d-g),o=e.util.getBoundsOfCurve(f,d,p,g,f+t[1],d+t[2],n,s),p=f+t[1],g=d+t[2],f=n,d=s;break;case"S":n=t[3],s=t[4],null===l[0].match(/[CcSs]/)?(p=f,g=d):(p=2*f-p,g=2*d-g),o=e.util.getBoundsOfCurve(f,d,p,g,t[1],t[2],n,s),f=n,d=s,p=t[1],g=t[2];break;case"q":n=f+t[3],s=d+t[4],p=f+t[1],g=d+t[2],o=e.util.getBoundsOfCurve(f,d,p,g,p,g,n,s),f=n,d=s;break;case"Q":p=t[1],g=t[2],o=e.util.getBoundsOfCurve(f,d,p,g,p,g,t[3],t[4]),f=t[3],d=t[4];break;case"t":n=f+t[1],s=d+t[2],null===l[0].match(/[QqTt]/)?(p=f,g=d):(p=2*f-p,g=2*d-g),o=e.util.getBoundsOfCurve(f,d,p,g,p,g,n,s),f=n,d=s;break;case"T":n=t[1],s=t[2],null===l[0].match(/[QqTt]/)?(p=f,g=d):(p=2*f-p,g=2*d-g),o=e.util.getBoundsOfCurve(f,d,p,g,p,g,n,s),f=n,d=s;break;case"a":o=e.util.getBoundsOfArc(f,d,t[1],t[2],t[3],t[4],t[5],t[6]+f,t[7]+d),f+=t[6],d+=t[7];break;case"A":o=e.util.getBoundsOfArc(f,d,t[1],t[2],t[3],t[4],t[5],t[6],t[7]),f=t[6],d=t[7];break;case"z":case"Z":f=h,d=u}l=t,o.forEach(function(t){a.push(t.x),c.push(t.y)}),a.push(f),c.push(d)}var b=i(a)||0,y=i(c)||0,_=r(a)||0,w=r(c)||0,x=_-b,C=w-y,O={left:b,top:y,width:x,height:C};return O}}),void(e.Path.fromObject=function(t,i){if("string"==typeof t.sourcePath){var r=t.sourcePath;e.loadSVGFromURL(r,function(e){var r=e[0];r.setOptions(t),i&&i(r)})}else e.Object._fromObject("Path",t,i,"path")}))}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,r=e.util.array.min,n=e.util.array.max;e.Group||(e.Group=e.util.createClass(e.Object,e.Collection,{type:"group",strokeWidth:0,subTargetCheck:!1,cacheProperties:[],useSetOnGroup:!1,initialize:function(t,e,i){e=e||{},this._objects=[],i&&this.callSuper("initialize",e),this._objects=t||[];for(var r=this._objects.length;r--;)this._objects[r].group=this;if(e.originX&&(this.originX=e.originX),e.originY&&(this.originY=e.originY),i)this._updateObjectsACoords();else{var n=e&&e.centerPoint;n||this._calcBounds(),this._updateObjectsCoords(n),delete e.centerPoint,this.callSuper("initialize",e)}this.setCoords()},_updateObjectsACoords:function(){for(var t=!0,e=!0,i=this._objects.length;i--;)this._objects[i].setCoords(t,e)},_updateObjectsCoords:function(t){for(var t=t||this.getCenterPoint(),e=this._objects.length;e--;)this._updateObjectCoords(this._objects[e],t)},_updateObjectCoords:function(t,e){var i=t.left,r=t.top,n=!0,s=!0;t.set({left:i-e.x,top:r-e.y}),t.group=this,t.setCoords(n,s)},toString:function(){return"#<fabric.Group: ("+this.complexity()+")>"},addWithUpdate:function(t){return this._restoreObjectsState(),e.util.resetObjectTransform(this),t&&(this._objects.push(t),t.group=this,t._set("canvas",this.canvas)),this._calcBounds(),this._updateObjectsCoords(),this.setCoords(),this.dirty=!0,this},removeWithUpdate:function(t){return this._restoreObjectsState(),e.util.resetObjectTransform(this),this.remove(t),this._calcBounds(),this._updateObjectsCoords(),this.setCoords(),this.dirty=!0,this},_onObjectAdded:function(t){this.dirty=!0,t.group=this,t._set("canvas",this.canvas)},_onObjectRemoved:function(t){this.dirty=!0,delete t.group},_set:function(t,e){var i=this._objects.length;if(this.useSetOnGroup)for(;i--;)this._objects[i].setOnGroup(t,e);if("canvas"===t)for(i=this._objects.length;i--;)this._objects[i]._set(t,e);this.callSuper("_set",t,e)},toObject:function(t){var e=this.getObjects().map(function(e){var i=e.includeDefaultValues;e.includeDefaultValues=e.group.includeDefaultValues;var r=e.toObject(t);return e.includeDefaultValues=i,r});return i(this.callSuper("toObject",t),{objects:e})},toDatalessObject:function(t){var e,r=this.sourcePath;return e=r?r:this.getObjects().map(function(e){var i=e.includeDefaultValues;e.includeDefaultValues=e.group.includeDefaultValues;var r=e.toDatalessObject(t);return e.includeDefaultValues=i,r}),i(this.callSuper("toDatalessObject",t),{objects:e})},render:function(t){this._transformDone=!0,this.callSuper("render",t),this._transformDone=!1},shouldCache:function(){var t=this.objectCaching&&(!this.group||this.needsItsOwnCache()||!this.group.isOnACache());if(this.ownCaching=t,t)for(var e=0,i=this._objects.length;i>e;e++)if(this._objects[e].willDrawShadow())return this.ownCaching=!1,!1;return t},willDrawShadow:function(){if(this.shadow)return this.callSuper("willDrawShadow");for(var t=0,e=this._objects.length;e>t;t++)if(this._objects[t].willDrawShadow())return!0;return!1},isOnACache:function(){return this.ownCaching||this.group&&this.group.isOnACache()},drawObject:function(t){for(var e=this.clipPath,i=0,r=this._objects.length;r>i;i++)this._objects[i].render(t);e&&(e.shouldCache(),e._transformDone=!0,e.renderCache(this,!0),this.drawClipPathOnCache(t))},isCacheDirty:function(t,e){if(this.callSuper("isCacheDirty",t,e))return!0;if(!this.statefullCache)return!1;for(var i=0,r=this._objects.length;r>i;i++)if(this._objects[i].isCacheDirty(!0,e)){if(this._cacheCanvas){var n=this.cacheWidth/this.zoomX,s=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-n/2,-s/2,n,s)}return!0}return!1},_restoreObjectsState:function(){return this._objects.forEach(this._restoreObjectState,this),this},realizeTransform:function(t){var i=t.calcTransformMatrix(),r=e.util.qrDecompose(i),n=new e.Point(r.translateX,r.translateY);return t.flipX=!1,t.flipY=!1,t.set("scaleX",r.scaleX),t.set("scaleY",r.scaleY),t.skewX=r.skewX,t.skewY=r.skewY,t.angle=r.angle,t.setPositionByOrigin(n,"center","center"),t},_restoreObjectState:function(t){return this.realizeTransform(t),t.setCoords(),delete t.group,this},destroy:function(){return this._objects.forEach(function(t){t.set("dirty",!0)}),this._restoreObjectsState()},toActiveSelection:function(){if(this.canvas){var t=this._objects,i=this.canvas;this._objects=[];var r=this.toObject();delete r.objects;var n=new e.ActiveSelection([]);return n.set(r),n.type="activeSelection",i.remove(this),t.forEach(function(t){t.group=n,t.dirty=!0,i.add(t)}),n.canvas=i,n._objects=t,i._activeObject=n,n.setCoords(),n}},ungroupOnCanvas:function(){return this._restoreObjectsState()},setObjectsCoords:function(){var t=!0,e=!0;return this.forEachObject(function(i){i.setCoords(t,e)}),this},_calcBounds:function(t){for(var e,i,r,n=[],s=[],o=["tr","br","bl","tl"],a=0,c=this._objects.length,h=o.length,l=!0;c>a;++a)for(e=this._objects[a],e.setCoords(l),r=0;h>r;r++)i=o[r],n.push(e.oCoords[i].x),s.push(e.oCoords[i].y);this.set(this._getBounds(n,s,t))},_getBounds:function(t,i,s){var o=new e.Point(r(t),r(i)),a=new e.Point(n(t),n(i)),c={width:a.x-o.x||0,height:a.y-o.y||0};return s||(c.left=o.x||0,c.top=o.y||0,"center"===this.originX&&(c.left+=c.width/2),"right"===this.originX&&(c.left+=c.width),"center"===this.originY&&(c.top+=c.height/2),"bottom"===this.originY&&(c.top+=c.height)),c}}),e.Group.fromObject=function(t,i){e.util.enlivenObjects(t.objects,function(r){var n=e.util.object.clone(t,!0);delete n.objects,i&&i(new e.Group(r,n,!0))})})}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={});e.ActiveSelection||(e.ActiveSelection=e.util.createClass(e.Group,{type:"activeSelection",initialize:function(t,i){i=i||{},this._objects=t||[];for(var r=this._objects.length;r--;)this._objects[r].group=this;i.originX&&(this.originX=i.originX),i.originY&&(this.originY=i.originY),this._calcBounds(),this._updateObjectsCoords(),e.Object.prototype.initialize.call(this,i),this.setCoords()},toGroup:function(){var t=this._objects;this._objects=[];var i=this.toObject(),r=new e.Group([]);if(delete i.objects,r.set(i),r.type="group",t.forEach(function(t){t.group=r,t.canvas.remove(t)}),r._objects=t,!this.canvas)return r;var n=this.canvas;return n.add(r),n._activeObject=r,r.setCoords(),r},onDeselect:function(){return this.destroy(),!1},toString:function(){return"#<fabric.ActiveSelection: ("+this.complexity()+")>"},_set:function(t,i){var r=this._objects.length;if("canvas"===t)for(;r--;)this._objects[r].set(t,i);if(this.useSetOnGroup)for(;r--;)this._objects[r].setOnGroup(t,i);e.Object.prototype._set.call(this,t,i)},shouldCache:function(){return!1},willDrawShadow:function(){if(this.shadow)return this.callSuper("willDrawShadow");for(var t=0,e=this._objects.length;e>t;t++)if(this._objects[t].willDrawShadow())return!0;return!1},isOnACache:function(){return!1},_renderControls:function(t,e,i){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,this.callSuper("_renderControls",t,e),i=i||{},"undefined"==typeof i.hasControls&&(i.hasControls=!1),"undefined"==typeof i.hasRotatingPoint&&(i.hasRotatingPoint=!1),i.forActiveSelection=!0;for(var r=0,n=this._objects.length;n>r;r++)this._objects[r]._renderControls(t,i);t.restore()}}),e.ActiveSelection.fromObject=function(t,i){e.util.enlivenObjects(t.objects,function(r){delete t.objects,i&&i(new e.ActiveSelection(r,t,!0))})})}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=fabric.util.object.extend;return t.fabric||(t.fabric={}),t.fabric.Image?void fabric.warn("fabric.Image is already defined."):(fabric.Image=fabric.util.createClass(fabric.Object,{type:"image",crossOrigin:"",strokeWidth:0,_lastScaleX:1,_lastScaleY:1,_filterScalingX:1,_filterScalingY:1,minimumScaleTrigger:.5,stateProperties:fabric.Object.prototype.stateProperties.concat("cropX","cropY"),cacheKey:"",cropX:0,cropY:0,initialize:function(t,e){e||(e={}),this.filters=[],this.cacheKey="texture"+fabric.Object.__uid++,this.callSuper("initialize",e),this._initElement(t,e)},getElement:function(){return this._element},setElement:function(t,e){var i=fabric.filterBackend;return i&&i.evictCachesForKey&&(i.evictCachesForKey(this.cacheKey),i.evictCachesForKey(this.cacheKey+"_filtered")),this._element=t,this._originalElement=t,this._initConfig(e),this.resizeFilter&&this.applyResizeFilters(),0!==this.filters.length&&this.applyFilters(),this},dispose:function(){var t=fabric.filterBackend;t&&t.evictCachesForKey&&(t.evictCachesForKey(this.cacheKey),t.evictCachesForKey(this.cacheKey+"_filtered")),this._originalElement=void 0,this._element=void 0,this._filteredEl=void 0},setCrossOrigin:function(t){return this.crossOrigin=t,this._element.crossOrigin=t,this},getOriginalSize:function(){var t=this.getElement();return{width:t.width,height:t.height}},_stroke:function(t){if(this.stroke&&0!==this.strokeWidth){var e=this.width/2,i=this.height/2;t.beginPath(),t.moveTo(-e,-i),t.lineTo(e,-i),t.lineTo(e,i),t.lineTo(-e,i),t.lineTo(-e,-i),t.closePath()}},_renderDashedStroke:function(t){var e=-this.width/2,i=-this.height/2,r=this.width,n=this.height;t.save(),this._setStrokeStyles(t,this),t.beginPath(),fabric.util.drawDashedLine(t,e,i,e+r,i,this.strokeDashArray),fabric.util.drawDashedLine(t,e+r,i,e+r,i+n,this.strokeDashArray),fabric.util.drawDashedLine(t,e+r,i+n,e,i+n,this.strokeDashArray),fabric.util.drawDashedLine(t,e,i+n,e,i,this.strokeDashArray),t.closePath(),t.restore()},toObject:function(t){var i=[];this.filters.forEach(function(t){t&&i.push(t.toObject())});var r=e(this.callSuper("toObject",["crossOrigin","cropX","cropY"].concat(t)),{src:this.getSrc(),filters:i});return this.resizeFilter&&(r.resizeFilter=this.resizeFilter.toObject()),r},hasCrop:function(){return this.cropX||this.cropY||this.width<this._element.width||this.height<this._element.height},getSrc:function(t){var e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():e.src:this.src||""},setSrc:function(t,e,i){return fabric.util.loadImage(t,function(t){this.setElement(t,i),this._setWidthHeight(),e(this)},this,i&&i.crossOrigin),this},toString:function(){return'#<fabric.Image: { src: "'+this.getSrc()+'" }>'},applyResizeFilters:function(){var t=this.resizeFilter,e=this.canvas?this.canvas.getRetinaScaling():1,i=this.minimumScaleTrigger,r=this.scaleX*e,n=this.scaleY*e,s=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||r>i&&n>i)return this._element=s,this._filterScalingX=1,void(this._filterScalingY=1);fabric.filterBackend||(fabric.filterBackend=fabric.initFilterBackend());var o=fabric.util.createCanvasElement(),a=this._filteredEl?this.cacheKey:this.cacheKey+"_filtered",c=s.width,h=s.height;o.width=c,o.height=h,this._element=o,t.scaleX=r,t.scaleY=n,fabric.filterBackend.applyFilters([t],s,c,h,this._element,a),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height},applyFilters:function(t){if(t=t||this.filters||[],t=t.filter(function(t){return t}),this.group&&this.set("dirty",!0),0===t.length)return this._element=this._originalElement,this._filteredEl=null,this._filterScalingX=1,this._filterScalingY=1,this;var e=this._originalElement,i=e.naturalWidth||e.width,r=e.naturalHeight||e.height;if(this._element===this._originalElement){var n=fabric.util.createCanvasElement();n.width=i,n.height=r,this._element=n,this._filteredEl=n}else this._element.getContext("2d").clearRect(0,0,i,r);return fabric.filterBackend||(fabric.filterBackend=fabric.initFilterBackend()),fabric.filterBackend.applyFilters(t,this._originalElement,i,r,this._element,this.cacheKey),(this._originalElement.width!==this._element.width||this._originalElement.height!==this._element.height)&&(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height),this},_render:function(t){this.isMoving===!1&&this.resizeFilter&&this._needsResize()&&(this._lastScaleX=this.scaleX,this._lastScaleY=this.scaleY,this.applyResizeFilters()),this._stroke(t),this._renderPaintInOrder(t)},_renderFill:function(t){var e=this.width,i=this.height,r=e*this._filterScalingX,n=i*this._filterScalingY,s=-e/2,o=-i/2,a=this._element;a&&t.drawImage(a,this.cropX*this._filterScalingX,this.cropY*this._filterScalingY,r,n,s,o,e,i)},_needsResize:function(){return this.scaleX!==this._lastScaleX||this.scaleY!==this._lastScaleY},_resetWidthHeight:function(){var t=this.getElement();this.set("width",t.width),this.set("height",t.height)},_initElement:function(t,e){this.setElement(fabric.util.getById(t),e),fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(t){t||(t={}),this.setOptions(t),this._setWidthHeight(t),this._element&&this.crossOrigin&&(this._element.crossOrigin=this.crossOrigin)},_initFilters:function(t,e){t&&t.length?fabric.util.enlivenObjects(t,function(t){e&&e(t)},"fabric.Image.filters"):e&&e()},_setWidthHeight:function(t){this.width=t&&"width"in t?t.width:this.getElement()?this.getElement().width||0:0,this.height=t&&"height"in t?t.height:this.getElement()?this.getElement().height||0:0},parsePreserveAspectRatioAttribute:function(){var t,e=fabric.util.parsePreserveAspectRatioAttribute(this.preserveAspectRatio||""),i=this._element.width,r=this._element.height,n=1,s=1,o=0,a=0,c=0,h=0,l=this.width,u=this.height,f={width:l,height:u};return!e||"none"===e.alignX&&"none"===e.alignY?(n=l/i,s=u/r):("meet"===e.meetOrSlice&&(n=s=fabric.util.findScaleToFit(this._element,f),t=(l-i*n)/2,"Min"===e.alignX&&(o=-t),"Max"===e.alignX&&(o=t),t=(u-r*s)/2,"Min"===e.alignY&&(a=-t),"Max"===e.alignY&&(a=t)),"slice"===e.meetOrSlice&&(n=s=fabric.util.findScaleToCover(this._element,f),t=i-l/n,"Mid"===e.alignX&&(c=t/2),"Max"===e.alignX&&(c=t),t=r-u/s,"Mid"===e.alignY&&(h=t/2),"Max"===e.alignY&&(h=t),i=l/n,r=u/s)),{width:i,height:r,scaleX:n,scaleY:s,offsetLeft:o,offsetTop:a,cropX:c,cropY:h}}}),fabric.Image.CSS_CANVAS="canvas-img",fabric.Image.prototype.getSvgSrc=fabric.Image.prototype.getSrc,fabric.Image.fromObject=function(t,e){var i=fabric.util.object.clone(t);fabric.util.loadImage(i.src,function(t,r){return r?void(e&&e(null,r)):void fabric.Image.prototype._initFilters.call(i,i.filters,function(r){i.filters=r||[],fabric.Image.prototype._initFilters.call(i,[i.resizeFilter],function(r){i.resizeFilter=r[0];var n=new fabric.Image(t,i);e(n)})})},null,i.crossOrigin)},void(fabric.Image.fromURL=function(t,e,i){fabric.util.loadImage(t,function(t){e&&e(new fabric.Image(t,i))},null,i&&i.crossOrigin)}))}("undefined"!=typeof exports?exports:this);fabric.util.object.extend(fabric.Object.prototype,{_getAngleValueForStraighten:function(){var t=this.angle%360;return t>0?90*Math.round((t-1)/90):90*Math.round(t/90)},straighten:function(){return this.rotate(this._getAngleValueForStraighten()),this},fxStraighten:function(t){t=t||{};var e=function(){},i=t.onComplete||e,r=t.onChange||e,n=this;return fabric.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(t){n.rotate(t),r()},onComplete:function(){n.setCoords(),i()}}),this}}),fabric.util.object.extend(fabric.StaticCanvas.prototype,{straightenObject:function(t){return t.straighten(),this.requestRenderAll(),this},fxStraightenObject:function(t){return t.fxStraighten({onChange:this.requestRenderAllBound}),this}});function resizeCanvasIfNeeded(t){var e=t.targetCanvas,i=e.width,r=e.height,n=t.destinationWidth,s=t.destinationHeight;(i!==n||r!==s)&&(e.width=n,e.height=s)}function copyGLTo2DDrawImage(t,e){var i=t.canvas,r=e.targetCanvas,n=r.getContext("2d");n.translate(0,r.height),n.scale(1,-1);var s=i.height-r.height;n.drawImage(i,0,s,r.width,r.height,0,0,r.width,r.height)}function copyGLTo2DPutImageData(t,e){var i=e.targetCanvas,r=i.getContext("2d"),n=e.destinationWidth,s=e.destinationHeight,o=n*s*4,a=new Uint8Array(this.imageBuffer,0,o),c=new Uint8ClampedArray(this.imageBuffer,0,o);t.readPixels(0,0,n,s,t.RGBA,t.UNSIGNED_BYTE,a);var h=new ImageData(c,n,s);r.putImageData(h,0,0)}!function(){"use strict";function t(t,e){var i="precision "+e+" float;\nvoid main(){}",r=t.createShader(t.FRAGMENT_SHADER);return t.shaderSource(r,i),t.compileShader(r),t.getShaderParameter(r,t.COMPILE_STATUS)?!0:!1}function e(t){t&&t.tileSize&&(this.tileSize=t.tileSize),this.setupGLContext(this.tileSize,this.tileSize),this.captureGPUInfo()}fabric.isWebglSupported=function(e){if(fabric.isLikelyNode)return!1;e=e||fabric.WebglFilterBackend.prototype.tileSize;var i=document.createElement("canvas"),r=i.getContext("webgl")||i.getContext("experimental-webgl"),n=!1;if(r){fabric.maxTextureSize=r.getParameter(r.MAX_TEXTURE_SIZE),n=fabric.maxTextureSize>=e;for(var s=["highp","mediump","lowp"],o=0;3>o;o++)if(t(r,s[o])){fabric.webGlPrecision=s[o];break}}return this.isSupported=n,n},fabric.WebglFilterBackend=e,e.prototype={tileSize:2048,resources:{},setupGLContext:function(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.aPosition=new Float32Array([0,0,0,1,1,0,1,1]),this.chooseFastestCopyGLTo2DMethod(t,e)},chooseFastestCopyGLTo2DMethod:function(t,e){var i,r="undefined"!=typeof window.performance;try{new ImageData(1,1),i=!0}catch(n){i=!1}var s="undefined"!=typeof ArrayBuffer,o="undefined"!=typeof Uint8ClampedArray;if(r&&i&&s&&o){var a,c,h,l=fabric.util.createCanvasElement(),u=new ArrayBuffer(t*e*4),f={imageBuffer:u,destinationWidth:t,destinationHeight:e,targetCanvas:l};l.width=t,l.height=e,a=window.performance.now(),copyGLTo2DDrawImage.call(f,this.gl,f),c=window.performance.now()-a,a=window.performance.now(),copyGLTo2DPutImageData.call(f,this.gl,f),h=window.performance.now()-a,c>h?(this.imageBuffer=u,this.copyGLTo2D=copyGLTo2DPutImageData):this.copyGLTo2D=copyGLTo2DDrawImage}},createWebGLCanvas:function(t,e){var i=fabric.util.createCanvasElement();i.width=t,i.height=e;var r={alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1},n=i.getContext("webgl",r);n||(n=i.getContext("experimental-webgl",r)),n&&(n.clearColor(0,0,0,0),this.canvas=i,this.gl=n)},applyFilters:function(t,e,i,r,n,s){var o,a=this.gl;s&&(o=this.getCachedTexture(s,e));var c={originalWidth:e.width||e.originalWidth,originalHeight:e.height||e.originalHeight,sourceWidth:i,sourceHeight:r,destinationWidth:i,destinationHeight:r,context:a,sourceTexture:this.createTexture(a,i,r,!o&&e),targetTexture:this.createTexture(a,i,r),originalTexture:o||this.createTexture(a,i,r,!o&&e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:n},h=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,h),t.forEach(function(t){t&&t.applyTo(c)}),resizeCanvasIfNeeded(c),this.copyGLTo2D(a,c),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(c.sourceTexture),a.deleteTexture(c.targetTexture),a.deleteFramebuffer(h),n.getContext("2d").setTransform(1,0,0,1,0,0),c},applyFiltersDebug:function(t,e,i,r,n,s){var o=this.gl,a=this.applyFilters(t,e,i,r,n,s),c=o.getError();if(c!==o.NO_ERROR){var h=this.glErrorToString(o,c),l=new Error("WebGL Error "+h);throw l.glErrorCode=c,l}return a},glErrorToString:function(t,e){if(!t)return"Context undefined for error code: "+e;if("number"!=typeof e)return"Error code is not a number";switch(e){case t.NO_ERROR:return"NO_ERROR";case t.INVALID_ENUM:return"INVALID_ENUM";case t.INVALID_VALUE:return"INVALID_VALUE";case t.INVALID_OPERATION:return"INVALID_OPERATION";case t.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case t.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case t.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"UNKNOWN_ERROR"}},dispose:function(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()},clearWebGLCaches:function(){this.programCache={},this.textureCache={}},createTexture:function(t,e,i,r){var n=t.createTexture();return t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),r?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),n},getCachedTexture:function(t,e){if(this.textureCache[t])return this.textureCache[t];var i=this.createTexture(this.gl,e.width,e.height,e);return this.textureCache[t]=i,i},evictCachesForKey:function(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])},copyGLTo2D:copyGLTo2DDrawImage,captureGPUInfo:function(){if(this.gpuInfo)return this.gpuInfo;var t=this.gl,e=t.getExtension("WEBGL_debug_renderer_info"),i={renderer:"",vendor:""};if(e){var r=t.getParameter(e.UNMASKED_RENDERER_WEBGL),n=t.getParameter(e.UNMASKED_VENDOR_WEBGL);r&&(i.renderer=r.toLowerCase()),n&&(i.vendor=n.toLowerCase())}return this.gpuInfo=i,i}}}();!function(){"use strict";function t(){}var e=function(){};fabric.Canvas2dFilterBackend=t,t.prototype={evictCachesForKey:e,dispose:e,clearWebGLCaches:e,resources:{},applyFilters:function(t,e,i,r,n){var s=n.getContext("2d");s.drawImage(e,0,0,i,r);var o=s.getImageData(0,0,i,r),a=s.getImageData(0,0,i,r),c={sourceWidth:i,sourceHeight:r,imageData:o,originalEl:e,originalImageData:a,canvasEl:n,ctx:s,filterBackend:this};return t.forEach(function(t){t.applyTo(c)}),(c.imageData.width!==i||c.imageData.height!==r)&&(n.width=c.imageData.width,n.height=c.imageData.height),s.putImageData(c.imageData,0,0),c}}}();fabric.Image.filters=fabric.Image.filters||{},fabric.Image.filters.BaseFilter=fabric.util.createClass({type:"BaseFilter",vertexSource:"attribute vec2 aPosition;\nvarying vec2 vTexCoord;\nvoid main() {\nvTexCoord = aPosition;\ngl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n}",fragmentSource:"precision highp float;\nvarying vec2 vTexCoord;\nuniform sampler2D uTexture;\nvoid main() {\ngl_FragColor = texture2D(uTexture, vTexCoord);\n}",initialize:function(t){t&&this.setOptions(t)},setOptions:function(t){for(var e in t)this[e]=t[e]},createProgram:function(t,e,i){e=e||this.fragmentSource,i=i||this.vertexSource,"highp"!==fabric.webGlPrecision&&(e=e.replace(/precision highp float/g,"precision "+fabric.webGlPrecision+" float"));var r=t.createShader(t.VERTEX_SHADER);if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Vertex shader compile error for "+this.type+": "+t.getShaderInfoLog(r));var n=t.createShader(t.FRAGMENT_SHADER);if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error("Fragment shader compile error for "+this.type+": "+t.getShaderInfoLog(n));var s=t.createProgram();if(t.attachShader(s,r),t.attachShader(s,n),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))throw new Error('Shader link error for "${this.type}" '+t.getProgramInfoLog(s));var o=this.getAttributeLocations(t,s),a=this.getUniformLocations(t,s)||{};return a.uStepW=t.getUniformLocation(s,"uStepW"),a.uStepH=t.getUniformLocation(s,"uStepH"),{program:s,attributeLocations:o,uniformLocations:a}},getAttributeLocations:function(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}},getUniformLocations:function(){return{}},sendAttributeData:function(t,e,i){var r=e.aPosition,n=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,n),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW)},_setupFrameBuffer:function(t){var e,i,r=t.context;t.passes>1?(e=t.destinationWidth,i=t.destinationHeight,(t.sourceWidth!==e||t.sourceHeight!==i)&&(r.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(r,e,i)),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,t.targetTexture,0)):(r.bindFramebuffer(r.FRAMEBUFFER,null),r.finish())},_swapTextures:function(t){t.passes--,t.pass++;var e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e},isNeutralState:function(){return!1},applyTo:function(t){if(t.webgl){if(t.passes>1&&this.isNeutralState(t))return;this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)}else this.isNeutralState()||this.applyTo2d(t)},retrieveShader:function(t){return t.programCache.hasOwnProperty(this.type)||(t.programCache[this.type]=this.createProgram(t.context)),t.programCache[this.type]},applyToWebGL:function(t){var e=t.context,i=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(i.program),this.sendAttributeData(e,i.attributeLocations,t.aPosition),e.uniform1f(i.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(i.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,i.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)},bindAdditionalTexture:function(t,e,i){t.activeTexture(i),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)},unbindAdditionalTexture:function(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)},getMainParameter:function(){return this[this.mainParameter]},setMainParameter:function(t){this[this.mainParameter]=t},sendUniformData:function(){},createHelpLayer:function(t){if(!t.helpLayer){var e=document.createElement("canvas");e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}},toObject:function(){var t={type:this.type},e=this.mainParameter;return e&&(t[e]=this[e]),t},toJSON:function(){return this.toObject()}}),fabric.Image.filters.BaseFilter.fromObject=function(t,e){var i=new fabric.Image.filters[t.type](t);return e&&e(i),i};!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.ColorMatrix=r(i.BaseFilter,{type:"ColorMatrix",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vTexCoord;\nuniform mat4 uColorMatrix;\nuniform vec4 uConstants;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor *= uColorMatrix;\ncolor += uConstants;\ngl_FragColor = color;\n}",matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],mainParameter:"matrix",colorsOnly:!0,initialize:function(t){this.callSuper("initialize",t),this.matrix=this.matrix.slice(0)},isNeutralState:function(){for(var t=i.ColorMatrix,e=20;e--;)if(this.matrix[e]!==t.prototype.matrix[e])return!1;return!0},applyTo2d:function(t){var e,i,r,n,s,o=t.imageData,a=o.data,c=a.length,h=this.matrix,l=this.colorsOnly;for(s=0;c>s;s+=4)e=a[s],i=a[s+1],r=a[s+2],l?(a[s]=e*h[0]+i*h[1]+r*h[2]+255*h[4],a[s+1]=e*h[5]+i*h[6]+r*h[7]+255*h[9],a[s+2]=e*h[10]+i*h[11]+r*h[12]+255*h[14]):(n=a[s+3],a[s]=e*h[0]+i*h[1]+r*h[2]+n*h[3]+255*h[4],a[s+1]=e*h[5]+i*h[6]+r*h[7]+n*h[8]+255*h[9],a[s+2]=e*h[10]+i*h[11]+r*h[12]+n*h[13]+255*h[14],a[s+3]=e*h[15]+i*h[16]+r*h[17]+n*h[18]+255*h[19])},getUniformLocations:function(t,e){return{uColorMatrix:t.getUniformLocation(e,"uColorMatrix"),uConstants:t.getUniformLocation(e,"uConstants")}},sendUniformData:function(t,e){var i=this.matrix,r=[i[0],i[1],i[2],i[3],i[5],i[6],i[7],i[8],i[10],i[11],i[12],i[13],i[15],i[16],i[17],i[18]],n=[i[4],i[9],i[14],i[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,r),t.uniform4fv(e.uConstants,n)}}),e.Image.filters.ColorMatrix.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Brightness=r(i.BaseFilter,{type:"Brightness",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uBrightness;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor.rgb += uBrightness;\ngl_FragColor = color;\n}",brightness:0,mainParameter:"brightness",applyTo2d:function(t){if(0!==this.brightness){var e,i=t.imageData,r=i.data,n=r.length,s=Math.round(255*this.brightness);for(e=0;n>e;e+=4)r[e]=r[e]+s,r[e+1]=r[e+1]+s,r[e+2]=r[e+2]+s}},getUniformLocations:function(t,e){return{uBrightness:t.getUniformLocation(e,"uBrightness")}},sendUniformData:function(t,e){t.uniform1f(e.uBrightness,this.brightness)}}),e.Image.filters.Brightness.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,r=e.Image.filters,n=e.util.createClass;r.Convolute=n(r.BaseFilter,{type:"Convolute",opaque:!1,matrix:[0,0,0,0,1,0,0,0,0],fragmentSource:{Convolute_3_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[9];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 3.0; h+=1.0) {\nfor (float w = 0.0; w < 3.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_3_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[9];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 3.0; h+=1.0) {\nfor (float w = 0.0; w < 3.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_5_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[25];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 5.0; h+=1.0) {\nfor (float w = 0.0; w < 5.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_5_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[25];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 5.0; h+=1.0) {\nfor (float w = 0.0; w < 5.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_7_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[49];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 7.0; h+=1.0) {\nfor (float w = 0.0; w < 7.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_7_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[49];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 7.0; h+=1.0) {\nfor (float w = 0.0; w < 7.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_9_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[81];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 9.0; h+=1.0) {\nfor (float w = 0.0; w < 9.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_9_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[81];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 9.0; h+=1.0) {\nfor (float w = 0.0; w < 9.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}"},retrieveShader:function(t){var e=Math.sqrt(this.matrix.length),i=this.type+"_"+e+"_"+(this.opaque?1:0),r=this.fragmentSource[i];return t.programCache.hasOwnProperty(i)||(t.programCache[i]=this.createProgram(t.context,r)),t.programCache[i]},applyTo2d:function(t){var e,i,r,n,o,s,a,c,h,l,u,f,d,g=t.imageData,p=g.data,v=this.matrix,m=Math.round(Math.sqrt(v.length)),b=Math.floor(m/2),y=g.width,_=g.height,w=t.ctx.createImageData(y,_),x=w.data,C=this.opaque?1:0;for(u=0;_>u;u++)for(l=0;y>l;l++){for(o=4*(u*y+l),e=0,i=0,r=0,n=0,d=0;m>d;d++)for(f=0;m>f;f++)a=u+d-b,s=l+f-b,0>a||a>_||0>s||s>y||(c=4*(a*y+s),h=v[d*m+f],e+=p[c]*h,i+=p[c+1]*h,r+=p[c+2]*h,C||(n+=p[c+3]*h));x[o]=e,x[o+1]=i,x[o+2]=r,x[o+3]=C?p[o+3]:n}t.imageData=w},getUniformLocations:function(t,e){return{uMatrix:t.getUniformLocation(e,"uMatrix"),uOpaque:t.getUniformLocation(e,"uOpaque"),uHalfSize:t.getUniformLocation(e,"uHalfSize"),uSize:t.getUniformLocation(e,"uSize")}},sendUniformData:function(t,e){t.uniform1fv(e.uMatrix,this.matrix)},toObject:function(){return i(this.callSuper("toObject"),{opaque:this.opaque,matrix:this.matrix})}}),e.Image.filters.Convolute.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Grayscale=r(i.BaseFilter,{type:"Grayscale",fragmentSource:{average:"precision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat average = (color.r + color.b + color.g) / 3.0;\ngl_FragColor = vec4(average, average, average, color.a);\n}",lightness:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uMode;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 col = texture2D(uTexture, vTexCoord);\nfloat average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\ngl_FragColor = vec4(average, average, average, col.a);\n}",luminosity:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uMode;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 col = texture2D(uTexture, vTexCoord);\nfloat average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\ngl_FragColor = vec4(average, average, average, col.a);\n}"},mode:"average",mainParameter:"mode",applyTo2d:function(t){var e,i,r=t.imageData,n=r.data,o=n.length,s=this.mode;for(e=0;o>e;e+=4)"average"===s?i=(n[e]+n[e+1]+n[e+2])/3:"lightness"===s?i=(Math.min(n[e],n[e+1],n[e+2])+Math.max(n[e],n[e+1],n[e+2]))/2:"luminosity"===s&&(i=.21*n[e]+.72*n[e+1]+.07*n[e+2]),n[e]=i,n[e+1]=i,n[e+2]=i},retrieveShader:function(t){var e=this.type+"_"+this.mode;if(!t.programCache.hasOwnProperty(e)){var i=this.fragmentSource[this.mode];t.programCache[e]=this.createProgram(t.context,i)}return t.programCache[e]},getUniformLocations:function(t,e){return{uMode:t.getUniformLocation(e,"uMode")}},sendUniformData:function(t,e){var i=1;t.uniform1i(e.uMode,i)}}),e.Image.filters.Grayscale.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Invert=r(i.BaseFilter,{type:"Invert",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uInvert;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nif (uInvert == 1) {\ngl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n} else {\ngl_FragColor = color;\n}\n}",invert:!0,mainParameter:"invert",applyTo2d:function(t){if(this.invert){var e,i=t.imageData,r=i.data,n=r.length;for(e=0;n>e;e+=4)r[e]=255-r[e],r[e+1]=255-r[e+1],r[e+2]=255-r[e+2]}},getUniformLocations:function(t,e){return{uInvert:t.getUniformLocation(e,"uInvert")}},sendUniformData:function(t,e){t.uniform1i(e.uInvert,this.invert)}}),e.Image.filters.Invert.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,r=e.Image.filters,n=e.util.createClass;r.Noise=n(r.BaseFilter,{type:"Noise",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uStepH;\nuniform float uNoise;\nuniform float uSeed;\nvarying vec2 vTexCoord;\nfloat rand(vec2 co, float seed, float vScale) {\nreturn fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n}\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\ngl_FragColor = color;\n}",mainParameter:"noise",noise:0,applyTo2d:function(t){if(0!==this.noise){var e,i,r=t.imageData,n=r.data,o=n.length,s=this.noise;for(e=0,o=n.length;o>e;e+=4)i=(.5-Math.random())*s,n[e]+=i,n[e+1]+=i,n[e+2]+=i}},getUniformLocations:function(t,e){return{uNoise:t.getUniformLocation(e,"uNoise"),uSeed:t.getUniformLocation(e,"uSeed")}},sendUniformData:function(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())},toObject:function(){return i(this.callSuper("toObject"),{noise:this.noise})}}),e.Image.filters.Noise.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Pixelate=r(i.BaseFilter,{type:"Pixelate",blocksize:4,mainParameter:"blocksize",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uBlocksize;\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nfloat blockW = uBlocksize * uStepW;\nfloat blockH = uBlocksize * uStepW;\nint posX = int(vTexCoord.x / blockW);\nint posY = int(vTexCoord.y / blockH);\nfloat fposX = float(posX);\nfloat fposY = float(posY);\nvec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\nvec4 color = texture2D(uTexture, squareCoords);\ngl_FragColor = color;\n}",applyTo2d:function(t){if(1!==this.blocksize){var e,i,r,n,o,s,a,c,h,l,u,f=t.imageData,d=f.data,g=f.height,p=f.width;for(i=0;g>i;i+=this.blocksize)for(r=0;p>r;r+=this.blocksize)for(e=4*i*p+4*r,n=d[e],o=d[e+1],s=d[e+2],a=d[e+3],l=Math.min(i+this.blocksize,g),u=Math.min(r+this.blocksize,p),c=i;l>c;c++)for(h=r;u>h;h++)e=4*c*p+4*h,d[e]=n,d[e+1]=o,d[e+2]=s,d[e+3]=a}},isNeutralState:function(){return 1===this.blocksize},getUniformLocations:function(t,e){return{uBlocksize:t.getUniformLocation(e,"uBlocksize"),uStepW:t.getUniformLocation(e,"uStepW"),uStepH:t.getUniformLocation(e,"uStepH")}},sendUniformData:function(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}),e.Image.filters.Pixelate.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,r=e.Image.filters,n=e.util.createClass;r.RemoveColor=n(r.BaseFilter,{type:"RemoveColor",color:"#FFFFFF",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\ngl_FragColor = texture2D(uTexture, vTexCoord);\nif(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\ngl_FragColor.a = 0.0;\n}\n}",distance:.02,useAlpha:!1,applyTo2d:function(t){var i,r,n,o,s=t.imageData,a=s.data,c=255*this.distance,l=new e.Color(this.color).getSource(),h=[l[0]-c,l[1]-c,l[2]-c],u=[l[0]+c,l[1]+c,l[2]+c];for(i=0;i<a.length;i+=4)r=a[i],n=a[i+1],o=a[i+2],r>h[0]&&n>h[1]&&o>h[2]&&r<u[0]&&n<u[1]&&o<u[2]&&(a[i+3]=0)},getUniformLocations:function(t,e){return{uLow:t.getUniformLocation(e,"uLow"),uHigh:t.getUniformLocation(e,"uHigh")}},sendUniformData:function(t,i){var r=new e.Color(this.color).getSource(),n=parseFloat(this.distance),o=[0+r[0]/255-n,0+r[1]/255-n,0+r[2]/255-n,1],s=[r[0]/255+n,r[1]/255+n,r[2]/255+n,1];t.uniform4fv(i.uLow,o),t.uniform4fv(i.uHigh,s)},toObject:function(){return i(this.callSuper("toObject"),{color:this.color,distance:this.distance})}}),e.Image.filters.RemoveColor.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass,n={Brownie:[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0],Vintage:[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0],Kodachrome:[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0],Technicolor:[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0],Polaroid:[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],Sepia:[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0],BlackWhite:[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]};for(var o in n)i[o]=r(i.ColorMatrix,{type:o,matrix:n[o],mainParameter:!1,colorsOnly:!0}),e.Image.filters[o].fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric,i=e.Image.filters,r=e.util.createClass;i.BlendColor=r(i.BaseFilter,{type:"BlendColor",color:"#F95C63",mode:"multiply",alpha:1,fragmentSource:{multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",diff:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"if (uColor.r < 0.5) {\ngl_FragColor.r *= 2.0 * uColor.r;\n} else {\ngl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n}\nif (uColor.g < 0.5) {\ngl_FragColor.g *= 2.0 * uColor.g;\n} else {\ngl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n}\nif (uColor.b < 0.5) {\ngl_FragColor.b *= 2.0 * uColor.b;\n} else {\ngl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n}\n",tint:"gl_FragColor.rgb *= (1.0 - uColor.a);\ngl_FragColor.rgb += uColor.rgb;\n"},buildSource:function(t){return"precision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ngl_FragColor = color;\nif (color.a > 0.0) {\n"+this.fragmentSource[t]+"}\n}"},retrieveShader:function(t){var e,i=this.type+"_"+this.mode;return t.programCache.hasOwnProperty(i)||(e=this.buildSource(this.mode),t.programCache[i]=this.createProgram(t.context,e)),t.programCache[i]},applyTo2d:function(t){var i,r,n,o,s,a,c,l=t.imageData,h=l.data,u=h.length,f=1-this.alpha;c=new e.Color(this.color).getSource(),i=c[0]*this.alpha,r=c[1]*this.alpha,n=c[2]*this.alpha;for(var d=0;u>d;d+=4)switch(o=h[d],s=h[d+1],a=h[d+2],this.mode){case"multiply":h[d]=o*i/255,h[d+1]=s*r/255,h[d+2]=a*n/255;break;case"screen":h[d]=255-(255-o)*(255-i)/255,h[d+1]=255-(255-s)*(255-r)/255,h[d+2]=255-(255-a)*(255-n)/255;break;case"add":h[d]=o+i,h[d+1]=s+r,h[d+2]=a+n;break;case"diff":case"difference":h[d]=Math.abs(o-i),h[d+1]=Math.abs(s-r),h[d+2]=Math.abs(a-n);break;case"subtract":h[d]=o-i,h[d+1]=s-r,h[d+2]=a-n;break;case"darken":h[d]=Math.min(o,i),h[d+1]=Math.min(s,r),h[d+2]=Math.min(a,n);break;case"lighten":h[d]=Math.max(o,i),h[d+1]=Math.max(s,r),h[d+2]=Math.max(a,n);break;case"overlay":h[d]=128>i?2*o*i/255:255-2*(255-o)*(255-i)/255,h[d+1]=128>r?2*s*r/255:255-2*(255-s)*(255-r)/255,h[d+2]=128>n?2*a*n/255:255-2*(255-a)*(255-n)/255;break;case"exclusion":h[d]=i+o-2*i*o/255,h[d+1]=r+s-2*r*s/255,h[d+2]=n+a-2*n*a/255;break;case"tint":h[d]=i+o*f,h[d+1]=r+s*f,h[d+2]=n+a*f}},getUniformLocations:function(t,e){return{uColor:t.getUniformLocation(e,"uColor")}},sendUniformData:function(t,i){var r=new e.Color(this.color).getSource();r[0]=this.alpha*r[0]/255,r[1]=this.alpha*r[1]/255,r[2]=this.alpha*r[2]/255,r[3]=this.alpha,t.uniform4fv(i.uColor,r)},toObject:function(){return{type:this.type,color:this.color,mode:this.mode,alpha:this.alpha}}}),e.Image.filters.BlendColor.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric,i=e.Image.filters,r=e.util.createClass;i.BlendImage=r(i.BaseFilter,{type:"BlendImage",image:null,mode:"multiply",alpha:1,vertexSource:"attribute vec2 aPosition;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nuniform mat3 uTransformMatrix;\nvoid main() {\nvTexCoord = aPosition;\nvTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\ngl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n}",fragmentSource:{multiply:"precision highp float;\nuniform sampler2D uTexture;\nuniform sampler2D uImage;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec4 color2 = texture2D(uImage, vTexCoord2);\ncolor.rgba *= color2.rgba;\ngl_FragColor = color;\n}",mask:"precision highp float;\nuniform sampler2D uTexture;\nuniform sampler2D uImage;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec4 color2 = texture2D(uImage, vTexCoord2);\ncolor.a = color2.a;\ngl_FragColor = color;\n}"},retrieveShader:function(t){var e=this.type+"_"+this.mode,i=this.fragmentSource[this.mode];return t.programCache.hasOwnProperty(e)||(t.programCache[e]=this.createProgram(t.context,i)),t.programCache[e]},applyToWebGL:function(t){var e=t.context,i=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,i,e.TEXTURE1),this.callSuper("applyToWebGL",t),this.unbindAdditionalTexture(e,e.TEXTURE1)},createTexture:function(t,e){return t.getCachedTexture(e.cacheKey,e._element)},calculateMatrix:function(){var t=this.image,e=t._element.width,i=t._element.height;return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/i,1]},applyTo2d:function(t){var e,i,r,n,o,s,a,c,l,h,u,f=t.imageData,d=t.filterBackend.resources,g=f.data,p=g.length,v=t.imageData.width,m=t.imageData.height,b=this.image;d.blendImage||(d.blendImage=document.createElement("canvas")),l=d.blendImage,(l.width!==v||l.height!==m)&&(l.width=v,l.height=m),h=l.getContext("2d"),h.setTransform(b.scaleX,0,0,b.scaleY,b.left,b.top),h.drawImage(b._element,0,0,v,m),u=h.getImageData(0,0,v,m).data;for(var y=0;p>y;y+=4)switch(o=g[y],s=g[y+1],a=g[y+2],c=g[y+3],e=u[y],i=u[y+1],r=u[y+2],n=u[y+3],this.mode){case"multiply":g[y]=o*e/255,g[y+1]=s*i/255,g[y+2]=a*r/255,g[y+3]=c*n/255;break;case"mask":g[y+3]=n}},getUniformLocations:function(t,e){return{uTransformMatrix:t.getUniformLocation(e,"uTransformMatrix"),uImage:t.getUniformLocation(e,"uImage")}},sendUniformData:function(t,e){var i=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,i)},toObject:function(){return{type:this.type,image:this.image&&this.image.toObject(),mode:this.mode,alpha:this.alpha}}}),e.Image.filters.BlendImage.fromObject=function(t,i){e.Image.fromObject(t.image,function(r){var n=e.util.object.clone(t);n.image=r,i(new e.Image.filters.BlendImage(n))})}}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=Math.pow,r=Math.floor,n=Math.sqrt,o=Math.abs,s=Math.round,a=Math.sin,c=Math.ceil,l=e.Image.filters,h=e.util.createClass;l.Resize=h(l.BaseFilter,{type:"Resize",resizeType:"hermite",scaleX:0,scaleY:0,lanczosLobes:3,getUniformLocations:function(t,e){return{uDelta:t.getUniformLocation(e,"uDelta"),uTaps:t.getUniformLocation(e,"uTaps")}},sendUniformData:function(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)},retrieveShader:function(t){var e=this.getFilterWindow(),i=this.type+"_"+e;if(!t.programCache.hasOwnProperty(i)){var r=this.generateShader(e);t.programCache[i]=this.createProgram(t.context,r)}return t.programCache[i]},getFilterWindow:function(){var t=this.tempScale;return Math.ceil(this.lanczosLobes/t)},getTaps:function(){for(var t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,i=this.getFilterWindow(),r=new Array(i),n=1;i>=n;n++)r[n-1]=t(n*e);return r},generateShader:function(t){for(var t,e=new Array(t),i=this.fragmentSourceTOP,r=1;t>=r;r++)e[r-1]=r+".0 * uDelta";return i+="uniform float uTaps["+t+"];\n",i+="void main() {\n",i+=" vec4 color = texture2D(uTexture, vTexCoord);\n",i+=" float sum = 1.0;\n",e.forEach(function(t,e){i+=" color += texture2D(uTexture, vTexCoord + "+t+") * uTaps["+e+"];\n",i+=" color += texture2D(uTexture, vTexCoord - "+t+") * uTaps["+e+"];\n",i+=" sum += 2.0 * uTaps["+e+"];\n"}),i+=" gl_FragColor = color / sum;\n",i+="}"},fragmentSourceTOP:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec2 uDelta;\nvarying vec2 vTexCoord;\n",applyTo:function(t){if(t.webgl){if(t.passes>1&&this.isNeutralState(t))return;t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceHeight=t.destinationHeight}else this.isNeutralState(t)||this.applyTo2d(t)},isNeutralState:function(t){var e=t.scaleX||this.scaleX,i=t.scaleY||this.scaleY;return 1===e&&1===i},lanczosCreate:function(t){return function(e){if(e>=t||-t>=e)return 0;if(1.1920929e-7>e&&e>-1.1920929e-7)return 1;e*=Math.PI;var i=e/t;return a(e)/e*a(i)/i}},applyTo2d:function(t){var e=t.imageData,i=this.scaleX,r=this.scaleY;this.rcpScaleX=1/i,this.rcpScaleY=1/r;var n,o=e.width,a=e.height,c=s(o*i),l=s(a*r);"sliceHack"===this.resizeType?n=this.sliceByTwo(t,o,a,c,l):"hermite"===this.resizeType?n=this.hermiteFastResize(t,o,a,c,l):"bilinear"===this.resizeType?n=this.bilinearFiltering(t,o,a,c,l):"lanczos"===this.resizeType&&(n=this.lanczosResize(t,o,a,c,l)),t.imageData=n},sliceByTwo:function(t,i,n,o,s){var a,c,l=t.imageData,h=.5,u=!1,f=!1,d=i*h,g=n*h,p=e.filterBackend.resources,v=0,m=0,b=i,y=0;for(p.sliceByTwo||(p.sliceByTwo=document.createElement("canvas")),a=p.sliceByTwo,(a.width<1.5*i||a.height<n)&&(a.width=1.5*i,a.height=n),c=a.getContext("2d"),c.clearRect(0,0,1.5*i,n),c.putImageData(l,0,0),o=r(o),s=r(s);!u||!f;)i=d,n=g,o<r(d*h)?d=r(d*h):(d=o,u=!0),s<r(g*h)?g=r(g*h):(g=s,f=!0),c.drawImage(a,v,m,i,n,b,y,d,g),v=b,m=y,y+=g;return c.getImageData(v,m,o,s)},lanczosResize:function(t,e,s,a,l){function h(t){var c,T,S,O,j,P,k,E,D,F,M;for(C.x=(t+.5)*p,w.x=r(C.x),c=0;l>c;c++){for(C.y=(c+.5)*v,w.y=r(C.y),j=0,P=0,k=0,E=0,D=0,T=w.x-y;T<=w.x+y;T++)if(!(0>T||T>=e)){F=r(1e3*o(T-C.x)),x[F]||(x[F]={});for(var A=w.y-_;A<=w.y+_;A++)0>A||A>=s||(M=r(1e3*o(A-C.y)),x[F][M]||(x[F][M]=g(n(i(F*m,2)+i(M*b,2))/1e3)),S=x[F][M],S>0&&(O=4*(A*e+T),j+=S,P+=S*u[O],k+=S*u[O+1],E+=S*u[O+2],D+=S*u[O+3]))}O=4*(c*a+t),d[O]=P/j,d[O+1]=k/j,d[O+2]=E/j,d[O+3]=D/j}return++t<a?h(t):f}var u=t.imageData.data,f=t.ctx.createImageData(a,l),d=f.data,g=this.lanczosCreate(this.lanczosLobes),p=this.rcpScaleX,v=this.rcpScaleY,m=2/this.rcpScaleX,b=2/this.rcpScaleY,y=c(p*this.lanczosLobes/2),_=c(v*this.lanczosLobes/2),x={},C={},w={};return h(0)},bilinearFiltering:function(t,e,i,n,o){var s,a,c,l,h,u,f,d,g,p,v,m,b,y=0,_=this.rcpScaleX,x=this.rcpScaleY,C=4*(e-1),w=t.imageData,T=w.data,S=t.ctx.createImageData(n,o),O=S.data;for(f=0;o>f;f++)for(d=0;n>d;d++)for(h=r(_*d),u=r(x*f),g=_*d-h,p=x*f-u,b=4*(u*e+h),v=0;4>v;v++)s=T[b+v],a=T[b+4+v],c=T[b+C+v],l=T[b+C+4+v],m=s*(1-g)*(1-p)+a*g*(1-p)+c*p*(1-g)+l*g*p,O[y++]=m;return S},hermiteFastResize:function(t,e,i,s,a){for(var l=this.rcpScaleX,h=this.rcpScaleY,u=c(l/2),f=c(h/2),d=t.imageData,g=d.data,p=t.ctx.createImageData(s,a),v=p.data,m=0;a>m;m++)for(var b=0;s>b;b++){for(var y=4*(b+m*s),_=0,x=0,C=0,w=0,T=0,S=0,O=0,j=(m+.5)*h,P=r(m*h);(m+1)*h>P;P++)for(var k=o(j-(P+.5))/f,E=(b+.5)*l,D=k*k,F=r(b*l);(b+1)*l>F;F++){var M=o(E-(F+.5))/u,A=n(D+M*M);A>1&&-1>A||(_=2*A*A*A-3*A*A+1,_>0&&(M=4*(F+P*e),O+=_*g[M+3],C+=_,g[M+3]<255&&(_=_*g[M+3]/250),w+=_*g[M],T+=_*g[M+1],S+=_*g[M+2],x+=_))}v[y]=w/x,v[y+1]=T/x,v[y+2]=S/x,v[y+3]=O/C}return p},toObject:function(){return{type:this.type,scaleX:this.scaleX,scaleY:this.scaleY,resizeType:this.resizeType,lanczosLobes:this.lanczosLobes}}}),e.Image.filters.Resize.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Contrast=r(i.BaseFilter,{type:"Contrast",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uContrast;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\ncolor.rgb = contrastF * (color.rgb - 0.5) + 0.5;\ngl_FragColor = color;\n}",contrast:0,mainParameter:"contrast",applyTo2d:function(t){if(0!==this.contrast){var e,i,r=t.imageData,n=r.data,i=n.length,o=Math.floor(255*this.contrast),s=259*(o+255)/(255*(259-o));for(e=0;i>e;e+=4)n[e]=s*(n[e]-128)+128,n[e+1]=s*(n[e+1]-128)+128,n[e+2]=s*(n[e+2]-128)+128}},getUniformLocations:function(t,e){return{uContrast:t.getUniformLocation(e,"uContrast")}},sendUniformData:function(t,e){t.uniform1f(e.uContrast,this.contrast)}}),e.Image.filters.Contrast.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Saturation=r(i.BaseFilter,{type:"Saturation",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uSaturation;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat rgMax = max(color.r, color.g);\nfloat rgbMax = max(rgMax, color.b);\ncolor.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\ncolor.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\ncolor.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\ngl_FragColor = color;\n}",saturation:0,mainParameter:"saturation",applyTo2d:function(t){if(0!==this.saturation){var e,i,r=t.imageData,n=r.data,o=n.length,s=-this.saturation;for(e=0;o>e;e+=4)i=Math.max(n[e],n[e+1],n[e+2]),n[e]+=i!==n[e]?(i-n[e])*s:0,n[e+1]+=i!==n[e+1]?(i-n[e+1])*s:0,n[e+2]+=i!==n[e+2]?(i-n[e+2])*s:0}},getUniformLocations:function(t,e){return{uSaturation:t.getUniformLocation(e,"uSaturation")}},sendUniformData:function(t,e){t.uniform1f(e.uSaturation,-this.saturation)}}),e.Image.filters.Saturation.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Blur=r(i.BaseFilter,{type:"Blur",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec2 uDelta;\nvarying vec2 vTexCoord;\nconst float nSamples = 15.0;\nvec3 v3offset = vec3(12.9898, 78.233, 151.7182);\nfloat random(vec3 scale) {\nreturn fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n}\nvoid main() {\nvec4 color = vec4(0.0);\nfloat total = 0.0;\nfloat offset = random(v3offset);\nfor (float t = -nSamples; t <= nSamples; t++) {\nfloat percent = (t + offset - 0.5) / nSamples;\nfloat weight = 1.0 - abs(percent);\ncolor += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;\ntotal += weight;\n}\ngl_FragColor = color / total;\n}",blur:0,mainParameter:"blur",applyTo:function(t){t.webgl?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)},applyTo2d:function(t){t.imageData=this.simpleBlur(t)},simpleBlur:function(t){var i,r,n=t.filterBackend.resources,o=t.imageData.width,s=t.imageData.height;n.blurLayer1||(n.blurLayer1=e.util.createCanvasElement(),n.blurLayer2=e.util.createCanvasElement()),i=n.blurLayer1,r=n.blurLayer2,(i.width!==o||i.height!==s)&&(r.width=i.width=o,r.height=i.height=s);var a,c,l,h,u=i.getContext("2d"),f=r.getContext("2d"),d=15,g=.06*this.blur*.5;for(u.putImageData(t.imageData,0,0),f.clearRect(0,0,o,s),h=-d;d>=h;h++)a=(Math.random()-.5)/4,c=h/d,l=g*c*o+a,f.globalAlpha=1-Math.abs(c),f.drawImage(i,l,a),u.drawImage(r,0,0),f.globalAlpha=1,f.clearRect(0,0,r.width,r.height);for(h=-d;d>=h;h++)a=(Math.random()-.5)/4,c=h/d,l=g*c*s+a,f.globalAlpha=1-Math.abs(c),f.drawImage(i,a,l),u.drawImage(r,0,0),f.globalAlpha=1,f.clearRect(0,0,r.width,r.height);t.ctx.drawImage(i,0,0);var p=t.ctx.getImageData(0,0,i.width,i.height);return u.globalAlpha=1,u.clearRect(0,0,i.width,i.height),p},getUniformLocations:function(t,e){return{delta:t.getUniformLocation(e,"uDelta")}},sendUniformData:function(t,e){var i=this.chooseRightDelta();t.uniform2fv(e.delta,i)},chooseRightDelta:function(){var t,e=1,i=[0,0];return this.horizontal?this.aspectRatio>1&&(e=1/this.aspectRatio):this.aspectRatio<1&&(e=this.aspectRatio),t=e*this.blur*.12,this.horizontal?i[0]=t:i[1]=t,i}}),i.Blur.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Gamma=r(i.BaseFilter,{type:"Gamma",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec3 uGamma;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec3 correction = (1.0 / uGamma);\ncolor.r = pow(color.r, correction.r);\ncolor.g = pow(color.g, correction.g);\ncolor.b = pow(color.b, correction.b);\ngl_FragColor = color;\ngl_FragColor.rgb *= color.a;\n}",gamma:[1,1,1],mainParameter:"gamma",applyTo2d:function(t){var e,i=t.imageData,r=i.data,n=this.gamma,o=r.length,s=1/n[0],a=1/n[1],c=1/n[2];for(this.rVals||(this.rVals=new Uint8Array(256),this.gVals=new Uint8Array(256),this.bVals=new Uint8Array(256)),e=0,o=256;o>e;e++)this.rVals[e]=255*Math.pow(e/255,s),this.gVals[e]=255*Math.pow(e/255,a),this.bVals[e]=255*Math.pow(e/255,c);for(e=0,o=r.length;o>e;e+=4)r[e]=this.rVals[r[e]],r[e+1]=this.gVals[r[e+1]],r[e+2]=this.bVals[r[e+2]]},getUniformLocations:function(t,e){return{uGamma:t.getUniformLocation(e,"uGamma")}},sendUniformData:function(t,e){t.uniform3fv(e.uGamma,this.gamma)}}),e.Image.filters.Gamma.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.Composed=r(i.BaseFilter,{type:"Composed",subFilters:[],initialize:function(t){this.callSuper("initialize",t),this.subFilters=this.subFilters.slice(0)},applyTo:function(t){t.passes+=this.subFilters.length-1,this.subFilters.forEach(function(e){e.applyTo(t)})},toObject:function(){return e.util.object.extend(this.callSuper("toObject"),{subFilters:this.subFilters.map(function(t){return t.toObject()})})}}),e.Image.filters.Composed.fromObject=function(t,i){var r=t.subFilters||[],n=r.map(function(t){return new e.Image.filters[t.type](t)}),o=new e.Image.filters.Composed({subFilters:n});return i&&i(o),o}}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.Image.filters,r=e.util.createClass;i.HueRotation=r(i.ColorMatrix,{type:"HueRotation",rotation:0,mainParameter:"rotation",calculateMatrix:function(){var t=this.rotation*Math.PI,i=e.util.cos(t),r=e.util.sin(t),n=1/3,o=Math.sqrt(n)*r,s=1-i;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=i+s/3,this.matrix[1]=n*s-o,this.matrix[2]=n*s+o,this.matrix[5]=n*s+o,this.matrix[6]=i+n*s,this.matrix[7]=n*s-o,this.matrix[10]=n*s-o,this.matrix[11]=n*s+o,this.matrix[12]=i+n*s},applyTo:function(t){this.calculateMatrix(),e.Image.filters.BaseFilter.prototype.applyTo.call(this,t)}}),e.Image.filters.HueRotation.fromObject=e.Image.filters.BaseFilter.fromObject}("undefined"!=typeof exports?exports:this);!function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.clone;return e.Text?void e.warn("fabric.Text is already defined"):(e.Text=e.util.createClass(e.Object,{_dimensionAffectingProps:["fontSize","fontWeight","fontFamily","fontStyle","lineHeight","text","charSpacing","textAlign","styles"],_reNewline:/\r?\n/,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,type:"text",fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:"left",fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stateProperties:e.Object.prototype.stateProperties.concat("fontFamily","fontWeight","fontSize","text","underline","overline","linethrough","textAlign","fontStyle","lineHeight","textBackgroundColor","charSpacing","styles"),cacheProperties:e.Object.prototype.cacheProperties.concat("fontFamily","fontWeight","fontSize","text","underline","overline","linethrough","textAlign","fontStyle","lineHeight","textBackgroundColor","charSpacing","styles"),stroke:null,shadow:null,_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,styles:null,_measuringContext:null,deltaY:0,_styleProperties:["stroke","strokeWidth","fill","fontFamily","fontSize","fontWeight","fontStyle","underline","overline","linethrough","deltaY","textBackgroundColor"],__charBounds:[],CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,initialize:function(t,e){this.styles=e?e.styles||{}:{},this.text=t,this.__skipDimension=!0,this.callSuper("initialize",e),this.__skipDimension=!1,this.initDimensions(),this.setCoords(),this.setupState({propertySet:"_dimensionAffectingProps"})},getMeasuringContext:function(){return e._measuringContext||(e._measuringContext=this.canvas&&this.canvas.contextCache||e.util.createCanvasElement().getContext("2d")),e._measuringContext},_splitText:function(){var t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t},initDimensions:function(){this.__skipDimension||(this._splitText(),this._clearCache(),this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight(),this.saveState({propertySet:"_dimensionAffectingProps"}))},enlargeSpaces:function(){for(var t,e,i,r,n,o,s,a=0,c=this._textLines.length;c>a;a++)if(("justify"===this.textAlign||a!==c-1&&!this.isEndOfWrapping(a))&&(r=0,n=this._textLines[a],e=this.getLineWidth(a),e<this.width&&(s=this.textLines[a].match(this._reSpacesAndTabs)))){i=s.length,t=(this.width-e)/i;for(var l=0,h=n.length;h>=l;l++)o=this.__charBounds[a][l],this._reSpaceAndTab.test(n[l])?(o.width+=t,o.kernedWidth+=t,o.left+=r,r+=t):o.left+=r}},isEndOfWrapping:function(t){return t===this._textLines.length-1},toString:function(){return"#<fabric.Text ("+this.complexity()+'): { "text": "'+this.text+'", "fontFamily": "'+this.fontFamily+'" }>'},_getCacheCanvasDimensions:function(){var t=this.callSuper("_getCacheCanvasDimensions"),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t},_render:function(t){this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")},_renderText:function(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))},_setTextStyles:function(t,e,i){t.textBaseline="alphabetic",t.font=this._getFontDeclaration(e,i)},calcTextWidth:function(){for(var t=this.getLineWidth(0),e=1,i=this._textLines.length;i>e;e++){var r=this.getLineWidth(e);r>t&&(t=r)}return t},_renderTextLine:function(t,e,i,r,n,o){this._renderChars(t,e,i,r,n,o)},_renderTextLinesBackground:function(t){if(this.textBackgroundColor||this.styleHas("textBackgroundColor")){for(var e,i,r,n,o,s,a=0,c=t.fillStyle,l=this._getLeftOffset(),h=this._getTopOffset(),u=0,f=0,d=0,g=this._textLines.length;g>d;d++)if(e=this.getHeightOfLine(d),this.textBackgroundColor||this.styleHas("textBackgroundColor",d)){r=this._textLines[d],i=this._getLineLeftOffset(d),f=0,u=0,n=this.getValueOfPropertyAt(d,0,"textBackgroundColor");for(var p=0,v=r.length;v>p;p++)o=this.__charBounds[d][p],s=this.getValueOfPropertyAt(d,p,"textBackgroundColor"),s!==n?(t.fillStyle=n,n&&t.fillRect(l+i+u,h+a,f,e/this.lineHeight),u=o.left,f=o.width,n=s):f+=o.kernedWidth;s&&(t.fillStyle=s,t.fillRect(l+i+u,h+a,f,e/this.lineHeight)),a+=e}else a+=e;t.fillStyle=c,this._removeShadow(t)}},getFontCache:function(t){var i=t.fontFamily.toLowerCase();e.charWidthsCache[i]||(e.charWidthsCache[i]={});var r=e.charWidthsCache[i],n=t.fontStyle.toLowerCase()+"_"+(t.fontWeight+"").toLowerCase();return r[n]||(r[n]={}),r[n]},_applyCharStyles:function(t,e,i,r,n){this._setFillStyles(e,n),this._setStrokeStyles(e,n),e.font=this._getFontDeclaration(n)},_measureChar:function(t,e,i,r){var n,o,s,a,c=this.getFontCache(e),l=this._getFontDeclaration(e),h=this._getFontDeclaration(r),u=i+t,f=l===h,d=e.fontSize/this.CACHE_FONT_SIZE;if(i&&void 0!==c[i]&&(s=c[i]),void 0!==c[t]&&(a=n=c[t]),f&&void 0!==c[u]&&(o=c[u],a=o-s),void 0===n||void 0===s||void 0===o){var g=this.getMeasuringContext();this._setTextStyles(g,e,!0)}return void 0===n&&(a=n=g.measureText(t).width,c[t]=n),void 0===s&&f&&i&&(s=g.measureText(i).width,c[i]=s),f&&void 0===o&&(o=g.measureText(u).width,c[u]=o,a=o-s),{width:n*d,kernedWidth:a*d}},getHeightOfChar:function(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")},measureLine:function(t){var e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e},_measureLine:function(t){var e,i,r,n,o=0,s=this._textLines[t],a=0,c=new Array(s.length);for(this.__charBounds[t]=c,e=0;e<s.length;e++)i=s[e],n=this._getGraphemeBox(i,t,e,r),c[e]=n,o+=n.kernedWidth,r=i;return c[e]={left:n?n.left+n.width:0,width:0,kernedWidth:0,height:this.fontSize},{width:o,numOfSpaces:a}},_getGraphemeBox:function(t,e,i,r,n){var o,s=this.getCompleteStyleDeclaration(e,i),a=r?this.getCompleteStyleDeclaration(e,i-1):{},c=this._measureChar(t,s,r,a),l=c.kernedWidth,h=c.width;0!==this.charSpacing&&(o=this._getWidthOfCharSpacing(),h+=o,l+=o);var u={width:h,left:0,height:s.fontSize,kernedWidth:l,deltaY:s.deltaY};if(i>0&&!n){var f=this.__charBounds[e][i-1];u.left=f.left+f.width+c.kernedWidth-c.width}return u},getHeightOfLine:function(t){if(this.__lineHeights[t])return this.__lineHeights[t];for(var e=this._textLines[t],i=this.getHeightOfChar(t,0),r=1,n=e.length;n>r;r++)i=Math.max(this.getHeightOfChar(t,r),i);return this.__lineHeights[t]=i*this.lineHeight*this._fontSizeMult},calcTextHeight:function(){for(var t,e=0,i=0,r=this._textLines.length;r>i;i++)t=this.getHeightOfLine(i),e+=i===r-1?t/this.lineHeight:t;return e},_getLeftOffset:function(){return-this.width/2},_getTopOffset:function(){return-this.height/2},_renderTextCommon:function(t,e){t.save();for(var i=0,r=this._getLeftOffset(),n=this._getTopOffset(),o=this._applyPatternGradientTransform(t,"fillText"===e?this.fill:this.stroke),s=0,a=this._textLines.length;a>s;s++){var c=this.getHeightOfLine(s),l=c/this.lineHeight,h=this._getLineLeftOffset(s);this._renderTextLine(e,t,this._textLines[s],r+h-o.offsetX,n+i+l-o.offsetY,s),i+=c}t.restore()},_renderTextFill:function(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")},_renderTextStroke:function(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())},_renderChars:function(t,e,i,r,n,o){var s,a,c,l,h=this.getHeightOfLine(o),u=-1!==this.textAlign.indexOf("justify"),f="",d=0,g=!u&&0===this.charSpacing&&this.isEmptyStyles(o);if(e.save(),n-=h*this._fontSizeFraction/this.lineHeight,g)return this._renderChar(t,e,o,0,this.textLines[o],r,n,h),void e.restore();for(var p=0,v=i.length-1;v>=p;p++)l=p===v||this.charSpacing,f+=i[p],c=this.__charBounds[o][p],0===d?(r+=c.kernedWidth-c.width,d+=c.width):d+=c.kernedWidth,u&&!l&&this._reSpaceAndTab.test(i[p])&&(l=!0),l||(s=s||this.getCompleteStyleDeclaration(o,p),a=this.getCompleteStyleDeclaration(o,p+1),l=this._hasStyleChanged(s,a)),l&&(this._renderChar(t,e,o,p,f,r,n,h),f="",s=a,r+=d,d=0);e.restore()},_renderChar:function(t,e,i,r,n,o,s){var a=this._getStyleDeclaration(i,r),c=this.getCompleteStyleDeclaration(i,r),l="fillText"===t&&c.fill,h="strokeText"===t&&c.stroke&&c.strokeWidth;(h||l)&&(a&&e.save(),this._applyCharStyles(t,e,i,r,c),a&&a.textBackgroundColor&&this._removeShadow(e),a&&a.deltaY&&(s+=a.deltaY),l&&e.fillText(n,o,s),h&&e.strokeText(n,o,s),a&&e.restore())},setSuperscript:function(t,e){return this._setScript(t,e,this.superscript)},setSubscript:function(t,e){return this._setScript(t,e,this.subscript)},_setScript:function(t,e,i){var r=this.get2DCursorLocation(t,!0),n=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"fontSize"),o=this.getValueOfPropertyAt(r.lineIndex,r.charIndex,"deltaY"),s={fontSize:n*i.size,deltaY:o+n*i.baseline};return this.setSelectionStyles(s,t,e),this},_hasStyleChanged:function(t,e){return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.deltaY!==e.deltaY},_hasStyleChangedForSvg:function(t,e){return this._hasStyleChanged(t,e)||t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough},_getLineLeftOffset:function(t){var e=this.getLineWidth(t);return"center"===this.textAlign?(this.width-e)/2:"right"===this.textAlign?this.width-e:"justify-center"===this.textAlign&&this.isEndOfWrapping(t)?(this.width-e)/2:"justify-right"===this.textAlign&&this.isEndOfWrapping(t)?this.width-e:0},_clearCache:function(){this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]},_shouldClearDimensionCache:function(){var t=this._forceClearCache;return t||(t=this.hasStateChanged("_dimensionAffectingProps")),t&&(this.dirty=!0,this._forceClearCache=!1),t},getLineWidth:function(t){if(this.__lineWidths[t])return this.__lineWidths[t];var e,i,r=this._textLines[t];return""===r?e=0:(i=this.measureLine(t),e=i.width),this.__lineWidths[t]=e,e},_getWidthOfCharSpacing:function(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0},getValueOfPropertyAt:function(t,e,i){var r=this._getStyleDeclaration(t,e);return r&&"undefined"!=typeof r[i]?r[i]:this[i]},_renderTextDecoration:function(t,e){if(this[e]||this.styleHas(e)){for(var i,r,n,o,s,a,c,l,h,u,f,d,g,p,v,m,b=this._getLeftOffset(),y=this._getTopOffset(),_=this._getWidthOfCharSpacing(),x=0,C=this._textLines.length;C>x;x++)if(i=this.getHeightOfLine(x),this[e]||this.styleHas(e,x)){c=this._textLines[x],p=i/this.lineHeight,o=this._getLineLeftOffset(x),u=0,f=0,l=this.getValueOfPropertyAt(x,0,e),m=this.getValueOfPropertyAt(x,0,"fill"),h=y+p*(1-this._fontSizeFraction),r=this.getHeightOfChar(x,0),s=this.getValueOfPropertyAt(x,0,"deltaY");for(var w=0,S=c.length;S>w;w++)d=this.__charBounds[x][w],g=this.getValueOfPropertyAt(x,w,e),v=this.getValueOfPropertyAt(x,w,"fill"),n=this.getHeightOfChar(x,w),a=this.getValueOfPropertyAt(x,w,"deltaY"),(g!==l||v!==m||n!==r||a!==s)&&f>0?(t.fillStyle=m,l&&m&&t.fillRect(b+o+u,h+this.offsets[e]*r+s,f,this.fontSize/15),u=d.left,f=d.width,l=g,m=v,r=n,s=a):f+=d.kernedWidth;t.fillStyle=v,g&&v&&t.fillRect(b+o+u,h+this.offsets[e]*r+s,f-_,this.fontSize/15),y+=i}else y+=i;this._removeShadow(t)}},_getFontDeclaration:function(t,i){var r=t||this,n=this.fontFamily,o=e.Text.genericFonts.indexOf(n.toLowerCase())>-1,s=void 0===n||n.indexOf("'")>-1||n.indexOf('"')>-1||o?r.fontFamily:'"'+r.fontFamily+'"';return[e.isLikelyNode?r.fontWeight:r.fontStyle,e.isLikelyNode?r.fontStyle:r.fontWeight,i?this.CACHE_FONT_SIZE+"px":r.fontSize+"px",s].join(" ")},render:function(t){this.visible&&(!this.canvas||!this.canvas.skipOffscreen||this.group||this.isOnScreen())&&(this._shouldClearDimensionCache()&&this.initDimensions(),this.callSuper("render",t))},_splitTextIntoLines:function(t){for(var i=t.split(this._reNewline),r=new Array(i.length),n=["\n"],o=[],s=0;s<i.length;s++)r[s]=e.util.string.graphemeSplit(i[s]),o=o.concat(r[s],n);return o.pop(),{_unwrappedLines:r,lines:i,graphemeText:o,graphemeLines:r}},toObject:function(t){var e=["text","fontSize","fontWeight","fontFamily","fontStyle","lineHeight","underline","overline","linethrough","textAlign","textBackgroundColor","charSpacing"].concat(t),r=this.callSuper("toObject",e);return r.styles=i(this.styles,!0),r},set:function(t,e){this.callSuper("set",t,e);var i=!1;if("object"==typeof t)for(var r in t)i=i||-1!==this._dimensionAffectingProps.indexOf(r);else i=-1!==this._dimensionAffectingProps.indexOf(t);return i&&(this.initDimensions(),this.setCoords()),this},complexity:function(){return 1}}),e.Text.fromObject=function(t,i){return e.Object._fromObject("Text",t,i,"text")},e.Text.genericFonts=["sans-serif","serif","cursive","fantasy","monospace"],void(e.util.createAccessors&&e.util.createAccessors(e.Text)))}("undefined"!=typeof exports?exports:this);!function(){fabric.util.object.extend(fabric.Text.prototype,{isEmptyStyles:function(t){if(!this.styles)return!0;if("undefined"!=typeof t&&!this.styles[t])return!0;var e="undefined"==typeof t?this.styles:{line:this.styles[t]};for(var i in e)for(var r in e[i])for(var n in e[i][r])return!1;return!0},styleHas:function(t,e){if(!this.styles||!t||""===t)return!1;if("undefined"!=typeof e&&!this.styles[e])return!1;var i="undefined"==typeof e?this.styles:{line:this.styles[e]};for(var r in i)for(var n in i[r])if("undefined"!=typeof i[r][n][t])return!0;return!1},cleanStyle:function(t){if(!this.styles||!t||""===t)return!1;var e,i,r,n=this.styles,o=0,s=!0,a=0;for(var c in n){e=0;for(var l in n[c]){var r=n[c][l],h=r.hasOwnProperty(t);o++,h?(i?r[t]!==i&&(s=!1):i=r[t],r[t]===this[t]&&delete r[t]):s=!1,0!==Object.keys(r).length?e++:delete n[c][l]}0===e&&delete n[c]}for(var u=0;u<this._textLines.length;u++)a+=this._textLines[u].length;s&&o===a&&(this[t]=i,this.removeStyle(t))},removeStyle:function(t){if(this.styles&&t&&""!==t){var e,i,r,n=this.styles;for(i in n){e=n[i];for(r in e)delete e[r][t],0===Object.keys(e[r]).length&&delete e[r];0===Object.keys(e).length&&delete n[i]}}},_extendStyles:function(t,e){var i=this.get2DCursorLocation(t);this._getLineStyle(i.lineIndex)||this._setLineStyle(i.lineIndex,{}),this._getStyleDeclaration(i.lineIndex,i.charIndex)||this._setStyleDeclaration(i.lineIndex,i.charIndex,{}),fabric.util.object.extend(this._getStyleDeclaration(i.lineIndex,i.charIndex),e)},get2DCursorLocation:function(t,e){"undefined"==typeof t&&(t=this.selectionStart);for(var i=e?this._unwrappedTextLines:this._textLines,r=i.length,n=0;r>n;n++){if(t<=i[n].length)return{lineIndex:n,charIndex:t};t-=i[n].length+1}return{lineIndex:n-1,charIndex:i[n-1].length<t?i[n-1].length:t}},getSelectionStyles:function(t,e,i){"undefined"==typeof t&&(t=this.selectionStart||0),"undefined"==typeof e&&(e=this.selectionEnd||t);for(var r=[],n=t;e>n;n++)r.push(this.getStyleAtPosition(n,i));return r},getStyleAtPosition:function(t,e){var i=this.get2DCursorLocation(t),r=e?this.getCompleteStyleDeclaration(i.lineIndex,i.charIndex):this._getStyleDeclaration(i.lineIndex,i.charIndex);return r||{}},setSelectionStyles:function(t,e,i){"undefined"==typeof e&&(e=this.selectionStart||0),"undefined"==typeof i&&(i=this.selectionEnd||e);for(var r=e;i>r;r++)this._extendStyles(r,t);return this._forceClearCache=!0,this},_getStyleDeclaration:function(t,e){var i=this.styles&&this.styles[t];return i?i[e]:null},getCompleteStyleDeclaration:function(t,e){for(var i,r=this._getStyleDeclaration(t,e)||{},n={},o=0;o<this._styleProperties.length;o++)i=this._styleProperties[o],n[i]="undefined"==typeof r[i]?this[i]:r[i];return n},_setStyleDeclaration:function(t,e,i){this.styles[t][e]=i},_deleteStyleDeclaration:function(t,e){delete this.styles[t][e]},_getLineStyle:function(t){return this.styles[t]},_setLineStyle:function(t,e){this.styles[t]=e},_deleteLineStyle:function(t){delete this.styles[t]}})}();!function(){function t(t){t.textDecoration&&(t.textDecoration.indexOf("underline")>-1&&(t.underline=!0),t.textDecoration.indexOf("line-through")>-1&&(t.linethrough=!0),t.textDecoration.indexOf("overline")>-1&&(t.overline=!0),delete t.textDecoration)}fabric.IText=fabric.util.createClass(fabric.Text,fabric.Observable,{type:"i-text",selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"#333",cursorDelay:1e3,cursorDuration:600,caching:!0,_reSpace:/\s|\n/,_currentCursorOpacity:0,_selectionDirection:null,_abortCursorAnimation:!1,__widthOfSpace:[],inCompositionMode:!1,initialize:function(t,e){this.callSuper("initialize",t,e),this.initBehavior()},setSelectionStart:function(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)},setSelectionEnd:function(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)},_updateAndFire:function(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()},_fireSelectionChanged:function(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})},initDimensions:function(){this.isEditing&&this.initDelayedCursor(),this.clearContextTop(),this.callSuper("initDimensions")},render:function(t){this.clearContextTop(),this.callSuper("render",t),this.cursorOffsetCache={},this.renderCursorOrSelection()},_render:function(t){this.callSuper("_render",t)},clearContextTop:function(t){if(this.isEditing&&this.canvas&&this.canvas.contextTop){var e=this.canvas.contextTop,i=this.canvas.viewportTransform;e.save(),e.transform(i[0],i[1],i[2],i[3],i[4],i[5]),this.transform(e),this.transformMatrix&&e.transform.apply(e,this.transformMatrix),this._clearTextArea(e),t||e.restore()}},renderCursorOrSelection:function(){if(this.isEditing&&this.canvas){var t,e=this._getCursorBoundaries();this.canvas&&this.canvas.contextTop?(t=this.canvas.contextTop,this.clearContextTop(!0)):(t=this.canvas.contextContainer,t.save()),this.selectionStart===this.selectionEnd?this.renderCursor(e,t):this.renderSelection(e,t),t.restore()}},_clearTextArea:function(t){var e=this.width+4,i=this.height+4;t.clearRect(-e/2,-i/2,e,i)},_getCursorBoundaries:function(t){"undefined"==typeof t&&(t=this.selectionStart);var e=this._getLeftOffset(),i=this._getTopOffset(),r=this._getCursorBoundariesOffsets(t);return{left:e,top:i,leftOffset:r.left,topOffset:r.top}},_getCursorBoundariesOffsets:function(t){if(this.cursorOffsetCache&&"top"in this.cursorOffsetCache)return this.cursorOffsetCache;var e,i,r,n,o=0,s=0,a=this.get2DCursorLocation(t);r=a.charIndex,i=a.lineIndex;for(var c=0;i>c;c++)o+=this.getHeightOfLine(c);e=this._getLineLeftOffset(i);var l=this.__charBounds[i][r];return l&&(s=l.left),0!==this.charSpacing&&r===this._textLines[i].length&&(s-=this._getWidthOfCharSpacing()),n={top:o,left:e+(s>0?s:0)},this.cursorOffsetCache=n,this.cursorOffsetCache},renderCursor:function(t,e){var i=this.get2DCursorLocation(),r=i.lineIndex,n=i.charIndex>0?i.charIndex-1:0,o=this.getValueOfPropertyAt(r,n,"fontSize"),s=this.scaleX*this.canvas.getZoom(),a=this.cursorWidth/s,c=t.topOffset,l=this.getValueOfPropertyAt(r,n,"deltaY");c+=(1-this._fontSizeFraction)*this.getHeightOfLine(r)/this.lineHeight-o*(1-this._fontSizeFraction),this.inCompositionMode&&this.renderSelection(t,e),e.fillStyle=this.getValueOfPropertyAt(r,n,"fill"),e.globalAlpha=this.__isMousedown?1:this._currentCursorOpacity,e.fillRect(t.left+t.leftOffset-a/2,c+t.top+l,a,o)},renderSelection:function(t,e){for(var i=this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,r=this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd,n=-1!==this.textAlign.indexOf("justify"),o=this.get2DCursorLocation(i),s=this.get2DCursorLocation(r),a=o.lineIndex,c=s.lineIndex,l=o.charIndex<0?0:o.charIndex,h=s.charIndex<0?0:s.charIndex,u=a;c>=u;u++){var f=this._getLineLeftOffset(u)||0,d=this.getHeightOfLine(u),g=0,p=0,v=0;if(u===a&&(p=this.__charBounds[a][l].left),u>=a&&c>u)v=n&&!this.isEndOfWrapping(u)?this.width:this.getLineWidth(u)||5;else if(u===c)if(0===h)v=this.__charBounds[c][h].left;else{var m=this._getWidthOfCharSpacing();v=this.__charBounds[c][h-1].left+this.__charBounds[c][h-1].width-m}g=d,(this.lineHeight<1||u===c&&this.lineHeight>1)&&(d/=this.lineHeight),this.inCompositionMode?(e.fillStyle=this.compositionColor||"black",e.fillRect(t.left+f+p,t.top+t.topOffset+d,v-p,1)):(e.fillStyle=this.selectionColor,e.fillRect(t.left+f+p,t.top+t.topOffset,v-p,d)),t.topOffset+=g}},getCurrentCharFontSize:function(){var t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")},getCurrentCharColor:function(){var t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fill")},_getCurrentCharIndex:function(){var t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}}),fabric.IText.fromObject=function(e,i){if(t(e),e.styles)for(var r in e.styles)for(var n in e.styles[r])t(e.styles[r][n]);fabric.Object._fromObject("IText",e,i,"text")}}();!function(){var t=fabric.util.object.clone;fabric.util.object.extend(fabric.IText.prototype,{initBehavior:function(){this.initAddedHandler(),this.initRemovedHandler(),this.initCursorSelectionHandlers(),this.initDoubleClickSimulation(),this.mouseMoveHandler=this.mouseMoveHandler.bind(this)},onDeselect:function(){this.isEditing&&this.exitEditing(),this.selected=!1},initAddedHandler:function(){var t=this;this.on("added",function(){var e=t.canvas;e&&(e._hasITextHandlers||(e._hasITextHandlers=!0,t._initCanvasHandlers(e)),e._iTextInstances=e._iTextInstances||[],e._iTextInstances.push(t))})},initRemovedHandler:function(){var t=this;this.on("removed",function(){var e=t.canvas;e&&(e._iTextInstances=e._iTextInstances||[],fabric.util.removeFromArray(e._iTextInstances,t),0===e._iTextInstances.length&&(e._hasITextHandlers=!1,t._removeCanvasHandlers(e)))})},_initCanvasHandlers:function(t){t._mouseUpITextHandler=function(){t._iTextInstances&&t._iTextInstances.forEach(function(t){t.__isMousedown=!1})},t.on("mouse:up",t._mouseUpITextHandler)},_removeCanvasHandlers:function(t){t.off("mouse:up",t._mouseUpITextHandler)},_tick:function(){this._currentTickState=this._animateCursor(this,1,this.cursorDuration,"_onTickComplete")},_animateCursor:function(t,e,i,r){var n;return n={isAborted:!1,abort:function(){this.isAborted=!0}},t.animate("_currentCursorOpacity",e,{duration:i,onComplete:function(){n.isAborted||t[r]()},onChange:function(){t.canvas&&t.selectionStart===t.selectionEnd&&t.renderCursorOrSelection()},abort:function(){return n.isAborted}}),n},_onTickComplete:function(){var t=this;this._cursorTimeout1&&clearTimeout(this._cursorTimeout1),this._cursorTimeout1=setTimeout(function(){t._currentTickCompleteState=t._animateCursor(t,0,this.cursorDuration/2,"_tick")},100)},initDelayedCursor:function(t){var e=this,i=t?0:this.cursorDelay;this.abortCursorAnimation(),this._currentCursorOpacity=1,this._cursorTimeout2=setTimeout(function(){e._tick()},i)},abortCursorAnimation:function(){var t=this._currentTickState||this._currentTickCompleteState,e=this.canvas;this._currentTickState&&this._currentTickState.abort(),this._currentTickCompleteState&&this._currentTickCompleteState.abort(),clearTimeout(this._cursorTimeout1),clearTimeout(this._cursorTimeout2),this._currentCursorOpacity=0,t&&e&&e.clearContext(e.contextTop||e.contextContainer)},selectAll:function(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this},getSelectedText:function(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")},findWordBoundaryLeft:function(t){var e=0,i=t-1;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i--;for(;/\S/.test(this._text[i])&&i>-1;)e++,i--;return t-e},findWordBoundaryRight:function(t){var e=0,i=t;if(this._reSpace.test(this._text[i]))for(;this._reSpace.test(this._text[i]);)e++,i++;for(;/\S/.test(this._text[i])&&i<this.text.length;)e++,i++;return t+e},findLineBoundaryLeft:function(t){for(var e=0,i=t-1;!/\n/.test(this._text[i])&&i>-1;)e++,i--;return t-e},findLineBoundaryRight:function(t){for(var e=0,i=t;!/\n/.test(this._text[i])&&i<this.text.length;)e++,i++;return t+e},searchWordBoundary:function(t,e){for(var i=this._reSpace.test(this.text.charAt(t))?t-1:t,r=this.text.charAt(i),n=/[ \n\.,;!\?\-]/;!n.test(r)&&i>0&&i<this.text.length;)i+=e,r=this.text.charAt(i);return n.test(r)&&"\n"!==r&&(i+=1===e?0:1),i},selectWord:function(t){t=t||this.selectionStart;var e=this.searchWordBoundary(t,-1),i=this.searchWordBoundary(t,1);this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()},selectLine:function(t){t=t||this.selectionStart;var e=this.findLineBoundaryLeft(t),i=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=i,this._fireSelectionChanged(),this._updateTextarea(),this},enterEditing:function(t){return!this.isEditing&&this.editable?(this.canvas&&(this.canvas.calcOffset(),this.exitEditingOnOthers(this.canvas)),this.isEditing=!0,this.initHiddenTextarea(t),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered"),this._fireSelectionChanged(),this.canvas?(this.canvas.fire("text:editing:entered",{target:this}),this.initMouseMoveHandler(),this.canvas.requestRenderAll(),this):this):void 0},exitEditingOnOthers:function(t){t._iTextInstances&&t._iTextInstances.forEach(function(t){t.selected=!1,t.isEditing&&t.exitEditing()})},initMouseMoveHandler:function(){this.canvas.on("mouse:move",this.mouseMoveHandler)},mouseMoveHandler:function(t){if(this.__isMousedown&&this.isEditing){var e=this.getSelectionStartFromPointer(t.e),i=this.selectionStart,r=this.selectionEnd;(e===this.__selectionStartOnMouseDown&&i!==r||i!==e&&r!==e)&&(e>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=e):(this.selectionStart=e,this.selectionEnd=this.__selectionStartOnMouseDown),(this.selectionStart!==i||this.selectionEnd!==r)&&(this.restartCursorIfNeeded(),this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}},_setEditingProps:function(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0},fromStringToGraphemeSelection:function(t,e,i){var r=i.slice(0,t),n=fabric.util.string.graphemeSplit(r).length;if(t===e)return{selectionStart:n,selectionEnd:n};var o=i.slice(t,e),s=fabric.util.string.graphemeSplit(o).length;return{selectionStart:n,selectionEnd:n+s}},fromGraphemeToStringSelection:function(t,e,i){var r=i.slice(0,t),n=r.join("").length;if(t===e)return{selectionStart:n,selectionEnd:n};var o=i.slice(t,e),s=o.join("").length;return{selectionStart:n,selectionEnd:n+s}},_updateTextarea:function(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){var t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}},updateFromTextArea:function(){if(this.hiddenTextarea){this.cursorOffsetCache={},this.text=this.hiddenTextarea.value,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords());var t=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value);this.selectionEnd=this.selectionStart=t.selectionEnd,this.inCompositionMode||(this.selectionStart=t.selectionStart),this.updateTextareaPosition()}},updateTextareaPosition:function(){if(this.selectionStart===this.selectionEnd){var t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}},_calcTextareaPosition:function(){if(!this.canvas)return{x:1,y:1};var t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),i=this.get2DCursorLocation(t),r=i.lineIndex,n=i.charIndex,o=this.getValueOfPropertyAt(r,n,"fontSize")*this.lineHeight,s=e.leftOffset,a=this.calcTransformMatrix(),c={x:e.left+s,y:e.top+e.topOffset+o},h=this.canvas.upperCanvasEl,l=h.width,u=h.height,f=l-o,d=u-o,g=h.clientWidth/l,p=h.clientHeight/u;return c=fabric.util.transformPoint(c,a),c=fabric.util.transformPoint(c,this.canvas.viewportTransform),c.x*=g,c.y*=p,c.x<0&&(c.x=0),c.x>f&&(c.x=f),c.y<0&&(c.y=0),c.y>d&&(c.y=d),c.x+=this.canvas._offset.left,c.y+=this.canvas._offset.top,{left:c.x+"px",top:c.y+"px",fontSize:o+"px",charHeight:o}},_saveEditingProps:function(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}},_restoreEditingProps:function(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor))},exitEditing:function(){var t=this._textBeforeEdit!==this.text;return this.selected=!1,this.isEditing=!1,this.selectable=!0,this.selectionEnd=this.selectionStart,this.hiddenTextarea&&(this.hiddenTextarea.blur&&this.hiddenTextarea.blur(),this.canvas&&this.hiddenTextarea.parentNode.removeChild(this.hiddenTextarea),this.hiddenTextarea=null),this.abortCursorAnimation(),this._restoreEditingProps(),this._currentCursorOpacity=0,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.off("mouse:move",this.mouseMoveHandler),this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this},_removeExtraneousStyles:function(){for(var t in this.styles)this._textLines[t]||delete this.styles[t]},removeStyleFromTo:function(t,e){var i,r,n=this.get2DCursorLocation(t,!0),o=this.get2DCursorLocation(e,!0),s=n.lineIndex,a=n.charIndex,c=o.lineIndex,h=o.charIndex;if(s!==c){if(this.styles[s])for(i=a;i<this._unwrappedTextLines[s].length;i++)delete this.styles[s][i];if(this.styles[c])for(i=h;i<this._unwrappedTextLines[c].length;i++)r=this.styles[c][i],r&&(this.styles[s]||(this.styles[s]={}),this.styles[s][a+i-h]=r);for(i=s+1;c>=i;i++)delete this.styles[i];this.shiftLineStyles(c,s-c)}else if(this.styles[s]){r=this.styles[s];var l,u,f=h-a;for(i=a;h>i;i++)delete r[i];for(u in this.styles[s])l=parseInt(u,10),l>=h&&(r[l-f]=r[u],delete r[u])}},shiftLineStyles:function(e,i){var r=t(this.styles);for(var n in this.styles){var o=parseInt(n,10);o>e&&(this.styles[o+i]=r[o],r[o-i]||delete this.styles[o])}},restartCursorIfNeeded:function(){(!this._currentTickState||this._currentTickState.isAborted||!this._currentTickCompleteState||this._currentTickCompleteState.isAborted)&&this.initDelayedCursor()},insertNewlineStyleObject:function(e,i,r,n){var o,s={},a=!1;r||(r=1),this.shiftLineStyles(e,r),this.styles[e]&&(o=this.styles[e][0===i?i:i-1]);for(var c in this.styles[e]){var h=parseInt(c,10);h>=i&&(a=!0,s[h-i]=this.styles[e][c],delete this.styles[e][c])}for(a?this.styles[e+r]=s:delete this.styles[e+r];r>1;)r--,n&&n[r]?this.styles[e+r]={0:t(n[r])}:o?this.styles[e+r]={0:t(o)}:delete this.styles[e+r];this._forceClearCache=!0},insertCharStyleObject:function(e,i,r,n){this.styles||(this.styles={});var o=this.styles[e],s=o?t(o):{};r||(r=1);for(var a in s){var c=parseInt(a,10);c>=i&&(o[c+r]=s[c],s[c-r]||delete o[c])}if(this._forceClearCache=!0,n)for(;r--;)Object.keys(n[r]).length&&(this.styles[e]||(this.styles[e]={}),this.styles[e][i+r]=t(n[r]));else if(o)for(var h=o[i?i-1:1];h&&r--;)this.styles[e][i+r]=t(h)},insertNewStyleBlock:function(t,e,i){for(var r=this.get2DCursorLocation(e,!0),n=[0],o=0,s=0;s<t.length;s++)"\n"===t[s]?(o++,n[o]=0):n[o]++;n[0]>0&&(this.insertCharStyleObject(r.lineIndex,r.charIndex,n[0],i),i=i&&i.slice(n[0]+1)),o&&this.insertNewlineStyleObject(r.lineIndex,r.charIndex+n[0],o);for(var s=1;o>s;s++)n[s]>0?this.insertCharStyleObject(r.lineIndex+s,0,n[s],i):i&&(this.styles[r.lineIndex+s][0]=i[0]),i=i&&i.slice(n[s]+1);n[s]>0&&this.insertCharStyleObject(r.lineIndex+s,0,n[s],i)},setSelectionStartEndWithShift:function(t,e,i){t>=i?(e===t?this._selectionDirection="left":"right"===this._selectionDirection&&(this._selectionDirection="left",this.selectionEnd=t),this.selectionStart=i):i>t&&e>i?"right"===this._selectionDirection?this.selectionEnd=i:this.selectionStart=i:(e===t?this._selectionDirection="right":"left"===this._selectionDirection&&(this._selectionDirection="right",this.selectionStart=e),this.selectionEnd=i)},setSelectionInBoundaries:function(){var t=this.text.length;this.selectionStart>t?this.selectionStart=t:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>t?this.selectionEnd=t:this.selectionEnd<0&&(this.selectionEnd=0)}})}();fabric.util.object.extend(fabric.IText.prototype,{initDoubleClickSimulation:function(){this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown)},onMouseDown:function(t){if(this.canvas){this.__newClickTime=+new Date;var e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),this._stopEvent(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y},_stopEvent:function(t){t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},initClicks:function(){this.on("mousedblclick",function(t){this.selectWord(this.getSelectionStartFromPointer(t.e))}),this.on("tripleclick",function(t){this.selectLine(this.getSelectionStartFromPointer(t.e))})},_mouseDownHandler:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||(this.__isMousedown=!0,this.selected&&this.setCursorByClick(t.e),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||this===this.canvas._activeObject&&(this.selected=!0)},initMousedownHandler:function(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore)},initMouseupHandler:function(){this.on("mouseup",this.mouseUpHandler)},mouseUpHandler:function(t){this.__isMousedown=!1,!this.editable||t.transform&&t.transform.actionPerformed||t.e.button&&1!==t.e.button||(this.__lastSelected&&!this.__corner&&(this.enterEditing(t.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()),this.selected=!0)},setCursorByClick:function(t){var e=this.getSelectionStartFromPointer(t),i=this.selectionStart,r=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(i,r,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(t){for(var e,i,r=this.getLocalPointer(t),n=0,o=0,s=0,a=0,c=0,h=0,l=this._textLines.length;l>h&&s<=r.y;h++)s+=this.getHeightOfLine(h)*this.scaleY,c=h,h>0&&(a+=this._textLines[h-1].length+1);e=this._getLineLeftOffset(c),o=e*this.scaleX,i=this._textLines[c];for(var u=0,f=i.length;f>u&&(n=o,o+=this.__charBounds[c][u].kernedWidth*this.scaleX,o<=r.x);u++)a++;return this._getNewSelectionStartFromOffset(r,n,o,a,f)},_getNewSelectionStartFromOffset:function(t,e,i,r,n){var o=t.x-e,s=i-t.x,a=s>o||0>s?0:1,c=r+a;return this.flipX&&(c=n-c),c>this._text.length&&(c=this._text.length),c}});fabric.util.object.extend(fabric.IText.prototype,{initHiddenTextarea:function(){this.hiddenTextarea=fabric.document.createElement("textarea"),this.hiddenTextarea.setAttribute("autocapitalize","off"),this.hiddenTextarea.setAttribute("autocorrect","off"),this.hiddenTextarea.setAttribute("autocomplete","off"),this.hiddenTextarea.setAttribute("spellcheck","false"),this.hiddenTextarea.setAttribute("data-fabric-hiddentextarea",""),this.hiddenTextarea.setAttribute("wrap","off");var t=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+t.top+"; left: "+t.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; line-height: 1px; paddingーtop: "+t.fontSize+";",fabric.document.body.appendChild(this.hiddenTextarea),fabric.util.addListener(this.hiddenTextarea,"keydown",this.onKeyDown.bind(this)),fabric.util.addListener(this.hiddenTextarea,"keyup",this.onKeyUp.bind(this)),fabric.util.addListener(this.hiddenTextarea,"input",this.onInput.bind(this)),fabric.util.addListener(this.hiddenTextarea,"copy",this.copy.bind(this)),fabric.util.addListener(this.hiddenTextarea,"cut",this.copy.bind(this)),fabric.util.addListener(this.hiddenTextarea,"paste",this.paste.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionstart",this.onCompositionStart.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionupdate",this.onCompositionUpdate.bind(this)),fabric.util.addListener(this.hiddenTextarea,"compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(fabric.util.addListener(this.canvas.upperCanvasEl,"click",this.onClick.bind(this)),this._clickHandlerInitialized=!0)},keysMap:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorRight",36:"moveCursorLeft",37:"moveCursorLeft",38:"moveCursorUp",39:"moveCursorRight",40:"moveCursorDown"},ctrlKeysMapUp:{67:"copy",88:"cut"},ctrlKeysMapDown:{65:"selectAll"},onClick:function(){this.hiddenTextarea&&this.hiddenTextarea.focus()},onKeyDown:function(t){if(this.isEditing&&!this.inCompositionMode){if(t.keyCode in this.keysMap)this[this.keysMap[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown&&(t.ctrlKey||t.metaKey)))return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(t){return!this.isEditing||this._copyDone||this.inCompositionMode?void(this._copyDone=!1):void(t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll()))},onInput:function(t){var e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),this.isEditing){var i,r,n=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,s=this._text.length,o=n.length,a=o-s;if(""===this.hiddenTextarea.value)return this.styles={},this.updateFromTextArea(),this.fire("changed"),void(this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll()));var c=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),h=this.selectionStart>c.selectionStart;this.selectionStart!==this.selectionEnd?(i=this._text.slice(this.selectionStart,this.selectionEnd),a+=this.selectionEnd-this.selectionStart):s>o&&(i=h?this._text.slice(this.selectionEnd+a,this.selectionEnd):this._text.slice(this.selectionStart,this.selectionStart-a)),r=n.slice(c.selectionEnd-a,c.selectionEnd),i&&i.length&&(this.selectionStart!==this.selectionEnd?this.removeStyleFromTo(this.selectionStart,this.selectionEnd):h?this.removeStyleFromTo(this.selectionEnd-i.length,this.selectionEnd):this.removeStyleFromTo(this.selectionEnd,this.selectionEnd+i.length)),r.length&&(e&&r.join("")===fabric.copiedText?this.insertNewStyleBlock(r,this.selectionStart,fabric.copiedTextStyle):this.insertNewStyleBlock(r,this.selectionStart)),this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())}},onCompositionStart:function(){this.inCompositionMode=!0},onCompositionEnd:function(){this.inCompositionMode=!1},onCompositionUpdate:function(t){this.compositionStart=t.target.selectionStart,this.compositionEnd=t.target.selectionEnd,this.updateTextareaPosition()},copy:function(){this.selectionStart!==this.selectionEnd&&(fabric.copiedText=this.getSelectedText(),fabric.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0)},paste:function(){this.fromPaste=!0},_getClipboardData:function(t){return t&&t.clipboardData||fabric.window.clipboardData},_getWidthBeforeCursor:function(t,e){var i,r=this._getLineLeftOffset(t);return e>0&&(i=this.__charBounds[t][e-1],r+=i.left+i.width),r},getDownCursorOffset:function(t,e){var i=this._getSelectionForOffset(t,e),r=this.get2DCursorLocation(i),n=r.lineIndex;if(n===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-i;var s=r.charIndex,o=this._getWidthBeforeCursor(n,s),a=this._getIndexOnLine(n+1,o),c=this._textLines[n].slice(s);return c.length+a+2},_getSelectionForOffset:function(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart},getUpCursorOffset:function(t,e){var i=this._getSelectionForOffset(t,e),r=this.get2DCursorLocation(i),n=r.lineIndex;if(0===n||t.metaKey||33===t.keyCode)return-i;var s=r.charIndex,o=this._getWidthBeforeCursor(n,s),a=this._getIndexOnLine(n-1,o),c=this._textLines[n].slice(0,s);return-this._textLines[n-1].length+a-c.length},_getIndexOnLine:function(t,e){for(var i,r,n=this._textLines[t],s=this._getLineLeftOffset(t),o=s,a=0,c=0,h=n.length;h>c;c++)if(i=this.__charBounds[t][c].width,o+=i,o>e){r=!0;var l=o-i,u=o,f=Math.abs(l-e),d=Math.abs(u-e);a=f>d?c:c-1;break}return r||(a=n.length-1),a},moveCursorDown:function(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)},moveCursorUp:function(t){(0!==this.selectionStart||0!==this.selectionEnd)&&this._moveCursorUpOrDown("Up",t)},_moveCursorUpOrDown:function(t,e){var i="get"+t+"CursorOffset",r=this[i](e,"right"===this._selectionDirection);e.shiftKey?this.moveCursorWithShift(r):this.moveCursorWithoutShift(r),0!==r&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(t){var e="left"===this._selectionDirection?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t},moveCursorWithoutShift:function(t){return 0>t?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t},moveCursorLeft:function(t){(0!==this.selectionStart||0!==this.selectionEnd)&&this._moveCursorLeftOrRight("Left",t)},_move:function(t,e,i){var r;if(t.altKey)r=this["findWordBoundary"+i](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===i?-1:1,!0;r=this["findLineBoundary"+i](this[e])}return void 0!==typeof r&&this[e]!==r?(this[e]=r,!0):void 0},_moveLeft:function(t,e){return this._move(t,e,"Left")},_moveRight:function(t,e){return this._move(t,e,"Right")},moveCursorLeftWithoutShift:function(t){var e=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e},moveCursorLeftWithShift:function(t){return"right"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection="left",this._moveLeft(t,"selectionStart")):void 0},moveCursorRight:function(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)},_moveCursorLeftOrRight:function(t,e){var i="moveCursor"+t+"With";this._currentCursorOpacity=1,i+=e.shiftKey?"Shift":"outShift",this[i](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(t){return"left"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection="right",this._moveRight(t,"selectionEnd")):void 0},moveCursorRightWithoutShift:function(t){var e=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e},removeChars:function(t,e){"undefined"==typeof e&&(e=t+1),this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(t,e,i,r){"undefined"==typeof r&&(r=i),r>i&&this.removeStyleFromTo(i,r);var n=fabric.util.string.graphemeSplit(t);this.insertNewStyleBlock(n,i,e),this._text=[].concat(this._text.slice(0,i),n,this._text.slice(r)),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()}});!function(t){"use strict";var e=t.fabric||(t.fabric={});e.Textbox=e.util.createClass(e.IText,e.Observable,{type:"textbox",minWidth:20,dynamicMinWidth:2,__cachedLines:null,lockScalingFlip:!0,noScaleCache:!1,_dimensionAffectingProps:e.Text.prototype._dimensionAffectingProps.concat("width"),initDimensions:function(){this.__skipDimension||(this.isEditing&&this.initDelayedCursor(),this.clearContextTop(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight(),this.saveState({propertySet:"_dimensionAffectingProps"}))},_generateStyleMap:function(t){for(var e=0,i=0,r=0,n={},s=0;s<t.graphemeLines.length;s++)"\n"===t.graphemeText[r]&&s>0?(i=0,r++,e++):this._reSpaceAndTab.test(t.graphemeText[r])&&s>0&&(i++,r++),n[s]={line:e,offset:i},r+=t.graphemeLines[s].length,i+=t.graphemeLines[s].length;return n},styleHas:function(t,i){if(this._styleMap&&!this.isWrapping){var r=this._styleMap[i];r&&(i=r.line)}return e.Text.prototype.styleHas.call(this,t,i)},isEmptyStyles:function(t){var e,i,r=0,n=t+1,s=!1,o=this._styleMap[t],a=this._styleMap[t+1];o&&(t=o.line,r=o.offset),a&&(n=a.line,s=n===t,e=a.offset),i="undefined"==typeof t?this.styles:{line:this.styles[t]};for(var c in i)for(var h in i[c])if(h>=r&&(!s||e>h))for(var l in i[c][h])return!1;return!0},_getStyleDeclaration:function(t,e){if(this._styleMap&&!this.isWrapping){var i=this._styleMap[t];if(!i)return null;t=i.line,e=i.offset+e}return this.callSuper("_getStyleDeclaration",t,e)},_setStyleDeclaration:function(t,e,i){var r=this._styleMap[t];t=r.line,e=r.offset+e,this.styles[t][e]=i},_deleteStyleDeclaration:function(t,e){var i=this._styleMap[t];t=i.line,e=i.offset+e,delete this.styles[t][e]},_getLineStyle:function(t){var e=this._styleMap[t];return this.styles[e.line]},_setLineStyle:function(t,e){var i=this._styleMap[t];this.styles[i.line]=e},_deleteLineStyle:function(t){var e=this._styleMap[t];delete this.styles[e.line]},_wrapText:function(t,e){var i,r=[];for(this.isWrapping=!0,i=0;i<t.length;i++)r=r.concat(this._wrapLine(t[i],i,e));return this.isWrapping=!1,r},_measureWord:function(t,e,i){var r,n=0,s=!0;i=i||0;for(var o=0,a=t.length;a>o;o++){var c=this._getGraphemeBox(t[o],e,o+i,r,s);n+=c.kernedWidth,r=t[o]}return n},_wrapLine:function(t,i,r,n){var s=0,o=[],a=[],c=t.split(this._reSpaceAndTab),h="",l=0,u=" ",f=0,d=0,g=0,p=!0,v=this._getWidthOfCharSpacing(),n=n||0;r-=n;for(var m=0;m<c.length;m++)h=e.util.string.graphemeSplit(c[m]),f=this._measureWord(h,i,l),l+=h.length,s+=d+f-v,s>=r&&!p?(o.push(a),a=[],s=f,p=!0):s+=v,p||a.push(u),a=a.concat(h),d=this._measureWord([u],i,l),l++,p=!1,f>g&&(g=f);return m&&o.push(a),g+n>this.dynamicMinWidth&&(this.dynamicMinWidth=g-v+n),o},isEndOfWrapping:function(t){return this._styleMap[t+1]?this._styleMap[t+1].line!==this._styleMap[t].line?!0:!1:!0},_splitTextIntoLines:function(t){for(var i=e.Text.prototype._splitTextIntoLines.call(this,t),r=this._wrapText(i.lines,this.width),n=new Array(r.length),s=0;s<r.length;s++)n[s]=r[s].join("");return i.lines=n,i.graphemeLines=r,i},getMinWidth:function(){return Math.max(this.minWidth,this.dynamicMinWidth)},toObject:function(t){return this.callSuper("toObject",["minWidth"].concat(t))}}),e.Textbox.fromObject=function(t,i){return e.Object._fromObject("Textbox",t,i,"text")}}("undefined"!=typeof exports?exports:this);!function(){var t=fabric.Canvas.prototype._setObjectScale;fabric.Canvas.prototype._setObjectScale=function(e,i,r,n,s,o,a){var c=i.target;if(!("x"===s&&c instanceof fabric.Textbox))return t.call(fabric.Canvas.prototype,e,i,r,n,s,o,a);var h=c._getTransformedDimensions().x,l=c.width*(e.x/h);return l>=c.getMinWidth()?(c.set("width",l),!0):void 0},fabric.util.object.extend(fabric.Textbox.prototype,{_removeExtraneousStyles:function(){for(var t in this._styleMap)this._textLines[t]||delete this.styles[this._styleMap[t].line]}})}();