Skip to content

Commit a4f9927

Browse files
committed
Rewrite append() to be on Infra terms. Rename the weirdly-named algorithm.
1 parent 05b03fc commit a4f9927

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

css-typed-om/Overview.bs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ spec:infra;
8484
type: dfn;
8585
text: list
8686
text: code point
87+
text: string
8788
</pre>
8889

8990
Introduction {#intro}
@@ -242,25 +243,22 @@ probably in an appendix.
242243
that have transitioned from being [=single-valued=] to [=list-valued=].
243244
To ensure that code written at a time when a property was [=single-valued=]
244245
does not break when it becomes [=list-valued=] in the future,
245-
the {{CSSPropertyMap}} is a <b>multi-map</b>;
246+
the {{StylePropertyMap}} is a <b>multi-map</b>;
246247
it stores <em>list</em> of values for each key,
247248
but allows you to interact with it as if there was only a single value for each key as well.
248249

249-
This means that multiple values for a single property in a {{CSSPropertyMap}}
250+
This means that multiple values for a single property in a {{StylePropertyMap}}
250251
do not represent multiple successive definition of that property's value;
251252
instead, they represent multiple comma-separated sub-values in a single property value,
252253
like each "layer" in a 'background-image' property.
253254
</div>
254255

255-
The <dfn method for=StylePropertyMap>append(DOMString <var>property</var>,
256-
(CSSStyleValue or DOMString)... <var>values</var>)</dfn> method, when invoked, must
257-
[=append to a StylePropertyMap=] with property <var>property</var> and values <var>values</var>.
258-
259256
<div algorithm>
260-
To <dfn>append to a StylePropertyMap</dfn> given a <var>property</var> and a list of
261-
<var>values</var>, run these steps:
257+
The <dfn method for=StylePropertyMap>append(|property|, ...|values|)</dfn> method,
258+
when called on a {{StylePropertyMap}} |this|,
259+
must perform the following steps:
262260

263-
1. If |property| does not start with two dashes (U+002D HYPHEN),
261+
1. If |property| is not a [=custom property name string=],
264262
let |property| be |property| [=ASCII lowercased=].
265263

266264
2. If |property| is not a [=supported property name=],
@@ -269,17 +267,20 @@ The <dfn method for=StylePropertyMap>append(DOMString <var>property</var>,
269267
3. If |property| is not a [=list-valued property=],
270268
[=throw=] a {{TypeError}} and exit this algorithm.
271269

272-
4. If {{StylePropertyMap}}’s [=contained properties map=] contains an entry for |property|,
273-
let |entry| be that entry.
274-
Otherwise, create a new entry for |property| with an empty list,
275-
add it to the [=contained properties map=],
276-
and let |entry| be the newly-created entry.
270+
4. Let |props| be |this|’s [=contained properties map=].
277271

278-
5. Let |values to append| be the empty list.
272+
5. If |props|[|property|] does not [=map/exist=],
273+
[=map/set=] |props|[|property|] to an empty [=list=].
279274

280-
6. For each |value| in |values| if the <a>algorithm that coerces |value| into an appropriate type for a given property</a> does not throw an error, append the returned object to |values to append|.
275+
6. Let |temp values| be an empty [=list=].
281276

282-
7. Append |values to append| to the end of |entry|’s list.
277+
7. For each |value| in |values|,
278+
[=normalize a style value=] with |property| and |value|,
279+
and [=list/append=] the returned value to |temp values|.
280+
281+
<!-- Using a temp list so that nothing gets mutated if normalizing ends up throwing an error. -->
282+
283+
8. [=list/Append=] the entries of |temp values| to |props|[|property|].
283284
</div>
284285

285286
<div algorithm>
@@ -296,17 +297,20 @@ The <dfn method for=StylePropertyMap>append(DOMString <var>property</var>,
296297
</div>
297298

298299
<div algorithm>
299-
This section describes the <dfn>algorithm that coerces value into an appropriate type for a given property</dfn>, or fails and throws a {{TypeError}}:
300-
: If |value| is a {{CSSStyleValue}},
301-
:: If |value| does not match the grammar of a [=list-valued property iteration=] of |property|,
302-
[=throw=] a {{TypeError}} and exit this algorithm.
303-
Otherwise, return the |value|.
304-
: If |value| is a {{DOMString}},
305-
:: [=Parse a CSSStyleValue=] with property |property| and value |value| and return the resulting |value|.
306-
If the result is null,
307-
[=throw=] a {{TypeError}} and exit this algorithm.
308-
Otherwise, append each [=list-valued property iteration=] in the result to a |values to append| object
309-
and return |values to append|.
300+
To <dfn export>normalize a style value</dfn>,
301+
given a [=string=] |property|
302+
and a [=string=] or {{CSSStyleValue}} |value|:
303+
304+
: If |value| is a {{CSSStyleValue}},
305+
:: If |value| does not match the grammar of a [=list-valued property iteration=] of |property|,
306+
[=throw=] a {{TypeError}} and exit this algorithm.
307+
Otherwise, return the |value|.
308+
309+
: If |value| is a {{DOMString}},
310+
:: [=Parse a CSSStyleValue=] with property |property|, value |value|, and |parseMultiple| set to `false`,
311+
and return the result.
312+
313+
Note: This can throw a {{TypeError}} instead.
310314
</div>
311315

312316
<div algorithm>
@@ -415,6 +419,13 @@ the [=contained properties map=]. This list of properties is sorted in the follo
415419

416420
[=computed StylePropertyMap=], [=declared StylePropertyMap=] and [=inline StylePropertyMap=] are all live objects: the attributes and methods on these objects must operate on the actual underlying data, not a snapshot of the data.
417421

422+
A [=string=] is a <dfn>custom property name string</dfn>
423+
if it starts with two dashes (U+002D HYPHEN-MINUS), like <code>--foo</code>.
424+
(This corresponds to the <<custom-property-name>> production,
425+
but applies to [=strings=],
426+
rather than [=identifiers=];
427+
it can be used without invoking the CSS parser.)
428+
418429
Issue(148): add detailed descriptions of the rest of the methods on {{StylePropertyMap}}
419430

420431
Issue(268): stringification

0 commit comments

Comments
 (0)