backgroundOrigin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "background-origin";
  4. const shorthand = "background";
  5. module.exports.parse = (v, opt = {}) => {
  6. const { globalObject } = opt;
  7. if (v === "") {
  8. return v;
  9. }
  10. const values = parsers.splitValue(v, { delimiter: "," });
  11. const parsedValues = [];
  12. for (const val of values) {
  13. const value = parsers.parsePropertyValue(property, val, {
  14. globalObject,
  15. inArray: true
  16. });
  17. if (Array.isArray(value) && value.length === 1) {
  18. const parsedValue = parsers.resolveKeywordValue(value);
  19. if (!parsedValue) {
  20. return;
  21. }
  22. parsedValues.push(parsedValue);
  23. } else if (typeof value === "string") {
  24. parsedValues.push(value);
  25. }
  26. }
  27. if (parsedValues.length) {
  28. return parsedValues.join(", ");
  29. }
  30. };
  31. module.exports.definition = {
  32. set(v) {
  33. v = parsers.prepareValue(v);
  34. if (parsers.hasVarFunc(v)) {
  35. this._setProperty(shorthand, "");
  36. this._setProperty(property, v);
  37. } else {
  38. const val = module.exports.parse(v, {
  39. globalObject: this._global
  40. });
  41. if (typeof val === "string") {
  42. const priority =
  43. !this._priorities.get(shorthand) && this._priorities.has(property)
  44. ? this._priorities.get(property)
  45. : "";
  46. this._setProperty(property, val, priority);
  47. }
  48. }
  49. },
  50. get() {
  51. return this.getPropertyValue(property);
  52. },
  53. enumerable: true,
  54. configurable: true
  55. };
  56. module.exports.property = property;