@worldcoin/idkit 2.3.0 → 2.4.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/build/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import {
2
2
  QRCode_default,
3
3
  __,
4
- idkit_default
5
- } from "./chunk-3HCETHXP.js";
4
+ getCurrentLanguage,
5
+ getLocalizationConfig,
6
+ getSupportedLanguages,
7
+ idkit_default,
8
+ setLocalizationConfig
9
+ } from "./chunk-PWFTYFSZ.js";
6
10
 
7
11
  // src/hooks/useIDKit.ts
8
12
  import { useEffect } from "react";
@@ -30,13 +34,13 @@ import { useEffect as useEffect2, useState } from "react";
30
34
  var useMedia = () => {
31
35
  const getInitialState = () => {
32
36
  if (typeof window !== "undefined") {
33
- return window.matchMedia("(max-width: 768px)").matches ? "mobile" : "desktop";
37
+ return window.matchMedia("(max-width: 1024px)").matches ? "mobile" : "desktop";
34
38
  }
35
39
  return "desktop";
36
40
  };
37
41
  const [media, setMedia] = useState(getInitialState());
38
42
  useEffect2(() => {
39
- const mql = window.matchMedia("(max-width: 768px)");
43
+ const mql = window.matchMedia("(max-width: 1024px)");
40
44
  const handleChange = (mql2) => setMedia(mql2.matches ? "mobile" : "desktop");
41
45
  handleChange(mql);
42
46
  mql.addEventListener("change", handleChange);
@@ -1314,6 +1318,9 @@ input[type='number']::-webkit-inner-spin-button,
1314
1318
  .md\\:mt-2 {
1315
1319
  margin-top: 8px;
1316
1320
  }
1321
+ .md\\:block {
1322
+ display: block;
1323
+ }
1317
1324
  .md\\:hidden {
1318
1325
  display: none;
1319
1326
  }
@@ -1340,6 +1347,14 @@ input[type='number']::-webkit-inner-spin-button,
1340
1347
  padding: 16px;
1341
1348
  }
1342
1349
  }
1350
+ @media (min-width: 1280px) {
1351
+ .xl\\:block {
1352
+ display: block;
1353
+ }
1354
+ .xl\\:hidden {
1355
+ display: none;
1356
+ }
1357
+ }
1343
1358
  `;
1344
1359
 
1345
1360
  // src/components/Styles.tsx
@@ -1504,25 +1519,36 @@ var WarningIcon_default = WarningIcon;
1504
1519
  // src/components/IDKitWidget/States/ErrorState.tsx
1505
1520
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
1506
1521
  var getParams = ({ retryFlow, errorState }) => ({ retryFlow, errorState });
1507
- var ERROR_TITLES = {
1508
- [AppErrorCodes.GenericError]: __("Something went wrong"),
1509
- [AppErrorCodes.FailedByHostApp]: __("Verification Declined"),
1510
- [AppErrorCodes.VerificationRejected]: __("Request cancelled")
1522
+ var getErrorTitle = (code) => {
1523
+ switch (code) {
1524
+ case AppErrorCodes.GenericError:
1525
+ return __("Something went wrong");
1526
+ case AppErrorCodes.FailedByHostApp:
1527
+ return __("Verification Declined");
1528
+ case AppErrorCodes.VerificationRejected:
1529
+ return __("Request cancelled");
1530
+ default:
1531
+ return __("Something went wrong");
1532
+ }
1511
1533
  };
1512
- var ERROR_MESSAGES = {
1513
- [AppErrorCodes.ConnectionFailed]: __("Connection to your wallet failed. Please try again."),
1514
- [AppErrorCodes.VerificationRejected]: __("You\u2019ve cancelled the request in World App."),
1515
- [AppErrorCodes.MaxVerificationsReached]: __(
1516
- "You have already verified the maximum number of times for this action."
1517
- ),
1518
- [AppErrorCodes.CredentialUnavailable]: __("It seems you do not have the verification level required by this app."),
1519
- [AppErrorCodes.InvalidNetwork]: __(
1520
- "Invalid network. If you are the app owner, visit docs.world.org/test for details."
1521
- ),
1522
- [AppErrorCodes.InclusionProofPending]: __(
1523
- "Your identity is still being registered. Please wait a few minutes and try again."
1524
- ),
1525
- [AppErrorCodes.GenericError]: __("We couldn't complete your request. Please try again.")
1534
+ var getErrorMessage = (code) => {
1535
+ switch (code) {
1536
+ case AppErrorCodes.ConnectionFailed:
1537
+ return __("Connection to your wallet failed. Please try again.");
1538
+ case AppErrorCodes.VerificationRejected:
1539
+ return __("You've cancelled the request in World App.");
1540
+ case AppErrorCodes.MaxVerificationsReached:
1541
+ return __("You've already verified the maximum number of times for this action.");
1542
+ case AppErrorCodes.CredentialUnavailable:
1543
+ return __("It seems you don't have the verification level required by this app.");
1544
+ case AppErrorCodes.InvalidNetwork:
1545
+ return __("Invalid network. If you are the app owner, visit docs.world.org/test for details.");
1546
+ case AppErrorCodes.InclusionProofPending:
1547
+ return __("Your identity is still being registered. Please wait a few minutes and try again.");
1548
+ case AppErrorCodes.GenericError:
1549
+ default:
1550
+ return __("We couldn't complete your request. Please try again.");
1551
+ }
1526
1552
  };
1527
1553
  var ErrorState = (props) => {
1528
1554
  const { retryFlow, errorState } = idkit_default(getParams);
@@ -1535,8 +1561,8 @@ var ErrorState = (props) => {
1535
1561
  return /* @__PURE__ */ jsxs3("div", { className: "space-y-8", children: [
1536
1562
  /* @__PURE__ */ jsx6("div", { className: clsx_default("flex items-center justify-center", show_modal ? "-mt-5" : ""), children: errorState?.code == AppErrorCodes.VerificationRejected ? /* @__PURE__ */ jsx6(WarningIcon_default, { className: "w-24" }) : /* @__PURE__ */ jsx6(ErrorIcon_default, { className: "w-24" }) }),
1537
1563
  /* @__PURE__ */ jsxs3("div", { children: [
1538
- /* @__PURE__ */ jsx6("p", { className: "text-center text-2xl font-semibold text-gray-900 dark:text-white", children: (errorState?.code && ERROR_TITLES[errorState.code]) ?? ERROR_TITLES[AppErrorCodes.GenericError] }),
1539
- /* @__PURE__ */ jsx6("p", { className: "mx-auto mt-2 max-w-[224px] text-center text-657080", children: (errorState?.code && ERROR_MESSAGES[errorState.code]) ?? ERROR_MESSAGES[AppErrorCodes.GenericError] })
1564
+ /* @__PURE__ */ jsx6("p", { className: "text-center text-2xl font-semibold text-gray-900 dark:text-white", children: errorState?.code ? getErrorTitle(errorState.code) : getErrorTitle(AppErrorCodes.GenericError) }),
1565
+ /* @__PURE__ */ jsx6("p", { className: "mx-auto mt-2 max-w-[224px] text-center text-657080", children: errorState?.code ? getErrorMessage(errorState.code) : getErrorMessage(AppErrorCodes.GenericError) })
1540
1566
  ] }),
1541
1567
  /* @__PURE__ */ jsx6("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx6(
1542
1568
  "button",
@@ -1748,15 +1774,22 @@ var QRState = ({ qrData, showQR, setShowQR }) => {
1748
1774
  setTimeout(() => setCopiedLink(false), 2e3);
1749
1775
  }, [qrData]);
1750
1776
  return /* @__PURE__ */ jsxs7(Fragment, { children: [
1751
- /* @__PURE__ */ jsxs7("div", { className: clsx_default("md:hidden", { "mb-10 space-y-4": !showQR }), children: [
1777
+ /* @__PURE__ */ jsx11("div", { className: "md:hidden", children: /* @__PURE__ */ jsxs7(
1778
+ "a",
1779
+ {
1780
+ href: qrData ?? "",
1781
+ className: "flex w-full items-center space-x-2 rounded-2xl border border-transparent p-4 font-medium shadow-sm bg-0d151d text-white dark:bg-white dark:text-0d151d",
1782
+ children: [
1783
+ /* @__PURE__ */ jsx11(WorldcoinIcon_default, { className: "size-5" }),
1784
+ /* @__PURE__ */ jsx11("span", { className: "flex-1 text-center", children: __("Open World App") })
1785
+ ]
1786
+ }
1787
+ ) }),
1788
+ /* @__PURE__ */ jsxs7("div", { className: clsx_default("hidden md:block xl:hidden", { "mb-10 space-y-4": !showQR }), children: [
1752
1789
  /* @__PURE__ */ jsxs7(
1753
- motion.a,
1790
+ "a",
1754
1791
  {
1755
1792
  href: qrData ?? "",
1756
- whileTap: { scale: 0.95 },
1757
- whileHover: { scale: 1.05 },
1758
- transition: { layout: { duration: 0.15 } },
1759
- layoutId: media == "desktop" ? void 0 : "worldid-button",
1760
1793
  className: clsx_default(
1761
1794
  "flex w-full items-center space-x-2 rounded-2xl border border-transparent p-4 font-medium shadow-sm",
1762
1795
  "bg-0d151d text-white dark:bg-white dark:text-0d151d",
@@ -1764,20 +1797,12 @@ var QRState = ({ qrData, showQR, setShowQR }) => {
1764
1797
  ),
1765
1798
  children: [
1766
1799
  /* @__PURE__ */ jsx11(WorldcoinIcon_default, { className: "size-5" }),
1767
- /* @__PURE__ */ jsx11(
1768
- motion.span,
1769
- {
1770
- className: "flex-1 text-center",
1771
- transition: { layout: { duration: 0.15 } },
1772
- layoutId: media == "desktop" ? void 0 : "worldid-text",
1773
- children: __("Open World App")
1774
- }
1775
- )
1800
+ /* @__PURE__ */ jsx11("span", { className: "flex-1 text-center", children: __("Open World App") })
1776
1801
  ]
1777
1802
  }
1778
1803
  ),
1779
- /* @__PURE__ */ jsxs7("div", { className: clsx_default("mb-3", { "space-y-4": !showQR, hidden: media === "mobile" }), children: [
1780
- /* @__PURE__ */ jsxs7("div", { className: clsx_default("flex items-center space-x-4 ", { hidden: showQR }), children: [
1804
+ /* @__PURE__ */ jsxs7("div", { className: clsx_default("mb-3 space-y-4", { hidden: showQR }), children: [
1805
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center space-x-4", children: [
1781
1806
  /* @__PURE__ */ jsx11("hr", { className: "flex-1" }),
1782
1807
  /* @__PURE__ */ jsx11("span", { className: "text-xs font-medium text-9ba3ae", children: "or" }),
1783
1808
  /* @__PURE__ */ jsx11("hr", { className: "flex-1" })
@@ -1787,12 +1812,61 @@ var QRState = ({ qrData, showQR, setShowQR }) => {
1787
1812
  {
1788
1813
  className: "w-full rounded-2xl border border-ebecef p-4 text-lg font-medium text-3c424b",
1789
1814
  onClick: () => setShowQR((state) => !state),
1790
- children: showQR ? __("Hide QR Code") : __("Display QR Code")
1815
+ children: __("Display QR Code")
1791
1816
  }
1792
1817
  )
1793
1818
  ] })
1794
1819
  ] }),
1795
- (media == "desktop" || showQR) && /* @__PURE__ */ jsxs7(Fragment, { children: [
1820
+ showQR && /* @__PURE__ */ jsxs7("div", { className: "hidden md:block xl:hidden", children: [
1821
+ /* @__PURE__ */ jsx11("div", { className: "mb-4", children: /* @__PURE__ */ jsx11(
1822
+ motion.button,
1823
+ {
1824
+ className: "w-full rounded-2xl border border-ebecef p-4 text-lg font-medium text-3c424b",
1825
+ onClick: () => setShowQR(false),
1826
+ children: __("Hide QR Code")
1827
+ }
1828
+ ) }),
1829
+ /* @__PURE__ */ jsx11("div", { className: "relative inline-flex items-center justify-center rounded-2xl border border-f1f5f8 p-3 dark:border-f1f5f8/10", children: /* @__PURE__ */ jsx11("div", { className: "text-29343f dark:text-white", children: qrData ? (
1830
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
1831
+ /* @__PURE__ */ jsx11("div", { onClick: copyLink, className: "cursor-pointer", children: /* @__PURE__ */ jsx11(QRCode_default, { data: qrData, size: 200 }) })
1832
+ ) : /* @__PURE__ */ jsx11("div", { className: "flex size-[200px] items-center justify-center", children: /* @__PURE__ */ jsx11(QRPlaceholderIcon_default, { className: "size-[200px] animate-pulse" }) }) }) }),
1833
+ /* @__PURE__ */ jsx11(AnimatePresence, { children: copiedLink && /* @__PURE__ */ jsx11(
1834
+ motion.div,
1835
+ {
1836
+ className: "text-sm text-9eafc0 text-center",
1837
+ initial: "hidden",
1838
+ animate: "visible",
1839
+ exit: "exit",
1840
+ variants: {
1841
+ hidden: { opacity: 0, height: 0, marginTop: 0 },
1842
+ visible: {
1843
+ opacity: 1,
1844
+ height: "auto",
1845
+ marginTop: 8,
1846
+ transition: {
1847
+ duration: 0.25,
1848
+ opacity: { delay: 0.05, duration: 0.2 },
1849
+ ease: "easeInOut"
1850
+ }
1851
+ },
1852
+ exit: {
1853
+ opacity: 0,
1854
+ height: 0,
1855
+ marginTop: 0,
1856
+ transition: {
1857
+ duration: 0.4,
1858
+ delay: 0.1,
1859
+ opacity: { duration: 0.25, delay: 0 },
1860
+ ease: "easeInOut"
1861
+ }
1862
+ }
1863
+ },
1864
+ children: /* @__PURE__ */ jsx11("span", { className: "rounded-lg border border-f1f5f8 px-2 py-1 text-sm", children: __("QR Code copied") })
1865
+ },
1866
+ "copied"
1867
+ ) })
1868
+ ] }),
1869
+ /* @__PURE__ */ jsxs7("div", { className: "hidden xl:block", children: [
1796
1870
  /* @__PURE__ */ jsx11(AnimatePresence, { children: copiedLink && /* @__PURE__ */ jsx11(
1797
1871
  motion.div,
1798
1872
  {
@@ -1971,7 +2045,8 @@ var WorldIDState = (props) => {
1971
2045
  /* @__PURE__ */ jsxs9("div", { className: clsx_default(!show_modal ? "hidden" : ""), children: [
1972
2046
  /* @__PURE__ */ jsx13("div", { className: "mb-4 flex items-center justify-center", children: /* @__PURE__ */ jsx13("div", { className: "flex size-14 items-center justify-center rounded-full border-[1.2px] border-solid border-[#EBECEF]", children: /* @__PURE__ */ jsx13(WorldcoinIcon_default, { className: "size-8 text-0d151d dark:text-white" }) }) }),
1973
2047
  /* @__PURE__ */ jsx13("p", { className: "text-2xl font-semibold text-gray-900 dark:text-white", children: __("Connect your World ID") }),
1974
- /* @__PURE__ */ jsx13("p", { className: clsx_default("mt-3 text-657080 dark:text-9eafc0 md:mt-2", { hidden: media === "mobile" }), children: __("Use phone camera to scan the QR code") })
2048
+ /* @__PURE__ */ jsx13("p", { className: clsx_default("mt-3 text-657080 dark:text-9eafc0 md:mt-2", { hidden: media === "mobile" }), children: __("Use phone camera to scan the QR code") }),
2049
+ /* @__PURE__ */ jsx13("p", { className: clsx_default("mt-3 text-657080 dark:text-9eafc0 md:mt-2", { hidden: media !== "mobile" }), children: __("You will be redirected to the app, please return to this page once you're done") })
1975
2050
  ] }),
1976
2051
  /* @__PURE__ */ jsxs9("div", { className: "relative w-full", children: [
1977
2052
  verificationState === VerificationState.WaitingForApp && /* @__PURE__ */ jsxs9("div", { className: "absolute inset-0 flex flex-col items-center justify-center space-y-6", children: [
@@ -2029,10 +2104,16 @@ var IDKitWidget = ({
2029
2104
  show_modal = true,
2030
2105
  container_id,
2031
2106
  disable_default_modal_behavior = false,
2107
+ language,
2032
2108
  ...config
2033
2109
  }) => {
2034
2110
  const media = useMedia_default();
2035
2111
  const { isOpen, onOpenChange, stage, setStage, setOptions, setErrorState } = idkit_default(getParams2, shallow2);
2112
+ useEffect7(() => {
2113
+ if (language) {
2114
+ setLocalizationConfig({ language });
2115
+ }
2116
+ }, [language]);
2036
2117
  useEffect7(() => {
2037
2118
  if (config.action === "") {
2038
2119
  throw new Error(__("Action cannot be an empty string."));
@@ -2050,7 +2131,7 @@ var IDKitWidget = ({
2050
2131
  case "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */:
2051
2132
  return /* @__PURE__ */ jsx15(HostAppVerificationState_default, {});
2052
2133
  default:
2053
- throw new Error(__("Invalid IDKitStage :stage.", { stage }));
2134
+ throw new Error(__("Invalid IDKitStage :stage.", { s: String(stage) }));
2054
2135
  }
2055
2136
  }, [stage, show_modal]);
2056
2137
  const widgetContent = /* @__PURE__ */ jsxs11(ShadowHost, { mode: "open", id: "idkit-widget", children: [
@@ -2194,6 +2275,10 @@ export {
2194
2275
  IDKitWidget_default as IDKitWidget,
2195
2276
  VerificationLevel2 as VerificationLevel,
2196
2277
  VerificationState3 as VerificationState,
2278
+ getCurrentLanguage,
2279
+ getLocalizationConfig,
2280
+ getSupportedLanguages,
2281
+ setLocalizationConfig,
2197
2282
  solidityEncode,
2198
2283
  useIDKit_default as useIDKit,
2199
2284
  useSession,
@@ -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
@@ -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-3HCETHXP.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
@@ -37,6 +37,9 @@
37
37
  "tsup": "^8.1.0",
38
38
  "typescript": "^5.5.3"
39
39
  },
40
+ "overrides": {
41
+ "rollup": "^4.22.4"
42
+ },
40
43
  "engines": {
41
44
  "node": ">=12.4"
42
45
  },
@@ -103,7 +106,7 @@
103
106
  ]
104
107
  }
105
108
  },
106
- "version": "2.3.0",
109
+ "version": "2.4.1",
107
110
  "scripts": {
108
111
  "build": "npm run build:css && tsup",
109
112
  "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'