schnee effeckt und fehler Korektur

This commit is contained in:
2023-08-14 17:52:24 +02:00
parent 4a843d4936
commit 79af4e9907
6813 changed files with 343821 additions and 356128 deletions

164
node_modules/gulp-imagemin/index.js generated vendored
View File

@@ -1,91 +1,119 @@
'use strict';
var path = require('path');
var gutil = require('gulp-util');
var through = require('through2-concurrent');
var assign = require('object-assign');
var prettyBytes = require('pretty-bytes');
var chalk = require('chalk');
var Imagemin = require('imagemin');
var plur = require('plur');
import {createRequire} from 'node:module';
import path from 'node:path';
import process from 'node:process';
import log from 'fancy-log';
import PluginError from 'plugin-error';
import through from 'through2-concurrent';
import prettyBytes from 'pretty-bytes';
import chalk from 'chalk';
import imagemin from 'imagemin';
import plur from 'plur';
module.exports = function (opts) {
opts = assign({
// TODO: remove this when gulp get's a real logger with levels
verbose: process.argv.indexOf('--verbose') !== -1
}, opts);
const require = createRequire(import.meta.url);
var totalBytes = 0;
var totalSavedBytes = 0;
var totalFiles = 0;
var validExts = ['.jpg', '.jpeg', '.png', '.gif', '.svg'];
const PLUGIN_NAME = 'gulp-imagemin';
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
return through.obj(function (file, enc, cb) {
const loadPlugin = (plugin, ...args) => {
try {
return require(`imagemin-${plugin}`)(...args);
} catch {
log(`${PLUGIN_NAME}: Could not load default plugin \`${plugin}\``);
}
};
const exposePlugin = plugin => (...args) => loadPlugin(plugin, ...args);
const getDefaultPlugins = () => defaultPlugins.flatMap(plugin => loadPlugin(plugin));
export default function gulpImagemin(plugins, options) {
if (typeof plugins === 'object' && !Array.isArray(plugins)) {
options = plugins;
plugins = undefined;
}
options = {
// TODO: Remove this when Gulp gets a real logger with levels
silent: process.argv.includes('--silent'),
verbose: process.argv.includes('--verbose'),
...options,
};
const validExtensions = new Set(['.jpg', '.jpeg', '.png', '.gif', '.svg']);
let totalBytes = 0;
let totalSavedBytes = 0;
let totalFiles = 0;
return through.obj({
maxConcurrency: 8,
}, (file, encoding, callback) => {
if (file.isNull()) {
cb(null, file);
callback(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-imagemin', 'Streaming not supported'));
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
return;
}
if (validExts.indexOf(path.extname(file.path).toLowerCase()) === -1) {
if (opts.verbose) {
gutil.log('gulp-imagemin: Skipping unsupported image ' + chalk.blue(file.relative));
if (!validExtensions.has(path.extname(file.path).toLowerCase())) {
if (options.verbose) {
log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
}
cb(null, file);
callback(null, file);
return;
}
var imagemin = new Imagemin()
.src(file.contents)
.use(Imagemin.gifsicle({interlaced: opts.interlaced}))
.use(Imagemin.jpegtran({progressive: opts.progressive}))
.use(Imagemin.optipng({optimizationLevel: opts.optimizationLevel}))
.use(Imagemin.svgo({
plugins: opts.svgoPlugins || [],
multipass: opts.multipass
}));
const localPlugins = plugins || getDefaultPlugins();
if (opts.use) {
opts.use.forEach(imagemin.use.bind(imagemin));
}
(async () => {
try {
const data = await imagemin.buffer(file.contents, {
plugins: localPlugins,
});
const originalSize = file.contents.length;
const optimizedSize = data.length;
const saved = originalSize - optimizedSize;
const percent = originalSize > 0 ? (saved / originalSize) * 100 : 0;
const savedMessage = `saved ${prettyBytes(saved)} - ${percent.toFixed(1).replace(/\.0$/, '')}%`;
const message = saved > 0 ? savedMessage : 'already optimized';
imagemin.run(function (err, files) {
if (err) {
cb(new gutil.PluginError('gulp-imagemin:', err, {fileName: file.path}));
return;
if (saved > 0) {
totalBytes += originalSize;
totalSavedBytes += saved;
totalFiles++;
}
if (options.verbose) {
log(`${PLUGIN_NAME}:`, chalk.green('✔ ') + file.relative + chalk.gray(` (${message})`));
}
file.contents = data;
callback(null, file);
} catch (error) {
callback(new PluginError(PLUGIN_NAME, error, {fileName: file.path}));
}
})();
}, callback => {
if (!options.silent) {
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
let message = `Minified ${totalFiles} ${plur('image', totalFiles)}`;
if (totalFiles > 0) {
message += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
}
var originalSize = file.contents.length;
var optimizedSize = files[0].contents.length;
var saved = originalSize - optimizedSize;
var percent = originalSize > 0 ? (saved / originalSize) * 100 : 0;
var savedMsg = 'saved ' + prettyBytes(saved) + ' - ' + percent.toFixed(1).replace(/\.0$/, '') + '%';
var msg = saved > 0 ? savedMsg : 'already optimized';
totalBytes += originalSize;
totalSavedBytes += saved;
totalFiles++;
if (opts.verbose) {
gutil.log('gulp-imagemin:', chalk.green('✔ ') + file.relative + chalk.gray(' (' + msg + ')'));
}
file.contents = files[0].contents;
cb(null, file);
});
}, function (cb) {
var percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
var msg = 'Minified ' + totalFiles + ' ' + plur('image', totalFiles);
if (totalFiles > 0) {
msg += chalk.gray(' (saved ' + prettyBytes(totalSavedBytes) + ' - ' + percent.toFixed(1).replace(/\.0$/, '') + '%)');
log(`${PLUGIN_NAME}:`, message);
}
gutil.log('gulp-imagemin:', msg);
cb();
callback();
});
};
}
export const gifsicle = exposePlugin('gifsicle');
export const mozjpeg = exposePlugin('mozjpeg');
export const optipng = exposePlugin('optipng');
export const svgo = exposePlugin('svgo');