diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2025-11-24 20:54:57 +0100 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2025-11-24 20:57:48 +0100 |
| commit | b1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c (patch) | |
| tree | 49d360fd6cbc6a2754efe93524ac47ff0fbe0f7d /node_modules/tailwindcss/src/util/validateFormalSyntax.js | |
Docs
Diffstat (limited to 'node_modules/tailwindcss/src/util/validateFormalSyntax.js')
| -rw-r--r-- | node_modules/tailwindcss/src/util/validateFormalSyntax.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/node_modules/tailwindcss/src/util/validateFormalSyntax.js b/node_modules/tailwindcss/src/util/validateFormalSyntax.js new file mode 100644 index 0000000..d3dafea --- /dev/null +++ b/node_modules/tailwindcss/src/util/validateFormalSyntax.js @@ -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') + }) +} |