Skip to content

Commit e1e4ed3

Browse files
committed
fix: use parsePosition to parse background-position
1 parent 3d1bae2 commit e1e4ed3

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

lib/properties/backgroundPosition.js

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
11
'use strict';
22

3-
const { parseKeyword, parseLengthOrPercentage } = require('../parsers');
4-
5-
var valid_keywords = ['top', 'center', 'bottom', 'left', 'right'];
6-
7-
var parse = function parse(v) {
8-
if (v === '') {
9-
return undefined;
10-
}
11-
var parts = v.split(/\s+/);
12-
if (parts.length > 2 || parts.length < 1) {
13-
return undefined;
14-
}
15-
if (parts.length === 1) {
16-
return parseLengthOrPercentage(parts[0]) || parseKeyword(parts[0], valid_keywords);
17-
}
18-
if (
19-
parseLengthOrPercentage(parts[0]) !== undefined &&
20-
parseLengthOrPercentage(parts[1]) !== undefined
21-
) {
22-
return v;
23-
}
24-
if (
25-
parseKeyword(parts[0], valid_keywords) === undefined ||
26-
parseKeyword(parts[1], valid_keywords) === undefined
27-
) {
28-
return undefined;
29-
}
30-
return v;
31-
};
3+
const { parsePosition } = require('../parsers');
324

335
module.exports.isValid = function isValid(v) {
34-
return parse(v) !== undefined;
6+
return parsePosition(v) !== undefined;
357
};
368

379
module.exports.definition = {
3810
set: function(v) {
39-
this._setProperty('background-position', parse(v));
11+
this._setProperty('background-position', parsePosition(v));
4012
},
4113
get: function() {
4214
return this.getPropertyValue('background-position');

0 commit comments

Comments
 (0)