-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve type checking for formal syntax (#9448)
* Improve type checking for formal syntax * Add test * Change order of test class name * fix failing tests * prefer `position` over `size` for backwards compatibility reasons Previously `bg-[10px_10%]` generated `background-position: 10px 10%` before we introduced the fallback plugins. Therefore we should prefer `position` over `size` as the default for backwards compatibility. * update changelog * ensure correct order Thanks Prettier! * update changelog Co-authored-by: lzt1008 <[email protected]> Co-authored-by: Jordan Pittman <[email protected]> Co-authored-by: liangzhengtai <[email protected]>
- Loading branch information
1 parent
94d6e72
commit 727de66
Showing
6 changed files
with
126 additions
and
15 deletions.
There are no files selected for viewing
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
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
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,34 @@ | ||
import { length, percentage } from './dataTypes' | ||
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly' | ||
|
||
/** | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#formal_syntax | ||
* | ||
* background-size = | ||
* <bg-size># | ||
* | ||
* <bg-size> = | ||
* [ <length-percentage [0,∞]> | auto ]{1,2} | | ||
* cover | | ||
* contain | ||
* | ||
* <length-percentage> = | ||
* <length> | | ||
* <percentage> | ||
* | ||
* @param {string} value | ||
*/ | ||
export function backgroundSize(value) { | ||
let keywordValues = ['cover', 'contain'] | ||
// the <length-percentage> type will probably be a css function | ||
// so we have to use `splitAtTopLevelOnly` | ||
return splitAtTopLevelOnly(value, ',').every((part) => { | ||
let sizes = splitAtTopLevelOnly(part, '_').filter(Boolean) | ||
if (sizes.length === 1 && keywordValues.includes(sizes[0])) return true | ||
|
||
if (sizes.length !== 1 && sizes.length !== 2) return false | ||
|
||
return sizes.every((size) => length(size) || percentage(size) || size === 'auto') | ||
}) | ||
} |
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