@superwall/cli 2.0.0 → 2.1.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.
- package/dist/{apple-CkKlHBZ9.js → apple-CSzNTGHM.js} +13 -13
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +3 -3
- package/dist/{billing-XCZU_T46.js → billing-C3Q8DBU2.js} +3 -3
- package/dist/{bind-drne__Ys.js → bind-BumHTi9O.js} +4 -4
- package/dist/{build-Gpdq5QXP.js → build-Bpviiclc.js} +6 -6
- package/dist/{client-DP6Rc0t_.js → client-BL0f_yGf.js} +2 -2
- package/dist/create-BSfvpWoD.js +19 -0
- package/dist/{create-Cwc3SRWJ.js → create-BUcVG4Ab.js} +23 -23
- package/dist/{create-BBrtgUgS.js → create-CfK3PeKA.js} +6 -6
- package/dist/{doctor-C9ldpPFC.js → doctor-BWqIYcMn.js} +6 -6
- package/dist/{drivers-DNrx4LWA.js → drivers-CPhdPkW5.js} +3 -3
- package/dist/entry.js +20 -21
- package/dist/{environment-DF1qKlny.js → environment-eBXjELoN.js} +1 -1
- package/dist/{existing-78LWSsqS.js → existing-BltvQiX5.js} +2 -2
- package/dist/held-CPve03KJ.js +16 -0
- package/dist/{held-Cy8Wl4D1.js → held-DgnTFMl3.js} +6 -6
- package/dist/{integrate-DcJhpXy8.js → integrate-BRsqoe01.js} +22 -22
- package/dist/{login-B2TsCE2H.js → login-BCEH5q0U.js} +1 -1
- package/dist/login-BPOONe7n.js +16 -0
- package/dist/{login-D0lh3_JI.js → login-BbTIrCFT.js} +5 -5
- package/dist/{lookup-D-nmmAbw.js → lookup-rr1AkCJA.js} +2 -2
- package/dist/{migrate-Cfec564E.js → migrate-C9X2Vz81.js} +22 -22
- package/dist/{notification-url-YDbq6FMA.js → notification-url-CV86qiKP.js} +2 -2
- package/dist/{open-Ba2vBl1_.js → open-CcpXotHG.js} +10 -10
- package/dist/{org-D0g_q3mv.js → org-BQQDo7wm.js} +2 -2
- package/dist/{paths-DxSLdpOI.js → paths-CRlU72cq.js} +1 -1
- package/dist/{playbook-DIeb7hne.js → playbook-DVMXN7fh.js} +10 -10
- package/dist/{promote-COD4fYdz.js → promote-Da8xctzy.js} +16 -16
- package/dist/push-BV-grvQg.js +22 -0
- package/dist/{push-CncywhkQ.js → push-D6R9icWN.js} +27 -14
- package/dist/{registry-DSrosOYs.js → registry-BYVD-_h6.js} +206 -49
- package/dist/{resources-Dqr01Dep.js → resources-DLON3-61.js} +18 -6
- package/dist/{run-C9qg_QlC.js → run-Co-BwhOg.js} +2 -2
- package/dist/scan-B88OlWOt.js +4 -0
- package/dist/{scan-DLrsrFS9.js → scan-CKuk-_6W.js} +1 -1
- package/dist/{scope-V336uz8j.js → scope-DV22_Ufm.js} +4 -4
- package/dist/{selection-Rdw-ZUoG.js → selection-C2_KbLuo.js} +10 -4
- package/dist/server-C4f6ccUr.js +22 -0
- package/dist/{server-D0tGG8C4.js → server-D0d2oP-5.js} +10 -8
- package/dist/{session-CFAmMhem.js → session-B-Uz0cQ7.js} +1 -1
- package/dist/session-BuvArt1j.js +6 -0
- package/dist/{session-D_nEWKXT.js → session-C4rbE3VS.js} +41 -13
- package/dist/skills/superwall-framework/SKILL.md +7 -3
- package/dist/skills/superwall-framework/references/cli.md +1 -0
- package/dist/skills/superwall-framework/references/layout.md +34 -1
- package/dist/{skills-DMG4bpKk.js → skills-CLGJuMnF.js} +8 -8
- package/dist/{skills-BvFOa4y6.js → skills-CZcpnEnG.js} +5 -4
- package/dist/{spinner-CneRK5rk.js → spinner-C2U6QBJ9.js} +3 -3
- package/dist/{storage-s2Dnz-yl.js → storage-6h9vyiAz.js} +1 -1
- package/dist/storekit-CK9JmM2D.js +16 -0
- package/dist/{storekit-yY_kS2iR.js → storekit-CinJra3V.js} +3 -3
- package/dist/{telemetry-DtG92m5O.js → telemetry-DKyDhURo.js} +1 -1
- package/dist/{token-DzRh7dI1.js → token-DaxQgQkv.js} +1 -1
- package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
- package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
- package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/tools-skills/mobile-design/SKILL.md +447 -0
- package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
- package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
- package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
- package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/tools-skills/superwall/SKILL.md +263 -0
- package/dist/tools-skills/superwall/references/api.md +303 -0
- package/dist/tools-skills/superwall/references/asa.md +166 -0
- package/dist/tools-skills/superwall/references/asc.md +95 -0
- package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
- package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
- package/dist/tools-skills/superwall/references/docs.md +51 -0
- package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
- package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
- package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
- package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
- package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
- package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
- package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
- package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
- package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
- package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
- package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
- package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
- package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
- package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
- package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
- package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
- package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
- package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
- package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
- package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
- package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
- package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
- package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
- package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
- package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
- package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
- package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
- package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
- package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
- package/dist/tools-skills/superwall-editor/references/design.md +51 -0
- package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
- package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/tools-skills/wwdc/SKILL.md +22 -0
- package/dist/tools-skills/wwdc/references/docs.md +52 -0
- package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +200 -18
- package/dist/{upgrade-Bt4Ouw1y.js → upgrade-DPo0a4Es.js} +1 -1
- package/dist/{upgrade-Cqy5orjb.js → upgrade-ffseQDMx.js} +2 -2
- package/package.json +2 -2
- package/dist/create-Yvf2gStM.js +0 -19
- package/dist/held-Ddw1XSsr.js +0 -16
- package/dist/kinds-GFXB3sYu.js +0 -11
- package/dist/login-BoBe8Psl.js +0 -16
- package/dist/push-CtD4FZQV.js +0 -22
- package/dist/scan-Cv5uOwVY.js +0 -4
- package/dist/send-BxD9yf6F.js +0 -150
- package/dist/server-z1LH94R_.js +0 -22
- package/dist/session-1AV_Bs_d.js +0 -6
- package/dist/storekit-DafAnGkM.js +0 -16
- /package/dist/{devtools-ByZ6XYnn.js → devtools-pBl_vt03.js} +0 -0
- /package/dist/{reports-DdPq4blM.js → reports-D_qbl7_u.js} +0 -0
- /package/dist/{screenshot-file-0UETadF8.js → screenshot-file-tVBfUEIi.js} +0 -0
- /package/dist/{storage-DYvmIOHa.d.ts → storage-CerJ5KLP.d.ts} +0 -0
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
// Reference implementation: the hand-off engine as shipped on Reflective's web2app
|
|
2
|
+
// discovery funnel (React + Vite). Copy and adapt: the hand-off names and their
|
|
3
|
+
// exits are specific to that funnel's copy (see handoffs.md for why each exists);
|
|
4
|
+
// the machinery (pin, settlePrevious, playMorph, fly,
|
|
5
|
+
// flyBack, intoBarPath, outOfBarPath, runHandoff) is general; A → B morphs come from morphFrame.ts.
|
|
6
|
+
//
|
|
7
|
+
// Expects: `FlowHandoff` from your flow types, the data attributes listed in
|
|
8
|
+
// engine.md, and navigation that calls runHandoff (engine.md "Navigation wiring").
|
|
9
|
+
|
|
10
|
+
import { flushSync } from "react-dom";
|
|
11
|
+
import type { FlowHandoff } from "@/lib/types";
|
|
12
|
+
import { decodedCopy, imageSize, isImageReady, releaseDecoded } from "./imageReady";
|
|
13
|
+
import { colorFace, fillFace, glideAt, lerp, morph, MORPH_STEPS, motionBlur, photoFace, roundness } from "./morphFrame";
|
|
14
|
+
import type { Box, Face } from "./morphFrame";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Story motion for flows with `motion: "story"`: each hand-off between two
|
|
18
|
+
* pages gets its own choreography, tied to what the pair says.
|
|
19
|
+
*
|
|
20
|
+
* The outgoing page is a DOM clone pinned over where it was, animated away
|
|
21
|
+
* here; the incoming page is live and runs its entrance from
|
|
22
|
+
* styles/story-motion.css, keyed on the same hand-off name.
|
|
23
|
+
*
|
|
24
|
+
* Only transform and opacity animate, plus the answer ↔ photo morph's clip
|
|
25
|
+
* (one element) and its 5px blur. Blur on anything large, clip-path and
|
|
26
|
+
* View Transition snapshots re-rasterise every frame, and without GPU raster
|
|
27
|
+
* that drops the flow to ~15fps.
|
|
28
|
+
*
|
|
29
|
+
* begin welcome leans back and floats up; the progress bar draws in
|
|
30
|
+
* kept plain lift; the answer's flight into the bar (below) carries this one
|
|
31
|
+
* picture the chosen price becomes the "investment" image: it travels and opens into it, never shrinking
|
|
32
|
+
* inward the big picture sinks back; the recall question rises slowly
|
|
33
|
+
* slip the page drifts up and away, like something forgotten
|
|
34
|
+
* fade answers leave one by one, each drifting a little further
|
|
35
|
+
* gone everything fades to nothing; a beat of emptiness before the image arrives
|
|
36
|
+
* blank the image lifts away first, then the words
|
|
37
|
+
* again re-explaining: the next page comes from above, back over the same ground
|
|
38
|
+
* jolt "something big happens": quick cut, tighter cadence
|
|
39
|
+
* cadence answers leave and arrive on an even beat, a pattern
|
|
40
|
+
* connect the other answers gather into the chosen one as it opens into the image
|
|
41
|
+
* settle the page settles down and away; the honest question arrives calmly
|
|
42
|
+
* finish the progress bar completes and hands over to "You're all set"
|
|
43
|
+
*
|
|
44
|
+
* On every question page except picture and connect (whose answers grow into
|
|
45
|
+
* the next image), the chosen answer also becomes the progress it earned: see fly().
|
|
46
|
+
*
|
|
47
|
+
* Back leaves the way the page came, quicker. Keyboard navigation and reduced
|
|
48
|
+
* motion get a plain fade ("plain").
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export type HandoffName = FlowHandoff | "default" | "plain";
|
|
52
|
+
export type HandoffDirection = "next" | "back";
|
|
53
|
+
|
|
54
|
+
const EASE_OUT = "cubic-bezier(0.23, 1, 0.32, 1)";
|
|
55
|
+
const EASE_IN_OUT = "cubic-bezier(0.77, 0, 0.175, 1)";
|
|
56
|
+
|
|
57
|
+
let lastInput: "pointer" | "keyboard" = "pointer";
|
|
58
|
+
let listening = false;
|
|
59
|
+
|
|
60
|
+
function listenForInputKind() {
|
|
61
|
+
if (listening || typeof window === "undefined") return;
|
|
62
|
+
listening = true;
|
|
63
|
+
window.addEventListener("pointerdown", () => (lastInput = "pointer"), { capture: true, passive: true });
|
|
64
|
+
window.addEventListener("keydown", () => (lastInput = "keyboard"), { capture: true, passive: true });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Keyboard navigation is repeated and deliberate, and reduced motion asks for less: both get a plain fade. */
|
|
68
|
+
export function handoffMode(): "story" | "plain" {
|
|
69
|
+
listenForInputKind();
|
|
70
|
+
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "plain";
|
|
71
|
+
return lastInput === "keyboard" ? "plain" : "story";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type Point = { x: number; y: number };
|
|
75
|
+
|
|
76
|
+
const q = (root: ParentNode | null, selector: string) => root?.querySelector<HTMLElement>(selector) ?? null;
|
|
77
|
+
const qa = (root: ParentNode | null, selector: string) => Array.from(root?.querySelectorAll<HTMLElement>(selector) ?? []);
|
|
78
|
+
const centre = (r: DOMRect): Point => ({ x: r.left + r.width / 2, y: r.top + r.height / 2 });
|
|
79
|
+
/** An <img> that hasn't loaded has no height yet: nothing to morph into. */
|
|
80
|
+
const loaded = (img: HTMLImageElement | null): boolean => img !== null && img.complete && img.naturalWidth > 0;
|
|
81
|
+
|
|
82
|
+
const easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);
|
|
83
|
+
const easeOut = (t: number) => 1 - Math.pow(1 - t, 3);
|
|
84
|
+
|
|
85
|
+
// The previous hand-off's leftovers, so a quick second tap can finish it instantly.
|
|
86
|
+
let running: Animation[] = [];
|
|
87
|
+
// Only what the copies' removal waits for: the copies' own animations and the live destinations'
|
|
88
|
+
// REVEAL_UNDER_COPY holds, which end on the same frame. Never the new page's entrances (CSS here, but
|
|
89
|
+
// if you move them into script, keep them out of this list): a copy that waits for them sits over
|
|
90
|
+
// them for their whole duration, and a full-screen colour frame hid a statement's words that way.
|
|
91
|
+
let handovers: Animation[] = [];
|
|
92
|
+
let clones: HTMLElement[] = [];
|
|
93
|
+
// The progress fill whose CSS transition is paused while an answer carries the bar.
|
|
94
|
+
let heldFill: HTMLElement | null = null;
|
|
95
|
+
|
|
96
|
+
function releaseFill() {
|
|
97
|
+
if (heldFill) heldFill.style.transition = "";
|
|
98
|
+
heldFill = null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function settlePrevious() {
|
|
102
|
+
running.forEach((a) => a.finish());
|
|
103
|
+
running = [];
|
|
104
|
+
handovers = [];
|
|
105
|
+
clones.forEach((c) => c.remove());
|
|
106
|
+
clones = [];
|
|
107
|
+
releaseDecoded();
|
|
108
|
+
releaseFill();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A copy of `el` pinned where it is on screen, outside the page, for the exit to animate.
|
|
113
|
+
*
|
|
114
|
+
* Every animated copy is position: absolute (at the same screen coordinates; the page itself never
|
|
115
|
+
* scrolls), never fixed: iOS 26 Safari tints its toolbar from a fixed element touching the top edge,
|
|
116
|
+
* so a full-screen fixed morph frame retinted the browser chrome mid-transition. The toolbar-tint
|
|
117
|
+
* sentinel (index.html) must stay the only fixed element.
|
|
118
|
+
*/
|
|
119
|
+
function pin(el: HTMLElement): HTMLElement {
|
|
120
|
+
const r = el.getBoundingClientRect();
|
|
121
|
+
const clone = el.cloneNode(true) as HTMLElement;
|
|
122
|
+
// A cloned <img> reloads, and Safari paints nothing until it has: swap in the decoded image.
|
|
123
|
+
const originals = el.querySelectorAll("img");
|
|
124
|
+
clone.querySelectorAll("img").forEach((img, i) => img.replaceWith(decodedCopy(originals[i])));
|
|
125
|
+
clone.removeAttribute("data-flow-page");
|
|
126
|
+
clone.setAttribute("aria-hidden", "true");
|
|
127
|
+
clone.setAttribute("data-handoff-clone", "");
|
|
128
|
+
Object.assign(clone.style, {
|
|
129
|
+
position: "absolute",
|
|
130
|
+
left: `${r.left + window.scrollX}px`,
|
|
131
|
+
top: `${r.top + window.scrollY}px`,
|
|
132
|
+
width: `${r.width}px`,
|
|
133
|
+
height: `${r.height}px`,
|
|
134
|
+
margin: "0",
|
|
135
|
+
zIndex: "30",
|
|
136
|
+
pointerEvents: "none",
|
|
137
|
+
});
|
|
138
|
+
document.body.appendChild(clone);
|
|
139
|
+
clones.push(clone);
|
|
140
|
+
return clone;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function animate(el: Element | null | undefined, keyframes: Keyframe[], options: KeyframeAnimationOptions) {
|
|
144
|
+
if (!el) return;
|
|
145
|
+
const animation = el.animate(keyframes, { fill: "both", easing: EASE_OUT, ...options });
|
|
146
|
+
running.push(animation);
|
|
147
|
+
if (keyframes === REVEAL_UNDER_COPY || el.closest("[data-handoff-clone]")) handovers.push(animation);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Every A → B transform (answer → progress bar, answer ↔ photo, bar → answer) runs this long, so
|
|
152
|
+
* one never feels slower than another.
|
|
153
|
+
*/
|
|
154
|
+
const TRANSFORM_MS = 504;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Keyframes that keep a live destination out of sight while its copy transforms into it, and hand
|
|
158
|
+
* over on the last frame: it's at opacity 0.001 throughout, then 1 the moment the animation ends,
|
|
159
|
+
* and the copy is removed in that same frame (see finish()).
|
|
160
|
+
*
|
|
161
|
+
* Why 0.001, not 0: a browser doesn't paint a fully transparent element, so one revealed only on the
|
|
162
|
+
* last frame shows a frame of nothing (a flash). At 0.001 it's already painted, yet adds nothing
|
|
163
|
+
* visible. Why not reveal it early under the copy: many destinations are translucent (a selected
|
|
164
|
+
* answer is 90% primary), and a 90% copy over a 90% element reads as ~99% — the answer darkens for
|
|
165
|
+
* the last stretch, then pops back when the copy goes.
|
|
166
|
+
*/
|
|
167
|
+
const REVEAL_UNDER_COPY: Keyframe[] = [{ opacity: 0.001 }, { opacity: 0.001 }];
|
|
168
|
+
const FLIGHT_MS = TRANSFORM_MS;
|
|
169
|
+
// The answer's right edge reaches the bar's end at 55%; the rest is the two growing together.
|
|
170
|
+
const JOIN = 0.55;
|
|
171
|
+
// Sampled timeline; STEPS * JOIN is whole so a keyframe sits exactly on the join.
|
|
172
|
+
const STEPS = 40;
|
|
173
|
+
|
|
174
|
+
/** Overshoots its target by ~12% and settles back. */
|
|
175
|
+
const easeOutBack = (t: number) => {
|
|
176
|
+
const c1 = 2;
|
|
177
|
+
return 1 + (c1 + 1) * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The chosen answer becomes the bar's leading edge. Its label fades, and the
|
|
182
|
+
* pill shrinks around its right edge while that edge flies to where the bar
|
|
183
|
+
* currently ends — same colour, same height. On that frame they join, then
|
|
184
|
+
* grow together to the new length: the answer is what pushes the bar
|
|
185
|
+
* forward, not a timer. Going back is its own move, not this one rewound:
|
|
186
|
+
* see flyBack().
|
|
187
|
+
*
|
|
188
|
+
* It rises to the bar's height (shrinking to the bar's size) while drifting
|
|
189
|
+
* left, reaching that height just before the end, so it slides the last
|
|
190
|
+
* stretch level into the bar's end. Once the bar has grown, its edge
|
|
191
|
+
* overshoots a little and settles back.
|
|
192
|
+
*/
|
|
193
|
+
function fly({
|
|
194
|
+
capsule,
|
|
195
|
+
track,
|
|
196
|
+
fill,
|
|
197
|
+
lo,
|
|
198
|
+
hi,
|
|
199
|
+
answerClone,
|
|
200
|
+
}: {
|
|
201
|
+
capsule: DOMRect;
|
|
202
|
+
track: DOMRect;
|
|
203
|
+
fill: HTMLElement;
|
|
204
|
+
/** Progress before this step: where the answer joins the bar. */
|
|
205
|
+
lo: number;
|
|
206
|
+
/** Progress after this step. */
|
|
207
|
+
hi: number;
|
|
208
|
+
answerClone?: HTMLElement;
|
|
209
|
+
}) {
|
|
210
|
+
const loX = track.left + track.width * lo;
|
|
211
|
+
const hiX = track.left + track.width * hi;
|
|
212
|
+
// The pill lands as the bar's tip: right edge on the bar's end, one step long (inside the fill).
|
|
213
|
+
const width = Math.max(track.height, Math.min(hiX - loX, loX - track.left));
|
|
214
|
+
const land = new DOMRect(Math.max(track.left, loX - width), track.top, width, track.height);
|
|
215
|
+
|
|
216
|
+
const slug = document.createElement("div");
|
|
217
|
+
slug.setAttribute("aria-hidden", "true");
|
|
218
|
+
slug.setAttribute("data-handoff-clone", "");
|
|
219
|
+
Object.assign(slug.style, {
|
|
220
|
+
position: "absolute",
|
|
221
|
+
left: `${land.left + window.scrollX}px`,
|
|
222
|
+
top: `${land.top + window.scrollY}px`,
|
|
223
|
+
width: `${land.width}px`,
|
|
224
|
+
height: `${land.height}px`,
|
|
225
|
+
borderRadius: "999px",
|
|
226
|
+
background: "rgb(var(--color-ui-primary))",
|
|
227
|
+
transformOrigin: "100% 50%",
|
|
228
|
+
zIndex: "31",
|
|
229
|
+
pointerEvents: "none",
|
|
230
|
+
});
|
|
231
|
+
document.body.appendChild(slug);
|
|
232
|
+
clones.push(slug);
|
|
233
|
+
if (answerClone) answerClone.style.transformOrigin = "100% 50%";
|
|
234
|
+
|
|
235
|
+
// Everything is placed by its right edge: the answer's, then the bar's.
|
|
236
|
+
const a = { x: capsule.right, y: capsule.top + capsule.height / 2 };
|
|
237
|
+
const b = { x: land.right, y: land.top + land.height / 2 };
|
|
238
|
+
// Both are long thin pills whose proportions track the page width, so this scale stays nearly uniform.
|
|
239
|
+
const sx0 = capsule.width / land.width;
|
|
240
|
+
const sy0 = capsule.height / land.height;
|
|
241
|
+
// Rising and drifting left together, the rise leading, and finishing first: it reaches the bar's
|
|
242
|
+
// height with ~13% of the way left to go, which it covers level, into the bar's end.
|
|
243
|
+
const riseAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f / 0.75)));
|
|
244
|
+
const slideAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f)));
|
|
245
|
+
|
|
246
|
+
const slugFrames: Keyframe[] = [];
|
|
247
|
+
const capsuleFrames: Keyframe[] = [];
|
|
248
|
+
const fillFrames: Keyframe[] = [];
|
|
249
|
+
for (let i = 0; i <= STEPS; i++) {
|
|
250
|
+
const p = i / STEPS;
|
|
251
|
+
// f: flight progress (0 = the answer, 1 = joined). g: how far the joined edge has grown (0 = lo, 1 = hi).
|
|
252
|
+
const f = p <= JOIN ? p / JOIN : 1;
|
|
253
|
+
const g = p <= JOIN ? 0 : easeOutBack((p - JOIN) / (1 - JOIN));
|
|
254
|
+
// e: how far it has become the bar's tip (shrinks with the rise).
|
|
255
|
+
const e = riseAt(f);
|
|
256
|
+
const x = a.x + (b.x - a.x) * slideAt(f) + (hiX - loX) * g;
|
|
257
|
+
const y = a.y + (b.y - a.y) * e;
|
|
258
|
+
const sx = Math.pow(sx0, 1 - e);
|
|
259
|
+
const sy = Math.pow(sy0, 1 - e);
|
|
260
|
+
// The capsule is 90% primary, the bar 100%: the pill deepens in flight and is exactly the bar's
|
|
261
|
+
// colour before it joins. Nothing about the bar's colour changes while it grows: the pill stays
|
|
262
|
+
// opaque and is removed once it sits exactly over the fill's identical end.
|
|
263
|
+
const tone = 0.9 + 0.1 * Math.min(1, e / 0.9);
|
|
264
|
+
slugFrames.push({
|
|
265
|
+
offset: p,
|
|
266
|
+
transform: `translate3d(${x - b.x}px, ${y - b.y}px, 0) scale(${sx}, ${sy})`,
|
|
267
|
+
opacity: tone,
|
|
268
|
+
});
|
|
269
|
+
fillFrames.push({ offset: p, transform: `translateX(${(lo + (hi - lo) * g - 1) * 100}%)` });
|
|
270
|
+
if (answerClone) {
|
|
271
|
+
capsuleFrames.push({
|
|
272
|
+
offset: p,
|
|
273
|
+
transform: `translate3d(${x - a.x}px, ${y - a.y}px, 0) scale(${sx / sx0}, ${sy / sy0})`,
|
|
274
|
+
// Its words and fill go first, over the pill.
|
|
275
|
+
opacity: Math.max(0, 1 - p / 0.13),
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
animate(slug, slugFrames, { duration: FLIGHT_MS, easing: "linear" });
|
|
281
|
+
animate(fill, fillFrames, { duration: FLIGHT_MS, easing: "linear", fill: "none" });
|
|
282
|
+
if (answerClone) animate(answerClone, capsuleFrames, { duration: FLIGHT_MS, easing: "linear" });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Going back, the answer comes back out of the bar: not the forward flight rewound (the edge
|
|
287
|
+
* pulling left, then the pill reversing to fly right would be a direction flip mid-motion), but its
|
|
288
|
+
* own physical move that ends, like every arrival, on the A → B clock's long, gentle tail.
|
|
289
|
+
*
|
|
290
|
+
* The pill starts as exactly the stretch of bar this answer earned and takes it with it: the bar
|
|
291
|
+
* gives that stretch up at once, hidden under the pill, and the pill slides out along the bar and
|
|
292
|
+
* drops to the answer, growing into it, on the A → B clock (critically damped: no overshoot, a soft
|
|
293
|
+
* landing), and hands over mid-flight to a copy of the answer travelling the same path; the live
|
|
294
|
+
* answer takes over on the last frame.
|
|
295
|
+
*/
|
|
296
|
+
function flyBack({
|
|
297
|
+
capsule,
|
|
298
|
+
track,
|
|
299
|
+
fill,
|
|
300
|
+
lo,
|
|
301
|
+
hi,
|
|
302
|
+
answerClone,
|
|
303
|
+
liveAnswer,
|
|
304
|
+
}: {
|
|
305
|
+
capsule: DOMRect;
|
|
306
|
+
track: DOMRect;
|
|
307
|
+
fill: HTMLElement;
|
|
308
|
+
/** Progress after this step (where the bar ends once the answer has left it). */
|
|
309
|
+
lo: number;
|
|
310
|
+
/** Progress before this step. */
|
|
311
|
+
hi: number;
|
|
312
|
+
answerClone?: HTMLElement;
|
|
313
|
+
liveAnswer?: HTMLElement;
|
|
314
|
+
}) {
|
|
315
|
+
const duration = TRANSFORM_MS;
|
|
316
|
+
const loX = track.left + track.width * lo;
|
|
317
|
+
const hiX = track.left + track.width * hi;
|
|
318
|
+
const seg = new DOMRect(loX, track.top, Math.max(track.height, hiX - loX), track.height);
|
|
319
|
+
|
|
320
|
+
const slug = document.createElement("div");
|
|
321
|
+
slug.setAttribute("aria-hidden", "true");
|
|
322
|
+
slug.setAttribute("data-handoff-clone", "");
|
|
323
|
+
Object.assign(slug.style, {
|
|
324
|
+
position: "absolute",
|
|
325
|
+
left: `${seg.left + window.scrollX}px`,
|
|
326
|
+
top: `${seg.top + window.scrollY}px`,
|
|
327
|
+
width: `${seg.width}px`,
|
|
328
|
+
height: `${seg.height}px`,
|
|
329
|
+
borderRadius: "999px",
|
|
330
|
+
background: "rgb(var(--color-ui-primary))",
|
|
331
|
+
transformOrigin: "100% 50%",
|
|
332
|
+
zIndex: "31",
|
|
333
|
+
pointerEvents: "none",
|
|
334
|
+
});
|
|
335
|
+
document.body.appendChild(slug);
|
|
336
|
+
clones.push(slug);
|
|
337
|
+
if (answerClone) answerClone.style.transformOrigin = "100% 50%";
|
|
338
|
+
|
|
339
|
+
// Placed by right edges, as going forward: the segment's, then the answer's.
|
|
340
|
+
const b = { x: seg.right, y: seg.top + seg.height / 2 };
|
|
341
|
+
const a = { x: capsule.right, y: capsule.top + capsule.height / 2 };
|
|
342
|
+
const sx0 = capsule.width / seg.width;
|
|
343
|
+
const sy0 = capsule.height / seg.height;
|
|
344
|
+
// Path shape, s = 1 at the bar → 0 at the answer. Across: linear. Down:
|
|
345
|
+
// level for the first quarter (sliding out along the bar), then curving down to arrive at the same
|
|
346
|
+
// rate as it goes across (slope 1 at the answer), so it arrives along its line of travel and a
|
|
347
|
+
// gentle clock stays gentle on screen (a steep final curve would magnify any change in speed).
|
|
348
|
+
const across = (s: number) => s;
|
|
349
|
+
const up = (s: number) => (s >= 0.75 ? 1 : s + 2.6667 * s * s - 2.963 * s * s * s);
|
|
350
|
+
|
|
351
|
+
const slugFrames: Keyframe[] = [];
|
|
352
|
+
const copyFrames: Keyframe[] = [];
|
|
353
|
+
let handedOver = false;
|
|
354
|
+
for (let i = 0; i <= MORPH_STEPS; i++) {
|
|
355
|
+
const t = i / MORPH_STEPS;
|
|
356
|
+
const s = 1 - glideAt(t);
|
|
357
|
+
const u = up(s); // 1 = bar-like, 0 = answer-like, < 0 past the answer
|
|
358
|
+
const x = a.x + (b.x - a.x) * across(s);
|
|
359
|
+
const y = a.y + (b.y - a.y) * u;
|
|
360
|
+
// Size grows linearly toward the answer (a multiplicative grow would rush the end of it).
|
|
361
|
+
const sx = 1 + (sx0 - 1) * (1 - u);
|
|
362
|
+
const sy = 1 + (sy0 - 1) * (1 - u);
|
|
363
|
+
const slugAt = `translate3d(${x - b.x}px, ${y - b.y}px, 0) scale(${sx}, ${sy})`;
|
|
364
|
+
const copyAt = `translate3d(${x - a.x}px, ${y - a.y}px, 0) scale(${sx / sx0}, ${sy / sy0})`;
|
|
365
|
+
// The bar's colour, lightening to the capsule's 90% as it becomes the answer.
|
|
366
|
+
const tone = 1 - 0.1 * Math.min(1, Math.max(0, 1 - u));
|
|
367
|
+
// Hand over from the pill to the answer's copy in one frame, not a crossfade: both are translucent,
|
|
368
|
+
// so mid-crossfade they'd cover less than either does alone and the answer would lighten. By 90%
|
|
369
|
+
// of the way the pill is the answer's colour and shape, so the swap is invisible; the label fades
|
|
370
|
+
// in on the copy on its own.
|
|
371
|
+
const past = 1 - s >= 0.9;
|
|
372
|
+
if (past && !handedOver) {
|
|
373
|
+
handedOver = true;
|
|
374
|
+
slugFrames.push({ offset: t, transform: slugAt, opacity: tone });
|
|
375
|
+
copyFrames.push({ offset: t, transform: copyAt, opacity: 0 });
|
|
376
|
+
}
|
|
377
|
+
slugFrames.push({ offset: t, transform: slugAt, opacity: past ? 0 : tone });
|
|
378
|
+
copyFrames.push({ offset: t, transform: copyAt, opacity: past ? 1 : 0 });
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// The bar gives the stretch up at once, under the pill that now carries it: its transition is held
|
|
382
|
+
// (heldFill), so the new length React just rendered applies on this frame.
|
|
383
|
+
animate(slug, slugFrames, { duration, easing: "linear" });
|
|
384
|
+
if (answerClone) {
|
|
385
|
+
animate(answerClone, copyFrames, { duration, easing: "linear" });
|
|
386
|
+
// The label comes back last, on the travelling copy.
|
|
387
|
+
qa(answerClone, "span").forEach((label) => animate(label, [{ opacity: 0 }, { offset: 0.8, opacity: 0 }, { opacity: 1 }], { duration, easing: "linear" }));
|
|
388
|
+
}
|
|
389
|
+
if (liveAnswer) {
|
|
390
|
+
// Hidden while something transforms into it; takes over on the last frame, exactly where the copy ends.
|
|
391
|
+
animate(liveAnswer, REVEAL_UNDER_COPY, { duration, easing: "linear", fill: "backwards" });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// The photo's resting corner radius (its rounded-[20px]).
|
|
396
|
+
const PHOTO_RADIUS = 20;
|
|
397
|
+
|
|
398
|
+
/** The stretch of progress bar between two fractions, in screen space (at least as long as it's tall). */
|
|
399
|
+
function barSegment(track: DOMRect, from: number, to: number): DOMRect {
|
|
400
|
+
const lo = Math.min(from, to);
|
|
401
|
+
const hi = Math.max(from, to);
|
|
402
|
+
return new DOMRect(track.left + track.width * lo, track.top, Math.max(track.height, track.width * (hi - lo)), track.height);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Any shape into the progress bar exactly the way an answer pill goes (fly()), as a morph path:
|
|
407
|
+
* its right edge flies to where the bar currently ends while it shrinks to the bar's height (rising
|
|
408
|
+
* first, a short level run in); they join, then grow together to the new length, and the edge
|
|
409
|
+
* bounces. Driven through the one-geometry frame, so a big shape (a full-screen colour) never gets
|
|
410
|
+
* stretched: its corners go from its own roundness to a fully round pill. Also returns the bar's
|
|
411
|
+
* keyframes (hold, then grow with the shape).
|
|
412
|
+
*/
|
|
413
|
+
function intoBarPath(source: DOMRect, sourceRadius: number, track: DOMRect, lo: number, hi: number) {
|
|
414
|
+
const loX = track.left + track.width * lo;
|
|
415
|
+
const hiX = track.left + track.width * hi;
|
|
416
|
+
const width = Math.max(track.height, Math.min(hiX - loX, loX - track.left));
|
|
417
|
+
const land = new DOMRect(Math.max(track.left, loX - width), track.top, width, track.height);
|
|
418
|
+
const a = { x: source.right, y: source.top + source.height / 2 };
|
|
419
|
+
const b = { x: land.right, y: land.top + land.height / 2 };
|
|
420
|
+
const riseAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f / 0.75)));
|
|
421
|
+
const slideAt = (f: number) => easeInOut(Math.min(1, Math.max(0, f)));
|
|
422
|
+
const fromRound = roundness(sourceRadius, source.width, source.height);
|
|
423
|
+
const phase = (t: number) => ({
|
|
424
|
+
f: t <= JOIN ? t / JOIN : 1,
|
|
425
|
+
g: t <= JOIN ? 0 : easeOutBack((t - JOIN) / (1 - JOIN)),
|
|
426
|
+
});
|
|
427
|
+
const path = (t: number): Box => {
|
|
428
|
+
const { f, g } = phase(t);
|
|
429
|
+
const e = riseAt(f); // how far it has become the bar's tip
|
|
430
|
+
const w = Math.exp(lerp(Math.log(source.width), Math.log(land.width), e));
|
|
431
|
+
const h = Math.exp(lerp(Math.log(source.height), Math.log(land.height), e));
|
|
432
|
+
const right = a.x + (b.x - a.x) * slideAt(f) + (hiX - loX) * g;
|
|
433
|
+
return { cx: right - w / 2, cy: a.y + (b.y - a.y) * e, w, h, r: lerp(fromRound, 0.5, e) * Math.min(w, h) };
|
|
434
|
+
};
|
|
435
|
+
const fillFrames: Keyframe[] = Array.from({ length: STEPS + 1 }, (_, i) => {
|
|
436
|
+
const t = i / STEPS;
|
|
437
|
+
return { offset: t, transform: `translateX(${(lo + (hi - lo) * phase(t).g - 1) * 100}%)` };
|
|
438
|
+
});
|
|
439
|
+
return { path, fillFrames, to: land };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Out of the progress bar into any shape, the way an answer comes back out (flyBack()): the stretch
|
|
444
|
+
* of bar slides out along it, then drops and grows into the shape by its right edge, on the A → B
|
|
445
|
+
* clock (critically damped: a soft landing). Corners go from a fully round pill to the shape's own.
|
|
446
|
+
*/
|
|
447
|
+
function outOfBarPath(dest: DOMRect, destRadius: number, track: DOMRect, lo: number, hi: number) {
|
|
448
|
+
const seg = barSegment(track, lo, hi);
|
|
449
|
+
const b = { x: seg.right, y: seg.top + seg.height / 2 };
|
|
450
|
+
const a = { x: dest.right, y: dest.top + dest.height / 2 };
|
|
451
|
+
const up = (s: number) => (s >= 0.75 ? 1 : s + 2.6667 * s * s - 2.963 * s * s * s);
|
|
452
|
+
const toRound = roundness(destRadius, dest.width, dest.height);
|
|
453
|
+
const path = (t: number): Box => {
|
|
454
|
+
const s = 1 - glideAt(t);
|
|
455
|
+
const u = up(s); // 1 = bar-like, 0 = the shape
|
|
456
|
+
const w = seg.width + (dest.width - seg.width) * (1 - u);
|
|
457
|
+
const h = seg.height + (dest.height - seg.height) * (1 - u);
|
|
458
|
+
const right = a.x + (b.x - a.x) * s;
|
|
459
|
+
return { cx: right - w / 2, cy: a.y + (b.y - a.y) * u, w, h, r: lerp(0.5, toRound, 1 - u) * Math.min(w, h) };
|
|
460
|
+
};
|
|
461
|
+
return { path, from: seg };
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Runs a Frame A → Frame B morph (morphFrame.ts) as part of this hand-off. */
|
|
465
|
+
function playMorph(args: Parameters<typeof morph>[0]) {
|
|
466
|
+
const m = morph(args);
|
|
467
|
+
running.push(...m.animations);
|
|
468
|
+
handovers.push(...m.animations);
|
|
469
|
+
clones.push(m.frame);
|
|
470
|
+
return m;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const out = (y: number, scale = 1): Keyframe[] => [
|
|
474
|
+
{ transform: "none", opacity: 1 },
|
|
475
|
+
{ transform: `translate3d(0, ${y}px, 0) scale(${scale})`, opacity: 0 },
|
|
476
|
+
];
|
|
477
|
+
|
|
478
|
+
export function runHandoff({
|
|
479
|
+
handoff,
|
|
480
|
+
direction,
|
|
481
|
+
update,
|
|
482
|
+
}: {
|
|
483
|
+
handoff: HandoffName;
|
|
484
|
+
direction: HandoffDirection;
|
|
485
|
+
update: () => void;
|
|
486
|
+
}) {
|
|
487
|
+
settlePrevious();
|
|
488
|
+
if (handoff === "plain") {
|
|
489
|
+
update();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const forward = direction === "next";
|
|
494
|
+
const oldPage = q(document, "[data-flow-page]");
|
|
495
|
+
if (!oldPage) {
|
|
496
|
+
update();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Measure the old page, pin a copy of it, then swap the real page underneath.
|
|
501
|
+
const oldOptions = qa(oldPage, "[data-flow-option]");
|
|
502
|
+
const oldSelectedIndex = oldOptions.findIndex((el) => el.hasAttribute("data-selected"));
|
|
503
|
+
const oldSelectedRect = oldSelectedIndex >= 0 ? oldOptions[oldSelectedIndex].getBoundingClientRect() : undefined;
|
|
504
|
+
const oldImage = q(oldPage, "[data-flow-image]");
|
|
505
|
+
const oldImageRect = oldImage?.getBoundingClientRect();
|
|
506
|
+
// Answers become progress, except where they grow into the next page's image or statement colour.
|
|
507
|
+
const intoImage = handoff === "picture" || handoff === "connect";
|
|
508
|
+
const intoScene = intoImage || handoff === "flood";
|
|
509
|
+
// A statement's full-screen colour (FlowRuntime's backdrop): the destination of `flood`, the
|
|
510
|
+
// source of `absorb`. Captured now; it's gone once the page swaps.
|
|
511
|
+
const oldBackdrop = q(document, "[data-flow-backdrop]");
|
|
512
|
+
const oldBackdropRect = oldBackdrop?.getBoundingClientRect();
|
|
513
|
+
const backdropColor = oldBackdrop ? getComputedStyle(oldBackdrop).backgroundColor : "";
|
|
514
|
+
// The answer ↔ photo morph's faces are captured before the page changes (morphFrame.ts). The
|
|
515
|
+
// photo's goes first so it gets the decoded image (the page copy's photo is hidden anyway).
|
|
516
|
+
const photoFaceBack: Face | null = !forward && intoImage && oldImage instanceof HTMLImageElement ? photoFace(oldImage) : null;
|
|
517
|
+
const ghost = pin(oldPage);
|
|
518
|
+
const ghostOptions = qa(ghost, "[data-flow-option]");
|
|
519
|
+
const ghostLines = qa(ghost, "[data-flow-line], [data-next-button]");
|
|
520
|
+
const ghostImage = q(ghost, "[data-flow-image]");
|
|
521
|
+
const answerFace: Face | null =
|
|
522
|
+
forward && intoScene && oldSelectedIndex >= 0 && oldSelectedRect ? fillFace(oldOptions[oldSelectedIndex], oldSelectedRect) : null;
|
|
523
|
+
if (answerFace) ghostOptions[oldSelectedIndex].style.visibility = "hidden";
|
|
524
|
+
if (photoFaceBack && ghostImage) ghostImage.style.visibility = "hidden";
|
|
525
|
+
const fill = q(document, "[data-progress-fill]");
|
|
526
|
+
const fromFraction = Number(fill?.dataset.progress ?? 0);
|
|
527
|
+
const answerFlies = forward && !intoScene && oldSelectedIndex >= 0 && oldSelectedRect !== undefined && fill !== null;
|
|
528
|
+
let answerClone: HTMLElement | undefined;
|
|
529
|
+
if (answerFlies) {
|
|
530
|
+
answerClone = pin(oldOptions[oldSelectedIndex]);
|
|
531
|
+
answerClone.style.zIndex = "32";
|
|
532
|
+
ghostOptions[oldSelectedIndex].style.visibility = "hidden";
|
|
533
|
+
}
|
|
534
|
+
// The bar moves only when something lands in it (or leaves it), so its own transition steps aside.
|
|
535
|
+
if (fill && (answerFlies || handoff === "absorb" || (!forward && !intoScene))) {
|
|
536
|
+
fill.style.transition = "none";
|
|
537
|
+
heldFill = fill;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
flushSync(update);
|
|
541
|
+
|
|
542
|
+
const page = q(document, "[data-flow-page]");
|
|
543
|
+
const newImage = q(page, "[data-flow-image]");
|
|
544
|
+
const newSelected = q(page, "[data-flow-option][data-selected]");
|
|
545
|
+
const toFraction = Number(fill?.dataset.progress ?? 0);
|
|
546
|
+
const trackRect = fill?.parentElement?.getBoundingClientRect();
|
|
547
|
+
|
|
548
|
+
const finish = () => {
|
|
549
|
+
const done = handovers;
|
|
550
|
+
// A copy only goes once the live photo under it has loaded (at most a second), so the handover
|
|
551
|
+
// never shows a blank frame even if Safari is still loading it.
|
|
552
|
+
const liveImage = newImage instanceof HTMLImageElement && !loaded(newImage) ? newImage : null;
|
|
553
|
+
const photoLoaded = liveImage
|
|
554
|
+
? Promise.race([
|
|
555
|
+
new Promise<void>((resolve) => liveImage.addEventListener("load", () => resolve(), { once: true })),
|
|
556
|
+
new Promise<void>((resolve) => window.setTimeout(resolve, 1000)),
|
|
557
|
+
])
|
|
558
|
+
: Promise.resolve();
|
|
559
|
+
Promise.all([...done.map((a) => a.finished), photoLoaded])
|
|
560
|
+
.catch(() => {})
|
|
561
|
+
.finally(() => {
|
|
562
|
+
if (handovers !== done) return;
|
|
563
|
+
// The same frame the live destinations reach full opacity (their REVEAL_UNDER_COPY ends with
|
|
564
|
+
// the transform, and they're already painted), so the swap is exact: no gap, no double layer.
|
|
565
|
+
// `running` keeps the rest, so a quick second tap can still finish it.
|
|
566
|
+
clones.forEach((c) => c.remove());
|
|
567
|
+
clones = [];
|
|
568
|
+
handovers = [];
|
|
569
|
+
releaseDecoded();
|
|
570
|
+
releaseFill();
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
if (answerFlies && fill && trackRect && oldSelectedRect) {
|
|
575
|
+
fly({ capsule: oldSelectedRect, track: trackRect, fill, lo: fromFraction, hi: toFraction, answerClone });
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (!forward && handoff === "absorb" && fill && trackRect) {
|
|
579
|
+
// Back into a statement: the stretch of bar it became grows back out into the full-screen colour.
|
|
580
|
+
// The bar gives the stretch up at once (held), under the frame that starts exactly on it.
|
|
581
|
+
const backdrop = q(document, "[data-flow-backdrop]");
|
|
582
|
+
if (backdrop) {
|
|
583
|
+
backdrop.dataset.morph = "";
|
|
584
|
+
const color = getComputedStyle(backdrop).backgroundColor;
|
|
585
|
+
const dest = backdrop.getBoundingClientRect();
|
|
586
|
+
const { path, from } = outOfBarPath(dest, 0, trackRect, toFraction, fromFraction);
|
|
587
|
+
playMorph({
|
|
588
|
+
from: { rect: from, radius: from.height / 2 },
|
|
589
|
+
to: { rect: dest, radius: 0 },
|
|
590
|
+
faces: { from: colorFace(color), to: colorFace(color) },
|
|
591
|
+
duration: TRANSFORM_MS,
|
|
592
|
+
blur: 0,
|
|
593
|
+
zIndex: 29,
|
|
594
|
+
path,
|
|
595
|
+
});
|
|
596
|
+
animate(backdrop, REVEAL_UNDER_COPY, { duration: TRANSFORM_MS, easing: "linear", fill: "backwards" });
|
|
597
|
+
}
|
|
598
|
+
animate(ghost, out(12), { duration: 160 });
|
|
599
|
+
finish();
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (!forward && handoff === "flood" && oldBackdropRect && newSelected) {
|
|
604
|
+
// Back out of a statement: the colour closes back into the answer that opened into it, its own
|
|
605
|
+
// move on the A → B clock; the statement's words fade above it.
|
|
606
|
+
newSelected.dataset.morph = "";
|
|
607
|
+
const r = newSelected.getBoundingClientRect();
|
|
608
|
+
const m = playMorph({
|
|
609
|
+
from: { rect: oldBackdropRect, radius: 0 },
|
|
610
|
+
to: { rect: r, radius: r.height / 2 },
|
|
611
|
+
faces: { from: colorFace(backdropColor), to: fillFace(newSelected, r) },
|
|
612
|
+
duration: TRANSFORM_MS,
|
|
613
|
+
handover: [0.7, 0.94],
|
|
614
|
+
zIndex: 29,
|
|
615
|
+
});
|
|
616
|
+
qa(m.faces.to, "span").forEach((label) => animate(label, [{ opacity: 0 }, { offset: 0.85, opacity: 0 }, { opacity: 1 }], { duration: TRANSFORM_MS, easing: "linear" }));
|
|
617
|
+
animate(newSelected, REVEAL_UNDER_COPY, { duration: TRANSFORM_MS, easing: "linear", fill: "backwards" });
|
|
618
|
+
animate(ghost, out(12), { duration: 160 });
|
|
619
|
+
finish();
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (!forward) {
|
|
624
|
+
if (heldFill && fill && trackRect) {
|
|
625
|
+
if (newSelected) {
|
|
626
|
+
// The answer comes back out of the stretch of bar it became.
|
|
627
|
+
newSelected.dataset.morph = "";
|
|
628
|
+
const copy = pin(newSelected);
|
|
629
|
+
copy.style.zIndex = "32";
|
|
630
|
+
flyBack({ capsule: newSelected.getBoundingClientRect(), track: trackRect, fill, lo: toFraction, hi: fromFraction, answerClone: copy, liveAnswer: newSelected });
|
|
631
|
+
} else {
|
|
632
|
+
animate(fill, [{ transform: `translateX(${(fromFraction - 1) * 100}%)` }, { transform: `translateX(${(toFraction - 1) * 100}%)` }], {
|
|
633
|
+
duration: 300,
|
|
634
|
+
fill: "none",
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (photoFaceBack && oldImageRect && newSelected) {
|
|
639
|
+
// The photo becomes the answer again in one frame (morphFrame.ts): one geometry the whole way,
|
|
640
|
+
// closing into the answer's pill while travelling to it, the answer taking over under the blur
|
|
641
|
+
// and sharpening until the last frame.
|
|
642
|
+
newSelected.dataset.morph = "";
|
|
643
|
+
const r = newSelected.getBoundingClientRect();
|
|
644
|
+
const duration = TRANSFORM_MS;
|
|
645
|
+
const m = playMorph({
|
|
646
|
+
from: { rect: oldImageRect, radius: PHOTO_RADIUS },
|
|
647
|
+
to: { rect: r, radius: r.height / 2 },
|
|
648
|
+
faces: { from: photoFaceBack, to: fillFace(newSelected, r) },
|
|
649
|
+
duration,
|
|
650
|
+
handover: [0.7, 0.94],
|
|
651
|
+
});
|
|
652
|
+
// Its words come back last.
|
|
653
|
+
qa(m.faces.to, "span").forEach((label) => animate(label, [{ opacity: 0 }, { offset: 0.85, opacity: 0 }, { opacity: 1 }], { duration, easing: "linear" }));
|
|
654
|
+
// The live answer takes over under the frame (see REVEAL_UNDER_COPY).
|
|
655
|
+
animate(newSelected, REVEAL_UNDER_COPY, { duration, easing: "linear", fill: "backwards" });
|
|
656
|
+
|
|
657
|
+
if (handoff === "connect") {
|
|
658
|
+
// Every answer went into the photo, so every answer comes back out of it, from where the
|
|
659
|
+
// frame is when they start (60% of the way, on the same clock).
|
|
660
|
+
const k = glideAt(0.6);
|
|
661
|
+
const from = {
|
|
662
|
+
cx: lerp(oldImageRect.left + oldImageRect.width / 2, r.left + r.width / 2, k),
|
|
663
|
+
cy: lerp(oldImageRect.top + oldImageRect.height / 2, r.top + r.height / 2, k),
|
|
664
|
+
};
|
|
665
|
+
qa(page, "[data-flow-option]").forEach((el, k) => {
|
|
666
|
+
if (el === newSelected) return;
|
|
667
|
+
el.dataset.morph = "";
|
|
668
|
+
const c = centre(el.getBoundingClientRect());
|
|
669
|
+
animate(
|
|
670
|
+
el,
|
|
671
|
+
[
|
|
672
|
+
{ transform: `translate3d(${from.cx - c.x}px, ${from.cy - c.y}px, 0) scale(0.95)`, opacity: 0, filter: `blur(${motionBlur(5)}px)` },
|
|
673
|
+
{ offset: 0.55 + k * 0.04, transform: `translate3d(${from.cx - c.x}px, ${from.cy - c.y}px, 0) scale(0.95)`, opacity: 0, filter: `blur(${motionBlur(5)}px)`, easing: EASE_IN_OUT },
|
|
674
|
+
{ transform: "none", opacity: 1, filter: "blur(0px)" },
|
|
675
|
+
],
|
|
676
|
+
{ duration, easing: "linear", fill: "backwards" },
|
|
677
|
+
);
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
ghostLines.forEach((el) => animate(el, out(12), { duration: 150 }));
|
|
681
|
+
} else {
|
|
682
|
+
// Leave the way the page came in, quicker: re-explaining came from above, so it goes back up.
|
|
683
|
+
animate(ghost, out(handoff === "again" ? -12 : 12), { duration: 160 });
|
|
684
|
+
if (photoFaceBack && ghostImage) ghostImage.style.visibility = "";
|
|
685
|
+
}
|
|
686
|
+
finish();
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
switch (handoff) {
|
|
691
|
+
case "begin":
|
|
692
|
+
animate(
|
|
693
|
+
ghost,
|
|
694
|
+
[
|
|
695
|
+
{ transformOrigin: "50% 100%", transform: "perspective(900px) rotateX(0deg)", opacity: 1 },
|
|
696
|
+
{ transformOrigin: "50% 100%", transform: "perspective(900px) translate3d(0, -20px, 0) rotateX(22deg) scale(0.97)", opacity: 0 },
|
|
697
|
+
],
|
|
698
|
+
{ duration: 320, easing: EASE_IN_OUT },
|
|
699
|
+
);
|
|
700
|
+
break;
|
|
701
|
+
|
|
702
|
+
case "picture":
|
|
703
|
+
case "connect": {
|
|
704
|
+
ghostLines.forEach((el) => animate(el, out(-10), { duration: 180 }));
|
|
705
|
+
// The photo is known if the new <img> has loaded or the flow already decoded it: Safari loads even
|
|
706
|
+
// a cached image a moment after the element is created, so requiring the former alone meant the
|
|
707
|
+
// morph never ran there.
|
|
708
|
+
const photoKnown =
|
|
709
|
+
newImage instanceof HTMLImageElement && (loaded(newImage) || isImageReady(newImage.getAttribute("src") ?? ""));
|
|
710
|
+
if (!(answerFace && oldSelectedRect && photoKnown)) {
|
|
711
|
+
// No morph target (the photo still hasn't loaded): the answers leave, and the photo fades in
|
|
712
|
+
// on its own the moment it arrives.
|
|
713
|
+
if (oldSelectedIndex >= 0) ghostOptions[oldSelectedIndex].style.visibility = "";
|
|
714
|
+
ghostOptions.forEach((el) => animate(el, out(-10), { duration: 180 }));
|
|
715
|
+
if (newImage && !loaded(newImage as HTMLImageElement)) {
|
|
716
|
+
newImage.addEventListener("load", () => newImage.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 240, easing: EASE_OUT }), { once: true });
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
if (!newImage) break;
|
|
721
|
+
// Its CSS entrance is switched off before measuring: the morph is its entrance.
|
|
722
|
+
newImage.dataset.morph = "";
|
|
723
|
+
// Its box is reserved from its known size (WelcomePage sets width/height); if it isn't, derive the
|
|
724
|
+
// height from the decoded image rather than trusting a not-yet-loaded element's zero height.
|
|
725
|
+
const laidOut = newImage.getBoundingClientRect();
|
|
726
|
+
const size = imageSize(newImage.getAttribute("src") ?? "");
|
|
727
|
+
const r =
|
|
728
|
+
laidOut.height >= 1 || !size ? laidOut : new DOMRect(laidOut.left, laidOut.top, laidOut.width, (laidOut.width * size.height) / size.width);
|
|
729
|
+
const duration = TRANSFORM_MS;
|
|
730
|
+
const a = { cx: oldSelectedRect.left + oldSelectedRect.width / 2, cy: oldSelectedRect.top + oldSelectedRect.height / 2 };
|
|
731
|
+
|
|
732
|
+
if (handoff === "picture") {
|
|
733
|
+
ghostOptions.forEach((el, k) => k !== oldSelectedIndex && animate(el, out(-10), { duration: 180 }));
|
|
734
|
+
} else {
|
|
735
|
+
// Connect: the other answers gather into the chosen one (never below 95%) as it becomes the photo.
|
|
736
|
+
ghostOptions.forEach((el, k) => {
|
|
737
|
+
if (k === oldSelectedIndex) return;
|
|
738
|
+
const c = centre(el.getBoundingClientRect());
|
|
739
|
+
animate(
|
|
740
|
+
el,
|
|
741
|
+
[
|
|
742
|
+
{ transform: "none", opacity: 1, filter: "blur(0px)", easing: EASE_IN_OUT },
|
|
743
|
+
{ offset: 0.35, transform: `translate3d(${a.cx - c.x}px, ${a.cy - c.y}px, 0) scale(0.95)`, opacity: 0, filter: `blur(${motionBlur(5)}px)` },
|
|
744
|
+
{ transform: `translate3d(${a.cx - c.x}px, ${a.cy - c.y}px, 0) scale(0.95)`, opacity: 0, filter: `blur(${motionBlur(5)}px)` },
|
|
745
|
+
],
|
|
746
|
+
{ duration, easing: "linear", delay: Math.abs(k - oldSelectedIndex) * 30 },
|
|
747
|
+
);
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// The answer becomes the photo in one frame (morphFrame.ts): one geometry the whole way, the
|
|
752
|
+
// photo taking over under the blur and sharpening until the last frame.
|
|
753
|
+
const m = playMorph({
|
|
754
|
+
from: { rect: oldSelectedRect, radius: oldSelectedRect.height / 2 },
|
|
755
|
+
to: { rect: r, radius: PHOTO_RADIUS },
|
|
756
|
+
faces: { from: answerFace, to: photoFace(newImage) },
|
|
757
|
+
duration,
|
|
758
|
+
// Under the motion blur (25–75% of the time): p 0.45–0.75 is ~32–45% of the duration.
|
|
759
|
+
handover: [0.45, 0.75],
|
|
760
|
+
});
|
|
761
|
+
// Its words go first.
|
|
762
|
+
qa(m.faces.from, "span").forEach((label) => animate(label, [{ opacity: 1 }, { offset: 0.15, opacity: 0 }, { opacity: 0 }], { duration, easing: "linear" }));
|
|
763
|
+
// The live photo takes over under the frame (see REVEAL_UNDER_COPY).
|
|
764
|
+
animate(newImage, REVEAL_UNDER_COPY, { duration, easing: "linear", fill: "backwards" });
|
|
765
|
+
break;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
case "flood": {
|
|
769
|
+
// The chosen answer opens into the statement's full-screen colour: the most prominent thing on the
|
|
770
|
+
// next screen, and the answer's own colour. The words arrive on it afterwards (story-motion.css).
|
|
771
|
+
ghostLines.forEach((el) => animate(el, out(-10), { duration: 180 }));
|
|
772
|
+
ghostOptions.forEach((el, k) => k !== oldSelectedIndex && animate(el, out(-10), { duration: 180 }));
|
|
773
|
+
const backdrop = q(document, "[data-flow-backdrop]");
|
|
774
|
+
if (!(answerFace && oldSelectedRect && backdrop)) break;
|
|
775
|
+
backdrop.dataset.morph = "";
|
|
776
|
+
const m = playMorph({
|
|
777
|
+
from: { rect: oldSelectedRect, radius: oldSelectedRect.height / 2 },
|
|
778
|
+
to: { rect: backdrop.getBoundingClientRect(), radius: 0 },
|
|
779
|
+
faces: { from: answerFace, to: colorFace(getComputedStyle(backdrop).backgroundColor) },
|
|
780
|
+
duration: TRANSFORM_MS,
|
|
781
|
+
handover: [0.45, 0.75],
|
|
782
|
+
});
|
|
783
|
+
qa(m.faces.from, "span").forEach((label) => animate(label, [{ opacity: 1 }, { offset: 0.15, opacity: 0 }, { opacity: 0 }], { duration: TRANSFORM_MS, easing: "linear" }));
|
|
784
|
+
animate(backdrop, REVEAL_UNDER_COPY, { duration: TRANSFORM_MS, easing: "linear", fill: "backwards" });
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
case "absorb": {
|
|
789
|
+
// The statement's colour collapses into the stretch of progress bar this step earns: the
|
|
790
|
+
// statement becomes progress (the progress-bar exception to the size floor). Its words leave
|
|
791
|
+
// first, above the colour, one after another; the bar takes the stretch as the colour lands.
|
|
792
|
+
ghostLines.forEach((el, k) => animate(el, out(-10), { duration: 180, delay: k * 40 }));
|
|
793
|
+
if (!(oldBackdropRect && fill && trackRect)) break;
|
|
794
|
+
const { path, fillFrames, to } = intoBarPath(oldBackdropRect, 0, trackRect, fromFraction, toFraction);
|
|
795
|
+
playMorph({
|
|
796
|
+
from: { rect: oldBackdropRect, radius: 0 },
|
|
797
|
+
to: { rect: to, radius: to.height / 2 },
|
|
798
|
+
faces: { from: colorFace(backdropColor), to: colorFace(backdropColor) },
|
|
799
|
+
duration: FLIGHT_MS,
|
|
800
|
+
blur: 0,
|
|
801
|
+
zIndex: 29,
|
|
802
|
+
path,
|
|
803
|
+
steps: STEPS,
|
|
804
|
+
});
|
|
805
|
+
// The bar holds until the colour's edge reaches it, then grows with it (the same as a pill).
|
|
806
|
+
animate(fill, fillFrames, { duration: FLIGHT_MS, easing: "linear", fill: "none" });
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
case "inward":
|
|
811
|
+
animate(ghost, out(8, 0.92), { duration: 320 });
|
|
812
|
+
break;
|
|
813
|
+
|
|
814
|
+
case "slip":
|
|
815
|
+
animate(ghost, out(-28), { duration: 380 });
|
|
816
|
+
break;
|
|
817
|
+
|
|
818
|
+
case "fade":
|
|
819
|
+
ghostLines.forEach((el) => animate(el, out(-8), { duration: 200 }));
|
|
820
|
+
ghostOptions.forEach((el, k) => animate(el, out(-6 - k * 3), { duration: 220, delay: 40 + k * 60 }));
|
|
821
|
+
break;
|
|
822
|
+
|
|
823
|
+
case "gone":
|
|
824
|
+
animate(ghost, out(0, 0.98), { duration: 300 });
|
|
825
|
+
break;
|
|
826
|
+
|
|
827
|
+
case "blank":
|
|
828
|
+
animate(ghostImage, out(-16), { duration: 200 });
|
|
829
|
+
ghostLines.forEach((el) => animate(el, out(-8), { duration: 160, delay: 60 }));
|
|
830
|
+
break;
|
|
831
|
+
|
|
832
|
+
case "again":
|
|
833
|
+
animate(ghost, out(14), { duration: 200 });
|
|
834
|
+
break;
|
|
835
|
+
|
|
836
|
+
case "jolt":
|
|
837
|
+
animate(ghost, out(0, 0.98), { duration: 120 });
|
|
838
|
+
break;
|
|
839
|
+
|
|
840
|
+
case "cadence":
|
|
841
|
+
ghostLines.forEach((el) => animate(el, out(-8), { duration: 160 }));
|
|
842
|
+
ghostOptions.forEach((el, k) => animate(el, out(-10), { duration: 160, delay: k * 50, easing: "linear" }));
|
|
843
|
+
break;
|
|
844
|
+
|
|
845
|
+
case "settle":
|
|
846
|
+
animate(ghost, out(20), { duration: 320 });
|
|
847
|
+
break;
|
|
848
|
+
|
|
849
|
+
case "finish":
|
|
850
|
+
animate(ghost, out(-12), { duration: 220 });
|
|
851
|
+
break;
|
|
852
|
+
|
|
853
|
+
default:
|
|
854
|
+
animate(ghost, out(-12), { duration: 180 });
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
finish();
|
|
858
|
+
}
|