File size: 1,430 Bytes
4086e5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";

const parsers = require("../parsers");

module.exports.parse = function parse(v) {
  const parts = parsers.splitValue(v);
  if (!parts.length || parts.length > 2) {
    return;
  }
  const validKeywordsX = ["left", "center", "right"];
  const validKeywordsY = ["top", "center", "bottom"];
  if (parts.length === 1) {
    const dim = parsers.parseMeasurement(parts[0]);
    if (dim) {
      return dim;
    }
    const validKeywords = new Set([...validKeywordsX, ...validKeywordsY]);
    return parsers.parseKeyword(v, [...validKeywords]);
  }
  const [partX, partY] = parts;
  const posX = parsers.parseMeasurement(partX) || parsers.parseKeyword(partX, validKeywordsX);
  if (posX) {
    const posY = parsers.parseMeasurement(partY) || parsers.parseKeyword(partY, validKeywordsY);
    if (posY) {
      return `${posX} ${posY}`;
    }
  }
};

module.exports.isValid = function isValid(v) {
  if (v === "") {
    return true;
  }
  return typeof module.exports.parse(v) === "string";
};

module.exports.definition = {
  set(v) {
    v = parsers.prepareValue(v, this._global);
    if (parsers.hasVarFunc(v)) {
      this._setProperty("background", "");
      this._setProperty("background-position", v);
    } else {
      this._setProperty("background-position", module.exports.parse(v));
    }
  },
  get() {
    return this.getPropertyValue("background-position");
  },
  enumerable: true,
  configurable: true
};