1. Introduction
This spec is a very rough draft. I’m not gonna try for precise wording here; you’ll get the gist. Details can be nailed down when we take this seriously.
2. Defining Complex Filters in CSS: the @filter rule
The syntax of an @filter rule is:
@filter = @filter <custom-ident> { <declaration-list> }
The @filter rule accepts a handful of descriptors, described in later subsections, but is mostly filled by other filter primitive rules, such as @blend. The presense of unknown descriptors, or at-rules other than filter primitive rules, are invalid and cause those descriptors/rules to be ignored, but do not make the @filter rule invalid.
Note: Equivalents of filterUnits and primitiveUnits are intentionally not included. The *Units properties are a weird SVG-ism caused by the fact that they only have two units - integers and percentages. CSS doesn’t need this.
2.1. Filter Errors
Some mistakes in defining a @filter rule or its contents can cause a filter error. When a @filter rule or its contents cause a filter error, the @filter rule represents the null filter, regardless of what else it specifies.
The null filter has no effect—
2.2. Referring to @filter Rules
I’m currently requiring filter names to be <custom-ident>s - can we just accept that as an ident in the filter property? Or maybe we can relax that and just prevent filter names from being "none" or the global keywords, like @counter-style does, ugh.
2.3. Sizing the Filter Region: the position and size descriptors
Name: | position |
---|---|
For: | @filter |
Value: | <position> |
Initial: | -10% -10% |
Name: | size |
---|---|
For: | @filter |
Value: | <‘background-size’> |
Initial: | 120% 120% |
2.4. Controlling the Resolution of a Filter: the resolution descriptor
Name: | resolution |
---|---|
For: | @filter |
Value: | auto | <resolution>{1,2} |
Initial: | auto |
3. Using Variable References in @filter Descriptors
All of the at-rules defined in this specification allow variable references
(the var() function)
in their descriptors,
in addition to whatever else their syntax states.
During parsing, these are interpreted identically to the use of var() in CSS properties—
Variables are substituted at time-of-use, based on the values of custom properties on the element referencing the @filter rule.
Note: Thus, a single @filter rule can have its variables filled in with multiple different values, if it’s referenced by multiple different elements. Each reference is a separate "instance" for this purpose.
Note: This should also work for @apply in the same way. Need to generalize/define the concept of "variable reference" to include that.
4. Filter Primitive Rules
The filter primitive rules are a set of at-rules that define the behavior of a filter. They’re only valid within the top-level of an @filter rule; if found anywhere else, they’re invalid and must be ignored.
4.1. Common Descriptors
All filter primitive rules accept the following descriptors, and interpret them in the same way:
Name: | position |
---|---|
For: | @blend |
Value: | <position> |
Initial: | -10% -10% |
Name: | size |
---|---|
For: | @blend |
Value: | <‘background-size’> |
Initial: | 120% 120% |
These two are interpreted the same as for @filter.
Name: | in |
---|---|
For: | @blend |
Value: | auto | source-graphic | source-alpha | background-image | background-alpha | fill-paint | stroke-paint | <string> |
Initial: | auto |
The in descriptor specifies what the input to the filter is. Values are defined as follows:
- auto
-
If this is specified on the first filter primitive rule in a @filter rule,
it behaves as source-graphic.
Otherwise, the input is the output of the previous filter primitive rule in the @filter rule.
- <string>
- Refers to the nearest preceding filter primitive rule which specified the same string as its result descriptor.
If there is no such preceding filter primitive rule, this causes a filter error.
- etc
- Same as SVG.
Name: | result |
---|---|
For: | @blend |
Value: | none | <string> |
Initial: | none |
The result descriptor gives the output of a filter primitive rule a name, so it can be referred to by later filter primitive rules in the same @filter rule.
Note: In most common cases it is not necessary to specify this, as the value of one filter primitive rule is fed directly into the following filter primitive rule by default.
5. Compositing Two Images: the @blend filter primitive rule
The @blend rule composites two inputs together into a single output.
Name: | in2 |
---|---|
For: | @blend |
Value: | <‘in’> |
Initial: | auto |
The @blend rule requires two inputs. The in2 descriptor specifies the second input.
Name: | mode |
---|---|
For: | @blend |
Value: | normal | multiply | screen | darken | lighten |
Initial: | normal |
The mode descriptor specifies how the two inputs are to be blended together. The values are defined in the SVG spec.