@prosopo/procaptcha-puzzle 2.13.3 → 2.14.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.
Files changed (77) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +6 -6
  2. package/.turbo/turbo-build$colon$tsc.log +20 -20
  3. package/.turbo/turbo-build.log +7 -7
  4. package/CHANGELOG.md +66 -0
  5. package/dist/cjs/components/procaptchaPuzzle.cjs +22 -0
  6. package/dist/cjs/components/procaptchaWidget.cjs +225 -0
  7. package/dist/cjs/components/puzzleCanvas.cjs +451 -0
  8. package/dist/cjs/index.cjs +7 -2
  9. package/dist/components/procaptchaPuzzle.d.ts +7 -0
  10. package/dist/components/procaptchaPuzzle.d.ts.map +1 -0
  11. package/dist/components/procaptchaPuzzle.js +21 -0
  12. package/dist/components/procaptchaPuzzle.js.map +1 -0
  13. package/dist/components/procaptchaWidget.d.ts +7 -0
  14. package/dist/components/procaptchaWidget.d.ts.map +1 -0
  15. package/dist/components/procaptchaWidget.js +225 -0
  16. package/dist/components/procaptchaWidget.js.map +1 -0
  17. package/dist/components/{PuzzleCanvas.d.ts → puzzleCanvas.d.ts} +6 -4
  18. package/dist/components/puzzleCanvas.d.ts.map +1 -0
  19. package/dist/components/puzzleCanvas.js +451 -0
  20. package/dist/components/puzzleCanvas.js.map +1 -0
  21. package/dist/index.d.ts +3 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/tests/domHarness.d.ts +20 -0
  26. package/dist/tests/domHarness.d.ts.map +1 -0
  27. package/dist/tests/domHarness.js +56 -0
  28. package/dist/tests/domHarness.js.map +1 -0
  29. package/dist/tests/invisibleCanvasVisibility.unit.test.d.ts +2 -0
  30. package/dist/tests/invisibleCanvasVisibility.unit.test.d.ts.map +1 -0
  31. package/dist/tests/invisibleCanvasVisibility.unit.test.js +102 -0
  32. package/dist/tests/invisibleCanvasVisibility.unit.test.js.map +1 -0
  33. package/dist/tests/procaptchaPuzzle.test-d.js +13 -10
  34. package/dist/tests/procaptchaPuzzle.test-d.js.map +1 -1
  35. package/dist/tests/procaptchaPuzzle.unit.test.js +44 -33
  36. package/dist/tests/procaptchaPuzzle.unit.test.js.map +1 -1
  37. package/dist/tests/procaptchaWidget.unit.test.js +108 -175
  38. package/dist/tests/procaptchaWidget.unit.test.js.map +1 -1
  39. package/dist/tests/puzzleCanvas.unit.test.js +56 -82
  40. package/dist/tests/puzzleCanvas.unit.test.js.map +1 -1
  41. package/package.json +10 -14
  42. package/src/components/procaptchaPuzzle.ts +54 -0
  43. package/src/components/procaptchaWidget.ts +392 -0
  44. package/src/components/puzzleCanvas.ts +658 -0
  45. package/src/index.ts +3 -2
  46. package/src/tests/domHarness.ts +122 -0
  47. package/src/tests/invisibleCanvasVisibility.unit.test.ts +179 -0
  48. package/src/tests/procaptchaPuzzle.test-d.ts +33 -17
  49. package/src/tests/procaptchaPuzzle.unit.test.ts +59 -44
  50. package/src/tests/procaptchaWidget.unit.test.ts +145 -258
  51. package/src/tests/puzzleCanvas.unit.test.ts +94 -122
  52. package/tsconfig.cjs.json +1 -2
  53. package/tsconfig.json +1 -2
  54. package/tsconfig.tsbuildinfo +1 -1
  55. package/vite.test.config.ts +3 -4
  56. package/dist/cjs/components/ProcaptchaPuzzle.cjs +0 -7
  57. package/dist/cjs/components/ProcaptchaWidget.cjs +0 -206
  58. package/dist/cjs/components/PuzzleCanvas.cjs +0 -476
  59. package/dist/components/ProcaptchaPuzzle.d.ts +0 -3
  60. package/dist/components/ProcaptchaPuzzle.d.ts.map +0 -1
  61. package/dist/components/ProcaptchaPuzzle.js +0 -7
  62. package/dist/components/ProcaptchaPuzzle.js.map +0 -1
  63. package/dist/components/ProcaptchaWidget.d.ts +0 -4
  64. package/dist/components/ProcaptchaWidget.d.ts.map +0 -1
  65. package/dist/components/ProcaptchaWidget.js +0 -207
  66. package/dist/components/ProcaptchaWidget.js.map +0 -1
  67. package/dist/components/PuzzleCanvas.d.ts.map +0 -1
  68. package/dist/components/PuzzleCanvas.js +0 -476
  69. package/dist/components/PuzzleCanvas.js.map +0 -1
  70. package/dist/tests/setup.d.ts +0 -5
  71. package/dist/tests/setup.d.ts.map +0 -1
  72. package/dist/tests/setup.js +0 -3
  73. package/dist/tests/setup.js.map +0 -1
  74. package/src/components/ProcaptchaPuzzle.tsx +0 -36
  75. package/src/components/ProcaptchaWidget.tsx +0 -320
  76. package/src/components/PuzzleCanvas.tsx +0 -638
  77. package/src/tests/setup.ts +0 -26
@@ -1,5 +1,5 @@
1
1
 
2
- > @prosopo/procaptcha-puzzle@2.13.3 build:cjs
2
+ > @prosopo/procaptcha-puzzle@2.14.1 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.22 kB │ gzip: 0.15 kB
50
- dist/cjs/components/ProcaptchaPuzzle.cjs 0.52 kB │ gzip: 0.27 kB
51
- dist/cjs/components/ProcaptchaWidget.cjs 7.61 kB │ gzip: 2.11 kB
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/PuzzleCanvas.cjs 15.24 kB │ gzip: 4.29 kB
53
+ dist/cjs/components/puzzleCanvas.cjs 13.73 kB │ gzip: 4.11 kB
54
54
 
55
- ✓ built in 79ms
55
+ ✓ built in 59ms
@@ -1,11 +1,11 @@
1
1
 
2
- > @prosopo/procaptcha-puzzle@2.13.3 build:tsc
2
+ > @prosopo/procaptcha-puzzle@2.14.1 build:tsc
3
3
  > tsc --build --verbose
4
4
 
5
- 2:42:51 PM - Projects in this build:
5
+ 3:28:51 PM - Projects in this build:
6
6
  * ../../dev/config/tsconfig.json
7
- * ../locale/tsconfig.json
8
7
  * ../util/tsconfig.json
8
+ * ../locale/tsconfig.json
9
9
  * ../util-crypto/tsconfig.json
10
10
  * ../types/tsconfig.json
11
11
  * ../api/tsconfig.json
@@ -20,37 +20,37 @@
20
20
  * ../procaptcha-common/tsconfig.json
21
21
  * tsconfig.json
22
22
 
23
- 2:42:51 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
23
+ 3:28:51 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
24
24
 
25
- 2:42:51 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
25
+ 3:28:51 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
26
26
 
27
- 2:42:51 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
27
+ 3:28:52 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
28
28
 
29
- 2:42:51 PM - 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'
29
+ 3:28:52 PM - 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
- 2:42:51 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/types.test-d.ts' is older than output '../types/tsconfig.tsbuildinfo'
31
+ 3:28:52 PM - 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
- 2:42:51 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
33
+ 3:28:52 PM - 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
- 2:42:51 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
35
+ 3:28:52 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/logger.ts' is older than output '../logger/tsconfig.tsbuildinfo'
36
36
 
37
- 2:42:51 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/utils/batches.ts' is older than output '../common/tsconfig.tsbuildinfo'
37
+ 3:28:52 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/index.ts' is older than output '../common/tsconfig.tsbuildinfo'
38
38
 
39
- 2:42:51 PM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/tests/productionProviderList.unit.test.ts' is older than output '../load-balancer/tsconfig.tsbuildinfo'
39
+ 3:28:52 PM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/tests/productionProviderList.unit.test.ts' is older than output '../load-balancer/tsconfig.tsbuildinfo'
40
40
 
41
- 2:42:51 PM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/webComponent/createWebComponent.ts' is older than output '../widget-skeleton/tsconfig.tsbuildinfo'
41
+ 3:28:52 PM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/theme.ts' is older than output '../widget-skeleton/tsconfig.tsbuildinfo'
42
42
 
43
- 2:42:51 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
43
+ 3:28:52 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
44
44
 
45
- 2:42:51 PM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
45
+ 3:28:52 PM - 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
- 2:42:52 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/pair/decode.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
47
+ 3:28:52 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/index.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
48
48
 
49
- 2:42:52 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/workers/cryptoWorker.ts' is older than output '../account/tsconfig.tsbuildinfo'
49
+ 3:28:52 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/index.ts' is older than output '../account/tsconfig.tsbuildinfo'
50
50
 
51
- 2:42:52 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/tests/challengeSurfaceRender.unit.test.tsx' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
51
+ 3:28:52 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/extensionLoader.ts' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
52
52
 
53
- 2:42:52 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
53
+ 3:28:52 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
54
54
 
55
- 2:42:52 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-puzzle/tsconfig.json'...
55
+ 3:28:52 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-puzzle/tsconfig.json'...
56
56
 
@@ -1,9 +1,9 @@
1
1
 
2
- > @prosopo/procaptcha-puzzle@2.13.3 build
2
+ > @prosopo/procaptcha-puzzle@2.14.1 build
3
3
  > npm run build:cross-env -- --mode ${NODE_ENV:-development}
4
4
 
5
5
 
6
- > @prosopo/procaptcha-puzzle@2.13.3 build:cross-env
6
+ > @prosopo/procaptcha-puzzle@2.14.1 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.14 kB │ gzip: 0.11 kB
55
- dist/components/ProcaptchaPuzzle.js 0.38 kB │ gzip: 0.24 kB
56
- dist/components/ProcaptchaWidget.js 7.08 kB │ gzip: 2.09 kB
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/PuzzleCanvas.js 14.47 kB │ gzip: 4.25 kB
58
+ dist/components/puzzleCanvas.js 13.15 kB │ gzip: 4.10 kB
59
59
 
60
- ✓ built in 64ms
60
+ ✓ built in 66ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # @prosopo/procaptcha-puzzle
2
2
 
3
+ ## 2.14.1
4
+ ### Patch Changes
5
+
6
+ - c3300ee: Stop a tap on the puzzle piece from spending the challenge.
7
+
8
+ Pressing the piece and letting go without moving it submitted an answer: the piece's own starting position. That position is never the right one, so the solution failed, the widget fetched a replacement — which the provider rejected, because the challenge had already been spent — and the user was dropped back to an unticked checkbox with "challenge failed".
9
+
10
+ On a mouse this was hard to do by accident. On a phone it is the normal thing to do: the panel opens centred, under the finger that just pressed the checkbox, so a tap lands on the piece far more often than a drag does. The visible symptom is that the first press appears to do nothing and the challenge only works on the second try.
11
+
12
+ A press and release with no movement now reports nothing and leaves the piece where it was, so the challenge stays open and can still be solved. A real drag is unaffected, including one that returns the piece to where it started — that still carries a movement trail, and is still submitted.
13
+ - Updated dependencies [94929c3]
14
+ - Updated dependencies [a9141c3]
15
+ - Updated dependencies [a9141c3]
16
+ - Updated dependencies [a9141c3]
17
+ - Updated dependencies [e180281]
18
+ - Updated dependencies [5e5fb9e]
19
+ - @prosopo/procaptcha-common@2.17.0
20
+ - @prosopo/locale@3.6.0
21
+ - @prosopo/common@3.1.59
22
+ - @prosopo/types@5.10.0
23
+ - @prosopo/util-crypto@13.5.33
24
+ - @prosopo/util@3.3.11
25
+ - @prosopo/widget-skeleton@2.9.0
26
+ - @prosopo/api@4.3.3
27
+
28
+ ## 2.14.0
29
+ ### Minor Changes
30
+
31
+ - 59c02da: Replace React with vanilla TS/DOM in the widget.
32
+
33
+ The widget packages no longer depend on react, react-dom, @emotion or
34
+ react-i18next: every component is now a `mount*` function returning a handle
35
+ with `update`/`destroy`. `useTranslation` is replaced by `createTranslator`,
36
+ which exposes i18next's `t` plus the events that used to trigger a re-render.
37
+ The rendered markup, styling and behaviour are unchanged — only the
38
+ implementation is.
39
+
40
+ Everything the widget has gained since this rewrite started is carried over,
41
+ so nothing is lost by dropping React: the shared challenge surface (popup and
42
+ float placement, escape/outside-click dismissal and the dialog focus trap),
43
+ the image-tile and puzzle-piece keyboard paths, the checkbox's focus handover
44
+ across the loading swap, the server-rendered puzzle imagery, `startMode:
45
+ "manual"` with `window.procaptcha.start()`, `data-bind` / targeted
46
+ `execute(widgetId)`, the Web Bot Auth "authenticated" badge, the client
47
+ session id, and the bounded session re-mint and reload handling in the
48
+ frictionless wrapper.
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [59c02da]
53
+ - @prosopo/procaptcha-common@2.16.0
54
+ - @prosopo/locale@3.5.0
55
+ - @prosopo/common@3.1.58
56
+ - @prosopo/types@5.9.2
57
+ - @prosopo/api@4.3.2
58
+
59
+ ## 2.13.4
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies [a22069d]
63
+ - @prosopo/types@5.9.1
64
+ - @prosopo/locale@3.4.4
65
+ - @prosopo/api@4.3.1
66
+ - @prosopo/common@3.1.57
67
+ - @prosopo/procaptcha-common@2.15.1
68
+
3
69
  ## 2.13.3
4
70
  ### Patch Changes
5
71
 
@@ -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;