From 05dd5bffadbcd3b2a9c3808e968e47e0f301e525 Mon Sep 17 00:00:00 2001 From: John Kenny Date: Sun, 6 Oct 2024 15:34:39 -0700 Subject: [PATCH 1/2] Remove removeEmptyAttrs from presets and change cleanupStyleAttributes to remove empty style attributes. --- plugins/cleanupStyleAttributes.js | 4 ++++ plugins/preset-default.js | 2 -- plugins/preset-next.js | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/cleanupStyleAttributes.js b/plugins/cleanupStyleAttributes.js index d428b06..cc87cd6 100644 --- a/plugins/cleanupStyleAttributes.js +++ b/plugins/cleanupStyleAttributes.js @@ -160,6 +160,10 @@ export const fn = (root, params, info) => { return; } + if (node.attributes['style'] === '') { + delete node.attributes.style; + } + const origProperties = getStyleDeclarations(node); if (!origProperties) { return; diff --git a/plugins/preset-default.js b/plugins/preset-default.js index 7145db2..6ced931 100644 --- a/plugins/preset-default.js +++ b/plugins/preset-default.js @@ -18,7 +18,6 @@ import * as removeComments from './removeComments.js'; import * as removeDesc from './removeDesc.js'; import * as removeDoctype from './removeDoctype.js'; import * as removeEditorsNSData from './removeEditorsNSData.js'; -import * as removeEmptyAttrs from './removeEmptyAttrs.js'; import * as removeEmptyContainers from './removeEmptyContainers.js'; import * as removeEmptyText from './removeEmptyText.js'; import * as removeHiddenElems from './removeHiddenElems.js'; @@ -58,7 +57,6 @@ const presetDefault = createPreset({ convertShapeToPath, combinePaths, minifyPathData, - removeEmptyAttrs, removeEmptyContainers, removeUnusedNS, ], diff --git a/plugins/preset-next.js b/plugins/preset-next.js index df3a768..26be3f1 100644 --- a/plugins/preset-next.js +++ b/plugins/preset-next.js @@ -18,7 +18,6 @@ import * as removeComments from './removeComments.js'; import * as removeDesc from './removeDesc.js'; import * as removeDoctype from './removeDoctype.js'; import * as removeEditorsNSData from './removeEditorsNSData.js'; -import * as removeEmptyAttrs from './removeEmptyAttrs.js'; import * as removeEmptyContainers from './removeEmptyContainers.js'; import * as removeEmptyText from './removeEmptyText.js'; import * as removeHiddenElems from './removeHiddenElems.js'; @@ -58,7 +57,6 @@ const presetNext = createPreset({ convertShapeToPath, combinePaths, minifyPathData, - removeEmptyAttrs, removeEmptyContainers, removeUnusedNS, ], From a6c0a99c78641c82162ae3406b3568ef413ca006 Mon Sep 17 00:00:00 2001 From: John Kenny Date: Sun, 6 Oct 2024 15:45:42 -0700 Subject: [PATCH 2/2] Add deprecation warning. --- plugins/removeEmptyAttrs.js | 9 +++++++++ plugins/removeUselessDefs.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/removeEmptyAttrs.js b/plugins/removeEmptyAttrs.js index 3986693..00eec48 100644 --- a/plugins/removeEmptyAttrs.js +++ b/plugins/removeEmptyAttrs.js @@ -3,6 +3,8 @@ import { attrsGroups } from './_collections.js'; export const name = 'removeEmptyAttrs'; export const description = 'removes empty attributes'; +let deprecationWarning = true; + /** * Remove attributes with empty values. * @@ -11,6 +13,13 @@ export const description = 'removes empty attributes'; * @type {import('./plugins-types.js').Plugin<'removeEmptyAttrs'>} */ export const fn = () => { + if (deprecationWarning) { + console.warn( + 'The removeEmptyAttrs plugin is deprecated and will be removed in a future release.', + ); + deprecationWarning = false; + } + return { element: { enter: (node) => { diff --git a/plugins/removeUselessDefs.js b/plugins/removeUselessDefs.js index cc2351e..0470cab 100644 --- a/plugins/removeUselessDefs.js +++ b/plugins/removeUselessDefs.js @@ -21,7 +21,7 @@ let deprecationWarning = true; export const fn = () => { if (deprecationWarning) { console.warn( - 'The moveGroupAttrsToElems plugin is deprecated and will be removed in a future release.', + 'The removeUselessDefs plugin is deprecated and will be removed in a future release.', ); deprecationWarning = false; }