Skip to content

Commit

Permalink
Merge pull request #244 from bezoerb/filter-option
Browse files Browse the repository at this point in the history
Adds filter option
  • Loading branch information
bezoerb committed Oct 8, 2023
2 parents 1d14b4c + 39cc1c6 commit 74bfee8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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_};
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/styles/filter.in.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.filter {
border-image: url('../images/blank.gif');
}
3 changes: 3 additions & 0 deletions test/fixtures/styles/filter.out.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.filter {
border-image: url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
}
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 74bfee8

Please sign in to comment.