ladybird/Libraries/LibWeb/CSS/CSSNumericValue.idl
Sam Atkins 277117eed5 LibWeb/CSS: Implement CSSNumericValue.parse()
Reifying the result gets quite ad-hoc. Firstly because "parse a
component value" produces a ComponentValue, not a full StyleValue like
we need for math functions. And second, because not all math functions
can be reified as a CSSNumericValue:

Besides the fact that I haven't implemented CalculatedStyleValue
reification at all yet, there are a lot of math functions with no
corresponding CSSMathValue in the spec yet. If the calculation tree
contains any of those, the best we can do is reify as a CSSStyleValue,
and that isn't a valid return value from CSSNumericValue.parse(). So, I
made us throw a SyntaxError in those cases. This seems to match
Chrome's behaviour. Spec issue:
https://github.com/w3c/css-houdini-drafts/issues/1090
2025-08-29 11:57:10 +02:00

47 lines
1.5 KiB
Text

#import <CSS/CSSStyleValue.idl>
// https://drafts.css-houdini.org/css-typed-om-1/#enumdef-cssnumericbasetype
enum CSSNumericBaseType {
"length",
"angle",
"time",
"frequency",
"resolution",
"flex",
"percent",
};
// https://drafts.css-houdini.org/css-typed-om-1/#dictdef-cssnumerictype
// AD-HOC: We give these default values and mark percentHint as nullable. https://github.com/w3c/css-houdini-drafts/issues/1149
dictionary CSSNumericType {
long length = 0;
long angle = 0;
long time = 0;
long frequency = 0;
long resolution = 0;
long flex = 0;
long percent = 0;
CSSNumericBaseType? percentHint;
};
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
interface CSSNumericValue : CSSStyleValue {
[FIXME] CSSNumericValue add(CSSNumberish... values);
[FIXME] CSSNumericValue sub(CSSNumberish... values);
[FIXME] CSSNumericValue mul(CSSNumberish... values);
[FIXME] CSSNumericValue div(CSSNumberish... values);
[FIXME] CSSNumericValue min(CSSNumberish... values);
[FIXME] CSSNumericValue max(CSSNumberish... values);
[FIXME] boolean equals(CSSNumberish... value);
// FIXME: CSSUnitValue to(USVString unit);
// FIXME: CSSMathSum toSum(USVString... units);
[ImplementedAs=type_for_bindings] CSSNumericType type();
[Exposed=Window] static CSSNumericValue parse(USVString cssText);
};
// https://drafts.css-houdini.org/css-typed-om-1/#typedefdef-cssnumberish
typedef (double or CSSNumericValue) CSSNumberish;