@superwall/studio 1.1.0 → 1.2.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 (50) hide show
  1. package/README.md +93 -14
  2. package/dist/assets/index-CVKQ82YR.js +11 -0
  3. package/dist/assets/index-_HCp6gCi.css +1 -0
  4. package/dist/index.html +2 -2
  5. package/dist/lib/StudioApp.d.ts +7 -0
  6. package/dist/lib/components/ActionMenu.d.ts +13 -0
  7. package/dist/lib/components/CompareMenu.d.ts +13 -0
  8. package/dist/lib/components/DeviceChrome.d.ts +12 -0
  9. package/dist/lib/components/DeviceFrame.d.ts +18 -0
  10. package/dist/lib/components/MissingProducts.d.ts +8 -0
  11. package/dist/lib/components/OpenInApp.d.ts +5 -0
  12. package/dist/lib/components/PaywallToasts.d.ts +5 -0
  13. package/dist/lib/components/SidePanel.d.ts +6 -0
  14. package/dist/lib/components/StudioShell.d.ts +4 -0
  15. package/dist/lib/components/SurfaceCard.d.ts +9 -0
  16. package/dist/lib/components/Toolbar.d.ts +6 -0
  17. package/dist/lib/components/TopBar.d.ts +8 -0
  18. package/dist/lib/components/VariablesPanel.d.ts +13 -0
  19. package/dist/lib/components/controls.d.ts +24 -0
  20. package/dist/lib/components/icons.d.ts +20 -0
  21. package/dist/lib/icon.svg +5 -0
  22. package/dist/lib/index.d.ts +14 -0
  23. package/dist/lib/index.js +1746 -0
  24. package/dist/lib/lib/actions.d.ts +4 -0
  25. package/dist/lib/lib/devices.d.ts +26 -0
  26. package/dist/lib/lib/events.d.ts +27 -0
  27. package/dist/lib/lib/preview.d.ts +7 -0
  28. package/dist/lib/lib/products.d.ts +16 -0
  29. package/dist/lib/lib/project.d.ts +12 -0
  30. package/dist/lib/lib/time.d.ts +1 -0
  31. package/dist/lib/lib/types.d.ts +77 -0
  32. package/dist/lib/products.js +51 -0
  33. package/dist/lib/screens/SurfaceEditor.d.ts +9 -0
  34. package/dist/lib/screens/SurfaceList.d.ts +7 -0
  35. package/dist/lib/studio.css +1 -0
  36. package/package.json +15 -4
  37. package/src/StudioApp.tsx +3 -2
  38. package/src/components/ActionMenu.tsx +1 -1
  39. package/src/components/CompareMenu.tsx +1 -1
  40. package/src/components/PaywallToasts.tsx +1 -0
  41. package/src/components/StudioShell.tsx +12 -0
  42. package/src/index.ts +9 -1
  43. package/src/lib/events.ts +10 -1
  44. package/src/lib/preview.ts +10 -0
  45. package/src/lib/products.ts +97 -0
  46. package/src/lib/types.ts +2 -0
  47. package/src/screens/SurfaceEditor.tsx +31 -12
  48. package/src/styles.css +8 -6
  49. package/dist/assets/index-CVKGrx00.js +0 -11
  50. package/dist/assets/index-D4RIpSbg.css +0 -1
@@ -0,0 +1,1746 @@
1
+ import { jsx as t, jsxs as o, Fragment as U } from "react/jsx-runtime";
2
+ import * as d from "react";
3
+ import { toast as D, Toaster as Xe } from "sonner";
4
+ const et = ({
5
+ children: e,
6
+ position: n = "fixed"
7
+ }) => /* @__PURE__ */ t(
8
+ "div",
9
+ {
10
+ className: `sw-studio bg-ink text-cream ${n} inset-0 flex flex-col font-sans text-[0.9375rem] tracking-[-0.01em] antialiased`,
11
+ children: e
12
+ }
13
+ ), y = ({ children: e }) => /* @__PURE__ */ t("svg", { className: "sw-icon", viewBox: "0 0 24 24", "aria-hidden": "true", children: e }), Ie = () => /* @__PURE__ */ o(y, { children: [
14
+ /* @__PURE__ */ t("path", { d: "M21 12a9 9 0 1 1-2.64-6.36" }),
15
+ /* @__PURE__ */ t("path", { d: "M21 3v6h-6" })
16
+ ] }), Z = () => /* @__PURE__ */ o(y, { children: [
17
+ /* @__PURE__ */ t("path", { d: "M15 3h6v6" }),
18
+ /* @__PURE__ */ t("path", { d: "M10 14 21 3" }),
19
+ /* @__PURE__ */ t("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" })
20
+ ] }), tt = () => /* @__PURE__ */ o(y, { children: [
21
+ /* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "4" }),
22
+ /* @__PURE__ */ t("path", { d: "M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" })
23
+ ] }), nt = () => /* @__PURE__ */ t(y, { children: /* @__PURE__ */ t("path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" }) }), st = () => /* @__PURE__ */ o(y, { children: [
24
+ /* @__PURE__ */ t("path", { d: "M21 4h-7M10 4H3M21 12h-9M8 12H3M21 20h-5M12 20H3" }),
25
+ /* @__PURE__ */ t("path", { d: "M14 2v4M8 10v4M16 18v4" })
26
+ ] }), Oe = () => /* @__PURE__ */ t(y, { children: /* @__PURE__ */ t("path", { d: "M18 6 6 18M6 6l12 12" }) }), Re = () => /* @__PURE__ */ t(y, { children: /* @__PURE__ */ t("path", { d: "m6 9 6 6 6-6" }) }), at = () => /* @__PURE__ */ o(y, { children: [
27
+ /* @__PURE__ */ t("rect", { x: "3", y: "4", width: "18", height: "16" }),
28
+ /* @__PURE__ */ t("path", { d: "M12 4v16" })
29
+ ] }), we = () => /* @__PURE__ */ o(y, { children: [
30
+ /* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "9" }),
31
+ /* @__PURE__ */ t("path", { d: "m8.5 12 2.5 2.5 4.5-5" })
32
+ ] }), ve = () => /* @__PURE__ */ o(y, { children: [
33
+ /* @__PURE__ */ t("path", { d: "M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z" }),
34
+ /* @__PURE__ */ t("path", { d: "M12 9v4" }),
35
+ /* @__PURE__ */ t("path", { d: "M12 17h.01" })
36
+ ] }), rt = () => /* @__PURE__ */ o(y, { children: [
37
+ /* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "9" }),
38
+ /* @__PURE__ */ t("path", { d: "M12 11v5" }),
39
+ /* @__PURE__ */ t("path", { d: "M12 8h.01" })
40
+ ] }), K = () => /* @__PURE__ */ t(y, { children: /* @__PURE__ */ t("path", { d: "M13 2 4.5 13H11l-1 9 8.5-11H12l1-9Z" }) }), re = () => /* @__PURE__ */ o(y, { children: [
41
+ /* @__PURE__ */ t("circle", { cx: "9", cy: "20", r: "1" }),
42
+ /* @__PURE__ */ t("circle", { cx: "18", cy: "20", r: "1" }),
43
+ /* @__PURE__ */ t("path", { d: "M2 3h2.5l2.2 11.2a2 2 0 0 0 2 1.6h8.4a2 2 0 0 0 2-1.6L21 7H5.4" })
44
+ ] }), it = () => /* @__PURE__ */ o(y, { children: [
45
+ /* @__PURE__ */ t("path", { d: "M18 8a6 6 0 1 0-12 0c0 6-2 8-2 8h16s-2-2-2-8" }),
46
+ /* @__PURE__ */ t("path", { d: "M13.7 21a2 2 0 0 1-3.4 0" })
47
+ ] }), lt = () => /* @__PURE__ */ t(y, { children: /* @__PURE__ */ t("path", { d: "m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1L3.2 9.5l6.1-.9L12 3Z" }) }), ot = () => /* @__PURE__ */ o(y, { children: [
48
+ /* @__PURE__ */ t("path", { d: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" }),
49
+ /* @__PURE__ */ t("circle", { cx: "12", cy: "7", r: "4" })
50
+ ] }), ct = () => /* @__PURE__ */ o(y, { children: [
51
+ /* @__PURE__ */ t("rect", { x: "4", y: "2", width: "10", height: "16", rx: "2" }),
52
+ /* @__PURE__ */ t("path", { d: "M17 12a5 5 0 0 1-5 9H9" }),
53
+ /* @__PURE__ */ t("path", { d: "m11 19-2 2 2 2" })
54
+ ] }), Q = {
55
+ push: ["link", "build", "assets", "push", "source"],
56
+ publish: ["link", "build", "assets", "push", "source", "promote"],
57
+ promote: ["link", "promote"]
58
+ }, dt = {
59
+ link: "Find paywall",
60
+ build: "Build snapshot",
61
+ assets: "Sync assets",
62
+ push: "Push version",
63
+ source: "Push source",
64
+ promote: "Promote to live"
65
+ }, je = [
66
+ { name: "push", label: "Push", hint: "New version, nothing live changes" },
67
+ { name: "publish", label: "Publish", hint: "Push and make it live" },
68
+ { name: "promote", label: "Promote", hint: "Make the latest push live" }
69
+ ], de = (e) => je.find((n) => n.name === e)?.label ?? e, Le = {
70
+ push: "Pushing…",
71
+ publish: "Publishing…",
72
+ promote: "Promoting…"
73
+ }, pt = ({ state: e }) => e === "active" ? /* @__PURE__ */ t("span", { className: "bg-accent h-2 w-2 animate-pulse" }) : e === "done" ? /* @__PURE__ */ t("span", { className: "bg-accent h-2 w-2" }) : e === "failed" ? /* @__PURE__ */ t("span", { className: "bg-red h-2 w-2" }) : /* @__PURE__ */ t("span", { className: "bg-cream/55 h-2 w-2" }), ht = ({ progress: e }) => {
74
+ const n = Q[e.action], s = n.filter((r) => e.steps[r] === "done").length, a = e.error !== void 0;
75
+ return /* @__PURE__ */ o("div", { className: "w-64", children: [
76
+ /* @__PURE__ */ o("div", { className: "border-b border-cream/10 px-3 py-2.5", children: [
77
+ /* @__PURE__ */ t("div", { className: "text-[0.8125rem] font-medium", children: a ? `${de(e.action)} failed` : s === n.length ? `${de(e.action)} complete` : Le[e.action] }),
78
+ /* @__PURE__ */ t("div", { className: "mt-2 h-0.5 w-full bg-cream/10", children: /* @__PURE__ */ t(
79
+ "div",
80
+ {
81
+ className: `h-full transition-[width] duration-300 ease-out ${a ? "bg-red" : "bg-accent"}`,
82
+ style: { width: `${s / n.length * 100}%` }
83
+ }
84
+ ) })
85
+ ] }),
86
+ /* @__PURE__ */ t("ul", { className: "m-0 list-none px-3 py-2", children: n.map((r, i) => {
87
+ const c = e.steps[r] ?? "pending";
88
+ return /* @__PURE__ */ o("li", { className: "flex items-center gap-2.5 py-1.5", children: [
89
+ /* @__PURE__ */ t(
90
+ "span",
91
+ {
92
+ className: `w-4 font-mono text-[0.625rem] tabular-nums ${c === "pending" ? "text-cream/25" : "text-cream/55"}`,
93
+ children: String(i + 1).padStart(2, "0")
94
+ }
95
+ ),
96
+ /* @__PURE__ */ t(
97
+ "span",
98
+ {
99
+ className: `flex-1 text-[0.8125rem] ${c === "pending" ? "text-cream/40" : "text-cream"}`,
100
+ children: dt[r]
101
+ }
102
+ ),
103
+ /* @__PURE__ */ t(pt, { state: c })
104
+ ] }, r);
105
+ }) }),
106
+ e.error && /* @__PURE__ */ t("div", { className: "text-red border-t border-cream/10 px-3 py-2.5 text-xs whitespace-pre-wrap", children: e.error })
107
+ ] });
108
+ }, mt = ({
109
+ progress: e,
110
+ blocked: n,
111
+ onRun: s,
112
+ onBlocked: a
113
+ }) => {
114
+ const [r, i] = d.useState("push"), [c, f] = d.useState(!1), u = d.useRef(null), l = n !== void 0, h = e !== void 0 && e.error === void 0 && Q[e.action].some((b) => e.steps[b] !== "done"), w = e !== void 0;
115
+ return d.useEffect(() => {
116
+ if (!c) return;
117
+ const b = (m) => {
118
+ u.current && !m.composedPath().includes(u.current) && f(!1);
119
+ };
120
+ return window.addEventListener("mousedown", b), () => window.removeEventListener("mousedown", b);
121
+ }, [c]), /* @__PURE__ */ o("div", { className: "relative flex", ref: u, children: [
122
+ /* @__PURE__ */ t(
123
+ "button",
124
+ {
125
+ type: "button",
126
+ className: "sw-btn sw-btn--primary disabled:cursor-not-allowed disabled:opacity-40",
127
+ disabled: h,
128
+ title: n,
129
+ onClick: () => l ? a?.() : s(r),
130
+ children: h ? Le[e.action] : de(r)
131
+ }
132
+ ),
133
+ /* @__PURE__ */ t(
134
+ "button",
135
+ {
136
+ type: "button",
137
+ className: "sw-btn sw-btn--primary -ml-px w-6 !px-0 disabled:cursor-not-allowed disabled:opacity-40",
138
+ "aria-label": "Choose action",
139
+ "aria-expanded": c,
140
+ title: n,
141
+ disabled: h,
142
+ onClick: () => f((b) => !b),
143
+ children: /* @__PURE__ */ t(Re, {})
144
+ }
145
+ ),
146
+ (w || c) && /* @__PURE__ */ t("div", { className: "bg-bar absolute top-full right-0 z-20 mt-1 border border-cream/20", children: w ? /* @__PURE__ */ t(ht, { progress: e }) : /* @__PURE__ */ t("div", { className: "w-64", children: je.map((b) => /* @__PURE__ */ o(
147
+ "button",
148
+ {
149
+ type: "button",
150
+ className: "flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left transition-colors hover:bg-cream/5",
151
+ onClick: () => {
152
+ i(b.name), f(!1);
153
+ },
154
+ children: [
155
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] font-medium", children: b.label }),
156
+ /* @__PURE__ */ t("span", { className: "text-xs text-cream/55", children: b.hint })
157
+ ]
158
+ },
159
+ b.name
160
+ )) }) })
161
+ ] });
162
+ }, ie = ({
163
+ label: e,
164
+ hint: n,
165
+ selected: s,
166
+ onSelect: a
167
+ }) => /* @__PURE__ */ o(
168
+ "button",
169
+ {
170
+ type: "button",
171
+ className: "flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left transition-colors hover:bg-cream/5",
172
+ "aria-current": s || void 0,
173
+ onClick: a,
174
+ children: [
175
+ /* @__PURE__ */ o("span", { className: "flex max-w-full items-center gap-1.5 text-[0.8125rem] font-medium", children: [
176
+ /* @__PURE__ */ t("span", { className: "truncate", children: e }),
177
+ s && /* @__PURE__ */ t("span", { className: "bg-accent size-[5px] shrink-0 rounded-full", "aria-hidden": "true" })
178
+ ] }),
179
+ /* @__PURE__ */ t("span", { className: "max-w-full truncate text-xs text-cream/55", children: n })
180
+ ]
181
+ }
182
+ ), ut = ({
183
+ active: e,
184
+ options: n,
185
+ onSelect: s
186
+ }) => {
187
+ const [a, r] = d.useState(!1), [i, c] = d.useState(""), f = d.useRef(null);
188
+ d.useEffect(() => {
189
+ if (!a) return;
190
+ const m = (E) => {
191
+ f.current && !E.composedPath().includes(f.current) && r(!1);
192
+ };
193
+ return window.addEventListener("mousedown", m), () => window.removeEventListener("mousedown", m);
194
+ }, [a]), d.useEffect(() => {
195
+ a || c("");
196
+ }, [a]);
197
+ const u = e && (e.type === "live" ? "live" : `surface:${e.surface.kind}/${e.surface.id}`), l = (m) => {
198
+ r(!1), s(m);
199
+ }, h = i.trim().toLowerCase(), w = n.filter((m) => m.key === "live"), b = n.filter((m) => m.key !== "live").filter(
200
+ (m) => h === "" || `${m.label} ${m.hint}`.toLowerCase().includes(h)
201
+ );
202
+ return /* @__PURE__ */ o("div", { className: "relative flex", ref: f, children: [
203
+ /* @__PURE__ */ o(
204
+ "button",
205
+ {
206
+ type: "button",
207
+ className: "sw-btn",
208
+ "aria-pressed": e !== void 0,
209
+ "aria-expanded": a,
210
+ onClick: () => r((m) => !m),
211
+ children: [
212
+ /* @__PURE__ */ t(at, {}),
213
+ "Compare"
214
+ ]
215
+ }
216
+ ),
217
+ a && /* @__PURE__ */ o("div", { className: "bg-bar absolute bottom-full left-0 z-20 mb-1 flex w-72 flex-col border border-cream/20", children: [
218
+ /* @__PURE__ */ t("div", { className: "p-2", children: /* @__PURE__ */ t(
219
+ "input",
220
+ {
221
+ className: "sw-input",
222
+ type: "search",
223
+ value: i,
224
+ placeholder: "Search paywalls",
225
+ "aria-label": "Search paywalls",
226
+ onChange: (m) => c(m.target.value)
227
+ }
228
+ ) }),
229
+ /* @__PURE__ */ t("div", { className: "max-h-64 overflow-y-auto", children: b.length === 0 ? /* @__PURE__ */ t("span", { className: "block px-3 pt-2 pb-4 text-[0.8125rem] text-cream/45", children: h === "" ? "No other paywalls here." : `Nothing matches “${i.trim()}”.` }) : b.map((m) => /* @__PURE__ */ t(
230
+ ie,
231
+ {
232
+ label: m.label,
233
+ hint: m.hint,
234
+ selected: m.key === u,
235
+ onSelect: () => l(m.target)
236
+ },
237
+ m.key
238
+ )) }),
239
+ /* @__PURE__ */ o("div", { className: "flex flex-col border-t border-cream/10", children: [
240
+ w.map((m) => /* @__PURE__ */ t(
241
+ ie,
242
+ {
243
+ label: m.label,
244
+ hint: m.hint,
245
+ selected: m.key === u,
246
+ onSelect: () => l(m.target)
247
+ },
248
+ m.key
249
+ )),
250
+ /* @__PURE__ */ t(
251
+ ie,
252
+ {
253
+ label: "Off",
254
+ hint: "A single preview",
255
+ selected: e === void 0,
256
+ onSelect: () => l(void 0)
257
+ }
258
+ )
259
+ ] })
260
+ ] })
261
+ ] });
262
+ }, ft = () => /* @__PURE__ */ o("svg", { width: "19", height: "12", viewBox: "0 0 19 12", fill: "currentColor", "aria-hidden": "true", children: [
263
+ /* @__PURE__ */ t("rect", { x: "0", y: "7.5", width: "3.5", height: "4.5", rx: "1" }),
264
+ /* @__PURE__ */ t("rect", { x: "5", y: "5", width: "3.5", height: "7", rx: "1" }),
265
+ /* @__PURE__ */ t("rect", { x: "10", y: "2.5", width: "3.5", height: "9.5", rx: "1" }),
266
+ /* @__PURE__ */ t("rect", { x: "15", y: "0", width: "3.5", height: "12", rx: "1" })
267
+ ] }), bt = () => /* @__PURE__ */ o("svg", { width: "27", height: "13", viewBox: "0 0 27 13", "aria-hidden": "true", children: [
268
+ /* @__PURE__ */ t(
269
+ "rect",
270
+ {
271
+ x: "0.5",
272
+ y: "0.5",
273
+ width: "23",
274
+ height: "12",
275
+ rx: "3.8",
276
+ fill: "none",
277
+ stroke: "currentColor",
278
+ strokeOpacity: "0.35"
279
+ }
280
+ ),
281
+ /* @__PURE__ */ t("path", { d: "M25 4.5v4a2.17 2.17 0 0 0 0-4Z", fill: "currentColor", fillOpacity: "0.4" }),
282
+ /* @__PURE__ */ t("rect", { x: "2", y: "2", width: "20", height: "9", rx: "2.5", fill: "currentColor" })
283
+ ] }), wt = () => /* @__PURE__ */ o("span", { className: "flex items-center gap-[7px]", children: [
284
+ /* @__PURE__ */ t(ft, {}),
285
+ /* @__PURE__ */ t("span", { style: { fontSize: 12.5, fontWeight: 700, letterSpacing: "0.02em" }, children: "SW" }),
286
+ /* @__PURE__ */ t(bt, {})
287
+ ] }), vt = ({
288
+ spec: e,
289
+ width: n,
290
+ height: s,
291
+ landscape: a,
292
+ theme: r
293
+ }) => {
294
+ const i = r === "dark" ? "rgba(255,255,255,0.95)" : "rgba(0,0,0,0.95)", c = Math.max(28, e.radius * 0.6);
295
+ return /* @__PURE__ */ o(
296
+ "div",
297
+ {
298
+ className: "pointer-events-none absolute inset-0 select-none",
299
+ style: { width: n, height: s, color: i },
300
+ "data-testid": "device-chrome",
301
+ children: [
302
+ !a && /* @__PURE__ */ o(
303
+ "div",
304
+ {
305
+ className: "absolute inset-x-0 top-0 flex items-center justify-between",
306
+ style: {
307
+ height: e.statusBarHeight,
308
+ paddingLeft: c,
309
+ paddingRight: c,
310
+ fontFamily: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif',
311
+ fontSize: 15,
312
+ fontWeight: 600,
313
+ letterSpacing: "-0.2px"
314
+ },
315
+ children: [
316
+ /* @__PURE__ */ t("span", { children: "9:41" }),
317
+ /* @__PURE__ */ t(wt, {})
318
+ ]
319
+ }
320
+ ),
321
+ e.cutout === "island" && (a ? /* @__PURE__ */ t(
322
+ "div",
323
+ {
324
+ className: "absolute rounded-full bg-black",
325
+ style: { left: 12, top: (s - 124) / 2, width: 36, height: 124 }
326
+ }
327
+ ) : /* @__PURE__ */ t(
328
+ "div",
329
+ {
330
+ className: "absolute rounded-full bg-black",
331
+ style: { left: (n - 124) / 2, top: 12, width: 124, height: 36 }
332
+ }
333
+ )),
334
+ e.cutout === "punch" && (a ? /* @__PURE__ */ t(
335
+ "div",
336
+ {
337
+ className: "absolute rounded-full bg-black",
338
+ style: { left: 16, top: (s - 13) / 2, width: 13, height: 13 }
339
+ }
340
+ ) : /* @__PURE__ */ t(
341
+ "div",
342
+ {
343
+ className: "absolute rounded-full bg-black",
344
+ style: { left: (n - 13) / 2, top: 15, width: 13, height: 13 }
345
+ }
346
+ )),
347
+ e.homeIndicator && /* @__PURE__ */ t(
348
+ "div",
349
+ {
350
+ className: "absolute rounded-full",
351
+ style: {
352
+ width: Math.round(Math.min(n, s) * 0.36),
353
+ height: 5,
354
+ left: "50%",
355
+ transform: "translateX(-50%)",
356
+ bottom: 8,
357
+ background: i,
358
+ opacity: 0.9
359
+ }
360
+ }
361
+ )
362
+ ]
363
+ }
364
+ );
365
+ }, ge = 96, gt = 250, Te = (e, n, s) => {
366
+ const [a, r] = d.useState(1);
367
+ return d.useLayoutEffect(() => {
368
+ const i = e.current;
369
+ if (!i) return;
370
+ const c = () => {
371
+ const u = i.getBoundingClientRect(), l = Math.min(
372
+ 1,
373
+ (u.width - ge) / n,
374
+ (u.height - ge) / s
375
+ );
376
+ r(Math.max(0.1, l));
377
+ };
378
+ if (c(), typeof ResizeObserver > "u") return;
379
+ const f = new ResizeObserver(c);
380
+ return f.observe(i), () => f.disconnect();
381
+ }, [e, n, s]), a;
382
+ }, xt = ({
383
+ width: e,
384
+ height: n,
385
+ stageRef: s,
386
+ children: a
387
+ }) => {
388
+ const r = Te(s, e, n);
389
+ return /* @__PURE__ */ t(
390
+ "div",
391
+ {
392
+ className: "flex flex-none items-center justify-center overflow-hidden border border-dashed border-cream/20 p-6 text-center text-sm text-cream/55",
393
+ "data-testid": "device-placeholder",
394
+ style: { width: e * r, height: n * r },
395
+ children: a
396
+ }
397
+ );
398
+ }, yt = (e, n, s) => {
399
+ try {
400
+ const a = window.location.origin, r = new URL(n, a), i = new URL(s, a);
401
+ if (r.origin !== i.origin || r.pathname !== i.pathname) return !1;
402
+ const c = e?.contentWindow?.__swPreviewApply;
403
+ return typeof c != "function" ? !1 : (c(i.search), !0);
404
+ } catch {
405
+ return !1;
406
+ }
407
+ }, Nt = ({
408
+ width: e,
409
+ height: n,
410
+ title: s,
411
+ src: a,
412
+ stageRef: r,
413
+ reloadKey: i = 0,
414
+ chrome: c,
415
+ landscape: f = !1,
416
+ theme: u = "light"
417
+ }) => {
418
+ const l = Te(r, e, n), h = d.useRef(0), [w, b] = d.useState([
419
+ { mountSrc: a, currentSrc: a, generation: 0, ready: !0 }
420
+ ]), m = d.useRef(w);
421
+ m.current = w;
422
+ const E = d.useRef(/* @__PURE__ */ new Map()), j = d.useRef(!1), L = d.useRef(i);
423
+ d.useEffect(() => {
424
+ if (!j.current) {
425
+ j.current = !0;
426
+ return;
427
+ }
428
+ const g = i !== L.current;
429
+ if (L.current = i, !g) {
430
+ const x = m.current.findLast((O) => O.ready), M = x ? E.current.get(x.generation) : void 0;
431
+ if (x && yt(M, x.currentSrc, a)) {
432
+ b(
433
+ (O) => O.map(
434
+ (T) => T.generation === x.generation ? { ...T, currentSrc: a } : T
435
+ )
436
+ );
437
+ return;
438
+ }
439
+ }
440
+ h.current += 1;
441
+ const S = {
442
+ mountSrc: a,
443
+ currentSrc: a,
444
+ generation: h.current,
445
+ ready: !1
446
+ };
447
+ b((x) => [...x.filter((M) => M.ready).slice(-1), S]);
448
+ }, [a, i]);
449
+ const C = (g) => {
450
+ window.setTimeout(() => {
451
+ b((S) => S.some((x) => x.generation === g) ? S.map((x) => x.generation === g ? { ...x, ready: !0 } : x).filter((x) => x.generation >= g) : S);
452
+ }, gt);
453
+ }, X = w.findLast((g) => g.ready), F = c ? c.radius * l : 0;
454
+ return /* @__PURE__ */ o(
455
+ "div",
456
+ {
457
+ className: `bg-panel relative flex-none overflow-hidden ${c ? "shadow-[0_0_0_1px] shadow-cream/25" : "border border-cream/20"}`,
458
+ "data-testid": "device-frame",
459
+ style: { width: e * l, height: n * l, borderRadius: F },
460
+ children: [
461
+ w.map((g) => /* @__PURE__ */ t(
462
+ "iframe",
463
+ {
464
+ ref: (S) => {
465
+ S ? E.current.set(g.generation, S) : E.current.delete(g.generation);
466
+ },
467
+ className: `absolute inset-0 origin-top-left border-0 bg-white transition-opacity duration-150 ${g === X ? "opacity-100" : "opacity-0"}`,
468
+ title: s,
469
+ src: g.mountSrc,
470
+ width: e,
471
+ height: n,
472
+ style: { transform: `scale(${l})` },
473
+ onLoad: () => {
474
+ g.ready || C(g.generation);
475
+ }
476
+ },
477
+ g.generation
478
+ )),
479
+ c && /* @__PURE__ */ t(
480
+ "div",
481
+ {
482
+ className: "pointer-events-none absolute inset-0 origin-top-left",
483
+ style: { width: e, height: n, transform: `scale(${l})` },
484
+ children: /* @__PURE__ */ t(
485
+ vt,
486
+ {
487
+ spec: c,
488
+ width: e,
489
+ height: n,
490
+ landscape: f,
491
+ theme: u
492
+ }
493
+ )
494
+ }
495
+ )
496
+ ]
497
+ }
498
+ );
499
+ }, St = ({
500
+ paywall: e,
501
+ missing: n,
502
+ onDismiss: s
503
+ }) => /* @__PURE__ */ t(
504
+ "div",
505
+ {
506
+ className: "fixed inset-0 z-50 flex items-center justify-center bg-ink/70 p-6",
507
+ role: "dialog",
508
+ "aria-modal": "true",
509
+ "aria-labelledby": "sw-missing-products",
510
+ children: /* @__PURE__ */ o("div", { className: "bg-panel flex w-full max-w-md flex-col gap-4 border border-cream/20 p-5", children: [
511
+ /* @__PURE__ */ o("div", { className: "flex flex-col gap-1.5", children: [
512
+ /* @__PURE__ */ t("span", { id: "sw-missing-products", className: "text-[0.9375rem] font-medium text-cream", children: n.length === 1 ? "A product is missing" : `${n.length} products are missing` }),
513
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] leading-relaxed text-cream/60", children: `${e} declares ${n.length === 1 ? "a product" : "products"} Superwall has no record of. Every variable on ${n.length === 1 ? "it" : "them"} will be undefined here and on device.` })
514
+ ] }),
515
+ /* @__PURE__ */ t("ul", { className: "flex flex-col gap-1.5 border-y border-cream/10 py-3", children: n.map((a) => /* @__PURE__ */ o("li", { className: "flex items-baseline justify-between gap-3", children: [
516
+ /* @__PURE__ */ t("span", { className: "font-mono text-[11px] text-cream/70", children: a.reference }),
517
+ /* @__PURE__ */ t("span", { className: "truncate font-mono text-[11px] text-cream/40", children: a.identifier })
518
+ ] }, a.reference)) }),
519
+ /* @__PURE__ */ o("span", { className: "text-xs text-cream/45", children: [
520
+ "Add ",
521
+ n.length === 1 ? "it" : "them",
522
+ " in the Superwall dashboard, or point the config at",
523
+ n.length === 1 ? " a product" : " products",
524
+ " that exists. Pushing is refused until then."
525
+ ] }),
526
+ /* @__PURE__ */ t("button", { type: "button", className: "sw-btn sw-btn--primary self-end", onClick: s, children: "View anyway" })
527
+ ] })
528
+ }
529
+ ), Ae = "superwall-studio", kt = /* @__PURE__ */ new Set([
530
+ "ping",
531
+ "page_view",
532
+ "page_styles",
533
+ "has_set_dom",
534
+ "haptic_feedback",
535
+ "var_click",
536
+ "template_variables",
537
+ "template_substitutions_prefix",
538
+ "products",
539
+ "paywall_open",
540
+ "experiment",
541
+ "purchase"
542
+ ]), _t = {
543
+ open_url: ["url"],
544
+ open_url_external: ["url"],
545
+ open_deep_link: ["link", "url"],
546
+ custom_placement: ["name", "placementName"],
547
+ custom: ["name", "data"],
548
+ request_permission: ["permissionType"],
549
+ request_callback: ["name"],
550
+ schedule_notification: ["title"]
551
+ }, Pt = /* @__PURE__ */ new Set(["close", "transaction_abandon", "transaction_fail"]), Et = /* @__PURE__ */ new Set(["transaction_complete", "freeTrial_start"]), Ct = (e) => {
552
+ for (const n of _t[e.event_name] ?? []) {
553
+ const s = e[n];
554
+ if (typeof s == "string" && s.length > 0) return s;
555
+ }
556
+ }, Mt = (e) => {
557
+ if (!kt.has(e.event_name))
558
+ return {
559
+ action: e.event_name,
560
+ subject: Ct(e),
561
+ tone: Pt.has(e.event_name) ? "warning" : Et.has(e.event_name) ? "success" : "info"
562
+ };
563
+ }, De = (e) => typeof e == "object" && e !== null && Reflect.get(e, "channel") === Ae && ["hello", "event", "ask"].includes(String(Reflect.get(e, "type"))), $t = (e) => Array.isArray(e) && e.every((n) => typeof n == "string"), It = (e) => De(e) && e.type === "hello" && $t(e.locales) ? e.locales : void 0, Ot = {
564
+ info: "text-cream/45",
565
+ success: "text-accent",
566
+ warning: "text-red"
567
+ }, Rt = {
568
+ purchase: re,
569
+ transaction_complete: we,
570
+ freeTrial_start: we,
571
+ transaction_abandon: ve,
572
+ transaction_fail: ve,
573
+ close: Oe,
574
+ restore: Ie,
575
+ open_url: Z,
576
+ open_url_external: Z,
577
+ open_deep_link: Z,
578
+ initiate_web_checkout: re,
579
+ open_payment_sheet: re,
580
+ custom_placement: K,
581
+ custom: K,
582
+ request_permission: K,
583
+ request_callback: K,
584
+ schedule_notification: it,
585
+ request_store_review: lt,
586
+ user_attribute_updated: ot
587
+ }, H = ({ children: e }) => /* @__PURE__ */ t("span", { className: "bg-accent/15 text-accent px-1.5 py-px font-mono text-xs whitespace-nowrap", children: e }), he = ({
588
+ action: e,
589
+ tone: n,
590
+ children: s,
591
+ actions: a
592
+ }) => {
593
+ const r = Rt[e] ?? rt;
594
+ return /* @__PURE__ */ t("div", { className: "bg-panel font-sans w-[344px] border border-cream/15 p-3 shadow-[0_8px_24px_-8px] shadow-black/60", children: /* @__PURE__ */ o("div", { className: "grid grid-cols-[14px_1fr] items-start gap-x-2.5", children: [
595
+ /* @__PURE__ */ t("span", { className: `flex h-5 items-center justify-center ${Ot[n]}`, children: /* @__PURE__ */ t(r, {}) }),
596
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] leading-5 font-medium text-cream", children: s }),
597
+ a && /* @__PURE__ */ t("div", { className: "col-start-2 mt-2.5 flex justify-end gap-2", children: a })
598
+ ] }) });
599
+ }, jt = ({ notice: e }) => /* @__PURE__ */ o(he, { action: e.action, tone: e.tone, children: [
600
+ "Tap triggered a ",
601
+ /* @__PURE__ */ t(H, { children: e.action }),
602
+ e.subject ? /* @__PURE__ */ o(U, { children: [
603
+ " for ",
604
+ /* @__PURE__ */ t(H, { children: e.subject })
605
+ ] }) : " action",
606
+ "."
607
+ ] }), xe = {
608
+ completed: { action: "transaction_complete", tone: "success", label: "purchase completed." },
609
+ abandoned: { action: "transaction_abandon", tone: "warning", label: "purchase abandoned." },
610
+ granted: { action: "request_permission", tone: "success", label: "granted." },
611
+ denied: { action: "request_permission", tone: "warning", label: "denied." },
612
+ success: { action: "request_callback", tone: "success", label: "succeeded." },
613
+ failure: { action: "request_callback", tone: "warning", label: "failed." }
614
+ }, Lt = ({ outcome: e, subject: n }) => {
615
+ const s = xe[e] ?? xe.completed;
616
+ return /* @__PURE__ */ o(he, { action: s?.action ?? "purchase", tone: s?.tone ?? "info", children: [
617
+ /* @__PURE__ */ t(H, { children: n }),
618
+ " ",
619
+ s?.label
620
+ ] });
621
+ }, ye = {
622
+ purchase: { action: "purchase", verb: "purchase", no: "Abandon", yes: "Complete" },
623
+ permission: { action: "request_permission", verb: "permission", no: "Deny", yes: "Grant" },
624
+ callback: { action: "request_callback", verb: "callback", no: "Fail", yes: "Succeed" }
625
+ }, Tt = {
626
+ purchase: ["abandoned", "completed"],
627
+ permission: ["denied", "granted"],
628
+ callback: ["failure", "success"]
629
+ }, At = ({
630
+ kind: e,
631
+ subject: n,
632
+ onAnswer: s
633
+ }) => {
634
+ const a = ye[e] ?? ye.purchase, [r, i] = Tt[e] ?? ["abandoned", "completed"];
635
+ return /* @__PURE__ */ o(
636
+ he,
637
+ {
638
+ action: a?.action ?? "purchase",
639
+ tone: "info",
640
+ actions: /* @__PURE__ */ o(U, { children: [
641
+ /* @__PURE__ */ t("button", { type: "button", className: "sw-btn", onClick: () => s(r), children: a?.no }),
642
+ /* @__PURE__ */ t("button", { type: "button", className: "sw-btn sw-btn--primary", onClick: () => s(i), children: a?.yes })
643
+ ] }),
644
+ children: [
645
+ "Tap triggered a ",
646
+ /* @__PURE__ */ t(H, { children: a?.verb }),
647
+ " for ",
648
+ /* @__PURE__ */ t(H, { children: n }),
649
+ "."
650
+ ]
651
+ }
652
+ );
653
+ }, Dt = ({
654
+ surfaceKey: e,
655
+ raised: n = !1
656
+ }) => (d.useEffect(() => {
657
+ D.dismiss();
658
+ }, [e]), d.useEffect(() => {
659
+ const s = (a) => {
660
+ if (!De(a.data)) return;
661
+ if (a.data.type === "ask") {
662
+ const { id: i, kind: c, subject: f } = a.data, u = (l) => {
663
+ a.source?.postMessage(
664
+ { channel: Ae, type: "answer", id: i, outcome: l },
665
+ "*"
666
+ ), D.dismiss(i), D.custom(() => /* @__PURE__ */ t(Lt, { outcome: l, subject: f }));
667
+ };
668
+ D.custom(() => /* @__PURE__ */ t(At, { kind: c, subject: f, onAnswer: u }), {
669
+ id: i,
670
+ duration: Number.POSITIVE_INFINITY
671
+ });
672
+ return;
673
+ }
674
+ if (a.data.type !== "event") return;
675
+ const r = Mt(a.data.message);
676
+ r && D.custom(() => /* @__PURE__ */ t(jt, { notice: r }));
677
+ };
678
+ return window.addEventListener("message", s), () => window.removeEventListener("message", s);
679
+ }, []), /* @__PURE__ */ t(
680
+ Xe,
681
+ {
682
+ position: "top-center",
683
+ swipeDirections: ["top"],
684
+ offset: n ? 84 : 52,
685
+ gap: 8,
686
+ visibleToasts: 3,
687
+ style: { zIndex: 5 },
688
+ toastOptions: { unstyled: !0, classNames: { toast: "w-full" } }
689
+ }
690
+ )), Bt = ({
691
+ value: e,
692
+ options: n,
693
+ onChange: s,
694
+ label: a
695
+ }) => /* @__PURE__ */ t("div", { className: "sw-segmented", role: "group", "aria-label": a, children: n.map((r) => /* @__PURE__ */ t(
696
+ "button",
697
+ {
698
+ type: "button",
699
+ "aria-pressed": r.value === e,
700
+ onClick: () => s(r.value),
701
+ children: r.label
702
+ },
703
+ r.value
704
+ )) }), Ne = ({
705
+ value: e,
706
+ options: n,
707
+ onChange: s,
708
+ label: a
709
+ }) => /* @__PURE__ */ t(
710
+ "select",
711
+ {
712
+ className: "sw-select",
713
+ "aria-label": a,
714
+ value: e,
715
+ onChange: (r) => s(r.target.value),
716
+ children: n.map((r) => /* @__PURE__ */ t("option", { value: r.value, children: r.label }, r.value))
717
+ }
718
+ ), Ut = ({
719
+ checked: e,
720
+ onChange: n,
721
+ label: s
722
+ }) => /* @__PURE__ */ t(
723
+ "button",
724
+ {
725
+ type: "button",
726
+ role: "switch",
727
+ "aria-checked": e,
728
+ "aria-label": s,
729
+ className: "sw-switch",
730
+ onClick: () => n(!e)
731
+ }
732
+ ), Ht = ({
733
+ open: e,
734
+ title: n,
735
+ onClose: s,
736
+ children: a
737
+ }) => /* @__PURE__ */ t(
738
+ "aside",
739
+ {
740
+ className: `flex-none overflow-hidden transition-[width] duration-200 ease-out motion-reduce:transition-none ${e ? "w-72" : "w-0"}`,
741
+ "aria-hidden": !e,
742
+ inert: !e,
743
+ children: /* @__PURE__ */ o("div", { className: "bg-bar flex h-full w-72 flex-col border-l border-cream/10", children: [
744
+ /* @__PURE__ */ o("div", { className: "flex h-11 flex-none items-center justify-between border-b border-cream/10 px-3", children: [
745
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] font-medium text-cream", children: n }),
746
+ /* @__PURE__ */ t(
747
+ "button",
748
+ {
749
+ type: "button",
750
+ className: "sw-btn sw-btn--icon border-transparent",
751
+ "aria-label": `Close ${n.toLowerCase()}`,
752
+ onClick: s,
753
+ children: /* @__PURE__ */ t(Oe, {})
754
+ }
755
+ )
756
+ ] }),
757
+ /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto px-4 py-2", children: a })
758
+ ] })
759
+ }
760
+ ), Ft = ({ children: e }) => /* @__PURE__ */ t("div", { className: "bg-bar z-10 flex min-h-14 flex-none flex-wrap items-center justify-center gap-3 border-t border-cream/10 px-4 py-2.5", children: e }), G = ({ label: e, children: n }) => /* @__PURE__ */ o("div", { className: "flex items-center gap-2.5", children: [
761
+ /* @__PURE__ */ t("span", { className: "sw-tool-label", children: e }),
762
+ n
763
+ ] }), Se = () => /* @__PURE__ */ t("span", { className: "h-6 w-px bg-cream/10" }), Be = ({
764
+ title: e,
765
+ onHome: n,
766
+ actions: s,
767
+ inset: a = !1,
768
+ label: r = "Studio"
769
+ }) => /* @__PURE__ */ t("header", { className: "relative z-10 flex h-11 flex-none items-center border-b border-cream/10 bg-ink", children: /* @__PURE__ */ o(
770
+ "div",
771
+ {
772
+ className: `flex h-full w-full items-center px-3 ${a ? "mx-auto max-w-[1080px] sm:px-0" : ""}`,
773
+ children: [
774
+ /* @__PURE__ */ o(
775
+ "a",
776
+ {
777
+ className: "flex items-center gap-3 text-[0.9375rem] font-semibold tracking-[0.01em]",
778
+ href: "/",
779
+ onClick: (i) => {
780
+ i.metaKey || i.ctrlKey || (i.preventDefault(), n());
781
+ },
782
+ children: [
783
+ /* @__PURE__ */ o("span", { className: "whitespace-nowrap", children: [
784
+ /* @__PURE__ */ t("em", { className: "text-accent not-italic", children: "$UPER" }),
785
+ "WALL"
786
+ ] }),
787
+ /* @__PURE__ */ t("span", { className: "h-4 w-px bg-cream/20" }),
788
+ /* @__PURE__ */ t("span", { className: "font-normal", children: r })
789
+ ]
790
+ }
791
+ ),
792
+ /* @__PURE__ */ t("span", { className: "absolute left-1/2 hidden -translate-x-1/2 text-sm font-medium whitespace-nowrap sm:block", children: e }),
793
+ /* @__PURE__ */ t("div", { className: "ml-auto flex items-center gap-2", children: s })
794
+ ]
795
+ }
796
+ ) }), zt = [
797
+ { key: "user", label: "User", blurb: "Attributes your app sets" },
798
+ { key: "device", label: "Device", blurb: "Platform, locale, OS — the SDK fills these in" },
799
+ { key: "params", label: "Params", blurb: "Passed in at the placement" },
800
+ { key: "products", label: "Products", blurb: "Store data for this paywall's products" }
801
+ ], ke = (e) => e == null ? "" : typeof e == "string" ? e : JSON.stringify(e), Vt = (e) => e === "true" ? !0 : e === "false" ? !1 : e.trim() !== "" && Number.isFinite(Number(e)) ? Number(e) : e, le = (e) => e.slice(e.indexOf(".") + 1), qt = ({
802
+ row: e,
803
+ override: n,
804
+ onChange: s
805
+ }) => {
806
+ const a = n !== void 0, r = a ? n : e.value;
807
+ return /* @__PURE__ */ o("div", { className: "flex flex-col gap-1 py-1.5", children: [
808
+ /* @__PURE__ */ o("div", { className: "flex items-baseline justify-between gap-2", children: [
809
+ /* @__PURE__ */ t("span", { className: "truncate font-mono text-[11px] text-cream/70", children: e.path }),
810
+ a && /* @__PURE__ */ t(
811
+ "button",
812
+ {
813
+ type: "button",
814
+ className: "shrink-0 text-[11px] text-cream/40 hover:text-cream",
815
+ "aria-label": `Reset ${e.path}`,
816
+ onClick: () => s(void 0),
817
+ children: "Reset"
818
+ }
819
+ )
820
+ ] }),
821
+ typeof r == "boolean" ? /* @__PURE__ */ t("span", { className: "flex h-7 items-center", children: /* @__PURE__ */ t(
822
+ "button",
823
+ {
824
+ type: "button",
825
+ className: "sw-switch",
826
+ role: "switch",
827
+ "aria-checked": r,
828
+ "aria-label": e.path,
829
+ onClick: () => s(!r)
830
+ }
831
+ ) }) : /* @__PURE__ */ t(
832
+ "input",
833
+ {
834
+ className: "sw-input w-full",
835
+ "aria-label": e.path,
836
+ value: ke(r),
837
+ placeholder: ke(e.value),
838
+ onChange: (i) => {
839
+ const c = i.target.value;
840
+ s(c === "" ? void 0 : Vt(c));
841
+ }
842
+ }
843
+ )
844
+ ] });
845
+ }, Wt = ({
846
+ label: e,
847
+ blurb: n,
848
+ rows: s,
849
+ overrideOf: a,
850
+ onChange: r
851
+ }) => {
852
+ const [i, c] = d.useState(!1), f = s.filter((u) => a(u.path) !== void 0).length;
853
+ return /* @__PURE__ */ o("section", { className: "border-b border-cream/10 last:border-b-0", children: [
854
+ /* @__PURE__ */ o(
855
+ "button",
856
+ {
857
+ type: "button",
858
+ className: "flex w-full items-center gap-2 py-3 text-left",
859
+ "aria-expanded": i,
860
+ onClick: () => c((u) => !u),
861
+ children: [
862
+ /* @__PURE__ */ o("span", { className: "flex min-w-0 flex-col gap-0.5", children: [
863
+ /* @__PURE__ */ o("span", { className: "flex items-baseline gap-2", children: [
864
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] font-medium text-cream", children: e }),
865
+ /* @__PURE__ */ t("span", { className: "text-xs text-cream/40", children: f > 0 ? /* @__PURE__ */ t("span", { className: "text-accent", children: `${f} set` }) : s.length || null })
866
+ ] }),
867
+ /* @__PURE__ */ t("span", { className: "truncate text-xs text-cream/55", children: n })
868
+ ] }),
869
+ /* @__PURE__ */ t(
870
+ "span",
871
+ {
872
+ className: `ml-auto shrink-0 text-cream/40 transition-transform ${i ? "" : "-rotate-90"}`,
873
+ "aria-hidden": "true",
874
+ children: /* @__PURE__ */ t(Re, {})
875
+ }
876
+ )
877
+ ]
878
+ }
879
+ ),
880
+ i && (s.length === 0 ? /* @__PURE__ */ t("span", { className: "block pb-3 text-xs text-cream/35", children: "Nothing here for this paywall." }) : /* @__PURE__ */ t("div", { className: "flex flex-col pb-2", children: s.map((u) => /* @__PURE__ */ t(
881
+ qt,
882
+ {
883
+ row: u,
884
+ override: a(u.path),
885
+ onChange: (l) => r(u.path, l)
886
+ },
887
+ u.path
888
+ )) }))
889
+ ] });
890
+ }, Kt = ({
891
+ overrides: e,
892
+ groups: n,
893
+ onChange: s
894
+ }) => {
895
+ const a = (r, i, c) => {
896
+ if (r !== "products") {
897
+ const w = { ...e[r] };
898
+ c === void 0 ? delete w[le(i)] : w[le(i)] = c, s({ ...e, [r]: w });
899
+ return;
900
+ }
901
+ const [, f = "", u = ""] = i.split("."), l = { ...e.products?.[f] };
902
+ c === void 0 ? delete l[u] : l[u] = c;
903
+ const h = { ...e.products, [f]: l };
904
+ Object.keys(l).length === 0 && delete h[f], s({ ...e, products: h });
905
+ };
906
+ return /* @__PURE__ */ t("div", { className: "flex flex-col", children: zt.map((r) => /* @__PURE__ */ t(
907
+ Wt,
908
+ {
909
+ label: r.label,
910
+ blurb: r.blurb,
911
+ rows: n[r.key] ?? [],
912
+ overrideOf: (i) => r.key === "products" ? e.products?.[i.split(".")[1] ?? ""]?.[i.split(".")[2] ?? ""] : e[r.key]?.[le(i)],
913
+ onChange: (i, c) => a(r.key, i, c)
914
+ },
915
+ r.key
916
+ )) });
917
+ }, Ue = (e) => {
918
+ const n = new URLSearchParams();
919
+ e.theme && n.set("theme", e.theme), e.locale && n.set("locale", e.locale);
920
+ for (const [s, a] of [
921
+ ["sw_device", e.device],
922
+ ["sw_user", e.user],
923
+ ["sw_params", e.params],
924
+ ["sw_products", e.products]
925
+ ])
926
+ a && Object.keys(a).length > 0 && n.set(s, JSON.stringify(a));
927
+ return e.trialEligible !== void 0 && n.set("sw_trial", e.trialEligible ? "1" : "0"), n;
928
+ }, $ = (e) => `${e.project ? `/${e.project}` : ""}/${e.kind}/${e.id}`, He = (e) => `/preview${$(e)}?sw_preview=1`, bn = (e, n) => {
929
+ const s = Ue(n).toString();
930
+ return `/preview${$(e)}${s ? `?${s}` : ""}`;
931
+ }, Fe = (e, n) => {
932
+ const s = Ue(n).toString();
933
+ return s ? `${e}${e.includes("?") ? "&" : "?"}${s}` : e;
934
+ }, Gt = (e) => /[?&]sw_preview=/.test(e) ? e : `${e}${e.includes("?") ? "&" : "?"}sw_preview=1`, wn = (e) => (n, s) => Fe(Gt(e(n)), s), Zt = async (e, n, s) => {
935
+ try {
936
+ const a = await fetch("/__studio/action", {
937
+ method: "POST",
938
+ headers: { "Content-Type": "application/json" },
939
+ body: JSON.stringify({
940
+ action: n,
941
+ kind: e.kind,
942
+ id: e.id,
943
+ project: e.project
944
+ })
945
+ });
946
+ if (!a.body)
947
+ return await a.json();
948
+ const r = a.body.getReader(), i = new TextDecoder();
949
+ let c = "", f;
950
+ const u = (l) => {
951
+ if (!l.trim()) return;
952
+ const h = JSON.parse(l);
953
+ h.result ? f = h.result : h.step && h.state && s?.(h.step, h.state);
954
+ };
955
+ for (; ; ) {
956
+ const { done: l, value: h } = await r.read();
957
+ if (l) break;
958
+ c += i.decode(h, { stream: !0 });
959
+ const w = c.split(`
960
+ `);
961
+ c = w.pop() ?? "";
962
+ for (const b of w) u(b);
963
+ }
964
+ return u(c), f ?? { ok: !1, error: "The dev server closed without a result." };
965
+ } catch (a) {
966
+ return { ok: !1, error: a instanceof Error ? a.message : String(a) };
967
+ }
968
+ }, pe = async (e) => {
969
+ try {
970
+ return await (await fetch(`/__studio/status${$(e)}`)).json();
971
+ } catch (n) {
972
+ return { unreachable: n instanceof Error ? n.message : String(n) };
973
+ }
974
+ }, Jt = async () => {
975
+ try {
976
+ const n = await (await fetch("/__studio/samples.json")).json();
977
+ return typeof n == "object" && n !== null ? n : {};
978
+ } catch (e) {
979
+ return { unreachable: e instanceof Error ? e.message : String(e) };
980
+ }
981
+ }, oe = {
982
+ radius: 54,
983
+ cutout: "island",
984
+ statusBarHeight: 64,
985
+ homeIndicator: !0
986
+ }, J = [
987
+ {
988
+ id: "iphone-se",
989
+ name: "iPhone SE",
990
+ width: 375,
991
+ height: 667,
992
+ device: { platform: "iOS", deviceModel: "iPhone14,6", osVersion: "26.0" },
993
+ chrome: { radius: 0, statusBarHeight: 20, homeIndicator: !1 }
994
+ },
995
+ {
996
+ id: "iphone-17",
997
+ name: "iPhone 17",
998
+ width: 402,
999
+ height: 874,
1000
+ device: { platform: "iOS", deviceModel: "iPhone18,3", osVersion: "26.0" },
1001
+ chrome: oe
1002
+ },
1003
+ {
1004
+ id: "iphone-air",
1005
+ name: "iPhone Air",
1006
+ width: 420,
1007
+ height: 912,
1008
+ device: { platform: "iOS", deviceModel: "iPhone18,4", osVersion: "26.0" },
1009
+ chrome: oe
1010
+ },
1011
+ {
1012
+ id: "iphone-17-pro-max",
1013
+ name: "iPhone 17 Pro Max",
1014
+ width: 440,
1015
+ height: 956,
1016
+ device: { platform: "iOS", deviceModel: "iPhone18,2", osVersion: "26.0" },
1017
+ chrome: oe
1018
+ },
1019
+ {
1020
+ id: "pixel-10",
1021
+ name: "Pixel 10",
1022
+ width: 412,
1023
+ height: 915,
1024
+ device: { platform: "Android", deviceModel: "Pixel 10", osVersion: "16" },
1025
+ chrome: { radius: 28, cutout: "punch", statusBarHeight: 48, homeIndicator: !0 }
1026
+ },
1027
+ {
1028
+ id: "galaxy-s25",
1029
+ name: "Galaxy S25",
1030
+ width: 360,
1031
+ height: 780,
1032
+ device: { platform: "Android", deviceModel: "SM-S931B", osVersion: "15" },
1033
+ chrome: { radius: 26, cutout: "punch", statusBarHeight: 40, homeIndicator: !0 }
1034
+ },
1035
+ {
1036
+ id: "ipad-mini",
1037
+ name: "iPad mini",
1038
+ width: 744,
1039
+ height: 1133,
1040
+ device: { platform: "iOS", deviceModel: "iPad14,1", osVersion: "26.0" },
1041
+ chrome: { radius: 21, statusBarHeight: 24, homeIndicator: !0 }
1042
+ },
1043
+ {
1044
+ id: "ipad-pro-11",
1045
+ name: "iPad Pro 11″",
1046
+ width: 834,
1047
+ height: 1194,
1048
+ device: { platform: "iOS", deviceModel: "iPad16,3", osVersion: "26.0" },
1049
+ chrome: { radius: 18, statusBarHeight: 24, homeIndicator: !0 }
1050
+ },
1051
+ {
1052
+ id: "desktop",
1053
+ name: "Desktop",
1054
+ width: 1440,
1055
+ height: 900
1056
+ }
1057
+ ], ze = "iphone-17", _e = "responsive", Yt = { width: 393, height: 852 }, Qt = (e) => J.find((n) => n.id === e) ?? J.find((n) => n.id === ze) ?? J[0], Xt = (e, n) => Number.isFinite(e) ? Math.min(3e3, Math.max(200, Math.round(e))) : n, Pe = ({
1058
+ label: e,
1059
+ value: n,
1060
+ onCommit: s
1061
+ }) => {
1062
+ const [a, r] = d.useState(String(n));
1063
+ return d.useEffect(() => {
1064
+ r(String(n));
1065
+ }, [n]), /* @__PURE__ */ t(
1066
+ "input",
1067
+ {
1068
+ className: "sw-input w-16 text-center",
1069
+ type: "number",
1070
+ "aria-label": e,
1071
+ value: a,
1072
+ onChange: (c) => r(c.target.value),
1073
+ onBlur: () => {
1074
+ const c = Xt(Number(a), n);
1075
+ r(String(c)), s(c);
1076
+ },
1077
+ onKeyDown: (c) => {
1078
+ c.key === "Enter" && c.target.blur();
1079
+ }
1080
+ }
1081
+ );
1082
+ }, Ee = ({
1083
+ label: e,
1084
+ width: n,
1085
+ height: s,
1086
+ title: a,
1087
+ src: r,
1088
+ reloadKey: i,
1089
+ empty: c,
1090
+ chrome: f,
1091
+ landscape: u,
1092
+ theme: l
1093
+ }) => {
1094
+ const h = d.useRef(null);
1095
+ return /* @__PURE__ */ t("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col items-center justify-center", ref: h, children: /* @__PURE__ */ o("div", { className: "flex flex-col gap-2", children: [
1096
+ e && /* @__PURE__ */ t("span", { className: "text-xs text-cream/55", children: e }),
1097
+ r ? /* @__PURE__ */ t(
1098
+ Nt,
1099
+ {
1100
+ width: n,
1101
+ height: s,
1102
+ title: a,
1103
+ src: r,
1104
+ stageRef: h,
1105
+ reloadKey: i,
1106
+ chrome: f,
1107
+ landscape: u,
1108
+ theme: l
1109
+ }
1110
+ ) : /* @__PURE__ */ t(xt, { width: n, height: s, stageRef: h, children: c ?? "Nothing live yet — publish to compare against production." })
1111
+ ] }) });
1112
+ }, ce = (e) => e.label ?? `${e.kind}/${e.id}`, en = ({
1113
+ source: e,
1114
+ surface: n,
1115
+ samples: s,
1116
+ onBack: a,
1117
+ actions: r
1118
+ }) => {
1119
+ const [i, c] = d.useState(ze), [f, u] = d.useState(Yt), [l, h] = d.useState("light"), [w, b] = d.useState(void 0), [m, E] = d.useState({}), [j, L] = d.useState(!1), [C, X] = d.useState(void 0), [F, g] = d.useState(0), [S, x] = d.useState(!1), [M, O] = d.useState({}), [T, A] = d.useState(void 0), ee = d.useRef(void 0);
1120
+ d.useEffect(() => () => window.clearTimeout(ee.current), []);
1121
+ const z = e.capabilities?.actions === !0, [qe, We] = d.useState([]);
1122
+ d.useEffect(() => {
1123
+ const p = (v) => {
1124
+ const N = It(v.data);
1125
+ N && We(N);
1126
+ };
1127
+ return window.addEventListener("message", p), () => window.removeEventListener("message", p);
1128
+ }, []);
1129
+ const me = n.locales.length > 0 ? n.locales : qe;
1130
+ d.useEffect(() => {
1131
+ if (!z) return;
1132
+ let p = !1;
1133
+ return pe(n).then((v) => {
1134
+ p || O(v);
1135
+ }), () => {
1136
+ p = !0;
1137
+ };
1138
+ }, [z, n]);
1139
+ const Ke = async (p) => {
1140
+ window.clearTimeout(ee.current), A({ action: p, steps: {} });
1141
+ const v = await Zt(n, p, (N, _) => {
1142
+ A(
1143
+ (P) => P?.action === p ? {
1144
+ ...P,
1145
+ steps: { ...P.steps, [N]: _ === "start" ? "active" : "done" }
1146
+ } : P
1147
+ );
1148
+ });
1149
+ if (v.ok) {
1150
+ const N = Object.fromEntries(
1151
+ Q[p].map((_) => [_, "done"])
1152
+ );
1153
+ A({ action: p, steps: N }), O(await pe(n)), ee.current = window.setTimeout(() => A(void 0), 1600);
1154
+ } else
1155
+ A((N) => {
1156
+ if (!N) return N;
1157
+ const _ = { ...N.steps };
1158
+ for (const P of Q[p])
1159
+ _[P] === "active" && (_[P] = "failed");
1160
+ return { ...N, steps: _, error: v.error };
1161
+ });
1162
+ }, Ge = () => {
1163
+ if (k.width > 768) {
1164
+ window.open(q, "_blank");
1165
+ return;
1166
+ }
1167
+ const p = Math.max(0, window.screen.width / 2 - k.width / 2), v = Math.max(0, window.screen.height / 2 - k.height / 2);
1168
+ window.open(
1169
+ q,
1170
+ "superwall-preview",
1171
+ `toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=${k.width},height=${k.height},top=${v},left=${p}`
1172
+ ) || window.open(q, "_blank");
1173
+ }, V = i === _e, R = Qt(i), te = V ? f : { width: R.width, height: R.height }, k = S ? { width: te.height, height: te.width } : te, ne = {
1174
+ theme: l,
1175
+ locale: w,
1176
+ user: m.user,
1177
+ params: m.params,
1178
+ products: m.products,
1179
+ trialEligible: m.trialEligible,
1180
+ device: {
1181
+ ...V ? {} : R.device,
1182
+ ...m.device
1183
+ }
1184
+ }, ue = V ? void 0 : R.chrome, q = e.previewUrl(n, ne), Ze = M.liveUrl ? Fe(M.liveUrl, ne) : void 0, fe = [
1185
+ ...z ? [
1186
+ {
1187
+ key: "live",
1188
+ label: "Live version",
1189
+ hint: "What SDKs receive today",
1190
+ target: { type: "live" }
1191
+ }
1192
+ ] : [],
1193
+ ...e.surfaces.map((p, v) => ({
1194
+ key: `surface:${v}`,
1195
+ label: ce(p),
1196
+ hint: e.compareHint ?? "Local preview",
1197
+ target: { type: "surface", surface: p }
1198
+ })).filter((p) => p.target.surface !== n)
1199
+ ], I = C && (C.type === "live" ? {
1200
+ label: "Live",
1201
+ src: Ze,
1202
+ title: `${n.id} live`,
1203
+ empty: M.unreachable ? `Couldn't read the live version — ${M.unreachable}` : void 0
1204
+ } : {
1205
+ label: ce(C.surface),
1206
+ src: e.previewUrl(C.surface, ne),
1207
+ title: `${ce(C.surface)} preview`
1208
+ }), Je = d.useMemo(() => {
1209
+ const p = (v, N) => Object.entries(N ?? {}).map(([_, P]) => ({ path: `${v}.${_}`, value: P })).toSorted((_, P) => _.path.localeCompare(P.path));
1210
+ return {
1211
+ user: p("user", { ...e.samples?.user, ...s.user }),
1212
+ device: p("device", {
1213
+ ...e.samples?.device,
1214
+ ...s.device,
1215
+ ...R.device
1216
+ }),
1217
+ params: p("params", e.samples?.params),
1218
+ products: Object.entries(n.products ?? {}).flatMap(
1219
+ ([v, N]) => p(`products.${v}`, s.products?.[N])
1220
+ )
1221
+ };
1222
+ }, [e.samples, s, R.device, n.products]), W = d.useMemo(() => s.products ? Object.entries(n.products ?? {}).filter(([, p]) => s.products?.[p] === void 0).map(([p, v]) => ({ reference: p, identifier: v })) : [], [s.products, n.products]), [Ye, se] = d.useState(!1);
1223
+ d.useEffect(() => se(!1), [n]);
1224
+ const ae = s.unreachable, Qe = W.length === 0, be = Object.keys(m.user ?? {}).length + Object.keys(m.params ?? {}).length + Object.keys(m.device ?? {}).length;
1225
+ return /* @__PURE__ */ o(U, { children: [
1226
+ /* @__PURE__ */ t(
1227
+ Dt,
1228
+ {
1229
+ surfaceKey: `${n.project ?? ""}/${n.id}`,
1230
+ raised: !!ae
1231
+ }
1232
+ ),
1233
+ W.length > 0 && !Ye && /* @__PURE__ */ t(
1234
+ St,
1235
+ {
1236
+ paywall: n.id,
1237
+ missing: W,
1238
+ onDismiss: () => se(!0)
1239
+ }
1240
+ ),
1241
+ ae && /* @__PURE__ */ o("div", { className: "border-b border-cream/10 bg-red/10 px-4 py-1.5 text-[0.8125rem] text-cream/75", children: [
1242
+ "Couldn't check this paywall's products — ",
1243
+ ae
1244
+ ] }),
1245
+ /* @__PURE__ */ t(
1246
+ Be,
1247
+ {
1248
+ title: `${n.project ?? e.title} / ${n.id}${n.label ? ` · ${n.label}` : ""}`,
1249
+ onHome: a,
1250
+ actions: /* @__PURE__ */ o(U, { children: [
1251
+ r,
1252
+ /* @__PURE__ */ t(
1253
+ "button",
1254
+ {
1255
+ type: "button",
1256
+ className: "sw-btn sw-btn--icon",
1257
+ "aria-label": "Reload preview",
1258
+ onClick: () => g((p) => p + 1),
1259
+ children: /* @__PURE__ */ t(Ie, {})
1260
+ }
1261
+ ),
1262
+ /* @__PURE__ */ t(
1263
+ "button",
1264
+ {
1265
+ type: "button",
1266
+ className: "sw-btn sw-btn--icon",
1267
+ "aria-label": "Open preview",
1268
+ onClick: Ge,
1269
+ children: /* @__PURE__ */ t(Z, {})
1270
+ }
1271
+ ),
1272
+ z && /* @__PURE__ */ t(
1273
+ mt,
1274
+ {
1275
+ progress: T,
1276
+ blocked: Qe ? void 0 : `Superwall has no product for ${W.map((p) => p.reference).join(", ")}`,
1277
+ onRun: Ke,
1278
+ onBlocked: () => se(!1)
1279
+ }
1280
+ )
1281
+ ] })
1282
+ }
1283
+ ),
1284
+ /* @__PURE__ */ o("div", { className: "flex min-h-0 flex-1", children: [
1285
+ /* @__PURE__ */ o("div", { className: "flex min-w-0 flex-1", children: [
1286
+ I && /* @__PURE__ */ t(
1287
+ Ee,
1288
+ {
1289
+ label: I.label,
1290
+ width: k.width,
1291
+ height: k.height,
1292
+ title: I.title,
1293
+ src: I.src,
1294
+ reloadKey: F,
1295
+ empty: "empty" in I ? I.empty : void 0,
1296
+ chrome: ue,
1297
+ landscape: S,
1298
+ theme: l
1299
+ }
1300
+ ),
1301
+ /* @__PURE__ */ t(
1302
+ Ee,
1303
+ {
1304
+ label: I ? n.label ?? "Local" : void 0,
1305
+ width: k.width,
1306
+ height: k.height,
1307
+ title: `${n.id} preview`,
1308
+ src: q,
1309
+ reloadKey: F,
1310
+ chrome: ue,
1311
+ landscape: S,
1312
+ theme: l
1313
+ }
1314
+ )
1315
+ ] }),
1316
+ /* @__PURE__ */ t(Ht, { open: j, title: "Variables", onClose: () => L(!1), children: /* @__PURE__ */ t(Kt, { overrides: m, groups: Je, onChange: E }) })
1317
+ ] }),
1318
+ /* @__PURE__ */ o(Ft, { children: [
1319
+ /* @__PURE__ */ t(G, { label: "Trial", children: /* @__PURE__ */ t(
1320
+ Ut,
1321
+ {
1322
+ label: "Trial eligibility",
1323
+ checked: m.trialEligible ?? !1,
1324
+ onChange: (p) => E((v) => ({ ...v, trialEligible: p }))
1325
+ }
1326
+ ) }),
1327
+ /* @__PURE__ */ o(G, { label: "Theme", children: [
1328
+ /* @__PURE__ */ t(
1329
+ Bt,
1330
+ {
1331
+ label: "Theme",
1332
+ value: l,
1333
+ options: [
1334
+ { value: "light", label: /* @__PURE__ */ t(tt, {}) },
1335
+ { value: "dark", label: /* @__PURE__ */ t(nt, {}) }
1336
+ ],
1337
+ onChange: h
1338
+ }
1339
+ ),
1340
+ /* @__PURE__ */ t(
1341
+ "button",
1342
+ {
1343
+ type: "button",
1344
+ className: "sw-btn sw-btn--icon",
1345
+ "aria-label": "Rotate device",
1346
+ "aria-pressed": S,
1347
+ title: S ? "Back to portrait" : "Rotate to landscape",
1348
+ onClick: () => x((p) => !p),
1349
+ children: /* @__PURE__ */ t(
1350
+ "span",
1351
+ {
1352
+ className: `flex transition-transform duration-200 ${S ? "-rotate-90" : ""}`,
1353
+ children: /* @__PURE__ */ t(ct, {})
1354
+ }
1355
+ )
1356
+ }
1357
+ )
1358
+ ] }),
1359
+ /* @__PURE__ */ t(Se, {}),
1360
+ /* @__PURE__ */ o(G, { label: "Device", children: [
1361
+ /* @__PURE__ */ t(
1362
+ Ne,
1363
+ {
1364
+ label: "Device",
1365
+ value: i,
1366
+ options: [
1367
+ ...J.map((p) => ({ value: p.id, label: p.name })),
1368
+ { value: _e, label: "Responsive" }
1369
+ ],
1370
+ onChange: c
1371
+ }
1372
+ ),
1373
+ V && /* @__PURE__ */ o("span", { className: "flex items-center gap-1.5", children: [
1374
+ /* @__PURE__ */ t(
1375
+ Pe,
1376
+ {
1377
+ label: "Preview width",
1378
+ value: k.width,
1379
+ onCommit: (p) => u((v) => ({ ...v, width: p }))
1380
+ }
1381
+ ),
1382
+ /* @__PURE__ */ t("span", { className: "text-cream/55", children: "×" }),
1383
+ /* @__PURE__ */ t(
1384
+ Pe,
1385
+ {
1386
+ label: "Preview height",
1387
+ value: k.height,
1388
+ onCommit: (p) => u((v) => ({ ...v, height: p }))
1389
+ }
1390
+ )
1391
+ ] })
1392
+ ] }),
1393
+ me.length > 1 && /* @__PURE__ */ t(G, { label: "Locale", children: /* @__PURE__ */ t(
1394
+ Ne,
1395
+ {
1396
+ label: "Locale",
1397
+ value: w ?? "default",
1398
+ options: [
1399
+ { value: "default", label: "Device" },
1400
+ ...me.map((p) => ({ value: p, label: p }))
1401
+ ],
1402
+ onChange: (p) => b(p === "default" ? void 0 : p)
1403
+ }
1404
+ ) }),
1405
+ /* @__PURE__ */ t(Se, {}),
1406
+ fe.length > 0 && /* @__PURE__ */ t(ut, { active: C, options: fe, onSelect: X }),
1407
+ /* @__PURE__ */ o(
1408
+ "button",
1409
+ {
1410
+ type: "button",
1411
+ className: "sw-btn",
1412
+ "aria-expanded": j,
1413
+ onClick: () => L((p) => !p),
1414
+ children: [
1415
+ /* @__PURE__ */ t(st, {}),
1416
+ "Variables",
1417
+ be > 0 && /* @__PURE__ */ t("span", { className: "text-accent", children: be })
1418
+ ]
1419
+ }
1420
+ )
1421
+ ] })
1422
+ ] });
1423
+ }, Ve = "superwall-device-scheme", tn = () => {
1424
+ try {
1425
+ return window.localStorage.getItem(Ve) ?? void 0;
1426
+ } catch {
1427
+ return;
1428
+ }
1429
+ }, nn = (e) => {
1430
+ try {
1431
+ window.localStorage.setItem(Ve, e);
1432
+ } catch {
1433
+ }
1434
+ }, Ce = (e, n) => `${e}://?superwall_dev=${encodeURIComponent(n)}`, sn = ({ origin: e, scheme: n }) => {
1435
+ const [s, a] = d.useState(tn), r = s ?? n, i = (f) => {
1436
+ const l = window.prompt("Your app's URL scheme, so this can open it:", f)?.trim();
1437
+ if (!(l === void 0 || l === ""))
1438
+ return a(l), nn(l), l;
1439
+ }, c = (f) => {
1440
+ if (r !== void 0) return;
1441
+ f.preventDefault();
1442
+ const u = i("");
1443
+ u !== void 0 && window.location.assign(Ce(u, e));
1444
+ };
1445
+ return /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
1446
+ r !== void 0 && /* @__PURE__ */ t(
1447
+ "button",
1448
+ {
1449
+ className: "sw-btn sw-btn--icon",
1450
+ type: "button",
1451
+ "aria-label": "Edit app URL scheme",
1452
+ onClick: () => i(r),
1453
+ children: /* @__PURE__ */ o("svg", { className: "sw-icon", viewBox: "0 0 24 24", "aria-hidden": "true", children: [
1454
+ /* @__PURE__ */ t("path", { d: "M12 20h9" }),
1455
+ /* @__PURE__ */ t("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4Z" })
1456
+ ] })
1457
+ }
1458
+ ),
1459
+ /* @__PURE__ */ t(
1460
+ "a",
1461
+ {
1462
+ className: "sw-btn sw-btn--primary",
1463
+ href: r === void 0 ? "#" : Ce(r, e),
1464
+ onClick: c,
1465
+ children: "Open In App"
1466
+ }
1467
+ )
1468
+ ] });
1469
+ }, an = [
1470
+ [60, "second"],
1471
+ [60, "minute"],
1472
+ [24, "hour"],
1473
+ [7, "day"],
1474
+ [4.348, "week"],
1475
+ [12, "month"],
1476
+ [Number.POSITIVE_INFINITY, "year"]
1477
+ ], rn = (e, n = Date.now()) => {
1478
+ const s = Date.parse(e);
1479
+ if (Number.isNaN(s)) return;
1480
+ let a = Math.max(0, (n - s) / 1e3);
1481
+ const r = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
1482
+ for (const [i, c] of an) {
1483
+ if (a < i) return r.format(-Math.round(a), c);
1484
+ a /= i;
1485
+ }
1486
+ }, Me = 390, ln = 844, on = (e) => {
1487
+ const [n, s] = d.useState(0);
1488
+ return d.useLayoutEffect(() => {
1489
+ const a = e.current;
1490
+ if (!a) return;
1491
+ const r = () => s(a.getBoundingClientRect().width);
1492
+ if (r(), typeof ResizeObserver > "u") return;
1493
+ const i = new ResizeObserver(r);
1494
+ return i.observe(a), () => i.disconnect();
1495
+ }, [e]), n;
1496
+ }, cn = ({
1497
+ surface: e,
1498
+ status: n,
1499
+ previewSrc: s,
1500
+ onOpen: a,
1501
+ href: r
1502
+ }) => {
1503
+ const i = d.useRef(null), c = on(i), f = c > 0 ? c / Me : 0;
1504
+ return /* @__PURE__ */ o(
1505
+ "a",
1506
+ {
1507
+ className: "group block",
1508
+ href: r ?? $(e),
1509
+ onClick: (u) => {
1510
+ u.metaKey || u.ctrlKey || (u.preventDefault(), a());
1511
+ },
1512
+ children: [
1513
+ /* @__PURE__ */ t(
1514
+ "div",
1515
+ {
1516
+ className: "bg-panel relative aspect-[390/844] overflow-hidden border border-cream/20 transition-colors group-hover:border-cream/35",
1517
+ ref: i,
1518
+ children: f > 0 && /* @__PURE__ */ t(
1519
+ "iframe",
1520
+ {
1521
+ className: "pointer-events-none block origin-top-left border-0 bg-white",
1522
+ title: `${e.project ? `${e.project}/` : ""}${e.id} preview`,
1523
+ src: s,
1524
+ loading: "lazy",
1525
+ tabIndex: -1,
1526
+ width: Me,
1527
+ height: ln,
1528
+ style: { transform: `scale(${f})` }
1529
+ }
1530
+ )
1531
+ }
1532
+ ),
1533
+ /* @__PURE__ */ o("div", { className: "flex items-center justify-between gap-2 pt-2.5", children: [
1534
+ /* @__PURE__ */ o("div", { className: "flex flex-col gap-0.5", children: [
1535
+ /* @__PURE__ */ o("span", { className: "text-sm font-medium", children: [
1536
+ e.project && /* @__PURE__ */ o("span", { className: "text-cream/45", children: [
1537
+ e.project,
1538
+ "/"
1539
+ ] }),
1540
+ e.id,
1541
+ e.platforms && e.platforms.length > 0 && /* @__PURE__ */ o("span", { className: "text-cream/45", children: [
1542
+ " · ",
1543
+ e.platforms.join(" · ")
1544
+ ] })
1545
+ ] }),
1546
+ n && /* @__PURE__ */ t("span", { className: "text-xs text-cream/55", children: n.updatedAt ? `Edited ${rn(n.updatedAt)}` : "Not published" })
1547
+ ] }),
1548
+ n?.paywallId && /* @__PURE__ */ t("span", { className: `text-xs ${n.active ? "text-accent" : "text-cream/55"}`, children: n.active ? "Active" : "Inactive" })
1549
+ ] })
1550
+ ]
1551
+ }
1552
+ );
1553
+ };
1554
+ let $e = 0;
1555
+ const dn = ({
1556
+ source: e,
1557
+ onOpen: n,
1558
+ device: s = !1
1559
+ }) => {
1560
+ const [a, r] = d.useState({});
1561
+ d.useEffect(() => {
1562
+ if (e.capabilities?.actions !== !0) return;
1563
+ let l = !1;
1564
+ for (const h of e.surfaces)
1565
+ pe(h).then((w) => {
1566
+ l || r((b) => ({ ...b, [$(h)]: w }));
1567
+ });
1568
+ return () => {
1569
+ l = !0;
1570
+ };
1571
+ }, [e]);
1572
+ const [i, c] = d.useState({}), f = d.useRef(null);
1573
+ d.useLayoutEffect(() => {
1574
+ const l = f.current;
1575
+ if (!l) return;
1576
+ l.scrollTop = $e;
1577
+ const h = () => {
1578
+ $e = l.scrollTop;
1579
+ };
1580
+ return l.addEventListener("scroll", h, { passive: !0 }), () => {
1581
+ h(), l.removeEventListener("scroll", h);
1582
+ };
1583
+ }, []);
1584
+ const u = [
1585
+ ["Paywalls", "paywall"],
1586
+ ["Funnels", "funnel"]
1587
+ ].map(([l, h]) => {
1588
+ const w = e.surfaces.filter((m) => m.kind === h), b = (i[h] ?? "").trim().toLowerCase();
1589
+ return {
1590
+ label: l,
1591
+ kind: h,
1592
+ all: w,
1593
+ needle: b,
1594
+ surfaces: w.filter(
1595
+ (m) => b === "" || `${m.project ?? ""} ${m.id}`.toLowerCase().includes(b)
1596
+ )
1597
+ };
1598
+ }).filter((l) => l.all.length > 0);
1599
+ return /* @__PURE__ */ o(U, { children: [
1600
+ /* @__PURE__ */ t(
1601
+ Be,
1602
+ {
1603
+ title: e.title,
1604
+ onHome: () => {
1605
+ },
1606
+ inset: !0,
1607
+ label: s ? "Preview" : void 0,
1608
+ actions: s ? /* @__PURE__ */ t(sn, { origin: window.location.origin, scheme: e.scheme }) : void 0
1609
+ }
1610
+ ),
1611
+ /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto px-3 pt-6 pb-16 sm:px-6 sm:pt-10", ref: f, children: /* @__PURE__ */ o("div", { className: "mx-auto max-w-[1080px]", children: [
1612
+ e.diagnostics && e.diagnostics.length > 0 && /* @__PURE__ */ t("div", { className: "border-red bg-red/10 mb-6 border-l-2 px-4 py-3 text-[0.8125rem] whitespace-pre-wrap", children: e.diagnostics.join(`
1613
+ `) }),
1614
+ u.map((l) => /* @__PURE__ */ o("section", { className: "mt-10 first:mt-0", children: [
1615
+ /* @__PURE__ */ o("div", { className: "mb-4 flex items-center gap-2", children: [
1616
+ /* @__PURE__ */ t("span", { className: "text-[1.0625rem] font-medium", children: l.label }),
1617
+ /* @__PURE__ */ t("span", { className: "text-[0.8125rem] text-cream/55 tabular-nums", children: l.surfaces.length }),
1618
+ l.all.length > 1 && /* @__PURE__ */ t(
1619
+ "input",
1620
+ {
1621
+ className: "sw-input ml-auto w-48",
1622
+ type: "search",
1623
+ value: i[l.kind] ?? "",
1624
+ placeholder: `Search ${l.label.toLowerCase()}`,
1625
+ "aria-label": `Search ${l.label.toLowerCase()}`,
1626
+ onChange: (h) => c((w) => ({ ...w, [l.kind]: h.target.value }))
1627
+ }
1628
+ )
1629
+ ] }),
1630
+ /* @__PURE__ */ t("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-[repeat(auto-fill,minmax(200px,1fr))] sm:gap-6", children: l.surfaces.map((h) => /* @__PURE__ */ t(
1631
+ cn,
1632
+ {
1633
+ surface: h,
1634
+ status: a[$(h)],
1635
+ previewSrc: e.previewUrl(h, {}),
1636
+ onOpen: () => n(h),
1637
+ href: s ? He(h) : void 0
1638
+ },
1639
+ $(h)
1640
+ )) }),
1641
+ l.surfaces.length === 0 && /* @__PURE__ */ t("span", { className: "block text-[0.8125rem] text-cream/45", children: `Nothing matches “${(i[l.kind] ?? "").trim()}”.` })
1642
+ ] }, l.kind)),
1643
+ e.surfaces.length === 0 && /* @__PURE__ */ o("div", { className: "border border-dashed border-cream/20 p-12 text-center text-cream/55", children: [
1644
+ "No paywalls yet — create",
1645
+ " ",
1646
+ /* @__PURE__ */ t("code", { className: "font-mono text-[0.8125rem] text-cream", children: "superwall/paywalls/<id>/app/page.tsx" }),
1647
+ " ",
1648
+ "and it appears here."
1649
+ ] })
1650
+ ] }) }),
1651
+ !s && /* @__PURE__ */ t("footer", { className: "bg-bar flex h-11 flex-none items-center justify-center border-t border-cream/10 text-xs text-cream/55", children: "Previews run against the simulated SDK host. Edit files under superwall/ and they update live." })
1652
+ ] });
1653
+ }, pn = (e, n) => {
1654
+ const s = n.match(/^\/(?:([a-z0-9-]+)\/)?(paywall|funnel)\/([a-z0-9-]+)\/?$/);
1655
+ if (s)
1656
+ return e.find(
1657
+ (a) => a.kind === s[2] && a.id === s[3] && (s[1] === void 0 || a.project === s[1])
1658
+ );
1659
+ }, vn = ({
1660
+ source: e,
1661
+ device: n = !1,
1662
+ openPreview: s = (a) => window.location.assign(a)
1663
+ }) => {
1664
+ const [a, r] = d.useState(() => window.location.pathname), [i, c] = d.useState({});
1665
+ d.useEffect(() => {
1666
+ const l = () => r(window.location.pathname);
1667
+ return window.addEventListener("popstate", l), () => window.removeEventListener("popstate", l);
1668
+ }, []), d.useEffect(() => {
1669
+ if (e.capabilities?.actions !== !0) return;
1670
+ let l = !1;
1671
+ return Jt().then((h) => {
1672
+ l || c(h);
1673
+ }), () => {
1674
+ l = !0;
1675
+ };
1676
+ }, [e.capabilities?.actions]);
1677
+ const f = (l) => {
1678
+ window.history.pushState(null, "", l), r(l);
1679
+ }, u = n ? void 0 : pn(e.surfaces, a);
1680
+ return /* @__PURE__ */ t(et, { children: u ? /* @__PURE__ */ t(
1681
+ en,
1682
+ {
1683
+ source: e,
1684
+ surface: u,
1685
+ samples: i,
1686
+ onBack: () => f("/")
1687
+ }
1688
+ ) : /* @__PURE__ */ t(
1689
+ dn,
1690
+ {
1691
+ source: e,
1692
+ device: n,
1693
+ onOpen: (l) => n ? s(He(l)) : f($(l))
1694
+ }
1695
+ ) });
1696
+ }, hn = (e) => typeof e == "object" && e !== null && !Array.isArray(e) && Object.values(e).every((n) => typeof n == "string"), B = (e) => typeof e == "object" && e !== null && !Array.isArray(e), Y = (e) => Array.isArray(e) && e.every((n) => typeof n == "string"), mn = (e) => {
1697
+ if (!B(e)) return;
1698
+ const n = e.kind === "paywall" || e.kind === "funnel" ? e.kind : void 0;
1699
+ if (!(!n || typeof e.id != "string"))
1700
+ return {
1701
+ kind: n,
1702
+ id: e.id,
1703
+ ...typeof e.project == "string" ? { project: e.project } : {},
1704
+ routes: Y(e.routes) ? e.routes : [],
1705
+ products: hn(e.products) ? e.products : {},
1706
+ locales: Y(e.locales) ? e.locales : [],
1707
+ ...Y(e.platforms) ? { platforms: e.platforms } : {},
1708
+ paywallId: typeof e.paywallId == "string" ? e.paywallId : void 0
1709
+ };
1710
+ }, gn = (e) => {
1711
+ if (!B(e))
1712
+ throw new Error("project payload is not an object");
1713
+ const n = Array.isArray(e.surfaces) ? e.surfaces.map(mn).filter((i) => i !== void 0) : [], s = B(e.capabilities) ? e.capabilities : {}, a = B(e.samples) ? e.samples : {}, r = (i) => B(a[i]) ? a[i] : {};
1714
+ return {
1715
+ title: typeof e.title == "string" ? e.title : "superwall",
1716
+ scheme: typeof e.scheme == "string" ? e.scheme : void 0,
1717
+ surfaces: n,
1718
+ diagnostics: Y(e.diagnostics) ? e.diagnostics : [],
1719
+ samples: {
1720
+ device: r("device"),
1721
+ user: r("user"),
1722
+ params: r("params")
1723
+ },
1724
+ capabilities: { actions: s.actions === !0 }
1725
+ };
1726
+ };
1727
+ export {
1728
+ ze as DEFAULT_DEVICE_ID,
1729
+ Nt as DeviceFrame,
1730
+ J as STUDIO_DEVICES,
1731
+ Bt as Segmented,
1732
+ Ne as Select,
1733
+ vn as StudioApp,
1734
+ et as StudioShell,
1735
+ en as SurfaceEditor,
1736
+ dn as SurfaceList,
1737
+ Ut as Switch,
1738
+ Be as TopBar,
1739
+ Kt as VariablesPanel,
1740
+ bn as buildPreviewPath,
1741
+ Qt as deviceById,
1742
+ gn as parseProjectPayload,
1743
+ wn as snapshotPreviewUrl,
1744
+ Fe as withOverrides,
1745
+ Gt as withPreviewOptIn
1746
+ };