Skip to content

Commit ead3cdf

Browse files
[css-view-transitions-1] Adding DOM intro sections (#8369)
1 parent 18d06fd commit ead3cdf

File tree

1 file changed

+86
-6
lines changed

1 file changed

+86
-6
lines changed

css-view-transitions-1/Overview.bs

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
8080
pre {
8181
tab-size: 2;
8282
}
83+
.domintro {
84+
position: relative;
85+
color: green;
86+
background: #DDFFDD;
87+
margin: 2.5em 0 2em 0;
88+
padding: 1.5em 1em 0.5em 2em;
89+
}
90+
.domintro dt, .domintro dt * {
91+
color: black;
92+
font-size: inherit;
93+
}
94+
.domintro dd {
95+
margin: 0.5em 0 1em 2em; padding: 0;
96+
}
97+
.domintro dd p {
98+
margin: 0.5em 0;
99+
}
100+
.domintro::before {
101+
content: 'For web developers (non-normative)';
102+
background: green;
103+
color: white;
104+
padding: 0.15em 0.25em;
105+
font-style: normal;
106+
position: absolute;
107+
top: -0.8em;
108+
left: -0.8em;
109+
}
83110
</style>
84111

85112
# Introduction # {#intro}
@@ -857,20 +884,34 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
857884

858885
<xmp class=idl>
859886
partial interface Document {
860-
ViewTransition startViewTransition(optional UpdateCallback? callback = null);
887+
ViewTransition startViewTransition(optional UpdateCallback? updateCallback = null);
861888
};
862889

863890
callback UpdateCallback = Promise<any> ();
864891
</xmp>
865892

893+
<dl class="domintro non-normative">
894+
: <code>{{ViewTransition|viewTransition}} = {{Document|document}}.{{startViewTransition}}({{UpdateCallback|updateCallback}})</code>
895+
:: Starts a new view transition.
896+
897+
{{UpdateCallback|updateCallback}} is called asynchronously, once the current state of the document is captured.
898+
Then, when the promise returned by {{UpdateCallback|updateCallback}} fulfills, the new state of the document is captured.
899+
900+
{{UpdateCallback|updateCallback}} is _always_ called, even if the transition cannot happen (e.g. due to duplicate `view-transition-name` values).
901+
The transition is an enhancement around the state change, so a failure to create a transition never prevents the state change.
902+
See [[#transitions-as-enhancements]] for more details on this principle.
903+
904+
If the promise returned by {{UpdateCallback|updateCallback}} rejects, the transition is skipped.
905+
</dl>
906+
866907
### {{Document/startViewTransition()}} ### {#ViewTransition-prepare}
867908

868909
<div algorithm>
869-
The [=method steps=] for <dfn method for=Document>startViewTransition(|callback|)</dfn> are as follows:
910+
The [=method steps=] for <dfn method for=Document>startViewTransition(|updateCallback|)</dfn> are as follows:
870911

871912
1. Let |transition| be a new {{ViewTransition}} object in [=this's=] [=relevant Realm=].
872913

873-
1. Set |transition|'s [=ViewTransition/update callback=] to |callback|.
914+
1. Set |transition|'s [=ViewTransition/update callback=] to |updateCallback|.
874915

875916
1. Let |document| be [=this's=] [=relevant global object's=] [=associated document=].
876917

@@ -894,17 +935,56 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
894935
<xmp class=idl>
895936
[Exposed=Window]
896937
interface ViewTransition {
897-
undefined skipTransition();
898-
readonly attribute Promise<undefined> finished;
899-
readonly attribute Promise<undefined> ready;
900938
readonly attribute Promise<undefined> updateCallbackDone;
939+
readonly attribute Promise<undefined> ready;
940+
readonly attribute Promise<undefined> finished;
941+
undefined skipTransition();
901942
};
902943
</xmp>
903944

904945
Note: The {{ViewTransition}} represents and controls a single same-document transition.
905946
That is, it controls a transition where the starting and ending document are the same,
906947
possibly with changes to the document's DOM structure.
907948

949+
<dl class="domintro non-normative">
950+
: <code>{{ViewTransition|viewTransition}}.{{ViewTransition/updateCallbackDone}}</code>
951+
:: A promise that fulfills when the promise returned by {{UpdateCallback|updateCallback}} fulfills, or rejects when it rejects.
952+
953+
The View Transition API wraps a DOM change and creates a transition.
954+
However, sometimes you don't care about the success/failure of the transition animation,
955+
you just want to know if and when the DOM change happens.
956+
{{ViewTransition/updateCallbackDone}} is for that use-case.
957+
958+
: <code>{{ViewTransition|viewTransition}}.{{ViewTransition/ready}}</code>
959+
:: A promise that fulfills once the pseudo-elements for the transition are created,
960+
and the animation is about to start.
961+
962+
It rejects if the transition cannot begin.
963+
This can be due to misconfiguration, such as duplicate 'view-transition-name's,
964+
or if {{ViewTransition/updateCallbackDone}} returns a rejected promise.
965+
966+
The point that {{ViewTransition/ready}} fulfills is the ideal opportunity to animate the view transition pseudo-elements with the [[web-animations-1#extensions-to-the-element-interface|web animation API]].
967+
968+
: <code>{{ViewTransition|viewTransition}}.{{ViewTransition/finished}}</code>
969+
:: A promise that fulfills once the end state is fully visible and interactive to the user.
970+
971+
It only rejects if {{UpdateCallback|updateCallback}} returns a rejected promise,
972+
as this indicates the end state wasn't created.
973+
974+
Otherwise, if a transition fails to begin, or is skipped (from skipTransition()), the end state is still reached,
975+
so {{ViewTransition/finished}} fulfills.
976+
977+
: <code>{{ViewTransition|viewTransition}}.{{ViewTransition/skipTransition}}()</code>
978+
:: Immediately finish the transition, or prevent it starting.
979+
980+
This never prevents {{UpdateCallback|updateCallback}} being called,
981+
as the DOM change is separate to the transition. See [[#transitions-as-enhancements]] for more details on this principle.
982+
983+
If this is called before {{ViewTransition/ready}} resolves, {{ViewTransition/ready}} will reject.
984+
985+
If {{ViewTransition/finished}} hasn't resolved, it will fulfill or reject along with {{ViewTransition/updateCallbackDone}}.
986+
</dl>
987+
908988
A {{ViewTransition}} has the following:
909989

910990
<dl dfn-for="ViewTransition">

0 commit comments

Comments
 (0)