@whop/elements 0.0.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Whop, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @whop/elements
2
+
3
+ Embed Whop in any site. Elements are hosted, themeable UI components across Whop's
4
+ product surface, with the catalog growing steadily. This package is a tiny loader plus
5
+ the full typed API: the element code itself is served from Whop's CDN and stays up to
6
+ date without you re-installing anything.
7
+
8
+ ```ts
9
+ import { loadWhop } from '@whop/elements';
10
+
11
+ const whop = (await loadWhop())({ locale: 'en' });
12
+ ```
13
+
14
+ Every element group hangs off the instance — create a handle, mount elements, listen to
15
+ events. The full catalog, live demos, and per-element API live in the docs.
16
+
17
+ Or warm the script from your document head:
18
+
19
+ ```ts
20
+ import { preloadHints } from '@whop/elements';
21
+ // render as <link> tags: [{ rel: 'preconnect', ... }, { rel: 'preload', ... }]
22
+ ```
23
+
24
+ Using React? [`@whop/elements-react`](https://www.npmjs.com/package/@whop/elements-react)
25
+ wraps the same elements as components.
26
+
27
+ ## Documentation
28
+
29
+ https://docs.whop.com/elements/latest
@@ -0,0 +1,179 @@
1
+ /** The locales this app's elements are built with (the default locale first) — element UI
2
+ * text ships in each of these. Any other value falls back to the default locale. Validate
3
+ * dynamic strings with `WHOP_ELEMENTS_LOCALES.includes(...)` from the package root. */
4
+ export type WhopElementsLocale = "en" | "es" | "zh" | "nl" | "pt" | "de" | "it" | "fr" | "ja" | "pl" | "tr";
5
+
6
+ /**
7
+ * A CSS property value, as a string (include units: `"12px"`, not `12`).
8
+ */
9
+ export type CSSValue = string;
10
+
11
+ /**
12
+ * A style declaration object that maps CSS properties to values, like React's `CSSProperties`.
13
+ * Property names can use camel case (`fontWeight`) or kebab case (`font-weight`). The framework
14
+ * normalizes each name and checks it against the list of safe properties before applying it.
15
+ */
16
+ export type CSSProps = Record<string, CSSValue>;
17
+
18
+ /**
19
+ * Style declarations for each `whop-*` class name. Each entry restyles one documented part of an
20
+ * element. See the Styling section on each element page for its class list. The framework checks
21
+ * each declaration, then injects the sanitized result inside the element's frame because page
22
+ * stylesheets cannot reach it.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * classes: {
27
+ * "whop-TipSummary": { fontWeight: "600", borderRadius: "8px" },
28
+ * }
29
+ * ```
30
+ */
31
+ export type Classes = Record<string, CSSProps>;
32
+
33
+ /**
34
+ * CSS custom properties (variables) that can be used to customize element styles.
35
+ * Keys must start with `--` prefix.
36
+ */
37
+ export type Variables = Record<`--${string}`, string>;
38
+
39
+ /**
40
+ * Available accent colors for theming elements.
41
+ *
42
+ * These colors are used for primary UI elements like buttons, links, and highlights.
43
+ */
44
+ export type AccentColor =
45
+ | "ruby"
46
+ | "blue"
47
+ | "red"
48
+ | "yellow"
49
+ | "green"
50
+ | "gray"
51
+ | "tomato"
52
+ | "crimson"
53
+ | "pink"
54
+ | "plum"
55
+ | "purple"
56
+ | "violet"
57
+ | "iris"
58
+ | "cyan"
59
+ | "teal"
60
+ | "jade"
61
+ | "grass"
62
+ | "brown"
63
+ | "orange"
64
+ | "indigo"
65
+ | "sky"
66
+ | "mint"
67
+ | "amber"
68
+ | "lime"
69
+ | "lemon"
70
+ | "magenta"
71
+ | "gold"
72
+ | "bronze";
73
+
74
+ /**
75
+ * Theme configuration for customizing the visual appearance of elements.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const theme: Theme = {
80
+ * appearance: "dark",
81
+ * accentColor: "blue",
82
+ * grayColor: "slate",
83
+ * };
84
+ * ```
85
+ */
86
+ export type Theme = {
87
+ /**
88
+ * The color scheme to use.
89
+ * - `"light"` - Light mode with dark text on light backgrounds
90
+ * - `"dark"` - Dark mode with light text on dark backgrounds
91
+ */
92
+ appearance?: "light" | "dark";
93
+ /**
94
+ * The primary accent color used for interactive elements.
95
+ */
96
+ accentColor?: AccentColor;
97
+ /**
98
+ * The gray color palette to use for neutral elements.
99
+ * Use `"auto"` to automatically match the accent color.
100
+ */
101
+ grayColor?: "gray" | "mauve" | "slate" | "sage" | "olive" | "sand" | "auto";
102
+ /**
103
+ * The color used for error states and destructive actions.
104
+ */
105
+ dangerColor?: "ruby" | "red" | "tomato";
106
+ /**
107
+ * The color used for warning states.
108
+ */
109
+ warningColor?: "yellow" | "amber";
110
+ /**
111
+ * The color used for success states.
112
+ */
113
+ successColor?: "green" | "teal" | "jade" | "grass";
114
+ /**
115
+ * The color used for informational states.
116
+ */
117
+ infoColor?: "sky" | "blue";
118
+ };
119
+
120
+ /**
121
+ * Configuration for customizing the visual appearance of Whop elements.
122
+ *
123
+ * Use this to match the embedded components to your application's design.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const appearance: Appearance = {
128
+ * theme: {
129
+ * appearance: "dark",
130
+ * accentColor: "blue",
131
+ * },
132
+ * };
133
+ *
134
+ * const whopElements = WhopElements({ appearance });
135
+ * ```
136
+ */
137
+ export type Appearance = {
138
+ /**
139
+ * CSS custom properties to override default styles.
140
+ */
141
+ variables?: Variables | null;
142
+ /**
143
+ * Custom CSS classes to apply to elements.
144
+ */
145
+ classes?: Classes | null;
146
+ /**
147
+ * Theme settings for colors and appearance mode.
148
+ */
149
+ theme?: Theme | null;
150
+ };
151
+
152
+ /**
153
+ * Framework-provided global config — NOT authored. Set on `WhopElements(config)` and
154
+ * delivered by the framework: `theme`/`locale` ride the iframe URL params (so the boot
155
+ * script applies them before first paint — anti-flash), `appearance` rides `init`, and
156
+ * `baseUrl` selects the element origin. Merged with any Root app globals (currently none).
157
+ */
158
+ export interface FrameworkGlobals {
159
+ /** Visual customization for every element — `theme` (light/dark + palettes), `variables`
160
+ * (CSS custom properties), and `classes` (per-part style declarations). The color scheme is
161
+ * applied before an element's first paint, so dark pages never flash light. */
162
+ appearance?: Appearance;
163
+ /** Locale for element UI text — one of the app's built locales; any other value falls back
164
+ * to the default locale. @default "en" */
165
+ locale?: WhopElementsLocale;
166
+ /** Which Whop API environment the elements talk to — `"sandbox"` targets the sandbox API
167
+ * (test data; no real money moves). Choosing an environment is the only way to change where
168
+ * the elements send what a buyer types, and both environments are Whop's own. The sandbox
169
+ * environment is not yet generally available. @default "production" */
170
+ environment?: "production" | "sandbox";
171
+ /** Whether elements may show toast notifications on your page — brief status messages
172
+ * ("Payment method added", "Payment failed") rendered in the bottom-right corner. Set
173
+ * `false` to turn them off entirely. @default true */
174
+ toasts?: boolean;
175
+ /** Origin serving the hosted element pages — for testing against a different environment.
176
+ * Cannot change after load.
177
+ * @internal */
178
+ baseUrl?: string;
179
+ }
@@ -0,0 +1,179 @@
1
+ /** The locales this app's elements are built with (the default locale first) — element UI
2
+ * text ships in each of these. Any other value falls back to the default locale. Validate
3
+ * dynamic strings with `WHOP_ELEMENTS_LOCALES.includes(...)` from the package root. */
4
+ export type WhopElementsLocale = "en" | "es" | "zh" | "nl" | "pt" | "de" | "it" | "fr" | "ja" | "pl" | "tr";
5
+
6
+ /**
7
+ * A CSS property value, as a string (include units: `"12px"`, not `12`).
8
+ */
9
+ export type CSSValue = string;
10
+
11
+ /**
12
+ * A style declaration object that maps CSS properties to values, like React's `CSSProperties`.
13
+ * Property names can use camel case (`fontWeight`) or kebab case (`font-weight`). The framework
14
+ * normalizes each name and checks it against the list of safe properties before applying it.
15
+ */
16
+ export type CSSProps = Record<string, CSSValue>;
17
+
18
+ /**
19
+ * Style declarations for each `whop-*` class name. Each entry restyles one documented part of an
20
+ * element. See the Styling section on each element page for its class list. The framework checks
21
+ * each declaration, then injects the sanitized result inside the element's frame because page
22
+ * stylesheets cannot reach it.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * classes: {
27
+ * "whop-TipSummary": { fontWeight: "600", borderRadius: "8px" },
28
+ * }
29
+ * ```
30
+ */
31
+ export type Classes = Record<string, CSSProps>;
32
+
33
+ /**
34
+ * CSS custom properties (variables) that can be used to customize element styles.
35
+ * Keys must start with `--` prefix.
36
+ */
37
+ export type Variables = Record<`--${string}`, string>;
38
+
39
+ /**
40
+ * Available accent colors for theming elements.
41
+ *
42
+ * These colors are used for primary UI elements like buttons, links, and highlights.
43
+ */
44
+ export type AccentColor =
45
+ | "ruby"
46
+ | "blue"
47
+ | "red"
48
+ | "yellow"
49
+ | "green"
50
+ | "gray"
51
+ | "tomato"
52
+ | "crimson"
53
+ | "pink"
54
+ | "plum"
55
+ | "purple"
56
+ | "violet"
57
+ | "iris"
58
+ | "cyan"
59
+ | "teal"
60
+ | "jade"
61
+ | "grass"
62
+ | "brown"
63
+ | "orange"
64
+ | "indigo"
65
+ | "sky"
66
+ | "mint"
67
+ | "amber"
68
+ | "lime"
69
+ | "lemon"
70
+ | "magenta"
71
+ | "gold"
72
+ | "bronze";
73
+
74
+ /**
75
+ * Theme configuration for customizing the visual appearance of elements.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const theme: Theme = {
80
+ * appearance: "dark",
81
+ * accentColor: "blue",
82
+ * grayColor: "slate",
83
+ * };
84
+ * ```
85
+ */
86
+ export type Theme = {
87
+ /**
88
+ * The color scheme to use.
89
+ * - `"light"` - Light mode with dark text on light backgrounds
90
+ * - `"dark"` - Dark mode with light text on dark backgrounds
91
+ */
92
+ appearance?: "light" | "dark";
93
+ /**
94
+ * The primary accent color used for interactive elements.
95
+ */
96
+ accentColor?: AccentColor;
97
+ /**
98
+ * The gray color palette to use for neutral elements.
99
+ * Use `"auto"` to automatically match the accent color.
100
+ */
101
+ grayColor?: "gray" | "mauve" | "slate" | "sage" | "olive" | "sand" | "auto";
102
+ /**
103
+ * The color used for error states and destructive actions.
104
+ */
105
+ dangerColor?: "ruby" | "red" | "tomato";
106
+ /**
107
+ * The color used for warning states.
108
+ */
109
+ warningColor?: "yellow" | "amber";
110
+ /**
111
+ * The color used for success states.
112
+ */
113
+ successColor?: "green" | "teal" | "jade" | "grass";
114
+ /**
115
+ * The color used for informational states.
116
+ */
117
+ infoColor?: "sky" | "blue";
118
+ };
119
+
120
+ /**
121
+ * Configuration for customizing the visual appearance of Whop elements.
122
+ *
123
+ * Use this to match the embedded components to your application's design.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const appearance: Appearance = {
128
+ * theme: {
129
+ * appearance: "dark",
130
+ * accentColor: "blue",
131
+ * },
132
+ * };
133
+ *
134
+ * const whopElements = WhopElements({ appearance });
135
+ * ```
136
+ */
137
+ export type Appearance = {
138
+ /**
139
+ * CSS custom properties to override default styles.
140
+ */
141
+ variables?: Variables | null;
142
+ /**
143
+ * Custom CSS classes to apply to elements.
144
+ */
145
+ classes?: Classes | null;
146
+ /**
147
+ * Theme settings for colors and appearance mode.
148
+ */
149
+ theme?: Theme | null;
150
+ };
151
+
152
+ /**
153
+ * Framework-provided global config — NOT authored. Set on `WhopElements(config)` and
154
+ * delivered by the framework: `theme`/`locale` ride the iframe URL params (so the boot
155
+ * script applies them before first paint — anti-flash), `appearance` rides `init`, and
156
+ * `baseUrl` selects the element origin. Merged with any Root app globals (currently none).
157
+ */
158
+ export interface FrameworkGlobals {
159
+ /** Visual customization for every element — `theme` (light/dark + palettes), `variables`
160
+ * (CSS custom properties), and `classes` (per-part style declarations). The color scheme is
161
+ * applied before an element's first paint, so dark pages never flash light. */
162
+ appearance?: Appearance;
163
+ /** Locale for element UI text — one of the app's built locales; any other value falls back
164
+ * to the default locale. @default "en" */
165
+ locale?: WhopElementsLocale;
166
+ /** Which Whop API environment the elements talk to — `"sandbox"` targets the sandbox API
167
+ * (test data; no real money moves). Choosing an environment is the only way to change where
168
+ * the elements send what a buyer types, and both environments are Whop's own. The sandbox
169
+ * environment is not yet generally available. @default "production" */
170
+ environment?: "production" | "sandbox";
171
+ /** Whether elements may show toast notifications on your page — brief status messages
172
+ * ("Payment method added", "Payment failed") rendered in the bottom-right corner. Set
173
+ * `false` to turn them off entirely. @default true */
174
+ toasts?: boolean;
175
+ /** Origin serving the hosted element pages — for testing against a different environment.
176
+ * Cannot change after load.
177
+ * @internal */
178
+ baseUrl?: string;
179
+ }