From c9be4f945202b53d59a75f2ed5e9a2894ce483b9 Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sat, 12 Jul 2014 22:31:15 +0200 Subject: [PATCH] Fixed save as file bug --- ...-12-06-35.css => piskel-style-packaged-2014-07-12-09-26.css} | 0 ...-2014-07-12-06-35.js => piskel-packaged-2014-07-12-09-26.js} | 1 - ...4-07-12-06-35.js => piskel-packaged-min-2014-07-12-09-26.js} | 2 +- js/piskel-packaged-min.js | 2 +- piskel-boot-0.1.0.js | 2 +- templates/settings.html | 2 +- 6 files changed, 4 insertions(+), 5 deletions(-) rename css/{piskel-style-packaged-2014-07-12-06-35.css => piskel-style-packaged-2014-07-12-09-26.css} (100%) rename js/{piskel-packaged-2014-07-12-06-35.js => piskel-packaged-2014-07-12-09-26.js} (99%) rename js/{piskel-packaged-min-2014-07-12-06-35.js => piskel-packaged-min-2014-07-12-09-26.js} (93%) diff --git a/css/piskel-style-packaged-2014-07-12-06-35.css b/css/piskel-style-packaged-2014-07-12-09-26.css similarity index 100% rename from css/piskel-style-packaged-2014-07-12-06-35.css rename to css/piskel-style-packaged-2014-07-12-09-26.css diff --git a/js/piskel-packaged-2014-07-12-06-35.js b/js/piskel-packaged-2014-07-12-09-26.js similarity index 99% rename from js/piskel-packaged-2014-07-12-06-35.js rename to js/piskel-packaged-2014-07-12-09-26.js index 3b3c7a7c..deb2fac2 100644 --- a/js/piskel-packaged-2014-07-12-06-35.js +++ b/js/piskel-packaged-2014-07-12-09-26.js @@ -19585,7 +19585,6 @@ zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License ns.SaveController.prototype.saveFile_ = function () { this.beforeSaving_(); - this.saveToFile_(); pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(), function(blob) { pskl.utils.FileUtils.downloadAsFile(blob, this.getLocalFilename_()); this.onSaveSuccess_(); diff --git a/js/piskel-packaged-min-2014-07-12-06-35.js b/js/piskel-packaged-min-2014-07-12-09-26.js similarity index 93% rename from js/piskel-packaged-min-2014-07-12-06-35.js rename to js/piskel-packaged-min-2014-07-12-09-26.js index a3495f01..050fdde2 100644 --- a/js/piskel-packaged-min-2014-07-12-06-35.js +++ b/js/piskel-packaged-min-2014-07-12-09-26.js @@ -8,6 +8,6 @@ h.append(e),c.blob=0===h.getBlob("application/zip").size}catch(f){c.blob=!1}}}}, a.ok?H(a):Cb.addClass("sp-validation-error")}function B(){$?F():C()}function C(){var c=b.Event("beforeShow.spectrum");return $?(O(),void 0):(Nb=I(),sb.trigger(c,[Nb]),Y.beforeShow(Nb)===!1||c.isDefaultPrevented()||(H(Nb),e(),$=!0,b(rb).bind("mousedown.spectrum",D),b(rb).bind("mouseup.spectrum",E),b(a).bind("resize.spectrum",Z),Jb.addClass("sp-active"),ub.removeClass("sp-hidden"),T.showPalette&&w(),O(),L(),x(),Y.show(Nb),sb.trigger("show.spectrum",[Nb])),void 0)}function D(a){var c=b(a.target),d=c.parents(),e=!d.is(ub)&&!c.is(ub);e&&F(a)}function E(a){var b=!u.equals(I(),Nb);b&&(Qb&&"cancel"!==a?N(!0):G())}function F(c){c&&"click"==c.type&&2==c.button||$&&!U&&($=!1,b(rb).unbind("mousedown.spectrum",D),b(rb).unbind("mouseup.spectrum",E),b(a).unbind("resize.spectrum",Z),Jb.removeClass("sp-active"),ub.addClass("sp-hidden"),E(c),t(I()),Y.hide(I()),sb.trigger("hide.spectrum",[I()]))}function G(){H(Nb,!0)}function H(a,b){if(!u.equals(a,I())){var c=u(a),d=c.toHsv();hb=d.h%360/360,ib=d.s,jb=d.v,kb=d.a,L(),c.ok&&!b&&(Pb=Ob||c.format)}}function I(a){return a=a||{},u.fromRatio({h:hb,s:ib,v:jb,a:Math.round(100*kb)/100},{format:a.format||Pb})}function J(){return!Cb.hasClass("sp-validation-error")}function K(){L(),Y.move(I()),sb.trigger("move.spectrum",[I()])}function L(){Cb.removeClass("sp-validation-error"),M();var a=u.fromRatio({h:hb,s:1,v:1});vb.css("background-color",a.toHexString());var b=Pb;1>kb&&("hex"===b||"hex3"===b||"hex6"===b||"name"===b)&&(b="rgb");var c=I({format:b}),d=c.toHexString(),e=c.toRgbString();if(q||1===c.alpha?Lb.css("background-color",e):(Lb.css("background-color","transparent"),Lb.css("filter",c.toFilter())),T.showAlpha){var f=c.toRgb();f.a=0;var g=u(f).toRgbString(),h="linear-gradient(left, "+g+", "+d+")";p?zb.css("filter",u(g).toFilter({gradientType:1},d)):(zb.css("background","-webkit-"+h),zb.css("background","-moz-"+h),zb.css("background","-ms-"+h),zb.css("background",h))}T.showInput&&Cb.val(c.toString(Constants.PREFERRED_COLOR_FORMAT||b)),T.showPalette&&w(),x()}function M(){var a=ib,b=jb,c=a*_,d=ab-b*ab;c=Math.max(-bb/2,Math.min(_-bb/2,c-bb/2)),d=Math.max(-bb/2,Math.min(ab-bb/2,d-bb/2)),wb.css({top:d,left:c});var e=kb*eb;Bb.css({left:e-fb/2});var f=hb*cb;yb.css({top:f-gb/2})}function N(a){var b=I();Hb&&sb.val(b.toString(Pb));var c=!u.equals(b,Nb);Nb=b,a&&c&&(Y.change(b),sb.trigger("change",[b]))}function O(){_=vb.width(),ab=vb.height(),bb=wb.height()+4,db=xb.width(),cb=xb.height(),gb=yb.height()+4,eb=Ab.width(),fb=Bb.width(),U||(ub.css("position","absolute"),ub.offset(h(ub,Kb))),M()}function P(){sb.show(),Kb.unbind("click.spectrum touchstart.spectrum"),ub.remove(),Jb.remove(),o[Rb.id]=null}function Q(a,d){return a===c?b.extend({},T):d===c?T[a]:(T[a]=d,k(),void 0)}function R(){tb=!1,sb.attr("disabled",!1),Kb.removeClass("sp-disabled")}function S(){F(),tb=!0,sb.attr("disabled",!0),Kb.addClass("sp-disabled")}var T=f(i,g),U=T.flat,V=T.showSelectionPalette,W=T.localStorageKey,X=T.theme,Y=T.callbacks,Z=m(O,10),$=!1,_=0,ab=0,bb=0,cb=0,db=0,eb=0,fb=0,gb=0,hb=0,ib=0,jb=0,kb=1,lb=T.palette.slice(0),mb=b.isArray(lb[0])?lb:[lb],nb=T.selectionPalette.slice(0),ob=T.maxSelectionSize,pb="sp-dragging",qb=null,rb=g.ownerDocument,sb=(rb.body,b(g)),tb=!1,ub=b(s,rb).addClass(X),vb=ub.find(".sp-color"),wb=ub.find(".sp-dragger"),xb=ub.find(".sp-hue"),yb=ub.find(".sp-slider"),zb=ub.find(".sp-alpha-inner"),Ab=ub.find(".sp-alpha"),Bb=ub.find(".sp-alpha-handle"),Cb=ub.find(".sp-input"),Db=ub.find(".sp-palette"),Eb=ub.find(".sp-initial"),Fb=ub.find(".sp-cancel"),Gb=ub.find(".sp-choose"),Hb=sb.is("input"),Ib=Hb&&!U,Jb=Ib?b(r).addClass(X).addClass(T.className):b([]),Kb=Ib?Jb:sb,Lb=Jb.find(".sp-preview-inner"),Mb=T.color||Hb&&sb.val(),Nb=!1,Ob=T.preferredFormat,Pb=Ob,Qb=!T.showButtons||T.clickoutFiresChange;n();var Rb={show:C,hide:F,toggle:B,reflow:O,option:Q,enable:R,disable:S,set:function(a){H(a),N()},get:I,destroy:P,container:ub};return Rb.id=o.push(Rb)-1,Rb}function h(a,c){var d=0,e=a.outerWidth(),f=a.outerHeight(),g=c.outerHeight(),h=a[0].ownerDocument,i=h.documentElement,j=i.clientWidth+b(h).scrollLeft(),k=i.clientHeight+b(h).scrollTop(),l=c.offset();return l.top+=g,Math.min(l.left,l.left+e>j&&j>e)?(l.left-=Math.abs(l.left+e-j),a.attr("data-x-position","right")):(l.left-=0,a.attr("data-x-position","left")),Math.min(l.top,l.top+f>k&&k>f)?(l.top-=Math.abs(f+g-d),a.attr("data-y-position","top")):(l.top-=d,a.attr("data-y-position","bottom")),l}function i(){}function j(a){a.stopPropagation()}function k(a,b){var c=Array.prototype.slice,d=c.call(arguments,2);return function(){return a.apply(b,d.concat(c.call(arguments)))}}function l(c,d,e,f){function g(a){a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.returnValue=!1}function h(a){if(l){if(p&&document.documentMode<9&&!a.button)return j();var b=a.originalEvent.touches,e=b?b[0].pageX:a.pageX,f=b?b[0].pageY:a.pageY,h=Math.max(0,Math.min(e-m.left,o)),i=Math.max(0,Math.min(f-m.top,n));q&&g(a),d.apply(c,[h,i,a])}}function i(a){var d=a.which?3==a.which:2==a.button;a.originalEvent.touches,d||l||e.apply(c,arguments)!==!1&&(l=!0,n=b(c).height(),o=b(c).width(),m=b(c).offset(),b(k).bind(r),b(k.body).addClass("sp-dragging"),q||h(a),g(a))}function j(){l&&(b(k).unbind(r),b(k.body).removeClass("sp-dragging"),f.apply(c,arguments)),l=!1}d=d||function(){},e=e||function(){},f=f||function(){};var k=c.ownerDocument||document,l=!1,m={},n=0,o=0,q="ontouchstart"in a,r={};r.selectstart=g,r.dragstart=g,r["touchmove mousemove"]=h,r["touchend mouseup"]=j,b(c).bind("touchstart mousedown",i)}function m(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d),(c||!d)&&(d=setTimeout(g,b))}}var n={beforeShow:i,move:i,change:i,show:i,hide:i,color:!1,flat:!1,showInput:!1,showButtons:!0,clickoutFiresChange:!1,showInitial:!1,showPalette:!1,showPaletteOnly:!1,showSelectionPalette:!0,localStorageKey:!1,appendTo:"body",maxSelectionSize:7,cancelText:"cancel",chooseText:"choose",preferredFormat:!1,className:"",showAlpha:!1,theme:"sp-light",palette:["fff","000"],selectionPalette:[],disabled:!1},o=[],p=!!/msie/i.exec(a.navigator.userAgent),q=function(){function a(a,b){return!!~(""+a).indexOf(b)}var b=document.createElement("div"),c=b.style;return c.cssText="background-color:rgba(0,0,0,.5)",a(c.backgroundColor,"rgba")||a(c.backgroundColor,"hsla")}(),r=["
","
","
","
"].join(""),s=function(){var a="";if(p)for(var b=1;6>=b;b++)a+="
";return["
","
","
","
","
","
","
","
","
","
","
","
","
","
","
","
","
",a,"
","
","
","
","
","","
","
","
","","","
","
","
"].join("")}(),t="spectrum.id";b.fn.spectrum=function(a){if("string"==typeof a){var c=this,d=Array.prototype.slice.call(arguments,1);return this.each(function(){var e=o[b(this).data(t)];if(e){var f=e[a];if(!f)throw new Error("Spectrum: no such method: '"+a+"'");"get"==a?c=e.get():"container"==a?c=e.container:"option"==a?c=e.option.apply(e,d):"destroy"==a?(e.destroy(),b(this).removeData(t)):f.apply(e,d)}}),c}return this.spectrum("destroy").each(function(){var c=g(this,a);b(this).data(t,c.id)})},b.fn.spectrum.load=!0,b.fn.spectrum.loadOpts={},b.fn.spectrum.draggable=l,b.fn.spectrum.defaults=n,b.spectrum={},b.spectrum.localization={},b.spectrum.palettes={},b.fn.spectrum.processNativeColorInputs=function(){var a=b("")[0],c="color"===a.type&&"!"!=a.value;c||b("input[type=color]").spectrum({preferredFormat:"hex6"})},function(){function b(a,d){if(a=a?a:"",d=d||{},"object"==typeof a&&a.hasOwnProperty("_tc_id"))return a;var f=c(a),h=f.r,j=f.g,m=f.b,n=f.a,o=x(100*n)/100,p=d.format||f.format;return 1>h&&(h=x(h)),1>j&&(j=x(j)),1>m&&(m=x(m)),{ok:f.ok,format:p,_tc_id:v++,alpha:n,getAlpha:function(){return n},setAlpha:function(a){n=k(a),o=x(100*n)/100},toHsv:function(){var a=g(h,j,m);return{h:360*a.h,s:a.s,v:a.v,a:n}},toHsvString:function(){var a=g(h,j,m),b=x(360*a.h),c=x(100*a.s),d=x(100*a.v);return 1==n?"hsv("+b+", "+c+"%, "+d+"%)":"hsva("+b+", "+c+"%, "+d+"%, "+o+")"},toHsl:function(){var a=e(h,j,m);return{h:360*a.h,s:a.s,l:a.l,a:n}},toHslString:function(){var a=e(h,j,m),b=x(360*a.h),c=x(100*a.s),d=x(100*a.l);return 1==n?"hsl("+b+", "+c+"%, "+d+"%)":"hsla("+b+", "+c+"%, "+d+"%, "+o+")"},toHex:function(a){return i(h,j,m,a)},toHexString:function(a){return"#"+i(h,j,m,a)},toRgb:function(){return{r:x(h),g:x(j),b:x(m),a:n}},toRgbString:function(){return 1==n?"rgb("+x(h)+", "+x(j)+", "+x(m)+")":"rgba("+x(h)+", "+x(j)+", "+x(m)+", "+o+")"},toPercentageRgb:function(){return{r:x(100*l(h,255))+"%",g:x(100*l(j,255))+"%",b:x(100*l(m,255))+"%",a:n}},toPercentageRgbString:function(){return 1==n?"rgb("+x(100*l(h,255))+"%, "+x(100*l(j,255))+"%, "+x(100*l(m,255))+"%)":"rgba("+x(100*l(h,255))+"%, "+x(100*l(j,255))+"%, "+x(100*l(m,255))+"%, "+o+")"},toName:function(){return 0===n?"transparent":C[i(h,j,m,!0)]||!1},toFilter:function(a){var c=i(h,j,m),e=c,f=Math.round(255*parseFloat(n)).toString(16),g=f,k=d&&d.gradientType?"GradientType = 1, ":"";if(a){var l=b(a);e=l.toHex(),g=Math.round(255*parseFloat(l.alpha)).toString(16)}return"progid:DXImageTransform.Microsoft.gradient("+k+"startColorstr=#"+q(f)+c+",endColorstr=#"+q(g)+e+")"},toString:function(a){var b=!!a;a=a||this.format;var c=!1,d=!b&&1>n&&n>0,e=d&&("hex"===a||"hex6"===a||"hex3"===a||"name"===a);return"rgb"===a&&(c=this.toRgbString()),"prgb"===a&&(c=this.toPercentageRgbString()),("hex"===a||"hex6"===a)&&(c=this.toHexString()),"hex3"===a&&(c=this.toHexString(!0)),"name"===a&&(c=this.toName()),"hsl"===a&&(c=this.toHslString()),"hsv"===a&&(c=this.toHsvString()),e?this.toRgbString():c||this.toHexString()}}}function c(a){var b={r:0,g:0,b:0},c=1,e=!1,g=!1;return"string"==typeof a&&(a=s(a)),"object"==typeof a&&(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b")?(b=d(a.r,a.g,a.b),e=!0,g="%"===String(a.r).substr(-1)?"prgb":"rgb"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")?(a.s=r(a.s),a.v=r(a.v),b=h(a.h,a.s,a.v),e=!0,g="hsv"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=r(a.s),a.l=r(a.l),b=f(a.h,a.s,a.l),e=!0,g="hsl"),a.hasOwnProperty("a")&&(c=a.a)),c=k(c),{ok:e,format:a.format||g,r:y(255,z(b.r,0)),g:y(255,z(b.g,0)),b:y(255,z(b.b,0)),a:c}}function d(a,b,c){return{r:255*l(a,255),g:255*l(b,255),b:255*l(c,255)}}function e(a,b,c){a=l(a,255),b=l(b,255),c=l(c,255);var d,e,f=z(a,b,c),g=y(a,b,c),h=(f+g)/2;if(f==g)d=e=0;else{var i=f-g;switch(e=h>.5?i/(2-f-g):i/(f+g),f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,l:h}}function f(a,b,c){function d(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+6*(b-a)*(2/3-c):a}var e,f,g;if(a=l(a,360),b=l(b,100),c=l(c,100),0===b)e=f=g=c;else{var h=.5>c?c*(1+b):c+b-c*b,i=2*c-h;e=d(i,h,a+1/3),f=d(i,h,a),g=d(i,h,a-1/3)}return{r:255*e,g:255*f,b:255*g}}function g(a,b,c){a=l(a,255),b=l(b,255),c=l(c,255);var d,e,f=z(a,b,c),g=y(a,b,c),h=f,i=f-g;if(e=0===f?0:i/f,f==g)d=0;else{switch(f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,v:h}}function h(a,b,c){a=6*l(a,360),b=l(b,100),c=l(c,100);var d=w.floor(a),e=a-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i=d%6,j=[c,g,f,f,h,c][i],k=[h,c,c,g,f,f][i],m=[f,f,h,c,c,g][i];return{r:255*j,g:255*k,b:255*m}}function i(a,b,c,d){var e=[q(x(a).toString(16)),q(x(b).toString(16)),q(x(c).toString(16))];return d&&e[0].charAt(0)==e[0].charAt(1)&&e[1].charAt(0)==e[1].charAt(1)&&e[2].charAt(0)==e[2].charAt(1)?e[0].charAt(0)+e[1].charAt(0)+e[2].charAt(0):e.join("")}function j(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[a[c]]=c);return b}function k(a){return a=parseFloat(a),(isNaN(a)||0>a||a>1)&&(a=1),a}function l(a,b){o(a)&&(a="100%");var c=p(a);return a=y(b,z(0,parseFloat(a))),c&&(a=parseInt(a*b,10)/100),w.abs(a-b)<1e-6?1:a%b/parseFloat(b)}function m(a){return y(1,z(0,a))}function n(a){return parseInt(a,16)}function o(a){return"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)}function p(a){return"string"==typeof a&&-1!=a.indexOf("%")}function q(a){return 1==a.length?"0"+a:""+a}function r(a){return 1>=a&&(a=100*a+"%"),a}function s(a){a=a.replace(t,"").replace(u,"").toLowerCase();var b=!1;if(B[a])a=B[a],b=!0;else if("transparent"==a)return{r:0,g:0,b:0,a:0,format:"name"};var c;return(c=D.rgb.exec(a))?{r:c[1],g:c[2],b:c[3]}:(c=D.rgba.exec(a))?{r:c[1],g:c[2],b:c[3],a:c[4]}:(c=D.hsl.exec(a))?{h:c[1],s:c[2],l:c[3]}:(c=D.hsla.exec(a))?{h:c[1],s:c[2],l:c[3],a:c[4]}:(c=D.hsv.exec(a))?{h:c[1],s:c[2],v:c[3]}:(c=D.hex6.exec(a))?{r:n(c[1]),g:n(c[2]),b:n(c[3]),format:b?"name":"hex"}:(c=D.hex3.exec(a))?{r:n(c[1]+""+c[1]),g:n(c[2]+""+c[2]),b:n(c[3]+""+c[3]),format:b?"name":"hex"}:!1}var t=/^[\s,#]+/,u=/\s+$/,v=0,w=Math,x=w.round,y=w.min,z=w.max,A=w.random;b.fromRatio=function(a,c){if("object"==typeof a){var d={};for(var e in a)a.hasOwnProperty(e)&&(d[e]="a"===e?a[e]:r(a[e]));a=d}return b(a,c)},b.equals=function(a,c){return a&&c?b(a).toRgbString()==b(c).toRgbString():!1},b.random=function(){return b.fromRatio({r:A(),g:A(),b:A()})},b.desaturate=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.s-=c/100,d.s=m(d.s),b(d)},b.saturate=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.s+=c/100,d.s=m(d.s),b(d)},b.greyscale=function(a){return b.desaturate(a,100)},b.lighten=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.l+=c/100,d.l=m(d.l),b(d)},b.darken=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.l-=c/100,d.l=m(d.l),b(d)},b.complement=function(a){var c=b(a).toHsl();return c.h=(c.h+180)%360,b(c)},b.triad=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+120)%360,s:c.s,l:c.l}),b({h:(d+240)%360,s:c.s,l:c.l})]},b.tetrad=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+90)%360,s:c.s,l:c.l}),b({h:(d+180)%360,s:c.s,l:c.l}),b({h:(d+270)%360,s:c.s,l:c.l})]},b.splitcomplement=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+72)%360,s:c.s,l:c.l}),b({h:(d+216)%360,s:c.s,l:c.l})]},b.analogous=function(a,c,d){c=c||6,d=d||30;var e=b(a).toHsl(),f=360/d,g=[b(a)];for(e.h=(e.h-(f*c>>1)+720)%360;--c;)e.h=(e.h+f)%360,g.push(b(e));return g},b.monochromatic=function(a,c){c=c||6;for(var d=b(a).toHsv(),e=d.h,f=d.s,g=d.v,h=[],i=1/c;c--;)h.push(b({h:e,s:f,v:g})),g=(g+i)%1;return h},b.readability=function(a,c){var d=b(a).toRgb(),e=b(c).toRgb(),f=(299*d.r+587*d.g+114*d.b)/1e3,g=(299*e.r+587*e.g+114*e.b)/1e3,h=Math.max(d.r,e.r)-Math.min(d.r,e.r)+Math.max(d.g,e.g)-Math.min(d.g,e.g)+Math.max(d.b,e.b)-Math.min(d.b,e.b);return{brightness:Math.abs(f-g),color:h}},b.readable=function(a,c){var d=b.readability(a,c);return d.brightness>125&&d.color>500},b.mostReadable=function(a,c){for(var d=null,e=0,f=!1,g=0;g125&&h.color>500,j=3*(h.brightness/125)+h.color/500;(i&&!f||i&&f&&j>e||!i&&!f&&j>e)&&(f=i,e=j,d=b(c[g]))}return d};var B=b.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},C=b.hexNames=j(B),D=function(){var a="[-\\+]?\\d+%?",b="[-\\+]?\\d*\\.\\d+%?",c="(?:"+b+")|(?:"+a+")",d="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?",e="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?";return{rgb:new RegExp("rgb"+d),rgba:new RegExp("rgba"+e),hsl:new RegExp("hsl"+d),hsla:new RegExp("hsla"+e),hsv:new RegExp("hsv"+d),hex3:/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();a.tinycolor=b}();var u=a.tinycolor;b(function(){b.fn.spectrum.load&&b.fn.spectrum.processNativeColorInputs()})}(window,jQuery),function(){var a=$.namespace("pskl.rendering");a.DrawingLoop=function(){this.requestAnimationFrame=this.getRequestAnimationFrameShim_(),this.isRunning=!1,this.previousTime=0,this.callbacks=[]},a.DrawingLoop.prototype.addCallback=function(a,b,c){var d={fn:a,scope:b,args:c};return this.callbacks.push(d),d},a.DrawingLoop.prototype.removeCallback=function(a){var b=this.callbacks.indexOf(a);-1!=b&&this.callbacks.splice(b,1)},a.DrawingLoop.prototype.start=function(){this.isRunning=!0,this.loop_()},a.DrawingLoop.prototype.loop_=function(){var a=Date.now(),b=a-this.previousTime;this.executeCallbacks_(b),this.previousTime=a,this.requestAnimationFrame.call(window,this.loop_.bind(this))},a.DrawingLoop.prototype.executeCallbacks_=function(a){for(var b=0;bd;d++){for(var e=[],f=0;b>f;f++)e.push(Constants.TRANSPARENT_COLOR);c[d]=e}return c},a.Frame.createEmptyFromFrame=function(b){return new a.Frame(b.getWidth(),b.getHeight())},a.Frame.prototype.clone=function(){var b=new a.Frame(this.width,this.height);return b.setPixels(this.getPixels()),b},a.Frame.prototype.getPixels=function(){return this.clonePixels_(this.pixels)},a.Frame.prototype.setPixels=function(a){this.pixels=this.clonePixels_(a),this.version++},a.Frame.prototype.clear=function(){var b=a.Frame.createEmptyPixelGrid_(this.getWidth(),this.getHeight());this.setPixels(b)},a.Frame.prototype.clonePixels_=function(a){for(var b=[],c=0;cd;d++)for(var e=0;c>e;e++)a(this.pixels[d][e],d,e,this)},a.Frame.prototype.getWidth=function(){return this.width},a.Frame.prototype.getHeight=function(){return this.height},a.Frame.prototype.containsPixel=function(a,b){return a>=0&&b>=0&&a0&&a[0].length()>0))throw"Piskel.fromLayers expects array of non empty pskl.model.Layer as first argument";var d=a[0].getFrameAt(0);return c=new pskl.model.Piskel(d.getWidth(),d.getHeight(),b),a.forEach(c.addLayer.bind(c)),c},a.Piskel.prototype.getLayers=function(){return this.layers},a.Piskel.prototype.getHeight=function(){return this.height},a.Piskel.prototype.getWidth=function(){return this.width},a.Piskel.prototype.getLayers=function(){return this.layers},a.Piskel.prototype.getLayerAt=function(a){return this.layers[a]},a.Piskel.prototype.getLayersByName=function(a){return this.layers.filter(function(b){return b.getName()==a})},a.Piskel.prototype.addLayer=function(a){this.layers.push(a)},a.Piskel.prototype.moveLayerUp=function(a){var b=this.layers.indexOf(a);b>-1&&b0&&(this.layers[b]=this.layers[b-1],this.layers[b-1]=a)},a.Piskel.prototype.removeLayer=function(a){var b=this.layers.indexOf(a);-1!=b&&this.layers.splice(b,1)},a.Piskel.prototype.removeLayerAt=function(a){this.layers.splice(a,1)},a.Piskel.prototype.getDescriptor=function(){return this.descriptor},a.Piskel.prototype.setDescriptor=function(a){this.descriptor=a,$(".piskel-name").html(this.descriptor.name)},a.Piskel.prototype.getHash=function(){return this.layers.map(function(a){return a.getHash()}).join("-")}}(),function(){var a=$.namespace("pskl.selection"),b={PASTE:"REPLAY_PASTE",ERASE:"REPLAY_ERASE"};a.SelectionManager=function(a){this.piskelController=a,this.currentSelection=null},a.SelectionManager.prototype.init=function(){$.subscribe(Events.SELECTION_CREATED,$.proxy(this.onSelectionCreated_,this)),$.subscribe(Events.SELECTION_DISMISSED,$.proxy(this.onSelectionDismissed_,this)),$.subscribe(Events.SELECTION_MOVE_REQUEST,$.proxy(this.onSelectionMoved_,this)),pskl.app.shortcutService.addShortcut("ctrl+V",this.paste.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+X",this.cut.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+C",this.copy.bind(this)),pskl.app.shortcutService.addShortcut("del",this.erase.bind(this)),pskl.app.shortcutService.addShortcut("back",this.onBackPressed_.bind(this)),$.subscribe(Events.TOOL_SELECTED,$.proxy(this.onToolSelected_,this))},a.SelectionManager.prototype.cleanSelection_=function(){this.currentSelection&&(this.currentSelection.reset(),this.currentSelection=null)},a.SelectionManager.prototype.onToolSelected_=function(a,b){var c=b instanceof pskl.drawingtools.BaseSelect;c||this.cleanSelection_()},a.SelectionManager.prototype.onSelectionDismissed_=function(){this.cleanSelection_()},a.SelectionManager.prototype.onBackPressed_=function(){return this.currentSelection?(this.erase(),void 0):!0},a.SelectionManager.prototype.erase=function(){for(var a=this.currentSelection.pixels,c=this.piskelController.getCurrentFrame(),d=0,e=a.length;e>d;d++)c.setPixel(a[d].col,a[d].row,Constants.TRANSPARENT_COLOR);$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{type:b.ERASE,pixels:JSON.parse(JSON.stringify(a.slice(0)))}})},a.SelectionManager.prototype.cut=function(){if(!this.currentSelection)throw"Bad state for CUT callback in SelectionManager";this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame()),this.erase()},a.SelectionManager.prototype.paste=function(){if(this.currentSelection&&this.currentSelection.hasPastedContent){var a=this.currentSelection.pixels,b=a.filter(function(a){return a.color!==Constants.TRANSPARENT_COLOR});this.pastePixels(b)}},a.SelectionManager.prototype.pastePixels=function(a){var c=this.piskelController.getCurrentFrame();$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{type:b.PASTE,pixels:JSON.parse(JSON.stringify(a.slice(0)))}}),a.forEach(function(a){c.setPixel(a.col,a.row,a.color)})},a.SelectionManager.prototype.replay=function(a,c){var d=c.pixels;d.forEach(function(d){var e=c.type===b.PASTE?d.color:Constants.TRANSPARENT_COLOR;a.setPixel(d.col,d.row,e)})},a.SelectionManager.prototype.copy=function(){if(!this.currentSelection||!this.piskelController.getCurrentFrame())throw"Bad state for CUT callback in SelectionManager";this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame())},a.SelectionManager.prototype.onSelectionCreated_=function(a,b){if(!b)throw"No selection set in SelectionManager";this.currentSelection=b},a.SelectionManager.prototype.onSelectionMoved_=function(a,b,c){if(!this.currentSelection)throw"Bad state: No currentSelection set when trying to move it in SelectionManager";this.currentSelection.move(b,c)}}(),function(){var a=$.namespace("pskl.selection");a.BaseSelection=function(){this.reset()},a.BaseSelection.prototype.reset=function(){this.pixels=[],this.hasPastedContent=!1},a.BaseSelection.prototype.move=function(a,b){for(var c,d=[],e=0,f=this.pixels.length;f>e;e++)c=this.pixels[e],c.col+=a,c.row+=b,d.push(c);this.pixels=d},a.BaseSelection.prototype.fillSelectionFromFrame=function(a){this.pixels.forEach(function(b){b.color=a.getPixel(b.col,b.row)}),this.hasPastedContent=!0}}(),function(){var a=$.namespace("pskl.selection");a.RectangularSelection=function(a,b,c,d){this.pixels=pskl.PixelUtils.getRectanglePixels(a,b,c,d)},pskl.utils.inherit(a.RectangularSelection,a.BaseSelection)}(),function(){var a=$.namespace("pskl.selection");a.ShapeSelection=function(a){this.pixels=a},pskl.utils.inherit(a.ShapeSelection,a.BaseSelection)}(),function(){var a=$.namespace("pskl.rendering");a.AbstractRenderer=function(){},a.AbstractRenderer.prototype.clear=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.render=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getCoordinates=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setGridWidth=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getGridWidth=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setZoom=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getZoom=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setOffset=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getOffset=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setDisplaySize=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getDisplaySize=Constants.ABSTRACT_FUNCTION}(),function(){var a=$.namespace("pskl.rendering");a.CompositeRenderer=function(){this.renderers=[]},pskl.utils.inherit(pskl.rendering.CompositeRenderer,pskl.rendering.AbstractRenderer),a.CompositeRenderer.prototype.add=function(a){return this.renderers.push(a),this},a.CompositeRenderer.prototype.clear=function(){this.renderers.forEach(function(a){a.clear()})},a.CompositeRenderer.prototype.setZoom=function(a){this.renderers.forEach(function(b){b.setZoom(a) })},a.CompositeRenderer.prototype.getZoom=function(){return this.getSampleRenderer_().getZoom()},a.CompositeRenderer.prototype.setDisplaySize=function(a,b){this.renderers.forEach(function(c){c.setDisplaySize(a,b)})},a.CompositeRenderer.prototype.getDisplaySize=function(){return this.getSampleRenderer_().getDisplaySize()},a.CompositeRenderer.prototype.setOffset=function(a,b){this.renderers.forEach(function(c){c.setOffset(a,b)})},a.CompositeRenderer.prototype.getOffset=function(){return this.getSampleRenderer_().getOffset()},a.CompositeRenderer.prototype.setGridWidth=function(a){this.renderers.forEach(function(b){b.setGridWidth(a)})},a.CompositeRenderer.prototype.getGridWidth=function(){return this.getSampleRenderer_().getGridWidth()},a.CompositeRenderer.prototype.getSampleRenderer_=function(){if(this.renderers.length>0)return this.renderers[0];throw"Renderer manager is empty"}}(),function(){var a=$.namespace("pskl.rendering.layer");a.LayersRenderer=function(a,b,c){pskl.rendering.CompositeRenderer.call(this),this.piskelController=c,this.belowRenderer=new pskl.rendering.frame.FrameRenderer(a,b,["layers-canvas","layers-below-canvas"]),this.aboveRenderer=new pskl.rendering.frame.FrameRenderer(a,b,["layers-canvas","layers-above-canvas"]),this.add(this.belowRenderer),this.add(this.aboveRenderer),this.serializedRendering=""},pskl.utils.inherit(pskl.rendering.layer.LayersRenderer,pskl.rendering.CompositeRenderer),a.LayersRenderer.prototype.render=function(){var a=this.getOffset(),b=this.getDisplaySize(),c=this.piskelController.getLayers(),d=this.piskelController.getCurrentFrameIndex(),e=this.piskelController.getCurrentLayerIndex(),f=[this.getZoom(),this.getGridWidth(),a.x,a.y,b.width,b.height,d,e,c.length].join("-");if(this.serializedRendering!=f){this.serializedRendering=f,this.clear();var g=c.slice(0,e);if(g.length>0){var h=this.getFrameForLayersAt_(d,g);this.belowRenderer.render(h)}var i=c.slice(e+1,c.length);if(i.length>0){var j=this.getFrameForLayersAt_(d,i);this.aboveRenderer.render(j)}}},a.LayersRenderer.prototype.setDisplaySize=function(a,b){var c=this.getDisplaySize();(c.width!==a||c.height!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.LayersRenderer.prototype.getFrameForLayersAt_=function(a,b){var c=b.map(function(b){return b.getFrameAt(a)});return pskl.utils.FrameUtils.merge(c)},a.LayersRenderer.prototype.flush=function(){this.serializedRendering=""}}(),function(){var a=$.namespace("pskl.rendering.frame");a.FrameRenderer=function(a,b,c){if(this.defaultRenderingOptions={supportGridRendering:!1,zoom:1},b=$.extend(!0,{},this.defaultRenderingOptions,b),void 0===a)throw"Bad FrameRenderer initialization. undefined.";if(isNaN(b.zoom))throw"Bad FrameRenderer initialization. not well defined.";this.container=a,this.zoom=b.zoom,this.offset={x:0,y:0},this.margin={x:0,y:0},this.supportGridRendering=b.supportGridRendering,this.classes=c||[],this.classes.push("canvas"),this.canvas=null,this.displayCanvas=null,this.setDisplaySize(b.width,b.height),this.setGridWidth(pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH)),$.subscribe(Events.USER_SETTINGS_CHANGED,this.onUserSettingsChange_.bind(this))},pskl.utils.inherit(pskl.rendering.frame.FrameRenderer,pskl.rendering.AbstractRenderer),a.FrameRenderer.prototype.render=function(a){a&&(this.clear(),this.renderFrame_(a))},a.FrameRenderer.prototype.clear=function(){pskl.CanvasUtils.clear(this.canvas),pskl.CanvasUtils.clear(this.displayCanvas)},a.FrameRenderer.prototype.setZoom=function(a){if(a>Constants.MINIMUM_ZOOM){var b=this.offset.x+this.displayWidth/(2*this.zoom),c=this.offset.y+this.displayHeight/(2*this.zoom);this.zoom=a,this.setOffset(b-this.displayWidth/(2*this.zoom),c-this.displayHeight/(2*this.zoom))}},a.FrameRenderer.prototype.getZoom=function(){return this.zoom},a.FrameRenderer.prototype.setDisplaySize=function(a,b){this.displayWidth=a,this.displayHeight=b,this.displayCanvas&&($(this.displayCanvas).remove(),this.displayCanvas=null),this.createDisplayCanvas_()},a.FrameRenderer.prototype.getDisplaySize=function(){return{height:this.displayHeight,width:this.displayWidth}},a.FrameRenderer.prototype.getOffset=function(){return{x:this.offset.x,y:this.offset.y}},a.FrameRenderer.prototype.setOffset=function(a,b){var c=pskl.app.piskelController.getWidth(),d=pskl.app.piskelController.getHeight(),e=c-this.displayWidth/this.zoom;a=pskl.utils.Math.minmax(a,0,e);var f=d-this.displayHeight/this.zoom;b=pskl.utils.Math.minmax(b,0,f),this.offset.x=a,this.offset.y=b},a.FrameRenderer.prototype.setGridWidth=function(a){this.gridWidth_=a},a.FrameRenderer.prototype.getGridWidth=function(){return this.supportGridRendering?this.gridWidth_:0},a.FrameRenderer.prototype.updateMargins_=function(a){var b=this.displayWidth-this.zoom*a.getWidth();this.margin.x=Math.max(0,b)/2;var c=this.displayHeight-this.zoom*a.getHeight();this.margin.y=Math.max(0,c)/2},a.FrameRenderer.prototype.createDisplayCanvas_=function(){var a=this.displayHeight,b=this.displayWidth;this.displayCanvas=pskl.CanvasUtils.createCanvas(b,a,this.classes),pskl.CanvasUtils.disableImageSmoothing(this.displayCanvas),this.container.append(this.displayCanvas)},a.FrameRenderer.prototype.onUserSettingsChange_=function(a,b,c){b==pskl.UserSettings.GRID_WIDTH&&this.setGridWidth(c)},a.FrameRenderer.prototype.renderPixel_=function(a,b,c,d){a!=Constants.TRANSPARENT_COLOR&&(d.fillStyle=a,d.fillRect(b,c,1,1))},a.FrameRenderer.prototype.getCoordinates=function(a,b){var c=this.container.offset();a-=c.left,b-=c.top,a-=this.margin.x,b-=this.margin.y;var d=this.zoom;return a+=this.offset.x*d,b+=this.offset.y*d,{x:Math.floor(a/d),y:Math.floor(b/d)}},a.FrameRenderer.prototype.renderFrame_=function(a){this.canvas&&a.getWidth()==this.canvas.width&&a.getHeight()==this.canvas.height||(this.canvas=pskl.CanvasUtils.createCanvas(a.getWidth(),a.getHeight()));for(var b=this.canvas.getContext("2d"),c=0,d=a.getWidth();d>c;c++)for(var e=0,f=a.getHeight();f>e;e++){var g=a.getPixel(c,e);this.renderPixel_(g,c,e,b)}this.updateMargins_(a);var h=this.displayCanvas.getContext("2d");h.save(),this.canvas.width*this.zoom0;if(k||i){var l=pskl.utils.ImageResizer.resizeNearestNeighbour(this.canvas,this.zoom,j);h.drawImage(l,0,0)}else h.scale(this.zoom,this.zoom),h.drawImage(this.canvas,0,0);h.restore()}}(),function(){var a=$.namespace("pskl.rendering");a.OnionSkinRenderer=function(a,b,c){pskl.rendering.CompositeRenderer.call(this),this.piskelController=c,this.renderer=new pskl.rendering.frame.FrameRenderer(a,b,["onion-skin-canvas"]),this.add(this.renderer),this.serializedRendering=""},pskl.utils.inherit(pskl.rendering.OnionSkinRenderer,pskl.rendering.CompositeRenderer),a.OnionSkinRenderer.prototype.render=function(){var a=this.getOffset(),b=this.getDisplaySize(),c=this.piskelController.getLayers(),d=this.piskelController.getCurrentFrameIndex(),e=[];this.addFrameAtIndexToArray_(d-1,e),this.addFrameAtIndexToArray_(d+1,e);var f=[this.getZoom(),this.getGridWidth(),a.x,a.y,b.width,b.height,e.map(function(a){return a.getHash()}).join("-"),c.length].join("-");if(this.serializedRendering!=f&&(this.serializedRendering=f,e.length>0)){this.clear();var g=pskl.utils.FrameUtils.merge(e);this.renderer.render(g)}},a.OnionSkinRenderer.prototype.addFrameAtIndexToArray_=function(a,b){var c=this.piskelController.getCurrentLayer();this.piskelController.hasFrameAt(a)&&b.push(c.getFrameAt(a))},a.OnionSkinRenderer.prototype.setDisplaySize=function(a,b){var c=this.getDisplaySize();(c.width!==a||c.height!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.OnionSkinRenderer.prototype.flush=function(){this.serializedRendering=""}}(),function(){var a=$.namespace("pskl.rendering.frame");a.TiledFrameRenderer=function(a,b){this.container=a,this.setZoom(b),this.displayContainer=document.createElement("div"),this.displayContainer.classList.add("tiled-frame-container"),a.get(0).appendChild(this.displayContainer),this.cachedFrameProcessor=new pskl.model.frame.CachedFrameProcessor,this.cachedFrameProcessor.setFrameProcessor(this.frameToDataUrl_.bind(this))},a.TiledFrameRenderer.prototype.frameToDataUrl_=function(a){var b=new pskl.utils.FrameUtils.toImage(a,this.zoom);return b.toDataURL("image/png")},a.TiledFrameRenderer.prototype.render=function(a){var b=this.cachedFrameProcessor.get(a,this.zoom);this.displayContainer.style.backgroundImage="url("+b+")"},a.TiledFrameRenderer.prototype.show=function(){this.displayContainer&&(this.displayContainer.style.display="block")},a.TiledFrameRenderer.prototype.setZoom=function(a){this.zoom=a},a.TiledFrameRenderer.prototype.getZoom=function(){return this.zoom}}(),function(){var a=$.namespace("pskl.rendering.frame");a.CachedFrameRenderer=function(a,b,c){pskl.rendering.frame.FrameRenderer.call(this,a,b,c),this.serializedFrame=""},pskl.utils.inherit(pskl.rendering.frame.CachedFrameRenderer,pskl.rendering.frame.FrameRenderer),a.CachedFrameRenderer.prototype.setDisplaySize=function(a,b){(this.displayWidth!==a||this.displayHeight!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.CachedFrameRenderer.prototype.render=function(a){var b=this.getOffset(),c=this.getDisplaySize(),d=[this.getZoom(),this.getGridWidth(),b.x,b.y,c.width,c.height,a.getHash()].join("-");this.serializedFrame!=d&&(this.serializedFrame=d,this.superclass.render.call(this,a))}}(),function(){var a=$.namespace("pskl.rendering");a.CanvasRenderer=function(a,b){this.frame=a,this.zoom=b,this.transparentColor_="white"},a.CanvasRenderer.prototype.drawTransparentAs=function(a){this.transparentColor_=a},a.CanvasRenderer.prototype.render=function(){var a=this.createCanvas_(),b=a.getContext("2d");this.frame.forEachPixel(function(a,c,d){this.renderPixel_(a,c,d,b)}.bind(this));var c=this.createCanvas_(this.zoom),d=c.getContext("2d");return pskl.CanvasUtils.disableImageSmoothing(c),d.scale(this.zoom,this.zoom),d.drawImage(a,0,0),c},a.CanvasRenderer.prototype.renderPixel_=function(a,b,c,d){a==Constants.TRANSPARENT_COLOR&&(a=this.transparentColor_),d.fillStyle=a,d.fillRect(b,c,1,1)},a.CanvasRenderer.prototype.createCanvas_=function(a){a=a||1;var b=this.frame.getWidth()*a,c=this.frame.getHeight()*a;return pskl.CanvasUtils.createCanvas(b,c)}}(),function(){var a=$.namespace("pskl.rendering");a.FramesheetRenderer=function(a){if(!(a.length>0))throw"FramesheetRenderer : Invalid argument : frames is empty";this.frames=a},a.FramesheetRenderer.prototype.renderAsCanvas=function(){for(var a=this.createCanvas_(),b=0;b=a&&this.currentFrameIndex>0&&this.setCurrentFrameIndex(this.currentFrameIndex-1)},a.PiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.currentFrameIndex)},a.PiskelController.prototype.duplicateFrameAt=function(a){this.getLayers().forEach(function(b){b.duplicateFrameAt(a)})},a.PiskelController.prototype.moveFrame=function(a,b){this.getLayers().forEach(function(c){c.moveFrame(a,b)})},a.PiskelController.prototype.getFrameCount=function(){var a=this.piskel.getLayerAt(0);return a.length()},a.PiskelController.prototype.setCurrentFrameIndex=function(a){this.currentFrameIndex=a},a.PiskelController.prototype.selectNextFrame=function(){var a=this.currentFrameIndex+1;a=0&&this.setCurrentFrameIndex(a)},a.PiskelController.prototype.setCurrentLayerIndex=function(a){this.currentLayerIndex=a},a.PiskelController.prototype.selectLayer=function(a){var b=this.getLayers().indexOf(a);-1!=b&&this.setCurrentLayerIndex(b)},a.PiskelController.prototype.renameLayerAt=function(a,b){var c=this.getLayerByIndex(a);c&&c.setName(b)},a.PiskelController.prototype.getLayerByIndex=function(a){var b=this.getLayers();return b[a]?b[a]:null},a.PiskelController.prototype.generateLayerName_=function(){for(var a="Layer "+this.layerIdCounter;this.hasLayerForName_(a);)this.layerIdCounter++,a="Layer "+this.layerIdCounter;return a},a.PiskelController.prototype.createLayer=function(a){if(a||(a=this.generateLayerName_()),this.hasLayerForName_(a))throw"Layer name should be unique";for(var b=new pskl.model.Layer(a),c=0;c0},a.PiskelController.prototype.moveLayerUp=function(){var a=this.getCurrentLayer();this.piskel.moveLayerUp(a),this.selectLayer(a)},a.PiskelController.prototype.moveLayerDown=function(){var a=this.getCurrentLayer();this.piskel.moveLayerDown(a),this.selectLayer(a)},a.PiskelController.prototype.removeLayerAt=function(a){if(this.getLayers().length>1){var b=this.getLayerAt(a);b&&(this.piskel.removeLayer(b),this.setCurrentLayerIndex(0))}},a.PiskelController.prototype.serialize=function(a){return pskl.utils.Serializer.serializePiskel(this.piskel,a)}}(),function(){var a=$.namespace("pskl.controller.piskel");a.PublicPiskelController=function(a){this.piskelController=a,pskl.utils.wrap(this,this.piskelController)},a.PublicPiskelController.prototype.init=function(){pskl.app.shortcutService.addShortcut("up",this.selectPreviousFrame.bind(this)),pskl.app.shortcutService.addShortcut("down",this.selectNextFrame.bind(this)),pskl.app.shortcutService.addShortcut("n",this.addFrameAtCurrentIndex.bind(this)),pskl.app.shortcutService.addShortcut("shift+n",this.duplicateCurrentFrame.bind(this))},a.PublicPiskelController.prototype.setPiskel=function(a,b){this.piskelController.setPiskel(a,b),$.publish(Events.FRAME_SIZE_CHANGED),$.publish(Events.PISKEL_RESET),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})},a.PublicPiskelController.prototype.addFrame=function(){this.addFrameAt(this.getFrameCount())},a.PublicPiskelController.prototype.addFrameAtCurrentIndex=function(){this.addFrameAt(this.getCurrentFrameIndex())},a.PublicPiskelController.prototype.addFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.addFrameAt,[a]),this.piskelController.addFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.removeFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.removeFrameAt,[a]),this.piskelController.removeFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.getCurrentFrameIndex())},a.PublicPiskelController.prototype.raiseSaveStateEvent_=function(a,b){$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{fn:a,args:b}})},a.PublicPiskelController.prototype.replay=function(a,b){b.fn.apply(this.piskelController,b.args)},a.PublicPiskelController.prototype.duplicateFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.duplicateFrameAt,[a]),this.piskelController.duplicateFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveFrame=function(a,b){this.raiseSaveStateEvent_(this.piskelController.moveFrame,[a,b]),this.piskelController.moveFrame(a,b),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.setCurrentFrameIndex=function(a){this.piskelController.setCurrentFrameIndex(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectNextFrame=function(){this.piskelController.selectNextFrame(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectPreviousFrame=function(){this.piskelController.selectPreviousFrame(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.setCurrentLayerIndex=function(a){this.piskelController.setCurrentLayerIndex(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectLayer=function(a){this.piskelController.selectLayer(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.renameLayerAt=function(a,b){this.raiseSaveStateEvent_(this.piskelController.renameLayerAt,[a,b]),this.piskelController.renameLayerAt(a,b)},a.PublicPiskelController.prototype.createLayer=function(a){this.raiseSaveStateEvent_(this.piskelController.createLayer,[a]),this.piskelController.createLayer(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveLayerUp=function(){this.raiseSaveStateEvent_(this.piskelController.moveLayerUp,[]),this.piskelController.moveLayerUp(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveLayerDown=function(){this.raiseSaveStateEvent_(this.piskelController.moveLayerDown,[]),this.piskelController.moveLayerDown(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.removeCurrentLayer=function(){var a=this.getCurrentLayerIndex();this.raiseSaveStateEvent_(this.piskelController.removeLayerAt,[a]),this.piskelController.removeLayerAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.getCurrentLayerIndex=function(){return this.piskelController.getCurrentLayerIndex()},a.PublicPiskelController.prototype.getCurrentFrameIndex=function(){return this.piskelController.currentFrameIndex},a.PublicPiskelController.prototype.getPiskel=function(){return this.piskelController.piskel}}(),function(){var a=$.namespace("pskl.controller");a.CursorCoordinatesController=function(a){this.piskelController=a,this.origin=null,this.coordinates={x:-1,y:-1}},a.CursorCoordinatesController.prototype.init=function(){this.coordinatesContainer=document.querySelector(".cursor-coordinates"),$.subscribe(Events.CURSOR_MOVED,this.onCursorMoved_.bind(this)),$.subscribe(Events.DRAG_START,this.onDragStart_.bind(this)),$.subscribe(Events.DRAG_END,this.onDragEnd_.bind(this)),$.subscribe(Events.FRAME_SIZE_CHANGED,this.redraw.bind(this)),this.redraw()},a.CursorCoordinatesController.prototype.redraw=function(){var a="";this.origin&&(a+=this.origin.x+":"+this.origin.y+" to ");var b=this.coordinates.x,c=this.coordinates.y,d=this.piskelController.getCurrentFrame();if(d.containsPixel(b,c)&&(a+=b+":"+c,this.origin)){var e=Math.abs(b-this.origin.x)+1,f=Math.abs(c-this.origin.y)+1;a+=" ("+e+"x"+f+")"}this.coordinatesContainer.innerHTML=this.getFrameSizeHTML_()+a},a.CursorCoordinatesController.prototype.getFrameSizeHTML_=function(){var a=this.piskelController.getWidth(),b=this.piskelController.getHeight();return"["+a+"x"+b+"] "},a.CursorCoordinatesController.prototype.onCursorMoved_=function(a,b,c){this.coordinates={x:b,y:c},this.redraw()},a.CursorCoordinatesController.prototype.onDragStart_=function(a,b,c){this.origin={x:b,y:c},this.redraw()},a.CursorCoordinatesController.prototype.onDragEnd_=function(){this.origin=null,this.redraw()}}(),function(){var a=$.namespace("pskl.controller");a.DrawingController=function(a,b,c){this.piskelController=a,this.paletteController=b,this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(a.getCurrentFrame()),this.container=c;var d={zoom:this.calculateZoom_(),supportGridRendering:!0,height:this.getContainerHeight_(),width:this.getContainerWidth_(),xOffset:0,yOffset:0};this.overlayRenderer=new pskl.rendering.frame.CachedFrameRenderer(this.container,d,["canvas-overlay"]),this.renderer=new pskl.rendering.frame.CachedFrameRenderer(this.container,d,["drawing-canvas"]),this.onionSkinRenderer=new pskl.rendering.OnionSkinRenderer(this.container,d,a),this.layersRenderer=new pskl.rendering.layer.LayersRenderer(this.container,d,a),this.compositeRenderer=new pskl.rendering.CompositeRenderer,this.compositeRenderer.add(this.overlayRenderer).add(this.renderer).add(this.layersRenderer).add(this.onionSkinRenderer),this.isClicked=!1,this.previousMousemoveTime=0,this.currentToolBehavior=null,this.currentMouseButton_=Constants.LEFT_BUTTON},a.DrawingController.prototype.init=function(){this.initMouseBehavior(),$.subscribe(Events.TOOL_SELECTED,$.proxy(function(a,b){this.currentToolBehavior=b,this.overlayFrame.clear()},this)),$(window).resize($.proxy(this.startResizeTimer_,this)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this)),$.subscribe(Events.FRAME_SIZE_CHANGED,$.proxy(this.onFrameSizeChanged_,this)),pskl.app.shortcutService.addShortcut("0",this.resetZoom_.bind(this)),pskl.app.shortcutService.addShortcut("+",this.increaseZoom_.bind(this,1)),pskl.app.shortcutService.addShortcut("-",this.decreaseZoom_.bind(this,1)),window.setTimeout(this.afterWindowResize_.bind(this),100)},a.DrawingController.prototype.initMouseBehavior=function(){var a=$("body");this.container.mousedown($.proxy(this.onMousedown_,this)),pskl.utils.UserAgent.isChrome?this.container.on("mousewheel",$.proxy(this.onMousewheel_,this)):this.container.on("wheel",$.proxy(this.onMousewheel_,this)),window.addEventListener("mouseup",this.onMouseup_.bind(this)),window.addEventListener("mousemove",this.onMousemove_.bind(this)),window.addEventListener("keyup",this.onKeyup_.bind(this)),a.contextmenu(this.onCanvasContextMenu_)},a.DrawingController.prototype.startResizeTimer_=function(){this.resizeTimer&&window.clearInterval(this.resizeTimer),this.resizeTimer=window.setTimeout($.proxy(this.afterWindowResize_,this),200)},a.DrawingController.prototype.afterWindowResize_=function(){var a=this.compositeRenderer.getDisplaySize().width;this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.centerColumnWrapperHorizontally_();var b=this.compositeRenderer.getDisplaySize().width/a,c=b*this.compositeRenderer.getZoom();this.compositeRenderer.setZoom(c),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.SHOW_GRID?console.warn("DrawingController:onUserSettingsChange_ not implemented !"):(b==pskl.UserSettings.ONION_SKIN||b==pskl.UserSettings.LAYER_PREVIEW)&&(this.onionSkinRenderer.clear(),this.onionSkinRenderer.flush(),this.layersRenderer.clear(),this.layersRenderer.flush(),this.render())},a.DrawingController.prototype.onFrameSizeChanged_=function(){this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.centerColumnWrapperHorizontally_(),this.compositeRenderer.setZoom(this.calculateZoom_()),this.compositeRenderer.setOffset(0,0),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onMousedown_=function(a){var b=this.piskelController.getCurrentFrame(),c=this.renderer.getCoordinates(a.clientX,a.clientY);a.button===Constants.MIDDLE_BUTTON?b.containsPixel(c.x,c.y)&&$.publish(Events.SELECT_PRIMARY_COLOR,[b.getPixel(c.x,c.y)]):(this.isClicked=!0,this.setCurrentButton(a),this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame),this.currentToolBehavior.applyToolAt(c.x,c.y,this.getCurrentColor_(),b,this.overlayFrame,a))},a.DrawingController.prototype.onMousemove_=function(a){this._clientX=a.clientX,this._clientY=a.clientY;var b=(new Date).getTime();b-this.previousMousemoveTime>Constants.MOUSEMOVE_THROTTLING&&(this.moveTool_(this._clientX,this._clientY,a),this.previousMousemoveTime=b)},a.DrawingController.prototype.resetZoom_=function(){this.setZoom_(this.calculateZoom_())},a.DrawingController.prototype.increaseZoom_=function(a){var b=(a||1)*this.getZoomStep_();this.setZoom_(this.renderer.getZoom()+b)},a.DrawingController.prototype.decreaseZoom_=function(a){var b=(a||1)*this.getZoomStep_();this.setZoom_(this.renderer.getZoom()-b)},a.DrawingController.prototype.getZoomStep_=function(){return this.calculateZoom_()/10},a.DrawingController.prototype.setZoom_=function(a){this.compositeRenderer.setZoom(a),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onKeyup_=function(a){this.moveTool_(this._clientX,this._clientY,a)},a.DrawingController.prototype.moveTool_=function(a,b,c){var d=this.renderer.getCoordinates(a,b),e=this.piskelController.getCurrentFrame();this.isClicked?this.currentToolBehavior.moveToolAt(0|d.x,0|d.y,this.getCurrentColor_(),e,this.overlayFrame,c):this.currentToolBehavior.moveUnactiveToolAt(d.x,d.y,this.getCurrentColor_(),e,this.overlayFrame,c),$.publish(Events.CURSOR_MOVED,[d.x,d.y])},a.DrawingController.prototype.onMousewheel_=function(a){var b=a.originalEvent,c=b.wheelDeltaY||-2*b.deltaY,d=Math.abs(c/120);c>0?this.increaseZoom_(d):0>c&&this.decreaseZoom_(d)},a.DrawingController.prototype.onMouseup_=function(a){if(this.isClicked){this.isClicked=!1,this.setCurrentButton(a);var b=this.renderer.getCoordinates(a.clientX,a.clientY);this.currentToolBehavior.releaseToolAt(b.x,b.y,this.getCurrentColor_(),this.piskelController.getCurrentFrame(),this.overlayFrame,a),$.publish(Events.TOOL_RELEASED)}},a.DrawingController.prototype.getSpriteCoordinates=function(a){return this.renderer.getCoordinates(a.clientX,a.clientY)},a.DrawingController.prototype.setCurrentButton=function(a){this.currentMouseButton_=a.button},a.DrawingController.prototype.getCurrentColor_=function(){return this.currentMouseButton_==Constants.RIGHT_BUTTON?this.paletteController.getSecondaryColor():this.currentMouseButton_==Constants.LEFT_BUTTON?this.paletteController.getPrimaryColor():Constants.DEFAULT_PEN_COLOR},a.DrawingController.prototype.onCanvasContextMenu_=function(a){return $(a.target).closest("#drawing-canvas-container").length?(a.preventDefault(),a.stopPropagation(),a.cancelBubble=!0,!1):void 0},a.DrawingController.prototype.render=function(){var a=this.piskelController.getCurrentFrame();a.isSameSize(this.overlayFrame)||(this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(a)),pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)&&this.onionSkinRenderer.render(),pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW)&&this.layersRenderer.render(),this.renderer.render(a),this.overlayRenderer.render(this.overlayFrame)},a.DrawingController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame().getHeight(),b=this.piskelController.getCurrentFrame().getWidth();return Math.min(this.getAvailableWidth_()/b,this.getAvailableHeight_()/a)},a.DrawingController.prototype.getAvailableHeight_=function(){return $("#main-wrapper").height()},a.DrawingController.prototype.getAvailableWidth_=function(){var a=$(".left-column").outerWidth(!0),b=$(".right-column").outerWidth(!0),c=$("#tool-section").outerWidth(!0),d=$("#application-action-section").outerWidth(!0),e=$("#main-wrapper").width()-a-b-c-d,f=10;return e-f},a.DrawingController.prototype.getContainerHeight_=function(){return this.calculateZoom_()*this.piskelController.getCurrentFrame().getHeight()},a.DrawingController.prototype.getContainerWidth_=function(){return this.calculateZoom_()*this.piskelController.getCurrentFrame().getWidth()},a.DrawingController.prototype.centerColumnWrapperHorizontally_=function(){var a=this.getContainerHeight_(),b=Math.floor(($("#main-wrapper").height()-a)/2);$("#column-wrapper").css({top:b+"px"})},a.DrawingController.prototype.getRenderer=function(){return this.compositeRenderer},a.DrawingController.prototype.setOffset=function(a,b){this.compositeRenderer.setOffset(a,b),$.publish(Events.ZOOM_CHANGED)}}(),function(){var a=$.namespace("pskl.controller"),b={SELECT:"select",CLONE:"clone",DELETE:"delete",NEW_FRAME:"newframe"};a.PreviewFilmController=function(a,b){this.piskelController=a,this.container=b,this.refreshZoom_(),this.redrawFlag=!0,this.cachedFrameProcessor=new pskl.model.frame.CachedFrameProcessor,this.cachedFrameProcessor.setFrameProcessor(this.frameToPreviewCanvas_.bind(this)),this.cachedFrameProcessor.setOutputCloner(this.clonePreviewCanvas_.bind(this))},a.PreviewFilmController.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.flagForRedraw_.bind(this)),$.subscribe(Events.USER_SETTINGS_CHANGED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.refreshZoom_.bind(this)),$("#preview-list-scroller").scroll(this.updateScrollerOverflows.bind(this)),this.container.get(0).addEventListener("click",this.onContainerClick_.bind(this)),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.flagForRedraw_=function(){this.redrawFlag=!0},a.PreviewFilmController.prototype.refreshZoom_=function(){this.zoom=this.calculateZoom_()},a.PreviewFilmController.prototype.render=function(){this.redrawFlag&&(this.createPreviews_(),this.redrawFlag=!1)},a.PreviewFilmController.prototype.updateScrollerOverflows=function(){var a=$("#preview-list-scroller"),b=a.height(),c=a.scrollTop(),d=$("#preview-list").height(),e=$(".top-overflow").height(),f=!1,g=!1;if(d>b){c>e&&(f=!0);var h=d-c-b;h>e&&(g=!0)}var i=$("#preview-list-wrapper");i.toggleClass("top-overflow-visible",f),i.toggleClass("bottom-overflow-visible",g)},a.PreviewFilmController.prototype.onContainerClick_=function(a){var c=pskl.utils.Dom.getParentWithData(a.target,"tileAction");if(c){var d=c.dataset.tileAction,e=parseInt(c.dataset.tileNumber,10);d===b.CLONE?(this.piskelController.duplicateFrameAt(e),this.piskelController.setCurrentFrameIndex(e+1),this.updateScrollerOverflows()):d===b.DELETE?(this.piskelController.removeFrameAt(e),this.updateScrollerOverflows()):d===b.SELECT?this.piskelController.setCurrentFrameIndex(e):d===b.NEW_FRAME&&(this.piskelController.addFrame(),this.piskelController.setCurrentFrameIndex(this.piskelController.getFrameCount()-1),this.updateScrollerOverflows()) }},a.PreviewFilmController.prototype.createPreviews_=function(){this.container.html(""),$(".tooltip").remove();for(var a=this.piskelController.getFrameCount(),c=0,d=a;d>c;c++)this.container.append(this.createPreviewTile_(c));var e=document.createElement("div");e.id="add-frame-action",e.className="add-frame-action",e.setAttribute("data-tile-action",b.NEW_FRAME),e.innerHTML="

Add new frame

",this.container.append(e);var f=a>1;f&&this.initDragndropBehavior_(),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.initDragndropBehavior_=function(){$("#preview-list").sortable({placeholder:"preview-tile-drop-proxy",update:$.proxy(this.onUpdate_,this),items:".preview-tile"}),$("#preview-list").disableSelection()},a.PreviewFilmController.prototype.onUpdate_=function(a,b){var c=parseInt(b.item.data("tile-number"),10),d=$(".preview-tile").index(b.item);this.piskelController.moveFrame(c,d),this.piskelController.setCurrentFrameIndex(d)},a.PreviewFilmController.prototype.createPreviewTile_=function(a){var c=this.piskelController.getCurrentLayer().getFrameAt(a),d=document.createElement("li");d.setAttribute("data-tile-number",a),d.setAttribute("data-tile-action",b.SELECT),d.classList.add("preview-tile"),this.piskelController.getCurrentFrame()==c&&d.classList.add("selected");var e=document.createElement("div");e.classList.add("canvas-container",pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));var f=document.createElement("div");f.className="canvas-background",e.appendChild(f);var g=document.createElement("button");if(g.setAttribute("rel","tooltip"),g.setAttribute("data-placement","right"),g.setAttribute("data-tile-number",a),g.setAttribute("data-tile-action",b.CLONE),g.setAttribute("title","Duplicate this frame"),g.className="tile-overlay duplicate-frame-action",d.appendChild(g),e.appendChild(this.getCanvasForFrame(c)),d.appendChild(e),a>0||this.piskelController.getFrameCount()>1){var h=document.createElement("button");h.setAttribute("rel","tooltip"),h.setAttribute("data-placement","right"),h.setAttribute("title","Delete this frame"),h.setAttribute("data-tile-number",a),h.setAttribute("data-tile-action",b.DELETE),h.className="tile-overlay delete-frame-action",d.appendChild(h);var i=document.createElement("div");i.className="tile-overlay dnd-action",d.appendChild(i)}var j=document.createElement("div");return j.className="tile-overlay tile-count",j.innerHTML=a+1,d.appendChild(j),d},a.PreviewFilmController.prototype.getCanvasForFrame=function(a){var b=this.cachedFrameProcessor.get(a,this.zoom);return b},a.PreviewFilmController.prototype.frameToPreviewCanvas_=function(a){var b=new pskl.rendering.CanvasRenderer(a,this.zoom);b.drawTransparentAs(Constants.TRANSPARENT_COLOR);var c=b.render();return c.classList.add("tile-view","canvas"),c},a.PreviewFilmController.prototype.clonePreviewCanvas_=function(a){var b=pskl.CanvasUtils.clone(a);return b.classList.add("tile-view","canvas"),b},a.PreviewFilmController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame(),b=a.getHeight(),c=a.getWidth();return Math.min(Constants.PREVIEW_FILM_SIZE/b,Constants.PREVIEW_FILM_SIZE/c)}}(),function(){var a=$.namespace("pskl.controller");a.LayersListController=function(a){this.piskelController=a},a.LayersListController.prototype.init=function(){this.layerItemTemplate_=pskl.utils.Template.get("layer-item-template"),this.rootEl=document.querySelector(".layers-list-container"),this.layersListEl=document.querySelector(".layers-list"),this.toggleLayerPreviewEl=document.querySelector(".layers-toggle-preview"),this.rootEl.addEventListener("click",this.onClick_.bind(this)),this.toggleLayerPreviewEl.addEventListener("click",this.toggleLayerPreview_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.renderLayerList_.bind(this)),pskl.app.shortcutService.addShortcut("alt+L",this.toggleLayerPreview_.bind(this)),this.renderLayerList_(),this.updateToggleLayerPreview_(),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this))},a.LayersListController.prototype.renderLayerList_=function(){this.layersListEl.innerHTML="";var a=this.piskelController.getLayers();a.forEach(this.addLayerItem.bind(this))},a.LayersListController.prototype.updateToggleLayerPreview_=function(){var a="layers-toggle-preview-enabled";pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW)?this.toggleLayerPreviewEl.classList.add(a):this.toggleLayerPreviewEl.classList.remove(a)},a.LayersListController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.LAYER_PREVIEW&&this.updateToggleLayerPreview_()},a.LayersListController.prototype.addLayerItem=function(a,b){var c=this.piskelController.getCurrentLayer()===a,d=pskl.utils.Template.replace(this.layerItemTemplate_,{layername:a.getName(),layerindex:b,"isselected:current-layer-item":c}),e=pskl.utils.Template.createFromHTML(d);this.layersListEl.insertBefore(e,this.layersListEl.firstChild)},a.LayersListController.prototype.onClick_=function(a){var b,c=a.target||a.srcElement;c.classList.contains("button")?this.onButtonClick_(c):c.classList.contains("layer-item")?(b=c.dataset.layerIndex,this.piskelController.setCurrentLayerIndex(parseInt(b,10))):c.classList.contains("edit-icon")&&(b=c.parentNode.dataset.layerIndex,this.renameLayerAt_(b))},a.LayersListController.prototype.renameLayerAt_=function(a){var b=this.piskelController.getLayerAt(a),c=window.prompt("Please enter the layer name",b.getName());c&&(this.piskelController.renameLayerAt(a,c),this.renderLayerList_())},a.LayersListController.prototype.onButtonClick_=function(a){var b=a.getAttribute("data-action");"up"==b?this.piskelController.moveLayerUp():"down"==b?this.piskelController.moveLayerDown():"add"==b?this.piskelController.createLayer():"delete"==b&&this.piskelController.removeCurrentLayer()},a.LayersListController.prototype.toggleLayerPreview_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW);pskl.UserSettings.set(pskl.UserSettings.LAYER_PREVIEW,!a)}}(),function(){var a=$.namespace("pskl.controller"),b=200;a.AnimatedPreviewController=function(a,b){this.piskelController=a,this.container=b,this.elapsedTime=0,this.currentIndex=0,this.setFPS(Constants.DEFAULT.FPS),this.piskelController.getCurrentFrame(),this.renderer=new pskl.rendering.frame.TiledFrameRenderer(this.container)},a.AnimatedPreviewController.prototype.init=function(){$("#preview-fps")[0].addEventListener("change",this.onFPSSliderChange.bind(this)),document.querySelector(".right-column").style.width=Constants.ANIMATED_PREVIEW_WIDTH+"px",this.toggleOnionSkinEl=document.querySelector(".preview-toggle-onion-skin"),this.toggleOnionSkinEl.addEventListener("click",this.toggleOnionSkin_.bind(this)),pskl.app.shortcutService.addShortcut("alt+O",this.toggleOnionSkin_.bind(this)),$.subscribe(Events.FRAME_SIZE_CHANGED,this.onFrameSizeChange_.bind(this)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this)),this.updateZoom_(),this.updateOnionSkinPreview_()},a.AnimatedPreviewController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.ONION_SKIN?this.updateOnionSkinPreview_():(this.updateZoom_(),this.updateContainerDimensions_())},a.AnimatedPreviewController.prototype.updateOnionSkinPreview_=function(){var a="preview-toggle-onion-skin-enabled";pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)?this.toggleOnionSkinEl.classList.add(a):this.toggleOnionSkinEl.classList.remove(a)},a.AnimatedPreviewController.prototype.updateZoom_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW),b=a?1:this.calculateZoom_();this.renderer.setZoom(b)},a.AnimatedPreviewController.prototype.getZoom=function(){return this.calculateZoom_()},a.AnimatedPreviewController.prototype.getCoordinates=function(a,b){var c=this.container.offset();a-=c.left,b-=c.top;var d=this.getZoom();return{x:Math.floor(a/d),y:Math.floor(b/d)}},a.AnimatedPreviewController.prototype.onFPSSliderChange=function(){this.setFPS(parseInt($("#preview-fps")[0].value,10))},a.AnimatedPreviewController.prototype.setFPS=function(a){this.fps=a,$("#preview-fps").val(this.fps),$("#display-fps").html(this.fps+" FPS")},a.AnimatedPreviewController.prototype.getFPS=function(){return this.fps},a.AnimatedPreviewController.prototype.render=function(a){this.elapsedTime+=a;var b=Math.floor(this.elapsedTime/(1e3/this.fps));if(b!=this.currentIndex){this.currentIndex=b,this.piskelController.hasFrameAt(this.currentIndex)||(this.currentIndex=0,this.elapsedTime=0);var c=this.piskelController.getFrameAt(this.currentIndex);this.renderer.render(c)}},a.AnimatedPreviewController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame(),b=200,c=b/a.getHeight(),d=b/a.getWidth();return Math.min(c,d)},a.AnimatedPreviewController.prototype.onFrameSizeChange_=function(){this.updateZoom_(),this.updateContainerDimensions_()},a.AnimatedPreviewController.prototype.updateContainerDimensions_=function(){var a,c,d=this.container.get(0),e=pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);if(e)a=b,c=b;else{var f=this.getZoom(),g=this.piskelController.getCurrentFrame();a=g.getHeight()*f,c=g.getWidth()*f}d.style.height=a+"px",d.style.width=c+"px",d.style.marginTop=(b-a)/2+"px",d.style.marginBottom=(b-a)/2+"px",d.style.marginLeft=(b-c)/2+"px",d.style.marginRight=(b-c)/2+"px"},a.AnimatedPreviewController.prototype.toggleOnionSkin_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN);pskl.UserSettings.set(pskl.UserSettings.ONION_SKIN,!a)}}(),function(){var a=$.namespace("pskl.controller");a.MinimapController=function(a,b,c,d){this.piskelController=a,this.animationController=b,this.drawingController=c,this.container=d,this.isClicked=!1},a.MinimapController.prototype.init=function(){this.cropFrame=document.createElement("DIV"),this.cropFrame.className="minimap-crop-frame",this.cropFrame.style.display="none",$(this.container).append(this.cropFrame),$(this.container).mousedown(this.onMinimapMousedown_.bind(this)),$("body").mousemove(this.onMinimapMousemove_.bind(this)),$("body").mouseup(this.onMinimapMouseup_.bind(this)),$.subscribe(Events.ZOOM_CHANGED,$.proxy(this.renderMinimap_,this))},a.MinimapController.prototype.renderMinimap_=function(){var a=this.getDrawingAreaZoomRatio_();a>1?this.displayCropFrame_(a,this.drawingController.getRenderer().getOffset()):this.hideCropFrame_()},a.MinimapController.prototype.displayCropFrame_=function(a,b){this.cropFrame.style.display="block",this.cropFrame.style.top=b.y*this.animationController.getZoom()+"px",this.cropFrame.style.left=b.x*this.animationController.getZoom()+"px";var c=this.getDrawingAreaZoomRatio_();this.cropFrame.style.width=this.container.width()/c+"px",this.cropFrame.style.height=this.container.height()/c+"px"},a.MinimapController.prototype.hideCropFrame_=function(){this.cropFrame.style.display="none"},a.MinimapController.prototype.onMinimapMousemove_=function(a){if(this.isClicked&&this.getDrawingAreaZoomRatio_()>1){var b=this.getCoordinatesCenteredAround_(a.clientX,a.clientY);this.drawingController.setOffset(b.x,b.y)}},a.MinimapController.prototype.onMinimapMousedown_=function(){this.isClicked=!0},a.MinimapController.prototype.onMinimapMouseup_=function(){this.isClicked=!1},a.MinimapController.prototype.getCoordinatesCenteredAround_=function(a,b){var c=this.animationController.getCoordinates(a,b),d=this.getDrawingAreaZoomRatio_(),e=this.piskelController.getCurrentFrame().getWidth(),f=this.piskelController.getCurrentFrame().getHeight(),g=e/d,h=f/d;return{x:c.x-g/2,y:c.y-h/2}},a.MinimapController.prototype.getDrawingAreaZoomRatio_=function(){var a=this.drawingController.getRenderer().getZoom(),b=this.piskelController.getCurrentFrame().getHeight()*a,c=b/this.drawingController.getRenderer().getDisplaySize().height;return c}}(),function(){var a=$.namespace("pskl.controller");a.ToolController=function(){var a=function(a,b,c){return{id:a,shortcut:b,instance:c}};this.tools=[a("simplePen","P",new pskl.drawingtools.SimplePen),a("verticalMirrorPen","V",new pskl.drawingtools.VerticalMirrorPen),a("paintBucket","B",new pskl.drawingtools.PaintBucket),a("colorSwap","A",new pskl.drawingtools.ColorSwap),a("eraser","E",new pskl.drawingtools.Eraser),a("stroke","L",new pskl.drawingtools.Stroke),a("rectangle","R",new pskl.drawingtools.Rectangle),a("circle","C",new pskl.drawingtools.Circle),a("move","M",new pskl.drawingtools.Move),a("rectangleSelect","S",new pskl.drawingtools.RectangleSelect),a("shapeSelect","Z",new pskl.drawingtools.ShapeSelect),a("lighten","U",new pskl.drawingtools.Lighten),a("colorPicker","O",new pskl.drawingtools.ColorPicker)],this.currentSelectedTool=this.tools[0],this.previousSelectedTool=this.tools[0]},a.ToolController.prototype.init=function(){this.createToolsDom_(),this.addKeyboardShortcuts_(),this.selectTool_(this.tools[0]),$("#tool-section").mousedown($.proxy(this.onToolIconClicked_,this))},a.ToolController.prototype.activateToolOnStage_=function(a){var b=$("body"),c=b.data("selected-tool-class");c&&(b.removeClass(c),b.removeClass(pskl.drawingtools.Move.TOOL_ID)),b.addClass(a.instance.toolId),b.data("selected-tool-class",a.instance.toolId)},a.ToolController.prototype.selectTool_=function(a){this.currentSelectedTool=a,this.activateToolOnStage_(this.currentSelectedTool);var b=$("#tool-section .tool-icon.selected"),c=$("[data-tool-id="+a.instance.toolId+"]");b.removeClass("selected"),c.addClass("selected"),$.publish(Events.TOOL_SELECTED,[a.instance])},a.ToolController.prototype.onToolIconClicked_=function(a){var b=$(a.target),c=b.closest(".tool-icon");if(c.length){var d=c.data().toolId,e=this.getToolById_(d);e&&this.selectTool_(e)}},a.ToolController.prototype.onKeyboardShortcut_=function(a){for(var b=0;b{{name}}',a)}).join("");this.paletteListOptGroup_.innerHTML=b},a.PalettesListController.prototype.fillColorListContainer=function(){var a=this.getSelectedPaletteColors_(),b=a.map(function(a){return pskl.utils.Template.replace(this.paletteColorTemplate_,{color:a})}.bind(this)).join("");this.colorListContainer_.innerHTML=b,this.highlightSelectedColors();var c=a.length>e;c&&!pskl.utils.UserAgent.isChrome?this.colorListContainer_.classList.add(d):this.colorListContainer_.classList.remove(d)},a.PalettesListController.prototype.getSelectedPaletteColors_=function(){var a=[],b=this.colorPaletteSelect_.value;if(b===Constants.CURRENT_COLORS_PALETTE_ID)a=this.usedColorService.getCurrentColors();else{var c=this.getPaletteById(b,this.retrievePalettes());c&&(a=c.colors)}return a.length>Constants.MAX_CURRENT_COLORS_DISPLAYED&&(a=a.slice(0,Constants.MAX_CURRENT_COLORS_DISPLAYED)),a},a.PalettesListController.prototype.selectPalette=function(a){this.colorPaletteSelect_.value=a},a.PalettesListController.prototype.selectPaletteFromUserSettings=function(){this.selectPalette(pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE))},a.PalettesListController.prototype.onPaletteSelected_=function(){var a=this.colorPaletteSelect_.value;a===Constants.MANAGE_PALETTE_ID?($.publish(Events.DIALOG_DISPLAY,"manage-palettes"),this.selectPaletteFromUserSettings()):pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE,a),this.fillColorListContainer()},a.PalettesListController.prototype.onColorContainerContextMenu=function(a){a.preventDefault()},a.PalettesListController.prototype.onColorContainerMouseup=function(a){var b=a.target,c=b.dataset.color;c&&(a.button==Constants.LEFT_BUTTON?$.publish(Events.SELECT_PRIMARY_COLOR,[c]):a.button==Constants.RIGHT_BUTTON&&$.publish(Events.SELECT_SECONDARY_COLOR,[c]))},a.PalettesListController.prototype.highlightSelectedColors=function(){this.removeClass_(b),this.removeClass_(c);var a=this.getColorContainer_(this.paletteController.getSecondaryColor());a&&(a.classList.remove(b),a.classList.add(c)),a=this.getColorContainer_(this.paletteController.getPrimaryColor()),a&&(a.classList.remove(c),a.classList.add(b))},a.PalettesListController.prototype.getColorContainer_=function(a){return this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+a+'"]')},a.PalettesListController.prototype.removeClass_=function(a){var b=document.querySelector("."+a);b&&b.classList.remove(a)},a.PalettesListController.prototype.onPaletteListUpdated=function(){this.fillPaletteList(),this.selectPaletteFromUserSettings(),this.fillColorListContainer()},a.PalettesListController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PalettesListController.prototype.retrievePalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller");a.NotificationController=function(){},a.NotificationController.prototype.init=function(){$.subscribe(Events.SHOW_NOTIFICATION,$.proxy(this.displayMessage_,this)),$.subscribe(Events.HIDE_NOTIFICATION,$.proxy(this.removeMessage_,this))},a.NotificationController.prototype.displayMessage_=function(a,b){this.removeMessage_();var c=document.createElement("div");c.id="user-message",c.className="user-message",c.innerHTML=b.content,c.innerHTML=c.innerHTML+"
x
",document.body.appendChild(c),$(c).find(".close").click($.proxy(this.removeMessage_,this)),b.behavior&&b.behavior(c)},a.NotificationController.prototype.removeMessage_=function(){var a=$("#user-message");a.length&&a.remove()}}(),function(){var a=$.namespace("pskl.controller");a.CanvasBackgroundController=function(){this.body=document.body},a.CanvasBackgroundController.prototype.init=function(){$.subscribe(Events.USER_SETTINGS_CHANGED,this.onUserSettingsChange_.bind(this)),this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND))},a.CanvasBackgroundController.prototype.onUserSettingsChange_=function(a,b,c){b==pskl.UserSettings.CANVAS_BACKGROUND&&this.updateBackgroundClass_(c)},a.CanvasBackgroundController.prototype.updateBackgroundClass_=function(a){var b=this.body.dataset.currentBackgroundClass;b&&this.body.classList.remove(b),this.body.classList.add(a),this.body.dataset.currentBackgroundClass=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.ApplicationSettingsController=function(){},a.ApplicationSettingsController.prototype.init=function(){var a=pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND);$("#background-picker-wrapper").find(".background-picker[data-background-class="+a+"]").addClass("selected");var b=pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH);$("#grid-width").val(b),$("#grid-width").change(this.onGridWidthChange.bind(this)),$("#background-picker-wrapper").click(this.onBackgroundClick.bind(this))},a.ApplicationSettingsController.prototype.onGridWidthChange=function(){var a=$("#grid-width").val();pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH,parseInt(a,10))},a.ApplicationSettingsController.prototype.onBackgroundClick=function(a){var b=$(a.target).closest(".background-picker");if(b.length){var c=b.data("background-class");pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND,c),$(".background-picker").removeClass("selected"),b.addClass("selected")}}}(),function(){var a=$.namespace("pskl.controller.settings");a.ResizeController=function(a){this.piskelController=a},a.ResizeController.prototype.init=function(){this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.resizeWidth.val(this.piskelController.getWidth()),this.resizeHeight.val(this.piskelController.getHeight()),this.cancelButton=$(".resize-cancel-button"),this.cancelButton.click(this.onCancelButtonClicked_.bind(this)),this.resizeForm=$("[name=resize-form]"),this.resizeForm.submit(this.onResizeFormSubmit_.bind(this)),this.resizeContentCheckbox=$(".resize-content-checkbox")},a.ResizeController.prototype.onResizeFormSubmit_=function(a){a.originalEvent.preventDefault(),parseInt(this.resizeWidth.val(),10),parseInt(this.resizeHeight.val(),10),this.isResizeContentEnabled_();var b=this.piskelController.getLayers().map(this.resizeLayer_.bind(this)),c=pskl.model.Piskel.fromLayers(b,this.piskelController.getPiskel().getDescriptor());pskl.app.piskelController.setPiskel(c,!0),$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ResizeController.prototype.resizeLayer_=function(a){var b=a.getFrames().map(this.resizeFrame_.bind(this));return pskl.model.Layer.fromFrames(a.getName(),b)},a.ResizeController.prototype.resizeFrame_=function(a){var b,c=parseInt(this.resizeWidth.val(),10),d=parseInt(this.resizeHeight.val(),10);return this.isResizeContentEnabled_()?b=pskl.utils.FrameUtils.resize(a,c,d,!1):(b=new pskl.model.Frame(c,d),a.forEachPixel(function(a,c,d){c"},a.GifExportController.prototype.getSelectedZoom_=function(){return this.selectResolutionEl.value},a.GifExportController.prototype.createOptionElements_=function(){for(var b=a.GifExportController.RESOLUTIONS,c=0;ce,g=new window.GIF({workers:2,quality:1,width:this.piskelController.getWidth()*a,height:this.piskelController.getHeight()*a,preserveColors:f}),h=0;hb){var d=Math.round((b-c.length)/2),e=a.substring(0,d),f=a.substring(a.length-d,a.length);a=e+c+f}return a}}(),function(){var a=$.namespace("pskl.controller.settings"),b=60;a.PngExportController=function(a){this.piskelController=a},a.PngExportController.prototype.init=function(){this.previewContainerEl=document.querySelectorAll(".png-export-preview")[0],document.querySelector(".png-download-button").addEventListener("click",this.onPngDownloadButtonClick_.bind(this)),document.querySelector(".zip-generate-button").addEventListener("click",this.onZipButtonClick_.bind(this)),this.updatePreview_(this.getFramesheetAsCanvas().toDataURL("image/png")),new a.GifExportController(this.piskelController).init()},a.PngExportController.prototype.onPngDownloadButtonClick_=function(){var a=this.getPiskelName_()+".png";pskl.utils.BlobUtils.canvasToBlob(this.getFramesheetAsCanvas(),function(b){pskl.utils.FileUtils.downloadAsFile(b,a)})},a.PngExportController.prototype.onZipButtonClick_=function(){for(var a=new window.JSZip,b=0;b"},a.PngExportController.prototype.shorten_=function(a,b,c){return a.length>b&&(a=a.substring(0,b),a+=c),a}}(),function(){var a=$.namespace("pskl.controller.settings");a.LocalStorageController=function(){},a.LocalStorageController.prototype.init=function(){this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillRestoreSession_(),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.LocalStorageController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),$.publish(Events.CLOSE_SETTINGS_DRAWER)):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.LocalStorageController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:this.formatDate_(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.LocalStorageController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))};var b=function(a){return 10>a?"0"+a:""+a};a.LocalStorageController.prototype.formatDate_=function(a,c){a=new Date(a);var d=pskl.utils.Template.replace(c,{Y:a.getFullYear(),M:b(a.getMonth()+1),D:b(a.getDate()),H:b(a.getHours()),m:b(a.getMinutes())});return d},a.LocalStorageController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=this.formatDate_(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.SaveController=function(a){this.piskelController=a},a.SaveController.prototype.init=function(){this.saveForm=$("form[name=save-form]"),this.nameInput=$("#save-name"),this.descriptionInput=$("#save-description"),this.isPublicCheckbox=$("input[name=save-public-checkbox]"),this.saveOnlineButton=$("#save-online-button"),this.saveLocalButton=$("#save-browser-button"),this.saveFileButton=$("#save-file-button"),this.piskelName=$(".piskel-name").get(0),this.saveOnlineStatus=$("#save-online-status"),this.saveFileStatus=$("#save-file-status"),this.timestamp=new Date;var a=this.piskelController.getPiskel().getDescriptor();this.nameInput.val(a.name),this.descriptionInput.val(a.description),this.isPublicCheckbox.prop("checked",a.isPublic),this.saveFileButton.click(this.saveFile_.bind(this)),this.saveLocalButton.click(this.saveLocal_.bind(this)),this.saveOnlineButton.click(this.saveOnline_.bind(this)),this.saveForm.submit(this.onSaveFormSubmit_.bind(this)),this.nameInput.keyup(this.updateLocalStatusFilename_.bind(this)),pskl.app.isLoggedIn()||(this.saveOnlineButton.hide(),$(".save-public-section").hide(),this.saveOnlineStatus.html(pskl.utils.Template.get("save-please-login-partial")),this.saveFileButton.get(0).classList.add("button-primary")),this.updateLocalStatusFilename_()},a.SaveController.prototype.updateLocalStatusFilename_=function(){this.saveFileStatus.html(pskl.utils.Template.getAndReplace("save-file-status-template",{name:this.getLocalFilename_()}))},a.SaveController.prototype.getLocalFilename_=function(){var a=this.getName(),b=pskl.utils.DateUtils.format(this.timestamp,"{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}");return a+"-"+b+".piskel"},a.SaveController.prototype.onSaveFormSubmit_=function(a){a.preventDefault(),a.stopPropagation(),pskl.app.isLoggedIn()?this.saveOnline_():this.saveLocal_()},a.SaveController.prototype.saveOnline_=function(){var a=this.getName();if(a||(a=window.prompt("Please specify a name","New piskel")),a){var b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d),this.beforeSaving_(),pskl.app.storageService.store({success:this.onSaveSuccess_.bind(this),error:this.onSaveError_.bind(this),after:this.afterSaving_.bind(this)})}},a.SaveController.prototype.saveLocal_=function(){var a=pskl.app.localStorageService,b=!0,c=this.getName(),d=this.getDescription();a.getPiskel(c)&&(b=window.confirm("There is already a piskel saved as "+c+". Override ?")),b&&(this.beforeSaving_(),a.save(c,d,pskl.app.piskelController.serialize()),window.setTimeout(function(){this.onSaveSuccess_(),this.afterSaving_()}.bind(this),500))},a.SaveController.prototype.saveFile_=function(){this.beforeSaving_(),this.saveToFile_(),pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(),function(a){pskl.utils.FileUtils.downloadAsFile(a,this.getLocalFilename_()),this.onSaveSuccess_(),this.afterSaving_()}.bind(this),"application/piskel+json")},a.SaveController.prototype.getName=function(){return this.nameInput.val()},a.SaveController.prototype.getDescription=function(){return this.descriptionInput.val()},a.SaveController.prototype.beforeSaving_=function(){this.updatePiskelDescriptor_(),this.saveOnlineButton.attr("disabled",!0),this.saveOnlineStatus.html("Saving ..."),this.piskelName&&this.piskelName.classList.add("piskel-name-saving")},a.SaveController.prototype.updatePiskelDescriptor_=function(){var a=this.getName(),b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d)},a.SaveController.prototype.onSaveSuccess_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER),$.publish(Events.SHOW_NOTIFICATION,[{content:"Successfully saved !"}]),$.publish(Events.PISKEL_SAVED)},a.SaveController.prototype.onSaveError_=function(a){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+a+")"}])},a.SaveController.prototype.afterSaving_=function(){this.saveOnlineButton.attr("disabled",!1),this.saveOnlineStatus.html(""),this.piskelName&&this.piskelName.classList.remove("piskel-name-saving"),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)}}(),function(){var a=$.namespace("pskl.controller.settings");a.ImportController=function(a){this.piskelController=a,this.importedImage_=null},a.ImportController.prototype.init=function(){this.hiddenOpenPiskelInput=$("[name=open-piskel-input]"),this.openPiskelInputButton=$(".open-piskel-button"),this.hiddenFileInput=$("[name=file-upload-input]"),this.fileInputButton=$(".file-input-button"),this.browseLocalButton=document.querySelector(".browse-local-button"),this.browseLocalButton.addEventListener("click",this.onBrowseLocalClick_.bind(this)),this.hiddenFileInput.change(this.onFileUploadChange_.bind(this)),this.fileInputButton.click(this.onFileInputClick_.bind(this)),this.hiddenOpenPiskelInput.change(this.onOpenPiskelChange_.bind(this)),this.openPiskelInputButton.click(this.onOpenPiskelClick_.bind(this)),this.prevSessionContainer=$(".previous-session"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.fillRestoreSession_()},a.ImportController.prototype.closeDrawer_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ImportController.prototype.onFileUploadChange_=function(){this.importPictureFromFile_()},a.ImportController.prototype.onFileInputClick_=function(){this.hiddenFileInput.click()},a.ImportController.prototype.onOpenPiskelChange_=function(){this.openPiskelFile_()},a.ImportController.prototype.onOpenPiskelClick_=function(){this.hiddenOpenPiskelInput.click()},a.ImportController.prototype.onBrowseLocalClick_=function(){$.publish(Events.DIALOG_DISPLAY,"browse-local"),this.closeDrawer_()},a.ImportController.prototype.openPiskelFile_=function(){var a=this.hiddenOpenPiskelInput.get(0).files;if(1==a.length){var b=a[0];this.isPiskel_(b)&&(pskl.utils.PiskelFileUtils.loadFromFile(b,function(a,b,c){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)}),this.closeDrawer_())}},a.ImportController.prototype.importPictureFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length){var b=a[0];if(!this.isImage_(b))throw this.closeDrawer_(),"File is not an image : "+b.type;$.publish(Events.DIALOG_DISPLAY,{dialogId:"import-image",initArgs:b}),this.closeDrawer_()}},a.ImportController.prototype.enableDisabledSections_=function(){this.fileInputButton.removeClass("button-primary"),this.fileInputButton.blur(),$(".import-options").show()},a.ImportController.prototype.isImage_=function(a){return 0===a.type.indexOf("image")},a.ImportController.prototype.isPiskel_=function(a){return/\.piskel$/.test(a.name)},a.ImportController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:pskl.utils.DateUtils.format(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.ImportController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))}}(),function(){var a=$.namespace("pskl.controller.settings"),b={user:{template:"templates/settings/application.html",controller:a.ApplicationSettingsController},resize:{template:"templates/settings/resize.html",controller:a.ResizeController},png:{template:"templates/settings/export.html",controller:a.PngExportController},"import":{template:"templates/settings/import.html",controller:a.ImportController},localstorage:{template:"templates/settings/localstorage.html",controller:a.LocalStorageController},save:{template:"templates/settings/save.html",controller:a.SaveController}},c="has-expanded-drawer",d="expanded";a.SettingsController=function(a){this.piskelController=a,this.drawerContainer=document.getElementById("drawer-container"),this.settingsContainer=$("[data-pskl-controller=settings]"),this.isExpanded=!1,this.currentSetting=null},a.SettingsController.prototype.init=function(){$("[data-setting]").click(this.onSettingIconClick.bind(this)),$("body").click(this.onBodyClick.bind(this)),$.subscribe(Events.CLOSE_SETTINGS_DRAWER,this.closeDrawer.bind(this))},a.SettingsController.prototype.onSettingIconClick=function(a){var b=a.originalEvent.currentTarget,c=b.getAttribute("data-setting");this.currentSetting!=c?this.loadSetting(c):this.closeDrawer(),a.originalEvent.stopPropagation(),a.originalEvent.preventDefault()},a.SettingsController.prototype.onBodyClick=function(a){var b=a.target,c=pskl.utils.Dom.isParent(b,this.drawerContainer),d=b.getAttribute("data-setting"),e=c||d;this.isExpanded&&!e&&this.closeDrawer()},a.SettingsController.prototype.loadSetting=function(a){this.drawerContainer.innerHTML=pskl.utils.Template.get(b[a].template),new b[a].controller(this.piskelController).init(),this.settingsContainer.addClass(d),$("."+c).removeClass(c),$("[data-setting="+a+"]").addClass(c),this.isExpanded=!0,this.currentSetting=a},a.SettingsController.prototype.closeDrawer=function(){this.settingsContainer.removeClass(d),$("."+c).removeClass(c),this.isExpanded=!1,this.currentSetting=null,document.activeElement.blur()}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.AbstractDialogController=function(){},a.AbstractDialogController.prototype.init=function(){this.closeButton=document.querySelector(".dialog-close"),this.closeButton.addEventListener("click",this.closeDialog.bind(this))},a.AbstractDialogController.prototype.destroy=function(){},a.AbstractDialogController.prototype.closeDialog=function(){$.publish(Events.DIALOG_HIDE)}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=window.tinycolor,c="selected",d="palette-manager-new-color",e="palette-manager-delete-card",f="edit-icon";a.PaletteManagerController=function(a){this.piskelController=a,this.palettes=this.retrieveUserPalettes(),this.originalPalettes=this.retrieveUserPalettes(),this.selectedPaletteId=null,this.spectrumContainers=[]},pskl.utils.inherit(a.PaletteManagerController,a.AbstractDialogController),a.PaletteManagerController.prototype.init=function(){this.superclass.init.call(this),this.palettesList=document.querySelector(".palette-manager-list"),this.paletteBody=document.querySelector(".palette-manager-details-body"),this.paletteHead=document.querySelector(".palette-manager-details-head"),this.createButton=document.querySelector('.palette-manager-actions-button[data-action="create"]'),this.saveAllButton=document.querySelector('.palette-manager-actions-button[data-action="save-all"]'),this.colorCardTemplate=pskl.utils.Template.get("palette-color-card-template"),this.newColorTemplate=pskl.utils.Template.get("palette-new-color-template"),this.paletteHeadTemplate=pskl.utils.Template.get("palette-details-head-template"),this.palettesList.addEventListener("click",this.onPaletteListClick.bind(this)),this.paletteBody.addEventListener("click",this.delegatedPaletteBodyClick.bind(this)),this.paletteHead.addEventListener("click",this.delegatedPaletteHeadClick.bind(this)),this.createButton.addEventListener("click",this.onCreateClick_.bind(this)),this.saveAllButton.addEventListener("click",this.saveAll.bind(this)),this.createPaletteListMarkup(),this.palettes.length>0?this.selectPalette(this.palettes[0].id):this.createPalette("New palette")},a.PaletteManagerController.prototype.destroy=function(){this.destroySpectrumPickers()},a.PaletteManagerController.prototype.onCreateClick_=function(){this.createPalette()},a.PaletteManagerController.prototype.createPalette=function(a){if(a||(a=window.prompt("Please enter a name for your palette","New palette")),a){var b=this.createPaletteObject(a);this.palettes.push(b),this.createPaletteListMarkup(),this.selectPalette(b.id)}},a.PaletteManagerController.prototype.createPaletteObject=function(a){return{id:"palette-"+Date.now()+"-"+Math.floor(1e3*Math.random()),name:a,colors:[]}},a.PaletteManagerController.prototype.redraw=function(){this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.selectPalette=function(a){this.deselectCurrentPalette();var b=this.palettesList.querySelector("[data-palette-id="+a+"]");b&&(this.selectedPaletteId=a,b.classList.add(c),this.refreshPaletteDetails())},a.PaletteManagerController.prototype.refreshPaletteDetails=function(){this.createPaletteHeadMarkup(),this.createPaletteBodyMarkup(),this.initPaletteDetailsEvents(),this.initPaletteCardsSpectrum()},a.PaletteManagerController.prototype.createPaletteListMarkup=function(){var a=this.palettes.map(function(a){var b={id:a.id,name:this.isPaletteModified(a)?a.name+" *":a.name};return pskl.utils.Template.replace('
  • {{name}}
  • ',b)}.bind(this)).join("");this.palettesList.innerHTML=a},a.PaletteManagerController.prototype.createPaletteHeadMarkup=function(){var a=this.getSelectedPalette(),b={name:a.name,"save:disabled":!this.isPaletteModified(a),"revert:disabled":!this.isPaletteModified(a),"delete:disabled":this.palettes.length<2},c=pskl.utils.Template.replace(this.paletteHeadTemplate,b);this.paletteHead.innerHTML=c},a.PaletteManagerController.prototype.isPaletteModified=function(a){var b=!1,c=this.getPaletteById(a.id,this.originalPalettes);if(c){var d=c.name!==a.name,e=a.colors.join("")!==c.colors.join("");b=d||e}else b=!0;return b},a.PaletteManagerController.prototype.createPaletteBodyMarkup=function(){var a=this.getSelectedPalette(),b=this.getColorCardsMarkup(a.colors);b+=pskl.utils.Template.replace(this.newColorTemplate,{classname:d}),this.paletteBody.innerHTML=b},a.PaletteManagerController.prototype.initPaletteDetailsEvents=function(){var a=this.paletteBody.querySelector("."+d);if(a.addEventListener("click",this.onNewCardClick.bind(this)),this.palettes.length<2){var b=this.paletteHead.querySelector('.palette-manager-palette-button[data-action="delete"]');b.setAttribute("disabled","disabled")}},a.PaletteManagerController.prototype.onNewCardClick=function(){var a,b=this.getSelectedPalette();a=b&&b.colors.length>0?b.colors[b.colors.length-1]:"#FFFFFF",this.addColorInSelectedPalette(a)},a.PaletteManagerController.prototype.delegatedPaletteBodyClick=function(a){var b=a.target;if(b.classList.contains(e)){var c=parseInt(b.parentNode.dataset.colorId,10);this.removeColorInSelectedPalette(c)}},a.PaletteManagerController.prototype.delegatedPaletteHeadClick=function(a){var b=a.target;if(b.classList.contains(f))this.renameSelectedPalette();else if(b.classList.contains("palette-manager-palette-button")){var c=b.dataset.action;"save"===c?(this.savePalette(this.getSelectedPalette().id),this.redraw()):"revert"===c?this.revertChanges():"delete"===c&&this.deleteSelectedPalette()}},a.PaletteManagerController.prototype.getSpectrumSelector_=function(){return":not(."+d+")>.palette-manager-color-square"},a.PaletteManagerController.prototype.initPaletteCardsSpectrum=function(){var a=this,b=$(this.getSpectrumSelector_());b.spectrum({clickoutFiresChange:!0,showInput:!0,showButtons:!1,change:function(b){var c=this,d=parseInt(c.parentNode.dataset.colorId,10);a.updateColorInSelectedPalette(d,b)},beforeShow:function(){var c=this,d=parseInt(c.parentNode.dataset.colorId,10),e=a.getSelectedPalette(),f=e.colors[d];b.spectrum("set",f)}}),this.spectrumContainers.push(b)},a.PaletteManagerController.prototype.destroySpectrumPickers=function(){this.spectrumContainers.forEach(function(a){a.spectrum("destroy")}),this.spectrumContainers=[]},a.PaletteManagerController.prototype.updateColorInSelectedPalette=function(a,b){var c=this.getSelectedPalette(),d="#"+b.toHex().toUpperCase();c.colors.splice(a,1,d),this.redraw()},a.PaletteManagerController.prototype.addColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.push(a),this.redraw()},a.PaletteManagerController.prototype.removeColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.splice(a,1),this.redraw()},a.PaletteManagerController.prototype.renameSelectedPalette=function(){var a=this.getSelectedPalette(),b=window.prompt('Please enter a new name for palette "'+a.name+'"',a.name);b&&(a.name=b,this.redraw())},a.PaletteManagerController.prototype.getSelectedPalette=function(){return this.getPaletteById(this.selectedPaletteId,this.palettes)},a.PaletteManagerController.prototype.getColorCardsMarkup=function(a){var c=a.map(function(a,c){var d={colorId:c,hex:a,rgb:b(a).toRgbString(),hsl:b(a).toHslString()};return pskl.utils.Template.replace(this.colorCardTemplate,d)}.bind(this)).join("");return c},a.PaletteManagerController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PaletteManagerController.prototype.removePaletteById=function(a,b){var c=this.getPaletteById(a,b);if(c){var d=b.indexOf(c);b.splice(d,1)}},a.PaletteManagerController.prototype.deselectCurrentPalette=function(){var a=this.palettesList.querySelector("."+c);a&&(this.selectedPaletteId=null,a.classList.remove(c))},a.PaletteManagerController.prototype.revertChanges=function(){var a=this.getSelectedPalette(),b=this.getPaletteById(a.id,this.originalPalettes);a.name=b.name,a.colors=b.colors.slice(0),this.redraw()},a.PaletteManagerController.prototype.deleteSelectedPalette=function(){var a=this.getSelectedPalette();this.palettes.length>1&&window.confirm('Are you sure you want to delete "'+a.name+'" ?')&&(this.removePaletteById(a.id,this.palettes),this.removePaletteById(a.id,this.originalPalettes),this.persistToLocalStorage(),this.createPaletteListMarkup(),this.selectPalette(this.palettes[0].id))},a.PaletteManagerController.prototype.onPaletteListClick=function(a){var b=a.target;b.dataset.paletteId&&this.selectPalette(b.dataset.paletteId)},a.PaletteManagerController.prototype.saveAll=function(){this.palettes.forEach(function(a){this.savePalette(a.id)}.bind(this)),this.redraw()},a.PaletteManagerController.prototype.savePalette=function(a){var b=this.getPaletteById(a,this.palettes),c=this.getPaletteById(a,this.originalPalettes);c?(c.name=b.name,c.colors=b.colors):this.originalPalettes.push(b),this.persistToLocalStorage(),$.publish(Events.SHOW_NOTIFICATION,[{content:"Palette "+b.name+" successfully saved !"}]),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)},a.PaletteManagerController.prototype.persistToLocalStorage=function(){window.localStorage.setItem("piskel.palettes",JSON.stringify(this.originalPalettes)),this.originalPalettes=this.retrieveUserPalettes(),$.publish(Events.PALETTE_LIST_UPDATED)},a.PaletteManagerController.prototype.retrieveUserPalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=60;a.ImportImageController=function(){this.importedImage_=null,this.file_=null},pskl.utils.inherit(a.ImportImageController,a.AbstractDialogController),a.ImportImageController.prototype.init=function(a){this.superclass.init.call(this),this.file_=a,this.importPreview=$(".import-section-preview"),this.fileNameContainer=$(".import-image-file-name"),this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.smoothResize=$("[name=smooth-resize-checkbox]"),this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this,"width")),this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this,"height")),this.importImageForm=$("[name=import-image-form]"),this.importImageForm.submit(this.onImportFormSubmit_.bind(this)),pskl.utils.FileUtils.readFile(this.file_,this.processImageSource_.bind(this))},a.ImportImageController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault(),this.importImageToPiskel_()},a.ImportImageController.prototype.onResizeInputKeyUp_=function(a,b){this.importedImage_&&this.synchronizeResizeFields_(b.target.value,a)},a.ImportImageController.prototype.synchronizeResizeFields_=function(a,b){a=parseInt(a,10),isNaN(a)&&(a=0);var c=this.importedImage_.height,d=this.importedImage_.width;"width"===b?this.resizeHeight.val(Math.round(a*c/d)):this.resizeWidth.val(Math.round(a*d/c))},a.ImportImageController.prototype.processImageSource_=function(a){this.importedImage_=new Image,this.importedImage_.onload=this.onImageLoaded_.bind(this),this.importedImage_.src=a},a.ImportImageController.prototype.onImageLoaded_=function(){var a=this.importedImage_.width,b=this.importedImage_.height;this.importedImage_.onload=function(){};var c=this.extractFileNameFromPath_(this.file_.name);this.fileNameContainer.html(c),this.resizeWidth.val(a),this.resizeHeight.val(b),this.importPreview.width("auto"),this.importPreview.html(""),this.importPreview.append(this.createImagePreview_())},a.ImportImageController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");return a.src=this.importedImage_.src,a.setAttribute("height",b),a},a.ImportImageController.prototype.extractFileNameFromPath_=function(a){var b=[];return b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a],b[b.length-1]},a.ImportImageController.prototype.importImageToPiskel_=function(){var a=this.importedImage_;if(a&&window.confirm("You are about to create a new Piskel, unsaved changes will be lost.")){var b=new window.SuperGif({gif:a});b.load({success:function(){var a=b.getFrames().map(function(a){return pskl.CanvasUtils.createFromImageData(a.data)});this.createPiskelFromImages_(a),this.closeDialog()}.bind(this),error:function(){this.createPiskelFromImages_([a]),this.closeDialog()}.bind(this)})}},a.ImportImageController.prototype.createFramesFromImages_=function(a){var b=this.resizeWidth.val(),c=this.resizeHeight.val(),d=!!this.smoothResize.prop("checked"),e=a.map(function(a){var e=pskl.utils.ImageResizer.resize(a,b,c,d);return pskl.utils.FrameUtils.createFromImage(e)});return e},a.ImportImageController.prototype.createPiskelFromImages_=function(a){var b=this.createFramesFromImages_(a),c=pskl.model.Layer.fromFrames("Layer 1",b),d=new pskl.model.piskel.Descriptor("Imported piskel",""),e=pskl.model.Piskel.fromLayers([c],d);pskl.app.piskelController.setPiskel(e),pskl.app.animationController.setFPS(Constants.DEFAULT.FPS)}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.BrowseLocalController=function(){},pskl.utils.inherit(a.BrowseLocalController,a.AbstractDialogController),a.BrowseLocalController.prototype.init=function(){this.superclass.init.call(this),this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.BrowseLocalController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),this.closeDialog()):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.BrowseLocalController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=pskl.utils.DateUtils.format(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController},"browse-local":{template:"templates/dialogs/browse-local.html",controller:a.BrowseLocalController},"import-image":{template:"templates/dialogs/import-image.html",controller:a.ImportImageController}};a.DialogsController=function(a){this.piskelController=a,this.currentDialog_=null},a.DialogsController.prototype.init=function(){this.dialogContainer_=document.getElementById("dialog-container"),this.dialogWrapper_=document.getElementById("dialog-container-wrapper"),$.subscribe(Events.DIALOG_DISPLAY,this.onDialogDisplayEvent_.bind(this)),$.subscribe(Events.DIALOG_HIDE,this.onDialogHideEvent_.bind(this)),pskl.app.shortcutService.addShortcut("alt+P",this.onDialogDisplayEvent_.bind(this,null,"manage-palettes")),this.dialogWrapper_.classList.add("animated")},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){var d,e;if("string"==typeof c?d=c:(d=c.dialogId,e=c.initArgs),!this.isDisplayed()){var f=b[d];if(f){this.dialogContainer_.innerHTML=pskl.utils.Template.get(f.template),this.dialogContainer_.classList.add(d);var g=new f.controller(this.piskelController);g.init(e),this.showDialogWrapper_(),this.currentDialog_={id:d,controller:g}}else console.error("Could not find dialog configuration for dialogId : "+d)}},a.DialogsController.prototype.onDialogHideEvent_=function(){this.hideDialog()},a.DialogsController.prototype.showDialogWrapper_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideDialog.bind(this)),this.dialogWrapper_.classList.add("show")},a.DialogsController.prototype.hideDialog=function(){var a=this.currentDialog_;if(a){a.controller.destroy();var b=this.currentDialog_.id;window.setTimeout(function(){this.dialogContainer_.classList.remove(b)}.bind(this),800)}this.hideDialogWrapper_(),this.currentDialog_=null},a.DialogsController.prototype.hideDialogWrapper_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.dialogWrapper_.classList.remove("show")},a.DialogsController.prototype.isDisplayed=function(){return null!==this.currentDialog_}}(),function(){var a=$.namespace("pskl.service");a.LocalStorageService=function(a){if(void 0===a)throw"Bad LocalStorageService initialization: ";this.piskelController=a},a.LocalStorageService.prototype.init=function(){},a.LocalStorageService.prototype.save=function(a,b,c){this.removeFromKeys_(a),this.addToKeys_(a,b,Date.now()),window.localStorage.setItem("piskel."+a,c)},a.LocalStorageService.prototype.load=function(a){var b=this.getPiskel(a),c=this.getKey_(a);pskl.utils.serialization.Deserializer.deserialize(JSON.parse(b),function(b){b.setDescriptor(new pskl.model.piskel.Descriptor(a,c.description,!0)),pskl.app.piskelController.setPiskel(b)})},a.LocalStorageService.prototype.remove=function(a){this.removeFromKeys_(a),window.localStorage.removeItem("piskel."+a)},a.LocalStorageService.prototype.saveKeys_=function(a){window.localStorage.setItem("piskel.keys",JSON.stringify(a))},a.LocalStorageService.prototype.removeFromKeys_=function(a){var b=this.getKeys(),c=b.filter(function(b){return b.name!==a});this.saveKeys_(c)},a.LocalStorageService.prototype.getKey_=function(a){var b=this.getKeys().filter(function(b){return b.name===a});return b.length>0?b[0]:null},a.LocalStorageService.prototype.addToKeys_=function(a,b,c){var d=this.getKeys();d.push({name:a,description:b,date:c}),this.saveKeys_(d)},a.LocalStorageService.prototype.getPiskel=function(a){return window.localStorage.getItem("piskel."+a)},a.LocalStorageService.prototype.getKeys=function(){var a=window.localStorage.getItem("piskel.keys");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.service");a.GithubStorageService=function(a){this.piskelController=a},a.GithubStorageService.prototype.init=function(){},a.GithubStorageService.prototype.store=function(){throw"Github save is no longer available. Use local save instead"}}(),function(){var a=$.namespace("pskl.service");a.AppEngineStorageService=function(a){this.piskelController=a},a.AppEngineStorageService.prototype.init=function(){},a.AppEngineStorageService.prototype.store=function(a){var b=this.prepareFormData_(),c=new XMLHttpRequest;c.open("POST",Constants.APPENGINE.URL.SAVE,!0),c.onload=function(b){200==this.status?(a.success(),a.after()):this.onerror(b)},c.onerror=function(){a.error(this.status),a.after()},c.send(b)},a.AppEngineStorageService.prototype.prepareFormData_=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=new FormData;return c.append("framesheet",this.piskelController.serialize()),c.append("fps",this.piskelController.getFPS()),c.append("name",b.name),c.append("description",b.description),b.isPublic&&c.append("public",!0),c.append("frames",this.piskelController.getFrameCount()),c.append("first_frame_as_png",pskl.app.getFirstFrameAsPng()),c.append("framesheet_as_png",pskl.app.getFramesheetAsPng()),c}}(),function(){var a=$.namespace("pskl.service"),b=6e4;a.BackupService=function(a){this.piskelController=a,this.lastHash=null},a.BackupService.prototype.init=function(){var a=window.localStorage.getItem("bkp.next.piskel"),c=window.localStorage.getItem("bkp.next.info"); +},a.PngExportController.prototype.updateStatus_=function(a){if(a){var c="{{shortLink}}",d=pskl.utils.Template.replace(c,{link:a,shortLink:this.shorten_(a,b,"...")});this.uploadStatusContainerEl.innerHTML="Your image is now available at : "+d}},a.PngExportController.prototype.updatePreview_=function(a){this.previewContainerEl.innerHTML=""},a.PngExportController.prototype.shorten_=function(a,b,c){return a.length>b&&(a=a.substring(0,b),a+=c),a}}(),function(){var a=$.namespace("pskl.controller.settings");a.LocalStorageController=function(){},a.LocalStorageController.prototype.init=function(){this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillRestoreSession_(),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.LocalStorageController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),$.publish(Events.CLOSE_SETTINGS_DRAWER)):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.LocalStorageController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:this.formatDate_(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.LocalStorageController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))};var b=function(a){return 10>a?"0"+a:""+a};a.LocalStorageController.prototype.formatDate_=function(a,c){a=new Date(a);var d=pskl.utils.Template.replace(c,{Y:a.getFullYear(),M:b(a.getMonth()+1),D:b(a.getDate()),H:b(a.getHours()),m:b(a.getMinutes())});return d},a.LocalStorageController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=this.formatDate_(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.SaveController=function(a){this.piskelController=a},a.SaveController.prototype.init=function(){this.saveForm=$("form[name=save-form]"),this.nameInput=$("#save-name"),this.descriptionInput=$("#save-description"),this.isPublicCheckbox=$("input[name=save-public-checkbox]"),this.saveOnlineButton=$("#save-online-button"),this.saveLocalButton=$("#save-browser-button"),this.saveFileButton=$("#save-file-button"),this.piskelName=$(".piskel-name").get(0),this.saveOnlineStatus=$("#save-online-status"),this.saveFileStatus=$("#save-file-status"),this.timestamp=new Date;var a=this.piskelController.getPiskel().getDescriptor();this.nameInput.val(a.name),this.descriptionInput.val(a.description),this.isPublicCheckbox.prop("checked",a.isPublic),this.saveFileButton.click(this.saveFile_.bind(this)),this.saveLocalButton.click(this.saveLocal_.bind(this)),this.saveOnlineButton.click(this.saveOnline_.bind(this)),this.saveForm.submit(this.onSaveFormSubmit_.bind(this)),this.nameInput.keyup(this.updateLocalStatusFilename_.bind(this)),pskl.app.isLoggedIn()||(this.saveOnlineButton.hide(),$(".save-public-section").hide(),this.saveOnlineStatus.html(pskl.utils.Template.get("save-please-login-partial")),this.saveFileButton.get(0).classList.add("button-primary")),this.updateLocalStatusFilename_()},a.SaveController.prototype.updateLocalStatusFilename_=function(){this.saveFileStatus.html(pskl.utils.Template.getAndReplace("save-file-status-template",{name:this.getLocalFilename_()}))},a.SaveController.prototype.getLocalFilename_=function(){var a=this.getName(),b=pskl.utils.DateUtils.format(this.timestamp,"{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}");return a+"-"+b+".piskel"},a.SaveController.prototype.onSaveFormSubmit_=function(a){a.preventDefault(),a.stopPropagation(),pskl.app.isLoggedIn()?this.saveOnline_():this.saveLocal_()},a.SaveController.prototype.saveOnline_=function(){var a=this.getName();if(a||(a=window.prompt("Please specify a name","New piskel")),a){var b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d),this.beforeSaving_(),pskl.app.storageService.store({success:this.onSaveSuccess_.bind(this),error:this.onSaveError_.bind(this),after:this.afterSaving_.bind(this)})}},a.SaveController.prototype.saveLocal_=function(){var a=pskl.app.localStorageService,b=!0,c=this.getName(),d=this.getDescription();a.getPiskel(c)&&(b=window.confirm("There is already a piskel saved as "+c+". Override ?")),b&&(this.beforeSaving_(),a.save(c,d,pskl.app.piskelController.serialize()),window.setTimeout(function(){this.onSaveSuccess_(),this.afterSaving_()}.bind(this),500))},a.SaveController.prototype.saveFile_=function(){this.beforeSaving_(),pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(),function(a){pskl.utils.FileUtils.downloadAsFile(a,this.getLocalFilename_()),this.onSaveSuccess_(),this.afterSaving_()}.bind(this),"application/piskel+json")},a.SaveController.prototype.getName=function(){return this.nameInput.val()},a.SaveController.prototype.getDescription=function(){return this.descriptionInput.val()},a.SaveController.prototype.beforeSaving_=function(){this.updatePiskelDescriptor_(),this.saveOnlineButton.attr("disabled",!0),this.saveOnlineStatus.html("Saving ..."),this.piskelName&&this.piskelName.classList.add("piskel-name-saving")},a.SaveController.prototype.updatePiskelDescriptor_=function(){var a=this.getName(),b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d)},a.SaveController.prototype.onSaveSuccess_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER),$.publish(Events.SHOW_NOTIFICATION,[{content:"Successfully saved !"}]),$.publish(Events.PISKEL_SAVED)},a.SaveController.prototype.onSaveError_=function(a){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+a+")"}])},a.SaveController.prototype.afterSaving_=function(){this.saveOnlineButton.attr("disabled",!1),this.saveOnlineStatus.html(""),this.piskelName&&this.piskelName.classList.remove("piskel-name-saving"),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)}}(),function(){var a=$.namespace("pskl.controller.settings");a.ImportController=function(a){this.piskelController=a,this.importedImage_=null},a.ImportController.prototype.init=function(){this.hiddenOpenPiskelInput=$("[name=open-piskel-input]"),this.openPiskelInputButton=$(".open-piskel-button"),this.hiddenFileInput=$("[name=file-upload-input]"),this.fileInputButton=$(".file-input-button"),this.browseLocalButton=document.querySelector(".browse-local-button"),this.browseLocalButton.addEventListener("click",this.onBrowseLocalClick_.bind(this)),this.hiddenFileInput.change(this.onFileUploadChange_.bind(this)),this.fileInputButton.click(this.onFileInputClick_.bind(this)),this.hiddenOpenPiskelInput.change(this.onOpenPiskelChange_.bind(this)),this.openPiskelInputButton.click(this.onOpenPiskelClick_.bind(this)),this.prevSessionContainer=$(".previous-session"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.fillRestoreSession_()},a.ImportController.prototype.closeDrawer_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ImportController.prototype.onFileUploadChange_=function(){this.importPictureFromFile_()},a.ImportController.prototype.onFileInputClick_=function(){this.hiddenFileInput.click()},a.ImportController.prototype.onOpenPiskelChange_=function(){this.openPiskelFile_()},a.ImportController.prototype.onOpenPiskelClick_=function(){this.hiddenOpenPiskelInput.click()},a.ImportController.prototype.onBrowseLocalClick_=function(){$.publish(Events.DIALOG_DISPLAY,"browse-local"),this.closeDrawer_()},a.ImportController.prototype.openPiskelFile_=function(){var a=this.hiddenOpenPiskelInput.get(0).files;if(1==a.length){var b=a[0];this.isPiskel_(b)&&(pskl.utils.PiskelFileUtils.loadFromFile(b,function(a,b,c){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)}),this.closeDrawer_())}},a.ImportController.prototype.importPictureFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length){var b=a[0];if(!this.isImage_(b))throw this.closeDrawer_(),"File is not an image : "+b.type;$.publish(Events.DIALOG_DISPLAY,{dialogId:"import-image",initArgs:b}),this.closeDrawer_()}},a.ImportController.prototype.enableDisabledSections_=function(){this.fileInputButton.removeClass("button-primary"),this.fileInputButton.blur(),$(".import-options").show()},a.ImportController.prototype.isImage_=function(a){return 0===a.type.indexOf("image")},a.ImportController.prototype.isPiskel_=function(a){return/\.piskel$/.test(a.name)},a.ImportController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:pskl.utils.DateUtils.format(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.ImportController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))}}(),function(){var a=$.namespace("pskl.controller.settings"),b={user:{template:"templates/settings/application.html",controller:a.ApplicationSettingsController},resize:{template:"templates/settings/resize.html",controller:a.ResizeController},png:{template:"templates/settings/export.html",controller:a.PngExportController},"import":{template:"templates/settings/import.html",controller:a.ImportController},localstorage:{template:"templates/settings/localstorage.html",controller:a.LocalStorageController},save:{template:"templates/settings/save.html",controller:a.SaveController}},c="has-expanded-drawer",d="expanded";a.SettingsController=function(a){this.piskelController=a,this.drawerContainer=document.getElementById("drawer-container"),this.settingsContainer=$("[data-pskl-controller=settings]"),this.isExpanded=!1,this.currentSetting=null},a.SettingsController.prototype.init=function(){$("[data-setting]").click(this.onSettingIconClick.bind(this)),$("body").click(this.onBodyClick.bind(this)),$.subscribe(Events.CLOSE_SETTINGS_DRAWER,this.closeDrawer.bind(this))},a.SettingsController.prototype.onSettingIconClick=function(a){var b=a.originalEvent.currentTarget,c=b.getAttribute("data-setting");this.currentSetting!=c?this.loadSetting(c):this.closeDrawer(),a.originalEvent.stopPropagation(),a.originalEvent.preventDefault()},a.SettingsController.prototype.onBodyClick=function(a){var b=a.target,c=pskl.utils.Dom.isParent(b,this.drawerContainer),d=b.getAttribute("data-setting"),e=c||d;this.isExpanded&&!e&&this.closeDrawer()},a.SettingsController.prototype.loadSetting=function(a){this.drawerContainer.innerHTML=pskl.utils.Template.get(b[a].template),new b[a].controller(this.piskelController).init(),this.settingsContainer.addClass(d),$("."+c).removeClass(c),$("[data-setting="+a+"]").addClass(c),this.isExpanded=!0,this.currentSetting=a},a.SettingsController.prototype.closeDrawer=function(){this.settingsContainer.removeClass(d),$("."+c).removeClass(c),this.isExpanded=!1,this.currentSetting=null,document.activeElement.blur()}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.AbstractDialogController=function(){},a.AbstractDialogController.prototype.init=function(){this.closeButton=document.querySelector(".dialog-close"),this.closeButton.addEventListener("click",this.closeDialog.bind(this))},a.AbstractDialogController.prototype.destroy=function(){},a.AbstractDialogController.prototype.closeDialog=function(){$.publish(Events.DIALOG_HIDE)}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=window.tinycolor,c="selected",d="palette-manager-new-color",e="palette-manager-delete-card",f="edit-icon";a.PaletteManagerController=function(a){this.piskelController=a,this.palettes=this.retrieveUserPalettes(),this.originalPalettes=this.retrieveUserPalettes(),this.selectedPaletteId=null,this.spectrumContainers=[]},pskl.utils.inherit(a.PaletteManagerController,a.AbstractDialogController),a.PaletteManagerController.prototype.init=function(){this.superclass.init.call(this),this.palettesList=document.querySelector(".palette-manager-list"),this.paletteBody=document.querySelector(".palette-manager-details-body"),this.paletteHead=document.querySelector(".palette-manager-details-head"),this.createButton=document.querySelector('.palette-manager-actions-button[data-action="create"]'),this.saveAllButton=document.querySelector('.palette-manager-actions-button[data-action="save-all"]'),this.colorCardTemplate=pskl.utils.Template.get("palette-color-card-template"),this.newColorTemplate=pskl.utils.Template.get("palette-new-color-template"),this.paletteHeadTemplate=pskl.utils.Template.get("palette-details-head-template"),this.palettesList.addEventListener("click",this.onPaletteListClick.bind(this)),this.paletteBody.addEventListener("click",this.delegatedPaletteBodyClick.bind(this)),this.paletteHead.addEventListener("click",this.delegatedPaletteHeadClick.bind(this)),this.createButton.addEventListener("click",this.onCreateClick_.bind(this)),this.saveAllButton.addEventListener("click",this.saveAll.bind(this)),this.createPaletteListMarkup(),this.palettes.length>0?this.selectPalette(this.palettes[0].id):this.createPalette("New palette")},a.PaletteManagerController.prototype.destroy=function(){this.destroySpectrumPickers()},a.PaletteManagerController.prototype.onCreateClick_=function(){this.createPalette()},a.PaletteManagerController.prototype.createPalette=function(a){if(a||(a=window.prompt("Please enter a name for your palette","New palette")),a){var b=this.createPaletteObject(a);this.palettes.push(b),this.createPaletteListMarkup(),this.selectPalette(b.id)}},a.PaletteManagerController.prototype.createPaletteObject=function(a){return{id:"palette-"+Date.now()+"-"+Math.floor(1e3*Math.random()),name:a,colors:[]}},a.PaletteManagerController.prototype.redraw=function(){this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.selectPalette=function(a){this.deselectCurrentPalette();var b=this.palettesList.querySelector("[data-palette-id="+a+"]");b&&(this.selectedPaletteId=a,b.classList.add(c),this.refreshPaletteDetails())},a.PaletteManagerController.prototype.refreshPaletteDetails=function(){this.createPaletteHeadMarkup(),this.createPaletteBodyMarkup(),this.initPaletteDetailsEvents(),this.initPaletteCardsSpectrum()},a.PaletteManagerController.prototype.createPaletteListMarkup=function(){var a=this.palettes.map(function(a){var b={id:a.id,name:this.isPaletteModified(a)?a.name+" *":a.name};return pskl.utils.Template.replace('
  • {{name}}
  • ',b)}.bind(this)).join("");this.palettesList.innerHTML=a},a.PaletteManagerController.prototype.createPaletteHeadMarkup=function(){var a=this.getSelectedPalette(),b={name:a.name,"save:disabled":!this.isPaletteModified(a),"revert:disabled":!this.isPaletteModified(a),"delete:disabled":this.palettes.length<2},c=pskl.utils.Template.replace(this.paletteHeadTemplate,b);this.paletteHead.innerHTML=c},a.PaletteManagerController.prototype.isPaletteModified=function(a){var b=!1,c=this.getPaletteById(a.id,this.originalPalettes);if(c){var d=c.name!==a.name,e=a.colors.join("")!==c.colors.join("");b=d||e}else b=!0;return b},a.PaletteManagerController.prototype.createPaletteBodyMarkup=function(){var a=this.getSelectedPalette(),b=this.getColorCardsMarkup(a.colors);b+=pskl.utils.Template.replace(this.newColorTemplate,{classname:d}),this.paletteBody.innerHTML=b},a.PaletteManagerController.prototype.initPaletteDetailsEvents=function(){var a=this.paletteBody.querySelector("."+d);if(a.addEventListener("click",this.onNewCardClick.bind(this)),this.palettes.length<2){var b=this.paletteHead.querySelector('.palette-manager-palette-button[data-action="delete"]');b.setAttribute("disabled","disabled")}},a.PaletteManagerController.prototype.onNewCardClick=function(){var a,b=this.getSelectedPalette();a=b&&b.colors.length>0?b.colors[b.colors.length-1]:"#FFFFFF",this.addColorInSelectedPalette(a)},a.PaletteManagerController.prototype.delegatedPaletteBodyClick=function(a){var b=a.target;if(b.classList.contains(e)){var c=parseInt(b.parentNode.dataset.colorId,10);this.removeColorInSelectedPalette(c)}},a.PaletteManagerController.prototype.delegatedPaletteHeadClick=function(a){var b=a.target;if(b.classList.contains(f))this.renameSelectedPalette();else if(b.classList.contains("palette-manager-palette-button")){var c=b.dataset.action;"save"===c?(this.savePalette(this.getSelectedPalette().id),this.redraw()):"revert"===c?this.revertChanges():"delete"===c&&this.deleteSelectedPalette()}},a.PaletteManagerController.prototype.getSpectrumSelector_=function(){return":not(."+d+")>.palette-manager-color-square"},a.PaletteManagerController.prototype.initPaletteCardsSpectrum=function(){var a=this,b=$(this.getSpectrumSelector_());b.spectrum({clickoutFiresChange:!0,showInput:!0,showButtons:!1,change:function(b){var c=this,d=parseInt(c.parentNode.dataset.colorId,10);a.updateColorInSelectedPalette(d,b)},beforeShow:function(){var c=this,d=parseInt(c.parentNode.dataset.colorId,10),e=a.getSelectedPalette(),f=e.colors[d];b.spectrum("set",f)}}),this.spectrumContainers.push(b)},a.PaletteManagerController.prototype.destroySpectrumPickers=function(){this.spectrumContainers.forEach(function(a){a.spectrum("destroy")}),this.spectrumContainers=[]},a.PaletteManagerController.prototype.updateColorInSelectedPalette=function(a,b){var c=this.getSelectedPalette(),d="#"+b.toHex().toUpperCase();c.colors.splice(a,1,d),this.redraw()},a.PaletteManagerController.prototype.addColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.push(a),this.redraw()},a.PaletteManagerController.prototype.removeColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.splice(a,1),this.redraw()},a.PaletteManagerController.prototype.renameSelectedPalette=function(){var a=this.getSelectedPalette(),b=window.prompt('Please enter a new name for palette "'+a.name+'"',a.name);b&&(a.name=b,this.redraw())},a.PaletteManagerController.prototype.getSelectedPalette=function(){return this.getPaletteById(this.selectedPaletteId,this.palettes)},a.PaletteManagerController.prototype.getColorCardsMarkup=function(a){var c=a.map(function(a,c){var d={colorId:c,hex:a,rgb:b(a).toRgbString(),hsl:b(a).toHslString()};return pskl.utils.Template.replace(this.colorCardTemplate,d)}.bind(this)).join("");return c},a.PaletteManagerController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PaletteManagerController.prototype.removePaletteById=function(a,b){var c=this.getPaletteById(a,b);if(c){var d=b.indexOf(c);b.splice(d,1)}},a.PaletteManagerController.prototype.deselectCurrentPalette=function(){var a=this.palettesList.querySelector("."+c);a&&(this.selectedPaletteId=null,a.classList.remove(c))},a.PaletteManagerController.prototype.revertChanges=function(){var a=this.getSelectedPalette(),b=this.getPaletteById(a.id,this.originalPalettes);a.name=b.name,a.colors=b.colors.slice(0),this.redraw()},a.PaletteManagerController.prototype.deleteSelectedPalette=function(){var a=this.getSelectedPalette();this.palettes.length>1&&window.confirm('Are you sure you want to delete "'+a.name+'" ?')&&(this.removePaletteById(a.id,this.palettes),this.removePaletteById(a.id,this.originalPalettes),this.persistToLocalStorage(),this.createPaletteListMarkup(),this.selectPalette(this.palettes[0].id))},a.PaletteManagerController.prototype.onPaletteListClick=function(a){var b=a.target;b.dataset.paletteId&&this.selectPalette(b.dataset.paletteId)},a.PaletteManagerController.prototype.saveAll=function(){this.palettes.forEach(function(a){this.savePalette(a.id)}.bind(this)),this.redraw()},a.PaletteManagerController.prototype.savePalette=function(a){var b=this.getPaletteById(a,this.palettes),c=this.getPaletteById(a,this.originalPalettes);c?(c.name=b.name,c.colors=b.colors):this.originalPalettes.push(b),this.persistToLocalStorage(),$.publish(Events.SHOW_NOTIFICATION,[{content:"Palette "+b.name+" successfully saved !"}]),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)},a.PaletteManagerController.prototype.persistToLocalStorage=function(){window.localStorage.setItem("piskel.palettes",JSON.stringify(this.originalPalettes)),this.originalPalettes=this.retrieveUserPalettes(),$.publish(Events.PALETTE_LIST_UPDATED)},a.PaletteManagerController.prototype.retrieveUserPalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=60;a.ImportImageController=function(){this.importedImage_=null,this.file_=null},pskl.utils.inherit(a.ImportImageController,a.AbstractDialogController),a.ImportImageController.prototype.init=function(a){this.superclass.init.call(this),this.file_=a,this.importPreview=$(".import-section-preview"),this.fileNameContainer=$(".import-image-file-name"),this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.smoothResize=$("[name=smooth-resize-checkbox]"),this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this,"width")),this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this,"height")),this.importImageForm=$("[name=import-image-form]"),this.importImageForm.submit(this.onImportFormSubmit_.bind(this)),pskl.utils.FileUtils.readFile(this.file_,this.processImageSource_.bind(this))},a.ImportImageController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault(),this.importImageToPiskel_()},a.ImportImageController.prototype.onResizeInputKeyUp_=function(a,b){this.importedImage_&&this.synchronizeResizeFields_(b.target.value,a)},a.ImportImageController.prototype.synchronizeResizeFields_=function(a,b){a=parseInt(a,10),isNaN(a)&&(a=0);var c=this.importedImage_.height,d=this.importedImage_.width;"width"===b?this.resizeHeight.val(Math.round(a*c/d)):this.resizeWidth.val(Math.round(a*d/c))},a.ImportImageController.prototype.processImageSource_=function(a){this.importedImage_=new Image,this.importedImage_.onload=this.onImageLoaded_.bind(this),this.importedImage_.src=a},a.ImportImageController.prototype.onImageLoaded_=function(){var a=this.importedImage_.width,b=this.importedImage_.height;this.importedImage_.onload=function(){};var c=this.extractFileNameFromPath_(this.file_.name);this.fileNameContainer.html(c),this.resizeWidth.val(a),this.resizeHeight.val(b),this.importPreview.width("auto"),this.importPreview.html(""),this.importPreview.append(this.createImagePreview_())},a.ImportImageController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");return a.src=this.importedImage_.src,a.setAttribute("height",b),a},a.ImportImageController.prototype.extractFileNameFromPath_=function(a){var b=[];return b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a],b[b.length-1]},a.ImportImageController.prototype.importImageToPiskel_=function(){var a=this.importedImage_;if(a&&window.confirm("You are about to create a new Piskel, unsaved changes will be lost.")){var b=new window.SuperGif({gif:a});b.load({success:function(){var a=b.getFrames().map(function(a){return pskl.CanvasUtils.createFromImageData(a.data)});this.createPiskelFromImages_(a),this.closeDialog()}.bind(this),error:function(){this.createPiskelFromImages_([a]),this.closeDialog()}.bind(this)})}},a.ImportImageController.prototype.createFramesFromImages_=function(a){var b=this.resizeWidth.val(),c=this.resizeHeight.val(),d=!!this.smoothResize.prop("checked"),e=a.map(function(a){var e=pskl.utils.ImageResizer.resize(a,b,c,d);return pskl.utils.FrameUtils.createFromImage(e)});return e},a.ImportImageController.prototype.createPiskelFromImages_=function(a){var b=this.createFramesFromImages_(a),c=pskl.model.Layer.fromFrames("Layer 1",b),d=new pskl.model.piskel.Descriptor("Imported piskel",""),e=pskl.model.Piskel.fromLayers([c],d);pskl.app.piskelController.setPiskel(e),pskl.app.animationController.setFPS(Constants.DEFAULT.FPS)}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.BrowseLocalController=function(){},pskl.utils.inherit(a.BrowseLocalController,a.AbstractDialogController),a.BrowseLocalController.prototype.init=function(){this.superclass.init.call(this),this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.BrowseLocalController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),this.closeDialog()):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.BrowseLocalController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=pskl.utils.DateUtils.format(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController},"browse-local":{template:"templates/dialogs/browse-local.html",controller:a.BrowseLocalController},"import-image":{template:"templates/dialogs/import-image.html",controller:a.ImportImageController}};a.DialogsController=function(a){this.piskelController=a,this.currentDialog_=null},a.DialogsController.prototype.init=function(){this.dialogContainer_=document.getElementById("dialog-container"),this.dialogWrapper_=document.getElementById("dialog-container-wrapper"),$.subscribe(Events.DIALOG_DISPLAY,this.onDialogDisplayEvent_.bind(this)),$.subscribe(Events.DIALOG_HIDE,this.onDialogHideEvent_.bind(this)),pskl.app.shortcutService.addShortcut("alt+P",this.onDialogDisplayEvent_.bind(this,null,"manage-palettes")),this.dialogWrapper_.classList.add("animated")},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){var d,e;if("string"==typeof c?d=c:(d=c.dialogId,e=c.initArgs),!this.isDisplayed()){var f=b[d];if(f){this.dialogContainer_.innerHTML=pskl.utils.Template.get(f.template),this.dialogContainer_.classList.add(d);var g=new f.controller(this.piskelController);g.init(e),this.showDialogWrapper_(),this.currentDialog_={id:d,controller:g}}else console.error("Could not find dialog configuration for dialogId : "+d)}},a.DialogsController.prototype.onDialogHideEvent_=function(){this.hideDialog()},a.DialogsController.prototype.showDialogWrapper_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideDialog.bind(this)),this.dialogWrapper_.classList.add("show")},a.DialogsController.prototype.hideDialog=function(){var a=this.currentDialog_;if(a){a.controller.destroy();var b=this.currentDialog_.id;window.setTimeout(function(){this.dialogContainer_.classList.remove(b)}.bind(this),800)}this.hideDialogWrapper_(),this.currentDialog_=null},a.DialogsController.prototype.hideDialogWrapper_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.dialogWrapper_.classList.remove("show")},a.DialogsController.prototype.isDisplayed=function(){return null!==this.currentDialog_}}(),function(){var a=$.namespace("pskl.service");a.LocalStorageService=function(a){if(void 0===a)throw"Bad LocalStorageService initialization: ";this.piskelController=a},a.LocalStorageService.prototype.init=function(){},a.LocalStorageService.prototype.save=function(a,b,c){this.removeFromKeys_(a),this.addToKeys_(a,b,Date.now()),window.localStorage.setItem("piskel."+a,c)},a.LocalStorageService.prototype.load=function(a){var b=this.getPiskel(a),c=this.getKey_(a);pskl.utils.serialization.Deserializer.deserialize(JSON.parse(b),function(b){b.setDescriptor(new pskl.model.piskel.Descriptor(a,c.description,!0)),pskl.app.piskelController.setPiskel(b)})},a.LocalStorageService.prototype.remove=function(a){this.removeFromKeys_(a),window.localStorage.removeItem("piskel."+a)},a.LocalStorageService.prototype.saveKeys_=function(a){window.localStorage.setItem("piskel.keys",JSON.stringify(a))},a.LocalStorageService.prototype.removeFromKeys_=function(a){var b=this.getKeys(),c=b.filter(function(b){return b.name!==a});this.saveKeys_(c)},a.LocalStorageService.prototype.getKey_=function(a){var b=this.getKeys().filter(function(b){return b.name===a});return b.length>0?b[0]:null},a.LocalStorageService.prototype.addToKeys_=function(a,b,c){var d=this.getKeys();d.push({name:a,description:b,date:c}),this.saveKeys_(d)},a.LocalStorageService.prototype.getPiskel=function(a){return window.localStorage.getItem("piskel."+a)},a.LocalStorageService.prototype.getKeys=function(){var a=window.localStorage.getItem("piskel.keys");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.service");a.GithubStorageService=function(a){this.piskelController=a},a.GithubStorageService.prototype.init=function(){},a.GithubStorageService.prototype.store=function(){throw"Github save is no longer available. Use local save instead"}}(),function(){var a=$.namespace("pskl.service");a.AppEngineStorageService=function(a){this.piskelController=a},a.AppEngineStorageService.prototype.init=function(){},a.AppEngineStorageService.prototype.store=function(a){var b=this.prepareFormData_(),c=new XMLHttpRequest;c.open("POST",Constants.APPENGINE.URL.SAVE,!0),c.onload=function(b){200==this.status?(a.success(),a.after()):this.onerror(b)},c.onerror=function(){a.error(this.status),a.after()},c.send(b)},a.AppEngineStorageService.prototype.prepareFormData_=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=new FormData;return c.append("framesheet",this.piskelController.serialize()),c.append("fps",this.piskelController.getFPS()),c.append("name",b.name),c.append("description",b.description),b.isPublic&&c.append("public",!0),c.append("frames",this.piskelController.getFrameCount()),c.append("first_frame_as_png",pskl.app.getFirstFrameAsPng()),c.append("framesheet_as_png",pskl.app.getFramesheetAsPng()),c}}(),function(){var a=$.namespace("pskl.service"),b=6e4;a.BackupService=function(a){this.piskelController=a,this.lastHash=null},a.BackupService.prototype.init=function(){var a=window.localStorage.getItem("bkp.next.piskel"),c=window.localStorage.getItem("bkp.next.info"); a&&c&&(window.localStorage.setItem("bkp.prev.piskel",a),window.localStorage.setItem("bkp.prev.info",c)),window.setInterval(this.backup.bind(this),b)},a.BackupService.prototype.backup=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=a.getHash(),d={name:b.name,description:b.info,date:Date.now(),hash:c};c!==this.lastHash&&(this.lastHash=c,window.localStorage.setItem("bkp.next.piskel",this.piskelController.serialize()),window.localStorage.setItem("bkp.next.info",JSON.stringify(d)))},a.BackupService.prototype.getPreviousPiskelInfo=function(){var a=window.localStorage.getItem("bkp.prev.info");return a?JSON.parse(a):void 0},a.BackupService.prototype.load=function(){var a=window.localStorage.getItem("bkp.prev.piskel"),b=window.localStorage.getItem("bkp.prev.info");a=JSON.parse(a),b=JSON.parse(b),pskl.utils.serialization.Deserializer.deserialize(a,function(a){a.setDescriptor(new pskl.model.piskel.Descriptor(b.name,b.description,!0)),pskl.app.piskelController.setPiskel(a)})}}(),function(){var a=$.namespace("pskl.service");a.BeforeUnloadService=function(a){this.piskelController=a},a.BeforeUnloadService.prototype.init=function(){window.addEventListener("beforeunload",this.onBeforeUnload.bind(this))},a.BeforeUnloadService.prototype.onBeforeUnload=function(a){if(pskl.app.backupService.backup(),pskl.app.savedStatusService.isDirty()){var b="Your Piskel seems to have unsaved changes";return(a||window.event).returnValue=b,b}}}(),function(){var a=$.namespace("pskl.service"),b=50,c=50;a.HistoryService=function(a){this.piskelController=a,this.stateQueue=[],this.currentIndex=-1,this.saveState__b=this.onSaveStateEvent.bind(this),this.lastLoadState=-1},a.HistoryService.SNAPSHOT="SNAPSHOT",a.HistoryService.REPLAY="REPLAY",a.HistoryService.prototype.init=function(){$.subscribe(Events.PISKEL_SAVE_STATE,this.saveState__b),pskl.app.shortcutService.addShortcut("ctrl+Z",this.undo.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+Y",this.redo.bind(this)),this.saveState({type:a.HistoryService.SNAPSHOT})},a.HistoryService.prototype.onSaveStateEvent=function(a,b){this.saveState(b)},a.HistoryService.prototype.saveState=function(c){this.stateQueue=this.stateQueue.slice(0,this.currentIndex+1),this.currentIndex=this.currentIndex+1;var d={action:c,frameIndex:this.piskelController.currentFrameIndex,layerIndex:this.piskelController.currentLayerIndex};(c.type===a.HistoryService.SNAPSHOT||0===this.currentIndex%b)&&(d.piskel=this.piskelController.serialize(!0)),this.stateQueue.push(d)},a.HistoryService.prototype.undo=function(){this.loadState(this.currentIndex-1)},a.HistoryService.prototype.redo=function(){this.loadState(this.currentIndex+1)},a.HistoryService.prototype.isLoadStateAllowed_=function(a){var b=Date.now()-this.lastLoadState>c,d=a>=0&&a2*b)););return a},a.HistoryService.prototype.loadState=function(a){try{if(this.isLoadStateAllowed_(a)){this.lastLoadState=Date.now();var b=this.getPreviousSnapshotIndex_(a);if(0>b)throw"Could not find previous SNAPSHOT saved in history stateQueue";var c=this.getSnapshotFromState_(b),d=this.onPiskelLoaded_.bind(this,a,b);pskl.utils.serialization.Deserializer.deserialize(c,d)}}catch(e){window.console.error("[CRITICAL ERROR] : Unable to load a history state."),window.console.error("Can you open an issue on http://github.com/juliandescottes/piskel or contact @piskelapp on twitter ? Thanks !"),window.console.error("Thanks !"),"string"==typeof e?window.console.error(e):(window.console.error(e.message),window.console.error(e.stack))}},a.HistoryService.prototype.getSnapshotFromState_=function(a){var b=this.stateQueue[a],c=b.piskel;return"string"==typeof c&&(c=JSON.parse(c),b.piskel=c),c},a.HistoryService.prototype.onPiskelLoaded_=function(a,b,c){var d=this.getPiskelSize_();c.setDescriptor(this.piskelController.piskel.getDescriptor()),this.piskelController.setPiskel(c);for(var e=b+1;a>=e;e++){var f=this.stateQueue[e];this.setupState(f),this.replayState(f)}var g=this.stateQueue[a+1];g&&this.setupState(g),this.currentIndex=a,$.publish(Events.PISKEL_RESET),d!==this.getPiskelSize_()&&$.publish(Events.FRAME_SIZE_CHANGED)},a.HistoryService.prototype.getPiskelSize_=function(){return this.piskelController.getWidth()+"x"+this.piskelController.getHeight()},a.HistoryService.prototype.setupState=function(a){this.piskelController.setCurrentFrameIndex(a.frameIndex),this.piskelController.setCurrentLayerIndex(a.layerIndex)},a.HistoryService.prototype.replayState=function(a){var b=a.action;b.type;var c=this.piskelController.getLayerAt(a.layerIndex),d=c.getFrameAt(a.frameIndex);b.scope.replay(d,b.replay)}}(),function(){var a=$.namespace("pskl.service");a.SavedStatusService=function(a){this.piskelController=a},a.SavedStatusService.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.onToolReleased.bind(this)),$.subscribe(Events.PISKEL_RESET,this.onPiskelReset.bind(this)),$.subscribe(Events.PISKEL_SAVED,this.onPiskelSaved.bind(this))},a.SavedStatusService.prototype.onPiskelReset=function(){var a=this.piskelController.getPiskel();a.firstResetDone_?this.updateDirtyStatus(!0):a.firstResetDone_=!0},a.SavedStatusService.prototype.onToolReleased=function(){this.updateDirtyStatus(!0)},a.SavedStatusService.prototype.onPiskelSaved=function(){this.updateDirtyStatus(!1)},a.SavedStatusService.prototype.updateDirtyStatus=function(a){var b=this.piskelController.getPiskel();b.isDirty_!==a&&(b.isDirty_=a,this.updatePiskelName())},a.SavedStatusService.prototype.updatePiskelName=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor().name;a.isDirty_?$(".piskel-name").html(b+" *"):$(".piskel-name").html(b)},a.SavedStatusService.prototype.isDirty=function(){var a=this.piskelController.getPiskel();return a.isDirty_}}(),function(){var a=$.namespace("pskl.service.keyboard");a.ShortcutService=function(){this.shortcuts_={}},a.ShortcutService.prototype.init=function(){$(document.body).keydown($.proxy(this.onKeyUp_,this))},a.ShortcutService.prototype.addShortcut=function(a,b){var c=this.parseKey_(a.toLowerCase()),d=c.key,e=c.meta;if(this.shortcuts_[d]=this.shortcuts_[d]||{},this.shortcuts_[d][e]){var f=("normal"!==e?e+" + ":"")+d;console.error("[ShortcutService] >>> Shortcut ["+f+"] already registered")}else this.shortcuts_[d][e]=b},a.ShortcutService.prototype.removeShortcut=function(a){var b=this.parseKey_(a.toLowerCase()),c=b.key,d=b.meta;this.shortcuts_[c]=this.shortcuts_[c]||{},this.shortcuts_[c][d]=null},a.ShortcutService.prototype.parseKey_=function(a){var b=this.getMetaKey_({alt:-1!=a.indexOf("alt+"),shift:-1!=a.indexOf("shift+"),ctrl:-1!=a.indexOf("ctrl+")}),c=a.split(/\+(?!$)/);return a=c[c.length-1],{meta:b,key:a}},a.ShortcutService.prototype.getMetaKey_=function(a){var b=[];return["alt","ctrl","shift"].forEach(function(c){a[c]&&b.push(c)}),b.length>0?b.join("+"):"normal"},a.ShortcutService.prototype.onKeyUp_=function(a){if(!this.isInInput_(a)){var b=a.which;a.target.nodeName.toUpperCase();var c=pskl.service.keyboard.KeycodeTranslator.toChar(b),d=this.shortcuts_[c];if(d){var e=this.getMetaKey_({alt:this.isAltKeyPressed_(a),shift:this.isShiftKeyPressed_(a),ctrl:this.isCtrlKeyPressed_(a)}),f=d[e];if(f){var g=f(c);g!==!0&&a.preventDefault()}}}},a.ShortcutService.prototype.isInInput_=function(a){var b=a.target.nodeName.toUpperCase();return"INPUT"===b||"TEXTAREA"===b},a.ShortcutService.prototype.isCtrlKeyPressed_=function(a){return pskl.utils.UserAgent.isMac?a.metaKey:a.ctrlKey},a.ShortcutService.prototype.isShiftKeyPressed_=function(a){return a.shiftKey},a.ShortcutService.prototype.isAltKeyPressed_=function(a){return a.altKey}}(),function(){var a={191:"?",8:"back",27:"esc",38:"up",40:"down",46:"del",189:"-",187:"+"},b=$.namespace("pskl.service.keyboard");b.KeycodeTranslator={toChar:function(b){return b>=48&&57>=b?b-48+"":b>=65&&90>=b?(b-65+10).toString(36):a[b]}}}(),function(){var a=$.namespace("pskl.service.keyboard");a.CheatsheetService=function(){this.isDisplayed_=!1},a.CheatsheetService.prototype.init=function(){if(this.cheatsheetEl_=document.getElementById("cheatsheet-wrapper"),!this.cheatsheetEl_)throw"cheatsheetEl_ DOM element could not be retrieved";this.initMarkup_(),pskl.app.shortcutService.addShortcut("shift+?",this.toggleCheatsheet_.bind(this)),pskl.app.shortcutService.addShortcut("?",this.toggleCheatsheet_.bind(this));var a=$(".cheatsheet-link");a.click(this.toggleCheatsheet_.bind(this)),$.subscribe(Events.TOGGLE_HELP,this.toggleCheatsheet_.bind(this)),$.subscribe(Events.ESCAPE,this.onEscape_.bind(this))},a.CheatsheetService.prototype.toggleCheatsheet_=function(){this.isDisplayed_?this.hideCheatsheet_():this.showCheatsheet_()},a.CheatsheetService.prototype.onEscape_=function(){this.isDisplayed_&&this.hideCheatsheet_()},a.CheatsheetService.prototype.showCheatsheet_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideCheatsheet_.bind(this)),this.cheatsheetEl_.style.display="block",this.isDisplayed_=!0},a.CheatsheetService.prototype.hideCheatsheet_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.cheatsheetEl_.style.display="none",this.isDisplayed_=!1},a.CheatsheetService.prototype.initMarkup_=function(){this.initMarkupForTools_(),this.initMarkupForMisc_(),this.initMarkupForSelection_()},a.CheatsheetService.prototype.toDescriptor_=function(a,b,c){return pskl.utils.UserAgent.isMac&&(a=a.replace("ctrl","cmd")),{shortcut:a,description:b,icon:c}},a.CheatsheetService.prototype.getDomFromDescriptor_=function(a){var b=pskl.utils.Template.get("cheatsheet-shortcut-template"),c=pskl.utils.Template.replace(b,{shortcutIcon:a.icon,shortcutDescription:a.description,shortcutKey:a.shortcut});return pskl.utils.Template.createFromHTML(c)},a.CheatsheetService.prototype.initMarkupAbstract_=function(a,b){for(var c=$(b,this.cheatsheetEl_).get(0),d=0;da?1:-1,i=d>c?1:-1,j=f-g;;){if(e.push({col:a,row:c}),a==b&&c==d)break;var k=2*j;k>-g&&(j-=g,a+=h),f>k&&(j+=f,c+=i)}return e}}(),function(){var a=$.namespace("pskl.drawingtools");a.ShapeTool=function(){this.startCol=null,this.startRow=null,this.tooltipDescriptors=[{key:"shift",description:"Keep 1 to 1 ratio"}]},pskl.utils.inherit(a.ShapeTool,a.BaseTool),a.ShapeTool.prototype.applyToolAt=function(a,b,c,d,e){$.publish(Events.DRAG_START,[a,b]),this.startCol=a,this.startRow=b,e.setPixel(a,b,c)},a.ShapeTool.prototype.moveToolAt=function(a,b,c,d,e,f){var g=this.getCoordinates_(a,b,f);$.publish(Events.CURSOR_MOVED,[g.col,g.row]),e.clear(),c==Constants.TRANSPARENT_COLOR&&(c=Constants.SELECTION_TRANSPARENT_COLOR),this.draw_(g.col,g.row,c,e)},a.ShapeTool.prototype.releaseToolAt=function(a,b,c,d,e,f){e.clear();var g=this.getCoordinates_(a,b,f);this.draw_(g.col,g.row,c,d),$.publish(Events.DRAG_END,[a,b]),this.raiseSaveStateEvent({col:a,row:b,startCol:this.startCol,startRow:this.startRow,color:c})},a.ShapeTool.prototype.replay=function(a,b){this.startCol=b.startCol,this.startRow=b.startRow,this.draw_(b.col,b.row,b.color,a)},a.ShapeTool.prototype.getCoordinates_=function(a,b,c){return c.shiftKey?this.getScaledCoordinates_(a,b):{col:a,row:b}},a.ShapeTool.prototype.getScaledCoordinates_=function(a,b){var c=this.startCol-a,d=Math.abs(c),e=this.startRow-b,f=Math.abs(e),g=Math.min(d,f);return b=this.startRow-e/f*g,a=this.startCol-c/d*g,{col:a,row:b}},a.ShapeTool.prototype.draw_=Constants.ABSTRACT_FUNCTION}(),function(){var a=$.namespace("pskl.drawingtools");a.SimplePen=function(){this.toolId="tool-pen",this.helpText="Pen tool",this.previousCol=null,this.previousRow=null,this.pixels=[]},pskl.utils.inherit(a.SimplePen,a.BaseTool),a.SimplePen.prototype.applyToolAt=function(a,b,c,d,e){this.previousCol=a,this.previousRow=b,e.setPixel(a,b,c),c===Constants.TRANSPARENT_COLOR&&d.setPixel(a,b,c),this.pixels.push({col:a,row:b,color:c})},a.SimplePen.prototype.moveToolAt=function(a,b,c,d,e,f){if(Math.abs(a-this.previousCol)>1||Math.abs(b-this.previousRow)>1)for(var g=this.getLinePixels_(a,this.previousCol,b,this.previousRow),h=0,i=g.length;i>h;h++){var j=g[h];this.applyToolAt(j.col,j.row,c,d,e,f)}else this.applyToolAt(a,b,c,d,e,f);this.previousCol=a,this.previousRow=b},a.SimplePen.prototype.releaseToolAt=function(a,b,c,d){this.setPixelsToFrame_(d,this.pixels),this.raiseSaveStateEvent({pixels:this.pixels.slice(0),color:c}),this.pixels=[]},a.SimplePen.prototype.replay=function(a,b){this.setPixelsToFrame_(a,b.pixels,b.color)},a.SimplePen.prototype.setPixelsToFrame_=function(a,b){b.forEach(function(b){a.setPixel(b.col,b.row,b.color)})}}(),function(){var a=$.namespace("pskl.drawingtools"),b=3;a.Lighten=function(){this.superclass.constructor.call(this),this.toolId="tool-lighten",this.helpText="Lighten",this.tooltipDescriptors=[{key:"ctrl",description:"Darken"},{key:"shift",description:"Apply only once per pixel"}],this.resetUsedPixels_()},pskl.utils.inherit(a.Lighten,a.SimplePen),a.Lighten.prototype.resetUsedPixels_=function(){this.usedPixels_={darken:{},lighten:{}}},a.Lighten.prototype.applyToolAt=function(a,c,d,e,f,g){var h=f.getPixel(a,c),i=e.getPixel(a,c),j=h===Constants.TRANSPARENT_COLOR?i:h,k=pskl.utils.UserAgent.isMac?g.metaKey:g.ctrlKey,l=g.shiftKey,m=j===Constants.TRANSPARENT_COLOR,n=k?this.usedPixels_.darken:this.usedPixels_.lighten,o=a+"-"+c,p=m||l&&n[o];if(p)d=j;else{var q=l?2*b:b;d=k?window.tinycolor.darken(j,q):window.tinycolor.lighten(j,q),d&&(n[o]=!0,this.superclass.applyToolAt.call(this,a,c,d.toRgbString(),e,f,g))}},a.Lighten.prototype.releaseToolAt=function(a,b,c,d){this.setPixelsToFrame_(d,this.pixels),this.resetUsedPixels_(),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})}}(),function(){var a=$.namespace("pskl.drawingtools");a.VerticalMirrorPen=function(){this.superclass.constructor.call(this),this.toolId="tool-vertical-mirror-pen",this.helpText="Vertical Mirror pen",this.tooltipDescriptors=[{key:"ctrl",description:"Use horizontal axis"},{key:"shift",description:"Use horizontal and vertical axis"}]},pskl.utils.inherit(a.VerticalMirrorPen,a.SimplePen),a.VerticalMirrorPen.prototype.backupPreviousPositions_=function(){this.backupPreviousCol=this.previousCol,this.backupPreviousRow=this.previousRow},a.VerticalMirrorPen.prototype.restorePreviousPositions_=function(){this.previousCol=this.backupPreviousCol,this.previousRow=this.backupPreviousRow},a.VerticalMirrorPen.prototype.applyToolAt=function(a,b,c,d,e,f){this.superclass.applyToolAt.call(this,a,b,c,d,e),this.backupPreviousPositions_();var g=this.getSymmetricCol_(a,d),h=this.getSymmetricRow_(b,d),i=pskl.utils.UserAgent.isMac?f.metaKey:f.ctrlKey;i||this.superclass.applyToolAt.call(this,g,b,c,d,e),(f.shiftKey||i)&&this.superclass.applyToolAt.call(this,a,h,c,d,e),f.shiftKey&&this.superclass.applyToolAt.call(this,g,h,c,d,e),this.restorePreviousPositions_()},a.VerticalMirrorPen.prototype.getSymmetricCol_=function(a,b){return b.getWidth()-a-1},a.VerticalMirrorPen.prototype.getSymmetricRow_=function(a,b){return b.getHeight()-a-1}}(),function(){var a=$.namespace("pskl.drawingtools");a.Eraser=function(){this.superclass.constructor.call(this),this.toolId="tool-eraser",this.helpText="Eraser tool"},pskl.utils.inherit(a.Eraser,a.SimplePen),a.Eraser.prototype.applyToolAt=function(a,b,c,d,e,f){this.superclass.applyToolAt.call(this,a,b,Constants.TRANSPARENT_COLOR,d,e,f)},a.Eraser.prototype.releaseToolAt=function(a,b,c,d,e,f){this.superclass.releaseToolAt.call(this,a,b,Constants.TRANSPARENT_COLOR,d,e,f)}}(),function(){var a=$.namespace("pskl.drawingtools");a.Stroke=function(){this.toolId="tool-stroke",this.helpText="Stroke tool",this.startCol=null,this.startRow=null},pskl.utils.inherit(a.Stroke,a.BaseTool),a.Stroke.prototype.applyToolAt=function(a,b,c,d,e){this.startCol=a,this.startRow=b,e.setPixel(a,b,c)},a.Stroke.prototype.moveToolAt=function(a,b,c,d,e){e.clear();for(var f=this.getLinePixels_(this.startCol,a,this.startRow,b),g=0;gi;i++)for(var j=0;h>j;j++){var k=i-a,l=j-b;e.shiftKey&&(k=(k+g)%g,l=(l+h)%h),f=d.containsPixel(k,l)?d.getPixel(k,l):Constants.TRANSPARENT_COLOR,c.setPixel(i,j,f)}},a.Move.prototype.releaseToolAt=function(a,b,c,d,e,f){this.moveToolAt(a,b,c,d,e,f),this.raiseSaveStateEvent({colDiff:a-this.startCol,rowDiff:b-this.startRow,shiftKey:f.shiftKey})},a.Move.prototype.replay=function(a,b){var c={shiftKey:b.shiftKey};this.shiftFrame(b.colDiff,b.rowDiff,a,a.clone(),c)}}(),function(){var a=$.namespace("pskl.drawingtools");a.BaseSelect=function(){this.secondaryToolId=pskl.drawingtools.Move.TOOL_ID,this.BodyRoot=$("body"),this.startCol=null,this.startRow=null,this.selection=null,this.tooltipDescriptors=[{description:"Drag the selection to move it. You may switch to other layers and frames."},{key:"ctrl+c",description:"Copy the selected area"},{key:"ctrl+v",description:"Paste the copied area"}]},pskl.utils.inherit(a.BaseSelect,a.BaseTool),a.BaseSelect.prototype.applyToolAt=function(a,b,c,d,e){this.startCol=a,this.startRow=b,this.lastCol=a,this.lastRow=b,this.isInSelection(a,b)?(this.mode="moveSelection",this.onSelectionDragStart_(a,b,c,d,e)):(this.mode="select",this.onSelectStart_(a,b,c,d,e))},a.BaseSelect.prototype.moveToolAt=function(a,b,c,d,e){"select"==this.mode?this.onSelect_(a,b,c,d,e):"moveSelection"==this.mode&&this.onSelectionDrag_(a,b,c,d,e)},a.BaseSelect.prototype.releaseToolAt=function(a,b,c,d,e){"select"==this.mode?this.onSelectEnd_(a,b,c,d,e):"moveSelection"==this.mode&&this.onSelectionDragEnd_(a,b,c,d,e)},a.BaseSelect.prototype.moveUnactiveToolAt=function(a,b,c,d,e){e.containsPixel(a,b)&&(this.isInSelection(a,b)?(this.BodyRoot.addClass(this.secondaryToolId),this.BodyRoot.removeClass(this.toolId)):(this.BodyRoot.addClass(this.toolId),this.BodyRoot.removeClass(this.secondaryToolId)))},a.BaseSelect.prototype.isInSelection=function(a,b){return this.selection&&this.selection.pixels.some(function(c){return c.col===a&&c.row===b})},a.BaseSelect.prototype.hideHighlightedPixel=function(){},a.BaseSelect.prototype.drawSelectionOnOverlay_=function(a){for(var b=this.selection.pixels,c=0,d=b.length;d>c;c++){var e=b[c],f=e.color&&e.color!==Constants.TRANSPARENT_COLOR,g=f?this.getTransparentVariant(e.color):Constants.SELECTION_TRANSPARENT_COLOR;a.setPixel(b[c].col,b[c].row,g)}},a.BaseSelect.prototype.getTransparentVariant=function(a){var b=window.tinycolor(a);return b=window.tinycolor.lighten(b,10),b.setAlpha(.5),b.toRgbString()},a.BaseSelect.prototype.onSelectStart_=function(){},a.BaseSelect.prototype.onSelect_=function(){},a.BaseSelect.prototype.onSelectEnd_=function(){},a.BaseSelect.prototype.onSelectionDragStart_=function(){},a.BaseSelect.prototype.onSelectionDrag_=function(a,b,c,d,e){var f=a-this.lastCol,g=b-this.lastRow;a-this.startCol,b-this.startRow,this.selection.move(f,g),e.clear(),this.drawSelectionOnOverlay_(e),this.lastCol=a,this.lastRow=b},a.BaseSelect.prototype.onSelectionDragEnd_=function(a,b,c,d,e){this.onSelectionDrag_(a,b,c,d,e)}}(),function(){var a=$.namespace("pskl.drawingtools");a.RectangleSelect=function(){this.toolId="tool-rectangle-select",this.helpText="Rectangle selection",a.BaseSelect.call(this),this.hasSelection=!1},pskl.utils.inherit(a.RectangleSelect,a.BaseSelect),a.RectangleSelect.prototype.onSelectStart_=function(a,b,c,d,e){this.hasSelection?(this.hasSelection=!1,e.clear(),$.publish(Events.SELECTION_DISMISSED)):(this.hasSelection=!0,$.publish(Events.DRAG_START,[a,b]),e.setPixel(a,b,c))},a.RectangleSelect.prototype.onSelect_=function(a,b,c,d,e){this.hasSelection&&(e.clear(),this.selection=new pskl.selection.RectangularSelection(this.startCol,this.startRow,a,b),$.publish(Events.SELECTION_CREATED,[this.selection]),this.drawSelectionOnOverlay_(e))},a.RectangleSelect.prototype.onSelectEnd_=function(a,b,c,d,e){this.hasSelection&&(this.onSelect_(a,b,c,d,e),$.publish(Events.DRAG_END,[a,b]))}}(),function(){var a=$.namespace("pskl.drawingtools");a.ShapeSelect=function(){this.toolId="tool-shape-select",this.helpText="Shape selection",a.BaseSelect.call(this)},pskl.utils.inherit(a.ShapeSelect,a.BaseSelect),a.ShapeSelect.prototype.onSelectStart_=function(a,b,c,d,e){$.publish(Events.SELECTION_DISMISSED),e.clear();var f=pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(d,a,b);this.selection=new pskl.selection.ShapeSelection(f),$.publish(Events.SELECTION_CREATED,[this.selection]),this.drawSelectionOnOverlay_(e)}}(),function(){var a=$.namespace("pskl.drawingtools");a.ColorPicker=function(){this.toolId="tool-colorpicker",this.helpText="Color picker"},pskl.utils.inherit(a.ColorPicker,a.BaseTool),a.ColorPicker.prototype.applyToolAt=function(a,b,c,d,e,f){if(d.containsPixel(a,b)){var g=d.getPixel(a,b);f.button==Constants.LEFT_BUTTON?$.publish(Events.SELECT_PRIMARY_COLOR,[g]):f.button==Constants.RIGHT_BUTTON&&$.publish(Events.SELECT_SECONDARY_COLOR,[g])}}}(),function(){var a=$.namespace("pskl.drawingtools");a.ColorSwap=function(){this.toolId="tool-colorswap",this.helpText="Paint all pixels of the same color",this.tooltipDescriptors=[{key:"ctrl",description:"Apply to all layers"},{key:"shift",description:"Apply to all frames"}]},pskl.utils.inherit(a.ColorSwap,a.BaseTool),a.ColorSwap.prototype.applyToolAt=function(a,b,c,d,e,f){if(d.containsPixel(a,b)){var g=d.getPixel(a,b),h=pskl.utils.UserAgent.isMac?f.metaKey:f.ctrlKey,i=f.shiftKey;this.swapColors(g,c,h,i),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})}},a.ColorSwap.prototype.swapColors=function(a,b,c,d){var e=function(c,d,e,f){c==a&&(f.pixels[d][e]=b)},f=pskl.app.piskelController.getCurrentLayer(),g=pskl.app.piskelController.getCurrentFrameIndex();pskl.app.piskelController.getPiskel().getLayers().forEach(function(a){(c||a===f)&&a.getFrames().forEach(function(a,b){(d||b===g)&&(a.forEachPixel(e),a.version++)})})}}(),function(){var a=$.namespace("pskl");a.app={init:function(){this.isAppEngineVersion=!!pskl.appEngineToken_,this.shortcutService=new pskl.service.keyboard.ShortcutService,this.shortcutService.init();var a={height:Constants.DEFAULT.HEIGHT,width:Constants.DEFAULT.WIDTH},b=new pskl.model.piskel.Descriptor("New Piskel",""),c=new pskl.model.Piskel(a.width,a.height,b),d=new pskl.model.Layer("Layer 1"),e=new pskl.model.Frame(a.width,a.height); d.addFrame(e),c.addLayer(d),this.corePiskelController=new pskl.controller.piskel.PiskelController(c),this.corePiskelController.init(),this.piskelController=new pskl.controller.piskel.PublicPiskelController(this.corePiskelController),this.piskelController.init(),this.paletteController=new pskl.controller.PaletteController,this.paletteController.init(),this.currentColorsService=new pskl.service.CurrentColorsService(this.piskelController),this.currentColorsService.init(),this.palettesListController=new pskl.controller.PalettesListController(this.paletteController,this.currentColorsService),this.palettesListController.init(),this.cursorCoordinatesController=new pskl.controller.CursorCoordinatesController(this.piskelController),this.cursorCoordinatesController.init(),this.drawingController=new pskl.controller.DrawingController(this.piskelController,this.paletteController,$("#drawing-canvas-container")),this.drawingController.init(),this.animationController=new pskl.controller.AnimatedPreviewController(this.piskelController,$("#animated-preview-canvas-container")),this.animationController.init(),this.minimapController=new pskl.controller.MinimapController(this.piskelController,this.animationController,this.drawingController,$("#animated-preview-canvas-container")),this.minimapController.init(),this.previewFilmController=new pskl.controller.PreviewFilmController(this.piskelController,$("#preview-list")),this.previewFilmController.init(),this.layersListController=new pskl.controller.LayersListController(this.piskelController),this.layersListController.init(),this.settingsController=new pskl.controller.settings.SettingsController(this.piskelController),this.settingsController.init(),this.dialogsController=new pskl.controller.dialogs.DialogsController(this.piskelController),this.dialogsController.init(),this.toolController=new pskl.controller.ToolController,this.toolController.init(),this.selectionManager=new pskl.selection.SelectionManager(this.piskelController),this.selectionManager.init(),this.historyService=new pskl.service.HistoryService(this.corePiskelController),this.historyService.init(),this.notificationController=new pskl.controller.NotificationController,this.notificationController.init(),this.canvasBackgroundController=new pskl.controller.CanvasBackgroundController,this.canvasBackgroundController.init(),this.localStorageService=new pskl.service.LocalStorageService(this.piskelController),this.localStorageService.init(),this.imageUploadService=new pskl.service.ImageUploadService,this.imageUploadService.init(),this.cheatsheetService=new pskl.service.keyboard.CheatsheetService,this.cheatsheetService.init(),this.savedStatusService=new pskl.service.SavedStatusService(this.piskelController),this.savedStatusService.init(),this.backupService=new pskl.service.BackupService(this.piskelController),this.backupService.init(),this.beforeUnloadService=new pskl.service.BeforeUnloadService(this.piskelController),this.beforeUnloadService.init(),this.fileDropperService=new pskl.service.FileDropperService(this.piskelController,$("#drawing-canvas-container").get(0)),this.fileDropperService.init(),this.storageService=this.isAppEngineVersion?new pskl.service.AppEngineStorageService(this.piskelController):new pskl.service.GithubStorageService(this.piskelController),this.storageService.init();var f=new pskl.rendering.DrawingLoop;f.addCallback(this.render,this),f.start(),this.initTooltips_();var g=this.getPiskelInitData_();g&&g.piskel&&this.loadPiskel_(g.piskel,g.descriptor,g.fps)},loadPiskel_:function(a,b,c){pskl.utils.serialization.Deserializer.deserialize(a,function(a){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)})},getPiskelInitData_:function(){return pskl.appEnginePiskelData_},isLoggedIn:function(){var a=this.getPiskelInitData_();return a&&a.isLoggedIn},initTooltips_:function(){$("body").tooltip({selector:"[rel=tooltip]"})},render:function(a){this.drawingController.render(a),this.animationController.render(a),this.previewFilmController.render(a)},getFirstFrameAsPng:function(){var a=this.piskelController.getFrameAt(0),b=new pskl.rendering.CanvasRenderer(a,1);b.drawTransparentAs("rgba(0,0,0,0)");var c=b.render();return c.toDataURL("image/png")},getFramesheetAsPng:function(){var a=new pskl.rendering.PiskelRenderer(this.piskelController),b=a.renderAsCanvas();return b.toDataURL("image/png")}}}(); \ No newline at end of file diff --git a/js/piskel-packaged-min.js b/js/piskel-packaged-min.js index a3495f01..050fdde2 100644 --- a/js/piskel-packaged-min.js +++ b/js/piskel-packaged-min.js @@ -8,6 +8,6 @@ h.append(e),c.blob=0===h.getBlob("application/zip").size}catch(f){c.blob=!1}}}}, a.ok?H(a):Cb.addClass("sp-validation-error")}function B(){$?F():C()}function C(){var c=b.Event("beforeShow.spectrum");return $?(O(),void 0):(Nb=I(),sb.trigger(c,[Nb]),Y.beforeShow(Nb)===!1||c.isDefaultPrevented()||(H(Nb),e(),$=!0,b(rb).bind("mousedown.spectrum",D),b(rb).bind("mouseup.spectrum",E),b(a).bind("resize.spectrum",Z),Jb.addClass("sp-active"),ub.removeClass("sp-hidden"),T.showPalette&&w(),O(),L(),x(),Y.show(Nb),sb.trigger("show.spectrum",[Nb])),void 0)}function D(a){var c=b(a.target),d=c.parents(),e=!d.is(ub)&&!c.is(ub);e&&F(a)}function E(a){var b=!u.equals(I(),Nb);b&&(Qb&&"cancel"!==a?N(!0):G())}function F(c){c&&"click"==c.type&&2==c.button||$&&!U&&($=!1,b(rb).unbind("mousedown.spectrum",D),b(rb).unbind("mouseup.spectrum",E),b(a).unbind("resize.spectrum",Z),Jb.removeClass("sp-active"),ub.addClass("sp-hidden"),E(c),t(I()),Y.hide(I()),sb.trigger("hide.spectrum",[I()]))}function G(){H(Nb,!0)}function H(a,b){if(!u.equals(a,I())){var c=u(a),d=c.toHsv();hb=d.h%360/360,ib=d.s,jb=d.v,kb=d.a,L(),c.ok&&!b&&(Pb=Ob||c.format)}}function I(a){return a=a||{},u.fromRatio({h:hb,s:ib,v:jb,a:Math.round(100*kb)/100},{format:a.format||Pb})}function J(){return!Cb.hasClass("sp-validation-error")}function K(){L(),Y.move(I()),sb.trigger("move.spectrum",[I()])}function L(){Cb.removeClass("sp-validation-error"),M();var a=u.fromRatio({h:hb,s:1,v:1});vb.css("background-color",a.toHexString());var b=Pb;1>kb&&("hex"===b||"hex3"===b||"hex6"===b||"name"===b)&&(b="rgb");var c=I({format:b}),d=c.toHexString(),e=c.toRgbString();if(q||1===c.alpha?Lb.css("background-color",e):(Lb.css("background-color","transparent"),Lb.css("filter",c.toFilter())),T.showAlpha){var f=c.toRgb();f.a=0;var g=u(f).toRgbString(),h="linear-gradient(left, "+g+", "+d+")";p?zb.css("filter",u(g).toFilter({gradientType:1},d)):(zb.css("background","-webkit-"+h),zb.css("background","-moz-"+h),zb.css("background","-ms-"+h),zb.css("background",h))}T.showInput&&Cb.val(c.toString(Constants.PREFERRED_COLOR_FORMAT||b)),T.showPalette&&w(),x()}function M(){var a=ib,b=jb,c=a*_,d=ab-b*ab;c=Math.max(-bb/2,Math.min(_-bb/2,c-bb/2)),d=Math.max(-bb/2,Math.min(ab-bb/2,d-bb/2)),wb.css({top:d,left:c});var e=kb*eb;Bb.css({left:e-fb/2});var f=hb*cb;yb.css({top:f-gb/2})}function N(a){var b=I();Hb&&sb.val(b.toString(Pb));var c=!u.equals(b,Nb);Nb=b,a&&c&&(Y.change(b),sb.trigger("change",[b]))}function O(){_=vb.width(),ab=vb.height(),bb=wb.height()+4,db=xb.width(),cb=xb.height(),gb=yb.height()+4,eb=Ab.width(),fb=Bb.width(),U||(ub.css("position","absolute"),ub.offset(h(ub,Kb))),M()}function P(){sb.show(),Kb.unbind("click.spectrum touchstart.spectrum"),ub.remove(),Jb.remove(),o[Rb.id]=null}function Q(a,d){return a===c?b.extend({},T):d===c?T[a]:(T[a]=d,k(),void 0)}function R(){tb=!1,sb.attr("disabled",!1),Kb.removeClass("sp-disabled")}function S(){F(),tb=!0,sb.attr("disabled",!0),Kb.addClass("sp-disabled")}var T=f(i,g),U=T.flat,V=T.showSelectionPalette,W=T.localStorageKey,X=T.theme,Y=T.callbacks,Z=m(O,10),$=!1,_=0,ab=0,bb=0,cb=0,db=0,eb=0,fb=0,gb=0,hb=0,ib=0,jb=0,kb=1,lb=T.palette.slice(0),mb=b.isArray(lb[0])?lb:[lb],nb=T.selectionPalette.slice(0),ob=T.maxSelectionSize,pb="sp-dragging",qb=null,rb=g.ownerDocument,sb=(rb.body,b(g)),tb=!1,ub=b(s,rb).addClass(X),vb=ub.find(".sp-color"),wb=ub.find(".sp-dragger"),xb=ub.find(".sp-hue"),yb=ub.find(".sp-slider"),zb=ub.find(".sp-alpha-inner"),Ab=ub.find(".sp-alpha"),Bb=ub.find(".sp-alpha-handle"),Cb=ub.find(".sp-input"),Db=ub.find(".sp-palette"),Eb=ub.find(".sp-initial"),Fb=ub.find(".sp-cancel"),Gb=ub.find(".sp-choose"),Hb=sb.is("input"),Ib=Hb&&!U,Jb=Ib?b(r).addClass(X).addClass(T.className):b([]),Kb=Ib?Jb:sb,Lb=Jb.find(".sp-preview-inner"),Mb=T.color||Hb&&sb.val(),Nb=!1,Ob=T.preferredFormat,Pb=Ob,Qb=!T.showButtons||T.clickoutFiresChange;n();var Rb={show:C,hide:F,toggle:B,reflow:O,option:Q,enable:R,disable:S,set:function(a){H(a),N()},get:I,destroy:P,container:ub};return Rb.id=o.push(Rb)-1,Rb}function h(a,c){var d=0,e=a.outerWidth(),f=a.outerHeight(),g=c.outerHeight(),h=a[0].ownerDocument,i=h.documentElement,j=i.clientWidth+b(h).scrollLeft(),k=i.clientHeight+b(h).scrollTop(),l=c.offset();return l.top+=g,Math.min(l.left,l.left+e>j&&j>e)?(l.left-=Math.abs(l.left+e-j),a.attr("data-x-position","right")):(l.left-=0,a.attr("data-x-position","left")),Math.min(l.top,l.top+f>k&&k>f)?(l.top-=Math.abs(f+g-d),a.attr("data-y-position","top")):(l.top-=d,a.attr("data-y-position","bottom")),l}function i(){}function j(a){a.stopPropagation()}function k(a,b){var c=Array.prototype.slice,d=c.call(arguments,2);return function(){return a.apply(b,d.concat(c.call(arguments)))}}function l(c,d,e,f){function g(a){a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),a.returnValue=!1}function h(a){if(l){if(p&&document.documentMode<9&&!a.button)return j();var b=a.originalEvent.touches,e=b?b[0].pageX:a.pageX,f=b?b[0].pageY:a.pageY,h=Math.max(0,Math.min(e-m.left,o)),i=Math.max(0,Math.min(f-m.top,n));q&&g(a),d.apply(c,[h,i,a])}}function i(a){var d=a.which?3==a.which:2==a.button;a.originalEvent.touches,d||l||e.apply(c,arguments)!==!1&&(l=!0,n=b(c).height(),o=b(c).width(),m=b(c).offset(),b(k).bind(r),b(k.body).addClass("sp-dragging"),q||h(a),g(a))}function j(){l&&(b(k).unbind(r),b(k.body).removeClass("sp-dragging"),f.apply(c,arguments)),l=!1}d=d||function(){},e=e||function(){},f=f||function(){};var k=c.ownerDocument||document,l=!1,m={},n=0,o=0,q="ontouchstart"in a,r={};r.selectstart=g,r.dragstart=g,r["touchmove mousemove"]=h,r["touchend mouseup"]=j,b(c).bind("touchstart mousedown",i)}function m(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d),(c||!d)&&(d=setTimeout(g,b))}}var n={beforeShow:i,move:i,change:i,show:i,hide:i,color:!1,flat:!1,showInput:!1,showButtons:!0,clickoutFiresChange:!1,showInitial:!1,showPalette:!1,showPaletteOnly:!1,showSelectionPalette:!0,localStorageKey:!1,appendTo:"body",maxSelectionSize:7,cancelText:"cancel",chooseText:"choose",preferredFormat:!1,className:"",showAlpha:!1,theme:"sp-light",palette:["fff","000"],selectionPalette:[],disabled:!1},o=[],p=!!/msie/i.exec(a.navigator.userAgent),q=function(){function a(a,b){return!!~(""+a).indexOf(b)}var b=document.createElement("div"),c=b.style;return c.cssText="background-color:rgba(0,0,0,.5)",a(c.backgroundColor,"rgba")||a(c.backgroundColor,"hsla")}(),r=["
    ","
    ","
    ","
    "].join(""),s=function(){var a="";if(p)for(var b=1;6>=b;b++)a+="
    ";return["
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ","
    ",a,"
    ","
    ","
    ","
    ","
    ","","
    ","
    ","
    ","","","
    ","
    ","
    "].join("")}(),t="spectrum.id";b.fn.spectrum=function(a){if("string"==typeof a){var c=this,d=Array.prototype.slice.call(arguments,1);return this.each(function(){var e=o[b(this).data(t)];if(e){var f=e[a];if(!f)throw new Error("Spectrum: no such method: '"+a+"'");"get"==a?c=e.get():"container"==a?c=e.container:"option"==a?c=e.option.apply(e,d):"destroy"==a?(e.destroy(),b(this).removeData(t)):f.apply(e,d)}}),c}return this.spectrum("destroy").each(function(){var c=g(this,a);b(this).data(t,c.id)})},b.fn.spectrum.load=!0,b.fn.spectrum.loadOpts={},b.fn.spectrum.draggable=l,b.fn.spectrum.defaults=n,b.spectrum={},b.spectrum.localization={},b.spectrum.palettes={},b.fn.spectrum.processNativeColorInputs=function(){var a=b("")[0],c="color"===a.type&&"!"!=a.value;c||b("input[type=color]").spectrum({preferredFormat:"hex6"})},function(){function b(a,d){if(a=a?a:"",d=d||{},"object"==typeof a&&a.hasOwnProperty("_tc_id"))return a;var f=c(a),h=f.r,j=f.g,m=f.b,n=f.a,o=x(100*n)/100,p=d.format||f.format;return 1>h&&(h=x(h)),1>j&&(j=x(j)),1>m&&(m=x(m)),{ok:f.ok,format:p,_tc_id:v++,alpha:n,getAlpha:function(){return n},setAlpha:function(a){n=k(a),o=x(100*n)/100},toHsv:function(){var a=g(h,j,m);return{h:360*a.h,s:a.s,v:a.v,a:n}},toHsvString:function(){var a=g(h,j,m),b=x(360*a.h),c=x(100*a.s),d=x(100*a.v);return 1==n?"hsv("+b+", "+c+"%, "+d+"%)":"hsva("+b+", "+c+"%, "+d+"%, "+o+")"},toHsl:function(){var a=e(h,j,m);return{h:360*a.h,s:a.s,l:a.l,a:n}},toHslString:function(){var a=e(h,j,m),b=x(360*a.h),c=x(100*a.s),d=x(100*a.l);return 1==n?"hsl("+b+", "+c+"%, "+d+"%)":"hsla("+b+", "+c+"%, "+d+"%, "+o+")"},toHex:function(a){return i(h,j,m,a)},toHexString:function(a){return"#"+i(h,j,m,a)},toRgb:function(){return{r:x(h),g:x(j),b:x(m),a:n}},toRgbString:function(){return 1==n?"rgb("+x(h)+", "+x(j)+", "+x(m)+")":"rgba("+x(h)+", "+x(j)+", "+x(m)+", "+o+")"},toPercentageRgb:function(){return{r:x(100*l(h,255))+"%",g:x(100*l(j,255))+"%",b:x(100*l(m,255))+"%",a:n}},toPercentageRgbString:function(){return 1==n?"rgb("+x(100*l(h,255))+"%, "+x(100*l(j,255))+"%, "+x(100*l(m,255))+"%)":"rgba("+x(100*l(h,255))+"%, "+x(100*l(j,255))+"%, "+x(100*l(m,255))+"%, "+o+")"},toName:function(){return 0===n?"transparent":C[i(h,j,m,!0)]||!1},toFilter:function(a){var c=i(h,j,m),e=c,f=Math.round(255*parseFloat(n)).toString(16),g=f,k=d&&d.gradientType?"GradientType = 1, ":"";if(a){var l=b(a);e=l.toHex(),g=Math.round(255*parseFloat(l.alpha)).toString(16)}return"progid:DXImageTransform.Microsoft.gradient("+k+"startColorstr=#"+q(f)+c+",endColorstr=#"+q(g)+e+")"},toString:function(a){var b=!!a;a=a||this.format;var c=!1,d=!b&&1>n&&n>0,e=d&&("hex"===a||"hex6"===a||"hex3"===a||"name"===a);return"rgb"===a&&(c=this.toRgbString()),"prgb"===a&&(c=this.toPercentageRgbString()),("hex"===a||"hex6"===a)&&(c=this.toHexString()),"hex3"===a&&(c=this.toHexString(!0)),"name"===a&&(c=this.toName()),"hsl"===a&&(c=this.toHslString()),"hsv"===a&&(c=this.toHsvString()),e?this.toRgbString():c||this.toHexString()}}}function c(a){var b={r:0,g:0,b:0},c=1,e=!1,g=!1;return"string"==typeof a&&(a=s(a)),"object"==typeof a&&(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b")?(b=d(a.r,a.g,a.b),e=!0,g="%"===String(a.r).substr(-1)?"prgb":"rgb"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")?(a.s=r(a.s),a.v=r(a.v),b=h(a.h,a.s,a.v),e=!0,g="hsv"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=r(a.s),a.l=r(a.l),b=f(a.h,a.s,a.l),e=!0,g="hsl"),a.hasOwnProperty("a")&&(c=a.a)),c=k(c),{ok:e,format:a.format||g,r:y(255,z(b.r,0)),g:y(255,z(b.g,0)),b:y(255,z(b.b,0)),a:c}}function d(a,b,c){return{r:255*l(a,255),g:255*l(b,255),b:255*l(c,255)}}function e(a,b,c){a=l(a,255),b=l(b,255),c=l(c,255);var d,e,f=z(a,b,c),g=y(a,b,c),h=(f+g)/2;if(f==g)d=e=0;else{var i=f-g;switch(e=h>.5?i/(2-f-g):i/(f+g),f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,l:h}}function f(a,b,c){function d(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+6*(b-a)*(2/3-c):a}var e,f,g;if(a=l(a,360),b=l(b,100),c=l(c,100),0===b)e=f=g=c;else{var h=.5>c?c*(1+b):c+b-c*b,i=2*c-h;e=d(i,h,a+1/3),f=d(i,h,a),g=d(i,h,a-1/3)}return{r:255*e,g:255*f,b:255*g}}function g(a,b,c){a=l(a,255),b=l(b,255),c=l(c,255);var d,e,f=z(a,b,c),g=y(a,b,c),h=f,i=f-g;if(e=0===f?0:i/f,f==g)d=0;else{switch(f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,v:h}}function h(a,b,c){a=6*l(a,360),b=l(b,100),c=l(c,100);var d=w.floor(a),e=a-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i=d%6,j=[c,g,f,f,h,c][i],k=[h,c,c,g,f,f][i],m=[f,f,h,c,c,g][i];return{r:255*j,g:255*k,b:255*m}}function i(a,b,c,d){var e=[q(x(a).toString(16)),q(x(b).toString(16)),q(x(c).toString(16))];return d&&e[0].charAt(0)==e[0].charAt(1)&&e[1].charAt(0)==e[1].charAt(1)&&e[2].charAt(0)==e[2].charAt(1)?e[0].charAt(0)+e[1].charAt(0)+e[2].charAt(0):e.join("")}function j(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[a[c]]=c);return b}function k(a){return a=parseFloat(a),(isNaN(a)||0>a||a>1)&&(a=1),a}function l(a,b){o(a)&&(a="100%");var c=p(a);return a=y(b,z(0,parseFloat(a))),c&&(a=parseInt(a*b,10)/100),w.abs(a-b)<1e-6?1:a%b/parseFloat(b)}function m(a){return y(1,z(0,a))}function n(a){return parseInt(a,16)}function o(a){return"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)}function p(a){return"string"==typeof a&&-1!=a.indexOf("%")}function q(a){return 1==a.length?"0"+a:""+a}function r(a){return 1>=a&&(a=100*a+"%"),a}function s(a){a=a.replace(t,"").replace(u,"").toLowerCase();var b=!1;if(B[a])a=B[a],b=!0;else if("transparent"==a)return{r:0,g:0,b:0,a:0,format:"name"};var c;return(c=D.rgb.exec(a))?{r:c[1],g:c[2],b:c[3]}:(c=D.rgba.exec(a))?{r:c[1],g:c[2],b:c[3],a:c[4]}:(c=D.hsl.exec(a))?{h:c[1],s:c[2],l:c[3]}:(c=D.hsla.exec(a))?{h:c[1],s:c[2],l:c[3],a:c[4]}:(c=D.hsv.exec(a))?{h:c[1],s:c[2],v:c[3]}:(c=D.hex6.exec(a))?{r:n(c[1]),g:n(c[2]),b:n(c[3]),format:b?"name":"hex"}:(c=D.hex3.exec(a))?{r:n(c[1]+""+c[1]),g:n(c[2]+""+c[2]),b:n(c[3]+""+c[3]),format:b?"name":"hex"}:!1}var t=/^[\s,#]+/,u=/\s+$/,v=0,w=Math,x=w.round,y=w.min,z=w.max,A=w.random;b.fromRatio=function(a,c){if("object"==typeof a){var d={};for(var e in a)a.hasOwnProperty(e)&&(d[e]="a"===e?a[e]:r(a[e]));a=d}return b(a,c)},b.equals=function(a,c){return a&&c?b(a).toRgbString()==b(c).toRgbString():!1},b.random=function(){return b.fromRatio({r:A(),g:A(),b:A()})},b.desaturate=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.s-=c/100,d.s=m(d.s),b(d)},b.saturate=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.s+=c/100,d.s=m(d.s),b(d)},b.greyscale=function(a){return b.desaturate(a,100)},b.lighten=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.l+=c/100,d.l=m(d.l),b(d)},b.darken=function(a,c){c=0===c?0:c||10;var d=b(a).toHsl();return d.l-=c/100,d.l=m(d.l),b(d)},b.complement=function(a){var c=b(a).toHsl();return c.h=(c.h+180)%360,b(c)},b.triad=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+120)%360,s:c.s,l:c.l}),b({h:(d+240)%360,s:c.s,l:c.l})]},b.tetrad=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+90)%360,s:c.s,l:c.l}),b({h:(d+180)%360,s:c.s,l:c.l}),b({h:(d+270)%360,s:c.s,l:c.l})]},b.splitcomplement=function(a){var c=b(a).toHsl(),d=c.h;return[b(a),b({h:(d+72)%360,s:c.s,l:c.l}),b({h:(d+216)%360,s:c.s,l:c.l})]},b.analogous=function(a,c,d){c=c||6,d=d||30;var e=b(a).toHsl(),f=360/d,g=[b(a)];for(e.h=(e.h-(f*c>>1)+720)%360;--c;)e.h=(e.h+f)%360,g.push(b(e));return g},b.monochromatic=function(a,c){c=c||6;for(var d=b(a).toHsv(),e=d.h,f=d.s,g=d.v,h=[],i=1/c;c--;)h.push(b({h:e,s:f,v:g})),g=(g+i)%1;return h},b.readability=function(a,c){var d=b(a).toRgb(),e=b(c).toRgb(),f=(299*d.r+587*d.g+114*d.b)/1e3,g=(299*e.r+587*e.g+114*e.b)/1e3,h=Math.max(d.r,e.r)-Math.min(d.r,e.r)+Math.max(d.g,e.g)-Math.min(d.g,e.g)+Math.max(d.b,e.b)-Math.min(d.b,e.b);return{brightness:Math.abs(f-g),color:h}},b.readable=function(a,c){var d=b.readability(a,c);return d.brightness>125&&d.color>500},b.mostReadable=function(a,c){for(var d=null,e=0,f=!1,g=0;g125&&h.color>500,j=3*(h.brightness/125)+h.color/500;(i&&!f||i&&f&&j>e||!i&&!f&&j>e)&&(f=i,e=j,d=b(c[g]))}return d};var B=b.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},C=b.hexNames=j(B),D=function(){var a="[-\\+]?\\d+%?",b="[-\\+]?\\d*\\.\\d+%?",c="(?:"+b+")|(?:"+a+")",d="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?",e="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?";return{rgb:new RegExp("rgb"+d),rgba:new RegExp("rgba"+e),hsl:new RegExp("hsl"+d),hsla:new RegExp("hsla"+e),hsv:new RegExp("hsv"+d),hex3:/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();a.tinycolor=b}();var u=a.tinycolor;b(function(){b.fn.spectrum.load&&b.fn.spectrum.processNativeColorInputs()})}(window,jQuery),function(){var a=$.namespace("pskl.rendering");a.DrawingLoop=function(){this.requestAnimationFrame=this.getRequestAnimationFrameShim_(),this.isRunning=!1,this.previousTime=0,this.callbacks=[]},a.DrawingLoop.prototype.addCallback=function(a,b,c){var d={fn:a,scope:b,args:c};return this.callbacks.push(d),d},a.DrawingLoop.prototype.removeCallback=function(a){var b=this.callbacks.indexOf(a);-1!=b&&this.callbacks.splice(b,1)},a.DrawingLoop.prototype.start=function(){this.isRunning=!0,this.loop_()},a.DrawingLoop.prototype.loop_=function(){var a=Date.now(),b=a-this.previousTime;this.executeCallbacks_(b),this.previousTime=a,this.requestAnimationFrame.call(window,this.loop_.bind(this))},a.DrawingLoop.prototype.executeCallbacks_=function(a){for(var b=0;bd;d++){for(var e=[],f=0;b>f;f++)e.push(Constants.TRANSPARENT_COLOR);c[d]=e}return c},a.Frame.createEmptyFromFrame=function(b){return new a.Frame(b.getWidth(),b.getHeight())},a.Frame.prototype.clone=function(){var b=new a.Frame(this.width,this.height);return b.setPixels(this.getPixels()),b},a.Frame.prototype.getPixels=function(){return this.clonePixels_(this.pixels)},a.Frame.prototype.setPixels=function(a){this.pixels=this.clonePixels_(a),this.version++},a.Frame.prototype.clear=function(){var b=a.Frame.createEmptyPixelGrid_(this.getWidth(),this.getHeight());this.setPixels(b)},a.Frame.prototype.clonePixels_=function(a){for(var b=[],c=0;cd;d++)for(var e=0;c>e;e++)a(this.pixels[d][e],d,e,this)},a.Frame.prototype.getWidth=function(){return this.width},a.Frame.prototype.getHeight=function(){return this.height},a.Frame.prototype.containsPixel=function(a,b){return a>=0&&b>=0&&a0&&a[0].length()>0))throw"Piskel.fromLayers expects array of non empty pskl.model.Layer as first argument";var d=a[0].getFrameAt(0);return c=new pskl.model.Piskel(d.getWidth(),d.getHeight(),b),a.forEach(c.addLayer.bind(c)),c},a.Piskel.prototype.getLayers=function(){return this.layers},a.Piskel.prototype.getHeight=function(){return this.height},a.Piskel.prototype.getWidth=function(){return this.width},a.Piskel.prototype.getLayers=function(){return this.layers},a.Piskel.prototype.getLayerAt=function(a){return this.layers[a]},a.Piskel.prototype.getLayersByName=function(a){return this.layers.filter(function(b){return b.getName()==a})},a.Piskel.prototype.addLayer=function(a){this.layers.push(a)},a.Piskel.prototype.moveLayerUp=function(a){var b=this.layers.indexOf(a);b>-1&&b0&&(this.layers[b]=this.layers[b-1],this.layers[b-1]=a)},a.Piskel.prototype.removeLayer=function(a){var b=this.layers.indexOf(a);-1!=b&&this.layers.splice(b,1)},a.Piskel.prototype.removeLayerAt=function(a){this.layers.splice(a,1)},a.Piskel.prototype.getDescriptor=function(){return this.descriptor},a.Piskel.prototype.setDescriptor=function(a){this.descriptor=a,$(".piskel-name").html(this.descriptor.name)},a.Piskel.prototype.getHash=function(){return this.layers.map(function(a){return a.getHash()}).join("-")}}(),function(){var a=$.namespace("pskl.selection"),b={PASTE:"REPLAY_PASTE",ERASE:"REPLAY_ERASE"};a.SelectionManager=function(a){this.piskelController=a,this.currentSelection=null},a.SelectionManager.prototype.init=function(){$.subscribe(Events.SELECTION_CREATED,$.proxy(this.onSelectionCreated_,this)),$.subscribe(Events.SELECTION_DISMISSED,$.proxy(this.onSelectionDismissed_,this)),$.subscribe(Events.SELECTION_MOVE_REQUEST,$.proxy(this.onSelectionMoved_,this)),pskl.app.shortcutService.addShortcut("ctrl+V",this.paste.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+X",this.cut.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+C",this.copy.bind(this)),pskl.app.shortcutService.addShortcut("del",this.erase.bind(this)),pskl.app.shortcutService.addShortcut("back",this.onBackPressed_.bind(this)),$.subscribe(Events.TOOL_SELECTED,$.proxy(this.onToolSelected_,this))},a.SelectionManager.prototype.cleanSelection_=function(){this.currentSelection&&(this.currentSelection.reset(),this.currentSelection=null)},a.SelectionManager.prototype.onToolSelected_=function(a,b){var c=b instanceof pskl.drawingtools.BaseSelect;c||this.cleanSelection_()},a.SelectionManager.prototype.onSelectionDismissed_=function(){this.cleanSelection_()},a.SelectionManager.prototype.onBackPressed_=function(){return this.currentSelection?(this.erase(),void 0):!0},a.SelectionManager.prototype.erase=function(){for(var a=this.currentSelection.pixels,c=this.piskelController.getCurrentFrame(),d=0,e=a.length;e>d;d++)c.setPixel(a[d].col,a[d].row,Constants.TRANSPARENT_COLOR);$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{type:b.ERASE,pixels:JSON.parse(JSON.stringify(a.slice(0)))}})},a.SelectionManager.prototype.cut=function(){if(!this.currentSelection)throw"Bad state for CUT callback in SelectionManager";this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame()),this.erase()},a.SelectionManager.prototype.paste=function(){if(this.currentSelection&&this.currentSelection.hasPastedContent){var a=this.currentSelection.pixels,b=a.filter(function(a){return a.color!==Constants.TRANSPARENT_COLOR});this.pastePixels(b)}},a.SelectionManager.prototype.pastePixels=function(a){var c=this.piskelController.getCurrentFrame();$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{type:b.PASTE,pixels:JSON.parse(JSON.stringify(a.slice(0)))}}),a.forEach(function(a){c.setPixel(a.col,a.row,a.color)})},a.SelectionManager.prototype.replay=function(a,c){var d=c.pixels;d.forEach(function(d){var e=c.type===b.PASTE?d.color:Constants.TRANSPARENT_COLOR;a.setPixel(d.col,d.row,e)})},a.SelectionManager.prototype.copy=function(){if(!this.currentSelection||!this.piskelController.getCurrentFrame())throw"Bad state for CUT callback in SelectionManager";this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame())},a.SelectionManager.prototype.onSelectionCreated_=function(a,b){if(!b)throw"No selection set in SelectionManager";this.currentSelection=b},a.SelectionManager.prototype.onSelectionMoved_=function(a,b,c){if(!this.currentSelection)throw"Bad state: No currentSelection set when trying to move it in SelectionManager";this.currentSelection.move(b,c)}}(),function(){var a=$.namespace("pskl.selection");a.BaseSelection=function(){this.reset()},a.BaseSelection.prototype.reset=function(){this.pixels=[],this.hasPastedContent=!1},a.BaseSelection.prototype.move=function(a,b){for(var c,d=[],e=0,f=this.pixels.length;f>e;e++)c=this.pixels[e],c.col+=a,c.row+=b,d.push(c);this.pixels=d},a.BaseSelection.prototype.fillSelectionFromFrame=function(a){this.pixels.forEach(function(b){b.color=a.getPixel(b.col,b.row)}),this.hasPastedContent=!0}}(),function(){var a=$.namespace("pskl.selection");a.RectangularSelection=function(a,b,c,d){this.pixels=pskl.PixelUtils.getRectanglePixels(a,b,c,d)},pskl.utils.inherit(a.RectangularSelection,a.BaseSelection)}(),function(){var a=$.namespace("pskl.selection");a.ShapeSelection=function(a){this.pixels=a},pskl.utils.inherit(a.ShapeSelection,a.BaseSelection)}(),function(){var a=$.namespace("pskl.rendering");a.AbstractRenderer=function(){},a.AbstractRenderer.prototype.clear=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.render=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getCoordinates=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setGridWidth=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getGridWidth=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setZoom=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getZoom=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setOffset=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getOffset=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.setDisplaySize=Constants.ABSTRACT_FUNCTION,a.AbstractRenderer.prototype.getDisplaySize=Constants.ABSTRACT_FUNCTION}(),function(){var a=$.namespace("pskl.rendering");a.CompositeRenderer=function(){this.renderers=[]},pskl.utils.inherit(pskl.rendering.CompositeRenderer,pskl.rendering.AbstractRenderer),a.CompositeRenderer.prototype.add=function(a){return this.renderers.push(a),this},a.CompositeRenderer.prototype.clear=function(){this.renderers.forEach(function(a){a.clear()})},a.CompositeRenderer.prototype.setZoom=function(a){this.renderers.forEach(function(b){b.setZoom(a) })},a.CompositeRenderer.prototype.getZoom=function(){return this.getSampleRenderer_().getZoom()},a.CompositeRenderer.prototype.setDisplaySize=function(a,b){this.renderers.forEach(function(c){c.setDisplaySize(a,b)})},a.CompositeRenderer.prototype.getDisplaySize=function(){return this.getSampleRenderer_().getDisplaySize()},a.CompositeRenderer.prototype.setOffset=function(a,b){this.renderers.forEach(function(c){c.setOffset(a,b)})},a.CompositeRenderer.prototype.getOffset=function(){return this.getSampleRenderer_().getOffset()},a.CompositeRenderer.prototype.setGridWidth=function(a){this.renderers.forEach(function(b){b.setGridWidth(a)})},a.CompositeRenderer.prototype.getGridWidth=function(){return this.getSampleRenderer_().getGridWidth()},a.CompositeRenderer.prototype.getSampleRenderer_=function(){if(this.renderers.length>0)return this.renderers[0];throw"Renderer manager is empty"}}(),function(){var a=$.namespace("pskl.rendering.layer");a.LayersRenderer=function(a,b,c){pskl.rendering.CompositeRenderer.call(this),this.piskelController=c,this.belowRenderer=new pskl.rendering.frame.FrameRenderer(a,b,["layers-canvas","layers-below-canvas"]),this.aboveRenderer=new pskl.rendering.frame.FrameRenderer(a,b,["layers-canvas","layers-above-canvas"]),this.add(this.belowRenderer),this.add(this.aboveRenderer),this.serializedRendering=""},pskl.utils.inherit(pskl.rendering.layer.LayersRenderer,pskl.rendering.CompositeRenderer),a.LayersRenderer.prototype.render=function(){var a=this.getOffset(),b=this.getDisplaySize(),c=this.piskelController.getLayers(),d=this.piskelController.getCurrentFrameIndex(),e=this.piskelController.getCurrentLayerIndex(),f=[this.getZoom(),this.getGridWidth(),a.x,a.y,b.width,b.height,d,e,c.length].join("-");if(this.serializedRendering!=f){this.serializedRendering=f,this.clear();var g=c.slice(0,e);if(g.length>0){var h=this.getFrameForLayersAt_(d,g);this.belowRenderer.render(h)}var i=c.slice(e+1,c.length);if(i.length>0){var j=this.getFrameForLayersAt_(d,i);this.aboveRenderer.render(j)}}},a.LayersRenderer.prototype.setDisplaySize=function(a,b){var c=this.getDisplaySize();(c.width!==a||c.height!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.LayersRenderer.prototype.getFrameForLayersAt_=function(a,b){var c=b.map(function(b){return b.getFrameAt(a)});return pskl.utils.FrameUtils.merge(c)},a.LayersRenderer.prototype.flush=function(){this.serializedRendering=""}}(),function(){var a=$.namespace("pskl.rendering.frame");a.FrameRenderer=function(a,b,c){if(this.defaultRenderingOptions={supportGridRendering:!1,zoom:1},b=$.extend(!0,{},this.defaultRenderingOptions,b),void 0===a)throw"Bad FrameRenderer initialization. undefined.";if(isNaN(b.zoom))throw"Bad FrameRenderer initialization. not well defined.";this.container=a,this.zoom=b.zoom,this.offset={x:0,y:0},this.margin={x:0,y:0},this.supportGridRendering=b.supportGridRendering,this.classes=c||[],this.classes.push("canvas"),this.canvas=null,this.displayCanvas=null,this.setDisplaySize(b.width,b.height),this.setGridWidth(pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH)),$.subscribe(Events.USER_SETTINGS_CHANGED,this.onUserSettingsChange_.bind(this))},pskl.utils.inherit(pskl.rendering.frame.FrameRenderer,pskl.rendering.AbstractRenderer),a.FrameRenderer.prototype.render=function(a){a&&(this.clear(),this.renderFrame_(a))},a.FrameRenderer.prototype.clear=function(){pskl.CanvasUtils.clear(this.canvas),pskl.CanvasUtils.clear(this.displayCanvas)},a.FrameRenderer.prototype.setZoom=function(a){if(a>Constants.MINIMUM_ZOOM){var b=this.offset.x+this.displayWidth/(2*this.zoom),c=this.offset.y+this.displayHeight/(2*this.zoom);this.zoom=a,this.setOffset(b-this.displayWidth/(2*this.zoom),c-this.displayHeight/(2*this.zoom))}},a.FrameRenderer.prototype.getZoom=function(){return this.zoom},a.FrameRenderer.prototype.setDisplaySize=function(a,b){this.displayWidth=a,this.displayHeight=b,this.displayCanvas&&($(this.displayCanvas).remove(),this.displayCanvas=null),this.createDisplayCanvas_()},a.FrameRenderer.prototype.getDisplaySize=function(){return{height:this.displayHeight,width:this.displayWidth}},a.FrameRenderer.prototype.getOffset=function(){return{x:this.offset.x,y:this.offset.y}},a.FrameRenderer.prototype.setOffset=function(a,b){var c=pskl.app.piskelController.getWidth(),d=pskl.app.piskelController.getHeight(),e=c-this.displayWidth/this.zoom;a=pskl.utils.Math.minmax(a,0,e);var f=d-this.displayHeight/this.zoom;b=pskl.utils.Math.minmax(b,0,f),this.offset.x=a,this.offset.y=b},a.FrameRenderer.prototype.setGridWidth=function(a){this.gridWidth_=a},a.FrameRenderer.prototype.getGridWidth=function(){return this.supportGridRendering?this.gridWidth_:0},a.FrameRenderer.prototype.updateMargins_=function(a){var b=this.displayWidth-this.zoom*a.getWidth();this.margin.x=Math.max(0,b)/2;var c=this.displayHeight-this.zoom*a.getHeight();this.margin.y=Math.max(0,c)/2},a.FrameRenderer.prototype.createDisplayCanvas_=function(){var a=this.displayHeight,b=this.displayWidth;this.displayCanvas=pskl.CanvasUtils.createCanvas(b,a,this.classes),pskl.CanvasUtils.disableImageSmoothing(this.displayCanvas),this.container.append(this.displayCanvas)},a.FrameRenderer.prototype.onUserSettingsChange_=function(a,b,c){b==pskl.UserSettings.GRID_WIDTH&&this.setGridWidth(c)},a.FrameRenderer.prototype.renderPixel_=function(a,b,c,d){a!=Constants.TRANSPARENT_COLOR&&(d.fillStyle=a,d.fillRect(b,c,1,1))},a.FrameRenderer.prototype.getCoordinates=function(a,b){var c=this.container.offset();a-=c.left,b-=c.top,a-=this.margin.x,b-=this.margin.y;var d=this.zoom;return a+=this.offset.x*d,b+=this.offset.y*d,{x:Math.floor(a/d),y:Math.floor(b/d)}},a.FrameRenderer.prototype.renderFrame_=function(a){this.canvas&&a.getWidth()==this.canvas.width&&a.getHeight()==this.canvas.height||(this.canvas=pskl.CanvasUtils.createCanvas(a.getWidth(),a.getHeight()));for(var b=this.canvas.getContext("2d"),c=0,d=a.getWidth();d>c;c++)for(var e=0,f=a.getHeight();f>e;e++){var g=a.getPixel(c,e);this.renderPixel_(g,c,e,b)}this.updateMargins_(a);var h=this.displayCanvas.getContext("2d");h.save(),this.canvas.width*this.zoom0;if(k||i){var l=pskl.utils.ImageResizer.resizeNearestNeighbour(this.canvas,this.zoom,j);h.drawImage(l,0,0)}else h.scale(this.zoom,this.zoom),h.drawImage(this.canvas,0,0);h.restore()}}(),function(){var a=$.namespace("pskl.rendering");a.OnionSkinRenderer=function(a,b,c){pskl.rendering.CompositeRenderer.call(this),this.piskelController=c,this.renderer=new pskl.rendering.frame.FrameRenderer(a,b,["onion-skin-canvas"]),this.add(this.renderer),this.serializedRendering=""},pskl.utils.inherit(pskl.rendering.OnionSkinRenderer,pskl.rendering.CompositeRenderer),a.OnionSkinRenderer.prototype.render=function(){var a=this.getOffset(),b=this.getDisplaySize(),c=this.piskelController.getLayers(),d=this.piskelController.getCurrentFrameIndex(),e=[];this.addFrameAtIndexToArray_(d-1,e),this.addFrameAtIndexToArray_(d+1,e);var f=[this.getZoom(),this.getGridWidth(),a.x,a.y,b.width,b.height,e.map(function(a){return a.getHash()}).join("-"),c.length].join("-");if(this.serializedRendering!=f&&(this.serializedRendering=f,e.length>0)){this.clear();var g=pskl.utils.FrameUtils.merge(e);this.renderer.render(g)}},a.OnionSkinRenderer.prototype.addFrameAtIndexToArray_=function(a,b){var c=this.piskelController.getCurrentLayer();this.piskelController.hasFrameAt(a)&&b.push(c.getFrameAt(a))},a.OnionSkinRenderer.prototype.setDisplaySize=function(a,b){var c=this.getDisplaySize();(c.width!==a||c.height!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.OnionSkinRenderer.prototype.flush=function(){this.serializedRendering=""}}(),function(){var a=$.namespace("pskl.rendering.frame");a.TiledFrameRenderer=function(a,b){this.container=a,this.setZoom(b),this.displayContainer=document.createElement("div"),this.displayContainer.classList.add("tiled-frame-container"),a.get(0).appendChild(this.displayContainer),this.cachedFrameProcessor=new pskl.model.frame.CachedFrameProcessor,this.cachedFrameProcessor.setFrameProcessor(this.frameToDataUrl_.bind(this))},a.TiledFrameRenderer.prototype.frameToDataUrl_=function(a){var b=new pskl.utils.FrameUtils.toImage(a,this.zoom);return b.toDataURL("image/png")},a.TiledFrameRenderer.prototype.render=function(a){var b=this.cachedFrameProcessor.get(a,this.zoom);this.displayContainer.style.backgroundImage="url("+b+")"},a.TiledFrameRenderer.prototype.show=function(){this.displayContainer&&(this.displayContainer.style.display="block")},a.TiledFrameRenderer.prototype.setZoom=function(a){this.zoom=a},a.TiledFrameRenderer.prototype.getZoom=function(){return this.zoom}}(),function(){var a=$.namespace("pskl.rendering.frame");a.CachedFrameRenderer=function(a,b,c){pskl.rendering.frame.FrameRenderer.call(this,a,b,c),this.serializedFrame=""},pskl.utils.inherit(pskl.rendering.frame.CachedFrameRenderer,pskl.rendering.frame.FrameRenderer),a.CachedFrameRenderer.prototype.setDisplaySize=function(a,b){(this.displayWidth!==a||this.displayHeight!==b)&&this.superclass.setDisplaySize.call(this,a,b)},a.CachedFrameRenderer.prototype.render=function(a){var b=this.getOffset(),c=this.getDisplaySize(),d=[this.getZoom(),this.getGridWidth(),b.x,b.y,c.width,c.height,a.getHash()].join("-");this.serializedFrame!=d&&(this.serializedFrame=d,this.superclass.render.call(this,a))}}(),function(){var a=$.namespace("pskl.rendering");a.CanvasRenderer=function(a,b){this.frame=a,this.zoom=b,this.transparentColor_="white"},a.CanvasRenderer.prototype.drawTransparentAs=function(a){this.transparentColor_=a},a.CanvasRenderer.prototype.render=function(){var a=this.createCanvas_(),b=a.getContext("2d");this.frame.forEachPixel(function(a,c,d){this.renderPixel_(a,c,d,b)}.bind(this));var c=this.createCanvas_(this.zoom),d=c.getContext("2d");return pskl.CanvasUtils.disableImageSmoothing(c),d.scale(this.zoom,this.zoom),d.drawImage(a,0,0),c},a.CanvasRenderer.prototype.renderPixel_=function(a,b,c,d){a==Constants.TRANSPARENT_COLOR&&(a=this.transparentColor_),d.fillStyle=a,d.fillRect(b,c,1,1)},a.CanvasRenderer.prototype.createCanvas_=function(a){a=a||1;var b=this.frame.getWidth()*a,c=this.frame.getHeight()*a;return pskl.CanvasUtils.createCanvas(b,c)}}(),function(){var a=$.namespace("pskl.rendering");a.FramesheetRenderer=function(a){if(!(a.length>0))throw"FramesheetRenderer : Invalid argument : frames is empty";this.frames=a},a.FramesheetRenderer.prototype.renderAsCanvas=function(){for(var a=this.createCanvas_(),b=0;b=a&&this.currentFrameIndex>0&&this.setCurrentFrameIndex(this.currentFrameIndex-1)},a.PiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.currentFrameIndex)},a.PiskelController.prototype.duplicateFrameAt=function(a){this.getLayers().forEach(function(b){b.duplicateFrameAt(a)})},a.PiskelController.prototype.moveFrame=function(a,b){this.getLayers().forEach(function(c){c.moveFrame(a,b)})},a.PiskelController.prototype.getFrameCount=function(){var a=this.piskel.getLayerAt(0);return a.length()},a.PiskelController.prototype.setCurrentFrameIndex=function(a){this.currentFrameIndex=a},a.PiskelController.prototype.selectNextFrame=function(){var a=this.currentFrameIndex+1;a=0&&this.setCurrentFrameIndex(a)},a.PiskelController.prototype.setCurrentLayerIndex=function(a){this.currentLayerIndex=a},a.PiskelController.prototype.selectLayer=function(a){var b=this.getLayers().indexOf(a);-1!=b&&this.setCurrentLayerIndex(b)},a.PiskelController.prototype.renameLayerAt=function(a,b){var c=this.getLayerByIndex(a);c&&c.setName(b)},a.PiskelController.prototype.getLayerByIndex=function(a){var b=this.getLayers();return b[a]?b[a]:null},a.PiskelController.prototype.generateLayerName_=function(){for(var a="Layer "+this.layerIdCounter;this.hasLayerForName_(a);)this.layerIdCounter++,a="Layer "+this.layerIdCounter;return a},a.PiskelController.prototype.createLayer=function(a){if(a||(a=this.generateLayerName_()),this.hasLayerForName_(a))throw"Layer name should be unique";for(var b=new pskl.model.Layer(a),c=0;c0},a.PiskelController.prototype.moveLayerUp=function(){var a=this.getCurrentLayer();this.piskel.moveLayerUp(a),this.selectLayer(a)},a.PiskelController.prototype.moveLayerDown=function(){var a=this.getCurrentLayer();this.piskel.moveLayerDown(a),this.selectLayer(a)},a.PiskelController.prototype.removeLayerAt=function(a){if(this.getLayers().length>1){var b=this.getLayerAt(a);b&&(this.piskel.removeLayer(b),this.setCurrentLayerIndex(0))}},a.PiskelController.prototype.serialize=function(a){return pskl.utils.Serializer.serializePiskel(this.piskel,a)}}(),function(){var a=$.namespace("pskl.controller.piskel");a.PublicPiskelController=function(a){this.piskelController=a,pskl.utils.wrap(this,this.piskelController)},a.PublicPiskelController.prototype.init=function(){pskl.app.shortcutService.addShortcut("up",this.selectPreviousFrame.bind(this)),pskl.app.shortcutService.addShortcut("down",this.selectNextFrame.bind(this)),pskl.app.shortcutService.addShortcut("n",this.addFrameAtCurrentIndex.bind(this)),pskl.app.shortcutService.addShortcut("shift+n",this.duplicateCurrentFrame.bind(this))},a.PublicPiskelController.prototype.setPiskel=function(a,b){this.piskelController.setPiskel(a,b),$.publish(Events.FRAME_SIZE_CHANGED),$.publish(Events.PISKEL_RESET),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})},a.PublicPiskelController.prototype.addFrame=function(){this.addFrameAt(this.getFrameCount())},a.PublicPiskelController.prototype.addFrameAtCurrentIndex=function(){this.addFrameAt(this.getCurrentFrameIndex())},a.PublicPiskelController.prototype.addFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.addFrameAt,[a]),this.piskelController.addFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.removeFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.removeFrameAt,[a]),this.piskelController.removeFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.getCurrentFrameIndex())},a.PublicPiskelController.prototype.raiseSaveStateEvent_=function(a,b){$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.REPLAY,scope:this,replay:{fn:a,args:b}})},a.PublicPiskelController.prototype.replay=function(a,b){b.fn.apply(this.piskelController,b.args)},a.PublicPiskelController.prototype.duplicateFrameAt=function(a){this.raiseSaveStateEvent_(this.piskelController.duplicateFrameAt,[a]),this.piskelController.duplicateFrameAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveFrame=function(a,b){this.raiseSaveStateEvent_(this.piskelController.moveFrame,[a,b]),this.piskelController.moveFrame(a,b),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.setCurrentFrameIndex=function(a){this.piskelController.setCurrentFrameIndex(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectNextFrame=function(){this.piskelController.selectNextFrame(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectPreviousFrame=function(){this.piskelController.selectPreviousFrame(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.setCurrentLayerIndex=function(a){this.piskelController.setCurrentLayerIndex(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.selectLayer=function(a){this.piskelController.selectLayer(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.renameLayerAt=function(a,b){this.raiseSaveStateEvent_(this.piskelController.renameLayerAt,[a,b]),this.piskelController.renameLayerAt(a,b)},a.PublicPiskelController.prototype.createLayer=function(a){this.raiseSaveStateEvent_(this.piskelController.createLayer,[a]),this.piskelController.createLayer(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveLayerUp=function(){this.raiseSaveStateEvent_(this.piskelController.moveLayerUp,[]),this.piskelController.moveLayerUp(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.moveLayerDown=function(){this.raiseSaveStateEvent_(this.piskelController.moveLayerDown,[]),this.piskelController.moveLayerDown(),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.removeCurrentLayer=function(){var a=this.getCurrentLayerIndex();this.raiseSaveStateEvent_(this.piskelController.removeLayerAt,[a]),this.piskelController.removeLayerAt(a),$.publish(Events.PISKEL_RESET)},a.PublicPiskelController.prototype.getCurrentLayerIndex=function(){return this.piskelController.getCurrentLayerIndex()},a.PublicPiskelController.prototype.getCurrentFrameIndex=function(){return this.piskelController.currentFrameIndex},a.PublicPiskelController.prototype.getPiskel=function(){return this.piskelController.piskel}}(),function(){var a=$.namespace("pskl.controller");a.CursorCoordinatesController=function(a){this.piskelController=a,this.origin=null,this.coordinates={x:-1,y:-1}},a.CursorCoordinatesController.prototype.init=function(){this.coordinatesContainer=document.querySelector(".cursor-coordinates"),$.subscribe(Events.CURSOR_MOVED,this.onCursorMoved_.bind(this)),$.subscribe(Events.DRAG_START,this.onDragStart_.bind(this)),$.subscribe(Events.DRAG_END,this.onDragEnd_.bind(this)),$.subscribe(Events.FRAME_SIZE_CHANGED,this.redraw.bind(this)),this.redraw()},a.CursorCoordinatesController.prototype.redraw=function(){var a="";this.origin&&(a+=this.origin.x+":"+this.origin.y+" to ");var b=this.coordinates.x,c=this.coordinates.y,d=this.piskelController.getCurrentFrame();if(d.containsPixel(b,c)&&(a+=b+":"+c,this.origin)){var e=Math.abs(b-this.origin.x)+1,f=Math.abs(c-this.origin.y)+1;a+=" ("+e+"x"+f+")"}this.coordinatesContainer.innerHTML=this.getFrameSizeHTML_()+a},a.CursorCoordinatesController.prototype.getFrameSizeHTML_=function(){var a=this.piskelController.getWidth(),b=this.piskelController.getHeight();return"["+a+"x"+b+"] "},a.CursorCoordinatesController.prototype.onCursorMoved_=function(a,b,c){this.coordinates={x:b,y:c},this.redraw()},a.CursorCoordinatesController.prototype.onDragStart_=function(a,b,c){this.origin={x:b,y:c},this.redraw()},a.CursorCoordinatesController.prototype.onDragEnd_=function(){this.origin=null,this.redraw()}}(),function(){var a=$.namespace("pskl.controller");a.DrawingController=function(a,b,c){this.piskelController=a,this.paletteController=b,this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(a.getCurrentFrame()),this.container=c;var d={zoom:this.calculateZoom_(),supportGridRendering:!0,height:this.getContainerHeight_(),width:this.getContainerWidth_(),xOffset:0,yOffset:0};this.overlayRenderer=new pskl.rendering.frame.CachedFrameRenderer(this.container,d,["canvas-overlay"]),this.renderer=new pskl.rendering.frame.CachedFrameRenderer(this.container,d,["drawing-canvas"]),this.onionSkinRenderer=new pskl.rendering.OnionSkinRenderer(this.container,d,a),this.layersRenderer=new pskl.rendering.layer.LayersRenderer(this.container,d,a),this.compositeRenderer=new pskl.rendering.CompositeRenderer,this.compositeRenderer.add(this.overlayRenderer).add(this.renderer).add(this.layersRenderer).add(this.onionSkinRenderer),this.isClicked=!1,this.previousMousemoveTime=0,this.currentToolBehavior=null,this.currentMouseButton_=Constants.LEFT_BUTTON},a.DrawingController.prototype.init=function(){this.initMouseBehavior(),$.subscribe(Events.TOOL_SELECTED,$.proxy(function(a,b){this.currentToolBehavior=b,this.overlayFrame.clear()},this)),$(window).resize($.proxy(this.startResizeTimer_,this)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this)),$.subscribe(Events.FRAME_SIZE_CHANGED,$.proxy(this.onFrameSizeChanged_,this)),pskl.app.shortcutService.addShortcut("0",this.resetZoom_.bind(this)),pskl.app.shortcutService.addShortcut("+",this.increaseZoom_.bind(this,1)),pskl.app.shortcutService.addShortcut("-",this.decreaseZoom_.bind(this,1)),window.setTimeout(this.afterWindowResize_.bind(this),100)},a.DrawingController.prototype.initMouseBehavior=function(){var a=$("body");this.container.mousedown($.proxy(this.onMousedown_,this)),pskl.utils.UserAgent.isChrome?this.container.on("mousewheel",$.proxy(this.onMousewheel_,this)):this.container.on("wheel",$.proxy(this.onMousewheel_,this)),window.addEventListener("mouseup",this.onMouseup_.bind(this)),window.addEventListener("mousemove",this.onMousemove_.bind(this)),window.addEventListener("keyup",this.onKeyup_.bind(this)),a.contextmenu(this.onCanvasContextMenu_)},a.DrawingController.prototype.startResizeTimer_=function(){this.resizeTimer&&window.clearInterval(this.resizeTimer),this.resizeTimer=window.setTimeout($.proxy(this.afterWindowResize_,this),200)},a.DrawingController.prototype.afterWindowResize_=function(){var a=this.compositeRenderer.getDisplaySize().width;this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.centerColumnWrapperHorizontally_();var b=this.compositeRenderer.getDisplaySize().width/a,c=b*this.compositeRenderer.getZoom();this.compositeRenderer.setZoom(c),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.SHOW_GRID?console.warn("DrawingController:onUserSettingsChange_ not implemented !"):(b==pskl.UserSettings.ONION_SKIN||b==pskl.UserSettings.LAYER_PREVIEW)&&(this.onionSkinRenderer.clear(),this.onionSkinRenderer.flush(),this.layersRenderer.clear(),this.layersRenderer.flush(),this.render())},a.DrawingController.prototype.onFrameSizeChanged_=function(){this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.centerColumnWrapperHorizontally_(),this.compositeRenderer.setZoom(this.calculateZoom_()),this.compositeRenderer.setOffset(0,0),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onMousedown_=function(a){var b=this.piskelController.getCurrentFrame(),c=this.renderer.getCoordinates(a.clientX,a.clientY);a.button===Constants.MIDDLE_BUTTON?b.containsPixel(c.x,c.y)&&$.publish(Events.SELECT_PRIMARY_COLOR,[b.getPixel(c.x,c.y)]):(this.isClicked=!0,this.setCurrentButton(a),this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame),this.currentToolBehavior.applyToolAt(c.x,c.y,this.getCurrentColor_(),b,this.overlayFrame,a))},a.DrawingController.prototype.onMousemove_=function(a){this._clientX=a.clientX,this._clientY=a.clientY;var b=(new Date).getTime();b-this.previousMousemoveTime>Constants.MOUSEMOVE_THROTTLING&&(this.moveTool_(this._clientX,this._clientY,a),this.previousMousemoveTime=b)},a.DrawingController.prototype.resetZoom_=function(){this.setZoom_(this.calculateZoom_())},a.DrawingController.prototype.increaseZoom_=function(a){var b=(a||1)*this.getZoomStep_();this.setZoom_(this.renderer.getZoom()+b)},a.DrawingController.prototype.decreaseZoom_=function(a){var b=(a||1)*this.getZoomStep_();this.setZoom_(this.renderer.getZoom()-b)},a.DrawingController.prototype.getZoomStep_=function(){return this.calculateZoom_()/10},a.DrawingController.prototype.setZoom_=function(a){this.compositeRenderer.setZoom(a),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onKeyup_=function(a){this.moveTool_(this._clientX,this._clientY,a)},a.DrawingController.prototype.moveTool_=function(a,b,c){var d=this.renderer.getCoordinates(a,b),e=this.piskelController.getCurrentFrame();this.isClicked?this.currentToolBehavior.moveToolAt(0|d.x,0|d.y,this.getCurrentColor_(),e,this.overlayFrame,c):this.currentToolBehavior.moveUnactiveToolAt(d.x,d.y,this.getCurrentColor_(),e,this.overlayFrame,c),$.publish(Events.CURSOR_MOVED,[d.x,d.y])},a.DrawingController.prototype.onMousewheel_=function(a){var b=a.originalEvent,c=b.wheelDeltaY||-2*b.deltaY,d=Math.abs(c/120);c>0?this.increaseZoom_(d):0>c&&this.decreaseZoom_(d)},a.DrawingController.prototype.onMouseup_=function(a){if(this.isClicked){this.isClicked=!1,this.setCurrentButton(a);var b=this.renderer.getCoordinates(a.clientX,a.clientY);this.currentToolBehavior.releaseToolAt(b.x,b.y,this.getCurrentColor_(),this.piskelController.getCurrentFrame(),this.overlayFrame,a),$.publish(Events.TOOL_RELEASED)}},a.DrawingController.prototype.getSpriteCoordinates=function(a){return this.renderer.getCoordinates(a.clientX,a.clientY)},a.DrawingController.prototype.setCurrentButton=function(a){this.currentMouseButton_=a.button},a.DrawingController.prototype.getCurrentColor_=function(){return this.currentMouseButton_==Constants.RIGHT_BUTTON?this.paletteController.getSecondaryColor():this.currentMouseButton_==Constants.LEFT_BUTTON?this.paletteController.getPrimaryColor():Constants.DEFAULT_PEN_COLOR},a.DrawingController.prototype.onCanvasContextMenu_=function(a){return $(a.target).closest("#drawing-canvas-container").length?(a.preventDefault(),a.stopPropagation(),a.cancelBubble=!0,!1):void 0},a.DrawingController.prototype.render=function(){var a=this.piskelController.getCurrentFrame();a.isSameSize(this.overlayFrame)||(this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(a)),pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)&&this.onionSkinRenderer.render(),pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW)&&this.layersRenderer.render(),this.renderer.render(a),this.overlayRenderer.render(this.overlayFrame)},a.DrawingController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame().getHeight(),b=this.piskelController.getCurrentFrame().getWidth();return Math.min(this.getAvailableWidth_()/b,this.getAvailableHeight_()/a)},a.DrawingController.prototype.getAvailableHeight_=function(){return $("#main-wrapper").height()},a.DrawingController.prototype.getAvailableWidth_=function(){var a=$(".left-column").outerWidth(!0),b=$(".right-column").outerWidth(!0),c=$("#tool-section").outerWidth(!0),d=$("#application-action-section").outerWidth(!0),e=$("#main-wrapper").width()-a-b-c-d,f=10;return e-f},a.DrawingController.prototype.getContainerHeight_=function(){return this.calculateZoom_()*this.piskelController.getCurrentFrame().getHeight()},a.DrawingController.prototype.getContainerWidth_=function(){return this.calculateZoom_()*this.piskelController.getCurrentFrame().getWidth()},a.DrawingController.prototype.centerColumnWrapperHorizontally_=function(){var a=this.getContainerHeight_(),b=Math.floor(($("#main-wrapper").height()-a)/2);$("#column-wrapper").css({top:b+"px"})},a.DrawingController.prototype.getRenderer=function(){return this.compositeRenderer},a.DrawingController.prototype.setOffset=function(a,b){this.compositeRenderer.setOffset(a,b),$.publish(Events.ZOOM_CHANGED)}}(),function(){var a=$.namespace("pskl.controller"),b={SELECT:"select",CLONE:"clone",DELETE:"delete",NEW_FRAME:"newframe"};a.PreviewFilmController=function(a,b){this.piskelController=a,this.container=b,this.refreshZoom_(),this.redrawFlag=!0,this.cachedFrameProcessor=new pskl.model.frame.CachedFrameProcessor,this.cachedFrameProcessor.setFrameProcessor(this.frameToPreviewCanvas_.bind(this)),this.cachedFrameProcessor.setOutputCloner(this.clonePreviewCanvas_.bind(this))},a.PreviewFilmController.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.flagForRedraw_.bind(this)),$.subscribe(Events.USER_SETTINGS_CHANGED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.refreshZoom_.bind(this)),$("#preview-list-scroller").scroll(this.updateScrollerOverflows.bind(this)),this.container.get(0).addEventListener("click",this.onContainerClick_.bind(this)),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.flagForRedraw_=function(){this.redrawFlag=!0},a.PreviewFilmController.prototype.refreshZoom_=function(){this.zoom=this.calculateZoom_()},a.PreviewFilmController.prototype.render=function(){this.redrawFlag&&(this.createPreviews_(),this.redrawFlag=!1)},a.PreviewFilmController.prototype.updateScrollerOverflows=function(){var a=$("#preview-list-scroller"),b=a.height(),c=a.scrollTop(),d=$("#preview-list").height(),e=$(".top-overflow").height(),f=!1,g=!1;if(d>b){c>e&&(f=!0);var h=d-c-b;h>e&&(g=!0)}var i=$("#preview-list-wrapper");i.toggleClass("top-overflow-visible",f),i.toggleClass("bottom-overflow-visible",g)},a.PreviewFilmController.prototype.onContainerClick_=function(a){var c=pskl.utils.Dom.getParentWithData(a.target,"tileAction");if(c){var d=c.dataset.tileAction,e=parseInt(c.dataset.tileNumber,10);d===b.CLONE?(this.piskelController.duplicateFrameAt(e),this.piskelController.setCurrentFrameIndex(e+1),this.updateScrollerOverflows()):d===b.DELETE?(this.piskelController.removeFrameAt(e),this.updateScrollerOverflows()):d===b.SELECT?this.piskelController.setCurrentFrameIndex(e):d===b.NEW_FRAME&&(this.piskelController.addFrame(),this.piskelController.setCurrentFrameIndex(this.piskelController.getFrameCount()-1),this.updateScrollerOverflows()) }},a.PreviewFilmController.prototype.createPreviews_=function(){this.container.html(""),$(".tooltip").remove();for(var a=this.piskelController.getFrameCount(),c=0,d=a;d>c;c++)this.container.append(this.createPreviewTile_(c));var e=document.createElement("div");e.id="add-frame-action",e.className="add-frame-action",e.setAttribute("data-tile-action",b.NEW_FRAME),e.innerHTML="

    Add new frame

    ",this.container.append(e);var f=a>1;f&&this.initDragndropBehavior_(),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.initDragndropBehavior_=function(){$("#preview-list").sortable({placeholder:"preview-tile-drop-proxy",update:$.proxy(this.onUpdate_,this),items:".preview-tile"}),$("#preview-list").disableSelection()},a.PreviewFilmController.prototype.onUpdate_=function(a,b){var c=parseInt(b.item.data("tile-number"),10),d=$(".preview-tile").index(b.item);this.piskelController.moveFrame(c,d),this.piskelController.setCurrentFrameIndex(d)},a.PreviewFilmController.prototype.createPreviewTile_=function(a){var c=this.piskelController.getCurrentLayer().getFrameAt(a),d=document.createElement("li");d.setAttribute("data-tile-number",a),d.setAttribute("data-tile-action",b.SELECT),d.classList.add("preview-tile"),this.piskelController.getCurrentFrame()==c&&d.classList.add("selected");var e=document.createElement("div");e.classList.add("canvas-container",pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));var f=document.createElement("div");f.className="canvas-background",e.appendChild(f);var g=document.createElement("button");if(g.setAttribute("rel","tooltip"),g.setAttribute("data-placement","right"),g.setAttribute("data-tile-number",a),g.setAttribute("data-tile-action",b.CLONE),g.setAttribute("title","Duplicate this frame"),g.className="tile-overlay duplicate-frame-action",d.appendChild(g),e.appendChild(this.getCanvasForFrame(c)),d.appendChild(e),a>0||this.piskelController.getFrameCount()>1){var h=document.createElement("button");h.setAttribute("rel","tooltip"),h.setAttribute("data-placement","right"),h.setAttribute("title","Delete this frame"),h.setAttribute("data-tile-number",a),h.setAttribute("data-tile-action",b.DELETE),h.className="tile-overlay delete-frame-action",d.appendChild(h);var i=document.createElement("div");i.className="tile-overlay dnd-action",d.appendChild(i)}var j=document.createElement("div");return j.className="tile-overlay tile-count",j.innerHTML=a+1,d.appendChild(j),d},a.PreviewFilmController.prototype.getCanvasForFrame=function(a){var b=this.cachedFrameProcessor.get(a,this.zoom);return b},a.PreviewFilmController.prototype.frameToPreviewCanvas_=function(a){var b=new pskl.rendering.CanvasRenderer(a,this.zoom);b.drawTransparentAs(Constants.TRANSPARENT_COLOR);var c=b.render();return c.classList.add("tile-view","canvas"),c},a.PreviewFilmController.prototype.clonePreviewCanvas_=function(a){var b=pskl.CanvasUtils.clone(a);return b.classList.add("tile-view","canvas"),b},a.PreviewFilmController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame(),b=a.getHeight(),c=a.getWidth();return Math.min(Constants.PREVIEW_FILM_SIZE/b,Constants.PREVIEW_FILM_SIZE/c)}}(),function(){var a=$.namespace("pskl.controller");a.LayersListController=function(a){this.piskelController=a},a.LayersListController.prototype.init=function(){this.layerItemTemplate_=pskl.utils.Template.get("layer-item-template"),this.rootEl=document.querySelector(".layers-list-container"),this.layersListEl=document.querySelector(".layers-list"),this.toggleLayerPreviewEl=document.querySelector(".layers-toggle-preview"),this.rootEl.addEventListener("click",this.onClick_.bind(this)),this.toggleLayerPreviewEl.addEventListener("click",this.toggleLayerPreview_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.renderLayerList_.bind(this)),pskl.app.shortcutService.addShortcut("alt+L",this.toggleLayerPreview_.bind(this)),this.renderLayerList_(),this.updateToggleLayerPreview_(),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this))},a.LayersListController.prototype.renderLayerList_=function(){this.layersListEl.innerHTML="";var a=this.piskelController.getLayers();a.forEach(this.addLayerItem.bind(this))},a.LayersListController.prototype.updateToggleLayerPreview_=function(){var a="layers-toggle-preview-enabled";pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW)?this.toggleLayerPreviewEl.classList.add(a):this.toggleLayerPreviewEl.classList.remove(a)},a.LayersListController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.LAYER_PREVIEW&&this.updateToggleLayerPreview_()},a.LayersListController.prototype.addLayerItem=function(a,b){var c=this.piskelController.getCurrentLayer()===a,d=pskl.utils.Template.replace(this.layerItemTemplate_,{layername:a.getName(),layerindex:b,"isselected:current-layer-item":c}),e=pskl.utils.Template.createFromHTML(d);this.layersListEl.insertBefore(e,this.layersListEl.firstChild)},a.LayersListController.prototype.onClick_=function(a){var b,c=a.target||a.srcElement;c.classList.contains("button")?this.onButtonClick_(c):c.classList.contains("layer-item")?(b=c.dataset.layerIndex,this.piskelController.setCurrentLayerIndex(parseInt(b,10))):c.classList.contains("edit-icon")&&(b=c.parentNode.dataset.layerIndex,this.renameLayerAt_(b))},a.LayersListController.prototype.renameLayerAt_=function(a){var b=this.piskelController.getLayerAt(a),c=window.prompt("Please enter the layer name",b.getName());c&&(this.piskelController.renameLayerAt(a,c),this.renderLayerList_())},a.LayersListController.prototype.onButtonClick_=function(a){var b=a.getAttribute("data-action");"up"==b?this.piskelController.moveLayerUp():"down"==b?this.piskelController.moveLayerDown():"add"==b?this.piskelController.createLayer():"delete"==b&&this.piskelController.removeCurrentLayer()},a.LayersListController.prototype.toggleLayerPreview_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW);pskl.UserSettings.set(pskl.UserSettings.LAYER_PREVIEW,!a)}}(),function(){var a=$.namespace("pskl.controller"),b=200;a.AnimatedPreviewController=function(a,b){this.piskelController=a,this.container=b,this.elapsedTime=0,this.currentIndex=0,this.setFPS(Constants.DEFAULT.FPS),this.piskelController.getCurrentFrame(),this.renderer=new pskl.rendering.frame.TiledFrameRenderer(this.container)},a.AnimatedPreviewController.prototype.init=function(){$("#preview-fps")[0].addEventListener("change",this.onFPSSliderChange.bind(this)),document.querySelector(".right-column").style.width=Constants.ANIMATED_PREVIEW_WIDTH+"px",this.toggleOnionSkinEl=document.querySelector(".preview-toggle-onion-skin"),this.toggleOnionSkinEl.addEventListener("click",this.toggleOnionSkin_.bind(this)),pskl.app.shortcutService.addShortcut("alt+O",this.toggleOnionSkin_.bind(this)),$.subscribe(Events.FRAME_SIZE_CHANGED,this.onFrameSizeChange_.bind(this)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this)),this.updateZoom_(),this.updateOnionSkinPreview_()},a.AnimatedPreviewController.prototype.onUserSettingsChange_=function(a,b){b==pskl.UserSettings.ONION_SKIN?this.updateOnionSkinPreview_():(this.updateZoom_(),this.updateContainerDimensions_())},a.AnimatedPreviewController.prototype.updateOnionSkinPreview_=function(){var a="preview-toggle-onion-skin-enabled";pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)?this.toggleOnionSkinEl.classList.add(a):this.toggleOnionSkinEl.classList.remove(a)},a.AnimatedPreviewController.prototype.updateZoom_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW),b=a?1:this.calculateZoom_();this.renderer.setZoom(b)},a.AnimatedPreviewController.prototype.getZoom=function(){return this.calculateZoom_()},a.AnimatedPreviewController.prototype.getCoordinates=function(a,b){var c=this.container.offset();a-=c.left,b-=c.top;var d=this.getZoom();return{x:Math.floor(a/d),y:Math.floor(b/d)}},a.AnimatedPreviewController.prototype.onFPSSliderChange=function(){this.setFPS(parseInt($("#preview-fps")[0].value,10))},a.AnimatedPreviewController.prototype.setFPS=function(a){this.fps=a,$("#preview-fps").val(this.fps),$("#display-fps").html(this.fps+" FPS")},a.AnimatedPreviewController.prototype.getFPS=function(){return this.fps},a.AnimatedPreviewController.prototype.render=function(a){this.elapsedTime+=a;var b=Math.floor(this.elapsedTime/(1e3/this.fps));if(b!=this.currentIndex){this.currentIndex=b,this.piskelController.hasFrameAt(this.currentIndex)||(this.currentIndex=0,this.elapsedTime=0);var c=this.piskelController.getFrameAt(this.currentIndex);this.renderer.render(c)}},a.AnimatedPreviewController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame(),b=200,c=b/a.getHeight(),d=b/a.getWidth();return Math.min(c,d)},a.AnimatedPreviewController.prototype.onFrameSizeChange_=function(){this.updateZoom_(),this.updateContainerDimensions_()},a.AnimatedPreviewController.prototype.updateContainerDimensions_=function(){var a,c,d=this.container.get(0),e=pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);if(e)a=b,c=b;else{var f=this.getZoom(),g=this.piskelController.getCurrentFrame();a=g.getHeight()*f,c=g.getWidth()*f}d.style.height=a+"px",d.style.width=c+"px",d.style.marginTop=(b-a)/2+"px",d.style.marginBottom=(b-a)/2+"px",d.style.marginLeft=(b-c)/2+"px",d.style.marginRight=(b-c)/2+"px"},a.AnimatedPreviewController.prototype.toggleOnionSkin_=function(){var a=pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN);pskl.UserSettings.set(pskl.UserSettings.ONION_SKIN,!a)}}(),function(){var a=$.namespace("pskl.controller");a.MinimapController=function(a,b,c,d){this.piskelController=a,this.animationController=b,this.drawingController=c,this.container=d,this.isClicked=!1},a.MinimapController.prototype.init=function(){this.cropFrame=document.createElement("DIV"),this.cropFrame.className="minimap-crop-frame",this.cropFrame.style.display="none",$(this.container).append(this.cropFrame),$(this.container).mousedown(this.onMinimapMousedown_.bind(this)),$("body").mousemove(this.onMinimapMousemove_.bind(this)),$("body").mouseup(this.onMinimapMouseup_.bind(this)),$.subscribe(Events.ZOOM_CHANGED,$.proxy(this.renderMinimap_,this))},a.MinimapController.prototype.renderMinimap_=function(){var a=this.getDrawingAreaZoomRatio_();a>1?this.displayCropFrame_(a,this.drawingController.getRenderer().getOffset()):this.hideCropFrame_()},a.MinimapController.prototype.displayCropFrame_=function(a,b){this.cropFrame.style.display="block",this.cropFrame.style.top=b.y*this.animationController.getZoom()+"px",this.cropFrame.style.left=b.x*this.animationController.getZoom()+"px";var c=this.getDrawingAreaZoomRatio_();this.cropFrame.style.width=this.container.width()/c+"px",this.cropFrame.style.height=this.container.height()/c+"px"},a.MinimapController.prototype.hideCropFrame_=function(){this.cropFrame.style.display="none"},a.MinimapController.prototype.onMinimapMousemove_=function(a){if(this.isClicked&&this.getDrawingAreaZoomRatio_()>1){var b=this.getCoordinatesCenteredAround_(a.clientX,a.clientY);this.drawingController.setOffset(b.x,b.y)}},a.MinimapController.prototype.onMinimapMousedown_=function(){this.isClicked=!0},a.MinimapController.prototype.onMinimapMouseup_=function(){this.isClicked=!1},a.MinimapController.prototype.getCoordinatesCenteredAround_=function(a,b){var c=this.animationController.getCoordinates(a,b),d=this.getDrawingAreaZoomRatio_(),e=this.piskelController.getCurrentFrame().getWidth(),f=this.piskelController.getCurrentFrame().getHeight(),g=e/d,h=f/d;return{x:c.x-g/2,y:c.y-h/2}},a.MinimapController.prototype.getDrawingAreaZoomRatio_=function(){var a=this.drawingController.getRenderer().getZoom(),b=this.piskelController.getCurrentFrame().getHeight()*a,c=b/this.drawingController.getRenderer().getDisplaySize().height;return c}}(),function(){var a=$.namespace("pskl.controller");a.ToolController=function(){var a=function(a,b,c){return{id:a,shortcut:b,instance:c}};this.tools=[a("simplePen","P",new pskl.drawingtools.SimplePen),a("verticalMirrorPen","V",new pskl.drawingtools.VerticalMirrorPen),a("paintBucket","B",new pskl.drawingtools.PaintBucket),a("colorSwap","A",new pskl.drawingtools.ColorSwap),a("eraser","E",new pskl.drawingtools.Eraser),a("stroke","L",new pskl.drawingtools.Stroke),a("rectangle","R",new pskl.drawingtools.Rectangle),a("circle","C",new pskl.drawingtools.Circle),a("move","M",new pskl.drawingtools.Move),a("rectangleSelect","S",new pskl.drawingtools.RectangleSelect),a("shapeSelect","Z",new pskl.drawingtools.ShapeSelect),a("lighten","U",new pskl.drawingtools.Lighten),a("colorPicker","O",new pskl.drawingtools.ColorPicker)],this.currentSelectedTool=this.tools[0],this.previousSelectedTool=this.tools[0]},a.ToolController.prototype.init=function(){this.createToolsDom_(),this.addKeyboardShortcuts_(),this.selectTool_(this.tools[0]),$("#tool-section").mousedown($.proxy(this.onToolIconClicked_,this))},a.ToolController.prototype.activateToolOnStage_=function(a){var b=$("body"),c=b.data("selected-tool-class");c&&(b.removeClass(c),b.removeClass(pskl.drawingtools.Move.TOOL_ID)),b.addClass(a.instance.toolId),b.data("selected-tool-class",a.instance.toolId)},a.ToolController.prototype.selectTool_=function(a){this.currentSelectedTool=a,this.activateToolOnStage_(this.currentSelectedTool);var b=$("#tool-section .tool-icon.selected"),c=$("[data-tool-id="+a.instance.toolId+"]");b.removeClass("selected"),c.addClass("selected"),$.publish(Events.TOOL_SELECTED,[a.instance])},a.ToolController.prototype.onToolIconClicked_=function(a){var b=$(a.target),c=b.closest(".tool-icon");if(c.length){var d=c.data().toolId,e=this.getToolById_(d);e&&this.selectTool_(e)}},a.ToolController.prototype.onKeyboardShortcut_=function(a){for(var b=0;b{{name}}',a)}).join("");this.paletteListOptGroup_.innerHTML=b},a.PalettesListController.prototype.fillColorListContainer=function(){var a=this.getSelectedPaletteColors_(),b=a.map(function(a){return pskl.utils.Template.replace(this.paletteColorTemplate_,{color:a})}.bind(this)).join("");this.colorListContainer_.innerHTML=b,this.highlightSelectedColors();var c=a.length>e;c&&!pskl.utils.UserAgent.isChrome?this.colorListContainer_.classList.add(d):this.colorListContainer_.classList.remove(d)},a.PalettesListController.prototype.getSelectedPaletteColors_=function(){var a=[],b=this.colorPaletteSelect_.value;if(b===Constants.CURRENT_COLORS_PALETTE_ID)a=this.usedColorService.getCurrentColors();else{var c=this.getPaletteById(b,this.retrievePalettes());c&&(a=c.colors)}return a.length>Constants.MAX_CURRENT_COLORS_DISPLAYED&&(a=a.slice(0,Constants.MAX_CURRENT_COLORS_DISPLAYED)),a},a.PalettesListController.prototype.selectPalette=function(a){this.colorPaletteSelect_.value=a},a.PalettesListController.prototype.selectPaletteFromUserSettings=function(){this.selectPalette(pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE))},a.PalettesListController.prototype.onPaletteSelected_=function(){var a=this.colorPaletteSelect_.value;a===Constants.MANAGE_PALETTE_ID?($.publish(Events.DIALOG_DISPLAY,"manage-palettes"),this.selectPaletteFromUserSettings()):pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE,a),this.fillColorListContainer()},a.PalettesListController.prototype.onColorContainerContextMenu=function(a){a.preventDefault()},a.PalettesListController.prototype.onColorContainerMouseup=function(a){var b=a.target,c=b.dataset.color;c&&(a.button==Constants.LEFT_BUTTON?$.publish(Events.SELECT_PRIMARY_COLOR,[c]):a.button==Constants.RIGHT_BUTTON&&$.publish(Events.SELECT_SECONDARY_COLOR,[c]))},a.PalettesListController.prototype.highlightSelectedColors=function(){this.removeClass_(b),this.removeClass_(c);var a=this.getColorContainer_(this.paletteController.getSecondaryColor());a&&(a.classList.remove(b),a.classList.add(c)),a=this.getColorContainer_(this.paletteController.getPrimaryColor()),a&&(a.classList.remove(c),a.classList.add(b))},a.PalettesListController.prototype.getColorContainer_=function(a){return this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+a+'"]')},a.PalettesListController.prototype.removeClass_=function(a){var b=document.querySelector("."+a);b&&b.classList.remove(a)},a.PalettesListController.prototype.onPaletteListUpdated=function(){this.fillPaletteList(),this.selectPaletteFromUserSettings(),this.fillColorListContainer()},a.PalettesListController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PalettesListController.prototype.retrievePalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller");a.NotificationController=function(){},a.NotificationController.prototype.init=function(){$.subscribe(Events.SHOW_NOTIFICATION,$.proxy(this.displayMessage_,this)),$.subscribe(Events.HIDE_NOTIFICATION,$.proxy(this.removeMessage_,this))},a.NotificationController.prototype.displayMessage_=function(a,b){this.removeMessage_();var c=document.createElement("div");c.id="user-message",c.className="user-message",c.innerHTML=b.content,c.innerHTML=c.innerHTML+"
    x
    ",document.body.appendChild(c),$(c).find(".close").click($.proxy(this.removeMessage_,this)),b.behavior&&b.behavior(c)},a.NotificationController.prototype.removeMessage_=function(){var a=$("#user-message");a.length&&a.remove()}}(),function(){var a=$.namespace("pskl.controller");a.CanvasBackgroundController=function(){this.body=document.body},a.CanvasBackgroundController.prototype.init=function(){$.subscribe(Events.USER_SETTINGS_CHANGED,this.onUserSettingsChange_.bind(this)),this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND))},a.CanvasBackgroundController.prototype.onUserSettingsChange_=function(a,b,c){b==pskl.UserSettings.CANVAS_BACKGROUND&&this.updateBackgroundClass_(c)},a.CanvasBackgroundController.prototype.updateBackgroundClass_=function(a){var b=this.body.dataset.currentBackgroundClass;b&&this.body.classList.remove(b),this.body.classList.add(a),this.body.dataset.currentBackgroundClass=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.ApplicationSettingsController=function(){},a.ApplicationSettingsController.prototype.init=function(){var a=pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND);$("#background-picker-wrapper").find(".background-picker[data-background-class="+a+"]").addClass("selected");var b=pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH);$("#grid-width").val(b),$("#grid-width").change(this.onGridWidthChange.bind(this)),$("#background-picker-wrapper").click(this.onBackgroundClick.bind(this))},a.ApplicationSettingsController.prototype.onGridWidthChange=function(){var a=$("#grid-width").val();pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH,parseInt(a,10))},a.ApplicationSettingsController.prototype.onBackgroundClick=function(a){var b=$(a.target).closest(".background-picker");if(b.length){var c=b.data("background-class");pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND,c),$(".background-picker").removeClass("selected"),b.addClass("selected")}}}(),function(){var a=$.namespace("pskl.controller.settings");a.ResizeController=function(a){this.piskelController=a},a.ResizeController.prototype.init=function(){this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.resizeWidth.val(this.piskelController.getWidth()),this.resizeHeight.val(this.piskelController.getHeight()),this.cancelButton=$(".resize-cancel-button"),this.cancelButton.click(this.onCancelButtonClicked_.bind(this)),this.resizeForm=$("[name=resize-form]"),this.resizeForm.submit(this.onResizeFormSubmit_.bind(this)),this.resizeContentCheckbox=$(".resize-content-checkbox")},a.ResizeController.prototype.onResizeFormSubmit_=function(a){a.originalEvent.preventDefault(),parseInt(this.resizeWidth.val(),10),parseInt(this.resizeHeight.val(),10),this.isResizeContentEnabled_();var b=this.piskelController.getLayers().map(this.resizeLayer_.bind(this)),c=pskl.model.Piskel.fromLayers(b,this.piskelController.getPiskel().getDescriptor());pskl.app.piskelController.setPiskel(c,!0),$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ResizeController.prototype.resizeLayer_=function(a){var b=a.getFrames().map(this.resizeFrame_.bind(this));return pskl.model.Layer.fromFrames(a.getName(),b)},a.ResizeController.prototype.resizeFrame_=function(a){var b,c=parseInt(this.resizeWidth.val(),10),d=parseInt(this.resizeHeight.val(),10);return this.isResizeContentEnabled_()?b=pskl.utils.FrameUtils.resize(a,c,d,!1):(b=new pskl.model.Frame(c,d),a.forEachPixel(function(a,c,d){c"},a.GifExportController.prototype.getSelectedZoom_=function(){return this.selectResolutionEl.value},a.GifExportController.prototype.createOptionElements_=function(){for(var b=a.GifExportController.RESOLUTIONS,c=0;ce,g=new window.GIF({workers:2,quality:1,width:this.piskelController.getWidth()*a,height:this.piskelController.getHeight()*a,preserveColors:f}),h=0;hb){var d=Math.round((b-c.length)/2),e=a.substring(0,d),f=a.substring(a.length-d,a.length);a=e+c+f}return a}}(),function(){var a=$.namespace("pskl.controller.settings"),b=60;a.PngExportController=function(a){this.piskelController=a},a.PngExportController.prototype.init=function(){this.previewContainerEl=document.querySelectorAll(".png-export-preview")[0],document.querySelector(".png-download-button").addEventListener("click",this.onPngDownloadButtonClick_.bind(this)),document.querySelector(".zip-generate-button").addEventListener("click",this.onZipButtonClick_.bind(this)),this.updatePreview_(this.getFramesheetAsCanvas().toDataURL("image/png")),new a.GifExportController(this.piskelController).init()},a.PngExportController.prototype.onPngDownloadButtonClick_=function(){var a=this.getPiskelName_()+".png";pskl.utils.BlobUtils.canvasToBlob(this.getFramesheetAsCanvas(),function(b){pskl.utils.FileUtils.downloadAsFile(b,a)})},a.PngExportController.prototype.onZipButtonClick_=function(){for(var a=new window.JSZip,b=0;b"},a.PngExportController.prototype.shorten_=function(a,b,c){return a.length>b&&(a=a.substring(0,b),a+=c),a}}(),function(){var a=$.namespace("pskl.controller.settings");a.LocalStorageController=function(){},a.LocalStorageController.prototype.init=function(){this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillRestoreSession_(),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.LocalStorageController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),$.publish(Events.CLOSE_SETTINGS_DRAWER)):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.LocalStorageController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:this.formatDate_(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.LocalStorageController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))};var b=function(a){return 10>a?"0"+a:""+a};a.LocalStorageController.prototype.formatDate_=function(a,c){a=new Date(a);var d=pskl.utils.Template.replace(c,{Y:a.getFullYear(),M:b(a.getMonth()+1),D:b(a.getDate()),H:b(a.getHours()),m:b(a.getMinutes())});return d},a.LocalStorageController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=this.formatDate_(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.SaveController=function(a){this.piskelController=a},a.SaveController.prototype.init=function(){this.saveForm=$("form[name=save-form]"),this.nameInput=$("#save-name"),this.descriptionInput=$("#save-description"),this.isPublicCheckbox=$("input[name=save-public-checkbox]"),this.saveOnlineButton=$("#save-online-button"),this.saveLocalButton=$("#save-browser-button"),this.saveFileButton=$("#save-file-button"),this.piskelName=$(".piskel-name").get(0),this.saveOnlineStatus=$("#save-online-status"),this.saveFileStatus=$("#save-file-status"),this.timestamp=new Date;var a=this.piskelController.getPiskel().getDescriptor();this.nameInput.val(a.name),this.descriptionInput.val(a.description),this.isPublicCheckbox.prop("checked",a.isPublic),this.saveFileButton.click(this.saveFile_.bind(this)),this.saveLocalButton.click(this.saveLocal_.bind(this)),this.saveOnlineButton.click(this.saveOnline_.bind(this)),this.saveForm.submit(this.onSaveFormSubmit_.bind(this)),this.nameInput.keyup(this.updateLocalStatusFilename_.bind(this)),pskl.app.isLoggedIn()||(this.saveOnlineButton.hide(),$(".save-public-section").hide(),this.saveOnlineStatus.html(pskl.utils.Template.get("save-please-login-partial")),this.saveFileButton.get(0).classList.add("button-primary")),this.updateLocalStatusFilename_()},a.SaveController.prototype.updateLocalStatusFilename_=function(){this.saveFileStatus.html(pskl.utils.Template.getAndReplace("save-file-status-template",{name:this.getLocalFilename_()}))},a.SaveController.prototype.getLocalFilename_=function(){var a=this.getName(),b=pskl.utils.DateUtils.format(this.timestamp,"{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}");return a+"-"+b+".piskel"},a.SaveController.prototype.onSaveFormSubmit_=function(a){a.preventDefault(),a.stopPropagation(),pskl.app.isLoggedIn()?this.saveOnline_():this.saveLocal_()},a.SaveController.prototype.saveOnline_=function(){var a=this.getName();if(a||(a=window.prompt("Please specify a name","New piskel")),a){var b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d),this.beforeSaving_(),pskl.app.storageService.store({success:this.onSaveSuccess_.bind(this),error:this.onSaveError_.bind(this),after:this.afterSaving_.bind(this)})}},a.SaveController.prototype.saveLocal_=function(){var a=pskl.app.localStorageService,b=!0,c=this.getName(),d=this.getDescription();a.getPiskel(c)&&(b=window.confirm("There is already a piskel saved as "+c+". Override ?")),b&&(this.beforeSaving_(),a.save(c,d,pskl.app.piskelController.serialize()),window.setTimeout(function(){this.onSaveSuccess_(),this.afterSaving_()}.bind(this),500))},a.SaveController.prototype.saveFile_=function(){this.beforeSaving_(),this.saveToFile_(),pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(),function(a){pskl.utils.FileUtils.downloadAsFile(a,this.getLocalFilename_()),this.onSaveSuccess_(),this.afterSaving_()}.bind(this),"application/piskel+json")},a.SaveController.prototype.getName=function(){return this.nameInput.val()},a.SaveController.prototype.getDescription=function(){return this.descriptionInput.val()},a.SaveController.prototype.beforeSaving_=function(){this.updatePiskelDescriptor_(),this.saveOnlineButton.attr("disabled",!0),this.saveOnlineStatus.html("Saving ..."),this.piskelName&&this.piskelName.classList.add("piskel-name-saving")},a.SaveController.prototype.updatePiskelDescriptor_=function(){var a=this.getName(),b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d)},a.SaveController.prototype.onSaveSuccess_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER),$.publish(Events.SHOW_NOTIFICATION,[{content:"Successfully saved !"}]),$.publish(Events.PISKEL_SAVED)},a.SaveController.prototype.onSaveError_=function(a){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+a+")"}])},a.SaveController.prototype.afterSaving_=function(){this.saveOnlineButton.attr("disabled",!1),this.saveOnlineStatus.html(""),this.piskelName&&this.piskelName.classList.remove("piskel-name-saving"),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)}}(),function(){var a=$.namespace("pskl.controller.settings");a.ImportController=function(a){this.piskelController=a,this.importedImage_=null},a.ImportController.prototype.init=function(){this.hiddenOpenPiskelInput=$("[name=open-piskel-input]"),this.openPiskelInputButton=$(".open-piskel-button"),this.hiddenFileInput=$("[name=file-upload-input]"),this.fileInputButton=$(".file-input-button"),this.browseLocalButton=document.querySelector(".browse-local-button"),this.browseLocalButton.addEventListener("click",this.onBrowseLocalClick_.bind(this)),this.hiddenFileInput.change(this.onFileUploadChange_.bind(this)),this.fileInputButton.click(this.onFileInputClick_.bind(this)),this.hiddenOpenPiskelInput.change(this.onOpenPiskelChange_.bind(this)),this.openPiskelInputButton.click(this.onOpenPiskelClick_.bind(this)),this.prevSessionContainer=$(".previous-session"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.fillRestoreSession_()},a.ImportController.prototype.closeDrawer_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ImportController.prototype.onFileUploadChange_=function(){this.importPictureFromFile_()},a.ImportController.prototype.onFileInputClick_=function(){this.hiddenFileInput.click()},a.ImportController.prototype.onOpenPiskelChange_=function(){this.openPiskelFile_()},a.ImportController.prototype.onOpenPiskelClick_=function(){this.hiddenOpenPiskelInput.click()},a.ImportController.prototype.onBrowseLocalClick_=function(){$.publish(Events.DIALOG_DISPLAY,"browse-local"),this.closeDrawer_()},a.ImportController.prototype.openPiskelFile_=function(){var a=this.hiddenOpenPiskelInput.get(0).files;if(1==a.length){var b=a[0];this.isPiskel_(b)&&(pskl.utils.PiskelFileUtils.loadFromFile(b,function(a,b,c){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)}),this.closeDrawer_())}},a.ImportController.prototype.importPictureFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length){var b=a[0];if(!this.isImage_(b))throw this.closeDrawer_(),"File is not an image : "+b.type;$.publish(Events.DIALOG_DISPLAY,{dialogId:"import-image",initArgs:b}),this.closeDrawer_()}},a.ImportController.prototype.enableDisabledSections_=function(){this.fileInputButton.removeClass("button-primary"),this.fileInputButton.blur(),$(".import-options").show()},a.ImportController.prototype.isImage_=function(a){return 0===a.type.indexOf("image")},a.ImportController.prototype.isPiskel_=function(a){return/\.piskel$/.test(a.name)},a.ImportController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:pskl.utils.DateUtils.format(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.ImportController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))}}(),function(){var a=$.namespace("pskl.controller.settings"),b={user:{template:"templates/settings/application.html",controller:a.ApplicationSettingsController},resize:{template:"templates/settings/resize.html",controller:a.ResizeController},png:{template:"templates/settings/export.html",controller:a.PngExportController},"import":{template:"templates/settings/import.html",controller:a.ImportController},localstorage:{template:"templates/settings/localstorage.html",controller:a.LocalStorageController},save:{template:"templates/settings/save.html",controller:a.SaveController}},c="has-expanded-drawer",d="expanded";a.SettingsController=function(a){this.piskelController=a,this.drawerContainer=document.getElementById("drawer-container"),this.settingsContainer=$("[data-pskl-controller=settings]"),this.isExpanded=!1,this.currentSetting=null},a.SettingsController.prototype.init=function(){$("[data-setting]").click(this.onSettingIconClick.bind(this)),$("body").click(this.onBodyClick.bind(this)),$.subscribe(Events.CLOSE_SETTINGS_DRAWER,this.closeDrawer.bind(this))},a.SettingsController.prototype.onSettingIconClick=function(a){var b=a.originalEvent.currentTarget,c=b.getAttribute("data-setting");this.currentSetting!=c?this.loadSetting(c):this.closeDrawer(),a.originalEvent.stopPropagation(),a.originalEvent.preventDefault()},a.SettingsController.prototype.onBodyClick=function(a){var b=a.target,c=pskl.utils.Dom.isParent(b,this.drawerContainer),d=b.getAttribute("data-setting"),e=c||d;this.isExpanded&&!e&&this.closeDrawer()},a.SettingsController.prototype.loadSetting=function(a){this.drawerContainer.innerHTML=pskl.utils.Template.get(b[a].template),new b[a].controller(this.piskelController).init(),this.settingsContainer.addClass(d),$("."+c).removeClass(c),$("[data-setting="+a+"]").addClass(c),this.isExpanded=!0,this.currentSetting=a},a.SettingsController.prototype.closeDrawer=function(){this.settingsContainer.removeClass(d),$("."+c).removeClass(c),this.isExpanded=!1,this.currentSetting=null,document.activeElement.blur()}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.AbstractDialogController=function(){},a.AbstractDialogController.prototype.init=function(){this.closeButton=document.querySelector(".dialog-close"),this.closeButton.addEventListener("click",this.closeDialog.bind(this))},a.AbstractDialogController.prototype.destroy=function(){},a.AbstractDialogController.prototype.closeDialog=function(){$.publish(Events.DIALOG_HIDE)}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=window.tinycolor,c="selected",d="palette-manager-new-color",e="palette-manager-delete-card",f="edit-icon";a.PaletteManagerController=function(a){this.piskelController=a,this.palettes=this.retrieveUserPalettes(),this.originalPalettes=this.retrieveUserPalettes(),this.selectedPaletteId=null,this.spectrumContainers=[]},pskl.utils.inherit(a.PaletteManagerController,a.AbstractDialogController),a.PaletteManagerController.prototype.init=function(){this.superclass.init.call(this),this.palettesList=document.querySelector(".palette-manager-list"),this.paletteBody=document.querySelector(".palette-manager-details-body"),this.paletteHead=document.querySelector(".palette-manager-details-head"),this.createButton=document.querySelector('.palette-manager-actions-button[data-action="create"]'),this.saveAllButton=document.querySelector('.palette-manager-actions-button[data-action="save-all"]'),this.colorCardTemplate=pskl.utils.Template.get("palette-color-card-template"),this.newColorTemplate=pskl.utils.Template.get("palette-new-color-template"),this.paletteHeadTemplate=pskl.utils.Template.get("palette-details-head-template"),this.palettesList.addEventListener("click",this.onPaletteListClick.bind(this)),this.paletteBody.addEventListener("click",this.delegatedPaletteBodyClick.bind(this)),this.paletteHead.addEventListener("click",this.delegatedPaletteHeadClick.bind(this)),this.createButton.addEventListener("click",this.onCreateClick_.bind(this)),this.saveAllButton.addEventListener("click",this.saveAll.bind(this)),this.createPaletteListMarkup(),this.palettes.length>0?this.selectPalette(this.palettes[0].id):this.createPalette("New palette")},a.PaletteManagerController.prototype.destroy=function(){this.destroySpectrumPickers()},a.PaletteManagerController.prototype.onCreateClick_=function(){this.createPalette()},a.PaletteManagerController.prototype.createPalette=function(a){if(a||(a=window.prompt("Please enter a name for your palette","New palette")),a){var b=this.createPaletteObject(a);this.palettes.push(b),this.createPaletteListMarkup(),this.selectPalette(b.id)}},a.PaletteManagerController.prototype.createPaletteObject=function(a){return{id:"palette-"+Date.now()+"-"+Math.floor(1e3*Math.random()),name:a,colors:[]}},a.PaletteManagerController.prototype.redraw=function(){this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.selectPalette=function(a){this.deselectCurrentPalette();var b=this.palettesList.querySelector("[data-palette-id="+a+"]");b&&(this.selectedPaletteId=a,b.classList.add(c),this.refreshPaletteDetails())},a.PaletteManagerController.prototype.refreshPaletteDetails=function(){this.createPaletteHeadMarkup(),this.createPaletteBodyMarkup(),this.initPaletteDetailsEvents(),this.initPaletteCardsSpectrum()},a.PaletteManagerController.prototype.createPaletteListMarkup=function(){var a=this.palettes.map(function(a){var b={id:a.id,name:this.isPaletteModified(a)?a.name+" *":a.name};return pskl.utils.Template.replace('
  • {{name}}
  • ',b)}.bind(this)).join("");this.palettesList.innerHTML=a},a.PaletteManagerController.prototype.createPaletteHeadMarkup=function(){var a=this.getSelectedPalette(),b={name:a.name,"save:disabled":!this.isPaletteModified(a),"revert:disabled":!this.isPaletteModified(a),"delete:disabled":this.palettes.length<2},c=pskl.utils.Template.replace(this.paletteHeadTemplate,b);this.paletteHead.innerHTML=c},a.PaletteManagerController.prototype.isPaletteModified=function(a){var b=!1,c=this.getPaletteById(a.id,this.originalPalettes);if(c){var d=c.name!==a.name,e=a.colors.join("")!==c.colors.join("");b=d||e}else b=!0;return b},a.PaletteManagerController.prototype.createPaletteBodyMarkup=function(){var a=this.getSelectedPalette(),b=this.getColorCardsMarkup(a.colors);b+=pskl.utils.Template.replace(this.newColorTemplate,{classname:d}),this.paletteBody.innerHTML=b},a.PaletteManagerController.prototype.initPaletteDetailsEvents=function(){var a=this.paletteBody.querySelector("."+d);if(a.addEventListener("click",this.onNewCardClick.bind(this)),this.palettes.length<2){var b=this.paletteHead.querySelector('.palette-manager-palette-button[data-action="delete"]');b.setAttribute("disabled","disabled")}},a.PaletteManagerController.prototype.onNewCardClick=function(){var a,b=this.getSelectedPalette();a=b&&b.colors.length>0?b.colors[b.colors.length-1]:"#FFFFFF",this.addColorInSelectedPalette(a)},a.PaletteManagerController.prototype.delegatedPaletteBodyClick=function(a){var b=a.target;if(b.classList.contains(e)){var c=parseInt(b.parentNode.dataset.colorId,10);this.removeColorInSelectedPalette(c)}},a.PaletteManagerController.prototype.delegatedPaletteHeadClick=function(a){var b=a.target;if(b.classList.contains(f))this.renameSelectedPalette();else if(b.classList.contains("palette-manager-palette-button")){var c=b.dataset.action;"save"===c?(this.savePalette(this.getSelectedPalette().id),this.redraw()):"revert"===c?this.revertChanges():"delete"===c&&this.deleteSelectedPalette()}},a.PaletteManagerController.prototype.getSpectrumSelector_=function(){return":not(."+d+")>.palette-manager-color-square"},a.PaletteManagerController.prototype.initPaletteCardsSpectrum=function(){var a=this,b=$(this.getSpectrumSelector_());b.spectrum({clickoutFiresChange:!0,showInput:!0,showButtons:!1,change:function(b){var c=this,d=parseInt(c.parentNode.dataset.colorId,10);a.updateColorInSelectedPalette(d,b)},beforeShow:function(){var c=this,d=parseInt(c.parentNode.dataset.colorId,10),e=a.getSelectedPalette(),f=e.colors[d];b.spectrum("set",f)}}),this.spectrumContainers.push(b)},a.PaletteManagerController.prototype.destroySpectrumPickers=function(){this.spectrumContainers.forEach(function(a){a.spectrum("destroy")}),this.spectrumContainers=[]},a.PaletteManagerController.prototype.updateColorInSelectedPalette=function(a,b){var c=this.getSelectedPalette(),d="#"+b.toHex().toUpperCase();c.colors.splice(a,1,d),this.redraw()},a.PaletteManagerController.prototype.addColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.push(a),this.redraw()},a.PaletteManagerController.prototype.removeColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.splice(a,1),this.redraw()},a.PaletteManagerController.prototype.renameSelectedPalette=function(){var a=this.getSelectedPalette(),b=window.prompt('Please enter a new name for palette "'+a.name+'"',a.name);b&&(a.name=b,this.redraw())},a.PaletteManagerController.prototype.getSelectedPalette=function(){return this.getPaletteById(this.selectedPaletteId,this.palettes)},a.PaletteManagerController.prototype.getColorCardsMarkup=function(a){var c=a.map(function(a,c){var d={colorId:c,hex:a,rgb:b(a).toRgbString(),hsl:b(a).toHslString()};return pskl.utils.Template.replace(this.colorCardTemplate,d)}.bind(this)).join("");return c},a.PaletteManagerController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PaletteManagerController.prototype.removePaletteById=function(a,b){var c=this.getPaletteById(a,b);if(c){var d=b.indexOf(c);b.splice(d,1)}},a.PaletteManagerController.prototype.deselectCurrentPalette=function(){var a=this.palettesList.querySelector("."+c);a&&(this.selectedPaletteId=null,a.classList.remove(c))},a.PaletteManagerController.prototype.revertChanges=function(){var a=this.getSelectedPalette(),b=this.getPaletteById(a.id,this.originalPalettes);a.name=b.name,a.colors=b.colors.slice(0),this.redraw()},a.PaletteManagerController.prototype.deleteSelectedPalette=function(){var a=this.getSelectedPalette();this.palettes.length>1&&window.confirm('Are you sure you want to delete "'+a.name+'" ?')&&(this.removePaletteById(a.id,this.palettes),this.removePaletteById(a.id,this.originalPalettes),this.persistToLocalStorage(),this.createPaletteListMarkup(),this.selectPalette(this.palettes[0].id))},a.PaletteManagerController.prototype.onPaletteListClick=function(a){var b=a.target;b.dataset.paletteId&&this.selectPalette(b.dataset.paletteId)},a.PaletteManagerController.prototype.saveAll=function(){this.palettes.forEach(function(a){this.savePalette(a.id)}.bind(this)),this.redraw()},a.PaletteManagerController.prototype.savePalette=function(a){var b=this.getPaletteById(a,this.palettes),c=this.getPaletteById(a,this.originalPalettes);c?(c.name=b.name,c.colors=b.colors):this.originalPalettes.push(b),this.persistToLocalStorage(),$.publish(Events.SHOW_NOTIFICATION,[{content:"Palette "+b.name+" successfully saved !"}]),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)},a.PaletteManagerController.prototype.persistToLocalStorage=function(){window.localStorage.setItem("piskel.palettes",JSON.stringify(this.originalPalettes)),this.originalPalettes=this.retrieveUserPalettes(),$.publish(Events.PALETTE_LIST_UPDATED)},a.PaletteManagerController.prototype.retrieveUserPalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=60;a.ImportImageController=function(){this.importedImage_=null,this.file_=null},pskl.utils.inherit(a.ImportImageController,a.AbstractDialogController),a.ImportImageController.prototype.init=function(a){this.superclass.init.call(this),this.file_=a,this.importPreview=$(".import-section-preview"),this.fileNameContainer=$(".import-image-file-name"),this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.smoothResize=$("[name=smooth-resize-checkbox]"),this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this,"width")),this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this,"height")),this.importImageForm=$("[name=import-image-form]"),this.importImageForm.submit(this.onImportFormSubmit_.bind(this)),pskl.utils.FileUtils.readFile(this.file_,this.processImageSource_.bind(this))},a.ImportImageController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault(),this.importImageToPiskel_()},a.ImportImageController.prototype.onResizeInputKeyUp_=function(a,b){this.importedImage_&&this.synchronizeResizeFields_(b.target.value,a)},a.ImportImageController.prototype.synchronizeResizeFields_=function(a,b){a=parseInt(a,10),isNaN(a)&&(a=0);var c=this.importedImage_.height,d=this.importedImage_.width;"width"===b?this.resizeHeight.val(Math.round(a*c/d)):this.resizeWidth.val(Math.round(a*d/c))},a.ImportImageController.prototype.processImageSource_=function(a){this.importedImage_=new Image,this.importedImage_.onload=this.onImageLoaded_.bind(this),this.importedImage_.src=a},a.ImportImageController.prototype.onImageLoaded_=function(){var a=this.importedImage_.width,b=this.importedImage_.height;this.importedImage_.onload=function(){};var c=this.extractFileNameFromPath_(this.file_.name);this.fileNameContainer.html(c),this.resizeWidth.val(a),this.resizeHeight.val(b),this.importPreview.width("auto"),this.importPreview.html(""),this.importPreview.append(this.createImagePreview_())},a.ImportImageController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");return a.src=this.importedImage_.src,a.setAttribute("height",b),a},a.ImportImageController.prototype.extractFileNameFromPath_=function(a){var b=[];return b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a],b[b.length-1]},a.ImportImageController.prototype.importImageToPiskel_=function(){var a=this.importedImage_;if(a&&window.confirm("You are about to create a new Piskel, unsaved changes will be lost.")){var b=new window.SuperGif({gif:a});b.load({success:function(){var a=b.getFrames().map(function(a){return pskl.CanvasUtils.createFromImageData(a.data)});this.createPiskelFromImages_(a),this.closeDialog()}.bind(this),error:function(){this.createPiskelFromImages_([a]),this.closeDialog()}.bind(this)})}},a.ImportImageController.prototype.createFramesFromImages_=function(a){var b=this.resizeWidth.val(),c=this.resizeHeight.val(),d=!!this.smoothResize.prop("checked"),e=a.map(function(a){var e=pskl.utils.ImageResizer.resize(a,b,c,d);return pskl.utils.FrameUtils.createFromImage(e)});return e},a.ImportImageController.prototype.createPiskelFromImages_=function(a){var b=this.createFramesFromImages_(a),c=pskl.model.Layer.fromFrames("Layer 1",b),d=new pskl.model.piskel.Descriptor("Imported piskel",""),e=pskl.model.Piskel.fromLayers([c],d);pskl.app.piskelController.setPiskel(e),pskl.app.animationController.setFPS(Constants.DEFAULT.FPS)}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.BrowseLocalController=function(){},pskl.utils.inherit(a.BrowseLocalController,a.AbstractDialogController),a.BrowseLocalController.prototype.init=function(){this.superclass.init.call(this),this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.BrowseLocalController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),this.closeDialog()):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.BrowseLocalController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=pskl.utils.DateUtils.format(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController},"browse-local":{template:"templates/dialogs/browse-local.html",controller:a.BrowseLocalController},"import-image":{template:"templates/dialogs/import-image.html",controller:a.ImportImageController}};a.DialogsController=function(a){this.piskelController=a,this.currentDialog_=null},a.DialogsController.prototype.init=function(){this.dialogContainer_=document.getElementById("dialog-container"),this.dialogWrapper_=document.getElementById("dialog-container-wrapper"),$.subscribe(Events.DIALOG_DISPLAY,this.onDialogDisplayEvent_.bind(this)),$.subscribe(Events.DIALOG_HIDE,this.onDialogHideEvent_.bind(this)),pskl.app.shortcutService.addShortcut("alt+P",this.onDialogDisplayEvent_.bind(this,null,"manage-palettes")),this.dialogWrapper_.classList.add("animated")},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){var d,e;if("string"==typeof c?d=c:(d=c.dialogId,e=c.initArgs),!this.isDisplayed()){var f=b[d];if(f){this.dialogContainer_.innerHTML=pskl.utils.Template.get(f.template),this.dialogContainer_.classList.add(d);var g=new f.controller(this.piskelController);g.init(e),this.showDialogWrapper_(),this.currentDialog_={id:d,controller:g}}else console.error("Could not find dialog configuration for dialogId : "+d)}},a.DialogsController.prototype.onDialogHideEvent_=function(){this.hideDialog()},a.DialogsController.prototype.showDialogWrapper_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideDialog.bind(this)),this.dialogWrapper_.classList.add("show")},a.DialogsController.prototype.hideDialog=function(){var a=this.currentDialog_;if(a){a.controller.destroy();var b=this.currentDialog_.id;window.setTimeout(function(){this.dialogContainer_.classList.remove(b)}.bind(this),800)}this.hideDialogWrapper_(),this.currentDialog_=null},a.DialogsController.prototype.hideDialogWrapper_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.dialogWrapper_.classList.remove("show")},a.DialogsController.prototype.isDisplayed=function(){return null!==this.currentDialog_}}(),function(){var a=$.namespace("pskl.service");a.LocalStorageService=function(a){if(void 0===a)throw"Bad LocalStorageService initialization: ";this.piskelController=a},a.LocalStorageService.prototype.init=function(){},a.LocalStorageService.prototype.save=function(a,b,c){this.removeFromKeys_(a),this.addToKeys_(a,b,Date.now()),window.localStorage.setItem("piskel."+a,c)},a.LocalStorageService.prototype.load=function(a){var b=this.getPiskel(a),c=this.getKey_(a);pskl.utils.serialization.Deserializer.deserialize(JSON.parse(b),function(b){b.setDescriptor(new pskl.model.piskel.Descriptor(a,c.description,!0)),pskl.app.piskelController.setPiskel(b)})},a.LocalStorageService.prototype.remove=function(a){this.removeFromKeys_(a),window.localStorage.removeItem("piskel."+a)},a.LocalStorageService.prototype.saveKeys_=function(a){window.localStorage.setItem("piskel.keys",JSON.stringify(a))},a.LocalStorageService.prototype.removeFromKeys_=function(a){var b=this.getKeys(),c=b.filter(function(b){return b.name!==a});this.saveKeys_(c)},a.LocalStorageService.prototype.getKey_=function(a){var b=this.getKeys().filter(function(b){return b.name===a});return b.length>0?b[0]:null},a.LocalStorageService.prototype.addToKeys_=function(a,b,c){var d=this.getKeys();d.push({name:a,description:b,date:c}),this.saveKeys_(d)},a.LocalStorageService.prototype.getPiskel=function(a){return window.localStorage.getItem("piskel."+a)},a.LocalStorageService.prototype.getKeys=function(){var a=window.localStorage.getItem("piskel.keys");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.service");a.GithubStorageService=function(a){this.piskelController=a},a.GithubStorageService.prototype.init=function(){},a.GithubStorageService.prototype.store=function(){throw"Github save is no longer available. Use local save instead"}}(),function(){var a=$.namespace("pskl.service");a.AppEngineStorageService=function(a){this.piskelController=a},a.AppEngineStorageService.prototype.init=function(){},a.AppEngineStorageService.prototype.store=function(a){var b=this.prepareFormData_(),c=new XMLHttpRequest;c.open("POST",Constants.APPENGINE.URL.SAVE,!0),c.onload=function(b){200==this.status?(a.success(),a.after()):this.onerror(b)},c.onerror=function(){a.error(this.status),a.after()},c.send(b)},a.AppEngineStorageService.prototype.prepareFormData_=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=new FormData;return c.append("framesheet",this.piskelController.serialize()),c.append("fps",this.piskelController.getFPS()),c.append("name",b.name),c.append("description",b.description),b.isPublic&&c.append("public",!0),c.append("frames",this.piskelController.getFrameCount()),c.append("first_frame_as_png",pskl.app.getFirstFrameAsPng()),c.append("framesheet_as_png",pskl.app.getFramesheetAsPng()),c}}(),function(){var a=$.namespace("pskl.service"),b=6e4;a.BackupService=function(a){this.piskelController=a,this.lastHash=null},a.BackupService.prototype.init=function(){var a=window.localStorage.getItem("bkp.next.piskel"),c=window.localStorage.getItem("bkp.next.info"); +},a.PngExportController.prototype.updateStatus_=function(a){if(a){var c="{{shortLink}}",d=pskl.utils.Template.replace(c,{link:a,shortLink:this.shorten_(a,b,"...")});this.uploadStatusContainerEl.innerHTML="Your image is now available at : "+d}},a.PngExportController.prototype.updatePreview_=function(a){this.previewContainerEl.innerHTML=""},a.PngExportController.prototype.shorten_=function(a,b,c){return a.length>b&&(a=a.substring(0,b),a+=c),a}}(),function(){var a=$.namespace("pskl.controller.settings");a.LocalStorageController=function(){},a.LocalStorageController.prototype.init=function(){this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillRestoreSession_(),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.LocalStorageController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),$.publish(Events.CLOSE_SETTINGS_DRAWER)):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.LocalStorageController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:this.formatDate_(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.LocalStorageController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))};var b=function(a){return 10>a?"0"+a:""+a};a.LocalStorageController.prototype.formatDate_=function(a,c){a=new Date(a);var d=pskl.utils.Template.replace(c,{Y:a.getFullYear(),M:b(a.getMonth()+1),D:b(a.getDate()),H:b(a.getHours()),m:b(a.getMinutes())});return d},a.LocalStorageController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=this.formatDate_(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.settings");a.SaveController=function(a){this.piskelController=a},a.SaveController.prototype.init=function(){this.saveForm=$("form[name=save-form]"),this.nameInput=$("#save-name"),this.descriptionInput=$("#save-description"),this.isPublicCheckbox=$("input[name=save-public-checkbox]"),this.saveOnlineButton=$("#save-online-button"),this.saveLocalButton=$("#save-browser-button"),this.saveFileButton=$("#save-file-button"),this.piskelName=$(".piskel-name").get(0),this.saveOnlineStatus=$("#save-online-status"),this.saveFileStatus=$("#save-file-status"),this.timestamp=new Date;var a=this.piskelController.getPiskel().getDescriptor();this.nameInput.val(a.name),this.descriptionInput.val(a.description),this.isPublicCheckbox.prop("checked",a.isPublic),this.saveFileButton.click(this.saveFile_.bind(this)),this.saveLocalButton.click(this.saveLocal_.bind(this)),this.saveOnlineButton.click(this.saveOnline_.bind(this)),this.saveForm.submit(this.onSaveFormSubmit_.bind(this)),this.nameInput.keyup(this.updateLocalStatusFilename_.bind(this)),pskl.app.isLoggedIn()||(this.saveOnlineButton.hide(),$(".save-public-section").hide(),this.saveOnlineStatus.html(pskl.utils.Template.get("save-please-login-partial")),this.saveFileButton.get(0).classList.add("button-primary")),this.updateLocalStatusFilename_()},a.SaveController.prototype.updateLocalStatusFilename_=function(){this.saveFileStatus.html(pskl.utils.Template.getAndReplace("save-file-status-template",{name:this.getLocalFilename_()}))},a.SaveController.prototype.getLocalFilename_=function(){var a=this.getName(),b=pskl.utils.DateUtils.format(this.timestamp,"{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}");return a+"-"+b+".piskel"},a.SaveController.prototype.onSaveFormSubmit_=function(a){a.preventDefault(),a.stopPropagation(),pskl.app.isLoggedIn()?this.saveOnline_():this.saveLocal_()},a.SaveController.prototype.saveOnline_=function(){var a=this.getName();if(a||(a=window.prompt("Please specify a name","New piskel")),a){var b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d),this.beforeSaving_(),pskl.app.storageService.store({success:this.onSaveSuccess_.bind(this),error:this.onSaveError_.bind(this),after:this.afterSaving_.bind(this)})}},a.SaveController.prototype.saveLocal_=function(){var a=pskl.app.localStorageService,b=!0,c=this.getName(),d=this.getDescription();a.getPiskel(c)&&(b=window.confirm("There is already a piskel saved as "+c+". Override ?")),b&&(this.beforeSaving_(),a.save(c,d,pskl.app.piskelController.serialize()),window.setTimeout(function(){this.onSaveSuccess_(),this.afterSaving_()}.bind(this),500))},a.SaveController.prototype.saveFile_=function(){this.beforeSaving_(),pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(),function(a){pskl.utils.FileUtils.downloadAsFile(a,this.getLocalFilename_()),this.onSaveSuccess_(),this.afterSaving_()}.bind(this),"application/piskel+json")},a.SaveController.prototype.getName=function(){return this.nameInput.val()},a.SaveController.prototype.getDescription=function(){return this.descriptionInput.val()},a.SaveController.prototype.beforeSaving_=function(){this.updatePiskelDescriptor_(),this.saveOnlineButton.attr("disabled",!0),this.saveOnlineStatus.html("Saving ..."),this.piskelName&&this.piskelName.classList.add("piskel-name-saving")},a.SaveController.prototype.updatePiskelDescriptor_=function(){var a=this.getName(),b=this.getDescription(),c=!!this.isPublicCheckbox.prop("checked"),d=new pskl.model.piskel.Descriptor(a,b,c);this.piskelController.getPiskel().setDescriptor(d)},a.SaveController.prototype.onSaveSuccess_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER),$.publish(Events.SHOW_NOTIFICATION,[{content:"Successfully saved !"}]),$.publish(Events.PISKEL_SAVED)},a.SaveController.prototype.onSaveError_=function(a){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+a+")"}])},a.SaveController.prototype.afterSaving_=function(){this.saveOnlineButton.attr("disabled",!1),this.saveOnlineStatus.html(""),this.piskelName&&this.piskelName.classList.remove("piskel-name-saving"),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)}}(),function(){var a=$.namespace("pskl.controller.settings");a.ImportController=function(a){this.piskelController=a,this.importedImage_=null},a.ImportController.prototype.init=function(){this.hiddenOpenPiskelInput=$("[name=open-piskel-input]"),this.openPiskelInputButton=$(".open-piskel-button"),this.hiddenFileInput=$("[name=file-upload-input]"),this.fileInputButton=$(".file-input-button"),this.browseLocalButton=document.querySelector(".browse-local-button"),this.browseLocalButton.addEventListener("click",this.onBrowseLocalClick_.bind(this)),this.hiddenFileInput.change(this.onFileUploadChange_.bind(this)),this.fileInputButton.click(this.onFileInputClick_.bind(this)),this.hiddenOpenPiskelInput.change(this.onOpenPiskelChange_.bind(this)),this.openPiskelInputButton.click(this.onOpenPiskelClick_.bind(this)),this.prevSessionContainer=$(".previous-session"),this.previousSessionTemplate_=pskl.utils.Template.get("previous-session-info-template"),this.fillRestoreSession_()},a.ImportController.prototype.closeDrawer_=function(){$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ImportController.prototype.onFileUploadChange_=function(){this.importPictureFromFile_()},a.ImportController.prototype.onFileInputClick_=function(){this.hiddenFileInput.click()},a.ImportController.prototype.onOpenPiskelChange_=function(){this.openPiskelFile_()},a.ImportController.prototype.onOpenPiskelClick_=function(){this.hiddenOpenPiskelInput.click()},a.ImportController.prototype.onBrowseLocalClick_=function(){$.publish(Events.DIALOG_DISPLAY,"browse-local"),this.closeDrawer_()},a.ImportController.prototype.openPiskelFile_=function(){var a=this.hiddenOpenPiskelInput.get(0).files;if(1==a.length){var b=a[0];this.isPiskel_(b)&&(pskl.utils.PiskelFileUtils.loadFromFile(b,function(a,b,c){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)}),this.closeDrawer_())}},a.ImportController.prototype.importPictureFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length){var b=a[0];if(!this.isImage_(b))throw this.closeDrawer_(),"File is not an image : "+b.type;$.publish(Events.DIALOG_DISPLAY,{dialogId:"import-image",initArgs:b}),this.closeDrawer_()}},a.ImportController.prototype.enableDisabledSections_=function(){this.fileInputButton.removeClass("button-primary"),this.fileInputButton.blur(),$(".import-options").show()},a.ImportController.prototype.isImage_=function(a){return 0===a.type.indexOf("image")},a.ImportController.prototype.isPiskel_=function(a){return/\.piskel$/.test(a.name)},a.ImportController.prototype.fillRestoreSession_=function(){var a=pskl.app.backupService.getPreviousPiskelInfo();if(a){var b={name:a.name,date:pskl.utils.DateUtils.format(a.date,"{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")};this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_,b)),$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this))}else this.prevSessionContainer.html("No piskel backup was found on this browser.")},a.ImportController.prototype.onRestorePreviousSessionClick_=function(){window.confirm("This will erase your current workspace. Continue ?")&&(pskl.app.backupService.load(),$.publish(Events.CLOSE_SETTINGS_DRAWER))}}(),function(){var a=$.namespace("pskl.controller.settings"),b={user:{template:"templates/settings/application.html",controller:a.ApplicationSettingsController},resize:{template:"templates/settings/resize.html",controller:a.ResizeController},png:{template:"templates/settings/export.html",controller:a.PngExportController},"import":{template:"templates/settings/import.html",controller:a.ImportController},localstorage:{template:"templates/settings/localstorage.html",controller:a.LocalStorageController},save:{template:"templates/settings/save.html",controller:a.SaveController}},c="has-expanded-drawer",d="expanded";a.SettingsController=function(a){this.piskelController=a,this.drawerContainer=document.getElementById("drawer-container"),this.settingsContainer=$("[data-pskl-controller=settings]"),this.isExpanded=!1,this.currentSetting=null},a.SettingsController.prototype.init=function(){$("[data-setting]").click(this.onSettingIconClick.bind(this)),$("body").click(this.onBodyClick.bind(this)),$.subscribe(Events.CLOSE_SETTINGS_DRAWER,this.closeDrawer.bind(this))},a.SettingsController.prototype.onSettingIconClick=function(a){var b=a.originalEvent.currentTarget,c=b.getAttribute("data-setting");this.currentSetting!=c?this.loadSetting(c):this.closeDrawer(),a.originalEvent.stopPropagation(),a.originalEvent.preventDefault()},a.SettingsController.prototype.onBodyClick=function(a){var b=a.target,c=pskl.utils.Dom.isParent(b,this.drawerContainer),d=b.getAttribute("data-setting"),e=c||d;this.isExpanded&&!e&&this.closeDrawer()},a.SettingsController.prototype.loadSetting=function(a){this.drawerContainer.innerHTML=pskl.utils.Template.get(b[a].template),new b[a].controller(this.piskelController).init(),this.settingsContainer.addClass(d),$("."+c).removeClass(c),$("[data-setting="+a+"]").addClass(c),this.isExpanded=!0,this.currentSetting=a},a.SettingsController.prototype.closeDrawer=function(){this.settingsContainer.removeClass(d),$("."+c).removeClass(c),this.isExpanded=!1,this.currentSetting=null,document.activeElement.blur()}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.AbstractDialogController=function(){},a.AbstractDialogController.prototype.init=function(){this.closeButton=document.querySelector(".dialog-close"),this.closeButton.addEventListener("click",this.closeDialog.bind(this))},a.AbstractDialogController.prototype.destroy=function(){},a.AbstractDialogController.prototype.closeDialog=function(){$.publish(Events.DIALOG_HIDE)}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=window.tinycolor,c="selected",d="palette-manager-new-color",e="palette-manager-delete-card",f="edit-icon";a.PaletteManagerController=function(a){this.piskelController=a,this.palettes=this.retrieveUserPalettes(),this.originalPalettes=this.retrieveUserPalettes(),this.selectedPaletteId=null,this.spectrumContainers=[]},pskl.utils.inherit(a.PaletteManagerController,a.AbstractDialogController),a.PaletteManagerController.prototype.init=function(){this.superclass.init.call(this),this.palettesList=document.querySelector(".palette-manager-list"),this.paletteBody=document.querySelector(".palette-manager-details-body"),this.paletteHead=document.querySelector(".palette-manager-details-head"),this.createButton=document.querySelector('.palette-manager-actions-button[data-action="create"]'),this.saveAllButton=document.querySelector('.palette-manager-actions-button[data-action="save-all"]'),this.colorCardTemplate=pskl.utils.Template.get("palette-color-card-template"),this.newColorTemplate=pskl.utils.Template.get("palette-new-color-template"),this.paletteHeadTemplate=pskl.utils.Template.get("palette-details-head-template"),this.palettesList.addEventListener("click",this.onPaletteListClick.bind(this)),this.paletteBody.addEventListener("click",this.delegatedPaletteBodyClick.bind(this)),this.paletteHead.addEventListener("click",this.delegatedPaletteHeadClick.bind(this)),this.createButton.addEventListener("click",this.onCreateClick_.bind(this)),this.saveAllButton.addEventListener("click",this.saveAll.bind(this)),this.createPaletteListMarkup(),this.palettes.length>0?this.selectPalette(this.palettes[0].id):this.createPalette("New palette")},a.PaletteManagerController.prototype.destroy=function(){this.destroySpectrumPickers()},a.PaletteManagerController.prototype.onCreateClick_=function(){this.createPalette()},a.PaletteManagerController.prototype.createPalette=function(a){if(a||(a=window.prompt("Please enter a name for your palette","New palette")),a){var b=this.createPaletteObject(a);this.palettes.push(b),this.createPaletteListMarkup(),this.selectPalette(b.id)}},a.PaletteManagerController.prototype.createPaletteObject=function(a){return{id:"palette-"+Date.now()+"-"+Math.floor(1e3*Math.random()),name:a,colors:[]}},a.PaletteManagerController.prototype.redraw=function(){this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.selectPalette=function(a){this.deselectCurrentPalette();var b=this.palettesList.querySelector("[data-palette-id="+a+"]");b&&(this.selectedPaletteId=a,b.classList.add(c),this.refreshPaletteDetails())},a.PaletteManagerController.prototype.refreshPaletteDetails=function(){this.createPaletteHeadMarkup(),this.createPaletteBodyMarkup(),this.initPaletteDetailsEvents(),this.initPaletteCardsSpectrum()},a.PaletteManagerController.prototype.createPaletteListMarkup=function(){var a=this.palettes.map(function(a){var b={id:a.id,name:this.isPaletteModified(a)?a.name+" *":a.name};return pskl.utils.Template.replace('
  • {{name}}
  • ',b)}.bind(this)).join("");this.palettesList.innerHTML=a},a.PaletteManagerController.prototype.createPaletteHeadMarkup=function(){var a=this.getSelectedPalette(),b={name:a.name,"save:disabled":!this.isPaletteModified(a),"revert:disabled":!this.isPaletteModified(a),"delete:disabled":this.palettes.length<2},c=pskl.utils.Template.replace(this.paletteHeadTemplate,b);this.paletteHead.innerHTML=c},a.PaletteManagerController.prototype.isPaletteModified=function(a){var b=!1,c=this.getPaletteById(a.id,this.originalPalettes);if(c){var d=c.name!==a.name,e=a.colors.join("")!==c.colors.join("");b=d||e}else b=!0;return b},a.PaletteManagerController.prototype.createPaletteBodyMarkup=function(){var a=this.getSelectedPalette(),b=this.getColorCardsMarkup(a.colors);b+=pskl.utils.Template.replace(this.newColorTemplate,{classname:d}),this.paletteBody.innerHTML=b},a.PaletteManagerController.prototype.initPaletteDetailsEvents=function(){var a=this.paletteBody.querySelector("."+d);if(a.addEventListener("click",this.onNewCardClick.bind(this)),this.palettes.length<2){var b=this.paletteHead.querySelector('.palette-manager-palette-button[data-action="delete"]');b.setAttribute("disabled","disabled")}},a.PaletteManagerController.prototype.onNewCardClick=function(){var a,b=this.getSelectedPalette();a=b&&b.colors.length>0?b.colors[b.colors.length-1]:"#FFFFFF",this.addColorInSelectedPalette(a)},a.PaletteManagerController.prototype.delegatedPaletteBodyClick=function(a){var b=a.target;if(b.classList.contains(e)){var c=parseInt(b.parentNode.dataset.colorId,10);this.removeColorInSelectedPalette(c)}},a.PaletteManagerController.prototype.delegatedPaletteHeadClick=function(a){var b=a.target;if(b.classList.contains(f))this.renameSelectedPalette();else if(b.classList.contains("palette-manager-palette-button")){var c=b.dataset.action;"save"===c?(this.savePalette(this.getSelectedPalette().id),this.redraw()):"revert"===c?this.revertChanges():"delete"===c&&this.deleteSelectedPalette()}},a.PaletteManagerController.prototype.getSpectrumSelector_=function(){return":not(."+d+")>.palette-manager-color-square"},a.PaletteManagerController.prototype.initPaletteCardsSpectrum=function(){var a=this,b=$(this.getSpectrumSelector_());b.spectrum({clickoutFiresChange:!0,showInput:!0,showButtons:!1,change:function(b){var c=this,d=parseInt(c.parentNode.dataset.colorId,10);a.updateColorInSelectedPalette(d,b)},beforeShow:function(){var c=this,d=parseInt(c.parentNode.dataset.colorId,10),e=a.getSelectedPalette(),f=e.colors[d];b.spectrum("set",f)}}),this.spectrumContainers.push(b)},a.PaletteManagerController.prototype.destroySpectrumPickers=function(){this.spectrumContainers.forEach(function(a){a.spectrum("destroy")}),this.spectrumContainers=[]},a.PaletteManagerController.prototype.updateColorInSelectedPalette=function(a,b){var c=this.getSelectedPalette(),d="#"+b.toHex().toUpperCase();c.colors.splice(a,1,d),this.redraw()},a.PaletteManagerController.prototype.addColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.push(a),this.redraw()},a.PaletteManagerController.prototype.removeColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.splice(a,1),this.redraw()},a.PaletteManagerController.prototype.renameSelectedPalette=function(){var a=this.getSelectedPalette(),b=window.prompt('Please enter a new name for palette "'+a.name+'"',a.name);b&&(a.name=b,this.redraw())},a.PaletteManagerController.prototype.getSelectedPalette=function(){return this.getPaletteById(this.selectedPaletteId,this.palettes)},a.PaletteManagerController.prototype.getColorCardsMarkup=function(a){var c=a.map(function(a,c){var d={colorId:c,hex:a,rgb:b(a).toRgbString(),hsl:b(a).toHslString()};return pskl.utils.Template.replace(this.colorCardTemplate,d)}.bind(this)).join("");return c},a.PaletteManagerController.prototype.getPaletteById=function(a,b){var c=null;return b.forEach(function(b){b.id===a&&(c=b)}),c},a.PaletteManagerController.prototype.removePaletteById=function(a,b){var c=this.getPaletteById(a,b);if(c){var d=b.indexOf(c);b.splice(d,1)}},a.PaletteManagerController.prototype.deselectCurrentPalette=function(){var a=this.palettesList.querySelector("."+c);a&&(this.selectedPaletteId=null,a.classList.remove(c))},a.PaletteManagerController.prototype.revertChanges=function(){var a=this.getSelectedPalette(),b=this.getPaletteById(a.id,this.originalPalettes);a.name=b.name,a.colors=b.colors.slice(0),this.redraw()},a.PaletteManagerController.prototype.deleteSelectedPalette=function(){var a=this.getSelectedPalette();this.palettes.length>1&&window.confirm('Are you sure you want to delete "'+a.name+'" ?')&&(this.removePaletteById(a.id,this.palettes),this.removePaletteById(a.id,this.originalPalettes),this.persistToLocalStorage(),this.createPaletteListMarkup(),this.selectPalette(this.palettes[0].id))},a.PaletteManagerController.prototype.onPaletteListClick=function(a){var b=a.target;b.dataset.paletteId&&this.selectPalette(b.dataset.paletteId)},a.PaletteManagerController.prototype.saveAll=function(){this.palettes.forEach(function(a){this.savePalette(a.id)}.bind(this)),this.redraw()},a.PaletteManagerController.prototype.savePalette=function(a){var b=this.getPaletteById(a,this.palettes),c=this.getPaletteById(a,this.originalPalettes);c?(c.name=b.name,c.colors=b.colors):this.originalPalettes.push(b),this.persistToLocalStorage(),$.publish(Events.SHOW_NOTIFICATION,[{content:"Palette "+b.name+" successfully saved !"}]),window.setTimeout($.publish.bind($,Events.HIDE_NOTIFICATION),2e3)},a.PaletteManagerController.prototype.persistToLocalStorage=function(){window.localStorage.setItem("piskel.palettes",JSON.stringify(this.originalPalettes)),this.originalPalettes=this.retrieveUserPalettes(),$.publish(Events.PALETTE_LIST_UPDATED)},a.PaletteManagerController.prototype.retrieveUserPalettes=function(){var a=window.localStorage.getItem("piskel.palettes");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=60;a.ImportImageController=function(){this.importedImage_=null,this.file_=null},pskl.utils.inherit(a.ImportImageController,a.AbstractDialogController),a.ImportImageController.prototype.init=function(a){this.superclass.init.call(this),this.file_=a,this.importPreview=$(".import-section-preview"),this.fileNameContainer=$(".import-image-file-name"),this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.smoothResize=$("[name=smooth-resize-checkbox]"),this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this,"width")),this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this,"height")),this.importImageForm=$("[name=import-image-form]"),this.importImageForm.submit(this.onImportFormSubmit_.bind(this)),pskl.utils.FileUtils.readFile(this.file_,this.processImageSource_.bind(this))},a.ImportImageController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault(),this.importImageToPiskel_()},a.ImportImageController.prototype.onResizeInputKeyUp_=function(a,b){this.importedImage_&&this.synchronizeResizeFields_(b.target.value,a)},a.ImportImageController.prototype.synchronizeResizeFields_=function(a,b){a=parseInt(a,10),isNaN(a)&&(a=0);var c=this.importedImage_.height,d=this.importedImage_.width;"width"===b?this.resizeHeight.val(Math.round(a*c/d)):this.resizeWidth.val(Math.round(a*d/c))},a.ImportImageController.prototype.processImageSource_=function(a){this.importedImage_=new Image,this.importedImage_.onload=this.onImageLoaded_.bind(this),this.importedImage_.src=a},a.ImportImageController.prototype.onImageLoaded_=function(){var a=this.importedImage_.width,b=this.importedImage_.height;this.importedImage_.onload=function(){};var c=this.extractFileNameFromPath_(this.file_.name);this.fileNameContainer.html(c),this.resizeWidth.val(a),this.resizeHeight.val(b),this.importPreview.width("auto"),this.importPreview.html(""),this.importPreview.append(this.createImagePreview_())},a.ImportImageController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");return a.src=this.importedImage_.src,a.setAttribute("height",b),a},a.ImportImageController.prototype.extractFileNameFromPath_=function(a){var b=[];return b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a],b[b.length-1]},a.ImportImageController.prototype.importImageToPiskel_=function(){var a=this.importedImage_;if(a&&window.confirm("You are about to create a new Piskel, unsaved changes will be lost.")){var b=new window.SuperGif({gif:a});b.load({success:function(){var a=b.getFrames().map(function(a){return pskl.CanvasUtils.createFromImageData(a.data)});this.createPiskelFromImages_(a),this.closeDialog()}.bind(this),error:function(){this.createPiskelFromImages_([a]),this.closeDialog()}.bind(this)})}},a.ImportImageController.prototype.createFramesFromImages_=function(a){var b=this.resizeWidth.val(),c=this.resizeHeight.val(),d=!!this.smoothResize.prop("checked"),e=a.map(function(a){var e=pskl.utils.ImageResizer.resize(a,b,c,d);return pskl.utils.FrameUtils.createFromImage(e)});return e},a.ImportImageController.prototype.createPiskelFromImages_=function(a){var b=this.createFramesFromImages_(a),c=pskl.model.Layer.fromFrames("Layer 1",b),d=new pskl.model.piskel.Descriptor("Imported piskel",""),e=pskl.model.Piskel.fromLayers([c],d);pskl.app.piskelController.setPiskel(e),pskl.app.animationController.setFPS(Constants.DEFAULT.FPS)}}(),function(){var a=$.namespace("pskl.controller.dialogs");a.BrowseLocalController=function(){},pskl.utils.inherit(a.BrowseLocalController,a.AbstractDialogController),a.BrowseLocalController.prototype.init=function(){this.superclass.init.call(this),this.localStorageItemTemplate_=pskl.utils.Template.get("local-storage-item-template"),this.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),this.prevSessionContainer=$(".previous-session"),this.fillLocalPiskelsList_(),this.piskelsList.click(this.onPiskelsListClick_.bind(this))},a.BrowseLocalController.prototype.onPiskelsListClick_=function(a){var b=a.target.getAttribute("data-action"),c=a.target.getAttribute("data-name");"load"===b?window.confirm("This will erase your current piskel. Continue ?")&&(this.service_.load(c),this.closeDialog()):"delete"===b&&window.confirm("This will permanently DELETE this piskel from your computer. Continue ?")&&(this.service_.remove(c),this.fillLocalPiskelsList_())},a.BrowseLocalController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys();b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var c=pskl.utils.DateUtils.format(b.date,"{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:c})}.bind(this));var c=this.piskelsList.get(0).tBodies[0];c.innerHTML=a}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController},"browse-local":{template:"templates/dialogs/browse-local.html",controller:a.BrowseLocalController},"import-image":{template:"templates/dialogs/import-image.html",controller:a.ImportImageController}};a.DialogsController=function(a){this.piskelController=a,this.currentDialog_=null},a.DialogsController.prototype.init=function(){this.dialogContainer_=document.getElementById("dialog-container"),this.dialogWrapper_=document.getElementById("dialog-container-wrapper"),$.subscribe(Events.DIALOG_DISPLAY,this.onDialogDisplayEvent_.bind(this)),$.subscribe(Events.DIALOG_HIDE,this.onDialogHideEvent_.bind(this)),pskl.app.shortcutService.addShortcut("alt+P",this.onDialogDisplayEvent_.bind(this,null,"manage-palettes")),this.dialogWrapper_.classList.add("animated")},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){var d,e;if("string"==typeof c?d=c:(d=c.dialogId,e=c.initArgs),!this.isDisplayed()){var f=b[d];if(f){this.dialogContainer_.innerHTML=pskl.utils.Template.get(f.template),this.dialogContainer_.classList.add(d);var g=new f.controller(this.piskelController);g.init(e),this.showDialogWrapper_(),this.currentDialog_={id:d,controller:g}}else console.error("Could not find dialog configuration for dialogId : "+d)}},a.DialogsController.prototype.onDialogHideEvent_=function(){this.hideDialog()},a.DialogsController.prototype.showDialogWrapper_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideDialog.bind(this)),this.dialogWrapper_.classList.add("show")},a.DialogsController.prototype.hideDialog=function(){var a=this.currentDialog_;if(a){a.controller.destroy();var b=this.currentDialog_.id;window.setTimeout(function(){this.dialogContainer_.classList.remove(b)}.bind(this),800)}this.hideDialogWrapper_(),this.currentDialog_=null},a.DialogsController.prototype.hideDialogWrapper_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.dialogWrapper_.classList.remove("show")},a.DialogsController.prototype.isDisplayed=function(){return null!==this.currentDialog_}}(),function(){var a=$.namespace("pskl.service");a.LocalStorageService=function(a){if(void 0===a)throw"Bad LocalStorageService initialization: ";this.piskelController=a},a.LocalStorageService.prototype.init=function(){},a.LocalStorageService.prototype.save=function(a,b,c){this.removeFromKeys_(a),this.addToKeys_(a,b,Date.now()),window.localStorage.setItem("piskel."+a,c)},a.LocalStorageService.prototype.load=function(a){var b=this.getPiskel(a),c=this.getKey_(a);pskl.utils.serialization.Deserializer.deserialize(JSON.parse(b),function(b){b.setDescriptor(new pskl.model.piskel.Descriptor(a,c.description,!0)),pskl.app.piskelController.setPiskel(b)})},a.LocalStorageService.prototype.remove=function(a){this.removeFromKeys_(a),window.localStorage.removeItem("piskel."+a)},a.LocalStorageService.prototype.saveKeys_=function(a){window.localStorage.setItem("piskel.keys",JSON.stringify(a))},a.LocalStorageService.prototype.removeFromKeys_=function(a){var b=this.getKeys(),c=b.filter(function(b){return b.name!==a});this.saveKeys_(c)},a.LocalStorageService.prototype.getKey_=function(a){var b=this.getKeys().filter(function(b){return b.name===a});return b.length>0?b[0]:null},a.LocalStorageService.prototype.addToKeys_=function(a,b,c){var d=this.getKeys();d.push({name:a,description:b,date:c}),this.saveKeys_(d)},a.LocalStorageService.prototype.getPiskel=function(a){return window.localStorage.getItem("piskel."+a)},a.LocalStorageService.prototype.getKeys=function(){var a=window.localStorage.getItem("piskel.keys");return JSON.parse(a)||[]}}(),function(){var a=$.namespace("pskl.service");a.GithubStorageService=function(a){this.piskelController=a},a.GithubStorageService.prototype.init=function(){},a.GithubStorageService.prototype.store=function(){throw"Github save is no longer available. Use local save instead"}}(),function(){var a=$.namespace("pskl.service");a.AppEngineStorageService=function(a){this.piskelController=a},a.AppEngineStorageService.prototype.init=function(){},a.AppEngineStorageService.prototype.store=function(a){var b=this.prepareFormData_(),c=new XMLHttpRequest;c.open("POST",Constants.APPENGINE.URL.SAVE,!0),c.onload=function(b){200==this.status?(a.success(),a.after()):this.onerror(b)},c.onerror=function(){a.error(this.status),a.after()},c.send(b)},a.AppEngineStorageService.prototype.prepareFormData_=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=new FormData;return c.append("framesheet",this.piskelController.serialize()),c.append("fps",this.piskelController.getFPS()),c.append("name",b.name),c.append("description",b.description),b.isPublic&&c.append("public",!0),c.append("frames",this.piskelController.getFrameCount()),c.append("first_frame_as_png",pskl.app.getFirstFrameAsPng()),c.append("framesheet_as_png",pskl.app.getFramesheetAsPng()),c}}(),function(){var a=$.namespace("pskl.service"),b=6e4;a.BackupService=function(a){this.piskelController=a,this.lastHash=null},a.BackupService.prototype.init=function(){var a=window.localStorage.getItem("bkp.next.piskel"),c=window.localStorage.getItem("bkp.next.info"); a&&c&&(window.localStorage.setItem("bkp.prev.piskel",a),window.localStorage.setItem("bkp.prev.info",c)),window.setInterval(this.backup.bind(this),b)},a.BackupService.prototype.backup=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor(),c=a.getHash(),d={name:b.name,description:b.info,date:Date.now(),hash:c};c!==this.lastHash&&(this.lastHash=c,window.localStorage.setItem("bkp.next.piskel",this.piskelController.serialize()),window.localStorage.setItem("bkp.next.info",JSON.stringify(d)))},a.BackupService.prototype.getPreviousPiskelInfo=function(){var a=window.localStorage.getItem("bkp.prev.info");return a?JSON.parse(a):void 0},a.BackupService.prototype.load=function(){var a=window.localStorage.getItem("bkp.prev.piskel"),b=window.localStorage.getItem("bkp.prev.info");a=JSON.parse(a),b=JSON.parse(b),pskl.utils.serialization.Deserializer.deserialize(a,function(a){a.setDescriptor(new pskl.model.piskel.Descriptor(b.name,b.description,!0)),pskl.app.piskelController.setPiskel(a)})}}(),function(){var a=$.namespace("pskl.service");a.BeforeUnloadService=function(a){this.piskelController=a},a.BeforeUnloadService.prototype.init=function(){window.addEventListener("beforeunload",this.onBeforeUnload.bind(this))},a.BeforeUnloadService.prototype.onBeforeUnload=function(a){if(pskl.app.backupService.backup(),pskl.app.savedStatusService.isDirty()){var b="Your Piskel seems to have unsaved changes";return(a||window.event).returnValue=b,b}}}(),function(){var a=$.namespace("pskl.service"),b=50,c=50;a.HistoryService=function(a){this.piskelController=a,this.stateQueue=[],this.currentIndex=-1,this.saveState__b=this.onSaveStateEvent.bind(this),this.lastLoadState=-1},a.HistoryService.SNAPSHOT="SNAPSHOT",a.HistoryService.REPLAY="REPLAY",a.HistoryService.prototype.init=function(){$.subscribe(Events.PISKEL_SAVE_STATE,this.saveState__b),pskl.app.shortcutService.addShortcut("ctrl+Z",this.undo.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+Y",this.redo.bind(this)),this.saveState({type:a.HistoryService.SNAPSHOT})},a.HistoryService.prototype.onSaveStateEvent=function(a,b){this.saveState(b)},a.HistoryService.prototype.saveState=function(c){this.stateQueue=this.stateQueue.slice(0,this.currentIndex+1),this.currentIndex=this.currentIndex+1;var d={action:c,frameIndex:this.piskelController.currentFrameIndex,layerIndex:this.piskelController.currentLayerIndex};(c.type===a.HistoryService.SNAPSHOT||0===this.currentIndex%b)&&(d.piskel=this.piskelController.serialize(!0)),this.stateQueue.push(d)},a.HistoryService.prototype.undo=function(){this.loadState(this.currentIndex-1)},a.HistoryService.prototype.redo=function(){this.loadState(this.currentIndex+1)},a.HistoryService.prototype.isLoadStateAllowed_=function(a){var b=Date.now()-this.lastLoadState>c,d=a>=0&&a2*b)););return a},a.HistoryService.prototype.loadState=function(a){try{if(this.isLoadStateAllowed_(a)){this.lastLoadState=Date.now();var b=this.getPreviousSnapshotIndex_(a);if(0>b)throw"Could not find previous SNAPSHOT saved in history stateQueue";var c=this.getSnapshotFromState_(b),d=this.onPiskelLoaded_.bind(this,a,b);pskl.utils.serialization.Deserializer.deserialize(c,d)}}catch(e){window.console.error("[CRITICAL ERROR] : Unable to load a history state."),window.console.error("Can you open an issue on http://github.com/juliandescottes/piskel or contact @piskelapp on twitter ? Thanks !"),window.console.error("Thanks !"),"string"==typeof e?window.console.error(e):(window.console.error(e.message),window.console.error(e.stack))}},a.HistoryService.prototype.getSnapshotFromState_=function(a){var b=this.stateQueue[a],c=b.piskel;return"string"==typeof c&&(c=JSON.parse(c),b.piskel=c),c},a.HistoryService.prototype.onPiskelLoaded_=function(a,b,c){var d=this.getPiskelSize_();c.setDescriptor(this.piskelController.piskel.getDescriptor()),this.piskelController.setPiskel(c);for(var e=b+1;a>=e;e++){var f=this.stateQueue[e];this.setupState(f),this.replayState(f)}var g=this.stateQueue[a+1];g&&this.setupState(g),this.currentIndex=a,$.publish(Events.PISKEL_RESET),d!==this.getPiskelSize_()&&$.publish(Events.FRAME_SIZE_CHANGED)},a.HistoryService.prototype.getPiskelSize_=function(){return this.piskelController.getWidth()+"x"+this.piskelController.getHeight()},a.HistoryService.prototype.setupState=function(a){this.piskelController.setCurrentFrameIndex(a.frameIndex),this.piskelController.setCurrentLayerIndex(a.layerIndex)},a.HistoryService.prototype.replayState=function(a){var b=a.action;b.type;var c=this.piskelController.getLayerAt(a.layerIndex),d=c.getFrameAt(a.frameIndex);b.scope.replay(d,b.replay)}}(),function(){var a=$.namespace("pskl.service");a.SavedStatusService=function(a){this.piskelController=a},a.SavedStatusService.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.onToolReleased.bind(this)),$.subscribe(Events.PISKEL_RESET,this.onPiskelReset.bind(this)),$.subscribe(Events.PISKEL_SAVED,this.onPiskelSaved.bind(this))},a.SavedStatusService.prototype.onPiskelReset=function(){var a=this.piskelController.getPiskel();a.firstResetDone_?this.updateDirtyStatus(!0):a.firstResetDone_=!0},a.SavedStatusService.prototype.onToolReleased=function(){this.updateDirtyStatus(!0)},a.SavedStatusService.prototype.onPiskelSaved=function(){this.updateDirtyStatus(!1)},a.SavedStatusService.prototype.updateDirtyStatus=function(a){var b=this.piskelController.getPiskel();b.isDirty_!==a&&(b.isDirty_=a,this.updatePiskelName())},a.SavedStatusService.prototype.updatePiskelName=function(){var a=this.piskelController.getPiskel(),b=a.getDescriptor().name;a.isDirty_?$(".piskel-name").html(b+" *"):$(".piskel-name").html(b)},a.SavedStatusService.prototype.isDirty=function(){var a=this.piskelController.getPiskel();return a.isDirty_}}(),function(){var a=$.namespace("pskl.service.keyboard");a.ShortcutService=function(){this.shortcuts_={}},a.ShortcutService.prototype.init=function(){$(document.body).keydown($.proxy(this.onKeyUp_,this))},a.ShortcutService.prototype.addShortcut=function(a,b){var c=this.parseKey_(a.toLowerCase()),d=c.key,e=c.meta;if(this.shortcuts_[d]=this.shortcuts_[d]||{},this.shortcuts_[d][e]){var f=("normal"!==e?e+" + ":"")+d;console.error("[ShortcutService] >>> Shortcut ["+f+"] already registered")}else this.shortcuts_[d][e]=b},a.ShortcutService.prototype.removeShortcut=function(a){var b=this.parseKey_(a.toLowerCase()),c=b.key,d=b.meta;this.shortcuts_[c]=this.shortcuts_[c]||{},this.shortcuts_[c][d]=null},a.ShortcutService.prototype.parseKey_=function(a){var b=this.getMetaKey_({alt:-1!=a.indexOf("alt+"),shift:-1!=a.indexOf("shift+"),ctrl:-1!=a.indexOf("ctrl+")}),c=a.split(/\+(?!$)/);return a=c[c.length-1],{meta:b,key:a}},a.ShortcutService.prototype.getMetaKey_=function(a){var b=[];return["alt","ctrl","shift"].forEach(function(c){a[c]&&b.push(c)}),b.length>0?b.join("+"):"normal"},a.ShortcutService.prototype.onKeyUp_=function(a){if(!this.isInInput_(a)){var b=a.which;a.target.nodeName.toUpperCase();var c=pskl.service.keyboard.KeycodeTranslator.toChar(b),d=this.shortcuts_[c];if(d){var e=this.getMetaKey_({alt:this.isAltKeyPressed_(a),shift:this.isShiftKeyPressed_(a),ctrl:this.isCtrlKeyPressed_(a)}),f=d[e];if(f){var g=f(c);g!==!0&&a.preventDefault()}}}},a.ShortcutService.prototype.isInInput_=function(a){var b=a.target.nodeName.toUpperCase();return"INPUT"===b||"TEXTAREA"===b},a.ShortcutService.prototype.isCtrlKeyPressed_=function(a){return pskl.utils.UserAgent.isMac?a.metaKey:a.ctrlKey},a.ShortcutService.prototype.isShiftKeyPressed_=function(a){return a.shiftKey},a.ShortcutService.prototype.isAltKeyPressed_=function(a){return a.altKey}}(),function(){var a={191:"?",8:"back",27:"esc",38:"up",40:"down",46:"del",189:"-",187:"+"},b=$.namespace("pskl.service.keyboard");b.KeycodeTranslator={toChar:function(b){return b>=48&&57>=b?b-48+"":b>=65&&90>=b?(b-65+10).toString(36):a[b]}}}(),function(){var a=$.namespace("pskl.service.keyboard");a.CheatsheetService=function(){this.isDisplayed_=!1},a.CheatsheetService.prototype.init=function(){if(this.cheatsheetEl_=document.getElementById("cheatsheet-wrapper"),!this.cheatsheetEl_)throw"cheatsheetEl_ DOM element could not be retrieved";this.initMarkup_(),pskl.app.shortcutService.addShortcut("shift+?",this.toggleCheatsheet_.bind(this)),pskl.app.shortcutService.addShortcut("?",this.toggleCheatsheet_.bind(this));var a=$(".cheatsheet-link");a.click(this.toggleCheatsheet_.bind(this)),$.subscribe(Events.TOGGLE_HELP,this.toggleCheatsheet_.bind(this)),$.subscribe(Events.ESCAPE,this.onEscape_.bind(this))},a.CheatsheetService.prototype.toggleCheatsheet_=function(){this.isDisplayed_?this.hideCheatsheet_():this.showCheatsheet_()},a.CheatsheetService.prototype.onEscape_=function(){this.isDisplayed_&&this.hideCheatsheet_()},a.CheatsheetService.prototype.showCheatsheet_=function(){pskl.app.shortcutService.addShortcut("ESC",this.hideCheatsheet_.bind(this)),this.cheatsheetEl_.style.display="block",this.isDisplayed_=!0},a.CheatsheetService.prototype.hideCheatsheet_=function(){pskl.app.shortcutService.removeShortcut("ESC"),this.cheatsheetEl_.style.display="none",this.isDisplayed_=!1},a.CheatsheetService.prototype.initMarkup_=function(){this.initMarkupForTools_(),this.initMarkupForMisc_(),this.initMarkupForSelection_()},a.CheatsheetService.prototype.toDescriptor_=function(a,b,c){return pskl.utils.UserAgent.isMac&&(a=a.replace("ctrl","cmd")),{shortcut:a,description:b,icon:c}},a.CheatsheetService.prototype.getDomFromDescriptor_=function(a){var b=pskl.utils.Template.get("cheatsheet-shortcut-template"),c=pskl.utils.Template.replace(b,{shortcutIcon:a.icon,shortcutDescription:a.description,shortcutKey:a.shortcut});return pskl.utils.Template.createFromHTML(c)},a.CheatsheetService.prototype.initMarkupAbstract_=function(a,b){for(var c=$(b,this.cheatsheetEl_).get(0),d=0;da?1:-1,i=d>c?1:-1,j=f-g;;){if(e.push({col:a,row:c}),a==b&&c==d)break;var k=2*j;k>-g&&(j-=g,a+=h),f>k&&(j+=f,c+=i)}return e}}(),function(){var a=$.namespace("pskl.drawingtools");a.ShapeTool=function(){this.startCol=null,this.startRow=null,this.tooltipDescriptors=[{key:"shift",description:"Keep 1 to 1 ratio"}]},pskl.utils.inherit(a.ShapeTool,a.BaseTool),a.ShapeTool.prototype.applyToolAt=function(a,b,c,d,e){$.publish(Events.DRAG_START,[a,b]),this.startCol=a,this.startRow=b,e.setPixel(a,b,c)},a.ShapeTool.prototype.moveToolAt=function(a,b,c,d,e,f){var g=this.getCoordinates_(a,b,f);$.publish(Events.CURSOR_MOVED,[g.col,g.row]),e.clear(),c==Constants.TRANSPARENT_COLOR&&(c=Constants.SELECTION_TRANSPARENT_COLOR),this.draw_(g.col,g.row,c,e)},a.ShapeTool.prototype.releaseToolAt=function(a,b,c,d,e,f){e.clear();var g=this.getCoordinates_(a,b,f);this.draw_(g.col,g.row,c,d),$.publish(Events.DRAG_END,[a,b]),this.raiseSaveStateEvent({col:a,row:b,startCol:this.startCol,startRow:this.startRow,color:c})},a.ShapeTool.prototype.replay=function(a,b){this.startCol=b.startCol,this.startRow=b.startRow,this.draw_(b.col,b.row,b.color,a)},a.ShapeTool.prototype.getCoordinates_=function(a,b,c){return c.shiftKey?this.getScaledCoordinates_(a,b):{col:a,row:b}},a.ShapeTool.prototype.getScaledCoordinates_=function(a,b){var c=this.startCol-a,d=Math.abs(c),e=this.startRow-b,f=Math.abs(e),g=Math.min(d,f);return b=this.startRow-e/f*g,a=this.startCol-c/d*g,{col:a,row:b}},a.ShapeTool.prototype.draw_=Constants.ABSTRACT_FUNCTION}(),function(){var a=$.namespace("pskl.drawingtools");a.SimplePen=function(){this.toolId="tool-pen",this.helpText="Pen tool",this.previousCol=null,this.previousRow=null,this.pixels=[]},pskl.utils.inherit(a.SimplePen,a.BaseTool),a.SimplePen.prototype.applyToolAt=function(a,b,c,d,e){this.previousCol=a,this.previousRow=b,e.setPixel(a,b,c),c===Constants.TRANSPARENT_COLOR&&d.setPixel(a,b,c),this.pixels.push({col:a,row:b,color:c})},a.SimplePen.prototype.moveToolAt=function(a,b,c,d,e,f){if(Math.abs(a-this.previousCol)>1||Math.abs(b-this.previousRow)>1)for(var g=this.getLinePixels_(a,this.previousCol,b,this.previousRow),h=0,i=g.length;i>h;h++){var j=g[h];this.applyToolAt(j.col,j.row,c,d,e,f)}else this.applyToolAt(a,b,c,d,e,f);this.previousCol=a,this.previousRow=b},a.SimplePen.prototype.releaseToolAt=function(a,b,c,d){this.setPixelsToFrame_(d,this.pixels),this.raiseSaveStateEvent({pixels:this.pixels.slice(0),color:c}),this.pixels=[]},a.SimplePen.prototype.replay=function(a,b){this.setPixelsToFrame_(a,b.pixels,b.color)},a.SimplePen.prototype.setPixelsToFrame_=function(a,b){b.forEach(function(b){a.setPixel(b.col,b.row,b.color)})}}(),function(){var a=$.namespace("pskl.drawingtools"),b=3;a.Lighten=function(){this.superclass.constructor.call(this),this.toolId="tool-lighten",this.helpText="Lighten",this.tooltipDescriptors=[{key:"ctrl",description:"Darken"},{key:"shift",description:"Apply only once per pixel"}],this.resetUsedPixels_()},pskl.utils.inherit(a.Lighten,a.SimplePen),a.Lighten.prototype.resetUsedPixels_=function(){this.usedPixels_={darken:{},lighten:{}}},a.Lighten.prototype.applyToolAt=function(a,c,d,e,f,g){var h=f.getPixel(a,c),i=e.getPixel(a,c),j=h===Constants.TRANSPARENT_COLOR?i:h,k=pskl.utils.UserAgent.isMac?g.metaKey:g.ctrlKey,l=g.shiftKey,m=j===Constants.TRANSPARENT_COLOR,n=k?this.usedPixels_.darken:this.usedPixels_.lighten,o=a+"-"+c,p=m||l&&n[o];if(p)d=j;else{var q=l?2*b:b;d=k?window.tinycolor.darken(j,q):window.tinycolor.lighten(j,q),d&&(n[o]=!0,this.superclass.applyToolAt.call(this,a,c,d.toRgbString(),e,f,g))}},a.Lighten.prototype.releaseToolAt=function(a,b,c,d){this.setPixelsToFrame_(d,this.pixels),this.resetUsedPixels_(),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})}}(),function(){var a=$.namespace("pskl.drawingtools");a.VerticalMirrorPen=function(){this.superclass.constructor.call(this),this.toolId="tool-vertical-mirror-pen",this.helpText="Vertical Mirror pen",this.tooltipDescriptors=[{key:"ctrl",description:"Use horizontal axis"},{key:"shift",description:"Use horizontal and vertical axis"}]},pskl.utils.inherit(a.VerticalMirrorPen,a.SimplePen),a.VerticalMirrorPen.prototype.backupPreviousPositions_=function(){this.backupPreviousCol=this.previousCol,this.backupPreviousRow=this.previousRow},a.VerticalMirrorPen.prototype.restorePreviousPositions_=function(){this.previousCol=this.backupPreviousCol,this.previousRow=this.backupPreviousRow},a.VerticalMirrorPen.prototype.applyToolAt=function(a,b,c,d,e,f){this.superclass.applyToolAt.call(this,a,b,c,d,e),this.backupPreviousPositions_();var g=this.getSymmetricCol_(a,d),h=this.getSymmetricRow_(b,d),i=pskl.utils.UserAgent.isMac?f.metaKey:f.ctrlKey;i||this.superclass.applyToolAt.call(this,g,b,c,d,e),(f.shiftKey||i)&&this.superclass.applyToolAt.call(this,a,h,c,d,e),f.shiftKey&&this.superclass.applyToolAt.call(this,g,h,c,d,e),this.restorePreviousPositions_()},a.VerticalMirrorPen.prototype.getSymmetricCol_=function(a,b){return b.getWidth()-a-1},a.VerticalMirrorPen.prototype.getSymmetricRow_=function(a,b){return b.getHeight()-a-1}}(),function(){var a=$.namespace("pskl.drawingtools");a.Eraser=function(){this.superclass.constructor.call(this),this.toolId="tool-eraser",this.helpText="Eraser tool"},pskl.utils.inherit(a.Eraser,a.SimplePen),a.Eraser.prototype.applyToolAt=function(a,b,c,d,e,f){this.superclass.applyToolAt.call(this,a,b,Constants.TRANSPARENT_COLOR,d,e,f)},a.Eraser.prototype.releaseToolAt=function(a,b,c,d,e,f){this.superclass.releaseToolAt.call(this,a,b,Constants.TRANSPARENT_COLOR,d,e,f)}}(),function(){var a=$.namespace("pskl.drawingtools");a.Stroke=function(){this.toolId="tool-stroke",this.helpText="Stroke tool",this.startCol=null,this.startRow=null},pskl.utils.inherit(a.Stroke,a.BaseTool),a.Stroke.prototype.applyToolAt=function(a,b,c,d,e){this.startCol=a,this.startRow=b,e.setPixel(a,b,c)},a.Stroke.prototype.moveToolAt=function(a,b,c,d,e){e.clear();for(var f=this.getLinePixels_(this.startCol,a,this.startRow,b),g=0;gi;i++)for(var j=0;h>j;j++){var k=i-a,l=j-b;e.shiftKey&&(k=(k+g)%g,l=(l+h)%h),f=d.containsPixel(k,l)?d.getPixel(k,l):Constants.TRANSPARENT_COLOR,c.setPixel(i,j,f)}},a.Move.prototype.releaseToolAt=function(a,b,c,d,e,f){this.moveToolAt(a,b,c,d,e,f),this.raiseSaveStateEvent({colDiff:a-this.startCol,rowDiff:b-this.startRow,shiftKey:f.shiftKey})},a.Move.prototype.replay=function(a,b){var c={shiftKey:b.shiftKey};this.shiftFrame(b.colDiff,b.rowDiff,a,a.clone(),c)}}(),function(){var a=$.namespace("pskl.drawingtools");a.BaseSelect=function(){this.secondaryToolId=pskl.drawingtools.Move.TOOL_ID,this.BodyRoot=$("body"),this.startCol=null,this.startRow=null,this.selection=null,this.tooltipDescriptors=[{description:"Drag the selection to move it. You may switch to other layers and frames."},{key:"ctrl+c",description:"Copy the selected area"},{key:"ctrl+v",description:"Paste the copied area"}]},pskl.utils.inherit(a.BaseSelect,a.BaseTool),a.BaseSelect.prototype.applyToolAt=function(a,b,c,d,e){this.startCol=a,this.startRow=b,this.lastCol=a,this.lastRow=b,this.isInSelection(a,b)?(this.mode="moveSelection",this.onSelectionDragStart_(a,b,c,d,e)):(this.mode="select",this.onSelectStart_(a,b,c,d,e))},a.BaseSelect.prototype.moveToolAt=function(a,b,c,d,e){"select"==this.mode?this.onSelect_(a,b,c,d,e):"moveSelection"==this.mode&&this.onSelectionDrag_(a,b,c,d,e)},a.BaseSelect.prototype.releaseToolAt=function(a,b,c,d,e){"select"==this.mode?this.onSelectEnd_(a,b,c,d,e):"moveSelection"==this.mode&&this.onSelectionDragEnd_(a,b,c,d,e)},a.BaseSelect.prototype.moveUnactiveToolAt=function(a,b,c,d,e){e.containsPixel(a,b)&&(this.isInSelection(a,b)?(this.BodyRoot.addClass(this.secondaryToolId),this.BodyRoot.removeClass(this.toolId)):(this.BodyRoot.addClass(this.toolId),this.BodyRoot.removeClass(this.secondaryToolId)))},a.BaseSelect.prototype.isInSelection=function(a,b){return this.selection&&this.selection.pixels.some(function(c){return c.col===a&&c.row===b})},a.BaseSelect.prototype.hideHighlightedPixel=function(){},a.BaseSelect.prototype.drawSelectionOnOverlay_=function(a){for(var b=this.selection.pixels,c=0,d=b.length;d>c;c++){var e=b[c],f=e.color&&e.color!==Constants.TRANSPARENT_COLOR,g=f?this.getTransparentVariant(e.color):Constants.SELECTION_TRANSPARENT_COLOR;a.setPixel(b[c].col,b[c].row,g)}},a.BaseSelect.prototype.getTransparentVariant=function(a){var b=window.tinycolor(a);return b=window.tinycolor.lighten(b,10),b.setAlpha(.5),b.toRgbString()},a.BaseSelect.prototype.onSelectStart_=function(){},a.BaseSelect.prototype.onSelect_=function(){},a.BaseSelect.prototype.onSelectEnd_=function(){},a.BaseSelect.prototype.onSelectionDragStart_=function(){},a.BaseSelect.prototype.onSelectionDrag_=function(a,b,c,d,e){var f=a-this.lastCol,g=b-this.lastRow;a-this.startCol,b-this.startRow,this.selection.move(f,g),e.clear(),this.drawSelectionOnOverlay_(e),this.lastCol=a,this.lastRow=b},a.BaseSelect.prototype.onSelectionDragEnd_=function(a,b,c,d,e){this.onSelectionDrag_(a,b,c,d,e)}}(),function(){var a=$.namespace("pskl.drawingtools");a.RectangleSelect=function(){this.toolId="tool-rectangle-select",this.helpText="Rectangle selection",a.BaseSelect.call(this),this.hasSelection=!1},pskl.utils.inherit(a.RectangleSelect,a.BaseSelect),a.RectangleSelect.prototype.onSelectStart_=function(a,b,c,d,e){this.hasSelection?(this.hasSelection=!1,e.clear(),$.publish(Events.SELECTION_DISMISSED)):(this.hasSelection=!0,$.publish(Events.DRAG_START,[a,b]),e.setPixel(a,b,c))},a.RectangleSelect.prototype.onSelect_=function(a,b,c,d,e){this.hasSelection&&(e.clear(),this.selection=new pskl.selection.RectangularSelection(this.startCol,this.startRow,a,b),$.publish(Events.SELECTION_CREATED,[this.selection]),this.drawSelectionOnOverlay_(e))},a.RectangleSelect.prototype.onSelectEnd_=function(a,b,c,d,e){this.hasSelection&&(this.onSelect_(a,b,c,d,e),$.publish(Events.DRAG_END,[a,b]))}}(),function(){var a=$.namespace("pskl.drawingtools");a.ShapeSelect=function(){this.toolId="tool-shape-select",this.helpText="Shape selection",a.BaseSelect.call(this)},pskl.utils.inherit(a.ShapeSelect,a.BaseSelect),a.ShapeSelect.prototype.onSelectStart_=function(a,b,c,d,e){$.publish(Events.SELECTION_DISMISSED),e.clear();var f=pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(d,a,b);this.selection=new pskl.selection.ShapeSelection(f),$.publish(Events.SELECTION_CREATED,[this.selection]),this.drawSelectionOnOverlay_(e)}}(),function(){var a=$.namespace("pskl.drawingtools");a.ColorPicker=function(){this.toolId="tool-colorpicker",this.helpText="Color picker"},pskl.utils.inherit(a.ColorPicker,a.BaseTool),a.ColorPicker.prototype.applyToolAt=function(a,b,c,d,e,f){if(d.containsPixel(a,b)){var g=d.getPixel(a,b);f.button==Constants.LEFT_BUTTON?$.publish(Events.SELECT_PRIMARY_COLOR,[g]):f.button==Constants.RIGHT_BUTTON&&$.publish(Events.SELECT_SECONDARY_COLOR,[g])}}}(),function(){var a=$.namespace("pskl.drawingtools");a.ColorSwap=function(){this.toolId="tool-colorswap",this.helpText="Paint all pixels of the same color",this.tooltipDescriptors=[{key:"ctrl",description:"Apply to all layers"},{key:"shift",description:"Apply to all frames"}]},pskl.utils.inherit(a.ColorSwap,a.BaseTool),a.ColorSwap.prototype.applyToolAt=function(a,b,c,d,e,f){if(d.containsPixel(a,b)){var g=d.getPixel(a,b),h=pskl.utils.UserAgent.isMac?f.metaKey:f.ctrlKey,i=f.shiftKey;this.swapColors(g,c,h,i),$.publish(Events.PISKEL_SAVE_STATE,{type:pskl.service.HistoryService.SNAPSHOT})}},a.ColorSwap.prototype.swapColors=function(a,b,c,d){var e=function(c,d,e,f){c==a&&(f.pixels[d][e]=b)},f=pskl.app.piskelController.getCurrentLayer(),g=pskl.app.piskelController.getCurrentFrameIndex();pskl.app.piskelController.getPiskel().getLayers().forEach(function(a){(c||a===f)&&a.getFrames().forEach(function(a,b){(d||b===g)&&(a.forEachPixel(e),a.version++)})})}}(),function(){var a=$.namespace("pskl");a.app={init:function(){this.isAppEngineVersion=!!pskl.appEngineToken_,this.shortcutService=new pskl.service.keyboard.ShortcutService,this.shortcutService.init();var a={height:Constants.DEFAULT.HEIGHT,width:Constants.DEFAULT.WIDTH},b=new pskl.model.piskel.Descriptor("New Piskel",""),c=new pskl.model.Piskel(a.width,a.height,b),d=new pskl.model.Layer("Layer 1"),e=new pskl.model.Frame(a.width,a.height); d.addFrame(e),c.addLayer(d),this.corePiskelController=new pskl.controller.piskel.PiskelController(c),this.corePiskelController.init(),this.piskelController=new pskl.controller.piskel.PublicPiskelController(this.corePiskelController),this.piskelController.init(),this.paletteController=new pskl.controller.PaletteController,this.paletteController.init(),this.currentColorsService=new pskl.service.CurrentColorsService(this.piskelController),this.currentColorsService.init(),this.palettesListController=new pskl.controller.PalettesListController(this.paletteController,this.currentColorsService),this.palettesListController.init(),this.cursorCoordinatesController=new pskl.controller.CursorCoordinatesController(this.piskelController),this.cursorCoordinatesController.init(),this.drawingController=new pskl.controller.DrawingController(this.piskelController,this.paletteController,$("#drawing-canvas-container")),this.drawingController.init(),this.animationController=new pskl.controller.AnimatedPreviewController(this.piskelController,$("#animated-preview-canvas-container")),this.animationController.init(),this.minimapController=new pskl.controller.MinimapController(this.piskelController,this.animationController,this.drawingController,$("#animated-preview-canvas-container")),this.minimapController.init(),this.previewFilmController=new pskl.controller.PreviewFilmController(this.piskelController,$("#preview-list")),this.previewFilmController.init(),this.layersListController=new pskl.controller.LayersListController(this.piskelController),this.layersListController.init(),this.settingsController=new pskl.controller.settings.SettingsController(this.piskelController),this.settingsController.init(),this.dialogsController=new pskl.controller.dialogs.DialogsController(this.piskelController),this.dialogsController.init(),this.toolController=new pskl.controller.ToolController,this.toolController.init(),this.selectionManager=new pskl.selection.SelectionManager(this.piskelController),this.selectionManager.init(),this.historyService=new pskl.service.HistoryService(this.corePiskelController),this.historyService.init(),this.notificationController=new pskl.controller.NotificationController,this.notificationController.init(),this.canvasBackgroundController=new pskl.controller.CanvasBackgroundController,this.canvasBackgroundController.init(),this.localStorageService=new pskl.service.LocalStorageService(this.piskelController),this.localStorageService.init(),this.imageUploadService=new pskl.service.ImageUploadService,this.imageUploadService.init(),this.cheatsheetService=new pskl.service.keyboard.CheatsheetService,this.cheatsheetService.init(),this.savedStatusService=new pskl.service.SavedStatusService(this.piskelController),this.savedStatusService.init(),this.backupService=new pskl.service.BackupService(this.piskelController),this.backupService.init(),this.beforeUnloadService=new pskl.service.BeforeUnloadService(this.piskelController),this.beforeUnloadService.init(),this.fileDropperService=new pskl.service.FileDropperService(this.piskelController,$("#drawing-canvas-container").get(0)),this.fileDropperService.init(),this.storageService=this.isAppEngineVersion?new pskl.service.AppEngineStorageService(this.piskelController):new pskl.service.GithubStorageService(this.piskelController),this.storageService.init();var f=new pskl.rendering.DrawingLoop;f.addCallback(this.render,this),f.start(),this.initTooltips_();var g=this.getPiskelInitData_();g&&g.piskel&&this.loadPiskel_(g.piskel,g.descriptor,g.fps)},loadPiskel_:function(a,b,c){pskl.utils.serialization.Deserializer.deserialize(a,function(a){a.setDescriptor(b),pskl.app.piskelController.setPiskel(a),pskl.app.animationController.setFPS(c)})},getPiskelInitData_:function(){return pskl.appEnginePiskelData_},isLoggedIn:function(){var a=this.getPiskelInitData_();return a&&a.isLoggedIn},initTooltips_:function(){$("body").tooltip({selector:"[rel=tooltip]"})},render:function(a){this.drawingController.render(a),this.animationController.render(a),this.previewFilmController.render(a)},getFirstFrameAsPng:function(){var a=this.piskelController.getFrameAt(0),b=new pskl.rendering.CanvasRenderer(a,1);b.drawTransparentAs("rgba(0,0,0,0)");var c=b.render();return c.toDataURL("image/png")},getFramesheetAsPng:function(){var a=new pskl.rendering.PiskelRenderer(this.piskelController),b=a.renderAsCanvas();return b.toDataURL("image/png")}}}(); \ No newline at end of file diff --git a/piskel-boot-0.1.0.js b/piskel-boot-0.1.0.js index 299b24de..93c409cc 100644 --- a/piskel-boot-0.1.0.js +++ b/piskel-boot-0.1.0.js @@ -1,6 +1,6 @@ (function () { - var version = '-2014-07-12-06-35'; + var version = '-2014-07-12-09-26'; var versionHasNotBeenReplaced = version.indexOf('@@') === 0; if (versionHasNotBeenReplaced) { version = ''; diff --git a/templates/settings.html b/templates/settings.html index d50d1164..61367b57 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -32,7 +32,7 @@