Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshjavier committed Aug 28, 2024
1 parent aff412f commit dd2491c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 28 deletions.
8 changes: 4 additions & 4 deletions config/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path"
import { build } from "esbuild"
import path from 'node:path'
import { build } from 'esbuild'

/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default function (eleventyConfig) {
Expand All @@ -23,7 +23,7 @@ export default function (eleventyConfig) {
format: 'esm',
minify: true,
metafile: true,
write: false
write: false,
})

let files = []
Expand All @@ -43,6 +43,6 @@ export default function (eleventyConfig) {
return async () => {
return result.outputFiles[0].text
}
}
},
})
}
12 changes: 6 additions & 6 deletions config/lightningcss.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path"
import browserslist from "browserslist"
import { bundleAsync, browserslistToTargets } from "lightningcss"
import path from 'node:path'
import browserslist from 'browserslist'
import { bundleAsync, browserslistToTargets } from 'lightningcss'

const targets = browserslistToTargets(browserslist())

Expand Down Expand Up @@ -28,8 +28,8 @@ export default function (eleventyConfig) {
const importPath = path.resolve(path.dirname(from), specifier)
imports.push(importPath)
return importPath
}
}
},
},
})

// Register imports as dependencies for incremental builds
Expand All @@ -38,6 +38,6 @@ export default function (eleventyConfig) {
return async () => {
return result.code.toString()
}
}
},
})
}
6 changes: 3 additions & 3 deletions config/process-bundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import browserslist from "browserslist"
import { transform as cssTransform, browserslistToTargets } from "lightningcss"
import { transform as jsTransform } from "esbuild"
import browserslist from 'browserslist'
import { transform as cssTransform, browserslistToTargets } from 'lightningcss'
import { transform as jsTransform } from 'esbuild'

const targets = browserslistToTargets(browserslist())

Expand Down
14 changes: 7 additions & 7 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pluginWebc from "@11ty/eleventy-plugin-webc"
import esbuild from "./config/esbuild.js"
import lightningcss from "./config/lightningcss.js"
import processBundle from "./config/process-bundle.js"
import pluginWebc from '@11ty/eleventy-plugin-webc'
import esbuild from './config/esbuild.js'
import lightningcss from './config/lightningcss.js'
import processBundle from './config/process-bundle.js'

/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ 'public': '/' })
eleventyConfig.addPassthroughCopy({ public: '/' })

eleventyConfig.addPlugin(esbuild)
eleventyConfig.addPlugin(lightningcss)
Expand All @@ -19,7 +19,7 @@ export default function (eleventyConfig) {
return {
dir: {
input: 'src',
output: 'dist'
}
output: 'dist',
},
}
}
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default [
},
},
rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@stylistic/brace-style': ['error', '1tbs'],
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/js/_components/filepicker-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ class FilePickerToggle extends HTMLElement {
set type(val) {
this.setAttribute('type', val)
}

get type() {
return this.getAttribute('type')
}

set label(val) {
this.setAttribute('label', val)
}

get label() {
return this.getAttribute('label')
}
Expand Down
15 changes: 10 additions & 5 deletions src/js/_components/image-card.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { bytesToSize } from "../_utils.js"
import { bytesToSize } from '../_utils.js'

export class ImageCard extends HTMLElement {
set quality(val) {
this.setAttribute('quality', val)
}

get quality() {
return Number(this.getAttribute('quality'))
}

set valid(val) {
const isValid = Boolean(val)
if (isValid) {
Expand All @@ -15,9 +17,11 @@ export class ImageCard extends HTMLElement {
this.setAttribute('aria-invalid', 'true')
}
}

get valid() {
return !this.getAttribute('aria-invalid')
}

set loading(bool) {
if (bool) {
const spinner = document.createElement('div')
Expand All @@ -29,14 +33,16 @@ export class ImageCard extends HTMLElement {
this.dom.thumbnail.replaceChildren(this.data.image)
}
}

get loading() {
return this.querySelector('.spinner')
}

static get observedAttributes() {
return ['quality']
}
attributeChangedCallback(name, oldVal, newVal) {

attributeChangedCallback(name, _oldVal, _newVal) {
if (!this.dom || !this.data.image) return
switch (name) {
case 'quality':
Expand Down Expand Up @@ -156,7 +162,6 @@ export class ImageCard extends HTMLElement {

this.data.compressed.url = URL.createObjectURL(this.data.compressed.blob)
this.dom.sizeCompressed.textContent = bytesToSize(this.data.compressed.blob.size)

} else {
const offscreenCanvas = new OffscreenCanvas(this.data.image.naturalWidth, this.data.image.naturalHeight)
const ctx = offscreenCanvas.getContext('2d')
Expand Down Expand Up @@ -197,12 +202,12 @@ export class ImageCard extends HTMLElement {
}
console.log(options)

return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
worker.onmessage = (e) => {
resolve(e.data.data)
worker.terminate()
}
this.data.file.arrayBuffer().then(buf => {
this.data.file.arrayBuffer().then((buf) => {
worker.postMessage({
file: new Uint8Array(buf),
options,
Expand Down
2 changes: 1 addition & 1 deletion src/js/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
export function bytesToSize(
bytes,
{ precision = 1, threshold = 100} = {},
{ precision = 1, threshold = 100 } = {},
) {
const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
let l = 0, n = parseInt(bytes, 10) || 0
Expand Down
4 changes: 2 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ImageCard } from './_components/image-card.js'

// Import functions
import JSZip from 'jszip'
import { saveAs } from "file-saver"
import { debounce } from "./_utils.js"
import { saveAs } from 'file-saver'
import { debounce } from './_utils.js'

// Make imports accessible in global scope
window.JSZip = JSZip
Expand Down
1 change: 1 addition & 0 deletions src/js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ importScripts('https://cdn.jsdelivr.net/gh/psych0der/pngquantjs@master/demo/js/p

onmessage = (e) => {
const { file, options } = e.data
// eslint-disable-next-line no-undef
const result = pngquant(file, options, console.log)
postMessage(result)
}

0 comments on commit dd2491c

Please sign in to comment.