@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,4 @@
1
+ import type { Samples, StudioActionName, StudioActionResult, StudioStatus, StudioSurface } from "./types";
2
+ export declare const runAction: (surface: StudioSurface, action: StudioActionName, onStep?: (step: string, state: "start" | "done") => void) => Promise<StudioActionResult>;
3
+ export declare const fetchStatus: (surface: StudioSurface) => Promise<StudioStatus>;
4
+ export declare const fetchSamples: () => Promise<Samples>;
@@ -0,0 +1,26 @@
1
+ export type DeviceChromeSpec = {
2
+ radius: number;
3
+ cutout?: "island" | "punch";
4
+ statusBarHeight: number;
5
+ homeIndicator: boolean;
6
+ };
7
+ export type StudioDevice = {
8
+ id: string;
9
+ name: string;
10
+ width: number;
11
+ height: number;
12
+ device?: {
13
+ platform: "iOS" | "Android";
14
+ deviceModel: string;
15
+ osVersion: string;
16
+ };
17
+ chrome?: DeviceChromeSpec;
18
+ };
19
+ export declare const STUDIO_DEVICES: readonly StudioDevice[];
20
+ export declare const DEFAULT_DEVICE_ID = "iphone-17";
21
+ export declare const RESPONSIVE_ID = "responsive";
22
+ export declare const RESPONSIVE_DEFAULT: {
23
+ width: number;
24
+ height: number;
25
+ };
26
+ export declare const deviceById: (id: string) => StudioDevice;
@@ -0,0 +1,27 @@
1
+ export declare const STUDIO_CHANNEL = "superwall-studio";
2
+ export type PaywallEvent = {
3
+ event_name: string;
4
+ } & Record<string, unknown>;
5
+ export type BridgeMessage = {
6
+ channel: typeof STUDIO_CHANNEL;
7
+ type: "hello";
8
+ locales: string[];
9
+ } | {
10
+ channel: typeof STUDIO_CHANNEL;
11
+ type: "event";
12
+ message: PaywallEvent;
13
+ } | {
14
+ channel: typeof STUDIO_CHANNEL;
15
+ type: "ask";
16
+ id: string;
17
+ kind: "purchase" | "permission" | "callback";
18
+ subject: string;
19
+ };
20
+ export type EventNotice = {
21
+ action: string;
22
+ subject?: string;
23
+ tone: "info" | "success" | "warning";
24
+ };
25
+ export declare const noticeFor: (event: PaywallEvent) => EventNotice | undefined;
26
+ export declare const isBridgeMessage: (data: unknown) => data is BridgeMessage;
27
+ export declare const localesAnnounced: (data: unknown) => string[] | undefined;
@@ -0,0 +1,7 @@
1
+ import type { PreviewOverrides, PreviewUrlBuilder, StudioSurface } from "./types";
2
+ export declare const surfacePath: (surface: StudioSurface) => string;
3
+ export declare const devicePreviewPath: (surface: StudioSurface) => string;
4
+ export declare const buildPreviewPath: PreviewUrlBuilder;
5
+ export declare const withOverrides: (url: string, overrides: PreviewOverrides) => string;
6
+ export declare const withPreviewOptIn: (url: string) => string;
7
+ export declare const snapshotPreviewUrl: (urlOf: (surface: StudioSurface) => string) => PreviewUrlBuilder;
@@ -0,0 +1,16 @@
1
+ export interface DashboardPrice {
2
+ amount?: number;
3
+ currency?: string;
4
+ }
5
+ export interface DashboardProduct {
6
+ identifier?: string;
7
+ price?: DashboardPrice | null;
8
+ trial_price?: DashboardPrice | null;
9
+ monthly_billing_plan_price?: DashboardPrice | null;
10
+ subscription?: {
11
+ period?: string;
12
+ period_count?: number;
13
+ trial_period_days?: number | null;
14
+ } | null;
15
+ }
16
+ export declare const productVariables: (product: DashboardProduct) => Record<string, unknown>;
@@ -0,0 +1,12 @@
1
+ import type { SampleDefaults, StudioSurface } from "./types";
2
+ export type StudioProjectPayload = {
3
+ title: string;
4
+ scheme?: string;
5
+ surfaces: StudioSurface[];
6
+ samples: SampleDefaults;
7
+ diagnostics: string[];
8
+ capabilities: {
9
+ actions: boolean;
10
+ };
11
+ };
12
+ export declare const parseProjectPayload: (data: unknown) => StudioProjectPayload;
@@ -0,0 +1 @@
1
+ export declare const timeAgo: (iso: string, now?: number) => string | undefined;
@@ -0,0 +1,77 @@
1
+ export type StudioSurfaceKind = "paywall" | "funnel";
2
+ export type StudioSurface = {
3
+ kind: StudioSurfaceKind;
4
+ id: string;
5
+ project?: string;
6
+ label?: string;
7
+ products?: Record<string, string>;
8
+ routes: string[];
9
+ locales: string[];
10
+ platforms?: string[];
11
+ paywallId?: string;
12
+ };
13
+ export type SampleDefaults = {
14
+ device: Record<string, unknown>;
15
+ user: Record<string, unknown>;
16
+ params: Record<string, unknown>;
17
+ };
18
+ export type PreviewOverrides = {
19
+ theme?: "light" | "dark";
20
+ locale?: string;
21
+ device?: Record<string, unknown>;
22
+ user?: Record<string, unknown>;
23
+ params?: Record<string, unknown>;
24
+ products?: Record<string, Record<string, unknown>>;
25
+ trialEligible?: boolean;
26
+ };
27
+ export type PreviewUrlBuilder = (surface: StudioSurface, overrides: PreviewOverrides) => string;
28
+ export type StudioActionName = "push" | "promote" | "publish";
29
+ export type CompareTarget = {
30
+ type: "live";
31
+ } | {
32
+ type: "surface";
33
+ surface: StudioSurface;
34
+ };
35
+ export type StudioActionResult = {
36
+ ok: true;
37
+ version: number;
38
+ live: boolean;
39
+ } | {
40
+ ok: false;
41
+ error: string;
42
+ };
43
+ export type StudioStepState = "pending" | "active" | "done" | "failed";
44
+ export type StudioActionStep = "link" | "build" | "assets" | "push" | "source" | "promote";
45
+ export declare const ACTION_STEPS: Record<StudioActionName, StudioActionStep[]>;
46
+ export declare const STEP_LABELS: Record<StudioActionStep, string>;
47
+ export type StudioStatus = {
48
+ paywallId?: string;
49
+ liveUrl?: string;
50
+ active?: boolean;
51
+ updatedAt?: string;
52
+ /** Why the live version couldn't be read, when it couldn't. */
53
+ unreachable?: string;
54
+ };
55
+ export type StudioSource = {
56
+ scheme?: string;
57
+ title: string;
58
+ surfaces: StudioSurface[];
59
+ diagnostics?: string[];
60
+ samples?: SampleDefaults;
61
+ previewUrl: PreviewUrlBuilder;
62
+ capabilities?: {
63
+ actions: boolean;
64
+ };
65
+ compareHint?: string;
66
+ };
67
+ export type Samples = {
68
+ device?: Record<string, unknown>;
69
+ user?: Record<string, unknown>;
70
+ products?: Record<string, Record<string, unknown>>;
71
+ live?: {
72
+ device: boolean;
73
+ user: boolean;
74
+ };
75
+ /** Why samples couldn't be fetched, when they couldn't. */
76
+ unreachable?: string;
77
+ };
@@ -0,0 +1,51 @@
1
+ const p = {
2
+ USD: "$",
3
+ CAD: "$",
4
+ AUD: "$",
5
+ NZD: "$",
6
+ EUR: "€",
7
+ GBP: "£",
8
+ JPY: "¥",
9
+ CNY: "¥",
10
+ INR: "₹",
11
+ KRW: "₩",
12
+ BRL: "R$",
13
+ MXN: "$",
14
+ CHF: "CHF",
15
+ SEK: "kr",
16
+ NOK: "kr",
17
+ DKK: "kr",
18
+ PLN: "zł",
19
+ TRY: "₺",
20
+ RUB: "₽",
21
+ ZAR: "R"
22
+ }, d = 100, u = { day: 365, week: 52, month: 12, year: 1 }, l = (r) => p[r.toUpperCase()] ?? "", c = (r, e) => {
23
+ try {
24
+ return new Intl.NumberFormat("en-US", { style: "currency", currency: e }).format(r);
25
+ } catch {
26
+ return `${l(e)}${r.toFixed(2)}`;
27
+ }
28
+ }, m = {
29
+ day: "daily",
30
+ week: "weekly",
31
+ month: "monthly",
32
+ year: "yearly"
33
+ }, R = (r) => {
34
+ const e = {};
35
+ r.identifier && (e.identifier = r.identifier);
36
+ const o = r.price;
37
+ if (!o || typeof o.amount != "number" || !o.currency) return e;
38
+ const t = o.currency.toUpperCase(), n = o.amount / d;
39
+ e.price = c(n, t), e.rawPrice = n, e.currencyCode = t, e.currencySymbol = l(t);
40
+ const i = r.subscription?.period;
41
+ if (!i) return e;
42
+ const a = r.subscription?.period_count ?? 1;
43
+ e.period = i, e.periodly = m[i] ?? `${i}ly`, e[`period${i.charAt(0).toUpperCase()}${i.slice(1)}s`] = a;
44
+ const s = (u[i] ?? 1) / a;
45
+ e.yearlyPrice = c(n * s, t), e.monthlyPrice = c(n * s / 12, t), e.weeklyPrice = c(n * s / 52, t), e.dailyPrice = c(n * s / 365, t);
46
+ const y = r.subscription?.trial_period_days;
47
+ return typeof y == "number" && y > 0 && (e.trialPeriodDays = y, e.trialPeriodText = `${y}-day`), e;
48
+ };
49
+ export {
50
+ R as productVariables
51
+ };
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import { type Samples, type StudioSource, type StudioSurface } from "../lib/types";
3
+ export declare const SurfaceEditor: ({ source, surface, samples, onBack, actions, }: {
4
+ source: StudioSource;
5
+ surface: StudioSurface;
6
+ samples: Samples;
7
+ onBack: () => void;
8
+ actions?: React.ReactNode;
9
+ }) => React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+ import type { StudioSource, StudioSurface } from "../lib/types";
3
+ export declare const SurfaceList: ({ source, onOpen, device, }: {
4
+ source: StudioSource;
5
+ onOpen: (surface: StudioSurface) => void;
6
+ device?: boolean;
7
+ }) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-duration:initial;--tw-ease:initial}}}@layer theme{:root,:host{--font-sans:"Manrope", ui-sans-serif, system-ui, -apple-system, sans-serif;--font-mono:"Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-md:28rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--leading-relaxed:1.625;--ease-out:cubic-bezier(0, 0, .2, 1);--animate-pulse:pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-ink:#1a1918;--color-bar:#211f1d;--color-panel:#242220;--color-cream:#fdfef6;--color-accent:#46d7d4;--color-red:#ff7474}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}.sw-studio{color-scheme:dark}.sw-studio ::selection{background:#46d7d480}@supports (color:color-mix(in lab,red,red)){.sw-studio ::selection{background:color-mix(in srgb,var(--color-accent) 50%,transparent)}}.sw-studio :focus-visible{outline:2px solid var(--color-accent);outline-offset:-2px}.sw-studio button{cursor:pointer}.sw-studio,.sw-studio *{scrollbar-width:none}.sw-studio::-webkit-scrollbar{width:0;height:0;display:none}.sw-studio ::-webkit-scrollbar{width:0;height:0;display:none}}@layer components{.sw-btn{border:1px solid #fdfef62e;justify-content:center;align-items:center;gap:7px;height:30px;padding:0 12px;display:inline-flex}@supports (color:color-mix(in lab,red,red)){.sw-btn{border:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-btn{color:var(--color-cream);white-space:nowrap;background:0 0;font-size:.8125rem;font-weight:500;transition:background-color .15s}.sw-btn:hover{background:#fdfef60d}@supports (color:color-mix(in lab,red,red)){.sw-btn:hover{background:color-mix(in srgb,var(--color-cream) 5%,transparent)}}.sw-btn--primary{background:var(--color-cream);border-color:var(--color-cream);color:var(--color-ink)}.sw-btn--primary:hover{background:#fdfef6d9}@supports (color:color-mix(in lab,red,red)){.sw-btn--primary:hover{background:color-mix(in srgb,var(--color-cream) 85%,transparent)}}.sw-btn--icon{width:30px;padding:0}.sw-icon,.sw-btn svg,.sw-segmented svg{stroke:currentColor;fill:none;stroke-width:1.5px;stroke-linecap:round;stroke-linejoin:round;width:14px;height:14px}.sw-chip{border:1px solid #fdfef62e;align-items:center;height:20px;padding:0 7px;display:inline-flex}@supports (color:color-mix(in lab,red,red)){.sw-chip{border:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-chip{color:var(--color-cream);white-space:nowrap}.sw-tool-label{color:#fdfef68c;font-size:.75rem;font-weight:500}@supports (color:color-mix(in lab,red,red)){.sw-tool-label{color:color-mix(in srgb,var(--color-cream) 55%,transparent)}}.sw-tool-label{white-space:nowrap}.sw-tool-label--key{font-family:var(--font-mono);letter-spacing:.04em;font-size:11px}.sw-select{appearance:none;cursor:pointer;border:1px solid #fdfef62e;height:30px;padding:0 24px 0 9px}@supports (color:color-mix(in lab,red,red)){.sw-select{border:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-select{background:linear-gradient(45deg,#0000 50%,#fdfef68c 50%) calc(100% - 13px) 55%/4px 4px no-repeat,linear-gradient(135deg,#fdfef68c 50%,#0000 50%) calc(100% - 9px) 55%/4px 4px no-repeat}@supports (color:color-mix(in lab,red,red)){.sw-select{background:linear-gradient(45deg,transparent 50%,color-mix(in srgb,var(--color-cream) 55%,transparent) 50%) calc(100% - 13px) 55% / 4px 4px no-repeat,linear-gradient(135deg,color-mix(in srgb,var(--color-cream) 55%,transparent) 50%,transparent 50%) calc(100% - 9px) 55% / 4px 4px no-repeat}}.sw-select{color:var(--color-cream);font:inherit;background-color:#0000;font-size:.8125rem;font-weight:500}.sw-select option{background:var(--color-bar)}.sw-segmented{border:1px solid #fdfef62e;display:inline-flex}@supports (color:color-mix(in lab,red,red)){.sw-segmented{border:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-segmented{height:30px}.sw-segmented button{color:#fdfef68c;align-items:center;gap:6px;padding:0 11px;font-size:.8125rem;font-weight:500;display:inline-flex}@supports (color:color-mix(in lab,red,red)){.sw-segmented button{color:color-mix(in srgb,var(--color-cream) 55%,transparent)}}.sw-segmented button{transition:background-color .15s,color .15s}.sw-segmented button+button{border-left:1px solid #fdfef62e}@supports (color:color-mix(in lab,red,red)){.sw-segmented button+button{border-left:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-segmented button[aria-pressed=true]{background:var(--color-cream);color:var(--color-ink)}input[type=search]::-webkit-search-cancel-button{appearance:none;display:none}input[type=search]::-webkit-search-decoration{appearance:none;display:none}input[type=search]::-webkit-search-results-button{appearance:none;display:none}input[type=search]::-webkit-search-results-decoration{appearance:none;display:none}.sw-input{border:1px solid #fdfef62e;height:30px;padding:0 9px}@supports (color:color-mix(in lab,red,red)){.sw-input{border:1px solid color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-input{color:var(--color-cream);font:inherit;background:0 0;width:100%;font-size:.8125rem}.sw-switch{background:#fdfef62e;border-radius:9999px;width:34px;height:19px;position:relative}@supports (color:color-mix(in lab,red,red)){.sw-switch{background:color-mix(in srgb,var(--color-cream) 18%,transparent)}}.sw-switch{flex:none;transition:background-color .15s}.sw-switch[aria-checked=true]{background:var(--color-accent)}.sw-switch:after{content:"";background:var(--color-ink);border-radius:9999px;width:13px;height:13px;transition:transform .15s;position:absolute;top:3px;left:3px}.sw-switch[aria-checked=true]:after{transform:translate(15px)}}@layer utilities{.pointer-events-none{pointer-events:none}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.inset-0{inset:0}.inset-x-0{inset-inline:0}.top-0{top:0}.top-full{top:100%}.right-0{right:0}.bottom-full{bottom:100%}.left-0{left:0}.left-1\/2{left:50%}.z-10{z-index:10}.z-20{z-index:20}.z-50{z-index:50}.col-start-2{grid-column-start:2}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.m-0{margin:0}.m-auto{margin:auto}.mx-auto{margin-inline:auto}.mt-1{margin-top:var(--spacing)}.mt-2{margin-top:calc(var(--spacing) * 2)}.mt-2\.5{margin-top:calc(var(--spacing) * 2.5)}.mt-10{margin-top:calc(var(--spacing) * 10)}.mb-1{margin-bottom:var(--spacing)}.mb-4{margin-bottom:calc(var(--spacing) * 4)}.mb-6{margin-bottom:calc(var(--spacing) * 6)}.-ml-px{margin-left:-1px}.ml-auto{margin-left:auto}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.aspect-\[390\/844\]{aspect-ratio:390/844}.size-\[5px\]{width:5px;height:5px}.h-0\.5{height:calc(var(--spacing) * .5)}.h-2{height:calc(var(--spacing) * 2)}.h-4{height:calc(var(--spacing) * 4)}.h-5{height:calc(var(--spacing) * 5)}.h-6{height:calc(var(--spacing) * 6)}.h-7{height:calc(var(--spacing) * 7)}.h-11{height:calc(var(--spacing) * 11)}.h-full{height:100%}.max-h-64{max-height:calc(var(--spacing) * 64)}.min-h-0{min-height:0}.min-h-14{min-height:calc(var(--spacing) * 14)}.w-0{width:0}.w-2{width:calc(var(--spacing) * 2)}.w-4{width:calc(var(--spacing) * 4)}.w-6{width:calc(var(--spacing) * 6)}.w-16{width:calc(var(--spacing) * 16)}.w-48{width:calc(var(--spacing) * 48)}.w-64{width:calc(var(--spacing) * 64)}.w-72{width:calc(var(--spacing) * 72)}.w-\[344px\]{width:344px}.w-full{width:100%}.w-px{width:1px}.max-w-\[1080px\]{max-width:1080px}.max-w-full{max-width:100%}.max-w-md{max-width:var(--container-md)}.min-w-0{min-width:0}.flex-1{flex:1}.flex-none{flex:none}.shrink-0{flex-shrink:0}.origin-top-left{transform-origin:0 0}.-translate-x-1\/2{--tw-translate-x: -50% ;translate:var(--tw-translate-x) var(--tw-translate-y)}.-rotate-90{rotate:-90deg}.transform{transform:var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,)}.animate-pulse{animation:var(--animate-pulse)}.list-none{list-style-type:none}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-\[14px_1fr\]{grid-template-columns:14px 1fr}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-baseline{align-items:baseline}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-0\.5{gap:calc(var(--spacing) * .5)}.gap-1{gap:var(--spacing)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.gap-2\.5{gap:calc(var(--spacing) * 2.5)}.gap-3{gap:calc(var(--spacing) * 3)}.gap-4{gap:calc(var(--spacing) * 4)}.gap-\[7px\]{gap:7px}.gap-x-2\.5{column-gap:calc(var(--spacing) * 2.5)}.self-end{align-self:flex-end}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.border{border-style:var(--tw-border-style);border-width:1px}.border-0{border-style:var(--tw-border-style);border-width:0}.border-y{border-block-style:var(--tw-border-style);border-block-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-l{border-left-style:var(--tw-border-style);border-left-width:1px}.border-l-2{border-left-style:var(--tw-border-style);border-left-width:2px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-cream\/10{border-color:#fdfef61a}@supports (color:color-mix(in lab,red,red)){.border-cream\/10{border-color:color-mix(in oklab,var(--color-cream) 10%,transparent)}}.border-cream\/15{border-color:#fdfef626}@supports (color:color-mix(in lab,red,red)){.border-cream\/15{border-color:color-mix(in oklab,var(--color-cream) 15%,transparent)}}.border-cream\/20{border-color:#fdfef633}@supports (color:color-mix(in lab,red,red)){.border-cream\/20{border-color:color-mix(in oklab,var(--color-cream) 20%,transparent)}}.border-red{border-color:var(--color-red)}.border-transparent{border-color:#0000}.bg-accent{background-color:var(--color-accent)}.bg-accent\/15{background-color:#46d7d426}@supports (color:color-mix(in lab,red,red)){.bg-accent\/15{background-color:color-mix(in oklab,var(--color-accent) 15%,transparent)}}.bg-bar{background-color:var(--color-bar)}.bg-black{background-color:var(--color-black)}.bg-cream\/10{background-color:#fdfef61a}@supports (color:color-mix(in lab,red,red)){.bg-cream\/10{background-color:color-mix(in oklab,var(--color-cream) 10%,transparent)}}.bg-cream\/20{background-color:#fdfef633}@supports (color:color-mix(in lab,red,red)){.bg-cream\/20{background-color:color-mix(in oklab,var(--color-cream) 20%,transparent)}}.bg-cream\/55{background-color:#fdfef68c}@supports (color:color-mix(in lab,red,red)){.bg-cream\/55{background-color:color-mix(in oklab,var(--color-cream) 55%,transparent)}}.bg-ink{background-color:var(--color-ink)}.bg-ink\/70{background-color:#1a1918b3}@supports (color:color-mix(in lab,red,red)){.bg-ink\/70{background-color:color-mix(in oklab,var(--color-ink) 70%,transparent)}}.bg-panel{background-color:var(--color-panel)}.bg-red{background-color:var(--color-red)}.bg-red\/10{background-color:#ff74741a}@supports (color:color-mix(in lab,red,red)){.bg-red\/10{background-color:color-mix(in oklab,var(--color-red) 10%,transparent)}}.bg-white{background-color:var(--color-white)}.p-2{padding:calc(var(--spacing) * 2)}.p-3{padding:calc(var(--spacing) * 3)}.p-5{padding:calc(var(--spacing) * 5)}.p-6{padding:calc(var(--spacing) * 6)}.p-12{padding:calc(var(--spacing) * 12)}.\!px-0{padding-inline:0!important}.px-1\.5{padding-inline:calc(var(--spacing) * 1.5)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-2\.5{padding-block:calc(var(--spacing) * 2.5)}.py-3{padding-block:calc(var(--spacing) * 3)}.py-px{padding-block:1px}.pt-2{padding-top:calc(var(--spacing) * 2)}.pt-2\.5{padding-top:calc(var(--spacing) * 2.5)}.pt-6{padding-top:calc(var(--spacing) * 6)}.pb-2{padding-bottom:calc(var(--spacing) * 2)}.pb-3{padding-bottom:calc(var(--spacing) * 3)}.pb-4{padding-bottom:calc(var(--spacing) * 4)}.pb-16{padding-bottom:calc(var(--spacing) * 16)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.font-sans{font-family:var(--font-sans)}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[0\.625rem\]{font-size:.625rem}.text-\[0\.6875rem\]{font-size:.6875rem}.text-\[0\.8125rem\]{font-size:.8125rem}.text-\[0\.9375rem\]{font-size:.9375rem}.text-\[1\.0625rem\]{font-size:1.0625rem}.text-\[11px\]{font-size:11px}.leading-5{--tw-leading:calc(var(--spacing) * 5);line-height:calc(var(--spacing) * 5)}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-\[-0\.01em\]{--tw-tracking:-.01em;letter-spacing:-.01em}.tracking-\[0\.01em\]{--tw-tracking:.01em;letter-spacing:.01em}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-wrap{white-space:pre-wrap}.text-accent{color:var(--color-accent)}.text-cream{color:var(--color-cream)}.text-cream\/25{color:#fdfef640}@supports (color:color-mix(in lab,red,red)){.text-cream\/25{color:color-mix(in oklab,var(--color-cream) 25%,transparent)}}.text-cream\/35{color:#fdfef659}@supports (color:color-mix(in lab,red,red)){.text-cream\/35{color:color-mix(in oklab,var(--color-cream) 35%,transparent)}}.text-cream\/40{color:#fdfef666}@supports (color:color-mix(in lab,red,red)){.text-cream\/40{color:color-mix(in oklab,var(--color-cream) 40%,transparent)}}.text-cream\/45{color:#fdfef673}@supports (color:color-mix(in lab,red,red)){.text-cream\/45{color:color-mix(in oklab,var(--color-cream) 45%,transparent)}}.text-cream\/55{color:#fdfef68c}@supports (color:color-mix(in lab,red,red)){.text-cream\/55{color:color-mix(in oklab,var(--color-cream) 55%,transparent)}}.text-cream\/60{color:#fdfef699}@supports (color:color-mix(in lab,red,red)){.text-cream\/60{color:color-mix(in oklab,var(--color-cream) 60%,transparent)}}.text-cream\/70{color:#fdfef6b3}@supports (color:color-mix(in lab,red,red)){.text-cream\/70{color:color-mix(in oklab,var(--color-cream) 70%,transparent)}}.text-cream\/75{color:#fdfef6bf}@supports (color:color-mix(in lab,red,red)){.text-cream\/75{color:color-mix(in oklab,var(--color-cream) 75%,transparent)}}.text-red{color:var(--color-red)}.not-italic{font-style:normal}.tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,) var(--tw-slashed-zero,) var(--tw-numeric-figure,) var(--tw-numeric-spacing,) var(--tw-numeric-fraction,)}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_0_0_1px\]{--tw-shadow:0 0 0 1px var(--tw-shadow-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_8px_24px_-8px\]{--tw-shadow:0 8px 24px -8px var(--tw-shadow-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-black\/60{--tw-shadow-color:#0009}@supports (color:color-mix(in lab,red,red)){.shadow-black\/60{--tw-shadow-color:color-mix(in oklab, color-mix(in oklab, var(--color-black) 60%, transparent) var(--tw-shadow-alpha), transparent)}}.shadow-cream\/25{--tw-shadow-color:#fdfef640}@supports (color:color-mix(in lab,red,red)){.shadow-cream\/25{--tw-shadow-color:color-mix(in oklab, color-mix(in oklab, var(--color-cream) 25%, transparent) var(--tw-shadow-alpha), transparent)}}.transition-\[width\]{transition-property:width;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-transform{transition-property:transform,translate,scale,rotate;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.select-none{-webkit-user-select:none;user-select:none}@media(hover:hover){.group-hover\:border-cream\/35:is(:where(.group):hover *){border-color:#fdfef659}@supports (color:color-mix(in lab,red,red)){.group-hover\:border-cream\/35:is(:where(.group):hover *){border-color:color-mix(in oklab,var(--color-cream) 35%,transparent)}}}.first\:mt-0:first-child{margin-top:0}.last\:border-b-0:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}@media(hover:hover){.hover\:bg-cream\/5:hover{background-color:#fdfef60d}@supports (color:color-mix(in lab,red,red)){.hover\:bg-cream\/5:hover{background-color:color-mix(in oklab,var(--color-cream) 5%,transparent)}}.hover\:text-cream:hover{color:var(--color-cream)}}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:opacity-40:disabled{opacity:.4}@media(prefers-reduced-motion:reduce){.motion-reduce\:transition-none{transition-property:none}}@media(min-width:40rem){.sm\:block{display:block}.sm\:grid-cols-\[repeat\(auto-fill\,minmax\(200px\,1fr\)\)\]{grid-template-columns:repeat(auto-fill,minmax(200px,1fr))}.sm\:gap-6{gap:calc(var(--spacing) * 6)}.sm\:px-0{padding-inline:0}.sm\:px-6{padding-inline:calc(var(--spacing) * 6)}.sm\:pt-10{padding-top:calc(var(--spacing) * 10)}}}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-ordinal{syntax:"*";inherits:false}@property --tw-slashed-zero{syntax:"*";inherits:false}@property --tw-numeric-figure{syntax:"*";inherits:false}@property --tw-numeric-spacing{syntax:"*";inherits:false}@property --tw-numeric-fraction{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes pulse{50%{opacity:.5}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/studio",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "The Superwall studio: paywall browsing, device preview, and editing surfaces. Shared between `superwall dev` (local studio) and the hosted dashboard.",
5
5
  "keywords": [
6
6
  "paywall",
@@ -23,8 +23,19 @@
23
23
  "src"
24
24
  ],
25
25
  "type": "module",
26
+ "sideEffects": [
27
+ "*.css"
28
+ ],
26
29
  "exports": {
27
- ".": "./src/index.ts",
30
+ ".": {
31
+ "types": "./dist/lib/index.d.ts",
32
+ "default": "./dist/lib/index.js"
33
+ },
34
+ "./products": {
35
+ "types": "./dist/lib/lib/products.d.ts",
36
+ "default": "./dist/lib/products.js"
37
+ },
38
+ "./studio.css": "./dist/lib/studio.css",
28
39
  "./styles.css": "./src/styles.css",
29
40
  "./package.json": "./package.json"
30
41
  },
@@ -33,9 +44,9 @@
33
44
  },
34
45
  "scripts": {
35
46
  "dev": "vite",
36
- "build": "vite build",
47
+ "build": "vite build && vite build -c vite.lib.config.ts && tsc -p tsconfig.lib.json",
37
48
  "preview": "vite preview",
38
- "typecheck": "tsc -p tsconfig.json",
49
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.lib.json --noEmit",
39
50
  "test": "vitest",
40
51
  "test:run": "vitest --run",
41
52
  "test:coverage": "vitest --run --coverage",
package/src/StudioApp.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { StudioShell } from "./components/StudioShell";
2
3
  import { SurfaceEditor } from "./screens/SurfaceEditor";
3
4
  import { SurfaceList } from "./screens/SurfaceList";
4
5
  import { devicePreviewPath, surfacePath } from "./lib/preview";
@@ -56,7 +57,7 @@ export const StudioApp = ({
56
57
  const active = device ? undefined : surfaceFromPath(source.surfaces, pathname);
57
58
 
58
59
  return (
59
- <div className="bg-ink text-cream fixed inset-0 flex flex-col font-sans text-[0.9375rem] tracking-[-0.01em] antialiased">
60
+ <StudioShell>
60
61
  {active ? (
61
62
  <SurfaceEditor
62
63
  source={source}
@@ -73,6 +74,6 @@ export const StudioApp = ({
73
74
  }
74
75
  />
75
76
  )}
76
- </div>
77
+ </StudioShell>
77
78
  );
78
79
  };
@@ -116,7 +116,7 @@ export const ActionMenu = ({
116
116
  React.useEffect(() => {
117
117
  if (!open) return undefined;
118
118
  const close = (event: MouseEvent) => {
119
- if (!menuRef.current?.contains(event.target as Node)) setOpen(false);
119
+ if (menuRef.current && !event.composedPath().includes(menuRef.current)) setOpen(false);
120
120
  };
121
121
  window.addEventListener("mousedown", close);
122
122
  return () => window.removeEventListener("mousedown", close);
@@ -52,7 +52,7 @@ export const CompareMenu = ({
52
52
  React.useEffect(() => {
53
53
  if (!open) return undefined;
54
54
  const close = (event: MouseEvent) => {
55
- if (!menuRef.current?.contains(event.target as Node)) setOpen(false);
55
+ if (menuRef.current && !event.composedPath().includes(menuRef.current)) setOpen(false);
56
56
  };
57
57
  window.addEventListener("mousedown", close);
58
58
  return () => window.removeEventListener("mousedown", close);
@@ -186,6 +186,7 @@ export const PaywallToasts = ({
186
186
  return;
187
187
  }
188
188
 
189
+ if (event.data.type !== "event") return;
189
190
  const notice = noticeFor(event.data.message);
190
191
  if (notice) toast.custom(() => <Notice notice={notice} />);
191
192
  };
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+
3
+ export const StudioShell = ({
4
+ children,
5
+ position = "fixed",
6
+ }: React.PropsWithChildren<{ position?: "fixed" | "absolute" }>) => (
7
+ <div
8
+ className={`sw-studio bg-ink text-cream ${position} inset-0 flex flex-col font-sans text-[0.9375rem] tracking-[-0.01em] antialiased`}
9
+ >
10
+ {children}
11
+ </div>
12
+ );
package/src/index.ts CHANGED
@@ -4,16 +4,24 @@ export { StudioApp } from "./StudioApp";
4
4
  export { SurfaceEditor } from "./screens/SurfaceEditor";
5
5
  export { SurfaceList } from "./screens/SurfaceList";
6
6
  export { DeviceFrame } from "./components/DeviceFrame";
7
+ export { StudioShell } from "./components/StudioShell";
7
8
  export { TopBar } from "./components/TopBar";
8
9
  export { VariablesPanel } from "./components/VariablesPanel";
9
10
  export { Segmented, Select, Switch } from "./components/controls";
10
11
  export { DEFAULT_DEVICE_ID, deviceById, STUDIO_DEVICES } from "./lib/devices";
11
12
  export type { StudioDevice } from "./lib/devices";
12
- export { buildPreviewPath } from "./lib/preview";
13
+ export {
14
+ buildPreviewPath,
15
+ snapshotPreviewUrl,
16
+ withOverrides,
17
+ withPreviewOptIn,
18
+ } from "./lib/preview";
13
19
  export { parseProjectPayload, type StudioProjectPayload } from "./lib/project";
14
20
  export type {
15
21
  PreviewOverrides,
16
22
  PreviewUrlBuilder,
23
+ SampleDefaults,
24
+ Samples,
17
25
  StudioSource,
18
26
  StudioSurface,
19
27
  StudioSurfaceKind,
package/src/lib/events.ts CHANGED
@@ -3,6 +3,7 @@ export const STUDIO_CHANNEL = "superwall-studio";
3
3
  export type PaywallEvent = { event_name: string } & Record<string, unknown>;
4
4
 
5
5
  export type BridgeMessage =
6
+ | { channel: typeof STUDIO_CHANNEL; type: "hello"; locales: string[] }
6
7
  | { channel: typeof STUDIO_CHANNEL; type: "event"; message: PaywallEvent }
7
8
  | {
8
9
  channel: typeof STUDIO_CHANNEL;
@@ -74,4 +75,12 @@ export const isBridgeMessage = (data: unknown): data is BridgeMessage =>
74
75
  typeof data === "object" &&
75
76
  data !== null &&
76
77
  Reflect.get(data, "channel") === STUDIO_CHANNEL &&
77
- (Reflect.get(data, "type") === "event" || Reflect.get(data, "type") === "ask");
78
+ ["hello", "event", "ask"].includes(String(Reflect.get(data, "type")));
79
+
80
+ const isStringArray = (value: unknown): value is string[] =>
81
+ Array.isArray(value) && value.every((entry) => typeof entry === "string");
82
+
83
+ export const localesAnnounced = (data: unknown): string[] | undefined =>
84
+ isBridgeMessage(data) && data.type === "hello" && isStringArray(data.locales)
85
+ ? data.locales
86
+ : undefined;
@@ -37,3 +37,13 @@ export const withOverrides = (url: string, overrides: PreviewOverrides): string
37
37
  if (!query) return url;
38
38
  return `${url}${url.includes("?") ? "&" : "?"}${query}`;
39
39
  };
40
+
41
+ export const withPreviewOptIn = (url: string): string => {
42
+ if (/[?&]sw_preview=/.test(url)) return url;
43
+ return `${url}${url.includes("?") ? "&" : "?"}sw_preview=1`;
44
+ };
45
+
46
+ export const snapshotPreviewUrl =
47
+ (urlOf: (surface: StudioSurface) => string): PreviewUrlBuilder =>
48
+ (surface, overrides) =>
49
+ withOverrides(withPreviewOptIn(urlOf(surface)), overrides);
@@ -0,0 +1,97 @@
1
+ export interface DashboardPrice {
2
+ amount?: number;
3
+ currency?: string;
4
+ }
5
+
6
+ export interface DashboardProduct {
7
+ identifier?: string;
8
+ price?: DashboardPrice | null;
9
+ trial_price?: DashboardPrice | null;
10
+ monthly_billing_plan_price?: DashboardPrice | null;
11
+ subscription?: {
12
+ period?: string;
13
+ period_count?: number;
14
+ trial_period_days?: number | null;
15
+ } | null;
16
+ }
17
+
18
+ const SYMBOLS: Record<string, string> = {
19
+ USD: "$",
20
+ CAD: "$",
21
+ AUD: "$",
22
+ NZD: "$",
23
+ EUR: "€",
24
+ GBP: "£",
25
+ JPY: "¥",
26
+ CNY: "¥",
27
+ INR: "₹",
28
+ KRW: "₩",
29
+ BRL: "R$",
30
+ MXN: "$",
31
+ CHF: "CHF",
32
+ SEK: "kr",
33
+ NOK: "kr",
34
+ DKK: "kr",
35
+ PLN: "zł",
36
+ TRY: "₺",
37
+ RUB: "₽",
38
+ ZAR: "R",
39
+ };
40
+
41
+ const MINOR = 100;
42
+
43
+ const PER_YEAR: Record<string, number> = { day: 365, week: 52, month: 12, year: 1 };
44
+
45
+ const symbolFor = (currency: string): string => SYMBOLS[currency.toUpperCase()] ?? "";
46
+
47
+ const money = (amount: number, currency: string): string => {
48
+ try {
49
+ return new Intl.NumberFormat("en-US", { style: "currency", currency }).format(amount);
50
+ } catch {
51
+ return `${symbolFor(currency)}${amount.toFixed(2)}`;
52
+ }
53
+ };
54
+
55
+ const PERIODLY: Record<string, string> = {
56
+ day: "daily",
57
+ week: "weekly",
58
+ month: "monthly",
59
+ year: "yearly",
60
+ };
61
+
62
+ export const productVariables = (product: DashboardProduct): Record<string, unknown> => {
63
+ const variables: Record<string, unknown> = {};
64
+ if (product.identifier) variables.identifier = product.identifier;
65
+
66
+ const price = product.price;
67
+ if (!price || typeof price.amount !== "number" || !price.currency) return variables;
68
+
69
+ const currency = price.currency.toUpperCase();
70
+ const value = price.amount / MINOR;
71
+ variables.price = money(value, currency);
72
+ variables.rawPrice = value;
73
+ variables.currencyCode = currency;
74
+ variables.currencySymbol = symbolFor(currency);
75
+
76
+ const period = product.subscription?.period;
77
+ if (!period) return variables;
78
+
79
+ const count = product.subscription?.period_count ?? 1;
80
+ variables.period = period;
81
+ variables.periodly = PERIODLY[period] ?? `${period}ly`;
82
+ variables[`period${period.charAt(0).toUpperCase()}${period.slice(1)}s`] = count;
83
+
84
+ const perYear = (PER_YEAR[period] ?? 1) / count;
85
+ variables.yearlyPrice = money(value * perYear, currency);
86
+ variables.monthlyPrice = money((value * perYear) / 12, currency);
87
+ variables.weeklyPrice = money((value * perYear) / 52, currency);
88
+ variables.dailyPrice = money((value * perYear) / 365, currency);
89
+
90
+ const trialDays = product.subscription?.trial_period_days;
91
+ if (typeof trialDays === "number" && trialDays > 0) {
92
+ variables.trialPeriodDays = trialDays;
93
+ variables.trialPeriodText = `${trialDays}-day`;
94
+ }
95
+
96
+ return variables;
97
+ };
package/src/lib/types.ts CHANGED
@@ -4,6 +4,7 @@ export type StudioSurface = {
4
4
  kind: StudioSurfaceKind;
5
5
  id: string;
6
6
  project?: string;
7
+ label?: string;
7
8
  products?: Record<string, string>;
8
9
  routes: string[];
9
10
  locales: string[];
@@ -73,6 +74,7 @@ export type StudioSource = {
73
74
  samples?: SampleDefaults;
74
75
  previewUrl: PreviewUrlBuilder;
75
76
  capabilities?: { actions: boolean };
77
+ compareHint?: string;
76
78
  };
77
79
 
78
80
  export type Samples = {