diff --git a/packages/utils/package-lock.json b/packages/utils/package-lock.json index 4fb781e..68a810d 100644 --- a/packages/utils/package-lock.json +++ b/packages/utils/package-lock.json @@ -1,12 +1,12 @@ { "name": "@iconify/utils", - "version": "1.0.32", + "version": "1.0.33", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@iconify/utils", - "version": "1.0.32", + "version": "1.0.33", "license": "MIT", "dependencies": { "@antfu/install-pkg": "^0.1.0", diff --git a/packages/utils/package.json b/packages/utils/package.json index a334032..c4412f2 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -3,7 +3,7 @@ "type": "module", "description": "Common functions for working with Iconify icon sets used by various packages.", "author": "Vjacheslav Trushkin", - "version": "1.0.32", + "version": "1.0.33", "license": "MIT", "bugs": "https://github.com/iconify/iconify/issues", "homepage": "https://iconify.design/", diff --git a/packages/utils/src/loader/custom.ts b/packages/utils/src/loader/custom.ts index 3ace3d1..a3d7299 100644 --- a/packages/utils/src/loader/custom.ts +++ b/packages/utils/src/loader/custom.ts @@ -30,17 +30,21 @@ export async function getCustomIcon( } if (result) { + const cleanupIdx = result.indexOf(' 0) result = result.slice(cleanupIdx); + const { transform } = options?.customizations ?? {}; + result = + typeof transform === 'function' + ? await transform(result, collection, icon) + : result; + if (!result.startsWith(' 0) svg = svg.slice(cleanupIdx); return typeof transform === 'function' ? await transform(svg) : svg; diff --git a/packages/utils/tests/file-system-icon-test.ts b/packages/utils/tests/file-system-icon-test.ts index f7e80df..3eb60c4 100644 --- a/packages/utils/tests/file-system-icon-test.ts +++ b/packages/utils/tests/file-system-icon-test.ts @@ -8,6 +8,13 @@ describe('Testing FileSystemIconLoader', () => { expect(result && result.indexOf('svg') > -1).toBeTruthy(); }); + test('FileSystemIconLoader cleanups svg preface', async () => { + const result = await FileSystemIconLoader(fixturesDir)( + 'circle-xml-preface' + ); + expect(result && result.indexOf(' { const result = await FileSystemIconLoader(fixturesDir, (icon) => { return icon.replace(' + + diff --git a/packages/utils/tests/get-custom-icon-test.ts b/packages/utils/tests/get-custom-icon-test.ts index 5c6de76..697a1bb 100644 --- a/packages/utils/tests/get-custom-icon-test.ts +++ b/packages/utils/tests/get-custom-icon-test.ts @@ -35,6 +35,21 @@ describe('Testing getCustomIcon', () => { ); }); + test('CustomIconLoader cleanups svg preface', async () => { + const svg = ` + + + + +`; + const result = await getCustomIcon(() => svg, 'a', 'b', { + customizations: { trimCustomSvg: true }, + }); + expect(result).toEqual( + '' + ); + }); + test("CustomIconLoader with transform: scale/width/height shouldn't take effect", async () => { const svg = await fs.readFile(fixturesDir + '/circle.svg', 'utf8'); const options: IconifyLoaderOptions = { @@ -66,7 +81,7 @@ describe('Testing getCustomIcon', () => { expect(usedProps.height).toEqual('4em'); }); - test('Icon with XML heading', async () => { + test.skip('Icon with XML heading', async () => { // Intercept console.warn let warned = false; const warn = console.warn; diff --git a/packages/utils/tests/load-icon-test.ts b/packages/utils/tests/load-icon-test.ts index 31bb93b..807888e 100644 --- a/packages/utils/tests/load-icon-test.ts +++ b/packages/utils/tests/load-icon-test.ts @@ -24,6 +24,7 @@ describe('Testing loadIcon', () => { }); test('CustomCollection using dynamic import', async () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const result = await loadIcon('flat-color-icons', 'up-right', { customCollections: { @@ -82,7 +83,15 @@ describe('Testing loadIcon', () => { // Restore console.warn console.warn = warn; - expect(svg).toEqual(result); - expect(warned).toEqual(true); + expect(svg).not.toEqual(result); + expect( + svg?.replace( + '', + '' + ) + ).toEqual(result); + + // warning should not longer be used + expect(warned).toEqual(false); }); }); diff --git a/packages/utils/tests/trim-svg-test.ts b/packages/utils/tests/trim-svg-test.ts index c76a761..5cd6d8c 100644 --- a/packages/utils/tests/trim-svg-test.ts +++ b/packages/utils/tests/trim-svg-test.ts @@ -89,89 +89,89 @@ describe('Trim SVG', () => { C11.75,32.56,35.14,9.17,64,9.17s52.25,23.39,52.25,52.25C116.25,90.28,92.86,113.68,64,113.68z"/> - - - - - - - - - - - - - - - - - - - -