@prosopo/procaptcha-puzzle 2.13.2 → 2.14.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.
- package/.turbo/turbo-build$colon$cjs.log +6 -6
- package/.turbo/turbo-build$colon$tsc.log +19 -19
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +50 -0
- package/dist/cjs/components/procaptchaPuzzle.cjs +22 -0
- package/dist/cjs/components/procaptchaWidget.cjs +225 -0
- package/dist/cjs/components/puzzleCanvas.cjs +450 -0
- package/dist/cjs/index.cjs +7 -2
- package/dist/components/procaptchaPuzzle.d.ts +7 -0
- package/dist/components/procaptchaPuzzle.d.ts.map +1 -0
- package/dist/components/procaptchaPuzzle.js +21 -0
- package/dist/components/procaptchaPuzzle.js.map +1 -0
- package/dist/components/procaptchaWidget.d.ts +7 -0
- package/dist/components/procaptchaWidget.d.ts.map +1 -0
- package/dist/components/procaptchaWidget.js +225 -0
- package/dist/components/procaptchaWidget.js.map +1 -0
- package/dist/components/{PuzzleCanvas.d.ts → puzzleCanvas.d.ts} +6 -4
- package/dist/components/puzzleCanvas.d.ts.map +1 -0
- package/dist/components/puzzleCanvas.js +450 -0
- package/dist/components/puzzleCanvas.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/tests/domHarness.d.ts +20 -0
- package/dist/tests/domHarness.d.ts.map +1 -0
- package/dist/tests/domHarness.js +56 -0
- package/dist/tests/domHarness.js.map +1 -0
- package/dist/tests/procaptchaPuzzle.test-d.js +13 -10
- package/dist/tests/procaptchaPuzzle.test-d.js.map +1 -1
- package/dist/tests/procaptchaPuzzle.unit.test.js +44 -33
- package/dist/tests/procaptchaPuzzle.unit.test.js.map +1 -1
- package/dist/tests/procaptchaWidget.unit.test.js +108 -175
- package/dist/tests/procaptchaWidget.unit.test.js.map +1 -1
- package/dist/tests/puzzleCanvas.unit.test.js +47 -80
- package/dist/tests/puzzleCanvas.unit.test.js.map +1 -1
- package/package.json +8 -12
- package/src/components/procaptchaPuzzle.ts +54 -0
- package/src/components/procaptchaWidget.ts +392 -0
- package/src/components/puzzleCanvas.ts +653 -0
- package/src/index.ts +3 -2
- package/src/tests/domHarness.ts +122 -0
- package/src/tests/procaptchaPuzzle.test-d.ts +33 -17
- package/src/tests/procaptchaPuzzle.unit.test.ts +59 -44
- package/src/tests/procaptchaWidget.unit.test.ts +145 -258
- package/src/tests/puzzleCanvas.unit.test.ts +76 -120
- package/tsconfig.cjs.json +1 -2
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.test.config.ts +3 -4
- package/dist/cjs/components/ProcaptchaPuzzle.cjs +0 -7
- package/dist/cjs/components/ProcaptchaWidget.cjs +0 -206
- package/dist/cjs/components/PuzzleCanvas.cjs +0 -476
- package/dist/components/ProcaptchaPuzzle.d.ts +0 -3
- package/dist/components/ProcaptchaPuzzle.d.ts.map +0 -1
- package/dist/components/ProcaptchaPuzzle.js +0 -7
- package/dist/components/ProcaptchaPuzzle.js.map +0 -1
- package/dist/components/ProcaptchaWidget.d.ts +0 -4
- package/dist/components/ProcaptchaWidget.d.ts.map +0 -1
- package/dist/components/ProcaptchaWidget.js +0 -207
- package/dist/components/ProcaptchaWidget.js.map +0 -1
- package/dist/components/PuzzleCanvas.d.ts.map +0 -1
- package/dist/components/PuzzleCanvas.js +0 -476
- package/dist/components/PuzzleCanvas.js.map +0 -1
- package/dist/tests/setup.d.ts +0 -5
- package/dist/tests/setup.d.ts.map +0 -1
- package/dist/tests/setup.js +0 -3
- package/dist/tests/setup.js.map +0 -1
- package/src/components/ProcaptchaPuzzle.tsx +0 -36
- package/src/components/ProcaptchaWidget.tsx +0 -320
- package/src/components/PuzzleCanvas.tsx +0 -638
- package/src/tests/setup.ts +0 -26
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/procaptcha-puzzle@2.
|
|
2
|
+
> @prosopo/procaptcha-puzzle@2.14.0 build:cjs
|
|
3
3
|
> NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
|
|
4
4
|
|
|
5
5
|
ViteCommonJSConfig: .
|
|
@@ -46,10 +46,10 @@ Bundle build started
|
|
|
46
46
|
✓ 6 modules transformed.
|
|
47
47
|
rendering chunks...
|
|
48
48
|
computing gzip size...
|
|
49
|
-
dist/cjs/index.cjs 0.
|
|
50
|
-
dist/cjs/components/
|
|
51
|
-
dist/cjs/components/
|
|
49
|
+
dist/cjs/index.cjs 0.60 kB │ gzip: 0.21 kB
|
|
50
|
+
dist/cjs/components/procaptchaPuzzle.cjs 0.74 kB │ gzip: 0.38 kB
|
|
51
|
+
dist/cjs/components/procaptchaWidget.cjs 7.49 kB │ gzip: 2.10 kB
|
|
52
52
|
dist/cjs/services/Manager.cjs 9.03 kB │ gzip: 2.48 kB
|
|
53
|
-
dist/cjs/components/
|
|
53
|
+
dist/cjs/components/puzzleCanvas.cjs 13.76 kB │ gzip: 4.12 kB
|
|
54
54
|
|
|
55
|
-
[32m✓ built in
|
|
55
|
+
[32m✓ built in 70ms[39m
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/procaptcha-puzzle@2.
|
|
2
|
+
> @prosopo/procaptcha-puzzle@2.14.0 build:tsc
|
|
3
3
|
> tsc --build --verbose
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
11:04:26 AM - Projects in this build:
|
|
6
6
|
* ../../dev/config/tsconfig.json
|
|
7
7
|
* ../locale/tsconfig.json
|
|
8
8
|
* ../util/tsconfig.json
|
|
@@ -20,37 +20,37 @@
|
|
|
20
20
|
* ../procaptcha-common/tsconfig.json
|
|
21
21
|
* tsconfig.json
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
11:04:26 AM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/vite/NodejsPolarsDirnamePlugin.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
11:04:26 AM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/process.ts' is older than output '../locale/tsconfig.tsbuildinfo'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
11:04:27 AM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/ofLen.ts' is older than output '../util/tsconfig.tsbuildinfo'
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
11:04:27 AM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/tsconfig.tsbuildinfo'
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
11:04:27 AM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/types.test-d.ts' is older than output '../types/tsconfig.tsbuildinfo'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
11:04:27 AM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
11:04:27 AM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
11:04:27 AM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/utils/batches.ts' is older than output '../common/tsconfig.tsbuildinfo'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
11:04:27 AM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/balancer.ts' is older than output '../load-balancer/tsconfig.tsbuildinfo'
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
11:04:27 AM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/index.ts' is older than output '../widget-skeleton/tsconfig.tsbuildinfo'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
11:04:27 AM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/async.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
11:04:27 AM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
11:04:27 AM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/keyring/keyring.test.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
11:04:27 AM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/custom.d.ts' is older than output '../account/tsconfig.tsbuildinfo'
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
11:04:27 AM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/tests/challengeSurfaceRender.unit.test.ts' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
11:04:27 AM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
11:04:27 AM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-puzzle/tsconfig.json'...
|
|
56
56
|
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @prosopo/procaptcha-puzzle@2.
|
|
2
|
+
> @prosopo/procaptcha-puzzle@2.14.0 build
|
|
3
3
|
> npm run build:cross-env -- --mode ${NODE_ENV:-development}
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @prosopo/procaptcha-puzzle@2.
|
|
6
|
+
> @prosopo/procaptcha-puzzle@2.14.0 build:cross-env
|
|
7
7
|
> vite build --config vite.esm.config.ts --mode production
|
|
8
8
|
|
|
9
9
|
ViteEsmConfig: .
|
|
@@ -51,10 +51,10 @@ Bundle build started
|
|
|
51
51
|
rendering chunks...
|
|
52
52
|
computing gzip size...
|
|
53
53
|
dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
54
|
-
dist/index.js 0.
|
|
55
|
-
dist/components/
|
|
56
|
-
dist/components/
|
|
54
|
+
dist/index.js 0.38 kB │ gzip: 0.16 kB
|
|
55
|
+
dist/components/procaptchaPuzzle.js 0.65 kB │ gzip: 0.36 kB
|
|
56
|
+
dist/components/procaptchaWidget.js 7.16 kB │ gzip: 2.09 kB
|
|
57
57
|
dist/services/Manager.js 8.49 kB │ gzip: 2.44 kB
|
|
58
|
-
dist/components/
|
|
58
|
+
dist/components/puzzleCanvas.js 13.18 kB │ gzip: 4.10 kB
|
|
59
59
|
|
|
60
|
-
[32m✓ built in
|
|
60
|
+
[32m✓ built in 58ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @prosopo/procaptcha-puzzle
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
- 59c02da: Replace React with vanilla TS/DOM in the widget.
|
|
7
|
+
|
|
8
|
+
The widget packages no longer depend on react, react-dom, @emotion or
|
|
9
|
+
react-i18next: every component is now a `mount*` function returning a handle
|
|
10
|
+
with `update`/`destroy`. `useTranslation` is replaced by `createTranslator`,
|
|
11
|
+
which exposes i18next's `t` plus the events that used to trigger a re-render.
|
|
12
|
+
The rendered markup, styling and behaviour are unchanged — only the
|
|
13
|
+
implementation is.
|
|
14
|
+
|
|
15
|
+
Everything the widget has gained since this rewrite started is carried over,
|
|
16
|
+
so nothing is lost by dropping React: the shared challenge surface (popup and
|
|
17
|
+
float placement, escape/outside-click dismissal and the dialog focus trap),
|
|
18
|
+
the image-tile and puzzle-piece keyboard paths, the checkbox's focus handover
|
|
19
|
+
across the loading swap, the server-rendered puzzle imagery, `startMode:
|
|
20
|
+
"manual"` with `window.procaptcha.start()`, `data-bind` / targeted
|
|
21
|
+
`execute(widgetId)`, the Web Bot Auth "authenticated" badge, the client
|
|
22
|
+
session id, and the bounded session re-mint and reload handling in the
|
|
23
|
+
frictionless wrapper.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [59c02da]
|
|
28
|
+
- @prosopo/procaptcha-common@2.16.0
|
|
29
|
+
- @prosopo/locale@3.5.0
|
|
30
|
+
- @prosopo/common@3.1.58
|
|
31
|
+
- @prosopo/types@5.9.2
|
|
32
|
+
- @prosopo/api@4.3.2
|
|
33
|
+
|
|
34
|
+
## 2.13.4
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [a22069d]
|
|
38
|
+
- @prosopo/types@5.9.1
|
|
39
|
+
- @prosopo/locale@3.4.4
|
|
40
|
+
- @prosopo/api@4.3.1
|
|
41
|
+
- @prosopo/common@3.1.57
|
|
42
|
+
- @prosopo/procaptcha-common@2.15.1
|
|
43
|
+
|
|
44
|
+
## 2.13.3
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [a606f54]
|
|
48
|
+
- Updated dependencies [0f23010]
|
|
49
|
+
- @prosopo/types@5.9.0
|
|
50
|
+
- @prosopo/procaptcha-common@2.15.0
|
|
51
|
+
- @prosopo/api@4.3.0
|
|
52
|
+
|
|
3
53
|
## 2.13.2
|
|
4
54
|
### Patch Changes
|
|
5
55
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/components/procaptchaPuzzle.ts
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic import so the puzzle widget lands in its own chunk, replacing the
|
|
4
|
+
* `lazy()` + `<Suspense>` pair that used to provide the split.
|
|
5
|
+
*/
|
|
6
|
+
var loadProcaptchaPuzzle = async () => (await Promise.resolve().then(() => require("./procaptchaWidget.cjs"))).mountProcaptchaPuzzleWidget;
|
|
7
|
+
var mountProcaptchaPuzzle = (container, props) => {
|
|
8
|
+
let destroyed = false;
|
|
9
|
+
let inner;
|
|
10
|
+
loadProcaptchaPuzzle().then((mount) => {
|
|
11
|
+
if (destroyed) return;
|
|
12
|
+
inner = mount(container, props);
|
|
13
|
+
});
|
|
14
|
+
return { destroy: () => {
|
|
15
|
+
destroyed = true;
|
|
16
|
+
inner?.destroy();
|
|
17
|
+
inner = void 0;
|
|
18
|
+
} };
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.loadProcaptchaPuzzle = loadProcaptchaPuzzle;
|
|
22
|
+
exports.mountProcaptchaPuzzle = mountProcaptchaPuzzle;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const require_Manager = require("../services/Manager.cjs");
|
|
2
|
+
const require_puzzleCanvas = require("./puzzleCanvas.cjs");
|
|
3
|
+
let _prosopo_locale = require("@prosopo/locale");
|
|
4
|
+
let _prosopo_procaptcha_common = require("@prosopo/procaptcha-common");
|
|
5
|
+
let _prosopo_types = require("@prosopo/types");
|
|
6
|
+
let _prosopo_widget_skeleton = require("@prosopo/widget-skeleton");
|
|
7
|
+
//#region src/components/procaptchaWidget.ts
|
|
8
|
+
var PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
|
|
9
|
+
var mountProcaptchaPuzzleWidget = (container, props) => {
|
|
10
|
+
const teardown = new _prosopo_procaptcha_common.Teardown();
|
|
11
|
+
const config = props.config;
|
|
12
|
+
const i18n = props.i18n;
|
|
13
|
+
const frictionlessState = props.frictionlessState;
|
|
14
|
+
const callbacks = props.callbacks || {};
|
|
15
|
+
const translator = (0, _prosopo_locale.createTranslator)(i18n);
|
|
16
|
+
const isInvisible = _prosopo_types.ModeEnum.invisible === config.mode;
|
|
17
|
+
const store = (0, _prosopo_procaptcha_common.createProcaptchaState)();
|
|
18
|
+
let loading = false;
|
|
19
|
+
let puzzlePhase = "checkbox";
|
|
20
|
+
let challengeData = null;
|
|
21
|
+
let showRetry = false;
|
|
22
|
+
let lastError = store.state.error;
|
|
23
|
+
let lastCoords = null;
|
|
24
|
+
let sessionInvalidatedFired = false;
|
|
25
|
+
let honeypot;
|
|
26
|
+
let checkbox;
|
|
27
|
+
let puzzle;
|
|
28
|
+
const updateState = (0, _prosopo_procaptcha_common.buildUpdateState)(store.state, store.update);
|
|
29
|
+
const manager = require_Manager.Manager(config, store.state, updateState, callbacks, frictionlessState, () => honeypot?.getValue());
|
|
30
|
+
const root = (0, _prosopo_procaptcha_common.createElement)("div");
|
|
31
|
+
container.appendChild(root);
|
|
32
|
+
if (frictionlessState?.hp) honeypot = (0, _prosopo_procaptcha_common.mountHoneypot)(root, { encodedQuestion: frictionlessState.hp });
|
|
33
|
+
const handlePuzzleComplete = async (finalX, finalY, puzzleEvents) => {
|
|
34
|
+
puzzlePhase = "submitting";
|
|
35
|
+
scheduler.schedule();
|
|
36
|
+
let verified = false;
|
|
37
|
+
try {
|
|
38
|
+
verified = await manager.submitSolution(finalX, finalY, puzzleEvents);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
callbacks.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
41
|
+
}
|
|
42
|
+
if (verified) {
|
|
43
|
+
puzzlePhase = "checkbox";
|
|
44
|
+
challengeData = null;
|
|
45
|
+
showRetry = false;
|
|
46
|
+
loading = false;
|
|
47
|
+
scheduler.schedule();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
showRetry = true;
|
|
51
|
+
puzzlePhase = "dragging";
|
|
52
|
+
scheduler.schedule();
|
|
53
|
+
try {
|
|
54
|
+
const newChallenge = await manager.start();
|
|
55
|
+
if (newChallenge) challengeData = newChallenge;
|
|
56
|
+
else {
|
|
57
|
+
puzzlePhase = "checkbox";
|
|
58
|
+
challengeData = null;
|
|
59
|
+
showRetry = false;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
puzzlePhase = "checkbox";
|
|
63
|
+
challengeData = null;
|
|
64
|
+
showRetry = false;
|
|
65
|
+
}
|
|
66
|
+
loading = false;
|
|
67
|
+
scheduler.schedule();
|
|
68
|
+
};
|
|
69
|
+
const handleDismiss = () => {
|
|
70
|
+
puzzlePhase = "checkbox";
|
|
71
|
+
challengeData = null;
|
|
72
|
+
showRetry = false;
|
|
73
|
+
loading = false;
|
|
74
|
+
scheduler.schedule();
|
|
75
|
+
};
|
|
76
|
+
const puzzleProps = (challenge) => ({
|
|
77
|
+
originX: challenge.originX,
|
|
78
|
+
originY: challenge.originY,
|
|
79
|
+
background: challenge.background,
|
|
80
|
+
piece: challenge.piece,
|
|
81
|
+
pieceSize: challenge.pieceSize,
|
|
82
|
+
onComplete: (finalX, finalY, events) => {
|
|
83
|
+
handlePuzzleComplete(finalX, finalY, events);
|
|
84
|
+
},
|
|
85
|
+
showRetry,
|
|
86
|
+
submitting: "submitting" === puzzlePhase,
|
|
87
|
+
theme: "light" === config.theme ? _prosopo_widget_skeleton.lightTheme : _prosopo_widget_skeleton.darkTheme,
|
|
88
|
+
translator,
|
|
89
|
+
placement: config.placement,
|
|
90
|
+
anchor: props.container,
|
|
91
|
+
onDismiss: handleDismiss
|
|
92
|
+
});
|
|
93
|
+
const runErrorEffect = () => {
|
|
94
|
+
if (store.state.error === lastError) return;
|
|
95
|
+
lastError = store.state.error;
|
|
96
|
+
if (!store.state.error) return;
|
|
97
|
+
loading = false;
|
|
98
|
+
puzzlePhase = "checkbox";
|
|
99
|
+
challengeData = null;
|
|
100
|
+
showRetry = false;
|
|
101
|
+
if ("CAPTCHA.NO_SESSION_FOUND" !== store.state.error.key) return;
|
|
102
|
+
if (props.onSessionInvalidated && !sessionInvalidatedFired) {
|
|
103
|
+
sessionInvalidatedFired = true;
|
|
104
|
+
props.onSessionInvalidated(lastCoords?.x, lastCoords?.y);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (frictionlessState) {
|
|
108
|
+
const timer = setTimeout(() => {
|
|
109
|
+
frictionlessState.restart();
|
|
110
|
+
}, 100);
|
|
111
|
+
teardown.add(() => clearTimeout(timer));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const render = () => {
|
|
115
|
+
runErrorEffect();
|
|
116
|
+
if (("dragging" === puzzlePhase || "submitting" === puzzlePhase) && null !== challengeData && null !== challengeData) if (void 0 === puzzle) puzzle = require_puzzleCanvas.mountPuzzleCanvas(puzzleProps(challengeData));
|
|
117
|
+
else puzzle.update(puzzleProps(challengeData));
|
|
118
|
+
else {
|
|
119
|
+
puzzle?.destroy();
|
|
120
|
+
puzzle = void 0;
|
|
121
|
+
}
|
|
122
|
+
checkbox?.update(checkboxProps());
|
|
123
|
+
};
|
|
124
|
+
const scheduler = (0, _prosopo_procaptcha_common.createRenderScheduler)(render);
|
|
125
|
+
const checkboxProps = () => ({
|
|
126
|
+
checked: store.state.isHuman,
|
|
127
|
+
theme: "light" === config.theme ? _prosopo_widget_skeleton.lightTheme : _prosopo_widget_skeleton.darkTheme,
|
|
128
|
+
labelText: translator.isReady() ? translator.t("WIDGET.I_AM_HUMAN") : "",
|
|
129
|
+
error: store.state.error?.message,
|
|
130
|
+
loadingText: translator.t("WIDGET.CHECKING", { defaultValue: "Checking that you are human" }),
|
|
131
|
+
loading: loading || "submitting" === puzzlePhase,
|
|
132
|
+
onChange: async (event) => {
|
|
133
|
+
if (loading) return;
|
|
134
|
+
loading = true;
|
|
135
|
+
showRetry = false;
|
|
136
|
+
scheduler.schedule();
|
|
137
|
+
let x = 0;
|
|
138
|
+
let y = 0;
|
|
139
|
+
if (!(0, _prosopo_procaptcha_common.isEventTrusted)(event)) {} else if ("touches" in event && event.touches.length > 0) {
|
|
140
|
+
const touch = event.touches[0];
|
|
141
|
+
if (touch) {
|
|
142
|
+
x = touch.clientX;
|
|
143
|
+
y = touch.clientY;
|
|
144
|
+
}
|
|
145
|
+
} else if ("clientX" in event && "clientY" in event) {
|
|
146
|
+
x = event.clientX;
|
|
147
|
+
y = event.clientY;
|
|
148
|
+
}
|
|
149
|
+
lastCoords = {
|
|
150
|
+
x,
|
|
151
|
+
y
|
|
152
|
+
};
|
|
153
|
+
try {
|
|
154
|
+
const challenge = await manager.start(x, y);
|
|
155
|
+
if (challenge) {
|
|
156
|
+
challengeData = challenge;
|
|
157
|
+
puzzlePhase = "dragging";
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
callbacks.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
161
|
+
} finally {
|
|
162
|
+
loading = false;
|
|
163
|
+
scheduler.schedule();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (!isInvisible) checkbox = (0, _prosopo_procaptcha_common.mountCheckbox)(root, checkboxProps());
|
|
168
|
+
teardown.add(scheduler.cancel);
|
|
169
|
+
teardown.add(store.subscribe(scheduler.schedule));
|
|
170
|
+
teardown.add(translator.subscribe(scheduler.schedule));
|
|
171
|
+
const handleExecute = () => {
|
|
172
|
+
(async () => {
|
|
173
|
+
if (loading) return;
|
|
174
|
+
loading = true;
|
|
175
|
+
showRetry = false;
|
|
176
|
+
scheduler.schedule();
|
|
177
|
+
try {
|
|
178
|
+
const challenge = await manager.start();
|
|
179
|
+
if (challenge) {
|
|
180
|
+
challengeData = challenge;
|
|
181
|
+
puzzlePhase = "dragging";
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
callbacks.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
185
|
+
} finally {
|
|
186
|
+
loading = false;
|
|
187
|
+
scheduler.schedule();
|
|
188
|
+
}
|
|
189
|
+
})();
|
|
190
|
+
};
|
|
191
|
+
if (props.container) teardown.addEventListener(props.container, PROCAPTCHA_EXECUTE_EVENT, handleExecute);
|
|
192
|
+
if (isInvisible) teardown.addEventListener(document, PROCAPTCHA_EXECUTE_EVENT, handleExecute);
|
|
193
|
+
if (config.language) if (i18n) {
|
|
194
|
+
if (i18n.language !== config.language) i18n.changeLanguage(config.language);
|
|
195
|
+
} else (0, _prosopo_locale.loadI18next)(false, config.language);
|
|
196
|
+
if (props.autoStart) {
|
|
197
|
+
loading = true;
|
|
198
|
+
showRetry = false;
|
|
199
|
+
const coords = props.startCoords;
|
|
200
|
+
lastCoords = coords ?? null;
|
|
201
|
+
scheduler.schedule();
|
|
202
|
+
manager.start(coords?.x ?? 0, coords?.y ?? 0).then((challenge) => {
|
|
203
|
+
if (challenge) {
|
|
204
|
+
challengeData = challenge;
|
|
205
|
+
puzzlePhase = "dragging";
|
|
206
|
+
}
|
|
207
|
+
loading = false;
|
|
208
|
+
scheduler.schedule();
|
|
209
|
+
}, () => {
|
|
210
|
+
loading = false;
|
|
211
|
+
scheduler.schedule();
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
render();
|
|
215
|
+
return { destroy: () => {
|
|
216
|
+
teardown.run();
|
|
217
|
+
puzzle?.destroy();
|
|
218
|
+
checkbox?.destroy();
|
|
219
|
+
honeypot?.destroy();
|
|
220
|
+
root.parentNode?.removeChild(root);
|
|
221
|
+
} };
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
224
|
+
exports.default = mountProcaptchaPuzzleWidget;
|
|
225
|
+
exports.mountProcaptchaPuzzleWidget = mountProcaptchaPuzzleWidget;
|