Skip to content

Commit 9db359f

Browse files
committed
Be more precise about internal slots in the numeric algorithms.
1 parent 3ef88ed commit 9db359f

File tree

1 file changed

+82
-57
lines changed

1 file changed

+82
-57
lines changed

css-typed-om/Overview.bs

Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Abstract: Converting CSSOM value strings into meaningfully typed JavaScript repr
1010
Editor: Shane Stephens, shanestephens@google.com
1111
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/, w3cid 42199
1212
Repository: w3c/css-houdini-drafts
13+
Inline Github Issues: title
1314
Ignored Vars: type, unit
1415
Ignored Terms: Drawable, paint image definition, list-valued property, list-valued property iteration, parse a CSSStyleValue, values to iterate over, CSS
1516
Markup Shorthands: markdown yes
@@ -553,12 +554,19 @@ The following are the arithmetic operations you can perform on dimensions:
553554
2. If |this| and |value| are both {{CSSUnitValue}}s:
554555
and have the same {{CSSUnitValue/unit}},
555556
return a new {{CSSUnitValue}}
556-
with the same unit
557-
and a value equal to the sum of |this|’s and |value|’s values.
558-
559-
3. Otherwise,
560-
return a {{CSSCalcValue}}
561-
representing the sum of the |this| and |value|.
557+
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
558+
and {{CSSUnitValue/value}} internal slot set to the sum of
559+
|this|’s and |value|’s {{CSSUnitValue/value}} internal slots.
560+
561+
3. Otherwise:
562+
1. Let |newEntries| be a copy of |this|’s [=map entries=].
563+
2. [=map/For each=] |unit| → |val| in |value|’s [=map entries=]:
564+
1. If |newEntries|[|unit|] [=map/exists=],
565+
set |newEntries|[|unit|] to |newEntries|[|unit|] plus |val|.
566+
2. Otherwise,
567+
set |newEntries|[|unit|] to |val|.
568+
3. Return a new {{CSSCalcValue}}
569+
whose [=map entries=] are |newEntries|.
562570
</div>
563571

564572
<div algorithm="CSSNumericValue.sub()">
@@ -573,12 +581,19 @@ The following are the arithmetic operations you can perform on dimensions:
573581
2. If |this| and |value| are both {{CSSUnitValue}}s:
574582
and have the same {{CSSUnitValue/unit}},
575583
return a new {{CSSUnitValue}}
576-
with the same unit
577-
and a value equal to the difference of |this|’s and |value|’s values.
578-
579-
3. Otherwise,
580-
return a {{CSSCalcValue}}
581-
representing the difference of the |this| and |value|.
584+
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
585+
and {{CSSUnitValue/value}} internal slot set to the difference of
586+
|this|’s and |value|’s {{CSSUnitValue/value}} internal slots.
587+
588+
3. Otherwise:
589+
1. Let |newEntries| be a copy of |this|’s [=map entries=].
590+
2. [=map/For each=] |unit| → |val| in |value|’s [=map entries=]:
591+
1. If |newEntries|[|unit|] [=map/exists=],
592+
set |newEntries|[|unit|] to |newEntries|[|unit|] minus |val|.
593+
2. Otherwise,
594+
set |newEntries|[|unit|] to -|val|.
595+
3. Return a new {{CSSCalcValue}}
596+
whose [=map entries=] are |newEntries|.
582597
</div>
583598

584599
<div algorithm="CSSNumericValue.mul()">
@@ -588,13 +603,15 @@ The following are the arithmetic operations you can perform on dimensions:
588603

589604
1. If |this| is a {{CSSUnitValue}},
590605
return a new {{CSSUnitValue}}
591-
with the same unit
592-
and a value equal to |this|’s value times |value|.
593-
594-
2. Otherwise,
595-
return a new {{CSSCalcValue}}
596-
containing the same keys,
597-
but with each value multiplied by |value|.
606+
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
607+
and {{CSSUnitValue/value}} internal slot set to |this|’s {{CSSUnitValue/value}} internal slot times |value|.
608+
609+
2. Otherwise:
610+
1. Let |newEntries| be a copy of |this|’s [=map entries=].
611+
2. [=map/For each=] |unit| → |val| in |newEntries|,
612+
set |newEntries|[|unit|] to |val| times |value|.
613+
3. Return a new {{CSSCalcValue}}
614+
whose [=map entries=] are |newEntries|.
598615
</div>
599616

600617
<div algorithm="CSSNumericValue.div()">
@@ -604,17 +621,19 @@ The following are the arithmetic operations you can perform on dimensions:
604621

605622
1. If |this| is a {{CSSUnitValue}},
606623
return a new {{CSSUnitValue}}
607-
with the same unit
608-
and a value equal to |this|’s value divided by |value|.
609-
610-
2. Otherwise,
611-
return a new {{CSSCalcValue}}
612-
containing the same keys,
613-
but with each value divided by |value|.
624+
whose {{CSSUnitValue/unit}} internal slot is set to |this|’s {{CSSUnitValue/unit}} internal slot,
625+
and {{CSSUnitValue/value}} internal slot set to |this|’s {{CSSUnitValue/value}} internal slot divided by |value|.
626+
627+
2. Otherwise:
628+
1. Let |newEntries| be a copy of |this|’s [=map entries=].
629+
2. [=map/For each=] |unit| → |val| in |newEntries|,
630+
set |newEntries|[|unit|] to |val| divided by |value|.
631+
3. Return a new {{CSSCalcValue}}
632+
whose [=map entries=] are |newEntries|.
614633
</div>
615634

616635
<div algorithm="CSSNumericValue.to()">
617-
The <dfn method for=CSSNumericValue>to(|unit|)</dfn> method converts an existing {{CSSNumericValue}}
636+
The <dfn method for=CSSNumericValue>to(|unit|)</dfn> method converts an existing {{CSSNumericValue}} |this|
618637
into another one with the specified |unit|.
619638
When called, it must perform the following steps:
620639

@@ -623,24 +642,21 @@ The following are the arithmetic operations you can perform on dimensions:
623642
and abort this algorithm.
624643

625644
2. If |this| is a {{CSSUnitValue}}
626-
and |this|’s unit and |unit| are [=compatible units=],
645+
and |this|’s {{CSSUnitValue/unit}} internal slot and |unit| are [=compatible units=],
627646
return a new {{CSSUnitValue}}
628-
with its unit set to |unit|
629-
and its value set to |this|’s value
647+
with its {{CSSUnitValue/unit}} internal slot set to |unit|
648+
and its {{CSSUnitValue/value}} internal slot set to |this|’s {{CSSUnitValue/value}}
630649
multiplied by the conversion ratio between the two units.
631650

632-
3. If |this| is a {{CSSCalcValue}}
633-
and all of its keys
634-
are [=compatible units=] with |unit|,
635-
return a new {{CSSUnitValue}}
636-
with its unit set to |unit|
637-
and its value to the sum of
638-
each of |this|’s values
639-
multiplied by the corresponding conversion ratios
640-
between their key and |unit|.
641-
642-
4. Otherwise,
643-
[=throw=] a {{TypeError}}.
651+
3. If |this| is a {{CSSCalcValue}}:
652+
1. Let |sum| be 0.
653+
2. [=map/For each=] |oldUnit| → |value| in |this|’s [=map entries=]:
654+
1. If |oldUnit| and |unit| are not [=compatible units=],
655+
[=throw=] a {{TypeError}}.
656+
2. Increment |sum| by |value| times the conversion ratio between |oldUnit| and |unit|.
657+
3. Return a new {{CSSUnitValue}}
658+
with its {{CSSUnitValue/unit}} internal slot set to |unit|
659+
and its {{CSSUnitValue/value}} internal slot set to |sum|.
644660
</div>
645661

646662
The {{CSSNumericValue/parse()}} method allows a {{CSSNumericValue}}
@@ -667,17 +683,24 @@ rather than on {{CSSNumericValue}} instances.
667683

668684
3. If |result| is a <<dimension-token>>, <<number-token>>, or <<percentage-token>>,
669685
return a new {{CSSUnitValue}} object
670-
with its value set to the token's value,
671-
and the unit set to the token's unit if it's a <<dimension-token>>,
672-
or `"number"` if it is a <<number-token>>,
673-
or `"percentage"` if it is a <<percentage-token>>.
674-
675-
4. If |result| is a <<calc()>>,
676-
normalize the ''calc()'' argument
677-
into a sum of values with unique units,
678-
then return a {{CSSCalcValue}} object,
679-
with keys for each unit in the calc,
680-
and values set to the corresponding numeric values.
686+
with its {{CSSUnitValue/value}} internal slot set to the token's value,
687+
and its {{CSSUnitValue/value}} internal slot set to the token's unit if it's a <<dimension-token>>,
688+
or `"number"` if it's a <<number-token>>,
689+
or `"percentage"` if it's a <<percentage-token>>.
690+
691+
4. If |result| is a <<calc()>>:
692+
1. Normalize the ''calc()'' argument
693+
into a sum of values with unique units |calcEntries|.
694+
2. Let |newEntries| be an empty [=ordered map=].
695+
3. If |calcEntries| contains a <<number>> term,
696+
set |newEntries|["number"] to the value of that term.
697+
4. For each <<dimension>> term in |calcEntries|,
698+
ordered [=ASCII case-insensitive=] alphabetically by their |unit|,
699+
set |newEntries|[|unit|] to the term's value.
700+
5. If |calcEntries| contains a <<percentage>> term,
701+
set |newEntries|["percentage"] to the value of that term.
702+
6. Return a new {{CSSCalcValue}} object
703+
with its [=map entries=] set to |newEntries|.
681704
</div>
682705

683706
{{CSSNumericValue}}s can be <dfn>strongly typed</dfn>
@@ -744,8 +767,8 @@ are represented as {{CSSUnitValue}}s.
744767
and abort this algorithm.
745768

746769
2. Return a new {{CSSUnitValue}}
747-
with its value set to |value|
748-
and its unit set to |unit|.
770+
with its {{CSSUnitValue/value}} internal slot set to |value|
771+
and its {{CSSUnitValue/unit}} set to |unit|.
749772
</div>
750773

751774
<div algorithm="CSSUnitValue.unit">
@@ -757,10 +780,10 @@ are represented as {{CSSUnitValue}}s.
757780
[=throw=] a {{TypeError}}.
758781

759782
2. Otherwise,
760-
set |this|’s internal {{CSSUnitValue/unit}} slot to |unit|.
783+
set |this|’s {{CSSUnitValue/unit}} internal slot to |unit|.
761784

762785
On reading,
763-
it must return the value of |this|’s internal {{CSSUnitValue/unit}} slot.
786+
it must return the value of |this|’s {{CSSUnitValue/unit}} internal slot.
764787
</div>
765788

766789
<div algorithm="CSSUnitValue.type">
@@ -1306,6 +1329,8 @@ is a [=list=] of {{CSSTransformComponent}}s.
13061329
Note: ''perspective()'' functions always represent 3D transforms.
13071330
</div>
13081331

1332+
Issue(366): Figure out how to define 2d vs 3d matrix.
1333+
13091334
<div class=note>
13101335
Each {{CSSTransformComponent}} can correspond to
13111336
one of a number of underlying transform functions.

0 commit comments

Comments
 (0)