Skip to content

Commit 80affd5

Browse files
committed
feat: clip-path
1 parent 651e5ed commit 80affd5

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
@@ -823,6 +823,19 @@ describe('properties', () => {
823823
expect(style.clip).toBe('rect(calc(10px), calc(10px), calc(10px), calc(10px))');
824824
});
825825
});
826+
describe('clip-path', () => {
827+
test('basic shape and geometry box in any order', () => {
828+
const style = new CSSStyleDeclaration();
829+
const valid = [
830+
['fill-box circle()', 'circle(at center center) fill-box'],
831+
['circle() fill-box', 'circle(at center center) fill-box'],
832+
];
833+
valid.forEach(([input, expected = input]) => {
834+
style.clipPath = input;
835+
expect(style.clipPath).toBe(expected);
836+
});
837+
});
838+
});
826839
describe('flex', () => {
827840
test('shorthand propagates to longhands', () => {
828841
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.js');
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)