mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-01 05:43:01 +00:00
Fix eslint issues
This commit is contained in:
parent
39bba6bef1
commit
cc795f0f95
5 changed files with 23 additions and 24 deletions
|
@ -47,10 +47,10 @@ async function shortcode_image_url(src) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shortcode_image_urlpass(src) {
|
async function shortcode_image_urlpass(src) {
|
||||||
let target_dir = `./_site/img`;
|
const target_dir = `./_site/img`;
|
||||||
if(!fs.existsSync(target_dir))
|
if(!fs.existsSync(target_dir))
|
||||||
await fs.promises.mkdir(target_dir, { recursive: true });
|
await fs.promises.mkdir(target_dir, { recursive: true });
|
||||||
let filename = path.basename(src);
|
const filename = path.basename(src);
|
||||||
// Generally speaking we optimise PNGs *very* well with oxipng/Zopfli,
|
// Generally speaking we optimise PNGs *very* well with oxipng/Zopfli,
|
||||||
// and the Image plugin doesn't respect this
|
// and the Image plugin doesn't respect this
|
||||||
await fs.promises.copyFile(src, path.join(target_dir, filename));
|
await fs.promises.copyFile(src, path.join(target_dir, filename));
|
||||||
|
|
|
@ -4,6 +4,7 @@ export default [
|
||||||
rules: {
|
rules: {
|
||||||
"prefer-const": "warn",
|
"prefer-const": "warn",
|
||||||
"no-constant-binary-expression": "error"
|
"no-constant-binary-expression": "error"
|
||||||
}
|
},
|
||||||
|
ignores: ["**/_site/**"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
let dropzone = document.querySelector("#dropzone");
|
const dropzone = document.querySelector("#dropzone");
|
||||||
dropzone.addEventListener("dragenter", handle_drag_enter);
|
dropzone.addEventListener("dragenter", handle_drag_enter);
|
||||||
dropzone.addEventListener("dragleave", handle_drag_leave);
|
dropzone.addEventListener("dragleave", handle_drag_leave);
|
||||||
dropzone.addEventListener("dragover", handle_drag_over);
|
dropzone.addEventListener("dragover", handle_drag_over);
|
||||||
dropzone.addEventListener("drop", handle_drop);
|
dropzone.addEventListener("drop", handle_drop);
|
||||||
|
|
||||||
document.querySelector("#brushimg-tsv").addEventListener("click", select_output);
|
document.querySelector("#brushimg-tsv").addEventListener("click", select_output);
|
||||||
let button_copy = document.querySelector("#brushimg-copy")
|
const button_copy = document.querySelector("#brushimg-copy")
|
||||||
button_copy.addEventListener("click", () => {
|
button_copy.addEventListener("click", () => {
|
||||||
select_output();
|
select_output();
|
||||||
button_copy.innerHTML = document.execCommand("copy") ? "Copied!" : "Failed to copy :-(";
|
button_copy.innerHTML = document.execCommand("copy") ? "Copied!" : "Failed to copy :-(";
|
||||||
|
@ -31,14 +31,14 @@ function get_source_channel_offset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_output() {
|
function select_output() {
|
||||||
let output = document.querySelector("#brushimg-tsv");
|
const output = document.querySelector("#brushimg-tsv");
|
||||||
|
|
||||||
let selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
|
|
||||||
if (selection.rangeCount > 0)
|
if (selection.rangeCount > 0)
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
|
|
||||||
let range = document.createRange();
|
const range = document.createRange();
|
||||||
range.selectNode(output);
|
range.selectNode(output);
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,11 @@ function handle_drop(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.target.classList.remove("dropzone-active");
|
event.target.classList.remove("dropzone-active");
|
||||||
|
|
||||||
let image_file = null;
|
const image_file = event.dataTransfer.files[0];
|
||||||
|
|
||||||
image_file = event.dataTransfer.files[0];
|
const reader = new FileReader();
|
||||||
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.addEventListener("load", function(_event) {
|
reader.addEventListener("load", function(_event) {
|
||||||
let image = new Image();
|
const image = new Image();
|
||||||
image.src = reader.result;
|
image.src = reader.result;
|
||||||
image.addEventListener("load", () => handle_new_image(image));
|
image.addEventListener("load", () => handle_new_image(image));
|
||||||
|
|
||||||
|
@ -78,7 +76,7 @@ function handle_drop(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function image2pixels(image) {
|
function image2pixels(image) {
|
||||||
let canvas = document.createElement("canvas"),
|
const canvas = document.createElement("canvas"),
|
||||||
ctx = canvas.getContext("2d");
|
ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
canvas.width = image.width;
|
canvas.width = image.width;
|
||||||
|
@ -90,7 +88,7 @@ function image2pixels(image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_new_image(image) {
|
function handle_new_image(image) {
|
||||||
let tsv = pixels2tsv(image2pixels(image));
|
const tsv = pixels2tsv(image2pixels(image));
|
||||||
document.querySelector("#brushimg-stats").value = `${image.width} x ${image.height} | ${image.width * image.height} pixels`;
|
document.querySelector("#brushimg-stats").value = `${image.width} x ${image.height} | ${image.width * image.height} pixels`;
|
||||||
document.querySelector("#brushimg-tsv").value = tsv;
|
document.querySelector("#brushimg-tsv").value = tsv;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +98,7 @@ function pixels2tsv(pixels) {
|
||||||
console.info(`pixels2tsv: offset is ${offset}`);
|
console.info(`pixels2tsv: offset is ${offset}`);
|
||||||
let result = "";
|
let result = "";
|
||||||
for(let y = 0; y < pixels.height; y++) {
|
for(let y = 0; y < pixels.height; y++) {
|
||||||
let row = [];
|
const row = [];
|
||||||
for(let x = 0; x < pixels.width; x++) {
|
for(let x = 0; x < pixels.width; x++) {
|
||||||
// No need to rescale here - this is done automagically by WorldEditAdditions.
|
// No need to rescale here - this is done automagically by WorldEditAdditions.
|
||||||
// r/b/g/alpha
|
// r/b/g/alpha
|
||||||
|
|
|
@ -62,10 +62,10 @@ async function srcset(source_image, target_dir, urlpath, format = "__AUTO__", si
|
||||||
|
|
||||||
debug(`SOURCE_SIZE`, source_size, `TARGET_FORMAT`, target_format);
|
debug(`SOURCE_SIZE`, source_size, `TARGET_FORMAT`, target_format);
|
||||||
|
|
||||||
let setitems = await Promise.all(sizes.map(async (size) => {
|
const setitems = await Promise.all(sizes.map(async (size) => {
|
||||||
let target_filename = `${source_parsed.name}_${size}.${target_format}`
|
const target_filename = `${source_parsed.name}_${size}.${target_format}`
|
||||||
.replace(/%/, "pcent");
|
.replace(/%/, "pcent");
|
||||||
let target_current = path.join(
|
const target_current = path.join(
|
||||||
target_dir,
|
target_dir,
|
||||||
target_filename
|
target_filename
|
||||||
);
|
);
|
||||||
|
|
|
@ -32,7 +32,7 @@ function extract_title(line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_section(acc, cat_current, cats) {
|
function make_section(acc, cat_current, cats) {
|
||||||
let title = extract_title(acc[0]);
|
const title = extract_title(acc[0]);
|
||||||
return {
|
return {
|
||||||
category: cat_current,
|
category: cat_current,
|
||||||
category_colour: cats.get(cat_current),
|
category_colour: cats.get(cat_current),
|
||||||
|
@ -62,14 +62,14 @@ export default function parse_sections(source) {
|
||||||
const result = [];
|
const result = [];
|
||||||
let acc = [];
|
let acc = [];
|
||||||
let cat_current = null;
|
let cat_current = null;
|
||||||
for(let line of lines) {
|
for(const line of lines) {
|
||||||
|
|
||||||
if(line.startsWith(`#`)) {
|
if(line.startsWith(`#`)) {
|
||||||
let heading_level = line.match(/^#+/)[0].length;
|
const heading_level = line.match(/^#+/)[0].length;
|
||||||
|
|
||||||
// 1: Deal with the previous section
|
// 1: Deal with the previous section
|
||||||
if(acc.length > 0) {
|
if(acc.length > 0) {
|
||||||
let heading_level_prev = acc[0].match(/^#+/)[0].length;
|
const heading_level_prev = acc[0].match(/^#+/)[0].length;
|
||||||
if(heading_level_prev === 3 && acc.length > 0 && heading_level <= 3) {
|
if(heading_level_prev === 3 && acc.length > 0 && heading_level <= 3) {
|
||||||
result.push(make_section(acc, cat_current, cats));
|
result.push(make_section(acc, cat_current, cats));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue