@linktr.ee/linkapp 0.0.20 → 0.0.22

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 (68) hide show
  1. package/dev-server/classic/main.tsx +313 -29
  2. package/dev-server/classic.html +21 -35
  3. package/dev-server/components/SettingsPreview.tsx +330 -0
  4. package/dev-server/components/ui/dialog.tsx +6 -3
  5. package/dev-server/featured/main.tsx +313 -29
  6. package/dev-server/featured.html +21 -35
  7. package/dev-server/index.html +8 -1
  8. package/dev-server/lib/utils.ts +6 -0
  9. package/dev-server/package-lock.json +245 -287
  10. package/dev-server/package.json +5 -1
  11. package/dev-server/postcss.config.mjs +5 -0
  12. package/dev-server/preview/Preview.tsx +95 -69
  13. package/dev-server/preview/preview.css +20 -35
  14. package/dev-server/public/apple-touch-icon.png +0 -0
  15. package/dev-server/public/favicon-96x96.png +0 -0
  16. package/dev-server/public/favicon.ico +0 -0
  17. package/dev-server/public/favicon.svg +6 -0
  18. package/dev-server/public/site.webmanifest +21 -0
  19. package/dev-server/public/web-app-manifest-192x192.png +0 -0
  20. package/dev-server/public/web-app-manifest-512x512.png +0 -0
  21. package/dev-server/vite-env.d.ts +8 -0
  22. package/dev-server/vite.config.ts +5 -0
  23. package/dist/commands/deploy.d.ts.map +1 -1
  24. package/dist/commands/deploy.js +19 -17
  25. package/dist/commands/deploy.js.map +1 -1
  26. package/dist/commands/dev.d.ts.map +1 -1
  27. package/dist/commands/dev.js +110 -2
  28. package/dist/commands/dev.js.map +1 -1
  29. package/dist/commands/test-url-match-rules.js +1 -1
  30. package/dist/commands/test-url-match-rules.js.map +1 -1
  31. package/dist/components/index.d.ts +0 -1
  32. package/dist/components/index.d.ts.map +1 -1
  33. package/dist/components/index.js +2 -1
  34. package/dist/components/index.js.map +1 -1
  35. package/dist/lib/auth/device-flow.d.ts +1 -6
  36. package/dist/lib/auth/device-flow.d.ts.map +1 -1
  37. package/dist/lib/auth/device-flow.js +3 -9
  38. package/dist/lib/auth/device-flow.js.map +1 -1
  39. package/dist/lib/auth/token-storage.d.ts +0 -5
  40. package/dist/lib/auth/token-storage.d.ts.map +1 -1
  41. package/dist/lib/auth/token-storage.js +16 -14
  42. package/dist/lib/auth/token-storage.js.map +1 -1
  43. package/dist/lib/deploy/generate-manifest-files.js +1 -1
  44. package/dist/lib/deploy/generate-manifest-files.js.map +1 -1
  45. package/dist/lib/deploy/pack-project.js +1 -1
  46. package/dist/lib/deploy/pack-project.js.map +1 -1
  47. package/dist/lib/deploy/test-url-match-rules.d.ts +2 -1
  48. package/dist/lib/deploy/test-url-match-rules.d.ts.map +1 -1
  49. package/dist/lib/deploy/test-url-match-rules.js +1 -1
  50. package/dist/lib/deploy/test-url-match-rules.js.map +1 -1
  51. package/dist/lib/deploy/upload.d.ts.map +1 -1
  52. package/dist/lib/deploy/upload.js +7 -3
  53. package/dist/lib/deploy/upload.js.map +1 -1
  54. package/dist/lib/utils/setup-runtime.d.ts.map +1 -1
  55. package/dist/lib/utils/setup-runtime.js +29 -2
  56. package/dist/lib/utils/setup-runtime.js.map +1 -1
  57. package/dist/lib/vite/config-factory.d.ts.map +1 -1
  58. package/dist/lib/vite/config-factory.js +2 -0
  59. package/dist/lib/vite/config-factory.js.map +1 -1
  60. package/dist/schema/config.schema.d.ts +104 -32
  61. package/dist/schema/config.schema.d.ts.map +1 -1
  62. package/dist/schema/config.schema.js +27 -17
  63. package/dist/schema/config.schema.js.map +1 -1
  64. package/dist/types.d.ts +6 -57
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js.map +1 -1
  67. package/package.json +1 -2
  68. package/runtime/index.html +19 -36
@@ -11,39 +11,323 @@ const Layout = Object.values(layoutModules)[0]?.default as
11
11
  | React.ComponentType<{ children: React.ReactNode; theme?: any }>
12
12
  | undefined;
13
13
 
14
+ // Declare global window property for theme application
15
+ declare global {
16
+ interface Window {
17
+ __linkapp_applyTheme?: (variables: Record<string, string>) => void
18
+ }
19
+ }
20
+
14
21
  // Preview props injected by dev server via Vite define
15
22
  declare const __PREVIEW_PROPS__: Record<string, unknown>;
16
23
 
17
- const previewProps = __PREVIEW_PROPS__ || {
18
- linkUrl: "https://example.com/demo",
19
- theme: {
20
- cssVariables: {
21
- "--button-style-text": "#000000",
22
- "--button-style-background": "#ffffff",
23
- "--button-style-inner-radius": "12px",
24
- "--button-style-border-color": "#e5e7eb",
25
- "--button-style-background-hover": "#f3f4f6",
26
- "--button-style-contrast-color": "#ffffff",
27
- "--profileBackground": "#ffffff",
28
- },
29
- // Legacy properties (deprecated)
30
- textColor: "#000000",
31
- backgroundColor: "#ffffff",
32
- borderRadius: "12px",
33
- borderColor: "#e5e7eb",
34
- backgroundHover: "#f3f4f6",
35
- contrastColor: "#ffffff",
36
- textHoverColor: "#111827",
24
+ // Theme presets matching Preview.tsx
25
+ const THEME_PRESETS: Record<string, Record<string, string>> = {
26
+ default: {
27
+ "--button-style-text": "#000000",
28
+ "--button-style-background": "#ffffff",
29
+ "--button-style-background-hover": "color-mix(in srgb, #ffffff 93%, #000000 7%)",
30
+ "--button-style-border": "none",
31
+ "--button-style-border-color": "transparent",
32
+ "--button-style-shadow": "none",
33
+ "--button-style-shadow-color": "#000000",
34
+ "--button-style-contrast-color": "#000000",
35
+ "--button-style-radius": "8px",
36
+ "--button-style-inner-radius": "min(8px, max(4px, calc(8px - 8px)))",
37
+ "--button-style-skeleton-color": "rgba(0, 0, 0, 0.05)",
38
+ "--link-gap": "14px",
39
+ "--link-inner-padding": "7px",
40
+ "--link-preview-thumbnail-width": "160px",
41
+ "--linkRadius": "8px",
42
+ "--profile-container-desktop-width": "580px",
43
+ "--profileBackground": "#eceef1",
44
+ "--background-contrast-color": "#000000",
45
+ "--bodyText": "#000000",
46
+ "--profileTitleText": "#000000",
47
+ "--profileDescriptionText": "#000000",
48
+ "--defaultAvatarBackground": "#000000",
49
+ "--defaultAvatarText": "#ffffff",
50
+ "--socialLinkFill": "#000000",
51
+ "--linkBackground": "#ffffff",
52
+ "--linkText": "#000000",
53
+ "--linkHoverBackground": "color-mix(in srgb, #ffffff 93%, #000000 7%)",
54
+ "--linkHoverText": "#000000",
55
+ "--linkShadow": "#000000",
56
+ "--bannerBackground": "#ffffff",
57
+ "--bannerText": "#000000",
58
+ "--desktop-frame-color": "color-mix(in srgb, #eceef1 88%, black 12%)",
59
+ "--profileFontFamilyPrimary": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
60
+ "--profileFontFamilySecondary": 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
61
+ "--header-font-family": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
62
+ "--profileFontWeightNormal": "500",
63
+ "--profileFontWeightBold": "700",
64
+ "--profileDescriptionFontWeight": "500",
65
+ "--linkTextFontWeight": "500",
66
+ "--headerFontWeight": "700",
67
+ "--header-font-weight": "600",
68
+ "--embedLinkTextFontWeight": "500",
69
+ "--signupSubmitTextFontWeight": "700",
70
+ "--bannerFontWeight": "700",
71
+ "--headerFontSize": "normal",
72
+ "--header-bio-font-size": "16px",
73
+ "--embedLinkTextFontSize": "14px",
74
+ "--signupSubmitTextFontSize": "14px",
75
+ "--linkHeaderFontSize": "14px",
76
+ "--bannerFontSize": "14px",
77
+ "--profileDescriptionLineHeight": "1.5",
78
+ "--headerLineHeight": "1.5",
79
+ "--header-text-color": "#000000",
80
+ },
81
+ dark: {
82
+ "--button-style-text": "#ffffff",
83
+ "--button-style-background": "#1f2937",
84
+ "--button-style-background-hover": "color-mix(in srgb, #1f2937 93%, #ffffff 7%)",
85
+ "--button-style-border": "none",
86
+ "--button-style-border-color": "transparent",
87
+ "--button-style-shadow": "none",
88
+ "--button-style-shadow-color": "#000000",
89
+ "--button-style-contrast-color": "#ffffff",
90
+ "--button-style-radius": "8px",
91
+ "--button-style-inner-radius": "min(8px, max(4px, calc(8px - 8px)))",
92
+ "--button-style-skeleton-color": "rgba(255, 255, 255, 0.1)",
93
+ "--link-gap": "14px",
94
+ "--link-inner-padding": "7px",
95
+ "--link-preview-thumbnail-width": "160px",
96
+ "--linkRadius": "8px",
97
+ "--profile-container-desktop-width": "580px",
98
+ "--profileBackground": "#111827",
99
+ "--background-contrast-color": "#ffffff",
100
+ "--bodyText": "#ffffff",
101
+ "--profileTitleText": "#ffffff",
102
+ "--profileDescriptionText": "#ffffff",
103
+ "--defaultAvatarBackground": "#ffffff",
104
+ "--defaultAvatarText": "#000000",
105
+ "--socialLinkFill": "#ffffff",
106
+ "--linkBackground": "#1f2937",
107
+ "--linkText": "#ffffff",
108
+ "--linkHoverBackground": "color-mix(in srgb, #1f2937 93%, #ffffff 7%)",
109
+ "--linkHoverText": "#ffffff",
110
+ "--linkShadow": "#000000",
111
+ "--bannerBackground": "#1f2937",
112
+ "--bannerText": "#ffffff",
113
+ "--desktop-frame-color": "color-mix(in srgb, #111827 88%, white 12%)",
114
+ "--profileFontFamilyPrimary": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
115
+ "--profileFontFamilySecondary": 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
116
+ "--header-font-family": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
117
+ "--profileFontWeightNormal": "500",
118
+ "--profileFontWeightBold": "700",
119
+ "--profileDescriptionFontWeight": "500",
120
+ "--linkTextFontWeight": "500",
121
+ "--headerFontWeight": "700",
122
+ "--header-font-weight": "600",
123
+ "--embedLinkTextFontWeight": "500",
124
+ "--signupSubmitTextFontWeight": "700",
125
+ "--bannerFontWeight": "700",
126
+ "--headerFontSize": "normal",
127
+ "--header-bio-font-size": "16px",
128
+ "--embedLinkTextFontSize": "14px",
129
+ "--signupSubmitTextFontSize": "14px",
130
+ "--linkHeaderFontSize": "14px",
131
+ "--bannerFontSize": "14px",
132
+ "--profileDescriptionLineHeight": "1.5",
133
+ "--headerLineHeight": "1.5",
134
+ "--header-text-color": "#ffffff",
135
+ },
136
+ purple: {
137
+ "--button-style-text": "#ffffff",
138
+ "--button-style-background": "#7c3aed",
139
+ "--button-style-background-hover": "color-mix(in srgb, #7c3aed 93%, #ffffff 7%)",
140
+ "--button-style-border": "none",
141
+ "--button-style-border-color": "transparent",
142
+ "--button-style-shadow": "none",
143
+ "--button-style-shadow-color": "#000000",
144
+ "--button-style-contrast-color": "#ede9fe",
145
+ "--button-style-radius": "16px",
146
+ "--button-style-inner-radius": "min(16px, max(4px, calc(16px - 8px)))",
147
+ "--button-style-skeleton-color": "rgba(124, 58, 237, 0.1)",
148
+ "--link-gap": "14px",
149
+ "--link-inner-padding": "7px",
150
+ "--link-preview-thumbnail-width": "160px",
151
+ "--linkRadius": "16px",
152
+ "--profile-container-desktop-width": "580px",
153
+ "--profileBackground": "#faf5ff",
154
+ "--background-contrast-color": "#1f2937",
155
+ "--bodyText": "#1f2937",
156
+ "--profileTitleText": "#1f2937",
157
+ "--profileDescriptionText": "#1f2937",
158
+ "--defaultAvatarBackground": "#7c3aed",
159
+ "--defaultAvatarText": "#ffffff",
160
+ "--socialLinkFill": "#1f2937",
161
+ "--linkBackground": "#7c3aed",
162
+ "--linkText": "#ffffff",
163
+ "--linkHoverBackground": "color-mix(in srgb, #7c3aed 93%, #ffffff 7%)",
164
+ "--linkHoverText": "#ffffff",
165
+ "--linkShadow": "#7c3aed",
166
+ "--bannerBackground": "#7c3aed",
167
+ "--bannerText": "#ffffff",
168
+ "--desktop-frame-color": "color-mix(in srgb, #faf5ff 88%, black 12%)",
169
+ "--profileFontFamilyPrimary": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
170
+ "--profileFontFamilySecondary": 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
171
+ "--header-font-family": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
172
+ "--profileFontWeightNormal": "500",
173
+ "--profileFontWeightBold": "700",
174
+ "--profileDescriptionFontWeight": "500",
175
+ "--linkTextFontWeight": "500",
176
+ "--headerFontWeight": "700",
177
+ "--header-font-weight": "600",
178
+ "--embedLinkTextFontWeight": "500",
179
+ "--signupSubmitTextFontWeight": "700",
180
+ "--bannerFontWeight": "700",
181
+ "--headerFontSize": "normal",
182
+ "--header-bio-font-size": "16px",
183
+ "--embedLinkTextFontSize": "14px",
184
+ "--signupSubmitTextFontSize": "14px",
185
+ "--linkHeaderFontSize": "14px",
186
+ "--bannerFontSize": "14px",
187
+ "--profileDescriptionLineHeight": "1.5",
188
+ "--headerLineHeight": "1.5",
189
+ "--header-text-color": "#1f2937",
190
+ },
191
+ outline: {
192
+ "--button-style-text": "#000000",
193
+ "--button-style-background": "transparent",
194
+ "--button-style-background-hover": "rgba(0, 0, 0, 0.05)",
195
+ "--button-style-border": "2px solid currentColor",
196
+ "--button-style-border-color": "#000000",
197
+ "--button-style-shadow": "none",
198
+ "--button-style-shadow-color": "#000000",
199
+ "--button-style-contrast-color": "#ffffff",
200
+ "--button-style-radius": "24px",
201
+ "--button-style-inner-radius": "min(24px, max(4px, calc(24px - 8px)))",
202
+ "--button-style-skeleton-color": "rgba(0, 0, 0, 0.05)",
203
+ "--link-gap": "14px",
204
+ "--link-inner-padding": "7px",
205
+ "--link-preview-thumbnail-width": "160px",
206
+ "--linkRadius": "24px",
207
+ "--profile-container-desktop-width": "580px",
208
+ "--profileBackground": "#ffffff",
209
+ "--background-contrast-color": "#000000",
210
+ "--bodyText": "#000000",
211
+ "--profileTitleText": "#000000",
212
+ "--profileDescriptionText": "#000000",
213
+ "--defaultAvatarBackground": "#000000",
214
+ "--defaultAvatarText": "#ffffff",
215
+ "--socialLinkFill": "#000000",
216
+ "--linkBackground": "transparent",
217
+ "--linkText": "#000000",
218
+ "--linkHoverBackground": "rgba(0, 0, 0, 0.05)",
219
+ "--linkHoverText": "#000000",
220
+ "--linkShadow": "#000000",
221
+ "--bannerBackground": "#ffffff",
222
+ "--bannerText": "#000000",
223
+ "--desktop-frame-color": "color-mix(in srgb, #ffffff 88%, black 12%)",
224
+ "--profileFontFamilyPrimary": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
225
+ "--profileFontFamilySecondary": 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
226
+ "--header-font-family": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
227
+ "--profileFontWeightNormal": "500",
228
+ "--profileFontWeightBold": "700",
229
+ "--profileDescriptionFontWeight": "500",
230
+ "--linkTextFontWeight": "500",
231
+ "--headerFontWeight": "700",
232
+ "--header-font-weight": "600",
233
+ "--embedLinkTextFontWeight": "500",
234
+ "--signupSubmitTextFontWeight": "700",
235
+ "--bannerFontWeight": "700",
236
+ "--headerFontSize": "normal",
237
+ "--header-bio-font-size": "16px",
238
+ "--embedLinkTextFontSize": "14px",
239
+ "--signupSubmitTextFontSize": "14px",
240
+ "--linkHeaderFontSize": "14px",
241
+ "--bannerFontSize": "14px",
242
+ "--profileDescriptionLineHeight": "1.5",
243
+ "--headerLineHeight": "1.5",
244
+ "--header-text-color": "#000000",
245
+ },
246
+ rounded: {
247
+ "--button-style-text": "#ffffff",
248
+ "--button-style-background": "#059669",
249
+ "--button-style-background-hover": "color-mix(in srgb, #059669 93%, #ffffff 7%)",
250
+ "--button-style-border": "none",
251
+ "--button-style-border-color": "transparent",
252
+ "--button-style-shadow": "none",
253
+ "--button-style-shadow-color": "#000000",
254
+ "--button-style-contrast-color": "#d1fae5",
255
+ "--button-style-radius": "28px",
256
+ "--button-style-inner-radius": "28px",
257
+ "--button-style-skeleton-color": "rgba(5, 150, 105, 0.1)",
258
+ "--link-gap": "14px",
259
+ "--link-inner-padding": "7px",
260
+ "--link-preview-thumbnail-width": "160px",
261
+ "--linkRadius": "28px",
262
+ "--profile-container-desktop-width": "580px",
263
+ "--profileBackground": "#ecfdf5",
264
+ "--background-contrast-color": "#1f2937",
265
+ "--bodyText": "#1f2937",
266
+ "--profileTitleText": "#1f2937",
267
+ "--profileDescriptionText": "#1f2937",
268
+ "--defaultAvatarBackground": "#059669",
269
+ "--defaultAvatarText": "#ffffff",
270
+ "--socialLinkFill": "#1f2937",
271
+ "--linkBackground": "#059669",
272
+ "--linkText": "#ffffff",
273
+ "--linkHoverBackground": "color-mix(in srgb, #059669 93%, #ffffff 7%)",
274
+ "--linkHoverText": "#ffffff",
275
+ "--linkShadow": "#059669",
276
+ "--bannerBackground": "#059669",
277
+ "--bannerText": "#ffffff",
278
+ "--desktop-frame-color": "color-mix(in srgb, #ecfdf5 88%, black 12%)",
279
+ "--profileFontFamilyPrimary": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
280
+ "--profileFontFamilySecondary": 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
281
+ "--header-font-family": 'Link Sans Product, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
282
+ "--profileFontWeightNormal": "500",
283
+ "--profileFontWeightBold": "700",
284
+ "--profileDescriptionFontWeight": "500",
285
+ "--linkTextFontWeight": "500",
286
+ "--headerFontWeight": "700",
287
+ "--header-font-weight": "600",
288
+ "--embedLinkTextFontWeight": "500",
289
+ "--signupSubmitTextFontWeight": "700",
290
+ "--bannerFontWeight": "700",
291
+ "--headerFontSize": "normal",
292
+ "--header-bio-font-size": "16px",
293
+ "--embedLinkTextFontSize": "14px",
294
+ "--signupSubmitTextFontSize": "14px",
295
+ "--linkHeaderFontSize": "14px",
296
+ "--bannerFontSize": "14px",
297
+ "--profileDescriptionLineHeight": "1.5",
298
+ "--headerLineHeight": "1.5",
299
+ "--header-text-color": "#1f2937",
37
300
  },
38
- locale: "en-US",
39
- currency: "USD",
40
- username: "demo-user",
41
- viewport: {
42
- width: 680,
43
- height: 800,
301
+ };
302
+
303
+ // Get theme from URL parameter
304
+ const params = new URLSearchParams(window.location.search);
305
+ const themeParam = params.get('theme') || 'default';
306
+ const themeVariables = THEME_PRESETS[themeParam] || THEME_PRESETS.default;
307
+
308
+ const previewProps = __PREVIEW_PROPS__ || {};
309
+
310
+ // Merge theme from URL with preview props
311
+ const mergedProps = {
312
+ ...previewProps,
313
+ theme: {
314
+ cssVariables: themeVariables,
315
+ // Legacy properties (deprecated) - derived from cssVariables
316
+ textColor: themeVariables["--button-style-text"] || "#000000",
317
+ backgroundColor: themeVariables["--button-style-background"] || "#ffffff",
318
+ borderRadius: themeVariables["--button-style-inner-radius"] || "12px",
319
+ borderColor: themeVariables["--button-style-border-color"] || "#e5e7eb",
320
+ backgroundHover: themeVariables["--button-style-background-hover"] || "#f3f4f6",
321
+ contrastColor: themeVariables["--button-style-contrast-color"] || "#ffffff",
322
+ textHoverColor: themeVariables["--linkHoverText"] || "#111827",
44
323
  },
45
324
  };
46
325
 
326
+ // Apply theme CSS variables on mount
327
+ if (themeVariables && window.__linkapp_applyTheme) {
328
+ window.__linkapp_applyTheme(themeVariables);
329
+ }
330
+
47
331
  const rootElement = document.getElementById("root");
48
332
  if (!rootElement) {
49
333
  throw new Error("Root element not found");
@@ -52,11 +336,11 @@ if (!rootElement) {
52
336
  createRoot(rootElement).render(
53
337
  <StrictMode>
54
338
  {Layout ? (
55
- <Layout theme={previewProps.theme}>
56
- <Classic {...previewProps} />
339
+ <Layout theme={mergedProps.theme}>
340
+ <Classic {...mergedProps} />
57
341
  </Layout>
58
342
  ) : (
59
- <Classic {...previewProps} />
343
+ <Classic {...mergedProps} />
60
344
  )}
61
345
  </StrictMode>,
62
346
  );
@@ -5,6 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Classic - LinkApp</title>
7
7
 
8
+ <!-- iframe-resizer: Required for iframe height auto-adjustment -->
9
+ <script crossorigin src="https://unpkg.com/iframe-resizer@4.3.2/js/iframeResizer.contentWindow.js"></script>
10
+
8
11
  <!-- Linktree theme variables will be injected here -->
9
12
  <style id="linktree-theme"></style>
10
13
 
@@ -21,46 +24,29 @@
21
24
  }
22
25
 
23
26
  /**
24
- * Listen for theme updates from parent window
25
- * Applies CSS variables to the document root
27
+ * Apply theme CSS variables to :root
28
+ * Called once on mount from main.tsx
29
+ * @param {Record<string, string>} variables - CSS variables to apply
26
30
  */
27
- window.addEventListener('message', function(event) {
28
- // Only process messages with the correct structure
29
- if (
30
- event.data &&
31
- typeof event.data === 'object' &&
32
- event.data.type === 'THEME_UPDATE'
33
- ) {
34
- const themeUpdate = event.data
35
-
36
- // Get the style element where theme variables are injected
37
- const themeStyle = document.getElementById('linktree-theme')
31
+ function applyTheme(variables) {
32
+ if (!variables || typeof variables !== 'object') {
33
+ return
34
+ }
38
35
 
39
- if (!themeStyle) {
40
- console.warn('linktree-theme style element not found')
41
- return
42
- }
36
+ // Get the style element where theme variables are injected
37
+ const themeStyle = document.getElementById('linktree-theme')
43
38
 
44
- // Inject CSS variables into :root
45
- themeStyle.textContent = ':root { ' + renderCssVariables(themeUpdate.payload.variables) + ' }'
39
+ if (!themeStyle) {
40
+ console.warn('linktree-theme style element not found')
41
+ return
42
+ }
46
43
 
47
- // Remove any existing theme classes
48
- const classesToRemove = []
49
- document.documentElement.classList.forEach((className) => {
50
- if (className.startsWith('linktree-theme-')) {
51
- classesToRemove.push(className)
52
- }
53
- })
54
- classesToRemove.forEach((className) => {
55
- document.documentElement.classList.remove(className)
56
- })
44
+ // Inject CSS variables into :root
45
+ themeStyle.textContent = ':root { ' + renderCssVariables(variables) + ' }'
46
+ }
57
47
 
58
- // Add theme class for additional styling hooks
59
- if (themeUpdate.payload.name && themeUpdate.payload.name !== 'legacy') {
60
- document.documentElement.classList.add('linktree-theme-' + themeUpdate.payload.name)
61
- }
62
- }
63
- }, false)
48
+ // Export applyTheme to be used by main.tsx
49
+ window.__linkapp_applyTheme = applyTheme
64
50
  </script>
65
51
  </head>
66
52
  <body>