1- import { createRequire } from 'module' ;
1+ import { createRequire } from 'node: module' ;
22
33import { fromParse5 } from 'hast-util-from-parse5' ;
44import { type Code , type Parent , type Root } from 'mdast' ;
5- import { type Mermaid } from 'mermaid' ;
5+ import { type MermaidConfig } from 'mermaid' ;
66import { parseFragment } from 'parse5' ;
77import puppeteer , { type Browser , type Page , type PuppeteerLaunchOptions } from 'puppeteer-core' ;
8- import { optimize , type OptimizedSvg , type OptimizeOptions } from 'svgo' ;
8+ import { type Config , optimize } from 'svgo' ;
99import { type Plugin } from 'unified' ;
1010import { visit } from 'unist-util-visit' ;
1111
1212const mermaidScript = {
1313 path : createRequire ( import . meta. url ) . resolve ( 'mermaid/dist/mermaid.min.js' ) ,
1414} ;
1515
16- declare const mermaid : Mermaid ;
17-
18- export const defaultSVGOOptions : OptimizeOptions = {
19- js2svg : {
20- indent : 2 ,
21- pretty : true ,
22- } ,
23- multipass : false ,
24- plugins : [
25- { name : 'addAttributesToSVGElement' , active : false } ,
26- { name : 'addClassesToSVGElement' , active : false } ,
27- { name : 'cleanupAttrs' , active : true } ,
28- { name : 'cleanupEnableBackground' , active : false } ,
29- { name : 'cleanupListOfValues' , active : false } ,
30- { name : 'cleanupNumericValues' , active : true } ,
31- { name : 'convertColors' , active : true } ,
32- { name : 'convertEllipseToCircle' , active : true } ,
33- { name : 'convertPathData' , active : true } ,
34- { name : 'convertShapeToPath' , active : false } ,
35- { name : 'convertTransform' , active : true } ,
36- { name : 'minifyStyles' , active : true } ,
37- { name : 'inlineStyles' , active : true , params : { onlyMatchedOnce : false } } ,
38- { name : 'convertStyleToAttrs' , active : true } ,
39- { name : 'mergePaths' , active : true } ,
40- { name : 'moveElemsAttrsToGroup' , active : false } ,
41- { name : 'moveGroupAttrsToElems' , active : false } ,
42- { name : 'prefixIds' , active : false } ,
43- { name : 'removeAttributesBySelector' , active : false } ,
44- { name : 'removeComments' , active : true } ,
45- { name : 'removeDesc' , active : true } ,
46- { name : 'removeDimensions' , active : false } ,
47- { name : 'removeDoctype' , active : true } ,
48- { name : 'removeEditorsNSData' , active : true } ,
49- { name : 'removeElementsByAttr' , active : false } ,
50- { name : 'removeEmptyAttrs' , active : false } ,
51- { name : 'removeEmptyContainers' , active : true } ,
52- { name : 'removeEmptyText' , active : true } ,
53- { name : 'removeHiddenElems' , active : true } ,
54- { name : 'removeMetadata' , active : true } ,
55- { name : 'removeNonInheritableGroupAttrs' , active : true } ,
56- { name : 'removeOffCanvasPaths' , active : true } ,
57- { name : 'removeRasterImages' , active : true } ,
58- { name : 'removeScriptElement' , active : true } ,
59- { name : 'removeStyleElement' , active : true } ,
60- { name : 'removeTitle' , active : true } ,
61- { name : 'removeUnknownsAndDefaults' , active : true } ,
62- { name : 'removeUnusedNS' , active : true } ,
63- { name : 'removeUselessDefs' , active : true } ,
64- { name : 'removeUselessStrokeAndFill' , active : true , params : { removeNone : true } } ,
65- { name : 'removeViewBox' , active : true } ,
66- { name : 'removeXMLNS' , active : true } ,
67- { name : 'removeXMLProcInst' , active : true } ,
68- { name : 'reusePaths' , active : true } ,
69- { name : 'removeAttrs' , active : true , params : { attrs : [ 'class' ] } } ,
70- { name : 'cleanupIDs' , active : true } ,
71- { name : 'sortAttrs' , active : true } ,
72- { name : 'sortDefsChildren' , active : true } ,
73- { name : 'collapseGroups' , active : true } ,
74- ] ,
75- } ;
16+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
17+ declare const mermaid : typeof import ( 'mermaid' ) . default ;
7618
7719export interface RemarkMermaidOptions {
7820 /**
@@ -85,21 +27,21 @@ export interface RemarkMermaidOptions {
8527 /**
8628 * SVGO options used to minify the SVO output.
8729 *
88- * Set to `null ` explicitly to disable this.
30+ * Set to `false ` explicitly to disable this.
8931 *
9032 * **Note**: This options is only supported in Node.js. In the browser this option is unused.
9133 *
9234 * @default defaultSVGOOptions
9335 */
94- svgo ?: OptimizeOptions | null ;
36+ svgo ?: Config | false ;
9537
9638 /**
9739 * The mermaid options to use.
9840 *
9941 * **Note**: This options is only supported in Node.js. In the browser this option is unused. If
10042 * you use this in a browser, call `mermaid.initialize()` manually.
10143 */
102- mermaidOptions ?: Parameters < typeof mermaid [ 'initialize' ] > [ 0 ] ;
44+ mermaidOptions ?: MermaidConfig ;
10345}
10446
10547/**
@@ -110,7 +52,7 @@ const remarkMermaid: Plugin<[RemarkMermaidOptions?], Root> = (options) => {
11052 throw new Error ( 'The option `launchOptions.executablePath` is required when using Node.js' ) ;
11153 }
11254
113- const { launchOptions, mermaidOptions, svgo = defaultSVGOOptions } = options ;
55+ const { launchOptions, mermaidOptions, svgo } = options ;
11456
11557 let browserPromise : Promise < Browser > | undefined ;
11658 let count = 0 ;
@@ -166,8 +108,8 @@ const remarkMermaid: Plugin<[RemarkMermaidOptions?], Root> = (options) => {
166108
167109 for ( const [ i , [ , index , parent ] ] of instances . entries ( ) ) {
168110 let value = results [ i ] ;
169- if ( svgo ) {
170- value = ( optimize ( value , svgo ) as OptimizedSvg ) . data ;
111+ if ( svgo !== false ) {
112+ value = optimize ( value , svgo ) . data ;
171113 }
172114 parent . children . splice ( index , 1 , {
173115 type : 'paragraph' ,
0 commit comments