altcha
Version:
Privacy-first CAPTCHA widget, compliant with global regulations (GDPR/HIPAA/CCPA/LGDP/DPDPA/PIPL) and WCAG accessible. No tracking, self-verifying.
2 lines (1 loc) • 2.85 kB
JavaScript
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["[name]"]={}))})(this,function(e){"use strict";var N=Object.defineProperty;var v=e=>{throw TypeError(e)};var V=(e,t,i)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var p=(e,t,i)=>V(e,typeof t!="symbol"?t+"":t,i),x=(e,t,i)=>t.has(e)||v("Cannot "+i);var y=(e,t,i)=>(x(e,t,"read from private field"),i?i.call(e):t.get(e)),b=(e,t,i)=>t.has(e)?v("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i);var R=(e,t,i)=>(x(e,t,"access private method"),i);var u,c,I,P;class t{constructor(l){this.context=l}static register(l){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(l)||globalThis.altchaPlugins.push(l)}destroy(){}onErrorChange(l){}onStateChange(l){}}p(t,"pluginName");var i=(s=>(s.CODE="code",s.ERROR="error",s.VERIFIED="verified",s.VERIFYING="verifying",s.UNVERIFIED="unverified",s.EXPIRED="expired",s))(i||{});class m extends t{constructor(n){var o,r;super(n);b(this,c);p(this,"elButton");b(this,u,R(this,c,I).bind(this));const a=n.el;this.elButton=((o=a.parentElement)==null?void 0:o.querySelector("[data-clarify-button]"))||((r=a.parentElement)==null?void 0:r.querySelector("button, a")),this.elButton&&this.elButton.addEventListener("click",y(this,u))}destroy(){this.elButton&&this.elButton.removeEventListener("click",y(this,u))}async clarify(){const{el:n,getConfiguration:a,getFloatingAnchor:o,setFloatingAnchor:r,reset:g,solve:T,setState:E}=this.context,{delay:C,floating:F,maxnumber:O,obfuscated:B}=a();if(this.elButton&&!o()&&r(this.elButton),!B){E(i.ERROR);return}g(i.VERIFYING),await new Promise(d=>setTimeout(d,C||0));const[k,D]=B.split("?");let h=new URLSearchParams(D||"").get("key")||void 0;if(h){const d=h.match(/^\(prompt:?(.*)\)$/);d&&(h=prompt(d[1]||"Enter Key:")||void 0)}const{solution:f}=await T({obfuscated:k,key:h,maxnumber:O});f&&"clearText"in f?(R(this,c,P).call(this,f.clearText),E(i.VERIFIED),this.context.dispatch("cleartext",f.clearText),F&&n&&(n.style.display="none")):E(i.ERROR,"Unable to decrypt data.")}}u=new WeakMap,c=new WeakSet,I=function(n){n.preventDefault();const{auto:a}=this.context.getConfiguration();a==="off"||this.clarify()},P=function(n){var r;const a=n.match(/^(mailto|tel|sms|https?):/);let o;if(a){const[g]=n.slice(n.indexOf(":")+1).replace(/^\/\//,"").split("?");o=document.createElement("a"),o.href=n,o.innerHTML=g}else o=document.createTextNode(n);this.elButton&&o&&(this.elButton.after(o),(r=this.elButton.parentElement)==null||r.removeChild(this.elButton))},p(m,"pluginName","obfuscation"),t.register(m),e.PluginObfuscation=m,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});