mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 17:49:52 +00:00
Features folder
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,4 +6,5 @@ build
|
|||||||
*.o
|
*.o
|
||||||
|
|
||||||
# Auto-generated by lib/image-worker-plugin.js
|
# Auto-generated by lib/image-worker-plugin.js
|
||||||
src/image-worker/index.ts
|
src/features/worker/index.ts
|
||||||
|
src/features/worker/tsconfig.json
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"static-build/*": ["src/static-build/*"],
|
"static-build/*": ["src/static-build/*"],
|
||||||
"image-worker/*": ["src/image-worker/*"],
|
"features/*": ["src/features/*"]
|
||||||
"worker-main-shared/*": ["src/worker-main-shared/*"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,24 +22,31 @@ export default function () {
|
|||||||
return {
|
return {
|
||||||
name: 'image-worker-plugin',
|
name: 'image-worker-plugin',
|
||||||
async buildStart() {
|
async buildStart() {
|
||||||
const base = path.join(process.cwd(), 'src', 'image-worker');
|
const base = path.join(process.cwd(), 'src', 'features', 'worker');
|
||||||
const dirs = (
|
const tsImports = (
|
||||||
await globP('*/', {
|
await globP('../*/**/worker/*.ts', {
|
||||||
cwd: base,
|
cwd: base,
|
||||||
})
|
})
|
||||||
).map((dir) => dir.slice(0, -1));
|
)
|
||||||
|
.filter((tsFile) => !tsFile.endsWith('.d.ts'))
|
||||||
|
.map((tsFile) => tsFile.slice(0, -'.ts'.length));
|
||||||
|
|
||||||
const file = [
|
const tsNames = tsImports.map((tsImport) => [
|
||||||
|
tsImport,
|
||||||
|
path.basename(tsImport),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const workerFile = [
|
||||||
`// This file is autogenerated by lib/image-worker-plugin.js`,
|
`// This file is autogenerated by lib/image-worker-plugin.js`,
|
||||||
`import { expose } from 'comlink';`,
|
`import { expose } from 'comlink';`,
|
||||||
`import { timed } from './util';`,
|
`import { timed } from './util';`,
|
||||||
dirs.map((dir) => `import ${dir} from './${dir}';`),
|
tsNames.map(([path, name]) => `import ${name} from './${path}';`),
|
||||||
`const exports = {`,
|
`const exports = {`,
|
||||||
dirs.map((dir) => [
|
tsNames.map(([_, name]) => [
|
||||||
` ${dir}(`,
|
` ${name}(`,
|
||||||
` ...args: Parameters<typeof ${dir}>`,
|
` ...args: Parameters<typeof ${name}>`,
|
||||||
` ): ReturnType<typeof ${dir}> {`,
|
` ): ReturnType<typeof ${name}> {`,
|
||||||
` return timed('${dir}', () => ${dir}(...args));`,
|
` return timed('${name}', () => ${name}(...args));`,
|
||||||
` },`,
|
` },`,
|
||||||
]),
|
]),
|
||||||
`};`,
|
`};`,
|
||||||
@@ -49,7 +56,23 @@ export default function () {
|
|||||||
.flat(Infinity)
|
.flat(Infinity)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
await fsp.writeFile(path.join(base, 'index.ts'), file);
|
const tsConfig = {
|
||||||
|
extends: '../../../generic-tsconfig.json',
|
||||||
|
compilerOptions: {
|
||||||
|
lib: ['webworker', 'esnext'],
|
||||||
|
},
|
||||||
|
references: tsImports.map((tsImport) => ({
|
||||||
|
path: path.dirname(tsImport),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
fsp.writeFile(
|
||||||
|
path.join(base, 'tsconfig.json'),
|
||||||
|
JSON.stringify(tsConfig, null, ' '),
|
||||||
|
),
|
||||||
|
fsp.writeFile(path.join(base, 'index.ts'), workerFile),
|
||||||
|
]);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"license": "apache-2.0",
|
"license": "apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rollup -c && node lib/move-output.js",
|
"build": "rollup -c && node lib/move-output.js",
|
||||||
|
"debug": "node --inspect-brk node_modules/.bin/rollup -c",
|
||||||
"dev": "rollup -cw & npm run serve",
|
"dev": "rollup -cw & npm run serve",
|
||||||
"serve": "serve --config server.json .tmp/build/static"
|
"serve": "serve --config server.json .tmp/build/static"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ export default async function ({ watch }) {
|
|||||||
resolveDirsPlugin([
|
resolveDirsPlugin([
|
||||||
'src/static-build',
|
'src/static-build',
|
||||||
'src/client',
|
'src/client',
|
||||||
'src/image-worker',
|
'src/features',
|
||||||
'src/worker-main-shared',
|
|
||||||
'codecs',
|
'codecs',
|
||||||
]),
|
]),
|
||||||
assetPlugin(),
|
assetPlugin(),
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { wrap } from 'comlink';
|
import { wrap } from 'comlink';
|
||||||
import workerURL from 'omt:image-worker';
|
import workerURL from 'omt:features/worker';
|
||||||
import imgURL from 'url:./tmp.png';
|
import imgURL from 'url:./tmp.png';
|
||||||
|
|
||||||
import type { ProcessorWorkerApi } from 'image-worker/index';
|
import type { ProcessorWorkerApi } from 'features/worker';
|
||||||
const worker = new Worker(workerURL);
|
const worker = new Worker(workerURL);
|
||||||
const api = wrap<ProcessorWorkerApi>(worker);
|
const api = wrap<ProcessorWorkerApi>(worker);
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
"lib": ["esnext", "dom", "dom.iterable"],
|
"lib": ["esnext", "dom", "dom.iterable"],
|
||||||
"types": []
|
"types": []
|
||||||
},
|
},
|
||||||
"references": [{ "path": "../image-worker" }]
|
"references": [{ "path": "../features/worker" }]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
import avifDecoder, { AVIFModule } from 'codecs/avif/dec/avif_dec';
|
import avifDecoder, { AVIFModule } from 'codecs/avif/dec/avif_dec';
|
||||||
import wasmUrl from 'url:codecs/avif/dec/avif_dec.wasm';
|
import wasmUrl from 'url:codecs/avif/dec/avif_dec.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<AVIFModule>;
|
let emscriptenModule: Promise<AVIFModule>;
|
||||||
|
|
||||||
13
src/features/decoders/avif/worker/missing-types.d.ts
vendored
Normal file
13
src/features/decoders/avif/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
7
src/features/decoders/avif/worker/tsconfig.json
Normal file
7
src/features/decoders/avif/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
13
src/features/decoders/webp/worker/missing-types.d.ts
vendored
Normal file
13
src/features/decoders/webp/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
7
src/features/decoders/webp/worker/tsconfig.json
Normal file
7
src/features/decoders/webp/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
import webpDecoder, { WebPModule } from 'codecs/webp/dec/webp_dec';
|
import webpDecoder, { WebPModule } from 'codecs/webp/dec/webp_dec';
|
||||||
import wasmUrl from 'url:codecs/webp/dec/webp_dec.wasm';
|
import wasmUrl from 'url:codecs/webp/dec/webp_dec.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<WebPModule>;
|
let emscriptenModule: Promise<WebPModule>;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ import avifEncoder, {
|
|||||||
EncodeOptions,
|
EncodeOptions,
|
||||||
} from 'codecs/avif/enc/avif_enc';
|
} from 'codecs/avif/enc/avif_enc';
|
||||||
import wasmUrl from 'url:codecs/avif/enc/avif_enc.wasm';
|
import wasmUrl from 'url:codecs/avif/enc/avif_enc.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<AVIFModule>;
|
let emscriptenModule: Promise<AVIFModule>;
|
||||||
|
|
||||||
13
src/features/encoders/avif/worker/missing-types.d.ts
vendored
Normal file
13
src/features/encoders/avif/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
7
src/features/encoders/avif/worker/tsconfig.json
Normal file
7
src/features/encoders/avif/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
13
src/features/encoders/mozjpeg/worker/missing-types.d.ts
vendored
Normal file
13
src/features/encoders/mozjpeg/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
@@ -15,7 +15,7 @@ import mozjpeg_enc, {
|
|||||||
EncodeOptions,
|
EncodeOptions,
|
||||||
} from 'codecs/mozjpeg_enc/mozjpeg_enc';
|
} from 'codecs/mozjpeg_enc/mozjpeg_enc';
|
||||||
import wasmUrl from 'url:codecs/mozjpeg_enc/mozjpeg_enc.wasm';
|
import wasmUrl from 'url:codecs/mozjpeg_enc/mozjpeg_enc.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<MozJPEGModule>;
|
let emscriptenModule: Promise<MozJPEGModule>;
|
||||||
|
|
||||||
7
src/features/encoders/mozjpeg/worker/tsconfig.json
Normal file
7
src/features/encoders/mozjpeg/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
13
src/features/encoders/webp/worker/missing-types.d.ts
vendored
Normal file
13
src/features/encoders/webp/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
7
src/features/encoders/webp/worker/tsconfig.json
Normal file
7
src/features/encoders/webp/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ import webpEncoder, {
|
|||||||
EncodeOptions,
|
EncodeOptions,
|
||||||
} from 'codecs/webp/enc/webp_enc';
|
} from 'codecs/webp/enc/webp_enc';
|
||||||
import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm';
|
import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<WebPModule>;
|
let emscriptenModule: Promise<WebPModule>;
|
||||||
|
|
||||||
13
src/features/processors/quantize/worker/missing-types.d.ts
vendored
Normal file
13
src/features/processors/quantize/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../../../missing-types.d.ts" />
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
import imagequant, { QuantizerModule } from 'codecs/imagequant/imagequant';
|
import imagequant, { QuantizerModule } from 'codecs/imagequant/imagequant';
|
||||||
import wasmUrl from 'url:codecs/imagequant/imagequant.wasm';
|
import wasmUrl from 'url:codecs/imagequant/imagequant.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from 'features/util';
|
||||||
|
|
||||||
export interface QuantizeOptions {
|
export interface QuantizeOptions {
|
||||||
zx: number;
|
zx: number;
|
||||||
7
src/features/processors/quantize/worker/tsconfig.json
Normal file
7
src/features/processors/quantize/worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../../../generic-tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["webworker", "esnext"]
|
||||||
|
},
|
||||||
|
"references": [{ "path": "../../../" }]
|
||||||
|
}
|
||||||
@@ -3,5 +3,6 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["webworker", "esnext"]
|
"lib": ["webworker", "esnext"]
|
||||||
},
|
},
|
||||||
|
"include": ["util.ts", "*.d.ts"],
|
||||||
"references": []
|
"references": []
|
||||||
}
|
}
|
||||||
@@ -32,8 +32,3 @@ export function clamp(
|
|||||||
): number {
|
): number {
|
||||||
return Math.min(Math.max(num, min), max);
|
return Math.min(Math.max(num, min), max);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function timed<T>(name: string, func: () => Promise<T>) {
|
|
||||||
console.time(name);
|
|
||||||
return func().finally(() => console.timeEnd(name));
|
|
||||||
}
|
|
||||||
13
src/features/worker/missing-types.d.ts
vendored
Normal file
13
src/features/worker/missing-types.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/// <reference path="../../../missing-types.d.ts" />
|
||||||
16
src/features/worker/util.ts
Normal file
16
src/features/worker/util.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
export function timed<T>(name: string, func: () => Promise<T>) {
|
||||||
|
console.time(name);
|
||||||
|
return func().finally(() => console.timeEnd(name));
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@
|
|||||||
"references": [
|
"references": [
|
||||||
{ "path": "./src/client" },
|
{ "path": "./src/client" },
|
||||||
{ "path": "./src/static-build" },
|
{ "path": "./src/static-build" },
|
||||||
{ "path": "./src/image-worker" }
|
{ "path": "./src/features/worker" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user