forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PostCSS + PostCSS plugins for style transformation (WordPress#49521)
* Use PostCSS + PostCSS plugins for style transformation. * Remove the now replaced CSS parsing code. * Use synchronous PostCSS API. * Update package-lock.json * Add basic wrapping test * Use correct postcss-prefixwrap package * Update test snapshots * Add more tests and fix type signature * Ensure that data URLs do not break the CSS transformer * Do not optional chain something that is not optional * Filter out non-CSS styles before passing the array to transformStyles --------- Co-authored-by: Luis Felipe Zaguini <[email protected]>
- Loading branch information
Showing
22 changed files
with
474 additions
and
1,874 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/block-editor/src/utils/test/__snapshots__/transform-styles.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`transformStyles URL rewrite should not replace absolute paths 1`] = ` | ||
[ | ||
"h1 { background: url(/images/test.png); }", | ||
] | ||
`; | ||
|
||
exports[`transformStyles URL rewrite should not replace remote paths 1`] = ` | ||
[ | ||
"h1 { background: url(http://wp.org/images/test.png); }", | ||
] | ||
`; | ||
exports[`transformStyles URL rewrite should replace complex relative paths 1`] = ` | ||
[ | ||
"h1 { background: url(http://wp-site.local/themes/gut/images/test.png); }", | ||
] | ||
`; | ||
exports[`transformStyles URL rewrite should rewrite relative paths 1`] = ` | ||
[ | ||
"h1 { background: url(http://wp-site.local/themes/gut/css/images/test.png); }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should ignore font-face selectors 1`] = ` | ||
[ | ||
" | ||
@font-face { | ||
font-family: myFirstFont; | ||
src: url(sansation_light.woff); | ||
}", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should ignore keyframes 1`] = ` | ||
[ | ||
" | ||
@keyframes edit-post__fade-in-animation { | ||
from { | ||
opacity: 0; | ||
} | ||
}", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should ignore selectors 1`] = ` | ||
[ | ||
".my-namespace h1, body { color: red; }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should not double wrap selectors 1`] = ` | ||
[ | ||
" .my-namespace h1, .my-namespace .red { color: red; }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should replace :root selectors 1`] = ` | ||
[ | ||
" | ||
.my-namespace { | ||
--my-color: #ff0000; | ||
}", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should replace root tags 1`] = ` | ||
[ | ||
".my-namespace, .my-namespace h1 { color: red; }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should wrap multiple selectors 1`] = ` | ||
[ | ||
".my-namespace h1, .my-namespace h2 { color: red; }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should wrap regular selectors 1`] = ` | ||
[ | ||
".my-namespace h1 { color: red; }", | ||
] | ||
`; | ||
exports[`transformStyles selector wrap should wrap selectors inside container queries 1`] = ` | ||
[ | ||
" | ||
@container (width > 400px) { | ||
.my-namespace h1 { color: red; } | ||
}", | ||
] | ||
`; | ||
exports[`transformStyles should not break with data urls 1`] = ` | ||
[ | ||
".wp-block-group { | ||
background-image: url("data:image/svg+xml,%3Csvg%3E.b%7Bclip-path:url(test);%7D%3C/svg%3E"); | ||
color: red !important; | ||
}", | ||
] | ||
`; |
Oops, something went wrong.