Skip to content

Commit 6ff9dfb

Browse files
committed
Add and use the CSSNumberish typedef.
1 parent f061863 commit 6ff9dfb

File tree

1 file changed

+80
-41
lines changed

1 file changed

+80
-41
lines changed

css-typed-om/Overview.bs

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,31 @@ Instead, clamping and/or rounding will occur during computation of style.
553553
and the value of `zIndex` is `15` ('z-index' is rounded to an integer value).
554554
</div>
555555

556-
Note that "numeric values" which incorporate variable references
556+
Note: "Numeric values" which incorporate variable references
557557
will instead be represented as {{CSSUnparsedValue}} objects,
558558
and keywords as {{CSSKeywordValue}} objects.
559559

560+
Any place that accepts a {{CSSNumericValue}}
561+
also accepts a raw {{double}},
562+
by using the following typedef and algorithm:
563+
564+
<pre class=idl>
565+
typedef (double or CSSNumericValue) CSSNumberish;
566+
</pre>
567+
568+
<div algorithm>
569+
To <dfn export lt="rectify a numberish value | rectifying a numberish value">rectify a numberish value</dfn> |num|,
570+
perform the following steps:
571+
572+
1. If |num| is a {{CSSNumericValue}},
573+
return |num|.
574+
575+
2. If |num| is a {{double}},
576+
return a new {{CSSUnitValue}}
577+
with its {{CSSUnitValue/value}} internal slot set to |num|
578+
and its {{CSSUnitValue/unit}} internal slot set to "number".
579+
</div>
580+
560581

561582
### Common Numeric Operations, and the {{CSSNumericValue}} Superclass ### {#numeric-value}
562583

@@ -566,12 +587,12 @@ are represented by subclasses of the {{CSSNumericValue}} interface.
566587

567588
<xmp class=idl>
568589
interface CSSNumericValue : CSSStyleValue {
569-
CSSNumericValue add(CSSNumericValue... values);
570-
CSSNumericValue sub(CSSNumericValue... values);
571-
CSSNumericValue mul(CSSNumericValue... values);
572-
CSSNumericValue div(CSSNumericValue... values);
590+
CSSNumericValue add(CSSNumberish... values);
591+
CSSNumericValue sub(CSSNumberish... values);
592+
CSSNumericValue mul(CSSNumberish... values);
593+
CSSNumericValue div(CSSNumberish... values);
573594

574-
boolean equals(CSSNumericValue... value);
595+
boolean equals(CSSNumberish... value);
575596

576597
CSSNumericValue to(DOMString unit);
577598

@@ -589,26 +610,29 @@ The following are the arithmetic operations you can perform on dimensions:
589610
when called on a {{CSSNumericValue}} |this|,
590611
must perform the following steps:
591612

592-
1. Prepend |this| to |values|.
613+
1. Replace each [=list/item=] of |values|
614+
with the result of [=rectifying a numberish value=] for the [=list/item=].
593615

594-
2. If there are at least two different [=strong types=]
616+
2. Prepend |this| to |values|.
617+
618+
3. If there are at least two different [=strong types=]
595619
among the [=list/items=] in |values|,
596620
[=throw=] a {{TypeError}}.
597621

598-
3. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s
622+
4. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s
599623
and have the same {{CSSUnitValue/unit}},
600624
return a new {{CSSUnitValue}}
601625
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
602626
and {{CSSUnitValue/value}} internal slot is set to the sum of
603627
the {{CSSUnitValue/value}} internal slots
604628
of the [=list/items=] in |values|.
605629

606-
4. If |this| is a {{CSSMathSum}} object,
630+
5. If |this| is a {{CSSMathSum}} object,
607631
remove |this| from |values|,
608632
and then [=list/append=] the remaining |values|
609633
to |this|’s {{CSSMathSum/values}} internal slot.
610634

611-
5. Otherwise,
635+
6. Otherwise,
612636
return a new {{CSSMathSum}} object
613637
whose {{CSSMathSum/values}} internal slot
614638
is set to |values|.
@@ -619,13 +643,16 @@ The following are the arithmetic operations you can perform on dimensions:
619643
when called on a {{CSSNumericValue}} |this|,
620644
must perform the following steps:
621645

622-
1. Let |thisAndValues| be |this| prepended to |values|.
646+
1. Replace each [=list/item=] of |values|
647+
with the result of [=rectifying a numberish value=] for the [=list/item=].
648+
649+
2. Let |thisAndValues| be |this| prepended to |values|.
623650

624-
1. If there are at least two different [=strong types=]
651+
3. If there are at least two different [=strong types=]
625652
among the [=list/items=] in |thisAndValues|,
626653
[=throw=] a {{TypeError}}.
627654

628-
2. If all of the [=list/items=] in |thisAndValues| are {{CSSUnitValue}}s
655+
4. If all of the [=list/items=] in |thisAndValues| are {{CSSUnitValue}}s
629656
and have the same {{CSSUnitValue/unit}},
630657
return a new {{CSSUnitValue}}
631658
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
@@ -634,13 +661,13 @@ The following are the arithmetic operations you can perform on dimensions:
634661
minus the sum of the {{CSSUnitValue/value}} internal slots
635662
of the [=list/items=] in |values|.
636663

637-
3. [=CSSMath/Negate=] all of the [=list/items=] in |values|.
664+
5. [=CSSMath/Negate=] all of the [=list/items=] in |values|.
638665

639-
4. If |this| is a {{CSSMathSum}} object,
666+
6. If |this| is a {{CSSMathSum}} object,
640667
[=list/append=] |values|
641668
to |this|’s {{CSSMathSum/values}} internal slot.
642669

643-
5. Otherwise,
670+
7. Otherwise,
644671
prepend |this| to |values|,
645672
then return a new {{CSSMathSum}} object
646673
whose {{CSSMathSum/values}} internal slot
@@ -664,11 +691,14 @@ The following are the arithmetic operations you can perform on dimensions:
664691
when called on a {{CSSNumericValue}} |this|,
665692
must perform the following steps:
666693

667-
1. Let |thisAndValues| be |this| prepended to |values|.
694+
1. Replace each [=list/item=] of |values|
695+
with the result of [=rectifying a numberish value=] for the [=list/item=].
696+
697+
2. Let |thisAndValues| be |this| prepended to |values|.
668698

669-
2. Let |mainValue| initially be null.
699+
3. Let |mainValue| initially be null.
670700

671-
3. [=list/For each=] |item| of |thisAndValues|:
701+
4. [=list/For each=] |item| of |thisAndValues|:
672702
1. If |item| has a [=strong type=],
673703
or a [=weak type=] other than "number":
674704

@@ -677,21 +707,21 @@ The following are the arithmetic operations you can perform on dimensions:
677707
2. Otherwise,
678708
[=throw=] a {{TypeError}}.
679709

680-
4. If |mainValue| is still null,
710+
5. If |mainValue| is still null,
681711
set |mainValue| to |this|.
682712

683-
5. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s,
713+
6. If all of the [=list/items=] in |values| are {{CSSUnitValue}}s,
684714
return a new {{CSSUnitValue}}
685715
whose {{CSSUnitValue/unit}} internal slot is set to |mainValue|’s {{CSSUnitValue/unit}} internal slot,
686716
and {{CSSUnitValue/value}} internal slot is set to
687717
the product of the {{CSSUnitValue/value}} internal slots
688718
of the [=list/items=] in |thisAndValues|.
689719

690-
6. If |this| is a {{CSSMathProduct}} object,
720+
7. If |this| is a {{CSSMathProduct}} object,
691721
[=list/append=] the [=list/items=] of |values|
692722
to |this|’s {{CSSMathProduct/values}} internal slot.
693723

694-
7. Otherwise,
724+
8. Otherwise,
695725
and return a new {{CSSMathProduct}}
696726
whose {{CSSMathProduct/values}} internal slot
697727
is set to |thisAndValues|.
@@ -702,11 +732,14 @@ The following are the arithmetic operations you can perform on dimensions:
702732
when called on a {{CSSNumericValue}} |this|,
703733
must perform the following steps:
704734

705-
1. Let |thisAndValues| be |this| prepended to |values|.
735+
1. Replace each [=list/item=] of |values|
736+
with the result of [=rectifying a numberish value=] for the [=list/item=].
737+
738+
2. Let |thisAndValues| be |this| prepended to |values|.
706739

707-
2. Let |mainValue| initially be null.
740+
3. Let |mainValue| initially be null.
708741

709-
3. [=list/For each=] |item| of |thisAndValues|:
742+
4. [=list/For each=] |item| of |thisAndValues|:
710743
1. If |item| has a [=strong type=],
711744
or a [=weak type=] other than "number":
712745

@@ -715,7 +748,7 @@ The following are the arithmetic operations you can perform on dimensions:
715748
2. Otherwise,
716749
[=throw=] a {{TypeError}}.
717750

718-
4. If |mainValue| is still null,
751+
5. If |mainValue| is still null,
719752
set |mainValue| to |this|.
720753

721754
6. If all of the [=list/items=] in |thisAndValues| are {{CSSUnitValue}}s,
@@ -728,11 +761,11 @@ The following are the arithmetic operations you can perform on dimensions:
728761

729762
7. [=CSSMath/Invert=] all of the [=list/items=] in |values|.
730763

731-
2. If |this| is a {{CSSMathProduct}} object,
764+
8. If |this| is a {{CSSMathProduct}} object,
732765
[=list/append=] the [=list/items=] of |values|
733766
to |this|’s {{CSSMathProduct/values}} internal slot.
734767

735-
3. Otherwise,
768+
9. Otherwise,
736769
prepend |this| to |values|,
737770
then return a new {{CSSMathProduct}} object
738771
whose {{CSSMathProduct/values}} internal slot
@@ -976,32 +1009,32 @@ interface CSSMathValue : CSSNumericValue {
9761009
readonly attribute DOMString type;
9771010
};
9781011

979-
[Constructor(CSSNumericValue... args)]
1012+
[Constructor(CSSNumberish... args)]
9801013
interface CSSMathSum : CSSMathValue {
9811014
attribute CSSNumericArray values;
9821015
};
9831016

984-
[Constructor(CSSNumericValue... args)]
1017+
[Constructor(CSSNumberish... args)]
9851018
interface CSSMathProduct : CSSMathValue {
9861019
attribute CSSNumericArray values;
9871020
};
9881021

989-
[Constructor(CSSNumericValue arg)]
1022+
[Constructor(CSSNumberish arg)]
9901023
interface CSSMathNegate : CSSMathValue {
9911024
attribute CSSNumericValue value;
9921025
};
9931026

994-
[Constructor(CSSNumericValue arg)]
1027+
[Constructor(CSSNumberish arg)]
9951028
interface CSSMathInvert : CSSMathValue {
9961029
attribute CSSNumericValue value;
9971030
};
9981031

999-
[Constructor(CSSNumericValue... args)]
1032+
[Constructor(CSSNumberish... args)]
10001033
interface CSSMathMin : CSSMathValue {
10011034
attribute CSSNumericArray values;
10021035
};
10031036

1004-
[Constructor(CSSNumericValue... args)]
1037+
[Constructor(CSSNumberish... args)]
10051038
interface CSSMathMax : CSSMathValue {
10061039
attribute CSSNumericArray values;
10071040
};
@@ -1086,14 +1119,17 @@ of all the "math" operations.
10861119
when called,
10871120
perform the following steps:
10881121

1089-
1. If |args| [=list/is empty=],
1122+
1. Replace each [=list/item=] of |args|
1123+
with the result of [=rectifying a numberish value=] for the [=list/item=].
1124+
1125+
2. If |args| [=list/is empty=],
10901126
[=throw=] a {{SyntaxError}}.
10911127

1092-
2. Let |strongType| initially be null.
1128+
3. Let |strongType| initially be null.
10931129

1094-
3. Let |values| be an initially empty [=list=].
1130+
4. Let |values| be an initially empty [=list=].
10951131

1096-
4. [=list/For each=] |arg| of |args|:
1132+
5. [=list/For each=] |arg| of |args|:
10971133

10981134
1. If |arg| has a [=strong type=], and |strongType| is null,
10991135
let |strongType| by |arg|’s [=strong type=].
@@ -1104,7 +1140,7 @@ of all the "math" operations.
11041140

11051141
3. [=list/Append=] |arg| to |values|.
11061142

1107-
5. Return a new {{CSSMathSum}}
1143+
6. Return a new {{CSSMathSum}}
11081144
whose {{CSSMathSum/values}} internal slot
11091145
is set to |values|.
11101146

@@ -1122,6 +1158,9 @@ of all the "math" operations.
11221158
when called,
11231159
perform the following steps:
11241160

1161+
1. Replace |arg|
1162+
with the result of [=rectifying a numberish value=] for |arg|.
1163+
11251164
1. Return a new {{CSSMathNegate}}
11261165
whose {{CSSMathNegate/value}} internal slot
11271166
is set to |arg|.

0 commit comments

Comments
 (0)