@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.
Files changed (139) hide show
  1. package/dist/{apple-CkKlHBZ9.js → apple-CSzNTGHM.js} +13 -13
  2. package/dist/auth.d.ts +1 -1
  3. package/dist/auth.js +3 -3
  4. package/dist/{billing-XCZU_T46.js → billing-C3Q8DBU2.js} +3 -3
  5. package/dist/{bind-drne__Ys.js → bind-BumHTi9O.js} +4 -4
  6. package/dist/{build-Gpdq5QXP.js → build-Bpviiclc.js} +6 -6
  7. package/dist/{client-DP6Rc0t_.js → client-BL0f_yGf.js} +2 -2
  8. package/dist/create-BSfvpWoD.js +19 -0
  9. package/dist/{create-Cwc3SRWJ.js → create-BUcVG4Ab.js} +23 -23
  10. package/dist/{create-BBrtgUgS.js → create-CfK3PeKA.js} +6 -6
  11. package/dist/{doctor-C9ldpPFC.js → doctor-BWqIYcMn.js} +6 -6
  12. package/dist/{drivers-DNrx4LWA.js → drivers-CPhdPkW5.js} +3 -3
  13. package/dist/entry.js +20 -21
  14. package/dist/{environment-DF1qKlny.js → environment-eBXjELoN.js} +1 -1
  15. package/dist/{existing-78LWSsqS.js → existing-BltvQiX5.js} +2 -2
  16. package/dist/held-CPve03KJ.js +16 -0
  17. package/dist/{held-Cy8Wl4D1.js → held-DgnTFMl3.js} +6 -6
  18. package/dist/{integrate-DcJhpXy8.js → integrate-BRsqoe01.js} +22 -22
  19. package/dist/{login-B2TsCE2H.js → login-BCEH5q0U.js} +1 -1
  20. package/dist/login-BPOONe7n.js +16 -0
  21. package/dist/{login-D0lh3_JI.js → login-BbTIrCFT.js} +5 -5
  22. package/dist/{lookup-D-nmmAbw.js → lookup-rr1AkCJA.js} +2 -2
  23. package/dist/{migrate-Cfec564E.js → migrate-C9X2Vz81.js} +22 -22
  24. package/dist/{notification-url-YDbq6FMA.js → notification-url-CV86qiKP.js} +2 -2
  25. package/dist/{open-Ba2vBl1_.js → open-CcpXotHG.js} +10 -10
  26. package/dist/{org-D0g_q3mv.js → org-BQQDo7wm.js} +2 -2
  27. package/dist/{paths-DxSLdpOI.js → paths-CRlU72cq.js} +1 -1
  28. package/dist/{playbook-DIeb7hne.js → playbook-DVMXN7fh.js} +10 -10
  29. package/dist/{promote-COD4fYdz.js → promote-Da8xctzy.js} +16 -16
  30. package/dist/push-BV-grvQg.js +22 -0
  31. package/dist/{push-CncywhkQ.js → push-D6R9icWN.js} +27 -14
  32. package/dist/{registry-DSrosOYs.js → registry-BYVD-_h6.js} +206 -49
  33. package/dist/{resources-Dqr01Dep.js → resources-DLON3-61.js} +18 -6
  34. package/dist/{run-C9qg_QlC.js → run-Co-BwhOg.js} +2 -2
  35. package/dist/scan-B88OlWOt.js +4 -0
  36. package/dist/{scan-DLrsrFS9.js → scan-CKuk-_6W.js} +1 -1
  37. package/dist/{scope-V336uz8j.js → scope-DV22_Ufm.js} +4 -4
  38. package/dist/{selection-Rdw-ZUoG.js → selection-C2_KbLuo.js} +10 -4
  39. package/dist/server-C4f6ccUr.js +22 -0
  40. package/dist/{server-D0tGG8C4.js → server-D0d2oP-5.js} +10 -8
  41. package/dist/{session-CFAmMhem.js → session-B-Uz0cQ7.js} +1 -1
  42. package/dist/session-BuvArt1j.js +6 -0
  43. package/dist/{session-D_nEWKXT.js → session-C4rbE3VS.js} +41 -13
  44. package/dist/skills/superwall-framework/SKILL.md +7 -3
  45. package/dist/skills/superwall-framework/references/cli.md +1 -0
  46. package/dist/skills/superwall-framework/references/layout.md +34 -1
  47. package/dist/{skills-DMG4bpKk.js → skills-CLGJuMnF.js} +8 -8
  48. package/dist/{skills-BvFOa4y6.js → skills-CZcpnEnG.js} +5 -4
  49. package/dist/{spinner-CneRK5rk.js → spinner-C2U6QBJ9.js} +3 -3
  50. package/dist/{storage-s2Dnz-yl.js → storage-6h9vyiAz.js} +1 -1
  51. package/dist/storekit-CK9JmM2D.js +16 -0
  52. package/dist/{storekit-yY_kS2iR.js → storekit-CinJra3V.js} +3 -3
  53. package/dist/{telemetry-DtG92m5O.js → telemetry-DKyDhURo.js} +1 -1
  54. package/dist/{token-DzRh7dI1.js → token-DaxQgQkv.js} +1 -1
  55. package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
  56. package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
  57. package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
  58. package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
  59. package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
  60. package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
  61. package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  62. package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
  63. package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
  64. package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  65. package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
  66. package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
  67. package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
  68. package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
  69. package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
  70. package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  71. package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  72. package/dist/tools-skills/mobile-design/SKILL.md +447 -0
  73. package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
  74. package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
  75. package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
  76. package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
  77. package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
  78. package/dist/tools-skills/superwall/SKILL.md +263 -0
  79. package/dist/tools-skills/superwall/references/api.md +303 -0
  80. package/dist/tools-skills/superwall/references/asa.md +166 -0
  81. package/dist/tools-skills/superwall/references/asc.md +95 -0
  82. package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
  83. package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
  84. package/dist/tools-skills/superwall/references/docs.md +51 -0
  85. package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
  86. package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
  87. package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
  88. package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
  89. package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
  90. package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
  91. package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
  92. package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
  93. package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
  94. package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
  95. package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
  96. package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
  97. package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
  98. package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
  99. package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
  100. package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
  101. package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
  102. package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
  103. package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
  104. package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
  105. package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
  106. package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
  107. package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
  108. package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
  109. package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
  110. package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
  111. package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
  112. package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
  113. package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
  114. package/dist/tools-skills/superwall-editor/references/design.md +51 -0
  115. package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
  116. package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
  117. package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
  118. package/dist/tools-skills/wwdc/SKILL.md +22 -0
  119. package/dist/tools-skills/wwdc/references/docs.md +52 -0
  120. package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
  121. package/dist/tools.d.ts +1 -1
  122. package/dist/tools.js +200 -18
  123. package/dist/{upgrade-Bt4Ouw1y.js → upgrade-DPo0a4Es.js} +1 -1
  124. package/dist/{upgrade-Cqy5orjb.js → upgrade-ffseQDMx.js} +2 -2
  125. package/package.json +2 -2
  126. package/dist/create-Yvf2gStM.js +0 -19
  127. package/dist/held-Ddw1XSsr.js +0 -16
  128. package/dist/kinds-GFXB3sYu.js +0 -11
  129. package/dist/login-BoBe8Psl.js +0 -16
  130. package/dist/push-CtD4FZQV.js +0 -22
  131. package/dist/scan-Cv5uOwVY.js +0 -4
  132. package/dist/send-BxD9yf6F.js +0 -150
  133. package/dist/server-z1LH94R_.js +0 -22
  134. package/dist/session-1AV_Bs_d.js +0 -6
  135. package/dist/storekit-DafAnGkM.js +0 -16
  136. /package/dist/{devtools-ByZ6XYnn.js → devtools-pBl_vt03.js} +0 -0
  137. /package/dist/{reports-DdPq4blM.js → reports-D_qbl7_u.js} +0 -0
  138. /package/dist/{screenshot-file-0UETadF8.js → screenshot-file-tVBfUEIi.js} +0 -0
  139. /package/dist/{storage-DYvmIOHa.d.ts → storage-CerJ5KLP.d.ts} +0 -0
@@ -0,0 +1,356 @@
1
+ // THE way to morph Frame A into Frame B (one frame, two faces, one geometry), as shipped on
2
+ // Reflective's web2app, with one addition for the superwall framework: the frame is mounted into
3
+ // the layout's motion layer (`mount`), never `document.body`, because a surface never positions
4
+ // anything fixed and its pages are absolute layers inside the framework's content box.
5
+
6
+ import { decodedCopy } from "./imageReady";
7
+
8
+ /**
9
+ * Frame A → Frame B morphs. The one rule: **A and B share the same geometry at
10
+ * every moment of the transition.** Not "two copies driven by the same numbers" —
11
+ * those drift apart the moment one has its own rounded corners, border, margin,
12
+ * blur or rounding error, and the eye catches it instantly.
13
+ *
14
+ * So there is exactly one frame, and it alone owns the geometry:
15
+ *
16
+ * outer (fixed at `home`, no transform) — the blur, in screen pixels
17
+ * middle — the transform: translate to the box's centre, scale only *up*
18
+ * clipper — the clip-path: the box's size and corner radius
19
+ * face A — fills the clipper; opacity only
20
+ * face B — fills the clipper; opacity only, on top
21
+ *
22
+ * The faces never have a shape of their own (no radius, border, margin or
23
+ * transform of their own): they fill the frame, and the frame's clip is the
24
+ * only outline anyone sees. A and B cannot differ in geometry because there is
25
+ * only one geometry.
26
+ *
27
+ * Usage, answer → photo:
28
+ *
29
+ * const answer = fillFace(answerEl, answerRect); // capture before the page swaps
30
+ * // …swap the page…
31
+ * const { frame, animations, faces } = morph({
32
+ * from: { rect: answerRect, radius: answerRect.height / 2 },
33
+ * to: { rect: photoRect, radius: 20 },
34
+ * faces: { from: answer, to: photoFace(photoEl) },
35
+ * duration: 504,
36
+ * });
37
+ */
38
+
39
+ /**
40
+ * One switch for every blur in the hand-offs (the morph frame's motion blur and the answers gathering
41
+ * into a photo). Off gives the same motion with no blur.
42
+ */
43
+ export const MOTION_BLUR_ENABLED = true;
44
+ /** A blur amount, or 0 while motion blur is switched off. */
45
+ export const motionBlur = (px: number) => (MOTION_BLUR_ENABLED ? px : 0);
46
+
47
+ export type MorphEnd = { rect: DOMRect; radius: number };
48
+ /** Builds a face that fills the frame; given the frame's home rect (its size when unscaled). */
49
+ export type Face = (home: DOMRect) => HTMLElement;
50
+
51
+ /** The frame's shape at one moment, in screen pixels: centre, size, corner radius. */
52
+ export type Box = { cx: number; cy: number; w: number; h: number; r: number };
53
+
54
+ /** A corner radius as a fraction of the shape's shorter side (0.5 = fully round ends). */
55
+ export const roundness = (radius: number, w: number, h: number) =>
56
+ Math.min(0.5, radius / Math.max(1e-6, Math.min(w, h)));
57
+
58
+ export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
59
+ /** 0 before `a`, 1 after `b`, linear in between. */
60
+ export const span = (t: number, a: number, b: number) =>
61
+ t <= a ? 0 : t >= b ? 1 : (t - a) / (b - a);
62
+ /** 0 → 1 across [a, b] with zero speed at both ends. */
63
+ export const ease01 = (t: number, a: number, b: number) => {
64
+ const k = span(t, a, b);
65
+ return k * k * (3 - 2 * k);
66
+ };
67
+
68
+ /**
69
+ * The A → B clock: a critically damped spring (ζ = 1, Apple's default for UI: no overshoot) chasing
70
+ * a target that eases in from rest after a barely-there pull-back (~1%). It speeds up to its top
71
+ * speed early (~27% of the time) and then slows continuously over a long, gentle tail, so there's
72
+ * no constant-speed middle and no snap at the end; a final taper lands it exactly at rest on the
73
+ * last frame. Speed is continuous everywhere and zero at both ends.
74
+ *
75
+ * Tried and dropped: a quintic ease to a 1.5% overshoot at 82% with a ~90ms settle (linear-feeling
76
+ * middle, snappy bounce at the end); a stiff spring (~6% overshoot, back in ~75ms); stock
77
+ * ease-in-out-back (10% both ways, rushed middle).
78
+ */
79
+ const CLOCK_RAMP = 0.25; // the target eases in over the first quarter
80
+ const CLOCK_OMEGA = 9; // spring stiffness, per transition length
81
+ const CLOCK_PULL = 0.6; // → ~1% pull-back
82
+ const CLOCK_TAPER = 0.12; // the last 12% eases the spring's tail exactly onto the target
83
+ const CLOCK_SAMPLES = 1200;
84
+ let clockTable: Float64Array | null = null;
85
+
86
+ function buildClock(): Float64Array {
87
+ const smoother = (u: number) => {
88
+ const k = Math.min(1, Math.max(0, u));
89
+ return k * k * k * (k * (k * 6 - 15) + 10);
90
+ };
91
+ const table = new Float64Array(CLOCK_SAMPLES + 1);
92
+ const dt = 1 / CLOCK_SAMPLES;
93
+ let x = 0;
94
+ let v = 0;
95
+ for (let i = 0; i <= CLOCK_SAMPLES; i++) {
96
+ const s = smoother((i * dt) / CLOCK_RAMP);
97
+ const target = s - CLOCK_PULL * Math.sin(Math.PI * s) * (1 - s);
98
+ table[i] = x;
99
+ v += (CLOCK_OMEGA * CLOCK_OMEGA * (target - x) - 2 * CLOCK_OMEGA * v) * dt; // ζ = 1
100
+ x += v * dt;
101
+ }
102
+ const end = table[CLOCK_SAMPLES];
103
+ for (let i = 0; i <= CLOCK_SAMPLES; i++) {
104
+ const y = table[i] / end;
105
+ table[i] = y + (1 - y) * ease01(i / CLOCK_SAMPLES, 1 - CLOCK_TAPER, 1);
106
+ }
107
+ return table;
108
+ }
109
+
110
+ export function glideAt(t: number): number {
111
+ clockTable ??= buildClock();
112
+ const f = Math.min(1, Math.max(0, t)) * CLOCK_SAMPLES;
113
+ const i = Math.floor(f);
114
+ return i >= CLOCK_SAMPLES
115
+ ? clockTable[CLOCK_SAMPLES]
116
+ : clockTable[i] + (clockTable[i + 1] - clockTable[i]) * (f - i);
117
+ }
118
+
119
+ /** Samples per morph; every channel is sampled from the same clock at the same instants. */
120
+ export const MORPH_STEPS = 30;
121
+
122
+ /** Up to a 20% dip for a dimension about equal at both ends (a bubble squeezing through); none once they differ by half. */
123
+ const dipFor = (x: number, y: number) =>
124
+ 0.2 * Math.max(0, 1 - (Math.max(x, y) / Math.min(x, y) - 1) / 0.5);
125
+
126
+ /**
127
+ * The frame's box at clock value p (0 = a, 1 = b; a hair below 0 at the start). It travels
128
+ * on p and opens on p^1.5, so the move leads and the opening follows without either restarting;
129
+ * size only interpolates between the ends (never below 80% of the smaller); a dimension equal at
130
+ * both ends dips and swells back.
131
+ *
132
+ * Corners are proportional: the radius is interpolated as a fraction of the shorter side (its
133
+ * "roundness"), not in pixels. A fully round answer (0.5) opening into a square background (0)
134
+ * stays visibly rounded while it's big and only goes square at the end; pixel interpolation would
135
+ * leave a big frame with tiny, sharp-looking corners almost at once.
136
+ */
137
+ function boxAt(a: Box, b: Box, p: number): Box {
138
+ const open = Math.sign(p) * Math.pow(Math.abs(p), 1.5);
139
+ const bulge = Math.sin(Math.PI * p);
140
+ const w = lerp(a.w, b.w, open) * (1 - dipFor(a.w, b.w) * bulge);
141
+ const h = lerp(a.h, b.h, open) * (1 - dipFor(a.h, b.h) * bulge);
142
+ const round = lerp(
143
+ roundness(a.r, a.w, a.h),
144
+ roundness(b.r, b.w, b.h),
145
+ Math.min(1, Math.max(0, open)),
146
+ );
147
+ return { cx: lerp(a.cx, b.cx, p), cy: lerp(a.cy, b.cy, p), w, h, r: round * Math.min(w, h) };
148
+ }
149
+
150
+ const boxOf = ({ rect, radius }: MorphEnd): Box => ({
151
+ cx: rect.left + rect.width / 2,
152
+ cy: rect.top + rect.height / 2,
153
+ w: rect.width,
154
+ h: rect.height,
155
+ r: radius,
156
+ });
157
+
158
+ /** Makes `el` fill its parent exactly, with no shape of its own. */
159
+ function fill(el: HTMLElement) {
160
+ el.removeAttribute("style");
161
+ Object.assign(el.style, {
162
+ position: "absolute",
163
+ left: "0",
164
+ top: "0",
165
+ width: "100%",
166
+ height: "100%",
167
+ margin: "0",
168
+ border: "0",
169
+ borderRadius: "0",
170
+ boxShadow: "none",
171
+ transform: "none",
172
+ animation: "none",
173
+ transition: "none",
174
+ });
175
+ return el;
176
+ }
177
+
178
+ /** A photo face: the decoded image covering the frame exactly as it covers its own box at rest. */
179
+ export function photoFace(img: HTMLImageElement): Face {
180
+ const copy = fill(decodedCopy(img));
181
+ copy.style.objectFit = "cover";
182
+ return () => copy;
183
+ }
184
+
185
+ /**
186
+ * A face for a filled element (an answer capsule, a button): its colour fills the whole frame, so
187
+ * the frame's shape is the only shape, and a copy of its content sits where the element rests.
188
+ * Captures the element now (call it before the page swaps, while the element still exists).
189
+ */
190
+ export function fillFace(el: HTMLElement, rest: DOMRect): Face {
191
+ const background = getComputedStyle(el).backgroundColor;
192
+ const content = el.cloneNode(true) as HTMLElement;
193
+ return (home) => {
194
+ const face = fill(document.createElement("div"));
195
+ face.style.background = background;
196
+ // Where the frame shows the element's own box, its content must sit: centred, at rest size
197
+ // (scaled by 1/k when that box is larger than the frame's home, as the frame scales it by k).
198
+ const k = Math.max(1, rest.width / home.width, rest.height / home.height);
199
+ content.removeAttribute("style");
200
+ Object.assign(content.style, {
201
+ position: "absolute",
202
+ left: `${(home.width - rest.width) / 2}px`,
203
+ top: `${(home.height - rest.height) / 2}px`,
204
+ width: `${rest.width}px`,
205
+ height: `${rest.height}px`,
206
+ margin: "0",
207
+ background: "transparent",
208
+ border: "0",
209
+ boxShadow: "none",
210
+ transform: k === 1 ? "none" : `scale(${1 / k})`,
211
+ animation: "none",
212
+ transition: "none",
213
+ });
214
+ face.appendChild(content);
215
+ return face;
216
+ };
217
+ }
218
+
219
+ /**
220
+ * A face that's just a colour: for a destination (or source) whose look is its fill, like a
221
+ * page background that ties to the chosen answer's colour.
222
+ */
223
+ export function colorFace(color: string): Face {
224
+ return () => {
225
+ const face = fill(document.createElement("div"));
226
+ face.style.background = color;
227
+ return face;
228
+ };
229
+ }
230
+
231
+ /**
232
+ * Morph Frame A into Frame B. `handover` is the clock window over which B fades in on top of A
233
+ * (A stays opaque underneath until B is fully in, so the frame never goes see-through); keep it
234
+ * inside the blur window so the swap happens under the blur. The blur is motion blur: crisp at both
235
+ * ends, blurred only while it's moving fastest — from 25% to 75% of the duration (easing in over
236
+ * 25–35%, full 35–65%, easing out over 65–75%). Returns the frame (remove it when done) and its
237
+ * animations (await them).
238
+ */
239
+ export function morph({
240
+ from,
241
+ to,
242
+ faces,
243
+ duration,
244
+ handover = [0.45, 0.75],
245
+ blur = 5,
246
+ blurWindow = [0.25, 0.75],
247
+ zIndex = 31,
248
+ path,
249
+ steps = MORPH_STEPS,
250
+ mount,
251
+ }: {
252
+ from: MorphEnd;
253
+ to: MorphEnd;
254
+ faces: { from: Face; to: Face };
255
+ duration: number;
256
+ /** Clock window (p) over which B takes over. */
257
+ handover?: [number, number];
258
+ /** Peak blur, on-screen px. */
259
+ blur?: number;
260
+ /** Time window (fraction of the duration) the blur spans; crisp outside it. */
261
+ blurWindow?: [number, number];
262
+ zIndex?: number;
263
+ /**
264
+ * The frame's shape at each moment t (0–1), for a move with its own geometry (e.g. into the
265
+ * progress bar, right edge first). Must start exactly on `from` and end exactly on `to`.
266
+ */
267
+ path?: (t: number) => Box;
268
+ /** Keyframe samples (make steps × any key moment a whole number so a sample lands on it). */
269
+ steps?: number;
270
+ /**
271
+ * Where the frame lives: a positioned layer and that layer's screen rect, so the frame is placed
272
+ * at `rect - origin` inside it. Defaults to document.body at page coordinates.
273
+ */
274
+ mount?: { into: HTMLElement; origin: { left: number; top: number } };
275
+ }) {
276
+ // Home: the larger end, so the frame is only ever scaled up (never squashed).
277
+ const home =
278
+ from.rect.width * from.rect.height >= to.rect.width * to.rect.height ? from.rect : to.rect;
279
+ const outer = document.createElement("div");
280
+ outer.setAttribute("aria-hidden", "true");
281
+ outer.setAttribute("data-handoff-clone", "");
282
+ const origin = mount?.origin ?? { left: -window.scrollX, top: -window.scrollY };
283
+ Object.assign(outer.style, {
284
+ position: "absolute",
285
+ left: `${home.left - origin.left}px`,
286
+ top: `${home.top - origin.top}px`,
287
+ width: `${home.width}px`,
288
+ height: `${home.height}px`,
289
+ zIndex: String(zIndex),
290
+ pointerEvents: "none",
291
+ });
292
+ const middle = fill(document.createElement("div"));
293
+ middle.style.transformOrigin = "50% 50%";
294
+ const clipper = fill(document.createElement("div"));
295
+ clipper.style.overflow = "hidden";
296
+ const faceA = faces.from(home);
297
+ const faceB = faces.to(home);
298
+ clipper.append(faceA, faceB);
299
+ middle.appendChild(clipper);
300
+ outer.appendChild(middle);
301
+ (mount?.into ?? document.body).appendChild(outer);
302
+
303
+ const a = boxOf(from);
304
+ const b = boxOf(to);
305
+ const homeCx = home.left + home.width / 2;
306
+ const homeCy = home.top + home.height / 2;
307
+ const [h0, h1] = handover;
308
+ const [b0, b1] = blurWindow;
309
+ const ramp = (b1 - b0) * 0.2;
310
+ const samples = Array.from({ length: steps + 1 }, (_, i) => ({
311
+ t: i / steps,
312
+ p: glideAt(i / steps),
313
+ }));
314
+
315
+ const middleFrames: Keyframe[] = [];
316
+ const clipFrames: Keyframe[] = [];
317
+ const outerFrames: Keyframe[] = [];
318
+ const aFrames: Keyframe[] = [];
319
+ const bFrames: Keyframe[] = [];
320
+ for (const { t, p } of samples) {
321
+ const box = path ? path(t) : boxAt(a, b, p);
322
+ // Scale only up, when the box is bigger than home; the clip shows the box, in local pixels.
323
+ const k = Math.max(1, box.w / home.width, box.h / home.height);
324
+ const w = box.w / k;
325
+ const h = box.h / k;
326
+ middleFrames.push({
327
+ offset: t,
328
+ transform: `translate3d(${box.cx - homeCx}px, ${box.cy - homeCy}px, 0) scale(${k})`,
329
+ });
330
+ clipFrames.push({
331
+ offset: t,
332
+ clipPath: `inset(${(home.height - h) / 2}px ${(home.width - w) / 2}px round ${box.r / k}px)`,
333
+ });
334
+ // Motion blur: only while it's moving fastest, crisp at both ends.
335
+ const amount = ease01(t, b0, b0 + ramp) * (1 - ease01(t, b1 - ramp, b1));
336
+ outerFrames.push({ offset: t, filter: `blur(${(motionBlur(blur) * amount).toFixed(3)}px)` });
337
+ bFrames.push({ offset: t, opacity: ease01(p, h0, h1) });
338
+ // A fades out gradually, from halfway through B's fade-in to a little after it. Never in one
339
+ // step: when B is translucent (a selected answer is 90%), whatever is under it shows through, and
340
+ // switching A off at once changes that instantly — a mid-morph brightness jump.
341
+ aFrames.push({
342
+ offset: t,
343
+ opacity: 1 - ease01(p, (h0 + h1) / 2, Math.min(1, h1 + (h1 - h0) / 2)),
344
+ });
345
+ }
346
+
347
+ const options: KeyframeAnimationOptions = { duration, easing: "linear", fill: "both" };
348
+ const animations = [
349
+ middle.animate(middleFrames, options),
350
+ clipper.animate(clipFrames, options),
351
+ outer.animate(outerFrames, options),
352
+ faceA.animate(aFrames, options),
353
+ faceB.animate(bFrames, options),
354
+ ];
355
+ return { frame: outer, animations, faces: { from: faceA, to: faceB } };
356
+ }
@@ -0,0 +1,41 @@
1
+ # Performance
2
+
3
+ "It's choppy, weird artefacts everywhere, not premium" was the first reaction
4
+ to a version that used View Transitions and blur everywhere. It ran at 15fps.
5
+ Premium motion is smooth motion first.
6
+
7
+ ## What may animate
8
+
9
+ | Property | Verdict |
10
+ |---|---|
11
+ | `transform`, `opacity` | Yes. Composited; nothing re-rasterises. |
12
+ | `filter: blur()` | Only on one element at a time: the A → B morph frame's outer wrapper (5px peak), never on text blocks, whole pages or lists. |
13
+ | `backdrop-filter` | Never on something that moves. Drop frosted-glass backgrounds on answers in the animated flow (over a soft gradient the difference is barely visible). |
14
+ | `clip-path` | Sanctioned for one element at a time: the A → B morph frame's clipper, its only outline (reshapes it without squashing corners). Not for page-wide wipes or reveals. |
15
+ | `width`, `height`, `top`, `left` | No. Progress fills slide with `translateX` inside an `overflow: hidden` track. |
16
+ | View Transitions (`document.startViewTransition`) | No, for page hand-offs: snapshot artefacts, stretched morphs, full-page re-compositing. |
17
+
18
+ Also:
19
+ - Keep simultaneous animated layers modest (tens, not hundreds).
20
+ - Clones are cheap; blur on a big clone is not.
21
+ - Don't animate CSS custom properties on a parent to drive children; write the
22
+ transform on the element.
23
+
24
+ ## Diagnosing "it's slow"
25
+
26
+ 1. **Judge a production build**, not the dev server (unminified React,
27
+ StrictMode double effects). Serve the build on an unused port
28
+ (`vite preview --port <free> --strictPort --host 0.0.0.0`).
29
+ 2. **Compare against the old motion** on the same build (`?motion=classic`).
30
+ If both are slow, it isn't your motion.
31
+ 3. **Check the browser's GPU.** In Chrome/Dia/Arc, open `chrome://gpu`. If it
32
+ says *Compositing: Software only* or *GPU process was unable to boot: GPU
33
+ access is disabled due to frequent crashes*, every page is being drawn on
34
+ the CPU (at 5K on a 2× display that caps any animation near 20–25fps).
35
+ A full browser restart clears the crash block; a disabled flag such as
36
+ Skia Graphite may be the cause (reset it in `chrome://flags`). Recheck
37
+ that Compositing and Rasterization say *Hardware accelerated*.
38
+ 4. Only then optimise the page, starting with anything on the "no" list above.
39
+
40
+ Real users (mostly phones from ads) have working GPUs; don't strip the design
41
+ for one broken browser, but do make it transform/opacity-only regardless.
@@ -0,0 +1,17 @@
1
+ # The web-runtime engine (not for surfaces)
2
+
3
+ `handoffs.ts` and `story-motion.css` are the hand-off engine as it first
4
+ shipped, in a hand-rolled web2app runtime that swaps pages itself: it clones
5
+ the outgoing page, pins the clone, keys entrances on its own
6
+ `data-motion` / `data-flow-transition` / `data-handoff` attributes, and
7
+ positions some copies with `position: fixed`.
8
+
9
+ On a Superwall surface none of that applies. The framework's router swaps
10
+ the pages, keeps the leaving one mounted and stamps `data-sw-transition` and
11
+ `data-sw-phase` on every layer, so the engine is `../framework/` instead:
12
+ no clone, exits and entrances as CSS on those attributes, flights in a
13
+ layout-level motion layer. Building a page swapper, a custom router or a
14
+ fixed copy on a surface is the wrong build, whatever this code made easy.
15
+
16
+ Read these files only when the user keeps a flow in their own web runtime
17
+ and has declined to move it to a surface.