@prosopo/procaptcha-puzzle 2.10.8 → 2.10.9
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 +53 -0
- package/.turbo/turbo-build$colon$tsc.log +56 -0
- package/.turbo/turbo-build.log +57 -57
- package/CHANGELOG.md +8 -0
- package/dist/cjs/components/ProcaptchaPuzzle.cjs +18 -0
- package/dist/cjs/components/ProcaptchaWidget.cjs +191 -0
- package/dist/cjs/components/PuzzleCanvas.cjs +275 -0
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/services/Manager.cjs +286 -0
- package/dist/components/ProcaptchaPuzzle.js +17 -5
- package/dist/components/ProcaptchaWidget.js +181 -144
- package/dist/components/PuzzleCanvas.js +258 -189
- package/dist/index.js +5 -3
- package/dist/services/Manager.js +270 -253
- package/package.json +4 -4
- package/src/components/ProcaptchaPuzzle.tsx +38 -0
- package/src/components/ProcaptchaWidget.tsx +261 -0
- package/src/components/PuzzleCanvas.tsx +336 -0
- package/src/index.ts +15 -0
- package/src/services/Manager.ts +454 -0
- package/tsconfig.cjs.json +44 -0
- package/tsconfig.json +45 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
- package/.turbo/turbo-typecheck.log +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
3
3
|
const CONTAINER_WIDTH = 300;
|
|
4
4
|
const CONTAINER_HEIGHT = 200;
|
|
5
5
|
const TARGET_SIZE = 30;
|
|
@@ -11,196 +11,265 @@ const SHAKE_KEYFRAMES = `
|
|
|
11
11
|
20%, 40%, 60%, 80% { transform: translateX(4px); }
|
|
12
12
|
}
|
|
13
13
|
`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
14
|
+
const PuzzleCanvas = ({
|
|
15
|
+
originX,
|
|
16
|
+
originY,
|
|
17
|
+
targetX,
|
|
18
|
+
targetY,
|
|
19
|
+
onComplete,
|
|
20
|
+
showRetry,
|
|
21
|
+
submitting
|
|
22
|
+
}) => {
|
|
23
|
+
const [posX, setPosX] = useState(originX);
|
|
24
|
+
const [posY, setPosY] = useState(originY);
|
|
25
|
+
const isDragging = useRef(false);
|
|
26
|
+
const puzzleEvents = useRef([]);
|
|
27
|
+
const containerRef = useRef(null);
|
|
28
|
+
const offsetRef = useRef({ x: 0, y: 0 });
|
|
29
|
+
const [visible, setVisible] = useState(false);
|
|
30
|
+
const [shaking, setShaking] = useState(false);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setPosX(originX);
|
|
33
|
+
setPosY(originY);
|
|
34
|
+
}, [originX, originY]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const frame = requestAnimationFrame(() => setVisible(true));
|
|
37
|
+
return () => cancelAnimationFrame(frame);
|
|
38
|
+
}, []);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (showRetry) {
|
|
41
|
+
setShaking(true);
|
|
42
|
+
const timer = setTimeout(() => setShaking(false), 500);
|
|
43
|
+
return () => clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
return () => {
|
|
46
|
+
};
|
|
47
|
+
}, [showRetry]);
|
|
48
|
+
const clamp = useCallback(
|
|
49
|
+
(value, min, max) => {
|
|
50
|
+
return Math.max(min, Math.min(max, value));
|
|
51
|
+
},
|
|
52
|
+
[]
|
|
53
|
+
);
|
|
54
|
+
const getContainerOffset = useCallback(() => {
|
|
55
|
+
if (containerRef.current) {
|
|
56
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
57
|
+
return { x: rect.left, y: rect.top };
|
|
58
|
+
}
|
|
59
|
+
return { x: 0, y: 0 };
|
|
60
|
+
}, []);
|
|
61
|
+
const handleMoveEvent = useCallback(
|
|
62
|
+
(clientX, clientY) => {
|
|
63
|
+
if (!isDragging.current) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const containerOffset = getContainerOffset();
|
|
67
|
+
const newX = clamp(
|
|
68
|
+
clientX - containerOffset.x - offsetRef.current.x,
|
|
69
|
+
0,
|
|
70
|
+
CONTAINER_WIDTH
|
|
71
|
+
);
|
|
72
|
+
const newY = clamp(
|
|
73
|
+
clientY - containerOffset.y - offsetRef.current.y,
|
|
74
|
+
0,
|
|
75
|
+
CONTAINER_HEIGHT
|
|
76
|
+
);
|
|
77
|
+
setPosX(newX);
|
|
78
|
+
setPosY(newY);
|
|
79
|
+
puzzleEvents.current.push({ x: newX, y: newY, t: Date.now() });
|
|
80
|
+
},
|
|
81
|
+
[clamp, getContainerOffset]
|
|
82
|
+
);
|
|
83
|
+
const handleEndEvent = useCallback(() => {
|
|
84
|
+
if (!isDragging.current) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
isDragging.current = false;
|
|
88
|
+
const currentEvents = [...puzzleEvents.current];
|
|
89
|
+
const lastEvent = currentEvents[currentEvents.length - 1];
|
|
90
|
+
const finalX = lastEvent ? lastEvent.x : originX;
|
|
91
|
+
const finalY = lastEvent ? lastEvent.y : originY;
|
|
92
|
+
onComplete(finalX, finalY, currentEvents);
|
|
93
|
+
}, [onComplete, originX, originY]);
|
|
94
|
+
const handleMouseMove = useCallback(
|
|
95
|
+
(event) => {
|
|
96
|
+
handleMoveEvent(event.clientX, event.clientY);
|
|
97
|
+
},
|
|
98
|
+
[handleMoveEvent]
|
|
99
|
+
);
|
|
100
|
+
const handleTouchMove = useCallback(
|
|
101
|
+
(event) => {
|
|
102
|
+
const touch = event.touches[0];
|
|
103
|
+
if (touch) {
|
|
104
|
+
handleMoveEvent(touch.clientX, touch.clientY);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
[handleMoveEvent]
|
|
108
|
+
);
|
|
109
|
+
const handleMouseUp = useCallback(() => {
|
|
110
|
+
handleEndEvent();
|
|
111
|
+
}, [handleEndEvent]);
|
|
112
|
+
const handleTouchEnd = useCallback(() => {
|
|
113
|
+
handleEndEvent();
|
|
114
|
+
}, [handleEndEvent]);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
117
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
118
|
+
document.addEventListener("touchmove", handleTouchMove);
|
|
119
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
120
|
+
return () => {
|
|
121
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
122
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
123
|
+
document.removeEventListener("touchmove", handleTouchMove);
|
|
124
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
125
|
+
};
|
|
126
|
+
}, [handleMouseMove, handleMouseUp, handleTouchMove, handleTouchEnd]);
|
|
127
|
+
const handlePieceMouseDown = useCallback(
|
|
128
|
+
(event) => {
|
|
129
|
+
if (submitting) return;
|
|
130
|
+
isDragging.current = true;
|
|
131
|
+
puzzleEvents.current = [];
|
|
132
|
+
const containerOffset = getContainerOffset();
|
|
133
|
+
offsetRef.current = {
|
|
134
|
+
x: event.clientX - containerOffset.x - posX,
|
|
135
|
+
y: event.clientY - containerOffset.y - posY
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
[getContainerOffset, posX, posY, submitting]
|
|
139
|
+
);
|
|
140
|
+
const handlePieceTouchStart = useCallback(
|
|
141
|
+
(event) => {
|
|
142
|
+
if (submitting) return;
|
|
143
|
+
const touch = event.touches[0];
|
|
144
|
+
if (touch) {
|
|
101
145
|
isDragging.current = true;
|
|
102
146
|
puzzleEvents.current = [];
|
|
103
147
|
const containerOffset = getContainerOffset();
|
|
104
148
|
offsetRef.current = {
|
|
105
|
-
|
|
106
|
-
|
|
149
|
+
x: touch.clientX - containerOffset.x - posX,
|
|
150
|
+
y: touch.clientY - containerOffset.y - posY
|
|
107
151
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
: "
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[getContainerOffset, posX, posY, submitting]
|
|
155
|
+
);
|
|
156
|
+
const instructionText = showRetry ? "Not quite — try again" : "Drag the piece to the target";
|
|
157
|
+
const headerBorderColor = showRetry ? "rgba(220, 53, 69, 0.4)" : "transparent";
|
|
158
|
+
const headerTextColor = showRetry ? "#dc3545" : "#333";
|
|
159
|
+
return /* @__PURE__ */ jsxs(
|
|
160
|
+
"div",
|
|
161
|
+
{
|
|
162
|
+
style: {
|
|
163
|
+
position: "fixed",
|
|
164
|
+
inset: 0,
|
|
165
|
+
zIndex: 2147483646,
|
|
166
|
+
display: "flex",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
justifyContent: "center",
|
|
169
|
+
backgroundColor: visible ? "rgba(0, 0, 0, 0.4)" : "rgba(0, 0, 0, 0)",
|
|
170
|
+
transition: "background-color 0.3s ease"
|
|
171
|
+
},
|
|
172
|
+
children: [
|
|
173
|
+
/* @__PURE__ */ jsx("style", { children: SHAKE_KEYFRAMES }),
|
|
174
|
+
/* @__PURE__ */ jsxs(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
style: {
|
|
178
|
+
display: "flex",
|
|
179
|
+
flexDirection: "column",
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
gap: "0",
|
|
182
|
+
zIndex: 2147483647,
|
|
183
|
+
opacity: visible ? 1 : 0,
|
|
184
|
+
transform: visible ? "scale(1)" : "scale(0.9)",
|
|
185
|
+
transition: "opacity 0.3s ease, transform 0.3s ease",
|
|
186
|
+
animation: shaking ? "prosopo-puzzle-shake 0.5s ease" : "none"
|
|
187
|
+
},
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ jsx(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
style: {
|
|
193
|
+
backgroundColor: "#fff",
|
|
194
|
+
borderRadius: "8px 8px 0 0",
|
|
195
|
+
padding: "12px 20px",
|
|
196
|
+
width: `${CONTAINER_WIDTH}px`,
|
|
197
|
+
boxSizing: "border-box",
|
|
198
|
+
textAlign: "center",
|
|
199
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
200
|
+
fontSize: "14px",
|
|
201
|
+
fontWeight: 500,
|
|
202
|
+
color: headerTextColor,
|
|
203
|
+
borderBottom: `2px solid ${headerBorderColor}`,
|
|
204
|
+
boxShadow: "0px 11px 15px -7px rgba(0,0,0,0.2), 0px 24px 38px 3px rgba(0,0,0,0.14), 0px 9px 46px 8px rgba(0,0,0,0.12)",
|
|
205
|
+
transition: "color 0.3s ease, border-color 0.3s ease"
|
|
206
|
+
},
|
|
207
|
+
children: instructionText
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
/* @__PURE__ */ jsxs(
|
|
211
|
+
"div",
|
|
212
|
+
{
|
|
213
|
+
ref: containerRef,
|
|
214
|
+
style: {
|
|
215
|
+
position: "relative",
|
|
216
|
+
width: `${CONTAINER_WIDTH}px`,
|
|
217
|
+
height: `${CONTAINER_HEIGHT}px`,
|
|
218
|
+
background: "linear-gradient(135deg, #e8eaf6 0%, #c5cae9 50%, #e8eaf6 100%)",
|
|
219
|
+
borderRadius: "0 0 8px 8px",
|
|
220
|
+
overflow: "hidden",
|
|
221
|
+
userSelect: "none",
|
|
222
|
+
boxShadow: "0px 11px 15px -7px rgba(0,0,0,0.2), 0px 24px 38px 3px rgba(0,0,0,0.14), 0px 9px 46px 8px rgba(0,0,0,0.12)",
|
|
223
|
+
opacity: submitting ? 0.6 : 1,
|
|
224
|
+
pointerEvents: submitting ? "none" : "auto",
|
|
225
|
+
transition: "opacity 0.2s ease"
|
|
226
|
+
},
|
|
227
|
+
children: [
|
|
228
|
+
/* @__PURE__ */ jsx(
|
|
229
|
+
"div",
|
|
230
|
+
{
|
|
231
|
+
style: {
|
|
232
|
+
position: "absolute",
|
|
233
|
+
left: `${targetX - TARGET_SIZE / 2}px`,
|
|
234
|
+
top: `${targetY - TARGET_SIZE / 2}px`,
|
|
235
|
+
width: `${TARGET_SIZE}px`,
|
|
236
|
+
height: `${TARGET_SIZE}px`,
|
|
237
|
+
borderRadius: "50%",
|
|
238
|
+
border: "2px dashed rgba(74, 144, 217, 0.6)",
|
|
239
|
+
backgroundColor: "rgba(74, 144, 217, 0.08)",
|
|
240
|
+
boxSizing: "border-box"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
/* @__PURE__ */ jsx(
|
|
245
|
+
"div",
|
|
246
|
+
{
|
|
247
|
+
onMouseDown: handlePieceMouseDown,
|
|
248
|
+
onTouchStart: handlePieceTouchStart,
|
|
249
|
+
style: {
|
|
250
|
+
position: "absolute",
|
|
251
|
+
left: `${posX - PIECE_SIZE / 2}px`,
|
|
252
|
+
top: `${posY - PIECE_SIZE / 2}px`,
|
|
253
|
+
width: `${PIECE_SIZE}px`,
|
|
254
|
+
height: `${PIECE_SIZE}px`,
|
|
255
|
+
borderRadius: "50%",
|
|
256
|
+
background: "radial-gradient(circle at 40% 40%, #6ab0ff, #4a90d9)",
|
|
257
|
+
cursor: submitting ? "default" : isDragging.current ? "grabbing" : "grab",
|
|
258
|
+
boxShadow: isDragging.current ? "0 4px 12px rgba(74, 144, 217, 0.5)" : "0 2px 6px rgba(74, 144, 217, 0.3)",
|
|
259
|
+
transition: isDragging.current ? "none" : "box-shadow 0.2s ease, left 0.3s ease, top 0.3s ease"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
export {
|
|
274
|
+
PuzzleCanvas
|
|
205
275
|
};
|
|
206
|
-
//# sourceMappingURL=PuzzleCanvas.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "./components/ProcaptchaWidget.js";
|
|
2
|
+
import { ProcaptchaPuzzle } from "./components/ProcaptchaPuzzle.js";
|
|
3
|
+
export {
|
|
4
|
+
ProcaptchaPuzzle
|
|
5
|
+
};
|