Skip to content

Commit 9573034

Browse files
committed
[css-easing-2] Rewrite/simplify linear() definition and parsing. Still need to rewrite output algo. w3c#10580
1 parent e7aae00 commit 9573034

File tree

1 file changed

+45
-87
lines changed

1 file changed

+45
-87
lines changed

css-easing-2/Overview.bs

Lines changed: 45 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -140,107 +140,65 @@ The syntax for specifying an [=easing function=] is as follows:
140140
A <dfn export>linear easing function</dfn>
141141
is an [=easing function=]
142142
that interpolates linearly
143-
between its [=linear easing function/points=].
143+
between its [=control points=].
144+
Each <dfn for="linear easing function">control point</dfn>
145+
is a pair of numbers,
146+
associating an [=input progress value=]
147+
to an [=output progress value=].
144148

145-
A [=linear easing function=] has <dfn for="linear easing function">points</dfn>,
146-
a [=/list=] of [=linear easing points=].
147-
Initially a new empty [=/list=].
148-
149-
A <dfn>linear easing point</dfn>
150-
is a [=/struct=]
151-
that has:
152-
153-
<dl dfn-for="linear easing point">
154-
155-
: <dfn>input</dfn>
156-
:: A number or null
157-
158-
Note: This is only null during [=create a linear easing function=].
159-
160-
: <dfn>output</dfn>
161-
:: A number
162-
163-
</dl>
164149

165150
### Syntax ### {#linear-easing-function-syntax}
166151

167152
A [=linear easing function=] has the following syntax:
168153

169154
<pre class="prod">
170-
<dfn>&lt;linear-easing-function></dfn> = <dfn function lt="linear()">linear(<<linear-stop-list>>)</dfn>
171-
<dfn>&lt;linear-stop-list></dfn> = [ <<linear-stop>> ]#
172-
<dfn>&lt;linear-stop></dfn> = <<number>> && <<linear-stop-length>>?
173-
<dfn>&lt;linear-stop-length></dfn> = <<percentage>>{1,2}
155+
<dfn>linear()</dfn> = linear( [ <<number>> && <<percentage>>{0,2} ]# )
174156
</pre>
175157

176158
<wpt>
177159
linear-timing-functions-syntax.html
178160
</wpt>
179161

180-
''linear()'' is parsed into a [=linear easing function=]
181-
by calling [=create a linear easing function=],
182-
passing in its <<linear-stop-list>> as a [=/list=] of <<linear-stop>>s.
183-
184-
### Parsing ### {#linear-easing-function-parsing}
185-
186-
<section algorithm="to create a linear easing function">
187-
188-
To <dfn>create a linear easing function</dfn>
189-
given a [=/list=] of <<linear-stop>>s |stopList|,
190-
perform the following.
191-
It returns a [=linear easing function=] or <i>failure</i>.
192-
193-
1. Let |function| be a new [=linear easing function=].
194-
195-
1. Let |largestInput| be negative infinity.
196-
197-
1. If there are less than two [=list/items=] in |stopList|, then return <i>failure</i>.
198-
199-
1. [=list/For each=] |stop| in |stopList|:
200-
201-
1. Let |point| be a new [=linear easing point=]
202-
with its [=linear easing point/output=] set to |stop|'s <<number>> as a number.
203-
204-
1. [=list/Append=] |point| to |function|'s [=linear easing function/points=].
205-
206-
1. If |stop| has a <<linear-stop-length>>, then:
207-
208-
1. Set |point|'s [=linear easing point/input=] to whichever is greater:
209-
|stop|'s <<linear-stop-length>>'s first <<percentage>> as a number,
210-
or |largestInput|.
211-
212-
1. Set |largestInput| to |point|'s [=linear easing point/input=].
213-
214-
1. If |stop|'s <<linear-stop-length>> has a second <<percentage>>, then:
215-
216-
1. Let |extraPoint| be a new [=linear easing point=]
217-
with its [=linear easing point/output=] set to |stop|'s <<number>> as a number.
218-
219-
1. [=list/Append=] |extraPoint| to |function|'s [=linear easing function/points=].
220-
221-
1. Set |extraPoint|'s [=linear easing point/input=] to whichever is greater:
222-
|stop|'s <<linear-stop-length>>'s second <<percentage>> as a number,
223-
or |largestInput|.
224-
225-
1. Set |largestInput| to |extraPoint|'s [=linear easing point/input=].
226-
227-
1. Otherwise, if |stop| is the first [=list/item=] in |stopList|, then:
228-
229-
1. Set |point|'s [=linear easing point/input=] to 0.
230-
231-
1. Set |largestInput| to 0.
232-
233-
1. Otherwise, if |stop| is the last [=list/item=] in |stopList|,
234-
then set |point|'s [=linear easing point/input=] to whichever is greater:
235-
1 or |largestInput|.
236-
237-
1. For runs of [=list/items=] in |function|'s [=linear easing function/points=] that have a null [=linear easing point/input=],
238-
assign a number to the [=linear easing point/input=] by linearly interpolating between the closest previous and next [=linear easing function/points=]
239-
that have a non-null [=linear easing point/input=].
240-
241-
1. Return |function|.
162+
Each comma-separated argument defines one or two [=control points=],
163+
with an [=input progress value=] equal to the specified <<percentage>>
164+
(converted to a <<number>> between 0 and 1),
165+
and an [=output progress value=] equal to the specified <<number>>.
166+
When the argument has two <<percentages>>,
167+
it defines two [=control points=] in the specified order,
168+
one per <<percentage>>.
169+
170+
If an argument lacks a <<percentage>>,
171+
its [=input progress value=] is initially empty,
172+
but that is immediately corrected by [=linear() canonicalization=] after parsing.
173+
174+
<div algorithm>
175+
To <dfn export lt="linear() canonicalization|canonicalize a linear()">canonicalize a linear()</dfn> function's [=control points=],
176+
perform the following:
177+
178+
1. If the first [=control point=] lacks an [=input progress value=],
179+
set its [=input progress value=] to 0.
180+
181+
2. If the last [=control point=] lacks an [=input progress value=],
182+
set its [=input progress value=] to 1.
183+
184+
3. If any [=control point=] has an [=input progress value=]
185+
that is less than the [=input progress value=] of any preceding [=control point=],
186+
set its [=input progress value=] to the largest [=input progress value=]
187+
of any preceding [=control point=].
188+
189+
4. If any [=control point=] still lacks an [=input progress value=],
190+
then for each contiguous run of such [=control points=],
191+
set their [=input progress values=]
192+
so that they are evenly spaced
193+
between the preceding and following [=control points=]
194+
with [=input progress values=].
195+
196+
After canonicalization,
197+
every [=control point=] has an [=input progress value=],
198+
and the [=input progress values=] are monotonically non-decreasing
199+
along the list.
200+
</div>
242201

243-
</section>
244202

245203
### Serializing ### {#linear-easing-function-serializing}
246204

0 commit comments

Comments
 (0)