-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from perimetre/3.3.0
3.3.0
- Loading branch information
Showing
9 changed files
with
14,649 additions
and
9,951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
import SVGOptimizer from 'svgo'; | ||
import { OptimizeOptions, optimize } from 'svgo'; | ||
import { nanoid } from 'nanoid'; | ||
|
||
/** | ||
* Returns an instance of SVGO | ||
* | ||
* @param root0 The options setting | ||
* @param root0.datauri Output as Data URI string. | ||
* @param root0.prefixIds prefix IDs and classes with the SVG filename or an arbitrary string | ||
* @param root0.removeOffCanvasPaths removes elements that are drawn outside of the viewbox | ||
* @param root0.removeRasterImages remove raster images | ||
* @param root0.removeXMLNS removes xmlns attribute (for inline svg) | ||
* @param root0.removeColors remove color attributes (to make sure it works with all colors) | ||
* @param svgString The SVG to be optimized | ||
* @param datauri Output as Data URI string. | ||
* @param root1 The options setting | ||
* @param root1.prefixIds prefix IDs and classes with the SVG filename or an arbitrary string | ||
* @param root1.removeOffCanvasPaths removes elements that are drawn outside of the viewbox | ||
* @param root1.removeRasterImages remove raster images | ||
* @param root1.removeXMLNS removes xmlns attribute (for inline svg) | ||
* @param root1.removeColors remove color attributes (to make sure it works with all colors) | ||
*/ | ||
export const getSvgo = ({ | ||
datauri, | ||
prefixIds, | ||
removeOffCanvasPaths, | ||
removeRasterImages, | ||
removeXMLNS, | ||
removeColors | ||
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
Record<string, any>) => | ||
new SVGOptimizer({ | ||
export const getSvgo = ( | ||
svgString: string | Buffer, | ||
datauri: OptimizeOptions['datauri'], | ||
{ | ||
prefixIds, | ||
removeOffCanvasPaths, | ||
removeRasterImages, | ||
removeXMLNS, | ||
removeColors | ||
}: Record<string, boolean | undefined> | ||
) => | ||
optimize(svgString, { | ||
multipass: true, | ||
datauri, | ||
plugins: [ | ||
{ removeDimensions: false }, | ||
{ removeViewBox: false }, | ||
...(prefixIds ? [{ prefixIds: { delim: `_${nanoid(5)}_` } }] : []), | ||
...(removeOffCanvasPaths ? [{ removeOffCanvasPaths: true }] : []), | ||
...(removeRasterImages ? [{ removeRasterImages: true }] : []), | ||
...(removeXMLNS ? [{ removeXMLNS: true }] : []), | ||
...(removeColors ? [{ removeAttrs: { attrs: '(stroke|fill)' } }] : []) | ||
{ name: 'removeDimensions', active: false }, | ||
{ name: 'removeViewBox', active: false }, | ||
{ name: 'prefixIds', params: { delim: `_${nanoid(5)}_` }, active: prefixIds }, | ||
{ name: 'removeOffCanvasPaths', active: removeOffCanvasPaths }, | ||
{ name: 'removeRasterImages', active: removeRasterImages }, | ||
{ name: 'removeXMLNS', active: removeXMLNS }, | ||
{ name: 'removeAttrs', params: { attrs: '(stroke|fill)' }, active: removeColors } | ||
] | ||
}); |