!function(t){"function"==typeof define&&define.amd?define("picker",["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):this.Picker=t(jQuery)}(function(t){function e(o,s,a,u){function h(){return e._.node("div",e._.node("div",e._.node("div",e._.node("div",C.component.nodes(b.open),x.box),x.wrap),x.frame),x.holder)}function f(){w.data(s,C).addClass(x.input).val(w.data("value")?C.get("select",y.format):o.value).on("focus."+b.id+" click."+b.id,v),y.editable||w.on("keydown."+b.id,function(t){var e=t.keyCode,i=/^(8|46)$/.test(e);return 27==e?(C.close(),!1):void((32==e||i||!b.open&&C.component.key[e])&&(t.preventDefault(),t.stopPropagation(),i?C.clear().close():C.open()))}),r(o,{haspopup:!0,expanded:!1,readonly:!1,owns:o.id+"_root"+(C._hidden?" "+C._hidden.id:"")})}function d(){C.$root.on({focusin:function(t){C.$root.removeClass(x.focused),t.stopPropagation()},"mousedown click":function(e){var i=e.target;i!=C.$root.children()[0]&&(e.stopPropagation(),"mousedown"!=e.type||t(i).is(":input")||"OPTION"==i.nodeName||(e.preventDefault(),o.focus()))}}),r(C.$root[0],"hidden",!0)}function p(){C.$root.find("[data-pick], [data-nav], [data-clear]").on("click",function(){var i=t(this),n=i.data(),r=i.hasClass(x.navDisabled)||i.hasClass(x.disabled),s=document.activeElement;s=s&&(s.type||s.href)&&s,(r||s&&!t.contains(C.$root[0],s))&&o.focus(),void 0!==n.nav&&(n.nav=parseInt(n.nav)),void 0!==n.pick&&(n.pick=parseInt(n.pick)),n.nav&&!r?(C.set("highlight",C.component.item.highlight,{nav:n.nav}),p()):e._.isInteger(n.pick)&&!r?C.set("select",n.pick).close(!0):n.clear&&C.clear().close(!0)}),C.$root.find("[data-close]").on("click",function(){C.close(!0)})}function g(){var e;y.hiddenName===!0?(e=o.name,o.name=""):(e=["string"==typeof y.hiddenPrefix?y.hiddenPrefix:"","string"==typeof y.hiddenSuffix?y.hiddenSuffix:"_submit"],e=e[0]+o.name+e[1]),C._hidden=t('")[0],w.on("change."+b.id,function(){C._hidden.value=o.value?C.get("select",y.formatSubmit):""}).after(C._hidden)}function v(t){t.stopPropagation(),"focus"==t.type&&C.$root.addClass(x.focused),C.open()}if(!o)return e;var m=!1,b={id:o.id||"P"+Math.abs(~~(Math.random()*new Date))},y=a?t.extend(!0,{},a.defaults,u):u||{},x=t.extend({},e.klasses(),y.klass),w=t(o),k=function(){return this.start()},C=k.prototype={constructor:k,$node:w,start:function(){return b&&b.start?C:(b.methods={},b.start=!0,b.open=!1,b.type=o.type,o.autofocus=o==document.activeElement,o.readOnly=!y.editable,o.id=o.id||b.id,"text"!=o.type&&(o.type="text"),C.component=new a(C,y),C.$root=t(e._.node("div",h(),x.picker,'id="'+o.id+'_root"')),d(),y.formatSubmit&&g(),f(),y.container?t(y.container).append(C.$root):w.after(C.$root),C.on({start:C.component.onStart,render:C.component.onRender,stop:C.component.onStop,open:C.component.onOpen,close:C.component.onClose,set:C.component.onSet}).on({start:y.onStart,render:y.onRender,stop:y.onStop,open:y.onOpen,close:y.onClose,set:y.onSet}),m=i(C.$root.children()[0]),o.autofocus&&C.open(),C.trigger("start").trigger("render"))},render:function(t){return t?C.$root.html(h()):C.$root.find("."+x.box).html(C.component.nodes(b.open)),C.trigger("render")},stop:function(){return b.start?(C.close(),C._hidden&&C._hidden.parentNode.removeChild(C._hidden),C.$root.remove(),w.removeClass(x.input).removeData(s),setTimeout(function(){w.off("."+b.id)},0),o.type=b.type,o.readOnly=!1,C.trigger("stop"),b.methods={},b.start=!1,C):C},open:function(i){return b.open?C:(w.addClass(x.active),r(o,"expanded",!0),setTimeout(function(){C.$root.addClass(x.opened),r(C.$root[0],"hidden",!1)},0),i!==!1&&(b.open=!0,m&&l.css("overflow","hidden").css("padding-right","+="+n()),w.trigger("focus"),c.on("click."+b.id+" focusin."+b.id,function(t){var e=t.target;e!=o&&e!=document&&3!=t.which&&C.close(e===C.$root.children()[0])}).on("keydown."+b.id,function(i){var n=i.keyCode,r=C.component.key[n],s=i.target;27==n?C.close(!0):s!=o||!r&&13!=n?t.contains(C.$root[0],s)&&13==n&&(i.preventDefault(),s.click()):(i.preventDefault(),r?e._.trigger(C.component.key.go,C,[e._.trigger(r)]):C.$root.find("."+x.highlighted).hasClass(x.disabled)||C.set("select",C.component.item.highlight).close())})),p(),C.trigger("open"))},close:function(t){return t&&(w.off("focus."+b.id).trigger("focus"),setTimeout(function(){w.on("focus."+b.id,v)},0)),w.removeClass(x.active),r(o,"expanded",!1),setTimeout(function(){C.$root.removeClass(x.opened+" "+x.focused),r(C.$root[0],"hidden",!0)},0),b.open?(b.open=!1,m&&l.css("overflow","").css("padding-right","-="+n()),c.off("."+b.id),C.trigger("close")):C},clear:function(t){return C.set("clear",null,t)},set:function(e,i,n){var r,o,s=t.isPlainObject(e),a=s?e:{};if(n=s&&t.isPlainObject(i)?i:n||{},e){s||(a[e]=i);for(r in a)o=a[r],r in C.component.item&&(void 0===o&&(o=null),C.component.set(r,o,n)),("select"==r||"clear"==r)&&w.val("clear"==r?"":C.get(r,y.format)).trigger("change");C.render()}return n.muted?C:C.trigger("set",a)},get:function(t,i){if(t=t||"value",null!=b[t])return b[t];if("value"==t)return o.value;if(t in C.component.item){if("string"==typeof i){var n=C.component.get(t);return n?e._.trigger(C.component.formats.toString,C.component,[i,n]):""}return C.component.get(t)}},on:function(e,i,n){var r,o,s=t.isPlainObject(e),a=s?e:{};if(e){s||(a[e]=i);for(r in a)o=a[r],n&&(r="_"+r),b.methods[r]=b.methods[r]||[],b.methods[r].push(o)}return C},off:function(){var t,e,i=arguments;for(t=0,namesCount=i.length;t').appendTo("body"),i=e[0].offsetWidth;e.css("overflow","scroll");var n=t('
').appendTo(e),r=n[0].offsetWidth;return e.remove(),i-r}function r(e,i,n){if(t.isPlainObject(i))for(var r in i)o(e,r,i[r]);else o(e,i,n)}function o(t,e,i){t.setAttribute(("role"==e?"":"aria-")+e,i)}function s(e,i){t.isPlainObject(e)||(e={attribute:i}),i="";for(var n in e){var r=("role"==n?"":"aria-")+n,o=e[n];i+=null==o?"":r+'="'+e[n]+'"'}return i}var a=t(window),c=t(document),l=t(document.documentElement);return e.klasses=function(t){return t=t||"picker",{picker:t,opened:t+"--opened",focused:t+"--focused",input:t+"__input",active:t+"__input--active",holder:t+"__holder",frame:t+"__frame",wrap:t+"__wrap",box:t+"__box"}},e._={group:function(t){for(var i,n="",r=e._.trigger(t.min,t);r<=e._.trigger(t.max,t,[r]);r+=t.i)i=e._.trigger(t.item,t,[r]),n+=e._.node(t.node,i[0],i[1],i[2]);return n},node:function(e,i,n,r){return i?(i=t.isArray(i)?i.join(""):i,n=n?' class="'+n+'"':"",r=r?" "+r:"","<"+e+n+r+">"+i+""):""},lead:function(t){return(10>t?"0":"")+t},trigger:function(t,e,i){return"function"==typeof t?t.apply(e,i||[]):t},digits:function(t){return/\d/.test(t[1])?2:1},isDate:function(t){return{}.toString.call(t).indexOf("Date")>-1&&this.isInteger(t.getDate())},isInteger:function(t){return{}.toString.call(t).indexOf("Number")>-1&&t%1===0},ariaAttr:s},e.extend=function(i,n){t.fn[i]=function(r,o){var s=this.data(i);return"picker"==r?s:s&&"string"==typeof r?e._.trigger(s[r],s,[o]):this.each(function(){var o=t(this);o.data(i)||new e(this,i,n,r)})},t.fn[i].defaults=n.defaults},e}),function(t){"function"==typeof define&&define.amd?define(["picker","jquery"],t):"object"==typeof exports?module.exports=t(require("./picker.js"),require("jquery")):t(Picker,jQuery)}(function(t,e){function i(t,e){var i=this,n=t.$node[0],r=n.value,o=t.$node.data("value"),s=o||r,a=o?e.formatSubmit:e.format,c=function(){return n.currentStyle?"rtl"==n.currentStyle.direction:"rtl"==getComputedStyle(t.$root[0]).direction};i.settings=e,i.$node=t.$node,i.queue={min:"measure create",max:"measure create",now:"now create",select:"parse create validate",highlight:"parse navigate create validate",view:"parse create validate viewset",disable:"deactivate",enable:"activate"},i.item={},i.item.clear=null,i.item.disable=(e.disable||[]).slice(0),i.item.enable=-function(t){return t[0]===!0?t.shift():-1}(i.item.disable),i.set("min",e.min).set("max",e.max).set("now"),s?i.set("select",s,{format:a}):i.set("select",null).set("highlight",i.item.now),i.key={40:7,38:-7,39:function(){return c()?-1:1},37:function(){return c()?1:-1},go:function(t){var e=i.item.highlight,n=new Date(e.year,e.month,e.date+t);i.set("highlight",[n.getFullYear(),n.getMonth(),n.getDate()],{interval:t}),this.render()}},t.on("render",function(){t.$root.find("."+e.klass.selectMonth).on("change",function(){var i=this.value;i&&(t.set("highlight",[t.get("view").year,i,t.get("highlight").date]),t.$root.find("."+e.klass.selectMonth).trigger("focus"))}),t.$root.find("."+e.klass.selectYear).on("change",function(){var i=this.value;i&&(t.set("highlight",[i,t.get("view").month,t.get("highlight").date]),t.$root.find("."+e.klass.selectYear).trigger("focus"))})},1).on("open",function(){var n="";i.disabled(i.get("now"))&&(n=":not(."+e.klass.buttonToday+")"),t.$root.find("button"+n+", select").attr("disabled",!1)},1).on("close",function(){t.$root.find("button, select").attr("disabled",!0)},1)}var n=7,r=6,o=t._;i.prototype.set=function(t,e,i){var n=this,r=n.item;return null===e?("clear"==t&&(t="select"),r[t]=e,n):(r["enable"==t?"disable":"flip"==t?"enable":t]=n.queue[t].split(" ").map(function(r){return e=n[r](t,e,i)}).pop(),"select"==t?n.set("highlight",r.select,i):"highlight"==t?n.set("view",r.highlight,i):t.match(/^(flip|min|max|disable|enable)$/)&&(r.select&&n.disabled(r.select)&&n.set("select",r.select,i),r.highlight&&n.disabled(r.highlight)&&n.set("highlight",r.highlight,i)),n)},i.prototype.get=function(t){return this.item[t]},i.prototype.create=function(t,i,n){var r,s=this;return i=void 0===i?t:i,i==-(1/0)||i==1/0?r=i:e.isPlainObject(i)&&o.isInteger(i.pick)?i=i.obj:e.isArray(i)?(i=new Date(i[0],i[1],i[2]),i=o.isDate(i)?i:s.create().obj):i=o.isInteger(i)||o.isDate(i)?s.normalize(new Date(i),n):s.now(t,i,n),{year:r||i.getFullYear(),month:r||i.getMonth(),date:r||i.getDate(),day:r||i.getDay(),obj:r||i,pick:r||i.getTime()}},i.prototype.createRange=function(t,i){var n=this,r=function(t){return t===!0||e.isArray(t)||o.isDate(t)?n.create(t):t};return o.isInteger(t)||(t=r(t)),o.isInteger(i)||(i=r(i)),o.isInteger(t)&&e.isPlainObject(i)?t=[i.year,i.month,i.date+t]:o.isInteger(i)&&e.isPlainObject(t)&&(i=[t.year,t.month,t.date+i]),{from:r(t),to:r(i)}},i.prototype.withinRange=function(t,e){return t=this.createRange(t.from,t.to),e.pick>=t.from.pick&&e.pick<=t.to.pick},i.prototype.overlapRanges=function(t,e){var i=this;return t=i.createRange(t.from,t.to),e=i.createRange(e.from,e.to),i.withinRange(t,e.from)||i.withinRange(t,e.to)||i.withinRange(e,t.from)||i.withinRange(e,t.to)},i.prototype.now=function(t,e,i){return e=new Date,i&&i.rel&&e.setDate(e.getDate()+i.rel),this.normalize(e,i)},i.prototype.navigate=function(t,i,n){var r,o,s,a,c=e.isArray(i),l=e.isPlainObject(i),u=this.item.view;if(c||l){for(l?(o=i.year,s=i.month,a=i.date):(o=+i[0],s=+i[1],a=+i[2]),n&&n.nav&&u&&u.month!==s&&(o=u.year,s=u.month),r=new Date(o,s+(n&&n.nav?n.nav:0),1),o=r.getFullYear(),s=r.getMonth();new Date(o,s,a).getMonth()!==s;)a-=1;i=[o,s,a]}return i},i.prototype.normalize=function(t){return t.setHours(0,0,0,0),t},i.prototype.measure=function(t,e){var i=this;return e?"string"==typeof e?e=i.parse(t,e):o.isInteger(e)&&(e=i.now(t,e,{rel:e})):e="min"==t?-(1/0):1/0,e},i.prototype.viewset=function(t,e){return this.create([e.year,e.month,1])},i.prototype.validate=function(t,i,n){var r,s,a,c,l=this,u=i,h=n&&n.interval?n.interval:1,f=-1===l.item.enable,d=l.item.min,p=l.item.max,g=f&&l.item.disable.filter(function(t){if(e.isArray(t)){var n=l.create(t).pick;ni.pick&&(s=!0)}return o.isInteger(t)}).length;if((!n||!n.nav)&&(!f&&l.disabled(i)||f&&l.disabled(i)&&(g||r||s)||!f&&(i.pick<=d.pick||i.pick>=p.pick)))for(f&&!g&&(!s&&h>0||!r&&0>h)&&(h*=-1);l.disabled(i)&&(Math.abs(h)>1&&(i.monthu.month)&&(i=u,h=h>0?1:-1),i.pick<=d.pick?(a=!0,h=1,i=l.create([d.year,d.month,d.date+(i.pick===d.pick?0:-1)])):i.pick>=p.pick&&(c=!0,h=-1,i=l.create([p.year,p.month,p.date+(i.pick===p.pick?0:1)])),!a||!c);)i=l.create([i.year,i.month,i.date+h]);return i},i.prototype.disabled=function(t){var i=this,n=i.item.disable.filter(function(n){return o.isInteger(n)?t.day===(i.settings.firstDay?n:n-1)%7:e.isArray(n)||o.isDate(n)?t.pick===i.create(n).pick:e.isPlainObject(n)?i.withinRange(n,t):void 0});return n=n.length&&!n.filter(function(t){return e.isArray(t)&&"inverted"==t[3]||e.isPlainObject(t)&&t.inverted}).length,-1===i.item.enable?!n:n||t.picki.item.max.pick},i.prototype.parse=function(t,e,i){var n=this,r={};return e&&"string"==typeof e?(i&&i.format||(i=i||{},i.format=n.settings.format),n.formats.toArray(i.format).map(function(t){var i=n.formats[t],s=i?o.trigger(i,n,[e,r]):t.replace(/^!/,"").length;i&&(r[t]=e.substr(0,s)),e=e.substr(s)}),[r.yyyy||r.yy,+(r.mm||r.m)-1,r.dd||r.d]):e},i.prototype.formats=function(){function t(t,e,i){var n=t.match(/\w+/)[0];return i.mm||i.m||(i.m=e.indexOf(n)+1),n.length}function e(t){return t.match(/\w+/)[0].length}return{d:function(t,e){return t?o.digits(t):e.date},dd:function(t,e){return t?2:o.lead(e.date)},ddd:function(t,i){return t?e(t):this.settings.weekdaysShort[i.day]},dddd:function(t,i){return t?e(t):this.settings.weekdaysFull[i.day]},m:function(t,e){return t?o.digits(t):e.month+1},mm:function(t,e){return t?2:o.lead(e.month+1)},mmm:function(e,i){var n=this.settings.monthsShort;return e?t(e,n,i):n[i.month]},mmmm:function(e,i){var n=this.settings.monthsFull;return e?t(e,n,i):n[i.month]},yy:function(t,e){return t?2:(""+e.year).slice(2)},yyyy:function(t,e){return t?4:e.year},toArray:function(t){return t.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g)},toString:function(t,e){var i=this;return i.formats.toArray(t).map(function(t){return o.trigger(i.formats[t],i,[0,e])||t.replace(/^!/,"")}).join("")}}}(),i.prototype.isDateExact=function(t,i){var n=this;return o.isInteger(t)&&o.isInteger(i)||"boolean"==typeof t&&"boolean"==typeof i?t===i:(o.isDate(t)||e.isArray(t))&&(o.isDate(i)||e.isArray(i))?n.create(t).pick===n.create(i).pick:e.isPlainObject(t)&&e.isPlainObject(i)?n.isDateExact(t.from,i.from)&&n.isDateExact(t.to,i.to):!1},i.prototype.isDateOverlap=function(t,i){var n=this,r=n.settings.firstDay?1:0;return o.isInteger(t)&&(o.isDate(i)||e.isArray(i))?(t=t%7+r,t===n.create(i).day+1):o.isInteger(i)&&(o.isDate(t)||e.isArray(t))?(i=i%7+r,i===n.create(t).day+1):e.isPlainObject(t)&&e.isPlainObject(i)?n.overlapRanges(t,i):!1},i.prototype.flipEnable=function(t){var e=this.item;e.enable=t||(-1==e.enable?1:-1)},i.prototype.deactivate=function(t,i){var n=this,r=n.item.disable.slice(0);return"flip"==i?n.flipEnable():i===!1?(n.flipEnable(1),r=[]):i===!0?(n.flipEnable(-1),r=[]):i.map(function(t){for(var i,s=0;sc;c+=1){if(a=r[c],n.isDateExact(a,t)){i=r[c]=null,l=!0;break}if(n.isDateOverlap(a,t)){e.isPlainObject(t)?(t.inverted=!0,i=t):e.isArray(t)?(i=t,i[3]||i.push("inverted")):o.isDate(t)&&(i=[t.getFullYear(),t.getMonth(),t.getDate(),"inverted"]);break}}if(i)for(c=0;s>c;c+=1)if(n.isDateExact(r[c],t)){r[c]=null;break}if(l)for(c=0;s>c;c+=1)if(n.isDateOverlap(r[c],t)){r[c]=null;break}i&&r.push(i)}),r.filter(function(t){return null!=t})},i.prototype.nodes=function(t){var e=this,i=e.settings,s=e.item,a=s.now,c=s.select,l=s.highlight,u=s.view,h=s.disable,f=s.min,d=s.max,p=function(t,e){return i.firstDay&&(t.push(t.shift()),e.push(e.shift())),o.node("thead",o.node("tr",o.group({min:0,max:n-1,i:1,node:"th",item:function(n){return[t[n],i.klass.weekdays,'scope=col title="'+e[n]+'"']}})))}((i.showWeekdaysFull?i.weekdaysFull:i.weekdaysShort).slice(0),i.weekdaysFull.slice(0)),g=function(t){return o.node("div"," ",i.klass["nav"+(t?"Next":"Prev")]+(t&&u.year>=d.year&&u.month>=d.month||!t&&u.year<=f.year&&u.month<=f.month?" "+i.klass.navDisabled:""),"data-nav="+(t||-1)+" "+o.ariaAttr({role:"button",controls:e.$node[0].id+"_table"})+' title="'+(t?i.labelMonthNext:i.labelMonthPrev)+'"')},v=function(){var n=i.showMonthsShort?i.monthsShort:i.monthsFull;return i.selectMonths?o.node("select",o.group({min:0,max:11,i:1,node:"option",item:function(t){return[n[t],0,"value="+t+(u.month==t?" selected":"")+(u.year==f.year&&td.month?" disabled":"")]}}),i.klass.selectMonth,(t?"":"disabled")+" "+o.ariaAttr({controls:e.$node[0].id+"_table"})+' title="'+i.labelMonthSelect+'"'):o.node("div",n[u.month],i.klass.month)},m=function(){var n=u.year,r=i.selectYears===!0?5:~~(i.selectYears/2);if(r){var s=f.year,a=d.year,c=n-r,l=n+r;if(s>c&&(l+=s-c,c=s),l>a){var h=c-s,p=l-a;c-=h>p?p:h,l=a}return o.node("select",o.group({min:c,max:l,i:1,node:"option",item:function(t){return[t,0,"value="+t+(n==t?" selected":"")]}}),i.klass.selectYear,(t?"":"disabled")+" "+o.ariaAttr({controls:e.$node[0].id+"_table"})+' title="'+i.labelYearSelect+'"')}return o.node("div",n,i.klass.year)};return o.node("div",(i.selectYears?m()+v():v()+m())+g()+g(1),i.klass.header)+o.node("table",p+o.node("tbody",o.group({min:0,max:r-1,i:1,node:"tr",item:function(t){var r=i.firstDay&&0===e.create([u.year,u.month,1]).day?-7:0;return[o.group({min:n*t-u.day+r+1,max:function(){return this.min+n-1},i:1,node:"td",item:function(t){t=e.create([u.year,u.month,t+(i.firstDay?1:0)]);var n=c&&c.pick==t.pick,r=l&&l.pick==t.pick,s=h&&e.disabled(t)||t.pickd.pick;return[o.node("div",t.date,function(e){return e.push(u.month==t.month?i.klass.infocus:i.klass.outfocus),a.pick==t.pick&&e.push(i.klass.now),n&&e.push(i.klass.selected),r&&e.push(i.klass.highlighted),s&&e.push(i.klass.disabled),e.join(" ")}([i.klass.day]),"data-pick="+t.pick+" "+o.ariaAttr({role:"gridcell",selected:n&&e.$node.val()===o.trigger(e.formats.toString,e,[i.format,t])?!0:null,activedescendant:r?!0:null,disabled:s?!0:null})),"",o.ariaAttr({role:"presentation"})]}})]}})),i.klass.table,'id="'+e.$node[0].id+'_table" '+o.ariaAttr({role:"grid",controls:e.$node[0].id,readonly:!0}))+o.node("div",o.node("button",i.today,i.klass.buttonToday,"type=button data-pick="+a.pick+(t&&!e.disabled(a)?"":" disabled")+" "+o.ariaAttr({controls:e.$node[0].id}))+o.node("button",i.clear,i.klass.buttonClear,"type=button data-clear=1"+(t?"":" disabled")+" "+o.ariaAttr({controls:e.$node[0].id}))+o.node("button",i.close,i.klass.buttonClose,"type=button data-close=true "+(t?"":" disabled")+" "+o.ariaAttr({controls:e.$node[0].id})),i.klass.footer)},i.defaults=function(t){return{labelMonthNext:"Next month",labelMonthPrev:"Previous month",labelMonthSelect:"Select a month",labelYearSelect:"Select a year",monthsFull:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],weekdaysFull:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],today:"Today",clear:"Clear",close:"Close",format:"d mmmm, yyyy",klass:{table:t+"table",header:t+"header",navPrev:t+"nav--prev",navNext:t+"nav--next",navDisabled:t+"nav--disabled",month:t+"month",year:t+"year",selectMonth:t+"select--month",selectYear:t+"select--year",weekdays:t+"weekday",day:t+"day",disabled:t+"day--disabled",selected:t+"day--selected",highlighted:t+"day--highlighted",now:t+"day--today",infocus:t+"day--infocus",outfocus:t+"day--outfocus",footer:t+"footer",buttonClear:t+"button--clear",buttonToday:t+"button--today",buttonClose:t+"button--close"}}}(t.klasses().picker+"__"),t.extend("pickadate",i)}),function(){var t=jQuery;!function(t){function e(e){return t.map(e.split("."),function(t){return parseInt(t,10)})}t.versioncompare=function(i,n){if("undefined"==typeof i)throw new Error("$.versioncompare needs at least one parameter.");if(n=n||t.fn.jquery,i==n)return 0;for(var r=e(i),o=e(n),s=Math.max(r.length,o.length),a=0;s>a;a++)if(r[a]=r[a]||0,o[a]=o[a]||0,r[a]!=o[a])return r[a]>o[a]?1:-1;return 0}}(jQuery),1===t.versioncompare("1.4.4",t().jquery)&&(t.fn.data=function(e,i){if(void 0!==i)return this.attr("data-"+e,i),this;if(void 0!==e)return this.attr("data-"+e);var n={};return t.each(this[0].attributes,function(){"data-"==this.name.substring(0,5)&&(n[this.name.substring(5)]=this.value)}),n},jQuery.expr[":"].focus=function(t){return t===document.activeElement&&(t.type||t.href)}),1===t.versioncompare("1.6",t().jquery)&&(t.fn.prop=t.fn.attr),1===t.versioncompare("1.5",t().jquery)&&(t._data=function(e){return t.data(e)}),t.fn.on||(t.fn.on=function(e,i,n){if("[object Object]"==Object.prototype.toString.call(e)){var r=this;t.each(e,function(t,e){r.on(t,e)})}else"[object Function]"==Object.prototype.toString.call(i)&&(n=i,i=""),t.fn.delegate&&i?this.delegate(i,e,n):i?t(i).live(e,n):this.bind(e,n);return this}),t.fn.off||(t.fn.off=function(t){return this.unbind(t),this}),t(function(){function e(){return/leclick\.dev$/.test(window.location.host)?"//leclick.dev":/leclick\.myterranet\.com$/.test(window.location.host)?"//leclick.myterranet.com":"//old.leclick.ru"}function i(i){i=t(i);var n=e(),r=i.data("lang");r&&"ru"!=r&&(n+="/"+r);var o=i.attr("data-remote-id");o=o?o.split(","):[];var s=i.attr("data-restaurant-id");s=s?s.split(","):[],n+=o.length>1||s.length>1?"/booking/restaurants":"/booking/partners";var a={restaurantId:"restaurant-id",remoteId:"remote-id",id:"id",partner:"partner",params:"params",header:"header",tab:"tab",from:"from",date:"date",time:"time",persons:"persons",beelineBarcode:"beeline-barcode",notifyToGCalendar:"notify-to-g-calendar",firstName:"first-name",lastName:"last-name",email:"email",fullPhone:"full-phone",wishes:"wishes",color:"color",container:"container",listName:"list-name",list:"list"};return t.each(a,function(t,e){var r=i.attr("data-"+e);r&&(n+="/"+t+"/"+encodeURIComponent(r))}),n}window.leclickPopup=function(e,i){var n,r,o,s,a,c=/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/;if(!i&&"string"==t.type(e)){var l=e.match(c);l&&(l[2]?o=!0:i=!0)}if(n=t(".leclick-popup-container"),n.length||(n=t('
'),n.hide(),t("body").append(n),n.stop(!0,!0).fadeIn("fast")),o&&(s=t(e),a=t("
"),a.insertAfter(s)),t.data(n[0],"container",o?e:null),t.data(n[0],"replacement",o?a:null),n.find(".leclick-popup-loading").show(),r=n.find(".leclick-popup-block"),i){var u=e.match(c),h=u?t(e):e,f=u?h.find("img:last"):null;if(f&&f.length){r.stop(!0,!0).fadeOut("fast");var d=function(){r.html(h),window.leclickPopup.success()};f.load(d).error(d)}else r.html(h),window.leclickPopup.success()}else o?(r.html(s),window.leclickPopup.success()):(r.stop(!0,!0).fadeOut("fast"),r.load(e,function(t,e){"error"==e&&r.html('
'+t+"
"),window.leclickPopup.success()}));return this},window.leclickPopup.success=function(){var e=t(".leclick-popup-container"),i=e.find(".leclick-popup-block"),n=e.find(".leclick-popup-loading");n.hide(),i.stop(!0,!0).fadeIn("fast"),i.prepend('
'),i.on("click",".leclick-popup-close",function(t){t.preventDefault(),window.leclickPopup.close()}),i.on("click",".leclick-popup-close-btn",function(t){if(t.preventDefault(),i.find(".leclick-r-content").hasClass("leclick-booking-success"))window.leclickPopup.close();else{var e=i.find(".leclick-popup-close-block");e.length?e.addClass("leclick-active"):window.leclickPopup.close()}}),i.on("click",".leclick-popup-close-block-btn",function(t){t.preventDefault(),i.find(".leclick-popup-close-block").removeClass("leclick-active")}),window.leclickPopup.resize(!0),t(window).unbind("resize",window.leclickPopup.resize).bind("resize",window.leclickPopup.resize)},window.leclickPopup.resize=function(e){var i=t(".leclick-popup-container"),n=i.find(".leclick-popup-block"),r=t(window),o=r.height(),s=r.width(),a=n.outerHeight(!0),c=n.outerWidth(!0),l=(o-a)/2,u=(s-c)/2,h=0>l||0>u,f=t("body");if(i.css({height:"100%",width:"100%",position:"fixed"}),h){i.css("position","absolute"),l=r.scrollTop();var d=f.outerHeight(!0);o=d+a-(d-l),d>o?o=d:i.css({height:o});var p=f.outerWidth(!0);s=c,p>s?s=p:i.css({width:s})}if(e)if(h)n.css({top:l+"px",left:0>u?0:u});else{var g=l/o*100,v=u/s*100;0>g&&(g=0),0>v&&(v=0),n.css({top:g+"%",left:v+"%"})}},window.leclickPopup.close=function(){var e=t(".leclick-popup-container");e.find(".leclick-r-content").hasClass("leclick-booking-success")||window.leclickSendInfo(e.find(".leclick-r-content"));var i=t.data(e[0],"container");e.fadeOut("fast",function(){if(i){var n=e.find(".leclick-popup-block").find(i);t.data(e[0],"replacement").replaceWith(n)}t(this).remove()})},window.leclickSendInfo=function(i){i=t(i);var n={url:window.location.href,restaurantId:i.data("restaurant-id"),date:i.find(".leclick-date").val(),time:i.find(".leclick-time").val(),persons:i.find(".leclick-persons").val(),wishes:i.find(".leclick-wishes").val(),firstName:i.find(".leclick-firstName").val(),lastName:i.find(".leclick-lastName").val(),email:i.find(".leclick-email").val(),fullPhone:i.find(".leclick-fullPhone").val()};if(n.fullPhone&&"7"!==n.fullPhone){var r=[];t.each(n,function(t,e){r.push(t+"="+encodeURIComponent(e))}),t.getScript(e()+"/booking/send-info?"+r.join("&"))}},window.leclickResult=function(e){if(e.list){var i=t("#"+e.list);i.find(".leclick-booking-list").hide(),i.find(".leclick-booking-container").html(e.content).show(),window.leclickPopup.resize(!0),i.on("click",".leclick-back-to-list",function(t){t.preventDefault(),i.find(".leclick-booking-list").show(),i.find(".leclick-booking-container").html("").show(),window.leclickPopup.resize(!0)})}else e.container?t(e.container).html(e.content):window.leclickPopup(e.content,!0)},t(document).on("click",".leclick-reservation",function(e){e.preventDefault(),t.getScript(i(this))});var n=1;t(".leclick-reservation-container").each(function(){var e=t(this),r=i(e),o="leclick-rc-"+n;e.addClass(o),r+="?container=."+o,t.getScript(r),++n}),t(document).on("change",".leclick-popup-container .leclick-time",function(){setTimeout(function(){window.leclickPopup.resize(!0)},1)}),t(document).on("click",".leclick-popup-container .leclick-tabs-nav li,.leclick-reserve-for-other,.leclick-next-step,.leclick-prev-step",function(){setTimeout(function(){window.leclickPopup.resize(!0)},1)})})}(),function(){function t(t){var e=t.__abstracts||[],i=t.__statics||{},n=t.__extend||[];n instanceof Array||(n=[n]);var r;r=t.__construct?t.__construct:n.length?function(){for(var t=0;t1){for(var e=!0,i=0;i"+e+"")}),a('
    ').html(i.join("")).insertAfter(t.parents(".leclick-controls"))}var a=jQuery;window.leclickGetParentBlock=n,window.leclickSchema={},window.leclickDepositBookingTime={},window.leclickBanquetSchema={},window.leclickBanquetDepositBookingTime={},window.schemas={},window.leclickUpdateSchema=function(t,e){var i=[];a.each(e.bookingTime,function(t,e){i.push('")}),e.banquet?(window.leclickBanquetSchema[t]=e.schema,window.leclickBanquetDepositBookingTime[t]=e.depositBookingTime,a("#"+t+"-rb-time").html(i.join("")).change(),e.schema.specialService?a("#"+t+"-rb-special-service").show():a("#"+t+"-rb-special-service").hide()):(window.schemas[t].setSchema(e.schema),window.leclickSchema[t]=e.schema,window.leclickDepositBookingTime[t]=e.depositBookingTime,a("#"+t+"-rt-time").html(i.join("")).change(),e.schema.specialService?a("#"+t+"-rt-special-service").show():a("#"+t+"-rt-special-service").hide())},window.leclickBookingResult=function(t,i){var n=a("#"+t),r=n.find(".leclick-step.leclick-active:first");switch(r.find(".leclick-error,.leclick-error-block").remove(),n.data("new-id",i.id),i.type){case"success":"undefined"!=typeof Storage&&n.find(".leclick-saveInfo")&&(localStorage.setItem("booking_"+t+"_firstName",n.find(".leclick-firstName").val()),localStorage.setItem("booking_"+t+"_lastName",n.find(".leclick-lastName").val()),localStorage.setItem("booking_"+t+"_email",n.find(".leclick-email").val()),localStorage.setItem("booking_"+t+"_fullPhone",n.find(".leclick-fullPhone").val())),window.buberStats&&window.buberStats.postTransaction({orderId:i.id}),i.row.tinkoffPortalId&&window.parent&&window.parent.postMessage&&window.parent.postMessage(JSON.stringify({portalId:i.row.tinkoffPortalId,orderId:i.row.id,restaurantId:i.row.restaurantId,bookingDateTime:i.row.timeFrom}),"*"),i.redirect?window.location=i.redirect:(e(n.find(".leclick-step.leclick-active:last")),n.addClass("leclick-booking-success")); break;case"error":if(i.element)s(n.find("[name="+i.element+"]"),[i.message]);else{var o='
    • '+i.message+"
    ";r.find("form").length?r.find("form").prepend(o):n.find("form .leclick-step.leclick-active:first .leclick-step-content").prepend(o)}}window.leclickPopup.resize(!0)},window.leclickSendPhoneCode=function(t,e){var i=a("#"+t+" .leclick-step.leclick-active");switch(i.find(".leclick-error").remove(),e.type){case"success":i.find(".leclick-phoneApproveCode-block").show(),i.find(".leclick-sendPhoneCode-block").removeClass("leclick-sendPhoneCode-disabled");break;case"error":i.find("form").prepend('

    '+e.message+"

    "),i.find(".leclick-phoneApproveCode-block").hide(),i.find(".leclick-sendPhoneCode-block").addClass("leclick-sendPhoneCode-disabled")}},window.leclickInviteResult=function(t,e){switch(e.type){case"success":a("#"+t+" .leclick-invitation-block").remove(),window.leclickPopup.close();break;case"error":alert(e.message)}},window.leclickOnResize=function(){a(".leclick-deposit-info").each(function(){var t=a(this),e=t.parents("form");a(window).width()<=460?t.insertAfter(e.find(".leclick-time").parents(".leclick-control-group:first")):t.insertAfter(e.find(".leclick-persons").parents(".leclick-control-group:first"))})},a(function(){function t(t){var e=!0;return a.each(["source"],function(i,n){var r=t.find(".leclick-"+n);!r.length||r.val()||void 0!=r.data("required")&&!r.data("required")||(r.parents(".leclick-control-group").addClass("leclick-error"),e=!1)}),e}function c(t){var e=!0;a.each(["firstName","email","phone","fullPhone"],function(i,n){var r=t.find(".leclick-"+n);!r.length||r.val()||void 0!=r.data("required")&&!parseInt(r.data("required"))||(r.parents(".leclick-control-group").addClass("leclick-error"),s(r,["Поле не может быть пустым."]),e=!1)});var i=t.find(".leclick-fullPhone");return"7"==i.val()&&(i.parents(".leclick-control-group").addClass("leclick-error"),s(i,["Поле не может быть пустым."]),e=!1),e}a(window).resize(function(){window.leclickOnResize()}),a(document).on("click",".leclick-tabs-nav a",function(t){t.preventDefault();var e=a(this);e.parent().addClass("leclick-active").siblings().removeClass("leclick-active"),n(e).find(".leclick-tab-item").removeClass("leclick-tab-active").filter(e.attr("href")).addClass("leclick-tab-active")}),a(document).on("change",".leclick-phoneCode",function(){var t=a(this),e=t.find("option:selected"),i=parseInt(e.data("length"));if(!isNaN(i)&&i>0){var r=n(this).find(".leclick-phone");r.attr("maxlength",i).val(r.val().substring(0,i))}}),a(document).on("change",".leclick-time",function(){a(this).prev("label").text(a(this).find("option:selected").data("text"))}),a(document).on("change",".leclick-source",function(){a(this).prev("label").text(a(this).find("option:selected").data("text"))}),a(document).on("change",".leclick-persons",function(){a(this).prev("label").find(".leclick-persons-text").text(a(this).find("option:selected").text())}),a(document).on("change",".leclick-time,.leclick-persons",function(){var t=a(this),e=t.parents("form"),i=n(t),r=i.attr("id"),o=e.find(".leclick-time"),s=o.attr("id")==r+"-rb-time",c=window[s?"leclickBanquetDepositBookingTime":"leclickDepositBookingTime"][r][o.val()],l=e.find(".leclick-deposit-info"),u=e.find(".leclick-price");if(c){l.show(),l.find(".leclick-description").html(c.depositDescription);var h=c.deposit;parseInt(c.fixedDeposit)||(h*=e.find(".leclick-persons").val()),u.show(),u.find(".leclick-deposit-price").text(h)}else l.hide(),u.hide()}),a(document).on("change",".leclick-select",function(){a(this).prev("label").text(a(this).find("option:selected").text()||"--")}),a(document).on("click",".leclick-reserve-for-other",function(){a(a(this).data("block")).toggle()}),a(document).on("change",".leclick-date",function(){var t=a(this),e=n(t),r=e.attr("id"),o=i()+"/booking/schema/restaurantId/"+e.data("restaurant-id")+"/uniqId/"+r+"/date/"+t.val();t.attr("id")==r+"-rb-date"&&(o+="/banquet/1"),a.getScript(o)}),a(document).on("change",".leclick-time,.leclick-persons",function(){var t=a(this),e=n(t),i=e.attr("id");if(t.attr("id")==i+"-rt-time"||t.attr("id")==i+"-rt-persons"){var r=a("#"+i+"-rt-time").val(),o=a("#"+i+"-rt-persons").val();if(window.leclickSchema[i].halls){var s=[''],c=[];a.each(window.leclickSchema[i].halls,function(t,e){var i=[];a.each(e.tables,function(t,e){-1===a.inArray(r,e.bookingTime)&&parseInt(e.row.persons)>=parseInt(o)&&i.push('")}),i.length&&(s.push(''+i.join("")+""),c.push('"))});var l=a("#"+i+"-rt-tableId"),u=l.val();l.html(s.join("")).val(u).change(),a("#"+i+"-hallId").html(c.join("")).change()}}}),a(document).on("click",".leclick-next-step",function(){a(this).parents("form").addClass("leclick-active")}),a(document).on("click",".leclick-prev-step",function(){a(this).parents("form").removeClass("leclick-active"),r(this),n(this).find(".leclick-step.leclick-active form").removeClass("leclick-active")}),a(document).on("click",".leclick-next-step1",function(){var i=a(this).parents("form");i.find(".leclick-error-list").remove(),i.find(".leclick-control-group").removeClass("leclick-error"),t(i)&&(n(this).find(".leclick-step2").length?e(this):o(this))}),a(document).on("click",".leclick-next-step2",function(){var t=a(this).parents("form");t.find(".leclick-error-list").remove(),t.find(".leclick-control-group").removeClass("leclick-error"),c(t)&&o(this)}),a(document).on("click",".leclick-next-step-all",function(){var e=a(this).parents("form");e.find(".leclick-error-list").remove(),e.find(".leclick-control-group").removeClass("leclick-error");var i=t(e),n=c(e);i&&n&&o(this)}),a(document).on("click",".leclick-sendPhoneCode",function(){var t=a(this),e=n(t);e.find(".leclick-error").remove();var r=e.attr("id"),o=i()+"/booking/change-phone/uniqId/"+r;o+="/phoneCode/"+encodeURIComponent(e.find(".leclick-phoneCode").val()),o+="/phone/"+encodeURIComponent(e.find(".leclick-phone").val()),o+="/fullPhone/"+encodeURIComponent(e.find(".leclick-fullPhone").val()),a.getScript(o)}),a(document).on("click",".leclick-schema-toggle",function(){var t=n(this),e=t.attr("id"),i=t.find(".leclick-schema");0!==parseInt(i.css("left"))?(i.css("left",0),setTimeout(function(){window.schemas[e].calcOffset()},220)):i.css("left","100%")}),a(document).on("change",".leclick-reasonId",function(){var t=a(this);""==t.val()?t.parents(".leclick-control-group:first").find(".leclick-otherReason").show():t.parents(".leclick-control-group:first").find(".leclick-otherReason").hide()}),a(window).bind("beforeunload",function(){a(".leclick-r-content").each(function(){a(this).hasClass("leclick-booking-success")||window.leclickSendInfo(this)})}),a(document).on("click",".leclick-new-invite",function(t){t.preventDefault();var e=n(this),i=e.find(".leclick-invite-list"),r=i.find(".leclick-invite:last").clone();r.find("input").val(""),i.append(r),a(this).hide().siblings(".leclick-del-invite").show(),window.leclickPopup.resize(!0)}),a(document).on("click",".leclick-del-invite",function(t){t.preventDefault(),a(this).parents(".leclick-invite:first").remove(),window.leclickPopup.resize(!0)}),a(document).on("click",".leclick-send-invites",function(t){t.preventDefault();var e=[],r=n(this);r.find(".leclick-invite-list .leclick-invites").each(function(){a(this).val()&&e.push(a(this).val())}),e.length&&a.getScript(i()+"/booking/send-invites/uniqId/"+r.attr("id")+"/id/"+r.data("new-id")+"?emails="+encodeURIComponent(e.join(",")))})}),window.leclickSchemaCanvas=t({__construct:function(t){this.uniqId=t,this.container=a("#"+t),this.schema=window.leclickSchema[t],this.initCanvas(),this.init()},initCanvas:function(){var t=this;this.canvas=new fabric.Canvas(this.container.find(".leclick-schema canvas").attr("id"),{selection:!1,hoverCursor:"pointer"}),this.canvas.on({"object:selected":function(e){t.selectTable(e.target.id)}}),a(this.container).on("click",".leclick-schema .leclick-tableName",function(){t.selectTable(a(this).data("id"))}),a(this.container).on("change",".leclick-hallId",function(){t.setHall(a(this).val())})},init:function(){this.container.find(".leclick-hallId").change()},calcOffset:function(){this.canvas.calcOffset()},setSchema:function(t){return this.schema=t,this},setHall:function(t){var e=this;if(this.canvas.clear(),this.container.find(".leclick-schema .leclick-tableName").remove(),!this.schema.halls)return this;var i=this.schema.halls[t];if(!i)return this;var n=e.container.find(".leclick-rt-time").val(),r=e.container.find(".leclick-tableId").val(),o=e.container.find(".leclick-rt-persons").val(),s=parseInt(i.row.width),c=parseInt(i.row.height);return this.canvas.setWidth(s),this.canvas.setHeight(c),this._ranks=[],this._elements={},i.decorators&&a.each(i.decorators,function(t,i){e.storeElement(i,"decorator")}),i.tables&&a.each(i.tables,function(t,i){e.storeElement(i,"table",n,o)}),this._ranks.sort(function(t,e){return t-e}),a.each(this._ranks,function(t,i){a.each(e._elements[i],function(t,i){var n={top:i.top,left:i.left,hasControls:!1,hasBorders:!1,lockMovementX:!0,lockMovementY:!0};switch(i.type){case"table":e.createTable(i,n,r);break;case"circle":e.createCircle(i,n);break;case"rectangle":e.createRect(i,n);break;case"text":e.createText(i,n)}})}),this.canvas.renderAll(),this},createTable:function(t,e,i){var n=this;return fabric.Image.fromURL(t.src,function(r){r.id=t.id,r.type="table";var o=t.overlay?"leclick-red":i==t.id?"leclick-brown":"leclick-green",s=a(''+t.name+"").css({position:"absolute",display:"block"});n.container.find(".canvas-container").append(s),s.css({left:e.left-s.outerWidth(!0)/2,top:e.top-s.outerHeight(!0)/2}),a(".canvas-container").append(s),r.setOptions(a.extend({angle:t.angle,perPixelTargetFind:!0,overlay:t.overlay},e)),n.canvas.add(r)}),this},createCircle:function(t,e){var i=new fabric.Circle({perPixelTargetFind:!0,fill:t.color,width:t.width,height:t.height,radius:t.width/2,overlay:!0});return i.setOptions(e),this.canvas.add(i),this},createRect:function(t,e){var i=new fabric.Rect({perPixelTargetFind:!0,fill:t.color,width:t.width,height:t.height,angle:t.angle,overlay:!0});return i.setOptions(e),this.canvas.add(i),this},createText:function(t,e){var i=new fabric.Text(t.name,{fill:t.color,angle:t.angle,fontFamily:"Arial",fontSize:t.fontSize,overlay:!0});return i.setOptions(e),this.canvas.add(i),this},storeElement:function(t,e,i,n){var r=t.row,o=parseInt(r.rank,10);-1===a.inArray(o,this._ranks)&&(this._ranks.push(o),this._elements[o]=[]);var s={id:parseInt(r.id,10),type:"decorator"==e?r.type:"table",name:r.name,top:parseInt(r.top,10),left:parseInt(r.left),angle:r.angle?parseFloat(r.angle):0};switch(e){case"table":s.src=r.image,s.overlay=!(a.inArray(parseInt(i),t.bookingTime)>-1&&r.persons>=n);break;case"decorator":s.width=parseInt(r.width,10),s.height=parseInt(r.height,10),s.color=r.color,s.fontSize=r.fontSize?parseInt(r.fontSize,10):0}return this._elements[o].push(s),this},selectTable:function(t){var e=this;this.container.find(".leclick-tableId").val(t).change(),this.canvas.forEachObject(function(i){if("table"==i.type&&!i.overlay){var n=a("#"+e.uniqId+"-tableName-"+i.id);n.removeClass("leclick-green leclick-brown").addClass(i.id==t?"leclick-brown":"leclick-green").css({left:i.left-n.outerWidth(!0)/2,top:i.top-n.outerHeight(!0)/2})}}),this.container.find(".leclick-schema-toggle:first").trigger("click")}})}();var fabric=fabric||{version:"1.1.0"};"undefined"!=typeof exports&&(exports.fabric=fabric),"undefined"!=typeof document&&"undefined"!=typeof window?(fabric.document=document,fabric.window=window):(fabric.document=require("jsdom").jsdom(""),fabric.window=fabric.document.createWindow()),fabric.isTouchSupported="ontouchstart"in fabric.document.documentElement,fabric.isLikelyNode="undefined"!=typeof Buffer&&"undefined"==typeof window;var Cufon=function(){function t(t){var e=this.face=t.face;this.glyphs=t.glyphs,this.w=t.w,this.baseSize=parseInt(e["units-per-em"],10),this.family=e["font-family"].toLowerCase(),this.weight=e["font-weight"],this.style=e["font-style"]||"normal",this.viewBox=function(){var t=e.bbox.split(/\s+/),i={minX:parseInt(t[0],10),minY:parseInt(t[1],10),maxX:parseInt(t[2],10),maxY:parseInt(t[3],10)};return i.width=i.maxX-i.minX,i.height=i.maxY-i.minY,i.toString=function(){return[this.minX,this.minY,this.width,this.height].join(" ")},i}(),this.ascent=-parseInt(e.ascent,10),this.descent=-parseInt(e.descent,10),this.height=-this.ascent+this.descent}function e(){var t={},e={oblique:"italic",italic:"oblique"};this.add=function(e){(t[e.style]||(t[e.style]={}))[e.weight]=e},this.get=function(i,n){var r=t[i]||t[e[i]]||t.normal||t.italic||t.oblique;if(!r)return null;if(n={normal:400,bold:700}[n]||parseInt(n,10),r[n])return r[n];var o,s,a={1:1,99:0}[n%100],c=[];void 0===a&&(a=n>400),500==n&&(n=400);for(var l in r)l=parseInt(l,10),(!o||o>l)&&(o=l),(!s||l>s)&&(s=l),c.push(l);return o>n&&(n=o),n>s&&(n=s),c.sort(function(t,e){return(a?t>n&&e>n?e>t:t>e:n>t&&n>e?t>e:e>t)?-1:1}),r[c[0]]}}function i(){function t(t,e){return t.contains?t.contains(e):16&t.compareDocumentPosition(e)}function e(e){var i=e.relatedTarget;i&&!t(this,i)&&n(this)}function i(t){n(this)}function n(t){setTimeout(function(){d.replace(t,m.get(t).options,!0)},10)}this.attach=function(t){void 0===t.onmouseenter?(o(t,"mouseover",e),o(t,"mouseout",e)):(o(t,"mouseenter",i),o(t,"mouseleave",i))}}function n(){function t(t){return t.cufid||(t.cufid=++i)}var e={},i=0;this.get=function(i){var n=t(i);return e[n]||(e[n]={})}}function r(t){var e={},i={};this.get=function(i){return void 0!=e[i]?e[i]:t[i]},this.getSize=function(t,e){return i[t]||(i[t]=new g.Size(this.get(t),e))},this.extend=function(t){for(var i in t)e[i]=t[i];return this}}function o(t,e,i){t.addEventListener?t.addEventListener(e,i,!1):t.attachEvent&&t.attachEvent("on"+e,function(){return i.call(t,fabric.window.event)})}function s(t,e){var i=m.get(t);return i.options?t:(e.hover&&e.hoverables[t.nodeName.toLowerCase()]&&b.attach(t),i.options=e,t)}function a(t){var e={};return function(i){return e.hasOwnProperty(i)||(e[i]=t.apply(null,arguments)),e[i]}}function c(t,e){e||(e=g.getStyle(t));for(var i,n=g.quotedList(e.get("fontFamily").toLowerCase()),r=0,o=n.length;o>r;++r)if(i=n[r],w[i])return w[i].get(e.get("fontStyle"),e.get("fontWeight"));return null}function l(t){return fabric.document.getElementsByTagName(t)}function u(){for(var t,e={},i=0,n=arguments.length;n>i;++i)for(t in arguments[i])e[t]=arguments[i][t];return e}function h(t,e,i,n,r,o){var s=n.separate;if("none"==s)return x[n.engine].apply(null,arguments);var a,c=fabric.document.createDocumentFragment(),l=e.split(C[s]),u="words"==s;u&&v&&(/^\s/.test(e)&&l.unshift(""),/\s$/.test(e)&&l.push(""));for(var h=0,f=l.length;f>h;++h)a=x[n.engine](t,u?g.textAlign(l[h],i,h,f):l[h],i,n,r,o,f-1>h),a&&c.appendChild(a);return c}function f(t,e){for(var i,n,r,o,a=s(t,e).firstChild;a;a=r){if(r=a.nextSibling,o=!1,1==a.nodeType){if(!a.firstChild)continue;if(!/cufon/.test(a.className)){arguments.callee(a,e);continue}o=!0}if(n||(n=g.getStyle(t).extend(e)),i||(i=c(t,n)),i)if(o)x[e.engine](i,null,n,e,a,t);else{var l=a.data;if("undefined"!=typeof G_vmlCanvasManager&&(l=l.replace(/\r/g,"\n")),""!==l){var u=h(i,l,n,e,a,t);u?a.parentNode.replaceChild(u,a):a.parentNode.removeChild(a)}}}}var d=function(){return d.replace.apply(null,arguments)},p=d.DOM={ready:function(){var t=!1,e={loaded:1,complete:1},i=[],n=function(){if(!t){t=!0;for(var e;e=i.shift();e());}};return fabric.document.addEventListener&&(fabric.document.addEventListener("DOMContentLoaded",n,!1),fabric.window.addEventListener("pageshow",n,!1)),!fabric.window.opera&&fabric.document.readyState&&function(){e[fabric.document.readyState]?n():setTimeout(arguments.callee,10)}(),fabric.document.readyState&&fabric.document.createStyleSheet&&function(){try{fabric.document.body.doScroll("left"),n()}catch(t){setTimeout(arguments.callee,1)}}(),o(fabric.window,"load",n),function(e){arguments.length?t?e():i.push(e):n()}}()},g=d.CSS={Size:function(t,e){this.value=parseFloat(t),this.unit=String(t).match(/[a-z%]*$/)[0]||"px",this.convert=function(t){return t/e*this.value},this.convertFrom=function(t){return t/this.value*e},this.toString=function(){return this.value+this.unit}},getStyle:function(t){return new r(t.style)},quotedList:a(function(t){for(var e,i=[],n=/\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g;e=n.exec(t);)i.push(e[3]||e[1]);return i}),ready:function(){var t=!1,e=[],i=function(){t=!0;for(var i;i=e.shift();i());},n=Object.prototype.propertyIsEnumerable?l("style"):{length:0},r=l("link");return p.ready(function(){for(var t,e=0,o=0,s=r.length;t=r[o],s>o;++o)t.disabled||"stylesheet"!=t.rel.toLowerCase()||++e;fabric.document.styleSheets.length>=n.length+e?i():setTimeout(arguments.callee,10)}),function(i){t?i():e.push(i)}}(),supports:function(t,e){var i=fabric.document.createElement("span").style;return void 0===i[t]?!1:(i[t]=e,i[t]===e)},textAlign:function(t,e,i,n){return"right"==e.get("textAlign")?i>0&&(t=" "+t):n-1>i&&(t+=" "),t},textDecoration:function(t,e){e||(e=this.getStyle(t));for(var i={underline:null,overline:null,"line-through":null},n=t;n.parentNode&&1==n.parentNode.nodeType;){var r=!0;for(var o in i)i[o]||(-1!=e.get("textDecoration").indexOf(o)&&(i[o]=e.get("color")),r=!1);if(r)break;e=this.getStyle(n=n.parentNode)}return i},textShadow:a(function(t){if("none"==t)return null;for(var e,i=[],n={},r=0,o=/(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)|(-?[\d.]+[a-z%]*)|,/gi;e=o.exec(t);)","==e[0]?(i.push(n),n={},r=0):e[1]?n.color=e[1]:n[["offX","offY","blur"][r++]]=e[2];return i.push(n),i}),color:a(function(t){var e={};return e.color=t.replace(/^rgba\((.*?),\s*([\d.]+)\)/,function(t,i,n){return e.opacity=parseFloat(n),"rgb("+i+")"}),e}),textTransform:function(t,e){return t[{uppercase:"toUpperCase",lowercase:"toLowerCase"}[e.get("textTransform")]||"toString"]()}},v=0==" ".split(/\s+/).length,m=new n,b=new i,y=[],x={},w={},k={engine:null,hover:!1,hoverables:{a:!0},printable:!0,selector:fabric.window.Sizzle||fabric.window.jQuery&&function(t){return jQuery(t)}||fabric.window.dojo&&dojo.query||fabric.window.$$&&function(t){return $$(t)}||fabric.window.$&&function(t){return $(t)}||fabric.document.querySelectorAll&&function(t){return fabric.document.querySelectorAll(t)}||l,separate:"words",textShadow:"none"},C={words:/\s+/,characters:""};return d.now=function(){return p.ready(),d},d.refresh=function(){for(var t=y.splice(0,y.length),e=0,i=t.length;i>e;++e)d.replace.apply(null,t[e]);return d},d.registerEngine=function(t,e){return e?(x[t]=e,d.set("engine",t)):d},d.registerFont=function(i){var n=new t(i),r=n.family;return w[r]||(w[r]=new e),w[r].add(n),d.set("fontFamily",'"'+r+'"')},d.replace=function(t,e,i){return e=u(k,e),e.engine?("string"==typeof e.textShadow&&e.textShadow&&(e.textShadow=g.textShadow(e.textShadow)),i||y.push(arguments),(t.nodeType||"string"==typeof t)&&(t=[t]),g.ready(function(){for(var i=0,n=t.length;n>i;++i){var r=t[i];"string"==typeof r?d.replace(e.selector(r),e,!0):f(r,e)}}),d):d},d.replaceElement=function(t,e){return e=u(k,e),"string"==typeof e.textShadow&&e.textShadow&&(e.textShadow=g.textShadow(e.textShadow)),f(t,e)},d.engines=x,d.fonts=w,d.getOptions=function(){return u(k)},d.set=function(t,e){return k[t]=e,d},d}();Cufon.registerEngine("canvas",function(){function t(t,e){var i,n=0,r=0,o=[],s=/([mrvxe])([^a-z]*)/g;t:for(var a=0;i=s.exec(t);++a){var c=i[2].split(",");switch(i[1]){case"v":o[a]={m:"bezierCurveTo",a:[n+~~c[0],r+~~c[1],n+~~c[2],r+~~c[3],n+=~~c[4],r+=~~c[5]]};break;case"r":o[a]={m:"lineTo",a:[n+=~~c[0],r+=~~c[1]]};break;case"m":o[a]={m:"moveTo",a:[n=~~c[0],r=~~c[1]]};break;case"x":o[a]={m:"closePath",a:[]};break;case"e":break t}e[o[a].m].apply(e,o[a].a)}return o}function e(t,e){for(var i=0,n=t.length;n>i;++i){var r=t[i];e[r.m].apply(e,r.a)}}var i=Cufon.CSS.supports("display","inline-block"),n=!i&&("BackCompat"==fabric.document.compatMode||/frameset|transitional/i.test(fabric.document.doctype.publicId)),r=fabric.document.createElement("style");r.type="text/css";var o=fabric.document.createTextNode(".cufon-canvas{text-indent:0}@media screen,projection{.cufon-canvas{display:inline;display:inline-block;position:relative;vertical-align:middle"+(n?"":";font-size:1px;line-height:1px")+"}.cufon-canvas .cufon-alt{display:-moz-inline-box;display:inline-block;width:0;height:0;overflow:hidden}"+(i?".cufon-canvas canvas{position:relative}":".cufon-canvas canvas{position:absolute}")+"}@media print{.cufon-canvas{padding:0 !important}.cufon-canvas canvas{display:none}.cufon-canvas .cufon-alt{display:inline}}");try{r.appendChild(o)}catch(s){r.setAttribute("type","text/css"),r.styleSheet.cssText=o.data}return fabric.document.getElementsByTagName("head")[0].appendChild(r),function(n,r,o,s,a,c){function l(){H.save();var t=0,e=0,i=[{left:0}];s.backgroundColor&&(H.save(),H.fillStyle=s.backgroundColor,H.translate(0,n.ascent),H.fillRect(0,0,T+10,(-n.ascent+n.descent)*P),H.restore()),"right"===s.textAlign?(H.translate(M[e],0),i[0].left=M[e]*q):"center"===s.textAlign&&(H.translate(M[e]/2,0),i[0].left=M[e]/2*q);for(var r=0,o=E.length;o>r;++r)if("\n"!==E[r]){var a=n.glyphs[E[r]]||n.missingGlyph;if(a){var c=Number(a.w||n.w)+p;s.textBackgroundColor&&(H.save(),H.fillStyle=s.textBackgroundColor,H.translate(0,n.ascent),H.fillRect(0,0,c+10,-n.ascent+n.descent),H.restore()),H.translate(c,0),t+=c,r==o-1&&(i[i.length-1].width=t*q,i[i.length-1].height=(-n.ascent+n.descent)*q)}}else{e++;var l=-n.ascent-n.ascent/5*s.lineHeight,u=i[i.length-1],h={left:0};u.width=t*q,u.height=(-n.ascent+n.descent)*q,"right"===s.textAlign?(H.translate(-T,l),H.translate(M[e],0),h.left=M[e]*q):"center"===s.textAlign?(H.translate(-t-M[e-1]/2,l),H.translate(M[e]/2,0),h.left=M[e]/2*q):H.translate(-t,l),i.push(h),t=0}H.restore(),Cufon.textOptions.boundaries=i}function u(i){H.fillStyle=i||Cufon.textOptions.color||o.get("color");var r=0,a=0;"right"===s.textAlign?H.translate(M[a],0):"center"===s.textAlign&&H.translate(M[a]/2,0);for(var c=0,l=E.length;l>c;++c)if("\n"!==E[c]){var u=n.glyphs[E[c]]||n.missingGlyph;if(u){var h=Number(u.w||n.w)+p;$&&(H.save(),H.strokeStyle=H.fillStyle,H.lineWidth+=H.lineWidth,H.beginPath(),$.underline&&(H.moveTo(0,-n.face["underline-position"]+.5),H.lineTo(h,-n.face["underline-position"]+.5)),$.overline&&(H.moveTo(0,n.ascent+.5),H.lineTo(h,n.ascent+.5)),$["line-through"]&&(H.moveTo(0,-n.descent+.5),H.lineTo(h,-n.descent+.5)),H.stroke(),H.restore()),J&&(H.save(),H.transform(1,0,-.25,1,0,0)),H.beginPath(),u.d&&(u.code?e(u.code,H):u.code=t("m"+u.d,H)),H.fill(),s.strokeStyle&&(H.closePath(),H.save(),H.lineWidth=s.strokeWidth,H.strokeStyle=s.strokeStyle,H.stroke(),H.restore()),J&&H.restore(),H.translate(h,0),r+=h}}else{a++;var f=-n.ascent-n.ascent/5*s.lineHeight;"right"===s.textAlign?(H.translate(-T,f),H.translate(M[a],0)):"center"===s.textAlign?(H.translate(-r-M[a-1]/2,f),H.translate(M[a]/2,0)):H.translate(-r,f),r=0}}var h=null===r,f=n.viewBox,d=o.getSize("fontSize",n.baseSize),p=o.get("letterSpacing");p="normal"==p?0:d.convertFrom(parseInt(p,10));var g=0,v=0,m=0,b=0,y=s.textShadow,x=[];if(Cufon.textOptions.shadowOffsets=[],Cufon.textOptions.shadows=null,y){Cufon.textOptions.shadows=y;for(var w=0,k=y.length;k>w;++w){var C=y[w],_=d.convertFrom(parseFloat(C.offX)),S=d.convertFrom(parseFloat(C.offY));x[w]=[_,S]}}for(var E=Cufon.CSS.textTransform(h?a.alt:r,o).split(""),T=0,O=null,j=0,P=1,A=[],w=0,k=E.length;k>w;++w)if("\n"!==E[w]){var I=n.glyphs[E[w]]||n.missingGlyph;I&&(T+=O=Number(I.w||n.w)+p)}else P++,T>j&&(j=T),A.push(T),T=0;A.push(T),T=Math.max(j,T);for(var M=[],w=A.length;w--;)M[w]=T-A[w];if(null===O)return null;v+=f.width-O,b+=f.minX;var D,F;if(h)D=a,F=a.firstChild;else if(D=fabric.document.createElement("span"),D.className="cufon cufon-canvas",D.alt=r,F=fabric.document.createElement("canvas"),D.appendChild(F),s.printable){var G=fabric.document.createElement("span");G.className="cufon-alt",G.appendChild(fabric.document.createTextNode(r)),D.appendChild(G)}var L=D.style,R=F.style||{},N=d.convert(f.height-g+m),X=Math.ceil(N),Y=X/N;F.width=Math.ceil(d.convert(T+v-b)*Y),F.height=X,g+=f.minY,R.top=Math.round(d.convert(g-n.ascent))+"px",R.left=Math.round(d.convert(b))+"px";var B=Math.ceil(d.convert(T*Y)),z=B+"px",W=d.convert(n.height),U=(s.lineHeight-1)*d.convert(-n.ascent/5)*(P-1);Cufon.textOptions.width=B,Cufon.textOptions.height=W*P+U,Cufon.textOptions.lines=P,Cufon.textOptions.totalLineHeight=U,i?(L.width=z,L.height=W+"px"):(L.paddingLeft=z,L.paddingBottom=W-1+"px");var H=Cufon.textOptions.context||F.getContext("2d"),q=X/f.height;Cufon.textOptions.fontAscent=n.ascent*q,Cufon.textOptions.boundaries=null;for(var V=Cufon.textOptions.shadowOffsets,w=x.length;w--;)V[w]=[x[w][0]*q,x[w][1]*q];H.save(),H.scale(q,q),H.translate(-b-1/q*F.width/2+(Cufon.fonts[n.family].offsetLeft||0),-g-Cufon.textOptions.height/q/2+(Cufon.fonts[n.family].offsetTop||0)),H.lineWidth=n.face["underline-thickness"],H.save();var $=Cufon.getTextDecoration(s),J="italic"===s.fontStyle;if(H.save(),l(),y)for(var w=0,k=y.length;k>w;++w){var C=y[w];H.save(),H.translate.apply(H,x[w]),u(C.color),H.restore()}return u(),H.restore(),H.restore(),H.restore(),D}}()),Cufon.registerEngine("vml",function(){function t(t,i){return e(t,/(?:em|ex|%)$/i.test(i)?"1em":i)}function e(t,e){if(/px$/i.test(e))return parseFloat(e);var i=t.style.left,n=t.runtimeStyle.left;t.runtimeStyle.left=t.currentStyle.left,t.style.left=e;var r=t.style.pixelLeft;return t.style.left=i,t.runtimeStyle.left=n,r}if(fabric.document.namespaces){var i=fabric.document.createElement("canvas");if(!(i&&i.getContext&&i.getContext.apply)){null==fabric.document.namespaces.cvml&&fabric.document.namespaces.add("cvml","urn:schemas-microsoft-com:vml");var n=fabric.document.createElement("cvml:shape");if(n.style.behavior="url(#default#VML)",n.coordsize)return n=null,fabric.document.write(''),function(i,n,r,o,s,a,c){var l=null===n;l&&(n=s.alt);var u=i.viewBox,h=r.computedFontSize||(r.computedFontSize=new Cufon.CSS.Size(t(a,r.get("fontSize"))+"px",i.baseSize)),f=r.computedLSpacing;void 0==f&&(f=r.get("letterSpacing"),r.computedLSpacing=f="normal"==f?0:~~h.convertFrom(e(a,f)));var d,p;if(l)d=s,p=s.firstChild;else{if(d=fabric.document.createElement("span"),d.className="cufon cufon-vml",d.alt=n,p=fabric.document.createElement("span"),p.className="cufon-vml-canvas",d.appendChild(p),o.printable){var g=fabric.document.createElement("span");g.className="cufon-alt",g.appendChild(fabric.document.createTextNode(n)),d.appendChild(g)}c||d.appendChild(fabric.document.createElement("cvml:shape"))}var v=d.style,m=p.style,b=h.convert(u.height),y=Math.ceil(b),x=y/b,w=u.minX,k=u.minY;m.height=y,m.top=Math.round(h.convert(k-i.ascent)),m.left=Math.round(h.convert(w)),v.height=h.convert(i.height)+"px";for(var C,_,S=(Cufon.getTextDecoration(o),r.get("color")),E=Cufon.CSS.textTransform(n,r).split(""),T=0,O=0,j=null,P=o.textShadow,A=0,I=0,M=E.length;M>A;++A)C=i.glyphs[E[A]]||i.missingGlyph,C&&(T+=j=~~(C.w||i.w)+f);if(null===j)return null;var D,F=-w+T+(u.width-j),G=h.convert(F*x),L=Math.round(G),R=F+","+u.height,N="r"+R+"nsnf";for(A=0;M>A;++A)if(C=i.glyphs[E[A]]||i.missingGlyph){l?(_=p.childNodes[I],_.firstChild&&_.removeChild(_.firstChild)):(_=fabric.document.createElement("cvml:shape"),p.appendChild(_)),_.stroked="f",_.coordsize=R,_.coordorigin=D=w-O+","+k,_.path=(C.d?"m"+C.d+"xe":"")+"m"+D+N,_.fillcolor=S;var X=_.style;if(X.width=L,X.height=y,P){var Y,B=P[0],z=P[1],W=Cufon.CSS.color(B.color),U=fabric.document.createElement("cvml:shadow");U.on="t",U.color=W.color,U.offset=B.offX+","+B.offY,z&&(Y=Cufon.CSS.color(z.color),U.type="double",U.color2=Y.color,U.offset2=z.offX+","+z.offY),U.opacity=W.opacity||Y&&Y.opacity||1,_.appendChild(U)}O+=~~(C.w||i.w)+f,++I}return v.width=Math.max(Math.ceil(h.convert(T*x)),0),d}}}}()),Cufon.getTextDecoration=function(t){return{underline:"underline"===t.textDecoration,overline:"overline"===t.textDecoration,"line-through":"line-through"===t.textDecoration}},"undefined"!=typeof exports&&(exports.Cufon=Cufon);var JSON;if(JSON||(JSON={}),function(){"use strict";function f(t){return 10>t?"0"+t:t}function quote(t){return escapable.lastIndex=0,escapable.test(t)?'"'+t.replace(escapable,function(t){var e=meta[t];return"string"==typeof e?e:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+t+'"'}function str(t,e){var i,n,r,o,s,a=gap,c=e[t];switch(c&&"object"==typeof c&&"function"==typeof c.toJSON&&(c=c.toJSON(t)),"function"==typeof rep&&(c=rep.call(e,t,c)),typeof c){case"string":return quote(c);case"number":return isFinite(c)?String(c):"null";case"boolean":case"null":return String(c);case"object":if(!c)return"null";if(gap+=indent,s=[],"[object Array]"===Object.prototype.toString.apply(c)){for(o=c.length,i=0;o>i;i+=1)s[i]=str(i,c)||"null";return r=0===s.length?"[]":gap?"[\n"+gap+s.join(",\n"+gap)+"\n"+a+"]":"["+s.join(",")+"]",gap=a,r}if(rep&&"object"==typeof rep)for(o=rep.length,i=0;o>i;i+=1)"string"==typeof rep[i]&&(n=rep[i],r=str(n,c),r&&s.push(quote(n)+(gap?": ":":")+r));else for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(r=str(n,c),r&&s.push(quote(n)+(gap?": ":":")+r));return r=0===s.length?"{}":gap?"{\n"+gap+s.join(",\n"+gap)+"\n"+a+"}":"{"+s.join(",")+"}",gap=a,r}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(t){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(t){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;"function"!=typeof JSON.stringify&&(JSON.stringify=function(t,e,i){var n;if(gap="",indent="","number"==typeof i)for(n=0;i>n;n+=1)indent+=" ";else"string"==typeof i&&(indent=i);if(rep=e,e&&"function"!=typeof e&&("object"!=typeof e||"number"!=typeof e.length))throw new Error("JSON.stringify");return str("",{"":t})}),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(t,e){var i,n,r=t[e];if(r&&"object"==typeof r)for(i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n=walk(r,i),void 0!==n?r[i]=n:delete r[i]);return reviver.call(t,e,r)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(t){return"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),"undefined"==typeof Event)var Event={};if("undefined"==typeof eventjs)var eventjs=Event;if(Event=function(t){"use strict";t.modifyEventListener=!1,t.modifySelectors=!1,t.add=function(t,e,n,r){return i(t,e,n,r,"add")},t.remove=function(t,e,n,r){return i(t,e,n,r,"remove"); },t.stop=function(t){t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0,t.bubble=0},t.prevent=function(t){t.preventDefault&&t.preventDefault(),t.returnValue=!1},t.cancel=function(e){t.stop(e),t.prevent(e)},t.supports=function(t,e){if("string"==typeof t&&(e=t,t=window),e="on"+e,e in t)return!0;if(t.setAttribute||(t=document.createElement("div")),t.setAttribute&&t.removeAttribute){t.setAttribute(e,"");var i="function"==typeof t[e];return"undefined"!=typeof t[e]&&(t[e]=null),t.removeAttribute(e),i}};var e=function(t){if(!t||"object"!=typeof t)return t;var i=new t.constructor;for(var n in t)t[n]&&"object"==typeof t[n]?i[n]=e(t[n]):i[n]=t[n];return i},i=function(a,h,f,d,p,g){d=d||{};{if("string"!=typeof a||"ready"!==h){if("string"==typeof a){if(a=document.querySelectorAll(a),0===a.length)return r("Missing target on listener!");1===a.length&&(a=a[0])}var v,m={};if(a.length>0){for(var b=0,y=a.length;y>b;b++)v=i(a[b],h,f,e(d),p),v&&(m[b]=v);return n(m)}if(h.indexOf&&-1!==h.indexOf(" ")&&(h=h.split(" ")),h.indexOf&&-1!==h.indexOf(",")&&(h=h.split(",")),"string"!=typeof h){if("number"==typeof h.length)for(var x=0,w=h.length;w>x;x++)v=i(a,h[x],f,e(d),p),v&&(m[h[x]]=v);else for(var k in h)v="function"==typeof h[k]?i(a,k,h[k],e(d),p):i(a,k,h[k].listener,e(h[k]),p),v&&(m[k]=v);return n(m)}if("function"!=typeof f)return r("Listener is not a function!");var C=d.useCapture||!1,_=o(h)+c(a)+"."+c(f)+"."+(C?1:0);if(t.Gesture&&t.Gesture._gestureHandlers[h]){if("remove"===p){if(!s[_])return;s[_].remove(),delete s[_]}else if("add"===p){if(s[_])return s[_];if(d.useCall&&!t.modifyEventListener){var S=f;f=function(t,e){for(var i in e)t[i]=e[i];return S.call(a,t)}}d.gesture=h,d.target=a,d.listener=f,d.fromOverwrite=g,s[_]=t.proxy[h](d)}}else if(h=o(h),"remove"===p){if(!s[_])return;a[u](h,f,C),delete s[_]}else if("add"===p){if(s[_])return s[_];a[l](h,f,C),s[_]={type:h,target:a,listener:f,remove:function(){t.remove(a,h,f,d)}}}return s[_]}var E=(new Date).getTime(),T=d.timeout,O=d.interval||1e3/60,j=window.setInterval(function(){(new Date).getTime()-E>T&&window.clearInterval(j),document.querySelector(a)&&(window.clearInterval(j),f())},O)}},n=function(t){return{remove:function(){for(var e in t)t[e].remove()},add:function(){for(var e in t)t[e].add()}}},r=function(t){"undefined"!=typeof console&&"undefined"!=typeof console.error&&console.error(t)},o=function(){var e={};return function(i){return t.pointerType||(window.navigator.msPointerEnabled?(t.pointerType="mspointer",e={mousedown:"MSPointerDown",mousemove:"MSPointerMove",mouseup:"MSPointerUp"}):t.supports("touchstart")?(t.pointerType="touch",e={mousedown:"touchstart",mouseup:"touchend",mousemove:"touchmove"}):t.pointerType="mouse"),e[i]&&(i=e[i]),document.addEventListener?i:"on"+i}}(),s={},a=0,c=function(t){return t===window?"#window":t===document?"#document":t?(t.uniqueID||(t.uniqueID="id"+a++),t.uniqueID):r("Missing target on listener!")},l=document.addEventListener?"addEventListener":"attachEvent",u=document.removeEventListener?"removeEventListener":"detachEvent";return t.createPointerEvent=function(e,i,n){var r=i.gesture,o=i.target,s=e.changedTouches||t.proxy.getCoords(e);if(s.length){var a=s[0];i.pointers=n?[]:s,i.pageX=a.pageX,i.pageY=a.pageY,i.x=i.pageX,i.y=i.pageY}var c=document.createEvent("Event");c.initEvent(r,!0,!0),c.originalEvent=e;for(var l in i)"target"!==l&&(c[l]=i[l]);o.dispatchEvent(c)},t.modifyEventListener&&window.HTMLElement&&function(){var e=function(e){var n=function(n){var r=n+"EventListener",s=e[r];e[r]=function(e,r,a){if(t.Gesture&&t.Gesture._gestureHandlers[e]){var c=a;"object"==typeof a?c.useCall=!0:c={useCall:!0,useCapture:a},i(this,e,r,c,n,!0),s.call(this,e,r,a)}else s.call(this,o(e),r,a)}};n("add"),n("remove")};navigator.userAgent.match(/Firefox/)?(e(HTMLDivElement.prototype),e(HTMLCanvasElement.prototype)):e(HTMLElement.prototype),e(document),e(window)}(),t.modifySelectors&&function(){var t=NodeList.prototype;t.removeEventListener=function(t,e,i){for(var n=0,r=this.length;r>n;n++)this[n].removeEventListener(t,e,i)},t.addEventListener=function(t,e,i){for(var n=0,r=this.length;r>n;n++)this[n].addEventListener(t,e,i)}}(),t}(Event),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";return t.pointerSetup=function(t,e){t.doc=t.target.ownerDocument||t.target,t.minFingers=t.minFingers||t.fingers||1,t.maxFingers=t.maxFingers||t.fingers||1/0,t.position=t.position||"relative",delete t.fingers,e=e||{},e.gesture=t.gesture,e.target=t.target,e.pointerType=Event.pointerType,Event.modifyEventListener&&t.fromOverwrite&&(t.listener=Event.createPointerEvent);var i=0,n=0===e.gesture.indexOf("pointer")&&Event.modifyEventListener?"pointer":"mouse";return e.listener=t.listener,e.proxy=function(i){e.defaultListener=t.listener,t.listener=i,i(t.event,e)},e.remove=function(){t.onPointerDown&&Event.remove(t.target,n+"down",t.onPointerDown),t.onPointerMove&&Event.remove(t.doc,n+"move",t.onPointerMove),t.onPointerUp&&Event.remove(t.doc,n+"up",t.onPointerUp)},e.resume=function(e){!t.onPointerMove||e&&!e.move||Event.add(t.doc,n+"move",t.onPointerMove),!t.onPointerUp||e&&!e.move||Event.add(t.doc,n+"up",t.onPointerUp),t.fingers=i},e.pause=function(e){i=t.fingers,!t.onPointerMove||e&&!e.move||Event.remove(t.doc,n+"move",t.onPointerMove),!t.onPointerUp||e&&!e.up||Event.remove(t.doc,n+"up",t.onPointerUp),t.fingers=0},e},t.pointerStart=function(e,i,n){var r=function(t,e){var i=n.bbox,r=s[e]={};switch(n.position){case"absolute":r.offsetX=0,r.offsetY=0;break;case"difference":r.offsetX=t.pageX,r.offsetY=t.pageY;break;case"move":r.offsetX=t.pageX-i.x1,r.offsetY=t.pageY-i.y1;break;default:r.offsetX=i.x1,r.offsetY=i.y1}if("relative"===n.position)var o=(t.pageX+i.scrollLeft-r.offsetX)*i.scaleX,a=(t.pageY+i.scrollTop-r.offsetY)*i.scaleY;else var o=t.pageX-r.offsetX,a=t.pageY-r.offsetY;r.rotation=0,r.scale=1,r.startTime=r.moveTime=(new Date).getTime(),r.move={x:o,y:a},r.start={x:o,y:a},n.fingers++};n.event=e,i.defaultListener&&(n.listener=i.defaultListener,delete i.defaultListener);for(var o=!n.fingers,s=n.tracker,a=e.changedTouches||t.getCoords(e),c=a.length,l=0;c>l;l++){var u=a[l],h=u.identifier||1/0;if(n.fingers){if(n.fingers>=n.maxFingers){var f=[];for(var h in n.tracker)f.push(h);return i.identifier=f.join(","),o}var d=0;for(var p in s){if(s[p].up){delete s[p],r(u,h),n.cancel=!0;break}d++}if(s[h])continue;r(u,h)}else s=n.tracker={},i.bbox=n.bbox=t.getBoundingBox(n.target),n.fingers=0,n.cancel=!1,r(u,h)}var f=[];for(var h in n.tracker)f.push(h);return i.identifier=f.join(","),o},t.pointerEnd=function(t,e,i,n){for(var r=t.touches||[],o=r.length,s={},a=0;o>a;a++){var c=r[a],l=c.identifier;s[l||1/0]=!0}for(var l in i.tracker){var u=i.tracker[l];s[l]||u.up||(n&&n({pageX:u.pageX,pageY:u.pageY,changedTouches:[{pageX:u.pageX,pageY:u.pageY,identifier:"Infinity"===l?1/0:l}]},"up"),u.up=!0,i.fingers--)}if(0!==i.fingers)return!1;var h=[];i.gestureFingers=0;for(var l in i.tracker)i.gestureFingers++,h.push(l);return e.identifier=h.join(","),!0},t.getCoords=function(e){return"undefined"!=typeof e.pageX?t.getCoords=function(t){return Array({type:"mouse",x:t.pageX,y:t.pageY,pageX:t.pageX,pageY:t.pageY,identifier:1/0})}:t.getCoords=function(t){return t=t||window.event,Array({type:"mouse",x:t.clientX+document.documentElement.scrollLeft,y:t.clientY+document.documentElement.scrollTop,pageX:t.clientX+document.documentElement.scrollLeft,pageY:t.clientY+document.documentElement.scrollTop,identifier:1/0})},t.getCoords(e)},t.getCoord=function(e){if("ontouchstart"in window){var i=0,n=0;t.getCoord=function(t){var e=t.changedTouches;return e.length?{x:i=e[0].pageX,y:n=e[0].pageY}:{x:i,y:n}}}else"undefined"!=typeof e.pageX&&"undefined"!=typeof e.pageY?t.getCoord=function(t){return{x:t.pageX,y:t.pageY}}:t.getCoord=function(t){return t=t||window.event,{x:t.clientX+document.documentElement.scrollLeft,y:t.clientY+document.documentElement.scrollTop}};return t.getCoord(e)},t.getBoundingBox=function(t){(t===window||t===document)&&(t=document.body);var e={x1:0,y1:0,x2:0,y2:0,scrollLeft:0,scrollTop:0};t===document.body?(e.height=window.innerHeight,e.width=window.innerWidth):(e.height=t.offsetHeight,e.width=t.offsetWidth),e.scaleX=t.width/e.width||1,e.scaleY=t.height/e.height||1;for(var i=t;null!==i;)e.x1+=i.offsetLeft,e.y1+=i.offsetTop,i=i.offsetParent;for(var i=t.parentNode;null!==i&&i!==document.body&&void 0!==i.scrollTop;)e.scrollLeft+=i.scrollLeft,e.scrollTop+=i.scrollTop,i=i.parentNode;return e.x2=e.x1+e.width,e.y2=e.y1+e.height,e},function(){var e=navigator.userAgent.toLowerCase(),i=-1!==e.indexOf("macintosh");if(i&&-1!==e.indexOf("khtml"))var n={91:!0,93:!0};else if(i&&-1!==e.indexOf("firefox"))var n={224:!0};else var n={17:!0};t.isMetaKey=function(t){return!!n[t.keyCode]},t.metaTracker=function(e){n[e.keyCode]&&(t.metaKey="keydown"===e.type)}}(),t}(Event.proxy),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";return t.click=function(e){e.maxFingers=e.maxFingers||e.fingers||1;var i;e.onPointerDown=function(i){t.pointerStart(i,n,e)&&(Event.add(e.doc,"mousemove",e.onPointerMove).listener(i),Event.add(e.doc,"mouseup",e.onPointerUp))},e.onPointerMove=function(t){i=t},e.onPointerUp=function(r){if(t.pointerEnd(r,n,e)){if(Event.remove(e.doc,"mousemove",e.onPointerMove),Event.remove(e.doc,"mouseup",e.onPointerUp),i.cancelBubble&&++i.bubble>1)return;var o=i.changedTouches||t.getCoords(i),s=o[0],a=e.bbox,c=t.getBoundingBox(e.target);if("relative"===e.position)var l=(s.pageX+a.scrollLeft-a.x1)*a.scaleX,u=(s.pageY+a.scrollTop-a.y1)*a.scaleY;else var l=s.pageX-a.x1,u=s.pageY-a.y1;l>0&&l0&&u0&&u0&&h=n&&!(o.cancelBubble&&++o.bubble>1)&&(c.state=e.gesture,e.listener(o,c)),clearTimeout(r),i=n=0)};var c=t.pointerSetup(e);return c.state="dblclick",Event.add(e.target,"mousedown",e.onPointerDown),c},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.dbltap=t.dbltap,Event.Gesture._gestureHandlers.dblclick=t.dblclick,t}(Event.proxy),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";return t.dragElement=function(e,i){t.drag({event:i,target:e,position:"move",listener:function(t,i){e.style.left=i.x+"px",e.style.top=i.y+"px",Event.prevent(t)}})},t.drag=function(e){e.gesture="drag",e.onPointerDown=function(n){t.pointerStart(n,i,e)&&(e.monitor||(Event.add(e.doc,"mousemove",e.onPointerMove),Event.add(e.doc,"mouseup",e.onPointerUp))),e.onPointerMove(n,"down")},e.onPointerMove=function(n,r){if(!e.tracker)return e.onPointerDown(n);for(var o=e.bbox,s=n.changedTouches||t.getCoords(n),a=s.length,c=0;a>c;c++){var l=s[c],u=l.identifier||1/0,h=e.tracker[u];h&&(h.pageX=l.pageX,h.pageY=l.pageY,i.state=r||"move",i.identifier=u,i.start=h.start,i.fingers=e.fingers,"relative"===e.position?(i.x=(h.pageX+o.scrollLeft-h.offsetX)*o.scaleX,i.y=(h.pageY+o.scrollTop-h.offsetY)*o.scaleY):(i.x=h.pageX-h.offsetX,i.y=h.pageY-h.offsetY),e.listener(n,i))}},e.onPointerUp=function(n){t.pointerEnd(n,i,e,e.onPointerMove)&&(e.monitor||(Event.remove(e.doc,"mousemove",e.onPointerMove),Event.remove(e.doc,"mouseup",e.onPointerUp)))};var i=t.pointerSetup(e);return e.event?e.onPointerDown(e.event):(Event.add(e.target,"mousedown",e.onPointerDown),e.monitor&&(Event.add(e.doc,"mousemove",e.onPointerMove),Event.add(e.doc,"mouseup",e.onPointerUp))),i},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.drag=t.drag,t}(Event.proxy),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";var e=Math.PI/180;return t.gesture=function(i){i.minFingers=i.minFingers||i.fingers||2,i.onPointerDown=function(e){var r=i.fingers;if(t.pointerStart(e,n,i)&&(Event.add(i.doc,"mousemove",i.onPointerMove),Event.add(i.doc,"mouseup",i.onPointerUp)),i.fingers===i.minFingers&&r!==i.fingers){n.fingers=i.minFingers,n.scale=1,n.rotation=0,n.state="start";var o="";for(var s in i.tracker)o+=s;n.identifier=parseInt(o),i.listener(e,n)}},i.onPointerMove=function(r,o){for(var s=i.bbox,a=i.tracker,c=r.changedTouches||t.getCoords(r),l=c.length,u=0;l>u;u++){var h=c[u],f=h.identifier||1/0,d=a[f];d&&("relative"===i.position?(d.move.x=(h.pageX+s.scrollLeft-s.x1)*s.scaleX,d.move.y=(h.pageY+s.scrollTop-s.y1)*s.scaleY):(d.move.x=h.pageX-s.x1,d.move.y=h.pageY-s.y1))}if(!(i.fingers0?C:-C,"undefined"!=typeof h.DEG2&&(C>0?h.rotation+=h.DEG1-h.DEG2:h.rotation-=h.DEG1-h.DEG2,g+=h.rotation),c.push(h.move)}}n.touches=c,n.fingers=i.fingers,n.scale=p/i.fingers,n.rotation=g/i.fingers,n.state="change",i.listener(r,n)}},i.onPointerUp=function(e){var r=i.fingers;t.pointerEnd(e,n,i)&&(Event.remove(i.doc,"mousemove",i.onPointerMove),Event.remove(i.doc,"mouseup",i.onPointerUp)),r===i.minFingers&&i.fingersp;p++){var v=f[p],m=e.acceleration[v],b=c[v],y=Math.abs(m);if(!(n>d-s)&&y>i){var x=d*m/y,w=Math.abs(x+b.value);b.value&&r>w?(b.value=x,b.count++,b.count===o&&(t.listener(l,e),s=d,b.value=0,b.count=0)):(b.value=x,b.count=1)}}};return window.addEventListener?(window.addEventListener("devicemotion",l,!1),e):void 0},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.shake=t.shake,t}(Event.proxy),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";var e=Math.PI/180;return t.swipe=function(i){i.snap=i.snap||90,i.threshold=i.threshold||1,i.onPointerDown=function(e){t.pointerStart(e,n,i)&&(Event.add(i.doc,"mousemove",i.onPointerMove).listener(e),Event.add(i.doc,"mouseup",i.onPointerUp))},i.onPointerMove=function(e){for(var n=e.changedTouches||t.getCoords(e),r=n.length,o=0;r>o;o++){var s=n[o],a=s.identifier||1/0,c=i.tracker[a];c&&(c.move.x=s.pageX,c.move.y=s.pageY,c.moveTime=(new Date).getTime())}},i.onPointerUp=function(r){if(t.pointerEnd(r,n,i)){Event.remove(i.doc,"mousemove",i.onPointerMove),Event.remove(i.doc,"mouseup",i.onPointerUp);var o,s,a,c,l={x:0,y:0},u=0,h=0,f=0;for(var d in i.tracker){var p=i.tracker[d],g=p.move.x-p.start.x,v=p.move.y-p.start.y;u+=p.move.x,h+=p.move.y,l.x+=p.start.x,l.y+=p.start.y,f++;var m=Math.sqrt(g*g+v*v),b=p.moveTime-p.startTime,c=Math.atan2(g,v)/e+180,s=b?m/b:0;if("undefined"==typeof a)a=c,o=s;else{if(!(Math.abs(c-a)<=20))return;a=(a+c)/2,o=(o+s)/2}}o>i.threshold&&(l.x/=f,l.y/=f,n.start=l,n.x=u/f,n.y=h/f,n.angle=-(((a/i.snap+.5>>0)*i.snap||360)-360),n.velocity=o,n.fingers=i.gestureFingers,n.state="swipe",i.listener(r,n))}};var n=t.pointerSetup(i);return Event.add(i.target,"mousedown",i.onPointerDown),n},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.swipe=t.swipe,t}(Event.proxy),"undefined"==typeof Event)var Event={};if("undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";return t.tap=t.longpress=function(e){e.delay=e.delay||500,e.timeout=e.timeout||250;var i,n;e.onPointerDown=function(o){if(t.pointerStart(o,r,e)){if(i=(new Date).getTime(),Event.add(e.doc,"mousemove",e.onPointerMove).listener(o),Event.add(e.doc,"mouseup",e.onPointerUp),"longpress"!==e.gesture)return;n=setTimeout(function(){if(!(o.cancelBubble&&++o.bubble>1)){var t=0;for(var i in e.tracker){if(e.tracker[i].end===!0)return;if(e.cancel)return;t++}r.state="start",r.fingers=t,e.listener(o,r)}},e.delay)}},e.onPointerMove=function(i){for(var n=e.bbox,r=i.changedTouches||t.getCoords(i),o=r.length,s=0;o>s;s++){var a=r[s],c=a.identifier||1/0,l=e.tracker[c];if(l){if("relative"===e.position)var u=(a.pageX+n.scrollLeft-n.x1)*n.scaleX,h=(a.pageY+n.scrollTop-n.y1)*n.scaleY;else var u=a.pageX-n.x1,h=a.pageY-n.y1;if(!(u>0&&u0&&h1)return;if("longpress"===e.gesture)return void("start"===r.state&&(r.state="end",e.listener(o,r)));if(e.cancel)return;if((new Date).getTime()-i>e.timeout)return;r.state="tap",r.fingers=e.gestureFingers,e.listener(o,r)}};var r=t.pointerSetup(e);return Event.add(e.target,"mousedown",e.onPointerDown),r},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.tap=t.tap,Event.Gesture._gestureHandlers.longpress=t.longpress,t}(Event.proxy),"undefined"==typeof Event)var Event={};"undefined"==typeof Event.proxy&&(Event.proxy={}),Event.proxy=function(t){"use strict";return t.wheel=function(t){var e,i=t.timeout||150,n=0,r={gesture:"wheel",state:"start",wheelDelta:0,target:t.target,listener:t.listener,remove:function(){t.target[a](c,o,!1)}},o=function(o){o=o||window.event,r.state=n++?"change":"start",r.wheelDelta=o.detail?-20*o.detail:o.wheelDelta,t.listener(o,r),clearTimeout(e),e=setTimeout(function(){n=0,r.state="end",r.wheelDelta=0,t.listener(o,r)},i)},s=document.addEventListener?"addEventListener":"attachEvent",a=document.removeEventListener?"removeEventListener":"detachEvent",c=Event.supports("mousewheel")?"mousewheel":"DOMMouseScroll";return t.target[s](c,o,!1),r},Event.Gesture=Event.Gesture||{},Event.Gesture._gestureHandlers=Event.Gesture._gestureHandlers||{},Event.Gesture._gestureHandlers.wheel=t.wheel,t}(Event.proxy),fabric.log=function(){},fabric.warn=function(){},"undefined"!=typeof console&&("undefined"!=typeof console.log&&console.log.apply&&(fabric.log=function(){return console.log.apply(console,arguments)}),"undefined"!=typeof console.warn&&console.warn.apply&&(fabric.warn=function(){return console.warn.apply(console,arguments)})),fabric.Observable={observe:function(t,e){if(this.__eventListeners||(this.__eventListeners={}),1===arguments.length)for(var i in t)this.on(i,t[i]);else this.__eventListeners[t]||(this.__eventListeners[t]=[]),this.__eventListeners[t].push(e)},stopObserving:function(t,e){this.__eventListeners||(this.__eventListeners={}),this.__eventListeners[t]&&(e?fabric.util.removeFromArray(this.__eventListeners[t],e):this.__eventListeners[t].length=0)},fire:function(t,e){this.__eventListeners||(this.__eventListeners={});var i=this.__eventListeners[t];if(i)for(var n=0,r=i.length;r>n;n++)i[n](e||{})}},fabric.Observable.on=fabric.Observable.observe,fabric.Observable.off=fabric.Observable.stopObserving,fabric.Observable.trigger=fabric.Observable.fire,function(){function t(t,e){var i=t.indexOf(e);return-1!==i&&t.splice(i,1),t}function e(t,e){return Math.floor(Math.random()*(e-t+1))+t}function i(t){return t*b}function n(t){return t/b}function r(t,e,i){var n=Math.sin(i),r=Math.cos(i);t.subtractEquals(e);var o=t.x*r-t.y*n,s=t.x*n+t.y*r;return new fabric.Point(o,s).addEquals(e)}function o(t,e){return parseFloat(Number(t).toFixed(e))}function s(){return!1}function a(t){t||(t={});var e,i=+new Date,n=t.duration||500,r=i+n,o=t.onChange||function(){},s=t.abort||function(){return!1},a=t.easing||function(t,e,i,n){return-i*Math.cos(t/n*(Math.PI/2))+i+e},c="startValue"in t?t.startValue:0,l="endValue"in t?t.endValue:100,u=t.byValue||l-c;t.onStart&&t.onStart(),function h(){e=+new Date;var l=e>r?n:e-i;return o(a(l,c,u,n)),e>r||s()?void(t.onComplete&&t.onComplete()):void x(h)}()}function c(t,e,i){if(t){var n=new Image;n.onload=function(){e&&e.call(i,n),n=n.onload=null},n.src=t}else e&&e.call(i,t)}function l(t,e){function i(t){return fabric[fabric.util.string.camelize(fabric.util.string.capitalize(t))]}function n(){++o===s&&e&&e(r)}var r=[],o=0,s=t.length;t.forEach(function(t,e){if(t.type){var o=i(t.type);o.async?o.fromObject(t,function(t,i){i||(r[e]=t),n()}):(r[e]=o.fromObject(t),n())}})}function u(t,e,i){var n;if(t.length>1){var r=t.some(function(t){return"text"===t.type});r?(n=new fabric.Group([],e),t.reverse().forEach(function(t){t.cx&&(t.left=t.cx),t.cy&&(t.top=t.cy),n.addWithUpdate(t)})):n=new fabric.PathGroup(t,e)}else n=t[0];return"undefined"!=typeof i&&n.setSourcePath(i),n}function h(t,e,i){if(i&&"[object Array]"===Object.prototype.toString.call(i))for(var n=0,r=i.length;r>n;n++)e[i[n]]=t[i[n]]}function f(t,e,i,n,r,o){var s=n-e,a=r-i,c=v(s*s+a*a),l=m(a,s),u=o.length,h=0,f=!0;for(t.save(),t.translate(e,i),t.moveTo(0,0),t.rotate(l),e=0;c>e;)e+=o[h++%u],e>c&&(e=c),t[f?"lineTo":"moveTo"](e,0),f=!f;t.restore()}function d(t){return t||(t=fabric.document.createElement("canvas")),t.getContext||"undefined"==typeof G_vmlCanvasManager||G_vmlCanvasManager.initElement(t),t}function p(t){for(var e=t.prototype,i=e.stateProperties.length;i--;){var n=e.stateProperties[i],r=n.charAt(0).toUpperCase()+n.slice(1),o="set"+r,s="get"+r;e[s]||(e[s]=function(t){return new Function('return this.get("'+t+'")')}(n)),e[o]||(e[o]=function(t){return new Function("value",'return this.set("'+t+'", value)')}(n))}}function g(t,e){e.save(),e.beginPath(),t.clipTo(e),e.clip()}var v=Math.sqrt,m=Math.atan2;fabric.util={};var b=Math.PI/180,y=fabric.window.requestAnimationFrame||fabric.window.webkitRequestAnimationFrame||fabric.window.mozRequestAnimationFrame||fabric.window.oRequestAnimationFrame||fabric.window.msRequestAnimationFrame||function(t){fabric.window.setTimeout(t,1e3/60)},x=function(){return y.apply(fabric.window,arguments)};fabric.util.removeFromArray=t,fabric.util.degreesToRadians=i,fabric.util.radiansToDegrees=n,fabric.util.rotatePoint=r,fabric.util.toFixed=o,fabric.util.getRandomInt=e,fabric.util.falseFunction=s,fabric.util.animate=a,fabric.util.requestAnimFrame=x,fabric.util.loadImage=c,fabric.util.enlivenObjects=l,fabric.util.groupSVGElements=u,fabric.util.populateWithProperties=h,fabric.util.drawDashedLine=f,fabric.util.createCanvasElement=d,fabric.util.createAccessors=p,fabric.util.clipContext=g}(),function(){function t(t,e){for(var i=n.call(arguments,2),r=[],o=0,s=t.length;s>o;o++)r[o]=i.length?t[o][e].apply(t[o],i):t[o][e].call(t[o]);return r}function e(t,e){if(!t||0===t.length)return void 0;var i=t.length-1,n=e?t[i][e]:t[i];if(e)for(;i--;)t[i][e]>=n&&(n=t[i][e]);else for(;i--;)t[i]>=n&&(n=t[i]);return n}function i(t,e){if(!t||0===t.length)return void 0;var i=t.length-1,n=e?t[i][e]:t[i];if(e)for(;i--;)t[i][e]>>0;if(0===i)return-1;var n=0;if(arguments.length>0&&(n=Number(arguments[1]),n!==n?n=0:0!==n&&n!==Number.POSITIVE_INFINITY&&n!==Number.NEGATIVE_INFINITY&&(n=(n>0||-1)*Math.floor(Math.abs(n)))),n>=i)return-1;for(var r=n>=0?n:Math.max(i-Math.abs(n),0);i>r;r++)if(r in e&&e[r]===t)return r;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(t,e){for(var i=0,n=this.length>>>0;n>i;i++)i in this&&t.call(e,this[i],i,this)}),Array.prototype.map||(Array.prototype.map=function(t,e){for(var i=[],n=0,r=this.length>>>0;r>n;n++)n in this&&(i[n]=t.call(e,this[n],n,this));return i}),Array.prototype.every||(Array.prototype.every=function(t,e){for(var i=0,n=this.length>>>0;n>i;i++)if(i in this&&!t.call(e,this[i],i,this))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(t,e){for(var i=0,n=this.length>>>0;n>i;i++)if(i in this&&t.call(e,this[i],i,this))return!0;return!1}),Array.prototype.filter||(Array.prototype.filter=function(t,e){for(var i,n=[],r=0,o=this.length>>>0;o>r;r++)r in this&&(i=this[r],t.call(e,i,r,this)&&n.push(i));return n}),Array.prototype.reduce||(Array.prototype.reduce=function(t){var e,i=this.length>>>0,n=0;if(arguments.length>1)e=arguments[1];else for(;;){if(n in this){e=this[n++];break}if(++n>=i)throw new TypeError}for(;i>n;n++)n in this&&(e=t.call(null,e,this[n],n,this));return e}),fabric.util.array={invoke:t,min:i,max:e}}(),function(){function t(t,e){for(var i in e)t[i]=e[i];return t}function e(e){return t({},e)}fabric.util.object={extend:t,clone:e}}(),function(){function t(t){return t.replace(/-+(.)?/g,function(t,e){return e?e.toUpperCase():""})}function e(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function i(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\xA0]+/,"").replace(/[\s\xA0]+$/,"")}),fabric.util.string={camelize:t,capitalize:e,escapeXml:i}}(),function(){var t=Array.prototype.slice,e=Function.prototype.apply,i=function(){};Function.prototype.bind||(Function.prototype.bind=function(n){var r,o=this,s=t.call(arguments,1);return r=s.length?function(){return e.call(o,this instanceof i?this:n,s.concat(t.call(arguments)))}:function(){return e.call(o,this instanceof i?this:n,arguments)},i.prototype=this.prototype,r.prototype=new i,r})}(),function(){function t(){}function e(t){var e=this.constructor.superclass.prototype[t];return arguments.length>1?e.apply(this,n.call(arguments,1)):e.call(this)}function i(){function i(){this.initialize.apply(this,arguments)}var o=null,a=n.call(arguments,0);"function"==typeof a[0]&&(o=a.shift()),i.superclass=o,i.subclasses=[],o&&(t.prototype=o.prototype,i.prototype=new t,o.subclasses.push(i));for(var c=0,l=a.length;l>c;c++)s(i,a[c],o);return i.prototype.initialize||(i.prototype.initialize=r),i.prototype.constructor=i,i.prototype.callSuper=e,i}var n=Array.prototype.slice,r=function(){},o=function(){for(var t in{toString:1})if("toString"===t)return!1;return!0}(),s=function(t,e,i){for(var n in e)n in t.prototype&&"function"==typeof t.prototype[n]&&(e[n]+"").indexOf("callSuper")>-1?t.prototype[n]=function(t){return function(){var n=this.constructor.superclass;this.constructor.superclass=i;var r=e[t].apply(this,arguments);return this.constructor.superclass=n,"initialize"!==t?r:void 0}}(n):t.prototype[n]=e[n],o&&(e.toString!==Object.prototype.toString&&(t.prototype.toString=e.toString),e.valueOf!==Object.prototype.valueOf&&(t.prototype.valueOf=e.valueOf))};fabric.util.createClass=i}(),function(){function t(t){var e,i,n=Array.prototype.slice.call(arguments,1),r=n.length;for(i=0;r>i;i++)if(e=typeof t[n[i]],!/^(?:function|object|unknown)$/.test(e))return!1;return!0}function e(t,e){return{handler:e,wrappedHandler:i(t,e)}}function i(t,e){return function(i){e.call(o(t),i||fabric.window.event)}}function n(t,e){return function(i){if(d[t]&&d[t][e])for(var n=d[t][e],r=0,o=n.length;o>r;r++)n[r].call(this,i||fabric.window.event)}}function r(t,e){t||(t=fabric.window.event);for(var i,n=t.target||("unknown"!=typeof t.srcElement?t.srcElement:null),r=fabric.document.body||{scrollLeft:0,scrollTop:0},o=fabric.document.documentElement,s=n,a=0,c=0;n&&n.parentNode&&!i;)n=n.parentNode,n!==fabric.document&&"fixed"===fabric.util.getElementPosition(n)&&(i=n),n!==fabric.document&&s!==e&&"absolute"===fabric.util.getElementPosition(n)?(a=0,c=0):n===fabric.document&&s!==e?(a=r.scrollLeft||o.scrollLeft||0,c=r.scrollTop||o.scrollTop||0):(a+=n.scrollLeft||0,c+=n.scrollTop||0);return{x:p(t)+a,y:g(t)+c}}var o,s,a=function(){var t=0;return function(e){return e.__uniqueID||(e.__uniqueID="uniqueID__"+t++)}}();!function(){var t={};o=function(e){return t[e]},s=function(e,i){t[e]=i}}();var c,l,u=t(fabric.document.documentElement,"addEventListener","removeEventListener")&&t(fabric.window,"addEventListener","removeEventListener"),h=t(fabric.document.documentElement,"attachEvent","detachEvent")&&t(fabric.window,"attachEvent","detachEvent"),f={},d={};u?(c=function(t,e,i){t.addEventListener(e,i,!1)},l=function(t,e,i){t.removeEventListener(e,i,!1)}):h?(c=function(t,i,n){var r=a(t);s(r,t),f[r]||(f[r]={}),f[r][i]||(f[r][i]=[]);var o=e(r,n);f[r][i].push(o),t.attachEvent("on"+i,o.wrappedHandler)},l=function(t,e,i){var n,r=a(t);if(f[r]&&f[r][e])for(var o=0,s=f[r][e].length;s>o;o++)n=f[r][e][o],n&&n.handler===i&&(t.detachEvent("on"+e,n.wrappedHandler),f[r][e][o]=null)}):(c=function(t,e,i){var r=a(t);if(d[r]||(d[r]={}), !d[r][e]){d[r][e]=[];var o=t["on"+e];o&&d[r][e].push(o),t["on"+e]=n(r,e)}d[r][e].push(i)},l=function(t,e,i){var n=a(t);if(d[n]&&d[n][e])for(var r=d[n][e],o=0,s=r.length;s>o;o++)r[o]===i&&r.splice(o,1)}),fabric.util.addListener=c,fabric.util.removeListener=l;var p=function(t){return"unknown"!=typeof t.clientX?t.clientX:0},g=function(t){return"unknown"!=typeof t.clientY?t.clientY:0};fabric.isTouchSupported&&(p=function(t){return"touchend"!==t.type?t.touches&&t.touches[0]?t.touches[0].pageX-(t.touches[0].pageX-t.touches[0].clientX)||t.clientX:t.clientX:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0].pageX-(t.changedTouches[0].pageX-t.changedTouches[0].clientX)||t.clientX:t.clientX},g=function(t){return"touchend"!==t.type?t.touches&&t.touches[0]?t.touches[0].pageY-(t.touches[0].pageY-t.touches[0].clientY)||t.clientY:t.clientY:t.changedTouches&&t.changedTouches[0]?t.changedTouches[0].pageY-(t.changedTouches[0].pageY-t.changedTouches[0].clientY)||t.clientY:t.clientY}),fabric.util.getPointer=r,fabric.util.object.extend(fabric.util,fabric.Observable)}(),function(){function t(t,e){var i=t.style;if(!i)return t;if("string"==typeof e)return t.style.cssText+=";"+e,e.indexOf("opacity")>-1?o(t,e.match(/opacity:\s*(\d?\.?\d*)/)[1]):t;for(var n in e)if("opacity"===n)o(t,e[n]);else{var r="float"===n||"cssFloat"===n?"undefined"==typeof i.styleFloat?"cssFloat":"styleFloat":n;i[r]=e[n]}return t}var e=fabric.document.createElement("div"),i="string"==typeof e.style.opacity,n="string"==typeof e.style.filter,r=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,o=function(t){return t};i?o=function(t,e){return t.style.opacity=e,t}:n&&(o=function(t,e){var i=t.style;return t.currentStyle&&!t.currentStyle.hasLayout&&(i.zoom=1),r.test(i.filter)?(e=e>=.9999?"":"alpha(opacity="+100*e+")",i.filter=i.filter.replace(r,e)):i.filter+=" alpha(opacity="+100*e+")",t}),fabric.util.setStyle=t}(),function(){function t(t){return"string"==typeof t?fabric.document.getElementById(t):t}function e(t,e){var i=fabric.document.createElement(t);for(var n in e)"class"===n?i.className=e[n]:"for"===n?i.htmlFor=e[n]:i.setAttribute(n,e[n]);return i}function i(t,e){-1===(" "+t.className+" ").indexOf(" "+e+" ")&&(t.className+=(t.className?" ":"")+e)}function n(t,i,n){return"string"==typeof i&&(i=e(i,n)),t.parentNode&&t.parentNode.replaceChild(i,t),i.appendChild(t),i}function r(t){var e=0,i=0;do e+=t.offsetTop||0,i+=t.offsetLeft||0,t=t.offsetParent;while(t);return{left:i,top:e}}var o,s=Array.prototype.slice,a=function(t){return s.call(t,0)};try{o=a(fabric.document.childNodes)instanceof Array}catch(c){}o||(a=function(t){for(var e=new Array(t.length),i=t.length;i--;)e[i]=t[i];return e});var l;l=fabric.document.defaultView&&fabric.document.defaultView.getComputedStyle?function(t){return fabric.document.defaultView.getComputedStyle(t,null).position}:function(t){var e=t.style.position;return!e&&t.currentStyle&&(e=t.currentStyle.position),e},function(){function t(t){return"undefined"!=typeof t.onselectstart&&(t.onselectstart=fabric.util.falseFunction),n?t.style[n]="none":"string"==typeof t.unselectable&&(t.unselectable="on"),t}function e(t){return"undefined"!=typeof t.onselectstart&&(t.onselectstart=null),n?t.style[n]="":"string"==typeof t.unselectable&&(t.unselectable=""),t}var i=fabric.document.documentElement.style,n="userSelect"in i?"userSelect":"MozUserSelect"in i?"MozUserSelect":"WebkitUserSelect"in i?"WebkitUserSelect":"KhtmlUserSelect"in i?"KhtmlUserSelect":"";fabric.util.makeElementUnselectable=t,fabric.util.makeElementSelectable=e}(),function(){function t(t,e){var i=fabric.document.getElementsByTagName("head")[0],n=fabric.document.createElement("script"),r=!0;n.type="text/javascript",n.setAttribute("runat","server"),n.onload=n.onreadystatechange=function(t){if(r){if("string"==typeof this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)return;r=!1,e(t||fabric.window.event),n=n.onload=n.onreadystatechange=null}},n.src=t,i.appendChild(n)}fabric.util.getScript=t}(),fabric.util.getById=t,fabric.util.toArray=a,fabric.util.makeElement=e,fabric.util.addClass=i,fabric.util.wrapElement=n,fabric.util.getElementOffset=r,fabric.util.getElementPosition=l}(),function(){function t(t,e){return t+(/\?/.test(t)?"&":"?")+e}function e(){}function i(i,r){r||(r={});var o,s=r.method?r.method.toUpperCase():"GET",a=r.onComplete||function(){},c=n();return c.onreadystatechange=function(){4===c.readyState&&(a(c),c.onreadystatechange=e)},"GET"===s&&(o=null,"string"==typeof r.parameters&&(i=t(i,r.parameters))),c.open(s,i,!0),("POST"===s||"PUT"===s)&&c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(o),c}var n=function(){for(var t=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest}],e=t.length;e--;)try{var i=t[e]();if(i)return t[e]}catch(n){}}();fabric.util.request=i}(),function(){function t(t,e,i,n){return i*(t/=n)*t+e}function e(t,e,i,n){return-i*(t/=n)*(t-2)+e}function i(t,e,i,n){return t/=n/2,1>t?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e}function n(t,e,i,n){return i*(t/=n)*t*t+e}function r(t,e,i,n){return i*((t=t/n-1)*t*t+1)+e}function o(t,e,i,n){return t/=n/2,1>t?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e}function s(t,e,i,n){return i*(t/=n)*t*t*t+e}function a(t,e,i,n){return-i*((t=t/n-1)*t*t*t-1)+e}function c(t,e,i,n){return t/=n/2,1>t?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e}function l(t,e,i,n){return i*(t/=n)*t*t*t*t+e}function u(t,e,i,n){return i*((t=t/n-1)*t*t*t*t+1)+e}function h(t,e,i,n){return t/=n/2,1>t?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e}function f(t,e,i,n){return-i*Math.cos(t/n*(Math.PI/2))+i+e}function d(t,e,i,n){return i*Math.sin(t/n*(Math.PI/2))+e}function p(t,e,i,n){return-i/2*(Math.cos(Math.PI*t/n)-1)+e}function g(t,e,i,n){return 0===t?e:i*Math.pow(2,10*(t/n-1))+e}function v(t,e,i,n){return t===n?e+i:i*(-Math.pow(2,-10*t/n)+1)+e}function m(t,e,i,n){return 0===t?e:t===n?e+i:(t/=n/2,1>t?i/2*Math.pow(2,10*(t-1))+e:i/2*(-Math.pow(2,-10*--t)+2)+e)}function b(t,e,i,n){return-i*(Math.sqrt(1-(t/=n)*t)-1)+e}function y(t,e,i,n){return i*Math.sqrt(1-(t=t/n-1)*t)+e}function x(t,e,i,n){return t/=n/2,1>t?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e}function w(t,e,i,n){var r=1.70158,o=0,s=i;return 0===t?e:(t/=n,1===t?e+i:(o||(o=.3*n),st?-.5*(s*Math.pow(2,10*(t-=1))*Math.sin((t*n-r)*(2*Math.PI)/o))+e:s*Math.pow(2,-10*(t-=1))*Math.sin((t*n-r)*(2*Math.PI)/o)*.5+i+e))}function _(t,e,i,n,r){return void 0===r&&(r=1.70158),i*(t/=n)*t*((r+1)*t-r)+e}function S(t,e,i,n,r){return void 0===r&&(r=1.70158),i*((t=t/n-1)*t*((r+1)*t+r)+1)+e}function E(t,e,i,n,r){return void 0===r&&(r=1.70158),t/=n/2,1>t?i/2*(t*t*(((r*=1.525)+1)*t-r))+e:i/2*((t-=2)*t*(((r*=1.525)+1)*t+r)+2)+e}function T(t,e,i,n){return i-O(n-t,0,i,n)+e}function O(t,e,i,n){return(t/=n)<1/2.75?i*(7.5625*t*t)+e:2/2.75>t?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:2.5/2.75>t?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e}function j(t,e,i,n){return n/2>t?.5*T(2*t,0,i,n)+e:.5*O(2*t-n,0,i,n)+.5*i+e}fabric.util.ease={easeInQuad:t,easeOutQuad:e,easeInOutQuad:i,easeInCubic:n,easeOutCubic:r,easeInOutCubic:o,easeInQuart:s,easeOutQuart:a,easeInOutQuart:c,easeInQuint:l,easeOutQuint:u,easeInOutQuint:h,easeInSine:f,easeOutSine:d,easeInOutSine:p,easeInExpo:g,easeOutExpo:v,easeInOutExpo:m,easeInCirc:b,easeOutCirc:y,easeInOutCirc:x,easeInElastic:w,easeOutElastic:k,easeInOutElastic:C,easeInBack:_,easeOutBack:S,easeInOutBack:E,easeInBounce:T,easeOutBounce:O,easeInOutBounce:j}}(),function(t){"use strict";function e(t){return t in b?b[t]:t}function i(t,i){if(t){var n,r,o={};t.parentNode&&/^g$/i.test(t.parentNode.nodeName)&&(o=p.parseAttributes(t.parentNode,i));var s=i.reduce(function(i,o){return n=t.getAttribute(o),r=parseFloat(n),n&&("fill"!==o&&"stroke"!==o||"none"!==n||(n=""),"fill-rule"===o&&(n="evenodd"===n?"destination-over":n),"transform"===o&&(n=p.parseTransformAttribute(n)),o=e(o),i[o]=isNaN(r)?n:r),i},{});return s=g(s,g(c(t),p.parseStyleAttribute(t))),g(o,s)}}function n(t){if(!t)return null;t=t.trim();var e=t.indexOf(",")>-1;t=t.split(/\s+/);var i,n,r=[];if(e)for(i=0,n=t.length;n>i;i++){var o=t[i].split(",");r.push({x:parseFloat(o[0]),y:parseFloat(o[1])})}else for(i=0,n=t.length;n>i;i+=2)r.push({x:parseFloat(t[i]),y:parseFloat(t[i+1])});return r.length%2!==0,r}function r(t){var i={},n=t.getAttribute("style");if(!n)return i;if("string"==typeof n)n=n.replace(/;$/,"").split(";").forEach(function(t){var n=t.split(":"),r=n[1].trim(),o=parseFloat(r);i[e(n[0].trim().toLowerCase())]=isNaN(o)?r:o});else for(var r in n)if("undefined"!=typeof n[r]){var o=parseFloat(n[r]);i[e(r.toLowerCase())]=isNaN(o)?n[r]:o}return i}function o(t){for(var e=t.length;e--;){var i=t[e].get("fill");if(/^url\(/.test(i)){var n=i.slice(5,i.length-1);p.gradientDefs[n]&&t[e].set("fill",p.Gradient.fromElement(p.gradientDefs[n],t[e]))}}}function s(t,e,i,n){function r(){0===--c&&(a=a.filter(function(t){return null!=t}),o(a),e(a))}for(var s,a=new Array(t.length),c=t.length,l=0,u=t.length;u>l;l++){s=t[l];var h=p[v(s.tagName)];if(h&&h.fromElement)try{if(h.async)h.fromElement(s,function(t,e){return function(i){n&&n(e,i),a.splice(t,0,i),r()}}(l),i);else{var f=h.fromElement(s,i);n&&n(s,f),a.splice(l,0,f),r()}}catch(d){p.log(d)}else r()}}function a(t){for(var e,i=t.getElementsByTagName("style"),n={},r=0,o=i.length;o>r;r++){var s=i[0].textContent;s=s.replace(/\/\*[\s\S]*?\*\//g,""),e=s.match(/[^{]*\{[\s\S]*?\}/g),e=e.map(function(t){return t.trim()}),e.forEach(function(t){var e=t.match(/([\s\S]*?)\s*\{([^}]*)\}/);t=e[1];var i=e[2].trim(),r=i.replace(/;$/,"").split(/\s*;\s*/);n[t]||(n[t]={});for(var o=0,s=r.length;s>o;o++){var a=r[o].split(/\s*:\s*/),c=a[0],l=a[1];n[t][c]=l}})}return n}function c(t){var e=t.nodeName,i=t.getAttribute("class"),n=t.getAttribute("id"),r={};for(var o in p.cssRules){var s=i&&new RegExp("^\\."+i).test(o)||n&&new RegExp("^#"+n).test(o)||new RegExp("^"+e).test(o);if(s)for(var a in p.cssRules[o])r[a]=p.cssRules[o][a]}return r}function l(t,e,i){function n(n){var r=n.responseXML;!r.documentElement&&p.window.ActiveXObject&&n.responseText&&(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n.responseText.replace(//i,""))),r.documentElement&&p.parseSVGDocument(r.documentElement,function(i,n){y.set(t,{objects:p.util.array.invoke(i,"toObject"),options:n}),e(i,n)},i)}t=t.replace(/^\n\s*/,"").trim(),y.has(t,function(i){i?y.get(t,function(t){var i=u(t);e(i.objects,i.options)}):new p.util.request(t,{method:"get",onComplete:n})})}function u(t){var e=t.objects,i=t.options;return e=e.map(function(t){return p[v(t.type)].fromObject(t)}),{objects:e,options:i}}function h(t,e,i){t=t.trim();var n;if("undefined"!=typeof DOMParser){var r=new DOMParser;r&&r.parseFromString&&(n=r.parseFromString(t,"text/xml"))}else p.window.ActiveXObject&&(n=new ActiveXObject("Microsoft.XMLDOM"),n.async="false",n.loadXML(t.replace(//i,"")));p.parseSVGDocument(n.documentElement,function(t,i){e(t,i)},i)}function f(t){for(var e="",i=0,n=t.length;n>i;i++)"text"===t[i].type&&t[i].path&&(e+=["@font-face {","font-family: ",t[i].fontFamily,"; ","src: url('",t[i].path,"')","}"].join(""));return e&&(e=['"].join("")),e}function d(t){var e="";return t.backgroundColor&&t.backgroundColor.source&&(e=['',''].join("")),e}var p=t.fabric||(t.fabric={}),g=p.util.object.extend,v=p.util.string.capitalize,m=p.util.object.clone,b={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix","text-decoration":"textDecoration","font-size":"fontSize","font-weight":"fontWeight","font-style":"fontStyle","font-family":"fontFamily"};p.parseTransformAttribute=function(){function t(t,e){var i=e[0];t[0]=Math.cos(i),t[1]=Math.sin(i),t[2]=-Math.sin(i),t[3]=Math.cos(i)}function e(t,e){var i=e[0],n=2===e.length?e[1]:e[0];t[0]=i,t[3]=n}function i(t,e){t[2]=e[0]}function n(t,e){t[1]=e[0]}function r(t,e){t[4]=e[0],2===e.length&&(t[5]=e[1])}var o=[1,0,0,1,0,0],s="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",a="(?:\\s+,?\\s*|,\\s*)",c="(?:(skewX)\\s*\\(\\s*("+s+")\\s*\\))",l="(?:(skewY)\\s*\\(\\s*("+s+")\\s*\\))",u="(?:(rotate)\\s*\\(\\s*("+s+")(?:"+a+"("+s+")"+a+"("+s+"))?\\s*\\))",h="(?:(scale)\\s*\\(\\s*("+s+")(?:"+a+"("+s+"))?\\s*\\))",f="(?:(translate)\\s*\\(\\s*("+s+")(?:"+a+"("+s+"))?\\s*\\))",d="(?:(matrix)\\s*\\(\\s*("+s+")"+a+"("+s+")"+a+"("+s+")"+a+"("+s+")"+a+"("+s+")"+a+"("+s+")\\s*\\))",p="(?:"+d+"|"+f+"|"+h+"|"+u+"|"+c+"|"+l+")",g="(?:"+p+"(?:"+a+p+")*)",v="^\\s*(?:"+g+"?)\\s*$",m=new RegExp(v),b=new RegExp(p);return function(s){var a=o.concat();return!s||s&&!m.test(s)?a:(s.replace(b,function(o){var s=new RegExp(p).exec(o).filter(function(t){return""!==t&&null!=t}),c=s[1],l=s.slice(2).map(parseFloat);switch(c){case"translate":r(a,l);break;case"rotate":t(a,l);break;case"scale":e(a,l);break;case"skewX":i(a,l);break;case"skewY":n(a,l);break;case"matrix":a=l}}),a)}}(),p.parseSVGDocument=function(){function t(t,e){for(;t&&(t=t.parentNode);)if(e.test(t.nodeName))return!0;return!1}var e=/^(path|circle|polygon|polyline|ellipse|rect|line|image|text)$/,i="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",n=new RegExp("^\\s*("+i+"+)\\s*,?\\s*("+i+"+)\\s*,?\\s*("+i+"+)\\s*,?\\s*("+i+"+)\\s*$");return function(i,r,o){if(i){var s=new Date,c=p.util.toArray(i.getElementsByTagName("*"));if(0===c.length){c=i.selectNodes("//*[name(.)!='svg']");for(var l=[],u=0,h=c.length;h>u;u++)l[u]=c[u];c=l}var f=c.filter(function(i){return e.test(i.tagName)&&!t(i,/^(?:pattern|defs)$/)});if(f&&(!f||f.length)){var d,g,v=i.getAttribute("viewBox"),b=i.getAttribute("width"),y=i.getAttribute("height"),x=null,w=null;v&&(v=v.match(n))&&(d=parseInt(v[1],10),g=parseInt(v[2],10),x=parseInt(v[3],10),w=parseInt(v[4],10)),x=b?parseFloat(b):x,w=y?parseFloat(y):w;var k={width:x,height:w};p.gradientDefs=p.getGradientDefs(i),p.cssRules=a(i),p.parseElements(f,function(t){p.documentParsingTime=new Date-s,r&&r(t,k)},m(k),o)}}}}();var y={has:function(t,e){e(!1)},get:function(){},set:function(){}};g(p,{parseAttributes:i,parseElements:s,parseStyleAttribute:r,parsePointsAttribute:n,getCSSRules:a,loadSVGFromURL:l,loadSVGFromString:h,createSVGFontFacesMarkup:f,createSVGRefElementsMarkup:d})}("undefined"!=typeof exports?exports:this),function(){function t(t){var e,i,n=t.getAttribute("style"),r=t.getAttribute("offset");if(r=parseFloat(r)/(/%$/.test(r)?100:1),n){var o=n.split(/\s*;\s*/);""===o[o.length-1]&&o.pop();for(var s=o.length;s--;){var a=o[s].split(/\s*:\s*/),c=a[0].trim(),l=a[1].trim();"stop-color"===c?e=l:"stop-opacity"===c&&(i=l)}}return e||(e=t.getAttribute("stop-color")),i||(i=t.getAttribute("stop-opacity")),e=new fabric.Color(e).toRgb(),{offset:r,color:e,opacity:i}}function e(t,e){for(var i in e){if("string"==typeof e[i]&&/^\d+%$/.test(e[i])){var n=parseFloat(e[i],10);"x1"===i||"x2"===i||"r2"===i?e[i]=fabric.util.toFixed(t.width*n/100,2):("y1"===i||"y2"===i)&&(e[i]=fabric.util.toFixed(t.height*n/100,2))}"x1"===i||"x2"===i?e[i]-=fabric.util.toFixed(t.width/2,2):("y1"===i||"y2"===i)&&(e[i]-=fabric.util.toFixed(t.height/2,2))}}function i(t,e){for(var i in e)"x1"===i||"x2"===i?e[i]+=fabric.util.toFixed(t.width/2,2):("y1"===i||"y2"===i)&&(e[i]+=fabric.util.toFixed(t.height/2,2)),"x1"===i||"x2"===i||"r2"===i?e[i]=fabric.util.toFixed(e[i]/t.width*100,2)+"%":("y1"===i||"y2"===i)&&(e[i]=fabric.util.toFixed(e[i]/t.height*100,2)+"%")}function n(t){var e,i,n=t.getElementsByTagName("linearGradient"),r=t.getElementsByTagName("radialGradient"),o={};for(i=n.length;i--;)e=n[i],o[e.getAttribute("id")]=e;for(i=r.length;i--;)e=r[i],o[e.getAttribute("id")]=e;return o}fabric.Gradient=fabric.util.createClass({initialize:function(t){t||(t={});var e={};this.id=fabric.Object.__uid++,this.type=t.type||"linear",e={x1:t.coords.x1||0,y1:t.coords.y1||0,x2:t.coords.x2||0,y2:t.coords.y2||0},"radial"===this.type&&(e.r1=t.coords.r1||0,e.r2=t.coords.r2||0),this.coords=e,this.gradientUnits=t.gradientUnits||"objectBoundingBox",this.colorStops=fabric.util.object.clone(t.colorStops)},addColorStop:function(t){for(var e in t){var i=new fabric.Color(t[e]);this.colorStops.push({offset:e,color:i.toRgb(),opacity:i.getAlpha()})}return this},toObject:function(){return{type:this.type,coords:this.coords,gradientUnits:this.gradientUnits,colorStops:this.colorStops}},toLive:function(t){var e;if(this.type){"linear"===this.type?e=t.createLinearGradient(this.coords.x1,this.coords.y1,this.coords.x2||t.canvas.width,this.coords.y2):"radial"===this.type&&(e=t.createRadialGradient(this.coords.x1,this.coords.y1,this.coords.r1,this.coords.x2,this.coords.y2,this.coords.r2));for(var i=0;i']:"radial"===this.type&&(n=["']);for(var o=0;o');return n.push("linear"===this.type?"":""),n.join("")}}),fabric.util.object.extend(fabric.Gradient,{fromElement:function(i,n){var r=i.getElementsByTagName("stop"),o="linearGradient"===i.nodeName?"linear":"radial",s=i.getAttribute("gradientUnits")||"objectBoundingBox",a=[],c={};"linear"===o?c={x1:i.getAttribute("x1")||0,y1:i.getAttribute("y1")||0,x2:i.getAttribute("x2")||"100%",y2:i.getAttribute("y2")||0}:"radial"===o&&(c={x1:i.getAttribute("fx")||i.getAttribute("cx")||"50%",y1:i.getAttribute("fy")||i.getAttribute("cy")||"50%",r1:0,x2:i.getAttribute("cx")||"50%",y2:i.getAttribute("cy")||"50%",r2:i.getAttribute("r")||"50%"});for(var l=r.length;l--;)a.push(t(r[l]));return e(n,c),new fabric.Gradient({type:o,coords:c,gradientUnits:s,colorStops:a})},forObject:function(t,i){return i||(i={}),e(t,i),new fabric.Gradient(i)}}),fabric.getGradientDefs=n}(),fabric.Pattern=fabric.util.createClass({repeat:"repeat",initialize:function(t){t||(t={}),t.source&&(this.source="string"==typeof t.source?new Function(t.source):t.source),t.repeat&&(this.repeat=t.repeat)},toObject:function(){var t;return"function"==typeof this.source?t=String(this.source).match(/function\s+\w*\s*\(.*\)\s+\{([\s\S]*)\}/)[1]:"string"==typeof this.source.src&&(t=this.source.src),{source:t,repeat:this.repeat}},toLive:function(t){var e="function"==typeof this.source?this.source():this.source;return t.createPattern(e,this.repeat)}}),fabric.Shadow=fabric.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,initialize:function(t){for(var e in t)this[e]=t[e]},toObject:function(){return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY}},toSVG:function(){}}),function(t){"use strict";function e(t,e){arguments.length>0&&this.init(t,e)}var i=t.fabric||(t.fabric={});return i.Point?void i.warn("fabric.Point is already defined"):(i.Point=e,void(e.prototype={constructor:e,init:function(t,e){this.x=t,this.y=e},add:function(t){return new e(this.x+t.x,this.y+t.y)},addEquals:function(t){return this.x+=t.x,this.y+=t.y,this},scalarAdd:function(t){return new e(this.x+t,this.y+t)},scalarAddEquals:function(t){return this.x+=t,this.y+=t,this},subtract:function(t){return new e(this.x-t.x,this.y-t.y)},subtractEquals:function(t){return this.x-=t.x,this.y-=t.y,this},scalarSubtract:function(t){return new e(this.x-t,this.y-t)},scalarSubtractEquals:function(t){return this.x-=t,this.y-=t,this},multiply:function(t){return new e(this.x*t,this.y*t)},multiplyEquals:function(t){return this.x*=t,this.y*=t,this},divide:function(t){return new e(this.x/t,this.y/t)},divideEquals:function(t){return this.x/=t,this.y/=t,this},eq:function(t){return this.x===t.x&&this.y===t.y},lt:function(t){return this.xt.x&&this.y>t.y},gte:function(t){return this.x>=t.x&&this.y>=t.y},lerp:function(t,i){return new e(this.x+(t.x-this.x)*i,this.y+(t.y-this.y)*i)},distanceFrom:function(t){var e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)},midPointFrom:function(t){return new e(this.x+(t.x-this.x)/2,this.y+(t.y-this.y)/2)},min:function(t){return new e(Math.min(this.x,t.x),Math.min(this.y,t.y))},max:function(t){return new e(Math.max(this.x,t.x),Math.max(this.y,t.y))},toString:function(){return this.x+","+this.y},setXY:function(t,e){this.x=t,this.y=e},setFromPoint:function(t){this.x=t.x,this.y=t.y},swap:function(t){var e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i}}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";function e(t){arguments.length>0&&this.init(t)}var i=t.fabric||(t.fabric={});return i.Intersection?void i.warn("fabric.Intersection is already defined"):(i.Intersection=e,i.Intersection.prototype={init:function(t){this.status=t,this.points=[]},appendPoint:function(t){this.points.push(t)},appendPoints:function(t){this.points=this.points.concat(t)}},i.Intersection.intersectLineLine=function(t,n,r,o){var s,a=(o.x-r.x)*(t.y-r.y)-(o.y-r.y)*(t.x-r.x),c=(n.x-t.x)*(t.y-r.y)-(n.y-t.y)*(t.x-r.x),l=(o.y-r.y)*(n.x-t.x)-(o.x-r.x)*(n.y-t.y);if(0!==l){var u=a/l,h=c/l;u>=0&&1>=u&&h>=0&&1>=h?(s=new e("Intersection"),s.points.push(new i.Point(t.x+u*(n.x-t.x),t.y+u*(n.y-t.y)))):s=new e("No Intersection")}else s=new e(0===a||0===c?"Coincident":"Parallel");return s},i.Intersection.intersectLinePolygon=function(t,i,n){for(var r=new e("No Intersection"),o=n.length,s=0;o>s;s++){var a=n[s],c=n[(s+1)%o],l=e.intersectLineLine(t,i,a,c);r.appendPoints(l.points)}return r.points.length>0&&(r.status="Intersection"),r},i.Intersection.intersectPolygonPolygon=function(t,i){for(var n=new e("No Intersection"),r=t.length,o=0;r>o;o++){var s=t[o],a=t[(o+1)%r],c=e.intersectLinePolygon(s,a,i);n.appendPoints(c.points)}return n.points.length>0&&(n.status="Intersection"),n},void(i.Intersection.intersectPolygonRectangle=function(t,n,r){var o=n.min(r),s=n.max(r),a=new i.Point(s.x,o.y),c=new i.Point(o.x,s.y),l=e.intersectLinePolygon(o,a,t),u=e.intersectLinePolygon(a,s,t),h=e.intersectLinePolygon(s,c,t),f=e.intersectLinePolygon(c,o,t),d=new e("No Intersection");return d.appendPoints(l.points),d.appendPoints(u.points),d.appendPoints(h.points),d.appendPoints(f.points),d.points.length>0&&(d.status="Intersection"),d}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";function e(t){t?this._tryParsingColor(t):this.setSource([0,0,0,1])}var i=t.fabric||(t.fabric={});return i.Color?void i.warn("fabric.Color is already defined."):(i.Color=e,i.Color.prototype={_tryParsingColor:function(t){var i;t in e.colorNameMap&&(t=e.colorNameMap[t]),i=e.sourceFromHex(t),i||(i=e.sourceFromRgb(t)),i&&this.setSource(i)},getSource:function(){return this._source},setSource:function(t){this._source=t},toRgb:function(){var t=this.getSource();return"rgb("+t[0]+","+t[1]+","+t[2]+")"},toRgba:function(){var t=this.getSource();return"rgba("+t[0]+","+t[1]+","+t[2]+","+t[3]+")"},toHex:function(){var t=this.getSource(),e=t[0].toString(16);e=1===e.length?"0"+e:e;var i=t[1].toString(16);i=1===i.length?"0"+i:i;var n=t[2].toString(16);return n=1===n.length?"0"+n:n,e.toUpperCase()+i.toUpperCase()+n.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(t){var e=this.getSource();return e[3]=t,this.setSource(e),this},toGrayscale:function(){var t=this.getSource(),e=parseInt((.3*t[0]+.59*t[1]+.11*t[2]).toFixed(0),10),i=t[3];return this.setSource([e,e,e,i]),this},toBlackWhite:function(t){var e=this.getSource(),i=(.3*e[0]+.59*e[1]+.11*e[2]).toFixed(0),n=e[3];return t=t||127,i=Number(i)a;a++)i.push(Math.round(o[a]*(1-r)+s[a]*r));return i[3]=n,this.setSource(i),this}},i.Color.reRGBa=/^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/,i.Color.reHex=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i,i.Color.colorNameMap={aqua:"#00FFFF",black:"#000000",blue:"#0000FF",fuchsia:"#FF00FF",gray:"#808080",green:"#008000",lime:"#00FF00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#FF0000",silver:"#C0C0C0",teal:"#008080",white:"#FFFFFF",yellow:"#FFFF00"},i.Color.fromRgb=function(t){return e.fromSource(e.sourceFromRgb(t))},i.Color.sourceFromRgb=function(t){var i=t.match(e.reRGBa);return i?[parseInt(i[1],10),parseInt(i[2],10),parseInt(i[3],10),i[4]?parseFloat(i[4]):1]:void 0},i.Color.fromRgba=e.fromRgb,i.Color.fromHex=function(t){return e.fromSource(e.sourceFromHex(t))},i.Color.sourceFromHex=function(t){if(t.match(e.reHex)){var i=t.slice(t.indexOf("#")+1),n=3===i.length,r=n?i.charAt(0)+i.charAt(0):i.substring(0,2),o=n?i.charAt(1)+i.charAt(1):i.substring(2,4),s=n?i.charAt(2)+i.charAt(2):i.substring(4,6);return[parseInt(r,16),parseInt(o,16),parseInt(s,16),1]}},void(i.Color.fromSource=function(t){var i=new e;return i.setSource(t),i}))}("undefined"!=typeof exports?exports:this),function(){"use strict";if(fabric.StaticCanvas)return void fabric.warn("fabric.StaticCanvas is already defined.");var t=fabric.util.object.extend,e=fabric.util.getElementOffset,i=fabric.util.removeFromArray,n=fabric.util.removeListener,r=new Error("Could not initialize `canvas` element");fabric.StaticCanvas=function(t,e){e||(e={}),this._initStatic(t,e),fabric.StaticCanvas.activeInstance=this},t(fabric.StaticCanvas.prototype,fabric.Observable),t(fabric.StaticCanvas.prototype,{backgroundColor:"",backgroundImage:"",backgroundImageOpacity:1,backgroundImageStretch:!0,overlayImage:"",overlayImageLeft:0,overlayImageTop:0,includeDefaultValues:!0,stateful:!0,renderOnAddition:!0,clipTo:null,controlsAboveOverlay:!1,onBeforeScaleRotate:function(){},_initStatic:function(t,e){this._objects=[],this._createLowerCanvas(t),this._initOptions(e),e.overlayImage&&this.setOverlayImage(e.overlayImage,this.renderAll.bind(this)),e.backgroundImage&&this.setBackgroundImage(e.backgroundImage,this.renderAll.bind(this)),e.backgroundColor&&this.setBackgroundColor(e.backgroundColor,this.renderAll.bind(this)),this.calcOffset()},calcOffset:function(){return this._offset=e(this.lowerCanvasEl),this},setOverlayImage:function(t,e,i){return fabric.util.loadImage(t,function(t){this.overlayImage=t,i&&"overlayImageLeft"in i&&(this.overlayImageLeft=i.overlayImageLeft),i&&"overlayImageTop"in i&&(this.overlayImageTop=i.overlayImageTop),e&&e()},this),this},setBackgroundImage:function(t,e,i){return fabric.util.loadImage(t,function(t){this.backgroundImage=t,i&&"backgroundImageOpacity"in i&&(this.backgroundImageOpacity=i.backgroundImageOpacity),i&&"backgroundImageStretch"in i&&(this.backgroundImageStretch=i.backgroundImageStretch),e&&e()},this),this},setBackgroundColor:function(t,e){if(t.source){var i=this;fabric.util.loadImage(t.source,function(n){i.backgroundColor=new fabric.Pattern({source:n,repeat:t.repeat}),e&&e()})}else this.backgroundColor=t,e&&e();return this},_createCanvasElement:function(){var t=fabric.document.createElement("canvas");if(t.style||(t.style={}),!t)throw r;return this._initCanvasElement(t),t},_initCanvasElement:function(t){if(fabric.util.createCanvasElement(t),"undefined"==typeof t.getContext)throw r},_initOptions:function(t){for(var e in t)this[e]=t[e];this.width=parseInt(this.lowerCanvasEl.width,10)||0,this.height=parseInt(this.lowerCanvasEl.height,10)||0,this.lowerCanvasEl.style&&(this.lowerCanvasEl.style.width=this.width+"px",this.lowerCanvasEl.style.height=this.height+"px")},_createLowerCanvas:function(t){this.lowerCanvasEl=fabric.util.getById(t)||this._createCanvasElement(),this._initCanvasElement(this.lowerCanvasEl),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(t){return this._setDimension("width",t)},setHeight:function(t){return this._setDimension("height",t)},setDimensions:function(t){for(var e in t)this._setDimension(e,t[e]);return this},_setDimension:function(t,e){return this.lowerCanvasEl[t]=e,this.lowerCanvasEl.style[t]=e+"px",this.upperCanvasEl&&(this.upperCanvasEl[t]=e,this.upperCanvasEl.style[t]=e+"px"),this.cacheCanvasEl&&(this.cacheCanvasEl[t]=e),this.wrapperEl&&(this.wrapperEl.style[t]=e+"px"),this[t]=e,this.calcOffset(),this.renderAll(),this},getElement:function(){return this.lowerCanvasEl},getActiveObject:function(){return null},getActiveGroup:function(){return null},_draw:function(t,e){if(e)if(this.controlsAboveOverlay){var i=e.hasBorders,n=e.hasControls;e.hasBorders=e.hasControls=!1,e.render(t),e.hasBorders=i,e.hasControls=n}else e.render(t)},add:function(){this._objects.push.apply(this._objects,arguments);for(var t=arguments.length;t--;)this._initObject(arguments[t]);return this.renderOnAddition&&this.renderAll(),this},_initObject:function(t){this.stateful&&t.setupState(),t.setCoords(),t.canvas=this,this.fire("object:added",{target:t}),t.fire("added")},insertAt:function(t,e,i){return i?this._objects[e]=t:this._objects.splice(e,0,t),this._initObject(t),this.renderOnAddition&&this.renderAll(),this},getObjects:function(){return this._objects},clearContext:function(t){return t.clearRect(0,0,this.width,this.height),this},getContext:function(){return this.contextContainer},clear:function(){return this._objects.length=0,this.discardActiveGroup&&this.discardActiveGroup(),this.clearContext(this.contextContainer),this.contextTop&&this.clearContext(this.contextTop),this.fire("canvas:cleared"),this.renderAll(),this},renderAll:function(t){var e=this[t===!0&&this.interactive?"contextTop":"contextContainer"];this.contextTop&&this.selection&&this.clearContext(this.contextTop),t||this.clearContext(e),this.fire("before:render"),this.clipTo&&fabric.util.clipCanvas(this,e),this.backgroundColor&&(e.fillStyle=this.backgroundColor.toLive?this.backgroundColor.toLive(e):this.backgroundColor,e.fillRect(0,0,this.width,this.height)),"object"==typeof this.backgroundImage&&this._drawBackroundImage(e);for(var i=this.getActiveGroup(),n=0,r=this._objects.length;r>n;++n)(!i||i&&this._objects[n]&&!i.contains(this._objects[n]))&&this._draw(e,this._objects[n]);if(i){var o=[];this.forEachObject(function(t){i.contains(t)&&o.push(t)}),i._set("objects",o),this._draw(e,i)}return this.clipTo&&e.restore(), this.overlayImage&&e.drawImage(this.overlayImage,this.overlayImageLeft,this.overlayImageTop),this.controlsAboveOverlay&&this.drawControls(e),this.fire("after:render"),this},_drawBackroundImage:function(t){t.save(),t.globalAlpha=this.backgroundImageOpacity,this.backgroundImageStretch?t.drawImage(this.backgroundImage,0,0,this.width,this.height):t.drawImage(this.backgroundImage,0,0),t.restore()},renderTop:function(){var t=this.contextTop||this.contextContainer;this.clearContext(t),this.selection&&this._groupSelector&&this._drawSelection();var e=this.getActiveGroup();return e&&e.render(t),this.overlayImage&&t.drawImage(this.overlayImage,this.overlayImageLeft,this.overlayImageTop),this.fire("after:render"),this},drawControls:function(t){var e=this.getActiveGroup();if(e)t.save(),fabric.Group.prototype.transform.call(e,t),e.drawBorders(t).drawControls(t),t.restore();else for(var i=0,n=this._objects.length;n>i;++i)this._objects[i]&&this._objects[i].active&&(t.save(),fabric.Object.prototype.transform.call(this._objects[i],t),this._objects[i].drawBorders(t).drawControls(t),t.restore(),this.lastRenderedObjectWithControlsAboveOverlay=this._objects[i])},toDataURL:function(t){t||(t={});var e=t.format||"png",i=t.quality||1,n=t.multiplier||1;return 1!==n?this.__toDataURLWithMultiplier(e,i,n):this.__toDataURL(e,i)},__toDataURL:function(t,e){this.renderAll(!0);var i=this.upperCanvasEl||this.lowerCanvasEl,n=fabric.StaticCanvas.supports("toDataURLWithQuality")?i.toDataURL("image/"+t,e):i.toDataURL("image/"+t);return this.contextTop&&this.clearContext(this.contextTop),this.renderAll(),n},__toDataURLWithMultiplier:function(t,e,i){var n=this.getWidth(),r=this.getHeight(),o=n*i,s=r*i,a=this.getActiveObject(),c=this.getActiveGroup(),l=this.contextTop||this.contextContainer;this.setWidth(o).setHeight(s),l.scale(i,i),c?this._tempRemoveBordersControlsFromGroup(c):a&&this.deactivateAll&&this.deactivateAll(),this.width=n,this.height=r,this.renderAll(!0);var u=this.toDataURL(t,e);return l.scale(1/i,1/i),this.setWidth(n).setHeight(r),c?this._restoreBordersControlsOnGroup(c):a&&this.setActiveObject&&this.setActiveObject(a),this.contextTop&&this.clearContext(this.contextTop),this.renderAll(),u},toDataURLWithMultiplier:function(t,e,i){return this.toDataURL({format:t,multiplier:e,quality:i})},_tempRemoveBordersControlsFromGroup:function(t){t.origHasControls=t.hasControls,t.origBorderColor=t.borderColor,t.hasControls=!0,t.borderColor="rgba(0,0,0,0)",t.forEachObject(function(t){t.origBorderColor=t.borderColor,t.borderColor="rgba(0,0,0,0)"})},_restoreBordersControlsOnGroup:function(t){t.hideControls=t.origHideControls,t.borderColor=t.origBorderColor,t.forEachObject(function(t){t.borderColor=t.origBorderColor,delete t.origBorderColor})},getCenter:function(){return{top:this.getHeight()/2,left:this.getWidth()/2}},centerObjectH:function(t){return t.set("left",this.getCenter().left),this.renderAll(),this},centerObjectV:function(t){return t.set("top",this.getCenter().top),this.renderAll(),this},centerObject:function(t){return this.centerObjectH(t).centerObjectV(t)},toDatalessJSON:function(t){return this.toDatalessObject(t)},toObject:function(t){return this._toObjectMethod("toObject",t)},toDatalessObject:function(t){return this._toObjectMethod("toDatalessObject",t)},_toObjectMethod:function(t,e){var i={objects:this._objects.map(function(i){var n;this.includeDefaultValues||(n=i.includeDefaultValues,i.includeDefaultValues=!1);var r=i[t](e);return this.includeDefaultValues||(i.includeDefaultValues=n),r},this),background:this.backgroundColor&&this.backgroundColor.toObject?this.backgroundColor.toObject():this.backgroundColor};return this.backgroundImage&&(i.backgroundImage=this.backgroundImage.src,i.backgroundImageOpacity=this.backgroundImageOpacity,i.backgroundImageStretch=this.backgroundImageStretch),this.overlayImage&&(i.overlayImage=this.overlayImage.src,i.overlayImageLeft=this.overlayImageLeft,i.overlayImageTop=this.overlayImageTop),fabric.util.populateWithProperties(this,i,e),i},toSVG:function(t){t||(t={});var e=[];t.suppressPreamble||e.push('',''),e.push("',"Created with Fabric.js ",fabric.version,"","",fabric.createSVGFontFacesMarkup(this.getObjects()),fabric.createSVGRefElementsMarkup(this),""),this.backgroundColor&&this.backgroundColor.source&&e.push('"),this.backgroundImage&&e.push(''),this.overlayImage&&e.push('');for(var i=0,n=this.getObjects(),r=n.length;r>i;i++)e.push(n[i].toSVG());return e.push(""),e.join("")},isEmpty:function(){return 0===this._objects.length},remove:function(t){this.getActiveObject()===t&&(this.fire("before:selection:cleared",{target:t}),this.discardActiveObject(),this.fire("selection:cleared"));var e=this._objects,i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.fire("object:removed",{target:t})),this.renderAll(),t},sendToBack:function(t){return i(this._objects,t),this._objects.unshift(t),this.renderAll()},bringToFront:function(t){return i(this._objects,t),this._objects.push(t),this.renderAll()},sendBackwards:function(t){var e=this._objects.indexOf(t),n=e;if(0!==e){for(var r=e-1;r>=0;--r){var o=t.intersectsWithObject(this._objects[r])||t.isContainedWithinObject(this._objects[r])||this._objects[r].isContainedWithinObject(t);if(o){n=r;break}}i(this._objects,t),this._objects.splice(n,0,t)}return this.renderAll()},bringForward:function(t){var e=this.getObjects(),n=e.indexOf(t),r=n;if(n!==e.length-1){for(var o=n+1,s=this._objects.length;s>o;++o){var a=t.intersectsWithObject(e[o])||t.isContainedWithinObject(this._objects[o])||this._objects[o].isContainedWithinObject(t);if(a){r=o;break}}i(e,t),e.splice(r,0,t)}this.renderAll()},item:function(t){return this.getObjects()[t]},complexity:function(){return this.getObjects().reduce(function(t,e){return t+=e.complexity?e.complexity():0},0)},forEachObject:function(t,e){for(var i=this.getObjects(),n=i.length;n--&&t.call(e,i[n],n,i)!==!1;);return this},dispose:function(){return this.clear(),this.interactive&&(n(this.upperCanvasEl,"mousedown",this._onMouseDown),n(this.upperCanvasEl,"mousemove",this._onMouseMove),n(fabric.window,"resize",this._onResize)),this},_resizeImageToFit:function(t){var e=t.width||t.offsetWidth,i=this.getWidth()/e;e&&(t.width=e*i)}}),fabric.StaticCanvas.prototype.toString=function(){return"#"},t(fabric.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(t){var e,i,n,r,o=t.getContext("2d"),s=o.getImageData(0,0,t.width,t.height),a=s.data,c=s.width,l=s.height;for(n=0;c>n;n++)for(r=0;l>r;r++)e=4*n*l+4*r,i=(a[e]+a[e+1]+a[e+2])/3,a[e]=i,a[e+1]=i,a[e+2]=i;o.putImageData(s,0,0)},supports:function(t){var e=fabric.util.createCanvasElement();if(!e||!e.getContext)return null;var i=e.getContext("2d");if(!i)return null;switch(t){case"getImageData":return"undefined"!=typeof i.getImageData;case"toDataURL":return"undefined"!=typeof e.toDataURL;case"toDataURLWithQuality":try{return e.toDataURL("image/jpeg",0),!0}catch(n){}return!1;default:return null}}}),fabric.StaticCanvas.prototype.toJSON=fabric.StaticCanvas.prototype.toObject}(),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.array.min,n=e.util.array.max;return e.FreeDrawing?void e.warn("fabric.FreeDrawing is already defined"):void(e.FreeDrawing=e.util.createClass({initialize:function(t){this.canvas=t,this._points=[]},_addPoint:function(t){this._points.push(t)},_reset:function(){this._points.length=0;var t=this.canvas.contextTop;t.strokeStyle=this.canvas.freeDrawingColor,t.lineWidth=this.canvas.freeDrawingLineWidth,t.lineCap=t.lineJoin="round"},_prepareForDrawing:function(t){this.canvas._isCurrentlyDrawing=!0,this.canvas.discardActiveObject().renderAll();var i=new e.Point(t.x,t.y);this._reset(),this._addPoint(i),this.canvas.contextTop.moveTo(i.x,i.y)},_captureDrawingPath:function(t){var i=new e.Point(t.x,t.y);this._addPoint(i)},_render:function(){var t=this.canvas.contextTop;t.beginPath();var e=this._points[0],i=this._points[1];t.moveTo(e.x,e.y);for(var n=1,r=this._points.length;r>n;n++){var o=e.midPointFrom(i);t.quadraticCurveTo(e.x,e.y,o.x,o.y),e=this._points[n],i=this._points[n+1]}t.lineTo(e.x,e.y),t.stroke()},_getSVGPathData:function(){return this.box=this.getPathBoundingBox(this._points),this.convertPointsToSVGPath(this._points,this.box.minx,this.box.maxx,this.box.miny,this.box.maxy)},getPathBoundingBox:function(t){for(var e=[],r=[],o=t[0],s=t[1],a=o,c=1,l=t.length;l>c;c++){var u=o.midPointFrom(s);e.push(a.x),e.push(u.x),r.push(a.y),r.push(u.y),o=t[c],s=t[c+1],a=u}return e.push(o.x),r.push(o.y),{minx:i(e),miny:i(r),maxx:n(e),maxy:n(r)}},convertPointsToSVGPath:function(t,i,n,r){var o=[],s=new e.Point(t[0].x-i,t[0].y-r),a=new e.Point(t[1].x-i,t[1].y-r);o.push("M ",t[0].x-i," ",t[0].y-r," ");for(var c=1,l=t.length;l>c;c++){var u=s.midPointFrom(a);o.push("Q ",s.x," ",s.y," ",u.x," ",u.y," "),s=new e.Point(t[c].x-i,t[c].y-r),c+10&&(e>this.targetFindTolerance?e-=this.targetFindTolerance:e=0,i>this.targetFindTolerance?i-=this.targetFindTolerance:i=0);for(var s=!0,a=n.getImageData(e,i,2*this.targetFindTolerance||1,2*this.targetFindTolerance||1),c=3;c=l,s===!1)break}return a=null,this.clearContext(n),s},_shouldClearSelection:function(t){var e=this.findTarget(t),i=this.getActiveGroup();return!e||e&&i&&!i.contains(e)&&i!==e&&!t.shiftKey},_setupCurrentTransform:function(t,e){var r,o="drag",s=i(t,e.canvas.upperCanvasEl);r=e._findTargetCorner(t,this._offset),r&&(o="ml"===r||"mr"===r?"scaleX":"mt"===r||"mb"===r?"scaleY":"mtr"===r?"rotate":"scale");var a="center",c="center";"ml"===r||"tl"===r||"bl"===r?a="right":("mr"===r||"tr"===r||"br"===r)&&(a="left"),"tl"===r||"mt"===r||"tr"===r?c="bottom":("bl"===r||"mb"===r||"br"===r)&&(c="top"),"mtr"===r&&(a="center",c="center"),this._currentTransform={target:e,action:o,scaleX:e.scaleX,scaleY:e.scaleY,offsetX:s.x-e.left,offsetY:s.y-e.top,originX:a,originY:c,ex:s.x,ey:s.y,left:e.left,top:e.top,theta:n(e.angle),width:e.width*e.scaleX,mouseXSign:1,mouseYSign:1},this._currentTransform.original={left:e.left,top:e.top,scaleX:e.scaleX,scaleY:e.scaleY,originX:a,originY:c},this._resetCurrentTransform(t)},_shouldHandleGroupLogic:function(t,e){var i=this.getActiveObject();return t.shiftKey&&(this.getActiveGroup()||i&&i!==e)&&this.selection},_handleGroupLogic:function(t,e){if(e!==this.getActiveGroup()||(e=this.findTarget(t,!0),e&&!e.isType("group"))){var i=this.getActiveGroup();if(i)i.contains(e)?(i.removeWithUpdate(e),this._resetObjectTransform(i),e.setActive(!1),1===i.size()&&this.discardActiveGroup()):(i.addWithUpdate(e),this._resetObjectTransform(i)),this.fire("selection:created",{target:i,e:t}),i.setActive(!0);else{if(this._activeObject&&e!==this._activeObject){var n=new fabric.Group([this._activeObject,e]);this.setActiveGroup(n),i=this.getActiveGroup()}e.setActive(!0)}i&&i.saveCoords()}},_translateObject:function(t,e){var i=this._currentTransform.target;i.get("lockMovementX")||i.set("left",t-this._currentTransform.offsetX),i.get("lockMovementY")||i.set("top",e-this._currentTransform.offsetY)},_scaleObject:function(t,e,i){var n=this._currentTransform,r=this._offset,o=n.target,s=o.get("lockScalingX"),a=o.get("lockScalingY");if(!s||!a){var c=o.translateToOriginPoint(o.getCenterPoint(),n.originX,n.originY),l=o.toLocalPoint(new fabric.Point(t-r.left,e-r.top),n.originX,n.originY);"right"===n.originX?l.x*=-1:"center"===n.originX&&(l.x*=2*n.mouseXSign,l.x<0&&(n.mouseXSign=-n.mouseXSign)),"bottom"===n.originY?l.y*=-1:"center"===n.originY&&(l.y*=2*n.mouseYSign,l.y<0&&(n.mouseYSign=-n.mouseYSign));var u=o.scaleX,h=o.scaleY;if("equally"!==i||s||a)i?"x"!==i||o.get("lockUniScaling")?"y"!==i||o.get("lockUniScaling")||(h=l.y/(o.height+o.padding),a||o.set("scaleY",h)):(u=l.x/(o.width+o.padding),s||o.set("scaleX",u)):(u=l.x/(o.width+o.padding),h=l.y/(o.height+o.padding),s||o.set("scaleX",u),a||o.set("scaleY",h));else{var f=l.y+l.x,d=o.height*n.original.scaleY+o.width*n.original.scaleX+2*o.padding-2*o.strokeWidth+1;u=n.original.scaleX*f/d,h=n.original.scaleY*f/d,o.set("scaleX",u),o.set("scaleY",h)}0>u&&("left"===n.originX?n.originX="right":"right"===n.originX&&(n.originX="left")),0>h&&("top"===n.originY?n.originY="bottom":"bottom"===n.originY&&(n.originY="top")),o.setPositionByOrigin(c,n.originX,n.originY)}},_rotateObject:function(t,e){var i=this._currentTransform,n=this._offset;if(!i.target.get("lockRotation")){var s=o(i.ey-i.top-n.top,i.ex-i.left-n.left),a=o(e-i.top-n.top,t-i.left-n.left);i.target.angle=r(a-s+i.theta)}},_setCursor:function(t){this.upperCanvasEl.style.cursor=t},_resetObjectTransform:function(t){t.scaleX=1,t.scaleY=1,t.setAngle(0)},_drawSelection:function(){var t=this.contextTop,e=this._groupSelector,i=e.left,n=e.top,r=s(i),o=s(n);if(t.fillStyle=this.selectionColor,t.fillRect(e.ex-(i>0?0:-i),e.ey-(n>0?0:-n),r,o),t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,this.selectionDashArray.length>1){var a=e.ex+l-(i>0?0:r),c=e.ey+l-(n>0?0:o);t.beginPath(),fabric.util.drawDashedLine(t,a,c,a+r,c,this.selectionDashArray),fabric.util.drawDashedLine(t,a,c+o-1,a+r,c+o-1,this.selectionDashArray),fabric.util.drawDashedLine(t,a,c,a,c+o,this.selectionDashArray),fabric.util.drawDashedLine(t,a+r-1,c,a+r-1,c+o,this.selectionDashArray),t.closePath(),t.stroke()}else t.strokeRect(e.ex+l-(i>0?0:r),e.ey+l-(n>0?0:o),r,o)},_findSelectedObjects:function(t){for(var e,i=[],n=this._groupSelector.ex,r=this._groupSelector.ey,o=n+this._groupSelector.left,s=r+this._groupSelector.top,l=new fabric.Point(a(n,o),a(r,s)),u=new fabric.Point(c(n,o),c(r,s)),h=0,f=this._objects.length;f>h;++h)e=this._objects[h],e&&(e.intersectsWithRect(l,u)||e.isContainedWithinRect(l,u))&&this.selection&&e.selectable&&(e.setActive(!0),i.push(e));1===i.length?this.setActiveObject(i[0],t):i.length>1&&(i=new fabric.Group(i),this.setActiveGroup(i),i.saveCoords(),this.fire("selection:created",{target:i})),this.renderAll()},findTarget:function(t,e){var i,n=this.getPointer(t);if(this.controlsAboveOverlay&&this.lastRenderedObjectWithControlsAboveOverlay&&this.containsPoint(t,this.lastRenderedObjectWithControlsAboveOverlay)&&this.lastRenderedObjectWithControlsAboveOverlay._findTargetCorner(t,this._offset))return i=this.lastRenderedObjectWithControlsAboveOverlay;var r=this.getActiveGroup();if(r&&!e&&this.containsPoint(t,r))return i=r;for(var o=[],s=this._objects.length;s--;)if(this._objects[s]&&!this._objects[s].overlay&&this.containsPoint(t,this._objects[s])){if(!this.perPixelTargetFind&&!this._objects[s].perPixelTargetFind){i=this._objects[s],this.relatedTarget=i;break}o[o.length]=this._objects[s]}for(var a=0,c=o.length;c>a;a++){n=this.getPointer(t);var l=this._isTargetTransparent(o[a],n.x,n.y);if(!l){i=o[a],this.relatedTarget=i;break}}return i&&i.selectable?i:void 0},getPointer:function(t){var e=i(t,this.upperCanvasEl);return{x:Math.ceil((e.x-this._offset.left)*(this.upperCanvasEl.getAttribute("width")/parseInt(this.upperCanvasEl.style.width))),y:Math.ceil((e.y-this._offset.top)*(this.upperCanvasEl.getAttribute("height")/parseInt(this.upperCanvasEl.style.height)))}},_createUpperCanvas:function(){this.upperCanvasEl=this._createCanvasElement(),this.upperCanvasEl.className="upper-canvas",this.wrapperEl.appendChild(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.getWidth()+"px",height:this.getHeight()+"px",position:"relative"}),fabric.util.makeElementUnselectable(this.wrapperEl)},_applyCanvasStyle:function(t){var e=this.getWidth()||t.width,i=this.getHeight()||t.height;fabric.util.setStyle(t,{position:"absolute",width:e+"px",height:i+"px",left:0,top:0}),t.width=e,t.height=i,fabric.util.makeElementUnselectable(t)},getSelectionContext:function(){return this.contextTop},getSelectionElement:function(){return this.upperCanvasEl},setActiveObject:function(t,e){return this._activeObject&&this._activeObject.setActive(!1),this._activeObject=t,t.setActive(!0),this.renderAll(),this.fire("object:selected",{target:t,e:e}),t.fire("selected",{e:e}),this},getActiveObject:function(){return this._activeObject},discardActiveObject:function(){return this._activeObject&&this._activeObject.setActive(!1),this._activeObject=null,this},setActiveGroup:function(t){return this._activeGroup=t,t&&(t.canvas=this,t.setActive(!0)),this},getActiveGroup:function(){return this._activeGroup},discardActiveGroup:function(){var t=this.getActiveGroup();return t&&t.destroy(),this.setActiveGroup(null)},deactivateAll:function(){for(var t=this.getObjects(),e=0,i=t.length;i>e;e++)t[e].setActive(!1);return this.discardActiveGroup(),this.discardActiveObject(),this},deactivateAllWithDispatch:function(){var t=this.getActiveGroup()||this.getActiveObject();return t&&this.fire("before:selection:cleared",{target:t}),this.deactivateAll(),t&&this.fire("selection:cleared"),this}};fabric.Canvas.prototype.toString=fabric.StaticCanvas.prototype.toString,e(fabric.Canvas.prototype,u);for(var h in fabric.StaticCanvas)"prototype"!==h&&(fabric.Canvas[h]=fabric.StaticCanvas[h]);fabric.isTouchSupported&&(fabric.Canvas.prototype._setCursorFromEvent=function(){}),fabric.Element=fabric.Canvas}(),function(){var t={tr:"ne-resize",br:"se-resize",bl:"sw-resize",tl:"nw-resize",ml:"w-resize",mt:"n-resize",mr:"e-resize",mb:"s-resize"},e=fabric.util.addListener,i=fabric.util.removeListener,n=fabric.util.getPointer;fabric.util.object.extend(fabric.Canvas.prototype,{_initEvents:function(){var t=this;this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onResize=this._onResize.bind(this),e(fabric.window,"resize",this._onResize),fabric.isTouchSupported?(e(this.upperCanvasEl,"touchstart",this._onMouseDown),e(this.upperCanvasEl,"touchmove",this._onMouseMove),"undefined"!=typeof Event&&"add"in Event&&Event.add(this.upperCanvasEl,"gesture",function(e,i){t.__onTransformGesture(e,i)})):(e(this.upperCanvasEl,"mousedown",this._onMouseDown),e(this.upperCanvasEl,"mousemove",this._onMouseMove))},_onMouseDown:function(t){this.__onMouseDown(t),!fabric.isTouchSupported&&e(fabric.document,"mouseup",this._onMouseUp),fabric.isTouchSupported&&e(fabric.document,"touchend",this._onMouseUp),!fabric.isTouchSupported&&e(fabric.document,"mousemove",this._onMouseMove),fabric.isTouchSupported&&e(fabric.document,"touchmove",this._onMouseMove),!fabric.isTouchSupported&&i(this.upperCanvasEl,"mousemove",this._onMouseMove),fabric.isTouchSupported&&i(this.upperCanvasEl,"touchmove",this._onMouseMove)},_onMouseUp:function(t){this.__onMouseUp(t),!fabric.isTouchSupported&&i(fabric.document,"mouseup",this._onMouseUp),fabric.isTouchSupported&&i(fabric.document,"touchend",this._onMouseUp),!fabric.isTouchSupported&&i(fabric.document,"mousemove",this._onMouseMove),fabric.isTouchSupported&&i(fabric.document,"touchmove",this._onMouseMove),!fabric.isTouchSupported&&e(this.upperCanvasEl,"mousemove",this._onMouseMove),fabric.isTouchSupported&&e(this.upperCanvasEl,"touchmove",this._onMouseMove)},_onMouseMove:function(t){this.__onMouseMove(t)},_onResize:function(){this.calcOffset()},__onMouseUp:function(t){var e;if(this.isDrawingMode&&this._isCurrentlyDrawing)return this.freeDrawing._finalizeAndAddPath(),void this.fire("mouse:up",{e:t});if(this._currentTransform){var i=this._currentTransform;e=i.target,e._scaling&&(e._scaling=!1);for(var n=this._objects.length;n--;)this._objects[n].setCoords();e.isMoving=!1,this.stateful&&e.hasStateChanged()&&(this.fire("object:modified",{target:e}),e.fire("modified")),this._previousOriginX&&(this._currentTransform.target.adjustPosition(this._previousOriginX),this._previousOriginX=null)}this._currentTransform=null,this._groupSelector&&this._findSelectedObjects(t);var r=this.getActiveGroup();r&&(r.setObjectsCoords(),r.set("isMoving",!1),this._setCursor(this.defaultCursor)),this._groupSelector=null,this.renderAll(),this._setCursorFromEvent(t,e),this._setCursor("");var o=this;setTimeout(function(){o._setCursorFromEvent(t,e)},50),this.fire("mouse:up",{target:e,e:t}),e&&e.fire("mouseup",{e:t})},__onMouseDown:function(t){var e,i="which"in t?1===t.which:1===t.button;if(i||fabric.isTouchSupported){if(this.isDrawingMode)return e=this.getPointer(t),this.freeDrawing._prepareForDrawing(e),this.freeDrawing._captureDrawingPath(e),void this.fire("mouse:down",{e:t});if(!this._currentTransform){var n,r=this.findTarget(t);e=this.getPointer(t),this._shouldClearSelection(t)?(this._groupSelector={ex:e.x,ey:e.y,top:0,left:0},this.deactivateAllWithDispatch()):(this.stateful&&r.saveState(),(n=r._findTargetCorner(t,this._offset))&&this.onBeforeScaleRotate(r),this._shouldHandleGroupLogic(t,r)?(this._handleGroupLogic(t,r),r=this.getActiveGroup()):(r!==this.getActiveGroup()&&this.deactivateAll(),this.setActiveObject(r,t)),this._setupCurrentTransform(t,r)),this.renderAll(),this.fire("mouse:down",{target:r,e:t}),r&&r.fire("mousedown",{e:t}),"mtr"===n&&(this._previousOriginX=this._currentTransform.target.originX,this._currentTransform.target.adjustPosition("center"),this._currentTransform.left=this._currentTransform.target.left,this._currentTransform.top=this._currentTransform.target.top)}}},__onMouseMove:function(t){var e,i;if(this.isDrawingMode)return t.preventDefault&&t.preventDefault(),this._isCurrentlyDrawing&&(i=this.getPointer(t),this.freeDrawing._captureDrawingPath(i),this.clearContext(this.contextTop),this.freeDrawing._render(this.contextTop)),this.upperCanvasEl.style.cursor=this.freeDrawingCursor,void this.fire("mouse:move",{e:t});var r=this._groupSelector;if(null!==r)i=n(t,this.upperCanvasEl),r.left=i.x-this._offset.left-r.ex,r.top=i.y-this._offset.top-r.ey,this.renderTop();else if(this._currentTransform){t.preventDefault&&t.preventDefault(),i=n(t,this.upperCanvasEl);var o=i.x,s=i.y;this._currentTransform.target.isMoving=!0;var a=this._currentTransform,c=!1;"scale"!==a.action&&"scaleX"!==a.action&&"scaleY"!==a.action||(!t.altKey||"center"===a.originX&&"center"===a.originY)&&(t.altKey||"center"!==a.originX||"center"!==a.originY)||(this._resetCurrentTransform(t),c=!0),"rotate"===this._currentTransform.action?(this._rotateObject(o,s),this.fire("object:rotating",{target:this._currentTransform.target,e:t}),this._currentTransform.target.fire("rotating")):"scale"===this._currentTransform.action?(t.shiftKey||this.uniScaleTransform?(this._currentTransform.currentAction="scale",this._scaleObject(o,s)):(c||"scale"!==a.currentAction||this._resetCurrentTransform(t),this._currentTransform.currentAction="scaleEqually",this._scaleObject(o,s,"equally")),this.fire("object:scaling",{target:this._currentTransform.target,e:t})):"scaleX"===this._currentTransform.action?(this._scaleObject(o,s,"x"),this.fire("object:scaling",{target:this._currentTransform.target,e:t}),this._currentTransform.target.fire("scaling",{e:t})):"scaleY"===this._currentTransform.action?(this._scaleObject(o,s,"y"),this.fire("object:scaling",{target:this._currentTransform.target,e:t}),this._currentTransform.target.fire("scaling",{e:t})):(this._translateObject(o,s),this.fire("object:moving",{target:this._currentTransform.target,e:t}),this._setCursor(this.moveCursor),this._currentTransform.target.fire("moving",{e:t})),this.renderAll()}else{var l=this.upperCanvasEl.style;if(e=this.findTarget(t))t.preventDefault&&t.preventDefault(),this._setCursorFromEvent(t,e);else{for(var u=this._objects.length;u--;)this._objects[u]&&!this._objects[u].active&&this._objects[u].setActive(!1);l.cursor=this.defaultCursor}}this.fire("mouse:move",{target:e,e:t}),e&&e.fire("mousemove",{e:t})},_setCursorFromEvent:function(e,i){var n=this.upperCanvasEl.style;if(!i)return n.cursor=this.defaultCursor,!1;var r=this.getActiveGroup(),o=i._findTargetCorner&&(!r||!r.contains(i))&&i._findTargetCorner(e,this._offset);if(o)if(o in t)n.cursor=t[o];else{if("mtr"!==o||!i.hasRotatingPoint)return n.cursor=this.defaultCursor,!1;n.cursor=this.rotationCursor}else n.cursor=this.hoverCursor;return!0}})}(),fabric.util.object.extend(fabric.StaticCanvas.prototype,{FX_DURATION:500,fxCenterObjectH:function(t,e){e=e||{};var i=function(){},n=e.onComplete||i,r=e.onChange||i,o=this;return fabric.util.animate({startValue:t.get("left"),endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(e){t.set("left",e),o.renderAll(),r()},onComplete:function(){t.setCoords(),n()}}),this},fxCenterObjectV:function(t,e){e=e||{};var i=function(){},n=e.onComplete||i,r=e.onChange||i,o=this;return fabric.util.animate({startValue:t.get("top"),endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(e){t.set("top",e),o.renderAll(),r()},onComplete:function(){t.setCoords(),n()}}),this},fxRemove:function(t,e){e=e||{};var i=function(){},n=e.onComplete||i,r=e.onChange||i,o=this;return fabric.util.animate({startValue:t.get("opacity"),endValue:0,duration:this.FX_DURATION,onStart:function(){t.setActive(!1)},onChange:function(e){t.set("opacity",e),o.renderAll(),r()},onComplete:function(){o.remove(t),n()}}),this}}),fabric.util.object.extend(fabric.StaticCanvas.prototype,{loadFromDatalessJSON:function(t,e){if(t){var i="string"==typeof t?JSON.parse(t):t;if(i&&(!i||i.objects)){this.clear();var n=this;this._enlivenDatalessObjects(i.objects,function(){n._setBgOverlayImages(i,e)})}}},_enlivenDatalessObjects:function(t,e){function i(t,i){r.insertAt(t,i,!0),t.setCoords(),++o===s&&e&&e()}function n(t,e){var n=t.paths?"paths":"path",r=t[n];if(delete t[n],"string"!=typeof r)if("image"===t.type||"group"===t.type)fabric[fabric.util.string.capitalize(t.type)].fromObject(t,function(t){i(t,e)});else{var o=fabric[fabric.util.string.camelize(fabric.util.string.capitalize(t.type))];if(!o||!o.fromObject)return;r&&(t[n]=r),i(o.fromObject(t),e)}else if("image"===t.type)fabric.util.loadImage(r,function(n){var o=new fabric.Image(n);o.setSourcePath(r),fabric.util.object.extend(o,t),o.setAngle(t.angle),i(o,e)});else if("text"===t.type)if(t.useNative)i(fabric.Text.fromObject(t),e);else{t.path=r;var s=fabric.Text.fromObject(t),a=function(){"[object Opera]"===Object.prototype.toString.call(fabric.window.opera)?setTimeout(function(){i(s,e)},500):i(s,e)};fabric.util.getScript(r,a)}else fabric.loadSVGFromURL(r,function(n){var o=fabric.util.groupSVGElements(n,t,r);o instanceof fabric.PathGroup||(fabric.util.object.extend(o,t),"undefined"!=typeof t.angle&&o.setAngle(t.angle)),i(o,e)})}var r=this,o=0,s=t.length;0===s&&e&&e();try{t.forEach(n,this)}catch(a){fabric.log(a)}},loadFromJSON:function(t,e){if(t){var i="string"==typeof t?JSON.parse(t):t,n=this;return this._enlivenObjects(i.objects,function(){n._setBgOverlayImages(i,e)}),this}},_setBgOverlayImages:function(t,e){var i,n,r,o=this;t.backgroundImage?this.setBackgroundImage(t.backgroundImage,function(){o.backgroundImageOpacity=t.backgroundImageOpacity,o.backgroundImageStretch=t.backgroundImageStretch,o.renderAll(),n=!0,e&&r&&i&&e()}):n=!0,t.overlayImage?this.setOverlayImage(t.overlayImage,function(){o.overlayImageLeft=t.overlayImageLeft||0,o.overlayImageTop=t.overlayImageTop||0,o.renderAll(),r=!0,e&&n&&i&&e()}):r=!0,t.background?this.setBackgroundColor(t.background,function(){o.renderAll(),i=!0,e&&r&&n&&e()}):i=!0,t.backgroundImage||t.overlayImage||t.background||e&&e()},_enlivenObjects:function(t,e){ var i=this;fabric.util.enlivenObjects(t,function(t){t.forEach(function(t,e){i.insertAt(t,e,!0)}),e&&e()})},_toDataURL:function(t,e){this.clone(function(i){e(i.toDataURL(t))})},_toDataURLWithMultiplier:function(t,e,i){this.clone(function(n){i(n.toDataURLWithMultiplier(t,e))})},clone:function(t){var e=JSON.stringify(this);this.cloneWithoutData(function(i){i.loadFromJSON(e,function(){t&&t(i)})})},cloneWithoutData:function(t){var e=fabric.document.createElement("canvas");e.width=this.getWidth(),e.height=this.getHeight();var i=new fabric.Canvas(e);i.clipTo=this.clipTo,this.backgroundImage?(i.setBackgroundImage(this.backgroundImage.src,function(){i.renderAll(),t&&t(i)}),i.backgroundImageOpacity=this.backgroundImageOpacity,i.backgroundImageStretch=this.backgroundImageStretch):t&&t(i)}}),function(){var t=fabric.util.degreesToRadians,e=fabric.util.radiansToDegrees;fabric.util.object.extend(fabric.Canvas.prototype,{__onTransformGesture:function(t,e){if(!this.isDrawingMode&&2===t.touches.length&&"gesture"===e.gesture){var i=this.findTarget(t);"undefined"!=typeof i&&(this.onBeforeScaleRotate(i),this._rotateObjectByAngle(e.rotation),this._scaleObjectBy(e.scale)),this.fire("touch:gesture",{target:i,e:t,self:e})}},_scaleObjectBy:function(t,e){var i=this._currentTransform,n=i.target,r=n.get("lockScalingX"),o=n.get("lockScalingY");r&&o||(n._scaling=!0,e?"x"!==e||n.get("lockUniScaling")?"y"!==e||n.get("lockUniScaling")||o||n.set("scaleY",i.scaleY*t):r||n.set("scaleX",i.scaleX*t):(r||n.set("scaleX",i.scaleX*t),o||n.set("scaleY",i.scaleY*t)))},_rotateObjectByAngle:function(i){var n=this._currentTransform;n.target.get("lockRotation")||(n.target.angle=e(t(i)+n.theta))}})}(),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,n=e.util.toFixed,r=e.util.string.capitalize,o=e.util.degreesToRadians;if(!e.Object){var s=t.Image;try{var a="undefined"!=typeof require&&require("canvas").Image;a&&(s=a)}catch(c){e.log(c)}e.Object=e.util.createClass({type:"object",originX:"center",originY:"center",top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,cornerSize:12,transparentCorners:!0,padding:0,borderColor:"rgba(102,153,255,0.75)",cornerColor:"rgba(102,153,255,0.5)",fill:"rgb(0,0,0)",fillRule:"source-over",overlayFill:null,stroke:null,strokeWidth:1,strokeDashArray:null,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,transformMatrix:null,minScaleLimit:.01,selectable:!0,overlay:!1,visible:!0,hasControls:!0,hasBorders:!0,hasRotatingPoint:!0,rotatingPointOffset:40,perPixelTargetFind:!1,includeDefaultValues:!0,clipTo:null,stateProperties:"top left width height scaleX scaleY flipX flipY angle opacity cornerSize fill overlayFill originX originY stroke strokeWidth strokeDashArray fillRule borderScaleFactor transformMatrix selectable shadow visible".split(" "),initialize:function(t){t&&this.setOptions(t)},_initGradient:function(t){!t.fill||!t.fill.colorStops||t.fill instanceof e.Gradient||this.set("fill",new e.Gradient(t.fill))},_initPattern:function(t){!t.fill||!t.fill.source||t.fill instanceof e.Pattern||this.set("fill",new e.Pattern(t.fill)),!t.stroke||!t.stroke.source||t.stroke instanceof e.Pattern||this.set("stroke",new e.Pattern(t.stroke))},_initShadow:function(t){!t.shadow||t.shadow instanceof e.Shadow||this.setShadow(t.shadow)},setOptions:function(t){for(var e in t)this.set(e,t[e]);this._initGradient(t),this._initPattern(t),this._initShadow(t)},transform:function(t){t.globalAlpha=this.opacity;var e=this.getCenterPoint();t.translate(e.x,e.y),t.rotate(o(this.angle)),t.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toObject:function(t){var i=e.Object.NUM_FRACTION_DIGITS,r={type:this.type,originX:this.originX,originY:this.originY,left:n(this.left,i),top:n(this.top,i),width:n(this.width,i),height:n(this.height,i),fill:this.fill&&this.fill.toObject?this.fill.toObject():this.fill,overlayFill:this.overlayFill,stroke:this.stroke&&this.stroke.toObject?this.stroke.toObject():this.stroke,strokeWidth:this.strokeWidth,strokeDashArray:this.strokeDashArray,scaleX:n(this.scaleX,i),scaleY:n(this.scaleY,i),angle:n(this.getAngle(),i),flipX:this.flipX,flipY:this.flipY,opacity:n(this.opacity,i),selectable:this.selectable,hasControls:this.hasControls,hasBorders:this.hasBorders,hasRotatingPoint:this.hasRotatingPoint,transparentCorners:this.transparentCorners,perPixelTargetFind:this.perPixelTargetFind,shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible};return this.includeDefaultValues||(r=this._removeDefaultValues(r)),e.util.populateWithProperties(this,r,t),r},toDatalessObject:function(t){return this.toObject(t)},getSvgStyles:function(){return["stroke: ",this.stroke?this.stroke:"none","; ","stroke-width: ",this.strokeWidth?this.strokeWidth:"0","; ","stroke-dasharray: ",this.strokeDashArray?this.strokeDashArray.join(" "):"; ","fill: ",this.fill?this.fill&&this.fill.toLive?"url(#SVGID_"+this.fill.id+")":this.fill:"none","; ","opacity: ",this.opacity?this.opacity:"1",";",this.visible?"":" visibility: hidden;"].join("")},getSvgTransform:function(){var t=this.getAngle(),i=this.getCenterPoint(),r=e.Object.NUM_FRACTION_DIGITS,o="translate("+n(i.x,r)+" "+n(i.y,r)+")",s=0!==t?" rotate("+n(t,r)+")":"",a=1===this.scaleX&&1===this.scaleY?"":" scale("+n(this.scaleX,r)+" "+n(this.scaleY,r)+")",c=this.flipX?"matrix(-1 0 0 1 0 0) ":"",l=this.flipY?"matrix(1 0 0 -1 0 0)":"";return[o,s,a,c,l].join("")},_removeDefaultValues:function(t){var i=e.Object.prototype.options;return i&&this.stateProperties.forEach(function(e){t[e]===i[e]&&delete t[e]}),t},isActive:function(){return!!this.active},setActive:function(t){return this.active=!!t,this},toString:function(){return"#"},get:function(t){return this[t]},set:function(t,e){if("object"==typeof t)for(var i in t)this._set(i,t[i]);else"function"==typeof e?this._set(t,e(this.get(t))):this._set(t,e);return this},_set:function(t,e){var i="scaleX"===t||"scaleY"===t;return i&&(e=this._constrainScale(e)),"scaleX"===t&&0>e?(this.flipX=!this.flipX,e*=-1):"scaleY"===t&&0>e?(this.flipY=!this.flipY,e*=-1):("width"===t||"height"===t)&&(this.minScaleLimit=n(Math.min(.1,1/Math.max(this.width,this.height)),2)),this[t]=e,this},toggle:function(t){var e=this.get(t);return"boolean"==typeof e&&this.set(t,!e),this},setSourcePath:function(t){return this.sourcePath=t,this},render:function(t,i){if(0!==this.width&&0!==this.height&&this.visible){t.save();var n=this.transformMatrix;n&&!this.group&&t.setTransform(n[0],n[1],n[2],n[3],n[4],n[5]),i||this.transform(t),(this.stroke||this.strokeDashArray)&&(t.lineWidth=this.strokeWidth,this.stroke&&this.stroke.toLive?t.strokeStyle=this.stroke.toLive(t):t.strokeStyle=this.stroke),this.overlayFill?t.fillStyle=this.overlayFill:this.fill&&(t.fillStyle=this.fill.toLive?this.fill.toLive(t):this.fill),n&&this.group&&(t.translate(-this.group.width/2,-this.group.height/2),t.transform(n[0],n[1],n[2],n[3],n[4],n[5])),this._setShadow(t),this.clipTo&&e.util.clipContext(this,t),this._render(t,i),this.clipTo&&t.restore(),this._removeShadow(t),this.active&&!i&&(this.drawBorders(t),this.drawControls(t)),t.restore()}},_setShadow:function(t){this.shadow&&(t.shadowColor=this.shadow.color,t.shadowBlur=this.shadow.blur,t.shadowOffsetX=this.shadow.offsetX,t.shadowOffsetY=this.shadow.offsetY)},_removeShadow:function(t){t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0},clone:function(t,i){return this.constructor.fromObject?this.constructor.fromObject(this.toObject(i),t):new e.Object(this.toObject(i))},cloneAsImage:function(t){if(e.Image){var i=new s;i.onload=function(){t&&t(new e.Image(i),n),i=i.onload=null};var n={angle:this.getAngle(),flipX:this.getFlipX(),flipY:this.getFlipY()};this.set({angle:0,flipX:!1,flipY:!1}),this.toDataURL(function(t){i.src=t})}return this},toDataURL:function(t){function i(e){e.left=n.width/2,e.top=n.height/2,e.setActive(!1),r.add(e);var i=r.toDataURL();r.dispose(),r=e=null,t&&t(i)}var n=e.util.createCanvasElement();n.width=this.getBoundingRectWidth(),n.height=this.getBoundingRectHeight(),e.util.wrapElement(n,"div");var r=new e.Canvas(n);r.backgroundColor="transparent",r.renderAll(),this.constructor.async?this.clone(i):i(this.clone())},hasStateChanged:function(){return this.stateProperties.some(function(t){return this[t]!==this.originalState[t]},this)},saveState:function(t){return this.stateProperties.forEach(function(t){this.originalState[t]=this.get(t)},this),t&&t.stateProperties&&t.stateProperties.forEach(function(t){this.originalState[t]=this.get(t)},this),this},setupState:function(){this.originalState={},this.saveState()},isType:function(t){return this.type===t},toGrayscale:function(){var t=this.get("fill");return t&&this.set("overlayFill",new e.Color(t).toGrayscale().toRgb()),this},complexity:function(){return 0},toJSON:function(t){return this.toObject(t)},setGradient:function(t,i){i||(i={});var n={colorStops:[]};n.type=i.type||(i.r1||i.r2?"radial":"linear"),n.coords={x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2},(i.r1||i.r2)&&(n.coords.r1=i.r1,n.coords.r2=i.r2);for(var r in i.colorStops){var o=new e.Color(i.colorStops[r]);n.colorStops.push({offset:r,color:o.toRgb(),opacity:o.getAlpha()})}this.set(t,e.Gradient.forObject(this,n))},setPatternFill:function(t){this.set("fill",new e.Pattern(t))},setShadow:function(t){this.set("shadow",new e.Shadow(t))},animate:function(){if(arguments[0]&&"object"==typeof arguments[0])for(var t in arguments[0])this._animate(t,arguments[0][t],arguments[1]);else this._animate.apply(this,arguments);return this},_animate:function(t,i,n){var r,o=this;i=i.toString(),n=n?e.util.object.clone(n):{},~t.indexOf(".")&&(r=t.split("."));var s=r?this.get(r[0])[r[1]]:this.get(t);"from"in n||(n.from=s),i=~i.indexOf("=")?s+parseFloat(i.replace("=","")):parseFloat(i),e.util.animate({startValue:n.from,endValue:i,byValue:n.by,easing:n.easing,duration:n.duration,onChange:function(e){r?o[r[0]][r[1]]=e:o.set(t,e),n.onChange&&n.onChange()},onComplete:function(){o.setCoords(),n.onComplete&&n.onComplete()}})},centerH:function(){return this.canvas.centerObjectH(this),this},centerV:function(){return this.canvas.centerObjectV(this),this},center:function(){return this.centerH().centerV()},remove:function(){return this.canvas.remove(this)},sendToBack:function(){return this.canvas.sendToBack(this),this},bringToFront:function(){return this.canvas.bringToFront(this),this},sendBackwards:function(){return this.canvas.sendBackwards(this),this},bringForward:function(){return this.canvas.bringForward(this),this}}),e.util.createAccessors(e.Object),e.Object.prototype.rotate=e.Object.prototype.setAngle,i(e.Object.prototype,e.Observable),e.Object.NUM_FRACTION_DIGITS=2,e.Object.__uid=0}}("undefined"!=typeof exports?exports:this),function(){var t=fabric.util.degreesToRadians;fabric.util.object.extend(fabric.Object.prototype,{translateToCenterPoint:function(e,i,n){var r=e.x,o=e.y;return"left"===i?r=e.x+this.getWidth()/2:"right"===i&&(r=e.x-this.getWidth()/2),"top"===n?o=e.y+this.getHeight()/2:"bottom"===n&&(o=e.y-this.getHeight()/2),fabric.util.rotatePoint(new fabric.Point(r,o),e,t(this.angle))},translateToOriginPoint:function(e,i,n){var r=e.x,o=e.y;return"left"===i?r=e.x-this.getWidth()/2:"right"===i&&(r=e.x+this.getWidth()/2),"top"===n?o=e.y-this.getHeight()/2:"bottom"===n&&(o=e.y+this.getHeight()/2),fabric.util.rotatePoint(new fabric.Point(r,o),e,t(this.angle))},getCenterPoint:function(){return this.translateToCenterPoint(new fabric.Point(this.left,this.top),this.originX,this.originY)},toLocalPoint:function(e,i,n){var r,o,s=this.getCenterPoint();return void 0!==i&&void 0!==n?(r="left"===i?s.x-this.getWidth()/2:"right"===i?s.x+this.getWidth()/2:s.x,o="top"===n?s.y-this.getHeight()/2:"bottom"===n?s.y+this.getHeight()/2:s.y):(r=this.left,o=this.top),fabric.util.rotatePoint(new fabric.Point(e.x,e.y),s,-t(this.angle)).subtractEquals(new fabric.Point(r,o))},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(e){var i=t(this.angle),n=this.getWidth()/2,r=Math.cos(i)*n,o=Math.sin(i)*n,s=this.getWidth(),a=Math.cos(i)*s,c=Math.sin(i)*s;"center"===this.originX&&"left"===e||"right"===this.originX&&"center"===e?(this.left-=r,this.top-=o):"left"===this.originX&&"center"===e||"center"===this.originX&&"right"===e?(this.left+=r,this.top+=o):"left"===this.originX&&"right"===e?(this.left+=a,this.top+=c):"right"===this.originX&&"left"===e&&(this.left-=a,this.top-=c),this.setCoords(),this.originX=e}})}(),function(){var t=fabric.util.degreesToRadians;fabric.util.object.extend(fabric.Object.prototype,{intersectsWithRect:function(t,e){var i=this.oCoords,n=new fabric.Point(i.tl.x,i.tl.y),r=new fabric.Point(i.tr.x,i.tr.y),o=new fabric.Point(i.bl.x,i.bl.y),s=new fabric.Point(i.br.x,i.br.y),a=fabric.Intersection.intersectPolygonRectangle([n,r,s,o],t,e);return"Intersection"===a.status},intersectsWithObject:function(t){function e(t){return{tl:new fabric.Point(t.tl.x,t.tl.y),tr:new fabric.Point(t.tr.x,t.tr.y),bl:new fabric.Point(t.bl.x,t.bl.y),br:new fabric.Point(t.br.x,t.br.y)}}var i=e(this.oCoords),n=e(t.oCoords),r=fabric.Intersection.intersectPolygonPolygon([i.tl,i.tr,i.br,i.bl],[n.tl,n.tr,n.br,n.bl]);return"Intersection"===r.status},isContainedWithinObject:function(t){return this.isContainedWithinRect(t.oCoords.tl,t.oCoords.br)},isContainedWithinRect:function(t,e){var i=this.oCoords,n=new fabric.Point(i.tl.x,i.tl.y),r=new fabric.Point(i.tr.x,i.tr.y),o=new fabric.Point(i.bl.x,i.bl.y);return n.x>t.x&&r.xt.y&&o.yt?-this.minScaleLimit:this.minScaleLimit:t},scale:function(t){return t=this._constrainScale(t),0>t&&(this.flipX=!this.flipX,this.flipY=!this.flipY,t*=-1),this.scaleX=t,this.scaleY=t,this.setCoords(),this},scaleToWidth:function(t){var e=this.getBoundingRectWidth()/this.getWidth();return this.scale(t/this.width/e)},scaleToHeight:function(t){var e=this.getBoundingRectHeight()/this.getHeight();return this.scale(t/this.height/e)},setCoords:function(){var e=this.strokeWidth>1?this.strokeWidth:0,i=this.padding,n=t(this.angle);this.currentWidth=(this.width+e)*this.scaleX+2*i,this.currentHeight=(this.height+e)*this.scaleY+2*i,this.currentWidth<0&&(this.currentWidth=Math.abs(this.currentWidth));var r=Math.sqrt(Math.pow(this.currentWidth/2,2)+Math.pow(this.currentHeight/2,2)),o=Math.atan(this.currentHeight/this.currentWidth),s=Math.cos(o+n)*r,a=Math.sin(o+n)*r,c=Math.sin(n),l=Math.cos(n),u=this.getCenterPoint(),h={x:u.x-s,y:u.y-a},f={x:h.x+this.currentWidth*l,y:h.y+this.currentWidth*c},d={x:f.x-this.currentHeight*c,y:f.y+this.currentHeight*l},p={x:h.x-this.currentHeight*c,y:h.y+this.currentHeight*l},g={x:h.x-this.currentHeight/2*c,y:h.y+this.currentHeight/2*l},v={x:h.x+this.currentWidth/2*l,y:h.y+this.currentWidth/2*c},m={x:f.x-this.currentHeight/2*c,y:f.y+this.currentHeight/2*l},b={x:p.x+this.currentWidth/2*l,y:p.y+this.currentWidth/2*c},y={x:h.x+this.currentWidth/2*l,y:h.y+this.currentWidth/2*c};return this.oCoords={tl:h,tr:f,br:d,bl:p,ml:g,mt:v,mr:m,mb:b,mtr:y},this._setCornerCoords(),this}})}(),function(){var t=fabric.util.getPointer,e=fabric.util.degreesToRadians;fabric.util.object.extend(fabric.Object.prototype,{_findTargetCorner:function(e,i){if(!this.hasControls||!this.active)return!1;var n,r,o=t(e,this.canvas.upperCanvasEl),s=o.x-i.left,a=o.y-i.top;for(var c in this.oCoords)if(("mtr"!==c||this.hasRotatingPoint)&&(!this.get("lockUniScaling")||"mt"!==c&&"mr"!==c&&"mb"!==c&&"ml"!==c)&&(r=this._getImageLines(this.oCoords[c].corner,c),n=this._findCrossPoints(s,a,r),n%2===1&&0!==n))return this.__corner=c,c;return!1},_findCrossPoints:function(t,e,i){var n,r,o,s,a,c,l,u=0;for(var h in i)if(l=i[h],!(l.o.y=e&&l.d.y>=e||(l.o.x===l.d.x&&l.o.x>=t?(a=l.o.x,c=e):(n=0,r=(l.d.y-l.o.y)/(l.d.x-l.o.x),o=e-n*t,s=l.o.y-r*l.o.x,a=-(o-s)/(n-r),c=o+n*a),a>=t&&(u+=1),2!==u)))break;return u},_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}}},_setCornerCoords:function(){var t=this.oCoords,i=e(this.angle),n=e(45-this.angle),r=Math.sqrt(2*Math.pow(this.cornerSize,2))/2,o=r*Math.cos(n),s=r*Math.sin(n),a=Math.sin(i),c=Math.cos(i);t.tl.corner={tl:{x:t.tl.x-s,y:t.tl.y-o},tr:{x:t.tl.x+o,y:t.tl.y-s},bl:{x:t.tl.x-o,y:t.tl.y+s},br:{x:t.tl.x+s,y:t.tl.y+o}},t.tr.corner={tl:{x:t.tr.x-s,y:t.tr.y-o},tr:{x:t.tr.x+o,y:t.tr.y-s},br:{x:t.tr.x+s,y:t.tr.y+o},bl:{x:t.tr.x-o,y:t.tr.y+s}},t.bl.corner={tl:{x:t.bl.x-s,y:t.bl.y-o},bl:{x:t.bl.x-o,y:t.bl.y+s},br:{x:t.bl.x+s,y:t.bl.y+o},tr:{x:t.bl.x+o,y:t.bl.y-s}},t.br.corner={tr:{x:t.br.x+o,y:t.br.y-s},bl:{x:t.br.x-o,y:t.br.y+s},br:{x:t.br.x+s,y:t.br.y+o},tl:{x:t.br.x-s,y:t.br.y-o}},t.ml.corner={tl:{x:t.ml.x-s,y:t.ml.y-o},tr:{x:t.ml.x+o,y:t.ml.y-s},bl:{x:t.ml.x-o,y:t.ml.y+s},br:{x:t.ml.x+s,y:t.ml.y+o}},t.mt.corner={tl:{x:t.mt.x-s,y:t.mt.y-o},tr:{x:t.mt.x+o,y:t.mt.y-s},bl:{x:t.mt.x-o,y:t.mt.y+s},br:{x:t.mt.x+s,y:t.mt.y+o}},t.mr.corner={tl:{x:t.mr.x-s,y:t.mr.y-o},tr:{x:t.mr.x+o,y:t.mr.y-s},bl:{x:t.mr.x-o,y:t.mr.y+s},br:{x:t.mr.x+s,y:t.mr.y+o}},t.mb.corner={tl:{x:t.mb.x-s,y:t.mb.y-o},tr:{x:t.mb.x+o,y:t.mb.y-s},bl:{x:t.mb.x-o,y:t.mb.y+s},br:{x:t.mb.x+s,y:t.mb.y+o}},t.mtr.corner={tl:{x:t.mtr.x-s+a*this.rotatingPointOffset,y:t.mtr.y-o-c*this.rotatingPointOffset},tr:{x:t.mtr.x+o+a*this.rotatingPointOffset,y:t.mtr.y-s-c*this.rotatingPointOffset},bl:{x:t.mtr.x-o+a*this.rotatingPointOffset,y:t.mtr.y+s-c*this.rotatingPointOffset},br:{x:t.mtr.x+s+a*this.rotatingPointOffset,y:t.mtr.y+o-c*this.rotatingPointOffset}}},drawBorders:function(t){if(this.hasBorders){var e=this.padding,i=2*e,n=this.strokeWidth>1?this.strokeWidth:0;t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,t.strokeStyle=this.borderColor;var r=1/this._constrainScale(this.scaleX),o=1/this._constrainScale(this.scaleY);t.lineWidth=1/this.borderScaleFactor,t.scale(r,o);var s=this.getWidth(),a=this.getHeight();if(t.strokeRect(~~(-(s/2)-e-n/2*this.scaleX)+.5,~~(-(a/2)-e-n/2*this.scaleY)+.5,~~(s+i+n*this.scaleX),~~(a+i+n*this.scaleY)),this.hasRotatingPoint&&!this.get("lockRotation")&&this.hasControls){var c=(this.flipY?a+n*this.scaleY+2*e:-a-n*this.scaleY-2*e)/2;t.beginPath(),t.moveTo(0,c),t.lineTo(0,c+(this.flipY?this.rotatingPointOffset:-this.rotatingPointOffset)),t.closePath(),t.stroke()}return t.restore(),this}},drawControls:function(t){if(this.hasControls){var e,i,n=this.cornerSize,r=n/2,o=this.strokeWidth/2,s=-(this.width/2),a=-(this.height/2),c=n/this.scaleX,l=n/this.scaleY,u=this.padding/this.scaleX,h=this.padding/this.scaleY,f=r/this.scaleY,d=r/this.scaleX,p=(r-n)/this.scaleX,g=(r-n)/this.scaleY,v=this.height,m=this.width,b=this.transparentCorners?"strokeRect":"fillRect",y="undefined"!=typeof G_vmlCanvasManager;return t.save(),t.lineWidth=1/Math.max(this.scaleX,this.scaleY),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,t.strokeStyle=t.fillStyle=this.cornerColor,e=s-d-o-u,i=a-f-o-h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s+m-d+o+u,i=a-f-o-h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s-d-o-u,i=a+v+g+o+h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s+m+p+o+u,i=a+v+g+o+h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),this.get("lockUniScaling")||(e=s+m/2-d,i=a-f-o-h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s+m/2-d,i=a+v+g+o+h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s+m+p+o+u,i=a+v/2-f,y||t.clearRect(e,i,c,l),t[b](e,i,c,l),e=s-d-o-u,i=a+v/2-f,y||t.clearRect(e,i,c,l),t[b](e,i,c,l)),this.hasRotatingPoint&&(e=s+m/2-d,i=this.flipY?a+v+this.rotatingPointOffset/this.scaleY-l/2+o+h:a-this.rotatingPointOffset/this.scaleY-l/2-o-h,y||t.clearRect(e,i,c,l),t[b](e,i,c,l)),t.restore(),this}}})}(),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,n={x1:1,x2:1,y1:1,y2:1};return e.Line?void e.warn("fabric.Line is already defined"):(e.Line=e.util.createClass(e.Object,{type:"line",initialize:function(t,e){e=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.set("width",this.x2-this.x1||1),this.set("height",this.y2-this.y1||1),this.set("left","left"in t?t.left:this.x1+this.width/2),this.set("top","top"in t?t.top:this.y1+this.height/2)},_set:function(t,e){return this[t]=e,t in n&&this._setWidthHeight(),this},_render:function(t){t.beginPath(),this.group&&t.translate(-this.group.width/2+this.left,-this.group.height/2+this.top),t.moveTo(1===this.width?0:-this.width/2,1===this.height?0:-this.height/2),t.lineTo(1===this.width?0:this.width/2,1===this.height?0:this.height/2),t.lineWidth=this.strokeWidth;var e=t.strokeStyle;t.strokeStyle=t.fillStyle,t.stroke(),t.strokeStyle=e},complexity:function(){return 1},toObject:function(t){return i(this.callSuper("toObject",t),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})},toSVG:function(){var t=[];return this.stroke&&this.stroke.toLive&&t.push(this.stroke.toSVG(this,!0)),t.push("'),t.join("")}}),e.Line.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" "),e.Line.fromElement=function(t,n){var r=e.parseAttributes(t,e.Line.ATTRIBUTE_NAMES),o=[r.x1||0,r.y1||0,r.x2||0,r.y2||0];return new e.Line(o,i(r,n))},void(e.Line.fromObject=function(t){var i=[t.x1,t.y1,t.x2,t.y2];return new e.Line(i,t)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";function e(t){return"radius"in t&&t.radius>0}var i=t.fabric||(t.fabric={}),n=2*Math.PI,r=i.util.object.extend;return i.Circle?void i.warn("fabric.Circle is already defined."):(i.Circle=i.util.createClass(i.Object,{type:"circle",initialize:function(t){t=t||{},this.set("radius",t.radius||0),this.callSuper("initialize",t);var e=2*this.get("radius");this.set("width",e).set("height",e)},toObject:function(t){return r(this.callSuper("toObject",t),{radius:this.get("radius")})},toSVG:function(){var t=[];return this.fill&&this.fill.toLive&&t.push(this.fill.toSVG(this,!1)),this.stroke&&this.stroke.toLive&&t.push(this.stroke.toSVG(this,!1)),t.push("'),t.join("")},_render:function(t,e){t.beginPath(),t.globalAlpha=this.group?t.globalAlpha*this.opacity:this.opacity,t.arc(e?this.left:0,e?this.top:0,this.radius,0,n,!1),t.closePath(),this.fill&&t.fill(),this._removeShadow(t),this.stroke&&t.stroke()},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(t){this.radius=t,this.set("width",2*t).set("height",2*t)},complexity:function(){return 1}}),i.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity opacity stroke stroke-width transform".split(" "),i.Circle.fromElement=function(t,n){n||(n={});var o=i.parseAttributes(t,i.Circle.ATTRIBUTE_NAMES);if(!e(o))throw new Error("value of `r` attribute is required and can not be negative");"left"in o&&(o.left-=n.width/2||0),"top"in o&&(o.top-=n.height/2||0);var s=new i.Circle(r(o,n));return s.cx=parseFloat(t.getAttribute("cx"))||0,s.cy=parseFloat(t.getAttribute("cy"))||0,s},void(i.Circle.fromObject=function(t){return new i.Circle(t)}))}("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",initialize:function(t){t=t||{},this.callSuper("initialize",t),this.set("width",t.width||100).set("height",t.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.fill&&t.fill(),this.stroke&&t.stroke()},complexity:function(){return 1},toSVG:function(){var t=[],e=this.width/2,i=this.height/2,n=[-e+" "+i,"0 "+-i,e+" "+i].join(",");return this.fill&&this.fill.toLive&&t.push(this.fill.toSVG(this,!0)),this.stroke&&this.stroke.toLive&&t.push(this.stroke.toSVG(this,!0)),t.push("'),t.join("")}}),void(e.Triangle.fromObject=function(t){return new e.Triangle(t)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=2*Math.PI,n=e.util.object.extend;return e.Ellipse?void e.warn("fabric.Ellipse is already defined."):(e.Ellipse=e.util.createClass(e.Object,{type:"ellipse",rx:0,ry:0,initialize:function(t){t=t||{},this.callSuper("initialize",t),this.set("rx",t.rx||0),this.set("ry",t.ry||0),this.set("width",2*this.get("rx")),this.set("height",2*this.get("ry"))},toObject:function(t){return n(this.callSuper("toObject",t),{rx:this.get("rx"),ry:this.get("ry")})},toSVG:function(){var t=[];return this.fill&&this.fill.toLive&&t.push(this.fill.toSVG(this,!1)),this.stroke&&this.stroke.toLive&&t.push(this.stroke.toSVG(this,!1)),t.push("'),t.join("")},render:function(t,e){return 0!==this.rx&&0!==this.ry?this.callSuper("render",t,e):void 0},_render:function(t,e){t.beginPath(),t.save(),t.globalAlpha=this.group?t.globalAlpha*this.opacity:this.opacity,this.transformMatrix&&this.group&&t.translate(this.cx,this.cy),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(e?this.left:0,e?this.top:0,this.rx,0,i,!1),this.stroke&&t.stroke(),this._removeShadow(t),this.fill&&t.fill(),t.restore()},complexity:function(){return 1}}),e.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity opacity stroke stroke-width transform".split(" "),e.Ellipse.fromElement=function(t,i){i||(i={});var r=e.parseAttributes(t,e.Ellipse.ATTRIBUTE_NAMES),o=r.left,s=r.top;"left"in r&&(r.left-=i.width/2||0),"top"in r&&(r.top-=i.height/2||0);var a=new e.Ellipse(n(r,i));return a.cx=o||0,a.cy=s||0,a},void(e.Ellipse.fromObject=function(t){return new e.Ellipse(t)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";function e(t){return t.left=t.left||0,t.top=t.top||0,t}var i=t.fabric||(t.fabric={}),n=i.util.object.extend;return i.Rect?void console.warn("fabric.Rect is already defined"):(i.Rect=i.util.createClass(i.Object,{type:"rect",rx:0,ry:0,initialize:function(t){t=t||{},this._initStateProperties(),this.callSuper("initialize",t),this._initRxRy(),this.x=0,this.y=0},_initStateProperties:function(){this.stateProperties=this.stateProperties.concat(["rx","ry"])},_initRxRy:function(){this.rx&&!this.ry?this.ry=this.rx:this.ry&&!this.rx&&(this.rx=this.ry)},_render:function(t){var e=this.rx||0,i=this.ry||0,n=-this.width/2,r=-this.height/2,o=this.width,s=this.height;t.beginPath(),t.globalAlpha=this.group?t.globalAlpha*this.opacity:this.opacity,this.transformMatrix&&this.group&&t.translate(this.width/2+this.x,this.height/2+this.y),!this.transformMatrix&&this.group&&t.translate(-this.group.width/2+this.width/2+this.x,-this.group.height/2+this.height/2+this.y),t.moveTo(n+e,r),t.lineTo(n+o-e,r),t.quadraticCurveTo(n+o,r,n+o,r+i,n+o,r+i),t.lineTo(n+o,r+s-i),t.quadraticCurveTo(n+o,r+s,n+o-e,r+s,n+o-e,r+s),t.lineTo(n+e,r+s),t.quadraticCurveTo(n,r+s,n,r+s-i,n,r+s-i),t.lineTo(n,r+i),t.quadraticCurveTo(n,r,n+e,r,n+e,r),t.closePath(),this.fill&&t.fill(),this._removeShadow(t),this.strokeDashArray?this._renderDashedStroke(t):this.stroke&&t.stroke()},_renderDashedStroke:function(t){function e(e,c){for(var l=0,u=0,h=(c?o.height:o.width)+2*s;h>l;){var f=o.strokeDashArray[i++];l+=f,l>h&&(u=l-h),e?n+=f*e-(u*e||0):r+=f*c-(u*c||0),t[1&i?"moveTo":"lineTo"](n,r),i>=a&&(i=0)}}1&this.strokeDashArray.length&&this.strokeDashArray.push.apply(this.strokeDashArray,this.strokeDashArray);var i=0,n=-this.width/2,r=-this.height/2,o=this,s=this.padding,a=this.strokeDashArray.length;t.save(),t.beginPath(),e(1,0),e(0,1),e(-1,0),e(0,-1),t.stroke(),t.closePath(),t.restore()},_normalizeLeftTopProperties:function(t){return t.left&&this.set("left",t.left+this.getWidth()/2),this.set("x",t.left||0),t.top&&this.set("top",t.top+this.getHeight()/2),this.set("y",t.top||0),this},complexity:function(){return 1},toObject:function(t){return n(this.callSuper("toObject",t),{rx:this.get("rx")||0,ry:this.get("ry")||0})},toSVG:function(){var t=[];return this.fill&&this.fill.toLive&&t.push(this.fill.toSVG(this,!1)),this.stroke&&this.stroke.toLive&&t.push(this.stroke.toSVG(this,!1)),t.push("'),t.join("")}}),i.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity opacity stroke stroke-width transform".split(" "),i.Rect.fromElement=function(t,r){if(!t)return null;var o=i.parseAttributes(t,i.Rect.ATTRIBUTE_NAMES);o=e(o);var s=new i.Rect(n(r?i.util.object.clone(r):{},o));return s._normalizeLeftTopProperties(o),s},void(i.Rect.fromObject=function(t){return new i.Rect(t)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.toFixed;return e.Polyline?void e.warn("fabric.Polyline is already defined"):(e.Polyline=e.util.createClass(e.Object,{type:"polyline",initialize:function(t,e,i){e=e||{},this.set("points",t),this.callSuper("initialize",e),this._calcDimensions(i)},_calcDimensions:function(t){return e.Polygon.prototype._calcDimensions.call(this,t)},toObject:function(t){return e.Polygon.prototype.toObject.call(this,t)},toSVG:function(){for(var t=[],e=[],n=0,r=this.points.length;r>n;n++)t.push(i(this.points[n].x,2),",",i(this.points[n].y,2)," ");return this.fill&&this.fill.toLive&&e.push(this.fill.toSVG(this,!1)),this.stroke&&this.stroke.toLive&&e.push(this.stroke.toSVG(this,!1)),e.push("'),e.join("")},_render:function(t){var e;t.beginPath(),t.moveTo(this.points[0].x,this.points[0].y);for(var i=0,n=this.points.length;n>i;i++)e=this.points[i],t.lineTo(e.x,e.y);this.fill&&t.fill(),this._removeShadow(t),this.stroke&&t.stroke()},complexity:function(){return this.get("points").length}}),e.Polyline.ATTRIBUTE_NAMES="fill fill-opacity opacity stroke stroke-width transform".split(" "),e.Polyline.fromElement=function(t,i){if(!t)return null;i||(i={});for(var n=e.parsePointsAttribute(t.getAttribute("points")),r=e.parseAttributes(t,e.Polyline.ATTRIBUTE_NAMES),o=0,s=n.length;s>o;o++)n[o].x-=i.width/2||0,n[o].y-=i.height/2||0;return new e.Polyline(n,e.util.object.extend(r,i),!0)},void(e.Polyline.fromObject=function(t){var i=t.points;return new e.Polyline(i,t,!0)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,n=e.util.array.min,r=e.util.array.max,o=e.util.toFixed;return e.Polygon?void e.warn("fabric.Polygon is already defined"):(e.Polygon=e.util.createClass(e.Object,{type:"polygon",initialize:function(t,e,i){e=e||{},this.points=t,this.callSuper("initialize",e),this._calcDimensions(i)},_calcDimensions:function(t){var e=this.points,i=n(e,"x"),o=n(e,"y"),s=r(e,"x"),a=r(e,"y");if(this.width=s-i||1, this.height=a-o||1,this.minX=i,this.minY=o,!t){var c=this.width/2,l=this.height/2;this.points.forEach(function(t){t.x-=c,t.y-=l},this)}},toObject:function(t){return i(this.callSuper("toObject",t),{points:this.points.concat()})},toSVG:function(){for(var t=[],e=[],i=0,n=this.points.length;n>i;i++)t.push(o(this.points[i].x,2),",",o(this.points[i].y,2)," ");return this.fill&&this.fill.toLive&&e.push(this.fill.toSVG(this,!1)),this.stroke&&this.stroke.toLive&&e.push(this.stroke.toSVG(this,!1)),e.push("'),e.join("")},_render:function(t){var e;t.beginPath(),t.moveTo(this.points[0].x,this.points[0].y);for(var i=0,n=this.points.length;n>i;i++)e=this.points[i],t.lineTo(e.x,e.y);this.fill&&t.fill(),this._removeShadow(t),this.stroke&&(t.closePath(),t.stroke())},complexity:function(){return this.points.length}}),e.Polygon.ATTRIBUTE_NAMES="fill fill-opacity opacity stroke stroke-width transform".split(" "),e.Polygon.fromElement=function(t,n){if(!t)return null;n||(n={});for(var r=e.parsePointsAttribute(t.getAttribute("points")),o=e.parseAttributes(t,e.Polygon.ATTRIBUTE_NAMES),s=0,a=r.length;a>s;s++)r[s].x-=n.width/2||0,r[s].y-=n.height/2||0;return new e.Polygon(r,i(o,n),!0)},void(e.Polygon.fromObject=function(t){return new e.Polygon(t.points,t,!0)}))}("undefined"!=typeof exports?exports:this),function(t){function e(t,e,r,o){for(var s=o[0],a=o[1],c=o[2],l=o[3],u=o[4],h=o[5],f=o[6],d=i(h,f,s,a,l,u,c,e,r),p=0;p1&&(m=Math.sqrt(m),i*=m,n*=m);var b=p/i,y=d/i,x=-d/n,w=p/n,k=b*l+y*h,C=x*l+w*h,_=b*t+y*e,S=x*t+w*e,E=(_-k)*(_-k)+(S-C)*(S-C),T=1/E-.25;0>T&&(T=0);var O=Math.sqrt(T);o===r&&(O=-O);var j=.5*(k+_)-O*(S-C),P=.5*(C+S)+O*(_-k),A=Math.atan2(C-P,k-j),I=Math.atan2(S-P,_-j),M=I-A;0>M&&1===o?M+=2*Math.PI:M>0&&0===o&&(M-=2*Math.PI);for(var D=Math.ceil(Math.abs(M/(.5*Math.PI+.001))),F=[],G=0;D>G;G++){var L=A+G*M/D,R=A+(G+1)*M/D;F[G]=[j,P,L,R,i,n,d,p]}return c[s]=F}function n(t,e,i,n,r,o,a,c){if(s=u.call(arguments),l[s])return l[s];var h=c*r,f=-a*o,d=a*r,p=c*o,g=.5*(n-i),v=8/3*Math.sin(.5*g)*Math.sin(.5*g)/Math.sin(g),m=t+Math.cos(i)-v*Math.sin(i),b=e+Math.sin(i)+v*Math.cos(i),y=t+Math.cos(n),x=e+Math.sin(n),w=y+v*Math.sin(n),k=x-v*Math.cos(n);return l[s]=[h*m+f*b,d*m+p*b,h*w+f*k,d*w+p*k,h*y+f*x,d*y+p*x]}function r(t){return"H"===t[0]?t[1]:t[t.length-2]}function o(t){return"V"===t[0]?t[1]:t[t.length-1]}var s,a={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},c={},l={},u=Array.prototype.join,h=t.fabric||(t.fabric={}),f=h.util.array.min,d=h.util.array.max,p=h.util.object.extend,g=Object.prototype.toString;return h.Path?void h.warn("fabric.Path is already defined"):(h.Path=h.util.createClass(h.Object,{type:"path",initialize:function(t,e){if(e=e||{},this.setOptions(e),!t)throw new Error("`path` argument is required");var i="[object Array]"===g.call(t);this.path=i?t:t.match&&t.match(/[mzlhvcsqta][^mzlhvcsqta]*/gi),this.path&&(i||(this.path=this._parsePath()),this._initializePath(e),e.sourcePath&&this.setSourcePath(e.sourcePath))},_initializePath:function(t){var e="width"in t,i="height"in t,n="left"in t,r="top"in t;e&&i?(r||(this.top=this.height/2),n||(this.left=this.width/2)):(p(this,this._parseDimensions()),e&&(this.width=t.width),i&&(this.height=t.height)),this.pathOffset=this._calculatePathOffset(r||n)},_calculatePathOffset:function(t){return{x:t?0:this.left-this.width/2,y:t?0:this.top-this.height/2}},_render:function(t){for(var i,n,r,o,s,a=null,c=0,l=0,u=0,h=0,f=-(this.width/2+this.pathOffset.x),d=-(this.height/2+this.pathOffset.y),p=0,g=this.path.length;g>p;++p){switch(i=this.path[p],i[0]){case"l":c+=i[1],l+=i[2],t.lineTo(c+f,l+d);break;case"L":c=i[1],l=i[2],t.lineTo(c+f,l+d);break;case"h":c+=i[1],t.lineTo(c+f,l+d);break;case"H":c=i[1],t.lineTo(c+f,l+d);break;case"v":l+=i[1],t.lineTo(c+f,l+d);break;case"V":l=i[1],t.lineTo(c+f,l+d);break;case"m":c+=i[1],l+=i[2],t[!a||"m"!==a[0]&&"M"!==a[0]?"moveTo":"lineTo"](c+f,l+d);break;case"M":c=i[1],l=i[2],t[!a||"m"!==a[0]&&"M"!==a[0]?"moveTo":"lineTo"](c+f,l+d);break;case"c":n=c+i[5],r=l+i[6],u=c+i[3],h=l+i[4],t.bezierCurveTo(c+i[1]+f,l+i[2]+d,u+f,h+d,n+f,r+d),c=n,l=r;break;case"C":c=i[5],l=i[6],u=i[3],h=i[4],t.bezierCurveTo(i[1]+f,i[2]+d,u+f,h+d,c+f,l+d);break;case"s":n=c+i[3],r=l+i[4],u=u?2*c-u:c,h=h?2*l-h:l,t.bezierCurveTo(u+f,h+d,c+i[1]+f,l+i[2]+d,n+f,r+d),u=c+i[1],h=l+i[2],c=n,l=r;break;case"S":n=i[3],r=i[4],u=2*c-u,h=2*l-h,t.bezierCurveTo(u+f,h+d,i[1]+f,i[2]+d,n+f,r+d),c=n,l=r,u=i[1],h=i[2];break;case"q":n=c+i[3],r=l+i[4],u=c+i[1],h=l+i[2],t.quadraticCurveTo(u+f,h+d,n+f,r+d),c=n,l=r;break;case"Q":n=i[3],r=i[4],t.quadraticCurveTo(i[1]+f,i[2]+d,n+f,r+d),c=n,l=r,u=i[1],h=i[2];break;case"t":n=c+i[1],r=l+i[2],null===a[0].match(/[QqTt]/)?(u=c,h=l):"t"===a[0]?(u=2*c-o,h=2*l-s):"q"===a[0]&&(u=2*c-u,h=2*l-h),o=u,s=h,t.quadraticCurveTo(u+f,h+d,n+f,r+d),c=n,l=r,u=c+i[1],h=l+i[2];break;case"T":n=i[1],r=i[2],u=2*c-u,h=2*l-h,t.quadraticCurveTo(u+f,h+d,n+f,r+d),c=n,l=r;break;case"a":e(t,c+f,l+d,[i[1],i[2],i[3],i[4],i[5],i[6]+c+f,i[7]+l+d]),c+=i[6],l+=i[7];break;case"A":e(t,c+f,l+d,[i[1],i[2],i[3],i[4],i[5],i[6]+f,i[7]+d]),c=i[6],l=i[7];break;case"z":case"Z":t.closePath()}a=i}},render:function(t,e){t.save();var i=this.transformMatrix;i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),e||this.transform(t),this.overlayFill?t.fillStyle=this.overlayFill:this.fill&&(t.fillStyle=this.fill.toLive?this.fill.toLive(t):this.fill),this.stroke&&(t.strokeStyle=this.stroke.toLive?this.stroke.toLive(t):this.stroke),this._setShadow(t),this.clipTo&&h.util.clipContext(this,t),t.beginPath(),this._render(t),this.fill&&t.fill(),this.clipTo&&t.restore(),this._removeShadow(t),this.stroke&&(t.strokeStyle=this.stroke,t.lineWidth=this.strokeWidth,t.lineCap=t.lineJoin="round",t.stroke()),!e&&this.active&&(this.drawBorders(t),this.drawControls(t)),t.restore()},toString:function(){return"#"},toObject:function(t){var e=p(this.callSuper("toObject",t),{path:this.path});return this.sourcePath&&(e.sourcePath=this.sourcePath),this.transformMatrix&&(e.transformMatrix=this.transformMatrix),e},toDatalessObject:function(t){var e=this.toObject(t);return this.sourcePath&&(e.path=this.sourcePath),delete e.sourcePath,e},toSVG:function(){for(var t=[],e=[],i=0,n=this.path.length;n>i;i++)t.push(this.path[i].join(" "));var r=t.join(" ");return this.fill&&this.fill.toLive&&e.push(this.fill.toSVG(this,!0)),this.stroke&&this.stroke.toLive&&e.push(this.stroke.toSVG(this,!0)),e.push('',"",""),e.join("")},complexity:function(){return this.path.length},_parsePath:function(){for(var t,e,i,n,r=[],o=0,s=this.path.length;s>o;o++){t=this.path[o],e=t.slice(1).trim().replace(/(\d)-/g,"$1###-").split(/\s|,|###/),n=[t.charAt(0)];for(var c=0,l=e.length;l>c;c++)i=parseFloat(e[c]),isNaN(i)||n.push(i);var u=n[0].toLowerCase(),h=a[u];if(n.length-1>h)for(var f=1,d=n.length;d>f;f+=h)r.push([n[0]].concat(n.slice(f,f+h)));else r.push(n)}return r},_parseDimensions:function(){var t,e,i,n,s=[],a=[],c=!1;this.path.forEach(function(l,u){"H"!==l[0]&&(t=r(0===u?l:this.path[u-1])),"V"!==l[0]&&(e=o(0===u?l:this.path[u-1])),l[0]===l[0].toLowerCase()&&(c=!0),i=c?t+r(l):"V"===l[0]?t:r(l),n=c?e+o(l):"H"===l[0]?e:o(l);var h=parseInt(i,10);isNaN(h)||s.push(h),h=parseInt(n,10),isNaN(h)||a.push(h)},this);var l=f(s),u=f(a),h=d(s),p=d(a),g=h-l,v=p-u,m={top:u+v/2,left:l+g/2,bottom:d(a)-v,right:d(s)-g};return m.width=g,m.height=v,m}}),h.Path.fromObject=function(t){return new h.Path(t.path,t)},h.Path.ATTRIBUTE_NAMES="d fill fill-opacity opacity fill-rule stroke stroke-width transform".split(" "),void(h.Path.fromElement=function(t,e){var i=h.parseAttributes(t,h.Path.ATTRIBUTE_NAMES);return new h.Path(i.d,p(i,e))}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";function e(t){for(var e=0,n=t.length;n>e;e++)if(!(t[e]instanceof i.Object)){var r=s(a(t[e].type));t[e]=i[r].fromObject(t[e])}return t}var i=t.fabric||(t.fabric={}),n=i.util.object.extend,r=i.util.array.invoke,o=i.Object.prototype.toObject,s=i.util.string.camelize,a=i.util.string.capitalize;return i.PathGroup?void i.warn("fabric.PathGroup is already defined"):(i.PathGroup=i.util.createClass(i.Path,{type:"path-group",fill:"",initialize:function(t,e){e=e||{},this.paths=t||[];for(var i=this.paths.length;i--;)this.paths[i].group=this;this.setOptions(e),this.setCoords(),e.sourcePath&&this.setSourcePath(e.sourcePath)},render:function(t){if(this.visible){t.save();var e=this.transformMatrix;e&&t.transform(e[0],e[1],e[2],e[3],e[4],e[5]),this.transform(t),this._setShadow(t),this.clipTo&&i.util.clipContext(this,t);for(var n=0,r=this.paths.length;r>n;++n)this.paths[n].render(t,!0);this.clipTo&&t.restore(),this._removeShadow(t),this.active&&(this.drawBorders(t),this.drawControls(t)),t.restore()}},_set:function(t,e){if(("fill"===t||"overlayFill"===t)&&e&&this.isSameColor())for(var i=this.paths.length;i--;)this.paths[i]._set(t,e);return this.callSuper("_set",t,e)},toObject:function(t){return n(o.call(this,t),{paths:r(this.getObjects(),"toObject",t),sourcePath:this.sourcePath})},toDatalessObject:function(t){var e=this.toObject(t);return this.sourcePath&&(e.paths=this.sourcePath),e},toSVG:function(){for(var t=this.getObjects(),e=[""],i=0,n=t.length;n>i;i++)e.push(t[i].toSVG());return e.push(""),e.join("")},toString:function(){return"#"},isSameColor:function(){var t=this.getObjects()[0].get("fill");return this.getObjects().every(function(e){return e.get("fill")===t})},complexity:function(){return this.paths.reduce(function(t,e){return t+(e&&e.complexity?e.complexity():0)},0)},toGrayscale:function(){for(var t=this.paths.length;t--;)this.paths[t].toGrayscale();return this},getObjects:function(){return this.paths}}),void(i.PathGroup.fromObject=function(t){var n=e(t.paths);return new i.PathGroup(n,t)}))}("undefined"!=typeof exports?exports:this),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,n=e.util.array.min,r=e.util.array.max,o=e.util.array.invoke,s=e.util.removeFromArray;if(!e.Group){var a={lockMovementX:!0,lockMovementY:!0,lockRotation:!0,lockScalingX:!0,lockScalingY:!0,lockUniScaling:!0};e.Group=e.util.createClass(e.Object,{type:"group",initialize:function(t,e){e=e||{},this.objects=t||[],this.originalState={},this.callSuper("initialize"),this._calcBounds(),this._updateObjectsCoords(),e&&i(this,e),this._setOpacityIfSame(),this.setCoords(!0),this.saveCoords()},_updateObjectsCoords:function(){var t=this.left,e=this.top;this.forEachObject(function(i){var n=i.get("left"),r=i.get("top");i.set("originalLeft",n),i.set("originalTop",r),i.set("left",n-t),i.set("top",r-e),i.setCoords(),i.__origHasControls=i.hasControls,i.hasControls=!1},this)},toString:function(){return"#"},getObjects:function(){return this.objects},addWithUpdate:function(t){return this._restoreObjectsState(),this.objects.push(t),this._calcBounds(),this._updateObjectsCoords(),this},removeWithUpdate:function(t){return this._restoreObjectsState(),s(this.objects,t),t.setActive(!1),this._calcBounds(),this._updateObjectsCoords(),this},add:function(t){return this.objects.push(t),this},remove:function(t){return s(this.objects,t),this},size:function(){return this.getObjects().length},delegatedProperties:{fill:!0,opacity:!0,fontFamily:!0,fontWeight:!0,fontSize:!0,fontStyle:!0,lineHeight:!0,textDecoration:!0,textShadow:!0,textAlign:!0,backgroundColor:!0},_set:function(t,e){if(t in this.delegatedProperties){var i=this.objects.length;for(this[t]=e;i--;)this.objects[i].set(t,e)}else this[t]=e},contains:function(t){return this.objects.indexOf(t)>-1},toObject:function(t){return i(this.callSuper("toObject",t),{objects:o(this.objects,"toObject",t)})},render:function(t,i){t.save(),this.transform(t);var n=Math.max(this.scaleX,this.scaleY);this.clipTo&&e.util.clipContext(this,t);for(var r=this.objects.length;r>0;r--){var o=this.objects[r-1],s=o.borderScaleFactor,a=o.hasRotatingPoint;o.borderScaleFactor=n,o.hasRotatingPoint=!1,o.render(t),o.borderScaleFactor=s,o.hasRotatingPoint=a}this.clipTo&&t.restore(),!i&&this.active&&(this.drawBorders(t),this.drawControls(t)),t.restore(),this.setCoords()},item:function(t){return this.getObjects()[t]},complexity:function(){return this.getObjects().reduce(function(t,e){return t+="function"==typeof e.complexity?e.complexity():0},0)},_restoreObjectsState:function(){return this.objects.forEach(this._restoreObjectState,this),this},_restoreObjectState:function(t){var e=this.get("left"),i=this.get("top"),n=this.getAngle()*(Math.PI/180),r=Math.cos(n)*t.get("top")+Math.sin(n)*t.get("left"),o=-Math.sin(n)*t.get("top")+Math.cos(n)*t.get("left");return t.setAngle(t.getAngle()+this.getAngle()),t.set("left",e+o*this.get("scaleX")),t.set("top",i+r*this.get("scaleY")),t.set("scaleX",t.get("scaleX")*this.get("scaleX")),t.set("scaleY",t.get("scaleY")*this.get("scaleY")),t.setCoords(),t.hasControls=t.__origHasControls,delete t.__origHasControls,t.setActive(!1),t.setCoords(),this},destroy:function(){return this._restoreObjectsState()},saveCoords:function(){return this._originalLeft=this.get("left"),this._originalTop=this.get("top"),this},hasMoved:function(){return this._originalLeft!==this.get("left")||this._originalTop!==this.get("top")},setObjectsCoords:function(){return this.forEachObject(function(t){t.setCoords()}),this},activateAllObjects:function(){return this.forEachObject(function(t){t.setActive()}),this},forEachObject:e.StaticCanvas.prototype.forEachObject,_setOpacityIfSame:function(){var t=this.getObjects(),e=t[0]?t[0].get("opacity"):1,i=t.every(function(t){return t.get("opacity")===e});i&&(this.opacity=e)},_calcBounds:function(){for(var t,e,i,o,s,a,c,l=[],u=[],h=0,f=this.objects.length;f>h;++h){s=this.objects[h],s.setCoords();for(var d in s.oCoords)l.push(s.oCoords[d].x),u.push(s.oCoords[d].y)}t=n(l),i=r(l),e=n(u),o=r(u),a=i-t||0,c=o-e||0,this.width=a,this.height=c,this.left=t+a/2||0,this.top=e+c/2||0},containsPoint:function(t){var e=this.get("width")/2,i=this.get("height")/2,n=this.get("left"),r=this.get("top");return n-et.x&&r-it.y},toGrayscale:function(){for(var t=this.objects.length;t--;)this.objects[t].toGrayscale();return this},toSVG:function(){for(var t=[],e=this.objects.length;e--;)t.push(this.objects[e].toSVG());return''+t.join("")+""},get:function(t){if(t in a){if(this[t])return this[t];for(var e=0,i=this.objects.length;i>e;e++)if(this.objects[e][t])return!0;return!1}return t in this.delegatedProperties?this.objects[0]&&this.objects[0].get(t):this[t]}}),e.Group.fromObject=function(t,i){e.util.enlivenObjects(t.objects,function(n){delete t.objects,i&&i(new e.Group(n,t))})},e.Group.async=!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",initialize:function(t,e){e||(e={}),this.callSuper("initialize",e),this._initElement(t),this._originalImage=this.getElement(),this._initConfig(e),this.filters=[],e.filters&&(this.filters=e.filters,this.applyFilters())},getElement:function(){return this._element},setElement:function(t){return this._element=t,this._initConfig(),this},getOriginalSize:function(){var t=this.getElement();return{width:t.width,height:t.height}},render:function(t,e){t.save();var i=this.transformMatrix;this.group&&t.translate(-this.group.width/2+this.width/2,-this.group.height/2+this.height/2),i&&t.transform(i[0],i[1],i[2],i[3],i[4],i[5]),e||this.transform(t),this._setShadow(t),this.clipTo&&fabric.util.clipContext(this,t),this._render(t),this.clipTo&&t.restore(),this._removeShadow(t),this.active&&!e&&(this.drawBorders(t),this.drawControls(t)),t.restore()},toObject:function(t){return e(this.callSuper("toObject",t),{src:this._originalImage.src||this._originalImage._src,filters:this.filters.concat()})},toSVG:function(){return''},getSrc:function(){return this.getElement().src||this.getElement()._src},toString:function(){return'#'},clone:function(t,e){this.constructor.fromObject(this.toObject(e),t)},applyFilters:function(t){if(0===this.filters.length)return this.setElement(this._originalImage),void(t&&t());var e="undefined"!=typeof Buffer&&"undefined"==typeof window,i=this._originalImage,n=fabric.util.createCanvasElement(),r=e?new(require("canvas").Image):fabric.document.createElement("img"),o=this;if(n.width=i.width,n.height=i.height,n.getContext("2d").drawImage(i,0,0,i.width,i.height),this.filters.forEach(function(t){t&&t.applyTo(n)}),r.onload=function(){o._element=r,t&&t(),r.onload=n=i=null},r.width=i.width,r.height=i.height,e){var s=n.toDataURL("image/png").substring(22);r.src=new Buffer(s,"base64"),o._element=r,t&&t()}else r.src=n.toDataURL("image/png");return this},_render:function(t){t.drawImage(this._element,-this.width/2,-this.height/2,this.width,this.height)},_resetWidthHeight:function(){var t=this.getElement();this.set("width",t.width),this.set("height",t.height)},_initElement:function(t){this.setElement(fabric.util.getById(t)),fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(t){t||(t={}),this.setOptions(t),this._setWidthHeight(t)},_initFilters:function(t){t.filters&&t.filters.length&&(this.filters=t.filters.map(function(t){return t&&fabric.Image.filters[t.type].fromObject(t)}))},_setWidthHeight:function(t){this.width="width"in t?t.width:this.getElement().width||0,this.height="height"in t?t.height:this.getElement().height||0},complexity:function(){return 1}}),fabric.Image.CSS_CANVAS="canvas-img",fabric.Image.prototype.getSvgSrc=fabric.Image.prototype.getSrc,fabric.Image.fromObject=function(t,e){var i=fabric.document.createElement("img"),n=t.src;t.width&&(i.width=t.width),t.height&&(i.height=t.height),i.onload=function(){fabric.Image.prototype._initFilters.call(t,t);var n=new fabric.Image(i,t);e&&e(n),i=i.onload=i.onerror=null},i.onerror=function(){fabric.log("Error loading "+i.src),e&&e(null,!0),i=i.onload=i.onerror=null},i.src=n},fabric.Image.fromURL=function(t,e,i){var n=fabric.document.createElement("img");n.onload=function(){e&&e(new fabric.Image(n,i)),n=n.onload=null},n.src=t},fabric.Image.ATTRIBUTE_NAMES="x y width height fill fill-opacity opacity stroke stroke-width transform xlink:href".split(" "),fabric.Image.fromElement=function(t,i,n){var r=fabric.parseAttributes(t,fabric.Image.ATTRIBUTE_NAMES);fabric.Image.fromURL(r["xlink:href"],i,e(n?fabric.util.object.clone(n):{},r))},void(fabric.Image.async=!0))}("undefined"!=typeof exports?exports:this),fabric.util.object.extend(fabric.Object.prototype,{_getAngleValueForStraighten:function(){var t=this.getAngle()%360;return t>0?90*Math.round((t-1)/90):90*Math.round(t/90)},straighten:function(){return this.setAngle(this._getAngleValueForStraighten()),this},fxStraighten:function(t){t=t||{};var e=function(){},i=t.onComplete||e,n=t.onChange||e,r=this;return fabric.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(t){r.setAngle(t),n()},onComplete:function(){r.setCoords(),i()},onStart:function(){r.setActive(!1)}}),this}}),fabric.util.object.extend(fabric.StaticCanvas.prototype,{straightenObject:function(t){return t.straighten(),this.renderAll(),this},fxStraightenObject:function(t){return t.fxStraighten({onChange:this.renderAll.bind(this)}),this}}),fabric.Image.filters={},fabric.Image.filters.Grayscale=fabric.util.createClass({type:"Grayscale",applyTo:function(t){var e,i,n,r,o=t.getContext("2d"),s=o.getImageData(0,0,t.width,t.height),a=s.data,c=s.width,l=s.height;for(n=0;c>n;n++)for(r=0;l>r;r++)e=4*n*l+4*r,i=(a[e]+a[e+1]+a[e+2])/3,a[e]=i,a[e+1]=i,a[e+2]=i;o.putImageData(s,0,0)},toJSON:function(){return{type:this.type}}}),fabric.Image.filters.Grayscale.fromObject=function(){return new fabric.Image.filters.Grayscale},fabric.Image.filters.RemoveWhite=fabric.util.createClass({type:"RemoveWhite",initialize:function(t){t||(t={}),this.threshold=t.threshold||30,this.distance=t.distance||20},applyTo:function(t){for(var e,i,n,r=t.getContext("2d"),o=r.getImageData(0,0,t.width,t.height),s=o.data,a=this.threshold,c=this.distance,l=255-a,u=Math.abs,h=0,f=s.length;f>h;h+=4)e=s[h],i=s[h+1],n=s[h+2],e>l&&i>l&&n>l&&u(e-i)e;e+=4)r[e]=255-r[e],r[e+1]=255-r[e+1],r[e+2]=255-r[e+2];i.putImageData(n,0,0)},toJSON:function(){return{type:this.type}}}),fabric.Image.filters.Invert.fromObject=function(){return new fabric.Image.filters.Invert},fabric.Image.filters.Sepia=fabric.util.createClass({type:"Sepia",applyTo:function(t){var e,i,n=t.getContext("2d"),r=n.getImageData(0,0,t.width,t.height),o=r.data,s=o.length;for(e=0;s>e;e+=4)i=.3*o[e]+.59*o[e+1]+.11*o[e+2],o[e]=i+100,o[e+1]=i+50,o[e+2]=i+255;n.putImageData(r,0,0)},toJSON:function(){return{type:this.type}}}),fabric.Image.filters.Sepia.fromObject=function(){return new fabric.Image.filters.Sepia},fabric.Image.filters.Sepia2=fabric.util.createClass({type:"Sepia2",applyTo:function(t){var e,i,n,r,o=t.getContext("2d"),s=o.getImageData(0,0,t.width,t.height),a=s.data,c=a.length;for(e=0;c>e;e+=4)i=a[e],n=a[e+1],r=a[e+2],a[e]=(.393*i+.769*n+.189*r)/1.351,a[e+1]=(.349*i+.686*n+.168*r)/1.203,a[e+2]=(.272*i+.534*n+.131*r)/2.14;o.putImageData(s,0,0)},toJSON:function(){return{type:this.type}}}),fabric.Image.filters.Sepia2.fromObject=function(){return new fabric.Image.filters.Sepia2},fabric.Image.filters.Brightness=fabric.util.createClass({type:"Brightness",initialize:function(t){t||(t={}),this.brightness=t.brightness||100},applyTo:function(t){for(var e=t.getContext("2d"),i=e.getImageData(0,0,t.width,t.height),n=i.data,r=this.brightness,o=0,s=n.length;s>o;o+=4)n[o]+=r,n[o+1]+=r,n[o+2]+=r;e.putImageData(i,0,0)},toJSON:function(){return{type:this.type,brightness:this.brightness}}}),fabric.Image.filters.Brightness.fromObject=function(t){return new fabric.Image.filters.Brightness(t)},fabric.Image.filters.Noise=fabric.util.createClass({type:"Noise",initialize:function(t){t||(t={}),this.noise=t.noise||100},applyTo:function(t){for(var e,i=t.getContext("2d"),n=i.getImageData(0,0,t.width,t.height),r=n.data,o=this.noise,s=0,a=r.length;a>s;s+=4)e=(.5-Math.random())*o,r[s]+=e,r[s+1]+=e,r[s+2]+=e;i.putImageData(n,0,0)},toJSON:function(){return{type:this.type,noise:this.noise}}}),fabric.Image.filters.Noise.fromObject=function(t){return new fabric.Image.filters.Noise(t)},fabric.Image.filters.GradientTransparency=fabric.util.createClass({type:"GradientTransparency",initialize:function(t){t||(t={}),this.threshold=t.threshold||100},applyTo:function(t){for(var e=t.getContext("2d"),i=e.getImageData(0,0,t.width,t.height),n=i.data,r=this.threshold,o=n.length,s=0,a=n.length;a>s;s+=4)n[s+3]=r+255*(o-s)/o;e.putImageData(i,0,0)},toJSON:function(){return{type:this.type,threshold:this.threshold}}}),fabric.Image.filters.GradientTransparency.fromObject=function(t){return new fabric.Image.filters.GradientTransparency(t)},fabric.Image.filters.Tint=fabric.util.createClass({type:"Tint",initialize:function(t){t||(t={}),this.color=t.color||0},applyTo:function(t){var e,i,n=t.getContext("2d"),r=n.getImageData(0,0,t.width,t.height),o=r.data,s=o.length,a=parseInt(this.color,10).toString(16),c=parseInt("0x"+a.substr(0,2),16),l=parseInt("0x"+a.substr(2,2),16),u=parseInt("0x"+a.substr(4,2),16);for(e=0;s>e;e+=4)i=o[e+3],i>0&&(o[e]=c,o[e+1]=l,o[e+2]=u);n.putImageData(r,0,0)},toJSON:function(){return{type:this.type,color:this.color}}}),fabric.Image.filters.Tint.fromObject=function(t){return new fabric.Image.filters.Tint(t)},fabric.Image.filters.Convolute=fabric.util.createClass({type:"Convolute",initialize:function(t){t||(t={}),this.opaque=t.opaque,this.matrix=t.matrix||[0,0,0,0,1,0,0,0,0];var e=fabric.util.createCanvasElement();this.tmpCtx=e.getContext("2d")},_createImageData:function(t,e){return this.tmpCtx.createImageData(t,e)},applyTo:function(t){for(var e=this.matrix,i=t.getContext("2d"),n=i.getImageData(0,0,t.width,t.height),r=Math.round(Math.sqrt(e.length)),o=Math.floor(r/2),s=n.data,a=n.width,c=n.height,l=a,u=c,h=this._createImageData(l,u),f=h.data,d=this.opaque?1:0,p=0;u>p;p++)for(var g=0;l>g;g++){for(var v=p,m=g,b=4*(p*l+g),y=0,x=0,w=0,k=0,C=0;r>C;C++)for(var _=0;r>_;_++){var S=v+C-o,E=m+_-o;if(S>=0&&c>S&&E>=0&&a>E){var T=4*(S*a+E),O=e[C*r+_];y+=s[T]*O,x+=s[T+1]*O,w+=s[T+2]*O,k+=s[T+3]*O}}f[b]=y,f[b+1]=x,f[b+2]=w,f[b+3]=k+d*(255-k)}i.putImageData(h,0,0)},toJSON:function(){return{type:this.type,matrix:this.matrix}}}),fabric.Image.filters.Convolute.fromObject=function(t){return new fabric.Image.filters.Convolute(t)},fabric.Image.filters.Pixelate=fabric.util.createClass({type:"Pixelate",initialize:function(t){t||(t={}),this.blocksize=t.blocksize||4},applyTo:function(t){var e,i,n,r,o,s,a,c=t.getContext("2d"),l=c.getImageData(0,0,t.width,t.height),u=l.data,h=l.width,f=l.height;for(i=0;h>i;i+=this.blocksize)for(n=0;f>n;n+=this.blocksize){e=4*i*f+4*n,r=u[e],o=u[e+1],s=u[e+2],a=u[e+3];for(var d=i,p=i+this.blocksize;p>d;d++)for(var g=n,v=n+this.blocksize;v>g;g++)e=4*d*f+4*g,u[e]=r,u[e+1]=o,u[e+2]=s,u[e+3]=a}c.putImageData(l,0,0)},toJSON:function(){return{type:this.type,blocksize:this.blocksize}}}),fabric.Image.filters.Pixelate.fromObject=function(t){return new fabric.Image.filters.Pixelate(t)},function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.object.extend,n=e.util.object.clone,r=e.util.toFixed;if(e.Text)return void e.warn("fabric.Text is already defined");var o={fontSize:!0,fontWeight:!0,fontFamily:!0,textDecoration:!0,fontStyle:!0,lineHeight:!0,strokeStyle:!0,strokeWidth:!0,text:!0},s=e.Object.prototype.stateProperties.concat();s.push("fontFamily","fontWeight","fontSize","path","text","textDecoration","textShadow","textAlign","fontStyle","lineHeight","strokeStyle","strokeWidth","backgroundColor","textBackgroundColor","useNative"),e.Text=e.util.createClass(e.Object,{fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",textDecoration:"",textShadow:"",textAlign:"left",fontStyle:"",lineHeight:1.3,strokeStyle:"",strokeWidth:1,backgroundColor:"",textBackgroundColor:"",path:null,type:"text",useNative:!0,stateProperties:s,initialize:function(t,e){e=e||{},this.text=t,this.setOptions(e),this._initDimensions(),this.setCoords()},_initDimensions:function(){var t=e.util.createCanvasElement();this._render(t.getContext("2d"))},toString:function(){return"#'},_render:function(t){"undefined"==typeof Cufon||this.useNative===!0?this._renderViaNative(t):this._renderViaCufon(t)},_renderViaCufon:function(t){var e=Cufon.textOptions||(Cufon.textOptions={});e.left=this.left,e.top=this.top,e.context=t,e.color=this.fill;var i=this._initDummyElementForCufon();this.transform(t),Cufon.replaceElement(i,{engine:"canvas",separate:"none",fontFamily:this.fontFamily,fontWeight:this.fontWeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,fontStyle:this.fontStyle,lineHeight:this.lineHeight,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor,textBackgroundColor:this.textBackgroundColor}),this.width=e.width,this.height=e.height,this._totalLineHeight=e.totalLineHeight,this._fontAscent=e.fontAscent,this._boundaries=e.boundaries,this._shadowOffsets=e.shadowOffsets,this._shadows=e.shadows||[],i=null,this.setCoords()},_renderViaNative:function(t){this.transform(t),this._setTextStyles(t);var i=this.text.split(/\r?\n/);this.width=this._getTextWidth(t,i),this.height=this._getTextHeight(t,i),this._renderTextBackground(t,i),"left"!==this.textAlign&&"justify"!==this.textAlign&&(t.save(),t.translate("center"===this.textAlign?this.width/2:this.width,0)),this._setTextShadow(t),this.clipTo&&e.util.clipContext(this,t),this._renderTextFill(t,i),this._renderTextStroke(t,i),this.clipTo&&t.restore(),this.textShadow&&t.restore(),"left"!==this.textAlign&&"justify"!==this.textAlign&&t.restore(),this._renderTextDecoration(t,i),this._setBoundaries(t,i),this._totalLineHeight=0,this.setCoords()},_setBoundaries:function(t,e){this._boundaries=[];for(var i=0,n=e.length;n>i;i++){var r=this._getLineWidth(t,e[i]),o=this._getLineLeftOffset(r);this._boundaries.push({height:this.fontSize*this.lineHeight,width:r,left:o})}},_setTextStyles:function(t){t.fillStyle=this.fill.toLive?this.fill.toLive(t):this.fill,t.strokeStyle=this.strokeStyle,t.lineWidth=this.strokeWidth,t.textBaseline="alphabetic",t.textAlign=this.textAlign,t.font=this._getFontDeclaration()},_getTextHeight:function(t,e){return this.fontSize*e.length*this.lineHeight},_getTextWidth:function(t,e){for(var i=t.measureText(e[0]).width,n=1,r=e.length;r>n;n++){var o=t.measureText(e[n]).width;o>i&&(i=o)}return i},_setTextShadow:function(t){if(this.textShadow){var e=/\s+(-?\d+)(?:px)?\s+(-?\d+)(?:px)?\s+(\d+)(?:px)?\s*/,i=this.textShadow,n=e.exec(this.textShadow),r=i.replace(e,"");t.save(),t.shadowColor=r,t.shadowOffsetX=parseInt(n[1],10),t.shadowOffsetY=parseInt(n[2],10),t.shadowBlur=parseInt(n[3],10),this._shadows=[{blur:t.shadowBlur,color:t.shadowColor,offX:t.shadowOffsetX,offY:t.shadowOffsetY}],this._shadowOffsets=[[parseInt(t.shadowOffsetX,10),parseInt(t.shadowOffsetY,10)]]}},_drawTextLine:function(t,e,i,n,r){if("justify"!==this.textAlign)return void e[t](i,n,r);var o=e.measureText(i).width,s=this.width;if(s>o)for(var a=i.split(/\s+/),c=e.measureText(i.replace(/\s+/g,"")).width,l=s-c,u=a.length-1,h=l/u,f=0,d=0,p=a.length;p>d;d++)e[t](a[d],n+f,r),f+=e.measureText(a[d]).width+h;else e[t](i,n,r)},_renderTextFill:function(t,e){this._boundaries=[];for(var i=0,n=e.length;n>i;i++)this._drawTextLine("fillText",t,e[i],-this.width/2,-this.height/2+i*this.fontSize*this.lineHeight+this.fontSize)},_renderTextStroke:function(t,e){if(this.strokeStyle){t.beginPath();for(var i=0,n=e.length;n>i;i++)this._drawTextLine("strokeText",t,e[i],-this.width/2,-this.height/2+i*this.fontSize*this.lineHeight+this.fontSize);t.closePath()}},_renderTextBackground:function(t,e){this._renderTextBoxBackground(t),this._renderTextLinesBackground(t,e)},_renderTextBoxBackground:function(t){this.backgroundColor&&(t.save(),t.fillStyle=this.backgroundColor,t.fillRect(-this.width/2,-this.height/2,this.width,this.height),t.restore())},_renderTextLinesBackground:function(t,e){if(this.textBackgroundColor){t.save(),t.fillStyle=this.textBackgroundColor;for(var i=0,n=e.length;n>i;i++)if(""!==e[i]){var r=this._getLineWidth(t,e[i]),o=this._getLineLeftOffset(r);t.fillRect(-this.width/2+o,-this.height/2+i*this.fontSize*this.lineHeight,r,this.fontSize*this.lineHeight)}t.restore()}},_getLineLeftOffset:function(t){ return"center"===this.textAlign?(this.width-t)/2:"right"===this.textAlign?this.width-t:0},_getLineWidth:function(t,e){return"justify"===this.textAlign?this.width:t.measureText(e).width},_renderTextDecoration:function(t,e){function i(i){for(var o=0,s=e.length;s>o;o++){var a=r._getLineWidth(t,e[o]),c=r._getLineLeftOffset(a);t.fillRect(-r.width/2+c,i+o*r.fontSize*r.lineHeight-n,a,1)}}var n=this._getTextHeight(t,e)/2,r=this;this.textDecoration.indexOf("underline")>-1&&i(this.fontSize),this.textDecoration.indexOf("line-through")>-1&&i(this.fontSize/2),this.textDecoration.indexOf("overline")>-1&&i(0)},_getFontDeclaration:function(){return[e.isLikelyNode?this.fontWeight:this.fontStyle,e.isLikelyNode?this.fontStyle:this.fontWeight,this.fontSize+"px",e.isLikelyNode?'"'+this.fontFamily+'"':this.fontFamily].join(" ")},_initDummyElementForCufon:function(){var t=e.document.createElement("pre"),i=e.document.createElement("div");return i.appendChild(t),"undefined"==typeof G_vmlCanvasManager?t.innerHTML=this.text:t.innerText=this.text.replace(/\r?\n/gi,"\r"),t.style.fontSize=this.fontSize+"px",t.style.letterSpacing="normal",t},render:function(t,e){t.save(),this._render(t),!e&&this.active&&(this.drawBorders(t),this.drawControls(t)),t.restore()},toObject:function(t){return i(this.callSuper("toObject",t),{text:this.text,fontSize:this.fontSize,fontWeight:this.fontWeight,fontFamily:this.fontFamily,fontStyle:this.fontStyle,lineHeight:this.lineHeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,path:this.path,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor,textBackgroundColor:this.textBackgroundColor,useNative:this.useNative})},toSVG:function(){var t=this.text.split(/\r?\n/),e=this.useNative?this.fontSize*this.lineHeight:-this._fontAscent-this._fontAscent/5*this.lineHeight,i=-(this.width/2),n=this.useNative?this.fontSize-1:this.height/2-t.length*this.fontSize-this._totalLineHeight,o=this._getSVGTextAndBg(e,i,t),s=this._getSVGShadows(e,t);return n+=this._fontAscent?this._fontAscent/5*this.lineHeight:0,['',o.textBgRects.join(""),"',s.join(""),o.textSpans.join(""),"",""].join("")},_getSVGShadows:function(t,i){var n,o,s,a,c=[],l=1;if(!this._shadows||!this._boundaries)return c;for(n=0,s=this._shadows.length;s>n;n++)for(o=0,a=i.length;a>o;o++)if(""!==i[o]){var u=this._boundaries&&this._boundaries[o]?this._boundaries[o].left:0;c.push('",e.util.string.escapeXml(i[o]),""),l=1}else l++;return c},_getSVGTextAndBg:function(t,i,n){var o,s,a,c=[],l=[],u=1;for(this.backgroundColor&&this._boundaries&&l.push("'),o=0,a=n.length;a>o;o++)""!==n[o]?(s=this._boundaries&&this._boundaries[o]?r(this._boundaries[o].left,2):0,c.push('",e.util.string.escapeXml(n[o]),""),u=1):u++,this.textBackgroundColor&&this._boundaries&&l.push("');return{textSpans:c,textBgRects:l}},_getFillAttributes:function(t){var i=t?new e.Color(t):"";return i&&i.getSource()&&1!==i.getAlpha()?'opacity="'+i.getAlpha()+'" fill="'+i.setAlpha(1).toRgb()+'"':'fill="'+t+'"'},setColor:function(t){return this.set("fill",t),this},getText:function(){return this.text},_set:function(t,e){"fontFamily"===t&&this.path&&(this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+e+"$3")),this.callSuper("_set",t,e),t in o&&(this._initDimensions(),this.setCoords())}}),e.Text.ATTRIBUTE_NAMES="x y fill fill-opacity opacity stroke stroke-width transform font-family font-style font-weight font-size text-decoration".split(" "),e.Text.fromObject=function(t){return new e.Text(t.text,n(t))},e.Text.fromElement=function(t,i){if(!t)return null;var n=e.parseAttributes(t,e.Text.ATTRIBUTE_NAMES);i=e.util.object.extend(i?e.util.object.clone(i):{},n);var r=new e.Text(t.textContent,i);return r.set({left:r.getLeft()+r.getWidth()/2,top:r.getTop()-r.getHeight()/2}),r},e.util.createAccessors(e.Text)}("undefined"!=typeof exports?exports:this),function(){function request(t,e,i){var n=URL.parse(t),r=HTTP.request({hostname:n.hostname,port:n.port,path:n.pathname,method:"GET"},function(t){var n="";e&&t.setEncoding(e),t.on("end",function(){i(n)}),t.on("data",function(e){200===t.statusCode&&(n+=e)})});r.on("error",function(t){t.errno===process.ECONNREFUSED?fabric.log("ECONNREFUSED: connection refused to "+n.hostname+":"+n.port):fabric.log(t.message)})}function request_fs(t,e){var i=require("fs"),n=i.createReadStream(t),r="";n.on("data",function(t){r+=t}),n.on("end",function(){e(r)})}if("undefined"==typeof document||"undefined"==typeof window){var DOMParser=new require("xmldom").DOMParser,URL=require("url"),HTTP=require("http"),Canvas=require("canvas"),Image=require("canvas").Image;fabric.util.loadImage=function(t,e,i){var n=function(n){r.src=new Buffer(n,"binary"),r._src=t,e&&e.call(i,r)},r=new Image;t&&0===t.indexOf("data")?(r.src=r._src=t,e&&e.call(i,r)):t&&0!==t.indexOf("http")?request_fs(t,n):t&&request(t,"binary",n)},fabric.loadSVGFromURL=function(t,e){t=t.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim(),request(t,"",function(t){fabric.loadSVGFromString(t,e)})},fabric.loadSVGFromString=function(t,e){var i=(new DOMParser).parseFromString(t);fabric.parseSVGDocument(i.documentElement,function(t,i){e(t,i)})},fabric.util.getScript=function(url,callback){request(url,"",function(body){eval(body),callback&&callback()})},fabric.Image.fromObject=function(t,e){fabric.util.loadImage(t.src,function(i){var n=new fabric.Image(i);n._initConfig(t),n._initFilters(t),e(n)})},fabric.createCanvasForNode=function(t,e){var i=fabric.document.createElement("canvas"),n=new Canvas(t||600,e||600);i.style={},i.width=n.width,i.height=n.height;var r=fabric.Canvas||fabric.StaticCanvas,o=new r(i);return o.contextContainer=n.getContext("2d"),o.nodeCanvas=n,o.Font=Canvas.Font,o},fabric.StaticCanvas.prototype.createPNGStream=function(){return this.nodeCanvas.createPNGStream()},fabric.StaticCanvas.prototype.createJPEGStream=function(t){return this.nodeCanvas.createJPEGStream(t)};var origSetWidth=fabric.StaticCanvas.prototype.setWidth;fabric.StaticCanvas.prototype.setWidth=function(t){return origSetWidth.call(this,t),this.nodeCanvas.width=t,this},fabric.Canvas&&(fabric.Canvas.prototype.setWidth=fabric.StaticCanvas.prototype.setWidth);var origSetHeight=fabric.StaticCanvas.prototype.setHeight;fabric.StaticCanvas.prototype.setHeight=function(t){return origSetHeight.call(this,t),this.nodeCanvas.height=t,this},fabric.Canvas&&(fabric.Canvas.prototype.setHeight=fabric.StaticCanvas.prototype.setHeight)}}(),function(t){function e(e){return c?e.data("events"):t._data(e[0]).events}function i(t,i,n){var r=e(t),o=r[i];if(!c){var s=n?o.splice(o.delegateCount-1,1)[0]:o.pop();return void o.splice(n?0:o.delegateCount||0,0,s)}n?r.live.unshift(r.live.pop()):o.unshift(o.pop())}function n(e,n,r){var o=n.split(/\s+/);e.each(function(){for(var e=0;es||1==s&&7>a;r("bind"),r("one"),t.fn.delegateFirst=function(){var e=t.makeArray(arguments),i=e[1];return i&&(e.splice(0,2),t.fn.delegate.apply(this,arguments),n(this,i,!0)),this},t.fn.liveFirst=function(){var e=t.makeArray(arguments);return e.unshift(this.selector),t.fn.delegateFirst.apply(t(document),e),this},c||(t.fn.onFirst=function(e,i){var r=t(this),o="string"==typeof i;if(t.fn.on.apply(r,arguments),"object"==typeof e)for(type in e)e.hasOwnProperty(type)&&n(r,type,o);else"string"==typeof e&&n(r,e,o);return r})}(jQuery),function(t){void 0==t.fn.inputmask&&(t.inputmask={defaults:{placeholder:"_",optionalmarker:{start:"[",end:"]"},escapeChar:"\\",mask:null,oncomplete:t.noop,onincomplete:t.noop,oncleared:t.noop,repeat:0,greedy:!0,autoUnmask:!1,clearMaskOnLostFocus:!0,insertMode:!0,clearIncomplete:!1,aliases:{},onKeyUp:t.noop,onKeyDown:t.noop,showMaskOnHover:!0,numericInput:!1,radixPoint:".",definitions:{9:{validator:"[0-9]",cardinality:1},a:{validator:"[A-Za-zА-яЁё]",cardinality:1},"*":{validator:"[A-Za-zА-яЁё0-9]",cardinality:1}},keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91},ignorables:[8,9,13,16,17,18,20,27,33,34,35,36,37,38,39,40,46,91,93,108]},val:t.fn.val},t.fn.inputmask=function(e,i){function n(t){var e=document.createElement("input"),t="on"+t,i=t in e;return i||(e.setAttribute(t,"return;"),i="function"==typeof e[t]),e=null,i}function r(e){var n=T.aliases[e];return n?(n.alias&&r(n.alias),t.extend(!0,T,n),t.extend(!0,T,i),!0):!1}function o(){var e=!1,i=0;1==T.mask.length&&0==T.greedy&&(T.placeholder="");for(var n=t.map(T.mask.split(""),function(t,n){var r=[];if(t==T.escapeChar)e=!0;else if(t!=T.optionalmarker.start&&t!=T.optionalmarker.end||e){var o=T.definitions[t];if(o&&!e)for(var s=0;s=l?a[l-1]:[],h=u.validator,f=u.cardinality;o.push({fn:h?"string"==typeof h?new RegExp(h):new function(){this.test=h}:new RegExp("."),cardinality:f?f:1,optionality:e,newBlockMarker:1==e?n:!1,offset:0,casing:s.casing,def:t}),1==e&&(n=!1)}o.push({fn:s.validator?"string"==typeof s.validator?new RegExp(s.validator):new function(){this.test=s.validator}:new RegExp("."),cardinality:s.cardinality,optionality:e,newBlockMarker:n,offset:0,casing:s.casing,def:t})}else o.push({fn:null,cardinality:0,optionality:e,newBlockMarker:n,offset:0,casing:null,def:t}),i=!1;return n=!1,o}e=!1,n=!0}else e=!0,n=!0})}function a(t,e,i,n){if(0>t||t>=h())return!1;for(var r=l(t),o=e?1:0,s="",a=D[r].cardinality;a>o;a--)s+=g(i,r-(a-1));return e&&(s+=e),null!=D[r].fn?D[r].fn.test(s,i,t,n,T):!1}function c(t){var e=l(t),i=D[e];return void 0!=i?i.fn:!1}function l(t){return t%D.length}function u(t){return T.placeholder.charAt(t%T.placeholder.length)}function h(){var t=M.length;return!T.greedy&&T.repeat>1&&(t+=M.length*(T.repeat-1)),t}function f(t,e){var i=h();if(e>=i)return i;for(var n=e;++n=i)return 0;for(;--i>0&&!c(i););return i}function p(t,e,i){var n=D[l(e)],r=i;if(void 0!=r)switch(n.casing){case"upper":r=i.toUpperCase();break;case"lower":r=i.toLowerCase()}t[e]=r}function g(t,e,i){return i&&(e=v(t,e)),t[e]}function v(t,e,i){var n;if(i)for(;0>e&&t.lengthn&&r>n;n++)p(t,n,g(M.slice(),n))}function y(t,e){var i=l(e);p(t,e,g(M,i))}function x(e,i,n,r){var o=t(e)[0].inputmask.isRTL,s=k(e._valueGet(),o).split("");if(o){var d=h(),v=s.reverse();v.length=d;for(var x=0;d>x;x++){var w=l(d-(x+1));null==D[w].fn&&v[x]!=g(M,w)?(v.splice(x,0,g(M,w)),v.length=d):v[x]=v[x]||g(M,w)}s=v.reverse()}b(i,0,i.length),i.length=M.length;for(var C,_=-1,S=-1,d=h(),E=s.length,O=0==E?d:-1,x=0;E>x;x++)for(var j=S+1;d>j;j++){if(c(j)){var P=s[x];(C=a(j,P,i,!n))!==!1?(C!==!0&&(j=C.pos||j,P=C.c||P),p(i,j,P),_=S=j):(y(i,j),P==u(j)&&(S=j,O=j));break}if(y(i,j),_==S&&(_=j),S=j,s[x]==g(i,j))break}if(0==T.greedy)for(var A=k(i.join(""),o).split("");i.length!=A.length;)o?i.shift():i.pop();return n&&m(e,i),o?T.numericInput?-1!=t.inArray(T.radixPoint,i)&&r!==!0?t.inArray(T.radixPoint,i):f(i,d):f(i,O):f(i,_)}function w(t){var e=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];return t.replace(new RegExp("(\\"+e.join("|\\")+")","gim"),"\\$1")}function k(t,e){return e?t.replace(new RegExp("^("+w(M.join(""))+")*"),""):t.replace(new RegExp("("+w(M.join(""))+")*$"),"")}function C(e,i){x(e,i,!1);var n=i.slice();if(t(e)[0].inputmask.isRTL)for(var r=0;r<=n.length-1;r++){var o=l(r);if(!D[o].optionality)break;if(u(r)!=i[r]&&c(r))break;n.splice(0,1)}else for(var r=n.length-1;r>=0;r--){var o=l(r);if(!D[o].optionality)break;if(u(r)!=i[r]&&c(r))break;n.pop()}m(e,n)}function _(e,i){var n=e[0];if(!D||i!==!0&&e.hasClass("hasDatepicker"))return n._valueGet();var r=M.slice();return x(n,r),t.map(r,function(t,e){return c(e)&&t!=g(M.slice(),e)?t:null}).join("")}function S(t,e,i){var n=t.jquery&&t.length>0?t[0]:t;if("number"!=typeof e){var r=P?o:null,o=null;if(null==r){if(n.setSelectionRange)e=n.selectionStart,i=n.selectionEnd;else if(document.selection&&document.selection.createRange){var s=document.selection.createRange();e=0-s.duplicate().moveStart("character",-1e5),i=e+s.text.length}r={begin:e,end:i}}return r}if(i="number"==typeof i?i:e,0==T.insertMode&&e==i&&i++,n.setSelectionRange)n.setSelectionRange(e,i);else if(n.createTextRange){var s=n.createTextRange();s.collapse(!0),s.moveEnd("character",i),s.moveStart("character",e),s.select()}n.focus(),P&&i!=n.selectionEnd&&(o={begin:e,end:i})}function E(e){function i(t){for(var e=!0,i=t._valueGet(),n=i.length,r=0;n>r;r++)if(c(r)&&i.charAt(r)==u(r)){e=!1;break}return e}function n(e){var i=t._data(e).events;i&&t.each(i,function(i,n){t(e).bind(i+".inputmask",function(t){return this.readOnly||this.disabled?(t.stopPropagation(),t.stopImmediatePropagation(),t.preventDefault(),!1):void 0});for(var r=n[n.length-1],o=n.length-1;o>0;o--)n[o]=n[o-1];n[0]=r})}function r(e){var i;Object.getOwnPropertyDescriptor&&(i=Object.getOwnPropertyDescriptor(e,"value")),i&&i.get?e._valueGet||(e._valueGet=i.get,e._valueSet=i.set,Object.defineProperty(e,"value",{get:function(){var e=t(this),i=t(this)[0].inputmask;return i&&i.autoUnmask?e.inputmask("unmaskedvalue"):this._valueGet()!=i._buffer.join("")?this._valueGet():""},set:function(e){this._valueSet(e),t(this).triggerHandler("setvalue.inputmask")}})):document.__lookupGetter__&&e.__lookupGetter__("value")?e._valueGet||(e._valueGet=e.__lookupGetter__("value"),e._valueSet=e.__lookupSetter__("value"),e.__defineGetter__("value",function(){var e=t(this),i=t(this)[0].inputmask;return i&&i.autoUnmask?e.inputmask("unmaskedvalue"):this._valueGet()!=i._buffer.join("")?this._valueGet():""}),e.__defineSetter__("value",function(e){this._valueSet(e),t(this).triggerHandler("setvalue.inputmask")})):(e._valueGet||(e._valueGet=function(){return this.value},e._valueSet=function(t){this.value=t}),1!=t.fn.val.inputmaskpatch&&(t.fn.val=function(){if(0==arguments.length){var e=t(this);if(e[0]&&e[0].inputmask){if(e[0].inputmask.autoUnmask)return e.inputmask("unmaskedvalue");var i=t.inputmask.val.apply(e);return i!=e[0].inputmask._buffer.join("")?i:""}return t.inputmask.val.apply(e)}var n=arguments;return this.each(function(){var e=t(this),i=t.inputmask.val.apply(e,n);return e[0].inputmask&&e.triggerHandler("setvalue.inputmask"),i})},t.extend(t.fn.val,{inputmaskpatch:!0})))}function o(t,e,i){for(;!c(t)&&t-1>=0;)t--;for(var n=t;e>n&&n=r&&r1||r.end-r.begin==1&&T.insertMode)b(F,r.begin,r.end),m(i,F,Y?x(i,F,!1):r.begin);else{var d=r.begin-(n==T.keyCode.DELETE?0:1);X>d&&n==T.keyCode.DELETE&&(d=X),d>=X&&(T.numericInput&&T.greedy&&n==T.keyCode.DELETE&&F[d]==T.radixPoint&&(d=f(F,d),Y=!1),Y?(d=s(X,d,u(d),!0),d=T.numericInput&&T.greedy&&n==T.keyCode.BACKSPACE&&F[d+1]==T.radixPoint?d+1:f(F,d)):d=o(d,l),m(i,F,d))}return i._valueGet()==M.join("")&&t(i).trigger("cleared"),!1}if(n==T.keyCode.END||n==T.keyCode.PAGE_DOWN)return setTimeout(function(){var t=x(i,F,!1,!0);T.insertMode||t!=h()||e.shiftKey||t--,S(i,e.shiftKey?r.begin:t,t)},0),!1;if(n==T.keyCode.HOME||n==T.keyCode.PAGE_UP)return S(i,0,e.shiftKey?r.begin:0),!1;if(n==T.keyCode.ESCAPE)return i._valueSet(G),S(i,0,x(i,F)),!1;if(n==T.keyCode.INSERT)return T.insertMode=!T.insertMode,S(i,T.insertMode||r.begin!=h()?r.begin:r.begin-1),!1;if(e.ctrlKey&&88==n)setTimeout(function(){S(i,x(i,F,!0))},0);else if(!T.insertMode){if(n==T.keyCode.RIGHT){var p=r.begin==r.end?r.end+1:r.end;return p=p0?p:0,S(i,p,e.shiftKey?r.end:p),!1}}T.onKeyDown.call(this,e,T),R=-1!=t.inArray(n,T.ignorables)}function _(e){if(L)return!1;L=!0;var n=this,r=t(n);e=e||window.event;var c=e.which||e.charCode||e.keyCode;if(T.numericInput&&c==T.radixPoint.charCodeAt(T.radixPoint.length-1)){var l=n._valueGet(),y=l.indexOf(T.radixPoint);S(n,f(F,-1!=y?y:h()))}if(e.ctrlKey||e.altKey||e.metaKey||R)return!0;if(c){r.trigger("input");var x=S(n),w=String.fromCharCode(c),k=h();if(b(F,x.begin,x.end),Y){var C,_=T.numericInput?x.end:d(F,x.end);if((C=a(_==k||g(F,_)==T.radixPoint?d(F,_):_,w,F,!1))!==!1){C!==!0&&(_=C.pos||x,w=C.c||w);var E=X;if(1==T.insertMode){if(1==T.greedy)for(var O=F.slice();g(O,E,!0)!=u(E)&&_>=E;)E=E==k?k+1:f(F,E);if(!(_>=E&&(T.greedy||F.length=_;)A=0==A?-1:d(F,A);if(!(A>=_))return!1;s(_,F.length,w)}else p(F,_,w);var I=f(F,_);m(n,F,I),setTimeout(function(){i(n)&&r.trigger("complete")},0)}else P&&m(n,F,x.begin)}return!1}}function E(e){var i=t(this),n=this,r=e.keyCode;T.onKeyUp.call(this,e,T),r==T.keyCode.TAB&&i.hasClass("focus.inputmask")&&0==n._valueGet().length&&(F=M.slice(),m(n,F),Y||S(n,0),G=n._valueGet())}var A=t(e);if(A.is(":input")){T.greedy=T.greedy?T.greedy:0==T.repeat;var I=A.prop("maxLength");h()>I&&I>-1&&(IN&&(a(i,F[i],F,!0)!==!1||!c(i))?i:N):S(t,N>i&&(a(i,F[i],F,!0)!==!1||!c(i))?i:N)}},0)}).bind("dblclick.inputmask",function(){var t=this;setTimeout(function(){S(t,0,N)},0)}).bind("keydown.inputmask",w).bind("keypress.inputmask",_).bind("keyup.inputmask",E).bind(O+".inputmask, dragdrop.inputmask, drop.inputmask",function(){var t=this;setTimeout(function(){S(t,x(t,F,!0))},0)}).bind("setvalue.inputmask",function(){var t=this;G=t._valueGet(),x(t,F,!0),t._valueGet()==M.join("")&&t._valueSet("")}).bind("complete.inputmask",T.oncomplete).bind("incomplete.inputmask",T.onincomplete).bind("cleared.inputmask",T.oncleared),N=x(e,F,!0);var z;try{z=document.activeElement}catch(W){}z===e?(A.addClass("focus.inputmask"),S(e,N)):T.clearMaskOnLostFocus&&(e._valueGet()==M.join("")?e._valueSet(""):C(e,F)),n(e)}}var T=t.extend(!0,{},t.inputmask.defaults,i),O=n("paste")?"paste":"input",j=null!=navigator.userAgent.match(/iphone/i),P=null!=navigator.userAgent.match(/android.*mobile safari.*/i);if(P){var A=navigator.userAgent.match(/mobile safari.*/i),I=parseInt(new RegExp(/[0-9]+/).exec(A));P=533>=I}if("string"==typeof e)switch(e){case"mask":var M=o(),D=s();return this.each(function(){E(this)});case"unmaskedvalue":var D=this[0].inputmask.tests,M=this[0].inputmask._buffer;return T.greedy=this[0].inputmask.greedy,T.repeat=this[0].inputmask.repeat,T.definitions=this[0].inputmask.definitions,_(this);case"remove":var D,M;return this.each(function(){var e=t(this),i=this;setTimeout(function(){if(e[0].inputmask){D=e[0].inputmask.tests,M=e[0].inputmask._buffer,T.greedy=e[0].inputmask.greedy,T.repeat=e[0].inputmask.repeat,T.definitions=e[0].inputmask.definitions,i._valueSet(_(e,!0)),e.removeData("inputmask"),e.unbind(".inputmask"),e.removeClass("focus.inputmask");var t;Object.getOwnPropertyDescriptor&&(t=Object.getOwnPropertyDescriptor(i,"value")),t&&t.get?i._valueGet&&Object.defineProperty(i,"value",{get:i._valueGet,set:i._valueSet}):document.__lookupGetter__&&i.__lookupGetter__("value")&&i._valueGet&&(i.__defineGetter__("value",i._valueGet),i.__defineSetter__("value",i._valueSet)),delete i._valueGet,delete i._valueSet}},0)});case"getemptymask":return this[0].inputmask?this[0].inputmask._buffer.join(""):"";case"hasMaskedValue":return this[0].inputmask?!this[0].inputmask.autoUnmask:!1;default:r(e)||(T.mask=e);var M=o(),D=s();return this.each(function(){E(this)})}if("object"==typeof e){T=t.extend(!0,{},t.inputmask.defaults,e),r(T.alias);var M=o(),D=s();return this.each(function(){E(this)})}})}(jQuery),function(t){t.masksLoad=function(e){var i;return t.ajax({url:e,async:!1,dataType:"json",success:function(t){i=t}}),i},t.masksSort=function(e,i,n,r){return e.sort(function(e,o){for(var s=0,a=0;sc?-1:1;s++,a++}else a++;else s++}for(;s0||i.charAt(r)!=e.replace);r++)i.charAt(r)==e.replace&&o--;for(o=r;r0;r++)i.charAt(r)==e.replace&&s--;return s=r,{begin:o,end:s}},p=function(){t(this).unbind("keypress.inputmask",y).unbind("input.inputmask",C).unbind("paste.inputmask",C).unbind("dragdrop.inputmask",C).unbind("drop.inputmask",C).unbind("keydown.inputmask",b).unbind("setvalue.inputmask",w).unbind("blur.inputmask",x)},g=function(){p.call(this),t(this).bindFirst("keypress.inputmask",y).bindFirst("input.inputmask",C).bindFirst("paste.inputmask",C).bindFirst("dragdrop.inputmask",C).bindFirst("drop.inputmask",C).bindFirst("keydown.inputmask",b).bindFirst("setvalue.inputmask",w).bind("blur.inputmask",x)},v=function(i,r){if(i&&(r||i.mask!=l.mask)){var o;r||(o=d(l.mask,i.mask,n.call(this))),r&&(this._valueSet?this._valueSet(r):this.value=r),t(this).inputmask(i.mask,t.extend(!0,e.inputmask,{insertMode:h})),r||n.call(this,o.begin,o.end)}return l=i,e.onMaskChange.call(this,i.obj,i.determined),!0},m=function(e,i,n){var r=f(i);return r&&r.obj==l.obj&&r.determined==l.determined?!0:(r&&(p.call(this),n?(v.call(this,r),t(this).trigger(e)):(t(this).trigger(e),v.call(this,r)),g.call(this)),e.stopImmediatePropagation(),!1)},b=function(t){t=t||window.event;var i=t.which||t.charCode||t.keyCode;if(8==i||46==i||c&&127==i){var r=this._valueGet(),o=n.call(this);if(o.begin==o.end||!h&&o.begin==o.end-1){var s=o.begin;do{46!=i&&s--;var a=r.charAt(s);r=r.substring(0,s)+r.substring(s+1)}while(s>0&&s0;)t=t.substr(0,t.length-1),e=f(t);v.call(this,e,t),g.call(this)},C=function(t){var e=this;return setTimeout(function(){k.call(e)},0),t.stopImmediatePropagation(),!0};switch(i){case"isCompleted":var _=f(this[0]._valueGet&&this[0]._valueGet()||this[0].value);return _&&_.completed;default:return this.each(function(){k.call(this)}),this}}}(jQuery);