Skip to content

Commit cd66949

Browse files
committed
feat: clip-path
1 parent 94b5677 commit cd66949

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/CSSStyleDeclaration.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,19 @@ describe('properties', () => {
805805
expect(style.clip).toBe('rect(calc(10px), calc(10px), calc(10px), calc(10px))');
806806
});
807807
});
808+
describe('clip-path', () => {
809+
test('basic shape and geometry box in any order', () => {
810+
const style = new CSSStyleDeclaration();
811+
const valid = [
812+
['fill-box circle()', 'circle(at center center) fill-box'],
813+
['circle() fill-box', 'circle(at center center) fill-box'],
814+
];
815+
valid.forEach(([input, expected = input]) => {
816+
style.clipPath = input;
817+
expect(style.clipPath).toBe(expected);
818+
});
819+
});
820+
});
808821
describe('flex', () => {
809822
test('shorthand propagates to longhands', () => {
810823
const style = new CSSStyleDeclaration();

lib/properties/clipPath.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const {
4+
parseGeometryBox,
5+
parseKeyword,
6+
parseResource,
7+
parseBasicShape,
8+
splitTokens,
9+
} = require('../parsers');
10+
11+
function parseShapeGeometry(val) {
12+
const [args] = splitTokens(val);
13+
if (args.length === 2) {
14+
let shape = parseBasicShape(args[0]);
15+
let box = parseGeometryBox(args[1]);
16+
if (!shape && !box) {
17+
shape = parseBasicShape(args[1]);
18+
box = parseGeometryBox(args[0]);
19+
}
20+
if (shape && box) {
21+
return `${shape} ${box}`;
22+
}
23+
}
24+
return parseBasicShape(val) || parseGeometryBox(val);
25+
}
26+
27+
function parse(val) {
28+
return parseResource(val) || parseShapeGeometry(val) || parseKeyword(val, ['none']);
29+
}
30+
31+
module.exports.definition = {
32+
set: function(v) {
33+
this._setProperty('clip-path', parse(v));
34+
},
35+
get: function() {
36+
return this.getPropertyValue('clip-path');
37+
},
38+
enumerable: true,
39+
configurable: true,
40+
};

0 commit comments

Comments
 (0)