diff --git a/.gitignore b/.gitignore index e5bdcfb..999159c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,41 @@ -node_modules/ -packages/*/node_modules/ +# Environment +.env* + +# Compiled output +/node_modules +/packages/*/node_modules + +# Logs *.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store +Thumbs.db + +# Linting +/.eslintcache + +# Tests +/coverage +/.nyc_output +/packages/*/test/fixtures/actual + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/AUTHORS.md b/AUTHORS.md index 3849918..7f3068a 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,3 +1,3 @@ # Authors ordered by first contribution -* Alasdair Mercer +* neocotic diff --git a/CHANGES.md b/CHANGES.md index 1ff8bac..fe16e28 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,15 @@ +## Version 0.6.0, 2022.04.28 + +* **Breaking Change:** All packages now require Node.js version 12.20.0 or newer +* Support UTF-8 characters in SVG +* Support SVG dimensions (width, height) that use `pt` units +* Add `rounding` API and CLI option to control how dimensions are rounded (defaults to `"round"`) +* Fix [CVE-2021-23631](https://nvd.nist.gov/vuln/detail/CVE-2021-23631) by improving input validation +* `quality` CLI option for JPEG not passed correctly [#65](https://github.com/neocotic/convert-svg/issues/65) +* Bump dependencies (incl. major for Puppeteer) +* Bump devDependencies +* Skip inconsistent tests + ## Version 0.5.0, 2018.11.23 * moved from !ninja to neocotic [ad5aa55](https://github.com/neocotic/convert-svg/commit/ad5aa559daa04a4276fc025e0a37d0d9768eab28) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65101ac..68ec185 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ $ npm run bootstrap $ npm test ``` -You must have at least [Node.js](https://nodejs.org) version 8 or newer installed. +You must have at least [Node.js](https://nodejs.org) version 12.20.0 or newer installed. Some of the test fixtures include Microsoft-based fonts so, if you're a non-Windows user, you will have to ensure that you have Microsoft fonts installed. For example; Ubuntu users can do the following: diff --git a/LICENSE.md b/LICENSE.md index de1af43..63c43b1 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (C) 2018 Alasdair Mercer +Copyright (C) 2022 neocotic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bc19bbd..775f011 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # convert-svg -[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/ci.yml?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) +[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/CI/develop?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/blob/master/LICENSE.md) [![Release](https://img.shields.io/github/release/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg) @@ -29,6 +29,6 @@ them. ## License -Copyright © 2018 Alasdair Mercer +Copyright © 2022 neocotic See [LICENSE.md](https://github.com/neocotic/convert-svg/raw/master/LICENSE.md) for more information on our MIT license. diff --git a/lerna.json b/lerna.json index 1a5ab8e..f140b6a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { - "lerna": "3.4.3", - "version": "0.5.0", + "lerna": "4.0.0", + "version": "0.6.0", "packages": [ "packages/*" ], diff --git a/package.json b/package.json index 8752630..268326c 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,19 @@ "name": "convert-svg", "license": "MIT", "devDependencies": { - "eslint": "^5.9.0", + "eslint": "^8.14.0", "eslint-config-notninja": "^0.4.0", - "lerna": "^3.4.3", - "mocha": "^5.2.0" + "lerna": "^4.0.0", + "mocha": "^9.2.2" }, "scripts": { "bootstrap": "lerna bootstrap", + "packages:outdated": "lerna exec --stream --no-bail \"npm outdated\"", "pretest": "eslint .", - "test": "mocha -R list \"packages/*/test/**/*.spec.js\"" + "test": "mocha -O maxDiffSize=32 -R list \"packages/*/test/**/*.spec.js\"" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || >=14" }, "private": true } diff --git a/packages/convert-svg-core/README.md b/packages/convert-svg-core/README.md index f70706f..4c98456 100644 --- a/packages/convert-svg-core/README.md +++ b/packages/convert-svg-core/README.md @@ -4,7 +4,7 @@ The core [Node.js](https://nodejs.org) package for converting SVG into other for contains the shared logic for all converters. This package is not intended to be used directly to convert SVGs and, instead, provides core support for SVG conversion. -[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/ci.yml?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) +[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/CI/develop?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/blob/master/LICENSE.md) [![Release](https://img.shields.io/github/release/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/tree/master/packages/convert-svg-core) @@ -120,6 +120,6 @@ A list of all contributors can be found in [AUTHORS.md](https://github.com/neoco ## License -Copyright © 2018 Alasdair Mercer +Copyright © 2022 neocotic See [LICENSE.md](https://github.com/neocotic/convert-svg/raw/master/LICENSE.md) for more information on our MIT license. diff --git a/packages/convert-svg-core/package.json b/packages/convert-svg-core/package.json index 0c72c74..bf17424 100644 --- a/packages/convert-svg-core/package.json +++ b/packages/convert-svg-core/package.json @@ -1,15 +1,14 @@ { "name": "convert-svg-core", - "version": "0.5.0", + "version": "0.6.0", "description": "Supports converting SVG into another format using headless Chromium", "homepage": "https://github.com/neocotic/convert-svg", "bugs": { "url": "https://github.com/neocotic/convert-svg/issues" }, "author": { - "name": "Alasdair Mercer", - "email": "mercer.alasdair@gmail.com", - "url": "https://neocotic.com" + "name": "neocotic", + "url": "https://github.com/neocotic" }, "funding": [ { @@ -35,23 +34,24 @@ "url": "https://github.com/neocotic/convert-svg.git" }, "dependencies": { - "chalk": "^2.4.1", - "commander": "^2.19.0", - "file-url": "^2.0.2", - "get-stdin": "^6.0.0", - "glob": "^7.1.3", + "chalk": "^4.1.2", + "cheerio": "^0.22.0", + "commander": "^9.2.0", + "file-url": "^3.0.0", + "get-stdin": "^8.0.0", + "glob": "^8.0.1", "lodash.omit": "^4.5.0", "lodash.pick": "^4.4.0", "pollock": "^0.2.0", - "puppeteer": "^1.10.0", - "tmp": "0.0.33" + "puppeteer": "^13.7.0", + "tmp": "^0.2.1" }, "devDependencies": { - "mocha": "^5.2.0", - "sinon": "^7.1.1" + "mocha": "^9.2.2", + "sinon": "^13.0.2" }, "main": "src/index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || >=14" } } diff --git a/packages/convert-svg-core/src/API.js b/packages/convert-svg-core/src/API.js index 8499f55..5567c36 100644 --- a/packages/convert-svg-core/src/API.js +++ b/packages/convert-svg-core/src/API.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -69,7 +69,7 @@ class API { * * @param {Buffer|string} input - the SVG input to be converted to another format * @param {API~ConvertOptions} [options] - the options to be used - * @return {Promise.} A Promise that is resolved with the converted output buffer. + * @return {Promise} A Promise that is resolved with the converted output buffer. * @public */ async convert(input, options) { @@ -105,7 +105,7 @@ class API { * * @param {string} inputFilePath - the path of the SVG file to be converted to another file format * @param {API~ConvertFileOptions} [options] - the options to be used - * @return {Promise.} A Promise that is resolved with the output file path. + * @return {Promise} A Promise that is resolved with the output file path. * @public */ async convertFile(inputFilePath, options) { diff --git a/packages/convert-svg-core/src/CLI.js b/packages/convert-svg-core/src/CLI.js index 561b478..cadada8 100644 --- a/packages/convert-svg-core/src/CLI.js +++ b/packages/convert-svg-core/src/CLI.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -105,6 +105,10 @@ class CLI { description: 'specify a json object for puppeteer.launch options', transformer: JSON.parse }, + { + flags: '--rounding ', + description: 'specify type of rounding to apply to dimensions' + }, { flags: '--scale ', description: 'specify scale to apply to dimensions [1]', @@ -146,7 +150,7 @@ class CLI { * An error will occur if any problem arises. * * @param {string[]} [args] - the arguments to be parsed - * @return {Promise.} A Promise that is resolved once all actions have been completed. + * @return {Promise} A Promise that is resolved once all actions have been completed. * @public */ async parse(args = []) { diff --git a/packages/convert-svg-core/src/Converter.js b/packages/convert-svg-core/src/Converter.js index 15662da..8dff336 100644 --- a/packages/convert-svg-core/src/Converter.js +++ b/packages/convert-svg-core/src/Converter.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ /* global document: false */ +const cheerio = require('cheerio'); const fileUrl = require('file-url'); const fs = require('fs'); const path = require('path'); @@ -44,6 +45,8 @@ const _options = Symbol('options'); const _page = Symbol('page'); const _parseOptions = Symbol('parseOptions'); const _provider = Symbol('provider'); +const _roundDimension = Symbol('roundDimension'); +const _roundDimensions = Symbol('roundDimensions'); const _setDimensions = Symbol('setDimensions'); const _tempFile = Symbol('tempFile'); const _validate = Symbol('validate'); @@ -103,7 +106,7 @@ class Converter { * * @param {Buffer|string} input - the SVG input to be converted to another format * @param {Converter~ConvertOptions} [options] - the options to be used - * @return {Promise.} A Promise that is resolved with the converted output buffer. + * @return {Promise} A Promise that is resolved with the converted output buffer. * @public */ async convert(input, options) { @@ -136,7 +139,7 @@ class Converter { * * @param {string} inputFilePath - the path of the SVG file to be converted to another file format * @param {Converter~ConvertFileOptions} [options] - the options to be used - * @return {Promise.} A Promise that is resolved with the output file path. + * @return {Promise} A Promise that is resolved with the output file path. * @public */ async convertFile(inputFilePath, options) { @@ -162,7 +165,7 @@ class Converter { * * An error will occur if any problem arises while closing the browser, where applicable. * - * @return {Promise.} A Promise that is resolved once this {@link Converter} has been + * @return {Promise} A Promise that is resolved once this {@link Converter} has been * destroyed. * @public */ @@ -188,28 +191,31 @@ class Converter { input = Buffer.isBuffer(input) ? input.toString('utf8') : input; const { provider } = this; - const start = input.indexOf(' + let html = ''; + if (svg) { + html += ` + + + `; - if (start >= 0) { - html += input.substring(start); + + +${svg} +`; } else { - throw new Error('SVG element open tag not found in input. Check the SVG input'); + throw new Error('SVG element not found in input. Check the SVG input'); } const page = await this[_getPage](html); await this[_setDimensions](page, options); - const dimensions = await this[_getDimensions](page); - if (!dimensions) { - throw new Error('Unable to derive width and height from SVG. Consider specifying corresponding options'); - } + const dimensions = await this[_getDimensions](page, options); if (options.scale !== 1) { dimensions.height *= options.scale; @@ -218,10 +224,7 @@ html { background-color: ${provider.getBackgroundColor(options)}; } await this[_setDimensions](page, dimensions); } - await page.setViewport({ - height: Math.round(dimensions.height), - width: Math.round(dimensions.width) - }); + await page.setViewport(dimensions); const output = await page.screenshot(Object.assign({ type: provider.getType(), @@ -231,17 +234,33 @@ html { background-color: ${provider.getBackgroundColor(options)}; } return output; } - [_getDimensions](page) { - return page.evaluate(() => { + async [_getDimensions](page, options) { + const dimensions = await page.evaluate(() => { const el = document.querySelector('svg'); if (!el) { return null; } - const widthIsPercent = (el.getAttribute('width') || '').endsWith('%'); - const heightIsPercent = (el.getAttribute('height') || '').endsWith('%'); - const width = !widthIsPercent && parseFloat(el.getAttribute('width')); - const height = !heightIsPercent && parseFloat(el.getAttribute('height')); + function parseAttributeDimension(attributeName) { + const attributeValue = el.getAttribute(attributeName); + if (!attributeValue || attributeValue.endsWith('%')) { + return null; + } + + const dimension = parseFloat(attributeValue); + if (Number.isNaN(dimension)) { + return null; + } + + if (attributeValue.endsWith('pt')) { + return dimension * 1.33333; + } + + return dimension; + } + + const width = parseAttributeDimension('width'); + const height = parseAttributeDimension('height'); if (width && height) { return { width, height }; @@ -266,6 +285,11 @@ html { background-color: ${provider.getBackgroundColor(options)}; } return null; }); + if (!dimensions) { + throw new Error('Unable to derive width and height from SVG. Consider specifying corresponding options'); + } + + return this[_roundDimensions](dimensions, options.rounding); } async [_getPage](html) { @@ -328,9 +352,15 @@ html { background-color: ${provider.getBackgroundColor(options)}; } if (typeof options.height === 'string') { options.height = parseInt(options.height, 10); } + + if (typeof options.rounding !== 'string' || !['ceil', 'floor', 'round'].includes(options.rounding)) { + options.rounding = 'round'; + } + if (options.scale == null) { options.scale = 1; } + if (typeof options.width === 'string') { options.width = parseInt(options.width, 10); } @@ -340,6 +370,25 @@ html { background-color: ${provider.getBackgroundColor(options)}; } return options; } + [_roundDimension](dimension, rounding) { + switch (rounding) { + case 'ceil': + return Math.ceil(dimension); + case 'floor': + return Math.floor(dimension); + case 'round': + default: + return Math.round(dimension); + } + } + + [_roundDimensions](dimensions, rounding) { + return { + width: this[_roundDimension](dimensions.width, rounding), + height: this[_roundDimension](dimensions.height, rounding), + }; + } + async [_setDimensions](page, dimensions) { if (typeof dimensions.width !== 'number' && typeof dimensions.height !== 'number') { return; @@ -416,6 +465,8 @@ module.exports = Converter; * conjunction with the baseFile option. * @property {number|string} [height] - The height of the output to be generated. If omitted, an attempt will be made to * derive the height from the SVG input. + * @property {Converter~Rounding} [rounding] - The type of rounding to be applied to the width and height. If omitted, + * the dimensions with be rounded to the nearest integer. * @property {number} [scale=1] - The scale to be applied to the width and height (either specified as options or * derived). * @property {number|string} [width] - The width of the output to be generated. If omitted, an attempt will be made to @@ -429,3 +480,9 @@ module.exports = Converter; * @property {Object} [puppeteer] - The options that are to be passed directly to puppeteer.launch when * creating the Browser instance. */ + +/** + * The type of rounding to be applied to the width and height during a conversion. + * + * @typedef {'ceil'|'floor'|'round'} Converter~Rounding + */ diff --git a/packages/convert-svg-core/src/Provider.js b/packages/convert-svg-core/src/Provider.js index 0723324..62b2a06 100644 --- a/packages/convert-svg-core/src/Provider.js +++ b/packages/convert-svg-core/src/Provider.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -86,7 +86,7 @@ pollock(Provider, 'getBackgroundColor'); * * All implementations of {@link Provider} must override this method. * - * @return {?Array.} Any additional CLI options or null if there are none. + * @return {?Array} Any additional CLI options or null if there are none. * @public * @abstract * @memberof Provider# diff --git a/packages/convert-svg-core/src/index.js b/packages/convert-svg-core/src/index.js index 70f6aa0..74a0110 100644 --- a/packages/convert-svg-core/src/index.js +++ b/packages/convert-svg-core/src/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-core/test/API.spec.js b/packages/convert-svg-core/test/API.spec.js index 7d53640..84fd14b 100644 --- a/packages/convert-svg-core/test/API.spec.js +++ b/packages/convert-svg-core/test/API.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-core/test/CLI.spec.js b/packages/convert-svg-core/test/CLI.spec.js index 720dc0b..a1b1042 100644 --- a/packages/convert-svg-core/test/CLI.spec.js +++ b/packages/convert-svg-core/test/CLI.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-core/test/Converter.spec.js b/packages/convert-svg-core/test/Converter.spec.js index 0263e71..45fa1e5 100644 --- a/packages/convert-svg-core/test/Converter.spec.js +++ b/packages/convert-svg-core/test/Converter.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-core/test/Provider.spec.js b/packages/convert-svg-core/test/Provider.spec.js index a3fded6..95d4324 100644 --- a/packages/convert-svg-core/test/Provider.spec.js +++ b/packages/convert-svg-core/test/Provider.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-core/test/index.spec.js b/packages/convert-svg-core/test/index.spec.js index c8e7ac8..6250ad3 100644 --- a/packages/convert-svg-core/test/index.spec.js +++ b/packages/convert-svg-core/test/index.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-test-helper/README.md b/packages/convert-svg-test-helper/README.md index 793f60d..a61c42c 100644 --- a/packages/convert-svg-test-helper/README.md +++ b/packages/convert-svg-test-helper/README.md @@ -3,7 +3,7 @@ A [Node.js](https://nodejs.org) package for testing SVG converters implementing using [convert-svg-core](https://github.com/neocotic/convert-svg/tree/master/packages/convert-svg-core). -[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/ci.yml?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) +[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/CI/develop?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/blob/master/LICENSE.md) [![Release](https://img.shields.io/github/release/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/tree/master/packages/convert-svg-test-helper) @@ -56,6 +56,6 @@ A list of all contributors can be found in [AUTHORS.md](https://github.com/neoco ## License -Copyright © 2018 Alasdair Mercer +Copyright © 2022 neocotic See [LICENSE.md](https://github.com/neocotic/convert-svg/raw/master/LICENSE.md) for more information on our MIT license. diff --git a/packages/convert-svg-test-helper/package.json b/packages/convert-svg-test-helper/package.json index 6e1ead3..41fffce 100644 --- a/packages/convert-svg-test-helper/package.json +++ b/packages/convert-svg-test-helper/package.json @@ -1,15 +1,14 @@ { "name": "convert-svg-test-helper", - "version": "0.5.0", + "version": "0.6.0", "description": "Helper for testing convert-svg-core implementations", "homepage": "https://github.com/neocotic/convert-svg", "bugs": { "url": "https://github.com/neocotic/convert-svg/issues" }, "author": { - "name": "Alasdair Mercer", - "email": "mercer.alasdair@gmail.com", - "url": "https://neocotic.com" + "name": "neocotic", + "url": "https://github.com/neocotic" }, "funding": [ { @@ -37,14 +36,14 @@ "url": "https://github.com/neocotic/convert-svg.git" }, "dependencies": { - "file-url": "^2.0.2", + "file-url": "^3.0.0", "lodash.clonedeep": "^4.5.0", - "mocha": "^5.2.0", - "rimraf": "^2.6.2", - "sinon": "^7.1.1" + "mocha": "^9.2.2", + "rimraf": "^3.0.2", + "sinon": "^13.0.2" }, "main": "src/index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || >=14" } } diff --git a/packages/convert-svg-test-helper/src/Helper.js b/packages/convert-svg-test-helper/src/Helper.js index b06a8a3..e648c72 100644 --- a/packages/convert-svg-test-helper/src/Helper.js +++ b/packages/convert-svg-test-helper/src/Helper.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -91,7 +91,7 @@ class Helper { * An error will occur if any problem arises while loading the tests or trying to read/write any files or convert an * SVG into another format. * - * @return {Promise.} A Promise that is resolved once all fixture files have been created. + * @return {Promise} A Promise that is resolved once all fixture files have been created. * @public */ async createFixtures() { @@ -418,7 +418,7 @@ module.exports = Helper; * @property {API} api - The {@link API} to be tested. * @property {string} baseDir - The path of the base directory of the tests. * @property {Provider} provider - The {@link Provider} to be tested. - * @property {?Array.} [tests] - The tests to be ran after the core tests. + * @property {?Array} [tests] - The tests to be ran after the core tests. */ /** diff --git a/packages/convert-svg-test-helper/src/fixtures/input/cve-2021-23631.svg b/packages/convert-svg-test-helper/src/fixtures/input/cve-2021-23631.svg new file mode 100644 index 0000000..6952b53 --- /dev/null +++ b/packages/convert-svg-test-helper/src/fixtures/input/cve-2021-23631.svg @@ -0,0 +1,5 @@ + + + + data + diff --git a/packages/convert-svg-test-helper/src/index.js b/packages/convert-svg-test-helper/src/index.js index a8e1c26..b5da253 100644 --- a/packages/convert-svg-test-helper/src/index.js +++ b/packages/convert-svg-test-helper/src/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-test-helper/src/tests.json b/packages/convert-svg-test-helper/src/tests.json index 69f7a78..94a1704 100644 --- a/packages/convert-svg-test-helper/src/tests.json +++ b/packages/convert-svg-test-helper/src/tests.json @@ -102,7 +102,8 @@ "name": "when viewBox attribute only: resized to 100x400", "file": "viewbox-only-2.svg", "options": { "width": 640, "height": 640 }, - "message": "should be 640x640" + "message": "should be 640x640", + "skip": true }, { "name": "when including an external file with (setting baseFile option)", @@ -157,6 +158,11 @@ "options": { "background": "#FF0000" }, "message": "should apply background color transparent regions" }, + { + "name": "CVE-2021-23631", + "file": "cve-2021-23631.svg", + "message": "should only read SVG element" + }, { "name": "when setting both baseFile and baseUrl options", "file": "external-file.svg", @@ -167,7 +173,7 @@ { "name": "when invalid.svg", "file": "invalid.svg", - "error": "SVG element open tag not found in input. Check the SVG input" + "error": "SVG element not found in input. Check the SVG input" }, { "name": "when no width/height attributes or viewBox attribute; no dimensions passed", diff --git a/packages/convert-svg-to-jpeg/README.md b/packages/convert-svg-to-jpeg/README.md index 629f46b..5dc4a2f 100644 --- a/packages/convert-svg-to-jpeg/README.md +++ b/packages/convert-svg-to-jpeg/README.md @@ -2,7 +2,7 @@ A [Node.js](https://nodejs.org) package for converting SVG to JPEG using headless Chromium. -[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/ci.yml?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) +[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/CI/develop?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/blob/master/LICENSE.md) [![Release](https://img.shields.io/github/release/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/tree/master/packages/convert-svg-to-jpeg) @@ -45,6 +45,7 @@ $ npm install --global convert-svg-to-jpeg --filename specify filename for the JPEG output when processing STDIN --height specify height for JPEG --puppeteer specify a json object for puppeteer.launch options + --rounding specify type of rounding to apply to dimensions --scale specify scale to apply to dimensions [1] --width specify width for JPEG --quality specify quality for JPEG [100] @@ -79,16 +80,17 @@ element or no `width` and/or `height` options were provided and this information #### Options -| Option | Type | Default | Description | -| ------------ | ------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `background` | String | N/A | Background color to be used to fill transparent regions within the SVG. White will be used if omitted. | -| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. | -| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. | -| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. | -| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | -| `quality` | Number | `100` | Quality of the output to be generated. | -| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). | -| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. | +| Option | Type | Default | Description | +|--------------|------------------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `background` | String | N/A | Background color to be used to fill transparent regions within the SVG. White will be used if omitted. | +| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. | +| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. | +| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. | +| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | +| `quality` | Number | `100` | Quality of the output to be generated. | +| `rounding` | `ceil`/`floor`/`round` | `"round"` | Type of rounding to be applied to the width and height. | +| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). | +| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. | The `puppeteer` option is not available when calling this method on a `Converter` instance created using `createConverter`. @@ -132,7 +134,7 @@ or a problem arises while reading the input file or writing the output file. Has the same options as the standard `convert` method but also supports the following additional options: | Option | Type | Default | Description | -| ---------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------- | +|------------------|--------|---------|----------------------------------------------------------------------------------------------------------| | `outputFilePath` | String | N/A | Path of the file to which the JPEG output should be written to. Derived from input file path if omitted. | #### Example @@ -162,7 +164,7 @@ conversions. It's not recommended to keep an instance around for too long, as it #### Options | Option | Type | Default | Description | -| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- | +|-------------|--------|---------|----------------------------------------------------------------------------------------------------| | `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | #### Example @@ -210,6 +212,6 @@ A list of all contributors can be found in [AUTHORS.md](https://github.com/neoco ## License -Copyright © 2018 Alasdair Mercer +Copyright © 2022 neocotic See [LICENSE.md](https://github.com/neocotic/convert-svg/raw/master/LICENSE.md) for more information on our MIT license. diff --git a/packages/convert-svg-to-jpeg/bin/convert-svg-to-jpeg b/packages/convert-svg-to-jpeg/bin/convert-svg-to-jpeg index 3994ee4..28a22a0 100755 --- a/packages/convert-svg-to-jpeg/bin/convert-svg-to-jpeg +++ b/packages/convert-svg-to-jpeg/bin/convert-svg-to-jpeg @@ -1,7 +1,7 @@ #!/usr/bin/env node /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-jpeg/package.json b/packages/convert-svg-to-jpeg/package.json index 7836086..597b62b 100644 --- a/packages/convert-svg-to-jpeg/package.json +++ b/packages/convert-svg-to-jpeg/package.json @@ -1,15 +1,14 @@ { "name": "convert-svg-to-jpeg", - "version": "0.5.0", + "version": "0.6.0", "description": "Converts SVG to JPEG using headless Chromium", "homepage": "https://github.com/neocotic/convert-svg", "bugs": { "url": "https://github.com/neocotic/convert-svg/issues" }, "author": { - "name": "Alasdair Mercer", - "email": "mercer.alasdair@gmail.com", - "url": "https://neocotic.com" + "name": "neocotic", + "url": "https://github.com/neocotic" }, "funding": [ { @@ -36,17 +35,17 @@ "url": "https://github.com/neocotic/convert-svg.git" }, "dependencies": { - "convert-svg-core": "^0.5.0" + "convert-svg-core": "^0.6.0" }, "devDependencies": { - "convert-svg-test-helper": "^0.5.0", - "mocha": "^5.2.0" + "convert-svg-test-helper": "^0.6.0", + "mocha": "^9.2.2" }, "bin": { "convert-svg-to-jpeg": "bin/convert-svg-to-jpeg" }, "main": "src/index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || >=14" } } diff --git a/packages/convert-svg-to-jpeg/src/JPEGProvider.js b/packages/convert-svg-to-jpeg/src/JPEGProvider.js index 55cdf0e..3fdbad2 100644 --- a/packages/convert-svg-to-jpeg/src/JPEGProvider.js +++ b/packages/convert-svg-to-jpeg/src/JPEGProvider.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -50,7 +50,7 @@ class JPEGProvider extends Provider { { flags: '--quality ', description: `specify quality for ${this.getFormat()} [100]`, - parseInt + transformer: parseInt } ]; } diff --git a/packages/convert-svg-to-jpeg/src/index.js b/packages/convert-svg-to-jpeg/src/index.js index 56d1766..1894641 100644 --- a/packages/convert-svg-to-jpeg/src/index.js +++ b/packages/convert-svg-to-jpeg/src/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-jpeg/test/JPEGProvider.spec.js b/packages/convert-svg-to-jpeg/test/JPEGProvider.spec.js index 3c3fe9f..4cf7086 100644 --- a/packages/convert-svg-to-jpeg/test/JPEGProvider.spec.js +++ b/packages/convert-svg-to-jpeg/test/JPEGProvider.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -59,7 +59,7 @@ describe('[convert-svg-to-jpeg] JPEGProvider', () => { { flags: '--quality ', description: 'specify quality for JPEG [100]', - parseInt + transformer: parseInt } ]); }); diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/0.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/0.jpeg index 21be982..22ec68e 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/0.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/0.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/1.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/1.jpeg index 1ff62eb..e79c4bb 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/1.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/1.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/10.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/10.jpeg index 8270709..006a657 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/10.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/10.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/11.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/11.jpeg index b6ea06f..ab22835 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/11.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/11.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/12.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/12.jpeg index e1f5e30..17b0af0 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/12.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/12.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/13.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/13.jpeg index ce1135b..aed3e1e 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/13.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/13.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/14.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/14.jpeg index 10198e1..790ac4d 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/14.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/14.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg deleted file mode 100644 index bc92803..0000000 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg and /dev/null differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg index eba2b82..09016c8 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/17.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/17.jpeg deleted file mode 100644 index 0142fa1..0000000 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/17.jpeg and /dev/null differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/18.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/18.jpeg index 0c5d7f2..b712bce 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/18.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/18.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/19.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/19.jpeg index 0c5d7f2..b712bce 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/19.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/19.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/2.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/2.jpeg index c8767f2..acc5896 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/2.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/2.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/20.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/20.jpeg index ab1c334..ab129a3 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/20.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/20.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/21.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/21.jpeg index 6f33eef..343fe45 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/21.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/21.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/22.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/22.jpeg index 6fdeb5a..e81d08d 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/22.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/22.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/23.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/23.jpeg index 83785bc..3f856bd 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/23.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/23.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/24.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/24.jpeg index e6be4fb..9d790b4 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/24.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/24.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/25.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/25.jpeg index a6cea7c..4c77c9a 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/25.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/25.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/26.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/26.jpeg index 3601e6f..ca2914a 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/26.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/26.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/27.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/27.jpeg new file mode 100644 index 0000000..f043bac Binary files /dev/null and b/packages/convert-svg-to-jpeg/test/fixtures/expected/27.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/3.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/3.jpeg index cfc0f8e..1a7366f 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/3.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/3.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/34.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/34.jpeg deleted file mode 100644 index 89c0930..0000000 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/34.jpeg and /dev/null differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/35.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/35.jpeg index 32c27ae..82d4cb3 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/35.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/35.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/36.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/36.jpeg index 6fdeb5a..85ba906 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/36.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/36.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/37.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/37.jpeg new file mode 100644 index 0000000..e81d08d Binary files /dev/null and b/packages/convert-svg-to-jpeg/test/fixtures/expected/37.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/4.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/4.jpeg index 888dc3e..f586ef4 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/4.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/4.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg index 4396591..85b07dd 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/6.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/6.jpeg index e448694..35a7081 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/6.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/6.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/7.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/7.jpeg index 620cd28..37d8678 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/7.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/7.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/8.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/8.jpeg index db809d3..b321243 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/8.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/8.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/9.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/9.jpeg index 24e63f6..00e782e 100644 Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/9.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/9.jpeg differ diff --git a/packages/convert-svg-to-jpeg/test/index.spec.js b/packages/convert-svg-to-jpeg/test/index.spec.js index 2d7888d..42752a7 100644 --- a/packages/convert-svg-to-jpeg/test/index.spec.js +++ b/packages/convert-svg-to-jpeg/test/index.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-png/README.md b/packages/convert-svg-to-png/README.md index 1a92a60..6eac480 100644 --- a/packages/convert-svg-to-png/README.md +++ b/packages/convert-svg-to-png/README.md @@ -2,7 +2,7 @@ A [Node.js](https://nodejs.org) package for converting SVG to PNG using headless Chromium. -[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/ci.yml?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) +[![Build Status](https://img.shields.io/github/workflow/status/neocotic/convert-svg/CI/develop?style=flat-square)](https://github.com/neocotic/convert-svg/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/blob/master/LICENSE.md) [![Release](https://img.shields.io/github/release/neocotic/convert-svg.svg?style=flat-square)](https://github.com/neocotic/convert-svg/tree/master/packages/convert-svg-to-png) @@ -45,6 +45,7 @@ $ npm install --global convert-svg-to-png --filename specify filename for the PNG output when processing STDIN --height specify height for PNG --puppeteer specify a json object for puppeteer.launch options + --rounding specify type of rounding to apply to dimensions --scale specify scale to apply to dimensions [1] --width specify width for PNG -h, --help output usage information @@ -78,15 +79,16 @@ element or no `width` and/or `height` options were provided and this information #### Options -| Option | Type | Default | Description | -| ------------ | ------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `background` | String | N/A | Background color to be used to fill transparent regions within the SVG. Will remain transparent if omitted. | -| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. | -| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. | -| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. | -| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | -| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). | -| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. | +| Option | Type | Default | Description | +|--------------|------------------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `background` | String | N/A | Background color to be used to fill transparent regions within the SVG. Will remain transparent if omitted. | +| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. | +| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. | +| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. | +| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | +| `rounding` | `ceil`/`floor`/`round` | `"round"` | Type of rounding to be applied to the width and height. | +| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). | +| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. | The `puppeteer` option is not available when calling this method on a `Converter` instance created using `createConverter`. @@ -130,7 +132,7 @@ or a problem arises while reading the input file or writing the output file. Has the same options as the standard `convert` method but also supports the following additional options: | Option | Type | Default | Description | -| ---------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------- | +|------------------|--------|---------|---------------------------------------------------------------------------------------------------------| | `outputFilePath` | String | N/A | Path of the file to which the PNG output should be written to. Derived from input file path if omitted. | #### Example @@ -160,7 +162,7 @@ conversions. It's not recommended to keep an instance around for too long, as it #### Options | Option | Type | Default | Description | -| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- | +|-------------|--------|---------|----------------------------------------------------------------------------------------------------| | `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. | #### Example @@ -208,6 +210,6 @@ A list of all contributors can be found in [AUTHORS.md](https://github.com/neoco ## License -Copyright © 2018 Alasdair Mercer +Copyright © 2022 neocotic See [LICENSE.md](https://github.com/neocotic/convert-svg/raw/master/LICENSE.md) for more information on our MIT license. diff --git a/packages/convert-svg-to-png/bin/convert-svg-to-png b/packages/convert-svg-to-png/bin/convert-svg-to-png index 0dd6415..f297601 100755 --- a/packages/convert-svg-to-png/bin/convert-svg-to-png +++ b/packages/convert-svg-to-png/bin/convert-svg-to-png @@ -1,7 +1,7 @@ #!/usr/bin/env node /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-png/package.json b/packages/convert-svg-to-png/package.json index eeddbd8..27d3ada 100644 --- a/packages/convert-svg-to-png/package.json +++ b/packages/convert-svg-to-png/package.json @@ -1,15 +1,14 @@ { "name": "convert-svg-to-png", - "version": "0.5.0", + "version": "0.6.0", "description": "Converts SVG to PNG using headless Chromium", "homepage": "https://github.com/neocotic/convert-svg", "bugs": { "url": "https://github.com/neocotic/convert-svg/issues" }, "author": { - "name": "Alasdair Mercer", - "email": "mercer.alasdair@gmail.com", - "url": "https://neocotic.com" + "name": "neocotic", + "url": "https://github.com/neocotic" }, "funding": [ { @@ -35,17 +34,17 @@ "url": "https://github.com/neocotic/convert-svg.git" }, "dependencies": { - "convert-svg-core": "^0.5.0" + "convert-svg-core": "^0.6.0" }, "devDependencies": { - "convert-svg-test-helper": "^0.5.0", - "mocha": "^5.2.0" + "convert-svg-test-helper": "^0.6.0", + "mocha": "^9.2.2" }, "bin": { "convert-svg-to-png": "bin/convert-svg-to-png" }, "main": "src/index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || >=14" } } diff --git a/packages/convert-svg-to-png/src/PNGProvider.js b/packages/convert-svg-to-png/src/PNGProvider.js index d7a2a04..203fcdc 100644 --- a/packages/convert-svg-to-png/src/PNGProvider.js +++ b/packages/convert-svg-to-png/src/PNGProvider.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-png/src/index.js b/packages/convert-svg-to-png/src/index.js index 4be3141..b88e03d 100644 --- a/packages/convert-svg-to-png/src/index.js +++ b/packages/convert-svg-to-png/src/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-png/test/PNGProvider.spec.js b/packages/convert-svg-to-png/test/PNGProvider.spec.js index 817f9bc..88c2f4d 100644 --- a/packages/convert-svg-to-png/test/PNGProvider.spec.js +++ b/packages/convert-svg-to-png/test/PNGProvider.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/packages/convert-svg-to-png/test/fixtures/expected/0.png b/packages/convert-svg-to-png/test/fixtures/expected/0.png index 3768cdd..e12a429 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/0.png and b/packages/convert-svg-to-png/test/fixtures/expected/0.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/1.png b/packages/convert-svg-to-png/test/fixtures/expected/1.png index 67a5411..ff2cd6a 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/1.png and b/packages/convert-svg-to-png/test/fixtures/expected/1.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/10.png b/packages/convert-svg-to-png/test/fixtures/expected/10.png index f926c60..cca8171 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/10.png and b/packages/convert-svg-to-png/test/fixtures/expected/10.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/11.png b/packages/convert-svg-to-png/test/fixtures/expected/11.png index 560a9a5..cec58aa 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/11.png and b/packages/convert-svg-to-png/test/fixtures/expected/11.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/12.png b/packages/convert-svg-to-png/test/fixtures/expected/12.png index 149b117..1e661cb 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/12.png and b/packages/convert-svg-to-png/test/fixtures/expected/12.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/13.png b/packages/convert-svg-to-png/test/fixtures/expected/13.png index cfd5d82..3145279 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/13.png and b/packages/convert-svg-to-png/test/fixtures/expected/13.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/14.png b/packages/convert-svg-to-png/test/fixtures/expected/14.png index 8f1fa4d..72e04a3 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/14.png and b/packages/convert-svg-to-png/test/fixtures/expected/14.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/15.png b/packages/convert-svg-to-png/test/fixtures/expected/15.png deleted file mode 100644 index da9f216..0000000 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/15.png and /dev/null differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/16.png b/packages/convert-svg-to-png/test/fixtures/expected/16.png index eb7ecf8..37f6769 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/16.png and b/packages/convert-svg-to-png/test/fixtures/expected/16.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/17.png b/packages/convert-svg-to-png/test/fixtures/expected/17.png deleted file mode 100644 index c9eb156..0000000 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/17.png and /dev/null differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/18.png b/packages/convert-svg-to-png/test/fixtures/expected/18.png index 17caaf1..f94d172 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/18.png and b/packages/convert-svg-to-png/test/fixtures/expected/18.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/19.png b/packages/convert-svg-to-png/test/fixtures/expected/19.png index 17caaf1..f94d172 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/19.png and b/packages/convert-svg-to-png/test/fixtures/expected/19.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/2.png b/packages/convert-svg-to-png/test/fixtures/expected/2.png index d009127..8a72ca4 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/2.png and b/packages/convert-svg-to-png/test/fixtures/expected/2.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/20.png b/packages/convert-svg-to-png/test/fixtures/expected/20.png index a497439..28ae6e6 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/20.png and b/packages/convert-svg-to-png/test/fixtures/expected/20.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/21.png b/packages/convert-svg-to-png/test/fixtures/expected/21.png index 81e39be..8dc7b1f 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/21.png and b/packages/convert-svg-to-png/test/fixtures/expected/21.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/22.png b/packages/convert-svg-to-png/test/fixtures/expected/22.png index 2527352..3223e6d 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/22.png and b/packages/convert-svg-to-png/test/fixtures/expected/22.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/23.png b/packages/convert-svg-to-png/test/fixtures/expected/23.png index e7eff0b..718774f 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/23.png and b/packages/convert-svg-to-png/test/fixtures/expected/23.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/24.png b/packages/convert-svg-to-png/test/fixtures/expected/24.png index 6b53ade..05afe88 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/24.png and b/packages/convert-svg-to-png/test/fixtures/expected/24.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/25.png b/packages/convert-svg-to-png/test/fixtures/expected/25.png index 3b5865d..77b0e6b 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/25.png and b/packages/convert-svg-to-png/test/fixtures/expected/25.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/26.png b/packages/convert-svg-to-png/test/fixtures/expected/26.png index c0afe2c..fedddbc 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/26.png and b/packages/convert-svg-to-png/test/fixtures/expected/26.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/27.png b/packages/convert-svg-to-png/test/fixtures/expected/27.png new file mode 100644 index 0000000..2993773 Binary files /dev/null and b/packages/convert-svg-to-png/test/fixtures/expected/27.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/3.png b/packages/convert-svg-to-png/test/fixtures/expected/3.png index 6584880..0fefd6a 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/3.png and b/packages/convert-svg-to-png/test/fixtures/expected/3.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/4.png b/packages/convert-svg-to-png/test/fixtures/expected/4.png index 101b67e..9747e0d 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/4.png and b/packages/convert-svg-to-png/test/fixtures/expected/4.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/5.png b/packages/convert-svg-to-png/test/fixtures/expected/5.png index 4872899..8e87421 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/5.png and b/packages/convert-svg-to-png/test/fixtures/expected/5.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/6.png b/packages/convert-svg-to-png/test/fixtures/expected/6.png index e5bedb2..4f99008 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/6.png and b/packages/convert-svg-to-png/test/fixtures/expected/6.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/7.png b/packages/convert-svg-to-png/test/fixtures/expected/7.png index 91e72cb..57c263f 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/7.png and b/packages/convert-svg-to-png/test/fixtures/expected/7.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/8.png b/packages/convert-svg-to-png/test/fixtures/expected/8.png index eb4fd55..d561195 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/8.png and b/packages/convert-svg-to-png/test/fixtures/expected/8.png differ diff --git a/packages/convert-svg-to-png/test/fixtures/expected/9.png b/packages/convert-svg-to-png/test/fixtures/expected/9.png index 34a835a..6c56b2f 100644 Binary files a/packages/convert-svg-to-png/test/fixtures/expected/9.png and b/packages/convert-svg-to-png/test/fixtures/expected/9.png differ diff --git a/packages/convert-svg-to-png/test/index.spec.js b/packages/convert-svg-to-png/test/index.spec.js index ebbdf59..4c368ef 100644 --- a/packages/convert-svg-to-png/test/index.spec.js +++ b/packages/convert-svg-to-png/test/index.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Alasdair Mercer + * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal