Skip to content

Commit feebfaa

Browse files
committed
feat: clip-path
1 parent 36468c0 commit feebfaa

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

lib/CSSStyleDeclaration.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,19 @@ describe('properties', () => {
812812
expect(style.clip).toBe('rect(calc(10px), calc(10px), calc(10px), calc(10px))');
813813
});
814814
});
815+
describe('clip-path', () => {
816+
test('basic shape and geometry box in any order', () => {
817+
const style = new CSSStyleDeclaration();
818+
const valid = [
819+
['fill-box circle()', 'circle(at center center) fill-box'],
820+
['circle() fill-box', 'circle(at center center) fill-box'],
821+
];
822+
valid.forEach(([input, expected = input]) => {
823+
style.clipPath = input;
824+
expect(style.clipPath).toBe(expected);
825+
});
826+
});
827+
});
815828
describe('flex', () => {
816829
test('shorthand propagates to longhands', () => {
817830
const style = new CSSStyleDeclaration();

lib/properties/clipPath.js

+40
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)