Skip to content

Commit e20fd7e

Browse files
Onno van der Zeecscott
authored andcommitted
Support clip properties.
The clip property has has browser support for a long time, and even parser-lib was nearly there. The clip property is now deprecated, and its successor clip-path is more versatile, the use cases are much more credible. Also support for the clip-rule propery. The properties can be used without support of a svg file. See: https://drafts.fxtf.org/css-masking-1/#the-clip-path Fixes: #160
1 parent 4bf70c7 commit e20fd7e

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

src/css/Properties.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ var Properties = {
246246
//C
247247
"caption-side" : "top | bottom | inherit",
248248
"clear" : "none | right | left | both | inherit",
249-
"clip" : 1,
249+
"clip" : "<shape> | auto | inherit",
250+
"-webkit-clip-path" : "<clip-source> | <clip-path> | none",
251+
"clip-path" : "<clip-source> | <clip-path> | none",
252+
"clip-rule" : "nonzero | evenodd | inherit",
250253
"color" : "<color> | inherit",
251254
"color-profile" : 1,
252255
"column-count" : "<integer> | auto", //http://www.w3.org/TR/css3-multicol/

src/css/ValidationTypes.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ var ValidationTypes = {
184184
return part.type == "function" && (part.name == "rect" || part.name == "inset-rect");
185185
},
186186

187+
"<basic-shape>": function(part){
188+
// inset() = inset( <shape-arg>{1,4} [round <border-radius>]? )
189+
// circle() = circle( [<shape-radius>]? [at <position>]? )
190+
// ellipse() = ellipse( [<shape-radius>{2}]? [at <position>]? )
191+
// polygon() = polygon( [<fill-rule>,]? [<shape-arg> <shape-arg>]# )
192+
return part.type == "function" && (
193+
part.name == "inset" || part.name == "circle" || part.name == "ellipse" || part.name == "polygon"
194+
);
195+
},
196+
197+
"<shape-box>": function(part) {
198+
return this["<box>"](part) || ValidationTypes.isLiteral(part, "margin-box");
199+
},
200+
201+
"<geometry-box>": function(part) {
202+
return this["<shape-box>"](part) || ValidationTypes.isLiteral(part, "fill-box | stroke-box | view-box");
203+
},
204+
187205
"<time>": function(part) {
188206
return part.type == "time";
189207
},
@@ -211,7 +229,7 @@ var ValidationTypes = {
211229
"<flex-wrap>": function(part){
212230
return ValidationTypes.isLiteral(part, "nowrap | wrap | wrap-reverse");
213231
},
214-
232+
215233
"<feature-tag-value>": function(part){
216234
return (part.type == "function" && /^[A-Z0-9]{4}$/i.test(part));
217235
}
@@ -308,6 +326,29 @@ var ValidationTypes = {
308326
return result;
309327
},
310328

329+
"<clip-source>": function(expression){
330+
return ValidationTypes.isAny(expression, "<uri>");
331+
},
332+
333+
"<clip-path>": function(expression) {
334+
// <basic-shape> || <geometry-box>
335+
var result = false;
336+
337+
if (ValidationTypes.isType(expression, "<basic-shape>")) {
338+
result = true;
339+
if (expression.hasNext()) {
340+
result = ValidationTypes.isType(expression, "<geometry-box>");
341+
}
342+
} else if (ValidationTypes.isType(expression, "<geometry-box>")) {
343+
result = true;
344+
if (expression.hasNext()) {
345+
result = ValidationTypes.isType(expression, "<basic-shape>");
346+
}
347+
}
348+
349+
return result && !expression.hasNext();
350+
},
351+
311352
"<repeat-style>": function(expression){
312353
//repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}
313354
var result = false,

tests/css/Validation.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,57 @@
573573
}
574574
}));
575575

576+
suite.add(new ValidationTestCase({
577+
property: "clip",
578+
579+
valid: [
580+
"rect(10%, 85%, 90%, 15%)",
581+
'auto'
582+
],
583+
584+
invalid: {
585+
"foo" : "Expected (<shape> | auto | inherit) but found 'foo'."
586+
}
587+
}));
588+
589+
suite.add(new ValidationTestCase({
590+
property: "clip-path",
591+
592+
valid: [
593+
"inset(10% 15% 10% 15%)",
594+
"circle(30% at 85% 15%)",
595+
"url('#myPath')",
596+
"ellipse(40% 40%)",
597+
"margin-box",
598+
"ellipse(40% 40%) content-box",
599+
"stroke-box ellipse(40% 40%)",
600+
"none"
601+
],
602+
603+
invalid: {
604+
"stroke-box ellipse(40% 40%) 40%" : "Expected end of value but found '40%'.",
605+
"x-box" : "Expected (<clip-source> | <clip-path> | none) but found 'x-box'.",
606+
"foo" : "Expected (<clip-source> | <clip-path> | none) but found 'foo'.",
607+
"invert(40% 40%)" : "Expected (<clip-source> | <clip-path> | none) but found 'invert(40% 40%)'.",
608+
"40%" : "Expected (<clip-source> | <clip-path> | none) but found '40%'.",
609+
"0.4" : "Expected (<clip-source> | <clip-path> | none) but found '0.4'."
610+
}
611+
}));
612+
613+
suite.add(new ValidationTestCase({
614+
property: "clip-rule",
615+
616+
valid: [
617+
"nonzero",
618+
"evenodd",
619+
"inherit"
620+
],
621+
622+
invalid: {
623+
"foo" : "Expected (nonzero | evenodd | inherit) but found 'foo'."
624+
}
625+
}));
626+
576627
suite.add(new ValidationTestCase({
577628
property: "color",
578629

0 commit comments

Comments
 (0)