@worldcoin/idkit 2.2.2 → 2.4.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.
@@ -33,25 +33,165 @@ __export(internal_exports, {
33
33
  ConfigSource: () => ConfigSource,
34
34
  QRCode: () => QRCode_default,
35
35
  __: () => __,
36
+ getCurrentLanguage: () => getCurrentLanguage,
37
+ getLocalizationConfig: () => getLocalizationConfig,
38
+ getSupportedLanguages: () => getSupportedLanguages,
39
+ setLocalizationConfig: () => setLocalizationConfig,
36
40
  useIDKitStore: () => idkit_default
37
41
  });
38
42
  module.exports = __toCommonJS(internal_exports);
39
43
 
44
+ // src/lang/translations/en.ts
45
+ var en = {
46
+ "All set!": "All set!",
47
+ "Your World ID is now connected": "Your World ID is now connected",
48
+ "Transmitting verification to host app. Please wait...": "Transmitting verification to host app. Please wait...",
49
+ "Something went wrong": "Something went wrong",
50
+ "Verification Declined": "Verification Declined",
51
+ "Request cancelled": "Request cancelled",
52
+ "Connection to your wallet failed. Please try again.": "Connection to your wallet failed. Please try again.",
53
+ "You've cancelled the request in World App.": "You've cancelled the request in World App.",
54
+ "You have already verified the maximum number of times for this action.": "You have already verified the maximum number of times for this action.",
55
+ "It seems you do not have the verification level required by this app.": "It seems you do not have the verification level required by this app.",
56
+ "Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Invalid network. If you are the app owner, visit docs.world.org/test for details.",
57
+ "Your identity is still being registered. Please wait a few minutes and try again.": "Your identity is still being registered. Please wait a few minutes and try again.",
58
+ "We couldn't complete your request. Please try again.": "We couldn't complete your request. Please try again.",
59
+ "Try Again": "Try Again",
60
+ "Open World App": "Open World App",
61
+ "Hide QR Code": "Hide QR Code",
62
+ "Display QR Code": "Display QR Code",
63
+ "QR Code copied": "QR Code copied",
64
+ "Connect your World ID": "Connect your World ID",
65
+ "Use phone camera to scan the QR code": "Use phone camera to scan the QR code",
66
+ "Connecting...": "Connecting...",
67
+ "Please continue in app": "Please continue in app",
68
+ "You will be redirected to the app, please return to this page once you're done": "You will be redirected to the app, please return to this page once you're done",
69
+ "Action cannot be an empty string.": "Action cannot be an empty string.",
70
+ "Invalid IDKitStage :stage.": "Invalid IDKitStage :stage.",
71
+ "Terms & Privacy": "Terms & Privacy"
72
+ };
73
+
74
+ // src/lang/translations/es.ts
75
+ var es = {
76
+ "All set!": "\xA1Todo listo!",
77
+ "Your World ID is now connected": "Tu World ID ahora est\xE1 conectado",
78
+ "Transmitting verification to host app. Please wait...": "Transmitiendo verificaci\xF3n a la aplicaci\xF3n host. Por favor espera...",
79
+ "Something went wrong": "Algo sali\xF3 mal",
80
+ "Verification Declined": "Verificaci\xF3n rechazada",
81
+ "Request cancelled": "Solicitud cancelada",
82
+ "Connection to your wallet failed. Please try again.": "La conexi\xF3n a tu billetera fall\xF3. Por favor intenta de nuevo.",
83
+ "You've cancelled the request in World App.": "Has cancelado la solicitud en World App.",
84
+ "You have already verified the maximum number of times for this action.": "Ya has verificado el n\xFAmero m\xE1ximo de veces para esta acci\xF3n.",
85
+ "It seems you do not have the verification level required by this app.": "Parece que no tienes el nivel de verificaci\xF3n requerido por esta aplicaci\xF3n.",
86
+ "Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Red inv\xE1lida. Si eres el propietario de la aplicaci\xF3n, visita docs.world.org/test para m\xE1s detalles.",
87
+ "Your identity is still being registered. Please wait a few minutes and try again.": "Tu identidad a\xFAn se est\xE1 registrando. Por favor espera unos minutos e intenta de nuevo.",
88
+ "We couldn't complete your request. Please try again.": "No pudimos completar tu solicitud. Por favor intenta de nuevo.",
89
+ "Try Again": "Intentar de nuevo",
90
+ "Open World App": "Abrir World App",
91
+ "Hide QR Code": "Ocultar c\xF3digo QR",
92
+ "Display QR Code": "Mostrar c\xF3digo QR",
93
+ "QR Code copied": "C\xF3digo QR copiado",
94
+ "Connect your World ID": "Conecta tu World ID",
95
+ "Use phone camera to scan the QR code": "Usa la c\xE1mara del tel\xE9fono para escanear el c\xF3digo QR",
96
+ "Connecting...": "Conectando...",
97
+ "Please continue in app": "Por favor contin\xFAa en la aplicaci\xF3n",
98
+ "You will be redirected to the app, please return to this page once you're done": "Ser\xE1s redirigido a la aplicaci\xF3n, por favor regresa a esta p\xE1gina una vez que hayas terminado",
99
+ "Action cannot be an empty string.": "La acci\xF3n no puede ser una cadena vac\xEDa.",
100
+ "Invalid IDKitStage :stage.": "IDKitStage inv\xE1lido :stage.",
101
+ "Terms & Privacy": "T\xE9rminos y privacidad"
102
+ };
103
+
104
+ // src/lang/translations/th.ts
105
+ var th = {
106
+ "All set!": "\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22!",
107
+ "Your World ID is now connected": "World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E41\u0E25\u0E49\u0E27",
108
+ "Transmitting verification to host app. Please wait...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B\u0E42\u0E2E\u0E2A\u0E15\u0E4C \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48...",
109
+ "Something went wrong": "\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14",
110
+ "Verification Declined": "\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E16\u0E39\u0E01\u0E1B\u0E0F\u0E34\u0E40\u0E2A\u0E18",
111
+ "Request cancelled": "\u0E04\u0E33\u0E02\u0E2D\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
112
+ "Connection to your wallet failed. Please try again.": "\u0E01\u0E32\u0E23\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E01\u0E23\u0E30\u0E40\u0E1B\u0E4B\u0E32\u0E40\u0E07\u0E34\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E25\u0E49\u0E21\u0E40\u0E2B\u0E25\u0E27 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
113
+ "You've cancelled the request in World App.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E19 World App",
114
+ "You have already verified the maximum number of times for this action.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E04\u0E23\u0E1A\u0E08\u0E33\u0E19\u0E27\u0E19\u0E04\u0E23\u0E31\u0E49\u0E07\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E19\u0E35\u0E49\u0E41\u0E25\u0E49\u0E27",
115
+ "It seems you do not have the verification level required by this app.": "\u0E14\u0E39\u0E40\u0E2B\u0E21\u0E37\u0E2D\u0E19\u0E27\u0E48\u0E32\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E23\u0E30\u0E14\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E17\u0E35\u0E48\u0E41\u0E2D\u0E1B\u0E19\u0E35\u0E49\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23",
116
+ "Invalid network. If you are the app owner, visit docs.world.org/test for details.": "\u0E40\u0E04\u0E23\u0E37\u0E2D\u0E02\u0E48\u0E32\u0E22\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 \u0E2B\u0E32\u0E01\u0E04\u0E38\u0E13\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E08\u0E49\u0E32\u0E02\u0E2D\u0E07\u0E41\u0E2D\u0E1B \u0E42\u0E1B\u0E23\u0E14\u0E44\u0E1B\u0E17\u0E35\u0E48 docs.world.org/test \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E23\u0E32\u0E22\u0E25\u0E30\u0E40\u0E2D\u0E35\u0E22\u0E14",
117
+ "Your identity is still being registered. Please wait a few minutes and try again.": "\u0E15\u0E31\u0E27\u0E15\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E22\u0E31\u0E07\u0E2D\u0E22\u0E39\u0E48\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E01\u0E32\u0E23\u0E25\u0E07\u0E17\u0E30\u0E40\u0E1A\u0E35\u0E22\u0E19 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
118
+ "We couldn't complete your request. Please try again.": "\u0E40\u0E23\u0E32\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E32\u0E21\u0E04\u0E33\u0E02\u0E2D\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
119
+ "Try Again": "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
120
+ "Open World App": "\u0E40\u0E1B\u0E34\u0E14 World App",
121
+ "Hide QR Code": "\u0E0B\u0E48\u0E2D\u0E19 QR Code",
122
+ "Display QR Code": "\u0E41\u0E2A\u0E14\u0E07 QR Code",
123
+ "QR Code copied": "\u0E04\u0E31\u0E14\u0E25\u0E2D\u0E01 QR Code \u0E41\u0E25\u0E49\u0E27",
124
+ "Connect your World ID": "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
125
+ "Use phone camera to scan the QR code": "\u0E43\u0E0A\u0E49\u0E01\u0E25\u0E49\u0E2D\u0E07\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E41\u0E01\u0E19 QR code",
126
+ "Connecting...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D...",
127
+ "Please continue in app": "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E48\u0E2D\u0E43\u0E19\u0E41\u0E2D\u0E1B",
128
+ "You will be redirected to the app, please return to this page once you're done": "\u0E04\u0E38\u0E13\u0E08\u0E30\u0E16\u0E39\u0E01\u0E19\u0E33\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B \u0E01\u0E23\u0E38\u0E13\u0E32\u0E01\u0E25\u0E31\u0E1A\u0E21\u0E32\u0E17\u0E35\u0E48\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49\u0E40\u0E21\u0E37\u0E48\u0E2D\u0E40\u0E2A\u0E23\u0E47\u0E08\u0E41\u0E25\u0E49\u0E27",
129
+ "Action cannot be an empty string.": "\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E27\u0E48\u0E32\u0E07\u0E44\u0E14\u0E49",
130
+ "Invalid IDKitStage :stage.": "IDKitStage \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 :stage.",
131
+ "Terms & Privacy": "\u0E02\u0E49\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E41\u0E25\u0E30\u0E04\u0E27\u0E32\u0E21\u0E40\u0E1B\u0E47\u0E19\u0E2A\u0E48\u0E27\u0E19\u0E15\u0E31\u0E27"
132
+ };
133
+
134
+ // src/lang/translations/index.ts
135
+ var translations = {
136
+ en,
137
+ es,
138
+ th
139
+ };
140
+
141
+ // src/lang/localization.ts
142
+ var currentConfig = {};
143
+ var setLocalizationConfig = (config) => {
144
+ currentConfig = config;
145
+ };
146
+ var getLocalizationConfig = () => currentConfig;
147
+ var detectBrowserLanguage = () => {
148
+ for (const lang of navigator.languages) {
149
+ const [language] = lang.split("-");
150
+ const normalizedLang = language.toLowerCase();
151
+ if (normalizedLang in translations) {
152
+ return normalizedLang;
153
+ }
154
+ }
155
+ return void 0;
156
+ };
157
+ var getCurrentLanguage = () => {
158
+ const config = getLocalizationConfig();
159
+ if (config.language && config.language in translations) {
160
+ return config.language;
161
+ }
162
+ const browserLang = detectBrowserLanguage();
163
+ if (browserLang) {
164
+ return browserLang;
165
+ }
166
+ return "en";
167
+ };
168
+ var getTranslations = () => {
169
+ const currentLang = getCurrentLanguage();
170
+ return translations[currentLang];
171
+ };
172
+ var getSupportedLanguages = () => {
173
+ return Object.keys(translations);
174
+ };
175
+
40
176
  // src/lang/index.ts
41
- var translations = {};
42
177
  var getLang = () => {
43
- if (!navigator?.languages) return;
44
- const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
45
- return translations[supportedLang];
178
+ return getTranslations();
46
179
  };
47
180
  var replaceParams = (str, params) => {
48
- let replaced = str;
49
- for (const [key, value] of Object.entries(params ?? {})) replaced = str.replace(`:${key}`, value);
50
- return replaced;
181
+ if (!params) return str;
182
+ let result = str;
183
+ for (const [key, value] of Object.entries(params)) {
184
+ result = result.replace(`:${key}`, value);
185
+ }
186
+ return result;
51
187
  };
52
- function __(str, params) {
53
- if (typeof navigator === "undefined") return str;
54
- return replaceParams(getLang()?.[str] ?? str, params);
188
+ function __(str, ...args) {
189
+ const [params] = args;
190
+ if (typeof navigator === "undefined" && typeof window === "undefined") {
191
+ return replaceParams(str, params);
192
+ }
193
+ const translated = getLang()?.[str] ?? str;
194
+ return replaceParams(translated, params);
55
195
  }
56
196
 
57
197
  // src/components/QRCode.tsx
@@ -111,7 +251,7 @@ var Qrcode = ({ data, size = 300 }) => {
111
251
  "circle",
112
252
  {
113
253
  fill: "currentColor",
114
- r: cellSize / 3,
254
+ r: cellSize / 2.2,
115
255
  cx: i * cellSize + cellSize / 2,
116
256
  cy: j * cellSize + cellSize / 2,
117
257
  className: "text-black dark:text-white"
@@ -265,5 +405,9 @@ var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
265
405
  ConfigSource,
266
406
  QRCode,
267
407
  __,
408
+ getCurrentLanguage,
409
+ getLocalizationConfig,
410
+ getSupportedLanguages,
411
+ setLocalizationConfig,
268
412
  useIDKitStore
269
413
  });
@@ -1,17 +1,32 @@
1
1
  import * as react from 'react';
2
2
  import * as zustand_traditional from 'zustand/traditional';
3
3
  import * as zustand_vanilla from 'zustand/vanilla';
4
- import { I as IDKITStage, a as ConfigSource, b as CallbackFn, C as Config } from './config-BRFx4nLT.cjs';
4
+ import { I as IDKITStage, c as ConfigSource, d as CallbackFn, C as Config } from './config-SH5TbLYj.cjs';
5
+ export { S as SupportedLanguage, a as getCurrentLanguage, g as getLocalizationConfig, b as getSupportedLanguages, s as setLocalizationConfig } from './config-SH5TbLYj.cjs';
5
6
  import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
6
7
 
7
- type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}` ? never : T extends '' ? never : T;
8
- type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}` ? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}` ? CleanWord<Word> | ExtractPlaceholders<Rest> : never : never;
9
- type NoPlaceholder<S extends string> = S extends `${string}:${string}` ? never : S;
10
- type PlaceholderValues<S extends string> = {
11
- [K in ExtractPlaceholders<S>]: string;
8
+ /**
9
+ * ## Adding Translations
10
+ * To add a new language:
11
+ * 1. Create a new translation file in `src/lang/translations/[lang].ts`
12
+ * 2. Implement all translation strings in the new file
13
+ * 3. Add the language to the `translations` index
14
+ * 4. Update the `SupportedLanguage` type in `src/lang/types.ts`
15
+ */
16
+ /**
17
+ * Translation function with type-safe parameter support
18
+ *
19
+ * Examples:
20
+ * - __('Hello world') // No parameters needed
21
+ * - __('Invalid IDKitStage :stage.', { stage: 'init' }) // Parameter required
22
+ */
23
+ type HasPlaceholder<T extends string> = T extends `${string}:${string}` ? true : false;
24
+ type GetPlaceholderName<T extends string> = T extends `:${infer Name}${infer Rest}` ? Name extends `${infer Word}${' ' | ',' | ':' | '!' | '?' | '.'}${string}` ? Word : Name : never;
25
+ type GetAllPlaceholders<T extends string> = T extends `${infer Before}:${infer After}` ? GetAllPlaceholders<After> | GetPlaceholderName<`:${After}`> : never;
26
+ type TranslationParams<T extends string> = GetAllPlaceholders<T> extends never ? never : {
27
+ [K in GetAllPlaceholders<T>]: string;
12
28
  };
13
- declare function __<S extends `${string}:${string}`>(str: S, params: PlaceholderValues<S>): string;
14
- declare function __<S extends string>(str: NoPlaceholder<S>): string;
29
+ declare function __<T extends string>(str: T, ...args: HasPlaceholder<T> extends true ? [params: TranslationParams<T>] : []): string;
15
30
 
16
31
  type Props = {
17
32
  data: string;
@@ -1,17 +1,32 @@
1
1
  import * as react from 'react';
2
2
  import * as zustand_traditional from 'zustand/traditional';
3
3
  import * as zustand_vanilla from 'zustand/vanilla';
4
- import { I as IDKITStage, a as ConfigSource, b as CallbackFn, C as Config } from './config-BRFx4nLT.js';
4
+ import { I as IDKITStage, c as ConfigSource, d as CallbackFn, C as Config } from './config-SH5TbLYj.js';
5
+ export { S as SupportedLanguage, a as getCurrentLanguage, g as getLocalizationConfig, b as getSupportedLanguages, s as setLocalizationConfig } from './config-SH5TbLYj.js';
5
6
  import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
6
7
 
7
- type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}` ? never : T extends '' ? never : T;
8
- type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}` ? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}` ? CleanWord<Word> | ExtractPlaceholders<Rest> : never : never;
9
- type NoPlaceholder<S extends string> = S extends `${string}:${string}` ? never : S;
10
- type PlaceholderValues<S extends string> = {
11
- [K in ExtractPlaceholders<S>]: string;
8
+ /**
9
+ * ## Adding Translations
10
+ * To add a new language:
11
+ * 1. Create a new translation file in `src/lang/translations/[lang].ts`
12
+ * 2. Implement all translation strings in the new file
13
+ * 3. Add the language to the `translations` index
14
+ * 4. Update the `SupportedLanguage` type in `src/lang/types.ts`
15
+ */
16
+ /**
17
+ * Translation function with type-safe parameter support
18
+ *
19
+ * Examples:
20
+ * - __('Hello world') // No parameters needed
21
+ * - __('Invalid IDKitStage :stage.', { stage: 'init' }) // Parameter required
22
+ */
23
+ type HasPlaceholder<T extends string> = T extends `${string}:${string}` ? true : false;
24
+ type GetPlaceholderName<T extends string> = T extends `:${infer Name}${infer Rest}` ? Name extends `${infer Word}${' ' | ',' | ':' | '!' | '?' | '.'}${string}` ? Word : Name : never;
25
+ type GetAllPlaceholders<T extends string> = T extends `${infer Before}:${infer After}` ? GetAllPlaceholders<After> | GetPlaceholderName<`:${After}`> : never;
26
+ type TranslationParams<T extends string> = GetAllPlaceholders<T> extends never ? never : {
27
+ [K in GetAllPlaceholders<T>]: string;
12
28
  };
13
- declare function __<S extends `${string}:${string}`>(str: S, params: PlaceholderValues<S>): string;
14
- declare function __<S extends string>(str: NoPlaceholder<S>): string;
29
+ declare function __<T extends string>(str: T, ...args: HasPlaceholder<T> extends true ? [params: TranslationParams<T>] : []): string;
15
30
 
16
31
  type Props = {
17
32
  data: string;
package/build/internal.js CHANGED
@@ -2,11 +2,19 @@ import {
2
2
  ConfigSource,
3
3
  QRCode_default,
4
4
  __,
5
- idkit_default
6
- } from "./chunk-5OWPJUHG.js";
5
+ getCurrentLanguage,
6
+ getLocalizationConfig,
7
+ getSupportedLanguages,
8
+ idkit_default,
9
+ setLocalizationConfig
10
+ } from "./chunk-PWFTYFSZ.js";
7
11
  export {
8
12
  ConfigSource,
9
13
  QRCode_default as QRCode,
10
14
  __,
15
+ getCurrentLanguage,
16
+ getLocalizationConfig,
17
+ getSupportedLanguages,
18
+ setLocalizationConfig,
11
19
  idkit_default as useIDKitStore
12
20
  };
package/package.json CHANGED
@@ -103,7 +103,7 @@
103
103
  ]
104
104
  }
105
105
  },
106
- "version": "2.2.2",
106
+ "version": "2.4.0",
107
107
  "scripts": {
108
108
  "build": "npm run build:css && tsup",
109
109
  "build:css": "npx tailwindcss -i ./src/styles/styles.css -o ./build/index.css --minify",
package/src/index.ts CHANGED
@@ -6,9 +6,22 @@ import { verifyCloudProof } from '@worldcoin/idkit-core/backend'
6
6
  import type { IVerifyResponse } from '@worldcoin/idkit-core/backend'
7
7
  import type { ISuccessResult, IErrorState } from '@worldcoin/idkit-core'
8
8
  import { VerificationLevel, VerificationState } from '@worldcoin/idkit-core'
9
+ import { setLocalizationConfig, getLocalizationConfig, getCurrentLanguage, getSupportedLanguages } from '@/lang'
10
+ import type { SupportedLanguage } from '@/lang'
9
11
 
10
- export { IDKitWidget, useIDKit, solidityEncode, verifyCloudProof, VerificationLevel, VerificationState }
11
- export type { ISuccessResult, IErrorState, IVerifyResponse, Config, WidgetProps }
12
+ export {
13
+ IDKitWidget,
14
+ useIDKit,
15
+ solidityEncode,
16
+ verifyCloudProof,
17
+ VerificationLevel,
18
+ VerificationState,
19
+ setLocalizationConfig,
20
+ getLocalizationConfig,
21
+ getCurrentLanguage,
22
+ getSupportedLanguages,
23
+ }
24
+ export type { ISuccessResult, IErrorState, IVerifyResponse, Config, WidgetProps, SupportedLanguage }
12
25
 
13
26
  // Session API
14
27
  export { useSession } from '@/hooks/useSession'
@@ -1,233 +0,0 @@
1
- // src/lang/index.ts
2
- var translations = {};
3
- var getLang = () => {
4
- if (!navigator?.languages) return;
5
- const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
6
- return translations[supportedLang];
7
- };
8
- var replaceParams = (str, params) => {
9
- let replaced = str;
10
- for (const [key, value] of Object.entries(params ?? {})) replaced = str.replace(`:${key}`, value);
11
- return replaced;
12
- };
13
- function __(str, params) {
14
- if (typeof navigator === "undefined") return str;
15
- return replaceParams(getLang()?.[str] ?? str, params);
16
- }
17
-
18
- // src/store/idkit.ts
19
- import { shallow } from "zustand/shallow";
20
- import { createWithEqualityFn } from "zustand/traditional";
21
- import {
22
- AppErrorCodes,
23
- DEFAULT_VERIFICATION_LEVEL
24
- } from "@worldcoin/idkit-core";
25
- var SELF_HOSTED_APP_ID = "self_hosted";
26
- var useIDKitStore = createWithEqualityFn()(
27
- (set, get) => ({
28
- app_id: "",
29
- signal: "",
30
- action: "",
31
- action_description: "",
32
- bridge_url: "",
33
- verification_level: DEFAULT_VERIFICATION_LEVEL,
34
- partner: false,
35
- open: false,
36
- result: null,
37
- errorTitle: "",
38
- errorDetail: "",
39
- autoClose: true,
40
- errorState: null,
41
- processing: false,
42
- errorCallbacks: {},
43
- verifyCallbacks: {},
44
- successCallbacks: {},
45
- stage: "WORLD_ID" /* WORLD_ID */,
46
- setStage: (stage) => set({ stage }),
47
- setErrorState: (errorState) => set({ errorState }),
48
- setProcessing: (processing) => set({ processing }),
49
- retryFlow: () => {
50
- set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
51
- },
52
- addErrorCallback: (cb, source) => {
53
- set((state) => {
54
- state.errorCallbacks[source] = cb;
55
- return state;
56
- });
57
- },
58
- addSuccessCallback: (cb, source) => {
59
- set((state) => {
60
- state.successCallbacks[source] = cb;
61
- return state;
62
- });
63
- },
64
- addVerificationCallback: (cb, source) => {
65
- set((state) => {
66
- state.verifyCallbacks[source] = cb;
67
- return state;
68
- });
69
- },
70
- setOptions: ({
71
- handleVerify,
72
- onSuccess,
73
- signal,
74
- action,
75
- app_id,
76
- partner,
77
- onError,
78
- verification_level,
79
- action_description,
80
- bridge_url,
81
- autoClose,
82
- advanced
83
- }, source) => {
84
- set({
85
- signal,
86
- action,
87
- bridge_url,
88
- action_description,
89
- autoClose: autoClose ?? true,
90
- app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
91
- verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL,
92
- partner
93
- });
94
- get().addSuccessCallback(onSuccess, source);
95
- if (onError) get().addErrorCallback(onError, source);
96
- if (handleVerify) get().addVerificationCallback(handleVerify, source);
97
- },
98
- handleVerify: (result) => {
99
- set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
100
- Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
101
- () => {
102
- set({ stage: "SUCCESS" /* SUCCESS */, result });
103
- if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
104
- },
105
- (response) => {
106
- let errorMessage = void 0;
107
- if (response && typeof response === "object" && response.message) {
108
- errorMessage = response.message;
109
- }
110
- set({
111
- stage: "ERROR" /* ERROR */,
112
- errorState: {
113
- code: AppErrorCodes.FailedByHostApp,
114
- message: errorMessage ? __(errorMessage) : void 0
115
- }
116
- });
117
- }
118
- );
119
- },
120
- onOpenChange: (open) => {
121
- if (open) {
122
- return set({ open });
123
- }
124
- const errorState = get().errorState;
125
- if (get().stage === "ERROR" /* ERROR */ && errorState) {
126
- const callbacks = get().errorCallbacks;
127
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
128
- }
129
- const result = get().result;
130
- if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
131
- const callbacks = get().successCallbacks;
132
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
133
- }
134
- set({
135
- open,
136
- result: null,
137
- errorState: null,
138
- processing: false,
139
- stage: "WORLD_ID" /* WORLD_ID */
140
- });
141
- }
142
- }),
143
- shallow
144
- );
145
- var idkit_default = useIDKitStore;
146
-
147
- // src/types/config.ts
148
- var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
149
- ConfigSource2["HOOK"] = "hook";
150
- ConfigSource2["PROPS"] = "props";
151
- ConfigSource2["MANUAL"] = "manual";
152
- return ConfigSource2;
153
- })(ConfigSource || {});
154
-
155
- // src/components/QRCode.tsx
156
- import { memo, useMemo } from "react";
157
- import QRCodeUtil from "qrcode/lib/core/qrcode.js";
158
- import { jsx } from "react/jsx-runtime";
159
- var generateMatrix = (data) => {
160
- const arr = QRCodeUtil.create(data, { errorCorrectionLevel: "M" }).modules.data;
161
- const sqrt = Math.sqrt(arr.length);
162
- return arr.reduce(
163
- (rows, key, index) => {
164
- if (index % sqrt === 0) rows.push([key]);
165
- else rows[rows.length - 1].push(key);
166
- return rows;
167
- },
168
- []
169
- );
170
- };
171
- var Qrcode = ({ data, size = 300 }) => {
172
- const dots = useMemo(() => {
173
- const dots2 = [];
174
- const matrix = generateMatrix(data);
175
- const cellSize = size / matrix.length;
176
- const qrList = [
177
- { x: 0, y: 0 },
178
- { x: 1, y: 0 },
179
- { x: 0, y: 1 }
180
- ];
181
- qrList.forEach(({ x, y }) => {
182
- const x1 = (matrix.length - 7) * cellSize * x;
183
- const y1 = (matrix.length - 7) * cellSize * y;
184
- for (let i = 0; i < 3; i++) {
185
- dots2.push(
186
- /* @__PURE__ */ jsx(
187
- "rect",
188
- {
189
- fill: "currentColor",
190
- x: x1 + cellSize * i,
191
- y: y1 + cellSize * i,
192
- width: cellSize * (7 - i * 2),
193
- height: cellSize * (7 - i * 2),
194
- rx: (i - 2) * -5,
195
- ry: (i - 2) * -5,
196
- className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
197
- },
198
- `${i}-${x}-${y}`
199
- )
200
- );
201
- }
202
- });
203
- matrix.forEach((row, i) => {
204
- row.forEach((_, j) => {
205
- if (!matrix[i][j]) return;
206
- if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
207
- dots2.push(
208
- /* @__PURE__ */ jsx(
209
- "circle",
210
- {
211
- fill: "currentColor",
212
- r: cellSize / 3,
213
- cx: i * cellSize + cellSize / 2,
214
- cy: j * cellSize + cellSize / 2,
215
- className: "text-black dark:text-white"
216
- },
217
- `circle-${i}-${j}`
218
- )
219
- );
220
- });
221
- });
222
- return dots2;
223
- }, [size, data]);
224
- return /* @__PURE__ */ jsx("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
225
- };
226
- var QRCode_default = memo(Qrcode);
227
-
228
- export {
229
- __,
230
- idkit_default,
231
- ConfigSource,
232
- QRCode_default
233
- };