@mochabug/adapt-web
Version:
Browser client library for Adapt automation platform
3 lines • 284 kB
JavaScript
var __MbAdapt_prev = typeof MbAdapt !== 'undefined' ? MbAdapt : undefined;
"use strict";var MbAdapt=(()=>{var hi=Object.create;var Zt=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var yi=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Gi=Object.prototype.hasOwnProperty;var Lo=e=>{throw TypeError(e)};var Ai=(e,t,n)=>t in e?Zt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Zi=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(n){throw t=0,n}},Ci=(e,t)=>{for(var n in t)Zt(e,n,{get:t[n],enumerable:!0})},zo=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yi(t))!Gi.call(e,o)&&o!==n&&Zt(e,o,{get:()=>t[o],enumerable:!(r=fi(t,o))||r.enumerable});return e};var Vi=(e,t,n)=>(n=e!=null?hi(Ii(e)):{},zo(t||!e||!e.__esModule?Zt(n,"default",{value:e,enumerable:!0}):n,e)),Si=e=>zo(Zt({},"__esModule",{value:!0}),e);var rr=(e,t,n)=>Ai(e,typeof t!="symbol"?t+"":t,n),or=(e,t,n)=>t.has(e)||Lo("Cannot "+n);var i=(e,t,n)=>(or(e,t,"read from private field"),n?n.call(e):t.get(e)),te=(e,t,n)=>t.has(e)?Lo("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),U=(e,t,n,r)=>(or(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),K=(e,t,n)=>(or(e,t,"access private method"),n);var Cs=Zi((Xn,ao)=>{(()=>{var ae,ue,le,M,F,P,ie,Ye,Fe,Ie,Ne,h,Ge,ce,Ee,Gt,He,C,at,jr,$r,Zn,qr,eo,to,ys,no,Is,Gs,ro,Cn,oo,As,Vn,tn,Zs,Sn;let e="vibrate"in navigator&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(typeof window>"u")return;let t=["#f5c2e7","#cba6f7","#f38ba8","#fab387","#f9e2af","#a6e3a1","#94e2d5","#89dceb","#b4befe"],n=(Q,Z,m)=>{let p=Z===0?"9999px":"0",y=Z===m-1?"9999px":"0";return`color:#1e1e2e;background:${(f=>{if(f==="cap")return"#89b4fa";let I=0;for(let V=0;V<f.length;V++)I=f.charCodeAt(V)+((I<<5)-I);return t[Math.abs(I)%t.length]})(Q)};margin-left:${Z?"-6px":0};padding:0 6px;border-radius:${p} ${y} ${y} ${p};font-weight:600`},r={};for(let Q of["debug","info","warn","error"])r[Q]=(Z,...m)=>{if(window.CAP_SILENT||Q==="debug"&&!window.CAP_DEBUG)return;let p=Z.map(f=>`%c${f}`).join(" "),y=Z.map((f,I)=>n(f,I,Z.length));console[Q==="debug"?"log":Q](p,...y,...m)};let o=Q=>Q?["cap",Q]:["cap"],a=Q=>`${Math.round(performance.now()-Q)}ms`,s=(Q,Z)=>Object.assign(new Error(Z),{code:Q}),c=(Q,Z={})=>window?.CAP_CUSTOM_FETCH?window.CAP_CUSTOM_FETCH(Q,Z):fetch(Q,Z),u=(Q,Z)=>Z?Z.aborted?Promise.reject(s("aborted","aborted")):Promise.race([Q,new Promise((m,p)=>Z.addEventListener("abort",()=>p(s("aborted","aborted")),{once:!0}))]):Q,g="initial-state,verifying-label,solved-label,error-label,required-label,troubleshooting-label,group-aria-label,verify-aria-label,verifying-aria-label,verified-aria-label,error-aria-label".split(","),S={"zh-cn":"\u786E\u8BA4\u4F60\u662F\u771F\u4EBA/\u6B63\u5728\u9A8C\u8BC1.../\u4F60\u662F\u771F\u4EBA/\u51FA\u9519\u4E86\u3002\u8BF7\u91CD\u8BD5\u3002/\u8BF7\u786E\u8BA4\u4F60\u662F\u771F\u4EBA/\u6545\u969C\u6392\u9664/Cap \u9A8C\u8BC1/\u70B9\u51FB\u4EE5\u786E\u8BA4\u4F60\u662F\u771F\u4EBA/\u6B63\u5728\u9A8C\u8BC1\u4F60\u662F\u771F\u4EBA\uFF0C\u8BF7\u7A0D\u5019/\u6211\u4EEC\u5DF2\u786E\u8BA4\u4F60\u662F\u771F\u4EBA\uFF0C\u4F60\u53EF\u4EE5\u7EE7\u7EED\u4E86/\u53D1\u751F\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5",es:"Verifica que eres humano/Verificando.../Eres humano/Error. Int\xE9ntalo de nuevo./Verifica que eres humano/Solucionar problemas/Verificaci\xF3n de Cap/Haz clic para verificar que eres humano/Verificando que eres humano, espera/Hemos verificado que eres humano, ya puedes continuar/Se produjo un error, int\xE9ntalo de nuevo",hi:"\u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930\u0947\u0902 \u0915\u093F \u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902/\u0938\u0924\u094D\u092F\u093E\u092A\u093F\u0924 \u0939\u094B \u0930\u0939\u093E \u0939\u0948.../\u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902/\u0924\u094D\u0930\u0941\u091F\u093F\u0964 \u092A\u0941\u0928\u0903 \u092A\u094D\u0930\u092F\u093E\u0938 \u0915\u0930\u0947\u0902\u0964/\u0915\u0943\u092A\u092F\u093E \u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930\u0947\u0902 \u0915\u093F \u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902/\u0938\u092E\u0938\u094D\u092F\u093E \u0928\u093F\u0935\u093E\u0930\u0923/Cap \u0938\u0924\u094D\u092F\u093E\u092A\u0928/\u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093F\u090F \u0915\u094D\u0932\u093F\u0915 \u0915\u0930\u0947\u0902 \u0915\u093F \u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902/\u0938\u0924\u094D\u092F\u093E\u092A\u093F\u0924 \u0915\u093F\u092F\u093E \u091C\u093E \u0930\u0939\u093E \u0939\u0948 \u0915\u093F \u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902, \u092A\u094D\u0930\u0924\u0940\u0915\u094D\u0937\u093E \u0915\u0930\u0947\u0902/\u0939\u092E\u0928\u0947 \u092A\u0941\u0937\u094D\u091F\u093F \u0915\u0930 \u0926\u0940 \u0939\u0948 \u0915\u093F \u0906\u092A \u092E\u093E\u0928\u0935 \u0939\u0948\u0902, \u0905\u092C \u0906\u092A \u091C\u093E\u0930\u0940 \u0930\u0916 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902/\u090F\u0915 \u0924\u094D\u0930\u0941\u091F\u093F \u0939\u0941\u0908, \u092A\u0941\u0928\u0903 \u092A\u094D\u0930\u092F\u093E\u0938 \u0915\u0930\u0947\u0902",ar:"\u062A\u062D\u0642\u0642 \u0645\u0646 \u0623\u0646\u0643 \u0625\u0646\u0633\u0627\u0646/\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u062D\u0642\u0642.../\u0623\u0646\u062A \u0625\u0646\u0633\u0627\u0646/\u062E\u0637\u0623. \u062D\u0627\u0648\u0644 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649./\u064A\u0631\u062C\u0649 \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0623\u0646\u0643 \u0625\u0646\u0633\u0627\u0646/\u0627\u0633\u062A\u0643\u0634\u0627\u0641 \u0627\u0644\u0623\u062E\u0637\u0627\u0621 \u0648\u0625\u0635\u0644\u0627\u062D\u0647\u0627/\u062A\u062D\u0642\u0642 Cap/\u0627\u0646\u0642\u0631 \u0644\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0623\u0646\u0643 \u0625\u0646\u0633\u0627\u0646/\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u062D\u0642\u0642 \u0645\u0646 \u0623\u0646\u0643 \u0625\u0646\u0633\u0627\u0646\u060C \u064A\u0631\u062C\u0649 \u0627\u0644\u0627\u0646\u062A\u0638\u0627\u0631/\u0644\u0642\u062F \u062A\u062D\u0642\u0642\u0646\u0627 \u0645\u0646 \u0623\u0646\u0643 \u0625\u0646\u0633\u0627\u0646\u060C \u064A\u0645\u0643\u0646\u0643 \u0627\u0644\u0645\u062A\u0627\u0628\u0639\u0629 \u0627\u0644\u0622\u0646/\u062D\u062F\u062B \u062E\u0637\u0623\u060C \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649",pt:"Sou humano/Verificando.../Voc\xEA \xE9 humano/Erro. Tente novamente./Verifique que voc\xEA \xE9 humano/Solu\xE7\xE3o de problemas/Verifica\xE7\xE3o Cap/Clique para verificar que voc\xEA \xE9 humano/Verificando que voc\xEA \xE9 humano, aguarde/Verificamos que voc\xEA \xE9 humano, voc\xEA pode continuar/Ocorreu um erro, tente novamente",ru:"\u042F \u0447\u0435\u043B\u043E\u0432\u0435\u043A/\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430.../\u0412\u044B \u0447\u0435\u043B\u043E\u0432\u0435\u043A/\u041E\u0448\u0438\u0431\u043A\u0430. \u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435./\u041F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u0435, \u0447\u0442\u043E \u0432\u044B \u0447\u0435\u043B\u043E\u0432\u0435\u043A/\u0423\u0441\u0442\u0440\u0430\u043D\u0435\u043D\u0438\u0435 \u043D\u0435\u043F\u043E\u043B\u0430\u0434\u043E\u043A/\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 Cap/\u041D\u0430\u0436\u043C\u0438\u0442\u0435, \u0447\u0442\u043E\u0431\u044B \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044C, \u0447\u0442\u043E \u0432\u044B \u0447\u0435\u043B\u043E\u0432\u0435\u043A/\u041F\u0440\u043E\u0432\u0435\u0440\u044F\u0435\u043C, \u0447\u0442\u043E \u0432\u044B \u0447\u0435\u043B\u043E\u0432\u0435\u043A, \u043F\u043E\u0434\u043E\u0436\u0434\u0438\u0442\u0435/\u041C\u044B \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043B\u0438, \u0447\u0442\u043E \u0432\u044B \u0447\u0435\u043B\u043E\u0432\u0435\u043A, \u043C\u043E\u0436\u0435\u0442\u0435 \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C/\u041F\u0440\u043E\u0438\u0437\u043E\u0448\u043B\u0430 \u043E\u0448\u0438\u0431\u043A\u0430, \u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0435 \u043F\u043E\u043F\u044B\u0442\u043A\u0443",ja:"\u79C1\u306F\u4EBA\u9593\u3067\u3059/\u78BA\u8A8D\u4E2D.../\u3042\u306A\u305F\u306F\u4EBA\u9593\u3067\u3059/\u30A8\u30E9\u30FC\u3002\u518D\u8A66\u884C\u3092\u3002/\u3042\u306A\u305F\u304C\u4EBA\u9593\u3067\u3042\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044/\u30C8\u30E9\u30D6\u30EB\u30B7\u30E5\u30FC\u30C6\u30A3\u30F3\u30B0/Cap \u8A8D\u8A3C/\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u4EBA\u9593\u3067\u3042\u308B\u3053\u3068\u3092\u78BA\u8A8D/\u3042\u306A\u305F\u304C\u4EBA\u9593\u3067\u3042\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u3066\u3044\u307E\u3059\u3002\u304A\u5F85\u3061\u304F\u3060\u3055\u3044/\u3042\u306A\u305F\u304C\u4EBA\u9593\u3067\u3042\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u307E\u3057\u305F\u3002\u7D9A\u884C\u3067\u304D\u307E\u3059/\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044",de:"Ich bin ein Mensch/Wird \xFCberpr\xFCft.../Sie sind ein Mensch/Fehler. Erneut versuchen./Bitte best\xE4tigen Sie, dass Sie ein Mensch sind/Fehlerbehebung/Cap-Verifizierung/Klicken, um zu best\xE4tigen, dass Sie ein Mensch sind/\xDCberpr\xFCfung, ob Sie ein Mensch sind, bitte warten/Wir haben best\xE4tigt, dass Sie ein Mensch sind, Sie k\xF6nnen fortfahren/Ein Fehler ist aufgetreten, bitte erneut versuchen",fr:"Je suis humain/V\xE9rification.../Vous \xEAtes humain/Erreur. R\xE9essayez./Veuillez v\xE9rifier que vous \xEAtes humain/D\xE9pannage/V\xE9rification Cap/Cliquez pour v\xE9rifier que vous \xEAtes humain/V\xE9rification que vous \xEAtes humain, veuillez patienter/Nous avons v\xE9rifi\xE9 que vous \xEAtes humain, vous pouvez continuer/Une erreur s'est produite, veuillez r\xE9essayer"};function x(Q,Z){let m=(function(f){let I=2166136261;for(let V=0;V<f.length;V++)I^=f.charCodeAt(V),I+=(I<<1)+(I<<4)+(I<<7)+(I<<8)+(I<<24);return I>>>0})(Q),p="";function y(){return m^=m<<13,m^=m>>>17,m^=m<<5,m>>>0}for(;p.length<Z;)p+=y().toString(16).padStart(8,"0");return p.substring(0,Z)}let L=null;async function b(Q){let Z=(p=>{let y=atob(p),f=new Uint8Array(y.length);for(let I=0;I<y.length;I++)f[I]=y.charCodeAt(I);return f})(Q),m=new TextDecoder().decode(await(async function(p){if(typeof DecompressionStream<"u")try{let y=new DecompressionStream("deflate-raw"),f=y.writable.getWriter(),I=y.readable.getReader();f.write(p).then(()=>f.close()).catch(()=>{});let V=[];for(;;){let{done:_,value:j}=await I.read();if(_)break;V.push(j)}let W=0;for(let _ of V)W+=_.length;let N=new Uint8Array(W),D=0;for(let _ of V)N.set(_,D),D+=_.length;return N}catch{}return L||(L=new Promise((y,f)=>{let I=window.CAP_PAKO_URL||"https://cdn.jsdelivr.net/npm/pako@2.1.0/dist/pako_inflate.min.js";r.debug(o("instr"),"DecompressionStream unavailable, loading pako from",I);let V=document.createElement("script");V.src=I;let W=window.CAP_SCRIPT_NONCE||window.CAP_CSS_NONCE;W&&V.setAttribute("nonce",W),V.onload=()=>{window.pako?.inflateRaw?y(window.pako):f(new Error("pako loaded but inflateRaw is missing"))},V.onerror=()=>{L=null,f(new Error(`failed to load pako fallback from ${I}`))},document.head.appendChild(V)})),(await L).inflateRaw(p)})(Z));return new Promise(p=>{var y=setTimeout(()=>{V(),p({__timeout:!0})},2e4),f=document.createElement("iframe");f.setAttribute("sandbox","allow-scripts"),f.setAttribute("aria-hidden","true"),f.style.cssText="position:absolute;width:1px;height:1px;top:-9999px;left:-9999px;border:none;opacity:0;pointer-events:none;";var I=!1;function V(){I||(I=!0,clearTimeout(y),window.removeEventListener("message",W),f.parentNode&&f.parentNode.removeChild(f))}function W(_){if(f.contentWindow&&_.source===f.contentWindow){var j=_.data;j&&typeof j=="object"&&(j.type==="cap:instr"?(V(),j.blocked?p({__blocked:!0,blockReason:j.blockReason||"automated_browser"}):j.result?p(j.result):p({__timeout:!0})):j.type==="cap:error"&&(V(),p({__timeout:!0})))}}window.addEventListener("message",W);let N=window.CAP_SCRIPT_NONCE||window.CAP_CSS_NONCE,D=N?` nonce="${String(N).replace(/"/g,""")}"`:"";f.srcdoc='<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><script'+D+">"+m+`
<\/script></body></html>`,document.body.appendChild(f)})}let X=null,k=()=>{if(X)return X;let Q=window.CAP_CUSTOM_WASM_URL||"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.7/browser/cap_wasm_bg.wasm",Z=performance.now();return r.debug(o("wasm"),"fetching",Q),X=fetch(Q).then(m=>{if(!m.ok)throw new Error(`Failed to fetch wasm: ${m.status}`);return m.arrayBuffer()}).then(m=>WebAssembly.compile(m)).then(m=>(r.debug(o("wasm"),`ready in ${a(Z)}`),m)).catch(m=>{throw X=null,r.warn(o("wasm"),`load failed (${a(Z)}):`,m.message||m),m}),X};typeof WebAssembly=="object"&&typeof WebAssembly.compile=="function"&&k().catch(()=>{});let z=null;function de(){return z||(z=URL.createObjectURL(new Blob(['(()=>{const e=(e,...t)=>{self.CAP_SILENT||console[e]("[cap worker]",...t)},t=async({salt:t,target:n})=>{let s=0;const r=new TextEncoder,o=4*n.length,a=Math.floor(o/8),l=o%8,i=n.length%2==0?n:`${n}0`,c=i.length/2,f=new Uint8Array(c);for(let e=0;e<c;e++)f[e]=parseInt(i.substring(2*e,2*e+2),16);const g=l>0?255<<8-l&255:0;for(;;)try{for(let e=0;e<5e4;e++){const e=t+s,n=r.encode(e),o=await crypto.subtle.digest("SHA-256",n),i=new Uint8Array(o);let c=!0;for(let e=0;e<a;e++)if(i[e]!==f[e]){c=!1;break}if(c&&l>0&&(i[a]&g)!==(f[a]&g)&&(c=!1),c)return void self.postMessage({nonce:s,found:!0});s++}}catch(t){return e("error","fallback solver crashed:",t.message||t),void self.postMessage({found:!1,error:t.message})}},n=e=>{const t=BigInt("0x"+e.N);let n=BigInt("0x"+e.x);const s=0|e.t,r=Math.max(64,Math.floor(s/50)),o=performance.now();for(let e=0;e<s;e+=r){const o=Math.min(s,e+r);for(let s=e;s<o;s++)n=n*n%t;o<s&&self.postMessage({progress:o/s})}self.postMessage({found:!0,y:n.toString(16),durationMs:(performance.now()-o).toFixed(2)})};if("object"!=typeof WebAssembly||"function"!=typeof WebAssembly?.instantiate)return e("warn","WebAssembly unavailable, using JS fallback solver (significantly slower)"),void(self.onmessage=async({data:e})=>"rsw"===e?.kind?n(e):t({salt:e.salt,target:e.target}));let s=null;self.onmessage=async({data:r})=>{if("rsw"===r?.kind)return n(r);const{salt:o,target:a,wasmModule:l}=r;if(l instanceof WebAssembly.Module&&null===s){const n=(t=>{try{let e,n=0,r=null;const o=()=>(null!==r&&0!==r.byteLength||(r=new Uint8Array(e.memory.buffer)),r),a=new TextEncoder,l=(e,t,s)=>{if(void 0===s){const s=a.encode(e),r=t(s.length,1)>>>0;return o().subarray(r,r+s.length).set(s),n=s.length,r}let r=e.length,l=t(r,1)>>>0;const i=o();let c=0;for(;c<r;c++){const t=e.charCodeAt(c);if(t>127)break;i[l+c]=t}if(c!==r){0!==c&&(e=e.slice(c));const t=c+3*e.length;l=s(l,r,t,1)>>>0,r=t;const n=o().subarray(l+c,l+r),{written:i}=a.encodeInto(e,n);c+=i,l=s(l,r,c,1)>>>0}return n=c,l},i={wbg:{}};i.wbg.__wbindgen_init_externref_table=()=>{const t=e.__wbindgen_export_0,n=t.grow(4);t.set(0,void 0),t.set(n+0,void 0),t.set(n+1,null),t.set(n+2,!0),t.set(n+3,!1)};const c=new WebAssembly.Instance(t,i);return e=c.exports,e.__wbindgen_start&&e.__wbindgen_start(),s=(t,s)=>{const r=l(t,e.__wbindgen_malloc,e.__wbindgen_realloc),o=n,a=l(s,e.__wbindgen_malloc,e.__wbindgen_realloc),i=n;return BigInt.asUintN(64,e.solve_pow(r,o,a,i))},!0}catch(t){return e("error","wasm init failed:",t.message||t),!1}})(l);if(!n)return e("warn","wasm init failed, falling back to JS solver"),t({salt:o,target:a})}if(null===s)return e("warn","no wasm module provided, falling back to JS solver"),t({salt:o,target:a});try{const e=performance.now(),t=s(o,a),n=performance.now();self.postMessage({nonce:Number(t),found:!0,durationMs:(n-e).toFixed(2)})}catch(t){e("error","solve_pow threw:",t.message||t),self.postMessage({found:!1,error:t.message||String(t)})}},self.onerror=e=>{self.postMessage({found:!1,error:e})}})();'],{type:"application/javascript"})),z)}class Xe{constructor(Z){this._size=Z,this._workers=[],this._idle=[],this._queue=[],this._wasmModule=null,this._spawnFailures=0}setWasm(Z){this._wasmModule=Z}_spawn(){let Z=de(),m=new Worker(Z);return m._busy=!1,this._workers.push(m),this._idle.push(m),m}_replaceWorker(Z){let m=this._workers.indexOf(Z);m!==-1&&this._workers.splice(m,1);let p=this._idle.indexOf(Z);p!==-1&&this._idle.splice(p,1);try{Z.terminate()}catch{}return this._spawnFailures++,r.warn(o("pool"),`worker died, replacing (attempt ${this._spawnFailures}/3)`),this._spawnFailures>3?(r.error(o("pool"),"worker spawn failed repeatedly, giving up"),null):this._spawn()}_ensureSize(Z){for(;this._workers.length<Z;)this._spawn()}run(Z,m){return new Promise((p,y)=>{this._queue.push({salt:Z,target:m,resolve:p,reject:y}),this._dispatch()})}runMsg(Z,m){return new Promise((p,y)=>{this._queue.push({msg:Z,onProgress:m,resolve:p,reject:y}),this._dispatch()})}_dispatch(){for(;this._idle.length>0&&this._queue.length>0;){let Z=this._idle.shift(),m=this._queue.shift(),{resolve:p,reject:y}=m,f=m.msg!==void 0,I=!1,V=({data:N})=>{if(!I){if(!N||typeof N.progress!="number"||N.found)I=!0,Z.removeEventListener("message",V),Z.removeEventListener("error",W),this._spawnFailures=0,this._idle.push(Z),N.found?p(f?N:N.nonce):y(new Error(N.error||"worker failed")),this._dispatch();else if(m.onProgress)try{m.onProgress(N.progress)}catch{}}},W=N=>{if(I)return;I=!0,Z.removeEventListener("message",V),Z.removeEventListener("error",W);let D=this._replaceWorker(Z);y(N),D&&this._dispatch()};Z.addEventListener("message",V),Z.addEventListener("error",W),f?Z.postMessage(m.msg):this._wasmModule?Z.postMessage({salt:m.salt,target:m.target,wasmModule:this._wasmModule},[]):Z.postMessage({salt:m.salt,target:m.target})}}terminate(){for(let Z of this._workers)try{Z.terminate()}catch{}this._workers=[],this._idle=[],this._queue=[]}}class Ue extends HTMLElement{constructor(){super();te(this,C);te(this,ae,null);te(this,ue,navigator.hardwareConcurrency||8);rr(this,"token",null);te(this,le);te(this,M);te(this,F);te(this,P);te(this,ie);te(this,Ye);te(this,Fe,!1);te(this,Ie);te(this,Ne);te(this,h,null);te(this,Ge,null);te(this,ce,null);te(this,Ee,null);te(this,Gt,null);te(this,He,null);te(this,tn,()=>{if(i(this,M)){try{this.scrollIntoView({behavior:"smooth",block:"center"})}catch{this.scrollIntoView()}i(this,M).classList.remove("invalid"),i(this,M).offsetWidth,i(this,M).classList.add("invalid"),setTimeout(()=>i(this,M)?.classList.remove("invalid"),1500)}});i(this,Ie)&&i(this,Ie).forEach((m,p)=>{this.removeEventListener(p.slice(2),m)}),U(this,Ie,new Map),this.boundHandleProgress=this.handleProgress.bind(this),this.boundHandleSolve=this.handleSolve.bind(this),this.boundHandleError=this.handleError.bind(this),this.boundHandleReset=this.handleReset.bind(this);try{U(this,Ne,this.attachInternals())}catch{}}getI18nText(m,p){return this.getAttribute(`data-cap-i18n-${m}`)||i(this,Gt)?.[m]||p}static get observedAttributes(){return["onsolve","onprogress","onreset","onerror","data-cap-worker-count","data-cap-i18n-initial-state","required"]}initialize(){de(),U(this,He,new AbortController),i(this,h)||U(this,h,K(this,C,jr).call(this)),i(this,ce)||(U(this,ce,new Xe(1)),i(this,ce)._spawn())}attributeChangedCallback(m,p,y){if(m.startsWith("on")){let f=m.slice(2),I=i(this,Ie).get(m);if(I&&this.removeEventListener(f,I),y){let V=W=>{let N=this.getAttribute(m);typeof window[N]=="function"&&window[N].call(this,W)};i(this,Ie).set(m,V),this.addEventListener(f,V)}}m==="data-cap-worker-count"&&this.setWorkersCount(parseInt(y,10)),m==="data-cap-i18n-initial-state"&&i(this,M)&&i(this,M)?.querySelector(".label.active")&&this.animateLabel(this.getI18nText("initial-state","Verify you're human")),m==="required"&&K(this,C,Vn).call(this)}async connectedCallback(){U(this,Ye,this),this.shadowRoot?U(this,le,this.shadowRoot):U(this,le,this.attachShadow({mode:"open"})),i(this,M)||U(this,M,document.createElement("div")),K(this,C,As).call(this),this.createUI(),this.addEventListeners(),this.initialize(),i(this,F).removeAttribute("disabled");let m=this.getAttribute("data-cap-worker-count"),p=m?parseInt(m,10):null;this.setWorkersCount(p||navigator.hardwareConcurrency||8),i(this,Ye).innerHTML=`<input type="hidden" name="${i(this,C,ro)}">`,r.debug(o(),`widget ready (workers=${i(this,ue)}, haptics=${i(this,C,at)})`),K(this,C,qr).call(this),K(this,C,Vn).call(this),this.addEventListener("invalid",i(this,tn))}async solve(){if(i(this,Fe))return;K(this,C,Sn).call(this);let m=performance.now(),p=i(this,He)?.signal;r.debug(o("solve"),"starting");try{U(this,Fe,!0),this.updateUI("verifying",this.getI18nText("verifying-label","Verifying..."),!0),i(this,F).setAttribute("aria-label",this.getI18nText("verifying-aria-label","Verifying you're a human, please wait")),this.dispatchEvent("progress",{progress:0});try{let y,f,I=this.getAttribute("data-cap-api-endpoint");if(!I&&window?.CAP_CUSTOM_FETCH)I="/";else if(!I)throw s("missing_endpoint","Missing API endpoint. Either custom fetch or an API endpoint must be provided.");if(I.endsWith("/")||(I+="/"),i(this,h).state==="done"&&i(this,h).token&&i(this,h).tokenExpires&&Date.now()<i(this,h).tokenExpires)return K(this,C,oo).call(this);if(i(this,h).state==="done")y=i(this,h).results,f=i(this,h).challengeResp,this.dispatchEvent("progress",{progress:100});else if(i(this,h).state==="solving"||i(this,h).state==="redeeming"||i(this,h).state==="fetching"||i(this,h).state==="waiting"){i(this,h).state==="waiting"&&(i(this,Ge)&&(clearTimeout(i(this,Ge)),U(this,Ge,null)),i(this,h).state="waiting",K(this,C,no).call(this)),i(this,h).pendingPromotion=i(this,ue),i(this,h).promoteFn&&i(this,h).promoteFn(i(this,ue));let R=setInterval(()=>{if(p?.aborted||!i(this,h))return void clearInterval(R);let v=i(this,h).state;if(v==="done"||v==="error")return void clearInterval(R);let q=i(this,h).challenges?i(this,h).challenges.length:1,me=i(this,h).completedCount,At=v==="redeeming"?99:v==="fetching"||v==="waiting"?0:Math.min(98,Math.round(me/q*100));this.dispatchEvent("progress",{progress:At})},150);if(await new Promise(v=>i(this,h).onSettled(v)),clearInterval(R),p?.aborted||!i(this,h))return;if(i(this,h).state==="idle"&&i(this,h).challengeResp?.format===2&&Array.isArray(i(this,h).challengeResp.challenges))f=i(this,h).challengeResp,i(this,h).challengeResp=null,y=await this.solveChallengesV2(f.challenges,p);else{if(i(this,h).state!=="done")throw s("solve_failed","Unable to solve challenge, self-hosted instance likely down. This is not an issue with Cap.");if(i(this,h).token&&i(this,h).tokenExpires&&Date.now()<i(this,h).tokenExpires)return K(this,C,oo).call(this);y=i(this,h).results,f=i(this,h).challengeResp,this.dispatchEvent("progress",{progress:100})}}else{let R=i(this,h).challengeResp;if(R?.format===2&&Array.isArray(R.challenges))f=R,i(this,h).challengeResp=null;else{let v=await c(`${I}challenge`,{method:"POST",signal:p});try{f=await v.json()}catch{throw s("challenge_parse_error","Failed to parse challenge response from server")}if(f.error)throw s("network_error",f.error)}if(f.format===2&&Array.isArray(f.challenges))y=await this.solveChallengesV2(f.challenges,p);else{let{challenge:v,token:q}=f,me=v;if(!Array.isArray(me)){let At=0;me=Array.from({length:v.c},()=>(At++,[x(`${q}${At}`,v.s),x(`${q}${At}d`,v.d)]))}y=await this.solveChallenges(me,p)}}let V=f.instrumentation?b(f.instrumentation):Promise.resolve(null),W=await V;if(p?.aborted||!i(this,h))return;if(W?.__timeout||W?.__blocked){c(`${I}redeem`,{method:"POST",body:JSON.stringify({token:f.token,solutions:y,...W.__blocked&&{instr_blocked:!0},...W.__timeout&&{instr_timeout:!0}}),headers:{"Content-Type":"application/json"},signal:p}).catch(()=>{}),this.updateUIBlocked(this.getI18nText("error-label","Error"),W?.__blocked),i(this,F).setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again"));let R=W?.__blocked?"instr_blocked":"instr_timeout",v=W?.__blocked?`Instrumentation blocked (${W.blockReason||"automated_browser"})`:"Instrumentation timed out";this.removeEventListener("error",this.boundHandleError);let q=new CustomEvent("error",{bubbles:!0,composed:!0,detail:{isCap:!0,code:R,message:v}});return super.dispatchEvent(q),this.addEventListener("error",this.boundHandleError),this.executeAttributeCode("onerror",q),r.error(o("instr"),`[${R}] ${v}`),void U(this,Fe,!1)}let{token:N}=f,D=await c(`${I}redeem`,{method:"POST",body:JSON.stringify({token:N,solutions:y,...W&&{instr:W}}),headers:{"Content-Type":"application/json"},signal:p}),_;try{_=await D.json()}catch{throw s("redeem_failed","Failed to parse server response")}if(p?.aborted||!i(this,h))return;if(this.dispatchEvent("progress",{progress:100}),!_.success)throw s("invalid_solution",_.error||"Invalid solution");K(this,C,Cn).call(this,_.token),this.dispatchEvent("solve",{token:_.token}),this.token=_.token,K(this,C,$r).call(this),i(this,ae)&&clearTimeout(i(this,ae));let j=new Date(_.expires).getTime()-Date.now();return j>0&&j<864e5?U(this,ae,setTimeout(()=>this.reset(),j)):this.error("Invalid expiration time","invalid_expires"),i(this,F).setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),i(this,C,at)&&navigator.vibrate([10,50,20,30,40]),r.debug(o("solve"),`verified in ${a(m)}`),K(this,C,to).call(this),{success:!0,token:this.token}}catch(y){if(p?.aborted||!i(this,h))return;throw i(this,F).setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again")),this.error(y.message,y.code||"solve_failed"),y}}finally{U(this,Fe,!1)}}async solveChallengesV2(m,p){let y=m.length,f=0,I=new Array(m.length);for(let R=0;R<m.length;R++){let v=m[R];if(!v||typeof v!="object"||v.protocol!=="sha256-pow"&&v.protocol!=="rsw"&&v.protocol!=="instrumentation")throw s("challenge_unsupported",`unsupported format-2 protocol '${v?.protocol}'`)}let V=null;if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function")try{V=await k()}catch(R){r.warn(o("wasm"),"unavailable, falling back to JS solver:",R.message||R)}let W=Math.max(1,Math.min(i(this,ue),m.length)),N=new Xe(W);N.setWasm(V),N._ensureSize(W);let D=(R,v)=>Promise.race([R,new Promise((q,me)=>setTimeout(()=>me(new Error(`[cap] ${v} timed out after 60000ms`)),6e4))]),_=new Array(m.length).fill(0),j=()=>{let R=_.reduce((q,me)=>q+me,0)+f,v=Math.min(99,Math.round(R/y*100));this.dispatchEvent("progress",{progress:v})};try{await u(Promise.all(m.map((R,v)=>R.protocol==="sha256-pow"?D(N.run(R.payload.salt,R.payload.target),`sha256-pow worker #${v}`).then(q=>{I[v]={nonce:Number(q)},_[v]=0,f++,j()}):R.protocol==="rsw"?D(N.runMsg({kind:"rsw",N:R.payload.N,x:R.payload.x,t:0|R.payload.t},q=>{_[v]=q,j()}),`rsw worker #${v}`).then(q=>{I[v]={y:q.y},_[v]=0,f++,j()}):b(R.payload.blob).then(q=>{I[v]=q?.__timeout?{timeout:!0}:q?.__blocked?{blocked:!0}:{instr:q},_[v]=0,f++,j()}))),p)}finally{N.terminate()}return I}async solveChallenges(m,p){let y=m.length,f=0,I=null,V=typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function";if(V)try{I=await k()}catch(D){r.warn(o("wasm"),"unavailable, falling back to JS solver:",D.message||D)}if(!V&&(r.warn(o("wasm"),"WebAssembly disabled in this browser, solver will be ~10x slower"),!i(this,le).querySelector(".warning"))){let D=document.createElement("div");D.className="warning",D.style.cssText="width:var(--cap-widget-width,230px);background:rgb(237,56,46);color:white;padding:4px 6px;padding-bottom:calc(var(--cap-border-radius,14px) + 5px);font-size:10px;box-sizing:border-box;font-family:system-ui;border-top-left-radius:8px;border-top-right-radius:8px;text-align:center;user-select:none;margin-bottom:-35.5px;opacity:0;transition:margin-bottom .3s,opacity .3s;",D.innerText=this.getI18nText("wasm-disabled","Enable WASM for significantly faster solving"),i(this,le).insertBefore(D,i(this,le).firstChild),setTimeout(()=>{D.style.marginBottom="calc(-1 * var(--cap-border-radius, 14px))",D.style.opacity=1},10)}let W=new Xe(i(this,ue));W.setWasm(I),W._ensureSize(i(this,ue));let N=[];try{for(let D=0;D<m.length;D+=i(this,ue)){let _=m.slice(D,Math.min(D+i(this,ue),m.length)),j=await u(Promise.all(_.map(([R,v])=>W.run(R,v).then(q=>{f++;let me=Math.min(99,Math.round((0+f)/y*100));return this.dispatchEvent("progress",{progress:me}),q}))),p);N.push(...j)}}finally{W.terminate()}return N}setWorkersCount(m){let p=parseInt(m,10),y=Math.min(navigator.hardwareConcurrency||8,16);U(this,ue,!Number.isNaN(p)&&p>0&&p<=y?p:navigator.hardwareConcurrency||8)}createUI(){i(this,M).classList.add("captcha"),i(this,M).setAttribute("role","group"),i(this,M).setAttribute("aria-label",this.getI18nText("group-aria-label","Cap verification")),U(this,F,document.createElement("div")),i(this,F).className="captcha-trigger",i(this,F).setAttribute("part","trigger"),i(this,F).setAttribute("role","button"),i(this,F).setAttribute("tabindex","0"),i(this,F).setAttribute("aria-label",this.getI18nText("verify-aria-label","Click to verify you're a human")),i(this,F).setAttribute("aria-live","polite"),i(this,F).setAttribute("disabled","true"),i(this,F).innerHTML=`<div class="checkbox" part="checkbox" aria-hidden="true"><svg class="progress-ring" viewBox="0 0 32 32" aria-hidden="true"><circle class="progress-ring-bg" cx="16" cy="16" r="14"></circle><circle class="progress-ring-circle" cx="16" cy="16" r="14"></circle></svg></div><p part="label" class="label-wrapper"><span class="label active">${this.getI18nText("initial-state","Verify you're human")}</span></p>`,i(this,M).appendChild(i(this,F)),U(this,ie,document.createElement("a")),i(this,ie).className="cap-troubleshoot-link",i(this,ie).setAttribute("part","troubleshoot"),i(this,ie).setAttribute("target","_blank"),i(this,ie).setAttribute("rel","noopener"),i(this,ie).hidden=!0,i(this,M).appendChild(i(this,ie)),U(this,P,document.createElement("a")),i(this,P).className="credits",i(this,P).setAttribute("aria-label","Secured by Cap"),i(this,P).setAttribute("href","https://trycap.dev"),i(this,P).setAttribute("target","_blank"),i(this,P).setAttribute("title","Secured by Cap: The self-hosted CAPTCHA for the modern web."),i(this,P).textContent="Cap",i(this,M).appendChild(i(this,P)),i(this,le).innerHTML=`<style${window.CAP_CSS_NONCE?` nonce=${window.CAP_CSS_NONCE}`:""}>:host{display:inline-block}@media (prefers-reduced-motion:reduce){.captcha,.captcha *{transition:none!important;animation:none!important}.label{filter:none!important;opacity:1!important;transition:none!important;transform:none!important}.label:not(.active),.label.exit{display:none!important}}.captcha,.captcha *{box-sizing:border-box}.captcha{width:var(--cap-widget-width,260px);height:var(--cap-widget-height,58px);background-color:var(--cap-background,#fdfdfd);border:1px solid var(--cap-border-color,#dddddd8f);border-radius:var(--cap-border-radius,14px);-webkit-user-select:none;user-select:none;cursor:pointer;-webkit-tap-highlight-color:#fff0;color:var(--cap-color,#212121);font-family:var(--cap-font,system, -apple-system, "BlinkMacSystemFont", ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", "Ubuntu", "arial", sans-serif);transition:filter .2s,transform .2s,height .2s;display:inline-block;position:relative;overflow:hidden}.captcha.has-troubleshoot{height:calc(var(--cap-widget-height,58px) + 26px)}.captcha.has-troubleshoot .captcha-trigger{inset-block-end:26px}.captcha:not([data-state]):active{transform:scale(.97)}.captcha:hover{filter:brightness(98%)}.captcha-trigger{padding:var(--cap-widget-padding,14px);align-items:center;gap:var(--cap-gap,15px);border-radius:inherit;transition:inset .2s;display:flex;position:absolute;inset:0}.captcha-trigger:focus-visible{outline:2px solid var(--cap-focus-ring,#06c);outline-offset:-3px}.checkbox{width:var(--cap-checkbox-size,25px);height:var(--cap-checkbox-size,25px);border:var(--cap-checkbox-border,1px solid #aaaaaad1);border-radius:var(--cap-checkbox-border-radius,6px);background-color:var(--cap-checkbox-background,#fafafa91);margin-top:var(--cap-checkbox-margin,2px);margin-bottom:var(--cap-checkbox-margin,2px);flex-shrink:0;transition:opacity .2s}.captcha p{-webkit-user-select:none;user-select:none;margin:0;font-size:15px;font-weight:500}.label-wrapper{flex:1;align-items:center;min-width:0;height:2em;display:flex;position:relative;overflow:hidden}.label-wrapper:before,.label-wrapper:after{content:"";pointer-events:none;z-index:1;width:100%;height:.6em;position:absolute;inset-inline-start:0}.label-wrapper:before{background:linear-gradient(to bottom, var(--cap-background,#fdfdfd), transparent);top:0}.label-wrapper:after{background:linear-gradient(to top, var(--cap-background,#fdfdfd), transparent);bottom:0}.label{white-space:nowrap;opacity:0;filter:blur(2px);transition:transform .5s cubic-bezier(.25,1,.5,1),opacity .5s,filter .5s;position:absolute;transform:translateY(100%)}.label.active{opacity:1;filter:none;transform:translateY(0)}.label.exit{opacity:0;filter:blur(2px);transform:translateY(-100%)}.checkbox .progress-ring{width:100%;height:100%;display:none;transform:rotate(-90deg)}.checkbox .progress-ring-bg{fill:none;stroke:var(--cap-spinner-background-color,#eee);stroke-width:var(--cap-spinner-thickness,3)}.checkbox .progress-ring-circle{fill:none;stroke:var(--cap-spinner-color,#000);stroke-width:var(--cap-spinner-thickness,3);stroke-linecap:round;stroke-dasharray:87.96;stroke-dashoffset:87.96px;transition:stroke-dashoffset .3s}.captcha[data-state=verifying] .checkbox{background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;display:flex;transform:scale(1.1)}.captcha[data-state=verifying] .checkbox .progress-ring{display:block}.captcha[data-state=done] .checkbox{background-image:var(--cap-checkmark,url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cstyle%3E%40keyframes%20anim%7B0%25%7Bstroke-dashoffset%3A23.21320343017578px%7Dto%7Bstroke-dashoffset%3A0%7D%7D%3C%2Fstyle%3E%3Cpath%20fill%3D%22none%22%20stroke%3D%22%2300a67d%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%20stroke-width%3D%222%22%20d%3D%22m5%2012%205%205L20%207%22%20style%3D%22stroke-dashoffset%3A0%3Bstroke-dasharray%3A23.21320343017578px%3Banimation%3Aanim%20.5s%20ease%22%2F%3E%3C%2Fsvg%3E));background-size:cover;border:1px solid #0000}.captcha[data-state=done] .checkbox .progress-ring{display:none}.captcha[data-state=error] .checkbox{background-image:var(--cap-error-cross,url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 24 24'%3E%3Cpath fill='%23f55b50' d='M11 15h2v2h-2zm0-8h2v6h-2zm1-5C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2m0 18a8 8 0 0 1-8-8a8 8 0 0 1 8-8a8 8 0 0 1 8 8a8 8 0 0 1-8 8'/%3E%3C%2Fsvg%3E"));background-size:cover;border:1px solid #0000}.captcha[data-state=error] .checkbox .progress-ring{display:none}.captcha.invalid{border-color:var(--cap-invalid-border-color,#f55b50);box-shadow:0 0 0 3px var(--cap-invalid-ring-color,#f55b5033);animation:.5s cubic-bezier(.36,.07,.19,.97) cap-shake}@keyframes cap-shake{10%,90%{transform:translate(-1px)}20%,80%{transform:translate(2px)}30%,50%,70%{transform:translate(-4px)}40%,60%{transform:translate(4px)}}@media (prefers-reduced-motion:reduce){.captcha.invalid{animation:none!important}}.captcha-trigger[disabled]{cursor:not-allowed}.captcha[data-state=verifying] .captcha-trigger{cursor:progress}.captcha[data-state=done] .captcha-trigger{cursor:default}.credits{color:var(--cap-color,#212121);text-underline-offset:.18em;z-index:2;border-radius:4px;justify-content:flex-end;align-items:center;min-width:24px;min-height:24px;padding:4px 6px;text-decoration:underline;text-decoration-thickness:.08em;position:absolute;inset-block-end:4px;inset-inline-end:4px;opacity:.8!important;font-size:12px!important;display:inline-flex!important}.captcha .credits{visibility:visible!important;pointer-events:all!important;display:inline-flex!important}.credits:focus-visible{outline:2px solid var(--cap-focus-ring,#06c);outline-offset:2px;opacity:1!important}.cap-troubleshoot-link{min-width:24px;min-height:24px;color:var(--cap-troubleshoot-color,#0050a0);text-underline-offset:.15em;cursor:pointer;z-index:2;border-radius:4px;align-items:center;padding:4px 6px;font-size:13px;font-weight:500;text-decoration:underline;text-decoration-thickness:.08em;display:inline-flex;position:absolute;inset-block-end:4px;inset-inline-start:14px}.cap-troubleshoot-link[hidden]{display:none}.cap-troubleshoot-link:hover{opacity:.85}.cap-troubleshoot-link:focus-visible{outline:2px solid var(--cap-focus-ring,#06c);outline-offset:2px}@media (forced-colors:active){.captcha,.checkbox{border-color:canvastext}:is(.captcha-trigger:focus-visible,.credits:focus-visible,.cap-troubleshoot-link:focus-visible){outline-color:highlight}.progress-ring-bg{stroke:graytext}.progress-ring-circle{stroke:canvastext}.captcha.invalid{box-shadow:none;border-color:mark}.credits{opacity:1!important}}</style>`,i(this,le).appendChild(i(this,M)),K(this,C,Sn).call(this),setTimeout(()=>K(this,C,Sn).call(this),100)}addEventListeners(){i(this,F)&&(i(this,P).addEventListener("click",m=>{m.preventDefault(),window.open(`https://trycap.dev/?${new URLSearchParams({utm_source:"cap_widget",utm_medium:"referral",utm_campaign:"widget",utm_content:window.CAP_DISABLE_WIDGET_REF?"":location.hostname,ref:window.CAP_DISABLE_WIDGET_REF?"":location.href||"",sub:window.CAP_DISABLE_WIDGET_REF?"":document.referrer||""}).toString()}`,"_blank")}),i(this,F).addEventListener("click",()=>{i(this,F).hasAttribute("disabled")||this.solve()}),i(this,F).addEventListener("mousedown",()=>{!i(this,F).hasAttribute("disabled")&&i(this,C,at)&&navigator.vibrate(5)}),i(this,F).addEventListener("keydown",m=>{m.target===i(this,F)&&(m.key!=="Enter"&&m.key!==" "||i(this,F).hasAttribute("disabled")||(m.preventDefault(),m.stopPropagation(),this.solve()))}),this.addEventListener("progress",this.boundHandleProgress),this.addEventListener("solve",this.boundHandleSolve),this.addEventListener("error",this.boundHandleError),this.addEventListener("reset",this.boundHandleReset))}animateLabel(m){if(!i(this,F))return;let p=i(this,F).querySelector(".label-wrapper");if(!p)return;if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches){let I=p.querySelector(".label.active");if(I)I.textContent=m;else{let V=document.createElement("span");V.className="label active",V.textContent=m,p.appendChild(V)}return}let y=p.querySelector(".label.active"),f=document.createElement("span");f.className="label",f.textContent=m,p.appendChild(f),f.offsetWidth,f.classList.add("active"),y&&(y.classList.remove("active"),y.classList.add("exit"),y.addEventListener("transitionend",()=>y.remove(),{once:!0}))}updateUI(m,p,y=!1){i(this,M)&&i(this,F)&&(i(this,M).setAttribute("data-state",m),i(this,M).classList.remove("has-troubleshoot"),this.animateLabel(p),i(this,ie)&&(i(this,ie).hidden=!0),y?i(this,F).setAttribute("disabled","true"):i(this,F).removeAttribute("disabled"))}updateUIBlocked(m,p=!1){if(i(this,M)&&i(this,F)&&(i(this,M).setAttribute("data-state","error"),i(this,F).removeAttribute("disabled"),this.animateLabel(m),i(this,ie)))if(p){let y=this.getAttribute("data-cap-troubleshooting-url")||"https://trycap.dev/guide/troubleshooting/instrumentation.html";i(this,ie).setAttribute("href",y),i(this,ie).textContent=this.getI18nText("troubleshooting-label","Troubleshoot"),i(this,ie).hidden=!1,i(this,M).classList.add("has-troubleshoot")}else i(this,ie).hidden=!0,i(this,M).classList.remove("has-troubleshoot")}handleProgress(m){if(!i(this,F))return;let p=i(this,F).querySelector(".progress-ring-circle");if(p){let f=2*Math.PI*14,I=f-m.detail.progress/100*f;p.style.strokeDashoffset=I}let y=i(this,F).querySelector(".label-wrapper");if(y){let f=y.querySelector(".label.active");f&&(f.textContent=`${this.getI18nText("verifying-label","Verifying...")}`)}this.executeAttributeCode("onprogress",m)}handleSolve(m){this.updateUI("done",this.getI18nText("solved-label","You're a human"),!0),this.executeAttributeCode("onsolve",m),i(this,Ne)?.setValidity?.({}),i(this,M)?.classList.remove("invalid")}handleError(m){this.updateUI("error",this.getI18nText("error-label","Error. Try again.")),this.executeAttributeCode("onerror",m),i(this,C,at)&&navigator.vibrate([10,40,10])}handleReset(m){this.updateUI("",this.getI18nText("initial-state","I'm a human")),this.executeAttributeCode("onreset",m),K(this,C,Vn).call(this)}executeAttributeCode(m,p){let y=this.getAttribute(m);y&&(r.warn(o(),"inline `onxxx='\u2026'` handlers are deprecated. use `addEventListener` callbacks instead."),new Function("event",y).call(this,p))}error(m="Unknown error",p="unknown"){r.error(o("solve"),`[${p}] ${m}`),this.dispatchEvent("error",{isCap:!0,code:p,message:m})}dispatchEvent(m,p={}){let y=new CustomEvent(m,{bubbles:!0,composed:!0,detail:p});super.dispatchEvent(y)}reset(){i(this,ae)&&(clearTimeout(i(this,ae)),U(this,ae,null)),this.token=null,this.dispatchEvent("reset"),K(this,C,Cn).call(this,"")}get tokenValue(){return this.token}disconnectedCallback(){i(this,He)?.abort(),this.removeEventListener("progress",this.boundHandleProgress),this.removeEventListener("solve",this.boundHandleSolve),this.removeEventListener("error",this.boundHandleError),this.removeEventListener("reset",this.boundHandleReset),i(this,Ie).forEach((m,p)=>{this.removeEventListener(p.slice(2),m)}),i(this,Ie).clear(),i(this,le)&&(i(this,le).innerHTML=""),this.reset(),this.cleanup()}cleanup(){i(this,ae)&&(clearTimeout(i(this,ae)),U(this,ae,null)),K(this,C,Zn).call(this),i(this,Ge)&&(clearTimeout(i(this,Ge)),U(this,Ge,null)),i(this,ce)&&(i(this,ce).terminate(),U(this,ce,null)),i(this,h)&&(i(this,h).state="error",i(this,h).notify(),U(this,h,null))}}ae=new WeakMap,ue=new WeakMap,le=new WeakMap,M=new WeakMap,F=new WeakMap,P=new WeakMap,ie=new WeakMap,Ye=new WeakMap,Fe=new WeakMap,Ie=new WeakMap,Ne=new WeakMap,h=new WeakMap,Ge=new WeakMap,ce=new WeakMap,Ee=new WeakMap,Gt=new WeakMap,He=new WeakMap,C=new WeakSet,at=function(){return e&&!window.CAP_DISABLE_HAPTICS&&!this.hasAttribute("data-cap-disable-haptics")},jr=function(){return{state:"idle",challengeResp:null,challenges:null,results:[],completedCount:0,solvePromise:null,promoteFn:null,_listeners:[],pendingPromotion:null,token:null,tokenExpires:null,notify(){for(let m of this._listeners)m();this._listeners=[]},onSettled(m){this.state==="done"||this.state==="error"?m():this._listeners.push(m)}}},$r=function(){U(this,h,K(this,C,jr).call(this)),K(this,C,qr).call(this)},Zn=function(){i(this,Ee)&&(window.removeEventListener("mousemove",i(this,Ee)),window.removeEventListener("touchstart",i(this,Ee)),window.removeEventListener("keydown",i(this,Ee)),U(this,Ee,null))},qr=function(){K(this,C,Zn).call(this);let m=()=>{K(this,C,Zn).call(this),K(this,C,ys).call(this)};U(this,Ee,m),window.addEventListener("mousemove",m,{passive:!0}),window.addEventListener("touchstart",m,{passive:!0}),window.addEventListener("keydown",m,{passive:!0})},eo=function(){return typeof this.checkVisibility=="function"?this.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0}):!!(this.offsetParent||this.getClientRects().length>0)},to=function(){K(this,C,eo).call(this)||r.info(o("challenges"),"solved invisible challenge")},ys=function(){i(this,h).state==="idle"&&K(this,C,eo).call(this)&&(i(this,h).state="waiting",U(this,Ge,setTimeout(()=>{K(this,C,no).call(this)},2500)))},no=async function(){if(i(this,h).state!=="waiting")return;i(this,h).state="fetching",i(this,h)._t0=performance.now();let m=this.getAttribute("data-cap-api-endpoint");if(!m&&window?.CAP_CUSTOM_FETCH&&(m="/"),m){m.endsWith("/")||(m+="/");try{let p=await c(`${m}challenge`,{method:"POST",signal:i(this,He)?.signal}),y;try{y=await p.json()}catch{throw new Error("Failed to parse speculative challenge response")}if(y.error)throw new Error(y.error);if(!i(this,h))return;if(y._apiEndpoint=m,i(this,h).challengeResp=y,y.format===2&&Array.isArray(y.challenges))return i(this,h).state="idle",void i(this,h).notify();let{challenge:f,token:I}=y,V=f;if(!Array.isArray(V)){let W=0;V=Array.from({length:f.c},()=>(W++,[x(`${I}${W}`,f.s),x(`${I}${W}d`,f.d)]))}i(this,h).challenges=V,i(this,h).state="solving",i(this,h).solvePromise=K(this,C,Is).call(this,V)}catch{if(!i(this,h))return;i(this,h).state="error",i(this,h).notify()}}else i(this,h).state="idle"},Is=async function(m){de();let p=null;try{p=await k()}catch{}i(this,ce)||(U(this,ce,new Xe(1)),i(this,ce)._spawn()),i(this,ce).setWasm(p);let y=m.length,f=new Array(y),I=1,V=!1;i(this,h).promoteFn=N=>{V||(V=!0,I=N,i(this,ce)._size=N,i(this,ce)._ensureSize(N))},i(this,h).pendingPromotion!==null&&(i(this,h).promoteFn(i(this,h).pendingPromotion),i(this,h).pendingPromotion=null);let W=0;for(;W<y;){let N=I,D=[],_=[];for(let R=0;R<N&&W<y;R++)_.push(W),D.push(m[W]),W++;i(this,ce)._ensureSize(Math.max(I,N));let j=await Promise.all(D.map(R=>i(this,ce).run(R[0],R[1]).then(v=>(i(this,h)&&i(this,h).completedCount++,v))));for(let R=0;R<_.length;R++)f[_[R]]=j[R];!V&&W<y&&await new Promise(R=>setTimeout(R,120))}return i(this,h)&&(i(this,h).results=f,i(this,h).state="redeeming",K(this,C,Gs).call(this,f)),f},Gs=async function(m){try{if(!i(this,h))return;let p=i(this,h).challengeResp,y=p._apiEndpoint;if(!y)throw s("missing_endpoint","speculative redeem: missing apiEndpoint");let f=null;if(p.instrumentation){if(f=await b(p.instrumentation),!i(this,h))return;if(f?.__timeout||f?.__blocked)return i(this,h).state="done",void i(this,h).notify()}let I=await c(`${y}redeem`,{method:"POST",body:JSON.stringify({token:p.token,solutions:m,...f&&{instr:f}}),headers:{"Content-Type":"application/json"},signal:i(this,He)?.signal}),V;try{V=await I.json()}catch{throw new Error("Failed to parse speculative redeem response")}if(!i(this,h))return;if(!V.success)throw new Error(V.error||"Speculative redeem failed");i(this,h).token=V.token,i(this,h).tokenExpires=new Date(V.expires).getTime(),i(this,h).state="done",i(this,h)._invisibleElapsed=i(this,h)._t0?a(i(this,h)._t0):"?",i(this,h).notify()}catch{if(!i(this,h))return;i(this,h).state="done",i(this,h).notify()}},ro=function(){return this.getAttribute("data-cap-hidden-field-name")||"cap-token"},Cn=function(m){let p=this.querySelector(`input[name='${i(this,C,ro)}']`);p&&(p.value=m)},oo=function(){r.debug(o("solve"),`served from speculative cache (saved ${i(this,h)._invisibleElapsed||"?"})`),this.dispatchEvent("progress",{progress:100}),K(this,C,Cn).call(this,i(this,h).token),this.dispatchEvent("solve",{token:i(this,h).token}),this.token=i(this,h).token;let m=i(this,h).tokenExpires-Date.now();return i(this,ae)&&clearTimeout(i(this,ae)),U(this,ae,setTimeout(()=>this.reset(),m)),i(this,F).setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),i(this,C,at)&&navigator.vibrate([10,50,20,30,40]),K(this,C,to).call(this),K(this,C,$r).call(this),U(this,Fe,!1),{success:!0,token:this.token}},As=function(){U(this,Gt,(function(m){let p=m?[m]:navigator.languages||[navigator.language||""];for(let y of p){if(!y)continue;if(y=y.toLowerCase(),y==="en"||y.startsWith("en-"))return null;let f=S[y]?y:S[y.split("-")[0]]?y.split("-")[0]:null;if(!f)return null;let I=S[f].split("/"),V={};return g.forEach((W,N)=>{V[W]=I[N]}),V}return null})(window.CAP_LANG||this.getAttribute("data-cap-lang")))},Vn=function(){i(this,Ne)?.setValidity&&(this.hasAttribute("required")&&!this.token?i(this,Ne).setValidity({valueMissing:!0},this.getI18nText("required-label","Please verify you're human"),i(this,M)||this):i(this,Ne).setValidity({}))},tn=new WeakMap,Zs=function(){if(!i(this,Ye))return!1;let m=i(this,Ye).getBoundingClientRect();if(m.width===0&&m.height===0)return!0;let p=window.getComputedStyle(i(this,Ye));return p.display==="none"||p.visibility==="hidden"},Sn=function(){i(this,P)&&i(this,M)&&!K(this,C,Zs).call(this)&&(i(this,P).isConnected&&i(this,P).parentNode===i(this,M)||i(this,M).appendChild(i(this,P)),i(this,P).textContent&&i(this,P).textContent.trim()||(i(this,P).textContent="Cap"),i(this,P).getAttribute("href")!=="https://trycap.dev"&&i(this,P).setAttribute("href","https://trycap.dev"),i(this,P).style.cssText=["display: inline-flex !important","visibility: visible !important","opacity: 0.8 !important","pointer-events: all !important","font-size: 12px !important","transform: none !important","clip-path: none !important","filter: none !important","position: absolute !important"].join("; "))},rr(Ue,"formAssociated",!0);class xe{constructor(Z={},m){let p=m||document.createElement("cap-widget");if(Object.entries(Z).forEach(([y,f])=>{p.setAttribute(y,f)}),!Z.apiEndpoint&&!window?.CAP_CUSTOM_FETCH)throw p.remove(),new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");Z.apiEndpoint&&p.setAttribute("data-cap-api-endpoint",Z.apiEndpoint),m||p.hasAttribute("data-cap-disable-haptics")||p.setAttribute("data-cap-disable-haptics",""),this.widget=p,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:()=>p.token,configurable:!0,enumerable:!0}),m||(p.style.display="none",document.documentElement.appendChild(p))}}window.Cap=xe,customElements.get("cap-widget")||window?.CAP_DONT_SKIP_REDEFINE?customElements.get("cap-widget")&&r.warn(o(),"cap-widget custom element already defined, skipping re-define. set window.CAP_DONT_SKIP_REDEFINE = true to override"):customElements.define("cap-widget",Ue),typeof Xn=="object"&&typeof ao<"u"?ao.exports=xe:typeof define=="function"&&define.amd&&define([],()=>xe),typeof Xn<"u"&&(Xn.default=xe)})()});var yd={};Ci(yd,{AdaptCapElement:()=>kt,Cap