From db9e832984a316016b84685e3234d6c9d18df6a1 Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sun, 30 Mar 2014 22:49:14 +0200 Subject: [PATCH] update --- build/piskel-packaged-min.js | 6 +-- build/piskel-packaged.js | 70 +++++++++++++------------- build/piskel-style-packaged.css | 22 +------- index.html | 5 +- templates/dialogs/manage-palettes.html | 2 +- 5 files changed, 43 insertions(+), 62 deletions(-) diff --git a/build/piskel-packaged-min.js b/build/piskel-packaged-min.js index c4d7e617..26786a2e 100644 --- a/build/piskel-packaged-min.js +++ b/build/piskel-packaged-min.js @@ -4,7 +4,7 @@ _b.optgroup=_b.option,_b.tbody=_b.tfoot=_b.colgroup=_b.caption=_b.thead,_b.th=_b var d=c&&"left"===c?"scrollLeft":"scrollTop",e=!1;return b[d]>0?!0:(b[d]=1,e=b[d]>0,b[d]=0,e)}})}(jQuery),function(a,b){var c=0,d=Array.prototype.slice,e=a.cleanData;a.cleanData=function(b){for(var c,d=0;null!=(c=b[d]);d++)try{a(c).triggerHandler("remove")}catch(f){}e(b)},a.widget=function(b,c,d){var e,f,g,h,i={},j=b.split(".")[0];b=b.split(".")[1],e=j+"-"+b,d||(d=c,c=a.Widget),a.expr[":"][e.toLowerCase()]=function(b){return!!a.data(b,e)},a[j]=a[j]||{},f=a[j][b],g=a[j][b]=function(a,b){return this._createWidget?(arguments.length&&this._createWidget(a,b),void 0):new g(a,b)},a.extend(g,f,{version:d.version,_proto:a.extend({},d),_childConstructors:[]}),h=new c,h.options=a.widget.extend({},h.options),a.each(d,function(b,d){return a.isFunction(d)?(i[b]=function(){var a=function(){return c.prototype[b].apply(this,arguments)},e=function(a){return c.prototype[b].apply(this,a)};return function(){var b,c=this._super,f=this._superApply;return this._super=a,this._superApply=e,b=d.apply(this,arguments),this._super=c,this._superApply=f,b}}(),void 0):(i[b]=d,void 0)}),g.prototype=a.widget.extend(h,{widgetEventPrefix:f?h.widgetEventPrefix:b},i,{constructor:g,namespace:j,widgetName:b,widgetFullName:e}),f?(a.each(f._childConstructors,function(b,c){var d=c.prototype;a.widget(d.namespace+"."+d.widgetName,g,c._proto)}),delete f._childConstructors):c._childConstructors.push(g),a.widget.bridge(b,g)},a.widget.extend=function(c){for(var e,f,g=d.call(arguments,1),h=0,i=g.length;i>h;h++)for(e in g[h])f=g[h][e],g[h].hasOwnProperty(e)&&f!==b&&(c[e]=a.isPlainObject(f)?a.isPlainObject(c[e])?a.widget.extend({},c[e],f):a.widget.extend({},f):f);return c},a.widget.bridge=function(c,e){var f=e.prototype.widgetFullName||c;a.fn[c]=function(g){var h="string"==typeof g,i=d.call(arguments,1),j=this;return g=!h&&i.length?a.widget.extend.apply(null,[g].concat(i)):g,h?this.each(function(){var d,e=a.data(this,f);return e?a.isFunction(e[g])&&"_"!==g.charAt(0)?(d=e[g].apply(e,i),d!==e&&d!==b?(j=d&&d.jquery?j.pushStack(d.get()):d,!1):void 0):a.error("no such method '"+g+"' for "+c+" widget instance"):a.error("cannot call methods on "+c+" prior to initialization; "+"attempted to call method '"+g+"'")}):this.each(function(){var b=a.data(this,f);b?b.option(g||{})._init():a.data(this,f,new e(g,this))}),j}},a.Widget=function(){},a.Widget._childConstructors=[],a.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"
",options:{disabled:!1,create:null},_createWidget:function(b,d){d=a(d||this.defaultElement||this)[0],this.element=a(d),this.uuid=c++,this.eventNamespace="."+this.widgetName+this.uuid,this.options=a.widget.extend({},this.options,this._getCreateOptions(),b),this.bindings=a(),this.hoverable=a(),this.focusable=a(),d!==this&&(a.data(d,this.widgetFullName,this),this._on(!0,this.element,{remove:function(a){a.target===d&&this.destroy()}}),this.document=a(d.style?d.ownerDocument:d.document||d),this.window=a(this.document[0].defaultView||this.document[0].parentWindow)),this._create(),this._trigger("create",null,this._getCreateEventData()),this._init()},_getCreateOptions:a.noop,_getCreateEventData:a.noop,_create:a.noop,_init:a.noop,destroy:function(){this._destroy(),this.element.unbind(this.eventNamespace).removeData(this.widgetName).removeData(this.widgetFullName).removeData(a.camelCase(this.widgetFullName)),this.widget().unbind(this.eventNamespace).removeAttr("aria-disabled").removeClass(this.widgetFullName+"-disabled "+"ui-state-disabled"),this.bindings.unbind(this.eventNamespace),this.hoverable.removeClass("ui-state-hover"),this.focusable.removeClass("ui-state-focus")},_destroy:a.noop,widget:function(){return this.element},option:function(c,d){var e,f,g,h=c;if(0===arguments.length)return a.widget.extend({},this.options);if("string"==typeof c)if(h={},e=c.split("."),c=e.shift(),e.length){for(f=h[c]=a.widget.extend({},this.options[c]),g=0;g=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}})}(jQuery),function(a){function b(a,b,c){return a>b&&b+c>a}function c(a){return/left|right/.test(a.css("float"))||/inline|table-cell/.test(a.css("display"))}a.widget("ui.sortable",a.ui.mouse,{version:"1.10.3",widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1e3,activate:null,beforeStop:null,change:null,deactivate:null,out:null,over:null,receive:null,remove:null,sort:null,start:null,stop:null,update:null},_create:function(){var a=this.options;this.containerCache={},this.element.addClass("ui-sortable"),this.refresh(),this.floating=this.items.length?"x"===a.axis||c(this.items[0].item):!1,this.offset=this.element.offset(),this._mouseInit(),this.ready=!0},_destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled"),this._mouseDestroy();for(var a=this.items.length-1;a>=0;a--)this.items[a].item.removeData(this.widgetName+"-item");return this},_setOption:function(b,c){"disabled"===b?(this.options[b]=c,this.widget().toggleClass("ui-sortable-disabled",!!c)):a.Widget.prototype._setOption.apply(this,arguments)},_mouseCapture:function(b,c){var d=null,e=!1,f=this;return this.reverting?!1:this.options.disabled||"static"===this.options.type?!1:(this._refreshItems(b),a(b.target).parents().each(function(){return a.data(this,f.widgetName+"-item")===f?(d=a(this),!1):void 0}),a.data(b.target,f.widgetName+"-item")===f&&(d=a(b.target)),d?!this.options.handle||c||(a(this.options.handle,d).find("*").addBack().each(function(){this===b.target&&(e=!0)}),e)?(this.currentItem=d,this._removeCurrentsFromItems(),!0):!1:!1)},_mouseStart:function(b,c,d){var e,f,g=this.options;if(this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(b),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.helper.css("position","absolute"),this.cssPosition=this.helper.css("position"),this.originalPosition=this._generatePosition(b),this.originalPageX=b.pageX,this.originalPageY=b.pageY,g.cursorAt&&this._adjustOffsetFromHelper(g.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!==this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),g.containment&&this._setContainment(),g.cursor&&"auto"!==g.cursor&&(f=this.document.find("body"),this.storedCursor=f.css("cursor"),f.css("cursor",g.cursor),this.storedStylesheet=a("").appendTo(f)),g.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",g.opacity)),g.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",g.zIndex)),this.scrollParent[0]!==document&&"HTML"!==this.scrollParent[0].tagName&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",b,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions(),!d)for(e=this.containers.length-1;e>=0;e--)this.containers[e]._trigger("activate",b,this._uiHash(this));return a.ui.ddmanager&&(a.ui.ddmanager.current=this),a.ui.ddmanager&&!g.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,b),this.dragging=!0,this.helper.addClass("ui-sortable-helper"),this._mouseDrag(b),!0},_mouseDrag:function(b){var c,d,e,f,g=this.options,h=!1;for(this.position=this._generatePosition(b),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs),this.options.scroll&&(this.scrollParent[0]!==document&&"HTML"!==this.scrollParent[0].tagName?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-b.pageY=0;c--)if(d=this.items[c],e=d.item[0],f=this._intersectsWithPointer(d),f&&d.instance===this.currentContainer&&e!==this.currentItem[0]&&this.placeholder[1===f?"next":"prev"]()[0]!==e&&!a.contains(this.placeholder[0],e)&&("semi-dynamic"===this.options.type?!a.contains(this.element[0],e):!0)){if(this.direction=1===f?"down":"up","pointer"!==this.options.tolerance&&!this._intersectsWithSides(d))break;this._rearrange(b,d),this._trigger("change",b,this._uiHash());break}return this._contactContainers(b),a.ui.ddmanager&&a.ui.ddmanager.drag(this,b),this._trigger("sort",b,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(b,c){if(b){if(a.ui.ddmanager&&!this.options.dropBehaviour&&a.ui.ddmanager.drop(this,b),this.options.revert){var d=this,e=this.placeholder.offset(),f=this.options.axis,g={};f&&"x"!==f||(g.left=e.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===document.body?0:this.offsetParent[0].scrollLeft)),f&&"y"!==f||(g.top=e.top-this.offset.parent.top-this.margins.top+(this.offsetParent[0]===document.body?0:this.offsetParent[0].scrollTop)),this.reverting=!0,a(this.helper).animate(g,parseInt(this.options.revert,10)||500,function(){d._clear(b)})}else this._clear(b,c);return!1}},cancel:function(){if(this.dragging){this._mouseUp({target:null}),"original"===this.options.helper?this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"):this.currentItem.show();for(var b=this.containers.length-1;b>=0;b--)this.containers[b]._trigger("deactivate",null,this._uiHash(this)),this.containers[b].containerCache.over&&(this.containers[b]._trigger("out",null,this._uiHash(this)),this.containers[b].containerCache.over=0)}return this.placeholder&&(this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]),"original"!==this.options.helper&&this.helper&&this.helper[0].parentNode&&this.helper.remove(),a.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?a(this.domPosition.prev).after(this.currentItem):a(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},a(c).each(function(){var c=(a(b.item||this).attr(b.attribute||"id")||"").match(b.expression||/(.+)[\-=_](.+)/);c&&d.push((b.key||c[1]+"[]")+"="+(b.key&&b.expression?c[1]:c[2]))}),!d.length&&b.key&&d.push(b.key+"="),d.join("&")},toArray:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},c.each(function(){d.push(a(b.item||this).attr(b.attribute||"id")||"")}),d},_intersectsWith:function(a){var b=this.positionAbs.left,c=b+this.helperProportions.width,d=this.positionAbs.top,e=d+this.helperProportions.height,f=a.left,g=f+a.width,h=a.top,i=h+a.height,j=this.offset.click.top,k=this.offset.click.left,l="x"===this.options.axis||d+j>h&&i>d+j,m="y"===this.options.axis||b+k>f&&g>b+k,n=l&&m;return"pointer"===this.options.tolerance||this.options.forcePointerForContainers||"pointer"!==this.options.tolerance&&this.helperProportions[this.floating?"width":"height"]>a[this.floating?"width":"height"]?n:f0?"down":"up")},_getDragHorizontalDirection:function(){var a=this.positionAbs.left-this.lastPositionAbs.left;return 0!==a&&(a>0?"right":"left")},refresh:function(a){return this._refreshItems(a),this.refreshPositions(),this},_connectWith:function(){var a=this.options;return a.connectWith.constructor===String?[a.connectWith]:a.connectWith},_getItemsAsjQuery:function(b){var c,d,e,f,g=[],h=[],i=this._connectWith();if(i&&b)for(c=i.length-1;c>=0;c--)for(e=a(i[c]),d=e.length-1;d>=0;d--)f=a.data(e[d],this.widgetFullName),f&&f!==this&&!f.options.disabled&&h.push([a.isFunction(f.options.items)?f.options.items.call(f.element):a(f.options.items,f.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),f]);for(h.push([a.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):a(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]),c=h.length-1;c>=0;c--)h[c][0].each(function(){g.push(this)});return a(g)},_removeCurrentsFromItems:function(){var b=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=a.grep(this.items,function(a){for(var c=0;c=0;c--)for(e=a(m[c]),d=e.length-1;d>=0;d--)f=a.data(e[d],this.widgetFullName),f&&f!==this&&!f.options.disabled&&(l.push([a.isFunction(f.options.items)?f.options.items.call(f.element[0],b,{item:this.currentItem}):a(f.options.items,f.element),f]),this.containers.push(f));for(c=l.length-1;c>=0;c--)for(g=l[c][1],h=l[c][0],d=0,j=h.length;j>d;d++)i=a(h[d]),i.data(this.widgetName+"-item",g),k.push({item:i,instance:g,width:0,height:0,left:0,top:0})},refreshPositions:function(b){this.offsetParent&&this.helper&&(this.offset.parent=this._getParentOffset());var c,d,e,f;for(c=this.items.length-1;c>=0;c--)d=this.items[c],d.instance!==this.currentContainer&&this.currentContainer&&d.item[0]!==this.currentItem[0]||(e=this.options.toleranceElement?a(this.options.toleranceElement,d.item):d.item,b||(d.width=e.outerWidth(),d.height=e.outerHeight()),f=e.offset(),d.left=f.left,d.top=f.top);if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(c=this.containers.length-1;c>=0;c--)f=this.containers[c].element.offset(),this.containers[c].containerCache.left=f.left,this.containers[c].containerCache.top=f.top,this.containers[c].containerCache.width=this.containers[c].element.outerWidth(),this.containers[c].containerCache.height=this.containers[c].element.outerHeight();return this},_createPlaceholder:function(b){b=b||this;var c,d=b.options;d.placeholder&&d.placeholder.constructor!==String||(c=d.placeholder,d.placeholder={element:function(){var d=b.currentItem[0].nodeName.toLowerCase(),e=a("<"+d+">",b.document[0]).addClass(c||b.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper");return"tr"===d?b.currentItem.children().each(function(){a(" ",b.document[0]).attr("colspan",a(this).attr("colspan")||1).appendTo(e)}):"img"===d&&e.attr("src",b.currentItem.attr("src")),c||e.css("visibility","hidden"),e},update:function(a,e){(!c||d.forcePlaceholderSize)&&(e.height()||e.height(b.currentItem.innerHeight()-parseInt(b.currentItem.css("paddingTop")||0,10)-parseInt(b.currentItem.css("paddingBottom")||0,10)),e.width()||e.width(b.currentItem.innerWidth()-parseInt(b.currentItem.css("paddingLeft")||0,10)-parseInt(b.currentItem.css("paddingRight")||0,10)))}}),b.placeholder=a(d.placeholder.element.call(b.element,b.currentItem)),b.currentItem.after(b.placeholder),d.placeholder.update(b,b.placeholder)},_contactContainers:function(d){var e,f,g,h,i,j,k,l,m,n,o=null,p=null;for(e=this.containers.length-1;e>=0;e--)if(!a.contains(this.currentItem[0],this.containers[e].element[0]))if(this._intersectsWith(this.containers[e].containerCache)){if(o&&a.contains(this.containers[e].element[0],o.element[0]))continue;o=this.containers[e],p=e}else this.containers[e].containerCache.over&&(this.containers[e]._trigger("out",d,this._uiHash(this)),this.containers[e].containerCache.over=0);if(o)if(1===this.containers.length)this.containers[p].containerCache.over||(this.containers[p]._trigger("over",d,this._uiHash(this)),this.containers[p].containerCache.over=1);else{for(g=1e4,h=null,n=o.floating||c(this.currentItem),i=n?"left":"top",j=n?"width":"height",k=this.positionAbs[i]+this.offset.click[i],f=this.items.length-1;f>=0;f--)a.contains(this.containers[p].element[0],this.items[f].item[0])&&this.items[f].item[0]!==this.currentItem[0]&&(!n||b(this.positionAbs.top+this.offset.click.top,this.items[f].top,this.items[f].height))&&(l=this.items[f].item.offset()[i],m=!1,Math.abs(l-k)>Math.abs(l+this.items[f][j]-k)&&(m=!0,l+=this.items[f][j]),Math.abs(l-k)this.containment[2]&&(f=this.containment[2]+this.offset.click.left),b.pageY-this.offset.click.top>this.containment[3]&&(g=this.containment[3]+this.offset.click.top)),e.grid&&(c=this.originalPageY+Math.round((g-this.originalPageY)/e.grid[1])*e.grid[1],g=this.containment?c-this.offset.click.top>=this.containment[1]&&c-this.offset.click.top<=this.containment[3]?c:c-this.offset.click.top>=this.containment[1]?c-e.grid[1]:c+e.grid[1]:c,d=this.originalPageX+Math.round((f-this.originalPageX)/e.grid[0])*e.grid[0],f=this.containment?d-this.offset.click.left>=this.containment[0]&&d-this.offset.click.left<=this.containment[2]?d:d-this.offset.click.left>=this.containment[0]?d-e.grid[0]:d+e.grid[0]:d)),{top:g-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():i?0:h.scrollTop()),left:f-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():i?0:h.scrollLeft())}},_rearrange:function(a,b,c,d){c?c[0].appendChild(this.placeholder[0]):b.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?b.item[0]:b.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var e=this.counter;this._delay(function(){e===this.counter&&this.refreshPositions(!d)})},_clear:function(a,b){this.reverting=!1;var c,d=[];if(!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null,this.helper[0]===this.currentItem[0]){for(c in this._storedCSS)("auto"===this._storedCSS[c]||"static"===this._storedCSS[c])&&(this._storedCSS[c]="");this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else this.currentItem.show();for(this.fromOutside&&!b&&d.push(function(a){this._trigger("receive",a,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||b||d.push(function(a){this._trigger("update",a,this._uiHash())}),this!==this.currentContainer&&(b||(d.push(function(a){this._trigger("remove",a,this._uiHash())}),d.push(function(a){return function(b){a._trigger("receive",b,this._uiHash(this))}}.call(this,this.currentContainer)),d.push(function(a){return function(b){a._trigger("update",b,this._uiHash(this))}}.call(this,this.currentContainer)))),c=this.containers.length-1;c>=0;c--)b||d.push(function(a){return function(b){a._trigger("deactivate",b,this._uiHash(this))}}.call(this,this.containers[c])),this.containers[c].containerCache.over&&(d.push(function(a){return function(b){a._trigger("out",b,this._uiHash(this)) }}.call(this,this.containers[c])),this.containers[c].containerCache.over=0);if(this.storedCursor&&(this.document.find("body").css("cursor",this.storedCursor),this.storedStylesheet.remove()),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex","auto"===this._storedZIndex?"":this._storedZIndex),this.dragging=!1,this.cancelHelperRemoval){if(!b){for(this._trigger("beforeStop",a,this._uiHash()),c=0;c
',trigger:"hover",title:"",delay:0,html:!0}}(window.jQuery),function(){var a=function(){!function(){function a(b,c){if({}.hasOwnProperty.call(a.cache,b))return a.cache[b];var d=a.resolve(b);if(!d)throw new Error("Failed to resolve module "+b);var e={id:b,require:a,filename:b,exports:{},loaded:!1,parent:c,children:[]};c&&c.children.push(e);var f=b.slice(0,b.lastIndexOf("/")+1);return a.cache[b]=e.exports,d.call(e.exports,e,e.exports,f,b),e.loaded=!0,a.cache[b]=e.exports}a.modules={},a.cache={},a.resolve=function(b){return{}.hasOwnProperty.call(a.modules,b)?a.modules[b]:void 0},a.define=function(b,c){a.modules[b]=c},a.define("/gif.worker.coffee",function(b){var c,d;c=a("/GIFEncoder.js",b),d=function(a){var b,d,e;return b=new c(a.width,a.height),0===a.index?b.writeHeader():b.firstFrame=!1,b.setRepeat(a.repeat),b.setDelay(a.delay),b.setQuality(a.quality),b.addFrame(a.data),a.last&&b.finish(),d=b.stream(),a.data=d.pages,a.cursor=d.cursor,a.pageSize=d.constructor.pageSize,a.canTransfer?(e=function(b){for(var c,d=0,e=a.data.length;e>d;++d)c=a.data[d],b.push(c.buffer);return b}.call(this,[]),self.postMessage(a,e)):self.postMessage(a)},self.onmessage=function(a){return d(a.data)}}),a.define("/GIFEncoder.js",function(b){function c(){this.page=-1,this.pages=[],this.newPage()}function d(a,b){this.width=~~a,this.height=~~b,this.transparent=null,this.transIndex=0,this.repeat=-1,this.delay=0,this.image=null,this.pixels=null,this.indexedPixels=null,this.colorDepth=null,this.colorTab=null,this.usedEntry=new Array,this.palSize=7,this.dispose=-1,this.firstFrame=!0,this.sample=10,this.out=new c}var e=a("/TypedNeuQuant.js",b),f=a("/LZWEncoder.js",b);c.pageSize=4096,c.charMap={};for(var g=0;256>g;g++)c.charMap[g]=String.fromCharCode(g);c.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(c.pageSize),this.cursor=0},c.prototype.getData=function(){for(var a="",b=0;b=c.pageSize&&this.newPage(),this.pages[this.page][this.cursor++]=a},c.prototype.writeUTFBytes=function(a){for(var b=a.length,c=0;b>c;c++)this.writeByte(a.charCodeAt(c))},c.prototype.writeBytes=function(a,b,c){for(var d=c||a.length,e=b||0;d>e;e++)this.writeByte(a[e])},d.prototype.setDelay=function(a){this.delay=Math.round(a/10)},d.prototype.setFrameRate=function(a){this.delay=Math.round(100/a)},d.prototype.setDispose=function(a){a>=0&&(this.dispose=a)},d.prototype.setRepeat=function(a){this.repeat=a},d.prototype.setTransparent=function(a){this.transparent=a},d.prototype.addFrame=function(a){this.image=a,this.getImagePixels(),this.analyzePixels(),this.firstFrame&&(this.writeLSD(),this.writePalette(),this.repeat>=0&&this.writeNetscapeExt()),this.writeGraphicCtrlExt(),this.writeImageDesc(),this.firstFrame||this.writePalette(),this.writePixels(),this.firstFrame=!1},d.prototype.finish=function(){this.out.writeByte(59)},d.prototype.setQuality=function(a){1>a&&(a=1),this.sample=a},d.prototype.writeHeader=function(){this.out.writeUTFBytes("GIF89a")},d.prototype.analyzePixels=function(){var a=this.pixels.length,b=a/3;this.indexedPixels=new Uint8Array(b);var c=new e(this.pixels,this.sample);c.buildColormap(),this.colorTab=c.getColormap();for(var d=0,f=0;b>f;f++){var g=c.lookupRGB(255&this.pixels[d++],255&this.pixels[d++],255&this.pixels[d++]);this.usedEntry[g]=!0,this.indexedPixels[f]=g}this.pixels=null,this.colorDepth=8,this.palSize=7,null!==this.transparent&&(this.transIndex=this.findClosest(this.transparent))},d.prototype.findClosest=function(a){if(null===this.colorTab)return-1;for(var b=(16711680&a)>>16,c=(65280&a)>>8,d=255&a,e=0,f=16777216,g=this.colorTab.length,h=0;g>h;){var i=b-(255&this.colorTab[h++]),j=c-(255&this.colorTab[h++]),k=d-(255&this.colorTab[h]),l=i*i+j*j+k*k,m=h/3;this.usedEntry[m]&&f>l&&(f=l,e=m),h++}return e},d.prototype.getImagePixels=function(){var a=this.width,b=this.height;this.pixels=new Uint8Array(3*a*b);for(var c=this.image,d=0,e=0;b>e;e++)for(var f=0;a>f;f++){var g=4*e*a+4*f;this.pixels[d++]=c[g],this.pixels[d++]=c[g+1],this.pixels[d++]=c[g+2]}},d.prototype.writeGraphicCtrlExt=function(){this.out.writeByte(33),this.out.writeByte(249),this.out.writeByte(4);var a,b;null===this.transparent?(a=0,b=0):(a=1,b=2),this.dispose>=0&&(b=7&dispose),b<<=2,this.out.writeByte(0|(0|b)|a),this.writeShort(this.delay),this.out.writeByte(this.transIndex),this.out.writeByte(0)},d.prototype.writeImageDesc=function(){this.out.writeByte(44),this.writeShort(0),this.writeShort(0),this.writeShort(this.width),this.writeShort(this.height),this.firstFrame?this.out.writeByte(0):this.out.writeByte(128|this.palSize)},d.prototype.writeLSD=function(){this.writeShort(this.width),this.writeShort(this.height),this.out.writeByte(240|this.palSize),this.out.writeByte(0),this.out.writeByte(0)},d.prototype.writeNetscapeExt=function(){this.out.writeByte(33),this.out.writeByte(255),this.out.writeByte(11),this.out.writeUTFBytes("NETSCAPE2.0"),this.out.writeByte(3),this.out.writeByte(1),this.writeShort(this.repeat),this.out.writeByte(0)},d.prototype.writePalette=function(){this.out.writeBytes(this.colorTab);for(var a=768-this.colorTab.length,b=0;a>b;b++)this.out.writeByte(0)},d.prototype.writeShort=function(a){this.out.writeByte(255&a),this.out.writeByte(255&a>>8)},d.prototype.writePixels=function(){var a=new f(this.width,this.height,this.indexedPixels,this.colorDepth);a.encode(this.out)},d.prototype.stream=function(){return this.out},b.exports=d}),a.define("/LZWEncoder.js",function(a){function b(a,b,g,h){function i(a,b){y[s++]=a,s>=254&&n(b)}function j(a){k(e),C=v+2,D=!0,q(v,a)}function k(a){for(var b=0;a>b;++b)z[b]=-1}function l(a,b){var f,g,h,i,l,m,n;for(u=a,D=!1,n_bits=u,t=o(n_bits),v=1<f;f*=2)++n;n=8-n,m=e,k(m),q(v,b);a:for(;(g=p())!=c;)if(f=(g<=0){l=m-h,0===h&&(l=1);do if((h-=l)<0&&(h+=m),z[h]===f){i=A[h];continue a}while(z[h]>=0)}q(i,b),i=g,1<C?(A[h]=C++,z[h]=f):j(b)}else i=A[h];q(i,b),q(w,b)}function m(c){c.writeByte(x),remaining=a*b,curPixel=0,l(x+1,c),c.writeByte(0)}function n(a){s>0&&(a.writeByte(s),a.writeBytes(y,0,s),s=0)}function o(a){return(1<0?r|=a<=8;)i(255&r,b),r>>=8,B-=8;if((C>t||D)&&(D?(t=o(n_bits=u),D=!1):(++n_bits,t=n_bits==d?1<0;)i(255&r,b),r>>=8,B-=8;n(b)}}var r,s,t,u,v,w,x=Math.max(2,h),y=new Uint8Array(256),z=new Int32Array(e),A=new Int32Array(e),B=0,C=0,D=!1;this.encode=m}var c=-1,d=12,e=5003,f=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];a.exports=b}),a.define("/TypedNeuQuant.js",function(a){function b(a,b){function m(){H=[],I=new Int32Array(256),J=new Int32Array(d),K=new Int32Array(d),L=new Int32Array(d>>3);var a,b;for(a=0;d>a;a++)b=(a<a;a++)H[a][0]>>=f,H[a][1]>>=f,H[a][2]>>=f,H[a][3]=a}function r(a,b,c,d,e){H[b][0]-=a*(H[b][0]-c)/s,H[b][1]-=a*(H[b][1]-d)/s,H[b][2]-=a*(H[b][2]-e)/s}function t(a,b,c,e,f){for(var g,h,i=Math.abs(b-a),j=Math.min(b+a,d),k=b+1,l=b-1,m=1;j>k||l>i;)h=L[m++],j>k&&(g=H[k++],g[0]-=h*(g[0]-c)/w,g[1]-=h*(g[1]-e)/w,g[2]-=h*(g[2]-f)/w),l>i&&(g=H[l--],g[0]-=h*(g[0]-c)/w,g[1]-=h*(g[1]-e)/w,g[2]-=h*(g[2]-f)/w)}function v(a,b,c){var e,h,m,n,o,p=2147483647,q=p,r=-1,s=r;for(e=0;d>e;e++)h=H[e],m=Math.abs(h[0]-a)+Math.abs(h[1]-b)+Math.abs(h[2]-c),p>m&&(p=m,r=e),n=m-(J[e]>>g-f),q>n&&(q=n,s=e),o=K[e]>>j,K[e]-=o,J[e]+=o<a;a++){for(c=H[a],g=a,h=c[1],b=a+1;d>b;b++)f=H[b],f[1]>1,b=i+1;h>b;b++)I[b]=a;i=h,j=a}}for(I[i]=j+e>>1,b=i+1;256>b;b++)I[b]=e}function D(a,b,c){for(var e,f,g,h=1e3,i=-1,j=I[b],k=j-1;d>j||k>=0;)d>j&&(f=H[j],g=f[1]-b,g>=h?j=d:(j++,0>g&&(g=-g),e=f[0]-a,0>e&&(e=-e),g+=e,h>g&&(e=f[2]-c,0>e&&(e=-e),g+=e,h>g&&(h=g,i=f[3])))),k>=0&&(f=H[k],g=b-f[1],g>=h?k=-1:(k--,0>g&&(g=-g),e=f[0]-a,0>e&&(e=-e),g+=e,h>g&&(e=f[2]-c,0>e&&(e=-e),g+=e,h>g&&(h=g,i=f[3]))));return i}function E(){var d,e=a.length,g=30+(b-1)/3,h=e/(3*b),i=~~(h/c),j=s,k=p,l=k>>n;for(1>=l&&(l=0),d=0;l>d;d++)L[d]=j*((l*l-d*d)*u/(l*l));var m;B>e?(b=1,m=3):m=0!==e%x?3*x:0!==e%y?3*y:0!==e%z?3*z:3*A;var o,w,C,D,E=0;for(d=0;h>d;)if(o=(255&a[E])<=e&&(E-=e),d++,0===i&&(i=1),0===d%i)for(j-=j/g,k-=k/q,l=k>>n,1>=l&&(l=0),D=0;l>D;D++)L[D]=j*((l*l-D*D)*u/(l*l))}function F(){m(),E(),o(),C()}function G(){for(var a=[],b=[],c=0;d>c;c++)b[H[c][3]]=c;for(var e=0,f=0;d>f;f++){var g=b[f];a[e++]=H[g][0],a[e++]=H[g][1],a[e++]=H[g][2]}return a}var H,I,J,K,L;this.buildColormap=F,this.getColormap=G,this.lookupRGB=D}var c=100,d=256,e=d-1,f=4,g=16,h=1<>j,l=h<>3,n=6,o=1<c;++c)if(c in b&&b[c]===a)return!0;return!1}function e(a,b){function d(){this.constructor=a}for(var e in b)c(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a}var f,g,h;g=b("events",a).EventEmitter,f=b("/browser.coffee",a),h=function(a,b,g){function h(a){var c,d;this.running=!1,this.options={},this.frames=[],this.freeWorkers=[],this.activeWorkers=[],this.setOptions(a);for(c in b)d=b[c],null!=this.options[c]?this.options[c]:this.options[c]=d}return e(h,a),b={workerScript:window.GifWorkerURL,workers:2,repeat:0,background:"#fff",quality:10,width:null,height:null},g={delay:500,copy:!1},h.prototype.setOption=function(a,b){return this.options[a]=b,null==this._canvas||"width"!==a&&"height"!==a?void 0:this._canvas[a]=b},h.prototype.setOptions=function(a){return function(b){var d,e;for(d in a)c(a,d)&&(e=a[d],b.push(this.setOption(d,e)));return b}.call(this,[])},h.prototype.addFrame=function(a,b){var c,d;null==b&&(b={}),c={};for(d in g)c[d]=b[d]||g[d];if(null!=this.options.width||this.setOption("width",a.width),null!=this.options.height||this.setOption("height",a.height),"undefined"!=typeof ImageData&&null!=ImageData&&a instanceof ImageData)c.data=a.data;else if("undefined"!=typeof CanvasRenderingContext2D&&null!=CanvasRenderingContext2D&&a instanceof CanvasRenderingContext2D||"undefined"!=typeof WebGLRenderingContext&&null!=WebGLRenderingContext&&a instanceof WebGLRenderingContext)b.copy?c.data=this.getContextData(a):c.context=a;else{if(null==a.childNodes)throw new Error("Invalid image");b.copy?c.data=this.getImageData(a):c.image=a}return this.frames.push(c)},h.prototype.render=function(){var a,b;if(this.running)throw new Error("Already running");if(null==this.options.width||null==this.options.height)throw new Error("Width and height must be set prior to rendering");this.running=!0,this.nextFrame=0,this.finishedFrames=0,this.imageParts=function(a){for(var b,c=0,d=function(){var a,a;a=[];for(var b=0;0<=this.frames.length?bthis.frames.length;0<=this.frames.length?++b:--b)a.push(b);return a}.apply(this,arguments).length;d>c;++c)b=function(){var a,a;a=[];for(var b=0;0<=this.frames.length?bthis.frames.length;0<=this.frames.length?++b:--b)a.push(b);return a}.apply(this,arguments)[c],a.push(null);return a}.call(this,[]),b=this.spawnWorkers();for(var c=0,d=function(){var a,a;a=[];for(var c=0;b>=0?b>c:c>b;b>=0?++c:--c)a.push(c);return a}.apply(this,arguments).length;d>c;++c)a=function(){var a,a;a=[];for(var c=0;b>=0?b>c:c>b;b>=0?++c:--c)a.push(c);return a}.apply(this,arguments)[c],this.renderNextFrame();return this.emit("start"),this.emit("progress",0)},h.prototype.abort=function(){for(var a;;){if(a=this.activeWorkers.shift(),!(null!=a))break;console.log("killing active worker"),a.terminate()}return this.running=!1,this.emit("abort")},h.prototype.spawnWorkers=function(){var a,b;return a=Math.min(this.options.workers,this.frames.length),function(){var b;b=[];for(var c=this.freeWorkers.length;this.freeWorkers.length<=a?a>c:c>a;this.freeWorkers.length<=a?++c:--c)b.push(c);return b}.apply(this,arguments).forEach((b=this,function(a){var c,d;return console.log("spawning worker "+a),d=new Worker(b.options.workerScript),c=b,d.onmessage=function(a){return c.activeWorkers.splice(c.activeWorkers.indexOf(d),1),c.freeWorkers.push(d),c.frameFinished(a.data)},b.freeWorkers.push(d)})),a},h.prototype.frameFinished=function(a){return console.log("frame "+a.index+" finished - "+this.activeWorkers.length+" active"),this.finishedFrames++,this.emit("progress",this.finishedFrames/this.frames.length),this.imageParts[a.index]=a,d(null,this.imageParts)?this.renderNextFrame():this.finishRendering()},h.prototype.finishRendering=function(){var a,b,c,d,e,f,g;e=0;for(var h=0,i=this.imageParts.length;i>h;++h)b=this.imageParts[h],e+=(b.data.length-1)*b.pageSize+b.cursor;e+=b.pageSize-b.cursor,console.log("rendering finished - filesize "+Math.round(e/1e3)+"kb"),a=new Uint8Array(e),f=0;for(var j=0,k=this.imageParts.length;k>j;++j){b=this.imageParts[j];for(var l=0,m=b.data.length;m>l;++l)g=b.data[l],c=l,a.set(g,f),f+=c===b.data.length-1?b.cursor:b.pageSize}return d=new Blob([a],{type:"image/gif"}),this.emit("finished",d,a)},h.prototype.renderNextFrame=function(){var a,b,c;if(0===this.freeWorkers.length)throw new Error("No free workers");return this.nextFrame>=this.frames.length?void 0:(a=this.frames[this.nextFrame++],c=this.freeWorkers.shift(),b=this.getTask(a),console.log("starting frame "+(b.index+1)+" of "+this.frames.length),this.activeWorkers.push(c),c.postMessage(b))},h.prototype.getContextData=function(a){return a.getImageData(0,0,this.options.width,this.options.height).data},h.prototype.getImageData=function(a){var b;return null!=this._canvas||(this._canvas=document.createElement("canvas"),this._canvas.width=this.options.width,this._canvas.height=this.options.height),b=this._canvas.getContext("2d"),b.setFill=this.options.background,b.fillRect(0,0,this.options.width,this.options.height),b.drawImage(a,0,0),this.getContextData(b)},h.prototype.getTask=function(a){var b,c;if(b=this.frames.indexOf(a),c={index:b,last:b===this.frames.length-1,delay:a.delay,width:this.options.width,height:this.options.height,quality:this.options.quality,repeat:this.options.repeat,canTransfer:"chrome"===f.name},null!=a.data)c.data=a.data;else if(null!=a.context)c.data=this.getContextData(a.context);else{if(null==a.image)throw new Error("Invalid frame");c.data=this.getImageData(a.image)}return c},h}(g),a.exports=h}),b.define("/browser.coffee",function(a){var b,c,d,e,f;e=navigator.userAgent.toLowerCase(),d=navigator.platform.toLowerCase(),f=e.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/)||[null,"unknown",0],c="ie"===f[1]&&document.documentMode,b={name:"version"===f[1]?f[3]:f[1],version:c||parseFloat("opera"===f[1]&&f[4]?f[4]:f[2]),platform:{name:e.match(/ip(?:ad|od|hone)/)?"ios":(e.match(/(?:webos|android)/)||d.match(/mac|win|linux/)||["other"])[0]}},b[b.name]=!0,b[b.name+parseInt(b.version,10)]=!0,b.platform[b.platform.name]=!0,a.exports=b}),b.define("events",function(a,b){c.EventEmitter||(c.EventEmitter=function(){});var d=b.EventEmitter=c.EventEmitter,e="function"==typeof Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},f=10;d.prototype.setMaxListeners=function(a){this._events||(this._events={}),this._events.maxListeners=a},d.prototype.emit=function(a){if("error"===a&&(!this._events||!this._events.error||e(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var b=this._events[a];if(!b)return!1;if("function"!=typeof b){if(e(b)){for(var c=Array.prototype.slice.call(arguments,1),d=b.slice(),f=0,g=d.length;g>f;f++)d[f].apply(this,c);return!0}return!1}switch(arguments.length){case 1:b.call(this);break;case 2:b.call(this,arguments[1]);break;case 3:b.call(this,arguments[1],arguments[2]);break;default:var c=Array.prototype.slice.call(arguments,1);b.apply(this,c)}return!0},d.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(e(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:f,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},d.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(e(c)){var d=c.indexOf(b);if(0>d)return this;c.splice(d,1),0==c.length&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},d.prototype.removeAllListeners=function(a){return a&&this._events&&this._events[a]&&(this._events[a]=null),this},d.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),e(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}),a.GIF=b("/gif.coffee")}.call(this,this),function(a,b,c){function d(a,b,c){for(var d=[],e=0;e')}return"
"+d.join("")+"
"}function e(){for(var a=0;a1&&(delete a.localStorage[W],b.each(e,function(a,b){t(b)}))}catch(f){}try{nb=a.localStorage[W].split(";")}catch(f){}}Kb.bind("click.spectrum touchstart.spectrum",function(a){tb||B(),a.stopPropagation(),b(a.target).is("input")||a.preventDefault()}),(sb.is(":disabled")||T.disabled===!0)&&S(),ub.click(j),Cb.change(A),Cb.bind("paste",function(){setTimeout(A,1)}),Cb.keydown(function(a){13==a.keyCode&&A()}),Fb.text(T.cancelText),Fb.bind("click.spectrum",function(a){a.stopPropagation(),a.preventDefault(),F("cancel")}),Gb.text(T.chooseText),Gb.bind("click.spectrum",function(a){a.stopPropagation(),a.preventDefault(),J()&&(N(!0),F())}),l(Ab,function(a,b,c){kb=a/eb,c.shiftKey&&(kb=Math.round(10*kb)/10),K()}),l(xb,function(a,b){hb=parseFloat(b/cb),K()},y,z),l(vb,function(a,b,c){if(c.shiftKey){if(!qb){var d=ib*_,e=ab-jb*ab,f=Math.abs(a-d)>Math.abs(b-e);qb=f?"x":"y"}}else qb=null;var g=!qb||"x"===qb,h=!qb||"y"===qb;g&&(ib=parseFloat(a/_)),h&&(jb=parseFloat((ab-b)/ab)),K()},y,z),Mb?(H(Mb),L(),Pb=Ob||u(Mb).format,t(Mb)):L(),U&&C();var g=p?"mousedown.spectrum":"click.spectrum touchstart.spectrum";Db.delegate(".sp-thumb-el",g,c),Eb.delegate(".sp-thumb-el:nth-child(1)",g,{ignore:!0},c)}function t(c){if(V){var d=u(c).toRgbString();if(-1===b.inArray(d,nb))for(nb.push(d);nb.length>ob;)nb.shift();if(W&&a.localStorage)try{a.localStorage[W]=nb.join(";")}catch(e){}}}function v(){var a,b=[],c=nb,d={};if(T.showPalette){for(var e=0;e=ab||0>=_||0>=cb)&&O(),ub.addClass(pb),qb=null}function z(){ub.removeClass(pb)}function A(){var a=u(Cb.val());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);var Constants={DEFAULT:{HEIGHT:32,WIDTH:32,FPS:12},MODEL_VERSION:2,MAX_HEIGHT:1024,MAX_WIDTH:1024,MINIMUM_ZOOM:1,PREVIEW_FILM_SIZE:120,ANIMATED_PREVIEW_WIDTH:200,DEFAULT_PEN_COLOR:"#000000",TRANSPARENT_COLOR:"rgba(0, 0, 0, 0)",NO_PALETTE_ID:"__no-palette",PREFERRED_COLOR_FORMAT:"rgb",SELECTION_TRANSPARENT_COLOR:"rgba(255, 255, 255, 0.6)",TOOL_TARGET_HIGHLIGHT_COLOR:"rgba(255, 255, 255, 0.2)",STATIC:{URL:{SAVE:"http://3.piskel-app.appspot.com/store",GET:"http://3.piskel-app.appspot.com/get"}},APPENGINE:{URL:{SAVE:"save"}},IMAGE_SERVICE_UPLOAD_URL:"http://piskel-imgstore-a.appspot.com/__/upload",IMAGE_SERVICE_GET_URL:"http://piskel-imgstore-a.appspot.com/img/",ZOOMED_OUT_BACKGROUND_COLOR:"#A0A0A0",LEFT_BUTTON:0,MIDDLE_BUTTON:1,RIGHT_BUTTON:2,MOUSEMOVE_THROTTLING:10,ABSTRACT_FUNCTION:function(){throw"abstract method should be implemented"}},Events={TOOL_SELECTED:"TOOL_SELECTED",TOOL_RELEASED:"TOOL_RELEASED",SELECT_PRIMARY_COLOR:"SELECT_PRIMARY_COLOR",SELECT_SECONDARY_COLOR:"SELECT_SECONDARY_COLOR",PRIMARY_COLOR_SELECTED:"PRIMARY_COLOR_SELECTED",SECONDARY_COLOR_SELECTED:"SECONDARY_COLOR_SELECTED",DIALOG_DISPLAY:"DIALOG_DISPLAY",DIALOG_HIDE:"DIALOG_HIDE",PALETTE_LIST_UPDATED:"PALETTE_LIST_UPDATED",LOCALSTORAGE_REQUEST:"LOCALSTORAGE_REQUEST",USER_SETTINGS_CHANGED:"USER_SETTINGS_CHANGED",CLOSE_SETTINGS_DRAWER:"CLOSE_SETTINGS_DRAWER",PISKEL_RESET:"PISKEL_RESET",PISKEL_SAVED:"PISKEL_SAVED",FRAME_SIZE_CHANGED:"FRAME_SIZE_CHANGED",SELECTION_CREATED:"SELECTION_CREATED",SELECTION_MOVE_REQUEST:"SELECTION_MOVE_REQUEST",SELECTION_DISMISSED:"SELECTION_DISMISSED",SHOW_NOTIFICATION:"SHOW_NOTIFICATION",HIDE_NOTIFICATION:"HIDE_NOTIFICATION",ZOOM_CHANGED:"ZOOM_CHANGED"};jQuery.namespace=function(){var a,b,c,d=arguments,e=null;for(a=0;a255||b>255||c>255)throw"Invalid color component";return(a<<16|b<<8|c).toString(16)},a.inherit=function(a,b){a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.prototype.superclass=b.prototype}}(),function(){var a=$.namespace("pskl.utils"),b=navigator.userAgent;a.UserAgent={isIE:/MSIE/i.test(b),isChrome:/Chrome/i.test(b),isFirefox:/Firefox/i.test(b)},a.UserAgent.version=function(){return pskl.utils.UserAgent.isIE?parseInt(/MSIE\s?(\d+)/i.exec(b)[1],10):pskl.utils.UserAgent.isChrome?parseInt(/Chrome\/(\d+)/i.exec(b)[1],10):pskl.utils.UserAgent.isFirefox?parseInt(/Firefox\/(\d+)/i.exec(b)[1],10):void 0}()}(),function(){var a=$.namespace("pskl");a.CanvasUtils={createCanvas:function(a,b,c){var d=document.createElement("canvas");if(d.setAttribute("width",a),d.setAttribute("height",b),"string"==typeof c&&(c=[c]),Array.isArray(c))for(var e=0;ee;e++){d[e]=[];for(var f=0;c>f;f++){var g=4*(f*b+e),h=a[g],i=a[g+1],j=a[g+2],k=a[g+3];d[e][f]=125>k?Constants.TRANSPARENT_COLOR:pskl.utils.FrameUtils.rgbToHex(h,i,j)}}return pskl.model.Frame.fromPixelGrid(d)},rgbToHex:function(a,b,c){return"#"+this.componentToHex(a)+this.componentToHex(b)+this.componentToHex(c)},componentToHex:function(a){var b=a.toString(16);return 1==b.length?"0"+b:b}}}(),function(){var a=$.namespace("pskl.utils");a.LayerUtils={createFromImage:function(a,b){var c=a.width,d=a.height,e=c/b,f=pskl.CanvasUtils.createCanvas(c,d),g=f.getContext("2d");g.drawImage(a,0,0,c,d,0,0,c,d);for(var h=[],i=0;b>i;i++){var j=g.getImageData(e*i,0,e,d).data,k=pskl.utils.FrameUtils.createFromImageData(j,e,d);h.push(k)}return h}}}(),function(){var a=$.namespace("pskl.utils");a.ImageResizer={resize:function(a,b,c,d){var e=pskl.CanvasUtils.createCanvas(b,c),f=e.getContext("2d");return f.save(),d||pskl.CanvasUtils.disableImageSmoothing(e),f.translate(e.width/2,e.height/2),f.scale(b/a.width,c/a.height),f.drawImage(a,-a.width/2,-a.height/2),f.restore(),e},resizeNearestNeighbour:function(a,b,c,d){c=c||0;for(var e,f,g=pskl.CanvasUtils.createCanvas(b*a.width,b*a.height),h=g.getContext("2d"),i=pskl.CanvasUtils.getImageDataFromCanvas(a),j={},k=0,l=0,m=0;m0;){k++;var m=g.pop();a.setPixel(m.col,m.row,d),f.push({col:m.col,row:m.row});for(var n=0;4>n;n++){var o=m.col+i[n],p=m.row+h[n];try{a.containsPixel(o,p)&&a.getPixel(o,p)==e&&g.push({col:o,row:p})}catch(j){}}if(k>10*l){console.log("loop breaker called");break}}return f}},calculateZoomForContainer:function(a,b,c){return this.calculateZoom(a.height(),a.width(),b,c)},calculateZoom:function(a,b,c,d){var e=Math.floor(a/c),f=Math.floor(b/d);return Math.min(e,f)}}}(),function(){var a=$.namespace("pskl.utils");a.Template={get:function(a){var b=document.getElementById(a);return b?b.innerHTML:(console.error("Could not find template for id :",a),void 0)},createFromHTML:function(a){var b=document.createElement("div");return b.innerHTML=a,b.children[0]},replace:function(a,b){for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];-1!==c.indexOf(":")&&(d===!0?d=c.split(":")[1]:d===!1&&(d="")),a=a.replace(new RegExp("\\{\\{"+c+"\\}\\}","g"),d)}return a}}}(),function(){var a=$.namespace("pskl");a.UserSettings={GRID_WIDTH:"GRID_WIDTH",CANVAS_BACKGROUND:"CANVAS_BACKGROUND",SELECTED_PALETTE:"SELECTED_PALETTE",KEY_TO_DEFAULT_VALUE_MAP_:{GRID_WIDTH:0,CANVAS_BACKGROUND:"lowcont-dark-canvas-background",SELECTED_PALETTE:Constants.NO_PALETTE_ID},cache_:{},get:function(a){return this.checkKeyValidity_(a),a in this.cache_||(this.cache_[a]=this.readFromLocalStorage_(a)||this.readFromDefaults_(a)),this.cache_[a]},set:function(a,b){this.checkKeyValidity_(a),this.cache_[a]=b,this.writeToLocalStorage_(a,b),$.publish(Events.USER_SETTINGS_CHANGED,[a,b])},readFromLocalStorage_:function(a){var b=window.localStorage[a];return"undefined"!=typeof b&&(b=JSON.parse(b)),b},writeToLocalStorage_:function(a,b){window.localStorage[a]=JSON.stringify(b)},readFromDefaults_:function(a){return this.KEY_TO_DEFAULT_VALUE_MAP_[a]},checkKeyValidity_:function(a){a in this.KEY_TO_DEFAULT_VALUE_MAP_||console.log("UserSettings key <"+a+"> not find in supported keys.")}}}(),function(){var a=$.namespace("pskl.utils");a.Serializer={serializePiskel:function(a){var b=a.getLayers().map(function(a){return pskl.utils.Serializer.serializeLayer(a)});return JSON.stringify({modelVersion:Constants.MODEL_VERSION,piskel:{height:a.getHeight(),width:a.getWidth(),layers:b}})},serializeLayer:function(a){var b=a.getFrames(),c=new pskl.rendering.FramesheetRenderer(b),d=c.renderAsCanvas().toDataURL();return JSON.stringify({name:a.getName(),base64PNG:d,frameCount:b.length})}}}(),function(){var a=$.namespace("pskl.utils.serialization");a.Deserializer=function(a,b){this.layersToLoad_=0,this.data_=a,this.callback_=b,this.piskel_=null},a.Deserializer.deserialize=function(b,c){var d;d=b.modelVersion==Constants.MODEL_VERSION?new a.Deserializer(b,c):1==b.modelVersion?new a.backward.Deserializer_v1(b,c):new a.backward.Deserializer_v0(b,c),d.deserialize()},a.Deserializer.prototype.deserialize=function(a){var b=this.data_,c=b.piskel;a=a||"Deserialized piskel";var d=new pskl.model.piskel.Descriptor(a,"");this.piskel_=new pskl.model.Piskel(c.width,c.height,d),this.layersToLoad_=c.layers.length,c.layers.forEach(function(a){var b=this.deserializeLayer(a);this.piskel_.addLayer(b)}.bind(this))},a.Deserializer.prototype.deserializeLayer=function(a){var b=JSON.parse(a),c=new pskl.model.Layer(b.name),d=b.base64PNG,e=new Image;return e.onload=function(){var a=pskl.utils.LayerUtils.createFromImage(e,b.frameCount);a.forEach(c.addFrame.bind(c)),this.onLayerLoaded_()}.bind(this),e.src=d,c},a.Deserializer.prototype.onLayerLoaded_=function(){this.layersToLoad_=this.layersToLoad_-1,0===this.layersToLoad_&&this.callback_(this.piskel_)}}(),function(){var a=$.namespace("pskl.utils.serialization.backward");a.Deserializer_v0=function(a,b){this.data_=a,this.callback_=b},a.Deserializer_v0.prototype.deserialize=function(){var a=this.data_,b=a.map(function(a){return pskl.model.Frame.fromPixelGrid(a)}),c=new pskl.model.piskel.Descriptor("Deserialized piskel",""),d=pskl.model.Layer.fromFrames("Layer 1",b);this.callback_(pskl.model.Piskel.fromLayers([d],c))}}(),function(){var a=$.namespace("pskl.utils.serialization.backward");a.Deserializer_v1=function(a,b){this.callback_=b,this.data_=a},a.Deserializer_v1.prototype.deserialize=function(){var a=this.data_.piskel,b=new pskl.model.piskel.Descriptor("Deserialized piskel",""),c=new pskl.model.Piskel(a.width,a.height,b);a.layers.forEach(function(a){var b=this.deserializeLayer(a);c.addLayer(b)}.bind(this)),this.callback_(c)},a.Deserializer_v1.prototype.deserializeLayer=function(a){var b=JSON.parse(a),c=new pskl.model.Layer(b.name);return b.frames.forEach(function(a){var b=this.deserializeFrame(a);c.addFrame(b)}.bind(this)),c},a.Deserializer_v1.prototype.deserializeFrame=function(a){var b=JSON.parse(a);return pskl.model.Frame.fromPixelGrid(b)}}(),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)},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;c=0&&b>=0&&a0&&(this.stateIndex--,this.setPixels(this.previousStates[this.stateIndex]))},a.Frame.prototype.loadNextState=function(){this.stateIndex0&&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)}}(),function(){var a=$.namespace("pskl.selection");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)),$.subscribe(Events.TOOL_SELECTED,$.proxy(this.onToolSelected_,this))},a.SelectionManager.prototype.cleanSelection_=function(){this.currentSelection&&this.currentSelection.reset()},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.erase=function(){for(var a=this.currentSelection.pixels,b=this.piskelController.getCurrentFrame(),c=0,d=a.length;d>c;c++)try{b.setPixel(a[c].col,a[c].row,Constants.TRANSPARENT_COLOR)}catch(e){}},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)for(var a=this.currentSelection.pixels,b=this.piskelController.getCurrentFrame(),c=0,d=a.length;d>c;c++)try{b.setPixel(a[c].col,a[c].row,a[c].copiedColor)}catch(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){for(var b,c=0,d=this.pixels.length;d>c;c++)b=this.pixels[c],b.copiedColor=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.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.moveOffset=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.moveOffset=function(a,b){this.renderers.forEach(function(c){c.moveOffset(a,b)})},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.currentFrameIndex,e=this.piskelController.currentLayerIndex,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.getFrameForLayersAt_=function(a,b){var c=b.map(function(b){return b.getFrameAt(a)});return pskl.utils.FrameUtils.merge(c)}}(),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)),this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,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.moveOffset=function(a,b){this.setOffset(this.offset.x+a,this.offset.y+b)},a.FrameRenderer.prototype.setOffset=function(a,b){if(this.canvas){var c=this.canvas.width-this.displayWidth/this.zoom;a=pskl.utils.Math.minmax(a,0,c);var d=this.canvas.height-this.displayHeight/this.zoom;b=pskl.utils.Math.minmax(b,0,d)}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(){var a=this.displayWidth-this.zoom*this.canvas.width;this.margin.x=Math.max(0,a)/2;var b=this.displayHeight-this.zoom*this.canvas.height;this.margin.y=Math.max(0,b)/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.CANVAS_BACKGROUND?this.updateBackgroundClass_(c):b==pskl.UserSettings.GRID_WIDTH&&this.setGridWidth(c)},a.FrameRenderer.prototype.updateBackgroundClass_=function(a){var b=this.container.data("current-background-class");b&&this.container.removeClass(b),this.container.addClass(a),this.container.data("current-background-class",a)},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_(),b=this.displayCanvas.getContext("2d"),b.save(),this.canvas.width*this.zoom0;if(j||h){var k=pskl.utils.ImageResizer.resizeNearestNeighbour(this.canvas,this.zoom,i);b.drawImage(k,0,0)}else b.scale(this.zoom,this.zoom),b.drawImage(this.canvas,0,0);b.restore()}}(),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.render=function(a){var b=this.getOffset(),c=this.getDisplaySize(),d=[this.getZoom(),this.getGridWidth(),b.x,b.y,c.width,c.height,a.serialize()].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");return this.frame.forEachPixel(function(a,c,d){this.renderPixel_(a,c,d,b)}.bind(this)),a},a.CanvasRenderer.prototype.renderPixel_=function(a,b,c,d){a==Constants.TRANSPARENT_COLOR&&(a=this.transparentColor_),d.fillStyle=a,d.fillRect(b*this.zoom,c*this.zoom,this.zoom,this.zoom)},a.CanvasRenderer.prototype.createCanvas_=function(){var a=this.frame.getWidth()*this.zoom,b=this.frame.getHeight()*this.zoom;return pskl.CanvasUtils.createCanvas(a,b)}}(),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),$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.currentFrameIndex)},a.PiskelController.prototype.duplicateFrameAt=function(a){var b=this.getLayers();b.forEach(function(b){b.duplicateFrameAt(a)}),$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.moveFrame=function(a,b){var c=this.getLayers();c.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,$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.selectNextFrame=function(){var a=this.currentFrameIndex+1;a=0&&this.setCurrentFrameIndex(a)},a.PiskelController.prototype.setCurrentLayerIndex=function(a){this.currentLayerIndex=a,$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.selectLayer=function(a){var b=this.getLayers().indexOf(a);-1!=b&&this.setCurrentLayerIndex(b)},a.PiskelController.prototype.selectLayerByName=function(a){if(this.hasLayerForName_(a)){var b=this.piskel.getLayersByName(a)[0];this.selectLayer(b)}},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.removeCurrentLayer=function(){if(this.getLayers().length>1){var a=this.getCurrentLayer();this.piskel.removeLayer(a),this.setCurrentLayerIndex(0)}},a.PiskelController.prototype.serialize=function(){return pskl.utils.Serializer.serializePiskel(this.piskel)},a.PiskelController.prototype.load=function(a){this.deserialize(JSON.stringify(a))}}(),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.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),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)),this.centerColumnWrapperHorizontally_()},a.DrawingController.prototype.initMouseBehavior=function(){var a=$("body");this.container.mousedown($.proxy(this.onMousedown_,this)),this.container.mouseenter($.proxy(this.onMouseenter_,this)),this.container.mouseleave($.proxy(this.onMouseleave_,this)),pskl.utils.UserAgent.isChrome?this.container.on("mousewheel",$.proxy(this.onMousewheel_,this)):this.container.on("wheel",$.proxy(this.onMousewheel_,this)),a.mouseup($.proxy(this.onMouseup_,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 !")},a.DrawingController.prototype.onFrameSizeChanged_=function(){this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.compositeRenderer.setZoom(this.calculateZoom_()),this.compositeRenderer.setOffset(0,0),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onMouseenter_=function(){this.container.bind("mousemove",$.proxy(this.onMousemove_,this))},a.DrawingController.prototype.onMouseleave_=function(){this.container.unbind("mousemove"),this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame)},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),$.publish(Events.LOCALSTORAGE_REQUEST))},a.DrawingController.prototype.onMousemove_=function(a){var b=(new Date).getTime();if(b-this.previousMousemoveTime>Constants.MOUSEMOVE_THROTTLING){var c=this.renderer.getCoordinates(a.clientX,a.clientY);this.isClicked?(this.currentToolBehavior.moveToolAt(c.x,c.y,this.getCurrentColor_(a),this.piskelController.getCurrentFrame(),this.overlayFrame,a),$.publish(Events.LOCALSTORAGE_REQUEST)):this.currentToolBehavior.moveUnactiveToolAt(c.x,c.y,this.getCurrentColor_(a),this.piskelController.getCurrentFrame(),this.overlayFrame,a),this.previousMousemoveTime=b}},a.DrawingController.prototype.onMousewheel_=function(a){var b=a.originalEvent,c=b.wheelDeltaY||-2*b.deltaY,d=this.renderer.getZoom(),e=this.calculateZoom_(),f=e/10;c>0?this.compositeRenderer.setZoom(d+f):0>c&&this.compositeRenderer.setZoom(d-f),$.publish(Events.ZOOM_CHANGED)},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)),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;return e-50},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");a.PreviewFilmController=function(a,b){this.piskelController=a,this.container=b,this.refreshZoom_(),this.redrawFlag=!0},a.PreviewFilmController.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.refreshZoom_.bind(this)),$("#preview-list-scroller").scroll(this.updateScrollerOverflows.bind(this)),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.addFrame=function(){this.piskelController.addFrame(),this.piskelController.setCurrentFrameIndex(this.piskelController.getFrameCount()-1),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.createPreviews_=function(){this.container.html(""),$(".tooltip").remove();for(var a=this.piskelController.getFrameCount(),b=0,c=a;c>b;b++)this.container.append(this.createPreviewTile_(b));var d=document.createElement("div");d.id="add-frame-action",d.className="add-frame-action",d.innerHTML="

Add new frame

",this.container.append(d),$(d).click(this.addFrame.bind(this));var e=a>1;e&&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),$.publish(Events.LOCALSTORAGE_REQUEST)},a.PreviewFilmController.prototype.createPreviewTile_=function(a){var b=this.piskelController.getCurrentLayer().getFrameAt(a),c=document.createElement("li"),d="preview-tile";c.setAttribute("data-tile-number",a),this.piskelController.getCurrentFrame()==b&&(d+=" selected"),c.className=d;var e=document.createElement("div");e.className="canvas-container";var f=document.createElement("div");f.className="canvas-background",e.appendChild(f),c.addEventListener("click",this.onPreviewClick_.bind(this,a));var g=document.createElement("button");g.setAttribute("rel","tooltip"),g.setAttribute("data-placement","right"),g.setAttribute("title","Duplicate this frame"),g.className="tile-overlay duplicate-frame-action",c.appendChild(g),g.addEventListener("click",this.onAddButtonClick_.bind(this,a));var h={zoom:this.zoom,height:this.piskelController.getCurrentFrame().getHeight()*this.zoom,width:this.piskelController.getCurrentFrame().getWidth()*this.zoom},i=new pskl.rendering.frame.FrameRenderer($(e),h,["tile-view"]);if(i.render(b),c.appendChild(e),a>0||this.piskelController.getFrameCount()>1){var j=document.createElement("button");j.setAttribute("rel","tooltip"),j.setAttribute("data-placement","right"),j.setAttribute("title","Delete this frame"),j.className="tile-overlay delete-frame-action",j.addEventListener("click",this.onDeleteButtonClick_.bind(this,a)),c.appendChild(j); +this.frames.splice(b,0,c)},a.Layer.prototype.swapFramesAt=function(a,b){var c=this.frames[a],d=this.frames[b];if(!c||!d)throw console.log("frames",this.frames),console.log("fromIndex",a,"toIndex",b),"Frame not found in moveFrameAt";this.frames[b]=c,this.frames[a]=d},a.Layer.prototype.duplicateFrame=function(a){var b=this.frames.indexOf(a);this.duplicateFrameAt(b)},a.Layer.prototype.duplicateFrameAt=function(a){var b=this.frames[a];if(!b)throw"Frame not found in duplicateFrameAt";var c=b.clone();this.addFrameAt(c,a)},a.Layer.prototype.length=function(){return this.frames.length}}(),function(){var a=$.namespace("pskl.model.piskel");a.Descriptor=function(a,b,c){this.name=a,this.description=b,this.isPublic=c}}(),function(){var a=$.namespace("pskl.model");a.Piskel=function(a,b,c){if(!(a&&b&&c))throw"Missing arguments in Piskel constructor : "+Array.prototype.join.call(arguments,",");this.layers=[],this.width=a,this.height=b,this.descriptor=c},a.Piskel.fromLayers=function(a,b){var c=null;if(!(a.length>0&&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)}}(),function(){var a=$.namespace("pskl.selection");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)),$.subscribe(Events.TOOL_SELECTED,$.proxy(this.onToolSelected_,this))},a.SelectionManager.prototype.cleanSelection_=function(){this.currentSelection&&this.currentSelection.reset()},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.erase=function(){for(var a=this.currentSelection.pixels,b=this.piskelController.getCurrentFrame(),c=0,d=a.length;d>c;c++)try{b.setPixel(a[c].col,a[c].row,Constants.TRANSPARENT_COLOR)}catch(e){}},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)for(var a=this.currentSelection.pixels,b=this.piskelController.getCurrentFrame(),c=0,d=a.length;d>c;c++)try{b.setPixel(a[c].col,a[c].row,a[c].copiedColor)}catch(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){for(var b,c=0,d=this.pixels.length;d>c;c++)b=this.pixels[c],b.copiedColor=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.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.moveOffset=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.moveOffset=function(a,b){this.renderers.forEach(function(c){c.moveOffset(a,b)})},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.currentFrameIndex,e=this.piskelController.currentLayerIndex,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.getFrameForLayersAt_=function(a,b){var c=b.map(function(b){return b.getFrameAt(a)});return pskl.utils.FrameUtils.merge(c)}}(),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)),this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND)),$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,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.moveOffset=function(a,b){this.setOffset(this.offset.x+a,this.offset.y+b)},a.FrameRenderer.prototype.setOffset=function(a,b){if(this.canvas){var c=this.canvas.width-this.displayWidth/this.zoom;a=pskl.utils.Math.minmax(a,0,c);var d=this.canvas.height-this.displayHeight/this.zoom;b=pskl.utils.Math.minmax(b,0,d)}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(){var a=this.displayWidth-this.zoom*this.canvas.width;this.margin.x=Math.max(0,a)/2;var b=this.displayHeight-this.zoom*this.canvas.height;this.margin.y=Math.max(0,b)/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.CANVAS_BACKGROUND?this.updateBackgroundClass_(c):b==pskl.UserSettings.GRID_WIDTH&&this.setGridWidth(c)},a.FrameRenderer.prototype.updateBackgroundClass_=function(a){var b=this.container.data("current-background-class");b&&this.container.removeClass(b),this.container.addClass(a),this.container.data("current-background-class",a)},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_(),b=this.displayCanvas.getContext("2d"),b.save(),this.canvas.width*this.zoom0;if(j||h){var k=pskl.utils.ImageResizer.resizeNearestNeighbour(this.canvas,this.zoom,i);b.drawImage(k,0,0)}else b.scale(this.zoom,this.zoom),b.drawImage(this.canvas,0,0);b.restore()}}(),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.render=function(a){var b=this.getOffset(),c=this.getDisplaySize(),d=[this.getZoom(),this.getGridWidth(),b.x,b.y,c.width,c.height,a.serialize()].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");return this.frame.forEachPixel(function(a,c,d){this.renderPixel_(a,c,d,b)}.bind(this)),a},a.CanvasRenderer.prototype.renderPixel_=function(a,b,c,d){a==Constants.TRANSPARENT_COLOR&&(a=this.transparentColor_),d.fillStyle=a,d.fillRect(b*this.zoom,c*this.zoom,this.zoom,this.zoom)},a.CanvasRenderer.prototype.createCanvas_=function(){var a=this.frame.getWidth()*this.zoom,b=this.frame.getHeight()*this.zoom;return pskl.CanvasUtils.createCanvas(a,b)}}(),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),$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.duplicateCurrentFrame=function(){this.duplicateFrameAt(this.currentFrameIndex)},a.PiskelController.prototype.duplicateFrameAt=function(a){var b=this.getLayers();b.forEach(function(b){b.duplicateFrameAt(a)}),$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.moveFrame=function(a,b){var c=this.getLayers();c.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,$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.selectNextFrame=function(){var a=this.currentFrameIndex+1;a=0&&this.setCurrentFrameIndex(a)},a.PiskelController.prototype.setCurrentLayerIndex=function(a){this.currentLayerIndex=a,$.publish(Events.PISKEL_RESET)},a.PiskelController.prototype.selectLayer=function(a){var b=this.getLayers().indexOf(a);-1!=b&&this.setCurrentLayerIndex(b)},a.PiskelController.prototype.selectLayerByName=function(a){if(this.hasLayerForName_(a)){var b=this.piskel.getLayersByName(a)[0];this.selectLayer(b)}},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.removeCurrentLayer=function(){if(this.getLayers().length>1){var a=this.getCurrentLayer();this.piskel.removeLayer(a),this.setCurrentLayerIndex(0)}},a.PiskelController.prototype.serialize=function(){return pskl.utils.Serializer.serializePiskel(this.piskel)},a.PiskelController.prototype.load=function(a){this.deserialize(JSON.stringify(a))}}(),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.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),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)),window.setTimeout(this.afterWindowResize_.bind(this),100)},a.DrawingController.prototype.initMouseBehavior=function(){var a=$("body");this.container.mousedown($.proxy(this.onMousedown_,this)),this.container.mouseenter($.proxy(this.onMouseenter_,this)),this.container.mouseleave($.proxy(this.onMouseleave_,this)),pskl.utils.UserAgent.isChrome?this.container.on("mousewheel",$.proxy(this.onMousewheel_,this)):this.container.on("wheel",$.proxy(this.onMousewheel_,this)),a.mouseup($.proxy(this.onMouseup_,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 !")},a.DrawingController.prototype.onFrameSizeChanged_=function(){this.compositeRenderer.setDisplaySize(this.getContainerWidth_(),this.getContainerHeight_()),this.compositeRenderer.setZoom(this.calculateZoom_()),this.compositeRenderer.setOffset(0,0),$.publish(Events.ZOOM_CHANGED)},a.DrawingController.prototype.onMouseenter_=function(){this.container.bind("mousemove",$.proxy(this.onMousemove_,this))},a.DrawingController.prototype.onMouseleave_=function(){this.container.unbind("mousemove"),this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame)},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),$.publish(Events.LOCALSTORAGE_REQUEST))},a.DrawingController.prototype.onMousemove_=function(a){var b=(new Date).getTime();if(b-this.previousMousemoveTime>Constants.MOUSEMOVE_THROTTLING){var c=this.renderer.getCoordinates(a.clientX,a.clientY);this.isClicked?(this.currentToolBehavior.moveToolAt(c.x,c.y,this.getCurrentColor_(a),this.piskelController.getCurrentFrame(),this.overlayFrame,a),$.publish(Events.LOCALSTORAGE_REQUEST)):this.currentToolBehavior.moveUnactiveToolAt(c.x,c.y,this.getCurrentColor_(a),this.piskelController.getCurrentFrame(),this.overlayFrame,a),this.previousMousemoveTime=b}},a.DrawingController.prototype.onMousewheel_=function(a){var b=a.originalEvent,c=b.wheelDeltaY||-2*b.deltaY,d=this.renderer.getZoom(),e=this.calculateZoom_(),f=e/10;c>0?this.compositeRenderer.setZoom(d+f):0>c&&this.compositeRenderer.setZoom(d-f),$.publish(Events.ZOOM_CHANGED)},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)),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");a.PreviewFilmController=function(a,b){this.piskelController=a,this.container=b,this.refreshZoom_(),this.redrawFlag=!0},a.PreviewFilmController.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.flagForRedraw_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.refreshZoom_.bind(this)),$("#preview-list-scroller").scroll(this.updateScrollerOverflows.bind(this)),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.addFrame=function(){this.piskelController.addFrame(),this.piskelController.setCurrentFrameIndex(this.piskelController.getFrameCount()-1),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.createPreviews_=function(){this.container.html(""),$(".tooltip").remove();for(var a=this.piskelController.getFrameCount(),b=0,c=a;c>b;b++)this.container.append(this.createPreviewTile_(b));var d=document.createElement("div");d.id="add-frame-action",d.className="add-frame-action",d.innerHTML="

Add new frame

",this.container.append(d),$(d).click(this.addFrame.bind(this));var e=a>1;e&&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),$.publish(Events.LOCALSTORAGE_REQUEST)},a.PreviewFilmController.prototype.createPreviewTile_=function(a){var b=this.piskelController.getCurrentLayer().getFrameAt(a),c=document.createElement("li"),d="preview-tile";c.setAttribute("data-tile-number",a),this.piskelController.getCurrentFrame()==b&&(d+=" selected"),c.className=d;var e=document.createElement("div");e.className="canvas-container";var f=document.createElement("div");f.className="canvas-background",e.appendChild(f),c.addEventListener("click",this.onPreviewClick_.bind(this,a));var g=document.createElement("button");g.setAttribute("rel","tooltip"),g.setAttribute("data-placement","right"),g.setAttribute("title","Duplicate this frame"),g.className="tile-overlay duplicate-frame-action",c.appendChild(g),g.addEventListener("click",this.onAddButtonClick_.bind(this,a));var h={zoom:this.zoom,height:this.piskelController.getCurrentFrame().getHeight()*this.zoom,width:this.piskelController.getCurrentFrame().getWidth()*this.zoom},i=new pskl.rendering.frame.FrameRenderer($(e),h,["tile-view"]);if(i.render(b),c.appendChild(e),a>0||this.piskelController.getFrameCount()>1){var j=document.createElement("button");j.setAttribute("rel","tooltip"),j.setAttribute("data-placement","right"),j.setAttribute("title","Delete this frame"),j.className="tile-overlay delete-frame-action",j.addEventListener("click",this.onDeleteButtonClick_.bind(this,a)),c.appendChild(j); var k=document.createElement("div");k.className="tile-overlay dnd-action",c.appendChild(k)}var l=document.createElement("div");return l.className="tile-overlay tile-count",l.innerHTML=a+1,c.appendChild(l),c},a.PreviewFilmController.prototype.onPreviewClick_=function(a,b){b.target.classList.contains("tile-overlay")||this.piskelController.setCurrentFrameIndex(a)},a.PreviewFilmController.prototype.onDeleteButtonClick_=function(a){this.piskelController.removeFrameAt(a),$.publish(Events.LOCALSTORAGE_REQUEST),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.onAddButtonClick_=function(a){this.piskelController.duplicateFrameAt(a),$.publish(Events.LOCALSTORAGE_REQUEST),this.piskelController.setCurrentFrameIndex(a+1),this.updateScrollerOverflows()},a.PreviewFilmController.prototype.calculateZoom_=function(){var a=this.piskelController.getCurrentFrame(),b=a.getHeight(),c=a.getWidth(),d=Math.max(c,b),e=Constants.PREVIEW_FILM_SIZE*b/d,f=Constants.PREVIEW_FILM_SIZE*c/d;return pskl.PixelUtils.calculateZoom(e,f,b,c)||1}}(),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.querySelectorAll(".layers-list-container")[0],this.layersListEl=document.querySelectorAll(".layers-list")[0],this.rootEl.addEventListener("click",this.onClick_.bind(this)),$.subscribe(Events.PISKEL_RESET,this.renderLayerList_.bind(this)),this.renderLayerList_()},a.LayersListController.prototype.renderLayerList_=function(){this.layersListEl.innerHTML="";var a=this.piskelController.getLayers();a.forEach(this.addLayerItem.bind(this))},a.LayersListController.prototype.addLayerItem=function(a){var b=pskl.utils.Template.replace(this.layerItemTemplate_,{layername:a.getName()}),c=pskl.utils.Template.createFromHTML(b);this.piskelController.getCurrentLayer()===a&&c.classList.add("current-layer-item"),this.layersListEl.insertBefore(c,this.layersListEl.firstChild)},a.LayersListController.prototype.onClick_=function(a){var b=a.target||a.srcElement;if("BUTTON"==b.nodeName)this.onButtonClick_(b);else if("LI"==b.nodeName){var c=b.getAttribute("data-layer-name");this.piskelController.selectLayerByName(c)}},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()}}(),function(){var a=$.namespace("pskl.controller");a.AnimatedPreviewController=function(a,b){this.piskelController=a,this.container=b,this.elapsedTime=0,this.currentIndex=0,this.setFPS(Constants.DEFAULT.FPS);var c=this.calculateZoom_(),d=this.piskelController.getCurrentFrame(),e={zoom:c,height:d.getHeight()*c,width:d.getWidth()*c};this.renderer=new pskl.rendering.frame.FrameRenderer(this.container,e),$.subscribe(Events.FRAME_SIZE_CHANGED,this.onFrameSizeChange_.bind(this))},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"},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));b!=this.currentIndex&&(this.currentIndex=b,this.piskelController.hasFrameAt(this.currentIndex)||(this.currentIndex=0,this.elapsedTime=0),this.renderer.render(this.piskelController.getFrameAt(this.currentIndex)))},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(){var a=this.piskelController.getCurrentFrame(),b=this.calculateZoom_();this.renderer.setDisplaySize(a.getWidth()*b,a.getHeight()*b),this.renderer.setZoom(b),this.renderer.setOffset(0,0)}}(),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.renderer.getZoom()+"px",this.cropFrame.style.left=b.x*this.animationController.renderer.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.renderer.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("eraser","E",new pskl.drawingtools.Eraser),a("paintBucket","B",new pskl.drawingtools.PaintBucket),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("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="",b=this.getSelectedPalette();b&&(a=b.colors.map(function(a){return pskl.utils.Template.replace(this.paletteColorTemplate_,{color:a})}.bind(this)).join("")),this.colorListContainer_.innerHTML=a},a.PalettesListController.prototype.getSelectedPalette=function(){var a=this.colorPaletteSelect_.value,b=this.retrievePalettes(),c=this.getPaletteById(a,b);return c},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;"__manage-palettes"===a?($.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.onColorUpdated=function(a,b,c){var d=this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+c+'"]');d&&("primary"===a?(this.removeClass_("primary",".palettes-list-color"),d.classList.add("primary"),d.classList.remove("secondary")):"secondary"===a&&(this.removeClass_("secondary",".palettes-list-color"),d.classList.add("secondary"),d.classList.remove("primary")))},a.PalettesListController.prototype.removeClass_=function(a,b){var c=document.querySelector(b+"."+a);c&&c.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.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))},a.ResizeController.prototype.onResizeFormSubmit_=function(a){a.originalEvent.preventDefault();for(var b=parseInt(this.resizeWidth.val(),10),c=parseInt(this.resizeHeight.val(),10),d=[],e=this.piskelController.getLayers(),f=0;f"},a.GifExportController.prototype.getSelectedZoom_=function(){var a=this.uploadForm.get(0).querySelectorAll("[name=gif-zoom-level]"),b=Array.prototype.slice.call(a,0),c=b.filter(function(a){return!!a.checked});if(1==c.length)return c[0].value;throw"Unexpected error when retrieving selected zoom"},a.GifExportController.prototype.createRadioElements_=function(){for(var b=a.GifExportController.RESOLUTIONS,c=0;cb&&(a=a.substring(0,b),a+=c),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],this.uploadStatusContainerEl=document.querySelectorAll(".png-upload-status")[0],this.uploadForm=$("[name=png-export-upload-form]"),this.uploadForm.submit(this.onUploadFormSubmit_.bind(this)),this.updatePreview_(this.getFramesheetAsBase64Png())},a.PngExportController.prototype.onUploadFormSubmit_=function(a){a.originalEvent.preventDefault(),this.previewContainerEl.classList.add("preview-upload-ongoing"),pskl.app.imageUploadService.upload(this.getFramesheetAsBase64Png(),this.onImageUploadCompleted_.bind(this))},a.PngExportController.prototype.getFramesheetAsBase64Png=function(){var a=new pskl.rendering.PiskelRenderer(this.piskelController),b=a.renderAsCanvas();return b.toDataURL("image/png")},a.PngExportController.prototype.onImageUploadCompleted_=function(a){this.updatePreview_(a),this.updateStatus_(a),this.previewContainerEl.classList.remove("preview-upload-ongoing")},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.service_=pskl.app.localStorageService,this.piskelsList=$(".local-piskels-list"),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),$.publish(Events.CLOSE_SETTINGS_DRAWER))},a.LocalStorageController.prototype.fillLocalPiskelsList_=function(){var a="",b=this.service_.getKeys(),c=function(a){return 10>a?"0"+a:""+a};b.sort(function(a,b){return a.dateb.date?-1:0}),b.forEach(function(b){var d=new Date(b.date),e=pskl.utils.Template.replace("{{Y}}/{{M}}/{{D}} {{H}}:{{m}}",{Y:d.getFullYear(),M:c(d.getMonth()+1),D:c(d.getDate()),H:c(d.getHours()),m:c(d.getMinutes())});a+=pskl.utils.Template.replace(this.localStorageItemTemplate_,{name:b.name,date:e})}.bind(this));var d=this.piskelsList.get(0).tBodies[0];d.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.saveCloudButton=$("#save-cloud-button"),this.saveLocalButton=$("#save-local-button"),this.piskelName=$(".piskel-name").get(0),this.status=$("#save-status");var a=this.piskelController.piskel.getDescriptor();this.nameInput.val(a.name),this.descriptionInput.val(a.description),this.isPublicCheckbox.prop("checked",a.isPublic),pskl.app.isLoggedIn()?this.saveForm.submit(this.onSaveFormSubmit_.bind(this)):(this.saveCloudButton.attr("disabled","disabled"),this.status.html("You are not logged in. Only Local Save is available.")),this.saveLocalButton.click(this.onSaveLocalClick_.bind(this))},a.SaveController.prototype.onSaveFormSubmit_=function(a){a.preventDefault(),a.stopPropagation();var b=this.getName(),c=this.getDescription(),d=!!this.isPublicCheckbox.prop("checked"),e=new pskl.model.piskel.Descriptor(b,c,d);this.piskelController.piskel.setDescriptor(e),this.beforeSaving_(),pskl.app.store({success:this.onSaveSuccess_.bind(this),error:this.onSaveError_.bind(this),after:this.afterSaving_.bind(this)})},a.SaveController.prototype.onSaveLocalClick_=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),1e3))},a.SaveController.prototype.getName=function(){return this.nameInput.val()},a.SaveController.prototype.getDescription=function(){return this.descriptionInput.val()},a.SaveController.prototype.beforeSaving_=function(){this.saveCloudButton.attr("disabled",!0),this.status.html("Saving ..."),this.piskelName&&this.piskelName.classList.add("piskel-name-saving")},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.saveCloudButton.attr("disabled",!1),this.status.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"),b="No file selected ...",c=60;a.ImportController=function(a){this.piskelController=a,this.importedImage_=null},a.ImportController.prototype.init=function(){this.importForm=$("[name=import-form]"),this.hiddenFileInput=$("[name=file-upload-input]"),this.fileInputButton=$(".file-input-button"),this.fileInputStatus=$(".file-input-status"),this.fileInputStatus.html(b),this.importPreview=$(".import-section-preview"),this.resizeWidth=$("[name=resize-width]"),this.resizeHeight=$("[name=resize-height]"),this.smoothResize=$("[name=smooth-resize-checkbox]"),this.submitButton=$("[name=import-submit]"),this.importForm.submit(this.onImportFormSubmit_.bind(this)),this.hiddenFileInput.change(this.onFileUploadChange_.bind(this)),this.fileInputButton.click(this.onFileInputClick_.bind(this)),this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this,"width")),this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this,"height"))},a.ImportController.prototype.reset_=function(){this.importForm.get(0).reset(),this.fileInputStatus.html(b),$.publish(Events.CLOSE_SETTINGS_DRAWER)},a.ImportController.prototype.onResizeInputKeyUp_=function(a,b){this.importedImage_&&this.synchronizeResizeFields_(b.target.value,a)},a.ImportController.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.ImportController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault(),this.importImageToPiskel_()},a.ImportController.prototype.onFileUploadChange_=function(){this.importFromFile_()},a.ImportController.prototype.onFileInputClick_=function(){this.hiddenFileInput.click()},a.ImportController.prototype.importFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length){var b=a[0];if(!this.isImage_(b))throw this.reset_(),"File is not an image : "+b.type;this.readImageFile_(b),this.enableDisabledSections_()}},a.ImportController.prototype.enableDisabledSections_=function(){this.resizeWidth.removeAttr("disabled"),this.resizeHeight.removeAttr("disabled"),this.smoothResize.removeAttr("disabled"),this.submitButton.removeAttr("disabled"),this.fileInputButton.removeClass("button-primary"),this.fileInputButton.blur(),$(".import-section-disabled").removeClass("import-section-disabled")},a.ImportController.prototype.readImageFile_=function(a){pskl.utils.FileUtils.readFile(a,this.processImageSource_.bind(this))},a.ImportController.prototype.processImageSource_=function(a){this.importedImage_=new Image,this.importedImage_.onload=this.onImageLoaded_.bind(this),this.importedImage_.src=a},a.ImportController.prototype.onImageLoaded_=function(){var a=this.importedImage_.width,b=this.importedImage_.height,c=this.hiddenFileInput.val(),d=this.extractFileNameFromPath_(c);this.fileInputStatus.html(d),this.resizeWidth.val(a),this.resizeHeight.val(b),this.importPreview.width("auto"),this.importPreview.html(""),this.importPreview.append(this.createImagePreview_())},a.ImportController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");return a.src=this.importedImage_.src,a.setAttribute("height",c),a},a.ImportController.prototype.extractFileNameFromPath_=function(a){var b=[];return b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a],b[b.length-1]},a.ImportController.prototype.importImageToPiskel_=function(){if(this.importedImage_&&window.confirm("You are about to create a new Piskel, unsaved changes will be lost.")){var a=this.resizeWidth.val(),b=this.resizeHeight.val(),c=!!this.smoothResize.prop("checked"),d=pskl.utils.ImageResizer.resize(this.importedImage_,a,b,c),e=pskl.utils.FrameUtils.createFromImage(d),f=pskl.model.Layer.fromFrames("Layer 1",[e]),g=new pskl.model.piskel.Descriptor("Imported piskel",""),h=pskl.model.Piskel.fromLayers([f],g); -pskl.app.piskelController.setPiskel(h),pskl.app.animationController.setFPS(Constants.DEFAULT.FPS),this.reset_()}},a.ImportController.prototype.isImage_=function(a){return 0===a.type.indexOf("image")}}(),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},gif:{template:"templates/settings/export-gif.html",controller:a.GifExportController},png:{template:"templates/settings/export-png.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}}(),function(){var a=$.namespace("pskl.controller.dialogs"),b=window.tinycolor,c="selected",d="palette-manager-new-color",e="palette-manager-delete-card",f="palette-manager-details-head-edit-icon";a.PaletteManagerController=function(a){this.piskelController=a,this.palettes=this.retrieveUserPalettes(),this.originalPalettes=this.retrieveUserPalettes(),this.selectedPaletteId=null},a.PaletteManagerController.prototype.init=function(){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.closeButton=document.querySelector(".palette-manager-close"),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.createPalette.bind(this)),this.saveAllButton.addEventListener("click",this.saveAll.bind(this)),this.closeButton.addEventListener("click",this.closeDialog.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.closeDialog=function(){$.publish(Events.DIALOG_HIDE)},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.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.destroySpectrumPickers(),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.savePaletteAndRedraw(this.getSelectedPalette().id):"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)}})},a.PaletteManagerController.prototype.destroySpectrumPickers=function(){var a=$(this.getSpectrumSelector_());a&&a.spectrum("destroy")},a.PaletteManagerController.prototype.updateColorInSelectedPalette=function(a,b){var c=this.getSelectedPalette();c.colors.splice(a,1,"#"+b.toHex().toUpperCase()),this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.addColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.push(a),this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},a.PaletteManagerController.prototype.removeColorInSelectedPalette=function(a){var b=this.getSelectedPalette();b.colors.splice(a,1),this.createPaletteListMarkup(),this.selectPalette(this.selectedPaletteId)},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.createPaletteListMarkup(),this.selectPalette(a.id))},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.createPaletteListMarkup(),this.selectPalette(a.id)},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.createPaletteListMarkup(),this.selectPalette(this.getSelectedPalette().id)},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()},a.PaletteManagerController.prototype.savePaletteAndRedraw=function(a){this.savePalette(a),this.createPaletteListMarkup(),this.selectPalette(this.getSelectedPalette().id)},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={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController}};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"))},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){if(!this.isDisplayed()){var d=b[c];if(d){this.dialogContainer_.innerHTML=pskl.utils.Template.get(d.template);var e=new d.controller(this.piskelController);e.init(),this.showDialogWrapper_(),this.currentDialog_={id:c,controller:e}}else console.error("Could not find dialog configuration for dialogId : "+c)}},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_;a&&a.controller.destroy(),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(){var a=new XMLHttpRequest,b=new FormData;b.append("framesheet_content",this.piskelController.serialize()),b.append("fps_speed",this.piskelController.getFPS()),a.open("POST",Constants.STATIC.URL.SAVE,!0),a.onload=function(a){if(200==this.status){var b=window.location.href.replace(window.location.search,"");window.location.href=b+"?frameId="+this.responseText}else this.onerror(a)},a.onerror=function(){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+this.status+")"}])},a.send(b)}}(),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.piskel,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");a.HistoryService=function(a){this.piskelController=a,this.saveState__b=this.saveState.bind(this)},a.HistoryService.prototype.init=function(){$.subscribe(Events.PISKEL_RESET,this.saveState__b),$.subscribe(Events.TOOL_RELEASED,this.saveState__b),pskl.app.shortcutService.addShortcut("ctrl+Z",this.undo.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+Y",this.redo.bind(this))},a.HistoryService.prototype.saveState=function(){this.piskelController.getCurrentFrame().saveState()},a.HistoryService.prototype.undo=function(){this.piskelController.getCurrentFrame().loadPreviousState(),$.unsubscribe(Events.PISKEL_RESET,this.saveState__b),$.publish(Events.PISKEL_RESET),$.subscribe(Events.PISKEL_RESET,this.saveState__b)},a.HistoryService.prototype.redo=function(){this.piskelController.getCurrentFrame().loadNextState(),$.unsubscribe(Events.PISKEL_RESET,this.saveState__b),$.publish(Events.PISKEL_RESET),$.subscribe(Events.PISKEL_RESET,this.saveState__b)}}(),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)),window.addEventListener("beforeunload",this.onBeforeUnload.bind(this))},a.SavedStatusService.prototype.onPiskelReset=function(){var a=this.piskelController_.piskel;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_.piskel;b.isDirty_!==a&&(b.isDirty_=a,this.updatePiskelName())},a.SavedStatusService.prototype.updatePiskelName=function(){var a=this.piskelController_.piskel,b=a.getDescriptor().name;a.isDirty_?$(".piskel-name").html(b+" *"):$(".piskel-name").html(b)},a.SavedStatusService.prototype.onBeforeUnload=function(a){var b=this.piskelController_.piskel;if(b.isDirty_){var c="Your Piskel seems to have unsaved changes";return(a||window.event).returnValue=c,c}}}(),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="normal";return 0===a.indexOf("ctrl+")?(b="ctrl",a=a.replace("ctrl+","")):0===a.indexOf("shift+")?(b="shift",a=a.replace("shift+","")):0===a.indexOf("alt+")&&(b="alt",a=a.replace("alt+","")),{meta:b,key:a}},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;e=this.isCtrlKeyPressed_(a)?d.ctrl:this.isShiftKeyPressed_(a)?d.shift:this.isAltKeyPressed_(a)?d.alt:d.normal,e&&(e(c),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 this.isMac_()?a.metaKey:a.ctrlKey},a.ShortcutService.prototype.isShiftKeyPressed_=function(a){return a.shiftKey},a.ShortcutService.prototype.isAltKeyPressed_=function(a){return a.altKey},a.ShortcutService.prototype.isMac_=function(){return-1!=navigator.appVersion.indexOf("Mac")}}(),function(){var a={191:"?",27:"esc",38:"up",40:"down",46:"del"},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{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.SimplePen=function(){this.toolId="tool-pen",this.helpText="Pen tool",this.previousCol=null,this.previousRow=null},pskl.utils.inherit(a.SimplePen,a.BaseTool),a.SimplePen.prototype.applyToolAt=function(a,b,c,d){d.containsPixel(a,b)&&d.setPixel(a,b,c),this.previousCol=a,this.previousRow=b},a.SimplePen.prototype.moveToolAt=function(a,b,c,d,e){if(Math.abs(a-this.previousCol)>1||Math.abs(b-this.previousRow)>1)for(var f=this.getLinePixels_(a,this.previousCol,b,this.previousRow),g=0,h=f.length;h>g;g++){var i=f[g];this.applyToolAt(i.col,i.row,c,d,e)}else this.applyToolAt(a,b,c,d,e);this.previousCol=a,this.previousRow=b}}(),function(){var a=$.namespace("pskl.drawingtools");a.VerticalMirrorPen=function(){this.toolId="tool-vertical-mirror-pen",this.helpText="vertical mirror pen tool",this.swap=null,this.mirroredPreviousCol=null,this.mirroredPreviousRow=null},pskl.utils.inherit(a.VerticalMirrorPen,a.SimplePen),a.VerticalMirrorPen.prototype.setMirrorContext=function(){this.swap=this.previousCol,this.previousCol=this.mirroredPreviousCol},a.VerticalMirrorPen.prototype.unsetMirrorContext=function(){this.mirroredPreviousCol=this.previousCol,this.previousCol=this.swap},a.VerticalMirrorPen.prototype.applyToolAt=function(a,b,c,d,e){this.superclass.applyToolAt.call(this,a,b,c,d,e);var f=this.getSymmetricCol_(a,d);this.mirroredPreviousCol=f,this.setMirrorContext(),this.superclass.applyToolAt.call(this,f,b,c,d,e),this.unsetMirrorContext()},a.VerticalMirrorPen.prototype.getSymmetricCol_=function(a,b){return b.getWidth()-a-1}}(),function(){var a=$.namespace("pskl.drawingtools");a.Eraser=function(){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)}}(),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;gd;d++)b.setPixel(c[d].col,c[d].row,Constants.SELECTION_TRANSPARENT_COLOR)},a.BaseSelect.prototype.shiftOverlayFrame_=function(a,b,c,d){for(var e,f=0;f0?this.selectPalette(this.palettes[0].id):this.createPalette("New palette")},a.PaletteManagerController.prototype.destroy=function(){this.destroySpectrumPickers()},a.PaletteManagerController.prototype.closeDialog=function(){$.publish(Events.DIALOG_HIDE)},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={"manage-palettes":{template:"templates/dialogs/manage-palettes.html",controller:a.PaletteManagerController}};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"))},a.DialogsController.prototype.onDialogDisplayEvent_=function(a,c){if(!this.isDisplayed()){var d=b[c];if(d){this.dialogContainer_.innerHTML=pskl.utils.Template.get(d.template);var e=new d.controller(this.piskelController);e.init(),this.showDialogWrapper_(),this.currentDialog_={id:c,controller:e}}else console.error("Could not find dialog configuration for dialogId : "+c)}},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_;a&&a.controller.destroy(),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(){var a=new XMLHttpRequest,b=new FormData;b.append("framesheet_content",this.piskelController.serialize()),b.append("fps_speed",this.piskelController.getFPS()),a.open("POST",Constants.STATIC.URL.SAVE,!0),a.onload=function(a){if(200==this.status){var b=window.location.href.replace(window.location.search,"");window.location.href=b+"?frameId="+this.responseText}else this.onerror(a)},a.onerror=function(){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+this.status+")"}])},a.send(b)}}(),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.piskel,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");a.HistoryService=function(a){this.piskelController=a,this.saveState__b=this.saveState.bind(this)},a.HistoryService.prototype.init=function(){$.subscribe(Events.PISKEL_RESET,this.saveState__b),$.subscribe(Events.TOOL_RELEASED,this.saveState__b),pskl.app.shortcutService.addShortcut("ctrl+Z",this.undo.bind(this)),pskl.app.shortcutService.addShortcut("ctrl+Y",this.redo.bind(this))},a.HistoryService.prototype.saveState=function(){this.piskelController.getCurrentFrame().saveState()},a.HistoryService.prototype.undo=function(){this.piskelController.getCurrentFrame().loadPreviousState(),$.unsubscribe(Events.PISKEL_RESET,this.saveState__b),$.publish(Events.PISKEL_RESET),$.subscribe(Events.PISKEL_RESET,this.saveState__b)},a.HistoryService.prototype.redo=function(){this.piskelController.getCurrentFrame().loadNextState(),$.unsubscribe(Events.PISKEL_RESET,this.saveState__b),$.publish(Events.PISKEL_RESET),$.subscribe(Events.PISKEL_RESET,this.saveState__b)}}(),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)),window.addEventListener("beforeunload",this.onBeforeUnload.bind(this))},a.SavedStatusService.prototype.onPiskelReset=function(){var a=this.piskelController_.piskel;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_.piskel;b.isDirty_!==a&&(b.isDirty_=a,this.updatePiskelName())},a.SavedStatusService.prototype.updatePiskelName=function(){var a=this.piskelController_.piskel,b=a.getDescriptor().name;a.isDirty_?$(".piskel-name").html(b+" *"):$(".piskel-name").html(b)},a.SavedStatusService.prototype.onBeforeUnload=function(a){var b=this.piskelController_.piskel;if(b.isDirty_){var c="Your Piskel seems to have unsaved changes";return(a||window.event).returnValue=c,c}}}(),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="normal";return 0===a.indexOf("ctrl+")?(b="ctrl",a=a.replace("ctrl+","")):0===a.indexOf("shift+")?(b="shift",a=a.replace("shift+","")):0===a.indexOf("alt+")&&(b="alt",a=a.replace("alt+","")),{meta:b,key:a}},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;e=this.isCtrlKeyPressed_(a)?d.ctrl:this.isShiftKeyPressed_(a)?d.shift:this.isAltKeyPressed_(a)?d.alt:d.normal,e&&(e(c),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 this.isMac_()?a.metaKey:a.ctrlKey},a.ShortcutService.prototype.isShiftKeyPressed_=function(a){return a.shiftKey},a.ShortcutService.prototype.isAltKeyPressed_=function(a){return a.altKey},a.ShortcutService.prototype.isMac_=function(){return-1!=navigator.appVersion.indexOf("Mac")}}(),function(){var a={191:"?",27:"esc",38:"up",40:"down",46:"del"},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{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.SimplePen=function(){this.toolId="tool-pen",this.helpText="Pen tool",this.previousCol=null,this.previousRow=null},pskl.utils.inherit(a.SimplePen,a.BaseTool),a.SimplePen.prototype.applyToolAt=function(a,b,c,d){d.containsPixel(a,b)&&d.setPixel(a,b,c),this.previousCol=a,this.previousRow=b},a.SimplePen.prototype.moveToolAt=function(a,b,c,d,e){if(Math.abs(a-this.previousCol)>1||Math.abs(b-this.previousRow)>1)for(var f=this.getLinePixels_(a,this.previousCol,b,this.previousRow),g=0,h=f.length;h>g;g++){var i=f[g];this.applyToolAt(i.col,i.row,c,d,e)}else this.applyToolAt(a,b,c,d,e);this.previousCol=a,this.previousRow=b}}(),function(){var a=$.namespace("pskl.drawingtools");a.VerticalMirrorPen=function(){this.toolId="tool-vertical-mirror-pen",this.helpText="vertical mirror pen tool",this.swap=null,this.mirroredPreviousCol=null,this.mirroredPreviousRow=null},pskl.utils.inherit(a.VerticalMirrorPen,a.SimplePen),a.VerticalMirrorPen.prototype.setMirrorContext=function(){this.swap=this.previousCol,this.previousCol=this.mirroredPreviousCol},a.VerticalMirrorPen.prototype.unsetMirrorContext=function(){this.mirroredPreviousCol=this.previousCol,this.previousCol=this.swap},a.VerticalMirrorPen.prototype.applyToolAt=function(a,b,c,d,e){this.superclass.applyToolAt.call(this,a,b,c,d,e);var f=this.getSymmetricCol_(a,d);this.mirroredPreviousCol=f,this.setMirrorContext(),this.superclass.applyToolAt.call(this,f,b,c,d,e),this.unsetMirrorContext()},a.VerticalMirrorPen.prototype.getSymmetricCol_=function(a,b){return b.getWidth()-a-1}}(),function(){var a=$.namespace("pskl.drawingtools");a.Eraser=function(){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)}}(),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;gd;d++)b.setPixel(c[d].col,c[d].row,Constants.SELECTION_TRANSPARENT_COLOR)},a.BaseSelect.prototype.shiftOverlayFrame_=function(a,b,c,d){for(var e,f=0;f - Loading pixels ... + Loading Piskel ... -
    - -
    diff --git a/templates/dialogs/manage-palettes.html b/templates/dialogs/manage-palettes.html index 208b1abf..946a4f61 100644 --- a/templates/dialogs/manage-palettes.html +++ b/templates/dialogs/manage-palettes.html @@ -21,7 +21,7 @@