@@ -123,14 +123,13 @@ Note that because these APIs are an enhancement to the DOM change, some principl
123
123
href="https://wicg.github.io/navigation-api/#navigate-event-class"> `signal`
124
124
on `NavigateEvent`</a> is an example of a feature developers could use to
125
125
handle this.
126
- * Although the transition API allows DOM changes to be asynchronous via the
127
- {{ViewTransitionInit/updateDOM}} callback, the transition API is not
128
- responsible for queuing or otherwise scheduling the DOM changes, beyond the
129
- scheduling needed for the transition itself. Some asynchronous DOM changes
130
- can happen concurrently (e.g if they're happening within independent
131
- components), whereas others need to queue, or abort an earlier change. This
132
- is best left to a feature or framework that has a more holistic view of the
133
- update.
126
+ * Although the transition API allows DOM changes to be asynchronous via the [=callback=] , the transition
127
+ API is not responsible for queuing or otherwise scheduling the DOM changes,
128
+ beyond the scheduling needed for the transition itself. Some asynchronous
129
+ DOM changes can happen concurrently (e.g if they're happening within
130
+ independent components), whereas others need to queue, or abort an earlier
131
+ change. This is best left to a feature or framework that has a more
132
+ holistic view of the update.
134
133
135
134
# CSS properties # {#css-properties}
136
135
@@ -449,26 +448,27 @@ A {{Document}} additionally has:
449
448
450
449
<script type=idl>
451
450
partial interface Document {
452
- ViewTransition createTransition(ViewTransitionInit init);
453
- };
454
-
455
- dictionary ViewTransitionInit {
456
- required UpdateDOMCallback updateDOM;
451
+ ViewTransition startViewTransition(optional UpdateDOMCallback? callback = null);
457
452
};
458
453
459
454
callback UpdateDOMCallback = Promise<any> ();
460
455
</script>
461
456
462
- ### {{Document/createTransition()}} ### {#ViewTransition-prepare}
457
+ <dl>
458
+ : <dfn>callback</dfn>
459
+ :: An asynchronous callback used to change the old DOM state into new DOM state.
460
+ </dl>
461
+
462
+ ### {{Document/startViewTransition()}} ### {#ViewTransition-prepare}
463
463
464
464
<div algorithm>
465
465
The [=method steps=] for
466
- <dfn method for=Document>createTransition(|init| )</dfn>
466
+ <dfn method for=Document>startViewTransition([=callback=] )</dfn>
467
467
are as follows:
468
468
469
469
1. Let |transition| be a new {{ViewTransition}} object in [=this's=] [=relevant Realm=] .
470
470
471
- 1. Set |transition|'s [=ViewTransition/DOM update callback=] to |init| [{{ViewTransitionInit/updateDOM}} ] .
471
+ 1. Set |transition|'s [=ViewTransition/DOM update callback=] to [=callback= ] .
472
472
473
473
1. Let |document| be [=this's=] [=relevant global object's=] [=associated document=] .
474
474
@@ -496,10 +496,8 @@ callback UpdateDOMCallback = Promise<any> ();
496
496
and a single line of script to start it:
497
497
498
498
<pre highlight=js>
499
- document.createTransition({
500
- updateDOM() {
501
- coolFramework.changeTheDOMToPageB();
502
- }
499
+ document.startViewTransition(async () => {
500
+ coolFramework.changeTheDOMToPageB();
503
501
});
504
502
</pre>
505
503
@@ -513,22 +511,20 @@ callback UpdateDOMCallback = Promise<any> ();
513
511
// the transitioning pseudo-element.
514
512
document.querySelector('.old-message' ).style.pageTransitionTag = 'message' ;
515
513
516
- const transition = document.createTransition({
517
- async updateDOM() {
518
- // This callback is invoked by the browser when "outgoing"
519
- // capture finishes and the DOM can be switched to the new
520
- // state. No frames are rendered until this callback returns.
521
-
522
- // DOM changes may be asynchronous
523
- await coolFramework.changeTheDOMToPageB();
524
-
525
- // Tagging elements during the updateDOM() callback marks them as
526
- // "incoming", to be matched up with the same-tagged "outgoing"
527
- // elements marked previously and transitioned between.
528
- document.querySelector('.new-message' ).style.pageTransitionTag =
529
- 'message' ;
530
- },
531
- });
514
+ const transition = document.startViewTransition(async () => {
515
+ // This callback is invoked by the browser when "outgoing"
516
+ // capture finishes and the DOM can be switched to the new
517
+ // state. No frames are rendered until this callback returns.
518
+
519
+ // DOM changes may be asynchronous
520
+ await coolFramework.changeTheDOMToPageB();
521
+
522
+ // Tagging elements during the callback marks them as
523
+ // "incoming", to be matched up with the same-tagged "outgoing"
524
+ // elements marked previously and transitioned between.
525
+ document.querySelector('.new-message' ).style.pageTransitionTag =
526
+ 'message' ;
527
+ });
532
528
533
529
// When ready resolves, all pseudo-elements for this transition have
534
530
// been generated.
@@ -759,7 +755,7 @@ The {{ViewTransition/domUpdated}} [=getter steps=] are to return [=this's=] [=Vi
759
755
760
756
1. [=Skip the page transition=] |transition| with a "{{TimeoutError}} " {{DOMException}} .
761
757
762
- * If the promise was fulfilled , then:
758
+ * If the promise was resolved , then:
763
759
764
760
1. If |transition|'s [=ViewTransition/phase=] is "`done`", then return.
765
761
@@ -1121,13 +1117,17 @@ The {{ViewTransition/domUpdated}} [=getter steps=] are to return [=this's=] [=Vi
1121
1117
1122
1118
1. [=Assert=] : |transition|'s [=ViewTransition/phase=] is [=phases/before=] "`dom-update-callback-called`".
1123
1119
1124
- 1. Let |callbackPromise| be the result of [=/invoking=] |transition|'s [=ViewTransition/DOM update callback=] .
1120
+ 1. Let |callbackPromise| be [=a new promise=] in |transition|'s [=relevant Realm=] .
1121
+
1122
+ * If |transition|'s [=ViewTransition/DOM update callback=] is null, then resolve |callbackPromise|.
1123
+
1124
+ * Otherwise, let |callbackPromise| be the result of [=/invoking=] |transition|'s [=ViewTransition/DOM update callback=] .
1125
1125
1126
1126
1. Set |transition|'s [=ViewTransition/phase=] to "`dom-update-callback-called`".
1127
1127
1128
1128
1. [=promise/React=] to |callbackPromise|:
1129
1129
1130
- * If |callbackPromise| was fulfilled , then [=resolve=] |transition|'s [=ViewTransition/DOM updated promise=] .
1130
+ * If |callbackPromise| was resolved , then [=resolve=] |transition|'s [=ViewTransition/DOM updated promise=] .
1131
1131
1132
1132
* If |callbackPromise| was rejected with reason |r|, then [=reject=] |transition|'s [=ViewTransition/DOM updated promise=] with |r|.
1133
1133
0 commit comments