CSS stylesheets are parsed into abstract UA-internal data structures, the internal representations of CSS, which various specification algorithms manipulate.
Internal representations can’t be directly manipulated, as they are implementation-dependent; UAs have to agree on how to interpret the internal representations, but the representations themselves are purposely left undefined so that UAs can store and manipulate CSS in whatever way is most efficient for them.
Previously, the only way to read or write to the internal representations was via strings—stylesheets or the CSSOM allowed authors to send strings to the UA, which were parsed into internal representations, and the CSSOM allowed authors to request that the UA serialize their internal representations back into strings.
This specification introduces a new way to interact with internal representations, by representing them with specialized JS objects that can be manipulated and understood more easily and more reliably than string parsing/concatenation. This new approach is both easier for authors (for example, numeric values are reflected with actual JS numbers, and have unit-aware mathematical operations defined for them) and in many cases are more performant, as values can be directly manipulated and then cheaply translated back into internal representations without having to build and then parse strings of CSS.
2.CSSStyleValue
objects
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSStyleValue
{ stringifier; [Exposed=Window] static CSSStyleValue parse(USVStringproperty
, USVStringcssText
); [Exposed=Window] static sequence<CSSStyleValue> parseAll(USVStringproperty
, USVStringcssText
); };
CSSStyleValue
objects are the base class of all CSS values accessible via the Typed OM API.
The stringification behavior of CSSStyleValue
objects is defined in § 6 CSSStyleValue Serialization.
The parse(property, cssText)
method, when invoked, must parse a CSSStyleValue with property property, cssText cssText, and parseMultiple set to false, and return the result.
The parseAll(property, cssText)
method, when invoked, must parse a CSSStyleValue with property property, cssText cssText, and parseMultiple set to true, and return the result.
To
parse a CSSStyleValuegiven a
string property, a
string cssText, and a
parseMultipleflag, run these steps:
If property is not a custom property name string, set property to property ASCII lowercased.
If property is not a valid CSS property, throw a TypeError
.
Attempt to parse cssText according to property’s grammar. If this fails, throw a TypeError
. Otherwise, let whole value be the parsed result.
The behavior of custom properties are different when modified via JavaScript than when defined in style sheets.
When a custom property is defined with an invalid syntax in a style sheet, then the value is recorded as "unset", to avoid having to reparse every style sheet when a custom property is registered.
Conversely, when a custom property is modified via the JavaScript API, any parse errors are propagated to the progamming environment via a TypeError
. This allows more immediate feedback of errors to developers.
Subdivide into iterations whole value, according to property, and let values be the result.
For each value in values, replace it with the result of reifying value for property.
If parseMultiple is false, return values[0]. Otherwise, return values.
To
subdivide into iterationsa CSS value
whole valuefor a property
property, execute the following steps:
If property is a single-valued property, return a list containing whole value.
Otherwise, divide whole value into individual iterations, as appropriate for property, and return a list containing the iterations in order.
How to divide a
list-valued propertyinto iterations is intentionally undefined and hand-wavey at the moment.
Generally, you just split it on top-level commas (corresponding to a top-level
<foo>#
term in the grammar), but some legacy properties (such as
counter-reset) don’t separate their iterations with commas.
It’s expected to be rigorously defined in the future, but at the moment is explicitly a "you know what we mean" thing.
2.1. DirectCSSStyleValue
Objects
Values that can’t yet be directly supported by a more specialized CSSStyleValue
subclass are instead represented as CSSStyleValue
objects.
Each CSSStyleValue
object is associated with a particular CSS property, via its [[associatedProperty]]
internal slot, and a particular, immutable, internal representation. These objects are said to "represent" the particular internal representation they were reified from, such that if they are set back into a stylesheet for the same property, they reproduce an equivalent internal representation.
These CSSStyleValue
objects are only considered valid for the property that they were parsed for. This is enforced by CSSStyleValue
objects having a [[associatedProperty]]
internal slot, which is either null
(the default) or a string specifying a property name.
Note: This slot is checked by StylePropertyMap
.set()
/append()
StylePropertyMap
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceStylePropertyMapReadOnly
{ iterable<USVString, sequence<CSSStyleValue>>; (undefined or CSSStyleValue) get(USVStringproperty
); sequence<CSSStyleValue> getAll(USVStringproperty
); boolean has(USVStringproperty
); readonly attribute unsigned long size; }; [Exposed=Window] interfaceStylePropertyMap
: StylePropertyMapReadOnly { undefined set(USVStringproperty
, (CSSStyleValue or USVString)...values
); undefined append(USVStringproperty
, (CSSStyleValue or USVString)...values
); undefined delete(USVStringproperty
); undefined clear(); };
StylePropertyMap
is an alternate way to represent a CSS declaration block as an object (when fetched via the [cssom], CSS declaration blocks are instead represented as CSSStyleDeclaration
objects.)
Some CSS properties are list-valued properties, such as background-image or animation; their value is a list of parallel grammar terms, almost always comma-separated (the only exceptions are certain legacy properties like counter-reset), indicating multiple distinct "values" interpreted in the same way. Other properties, such as color, are single-valued properties; they take only a single (possibly complex) value.
There are multiple examples of CSS properties that have transitioned from being
single-valuedto
list-valued. To ensure that code written at a time when a property was
single-valueddoes not break when it becomes
list-valuedin the future, the
StylePropertyMap
is a
multi-map; it stores
listof values for each key, but allows you to interact with it as if there was only a single value for each key as well.
This means that multiple values for a single property in a StylePropertyMap
do not represent multiple successive definition of that property’s value; instead, they represent multiple comma-separated sub-values in a single property value, like each "layer" in a background-image property.
The
set(property, ...values)
method, when called on a
StylePropertyMap
this
, must perform the following steps:
If property is not a custom property name string, set property to property ASCII lowercased.
If property is not a valid CSS property, throw a TypeError
.
If property is a single-valued property and values has more than one item, throw a TypeError
.
If any of the items in values have a non-null [[associatedProperty]]
internal slot, and that slot’s value is anything other than property, throw a TypeError
.
If the size of values is two or more, and one or more of the items are a CSSUnparsedValue
or CSSVariableReferenceValue
object, throw a TypeError
.
Note: Having 2+ values implies that you’re setting multiple items of a list-valued property, but the presence of a var() function in the string-based OM disables all syntax parsing, including splitting into individual iterations (because there might be more commas inside of the var() value, so you can’t tell how many items are actually going to show up). This step’s restriction preserves the same semantics in the Typed OM.
Let props be the value of this’s [[declarations]]
internal slot.
Let values to set be an empty list.
For each value in values, create an internal representation for property and value, and append the result to values to set.
Set props[property] to values to set.
Note: The property is deleted then added back so that it gets put at the end of the ordered map, which gives the expected behavior in the face of shorthand properties.
The
append(property, ...values)
method, when called on a
StylePropertyMap
this
, must perform the following steps:
If property is not a custom property name string, set property to property ASCII lowercased.
If property is not a valid CSS property, throw a TypeError
.
If property is not a list-valued property, throw a TypeError
.
If any of the items in values have a non-null [[associatedProperty]]
internal slot, and that slot’s value is anything other than property, throw a TypeError
.
If any of the items in values are a CSSUnparsedValue
or CSSVariableReferenceValue
object, throw a TypeError
.
Note: When a property is set via string-based APIs, the presence of var() in a property prevents the entire thing from being interpreted. In other words, everything besides the var() is a plain component value, not a meaningful type. This step’s restriction preserves the same semantics in the Typed OM.
Let props be the value of this’s [[declarations]]
internal slot.
If props[property] does not exist, set props[property] to an empty list.
If props[property] contains a var() reference, throw a TypeError
.
Let temp values be an empty list.
For each value in values, create an internal representation with property and value, and append the returned value to temp values.
Append the entries of temp values to props[property].
To
create an internal representation, given a
string propertyand a
stringor
CSSStyleValue
value
:
CSSStyleValue
,
Return value’s associated value.
CSSStyleValue
subclass,
If value does not match the grammar of a list-valued property iteration of property, throw a TypeError
.
If any component of property’s CSS grammar has a limited numeric range, and the corresponding part of value is a CSSUnitValue
that is outside of that range, replace that value with the result of wrapping it in a fresh CSSMathSum
whose values
internal slot contains only that part of value.
Return the value.
USVString
,
Parse a CSSStyleValue with property property, cssText value, and parseMultiple set to false
, and return the result.
Note: This can throw a TypeError
instead.
A string is a custom property name string if it starts with two dashes (U+002D HYPHEN-MINUS), like --foo
. (This corresponds to the <custom-property-name> production, but applies to strings, rather than identifiers; it can be used without invoking the CSS parser.)
A string is a valid CSS property if it is a custom property name string, or is a CSS property name recognized by the user agent.
3.1. ComputedStylePropertyMapReadOnly
objects
partial interface Element { [SameObject] StylePropertyMapReadOnly computedStyleMap(); };
Computed StylePropertyMap objects represent the computed values of an Element
, and are accessed by calling the computedStyleMap()
method.
Every Element
has a [[computedStyleMapCache]]
internal slot, initially set to null
, which caches the result of the computedStyleMap()
method when it is first called.
The
computedStyleMap()
method must, when called on an
Element
this
, perform the following steps:
If this’s [[computedStyleMapCache]]
internal slot is set to null
, set its value to a new StylePropertyMapReadOnly
object, whose [[declarations]]
internal slot are the name and computed value of every longhand CSS property supported by the User Agent, every registered custom property, and every non-registered custom property which is not set to its initial value on this, in the standard order.
The computed values in the [[declarations]]
of this object must remain up-to-date, changing as style resolution changes the properties on this and how they’re computed.
Note: In practice, since the values are "hidden" behind a .get()
method call, UAs can delay computing anything until a given property is actually requested.
Return this’s [[computedStyleMapCache]]
internal slot.
Note: like Window.getComputedStyle()
, this method can expose information from stylesheets with the origin-clean flag unset.
Note: The StylePropertyMapReadOnly
returned by this method represents the actual computed values, not the resolved value concept used by Window.getComputedStyle()
. It can thus return different values than Window.getComputedStyle()
for some properties (such as width).
Note: Per WG resolution, pseudo-element styles are intended to be obtainable by adding this method to the new PseudoElement
interface (rather than using a pseudoElt
argument like Window.getComputedStyle()
does).
StylePropertyMap
objects
partial interface CSSStyleRule { [SameObject] readonly attribute StylePropertyMap styleMap; }; partial interface mixin ElementCSSInlineStyle { [SameObject] readonly attribute StylePropertyMap attributeStyleMap; };
Declared StylePropertyMap objects represent style property-value pairs embedded in a style rule or inline style, and are accessed via the styleMap
attribute of CSSStyleRule
objects, or the attributeStyleMap
attribute of objects implementing the ElementCSSInlineStyle
interface mixin (such as HTMLElement
s).
When constructed, the [[declarations]]
internal slot for declared StylePropertyMap objects is initialized to contain an entry for each property with a valid value inside the CSSStyleRule
or inline style that the object represents, in the same order as the CSSStyleRule
or inline style.
CSSStyleValue
subclasses 4.1. CSSUnparsedValue
objects
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSUnparsedValue
: CSSStyleValue {constructor
(sequence<CSSUnparsedSegment>members
); iterable<CSSUnparsedSegment>; readonly attribute unsigned long length; getter CSSUnparsedSegment (unsigned longindex
); setter CSSUnparsedSegment (unsigned longindex
, CSSUnparsedSegmentval
); }; typedef (USVString or CSSVariableReferenceValue)CSSUnparsedSegment
; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSVariableReferenceValue
{ constructor(USVStringvariable
, optional CSSUnparsedValue?fallback
= null); attribute USVString variable; readonly attribute CSSUnparsedValue?fallback
; };
CSSUnparsedValue
objects represent property values that reference custom properties. They are comprised of a list of string fragments and variable references.
They have a [[tokens]]
internal slot, which is a list of USVString
s and CSSVariableReferenceValue
objects. This list is the object’s values to iterate over.
The length
attribute returns the size of the [[tokens]]
internal slot.
The
supported property indexesof a
CSSUnparsedValue
this
are the integers greater than or equal to 0, and less than the
sizeof
this’s
[[tokens]]
internal slot.
To determine the value of an indexed property of a CSSUnparsedValue
this and an index n, let tokens be this’s [[tokens]]
internal slot, and return tokens[n].
To set the value of an existing indexed property of a CSSUnparsedValue
this, an index n, and a value new value, let tokens be this’s [[tokens]]
internal slot, and set tokens[n] to new value.
To set the value of a new indexed property of a CSSUnparsedValue
this, an index n, and a value new value, let tokens be this’s [[tokens]]
internal slot. If n is not equal to the size of tokens, throw a RangeError
. Otherwise, append new value to tokens.
CSSKeywordValue
objects
CSSKeywordValue
objects represent CSS keywords and other idents.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSKeywordValue
: CSSStyleValue { constructor(USVStringvalue
); attribute USVString value; };
The
CSSKeywordValue(value)
constructor must, when called, perform the following steps:
Otherwise, return a new CSSKeywordValue
with its value
internal slot set to value.
Any place that accepts a CSSKeywordValue
also accepts a raw USVString
, by using the following typedef and algorithm:
typedef (DOMString or CSSKeywordValue) CSSKeywordish
;
The
value
attribute of a
CSSKeywordValue
this
must, on setting a value
value, perform the following steps:
Otherwise, set this’s value
internal slot, to value.
CSSNumericValue
objects represent CSS values that are numeric in nature (<number>s, <percentage>s, <dimension>s). There are two interfaces that inherit from CSSNumericValue
:
CSSUnitValue
objects represent values that contain a single unit type (for example "42px").
CSSMathValue
objects represent math expressions, which can contain more than one value/unit (for example "calc(56em + 10%)").
CSSNumericValue
objects are not range-restricted. Any valid numeric value can be represented by a CSSNumericValue
, and that value will not be clamped, rounded, or rejected when set on a declared StylePropertyMap. Instead, clamping and/or rounding will occur during computation of style.
The following code is valid
myElement.attributeStyleMap.set("opacity", CSS.number(3)); myElement.attributeStyleMap.set("z-index", CSS.number(15.4)); console.log(myElement.attributeStyleMap.get("opacity").value); // 3 console.log(myElement.attributeStyleMap.get("z-index").value); // 15.4 var computedStyle = myElement.computedStyleMap(); var opacity = computedStyle.get("opacity"); var zIndex = computedStyle.get("z-index");
After execution, the value of opacity
is 1
(opacity is range-restricted), and the value of zIndex
is 15
(z-index is rounded to an integer value).
Note: "Numeric values" which incorporate variable references will instead be represented as CSSUnparsedValue
objects, and keywords as CSSKeywordValue
objects.
Any place that accepts a CSSNumericValue
also accepts a raw double
, by using the following typedef and algorithm:
typedef (double or CSSNumericValue) CSSNumberish
;
To
rectify a numberish value num, optionally to a given unit
unit(defaulting to "number"), perform the following steps:
If num is a CSSNumericValue
, return num.
If num is a double
, return a new CSSUnitValue
with its value
internal slot set to num and its unit
internal slot set to unit.
CSSNumericValue
Superclass
All numeric CSS values (<number>s, <percentage>s, and <dimension>s) are represented by subclasses of the CSSNumericValue
interface.
enumCSSNumericBaseType
{"length"
,"angle"
,"time"
,"frequency"
,"resolution"
,"flex"
,"percent"
, }; dictionaryCSSNumericType
{ longlength
; longangle
; longtime
; longfrequency
; longresolution
; longflex
; longpercent
; CSSNumericBaseTypepercentHint
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSNumericValue
: CSSStyleValue { CSSNumericValue add(CSSNumberish...values
); CSSNumericValue sub(CSSNumberish...values
); CSSNumericValue mul(CSSNumberish...values
); CSSNumericValue div(CSSNumberish...values
); CSSNumericValue min(CSSNumberish...values
); CSSNumericValue max(CSSNumberish...values
); boolean equals(CSSNumberish...value
); CSSUnitValue to(USVStringunit
); CSSMathSum toSum(USVString...units
); CSSNumericType type(); [Exposed=Window] static CSSNumericValue parse(USVStringcssText
); };
The methods on the CSSNumericValue
superclass represent operations that all numeric values can perform.
The following are the arithmetic operations you can perform on dimensions:
The
add(...values)
method, when called on a
CSSNumericValue
this
, must perform the following steps:
Replace each item of values with the result of rectifying a numberish value for the item.
If this is a CSSMathSum
object, prepend the items in this’s values
internal slot to values. Otherwise, prepend this to values.
If all of the items in values are CSSUnitValue
s and have the same unit
, return a new CSSUnitValue
whose unit
internal slot is set to this’s unit
internal slot, and value
internal slot is set to the sum of the value
internal slots of the items in values. This addition must be done "left to right" - if values is « 1, 2, 3, 4 », the result must be (((1 + 2) + 3) + 4). (This detail is necessary to ensure interoperability in the presence of floating-point arithmetic.)
Let type be the result of adding the types of every item in values. If type is failure, throw a TypeError
.
Return a new CSSMathSum
object whose values
internal slot is set to values.
The
mul(...values)
method, when called on a
CSSNumericValue
this
, must perform the following steps:
Replace each item of values with the result of rectifying a numberish value for the item.
If this is a CSSMathProduct
object, prepend the items in this’s values
internal slot to values. Otherwise, prepend this to values.
If all of the items in values are CSSUnitValue
s with unit
internal slot set to "number", return a new CSSUnitValue
whose unit
internal slot is set to "number", and value
internal slot is set to the product of the value
internal slots of the items in values.
This multiplication must be done "left to right" - if values is « 1, 2, 3, 4 », the result must be (((1 × 2) × 3) × 4). (This detail is necessary to ensure interoperability in the presence of floating-point arithmetic.)
If all of the items in values are CSSUnitValue
s with unit
internal slot set to "number" except one which is set to unit, return a new CSSUnitValue
whose unit
internal slot is set to unit, and value
internal slot is set to the product of the value
internal slots of the items in values.
This multiplication must be done "left to right" - if values is « 1, 2, 3, 4 », the result must be (((1 × 2) × 3) × 4).
Let type be the result of multiplying the types of every item in values. If type is failure, throw a TypeError
.
Return a new CSSMathProduct
object whose values
internal slot is set to values.
This notion of equality is purposely fairly exacting; all the values must be the exact same type and value, in the same order. For example,
CSSMathSum(CSS.px(1), CSS.px(2))
is
notequal to
CSSMathSum(CSS.px(2), CSS.px(1))
.
This precise notion is used because it allows structural equality to be tested for very quickly; if we were to use a slower and more forgiving notion of equality, such as allowing the arguments to match in any order, we’d probably want to go all the way and perform other simplifications, like considering 96px to be equal to 1in; this looser notion of equality might be added in the future.
When asked to
create a CSSUnitValue from a sum value item item, perform the following steps:
If item has more than one entry in its unit map, return failure.
If item has no entries in its unit map, return a new CSSUnitValue
whose unit
internal slot is set to "number", and whose value
internal slot is set to item’s value.
Otherwise, item has a single entry in its unit map. If that entry’s value is anything other than 1
, return failure.
Otherwise, return a new CSSUnitValue
whose unit
internal slot is set to that entry’s key, and whose value
internal slot is set to item’s value.
The
toSum(...units)
method converts an existing
CSSNumericValue
this
into a
CSSMathSum
of only
CSSUnitValue
s with the specified units, if possible. (It’s like
to()
, but allows the result to have multiple units in it.) If called without any units, it just simplifies
thisinto a minimal sum of
CSSUnitValue
s.
When called, it must perform the following steps:
For each unit in units, if the result of creating a type from unit is failure, throw a SyntaxError
.
Let sum be the result of creating a sum value from this. If sum is failure, throw a TypeError
.
Let values be the result of creating a CSSUnitValue for each item in sum. If any item of values is failure, throw a TypeError
.
If units is empty, sort values in code point order according to the unit
internal slot of its items, then return a new CSSMathSum
object whose values
internal slot is set to values.
Otherwise, let result initially be an empty list. For each unit in units:
Let temp initially be a new CSSUnitValue
whose unit
internal slot is set to unit and whose value
internal slot is set to 0
.
For each value in values:
Append temp to result.
If values is not empty, throw a TypeError
. this had units that you didn’t ask for.
Return a new CSSMathSum
object whose values
internal slot is set to result.
The
type()
method returns a representation of the
typeof
this.
When called, it must perform the following steps:
Let result be a new CSSNumericType
.
For each baseType → power in the type of this,
If power is not 0, set result[baseType] to power.
If the percent hint of this is not null,
Set percentHint
to the percent hint of this.
Return result.
A
sum valueis an abstract representation of a
CSSNumericValue
as a sum of numbers with (possibly complex) units. Not all
CSSNumericValue
s can be expressed as a
sum value.
A sum value is a list. Each entry in the list is a tuple of a value, which is a number, and a unit map, which is a map of units (strings) to powers (integers).
Here are a few examples of CSS values, and their equivalent
sum values:
1px becomes «(1, «["px" → 1]»)»
calc(1px + 1in) becomes «(97, «["px" → 1]»)»
(because in and px are compatible units, and px is the canonical unit for them)
calc(1px + 2em) becomes «(1, «["px" → 1]»), (2, «["em" → 1]»)»
calc(1px + 2%) becomes «(1, «["px" → 1]»), (2, «["percent" → 1]»)»
(percentages are allowed to add to other units, but aren’t resolved into another unit, like they are in a type)
calc(1px * 2em) becomes «(2, «["em" → 1, "px" → 1]»)»
calc(1px + 1deg) can’t be represented as a sum value because it’s an invalid computation
calc(1px * 2deg) becomes «(2, «["deg" → 1, "px" → 1]»)»
To create a sum value from a CSSNumericValue
this, the steps differ based on this’s class:
CSSUnitValue
Let unit be the value of this’s unit
internal slot, and value be the value of this’s value
internal slot.
If unit is a member of a set of compatible units, and is not the set’s canonical unit, multiply value by the conversion ratio between unit and the canonical unit, and change unit to the canonical unit.
If unit is "number"
, return «(value, «[ ]»)».
Otherwise, return «(value, «[unit → 1]»)»
.
CSSMathSum
CSSMathNegate
Let values be the result of creating a sum value from this’s value
internal slot.
If values is failure, return failure.
Return values.
CSSMathProduct
Let values initially be the sum value «(1, «[ ]»)». (I.e. what you’d get from 1.)
For each item in this’s values
internal slot:
Let new values be the result of creating a sum value from item. Let temp initially be an empty list.
If new values is failure, return failure.
For each item1 in values:
Set values to temp.
Return values.
CSSMathInvert
Let values be the result of creating a sum value from this’s value
internal slot.
If values is failure, return failure.
If the length of values is more than one, return failure.
Invert (find the reciprocal of) the value of the item in values, and negate the value of each entry in its unit map.
Return values.
CSSMathMin
CSSMathMax
To
create a type from a unit map unit map:
Let types be an initially empty list.
For each unit → power in unit map:
Let type be the result of creating a type from unit.
Set type’s sole value to power.
Append type to types.
Return the result of multiplying all the items of types.
The
product of two unit maps units1and
units2is the result given by the following steps:
Let result be a copy of units1.
For each unit → power in units2:
If result[unit] exists, increment result[unit] by power.
Otherwise, set result[unit] to power.
Return result.
The parse()
method allows a CSSNumericValue
to be constructed directly from a string containing CSS. Note that this is a static method, existing directly on the CSSNumericValue
interface object, rather than on CSSNumericValue
instances.
Each CSSNumericValue
has an associated type, which is a map of base types to integers (denoting the exponent of each type, so a <length>2, such as from calc(1px * 1em), is «[ "length" → 2 ]»), and an associated percent hint (indicating that the type actually holds a percentage, but that percentage will eventually resolve to the hinted base type, and so has been replaced with it in the type).
The base types are "length", "angle", "time", "frequency", "resolution", "flex", and "percent". The ordering of a type’s entries always matches this base type ordering. The percent hint is either null or a base type other than "percent".
Note: As new unit types are added to CSS, they’ll be added to this list of base types, and to the CSS math functions.
To
create a typefrom a string
unit, follow the appropriate branch of the following:
Return «[ ]» (empty map)
Return «[ "percent" → 1 ]»
Return «[ "length" → 1 ]»
Return «[ "angle" → 1 ]»
Return «[ "time" → 1 ]»
Return «[ "frequency" → 1 ]»
Return «[ "resolution" → 1 ]»
Return «[ "flex" → 1 ]»
Return failure.
In all cases, the associated percent hint is null.
To
add two types type1and
type2, perform the following steps:
Replace type1 with a fresh copy of type1, and type2 with a fresh copy of type2. Let finalType be a new type with an initially empty ordered map and an initially null percent hint.
The types can’t be added. Return failure.
Apply the percent hint hint to type2.
Vice versa if type2 has a non-null percent hint and type1 doesn’t.
Continue to the next step.
Copy all of type1’s entries to finalType, and then copy all of type2’s entries to finalType that finalType doesn’t already contain. Set finalType’s percent hint to type1’s percent hint. Return finalType.
For each base type other than "percent" hint:
Provisionally apply the percent hint hint to both type1 and type2.
If, afterwards, all the entries of type1 with non-zero values are contained in type2 with the same value, and vice versa, then copy all of type1’s entries to finalType, and then copy all of type2’s entries to finalType that finalType doesn’t already contain. Set finalType’s percent hint to hint. Return finalType.
Otherwise, revert type1 and type2 to their state at the start of this loop.
If the loop finishes without returning finalType, then the types can’t be added. Return failure.
Note: You can shortcut this in some cases by just checking the sum of all the values of type1 vs type2. If the sums are different, the types can’t be added.
The types can’t be added. Return failure.
To
apply the percent hint hintto a
type, perform the following steps:
If type doesn’t contain hint, set type[hint] to 0.
If type contains "percent", add type["percent"] to type[hint], then set type["percent"] to 0.
Set type’s percent hint to hint.
To
multiply two types type1and
type2, perform the following steps:
Replace type1 with a fresh copy of type1, and type2 with a fresh copy of type2. Let finalType be a new type with an initially empty ordered map and an initially null percent hint.
If both type1 and type2 have non-null percent hints with different values, the types can’t be multiplied. Return failure.
If type1 has a non-null percent hint hint and type2 doesn’t, apply the percent hint hint to type2.
Vice versa if type2 has a non-null percent hint and type1 doesn’t.
Copy all of type1’s entries to finalType, then for each baseType → power of type2:
If finalType[baseType] exists, increment its value by power.
Otherwise, set finalType[baseType] to power.
Set finalType’s percent hint to type1’s percent hint.
Return finalType.
To
invert a type type, perform the following steps:
Let result be a new type with an initially empty ordered map and a percent hint matching that of type.
For each unit → exponent of type, set result[unit] to (-1 * exponent).
Return result.
Note: Types form a semi-group under both addition and a monoid under multiplication (with the multiplicative identity being «[ ]» with a null percent hint), meaning that they’re associative and commutative. Thus the spec can, for example, add an unbounded number of types together unambiguously, rather than having to manually add them pair-wise.
4.3.3. Value + Unit:CSSUnitValue
objects
Numeric values that can be expressed as a single unit (or a naked number or percentage) are represented as CSSUnitValue
s.
For example, the value
5pxin a stylesheet will be represented by a
CSSUnitValue
with its
value
attribute set to
5
and its
unit
attribute set to
"px"
.
Similarly, the value 10 in a stylesheet will be represented by a CSSUnitValue
with its value
attribute set to 10
and its unit
attribute set to "number"
.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSUnitValue
: CSSNumericValue { constructor(doublevalue
, USVStringunit
); attribute doublevalue
; readonly attribute USVStringunit
; };
The
CSSUnitValue(value, unit)
constructor must, when called, perform the following steps:
If creating a type from unit returns failure, throw a TypeError
and abort this algorithm.
Return a new CSSUnitValue
with its value
internal slot set to value and its unit
set to unit.
To
create a CSSUnitValue from a pair(
num,
unit), return a new
CSSUnitValue
object with its
value
internal slot set to
num, and its
unit
internal slot set to
unit.
For example, creating a
new unit valuefrom
(5, "px")
creates an object equivalent to
new CSSUnitValue(5, "px")
.
Note: This is a spec-internal algorithm, meant simply to make it easier to create unit values in algorithms when needed.
To
convert a CSSUnitValue thisto a unit
unit, perform the following steps:
Let old unit be the value of this’s unit
internal slot, and old value be the value of this’s value
internal slot.
If old unit and unit are not compatible units, return failure.
Return a new CSSUnitValue
whose unit
internal slot is set to unit, and whose value
internal slot is set to old value multiplied by the conversation ratio between old unit and unit.
CSSMathValue
objects
Numeric values that are more complicated than a single value+unit are represented by a tree of CSSMathValue
subclasses, eventually terminating in CSSUnitValue
objects at the leaf nodes. The calc(), min(), and max() functions in CSS are represented in this way.
For example, the CSS value
calc(1em + 5px)will be represented by a
CSSMathSum
like
CSSMathSum(CSS.em(1), CSS.px(5))
.
A more complex expression, like calc(1em + 5px * 2), will be represented by a nested structure like CSSMathSum(CSS.em(1), CSSMathProduct(CSS.px(5), 2))
.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathValue
: CSSNumericValue { readonly attribute CSSMathOperator operator; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathSum
: CSSMathValue { constructor(CSSNumberish...args
); readonly attribute CSSNumericArrayvalues
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathProduct
: CSSMathValue { constructor(CSSNumberish...args
); readonly attribute CSSNumericArrayvalues
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathNegate
: CSSMathValue { constructor(CSSNumberisharg
); readonly attribute CSSNumericValuevalue
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathInvert
: CSSMathValue { constructor(CSSNumberisharg
); readonly attribute CSSNumericValuevalue
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathMin
: CSSMathValue { constructor(CSSNumberish...args
); readonly attribute CSSNumericArrayvalues
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathMax
: CSSMathValue { constructor(CSSNumberish...args
); readonly attribute CSSNumericArrayvalues
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMathClamp
: CSSMathValue { constructor(CSSNumberishlower
, CSSNumberishvalue
, CSSNumberishupper
); readonly attribute CSSNumericValuelower
; readonly attribute CSSNumericValuevalue
; readonly attribute CSSNumericValueupper
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSNumericArray
{ iterable<CSSNumericValue>; readonly attribute unsigned long length; getter CSSNumericValue (unsigned longindex
); }; enumCSSMathOperator
{"sum"
,"product"
,"negate"
,"invert"
,"min"
,"max"
,"clamp"
, };
Note: CSSMathValue, being a pure superclass, cannot be directly constructed. It exists solely to host the common attributes of all the "math" operations.
The
CSSMathClamp(lower, value, upper)
constructor must, when called, perform the following steps:
Replace lower, value, and upper with the result of rectifying a numberish value for each.
Let type be the result of adding the types of lower, value, and upper. If type is failure, throw a TypeError
.
Return a new CSSMathClamp
whose lower
, value
, and upper
internal slots are set to lower, value, and upper, respectively.
The
CSSMathNegate(arg)
constructor must, when called, perform the following steps:
Replace arg with the result of rectifying a numberish value for arg.
Return a new CSSMathNegate
whose value
internal slot is set to arg.
The CSSMathInvert(arg)
constructor is defined identically to the above, except that in the last step it returns a new CSSMathInvert
object.
The length
attribute of CSSNumericArray
indicates how many CSSNumericValue
s are contained within the CSSNumericArray
.
The indexed property getter of CSSNumericArray
retrieves the CSSNumericValue
at the provided index.
The following factory functions can be used to create new numeric values much less verbosely than using the constructors directly.
partial namespace CSS { CSSUnitValuenumber
(doublevalue
); CSSUnitValuepercent
(doublevalue
); // <length> CSSUnitValuecap
(doublevalue
); CSSUnitValuech
(doublevalue
); CSSUnitValueem
(doublevalue
); CSSUnitValueex
(doublevalue
); CSSUnitValueic
(doublevalue
); CSSUnitValuelh
(doublevalue
); CSSUnitValuercap
(doublevalue
); CSSUnitValuerch
(doublevalue
); CSSUnitValuerem
(doublevalue
); CSSUnitValuerex
(doublevalue
); CSSUnitValueric
(doublevalue
); CSSUnitValuerlh
(doublevalue
); CSSUnitValuevw
(doublevalue
); CSSUnitValuevh
(doublevalue
); CSSUnitValuevi
(doublevalue
); CSSUnitValuevb
(doublevalue
); CSSUnitValuevmin
(doublevalue
); CSSUnitValuevmax
(doublevalue
); CSSUnitValuesvw
(doublevalue
); CSSUnitValuesvh
(doublevalue
); CSSUnitValuesvi
(doublevalue
); CSSUnitValuesvb
(doublevalue
); CSSUnitValuesvmin
(doublevalue
); CSSUnitValuesvmax
(doublevalue
); CSSUnitValuelvw
(doublevalue
); CSSUnitValuelvh
(doublevalue
); CSSUnitValuelvi
(doublevalue
); CSSUnitValuelvb
(doublevalue
); CSSUnitValuelvmin
(doublevalue
); CSSUnitValuelvmax
(doublevalue
); CSSUnitValuedvw
(doublevalue
); CSSUnitValuedvh
(doublevalue
); CSSUnitValuedvi
(doublevalue
); CSSUnitValuedvb
(doublevalue
); CSSUnitValuedvmin
(doublevalue
); CSSUnitValuedvmax
(doublevalue
); CSSUnitValuecqw
(doublevalue
); CSSUnitValuecqh
(doublevalue
); CSSUnitValuecqi
(doublevalue
); CSSUnitValuecqb
(doublevalue
); CSSUnitValuecqmin
(doublevalue
); CSSUnitValuecqmax
(doublevalue
); CSSUnitValuecm
(doublevalue
); CSSUnitValuemm
(doublevalue
); CSSUnitValueQ
(doublevalue
); CSSUnitValuein
(doublevalue
); CSSUnitValuept
(doublevalue
); CSSUnitValuepc
(doublevalue
); CSSUnitValuepx
(doublevalue
); // <angle> CSSUnitValuedeg
(doublevalue
); CSSUnitValuegrad
(doublevalue
); CSSUnitValuerad
(doublevalue
); CSSUnitValueturn
(doublevalue
); // <time> CSSUnitValues
(doublevalue
); CSSUnitValuems
(doublevalue
); // <frequency> CSSUnitValueHz
(doublevalue
); CSSUnitValuekHz
(doublevalue
); // <resolution> CSSUnitValuedpi
(doublevalue
); CSSUnitValuedpcm
(doublevalue
); CSSUnitValuedppx
(doublevalue
); // <flex> CSSUnitValuefr
(doublevalue
); };
All of the above methods must, when called with a double
value, return a new
CSSUnitValue
whose
value
internal slot is set to
valueand whose
unit
internal slot is set to the name of the method as defined here.
Note: The unit used does not depend on the current name of the function, if it’s stored in another variable; let foo = CSS.px; let val = foo(5);
does not return a {value: 5, unit: "foo"}
CSSUnitValue
. The above talk about names is just a shorthand to avoid defining the unit individually for all ~60 functions.
The above list of methods reflects the set of CSS’s valid predefined units at one particular point in time. It will be updated over time, but might be out-of-date at any given moment. If an implementation supports additional CSS units that do not have a corresponding method in the above list, but that do correspond to one of the existing CSSNumericType
values, it must additionally support such a method, named after the unit in its defined canonical casing, using the generic behavior defined above.
If an implementation supports units that do not correspond to one of the existing CSSNumericType
values, it must not support those units in the APIs defined in this specification; it should request the units and their types be added explicitly to this specification, as the appropriate type name is not implicit from the unit.
If an implementation does not support a given unit, it must not implement its corresponding method from the list above.
For example, the CSS Speech spec
[CSS-SPEECH-1]defines two additional units, the decibel
dBand semitone
st. No current browser implementation supports these or has plans to, so they’re not included in the above list, but if an implementation
doessupport the Speec spec, it must also expose
CSS.dB()
and
CSS.st()
methods.
4.4.CSSTransformValue
objects
CSSTransformValue
objects represent <transform-list> values, used by the transform property. They "contain" one or more CSSTransformComponent
s, which represent individual <transform-function> values.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSTransformValue
: CSSStyleValue { constructor(sequence<CSSTransformComponent>transforms
); iterable<CSSTransformComponent>; readonly attribute unsigned long length; getter CSSTransformComponent (unsigned longindex
); setter CSSTransformComponent (unsigned longindex
, CSSTransformComponentval
); readonly attribute boolean is2D; DOMMatrix toMatrix(); };
A CSSTransformValue
’s values to iterate over is a list of CSSTransformComponent
s.
The
toMatrix()
method of a
CSSTransformValue
this
must, when called, perform the following steps:
Let matrix be a new DOMMatrix
, initialized to the identity matrix, with its is2D
internal slot set to true
.
For each func in this’s values to iterate over:
Let funcMatrix be the DOMMatrix
returned by calling toMatrix()
on func.
Set matrix to the result of multiplying matrix and the matrix represented by funcMatrix.
Return matrix.
The length
attribute indicates how many transform components are contained within the CSSTransformValue
.
They have a [[values]]
internal slot, which is a list of CSSTransformComponent
objects. This list is the object’s values to iterate over.
The
supported property indexesof a
CSSTransformValue
this
are the integers greater than or equal to 0, and less than the
sizeof
this’s
[[values]]
internal slot.
To determine the value of an indexed property of a CSSTransformValue
this and an index n, let values be this’s [[values]]
internal slot, and return values[n].
To set the value of an existing indexed property of a CSSTransformValue
this, an index n, and a value new value, let values be this’s [[values]]
internal slot, and set values[n] to new value.
To set the value of a new indexed property of a CSSTransformValue
this, an index n, and a value new value, let values be this’s [[values]]
internal slot. If n is not equal to the size of values, throw a RangeError
. Otherwise, append new value to values.
typedef (CSSNumericValue or CSSKeywordish)CSSPerspectiveValue
; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSTransformComponent
{ stringifier; attribute boolean is2D; DOMMatrix toMatrix(); }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSTranslate
: CSSTransformComponent { constructor(CSSNumericValuex
, CSSNumericValuey
, optional CSSNumericValuez
); attribute CSSNumericValuex
; attribute CSSNumericValuey
; attribute CSSNumericValuez
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSRotate
: CSSTransformComponent { constructor(CSSNumericValueangle
); constructor(CSSNumberishx
, CSSNumberishy
, CSSNumberishz
, CSSNumericValueangle
); attribute CSSNumberish x; attribute CSSNumberish y; attribute CSSNumberish z; attribute CSSNumericValueangle
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSScale
: CSSTransformComponent { constructor(CSSNumberishx
, CSSNumberishy
, optional CSSNumberishz
); attribute CSSNumberish x; attribute CSSNumberish y; attribute CSSNumberish z; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSSkew
: CSSTransformComponent { constructor(CSSNumericValueax
, CSSNumericValueay
); attribute CSSNumericValueax
; attribute CSSNumericValueay
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSSkewX
: CSSTransformComponent { constructor(CSSNumericValueax
); attribute CSSNumericValueax
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSSkewY
: CSSTransformComponent { constructor(CSSNumericValueay
); attribute CSSNumericValueay
; }; /* Note that skew(x,y) is *not* the same as skewX(x) skewY(y), thus the separate interfaces for all three. */ [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSPerspective
: CSSTransformComponent { constructor(CSSPerspectiveValuelength
); attribute CSSPerspectiveValuelength
; }; [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSMatrixComponent
: CSSTransformComponent { constructor(DOMMatrixReadOnlymatrix
, optional CSSMatrixComponentOptionsoptions
= {}); attribute DOMMatrixmatrix
; }; dictionaryCSSMatrixComponentOptions
{ booleanis2D
; };
The
is2D
attribute indicates whether the transform is 2D or 3D. When it’s
true
, the attributes of the transform that are relevant to 3D transforms (such as the
CSSTranslate.z
attribute) simply have no effect on the transform they represent.
Note: This affects the serialization of the object, and concepts such as the object’s "equivalent 4x4 matrix".
is2D
Design Considerations
For legacy reasons, 2D and 3D transforms are distinct, even if they have identical effects; a translateZ(0px) has observable effects on a page, even tho it’s defined to be an identity transform, as the UA activates some 3D-based optimizations for the element.
There were several possible ways to reflect this—nullable 3D-related attributes, separate 2D and 3D interfaces, etc—but we chose the current design (an author-flippable switch that dictates the behavior) because it allows authors to, in most circumstances, operate on transforms without having to care whether they’re 2D or 3D, but also prevents "accidentally" flipping a 2D transform into becoming 3D.
The
CSSTranslate(x, y, z)
constructor must, when invoked, perform the following steps:
If x or y don’t match <length-percentage>, throw a TypeError
.
If z was passed, but doesn’t match <length>, throw a TypeError
.
Let this be a new CSSTranslate
object, with its x
and y
internal slots set to x and y.
If z was passed, set this’s z
internal slot to z, and set this’s is2D
internal slot to false
.
If z was not passed, set this’s z
internal slot to a new unit value of (0, "px")
, and set this’s is2D
internal slot to true
.
Return this.
The
CSSRotate(x, y, z, angle)
constructor must, when invoked, perform the following steps:
Let x, y, and z be replaced by the result of rectifying a numberish value.
Return a new CSSRotate
with its angle
internal slot set to angle, its x
, y
, z
internal slots set to x, y, and z, and its is2D
internal slot set to false
.
The
x
,
y
, and
z
attributes must, on setting to a new value
val,
rectify a numberish valuefrom
valand set the corresponding internal slot to the result of that.
The
CSSScale(x, y, z)
constructor must, when invoked, perform the following steps:
Let x, y, and z (if passed) be replaced by the result of rectifying a numberish value.
If x, y, or z (if passed) don’t match <number>, throw a TypeError
.
Let this be a new CSSScale
object, with its x
and y
internal slots set to x and y.
If z was passed, set this’s z
internal slot to z, and set this’s is2D
internal slot to false
.
If z was not passed, set this’s z
internal slot to a new unit value of (1, "number")
, and set this’s is2D
internal slot to true
.
Return this.
The
x
,
y
, and
z
attributes must, on setting to a new value
val,
rectify a numberish valuefrom
valand set the corresponding internal slot to the result of that.
The
CSSSkew(ax, ay)
constructor must, when invoked, perform the following steps:
Return a new CSSSkew
object with its ax
and ay
internal slots set to ax and ay, and its is2D
internal slot set to true
.
The
CSSSkewX(ax)
constructor must, when invoked, perform the following steps:
Return a new CSSSkewX
object with its ax
internal slot set to ax, and its is2D
internal slot set to true
.
The
CSSSkewY(ay)
constructor must, when invoked, perform the following steps:
Return a new CSSSkewY
object with its ay
internal slot set to ay, and its is2D
internal slot set to true
.
The
is2D
attribute of a
CSSPerspective
object must, on setting, do nothing.
Note: perspective() functions always represent 3D transforms.
The
CSSMatrixComponent(matrix, options)
constructor must, when invoked, perform the following steps:
Let this be a new CSSMatrixComponent
object with its matrix
internal slot set to matrix.
If options was passed and has a is2D
field, set this’s is2D
internal slot to the value of that field.
Otherwise, set this’s is2D
internal slot to the value of matrix’s is2D
internal slot.
Return this.
Each
CSSTransformComponent
can correspond to one of a number of underlying transform functions. For example, a
CSSTranslate
with an x value of
10pxand y & z values of
0pxcould represent any of the following:
translate(10px)
translate(10px, 0)
translateX(10px)
translate3d(10px, 0, 0)
When stringified, however, it will always print out either translate(10px, 0px) or translate3d(10px, 0px, 0px), depending on whether its is2D
internal slot is true
or false
, respectively.
CSSImageValue
objects
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
interface CSSImageValue
: CSSStyleValue {
};
CSSImageValue
objects represent values for properties that take <image> productions, for example background-image, list-style-image, and border-image-source.
Note: This object is intentionally opaque, and exposes no details of what kind of image it contains, or any aspect of the image. This is because having something to represent images is necessary for Custom Paint, but there are sufficient complexities in getting URL-handling and loading specified firmly that it’s not realistically possible to specify in the timeline of this specification. This will be expanded on in future levels.
If a CSSImageValue
object represents an <image> that involves a URL (such as url() or image()), the handling of such values is identical to how CSS currently handles them. In particular, resolving relative URLs or fragment URLs has the same behavior as in normal CSS.
For example, relative URLs are resolved against the URL of the stylesheet they’re within (or the document’s URL, if they’re specified in a
style
element or
style
attribute). This resolution doesn’t happen eagerly at parse-time, but at some currently-unspecified point during value computation.
Thus, if an element’s style is set to background-image: url(foo);, and that specified value is extracted via the Typed OM and then set on an element in a different document, both the source and destination elements will resolve the URL differently, as they provide different base URLs.
On the other hand, if the extracted value was a computed value (from computedStyleMap()
), then it would already be resolved to an absolute URL, and thus would act identically no matter where you later set it to. (Unless it was a fragment URL, which CSS treats differently and never fully resolves, so it always resolves against the current document.)
CSSColorValue
objects
CSSColorValue
objects represent <color> values. It is an abstract superclass, with the subclasses representing individual CSS color functions.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSColorValue
: CSSStyleValue { [Exposed=Window] static (CSSColorValue or CSSStyleValue) parse(USVStringcssText
); };
The
parse(cssText)
method, when called, must perform the following steps:
Parse cssText as a <color> and let result be the result. If result is a syntax error, throw a SyntaxError
and abort this algorithm.
Reify a color value from result, and return the result.
Several IDL types are defined to be used in CSSColorValue
s:
typedef (CSSNumberish or CSSKeywordish)CSSColorRGBComp
; typedef (CSSNumberish or CSSKeywordish)CSSColorPercent
; typedef (CSSNumberish or CSSKeywordish)CSSColorNumber
; typedef (CSSNumberish or CSSKeywordish)CSSColorAngle
;
All of these types are the same in terms of type signature, but they represent distinct values: CSSColorRGBComp
represents a value that is, canonically, either a <number>, <percentage>, or the keyword none; CSSColorPercent
represents a value that is, canonically, either a <percentage> or the keyword none; CSSColorNumber
represents a value that is, canonically, either a <number> or the keyword none; CSSColorAngle
represents a value that is, canonically, either an <angle> or the keyword none.
Their corresponding rectification algorithms also all have distinct behaviors for translating a double
value into a CSSNumericValue
.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSRGB
: CSSColorValue {constructor
(CSSColorRGBCompr
, CSSColorRGBCompg
, CSSColorRGBCompb
, optional CSSColorPercentalpha
= 1); attribute CSSColorRGBComp r; attribute CSSColorRGBComp g; attribute CSSColorRGBComp b; attribute CSSColorPercent alpha; };
The CSSRGB
class represents the CSS rgb()/rgba() functions.
The
CSSRGB(r, g, b, optional alpha)
constructor must, when invoked, perform the following steps:
Let r, g, b be replaced by the result of rectifying a CSSColorRGBComp from each of them. Let alpha be replaced by the result of rectifying a CSSColorPercent from it.
Return a new CSSRGB
with its r
, g
, b
, and alpha
internal slots set to r, g, b, and alpha.
The
r
,
g
, and
b
attributes of a
CSSRGB
value must, on setting to a new value
val,
rectify a CSSColorRGBCompfrom
valand set the corresponding internal slot to the result of that.
The
alpha
attribute of a
CSSRGB
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSHSL
: CSSColorValue {constructor
(CSSColorAngleh
, CSSColorPercents
, CSSColorPercentl
, optional CSSColorPercentalpha
= 1); attribute CSSColorAngle h; attribute CSSColorPercent s; attribute CSSColorPercent l; attribute CSSColorPercent alpha; };
The CSSHSL
class represents the CSS hsl()/hsla() functions.
The
CSSHSL(h, s, l, optional alpha)
constructor must, when invoked, perform the following steps:
Let h be replaced by the result of rectifying a CSSColorAngle from it. Let s, l, and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSHSL
with its h
, s
, l
, and alpha
internal slots set to h, s, l, and alpha.
The
h
attribute of a
CSSHSL
value must, on setting to a new value
val,
rectify a CSSColorAnglefrom
valand set the corresponding internal slot to the result of that.
The
s
,
l
, and
alpha
attributes of a
CSSHSL
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSHWB
: CSSColorValue {constructor
(CSSNumericValueh
, CSSNumberishw
, CSSNumberishb
, optional CSSNumberishalpha
= 1); attribute CSSNumericValue h; attribute CSSNumberish w; attribute CSSNumberish b; attribute CSSNumberish alpha; };
The CSSHWB
class represents the CSS hwb() function.
The
CSSHWB(h, w, b, optional alpha)
constructor must, when invoked, perform the following steps:
Let h be replaced by the result of rectifying a CSSColorAngle from it. Let w, b, and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSHWB
with its h
, w
, b
, and alpha
internal slots set to h, w, b, and alpha.
The
h
attribute of a
CSSHWB
value must, on setting to a new value
val,
rectify a CSSColorAnglefrom
valand set the corresponding internal slot to the result of that.
The
w
,
b
, and
alpha
attributes of a
CSSHWB
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSLab
: CSSColorValue {constructor
(CSSColorPercentl
, CSSColorNumbera
, CSSColorNumberb
, optional CSSColorPercentalpha
= 1); attribute CSSColorPercent l; attribute CSSColorNumber a; attribute CSSColorNumber b; attribute CSSColorPercent alpha; };
The CSSLab
class represents the CSS lab() function.
The
CSSLab(l, a, b, optional alpha)
constructor must, when invoked, perform the following steps:
Let a and b be replaced by the result of rectifying a CSSColorNumber from each of them. Let l and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSLab
with its l
, a
, b
, and alpha
internal slots set to l, a, b, and alpha.
The
l
and
alpha
attributes of a
CSSLab
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
The
a
, and
b
attributes of a
CSSLab
value must, on setting to a new value
val,
rectify a CSSColorNumberfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSLCH
: CSSColorValue {constructor
(CSSColorPercentl
, CSSColorPercentc
, CSSColorAngleh
, optional CSSColorPercentalpha
= 1); attribute CSSColorPercent l; attribute CSSColorPercent c; attribute CSSColorAngle h; attribute CSSColorPercent alpha; };
The CSSLCH
class represents the CSS lch() function.
The
CSSLCH(l, c, h, optional alpha)
constructor must, when invoked, perform the following steps:
Let h be replaced by the result of rectifying a CSSColorAngle from it. Let l, c, and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSLCH
with its l
, c
, h
, and alpha
internal slots set to l, c, h, and alpha.
The
h
attribute of a
CSSLCH
value must, on setting to a new value
val,
rectify a CSSColorAnglefrom
valand set the corresponding internal slot to the result of that.
The
l
,
c
, and
alpha
attributes of a
CSSLCH
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSOKLab
: CSSColorValue {constructor
(CSSColorPercentl
, CSSColorNumbera
, CSSColorNumberb
, optional CSSColorPercentalpha
= 1); attribute CSSColorPercent l; attribute CSSColorNumber a; attribute CSSColorNumber b; attribute CSSColorPercent alpha; };
The CSSOKLab
class represents the CSS oklab() function.
The
CSSOKLab(l, a, b, optional alpha)
constructor must, when invoked, perform the following steps:
Let a and b be replaced by the result of rectifying a CSSColorNumber from each of them. Let l and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSOKLab
with its l
, a
, b
, and alpha
internal slots set to l, a, b, and alpha.
The
l
and
alpha
attributes of a
CSSOKLab
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
The
a
, and
b
attributes of a
CSSOKLab
value must, on setting to a new value
val,
rectify a CSSColorNumberfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSOKLCH
: CSSColorValue {constructor
(CSSColorPercentl
, CSSColorPercentc
, CSSColorAngleh
, optional CSSColorPercentalpha
= 1); attribute CSSColorPercent l; attribute CSSColorPercent c; attribute CSSColorAngle h; attribute CSSColorPercent alpha; };
The CSSOKLCH
class represents the CSS lch() function.
The
CSSOKLCH(l, c, h, optional alpha)
constructor must, when invoked, perform the following steps:
Let h be replaced by the result of rectifying a CSSColorAngle from it. Let l, c, and alpha be replaced by the result of rectifying a CSSColorPercent from each of them.
Return a new CSSOKLCH
with its l
, c
, h
, and alpha
internal slots set to l, c, h, and alpha.
The
h
attribute of a
CSSOKLCH
value must, on setting to a new value
val,
rectify a CSSColorAnglefrom
valand set the corresponding internal slot to the result of that.
The
l
,
c
, and
alpha
attributes of a
CSSOKLCH
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] interfaceCSSColor
: CSSColorValue {constructor
(CSSKeywordishcolorSpace
, sequence<CSSColorPercent>channels
, optional CSSNumberishalpha
= 1); attribute CSSKeywordish colorSpace; attribute ObservableArray<CSSColorPercent>channels
; attribute CSSNumberish alpha; };
The CSSColor
class represents the CSS color() function.
The
colorSpace
attribute of a
CSSColor
value must, on setting to a new value
val,
rectify a keywordish valuefrom
valand set the corresponding internal slot to the result of that.
The
alpha
attribute of a
CSSColor
value must, on setting to a new value
val,
rectify a CSSColorPercentfrom
valand set the corresponding internal slot to the result of that.
5.CSSStyleValue
Reification
This section describes how Typed OM objects are constructed from internal representations, a process called reification.
Some general principles apply to all reification, and so aren’t stated in each individual instance:
If an internal representation is from a list-valued property, this list defines how to reify a single iteration of the property; multiple iterations are reflected by returning multiple values from StylePropertyMap
.getAll()
.
If an internal representation contains a var() reference, then it is reified by reifying a list of component values, regardless of what property it is for.
The following list defines the reification behavior for every single property in CSS, for both specified and computed values.
For both specified and computed values, reify a list of component values from the value, and return the result.
Reified as described by CSS Properties and Values API 1 § 6.2 CSSStyleValue Reification.
For both specified and computed values:
If the value is normal or stretch, reify an identifier from the value and return the result.
If the value is baseline or first baseline,, reify an identifier "baseline" and return the result.
If the value is a <self-position> with no <overflow-position>, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is auto, normal, or stretch, reify an identifier from the value and return the result.
If the value is baseline or first baseline,, reify an identifier "baseline" and return the result.
If the value is a <self-position> with no <overflow-position>, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
If the value is an <angle>, reify a numeric value from the value and return the result.
If the value is a single keyword, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
Reify a numeric value from the angle and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
If the value is a url() function, reify a url from the value and return the result.
Otherwise, reify an image from the value and return the result.
For both specified and computed values, reify a position from the value and return the result.
For both specified and computed values:
If the value is a single keyword, or the same keyword repeated twice, reify an identifier from the keyword and return the result.
If the value is repeat no-repeat, reify an identifier "repeat-x" and return the result.
If the value is no-repeat repeat, reify an identifier "repeat-y" and return the result.
Otherwise, reify to a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is sub or super, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
Same as for width
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as border-block-start
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as border-block-start
Same as border-top-color
Same as border-top-style
Same as border-top-width
Same as border-top
Same as border-top-color
Same as border-top-style
Same as border-top-width
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as border-top
Same as border-top-color
Same as border-top-style
Same as border-top-width
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as border-top
Same as border-top-color
Same as border-top-style
Same as border-top-width
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as border-top
Same as border-top-color
Same as border-top-style
Same as border-top-width
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is currentcolor, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is a <length>, reify a numeric value from the value and return the result.
Otherwise, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is currentcolor, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is currentcolor, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is normal, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is normal, light or dark, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is an <absolute-size> or <relative-size>, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is a <percentage>, reify a numeric value from the value and return the result.
Otherwise, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is none, weight, style or small-caps, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is none or historical-forms, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is normal, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values:
If the value is a <number>, reify a numeric value from the value and return the result.
Otherwise, reify an identifier from the value
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
If the value is a <length> or <percentage>, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is normal, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
If the value is a url() function, reify a url from the value and return the result.
Otherwise, reify an image from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as margin-top
Same as margin-top
Same as margin-top
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is none, reify an identifier from the value and return the result.
Otherwise, reify an image from the value and return the result.
For both specified and computed values, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is currentcolor, reify an identifier from the value and return the result.
Otherwise, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify as a CSSStyleValue
and return the result.
Same as padding-top
Same as padding-top
Same as padding-top
For both specified and computed values, reify a numeric value from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values:
If the value is baseline, reify an identifier from the value and return the result.
Otherwise, reify a numeric value from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values, reify an identifier from the value and return the result.
For both specified and computed values:
If the value is auto, reify an identifier from the value and return the result.
If the value is a <length> or <percentage>, reify a numeric value from the value and return the result.
Not all internal representations are simple enough to be reified with the current set of CSSStyleValue
subclasses. When this is the case, the property is reified as a CSSStyleValue for a particular property, ensuring that it can be used as a value for that property, and nothing else.
Regardless of what the property’s grammar is otherwise, a property value with an un-substituted var() reference is represented as a list of component values, which becomes a CSSUnparsedValue
in the Typed OM.
var() references become CSSVariableReferenceValue
s in the Typed OM.
CSS identifiers become CSSKeywordValue
s in the Typed OM.
CSS <number>, <percentage>, and <dimension> values become CSSNumericValue
s in the Typed OM.
To
reify a numeric value num:
If num is a math function, reify a math expression from num and return the result.
If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue
with its value
internal slot set to 0, and its unit
internal slot set to "px".
Return a new CSSUnitValue
with its value
internal slot set to the numeric value of num, and its unit
internal slot set to "number" if num is a <number>, "percent" if num is a <percentage>, and num’s unit if num is a <dimension>.
If the value being reified is a computed value, the unit used must be the appropriate canonical unit for the value’s type, with the numeric value scaled accordingly.
For example, if an element has
style = "width: 1in;"
,
el . attributeStyleMap . get ( 'width' )
will return
CSS . in ( 1 )
, but
el . computedStyleMap . get ( 'width' )
will return
CSS . px ( 96 )
, as
pxis the
canonical unitfor absolute lengths.
To
reify a math expression num:
If num is a min() or max() expression:
Let values be the result of reifying the arguments to the expression, treating each argument as if it were the contents of a calc() expression.
Return a new CSSMathMin
or CSSMathMax
object, respectively, with its values
internal slot set to values.
Assert: Otherwise, num is a calc().
Turn num’s argument into an expression tree using standard PEMDAS precedence rules, with the following exceptions/clarification:
Treat subtraction as instead being addition, with the RHS argument instead wrapped in a special "negate" node.
Treat division as instead being multiplication, with the RHS argument instead wrapped in a special "invert" node.
Addition and multiplication are N-ary; each node can have any number of arguments.
If an expression has only a single value in it, and no operation, treat it as an addition node with the single argument.
Recursively transform the expression tree into objects, as follows:
becomes a new CSSMathSum
object, with its values
internal slot set to its list of arguments
becomes a new CSSMathProduct
object, with its values
internal slot set to its list of arguments
becomes a new CSSMathNegate
object, with its value
internal slot set to its argument
becomes a new CSSMathInvert
object, with its value
internal slot set to its argument
reified as appropriate
For example,
calc(1px - 2 * 3em)produces the structure:
CSSMathSum( CSS.px(1), CSSMathNegate( CSSMathProduct( 2, CSS.em(3) ) ) )
Note that addition and multiplication are N-ary, so
calc(1px + 2px + 3px)produces the structure:
CSSMathSum( CSS.px(1), CSS.px(2), CSS.px(3) )
but calc(calc(1px + 2px) + 3px) produces the structure:
CSSMathSum( CSSMathSum( CSS.px(1), CSS.px(2) ), CSS.px(3) )
Note: The value computation process may transform different units into identical ones, simplifying the resulting expression. For example, calc(1px + 2em) as a specified value results in a CSSMathSum(CSS.px(1), CSS.em(2))
, but as a computed value will give CSS.px(33)
or similar (depending on the value of an em in that context).
CSS <color> values become either CSSColorValue
s (if they can be resolved to an absolute color) or generic CSSStyleValue
s (otherwise).
To
reify a color value val:
If val is a <hex-color>, an rgb() function, or an rgba() function, then return a new CSSRGB
object with its r
, g
, b
, and alpha
internal slots set to the reification of its red, green, blue, and alpha components, respectively.
If val is an hsl() or hsla() function, then return a new CSSHSL
object with its h
, s
, l
, and alpha
internal slots set to the reification of its hue angle, saturation, lightness, and alpha components, respectively.
If val is an hwb() function, then return a new CSSHWB
object with its h
, w
, b
, and alpha
internal slots set to the reification of its hue angle, whiteness, blackness, and alpha components, respectively.
If val is an lch() function, then return a new CSSLCH
object with its l
, c
, h
, and alpha
internal slots set to the reification of its lightness, chroma, hue angle, and alpha components, respectively.
If val is an lab() function, then return a new CSSLab
object with its l
, a
, b
, and alpha
internal slots set to the reification of its lightness, a, b, and alpha components, respectively.
If val is a color() function, then return a new CSSColor
object with its colorSpace
internal slot set to the result of reifying an identifier from val’s color space, its channels
internal slot’s backing list set to the result of reifying val’s list of non-alpha components, and alpha
internal slot set to the result of reifying val’s alpha component.
If val is a <named-color> or the keyword transparent, then return a new CSSRGB
object with its r
, g
, b
, and alpha
internal slots set to the reification of its red, green, blue, and alpha components, respectively.
If val is any other color keyword, return the result of reifying an identifier from val.
CSS <transform-list> values become CSSTransformValue
s in the Typed OM, while CSS <transform-function> values become CSSTransformComponent
s.
To
reify a <transform-function> func, perform the appropriate set of steps below, based on
func:
Return a new CSSMatrixComponent
object, whose matrix
internal slot is set to a 4x4 matrix representing the same information as func, and whose is2D
internal slot is true
if func is matrix(), and false
otherwise.
Return a new CSSTranslate
object, whose x
, y
, and z
internal slots are set to the reification of the specified x/y/z offsets, or the reification of 0px if not specified in func, and whose is2D
internal slot is true
if func is translate(), translateX(), or translateY(), and false
otherwise.
Return a new CSSRotate
object, whose angle
internal slot is set to the reification of the specified angle, and whose x
, y
, and z
internal slots are set to the specified rotation axis coordinates, or the implicit axis coordinates if not specified in func and whose is2D
internal slot is true
if func is rotate(), and false
otherwise.
Return a new CSSSkew
object, whose ax
and ay
internal slots are set to the reification of the specified x and y angles, or the reification of 0deg if not specified in func, and whose is2D
internal slot is true
.
Return a new CSSSkewX
object, whose ax
internal slot is set to the reification of the specified x angle, or the reification of 0deg if not specified in func, and whose is2D
internal slot is true
.
Return a new CSSSkewY
object, whose ay
internal slot is set to the reification of the specified y angle, or the reification of 0deg if not specified in func, and whose is2D
internal slot is true
.
Return a new CSSPerspective
object, whose length
internal slot is set to the reification of the specified length (see reify a numeric value if it is a length, and reify an identifier if it is the keyword none) and whose is2D
internal slot is false
.
CSSStyleValue
Serialization
The way that a CSSStyleValue
serializes is dependent on how the value was constructed.
the serialization is the USVString from which the value was constructed.
the serialization is specified in the sections below.
the serialization is specified in § 6.7 Serialization from CSSOM Values below.
For example:
var length1 = CSSNumericValue.parse("42.0px"); length1.toString(); // "42.0px" var length2 = CSS.px(42.0); length2.toString(); // "42px"; element.style.width = "42.0px"; var length3 = element.attributeStyleMap.get('width'); length3.toString(); // "42px";6.1.
CSSUnparsedValue
Serialization
To
serialize aCSSVariableReferenceValue
this
:
Let s initally be "var(".
Append this’s variable
internal slot to s.
If this’s fallback
internal slot is not null
, append ", " to s, then serialize the fallback
internal slot and append it to s.
Append ")" to s and return s.
CSSKeywordValue
Serialization 6.3. CSSNumericValue
Serialization 6.4. CSSUnitValue
Serialization
To
serialize aCSSUnitValue
this
, with optional arguments
minimum, a numeric value, and
maximum, a numeric value:
Set s to the result of serializing a <number> from value, per CSSOM § 6.7.2 Serializing CSS Values.
If unit is:
Do nothing.
Append "%" to s.
Append unit to s.
If minimum was passed and this is less than minimum, or if maximum was passed and this is greater than maximum, or either minimum and/or maximum were passed and the relative size of this and minimum/maximum can’t be determined with the available information at this time, prepend "calc(" to s, then append ")" to s.
Return s.
CSSMathValue
Serialization
To
serialize aCSSMathValue
this
, with optional arguments
nested, a boolean (defaulting to false if unspecified),
paren-less, a boolean (defaulting to false if unspecified), perform the following steps.
Let s initially be the empty string.
If this is a CSSMathMin
or CSSMathMax
:
Otherwise, if this is a CSSMathSum
:
If paren-less is true, continue to the next step; otherwise, if nested is true, append "(" to s; otherwise, append "calc(" to s.
Serialize the first item in this’s values
internal slot with nested set to true, and append the result to s.
For each arg in this’s values
internal slot beyond the first:
If arg is a CSSMathNegate
, append " - " to s, then serialize arg’s value
internal slot with nested set to true, and append the result to s.
Otherwise, append " + " to s, then serialize arg with nested set to true, and append the result to s.
If paren-less is false, append ")" to s,
Return s.
Otherwise, if this is a CSSMathNegate
:
If paren-less is true, continue to the next step; otherwise, if nested is true, append "(" to s; otherwise, append "calc(" to s.
Append "-" to s.
Serialize this’s value
internal slot with nested set to true, and append the result to s.
If paren-less is false, append ")" to s,
Return s.
Otherwise, if this is a CSSMathProduct
:
If paren-less is true, continue to the next step; otherwise, if nested is true, append "(" to s; otherwise, append "calc(" to s.
Serialize the first item in this’s values
internal slot with nested set to true, and append the result to s.
For each arg in this’s values
internal slot beyond the first:
If arg is a CSSMathInvert
, append " / " to s, then serialize arg’s value
internal slot with nested set to true, and append the result to s.
Otherwise, append " * " to s, then serialize arg with nested set to true, and append the result to s.
If paren-less is false, append ")" to s,
Return s.
Otherwise, if this is a CSSMathInvert
:
If paren-less is true, continue to the next step; otherwise, if nested is true, append "(" to s; otherwise, append "calc(" to s.
Append "1 / " to s.
Serialize this’s value
internal slot with nested set to true, and append the result to s.
If paren-less is false, append ")" to s,
Return s.
CSSTransformValue
and CSSTransformComponent
Serialization
To
serialize aCSSTranslate
this
:
To
serialize aCSSRotate
this
:
Let s initially be the empty string.
If this’s is2D
internal slot is false
:
Append "rotate3d(" to s.
Serialize this’s x
internal slot, and append it to s.
Append ", " to s.
Serialize this’s y
internal slot, and append it to s.
Append ", " to s.
Serialize this’s z
internal slot, and append it to s.
Append "," to s.
Serialize this’s angle
internal slot, and append it to s.
Append ")" to s, and return s.
Otherwise:
Append "rotate(" to s.
Serialize this’s angle
internal slot, and append it to s.
Append ")" to s, and return s.
To
serialize aCSSScale
this
:
Let s initially be the empty string.
If this’s is2D
internal slot is false
:
Otherwise:
Append "scale(" to s.
Serialize this’s x
internal slot, and append it to s.
If this’s x
and y
internal slots are equal numeric values, append ")" to s and return s.
Otherwise, append ", " to s.
Serialize this’s y
internal slot, and append it to s.
Append ")" to s, and return s.
To
serialize aCSSSkew
this
:
Let s initially be "skew(".
Serialize this’s ax
internal slot, and append it to s.
If this’s ay
internal slot is a CSSUnitValue
with a value
of 0
, then append ")" to s and return s.
Otherwise, append ", " to s.
Serialize this’s ay
internal slot, and append it to s.
Append ")" to s, and return s.
To
serialize aCSSSkewX
this
:
Let s initially be "skewX(".
Serialize this’s ax
internal slot, and append it to s.
Append ")" to s, and return s.
To
serialize aCSSSkewY
this
:
Let s initially be "skewY(".
Serialize this’s ay
internal slot, and append it to s.
Append ")" to s, and return s.
To
serialize aCSSPerspective
this
:
Let s initially be "perspective(".
Serialize this’s length
internal slot, with a minimum of 0px, and append it to s.
Append ")" to s, and return s.
CSSStyleValue
objects produced by the user agent from values in the CSSOM, rather than directly constructed by the author, are serialized according to the following rules, depending on the property they came from:
If the value is the currentcolor keyword, return "currentcolor".
Otherwise, return the result of serializing the <color> value.
If the value is the currentcolor keyword, return "currentcolor".
Otherwise, return the result of serializing the <color> value.
Let values initially be the empty list.
If border-image-source is not none, serialize border-image-source and append it to values.
If border-image-slice does not specify 100% for all sides and omits the fill keyword, serialize border-image-slice and append it to values.
If border-image-width does not specify 1 for all sides, append "/ " (U+002F FORWARD SLASH followed by U+0020 SPACE) to the result of serializing border-image-width and append it to values.
If border-image-outset does not specify 0 for all sides:
If the previous border-image-width step did not append anything to values, let prefix be "// " (two U+002F FORWARD SLASH characters followed by U+0020 SPACE); otherwise let prefix be "/ " (U+002F FORWARD SLASH followed by U+0020 SPACE)
Append prefix to the result of serializing border-image-outset and append it to values.
If border-image-repeat is not stretch in both axises, serialize border-image-repeat and append it to values.
If values is empty, append "none" to values.
Return the result of concatenating all the items in values, separated by " " (U+0020 SPACE).
If the value is the auto keyword, return "auto".
If the value is of type <length>, return the result of serializing the <length> value.
Otherwise, return the result of serializing the <percentage> value.
If the value is the currentcolor keyword, return "currentcolor".
Otherwise, return the result of serializing the <color> value.
If the value is the auto keyword, return "auto".
If the value is of type <length>, return the result of serializing the <length> value.
Otherwise, return the result of serializing the <percentage> value.
If the value is of type <number>, return the result of serializing the <number> value.
Otherwise, return the result of serializing the <percentage> value.
If the value is the auto keyword, return "auto".
If the value is of type <length>, return the result of serializing the <length> value.
Otherwise, return the result of serializing the <percentage> value.
If the value is the auto keyword, return "auto".
If the value is of type <length>, return the result of serializing the <length> value.
Otherwise, return the result of serializing the <percentage> value.
There are no known security issues introduced by these features.
8. Privacy ConsiderationsThere are no known privacy issues introduced by these features.
9. Changes 9.1. Changes since the 10 April 2018 Working DraftFixed the type match algorithm to refer to the percent hint more abstractly.
Clarified that "invert a type" needs to preserve the percent hint.
Added missing font units to CSS numeric factory. (#1107)
Specified that the list of unit shorthand methods must be reduced or expanded to match the implementation’s support.
Used undefined union value for "StylePropertyMapReadOnly.get()". (#1087)
Removed .to() and the CSSColorValue.colorSpace, as conversion isn’t really in Typed OM’s remit. (#1070)
Added min/max to "serialize a CSSUnitValue", and pass it when serializing the argument of CSSPerspective. (#1069)
Changed reifying from "a CSSStyleValue" to "an identifier". (#1068)
Added factory functions for new viewport/container units. (#1067)
Added type checking to CSSNumericValue.parse. (#1065)
Removed CSSDeviceCMYK, add CSSOKLab and CSSOKLCH, made all the color classes accept the "none" keyword.
Defined how to reify a color value.
Allowed "new unit value" to link to "create a CSSUnitValue from a pair" since that phrasing is used everywhere already.
Added support for perspective(none) to CSSPerspective. (#1053)
Fixed accidental clash of CSSClampValue.min/max with CSSNumericValue.min/max. (#855)
Simplified the Abstract
Removed CSSGray and associated spec text, since Color 4 dropped gray() some time ago. (#1027)
Moved .colorSpace up to the CSSColorValue superclass. Swapped the .to*() color-conversion functions for a generic .to(colorSpace) method. (#1036)
Added device-cmyk() support.
Fix the OM for CSSColor to match recent simplifications.
Specified which color function each CSSColorValue subclass represents, and added CSSGray.
Added missing parentheses for union. (#1016)
Added some explanatory text about the makeup of a "type".
Fixed algorithm nesting.
Added default dictionary value, required by update to WebIDL. (#936)
Switched term from "underlying value" to :internal representation", as Web Animations already uses "underlying value" for something different.
Clarified that reifying as a CSSSTyleValue requires a property.
Defined reification behavior for registered custom properties (#886)
Used partial interface mixin ElementCSSInlineStyle (#853)
Used the correct name from WebIDL for indexed property getter.
Exported a number of terms for use in other specifications
Droped CSSPositionValue from this level.
Added CSSMathClamp for the "clamp()"" function.
Made the "match a grammar" algorithm a little more precise.
Reifying computed numeric values uses the canonical unit. (#725)
Added note about new unit types. (#734)
Used correct unit "percent", not "percentage" (#761).
Added note about custom property parsing
Moved Naina Raisinghani to Former Editor
Added an 'invert a type' operation.
Exported several numeric-type terms, so CSS Values & Units can refer to them.
Moved Shane Stephens to Former Editor
Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example"
, like this:
Informative notes begin with the word “Note” and are set apart from the normative text with class="note"
, like this:
Note, this is an informative note.
Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">
, like this: UAs MUST provide an accessible alternative.
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4