@prosopo/procaptcha-bundle 3.0.9 → 3.0.11

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 (135) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/bundle/ProcaptchaWidget-48FxVPQd.js +187 -0
  3. package/dist/bundle/ProcaptchaWidget-B2BzhXLv.js +992 -0
  4. package/dist/bundle/builder-DNHtDoNG.js +44 -0
  5. package/dist/bundle/{captchaComponentProvider-CZppE3Vb.js → captchaComponentProvider-B7Vxx339.js} +256 -99
  6. package/dist/bundle/{captchaRenderer-CY8KuZK-.js → captchaRenderer-DdOlOCKw.js} +3 -3
  7. package/dist/bundle/{commonChunk-24zMb_mF.js → commonChunk-HCVkoCqn.js} +9 -12
  8. package/dist/bundle/{emotion-element-5486c51c.browser.esm-PRDDgd_k.js → emotion-element-5486c51c.browser.esm-D7qvHZDV.js} +1 -1
  9. package/dist/bundle/{fp.esm-BADUiinQ.js → fp.esm-DYWeNGcH.js} +648 -548
  10. package/dist/bundle/index-7Xh-Mf8v.js +1318 -0
  11. package/dist/bundle/{index-BiwZ4wVT.js → index-C00_J7av.js} +48 -12
  12. package/dist/bundle/{index-BzOMq-ud.js → index-DyYmvHVN.js} +1 -1
  13. package/dist/bundle/locales/ar/translation.json +12 -11
  14. package/dist/bundle/locales/az/translation.json +12 -11
  15. package/dist/bundle/locales/cs/translation.json +12 -11
  16. package/dist/bundle/locales/de/translation.json +12 -11
  17. package/dist/bundle/locales/el/translation.json +12 -11
  18. package/dist/bundle/locales/en/translation.json +4 -3
  19. package/dist/bundle/locales/es/translation.json +12 -11
  20. package/dist/bundle/locales/fi/translation.json +29 -28
  21. package/dist/bundle/locales/fr/translation.json +12 -11
  22. package/dist/bundle/locales/hi/translation.json +41 -40
  23. package/dist/bundle/locales/hu/translation.json +12 -11
  24. package/dist/bundle/locales/id/translation.json +12 -11
  25. package/dist/bundle/locales/it/translation.json +12 -11
  26. package/dist/bundle/locales/ja/translation.json +12 -11
  27. package/dist/bundle/locales/jv/translation.json +12 -11
  28. package/dist/bundle/locales/ko/translation.json +7 -6
  29. package/dist/bundle/locales/ml/translation.json +12 -11
  30. package/dist/bundle/locales/ms/translation.json +12 -11
  31. package/dist/bundle/locales/nl/translation.json +12 -11
  32. package/dist/bundle/locales/no/translation.json +12 -11
  33. package/dist/bundle/locales/pl/translation.json +12 -11
  34. package/dist/bundle/locales/pt/translation.json +12 -11
  35. package/dist/bundle/locales/pt-BR/translation.json +12 -11
  36. package/dist/bundle/locales/ro/translation.json +12 -11
  37. package/dist/bundle/locales/ru/translation.json +12 -11
  38. package/dist/bundle/locales/sr/translation.json +12 -11
  39. package/dist/bundle/locales/sv/translation.json +12 -11
  40. package/dist/bundle/locales/th/translation.json +12 -11
  41. package/dist/bundle/locales/tr/translation.json +7 -6
  42. package/dist/bundle/locales/uk/translation.json +12 -11
  43. package/dist/bundle/locales/vi/translation.json +12 -11
  44. package/dist/bundle/locales/zh-CN/translation.json +12 -11
  45. package/dist/bundle/nobleChunk-Qozzkbsq.js +3648 -0
  46. package/dist/bundle/procaptcha.bundle.js +2 -2
  47. package/dist/bundle/{utilCryptoChunk-CIPUtfoO.js → utilCryptoChunk-qm-BM2eT.js} +618 -647
  48. package/dist/bundle/{web2Chunk-7Vd8yt2r.js → web2Chunk-DCsWA5PR.js} +1150 -994
  49. package/dist/bundle/{web3Chunk-DrUvbVNW.js → web3Chunk-B8txCqUJ.js} +3 -3
  50. package/dist/index.js +142 -108
  51. package/dist/util/captcha/captchaComponentProvider.js +18 -10
  52. package/dist/util/captcha/captchaComponentsList.js +6 -5
  53. package/dist/util/captcha/captchaRenderer.js +58 -40
  54. package/dist/util/captcha/captchaType.js +9 -5
  55. package/dist/util/captcha/components/frictionlessCaptcha.js +19 -9
  56. package/dist/util/captcha/components/imageCaptcha.js +13 -5
  57. package/dist/util/captcha/components/powCaptcha.js +13 -5
  58. package/dist/util/config.js +15 -12
  59. package/dist/util/configCreator.js +21 -22
  60. package/dist/util/language.js +14 -13
  61. package/dist/util/timeout.js +13 -8
  62. package/dist/util/widgetFactory.js +77 -55
  63. package/dist/util/widgetThemeResolver.js +14 -17
  64. package/package.json +23 -20
  65. package/stats.html +1 -1
  66. package/vite.cjs.config.ts +2 -3
  67. package/vite.esm.config.ts +20 -0
  68. package/vite.test.config.ts +9 -5
  69. package/dist/bundle/ProcaptchaWidget-D_kzGjgO.js +0 -612
  70. package/dist/bundle/ProcaptchaWidget-DlrcrISF.js +0 -148
  71. package/dist/bundle/builder-CQlqPNRd.js +0 -37
  72. package/dist/bundle/index-BRg_gWPo.js +0 -1328
  73. package/dist/bundle/nobleChunk-Xl5XLrx3.js +0 -3635
  74. package/dist/components.d.ts +0 -5
  75. package/dist/components.d.ts.map +0 -1
  76. package/dist/components.js +0 -5
  77. package/dist/components.js.map +0 -1
  78. package/dist/index.d.ts +0 -16
  79. package/dist/index.d.ts.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/tests/util/captchaType.test.d.ts +0 -2
  82. package/dist/tests/util/captchaType.test.d.ts.map +0 -1
  83. package/dist/tests/util/captchaType.test.js +0 -36
  84. package/dist/tests/util/captchaType.test.js.map +0 -1
  85. package/dist/tests/util/config.test.d.ts +0 -2
  86. package/dist/tests/util/config.test.d.ts.map +0 -1
  87. package/dist/tests/util/config.test.js +0 -69
  88. package/dist/tests/util/config.test.js.map +0 -1
  89. package/dist/tests/util/renderLogic.test.d.ts +0 -2
  90. package/dist/tests/util/renderLogic.test.d.ts.map +0 -1
  91. package/dist/tests/util/renderLogic.test.js +0 -126
  92. package/dist/tests/util/renderLogic.test.js.map +0 -1
  93. package/dist/util/captcha/captchaComponentProvider.d.ts +0 -8
  94. package/dist/util/captcha/captchaComponentProvider.d.ts.map +0 -1
  95. package/dist/util/captcha/captchaComponentProvider.js.map +0 -1
  96. package/dist/util/captcha/captchaComponentsList.d.ts +0 -6
  97. package/dist/util/captcha/captchaComponentsList.d.ts.map +0 -1
  98. package/dist/util/captcha/captchaComponentsList.js.map +0 -1
  99. package/dist/util/captcha/captchaProps.d.ts +0 -9
  100. package/dist/util/captcha/captchaProps.d.ts.map +0 -1
  101. package/dist/util/captcha/captchaProps.js +0 -2
  102. package/dist/util/captcha/captchaProps.js.map +0 -1
  103. package/dist/util/captcha/captchaRenderer.d.ts +0 -24
  104. package/dist/util/captcha/captchaRenderer.d.ts.map +0 -1
  105. package/dist/util/captcha/captchaRenderer.js.map +0 -1
  106. package/dist/util/captcha/captchaType.d.ts +0 -3
  107. package/dist/util/captcha/captchaType.d.ts.map +0 -1
  108. package/dist/util/captcha/captchaType.js.map +0 -1
  109. package/dist/util/captcha/components/frictionlessCaptcha.d.ts +0 -4
  110. package/dist/util/captcha/components/frictionlessCaptcha.d.ts.map +0 -1
  111. package/dist/util/captcha/components/frictionlessCaptcha.js.map +0 -1
  112. package/dist/util/captcha/components/imageCaptcha.d.ts +0 -4
  113. package/dist/util/captcha/components/imageCaptcha.d.ts.map +0 -1
  114. package/dist/util/captcha/components/imageCaptcha.js.map +0 -1
  115. package/dist/util/captcha/components/powCaptcha.d.ts +0 -4
  116. package/dist/util/captcha/components/powCaptcha.d.ts.map +0 -1
  117. package/dist/util/captcha/components/powCaptcha.js.map +0 -1
  118. package/dist/util/config.d.ts +0 -6
  119. package/dist/util/config.d.ts.map +0 -1
  120. package/dist/util/config.js.map +0 -1
  121. package/dist/util/configCreator.d.ts +0 -5
  122. package/dist/util/configCreator.d.ts.map +0 -1
  123. package/dist/util/configCreator.js.map +0 -1
  124. package/dist/util/language.d.ts +0 -3
  125. package/dist/util/language.d.ts.map +0 -1
  126. package/dist/util/language.js.map +0 -1
  127. package/dist/util/timeout.d.ts +0 -3
  128. package/dist/util/timeout.d.ts.map +0 -1
  129. package/dist/util/timeout.js.map +0 -1
  130. package/dist/util/widgetFactory.d.ts +0 -18
  131. package/dist/util/widgetFactory.d.ts.map +0 -1
  132. package/dist/util/widgetFactory.js.map +0 -1
  133. package/dist/util/widgetThemeResolver.d.ts +0 -9
  134. package/dist/util/widgetThemeResolver.d.ts.map +0 -1
  135. package/dist/util/widgetThemeResolver.js.map +0 -1
@@ -16,8 +16,7 @@ import { ViteCommonJSConfig } from "@prosopo/config";
16
16
 
17
17
  export default function () {
18
18
  return ViteCommonJSConfig(
19
- "procaptcha-bundle",
20
- path.resolve("./tsconfig.cjs.json"),
21
- "src/index.ts",
19
+ path.basename("."),
20
+ path.resolve("./tsconfig.json"),
22
21
  );
23
22
  }
@@ -0,0 +1,20 @@
1
+ // Copyright 2021-2025 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import path from "node:path";
16
+ import { ViteEsmConfig } from "@prosopo/config";
17
+
18
+ export default function () {
19
+ return ViteEsmConfig(path.basename("."), path.resolve("./tsconfig.json"));
20
+ }
@@ -1,3 +1,5 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
1
3
  // Copyright 2021-2025 Prosopo (UK) Ltd.
2
4
  //
3
5
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -11,12 +13,8 @@
11
13
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
14
  // See the License for the specific language governing permissions and
13
15
  // limitations under the License.
14
-
15
- import fs from "node:fs";
16
- import path from "node:path";
17
16
  import { ViteTestConfig } from "@prosopo/config";
18
17
  import dotenv from "dotenv";
19
-
20
18
  process.env.NODE_ENV = "test";
21
19
  // if .env.test exists at this level, use it, otherwise use the one at the root
22
20
  const envFile = `.env.${process.env.NODE_ENV || "development"}`;
@@ -31,4 +29,10 @@ if (fs.existsSync(envFile)) {
31
29
 
32
30
  dotenv.config({ path: envPath });
33
31
 
34
- export default ViteTestConfig();
32
+ export default function () {
33
+ const config = ViteTestConfig();
34
+ config.test = config.test || {};
35
+ config.test.environment = "jsdom";
36
+ config.test.globals = true;
37
+ return config;
38
+ }
@@ -1,612 +0,0 @@
1
- import { j as l, a as H, g as ne, p as U, b as oe, P as ae, E as re, c as se, C as ie } from "./captchaComponentProvider-CZppE3Vb.js";
2
- import { r as m, u as V, a as b, A as w, f as ce, h as le, s as de, P as X, g as ue, l as he } from "./web2Chunk-7Vd8yt2r.js";
3
- import { l as M, d as D } from "./index-BiwZ4wVT.js";
4
- import { b as _, c as W, P as v, a as N } from "./commonChunk-24zMb_mF.js";
5
- import { r as pe } from "./index-BzOMq-ud.js";
6
- import { v as ge } from "./utilCryptoChunk-CIPUtfoO.js";
7
- import { w as fe } from "./utilChunk-sqstc6C5.js";
8
- import { b as me, u as xe } from "./builder-CQlqPNRd.js";
9
- const Ce = {
10
- border: "none",
11
- paddingTop: "6px",
12
- paddingBottom: "6px",
13
- cursor: "pointer",
14
- height: "39px",
15
- width: "39px",
16
- borderRadius: "50%",
17
- display: "flex"
18
- }, we = ({ themeColor: r, onReload: e }) => {
19
- const n = m.useMemo(() => r === "light" ? M : D, [r]), [o, t] = m.useState(!1), i = m.useMemo(() => ({
20
- ...{
21
- ...Ce,
22
- backgroundColor: n.palette.background.default,
23
- color: o ? n.palette.primary.contrastText : n.palette.background.contrastText,
24
- border: `1px solid ${n.palette.grey[500]}`,
25
- borderRadius: "50%",
26
- transition: "background-color 0.3s",
27
- boxShadow: `0px 1px 3px 0px ${n.palette.grey[500]}`,
28
- justifyContent: "center",
29
- alignItems: "center",
30
- margin: "0 auto"
31
- },
32
- backgroundColor: o ? n.palette.grey[700] : n.palette.background.default
33
- }), [o, n]);
34
- return l("button", { className: "reload-button", "aria-label": "Reload", type: "button", style: i, onMouseEnter: () => t(!0), onMouseLeave: () => t(!1), onClick: (a) => {
35
- a.preventDefault(), e();
36
- }, children: H("svg", { width: "16px", height: "16px", viewBox: "0 0 16 16", version: "1.1", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink", style: { display: "flex" }, children: [l("title", { children: "reload" }), l("path", { shapeRendering: "optimizeQuality", fill: o ? n.palette.primary.contrastText : n.palette.grey[700], transform: "scale(0.0416)", d: "M234.666667,149.333333 L234.666667,106.666667 L314.564847,106.664112 C287.579138,67.9778918 242.745446,42.6666667 192,42.6666667 C109.525477,42.6666667 42.6666667,109.525477 42.6666667,192 C42.6666667,274.474523 109.525477,341.333333 192,341.333333 C268.201293,341.333333 331.072074,284.258623 340.195444,210.526102 L382.537159,215.817985 C370.807686,310.617565 289.973536,384 192,384 C85.961328,384 1.42108547e-14,298.038672 1.42108547e-14,192 C1.42108547e-14,85.961328 85.961328,1.42108547e-14 192,1.42108547e-14 C252.316171,1.42108547e-14 306.136355,27.8126321 341.335366,71.3127128 L341.333333,1.42108547e-14 L384,1.42108547e-14 L384,149.333333 L234.666667,149.333333 Z" })] }) });
37
- }, be = (r) => {
38
- if (!r.hash)
39
- throw new _("CAPTCHA.MISSING_ITEM_HASH", {
40
- context: { item: r }
41
- });
42
- return r.hash;
43
- }, Ae = ({ challenge: r, solution: e, onClick: n, themeColor: o }) => {
44
- const t = r.items, i = m.useMemo(() => o === "light" ? M : D, [o]), a = `${i.spacing.unit}px`;
45
- return l("div", { style: {
46
- width: "100%",
47
- height: "100%",
48
- display: "flex",
49
- flexDirection: "row",
50
- flexWrap: "wrap",
51
- justifyContent: "space-between",
52
- paddingBottom: a,
53
- paddingTop: a,
54
- gap: "10px"
55
- }, children: t.map((s, d) => {
56
- const u = be(s);
57
- return l("div", { style: {
58
- flexGrow: 1,
59
- flexBasis: "calc(33.333% - 10px)",
60
- boxSizing: "border-box"
61
- }, children: H("div", { style: {
62
- position: "relative",
63
- cursor: "pointer",
64
- height: "100%",
65
- width: "100%",
66
- padding: 0,
67
- margin: 0
68
- }, onClick: () => n(u), children: [l("img", { style: {
69
- width: "100%",
70
- display: "block",
71
- objectFit: "cover",
72
- aspectRatio: "1/1",
73
- height: "auto",
74
- overflow: "hidden",
75
- borderStyle: "solid",
76
- borderWidth: "1px",
77
- borderColor: i.palette.grey[300]
78
- }, src: s.data, alt: `Captcha image ${d + 1}` }), l("div", { style: {
79
- position: "absolute",
80
- top: 0,
81
- left: 0,
82
- bottom: 0,
83
- right: 0,
84
- height: "100%",
85
- width: "100%",
86
- display: "flex",
87
- alignItems: "center",
88
- justifyContent: "center",
89
- backgroundColor: "rgba(0,0,0,0.5)",
90
- visibility: e.includes(u) ? "visible" : "hidden"
91
- }, children: l("svg", { style: {
92
- backgroundColor: "transparent",
93
- display: "block",
94
- width: "35%",
95
- height: "35%",
96
- transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
97
- userSelect: "none",
98
- fill: "currentcolor"
99
- }, focusable: "false", color: "#fff", "aria-hidden": "true", viewBox: "0 0 24 24", "data-testid": "CheckIcon", "aria-label": "Check icon", children: l("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }) })] }) }, s.hash);
100
- }) });
101
- };
102
- function ye(r = {}) {
103
- return Object.keys(r).reduce((e, n) => ({ ...e, [`data-${n}`]: r[n] }), {});
104
- }
105
- function q({ general: r, dev: e }) {
106
- return {
107
- ...ye(r)
108
- };
109
- }
110
- const ve = {
111
- display: "inline-flex",
112
- alignItems: "center",
113
- justifyContent: "center",
114
- position: "relative",
115
- boxSizing: "border-box",
116
- outline: "0px",
117
- margin: "0px",
118
- cursor: "pointer",
119
- userSelect: "none",
120
- verticalAlign: "middle",
121
- appearance: void 0,
122
- textDecoration: "none",
123
- fontWeight: "500",
124
- fontSize: "0.875rem",
125
- lineHeight: "1.75",
126
- letterSpacing: "0.02857em",
127
- textTransform: "uppercase",
128
- minWidth: "64px",
129
- padding: "6px 16px",
130
- borderRadius: "4px",
131
- transition: "background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
132
- backgroundColor: "#ffffff"
133
- }, B = ({ themeColor: r, buttonType: e, text: n, onClick: o }) => {
134
- const t = m.useMemo(() => r === "light" ? M : D, [r]), [i, a] = m.useState(!1), s = m.useMemo(() => {
135
- const d = {
136
- ...ve,
137
- border: `1px solid ${t.palette.grey[500]}`,
138
- boxShadow: `0px 1px 3px 0px ${t.palette.grey[500]}`,
139
- fontFamily: t.font.fontFamily,
140
- width: "100%",
141
- color: i ? t.palette.primary.contrastText : t.palette.background.contrastText
142
- };
143
- return e === "cancel" ? {
144
- ...d,
145
- backgroundColor: i ? t.palette.grey[600] : "transparent"
146
- } : {
147
- ...d,
148
- backgroundColor: i ? t.palette.primary.main : t.palette.background.default
149
- };
150
- }, [e, i, t]);
151
- return l("button", { ...q({ dev: {} }), onMouseEnter: () => a(!0), onMouseLeave: () => a(!1), style: s, onClick: (d) => {
152
- d.preventDefault(), o();
153
- }, "aria-label": n, children: n });
154
- }, $ = ({ challenge: r, index: e, solutions: n, onSubmit: o, onCancel: t, onClick: i, onNext: a, onReload: s, themeColor: d }) => {
155
- const { t: u } = V(), C = r.captchas ? b(r.captchas, e) : null, p = n ? b(n, e) : [], A = m.useMemo(() => d === "light" ? M : D, [d]), k = `${A.spacing.unit * 2}px`, g = `${A.spacing.unit}px`;
156
- return l(m.Suspense, { fallback: l("div", { children: "Loading..." }), children: l("div", { style: {
157
- overflowX: "auto",
158
- overflowY: "auto",
159
- maxWidth: "500px",
160
- maxHeight: "100%",
161
- display: "flex",
162
- flexDirection: "column",
163
- border: "1px solid #dddddd",
164
- boxShadow: "rgba(255, 255, 255, 0.2) 0px 0px 4px",
165
- borderRadius: "4px",
166
- backgroundColor: A.palette.background.default,
167
- userSelect: "none",
168
- touchAction: "none",
169
- overscrollBehavior: "none"
170
- }, children: H("div", { style: {
171
- backgroundColor: A.palette.background.default,
172
- display: "flex",
173
- flexDirection: "column",
174
- minWidth: "300px",
175
- marginLeft: g,
176
- marginRight: g,
177
- justifyContent: "center"
178
- }, children: [l("div", { style: {
179
- display: "flex",
180
- alignItems: "center",
181
- width: "100%"
182
- }, children: l("div", { style: {
183
- backgroundColor: A.palette.primary.main,
184
- width: "100%",
185
- marginTop: g
186
- }, children: H("div", { style: {
187
- padding: `${A.spacing.half}px`,
188
- fontFamily: A.font.fontFamily
189
- }, children: [H("p", { style: {
190
- color: "#ffffff",
191
- fontWeight: 700,
192
- lineHeight: 1.5
193
- }, children: [u("WIDGET.SELECT_ALL"), ":", " ", l("span", { children: `${b(r.captchas, e).target} ` })] }), l("p", { style: {
194
- color: "#ffffff",
195
- fontWeight: 500,
196
- lineHeight: 0.8,
197
- fontSize: "0.8rem"
198
- }, children: u("WIDGET.IF_NONE_CLICK_NEXT") })] }) }) }), l("div", { ...q({ dev: {} }), style: { overflow: "hidden" }, children: C && l(Ae, { challenge: C, solution: p, onClick: i, themeColor: d }) }), l("div", { style: {
199
- display: "flex",
200
- alignItems: "center",
201
- justifyContent: "space-between",
202
- lineHeight: 1.75,
203
- padding: `${g} 0 ${k} 0`
204
- }, children: H("div", { style: {
205
- width: "100%",
206
- height: "100%",
207
- display: "flex",
208
- flexDirection: "row",
209
- flexWrap: "wrap",
210
- justifyContent: "space-between",
211
- gap: "10px"
212
- }, children: [l("div", { style: {
213
- position: "relative",
214
- flexGrow: 1,
215
- flexBasis: "calc(33.333% - 10px)"
216
- }, children: l(B, { themeColor: d, buttonType: "cancel", onClick: t, text: u("WIDGET.CANCEL"), "aria-label": u("WIDGET.CANCEL") }) }), l("div", { style: {
217
- position: "relative",
218
- flexGrow: 1,
219
- flexBasis: "calc(33.333% - 10px)"
220
- }, children: l(we, { themeColor: d, onReload: s }) }), l("div", { style: {
221
- position: "relative",
222
- flexGrow: 1,
223
- flexBasis: "calc(33.333% - 10px)"
224
- }, children: l(B, { themeColor: d, buttonType: "next", text: e < r.captchas.length - 1 ? u("WIDGET.NEXT") : u("WIDGET.SUBMIT"), onClick: e < r.captchas.length - 1 ? a : o, "aria-label": e < r.captchas.length - 1 ? u("WIDGET.NEXT") : u("WIDGET.SUBMIT"), "data-cy": "button-next" }) })] }) })] }) }) });
225
- };
226
- function Ee(r) {
227
- return W([
228
- r.captchaId,
229
- r.captchaContentId,
230
- [...r.solution].sort(),
231
- r.salt
232
- ]);
233
- }
234
- class z {
235
- constructor(e) {
236
- this.hash = e, this.parent = null;
237
- }
238
- }
239
- class Te {
240
- constructor() {
241
- this.leaves = [], this.layers = [];
242
- }
243
- getRoot() {
244
- if (this.root === void 0)
245
- throw new v("DATASET.MERKLE_ERROR", {
246
- context: {
247
- error: "root undefined",
248
- failedFuncName: this.getRoot.name
249
- }
250
- });
251
- return this.root;
252
- }
253
- build(e) {
254
- this.layers.length && (this.layers = []);
255
- const n = [];
256
- for (const o of e) {
257
- const t = new z(o);
258
- this.leaves.push(t), n.push(t.hash);
259
- }
260
- this.layers.push(n), this.root = this.buildMerkleTree(this.leaves)[0];
261
- }
262
- buildMerkleTree(e) {
263
- const n = e.length;
264
- if (n === 1)
265
- return e;
266
- const o = [];
267
- let t = 0;
268
- const i = [];
269
- for (; t < n; ) {
270
- const a = e[t];
271
- if (a === void 0)
272
- throw new v("DEVELOPER.GENERAL", {
273
- context: { error: "leftChild undefined" }
274
- });
275
- const s = t + 1 < n ? b(e, t + 1) : a, d = this.createParent(a, s);
276
- i.push(d.hash), o.push(d), t += 2;
277
- }
278
- return this.layers.push(i), this.buildMerkleTree(o);
279
- }
280
- createParent(e, n) {
281
- const o = new z(W([e.hash, n.hash]));
282
- return e.parent = o.hash, n.parent = o.hash, o;
283
- }
284
- proof(e) {
285
- const n = [];
286
- let o = 0;
287
- for (; o < this.layers.length - 1; ) {
288
- const i = this.layers[o];
289
- if (i === void 0)
290
- throw new v("DATASET.MERKLE_ERROR", {
291
- context: {
292
- error: "layer undefined",
293
- failedFuncName: this.proof.name,
294
- layerNum: o
295
- }
296
- });
297
- const a = i.indexOf(e);
298
- let s = a % 2 && a > 0 ? a - 1 : a + 1;
299
- s > i.length - 1 && (s = a);
300
- const d = [e], u = b(i, s);
301
- s > a ? d.push(u) : d.unshift(u), n.push([b(d, 0), b(d, 1)]), o += 1, e = W(d);
302
- }
303
- const t = b(this.layers, this.layers.length - 1);
304
- return [...n, [b(t, 0)]];
305
- }
306
- }
307
- class F {
308
- constructor(e, n, o, t, i) {
309
- this.userAccount = e, this.provider = n, this.providerApi = o, this._web2 = t, this.dappAccount = i;
310
- }
311
- get web2() {
312
- return this._web2;
313
- }
314
- async getCaptchaChallenge(e) {
315
- try {
316
- const n = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider, e);
317
- if (n[w.error])
318
- return n;
319
- for (const o of n.captchas)
320
- for (const t of o.items)
321
- t.data && (t.data = `https://${t.data.replace(/^http(s)*:\/\//, "")}`);
322
- return n;
323
- } catch (n) {
324
- throw new N("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
325
- context: { error: n }
326
- });
327
- }
328
- }
329
- async submitCaptchaSolution(e, n, o, t, i) {
330
- const a = new Te(), s = o.map((C) => Ee(C));
331
- if (a.build(s), !a.root)
332
- throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
333
- context: { error: "Merkle tree root is undefined" }
334
- });
335
- const d = a.root.hash;
336
- let u;
337
- try {
338
- u = await this.providerApi.submitCaptchaSolution(o, n, this.userAccount, t, i, e);
339
- } catch (C) {
340
- throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
341
- context: { error: C }
342
- });
343
- }
344
- return [u, d];
345
- }
346
- }
347
- const Ie = () => ({
348
- showModal: !1,
349
- loading: !1,
350
- index: 0,
351
- challenge: void 0,
352
- solutions: void 0,
353
- isHuman: !1,
354
- captchaApi: void 0,
355
- account: void 0
356
- });
357
- function Ne(r, e, n, o, t) {
358
- const i = ne(o), a = me(e, n), s = () => {
359
- const c = {
360
- userAccountAddress: "",
361
- ...r
362
- };
363
- return e.account && (c.userAccountAddress = e.account.account.address), X.parse(c);
364
- }, d = async () => {
365
- i.onOpen(), await U(async () => {
366
- var R;
367
- if (e.loading || e.isHuman)
368
- return;
369
- a({ loading: !0 }), a({
370
- attemptCount: e.attemptCount ? e.attemptCount + 1 : 1
371
- }), a({
372
- sessionId: t == null ? void 0 : t.sessionId
373
- });
374
- const c = s();
375
- a({ dappAccount: c.account.address }), await de(100);
376
- const f = await Y();
377
- let x = e.captchaApi;
378
- if (t != null && t.provider) {
379
- const I = t.provider.provider.url, y = await g(I);
380
- x = new F(f.account.address, t.provider, y, c.web2, c.account.address || ""), a({ captchaApi: x });
381
- } else {
382
- const I = await oe(s()), y = I.provider.url, E = await g(y);
383
- x = new F(f.account.address, I, E, c.web2, c.account.address || ""), a({ captchaApi: x });
384
- }
385
- const h = await (x == null ? void 0 : x.getCaptchaChallenge(e.sessionId));
386
- if (h.error)
387
- a({
388
- loading: !1,
389
- error: {
390
- message: h.error.message,
391
- key: h.error.key || "API.UNKNOWN_ERROR"
392
- }
393
- }), i.onError(new Error((R = h.error) == null ? void 0 : R.message));
394
- else {
395
- if (h.captchas.length <= 0)
396
- throw new _("DEVELOPER.PROVIDER_NO_CAPTCHA");
397
- const I = h.captchas.map((E) => E.timeLimitMs || c.captchas.image.challengeTimeout).reduce((E, L) => E + L), y = setTimeout(() => {
398
- i.onChallengeExpired(), a({ isHuman: !1, showModal: !1, loading: !1 });
399
- }, I);
400
- a({
401
- index: 0,
402
- solutions: h.captchas.map(() => []),
403
- challenge: h,
404
- showModal: !0,
405
- timeout: y,
406
- loading: !1
407
- });
408
- }
409
- }, d, P, e.attemptCount, 10);
410
- }, u = async () => {
411
- await U(async () => {
412
- if (T(), !e.challenge)
413
- throw new v("CAPTCHA.NO_CAPTCHA", {
414
- context: { error: "Cannot submit, no Captcha found in state" }
415
- });
416
- a({ showModal: !1 });
417
- const c = e.challenge, f = ge(), x = e.challenge.captchas.map((O, ee) => {
418
- const te = b(e.solutions, ee);
419
- return {
420
- captchaId: O.captchaId,
421
- captchaContentId: O.captchaContentId,
422
- salt: f,
423
- solution: te
424
- };
425
- }), h = G(), R = Q(h).signer;
426
- if (!b(c.captchas, 0).datasetId)
427
- throw new _("CAPTCHA.INVALID_CAPTCHA_ID", {
428
- context: { error: "No datasetId set for challenge" }
429
- });
430
- const y = e.captchaApi;
431
- if (!y)
432
- throw new v("CAPTCHA.INVALID_TOKEN", {
433
- context: { error: "No Captcha API found in state" }
434
- });
435
- if (!R || !R.signRaw)
436
- throw new N("GENERAL.CANT_FIND_KEYRINGPAIR", {
437
- context: {
438
- error: "Signer is not defined, cannot sign message to prove account ownership"
439
- }
440
- });
441
- const E = await R.signRaw({
442
- address: h.account.address,
443
- data: fe(c[w.timestamp]),
444
- type: "bytes"
445
- }), L = await y.submitCaptchaSolution(E.signature, c.requestHash, x, c.timestamp, c.signature.provider.requestHash), J = L[0].verified;
446
- if (a({
447
- submission: L,
448
- isHuman: J,
449
- loading: !1
450
- }), e.isHuman) {
451
- const O = y.provider.provider.url;
452
- i.onHuman(ce({
453
- [w.providerUrl]: O,
454
- [w.user]: h.account.address,
455
- [w.dapp]: Z(),
456
- [w.commitmentId]: le(L[1]),
457
- [w.timestamp]: c.timestamp,
458
- [w.signature]: {
459
- [w.provider]: {
460
- [w.requestHash]: c.signature.provider.requestHash
461
- },
462
- [w.user]: {
463
- [w.timestamp]: E.signature
464
- }
465
- }
466
- })), S();
467
- } else
468
- i.onFailed(), P(t == null ? void 0 : t.restart);
469
- }, d, P, e.attemptCount, 10);
470
- }, C = async () => {
471
- T(), P(t == null ? void 0 : t.restart), i.onClose();
472
- }, p = async () => {
473
- T(), i.onReload(), P(t == null ? void 0 : t.restart), t != null && t.restart || await d();
474
- }, A = (c) => {
475
- if (!e.challenge)
476
- throw new v("CAPTCHA.NO_CAPTCHA", {
477
- context: { error: "Cannot select, no Captcha found in state" }
478
- });
479
- if (e.index >= e.challenge.captchas.length || e.index < 0)
480
- throw new v("CAPTCHA.NO_CAPTCHA", {
481
- context: {
482
- error: "Cannot select, index is out of range for this Captcha"
483
- }
484
- });
485
- const f = e.index, x = e.solutions, h = b(x, f);
486
- h.includes(c) ? h.splice(h.indexOf(c), 1) : h.push(c), a({ solutions: x });
487
- }, k = () => {
488
- if (!e.challenge)
489
- throw new v("CAPTCHA.NO_CAPTCHA", {
490
- context: { error: "Cannot select, no Captcha found in state" }
491
- });
492
- if (e.index + 1 >= e.challenge.captchas.length)
493
- throw new v("CAPTCHA.NO_CAPTCHA", {
494
- context: {
495
- error: "Cannot select, index is out of range for this Captcha"
496
- }
497
- });
498
- a({ index: e.index + 1 });
499
- }, g = async (c) => {
500
- const f = s();
501
- if (!f.account.address)
502
- throw new N("GENERAL.SITE_KEY_MISSING");
503
- return new ae(c, f.account.address);
504
- }, T = () => {
505
- window.clearTimeout(Number(e.timeout)), a({ timeout: void 0 });
506
- }, S = () => {
507
- const c = r.captchas.image.solutionTimeout, f = setTimeout(() => {
508
- a({ isHuman: !1 }), i.onExpired();
509
- }, c);
510
- a({ successfullChallengeTimeout: f });
511
- }, P = (c) => {
512
- T(), a(Ie()), i.onReset(), c && c();
513
- }, Y = async () => {
514
- const c = s();
515
- if (!c.web2 && !c.userAccountAddress)
516
- throw new N("GENERAL.ACCOUNT_NOT_FOUND", {
517
- context: { error: "Account address has not been set for web3 mode" }
518
- });
519
- const x = await (async () => {
520
- const h = new (await re(c.web2))();
521
- return t ? t.userAccount : await h.getAccount(c);
522
- })();
523
- return a({ account: x }), G();
524
- }, G = () => {
525
- if (!e.account)
526
- throw new N("GENERAL.ACCOUNT_NOT_FOUND", {
527
- context: { error: "Account not loaded" }
528
- });
529
- return e.account;
530
- }, Z = () => {
531
- if (!e.dappAccount)
532
- throw new N("GENERAL.SITE_KEY_MISSING");
533
- return e.dappAccount;
534
- }, Q = (c) => {
535
- const f = c || G();
536
- if (!f.extension)
537
- throw new N("ACCOUNT.NO_POLKADOT_EXTENSION", {
538
- context: { error: "Extension not loaded" }
539
- });
540
- return f.extension;
541
- };
542
- return {
543
- start: d,
544
- cancel: C,
545
- submit: u,
546
- select: A,
547
- nextRound: k,
548
- reload: p
549
- };
550
- }
551
- const He = se`
552
- position: absolute;
553
- top: 50%;
554
- left: 50%;
555
- transform: translate(-50%, -50%);
556
- max-width: 500px;
557
- background-color: transparent;
558
- border: none;
559
- border-radius: 4px;
560
- z-index: 2147483647;
561
- align-self: center;
562
- box-shadow: rgba(0, 0, 0, 0.2) 0px 11px 15px -7px,
563
- rgba(0, 0, 0, 0.14) 0px 24px 38px 3px,
564
- rgba(0, 0, 0, 0.12) 0px 9px 46px 8px;
565
- box-sizing: border-box; /* Ensures border is part of width */
566
- /* iOS only */
567
- @supports (-webkit-touch-callout: none) {
568
- transform: translate(-50%, -100%);
569
- }
570
- `, j = ue.memo((r) => {
571
- const { show: e, children: n } = r, t = {
572
- position: "fixed",
573
- zIndex: 2147483646,
574
- inset: 0,
575
- display: e ? "flex" : "none",
576
- alignItems: "center",
577
- justifyContent: "center",
578
- minHeight: "100vh"
579
- };
580
- return pe.createPortal(l("div", { className: "prosopo-modalOuter", style: t, children: l("div", { className: "prosopo-modalInner", css: He, children: n }) }), document.body);
581
- }), K = "procaptcha:execute", Se = (r) => {
582
- var k;
583
- const { t: e, ready: n } = V(), o = X.parse(r.config), t = r.frictionlessState, i = r.i18n, a = r.callbacks || {}, [s, d] = xe(m.useState, m.useRef), [u, C] = m.useState(!1), p = Ne(o, s, d, a, t), A = r.config.theme === "light" ? M : D;
584
- return m.useEffect(() => {
585
- o.language && (i ? i.language !== o.language && i.changeLanguage(o.language).then((g) => g) : he().then((g) => {
586
- g.language !== o.language && g.changeLanguage(o.language).then((T) => T);
587
- }));
588
- }, [i, o.language]), m.useEffect(() => {
589
- s.error && (C(!1), s.error.key === "CAPTCHA.NO_SESSION_FOUND" && t && setTimeout(() => {
590
- t.restart();
591
- }, 3e3));
592
- }, [s.error, t]), m.useEffect(() => {
593
- const g = (T) => {
594
- if (d({
595
- showModal: !0
596
- }), !s.challenge && p.start)
597
- try {
598
- p.start();
599
- } catch (S) {
600
- console.error("Error starting verification:", S);
601
- }
602
- };
603
- return document.addEventListener(K, g), () => {
604
- document.removeEventListener(K, g);
605
- };
606
- }, [p, s.challenge, d]), o.mode === "invisible" ? l(j, { show: s.showModal, children: s.challenge ? l($, { challenge: s.challenge, index: s.index, solutions: s.solutions, onSubmit: p.submit, onCancel: p.cancel, onClick: p.select, onNext: p.nextRound, onReload: p.reload, themeColor: o.theme ?? "light" }) : null }) : H("div", { className: "image-captcha", children: [l(j, { show: s.showModal, children: s.challenge ? l($, { challenge: s.challenge, index: s.index, solutions: s.solutions, onSubmit: p.submit, onCancel: p.cancel, onClick: p.select, onNext: p.nextRound, onReload: p.reload, themeColor: o.theme ?? "light" }) : l("div", { children: "No challenge set." }) }), l(ie, { theme: A, onChange: async () => {
607
- u || (C(!0), await p.start(), C(!1));
608
- }, checked: s.isHuman, labelText: n ? e("WIDGET.I_AM_HUMAN") : "", error: (k = s.error) == null ? void 0 : k.message, "aria-label": "human checkbox", loading: u })] });
609
- };
610
- export {
611
- Se as default
612
- };