@mochabug/adapt-web 1.0.1-rc.24 → 1.0.1-rc.26
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/README.md +15 -15
- package/dist/esm/cap-adapter.js +1 -1
- package/dist/umd/adapt-web.cap.js +63 -60
- package/dist/umd/adapt-web.cap.js.br +0 -0
- package/dist/umd/adapt-web.cap.min.js +5 -5
- package/dist/umd/adapt-web.cap.min.js.br +0 -0
- package/dist/umd/adapt-web.js +63 -60
- package/dist/umd/adapt-web.js.br +0 -0
- package/dist/umd/adapt-web.min.js +6 -6
- package/dist/umd/adapt-web.min.js.br +0 -0
- package/package.json +7 -7
package/dist/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Embed Adapt automations in any website.
|
|
|
6
6
|
npm install @mochabug/adapt-web
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
**CDN base:** `https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
9
|
+
**CDN base:** `https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/`
|
|
10
10
|
|
|
11
11
|
| Bundle | File | Includes |
|
|
12
12
|
|--------|------|----------|
|
|
@@ -20,8 +20,8 @@ npm install @mochabug/adapt-web
|
|
|
20
20
|
Bundles merge into a single `MbAdapt` global, so you can combine them. For example, headless + Cap for automations that need proof-of-work but no UI:
|
|
21
21
|
|
|
22
22
|
```html
|
|
23
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
24
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
23
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-core.min.js"></script>
|
|
24
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.cap.min.js"></script>
|
|
25
25
|
<script>
|
|
26
26
|
// MbAdapt has exports from both scripts
|
|
27
27
|
var client = MbAdapt.createAdaptClient(
|
|
@@ -43,12 +43,12 @@ Preload the script and load the stylesheet in `<head>` to eliminate flash of uns
|
|
|
43
43
|
|
|
44
44
|
```html
|
|
45
45
|
<head>
|
|
46
|
-
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
47
|
-
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
46
|
+
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.min.js" as="script">
|
|
47
|
+
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/styles.css">
|
|
48
48
|
</head>
|
|
49
49
|
<body>
|
|
50
50
|
<adapt-automation automation-id="YOUR_ID" requires-challenge style="height: 600px"></adapt-automation>
|
|
51
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
51
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.min.js"></script>
|
|
52
52
|
</body>
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -56,12 +56,12 @@ No challenges? Use the core bundle and drop `requires-challenge`:
|
|
|
56
56
|
|
|
57
57
|
```html
|
|
58
58
|
<head>
|
|
59
|
-
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
60
|
-
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
59
|
+
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.core.min.js" as="script">
|
|
60
|
+
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/styles.css">
|
|
61
61
|
</head>
|
|
62
62
|
<body>
|
|
63
63
|
<adapt-automation automation-id="YOUR_ID" style="height: 600px"></adapt-automation>
|
|
64
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
64
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.core.min.js"></script>
|
|
65
65
|
</body>
|
|
66
66
|
```
|
|
67
67
|
|
|
@@ -71,14 +71,14 @@ Just the element and script. CSS is auto-injected at runtime.
|
|
|
71
71
|
|
|
72
72
|
```html
|
|
73
73
|
<adapt-automation automation-id="YOUR_ID" requires-challenge style="height: 600px"></adapt-automation>
|
|
74
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
74
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.min.js"></script>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Without challenges:
|
|
78
78
|
|
|
79
79
|
```html
|
|
80
80
|
<adapt-automation automation-id="YOUR_ID" style="height: 600px"></adapt-automation>
|
|
81
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
81
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.core.min.js"></script>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
### ESM
|
|
@@ -160,12 +160,12 @@ Requires a `client` JS property — set it after the element is in the DOM.
|
|
|
160
160
|
|
|
161
161
|
```html
|
|
162
162
|
<head>
|
|
163
|
-
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
164
|
-
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
163
|
+
<link rel="preload" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.cap.min.js" as="script">
|
|
164
|
+
<link rel="stylesheet" href="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/styles.css">
|
|
165
165
|
</head>
|
|
166
166
|
<body>
|
|
167
167
|
<adapt-cap automation-id="YOUR_ID"></adapt-cap>
|
|
168
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
168
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.cap.min.js"></script>
|
|
169
169
|
<script>
|
|
170
170
|
var el = document.querySelector('adapt-cap');
|
|
171
171
|
el.client = MbAdapt.createConnectClient({ id: 'YOUR_ID' });
|
|
@@ -180,7 +180,7 @@ Requires a `client` JS property — set it after the element is in the DOM.
|
|
|
180
180
|
|
|
181
181
|
```html
|
|
182
182
|
<adapt-cap automation-id="YOUR_ID"></adapt-cap>
|
|
183
|
-
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
183
|
+
<script src="https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/adapt-web.cap.min.js"></script>
|
|
184
184
|
<script>
|
|
185
185
|
var el = document.querySelector('adapt-cap');
|
|
186
186
|
el.client = MbAdapt.createConnectClient({ id: 'YOUR_ID' });
|
package/dist/esm/cap-adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
typeof window<"u"&&!window.CAP_CUSTOM_WASM_URL&&(window.CAP_CUSTOM_WASM_URL=new URL("https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
1
|
+
typeof window<"u"&&!window.CAP_CUSTOM_WASM_URL&&(window.CAP_CUSTOM_WASM_URL=new URL("https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/cap_wasm_bg.wasm",window.location.href).href);import{timestampDate}from"@bufbuild/protobuf/wkt";let currentClient=null,currentAutomationId=null;const verificationTokens=new Map;async function createChallenge(client,id){const response=await client.createChallenge({id});return{count:response.count,size:response.size,difficulty:response.difficulty,expires:response.expires?timestampDate(response.expires):new Date,token:response.token,verificationToken:response.verificationToken}}async function redeemChallenge(client,id,verificationToken,solutions){const response=await client.redeemChallenge({id,verificationToken,solutions});return{token:response.token,expires:response.expires?timestampDate(response.expires):new Date}}typeof window<"u"&&(window.CAP_CUSTOM_FETCH=async(url,options)=>{const urlStr=url.toString();if(urlStr.endsWith("/challenge")){if(!currentClient||!currentAutomationId)return new Response(JSON.stringify({error:"Cap adapter not initialized"}),{status:500,headers:{"Content-Type":"application/json"}});try{const challengeInfo=await createChallenge(currentClient,currentAutomationId);return verificationTokens.set(currentAutomationId,challengeInfo.verificationToken),new Response(JSON.stringify({challenge:{c:challengeInfo.count,s:challengeInfo.size,d:challengeInfo.difficulty},token:challengeInfo.token,expires:challengeInfo.expires.toISOString()}),{status:200,headers:{"Content-Type":"application/json"}})}catch(error){return new Response(JSON.stringify({error:String(error)}),{status:500,headers:{"Content-Type":"application/json"}})}}if(urlStr.endsWith("/redeem")){if(!currentClient||!currentAutomationId)return new Response(JSON.stringify({error:"Cap adapter not initialized"}),{status:500,headers:{"Content-Type":"application/json"}});const verificationToken=verificationTokens.get(currentAutomationId);if(!verificationToken)return new Response(JSON.stringify({error:"No verification token found - challenge must be created first"}),{status:400,headers:{"Content-Type":"application/json"}});try{const solutions=((options?.body?JSON.parse(options.body):{}).solutions||[]).map(s=>BigInt(s)),redeemed=await redeemChallenge(currentClient,currentAutomationId,verificationToken,solutions);return verificationTokens.delete(currentAutomationId),new Response(JSON.stringify({success:!0,token:redeemed.token,expires:redeemed.expires.toISOString()}),{status:200,headers:{"Content-Type":"application/json"}})}catch(error){return new Response(JSON.stringify({error:String(error)}),{status:500,headers:{"Content-Type":"application/json"}})}}return fetch(url,options)});function setupCapAdapter(client,automationId){currentClient=client,currentAutomationId=automationId}function cleanupCapAdapter(){currentAutomationId&&verificationTokens.delete(currentAutomationId),currentClient=null,currentAutomationId=null}export{cleanupCapAdapter,createChallenge,redeemChallenge,setupCapAdapter};
|
|
@@ -46,7 +46,7 @@ var MbAdapt = (() => {
|
|
|
46
46
|
var require_cap_min = __commonJS({
|
|
47
47
|
"../node_modules/@cap.js/widget/cap.min.js"(exports, module) {
|
|
48
48
|
(() => {
|
|
49
|
-
var _e, _t, _i, _s, _r, _a, _n, _o, _l, _c, _h, _c_instances,
|
|
49
|
+
var _e, _t, _i, _s, _r, _a, _n, _o, _l, _c, _h, _c_instances, d_get, p_fn, u_fn, g_fn, v_fn, b_fn, m_fn, w_fn, f_fn, y_fn;
|
|
50
50
|
const e = "vibrate" in navigator && !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
51
51
|
if ("undefined" == typeof window) return;
|
|
52
52
|
const t = (e2, t2 = {}) => window?.CAP_CUSTOM_FETCH ? window.CAP_CUSTOM_FETCH(e2, t2) : fetch(e2, t2);
|
|
@@ -200,7 +200,7 @@ var MbAdapt = (() => {
|
|
|
200
200
|
return ["onsolve", "onprogress", "onreset", "onerror", "data-cap-worker-count", "data-cap-i18n-initial-state"];
|
|
201
201
|
}
|
|
202
202
|
initialize() {
|
|
203
|
-
o(), __privateGet(this, _o) || __privateSet(this, _o, __privateMethod(this, _c_instances,
|
|
203
|
+
o(), __privateGet(this, _o) || __privateSet(this, _o, __privateMethod(this, _c_instances, p_fn).call(this)), __privateGet(this, _c) || (__privateSet(this, _c, new l(1)), __privateGet(this, _c)._spawn());
|
|
204
204
|
}
|
|
205
205
|
attributeChangedCallback(e2, t2, i2) {
|
|
206
206
|
if (e2.startsWith("on")) {
|
|
@@ -220,73 +220,73 @@ var MbAdapt = (() => {
|
|
|
220
220
|
const e2 = this.getAttribute("data-cap-worker-count"), t2 = e2 ? parseInt(e2, 10) : null;
|
|
221
221
|
this.setWorkersCount(t2 || navigator.hardwareConcurrency || 8);
|
|
222
222
|
const i2 = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
223
|
-
__privateGet(this, _r).innerHTML = `<input type="hidden" name="${i2}">`, __privateMethod(this, _c_instances,
|
|
223
|
+
__privateGet(this, _r).innerHTML = `<input type="hidden" name="${i2}">`, __privateMethod(this, _c_instances, v_fn).call(this);
|
|
224
224
|
}
|
|
225
225
|
async solve() {
|
|
226
226
|
if (!__privateGet(this, _a)) try {
|
|
227
227
|
__privateSet(this, _a, true), this.updateUI("verifying", this.getI18nText("verifying-label", "Verifying..."), true), __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("verifying-aria-label", "Verifying you're a human, please wait")), this.dispatchEvent("progress", { progress: 0 });
|
|
228
228
|
try {
|
|
229
|
-
let r2, a2
|
|
230
|
-
if (!
|
|
231
|
-
else if (!
|
|
232
|
-
if (
|
|
229
|
+
let e2, r2, a2 = this.getAttribute("data-cap-api-endpoint");
|
|
230
|
+
if (!a2 && window?.CAP_CUSTOM_FETCH) a2 = "/";
|
|
231
|
+
else if (!a2) throw new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");
|
|
232
|
+
if (a2.endsWith("/") || (a2 += "/"), "done" === __privateGet(this, _o).state && __privateGet(this, _o).token && __privateGet(this, _o).tokenExpires && Date.now() < __privateGet(this, _o).tokenExpires) {
|
|
233
233
|
this.dispatchEvent("progress", { progress: 100 });
|
|
234
|
-
const
|
|
235
|
-
this.querySelector(`input[name='${
|
|
236
|
-
const
|
|
237
|
-
return __privateGet(this, _e) && clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, setTimeout(() => this.reset(),
|
|
234
|
+
const e3 = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
235
|
+
this.querySelector(`input[name='${e3}']`) && (this.querySelector(`input[name='${e3}']`).value = __privateGet(this, _o).token), this.dispatchEvent("solve", { token: __privateGet(this, _o).token }), this.token = __privateGet(this, _o).token;
|
|
236
|
+
const t2 = __privateGet(this, _o).tokenExpires - Date.now();
|
|
237
|
+
return __privateGet(this, _e) && clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, setTimeout(() => this.reset(), t2)), __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("verified-aria-label", "We have verified you're a human, you may now continue")), __privateGet(this, _c_instances, d_get) && navigator.vibrate([10, 50, 20, 30, 40]), __privateMethod(this, _c_instances, u_fn).call(this), __privateSet(this, _a, false), { success: true, token: this.token };
|
|
238
238
|
}
|
|
239
|
-
if ("done" === __privateGet(this, _o).state)
|
|
239
|
+
if ("done" === __privateGet(this, _o).state) e2 = __privateGet(this, _o).results, r2 = __privateGet(this, _o).challengeResp, this.dispatchEvent("progress", { progress: 100 });
|
|
240
240
|
else if ("solving" === __privateGet(this, _o).state || "redeeming" === __privateGet(this, _o).state || "fetching" === __privateGet(this, _o).state || "waiting" === __privateGet(this, _o).state) {
|
|
241
|
-
"waiting" === __privateGet(this, _o).state && (__privateGet(this, _l) && (clearTimeout(__privateGet(this, _l)), __privateSet(this, _l, null)), __privateGet(this, _o).state = "waiting", __privateMethod(this, _c_instances,
|
|
241
|
+
"waiting" === __privateGet(this, _o).state && (__privateGet(this, _l) && (clearTimeout(__privateGet(this, _l)), __privateSet(this, _l, null)), __privateGet(this, _o).state = "waiting", __privateMethod(this, _c_instances, w_fn).call(this)), __privateGet(this, _o).pendingPromotion = __privateGet(this, _t), __privateGet(this, _o).promoteFn && __privateGet(this, _o).promoteFn(__privateGet(this, _t));
|
|
242
242
|
const t2 = setInterval(() => {
|
|
243
243
|
if ("solving" !== __privateGet(this, _o).state && "redeeming" !== __privateGet(this, _o).state) return void clearInterval(t2);
|
|
244
|
-
const
|
|
244
|
+
const e3 = __privateGet(this, _o).challenges ? __privateGet(this, _o).challenges.length : 1, i2 = __privateGet(this, _o).completedCount, s2 = "redeeming" === __privateGet(this, _o).state ? 99 : Math.min(98, Math.round(i2 / e3 * 100));
|
|
245
245
|
this.dispatchEvent("progress", { progress: s2 });
|
|
246
246
|
}, 150);
|
|
247
|
-
if (await new Promise((
|
|
247
|
+
if (await new Promise((e3) => __privateGet(this, _o).onSettled(e3)), clearInterval(t2), "done" !== __privateGet(this, _o).state) throw new Error("Speculative solve failed \u2013 please try again");
|
|
248
248
|
if (__privateGet(this, _o).token && __privateGet(this, _o).tokenExpires && Date.now() < __privateGet(this, _o).tokenExpires) {
|
|
249
249
|
this.dispatchEvent("progress", { progress: 100 });
|
|
250
|
-
const
|
|
251
|
-
this.querySelector(`input[name='${
|
|
252
|
-
const
|
|
253
|
-
return __privateGet(this, _e) && clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, setTimeout(() => this.reset(),
|
|
250
|
+
const e3 = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
251
|
+
this.querySelector(`input[name='${e3}']`) && (this.querySelector(`input[name='${e3}']`).value = __privateGet(this, _o).token), this.dispatchEvent("solve", { token: __privateGet(this, _o).token }), this.token = __privateGet(this, _o).token;
|
|
252
|
+
const t3 = __privateGet(this, _o).tokenExpires - Date.now();
|
|
253
|
+
return __privateGet(this, _e) && clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, setTimeout(() => this.reset(), t3)), __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("verified-aria-label", "We have verified you're a human, you may now continue")), __privateGet(this, _c_instances, d_get) && navigator.vibrate([10, 50, 20, 30, 40]), __privateMethod(this, _c_instances, u_fn).call(this), __privateSet(this, _a, false), { success: true, token: this.token };
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
e2 = __privateGet(this, _o).results, r2 = __privateGet(this, _o).challengeResp, this.dispatchEvent("progress", { progress: 100 });
|
|
256
256
|
} else {
|
|
257
|
-
const
|
|
257
|
+
const s2 = await t(`${a2}challenge`, { method: "POST" });
|
|
258
258
|
try {
|
|
259
|
-
|
|
259
|
+
r2 = await s2.json();
|
|
260
260
|
} catch {
|
|
261
261
|
throw new Error("Failed to parse challenge response from server");
|
|
262
262
|
}
|
|
263
|
-
if (
|
|
264
|
-
const { challenge:
|
|
265
|
-
let l3 =
|
|
263
|
+
if (r2.error) throw new Error(r2.error);
|
|
264
|
+
const { challenge: n3, token: o3 } = r2;
|
|
265
|
+
let l3 = n3;
|
|
266
266
|
if (!Array.isArray(l3)) {
|
|
267
267
|
let e3 = 0;
|
|
268
|
-
l3 = Array.from({ length:
|
|
268
|
+
l3 = Array.from({ length: n3.c }, () => (e3++, [i(`${o3}${e3}`, n3.s), i(`${o3}${e3}d`, n3.d)]));
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
e2 = await this.solveChallenges(l3);
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
this.updateUIBlocked(this.getI18nText("error-label", "Error"),
|
|
275
|
-
const
|
|
276
|
-
return super.dispatchEvent(
|
|
272
|
+
const n2 = r2.instrumentation ? s(r2.instrumentation) : Promise.resolve(null), o2 = await n2;
|
|
273
|
+
if (o2?.__timeout || o2?.__blocked) {
|
|
274
|
+
this.updateUIBlocked(this.getI18nText("error-label", "Error"), o2?.__blocked), __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("error-aria-label", "An error occurred, please try again")), this.removeEventListener("error", this.boundHandleError);
|
|
275
|
+
const e3 = new CustomEvent("error", { bubbles: true, composed: true, detail: { isCap: true, message: "Instrumentation failed" } });
|
|
276
|
+
return super.dispatchEvent(e3), this.addEventListener("error", this.boundHandleError), this.executeAttributeCode("onerror", e3), console.error("[cap]", "Instrumentation failed"), void __privateSet(this, _a, false);
|
|
277
277
|
}
|
|
278
|
-
const { token:
|
|
279
|
-
let
|
|
278
|
+
const { token: l2 } = r2, c2 = await t(`${a2}redeem`, { method: "POST", body: JSON.stringify({ token: l2, solutions: e2, ...o2 && { instr: o2 } }), headers: { "Content-Type": "application/json" } });
|
|
279
|
+
let h2;
|
|
280
280
|
try {
|
|
281
|
-
|
|
281
|
+
h2 = await c2.json();
|
|
282
282
|
} catch {
|
|
283
283
|
throw new Error("Failed to parse server response");
|
|
284
284
|
}
|
|
285
|
-
if (this.dispatchEvent("progress", { progress: 100 }), !
|
|
286
|
-
const
|
|
287
|
-
this.querySelector(`input[name='${
|
|
288
|
-
const
|
|
289
|
-
return
|
|
285
|
+
if (this.dispatchEvent("progress", { progress: 100 }), !h2.success) throw new Error(h2.error || "Invalid solution");
|
|
286
|
+
const d = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
|
|
287
|
+
this.querySelector(`input[name='${d}']`) && (this.querySelector(`input[name='${d}']`).value = h2.token), this.dispatchEvent("solve", { token: h2.token }), this.token = h2.token, __privateMethod(this, _c_instances, u_fn).call(this), __privateGet(this, _e) && clearTimeout(__privateGet(this, _e));
|
|
288
|
+
const p = new Date(h2.expires).getTime() - Date.now();
|
|
289
|
+
return p > 0 && p < 864e5 ? __privateSet(this, _e, setTimeout(() => this.reset(), p)) : this.error("Invalid expiration time"), __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("verified-aria-label", "We have verified you're a human, you may now continue")), __privateGet(this, _c_instances, d_get) && navigator.vibrate([10, 50, 20, 30, 40]), { success: true, token: this.token };
|
|
290
290
|
} catch (e2) {
|
|
291
291
|
throw __privateGet(this, _s).setAttribute("aria-label", this.getI18nText("error-aria-label", "An error occurred, please try again")), this.error(e2.message), e2;
|
|
292
292
|
}
|
|
@@ -340,7 +340,7 @@ var MbAdapt = (() => {
|
|
|
340
340
|
}), __privateGet(this, _s).addEventListener("click", () => {
|
|
341
341
|
__privateGet(this, _s).hasAttribute("disabled") || this.solve();
|
|
342
342
|
}), __privateGet(this, _s).addEventListener("mousedown", () => {
|
|
343
|
-
!__privateGet(this, _s).hasAttribute("disabled") &&
|
|
343
|
+
!__privateGet(this, _s).hasAttribute("disabled") && __privateGet(this, _c_instances, d_get) && navigator.vibrate(5);
|
|
344
344
|
}), __privateGet(this, _s).addEventListener("keydown", (e2) => {
|
|
345
345
|
"Enter" !== e2.key && " " !== e2.key || __privateGet(this, _s).hasAttribute("disabled") || (e2.preventDefault(), e2.stopPropagation(), this.solve());
|
|
346
346
|
}), this.addEventListener("progress", this.boundHandleProgress), this.addEventListener("solve", this.boundHandleSolve), this.addEventListener("error", this.boundHandleError), this.addEventListener("reset", this.boundHandleReset));
|
|
@@ -393,8 +393,8 @@ var MbAdapt = (() => {
|
|
|
393
393
|
handleSolve(e2) {
|
|
394
394
|
this.updateUI("done", this.getI18nText("solved-label", "You're a human"), true), this.executeAttributeCode("onsolve", e2);
|
|
395
395
|
}
|
|
396
|
-
handleError(
|
|
397
|
-
this.updateUI("error", this.getI18nText("error-label", "Error. Try again.")), this.executeAttributeCode("onerror",
|
|
396
|
+
handleError(e2) {
|
|
397
|
+
this.updateUI("error", this.getI18nText("error-label", "Error. Try again.")), this.executeAttributeCode("onerror", e2), __privateGet(this, _c_instances, d_get) && navigator.vibrate([10, 40, 10]);
|
|
398
398
|
}
|
|
399
399
|
handleReset(e2) {
|
|
400
400
|
this.updateUI("", this.getI18nText("initial-state", "I'm a human")), this.executeAttributeCode("onreset", e2);
|
|
@@ -424,7 +424,7 @@ var MbAdapt = (() => {
|
|
|
424
424
|
}), __privateGet(this, _n).clear(), __privateGet(this, _i) && (__privateGet(this, _i).innerHTML = ""), this.reset(), this.cleanup();
|
|
425
425
|
}
|
|
426
426
|
cleanup() {
|
|
427
|
-
__privateGet(this, _e) && (clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, null)), __privateMethod(this, _c_instances,
|
|
427
|
+
__privateGet(this, _e) && (clearTimeout(__privateGet(this, _e)), __privateSet(this, _e, null)), __privateMethod(this, _c_instances, g_fn).call(this), __privateGet(this, _l) && (clearTimeout(__privateGet(this, _l)), __privateSet(this, _l, null)), __privateGet(this, _c) && (__privateGet(this, _c).terminate(), __privateSet(this, _c, null)), __privateGet(this, _o) && (__privateGet(this, _o).state = "error", __privateGet(this, _o).notify(), __privateSet(this, _o, null));
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
430
|
_e = new WeakMap();
|
|
@@ -439,7 +439,10 @@ var MbAdapt = (() => {
|
|
|
439
439
|
_c = new WeakMap();
|
|
440
440
|
_h = new WeakMap();
|
|
441
441
|
_c_instances = new WeakSet();
|
|
442
|
-
|
|
442
|
+
d_get = function() {
|
|
443
|
+
return e && !window.CAP_DISABLE_HAPTICS && !this.hasAttribute("data-cap-disable-haptics");
|
|
444
|
+
};
|
|
445
|
+
p_fn = function() {
|
|
443
446
|
return { state: "idle", challengeResp: null, challenges: null, results: [], completedCount: 0, solvePromise: null, promoteFn: null, _listeners: [], pendingPromotion: null, token: null, tokenExpires: null, notify() {
|
|
444
447
|
for (const e2 of this._listeners) e2();
|
|
445
448
|
this._listeners = [];
|
|
@@ -447,28 +450,28 @@ var MbAdapt = (() => {
|
|
|
447
450
|
"done" === this.state || "error" === this.state ? e2() : this._listeners.push(e2);
|
|
448
451
|
} };
|
|
449
452
|
};
|
|
450
|
-
|
|
451
|
-
__privateSet(this, _o, __privateMethod(this, _c_instances,
|
|
453
|
+
u_fn = function() {
|
|
454
|
+
__privateSet(this, _o, __privateMethod(this, _c_instances, p_fn).call(this)), __privateMethod(this, _c_instances, v_fn).call(this);
|
|
452
455
|
};
|
|
453
|
-
|
|
456
|
+
g_fn = function() {
|
|
454
457
|
__privateGet(this, _h) && (window.removeEventListener("mousemove", __privateGet(this, _h)), window.removeEventListener("touchstart", __privateGet(this, _h)), window.removeEventListener("keydown", __privateGet(this, _h)), __privateSet(this, _h, null));
|
|
455
458
|
};
|
|
456
|
-
|
|
457
|
-
__privateMethod(this, _c_instances,
|
|
459
|
+
v_fn = function() {
|
|
460
|
+
__privateMethod(this, _c_instances, g_fn).call(this);
|
|
458
461
|
const e2 = () => {
|
|
459
|
-
__privateMethod(this, _c_instances,
|
|
462
|
+
__privateMethod(this, _c_instances, g_fn).call(this), __privateMethod(this, _c_instances, m_fn).call(this);
|
|
460
463
|
};
|
|
461
464
|
__privateSet(this, _h, e2), window.addEventListener("mousemove", e2, { passive: true }), window.addEventListener("touchstart", e2, { passive: true }), window.addEventListener("keydown", e2, { passive: true });
|
|
462
465
|
};
|
|
463
|
-
|
|
466
|
+
b_fn = function() {
|
|
464
467
|
return "function" == typeof this.checkVisibility ? this.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) : !!(this.offsetParent || this.getClientRects().length > 0);
|
|
465
468
|
};
|
|
466
|
-
|
|
467
|
-
"idle" === __privateGet(this, _o).state && __privateMethod(this, _c_instances,
|
|
468
|
-
__privateMethod(this, _c_instances,
|
|
469
|
+
m_fn = function() {
|
|
470
|
+
"idle" === __privateGet(this, _o).state && __privateMethod(this, _c_instances, b_fn).call(this) && (__privateGet(this, _o).state = "waiting", __privateSet(this, _l, setTimeout(() => {
|
|
471
|
+
__privateMethod(this, _c_instances, w_fn).call(this);
|
|
469
472
|
}, 2500)));
|
|
470
473
|
};
|
|
471
|
-
|
|
474
|
+
w_fn = async function() {
|
|
472
475
|
if ("waiting" !== __privateGet(this, _o).state) return;
|
|
473
476
|
__privateGet(this, _o).state = "fetching";
|
|
474
477
|
let e2 = this.getAttribute("data-cap-api-endpoint");
|
|
@@ -518,9 +521,9 @@ var MbAdapt = (() => {
|
|
|
518
521
|
for (let e3 = 0; e3 < o2.length; e3++) s2[o2[e3]] = l2[e3];
|
|
519
522
|
!n2 && c2 < i2 && await new Promise((e3) => setTimeout(e3, 120));
|
|
520
523
|
}
|
|
521
|
-
return __privateGet(this, _o).results = s2, __privateGet(this, _o).state = "redeeming", __privateMethod(this, _c_instances,
|
|
524
|
+
return __privateGet(this, _o).results = s2, __privateGet(this, _o).state = "redeeming", __privateMethod(this, _c_instances, y_fn).call(this, s2), s2;
|
|
522
525
|
};
|
|
523
|
-
|
|
526
|
+
y_fn = async function(e2) {
|
|
524
527
|
try {
|
|
525
528
|
const i2 = __privateGet(this, _o).challengeResp, r2 = i2._apiEndpoint;
|
|
526
529
|
if (!r2) throw new Error("[cap] speculative redeem: missing apiEndpoint");
|
|
@@ -545,7 +548,7 @@ var MbAdapt = (() => {
|
|
|
545
548
|
if (Object.entries(e2).forEach(([e3, t3]) => {
|
|
546
549
|
i2.setAttribute(e3, t3);
|
|
547
550
|
}), !e2.apiEndpoint && !window?.CAP_CUSTOM_FETCH) throw i2.remove(), new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");
|
|
548
|
-
e2.apiEndpoint && i2.setAttribute("data-cap-api-endpoint", e2.apiEndpoint), this.widget = i2, this.solve = this.widget.solve.bind(this.widget), this.reset = this.widget.reset.bind(this.widget), this.addEventListener = this.widget.addEventListener.bind(this.widget), Object.defineProperty(this, "token", { get: () => i2.token, configurable: true, enumerable: true }), t2 || (i2.style.display = "none", document.documentElement.appendChild(i2));
|
|
551
|
+
e2.apiEndpoint && i2.setAttribute("data-cap-api-endpoint", e2.apiEndpoint), t2 || i2.hasAttribute("data-cap-disable-haptics") || i2.setAttribute("data-cap-disable-haptics", ""), this.widget = i2, this.solve = this.widget.solve.bind(this.widget), this.reset = this.widget.reset.bind(this.widget), this.addEventListener = this.widget.addEventListener.bind(this.widget), Object.defineProperty(this, "token", { get: () => i2.token, configurable: true, enumerable: true }), t2 || (i2.style.display = "none", document.documentElement.appendChild(i2));
|
|
549
552
|
}
|
|
550
553
|
}
|
|
551
554
|
window.Cap = h, customElements.get("cap-widget") || window?.CAP_DONT_SKIP_REDEFINE ? customElements.get("cap-widget") && console.warn("[cap] the cap-widget element has already been defined, skipping re-defining it.\nto prevent this, set window.CAP_DONT_SKIP_REDEFINE to true") : customElements.define("cap-widget", c), "object" == typeof exports && "undefined" != typeof module ? module.exports = h : "function" == typeof define && define.amd && define([], () => h), "undefined" != typeof exports && (exports.default = h);
|
|
@@ -4324,7 +4327,7 @@ var MbAdapt = (() => {
|
|
|
4324
4327
|
// src/cap-adapter.ts
|
|
4325
4328
|
if (typeof window !== "undefined" && true && !window.CAP_CUSTOM_WASM_URL) {
|
|
4326
4329
|
window.CAP_CUSTOM_WASM_URL = new URL(
|
|
4327
|
-
"https://cdn.mochabug.com/adapt/web/1.0.1-rc.
|
|
4330
|
+
"https://cdn.mochabug.com/adapt/web/1.0.1-rc.26/cap_wasm_bg.wasm",
|
|
4328
4331
|
window.location.href
|
|
4329
4332
|
).href;
|
|
4330
4333
|
}
|
|
Binary file
|