@prosopo/procaptcha-bundle 1.0.2 → 2.0.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.
@@ -0,0 +1,783 @@
1
+ import { r as m, z, a as C, e as he, A as v, P as se, l as U, d as $, j as d, b as A, R as fe, C as ge, W as me, c as be, f as xe, g as ye, h as Ce, i as we, L as Ae, k as ve, m as Te, n as Ie } from "./index-jr-ls0GZ.js";
2
+ import { u as Ee, h as Se, _ as Ne, a as Pe, b as ke, I as Oe, R as Re, g as De, c as Le, d as He, i as _e, e as J, P as T, f as S, j as _, s as ce, k as Me, l as We, m as Ge, n as je, r as ze, o as Be, E as Ue, p as $e, q as Fe, t as Ke, C as Ve } from "./utils-CHbJaqXT.js";
3
+ function Xe(t) {
4
+ return Ee(Se(t));
5
+ }
6
+ function Ye() {
7
+ if (console && console.warn) {
8
+ for (var t, e = arguments.length, n = new Array(e), o = 0; o < e; o++)
9
+ n[o] = arguments[o];
10
+ typeof n[0] == "string" && (n[0] = "react-i18next:: ".concat(n[0])), (t = console).warn.apply(t, n);
11
+ }
12
+ }
13
+ var te = {};
14
+ function q() {
15
+ for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++)
16
+ e[n] = arguments[n];
17
+ typeof e[0] == "string" && te[e[0]] || (typeof e[0] == "string" && (te[e[0]] = /* @__PURE__ */ new Date()), Ye.apply(void 0, e));
18
+ }
19
+ function ne(t, e, n) {
20
+ t.loadNamespaces(e, function() {
21
+ if (t.isInitialized)
22
+ n();
23
+ else {
24
+ var o = function a() {
25
+ setTimeout(function() {
26
+ t.off("initialized", a);
27
+ }, 0), n();
28
+ };
29
+ t.on("initialized", o);
30
+ }
31
+ });
32
+ }
33
+ function Je(t, e) {
34
+ var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, o = e.languages[0], a = e.options ? e.options.fallbackLng : !1, r = e.languages[e.languages.length - 1];
35
+ if (o.toLowerCase() === "cimode") return !0;
36
+ var i = function(s, h) {
37
+ var b = e.services.backendConnector.state["".concat(s, "|").concat(h)];
38
+ return b === -1 || b === 2;
39
+ };
40
+ return n.bindI18n && n.bindI18n.indexOf("languageChanging") > -1 && e.services.backendConnector.backend && e.isLanguageChangingTo && !i(e.isLanguageChangingTo, t) ? !1 : !!(e.hasResourceBundle(o, t) || !e.services.backendConnector.backend || e.options.resources && !e.options.partialBundledLanguages || i(o, t) && (!a || i(r, t)));
41
+ }
42
+ function qe(t, e) {
43
+ var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
44
+ if (!e.languages || !e.languages.length)
45
+ return q("i18n.languages were undefined or empty", e.languages), !0;
46
+ var o = e.options.ignoreJSONStructure !== void 0;
47
+ return o ? e.hasLoadedNamespace(t, {
48
+ precheck: function(r, i) {
49
+ if (n.bindI18n && n.bindI18n.indexOf("languageChanging") > -1 && r.services.backendConnector.backend && r.isLanguageChangingTo && !i(r.isLanguageChangingTo, t)) return !1;
50
+ }
51
+ }) : Je(t, e, n);
52
+ }
53
+ function Ze(t, e) {
54
+ var n = t == null ? null : typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"];
55
+ if (n != null) {
56
+ var o, a, r, i, l = [], s = !0, h = !1;
57
+ try {
58
+ if (r = (n = n.call(t)).next, e !== 0) for (; !(s = (o = r.call(n)).done) && (l.push(o.value), l.length !== e); s = !0) ;
59
+ } catch (b) {
60
+ h = !0, a = b;
61
+ } finally {
62
+ try {
63
+ if (!s && n.return != null && (i = n.return(), Object(i) !== i)) return;
64
+ } finally {
65
+ if (h) throw a;
66
+ }
67
+ }
68
+ return l;
69
+ }
70
+ }
71
+ function Qe(t, e) {
72
+ return Ne(t) || Ze(t, e) || Pe(t, e) || ke();
73
+ }
74
+ function oe(t, e) {
75
+ var n = Object.keys(t);
76
+ if (Object.getOwnPropertySymbols) {
77
+ var o = Object.getOwnPropertySymbols(t);
78
+ e && (o = o.filter(function(a) {
79
+ return Object.getOwnPropertyDescriptor(t, a).enumerable;
80
+ })), n.push.apply(n, o);
81
+ }
82
+ return n;
83
+ }
84
+ function V(t) {
85
+ for (var e = 1; e < arguments.length; e++) {
86
+ var n = arguments[e] != null ? arguments[e] : {};
87
+ e % 2 ? oe(Object(n), !0).forEach(function(o) {
88
+ Le(t, o, n[o]);
89
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : oe(Object(n)).forEach(function(o) {
90
+ Object.defineProperty(t, o, Object.getOwnPropertyDescriptor(n, o));
91
+ });
92
+ }
93
+ return t;
94
+ }
95
+ var et = function(e, n) {
96
+ var o = m.useRef();
97
+ return m.useEffect(function() {
98
+ o.current = e;
99
+ }, [e, n]), o.current;
100
+ };
101
+ function tt(t) {
102
+ var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, n = e.i18n, o = m.useContext(Oe) || {}, a = o.i18n, r = n || a || He();
103
+ if (r && !r.reportNamespaces && (r.reportNamespaces = new Re()), !r) {
104
+ q("You will need to pass in an i18next instance by using initReactI18next");
105
+ var i = function(u) {
106
+ return Array.isArray(u) ? u[u.length - 1] : u;
107
+ }, l = [i, {}, !1];
108
+ return l.t = i, l.i18n = {}, l.ready = !1, l;
109
+ }
110
+ r.options.react && r.options.react.wait !== void 0 && q("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
111
+ var s = V(V(V({}, De()), r.options.react), e), h = s.useSuspense, b = s.keyPrefix, p = t;
112
+ p = typeof p == "string" ? [p] : p || ["translation"], r.reportNamespaces.addUsedNamespaces && r.reportNamespaces.addUsedNamespaces(p);
113
+ var f = (r.isInitialized || r.initializedStoreOnce) && p.every(function(c) {
114
+ return qe(c, r, s);
115
+ });
116
+ function y() {
117
+ return r.getFixedT(null, s.nsMode === "fallback" ? p : p[0], b);
118
+ }
119
+ var w = m.useState(y), O = Qe(w, 2), M = O[0], N = O[1], L = p.join(), R = et(L), I = m.useRef(!0);
120
+ m.useEffect(function() {
121
+ var c = s.bindI18n, u = s.bindI18nStore;
122
+ I.current = !0, !f && !h && ne(r, p, function() {
123
+ I.current && N(y);
124
+ }), f && R && R !== L && I.current && N(y);
125
+ function g() {
126
+ I.current && N(y);
127
+ }
128
+ return c && r && r.on(c, g), u && r && r.store.on(u, g), function() {
129
+ I.current = !1, c && r && c.split(" ").forEach(function(x) {
130
+ return r.off(x, g);
131
+ }), u && r && u.split(" ").forEach(function(x) {
132
+ return r.store.off(x, g);
133
+ });
134
+ };
135
+ }, [r, L]);
136
+ var W = m.useRef(!0);
137
+ m.useEffect(function() {
138
+ I.current && !W.current && N(y), W.current = !1;
139
+ }, [r, b]);
140
+ var P = [M, r, f];
141
+ if (P.t = M, P.i18n = r, P.ready = f, f || !f && !h) return P;
142
+ throw new Promise(function(c) {
143
+ ne(r, p, function() {
144
+ c();
145
+ });
146
+ });
147
+ }
148
+ function nt(t) {
149
+ return tt("translation", { i18n: _e, ...t });
150
+ }
151
+ const ot = (t) => Array.isArray(t) && t !== null, B = new Array(256), le = new Array(256 * 256);
152
+ for (let t = 0; t < 256; t++)
153
+ B[t] = t.toString(16).padStart(2, "0");
154
+ for (let t = 0; t < 256; t++) {
155
+ const e = t << 8;
156
+ for (let n = 0; n < 256; n++)
157
+ le[e | n] = B[t] + B[n];
158
+ }
159
+ function X(t, e) {
160
+ const n = t.length % 2 | 0, o = t.length - n | 0;
161
+ for (let a = 0; a < o; a += 2)
162
+ e += le[t[a] << 8 | t[a + 1]];
163
+ return n && (e += B[t[o] | 0]), e;
164
+ }
165
+ function rt(t, e = -1, n = !0) {
166
+ const o = n ? "0x" : "";
167
+ if (!(t != null && t.length))
168
+ return o;
169
+ if (e > 0) {
170
+ const a = Math.ceil(e / 8);
171
+ if (t.length > a)
172
+ return `${X(t.subarray(0, a / 2), o)}…${X(t.subarray(t.length - a / 2), "")}`;
173
+ }
174
+ return X(t, o);
175
+ }
176
+ const at = (t) => ot(t) ? rt(new Uint8Array(t)) : t.toString(), de = z.object({
177
+ account: z.string().optional(),
178
+ blockNumber: z.number().optional(),
179
+ providerUrl: z.string().optional()
180
+ });
181
+ function it(t) {
182
+ return J([
183
+ t.captchaId,
184
+ t.captchaContentId,
185
+ [...t.solution].sort(),
186
+ t.salt
187
+ ]);
188
+ }
189
+ class re {
190
+ constructor(e) {
191
+ this.hash = e, this.parent = null;
192
+ }
193
+ }
194
+ class st {
195
+ constructor() {
196
+ this.leaves = [], this.layers = [];
197
+ }
198
+ getRoot() {
199
+ if (this.root === void 0)
200
+ throw new T("DATASET.MERKLE_ERROR", {
201
+ context: {
202
+ error: "root undefined",
203
+ failedFuncName: this.getRoot.name
204
+ }
205
+ });
206
+ return this.root;
207
+ }
208
+ build(e) {
209
+ this.layers.length && (this.layers = []);
210
+ const n = [];
211
+ for (const o of e) {
212
+ const a = new re(o);
213
+ this.leaves.push(a), n.push(a.hash);
214
+ }
215
+ this.layers.push(n), this.root = this.buildMerkleTree(this.leaves)[0];
216
+ }
217
+ buildMerkleTree(e) {
218
+ const n = e.length;
219
+ if (n === 1)
220
+ return e;
221
+ const o = [];
222
+ let a = 0;
223
+ const r = [];
224
+ for (; a < n; ) {
225
+ const i = e[a];
226
+ if (i === void 0)
227
+ throw new T("DEVELOPER.GENERAL", {
228
+ context: { error: "leftChild undefined" }
229
+ });
230
+ const l = a + 1 < n ? C(e, a + 1) : i, s = this.createParent(i, l);
231
+ r.push(s.hash), o.push(s), a += 2;
232
+ }
233
+ return this.layers.push(r), this.buildMerkleTree(o);
234
+ }
235
+ createParent(e, n) {
236
+ const o = new re(J([e.hash, n.hash]));
237
+ return e.parent = o.hash, n.parent = o.hash, o;
238
+ }
239
+ proof(e) {
240
+ const n = [];
241
+ let o = 0;
242
+ for (; o < this.layers.length - 1; ) {
243
+ const r = this.layers[o];
244
+ if (r === void 0)
245
+ throw new T("DATASET.MERKLE_ERROR", {
246
+ context: {
247
+ error: "layer undefined",
248
+ failedFuncName: this.proof.name,
249
+ layerNum: o
250
+ }
251
+ });
252
+ const i = r.indexOf(e);
253
+ let l = i % 2 && i > 0 ? i - 1 : i + 1;
254
+ l > r.length - 1 && (l = i);
255
+ const s = [e], h = C(r, l);
256
+ l > i ? s.push(h) : s.unshift(h), n.push([C(s, 0), C(s, 1)]), o += 1, e = J(s);
257
+ }
258
+ const a = C(this.layers, this.layers.length - 1);
259
+ return [...n, [C(a, 0)]];
260
+ }
261
+ }
262
+ class ct {
263
+ constructor(e, n, o, a, r, i) {
264
+ this.userAccount = e, this.contract = n, this.provider = o, this.providerApi = a, this._web2 = r, this.dappAccount = i;
265
+ }
266
+ get web2() {
267
+ return this._web2;
268
+ }
269
+ async getCaptchaChallenge() {
270
+ try {
271
+ const e = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
272
+ for (const n of e.captchas)
273
+ for (const o of n.items)
274
+ o.data && (o.data = o.data.replace(/^http(s)*:\/\//, "//"));
275
+ return e;
276
+ } catch (e) {
277
+ throw new S("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
278
+ context: { error: e }
279
+ });
280
+ }
281
+ }
282
+ async submitCaptchaSolution(e, n, o, a, r, i) {
283
+ const l = new st(), s = o.map((w) => it(w));
284
+ if (l.build(s), !l.root)
285
+ throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
286
+ context: { error: "Merkle tree root is undefined" }
287
+ });
288
+ const h = l.root.hash, b = void 0;
289
+ let p;
290
+ if (!e || !e.signRaw)
291
+ throw new S("GENERAL.CANT_FIND_KEYRINGPAIR", {
292
+ context: {
293
+ error: "Signer is not defined, cannot sign message to prove account ownership"
294
+ }
295
+ });
296
+ let f;
297
+ p = (await e.signRaw({
298
+ address: this.userAccount,
299
+ data: ce(n),
300
+ type: "bytes"
301
+ })).signature;
302
+ try {
303
+ f = await this.providerApi.submitCaptchaSolution(o, n, this.userAccount, a, r, i, p);
304
+ } catch (w) {
305
+ throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
306
+ context: { error: w }
307
+ });
308
+ }
309
+ return [f, h, b];
310
+ }
311
+ }
312
+ const ue = "@prosopo/procaptcha";
313
+ function Q() {
314
+ return de.parse(JSON.parse(Xe(localStorage.getItem(ue) || "0x7b7d")));
315
+ }
316
+ function pe(t) {
317
+ localStorage.setItem(ue, ce(JSON.stringify(de.parse(t))));
318
+ }
319
+ function lt(t) {
320
+ pe({ ...Q(), account: t });
321
+ }
322
+ function dt() {
323
+ return Q().account || null;
324
+ }
325
+ const Y = {
326
+ setAccount: lt,
327
+ getAccount: dt,
328
+ setProcaptchaStorage: pe,
329
+ getProcaptchaStorage: Q
330
+ }, ut = () => ({
331
+ showModal: !1,
332
+ loading: !1,
333
+ index: 0,
334
+ challenge: void 0,
335
+ solutions: void 0,
336
+ isHuman: !1,
337
+ captchaApi: void 0,
338
+ account: void 0
339
+ }), ae = (t) => {
340
+ const e = t.networks[t.defaultNetwork];
341
+ if (!e)
342
+ throw new S("DEVELOPER.NETWORK_NOT_FOUND", {
343
+ context: {
344
+ error: `No network found for environment ${t.defaultEnvironment}`
345
+ }
346
+ });
347
+ return e;
348
+ }, pt = (t) => {
349
+ const e = (a, r) => Math.floor(Math.random() * (r - a + 1) + a), n = Fe(t.defaultEnvironment), o = C(n, e(0, n.length - 1));
350
+ return {
351
+ providerAccount: o.address,
352
+ provider: {
353
+ url: o.url,
354
+ datasetId: o.datasetId,
355
+ datasetIdContent: o.datasetIdContent
356
+ },
357
+ blockNumber: 0
358
+ };
359
+ };
360
+ function ht(t, e, n, o) {
361
+ const a = Me(n, e, o), r = (c) => {
362
+ const u = c instanceof Error ? c : new Error(String(c));
363
+ a.onError(u);
364
+ }, i = We(e, n), l = () => {
365
+ const c = {
366
+ userAccountAddress: "",
367
+ ...t
368
+ };
369
+ return e.account && (c.userAccountAddress = e.account.account.address), se.parse(c);
370
+ }, s = async (c) => {
371
+ try {
372
+ await c();
373
+ } catch (u) {
374
+ console.error(u), r(u), i({ isHuman: !1, showModal: !1, loading: !1 });
375
+ }
376
+ }, h = async () => {
377
+ a.onOpen(), await s(async () => {
378
+ if (e.loading || e.isHuman)
379
+ return;
380
+ await Ge(), N(), i({ loading: !0 });
381
+ const c = l();
382
+ i({ dappAccount: c.account.address }), await je(100);
383
+ const u = await L(), g = ae(c).contract.address, x = pt(l()), G = x.blockNumber, F = x.provider.url, ee = await w(F), D = new ct(u.account.address, g, x, ee, c.web2, c.account.address || "");
384
+ i({ captchaApi: D });
385
+ const E = await D.getCaptchaChallenge();
386
+ if (E.captchas.length <= 0)
387
+ throw new _("DEVELOPER.PROVIDER_NO_CAPTCHA");
388
+ const j = E.captchas.map((H) => H.timeLimitMs || c.captchas.image.challengeTimeout).reduce((H, K) => H + K), k = setTimeout(() => {
389
+ a.onChallengeExpired(), i({ isHuman: !1, showModal: !1, loading: !1 });
390
+ }, j);
391
+ i({
392
+ index: 0,
393
+ solutions: E.captchas.map(() => []),
394
+ challenge: E,
395
+ showModal: !0,
396
+ timeout: k,
397
+ blockNumber: G
398
+ });
399
+ });
400
+ }, b = async () => {
401
+ await s(async () => {
402
+ if (O(), !e.challenge)
403
+ throw new T("CAPTCHA.NO_CAPTCHA", {
404
+ context: { error: "Cannot submit, no Captcha found in state" }
405
+ });
406
+ i({ showModal: !1 });
407
+ const c = e.challenge, u = ze(), g = e.challenge.captchas.map((k, H) => {
408
+ const K = C(e.solutions, H);
409
+ return {
410
+ captchaId: k.captchaId,
411
+ captchaContentId: k.captchaContentId,
412
+ salt: u,
413
+ solution: K
414
+ };
415
+ }), x = R(), G = W(), F = P(x).signer;
416
+ if (!C(c.captchas, 0).datasetId)
417
+ throw new _("CAPTCHA.INVALID_CAPTCHA_ID", {
418
+ context: { error: "No datasetId set for challenge" }
419
+ });
420
+ const D = e.captchaApi;
421
+ if (!D)
422
+ throw new T("CAPTCHA.INVALID_TOKEN", {
423
+ context: { error: "No Captcha API found in state" }
424
+ });
425
+ const E = await D.submitCaptchaSolution(F, c.requestHash, g, u, c.timestamp, c.signature.provider.timestamp), j = E[0].verified;
426
+ if (j || a.onFailed(), i({
427
+ submission: E,
428
+ isHuman: j,
429
+ loading: !1
430
+ }), e.isHuman) {
431
+ const k = D.provider.provider.url;
432
+ Y.setProcaptchaStorage({
433
+ ...Y.getProcaptchaStorage(),
434
+ providerUrl: k,
435
+ blockNumber: G
436
+ }), a.onHuman(he({
437
+ [v.providerUrl]: k,
438
+ [v.user]: x.account.address,
439
+ [v.dapp]: I(),
440
+ [v.commitmentId]: at(E[1]),
441
+ [v.blockNumber]: G,
442
+ [v.timestamp]: c.timestamp,
443
+ [v.signature]: {
444
+ [v.provider]: {
445
+ [v.timestamp]: c.signature.provider.timestamp
446
+ }
447
+ }
448
+ })), M();
449
+ }
450
+ });
451
+ }, p = async () => {
452
+ O(), N(), a.onClose();
453
+ }, f = (c) => {
454
+ if (!e.challenge)
455
+ throw new T("CAPTCHA.NO_CAPTCHA", {
456
+ context: { error: "Cannot select, no Captcha found in state" }
457
+ });
458
+ if (e.index >= e.challenge.captchas.length || e.index < 0)
459
+ throw new T("CAPTCHA.NO_CAPTCHA", {
460
+ context: {
461
+ error: "Cannot select, index is out of range for this Captcha"
462
+ }
463
+ });
464
+ const u = e.index, g = e.solutions, x = C(g, u);
465
+ x.includes(c) ? x.splice(x.indexOf(c), 1) : x.push(c), i({ solutions: g });
466
+ }, y = () => {
467
+ if (!e.challenge)
468
+ throw new T("CAPTCHA.NO_CAPTCHA", {
469
+ context: { error: "Cannot select, no Captcha found in state" }
470
+ });
471
+ if (e.index + 1 >= e.challenge.captchas.length)
472
+ throw new T("CAPTCHA.NO_CAPTCHA", {
473
+ context: {
474
+ error: "Cannot select, index is out of range for this Captcha"
475
+ }
476
+ });
477
+ i({ index: e.index + 1 });
478
+ }, w = async (c) => {
479
+ const u = l(), g = ae(u);
480
+ if (!u.account.address)
481
+ throw new S("GENERAL.SITE_KEY_MISSING");
482
+ return new Be(g, c, u.account.address);
483
+ }, O = () => {
484
+ window.clearTimeout(e.timeout), i({ timeout: void 0 });
485
+ }, M = () => {
486
+ const c = t.captchas.image.solutionTimeout, u = setTimeout(() => {
487
+ i({ isHuman: !1 }), a.onExpired();
488
+ }, c);
489
+ i({ successfullChallengeTimeout: u });
490
+ }, N = () => {
491
+ O(), i(ut());
492
+ }, L = async () => {
493
+ const c = l();
494
+ if (!c.web2 && !c.userAccountAddress)
495
+ throw new S("GENERAL.ACCOUNT_NOT_FOUND", {
496
+ context: { error: "Account address has not been set for web3 mode" }
497
+ });
498
+ const g = await (c.web2 ? new Ue() : new $e()).getAccount(c);
499
+ return Y.setAccount(g.account.address), i({ account: g }), R();
500
+ }, R = () => {
501
+ if (!e.account)
502
+ throw new S("GENERAL.ACCOUNT_NOT_FOUND", {
503
+ context: { error: "Account not loaded" }
504
+ });
505
+ return e.account;
506
+ }, I = () => {
507
+ if (!e.dappAccount)
508
+ throw new S("GENERAL.SITE_KEY_MISSING");
509
+ return e.dappAccount;
510
+ }, W = () => e.blockNumber || 0, P = (c) => {
511
+ const u = c || R();
512
+ if (!u.extension)
513
+ throw new S("ACCOUNT.NO_POLKADOT_EXTENSION", {
514
+ context: { error: "Extension not loaded" }
515
+ });
516
+ return u.extension;
517
+ };
518
+ return {
519
+ start: h,
520
+ cancel: p,
521
+ submit: b,
522
+ select: f,
523
+ nextRound: y
524
+ };
525
+ }
526
+ const ft = (t) => {
527
+ if (!t.hash)
528
+ throw new _("CAPTCHA.MISSING_ITEM_HASH", {
529
+ context: { item: t }
530
+ });
531
+ return t.hash;
532
+ }, gt = ({ challenge: t, solution: e, onClick: n, themeColor: o }) => {
533
+ const a = t.items, r = m.useMemo(() => o === "light" ? U : $, [o]), i = "ontouchstart" in window, l = `${r.spacing.unit}px`, s = `${r.spacing.half}px`, h = {
534
+ 0: {
535
+ paddingLeft: 0,
536
+ paddingRight: s,
537
+ paddingTop: s,
538
+ paddingBottom: s
539
+ },
540
+ 1: {
541
+ paddingLeft: s,
542
+ paddingRight: s,
543
+ paddingTop: s,
544
+ paddingBottom: s
545
+ },
546
+ 2: {
547
+ paddingLeft: s,
548
+ paddingRight: 0,
549
+ paddingTop: s,
550
+ paddingBottom: s
551
+ }
552
+ }, b = {
553
+ 0: { paddingTop: l },
554
+ 2: { paddingBottom: l }
555
+ };
556
+ return d("div", { style: {
557
+ paddingRight: 0.5,
558
+ paddingBottom: 0.5,
559
+ width: "100%",
560
+ height: "100%",
561
+ display: "flex",
562
+ flexDirection: "row",
563
+ flexWrap: "wrap"
564
+ }, children: a.map((p, f) => {
565
+ const y = ft(p), w = {
566
+ ...h[f % 3],
567
+ ...b[Math.floor(f / 3)],
568
+ flexGrow: 1,
569
+ flexBasis: "33.3333%",
570
+ boxSizing: "border-box"
571
+ };
572
+ return d("div", { style: w, children: A("div", { style: {
573
+ cursor: "pointer",
574
+ height: "100%",
575
+ width: "100%",
576
+ border: 1,
577
+ borderStyle: "solid",
578
+ borderColor: r.palette.grey[300]
579
+ }, onClick: i ? void 0 : () => n(y), onTouchStart: i ? () => n(y) : void 0, children: [d("div", { children: d("img", { style: {
580
+ width: "100%",
581
+ backgroundColor: r.palette.grey[300],
582
+ opacity: e.includes(y) && i ? "50%" : "100%",
583
+ display: "block",
584
+ objectFit: "contain",
585
+ aspectRatio: "1/1",
586
+ height: "auto"
587
+ }, src: p.data, alt: `Captcha image ${f + 1}` }) }), d("div", { style: {
588
+ position: "relative",
589
+ width: "100%",
590
+ height: "100%",
591
+ top: "-100%",
592
+ visibility: e.includes(y) ? "visible" : "hidden",
593
+ transition: "opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
594
+ opacity: 1
595
+ }, children: d("div", { style: {
596
+ position: "absolute",
597
+ top: 0,
598
+ left: 0,
599
+ bottom: 0,
600
+ right: 0,
601
+ height: "100%",
602
+ width: "100%",
603
+ display: "flex",
604
+ alignItems: "center",
605
+ justifyContent: "center",
606
+ backgroundColor: "rgba(0,0,0,0.5)"
607
+ }, children: d("svg", { style: {
608
+ backgroundColor: "transparent",
609
+ display: "block",
610
+ width: "35%",
611
+ height: "35%",
612
+ transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
613
+ userSelect: "none",
614
+ fill: "currentcolor"
615
+ }, focusable: "false", color: "#fff", "aria-hidden": "true", viewBox: "0 0 24 24", "data-testid": "CheckIcon", "aria-label": "Check icon", children: d("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }) }) })] }) }, p.hash);
616
+ }) });
617
+ };
618
+ function mt(t = {}) {
619
+ return Object.keys(t).reduce((e, n) => ({ ...e, [`data-${n}`]: t[n] }), {});
620
+ }
621
+ function Z({ general: t, dev: e }) {
622
+ return {
623
+ ...mt(t)
624
+ };
625
+ }
626
+ const bt = {
627
+ display: "inline-flex",
628
+ alignItems: "center",
629
+ justifyContent: "center",
630
+ position: "relative",
631
+ boxSizing: "border-box",
632
+ outline: "0px",
633
+ border: "0px",
634
+ margin: "0px",
635
+ cursor: "pointer",
636
+ userSelect: "none",
637
+ verticalAlign: "middle",
638
+ appearance: void 0,
639
+ textDecoration: "none",
640
+ fontWeight: "500",
641
+ fontSize: "0.875rem",
642
+ lineHeight: "1.75",
643
+ letterSpacing: "0.02857em",
644
+ textTransform: "uppercase",
645
+ minWidth: "64px",
646
+ padding: "6px 16px",
647
+ borderRadius: "4px",
648
+ 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",
649
+ color: "rgb(0, 0, 0)",
650
+ backgroundColor: "#ffffff",
651
+ boxShadow: "rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px"
652
+ }, ie = ({ themeColor: t, buttonType: e, text: n, onClick: o }) => {
653
+ const a = m.useMemo(() => t === "light" ? U : $, [t]), [r, i] = m.useState(!1), l = m.useMemo(() => {
654
+ const s = {
655
+ ...bt,
656
+ color: r ? a.palette.primary.contrastText : a.palette.background.contrastText
657
+ };
658
+ return e === "cancel" ? {
659
+ ...s,
660
+ backgroundColor: r ? a.palette.grey[600] : "transparent"
661
+ } : {
662
+ ...s,
663
+ backgroundColor: r ? a.palette.primary.main : a.palette.background.default
664
+ };
665
+ }, [e, r, a]);
666
+ return d("button", { ...Z({ dev: { cy: `button-${e}` } }), onMouseEnter: () => i(!0), onMouseLeave: () => i(!1), style: l, onClick: (s) => {
667
+ s.preventDefault(), o();
668
+ }, "aria-label": n, children: n });
669
+ }, xt = ({ challenge: t, index: e, solutions: n, onSubmit: o, onCancel: a, onClick: r, onNext: i, themeColor: l }) => {
670
+ const { t: s } = nt(), h = t.captchas ? C(t.captchas, e) : null, b = n ? C(n, e) : [], p = m.useMemo(() => l === "light" ? U : $, [l]);
671
+ return d(m.Suspense, { fallback: d("div", { children: "Loading..." }), children: d("div", { style: {
672
+ overflowX: "auto",
673
+ overflowY: "auto",
674
+ width: "100%",
675
+ maxWidth: "500px",
676
+ maxHeight: "100%",
677
+ display: "flex",
678
+ flexDirection: "column",
679
+ border: "1px solid #dddddd",
680
+ boxShadow: "rgba(255, 255, 255, 0.2) 0px 0px 4px",
681
+ borderRadius: "4px",
682
+ padding: `${p.spacing.unit}px`,
683
+ backgroundColor: p.palette.background.default
684
+ }, children: A("div", { style: {
685
+ backgroundColor: p.palette.background.default,
686
+ display: "flex",
687
+ flexDirection: "column",
688
+ minWidth: "300px"
689
+ }, children: [d("div", { style: {
690
+ display: "flex",
691
+ alignItems: "center",
692
+ width: "100%"
693
+ }, children: d("div", { style: {
694
+ backgroundColor: p.palette.primary.main,
695
+ width: "100%"
696
+ }, children: A("div", { style: {
697
+ paddingLeft: `${p.spacing.half}px`,
698
+ paddingRight: `${p.spacing.half}px`
699
+ }, children: [A("p", { style: {
700
+ color: "#ffffff",
701
+ fontWeight: 700,
702
+ lineHeight: 1.5
703
+ }, children: [s("WIDGET.SELECT_ALL"), ":", " ", d("span", { style: { textTransform: "capitalize" }, children: `${C(t.captchas, e).target}` })] }), d("p", { style: {
704
+ color: "#ffffff",
705
+ fontWeight: 500,
706
+ lineHeight: 0.8,
707
+ fontSize: "0.8rem"
708
+ }, children: s("WIDGET.IF_NONE_CLICK_NEXT") })] }) }) }), d("div", { ...Z({ dev: { cy: `captcha-${e}` } }), children: h && d(gt, { challenge: h, solution: b, onClick: r, themeColor: l }) }), d("div", { style: {
709
+ display: "flex",
710
+ alignItems: "center",
711
+ justifyContent: "center",
712
+ width: "100%"
713
+ }, ...Z({ dev: { cy: "dots-captcha" } }) }), d("div", { style: {
714
+ padding: `0 ${p.spacing}px`,
715
+ display: "flex",
716
+ width: "100%"
717
+ } }), A("div", { style: {
718
+ padding: `0 ${p.spacing}px`,
719
+ display: "flex",
720
+ alignItems: "center",
721
+ justifyContent: "space-between",
722
+ lineHeight: 1.75
723
+ }, children: [d(ie, { themeColor: l, buttonType: "cancel", onClick: a, text: s("WIDGET.CANCEL"), "aria-label": s("WIDGET.CANCEL") }), d(ie, { themeColor: l, buttonType: "next", text: e < t.captchas.length - 1 ? s("WIDGET.NEXT") : s("WIDGET.SUBMIT"), onClick: e < t.captchas.length - 1 ? i : o, "aria-label": e < t.captchas.length - 1 ? s("WIDGET.NEXT") : s("WIDGET.SUBMIT"), "data-cy": "button-next" })] })] }) }) });
724
+ }, yt = fe.memo((t, e) => {
725
+ const { show: n, children: o } = t, r = {
726
+ position: "fixed",
727
+ zIndex: 2147483646,
728
+ inset: 0,
729
+ display: n ? "block" : "none"
730
+ }, i = {
731
+ position: "fixed",
732
+ display: "flex",
733
+ alignItems: "center",
734
+ justifyContent: "center",
735
+ right: 0,
736
+ bottom: 0,
737
+ top: 0,
738
+ left: 0,
739
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
740
+ zIndex: -1
741
+ }, l = {
742
+ position: "absolute",
743
+ top: "50%",
744
+ left: "50%",
745
+ transform: "translate(-50%, -50%)",
746
+ width: "400px",
747
+ backgroundColor: "transparent",
748
+ border: "none",
749
+ boxShadow: "rgba(0, 0, 0, 0.2) 0px 11px 15px -7px, rgba(0, 0, 0, 0.14) 0px 24px 38px 3px, rgba(0, 0, 0, 0.12) 0px 9px 46px 8px,"
750
+ };
751
+ return A("div", { className: "modalOuter", style: r, children: [d("div", { className: "modalBackground", style: i }), d("div", { className: "modalInner", style: l, children: o })] });
752
+ }), At = (t) => {
753
+ const e = se.parse(t.config), n = t.callbacks || {}, [o, a] = Ke(m.useState, m.useRef), r = ht(e, o, a, n), i = t.config.theme === "light" ? "light" : "dark", l = t.config.theme === "light" ? U : $;
754
+ return d("div", { children: A("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: [d(yt, { show: o.showModal, children: o.challenge ? d(xt, { challenge: o.challenge, index: o.index, solutions: o.solutions, onSubmit: r.submit, onCancel: r.cancel, onClick: r.select, onNext: r.nextRound, themeColor: e.theme ?? "light" }) : d("div", { children: "No challenge set." }) }), d(ge, { children: d(me, { children: A("div", { style: be, "data-cy": "button-human", children: [" ", A("div", { style: {
755
+ padding: xe,
756
+ border: ye,
757
+ backgroundColor: l.palette.background.default,
758
+ borderColor: l.palette.grey[300],
759
+ borderRadius: Ce,
760
+ display: "flex",
761
+ alignItems: "center",
762
+ flexWrap: "wrap",
763
+ justifyContent: "space-between",
764
+ minHeight: `${we}px`,
765
+ overflow: "hidden"
766
+ }, children: [d("div", { style: { display: "inline-flex", flexDirection: "column" }, children: d("div", { style: {
767
+ alignItems: "center",
768
+ flex: 1
769
+ }, children: A("div", { style: {
770
+ display: "flex",
771
+ alignItems: "center",
772
+ justifyContent: "center",
773
+ flexDirection: "column",
774
+ verticalAlign: "middle"
775
+ }, children: [d("div", { style: {
776
+ display: o.loading ? "none" : "flex"
777
+ }, children: d(Ve, { themeColor: i, onChange: r.start, checked: o.isHuman, labelText: "I am human", "aria-label": "human checkbox" }) }), d("div", { style: {
778
+ display: o.loading ? "flex" : "none"
779
+ }, children: d("div", { style: { display: "inline-flex" }, children: d(Ae, { themeColor: i, "aria-label": "Loading spinner" }) }) })] }) }) }), d("div", { style: { display: "inline-flex", flexDirection: "column" }, children: d("a", { href: ve, target: "_blank", "aria-label": Te, rel: "noreferrer", children: d("div", { style: { flex: 1 }, children: d(Ie, { themeColor: i, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) })] }) });
780
+ };
781
+ export {
782
+ At as default
783
+ };