Skip to content

Commit

Permalink
feat: clip-path
Browse files Browse the repository at this point in the history
  • Loading branch information
cdoublev committed Jun 11, 2021
1 parent 961396e commit 3ae3298
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/CSSStyleDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,19 @@ describe('properties', () => {
expect(style.clip).toBe('rect(calc(10px), calc(10px), calc(10px), calc(10px))');
});
});
describe('clip-path', () => {
test('basic shape and geometry box in any order', () => {
const style = new CSSStyleDeclaration();
const valid = [
['fill-box circle()', 'circle(at center center) fill-box'],
['circle() fill-box', 'circle(at center center) fill-box'],
];
valid.forEach(([input, expected = input]) => {
style.clipPath = input;
expect(style.clipPath).toBe(expected);
});
});
});
describe('flex', () => {
test('shorthand propagates to longhands', () => {
const style = new CSSStyleDeclaration();
Expand Down
40 changes: 40 additions & 0 deletions lib/properties/clipPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const {
parseGeometryBox,
parseKeyword,
parseResource,
parseBasicShape,
splitTokens,
} = require('../parsers');

function parseShapeGeometry(val) {
const [args] = splitTokens(val);
if (args.length === 2) {
let shape = parseBasicShape(args[0]);
let box = parseGeometryBox(args[1]);
if (!shape && !box) {
shape = parseBasicShape(args[1]);
box = parseGeometryBox(args[0]);
}
if (shape && box) {
return `${shape} ${box}`;
}
}
return parseBasicShape(val) || parseGeometryBox(val);
}

function parse(val) {
return parseResource(val) || parseShapeGeometry(val) || parseKeyword(val, ['none']);
}

module.exports.definition = {
set: function(v) {
this._setProperty('clip-path', parse(v));
},
get: function() {
return this.getPropertyValue('clip-path');
},
enumerable: true,
configurable: true,
};

0 comments on commit 3ae3298

Please sign in to comment.