From 39cc1c611f1dde3564b1958a7b7cffb2e73c7862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Z=C3=B6rb?= Date: Sun, 8 Oct 2023 23:47:43 +0200 Subject: [PATCH] Adds filter option --- index.js | 5 +++-- test/fixtures/styles/filter.in.css | 3 +++ test/fixtures/styles/filter.out.css | 3 +++ test/test.js | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/styles/filter.in.css create mode 100644 test/fixtures/styles/filter.out.css diff --git a/index.js b/index.js index 77b7338..4933f08 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const DEFAULTS = { maxFileSize: 10240, b64Svg: false, strict: false, + filter: /^(mask(?:-image)?)|(list-style(?:-image)?)|(background(?:-image)?)|(content)|(cursor)/, largeFileCallback: undefined, svgoPlugins: [ { @@ -31,7 +32,7 @@ const loop = (cb) => { }; }; -const escapeRegExp = string => string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'); +const escapeRegExp = (string) => string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'); module.exports = (options_ = {}) => { const options = {...DEFAULTS, ...options_}; @@ -44,7 +45,7 @@ module.exports = (options_ = {}) => { postcssPlugin: 'postcss-image-inliner', async Once(root) { const urls = new Set([]); - const filter = /^(background(?:-image)?)|(content)|(cursor)/; + const {filter} = options; // Get urls root.walkDecls( filter, diff --git a/test/fixtures/styles/filter.in.css b/test/fixtures/styles/filter.in.css new file mode 100644 index 0000000..e6cae42 --- /dev/null +++ b/test/fixtures/styles/filter.in.css @@ -0,0 +1,3 @@ +.filter { + border-image: url('../images/blank.gif'); +} diff --git a/test/fixtures/styles/filter.out.css b/test/fixtures/styles/filter.out.css new file mode 100644 index 0000000..f15918f --- /dev/null +++ b/test/fixtures/styles/filter.out.css @@ -0,0 +1,3 @@ +.filter { + border-image: url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); +} diff --git a/test/test.js b/test/test.js index 0900855..1cd1d62 100644 --- a/test/test.js +++ b/test/test.js @@ -102,4 +102,8 @@ describe('postcss-image-inliner', () => { it('should allow globbing', (done) => { test('glob.in.css', 'glob.out.css', {assetPaths: 'test/*/images/'}, done); }); + + it('should consider filter option', (done) => { + test('filter.in.css', 'filter.out.css', {filter: /^border-image/}, done); + }); });