piskel/closure_compiled_binary.js
2013-10-23 23:43:37 +02:00

190 lines
111 KiB
JavaScript

var Constants={DEFAULT:{HEIGHT:32,WIDTH:32,FPS:12},MODEL_VERSION:1,MAX_HEIGHT:128,MAX_WIDTH:128,PREVIEW_FILM_SIZE:120,DEFAULT_PEN_COLOR:"#000000",TRANSPARENT_COLOR:"TRANSPARENT",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://screenletstore.appspot.com/__/upload",IMAGE_SERVICE_GET_URL:"http://screenletstore.appspot.com/img/",
GRID_STROKE_WIDTH:1,LEFT_BUTTON:"left_button_1",RIGHT_BUTTON:"right_button_2"};var Events={TOOL_SELECTED:"TOOL_SELECTED",TOOL_RELEASED:"TOOL_RELEASED",PRIMARY_COLOR_SELECTED:"PRIMARY_COLOR_SELECTED",PRIMARY_COLOR_UPDATED:"PRIMARY_COLOR_UPDATED",SECONDARY_COLOR_SELECTED:"SECONDARY_COLOR_SELECTED",SECONDARY_COLOR_UPDATED:"SECONDARY_COLOR_UPDATED",LOCALSTORAGE_REQUEST:"LOCALSTORAGE_REQUEST",CANVAS_RIGHT_CLICKED:"CANVAS_RIGHT_CLICKED",REFRESH:"REFRESH",REDRAW_PREVIEWFILM:"REDRAW_PREVIEWFILM",USER_SETTINGS_CHANGED:"USER_SETTINGS_CHANGED",CLOSE_SETTINGS_DRAWER:"CLOSE_SETTINGS_DRAWER",
PISKEL_RESET:"PISKEL_RESET",FRAME_SIZE_CHANGED:"FRAME_SIZE_CHANGED",CURRENT_FRAME_SET:"CURRENT_FRAME_SET",SELECTION_CREATED:"SELECTION_CREATED",SELECTION_MOVE_REQUEST:"SELECTION_MOVE_REQUEST",SELECTION_DISMISSED:"SELECTION_DISMISSED",SHOW_NOTIFICATION:"SHOW_NOTIFICATION",HIDE_NOTIFICATION:"HIDE_NOTIFICATION",UNDO:"UNDO",REDO:"REDO",CUT:"CUT",COPY:"COPY",PASTE:"PASTE"};(function(){$.namespace("pskl").app={init:function(){var a=this.readSizeFromURL_(),d=new pskl.model.Piskel(a.width,a.height),b=new pskl.model.Layer("Layer 1"),a=new pskl.model.Frame(a.width,a.height);b.addFrame(a);d.addLayer(b);this.piskelController=new pskl.controller.PiskelController(d);this.drawingController=new pskl.controller.DrawingController(this.piskelController,$("#drawing-canvas-container"));this.drawingController.init();this.animationController=new pskl.controller.AnimatedPreviewController(this.piskelController,
$("#preview-canvas-container"));this.animationController.init();this.previewsController=new pskl.controller.PreviewFilmController(this.piskelController,$("#preview-list"));this.previewsController.init();this.layersListController=new pskl.controller.LayersListController(this.piskelController);this.layersListController.init();this.settingsController=new pskl.controller.settings.SettingsController(this.piskelController);this.settingsController.init();this.selectionManager=new pskl.selection.SelectionManager(this.piskelController);
this.selectionManager.init();this.historyService=new pskl.service.HistoryService(this.piskelController);this.historyService.init();this.keyboardEventService=new pskl.service.KeyboardEventService;this.keyboardEventService.init();this.notificationController=new pskl.controller.NotificationController;this.notificationController.init();this.localStorageService=new pskl.service.LocalStorageService(this.piskelController);this.localStorageService.init();this.imageUploadService=new pskl.service.ImageUploadService;
this.imageUploadService.init();this.toolController=new pskl.controller.ToolController;this.toolController.init();this.paletteController=new pskl.controller.PaletteController;this.paletteController.init();d=new pskl.rendering.DrawingLoop;d.addCallback(this.render,this);d.start();this.initBootstrapTooltips_();(this.isStaticVersion=!pskl.appEngineToken_)?this.finishInitStatic_():this.finishInitAppEngine_()},finishInitStatic_:function(){var a=this.readFramesheetIdFromURL_();a?($.publish(Events.SHOW_NOTIFICATION,
[{content:"Loading animation with id : ["+a+"]"}]),this.loadFramesheetFromService(a)):this.localStorageService.displayRestoreNotification()},finishInitAppEngine_:function(){if(pskl.framesheetData_&&pskl.framesheetData_.content){var a=pskl.utils.Serializer.createPiskel(pskl.framesheetData_.content);pskl.app.piskelController.setPiskel(a);pskl.app.animationController.setFPS(pskl.framesheetData_.fps)}},initBootstrapTooltips_:function(){$("body").tooltip({selector:"[rel=tooltip]"})},render:function(a){this.drawingController.render(a);
this.animationController.render(a);this.previewsController.render(a)},readSizeFromURL_:function(){var a,d=this.readUrlParameter_("size").split("x");!d||2!=d.length||isNaN(d[0])||isNaN(d[1])?a={height:Constants.DEFAULT.HEIGHT,width:Constants.DEFAULT.WIDTH}:(a=parseInt(d[0],10),d=parseInt(d[1],10),a={height:Math.min(d,Constants.MAX_HEIGHT),width:Math.min(a,Constants.MAX_WIDTH)});return a},readFramesheetIdFromURL_:function(){return this.readUrlParameter_("frameId")},readUrlParameter_:function(a){var d,
b,c=window.location.search.substring(1).split("&");for(d=0;d<c.length;d++)if(b=c[d].split("="),b[0]==a)return window.unescape(b[1]);return""},loadFramesheetFromService:function(a){var d=new XMLHttpRequest;d.open("GET",Constants.STATIC.URL.GET+"?l="+a,!0);d.responseType="text";d.onload=function(d){d=JSON.parse(this.responseText);var a=pskl.utils.Serializer.createPiskel(d.framesheet);pskl.app.piskelController.setPiskel(a);pskl.app.animationController.setFPS(d.fps);$.publish(Events.HIDE_NOTIFICATION)};
d.onerror=function(){$.publish(Events.HIDE_NOTIFICATION)};d.send()},storeSheet:function(a){this.isStaticVersion?this.storeSheetStatic_():this.storeSheetAppEngine_();a&&(a.stopPropagation(),a.preventDefault());return!1},storeSheetStatic_:function(){var a=new XMLHttpRequest,d=new FormData;d.append("framesheet_content",this.piskelController.serialize());d.append("fps_speed",$("#preview-fps").val());a.open("POST",Constants.STATIC.URL.SAVE,!0);a.onload=function(d){if(200==this.status)d=window.location.href.replace(window.location.search,
""),window.location.href=d+"?frameId="+this.responseText;else this.onerror(d)};a.onerror=function(d){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+this.status+")"}])};a.send(d)},storeSheetAppEngine_:function(){var a=new XMLHttpRequest,d=new FormData;d.append("framesheet_content",this.piskelController.serialize());d.append("fps_speed",$("#preview-fps").val());d.append("name",$("#piskel-name").val());d.append("frames",this.piskelController.getFrameCount());d.append("preview",this.getFirstFrameAsPng());
d.append("framesheet",this.getFramesheetAsPng());a.open("POST",Constants.APPENGINE.URL.SAVE,!0);a.onload=function(d){if(200==this.status)$.publish(Events.SHOW_NOTIFICATION,[{content:"Successfully saved !"}]);else this.onerror(d)};a.onerror=function(d){$.publish(Events.SHOW_NOTIFICATION,[{content:"Saving failed ("+this.status+")"}])};a.send(d)},getFirstFrameAsPng:function(){var a=this.piskelController.getFrameAt(0),a=new pskl.rendering.CanvasRenderer(a,1);a.drawTransparentAs("rgba(0,0,0,0)");return a.render().canvas.toDataURL("image/png")},
getFramesheetAsPng:function(){return(new pskl.rendering.SpritesheetRenderer(this.piskelController)).render().toDataURL("image/png")},uploadAsSpritesheetPNG:function(){var a=this.getFramesheetAsPng();this.imageUploadService.upload(a,this.openWindow.bind(this))},openWindow:function(a){var d=["dialog=yes,scrollbars=no,status=no","width="+this.piskelController.getWidth()*this.piskelController.getFrameCount(),"height="+this.piskelController.getHeight()].join();window.open(a,"piskel-export",d)}}})();(function(){var a=$.namespace("pskl.controller");a.AnimatedPreviewController=function(d,a,c){this.piskelController=d;this.container=a;this.currentIndex=this.elapsedTime=0;this.setFPS(Constants.DEFAULT.FPS);d={dpi:this.calculateDPI_()};this.renderer=new pskl.rendering.FrameRenderer(this.container,d);$.subscribe(Events.FRAME_SIZE_CHANGED,this.updateDPI_.bind(this))};a.AnimatedPreviewController.prototype.init=function(){$("#preview-fps")[0].addEventListener("change",this.onFPSSliderChange.bind(this))};
a.AnimatedPreviewController.prototype.onFPSSliderChange=function(d){this.setFPS(parseInt($("#preview-fps")[0].value,10))};a.AnimatedPreviewController.prototype.setFPS=function(d){this.fps=d;$("#preview-fps").val(this.fps);$("#display-fps").html(this.fps+" FPS")};a.AnimatedPreviewController.prototype.getFPS=function(){return this.fps};a.AnimatedPreviewController.prototype.render=function(d){this.elapsedTime+=d;d=Math.floor(this.elapsedTime/(1E3/this.fps));d!=this.currentIndex&&(this.currentIndex=d,
this.piskelController.hasFrameAt(this.currentIndex)||(this.elapsedTime=this.currentIndex=0),this.renderer.render(this.piskelController.getFrameAt(this.currentIndex)))};a.AnimatedPreviewController.prototype.calculateDPI_=function(){var d=this.piskelController.getCurrentFrame().getHeight(),a=this.piskelController.getCurrentFrame().getWidth();return pskl.PixelUtils.calculateDPI(200,200,d,a)};a.AnimatedPreviewController.prototype.updateDPI_=function(){this.dpi=this.calculateDPI_();this.renderer.setDPI(this.dpi)}})();(function(){var a=$.namespace("pskl.controller");a.DrawingController=function(d,a){this.piskelController=d;this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(d.getCurrentFrame());this.container=a;this.dpi=this.calculateDPI_();var c={dpi:this.dpi,supportGridRendering:!0};this.overlayRenderer=new pskl.rendering.FrameRenderer(this.container,c,["canvas-overlay"]);this.renderer=new pskl.rendering.FrameRenderer(this.container,c,["drawing-canvas"]);this.layersBelowRenderer=new pskl.rendering.FrameRenderer(this.container,
c,["layers-canvas","layers-below-canvas"]);this.layersAboveRenderer=new pskl.rendering.FrameRenderer(this.container,c,["layers-canvas","layers-above-canvas"]);this.isRightClicked=this.isClicked=!1;this.previousMousemoveTime=0;this.currentToolBehavior=null;this.primaryColor=Constants.DEFAULT_PEN_COLOR;this.secondaryColor=Constants.TRANSPARENT_COLOR};a.DrawingController.prototype.init=function(){this.initMouseBehavior();$.subscribe(Events.TOOL_SELECTED,$.proxy(function(d,a){console.log("Tool selected: ",
a);this.currentToolBehavior=a;this.overlayFrame.clear()},this));$.subscribe(Events.PRIMARY_COLOR_SELECTED,$.proxy(function(d,a){console.log("Primary color selected: ",a);this.primaryColor=a;$.publish(Events.PRIMARY_COLOR_UPDATED,[a])},this));$.subscribe(Events.SECONDARY_COLOR_SELECTED,$.proxy(function(d,a){console.log("Secondary color selected: ",a);this.secondaryColor=a;$.publish(Events.SECONDARY_COLOR_UPDATED,[a])},this));$(window).resize($.proxy(this.startDPIUpdateTimer_,this));$.subscribe(Events.USER_SETTINGS_CHANGED,
$.proxy(this.onUserSettingsChange_,this));$.subscribe(Events.FRAME_SIZE_CHANGED,$.proxy(this.updateDPI_,this));this.updateDPI_()};a.DrawingController.prototype.initMouseBehavior=function(){var d=$("body");this.container.mousedown($.proxy(this.onMousedown_,this));this.container.mousemove($.proxy(this.onMousemove_,this));d.mouseup($.proxy(this.onMouseup_,this));d.contextmenu(this.onCanvasContextMenu_)};a.DrawingController.prototype.startDPIUpdateTimer_=function(){this.dpiUpdateTimer&&window.clearInterval(this.dpiUpdateTimer);
this.dpiUpdateTimer=window.setTimeout($.proxy(this.updateDPI_,this),200)};a.DrawingController.prototype.onUserSettingsChange_=function(d,a,c){a==pskl.UserSettings.SHOW_GRID&&this.updateDPI_()};a.DrawingController.prototype.onMousedown_=function(d){this.isClicked=!0;2==d.button&&(this.isRightClicked=!0,$.publish(Events.CANVAS_RIGHT_CLICKED));var a=this.getSpriteCoordinates(d);this.currentToolBehavior.applyToolAt(a.col,a.row,this.getCurrentColor_(),this.piskelController.getCurrentFrame(),this.overlayFrame,
this.wrapEvtInfo_(d));$.publish(Events.LOCALSTORAGE_REQUEST)};a.DrawingController.prototype.onMousemove_=function(d){var a=(new Date).getTime();if(40<a-this.previousMousemoveTime){var c=this.getSpriteCoordinates(d);this.isClicked?(this.currentToolBehavior.moveToolAt(c.col,c.row,this.getCurrentColor_(),this.piskelController.getCurrentFrame(),this.overlayFrame,this.wrapEvtInfo_(d)),$.publish(Events.LOCALSTORAGE_REQUEST)):this.currentToolBehavior.moveUnactiveToolAt(c.col,c.row,this.getCurrentColor_(),
this.piskelController.getCurrentFrame(),this.overlayFrame,this.wrapEvtInfo_(d));this.previousMousemoveTime=a}};a.DrawingController.prototype.onMouseup_=function(d){if(this.isClicked||this.isRightClicked){this.isRightClicked=this.isClicked=!1;var a=this.getSpriteCoordinates(d);this.currentToolBehavior.releaseToolAt(a.col,a.row,this.getCurrentColor_(),this.piskelController.getCurrentFrame(),this.overlayFrame,this.wrapEvtInfo_(d));$.publish(Events.TOOL_RELEASED)}};a.DrawingController.prototype.wrapEvtInfo_=
function(d){var a={};0===d.button?a.button=Constants.LEFT_BUTTON:2==d.button&&(a.button=Constants.RIGHT_BUTTON);return a};a.DrawingController.prototype.getRelativeCoordinates=function(d,a){var c=this.container.offset();return{x:d-c.left,y:a-c.top}};a.DrawingController.prototype.getSpriteCoordinates=function(d){d=this.getRelativeCoordinates(d.clientX,d.clientY);return this.renderer.convertPixelCoordinatesIntoSpriteCoordinate(d)};a.DrawingController.prototype.getCurrentColor_=function(){return this.isRightClicked?
this.secondaryColor:this.primaryColor};a.DrawingController.prototype.onCanvasContextMenu_=function(d){if($(d.target).closest("#drawing-canvas-container").length)return d.preventDefault(),d.stopPropagation(),d.cancelBubble=!0,!1};a.DrawingController.prototype.render=function(){this.renderLayers();this.renderFrame();this.renderOverlay()};a.DrawingController.prototype.renderFrame=function(){var d=this.piskelController.getCurrentFrame(),a=this.dpi+"-"+d.serialize();this.serializedFrame!=a&&(d.isSameSize(this.overlayFrame)||
(this.overlayFrame=pskl.model.Frame.createEmptyFromFrame(d)),this.serializedFrame=a,this.renderer.render(d))};a.DrawingController.prototype.renderOverlay=function(){var d=this.dpi+"-"+this.overlayFrame.serialize();this.serializedOverlay!=d&&(this.serializedOverlay=d,this.overlayRenderer.render(this.overlayFrame))};a.DrawingController.prototype.renderLayers=function(){var d=this.piskelController.getLayers(),a=this.piskelController.currentFrameIndex,c=this.piskelController.currentLayerIndex,f=[this.dpi,
a,c,d.length].join("-");if(this.serializedLayerFrame!=f){this.layersAboveRenderer.clear();this.layersBelowRenderer.clear();var e=d.slice(0,c),e=this.getFrameForLayersAt_(a,e);this.layersBelowRenderer.render(e);c+1<d.length&&(d=d.slice(c+1,d.length),a=this.getFrameForLayersAt_(a,d),this.layersAboveRenderer.render(a));this.serializedLayerFrame=f}};a.DrawingController.prototype.getFrameForLayersAt_=function(a,b){var c=b.map(function(c){return c.getFrameAt(a)});return pskl.utils.FrameUtils.merge(c)};
a.DrawingController.prototype.calculateDPI_=function(){var a=$("#main-wrapper").height(),b=$(".left-column").outerWidth(!0),c=$(".right-column").outerWidth(!0),b=$("#main-wrapper").width()-b-c,c=this.piskelController.getCurrentFrame().getHeight(),f=this.piskelController.getCurrentFrame().getWidth();pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID)&&(b-=f*Constants.GRID_STROKE_WIDTH,a-=c*Constants.GRID_STROKE_WIDTH);return pskl.PixelUtils.calculateDPI(a,b,c,f)};a.DrawingController.prototype.updateDPI_=
function(){this.dpi=this.calculateDPI_();this.overlayRenderer.setDPI(this.dpi);this.renderer.setDPI(this.dpi);this.layersAboveRenderer.setDPI(this.dpi);this.layersBelowRenderer.setDPI(this.dpi);var a=this.piskelController.getCurrentFrame().getHeight(),b=a*this.dpi;pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID)&&(b+=Constants.GRID_STROKE_WIDTH*a);a=Math.floor(($("#main-wrapper").height()-b)/2);$("#column-wrapper").css({top:a+"px",height:b+"px"})}})();(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="";this.piskelController.getLayers().forEach(this.addLayerItem.bind(this))};a.LayersListController.prototype.addLayerItem=function(a){var b=pskl.utils.Template.replace(this.layerItemTemplate_,{layername:a.getName()}),b=pskl.utils.Template.createFromHTML(b);this.piskelController.getCurrentLayer()===a&&b.classList.add("current-layer-item");this.layersListEl.insertBefore(b,this.layersListEl.firstChild)};a.LayersListController.prototype.onClick_=
function(a){a=a.target||a.srcElement;if("BUTTON"==a.nodeName)this.onButtonClick_(a);else"LI"==a.nodeName&&(a=a.getAttribute("data-layer-name"),this.piskelController.selectLayerByName(a))};a.LayersListController.prototype.onButtonClick_=function(a){a=a.getAttribute("data-action");"up"==a?this.piskelController.moveLayerUp():"down"==a?this.piskelController.moveLayerDown():"add"==a?this.piskelController.createLayer():"delete"==a&&this.piskelController.removeCurrentLayer()}})();(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){var c=document.createElement("div");c.id="user-message";c.className="user-message";c.innerHTML=b.content;c.innerHTML+="<div title='Close message' class='close'>x</div>";
document.body.appendChild(c);$(c).find(".close").click($.proxy(this.removeMessage_,this));b.behavior&&b.behavior(c)};a.NotificationController.prototype.removeMessage_=function(a){a=$("#user-message");a.length&&a.remove()}})();(function(){var a=$.namespace("pskl.controller");a.PaletteController=function(){};a.PaletteController.prototype.init=function(){$(".palette-color[data-color=TRANSPARENT]").mouseup($.proxy(this.onPaletteColorClick_,this));$.subscribe(Events.PRIMARY_COLOR_UPDATED,$.proxy(function(a,d){this.updateColorPicker_(d,$("#color-picker"))},this));$.subscribe(Events.SECONDARY_COLOR_UPDATED,$.proxy(function(a,d){this.updateColorPicker_(d,$("#secondary-color-picker"))},this));var a=$("#color-picker");a.val(Constants.DEFAULT_PEN_COLOR);
a.change({isPrimary:!0},$.proxy(this.onPickerChange_,this));a=$("#secondary-color-picker");a.val(Constants.TRANSPARENT_COLOR);a.change({isPrimary:!1},$.proxy(this.onPickerChange_,this));window.jscolor.install()};a.PaletteController.prototype.onPickerChange_=function(a,b){var c=$(a.target);a.data.isPrimary?$.publish(Events.PRIMARY_COLOR_SELECTED,[c.val()]):$.publish(Events.SECONDARY_COLOR_SELECTED,[c.val()])};a.PaletteController.prototype.onPaletteColorClick_=function(a){var b=$(a.target).data("color"),
c=3==a.which;1==a.which?$.publish(Events.PRIMARY_COLOR_SELECTED,[b]):c&&$.publish(Events.SECONDARY_COLOR_SELECTED,[b])};a.PaletteController.prototype.updateColorPicker_=function(a,b){a==Constants.TRANSPARENT_COLOR?(b[0].color.fromString("#fff"),b.val(Constants.TRANSPARENT_COLOR)):b[0].color.fromString(a)}})();(function(){var a=$.namespace("pskl.controller");a.PiskelController=function(a){if(a)this.setPiskel(a);else throw"A piskel instance is mandatory for instanciating PiskelController";};a.PiskelController.prototype.setPiskel=function(a){this.piskel=a;this.currentFrameIndex=this.currentLayerIndex=0;this.layerIdCounter=1;$.publish(Events.PISKEL_RESET);$.publish(Events.FRAME_SIZE_CHANGED)};a.PiskelController.prototype.getHeight=function(){return this.piskel.getHeight()};a.PiskelController.prototype.getWidth=
function(){return this.piskel.getWidth()};a.PiskelController.prototype.getFPS=function(){return pskl.app.animationController.getFPS()};a.PiskelController.prototype.getLayers=function(){return this.piskel.getLayers()};a.PiskelController.prototype.getCurrentLayer=function(){return this.piskel.getLayerAt(this.currentLayerIndex)};a.PiskelController.prototype.getCurrentFrame=function(){return this.getCurrentLayer().getFrameAt(this.currentFrameIndex)};a.PiskelController.prototype.getFrameAt=function(a){var b=
this.getLayers().map(function(c){return c.getFrameAt(a)});return pskl.utils.FrameUtils.merge(b)};a.PiskelController.prototype.hasFrameAt=function(a){return!!this.getCurrentLayer().getFrameAt(a)};a.PiskelController.prototype.getFrameByIndex=a.PiskelController.prototype.getMergedFrameAt;a.PiskelController.prototype.addEmptyFrame=function(){this.getLayers().forEach(function(a){a.addFrame(this.createEmptyFrame_())}.bind(this))};a.PiskelController.prototype.createEmptyFrame_=function(){var a=this.piskel.getWidth(),
b=this.piskel.getHeight();return new pskl.model.Frame(a,b)};a.PiskelController.prototype.removeFrameAt=function(a){this.getLayers().forEach(function(b){b.removeFrameAt(a)});this.currentFrameIndex>=a&&this.setCurrentFrameIndex(this.currentFrameIndex-1);$.publish(Events.PISKEL_RESET)};a.PiskelController.prototype.duplicateFrameAt=function(a){this.getLayers().forEach(function(b){b.duplicateFrameAt(a)})};a.PiskelController.prototype.moveFrame=function(a,b){this.getLayers().forEach(function(c){c.moveFrame(a,
b)})};a.PiskelController.prototype.getFrameCount=function(){return this.piskel.getLayerAt(0).length()};a.PiskelController.prototype.setCurrentFrameIndex=function(a){this.currentFrameIndex=a;$.publish(Events.PISKEL_RESET)};a.PiskelController.prototype.setCurrentLayerIndex=function(a){this.currentLayerIndex=a;$.publish(Events.PISKEL_RESET)};a.PiskelController.prototype.selectLayer=function(a){a=this.getLayers().indexOf(a);-1!=a&&this.setCurrentLayerIndex(a)};a.PiskelController.prototype.selectLayerByName=
function(a){this.hasLayerForName_(a)&&(a=this.piskel.getLayersByName(a)[0],this.selectLayer(a))};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){a||(a=this.generateLayerName_());if(this.hasLayerForName_(a))throw"Layer name should be unique";a=new pskl.model.Layer(a);for(var b=0;b<this.getFrameCount();b++)a.addFrame(this.createEmptyFrame_());
this.piskel.addLayer(a);this.setCurrentLayerIndex(this.piskel.getLayers().length-1)};a.PiskelController.prototype.hasLayerForName_=function(a){return 0<this.piskel.getLayersByName(a).length};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(1<this.getLayers().length){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.PreviewFilmController=function(a,b,c){this.piskelController=a;this.container=b;this.dpi=this.calculateDPI_();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.refreshDPI_.bind(this));$("#preview-list-scroller").scroll(this.updateScrollerOverflows.bind(this));this.updateScrollerOverflows()};
a.PreviewFilmController.prototype.addFrame=function(){this.piskelController.addEmptyFrame();this.piskelController.setCurrentFrameIndex(this.piskelController.getFrameCount()-1);this.updateScrollerOverflows()};a.PreviewFilmController.prototype.flagForRedraw_=function(){this.redrawFlag=!0};a.PreviewFilmController.prototype.refreshDPI_=function(){this.dpi=this.calculateDPI_()};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(),f=$("#preview-list").height(),e=$(".top-overflow").height(),g=a=!1;b<f&&(c>e&&(a=!0),f-c-b>e&&(g=!0));b=$("#preview-list-wrapper");b.toggleClass("top-overflow-visible",a);b.toggleClass("bottom-overflow-visible",g)};a.PreviewFilmController.prototype.createPreviews_=function(){this.container.html("");$(".tooltip").remove();for(var a=this.piskelController.getFrameCount(),b=0;b<a;b++)this.container.append(this.createPreviewTile_(b));
b=document.createElement("div");b.id="add-frame-action";b.className="add-frame-action";b.innerHTML="<p class='label'>Add new frame</p>";this.container.append(b);$(b).click(this.addFrame.bind(this));1<a&&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),f=$(".preview-tile").index(b.item);this.piskelController.moveFrame(c,f);this.piskelController.setCurrentFrameIndex(f);$.publish(Events.LOCALSTORAGE_REQUEST)};a.PreviewFilmController.prototype.createPreviewTile_=function(a){var b=this.piskelController.getCurrentLayer().getFrameAt(a),c=document.createElement("li"),f="preview-tile";c.setAttribute("data-tile-number",a);this.piskelController.getCurrentFrame()==b&&(f+=" selected");c.className=
f;f=document.createElement("div");f.className="canvas-container";var e=document.createElement("div");e.className="canvas-background";f.appendChild(e);c.addEventListener("click",this.onPreviewClick_.bind(this,a));e=document.createElement("button");e.setAttribute("rel","tooltip");e.setAttribute("data-placement","right");e.setAttribute("title","Duplicate this frame");e.className="tile-overlay duplicate-frame-action";c.appendChild(e);e.addEventListener("click",this.onAddButtonClick_.bind(this,a));e={dpi:this.dpi};
(new pskl.rendering.FrameRenderer($(f),e,["tile-view"])).render(b);c.appendChild(f);if(0<a||1<this.piskelController.getFrameCount())b=document.createElement("button"),b.setAttribute("rel","tooltip"),b.setAttribute("data-placement","right"),b.setAttribute("title","Delete this frame"),b.className="tile-overlay delete-frame-action",b.addEventListener("click",this.onDeleteButtonClick_.bind(this,a)),c.appendChild(b),b=document.createElement("div"),b.className="tile-overlay dnd-action",c.appendChild(b);
b=document.createElement("div");b.className="tile-overlay tile-count";b.innerHTML=a;c.appendChild(b);return c};a.PreviewFilmController.prototype.onPreviewClick_=function(a,b){b.target.classList.contains("tile-overlay")||this.piskelController.setCurrentFrameIndex(a)};a.PreviewFilmController.prototype.onDeleteButtonClick_=function(a,b){this.piskelController.removeFrameAt(a);$.publish(Events.LOCALSTORAGE_REQUEST);this.updateScrollerOverflows()};a.PreviewFilmController.prototype.onAddButtonClick_=function(a,
b){this.piskelController.duplicateFrameAt(a);$.publish(Events.LOCALSTORAGE_REQUEST);this.piskelController.setCurrentFrameIndex(a+1);this.updateScrollerOverflows()};a.PreviewFilmController.prototype.calculateDPI_=function(){var a=this.piskelController.getCurrentFrame(),b=a.getHeight(),a=a.getWidth(),c=Math.max(a,b);return pskl.PixelUtils.calculateDPI(Constants.PREVIEW_FILM_SIZE*b/c,Constants.PREVIEW_FILM_SIZE*a/c,b,a)||1}})();(function(){var a=$.namespace("pskl.controller");a.ToolController=function(){this.toolInstances={simplePen:new pskl.drawingtools.SimplePen,verticalMirrorPen:new pskl.drawingtools.VerticalMirrorPen,eraser:new pskl.drawingtools.Eraser,paintBucket:new pskl.drawingtools.PaintBucket,stroke:new pskl.drawingtools.Stroke,rectangle:new pskl.drawingtools.Rectangle,circle:new pskl.drawingtools.Circle,move:new pskl.drawingtools.Move,rectangleSelect:new pskl.drawingtools.RectangleSelect,shapeSelect:new pskl.drawingtools.ShapeSelect,
colorPicker:new pskl.drawingtools.ColorPicker};this.previousSelectedTool=this.currentSelectedTool=this.toolInstances.simplePen};a.ToolController.prototype.init=function(){this.createToolMarkup_();this.selectTool_(this.toolInstances.simplePen);$("#tool-section").click($.proxy(this.onToolIconClicked_,this))};a.ToolController.prototype.activateToolOnStage_=function(a){var b=$("body"),c=b.data("selected-tool-class");c&&b.removeClass(c);b.addClass(a.toolId);b.data("selected-tool-class",a.toolId)};a.ToolController.prototype.selectTool_=
function(a){console.log("Selecting Tool:",this.currentSelectedTool);this.currentSelectedTool=a;this.activateToolOnStage_(this.currentSelectedTool);$.publish(Events.TOOL_SELECTED,[a])};a.ToolController.prototype.onToolIconClicked_=function(a){a=$(a.target).closest(".tool-icon");if(a.length){var b=a.data().toolId;if(b=this.getToolById_(b))this.selectTool_(b),$("#tool-section .tool-icon.selected").removeClass("selected"),a.addClass("selected")}};a.ToolController.prototype.getToolById_=function(a){for(var b in this.toolInstances)if(this.toolInstances[b].toolId==
a)return this.toolInstances[b];return null};a.ToolController.prototype.createToolMarkup_=function(){var a,b="",c,f;for(f in this.toolInstances)a=this.toolInstances[f],c=a.toolId,this.currentSelectedTool==a&&(c+=" selected"),b+='<li rel="tooltip" data-placement="right" class="tool-icon '+c+'" data-tool-id="'+a.toolId+'" title="'+a.helpText+'"></li>';$("#tools-container").html(b)}})();(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");a=pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID);$("#show-grid").prop("checked",a);$("#show-grid").change($.proxy(function(a){a=$("#show-grid").prop("checked");pskl.UserSettings.set(pskl.UserSettings.SHOW_GRID,
a)},this));$("#background-picker-wrapper").click(function(a){a=$(a.target).closest(".background-picker");if(a.length){var d=a.data("background-class");pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND,d);$(".background-picker").removeClass("selected");a.addClass("selected")}})}})();(function(){var a=$.namespace("pskl.controller.settings");a.GifExportController=function(a){this.piskelController=a};a.GifExportController.RESOLUTIONS=[{dpi:1},{dpi:5},{dpi:10,"default":!0},{dpi:20}];a.GifExportController.prototype.init=function(){this.radioTemplate_=pskl.utils.Template.get("gif-export-radio-template");this.previewContainerEl=document.querySelectorAll(".gif-export-preview")[0];this.radioGroupEl=document.querySelectorAll(".gif-export-radio-group")[0];this.uploadForm=$("[name=gif-export-upload-form]");
this.uploadForm.submit(this.onUploadFormSubmit_.bind(this));this.createRadioElements_()};a.GifExportController.prototype.onUploadFormSubmit_=function(a){a.originalEvent.preventDefault();a=this.getSelectedDpi_();var b=this.piskelController.getFPS();this.renderAsImageDataAnimatedGIF(a,b,this.onGifRenderingCompleted_.bind(this))};a.GifExportController.prototype.onGifRenderingCompleted_=function(a){this.updatePreview_(a);this.previewContainerEl.classList.add("preview-upload-ongoing");pskl.app.imageUploadService.upload(a,
this.onImageUploadCompleted_.bind(this))};a.GifExportController.prototype.onImageUploadCompleted_=function(a){this.updatePreview_(a);this.previewContainerEl.classList.remove("preview-upload-ongoing")};a.GifExportController.prototype.updatePreview_=function(a){this.previewContainerEl.innerHTML="<div><img style='max-width:240px;' src='"+a+"'/></div>"};a.GifExportController.prototype.getSelectedDpi_=function(){var a=this.uploadForm.get(0).querySelectorAll("[name=gif-dpi]"),a=Array.prototype.slice.call(a,
0).filter(function(a){return!!a.checked});if(1==a.length)return a[0].value;throw"Unexpected error when retrieving selected dpi";};a.GifExportController.prototype.createRadioElements_=function(){for(var d=a.GifExportController.RESOLUTIONS,b=0;b<d.length;b++){var c=this.createRadioForResolution_(d[b]);this.radioGroupEl.appendChild(c)}};a.GifExportController.prototype.createRadioForResolution_=function(a){var b=a.dpi,c=b*this.piskelController.getWidth()+"x"+b*this.piskelController.getHeight(),b=pskl.utils.Template.replace(this.radioTemplate_,
{value:b,label:c}),b=pskl.utils.Template.createFromHTML(b);a["default"]&&b.getElementsByTagName("input")[0].setAttribute("checked","checked");return b};a.GifExportController.prototype.blobToBase64_=function(a,b){var c=new FileReader;c.onload=function(){b(c.result)};c.readAsDataURL(a)};a.GifExportController.prototype.renderAsImageDataAnimatedGIF=function(a,b,c){for(var f=new window.GIF({workers:2,quality:10,width:this.piskelController.getWidth()*a,height:this.piskelController.getHeight()*a}),e=0;e<
this.piskelController.getFrameCount();e++){var g=this.piskelController.getFrameAt(e),g=new pskl.rendering.CanvasRenderer(g,a);f.addFrame(g.render(),{delay:1E3/b})}f.on("finished",function(a){this.blobToBase64_(a,c)}.bind(this));f.render()}})();(function(){var a=$.namespace("pskl.controller.settings");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("No file selected ...");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("No file selected ...");$.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,f=this.importedImage_.width;"width"===b?this.resizeHeight.val(Math.round(a*c/f)):this.resizeWidth.val(Math.round(a*
f/c))};a.ImportController.prototype.onImportFormSubmit_=function(a){a.originalEvent.preventDefault();this.importImageToPiskel_()};a.ImportController.prototype.onFileUploadChange_=function(a){this.importFromFile_()};a.ImportController.prototype.onFileInputClick_=function(a){this.hiddenFileInput.click()};a.ImportController.prototype.importFromFile_=function(){var a=this.hiddenFileInput.get(0).files;if(1==a.length)if(a=a[0],this.isImage_(a))this.readImageFile_(a),this.enableDisabledSections_();else throw this.reset_(),
"File is not an image : "+a.type;};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(a){a=this.importedImage_.width;var b=this.importedImage_.height,c=this.hiddenFileInput.val(),c=this.extractFileNameFromPath_(c);this.fileInputStatus.html(c);this.resizeWidth.val(a);this.resizeHeight.val(b);this.importPreview.width("auto");this.importPreview.append(this.createImagePreview_())};
a.ImportController.prototype.createImagePreview_=function(){var a=document.createElement("IMG");a.src=this.importedImage_.src;a.setAttribute("height",60);return a};a.ImportController.prototype.extractFileNameFromPath_=function(a){var b=[],b=-1!==a.indexOf("/")?a.split("/"):-1!==a.indexOf("\\")?a.split("\\"):[a];return 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"),a=pskl.utils.ImageResizer.resize(this.importedImage_,a,b,c),a=pskl.utils.FrameUtils.createFromImage(a),a=pskl.utils.Serializer.createPiskel([a]);pskl.app.piskelController.setPiskel(a);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"),d={user:{template:"templates/settings/application.html",controller:a.ApplicationSettingsController},gif:{template:"templates/settings/export-gif.html",controller:a.GifExportController},"import":{template:"templates/settings/import.html",controller:a.ImportController}};a.SettingsController=function(a){this.piskelController=a;this.drawerContainer=document.getElementById("drawer-container");this.settingsContainer=$("[data-pskl-controller=settings]");
this.expanded=!1;this.currentSetting=null};a.SettingsController.prototype.init=function(){$("[data-setting]").click(function(a){a=a.originalEvent.currentTarget.getAttribute("data-setting");this.currentSetting!=a?this.loadSetting(a):this.closeDrawer()}.bind(this));$("body").click(function(a){a=$.contains(this.settingsContainer.get(0),a.target);this.expanded&&!a&&this.closeDrawer()}.bind(this));$.subscribe(Events.CLOSE_SETTINGS_DRAWER,this.closeDrawer.bind(this))};a.SettingsController.prototype.loadSetting=
function(a){this.drawerContainer.innerHTML=pskl.utils.Template.get(d[a].template);(new d[a].controller(this.piskelController)).init();this.settingsContainer.addClass("expanded");$(".has-expanded-drawer").removeClass("has-expanded-drawer");$("[data-setting="+a+"]").addClass("has-expanded-drawer");this.expanded=!0;this.currentSetting=a};a.SettingsController.prototype.closeDrawer=function(){this.settingsContainer.removeClass("expanded");$(".has-expanded-drawer").removeClass("has-expanded-drawer");this.expanded=
!1;this.currentSetting=null}})();(function(){var a=$.namespace("pskl.drawingtools");a.BaseTool=function(){};a.BaseTool.prototype.applyToolAt=function(a,b,c,f,e){};a.BaseTool.prototype.moveToolAt=function(a,b,c,f,e){};a.BaseTool.prototype.moveUnactiveToolAt=function(a,b,c,f,e){e.containsPixel(a,b)&&(isNaN(this.highlightedPixelCol)||isNaN(this.highlightedPixelRow)||this.highlightedPixelRow==b&&this.highlightedPixelCol==a||e.clear(),e.setPixel(a,b,Constants.TOOL_TARGET_HIGHLIGHT_COLOR),this.highlightedPixelCol=a,this.highlightedPixelRow=
b)};a.BaseTool.prototype.releaseToolAt=function(a,b,c,f,e){};a.BaseTool.prototype.getLinePixels_=function(a,b,c,f){for(var e=[],g=Math.abs(b-a),h=Math.abs(f-c),k=a<b?1:-1,l=c<f?1:-1,m=g-h;;){e.push({col:a,row:c});if(a==b&&c==f)break;var n=2*m;n>-h&&(m-=h,a+=k);n<g&&(m+=g,c+=l)}return e}})();(function(){var a=$.namespace("pskl.drawingtools");a.Circle=function(){this.toolId="tool-circle";this.helpText="Circle tool";this.startRow=this.startCol=null};pskl.utils.inherit(a.Circle,a.BaseTool);a.Circle.prototype.applyToolAt=function(a,b,c,f,e){this.startCol=a;this.startRow=b;e.setPixel(a,b,c)};a.Circle.prototype.moveToolAt=function(a,b,c,f,e){e.clear();c==Constants.TRANSPARENT_COLOR&&(c=Constants.SELECTION_TRANSPARENT_COLOR);this.drawCircle_(a,b,c,e)};a.Circle.prototype.releaseToolAt=function(a,
b,c,f,e){e.clear();f.containsPixel(a,b)&&this.drawCircle_(a,b,c,f)};a.Circle.prototype.drawCircle_=function(a,b,c,f){a=this.getCirclePixels_(this.startCol,this.startRow,a,b);for(b=0;b<a.length;b++)f.setPixel(a[b].col,a[b].row,c)};a.Circle.prototype.getCirclePixels_=function(a,b,c,f){a=pskl.PixelUtils.getOrderedRectangleCoordinates(a,b,c,f);b=(a.x0+a.x1)/2;c=(a.y0+a.y1)/2;f=a.x1-b;var e=a.y1-c,g=[],h,k,l;for(h=a.x0;h<a.x1;h++)l=Math.acos((h-b)/f),k=Math.round(e*Math.sin(l)+c),g.push({col:h,row:k}),
g.push({col:2*b-h,row:2*c-k});for(k=a.y0;k<a.y1;k++)l=Math.asin((k-c)/e),h=Math.round(f*Math.cos(l)+b),g.push({col:h,row:k}),g.push({col:2*b-h,row:2*c-k});return g}})();(function(){var a=$.namespace("pskl.drawingtools");a.ColorPicker=function(){this.toolId="tool-colorpicker";this.helpText="Color picker"};pskl.utils.inherit(a.ColorPicker,a.BaseTool);a.ColorPicker.prototype.applyToolAt=function(a,b,c,f,e,g){f.containsPixel(a,b)&&(a=f.getPixel(a,b),g.button==Constants.LEFT_BUTTON?$.publish(Events.PRIMARY_COLOR_SELECTED,[a]):g.button==Constants.RIGHT_BUTTON&&$.publish(Events.SECONDARY_COLOR_SELECTED,[a]))}})();(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,f,e){this.superclass.applyToolAt.call(this,a,b,Constants.TRANSPARENT_COLOR,f,e)}})();(function(){var a=$.namespace("pskl.drawingtools");a.Move=function(){this.toolId="tool-move";this.helpText="Move tool";this.startRow=this.startCol=null};pskl.utils.inherit(a.Move,a.BaseTool);a.Move.prototype.applyToolAt=function(a,b,c,f,e){this.startCol=a;this.startRow=b;this.frameClone=f.clone()};a.Move.prototype.moveToolAt=function(a,b,c,f,e){this.shiftFrame(a-this.startCol,b-this.startRow,f,this.frameClone)};a.Move.prototype.shiftFrame=function(a,b,c,f){for(var e,g=0;g<c.getWidth();g++)for(var h=
0;h<c.getHeight();h++)e=f.containsPixel(g-a,h-b)?f.getPixel(g-a,h-b):Constants.TRANSPARENT_COLOR,c.setPixel(g,h,e)};a.Move.prototype.releaseToolAt=function(a,b,c,f,e){this.moveToolAt(a,b,c,f,e)}})();(function(){var a=$.namespace("pskl.drawingtools");a.PaintBucket=function(){this.toolId="tool-paint-bucket";this.helpText="Paint bucket tool"};pskl.utils.inherit(a.PaintBucket,a.BaseTool);a.PaintBucket.prototype.applyToolAt=function(a,b,c,f,e){pskl.PixelUtils.paintSimilarConnectedPixelsFromFrame(f,a,b,c)}})();(function(){var a=$.namespace("pskl.drawingtools");a.Rectangle=function(){this.toolId="tool-rectangle";this.helpText="Rectangle tool";this.startRow=this.startCol=null};pskl.utils.inherit(a.Rectangle,a.BaseTool);a.Rectangle.prototype.applyToolAt=function(a,b,c,f,e){this.startCol=a;this.startRow=b;e.setPixel(a,b,c)};a.Rectangle.prototype.moveToolAt=function(a,b,c,f,e){e.clear();c==Constants.TRANSPARENT_COLOR&&(c=Constants.SELECTION_TRANSPARENT_COLOR);this.drawRectangle_(a,b,c,e)};a.Rectangle.prototype.releaseToolAt=
function(a,b,c,f,e){e.clear();f.containsPixel(a,b)&&this.drawRectangle_(a,b,c,f)};a.Rectangle.prototype.drawRectangle_=function(a,b,c,f){a=pskl.PixelUtils.getBoundRectanglePixels(this.startCol,this.startRow,a,b);for(b=0;b<a.length;b++)f.setPixel(a[b].col,a[b].row,c)}})();(function(){var a=$.namespace("pskl.drawingtools");a.SimplePen=function(){this.toolId="tool-pen";this.helpText="Pen tool";this.previousRow=this.previousCol=null};pskl.utils.inherit(a.SimplePen,a.BaseTool);a.SimplePen.prototype.applyToolAt=function(a,b,c,f,e){f.containsPixel(a,b)&&f.setPixel(a,b,c);this.previousCol=a;this.previousRow=b};a.SimplePen.prototype.moveToolAt=function(a,b,c,f,e){if(1<Math.abs(a-this.previousCol)||1<Math.abs(b-this.previousRow))for(var g=this.getLinePixels_(a,this.previousCol,
b,this.previousRow),h=0,k=g.length;h<k;h++){var l=g[h];this.applyToolAt(l.col,l.row,c,f,e)}else this.applyToolAt(a,b,c,f,e);this.previousCol=a;this.previousRow=b}})();(function(){var a=$.namespace("pskl.drawingtools");a.Stroke=function(){this.toolId="tool-stroke";this.helpText="Stroke tool";this.startRow=this.startCol=null};pskl.utils.inherit(a.Stroke,a.BaseTool);a.Stroke.prototype.applyToolAt=function(a,b,c,f,e){this.startCol=a;this.startRow=b;e.setPixel(a,b,c)};a.Stroke.prototype.moveToolAt=function(a,b,c,f,e){e.clear();a=this.getLinePixels_(this.startCol,a,this.startRow,b);for(b=0;b<a.length;b++)c==Constants.TRANSPARENT_COLOR&&(c=Constants.SELECTION_TRANSPARENT_COLOR),
e.setPixel(a[b].col,a[b].row,c)};a.Stroke.prototype.releaseToolAt=function(a,b,c,f,e){if(f.containsPixel(a,b))for(a=this.getLinePixels_(this.startCol,a,this.startRow,b),b=0;b<a.length;b++)f.setPixel(a[b].col,a[b].row,c);e.clear()}})();(function(){var a=$.namespace("pskl.drawingtools");a.VerticalMirrorPen=function(){this.toolId="tool-vertical-mirror-pen";this.helpText="vertical mirror pen tool";this.mirroredPreviousRow=this.mirroredPreviousCol=this.swap=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,f,e){this.superclass.applyToolAt.call(this,a,b,c,f,e);this.mirroredPreviousCol=a=this.getSymmetricCol_(a,f);this.setMirrorContext();this.superclass.applyToolAt.call(this,a,b,c,f,e);this.unsetMirrorContext()};a.VerticalMirrorPen.prototype.getSymmetricCol_=function(a,b){return b.getWidth()-a-1}})();(function(){var a=$.namespace("pskl.drawingtools");a.BaseSelect=function(){this.secondaryToolId="tool-move";this.BodyRoot=$("body");this.startRow=this.startCol=null};pskl.utils.inherit(a.BaseSelect,a.BaseTool);a.BaseSelect.prototype.applyToolAt=function(a,b,c,f,e){this.startCol=a;this.startRow=b;this.lastCol=a;this.lastRow=b;e.getPixel(a,b)!=Constants.SELECTION_TRANSPARENT_COLOR?(this.mode="select",this.onSelectStart_(a,b,c,f,e)):(this.mode="moveSelection",this.onSelectionDragStart_(a,b,c,f,e))};
a.BaseSelect.prototype.moveToolAt=function(a,b,c,f,e){if("select"==this.mode)this.onSelect_(a,b,c,f,e);else if("moveSelection"==this.mode)this.onSelectionDrag_(a,b,c,f,e)};a.BaseSelect.prototype.releaseToolAt=function(a,b,c,f,e){if("select"==this.mode)this.onSelectEnd_(a,b,c,f,e);else if("moveSelection"==this.mode)this.onSelectionDragEnd_(a,b,c,f,e)};a.BaseSelect.prototype.moveUnactiveToolAt=function(a,b,c,f,e){e.getPixel(a,b)!=Constants.SELECTION_TRANSPARENT_COLOR?(this.BodyRoot.addClass(this.toolId),
this.BodyRoot.removeClass(this.secondaryToolId)):(this.BodyRoot.addClass(this.secondaryToolId),this.BodyRoot.removeClass(this.toolId))};a.BaseSelect.prototype.drawSelectionOnOverlay_=function(a,b){for(var c=a.pixels,f=0,e=c.length;f<e;f++)b.setPixel(c[f].col,c[f].row,Constants.SELECTION_TRANSPARENT_COLOR)};a.BaseSelect.prototype.shiftOverlayFrame_=function(a,b,c,f){for(var e,g=0;g<c.getWidth();g++)for(var h=0;h<c.getHeight();h++)e=f.containsPixel(g-a,h-b)?f.getPixel(g-a,h-b):Constants.TRANSPARENT_COLOR,
c.setPixel(g,h,e)};a.BaseSelect.prototype.onSelectStart_=function(a,b,c,f,e){};a.BaseSelect.prototype.onSelect_=function(a,b,c,f,e){};a.BaseSelect.prototype.onSelectEnd_=function(a,b,c,f,e){};a.BaseSelect.prototype.onSelectionDragStart_=function(a,b,c,f,e){this.overlayFrameReference=e.clone()};a.BaseSelect.prototype.onSelectionDrag_=function(a,b,c,f,e){c=a-this.lastCol;f=b-this.lastRow;this.shiftOverlayFrame_(a-this.startCol,b-this.startRow,e,this.overlayFrameReference);$.publish(Events.SELECTION_MOVE_REQUEST,
[c,f]);this.lastCol=a;this.lastRow=b};a.BaseSelect.prototype.onSelectionDragEnd_=function(a,b,c,f,e){this.onSelectionDrag_(a,b,c,f,e)}})();(function(){var a=$.namespace("pskl.drawingtools");a.RectangleSelect=function(){this.toolId="tool-rectangle-select";this.helpText="Rectangle selection tool";a.BaseSelect.call(this)};pskl.utils.inherit(a.RectangleSelect,a.BaseSelect);a.RectangleSelect.prototype.onSelectStart_=function(a,b,c,f,e){e.setPixel(a,b,c)};a.RectangleSelect.prototype.onSelect_=function(a,b,c,f,e){e.clear();this.startCol==a&&this.startRow==b?$.publish(Events.SELECTION_DISMISSED):(a=new pskl.selection.RectangularSelection(this.startCol,
this.startRow,a,b),$.publish(Events.SELECTION_CREATED,[a]),this.drawSelectionOnOverlay_(a,e))};a.RectangleSelect.prototype.onSelectEnd_=function(a,b,c,f,e){this.onSelect_(a,b,c,f,e)}})();(function(){var a=$.namespace("pskl.drawingtools");a.ShapeSelect=function(){this.toolId="tool-shape-select";this.helpText="Shape selection tool";a.BaseSelect.call(this)};pskl.utils.inherit(a.ShapeSelect,a.BaseSelect);a.ShapeSelect.prototype.onSelectStart_=function(a,b,c,f,e){$.publish(Events.SELECTION_DISMISSED);e.clear();a=pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(f,a,b);a=new pskl.selection.ShapeSelection(a);$.publish(Events.SELECTION_CREATED,[a]);this.drawSelectionOnOverlay_(a,e)}})();(function(){window.iframeloader={onLoad:function(a){a=a.target||a.srcElement;var d=a.getAttribute("data-iframe-loader");"display"===d?(d=document.createElement("div"),d.innerHTML=a.contentWindow.document.body.innerHTML,1==d.children.length&&(d=d.children[0]),a.parentNode.replaceChild(d,a)):"store"===d?(d=document.createElement("script"),d.setAttribute("type","text/html"),d.setAttribute("id",a.getAttribute("src")),d.innerHTML=a.contentWindow.document.body.innerHTML,a.parentNode.removeChild(a),document.body.appendChild(d)):
console.error("iframeLoader invalid type : "+d)}}})();(function(a,d){function b(b,d){var e,f;e=b.nodeName.toLowerCase();if("area"===e){e=b.parentNode;f=e.name;if(!b.href||!f||"map"!==e.nodeName.toLowerCase())return!1;e=a("img[usemap=#"+f+"]")[0];return!!e&&c(e)}return(/input|select|textarea|button|object/.test(e)?!b.disabled:"a"===e?b.href||d:d)&&c(b)}function c(c){return a.expr.filters.visible(c)&&!a(c).parents().addBack().filter(function(){return"hidden"===a.css(this,"visibility")}).length}var f=0,e=/^ui-id-\d+$/;a.ui=a.ui||{};a.extend(a.ui,{version:"1.10.3",
keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38}});a.fn.extend({focus:function(c){return function(b,d){return"number"===typeof b?this.each(function(){var c=this;setTimeout(function(){a(c).focus();d&&d.call(c)},b)}):c.apply(this,arguments)}}(a.fn.focus),scrollParent:function(){var c;c=
a.ui.ie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(a.css(this,"position"))&&/(auto|scroll)/.test(a.css(this,"overflow")+a.css(this,"overflow-y")+a.css(this,"overflow-x"))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(a.css(this,"overflow")+a.css(this,"overflow-y")+a.css(this,"overflow-x"))}).eq(0);return/fixed/.test(this.css("position"))||!c.length?a(document):
c},zIndex:function(c){if(c!==d)return this.css("zIndex",c);if(this.length){c=a(this[0]);for(var b;c.length&&c[0]!==document;){b=c.css("position");if("absolute"===b||"relative"===b||"fixed"===b)if(b=parseInt(c.css("zIndex"),10),!isNaN(b)&&0!==b)return b;c=c.parent()}}return 0},uniqueId:function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++f)})},removeUniqueId:function(){return this.each(function(){e.test(this.id)&&a(this).removeAttr("id")})}});a.extend(a.expr[":"],{data:a.expr.createPseudo?
a.expr.createPseudo(function(c){return function(b){return!!a.data(b,c)}}):function(c,b,d){return!!a.data(c,d[3])},focusable:function(c){return b(c,!isNaN(a.attr(c,"tabindex")))},tabbable:function(c){var d=a.attr(c,"tabindex"),e=isNaN(d);return(e||0<=d)&&b(c,!e)}});a("<a>").outerWidth(1).jquery||a.each(["Width","Height"],function(c,b){function e(c,b,d,g){a.each(f,function(){b-=parseFloat(a.css(c,"padding"+this))||0;d&&(b-=parseFloat(a.css(c,"border"+this+"Width"))||0);g&&(b-=parseFloat(a.css(c,"margin"+
this))||0)});return b}var f="Width"===b?["Left","Right"]:["Top","Bottom"],m=b.toLowerCase(),n={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};a.fn["inner"+b]=function(c){return c===d?n["inner"+b].call(this):this.each(function(){a(this).css(m,e(this,c)+"px")})};a.fn["outer"+b]=function(c,d){return"number"!==typeof c?n["outer"+b].call(this,c):this.each(function(){a(this).css(m,e(this,c,!0,d)+"px")})}});a.fn.addBack||(a.fn.addBack=function(a){return this.add(null==
a?this.prevObject:this.prevObject.filter(a))});a("<a>").data("a-b","a").removeData("a-b").data("a-b")&&(a.fn.removeData=function(c){return function(b){return arguments.length?c.call(this,a.camelCase(b)):c.call(this)}}(a.fn.removeData));a.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase());a.support.selectstart="onselectstart"in document.createElement("div");a.fn.extend({disableSelection:function(){return this.bind((a.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",
function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});a.extend(a.ui,{plugin:{add:function(c,b,d){var e;c=a.ui[c].prototype;for(e in d)c.plugins[e]=c.plugins[e]||[],c.plugins[e].push([b,d[e]])},call:function(a,c,b){var d=a.plugins[c];if(d&&a.element[0].parentNode&&11!==a.element[0].parentNode.nodeType)for(c=0;c<d.length;c++)a.options[d[c][0]]&&d[c][1].apply(a.element,b)}},hasScroll:function(c,b){if("hidden"===a(c).css("overflow"))return!1;var d=
b&&"left"===b?"scrollLeft":"scrollTop",e=!1;if(0<c[d])return!0;c[d]=1;e=0<c[d];c[d]=0;return e}})})(jQuery);
(function(a,d){var b=0,c=Array.prototype.slice,f=a.cleanData;a.cleanData=function(c){for(var b=0,d;null!=(d=c[b]);b++)try{a(d).triggerHandler("remove")}catch(k){}f(c)};a.widget=function(c,b,d){var f,l,m,n,q={},p=c.split(".")[0];c=c.split(".")[1];f=p+"-"+c;d||(d=b,b=a.Widget);a.expr[":"][f.toLowerCase()]=function(c){return!!a.data(c,f)};a[p]=a[p]||{};l=a[p][c];m=a[p][c]=function(a,c){if(!this._createWidget)return new m(a,c);arguments.length&&this._createWidget(a,c)};a.extend(m,l,{version:d.version,
_proto:a.extend({},d),_childConstructors:[]});n=new b;n.options=a.widget.extend({},n.options);a.each(d,function(c,d){a.isFunction(d)?q[c]=function(){var a=function(){return b.prototype[c].apply(this,arguments)},e=function(a){return b.prototype[c].apply(this,a)};return function(){var c=this._super,b=this._superApply,f;this._super=a;this._superApply=e;f=d.apply(this,arguments);this._super=c;this._superApply=b;return f}}():q[c]=d});m.prototype=a.widget.extend(n,{widgetEventPrefix:l?n.widgetEventPrefix:
c},q,{constructor:m,namespace:p,widgetName:c,widgetFullName:f});l?(a.each(l._childConstructors,function(c,b){var d=b.prototype;a.widget(d.namespace+"."+d.widgetName,m,b._proto)}),delete l._childConstructors):b._childConstructors.push(m);a.widget.bridge(c,m)};a.widget.extend=function(b){for(var f=c.call(arguments,1),h=0,k=f.length,l,m;h<k;h++)for(l in f[h])m=f[h][l],f[h].hasOwnProperty(l)&&m!==d&&(a.isPlainObject(m)?b[l]=a.isPlainObject(b[l])?a.widget.extend({},b[l],m):a.widget.extend({},m):b[l]=m);
return b};a.widget.bridge=function(b,f){var h=f.prototype.widgetFullName||b;a.fn[b]=function(k){var l="string"===typeof k,m=c.call(arguments,1),n=this;k=!l&&m.length?a.widget.extend.apply(null,[k].concat(m)):k;l?this.each(function(){var c,f=a.data(this,h);if(!f)return a.error("cannot call methods on "+b+" prior to initialization; attempted to call method '"+k+"'");if(!a.isFunction(f[k])||"_"===k.charAt(0))return a.error("no such method '"+k+"' for "+b+" widget instance");c=f[k].apply(f,m);if(c!==
f&&c!==d)return n=c&&c.jquery?n.pushStack(c.get()):c,!1}):this.each(function(){var c=a.data(this,h);c?c.option(k||{})._init():a.data(this,h,new f(k,this))});return n}};a.Widget=function(){};a.Widget._childConstructors=[];a.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",defaultElement:"<div>",options:{disabled:!1,create:null},_createWidget:function(c,d){d=a(d||this.defaultElement||this)[0];this.element=a(d);this.uuid=b++;this.eventNamespace="."+this.widgetName+this.uuid;this.options=a.widget.extend({},
this.options,this._getCreateOptions(),c);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,b){var f=c,k,l,m;if(0===arguments.length)return a.widget.extend({},this.options);if("string"===typeof c)if(f={},k=c.split("."),c=k.shift(),k.length){l=f[c]=a.widget.extend({},this.options[c]);for(m=0;m<k.length-1;m++)l[k[m]]=l[k[m]]||{},l=l[k[m]];c=k.pop();if(b===d)return l[c]===d?null:l[c];l[c]=b}else{if(b===d)return this.options[c]===d?null:this.options[c];f[c]=b}this._setOptions(f);return this},_setOptions:function(a){for(var c in a)this._setOption(c,a[c]);return this},_setOption:function(a,
c){this.options[a]=c;"disabled"===a&&(this.widget().toggleClass(this.widgetFullName+"-disabled ui-state-disabled",!!c).attr("aria-disabled",c),this.hoverable.removeClass("ui-state-hover"),this.focusable.removeClass("ui-state-focus"));return this},enable:function(){return this._setOption("disabled",!1)},disable:function(){return this._setOption("disabled",!0)},_on:function(c,b,d){var f,l=this;"boolean"!==typeof c&&(d=b,b=c,c=!1);d?(b=f=a(b),this.bindings=this.bindings.add(b)):(d=b,b=this.element,f=
this.widget());a.each(d,function(d,h){function q(){if(c||!0!==l.options.disabled&&!a(this).hasClass("ui-state-disabled"))return("string"===typeof h?l[h]:h).apply(l,arguments)}"string"!==typeof h&&(q.guid=h.guid=h.guid||q.guid||a.guid++);var p=d.match(/^(\w+)\s*(.*)$/),r=p[1]+l.eventNamespace;(p=p[2])?f.delegate(p,r,q):b.bind(r,q)})},_off:function(a,c){c=(c||"").split(" ").join(this.eventNamespace+" ")+this.eventNamespace;a.unbind(c).undelegate(c)},_delay:function(a,c){var b=this;return setTimeout(function(){return("string"===
typeof a?b[a]:a).apply(b,arguments)},c||0)},_hoverable:function(c){this.hoverable=this.hoverable.add(c);this._on(c,{mouseenter:function(c){a(c.currentTarget).addClass("ui-state-hover")},mouseleave:function(c){a(c.currentTarget).removeClass("ui-state-hover")}})},_focusable:function(c){this.focusable=this.focusable.add(c);this._on(c,{focusin:function(c){a(c.currentTarget).addClass("ui-state-focus")},focusout:function(c){a(c.currentTarget).removeClass("ui-state-focus")}})},_trigger:function(c,b,d){var f,
l=this.options[c];d=d||{};b=a.Event(b);b.type=(c===this.widgetEventPrefix?c:this.widgetEventPrefix+c).toLowerCase();b.target=this.element[0];if(c=b.originalEvent)for(f in c)f in b||(b[f]=c[f]);this.element.trigger(b,d);return!(a.isFunction(l)&&!1===l.apply(this.element[0],[b].concat(d))||b.isDefaultPrevented())}};a.each({show:"fadeIn",hide:"fadeOut"},function(c,b){a.Widget.prototype["_"+c]=function(d,f,l){"string"===typeof f&&(f={effect:f});var m,n=f?!0===f||"number"===typeof f?b:f.effect||b:c;f=
f||{};"number"===typeof f&&(f={duration:f});m=!a.isEmptyObject(f);f.complete=l;f.delay&&d.delay(f.delay);if(m&&a.effects&&a.effects.effect[n])d[c](f);else if(n!==c&&d[n])d[n](f.duration,f.easing,l);else d.queue(function(b){a(this)[c]();l&&l.call(d[0]);b()})}})})(jQuery);
(function(a,d){var b=!1;a(document).mouseup(function(){b=!1});a.widget("ui.mouse",{version:"1.10.3",options:{cancel:"input,textarea,button,select,option",distance:1,delay:0},_mouseInit:function(){var c=this;this.element.bind("mousedown."+this.widgetName,function(a){return c._mouseDown(a)}).bind("click."+this.widgetName,function(b){if(!0===a.data(b.target,c.widgetName+".preventClickEvent"))return a.removeData(b.target,c.widgetName+".preventClickEvent"),b.stopImmediatePropagation(),!1});this.started=
!1},_mouseDestroy:function(){this.element.unbind("."+this.widgetName);this._mouseMoveDelegate&&a(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate)},_mouseDown:function(c){if(!b){this._mouseStarted&&this._mouseUp(c);this._mouseDownEvent=c;var d=this,e=1===c.which,g="string"===typeof this.options.cancel&&c.target.nodeName?a(c.target).closest(this.options.cancel).length:!1;if(!e||g||!this._mouseCapture(c))return!0;this.mouseDelayMet=
!this.options.delay;this.mouseDelayMet||(this._mouseDelayTimer=setTimeout(function(){d.mouseDelayMet=!0},this.options.delay));if(this._mouseDistanceMet(c)&&this._mouseDelayMet(c)&&(this._mouseStarted=!1!==this._mouseStart(c),!this._mouseStarted))return c.preventDefault(),!0;!0===a.data(c.target,this.widgetName+".preventClickEvent")&&a.removeData(c.target,this.widgetName+".preventClickEvent");this._mouseMoveDelegate=function(a){return d._mouseMove(a)};this._mouseUpDelegate=function(a){return d._mouseUp(a)};
a(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);c.preventDefault();return b=!0}},_mouseMove:function(c){if(a.ui.ie&&(!document.documentMode||9>document.documentMode)&&!c.button)return this._mouseUp(c);if(this._mouseStarted)return this._mouseDrag(c),c.preventDefault();this._mouseDistanceMet(c)&&this._mouseDelayMet(c)&&((this._mouseStarted=!1!==this._mouseStart(this._mouseDownEvent,c))?this._mouseDrag(c):this._mouseUp(c));
return!this._mouseStarted},_mouseUp:function(c){a(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);this._mouseStarted&&(this._mouseStarted=!1,c.target===this._mouseDownEvent.target&&a.data(c.target,this.widgetName+".preventClickEvent",!0),this._mouseStop(c));return!1},_mouseDistanceMet:function(a){return Math.max(Math.abs(this._mouseDownEvent.pageX-a.pageX),Math.abs(this._mouseDownEvent.pageY-a.pageY))>=this.options.distance},
_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return!0}})})(jQuery);
(function(a,d){function b(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||b(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;0<=a;a--)this.items[a].item.removeData(this.widgetName+"-item");return this},_setOption:function(c,b){"disabled"===c?(this.options[c]=b,this.widget().toggleClass("ui-sortable-disabled",!!b)):a.Widget.prototype._setOption.apply(this,arguments)},_mouseCapture:function(c,b){var d=null,g=!1,h=this;if(this.reverting||this.options.disabled||"static"===this.options.type)return!1;this._refreshItems(c);a(c.target).parents().each(function(){if(a.data(this,h.widgetName+"-item")===
h)return d=a(this),!1});a.data(c.target,h.widgetName+"-item")===h&&(d=a(c.target));if(!d||this.options.handle&&!b&&(a(this.options.handle,d).find("*").addBack().each(function(){this===c.target&&(g=!0)}),!g))return!1;this.currentItem=d;this._removeCurrentsFromItems();return!0},_mouseStart:function(c,b,d){var g;b=this.options;this.currentContainer=this;this.refreshPositions();this.helper=this._createHelper(c);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:c.pageX-this.offset.left,top:c.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(c);this.originalPageX=c.pageX;this.originalPageY=c.pageY;b.cursorAt&&this._adjustOffsetFromHelper(b.cursorAt);
this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};this.helper[0]!==this.currentItem[0]&&this.currentItem.hide();this._createPlaceholder();b.containment&&this._setContainment();b.cursor&&"auto"!==b.cursor&&(g=this.document.find("body"),this.storedCursor=g.css("cursor"),g.css("cursor",b.cursor),this.storedStylesheet=a("<style>*{ cursor: "+b.cursor+" !important; }</style>").appendTo(g));b.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),
this.helper.css("opacity",b.opacity));b.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",b.zIndex));this.scrollParent[0]!==document&&"HTML"!==this.scrollParent[0].tagName&&(this.overflowOffset=this.scrollParent.offset());this._trigger("start",c,this._uiHash());this._preserveHelperProportions||this._cacheHelperProportions();if(!d)for(d=this.containers.length-1;0<=d;d--)this.containers[d]._trigger("activate",c,this._uiHash(this));a.ui.ddmanager&&
(a.ui.ddmanager.current=this);a.ui.ddmanager&&!b.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,c);this.dragging=!0;this.helper.addClass("ui-sortable-helper");this._mouseDrag(c);return!0},_mouseDrag:function(c){var b,d,g,h;b=this.options;d=!1;this.position=this._generatePosition(c);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-c.pageY<b.scrollSensitivity?this.scrollParent[0].scrollTop=d=this.scrollParent[0].scrollTop+b.scrollSpeed:c.pageY-this.overflowOffset.top<b.scrollSensitivity&&(this.scrollParent[0].scrollTop=d=this.scrollParent[0].scrollTop-b.scrollSpeed),this.overflowOffset.left+this.scrollParent[0].offsetWidth-c.pageX<b.scrollSensitivity?this.scrollParent[0].scrollLeft=d=this.scrollParent[0].scrollLeft+b.scrollSpeed:c.pageX-this.overflowOffset.left<b.scrollSensitivity&&(this.scrollParent[0].scrollLeft=
d=this.scrollParent[0].scrollLeft-b.scrollSpeed)):(c.pageY-a(document).scrollTop()<b.scrollSensitivity?d=a(document).scrollTop(a(document).scrollTop()-b.scrollSpeed):a(window).height()-(c.pageY-a(document).scrollTop())<b.scrollSensitivity&&(d=a(document).scrollTop(a(document).scrollTop()+b.scrollSpeed)),c.pageX-a(document).scrollLeft()<b.scrollSensitivity?d=a(document).scrollLeft(a(document).scrollLeft()-b.scrollSpeed):a(window).width()-(c.pageX-a(document).scrollLeft())<b.scrollSensitivity&&(d=a(document).scrollLeft(a(document).scrollLeft()+
b.scrollSpeed))),!1!==d&&a.ui.ddmanager&&!b.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,c));this.positionAbs=this._convertPositionTo("absolute");this.options.axis&&"y"===this.options.axis||(this.helper[0].style.left=this.position.left+"px");this.options.axis&&"x"===this.options.axis||(this.helper[0].style.top=this.position.top+"px");for(b=this.items.length-1;0<=b;b--)if(d=this.items[b],g=d.item[0],(h=this._intersectsWithPointer(d))&&d.instance===this.currentContainer&&g!==this.currentItem[0]&&
this.placeholder[1===h?"next":"prev"]()[0]!==g&&!a.contains(this.placeholder[0],g)&&("semi-dynamic"===this.options.type?!a.contains(this.element[0],g):1)){this.direction=1===h?"down":"up";if("pointer"===this.options.tolerance||this._intersectsWithSides(d))this._rearrange(c,d);else break;this._trigger("change",c,this._uiHash());break}this._contactContainers(c);a.ui.ddmanager&&a.ui.ddmanager.drag(this,c);this._trigger("sort",c,this._uiHash());this.lastPositionAbs=this.positionAbs;return!1},_mouseStop:function(c,
b){if(c){a.ui.ddmanager&&!this.options.dropBehaviour&&a.ui.ddmanager.drop(this,c);if(this.options.revert){var d=this,g=this.placeholder.offset(),h=this.options.axis,k={};h&&"x"!==h||(k.left=g.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]===document.body?0:this.offsetParent[0].scrollLeft));h&&"y"!==h||(k.top=g.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(k,parseInt(this.options.revert,
10)||500,function(){d._clear(c)})}else this._clear(c,b);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 c=this.containers.length-1;0<=c;c--)this.containers[c]._trigger("deactivate",null,this._uiHash(this)),this.containers[c].containerCache.over&&(this.containers[c]._trigger("out",null,this._uiHash(this)),this.containers[c].containerCache.over=
0)}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));return this},serialize:function(c){var b=this._getItemsAsjQuery(c&&c.connected),d=[];c=c||{};
a(b).each(function(){var b=(a(c.item||this).attr(c.attribute||"id")||"").match(c.expression||/(.+)[\-=_](.+)/);b&&d.push((c.key||b[1]+"[]")+"="+(c.key&&c.expression?b[1]:b[2]))});!d.length&&c.key&&d.push(c.key+"=");return d.join("&")},toArray:function(c){var b=this._getItemsAsjQuery(c&&c.connected),d=[];c=c||{};b.each(function(){d.push(a(c.item||this).attr(c.attribute||"id")||"")});return d},_intersectsWith:function(a){var b=this.positionAbs.left,d=b+this.helperProportions.width,g=this.positionAbs.top,
h=g+this.helperProportions.height,k=a.left,l=k+a.width,m=a.top,n=m+a.height,q=this.offset.click.top,p=this.offset.click.left,p="y"===this.options.axis||b+p>k&&b+p<l,q=("x"===this.options.axis||g+q>m&&g+q<n)&&p;return"pointer"===this.options.tolerance||this.options.forcePointerForContainers||"pointer"!==this.options.tolerance&&this.helperProportions[this.floating?"width":"height"]>a[this.floating?"width":"height"]?q:k<b+this.helperProportions.width/2&&d-this.helperProportions.width/2<l&&m<g+this.helperProportions.height/
2&&h-this.helperProportions.height/2<n},_intersectsWithPointer:function(a){var b="y"===this.options.axis||this.positionAbs.left+this.offset.click.left>a.left&&this.positionAbs.left+this.offset.click.left<a.left+a.width;a=("x"===this.options.axis||this.positionAbs.top+this.offset.click.top>a.top&&this.positionAbs.top+this.offset.click.top<a.top+a.height)&&b;var b=this._getDragVerticalDirection(),d=this._getDragHorizontalDirection();return a?this.floating?d&&"right"===d||"down"===b?2:1:b&&("down"===
b?2:1):!1},_intersectsWithSides:function(a){var b=this.positionAbs.top+this.offset.click.top>a.top+a.height/2&&this.positionAbs.top+this.offset.click.top<a.top+a.height/2+a.height;a=this.positionAbs.left+this.offset.click.left>a.left+a.width/2&&this.positionAbs.left+this.offset.click.left<a.left+a.width/2+a.width;var d=this._getDragVerticalDirection(),g=this._getDragHorizontalDirection();return this.floating&&g?"right"===g&&a||"left"===g&&!a:d&&("down"===d&&b||"up"===d&&!b)},_getDragVerticalDirection:function(){var a=
this.positionAbs.top-this.lastPositionAbs.top;return 0!==a&&(0<a?"down":"up")},_getDragHorizontalDirection:function(){var a=this.positionAbs.left-this.lastPositionAbs.left;return 0!==a&&(0<a?"right":"left")},refresh:function(a){this._refreshItems(a);this.refreshPositions();return this},_connectWith:function(){var a=this.options;return a.connectWith.constructor===String?[a.connectWith]:a.connectWith},_getItemsAsjQuery:function(c){var b,d,g,h=[],k=[],l=this._connectWith();if(l&&c)for(c=l.length-1;0<=
c;c--)for(d=a(l[c]),b=d.length-1;0<=b;b--)(g=a.data(d[b],this.widgetFullName))&&g!==this&&!g.options.disabled&&k.push([a.isFunction(g.options.items)?g.options.items.call(g.element):a(g.options.items,g.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),g]);k.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]);
for(c=k.length-1;0<=c;c--)k[c][0].each(function(){h.push(this)});return a(h)},_removeCurrentsFromItems:function(){var c=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=a.grep(this.items,function(a){for(var b=0;b<c.length;b++)if(c[b]===a.item[0])return!1;return!0})},_refreshItems:function(c){this.items=[];this.containers=[this];var b,d,g,h,k,l=this.items,m=[[a.isFunction(this.options.items)?this.options.items.call(this.element[0],c,{item:this.currentItem}):a(this.options.items,
this.element),this]];if((k=this._connectWith())&&this.ready)for(b=k.length-1;0<=b;b--)for(g=a(k[b]),d=g.length-1;0<=d;d--)(h=a.data(g[d],this.widgetFullName))&&h!==this&&!h.options.disabled&&(m.push([a.isFunction(h.options.items)?h.options.items.call(h.element[0],c,{item:this.currentItem}):a(h.options.items,h.element),h]),this.containers.push(h));for(b=m.length-1;0<=b;b--)for(c=m[b][1],g=m[b][0],d=0,k=g.length;d<k;d++)h=a(g[d]),h.data(this.widgetName+"-item",c),l.push({item:h,instance:c,width:0,height:0,
left:0,top:0})},refreshPositions:function(b){this.offsetParent&&this.helper&&(this.offset.parent=this._getParentOffset());var d,e,g;for(d=this.items.length-1;0<=d;d--)e=this.items[d],e.instance!==this.currentContainer&&this.currentContainer&&e.item[0]!==this.currentItem[0]||(g=this.options.toleranceElement?a(this.options.toleranceElement,e.item):e.item,b||(e.width=g.outerWidth(),e.height=g.outerHeight()),g=g.offset(),e.left=g.left,e.top=g.top);if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);
else for(d=this.containers.length-1;0<=d;d--)g=this.containers[d].element.offset(),this.containers[d].containerCache.left=g.left,this.containers[d].containerCache.top=g.top,this.containers[d].containerCache.width=this.containers[d].element.outerWidth(),this.containers[d].containerCache.height=this.containers[d].element.outerHeight();return this},_createPlaceholder:function(b){b=b||this;var d,e=b.options;e.placeholder&&e.placeholder.constructor!==String||(d=e.placeholder,e.placeholder={element:function(){var e=
b.currentItem[0].nodeName.toLowerCase(),h=a("<"+e+">",b.document[0]).addClass(d||b.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper");"tr"===e?b.currentItem.children().each(function(){a("<td>&#160;</td>",b.document[0]).attr("colspan",a(this).attr("colspan")||1).appendTo(h)}):"img"===e&&h.attr("src",b.currentItem.attr("src"));d||h.css("visibility","hidden");return h},update:function(a,h){if(!d||e.forcePlaceholderSize)h.height()||h.height(b.currentItem.innerHeight()-
parseInt(b.currentItem.css("paddingTop")||0,10)-parseInt(b.currentItem.css("paddingBottom")||0,10)),h.width()||h.width(b.currentItem.innerWidth()-parseInt(b.currentItem.css("paddingLeft")||0,10)-parseInt(b.currentItem.css("paddingRight")||0,10))}});b.placeholder=a(e.placeholder.element.call(b.element,b.currentItem));b.currentItem.after(b.placeholder);e.placeholder.update(b,b.placeholder)},_contactContainers:function(c){var d,e,g,h,k,l,m,n,q,p=e=null;for(d=this.containers.length-1;0<=d;d--)a.contains(this.currentItem[0],
this.containers[d].element[0])||(this._intersectsWith(this.containers[d].containerCache)?e&&a.contains(this.containers[d].element[0],e.element[0])||(e=this.containers[d],p=d):this.containers[d].containerCache.over&&(this.containers[d]._trigger("out",c,this._uiHash(this)),this.containers[d].containerCache.over=0));if(e)if(1===this.containers.length)this.containers[p].containerCache.over||(this.containers[p]._trigger("over",c,this._uiHash(this)),this.containers[p].containerCache.over=1);else{d=1E4;
g=null;h=(q=e.floating||b(this.currentItem))?"left":"top";k=q?"width":"height";l=this.positionAbs[h]+this.offset.click[h];for(e=this.items.length-1;0<=e;e--)a.contains(this.containers[p].element[0],this.items[e].item[0])&&this.items[e].item[0]!==this.currentItem[0]&&(!q||this.positionAbs.top+this.offset.click.top>this.items[e].top&&this.positionAbs.top+this.offset.click.top<this.items[e].top+this.items[e].height)&&(m=this.items[e].item.offset()[h],n=!1,Math.abs(m-l)>Math.abs(m+this.items[e][k]-l)&&
(n=!0,m+=this.items[e][k]),Math.abs(m-l)<d&&(d=Math.abs(m-l),g=this.items[e],this.direction=n?"up":"down"));(g||this.options.dropOnEmpty)&&this.currentContainer!==this.containers[p]&&(g?this._rearrange(c,g,null,!0):this._rearrange(c,null,this.containers[p].element,!0),this._trigger("change",c,this._uiHash()),this.containers[p]._trigger("change",c,this._uiHash(this)),this.currentContainer=this.containers[p],this.options.placeholder.update(this.currentContainer,this.placeholder),this.containers[p]._trigger("over",
c,this._uiHash(this)),this.containers[p].containerCache.over=1)}},_createHelper:function(b){var d=this.options;b=a.isFunction(d.helper)?a(d.helper.apply(this.element[0],[b,this.currentItem])):"clone"===d.helper?this.currentItem.clone():this.currentItem;b.parents("body").length||a("parent"!==d.appendTo?d.appendTo:this.currentItem[0].parentNode)[0].appendChild(b[0]);b[0]===this.currentItem[0]&&(this._storedCSS={width:this.currentItem[0].style.width,height:this.currentItem[0].style.height,position:this.currentItem.css("position"),
top:this.currentItem.css("top"),left:this.currentItem.css("left")});b[0].style.width&&!d.forceHelperSize||b.width(this.currentItem.width());b[0].style.height&&!d.forceHelperSize||b.height(this.currentItem.height());return b},_adjustOffsetFromHelper:function(b){"string"===typeof b&&(b=b.split(" "));a.isArray(b)&&(b={left:+b[0],top:+b[1]||0});"left"in b&&(this.offset.click.left=b.left+this.margins.left);"right"in b&&(this.offset.click.left=this.helperProportions.width-b.right+this.margins.left);"top"in
b&&(this.offset.click.top=b.top+this.margins.top);"bottom"in b&&(this.offset.click.top=this.helperProportions.height-b.bottom+this.margins.top)},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var b=this.offsetParent.offset();"absolute"===this.cssPosition&&this.scrollParent[0]!==document&&a.contains(this.scrollParent[0],this.offsetParent[0])&&(b.left+=this.scrollParent.scrollLeft(),b.top+=this.scrollParent.scrollTop());if(this.offsetParent[0]===document.body||this.offsetParent[0].tagName&&
"html"===this.offsetParent[0].tagName.toLowerCase()&&a.ui.ie)b={top:0,left:0};return{top:b.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:b.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)}},_getRelativeOffset:function(){if("relative"===this.cssPosition){var a=this.currentItem.position();return{top:a.top-(parseInt(this.helper.css("top"),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css("left"),10)||0)+this.scrollParent.scrollLeft()}}return{top:0,
left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.currentItem.css("marginLeft"),10)||0,top:parseInt(this.currentItem.css("marginTop"),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var b,d,e;d=this.options;"parent"===d.containment&&(d.containment=this.helper[0].parentNode);if("document"===d.containment||"window"===d.containment)this.containment=[0-this.offset.relative.left-
this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,a("document"===d.containment?document:window).width()-this.helperProportions.width-this.margins.left,(a("document"===d.containment?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];/^(document|window|parent)$/.test(d.containment)||(b=a(d.containment)[0],d=a(d.containment).offset(),e="hidden"!==a(b).css("overflow"),this.containment=[d.left+(parseInt(a(b).css("borderLeftWidth"),
10)||0)+(parseInt(a(b).css("paddingLeft"),10)||0)-this.margins.left,d.top+(parseInt(a(b).css("borderTopWidth"),10)||0)+(parseInt(a(b).css("paddingTop"),10)||0)-this.margins.top,d.left+(e?Math.max(b.scrollWidth,b.offsetWidth):b.offsetWidth)-(parseInt(a(b).css("borderLeftWidth"),10)||0)-(parseInt(a(b).css("paddingRight"),10)||0)-this.helperProportions.width-this.margins.left,d.top+(e?Math.max(b.scrollHeight,b.offsetHeight):b.offsetHeight)-(parseInt(a(b).css("borderTopWidth"),10)||0)-(parseInt(a(b).css("paddingBottom"),
10)||0)-this.helperProportions.height-this.margins.top])},_convertPositionTo:function(b,d){d||(d=this.position);var e="absolute"===b?1:-1,g="absolute"!==this.cssPosition||this.scrollParent[0]!==document&&a.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,h=/(html|body)/i.test(g[0].tagName);return{top:d.top+this.offset.relative.top*e+this.offset.parent.top*e-("fixed"===this.cssPosition?-this.scrollParent.scrollTop():h?0:g.scrollTop())*e,left:d.left+this.offset.relative.left*
e+this.offset.parent.left*e-("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():h?0:g.scrollLeft())*e}},_generatePosition:function(b){var d,e,g=this.options;e=b.pageX;d=b.pageY;var h="absolute"!==this.cssPosition||this.scrollParent[0]!==document&&a.contains(this.scrollParent[0],this.offsetParent[0])?this.scrollParent:this.offsetParent,k=/(html|body)/i.test(h[0].tagName);"relative"!==this.cssPosition||this.scrollParent[0]!==document&&this.scrollParent[0]!==this.offsetParent[0]||(this.offset.relative=
this._getRelativeOffset());this.originalPosition&&(this.containment&&(b.pageX-this.offset.click.left<this.containment[0]&&(e=this.containment[0]+this.offset.click.left),b.pageY-this.offset.click.top<this.containment[1]&&(d=this.containment[1]+this.offset.click.top),b.pageX-this.offset.click.left>this.containment[2]&&(e=this.containment[2]+this.offset.click.left),b.pageY-this.offset.click.top>this.containment[3]&&(d=this.containment[3]+this.offset.click.top)),g.grid&&(d=this.originalPageY+Math.round((d-
this.originalPageY)/g.grid[1])*g.grid[1],d=this.containment?d-this.offset.click.top>=this.containment[1]&&d-this.offset.click.top<=this.containment[3]?d:d-this.offset.click.top>=this.containment[1]?d-g.grid[1]:d+g.grid[1]:d,e=this.originalPageX+Math.round((e-this.originalPageX)/g.grid[0])*g.grid[0],e=this.containment?e-this.offset.click.left>=this.containment[0]&&e-this.offset.click.left<=this.containment[2]?e:e-this.offset.click.left>=this.containment[0]?e-g.grid[0]:e+g.grid[0]:e));return{top:d-
this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():k?0:h.scrollTop()),left:e-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():k?0:h.scrollLeft())}},_rearrange:function(a,b,d,g){d?d[0].appendChild(this.placeholder[0]):b.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?b.item[0]:b.item[0].nextSibling);var h=this.counter=
this.counter?++this.counter:1;this._delay(function(){h===this.counter&&this.refreshPositions(!g)})},_clear:function(a,b){this.reverting=!1;var d,g=[];!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem);this._noFinalSort=null;if(this.helper[0]===this.currentItem[0]){for(d in this._storedCSS)if("auto"===this._storedCSS[d]||"static"===this._storedCSS[d])this._storedCSS[d]="";this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else this.currentItem.show();
this.fromOutside&&!b&&g.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||g.push(function(a){this._trigger("update",a,this._uiHash())});this===this.currentContainer||b||(g.push(function(a){this._trigger("remove",a,this._uiHash())}),g.push(function(a){return function(b){a._trigger("receive",b,this._uiHash(this))}}.call(this,
this.currentContainer)),g.push(function(a){return function(b){a._trigger("update",b,this._uiHash(this))}}.call(this,this.currentContainer)));for(d=this.containers.length-1;0<=d;d--)b||g.push(function(a){return function(b){a._trigger("deactivate",b,this._uiHash(this))}}.call(this,this.containers[d])),this.containers[d].containerCache.over&&(g.push(function(a){return function(b){a._trigger("out",b,this._uiHash(this))}}.call(this,this.containers[d])),this.containers[d].containerCache.over=0);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;if(this.cancelHelperRemoval){if(!b){this._trigger("beforeStop",a,this._uiHash());for(d=0;d<g.length;d++)g[d].call(this,a);this._trigger("stop",a,this._uiHash())}return this.fromOutside=!1}b||this._trigger("beforeStop",a,this._uiHash());
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);this.helper[0]!==this.currentItem[0]&&this.helper.remove();this.helper=null;if(!b){for(d=0;d<g.length;d++)g[d].call(this,a);this._trigger("stop",a,this._uiHash())}this.fromOutside=!1;return!0},_trigger:function(){!1===a.Widget.prototype._trigger.apply(this,arguments)&&this.cancel()},_uiHash:function(b){var d=b||this;return{helper:d.helper,placeholder:d.placeholder||a([]),position:d.position,originalPosition:d.originalPosition,offset:d.positionAbs,
item:d.currentItem,sender:b?b.element:null}}})})(jQuery);(function(a){var d=a({});a.subscribe=function(){d.on.apply(d,arguments)};a.unsubscribe=function(){d.off.apply(d,arguments)};a.publish=function(){d.trigger.apply(d,arguments)}})(jQuery);(function(){var a=$.namespace("pskl.model");a.Frame=function(d,b){if(d&&b)this.width=d,this.height=b,this.pixels=a.Frame.createEmptyPixelGrid_(d,b),this.previousStates=[this.getPixels()],this.stateIndex=0;else throw"Bad arguments in pskl.model.Frame constructor : "+d+", "+b;};a.Frame.fromPixelGrid=function(a){if(a.length&&a[0].length){var b=new pskl.model.Frame(a.length,a[0].length);b.setPixels(a);return b}throw"Bad arguments in pskl.model.Frame.fromPixelGrid : "+a;};a.Frame.createEmptyPixelGrid_=
function(a,b){for(var c=[],f=0;f<a;f++){for(var e=[],g=0;g<b;g++)e.push(Constants.TRANSPARENT_COLOR);c[f]=e}return c};a.Frame.createEmptyFromFrame=function(d){return new a.Frame(d.getWidth(),d.getHeight())};a.Frame.prototype.clone=function(){var d=new a.Frame(this.width,this.height);d.setPixels(this.getPixels());return d};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 d=
a.Frame.createEmptyPixelGrid_(this.getWidth(),this.getHeight());this.setPixels(d)};a.Frame.prototype.clonePixels_=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=a[c].slice(0,a[c].length);return b};a.Frame.prototype.serialize=function(){return JSON.stringify(this.pixels)};a.Frame.prototype.setPixel=function(a,b,c){this.pixels[a][b]=c};a.Frame.prototype.getPixel=function(a,b){return this.pixels[a][b]};a.Frame.prototype.forEachPixel=function(a){for(var b=0;b<this.getWidth();b++)for(var c=0;c<this.getHeight();c++)a(this.getPixel(b,
c),b,c)};a.Frame.prototype.getWidth=function(){return this.width};a.Frame.prototype.getHeight=function(){return this.height};a.Frame.prototype.containsPixel=function(a,b){return 0<=a&&0<=b&&a<this.pixels.length&&b<this.pixels[0].length};a.Frame.prototype.saveState=function(){this.previousStates.length=this.stateIndex+1;this.previousStates.push(this.getPixels());this.stateIndex=this.previousStates.length-1};a.Frame.prototype.loadPreviousState=function(){0<this.stateIndex&&(this.stateIndex--,this.setPixels(this.previousStates[this.stateIndex]))};
a.Frame.prototype.loadNextState=function(){this.stateIndex<this.previousStates.length-1&&(this.stateIndex++,this.setPixels(this.previousStates[this.stateIndex]))};a.Frame.prototype.isSameSize=function(a){return this.getHeight()==a.getHeight()&&this.getWidth()==a.getWidth()}})();(function(){var a=$.namespace("pskl.model");a.Layer=function(a){if(a)this.name=a,this.frames=[];else throw"Invalid arguments in Layer constructor : 'name' is mandatory";};a.Layer.prototype.getName=function(){return this.name};a.Layer.prototype.getFrames=function(){return this.frames};a.Layer.prototype.getFrameAt=function(a){return this.frames[a]};a.Layer.prototype.addFrame=function(a){this.frames.push(a)};a.Layer.prototype.addFrameAt=function(a,b){this.frames.splice(b,0,a)};a.Layer.prototype.removeFrame=
function(a){a=this.frames.indexOf(a);this.removeFrameAt(a)};a.Layer.prototype.removeFrameAt=function(a){if(this.frames[a])this.frames.splice(a,1);else throw"Invalid index in removeFrameAt : "+a+" (size : "+this.length()+")";};a.Layer.prototype.moveFrame=function(a,b){var c=this.frames.splice(a,1)[0];this.frames.splice(b,0,c)};a.Layer.prototype.swapFramesAt=function(a,b){var c=this.frames[a],f=this.frames[b];if(c&&f)this.frames[b]=c,this.frames[a]=f;else throw console.log("frames",this.frames),console.log("fromIndex",
a,"toIndex",b),"Frame not found in moveFrameAt";};a.Layer.prototype.duplicateFrame=function(a){this.frames.indexOf(a);this.duplicateFrameAt()};a.Layer.prototype.duplicateFrameAt=function(a){var b=this.frames[a];if(b)b=b.clone(),this.addFrameAt(b,a);else throw"Frame not found in duplicateFrameAt";};a.Layer.prototype.length=function(){return this.frames.length}})();(function(){var a=$.namespace("pskl.model");a.Piskel=function(a,b){if(a&&b)this.layers=[],this.width=a,this.height=b;else throw"Missing arguments in Piskel constructor : "+Array.prototype.join.call(arguments,",");};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);-1<b&&b<this.layers.length-1&&(this.layers[b]=this.layers[b+1],this.layers[b+1]=a)};a.Piskel.prototype.moveLayerDown=function(a){var b=this.layers.indexOf(a);0<b&&(this.layers[b]=this.layers[b-1],this.layers[b-1]=a)};a.Piskel.prototype.removeLayer=function(a){a=
this.layers.indexOf(a);-1!=a&&this.layers.splice(a,1)};a.Piskel.prototype.removeLayerAt=function(a){this.layers.splice(a,1)}})();(function(){var a=$.namespace("pskl.rendering");a.CanvasRenderer=function(a,b){this.frame=a;this.dpi=b;this.transparentColor_="white"};a.CanvasRenderer.prototype.drawTransparentAs=function(a){this.transparentColor_=a};a.CanvasRenderer.prototype.render=function(){for(var a=this.createCanvas_().getContext("2d"),b=0,c=this.frame.getWidth();b<c;b++)for(var f=0,e=this.frame.getHeight();f<e;f++){var g=this.frame.getPixel(b,f);this.renderPixel_(g,b,f,a)}return a};a.CanvasRenderer.prototype.renderPixel_=
function(a,b,c,f){a==Constants.TRANSPARENT_COLOR&&(a=this.transparentColor_);f.fillStyle=a;f.fillRect(b*this.dpi,c*this.dpi,this.dpi,this.dpi)};a.CanvasRenderer.prototype.createCanvas_=function(){var a=this.frame.getWidth()*this.dpi,b=this.frame.getHeight()*this.dpi;return pskl.CanvasUtils.createCanvas(a,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){a={fn:a,scope:b,args:c};this.callbacks.push(a);return a};a.DrawingLoop.prototype.removeCallback=function(a){a=this.callbacks.indexOf(a);-1!=a&&this.callbacks.splice(a,1)};a.DrawingLoop.prototype.start=function(){this.isRunning=!0;this.loop_()};a.DrawingLoop.prototype.loop_=
function(){var a=Date.now();this.executeCallbacks_(a-this.previousTime);this.previousTime=a;this.requestAnimationFrame.call(window,this.loop_.bind(this))};a.DrawingLoop.prototype.executeCallbacks_=function(a){for(var b=0;b<this.callbacks.length;b++){var c=this.callbacks[b];c.fn.call(c.scope,a,c.args)}};a.DrawingLoop.prototype.stop=function(){this.isRunning=!1};a.DrawingLoop.prototype.getRequestAnimationFrameShim_=function(){return window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||
window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}})();(function(){var a=$.namespace("pskl.rendering");a.FrameRenderer=function(a,b,c){this.defaultRenderingOptions={supportGridRendering:!1};b=$.extend(!0,{},this.defaultRenderingOptions,b);if(void 0===a)throw"Bad FrameRenderer initialization. <container> undefined.";if(isNaN(b.dpi))throw"Bad FrameRenderer initialization. <dpi> not well defined.";this.container=a;this.dpi=b.dpi;this.supportGridRendering=b.supportGridRendering;this.classes=c||[];this.classes.push("canvas");this.canvas=null;this.enableGrid(pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID));
this.canvasConfigDirty=!0;this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));$.subscribe(Events.USER_SETTINGS_CHANGED,$.proxy(this.onUserSettingsChange_,this))};a.FrameRenderer.prototype.setDPI=function(a){this.dpi=a;this.canvasConfigDirty=!0};a.FrameRenderer.prototype.onUserSettingsChange_=function(a,b,c){b==pskl.UserSettings.SHOW_GRID?this.enableGrid(c):b==pskl.UserSettings.CANVAS_BACKGROUND&&this.updateBackgroundClass_(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.enableGrid=function(a){this.gridStrokeWidth=a&&this.supportGridRendering?Constants.GRID_STROKE_WIDTH:0;this.canvasConfigDirty=!0};a.FrameRenderer.prototype.render=function(a){if(a){this.clear();for(var b=this.getCanvas_(a).getContext("2d"),c=0,f=a.getWidth();c<f;c++)for(var e=0,g=a.getHeight();e<g;e++){var h=
a.getPixel(c,e);this.renderPixel_(h,c,e,b)}this.lastRenderedFrame=a}};a.FrameRenderer.prototype.renderPixel_=function(a,b,c,f){a!=Constants.TRANSPARENT_COLOR&&(f.fillStyle=a,f.fillRect(this.getFramePos_(b),this.getFramePos_(c),this.dpi,this.dpi))};a.FrameRenderer.prototype.clear=function(){this.canvas&&this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height)};a.FrameRenderer.prototype.convertPixelCoordinatesIntoSpriteCoordinate=function(a){var b=this.dpi+this.gridStrokeWidth;
return{col:(a.x-a.x%b)/b,row:(a.y-a.y%b)/b}};a.FrameRenderer.prototype.getFramePos_=function(a){return a*this.dpi+(a-1)*this.gridStrokeWidth};a.FrameRenderer.prototype.getCanvas_=function(a){if(this.canvasConfigDirty){$(this.canvas).remove();var b=a.getWidth();a=a.getHeight();b=pskl.CanvasUtils.createCanvas(b*this.dpi+this.gridStrokeWidth*(b-1),a*this.dpi+this.gridStrokeWidth*(a-1),this.classes);this.container.append(b);this.canvas=b;this.canvasConfigDirty=!1}return this.canvas}})();(function(){var a=$.namespace("pskl.rendering");a.SpritesheetRenderer=function(a){this.piskelController=a};a.SpritesheetRenderer.prototype.render=function(){for(var a=this.createCanvas_(),b=0;b<this.piskelController.getFrameCount();b++){var c=this.piskelController.getFrameAt(b);this.drawFrameInCanvas_(c,a,b*this.piskelController.getWidth(),0)}return a};a.SpritesheetRenderer.prototype.drawFrameInCanvas_=function(a,b,c,f){b=b.getContext("2d");for(var e=0,g=a.getWidth();e<g;e++)for(var h=0,k=a.getHeight();h<
k;h++){var l=a.getPixel(e,h);l!=Constants.TRANSPARENT_COLOR&&(b.fillStyle=l,b.fillRect(e+c,h+f,1,1))}};a.SpritesheetRenderer.prototype.createCanvas_=function(){var a=this.piskelController.getFrameCount();if(0<a){var a=a*this.piskelController.getWidth(),b=this.piskelController.getHeight();return pskl.CanvasUtils.createCanvas(a,b)}throw"Cannot render empty Spritesheet";}})();(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,f=[],e=0,g=this.pixels.length;e<g;e++)c=this.pixels[e],c.col+=a,c.row+=b,f.push(c);this.pixels=f};a.BaseSelection.prototype.fillSelectionFromFrame=function(a){for(var b,c=0,f=this.pixels.length;c<f;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,f){this.pixels=pskl.PixelUtils.getRectanglePixels(a,b,c,f)};pskl.utils.inherit(a.RectangularSelection,a.BaseSelection)})();(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));$.subscribe(Events.PASTE,$.proxy(this.onPaste_,this));$.subscribe(Events.COPY,$.proxy(this.onCopy_,
this));$.subscribe(Events.CUT,$.proxy(this.onCut_,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){b instanceof pskl.drawingtools.BaseSelect||this.cleanSelection_()};a.SelectionManager.prototype.onSelectionDismissed_=function(a){this.cleanSelection_()};a.SelectionManager.prototype.onCut_=function(a){if(this.currentSelection){this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame());
a=this.currentSelection.pixels;for(var b=this.piskelController.getCurrentFrame(),c=0,f=a.length;c<f;c++)try{b.setPixel(a[c].col,a[c].row,Constants.TRANSPARENT_COLOR)}catch(e){}}else throw"Bad state for CUT callback in SelectionManager";};a.SelectionManager.prototype.onPaste_=function(a){if(this.currentSelection&&this.currentSelection.hasPastedContent){a=this.currentSelection.pixels;for(var b=this.piskelController.getCurrentFrame(),c=0,f=a.length;c<f;c++)try{b.setPixel(a[c].col,a[c].row,a[c].copiedColor)}catch(e){}}};
a.SelectionManager.prototype.onCopy_=function(a){if(this.currentSelection&&this.piskelController.getCurrentFrame())this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame());else throw"Bad state for CUT callback in SelectionManager";};a.SelectionManager.prototype.onSelectionCreated_=function(a,b){if(b)this.currentSelection=b;else throw"No selection set in SelectionManager";};a.SelectionManager.prototype.onSelectionMoved_=function(a,b,c){if(this.currentSelection)this.currentSelection.move(b,
c);else throw"Bad state: No currentSelection set when trying to move it in SelectionManager";}})();(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.service");a.HistoryService=function(a){this.piskelController=a};a.HistoryService.prototype.init=function(){$.subscribe(Events.TOOL_RELEASED,this.saveState.bind(this));$.subscribe(Events.UNDO,this.undo.bind(this));$.subscribe(Events.REDO,this.redo.bind(this))};a.HistoryService.prototype.saveState=function(){this.piskelController.getCurrentFrame().saveState()};a.HistoryService.prototype.undo=function(){this.piskelController.getCurrentFrame().loadPreviousState();$.publish(Events.PISKEL_RESET)};
a.HistoryService.prototype.redo=function(){this.piskelController.getCurrentFrame().loadNextState();$.publish(Events.PISKEL_RESET)}})();(function(){var a=$.namespace("pskl.service");a.ImageUploadService=function(){};a.ImageUploadService.prototype.init=function(){};a.ImageUploadService.prototype.upload=function(a,b,c){var f=new XMLHttpRequest,e=new FormData;e.append("data",a);f.open("POST",Constants.IMAGE_SERVICE_UPLOAD_URL,!0);f.onload=function(a){200==this.status?b(Constants.IMAGE_SERVICE_GET_URL+this.responseText):c()};f.send(e)}})();(function(){var a=$.namespace("pskl.service");a.KeyboardEventService=function(){};a.KeyboardEventService.prototype.KeyboardActions_={ctrl:{z:Events.UNDO,y:Events.REDO,x:Events.CUT,c:Events.COPY,v:Events.PASTE}};a.KeyboardEventService.prototype.CharCodeToKeyCodeMap_={90:"z",89:"y",88:"x",67:"c",86:"v"};a.KeyboardEventService.prototype.onKeyUp_=function(a){var b=!1;-1!=navigator.appVersion.indexOf("Mac")&&(b=!0);if(b?a.metaKey:a.ctrlKey)if(b=this.CharCodeToKeyCodeMap_[a.which])if(b=this.KeyboardActions_.ctrl[b])return $.publish(b),
a.preventDefault(),!1};a.KeyboardEventService.prototype.init=function(){$(document.body).keydown($.proxy(this.onKeyUp_,this))}})();(function(){var a=$.namespace("pskl.service");a.LocalStorageService=function(a){if(void 0===a)throw"Bad LocalStorageService initialization: <undefined piskelController>";this.piskelController=a;this.localStorageThrottler_=null};a.LocalStorageService.prototype.init=function(a){$.subscribe(Events.LOCALSTORAGE_REQUEST,$.proxy(this.persistToLocalStorageRequest_,this))};a.LocalStorageService.prototype.persistToLocalStorageRequest_=function(){null!==this.localStorageThrottler_&&window.clearTimeout(this.localStorageThrottler_);
this.localStorageThrottler_=window.setTimeout($.proxy(function(){this.persistToLocalStorage_();this.localStorageThrottler_=null},this),1E3)};a.LocalStorageService.prototype.persistToLocalStorage_=function(){console.log("[LocalStorage service]: Snapshot stored");window.localStorage.snapShot=this.piskelController.serialize()};a.LocalStorageService.prototype.restoreFromLocalStorage_=function(){this.piskelController.deserialize(window.localStorage.snapShot);this.piskelController.setCurrentFrameIndex(0)};
a.LocalStorageService.prototype.cleanLocalStorage_=function(){console.log("[LocalStorage service]: Snapshot removed");delete window.localStorage.snapShot};a.LocalStorageService.prototype.displayRestoreNotification=function(){window.localStorage&&window.localStorage.snapShot&&$.publish(Events.SHOW_NOTIFICATION,[{content:"Non saved version found. <a href='#' class='localstorage-restore onclick='pskl.app.restoreFromLocalStorage()'>reload</a> or <a href='#' class='localstorage-discard' onclick='pskl.app.cleanLocalStorage()'>discard</a>",
behavior:$.proxy(function(a){a=$(a);a.click($.proxy(function(a){a=$(a.target);a.hasClass("localstorage-restore")?this.restoreFromLocalStorage_():a.hasClass("localstorage-discard")&&this.cleanLocalStorage_();$.publish(Events.HIDE_NOTIFICATION)},this))},this)}])}})();(function(){$.namespace("pskl").CanvasUtils={createCanvas:function(a,d,b){var c=document.createElement("canvas");c.setAttribute("width",a);c.setAttribute("height",d);"string"==typeof b&&(b=[b]);if(Array.isArray(b))for(a=0;a<b.length;a++)c.classList.add(b[a]);return c}}})();(function(){$.namespace("pskl.utils").FileUtils={readFile:function(a,d){var b=new FileReader;b.onload=function(a){d(a.target.result)};b.readAsDataURL(a)}}})();(function(){$.namespace("pskl.utils").FrameUtils={merge:function(a){var d=null;if(a.length){d=a[0].clone();d.getWidth();d.getHeight();for(var b=1;b<a.length;b++)pskl.utils.FrameUtils.mergeFrames_(d,a[b])}return d},mergeFrames_:function(a,d){d.forEachPixel(function(b,c,d){b!=Constants.TRANSPARENT_COLOR&&a.setPixel(c,d,b)})},createFromImage:function(a){var d=a.width,b=a.height,c=pskl.CanvasUtils.createCanvas(d,b).getContext("2d");c.drawImage(a,0,0,d,b,0,0,d,b);d=c.getImageData(0,0,d,b).data;b=[];for(c=
0;c<a.width;++c){b[c]=[];for(var f=0;f<a.height;++f){var e=4*(f*a.width+c),g=d[e],h=d[e+1],k=d[e+2];b[c][f]=125>d[e+3]?"TRANSPARENT":this.rgbToHex(g,h,k)}}return b},rgbToHex:function(a,d,b){return"#"+this.componentToHex(a)+this.componentToHex(d)+this.componentToHex(b)},componentToHex:function(a){a=a.toString(16);return 1==a.length?"0"+a:a}}})();(function(){$.namespace("pskl.utils").ImageResizer={resize:function(a,d,b,c){var f=pskl.CanvasUtils.createCanvas(d,b),e=f.getContext("2d");e.save();c||this.disableSmoothingOnContext(e);e.translate(f.width/2,f.height/2);e.scale(d/a.width,b/a.height);e.drawImage(a,-a.width/2,-a.height/2);e.restore();return f},disableSmoothingOnContext:function(a){a.imageSmoothingEnabled=!1;a.mozImageSmoothingEnabled=!1;a.oImageSmoothingEnabled=!1;a.webkitImageSmoothingEnabled=!1;a.msImageSmoothingEnabled=!1}}})();(function(){$.namespace("pskl").PixelUtils={getRectanglePixels:function(a,d,b,c){a=this.getOrderedRectangleCoordinates(a,d,b,c);d=[];for(b=a.x0;b<=a.x1;b++)for(c=a.y0;c<=a.y1;c++)d.push({col:b,row:c});return d},getBoundRectanglePixels:function(a,d,b,c){a=this.getOrderedRectangleCoordinates(a,d,b,c);d=[];for(b=a.x0;b<=a.x1;b++)d.push({col:b,row:a.y0}),d.push({col:b,row:a.y1});for(b=a.y0;b<=a.y1;b++)d.push({col:a.x0,row:b}),d.push({col:a.x1,row:b});return d},getOrderedRectangleCoordinates:function(a,
d,b,c){return{x0:Math.min(a,b),y0:Math.min(d,c),x1:Math.max(a,b),y1:Math.max(d,c)}},getSimilarConnectedPixelsFromFrame:function(a,d,b){a=a.clone();return this.paintSimilarConnectedPixelsFromFrame(a,d,b,"sdfsdfsdf")},paintSimilarConnectedPixelsFromFrame:function(a,d,b,c){var f=[],e=[],g=[-1,0,1,0],h=[0,1,0,-1],k;try{k=a.getPixel(d,b)}catch(l){}if(k!=c){e.push({col:d,row:b});d=0;for(b=a.getWidth()*a.getHeight();0<e.length;){d++;var m=e.pop();a.setPixel(m.col,m.row,c);f.push({col:m.col,row:m.row});for(var n=
0;4>n;n++){var q=m.col+h[n],p=m.row+g[n];try{a.containsPixel(q,p)&&a.getPixel(q,p)==k&&e.push({col:q,row:p})}catch(r){}}if(d>10*b){console.log("loop breaker called");break}}return f}},calculateDPIForContainer:function(a,d,b){return this.calculateDPI(a.height(),a.width(),d,b)},calculateDPI:function(a,d,b,c){return Math.min(Math.floor(a/b),Math.floor(d/c))}}})();(function(){$.namespace("pskl.utils").Serializer={serializePiskel:function(a){var d=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:d}})},serializeLayer:function(a){var d=a.getFrames().map(function(a){return a.serialize()});return JSON.stringify({name:a.getName(),frames:d})},deserializePiskel:function(a){a=JSON.parse(a);return this.createPiskelFromData(a)},
createPiskel:function(a){var d=null;a.modelVersion==Constants.MODEL_VERSION?(a=a.piskel,d=new pskl.model.Piskel(a.width,a.height),a.layers.forEach(function(a){a=pskl.utils.Serializer.deserializeLayer(a);d.addLayer(a)})):d=pskl.utils.Serializer.backwardDeserializer_(a);return d},deserializeLayer:function(a){a=JSON.parse(a);var d=new pskl.model.Layer(a.name);a.frames.forEach(function(a){a=pskl.utils.Serializer.deserializeFrame(a);d.addFrame(a)});return d},deserializeFrame:function(a){a=JSON.parse(a);
return pskl.model.Frame.fromPixelGrid(a)},backwardDeserializer_:function(a){var d=new pskl.model.Layer("Layer 1");a.forEach(function(a){d.addFrame(pskl.model.Frame.fromPixelGrid(a))});a=d.getFrameAt(0).getWidth();var b=d.getFrameAt(0).getHeight();a=new pskl.model.Piskel(a,b);a.addLayer(d);return a}}})();(function(){$.namespace("pskl.utils").Template={get:function(a){var d=document.getElementById(a);if(d)return d.innerHTML;console.error("Could not find template for id :",a)},createFromHTML:function(a){var d=document.createElement("div");d.innerHTML=a;return d.children[0]},replace:function(a,d){for(var b in d)d.hasOwnProperty(b)&&(a=a.replace(RegExp("\\{\\{"+b+"\\}\\}","g"),d[b]));return a}}})();(function(){$.namespace("pskl").UserSettings={SHOW_GRID:"SHOW_GRID",CANVAS_BACKGROUND:"CANVAS_BACKGROUND",KEY_TO_DEFAULT_VALUE_MAP_:{SHOW_GRID:!1,CANVAS_BACKGROUND:"medium-canvas-background"},cache_:{},get:function(a){this.checkKeyValidity_(a);a in this.cache_||(this.cache_[a]=this.readFromLocalStorage_(a)||this.readFromDefaults_(a));return this.cache_[a]},set:function(a,d){this.checkKeyValidity_(a);this.cache_[a]=d;this.writeToLocalStorage_(a,d);$.publish(Events.USER_SETTINGS_CHANGED,[a,d])},readFromLocalStorage_:function(a){a=
window.localStorage[a];"undefined"!=typeof a&&(a=JSON.parse(a));return a},writeToLocalStorage_:function(a,d){window.localStorage[a]=JSON.stringify(d)},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.")}}})();jQuery.namespace=function(){var a=arguments,d=null,b,c,f;for(b=0;b<a.length;b+=1)for(f=a[b].split("."),d=window,c=0;c<f.length;c+=1)d[f[c]]=d[f[c]]||{},d=d[f[c]];return d};"function"!==typeof Function.prototype.bind&&(Function.prototype.bind=function(a){var d=this;return function(){return d.apply(a,arguments)}});
(function(){var a=$.namespace("pskl.utils");a.rgbToHex=function(a,b,c){if(255<a||255<b||255<c)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=function(a,b){var c=window.document.createElement("script");c.setAttribute("src",a);c.setAttribute("onload",b);window.document.body.appendChild(c)};if(-1!=window.location.href.indexOf("debug")){window.exports={};var d=0;window.loadNextScript=function(){d==window.exports.scripts.length?(pskl.app.init(),delete window.exports,delete window.loadDebugScripts,delete window.done):(a(window.exports.scripts[d],"loadNextScript()"),d++)};a("piskel-script-list.js","loadNextScript()")}else{var b;
b=-1!=window.location.href.indexOf("pack")?"build/piskel-packaged.js":"build/piskel-packaged-min.js";var c=window.setInterval(function(){0===document.querySelectorAll("._ctl").length?(window.clearInterval(c),a(b,"pskl.app.init()")):console.log("waiting for templates to load ....")},100)}})();exports.scripts="js/lib/jquery-1.8.0.js js/lib/jquery-ui-1.10.3.custom.js js/lib/pubsub.js js/lib/bootstrap/bootstrap.js js/lib/gif/gif.worker.js js/lib/gif/gif.js js/Constants.js js/Events.js js/utils/core.js js/utils/CanvasUtils.js js/utils/FileUtils.js js/utils/FrameUtils.js js/utils/ImageResizer.js js/utils/PixelUtils.js js/utils/Serializer.js js/utils/Template.js js/utils/UserSettings.js js/lib/jsColor_1_4_0/jscolor.js js/rendering/DrawingLoop.js js/model/Frame.js js/model/Layer.js js/model/Piskel.js js/selection/SelectionManager.js js/selection/BaseSelection.js js/selection/RectangularSelection.js js/selection/ShapeSelection.js js/rendering/CanvasRenderer.js js/rendering/FrameRenderer.js js/rendering/SpritesheetRenderer.js js/controller/PiskelController.js js/controller/DrawingController.js js/controller/PreviewFilmController.js js/controller/LayersListController.js js/controller/AnimatedPreviewController.js js/controller/ToolController.js js/controller/PaletteController.js js/controller/NotificationController.js js/controller/settings/ApplicationSettingsController.js js/controller/settings/GifExportController.js js/controller/settings/ImportController.js js/controller/settings/SettingsController.js js/service/LocalStorageService.js js/service/HistoryService.js js/service/KeyboardEventService.js js/service/ImageUploadService.js js/drawingtools/BaseTool.js js/drawingtools/SimplePen.js js/drawingtools/VerticalMirrorPen.js js/drawingtools/Eraser.js js/drawingtools/Stroke.js js/drawingtools/PaintBucket.js js/drawingtools/Rectangle.js js/drawingtools/Circle.js js/drawingtools/Move.js js/drawingtools/selectiontools/BaseSelect.js js/drawingtools/selectiontools/RectangleSelect.js js/drawingtools/selectiontools/ShapeSelect.js js/drawingtools/ColorPicker.js js/app.js".split(" ");