UNPKG

@mochabug/adapt-web

Version:

Browser client library for Adapt automation platform

3 lines 429 kB
var __MbAdapt_prev = typeof MbAdapt !== 'undefined' ? MbAdapt : undefined; "use strict";var MbAdapt=(()=>{var ul=Object.create;var Yt=Object.defineProperty;var ml=Object.getOwnPropertyDescriptor;var pl=Object.getOwnPropertyNames;var hl=Object.getPrototypeOf,gl=Object.prototype.hasOwnProperty;var Si=t=>{throw TypeError(t)};var fl=(t,e,n)=>e in t?Yt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var bl=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}},yl=(t,e)=>{for(var n in e)Yt(t,n,{get:e[n],enumerable:!0})},Zi=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pl(e))!gl.call(t,o)&&o!==n&&Yt(t,o,{get:()=>e[o],enumerable:!(r=ml(e,o))||r.enumerable});return t};var Il=(t,e,n)=>(n=t!=null?ul(hl(t)):{},Zi(e||!t||!t.__esModule?Yt(n,"default",{value:t,enumerable:!0}):n,t)),Gl=t=>Zi(Yt({},"__esModule",{value:!0}),t);var Wr=(t,e,n)=>fl(t,typeof e!="symbol"?e+"":e,n),Mr=(t,e,n)=>e.has(t)||Si("Cannot "+n);var d=(t,e,n)=>(Mr(t,e,"read from private field"),n?n.call(t):e.get(t)),ge=(t,e,n)=>e.has(t)?Si("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),P=(t,e,n,r)=>(Mr(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),Q=(t,e,n)=>(Mr(t,e,"access private method"),n);var dl=bl((kr,xi)=>{(()=>{var pe,ye,ae,U,N,v,Z,x,J,F,re,b,he,q,$,me,Se,w,Ft,fi,bi,wr,yi,Ii,Gi,il,vi,al,sl,Ai,Br,Ci,ll,Xr,Cn,cl,Rr;let t="vibrate"in navigator&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(typeof window>"u")return;let e=["#f5c2e7","#cba6f7","#f38ba8","#fab387","#f9e2af","#a6e3a1","#94e2d5","#89dceb","#b4befe"],n=(ee,X,p)=>{let y=X===0?"9999px":"0",G=X===p-1?"9999px":"0";return`color:#1e1e2e;background:${(I=>{if(I==="cap")return"#89b4fa";let E=0;for(let k=0;k<I.length;k++)E=I.charCodeAt(k)+((E<<5)-E);return e[Math.abs(E)%e.length]})(ee)};margin-left:${X?"-6px":0};padding:0 6px;border-radius:${y} ${G} ${G} ${y};font-weight:600`},r={};for(let ee of["debug","info","warn","error"])r[ee]=(X,...p)=>{if(window.CAP_SILENT||ee==="debug"&&!window.CAP_DEBUG)return;let y=X.map(I=>`%c${I}`).join(" "),G=X.map((I,E)=>n(I,E,X.length));console[ee==="debug"?"log":ee](y,...G,...p)};let o=ee=>ee?["cap",ee]:["cap"],i=ee=>`${Math.round(performance.now()-ee)}ms`,a=(ee,X)=>Object.assign(new Error(X),{code:ee}),s=(ee,X={})=>window?.CAP_CUSTOM_FETCH?window.CAP_CUSTOM_FETCH(ee,X):fetch(ee,X),l=(ee,X)=>X?X.aborted?Promise.reject(a("aborted","aborted")):Promise.race([ee,new Promise((p,y)=>X.addEventListener("abort",()=>y(a("aborted","aborted")),{once:!0}))]):ee,c="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(","),h={"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 f(ee,X){let p=(function(I){let E=2166136261;for(let k=0;k<I.length;k++)E^=I.charCodeAt(k),E+=(E<<1)+(E<<4)+(E<<7)+(E<<8)+(E<<24);return E>>>0})(ee),y="";function G(){return p^=p<<13,p^=p>>>17,p^=p<<5,p>>>0}for(;y.length<X;)y+=G().toString(16).padStart(8,"0");return y.substring(0,X)}let C=null;async function g(ee){let X=(y=>{let G=atob(y),I=new Uint8Array(G.length);for(let E=0;E<G.length;E++)I[E]=G.charCodeAt(E);return I})(ee),p=new TextDecoder().decode(await(async function(y){if(typeof DecompressionStream<"u")try{let G=new DecompressionStream("deflate-raw"),I=G.writable.getWriter(),E=G.readable.getReader();I.write(y).then(()=>I.close()).catch(()=>{});let k=[];for(;;){let{done:ne,value:se}=await E.read();if(ne)break;k.push(se)}let z=0;for(let ne of k)z+=ne.length;let _=new Uint8Array(z),te=0;for(let ne of k)_.set(ne,te),te+=ne.length;return _}catch{}return C||(C=new Promise((G,I)=>{let E=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",E);let k=document.createElement("script");k.src=E;let z=window.CAP_SCRIPT_NONCE||window.CAP_CSS_NONCE;z&&k.setAttribute("nonce",z),k.onload=()=>{window.pako?.inflateRaw?G(window.pako):I(new Error("pako loaded but inflateRaw is missing"))},k.onerror=()=>{C=null,I(new Error(`failed to load pako fallback from ${E}`))},document.head.appendChild(k)})),(await C).inflateRaw(y)})(X));return new Promise(y=>{var G=setTimeout(()=>{k(),y({__timeout:!0})},2e4),I=document.createElement("iframe");I.setAttribute("sandbox","allow-scripts"),I.setAttribute("aria-hidden","true"),I.style.cssText="position:absolute;width:1px;height:1px;top:-9999px;left:-9999px;border:none;opacity:0;pointer-events:none;";var E=!1;function k(){E||(E=!0,clearTimeout(G),window.removeEventListener("message",z),I.parentNode&&I.parentNode.removeChild(I))}function z(ne){if(I.contentWindow&&ne.source===I.contentWindow){var se=ne.data;se&&typeof se=="object"&&(se.type==="cap:instr"?(k(),se.blocked?y({__blocked:!0,blockReason:se.blockReason||"automated_browser"}):se.result?y(se.result):y({__timeout:!0})):se.type==="cap:error"&&(k(),y({__timeout:!0})))}}window.addEventListener("message",z);let _=window.CAP_SCRIPT_NONCE||window.CAP_CSS_NONCE,te=_?` nonce="${String(_).replace(/"/g,"&quot;")}"`:"";I.srcdoc='<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><script'+te+">"+p+` <\/script></body></html>`,document.body.appendChild(I)})}let S=null,W=()=>{if(S)return S;let ee=window.CAP_CUSTOM_WASM_URL||"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.7/browser/cap_wasm_bg.wasm",X=performance.now();return r.debug(o("wasm"),"fetching",ee),S=fetch(ee).then(p=>{if(!p.ok)throw new Error(`Failed to fetch wasm: ${p.status}`);return p.arrayBuffer()}).then(p=>WebAssembly.compile(p)).then(p=>(r.debug(o("wasm"),`ready in ${i(X)}`),p)).catch(p=>{throw S=null,r.warn(o("wasm"),`load failed (${i(X)}):`,p.message||p),p}),S};typeof WebAssembly=="object"&&typeof WebAssembly.compile=="function"&&W().catch(()=>{});let B=null;function j(){return B||(B=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"})),B)}class Ce{constructor(X){this._size=X,this._workers=[],this._idle=[],this._queue=[],this._wasmModule=null,this._spawnFailures=0}setWasm(X){this._wasmModule=X}_spawn(){let X=j(),p=new Worker(X);return p._busy=!1,this._workers.push(p),this._idle.push(p),p}_replaceWorker(X){let p=this._workers.indexOf(X);p!==-1&&this._workers.splice(p,1);let y=this._idle.indexOf(X);y!==-1&&this._idle.splice(y,1);try{X.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(X){for(;this._workers.length<X;)this._spawn()}run(X,p){return new Promise((y,G)=>{this._queue.push({salt:X,target:p,resolve:y,reject:G}),this._dispatch()})}runMsg(X,p){return new Promise((y,G)=>{this._queue.push({msg:X,onProgress:p,resolve:y,reject:G}),this._dispatch()})}_dispatch(){for(;this._idle.length>0&&this._queue.length>0;){let X=this._idle.shift(),p=this._queue.shift(),{resolve:y,reject:G}=p,I=p.msg!==void 0,E=!1,k=({data:_})=>{if(!E){if(!_||typeof _.progress!="number"||_.found)E=!0,X.removeEventListener("message",k),X.removeEventListener("error",z),this._spawnFailures=0,this._idle.push(X),_.found?y(I?_:_.nonce):G(new Error(_.error||"worker failed")),this._dispatch();else if(p.onProgress)try{p.onProgress(_.progress)}catch{}}},z=_=>{if(E)return;E=!0,X.removeEventListener("message",k),X.removeEventListener("error",z);let te=this._replaceWorker(X);G(_),te&&this._dispatch()};X.addEventListener("message",k),X.addEventListener("error",z),I?X.postMessage(p.msg):this._wasmModule?X.postMessage({salt:p.salt,target:p.target,wasmModule:this._wasmModule},[]):X.postMessage({salt:p.salt,target:p.target})}}terminate(){for(let X of this._workers)try{X.terminate()}catch{}this._workers=[],this._idle=[],this._queue=[]}}class ue extends HTMLElement{constructor(){super();ge(this,w);ge(this,pe,null);ge(this,ye,navigator.hardwareConcurrency||8);Wr(this,"token",null);ge(this,ae);ge(this,U);ge(this,N);ge(this,v);ge(this,Z);ge(this,x);ge(this,J,!1);ge(this,F);ge(this,re);ge(this,b,null);ge(this,he,null);ge(this,q,null);ge(this,$,null);ge(this,me,null);ge(this,Se,null);ge(this,Cn,()=>{if(d(this,U)){try{this.scrollIntoView({behavior:"smooth",block:"center"})}catch{this.scrollIntoView()}d(this,U).classList.remove("invalid"),d(this,U).offsetWidth,d(this,U).classList.add("invalid"),setTimeout(()=>d(this,U)?.classList.remove("invalid"),1500)}});d(this,F)&&d(this,F).forEach((p,y)=>{this.removeEventListener(y.slice(2),p)}),P(this,F,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{P(this,re,this.attachInternals())}catch{}}getI18nText(p,y){return this.getAttribute(`data-cap-i18n-${p}`)||d(this,me)?.[p]||y}static get observedAttributes(){return["onsolve","onprogress","onreset","onerror","data-cap-worker-count","data-cap-i18n-initial-state","required"]}initialize(){j(),P(this,Se,new AbortController),d(this,b)||P(this,b,Q(this,w,fi).call(this)),d(this,q)||(P(this,q,new Ce(1)),d(this,q)._spawn())}attributeChangedCallback(p,y,G){if(p.startsWith("on")){let I=p.slice(2),E=d(this,F).get(p);if(E&&this.removeEventListener(I,E),G){let k=z=>{let _=this.getAttribute(p);typeof window[_]=="function"&&window[_].call(this,z)};d(this,F).set(p,k),this.addEventListener(I,k)}}p==="data-cap-worker-count"&&this.setWorkersCount(parseInt(G,10)),p==="data-cap-i18n-initial-state"&&d(this,U)&&d(this,U)?.querySelector(".label.active")&&this.animateLabel(this.getI18nText("initial-state","Verify you're human")),p==="required"&&Q(this,w,Xr).call(this)}async connectedCallback(){P(this,x,this),this.shadowRoot?P(this,ae,this.shadowRoot):P(this,ae,this.attachShadow({mode:"open"})),d(this,U)||P(this,U,document.createElement("div")),Q(this,w,ll).call(this),this.createUI(),this.addEventListeners(),this.initialize(),d(this,N).removeAttribute("disabled");let p=this.getAttribute("data-cap-worker-count"),y=p?parseInt(p,10):null;this.setWorkersCount(y||navigator.hardwareConcurrency||8),d(this,x).innerHTML=`<input type="hidden" name="${d(this,w,Ai)}">`,r.debug(o(),`widget ready (workers=${d(this,ye)}, haptics=${d(this,w,Ft)})`),Q(this,w,yi).call(this),Q(this,w,Xr).call(this),this.addEventListener("invalid",d(this,Cn))}async solve(){if(d(this,J))return;Q(this,w,Rr).call(this);let p=performance.now(),y=d(this,Se)?.signal;r.debug(o("solve"),"starting");try{P(this,J,!0),this.updateUI("verifying",this.getI18nText("verifying-label","Verifying..."),!0),d(this,N).setAttribute("aria-label",this.getI18nText("verifying-aria-label","Verifying you're a human, please wait")),this.dispatchEvent("progress",{progress:0});try{let G,I,E=this.getAttribute("data-cap-api-endpoint");if(!E&&window?.CAP_CUSTOM_FETCH)E="/";else if(!E)throw a("missing_endpoint","Missing API endpoint. Either custom fetch or an API endpoint must be provided.");if(E.endsWith("/")||(E+="/"),d(this,b).state==="done"&&d(this,b).token&&d(this,b).tokenExpires&&Date.now()<d(this,b).tokenExpires)return Q(this,w,Ci).call(this);if(d(this,b).state==="done")G=d(this,b).results,I=d(this,b).challengeResp,this.dispatchEvent("progress",{progress:100});else if(d(this,b).state==="solving"||d(this,b).state==="redeeming"||d(this,b).state==="fetching"||d(this,b).state==="waiting"){d(this,b).state==="waiting"&&(d(this,he)&&(clearTimeout(d(this,he)),P(this,he,null)),d(this,b).state="waiting",Q(this,w,vi).call(this)),d(this,b).pendingPromotion=d(this,ye),d(this,b).promoteFn&&d(this,b).promoteFn(d(this,ye));let Y=setInterval(()=>{if(y?.aborted||!d(this,b))return void clearInterval(Y);let T=d(this,b).state;if(T==="done"||T==="error")return void clearInterval(Y);let de=d(this,b).challenges?d(this,b).challenges.length:1,Ve=d(this,b).completedCount,zt=T==="redeeming"?99:T==="fetching"||T==="waiting"?0:Math.min(98,Math.round(Ve/de*100));this.dispatchEvent("progress",{progress:zt})},150);if(await new Promise(T=>d(this,b).onSettled(T)),clearInterval(Y),y?.aborted||!d(this,b))return;if(d(this,b).state==="idle"&&d(this,b).challengeResp?.format===2&&Array.isArray(d(this,b).challengeResp.challenges))I=d(this,b).challengeResp,d(this,b).challengeResp=null,G=await this.solveChallengesV2(I.challenges,y);else{if(d(this,b).state!=="done")throw a("solve_failed","Unable to solve challenge, self-hosted instance likely down. This is not an issue with Cap.");if(d(this,b).token&&d(this,b).tokenExpires&&Date.now()<d(this,b).tokenExpires)return Q(this,w,Ci).call(this);G=d(this,b).results,I=d(this,b).challengeResp,this.dispatchEvent("progress",{progress:100})}}else{let Y=d(this,b).challengeResp;if(Y?.format===2&&Array.isArray(Y.challenges))I=Y,d(this,b).challengeResp=null;else{let T=await s(`${E}challenge`,{method:"POST",signal:y});try{I=await T.json()}catch{throw a("challenge_parse_error","Failed to parse challenge response from server")}if(I.error)throw a("network_error",I.error)}if(I.format===2&&Array.isArray(I.challenges))G=await this.solveChallengesV2(I.challenges,y);else{let{challenge:T,token:de}=I,Ve=T;if(!Array.isArray(Ve)){let zt=0;Ve=Array.from({length:T.c},()=>(zt++,[f(`${de}${zt}`,T.s),f(`${de}${zt}d`,T.d)]))}G=await this.solveChallenges(Ve,y)}}let k=I.instrumentation?g(I.instrumentation):Promise.resolve(null),z=await k;if(y?.aborted||!d(this,b))return;if(z?.__timeout||z?.__blocked){s(`${E}redeem`,{method:"POST",body:JSON.stringify({token:I.token,solutions:G,...z.__blocked&&{instr_blocked:!0},...z.__timeout&&{instr_timeout:!0}}),headers:{"Content-Type":"application/json"},signal:y}).catch(()=>{}),this.updateUIBlocked(this.getI18nText("error-label","Error"),z?.__blocked),d(this,N).setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again"));let Y=z?.__blocked?"instr_blocked":"instr_timeout",T=z?.__blocked?`Instrumentation blocked (${z.blockReason||"automated_browser"})`:"Instrumentation timed out";this.removeEventListener("error",this.boundHandleError);let de=new CustomEvent("error",{bubbles:!0,composed:!0,detail:{isCap:!0,code:Y,message:T}});return super.dispatchEvent(de),this.addEventListener("error",this.boundHandleError),this.executeAttributeCode("onerror",de),r.error(o("instr"),`[${Y}] ${T}`),void P(this,J,!1)}let{token:_}=I,te=await s(`${E}redeem`,{method:"POST",body:JSON.stringify({token:_,solutions:G,...z&&{instr:z}}),headers:{"Content-Type":"application/json"},signal:y}),ne;try{ne=await te.json()}catch{throw a("redeem_failed","Failed to parse server response")}if(y?.aborted||!d(this,b))return;if(this.dispatchEvent("progress",{progress:100}),!ne.success)throw a("invalid_solution",ne.error||"Invalid solution");Q(this,w,Br).call(this,ne.token),this.dispatchEvent("solve",{token:ne.token}),this.token=ne.token,Q(this,w,bi).call(this),d(this,pe)&&clearTimeout(d(this,pe));let se=new Date(ne.expires).getTime()-Date.now();return se>0&&se<864e5?P(this,pe,setTimeout(()=>this.reset(),se)):this.error("Invalid expiration time","invalid_expires"),d(this,N).setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),d(this,w,Ft)&&navigator.vibrate([10,50,20,30,40]),r.debug(o("solve"),`verified in ${i(p)}`),Q(this,w,Gi).call(this),{success:!0,token:this.token}}catch(G){if(y?.aborted||!d(this,b))return;throw d(this,N).setAttribute("aria-label",this.getI18nText("error-aria-label","An error occurred, please try again")),this.error(G.message,G.code||"solve_failed"),G}}finally{P(this,J,!1)}}async solveChallengesV2(p,y){let G=p.length,I=0,E=new Array(p.length);for(let Y=0;Y<p.length;Y++){let T=p[Y];if(!T||typeof T!="object"||T.protocol!=="sha256-pow"&&T.protocol!=="rsw"&&T.protocol!=="instrumentation")throw a("challenge_unsupported",`unsupported format-2 protocol '${T?.protocol}'`)}let k=null;if(typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function")try{k=await W()}catch(Y){r.warn(o("wasm"),"unavailable, falling back to JS solver:",Y.message||Y)}let z=Math.max(1,Math.min(d(this,ye),p.length)),_=new Ce(z);_.setWasm(k),_._ensureSize(z);let te=(Y,T)=>Promise.race([Y,new Promise((de,Ve)=>setTimeout(()=>Ve(new Error(`[cap] ${T} timed out after 60000ms`)),6e4))]),ne=new Array(p.length).fill(0),se=()=>{let Y=ne.reduce((de,Ve)=>de+Ve,0)+I,T=Math.min(99,Math.round(Y/G*100));this.dispatchEvent("progress",{progress:T})};try{await l(Promise.all(p.map((Y,T)=>Y.protocol==="sha256-pow"?te(_.run(Y.payload.salt,Y.payload.target),`sha256-pow worker #${T}`).then(de=>{E[T]={nonce:Number(de)},ne[T]=0,I++,se()}):Y.protocol==="rsw"?te(_.runMsg({kind:"rsw",N:Y.payload.N,x:Y.payload.x,t:0|Y.payload.t},de=>{ne[T]=de,se()}),`rsw worker #${T}`).then(de=>{E[T]={y:de.y},ne[T]=0,I++,se()}):g(Y.payload.blob).then(de=>{E[T]=de?.__timeout?{timeout:!0}:de?.__blocked?{blocked:!0}:{instr:de},ne[T]=0,I++,se()}))),y)}finally{_.terminate()}return E}async solveChallenges(p,y){let G=p.length,I=0,E=null,k=typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function";if(k)try{E=await W()}catch(te){r.warn(o("wasm"),"unavailable, falling back to JS solver:",te.message||te)}if(!k&&(r.warn(o("wasm"),"WebAssembly disabled in this browser, solver will be ~10x slower"),!d(this,ae).querySelector(".warning"))){let te=document.createElement("div");te.className="warning",te.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;",te.innerText=this.getI18nText("wasm-disabled","Enable WASM for significantly faster solving"),d(this,ae).insertBefore(te,d(this,ae).firstChild),setTimeout(()=>{te.style.marginBottom="calc(-1 * var(--cap-border-radius, 14px))",te.style.opacity=1},10)}let z=new Ce(d(this,ye));z.setWasm(E),z._ensureSize(d(this,ye));let _=[];try{for(let te=0;te<p.length;te+=d(this,ye)){let ne=p.slice(te,Math.min(te+d(this,ye),p.length)),se=await l(Promise.all(ne.map(([Y,T])=>z.run(Y,T).then(de=>{I++;let Ve=Math.min(99,Math.round((0+I)/G*100));return this.dispatchEvent("progress",{progress:Ve}),de}))),y);_.push(...se)}}finally{z.terminate()}return _}setWorkersCount(p){let y=parseInt(p,10),G=Math.min(navigator.hardwareConcurrency||8,16);P(this,ye,!Number.isNaN(y)&&y>0&&y<=G?y:navigator.hardwareConcurrency||8)}createUI(){d(this,U).classList.add("captcha"),d(this,U).setAttribute("role","group"),d(this,U).setAttribute("aria-label",this.getI18nText("group-aria-label","Cap verification")),P(this,N,document.createElement("div")),d(this,N).className="captcha-trigger",d(this,N).setAttribute("part","trigger"),d(this,N).setAttribute("role","button"),d(this,N).setAttribute("tabindex","0"),d(this,N).setAttribute("aria-label",this.getI18nText("verify-aria-label","Click to verify you're a human")),d(this,N).setAttribute("aria-live","polite"),d(this,N).setAttribute("disabled","true"),d(this,N).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>`,d(this,U).appendChild(d(this,N)),P(this,Z,document.createElement("a")),d(this,Z).className="cap-troubleshoot-link",d(this,Z).setAttribute("part","troubleshoot"),d(this,Z).setAttribute("target","_blank"),d(this,Z).setAttribute("rel","noopener"),d(this,Z).hidden=!0,d(this,U).appendChild(d(this,Z)),P(this,v,document.createElement("a")),d(this,v).className="credits",d(this,v).setAttribute("aria-label","Secured by Cap"),d(this,v).setAttribute("href","https://trycap.dev"),d(this,v).setAttribute("target","_blank"),d(this,v).setAttribute("title","Secured by Cap: The self-hosted CAPTCHA for the modern web."),d(this,v).textContent="Cap",d(this,U).appendChild(d(this,v)),d(this,ae).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>`,d(this,ae).appendChild(d(this,U)),Q(this,w,Rr).call(this),setTimeout(()=>Q(this,w,Rr).call(this),100)}addEventListeners(){d(this,N)&&(d(this,v).addEventListener("click",p=>{p.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")}),d(this,N).addEventListener("click",()=>{d(this,N).hasAttribute("disabled")||this.solve()}),d(this,N).addEventListener("mousedown",()=>{!d(this,N).hasAttribute("disabled")&&d(this,w,Ft)&&navigator.vibrate(5)}),d(this,N).addEventListener("keydown",p=>{p.target===d(this,N)&&(p.key!=="Enter"&&p.key!==" "||d(this,N).hasAttribute("disabled")||(p.preventDefault(),p.stopPropagation(),this.solve()))}),this.addEventListener("progress",this.boundHandleProgress),this.addEventListener("solve",this.boundHandleSolve),this.addEventListener("error",this.boundHandleError),this.addEventListener("reset",this.boundHandleReset))}animateLabel(p){if(!d(this,N))return;let y=d(this,N).querySelector(".label-wrapper");if(!y)return;if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches){let E=y.querySelector(".label.active");if(E)E.textContent=p;else{let k=document.createElement("span");k.className="label active",k.textContent=p,y.appendChild(k)}return}let G=y.querySelector(".label.active"),I=document.createElement("span");I.className="label",I.textContent=p,y.appendChild(I),I.offsetWidth,I.classList.add("active"),G&&(G.classList.remove("active"),G.classList.add("exit"),G.addEventListener("transitionend",()=>G.remove(),{once:!0}))}updateUI(p,y,G=!1){d(this,U)&&d(this,N)&&(d(this,U).setAttribute("data-state",p),d(this,U).classList.remove("has-troubleshoot"),this.animateLabel(y),d(this,Z)&&(d(this,Z).hidden=!0),G?d(this,N).setAttribute("disabled","true"):d(this,N).removeAttribute("disabled"))}updateUIBlocked(p,y=!1){if(d(this,U)&&d(this,N)&&(d(this,U).setAttribute("data-state","error"),d(this,N).removeAttribute("disabled"),this.animateLabel(p),d(this,Z)))if(y){let G=this.getAttribute("data-cap-troubleshooting-url")||"https://trycap.dev/guide/troubleshooting/instrumentation.html";d(this,Z).setAttribute("href",G),d(this,Z).textContent=this.getI18nText("troubleshooting-label","Troubleshoot"),d(this,Z).hidden=!1,d(this,U).classList.add("has-troubleshoot")}else d(this,Z).hidden=!0,d(this,U).classList.remove("has-troubleshoot")}handleProgress(p){if(!d(this,N))return;let y=d(this,N).querySelector(".progress-ring-circle");if(y){let I=2*Math.PI*14,E=I-p.detail.progress/100*I;y.style.strokeDashoffset=E}let G=d(this,N).querySelector(".label-wrapper");if(G){let I=G.querySelector(".label.active");I&&(I.textContent=`${this.getI18nText("verifying-label","Verifying...")}`)}this.executeAttributeCode("onprogress",p)}handleSolve(p){this.updateUI("done",this.getI18nText("solved-label","You're a human"),!0),this.executeAttributeCode("onsolve",p),d(this,re)?.setValidity?.({}),d(this,U)?.classList.remove("invalid")}handleError(p){this.updateUI("error",this.getI18nText("error-label","Error. Try again.")),this.executeAttributeCode("onerror",p),d(this,w,Ft)&&navigator.vibrate([10,40,10])}handleReset(p){this.updateUI("",this.getI18nText("initial-state","I'm a human")),this.executeAttributeCode("onreset",p),Q(this,w,Xr).call(this)}executeAttributeCode(p,y){let G=this.getAttribute(p);G&&(r.warn(o(),"inline `onxxx='\u2026'` handlers are deprecated. use `addEventListener` callbacks instead."),new Function("event",G).call(this,y))}error(p="Unknown error",y="unknown"){r.error(o("solve"),`[${y}] ${p}`),this.dispatchEvent("error",{isCap:!0,code:y,message:p})}dispatchEvent(p,y={}){let G=new CustomEvent(p,{bubbles:!0,composed:!0,detail:y});super.dispatchEvent(G)}reset(){d(this,pe)&&(clearTimeout(d(this,pe)),P(this,pe,null)),this.token=null,this.dispatchEvent("reset"),Q(this,w,Br).call(this,"")}get tokenValue(){return this.token}disconnectedCallback(){d(this,Se)?.abort(),this.removeEventListener("progress",this.boundHandleProgress),this.removeEventListener("solve",this.boundHandleSolve),this.removeEventListener("error",this.boundHandleError),this.removeEventListener("reset",this.boundHandleReset),d(this,F).forEach((p,y)=>{this.removeEventListener(y.slice(2),p)}),d(this,F).clear(),d(this,ae)&&(d(this,ae).innerHTML=""),this.reset(),this.cleanup()}cleanup(){d(this,pe)&&(clearTimeout(d(this,pe)),P(this,pe,null)),Q(this,w,wr).call(this),d(this,he)&&(clearTimeout(d(this,he)),P(this,he,null)),d(this,q)&&(d(this,q).terminate(),P(this,q,null)),d(this,b)&&(d(this,b).state="error",d(this,b).notify(),P(this,b,null))}}pe=new WeakMap,ye=new WeakMap,ae=new WeakMap,U=new WeakMap,N=new WeakMap,v=new WeakMap,Z=new WeakMap,x=new WeakMap,J=new WeakMap,F=new WeakMap,re=new WeakMap,b=new WeakMap,he=new WeakMap,q=new WeakMap,$=new WeakMap,me=new WeakMap,Se=new WeakMap,w=new WeakSet,Ft=function(){return t&&!window.CAP_DISABLE_HAPTICS&&!this.hasAttribute("data-cap-disable-haptics")},fi=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 p of this._listeners)p();this._listeners=[]},onSettled(p){this.state==="done"||this.state==="error"?p():this._listeners.push(p)}}},bi=function(){P(this,b,Q(this,w,fi).call(this)),Q(this,w,yi).call(this)},wr=function(){d(this,$)&&(window.removeEventListener("mousemove",d(this,$)),window.removeEventListener("touchstart",d(this,$)),window.removeEventListener("keydown",d(this,$)),P(this,$,null))},yi=function(){Q(this,w,wr).call(this);let p=()=>{Q(this,w,wr).call(this),Q(this,w,il).call(this)};P(this,$,p),window.addEventListener("mousemove",p,{passive:!0}),window.addEventListener("touchstart",p,{passive:!0}),window.addEventListener("keydown",p,{passive:!0})},Ii=function(){return typeof this.checkVisibility=="function"?this.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0}):!!(this.offsetParent||this.getClientRects().length>0)},Gi=function(){Q(this,w,Ii).call(this)||r.info(o("challenges"),"solved invisible challenge")},il=function(){d(this,b).state==="idle"&&Q(this,w,Ii).call(this)&&(d(this,b).state="waiting",P(this,he,setTimeout(()=>{Q(this,w,vi).call(this)},2500)))},vi=async function(){if(d(this,b).state!=="waiting")return;d(this,b).state="fetching",d(this,b)._t0=performance.now();let p=this.getAttribute("data-cap-api-endpoint");if(!p&&window?.CAP_CUSTOM_FETCH&&(p="/"),p){p.endsWith("/")||(p+="/");try{let y=await s(`${p}challenge`,{method:"POST",signal:d(this,Se)?.signal}),G;try{G=await y.json()}catch{throw new Error("Failed to parse speculative challenge response")}if(G.error)throw new Error(G.error);if(!d(this,b))return;if(G._apiEndpoint=p,d(this,b).challengeResp=G,G.format===2&&Array.isArray(G.challenges))return d(this,b).state="idle",void d(this,b).notify();let{challenge:I,token:E}=G,k=I;if(!Array.isArray(k)){let z=0;k=Array.from({length:I.c},()=>(z++,[f(`${E}${z}`,I.s),f(`${E}${z}d`,I.d)]))}d(this,b).challenges=k,d(this,b).state="solving",d(this,b).solvePromise=Q(this,w,al).call(this,k)}catch{if(!d(this,b))return;d(this,b).state="error",d(this,b).notify()}}else d(this,b).state="idle"},al=async function(p){j();let y=null;try{y=await W()}catch{}d(this,q)||(P(this,q,new Ce(1)),d(this,q)._spawn()),d(this,q).setWasm(y);let G=p.length,I=new Array(G),E=1,k=!1;d(this,b).promoteFn=_=>{k||(k=!0,E=_,d(this,q)._size=_,d(this,q)._ensureSize(_))},d(this,b).pendingPromotion!==null&&(d(this,b).promoteFn(d(this,b).pendingPromotion),d(this,b).pendingPromotion=null);let z=0;for(;z<G;){let _=E,te=[],ne=[];for(let Y=0;Y<_&&z<G;Y++)ne.push(z),te.push(p[z]),z++;d(this,q)._ensureSize(Math.max(E,_));let se=await Promise.all(te.map(Y=>d(this,q).run(Y[0],Y[1]).then(T=>(d(this,b)&&d(this,b).completedCount++,T))));for(let Y=0;Y<ne.length;Y++)I[ne[Y]]=se[Y];!k&&z<G&&await new Promise(Y=>setTimeout(Y,120))}return d(this,b)&&(d(this,b).results=I,d(this,b).state="redeeming",Q(this,w,sl).call(this,I)),I},sl=async function(p){try{if(!d(this,b))return;let y=d(this,b).challengeResp,G=y._apiEndpoint;if(!G)throw a("missing_endpoint","speculative redeem: missing apiEndpoint");let I=null;if(y.instrumentation){if(I=await g(y.instrumentation),!d(this,b))return;if(I?.__timeout||I?.__blocked)return d(this,b).state="done",void d(this,b).notify()}let E=await s(`${G}redeem`,{method:"POST",body:JSON.stringify({token:y.token,solutions:p,...I&&{instr:I}}),headers:{"Content-Type":"application/json"},signal:d(this,Se)?.signal}),k;try{k=await E.json()}catch{throw new Error("Failed to parse speculative redeem response")}if(!d(this,b))return;if(!k.success)throw new Error(k.error||"Speculative redeem failed");d(this,b).token=k.token,d(this,b).tokenExpires=new Date(k.expires).getTime(),d(this,b).state="done",d(this,b)._invisibleElapsed=d(this,b)._t0?i(d(this,b)._t0):"?",d(this,b).notify()}catch{if(!d(this,b))return;d(this,b).state="done",d(this,b).notify()}},Ai=function(){return this.getAttribute("data-cap-hidden-field-name")||"cap-token"},Br=function(p){let y=this.querySelector(`input[name='${d(this,w,Ai)}']`);y&&(y.value=p)},Ci=function(){r.debug(o("solve"),`served from speculative cache (saved ${d(this,b)._invisibleElapsed||"?"})`),this.dispatchEvent("progress",{progress:100}),Q(this,w,Br).call(this,d(this,b).token),this.dispatchEvent("solve",{token:d(this,b).token}),this.token=d(this,b).token;let p=d(this,b).tokenExpires-Date.now();return d(this,pe)&&clearTimeout(d(this,pe)),P(this,pe,setTimeout(()=>this.reset(),p)),d(this,N).setAttribute("aria-label",this.getI18nText("verified-aria-label","We have verified you're a human, you may now continue")),d(this,w,Ft)&&navigator.vibrate([10,50,20,30,40]),Q(this,w,Gi).call(this),Q(this,w,bi).call(this),P(this,J,!1),{success:!0,token:this.token}},ll=function(){P(this,me,(function(p){let y=p?[p]:navigator.languages||[navigator.language||""];for(let G of y){if(!G)continue;if(G=G.toLowerCase(),G==="en"||G.startsWith("en-"))return null;let I=h[G]?G:h[G.split("-")[0]]?G.split("-")[0]:null;if(!I)return null;let E=h[I].split("/"),k={};return c.forEach((z,_)=>{k[z]=E[_]}),k}return null})(window.CAP_LANG||this.getAttribute("data-cap-lang")))},Xr=function(){d(this,re)?.setValidity&&(this.hasAttribute("required")&&!this.token?d(this,re).setValidity({valueMissing:!0},this.getI18nText("required-label","Please verify you're human"),d(this,U)||this):d(this,re).setValidity({}))},Cn=new WeakMap,cl=function(){if(!d(this,x))return!1;let p=d(this,x).getBoundingClientRect();if(p.width===0&&p.height===0)return!0;let y=window.getComputedStyle(d(this,x));return y.display==="none"||y.visibility==="hidden"},Rr=function(){d(this,v)&&d(this,U)&&!Q(this,w,cl).call(this)&&(d(this,v).isConnected&&d(this,v).parentNode===d(this,U)||d(this,U).appendChild(d(this,v)),d(this,v).textContent&&d(this,v).textContent.trim()||(d(this,v).textContent="Cap"),d(this,v).getAttribute("href")!=="https://trycap.dev"&&d(this,v).setAttribute("href","https://trycap.dev"),d(this,v).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("; "))},Wr(ue,"formAssociated",!0);class xe{constructor(X={},p){let y=p||document.createElement("cap-widget");if(Object.entries(X).forEach(([G,I])=>{y.setAttribute(G,I)}),!X.apiEndpoint&&!window?.CAP_CUSTOM_FETCH)throw y.remove(),new Error("Missing API endpoint. Either custom fetch or an API endpoint must be provided.");X.apiEndpoint&&y.setAttribute("data-cap-api-endpoint",X.apiEndpoint),p||y.hasAttribute("data-cap-disable-haptics")||y.setAttribute("data-cap-disable-haptics",""),this.widget=y,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:()=>y.token,configurable:!0,enumerable:!0}),p||(y.style.display="none",document.documentElement.appendChild(y))}}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 kr=="object"&&typeof xi<"u"?xi.exports=xe:typeof define=="function"&&define.amd&&define([],()=>xe),typeof kr<"u"&&(kr.