diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:10:59 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:41:44 +0800 |
| commit | fc87c009806dcc98867f6b58efe29b042aa01dee (patch) | |
| tree | 8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/svgo/lib/svgo.js | |
| parent | 3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff) | |
node: updatemain
Diffstat (limited to 'node_modules/svgo/lib/svgo.js')
| -rw-r--r-- | node_modules/svgo/lib/svgo.js | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/node_modules/svgo/lib/svgo.js b/node_modules/svgo/lib/svgo.js deleted file mode 100644 index acb1f72e..00000000 --- a/node_modules/svgo/lib/svgo.js +++ /dev/null @@ -1,102 +0,0 @@ -'use strict'; - -const { parseSvg } = require('./parser.js'); -const { stringifySvg } = require('./stringifier.js'); -const { builtin } = require('./builtin.js'); -const { invokePlugins } = require('./svgo/plugins.js'); -const { encodeSVGDatauri } = require('./svgo/tools.js'); - -const pluginsMap = {}; -for (const plugin of builtin) { - pluginsMap[plugin.name] = plugin; -} - -const resolvePluginConfig = (plugin) => { - if (typeof plugin === 'string') { - // resolve builtin plugin specified as string - const builtinPlugin = pluginsMap[plugin]; - if (builtinPlugin == null) { - throw Error(`Unknown builtin plugin "${plugin}" specified.`); - } - return { - name: plugin, - params: {}, - fn: builtinPlugin.fn, - }; - } - if (typeof plugin === 'object' && plugin != null) { - if (plugin.name == null) { - throw Error(`Plugin name should be specified`); - } - // use custom plugin implementation - let fn = plugin.fn; - if (fn == null) { - // resolve builtin plugin implementation - const builtinPlugin = pluginsMap[plugin.name]; - if (builtinPlugin == null) { - throw Error(`Unknown builtin plugin "${plugin.name}" specified.`); - } - fn = builtinPlugin.fn; - } - return { - name: plugin.name, - params: plugin.params, - fn, - }; - } - return null; -}; - -const optimize = (input, config) => { - if (config == null) { - config = {}; - } - if (typeof config !== 'object') { - throw Error('Config should be an object'); - } - const maxPassCount = config.multipass ? 10 : 1; - let prevResultSize = Number.POSITIVE_INFINITY; - let output = ''; - const info = {}; - if (config.path != null) { - info.path = config.path; - } - for (let i = 0; i < maxPassCount; i += 1) { - info.multipassCount = i; - const ast = parseSvg(input, config.path); - const plugins = config.plugins || ['preset-default']; - if (!Array.isArray(plugins)) { - throw Error( - 'malformed config, `plugins` property must be an array.\nSee more info here: https://github.com/svg/svgo#configuration', - ); - } - const resolvedPlugins = plugins - .filter((plugin) => plugin != null) - .map(resolvePluginConfig); - - if (resolvedPlugins.length < plugins.length) { - console.warn( - 'Warning: plugins list includes null or undefined elements, these will be ignored.', - ); - } - const globalOverrides = {}; - if (config.floatPrecision != null) { - globalOverrides.floatPrecision = config.floatPrecision; - } - invokePlugins(ast, info, resolvedPlugins, null, globalOverrides); - output = stringifySvg(ast, config.js2svg); - if (output.length < prevResultSize) { - input = output; - prevResultSize = output.length; - } else { - break; - } - } - if (config.datauri) { - output = encodeSVGDatauri(output, config.datauri); - } - return { - data: output, - }; -}; -exports.optimize = optimize; |
