@@ -123,14 +123,13 @@ Note that because these APIs are an enhancement to the DOM change, some principl
123123 href="https://wicg.github.io/navigation-api/#navigate-event-class"> `signal`
124124 on `NavigateEvent`</a> is an example of a feature developers could use to
125125 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.
134133
135134# CSS properties # {#css-properties}
136135
@@ -449,26 +448,27 @@ A {{Document}} additionally has:
449448
450449<script type=idl>
451450partial interface Document {
452- ViewTransition createTransition(ViewTransitionInit init);
453- };
454-
455- dictionary ViewTransitionInit {
456- required UpdateDOMCallback updateDOM;
451+ ViewTransition startViewTransition(optional UpdateDOMCallback? callback = null);
457452};
458453
459454callback UpdateDOMCallback = Promise<any> ();
460455</script>
461456
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}
463463
464464<div algorithm>
465465 The [=method steps=] for
466- <dfn method for=Document>createTransition(|init| )</dfn>
466+ <dfn method for=Document>startViewTransition([=callback=] )</dfn>
467467 are as follows:
468468
469469 1. Let |transition| be a new {{ViewTransition}} object in [=this's=] [=relevant Realm=] .
470470
471- 1. Set |transition|'s [=ViewTransition/DOM update callback=] to |init| [{{ViewTransitionInit/updateDOM}} ] .
471+ 1. Set |transition|'s [=ViewTransition/DOM update callback=] to [=callback= ] .
472472
473473 1. Let |document| be [=this's=] [=relevant global object's=] [=associated document=] .
474474
@@ -496,10 +496,8 @@ callback UpdateDOMCallback = Promise<any> ();
496496 and a single line of script to start it:
497497
498498 <pre highlight=js>
499- document.createTransition({
500- updateDOM() {
501- coolFramework.changeTheDOMToPageB();
502- }
499+ document.startViewTransition(async () => {
500+ coolFramework.changeTheDOMToPageB();
503501 });
504502 </pre>
505503
@@ -513,22 +511,20 @@ callback UpdateDOMCallback = Promise<any> ();
513511 // the transitioning pseudo-element.
514512 document.querySelector('.old-message' ).style.pageTransitionTag = 'message' ;
515513
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+ });
532528
533529 // When ready resolves, all pseudo-elements for this transition have
534530 // been generated.
@@ -759,7 +755,7 @@ The {{ViewTransition/domUpdated}} [=getter steps=] are to return [=this's=] [=Vi
759755
760756 1. [=Skip the page transition=] |transition| with a "{{TimeoutError}} " {{DOMException}} .
761757
762- * If the promise was fulfilled , then:
758+ * If the promise was resolved , then:
763759
764760 1. If |transition|'s [=ViewTransition/phase=] is "`done`", then return.
765761
@@ -1121,13 +1117,17 @@ The {{ViewTransition/domUpdated}} [=getter steps=] are to return [=this's=] [=Vi
11211117
11221118 1. [=Assert=] : |transition|'s [=ViewTransition/phase=] is [=phases/before=] "`dom-update-callback-called`".
11231119
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=] .
11251125
11261126 1. Set |transition|'s [=ViewTransition/phase=] to "`dom-update-callback-called`".
11271127
11281128 1. [=promise/React=] to |callbackPromise|:
11291129
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=] .
11311131
11321132 * If |callbackPromise| was rejected with reason |r|, then [=reject=] |transition|'s [=ViewTransition/DOM updated promise=] with |r|.
11331133
0 commit comments