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
|
||||
|
||||
# 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,
|
||||
"paths": {
|
||||
"static-build/*": ["src/static-build/*"],
|
||||
"image-worker/*": ["src/image-worker/*"],
|
||||
"worker-main-shared/*": ["src/worker-main-shared/*"]
|
||||
"features/*": ["src/features/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,24 +22,31 @@ export default function () {
|
||||
return {
|
||||
name: 'image-worker-plugin',
|
||||
async buildStart() {
|
||||
const base = path.join(process.cwd(), 'src', 'image-worker');
|
||||
const dirs = (
|
||||
await globP('*/', {
|
||||
const base = path.join(process.cwd(), 'src', 'features', 'worker');
|
||||
const tsImports = (
|
||||
await globP('../*/**/worker/*.ts', {
|
||||
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`,
|
||||
`import { expose } from 'comlink';`,
|
||||
`import { timed } from './util';`,
|
||||
dirs.map((dir) => `import ${dir} from './${dir}';`),
|
||||
tsNames.map(([path, name]) => `import ${name} from './${path}';`),
|
||||
`const exports = {`,
|
||||
dirs.map((dir) => [
|
||||
` ${dir}(`,
|
||||
` ...args: Parameters<typeof ${dir}>`,
|
||||
` ): ReturnType<typeof ${dir}> {`,
|
||||
` return timed('${dir}', () => ${dir}(...args));`,
|
||||
tsNames.map(([_, name]) => [
|
||||
` ${name}(`,
|
||||
` ...args: Parameters<typeof ${name}>`,
|
||||
` ): ReturnType<typeof ${name}> {`,
|
||||
` return timed('${name}', () => ${name}(...args));`,
|
||||
` },`,
|
||||
]),
|
||||
`};`,
|
||||
@@ -49,7 +56,23 @@ export default function () {
|
||||
.flat(Infinity)
|
||||
.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",
|
||||
"scripts": {
|
||||
"build": "rollup -c && node lib/move-output.js",
|
||||
"debug": "node --inspect-brk node_modules/.bin/rollup -c",
|
||||
"dev": "rollup -cw & npm run serve",
|
||||
"serve": "serve --config server.json .tmp/build/static"
|
||||
},
|
||||
|
||||
@@ -54,8 +54,7 @@ export default async function ({ watch }) {
|
||||
resolveDirsPlugin([
|
||||
'src/static-build',
|
||||
'src/client',
|
||||
'src/image-worker',
|
||||
'src/worker-main-shared',
|
||||
'src/features',
|
||||
'codecs',
|
||||
]),
|
||||
assetPlugin(),
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { wrap } from 'comlink';
|
||||
import workerURL from 'omt:image-worker';
|
||||
import workerURL from 'omt:features/worker';
|
||||
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 api = wrap<ProcessorWorkerApi>(worker);
|
||||
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
"lib": ["esnext", "dom", "dom.iterable"],
|
||||
"types": []
|
||||
},
|
||||
"references": [{ "path": "../image-worker" }]
|
||||
"references": [{ "path": "../features/worker" }]
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
import avifDecoder, { AVIFModule } from 'codecs/avif/dec/avif_dec';
|
||||
import wasmUrl from 'url:codecs/avif/dec/avif_dec.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
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 wasmUrl from 'url:codecs/webp/dec/webp_dec.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
let emscriptenModule: Promise<WebPModule>;
|
||||
|
||||
@@ -15,7 +15,7 @@ import avifEncoder, {
|
||||
EncodeOptions,
|
||||
} from 'codecs/avif/enc/avif_enc';
|
||||
import wasmUrl from 'url:codecs/avif/enc/avif_enc.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
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,
|
||||
} from 'codecs/mozjpeg_enc/mozjpeg_enc';
|
||||
import wasmUrl from 'url:codecs/mozjpeg_enc/mozjpeg_enc.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
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,
|
||||
} from 'codecs/webp/enc/webp_enc';
|
||||
import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
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 wasmUrl from 'url:codecs/imagequant/imagequant.wasm';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
import { initEmscriptenModule } from 'features/util';
|
||||
|
||||
export interface QuantizeOptions {
|
||||
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": {
|
||||
"lib": ["webworker", "esnext"]
|
||||
},
|
||||
"include": ["util.ts", "*.d.ts"],
|
||||
"references": []
|
||||
}
|
||||
@@ -32,8 +32,3 @@ export function clamp(
|
||||
): number {
|
||||
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": [
|
||||
{ "path": "./src/client" },
|
||||
{ "path": "./src/static-build" },
|
||||
{ "path": "./src/image-worker" }
|
||||
{ "path": "./src/features/worker" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user