altcha 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/altcha.d.ts +27 -1
- package/dist/altcha.js +1 -1
- package/dist/altcha.umd.cjs +1 -1
- package/dist_external/altcha.d.ts +27 -1
- package/dist_external/altcha.js +1 -1
- package/dist_external/altcha.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/altcha.d.ts
CHANGED
|
@@ -106,4 +106,30 @@ declare global {
|
|
|
106
106
|
style?: AltchaWidgetCSSProperties;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare module "react" {
|
|
112
|
+
namespace JSX {
|
|
113
|
+
interface IntrinsicElements {
|
|
114
|
+
'altcha-widget': AltchaWidgetReact;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface AltchaWidgetCSSProperties extends React.CSSProperties {
|
|
118
|
+
'--altcha-border-width'?: string;
|
|
119
|
+
'--altcha-border-radius'?: string;
|
|
120
|
+
'--altcha-color-base'?: string;
|
|
121
|
+
'--altcha-color-border'?: string;
|
|
122
|
+
'--altcha-color-text'?: string;
|
|
123
|
+
'--altcha-color-border-focus'?: string;
|
|
124
|
+
'--altcha-color-error-text'?: string;
|
|
125
|
+
'--altcha-color-footer-bg'?: string;
|
|
126
|
+
'--altcha-max-width'?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface AltchaWidgetReact extends AltchaWidget extends React.HTMLAttributes<HTMLElement> {
|
|
130
|
+
children?: React.ReactNode;
|
|
131
|
+
ref?: React.RefObject<HTMLElement | null>;
|
|
132
|
+
style?: AltchaWidgetCSSProperties;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/dist/altcha.js
CHANGED
|
@@ -1926,7 +1926,7 @@ function ea(e, t) {
|
|
|
1926
1926
|
Un(), w && (w.removeEventListener("submit", vr), w.removeEventListener("reset", gr), w.removeEventListener("focusin", hr), w = null), fe && (clearTimeout(fe), fe = null), document.removeEventListener("click", cr), document.removeEventListener("scroll", dr), window.removeEventListener("resize", mr);
|
|
1927
1927
|
}), On(() => {
|
|
1928
1928
|
var n;
|
|
1929
|
-
S("mounted", "1.1.
|
|
1929
|
+
S("mounted", "1.1.1"), S("workers", ue()), Jn(), S("plugins", pe.length ? pe.map((s) => s.constructor.pluginName).join(", ") : "none"), I() && S("using test mode"), f() && bt(f()), r() !== void 0 && S("auto", r()), c() !== void 0 && yr(c()), w = (n = h(U)) == null ? void 0 : n.closest("form"), w && (w.addEventListener("submit", vr, { capture: !0 }), w.addEventListener("reset", gr), r() === "onfocus" && w.addEventListener("focusin", hr)), r() === "onload" && (D() ? nt() : we()), h(Pt) && (m() || p()) && S("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."), requestAnimationFrame(() => {
|
|
1930
1930
|
tt("load");
|
|
1931
1931
|
});
|
|
1932
1932
|
});
|
package/dist/altcha.umd.cjs
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
100% {
|
|
6
6
|
transform: rotate(360deg);
|
|
7
7
|
}
|
|
8
|
-
}`};function vn(e,t){var Zn,Wn;Jr(t,!0),el(e,Nl);let r=N(t,"auto",7,void 0),l=N(t,"blockspam",7,void 0),i=N(t,"challengeurl",7,void 0),a=N(t,"challengejson",7,void 0),o=N(t,"customfetch",7,void 0),d=N(t,"debug",7,!1),u=N(t,"delay",7,0),f=N(t,"expire",7,void 0),c=N(t,"floating",7,void 0),v=N(t,"floatinganchor",7,void 0),g=N(t,"floatingoffset",7,void 0),m=N(t,"hidefooter",7,!1),p=N(t,"hidelogo",7,!1),T=N(t,"name",7,"altcha"),Y=N(t,"maxnumber",7,1e6),ne=N(t,"mockerror",7,!1),F=N(t,"obfuscated",7,void 0),M=N(t,"plugins",7,void 0),pe=N(t,"refetchonexpire",7,!0),U=N(t,"spamfilter",7,!1),Se=N(t,"strings",7,void 0),S=N(t,"test",7,!1),j=N(t,"verifyurl",7,void 0),_e=N(t,"workers",23,()=>Math.min(16,navigator.hardwareConcurrency||8)),vt=N(t,"workerurl",7,void 0);const gn=["SHA-256","SHA-384","SHA-512"],_n="Visit Altcha.org",mn="https://altcha.org/",gt=(n,s)=>{t.$$host.dispatchEvent(new CustomEvent(n,{detail:s}))},bn=(Wn=(Zn=document.documentElement.lang)==null?void 0:Zn.split("-"))==null?void 0:Wn[0],rr=st(()=>{var n;return i()&&new URL(i(),location.origin).host.endsWith(".altcha.org")&&!!((n=i())!=null&&n.includes("apiKey=ckey_"))}),nr=st(()=>a()?Sn(a()):void 0),yn=st(()=>Se()?Sn(Se()):{}),ie=st(()=>{var n;return{ariaLinkLabel:_n,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${mn}" target="_blank" aria-label="${((n=h(yn))==null?void 0:n.ariaLinkLabel)||_n}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...h(yn)}});let Qe=Xe(!1),L=Xe(oe(w.UNVERIFIED)),B=Xe(void 0),_t=Xe(null),et=null,E=null,tt=Xe(null),me=null,Ne=[],Ge=Xe(null);Mt(()=>{Dl(h(tt))}),Mt(()=>{Yl(h(L))}),ll(()=>{Ll(),E&&(E.removeEventListener("submit",Cn),E.removeEventListener("reset",Rn),E.removeEventListener("focusin",kn),E=null),me&&(clearTimeout(me),me=null),document.removeEventListener("click",En),document.removeEventListener("scroll",xn),window.removeEventListener("resize",$n)}),fn(()=>{var n;A("mounted","1.1.
|
|
8
|
+
}`};function vn(e,t){var Zn,Wn;Jr(t,!0),el(e,Nl);let r=N(t,"auto",7,void 0),l=N(t,"blockspam",7,void 0),i=N(t,"challengeurl",7,void 0),a=N(t,"challengejson",7,void 0),o=N(t,"customfetch",7,void 0),d=N(t,"debug",7,!1),u=N(t,"delay",7,0),f=N(t,"expire",7,void 0),c=N(t,"floating",7,void 0),v=N(t,"floatinganchor",7,void 0),g=N(t,"floatingoffset",7,void 0),m=N(t,"hidefooter",7,!1),p=N(t,"hidelogo",7,!1),T=N(t,"name",7,"altcha"),Y=N(t,"maxnumber",7,1e6),ne=N(t,"mockerror",7,!1),F=N(t,"obfuscated",7,void 0),M=N(t,"plugins",7,void 0),pe=N(t,"refetchonexpire",7,!0),U=N(t,"spamfilter",7,!1),Se=N(t,"strings",7,void 0),S=N(t,"test",7,!1),j=N(t,"verifyurl",7,void 0),_e=N(t,"workers",23,()=>Math.min(16,navigator.hardwareConcurrency||8)),vt=N(t,"workerurl",7,void 0);const gn=["SHA-256","SHA-384","SHA-512"],_n="Visit Altcha.org",mn="https://altcha.org/",gt=(n,s)=>{t.$$host.dispatchEvent(new CustomEvent(n,{detail:s}))},bn=(Wn=(Zn=document.documentElement.lang)==null?void 0:Zn.split("-"))==null?void 0:Wn[0],rr=st(()=>{var n;return i()&&new URL(i(),location.origin).host.endsWith(".altcha.org")&&!!((n=i())!=null&&n.includes("apiKey=ckey_"))}),nr=st(()=>a()?Sn(a()):void 0),yn=st(()=>Se()?Sn(Se()):{}),ie=st(()=>{var n;return{ariaLinkLabel:_n,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${mn}" target="_blank" aria-label="${((n=h(yn))==null?void 0:n.ariaLinkLabel)||_n}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...h(yn)}});let Qe=Xe(!1),L=Xe(oe(w.UNVERIFIED)),B=Xe(void 0),_t=Xe(null),et=null,E=null,tt=Xe(null),me=null,Ne=[],Ge=Xe(null);Mt(()=>{Dl(h(tt))}),Mt(()=>{Yl(h(L))}),ll(()=>{Ll(),E&&(E.removeEventListener("submit",Cn),E.removeEventListener("reset",Rn),E.removeEventListener("focusin",kn),E=null),me&&(clearTimeout(me),me=null),document.removeEventListener("click",En),document.removeEventListener("scroll",xn),window.removeEventListener("resize",$n)}),fn(()=>{var n;A("mounted","1.1.1"),A("workers",_e()),zl(),A("plugins",Ne.length?Ne.map(s=>s.constructor.pluginName).join(", "):"none"),S()&&A("using test mode"),f()&&Gt(f()),r()!==void 0&&A("auto",r()),c()!==void 0&&Nn(c()),E=(n=h(B))==null?void 0:n.closest("form"),E&&(E.addEventListener("submit",Cn,{capture:!0}),E.addEventListener("reset",Rn),r()==="onfocus"&&E.addEventListener("focusin",kn)),r()==="onload"&&(F()?mt():Le()),h(rr)&&(m()||p())&&A("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."),requestAnimationFrame(()=>{gt("load")})});function pn(n,s){return btoa(JSON.stringify({algorithm:n.algorithm,challenge:n.challenge,number:s.number,salt:n.salt,signature:n.signature,test:S()?!0:void 0,took:s.took}))}function Ll(){for(const n of Ne)n.destroy()}function wn(){i()&&pe()&&h(L)===w.VERIFIED?Le():bt(w.EXPIRED,h(ie).expired)}async function Al(){var n;if(ne())throw A("mocking error"),new Error("Mocked error.");if(h(nr))return A("using provided json data"),h(nr);if(S())return A("generating test challenge",{test:S()}),hl(typeof S()!="boolean"?+S():void 0);{if(!i()&&E){const P=E.getAttribute("action");P!=null&&P.includes("/form/")&&i(P+"/altcha")}if(!i())throw new Error("Attribute challengeurl not set.");A("fetching challenge from",i());let s=null,_=null;if(o())if(A("using customfetch"),typeof o()=="string"){if(s=globalThis[o()]||null,!s)throw new Error(`Custom fetch function not found: ${o()}`)}else s=o();const x={headers:U()!==!1?{"x-altcha-spam-filter":"1"}:{}};if(s){if(_=await s(i(),x),!_||!(_ instanceof Response))throw new Error("Custom fetch function did not return a response.")}else _=await fetch(i(),x);if(_.status!==200)throw new Error(`Server responded with ${_.status}.`);const G=_.headers.get("Expires"),$=_.headers.get("X-Altcha-Config"),b=await _.json(),O=new URLSearchParams((n=b.salt.split("?"))==null?void 0:n[1]),we=O.get("expires")||O.get("expire");if(we){const P=new Date(+we*1e3),fe=isNaN(P.getTime())?0:P.getTime()-Date.now();fe>0&&Gt(fe)}if($)try{const P=JSON.parse($);P&&typeof P=="object"&&(P.verifyurl&&(P.verifyurl=new URL(P.verifyurl,new URL(i())).toString()),Tn(P))}catch(P){A("unable to configure from X-Altcha-Config",P)}if(!f()&&(G!=null&&G.length)){const P=Date.parse(G);if(P){const fe=P-Date.now();fe>0&&Gt(fe)}}return b}}function Tl(n){var _;const s=E==null?void 0:E.querySelector(typeof n=="string"?`input[name="${n}"]`:'input[type="email"]:not([data-no-spamfilter])');return((_=s==null?void 0:s.value)==null?void 0:_.slice(s.value.indexOf("@")))||void 0}function Pl(){return U()==="ipAddress"?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:typeof U()=="object"?U():{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0}}function Vl(n){return[...(E==null?void 0:E.querySelectorAll(n!=null&&n.length?n.map(_=>`input[name="${_}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((_,x)=>{const G=x.name,$=x.value;return G&&$&&(_[G]=/\n/.test($)?$.replace(new RegExp("(?<!\\r)\\n","g"),`\r
|
|
9
9
|
`):$),_},{})}function zl(){const n=M()!==void 0?M().split(","):void 0;for(const s of globalThis.altchaPlugins)(!n||n.includes(s.pluginName))&&Ne.push(new s({el:h(B),clarify:mt,dispatch:gt,getConfiguration:Pn,getFloatingAnchor:Vn,getState:zn,log:A,reset:bt,solve:An,setState:De,setFloatingAnchor:Gn,verify:Le}))}function A(...n){(d()||n.some(s=>s instanceof Error))&&console[n[0]instanceof Error?"error":"log"]("ALTCHA",`[name=${T()}]`,...n)}function Gl(){[w.UNVERIFIED,w.ERROR,w.EXPIRED].includes(h(L))?U()!==!1&&(E==null?void 0:E.reportValidity())===!1?V(Qe,!1):F()?mt():Le():V(Qe,!0)}function En(n){const s=n.target;c()&&s&&!h(B).contains(s)&&(h(L)===w.VERIFIED||r()==="off"&&h(L)===w.UNVERIFIED)&&(h(B).style.display="none")}function xn(){c()&&h(L)!==w.UNVERIFIED&&zt()}function Dl(n){for(const s of Ne)typeof s.onErrorChange=="function"&&s.onErrorChange(h(tt))}function kn(n){h(L)===w.UNVERIFIED&&Le()}function Cn(n){E&&r()==="onsubmit"?h(L)===w.UNVERIFIED?(n.preventDefault(),n.stopPropagation(),Le().then(()=>{E==null||E.requestSubmit()})):h(L)!==w.VERIFIED&&(n.preventDefault(),n.stopPropagation(),h(L)===w.VERIFYING&&In()):E&&c()&&r()==="off"&&h(L)===w.UNVERIFIED&&(n.preventDefault(),n.stopPropagation(),h(B).style.display="block",zt())}function Rn(){bt()}function In(){h(L)===w.VERIFYING&&h(ie).waitAlert&&alert(h(ie).waitAlert)}function Yl(n){for(const s of Ne)typeof s.onStateChange=="function"&&s.onStateChange(h(L));c()&&h(L)!==w.UNVERIFIED&&requestAnimationFrame(()=>{zt()}),V(Qe,h(L)===w.VERIFIED)}function $n(){c()&&zt()}function Sn(n){return JSON.parse(n)}function zt(n=20){if(h(B))if(et||(et=(v()?document.querySelector(v()):E==null?void 0:E.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||E),et){const s=parseInt(g(),10)||12,_=et.getBoundingClientRect(),x=h(B).getBoundingClientRect(),G=document.documentElement.clientHeight,$=document.documentElement.clientWidth,b=c()==="auto"?_.bottom+x.height+s+n>G:c()==="top",O=Math.max(n,Math.min($-n-x.width,_.left+_.width/2-x.width/2));if(b?h(B).style.top=`${_.top-(x.height+s)}px`:h(B).style.top=`${_.bottom+s}px`,h(B).style.left=`${O}px`,h(B).setAttribute("data-floating",b?"top":"bottom"),h(_t)){const we=h(_t).getBoundingClientRect();h(_t).style.left=_.left-O+_.width/2-we.width/2+"px"}}else A("unable to find floating anchor element")}async function Fl(n){if(!j())throw new Error("Attribute verifyurl not set.");A("requesting server verification from",j());const s={payload:n};if(U()!==!1){const{blockedCountries:G,classifier:$,disableRules:b,email:O,expectedLanguages:we,expectedCountries:P,fields:fe,ipAddress:pt,text:Ql,timeZone:Un}=Pl();s.blockedCountries=G,s.classifier=$,s.disableRules=b,s.email=O===!1?void 0:Tl(O),s.expectedCountries=P,s.expectedLanguages=we||(bn?[bn]:void 0),s.fields=fe===!1?void 0:Vl(fe),s.ipAddress=pt===!1?void 0:pt||"auto",s.text=Ql,s.timeZone=Un===!1?void 0:Un||gl()}const _=await fetch(j(),{body:JSON.stringify(s),headers:{"content-type":"application/json"},method:"POST"});if(_.status!==200)throw new Error(`Server responded with ${_.status}.`);const x=await _.json();if(x!=null&&x.payload&&V(Ge,oe(x.payload)),gt("serververification",x),l()&&x.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function Gt(n){A("expire",n),me&&(clearTimeout(me),me=null),n<1?wn():me=setTimeout(wn,n)}function Nn(n){A("floating",n),c()!==n&&(h(B).style.left="",h(B).style.top=""),c(n===!0||n===""?"auto":n===!1||n==="false"?void 0:c()),c()?(r()||r("onsubmit"),document.addEventListener("scroll",xn),document.addEventListener("click",En),window.addEventListener("resize",$n)):r()==="onsubmit"&&r(void 0)}function Ln(n){if(!n.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(n.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!gn.includes(n.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${gn.join(", ")}`);if(!n.challenge||n.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!n.salt||n.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function An(n){let s=null;if("Worker"in window){try{s=await Ol(n,n.maxnumber)}catch(_){A(_)}if((s==null?void 0:s.number)!==void 0||"obfuscated"in n)return{data:n,solution:s}}if("obfuscated"in n){const _=await bl(n.obfuscated,n.key,n.maxnumber);return{data:n,solution:await _.promise}}return{data:n,solution:await vl(n.challenge,n.salt,n.algorithm,n.maxnumber||Y()).promise}}async function Ol(n,s=typeof S()=="number"?S():Y(),_=Math.ceil(_e())){const x=[];_=Math.min(16,Math.max(1,_));for(let b=0;b<_;b++)x.push(altchaCreateWorker(vt()));const G=Math.ceil(s/_),$=await Promise.all(x.map((b,O)=>{const we=O*G;return new Promise(P=>{b.addEventListener("message",fe=>{if(fe.data)for(const pt of x)pt!==b&&pt.postMessage({type:"abort"});P(fe.data)}),b.postMessage({payload:n,max:we+G,start:we,type:"work"})})}));for(const b of x)b.terminate();return $.find(b=>!!b)||null}async function mt(){if(!F()){De(w.ERROR);return}const n=Ne.find(s=>s.constructor.pluginName==="obfuscation");if(!n||!("clarify"in n)){De(w.ERROR),A("Plugin `obfuscation` not found. Import `altcha/plugins/obfuscation` to load it.");return}if("clarify"in n&&typeof n.clarify=="function")return n.clarify()}function Tn(n){n.obfuscated!==void 0&&F(n.obfuscated),n.auto!==void 0&&(r(n.auto),r()==="onload"&&(F()?mt():Le())),n.blockspam!==void 0&&l(!!n.blockspam),n.customfetch!==void 0&&o(n.customfetch),n.floatinganchor!==void 0&&v(n.floatinganchor),n.delay!==void 0&&u(n.delay),n.floatingoffset!==void 0&&g(n.floatingoffset),n.floating!==void 0&&Nn(n.floating),n.expire!==void 0&&(Gt(n.expire),f(n.expire)),n.challenge&&(a(typeof n.challenge=="string"?n.challenge:JSON.stringify(n.challenge)),Ln(h(nr))),n.challengeurl!==void 0&&i(n.challengeurl),n.debug!==void 0&&d(!!n.debug),n.hidefooter!==void 0&&m(!!n.hidefooter),n.hidelogo!==void 0&&p(!!n.hidelogo),n.maxnumber!==void 0&&Y(+n.maxnumber),n.mockerror!==void 0&&ne(!!n.mockerror),n.name!==void 0&&T(n.name),n.refetchonexpire!==void 0&&pe(!!n.refetchonexpire),n.spamfilter!==void 0&&U(typeof n.spamfilter=="object"?n.spamfilter:!!n.spamfilter),n.strings&&Se(typeof n.strings=="string"?n.strings:JSON.stringify(n.strings)),n.test!==void 0&&S(typeof n.test=="number"?n.test:!!n.test),n.verifyurl!==void 0&&j(n.verifyurl),n.workers!==void 0&&_e(+n.workers),n.workerurl!==void 0&&vt(n.workerurl)}function Pn(){return{auto:r(),blockspam:l(),challengeurl:i(),debug:d(),delay:u(),expire:f(),floating:c(),floatinganchor:v(),floatingoffset:g(),hidefooter:m(),hidelogo:p(),name:T(),maxnumber:Y(),mockerror:ne(),obfuscated:F(),refetchonexpire:pe(),spamfilter:U(),strings:h(ie),test:S(),verifyurl:j(),workers:_e(),workerurl:vt()}}function Vn(){return et}function Xl(n){return Ne.find(s=>s.constructor.pluginName===n)}function zn(){return h(L)}function bt(n=w.UNVERIFIED,s=null){me&&(clearTimeout(me),me=null),V(Qe,!1),V(Ge,null),De(n,s)}function Gn(n){et=n}function De(n,s=null){V(L,oe(n)),V(tt,oe(s)),gt("statechange",{payload:h(Ge),state:h(L)})}async function Le(){return bt(w.VERIFYING),await new Promise(n=>setTimeout(n,u()||0)),Al().then(n=>(Ln(n),A("challenge",n),An(n))).then(({data:n,solution:s})=>{if(A("solution",s),"challenge"in n&&s&&!("clearText"in s))if((s==null?void 0:s.number)!==void 0){if(j())return Fl(pn(n,s));V(Ge,oe(pn(n,s))),A("payload",h(Ge))}else throw A("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{De(w.VERIFIED),A("verified"),Xi().then(()=>{gt("verified",{payload:h(Ge)})})}).catch(n=>{A(n),De(w.ERROR,n.message)})}var Dn=Sl(),Yn=Wt(Dn);Qi(Yn,t,"default",{});var yt=be(Yn,2),ir=Q(yt),Fn=Q(ir);{var Zl=n=>{var s=yl();te(n,s)};$e(Fn,n=>{h(L)===w.VERIFYING&&n(Zl)})}var Dt=be(Fn,2),rt=Q(Dt);an(rt),rt.__change=Gl,q(Dt);var lr=be(Dt,2),Wl=Q(lr);{var Ul=n=>{var s=pl(),_=Wt(s),x=Q(_);qe(x,()=>h(ie).verified),q(_);var G=be(_,2);an(G),Me(()=>{ue(G,"name",T()),tl(G,h(Ge))}),te(n,s)},Ml=n=>{var s=Bi(),_=Wt(s);{var x=$=>{var b=wl(),O=Q(b);qe(O,()=>h(ie).verifying),q(b),te($,b)},G=$=>{var b=El(),O=Q(b);qe(O,()=>h(ie).label),q(b),Me(()=>ue(b,"for",`${T()??""}_checkbox`)),te($,b)};$e(_,$=>{h(L)===w.VERIFYING?$(x):$(G,!1)},!0)}te(n,s)};$e(Wl,n=>{h(L)===w.VERIFIED?n(Ul):n(Ml,!1)})}q(lr);var jl=be(lr,2);{var Bl=n=>{var s=xl(),_=Q(s);ue(_,"href",mn),q(s),Me(()=>ue(_,"aria-label",h(ie).ariaLinkLabel)),te(n,s)};$e(jl,n=>{(p()!==!0||h(rr))&&n(Bl)})}q(ir);var On=be(ir,2);{var Hl=n=>{var s=Rl(),_=be(Q(s),2);{var x=$=>{var b=kl(),O=Q(b);qe(O,()=>h(ie).expired),q(b),Me(()=>ue(b,"title",h(tt))),te($,b)},G=$=>{var b=Cl(),O=Q(b);qe(O,()=>h(ie).error),q(b),Me(()=>ue(b,"title",h(tt))),te($,b)};$e(_,$=>{h(L)===w.EXPIRED?$(x):$(G,!1)})}q(s),te(n,s)};$e(On,n=>{(h(tt)||h(L)===w.EXPIRED)&&n(Hl)})}var Xn=be(On,2);{var Jl=n=>{var s=Il(),_=Q(s),x=Q(_);qe(x,()=>h(ie).footer),q(_),q(s),te(n,s)};$e(Xn,n=>{h(ie).footer&&(m()!==!0||h(rr))&&n(Jl)})}var Kl=be(Xn,2);{var ql=n=>{var s=$l();un(s,_=>V(_t,_),()=>h(_t)),te(n,s)};$e(Kl,n=>{c()&&n(ql)})}return q(yt),un(yt,n=>V(B,n),()=>h(B)),Me(()=>{ue(yt,"data-state",h(L)),ue(yt,"data-floating",c()),nl(Dt,"altcha-hidden",h(L)===w.VERIFYING),ue(rt,"id",`${T()??""}_checkbox`),rt.required=r()!=="onsubmit"&&(!c()||r()!=="off")}),Mi("invalid",rt,In),il(rt,()=>h(Qe),n=>V(Qe,n)),te(e,Dn),Kr({clarify:mt,configure:Tn,getConfiguration:Pn,getFloatingAnchor:Vn,getPlugin:Xl,getState:zn,reset:bt,setFloatingAnchor:Gn,setState:De,verify:Le,get auto(){return r()},set auto(n=void 0){r(n),C()},get blockspam(){return l()},set blockspam(n=void 0){l(n),C()},get challengeurl(){return i()},set challengeurl(n=void 0){i(n),C()},get challengejson(){return a()},set challengejson(n=void 0){a(n),C()},get customfetch(){return o()},set customfetch(n=void 0){o(n),C()},get debug(){return d()},set debug(n=!1){d(n),C()},get delay(){return u()},set delay(n=0){u(n),C()},get expire(){return f()},set expire(n=void 0){f(n),C()},get floating(){return c()},set floating(n=void 0){c(n),C()},get floatinganchor(){return v()},set floatinganchor(n=void 0){v(n),C()},get floatingoffset(){return g()},set floatingoffset(n=void 0){g(n),C()},get hidefooter(){return m()},set hidefooter(n=!1){m(n),C()},get hidelogo(){return p()},set hidelogo(n=!1){p(n),C()},get name(){return T()},set name(n="altcha"){T(n),C()},get maxnumber(){return Y()},set maxnumber(n=1e6){Y(n),C()},get mockerror(){return ne()},set mockerror(n=!1){ne(n),C()},get obfuscated(){return F()},set obfuscated(n=void 0){F(n),C()},get plugins(){return M()},set plugins(n=void 0){M(n),C()},get refetchonexpire(){return pe()},set refetchonexpire(n=!0){pe(n),C()},get spamfilter(){return U()},set spamfilter(n=!1){U(n),C()},get strings(){return Se()},set strings(n=void 0){Se(n),C()},get test(){return S()},set test(n=!1){S(n),C()},get verifyurl(){return j()},set verifyurl(n=void 0){j(n),C()},get workers(){return _e()},set workers(n=Math.min(16,navigator.hardwareConcurrency||8)){_e(n),C()},get workerurl(){return vt()},set workerurl(n=void 0){vt(n),C()}})}ji(["change"]),customElements.define("altcha-widget",cl(vn,{blockspam:{type:"Boolean"},debug:{type:"Boolean"},delay:{type:"Number"},expire:{type:"Number"},floatingoffset:{type:"Number"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},maxnumber:{type:"Number"},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},test:{type:"Boolean"},workers:{type:"Number"},auto:{},challengeurl:{},challengejson:{},customfetch:{},floating:{},floatinganchor:{},name:{},obfuscated:{},plugins:{},spamfilter:{},strings:{},verifyurl:{},workerurl:{}},["default"],["clarify","configure","getConfiguration","getFloatingAnchor","getPlugin","getState","reset","setFloatingAnchor","setState","verify"],!1)),globalThis.altchaCreateWorker=e=>e?new Worker(new URL(e)):new Bn,globalThis.altchaPlugins=globalThis.altchaPlugins||[],k.Altcha=vn,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -106,4 +106,30 @@ declare global {
|
|
|
106
106
|
style?: AltchaWidgetCSSProperties;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
declare module "react" {
|
|
112
|
+
namespace JSX {
|
|
113
|
+
interface IntrinsicElements {
|
|
114
|
+
'altcha-widget': AltchaWidgetReact;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface AltchaWidgetCSSProperties extends React.CSSProperties {
|
|
118
|
+
'--altcha-border-width'?: string;
|
|
119
|
+
'--altcha-border-radius'?: string;
|
|
120
|
+
'--altcha-color-base'?: string;
|
|
121
|
+
'--altcha-color-border'?: string;
|
|
122
|
+
'--altcha-color-text'?: string;
|
|
123
|
+
'--altcha-color-border-focus'?: string;
|
|
124
|
+
'--altcha-color-error-text'?: string;
|
|
125
|
+
'--altcha-color-footer-bg'?: string;
|
|
126
|
+
'--altcha-max-width'?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface AltchaWidgetReact extends AltchaWidget extends React.HTMLAttributes<HTMLElement> {
|
|
130
|
+
children?: React.ReactNode;
|
|
131
|
+
ref?: React.RefObject<HTMLElement | null>;
|
|
132
|
+
style?: AltchaWidgetCSSProperties;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/dist_external/altcha.js
CHANGED
|
@@ -1904,7 +1904,7 @@ function Jl(e, t) {
|
|
|
1904
1904
|
jn(), b && (b.removeEventListener("submit", hr), b.removeEventListener("reset", _r), b.removeEventListener("focusin", vr), b = null), fe && (clearTimeout(fe), fe = null), document.removeEventListener("click", cr), document.removeEventListener("scroll", dr), window.removeEventListener("resize", mr);
|
|
1905
1905
|
}), Mn(() => {
|
|
1906
1906
|
var n;
|
|
1907
|
-
I("mounted", "1.1.
|
|
1907
|
+
I("mounted", "1.1.1"), I("workers", ue()), Zn(), I("plugins", we.length ? we.map((s) => s.constructor.pluginName).join(", ") : "none"), A() && I("using test mode"), f() && pt(f()), r() !== void 0 && I("auto", r()), c() !== void 0 && yr(c()), b = (n = v(H)) == null ? void 0 : n.closest("form"), b && (b.addEventListener("submit", hr, { capture: !0 }), b.addEventListener("reset", _r), r() === "onfocus" && b.addEventListener("focusin", vr)), r() === "onload" && (F() ? nt() : be()), v(Pt) && (m() || w()) && I("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."), requestAnimationFrame(() => {
|
|
1908
1908
|
tt("load");
|
|
1909
1909
|
});
|
|
1910
1910
|
});
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
100% {
|
|
6
6
|
transform: rotate(360deg);
|
|
7
7
|
}
|
|
8
|
-
}`};function vn(e,t){var jn,Bn;Jr(t,!0),Ki(e,Ao);let r=S(t,"auto",7,void 0),o=S(t,"blockspam",7,void 0),i=S(t,"challengeurl",7,void 0),l=S(t,"challengejson",7,void 0),a=S(t,"customfetch",7,void 0),d=S(t,"debug",7,!1),u=S(t,"delay",7,0),f=S(t,"expire",7,void 0),c=S(t,"floating",7,void 0),v=S(t,"floatinganchor",7,void 0),_=S(t,"floatingoffset",7,void 0),m=S(t,"hidefooter",7,!1),w=S(t,"hidelogo",7,!1),L=S(t,"name",7,"altcha"),M=S(t,"maxnumber",7,1e6),ne=S(t,"mockerror",7,!1),q=S(t,"obfuscated",7,void 0),Y=S(t,"plugins",7,void 0),we=S(t,"refetchonexpire",7,!0),H=S(t,"spamfilter",7,!1),Ie=S(t,"strings",7,void 0),I=S(t,"test",7,!1),W=S(t,"verifyurl",7,void 0),ge=S(t,"workers",23,()=>Math.min(16,navigator.hardwareConcurrency||8)),ht=S(t,"workerurl",7,void 0);const _n=["SHA-256","SHA-384","SHA-512"],gn="Visit Altcha.org",mn="https://altcha.org/",vt=(n,s)=>{t.$$host.dispatchEvent(new CustomEvent(n,{detail:s}))},pn=(Bn=(jn=document.documentElement.lang)==null?void 0:jn.split("-"))==null?void 0:Bn[0],rr=at(()=>{var n;return i()&&new URL(i(),location.origin).host.endsWith(".altcha.org")&&!!((n=i())!=null&&n.includes("apiKey=ckey_"))}),nr=at(()=>l()?In(l()):void 0),yn=at(()=>Ie()?In(Ie()):{}),ie=at(()=>{var n;return{ariaLinkLabel:gn,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${mn}" target="_blank" aria-label="${((n=h(yn))==null?void 0:n.ariaLinkLabel)||gn}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...h(yn)}});let Qe=Ve(!1),T=Ve(ae(b.UNVERIFIED)),Z=Ve(void 0),_t=Ve(null),et=null,E=null,tt=Ve(null),me=null,Se=[],Oe=Ve(null);Yt(()=>{zo(h(tt))}),Yt(()=>{Oo(h(T))}),ro(()=>{Io(),E&&(E.removeEventListener("submit",kn),E.removeEventListener("reset",Cn),E.removeEventListener("focusin",$n),E=null),me&&(clearTimeout(me),me=null),document.removeEventListener("click",En),document.removeEventListener("scroll",xn),window.removeEventListener("resize",An)}),fn(()=>{var n;N("mounted","1.1.
|
|
8
|
+
}`};function vn(e,t){var jn,Bn;Jr(t,!0),Ki(e,Ao);let r=S(t,"auto",7,void 0),o=S(t,"blockspam",7,void 0),i=S(t,"challengeurl",7,void 0),l=S(t,"challengejson",7,void 0),a=S(t,"customfetch",7,void 0),d=S(t,"debug",7,!1),u=S(t,"delay",7,0),f=S(t,"expire",7,void 0),c=S(t,"floating",7,void 0),v=S(t,"floatinganchor",7,void 0),_=S(t,"floatingoffset",7,void 0),m=S(t,"hidefooter",7,!1),w=S(t,"hidelogo",7,!1),L=S(t,"name",7,"altcha"),M=S(t,"maxnumber",7,1e6),ne=S(t,"mockerror",7,!1),q=S(t,"obfuscated",7,void 0),Y=S(t,"plugins",7,void 0),we=S(t,"refetchonexpire",7,!0),H=S(t,"spamfilter",7,!1),Ie=S(t,"strings",7,void 0),I=S(t,"test",7,!1),W=S(t,"verifyurl",7,void 0),ge=S(t,"workers",23,()=>Math.min(16,navigator.hardwareConcurrency||8)),ht=S(t,"workerurl",7,void 0);const _n=["SHA-256","SHA-384","SHA-512"],gn="Visit Altcha.org",mn="https://altcha.org/",vt=(n,s)=>{t.$$host.dispatchEvent(new CustomEvent(n,{detail:s}))},pn=(Bn=(jn=document.documentElement.lang)==null?void 0:jn.split("-"))==null?void 0:Bn[0],rr=at(()=>{var n;return i()&&new URL(i(),location.origin).host.endsWith(".altcha.org")&&!!((n=i())!=null&&n.includes("apiKey=ckey_"))}),nr=at(()=>l()?In(l()):void 0),yn=at(()=>Ie()?In(Ie()):{}),ie=at(()=>{var n;return{ariaLinkLabel:gn,error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by <a href="${mn}" target="_blank" aria-label="${((n=h(yn))==null?void 0:n.ariaLinkLabel)||gn}">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...h(yn)}});let Qe=Ve(!1),T=Ve(ae(b.UNVERIFIED)),Z=Ve(void 0),_t=Ve(null),et=null,E=null,tt=Ve(null),me=null,Se=[],Oe=Ve(null);Yt(()=>{zo(h(tt))}),Yt(()=>{Oo(h(T))}),ro(()=>{Io(),E&&(E.removeEventListener("submit",kn),E.removeEventListener("reset",Cn),E.removeEventListener("focusin",$n),E=null),me&&(clearTimeout(me),me=null),document.removeEventListener("click",En),document.removeEventListener("scroll",xn),window.removeEventListener("resize",An)}),fn(()=>{var n;N("mounted","1.1.1"),N("workers",ge()),Do(),N("plugins",Se.length?Se.map(s=>s.constructor.pluginName).join(", "):"none"),I()&&N("using test mode"),f()&&Ot(f()),r()!==void 0&&N("auto",r()),c()!==void 0&&Sn(c()),E=(n=h(Z))==null?void 0:n.closest("form"),E&&(E.addEventListener("submit",kn,{capture:!0}),E.addEventListener("reset",Cn),r()==="onfocus"&&E.addEventListener("focusin",$n)),r()==="onload"&&(q()?gt():Te()),h(rr)&&(m()||w())&&N("Attributes hidefooter and hidelogo ignored because usage with free API Keys requires attribution."),requestAnimationFrame(()=>{vt("load")})});function wn(n,s){return btoa(JSON.stringify({algorithm:n.algorithm,challenge:n.challenge,number:s.number,salt:n.salt,signature:n.signature,test:I()?!0:void 0,took:s.took}))}function Io(){for(const n of Se)n.destroy()}function bn(){i()&&we()&&h(T)===b.VERIFIED?Te():mt(b.EXPIRED,h(ie).expired)}async function So(){var n;if(ne())throw N("mocking error"),new Error("Mocked error.");if(h(nr))return N("using provided json data"),h(nr);if(I())return N("generating test challenge",{test:I()}),fo(typeof I()!="boolean"?+I():void 0);{if(!i()&&E){const D=E.getAttribute("action");D!=null&&D.includes("/form/")&&i(D+"/altcha")}if(!i())throw new Error("Attribute challengeurl not set.");N("fetching challenge from",i());let s=null,g=null;if(a())if(N("using customfetch"),typeof a()=="string"){if(s=globalThis[a()]||null,!s)throw new Error(`Custom fetch function not found: ${a()}`)}else s=a();const x={headers:H()!==!1?{"x-altcha-spam-filter":"1"}:{}};if(s){if(g=await s(i(),x),!g||!(g instanceof Response))throw new Error("Custom fetch function did not return a response.")}else g=await fetch(i(),x);if(g.status!==200)throw new Error(`Server responded with ${g.status}.`);const O=g.headers.get("Expires"),A=g.headers.get("X-Altcha-Config"),p=await g.json(),U=new URLSearchParams((n=p.salt.split("?"))==null?void 0:n[1]),be=U.get("expires")||U.get("expire");if(be){const D=new Date(+be*1e3),fe=isNaN(D.getTime())?0:D.getTime()-Date.now();fe>0&&Ot(fe)}if(A)try{const D=JSON.parse(A);D&&typeof D=="object"&&(D.verifyurl&&(D.verifyurl=new URL(D.verifyurl,new URL(i())).toString()),Ln(D))}catch(D){N("unable to configure from X-Altcha-Config",D)}if(!f()&&(O!=null&&O.length)){const D=Date.parse(O);if(D){const fe=D-Date.now();fe>0&&Ot(fe)}}return p}}function To(n){var g;const s=E==null?void 0:E.querySelector(typeof n=="string"?`input[name="${n}"]`:'input[type="email"]:not([data-no-spamfilter])');return((g=s==null?void 0:s.value)==null?void 0:g.slice(s.value.indexOf("@")))||void 0}function No(){return H()==="ipAddress"?{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:!1,expectedCountries:void 0,expectedLanguages:void 0,fields:!1,ipAddress:void 0,text:void 0,timeZone:void 0}:typeof H()=="object"?H():{blockedCountries:void 0,classifier:void 0,disableRules:void 0,email:void 0,expectedCountries:void 0,expectedLanguages:void 0,fields:void 0,ipAddress:void 0,text:void 0,timeZone:void 0}}function Lo(n){return[...(E==null?void 0:E.querySelectorAll(n!=null&&n.length?n.map(g=>`input[name="${g}"]`).join(", "):'input[type="text"]:not([data-no-spamfilter]), textarea:not([data-no-spamfilter])'))||[]].reduce((g,x)=>{const O=x.name,A=x.value;return O&&A&&(g[O]=/\n/.test(A)?A.replace(new RegExp("(?<!\\r)\\n","g"),`\r
|
|
9
9
|
`):A),g},{})}function Do(){const n=Y()!==void 0?Y().split(","):void 0;for(const s of globalThis.altchaPlugins)(!n||n.includes(s.pluginName))&&Se.push(new s({el:h(Z),clarify:gt,dispatch:vt,getConfiguration:Dn,getFloatingAnchor:Pn,getState:zn,log:N,reset:mt,solve:Nn,setState:Fe,setFloatingAnchor:On,verify:Te}))}function N(...n){(d()||n.some(s=>s instanceof Error))&&console[n[0]instanceof Error?"error":"log"]("ALTCHA",`[name=${L()}]`,...n)}function Po(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(h(T))?H()!==!1&&(E==null?void 0:E.reportValidity())===!1?P(Qe,!1):q()?gt():Te():P(Qe,!0)}function En(n){const s=n.target;c()&&s&&!h(Z).contains(s)&&(h(T)===b.VERIFIED||r()==="off"&&h(T)===b.UNVERIFIED)&&(h(Z).style.display="none")}function xn(){c()&&h(T)!==b.UNVERIFIED&&zt()}function zo(n){for(const s of Se)typeof s.onErrorChange=="function"&&s.onErrorChange(h(tt))}function $n(n){h(T)===b.UNVERIFIED&&Te()}function kn(n){E&&r()==="onsubmit"?h(T)===b.UNVERIFIED?(n.preventDefault(),n.stopPropagation(),Te().then(()=>{E==null||E.requestSubmit()})):h(T)!==b.VERIFIED&&(n.preventDefault(),n.stopPropagation(),h(T)===b.VERIFYING&&Rn()):E&&c()&&r()==="off"&&h(T)===b.UNVERIFIED&&(n.preventDefault(),n.stopPropagation(),h(Z).style.display="block",zt())}function Cn(){mt()}function Rn(){h(T)===b.VERIFYING&&h(ie).waitAlert&&alert(h(ie).waitAlert)}function Oo(n){for(const s of Se)typeof s.onStateChange=="function"&&s.onStateChange(h(T));c()&&h(T)!==b.UNVERIFIED&&requestAnimationFrame(()=>{zt()}),P(Qe,h(T)===b.VERIFIED)}function An(){c()&&zt()}function In(n){return JSON.parse(n)}function zt(n=20){if(h(Z))if(et||(et=(v()?document.querySelector(v()):E==null?void 0:E.querySelector('input[type="submit"], button[type="submit"], button:not([type="button"]):not([type="reset"])'))||E),et){const s=parseInt(_(),10)||12,g=et.getBoundingClientRect(),x=h(Z).getBoundingClientRect(),O=document.documentElement.clientHeight,A=document.documentElement.clientWidth,p=c()==="auto"?g.bottom+x.height+s+n>O:c()==="top",U=Math.max(n,Math.min(A-n-x.width,g.left+g.width/2-x.width/2));if(p?h(Z).style.top=`${g.top-(x.height+s)}px`:h(Z).style.top=`${g.bottom+s}px`,h(Z).style.left=`${U}px`,h(Z).setAttribute("data-floating",p?"top":"bottom"),h(_t)){const be=h(_t).getBoundingClientRect();h(_t).style.left=g.left-U+g.width/2-be.width/2+"px"}}else N("unable to find floating anchor element")}async function Fo(n){if(!W())throw new Error("Attribute verifyurl not set.");N("requesting server verification from",W());const s={payload:n};if(H()!==!1){const{blockedCountries:O,classifier:A,disableRules:p,email:U,expectedLanguages:be,expectedCountries:D,fields:fe,ipAddress:yt,text:Ko,timeZone:Hn}=No();s.blockedCountries=O,s.classifier=A,s.disableRules=p,s.email=U===!1?void 0:To(U),s.expectedCountries=D,s.expectedLanguages=be||(pn?[pn]:void 0),s.fields=fe===!1?void 0:Lo(fe),s.ipAddress=yt===!1?void 0:yt||"auto",s.text=Ko,s.timeZone=Hn===!1?void 0:Hn||ho()}const g=await fetch(W(),{body:JSON.stringify(s),headers:{"content-type":"application/json"},method:"POST"});if(g.status!==200)throw new Error(`Server responded with ${g.status}.`);const x=await g.json();if(x!=null&&x.payload&&P(Oe,ae(x.payload)),vt("serververification",x),o()&&x.classification==="BAD")throw new Error("SpamFilter returned negative classification.")}function Ot(n){N("expire",n),me&&(clearTimeout(me),me=null),n<1?bn():me=setTimeout(bn,n)}function Sn(n){N("floating",n),c()!==n&&(h(Z).style.left="",h(Z).style.top=""),c(n===!0||n===""?"auto":n===!1||n==="false"?void 0:c()),c()?(r()||r("onsubmit"),document.addEventListener("scroll",xn),document.addEventListener("click",En),window.addEventListener("resize",An)):r()==="onsubmit"&&r(void 0)}function Tn(n){if(!n.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(n.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!_n.includes(n.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${_n.join(", ")}`);if(!n.challenge||n.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!n.salt||n.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function Nn(n){let s=null;if("Worker"in window){try{s=await Mo(n,n.maxnumber)}catch(g){N(g)}if((s==null?void 0:s.number)!==void 0||"obfuscated"in n)return{data:n,solution:s}}if("obfuscated"in n){const g=await go(n.obfuscated,n.key,n.maxnumber);return{data:n,solution:await g.promise}}return{data:n,solution:await co(n.challenge,n.salt,n.algorithm,n.maxnumber||M()).promise}}async function Mo(n,s=typeof I()=="number"?I():M(),g=Math.ceil(ge())){const x=[];g=Math.min(16,Math.max(1,g));for(let p=0;p<g;p++)x.push(altchaCreateWorker(ht()));const O=Math.ceil(s/g),A=await Promise.all(x.map((p,U)=>{const be=U*O;return new Promise(D=>{p.addEventListener("message",fe=>{if(fe.data)for(const yt of x)yt!==p&&yt.postMessage({type:"abort"});D(fe.data)}),p.postMessage({payload:n,max:be+O,start:be,type:"work"})})}));for(const p of x)p.terminate();return A.find(p=>!!p)||null}async function gt(){if(!q()){Fe(b.ERROR);return}const n=Se.find(s=>s.constructor.pluginName==="obfuscation");if(!n||!("clarify"in n)){Fe(b.ERROR),N("Plugin `obfuscation` not found. Import `altcha/plugins/obfuscation` to load it.");return}if("clarify"in n&&typeof n.clarify=="function")return n.clarify()}function Ln(n){n.obfuscated!==void 0&&q(n.obfuscated),n.auto!==void 0&&(r(n.auto),r()==="onload"&&(q()?gt():Te())),n.blockspam!==void 0&&o(!!n.blockspam),n.customfetch!==void 0&&a(n.customfetch),n.floatinganchor!==void 0&&v(n.floatinganchor),n.delay!==void 0&&u(n.delay),n.floatingoffset!==void 0&&_(n.floatingoffset),n.floating!==void 0&&Sn(n.floating),n.expire!==void 0&&(Ot(n.expire),f(n.expire)),n.challenge&&(l(typeof n.challenge=="string"?n.challenge:JSON.stringify(n.challenge)),Tn(h(nr))),n.challengeurl!==void 0&&i(n.challengeurl),n.debug!==void 0&&d(!!n.debug),n.hidefooter!==void 0&&m(!!n.hidefooter),n.hidelogo!==void 0&&w(!!n.hidelogo),n.maxnumber!==void 0&&M(+n.maxnumber),n.mockerror!==void 0&&ne(!!n.mockerror),n.name!==void 0&&L(n.name),n.refetchonexpire!==void 0&&we(!!n.refetchonexpire),n.spamfilter!==void 0&&H(typeof n.spamfilter=="object"?n.spamfilter:!!n.spamfilter),n.strings&&Ie(typeof n.strings=="string"?n.strings:JSON.stringify(n.strings)),n.test!==void 0&&I(typeof n.test=="number"?n.test:!!n.test),n.verifyurl!==void 0&&W(n.verifyurl),n.workers!==void 0&&ge(+n.workers),n.workerurl!==void 0&&ht(n.workerurl)}function Dn(){return{auto:r(),blockspam:o(),challengeurl:i(),debug:d(),delay:u(),expire:f(),floating:c(),floatinganchor:v(),floatingoffset:_(),hidefooter:m(),hidelogo:w(),name:L(),maxnumber:M(),mockerror:ne(),obfuscated:q(),refetchonexpire:we(),spamfilter:H(),strings:h(ie),test:I(),verifyurl:W(),workers:ge(),workerurl:ht()}}function Pn(){return et}function qo(n){return Se.find(s=>s.constructor.pluginName===n)}function zn(){return h(T)}function mt(n=b.UNVERIFIED,s=null){me&&(clearTimeout(me),me=null),P(Qe,!1),P(Oe,null),Fe(n,s)}function On(n){et=n}function Fe(n,s=null){P(T,ae(n)),P(tt,ae(s)),vt("statechange",{payload:h(Oe),state:h(T)})}async function Te(){return mt(b.VERIFYING),await new Promise(n=>setTimeout(n,u()||0)),So().then(n=>(Tn(n),N("challenge",n),Nn(n))).then(({data:n,solution:s})=>{if(N("solution",s),"challenge"in n&&s&&!("clearText"in s))if((s==null?void 0:s.number)!==void 0){if(W())return Fo(wn(n,s));P(Oe,ae(wn(n,s))),N("payload",h(Oe))}else throw N("Unable to find a solution. Ensure that the 'maxnumber' attribute is greater than the randomly generated number."),new Error("Unexpected result returned.")}).then(()=>{Fe(b.VERIFIED),N("verified"),Mi().then(()=>{vt("verified",{payload:h(Oe)})})}).catch(n=>{N(n),Fe(b.ERROR,n.message)})}var Fn=Ro(),Mn=Bt(Fn);Ji(Mn,t,"default",{});var pt=pe(Mn,2),ir=Q(pt),qn=Q(ir);{var Uo=n=>{var s=mo();te(n,s)};Ae(qn,n=>{h(T)===b.VERIFYING&&n(Uo)})}var Ft=pe(qn,2),rt=Q(Ft);ln(rt),rt.__change=Po,X(Ft);var or=pe(Ft,2),Vo=Q(or);{var jo=n=>{var s=po(),g=Bt(s),x=Q(g);Xe(x,()=>h(ie).verified),X(g);var O=pe(g,2);ln(O),Ye(()=>{ue(O,"name",L()),Xi(O,h(Oe))}),te(n,s)},Bo=n=>{var s=Hi(),g=Bt(s);{var x=A=>{var p=yo(),U=Q(p);Xe(U,()=>h(ie).verifying),X(p),te(A,p)},O=A=>{var p=wo(),U=Q(p);Xe(U,()=>h(ie).label),X(p),Ye(()=>ue(p,"for",`${L()??""}_checkbox`)),te(A,p)};Ae(g,A=>{h(T)===b.VERIFYING?A(x):A(O,!1)},!0)}te(n,s)};Ae(Vo,n=>{h(T)===b.VERIFIED?n(jo):n(Bo,!1)})}X(or);var Ho=pe(or,2);{var Yo=n=>{var s=bo(),g=Q(s);ue(g,"href",mn),X(s),Ye(()=>ue(g,"aria-label",h(ie).ariaLinkLabel)),te(n,s)};Ae(Ho,n=>{(w()!==!0||h(rr))&&n(Yo)})}X(ir);var Un=pe(ir,2);{var Wo=n=>{var s=$o(),g=pe(Q(s),2);{var x=A=>{var p=Eo(),U=Q(p);Xe(U,()=>h(ie).expired),X(p),Ye(()=>ue(p,"title",h(tt))),te(A,p)},O=A=>{var p=xo(),U=Q(p);Xe(U,()=>h(ie).error),X(p),Ye(()=>ue(p,"title",h(tt))),te(A,p)};Ae(g,A=>{h(T)===b.EXPIRED?A(x):A(O,!1)})}X(s),te(n,s)};Ae(Un,n=>{(h(tt)||h(T)===b.EXPIRED)&&n(Wo)})}var Vn=pe(Un,2);{var Zo=n=>{var s=ko(),g=Q(s),x=Q(g);Xe(x,()=>h(ie).footer),X(g),X(s),te(n,s)};Ae(Vn,n=>{h(ie).footer&&(m()!==!0||h(rr))&&n(Zo)})}var Go=pe(Vn,2);{var Jo=n=>{var s=Co();un(s,g=>P(_t,g),()=>h(_t)),te(n,s)};Ae(Go,n=>{c()&&n(Jo)})}return X(pt),un(pt,n=>P(Z,n),()=>h(Z)),Ye(()=>{ue(pt,"data-state",h(T)),ue(pt,"data-floating",c()),eo(Ft,"altcha-hidden",h(T)===b.VERIFYING),ue(rt,"id",`${L()??""}_checkbox`),rt.required=r()!=="onsubmit"&&(!c()||r()!=="off")}),ji("invalid",rt,Rn),to(rt,()=>h(Qe),n=>P(Qe,n)),te(e,Fn),Kr({clarify:gt,configure:Ln,getConfiguration:Dn,getFloatingAnchor:Pn,getPlugin:qo,getState:zn,reset:mt,setFloatingAnchor:On,setState:Fe,verify:Te,get auto(){return r()},set auto(n=void 0){r(n),C()},get blockspam(){return o()},set blockspam(n=void 0){o(n),C()},get challengeurl(){return i()},set challengeurl(n=void 0){i(n),C()},get challengejson(){return l()},set challengejson(n=void 0){l(n),C()},get customfetch(){return a()},set customfetch(n=void 0){a(n),C()},get debug(){return d()},set debug(n=!1){d(n),C()},get delay(){return u()},set delay(n=0){u(n),C()},get expire(){return f()},set expire(n=void 0){f(n),C()},get floating(){return c()},set floating(n=void 0){c(n),C()},get floatinganchor(){return v()},set floatinganchor(n=void 0){v(n),C()},get floatingoffset(){return _()},set floatingoffset(n=void 0){_(n),C()},get hidefooter(){return m()},set hidefooter(n=!1){m(n),C()},get hidelogo(){return w()},set hidelogo(n=!1){w(n),C()},get name(){return L()},set name(n="altcha"){L(n),C()},get maxnumber(){return M()},set maxnumber(n=1e6){M(n),C()},get mockerror(){return ne()},set mockerror(n=!1){ne(n),C()},get obfuscated(){return q()},set obfuscated(n=void 0){q(n),C()},get plugins(){return Y()},set plugins(n=void 0){Y(n),C()},get refetchonexpire(){return we()},set refetchonexpire(n=!0){we(n),C()},get spamfilter(){return H()},set spamfilter(n=!1){H(n),C()},get strings(){return Ie()},set strings(n=void 0){Ie(n),C()},get test(){return I()},set test(n=!1){I(n),C()},get verifyurl(){return W()},set verifyurl(n=void 0){W(n),C()},get workers(){return ge()},set workers(n=Math.min(16,navigator.hardwareConcurrency||8)){ge(n),C()},get workerurl(){return ht()},set workerurl(n=void 0){ht(n),C()}})}Bi(["change"]),customElements.define("altcha-widget",so(vn,{blockspam:{type:"Boolean"},debug:{type:"Boolean"},delay:{type:"Number"},expire:{type:"Number"},floatingoffset:{type:"Number"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},maxnumber:{type:"Number"},mockerror:{type:"Boolean"},refetchonexpire:{type:"Boolean"},test:{type:"Boolean"},workers:{type:"Number"},auto:{},challengeurl:{},challengejson:{},customfetch:{},floating:{},floatinganchor:{},name:{},obfuscated:{},plugins:{},spamfilter:{},strings:{},verifyurl:{},workerurl:{}},["default"],["clarify","configure","getConfiguration","getFloatingAnchor","getPlugin","getState","reset","setFloatingAnchor","setState","verify"],!1)),globalThis.altchaCreateWorker=e=>new Worker(new URL(e||"./worker.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:k&&k.tagName.toUpperCase()==="SCRIPT"&&k.src||new URL("altcha.umd.cjs",document.baseURI).href)),globalThis.altchaPlugins=globalThis.altchaPlugins||[],$.Altcha=vn,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|