@incodetech/web 2.0.0-alpha.1 → 2.0.0-alpha.3

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 (212) hide show
  1. package/dist/asset-manifest.json +18 -0
  2. package/dist/browser-ponyfill-B6W6hHVY.js +344 -0
  3. package/dist/button-DeMZ_34N.js +266 -0
  4. package/dist/button.css +335 -0
  5. package/dist/email/email.es.js +145 -0
  6. package/dist/email/styles.css +123 -0
  7. package/dist/flow/flow.es.js +9 -0
  8. package/dist/flow/styles.css +204 -0
  9. package/dist/flow-ZK6OBsa3.js +568 -0
  10. package/dist/incodeModule-BF5MX9GT.js +243 -0
  11. package/dist/incodeModule.css +119 -0
  12. package/dist/index.es.js +101 -0
  13. package/dist/otpInput-BUrV4IAF.js +151 -0
  14. package/dist/otpInput.css +167 -0
  15. package/dist/phone/phone.es.js +3442 -0
  16. package/dist/phone/styles.css +305 -0
  17. package/dist/selfie/selfie.es.js +893 -0
  18. package/dist/selfie/styles.css +1163 -0
  19. package/dist/selfieTutorial-C-u5GufD.js +29 -0
  20. package/dist/styles/core.css +1013 -0
  21. package/dist/styles/tokens.css +543 -0
  22. package/dist/successIcon.css +4 -0
  23. package/dist/title-ng7q7YDh.js +2161 -0
  24. package/dist/title.css +38 -0
  25. package/dist/types/core.d.ts +1 -0
  26. package/dist/types/email/email.d.ts +2 -0
  27. package/dist/types/email.d.ts +50 -0
  28. package/dist/types/flow/flow.d.ts +2 -0
  29. package/dist/types/flow.d.ts +46 -0
  30. package/dist/types/index.d.ts +223 -0
  31. package/dist/types/phone/phone.d.ts +2 -0
  32. package/dist/types/phone.d.ts +51 -0
  33. package/dist/types/selfie/selfie.d.ts +2 -0
  34. package/dist/types/selfie.d.ts +24 -0
  35. package/dist/types/styles/core.d.ts +1 -0
  36. package/dist/vendor-preact-CK0WeTOR.js +584 -0
  37. package/package.json +20 -17
  38. package/dev/README.md +0 -163
  39. package/dev/getToken.ts +0 -36
  40. package/dev/headless.html +0 -875
  41. package/dev/index.html +0 -366
  42. package/dev/main-headless.tsx +0 -1332
  43. package/dev/main-orchestrated-flow.tsx +0 -1158
  44. package/dev/main-preact.tsx +0 -323
  45. package/dev/main-simplified.tsx +0 -123
  46. package/dev/main-web-component.tsx +0 -256
  47. package/dev/main.tsx +0 -332
  48. package/dev/manual.html +0 -27
  49. package/dev/orchestrated-flow.html +0 -64
  50. package/dev/simplified.html +0 -64
  51. package/dev/tiktok-logo.svg +0 -7
  52. package/src/defineCustomElement.tsx +0 -30
  53. package/src/email/email.test.tsx +0 -368
  54. package/src/email/email.tsx +0 -255
  55. package/src/email/emailInput.test.tsx +0 -264
  56. package/src/email/emailInput.tsx +0 -85
  57. package/src/email/styles.css +0 -59
  58. package/src/flow/flow.test.tsx +0 -796
  59. package/src/flow/flow.tsx +0 -292
  60. package/src/flow/flowCompleted.css +0 -30
  61. package/src/flow/flowCompleted.test.tsx +0 -331
  62. package/src/flow/flowCompleted.tsx +0 -121
  63. package/src/flow/flowInit.test.ts +0 -264
  64. package/src/flow/flowInit.ts +0 -94
  65. package/src/flow/flowStart.css +0 -58
  66. package/src/flow/flowStart.test.tsx +0 -49
  67. package/src/flow/flowStart.tsx +0 -41
  68. package/src/flow/incode-logo.svg +0 -8
  69. package/src/flow/index.ts +0 -7
  70. package/src/flow/preloadFlow.test.ts +0 -421
  71. package/src/flow/preloadFlow.ts +0 -171
  72. package/src/flow/styles.css +0 -9
  73. package/src/flow/unsupportedModule.css +0 -21
  74. package/src/flow/unsupportedModule.tsx +0 -39
  75. package/src/flow/useFlowInitialization.test.tsx +0 -292
  76. package/src/flow/useFlowInitialization.ts +0 -128
  77. package/src/flow/useModuleLoader.test.tsx +0 -212
  78. package/src/flow/useModuleLoader.ts +0 -92
  79. package/src/hooks/index.ts +0 -1
  80. package/src/hooks/useManager.test.ts +0 -91
  81. package/src/hooks/useManager.ts +0 -40
  82. package/src/i18n/index.ts +0 -3
  83. package/src/i18n/instance.ts +0 -16
  84. package/src/i18n/setup.ts +0 -184
  85. package/src/i18n/useTranslation.ts +0 -42
  86. package/src/index.ts +0 -27
  87. package/src/permissions/assets/android-dots-icon.svg +0 -7
  88. package/src/permissions/assets/android-settings-icon.svg +0 -16
  89. package/src/permissions/assets/android-toggle-icon.svg +0 -20
  90. package/src/permissions/assets/bank-card-icon.svg +0 -14
  91. package/src/permissions/assets/camera-icon.svg +0 -12
  92. package/src/permissions/assets/camera-ios.svg +0 -53
  93. package/src/permissions/assets/check-icon.svg +0 -8
  94. package/src/permissions/assets/chrome-icon.svg +0 -43
  95. package/src/permissions/assets/password-icon.svg +0 -11
  96. package/src/permissions/assets/permissions-img.svg +0 -51
  97. package/src/permissions/assets/safari-icon.svg +0 -37
  98. package/src/permissions/assets/settings-icon.svg +0 -33
  99. package/src/permissions/assets/toggle-icon.svg +0 -19
  100. package/src/permissions/assets/warning-icon.svg +0 -6
  101. package/src/permissions/boldWithArrow.css +0 -9
  102. package/src/permissions/boldWithArrow.tsx +0 -41
  103. package/src/permissions/denied.css +0 -37
  104. package/src/permissions/denied.tsx +0 -29
  105. package/src/permissions/deniedAndroid.tsx +0 -56
  106. package/src/permissions/deniedDesktop.css +0 -9
  107. package/src/permissions/deniedDesktop.tsx +0 -64
  108. package/src/permissions/deniedIOS.tsx +0 -73
  109. package/src/permissions/deniedInstructions.tsx +0 -19
  110. package/src/permissions/iconWrapper.css +0 -9
  111. package/src/permissions/iconWrapper.tsx +0 -15
  112. package/src/permissions/learnMore.css +0 -37
  113. package/src/permissions/learnMore.tsx +0 -85
  114. package/src/permissions/numberedStep.css +0 -13
  115. package/src/permissions/numberedStep.tsx +0 -14
  116. package/src/permissions/permissions.css +0 -13
  117. package/src/permissions/permissions.tsx +0 -68
  118. package/src/phone/phone.tsx +0 -246
  119. package/src/phone/phoneInput.test.tsx +0 -275
  120. package/src/phone/phoneInput.tsx +0 -249
  121. package/src/phone/styles.css +0 -158
  122. package/src/selfie/cameraButton.css +0 -13
  123. package/src/selfie/cameraButton.tsx +0 -35
  124. package/src/selfie/capture.css +0 -57
  125. package/src/selfie/capture.tsx +0 -232
  126. package/src/selfie/errorModal.tsx +0 -218
  127. package/src/selfie/errorModalContent.css +0 -33
  128. package/src/selfie/errorModalContent.tsx +0 -44
  129. package/src/selfie/faceOutline.css +0 -5
  130. package/src/selfie/faceOutline.tsx +0 -22
  131. package/src/selfie/loadingBorder.css +0 -12
  132. package/src/selfie/loadingBorder.tsx +0 -77
  133. package/src/selfie/manualCaptureButton.css +0 -13
  134. package/src/selfie/manualCaptureButton.tsx +0 -35
  135. package/src/selfie/noMoreAttemptsModal.tsx +0 -44
  136. package/src/selfie/notification.css +0 -9
  137. package/src/selfie/notification.tsx +0 -36
  138. package/src/selfie/retryErrorModal.tsx +0 -56
  139. package/src/selfie/selfie.test.tsx +0 -458
  140. package/src/selfie/selfie.tsx +0 -83
  141. package/src/selfie/selfieTutorial.json +0 -2626
  142. package/src/selfie/styles.css +0 -1
  143. package/src/selfie/tutorial.test.tsx +0 -200
  144. package/src/selfie/tutorial.tsx +0 -43
  145. package/src/setup.ts +0 -33
  146. package/src/shared/baseTutorial/baseTutorial.css +0 -21
  147. package/src/shared/baseTutorial/baseTutorial.test.tsx +0 -184
  148. package/src/shared/baseTutorial/baseTutorial.tsx +0 -55
  149. package/src/shared/baseTutorial/replaceBaseTutorial.test.ts +0 -267
  150. package/src/shared/baseTutorial/replaceBaseTutorial.ts +0 -68
  151. package/src/shared/button/button.css +0 -55
  152. package/src/shared/button/button.test.tsx +0 -101
  153. package/src/shared/button/button.tsx +0 -47
  154. package/src/shared/componentRoot/incodeComponent.tsx +0 -12
  155. package/src/shared/countries/countries.test.ts +0 -75
  156. package/src/shared/countries/countries.ts +0 -139
  157. package/src/shared/countries/index.ts +0 -6
  158. package/src/shared/icons/chevronDown.tsx +0 -22
  159. package/src/shared/icons/index.ts +0 -2
  160. package/src/shared/icons/successIcon.css +0 -5
  161. package/src/shared/icons/successIcon.test.tsx +0 -40
  162. package/src/shared/icons/successIcon.tsx +0 -26
  163. package/src/shared/loader/loadingIcon.css +0 -28
  164. package/src/shared/loader/loadingIcon.tsx +0 -67
  165. package/src/shared/lottie/lottie.tsx +0 -108
  166. package/src/shared/otpInput/otpInput.css +0 -85
  167. package/src/shared/otpInput/otpInput.test.tsx +0 -356
  168. package/src/shared/otpInput/otpInput.tsx +0 -241
  169. package/src/shared/page/incode-logo.svg +0 -3
  170. package/src/shared/page/page.css +0 -47
  171. package/src/shared/page/page.test.tsx +0 -97
  172. package/src/shared/page/page.tsx +0 -91
  173. package/src/shared/page/pageUiConfig.test.ts +0 -112
  174. package/src/shared/page/pageUiConfig.ts +0 -64
  175. package/src/shared/page/verifiedByIncode.css +0 -5
  176. package/src/shared/page/verifiedByIncode.tsx +0 -75
  177. package/src/shared/spacer/spacer.css +0 -149
  178. package/src/shared/spacer/spacer.test.tsx +0 -143
  179. package/src/shared/spacer/spacer.tsx +0 -88
  180. package/src/shared/spinner/index.ts +0 -2
  181. package/src/shared/spinner/spinner.css +0 -28
  182. package/src/shared/spinner/spinner.test.tsx +0 -82
  183. package/src/shared/spinner/spinner.tsx +0 -65
  184. package/src/shared/title/title.css +0 -7
  185. package/src/shared/title/title.tsx +0 -12
  186. package/src/shared/uiConfig/uiConfig.ts +0 -36
  187. package/src/shared/webComponent/incodeModule.ts +0 -29
  188. package/src/shared/webComponent/registerIncodeElement.ts +0 -15
  189. package/src/styles/__mocks__/fetchTheme.ts +0 -19
  190. package/src/styles/applyTheme.ts +0 -37
  191. package/src/styles/cn.test.tsx +0 -57
  192. package/src/styles/cn.tsx +0 -21
  193. package/src/styles/core.css +0 -12
  194. package/src/styles/fetchTheme.test.ts +0 -390
  195. package/src/styles/fetchTheme.ts +0 -88
  196. package/src/styles/generatePalette.ts +0 -111
  197. package/src/styles/reset.css +0 -65
  198. package/src/styles/resolveCssVariableToHex.ts +0 -28
  199. package/src/styles/tailwind.css +0 -291
  200. package/src/styles/themeTypes.ts +0 -18
  201. package/src/styles/tokens/colors.css +0 -190
  202. package/src/styles/tokens/components.css +0 -174
  203. package/src/styles/tokens/index.css +0 -4
  204. package/src/styles/tokens/primitives.css +0 -129
  205. package/src/styles/tokens/semantic.css +0 -51
  206. package/src/svg.d.ts +0 -4
  207. package/src/types/assets.d.ts +0 -1
  208. package/src/types/custom-elements.d.ts +0 -104
  209. package/tsconfig.json +0 -22
  210. package/vite.config.ts +0 -260
  211. package/vitest.config.ts +0 -40
  212. package/vitest.setup.ts +0 -16
@@ -1,390 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { fetchAndApplyTheme, fetchAssets, fetchTheme } from './fetchTheme';
3
- import type { AssetsResponse, ThemeConfig } from './themeTypes';
4
-
5
- const mockApiGet = vi.fn();
6
- const mockFetch = vi.fn();
7
-
8
- vi.mock('@incodetech/core', () => ({
9
- api: {
10
- get: (...args: unknown[]) => mockApiGet(...args),
11
- },
12
- }));
13
-
14
- global.fetch = mockFetch as typeof fetch;
15
-
16
- class MockFileReaderClass {
17
- result = '';
18
- onloadend: (() => void) | null = null;
19
- onerror: ((error: Event) => void) | null = null;
20
- readAsDataURL = vi.fn((_blob: Blob) => {
21
- const mockResult = (global as { __mockFileReaderResult?: string })
22
- .__mockFileReaderResult;
23
- if (mockResult) {
24
- this.result = mockResult;
25
- }
26
- setTimeout(() => {
27
- if (this.onloadend) {
28
- this.onloadend();
29
- }
30
- }, 0);
31
- });
32
-
33
- constructor() {
34
- const mockResult = (global as { __mockFileReaderResult?: string })
35
- .__mockFileReaderResult;
36
- if (mockResult) {
37
- this.result = mockResult;
38
- }
39
- }
40
- }
41
-
42
- global.FileReader = MockFileReaderClass as unknown as typeof FileReader;
43
-
44
- describe('fetchTheme', () => {
45
- beforeEach(() => {
46
- vi.clearAllMocks();
47
- (global as { __mockFileReaderResult?: string }).__mockFileReaderResult =
48
- undefined;
49
- const styleElement = document.getElementById('incode-theme');
50
- if (styleElement) {
51
- styleElement.remove();
52
- }
53
- });
54
-
55
- describe('fetchAssets', () => {
56
- it('should fetch assets from API', async () => {
57
- const mockAssets: AssetsResponse = {
58
- theme: '/api/theme.json',
59
- 'logo.png': 'https://example.com/logo.png',
60
- };
61
-
62
- mockApiGet.mockResolvedValueOnce({
63
- data: mockAssets,
64
- });
65
-
66
- const result = await fetchAssets();
67
-
68
- expect(mockApiGet).toHaveBeenCalledWith('/omni/asset/fetch-all');
69
- expect(result).toEqual(mockAssets);
70
- });
71
-
72
- it('should handle API errors', async () => {
73
- mockApiGet.mockRejectedValueOnce(new Error('Network error'));
74
-
75
- await expect(fetchAssets()).rejects.toThrow('Network error');
76
- });
77
- });
78
-
79
- describe('fetchTheme', () => {
80
- it('should fetch theme with relative URL using API', async () => {
81
- const mockAssets: AssetsResponse = {
82
- theme: '/api/theme.json',
83
- };
84
-
85
- const mockTheme: ThemeConfig = {
86
- main: '#ff0000',
87
- buttonColor: '#ffffff',
88
- };
89
-
90
- mockApiGet
91
- .mockResolvedValueOnce({
92
- data: mockAssets,
93
- })
94
- .mockResolvedValueOnce({
95
- data: mockTheme,
96
- });
97
-
98
- const result = await fetchTheme();
99
-
100
- expect(mockApiGet).toHaveBeenCalledTimes(2);
101
- expect(mockApiGet).toHaveBeenNthCalledWith(1, '/omni/asset/fetch-all');
102
- expect(mockApiGet).toHaveBeenNthCalledWith(2, '/api/theme.json');
103
- expect(result.main).toBe('#ff0000');
104
- expect(result.buttonColor).toBe('#ffffff');
105
- });
106
-
107
- it('should fetch theme with absolute URL using fetch', async () => {
108
- const mockAssets: AssetsResponse = {
109
- theme: 'https://example.com/theme.json',
110
- };
111
-
112
- const mockTheme: ThemeConfig = {
113
- main: '#00ff00',
114
- buttonColor: '#000000',
115
- };
116
-
117
- mockApiGet.mockResolvedValueOnce({
118
- data: mockAssets,
119
- });
120
-
121
- mockFetch.mockResolvedValueOnce({
122
- ok: true,
123
- json: async () => mockTheme,
124
- } as Response);
125
-
126
- const result = await fetchTheme();
127
-
128
- expect(mockApiGet).toHaveBeenCalledTimes(1);
129
- expect(mockFetch).toHaveBeenCalledWith('https://example.com/theme.json');
130
- expect(result.main).toBe('#00ff00');
131
- expect(result.buttonColor).toBe('#000000');
132
- });
133
-
134
- it('should throw error when theme URL is not found in assets', async () => {
135
- const mockAssets: AssetsResponse = {} as AssetsResponse;
136
-
137
- mockApiGet.mockResolvedValueOnce({
138
- data: mockAssets,
139
- });
140
-
141
- await expect(fetchTheme()).rejects.toThrow(
142
- 'Theme URL not found in assets response',
143
- );
144
- });
145
-
146
- it('should throw error when absolute URL fetch fails', async () => {
147
- const mockAssets: AssetsResponse = {
148
- theme: 'https://example.com/theme.json',
149
- };
150
-
151
- mockApiGet.mockResolvedValueOnce({
152
- data: mockAssets,
153
- });
154
-
155
- mockFetch.mockResolvedValueOnce({
156
- ok: false,
157
- statusText: 'Not Found',
158
- } as Response);
159
-
160
- await expect(fetchTheme()).rejects.toThrow(
161
- 'Failed to fetch theme: Not Found',
162
- );
163
- });
164
-
165
- it('should convert logo URL to data URL', async () => {
166
- const mockAssets: AssetsResponse = {
167
- theme: '/api/theme.json',
168
- 'logo.png': 'https://example.com/logo.png',
169
- };
170
-
171
- const mockTheme: ThemeConfig = {
172
- main: '#ff0000',
173
- };
174
-
175
- const mockBlob = new Blob(['logo-data'], { type: 'image/png' });
176
-
177
- mockApiGet
178
- .mockResolvedValueOnce({
179
- data: mockAssets,
180
- })
181
- .mockResolvedValueOnce({
182
- data: mockTheme,
183
- });
184
-
185
- mockFetch.mockResolvedValueOnce({
186
- blob: async () => mockBlob,
187
- } as Response);
188
-
189
- (global as { __mockFileReaderResult?: string }).__mockFileReaderResult =
190
- 'data:image/png;base64,logo-data';
191
-
192
- const result = await fetchTheme();
193
-
194
- expect(mockFetch).toHaveBeenCalledWith('https://example.com/logo.png');
195
- expect(result.logo).toBe('data:image/png;base64,logo-data');
196
- });
197
-
198
- it('should return data URL as-is if logo is already a data URL', async () => {
199
- const mockAssets: AssetsResponse = {
200
- theme: '/api/theme.json',
201
- };
202
-
203
- const mockTheme: ThemeConfig = {
204
- main: '#ff0000',
205
- logo: 'data:image/png;base64,existing-data',
206
- };
207
-
208
- mockApiGet
209
- .mockResolvedValueOnce({
210
- data: mockAssets,
211
- })
212
- .mockResolvedValueOnce({
213
- data: mockTheme,
214
- });
215
-
216
- const result = await fetchTheme();
217
-
218
- expect(result.logo).toBe('data:image/png;base64,existing-data');
219
- expect(mockFetch).not.toHaveBeenCalled();
220
- });
221
-
222
- it('should prefer logo from assets over theme', async () => {
223
- const mockAssets: AssetsResponse = {
224
- theme: '/api/theme.json',
225
- 'logo.png': 'https://example.com/assets-logo.png',
226
- };
227
-
228
- const mockTheme: ThemeConfig = {
229
- main: '#ff0000',
230
- logo: 'https://example.com/theme-logo.png',
231
- };
232
-
233
- mockApiGet
234
- .mockResolvedValueOnce({
235
- data: mockAssets,
236
- })
237
- .mockResolvedValueOnce({
238
- data: mockTheme,
239
- });
240
-
241
- mockFetch.mockResolvedValueOnce({
242
- blob: async () => new Blob(['logo'], { type: 'image/png' }),
243
- } as Response);
244
-
245
- (global as { __mockFileReaderResult?: string }).__mockFileReaderResult =
246
- 'data:image/png;base64,assets-logo';
247
-
248
- await fetchTheme();
249
-
250
- expect(mockFetch).toHaveBeenCalledWith(
251
- 'https://example.com/assets-logo.png',
252
- );
253
- });
254
-
255
- it('should check multiple logo formats in order', async () => {
256
- const uniqueUrl = `https://example.com/logo-formats-${Date.now()}.png`;
257
- const mockAssets: AssetsResponse = {
258
- theme: '/api/theme.json',
259
- 'logo.svg': `https://example.com/logo-formats-${Date.now()}.svg`,
260
- 'logo.png': uniqueUrl,
261
- };
262
-
263
- const mockTheme: ThemeConfig = {
264
- main: '#ff0000',
265
- };
266
-
267
- mockApiGet
268
- .mockResolvedValueOnce({
269
- data: mockAssets,
270
- })
271
- .mockResolvedValueOnce({
272
- data: mockTheme,
273
- });
274
-
275
- mockFetch.mockResolvedValueOnce({
276
- blob: async () => new Blob(['logo'], { type: 'image/png' }),
277
- } as Response);
278
-
279
- (global as { __mockFileReaderResult?: string }).__mockFileReaderResult =
280
- 'data:image/png;base64,logo-formats';
281
-
282
- const result = await fetchTheme();
283
-
284
- expect(mockFetch).toHaveBeenCalledWith(uniqueUrl);
285
- expect(result.logo).toBe('data:image/png;base64,logo-formats');
286
- });
287
-
288
- it('should cache converted logo URLs', async () => {
289
- const uniqueUrl = `https://example.com/cached-logo-${Date.now()}.png`;
290
- const mockAssets: AssetsResponse = {
291
- theme: '/api/theme.json',
292
- 'logo.png': uniqueUrl,
293
- };
294
-
295
- const mockTheme: ThemeConfig = {
296
- main: '#ff0000',
297
- };
298
-
299
- mockApiGet
300
- .mockResolvedValueOnce({
301
- data: mockAssets,
302
- })
303
- .mockResolvedValueOnce({
304
- data: mockTheme,
305
- })
306
- .mockResolvedValueOnce({
307
- data: mockAssets,
308
- })
309
- .mockResolvedValueOnce({
310
- data: mockTheme,
311
- });
312
-
313
- mockFetch.mockResolvedValue({
314
- blob: async () => new Blob(['logo'], { type: 'image/png' }),
315
- } as Response);
316
-
317
- (global as { __mockFileReaderResult?: string }).__mockFileReaderResult =
318
- 'data:image/png;base64,cached-logo';
319
-
320
- const result1 = await fetchTheme();
321
- const result2 = await fetchTheme();
322
-
323
- expect(mockFetch).toHaveBeenCalledTimes(1);
324
- expect(result1.logo).toBe('data:image/png;base64,cached-logo');
325
- expect(result2.logo).toBe('data:image/png;base64,cached-logo');
326
- });
327
- });
328
-
329
- describe('fetchAndApplyTheme', () => {
330
- it('should fetch theme and apply it', async () => {
331
- const mockAssets: AssetsResponse = {
332
- theme: '/api/theme.json',
333
- };
334
-
335
- const mockTheme: ThemeConfig = {
336
- main: '#ff0000',
337
- buttonColor: '#ffffff',
338
- };
339
-
340
- mockApiGet
341
- .mockResolvedValueOnce({
342
- data: mockAssets,
343
- })
344
- .mockResolvedValueOnce({
345
- data: mockTheme,
346
- });
347
-
348
- const result = await fetchAndApplyTheme();
349
-
350
- expect(result).toEqual({
351
- ...mockTheme,
352
- logo: undefined,
353
- });
354
-
355
- const styleElement = document.getElementById(
356
- 'incode-theme',
357
- ) as HTMLStyleElement;
358
- expect(styleElement).toBeTruthy();
359
- expect(styleElement.textContent).toContain('--primitive-color-brand-500');
360
- });
361
-
362
- it('should not apply theme if main color is missing', async () => {
363
- const styleElement = document.getElementById('incode-theme');
364
- if (styleElement) {
365
- styleElement.remove();
366
- }
367
-
368
- const mockAssets: AssetsResponse = {
369
- theme: '/api/theme.json',
370
- };
371
-
372
- const mockTheme = {
373
- buttonColor: '#ffffff',
374
- } as ThemeConfig;
375
-
376
- mockApiGet
377
- .mockResolvedValueOnce({
378
- data: mockAssets,
379
- })
380
- .mockResolvedValueOnce({
381
- data: mockTheme,
382
- });
383
-
384
- await fetchAndApplyTheme();
385
-
386
- const newStyleElement = document.getElementById('incode-theme');
387
- expect(newStyleElement).toBeFalsy();
388
- });
389
- });
390
- });
@@ -1,88 +0,0 @@
1
- import { api } from '@incodetech/core';
2
- import { applyTheme } from './applyTheme';
3
- import type { AssetsResponse, ThemeConfig } from './themeTypes';
4
-
5
- export async function fetchAssets(): Promise<AssetsResponse> {
6
- const response = await api.get<AssetsResponse>('/omni/asset/fetch-all');
7
- return response.data;
8
- }
9
-
10
- const dataUrlCache = new Map<string, string>();
11
-
12
- async function urlToDataUrl(url: string): Promise<string> {
13
- if (url.startsWith('data:')) {
14
- return url;
15
- }
16
-
17
- const cached = dataUrlCache.get(url);
18
- if (cached) {
19
- return cached;
20
- }
21
-
22
- const response = await fetch(url);
23
- const blob = await response.blob();
24
- const dataUrl = await new Promise<string>((resolve, reject) => {
25
- const reader = new FileReader();
26
- reader.onloadend = () => resolve(reader.result as string);
27
- reader.onerror = reject;
28
- reader.readAsDataURL(blob);
29
- });
30
-
31
- dataUrlCache.set(url, dataUrl);
32
- return dataUrl;
33
- }
34
-
35
- export async function fetchTheme(): Promise<ThemeConfig> {
36
- const assets = await fetchAssets();
37
-
38
- if (!assets.theme) {
39
- throw new Error('Theme URL not found in assets response');
40
- }
41
-
42
- const themeUrl = assets.theme;
43
- const isAbsoluteUrl =
44
- themeUrl.startsWith('http://') || themeUrl.startsWith('https://');
45
-
46
- let theme: ThemeConfig;
47
-
48
- if (isAbsoluteUrl) {
49
- const themeResponse = await fetch(themeUrl);
50
-
51
- if (!themeResponse.ok) {
52
- throw new Error(`Failed to fetch theme: ${themeResponse.statusText}`);
53
- }
54
-
55
- theme = (await themeResponse.json()) as ThemeConfig;
56
- } else {
57
- const themeResponse = await api.get<ThemeConfig>(themeUrl);
58
- theme = themeResponse.data;
59
- }
60
-
61
- const logoUrl =
62
- assets['logo.png'] ||
63
- assets['logo.svg'] ||
64
- assets['logo.jpg'] ||
65
- assets['logo.jpeg'] ||
66
- assets['logo.webp'] ||
67
- theme.logo;
68
-
69
- let cachedLogoUrl = logoUrl;
70
- if (logoUrl) {
71
- cachedLogoUrl = await urlToDataUrl(logoUrl);
72
- }
73
-
74
- return {
75
- ...theme,
76
- logo: cachedLogoUrl,
77
- };
78
- }
79
-
80
- export async function fetchAndApplyTheme(): Promise<ThemeConfig> {
81
- const theme = await fetchTheme();
82
-
83
- if (theme.main) {
84
- applyTheme(theme.main, theme.buttonColor);
85
- }
86
-
87
- return theme;
88
- }
@@ -1,111 +0,0 @@
1
- type HslColor = {
2
- h: number;
3
- s: number;
4
- l: number;
5
- };
6
-
7
- function hexToHsl(hex: string): HslColor | null {
8
- let normalizedHex = hex.replace('#', '');
9
- if (normalizedHex.length === 3) {
10
- normalizedHex = normalizedHex
11
- .split('')
12
- .map((char) => char + char)
13
- .join('');
14
- }
15
-
16
- const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(normalizedHex);
17
- if (!result) return null;
18
-
19
- const r = Number.parseInt(result[1], 16) / 255;
20
- const g = Number.parseInt(result[2], 16) / 255;
21
- const b = Number.parseInt(result[3], 16) / 255;
22
-
23
- const max = Math.max(r, g, b);
24
- const min = Math.min(r, g, b);
25
- let h = 0;
26
- let s = 0;
27
- const l = (max + min) / 2;
28
-
29
- if (max !== min) {
30
- const d = max - min;
31
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
32
-
33
- switch (max) {
34
- case r:
35
- h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
36
- break;
37
- case g:
38
- h = ((b - r) / d + 2) / 6;
39
- break;
40
- case b:
41
- h = ((r - g) / d + 4) / 6;
42
- break;
43
- }
44
- }
45
-
46
- return { h: h * 360, s: s * 100, l: l * 100 };
47
- }
48
-
49
- function hslToHex(h: number, s: number, l: number): string {
50
- const hNorm = h / 360;
51
- const sNorm = s / 100;
52
- const lNorm = l / 100;
53
-
54
- let r: number;
55
- let g: number;
56
- let b: number;
57
-
58
- if (sNorm === 0) {
59
- r = g = b = lNorm;
60
- } else {
61
- const hue2rgb = (p: number, q: number, t: number) => {
62
- if (t < 0) t += 1;
63
- if (t > 1) t -= 1;
64
- if (t < 1 / 6) return p + (q - p) * 6 * t;
65
- if (t < 1 / 2) return q;
66
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
67
- return p;
68
- };
69
-
70
- const q = lNorm < 0.5 ? lNorm * (1 + sNorm) : lNorm + sNorm - lNorm * sNorm;
71
- const p = 2 * lNorm - q;
72
-
73
- r = hue2rgb(p, q, hNorm + 1 / 3);
74
- g = hue2rgb(p, q, hNorm);
75
- b = hue2rgb(p, q, hNorm - 1 / 3);
76
- }
77
-
78
- const toHex = (n: number) => {
79
- const hex = Math.round(n * 255).toString(16);
80
- return hex.length === 1 ? `0${hex}` : hex;
81
- };
82
-
83
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
84
- }
85
-
86
- export type BrandPalette = {
87
- '50': string;
88
- '200': string;
89
- '300': string;
90
- '400': string;
91
- '500': string;
92
- '600': string;
93
- '900': string;
94
- };
95
-
96
- export function generateBrandPalette(mainColor: string): BrandPalette {
97
- const hsl = hexToHsl(mainColor);
98
- if (!hsl) {
99
- throw new Error(`Invalid color format: ${mainColor}`);
100
- }
101
-
102
- return {
103
- '50': hslToHex(hsl.h, hsl.s, 95),
104
- '200': hslToHex(hsl.h, hsl.s, 80),
105
- '300': hslToHex(hsl.h, hsl.s, 65),
106
- '400': hslToHex(hsl.h, hsl.s, Math.min(100, hsl.l + 10)),
107
- '500': mainColor,
108
- '600': hslToHex(hsl.h, hsl.s, Math.max(0, hsl.l - 10)),
109
- '900': hslToHex(hsl.h, hsl.s, 20),
110
- };
111
- }
@@ -1,65 +0,0 @@
1
- .IncodeComponent,
2
- .IncodeComponent * {
3
- box-sizing: border-box;
4
- }
5
-
6
- .IncodeComponent {
7
- font-family: var(--primitive-typography-family-dm-sans), sans-serif;
8
- -webkit-font-smoothing: antialiased;
9
- -moz-osx-font-smoothing: grayscale;
10
- text-rendering: optimizeLegibility;
11
- color: var(--text-body-primary);
12
- margin: 0;
13
- padding: 0;
14
- height: 100%;
15
- width: 100%;
16
- }
17
-
18
- .IncodeComponent {
19
- *,
20
- ::after,
21
- ::before,
22
- ::backdrop,
23
- ::file-selector-button {
24
- margin: 0;
25
- padding: 0;
26
- box-sizing: border-box;
27
- border: 0 solid;
28
- }
29
-
30
- h1,
31
- h2,
32
- h3,
33
- h4,
34
- h5,
35
- h6 {
36
- font-size: inherit;
37
- font-weight: inherit;
38
- margin: 0;
39
- padding: 0;
40
- }
41
-
42
- ol,
43
- ul,
44
- menu {
45
- list-style: none;
46
- }
47
-
48
- img,
49
- svg,
50
- video,
51
- canvas,
52
- audio,
53
- iframe,
54
- embed,
55
- object {
56
- display: block;
57
- vertical-align: middle;
58
- }
59
-
60
- img,
61
- video {
62
- max-width: 100%;
63
- height: auto;
64
- }
65
- }
@@ -1,28 +0,0 @@
1
- export const resolveCssVariableToHex = (cssVar: string): string | null => {
2
- if (typeof document === 'undefined') return null;
3
-
4
- const tempEl = document.createElement('div');
5
- tempEl.style.color = cssVar;
6
- tempEl.style.position = 'absolute';
7
- tempEl.style.visibility = 'hidden';
8
- document.body.appendChild(tempEl);
9
-
10
- const computedColor = getComputedStyle(tempEl).color;
11
- document.body.removeChild(tempEl);
12
-
13
- if (!computedColor || computedColor === 'transparent') return null;
14
-
15
- const rgbMatch = computedColor.match(/\d+/g);
16
- if (rgbMatch && rgbMatch.length >= 3) {
17
- const r = Number.parseInt(rgbMatch[0], 10);
18
- const g = Number.parseInt(rgbMatch[1], 10);
19
- const b = Number.parseInt(rgbMatch[2], 10);
20
- const toHex = (n: number) => {
21
- const hex = n.toString(16);
22
- return hex.length === 1 ? `0${hex}` : hex;
23
- };
24
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
25
- }
26
-
27
- return null;
28
- };