@superwall/cli 1.6.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +281 -34
  2. package/dist/apple-CkKlHBZ9.js +195 -0
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-H7f6knyY.js → billing-XCZU_T46.js} +98 -28
  6. package/dist/{bind-BIzaGq8K.js → bind-drne__Ys.js} +38 -33
  7. package/dist/{build-B7BS1rF2.js → build-Gpdq5QXP.js} +20 -26
  8. package/dist/client-BZ1UbpXz.js +66 -0
  9. package/dist/client-DP6Rc0t_.js +176 -0
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BBrtgUgS.js +969 -0
  12. package/dist/{create-CwnnNqv4.js → create-Cwc3SRWJ.js} +194 -168
  13. package/dist/create-Yvf2gStM.js +19 -0
  14. package/dist/doctor-C9ldpPFC.js +83 -0
  15. package/dist/{drivers-6RMOPIdn.js → drivers-DNrx4LWA.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28083 -801
  18. package/dist/environment-DF1qKlny.js +58 -0
  19. package/dist/{existing-DHpPn1y6.js → existing-78LWSsqS.js} +12 -6
  20. package/dist/held-Cy8Wl4D1.js +1112 -0
  21. package/dist/held-Ddw1XSsr.js +16 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-BR2LR-EK.js → integrate-DcJhpXy8.js} +277 -253
  24. package/dist/kinds-GFXB3sYu.js +11 -0
  25. package/dist/log-NVhVe_oe.js +62 -0
  26. package/dist/login-B2TsCE2H.js +53 -0
  27. package/dist/login-BoBe8Psl.js +16 -0
  28. package/dist/{login-Bhxgqwtm.js → login-D0lh3_JI.js} +144 -66
  29. package/dist/lookup-D-nmmAbw.js +71 -0
  30. package/dist/migrate-Cfec564E.js +274 -0
  31. package/dist/notification-url-YDbq6FMA.js +100 -0
  32. package/dist/{open-studio-BnVD6tJ9.js → open-Ba2vBl1_.js} +34 -43
  33. package/dist/org-D0g_q3mv.js +35 -0
  34. package/dist/output-Ggzq5_-t.js +122 -0
  35. package/dist/paths-DxSLdpOI.js +29 -0
  36. package/dist/playbook-DIeb7hne.js +53 -0
  37. package/dist/{asc-products-Dvcyef3_.js → products-DH_fK9tY.js} +6 -39
  38. package/dist/promote-COD4fYdz.js +91 -0
  39. package/dist/push-CncywhkQ.js +482 -0
  40. package/dist/push-CtD4FZQV.js +22 -0
  41. package/dist/registry-DSrosOYs.js +10228 -0
  42. package/dist/{reports-DqMs9xNR.js → reports-DdPq4blM.js} +7 -6
  43. package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
  44. package/dist/{run-D-NbZLpj.js → run-C9qg_QlC.js} +16 -22
  45. package/dist/scan-Cv5uOwVY.js +4 -0
  46. package/dist/{scan-BmAW413l.js → scan-DLrsrFS9.js} +48 -37
  47. package/dist/scope-V336uz8j.js +198 -0
  48. package/dist/screenshot-file-0UETadF8.js +16 -0
  49. package/dist/{selection-BGi6GyxC.js → selection-Rdw-ZUoG.js} +94 -51
  50. package/dist/send-BxD9yf6F.js +150 -0
  51. package/dist/{dev-CgGAb5Al.js → server-D0tGG8C4.js} +82 -87
  52. package/dist/server-z1LH94R_.js +22 -0
  53. package/dist/session-1AV_Bs_d.js +6 -0
  54. package/dist/session-CFAmMhem.js +40 -0
  55. package/dist/session-D_nEWKXT.js +768 -0
  56. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  57. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  58. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  59. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  60. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  61. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  62. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  63. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  64. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  65. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  66. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  67. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  68. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  69. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  71. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  72. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  73. package/dist/skills/index.json +37 -0
  74. package/dist/skills/mobile-design/SKILL.md +447 -0
  75. package/dist/skills/mobile-design/references/responsive.md +162 -0
  76. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  77. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  78. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  79. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  80. package/dist/skills/superwall/SKILL.md +82 -9
  81. package/dist/skills/superwall/references/api.md +153 -37
  82. package/dist/skills/superwall/references/apple-setup.md +316 -0
  83. package/dist/skills/superwall/references/asc.md +74 -38
  84. package/dist/skills/superwall/references/data-analytics.md +55 -21
  85. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  86. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  87. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  88. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  89. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  90. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  91. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  96. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  97. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  98. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  99. package/dist/skills/superwall-editor/SKILL.md +61 -0
  100. package/dist/skills/superwall-editor/references/cli.md +135 -0
  101. package/dist/skills/superwall-editor/references/design.md +51 -0
  102. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  103. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  104. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  105. package/dist/skills/superwall-framework/SKILL.md +78 -28
  106. package/dist/skills/superwall-framework/references/cli.md +58 -28
  107. package/dist/skills/superwall-framework/references/examples.md +4 -3
  108. package/dist/skills/superwall-framework/references/layout.md +30 -8
  109. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  110. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  111. package/dist/skills/wwdc/SKILL.md +22 -0
  112. package/dist/skills/wwdc/references/docs.md +52 -0
  113. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  114. package/dist/{skills-AxAf7bDB.js → skills-BvFOa4y6.js} +99 -122
  115. package/dist/skills-DMG4bpKk.js +14 -0
  116. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  117. package/dist/spinner-CneRK5rk.js +294 -0
  118. package/dist/storage-DYvmIOHa.d.ts +16 -0
  119. package/dist/storage-s2Dnz-yl.js +31 -0
  120. package/dist/storekit-DafAnGkM.js +16 -0
  121. package/dist/storekit-yY_kS2iR.js +47 -0
  122. package/dist/telemetry-DtG92m5O.js +56 -0
  123. package/dist/theme-DUsCh-Vd.js +25 -0
  124. package/dist/timing-BVxPrYq3.js +5 -0
  125. package/dist/{token-BGAVPSQc.js → token-DzRh7dI1.js} +6 -38
  126. package/dist/tools.d.ts +96 -0
  127. package/dist/tools.js +11178 -0
  128. package/dist/ui-D_qf3Gvw.js +53 -0
  129. package/dist/upgrade-Bt4Ouw1y.js +117 -0
  130. package/dist/upgrade-Cqy5orjb.js +7 -0
  131. package/package.json +10 -5
  132. package/dist/api-Dv3LyZ5m.js +0 -151
  133. package/dist/api-output-aJNw7Syy.js +0 -20
  134. package/dist/app-mJC5NDtW.js +0 -189
  135. package/dist/asa-D6H7Pjae.js +0 -1194
  136. package/dist/asc-xCin0akG.js +0 -539
  137. package/dist/auth-ZlLL-Gko.js +0 -139
  138. package/dist/billing-C8kBge_S.js +0 -80
  139. package/dist/command-3fGYyC8r.js +0 -301
  140. package/dist/dev-Dx99K183.js +0 -22
  141. package/dist/doctor-CyUvut31.js +0 -88
  142. package/dist/feedback-RKyGuQ8_.js +0 -152
  143. package/dist/hosted-BeGVAntr.js +0 -32
  144. package/dist/migrate-C-4ISELN.js +0 -284
  145. package/dist/org-CQduIOic.js +0 -40
  146. package/dist/output-C-4UKMot.js +0 -136
  147. package/dist/params-l3CrvRtR.js +0 -51
  148. package/dist/pipeline-CHX0Syre.js +0 -977
  149. package/dist/print-skill-BiZLdCKv.js +0 -74
  150. package/dist/promote-Pgpz-3xl.js +0 -88
  151. package/dist/publish-BPeuc3lq.js +0 -35
  152. package/dist/push-DcSQ4odB.js +0 -35
  153. package/dist/query-CWLaZkdm.js +0 -53
  154. package/dist/resource-jwASPCrw.js +0 -483
  155. package/dist/skills-FK5aDuNV.js +0 -64
  156. package/dist/spinner-DFctF_Jw.js +0 -18
  157. package/dist/storekit-CC4gnTI6.js +0 -29
  158. package/dist/telemetry-Ch9cCTI-.js +0 -169
  159. package/dist/ui-4gLyfrgl.js +0 -27737
  160. package/dist/update-DIXbL-H9.js +0 -59
  161. package/dist/upgrade-De7JMI1g.js +0 -72
  162. /package/dist/{devtools-8EgLo86w.js → devtools-ByZ6XYnn.js} +0 -0
@@ -0,0 +1,869 @@
1
+ // The hand-off engine on the superwall framework's router.
2
+ //
3
+ // What the router already does: every page is an absolute layer inside [data-sw-routes]; the page
4
+ // being left stays mounted with data-sw-phase="recede" (forward) or "leave" (back) for as long as
5
+ // the animation declared on it runs, and the arriving page carries "enter" or "return". So there is
6
+ // no clone of the leaving page here: its exit and the new page's entrance are CSS in motion.css,
7
+ // keyed on the transition name (`story-<handoff>`) and the phase. This script does only what CSS
8
+ // can't: the shared elements that travel BETWEEN the two pages — the chosen answer flying into the
9
+ // progress bar (fly / flyBack), an answer opening into the next page's photo or into a statement's
10
+ // full-screen colour, and that colour collapsing into the bar (morphFrame.ts, one frame two faces).
11
+ //
12
+ // Copies are pinned inside the layout's motion layer ([data-motion-layer], position: absolute over
13
+ // the content box), never position: fixed: the framework's insets rule, and on a web funnel the
14
+ // iOS 26 toolbar-tint sentinel must stay the only fixed element.
15
+ //
16
+ // Only transform and opacity animate, plus the morph frame's clip-path and its 5px motion blur, on
17
+ // one element at a time.
18
+
19
+ import { flushSync } from "react-dom";
20
+ import type { Handoff } from "../flow";
21
+ import { decodedCopy, imageSize, isImageReady, releaseDecoded } from "./imageReady";
22
+ import {
23
+ colorFace,
24
+ fillFace,
25
+ glideAt,
26
+ lerp,
27
+ morph,
28
+ MORPH_STEPS,
29
+ motionBlur,
30
+ photoFace,
31
+ roundness,
32
+ } from "./morphFrame";
33
+ import type { Box, Face } from "./morphFrame";
34
+
35
+ export type HandoffName = Handoff | "plain";
36
+ export type HandoffDirection = "next" | "back";
37
+
38
+ const EASE_OUT = "cubic-bezier(0.23, 1, 0.32, 1)";
39
+ const EASE_IN_OUT = "cubic-bezier(0.77, 0, 0.175, 1)";
40
+
41
+ let lastInput: "pointer" | "keyboard" = "pointer";
42
+ let listening = false;
43
+
44
+ function listenForInputKind() {
45
+ if (listening || typeof window === "undefined") return;
46
+ listening = true;
47
+ window.addEventListener("pointerdown", () => (lastInput = "pointer"), {
48
+ capture: true,
49
+ passive: true,
50
+ });
51
+ window.addEventListener("keydown", () => (lastInput = "keyboard"), {
52
+ capture: true,
53
+ passive: true,
54
+ });
55
+ }
56
+
57
+ /** Keyboard navigation is repeated and deliberate, and reduced motion asks for less: both get a plain fade. */
58
+ export function handoffMode(): "story" | "plain" {
59
+ listenForInputKind();
60
+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "plain";
61
+ return lastInput === "keyboard" ? "plain" : "story";
62
+ }
63
+
64
+ type Point = { x: number; y: number };
65
+
66
+ const q = (root: ParentNode | null, selector: string) =>
67
+ root?.querySelector<HTMLElement>(selector) ?? null;
68
+ const qa = (root: ParentNode | null, selector: string) =>
69
+ Array.from(root?.querySelectorAll<HTMLElement>(selector) ?? []);
70
+ const centre = (r: DOMRect): Point => ({ x: r.left + r.width / 2, y: r.top + r.height / 2 });
71
+ /** An <img> that hasn't loaded has no height yet: nothing to morph into. */
72
+ const loaded = (img: HTMLImageElement | null): boolean =>
73
+ img !== null && img.complete && img.naturalWidth > 0;
74
+
75
+ const easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);
76
+ /** Overshoots its target by ~12% and settles back. */
77
+ const easeOutBack = (t: number) => {
78
+ const c1 = 2;
79
+ return 1 + (c1 + 1) * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
80
+ };
81
+
82
+ /** Every A → B transform (answer → bar, answer ↔ photo, colour → bar) runs this long, so none feels slower. */
83
+ const TRANSFORM_MS = 504;
84
+ const FLIGHT_MS = TRANSFORM_MS;
85
+ /** The answer's right edge reaches the bar's end at 55%; the rest is the two growing together. */
86
+ const JOIN = 0.55;
87
+ /** Sampled timeline; STEPS * JOIN is whole so a keyframe sits exactly on the join. */
88
+ const STEPS = 40;
89
+ /** The photo's resting corner radius (theme.css .hero). */
90
+ const PHOTO_RADIUS = 20;
91
+
92
+ /**
93
+ * Keeps a live destination out of sight while its copy transforms into it, and hands over on the
94
+ * last frame. 0.001, not 0: a browser doesn't paint a fully transparent element, so one revealed
95
+ * only on the last frame shows a frame of nothing. At 0.001 it's painted, yet invisible.
96
+ */
97
+ const REVEAL_UNDER_COPY: Keyframe[] = [{ opacity: 0.001 }, { opacity: 0.001 }];
98
+
99
+ // The previous hand-off's leftovers, so a quick second tap can finish it instantly.
100
+ let running: Animation[] = [];
101
+ // Only what the copies' removal waits for: the copies' own animations and the live destinations'
102
+ // REVEAL_UNDER_COPY holds. Never the new page's entrances (CSS): a copy that waited for them would
103
+ // sit over them for their whole duration.
104
+ let handovers: Animation[] = [];
105
+ let clones: HTMLElement[] = [];
106
+ // Elements of the leaving page hidden while a copy stands in for them; restored when the copies go
107
+ // (the page stays mounted, and comes back when the user goes back).
108
+ let hidden: HTMLElement[] = [];
109
+ // Animations on the leaving page's own elements that must not outlive the hand-off (the page stays
110
+ // mounted and comes back on Back): held at their end frame until the copies go, then cancelled.
111
+ let parked: Animation[] = [];
112
+ // The progress fill whose CSS transition is paused while an answer carries the bar.
113
+ let heldFill: HTMLElement | null = null;
114
+
115
+ function releaseFill() {
116
+ if (heldFill) heldFill.style.transition = "";
117
+ heldFill = null;
118
+ }
119
+
120
+ function settlePrevious() {
121
+ // A cancelled (parked) animation is idle: finishing it would replay its end frame.
122
+ running.forEach((a) => a.playState !== "idle" && a.finish());
123
+ running = [];
124
+ handovers = [];
125
+ clones.forEach((c) => c.remove());
126
+ clones = [];
127
+ hidden.forEach((el) => (el.style.visibility = ""));
128
+ hidden = [];
129
+ parked.forEach((a) => a.cancel());
130
+ parked = [];
131
+ releaseDecoded();
132
+ releaseFill();
133
+ }
134
+
135
+ /** The layout's motion layer and its screen rect: every copy is placed at `rect - origin` inside it. */
136
+ function layerOf() {
137
+ const into = q(document, "[data-motion-layer]");
138
+ if (!into) return null;
139
+ const r = into.getBoundingClientRect();
140
+ return { into, origin: { left: r.left, top: r.top } };
141
+ }
142
+
143
+ /** A copy of `el` pinned where it is on screen, inside the motion layer, for a flight to animate. */
144
+ function pin(el: HTMLElement, layer: NonNullable<ReturnType<typeof layerOf>>): HTMLElement {
145
+ const r = el.getBoundingClientRect();
146
+ const clone = el.cloneNode(true) as HTMLElement;
147
+ // A cloned <img> reloads, and Safari paints nothing until it has: swap in the decoded image.
148
+ const originals = el.querySelectorAll("img");
149
+ clone.querySelectorAll("img").forEach((img, i) => img.replaceWith(decodedCopy(originals[i])));
150
+ clone.setAttribute("aria-hidden", "true");
151
+ clone.setAttribute("data-handoff-clone", "");
152
+ Object.assign(clone.style, {
153
+ position: "absolute",
154
+ left: `${r.left - layer.origin.left}px`,
155
+ top: `${r.top - layer.origin.top}px`,
156
+ width: `${r.width}px`,
157
+ height: `${r.height}px`,
158
+ margin: "0",
159
+ zIndex: "32",
160
+ pointerEvents: "none",
161
+ animation: "none",
162
+ transition: "none",
163
+ });
164
+ layer.into.appendChild(clone);
165
+ clones.push(clone);
166
+ return clone;
167
+ }
168
+
169
+ /** A plain pill in the bar's colour, pinned at `rect` inside the layer: the bar's tip in flight. */
170
+ function slugAt(
171
+ rect: DOMRect,
172
+ layer: NonNullable<ReturnType<typeof layerOf>>,
173
+ color: string,
174
+ ): HTMLElement {
175
+ const slug = document.createElement("div");
176
+ slug.setAttribute("aria-hidden", "true");
177
+ slug.setAttribute("data-handoff-clone", "");
178
+ Object.assign(slug.style, {
179
+ position: "absolute",
180
+ left: `${rect.left - layer.origin.left}px`,
181
+ top: `${rect.top - layer.origin.top}px`,
182
+ width: `${rect.width}px`,
183
+ height: `${rect.height}px`,
184
+ borderRadius: "999px",
185
+ background: color,
186
+ transformOrigin: "100% 50%",
187
+ zIndex: "31",
188
+ pointerEvents: "none",
189
+ });
190
+ layer.into.appendChild(slug);
191
+ clones.push(slug);
192
+ return slug;
193
+ }
194
+
195
+ function hide(el: HTMLElement | null | undefined) {
196
+ if (!el) return;
197
+ el.style.visibility = "hidden";
198
+ hidden.push(el);
199
+ }
200
+
201
+ function animate(
202
+ el: Element | null | undefined,
203
+ keyframes: Keyframe[],
204
+ options: KeyframeAnimationOptions,
205
+ ) {
206
+ if (!el) return;
207
+ const animation = el.animate(keyframes, { fill: "both", easing: EASE_OUT, ...options });
208
+ running.push(animation);
209
+ if (keyframes === REVEAL_UNDER_COPY || el.closest("[data-handoff-clone]"))
210
+ handovers.push(animation);
211
+ return animation;
212
+ }
213
+
214
+ /** `animate` for a live element of the leaving page: held at its end until the hand-off is over, then released. */
215
+ function park(
216
+ el: Element | null | undefined,
217
+ keyframes: Keyframe[],
218
+ options: KeyframeAnimationOptions,
219
+ ) {
220
+ const animation = animate(el, keyframes, { ...options, fill: "forwards" });
221
+ if (animation) parked.push(animation);
222
+ }
223
+
224
+ /**
225
+ * The chosen answer becomes the bar's leading edge: it shrinks around its right edge while that
226
+ * edge flies to where the bar currently ends — same colour, same height. On that frame they join,
227
+ * then grow together to the new length: the answer is what pushes the bar forward, not a timer.
228
+ */
229
+ function fly({
230
+ capsule,
231
+ track,
232
+ fill,
233
+ lo,
234
+ hi,
235
+ answerClone,
236
+ layer,
237
+ }: {
238
+ capsule: DOMRect;
239
+ track: DOMRect;
240
+ fill: HTMLElement;
241
+ /** Progress before this step: where the answer joins the bar. */
242
+ lo: number;
243
+ /** Progress after this step. */
244
+ hi: number;
245
+ answerClone: HTMLElement;
246
+ layer: NonNullable<ReturnType<typeof layerOf>>;
247
+ }) {
248
+ const loX = track.left + track.width * lo;
249
+ const hiX = track.left + track.width * hi;
250
+ // The pill lands as the bar's tip: right edge on the bar's end, one step long (inside the fill).
251
+ const width = Math.max(track.height, Math.min(hiX - loX, loX - track.left));
252
+ const land = new DOMRect(Math.max(track.left, loX - width), track.top, width, track.height);
253
+ const slug = slugAt(land, layer, getComputedStyle(fill).backgroundColor);
254
+ answerClone.style.transformOrigin = "100% 50%";
255
+
256
+ // Everything is placed by its right edge: the answer's, then the bar's.
257
+ const a: Point = { x: capsule.right, y: capsule.top + capsule.height / 2 };
258
+ const b: Point = { x: land.right, y: land.top + land.height / 2 };
259
+ const sx0 = capsule.width / land.width;
260
+ const sy0 = capsule.height / land.height;
261
+ // Rising and drifting left together, the rise leading and finishing first (~87% across), then a
262
+ // short level entry into the bar's end.
263
+ const riseAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f / 0.75)));
264
+ const slideAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f)));
265
+
266
+ const slugFrames: Keyframe[] = [];
267
+ const capsuleFrames: Keyframe[] = [];
268
+ const fillFrames: Keyframe[] = [];
269
+ for (let i = 0; i <= STEPS; i++) {
270
+ const p = i / STEPS;
271
+ const f = p <= JOIN ? p / JOIN : 1;
272
+ const g = p <= JOIN ? 0 : easeOutBack((p - JOIN) / (1 - JOIN));
273
+ const e = riseAt(f);
274
+ const x = a.x + (b.x - a.x) * slideAt(f) + (hiX - loX) * g;
275
+ const y = a.y + (b.y - a.y) * e;
276
+ const sx = Math.pow(sx0, 1 - e);
277
+ const sy = Math.pow(sy0, 1 - e);
278
+ // The capsule is translucent, the bar opaque: the pill deepens in flight and is exactly the
279
+ // bar's colour before it joins; nothing about the bar changes while it grows.
280
+ const tone = 0.9 + 0.1 * Math.min(1, e / 0.9);
281
+ slugFrames.push({
282
+ offset: p,
283
+ transform: `translate3d(${x - b.x}px, ${y - b.y}px, 0) scale(${sx}, ${sy})`,
284
+ opacity: tone,
285
+ });
286
+ fillFrames.push({ offset: p, transform: `translateX(${(lo + (hi - lo) * g - 1) * 100}%)` });
287
+ capsuleFrames.push({
288
+ offset: p,
289
+ transform: `translate3d(${x - a.x}px, ${y - a.y}px, 0) scale(${sx / sx0}, ${sy / sy0})`,
290
+ // Its words and fill go first, over the pill.
291
+ opacity: Math.max(0, 1 - p / 0.13),
292
+ });
293
+ }
294
+
295
+ animate(slug, slugFrames, { duration: FLIGHT_MS, easing: "linear" });
296
+ animate(fill, fillFrames, { duration: FLIGHT_MS, easing: "linear", fill: "none" });
297
+ animate(answerClone, capsuleFrames, { duration: FLIGHT_MS, easing: "linear" });
298
+ }
299
+
300
+ /**
301
+ * Going back, the answer comes back out of the bar: not the flight rewound (a direction flip
302
+ * mid-motion) but its own move on the A → B clock. The pill starts as exactly the stretch of bar
303
+ * this answer earned and takes it with it, slides out along the bar, drops and grows into the
304
+ * answer, and hands over to a copy of the answer travelling the same path; the live answer takes
305
+ * over on the last frame.
306
+ */
307
+ function flyBack({
308
+ capsule,
309
+ track,
310
+ fill,
311
+ lo,
312
+ hi,
313
+ answerClone,
314
+ liveAnswer,
315
+ layer,
316
+ }: {
317
+ capsule: DOMRect;
318
+ track: DOMRect;
319
+ fill: HTMLElement;
320
+ /** Progress after this step (where the bar ends once the answer has left it). */
321
+ lo: number;
322
+ /** Progress before this step. */
323
+ hi: number;
324
+ answerClone: HTMLElement;
325
+ liveAnswer: HTMLElement;
326
+ layer: NonNullable<ReturnType<typeof layerOf>>;
327
+ }) {
328
+ const duration = TRANSFORM_MS;
329
+ const loX = track.left + track.width * lo;
330
+ const hiX = track.left + track.width * hi;
331
+ const seg = new DOMRect(loX, track.top, Math.max(track.height, hiX - loX), track.height);
332
+ const slug = slugAt(seg, layer, getComputedStyle(fill).backgroundColor);
333
+ answerClone.style.transformOrigin = "100% 50%";
334
+
335
+ const b: Point = { x: seg.right, y: seg.top + seg.height / 2 };
336
+ const a: Point = { x: capsule.right, y: capsule.top + capsule.height / 2 };
337
+ const sx0 = capsule.width / seg.width;
338
+ const sy0 = capsule.height / seg.height;
339
+ // Level for the first quarter (sliding out along the bar), then curving down to arrive at the
340
+ // same rate it goes across, so it lands along its line of travel.
341
+ const up = (s: number) => (s >= 0.75 ? 1 : s + 2.6667 * s * s - 2.963 * s * s * s);
342
+
343
+ const slugFrames: Keyframe[] = [];
344
+ const copyFrames: Keyframe[] = [];
345
+ let handedOver = false;
346
+ for (let i = 0; i <= MORPH_STEPS; i++) {
347
+ const t = i / MORPH_STEPS;
348
+ const s = 1 - glideAt(t);
349
+ const u = up(s);
350
+ const x = a.x + (b.x - a.x) * s;
351
+ const y = a.y + (b.y - a.y) * u;
352
+ const sx = 1 + (sx0 - 1) * (1 - u);
353
+ const sy = 1 + (sy0 - 1) * (1 - u);
354
+ const slugTransform = `translate3d(${x - b.x}px, ${y - b.y}px, 0) scale(${sx}, ${sy})`;
355
+ const copyTransform = `translate3d(${x - a.x}px, ${y - a.y}px, 0) scale(${sx / sx0}, ${sy / sy0})`;
356
+ const tone = 1 - 0.1 * Math.min(1, Math.max(0, 1 - u));
357
+ // Hand over from the pill to the answer's copy in one frame, not a crossfade: by 90% of the way
358
+ // the pill is the answer's colour and shape, so the swap is invisible.
359
+ const past = 1 - s >= 0.9;
360
+ if (past && !handedOver) {
361
+ handedOver = true;
362
+ slugFrames.push({ offset: t, transform: slugTransform, opacity: tone });
363
+ copyFrames.push({ offset: t, transform: copyTransform, opacity: 0 });
364
+ }
365
+ slugFrames.push({ offset: t, transform: slugTransform, opacity: past ? 0 : tone });
366
+ copyFrames.push({ offset: t, transform: copyTransform, opacity: past ? 1 : 0 });
367
+ }
368
+
369
+ animate(slug, slugFrames, { duration, easing: "linear" });
370
+ animate(answerClone, copyFrames, { duration, easing: "linear" });
371
+ // The label comes back last, on the travelling copy.
372
+ qa(answerClone, "span").forEach((label) =>
373
+ animate(label, [{ opacity: 0 }, { offset: 0.8, opacity: 0 }, { opacity: 1 }], {
374
+ duration,
375
+ easing: "linear",
376
+ }),
377
+ );
378
+ // Hidden while something transforms into it; takes over on the last frame, exactly where the copy ends.
379
+ animate(liveAnswer, REVEAL_UNDER_COPY, { duration, easing: "linear", fill: "backwards" });
380
+ }
381
+
382
+ /** The stretch of progress bar between two fractions, in screen space (at least as long as it's tall). */
383
+ function barSegment(track: DOMRect, from: number, to: number): DOMRect {
384
+ const lo = Math.min(from, to);
385
+ const hi = Math.max(from, to);
386
+ return new DOMRect(
387
+ track.left + track.width * lo,
388
+ track.top,
389
+ Math.max(track.height, track.width * (hi - lo)),
390
+ track.height,
391
+ );
392
+ }
393
+
394
+ /**
395
+ * Any shape into the progress bar exactly the way an answer pill goes, as a morph path: right edge
396
+ * to the bar's current end while shrinking to the bar's height, join, grow together, bounce. Through
397
+ * the one-geometry frame, so a full-screen colour is never stretched: its corners go from its own
398
+ * roundness to a fully round pill. Also returns the bar's keyframes (hold, then grow with the shape).
399
+ */
400
+ function intoBarPath(
401
+ source: DOMRect,
402
+ sourceRadius: number,
403
+ track: DOMRect,
404
+ lo: number,
405
+ hi: number,
406
+ ) {
407
+ const loX = track.left + track.width * lo;
408
+ const hiX = track.left + track.width * hi;
409
+ const width = Math.max(track.height, Math.min(hiX - loX, loX - track.left));
410
+ const land = new DOMRect(Math.max(track.left, loX - width), track.top, width, track.height);
411
+ const a: Point = { x: source.right, y: source.top + source.height / 2 };
412
+ const b: Point = { x: land.right, y: land.top + land.height / 2 };
413
+ const riseAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f / 0.75)));
414
+ const slideAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f)));
415
+ const fromRound = roundness(sourceRadius, source.width, source.height);
416
+ const phase = (t: number) => ({
417
+ f: t <= JOIN ? t / JOIN : 1,
418
+ g: t <= JOIN ? 0 : easeOutBack((t - JOIN) / (1 - JOIN)),
419
+ });
420
+ const path = (t: number): Box => {
421
+ const { f, g } = phase(t);
422
+ const e = riseAt(f);
423
+ const w = Math.exp(lerp(Math.log(source.width), Math.log(land.width), e));
424
+ const h = Math.exp(lerp(Math.log(source.height), Math.log(land.height), e));
425
+ const right = a.x + (b.x - a.x) * slideAt(f) + (hiX - loX) * g;
426
+ return {
427
+ cx: right - w / 2,
428
+ cy: a.y + (b.y - a.y) * e,
429
+ w,
430
+ h,
431
+ r: lerp(fromRound, 0.5, e) * Math.min(w, h),
432
+ };
433
+ };
434
+ const fillFrames: Keyframe[] = Array.from({ length: STEPS + 1 }, (_, i) => {
435
+ const t = i / STEPS;
436
+ return { offset: t, transform: `translateX(${(lo + (hi - lo) * phase(t).g - 1) * 100}%)` };
437
+ });
438
+ return { path, fillFrames, to: land };
439
+ }
440
+
441
+ /**
442
+ * Out of the progress bar into any shape, the way an answer comes back out: the stretch of bar
443
+ * slides out along it, then drops and grows into the shape by its right edge, on the A → B clock.
444
+ */
445
+ function outOfBarPath(dest: DOMRect, destRadius: number, track: DOMRect, lo: number, hi: number) {
446
+ const seg = barSegment(track, lo, hi);
447
+ const b: Point = { x: seg.right, y: seg.top + seg.height / 2 };
448
+ const a: Point = { x: dest.right, y: dest.top + dest.height / 2 };
449
+ const up = (s: number) => (s >= 0.75 ? 1 : s + 2.6667 * s * s - 2.963 * s * s * s);
450
+ const toRound = roundness(destRadius, dest.width, dest.height);
451
+ const path = (t: number): Box => {
452
+ const s = 1 - glideAt(t);
453
+ const u = up(s);
454
+ const w = seg.width + (dest.width - seg.width) * (1 - u);
455
+ const h = seg.height + (dest.height - seg.height) * (1 - u);
456
+ const right = a.x + (b.x - a.x) * s;
457
+ return {
458
+ cx: right - w / 2,
459
+ cy: a.y + (b.y - a.y) * u,
460
+ w,
461
+ h,
462
+ r: lerp(0.5, toRound, 1 - u) * Math.min(w, h),
463
+ };
464
+ };
465
+ return { path, from: seg };
466
+ }
467
+
468
+ /** Runs a Frame A → Frame B morph (morphFrame.ts) as part of this hand-off. */
469
+ function playMorph(args: Parameters<typeof morph>[0]) {
470
+ const m = morph(args);
471
+ running.push(...m.animations);
472
+ handovers.push(...m.animations);
473
+ clones.push(m.frame);
474
+ return m;
475
+ }
476
+
477
+ const labelOut: Keyframe[] = [{ opacity: 1 }, { offset: 0.15, opacity: 0 }, { opacity: 0 }];
478
+ const labelBack: Keyframe[] = [{ opacity: 0 }, { offset: 0.85, opacity: 0 }, { opacity: 1 }];
479
+
480
+ /**
481
+ * Runs one hand-off: measures the leaving page, swaps the route synchronously (`update` is the
482
+ * router call), measures the arriving page, and plays the shared-element transforms across both.
483
+ * The pages' own exits and entrances are CSS (motion.css), keyed on the router's phase.
484
+ */
485
+ export function runHandoff({
486
+ handoff,
487
+ direction,
488
+ update,
489
+ }: {
490
+ handoff: HandoffName;
491
+ direction: HandoffDirection;
492
+ update: () => void;
493
+ }) {
494
+ settlePrevious();
495
+ const layer = layerOf();
496
+ // The page on top right now is the one being left. Only its live element exists; no clone.
497
+ const oldPage = q(document, '[data-sw-route][data-sw-state="active"] [data-flow-page]');
498
+ if (handoff === "plain" || !layer || !oldPage) {
499
+ flushSync(update);
500
+ return;
501
+ }
502
+
503
+ const forward = direction === "next";
504
+ const oldOptions = qa(oldPage, "[data-flow-option]");
505
+ const oldSelected = oldOptions.find((el) => el.hasAttribute("data-selected")) ?? null;
506
+ const oldSelectedRect = oldSelected?.getBoundingClientRect();
507
+ const oldImage = q(oldPage, "[data-flow-image]");
508
+ const oldImageRect = oldImage?.getBoundingClientRect();
509
+ // A statement's full-screen colour: the destination of `flood`, the source of `absorb`. Measured
510
+ // now, on the page that is about to leave (going forward, absorb) or stay (going back, flood).
511
+ const oldBackdrop = q(oldPage, "[data-flow-backdrop]");
512
+ const oldBackdropRect = oldBackdrop?.getBoundingClientRect();
513
+ const backdropColor = oldBackdrop ? getComputedStyle(oldBackdrop).backgroundColor : "";
514
+ // Answers become progress, except where they open into the next page's image or statement colour.
515
+ const intoImage = handoff === "picture" || handoff === "connect";
516
+ const intoScene = intoImage || handoff === "flood";
517
+ // Faces are captured before the page changes (the photo's first, so it gets the decoded image).
518
+ const photoFaceBack: Face | null =
519
+ !forward && intoImage && oldImage instanceof HTMLImageElement ? photoFace(oldImage) : null;
520
+ const answerFace: Face | null =
521
+ forward && intoScene && oldSelected && oldSelectedRect
522
+ ? fillFace(oldSelected, oldSelectedRect)
523
+ : null;
524
+
525
+ const fill = q(document, "[data-progress-fill]");
526
+ const fromFraction = Number(fill?.dataset.progress ?? 0);
527
+ const answerFlies =
528
+ forward && !intoScene && oldSelected !== null && oldSelectedRect !== undefined && fill !== null;
529
+ let answerClone: HTMLElement | undefined;
530
+ if (answerFlies && oldSelected) {
531
+ answerClone = pin(oldSelected, layer);
532
+ // The live answer stays mounted (the page comes back on Back): hide it under its copy for now.
533
+ hide(oldSelected);
534
+ }
535
+ if (answerFace && oldSelected) hide(oldSelected);
536
+ // The bar moves only when something lands in it (or leaves it), so its own transition steps aside.
537
+ if (fill && (answerFlies || handoff === "absorb" || (!forward && !intoScene))) {
538
+ fill.style.transition = "none";
539
+ heldFill = fill;
540
+ }
541
+
542
+ // Swap the route now, synchronously: the destination exists in the DOM when this returns.
543
+ flushSync(update);
544
+
545
+ const page = q(document, '[data-sw-route][data-sw-state="active"] [data-flow-page]');
546
+ const newImage = q(page, "[data-flow-image]");
547
+ const newSelected = q(page, "[data-flow-option][data-selected]");
548
+ const newBackdrop = q(page, "[data-flow-backdrop]");
549
+ const toFraction = Number(fill?.dataset.progress ?? 0);
550
+ const trackRect = fill?.parentElement?.getBoundingClientRect();
551
+
552
+ const finish = () => {
553
+ const done = handovers;
554
+ const liveImage = newImage instanceof HTMLImageElement && !loaded(newImage) ? newImage : null;
555
+ const photoLoaded = liveImage
556
+ ? Promise.race([
557
+ new Promise<void>((resolve) =>
558
+ liveImage.addEventListener("load", () => resolve(), { once: true }),
559
+ ),
560
+ new Promise<void>((resolve) => window.setTimeout(resolve, 1000)),
561
+ ])
562
+ : Promise.resolve();
563
+ Promise.all([...done.map((a) => a.finished), photoLoaded])
564
+ .catch(() => {})
565
+ .finally(() => {
566
+ if (handovers !== done) return;
567
+ // The same frame the live destinations reach full opacity: no gap, no double layer.
568
+ clones.forEach((c) => c.remove());
569
+ clones = [];
570
+ handovers = [];
571
+ hidden.forEach((el) => (el.style.visibility = ""));
572
+ hidden = [];
573
+ parked.forEach((a) => a.cancel());
574
+ parked = [];
575
+ releaseDecoded();
576
+ releaseFill();
577
+ });
578
+ };
579
+
580
+ // ---- forward: the answer becomes the progress (every question page, unless it opens into a scene)
581
+ if (answerFlies && fill && trackRect && oldSelectedRect && answerClone) {
582
+ fly({
583
+ capsule: oldSelectedRect,
584
+ track: trackRect,
585
+ fill,
586
+ lo: fromFraction,
587
+ hi: toFraction,
588
+ answerClone,
589
+ layer,
590
+ });
591
+ }
592
+
593
+ // ---- back from a question whose answer flew: it comes back out of the bar
594
+ if (!forward && heldFill && fill && trackRect) {
595
+ if (newSelected) {
596
+ newSelected.dataset.morph = "";
597
+ const copy = pin(newSelected, layer);
598
+ flyBack({
599
+ capsule: newSelected.getBoundingClientRect(),
600
+ track: trackRect,
601
+ fill,
602
+ lo: toFraction,
603
+ hi: fromFraction,
604
+ answerClone: copy,
605
+ liveAnswer: newSelected,
606
+ layer,
607
+ });
608
+ } else {
609
+ animate(
610
+ fill,
611
+ [
612
+ { transform: `translateX(${(fromFraction - 1) * 100}%)` },
613
+ { transform: `translateX(${(toFraction - 1) * 100}%)` },
614
+ ],
615
+ {
616
+ duration: 300,
617
+ fill: "none",
618
+ },
619
+ );
620
+ }
621
+ }
622
+
623
+ switch (handoff) {
624
+ case "picture":
625
+ case "connect": {
626
+ if (forward) {
627
+ const photoKnown =
628
+ newImage instanceof HTMLImageElement &&
629
+ (loaded(newImage) || isImageReady(newImage.getAttribute("src") ?? ""));
630
+ if (!(answerFace && oldSelectedRect && newImage && photoKnown)) {
631
+ // No morph target yet: the answer leaves with the page, and the photo fades in on load.
632
+ hidden.forEach((el) => (el.style.visibility = ""));
633
+ hidden = [];
634
+ if (newImage && !loaded(newImage as HTMLImageElement)) {
635
+ newImage.addEventListener(
636
+ "load",
637
+ () =>
638
+ newImage.animate([{ opacity: 0 }, { opacity: 1 }], {
639
+ duration: 240,
640
+ easing: EASE_OUT,
641
+ }),
642
+ { once: true },
643
+ );
644
+ }
645
+ break;
646
+ }
647
+ // Its CSS entrance is off (motion.css declares it; data-morph is the backstop) before measuring.
648
+ newImage.dataset.morph = "";
649
+ const laidOut = newImage.getBoundingClientRect();
650
+ const size = imageSize(newImage.getAttribute("src") ?? "");
651
+ const r =
652
+ laidOut.height >= 1 || !size
653
+ ? laidOut
654
+ : new DOMRect(
655
+ laidOut.left,
656
+ laidOut.top,
657
+ laidOut.width,
658
+ (laidOut.width * size.height) / size.width,
659
+ );
660
+ if (handoff === "connect") {
661
+ // Connect: the other answers gather into the chosen one (never below 95%) as it becomes the
662
+ // photo. They are the leaving page's live elements (motion.css leaves them alone for this).
663
+ const a = centre(oldSelectedRect);
664
+ const chosen = oldOptions.indexOf(oldSelected as HTMLElement);
665
+ oldOptions.forEach((el, k) => {
666
+ if (el === oldSelected) return;
667
+ const c = centre(el.getBoundingClientRect());
668
+ park(
669
+ el,
670
+ [
671
+ { transform: "none", opacity: 1, filter: "blur(0px)", easing: EASE_IN_OUT },
672
+ {
673
+ offset: 0.35,
674
+ transform: `translate3d(${a.x - c.x}px, ${a.y - c.y}px, 0) scale(0.95)`,
675
+ opacity: 0,
676
+ filter: `blur(${motionBlur(5)}px)`,
677
+ },
678
+ {
679
+ transform: `translate3d(${a.x - c.x}px, ${a.y - c.y}px, 0) scale(0.95)`,
680
+ opacity: 0,
681
+ filter: `blur(${motionBlur(5)}px)`,
682
+ },
683
+ ],
684
+ { duration: TRANSFORM_MS, easing: "linear", delay: Math.abs(k - chosen) * 30 },
685
+ );
686
+ });
687
+ }
688
+ const m = playMorph({
689
+ from: { rect: oldSelectedRect, radius: oldSelectedRect.height / 2 },
690
+ to: { rect: r, radius: PHOTO_RADIUS },
691
+ faces: { from: answerFace, to: photoFace(newImage) },
692
+ duration: TRANSFORM_MS,
693
+ handover: [0.45, 0.75],
694
+ mount: layer,
695
+ });
696
+ qa(m.faces.from, "span").forEach((label) =>
697
+ animate(label, labelOut, { duration: TRANSFORM_MS, easing: "linear" }),
698
+ );
699
+ animate(newImage, REVEAL_UNDER_COPY, {
700
+ duration: TRANSFORM_MS,
701
+ easing: "linear",
702
+ fill: "backwards",
703
+ });
704
+ } else if (photoFaceBack && oldImageRect && newSelected) {
705
+ // The photo becomes the answer again, closing into its pill while travelling to it.
706
+ newSelected.dataset.morph = "";
707
+ hide(oldImage);
708
+ const r = newSelected.getBoundingClientRect();
709
+ const m = playMorph({
710
+ from: { rect: oldImageRect, radius: PHOTO_RADIUS },
711
+ to: { rect: r, radius: r.height / 2 },
712
+ faces: { from: photoFaceBack, to: fillFace(newSelected, r) },
713
+ duration: TRANSFORM_MS,
714
+ handover: [0.7, 0.94],
715
+ mount: layer,
716
+ });
717
+ qa(m.faces.to, "span").forEach((label) =>
718
+ animate(label, labelBack, { duration: TRANSFORM_MS, easing: "linear" }),
719
+ );
720
+ animate(newSelected, REVEAL_UNDER_COPY, {
721
+ duration: TRANSFORM_MS,
722
+ easing: "linear",
723
+ fill: "backwards",
724
+ });
725
+
726
+ if (handoff === "connect") {
727
+ // Every answer went into the photo, so every answer comes back out of it, from where the
728
+ // frame is when they start (60% of the way, on the same clock).
729
+ const k = glideAt(0.6);
730
+ const from = {
731
+ x: lerp(oldImageRect.left + oldImageRect.width / 2, r.left + r.width / 2, k),
732
+ y: lerp(oldImageRect.top + oldImageRect.height / 2, r.top + r.height / 2, k),
733
+ };
734
+ qa(page, "[data-flow-option]").forEach((el, i) => {
735
+ if (el === newSelected) return;
736
+ el.dataset.morph = "";
737
+ const c = centre(el.getBoundingClientRect());
738
+ animate(
739
+ el,
740
+ [
741
+ {
742
+ transform: `translate3d(${from.x - c.x}px, ${from.y - c.y}px, 0) scale(0.95)`,
743
+ opacity: 0,
744
+ filter: `blur(${motionBlur(5)}px)`,
745
+ },
746
+ {
747
+ offset: 0.55 + i * 0.04,
748
+ transform: `translate3d(${from.x - c.x}px, ${from.y - c.y}px, 0) scale(0.95)`,
749
+ opacity: 0,
750
+ filter: `blur(${motionBlur(5)}px)`,
751
+ easing: EASE_IN_OUT,
752
+ },
753
+ { transform: "none", opacity: 1, filter: "blur(0px)" },
754
+ ],
755
+ { duration: TRANSFORM_MS, easing: "linear", fill: "backwards" },
756
+ );
757
+ });
758
+ }
759
+ }
760
+ break;
761
+ }
762
+
763
+ case "flood": {
764
+ if (forward) {
765
+ // The chosen answer opens into the statement's full-screen colour: the most prominent thing on
766
+ // the next screen, and the answer's own colour. The words arrive on it afterwards (motion.css).
767
+ if (!(answerFace && oldSelectedRect && newBackdrop)) break;
768
+ newBackdrop.dataset.morph = "";
769
+ const m = playMorph({
770
+ from: { rect: oldSelectedRect, radius: oldSelectedRect.height / 2 },
771
+ to: { rect: newBackdrop.getBoundingClientRect(), radius: 0 },
772
+ faces: { from: answerFace, to: colorFace(getComputedStyle(newBackdrop).backgroundColor) },
773
+ duration: TRANSFORM_MS,
774
+ handover: [0.45, 0.75],
775
+ mount: layer,
776
+ });
777
+ qa(m.faces.from, "span").forEach((label) =>
778
+ animate(label, labelOut, { duration: TRANSFORM_MS, easing: "linear" }),
779
+ );
780
+ animate(newBackdrop, REVEAL_UNDER_COPY, {
781
+ duration: TRANSFORM_MS,
782
+ easing: "linear",
783
+ fill: "backwards",
784
+ });
785
+ } else if (oldBackdropRect && newSelected) {
786
+ // Back out of a statement: the colour closes back into the answer that opened into it.
787
+ newSelected.dataset.morph = "";
788
+ hide(oldBackdrop);
789
+ const r = newSelected.getBoundingClientRect();
790
+ const m = playMorph({
791
+ from: { rect: oldBackdropRect, radius: 0 },
792
+ to: { rect: r, radius: r.height / 2 },
793
+ faces: { from: colorFace(backdropColor), to: fillFace(newSelected, r) },
794
+ duration: TRANSFORM_MS,
795
+ handover: [0.7, 0.94],
796
+ zIndex: 29,
797
+ mount: layer,
798
+ });
799
+ qa(m.faces.to, "span").forEach((label) =>
800
+ animate(label, labelBack, { duration: TRANSFORM_MS, easing: "linear" }),
801
+ );
802
+ animate(newSelected, REVEAL_UNDER_COPY, {
803
+ duration: TRANSFORM_MS,
804
+ easing: "linear",
805
+ fill: "backwards",
806
+ });
807
+ }
808
+ break;
809
+ }
810
+
811
+ case "absorb": {
812
+ if (!(fill && trackRect)) break;
813
+ if (forward) {
814
+ // The statement's colour collapses into the stretch of bar this step earns: the statement
815
+ // becomes progress (the bar's exception to the size floor). Its words leave first (motion.css).
816
+ if (!oldBackdropRect) break;
817
+ hide(oldBackdrop);
818
+ const { path, fillFrames, to } = intoBarPath(
819
+ oldBackdropRect,
820
+ 0,
821
+ trackRect,
822
+ fromFraction,
823
+ toFraction,
824
+ );
825
+ playMorph({
826
+ from: { rect: oldBackdropRect, radius: 0 },
827
+ to: { rect: to, radius: to.height / 2 },
828
+ faces: { from: colorFace(backdropColor), to: colorFace(backdropColor) },
829
+ duration: FLIGHT_MS,
830
+ blur: 0,
831
+ zIndex: 29,
832
+ path,
833
+ steps: STEPS,
834
+ mount: layer,
835
+ });
836
+ // The bar holds until the colour's edge reaches it, then grows with it (the same as a pill).
837
+ animate(fill, fillFrames, { duration: FLIGHT_MS, easing: "linear", fill: "none" });
838
+ } else if (newBackdrop) {
839
+ // Back into a statement: the stretch of bar it became grows back out into the colour.
840
+ newBackdrop.dataset.morph = "";
841
+ const color = getComputedStyle(newBackdrop).backgroundColor;
842
+ const dest = newBackdrop.getBoundingClientRect();
843
+ const { path, from } = outOfBarPath(dest, 0, trackRect, toFraction, fromFraction);
844
+ playMorph({
845
+ from: { rect: from, radius: from.height / 2 },
846
+ to: { rect: dest, radius: 0 },
847
+ faces: { from: colorFace(color), to: colorFace(color) },
848
+ duration: TRANSFORM_MS,
849
+ blur: 0,
850
+ zIndex: 29,
851
+ path,
852
+ mount: layer,
853
+ });
854
+ animate(newBackdrop, REVEAL_UNDER_COPY, {
855
+ duration: TRANSFORM_MS,
856
+ easing: "linear",
857
+ fill: "backwards",
858
+ });
859
+ }
860
+ break;
861
+ }
862
+
863
+ default:
864
+ // begin, kept, finish: the pages' own CSS does the rest.
865
+ break;
866
+ }
867
+
868
+ finish();
869
+ }