diff --git a/widget/build.js b/widget/build.js index b810f53..9678c3b 100644 --- a/widget/build.js +++ b/widget/build.js @@ -1,5 +1,5 @@ -import fs from "fs/promises" -import babel from "@babel/core" +import fs from "fs/promises"; +import babel from "@babel/core"; import { minify } from "terser"; const paths = [ @@ -19,9 +19,9 @@ paths.forEach(async function ([inpath, outpath]) { "@babel/preset-env", { targets: outpath.includes(".compat") - ? "last 600 Chrome versions, last 600 Firefox versions, last 20 Safari versions, last 20 Edge versions" + ? "last 60 Chrome versions, last 60 Firefox versions, last 20 Safari versions, last 20 Edge versions" : "last 20 Chrome versions, last 15 Firefox versions, last 10 Safari versions, last 10 Edge versions", - loose: true + loose: true, }, ], ], diff --git a/widget/src/cap.compat.min.js b/widget/src/cap.compat.min.js index 70c12d8..bc5f058 100644 --- a/widget/src/cap.compat.min.js +++ b/widget/src/cap.compat.min.js @@ -1 +1 @@ -"use strict";function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,r){return e[t]=r}}function u(e,t,r,n){var o=t&&t.prototype instanceof b?t:b,i=Object.create(o.prototype),s=new S(n||[]);return a(i,"_invoke",{value:F(e,r,s)}),i}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=u;var d="suspendedStart",h="suspendedYield",f="executing",v="completed",g={};function b(){}function y(){}function m(){}var w={};l(w,i,(function(){return this}));var _=Object.getPrototypeOf,k=_&&_(_(j([])));k&&k!==r&&n.call(k,i)&&(w=k);var L=m.prototype=b.prototype=Object.create(w);function x(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function P(e,t){function r(a,o,i,s){var c=p(e[a],e,o);if("throw"!==c.type){var l=c.arg,u=l.value;return u&&"object"==typeof u&&n.call(u,"__await")?t.resolve(u.__await).then((function(e){r("next",e,i,s)}),(function(e){r("throw",e,i,s)})):t.resolve(u).then((function(e){l.value=e,i(l)}),(function(e){return r("throw",e,i,s)}))}s(c.arg)}var o;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return o=o?o.then(a,a):a()}})}function F(t,r,n){var a=d;return function(o,i){if(a===f)throw Error("Generator is already running");if(a===v){if("throw"===o)throw i;return{value:e,done:!0}}for(n.method=o,n.arg=i;;){var s=n.delegate;if(s){var c=E(s,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=f;var l=p(t,r,n);if("normal"===l.type){if(a=n.done?v:h,l.arg===g)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(a=v,n.method="throw",n.arg=l.arg)}}}function E(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var o=p(a,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,g;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,g):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function B(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(B,this),this.reset(!0)}function j(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),l=n.call(i,"finallyLoc");if(c&&l){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;O(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:j(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),g}},t}function asyncGeneratorStep(e,t,r,n,a,o,i){try{var s=e[o](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function i(e){asyncGeneratorStep(o,n,a,i,s,"next",e)}function s(e){asyncGeneratorStep(o,n,a,i,s,"throw",e)}i(void 0)}))}}function _defineProperties(e,t){for(var r=0;r';case 11:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),h.solve=function(){var e=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var a,i,s,c,u,p,d,h=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!_classPrivateFieldLooseBase(this,l)[l]){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,_classPrivateFieldLooseBase(this,l)[l]=!0,this.updateUI("verifying","Verifying...",!0),e.next=7,t((function(){return!!_classPrivateFieldLooseBase(h,r)[r]}));case 7:if(this.dispatchEvent("progress",{progress:0}),e.prev=8,a=this.getAttribute("data-cap-api-endpoint")){e.next=12;break}throw new Error("Missing API endpoint");case 12:return e.next=14,fetch(a+"challenge",{method:"POST"});case 14:return e.next=16,e.sent.json();case 16:return i=e.sent,s=i.challenge,i.target,c=i.token,e.next=22,this.solveChallenges(s);case 22:return u=e.sent,e.next=25,fetch(a+"redeem",{method:"POST",body:JSON.stringify({token:c,solutions:u}),headers:{"Content-Type":"application/json"}});case 25:return e.next=27,e.sent.json();case 27:if((p=e.sent).success){e.next=30;break}throw new Error("Invalid solution");case 30:return this.dispatchEvent("progress",{progress:100}),this.dispatchEvent("solve",{token:p.token}),_classPrivateFieldLooseBase(this,o)[o]=p.token,this.querySelector("input[name='cap-token']")&&(this.querySelector("input[name='cap-token']").value=p.token),_classPrivateFieldLooseBase(this,n)[n]&&clearTimeout(_classPrivateFieldLooseBase(this,n)[n]),(d=new Date(p.expires).getTime()-Date.now())>0&&d<864e5?_classPrivateFieldLooseBase(this,n)[n]=setTimeout((function(){return h.reset()}),d):this.error("Invalid expiration time"),e.abrupt("return",{success:!0,token:_classPrivateFieldLooseBase(this,o)[o]});case 40:throw e.prev=40,e.t0=e.catch(8),this.error(e.t0.message),e.t0;case 44:return e.prev=44,_classPrivateFieldLooseBase(this,l)[l]=!1,e.finish(44);case 47:case"end":return e.stop()}}),e,this,[[2,,44,47],[8,40]])})));return function(){return e.apply(this,arguments)}}(),h.solveChallenges=function(){var e=_asyncToGenerator(_regeneratorRuntime().mark((function e(t){var n,o,i,s,c,l,u,p,d=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=t.length,o=0,i=Array(_classPrivateFieldLooseBase(this,a)[a]).fill(null).map((function(){return new Worker(_classPrivateFieldLooseBase(d,r)[r])})),s=function(e,t){var a=e[0],s=e[1];return new Promise((function(e,c){var l=i[t],u=setTimeout((function(){l.terminate(),i[t]=new Worker(_classPrivateFieldLooseBase(d,r)[r]),c(new Error("Worker timeout"))}),3e4);l.onmessage=function(t){var r=t.data;r.found&&(clearTimeout(u),o++,d.dispatchEvent("progress",{progress:Math.round(o/n*100)}),e([a,s,r.nonce]))},l.onerror=function(e){clearTimeout(u),d.error("Error in worker: "+e),c(e)},l.postMessage({salt:a,target:s})}))},c=[],e.prev=5,l=0;case 7:if(!(l0&&t<=r?t:navigator.hardwareConcurrency||8},h.createUI=function(){_classPrivateFieldLooseBase(this,s)[s].classList.add("captcha"),_classPrivateFieldLooseBase(this,s)[s].setAttribute("role","button"),_classPrivateFieldLooseBase(this,s)[s].setAttribute("tabindex","0"),_classPrivateFieldLooseBase(this,s)[s].setAttribute("disabled","true"),_classPrivateFieldLooseBase(this,s)[s].innerHTML='

I\'m a human

Secured by Cap',_classPrivateFieldLooseBase(this,i)[i].innerHTML='',_classPrivateFieldLooseBase(this,i)[i].appendChild(_classPrivateFieldLooseBase(this,s)[s])},h.addEventListeners=function(){var e=this;_classPrivateFieldLooseBase(this,s)[s].querySelector("a").addEventListener("click",(function(e){e.stopPropagation(),e.preventDefault(),window.open("#","_blank")})),_classPrivateFieldLooseBase(this,s)[s].addEventListener("click",(function(){_classPrivateFieldLooseBase(e,s)[s].hasAttribute("disabled")||e.solve()})),this.addEventListener("progress",this.boundHandleProgress),this.addEventListener("solve",this.boundHandleSolve),this.addEventListener("error",this.boundHandleError),this.addEventListener("reset",this.boundHandleReset)},h.updateUI=function(e,t,r){void 0===r&&(r=!1),_classPrivateFieldLooseBase(this,s)[s].setAttribute("data-state",e),_classPrivateFieldLooseBase(this,s)[s].querySelector("p").innerText=t,r?_classPrivateFieldLooseBase(this,s)[s].setAttribute("disabled","true"):_classPrivateFieldLooseBase(this,s)[s].removeAttribute("disabled")},h.handleProgress=function(e){var t=_classPrivateFieldLooseBase(this,s)[s].querySelector("p");t&&(_classPrivateFieldLooseBase(this,s)[s].querySelector(".checkbox").style.setProperty("--progress",e.detail.progress+"%"),t.innerText="Verifying... "+e.detail.progress+"%"),this.executeAttributeCode("onprogress",e)},h.handleSolve=function(e){this.updateUI("done","You're a human",!0),this.executeAttributeCode("onsolve",e)},h.handleError=function(e){this.updateUI("error","Error. Try again."),this.executeAttributeCode("onerror",e)},h.handleReset=function(e){this.updateUI("","I'm a human"),this.executeAttributeCode("onreset",e)},h.executeAttributeCode=function(e,t){var r=this.getAttribute(e);r&&new Function("event",r).call(this,t)},h.error=function(e){void 0===e&&(e="Unknown error"),console.error("[Cap] Error:",e),this.dispatchEvent("error",{isCap:!0,message:e})},h.dispatchEvent=function(e,t){void 0===t&&(t={});var r=new CustomEvent(e,{bubbles:!0,composed:!0,detail:t});p.prototype.dispatchEvent.call(this,r)},h.reset=function(){_classPrivateFieldLooseBase(this,n)[n]&&(clearTimeout(_classPrivateFieldLooseBase(this,n)[n]),_classPrivateFieldLooseBase(this,n)[n]=null),this.dispatchEvent("reset"),_classPrivateFieldLooseBase(this,o)[o]=null,this.querySelector("input[name='cap-token']")&&(this.querySelector("input[name='cap-token']").value="")},h.disconnectedCallback=function(){var e=this;this.removeEventListener("progress",this.boundHandleProgress),this.removeEventListener("solve",this.boundHandleSolve),this.removeEventListener("error",this.boundHandleError),this.removeEventListener("reset",this.boundHandleReset),_classPrivateFieldLooseBase(this,u)[u].forEach((function(t,r){e.removeEventListener(r.slice(2),t)})),_classPrivateFieldLooseBase(this,u)[u].clear(),_classPrivateFieldLooseBase(this,i)[i]&&(_classPrivateFieldLooseBase(this,i)[i].innerHTML=""),this.reset(),this.cleanup()},h.cleanup=function(){_classPrivateFieldLooseBase(this,n)[n]&&(clearTimeout(_classPrivateFieldLooseBase(this,n)[n]),_classPrivateFieldLooseBase(this,n)[n]=null),_classPrivateFieldLooseBase(this,r)[r]&&(URL.revokeObjectURL(_classPrivateFieldLooseBase(this,r)[r]),_classPrivateFieldLooseBase(this,r)[r]="")},_createClass(d,[{key:"token",get:function(){return _classPrivateFieldLooseBase(this,o)[o]}}],[{key:"observedAttributes",get:function(){return["onsolve","onprogress","onreset","onerror","workers"]}}])}(_wrapNativeSuper(HTMLElement)),d=function(e,t){void 0===e&&(e={});var r=t||document.createElement("cap-widget");if(Object.entries(e).forEach((function(e){var t=e[0],n=e[1];r.setAttribute(t,n)})),!e.apiEndpoint)throw r.remove(),new Error("Missing API endpoint");console.log(e),r.setAttribute("data-cap-api-endpoint",e.apiEndpoint),this.widget=r,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:function(){return r.getToken()},configurable:!0,enumerable:!0}),t||(r.style.display="none",document.documentElement.appendChild(r))},h=new CSSStyleSheet;h.replaceSync('html{--cap-font:system,-apple-system,"BlinkMacSystemFont",".SFNSText-Regular","San Francisco","Roboto","Segoe UI","Helvetica Neue","Lucida Grande","Ubuntu","arial",sans-serif;--cap-color:#212121;--cap-background:#fdfdfd;--cap-border-color:#dddddd8f;--cap-border-radius:14px;--cap-checkbox-border:1px solid #aaaaaad1;--cap-checkbox-border-radius:6px;--cap-checkbox-background:#fafafa91;--cap-widget-width:240px;--cap-widget-padding:14px;--cap-checkbox-size:24px;--cap-checkbox-margin:2px;--cap-transition-duration:0.2s;--cap-gap:15px;--cap-opacity-hover:0.8;--cap-hover-filter:brightness(97%);--cap-active-scale:0.98;--cap-credits-font-size:12px;--cap-spinner-color:black;--cap-spinner-background-color:#eee;--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/svg%3E");--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");--cap-spinner-thickness:5px;}'),document.adoptedStyleSheets.push(h);var f=function(){var e;self.onmessage=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark((function t(r){var n,a,o,i,s,c,l,u,p,d,h,f,v,g,b,y,m,w,_,k;return _regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.data,a=n.salt,o=n.target,i=0,s=5e4,c=new TextEncoder,"object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){t.next=46;break}for(console.log("[cap] WASM not enabled, falling back to crypto.subtle\nThis is significanty slower than the WASM implementation"),l=new Uint8Array(o.length/2),u=0;u{const i=setTimeout((()=>{a(new Error("Initialize timeout"))}),t),r=()=>{e()?(clearTimeout(i),s()):setTimeout(r,500)};r()}))};var s=_classPrivateFieldLooseKey("workerUrl"),a=_classPrivateFieldLooseKey("resetTimer"),i=_classPrivateFieldLooseKey("workersCount"),r=_classPrivateFieldLooseKey("token"),o=_classPrivateFieldLooseKey("shadow"),n=_classPrivateFieldLooseKey("div"),c=_classPrivateFieldLooseKey("host"),l=_classPrivateFieldLooseKey("solving"),d=_classPrivateFieldLooseKey("eventHandlers");class h extends HTMLElement{static get observedAttributes(){return["onsolve","onprogress","onreset","onerror","workers"]}constructor(){super(),Object.defineProperty(this,s,{writable:!0,value:""}),Object.defineProperty(this,a,{writable:!0,value:null}),Object.defineProperty(this,i,{writable:!0,value:navigator.hardwareConcurrency||8}),Object.defineProperty(this,r,{writable:!0,value:null}),Object.defineProperty(this,o,{writable:!0,value:void 0}),Object.defineProperty(this,n,{writable:!0,value:void 0}),Object.defineProperty(this,c,{writable:!0,value:void 0}),Object.defineProperty(this,l,{writable:!0,value:!1}),Object.defineProperty(this,d,{writable:!0,value:void 0}),_classPrivateFieldLooseBase(this,d)[d]&&_classPrivateFieldLooseBase(this,d)[d].forEach(((e,t)=>{this.removeEventListener(t.slice(2),e)})),_classPrivateFieldLooseBase(this,d)[d]=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)}async initialize(){_classPrivateFieldLooseBase(this,s)[s]&&URL.revokeObjectURL(_classPrivateFieldLooseBase(this,s)[s]);try{await t((()=>!!e)),_classPrivateFieldLooseBase(this,s)[s]=URL.createObjectURL(new Blob([e],{type:"application/javascript"}))}catch(e){throw this.error("Failed to initialize worker"),e}}attributeChangedCallback(e,t,s){if(e.startsWith("on")){const t=e.slice(2),a=_classPrivateFieldLooseBase(this,d)[d].get(e);if(a&&this.removeEventListener(t,a),s){const s=t=>{const s=this.getAttribute(e);"function"==typeof window[s]&&window[s].call(this,t)};_classPrivateFieldLooseBase(this,d)[d].set(e,s),this.addEventListener(t,s)}}}async connectedCallback(){_classPrivateFieldLooseBase(this,c)[c]=this,_classPrivateFieldLooseBase(this,o)[o]=this.attachShadow({mode:"open"}),_classPrivateFieldLooseBase(this,n)[n]=document.createElement("div"),this.createUI(),this.addEventListeners(),await this.initialize(),_classPrivateFieldLooseBase(this,n)[n].removeAttribute("disabled");const e=this.getAttribute("data-cap-worker-count");this.setWorkersCount(parseInt(e)?parseInt(e,10):navigator.hardwareConcurrency||8),_classPrivateFieldLooseBase(this,c)[c].innerHTML=''}async solve(){if(!_classPrivateFieldLooseBase(this,l)[l])try{_classPrivateFieldLooseBase(this,l)[l]=!0,this.updateUI("verifying","Verifying...",!0),await t((()=>!!_classPrivateFieldLooseBase(this,s)[s])),this.dispatchEvent("progress",{progress:0});try{const e=this.getAttribute("data-cap-api-endpoint");if(!e)throw new Error("Missing API endpoint");const{challenge:t,target:s,token:i}=await(await fetch(`${e}challenge`,{method:"POST"})).json(),o=await this.solveChallenges(t),n=await(await fetch(`${e}redeem`,{method:"POST",body:JSON.stringify({token:i,solutions:o}),headers:{"Content-Type":"application/json"}})).json();if(!n.success)throw new Error("Invalid solution");this.dispatchEvent("progress",{progress:100}),this.dispatchEvent("solve",{token:n.token}),_classPrivateFieldLooseBase(this,r)[r]=n.token,this.querySelector("input[name='cap-token']")&&(this.querySelector("input[name='cap-token']").value=n.token),_classPrivateFieldLooseBase(this,a)[a]&&clearTimeout(_classPrivateFieldLooseBase(this,a)[a]);const c=new Date(n.expires).getTime()-Date.now();return c>0&&c<864e5?_classPrivateFieldLooseBase(this,a)[a]=setTimeout((()=>this.reset()),c):this.error("Invalid expiration time"),{success:!0,token:_classPrivateFieldLooseBase(this,r)[r]}}catch(e){throw this.error(e.message),e}}finally{_classPrivateFieldLooseBase(this,l)[l]=!1}}async solveChallenges(e){const t=e.length;let a=0;const r=Array(_classPrivateFieldLooseBase(this,i)[i]).fill(null).map((()=>new Worker(_classPrivateFieldLooseBase(this,s)[s]))),o=(e,i)=>{let[o,n]=e;return new Promise(((e,c)=>{const l=r[i],d=setTimeout((()=>{l.terminate(),r[i]=new Worker(_classPrivateFieldLooseBase(this,s)[s]),c(new Error("Worker timeout"))}),3e4);l.onmessage=s=>{let{data:i}=s;i.found&&(clearTimeout(d),a++,this.dispatchEvent("progress",{progress:Math.round(a/t*100)}),e([o,n,i.nonce]))},l.onerror=e=>{clearTimeout(d),this.error(`Error in worker: ${e}`),c(e)},l.postMessage({salt:o,target:n})}))},n=[];try{for(let t=0;to(e,t))));n.push(...a)}}finally{r.forEach((e=>e.terminate()))}return n}setWorkersCount(e){const t=parseInt(e,10),s=Math.min(navigator.hardwareConcurrency||8,16);_classPrivateFieldLooseBase(this,i)[i]=!isNaN(t)&&t>0&&t<=s?t:navigator.hardwareConcurrency||8}createUI(){_classPrivateFieldLooseBase(this,n)[n].classList.add("captcha"),_classPrivateFieldLooseBase(this,n)[n].setAttribute("role","button"),_classPrivateFieldLooseBase(this,n)[n].setAttribute("tabindex","0"),_classPrivateFieldLooseBase(this,n)[n].setAttribute("disabled","true"),_classPrivateFieldLooseBase(this,n)[n].innerHTML='

I\'m a human

Secured by Cap',_classPrivateFieldLooseBase(this,o)[o].innerHTML='',_classPrivateFieldLooseBase(this,o)[o].appendChild(_classPrivateFieldLooseBase(this,n)[n])}addEventListeners(){_classPrivateFieldLooseBase(this,n)[n].querySelector("a").addEventListener("click",(e=>{e.stopPropagation(),e.preventDefault(),window.open("#","_blank")})),_classPrivateFieldLooseBase(this,n)[n].addEventListener("click",(()=>{_classPrivateFieldLooseBase(this,n)[n].hasAttribute("disabled")||this.solve()})),this.addEventListener("progress",this.boundHandleProgress),this.addEventListener("solve",this.boundHandleSolve),this.addEventListener("error",this.boundHandleError),this.addEventListener("reset",this.boundHandleReset)}updateUI(e,t,s){void 0===s&&(s=!1),_classPrivateFieldLooseBase(this,n)[n].setAttribute("data-state",e),_classPrivateFieldLooseBase(this,n)[n].querySelector("p").innerText=t,s?_classPrivateFieldLooseBase(this,n)[n].setAttribute("disabled","true"):_classPrivateFieldLooseBase(this,n)[n].removeAttribute("disabled")}handleProgress(e){const t=_classPrivateFieldLooseBase(this,n)[n].querySelector("p");t&&(_classPrivateFieldLooseBase(this,n)[n].querySelector(".checkbox").style.setProperty("--progress",`${e.detail.progress}%`),t.innerText=`Verifying... ${e.detail.progress}%`),this.executeAttributeCode("onprogress",e)}handleSolve(e){this.updateUI("done","You're a human",!0),this.executeAttributeCode("onsolve",e)}handleError(e){this.updateUI("error","Error. Try again."),this.executeAttributeCode("onerror",e)}handleReset(e){this.updateUI("","I'm a human"),this.executeAttributeCode("onreset",e)}executeAttributeCode(e,t){const s=this.getAttribute(e);if(!s)return;new Function("event",s).call(this,t)}error(e){void 0===e&&(e="Unknown error"),console.error("[Cap] Error:",e),this.dispatchEvent("error",{isCap:!0,message:e})}dispatchEvent(e,t){void 0===t&&(t={});const s=new CustomEvent(e,{bubbles:!0,composed:!0,detail:t});super.dispatchEvent(s)}reset(){_classPrivateFieldLooseBase(this,a)[a]&&(clearTimeout(_classPrivateFieldLooseBase(this,a)[a]),_classPrivateFieldLooseBase(this,a)[a]=null),this.dispatchEvent("reset"),_classPrivateFieldLooseBase(this,r)[r]=null,this.querySelector("input[name='cap-token']")&&(this.querySelector("input[name='cap-token']").value="")}get token(){return _classPrivateFieldLooseBase(this,r)[r]}disconnectedCallback(){this.removeEventListener("progress",this.boundHandleProgress),this.removeEventListener("solve",this.boundHandleSolve),this.removeEventListener("error",this.boundHandleError),this.removeEventListener("reset",this.boundHandleReset),_classPrivateFieldLooseBase(this,d)[d].forEach(((e,t)=>{this.removeEventListener(t.slice(2),e)})),_classPrivateFieldLooseBase(this,d)[d].clear(),_classPrivateFieldLooseBase(this,o)[o]&&(_classPrivateFieldLooseBase(this,o)[o].innerHTML=""),this.reset(),this.cleanup()}cleanup(){_classPrivateFieldLooseBase(this,a)[a]&&(clearTimeout(_classPrivateFieldLooseBase(this,a)[a]),_classPrivateFieldLooseBase(this,a)[a]=null),_classPrivateFieldLooseBase(this,s)[s]&&(URL.revokeObjectURL(_classPrivateFieldLooseBase(this,s)[s]),_classPrivateFieldLooseBase(this,s)[s]="")}}class p{constructor(e,t){void 0===e&&(e={});let s=t||document.createElement("cap-widget");if(Object.entries(e).forEach((e=>{let[t,a]=e;s.setAttribute(t,a)})),!e.apiEndpoint)throw s.remove(),new Error("Missing API endpoint");console.log(e),s.setAttribute("data-cap-api-endpoint",e.apiEndpoint),this.widget=s,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:()=>s.getToken(),configurable:!0,enumerable:!0}),t||(s.style.display="none",document.documentElement.appendChild(s))}}const v=new CSSStyleSheet;v.replaceSync('html{--cap-font:system,-apple-system,"BlinkMacSystemFont",".SFNSText-Regular","San Francisco","Roboto","Segoe UI","Helvetica Neue","Lucida Grande","Ubuntu","arial",sans-serif;--cap-color:#212121;--cap-background:#fdfdfd;--cap-border-color:#dddddd8f;--cap-border-radius:14px;--cap-checkbox-border:1px solid #aaaaaad1;--cap-checkbox-border-radius:6px;--cap-checkbox-background:#fafafa91;--cap-widget-width:240px;--cap-widget-padding:14px;--cap-checkbox-size:24px;--cap-checkbox-margin:2px;--cap-transition-duration:0.2s;--cap-gap:15px;--cap-opacity-hover:0.8;--cap-hover-filter:brightness(97%);--cap-active-scale:0.98;--cap-credits-font-size:12px;--cap-spinner-color:black;--cap-spinner-background-color:#eee;--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/svg%3E");--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");--cap-spinner-thickness:5px;}'),document.adoptedStyleSheets.push(v);const u=function(){let e;self.onmessage=async t=>{let{data:{salt:s,target:a}}=t,i=0;const r=5e4;let o=0;const n=new TextEncoder;if("object"!=typeof WebAssembly||"function"!=typeof WebAssembly.instantiate){console.log("[cap] WASM not enabled, falling back to crypto.subtle\nThis is significanty slower than the WASM implementation");const e=new Uint8Array(a.length/2);for(let t=0;t