Comparing version
@@ -172,9 +172,13 @@ import SAX from 'sax'; | ||
pushToContent(node); | ||
} else if (/\S/.test(text)) { | ||
/** @type {import('./types.js').XastText} */ | ||
const node = { | ||
type: 'text', | ||
value: text.trim(), | ||
}; | ||
pushToContent(node); | ||
} else { | ||
const value = text.trim(); | ||
if (value !== '') { | ||
/** @type {import('./types.js').XastText} */ | ||
const node = { | ||
type: 'text', | ||
value, | ||
}; | ||
pushToContent(node); | ||
} | ||
} | ||
@@ -181,0 +185,0 @@ } |
import * as csstree from 'css-tree'; | ||
import * as csswhat from 'css-what'; | ||
import { syntax } from 'csso'; | ||
import { matches, visit } from './xast.js'; | ||
import { matches } from './xast.js'; | ||
import { visit } from './util/visit.js'; | ||
import { | ||
@@ -6,0 +7,0 @@ attrsGroups, |
@@ -5,2 +5,3 @@ import os from 'os'; | ||
import * as svgo from './svgo.js'; | ||
import url from 'url'; | ||
@@ -12,3 +13,4 @@ /** | ||
const importConfig = async (configFile) => { | ||
const imported = await import(path.resolve(configFile)); | ||
const resolvedPath = path.resolve(configFile); | ||
const imported = await import(url.pathToFileURL(resolvedPath).toString()); | ||
const config = imported.default; | ||
@@ -15,0 +17,0 @@ |
import { builtinPlugins } from './builtin.js'; | ||
import { encodeSVGDatauri } from './svgo/tools.js'; | ||
import { invokePlugins } from './svgo/plugins.js'; | ||
import { mapNodesToParents, querySelector, querySelectorAll } from './xast.js'; | ||
import { querySelector, querySelectorAll } from './xast.js'; | ||
import { mapNodesToParents } from './util/map-nodes-to-parents.js'; | ||
import { parseSvg } from './parser.js'; | ||
@@ -6,0 +7,0 @@ import { stringifySvg } from './stringifier.js'; |
@@ -0,1 +1,3 @@ | ||
import { mapNodesToParents } from '../util/map-nodes-to-parents.js'; | ||
/** @type {Required<import('css-select').Options<import('../types.js').XastNode & { children?: any }, import('../types.js').XastElement>>['adapter']['isTag']} */ | ||
@@ -72,8 +74,13 @@ const isTag = (node) => { | ||
/** | ||
* @param {Map<import('../types.js').XastNode, import('../types.js').XastParent>} parents | ||
* @param {import('../types.js').XastParent} relativeNode | ||
* @param {Map<import('../types.js').XastNode, import('../types.js').XastParent>=} parents | ||
* @returns {Required<import('css-select').Options<import('../types.js').XastNode & { children?: any }, import('../types.js').XastElement>>['adapter']} | ||
*/ | ||
export function createAdapter(parents) { | ||
export function createAdapter(relativeNode, parents) { | ||
/** @type {Required<import('css-select').Options<import('../types.js').XastNode & { children?: any }, import('../types.js').XastElement>>['adapter']['getParent']} */ | ||
const getParent = (node) => { | ||
if (!parents) { | ||
parents = mapNodesToParents(relativeNode); | ||
} | ||
return parents.get(node) || null; | ||
@@ -80,0 +87,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { visit } from '../xast.js'; | ||
import { visit } from '../util/visit.js'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -7,2 +7,2 @@ /** | ||
*/ | ||
export const VERSION = '4.0.0-rc.4'; | ||
export const VERSION = '4.0.0-rc.5'; |
@@ -5,9 +5,10 @@ import { is, selectAll, selectOne } from 'css-select'; | ||
/** | ||
* @param {Map<import('./types.js').XastNode, import('./types.js').XastParent>} parents | ||
* @param {import('./types.js').XastParent} relativeNode | ||
* @param {Map<import('./types.js').XastNode, import('./types.js').XastParent>=} parents | ||
* @returns {import('css-select').Options<import('./types.js').XastNode & { children?: any }, import('./types.js').XastElement>} | ||
*/ | ||
function createCssSelectOptions(parents) { | ||
function createCssSelectOptions(relativeNode, parents) { | ||
return { | ||
xmlMode: true, | ||
adapter: createAdapter(parents), | ||
adapter: createAdapter(relativeNode, parents), | ||
}; | ||
@@ -17,30 +18,2 @@ } | ||
/** | ||
* Maps all nodes to their parent node recursively. | ||
* | ||
* @param {import('./types.js').XastParent} node | ||
* @returns {Map<import('./types.js').XastNode, import('./types.js').XastParent>} | ||
*/ | ||
export function mapNodesToParents(node) { | ||
/** @type {Map<import('./types.js').XastNode, import('./types.js').XastParent>} */ | ||
const parents = new Map(); | ||
for (const child of node.children) { | ||
parents.set(child, node); | ||
visit( | ||
child, | ||
{ | ||
element: { | ||
enter: (child, parent) => { | ||
parents.set(child, parent); | ||
}, | ||
}, | ||
}, | ||
node, | ||
); | ||
} | ||
return parents; | ||
} | ||
/** | ||
* @param {import('./types.js').XastParent} node Element to query the children of. | ||
@@ -51,8 +24,4 @@ * @param {string} selector CSS selector string. | ||
*/ | ||
export const querySelectorAll = ( | ||
node, | ||
selector, | ||
parents = mapNodesToParents(node), | ||
) => { | ||
return selectAll(selector, node, createCssSelectOptions(parents)); | ||
export const querySelectorAll = (node, selector, parents) => { | ||
return selectAll(selector, node, createCssSelectOptions(node, parents)); | ||
}; | ||
@@ -66,8 +35,4 @@ | ||
*/ | ||
export const querySelector = ( | ||
node, | ||
selector, | ||
parents = mapNodesToParents(node), | ||
) => { | ||
return selectOne(selector, node, createCssSelectOptions(parents)); | ||
export const querySelector = (node, selector, parents) => { | ||
return selectOne(selector, node, createCssSelectOptions(node, parents)); | ||
}; | ||
@@ -81,44 +46,7 @@ | ||
*/ | ||
export const matches = (node, selector, parents = mapNodesToParents(node)) => { | ||
return is(node, selector, createCssSelectOptions(parents)); | ||
export const matches = (node, selector, parents) => { | ||
return is(node, selector, createCssSelectOptions(node, parents)); | ||
}; | ||
export const visitSkip = Symbol(); | ||
/** | ||
* @param {import('./types.js').XastNode} node | ||
* @param {import('./types.js').Visitor} visitor | ||
* @param {any=} parentNode | ||
*/ | ||
export const visit = (node, visitor, parentNode) => { | ||
const callbacks = visitor[node.type]; | ||
if (callbacks?.enter) { | ||
// @ts-expect-error hard to infer | ||
const symbol = callbacks.enter(node, parentNode); | ||
if (symbol === visitSkip) { | ||
return; | ||
} | ||
} | ||
// visit root children | ||
if (node.type === 'root') { | ||
// copy children array to not lose cursor when children is spliced | ||
for (const child of node.children) { | ||
visit(child, visitor, node); | ||
} | ||
} | ||
// visit element children if still attached to parent | ||
if (node.type === 'element') { | ||
if (parentNode.children.includes(node)) { | ||
for (const child of node.children) { | ||
visit(child, visitor, node); | ||
} | ||
} | ||
} | ||
if (callbacks?.exit) { | ||
// @ts-expect-error hard to infer | ||
callbacks.exit(node, parentNode); | ||
} | ||
}; | ||
/** | ||
* @param {import('./types.js').XastChild} node | ||
@@ -125,0 +53,0 @@ * @param {import('./types.js').XastParent} parentNode |
{ | ||
"packageManager": "yarn@3.8.7", | ||
"name": "svgo", | ||
"version": "4.0.0-rc.4", | ||
"version": "4.0.0-rc.5", | ||
"description": "SVGO is a Node.js library and command-line application for optimizing vector images.", | ||
@@ -129,3 +129,3 @@ "license": "MIT", | ||
"pixelmatch": "^7.1.0", | ||
"playwright": "^1.51.1", | ||
"playwright": "^1.52.0", | ||
"pngjs": "^7.0.0", | ||
@@ -132,0 +132,0 @@ "prettier": "^3.5.3", |
@@ -2083,2 +2083,3 @@ /** | ||
'http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd', | ||
'http://krita.org/namespaces/svg/krita', | ||
'http://ns.adobe.com/AdobeIllustrator/10.0/', | ||
@@ -2104,2 +2105,3 @@ 'http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/', | ||
'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
'https://boxy-svg.com', | ||
]); | ||
@@ -2106,0 +2108,0 @@ |
import * as csstree from 'css-tree'; | ||
import { visit } from '../lib/xast.js'; | ||
import { visit } from '../lib/util/visit.js'; | ||
@@ -4,0 +4,0 @@ export const name = 'cleanupEnableBackground'; |
@@ -1,2 +0,2 @@ | ||
import { visitSkip } from '../lib/xast.js'; | ||
import { visitSkip } from '../lib/util/visit.js'; | ||
import { findReferences, hasScripts } from '../lib/svgo/tools.js'; | ||
@@ -3,0 +3,0 @@ |
@@ -110,3 +110,3 @@ import { colorsNames, colorsProps, colorsShortNames } from './_collections.js'; | ||
if (matched) { | ||
val = 'currentcolor'; | ||
val = 'currentColor'; | ||
} | ||
@@ -140,3 +140,7 @@ } | ||
if (convertCase && !includesUrlReference(val)) { | ||
if ( | ||
convertCase && | ||
!includesUrlReference(val) && | ||
val !== 'currentColor' | ||
) { | ||
if (convertCase === 'lower') { | ||
@@ -143,0 +147,0 @@ val = val.toLowerCase(); |
@@ -5,3 +5,3 @@ import { js2path, path2js } from './_path.js'; | ||
import { collectStylesheet, computeStyle } from '../lib/style.js'; | ||
import { visit } from '../lib/xast.js'; | ||
import { visit } from '../lib/util/visit.js'; | ||
import { cleanupOutData, toFixed } from '../lib/svgo/tools.js'; | ||
@@ -8,0 +8,0 @@ |
import * as csstree from 'css-tree'; | ||
import { syntax } from 'csso'; | ||
import { attrsGroups, pseudoClasses } from './_collections.js'; | ||
import { | ||
detachNodeFromParent, | ||
querySelectorAll, | ||
visitSkip, | ||
} from '../lib/xast.js'; | ||
import { detachNodeFromParent, querySelectorAll } from '../lib/xast.js'; | ||
import { visitSkip } from '../lib/util/visit.js'; | ||
import { compareSpecificity, includesAttrSelector } from '../lib/style.js'; | ||
@@ -10,0 +7,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { detachNodeFromParent, visitSkip } from '../lib/xast.js'; | ||
import { detachNodeFromParent } from '../lib/xast.js'; | ||
import { visitSkip } from '../lib/util/visit.js'; | ||
@@ -3,0 +4,0 @@ export const name = 'mergeStyles'; |
@@ -1,2 +0,2 @@ | ||
import { visit } from '../lib/xast.js'; | ||
import { visit } from '../lib/util/visit.js'; | ||
import { inheritableAttrs, pathElems } from './_collections.js'; | ||
@@ -3,0 +3,0 @@ |
import { elemsGroups } from './_collections.js'; | ||
import { | ||
detachNodeFromParent, | ||
querySelector, | ||
visit, | ||
visitSkip, | ||
} from '../lib/xast.js'; | ||
import { detachNodeFromParent, querySelector } from '../lib/xast.js'; | ||
import { visit, visitSkip } from '../lib/util/visit.js'; | ||
import { collectStylesheet, computeStyle } from '../lib/style.js'; | ||
@@ -9,0 +5,0 @@ import { parsePathData } from '../lib/path.js'; |
@@ -1,2 +0,3 @@ | ||
import { detachNodeFromParent, visitSkip } from '../lib/xast.js'; | ||
import { detachNodeFromParent } from '../lib/xast.js'; | ||
import { visitSkip } from '../lib/util/visit.js'; | ||
import { parsePathData } from '../lib/path.js'; | ||
@@ -3,0 +4,0 @@ import { intersects } from './_path.js'; |
@@ -8,3 +8,4 @@ import { | ||
} from './_collections.js'; | ||
import { detachNodeFromParent, visitSkip } from '../lib/xast.js'; | ||
import { detachNodeFromParent } from '../lib/xast.js'; | ||
import { visitSkip } from '../lib/util/visit.js'; | ||
import { collectStylesheet, computeStyle } from '../lib/style.js'; | ||
@@ -11,0 +12,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { detachNodeFromParent, visit, visitSkip } from '../lib/xast.js'; | ||
import { detachNodeFromParent } from '../lib/xast.js'; | ||
import { visit, visitSkip } from '../lib/util/visit.js'; | ||
import { collectStylesheet, computeStyle } from '../lib/style.js'; | ||
@@ -3,0 +4,0 @@ import { hasScripts } from '../lib/svgo/tools.js'; |
@@ -5,3 +5,3 @@ export * from "./types.js"; | ||
import { builtinPlugins } from './builtin.js'; | ||
import { mapNodesToParents } from './xast.js'; | ||
import { mapNodesToParents } from './util/map-nodes-to-parents.js'; | ||
import { querySelector } from './xast.js'; | ||
@@ -8,0 +8,0 @@ import { querySelectorAll } from './xast.js'; |
/** | ||
* @param {Map<import('../types.js').XastNode, import('../types.js').XastParent>} parents | ||
* @param {import('../types.js').XastParent} relativeNode | ||
* @param {Map<import('../types.js').XastNode, import('../types.js').XastParent>=} parents | ||
* @returns {Required<import('css-select').Options<import('../types.js').XastNode & { children?: any }, import('../types.js').XastElement>>['adapter']} | ||
*/ | ||
export function createAdapter(parents: Map<import("../types.js").XastNode, import("../types.js").XastParent>): Required<import("css-select").Options<import("../types.js").XastNode & { | ||
export function createAdapter(relativeNode: import("../types.js").XastParent, parents?: Map<import("../types.js").XastNode, import("../types.js").XastParent> | undefined): Required<import("css-select").Options<import("../types.js").XastNode & { | ||
children?: any; | ||
}, import("../types.js").XastElement>>["adapter"]; |
@@ -1,13 +0,4 @@ | ||
/** | ||
* Maps all nodes to their parent node recursively. | ||
* | ||
* @param {import('./types.js').XastParent} node | ||
* @returns {Map<import('./types.js').XastNode, import('./types.js').XastParent>} | ||
*/ | ||
export function mapNodesToParents(node: import("./types.js").XastParent): Map<import("./types.js").XastNode, import("./types.js").XastParent>; | ||
export function querySelectorAll(node: import("./types.js").XastParent, selector: string, parents?: Map<import("./types.js").XastNode, import("./types.js").XastParent> | undefined): import("./types.js").XastChild[]; | ||
export function querySelector(node: import("./types.js").XastParent, selector: string, parents?: Map<import("./types.js").XastNode, import("./types.js").XastParent> | undefined): import("./types.js").XastChild | null; | ||
export function matches(node: import("./types.js").XastElement, selector: string, parents?: Map<import("./types.js").XastNode, import("./types.js").XastParent> | undefined): boolean; | ||
export const visitSkip: unique symbol; | ||
export function visit(node: import("./types.js").XastNode, visitor: import("./types.js").Visitor, parentNode?: any | undefined): void; | ||
export function detachNodeFromParent(node: import("./types.js").XastChild, parentNode: import("./types.js").XastParent): void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1446785
0.1%154
2.67%27463
0.06%