@faable/challenge 1.2.0 → 1.3.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/dist/api.js +2 -2
- package/dist/api.js.map +2 -2
- package/dist/index.js +17 -2
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -303,11 +303,26 @@ var announce = (state, onChallenge) => {
|
|
|
303
303
|
);
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
+
var announceBadge = (state) => {
|
|
307
|
+
if (typeof window !== "undefined" && typeof CustomEvent === "function") {
|
|
308
|
+
window.dispatchEvent(
|
|
309
|
+
new CustomEvent(CHALLENGE_EVENT, { detail: { state } })
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
306
313
|
var postWithChallenge = async (send, onChallenge) => {
|
|
307
314
|
var _a;
|
|
308
|
-
|
|
315
|
+
announceBadge("solving");
|
|
316
|
+
let first;
|
|
317
|
+
try {
|
|
318
|
+
first = await send();
|
|
319
|
+
} catch (e) {
|
|
320
|
+
announceBadge("idle");
|
|
321
|
+
throw e;
|
|
322
|
+
}
|
|
309
323
|
const details = (_a = first.data) == null ? void 0 : _a.details;
|
|
310
324
|
if (!first.error || first.code !== "challenge_required" && first.code !== "challenge_invalid" || !isChallengeDetails(details)) {
|
|
325
|
+
announceBadge(first.error ? "idle" : "done");
|
|
311
326
|
return first;
|
|
312
327
|
}
|
|
313
328
|
announce("solving", onChallenge);
|
|
@@ -1422,7 +1437,7 @@ var mountChallengeWidget = (el, opts = {}, driver = {}) => {
|
|
|
1422
1437
|
pending = null;
|
|
1423
1438
|
}
|
|
1424
1439
|
const shown = Date.now() - solvingSince;
|
|
1425
|
-
if (state === "solving" && (next === "done" || next === "error") && shown < MIN_SOLVING_MS && !reducedMotion()) {
|
|
1440
|
+
if (state === "solving" && (next === "done" || next === "error" || next === "idle") && shown < MIN_SOLVING_MS && !reducedMotion()) {
|
|
1426
1441
|
pending = setTimeout(() => {
|
|
1427
1442
|
pending = null;
|
|
1428
1443
|
apply(next);
|