fixed merge

This commit is contained in:
Sam Keddy 2020-04-15 00:10:21 +00:00
commit f3ce09ac5a
45 changed files with 5409 additions and 4199 deletions

34
.eslintrc.json Normal file
View File

@ -0,0 +1,34 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}

106
build.js
View File

@ -1,28 +1,25 @@
var fs = require('fs-extra'); const fs = require('fs');
var hbs = require('handlebars'); const path = require('path');
var glob = require("glob"); const gulp = require('gulp');
var sass = require("sass"); const include = require('gulp-include');
var path = require("path"); const hb = require('gulp-hb');
var gulp = require('gulp'); const sass = require('gulp-sass');
var include = require('gulp-include'); const rename = require('gulp-rename');
const BUILDDIR = './build'; const hb_svg = require('handlebars-helper-svg');
const BUILDDIR = process.argv[2] || './build/';
const SLUG = 'pixel-editor'; const SLUG = 'pixel-editor';
console.log('Building Pixel Editor'); console.log('Building Pixel Editor');
hbs.registerHelper('svg', require('handlebars-helper-svg'));
require('hbs-register-helpers')(hbs,'./_ext/modules/hbs/helpers/**/*.js');
require('hbs-register-partials')(hbs,'./_ext/modules/hbs/_*.hbs');
//empty the build folder, or create it function copy_images(){
fs.emptyDirSync(BUILDDIR); gulp.src('./images/')
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
function render_js(){
//copy images
fs.copySync('./images','./build/'+SLUG);
//render js
gulp.src('./js/*.js') gulp.src('./js/*.js')
.pipe(include({includePaths: [ .pipe(include({includePaths: [
'_ext/scripts', '_ext/scripts',
@ -30,64 +27,33 @@ gulp.src('./js/*.js')
'!js/_*.js', '!js/_*.js',
]})) ]}))
.on('error', console.log) .on('error', console.log)
.pipe(gulp.dest('build/'+SLUG)); .pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
//render css function render_css(){
var sassFiles = glob.sync('css/*.scss'); gulp.src('css/*.scss')
.pipe(sass({includePaths: ['css', '_ext/sass', '_ext/modules/css']}))
.pipe(gulp.dest(path.join(BUILDDIR, SLUG)));
}
sassFiles.forEach((s) => { function compile_page(){
gulp.src(path.join('./views/', SLUG + '.hbs'))
var f = sass.renderSync({file: s, outFile: 'test.css', includePaths: ['css', '_ext/sass', '_ext/modules/css']}); .pipe(hb({encoding: 'utf8'})
.partials('./_ext/modules/_*.hbs')
console.log('compiling:',path.basename(f.stats.entry)) .helpers({ svg: hb_svg })
fs.writeFileSync('build/'+SLUG+'/'+path.basename(f.stats.entry,'scss')+'css', f.css); .helpers('./_ext/modules/hbs/helpers/**/*.js')
}); .data({
//compile page
var pageTemplate = hbs.compile(fs.readFileSync('./views/'+SLUG+'.hbs',{encoding: 'utf8'}));
var page = pageTemplate({
projectSlug: SLUG, projectSlug: SLUG,
title: 'Lospec Pixel Editor', title: 'Lospec Pixel Editor',
layout: false, layout: false,
}); }))
.pipe(rename('index.htm'))
//save output .pipe(gulp.dest(BUILDDIR));
fs.writeFileSync('./build/index.htm',page);
//server
const express = require('express');
const app = express();
//ROUTE - index.htm
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname+'/build/index.htm'), {}, function (err) {
if (err) console.log('error sending file',err);
else {
setTimeout(()=>{
console.log('closing server')
server.close();
process.exit();
},1000*10);
} }
});
});
//ROUTE - other files
app.use(express.static(path.join(__dirname, 'build')));
//start server
var server = app.listen(3000, () => {
console.log('\nTemp server started at http://localhost:3000!');
//console.log('press ctrl+c to stop ');
var opn = require('opn');
// opens the url in the default browser
opn('http://localhost:3000');
}); // empty the build folder, or create it
fs.rmdirSync(BUILDDIR, { recursive: true });
fs.mkdirSync(BUILDDIR);
gulp.parallel(copy_images, render_js, render_css, compile_page)();

34
js/.eslintrc.json Normal file
View File

@ -0,0 +1,34 @@
{
"env": {
"browser": true,
"es6": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}

View File

@ -8,13 +8,13 @@ function addColor (newColor) {
newColor = '#' + newColor; newColor = '#' + newColor;
//create list item //create list item
var listItem = document.createElement("li"); var listItem = document.createElement('li');
//create button //create button
var button = document.createElement("button"); var button = document.createElement('button');
button.classList.add("color-button"); button.classList.add('color-button');
button.style.backgroundColor = newColor; button.style.backgroundColor = newColor;
button.addEventListener("mouseup", clickedColor); button.addEventListener('mouseup', clickedColor);
listItem.appendChild(button); listItem.appendChild(button);
/* /*

View File

@ -7,15 +7,15 @@ on('click', 'add-color-button', function(){
background: #3c4cc2; background: #3c4cc2;
`; `;
var colorIsUnique = true var colorIsUnique = true;
do { do {
//console.log('%cchecking for unique colors', colorCheckingStyle) //console.log('%cchecking for unique colors', colorCheckingStyle)
//generate random color //generate random color
var hue = Math.floor(Math.random()*255); var hue = Math.floor(Math.random()*255);
var sat = 130+Math.floor(Math.random()*100); var sat = 130+Math.floor(Math.random()*100);
var lit = 70+Math.floor(Math.random()*100); var lit = 70+Math.floor(Math.random()*100);
var newColorRgb = hslToRgb(hue,sat,lit) var newColorRgb = hslToRgb(hue,sat,lit);
var newColor = rgbToHex(newColorRgb.r,newColorRgb.g,newColorRgb.b) var newColor = rgbToHex(newColorRgb.r,newColorRgb.g,newColorRgb.b);
var newColorHex = newColor; var newColorHex = newColor;
@ -39,7 +39,7 @@ on('click', 'add-color-button', function(){
while (colorIsUnique == false); while (colorIsUnique == false);
//remove current color selection //remove current color selection
document.querySelector("#colors-menu li.selected").classList.remove("selected"); document.querySelector('#colors-menu li.selected').classList.remove('selected');
//add new color and make it selected //add new color and make it selected
var addedColor = addColor(newColor); var addedColor = addColor(newColor);
@ -52,7 +52,7 @@ on('click', 'add-color-button', function(){
//show color picker //show color picker
addedColor.firstElementChild.jscolor.show(); addedColor.firstElementChild.jscolor.show();
console.log("showing picker"); console.log('showing picker');
//hide edit button //hide edit button
addedColor.lastChild.classList.add('hidden'); addedColor.lastChild.classList.add('hidden');

View File

@ -1,26 +0,0 @@
function changeTool (newToolName) {
console.log('changing tool to',newToolName)
var selectedTool = tool[newToolName];
// Ending any selection in progress
if (currentTool.name.includes("select") && !selectedTool.name.includes("select") && !selectionCanceled) {
endSelection();
}
//set tool and temp tje tje tpp;
currentTool = selectedTool;
currentToolTemp = selectedTool;
var tools = document.getElementById("tools-menu").children;
for (var i = 0; i < tools.length; i++) {
tools[i].classList.remove("selected");
}
//give the button of the selected tool the .selected class
document.getElementById(selectedTool.name+"-button").parentNode.classList.add("selected");
//change cursor
currentTool.updateCursor();
}

View File

@ -1,4 +1,3 @@
function changeZoom (layer, direction, cursorLocation) { function changeZoom (layer, direction, cursorLocation) {
var oldWidth = canvasSize[0] * zoom; var oldWidth = canvasSize[0] * zoom;
var oldHeight = canvasSize[1] * zoom; var oldHeight = canvasSize[1] * zoom;

View File

@ -1,11 +1,10 @@
/////=include libraries/bowser.js /////=include libraries/bowser.js
function closeCompatibilityWarning () { function closeCompatibilityWarning () {
document.getElementById('compatibility-warning').style.visibility = 'hidden'; document.getElementById('compatibility-warning').style.visibility = 'hidden';
} }
console.log('checking compatibility') console.log('checking compatibility');
//check browser/version //check browser/version
if ((bowser.msie && bowser.version < 11) || if ((bowser.msie && bowser.version < 11) ||
@ -17,4 +16,4 @@ if ( (bowser.msie && bowser.version < 11) ||
//show warning //show warning
document.getElementById('compatibility-warning').style.visibility = 'visible'; document.getElementById('compatibility-warning').style.visibility = 'visible';
else alert(bowser.name+' '+bowser.version+' is fine!') else alert(bowser.name+' '+bowser.version+' is fine!');

View File

@ -3,10 +3,9 @@ function clickedColor (e){
//left clicked color //left clicked color
if (e.which == 1) { if (e.which == 1) {
// remove current color selection // remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected") var selectedColor = document.querySelector('#colors-menu li.selected');
if (selectedColor) selectedColor.classList.remove("selected"); if (selectedColor) selectedColor.classList.remove('selected');
//set current color //set current color
currentLayer.context.fillStyle = this.style.backgroundColor; currentLayer.context.fillStyle = this.style.backgroundColor;
@ -15,16 +14,14 @@ function clickedColor (e){
//make color selected //make color selected
e.target.parentElement.classList.add('selected'); e.target.parentElement.classList.add('selected');
//right clicked color } else if (e.which == 3) { //right clicked color
} else if (e.which == 3) { console.log('right clicked color button');
console.log('right clicked color button')
//hide edit color button (to prevent it from showing) //hide edit color button (to prevent it from showing)
e.target.parentElement.lastChild.classList.add('hidden'); e.target.parentElement.lastChild.classList.add('hidden');
//show color picker //show color picker
e.target.jscolor.show(); e.target.jscolor.show();
} }
} }

View File

@ -18,7 +18,7 @@ on('input', 'jscolor-hex-input', function (e) {
currentlyEditedColor.firstChild.jscolor.fromString(newColorHex); currentlyEditedColor.firstChild.jscolor.fromString(newColorHex);
colorChanged(e); colorChanged(e);
}) });
//changes all of one color to another after being changed from color picker //changes all of one color to another after being changed from color picker
@ -34,11 +34,11 @@ function colorChanged(e) {
//get the currently selected color //get the currently selected color
var currentlyEditedColor = document.getElementsByClassName('jscolor-active')[0]; var currentlyEditedColor = document.getElementsByClassName('jscolor-active')[0];
var duplicateColorWarning = document.getElementById("duplicate-color-warning"); var duplicateColorWarning = document.getElementById('duplicate-color-warning');
//check if selected color already matches another color //check if selected color already matches another color
colors = document.getElementsByClassName('color-button'); colors = document.getElementsByClassName('color-button');
var colorCheckingStyle = "background: #bc60c4; color: white" var colorCheckingStyle = 'background: #bc60c4; color: white';
var newColorHex = e.target.value.toLowerCase(); var newColorHex = e.target.value.toLowerCase();
//if the color is not a valid hex color, exit this function and do nothing //if the color is not a valid hex color, exit this function and do nothing
@ -54,7 +54,7 @@ function colorChanged(e) {
//if the color isnt the one that has the picker currently open //if the color isnt the one that has the picker currently open
if (!colors[i].parentElement.classList.contains('jscolor-active')) { if (!colors[i].parentElement.classList.contains('jscolor-active')) {
//console.log('%cColor is duplicate', colorCheckingStyle) // console.log('%cColor is duplicate', colorCheckingStyle);
//show the duplicate color warning //show the duplicate color warning
duplicateColorWarning.style.visibility = 'visible'; duplicateColorWarning.style.visibility = 'visible';
@ -73,7 +73,7 @@ function colorChanged(e) {
//if the color being edited has a duplicate color warning, remove it //if the color being edited has a duplicate color warning, remove it
duplicateColorWarning.style.visibility = 'hidden'; duplicateColorWarning.style.visibility = 'hidden';
currentlyEditedColor.firstChild.jscolor.fromString(newColorHex) currentlyEditedColor.firstChild.jscolor.fromString(newColorHex);
replaceAllOfColor(oldColor, newColor); replaceAllOfColor(oldColor, newColor);

View File

@ -1,4 +1,3 @@
on('click', 'create-button', function (){ on('click', 'create-button', function (){
var width = getValue('size-width'); var width = getValue('size-width');
var height = getValue('size-height'); var height = getValue('size-height');

View File

@ -23,8 +23,8 @@ function createColorPalette(selectedPalette, fillBackground) {
if (newColorHex.r + newColorHex.g + newColorHex.b < darkestColorHex.r + darkestColorHex.g + darkestColorHex.b) { if (newColorHex.r + newColorHex.g + newColorHex.b < darkestColorHex.r + darkestColorHex.g + darkestColorHex.b) {
//remove current color selection //remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected") var selectedColor = document.querySelector('#colors-menu li.selected');
if (selectedColor) selectedColor.classList.remove("selected"); if (selectedColor) selectedColor.classList.remove('selected');
//set as current color //set as current color
newColorElement.classList.add('selected'); newColorElement.classList.add('selected');

View File

@ -9,16 +9,16 @@ function deleteColor (color) {
//if color is a string, then find the corresponding button //if color is a string, then find the corresponding button
if (typeof color === 'string') { if (typeof color === 'string') {
console.log('trying to find ',color) console.log('trying to find ',color);
//get all colors in palette //get all colors in palette
colors = document.getElementsByClassName('color-button'); colors = document.getElementsByClassName('color-button');
//loop through colors //loop through colors
for (var i = 0; i < colors.length; i++) { for (var i = 0; i < colors.length; i++) {
console.log(color,'=',colors[i].jscolor.toString()) console.log(color,'=',colors[i].jscolor.toString());
if (color == colors[i].jscolor.toString()) { if (color == colors[i].jscolor.toString()) {
console.log('match') console.log('match');
//set color to the color button //set color to the color button
color = colors[i]; color = colors[i];
console.log('found color', color); console.log('found color', color);

View File

@ -22,7 +22,7 @@ function closeDialogue () {
dialogueOpen = false; dialogueOpen = false;
} }
popUpContainer.addEventListener("click", function (e) { popUpContainer.addEventListener('click', function (e) {
if (e.target == popUpContainer) if (e.target == popUpContainer)
closeDialogue(); closeDialogue();
}); });

View File

@ -1,4 +1,4 @@
var mainMenuItems = document.getElementById("main-menu").children; var mainMenuItems = document.getElementById('main-menu').children;
//for each button in main menu (starting at 1 to avoid logo) //for each button in main menu (starting at 1 to avoid logo)
for (var i = 1; i < mainMenuItems.length; i++) { for (var i = 1; i < mainMenuItems.length; i++) {
@ -7,11 +7,11 @@ for (var i = 1; i < mainMenuItems.length; i++) {
var menuItem = mainMenuItems[i]; var menuItem = mainMenuItems[i];
var menuButton = menuItem.children[0]; var menuButton = menuItem.children[0];
console.log(mainMenuItems) console.log(mainMenuItems);
//when you click a main menu items button //when you click a main menu items button
on('click', menuButton, function (e, button) { on('click', menuButton, function (e, button) {
console.log('parent ', button.parentElement) console.log('parent ', button.parentElement);
select(button.parentElement); select(button.parentElement);
}); });
@ -26,7 +26,7 @@ for (var i = 1; i < mainMenuItems.length; i++) {
var subMenuItem = subMenuItems[j]; var subMenuItem = subMenuItems[j];
var subMenuButton = subMenuItem.children[0]; var subMenuButton = subMenuItem.children[0];
subMenuButton.addEventListener("click", function (e) { subMenuButton.addEventListener('click', function (e) {
switch(this.textContent) { switch(this.textContent) {
@ -42,11 +42,11 @@ for (var i = 1; i < mainMenuItems.length; i++) {
//check if the user wants to overwrite //check if the user wants to overwrite
if (confirm('Opening a pixel will discard your current one. Are you sure you want to do that?')) if (confirm('Opening a pixel will discard your current one. Are you sure you want to do that?'))
//open file selection dialog //open file selection dialog
document.getElementById("open-image-browse-holder").click(); document.getElementById('open-image-browse-holder').click();
} }
else else
//open file selection dialog //open file selection dialog
document.getElementById("open-image-browse-holder").click(); document.getElementById('open-image-browse-holder').click();
break; break;
@ -64,7 +64,7 @@ for (var i = 1; i < mainMenuItems.length; i++) {
} }
//set download link //set download link
var linkHolder = document.getElementById("save-image-link-holder"); var linkHolder = document.getElementById('save-image-link-holder');
linkHolder.href = canvas.toDataURL(); linkHolder.href = canvas.toDataURL();
linkHolder.download = fileName; linkHolder.download = fileName;
@ -78,7 +78,7 @@ for (var i = 1; i < mainMenuItems.length; i++) {
case 'Exit': case 'Exit':
console.log('exit') console.log('exit');
//if a document exists, make sure they want to delete it //if a document exists, make sure they want to delete it
if (documentCreated) { if (documentCreated) {

View File

@ -13,7 +13,7 @@ function HistoryStateEditCanvas () {
this.canvas = currentCanvas; this.canvas = currentCanvas;
redoStates.push(this); redoStates.push(this);
} };
this.redo = function () { this.redo = function () {
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
@ -21,7 +21,7 @@ function HistoryStateEditCanvas () {
this.canvas = currentCanvas; this.canvas = currentCanvas;
undoStates.push(this); undoStates.push(this);
} };
//add self to undo array //add self to undo array
saveHistoryState(this); saveHistoryState(this);
@ -34,12 +34,12 @@ function HistoryStateAddColor (colorValue) {
this.undo = function () { this.undo = function () {
redoStates.push(this); redoStates.push(this);
deleteColor(this.colorValue); deleteColor(this.colorValue);
} };
this.redo = function () { this.redo = function () {
addColor(this.colorValue); addColor(this.colorValue);
undoStates.push(this); undoStates.push(this);
} };
//add self to undo array //add self to undo array
saveHistoryState(this); saveHistoryState(this);
@ -58,7 +58,7 @@ function HistoryStateDeleteColor (colorValue) {
this.canvas = currentCanvas; this.canvas = currentCanvas;
redoStates.push(this); redoStates.push(this);
} };
this.redo = function () { this.redo = function () {
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
@ -68,7 +68,7 @@ function HistoryStateDeleteColor (colorValue) {
this.canvas = currentCanvas; this.canvas = currentCanvas;
undoStates.push(this); undoStates.push(this);
} };
//add self to undo array //add self to undo array
saveHistoryState(this); saveHistoryState(this);
@ -87,7 +87,7 @@ function HistoryStateEditColor (newColorValue, oldColorValue) {
//find new color in palette and change it back to old color //find new color in palette and change it back to old color
var colors = document.getElementsByClassName('color-button'); var colors = document.getElementsByClassName('color-button');
for (var i = 0; i < colors.length; i++) { for (var i = 0; i < colors.length; i++) {
console.log(newColorValue, '==', colors[i].jscolor.toString()) console.log(newColorValue, '==', colors[i].jscolor.toString());
if (newColorValue == colors[i].jscolor.toString()) { if (newColorValue == colors[i].jscolor.toString()) {
colors[i].jscolor.fromString(oldColorValue); colors[i].jscolor.fromString(oldColorValue);
break; break;
@ -96,7 +96,7 @@ function HistoryStateEditColor (newColorValue, oldColorValue) {
this.canvas = currentCanvas; this.canvas = currentCanvas;
redoStates.push(this); redoStates.push(this);
} };
this.redo = function () { this.redo = function () {
var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);
@ -105,7 +105,7 @@ function HistoryStateEditColor (newColorValue, oldColorValue) {
//find old color in palette and change it back to new color //find old color in palette and change it back to new color
var colors = document.getElementsByClassName('color-button'); var colors = document.getElementsByClassName('color-button');
for (var i = 0; i < colors.length; i++) { for (var i = 0; i < colors.length; i++) {
console.log(oldColorValue, '==', colors[i].jscolor.toString()) console.log(oldColorValue, '==', colors[i].jscolor.toString());
if (oldColorValue == colors[i].jscolor.toString()) { if (oldColorValue == colors[i].jscolor.toString()) {
colors[i].jscolor.fromString(newColorValue); colors[i].jscolor.fromString(newColorValue);
break; break;
@ -114,7 +114,7 @@ function HistoryStateEditColor (newColorValue, oldColorValue) {
this.canvas = currentCanvas; this.canvas = currentCanvas;
undoStates.push(this); undoStates.push(this);
} };
//add self to undo array //add self to undo array
saveHistoryState(this); saveHistoryState(this);
@ -123,8 +123,8 @@ function HistoryStateEditColor (newColorValue, oldColorValue) {
//rename to add undo state //rename to add undo state
function saveHistoryState (state) { function saveHistoryState (state) {
console.log('%csaving history state', undoLogStyle) console.log('%csaving history state', undoLogStyle);
console.log(state) console.log(state);
//get current canvas data and save to undoStates array //get current canvas data and save to undoStates array
undoStates.push(state); undoStates.push(state);
@ -140,8 +140,8 @@ function saveHistoryState (state) {
//there should be no redoStates after an undoState is saved //there should be no redoStates after an undoState is saved
redoStates = []; redoStates = [];
console.log(undoStates) console.log(undoStates);
console.log(redoStates) console.log(redoStates);
} }
function undo () { function undo () {
@ -167,8 +167,8 @@ function undo () {
document.getElementById('undo-button').classList.add('disabled'); document.getElementById('undo-button').classList.add('disabled');
} }
console.log(undoStates) console.log(undoStates);
console.log(redoStates) console.log(redoStates);
} }
function redo () { function redo () {
@ -193,6 +193,6 @@ function redo () {
if (redoStates.length == 0) if (redoStates.length == 0)
document.getElementById('redo-button').classList.add('disabled'); document.getElementById('redo-button').classList.add('disabled');
} }
console.log(undoStates) console.log(undoStates);
console.log(redoStates) console.log(redoStates);
} }

View File

@ -12,9 +12,10 @@
//Ive made changes to this script. ctrl+f [lospec] //Ive made changes to this script. ctrl+f [lospec]
//skeddles variables [lospec] //skeddles variables [lospec]
/* eslint-disable */
var colorPickerBottomAdded; var colorPickerBottomAdded;
var newjsColorPickerBottom; var newjsColorPickerBottom;
"use strict"; 'use strict';
if (!window.jscolor) { window.jscolor = (function () { if (!window.jscolor) { window.jscolor = (function () {
@ -181,7 +182,7 @@ var jsc = {
document.detachEvent('onreadystatechange', arguments.callee); document.detachEvent('onreadystatechange', arguments.callee);
fireOnce(); fireOnce();
} }
}) });
// Fallback // Fallback
window.attachEvent('onload', fireOnce); window.attachEvent('onload', fireOnce);
@ -561,8 +562,8 @@ var jsc = {
else { else {
//console.log('clicked outside of color picker') //console.log('clicked outside of color picker')
//unhide hidden edit button [lospec] //unhide hidden edit button [lospec]
var hiddenButton = document.querySelector(".color-edit-button.hidden") var hiddenButton = document.querySelector('.color-edit-button.hidden');
if (hiddenButton) hiddenButton.classList.remove("hidden"); if (hiddenButton) hiddenButton.classList.remove('hidden');
//close color picker //close color picker
jsc.picker.owner.hide(); jsc.picker.owner.hide();
@ -650,8 +651,8 @@ var jsc = {
case 'pad': case 'pad':
// if the slider is at the bottom, move it up // if the slider is at the bottom, move it up
switch (jsc.getSliderComponent(thisObj)) { switch (jsc.getSliderComponent(thisObj)) {
case 's': if (thisObj.hsv[1] === 0) { thisObj.fromHSV(null, 100, null); }; break; case 's': if (thisObj.hsv[1] === 0) { thisObj.fromHSV(null, 100, null); } break;
case 'v': if (thisObj.hsv[2] === 0) { thisObj.fromHSV(null, null, 100); }; break; case 'v': if (thisObj.hsv[2] === 0) { thisObj.fromHSV(null, null, 100); } break;
} }
jsc.setPad(thisObj, e, 0, 0); jsc.setPad(thisObj, e, 0, 0);
break; break;
@ -681,7 +682,7 @@ var jsc = {
jsc.dispatchFineChange(thisObj); jsc.dispatchFineChange(thisObj);
break; break;
} }
} };
}, },
@ -835,7 +836,7 @@ var jsc = {
hGrad.type = 'gradient'; hGrad.type = 'gradient';
hGrad.method = 'linear'; hGrad.method = 'linear';
hGrad.angle = '90'; hGrad.angle = '90';
hGrad.colors = '16.67% #F0F, 33.33% #00F, 50% #0FF, 66.67% #0F0, 83.33% #FF0' hGrad.colors = '16.67% #F0F, 33.33% #00F, 50% #0FF, 66.67% #0F0, 83.33% #FF0';
var hRect = document.createElement(jsc._vmlNS + ':rect'); var hRect = document.createElement(jsc._vmlNS + ':rect');
hRect.style.position = 'absolute'; hRect.style.position = 'absolute';
@ -1074,7 +1075,7 @@ var jsc = {
//set the color to old color, in case the color is a duplicate that hasn't been resolved yet [lospec] //set the color to old color, in case the color is a duplicate that hasn't been resolved yet [lospec]
var hexInput = document.getElementById('jscolor-hex-input'); var hexInput = document.getElementById('jscolor-hex-input');
var oldColor = '#'+rgbToHex(hexInput.oldColor); var oldColor = '#'+rgbToHex(hexInput.oldColor);
this.fromString(oldColor) this.fromString(oldColor);
document.getElementById('duplicate-color-warning').style.visibility = 'hidden'; document.getElementById('duplicate-color-warning').style.visibility = 'hidden';
//dialog is closed //dialog is closed
@ -1096,7 +1097,7 @@ var jsc = {
var hexInput = document.getElementById('jscolor-hex-input'); var hexInput = document.getElementById('jscolor-hex-input');
//set the value element to the hex input //set the value element to the hex input
this.valueElement = hexInput this.valueElement = hexInput;
//update hex code //update hex code
this.exportColor(); this.exportColor();
@ -1116,7 +1117,7 @@ var jsc = {
deleteButton.classList.remove('disabled'); deleteButton.classList.remove('disabled');
//hide duplicate color warning //hide duplicate color warning
var duplicateColorWarning = document.getElementById("duplicate-color-warning"); var duplicateColorWarning = document.getElementById('duplicate-color-warning');
duplicateColorWarning.style.visibility = 'hidden'; duplicateColorWarning.style.visibility = 'hidden';
}; };

View File

@ -15,9 +15,9 @@
* @param canvas HTML canvas element * @param canvas HTML canvas element
*/ */
function Layer(width, height, canvas) { function Layer(width, height, canvas) {
this.canvasSize = [width, height], this.canvasSize = [width, height];
this.canvas = canvas, this.canvas = canvas;
this.context = this.canvas.getContext("2d"), this.context = this.canvas.getContext('2d');
// Initializes the canvas // Initializes the canvas
this.initialize = function() { this.initialize = function() {
var maxHorizontalZoom = Math.floor(window.innerWidth/this.canvasSize[0]*0.75); var maxHorizontalZoom = Math.floor(window.innerWidth/this.canvasSize[0]*0.75);
@ -41,7 +41,7 @@ function Layer(width, height, canvas) {
this.context.imageSmoothingEnabled = false; this.context.imageSmoothingEnabled = false;
this.context.mozImageSmoothingEnabled = false; this.context.mozImageSmoothingEnabled = false;
}, };
// Resizes canvas // Resizes canvas
this.resize = function() { this.resize = function() {
let newWidth = (this.canvas.width * zoom) + 'px'; let newWidth = (this.canvas.width * zoom) + 'px';
@ -49,7 +49,7 @@ function Layer(width, height, canvas) {
this.canvas.style.width = newWidth; this.canvas.style.width = newWidth;
this.canvas.style.height = newHeight; this.canvas.style.height = newHeight;
}, };
// Copies the otherCanvas' position and size // Copies the otherCanvas' position and size
this.copyData = function(otherCanvas) { this.copyData = function(otherCanvas) {
this.canvas.style.width = otherCanvas.canvas.style.width; this.canvas.style.width = otherCanvas.canvas.style.width;
@ -57,5 +57,5 @@ function Layer(width, height, canvas) {
this.canvas.style.left = otherCanvas.canvas.style.left; this.canvas.style.left = otherCanvas.canvas.style.left;
this.canvas.style.top = otherCanvas.canvas.style.top; this.canvas.style.top = otherCanvas.canvas.style.top;
} };
} }

View File

@ -22,7 +22,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
var imagePixelDataLength = imagePixelData.length; var imagePixelDataLength = imagePixelData.length;
console.log(imagePixelData) console.log(imagePixelData);
for (var i = 0; i < imagePixelDataLength; i += 4) { for (var i = 0; i < imagePixelDataLength; i += 4) {
var color = imagePixelData[i]+','+imagePixelData[i + 1]+','+imagePixelData[i + 2]; var color = imagePixelData[i]+','+imagePixelData[i + 1]+','+imagePixelData[i + 2];
if (!colorPalette[color]) { if (!colorPalette[color]) {
@ -30,7 +30,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
//don't allow more than 256 colors to be added //don't allow more than 256 colors to be added
if (Object.keys(colorPalette).length >= settings.maxColorsOnImportedImage) { if (Object.keys(colorPalette).length >= settings.maxColorsOnImportedImage) {
alert('The image loaded seems to have more than '+settings.maxColorsOnImportedImage+' colors.') alert('The image loaded seems to have more than '+settings.maxColorsOnImportedImage+' colors.');
break; break;
} }
} }
@ -43,7 +43,7 @@ document.getElementById('open-image-browse-holder').addEventListener('change', f
colorPaletteArray.push('#'+rgbToHex(colorPalette[color])); colorPaletteArray.push('#'+rgbToHex(colorPalette[color]));
} }
} }
console.log('COLOR PALETTE ARRAY', colorPaletteArray) console.log('COLOR PALETTE ARRAY', colorPaletteArray);
//create palette form colors array //create palette form colors array
createColorPalette(colorPaletteArray, false); createColorPalette(colorPaletteArray, false);

View File

@ -14,8 +14,8 @@ document.getElementById('load-palette-browse-holder').addEventListener('change',
img.onload = function() { img.onload = function() {
//draw image onto the temporary canvas //draw image onto the temporary canvas
var loadPaletteCanvas = document.getElementById("load-palette-canvas-holder"); var loadPaletteCanvas = document.getElementById('load-palette-canvas-holder');
var loadPaletteContext = loadPaletteCanvas.getContext("2d"); var loadPaletteContext = loadPaletteCanvas.getContext('2d');
loadPaletteCanvas.width = img.width; loadPaletteCanvas.width = img.width;
loadPaletteCanvas.height = img.height; loadPaletteCanvas.height = img.height;
@ -26,7 +26,7 @@ document.getElementById('load-palette-browse-holder').addEventListener('change',
var colorPalette = []; var colorPalette = [];
var imagePixelData = loadPaletteContext.getImageData(0,0,this.width, this.height).data; var imagePixelData = loadPaletteContext.getImageData(0,0,this.width, this.height).data;
console.log(imagePixelData) console.log(imagePixelData);
//loop through pixels looking for colors to add to palette //loop through pixels looking for colors to add to palette
for (var i = 0; i < imagePixelData.length; i += 4) { for (var i = 0; i < imagePixelData.length; i += 4) {

View File

@ -118,8 +118,29 @@ window.addEventListener("mouseup", function (mouseEvent) {
if (mouseEvent.which == 1){ if (mouseEvent.which == 1){
mode = "in"; mode = "in";
} }
}
else if (currentTool == 'fill' && mouseEvent.target.className == 'drawingCanvas') {
console.log('filling');
//if you clicked on anything but the canvas, do nothing
if (!mouseEvent.target == currentLayer.canvas) return;
//get cursor postion
var cursorLocation = getCursorPosition(mouseEvent);
//offset to match cursor point
cursorLocation[0] += 2;
cursorLocation[1] += 12;
//fill starting at the location
fill(cursorLocation);
}
else if (currentTool == 'zoom' && mouseEvent.target.className == 'drawingCanvas') {
let mode;
if (mouseEvent.which == 1){
mode = 'in';
}
else if (mouseEvent.which == 3){ else if (mouseEvent.which == 3){
mode = "out"; mode = 'out';
} }
changeZoom(layers[0], mode, getCursorPosition(mouseEvent)); changeZoom(layers[0], mode, getCursorPosition(mouseEvent));
@ -143,6 +164,19 @@ window.addEventListener("mouseup", function (mouseEvent) {
}, false); }, false);
function setPreviewPosition(preview, cursor, size){
preview.style.left = (
currentLayer.canvas.offsetLeft
+ Math.floor(cursor[0]/zoom) * zoom
- Math.floor(size / 2) * zoom
) + 'px';
preview.style.top = (
currentLayer.canvas.offsetTop
+ Math.floor(cursor[1]/zoom) * zoom
- Math.floor(size / 2) * zoom
) + 'px';
}
// OPTIMIZABLE: redundant || mouseEvent.target.className in currentTool ifs // OPTIMIZABLE: redundant || mouseEvent.target.className in currentTool ifs
@ -339,7 +373,7 @@ canvasView.addEventListener("wheel", function(mouseEvent){
} }
// Changing zoom and position of the first layer // Changing zoom and position of the first layer
changeZoom(layers[0], mode, getCursorPosition(mouseEvent)) changeZoom(layers[0], mode, getCursorPosition(mouseEvent));
for (let i=1; i<layers.length; i++) { for (let i=1; i<layers.length; i++) {
// Copying first layer's data into the other layers // Copying first layer's data into the other layers

View File

@ -26,7 +26,7 @@ function updateMovePreview(mouseEvent) {
Math.round(lastMousePos[1] / zoom - imageDataToMove.height / 2)); Math.round(lastMousePos[1] / zoom - imageDataToMove.height / 2));
lastMovePos = lastMousePos; lastMovePos = lastMousePos;
moveSelection(lastMousePos[0] / zoom, lastMousePos[1] / zoom, imageDataToMove.width, imageDataToMove.height) moveSelection(lastMousePos[0] / zoom, lastMousePos[1] / zoom, imageDataToMove.width, imageDataToMove.height);
} }
function endSelection() { function endSelection() {

View File

@ -4,4 +4,4 @@ window.onbeforeunload = function() {
return 'You will lose your pixel if it\'s not saved!'; return 'You will lose your pixel if it\'s not saved!';
else return; else return;
} };

View File

@ -1,10 +1,10 @@
//populate palettes list in new pixel menu //populate palettes list in new pixel menu
Object.keys(palettes).forEach(function(paletteName,index) { Object.keys(palettes).forEach(function(paletteName,index) {
var palettesMenu = document.getElementById("palette-menu"); var palettesMenu = document.getElementById('palette-menu');
//create button //create button
var button = document.createElement("button"); var button = document.createElement('button');
button.appendChild(document.createTextNode(paletteName)); button.appendChild(document.createTextNode(paletteName));
//insert new element //insert new element
@ -39,7 +39,7 @@ on('click', 'no-palette-button', function () {
//select load palette //select load palette
on('click', 'load-palette-button', function () { on('click', 'load-palette-button', function () {
document.getElementById("load-palette-browse-holder").click(); document.getElementById('load-palette-browse-holder').click();
}); });

View File

@ -20,10 +20,10 @@ var presets = {
//populate preset list in new pixel menu //populate preset list in new pixel menu
Object.keys(presets).forEach(function(presetName,index) { Object.keys(presets).forEach(function(presetName,index) {
var presetsMenu = document.getElementById("preset-menu"); var presetsMenu = document.getElementById('preset-menu');
//create button //create button
var button = document.createElement("button"); var button = document.createElement('button');
button.appendChild(document.createTextNode(presetName)); button.appendChild(document.createTextNode(presetName));
//insert new element //insert new element

View File

@ -86,12 +86,12 @@ function cutSelection(mouseEvent) {
function drawRect(x, y) { function drawRect(x, y) {
// Getting the vfx context // Getting the vfx context
let vfxContext = VFXCanvas.getContext("2d"); let vfxContext = VFXCanvas.getContext('2d');
// Clearing the vfx canvas // Clearing the vfx canvas
vfxContext.clearRect(0, 0, VFXCanvas.width, VFXCanvas.height); vfxContext.clearRect(0, 0, VFXCanvas.width, VFXCanvas.height);
vfxContext.lineWidth = 1; vfxContext.lineWidth = 1;
vfxContext.strokeStyle = "black"; vfxContext.strokeStyle = 'black';
vfxContext.setLineDash([4]); vfxContext.setLineDash([4]);
// Drawing the rect // Drawing the rect
@ -131,7 +131,7 @@ function cursorInSelectedArea() {
function moveSelection(x, y, width, height) { function moveSelection(x, y, width, height) {
// Getting the vfx context // Getting the vfx context
let vfxContext = VFXCanvas.getContext("2d"); let vfxContext = VFXCanvas.getContext('2d');
// Clearing the vfx canvas // Clearing the vfx canvas
vfxContext.clearRect(0, 0, VFXCanvas.width, VFXCanvas.height); vfxContext.clearRect(0, 0, VFXCanvas.width, VFXCanvas.height);

View File

@ -19,8 +19,8 @@ function startRectDrawing(mouseEvent) {
// Saving the start coords of the rect // Saving the start coords of the rect
let cursorPos = getCursorPosition(mouseEvent); let cursorPos = getCursorPosition(mouseEvent);
startRectX = Math.round(cursorPos[0] / zoom) - 0.5; startRectX = Math.floor(cursorPos[0] / zoom) + 0.5;
startRectY = Math.round(cursorPos[1] / zoom) - 0.5; startRectY = Math.floor(cursorPos[1] / zoom) + 0.5;
drawRectangle(startRectX, startRectY); drawRectangle(startRectX, startRectY);
} }
@ -106,12 +106,12 @@ function drawRectangle(x, y) {
function setRectToolSvg() { function setRectToolSvg() {
if (drawMode == 'empty') { if (drawMode == 'empty') {
emptySVG.setAttribute("display", "visible"); emptySVG.setAttribute('display', 'visible');
fullSVG.setAttribute("display", "none"); fullSVG.setAttribute('display', 'none');
} }
else { else {
emptySVG.setAttribute("display", "none"); emptySVG.setAttribute('display', 'none');
fullSVG.setAttribute("display", "visible"); fullSVG.setAttribute('display', 'visible');
} }
} }

View File

@ -7,7 +7,7 @@ if (!Cookies.enabled) {
//try to load settings from cookie //try to load settings from cookie
var settingsFromCookie = Cookies.get('pixelEditorSettings'); var settingsFromCookie = Cookies.get('pixelEditorSettings');
if(!settingsFromCookie) { if(!settingsFromCookie) {
console.log('settings cookie not found') console.log('settings cookie not found');
settings = { settings = {
switchToChangedColor: true, switchToChangedColor: true,
enableDynamicCursorOutline: true, //unused - performance enableDynamicCursorOutline: true, //unused - performance
@ -29,7 +29,7 @@ on('click', 'save-settings', function (){
//check if values are valid //check if values are valid
if (isNaN(getValue('setting-numberOfHistoryStates'))) { if (isNaN(getValue('setting-numberOfHistoryStates'))) {
alert('Invalid value for numberOfHistoryStates') alert('Invalid value for numberOfHistoryStates');
return; return;
} }

View File

@ -31,7 +31,7 @@ on('click',"eraser-smaller-button", function(e){
}, false); }, false);
// rectangle // rectangle
on('click',"rectangle-button", function(){ on('click','rectangle-button', function(){
// If the user clicks twice on the button, they change the draw mode // If the user clicks twice on the button, they change the draw mode
if (currentTool.name == 'rectangle') { if (currentTool.name == 'rectangle') {
if (drawMode == 'empty') { if (drawMode == 'empty') {
@ -80,7 +80,7 @@ on('click',"zoom-button", function(){
}, false); }, false);
//zoom in button //zoom in button
on('click',"zoom-in-button", function(){ on('click','zoom-in-button', function(){
//changeZoom('in',[window.innerWidth/2-canvas.offsetLeft,window.innerHeight/2-canvas.offsetTop]); //changeZoom('in',[window.innerWidth/2-canvas.offsetLeft,window.innerHeight/2-canvas.offsetTop]);
changeZoom(layers[0],'in', [canvasSize[0] * zoom / 2, canvasSize[1] * zoom / 2]); changeZoom(layers[0],'in', [canvasSize[0] * zoom / 2, canvasSize[1] * zoom / 2]);
@ -90,7 +90,7 @@ on('click',"zoom-in-button", function(){
}, false); }, false);
//zoom out button //zoom out button
on('click',"zoom-out-button", function(){ on('click','zoom-out-button', function(){
changeZoom(layers[0],'out',[canvasSize[0]*zoom/2,canvasSize[1]*zoom/2]); changeZoom(layers[0],'out',[canvasSize[0]*zoom/2,canvasSize[1]*zoom/2]);
for (let i=1; i<layers.length; i++) { for (let i=1; i<layers.length; i++) {

View File

@ -13,7 +13,7 @@ var secondCheckerBoardColor = 'rgba(204, 200, 206, 1)';
// Square size for the checkerboard // Square size for the checkerboard
var checkerBoardSquareSize = 16; var checkerBoardSquareSize = 16;
// Checkerboard canvas // Checkerboard canvas
var checkerBoardCanvas = document.getElementById("checkerboard"); var checkerBoardCanvas = document.getElementById('checkerboard');
//common elements //common elements
var brushPreview = document.getElementById("brush-preview"); var brushPreview = document.getElementById("brush-preview");
@ -24,8 +24,8 @@ var colorsMenu = document.getElementById("colors-menu");
var popUpContainer = document.getElementById("pop-up-container"); var popUpContainer = document.getElementById("pop-up-container");
// main canvas // main canvas
var canvas = document.getElementById("pixel-canvas"); var canvas = document.getElementById('pixel-canvas');
var context = canvas.getContext("2d"); var context = canvas.getContext('2d');
var currentGlobalColor; var currentGlobalColor;
// Layers // Layers
@ -36,9 +36,9 @@ var currentLayer;
// VFX layer used to draw previews of the selection and things like that // VFX layer used to draw previews of the selection and things like that
var VFXLayer; var VFXLayer;
// VFX canvas // VFX canvas
var VFXCanvas = document.getElementById("vfx-canvas"); var VFXCanvas = document.getElementById('vfx-canvas');
// TMP layer // TMP layer
var TMPLayer; var TMPLayer;
// TMP canvas // TMP canvas
var TMPCanvas = document.getElementById("tmp-canvas"); var TMPCanvas = document.getElementById('tmp-canvas');

2831
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,21 +4,22 @@
"description": "Online pixel art creation tool", "description": "Online pixel art creation tool",
"main": "build.js", "main": "build.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "build": "node ./build.js ./build",
"serve": "node ./server.js ./build 3000",
"test": "npm run build && npm run serve"
}, },
"author": "Lospec", "author": "Lospec",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.16.4", "express": "^4.16.4",
"fs-extra": "^7.0.1", "fs-extra": "^7.0.1",
"glob": "^7.1.3", "gulp": "^4.0.2",
"gulp": "^4.0.0", "gulp-hb": "^8.0.0",
"gulp-include": "^2.3.1", "gulp-include": "^2.3.1",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.0.2",
"handlebars-helper-svg": "git+https://bitbucket.org/skeddles/npm-handlebars-helper-svg-lospec-open-source.git", "handlebars-helper-svg": "git+https://bitbucket.org/skeddles/npm-handlebars-helper-svg-lospec-open-source.git",
"hbs": "^4.0.3", "open": "^6.0.0",
"hbs-register-helpers": "git+https://skeddles@bitbucket.org/skeddles/hbs-register-helpers.git",
"hbs-register-partials": "git+https://skeddles@bitbucket.org/skeddles/hbs-register-partials.git",
"opn": "^6.0.0",
"sass": "^1.17.3" "sass": "^1.17.3"
} }
} }

37
server.js Normal file
View File

@ -0,0 +1,37 @@
const path = require('path');
const express = require('express');
const app = express();
const BUILDDIR = process.argv[2] || './build';
const PORT = process.argv[3] || 3000;
//ROUTE - index.htm
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, BUILDDIR, 'index.htm'), {}, function (err) {
if(err){
console.log('error sending file',err);
} else {
setTimeout(()=>{
console.log('closing server');
server.close();
process.exit();
},1000*10);
}
});
});
//ROUTE - other files
app.use(express.static(path.join(__dirname, BUILDDIR)));
//start server
var server = app.listen(PORT, () => {
console.log(`\nTemp server started at http://localhost:${PORT}!`);
//console.log('press ctrl+c to stop ');
var opn = require('open');
// opens the url in the default browser
opn(`http://localhost:${PORT}`);
});