@prosopo/procaptcha-pow 2.10.23 → 2.10.24

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.
@@ -1,129 +1,111 @@
1
- import { jsx, jsxs, Fragment } from "@emotion/react/jsx-runtime";
2
- import { useTranslation, loadI18next } from "@prosopo/locale";
3
- import { useProcaptcha, buildUpdateState, Honeypot, Checkbox } from "@prosopo/procaptcha-common";
4
- import { ModeEnum } from "@prosopo/types";
5
- import { lightTheme, darkTheme } from "@prosopo/widget-skeleton";
6
- import { useState, useRef, useEffect } from "react";
1
+ import "../_virtual/_rolldown/runtime.js";
7
2
  import { Manager } from "../services/Manager.js";
8
- const PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
9
- const Procaptcha = (props) => {
10
- const { t, ready: isTranslationReady } = useTranslation();
11
- const config = props.config;
12
- const i18n = props.i18n;
13
- const theme = "light" === config.theme ? lightTheme : darkTheme;
14
- const frictionlessState = props.frictionlessState;
15
- const callbacks = props.callbacks || {};
16
- const [state, _updateState] = useProcaptcha(useState, useRef);
17
- const [loading, setLoading] = useState(false);
18
- const updateState = buildUpdateState(state, _updateState);
19
- const hpRef = useRef(null);
20
- const manager = useRef(
21
- Manager(
22
- config,
23
- state,
24
- updateState,
25
- callbacks,
26
- frictionlessState,
27
- props.onEscalate,
28
- () => hpRef.current?.value || void 0
29
- )
30
- );
31
- const lastCoordsRef = useRef(null);
32
- const sessionInvalidatedFiredRef = useRef(false);
33
- useEffect(() => {
34
- if (!config.language) return;
35
- if (i18n) {
36
- if (i18n.language !== config.language) {
37
- void i18n.changeLanguage(config.language);
38
- }
39
- return;
40
- }
41
- void loadI18next(false, config.language);
42
- }, [i18n, config.language]);
43
- useEffect(() => {
44
- if (!props.autoStart) return;
45
- setLoading(true);
46
- const coords = props.startCoords;
47
- lastCoordsRef.current = coords ?? null;
48
- manager.current.start(coords?.x ?? 0, coords?.y ?? 0).finally(() => {
49
- setLoading(false);
50
- });
51
- }, [props.autoStart, props.startCoords]);
52
- useEffect(() => {
53
- if (!state.error) return;
54
- setLoading(false);
55
- if (state.error.key !== "CAPTCHA.NO_SESSION_FOUND") return;
56
- if (props.onSessionInvalidated && !sessionInvalidatedFiredRef.current) {
57
- sessionInvalidatedFiredRef.current = true;
58
- const coords = lastCoordsRef.current;
59
- props.onSessionInvalidated(coords?.x, coords?.y);
60
- return;
61
- }
62
- if (frictionlessState) {
63
- setTimeout(() => {
64
- frictionlessState.restart();
65
- }, 100);
66
- }
67
- }, [state.error, frictionlessState, props.onSessionInvalidated]);
68
- useEffect(() => {
69
- if (config.mode === ModeEnum.invisible) {
70
- const handleExecuteEvent = (event) => {
71
- try {
72
- manager.current.start();
73
- } catch (error) {
74
- console.error("Error starting PoW verification:", error);
75
- }
76
- };
77
- document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
78
- return () => {
79
- document.removeEventListener(
80
- PROCAPTCHA_EXECUTE_EVENT,
81
- handleExecuteEvent
82
- );
83
- };
84
- }
85
- return () => {
86
- };
87
- }, [config.mode]);
88
- const honeypot = frictionlessState?.hp ? /* @__PURE__ */ jsx(Honeypot, { ref: hpRef, encodedQuestion: frictionlessState.hp }) : null;
89
- if (config.mode === ModeEnum.invisible) {
90
- return honeypot;
91
- }
92
- return /* @__PURE__ */ jsxs(Fragment, { children: [
93
- honeypot,
94
- /* @__PURE__ */ jsx(
95
- Checkbox,
96
- {
97
- checked: state.isHuman,
98
- theme,
99
- onChange: async (event) => {
100
- if (loading) {
101
- return;
102
- }
103
- setLoading(true);
104
- let x = 0;
105
- let y = 0;
106
- const mouseOrTouchEvent = event.nativeEvent;
107
- if (!mouseOrTouchEvent.isTrusted) {
108
- } else if ("touches" in mouseOrTouchEvent && mouseOrTouchEvent.touches.length > 0 && mouseOrTouchEvent.touches[0]) {
109
- x = mouseOrTouchEvent.touches[0].clientX;
110
- y = mouseOrTouchEvent.touches[0].clientY;
111
- } else if ("clientX" in mouseOrTouchEvent && "clientY" in mouseOrTouchEvent) {
112
- x = mouseOrTouchEvent.clientX;
113
- y = mouseOrTouchEvent.clientY;
114
- }
115
- lastCoordsRef.current = { x, y };
116
- await manager.current.start(x, y);
117
- setLoading(false);
118
- },
119
- labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
120
- error: state.error?.message,
121
- "aria-label": "human checkbox",
122
- loading
123
- }
124
- )
125
- ] });
126
- };
127
- export {
128
- Procaptcha as default
3
+ import { loadI18next, useTranslation } from "@prosopo/locale";
4
+ import { Checkbox, Honeypot, buildUpdateState, useProcaptcha } from "@prosopo/procaptcha-common";
5
+ import { ModeEnum } from "@prosopo/types";
6
+ import { darkTheme, lightTheme } from "@prosopo/widget-skeleton";
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "@emotion/react/jsx-runtime";
9
+ //#region src/components/ProcaptchaWidget.tsx
10
+ var PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
11
+ var Procaptcha = (props) => {
12
+ const { t, ready: isTranslationReady } = useTranslation();
13
+ const config = props.config;
14
+ const i18n = props.i18n;
15
+ const theme = "light" === config.theme ? lightTheme : darkTheme;
16
+ const frictionlessState = props.frictionlessState;
17
+ const callbacks = props.callbacks || {};
18
+ const [state, _updateState] = useProcaptcha(useState, useRef);
19
+ const [loading, setLoading] = useState(false);
20
+ const updateState = buildUpdateState(state, _updateState);
21
+ const hpRef = useRef(null);
22
+ const manager = useRef(Manager(config, state, updateState, callbacks, frictionlessState, props.onEscalate, () => hpRef.current?.value || void 0));
23
+ const lastCoordsRef = useRef(null);
24
+ const sessionInvalidatedFiredRef = useRef(false);
25
+ useEffect(() => {
26
+ if (!config.language) return;
27
+ if (i18n) {
28
+ if (i18n.language !== config.language) i18n.changeLanguage(config.language);
29
+ return;
30
+ }
31
+ loadI18next(false, config.language);
32
+ }, [i18n, config.language]);
33
+ useEffect(() => {
34
+ if (!props.autoStart) return;
35
+ setLoading(true);
36
+ const coords = props.startCoords;
37
+ lastCoordsRef.current = coords ?? null;
38
+ manager.current.start(coords?.x ?? 0, coords?.y ?? 0).finally(() => {
39
+ setLoading(false);
40
+ });
41
+ }, [props.autoStart, props.startCoords]);
42
+ useEffect(() => {
43
+ if (!state.error) return;
44
+ setLoading(false);
45
+ if (state.error.key !== "CAPTCHA.NO_SESSION_FOUND") return;
46
+ if (props.onSessionInvalidated && !sessionInvalidatedFiredRef.current) {
47
+ sessionInvalidatedFiredRef.current = true;
48
+ const coords = lastCoordsRef.current;
49
+ props.onSessionInvalidated(coords?.x, coords?.y);
50
+ return;
51
+ }
52
+ if (frictionlessState) setTimeout(() => {
53
+ frictionlessState.restart();
54
+ }, 100);
55
+ }, [
56
+ state.error,
57
+ frictionlessState,
58
+ props.onSessionInvalidated
59
+ ]);
60
+ useEffect(() => {
61
+ if (config.mode === ModeEnum.invisible) {
62
+ const handleExecuteEvent = (event) => {
63
+ try {
64
+ manager.current.start();
65
+ } catch (error) {
66
+ console.error("Error starting PoW verification:", error);
67
+ }
68
+ };
69
+ document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
70
+ return () => {
71
+ document.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
72
+ };
73
+ }
74
+ return () => {};
75
+ }, [config.mode]);
76
+ const honeypot = frictionlessState?.hp ? /* @__PURE__ */ jsx(Honeypot, {
77
+ ref: hpRef,
78
+ encodedQuestion: frictionlessState.hp
79
+ }) : null;
80
+ if (config.mode === ModeEnum.invisible) return honeypot;
81
+ return /* @__PURE__ */ jsxs(Fragment, { children: [honeypot, /* @__PURE__ */ jsx(Checkbox, {
82
+ checked: state.isHuman,
83
+ theme,
84
+ onChange: async (event) => {
85
+ if (loading) return;
86
+ setLoading(true);
87
+ let x = 0;
88
+ let y = 0;
89
+ const mouseOrTouchEvent = event.nativeEvent;
90
+ if (!mouseOrTouchEvent.isTrusted) {} else if ("touches" in mouseOrTouchEvent && mouseOrTouchEvent.touches.length > 0 && mouseOrTouchEvent.touches[0]) {
91
+ x = mouseOrTouchEvent.touches[0].clientX;
92
+ y = mouseOrTouchEvent.touches[0].clientY;
93
+ } else if ("clientX" in mouseOrTouchEvent && "clientY" in mouseOrTouchEvent) {
94
+ x = mouseOrTouchEvent.clientX;
95
+ y = mouseOrTouchEvent.clientY;
96
+ }
97
+ lastCoordsRef.current = {
98
+ x,
99
+ y
100
+ };
101
+ await manager.current.start(x, y);
102
+ setLoading(false);
103
+ },
104
+ labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
105
+ error: state.error?.message,
106
+ "aria-label": "human checkbox",
107
+ loading
108
+ })] });
129
109
  };
110
+ //#endregion
111
+ export { Procaptcha as default };
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import "./components/ProcaptchaWidget.js";
1
+ import "./_virtual/_rolldown/runtime.js";
2
2
  import { ProcaptchaPow } from "./components/ProcaptchaPoW.js";
3
- export {
4
- ProcaptchaPow
5
- };
3
+ export { ProcaptchaPow };
@@ -1 +1 @@
1
- {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/services/Manager.ts"],"names":[],"mappings":"AA8BA,OAAO,EAIN,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEhC,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAE5B,MAAM,gBAAgB,CAAC;AAKxB,eAAO,MAAM,OAAO,gBACN,2BAA2B,SACjC,eAAe,iBACP,uBAAuB,aAC3B,mBAAmB,sBACV,iBAAiB,eACxB,2BAA2B,qBAIrB,MAAM,MAAM,GAAG,SAAS;;uCAmFD,MAAM,IAAI;CAuTpD,CAAC"}
1
+ {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/services/Manager.ts"],"names":[],"mappings":"AA+BA,OAAO,EAIN,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEhC,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAE5B,MAAM,gBAAgB,CAAC;AAKxB,eAAO,MAAM,OAAO,gBACN,2BAA2B,SACjC,eAAe,iBACP,uBAAuB,aAC3B,mBAAmB,sBACV,iBAAiB,eACxB,2BAA2B,qBAIrB,MAAM,MAAM,GAAG,SAAS;;uCAmFD,MAAM,IAAI;CAuTpD,CAAC"}