Skip to content

Commit 529ec2a

Browse files
committed
Rewrite 'parse a CSS value' to match the other algos in property parsing, explicitly invoke normalization, and throw if you call parseAll for a single-valued property.
1 parent 989c1c8 commit 529ec2a

File tree

1 file changed

+62
-33
lines changed

1 file changed

+62
-33
lines changed

css-typed-om/Overview.bs

+62-33
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ Some particular considerations:
120120
<xmp class='idl'>
121121
interface CSSStyleValue {
122122
stringifier;
123-
static CSSStyleValue? parse(DOMString property, DOMString cssText);
124-
static sequence<CSSStyleValue>? parseAll(DOMString property, DOMString cssText);
123+
static CSSStyleValue parse(DOMString property, DOMString cssText);
124+
static sequence<CSSStyleValue> parseAll(DOMString property, DOMString cssText);
125125
};
126126
</xmp>
127127

@@ -136,50 +136,78 @@ return a normalized representation
136136
(see [[#stylevalue-normalization]])
137137
of the value the {{CSSStyleValue}} object represents.
138138

139-
The <dfn method for=CSSStyleValue>parse(DOMString <var>property</var>, DOMString <var>cssText</var>)</dfn>,
140-
when invoked, must [=parse a CSSStyleValue=] with property <var>property</var>, cssText <var>cssText</var>,
141-
and parseMultiple set to false.
139+
The <dfn method for=CSSStyleValue>parse(|property|, |cssText|)</dfn> method,
140+
when invoked,
141+
must [=parse a CSSStyleValue=]
142+
with property |property|, cssText |cssText|, and parseMultiple set to false.
142143

143-
The <dfn method for=CSSStyleValue>parseAll(DOMString <var>property</var>, DOMString <var>cssText</var>)</dfn>,
144-
when invoked, must [=parse a CSSStyleValue=] with property <var>property</var>, cssText <var>cssText</var>,
145-
and parseMultiple set to true.
144+
The <dfn method for=CSSStyleValue>parseAll(|property|, |cssText|)</dfn>,
145+
when invoked,
146+
must [=parse a CSSStyleValue=]
147+
with property |property|, cssText |cssText|, and parseMultiple set to true.
146148

147149
<div algorithm="parse a CSSStyleValue">
148-
To <dfn>parse a CSSStyleValue</dfn> given a <var>property</var>, <var>cssText</var>, and a
149-
<var>parseMultiple</var> flag, run these steps:
150+
To <dfn>parse a CSSStyleValue</dfn> given a [=string=] |property|, a [=string=] |cssText|,
151+
and a |parseMultiple| flag, run these steps:
150152

151-
1. Attempt to parse |property| as an <<ident>>.
152-
If this fails,
153-
[=throw=] a {{TypeError}} and exit this algorithm.
154-
Otherwise, let |property| be the parsed result.
155-
If |property| does not start with two dashes (U+002D HYPHEN),
153+
1. If |property| is not a [=custom property name string=],
156154
let |property| be |property| [=ASCII lowercased=].
157155

158-
2. If |property| is not a [[=valid CSS property=],
156+
2. If |property| is not a [=valid CSS property=],
157+
[=throw=] a {{TypeError}} and exit this algorithm.
158+
159+
3. If |parseMultiple| is true,
160+
but |property| is a [=single-valued property=],
159161
[=throw=] a {{TypeError}} and exit this algorithm.
160162

161-
3. Attempt to <a lt="parse something according to a CSS grammar">parse</a> |cssText| according to |property|’s grammar.
163+
3. Attempt to [=CSS/parse=] |cssText| according to |property|’s grammar.
162164
If this fails,
163165
[=throw=] a {{TypeError}} and exit this algorithm.
164166
Otherwise,
165-
let |value| be the parsed result.
167+
let |whole value| be the parsed result.
166168

167-
4. If |parseMultiple| is true,
168-
subdivide |value| into a list of {{CSSStyleValue}} objects,
169-
each representing one [=list-valued property iteration=],
170-
and let |value| be the result. Return |value| as a sequence of
171-
{{CSSStyleValue}} objects.
169+
4. [=Subdivide into iterations=] |whole value|,
170+
according to |property|,
171+
and let |values| be the result.
172172

173-
5. If |parseMultiple| is false
174-
subdivide |value| into a list of {{CSSStyleValue}} objects,
175-
each representing one [=list-valued property iteration=],
176-
and let |value| be the first entry in this list.
177-
178-
6. return a {{CSSStyleValue}} representing |value|.
173+
5. [=list/For each=] |value| in |values|,
174+
replace it with the result of [=normalize a CSS value|normalizing=] |value| for |property|.
179175

176+
6. If |parseMultiple| is false,
177+
return |values|[0].
178+
Otherwise, return |values|.
180179
</div>
181180

182-
Issue(305): appropriate failure indicators for this algorithm
181+
<div algorithm>
182+
To <dfn export>subdivide into iterations</dfn>
183+
a CSS value |whole value|
184+
for a property |property|,
185+
execute the following steps:
186+
187+
1. If |property| is a [=single-valued property=],
188+
return a [=list=] containing |whole value|.
189+
190+
2. Otherwise,
191+
divide |whole value| into individual iterations,
192+
as appropriate for |property|,
193+
and return a [=list=] containing the iterations in order.
194+
195+
<div class=note>
196+
How to divide a [=list-valued property=] into iterations
197+
is intentionally undefined and hand-wavey at the moment.
198+
<em>Generally</em>,
199+
you just split it on top-level commas
200+
(corresponding to a top-level `<foo>#` term in the grammar),
201+
but some legacy properties (such as 'counter-reset')
202+
don't separate their iterations with commas,
203+
and some properties (such as 'animation')
204+
use a special singular value (generally ''animation/none'')
205+
to indicate <strong>zero</strong> iterations.
206+
207+
It's expected to be rigorously defined in the future,
208+
but at the moment is explicitly a "you know what we mean" thing.
209+
</div>
210+
</div>
183211

184212
<!--
185213
██████ ████████ ██ ██ ██ ████████ ██ ██ ███ ████████
@@ -377,7 +405,7 @@ probably in an appendix.
377405
2. If |property| is not a [[=valid CSS property=],
378406
[=throw=] a {{TypeError}} and exit this algorithm.
379407

380-
3. If |property| is a [=single-valued property=] and |values| has more than one [=list/entry=],
408+
3. If |property| is a [=single-valued property=] and |values| has more than one [=list/item=],
381409
[=throw=] a {{TypeError}} and exit this algorithm.
382410

383411
4. Let |props| be |this|’s [=StylePropertyMap/map entries=].
@@ -2479,10 +2507,11 @@ Issue(159): Spec up ColorValue
24792507
{{CSSStyleValue}} normalization {#stylevalue-normalization}
24802508
===========================================================
24812509

2482-
This section describes how Typed OM objects are constructed from CSS values.
2510+
This section describes how Typed OM objects are constructed from abstract CSS values
2511+
(aka how to <dfn export>normalize a CSS value</dfn> for a given property).
24832512

24842513
If a property's grammar is more complex than one of the types listed here,
2485-
it produces a raw {{CSSStyleValue}},
2514+
it [=normalizes=] to a raw {{CSSStyleValue}},
24862515
with a <a for=CSSStyleValue>stringification behavior</a>
24872516
that produces the CSSOM serialization of the property.
24882517

0 commit comments

Comments
 (0)