validateFormalSyntax.js 998 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "backgroundSize", {
  6. enumerable: true,
  7. get: function() {
  8. return backgroundSize;
  9. }
  10. });
  11. const _dataTypes = require("./dataTypes");
  12. const _splitAtTopLevelOnly = require("./splitAtTopLevelOnly");
  13. function backgroundSize(value) {
  14. let keywordValues = [
  15. "cover",
  16. "contain"
  17. ];
  18. // the <length-percentage> type will probably be a css function
  19. // so we have to use `splitAtTopLevelOnly`
  20. return (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(value, ",").every((part)=>{
  21. let sizes = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(part, "_").filter(Boolean);
  22. if (sizes.length === 1 && keywordValues.includes(sizes[0])) return true;
  23. if (sizes.length !== 1 && sizes.length !== 2) return false;
  24. return sizes.every((size)=>(0, _dataTypes.length)(size) || (0, _dataTypes.percentage)(size) || size === "auto");
  25. });
  26. }