Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ exports[`cli api --help shows help screen to user 1`] = `
ffffff00
--primitive-cores number number of parallel workers
(default uses all cores)
-b, --blur-blur number Set the stdDeviation value for
the GaussianBlur SVG filter. See:
-b, --blur-blur number Set the radius value [pixel] for
the GaussianBlur CSS filter. See:
https://developer.mozilla.org/en-
US/docs/Web/SVG/Element/feGaussianBlur
US/docs/Web/CSS/filter-
function/blur#syntax

Examples

Expand Down
7 changes: 4 additions & 3 deletions packages/sqip-plugin-blur/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# `sqip-plugin-blur`

> TODO: description

##### Options
| command | Description |
| ------------- | ------------- |
|-b, --blur-blur *number* | Set the stdDeviation value for the GaussianBlur SVG filter. See: https://developer.mozilla.org/en- US/docs/Web/SVG/Element/feGaussianBlur
| command | Description |
| ----------------------- | ----------- |
|-b, --blur-blur *number* | Set the radius value [pixel] for the [GaussianBlur CSS filter](https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/blur#syntax). |

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

exports[`applies blur filter do nothing when no blur is given 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><rect fill=\\"#bada55\\"/><g><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></svg>"`;

exports[`applies blur filter svg with group and blur 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><filter id=\\"b\\"><feGaussianBlur stdDeviation=\\"5\\"/></filter><rect fill=\\"#bada55\\"/><g filter=\\"url(#b)\\"><g><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></g></svg>"`;
exports[`applies blur filter svg with group and blur 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><rect fill=\\"#bada55\\"/><g filter=\\"blur(5px)\\"><g><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></g></svg>"`;

exports[`applies blur filter svg without group and blur 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><filter id=\\"b\\"><feGaussianBlur stdDeviation=\\"5\\"/></filter><rect fill=\\"#bada55\\"/><polygon points=\\"0,100 50,25 50,75 100,0\\"/></svg>"`;
exports[`applies blur filter svg without group and blur 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><rect fill=\\"#bada55\\"/><polygon points=\\"0,100 50,25 50,75 100,0\\"/></svg>"`;

exports[`does prepare problematic svgs properly for blurring svg with group 1`] = `"<svg viewBox=\\"0 0 1024 768\\"><rect fill=\\"#bada55\\"/><g><path fill=\\"#C0FFEE\\" d=\\"M51.5 17.5l4 18 15 1z\\"/></g></svg>"`;

Expand Down
8 changes: 2 additions & 6 deletions packages/sqip-plugin-blur/src/sqip-plugin-blur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class SVGPlugin extends SqipPlugin {
alias: 'b',
type: Number,
description:
'Set the stdDeviation value for the GaussianBlur SVG filter. See: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feGaussianBlur',
'Set the radius value [pixel] for the GaussianBlur CSS filter. See: https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/blur#syntax',
defaultValue: 12
}
]
Expand Down Expand Up @@ -87,11 +87,7 @@ export default class SVGPlugin extends SqipPlugin {
}
const patchedSVG = patchSVGGroup(svg)
const $ = loadSVG(patchedSVG)
const blurFilterId = 'b'
$('svg > g').attr('filter', `url(#${blurFilterId})`)
$('svg').prepend(
`<filter id="${blurFilterId}"><feGaussianBlur stdDeviation="${this.options.blur}" />`
)
$('svg > g').attr('filter', `blur(${this.options.blur}px)`)

return $.html()
}
Expand Down