From b958d46086ee86cce69c55acadee2b5e9f5eb834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1mal=20Rasmussen?= Date: Thu, 27 Aug 2020 23:14:05 +0100 Subject: [PATCH 1/8] Add keyboard shortcuts for moving the split view separator --- .../Compress/Output/custom-els/TwoUp/index.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts b/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts index 35b51831..c2cb7b95 100644 --- a/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts +++ b/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts @@ -68,6 +68,8 @@ export default class TwoUp extends HTMLElement { ); }, }); + + window.addEventListener('keydown', event => this._onKeyDown(event)); } connectedCallback() { @@ -94,6 +96,29 @@ export default class TwoUp extends HTMLElement { } } + // KeyDown event handler + private _onKeyDown(event: KeyboardEvent) { + if (event.code === 'Digit1' || event.code === 'Numpad1') { + this._position = 0; + this._relativePosition = 0; + this._setPosition(); + } else if (event.code === 'Digit2' || event.code === 'Numpad2') { + const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width'; + const bounds = this.getBoundingClientRect(); + + this._position = bounds[dimensionAxis] / 2; + this._relativePosition = (this._position / bounds[dimensionAxis]) / 2; + this._setPosition(); + } else if (event.code === 'Digit3' || event.code === 'Numpad3') { + const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width'; + const bounds = this.getBoundingClientRect(); + + this._position = bounds[dimensionAxis]; + this._relativePosition = this._position / bounds[dimensionAxis]; + this._setPosition(); + } + } + private _resetPosition() { // Set the initial position of the handle. requestAnimationFrame(() => { From 3338808f17a0c69d1454fcedb5309f8f54a10107 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 15 Dec 2020 10:42:18 +0000 Subject: [PATCH 2/8] Make vector the default resize type for vector images --- src/client/lazy-app/Compress/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/lazy-app/Compress/index.tsx b/src/client/lazy-app/Compress/index.tsx index 0da8f769..232fe667 100644 --- a/src/client/lazy-app/Compress/index.tsx +++ b/src/client/lazy-app/Compress/index.tsx @@ -604,6 +604,7 @@ export default class Compress extends Component { const resizeState: Partial = { width: decoded.width, height: decoded.height, + method: vectorImage ? 'vector' : 'lanczos3', // Disable resizing, to make it clearer to the user that something changed here enabled: false, }; From 62b4d39128b90bffbd88bba087101548c61d6eb2 Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Sat, 19 Dec 2020 05:46:16 +0700 Subject: [PATCH 3/8] Fix wrong development script in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81afda9f..8bcfb7b6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ npm run build You can run the development server with: ```sh -npm start +npm run dev ``` [squoosh]: https://squoosh.app From 733b470f1f3bf7d1ab8b86316f5b05e53603e692 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sat, 26 Dec 2020 22:56:23 +1000 Subject: [PATCH 4/8] allow passing entire directories as input --- cli/src/index.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/cli/src/index.js b/cli/src/index.js index d7c97eda..ba1107ee 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -183,31 +183,37 @@ function progressTracker(results) { return tracker; } -async function checkInputFilesValid(files) { +async function getInputFiles(paths) { const validFiles = []; - for (const file of files) { - try { - await fsp.stat(file); - } catch (err) { - if (err.code === 'ENOENT') { - console.warn( - `Warning: Input file does not exist: ${resolvePath(file)}`, - ); - continue; - } else { - throw err; + for (const path of paths) { + //allow paths ending in / of \ to get all files in that directory + const files = path.endsWith('/') || path.endsWith('\\') + ? await fs.readdir(paths) + : [path]; + for (const file of files) { + try { + await fsp.stat(file); + } catch (err) { + if (err.code === 'ENOENT') { + console.warn( + `Warning: Input file does not exist: ${resolvePath(file)}`, + ); + continue; + } else { + throw err; + } } - } - validFiles.push(file); + validFiles.push(file); + } } return validFiles; } async function processFiles(files) { - files = await checkInputFilesValid(files); + files = await getInputFiles(files); const parallelism = cpus().length; From 1e64e52298be93f46bee98291c350a2c3f6f1ff4 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sat, 26 Dec 2020 23:26:27 +1000 Subject: [PATCH 5/8] fix reading directories --- cli/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/index.js b/cli/src/index.js index ba1107ee..c58d99c2 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -189,7 +189,7 @@ async function getInputFiles(paths) { for (const path of paths) { //allow paths ending in / of \ to get all files in that directory const files = path.endsWith('/') || path.endsWith('\\') - ? await fs.readdir(paths) + ? (await fsp.readdir(path)).map(file => join(path, file)) : [path]; for (const file of files) { try { From 10d648c28d159fc45b3a7685ce552d670c2f0c9b Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sun, 27 Dec 2020 15:59:56 +1000 Subject: [PATCH 6/8] check if path is directory using lstat instead of requiring trailing slash --- cli/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/index.js b/cli/src/index.js index c58d99c2..6098949a 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -188,7 +188,7 @@ async function getInputFiles(paths) { for (const path of paths) { //allow paths ending in / of \ to get all files in that directory - const files = path.endsWith('/') || path.endsWith('\\') + const files = (await fsp.lstat(path)).isDirectory() ? (await fsp.readdir(path)).map(file => join(path, file)) : [path]; for (const file of files) { From 935256985231aafce71929d388d57afe0e9e22ba Mon Sep 17 00:00:00 2001 From: DetachHead Date: Sun, 27 Dec 2020 16:01:02 +1000 Subject: [PATCH 7/8] remove outdated comment --- cli/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/src/index.js b/cli/src/index.js index 6098949a..390dc43d 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -187,7 +187,6 @@ async function getInputFiles(paths) { const validFiles = []; for (const path of paths) { - //allow paths ending in / of \ to get all files in that directory const files = (await fsp.lstat(path)).isDirectory() ? (await fsp.readdir(path)).map(file => join(path, file)) : [path]; From e7e205c326dfcc8c14760f42179013f91aa3ccb9 Mon Sep 17 00:00:00 2001 From: Surma Date: Tue, 5 Jan 2021 14:26:26 +0000 Subject: [PATCH 8/8] Simplify WorkerPool joining (closes #925) --- cli/src/worker_pool.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/cli/src/worker_pool.js b/cli/src/worker_pool.js index 90830f5d..57ebbfa7 100644 --- a/cli/src/worker_pool.js +++ b/cli/src/worker_pool.js @@ -24,7 +24,7 @@ function jobPromise(worker, msg) { export default class WorkerPool { constructor(numWorkers, workerFile) { - this.closing = false; + this.numWorkers = numWorkers; this.jobQueue = new TransformStream(); this.workerQueue = new TransformStream(); @@ -42,7 +42,6 @@ export default class WorkerPool { while (true) { const { value, done } = await reader.read(); if (done) { - this.workerQueue.writable.close(); await this._terminateAll(); return; } @@ -50,12 +49,6 @@ export default class WorkerPool { const worker = await this._nextWorker(); jobPromise(worker, msg).then((result) => { resolve(result); - // If we are in the process of closing, `workerQueue` is - // already closed and we can’t requeue the worker. - if (this.closing) { - worker.terminate(); - return; - } const writer = this.workerQueue.writable.getWriter(); writer.write(worker); writer.releaseLock(); @@ -71,18 +64,15 @@ export default class WorkerPool { } async _terminateAll() { - while (true) { + for (let n = 0; n < this.numWorkers; n++) { const worker = await this._nextWorker(); - if (!worker) { - return; - } worker.terminate(); } + this.workerQueue.writable.close(); } async join() { - this.closing = true; - this.jobQueue.writable.close(); + this.jobQueue.writable.getWriter().close(); await this.done; }