mirror of
https://github.com/SamEyeBam/animate.git
synced 2025-09-28 15:05:25 +00:00
larry babby and threejs for glsl
This commit is contained in:
21
webGl/my-threejs-test/node_modules/@parcel/transformer-image/LICENSE
generated
vendored
Normal file
21
webGl/my-threejs-test/node_modules/@parcel/transformer-image/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
106
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/ImageTransformer.js
generated
vendored
Normal file
106
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/ImageTransformer.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _validateConfig = require("./validateConfig");
|
||||
function _plugin() {
|
||||
const data = require("@parcel/plugin");
|
||||
_plugin = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _nullthrows() {
|
||||
const data = _interopRequireDefault(require("nullthrows"));
|
||||
_nullthrows = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
function _workers() {
|
||||
const data = _interopRequireDefault(require("@parcel/workers"));
|
||||
_workers = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
var _loadSharp = _interopRequireDefault(require("./loadSharp"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
// from https://github.com/lovell/sharp/blob/df7b8ba73808fc494be413e88cfb621b6279218c/lib/output.js#L6-L17
|
||||
const FORMATS = new Map([['jpeg', 'jpeg'], ['jpg', 'jpeg'], ['png', 'png'], ['webp', 'webp'], ['gif', 'gif'], ['tiff', 'tiff'], ['avif', 'avif'], ['heic', 'heif'], ['heif', 'heif']]);
|
||||
let isSharpLoadedOnMainThread = false;
|
||||
var _default = exports.default = new (_plugin().Transformer)({
|
||||
async loadConfig({
|
||||
config
|
||||
}) {
|
||||
let configFile = await config.getConfig(['sharp.config.json'],
|
||||
// '.sharprc', '.sharprc.json'
|
||||
{
|
||||
packageKey: 'sharp'
|
||||
});
|
||||
if (configFile !== null && configFile !== void 0 && configFile.contents) {
|
||||
(0, _validateConfig.validateConfig)(configFile.contents, configFile.filePath);
|
||||
return configFile.contents;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
async transform({
|
||||
config,
|
||||
asset,
|
||||
options
|
||||
}) {
|
||||
var _asset$query$get;
|
||||
asset.bundleBehavior = 'isolated';
|
||||
const originalFormat = FORMATS.get(asset.type);
|
||||
if (!originalFormat) {
|
||||
throw new Error(`The image transformer does not support ${asset.type} images.`);
|
||||
}
|
||||
const width = asset.query.has('width') ? parseInt(asset.query.get('width'), 10) : null;
|
||||
const height = asset.query.has('height') ? parseInt(asset.query.get('height'), 10) : null;
|
||||
const quality = asset.query.has('quality') ? parseInt(asset.query.get('quality'), 10) : config.quality;
|
||||
let targetFormat = (_asset$query$get = asset.query.get('as')) === null || _asset$query$get === void 0 ? void 0 : _asset$query$get.toLowerCase().trim();
|
||||
if (targetFormat && !FORMATS.has(targetFormat)) {
|
||||
throw new Error(`The image transformer does not support ${targetFormat} images.`);
|
||||
}
|
||||
const format = (0, _nullthrows().default)(FORMATS.get(targetFormat || originalFormat));
|
||||
const outputOptions = config[format];
|
||||
if (width || height || quality || targetFormat || outputOptions) {
|
||||
// Sharp must be required from the main thread as well to prevent errors when workers exit
|
||||
// See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
|
||||
if (_workers().default.isWorker() && !isSharpLoadedOnMainThread) {
|
||||
let api = _workers().default.getWorkerApi();
|
||||
await api.callMaster({
|
||||
location: __dirname + '/loadSharp.js',
|
||||
args: [options.packageManager, asset.filePath, options.shouldAutoInstall]
|
||||
});
|
||||
isSharpLoadedOnMainThread = true;
|
||||
}
|
||||
let inputBuffer = await asset.getBuffer();
|
||||
let sharp = await (0, _loadSharp.default)(options.packageManager, asset.filePath, options.shouldAutoInstall, true);
|
||||
let imagePipeline = sharp(inputBuffer, {
|
||||
animated: true
|
||||
});
|
||||
imagePipeline.withMetadata();
|
||||
if (width || height) {
|
||||
imagePipeline.resize(width, height);
|
||||
}
|
||||
imagePipeline.rotate();
|
||||
const normalizedOutputOptions = outputOptions || {};
|
||||
if (format === 'jpeg') {
|
||||
var _normalizedOutputOpti;
|
||||
normalizedOutputOptions.mozjpeg = (_normalizedOutputOpti = normalizedOutputOptions.mozjpeg) !== null && _normalizedOutputOpti !== void 0 ? _normalizedOutputOpti : true;
|
||||
}
|
||||
imagePipeline[format]({
|
||||
quality,
|
||||
...normalizedOutputOptions
|
||||
});
|
||||
asset.type = format;
|
||||
let buffer = await imagePipeline.toBuffer();
|
||||
asset.setBuffer(buffer);
|
||||
}
|
||||
return [asset];
|
||||
}
|
||||
});
|
15
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/loadSharp.js
generated
vendored
Normal file
15
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/loadSharp.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
const SHARP_RANGE = '^0.31.1';
|
||||
|
||||
// This is used to load sharp on the main thread, which prevents errors when worker threads exit
|
||||
// See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
|
||||
module.exports = async (packageManager, filePath, shouldAutoInstall, shouldReturn) => {
|
||||
let sharp = await packageManager.require('sharp', filePath, {
|
||||
range: SHARP_RANGE,
|
||||
shouldAutoInstall: shouldAutoInstall
|
||||
});
|
||||
if (shouldReturn) {
|
||||
return sharp;
|
||||
}
|
||||
};
|
265
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/validateConfig.js
generated
vendored
Normal file
265
webGl/my-threejs-test/node_modules/@parcel/transformer-image/lib/validateConfig.js
generated
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.validateConfig = validateConfig;
|
||||
function _utils() {
|
||||
const data = require("@parcel/utils");
|
||||
_utils = function () {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
// https://sharp.pixelplumbing.com/api-output#jpeg
|
||||
const JPEG_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
progressive: {
|
||||
type: 'boolean'
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string'
|
||||
},
|
||||
optimiseCoding: {
|
||||
type: 'boolean'
|
||||
},
|
||||
optimizeCoding: {
|
||||
type: 'boolean'
|
||||
},
|
||||
mozjpeg: {
|
||||
type: 'boolean'
|
||||
},
|
||||
trellisQuantisation: {
|
||||
type: 'boolean'
|
||||
},
|
||||
overshootDeringing: {
|
||||
type: 'boolean'
|
||||
},
|
||||
optimiseScans: {
|
||||
type: 'boolean'
|
||||
},
|
||||
optimizeScans: {
|
||||
type: 'boolean'
|
||||
},
|
||||
quantisationTable: {
|
||||
type: 'number'
|
||||
},
|
||||
quantizationTable: {
|
||||
type: 'number'
|
||||
},
|
||||
force: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#png
|
||||
const PNG_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
progressive: {
|
||||
type: 'boolean'
|
||||
},
|
||||
compressionLevel: {
|
||||
type: 'number'
|
||||
},
|
||||
adaptiveFiltering: {
|
||||
type: 'boolean'
|
||||
},
|
||||
palette: {
|
||||
type: 'boolean'
|
||||
},
|
||||
colours: {
|
||||
type: 'number'
|
||||
},
|
||||
colors: {
|
||||
type: 'number'
|
||||
},
|
||||
dither: {
|
||||
type: 'number'
|
||||
},
|
||||
force: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#webp
|
||||
const WEBP_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
alphaQuality: {
|
||||
type: 'number'
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean'
|
||||
},
|
||||
nearLossless: {
|
||||
type: 'boolean'
|
||||
},
|
||||
smartSubsample: {
|
||||
type: 'boolean'
|
||||
},
|
||||
reductionEffort: {
|
||||
type: 'number'
|
||||
},
|
||||
pageHeight: {
|
||||
type: 'number'
|
||||
},
|
||||
loop: {
|
||||
type: 'number'
|
||||
},
|
||||
delay: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
force: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#gif
|
||||
const GIF_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
pageHeight: {
|
||||
type: 'number'
|
||||
},
|
||||
loop: {
|
||||
type: 'number'
|
||||
},
|
||||
delay: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
force: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#tiff
|
||||
const TIFF_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
force: {
|
||||
type: 'boolean'
|
||||
},
|
||||
compression: {
|
||||
type: 'string'
|
||||
},
|
||||
predictor: {
|
||||
type: 'string'
|
||||
},
|
||||
pyramid: {
|
||||
type: 'boolean'
|
||||
},
|
||||
tile: {
|
||||
type: 'boolean'
|
||||
},
|
||||
tileWidth: {
|
||||
type: 'number'
|
||||
},
|
||||
tileHeight: {
|
||||
type: 'number'
|
||||
},
|
||||
xres: {
|
||||
type: 'number'
|
||||
},
|
||||
yres: {
|
||||
type: 'number'
|
||||
},
|
||||
bitdepth: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#avif
|
||||
const AVIF_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean'
|
||||
},
|
||||
speed: {
|
||||
type: 'number'
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#heif
|
||||
const HEIF_OUTPUT_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
compression: {
|
||||
type: 'string'
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean'
|
||||
},
|
||||
speed: {
|
||||
type: 'number'
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
additionalProperties: true
|
||||
};
|
||||
const CONFIG_SCHEMA = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
// Fallback quality
|
||||
quality: {
|
||||
type: 'number'
|
||||
},
|
||||
jpeg: JPEG_OUTPUT_SCHEMA,
|
||||
png: PNG_OUTPUT_SCHEMA,
|
||||
webp: WEBP_OUTPUT_SCHEMA,
|
||||
gif: GIF_OUTPUT_SCHEMA,
|
||||
tiff: TIFF_OUTPUT_SCHEMA,
|
||||
avif: AVIF_OUTPUT_SCHEMA,
|
||||
heif: HEIF_OUTPUT_SCHEMA
|
||||
},
|
||||
additionalProperties: false
|
||||
};
|
||||
function validateConfig(data, filePath) {
|
||||
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
||||
data,
|
||||
filePath
|
||||
}, '@parcel/transformer-image', 'Invalid sharp config');
|
||||
}
|
31
webGl/my-threejs-test/node_modules/@parcel/transformer-image/package.json
generated
vendored
Normal file
31
webGl/my-threejs-test/node_modules/@parcel/transformer-image/package.json
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@parcel/transformer-image",
|
||||
"version": "2.12.0",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/parcel.git"
|
||||
},
|
||||
"main": "lib/ImageTransformer.js",
|
||||
"source": "src/ImageTransformer.js",
|
||||
"engines": {
|
||||
"node": ">= 12.0.0",
|
||||
"parcel": "^2.12.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parcel/plugin": "2.12.0",
|
||||
"@parcel/utils": "2.12.0",
|
||||
"@parcel/workers": "2.12.0",
|
||||
"nullthrows": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sharp": "^0.31.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@parcel/core": "^2.12.0"
|
||||
},
|
||||
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
|
||||
}
|
120
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/ImageTransformer.js
generated
vendored
Normal file
120
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/ImageTransformer.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// @flow
|
||||
import {validateConfig} from './validateConfig';
|
||||
import {Transformer} from '@parcel/plugin';
|
||||
import nullthrows from 'nullthrows';
|
||||
import WorkerFarm from '@parcel/workers';
|
||||
import loadSharp from './loadSharp';
|
||||
|
||||
// from https://github.com/lovell/sharp/blob/df7b8ba73808fc494be413e88cfb621b6279218c/lib/output.js#L6-L17
|
||||
const FORMATS = new Map([
|
||||
['jpeg', 'jpeg'],
|
||||
['jpg', 'jpeg'],
|
||||
['png', 'png'],
|
||||
['webp', 'webp'],
|
||||
['gif', 'gif'],
|
||||
['tiff', 'tiff'],
|
||||
['avif', 'avif'],
|
||||
['heic', 'heif'],
|
||||
['heif', 'heif'],
|
||||
]);
|
||||
|
||||
let isSharpLoadedOnMainThread = false;
|
||||
|
||||
export default (new Transformer({
|
||||
async loadConfig({config}) {
|
||||
let configFile: any = await config.getConfig(
|
||||
['sharp.config.json'], // '.sharprc', '.sharprc.json'
|
||||
{packageKey: 'sharp'},
|
||||
);
|
||||
|
||||
if (configFile?.contents) {
|
||||
validateConfig(configFile.contents, configFile.filePath);
|
||||
return configFile.contents;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
|
||||
async transform({config, asset, options}) {
|
||||
asset.bundleBehavior = 'isolated';
|
||||
|
||||
const originalFormat = FORMATS.get(asset.type);
|
||||
if (!originalFormat) {
|
||||
throw new Error(
|
||||
`The image transformer does not support ${asset.type} images.`,
|
||||
);
|
||||
}
|
||||
|
||||
const width = asset.query.has('width')
|
||||
? parseInt(asset.query.get('width'), 10)
|
||||
: null;
|
||||
const height = asset.query.has('height')
|
||||
? parseInt(asset.query.get('height'), 10)
|
||||
: null;
|
||||
const quality = asset.query.has('quality')
|
||||
? parseInt(asset.query.get('quality'), 10)
|
||||
: config.quality;
|
||||
let targetFormat = asset.query.get('as')?.toLowerCase().trim();
|
||||
if (targetFormat && !FORMATS.has(targetFormat)) {
|
||||
throw new Error(
|
||||
`The image transformer does not support ${targetFormat} images.`,
|
||||
);
|
||||
}
|
||||
|
||||
const format = nullthrows(FORMATS.get(targetFormat || originalFormat));
|
||||
const outputOptions = config[format];
|
||||
|
||||
if (width || height || quality || targetFormat || outputOptions) {
|
||||
// Sharp must be required from the main thread as well to prevent errors when workers exit
|
||||
// See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
|
||||
if (WorkerFarm.isWorker() && !isSharpLoadedOnMainThread) {
|
||||
let api = WorkerFarm.getWorkerApi();
|
||||
await api.callMaster({
|
||||
location: __dirname + '/loadSharp.js',
|
||||
args: [
|
||||
options.packageManager,
|
||||
asset.filePath,
|
||||
options.shouldAutoInstall,
|
||||
],
|
||||
});
|
||||
|
||||
isSharpLoadedOnMainThread = true;
|
||||
}
|
||||
|
||||
let inputBuffer = await asset.getBuffer();
|
||||
let sharp = await loadSharp(
|
||||
options.packageManager,
|
||||
asset.filePath,
|
||||
options.shouldAutoInstall,
|
||||
true,
|
||||
);
|
||||
|
||||
let imagePipeline = sharp(inputBuffer, {animated: true});
|
||||
|
||||
imagePipeline.withMetadata();
|
||||
|
||||
if (width || height) {
|
||||
imagePipeline.resize(width, height);
|
||||
}
|
||||
|
||||
imagePipeline.rotate();
|
||||
|
||||
const normalizedOutputOptions = outputOptions || {};
|
||||
if (format === 'jpeg') {
|
||||
normalizedOutputOptions.mozjpeg =
|
||||
normalizedOutputOptions.mozjpeg ?? true;
|
||||
}
|
||||
imagePipeline[format]({
|
||||
quality,
|
||||
...normalizedOutputOptions,
|
||||
});
|
||||
|
||||
asset.type = format;
|
||||
|
||||
let buffer = await imagePipeline.toBuffer();
|
||||
asset.setBuffer(buffer);
|
||||
}
|
||||
|
||||
return [asset];
|
||||
},
|
||||
}): Transformer);
|
23
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/loadSharp.js
generated
vendored
Normal file
23
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/loadSharp.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// @flow
|
||||
import type {PackageManager} from '@parcel/package-manager';
|
||||
import type {FilePath} from '@parcel/types';
|
||||
|
||||
const SHARP_RANGE = '^0.31.1';
|
||||
|
||||
// This is used to load sharp on the main thread, which prevents errors when worker threads exit
|
||||
// See https://sharp.pixelplumbing.com/install#worker-threads and https://github.com/lovell/sharp/issues/2263
|
||||
module.exports = async (
|
||||
packageManager: PackageManager,
|
||||
filePath: FilePath,
|
||||
shouldAutoInstall: boolean,
|
||||
shouldReturn: boolean,
|
||||
): Promise<any> => {
|
||||
let sharp = await packageManager.require('sharp', filePath, {
|
||||
range: SHARP_RANGE,
|
||||
shouldAutoInstall: shouldAutoInstall,
|
||||
});
|
||||
|
||||
if (shouldReturn) {
|
||||
return sharp;
|
||||
}
|
||||
};
|
260
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/validateConfig.js
generated
vendored
Normal file
260
webGl/my-threejs-test/node_modules/@parcel/transformer-image/src/validateConfig.js
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
// @flow
|
||||
import type {SchemaEntity} from '@parcel/utils';
|
||||
import {validateSchema} from '@parcel/utils';
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#jpeg
|
||||
const JPEG_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
progressive: {
|
||||
type: 'boolean',
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string',
|
||||
},
|
||||
optimiseCoding: {
|
||||
type: 'boolean',
|
||||
},
|
||||
optimizeCoding: {
|
||||
type: 'boolean',
|
||||
},
|
||||
mozjpeg: {
|
||||
type: 'boolean',
|
||||
},
|
||||
trellisQuantisation: {
|
||||
type: 'boolean',
|
||||
},
|
||||
overshootDeringing: {
|
||||
type: 'boolean',
|
||||
},
|
||||
optimiseScans: {
|
||||
type: 'boolean',
|
||||
},
|
||||
optimizeScans: {
|
||||
type: 'boolean',
|
||||
},
|
||||
quantisationTable: {
|
||||
type: 'number',
|
||||
},
|
||||
quantizationTable: {
|
||||
type: 'number',
|
||||
},
|
||||
force: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#png
|
||||
const PNG_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
progressive: {
|
||||
type: 'boolean',
|
||||
},
|
||||
compressionLevel: {
|
||||
type: 'number',
|
||||
},
|
||||
adaptiveFiltering: {
|
||||
type: 'boolean',
|
||||
},
|
||||
palette: {
|
||||
type: 'boolean',
|
||||
},
|
||||
colours: {
|
||||
type: 'number',
|
||||
},
|
||||
colors: {
|
||||
type: 'number',
|
||||
},
|
||||
dither: {
|
||||
type: 'number',
|
||||
},
|
||||
force: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#webp
|
||||
const WEBP_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
alphaQuality: {
|
||||
type: 'number',
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean',
|
||||
},
|
||||
nearLossless: {
|
||||
type: 'boolean',
|
||||
},
|
||||
smartSubsample: {
|
||||
type: 'boolean',
|
||||
},
|
||||
reductionEffort: {
|
||||
type: 'number',
|
||||
},
|
||||
pageHeight: {
|
||||
type: 'number',
|
||||
},
|
||||
loop: {
|
||||
type: 'number',
|
||||
},
|
||||
delay: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
force: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#gif
|
||||
const GIF_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
pageHeight: {
|
||||
type: 'number',
|
||||
},
|
||||
loop: {
|
||||
type: 'number',
|
||||
},
|
||||
delay: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
force: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#tiff
|
||||
const TIFF_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
force: {
|
||||
type: 'boolean',
|
||||
},
|
||||
compression: {
|
||||
type: 'string',
|
||||
},
|
||||
predictor: {
|
||||
type: 'string',
|
||||
},
|
||||
pyramid: {
|
||||
type: 'boolean',
|
||||
},
|
||||
tile: {
|
||||
type: 'boolean',
|
||||
},
|
||||
tileWidth: {
|
||||
type: 'number',
|
||||
},
|
||||
tileHeight: {
|
||||
type: 'number',
|
||||
},
|
||||
xres: {
|
||||
type: 'number',
|
||||
},
|
||||
yres: {
|
||||
type: 'number',
|
||||
},
|
||||
bitdepth: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#avif
|
||||
const AVIF_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean',
|
||||
},
|
||||
speed: {
|
||||
type: 'number',
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
// https://sharp.pixelplumbing.com/api-output#heif
|
||||
const HEIF_OUTPUT_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
compression: {
|
||||
type: 'string',
|
||||
},
|
||||
lossless: {
|
||||
type: 'boolean',
|
||||
},
|
||||
speed: {
|
||||
type: 'number',
|
||||
},
|
||||
chromaSubsampling: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
additionalProperties: true,
|
||||
};
|
||||
|
||||
const CONFIG_SCHEMA: SchemaEntity = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
// Fallback quality
|
||||
quality: {
|
||||
type: 'number',
|
||||
},
|
||||
jpeg: JPEG_OUTPUT_SCHEMA,
|
||||
png: PNG_OUTPUT_SCHEMA,
|
||||
webp: WEBP_OUTPUT_SCHEMA,
|
||||
gif: GIF_OUTPUT_SCHEMA,
|
||||
tiff: TIFF_OUTPUT_SCHEMA,
|
||||
avif: AVIF_OUTPUT_SCHEMA,
|
||||
heif: HEIF_OUTPUT_SCHEMA,
|
||||
},
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
export function validateConfig(data: any, filePath: string) {
|
||||
validateSchema.diagnostic(
|
||||
CONFIG_SCHEMA,
|
||||
{data, filePath},
|
||||
'@parcel/transformer-image',
|
||||
'Invalid sharp config',
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user