New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(#119): add grid prefix support #285
Conversation
TODO:
|
The PR is ready for review. And here is a few things:
|
Pull Request Test Coverage Report for Build d74963977ee5661da6a526faa4b7120ed49de8e8-PR-285
💛 - Coveralls |
Elaborate? |
The prefixer middleware, which has access to the complete state of the css token graph does not have this limitation, the Line 42 in 9e61e05
|
If
The same rule applies to I mainly port the features from @robinweser's inline-style-prefixer (He recently switch Fela's prefixer from his own |
Co-authored-by: thysultan <sultantarimo@me.com>
One concern that I have is that it might potentially increase the output quite a bit for existing users. I wonder if this could be split into 2 plugins somehow? Or should I potentially get ready for copying over the older version of the prefixed into Emotion's codebase? 🤔 |
Chiming in since I was mentioned in this thread: |
That's why I said my initial changes are And currently, the after-gzipped size is only increased by about 200 bytes. That doesn't sound so bad, right? |
Use ternary expressions to avoid duplicated statements
I'm not that concerned about the increase of the Stylis' size - but rather about the increased size of the prefixed output. My concern is about the generated CSS. |
Only those grid-related declarations will contribute to the increasing final CSS output. So it really depends on how much grid do the developers use in their project currently: if they use none, then the prefixed output will not be affected at all. So I've done some naive tests here:
I've checked dev.to (their source code can be found here), a website whose layout is heavily based on the CSS grid. And the CSS size before and after autoprefixer is I've also run the test on https://emotion.sh 's doc page by extracting all inlined |
src/Prefixer.js
Outdated
return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/, '') | ||
+ ( | ||
// center, end, start, stretch | ||
match(substr(value, length + 1, sizeof(value) - 1), /^(center|end|start|stretch)$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flexbox supports plain center|end|start|stretch
wouldn't this now add grid properties to what was intended as flexbox align-self
given that center|end|start|stretch
are universal properties for both flexbox and grid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, at least it is also how autoprefixer handle align-self
:
.example {
align-self: stretch
}
will become
/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.3.6,
* Autoprefixer: v10.3.1
* Browsers: since 2010
*/
.example {
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
-ms-grid-row-align: stretch;
align-self: stretch
}
@thysultan Done in #287 |
Omg, that would be a dream come true! Especially for something like prefixers where the amount of code and required prefixes differs so much depending on the browser range. |
@@ -82,12 +98,42 @@ export function prefix (value, length) { | |||
return ~indexof(value, 'stretch') ? prefix(replace(value, 'stretch', 'fill-available'), length) + value : value | |||
} | |||
break | |||
// grid-(column|row) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't use arrow functions, also possibly more size optimisations, i.e hoisting the regex. I'll submit these and more to this branch this weekend.
src/Prefixer.js
Outdated
@@ -34,10 +34,17 @@ export function prefix (value, length) { | |||
return WEBKIT + value + replace(value, /(\w+).+(:[^]+)/, WEBKIT + 'box-$1$2' + MS + 'flex-$1$2') + value | |||
// align-self | |||
case 5443: | |||
return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/, '') + value | |||
return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/g, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: size optimisations. assigning to myself.
@thysultan Thanks for your review! I will remove whitespace (and possibly other style-related) diff first. |
- fix justify-self:flex-start getting grid prefixes.
the following fixes the previous failing test, and uses only 1 regex, is there still space for improvement? will think on it.
// justify-self | ||
case 4200: | ||
if (!match(value, /flex-|baseline/)) return MS + 'grid-column-align' + substr(value, length) + value | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-checked the implementation of autoprefixer
, it only excludes flex-|baseline
from being prefixed with grid:
https://github.com/postcss/autoprefixer/blob/3041c7bfced438875d668767432666b10a88ef36/lib/hacks/grid-column-align.js#L7-L9
https://github.com/postcss/autoprefixer/blob/3041c7bfced438875d668767432666b10a88ef36/lib/hacks/grid-row-align.js#L7-L9
Adopting the same behavior allows us to simplify the regexp even further, resulting in an even smaller size.
return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/, '') + value | ||
return WEBKIT + value + MS + 'flex-item-' + replace(value, /flex-|-self/g, '') + (!match(value, /flex-|baseline/) ? MS + 'grid-row-' + replace(value, /flex-|-self/g, '') : '') + value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SukkaW Any reason why /flex-|-self/
is converted to /flex-|-self/g
and also /align-content|flex-|-self/g
, does a test fail because of this, can there be multiple flex- -self notations in the declaration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align-self:flex-start;
should be prefixed as -ms-flex-line-pack:end;
, not -ms-flex-line-pack:flex-end;
. That's why g
is added.
@@ -82,12 +89,15 @@ export function prefix (value, length) { | |||
return ~indexof(value, 'stretch') ? prefix(replace(value, 'stretch', 'fill-available'), length) + value : value | |||
} | |||
break | |||
// grid-(column|row) | |||
case 5152: case 5920: | |||
return replace(value, /(.+?):(\d+)(\s*\/\s*(span)?\s*(\d+))?(.*)/, function (_, a, b, c, d, e, f) { return (MS + a + ':' + b + f) + (c ? (MS + a + '-span:' + (d ? e : +e - +b)) + f : '') + value }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SukkaW I updated this, can you review? does it still handle the original cases you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the test cases passed, so I assume it does.
@SukkaW Thanks for the work you've done on this. |
When finished, this should close #119 once and for all.
Note:
It is still WIPAlthough the feature is implemented, it hasn't been optimized AT ALL, so suggestions, optimizations, discussions are welcome!